AMIMethod.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2013-2016 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 Class
25  Foam::AMIMethod
26 
27 Description
28  Base class for Arbitrary Mesh Interface (AMI) methods
29 
30 SourceFiles
31  AMIMethod.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef AMIMethod_H
36 #define AMIMethod_H
37 
38 #include "className.H"
39 #include "DynamicList.H"
40 #include "faceAreaIntersect.H"
41 #include "indexedOctree.H"
42 #include "treeDataPrimitivePatch.H"
43 #include "treeBoundBoxList.H"
44 #include "runTimeSelectionTables.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class AMIMethod Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 template<class SourcePatch, class TargetPatch>
56 class AMIMethod
57 {
58 
59 private:
60 
61  // Private Member Functions
62 
63  //- Disallow default bitwise copy construct
64  AMIMethod(const AMIMethod&);
65 
66  //- Disallow default bitwise assignment
67  void operator=(const AMIMethod&);
68 
69 
70 protected:
71 
72  //- Local typedef to octree tree-type
74 
75 
76  // Protected data
77 
78  //- Reference to source patch
79  const SourcePatch& srcPatch_;
80 
81  //- Reference to target patch
82  const TargetPatch& tgtPatch_;
83 
84  //- Flag to indicate that the two patches are co-directional and
85  // that the orientation of the target patch should be reversed
86  const bool reverseTarget_;
87 
88  //- Flag to indicate that the two patches must be matched/an overlap
89  // exists between them
90  const bool requireMatch_;
91 
92  //- Source face areas
93  const scalarField& srcMagSf_;
94 
95  //- Target face areas
96  const scalarField& tgtMagSf_;
97 
98  //- Labels of faces that are not overlapped by any target faces
99  // (should be empty for correct functioning)
101 
102  //- Octree used to find face seeds
104 
105  //- Face triangulation mode
107 
108 
109  // Protected Member Functions
110 
111  // Helper functions
112 
113  //- Check AMI patch coupling
114  void checkPatches() const;
115 
116  //- Initialise and return true if all ok
117  bool initialise
118  (
119  labelListList& srcAddress,
120  scalarListList& srcWeights,
121  labelListList& tgtAddress,
122  scalarListList& tgtWeights,
123  label& srcFacei,
124  label& tgtFacei
125  );
126 
127  //- Write triangle intersection to OBJ file
129  (
130  const scalar area,
131  const face& f1,
132  const face& f2,
133  const pointField& f1Points,
134  const pointField& f2Points
135  ) const;
136 
137 
138  // Common AMI method functions
139 
140  //- Reset the octree for the target patch face search
141  void resetTree();
142 
143  //- Find face on target patch that overlaps source face
144  label findTargetFace(const label srcFacei) const;
145 
146  //- Add faces neighbouring facei to the ID list
147  void appendNbrFaces
148  (
149  const label facei,
150  const TargetPatch& patch,
151  const DynamicList<label>& visitedFaces,
152  DynamicList<label>& faceIDs
153  ) const;
154 
155 
156 public:
157 
158  //- Runtime type information
159  TypeName("AMIMethod");
160 
161  //- Declare runtime constructor selection table
163  (
164  autoPtr,
165  AMIMethod,
166  components,
167  (
168  const SourcePatch& srcPatch,
169  const TargetPatch& tgtPatch,
170  const scalarField& srcMagSf,
171  const scalarField& tgtMagSf,
173  const bool reverseTarget,
174  const bool requireMatch
175  ),
176  (
177  srcPatch,
178  tgtPatch,
179  srcMagSf,
180  tgtMagSf,
181  triMode,
182  reverseTarget,
183  requireMatch
184  )
185  );
186 
187  //- Construct from components
188  AMIMethod
189  (
190  const SourcePatch& srcPatch,
191  const TargetPatch& tgtPatch,
192  const scalarField& srcMagSf,
193  const scalarField& tgtMagSf,
195  const bool reverseTarget,
196  const bool requireMatch
197  );
198 
199  //- Selector
200  static autoPtr<AMIMethod> New
201  (
202  const word& methodName,
203  const SourcePatch& srcPatch,
204  const TargetPatch& tgtPatch,
205  const scalarField& srcMagSf,
206  const scalarField& tgtMagSf,
208  const bool reverseTarget,
209  const bool requireMatch
210  );
211 
212 
213  //- Destructor
214  virtual ~AMIMethod();
215 
216 
217  // Member Functions
218 
219  // Access
220 
221  //- Labels of faces that are not overlapped by any target faces
222  // Note: this should be empty for correct functioning
223  inline const labelList& srcNonOverlap() const;
224 
225  //- Flag to indicate that interpolation patches are conformal
226  virtual bool conformal() const;
227 
228 
229  // Manipulation
230 
231  //- Update addressing and weights
232  virtual void calculate
233  (
234  labelListList& srcAddress,
235  scalarListList& srcWeights,
236  labelListList& tgtAddress,
237  scalarListList& tgtWeights,
238  label srcFacei = -1,
239  label tgtFacei = -1
240  ) = 0;
241 };
242 
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 } // End namespace Foam
247 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 #define makeAMIMethod(AMIType) \
251  \
252  typedef AMIMethod<AMIType::sourcePatchType,AMIType::targetPatchType> \
253  AMIMethod##AMIType; \
254  \
255  defineNamedTemplateTypeNameAndDebug(AMIMethod##AMIType, 0); \
256  defineTemplateRunTimeSelectionTable(AMIMethod##AMIType, components);
257 
259 #define makeAMIMethodType(AMIType, Method) \
260  \
261  typedef Method<AMIType::sourcePatchType,AMIType::targetPatchType> \
262  Method##AMIType; \
263  \
264  defineNamedTemplateTypeNameAndDebug(Method##AMIType, 0); \
265  \
266  AMIMethod<AMIType::sourcePatchType,AMIType::targetPatchType>:: \
267  addcomponentsConstructorToTable<Method##AMIType> \
268  add##Method##AMIType##ConstructorToTable_;
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #include "AMIMethodI.H"
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #ifdef NoRepository
278  #include "AMIMethod.C"
279  #include "AMIMethodNew.C"
280 #endif
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 #endif
285 
286 // ************************************************************************* //
treeDataPrimitivePatch< TargetPatch > treeType
Local typedef to octree tree-type.
Definition: AMIMethod.H:72
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
declareRunTimeSelectionTable(autoPtr, AMIMethod, components,(const SourcePatch &srcPatch, const TargetPatch &tgtPatch, const scalarField &srcMagSf, const scalarField &tgtMagSf, const faceAreaIntersect::triangulationMode &triMode, const bool reverseTarget, const bool requireMatch),(srcPatch, tgtPatch, srcMagSf, tgtMagSf, triMode, reverseTarget, requireMatch))
Declare runtime constructor selection table.
const TargetPatch & tgtPatch_
Reference to target patch.
Definition: AMIMethod.H:81
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
virtual ~AMIMethod()
Destructor.
Definition: AMIMethod.C:341
const bool requireMatch_
Flag to indicate that the two patches must be matched/an overlap.
Definition: AMIMethod.H:89
void appendNbrFaces(const label facei, const TargetPatch &patch, const DynamicList< label > &visitedFaces, DynamicList< label > &faceIDs) const
Add faces neighbouring facei to the ID list.
Definition: AMIMethod.C:261
const labelList & srcNonOverlap() const
Labels of faces that are not overlapped by any target faces.
Definition: AMIMethodI.H:28
virtual void calculate(labelListList &srcAddress, scalarListList &srcWeights, labelListList &tgtAddress, scalarListList &tgtWeights, label srcFacei=-1, label tgtFacei=-1)=0
Update addressing and weights.
label findTargetFace(const label srcFacei) const
Find face on target patch that overlaps source face.
Definition: AMIMethod.C:230
const SourcePatch & srcPatch_
Reference to source patch.
Definition: AMIMethod.H:78
scalar f1
Definition: createFields.H:28
const scalarField & tgtMagSf_
Target face areas.
Definition: AMIMethod.H:95
labelList srcNonOverlap_
Labels of faces that are not overlapped by any target faces.
Definition: AMIMethod.H:99
A class for handling words, derived from string.
Definition: word.H:59
Encapsulation of data needed to search on PrimitivePatches.
virtual bool conformal() const
Flag to indicate that interpolation patches are conformal.
Definition: AMIMethod.C:348
void resetTree()
Reset the octree for the target patch face search.
Definition: AMIMethod.C:198
static autoPtr< AMIMethod > New(const word &methodName, const SourcePatch &srcPatch, const TargetPatch &tgtPatch, const scalarField &srcMagSf, const scalarField &tgtMagSf, const faceAreaIntersect::triangulationMode &triMode, const bool reverseTarget, const bool requireMatch)
Selector.
Definition: AMIMethodNew.C:31
Base class for Arbitrary Mesh Interface (AMI) methods.
Definition: AMIMethod.H:55
void checkPatches() const
Check AMI patch coupling.
Definition: AMIMethod.C:34
autoPtr< indexedOctree< treeType > > treePtr_
Octree used to find face seeds.
Definition: AMIMethod.H:102
const faceAreaIntersect::triangulationMode triMode_
Face triangulation mode.
Definition: AMIMethod.H:105
const scalarField & srcMagSf_
Source face areas.
Definition: AMIMethod.H:92
TypeName("AMIMethod")
Runtime type information.
bool initialise(labelListList &srcAddress, scalarListList &srcWeights, labelListList &tgtAddress, scalarListList &tgtWeights, label &srcFacei, label &tgtFacei)
Initialise and return true if all ok.
Definition: AMIMethod.C:72
Macro definitions for declaring ClassName(), NamespaceName(), etc.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Macros to ease declaration of run-time selection tables.
const bool reverseTarget_
Flag to indicate that the two patches are co-directional and.
Definition: AMIMethod.H:85
Namespace for OpenFOAM.
void writeIntersectionOBJ(const scalar area, const face &f1, const face &f2, const pointField &f1Points, const pointField &f2Points) const
Write triangle intersection to OBJ file.
Definition: AMIMethod.C:147