Skip to content

Commit

Permalink
Merge branch 'test-examples-with-doctest' into 'development'
Browse files Browse the repository at this point in the history
example output tested with doctest

See merge request damask/DAMASK!951
  • Loading branch information
dmentock committed Jun 18, 2024
2 parents 514b84f + 60389f3 commit 0166334
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.pdf binary
*.dream3d binary
*.pbz2 binary
*.vtk binary

# ignore files from MSC.Marc in language statistics
install/MarcMentat/** linguist-vendored
Expand Down
2 changes: 2 additions & 0 deletions python/damask/_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def from_range(low: FloatSequence,
--------
>>> import damask
>>> damask.Colormap.from_range((0,0,1),(0,0,0),'blue_to_black')
Colormap: blue_to_black
"""
toMsh = dict(
Expand Down Expand Up @@ -248,6 +249,7 @@ def from_predefined(name: str,
--------
>>> import damask
>>> damask.Colormap.from_predefined('strain')
Colormap: strain
"""
if name in cm.__dict__:
Expand Down
188 changes: 114 additions & 74 deletions python/damask/_configmaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,42 +197,43 @@ def from_table(table: Table,*,
Examples
--------
>>> import damask
>>> import damask.ConfigMaterial as cm
>>> from damask import ConfigMaterial as cm
>>> t = damask.Table.load('small.txt')
>>> t
3:pos pos pos 4:qu qu qu qu phase homog
0 0 0 0 0.19 0.8 0.24 -0.51 Aluminum SX
1 1 0 0 0.8 0.19 0.24 -0.51 Steel SX
2 1 1 0 0.8 0.19 0.24 -0.51 Steel SX
3:pos pos pos 4:qu qu qu qu phase homog
0 0 0 0 1.0 0.0 0.0 0.0 Aluminum SX
1 1 0 0 0.0 1.0 0.0 0.0 Steel SX
2 1 1 0 0.0 1.0 0.0 0.0 Steel SX
>>> cm.from_table(t,O='qu',phase='phase',homogenization='homog')
material:
- constituents:
- O: [0.19, 0.8, 0.24, -0.51]
v: 1.0
phase: Aluminum
homogenization: SX
- constituents:
- O: [0.8, 0.19, 0.24, -0.51]
v: 1.0
phase: Steel
homogenization: SX
homogenization: {SX: null}
phase: {Aluminum: null, Steel: null}
material:
- constituents:
- phase: Aluminum
O: [1.0, 0.0, 0.0, 0.0]
v: 1.0
homogenization: SX
- constituents:
- phase: Steel
O: [0.0, 1.0, 0.0, 0.0]
v: 1.0
homogenization: SX
>>> cm.from_table(t,O='qu',phase='phase',homogenization='single_crystal')
material:
- constituents:
- O: [0.19, 0.8, 0.24, -0.51]
v: 1.0
phase: Aluminum
homogenization: single_crystal
- constituents:
- O: [0.8, 0.19, 0.24, -0.51]
v: 1.0
phase: Steel
homogenization: single_crystal
homogenization: {single_crystal: null}
phase: {Aluminum: null, Steel: null}
material:
- constituents:
- phase: Aluminum
O: [1.0, 0.0, 0.0, 0.0]
v: 1.0
homogenization: single_crystal
- constituents:
- phase: Steel
O: [0.0, 1.0, 0.0, 0.0]
v: 1.0
homogenization: single_crystal
"""
kwargs = {}
Expand Down Expand Up @@ -463,74 +464,113 @@ def material_add(self,*,
>>> import damask
>>> m = damask.ConfigMaterial()
>>> m = m.material_add(phase = ['Ferrite','Martensite','Ferrite'],
... O = damask.Rotation.from_random(3),
... O = damask.Rotation.from_random(3,rng_seed=20191102),
... homogenization = 'SX')
>>> m
homogenization: {SX: null}
phase: {Ferrite: null, Martensite: null}
material:
- constituents:
- O: [0.577764, -0.146299, -0.617669, 0.513010]
- phase: Ferrite
O: [0.0047, -0.9582, 0.1084, 0.2645]
v: 1.0
phase: Ferrite
homogenization: SX
- constituents:
- O: [0.184176, 0.340305, 0.737247, 0.553840]
- phase: Martensite
O: [0.9147, -0.1907, 0.2901, -0.2068]
v: 1.0
phase: Martensite
homogenization: SX
- constituents:
- O: [0.47925185, -0.04294454, 0.78760173, -0.3849116 ]
- phase: Ferrite
O: [0.1068, -0.4427, 0.1369, 0.8797]
v: 1.0
phase: Ferrite
homogenization: SX
homogenization: {SX: null}
phase: {Ferrite: null, Martensite: null}
Create hundred materials that each approximate a duplex stainless steel microstructure
Create five materials that each approximate a duplex stainless steel microstructure
with three austenite and one relatively bigger ferrite grain of random orientation each:
>>> import numpy as np
>>> import damask
>>> m = damask.ConfigMaterial()
>>> m = m.material_add(phase = np.array(['Austenite']*3+['Ferrite']),
... O = damask.Rotation.from_random((100,4)),
... v = np.array([0.2]*3+[0.4]),
>>> N_materials = 5
>>> m = m.material_add(phase = np.array([['Austenite']*3+['Ferrite']]),
... O = damask.Rotation.from_random((N_materials,4),rng_seed=20191102),
... v = np.array([[0.2]*3+[0.4]]),
... homogenization = 'Taylor')
>>> m
material:
- constituents:
- v: 0.2
phase: Austenite
O: [0.46183665006602664, 0.2215160420973196, -0.5594313187331139, 0.6516702781083836]
- v: 0.2
phase: Austenite
O: [0.11321658382410027, 0.6354079414360444, 0.00562701344273936, 0.7638108992590535]
- v: 0.2
phase: Austenite
O: [0.050991978809077604, 0.8069522034362003, -0.11352928955610851, -0.5773552285027659]
- v: 0.4
phase: Ferrite
O: [0.9460076150721788, 0.15880754622367604, -0.0069841062241482385, -0.28249066842661014]
homogenization: Taylor
.
.
.
- constituents:
- v: 0.2
phase: Austenite
O: [0.12531400788494199, -0.18637769037997565, 0.31737548053338394, -0.9213210951197429]
- v: 0.2
phase: Austenite
O: [0.37453930577161404, -0.33529507696450805, -0.3266564259130028, -0.800370601162502]
- v: 0.2
phase: Austenite
O: [0.035776891752713764, -0.720706371010592, -0.4540438656728926, -0.5226342017569017]
- v: 0.4
phase: Ferrite
O: [0.6782596727966124, -0.20800082041703685, -0.138636083554039, 0.6909989227925536]
homogenization: Taylor
homogenization: {Taylor: null}
phase: {Austenite: null, Ferrite: null}
material:
- constituents:
- phase: Austenite
v: 0.2
O: [0.004702411137213036, -0.9582446864633862, 0.1084379916089085, 0.2645490694937509]
- phase: Austenite
v: 0.2
O: [0.9147097460704486, -0.19068436891182194, 0.29014401444532145, -0.20678975501215882]
- phase: Austenite
v: 0.2
O: [0.10677819003833185, -0.4427133706883004, 0.13690394495734726, 0.879693468999888]
- phase: Ferrite
v: 0.4
O: [0.8664338002923555, 0.04448357787828491, -0.4945927532088464, 0.05188149461403649]
homogenization: Taylor
- constituents:
- phase: Austenite
v: 0.2
O: [0.5621873738314133, 0.0028841916095125584, -0.817023371343172, -0.1281009321680984]
- phase: Austenite
v: 0.2
O: [0.1566777437467901, -0.8117282158019414, 0.5096142534839398, 0.23841707348975383]
- phase: Austenite
v: 0.2
O: [0.3559036203819333, 0.1946923701552408, 0.058744995087853975, -0.9121274689178566]
- phase: Ferrite
v: 0.4
O: [0.467387781713959, -0.35644325887489176, 0.8031986430613528, 0.09679258489963502]
homogenization: Taylor
- constituents:
- phase: Austenite
v: 0.2
O: [0.4399087544327661, 0.12802483830067418, -0.8257167208737983, 0.32906203886337354]
- phase: Austenite
v: 0.2
O: [0.12410381094181624, -0.5125024631828828, -0.8493860709598213, 0.021972068647108236]
- phase: Austenite
v: 0.2
O: [0.03909373022192218, 0.4596226773046959, 0.42809626138739537, 0.7771436583738773]
- phase: Ferrite
v: 0.4
O: [0.737821660605232, 0.38809925187040367, -0.012129167758963711, 0.5521331824196455]
homogenization: Taylor
- constituents:
- phase: Austenite
v: 0.2
O: [0.4924738838478857, -0.0534798919571679, -0.6570981342247908, 0.5681825559468784]
- phase: Austenite
v: 0.2
O: [0.13073521303792138, 0.2534173177988532, -0.9582490914178947, -0.021133998872519554]
- phase: Austenite
v: 0.2
O: [0.1633346595899539, 0.6775968809652247, -0.07127256805012916, -0.71351557581203]
- phase: Ferrite
v: 0.4
O: [0.7658044627436773, -0.5327872540278646, 0.1102330397070761, 0.34282640467772235]
homogenization: Taylor
- constituents:
- phase: Austenite
v: 0.2
O: [0.25814496892598815, -0.6159961898524933, -0.5080223627084379, 0.543896265930874]
- phase: Austenite
v: 0.2
O: [0.8497433829153472, 0.4264182767672584, 0.05570674517418605, -0.3049596612218108]
- phase: Austenite
v: 0.2
O: [0.5146112784760113, 0.529467219604771, 0.661078636611197, 0.13347183839881469]
- phase: Ferrite
v: 0.4
O: [0.18430893147208752, 0.012407731059331692, -0.5551804816056372, -0.8109567798802285]
homogenization: Taylor
"""
dim = {'O':(4,),'V_e':(3,3,)}
Expand Down
21 changes: 11 additions & 10 deletions python/damask/_geomgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ def load_Neper(fname: Union[str, Path]) -> 'GeomGrid':
>>> N_grains = 20
>>> cells = (32,32,32)
>>> damask.util.run(f'neper -T -n {N_grains} -tesrsize {cells[0]}:{cells[1]}:{cells[2]} -periodicity all -format vtk')
running 'neper -T -n 20 -tesrsize 32:32:32 -periodicity all -format vtk' ...
>>> damask.GeomGrid.load_Neper(f'n{N_grains}-id1.vtk').renumber()
cells: 32 × 32 × 32
size: 1.0 × 1.0 × 1.0 m³
Expand Down Expand Up @@ -736,8 +737,8 @@ def from_minimal_surface(cells: IntSequence,
>>> import numpy as np
>>> import damask
>>> damask.GeomGrid.from_minimal_surface([64]*3,np.ones(3)*1.e-4,'Gyroid')
cells : 64 × 64 × 64
size : 0.0001 × 0.0001 × 0.0001 m³
cells: 64 × 64 × 64
size: 0.0001 × 0.0001 × 0.0001 m³
origin: 0.0 0.0 0.0 m
# materials: 2
Expand All @@ -747,8 +748,8 @@ def from_minimal_surface(cells: IntSequence,
>>> import damask
>>> damask.GeomGrid.from_minimal_surface([80]*3,np.ones(3)*5.e-4,
... 'Neovius',materials=(1,5))
cells : 80 × 80 × 80
size : 0.0005 × 0.0005 × 0.0005 m³
cells: 80 × 80 × 80
size: 0.0005 × 0.0005 × 0.0005 m³
origin: 0.0 0.0 0.0 m
# materials: 2 (min: 1, max: 5)
Expand Down Expand Up @@ -1087,8 +1088,8 @@ def scale(self,
origin: 0.0 0.0 0.0 m
# materials: 1
>>> g.scale(g.cells*2)
cells : 64 × 64 × 64
size : 0.0001 × 0.0001 × 0.0001 m³
cells: 64 × 64 × 64
size: 0.0001 × 0.0001 × 0.0001 m³
origin: 0.0 0.0 0.0 m
# materials: 1
Expand Down Expand Up @@ -1328,8 +1329,8 @@ def add_primitive(self,
>>> import damask
>>> g = damask.GeomGrid(np.zeros([64]*3,int), np.ones(3)*1e-4)
>>> g.add_primitive(np.ones(3)*5e-5,np.ones(3)*5e-5,1)
cells : 64 × 64 × 64
size : 0.0001 × 0.0001 × 0.0001 m³
cells: 64 × 64 × 64
size: 0.0001 × 0.0001 × 0.0001 m³
origin: 0.0 0.0 0.0 m
# materials: 2
Expand All @@ -1339,8 +1340,8 @@ def add_primitive(self,
>>> import damask
>>> g = damask.GeomGrid(np.zeros([64]*3,int), np.ones(3)*1e-4)
>>> g.add_primitive(np.ones(3,int)*32,np.zeros(3),np.inf)
cells : 64 × 64 × 64
size : 0.0001 × 0.0001 × 0.0001 m³
cells: 64 × 64 × 64
size: 0.0001 × 0.0001 × 0.0001 m³
origin: 0.0 0.0 0.0 m
# materials: 2
Expand Down
Loading

0 comments on commit 0166334

Please sign in to comment.