@@ -61,7 +61,7 @@ def __init__(self, u, material, quadrature_degree=2, bcs=None):
6161 # compute Gauss points numbers
6262 self .ngauss = Function (self .W0 ).vector ().local_size ()
6363 # Set data manager
64- self .material .set_data_manager (self .ngauss )
64+ self .material .set_data_manager (self .quadrature_degree , self . ngauss , self . mesh )
6565 # dummy function used for computing global quantity
6666 self ._dummy_function = Function (self .W0 )
6767
@@ -90,6 +90,14 @@ def __init__(self, u, material, quadrature_degree=2, bcs=None):
9090
9191 self .dt = 0
9292
93+ if self .material .rotation_matrix is not None :
94+ if isinstance (self .material .rotation_matrix , (list , tuple , np .ndarray )):
95+ self .rotation_values = np .asarray (self .material .rotation_matrix ).ravel ()
96+ else :
97+ self .rotation_values = compute_on_quadrature (self .material .rotation_matrix ,
98+ self .mesh , self .quadrature_degree )
99+ self .rotation_values = self .rotation_values .vector ().get_local ()
100+
93101 self .state_variables = {"internal" : None ,
94102 "external" : dict .fromkeys (self .material .get_external_state_variable_names (), None )}
95103 self .gradients = dict .fromkeys (self .material .get_gradient_names (), None )
@@ -194,12 +202,9 @@ def register_external_state_variable(self, name, expression):
194202 vtype = self .material .behaviour .external_state_variables [pos ].type
195203 if vtype != mgis_bv .VariableType .Scalar :
196204 raise NotImplementedError ("Only scalar external state variables are handled" )
197- if isinstance (expression , Constant ):
198- self .state_variables ["external" ].update ({name : expression })
199- elif type (expression ) == float :
200- self .state_variables ["external" ].update ({name : Constant (expression )})
201- else :
202- self .state_variables ["external" ].update ({name : Var (self .u , expression , name )})
205+ if type (expression ) == float :
206+ expression = Constant (expression )
207+ self .state_variables ["external" ].update ({name : Var (self .u , expression , name )})
203208
204209 def set_loading (self , Fext ):
205210 """
@@ -212,38 +217,20 @@ def set_loading(self, Fext):
212217 """
213218 self ._Fext = ufl .replace (Fext , {self .u : self .u_ })
214219
215- def set_quadrature_function_spaces (self ):
216- cell = self .mesh .ufl_cell ()
217- W0e = get_quadrature_element (cell , self .quadrature_degree )
218- # scalar quadrature space
219- self .W0 = FunctionSpace (self .mesh , W0e )
220- # compute Gauss points numbers
221- self .ngauss = Function (self .W0 ).vector ().local_size ()
222- # Set data manager
223- self .material .set_data_manager (self .ngauss )
224-
225- # Get strain measure dimension
226- self .strain_dim = ufl .shape (self .strain_measure (self .u ))[0 ]
227- # Define quadrature spaces for stress/strain and tangent matrix
228- Wsige = get_quadrature_element (cell , self .quadrature_degree , self .strain_dim )
229- # stress/strain quadrature space
230- self .Wsig = FunctionSpace (self .mesh , Wsige )
231- Wce = get_quadrature_element (cell , self .quadrature_degree , (self .strain_dim , self .strain_dim ))
232- # tangent matrix quadrature space
233- self .WCt = FunctionSpace (self .mesh , Wce )
234-
235220 def initialize_external_state_variables (self ):
236221 for (s , size ) in zip (self .material .get_external_state_variable_names (), self .material .get_external_state_variable_sizes ()):
237222 state_var = self .state_variables ["external" ][s ]
238- if isinstance (state_var , Gradient ):
239- state_var .initialize_function (self .mesh , self .quadrature_degree )
240- values = state_var .function .vector ().get_local ()
241- mgis_bv .setExternalStateVariable (self .material .data_manager .s0 , s ,
242- values , mgis_bv .MaterialStateManagerStorageMode .LocalStorage )
243- elif isinstance (state_var , Constant ):
223+ if isinstance (state_var , Constant ):
244224 mgis_bv .setExternalStateVariable (self .material .data_manager .s0 , s , float (state_var ))
245225 else :
246- raise ValueError ("External state variable '{}' has not been registered." .format (s ))
226+ if isinstance (state_var , Var ):
227+ state_var .initialize_function (self .mesh , self .quadrature_degree )
228+ values = state_var .function .vector ().get_local ()
229+ else :
230+ values = compute_on_quadrature (state_var , self .mesh ,
231+ self .quadrature_degree ).vector ().get_local ()
232+ mgis_bv .setExternalStateVariable (self .material .data_manager .s0 , s ,
233+ values , mgis_bv .MaterialStateManagerStorageMode .LocalStorage )
247234
248235 def initialize_gradients (self ):
249236 buff = 0
@@ -287,7 +274,7 @@ def initialize_tangent_blocks(self):
287274 except :
288275 value = self .state_variables ["external" ].get (t [1 ], None )
289276 if value is not None and isinstance (value , Var ):
290- flux_gradients .append (value )
277+ flux_gradients .append (value )
291278 else :
292279 raise ValueError ("'{}' could not be associated with a registered gradient or state variable." .format (t [1 ]))
293280 self .fluxes [f ].initialize_tangent_blocks (flux_gradients )
@@ -347,15 +334,23 @@ def update_tangent_blocks(self):
347334 except KeyError :
348335 raise KeyError ("'{}' could not be found as a flux or an internal state variable." )
349336 block_shape = self .flattened_block_shapes [i ]
350- t .vector ().set_local (self .material .data_manager .K [:,buff :buff + block_shape ].flatten ())
337+ tang_block_vals = self .material .data_manager .K [:,buff :buff + block_shape ].ravel ()
338+ if self .material .rotation_matrix is not None :
339+ mgis_bv .rotateTangentOperatorBlocks (tang_block_vals , self .material .behaviour ,
340+ self .rotation_values )
341+ t .vector ().set_local (tang_block_vals )
351342 buff += block_shape
352343
353344 def update_fluxes (self ):
354345 buff = 0
355346 for (i , f ) in enumerate (self .material .get_flux_names ()):
356347 flux = self .fluxes [f ]
357348 block_shape = self .material .get_flux_sizes ()[i ]
358- flux .function .vector ().set_local (self .material .data_manager .s1 .thermodynamic_forces [:,buff :buff + block_shape ].flatten ())
349+ flux_vals = self .material .data_manager .s1 .thermodynamic_forces [:,buff :buff + block_shape ].ravel ()
350+ if self .material .rotation_matrix is not None :
351+ mgis_bv .rotateThermodynamicForces (flux_vals , self .material .behaviour ,
352+ self .rotation_values )
353+ flux .function .vector ().set_local (flux_vals )
359354 buff += block_shape
360355
361356 def update_gradients (self ):
@@ -365,6 +360,9 @@ def update_gradients(self):
365360 gradient .update ()
366361 block_shape = self .material .get_gradient_sizes ()[i ]
367362 grad_vals = gradient .function .vector ().get_local ()
363+ if self .material .rotation_matrix is not None :
364+ mgis_bv .rotateGradients (grad_vals , self .material .behaviour ,
365+ self .rotation_values )
368366 if gradient .shape > 0 :
369367 grad_vals = grad_vals .reshape ((self .material .data_manager .n , gradient .shape ))
370368 else :
@@ -384,7 +382,8 @@ def update_internal_state_variables(self):
384382 def update_constitutive_law (self ):
385383 """Performs the consitutive law update"""
386384 self .update_gradients ()
387- self .material .update_external_state_variables (self .state_variables ["external" ])
385+ self .material .update_external_state_variables (self .quadrature_degree , self .mesh ,
386+ self .state_variables ["external" ])
388387 # integrate the behaviour
389388 mgis_bv .integrate (self .material .data_manager , self .integration_type ,
390389 self .dt , 0 , self .material .data_manager .n );
0 commit comments