fileControl.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2017 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "fileControl.H"
30#include "tetPointRef.H"
31#include "scalarList.H"
32#include "vectorTools.H"
33#include "pointIOField.H"
34#include "scalarIOField.H"
35#include "triadIOField.H"
36
37// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38
39namespace Foam
40{
41
42defineTypeNameAndDebug(fileControl, 0);
44(
45 cellSizeAndAlignmentControl,
46 fileControl,
47 dictionary
48);
49
50}
51
52
53// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
54
55
56// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57
59(
60 const Time& runTime,
61 const word& name,
62 const dictionary& controlFunctionDict,
63 const conformationSurfaces& geometryToConformTo,
64 const scalar& defaultCellSize
65)
66:
67 cellSizeAndAlignmentControl
68 (
69 runTime,
70 name,
71 controlFunctionDict,
72 geometryToConformTo,
73 defaultCellSize
74 ),
75 pointsFile_(controlFunctionDict.get<fileName>("pointsFile")),
76 sizesFile_(controlFunctionDict.get<fileName>("sizesFile")),
77 alignmentsFile_(controlFunctionDict.get<fileName>("alignmentsFile")),
78 maxPriority_(controlFunctionDict.get<label>("priority"))
79{
80 Info<< indent << "Loading " << name << " from file:" << nl
81 << indent << " priority : " << maxPriority_ << nl
82 << indent << " points : " << pointsFile_ << nl
83 << indent << " sizes : " << sizesFile_ << nl
84 << indent << " alignments : " << alignmentsFile_
85 << endl;
86}
87
88
89// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
90//
91//Foam::scalar Foam::fileControl::cellSize(const point& pt) const
92//{
93// FixedList<scalar, 4> bary;
94// Cell_handle ch;
95//
96// triangulatedMesh_.barycentricCoords(pt, bary, ch);
97//
98// scalar size = 0;
99// forAll(bary, pI)
100// {
101// size += bary[pI]*ch->vertex(pI)->size();
102// }
103//
104// return size;
105//}
106//
107//
109//Foam::tensor Foam::fileControl::cellAlignment(const point& pt) const
110//{
111// FixedList<scalar, 4> bary;
112// Cell_handle ch;
113//
114// triangulatedMesh_.barycentricCoords(pt, bary, ch);
115//
116// label nearest = 0;
117//
118// tensor alignment = Zero;
119// forAll(bary, pI)
120// {
121// //alignment += bary[pI]*ch->vertex(pI)->alignment();
122//
123// // Find nearest point
124// if (bary[pI] > nearest)
125// {
126// alignment = ch->vertex(pI)->alignment();
127// nearest = bary[pI];
128// }
129// }
130//
131// return alignment;
132//}
133//
134//
136//void Foam::fileControl::cellSizeAndAlignment
137//(
138// const point& pt,
139// scalar& size,
140// tensor& alignment
141//) const
142//{
143// FixedList<scalar, 4> bary;
144// Cell_handle ch;
145//
146// triangulatedMesh_.barycentricCoords(pt, bary, ch);
147//
148// size = 0;
149// forAll(bary, pI)
150// {
151// size += bary[pI]*ch->vertex(pI)->size();
152// }
153//
159//
160// alignment = cellAlignment(pt);
161//}
162
163
165(
166 DynamicList<Foam::point>& pts,
167 DynamicList<scalar>& sizes
168) const
169{
170 return;
171}
172
173
175(
176 pointField& pts,
177 scalarField& sizes,
178 triadField& alignments
179) const
180{
181 Info<< " Reading points from file : " << pointsFile_ << endl;
182
183 pointIOField pointsTmp
184 (
185 IOobject
186 (
187 pointsFile_,
188 runTime_.constant(),
189 runTime_,
192 false
193 )
194 );
195
196 pts.transfer(pointsTmp);
197
198 Info<< " Reading sizes from file : " << sizesFile_ << endl;
199
200 scalarIOField sizesTmp
201 (
202 IOobject
203 (
204 sizesFile_,
205 runTime_.constant(),
206 runTime_,
209 false
210 )
211 );
212
213 sizes.transfer(sizesTmp);
214
215 Info<< " Reading alignments from file : " << alignmentsFile_ << endl;
216
217 triadIOField alignmentsTmp
218 (
219 IOobject
220 (
221 alignmentsFile_,
222 runTime_.constant(),
223 runTime_,
226 false
227 )
228 );
229
230 alignments.transfer(alignmentsTmp);
231
232 if ((pts.size() != sizes.size()) || (pts.size() != alignments.size()))
233 {
235 << "Size of list of points, sizes and alignments do not match:"
236 << nl
237 << "Points size = " << pts.size() << nl
238 << "Sizes size = " << sizes.size() << nl
239 << "Alignments size = " << alignments.size()
240 << abort(FatalError);
241 }
242}
243
244
245// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
virtual void cellSizeFunctionVertices(DynamicList< Foam::point > &pts, DynamicList< scalar > &sizes) const
virtual void initialVertices(pointField &pts, scalarField &sizes, triadField &alignments) const
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
Namespace for OpenFOAM.
IOField< triad > triadIOField
triadField with IO.
Definition: triadIOField.H:44
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOField< scalar > scalarIOField
scalarField with IO.
Definition: scalarIOField.H:44
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Field< triad > triadField
Specialisation of Field<T> for triad.
Definition: triadFieldFwd.H:45
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53