SPH
RotatingRod.cpp
Go to the documentation of this file.
1 
6 #include "Common.h"
7 #include "catch.hpp"
8 
9 using namespace Sph;
10 
12 private:
13  std::ofstream ofs;
14 
15 public:
16  AngularMomentumLog(const Float period)
17  : PeriodicTrigger(period, 0._f)
18  , ofs("rod/angmom.txt") {}
19 
20  virtual AutoPtr<ITrigger> action(Storage& storage, Statistics& stats) override {
21  const Float t = stats.get<Float>(StatisticsId::RUN_TIME);
22  const Vector L = TotalAngularMomentum().evaluate(storage);
23  ofs << t << " " << L[Y] << "\n";
24  return nullptr;
25  }
26 };
27 
28 class RotatingRod : public IRun {
29 public:
31  settings.set(RunSettingsId::RUN_NAME, std::string("Rotating Rod Problem"))
38  .set(RunSettingsId::RUN_OUTPUT_PATH, std::string("rod"))
39  .set(RunSettingsId::RUN_OUTPUT_NAME, std::string("rod_%d.txt"))
44  .set(RunSettingsId::RUN_END_TIME, 2500._f)
50  .set(RunSettingsId::SPH_AV_ALPHA, 1.5_f)
51  .set(RunSettingsId::SPH_AV_BETA, 3._f)
63 
64  scheduler = Factory::getScheduler(settings);
65  }
66 
67  virtual void setUp(SharedPtr<Storage> storage) override {
68  BodySettings body;
69  body.set(BodySettingsId::ENERGY, 10._f)
77 
78  InitialConditions ic(settings);
79  const Float height = 100.e3_f;
80  const Float radius = 15e3_f;
81  BodyView view =
82  ic.addMonolithicBody(*storage, CylindricalDomain(Vector(0._f), radius, height, true), body);
83  std::cout << "Created " << storage->getParticleCnt() << " particles" << std::endl;
84 
85  const Float spinRate = 2._f * PI / (3600._f * 1._f); // 1h
86  view.addRotation(Vector(0._f, spinRate, 0._f), Vector(0._f));
87 
88  logWriter = makeAuto<NullLogWriter>();
89 
91  triggers.pushBack(makeAuto<ProgressLog>(25._f));
92 
93  triggers.pushBack(makeAuto<AngularMomentumLog>(1._f));
94  }
95 
96 protected:
97  virtual void tearDown(const Storage& storage, const Statistics& stats) override {
98  output->dump(storage, stats);
99  }
100 };
101 
102 TEST_CASE("Rotating rod", "[rod]") {
103  RotatingRod run;
104  Storage storage;
105  run.run(storage);
106 }
const float radius
Definition: CurveDialog.cpp:18
const EmptyFlags EMPTY_FLAGS
Definition: Flags.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
constexpr Float PI
Mathematical constants.
Definition: MathUtils.h:361
@ PRESSURE
Pressure, reduced by yielding and fracture model (multiplied by 1-damage); always a scalar quantity.
@ VELOCITY
Current velocities of particles, always a vector quantity.
@ POSITION
Positions of particles, always a vector quantity.
@ ENERGY
Specific internal energy, always a scalar quantity.
@ SMOOTHING_LENGTH
Smoothing lenghts of particles.
@ DENSITY
Density, always a scalar quantity.
TEST_CASE("Rotating rod", "[rod]")
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
BasicVector< Float > Vector
Definition: Vector.h:539
@ Y
Definition: Vector.h:23
AngularMomentumLog(const Float period)
Definition: RotatingRod.cpp:16
virtual AutoPtr< ITrigger > action(Storage &storage, Statistics &stats) override
Action executed when the condition is fulfilled.
Definition: RotatingRod.cpp:20
Wrapper of pointer that deletes the resource from destructor.
Definition: AutoPtr.h:15
Non-owning view of particles belonging to the same body.
Definition: Initial.h:20
BodyView & addRotation(const Vector &omega, const RotationOrigin origin)
Adds an angular velocity to all particles of the body.
Definition: Initial.cpp:72
Cylinder aligned with z-axis, optionally including bases (can be either open or close cylinder).
Definition: Domain.h:218
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
Trigger executing given action every period.
Definition: Trigger.h:37
virtual void setUp(SharedPtr< Storage > storage) override
Prepares the run, creates logger, output, ...
Definition: RotatingRod.cpp:67
virtual void tearDown(const Storage &storage, const Statistics &stats) override
Called after the run.
Definition: RotatingRod.cpp:97
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
TValue get(const StatisticsId idx) const
Returns value of a statistic.
Definition: Statistics.h:88
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Size getParticleCnt() const
Returns the number of particles.
Definition: Storage.cpp:445
Computes total angular momentum of all SPH particles with a respect to the reference frame.
Definition: Integrals.h:81
virtual Vector evaluate(const Storage &storage) const override
Computes the integral quantity using particles in the storage.
Definition: Integrals.cpp:40
@ 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.
@ COURANT
Time step determined using CFL condition.
@ BARNES_HUT
Use Barnes-Hut algorithm, approximating gravity by multipole expansion (up to octupole order)
@ TEXT_FILE
Formatted human-readable text file.
@ PREDICTOR_CORRECTOR
Predictor-corrector scheme.
@ STANDARD
P_i / rho_i^2 + P_j / rho_j^2.
@ SPH_KERNEL
Use gravity smoothing kernel corresponding to selected SPH kernel.
@ ASYMMETRIC_SOLVER
Generic solver evaluating all derivatives asymmetrically.
@ STANDARD
Standard artificial viscosity term by Monaghan (1989).
@ HEXAGONAL
Hexagonally close packing.
@ NONE
No fragmentation.
@ TILLOTSON
Tillotson (1962) equation of state.
@ 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.
@ PARTICLE_COUNT
Number of SPH particles in the body.
@ 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.
@ RUN_OUTPUT_QUANTITIES
List of quantities to write to text output. Binary output always stores all quantitites.
@ SPH_STRAIN_RATE_CORRECTION_TENSOR
@ RUN_OUTPUT_INTERVAL
Time interval of dumping data to disk.
@ TIMESTEPPING_MAX_TIMESTEP
@ FINDER_LEAF_SIZE
Maximum number of particles in a leaf node.
@ 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.
@ GRAVITY_SOLVER
Algorithm to compute gravitational acceleration.
@ 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.
@ GRAVITY_RECOMPUTATION_PERIOD
@ GRAVITY_OPENING_ANGLE
Opening angle Theta for multipole approximation of gravity.
@ GRAVITY_KERNEL
Gravity smoothing kernel.
@ 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
Definition: MemoryPool.h:5