CGStaticBalanceSelfTest.cpp File Reference
#include "Mercury3D.h"
#include "StatisticsVector.h"
#include "Walls/InfiniteWall.h"
#include "CG/CG.h"
#include "CG/TimeSmoothedCG.h"
#include "CG/TimeAveragedCG.h"
#include "CG/Functions/Lucy.h"
#include "CG/Functions/Linear.h"
#include "CG/Functions/Heaviside.h"
#include "CG/Functions/Gauss.h"
#include <cmath>
#include <iostream>
#include <iomanip>
#include <Species/LinearViscoelasticSpecies.h>

Classes

class  CGStaticBalanceSelfTest
 Tests if the different CG templates work correctly. More...
 

Functions

void setCGHandler (DPMBase &problem)
 
void testCGHandler (DPMBase &problem)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)
322 {
323  //declare the DPM problem and set the name
324  CGStaticBalanceSelfTest problem;
325  problem.setName("CGStaticBalanceSelfTest");
326 
327  //problem is steady after t=0.6, see gnuplot:
328  //set logscale y; p 'CGStaticBalanceSelfTest.ene' u 1:3
329  setCGHandler(problem);
330 
331  //run the simulation
332  problem.solve(argc, argv);
333 
334  //problem is steady after t=0.6, see gnuplot:
335  //set logscale y; p 'CGStaticBalanceSelfTest.ene' u 1:3
336  testCGHandler(problem);
337 
338 }
void setCGHandler(DPMBase &problem)
Definition: CGStaticBalanceSelfTest.cpp:129
void testCGHandler(DPMBase &problem)
Definition: CGStaticBalanceSelfTest.cpp:281
Tests if the different CG templates work correctly.
Definition: CGStaticBalanceSelfTest.cpp:84
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:422
void solve()
The work horse of the code.
Definition: DPMBase.cc:4270

References setCGHandler(), DPMBase::setName(), DPMBase::solve(), and testCGHandler().

◆ setCGHandler()

void setCGHandler ( DPMBase problem)
130 {
131  //define the different coarse-graining objects
132 
133  //case 0: create global average rho(t)
135  cg0.statFile.setSaveCount(20);
136  cg0.statFile.setName(problem.getName() + ".LucyO.stat");
137  problem.cgHandler.copyAndAddObject(cg0);
138 
139 // TimeSmoothedCG<CGCoordinates::O> cg1;
140 // cg1.setWidthTime(0.01);
141 // cg1.setTimeStep(0.004);
142 // cg1.setTimeMax(0.2);
143 // cg1.statFile.setSaveCount(5);
144 // cg1.statFile.setName(problem.getName() + ".LucyO.TS.stat");
145 // problem.cgHandler.copyAndAddObject(cg1);
146 //
147 // TimeAveragedCG<CGCoordinates::O> cg2;
148 // cg2.setTimeMin(0.6);
149 // cg2.statFile.setSaveCount(50);
150 // cg2.statFile.setName(problem.getName() + ".LucyO.TA.stat");
151 // problem.cgHandler.copyAndAddObject(cg2);
152 //
154  cgB.setNZ(200);
155  cgB.setWidth(0.3);
156  cgB.statFile.setSaveCount(20000);
157  cgB.statFile.setName(problem.getName() + ".LucyZ.stat");
158  problem.cgHandler.copyAndAddObject(cgB);
159 //
160 // CG<CGFunctions::LinearZ> cgC;
161 // cgC.setNZ(200);
162 // cgC.setWidth(0.3);
163 // cgC.statFile.setSaveCount(20000);
164 // cgC.statFile.setName(problem.getName() + ".LinearZ.stat");
165 // problem.cgHandler.copyAndAddObject(cgC);
166 //
167 // CG<CGFunctions::HeavisideZ> cgD;
168 // cgD.setNZ(200);
169 // cgD.setWidth(0.3);
170 // cgD.statFile.setSaveCount(20000);
171 // cgD.statFile.setName(problem.getName() + ".HeavisideZ.stat");
172 // problem.cgHandler.copyAndAddObject(cgD);
173 //
174 // CG<CGFunctions::GaussZ> cgE;
175 // cgE.setNZ(200);
176 // cgE.setWidth(0.1);
177 // cgE.statFile.setSaveCount(20000);
178 // cgE.statFile.setName(problem.getName() + ".GaussZ.stat");
179 // problem.cgHandler.copyAndAddObject(cgE);
180 //
181 // CG<CGCoordinates::XZ> cgF;
182 // cgF.setNX(30);
183 // cgF.setNZ(30);
184 // cgF.setWidth(0.45);
185 // cgF.statFile.setSaveCount(20000);
186 // cgF.statFile.setName(problem.getName() + ".LucyXZ.stat");
187 // problem.cgHandler.copyAndAddObject(cgF);
188 //
189 // CG<CGFunctions::LinearXZ> cgG;
190 // cgG.setNX(30);
191 // cgG.setNZ(30);
192 // cgG.setWidth(0.45);
193 // cgG.statFile.setSaveCount(20000);
194 // cgG.statFile.setName(problem.getName() + ".LinearXZ.stat");
195 // problem.cgHandler.copyAndAddObject(cgG);
196 //
197 // CG<CGFunctions::HeavisideXZ> cgH;
198 // cgH.setNX(30);
199 // cgH.setNZ(30);
200 // cgH.setWidth(0.45);
201 // cgH.statFile.setSaveCount(20000);
202 // cgH.statFile.setName(problem.getName() + ".HeavisideXZ.stat");
203 // problem.cgHandler.copyAndAddObject(cgH);
204 //
205 // CG<CGFunctions::GaussXZ> cgI;
206 // cgI.setNX(30);
207 // cgI.setNZ(30);
208 // cgI.setWidth(0.15);
209 // cgI.statFile.setSaveCount(20000);
210 // cgI.statFile.setName(problem.getName() + ".GaussXZ.stat");
211 // problem.cgHandler.copyAndAddObject(cgI);
212 //
213 // CG<CGCoordinates::XYZ> cgJ;
214 // cgJ.setNX(10);
215 // cgJ.setNY(10);
216 // cgJ.setNZ(10);
217 // cgJ.setWidth(0.45);
218 // cgJ.statFile.setSaveCount(20000);
219 // cgJ.statFile.setName(problem.getName() + ".LucyXYZ.stat");
220 // problem.cgHandler.copyAndAddObject(cgJ);
221 //
222 // CG<CGFunctions::LinearXYZ> cgK;
223 // cgK.setNX(10);
224 // cgK.setNY(10);
225 // cgK.setNZ(10);
226 // cgK.setWidth(0.45);
227 // cgK.statFile.setSaveCount(20000);
228 // cgK.statFile.setName(problem.getName() + ".LinearXYZ.stat");
229 // problem.cgHandler.copyAndAddObject(cgK);
230 //
231 // CG<CGFunctions::HeavisideXYZ> cgL;
232 // cgL.setNX(10);
233 // cgL.setNY(10);
234 // cgL.setNZ(10);
235 // cgL.setWidth(0.45);
236 // cgL.statFile.setSaveCount(20000);
237 // cgL.statFile.setName(problem.getName() + ".HeavisideXYZ.stat");
238 // problem.cgHandler.copyAndAddObject(cgL);
239 //
240 // CG<CGFunctions::GaussXYZ> cgM;
241 // cgM.setNX(10);
242 // cgM.setNY(10);
243 // cgM.setNZ(10);
244 // cgM.setWidth(0.15);
245 // cgM.statFile.setSaveCount(20000);
246 // cgM.statFile.setName(problem.getName() + ".GaussXYZ.stat");
247 // problem.cgHandler.copyAndAddObject(cgM);
248 //
249 // CG<CGFunctions::GaussY> cg7;
250 // cg7.setNY(200);
251 // cg7.setWidth(0.15);
252 // cg7.statFile.setSaveCount(20000);
253 // cg7.statFile.setName(problem.getName() + ".GaussY.stat");
254 // problem.cgHandler.copyAndAddObject(cg7);
255 //
256 // CG<CGFunctions::GaussX> cg8;
257 // cg8.setNX(200);
258 // cg8.setWidth(0.15);
259 // cg8.statFile.setSaveCount(20000);
260 // cg8.statFile.setName(problem.getName() + ".GaussX.stat");
261 // problem.cgHandler.copyAndAddObject(cg8);
262 //
263 // CG<CGFunctions::GaussYZ> cg9;
264 // cg9.setNY(30);
265 // cg9.setNZ(30);
266 // cg9.setWidth(0.15);
267 // cg9.statFile.setSaveCount(20000);
268 // cg9.statFile.setName(problem.getName() + ".GaussYZ.stat");
269 // problem.cgHandler.copyAndAddObject(cg9);
270 //
271 // CG<CGFunctions::GaussXY> cgA;
272 // cgA.setNX(30);
273 // cgA.setNY(30);
274 // cgA.setWidth(0.15);
275 // cgA.statFile.setSaveCount(20000);
276 // cgA.statFile.setName(problem.getName() + ".GaussXY.stat");
277 // problem.cgHandler.copyAndAddObject(cgA);
278 
279 }
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:376
void setNZ(std::size_t nZ)
Sets nZ_, the number of spatial mesh points in the z-direction.
Definition: BaseCG.cc:102
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
Evaluates time-resolved continuum fields and writes the data into a stat file.
Definition: CG.h:76
void setWidth(Mdouble width) override
Definition: CG.h:220
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: DPMBase.cc:399
CGHandler cgHandler
Object of the class cgHandler.
Definition: DPMBase.h:1473
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:198
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_.
Definition: File.cc:273

References DPMBase::cgHandler, BaseHandler< T >::copyAndAddObject(), DPMBase::getName(), File::setName(), BaseCG::setNZ(), File::setSaveCount(), CG< Coordinates, BaseFunction, Fields >::setWidth(), and BaseCG::statFile.

Referenced by main().

◆ testCGHandler()

void testCGHandler ( DPMBase problem)
282 {
283  Mdouble totalMass;
284  Vec3D momentumBalance;
285 
286  logger(INFO, "Analysing #0: spatially averaged statistics rho(t) at t=1");
287  // cg0 stores the last available time step for analysis
288  CG<CGCoordinates::O>& cg0 =
289  *dynamic_cast<CG<CGCoordinates::O>*>(problem.cgHandler.getObject(0));
290  cg0.writeAll(std::cout);
291 
292  //check total mass
293  totalMass = cg0.getPoint(0).getDensity() - 0.8;
294  momentumBalance = cg0.getPoint(0).getInteractionForceDensity()
295  + cg0.getPoint(0).getDensity() * problem.getGravity();
296  logger(INFO, "Error in totalMass=%\n"
297  "Error in momentumBalance=%", totalMass, Vec3D::getLength(momentumBalance));
298 
299  //case B: z-statistics
300  CG<CGCoordinates::Z>& cgB =
301  *dynamic_cast<CG<CGCoordinates::Z>*>(problem.cgHandler.getObject(1));
302  cgB.writeAll(std::cout);
303  std::cout << std::endl;
304  totalMass = 0.0;
305  momentumBalance.setZero();
306  for (auto& p: cgB.getPoints())
307  {
308  logger(INFO, "z=%", p.coordinates.getZ());
309  totalMass += p.getDensity();
310  momentumBalance += p.getInteractionForceDensity()
311  + p.getDensity() * problem.getGravity();
312  }
313  totalMass = totalMass / cgB.getPoints().size() - 0.8;
314  momentumBalance /= cgB.getPoints().size();
315  logger(INFO, "Error in totalMass=%\n"
316  "Error in momentumBalance=%", totalMass, Vec3D::getLength(momentumBalance));
317 
318 
319 }
double Mdouble
Definition: GeneralDefine.h:34
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
Mdouble getDensity() const
Definition: StandardFields.h:161
Vec3D getInteractionForceDensity() const
Definition: StandardFields.h:181
const std::vector< Point > & getPoints() const
Definition: CG.h:187
const Point & getPoint(size_t i) const
Definition: CG.h:182
void writeAll(std::ostream &os) const
Writes class content, including the points_, into an output stream, usually a stat file.
Vec3D getGravity() const
Returns the gravitational acceleration.
Definition: DPMBase.cc:1391
Definition: Vector.h:51
void setZero()
Sets all elements to zero.
Definition: Vector.cc:43
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:320

References DPMBase::cgHandler, CGFields::StandardFields::getDensity(), DPMBase::getGravity(), CGFields::StandardFields::getInteractionForceDensity(), Vec3D::getLength(), BaseHandler< T >::getObject(), CG< Coordinates, BaseFunction, Fields >::getPoint(), CG< Coordinates, BaseFunction, Fields >::getPoints(), INFO, logger, Vec3D::setZero(), and CG< Coordinates, BaseFunction, Fields >::writeAll().

Referenced by main().