regionModel1D.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "regionModel1D.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 namespace regionModels
33 {
34  defineTypeNameAndDebug(regionModel1D, 0);
35 }
36 }
37 
38 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
39 
40 void Foam::regionModels::regionModel1D::constructMeshObjects()
41 {
42  nMagSfPtr_.reset
43  (
45  (
46  IOobject
47  (
48  "nMagSf",
49  time().timeName(),
50  regionMesh(),
53  ),
54  regionMesh(),
56  )
57  );
58 }
59 
60 
61 void Foam::regionModels::regionModel1D::initialise()
62 {
63  if (debug)
64  {
65  Pout<< "regionModel1D::initialise()" << endl;
66  }
67 
68  // Calculate boundaryFaceFaces and boundaryFaceCells
69 
70  DynamicList<label> faceIDs;
71  DynamicList<label> cellIDs;
72 
73  label localPyrolysisFacei = 0;
74 
75  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
76 
77  forAll(intCoupledPatchIDs_, i)
78  {
79  const label patchi = intCoupledPatchIDs_[i];
80  const polyPatch& ppCoupled = rbm[patchi];
81  forAll(ppCoupled, localFacei)
82  {
83  label facei = ppCoupled.start() + localFacei;
84  label celli = -1;
85  label nFaces = 0;
86  label nCells = 0;
87  do
88  {
89  label ownCelli = regionMesh().faceOwner()[facei];
90  if (ownCelli != celli)
91  {
92  celli = ownCelli;
93  }
94  else
95  {
96  celli = regionMesh().faceNeighbour()[facei];
97  }
98  nCells++;
99  cellIDs.append(celli);
100  const cell& cFaces = regionMesh().cells()[celli];
101  facei = cFaces.opposingFaceLabel(facei, regionMesh().faces());
102  faceIDs.append(facei);
103  nFaces++;
104  } while (regionMesh().isInternalFace(facei));
105 
106  boundaryFaceOppositeFace_[localPyrolysisFacei] = facei;
107  faceIDs.remove(); // remove boundary face.
108  nFaces--;
109 
110  boundaryFaceFaces_[localPyrolysisFacei].transfer(faceIDs);
111  boundaryFaceCells_[localPyrolysisFacei].transfer(cellIDs);
112 
113  localPyrolysisFacei++;
114  nLayers_ = nCells;
115  }
116  }
117 
118  boundaryFaceOppositeFace_.setSize(localPyrolysisFacei);
119  boundaryFaceFaces_.setSize(localPyrolysisFacei);
120  boundaryFaceCells_.setSize(localPyrolysisFacei);
121 
122  surfaceScalarField& nMagSf = nMagSfPtr_();
123 
124  surfaceScalarField::Boundary nMagSfBf =
125  nMagSf.boundaryFieldRef();
126 
127  localPyrolysisFacei = 0;
128 
129  forAll(intCoupledPatchIDs_, i)
130  {
131  const label patchi = intCoupledPatchIDs_[i];
132  const polyPatch& ppCoupled = rbm[patchi];
133  const vectorField& pNormals = ppCoupled.faceNormals();
134  nMagSfBf[patchi] = regionMesh().Sf().boundaryField()[patchi] & pNormals;
135  forAll(pNormals, localFacei)
136  {
137  const vector& n = pNormals[localFacei];
138  const labelList& faces = boundaryFaceFaces_[localPyrolysisFacei++];
139  forAll(faces, facei)
140  {
141  const label faceID = faces[facei];
142  nMagSf[faceID] = regionMesh().Sf()[faceID] & n;
143  }
144  }
145  }
146 }
147 
148 
149 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
150 
152 {
153  if (regionModel::read())
154  {
155  moveMesh_.readIfPresent("moveMesh", coeffs_);
156 
157  return true;
158  }
159  else
160  {
161  return false;
162  }
163 }
164 
165 
167 {
168  if (regionModel::read(dict))
169  {
170  moveMesh_.readIfPresent("moveMesh", coeffs_);
171 
172  return true;
173  }
174  else
175  {
176  return false;
177  }
178 }
179 
180 
182 (
183  const scalarList& deltaV,
184  const scalar minDelta
185 )
186 {
187  tmp<labelField> tcellMoveMap(new labelField(regionMesh().nCells(), 0));
188  labelField& cellMoveMap = tcellMoveMap.ref();
189 
190  if (!moveMesh_)
191  {
192  return cellMoveMap;
193  }
194 
195  pointField oldPoints = regionMesh().points();
196  pointField newPoints = oldPoints;
197 
198  const polyBoundaryMesh& bm = regionMesh().boundaryMesh();
199 
200  label totalFaceId = 0;
201  forAll(intCoupledPatchIDs_, localPatchi)
202  {
203  label patchi = intCoupledPatchIDs_[localPatchi];
204  const polyPatch pp = bm[patchi];
205  const vectorField& cf = regionMesh().Cf().boundaryField()[patchi];
206 
207  forAll(pp, patchFacei)
208  {
209  const labelList& faces = boundaryFaceFaces_[totalFaceId];
210  const labelList& cells = boundaryFaceCells_[totalFaceId];
211 
212  const vector n = pp.faceNormals()[patchFacei];
213  const vector sf = pp.faceAreas()[patchFacei];
214 
215  List<point> oldCf(faces.size() + 1);
216  oldCf[0] = cf[patchFacei];
217  forAll(faces, i)
218  {
219  oldCf[i + 1] = regionMesh().faceCentres()[faces[i]];
220  }
221 
222  vector newDelta = Zero;
223  point nbrCf = oldCf[0];
224 
225  forAll(faces, i)
226  {
227  const label facei = faces[i];
228  const label celli = cells[i];
229 
230  const face f = regionMesh().faces()[facei];
231 
232  newDelta += (deltaV[celli]/mag(sf))*n;
233 
234  vector localDelta = Zero;
235  forAll(f, pti)
236  {
237  const label pointi = f[pti];
238 
239  if
240  (
241  mag((nbrCf - (oldPoints[pointi] + newDelta)) & n)
242  > minDelta
243  )
244  {
245  newPoints[pointi] = oldPoints[pointi] + newDelta;
246  localDelta = newDelta;
247  cellMoveMap[celli] = 1;
248  }
249  }
250  nbrCf = oldCf[i + 1] + localDelta;
251  }
252  // Modify boundary
253  const label bFacei = boundaryFaceOppositeFace_[totalFaceId];
254  const face f = regionMesh().faces()[bFacei];
255  const label celli = cells[cells.size() - 1];
256  newDelta += (deltaV[celli]/mag(sf))*n;
257  forAll(f, pti)
258  {
259  const label pointi = f[pti];
260  if
261  (
262  mag((nbrCf - (oldPoints[pointi] + newDelta)) & n)
263  > minDelta
264  )
265  {
266  newPoints[pointi] = oldPoints[pointi] + newDelta;
267  cellMoveMap[celli] = 1;
268  }
269  }
270  totalFaceId ++;
271  }
272  }
273  // Move points
274  regionMesh().movePoints(newPoints);
275 
276  return tcellMoveMap;
277 }
278 
279 
280 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
281 
282 Foam::regionModels::regionModel1D::regionModel1D
283 (
284  const fvMesh& mesh,
285  const word& regionType
286 )
287 :
288  regionModel(mesh, regionType),
289  boundaryFaceFaces_(),
290  boundaryFaceCells_(),
291  boundaryFaceOppositeFace_(),
292  nLayers_(0),
293  nMagSfPtr_(nullptr),
294  moveMesh_(false)
295 {}
296 
297 
298 Foam::regionModels::regionModel1D::regionModel1D
299 (
300  const fvMesh& mesh,
301  const word& regionType,
302  const word& modelName,
303  bool readFields
304 )
305 :
306  regionModel(mesh, regionType, modelName, false),
307  boundaryFaceFaces_(regionMesh().nCells()),
308  boundaryFaceCells_(regionMesh().nCells()),
309  boundaryFaceOppositeFace_(regionMesh().nCells()),
310  nLayers_(0),
311  nMagSfPtr_(nullptr),
312  moveMesh_(true)
313 {
314  if (active_)
315  {
316  constructMeshObjects();
317  initialise();
318 
319  if (readFields)
320  {
321  read();
322  }
323  }
324 }
325 
326 
327 Foam::regionModels::regionModel1D::regionModel1D
328 (
329  const fvMesh& mesh,
330  const word& regionType,
331  const word& modelName,
332  const dictionary& dict,
333  bool readFields
334 )
335 :
336  regionModel(mesh, regionType, modelName, dict, readFields),
337  boundaryFaceFaces_(regionMesh().nCells()),
338  boundaryFaceCells_(regionMesh().nCells()),
339  boundaryFaceOppositeFace_(regionMesh().nCells()),
340  nLayers_(0),
341  nMagSfPtr_(nullptr),
342  moveMesh_(false)
343 {
344  if (active_)
345  {
346  constructMeshObjects();
347  initialise();
348 
349  if (readFields)
350  {
351  read(dict);
352  }
353  }
354 }
355 
356 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
357 
359 {}
360 
361 
362 // ************************************************************************* //
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:49
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
tmp< labelField > moveMesh(const scalarList &deltaV, const scalar minDelta=0.0)
Move mesh points according to change in cell volumes.
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
defineTypeNameAndDebug(regionModel, 0)
bool read(const char *, int32_t &)
Definition: int32IO.C:85
const cellShapeList & cells
virtual ~regionModel1D()
Destructor.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read()
Read control parameters from dictionary.
Definition: regionModel.C:146
word timeName
Definition: getTimeIndex.H:3
List< label > labelList
A List of labels.
Definition: labelList.H:56
static const zero Zero
Definition: zero.H:97
const Field< PointType > & faceNormals() const
Return face normals for patch.
Foam::polyBoundaryMesh.
const vectorField::subField faceAreas() const
Return face normals.
Definition: polyPatch.C:290
labelList f(nPoints)
volScalarField sf(fieldObject, mesh)
label patchi
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
virtual bool read()
Read control parameters from dictionary.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
dimensioned< scalar > mag(const dimensioned< Type > &)
label n
Base class for region models.
Definition: regionModel.H:57
Field< vector > vectorField
Specialisation of Field<T> for vector.
A class for managing temporary objects.
Definition: PtrList.H:53
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:57
Namespace for OpenFOAM.