AMIMethod.H
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) 2013-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 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  //- The maximum edge angle that the walk will cross
156  virtual scalar maxWalkAngle() const;
157 
158 
159 public:
160 
161  //- Runtime type information
162  TypeName("AMIMethod");
163 
164  //- Declare runtime constructor selection table
166  (
167  autoPtr,
168  AMIMethod,
169  components,
170  (
171  const SourcePatch& srcPatch,
172  const TargetPatch& tgtPatch,
173  const scalarField& srcMagSf,
174  const scalarField& tgtMagSf,
176  const bool reverseTarget,
177  const bool requireMatch
178  ),
179  (
180  srcPatch,
181  tgtPatch,
182  srcMagSf,
183  tgtMagSf,
184  triMode,
185  reverseTarget,
186  requireMatch
187  )
188  );
189 
190  //- Construct from components
191  AMIMethod
192  (
193  const SourcePatch& srcPatch,
194  const TargetPatch& tgtPatch,
195  const scalarField& srcMagSf,
196  const scalarField& tgtMagSf,
198  const bool reverseTarget,
199  const bool requireMatch
200  );
201 
202  //- Selector
203  static autoPtr<AMIMethod> New
204  (
205  const word& methodName,
206  const SourcePatch& srcPatch,
207  const TargetPatch& tgtPatch,
208  const scalarField& srcMagSf,
209  const scalarField& tgtMagSf,
211  const bool reverseTarget,
212  const bool requireMatch
213  );
214 
215 
216  //- Destructor
217  virtual ~AMIMethod();
218 
219 
220  // Member Functions
221 
222  // Access
223 
224  //- Labels of faces that are not overlapped by any target faces
225  // Note: this should be empty for correct functioning
226  inline const labelList& srcNonOverlap() const;
227 
228  //- Flag to indicate that interpolation patches are conformal
229  virtual bool conformal() const;
230 
231 
232  // Manipulation
233 
234  //- Update addressing and weights
235  virtual void calculate
236  (
237  labelListList& srcAddress,
238  scalarListList& srcWeights,
239  labelListList& tgtAddress,
240  scalarListList& tgtWeights,
241  label srcFacei = -1,
242  label tgtFacei = -1
243  ) = 0;
244 };
245 
246 
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 
249 } // End namespace Foam
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 #define makeAMIMethod(AMIType) \
254  \
255  typedef AMIMethod<AMIType::sourcePatchType,AMIType::targetPatchType> \
256  AMIMethod##AMIType; \
257  \
258  defineNamedTemplateTypeNameAndDebug(AMIMethod##AMIType, 0); \
259  defineTemplateRunTimeSelectionTable(AMIMethod##AMIType, components);
260 
262 #define makeAMIMethodType(AMIType, Method) \
263  \
264  typedef Method<AMIType::sourcePatchType,AMIType::targetPatchType> \
265  Method##AMIType; \
266  \
267  defineNamedTemplateTypeNameAndDebug(Method##AMIType, 0); \
268  \
269  AMIMethod<AMIType::sourcePatchType,AMIType::targetPatchType>:: \
270  addcomponentsConstructorToTable<Method##AMIType> \
271  add##Method##AMIType##ConstructorToTable_;
272 
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #include "AMIMethodI.H"
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 #ifdef NoRepository
281  #include "AMIMethod.C"
282  #include "AMIMethodNew.C"
283 #endif
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 #endif
288 
289 // ************************************************************************* //
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:348
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:355
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.
virtual scalar maxWalkAngle() const
The maximum edge angle that the walk will cross.
Definition: AMIMethod.C:314
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