Skip to content

Commit

Permalink
Merge branch 'develop' into performance/openmp-schedule-mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrayst authored Jul 24, 2020
2 parents 7d8cc4a + b318d94 commit d8ddb3a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
20 changes: 20 additions & 0 deletions include/solvers/mpm_base.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,26 @@ bool mpm::MPMBase<Tdim>::initialise_particles() {
particles_volume_end - particles_volume_begin)
.count());

// Material id update using particle sets
try {
auto material_sets = io_->json_object("material_sets");
if (!material_sets.empty()) {
for (const auto& material_set : material_sets) {
unsigned material_id =
material_set["material_id"].template get<unsigned>();
unsigned pset_id = material_set["pset_id"].template get<unsigned>();
// Update material_id for particles in each pset
mesh_->iterate_over_particle_set(
pset_id,
std::bind(&mpm::ParticleBase<Tdim>::assign_material,
std::placeholders::_1, materials_.at(material_id)));
}
}
} catch (std::exception& exception) {
console_->warn("{} #{}: Material sets are not specified", __FILE__, __LINE__,
exception.what());
}

} catch (std::exception& exception) {
console_->error("#{}: MPM Base generating particles: {}", __LINE__,
exception.what());
Expand Down
3 changes: 3 additions & 0 deletions tests/include/write_mesh_particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace mpm_test {
bool write_json(unsigned dim, bool resume, const std::string& analysis,
const std::string& stress_update, const std::string& file_name);

// Write JSON Entity Set
bool write_entity_set();

// Write Mesh file in 2D
bool write_mesh_2d();
// Write particles file in 2D
Expand Down
21 changes: 20 additions & 1 deletion tests/io/write_mesh_particles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool write_json(unsigned dim, bool resume, const std::string& analysis,
auto io_type = "Ascii2D";
std::string material = "LinearElastic2D";
std::vector<double> gravity{{0., -9.81}};
unsigned material_id = 1;
unsigned material_id = 0;
std::vector<double> xvalues{{0.0, 0.5, 1.0}};
std::vector<double> fxvalues{{0.0, 1.0, 1.0}};

Expand All @@ -35,6 +35,7 @@ bool write_json(unsigned dim, bool resume, const std::string& analysis,
{"title", "Example JSON Input for MPM"},
{"mesh",
{{"mesh", "mesh-" + dimension + ".txt"},
{"entity_sets", "entity_sets_0.json"},
{"io_type", io_type},
{"check_duplicates", true},
{"isoparametric", false},
Expand Down Expand Up @@ -64,6 +65,7 @@ bool write_json(unsigned dim, bool resume, const std::string& analysis,
{"density", 2300.},
{"youngs_modulus", 1.5E+6},
{"poisson_ratio", 0.25}}}},
{"material_sets", {{{"material_id", 1}, {"pset_id", 2}}}},
{"external_loading_conditions",
{{"gravity", gravity},
{"particle_surface_traction",
Expand Down Expand Up @@ -110,6 +112,23 @@ bool write_json(unsigned dim, bool resume, const std::string& analysis,
return true;
}

// Write JSON Entity Set
bool write_entity_set() {
// JSON Entity Sets
Json json_file = {
{"particle_sets",
{{{"id", 2},
{"set", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}}}}}};

// Dump JSON as an input file to be read
std::ofstream file;
file.open("entity_sets_0.json");
file << json_file.dump(2);
file.close();

return true;
}

// Write Mesh file in 2D
bool write_mesh_2d() {
// Dimension
Expand Down
6 changes: 6 additions & 0 deletions tests/mpm_explicit_usf_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ TEST_CASE("MPM 2D Explicit implementation is checked",
REQUIRE(mpm_test::write_json(2, resume, analysis, stress_update, fname) ==
true);

// Write JSON Entity Sets file
REQUIRE(mpm_test::write_entity_set() == true);

// Write Mesh
REQUIRE(mpm_test::write_mesh_2d() == true);

Expand Down Expand Up @@ -101,6 +104,9 @@ TEST_CASE("MPM 3D Explicit implementation is checked",
REQUIRE(mpm_test::write_json(3, resume, analysis, stress_update, fname) ==
true);

// Write JSON Entity Sets file
REQUIRE(mpm_test::write_entity_set() == true);

// Write Mesh
REQUIRE(mpm_test::write_mesh_3d() == true);

Expand Down
6 changes: 6 additions & 0 deletions tests/mpm_explicit_usl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ TEST_CASE("MPM 2D Explicit USL implementation is checked",
REQUIRE(mpm_test::write_json(2, resume, analysis, stress_update, fname) ==
true);

// Write JSON Entity Sets file
REQUIRE(mpm_test::write_entity_set() == true);

// Write Mesh
REQUIRE(mpm_test::write_mesh_2d() == true);

Expand Down Expand Up @@ -101,6 +104,9 @@ TEST_CASE("MPM 3D Explicit USL implementation is checked",
REQUIRE(mpm_test::write_json(3, resume, analysis, stress_update, fname) ==
true);

// Write JSON Entity Sets file
REQUIRE(mpm_test::write_entity_set() == true);

// Write Mesh
REQUIRE(mpm_test::write_mesh_3d() == true);

Expand Down

0 comments on commit d8ddb3a

Please sign in to comment.