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-2026 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>
277 {
278  return const_iterator(*this, 0);
279 }
280 
281 
282 template<class Type>
285 {
286  return const_iterator(*this, f_.size());
287 }
288 
289 
290 template<class Type>
292 {
293  const label j = (j_ + 1) % size(i_);
294  const label i = i_ + (fValues_.below_ != separatedBelow && j == 0);
295  return i == fValues_.fCuts_.size() ? psi(0, 0) : psi(i, j);
296 }
297 
298 
299 template<class Type>
302 {
303  return const_iterator(*this, 0, 0);
304 }
305 
306 
307 template<class Type>
310 {
311  return const_iterator(*this, this->fCuts_.size(), 0);
312 }
313 
314 
315 template<class Type>
318 {
319  return const_iterator(*this, 0, 0);
320 }
321 
322 
323 template<class Type>
326 {
327  return const_iterator(*this, this->fCuts_.size(), 0);
328 }
329 
330 
331 template<class Type>
333 {
334  return psis_.second();
335 }
336 
337 
338 template<class Type>
341 {
342  return const_iterator(*this, 0, 0);
343 }
344 
345 
346 template<class Type>
349 {
350  return const_iterator(*this, this->cCuts_.size(), 0);
351 }
352 
353 
354 template<class Type>
357 {
358  return const_iterator(*this, 0, 0);
359 }
360 
361 
362 template<class Type>
365 {
366  return const_iterator(*this, this->cCuts_.size(), 0);
367 }
368 
369 
370 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
371 
372 template<class Type>
374 (
375  const const_iterator& it
376 ) const
377 {
378  return it.i_ == i_;
379 }
380 
381 
382 template<class Type>
384 (
385  const const_iterator& it
386 ) const
387 {
388  return !(it == *this);
389 }
390 
391 
392 template<class Type>
394 {
395  return fValues_.pPsis_[fValues_.f_[i_]];
396 }
397 
398 
399 template<class Type>
402 {
403  ++ i_;
404  return *this;
405 }
406 
407 
408 template<class Type>
411 {
412  const const_iterator it(*this);
413  ++ *this;
414  return it;
415 }
416 
417 
418 template<class Type>
420 (
421  const const_iterator& it
422 ) const
423 {
424  return it.i_ == i_ && it.j_ == j_;
425 }
426 
427 
428 template<class Type>
430 (
431  const const_iterator& it
432 ) const
433 {
434  return !(it == *this);
435 }
436 
437 
438 template<class Type>
440 {
441  return psi(i_, j_);
442 }
443 
444 
445 template<class Type>
448 {
449  j_ = (j_ + 1) % size(i_);
450  i_ += j_ == 0;
451  return *this;
452 }
453 
454 
455 template<class Type>
458 {
459  const const_iterator it(*this);
460  ++ *this;
461  return it;
462 }
463 
464 
465 template<class Type>
467 (
468  const const_iterator& it
469 ) const
470 {
471  return it.i_ == i_ && it.j_ == j_;
472 }
473 
474 template<class Type>
476 (
477  const const_iterator& it
478 ) const
479 {
480  return !(it == *this);
481 }
482 
483 
484 template<class Type>
485 const Type&
487 {
488  return psis_.first();
489 }
490 
491 
492 template<class Type>
495 {
496  ++ j_;
497 
498  if (j_ == cValues_.cCuts_[i_].size())
499  {
500  j_ = 0;
501  ++ i_;
502  psis_.first() = psi(i_, j_);
503  }
504  else
505  {
506  psis_.first() = psis_.second();
507  }
508 
509  psis_.second() = psi(i_, j_ + 1);
510 
511  return *this;
512 }
513 
514 
515 template<class Type>
518 {
519  const const_iterator it(*this);
520  ++ *this;
521  return it;
522 }
523 
524 
525 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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:67
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 cbegin() const
Get the beginning of the iteration over the values.
const_iterator end() const
Get the end of the iteration over the values.
const_iterator cend() 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 cend() const
Get the end of the iteration over the values.
const_iterator end() const
Get the end of the iteration over the values.
const_iterator cbegin() const
Get the beginning 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.
const_iterator cbegin() const
Get the beginning of the iteration over the values.
const_iterator cend() 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
Motion of the mesh specified as a list of pointMeshMovers.
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)