Skip to content
Snippets Groups Projects
Commit 2a9557c2 authored by Ujjal Saikia's avatar Ujjal Saikia
Browse files

Upload New File

parent dc3757cf
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:f1e7d1dc-e3d5-423b-b21a-9ffe83a19cb8 tags:
## <font style="font-family:roboto;color:#455e6c"> Multiple Rolling Simulation with DAMASK </font>
%% Cell type:markdown id:342a274f-b949-4cfc-8dd2-008f930c8cb8 tags:
<div class="admonition note" name="html-admonition" style="background:#e3f2fd; padding: 10px">
<font style="font-family:roboto;color:#455e6c"> <b> StahlDigital Tutorial: Creating and Running Simulations for Steel Development </b> </font> </br>
<font style="font-family:roboto;color:#455e6c"> 25 April 2024 </font>
</div>
%% Cell type:markdown id:9cc1f7f7-f5c8-48e3-b7b4-950ba2cd2a8e tags:
In this notebook, we will use `pyiron` to setup and run a workflow for multiple rolling simulation of steel with the continuum code [DAMASK](https://damask.mpie.de/release/). A damask simulation requires material specific information (`Elastic` and `Plastic` parameters of the material). We will show, how we can get these parameters from a `Tensile Test Experiment` data using [DSMS](https://stahldigital.materials-data.space/) and run damask simulation with these parameters.
%% Cell type:markdown id:e79d0bd7-bc28-4aba-a8c2-18d5c0b6033d tags:
### <font style="font-family:roboto;color:#455e6c"> Import necessary libraries </font>
%% Cell type:code id:db94105a-253a-4d6e-827f-1fde282f9e2a tags:
``` python
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
from pyiron import Project
from damask import Rotation
from dsms import DSMS, KItem
from getpass import getpass
from urllib.parse import urljoin
from data2rdf import AnnotationPipeline, Parser
```
%% Cell type:code id:fb9ec662-3663-4d5a-800a-c67463350838 tags:
``` python
# Unit conversion factors: from megapascal(MPa) and gegapascal(GPa) to pascal(Pa)
MPa_to_Pa = 1e+6
GPa_to_Pa = 1e+9
```
%% Cell type:markdown id:5f47d4fe-d51d-48ec-9ea7-228cdd104122 tags:
#### <font style="font-family:roboto;color:#455e6c"> Create a pyiron project </font>
%% Cell type:code id:54951d3f-7b2a-48a9-b9c6-466f84362247 tags:
``` python
pr = Project('damask_rolling_simulation')
```
%% Cell type:markdown id:864bf1f6-1fad-4c6a-909c-2236bd0d4fcc tags:
### <font style="font-family:roboto;color:#455e6c"> Running a multiple rolling simulation with DAMASK </font>
Suppose your colluge performed a nice tensile test experiment and uploaded the data, the fitted elasticity parameters, and phenopowerlaw parameters required for damask simulation into the `DSMS`. Now, we will show how you can get the required parameters from dsms and run your `DAMASK` simulation with it.
%% Cell type:markdown id:1af5a9eb-1430-4288-b38f-b197a6588711 tags:
First, we will write two python functions to get the required data from DSMS
- A python function to get experimental elastic parameters
- A python function to get experimental plastic parameters
%% Cell type:code id:abfff782-2657-431c-8161-253a1f302b57 tags:
``` python
# A python function to get experimental elastic parameters from dsms
def get_elasticity_data_from_dsms(item):
elasticity_data = {"type": "Hooke",
"C_11": item.custom_properties.ElasticConstantC11.convert_to('Pa'),
"C_12": item.custom_properties.ElasticConstantC12.convert_to('Pa'),
"C_44": item.custom_properties.ElasticConstantC44.convert_to('Pa')
}
return elasticity_data
```
%% Cell type:code id:6c46c8d6-84e9-4bd1-a7c3-481d9fdf3aa1 tags:
``` python
# A python function to get experimental plastic parameters from dsms
def get_plasticity_data_from_dsms(item):
plasticity_data = {"type": "phenopowerlaw",
"references": ["https://doi.org/10.1016/j.actamat.2014.07.071",
"https://doi.org/10.1007/BF02900224"],
"output": ["xi_sl", "gamma_sl"],
"N_sl": item.hdf5.NumberSlipSystems.get(),
"dot_gamma_0_sl": item.hdf5.ReferenceShearRate.get(),
"n_sl": item.hdf5.Inv_ShearRateSensitivity.get(),
"a_sl": item.hdf5.HardeningExponent.get(),
"xi_0_sl": item.hdf5.InitialCriticalStrength.convert_to('Pa'),
"xi_inf_sl": item.hdf5.FinalCriticalStrength.convert_to('Pa'),
"h_0_sl_sl": item.hdf5.InitialHardening.convert_to('Pa'),
"h_sl_sl": [1, 1.4, 1, 1.4, 1.4, 1.4, 1.4, 1.4,
1.4,1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.4,
1.4,1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.4]
}
return plasticity_data
```
%% Cell type:markdown id:999583c8-e629-46c9-8944-ba803c2a5b94 tags:
Now, we have to connect to `dsms`. For the next step you need your dsms `username` and `password`. If you don't have a dsms account, please look [here](https://stahldigital.materials-data.space/support) for help.
%% Cell type:code id:b0c4d5dc-d75a-4dc3-9c7b-0762e81db52e tags:
``` python
# After executing this cell, you have to enter your dsms username
username = getpass()
```
%% Cell type:code id:e2e5d11f-9c54-4522-92c5-319c88b1de2b tags:
``` python
# After executing this cell, you have to enter your dsms password
password = getpass()
```
%% Cell type:code id:4903c8d2-5d8d-4766-863d-fd12aebe24d6 tags:
``` python
# Now we will connect to dsms
dsms = DSMS(host_url="https://stahldigital.materials-data.space",
username=username,
password=password)
```
%% Cell type:code id:bc63a848-04af-40b8-8ddf-4506bd5999a6 tags:
``` python
# Search for our data item using unique KItem UUID
# input_kitem_id = 'ff8ee824-cef6-465c-84af-4d332e73ac64' # dsms KItem UUID for our dataset
input_kitem_id = '1ba3712b-68f2-4f2f-89d9-e0b3e4823d48' # New KItem
item = dsms[input_kitem_id]
```
%% Cell type:code id:ad51b16c-ff58-45bd-a3b7-8ef1510d399c tags:
``` python
# Run the functions defined above to get experimental elasticity and plasticity data from dsms
elasticity_data = get_elasticity_data_from_dsms(item)
plasticity_data = get_plasticity_data_from_dsms(item)
```
%% Cell type:markdown id:c250e1ca-d125-495d-838e-673351b64db5 tags:
Now, we will use these data obtained from `dsms` to create a `damask` simulation.
%% Cell type:markdown id:6f169a43-2038-46d9-b727-1caff3128c9b tags:
Again, we start by creating a pyiron job `job_rolling`. For multiple rolling, we need to use the pyiron class `ROLLING`
%% Cell type:code id:d7080422-6e97-48d7-8b76-f97f20eb32c8 tags:
``` python
job_rolling = pr.create.job.ROLLING('damask_job')
```
%% Cell type:markdown id:1c603694-608e-4297-bd15-c587cec182d1 tags:
Now, we use pyiron functinalities to configure our simulation with parameters obtained from `dsms`
%% Cell type:code id:e7707c9c-5dab-4c33-b82e-20373cdd088c tags:
``` python
# Elastic paramaters of the material
elasticity = pr.continuum.damask.Elasticity(**elasticity_data)
```
%% Cell type:code id:0b91a652-f6ce-47cf-92f9-d27fb64ec3e3 tags:
``` python
# Plastic parameters of the material
plasticity = pr.continuum.damask.Plasticity(**plasticity_data)
```
%% Cell type:code id:0455d697-04eb-4bd7-bb1e-8af90aac2ae9 tags:
``` python
# Define phase of the material
phase = pr.continuum.damask.Phase(composition ='DX56D',
lattice = 'cI',
output_list = ['F', 'P'],
elasticity = elasticity,
plasticity = plasticity
)
```
%% Cell type:code id:31322d37-e28a-4111-b81b-c31b79c1b8d0 tags:
``` python
# Define homogenization
homogenization = pr.continuum.damask.Homogenization(method='SX',
parameters={'N_constituents': 1,
"mechanical": {"type": "pass"}})
```
%% Cell type:code id:2040cbbc-be5e-4cd8-8aba-eba59142b468 tags:
``` python
# Defines the number of grains and grids
grains = 60
grids = 16
```
%% Cell type:code id:4f1923bb-6ee3-4af6-8d8d-a8c9134617ed tags:
``` python
# Define homogenization
rotation = pr.continuum.damask.Rotation(Rotation.from_random,
grains)
```
%% Cell type:code id:ceb379cf-fed5-4f75-97bb-f4403b30d400 tags:
``` python
# Materialpoint configuration
material = pr.continuum.damask.Material([rotation],
['DX56D'],
phase,
homogenization)
```
%% Cell type:code id:8a7ea72f-7685-4937-b0fb-d52d8f57a5a3 tags:
``` python
# Define grid
grid = pr.continuum.damask.Grid.via_voronoi_tessellation(spatial_discretization=grids,
num_grains=grains,
box_size=1.6e-5)
```
%% Cell type:code id:d8f30b8c-ad73-4a3d-9c99-c2700c0bb9c9 tags:
``` python
# Assign the material and grid to the damask job
job_rolling.material = material
job_rolling.grid = grid
```
%% Cell type:markdown id:ecdfb5f9-1048-4602-a6f9-74ad7df39f56 tags:
#### <font style="font-family:roboto;color:#455e6c"> Now we are ready to start rolling simulation </font>
%% Cell type:markdown id:fbbe8875-6a12-4992-aa50-0321781d3f30 tags:
Let's do the first rolling
%% Cell type:code id:813b76aa-6367-4bc0-91c7-5acfd855c0e4 tags:
``` python
# Define parameters for first rolling
reduction_height = 0.05
reduction_speed = 5.0e-2
reduction_outputs = 250
regrid_flag = False
damask_exe = ''
```
%% Cell type:code id:e7550ce1-43e1-42a0-ab3a-5861d325e82b tags:
``` python
# Run first rolling simulation
job_rolling.executeRolling(reduction_height,
reduction_speed,
reduction_outputs,
regrid_flag,
damask_exe
)
```
%% Cell type:code id:17662409-eeb4-4b09-a8eb-8baf7b1cc0a2 tags:
``` python
# Process the result after first rolling simulation
job_rolling.postProcess()
```
%% Cell type:code id:6b631b17-4826-477b-9f3a-465e7c4cf417 tags:
``` python
%matplotlib inline
```
%% Cell type:code id:afa2051c-72d7-48cb-8c84-8eddec52038b tags:
``` python
# Plot the result after first rolling simulation
job_rolling.plotStressStrainCurve(0.0,0.60,0.0,6.0e+8) # xmin,xmax, ymin,ymax
plt.show();
```
%% Cell type:markdown id:126aeb39-e4dc-45f3-aa4f-2d7055ec783a tags:
Let's upload the result to dsms
%% Cell type:code id:c7b6df21-7c7a-4e00-b60b-85cb3362d6ea tags:
``` python
# A function to get stress-strain data from a pyiron damask job as dictionary
def get_pyiron_damask_output():
stress_strain_data = {}
stress_strain_data['TrueStrain'] = job_rolling.strain_von_Mises.tolist()
stress_strain_data['TrueStress'] = job_rolling.stress_von_Mises.tolist()
return stress_strain_data
```
%% Cell type:code id:61eb2c2f-1114-4989-a88b-4e4954aeb65e tags:
``` python
# After executing this cell, you have to enter your dsms username
username = getpass()
```
%% Cell type:code id:35b63dea-0d07-4713-96db-e31c7e886e52 tags:
``` python
# After executing this cell, you have to enter your dsms password
password = getpass()
```
%% Cell type:code id:41003d93-d10b-4f2e-ba51-4252dcf814c6 tags:
``` python
# Now we will connect to dsms
dsms = DSMS(host_url="https://stahldigital.materials-data.space",
username=username,
password=password)
```
%% Cell type:code id:73fa5b1a-7037-4599-aae5-a45e42dc22d3 tags:
``` python
# Create new Dataset KItem
item_damask_output = KItem(name='DASMASK output file by Ujjal test',
ktype_id=dsms.ktypes.Dataset,
annotations = [{'iri':'https://w3id.org/steel/ProcessOntology/TrueStrain',
'name':'TrueStrain',
'namespace':'https://w3id.org/steel/ProcessOntology'},
{'iri':'https://w3id.org/steel/ProcessOntology/TrueStress',
'name':'TrueStress',
'namespace':'https://w3id.org/steel/ProcessOntology'}],
#attachments = [{"name": "../resources/Poly_60_16x16x16.vti"}], # in case you have an output vti, you can place it here
# linked_kitems = [input_kitem_id]
)
dsms.commit()
```
%% Cell type:code id:131f1047-cf93-4ae2-b2c8-60b8b3482564 tags:
``` python
print(item_damask_output.id)
```
%% Cell type:code id:f7a83b41-b06c-4ed5-82f6-fb732d0b4a62 tags:
``` python
stress_strain_data = get_pyiron_damask_output()
```
%% Cell type:code id:916dcda6-e33d-4386-aff2-8bbc9662933c tags:
``` python
# fill the kitem with stress-strain data
base_iri = urljoin(str(dsms.config.host_url), str(item_damask_output.id))
download_uri = urljoin(str(dsms.config.host_url), f"api/knowledge/data_api/{item_damask_output.id}")
pipeline = AnnotationPipeline(
raw_data=stress_strain_data,
mapping={
"TrueStrain": {
"iri": "https://w3id.org/steel/ProcessOntology/TrueStrain",
"key": "TrueStrain",
"unit": "http://qudt.org/vocab/unit/NUM",
"value_location": "TrueStrain"
},
"TrueStress": {
"iri": "https://w3id.org/steel/ProcessOntology/TrueStress",
"key": "TrueStress",
"unit": "Pa",
"value_location": "TrueStress"
}
},
parser=Parser.json,
config = {
"base_iri": base_iri,
"data_download_uri": download_uri,
"graph_identifier": base_iri
}
)
item_damask_output.custom_properties = pipeline.plain_metadata
item_damask_output.hdf5 = pd.DataFrame(pipeline.time_series)
dsms.sparql_interface.subgraph.update(pipeline.graph)
dsms.commit()
```
%% Cell type:code id:da3ca64c-1ef3-4c17-b79f-9a8c52f4fe6e tags:
``` python
print(dsms[item_damask_output.id].hdf5.TrueStress.convert_to('Pa'))
```
%% Cell type:markdown id:d0cfb11d-4178-4b27-9a36-97ae0ebbf478 tags:
Now, we will do second rolling
%% Cell type:code id:4642deb5-8727-4050-b6b1-cd84a9613de8 tags:
``` python
# Define parameters for second rolling
reduction_height = 0.1
reduction_speed = 4.5e-2
reduction_outputs = 300
regrid_flag = True
damask_exe = ''
```
%% Cell type:code id:122fc104-e12c-4a3b-88f3-67e9f8ef6aec tags:
``` python
# Run second rolling simulation
job_rolling.executeRolling(reduction_height,
reduction_speed,
reduction_outputs,
regrid_flag,
damask_exe
)
```
%% Cell type:code id:a180e420-a635-4e09-89db-b017b3217622 tags:
``` python
# Process the result after second rolling simulation
job_rolling.postProcess()
```
%% Cell type:code id:28e08cad-45ae-49ff-9f77-3e9ffa698901 tags:
``` python
# Plot the result after second rolling simulation
job_rolling.plotStressStrainCurve(0.0,0.60,0.0,6.0e8) # xmin,xmax, ymin,ymax
plt.show();
```
%% Cell type:markdown id:fac8ad8a-a77b-4209-9736-ec1c944137ea tags:
Third rolling simulation
%% Cell type:code id:0702aaa4-e037-404d-8d34-6bc604d88372 tags:
``` python
# Define parameters for third rolling
reduction_height = 0.1
reduction_speed = 4.5e-2
reduction_outputs = 350
regrid_flag = True
damask_exe = ''
```
%% Cell type:code id:f919ffdf-0f27-4d74-bba0-d14c20faf0c4 tags:
``` python
# Run third rolling simulation
job_rolling.executeRolling(reduction_height,
reduction_speed,
reduction_outputs,
regrid_flag,
damask_exe
)
```
%% Cell type:code id:3ef7ed31-bae2-4655-aff3-c0e279b394bf tags:
``` python
# Process the result after third rolling simulation
job_rolling.postProcess()
```
%% Cell type:code id:b091cd24-4dc4-40b3-a7fe-f21c94cfedcb tags:
``` python
# Plot the result after third rolling simulation
job_rolling.plotStressStrainCurve(0.0,0.60,0.0,6.0e+8) # xmin,xmax, ymin,ymax
plt.show();
```
%% Cell type:markdown id:3d95a445-b83c-4afa-9d35-fcd41d5c0d6a tags:
Forth rolling simulation
%% Cell type:code id:c7e25f6e-8290-469c-b1e3-5c8dd9d57c17 tags:
``` python
# Define parameters for forth rolling
reduction_height = 0.12
reduction_speed = 4.25e-2
reduction_outputs = 300
regrid_flag = True
damask_exe = ''
```
%% Cell type:code id:44f66a76-2b28-483c-9ba0-528961317dbb tags:
``` python
# Run forth rolling simulation
job_rolling.executeRolling(reduction_height,
reduction_speed,
reduction_outputs,
regrid_flag,
damask_exe
)
```
%% Cell type:code id:ea1df326-da41-4099-bd62-6d72509f6abc tags:
``` python
# Process the result after forth rolling simulation
job_rolling.postProcess()
```
%% Cell type:code id:3548cd0f-7b4a-4f2b-884d-498426684c03 tags:
``` python
# Plot the result after forth rolling simulation
job_rolling.plotStressStrainCurve(0.0,0.60,0.0,6.0e+8) # xmin,xmax, ymin,ymax
plt.show();
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment