Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor testcase total aritificial heart for c++ backend and webassembly example #26

Merged
merged 23 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
175e153
remove var declaration only
chuvirtonomy Jun 18, 2021
e0364e2
add SimTotalArtificialHeart class and functions for JS to call
chuvirtonomy Jun 18, 2021
a654d2f
rename function
chuvirtonomy Jun 18, 2021
9bf8187
simplify input for SimTotalArtificialHeart
chuvirtonomy Jun 18, 2021
937a62f
simplify code
chuvirtonomy Jun 18, 2021
b0c61f0
add comments
chuvirtonomy Jun 18, 2021
70b5602
move sim_total_artificial_heart class to seperate file
chuvirtonomy Jun 19, 2021
6c596e2
add SimTotalArtificialHeartInput
chuvirtonomy Jun 19, 2021
a84def6
code reformat
chuvirtonomy Jun 19, 2021
f15f74d
SimTotalArtificialHeartInput input;
chuvirtonomy Jun 19, 2021
d913ce0
update steps
chuvirtonomy Jun 19, 2021
0810626
update README
chuvirtonomy Jun 22, 2021
e631dfe
Merge branch 'master' of github.com:Xiangyu-Hu/SPHinXsys into refacto…
chuvirtonomy Jun 22, 2021
f30f271
refactor
chuvirtonomy Jun 22, 2021
a679902
refactor
chuvirtonomy Jun 22, 2021
66a6a09
change values to vector
chuvirtonomy Jun 22, 2021
45a78d2
Merge branch 'master' of github.com:Xiangyu-Hu/SPHinXsys into refacto…
chuvirtonomy Jun 22, 2021
4750853
fixes from master
BenceVirtonomy Jun 22, 2021
48dae03
bugs fixed, simulation based on number of steps
BenceVirtonomy Jun 22, 2021
6542e09
move TAH test case and fix WASM build
chuvirtonomy Jun 23, 2021
621921d
refactoring cmake files
chuvirtonomy Jun 23, 2021
4e8dfc1
Merge branch 'master' of github.com:Xiangyu-Hu/SPHinXsys into refacto…
chuvirtonomy Jun 23, 2021
7ef4620
remove warning as error flag
chuvirtonomy Jun 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ if(MSVC)
add_definitions(-D_USE_MATH_DEFINES)
else(MSVC)
add_compile_definitions(__linux__=1)
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -DUNIX -pthread -Werror=reorder")
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -DUNIX -pthread")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -ggdb")
IF(${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ELSE(${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
ENDIF(${CMAKE_BUILD_TYPE} MATCHES "Debug")

endif(MSVC)
message("===========================================")
message("${PROJECT_NAME}, VERSION ${PROJECT_VERSION}")
Expand Down Expand Up @@ -79,6 +80,7 @@ if(NOT WASM_BUILD)
add_subdirectory(cases_test)
add_subdirectory(cases_user)
endif()
add_subdirectory(cases_high_level_simulation)

if(ACTIVATE_CUDA)
add_subdirectory(cases_test_gpu)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ command to run test:

docker run sphinxsys:latest bash scripts/runTest.sh

2. dev.Dockerfile: development packages are all installed and development. This image is too big and can not be used for github testing. Only for local development purposes.
2. dev.Dockerfile: development packages are all installed and simbody is downloaded and compiled in the image building process. This image is too big and can not be used for github testing. Only for local development purposes.

command to build:

Expand All @@ -233,7 +233,6 @@ additional build arguement can be added to the end of the docker build command u
build_with_dependencies_source=0 : default, builds with preprecompiled dependencies
build_with_dependencies_source=1 : builds dependencies together with Sphinxsys


### How to run gpuSPHinXsys cases on CUDA enabled GPUs?
The build process for GPU cases are identical to the CPU cases on all platforms, viz. Linux, Windows and Mac OSX.
However, the following notes must be considered:
Expand Down
8 changes: 2 additions & 6 deletions SPHINXsys/cmake/Simbody_header_directories.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
set(SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS "")
if(NOT WASM_BUILD)
set(SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}") #SPHinXsys
else()
set(SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/SPHinXsys_Virtonomy/SPHinXsys") #SPH_to_JS/SPHinXsys_Virtonomy/SPHinXsys
endif()
set(SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}") #SPHinXsys

SET(SIMBODY_HEADER_DIRECTORIES
set(SIMBODY_HEADER_DIRECTORIES
"${SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS}/SPHINXsys/src/shared/simbody/SimTKcommon/BigMatrix/include"
"${SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS}/SPHINXsys/src/shared/simbody/SimTKcommon/Geometry/include"
"${SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS}/SPHINXsys/src/shared/simbody/SimTKcommon/Mechanics/include"
Expand Down
8 changes: 2 additions & 6 deletions SPHINXsys/cmake/oneTBB_header_directory.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
if(NOT WASM_BUILD)
set(SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}") #SPHinXsys
else()
set(SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/SPHinXsys_Virtonomy/SPHinXsys") #SPH_to_JS/SPHinXsys_Virtonomy/SPHinXsys
endif()
set(SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}") #SPHinXsys

SET(ONETBB_HEADER_DIRECTORY
set(ONETBB_HEADER_DIRECTORY
"${SHP_SOURCE_DIRECTORY_FOR_INCLUDE_PATHS}/oneTBB/include"
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) # main (top) cmake dir
include(Headersearch)

file(GLOB BASE_DIR_HEADERS *.h)
DIR_INC_HEADER_NAMES("${BASE_DIR_HEADERS}" BASE_DIR_HEADER_NAMES)
#message("${BASE_DIR_HEADER_NAMES}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) # main (top) cmake dir
include(Headersearch)
file(GLOB BASE_DIR_HEADERS *.h)
DIR_INC_HEADER_NAMES("${BASE_DIR_HEADERS}" BASE_DIR_HEADER_NAMES)
#message("${BASE_DIR_HEADER_NAMES}")
INSTALL(FILES ${BASE_DIR_HEADER_NAMES} DESTINATION 3d_code/include)
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ BodyPartByParticleTriMesh::~BodyPartByParticleTriMesh()
delete body_part_shape_;
}

ImportedModel::ImportedModel(SPHSystem &system, string body_name, TriangleMeshShape* triangle_mesh_shape, Real resolution)
: SolidBody(system, body_name, resolution)
ImportedModel::ImportedModel(SPHSystem &system, string body_name, TriangleMeshShape* triangle_mesh_shape, ParticleAdaptation* particle_adaptation)
: SolidBody(system, body_name, particle_adaptation)
{
ComplexShape original_body_shape;
original_body_shape.addTriangleMeshShape(triangle_mesh_shape, ShapeBooleanOps::add);
Expand All @@ -30,8 +30,8 @@ ImportedModel::~ImportedModel()
delete body_shape_;
}

SolidBodyForSimulation::SolidBodyForSimulation(SPHSystem &system, string body_name, TriangleMeshShape& triangle_mesh_shape, Real resolution, Real physical_viscosity, LinearElasticSolid& material_model):
imported_model_(ImportedModel(system, body_name, &triangle_mesh_shape, resolution)),
SolidBodyForSimulation::SolidBodyForSimulation(SPHSystem &system, string body_name, TriangleMeshShape& triangle_mesh_shape, ParticleAdaptation& particle_adaptation, Real physical_viscosity, LinearElasticSolid& material_model):
imported_model_(ImportedModel(system, body_name, &triangle_mesh_shape, &particle_adaptation)),
//material_model_(material_model),
elastic_solid_particles_(ElasticSolidParticles(&imported_model_, &material_model)),
inner_body_relation_(InnerBodyRelation(&imported_model_)),
Expand Down Expand Up @@ -115,7 +115,7 @@ StructuralSimulationInput::StructuralSimulationInput(
vector<Real> resolution_list,
vector<LinearElasticSolid> material_model_list,
Real physical_viscosity,
vector<IndexPair> contacting_bodies_list
vector<array<int, 2>> contacting_bodies_list
):
relative_input_path_(relative_input_path),
imported_stl_list_(imported_stl_list),
Expand Down Expand Up @@ -143,7 +143,7 @@ StructuralSimulation::StructuralSimulation(StructuralSimulationInput* input):
imported_stl_list_(input->imported_stl_list_),
scale_stl_(input->scale_stl_),
translation_list_(input->translation_list_),
default_resolution_(input->resolution_list_[0]),
default_resolution_(0.0),
resolution_list_(input->resolution_list_),
material_model_list_(input->material_model_list_),
physical_viscosity_(input->physical_viscosity_),
Expand All @@ -161,8 +161,12 @@ StructuralSimulation::StructuralSimulation(StructuralSimulationInput* input):
{
// scaling of translation and resolution
ScaleTranslationAndResolution();
// creating body mesh list for triangular mesh shapes storage
// set the default resolution to the max in the resolution list
SetDefaultSystemResolutionMax();
// create the body mesh list for triangular mesh shapes storage
CreateBodyMeshList();
// create the particle adaptions for the bodies
CreateParticleAdaptationList();
// set up the system
CalculateSystemBoundaries();
system_.run_particle_relaxation_ = true;
Expand All @@ -176,6 +180,9 @@ StructuralSimulation::StructuralSimulation(StructuralSimulationInput* input):
InitializeAccelerationForBodyPartInBoundingBox();
InitializeSpringDamperConstraintParticleWise();
InitializeConstrainSolidBodyRegion();

// initialize simulation
InitSimulation();
}

StructuralSimulation::~StructuralSimulation()
Expand Down Expand Up @@ -230,6 +237,19 @@ void StructuralSimulation::ScaleTranslationAndResolution()
}
}

void StructuralSimulation::SetDefaultSystemResolutionMax()
{
default_resolution_ = 0.0;
for (unsigned int i = 0; i < resolution_list_.size(); i++)
{
if (default_resolution_ < resolution_list_[i])
{
default_resolution_ = resolution_list_[i];
}
}
system_.resolution_ref_ = default_resolution_;
}

void StructuralSimulation::CalculateSystemBoundaries()
{
for (unsigned int i = 0; i < body_mesh_list_.size(); i++)
Expand All @@ -249,12 +269,22 @@ void StructuralSimulation::CreateBodyMeshList()
}
}

void StructuralSimulation::CreateParticleAdaptationList()
{
particle_adaptation_list_ = {};
for (unsigned int i = 0; i < resolution_list_.size(); i++)
{
Real h_spacing_ratio = resolution_list_[i] / default_resolution_;
particle_adaptation_list_.push_back(ParticleAdaptation(h_spacing_ratio, 0));
}
}

void StructuralSimulation::InitializeElasticSolidBodies(bool particle_relaxation)
{
solid_body_list_ = {};
for (unsigned int i = 0; i < body_mesh_list_.size(); i++)
{
SolidBodyForSimulation* sb = new SolidBodyForSimulation(system_, imported_stl_list_[i], body_mesh_list_[i], resolution_list_[i], physical_viscosity_, material_model_list_[i]);
SolidBodyForSimulation* sb = new SolidBodyForSimulation(system_, imported_stl_list_[i], body_mesh_list_[i], particle_adaptation_list_[i], physical_viscosity_, material_model_list_[i]);
solid_body_list_.push_back(sb);
if (particle_relaxation)
{
Expand Down Expand Up @@ -286,7 +316,7 @@ void StructuralSimulation::InitializeAllContacts()
contact_force_list_ = {};
for (unsigned int i = 0; i < contacting_bodies_list_.size(); i++)
{
InitializeContactBetweenTwoBodies(contacting_bodies_list_[i].first, contacting_bodies_list_[i].second);
InitializeContactBetweenTwoBodies(contacting_bodies_list_[i][0], contacting_bodies_list_[i][1]);
}
}

Expand Down Expand Up @@ -477,14 +507,14 @@ void StructuralSimulation::RunSimulation(Real end_time)
{
WriteBodyStatesToVtu write_states(in_output_, system_.real_bodies_);
GlobalStaticVariables::physical_time_ = 0.0;

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

/** INITIAL CONDITION */
ExecuteCorrectConfiguration();
ExecuteCorrectConfiguration();

/** Statistics for computing time. */
write_states.WriteToFile(GlobalStaticVariables::physical_time_);
int ite = 0;
Expand All @@ -510,3 +540,46 @@ void StructuralSimulation::RunSimulation(Real end_time)
tt = t4 - t1 - interval;
cout << "Total wall time for computation: " << tt.seconds() << " seconds." << endl;
}

void StructuralSimulation::InitSimulation()
{
/** INITIALALIZE SYSTEM */
system_.initializeSystemCellLinkedLists();
system_.initializeSystemConfigurations();

/** INITIAL CONDITION */
ExecuteCorrectConfiguration();
}

double StructuralSimulation::RunSimulationFixedDurationJS(int number_of_steps)
{
WriteBodyStatesToVtu write_states(in_output_, system_.real_bodies_);
GlobalStaticVariables::physical_time_ = 0.0;

/** Statistics for computing time. */
write_states.WriteToFile(GlobalStaticVariables::physical_time_);
int output_period = 100;
int ite = 0;
Real dt = 0.0;
tick_count t1 = tick_count::now();
tick_count::interval_t interval;
/** Main loop */
while (ite < number_of_steps)
{
Real integration_time = 0.0;
int output_step = 0;
while (output_step < output_period)
{
RunSimulationStep(ite, dt, integration_time);
output_step++;
}
tick_count t2 = tick_count::now();
write_states.WriteToFile(GlobalStaticVariables::physical_time_);
tick_count t3 = tick_count::now();
interval += t3 - t2;
}
tick_count t4 = tick_count::now();
tick_count::interval_t tt;
tt = t4 - t1 - interval;
return tt.seconds();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

using namespace SPH;
using namespace std;
using IndexPair = pair<int, int>;
using GravityPair = pair<int, Vec3d>;
using AccelTuple = tuple<int, BoundingBox, Vec3d>;
using SpringDamperTuple = tuple<int, Vec3d, Real>;
Expand All @@ -28,7 +27,7 @@ class BodyPartByParticleTriMesh : public BodyPartByParticle
class ImportedModel : public SolidBody
{
public:
ImportedModel(SPHSystem &system, string body_name, TriangleMeshShape* triangle_mesh_shape, Real resolution);
ImportedModel(SPHSystem &system, string body_name, TriangleMeshShape* triangle_mesh_shape, ParticleAdaptation* particle_adaptation);
~ImportedModel();
};

Expand All @@ -46,7 +45,7 @@ class SolidBodyForSimulation
DampingWithRandomChoice<DampingPairwiseInner<indexVector, Vec3d>> damping_random_;

public:
SolidBodyForSimulation(SPHSystem &system, string body_name, TriangleMeshShape& triangle_mesh_shape, Real resolution, Real physical_viscosity, LinearElasticSolid& material_model);
SolidBodyForSimulation(SPHSystem &system, string body_name, TriangleMeshShape& triangle_mesh_shape, ParticleAdaptation& particle_adaptation, Real physical_viscosity, LinearElasticSolid& material_model);
~SolidBodyForSimulation(){};

ImportedModel* GetImportedModel() { return &imported_model_; };
Expand Down Expand Up @@ -79,7 +78,7 @@ class StructuralSimulationInput
vector<Real> resolution_list_;
vector<LinearElasticSolid> material_model_list_;
Real physical_viscosity_;
vector<IndexPair> contacting_bodies_list_;
vector<array<int, 2>> contacting_bodies_list_;
// particle relaxation
bool particle_relaxation_;
// boundary conditions
Expand All @@ -96,7 +95,7 @@ class StructuralSimulationInput
vector<Real> resolution_list,
vector<LinearElasticSolid> material_model_list,
Real physical_viscosity,
vector<IndexPair> contacting_bodies_list
vector<array<int, 2>> contacting_bodies_list
);
};

Expand All @@ -120,11 +119,11 @@ class StructuralSimulation
In_Output in_output_;

vector<TriangleMeshShape> body_mesh_list_;
vector<TriangleMeshShape> primitive_shape_list_;
vector<ParticleAdaptation> particle_adaptation_list_;

vector<SolidBodyForSimulation*> solid_body_list_;

vector<IndexPair> contacting_bodies_list_;
vector<array<int, 2>> contacting_bodies_list_;
vector<SolidContactBodyRelation*> contact_list_;
vector<solid_dynamics::ContactDensitySummation*> contact_density_list_;
vector<solid_dynamics::ContactForce*> contact_force_list_;
Expand All @@ -144,7 +143,9 @@ class StructuralSimulation

// for constructor, the order is important
void ScaleTranslationAndResolution();
void SetDefaultSystemResolutionMax();
void CreateBodyMeshList();
void CreateParticleAdaptationList();
void CalculateSystemBoundaries();
void InitializeElasticSolidBodies(bool particle_relaxation);
void InitializeContactBetweenTwoBodies(int first, int second);
Expand All @@ -171,11 +172,18 @@ class StructuralSimulation
void ExecuteContactUpdateConfiguration();
void RunSimulationStep(int &ite, Real &dt, Real &integration_time);

// Initialize simulation
void InitSimulation();

public:
StructuralSimulation(StructuralSimulationInput* input);
~StructuralSimulation();

//For c++
void RunSimulation(Real end_time);

//For JS
double RunSimulationFixedDurationJS(int number_of_steps);
};

#endif //SOLID_STRUCTURAL_SIMULATION_CLASS_H
7 changes: 4 additions & 3 deletions SPHINXsys/src/shared/materials/elastic_solid.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ namespace SPH {
LinearElasticSolid(Real rho_0, Real Youngs_modulus, Real poisson) : ElasticSolid()
{
material_name_ = "LinearElasticSolid";
rho0_ = rho_0;
E0_ = Youngs_modulus;
nu_ = poisson;
rho0_ = rho_0;
youngs_modulus_ = Youngs_modulus;
poisson_ratio_ = poisson;

assignDerivedMaterialParameters();
};
virtual ~LinearElasticSolid() {};
Expand Down
Loading