11 double grid_spacing,
double mass,
const std::array<double, 3>& initial_velocity,
int type,
12 double epsilon,
double sigma,
double spring_constant,
ThirdDimension third_dimension,
13 double initial_temperature)
14 : lower_left_corner(lower_left_corner),
15 grid_dimensions(grid_dimensions),
16 grid_spacing(grid_spacing),
21 spring_constant(spring_constant),
22 initial_velocity(initial_velocity),
23 initial_temperature(initial_temperature),
24 third_dimension(third_dimension) {}
27 auto prev_size = particles.size();
32 const auto grid_pos = std::array<double, 3>{
static_cast<double>(i),
static_cast<double>(j),
static_cast<double>(k)};
38 particles.push_back(std::move(particle));
43 auto particle_pos_to_index = [
this, &prev_size](
const std::array<int, 3>& grid_pos) {
49 return static_cast<int>(prev_size) + grid_pos[2] +
grid_dimensions[2] * grid_pos[1] +
57 auto curr_index = particle_pos_to_index({i, j, k});
58 auto& curr_particle = particles[curr_index];
60 for (
int l = -1; l <= 1; l++) {
61 for (
int m = -1; m <= 1; m++) {
62 for (
int n = -1; n <= 1; n++) {
63 if (l == 0 && m == 0 && n == 0) {
67 auto neighbor_index = particle_pos_to_index({i + l, j + m, k + n});
69 if (neighbor_index == -1) {
73 auto& neighbor_particle = particles[neighbor_index];
75 auto initial_distance =
ArrayUtils::L2Norm(curr_particle.getX() - neighbor_particle.getX());
77 curr_particle.addConnectedParticle(&neighbor_particle - &curr_particle, initial_distance,
spring_constant);
ThirdDimension
Enum class to define the dimension count of the simulation (2D or 3D). Affects primarily the dimensio...
Class to represent a particle.
double sigma
Defines the Lennard-Jones sigma parameter of the particles in the cuboid.
const double initial_temperature
Defines the initial temperature of the particles in the cuboid.
const std::array< double, 3 > lower_left_corner
Defines the lower left corner where the cuboid will be spawned.
double epsilon
Defines the Lennard-Jones epsilon parameter of the particles in the cuboid.
size_t getEstimatedNumberOfParticles() const override
Estimate the number of particles to be spawned.
const int type
Defines the type of the particles in the cuboid.
const std::array< double, 3 > initial_velocity
Defines the initial velocity of the particles in the cuboid.
const ThirdDimension third_dimension
Defines whether the third dimension is enabled.
const double mass
Defines the mass of the particles in the cuboid.
const double grid_spacing
Defines the spacing between neighboring particles in the cuboid.
SoftBodyCuboidSpawner(const std::array< double, 3 > &lower_left_corner, const std::array< int, 3 > &grid_dimensions, double grid_spacing, double mass, const std::array< double, 3 > &initial_velocity, int type, double epsilon=1.0, double sigma=1.2, double spring_constant=300, ThirdDimension third_dimension=ThirdDimension::ENABLED, double initial_temperature=0.1)
Constructor.
int spawnParticles(std::vector< Particle > &particles) const override
Spawns particles in the given container.
const double spring_constant
Spring constant of the harmonic springs.
const std::array< int, 3 > grid_dimensions
Defines how big the cuboid will be. Each entry defines the number of particles in the respective dire...
static void setParticleTemperature(double new_temperature, Particle &particle, ThirdDimension third_dimension)
Set the temperature of a particle. This method adds a random velocity to the particle according to th...
auto L2Norm(const Container &c)