SPH
GeometryJobs.cpp
Go to the documentation of this file.
2 #include "math/Functional.h"
3 #include "math/rng/VectorRng.h"
5 #include "post/MarchingCubes.h"
6 #include "post/MeshFile.h"
7 #include "run/IRun.h"
9 #include "system/Factory.h"
10 
12 
13 //-----------------------------------------------------------------------------------------------------------
14 // SphereJob
15 //-----------------------------------------------------------------------------------------------------------
16 
17 SphereJob::SphereJob(const std::string& name)
18  : IGeometryJob(name) {}
19 
20 std::string SphereJob::className() const {
21  return "sphere";
22 }
23 
25  return {};
26 }
27 
29  VirtualSettings connector;
30  addGenericCategory(connector, instName);
31  VirtualSettings::Category& geoCat = connector.addCategory("geometry");
32  geoCat.connect("Radius [km]", "radius", radius).setUnits(1.e3_f);
33  return connector;
34 }
35 
36 void SphereJob::evaluate(const RunSettings& UNUSED(global), IRunCallbacks& UNUSED(callbacks)) {
37  result = makeAuto<SphericalDomain>(Vector(0._f), radius);
38 }
39 
40 static JobRegistrar sRegisterSphere(
41  "sphere",
42  "geometry",
43  [](const std::string& name) { return makeAuto<SphereJob>(name); },
44  "Geometric shape representing a sphere with given radius.");
45 
46 //-----------------------------------------------------------------------------------------------------------
47 // BlockJob
48 //-----------------------------------------------------------------------------------------------------------
49 
51  VirtualSettings connector;
52  addGenericCategory(connector, instName);
53  VirtualSettings::Category& geoCat = connector.addCategory("geometry");
54  geoCat.connect("Center [km]", "center", center).setUnits(1.e3_f);
55  geoCat.connect("Dimensions [km]", "dimensions", dimensions).setUnits(1.e3_f);
56  return connector;
57 }
58 
59 void BlockJob::evaluate(const RunSettings& UNUSED(global), IRunCallbacks& UNUSED(callbacks)) {
60  result = makeAuto<BlockDomain>(center, dimensions);
61 }
62 
63 static JobRegistrar sRegisterBlock(
64  "block",
65  "geometry",
66  [](const std::string& name) { return makeAuto<BlockJob>(name); },
67  "Geometric shape representing a block with given dimensions.");
68 
69 //-----------------------------------------------------------------------------------------------------------
70 // EllipsoidJob
71 //-----------------------------------------------------------------------------------------------------------
72 
74  VirtualSettings connector;
75  addGenericCategory(connector, instName);
76  VirtualSettings::Category& geoCat = connector.addCategory("geometry");
77  geoCat.connect("Semi-axes [km]", "semixes", semiaxes).setUnits(1.e3_f);
78  return connector;
79 }
80 
81 void EllipsoidJob::evaluate(const RunSettings& UNUSED(global), IRunCallbacks& UNUSED(callbacks)) {
82  result = makeAuto<EllipsoidalDomain>(Vector(0._f), semiaxes);
83 }
84 
85 static JobRegistrar sRegisterEllipsoid(
86  "ellipsoid",
87  "geometry",
88  [](const std::string& name) { return makeAuto<EllipsoidJob>(name); },
89  "Geometric shape representing a triaxial ellipsoid.");
90 
91 //-----------------------------------------------------------------------------------------------------------
92 // CylinderJob
93 //-----------------------------------------------------------------------------------------------------------
94 
95 CylinderJob::CylinderJob(const std::string& name)
96  : IGeometryJob(name) {}
97 
98 std::string CylinderJob::className() const {
99  return "cylinder";
100 }
101 
103  return {};
104 }
105 
107  VirtualSettings connector;
108  addGenericCategory(connector, instName);
109  VirtualSettings::Category& geoCat = connector.addCategory("geometry");
110  geoCat.connect("Height [km]", "height", height).setUnits(1.e3_f);
111  geoCat.connect("Radius [km]", "radius", radius).setUnits(1.e3_f);
112  return connector;
113 }
114 
115 void CylinderJob::evaluate(const RunSettings& UNUSED(global), IRunCallbacks& UNUSED(callbacks)) {
116  result = makeAuto<CylindricalDomain>(Vector(0._f), radius, height, true);
117 }
118 
119 static JobRegistrar sRegisterCylinder(
120  "cylinder",
121  "geometry",
122  [](const std::string& name) { return makeAuto<CylinderJob>(name); },
123  "Geometric shape representing a cylinder aligned with z-axis, using provided radius and height.");
124 
125 
126 //-----------------------------------------------------------------------------------------------------------
127 // MaclaurinSpheroidJob
128 //-----------------------------------------------------------------------------------------------------------
129 
130 // Maclaurin formula (https://en.wikipedia.org/wiki/Maclaurin_spheroid)
131 static Float evalMaclaurinFormula(const Float e) {
132  return 2._f * sqrt(1._f - sqr(e)) / pow<3>(e) * (3._f - 2._f * sqr(e)) * asin(e) -
133  6._f / sqr(e) * (1._f - sqr(e));
134 }
135 
137  VirtualSettings connector;
138  addGenericCategory(connector, instName);
139  VirtualSettings::Category& geoCat = connector.addCategory("geometry");
140  geoCat.connect("Semi-major axis [km]", "semimajor", semimajorAxis).setUnits(1.e3_f);
141  geoCat.connect("Spin rate [rev/day]", "spinRate", spinRate).setUnits(2._f * PI / (3600._f * 24._f));
142  geoCat.connect("Density [kg/m^3]", "density", density);
143  return connector;
144 }
145 
147  const Float y = sqr(spinRate) / (PI * Constants::gravity * density);
148  const Float e_max = 0.812670_f; // for larger values, Jacobi ellipsoid should be used
149  const Optional<Float> e =
150  getRoot(Interval(0._f, e_max), EPS, [y](const Float e) { return evalMaclaurinFormula(e) - y; });
151  if (!e) {
152  throw InvalidSetup("Failed to calculate the eccentricity of Maclaurin spheroid");
153  }
154  const Float a = semimajorAxis;
155  const Float c = sqrt(1._f - sqr(e.value())) * a;
156  result = makeAuto<EllipsoidalDomain>(Vector(0._f), Vector(a, a, c));
157 }
158 
159 static JobRegistrar sRegisterMaclaurin(
160  "Maclaurin spheroid",
161  "spheroid",
162  "geometry",
163  [](const std::string& name) { return makeAuto<MaclaurinSpheroidJob>(name); },
164  "Creates a Maclaurin spheroid, given the density and the spin rate of the body.");
165 
166 //-----------------------------------------------------------------------------------------------------------
167 // HalfSpaceJob
168 //-----------------------------------------------------------------------------------------------------------
169 
171  VirtualSettings connector;
172  addGenericCategory(connector, instName);
173  return connector;
174 }
175 
176 void HalfSpaceJob::evaluate(const RunSettings& UNUSED(global), IRunCallbacks& UNUSED(callbacks)) {
177  result = makeAuto<HalfSpaceDomain>();
178 }
179 
180 static JobRegistrar sRegisterHalfSpace(
181  "half space",
182  "geometry",
183  [](const std::string& name) { return makeAuto<HalfSpaceJob>(name); },
184  "Represents a half space z>0. Note that this cannot be used as a domain for generating particles as the "
185  "volume of the domain is infinite. It can be used as an input to a composite domain (boolean, etc.) or "
186  "as a domain for boundary conditions of a simulation.");
187 
188 
189 //-----------------------------------------------------------------------------------------------------------
190 // GaussianSphereJob
191 //-----------------------------------------------------------------------------------------------------------
192 
194  VirtualSettings connector;
195  addGenericCategory(connector, instName);
196  VirtualSettings::Category& geoCat = connector.addCategory("geometry");
197  geoCat.connect("Radius [km]", "radius", radius).setUnits(1.e3_f);
198  geoCat.connect("Variance", "variance", beta);
199  geoCat.connect("Random seed", "seed", seed);
200  return connector;
201 }
202 
204  result = makeAuto<GaussianRandomSphere>(Vector(0._f), radius, beta, seed);
205 }
206 
207 static JobRegistrar sRegisterGaussian(
208  "Gaussian sphere",
209  "geometry",
210  [](const std::string& name) { return makeAuto<GaussianSphereJob>(name); },
211  "TODO");
212 
213 //-----------------------------------------------------------------------------------------------------------
214 // MeshGeometryJob
215 //-----------------------------------------------------------------------------------------------------------
216 
217 MeshGeometryJob::MeshGeometryJob(const std::string& name)
218  : IGeometryJob(name) {}
219 
220 std::string MeshGeometryJob::className() const {
221  return "triangle mesh";
222 }
223 
225  return {};
226 }
227 
229  VirtualSettings connector;
230  addGenericCategory(connector, instName);
231  VirtualSettings::Category& pathCat = connector.addCategory("Mesh source");
232  pathCat.connect("Path", "path", path)
234  .setFileFormats({
235  { "Wavefront OBJ file", "obj" },
236  { "Stanford PLY file", "ply" },
237  });
238  pathCat.connect("Scaling factor", "scale", scale);
239  pathCat.connect("Precompute", "precompute", precompute);
240  return connector;
241 }
242 
243 void MeshGeometryJob::evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) {
244  AutoPtr<IMeshFile> meshLoader = getMeshFile(path);
245  Expected<Array<Triangle>> triangles = meshLoader->load(path);
246  if (!triangles) {
247  throw InvalidSetup("cannot load " + path.native());
248  }
249 
250  SharedPtr<IScheduler> scheduler = Factory::getScheduler(global);
251  MeshParams params;
252  params.matrix = AffineMatrix::scale(Vector(scale));
253  params.precomputeInside = precompute;
254  result = makeAuto<MeshDomain>(*scheduler, std::move(triangles.value()), params);
255 }
256 
257 static JobRegistrar sRegisterMeshGeometry(
258  "triangle mesh",
259  "mesh",
260  "geometry",
261  [](const std::string& name) { return makeAuto<MeshGeometryJob>(name); },
262  "Geometric shape given by provided triangular mesh.");
263 
264 //-----------------------------------------------------------------------------------------------------------
265 // ParticleGeometryJob
266 //-----------------------------------------------------------------------------------------------------------
267 
269  VirtualSettings connector;
270  addGenericCategory(connector, instName);
271  VirtualSettings::Category& pathCat = connector.addCategory("Surface");
272  pathCat.connect("Spatial resolution [m]", "resolution", resolution);
273  pathCat.connect("Iso-surface value", "level", surfaceLevel);
274  return connector;
275 }
276 
277 void ParticleGeometryJob::evaluate(const RunSettings& global, IRunCallbacks& callbacks) {
278  Storage input = std::move(this->getInput<ParticleData>("particles")->storage);
279  // sanitize the resolution
280  const Box boundingBox = getBoundingBox(input);
281  const Float scale = maxElement(boundingBox.size());
282 
283  SharedPtr<IScheduler> scheduler = Factory::getScheduler(global);
284 
285  McConfig config;
286  config.gridResolution = clamp(resolution, 0.001_f * scale, 0.25_f * scale);
287  config.smoothingMult = smoothingMult;
288  config.surfaceLevel = surfaceLevel;
289  config.progressCallback = [&callbacks](const Float progress) {
290  Statistics stats;
291  stats.set(StatisticsId::RELATIVE_PROGRESS, progress);
292  callbacks.onTimeStep(Storage(), stats);
293  return !callbacks.shouldAbortRun();
294  };
295  Array<Triangle> triangles = getSurfaceMesh(*scheduler, input, config);
296  result = makeAuto<MeshDomain>(*scheduler, std::move(triangles));
297 }
298 
299 static JobRegistrar sRegisterParticleGeometry(
300  "particle geometry",
301  "particles",
302  "geometry",
303  [](const std::string& name) { return makeAuto<ParticleGeometryJob>(name); },
304  "Geometric shape represented by input particles");
305 
306 
307 //-----------------------------------------------------------------------------------------------------------
308 // SpheresGeometryJob
309 //-----------------------------------------------------------------------------------------------------------
310 
311 class SpheresDomain : public IDomain {
312 private:
313  Array<Sphere> spheres;
314  Box boundingBox;
315 
316 public:
318  spheres.resize(r.size());
319  for (Size i = 0; i < r.size(); ++i) {
320  spheres[i] = Sphere(r[i], r[i][H]);
321  boundingBox.extend(r[i] + Vector(r[i][H]));
322  boundingBox.extend(r[i] - Vector(r[i][H]));
323  }
324  }
325 
326  virtual Vector getCenter() const override {
327  return boundingBox.center();
328  }
329 
330  virtual Box getBoundingBox() const override {
331  return boundingBox;
332  }
333 
334  virtual Float getVolume() const override {
335  Float volume = 0._f;
336  for (const Sphere& s : spheres) {
337  volume += s.volume();
338  }
339  return volume;
340  }
341 
342  virtual Float getSurfaceArea() const override {
343  Float area = 0._f;
344  for (const Sphere& s : spheres) {
345  area += sphereSurfaceArea(s.radius());
346  }
347  return area;
348  }
349 
350  virtual bool contains(const Vector& v) const override {
351  if (!boundingBox.contains(v)) {
352  return false;
353  }
354  for (const Sphere& s : spheres) {
355  if (s.contains(v)) {
356  return true;
357  }
358  }
359  return false;
360  }
361 
362  virtual void getSubset(ArrayView<const Vector>, Array<Size>&, const SubsetType) const override {
364  }
365 
368  }
369 
370  virtual void project(ArrayView<Vector>, Optional<ArrayView<Size>>) const override {
372  }
373 
374  virtual void addGhosts(ArrayView<const Vector>, Array<Ghost>&, const Float, const Float) const override {
376  }
377 };
378 
380  VirtualSettings connector;
381  addGenericCategory(connector, instName);
382  return connector;
383 }
384 
386  SharedPtr<ParticleData> data = this->getInput<ParticleData>("spheres");
388  result = makeShared<SpheresDomain>(r);
389 }
390 
391 static JobRegistrar sRegisterSpheresGeometry(
392  "spheres geometry",
393  "spheres",
394  "geometry",
395  [](const std::string& name) { return makeAuto<SpheresGeometryJob>(name); },
396  "Geometric shape given by a set of spheres, specifies by the input particles.");
397 
398 //-----------------------------------------------------------------------------------------------------------
399 // InvertGeometryJob
400 //-----------------------------------------------------------------------------------------------------------
401 
402 class InvertDomain : public IDomain {
403 private:
404  SharedPtr<IDomain> domain;
405 
406 public:
408  : domain(domain) {}
409 
410  virtual Vector getCenter() const override {
411  return domain->getCenter();
412  }
413 
414  virtual Box getBoundingBox() const override {
415  return Box(Vector(-LARGE), Vector(LARGE));
416  }
417 
418  virtual Float getVolume() const override {
419  return LARGE;
420  }
421 
422  virtual Float getSurfaceArea() const override {
423  return domain->getSurfaceArea();
424  }
425 
426  virtual bool contains(const Vector& v) const override {
427  return !domain->contains(v);
428  }
429 
431  Array<Size>& output,
432  const SubsetType type) const override {
433  const SubsetType invertedType =
435  return domain->getSubset(vs, output, invertedType);
436  }
437 
438  virtual void getDistanceToBoundary(ArrayView<const Vector> vs, Array<Float>& distances) const override {
439  domain->getDistanceToBoundary(vs, distances);
440  for (Float& dist : distances) {
441  dist *= -1._f;
442  }
443  }
444 
445  virtual void project(ArrayView<Vector>, Optional<ArrayView<Size>>) const override {
447  }
448 
449  virtual void addGhosts(ArrayView<const Vector>, Array<Ghost>&, const Float, const Float) const override {
451  }
452 };
453 
455  VirtualSettings connector;
456  addGenericCategory(connector, instName);
457  return connector;
458 }
459 
461  SharedPtr<IDomain> domain = this->getInput<IDomain>("geometry");
462  result = makeShared<InvertDomain>(domain);
463 }
464 
465 static JobRegistrar sRegisterInvertGeometry(
466  "invert geometry",
467  "inverter",
468  "geometry",
469  [](const std::string& name) { return makeAuto<InvertGeometryJob>(name); },
470  "Shape modifier that inverts the geometry, i.e. swaps the outside and inside of a shape. This converts a "
471  "sphere into a space with spherical hole, etc.");
472 
473 //-----------------------------------------------------------------------------------------------------------
474 // TransformGeometryJob
475 //-----------------------------------------------------------------------------------------------------------
476 
477 
479  VirtualSettings connector;
480  addGenericCategory(connector, instName);
481 
482  VirtualSettings::Category& transformCat = connector.addCategory("Transform");
483  transformCat.connect("Scaling", "scaling", scaling);
484  transformCat.connect("Offset", "offset", offset);
485  return connector;
486 }
487 
489  SharedPtr<IDomain> domain = this->getInput<IDomain>("geometry");
490  const Vector center = domain->getCenter();
492  matrix.translate(-center);
493  matrix = AffineMatrix::scale(scaling) * matrix;
494  matrix.translate(center + offset);
495  result = makeShared<TransformedDomain>(domain, matrix);
496 }
497 
498 static JobRegistrar sRegisterTransformGeometry(
499  "transform geometry",
500  "transform",
501  "geometry",
502  [](const std::string& name) { return makeAuto<TransformGeometryJob>(name); },
503  "Shape modifier, adding a translation and scaling to the input geometry.");
504 
505 //-----------------------------------------------------------------------------------------------------------
506 // BooleanGeometryJob
507 //-----------------------------------------------------------------------------------------------------------
508 
509 class BooleanDomain : public IDomain {
510 private:
511  SharedPtr<IDomain> operA;
512  SharedPtr<IDomain> operB;
513  Vector offset;
514  BooleanEnum mode;
515 
516  Float volume;
517 
518 public:
520  SharedPtr<IDomain> operB,
521  const Vector& offset,
522  const BooleanEnum mode)
523  : operA(operA)
524  , operB(operB)
525  , offset(offset)
526  , mode(mode) {
527  // avoid integration for invalid bbox
528  const Box box = this->getBoundingBox();
529  if (box == Box::EMPTY()) {
530  volume = 0._f;
531  } else {
532  const Size N = 100000;
533  Size inside = 0;
535  for (Size i = 0; i < N; ++i) {
536  const Vector r = box.lower() + rng() * box.size();
537  inside += int(this->contains(r));
538  }
539  volume = box.volume() * Float(inside) / N;
540  }
541 
542  if (volume == 0._f) {
543  throw InvalidSetup("The boolean domain is empty.");
544  }
545  }
546 
547  virtual Vector getCenter() const override {
548  return this->getBoundingBox().center();
549  }
550 
551  virtual Box getBoundingBox() const override {
552  Box boxA = operA->getBoundingBox();
553  Box boxB = operB->getBoundingBox().translate(offset);
554  switch (mode) {
555  case BooleanEnum::UNION:
556  boxA.extend(boxB);
557  break;
559  boxA = boxA.intersect(boxB);
560  break;
562  break;
563  default:
565  }
566  return boxA;
567  }
568 
569  virtual Float getVolume() const override {
570  return volume;
571  }
572 
573  virtual Float getSurfaceArea() const override {
575  return 0._f;
576  }
577 
578  virtual bool contains(const Vector& v1) const override {
579  const Vector v2 = v1 - offset;
580  switch (mode) {
581  case BooleanEnum::UNION:
582  return operA->contains(v1) || operB->contains(v2);
584  return operA->contains(v1) && operB->contains(v2);
586  return operA->contains(v1) && !operB->contains(v2);
587  default:
589  }
590  }
591 
593  Array<Size>& output,
594  const SubsetType type) const override {
595  switch (type) {
596  case SubsetType::OUTSIDE:
597  for (Size i = 0; i < vs.size(); ++i) {
598  if (!this->contains(vs[i])) {
599  output.push(i);
600  }
601  }
602  break;
603  case SubsetType::INSIDE:
604  for (Size i = 0; i < vs.size(); ++i) {
605  if (this->contains(vs[i])) {
606  output.push(i);
607  }
608  }
609  }
610  }
611 
614  }
615 
616  virtual void project(ArrayView<Vector> vs, Optional<ArrayView<Size>> indices) const override {
617  if (mode != BooleanEnum::UNION) {
619  }
620 
622  operA->project(vs, indices);
623  operB->project(vs, indices);
624  }
625 
627  Array<Ghost>& ghosts,
628  const Float eta,
629  const Float eps) const override {
630  if (mode != BooleanEnum::UNION) {
632  }
633 
635  operA->addGhosts(vs, ghosts, eta, eps);
636  operB->addGhosts(vs, ghosts, eta, eps);
637  }
638 };
639 
641  SharedPtr<IDomain> operA = this->getInput<IDomain>("operand A");
642  SharedPtr<IDomain> operB = this->getInput<IDomain>("operand B");
643  result = makeAuto<BooleanDomain>(operA, operB, offset, BooleanEnum(mode.value));
644 }
645 
647  VirtualSettings connector;
648  addGenericCategory(connector, instName);
649 
650  VirtualSettings::Category& boolCat = connector.addCategory("Boolean");
651  boolCat.connect("Operation", "operation", mode);
652  boolCat.connect("Offset [km]", "offset", offset).setUnits(1.e3_f);
653 
654  return connector;
655 }
656 
657 static JobRegistrar sRegisterBoolean(
658  "boolean",
659  "geometry",
660  [](const std::string& name) { return makeAuto<BooleanGeometryJob>(name); },
661  "Composite shape that applies given boolean operation to two input shapes.");
662 
663 
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Definition: Assert.h:100
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
SubsetType
Definition: Domain.h:16
@ INSIDE
Marks all vectors inside of the domain.
@ OUTSIDE
Marks all vectors outside of the domain.
INLINE Optional< Float > getRoot(const Interval &range, const Float eps, const TFunctor &functor)
Returns a root of a R->R function on given range.
Definition: Functional.h:91
INLINE Float maxElement(const T &value)
Returns maximum element, simply the value iself by default.
Definition: Generic.h:29
BooleanEnum
Definition: GeometryJobs.h:247
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Basic interface defining a single run.
VirtualSettings::Category & addGenericCategory(VirtualSettings &connector, std::string &instanceName)
Adds a common settings category, used by all jobs.
Definition: Job.cpp:43
Array< Triangle > getSurfaceMesh(IScheduler &scheduler, const Storage &storage, const McConfig &config)
Returns the triangle mesh of the body surface (or surfaces of bodies).
constexpr INLINE T clamp(const T &f, const T &f1, const T &f2)
Definition: MathBasic.h:35
constexpr Float EPS
Definition: MathUtils.h:30
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
Definition: MathUtils.h:67
INLINE T sqrt(const T f)
Return a squared root of a value.
Definition: MathUtils.h:78
constexpr INLINE Float pow< 3 >(const Float v)
Definition: MathUtils.h:132
constexpr INLINE Float sphereSurfaceArea(const Float radius)
Computes a surface area of a sphere given its radius.
Definition: MathUtils.h:380
INLINE T asin(const T f)
Definition: MathUtils.h:311
constexpr Float PI
Mathematical constants.
Definition: MathUtils.h:361
constexpr Float LARGE
Definition: MathUtils.h:34
Domain represented by triangular mesh.
AutoPtr< IMeshFile > getMeshFile(const Path &path)
Deduces mesh type from extension of given path.
Definition: MeshFile.cpp:212
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
Object representing a three-dimensional sphere.
Box getBoundingBox(const Storage &storage, const Float radius)
Convenience function to get the bounding box of all particles.
Definition: Storage.cpp:832
constexpr int N
Objects for generating random vectors.
BasicVector< Float > Vector
Definition: Vector.h:539
@ H
Definition: Vector.h:25
static AffineMatrix identity()
Definition: AffineMatrix.h:132
static AffineMatrix scale(const Vector &scaling)
Definition: AffineMatrix.h:136
INLINE AffineMatrix & translate(const Vector &t)
Definition: AffineMatrix.h:58
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
INLINE TCounter size() const
Definition: ArrayView.h:101
void resize(const TCounter newSize)
Resizes the array to new size.
Definition: Array.h:215
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Definition: Array.h:306
Wrapper of pointer that deletes the resource from destructor.
Definition: AutoPtr.h:15
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
BooleanDomain(SharedPtr< IDomain > operA, SharedPtr< IDomain > operB, const Vector &offset, const BooleanEnum mode)
virtual void getDistanceToBoundary(ArrayView< const Vector >, Array< Float > &) const override
Returns distances of particles lying close to the boundary.
virtual Float getSurfaceArea() const override
Returns the surface area of the domain.
virtual void getSubset(ArrayView< const Vector > vs, Array< Size > &output, const SubsetType type) const override
Returns an array of indices, marking vectors with given property by their index.
virtual Box getBoundingBox() const override
Returns the bounding box of the domain.
virtual bool contains(const Vector &v1) const override
Checks if the given point lies inside the domain.
virtual Vector getCenter() const override
Returns the center of the domain.
virtual void project(ArrayView< Vector > vs, Optional< ArrayView< Size >> indices) const override
Projects vectors outside of the domain onto its boundary.
virtual Float getVolume() const override
Returns the total volume of the domain.
virtual void addGhosts(ArrayView< const Vector > vs, Array< Ghost > &ghosts, const Float eta, const Float eps) const override
Duplicates positions located close to the boundary, placing copies ("ghosts") symmetrically to the ot...
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
Helper object defining three-dimensional interval (box).
Definition: Box.h:17
INLINE Box translate(const Vector &offset) const
Returns a box with specified offset.
Definition: Box.h:134
INLINE void extend(const Vector &v)
Enlarges the box to contain the vector.
Definition: Box.h:49
INLINE const Vector & lower() const
Returns lower bounds of the box.
Definition: Box.h:82
INLINE Vector center() const
Returns the center of the box.
Definition: Box.h:112
INLINE bool contains(const Vector &v) const
Checks if the vector lies inside the box.
Definition: Box.h:66
INLINE Vector size() const
Returns box dimensions.
Definition: Box.h:106
INLINE Box intersect(const Box &other) const
Computes the intersection of this box with another one.
Definition: Box.h:155
INLINE Float volume() const
Returns the volume of the box.
Definition: Box.h:118
static Box EMPTY()
Syntactic sugar, returns a default-constructed (empty) box.
Definition: Box.h:41
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
CylinderJob(const std::string &name)
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
EntryControl & setPathType(const PathType &newType)
Sets the type of the path.
EntryControl & setUnits(const Float newMult)
Sets units in which the entry is stored.
EntryControl & setFileFormats(Array< FileFormat > &&formats)
Sets the allowed file formats.
Wrapper of type that either contains a value of given type, or an error message.
Definition: Expected.h:25
Type & value()
Returns the reference to expected value.
Definition: Expected.h:69
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
Base class for computational domains.
Definition: Domain.h:29
virtual Float getSurfaceArea() const =0
Returns the surface area of the domain.
virtual void getSubset(ArrayView< const Vector > vs, Array< Size > &output, const SubsetType type) const =0
Returns an array of indices, marking vectors with given property by their index.
virtual void getDistanceToBoundary(ArrayView< const Vector > vs, Array< Float > &distances) const =0
Returns distances of particles lying close to the boundary.
virtual Box getBoundingBox() const =0
Returns the bounding box of the domain.
virtual void project(ArrayView< Vector > vs, Optional< ArrayView< Size >> indices=NOTHING) const =0
Projects vectors outside of the domain onto its boundary.
virtual void addGhosts(ArrayView< const Vector > vs, Array< Ghost > &ghosts, const Float eta=2._f, const Float eps=0.05_f) const =0
Duplicates positions located close to the boundary, placing copies ("ghosts") symmetrically to the ot...
virtual bool contains(const Vector &v) const =0
Checks if the given point lies inside the domain.
virtual Vector getCenter() const =0
Returns the center of the domain.
Base class for jobs providing a geometric shape.
Definition: Job.h:284
SharedPtr< IDomain > result
Data filled by the job when it finishes.
Definition: Job.h:287
std::string instName
Definition: Job.h:100
Callbacks executed by the simulation to provide feedback to the user.
Definition: IRun.h:27
virtual bool shouldAbortRun() const =0
Returns whether current run should be aborted or not.
virtual void onTimeStep(const Storage &storage, Statistics &stats)=0
Called every timestep.
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Thrown when components of the run are mutually incompatible.
Definition: Exceptions.h:24
InvertDomain(SharedPtr< IDomain > domain)
virtual void getSubset(ArrayView< const Vector > vs, Array< Size > &output, const SubsetType type) const override
Returns an array of indices, marking vectors with given property by their index.
virtual void project(ArrayView< Vector >, Optional< ArrayView< Size >>) const override
Projects vectors outside of the domain onto its boundary.
virtual void addGhosts(ArrayView< const Vector >, Array< Ghost > &, const Float, const Float) const override
Duplicates positions located close to the boundary, placing copies ("ghosts") symmetrically to the ot...
virtual Box getBoundingBox() const override
Returns the bounding box of the domain.
virtual void getDistanceToBoundary(ArrayView< const Vector > vs, Array< Float > &distances) const override
Returns distances of particles lying close to the boundary.
virtual bool contains(const Vector &v) const override
Checks if the given point lies inside the domain.
virtual Float getSurfaceArea() const override
Returns the surface area of the domain.
virtual Vector getCenter() const override
Returns the center of the domain.
virtual Float getVolume() const override
Returns the total volume of the domain.
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
MeshGeometryJob(const std::string &name)
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
INLINE Type & value()
Returns the reference to the stored value.
Definition: Optional.h:172
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
std::string native() const
Returns the native version of the path.
Definition: Path.cpp:71
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
SphereJob(const std::string &name)
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
Definition: Sphere.h:18
virtual bool contains(const Vector &v) const override
Checks if the given point lies inside the domain.
SpheresDomain(ArrayView< const Vector > r)
virtual Float getSurfaceArea() const override
Returns the surface area of the domain.
virtual Float getVolume() const override
Returns the total volume of the domain.
virtual void project(ArrayView< Vector >, Optional< ArrayView< Size >>) const override
Projects vectors outside of the domain onto its boundary.
virtual void addGhosts(ArrayView< const Vector >, Array< Ghost > &, const Float, const Float) const override
Duplicates positions located close to the boundary, placing copies ("ghosts") symmetrically to the ot...
virtual Vector getCenter() const override
Returns the center of the domain.
virtual Box getBoundingBox() const override
Returns the bounding box of the domain.
virtual void getSubset(ArrayView< const Vector >, Array< Size > &, const SubsetType) const override
Returns an array of indices, marking vectors with given property by their index.
virtual void getDistanceToBoundary(ArrayView< const Vector >, Array< Float > &) const override
Returns distances of particles lying close to the boundary.
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
Object holding various statistics about current run.
Definition: Statistics.h:22
Statistics & set(const StatisticsId idx, TValue &&value)
Sets new values of a statistic.
Definition: Statistics.h:52
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
virtual void evaluate(const RunSettings &global, IRunCallbacks &callbacks) override
Runs the operation provided by the job.
Wrapper for generating random vectors.
Definition: VectorRng.h:18
EntryControl & connect(const std::string &name, const std::string &key, TValue &value)
Connects to given reference.
Holds a map of virtual entries, associated with a unique name.
Category & addCategory(const std::string &name)
Creates a new category of entries.
Creating code components based on values from settings.
constexpr Float gravity
Gravitational constant (CODATA 2014)
Definition: Constants.h:29
SharedPtr< IScheduler > getScheduler(const RunSettings &settings=RunSettings::getDefaults())
Definition: Factory.cpp:178
int value
Definition: Settings.h:38
Helper class, allowing to register job into the global list of jobs.
Definition: Job.h:203
Function< bool(Float progress)> progressCallback
Generic functor called during MC evaluation.
Float smoothingMult
Multiplier of the smoothing lengths.
Float gridResolution
Absolute size of each produced triangle.
Float surfaceLevel
bool precomputeInside
If true, cached volume is created to allow fast calls of contains.
Definition: MeshDomain.h:22
AffineMatrix matrix
Arbitrary transformation matrix applied on the mesh.
Definition: MeshDomain.h:19
Storage storage
Holds all particle positions and other quantities.
Definition: Job.h:35