refinementHistoryConstraint.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) 2015-2022 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 
28 #include "syncTools.H"
29 #include "refinementHistory.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeName(refinementHistoryConstraint);
36 
38  (
39  decompositionConstraint,
40  refinementHistoryConstraint,
41  dictionary
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const dictionary& constraintsDict,
51  const word& modelType
52 )
53 :
54  decompositionConstraint(constraintsDict, typeName)
55 {
56  if (decompositionConstraint::debug)
57  {
58  Info<< type() << " : setting constraints to preserve refinement history"
59  << endl;
60  }
61 }
62 
63 
65 :
67 {
68  if (decompositionConstraint::debug)
69  {
70  Info<< type() << " : setting constraints to refinement history"
71  << endl;
72  }
73 }
74 
75 
76 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
77 
79 (
80  const polyMesh& mesh,
81  boolList& blockedFace,
82  PtrList<labelList>& specifiedProcessorFaces,
83  labelList& specifiedProcessor,
84  List<labelPair>& explicitConnections
85 ) const
86 {
88  refinementHistory const* refPtr = nullptr;
89 
90  if (mesh.foundObject<refinementHistory>("refinementHistory"))
91  {
92  if (decompositionConstraint::debug)
93  {
94  Info<< type() << " add : found refinementHistory" << endl;
95  }
96  refPtr = &mesh.lookupObject<refinementHistory>("refinementHistory");
97  }
98  else
99  {
100  if (decompositionConstraint::debug)
101  {
102  Info<< type() << " add : reading refinementHistory from time "
103  << mesh.facesInstance() << endl;
104  }
105  storagePtr.reset
106  (
108  (
109  IOobject
110  (
111  "refinementHistory",
112  mesh.facesInstance(),
114  mesh,
117  ),
118  mesh.nCells()
119  )
120  );
121  }
122 
123  const refinementHistory& history =
124  (
125  storagePtr.valid()
126  ? storagePtr()
127  : *refPtr
128  );
129 
130  if (history.active())
131  {
132  if (decompositionConstraint::debug)
133  {
134  Info<< type() << " add : adding refinementHistory " << endl;
135  }
136 
137  // refinementHistory itself implements decompositionConstraint
138  history.add
139  (
140  blockedFace,
141  specifiedProcessorFaces,
142  specifiedProcessor,
143  explicitConnections
144  );
145  }
146 }
147 
148 
150 (
151  const polyMesh& mesh,
152  const boolList& blockedFace,
153  const PtrList<labelList>& specifiedProcessorFaces,
154  const labelList& specifiedProcessor,
155  const List<labelPair>& explicitConnections,
156  labelList& decomposition
157 ) const
158 {
160  refinementHistory const* refPtr = nullptr;
161 
162  if (mesh.foundObject<refinementHistory>("refinementHistory"))
163  {
164  if (decompositionConstraint::debug)
165  {
166  Info<< type() << " apply : found refinementHistory" << endl;
167  }
168  refPtr = &mesh.lookupObject<refinementHistory>("refinementHistory");
169  }
170  else
171  {
172  if (decompositionConstraint::debug)
173  {
174  Info<< type() << " apply : reading refinementHistory from time "
175  << mesh.facesInstance() << endl;
176  }
177  storagePtr.reset
178  (
180  (
181  IOobject
182  (
183  "refinementHistory",
184  mesh.facesInstance(),
186  mesh,
189  ),
190  mesh.nCells()
191  )
192  );
193  }
194 
195  const refinementHistory& history =
196  (
197  storagePtr.valid()
198  ? storagePtr()
199  : *refPtr
200  );
201 
202  if (history.active())
203  {
204  if (decompositionConstraint::debug)
205  {
206  Info<< type() << " apply : adding refinementHistory " << endl;
207  }
208 
209  // refinementHistory itself implements decompositionConstraint
210  history.apply
211  (
212  blockedFace,
213  specifiedProcessorFaces,
214  specifiedProcessor,
215  explicitConnections,
216  decomposition
217  );
218  }
219 }
220 
221 
222 // ************************************************************************* //
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:888
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
bool active() const
Is there unrefinement history?
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:328
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool foundObject(const word &name) const
Is the named Type found?
fvMesh & mesh
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Macros for easy insertion into run-time selection tables.
virtual void apply(const polyMesh &mesh, const boolList &blockedFace, const PtrList< labelList > &specifiedProcessorFaces, const labelList &specifiedProcessor, const List< labelPair > &explicitConnections, labelList &decomposition) const
Apply any additional post-decomposition constraints.
refinementHistoryConstraint()
Construct from components.
A class for handling words, derived from string.
Definition: word.H:59
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Definition: autoPtrI.H:83
virtual void add(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my constraints to list of constraints.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeName(refinementHistoryConstraint)
void apply(const boolList &blockedFace, const PtrList< labelList > &specifiedProcessorFaces, const labelList &specifiedProcessor, const List< labelPair > &explicitConnections, labelList &decomposition) const
Apply any additional post-decomposition constraints.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
All refinement history. Used in unrefinement.
void add(boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my decomposition constraints.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
Namespace for OpenFOAM.