PatchInteractionFields.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) 2020 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 
28 #include "PatchInteractionFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 template<class CloudType>
35 ({
36  { resetMode::none, "none" },
37  { resetMode::timeStep, "timeStep" },
38  { resetMode::writeTime, "writeTime" },
39 });
40 
41 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
42 
43 template<class CloudType>
45 (
46  autoPtr<volScalarField>& fieldPtr,
47  const word& fieldName,
48  const dimensionSet& dims
49 ) const
50 {
51  if (fieldPtr)
52  {
53  fieldPtr->primitiveFieldRef() = 0.0;
54  }
55  else
56  {
57  const fvMesh& mesh = this->owner().mesh();
58 
59  fieldPtr.reset
60  (
61  new volScalarField
62  (
63  IOobject
64  (
65  this->owner().name() + ":" + this->modelName() + ":" + fieldName,
66  mesh.time().timeName(),
67  mesh,
68  IOobject::READ_IF_PRESENT,
69  IOobject::NO_WRITE
70  ),
71  mesh,
72  dimensionedScalar(dims, Zero)
73  )
74  );
75  }
76 }
77 
78 
79 template<class CloudType>
81 {
82  clearOrReset(massPtr_, "mass", dimMass);
83  clearOrReset(countPtr_, "count", dimless);
84 }
85 
86 
87 template<class CloudType>
89 {
90  if (massPtr_)
91  {
92  massPtr_->write();
93  }
94  else
95  {
97  << "massPtr not valid" << abort(FatalError);
98  }
99 
100  if (countPtr_)
101  {
102  countPtr_->write();
103  }
104  else
105  {
107  << "countPtr not valid" << abort(FatalError);
108  }
109 
110  if (resetMode_ == resetMode::writeTime)
111  {
112  reset();
113  }
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118 
119 template<class CloudType>
121 (
122  const dictionary& dict,
123  CloudType& owner,
124  const word& modelName
125 )
126 :
127  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
128  massPtr_(nullptr),
129  countPtr_(nullptr),
130  resetMode_
131  (
132  resetModeNames_.getOrDefault
133  (
134  "resetMode",
135  this->coeffDict(),
137  )
138  )
139 {
140  reset();
141 }
142 
143 
144 template<class CloudType>
146 (
148 )
149 :
151  massPtr_(nullptr),
152  countPtr_(nullptr),
153  resetMode_(pii.resetMode_)
154 {}
155 
156 
157 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
158 
159 template<class CloudType>
161 (
162  const typename parcelType::trackingData&
163 )
164 {
165  if (resetMode_ == resetMode::timeStep)
166  {
167  reset();
168  }
169 }
170 
171 
172 template<class CloudType>
174 (
175  const parcelType& p,
176  const polyPatch& pp,
177  bool&
178 )
179 {
180  const label patchi = pp.index();
181  const label facei = pp.whichFace(p.face());
182 
183  massPtr_->boundaryFieldRef()[patchi][facei] += p.nParticle()*p.mass();
184  countPtr_->boundaryFieldRef()[patchi][facei] += 1;
185 }
186 
187 
188 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::PatchInteractionFields::PatchInteractionFields
PatchInteractionFields(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: PatchInteractionFields.C:121
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::dimensionSet
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:108
Foam::PatchInteractionFields
Creates volume fields whose boundaries are used to store patch interaction statistics.
Definition: PatchInteractionFields.H:76
Foam::PatchInteractionFields::preEvolve
virtual void preEvolve(const typename parcelType::trackingData &td)
Pre-evolve hook.
Definition: PatchInteractionFields.C:161
Foam::PatchInteractionFields::resetModeNames_
static const Enum< resetMode > resetModeNames_
Definition: PatchInteractionFields.H:92
Foam::PatchInteractionFields::postPatch
virtual void postPatch(const parcelType &p, const polyPatch &pp, bool &keepParticle)
Post-patch hook.
Definition: PatchInteractionFields.C:174
Foam::PatchInteractionFields::reset
void reset()
Create|read|reset the fields.
Definition: PatchInteractionFields.C:80
Foam::DSMCCloud::mesh
const fvMesh & mesh() const
Return reference to the mesh.
Definition: DSMCCloudI.H:44
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
PatchInteractionFields.H
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::dimMass
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:51
Foam::patchIdentifier::index
label index() const noexcept
The index of this patch in the boundaryMesh.
Definition: patchIdentifier.H:147
Foam::PatchInteractionFields::clearOrReset
void clearOrReset(autoPtr< volScalarField > &fieldPtr, const word &fieldName, const dimensionSet &dims) const
Helper function to clear or reset fields.
Definition: PatchInteractionFields.C:45
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::BitOps::none
bool none(const UList< bool > &bools)
True if no entries are 'true'.
Definition: BitOps.H:98
reset
meshPtr reset(new Foam::fvMesh(Foam::IOobject(regionName, runTime.timeName(), runTime, Foam::IOobject::MUST_READ), false))
Foam::autoPtr::reset
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:117
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::polyPatch::whichFace
label whichFace(const label l) const
Return label of face in patch from global face label.
Definition: polyPatch.H:448
Foam::CloudFunctionObject
Templated cloud function object base class.
Definition: CloudFunctionObject.H:62
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::PatchInteractionFields::write
virtual void write()
Write post-processing info.
Definition: PatchInteractionFields.C:88
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189