From adb1e51e24833929a600c9c19852f3bb245494a1 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 25 May 2021 22:31:54 +0200 Subject: [PATCH] support for 2D tensor in load case currently optional, but should become mandatory after a transition period --- examples/grid/shearXY.yaml | 4 +-- examples/grid/shearZX.yaml | 4 +-- examples/grid/tensionX.yaml | 24 ++++++++-------- python/damask/_config.py | 7 +++-- src/grid/DAMASK_grid.f90 | 55 +++++++++++++++++++++++-------------- 5 files changed, 52 insertions(+), 42 deletions(-) diff --git a/examples/grid/shearXY.yaml b/examples/grid/shearXY.yaml index 58471e8f1..900877533 100644 --- a/examples/grid/shearXY.yaml +++ b/examples/grid/shearXY.yaml @@ -6,9 +6,7 @@ solver: loadstep: - boundary_conditions: mechanical: - dot_F: [0, 0, 0, - 1e-3, 0, 0, - 0, 0, 0] + dot_F: [ [0, 0, 0], [1e-3, 0, 0], [0, 0, 0] ] discretization: t: 60 N: 120 diff --git a/examples/grid/shearZX.yaml b/examples/grid/shearZX.yaml index a32fafb85..0d47e6c8b 100644 --- a/examples/grid/shearZX.yaml +++ b/examples/grid/shearZX.yaml @@ -6,9 +6,7 @@ solver: loadstep: - boundary_conditions: mechanical: - dot_F: [0, 0, 1e-3, - 0, 0, 0, - 0, 0, 0] + dot_F: [[0, 0, 1e-3], [0, 0, 0], [0, 0, 0]] discretization: t: 60 N: 120 diff --git a/examples/grid/tensionX.yaml b/examples/grid/tensionX.yaml index 870755d58..154ae4a60 100644 --- a/examples/grid/tensionX.yaml +++ b/examples/grid/tensionX.yaml @@ -6,24 +6,24 @@ solver: loadstep: - boundary_conditions: mechanical: - dot_F: [1.0e-3, 0, 0, - 0, x, 0, - 0, 0, x] - P: [x, x, x, - x, 0, x, - x, x, 0] + dot_F: [[1.0e-3, 0, 0], + [0, x, 0], + [0, 0, x]] + P: [[x, x, x], + [x, 0, x], + [x, x, 0]] discretization: t: 10 N: 40 f_out: 4 - boundary_conditions: mechanical: - dot_F: [1.0e-3, 0, 0, - 0, x, 0, - 0, 0, x] - P: [x, x, x, - x, 0, x, - x, x, 0] + dot_F: [[1.0e-3, 0, 0], + [0, x, 0], + [0, 0, x]] + P: [[x, x, x], + [x, 0, x], + [x, x, 0]] discretization: t: 60 N: 60 diff --git a/python/damask/_config.py b/python/damask/_config.py index 627fc88c8..9b3adf491 100644 --- a/python/damask/_config.py +++ b/python/damask/_config.py @@ -7,7 +7,6 @@ import numpy as np import yaml from . import Rotation -from . import Orientation class NiceDumper(yaml.SafeDumper): """Make YAML readable for humans.""" @@ -25,8 +24,10 @@ class NiceDumper(yaml.SafeDumper): """Cast Config objects and its subclasses to dict.""" if isinstance(data, dict) and type(data) != dict: return self.represent_data(dict(data)) - if isinstance(data, (Rotation, Orientation)): - return self.represent_data(data.as_quaternion()) + if isinstance(data, np.ndarray): + return self.represent_data(data.tolist()) + if isinstance(data, Rotation): + return self.represent_data(data.quaternion.tolist()) else: return super().represent_data(data) diff --git a/src/grid/DAMASK_grid.f90 b/src/grid/DAMASK_grid.f90 index 991c39024..588fc1c77 100644 --- a/src/grid/DAMASK_grid.f90 +++ b/src/grid/DAMASK_grid.f90 @@ -107,9 +107,7 @@ program DAMASK_grid thermal, & step_bc, & step_mech, & - step_discretization, & - step_deformation, & - step_stress + step_discretization !-------------------------------------------------------------------------------------------------- ! init DAMASK (all modules) @@ -198,26 +196,10 @@ program DAMASK_grid select case (step_mech%getKey(m)) case ('L','dot_F','F') ! assign values for the deformation BC matrix loadCases(l)%deformation%myType = step_mech%getKey(m) - step_deformation => step_mech%get(m) - - temp_valueVector = 0.0_pReal - do j = 1, 9 - temp_maskVector(j) = step_deformation%get_asString(j) /= 'x' - if (temp_maskVector(j)) temp_valueVector(j) = step_deformation%get_asFloat(j) - enddo - loadCases(l)%deformation%mask = transpose(reshape(temp_maskVector,[3,3])) - loadCases(l)%deformation%values = math_9to33(temp_valueVector) + call getMaskedTensor(loadCases(l)%deformation%values,loadCases(l)%deformation%mask,step_mech%get(m)) case ('dot_P','P') loadCases(l)%stress%myType = step_mech%getKey(m) - step_stress => step_mech%get(m) - - temp_valueVector = 0.0_pReal - do j = 1, 9 - temp_maskVector(j) = step_stress%get_asString(j) /= 'x' - if (temp_maskVector(j)) temp_valueVector(j) = step_stress%get_asFloat(j) - enddo - loadCases(l)%stress%mask = transpose(reshape(temp_maskVector,[3,3])) - loadCases(l)%stress%values = math_9to33(temp_valueVector) + call getMaskedTensor(loadCases(l)%stress%values,loadCases(l)%stress%mask,step_mech%get(m)) end select call loadCases(l)%rot%fromAxisAngle(step_mech%get_as1dFloat('R',defaultVal = real([0.0,0.0,1.0,0.0],pReal)),degrees=.true.) enddo readMech @@ -487,4 +469,35 @@ program DAMASK_grid call quit(0) ! no complains ;) + +contains + +subroutine getMaskedTensor(values,mask,tensor) + + real(pReal), intent(out), dimension(3,3) :: values + logical, intent(out), dimension(3,3) :: mask + class (tNode), pointer :: tensor + + class (tNode), pointer :: row + integer :: i,j + + + values = 0.0 + if (tensor%length == 9) then ! temporary support for deprecated 1D tensor + do i = 1,9 + mask((i-1)/3+1,mod(i-1,3)+1) = tensor%get_asString(i) /= 'x' + if (mask((i-1)/3+1,mod(i-1,3)+1)) values((i-1)/3+1,mod(i-1,3)+1) = tensor%get_asFloat(i) + enddo + else + do i = 1,3 + row => tensor%get(i) + do j = 1,3 + mask(i,j) = row%get_asString(j) /= 'x' ! ToDo change to np.masked behavior + if (mask(i,j)) values(i,j) = row%get_asFloat(j) + enddo + enddo + endif + +end subroutine + end program DAMASK_grid