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 -------------------------------------------------------------------------------
10 License
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 "scalarList.H"
31 #include "vectorTools.H"
32 #include "pointIOField.H"
33 #include "scalarIOField.H"
34 #include "triadIOField.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 defineTypeNameAndDebug(fileControl, 0);
43 (
44  cellSizeAndAlignmentControl,
45  fileControl,
46  dictionary
47 );
48 
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
54 Foam::fileControl::fileControl
55 (
56  const Time& runTime,
57  const word& name,
58  const dictionary& controlFunctionDict,
59  const conformationSurfaces& geometryToConformTo,
60  const scalar& defaultCellSize
61 )
62 :
63  cellSizeAndAlignmentControl
64  (
65  runTime,
66  name,
67  controlFunctionDict,
68  geometryToConformTo,
69  defaultCellSize
70  ),
71  pointsFile_(controlFunctionDict.get<fileName>("pointsFile")),
72  sizesFile_(controlFunctionDict.get<fileName>("sizesFile")),
73  alignmentsFile_(controlFunctionDict.get<fileName>("alignmentsFile")),
74  maxPriority_(controlFunctionDict.get<label>("priority"))
75 {
76  Info<< indent << "Loading " << name << " from file:" << nl
77  << indent << " priority : " << maxPriority_ << nl
78  << indent << " points : " << pointsFile_ << nl
79  << indent << " sizes : " << sizesFile_ << nl
80  << indent << " alignments : " << alignmentsFile_
81  << endl;
82 }
83 
84 
85 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
86 //
87 //Foam::scalar Foam::fileControl::cellSize(const point& pt) const
88 //{
89 // FixedList<scalar, 4> bary;
90 // Cell_handle ch;
91 //
92 // triangulatedMesh_.barycentricCoords(pt, bary, ch);
93 //
94 // scalar size = 0;
95 // forAll(bary, pI)
96 // {
97 // size += bary[pI]*ch->vertex(pI)->size();
98 // }
99 //
100 // return size;
101 //}
102 //
103 //
105 //Foam::tensor Foam::fileControl::cellAlignment(const point& pt) const
106 //{
107 // FixedList<scalar, 4> bary;
108 // Cell_handle ch;
109 //
110 // triangulatedMesh_.barycentricCoords(pt, bary, ch);
111 //
112 // label nearest = 0;
113 //
114 // tensor alignment = Zero;
115 // forAll(bary, pI)
116 // {
117 // //alignment += bary[pI]*ch->vertex(pI)->alignment();
118 //
119 // // Find nearest point
120 // if (bary[pI] > nearest)
121 // {
122 // alignment = ch->vertex(pI)->alignment();
123 // nearest = bary[pI];
124 // }
125 // }
126 //
127 // return alignment;
128 //}
129 //
130 //
132 //void Foam::fileControl::cellSizeAndAlignment
133 //(
134 // const point& pt,
135 // scalar& size,
136 // tensor& alignment
137 //) const
138 //{
139 // FixedList<scalar, 4> bary;
140 // Cell_handle ch;
141 //
142 // triangulatedMesh_.barycentricCoords(pt, bary, ch);
143 //
144 // size = 0;
145 // forAll(bary, pI)
146 // {
147 // size += bary[pI]*ch->vertex(pI)->size();
148 // }
149 //
155 //
156 // alignment = cellAlignment(pt);
157 //}
158 
159 
161 (
162  DynamicList<Foam::point>& pts,
163  DynamicList<scalar>& sizes
164 ) const
165 {
166  return;
167 }
168 
169 
171 (
172  pointField& pts,
173  scalarField& sizes,
174  triadField& alignments
175 ) const
176 {
177  Info<< " Reading points from file : " << pointsFile_ << endl;
178 
180  (
181  IOobject
182  (
183  pointsFile_,
184  runTime_.constant(),
185  runTime_,
187  )
188  );
189 
190  Info<< " Reading sizes from file : " << sizesFile_ << endl;
191 
193  (
194  IOobject
195  (
196  sizesFile_,
197  runTime_.constant(),
198  runTime_,
200  )
201  );
202 
203  Info<< " Reading alignments from file : " << alignmentsFile_ << endl;
204 
205  alignments = triadIOField::readContents
206  (
207  IOobject
208  (
209  alignmentsFile_,
210  runTime_.constant(),
211  runTime_,
213  )
214  );
215 
216  if ((pts.size() != sizes.size()) || (pts.size() != alignments.size()))
217  {
219  << "Size of list of points, sizes and alignments do not match:"
220  << nl
221  << "Points size = " << pts.size() << nl
222  << "Sizes size = " << sizes.size() << nl
223  << "Alignments size = " << alignments.size()
224  << abort(FatalError);
225  }
226 }
227 
228 
229 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
virtual void initialVertices(pointField &pts, scalarField &sizes, triadField &alignments) const
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:493
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual void cellSizeFunctionVertices(DynamicList< Foam::point > &pts, DynamicList< scalar > &sizes) const
Macros for easy insertion into run-time selection tables.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Field< triad > triadField
Specialisation of Field<T> for triad.
Definition: triadFieldFwd.H:37
defineTypeNameAndDebug(combustionModel, 0)
messageStream Info
Information stream (stdout output on master, null elsewhere)
static Field< Type > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
Definition: IOField.C:176
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
const pointField & pts