All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sweptFaceAreaWeightAMI.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) 2017-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::sweptFaceAreaWeightAMI
26 
27 Description
28  Swept face area weighted Arbitrary Mesh Interface (AMI) method
29 
30  This method uses the point normals of the source patch to sweep the source
31  faces over the target patches. This creates a projection which fills space,
32  and which therefore generates overlap areas which are consistent between
33  neighbouring faces. The projection of a source edge is shown below:
34  \verbatim
35  /
36  /
37  n_1 ^
38  /
39  /
40  p_1 o
41  \\
42  \\ ^ u
43  \\ \
44  \\ + - > v
45  \\
46  o - - - > - - -
47  p_0 n_0
48  \endverbatim
49 
50  The surface is, in general, not flat. Any deviation between the two end
51  normals generates expansion, contraction, and twist in the surface. The
52  surface connects with surfaces emanating from connected edges along the end
53  normals. This is what makes the projection fill space and generate
54  consistent overlaps between neighbouring faces.
55 
56  The projected surface is parameterised by the local coordinates, \f$u\f$
57  and \f$v\f$, and a position on this plane is calculated from \f$u\f$ and
58  \f$v\f$ as follows:
59  \f[
60  x(u, v) = p_0 + (p_1 - p_0) u + [ q_0 + (q_1 - q_0) u ] v
61  \f]
62 
63  To calculate an intersection with a line between points \f$l_0\f$ to
64  \f$l_1\f$, we define a local coordinate, \f$w\f$, along the line, and
65  subtract it's equation from that of the surface:
66  \f[
67  0 = (p_0 - l_0) - (l_1 - l_0) w + (p_1 - p_0) u +
68  [ q_0 + (q_1 - q_0) u ] v
69  \f]
70 
71  This is a system of three equations in three unknowns. It is non-linear,
72  courtesy of the \f$u v\f$ term at the end. It can be reduced to a single
73  quadratic in any of the three variables. We choose to solve for \f$u\f$ by
74  taking the dot product of the above equation with the following vector:
75  \f[
76  (l_1 - l_0) \times [ q_0 + (q_1 - q_0) u ]
77  \f]
78 
79  The sign of the intersection (i.e., whether the line crosses from below the
80  surface to above or vice versa) can be determined by taking the dot product
81  of the line vector with the surface normal at the intersection. The surface
82  normal is as follows:
83  \f[
84  n(u, v) = (p_1 - p_0) \times [q_0 + (q_1 - q_0) u] + (q_1 \times q_0) v
85  \f]
86 
87 SourceFiles
88  sweptFaceAreaWeightAMI.C
89 
90 \*---------------------------------------------------------------------------*/
91 
92 #ifndef sweptFaceAreaWeightAMI_H
93 #define sweptFaceAreaWeightAMI_H
94 
95 #include "faceAreaWeightAMI.H"
96 
97 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
98 
99 namespace Foam
100 {
101 
102 /*---------------------------------------------------------------------------*\
103  Class sweptFaceAreaWeightAMI Declaration
104 \*---------------------------------------------------------------------------*/
105 
106 template<class SourcePatch, class TargetPatch>
108 :
109  public faceAreaWeightAMI<SourcePatch, TargetPatch>
110 {
111 private:
112 
113  // Private static data
114 
115  //- Minimum length of a cut as a ratio of the overall projected edge
116  // length
117  static const scalar minCutRatio_;
118 
119  //- Maximum allowable dot product between a source point normal and a
120  // target triangle
121  static const scalar maxDot_;
122 
123 
124  // Private classes
125 
126  //- A fixed list of tris which simulates a dynamic list by incrementing
127  // a counter whenever its append method is called. This is used as an
128  // optimisation so that the tri cutting does not allocate memory.
129  template<unsigned Size>
130  class cutTriList
131  :
132  public FixedList<FixedList<point, 3>, Size>
133  {
134  private:
135 
136  //- The number of stored elements
137  label n_;
138 
139 
140  public:
141 
142  //- Construct null
143  cutTriList()
144  :
145  n_(0)
146  {}
147 
148  //- Clear the array
149  void clear()
150  {
151  n_ = 0;
152  }
153 
154  //- Get the current size
155  label size() const
156  {
157  return n_;
158  }
159 
160  //- Add a new tet to the end of the array
161  void append(const FixedList<point, 3>& t)
162  {
163  this->operator[](n_) = t;
164  ++ n_;
165  }
166  };
167 
168 
169  // Private member functions
170 
171  // Debugging
172 
173  //- Write a VTK file of cut triangles
174  template<unsigned Size>
175  void writeCutTrisVTK
176  (
177  const cutTriList<Size>& tris,
178  const word& name
179  ) const;
180 
181  //- Write an OBJ file of a face
182  void writeFaceOBJ
183  (
184  const face& f,
185  const pointField& ps,
186  const string& name
187  ) const;
188 
189  //- Write an OBJ file of the source projection
190  void writeProjectionOBJ
191  (
192  const label srcN,
193  const FixedList<point, 4>& srcTri,
194  const FixedList<point, 4>& srcPrj
195  ) const;
196 
197 
198  //- Convert the source tris and normals to a projection. Most of the
199  // time this does nothing, but if some of the normals point in the
200  // reverse direction the projection will be reduced to span only the
201  // region in which the projection points forward through the target
202  // plane. Returns the number of edges in the projection (0, 3 or 4).
203  label getSourceProjection
204  (
205  FixedList<point, 4>& srcTri,
206  FixedList<point, 4>& srcNrm,
207  const FixedList<point, 3>& tgtTri
208  ) const;
209 
210  //- Get the cutting plane, for an edge of the source projection.
211  plane getCutPlane
212  (
213  const point& p0,
214  const point& p1,
215  const vector& n0,
216  const vector& n1,
217  const FixedList<point, 3>& tgtTri
218  ) const;
219 
220  //- The minimum weight below which connections are discarded
221  virtual scalar minWeight() const;
222 
223  //- The maximum edge angle that the walk will cross
224  virtual scalar maxWalkAngle() const;
225 
226 
227 
228 protected:
229 
230  // Protected Member Functions
231 
232  // Evaluation
233 
234  //- Area of intersection between source and target faces
235  virtual scalar interArea
236  (
237  const label srcFacei,
238  const label tgtFacei
239  ) const;
240 
241 
242 public:
243 
244  //- Runtime type information
245  TypeName("sweptFaceAreaWeightAMI");
246 
247 
248  // Constructors
249 
250  //- Use parent constructors
252 
253 
254  //- Destructor
255  virtual ~sweptFaceAreaWeightAMI();
256 };
257 
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 } // End namespace Foam
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 #ifdef NoRepository
266  #include "sweptFaceAreaWeightAMI.C"
267 #endif
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #endif
272 
273 // ************************************************************************* //
Swept face area weighted Arbitrary Mesh Interface (AMI) method.
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 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:54
tUEqn clear()
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Face area weighted Arbitrary Mesh Interface (AMI) method.
A class for handling words, derived from string.
Definition: word.H:59
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
TypeName("sweptFaceAreaWeightAMI")
Runtime type information.
labelList f(nPoints)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
virtual scalar interArea(const label srcFacei, const label tgtFacei) const
Area of intersection between source and target faces.
Namespace for OpenFOAM.
virtual ~sweptFaceAreaWeightAMI()
Destructor.