cutPolyValueTemplates.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) 2022-2025 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 
26 #include "cutPolyValue.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const edge& e,
34  const scalar lambda,
35  const Field<Type>& pPsis
36 )
37 {
38  return (1 - lambda)*pPsis[e[0]] + lambda*pPsis[e[1]];
39 }
40 
41 
42 template<class Type>
44 (
45  const edge& e,
46  const scalarField& pAlphas,
47  const scalar isoAlpha,
48  const Field<Type>& pPsis
49 )
50 {
51  return edgeCutValue(e, edgeCutLambda(e, pAlphas, isoAlpha), pPsis);
52 }
53 
54 
55 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
56 
57 template<class Type>
58 const Foam::Pair<Type>&
60 {
61  if (i != iAndCutPsis_.first())
62  {
63  const face& f = fValues_.f_;
64  const labelPair& fCut = fValues_.fCuts_[i];
65 
66  iAndCutPsis_.first() = i;
67 
68  forAll(iAndCutPsis_.second(), j)
69  {
70  iAndCutPsis_.second()[j] =
72  (
73  f.faceEdge(fCut[j]),
74  fValues_.pAlphas_,
75  fValues_.isoAlpha_,
76  fValues_.pPsis_
77  );
78  }
79  }
80 
81  return iAndCutPsis_.second();
82 }
83 
84 
85 template<class Type>
88 {
89  const face& f = fValues_.f_;
90  const List<labelPair>& fCuts = fValues_.fCuts_;
91  const labelPair& fCut0 = fCuts[i];
92  const labelPair& fCut1 = fCuts[(i + 1) % fCuts.size()];
93 
94  const label dfCut =
95  fValues_.below_ == separatedBelow
96  ? fCut0[1] - fCut0[0]
97  : fCut1[0] - fCut0[1];
98 
99  return 2 + ((dfCut + f.size()) % f.size());
100 }
101 
102 
103 template<class Type>
105 (
106  const label i,
107  const label j
108 ) const
109 {
110  const face& f = fValues_.f_;
111  const labelPair& fCut = fValues_.fCuts_[i];
112 
113  if (j < 2)
114  {
115  const label fCutj = fValues_.below_ == separatedBelow ? 1 - j : j;
116  return cutPsis(i)[fCutj];
117  }
118  else
119  {
120  const label fCutj = fValues_.below_ == separatedBelow ? 0 : 1;
121  return fValues_.pPsis_[f[(j - 2 + fCut[fCutj] + 1) % f.size()]];
122  }
123 }
124 
125 
126 template<class Type>
128 (
129  const label i,
130  const label j
131 )
132 {
133  const label iStar = i % cValues_.cCuts_.size();
134  const label jStar = j % cValues_.cCuts_[iStar].size();
135 
136  const label cei = cValues_.cCuts_[iStar][jStar];
137  const label cfi = cValues_.cAddr_.ceiToCfiAndFei()[cei][0][0];
138  const label fei = cValues_.cAddr_.ceiToCfiAndFei()[cei][0][1];
139 
140  return
142  (
143  cValues_.fs_[cValues_.c_[cfi]].faceEdge(fei),
144  cValues_.pAlphas_,
145  cValues_.isoAlpha_,
146  cValues_.pPsis_
147  );
148 }
149 
150 
151 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
152 
153 template<class Type>
155 (
156  const FaceValues<Type>& fValues,
157  const label i
158 )
159 :
160  fValues_(fValues),
161  i_(i)
162 {}
163 
164 
165 template<class Type>
167 (
168  const face& f,
169  const Field<Type>& pPsis
170 )
171 :
172  f_(f),
173  pPsis_(pPsis)
174 {}
175 
176 
177 template<class Type>
179 (
180  const FaceCutValues<Type>& fValues,
181  const label i,
182  const label j
183 )
184 :
185  fValues_(fValues),
186  i_(i),
187  j_(j),
188  iAndCutPsis_(-1, Pair<Type>(Zero, Zero))
189 {}
190 
191 
192 template<class Type>
194 (
195  const face& f,
196  const List<labelPair>& fCuts,
197  const Field<Type>& pPsis,
198  const scalarField& pAlphas,
199  const scalar isoAlpha,
200  const bool below
201 )
202 :
203  f_(f),
204  fCuts_(fCuts),
205  pPsis_(pPsis),
206  pAlphas_(pAlphas),
207  isoAlpha_(isoAlpha),
208  below_(below)
209 {}
210 
211 
212 template<class Type>
214 (
215  const CellCutValues<Type>& cValues,
216  const label i,
217  const label j
218 )
219 :
220  cValues_(cValues),
221  i_(i),
222  j_(j),
223  psis_(psi(i, j), psi(i, j + 1))
224 {}
225 
226 
227 template<class Type>
229 (
230  const cell& c,
231  const cellEdgeAddressing& cAddr,
232  const labelListList& cCuts,
233  const faceList& fs,
234  const Field<Type>& pPsis,
235  const scalarField& pAlphas,
236  const scalar isoAlpha
237 )
238 :
239  c_(c),
240  cAddr_(cAddr),
241  cCuts_(cCuts),
242  fs_(fs),
243  pPsis_(pPsis),
244  pAlphas_(pAlphas),
245  isoAlpha_(isoAlpha)
246 {}
247 
248 
249 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
250 
251 template<class Type>
253 {
254  return fValues_.pPsis_[fValues_.f_[(i_ + 1) % fValues_.f_.size()]];
255 }
256 
257 
258 template<class Type>
261 {
262  return const_iterator(*this, 0);
263 }
264 
265 
266 template<class Type>
269 {
270  return const_iterator(*this, f_.size());
271 }
272 
273 
274 template<class Type>
276 {
277  const label j = (j_ + 1) % size(i_);
278  const label i = i_ + (fValues_.below_ != separatedBelow && j == 0);
279  return i == fValues_.fCuts_.size() ? psi(0, 0) : psi(i, j);
280 }
281 
282 
283 template<class Type>
286 {
287  return const_iterator(*this, 0, 0);
288 }
289 
290 
291 template<class Type>
294 {
295  return const_iterator(*this, this->fCuts_.size(), 0);
296 }
297 
298 
299 template<class Type>
301 {
302  return psis_.second();
303 }
304 
305 
306 template<class Type>
309 {
310  return const_iterator(*this, 0, 0);
311 }
312 
313 
314 template<class Type>
317 {
318  return const_iterator(*this, this->cCuts_.size(), 0);
319 }
320 
321 
322 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
323 
324 template<class Type>
326 (
327  const const_iterator& it
328 ) const
329 {
330  return it.i_ == i_;
331 }
332 
333 
334 template<class Type>
336 (
337  const const_iterator& it
338 ) const
339 {
340  return !(it == *this);
341 }
342 
343 
344 template<class Type>
346 {
347  return fValues_.pPsis_[fValues_.f_[i_]];
348 }
349 
350 
351 template<class Type>
354 {
355  ++ i_;
356  return *this;
357 }
358 
359 
360 template<class Type>
363 {
364  const const_iterator it(*this);
365  ++ *this;
366  return it;
367 }
368 
369 
370 template<class Type>
372 (
373  const const_iterator& it
374 ) const
375 {
376  return it.i_ == i_ && it.j_ == j_;
377 }
378 
379 
380 template<class Type>
382 (
383  const const_iterator& it
384 ) const
385 {
386  return !(it == *this);
387 }
388 
389 
390 template<class Type>
392 {
393  return psi(i_, j_);
394 }
395 
396 
397 template<class Type>
400 {
401  j_ = (j_ + 1) % size(i_);
402  i_ += j_ == 0;
403  return *this;
404 }
405 
406 
407 template<class Type>
410 {
411  const const_iterator it(*this);
412  ++ *this;
413  return it;
414 }
415 
416 
417 template<class Type>
419 (
420  const const_iterator& it
421 ) const
422 {
423  return it.i_ == i_ && it.j_ == j_;
424 }
425 
426 template<class Type>
428 (
429  const const_iterator& it
430 ) const
431 {
432  return !(it == *this);
433 }
434 
435 
436 template<class Type>
437 const Type&
439 {
440  return psis_.first();
441 }
442 
443 
444 template<class Type>
447 {
448  ++ j_;
449 
450  if (j_ == cValues_.cCuts_[i_].size())
451  {
452  j_ = 0;
453  ++ i_;
454  psis_.first() = psi(i_, j_);
455  }
456  else
457  {
458  psis_.first() = psis_.second();
459  }
460 
461  psis_.second() = psi(i_, j_ + 1);
462 
463  return *this;
464 }
465 
466 
467 template<class Type>
470 {
471  const const_iterator it(*this);
472  ++ *this;
473  return it;
474 }
475 
476 
477 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Pre-declare SubField and related Field type.
Definition: Field.H:83
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An ordered pair of two objects of type <Type> with first() and second() elements.
Definition: Pair.H:66
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:60
const Type & next() const
Get the next value around the loop.
const_iterator(const CellCutValues< Type > &cValues, const label i, const label j)
Construct from components.
const_iterator begin() const
Get the beginning of the iteration over the values.
const_iterator end() const
Get the end of the iteration over the values.
CellCutValues(const cell &c, const cellEdgeAddressing &cAddr, const labelListList &cCuts, const faceList &fs, const Field< Type > &pPsis, const scalarField &pAlphas, const scalar isoAlpha)
Construct from components.
const_iterator(const FaceCutValues< Type > &fValues, const label i, const label j)
Construct from components.
Type next() const
Get the next value around the sub-face.
const_iterator end() const
Get the end of the iteration over the values.
const_iterator begin() const
Get the beginning of the iteration over the values.
FaceCutValues(const face &f, const List< labelPair > &fCuts, const Field< Type > &pPsis, const scalarField &pAlphas, const scalar isoAlpha, const bool below)
Construct from components.
const_iterator(const FaceValues< Type > &fValues, const label i)
Construct from components.
Type next() const
Get the next value around the sub-face.
const_iterator begin() const
Get the beginning of the iteration over the values.
const_iterator end() const
Get the end of the iteration over the values.
FaceValues(const face &f, const Field< Type > &pPsis)
Construct from components.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
const volScalarField & psi
dimensionedScalar lambda(viscosity->lookup("lambda"))
const dimensionedScalar e
Elementary charge.
const dimensionedScalar c
Speed of light in a vacuum.
scalar edgeCutLambda(const edge &e, const scalarField &pAlphas, const scalar isoAlpha)
Get the local coordinate within an edge, given end point values and an.
Definition: cutPolyValueI.H:31
Type edgeCutValue(const edge &e, const scalar lambda, const Field< Type > &pPsis)
Linearly interpolate a value from the end points to the cut point of an.
static const bool separatedBelow
This flag determines which side of the iso-surface is separated into.
Definition: cutPoly.H:65
static const zero Zero
Definition: zero.H:97
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
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
labelList f(nPoints)