From 69857176b2311513da4f4fcd824923ca4f097274 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 Apr 2020 11:13:07 +0200 Subject: [PATCH 1/5] search and replace error --- python/damask/grid_filters.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/damask/grid_filters.py b/python/damask/grid_filters.py index 8106ed905..5134fd15e 100644 --- a/python/damask/grid_filters.py +++ b/python/damask/grid_filters.py @@ -41,8 +41,8 @@ def curl(size,field): e[0, 2, 1] = e[2, 1, 0] = e[1, 0, 2] = -1.0 field_fourier = _np.fft.rfftn(field,axes=(0,1,2)) - curl_ = (_np.einsum('slm,ijkl,ijkm ->ijks', e,k_s,field_fourier)*2.0j*_np.pi if n == 3 else # vector, 3 -> 3 - _np.einsum('slm,ijkl,ijknm->ijksn',e,k_s,field_fourier)*2.0j*_np.pi) # tensor, 3x3 -> 3x3 + curl_ = (_np.einsum('slm,ijkl,ijkm ->ijks', e,k_s,field_fourier)*2.0j*_np.pi if n == 3 else # vector, 3 -> 3 + _np.einsum('slm,ijkl,ijknm->ijksn',e,k_s,field_fourier)*2.0j*_np.pi) # tensor, 3x3 -> 3x3 return _np.fft.irfftn(curl_,axes=(0,1,2),s=field.shape[:3]) @@ -61,8 +61,8 @@ def divergence(size,field): k_s = _ks(size,field.shape[:3],True) field_fourier = _np.fft.rfftn(field,axes=(0,1,2)) - div_ = (_np.einsum('ijkl,ijkl ->ijk', k_s,field_fourier)*2.0j*_np.pi if n == 3 else # vector, 3 -> 1 - _np.einsum('ijkm,ijklm->ijkl',k_s,field_fourier)*2.0j*_np.pi) # tensor, 3x3 -> 3 + div_ = (_np.einsum('ijkl,ijkl ->ijk', k_s,field_fourier)*2.0j*_np.pi if n == 3 else # vector, 3 -> 1 + _np.einsum('ijkm,ijklm->ijkl',k_s,field_fourier)*2.0j*_np.pi) # tensor, 3x3 -> 3 return _np.fft.irfftn(div_,axes=(0,1,2),s=field.shape[:3]) @@ -81,8 +81,8 @@ def gradient(size,field): k_s = _ks(size,field.shape[:3],True) field_fourier = _np.fft.rfftn(field,axes=(0,1,2)) - grad_ = (_np.einsum('ijkl,ijkm->ijkm', field_fourier,k_s)*2.0j*_np.pi if n == 1 else # scalar, 1 -> 3 - _np.einsum('ijkl,ijkm->ijklm',field_fourier,k_s)*2.0j*_np.pi) # vector, 3 -> 3x3 + grad_ = (_np.einsum('ijkl,ijkm->ijkm', field_fourier,k_s)*2.0j*_np.pi if n == 1 else # scalar, 1 -> 3 + _np.einsum('ijkl,ijkm->ijklm',field_fourier,k_s)*2.0j*_np.pi) # vector, 3 -> 3x3 return _np.fft.irfftn(grad_,axes=(0,1,2),s=field.shape[:3]) @@ -217,7 +217,7 @@ def cell_coord0_gridSizeOrigin(coord0,ordered=True): raise ValueError('Regular grid spacing violated.') if ordered and not _np.allclose(coord0.reshape(tuple(grid[::-1])+(3,)),cell_coord0(grid,size,origin)): - raise ValueError('I_nput data is not a regular grid.') + raise ValueError('Input data is not a regular grid.') return (grid,size,origin) @@ -363,7 +363,7 @@ def node_coord0_gridSizeOrigin(coord0,ordered=False): raise ValueError('Regular grid spacing violated.') if ordered and not _np.allclose(coord0.reshape(tuple((grid+1)[::-1])+(3,)),node_coord0(grid,size,origin)): - raise ValueError('I_nput data is not a regular grid.') + raise ValueError('Input data is not a regular grid.') return (grid,size,origin) From a4c52ec1fad29359a1faa889f6cb7456e676b2b7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 15 Apr 2020 21:56:20 +0200 Subject: [PATCH 2/5] extra variable not needed --- src/homogenization.f90 | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/homogenization.f90 b/src/homogenization.f90 index 8b6d80089..62150899e 100644 --- a/src/homogenization.f90 +++ b/src/homogenization.f90 @@ -184,8 +184,6 @@ subroutine materialpoint_stressAndItsTangent(updateJaco,dt) e, & !< element number mySource, & myNgrains - real(pReal), dimension(3,3) :: & - subF real(pReal), dimension(discretization_nIP,discretization_nElem) :: & subFrac, & subStep @@ -376,16 +374,15 @@ subroutine materialpoint_stressAndItsTangent(updateJaco,dt) !-------------------------------------------------------------------------------------------------- ! deformation partitioning -! based on materialpoint_subF0,.._subF,crystallite_partionedF0, and homogenization_state, -! results in crystallite_partionedF - !$OMP PARALLEL DO PRIVATE(myNgrains,subF) + !$OMP PARALLEL DO PRIVATE(myNgrains) elementLooping2: do e = FEsolving_execElem(1),FEsolving_execElem(2) myNgrains = homogenization_Ngrains(material_homogenizationAt(e)) IpLooping2: do i = FEsolving_execIP(1),FEsolving_execIP(2) if(requested(i,e) .and. .not. doneAndHappy(1,i,e)) then ! requested but not yet done - subF = materialpoint_F0(1:3,1:3,i,e) & - + (materialpoint_F(1:3,1:3,i,e)-materialpoint_F0(1:3,1:3,i,e))*(subStep(i,e)+subFrac(i,e)) - call partitionDeformation(subF,i,e) ! partition deformation onto constituents + call partitionDeformation(materialpoint_F0(1:3,1:3,i,e) & + + (materialpoint_F(1:3,1:3,i,e)-materialpoint_F0(1:3,1:3,i,e))& + *(subStep(i,e)+subFrac(i,e)), & + i,e) crystallite_dt(1:myNgrains,i,e) = dt*subStep(i,e) ! propagate materialpoint dt to grains crystallite_requested(1:myNgrains,i,e) = .true. ! request calculation for constituents else @@ -397,23 +394,22 @@ subroutine materialpoint_stressAndItsTangent(updateJaco,dt) !-------------------------------------------------------------------------------------------------- ! crystallite integration -! based on crystallite_partionedF0,.._partionedF -! incrementing by crystallite_dt - converged = crystallite_stress() !ToDo: MD not sure if that is the best logic !-------------------------------------------------------------------------------------------------- ! state update - !$OMP PARALLEL DO PRIVATE(subF) + !$OMP PARALLEL DO elementLooping3: do e = FEsolving_execElem(1),FEsolving_execElem(2) IpLooping3: do i = FEsolving_execIP(1),FEsolving_execIP(2) if (requested(i,e) .and. .not. doneAndHappy(1,i,e)) then if (.not. converged(i,e)) then doneAndHappy(1:2,i,e) = [.true.,.false.] else - subF = materialpoint_F0(1:3,1:3,i,e) & - + (materialpoint_F(1:3,1:3,i,e)-materialpoint_F0(1:3,1:3,i,e))*(subStep(i,e)+subFrac(i,e)) - doneAndHappy(1:2,i,e) = updateState(dt*subStep(i,e),subF,i,e) + doneAndHappy(1:2,i,e) = updateState(dt*subStep(i,e), & + materialpoint_F0(1:3,1:3,i,e) & + + (materialpoint_F(1:3,1:3,i,e)-materialpoint_F0(1:3,1:3,i,e)) & + *(subStep(i,e)+subFrac(i,e)), & + i,e) converged(i,e) = all(doneAndHappy(1:2,i,e)) ! converged if done and happy endif endif From e06251e53eb48986d53db06f95412557398c9308 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 19 Apr 2020 14:20:34 +0200 Subject: [PATCH 3/5] proper doxygen style --- src/quaternions.f90 | 76 ++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/quaternions.f90 b/src/quaternions.f90 index 8d62fe6aa..991f970ab 100644 --- a/src/quaternions.f90 +++ b/src/quaternions.f90 @@ -63,27 +63,27 @@ module quaternions module procedure assign_quat__ module procedure assign_vec__ end interface assignment (=) - + interface quaternion module procedure init__ end interface quaternion - + interface abs procedure abs__ end interface abs - + interface dot_product procedure dot_product__ end interface dot_product - + interface conjg module procedure conjg__ end interface conjg - + interface exp module procedure exp__ end interface exp - + interface log module procedure log__ end interface log @@ -95,7 +95,7 @@ module quaternions interface aimag module procedure aimag__ end interface aimag - + public :: & quaternions_init, & assignment(=), & @@ -118,7 +118,7 @@ end subroutine quaternions_init !--------------------------------------------------------------------------------------------------- -!> construct a quaternion from a 4-vector +!> @brief construct a quaternion from a 4-vector !--------------------------------------------------------------------------------------------------- type(quaternion) pure function init__(array) @@ -133,7 +133,7 @@ end function init__ !--------------------------------------------------------------------------------------------------- -!> assign a quaternion +!> @brief assign a quaternion !--------------------------------------------------------------------------------------------------- elemental pure subroutine assign_quat__(self,other) @@ -141,12 +141,12 @@ elemental pure subroutine assign_quat__(self,other) type(quaternion), intent(in) :: other self = [other%w,other%x,other%y,other%z] - + end subroutine assign_quat__ !--------------------------------------------------------------------------------------------------- -!> assign a 4-vector +!> @brief assign a 4-vector !--------------------------------------------------------------------------------------------------- pure subroutine assign_vec__(self,other) @@ -162,7 +162,7 @@ end subroutine assign_vec__ !--------------------------------------------------------------------------------------------------- -!> add a quaternion +!> @brief add a quaternion !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function add__(self,other) @@ -170,24 +170,24 @@ type(quaternion) elemental pure function add__(self,other) add__ = [ self%w, self%x, self%y ,self%z] & + [other%w, other%x, other%y,other%z] - + end function add__ !--------------------------------------------------------------------------------------------------- -!> return (unary positive operator) +!> @brief return (unary positive operator) !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function pos__(self) class(quaternion), intent(in) :: self pos__ = self * (+1.0_pReal) - + end function pos__ !--------------------------------------------------------------------------------------------------- -!> subtract a quaternion +!> @brief subtract a quaternion !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function sub__(self,other) @@ -195,24 +195,24 @@ type(quaternion) elemental pure function sub__(self,other) sub__ = [ self%w, self%x, self%y ,self%z] & - [other%w, other%x, other%y,other%z] - + end function sub__ !--------------------------------------------------------------------------------------------------- -!> negate (unary negative operator) +!> @brief negate (unary negative operator) !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function neg__(self) class(quaternion), intent(in) :: self neg__ = self * (-1.0_pReal) - + end function neg__ !--------------------------------------------------------------------------------------------------- -!> multiply with a quaternion +!> @brief multiply with a quaternion !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function mul_quat__(self,other) @@ -227,7 +227,7 @@ end function mul_quat__ !--------------------------------------------------------------------------------------------------- -!> multiply with a scalar +!> @brief multiply with a scalar !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function mul_scal__(self,scal) @@ -235,12 +235,12 @@ type(quaternion) elemental pure function mul_scal__(self,scal) real(pReal), intent(in) :: scal mul_scal__ = [self%w,self%x,self%y,self%z]*scal - + end function mul_scal__ !--------------------------------------------------------------------------------------------------- -!> divide by a quaternion +!> @brief divide by a quaternion !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function div_quat__(self,other) @@ -252,7 +252,7 @@ end function div_quat__ !--------------------------------------------------------------------------------------------------- -!> divide by a scalar +!> @brief divide by a scalar !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function div_scal__(self,scal) @@ -265,7 +265,7 @@ end function div_scal__ !--------------------------------------------------------------------------------------------------- -!> test equality +!> @brief test equality !--------------------------------------------------------------------------------------------------- logical elemental pure function eq__(self,other) @@ -278,7 +278,7 @@ end function eq__ !--------------------------------------------------------------------------------------------------- -!> test inequality +!> @brief test inequality !--------------------------------------------------------------------------------------------------- logical elemental pure function neq__(self,other) @@ -290,7 +290,7 @@ end function neq__ !--------------------------------------------------------------------------------------------------- -!> raise to the power of a quaternion +!> @brief raise to the power of a quaternion !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function pow_quat__(self,expon) @@ -303,7 +303,7 @@ end function pow_quat__ !--------------------------------------------------------------------------------------------------- -!> raise to the power of a scalar +!> @brief raise to the power of a scalar !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function pow_scal__(self,expon) @@ -316,7 +316,7 @@ end function pow_scal__ !--------------------------------------------------------------------------------------------------- -!> take exponential +!> @brief take exponential !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function exp__(a) @@ -336,7 +336,7 @@ end function exp__ !--------------------------------------------------------------------------------------------------- -!> take logarithm +!> @brief take logarithm !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function log__(a) @@ -356,7 +356,7 @@ end function log__ !--------------------------------------------------------------------------------------------------- -!> return norm +!> @brief return norm !--------------------------------------------------------------------------------------------------- real(pReal) elemental pure function abs__(self) @@ -368,7 +368,7 @@ end function abs__ !--------------------------------------------------------------------------------------------------- -!> calculate dot product +!> @brief calculate dot product !--------------------------------------------------------------------------------------------------- real(pReal) elemental pure function dot_product__(a,b) @@ -380,7 +380,7 @@ end function dot_product__ !--------------------------------------------------------------------------------------------------- -!> take conjugate complex +!> @brief take conjugate complex !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function conjg__(self) @@ -392,7 +392,7 @@ end function conjg__ !--------------------------------------------------------------------------------------------------- -!> homomorph +!> @brief homomorph !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function homomorphed(self) @@ -404,7 +404,7 @@ end function homomorphed !--------------------------------------------------------------------------------------------------- -!> return as plain array +!> @brief return as plain array !--------------------------------------------------------------------------------------------------- pure function asArray(self) @@ -417,7 +417,7 @@ end function asArray !--------------------------------------------------------------------------------------------------- -!> real part (scalar) +!> @brief real part (scalar) !--------------------------------------------------------------------------------------------------- pure function real__(self) @@ -430,7 +430,7 @@ end function real__ !--------------------------------------------------------------------------------------------------- -!> imaginary part (3-vector) +!> @brief imaginary part (3-vector) !--------------------------------------------------------------------------------------------------- pure function aimag__(self) @@ -443,7 +443,7 @@ end function aimag__ !--------------------------------------------------------------------------------------------------- -!> inverse +!> @brief inverse !--------------------------------------------------------------------------------------------------- type(quaternion) elemental pure function inverse(self) From bce5ed62d5813cee8e112940ca434d61aad90cda Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 20 Apr 2020 10:13:15 +0200 Subject: [PATCH 4/5] polishing --- python/damask/grid_filters.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/damask/grid_filters.py b/python/damask/grid_filters.py index 5134fd15e..d8b136a6b 100644 --- a/python/damask/grid_filters.py +++ b/python/damask/grid_filters.py @@ -146,7 +146,7 @@ def cell_displacement_avg(size,F): """ F_avg = _np.average(F,axis=(0,1,2)) - return _np.einsum('ml,ijkl->ijkm',F_avg-_np.eye(3),cell_coord0(F.shape[:3][::-1],size)) + return _np.einsum('ml,ijkl->ijkm',F_avg - _np.eye(3),cell_coord0(F.shape[:3][::-1],size)) def cell_displacement(size,F): @@ -250,8 +250,8 @@ def node_coord0(grid,size,origin=_np.zeros(3)): """ return _np.mgrid[origin[0]:size[0]+origin[0]:(grid[0]+1)*1j, - origin[1]:size[1]+origin[1]:(grid[1]+1)*1j, - origin[2]:size[2]+origin[2]:(grid[2]+1)*1j].T + origin[1]:size[1]+origin[1]:(grid[1]+1)*1j, + origin[2]:size[2]+origin[2]:(grid[2]+1)*1j].T def node_displacement_fluct(size,F): @@ -282,7 +282,7 @@ def node_displacement_avg(size,F): """ F_avg = _np.average(F,axis=(0,1,2)) - return _np.einsum('ml,ijkl->ijkm',F_avg-_np.eye(3),node_coord0(F.shape[:3][::-1],size)) + return _np.einsum('ml,ijkl->ijkm',F_avg - _np.eye(3),node_coord0(F.shape[:3][::-1],size)) def node_displacement(size,F): From ac75b9e4cac2d10f04a80f9a63c9d4799e4fbf1f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 21 Apr 2020 11:17:15 +0200 Subject: [PATCH 5/5] improved reporting + test --- python/damask/_result.py | 18 ++++++++++++------ python/tests/test_Result.py | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index ee7d696a9..0d84847fb 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -68,12 +68,12 @@ class Result: self.con_physics = [] for c in self.constituents: self.con_physics += f['/'.join([self.increments[0],'constituent',c])].keys() - self.con_physics = list(set(self.con_physics)) # make unique + self.con_physics = list(set(self.con_physics)) # make unique self.mat_physics = [] for m in self.materialpoints: self.mat_physics += f['/'.join([self.increments[0],'materialpoint',m])].keys() - self.mat_physics = list(set(self.mat_physics)) # make unique + self.mat_physics = list(set(self.mat_physics)) # make unique self.selection = {'increments': self.increments, 'constituents': self.constituents,'materialpoints': self.materialpoints, @@ -86,13 +86,19 @@ class Result: def __repr__(self): """Show selected data.""" all_selected_increments = self.selection['increments'] + self.pick('increments',all_selected_increments[0:1]) first = self.list_data() + self.pick('increments',all_selected_increments[-1:]) - last = self.list_data() + last = '' if len(all_selected_increments) < 2 else self.list_data() + self.pick('increments',all_selected_increments) - in_between = ''.join(['\n{}\n ...\n'.format(inc) for inc in all_selected_increments[1:-2]]) - return util.srepr(first+ in_between + last) + + in_between = '' if len(all_selected_increments) < 3 else \ + ''.join(['\n{}\n ...\n'.format(inc) for inc in all_selected_increments[1:-2]]) + + return util.srepr(first + in_between + last) def _manage_selection(self,action,what,datasets): @@ -1009,7 +1015,7 @@ class Result: continue lock.acquire() with h5py.File(self.fname, 'a') as f: - try: + try: # ToDo: Replace if exists? dataset = f[result[0]].create_dataset(result[1]['label'],data=result[1]['data']) for l,v in result[1]['meta'].items(): dataset.attrs[l]=v.encode() diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index a90430096..c117f33f7 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -24,6 +24,10 @@ def reference_dir(reference_dir_base): class TestResult: + def test_self_report(self,default): + print(default) + + def test_time_increments(self,default): shape = default.read_dataset(default.get_dataset_location('F'),0).shape default.set_by_time(0.0,20.0)