Skip to content

Commit

Permalink
pointers removed
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceVirtonomy committed Jun 2, 2021
1 parent 97a363e commit 83b00e2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ void RelaxParticlesSingleResolution(In_Output* in_output,
/* SolidStructuralSimulation members */
///////////////////////////////////////

void SolidStructuralSimulation::AddPrimitiveCuboid(Vec3d halfsize_cuboid, Vec3d translation, Real resolution, LinearElasticSolid* material)
void SolidStructuralSimulation::AddPrimitiveCuboid(Vec3d halfsize_cuboid, Vec3d translation, Real resolution, LinearElasticSolid& material)
{
primitive_shape_list_.push_back( new TriangleMeshShape(halfsize_cuboid, 20, translation) );
(*resolution_list_).push_back(resolution);
(*material_model_list_).push_back(material);
primitive_shape_list_.push_back( TriangleMeshShape(halfsize_cuboid, 20, translation) );
resolution_list_.push_back(resolution);
material_model_list_.push_back(material);
}

void SolidStructuralSimulation::ImportSTLModelsAndAddPrimitives()
{
// add shapes that are imported from STLs
int i = 0;
for (auto imported_stl: *imported_stl_list_)
for (auto imported_stl: imported_stl_list_)
{
std::string relative_input_path_copy = relative_input_path_;
body_mesh_list_.push_back(new TriangleMeshShape(relative_input_path_copy.append(imported_stl), (*translation_list_)[i], scale_stl_));
body_mesh_list_.push_back(TriangleMeshShape(relative_input_path_copy.append(imported_stl), translation_list_[i], scale_stl_));
i++;
}
// add primitive shapes
Expand All @@ -105,55 +105,51 @@ void SolidStructuralSimulation::ImportSTLModelsAndAddPrimitives()
}
}

BoundingBox* SolidStructuralSimulation::CalculateSystemBoundaries()
{
BoundingBox* system_domain_bounds = new BoundingBox(Vec3d(0, 0, 0), Vec3d(0, 0, 0));

void SolidStructuralSimulation::CalculateSystemBoundaries()
{
for (auto body_mesh: body_mesh_list_)
{
BoundingBox additional = body_mesh->findBounds();
ExpandBoundingBox(system_domain_bounds, &additional);
BoundingBox additional = body_mesh.findBounds();
ExpandBoundingBox(&system_.system_domain_bounds_, &additional);
}
return system_domain_bounds;
}

void SolidStructuralSimulation::SetupSystem()
{
system_ = new SPHSystem (*CalculateSystemBoundaries(), default_resolution_);
system_->run_particle_relaxation_ = true;
in_output_ = new In_Output (*system_);
};
CalculateSystemBoundaries();
system_.run_particle_relaxation_ = true;
}

void SolidStructuralSimulation::InitializeElasticBodies(bool write_particle_relaxation)
{
int i = 0;
int number_stls = (*imported_stl_list_).size();
int number_stls = imported_stl_list_.size();
for (auto body_mesh: body_mesh_list_)
{
std::string name;
// imported STLs
if (i < number_stls)
{
name = (*imported_stl_list_)[i];
name = imported_stl_list_[i];
}
// primitive bodies
else
{
name = "Primitive";
name.append(std::to_string(i));
}
ImportedModel* imported_model = new ImportedModel(*system_, name, body_mesh, (*resolution_list_)[i]);
ImportedModel* imported_model = new ImportedModel(system_, name, &body_mesh, resolution_list_[i]);
imported_model_list_.push_back(imported_model);

ElasticSolidParticles* imported_model_particles = new ElasticSolidParticles(imported_model, (*material_model_list_)[i]);
ElasticSolidParticles* imported_model_particles = new ElasticSolidParticles(imported_model, &material_model_list_[i]);
imported_model_particles_list_.push_back(imported_model_particles);

InnerBodyRelation* imported_model_inner = new InnerBodyRelation(imported_model);
imported_model_inner_list_.push_back(imported_model_inner);
// particle relaxtion, only for STL geometries, not for primitives
if (i < number_stls)
{
RelaxParticlesSingleResolution(in_output_, write_particle_relaxation, imported_model, imported_model_particles, imported_model_inner);
RelaxParticlesSingleResolution(&in_output_, write_particle_relaxation, imported_model, imported_model_particles, imported_model_inner);
}

correct_configuration_list_.push_back(new solid_dynamics::CorrectConfiguration(imported_model_inner));
Expand Down Expand Up @@ -257,7 +253,7 @@ void SolidStructuralSimulation::InitializeConstrainSolidBodyRegion()
{
for (auto body_index: body_indeces_fixed_contraint_)
{
BodyPartByParticle* bp = new BodyPartByParticle(imported_model_list_[body_index], (*imported_stl_list_)[body_index], body_mesh_list_[body_index]);
BodyPartByParticle* bp = new BodyPartByParticle(imported_model_list_[body_index], imported_stl_list_[body_index], &body_mesh_list_[body_index]);
fixed_contraint_.push_back(new solid_dynamics::ConstrainSolidBodyRegion(imported_model_list_[body_index], bp));
}
}
Expand Down Expand Up @@ -385,7 +381,7 @@ void SolidStructuralSimulation::RunSimulationStep(int &ite, Real &dt, Real &inte

/** UPDATE TIME STEP SIZE, INCREMENT */
ite++;
dt = system_->getSmallestTimeStepAmongSolidBodies();
dt = system_.getSmallestTimeStepAmongSolidBodies();
integration_time += dt;
GlobalStaticVariables::physical_time_ += dt;

Expand All @@ -398,12 +394,12 @@ void SolidStructuralSimulation::RunSimulationStep(int &ite, Real &dt, Real &inte

void SolidStructuralSimulation::RunSimulation(Real end_time)
{
WriteBodyStatesToVtu write_states(*in_output_, system_->real_bodies_);
WriteBodyStatesToVtu write_states(in_output_, system_.real_bodies_);
GlobalStaticVariables::physical_time_ = 0.0;

/** INITIALALIZE SYSTEM */
system_->initializeSystemCellLinkedLists();
system_->initializeSystemConfigurations();
system_.initializeSystemCellLinkedLists();
system_.initializeSystemConfigurations();

/** INITIAL CONDITION */
ExecuteCorrectConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ImportedModel : public SolidBody
{
public:
ImportedModel(SPHSystem &system, std::string body_name, TriangleMeshShape* triangle_mesh_shape, Real resolution);
~ImportedModel(){};
};

void ExpandBoundingBox(BoundingBox* original, BoundingBox* additional);
Expand All @@ -31,12 +32,12 @@ void RelaxParticlesSingleResolution(In_Output* in_output,
struct SolidStructuralSimulationInput
{
std::string relative_input_path;
std::vector<std::string>* imported_stl_list;
std::vector<std::string> imported_stl_list;
Real scale_stl;
std::vector<Vec3d>* translation_list;
std::vector<Vec3d> translation_list;
Real default_resolution;
std::vector<Real>* resolution_list;
std::vector<LinearElasticSolid*>* material_model_list;
std::vector<Real> resolution_list;
std::vector<LinearElasticSolid> material_model_list;
Real physical_viscosity;
};

Expand All @@ -45,20 +46,20 @@ class SolidStructuralSimulation
private:
// input members
std::string relative_input_path_;
std::vector<std::string>* imported_stl_list_;
std::vector<std::string> imported_stl_list_;
Real scale_stl_;
std::vector<Vec3d>* translation_list_;
std::vector<Vec3d> translation_list_;
Real default_resolution_;
std::vector<Real>* resolution_list_;
std::vector<LinearElasticSolid*>* material_model_list_;
std::vector<Real> resolution_list_;
std::vector<LinearElasticSolid> material_model_list_;
Real physical_viscosity_;

// internal members
SPHSystem* system_;
In_Output* in_output_;
SPHSystem system_;
In_Output in_output_;

std::vector<TriangleMeshShape*> body_mesh_list_;
std::vector<TriangleMeshShape*> primitive_shape_list_;
std::vector<TriangleMeshShape> body_mesh_list_;
std::vector<TriangleMeshShape> primitive_shape_list_;

std::vector<ImportedModel*> imported_model_list_;
std::vector<ElasticSolidParticles*> imported_model_particles_list_;
Expand Down Expand Up @@ -94,7 +95,7 @@ class SolidStructuralSimulation

// for PreprocessSimulation, the order is important
void ImportSTLModelsAndAddPrimitives();
BoundingBox* CalculateSystemBoundaries(); //for SetupSystem
void CalculateSystemBoundaries(); //for SetupSystem
void SetupSystem();
void InitializeElasticBodies(bool write_particle_relaxation);
void InitializeContactBetweenTwoBodies(int first, int second);
Expand Down Expand Up @@ -123,23 +124,24 @@ class SolidStructuralSimulation

public:
SolidStructuralSimulation(SolidStructuralSimulationInput* input)
{
relative_input_path_ = input->relative_input_path;
imported_stl_list_ = input->imported_stl_list;
scale_stl_ = input->scale_stl;
translation_list_ = input->translation_list;
default_resolution_ = input->default_resolution;
resolution_list_ = input->resolution_list;
material_model_list_ = input->material_model_list;
physical_viscosity_ = input->physical_viscosity;
};
virtual ~SolidStructuralSimulation() {};
: relative_input_path_(input->relative_input_path),
imported_stl_list_(input->imported_stl_list),
scale_stl_(input->scale_stl),
translation_list_(input->translation_list),
default_resolution_(input->default_resolution),
resolution_list_(input->resolution_list),
material_model_list_(input->material_model_list),
physical_viscosity_(input->physical_viscosity),
system_(SPHSystem(BoundingBox(Vec3d(0), Vec3d(0)), default_resolution_)),
in_output_(In_Output (system_))
{};
virtual ~SolidStructuralSimulation() {};

//add primitive shapes
void AddPrimitiveCuboid(Vec3d halfsize_cuboid, Vec3d translation, Real resolution, LinearElasticSolid* material);
void AddPrimitiveCuboid(Vec3d halfsize_cuboid, Vec3d translation, Real resolution, LinearElasticSolid& material);

// get data from private members
TriangleMeshShape* GetBodyMesh(int body_index) { return body_mesh_list_[body_index]; };
TriangleMeshShape* GetBodyMesh(int body_index) { return &body_mesh_list_[body_index]; };

This comment has been minimized.

Copy link
@chuvirtonomy

chuvirtonomy Jun 2, 2021

Collaborator

TriangleMeshShape* this should be changed to return reference


// add contacting bodies
void AddContactPair(int first_id, int second_id);
Expand Down

0 comments on commit 83b00e2

Please sign in to comment.