Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions include/MaterialManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
10 changes: 5 additions & 5 deletions include/material_models/GBDiffusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,13 +69,13 @@ class GBDiffusion : public ThermalModel, public LinearModel<1, 3> {
GBnormals[(tag) * 3 + 1] = normal[1].get<double>();
GBnormals[(tag) * 3 + 2] = normal[2].get<double>();
}
GB_unformity = reader.materialProperties["GB_unformity"].get<bool>();
GB_uniformity = reader.materialProperties["GB_uniformity"].get<bool>();

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>();
double par_val = reader.materialProperties["D_par"].get<double>();
double perp_val = reader.materialProperties["D_perp"].get<double>();
Expand Down Expand Up @@ -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<double> D_bulk;
vector<double> D_par;
Expand Down
56 changes: 27 additions & 29 deletions include/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,15 @@ void Solver<howmany, n_str>::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<double> &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) {
Expand All @@ -610,13 +611,13 @@ void Solver<howmany, n_str>::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;
Expand All @@ -625,16 +626,16 @@ void Solver<howmany, n_str>::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;
Expand All @@ -645,10 +646,7 @@ void Solver<howmany, n_str>::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);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(FANS_TEST_CASES
J2Plasticity
LinearElastic
LinearThermal
GBDiffusion
PseudoPlastic
MixedBCs
CompressibleNeoHookean
Expand Down
33 changes: 33 additions & 0 deletions test/input_files/test_GBDiffusion.json
Original file line number Diff line number Diff line change
@@ -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"]
}
Binary file added test/microstructures/diamond_GB.h5
Binary file not shown.
1 change: 1 addition & 0 deletions test/pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def pytest_addoption(parser):
"test_J2Plasticity",
"test_LinearElastic",
"test_LinearThermal",
"test_GBDiffusion",
"test_PseudoPlastic",
"test_MixedBCs",
"test_CompressibleNeoHookean",
Expand Down
1 change: 1 addition & 0 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ FANS_TEST_CASES=(
"J2Plasticity"
"LinearElastic"
"LinearThermal"
"GBDiffusion"
"PseudoPlastic"
"MixedBCs"
"CompressibleNeoHookean"
Expand Down
Loading