Molecular Dynamics Simulation  1.0
Public Member Functions | Private Attributes | List of all members
SoftBodyCuboidSpawner Class Reference

Class to spawn particles of a soft body in a cuboid. Implements the interface ParticleSpawner. More...

#include <SoftBodyCuboidSpawner.h>

Inheritance diagram for SoftBodyCuboidSpawner:
Inheritance graph
Collaboration diagram for SoftBodyCuboidSpawner:
Collaboration graph

Public Member Functions

 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. More...
 
int spawnParticles (std::vector< Particle > &particles) const override
 Spawns particles in the given container. More...
 
size_t getEstimatedNumberOfParticles () const override
 Estimate the number of particles to be spawned. More...
 

Private Attributes

const std::array< double, 3 > lower_left_corner
 Defines the lower left corner where the cuboid will be spawned. More...
 
const std::array< int, 3 > grid_dimensions
 Defines how big the cuboid will be. Each entry defines the number of particles in the respective direction. More...
 
const double grid_spacing
 Defines the spacing between neighboring particles in the cuboid. More...
 
const double mass
 Defines the mass of the particles in the cuboid. More...
 
const int type
 Defines the type of the particles in the cuboid. More...
 
double epsilon
 Defines the Lennard-Jones epsilon parameter of the particles in the cuboid. More...
 
double sigma
 Defines the Lennard-Jones sigma parameter of the particles in the cuboid. More...
 
const double spring_constant
 Spring constant of the harmonic springs. More...
 
const std::array< double, 3 > initial_velocity
 Defines the initial velocity of the particles in the cuboid. More...
 
const double initial_temperature
 Defines the initial temperature of the particles in the cuboid. More...
 
const ThirdDimension third_dimension
 Defines whether the third dimension is enabled. More...
 

Detailed Description

Class to spawn particles of a soft body in a cuboid. Implements the interface ParticleSpawner.

Implementation of the particle spawning in a soft body cuboid. This class is very similar to the CuboidSpawner, but it links neighboring particles with harmonic springs. The HarmonicForce then class calculates the force on the particles.

Definition at line 13 of file SoftBodyCuboidSpawner.h.

Constructor & Destructor Documentation

◆ SoftBodyCuboidSpawner()

SoftBodyCuboidSpawner::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.

Parameters
lower_left_cornerLower left corner of the soft body
grid_dimensionsGrid dimensions
grid_spacingSpacing between neighboring particles
massMass of the particles
initial_velocityInitial velocity of the particles, the velocity is then jittered by a Maxwell-Boltzmann distribution
typeType of the particles in the cuboid
epsilonLennard-Jones epsilon parameter of the particles in the cuboid
sigmaLennard-Jones sigma parameter of the particles in the cuboid
spring_constantSpring constant of the harmonic springs
initial_temperatureInitial temperature of the particles
third_dimensionWhether to spawn particles in the third dimension

Constructor to initialize the cuboid spawner. The velocity of the particles is jittered by a Maxwell-Boltzmann distribution.

Definition at line 10 of file SoftBodyCuboidSpawner.cpp.

17  mass(mass),
18  type(type),
20  sigma(sigma),
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.
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.
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...

Member Function Documentation

◆ getEstimatedNumberOfParticles()

size_t SoftBodyCuboidSpawner::getEstimatedNumberOfParticles ( ) const
overridevirtual

Estimate the number of particles to be spawned.

returns the number of particles to be spawned by this spawner this can be used to reserve enought memory in the particle container

Implements ParticleSpawner.

Definition at line 88 of file SoftBodyCuboidSpawner.cpp.

88  {
89  return static_cast<size_t>(grid_dimensions[0]) * grid_dimensions[1] * grid_dimensions[2];
90 }

◆ spawnParticles()

int SoftBodyCuboidSpawner::spawnParticles ( std::vector< Particle > &  particles) const
overridevirtual

Spawns particles in the given container.

Parameters
particlesA vector of particles to spawn
Returns
Number of particles spawned Spawns particles in the given container.

Implements ParticleSpawner.

Definition at line 26 of file SoftBodyCuboidSpawner.cpp.

26  {
27  auto prev_size = particles.size();
28  particles.reserve(particles.size() + getEstimatedNumberOfParticles());
29  for (int i = 0; i < grid_dimensions[0]; i++) {
30  for (int j = 0; j < grid_dimensions[1]; j++) {
31  for (int k = 0; k < grid_dimensions[2]; k++) {
32  const auto grid_pos = std::array<double, 3>{static_cast<double>(i), static_cast<double>(j), static_cast<double>(k)};
33 
34  const auto x = lower_left_corner + grid_spacing * grid_pos;
35 
38  particles.push_back(std::move(particle));
39  }
40  }
41  }
42 
43  auto particle_pos_to_index = [this, &prev_size](const std::array<int, 3>& grid_pos) {
44  if (grid_pos[0] < 0 || grid_pos[0] >= grid_dimensions[0] || grid_pos[1] < 0 || grid_pos[1] >= grid_dimensions[1] ||
45  grid_pos[2] < 0 || grid_pos[2] >= grid_dimensions[2]) {
46  return -1;
47  }
48 
49  return static_cast<int>(prev_size) + grid_pos[2] + grid_dimensions[2] * grid_pos[1] +
50  grid_dimensions[2] * grid_dimensions[1] * grid_pos[0];
51  };
52 
53  // connect particles with harmonic springs
54  for (int i = 0; i < grid_dimensions[0]; i++) {
55  for (int j = 0; j < grid_dimensions[1]; j++) {
56  for (int k = 0; k < grid_dimensions[2]; k++) {
57  auto curr_index = particle_pos_to_index({i, j, k});
58  auto& curr_particle = particles[curr_index];
59 
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) {
64  continue;
65  }
66 
67  auto neighbor_index = particle_pos_to_index({i + l, j + m, k + n});
68 
69  if (neighbor_index == -1) {
70  continue;
71  }
72 
73  auto& neighbor_particle = particles[neighbor_index];
74 
75  auto initial_distance = ArrayUtils::L2Norm(curr_particle.getX() - neighbor_particle.getX());
76 
77  curr_particle.addConnectedParticle(&neighbor_particle - &curr_particle, initial_distance, spring_constant);
78  }
79  }
80  }
81  }
82  }
83  }
84 
86 }
Class to represent a particle.
Definition: Particle.h:26
size_t getEstimatedNumberOfParticles() const override
Estimate the number of particles to be spawned.
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...
Definition: Thermostat.cpp:20
auto L2Norm(const Container &c)
Definition: ArrayUtils.h:174

Member Data Documentation

◆ epsilon

double SoftBodyCuboidSpawner::epsilon
private

Defines the Lennard-Jones epsilon parameter of the particles in the cuboid.

Definition at line 43 of file SoftBodyCuboidSpawner.h.

◆ grid_dimensions

const std::array<int, 3> SoftBodyCuboidSpawner::grid_dimensions
private

Defines how big the cuboid will be. Each entry defines the number of particles in the respective direction.

Definition at line 23 of file SoftBodyCuboidSpawner.h.

◆ grid_spacing

const double SoftBodyCuboidSpawner::grid_spacing
private

Defines the spacing between neighboring particles in the cuboid.

Definition at line 28 of file SoftBodyCuboidSpawner.h.

◆ initial_temperature

const double SoftBodyCuboidSpawner::initial_temperature
private

Defines the initial temperature of the particles in the cuboid.

Definition at line 63 of file SoftBodyCuboidSpawner.h.

◆ initial_velocity

const std::array<double, 3> SoftBodyCuboidSpawner::initial_velocity
private

Defines the initial velocity of the particles in the cuboid.

Definition at line 58 of file SoftBodyCuboidSpawner.h.

◆ lower_left_corner

const std::array<double, 3> SoftBodyCuboidSpawner::lower_left_corner
private

Defines the lower left corner where the cuboid will be spawned.

Definition at line 18 of file SoftBodyCuboidSpawner.h.

◆ mass

const double SoftBodyCuboidSpawner::mass
private

Defines the mass of the particles in the cuboid.

Definition at line 33 of file SoftBodyCuboidSpawner.h.

◆ sigma

double SoftBodyCuboidSpawner::sigma
private

Defines the Lennard-Jones sigma parameter of the particles in the cuboid.

Definition at line 48 of file SoftBodyCuboidSpawner.h.

◆ spring_constant

const double SoftBodyCuboidSpawner::spring_constant
private

Spring constant of the harmonic springs.

Definition at line 53 of file SoftBodyCuboidSpawner.h.

◆ third_dimension

const ThirdDimension SoftBodyCuboidSpawner::third_dimension
private

Defines whether the third dimension is enabled.

Definition at line 68 of file SoftBodyCuboidSpawner.h.

◆ type

const int SoftBodyCuboidSpawner::type
private

Defines the type of the particles in the cuboid.

Definition at line 38 of file SoftBodyCuboidSpawner.h.


The documentation for this class was generated from the following files: