CollidingCloud.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) 2011-2017 OpenFOAM Foundation
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 "CollidingCloud.H"
29 #include "CollisionModel.H"
30 #include "NoCollision.H"
31 
32 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
33 
34 template<class CloudType>
36 {
37  collisionModel_.reset
38  (
40  (
41  this->subModelProperties(),
42  *this
43  ).ptr()
44  );
45 }
46 
47 
48 template<class CloudType>
49 template<class TrackCloudType>
51 (
52  TrackCloudType& cloud,
53  typename parcelType::trackingData& td,
54  const scalar deltaT
55 )
56 {
57  td.part() = parcelType::trackingData::tpVelocityHalfStep;
58  CloudType::move(cloud, td, deltaT);
59 
60  td.part() = parcelType::trackingData::tpLinearTrack;
61  CloudType::move(cloud, td, deltaT);
62 
63  // td.part() = parcelType::trackingData::tpRotationalTrack;
64  // CloudType::move(cloud, td, deltaT);
65 
66  this->updateCellOccupancy();
67 
68  this->collision().collide();
69 
70  td.part() = parcelType::trackingData::tpVelocityHalfStep;
71  CloudType::move(cloud, td, deltaT);
72 }
73 
74 
75 
76 template<class CloudType>
78 {
79  CloudType::cloudReset(c);
80 
81  collisionModel_.reset(c.collisionModel_.ptr());
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
87 template<class CloudType>
89 (
90  const word& cloudName,
91  const volScalarField& rho,
92  const volVectorField& U,
93  const volScalarField& mu,
94  const dimensionedVector& g,
95  bool readFields
96 )
97 :
98  CloudType(cloudName, rho, U, mu, g, false),
99  constProps_(this->particleProperties()),
100  collisionModel_(nullptr)
101 {
102  if (this->solution().active())
103  {
104  setModels();
105 
106  if (readFields)
107  {
108  parcelType::readFields(*this);
109  this->deleteLostParticles();
110  }
111 
112  if
113  (
114  this->solution().steadyState()
115  && !isType<NoCollision<CollidingCloud<CloudType>>>(collisionModel_())
116  )
117  {
119  << "Collision modelling not currently available "
120  << "for steady state calculations" << exit(FatalError);
121  }
122  }
123 }
124 
125 
126 template<class CloudType>
128 (
129  CollidingCloud<CloudType>& c,
130  const word& name
131 )
132 :
134  collisionModel_(c.collisionModel_->clone())
135 {}
136 
137 
138 template<class CloudType>
140 (
141  const fvMesh& mesh,
142  const word& name,
144 )
145 :
146  CloudType(mesh, name, c),
147  collisionModel_(nullptr)
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
152 
153 template<class CloudType>
155 {}
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
160 template<class CloudType>
162 {
163  cloudCopyPtr_.reset
164  (
165  static_cast<CollidingCloud<CloudType>*>
166  (
167  clone(this->name() + "Copy").ptr()
168  )
169  );
170 }
171 
172 
173 template<class CloudType>
175 {
176  cloudReset(cloudCopyPtr_());
177  cloudCopyPtr_.clear();
178 }
179 
180 
181 template<class CloudType>
183 {
184  if (this->solution().canEvolve())
185  {
186  typename parcelType::trackingData td(*this);
187 
188  this->solve(*this, td);
189  }
190 }
191 
192 
193 template<class CloudType>
194 template<class TrackCloudType>
196 (
197  TrackCloudType& cloud,
198  typename parcelType::trackingData& td
199 )
200 {
201  // Sympletic leapfrog integration of particle forces:
202  // + apply half deltaV with stored force
203  // + move positions with new velocity
204  // + calculate forces in new position
205  // + apply half deltaV with new force
206 
207  label nSubCycles = collision().nSubCycles();
208 
209  if (nSubCycles > 1)
210  {
211  Log_<< " " << nSubCycles << " move-collide subCycles" << endl;
212 
213  subCycleTime moveCollideSubCycle
214  (
215  const_cast<Time&>(this->db().time()),
216  nSubCycles
217  );
218 
219  while(!(++moveCollideSubCycle).end())
220  {
221  moveCollide(cloud, td, this->db().time().deltaTValue());
222  }
223 
224  moveCollideSubCycle.endSubCycle();
225  }
226  else
227  {
228  moveCollide(cloud, td, this->db().time().deltaTValue());
229  }
230 }
231 
232 
233 template<class CloudType>
235 {
236  CloudType::info();
237 
238  scalar rotationalKineticEnergy = rotationalKineticEnergyOfSystem();
239  reduce(rotationalKineticEnergy, sumOp<scalar>());
240 
241  Log_<< " Rotational kinetic energy = "
242  << rotationalKineticEnergy << nl;
243 }
244 
245 
246 // ************************************************************************* //
void cloudReset(CollidingCloud< CloudType > &c)
Reset state of cloud.
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
void evolve()
Evolve the cloud.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
CEqn solve()
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
#define Log_
Report write to Foam::Info if the class log switch is true.
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
const word cloudName(propsDict.get< word >("cloud"))
A class for handling words, derived from Foam::string.
Definition: word.H:63
void motion(TrackCloudType &cloud, typename parcelType::trackingData &td)
Particle motion.
void moveCollide(TrackCloudType &cloud, typename parcelType::trackingData &td, const scalar deltaT)
Move-collide particles.
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:53
bool isType(const U &obj)
Check if typeid of the object and Type are identical.
Definition: typeInfo.H:99
Templated collision model class.
Adds coolisions to kinematic clouds.
const uniformDimensionedVectorField & g
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
Place holder for &#39;none&#39; option.
Definition: NoCollision.H:50
const dimensionedScalar mu
Atomic mass unit.
void restoreState()
Reset the current cloud to the previously stored state.
void info()
Print cloud information.
U
Definition: pEqn.H:72
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const dimensionedScalar c
Speed of light in a vacuum.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:92
void setModels()
Set cloud sub-models.
virtual ~CollidingCloud()
Destructor.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:67
void storeState()
Store the current cloud state.