cellCellStencilTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 
30 // * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
31 
32 template<class T>
34 (
35  Field<T>& psi,
36  const fvMesh& mesh,
37  const cellCellStencil& overlap,
38  const List<scalarList>& wghts
39 )
40 {
41  const labelListList& stencil = overlap.cellStencil();
42 
43  if (stencil.size() != mesh.nCells())
44  {
45  return;
46  }
47 
48  const mapDistribute& map = overlap.cellInterpolationMap();
49  const labelList& cellIDs = overlap.interpolationCells();
50  const scalarList& factor = overlap.cellInterpolationWeight();
51 
52  Field<T> work(psi);
53  map.mapDistributeBase::distribute(work, UPstream::msgType()+1);
54 
55  forAll(cellIDs, i)
56  {
57  const label celli = cellIDs[i];
58 
59  const scalarList& w = wghts[celli];
60  const labelList& nbrs = stencil[celli];
61  const scalar f = factor[celli];
62 
63  if (nbrs.size() == 0 && f != 0.0)
64  {
65  FatalErrorInFunction << "problem: cell:" << celli
66  << " at:" << mesh.cellCentres()[celli]
67  << " type:" << overlap.cellTypes()[celli]
68  << " stencil:" << nbrs
69  << " factor:" << f << exit(FatalError);
70  }
71 
73  forAll(nbrs, nbrI)
74  {
75  s += w[nbrI]*work[nbrs[nbrI]];
76  }
77 
78  psi[celli] = (1.0-f)*psi[celli] + f*s;
79  }
80 }
81 
82 
83 template<class T>
84 void Foam::cellCellStencil::interpolate(const fvMesh& mesh, Field<T>& psi) const
85 {
86  const cellCellStencil& overlap = *this;
87 
89  (
90  psi,
91  mesh,
94  );
95 }
96 
97 
98 template<class GeoField>
99 void Foam::cellCellStencil::interpolate(GeoField& psi) const
100 {
102  (
103  psi.mesh(),
105  );
107 }
108 
109 
110 template<class GeoField>
112 (
113  const fvMesh& mesh,
114  const wordHashSet& suppressed
115 ) const
116 {
117  const cellCellStencil& overlap = *this;
118 
119  for (const GeoField& field : mesh.thisDb().csorted<GeoField>())
120  {
121  const word& name = field.name();
122 
123  if (!suppressed.found(baseName(name)))
124  {
125  if (debug)
126  {
127  Pout<< "cellCellStencil::interpolate: interpolating : "
128  << name << endl;
129  }
130 
131  auto& fld = const_cast<GeoField&>(field);
132 
134  (
135  fld.primitiveFieldRef(),
136  mesh,
137  overlap,
139  );
140  }
141  else
142  {
143  if (debug)
144  {
145  Pout<< "cellCellStencil::interpolate: skipping : "
146  << name << endl;
147  }
148  }
149  }
150 }
151 
152 template<class Type>
155 (
156  const fvMesh& mesh,
157  const word& name,
158  const UList<Type>& psi
159 )
160 {
161  auto tfld = tmp<volScalarField>::New
162  (
163  IOobject
164  (
165  name,
166  mesh.time().timeName(),
167  mesh,
171  ),
172  mesh,
175  );
176  volScalarField& fld = tfld.ref();
177 
178  forAll(psi, cellI)
179  {
180  fld[cellI] = psi[cellI];
181  }
182  return tfld;
183 }
184 
185 
186 template<class GeoField, class SuppressBC>
188 (
189  GeoField& psi
190 )
191 {
192  // Version of GeoField::correctBoundaryConditions that exclude evaluation
193  // of oversetFvPatchFields
194 
195  typename GeoField::Boundary& bfld = psi.boundaryFieldRef();
196 
197  const label nReq = Pstream::nRequests();
198 
199  forAll(bfld, patchi)
200  {
201  if (!isA<SuppressBC>(bfld[patchi]))
202  {
203  bfld[patchi].initEvaluate(Pstream::commsTypes::nonBlocking);
204  }
205  }
206 
207  // Block for any outstanding requests
208  if (Pstream::parRun())
209  {
210  Pstream::waitRequests(nReq);
211  }
212 
213  forAll(bfld, patchi)
214  {
215  if (!isA<SuppressBC>(bfld[patchi]))
216  {
217  bfld[patchi].evaluate(Pstream::commsTypes::nonBlocking);
218  }
219  }
220 }
221 
222 
223 // ************************************************************************* //
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: fvPatchField.H:221
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
rDeltaTY field()
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
bool found(const Key &key) const
Same as contains()
Definition: HashTable.H:1354
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
UPtrList< const Type > csorted() const
Return sorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1229
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
static void interpolate(Field< T > &psi, const fvMesh &mesh, const cellCellStencil &overlap, const List< scalarList > &wghts)
Interpolation of acceptor cells from donor cells.
static void waitRequests()
Wait for all requests to finish.
Definition: UPstream.H:1538
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:376
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Calculation of interpolation stencils.
A class for handling words, derived from Foam::string.
Definition: word.H:63
const cellCellStencilObject & overlap
Definition: correctPhi.H:57
virtual const List< scalarList > & cellInterpolationWeights() const
Weights for cellStencil.
static tmp< volScalarField > createField(const fvMesh &mesh, const word &name, const UList< Type > &)
Helper: create volScalarField for postprocessing.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
const Mesh & mesh() const noexcept
Return mesh.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
int debug
Static debugging option.
labelList f(nPoints)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
Class containing processor-to-processor mapping information.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Nothing to be read.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
void correctBoundaryConditions()
Correct boundary field.
"nonBlocking" : (MPI_Isend, MPI_Irecv)
static void correctBoundaryConditions(GeoField &psi)
Version of correctBoundaryConditions that excludes &#39;overset&#39; bcs.
const volScalarField & psi
A class for managing temporary objects.
Definition: HashPtrTable.H:50
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
labelList cellIDs
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Do not request registration (bool: false)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127