SPH
ElasticBands.cpp
Go to the documentation of this file.
1 
6 #include "Common.h"
7 #include "catch.hpp"
8 
9 using namespace Sph;
10 
11 class ElasticBands : public IRun {
12 public:
14  settings.set(RunSettingsId::RUN_NAME, std::string("Colliding Elastic Bands Problem"))
20  .set(RunSettingsId::RUN_OUTPUT_PATH, std::string("elastic_bands"))
21  .set(RunSettingsId::RUN_OUTPUT_NAME, std::string("bands_%d.ssf"))
22  .set(RunSettingsId::RUN_END_TIME, 4.e-3_f)
30  .set(RunSettingsId::SPH_AV_ALPHA, 1.5_f)
31  .set(RunSettingsId::SPH_AV_BETA, 3._f)
39 
40  scheduler = Factory::getScheduler(settings);
41  }
42 
43  class SubtractDomain : public IDomain {
44  private:
45  IDomain& primary;
46  IDomain& subtracted;
47 
48  public:
49  SubtractDomain(IDomain& primary, IDomain& subtracted)
50  : primary(primary)
51  , subtracted(subtracted) {}
52 
53  virtual Vector getCenter() const override {
54  return primary.getCenter();
55  }
56 
57  virtual Box getBoundingBox() const override {
58  return primary.getBoundingBox();
59  }
60 
61  virtual Float getVolume() const override {
62  return primary.getVolume() - subtracted.getVolume();
63  }
64 
65  virtual Float getSurfaceArea() const override {
66  return primary.getSurfaceArea();
67  }
68 
69  virtual bool contains(const Vector& v) const override {
70  return primary.contains(v) && !subtracted.contains(v);
71  }
72 
73  virtual void getSubset(ArrayView<const Vector>, Array<Size>&, const SubsetType) const override {
75  }
76 
79  }
80 
81  virtual void project(ArrayView<Vector>, Optional<ArrayView<Size>>) const override {
83  }
84 
86  Array<Ghost>&,
87  const Float,
88  const Float) const override {
90  }
91  };
92 
93  virtual void setUp(SharedPtr<Storage> storage) override {
94  Size N = 10000;
95 
96  BodySettings body;
97  body.set(BodySettingsId::ENERGY, 10._f)
109 
110  InitialConditions ic(settings);
111 
112  CylindricalDomain outerRing(Vector(0._f), 0.04_f, 0.01_f, true);
113  CylindricalDomain innerRing(Vector(0._f), 0.03_f, 0.01_f, true);
114  SubtractDomain domain(outerRing, innerRing);
115  ic.addMonolithicBody(*storage, domain, body)
116  .displace(Vector(-0.06_f, 0._f, 0._f))
117  .addVelocity(Vector(80._f, 0._f, 0._f));
118  ic.addMonolithicBody(*storage, domain, body)
119  .displace(Vector(0.06_f, 0._f, 0._f))
120  .addVelocity(Vector(-80._f, 0._f, 0._f));
121 
122  logWriter = makeAuto<NullLogWriter>();
123 
125  triggers.pushBack(makeAuto<ProgressLog>(2.e-4_f));
126  }
127 
128 protected:
129  virtual void tearDown(const Storage& storage, const Statistics& stats) override {
130  output->dump(storage, stats);
131  }
132 };
133 
134 TEST_CASE("Elastic Bands", "[elastic]") {
135  Array<Path> filesToCheck = { Path("elastic_bands/bands_0000.ssf"), Path("elastic_bands/bands_0001.ssf") };
136 
137  for (Path file : filesToCheck) {
139  }
140 
141  measureRun(Path("elastic_bands/stats"), [] {
142  ElasticBands run;
143  Storage storage;
144  run.run(storage);
145  });
146 
147  for (Path file : filesToCheck) {
148  REQUIRE(areFilesApproxEqual(file, REFERENCE_DIR / file.fileName()) == SUCCESS);
149  }
150 }
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Definition: Assert.h:100
void measureRun(const Path &file, Function< void()> run)
Definition: Common.cpp:67
Outcome areFilesApproxEqual(const Path &path1, const Path &path2)
Checks if two .ssf files are almost equal (may have eps-differences in quantities).
Definition: Common.cpp:29
SubsetType
Definition: Domain.h:16
TEST_CASE("Elastic Bands", "[elastic]")
const EmptyFlags EMPTY_FLAGS
Definition: Flags.h:16
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
constexpr Float INFTY
Definition: MathUtils.h:38
const SuccessTag SUCCESS
Global constant for successful outcome.
Definition: Outcome.h:141
constexpr int N
BasicVector< Float > Vector
Definition: Vector.h:539
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
BodyView & addVelocity(const Vector &v)
Adds a velocity vector to all particles of the body.
Definition: Initial.cpp:38
BodyView & displace(const Vector &dr)
Moves the particles of the body in given direction.
Definition: Initial.cpp:23
Helper object defining three-dimensional interval (box).
Definition: Box.h:17
Cylinder aligned with z-axis, optionally including bases (can be either open or close cylinder).
Definition: Domain.h:218
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 Float getVolume() const override
Returns the total volume of the domain.
virtual Vector getCenter() const override
Returns the center of the domain.
virtual void project(ArrayView< Vector >, Optional< ArrayView< Size >>) const override
Projects vectors outside of the domain onto its boundary.
SubtractDomain(IDomain &primary, IDomain &subtracted)
virtual Float getSurfaceArea() const override
Returns the surface area of the domain.
virtual bool contains(const Vector &v) const override
Checks if the given point lies inside the domain.
virtual void getDistanceToBoundary(ArrayView< const Vector >, Array< Float > &) const override
Returns distances of particles lying close to the boundary.
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 tearDown(const Storage &storage, const Statistics &stats) override
Called after the run.
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
Base class for computational domains.
Definition: Domain.h:29
virtual Float getSurfaceArea() const =0
Returns the surface area of the domain.
virtual Box getBoundingBox() const =0
Returns the bounding box of the domain.
virtual Float getVolume() const =0
Returns the total volume of the domain.
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.
Defines the interface for a run.
Definition: IRun.h:61
Statistics run(Storage &storage)
Runs the simulation.
Definition: IRun.cpp:187
Object for adding one or more bodies with given material into a Storage.
Definition: Initial.h:106
BodyView addMonolithicBody(Storage &storage, const BodySettings &body)
Creates a monolithic body by filling given domain with particles.
Definition: Initial.cpp:81
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Wrapper of type value of which may or may not be present.
Definition: Optional.h:23
Object representing a path on a filesystem.
Definition: Path.h:17
Settings & set(const TEnum idx, TValue &&value, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0)
Saves a value into the settings.
Definition: Settings.h:226
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
@ PRESSURE
Use force from pressure gradient in the solver.
@ ELASTIC
No yielding, just elastic deformations following Hooke's law.
@ KD_TREE
Using K-d tree.
@ BINARY_FILE
@ PREDICTOR_CORRECTOR
Predictor-corrector scheme.
@ STANDARD
P_i / rho_i^2 + P_j / rho_j^2.
@ ASYMMETRIC_SOLVER
Generic solver evaluating all derivatives asymmetrically.
@ STANDARD
Standard artificial viscosity term by Monaghan (1989).
@ HEXAGONAL
Hexagonally close packing.
@ CUBIC_SPLINE
M4 B-spline (piecewise cubic polynomial)
@ NONE
No fragmentation.
@ MURNAGHAN
Murnaghan equation of state.
@ ENERGY_MIN
Estimated minimal value of energy used to determine timestepping error.
@ DAMAGE_MIN
Estimate minimal value of damage used to determine timestepping error.
@ RHEOLOGY_DAMAGE
Model of fragmentation used within the rheological model.
@ INITIAL_DISTRIBUTION
Initial distribution of SPH particles within the domain, see DistributionEnum for options.
@ ENERGY
Initial specific internal energy.
@ SHEAR_MODULUS
Shear modulus mu (a.k.a Lame's second parameter) of the material.
@ PARTICLE_COUNT
Number of SPH particles in the body.
@ STRESS_TENSOR_MIN
Estimated minial value of stress tensor components used to determined timestepping error.
@ EOS
Equation of state for this material, see EosEnum for options.
@ ENERGY_RANGE
Allowed range of specific internal energy.
@ RHEOLOGY_YIELDING
Model of stress reducing used within the rheological model.
@ SPH_STRAIN_RATE_CORRECTION_TENSOR
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ TIMESTEPPING_MAX_TIMESTEP
@ SPH_AV_STRESS_FACTOR
Multiplicative factor of the artificial stress term (= strength of the viscosity)
@ SPH_KERNEL
Index of SPH Kernel, see KernelEnum.
@ SPH_SOLVER_FORCES
List of forces to compute by the solver.
@ SPH_AV_TYPE
Type of used artificial viscosity.
@ SPH_AV_BETA
Artificial viscosity beta coefficient.
@ SPH_AV_ALPHA
Artificial viscosity alpha coefficient.
@ RUN_OUTPUT_PATH
Path where all output files (dumps, logs, ...) will be written.
@ SPH_SOLVER_TYPE
Selected solver for computing derivatives of physical variables.
@ TIMESTEPPING_INITIAL_TIMESTEP
@ SPH_ADAPTIVE_SMOOTHING_LENGTH
Solution for evolutions of the smoothing length.
@ SPH_AV_USE_STRESS
Whether to use artificial stress.
@ TIMESTEPPING_DERIVATIVE_FACTOR
Multiplicative factor k for the derivative criterion; dt = k * v / dv.
@ SPH_DISCRETIZATION
Specifies a discretization of SPH equations; see DiscretizationEnum.
@ RUN_OUTPUT_TYPE
Selected format of the output file, see IoEnum.
@ TIMESTEPPING_INTEGRATOR
Selected timestepping integrator.
@ TIMESTEPPING_COURANT_NUMBER
Courant number.
@ SPH_FINDER
Structure for searching nearest neighbours of particles.
@ RUN_NAME
User-specified name of the run, used in some output files.
@ RUN_OUTPUT_NAME
File name of the output file (including extension), where d is a placeholder for output number.
SharedPtr< IScheduler > getScheduler(const RunSettings &settings=RunSettings::getDefaults())
Definition: Factory.cpp:178
Outcome removePath(const Path &path, const Flags< RemovePathFlag > flags=EMPTY_FLAGS)
Definition: FileSystem.cpp:137
Definition: MemoryPool.h:5