diff --git a/.gitignore b/.gitignore index adf2c61..613dedb 100644 --- a/.gitignore +++ b/.gitignore @@ -199,10 +199,12 @@ test/input_files/**/*.json # Test microstructure files !sphere32.h5 +!diamond_GB.h5 # Test input files !test_LinearElastic.json !test_LinearThermal.json +!test_GBDiffusion.json !test_PseudoPlastic.json !test_J2Plasticity.json !test_MixedBCs.json diff --git a/CHANGELOG.md b/CHANGELOG.md index f981cc4..3596655 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## latest +- Bugfix: fixes GBDiffusion post MaterialManager update and adds a test case [#147](https://github.com/DataAnalyticsEngineering/FANS/pull/147) - Bugfix: mem-leak while reading microstructure and added wider CMake support [#140](https://github.com/DataAnalyticsEngineering/FANS/pull/140) - Added MPI communicator abstraction [#139](https://github.com/DataAnalyticsEngineering/FANS/pull/139) diff --git a/include/MaterialManager.h b/include/MaterialManager.h index cbff981..ee3f7bc 100644 --- a/include/MaterialManager.h +++ b/include/MaterialManager.h @@ -260,6 +260,8 @@ class MaterialManager { temp_reader.method = base_reader.method; temp_reader.l_e = base_reader.l_e; temp_reader.dims = base_reader.dims; + std::snprintf(temp_reader.ms_filename, sizeof(temp_reader.ms_filename), "%s", base_reader.ms_filename); + std::snprintf(temp_reader.ms_datasetname, sizeof(temp_reader.ms_datasetname), "%s", base_reader.ms_datasetname); // Override material properties and n_mat for this specific material group temp_reader.materialProperties = mat_group["material_properties"]; diff --git a/include/material_models/GBDiffusion.h b/include/material_models/GBDiffusion.h index 7b5e3e6..1345390 100644 --- a/include/material_models/GBDiffusion.h +++ b/include/material_models/GBDiffusion.h @@ -24,9 +24,9 @@ * - Provides visualization of grain boundary normals in post-processing * * Required material parameters in JSON format: - * - GB_unformity: Boolean flag for uniform GB properties + * - GB_uniformity: Boolean flag for uniform GB properties * - * When GB_unformity is true (uniform properties): + * When GB_uniformity is true (uniform properties): * { * "GB_unformity": true, * "D_bulk": 1.0, // Isotropic diffusion coefficient for all crystals @@ -69,13 +69,13 @@ class GBDiffusion : public ThermalModel, public LinearModel<1, 3> { GBnormals[(tag) * 3 + 1] = normal[1].get(); GBnormals[(tag) * 3 + 2] = normal[2].get(); } - GB_unformity = reader.materialProperties["GB_unformity"].get(); + GB_uniformity = reader.materialProperties["GB_uniformity"].get(); D_bulk.resize(n_mat, 0.0); D_par.resize(n_mat, 0.0); D_perp.resize(n_mat, 0.0); - if (GB_unformity) { + if (GB_uniformity) { double bulk_val = reader.materialProperties["D_bulk"].get(); double par_val = reader.materialProperties["D_par"].get(); double perp_val = reader.materialProperties["D_perp"].get(); @@ -187,7 +187,7 @@ class GBDiffusion : public ThermalModel, public LinearModel<1, 3> { private: int num_crystals = 0; int num_GB = 0; - bool GB_unformity; + bool GB_uniformity; vector D_bulk; vector D_par; diff --git a/include/solver.h b/include/solver.h index 3858a42..d4301ff 100644 --- a/include/solver.h +++ b/include/solver.h @@ -592,14 +592,15 @@ void Solver::postprocess(Reader &reader, int load_idx, int time_ /* ====================================================================== * * u_total = g0·X + ũ (vector or scalar, decided at compile time) * ====================================================================== */ - const double dx = reader.l_e[0]; - const double dy = reader.l_e[1]; - const double dz = reader.l_e[2]; - const double Lx2 = reader.L[0] / 2.0; - const double Ly2 = reader.L[1] / 2.0; - const double Lz2 = reader.L[2] / 2.0; - constexpr double rs2 = 0.7071067811865475; // 1.0 / std::sqrt(2.0) - VectorXd u_total(local_n0 * n_y * n_z * howmany); + const vector &ml = matmanager->models[0]->macroscale_loading; + const double dx = reader.l_e[0]; + const double dy = reader.l_e[1]; + const double dz = reader.l_e[2]; + const double Lx2 = reader.L[0] / 2.0; + const double Ly2 = reader.L[1] / 2.0; + const double Lz2 = reader.L[2] / 2.0; + constexpr double rs2 = 0.7071067811865475; // 1.0 / std::sqrt(2.0) + VectorXd u_total(local_n0 * n_y * n_z * howmany); /* ---------- single sweep ------------------------------------------------- */ ptrdiff_t n = 0; for (ptrdiff_t ix = 0; ix < local_n0; ++ix) { @@ -610,13 +611,13 @@ void Solver::postprocess(Reader &reader, int load_idx, int time_ const double z = iz * dz - Lz2; if (howmany == 3) { /* ===== mechanics (vector) ===== */ if constexpr (n_str == 6) { - /* Small strain: strain_average contains 6 Voigt components */ - const double g11 = strain_average[0]; - const double g22 = strain_average[1]; - const double g33 = strain_average[2]; - const double g12 = strain_average[3] * rs2; - const double g13 = strain_average[4] * rs2; - const double g23 = strain_average[5] * rs2; + /* Small strain: ml holds 6 Mandel components of the mean strain */ + const double g11 = ml[0]; + const double g22 = ml[1]; + const double g33 = ml[2]; + const double g12 = ml[3] * rs2; + const double g13 = ml[4] * rs2; + const double g23 = ml[5] * rs2; const double ux = g11 * x + g12 * y + g13 * z; const double uy = g12 * x + g22 * y + g23 * z; const double uz = g13 * x + g23 * y + g33 * z; @@ -625,16 +626,16 @@ void Solver::postprocess(Reader &reader, int load_idx, int time_ u_total[b + 1] = v_u[b + 1] + uy; u_total[b + 2] = v_u[b + 2] + uz; } else if constexpr (n_str == 9) { - /* Large strain: strain_average contains 9 components of F */ - const double F11 = strain_average[0]; - const double F12 = strain_average[1]; - const double F13 = strain_average[2]; - const double F21 = strain_average[3]; - const double F22 = strain_average[4]; - const double F23 = strain_average[5]; - const double F31 = strain_average[6]; - const double F32 = strain_average[7]; - const double F33 = strain_average[8]; + /* Large strain: ml holds 9 components of the mean deformation gradient F */ + const double F11 = ml[0]; + const double F12 = ml[1]; + const double F13 = ml[2]; + const double F21 = ml[3]; + const double F22 = ml[4]; + const double F23 = ml[5]; + const double F31 = ml[6]; + const double F32 = ml[7]; + const double F33 = ml[8]; // u = (F - I) * X const double ux = (F11 - 1.0) * x + F12 * y + F13 * z; const double uy = F21 * x + (F22 - 1.0) * y + F23 * z; @@ -645,10 +646,7 @@ void Solver::postprocess(Reader &reader, int load_idx, int time_ u_total[b + 2] = v_u[b + 2] + uz; } } else { /* ===== scalar (howmany==1) ==== */ - const double g1 = strain_average[0]; - const double g2 = strain_average[1]; - const double g3 = strain_average[2]; - u_total[n] = v_u[n] + (g1 * x + g2 * y + g3 * z); + u_total[n] = v_u[n] + (ml[0] * x + ml[1] * y + ml[2] * z); } } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 993bb85..f012038 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,7 @@ set(FANS_TEST_CASES J2Plasticity LinearElastic LinearThermal + GBDiffusion PseudoPlastic MixedBCs CompressibleNeoHookean diff --git a/test/input_files/test_GBDiffusion.json b/test/input_files/test_GBDiffusion.json new file mode 100644 index 0000000..bf2807b --- /dev/null +++ b/test/input_files/test_GBDiffusion.json @@ -0,0 +1,33 @@ +{ + "microstructure": { + "filepath": "microstructures/diamond_GB.h5", + "datasetname": "/dset_0/eroded_image", + "L": [1.0, 1.0, 1.0] + }, + "problem_type": "thermal", + "strain_type": "small", + "materials": [ + { + "phases": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], + "matmodel": "GBDiffusion", + "material_properties": { + "GB_uniformity": true, + "D_bulk": 1.0, + "D_perp": 0.1, + "D_par": 10.0 + } + } + ], + "method": "cg", + "error_parameters": { + "measure": "Linfinity", + "type": "absolute", + "tolerance": 1e-10 + }, + "n_it": 1000, + "macroscale_loading": [ + [[0.01, 0.02, -0.01]] + ], + "results": ["homogenized_tangent", "stress_average", "strain_average", "absolute_error", + "microstructure", "displacement", "displacement_fluctuation", "stress", "strain"] +} diff --git a/test/microstructures/diamond_GB.h5 b/test/microstructures/diamond_GB.h5 new file mode 100644 index 0000000..0bb61a0 Binary files /dev/null and b/test/microstructures/diamond_GB.h5 differ diff --git a/test/pytest/conftest.py b/test/pytest/conftest.py index c1417a7..a6750ce 100644 --- a/test/pytest/conftest.py +++ b/test/pytest/conftest.py @@ -16,6 +16,7 @@ def pytest_addoption(parser): "test_J2Plasticity", "test_LinearElastic", "test_LinearThermal", + "test_GBDiffusion", "test_PseudoPlastic", "test_MixedBCs", "test_CompressibleNeoHookean", diff --git a/test/run_tests.sh b/test/run_tests.sh index 28d2baf..65873b0 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -22,6 +22,7 @@ FANS_TEST_CASES=( "J2Plasticity" "LinearElastic" "LinearThermal" + "GBDiffusion" "PseudoPlastic" "MixedBCs" "CompressibleNeoHookean"