Skip to content

Commit

Permalink
Small strain material models and minor improvements (#18)
Browse files Browse the repository at this point in the history
* added youngs modulus plotting to dash

* added nonlinear pseudo plastic hardening (not working yet)

* rate independent J2 plasticity added

* visco plastic models

* refactorted J2 plasticity

* Formatting

* Disambiguate mandel notation definition in readme.md #17

* renamed internal variable in J2plasticity.h

---------

Co-authored-by: Ishaan Desai <[email protected]>
  • Loading branch information
sanathkeshav and IshaanDesai authored Sep 20, 2024
1 parent 2961ccf commit 034d8cf
Show file tree
Hide file tree
Showing 19 changed files with 689 additions and 320 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test/input_files/**/*.json
!sphere.h5

# Test input files
!test_LinearElasticIsotropic.json
!test_LinearThermalIsotropic.json
!test_PseudoPlasticLinearHardening.json
!test_VonMisesPlasticLinearIsotropicHardening.json
!test_LinearElastic.json
!test_LinearThermal.json
!test_PseudoPlastic.json
!test_J2Plasticity.json
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ set_property(TARGET FANS_FANS PROPERTY PUBLIC_HEADER

include/material_models/LinearThermalIsotropic.h
include/material_models/LinearElasticIsotropic.h
include/material_models/PseudoPlasticLinearHardening.h
include/material_models/VonMisesPlasticLinearIsotropicHardening.h
include/material_models/PseudoPlastic.h
include/material_models/J2Plasticity.h
)

# ##############################################################################
Expand Down
18 changes: 9 additions & 9 deletions FANS_Dashboard/FANS_Dashboard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
"outputs": [],
"source": [
"# Specify which microstructures, load cases, and quantities to load\n",
"microstructures_to_load = ['/sphere/32x32x32/ms']\n",
"load_cases_to_load = ['load0']\n",
"microstructures_to_load = list(hierarchy.keys())\n",
"load_cases_to_load = list(hierarchy[microstructures_to_load[0]].keys())\n",
"quantities_to_load = ['strain_average', 'stress_average', 'phase_stress_average_phase0', \"stress\"]\n",
"time_steps_to_load = []\n",
"\n",
Expand All @@ -143,7 +143,11 @@
" quantities_to_load, \n",
" microstructures_to_load, \n",
" load_cases_to_load, \n",
" time_steps_to_load)"
" time_steps_to_load)\n",
"\n",
"strain_average = data[microstructures_to_load[0]][load_cases_to_load[0]]['strain_average'] \n",
"stress_average = data[microstructures_to_load[0]][load_cases_to_load[0]]['stress_average']\n",
"time_steps = data[microstructures_to_load[0]][load_cases_to_load[0]]['time_steps']\n"
]
},
{
Expand All @@ -164,10 +168,6 @@
"metadata": {},
"outputs": [],
"source": [
"strain_average = data['/sphere/32x32x32/ms']['load0']['strain_average']\n",
"stress_average = data['/sphere/32x32x32/ms']['load0']['stress_average']\n",
"time_steps = data['/sphere/32x32x32/ms']['load0']['time_steps']\n",
"\n",
"# Specify measures to compute\n",
"measures_to_compute = ['von_mises', 'hydrostatic', 'deviatoric', 'principal', \n",
" 'max_shear', 'I_invariants', 'J_invariants', 'eigenvalues',\n",
Expand Down Expand Up @@ -209,8 +209,8 @@
"# Postprocessing and writing to h5 file\n",
"quantities_to_postprocess = ['stress_average', 'stress']\n",
"measures_to_postprocess = ['deviatoric', 'von_mises']\n",
"microstructures_to_postprocess = ['/sphere/32x32x32/ms']\n",
"load_cases_to_postprocess = ['load0']\n",
"microstructures_to_postprocess = microstructures_to_load[0]\n",
"load_cases_to_postprocess = load_cases_to_load[0]\n",
"\n",
"processed_data = postprocess_and_write_to_h5(file_path, hierarchy, quantities_to_postprocess, measures_to_postprocess, \n",
" microstructures_to_postprocess, load_cases_to_postprocess)"
Expand Down
110 changes: 110 additions & 0 deletions FANS_Dashboard/PlotYoungsModulus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import numpy as np
import plotly.graph_objs as go


def compute_3d_youngs_modulus(C):
"""
Compute Young's modulus for all directions in 3D.
Parameters:
C : ndarray
Stiffness tensor in Mandel notation.
Returns:
E: ndarray
Young's modulus in all directions.
X, Y, Z: ndarrays
Coordinates for plotting the modulus surface.
"""

n_theta = 180
n_phi = 360
theta = np.linspace(0, np.pi, n_theta) # Polar angle
phi = np.linspace(0, 2 * np.pi, n_phi) # Azimuthal angle

S = np.linalg.inv(C)

E = np.zeros((n_theta, n_phi))

for i in range(n_theta):
for j in range(n_phi):
d = np.array(
[
np.sin(theta[i]) * np.cos(phi[j]),
np.sin(theta[i]) * np.sin(phi[j]),
np.cos(theta[i]),
]
)

N = np.array(
[
d[0] ** 2,
d[1] ** 2,
d[2] ** 2,
np.sqrt(2.0) * d[0] * d[1],
np.sqrt(2.0) * d[0] * d[2],
np.sqrt(2.0) * d[2] * d[1],
]
)

E[i, j] = 1.0 / (N.T @ S @ N)

X = E * np.sin(theta)[:, np.newaxis] * np.cos(phi)[np.newaxis, :]
Y = E * np.sin(theta)[:, np.newaxis] * np.sin(phi)[np.newaxis, :]
Z = E * np.cos(theta)[:, np.newaxis]

return X, Y, Z, E


def plot_3d_youngs_modulus_surface(C, title="Young's Modulus Surface"):
"""
Plot a 3D surface of Young's modulus.
Parameters:
C : ndarray
Stiffness tensor in Mandel notation.
title : str
Title of the plot.
"""
X, Y, Z, E = compute_3d_youngs_modulus(C)

surface = go.Surface(x=X, y=Y, z=Z, surfacecolor=E, colorscale="Viridis")

layout = go.Layout(
title=title,
scene=dict(
xaxis=dict(title="X"),
yaxis=dict(title="Y"),
zaxis=dict(title="Z"),
aspectmode="auto",
),
)

fig = go.Figure(data=[surface], layout=layout)
fig.show()


def demoCubic():
"""
Demonstrates the Young's modulus surface plotting routine for a cubic material (Copper)
Returns
-------
None.
"""
P1 = np.zeros((6, 6))
P1[:3, :3] = 1.0 / 3.0
D = np.diag([1, 1, 1, 0, 0, 0])
P2 = D - P1
P3 = np.eye(6) - D

# generate stiffness for a cubic material: copper
l1, l2, l3 = 136.67, 46, 150
C = 3 * l1 * P1 + l2 * P2 + l3 * P3

print(C)

# show the 3D Young's modulus plot for copper
plot_3d_youngs_modulus_surface(C, title="Young's Modulus Surface for Copper")
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Fourier Accelerated Nodal Solvers (FANS) is an FFT-based homogenization solver d
- [Input File Format](#input-file-format)
- [Examples](#examples)
- [Acknowledgements](#acknowledgements)
- [Contributors](#contributors)

## Installation

Expand Down Expand Up @@ -159,8 +160,8 @@ Example input files can be found in the [`test/input_files`](test/input_files)
```
- `problem_type`: This defines the type of physical problem you are solving. Common options include "thermal" problems and "mechanical" problems.
- `matmodel`: This specifies the material model to be used in the simulation. Examples include `LinearThermalIsotropic` for isotropic linear thermal problems, `LinearElasticIsotropic` for isotropic linear elastic mechanical problems, `PseudoPlasticLinearHardening` for plasticity mimicking model with linear hardening, and `VonMisesPlasticLinearIsotropicHardening` for rate independent J2 plasticity model with linear isotropic hardening.
- `material_properties`: This provides the necessary material parameters for the chosen material model. For thermal problems, you might specify `conductivity`, while mechanical problems might require `bulk_modulus`, `shear_modulus`, `yield_stress`, and `hardening_parameter`. These properties can be defined as arrays to represent multiple phases within the microstructure.
- `matmodel`: This specifies the material model to be used in the simulation. Examples include `LinearThermalIsotropic` for isotropic linear thermal problems, `LinearElasticIsotropic` for isotropic linear elastic mechanical problems, `PseudoPlasticLinearHardening`/`PseudoPlasticNonLinearHardening` for plasticity mimicking model with linear/nonlinear hardening, and `J2ViscoPlastic_LinearIsotropicHardening`/`J2ViscoPlastic_NonLinearIsotropicHardening` for rate dependent J2 plasticity model with linear/nonlinear isotropic hardening.
- `material_properties`: This provides the necessary material parameters for the chosen material model. For thermal problems, you might specify `conductivity`, while mechanical problems might require `bulk_modulus`, `shear_modulus`, and more properties for advanced material models. These properties can be defined as arrays to represent multiple phases within the microstructure.
### Solver Settings
Expand Down Expand Up @@ -194,9 +195,8 @@ Example input files can be found in the [`test/input_files`](test/input_files)
```
- `macroscale_loading`: This defines the external loading applied to the microstructure. It is an array of arrays, where each sub-array represents a loading condition applied to the system. The format of the loading array depends on the problem type:
- For `thermal` problems, the array typically has 3 components, representing the temperature gradients in the x, y, and z directions.
- For `mechanical` problems, the array must have 6 components, corresponding to the components of the strain tensor in Mandel notation (e.g., [[ε11, ε22, ε33, ε12, ε13, ε23]]).
- For `thermal` problems, the array typically has 3 components, representing the temperature gradients in the x, y, and z directions.
- For `mechanical` problems, the array must have 6 components, corresponding to the components of the strain tensor in Mandel notation (e.g., [[ε_11, ε_22, ε_33, √2 ε_12, √2 ε_13, √2 ε_23]]).
In the case of path/time-dependent loading as shown, for example as in plasticity problems, the `macroscale_loading` array can include multiple steps with corresponding loading conditions.
Expand All @@ -216,16 +216,23 @@ In the case of path/time-dependent loading as shown, for example as in plasticit
- `displacement`: The displacement fluctuation field (for mechanical problems) and temperature fluctuation field (for thermal problems).
- `stress` and `strain`: The stress and strain fields at each voxel in the microstructure.
- Additional material model specific results, such as `plastic_flag`, `plastic_strain`, and `hardening_variable`, can be included depending on the problem type and material model.
- Additional material model specific results can be included depending on the problem type and material model.
### Examples
If you would like to run some example tests, you can execute the [`run_tests.sh`](test/run_tests.sh) file. For example to run a linear elastic mechanical homogenization problem for a 6 othonormal load cases on a microstructure image of size `32 x 32 x 32` with a single spherical inclusion,
```bash
mpiexec -n 2 ./FANS input_files/test_LinearElasticIsotropic.json test_results.h5
mpiexec -n 2 ./FANS input_files/test_LinearElastic.json test_results.h5
```
## Acknowledgements
Funded by Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Germany’s Excellence Strategy - EXC 2075 – 390740016. Contributions by Felix Fritzen are funded by Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) within the Heisenberg program - DFG-FR2702/8 - 406068690; DFG-FR2702/10 - 517847245 and through NFDI-MatWerk - NFDI 38/1 - 460247524. We acknowledge the support by the Stuttgart Center for Simulation Science (SimTech).
## Contributors
- [Sanath Keshav](https://github.com/sanathkeshav)
- [Florian Rieg](about:blank)
- [Ishaan Desai](https://github.com/IshaanDesai)
- [Moritz Sigg](https://github.com/siggmo)
Loading

0 comments on commit 034d8cf

Please sign in to comment.