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-2019 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 
107 :
108  public faceAreaWeightAMI
109 {
110  // Private static data
111 
112  //- Minimum length of a cut as a ratio of the overall projected edge
113  // length
114  static const scalar minCutRatio_;
115 
116  //- Maximum allowable dot product between a source point normal and a
117  // target triangle
118  static const scalar maxDot_;
119 
120 
121  // Private classes
122 
123  //- A fixed list of tris which simulates a dynamic list by incrementing
124  // a counter whenever its append method is called. This is used as an
125  // optimisation so that the tri cutting does not allocate memory.
126  template<unsigned Size>
127  class cutTriList
128  :
129  public FixedList<FixedList<point, 3>, Size>
130  {
131  private:
132 
133  //- The number of stored elements
134  label n_;
135 
136 
137  public:
138 
139  //- Construct null
140  cutTriList()
141  :
142  n_(0)
143  {}
144 
145  //- Clear the array
146  void clear()
147  {
148  n_ = 0;
149  }
150 
151  //- Get the current size
152  label size() const
153  {
154  return n_;
155  }
156 
157  //- Add a new tet to the end of the array
158  void append(const FixedList<point, 3>& t)
159  {
160  this->operator[](n_) = t;
161  ++ n_;
162  }
163  };
164 
165 
166  // Private Member Functions
167 
168  // Debugging
169 
170  //- Write a VTK file of cut triangles
171  template<unsigned Size>
172  void writeCutTrisVTK
173  (
174  const cutTriList<Size>& tris,
175  const word& name
176  ) const;
177 
178  //- Write an OBJ file of a face
179  void writeFaceOBJ
180  (
181  const face& f,
182  const pointField& ps,
183  const string& name
184  ) const;
185 
186  //- Write an OBJ file of the source projection
187  void writeProjectionOBJ
188  (
189  const label srcN,
190  const FixedList<point, 4>& srcTri,
191  const FixedList<point, 4>& srcPrj
192  ) const;
193 
194 
195  //- Convert the source tris and normals to a projection. Most of the
196  // time this does nothing, but if some of the normals point in the
197  // reverse direction the projection will be reduced to span only the
198  // region in which the projection points forward through the target
199  // plane. Returns the number of edges in the projection (0, 3 or 4).
200  label getSourceProjection
201  (
202  FixedList<point, 4>& srcTri,
203  FixedList<point, 4>& srcNrm,
204  const FixedList<point, 3>& tgtTri
205  ) const;
206 
207  //- Get the cutting plane, for an edge of the source projection.
208  plane getCutPlane
209  (
210  const point& p0,
211  const point& p1,
212  const vector& n0,
213  const vector& n1,
214  const FixedList<point, 3>& tgtTri
215  ) const;
216 
217  //- The minimum weight below which connections are discarded
218  virtual scalar minWeight() const;
219 
220  //- The maximum edge angle that the walk will cross
221  virtual scalar maxWalkAngle() const;
222 
223 
224 
225 protected:
226 
227  // Protected Member Functions
228 
229  // Evaluation
230 
231  //- Area of intersection between source and target faces
232  virtual scalar interArea
233  (
234  const label srcFacei,
235  const label tgtFacei
236  ) const;
237 
238 
239 public:
240 
241  //- Runtime type information
242  TypeName("sweptFaceAreaWeightAMI");
243 
244 
245  // Constructors
246 
247  //- Use parent constructors
249 
250 
251  //- Destructor
252  virtual ~sweptFaceAreaWeightAMI();
253 };
254 
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 } // End namespace Foam
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 #endif
263 
264 // ************************************************************************* //
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.
faceAreaWeightAMI(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const scalarField &srcMagSf, const scalarField &tgtMagSf, const faceAreaIntersect::triangulationMode &triMode, const bool reverseTarget=false, const bool requireMatch=true, const bool restartUncoveredSourceFace=true)
Construct from components.
Namespace for OpenFOAM.
virtual ~sweptFaceAreaWeightAMI()
Destructor.