def test_behaviour_data2(self): E = 200e9 nu = 0.3 sxx = 150e6 eps = 10 * sxx * 1e-14 h = mgis_bv.Hypothesis.Tridimensional b = self.__get_behaviour(h) d = mgis_bv.BehaviourData(b) d.s0.thermodynamic_forces[:] = [sxx, 0, 0, 0, 0, 0] mgis_bv.setExternalStateVariable(d.s0, "Temperature", 293.15) mgis_bv.setExternalStateVariable(d.s1, "Temperature", 293.15) v = mgis_bv.make_view(d) mgis_bv.executeInitializeFunction(v, b, "ElasticStrainFromInitialStress") # Due to restrictions of the BehaviourDataView class (the # initial state is assumed immutable), only the state at the # end of the time step is initialized. Calling update is thus # required in most cases mgis_bv.update(d) eel_values = [sxx / E, -nu * sxx / E, -nu * sxx / E, 0, 0, 0] eel0 = d.s0.internal_state_variables eel1 = d.s1.internal_state_variables for i in range(0, 6): self.assertTrue( abs(eel0[i] - eel_values[i]) < eps, "invalid elastic strain value at the beginning of the time step" ) self.assertTrue( abs(eel1[i] - eel_values[i]) < eps, "invalid elastic strain value at the end of the time step")
def test_behaviour_data(self): pr = -1.2e5 eps = -pr * 1.e-14 h = mgis_bv.Hypothesis.Tridimensional b = self.__get_behaviour(h) d = mgis_bv.BehaviourData(b) mgis_bv.setExternalStateVariable(d.s0, "Temperature", 293.15) mgis_bv.setExternalStateVariable(d.s1, "Temperature", 293.15) inputs = numpy.asarray([pr], dtype=numpy.float64) v = mgis_bv.make_view(d) mgis_bv.executeInitializeFunction(v, b, "StressFromInitialPressure", inputs) # Due to restrictions of the BehaviourDataView class (the # initial state is assumed immutable), only the state at the # end of the time step is initialized. Calling update is thus # required in most cases mgis_bv.update(d) s0 = d.s0.thermodynamic_forces s1 = d.s1.thermodynamic_forces for i in range(0, 3): self.assertTrue( abs(s0[i] - pr) < eps, "invalid stress value at the beginning of the time step") self.assertTrue( abs(s1[i] - pr) < eps, "invalid stress value at the end of the time step") for i in range(3, 6): self.assertTrue( abs(s0[i]) < eps, "invalid stress value at the beginning of the time step") self.assertTrue( abs(s1[i]) < eps, "invalid stress value at the end of the time step")
def set_temperature(self): """ """ T = self.temperature * np.ones(self.nq) mgis_bv.setExternalStateVariable(self.mat_data.s0, "Temperature", T, self.storage_mode) mgis_bv.setExternalStateVariable(self.mat_data.s1, "Temperature", T, self.storage_mode)
def __updateMaterialData(self,res): self.__materData = mgis_bv.MaterialDataManager(behaviour, self.__npts) for s in [self.__materData.s0, self.__materData.s1]: # material initialization mgis_bv.setMaterialProperty(s,"YoungModulus",self.mater['young']) mgis_bv.setMaterialProperty(s,"PoissonRatio",self.mater['poisson']) mgis_bv.setMaterialProperty(s,"InitYieldStress",self.mater['tau0']) mgis_bv.setMaterialProperty(s,"ResidualYieldStress",self.mater['taur']) mgis_bv.setMaterialProperty(s,"SoftenExponent",self.mater['b']) mgis_bv.setExternalStateVariable(s,"Temperature",293.15) s.internal_state_variables[:,:] = res[:,:5] #s.thermodynamic_forces[:,:] = res[:,5:9] s.gradients[:,:] = res[:,5:] mgis_bv.integrate(pool, self.__materData, intType, self.__dt) mgis_bv.update(self.__materData)
def test_pass(self): # path to the test library lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY'] # reference values pref = [ 0, 1.3523277308229e-11, 1.0955374667213e-07, 5.5890770166084e-06, 3.2392193670428e-05, 6.645865307584e-05, 9.9676622883138e-05, 0.00013302758358953, 0.00016635821069889, 0.00019969195920296, 0.00023302522883648, 0.00026635857194317, 0.000299691903777, 0.0003330252373404, 0.00036635857063843, 0.00039969190397718, 0.00043302523730968, 0.00046635857064314, 0.00049969190397646, 0.00053302523730979, 0.00056635857064313 ] # comparison criterion eps = 1.e-12 b = mgis_bv.load(lib, 'Norton', mgis_bv.Hypothesis.Tridimensional) d = mgis_bv.BehaviourData(b) o = mgis_bv.getVariableOffset(b.isvs, 'EquivalentViscoplasticStrain', b.hypothesis) # strain increment per time step de = 5.e-5 # time step d.dt = 180 # setting the temperature mgis_bv.setExternalStateVariable(d.s1, 'Temperature', 293.15) # copy d.s1 in d.s0 mgis_bv.update(d) d.s1.gradients[0] = de # equivalent plastic strain p = [d.s0.internal_state_variables[o]] # integrate the behaviour for i in range(0, 20): mgis_bv.integrate(d, b) mgis_bv.update(d) d.s1.gradients[0] += de p.append(d.s1.internal_state_variables[o]) # check-in results for i in range(0, 20): self.assertTrue(abs(p[i] - pref[i]) < eps) pass
def __init__(self, pts, mater=None, sigma=None, gravity=[0., 0.], charlen=1.): """ :var pts: type numpy ndarray, shape = (npts, 2), points coordinates :var mater: type structure, material properties :var sigma: type numpy ndarray, initial stress, shape = (4,) or (npts, 4) :var gravity: type vector, size = 2, gravity constant :var charlen: type double, characteristic spacing :var limlen: type double, minimum spacing """ self.__npts = len(pts) # no. of nodes self.__pts = pts self.__spfem = SPFEM( ) # SPFEM module with C++ backend and Python binding through compiled shared library self.__materData = mgis_bv.MaterialDataManager( behaviour, self.__npts) # material data container for s in [self.__materData.s0, self.__materData.s1]: # material initialization mgis_bv.setMaterialProperty(s, "YoungModulus", mater['young']) mgis_bv.setMaterialProperty(s, "PoissonRatio", mater['poisson']) mgis_bv.setExternalStateVariable(s, "Temperature", 293.15) self.__wavespeed = numpy.sqrt(mater['young'] * (1 - mater['poisson']) / mater['rho'] / (1 + mater['poisson']) / (1 - 2 * mater['poisson'])) print('wave speed:', self.__wavespeed) self.__acc = numpy.zeros(self.__npts * 2) self.__vel = numpy.zeros(self.__npts * 2) self.__disp = numpy.zeros(self.__npts * 2) self.__T = 0. # total elapsed time self.__charlen = charlen self.__dt = self.__updateMeshBmatrixFint( ) # update the triangulation and internal force vector print(self.__dt) mass = numpy.multiply( self.__area, mater['rho'] ) # after initialization, mass will not change to guarantee mass conservation self.__fbody = numpy.outer(mass, gravity).reshape( -1) # body force due to gravity self.__mass = numpy.repeat(mass, 2)
def test_behaviour_data(self): eps = 1.e-14 h = mgis_bv.Hypothesis.Tridimensional b = self.__get_behaviour(h) d = mgis_bv.BehaviourData(b) self.assertTrue(len(d.s0.external_state_variables) == 55, "invalid array size for the external state variables") self.assertTrue(len(d.s1.external_state_variables) == 55, "invalid array size for the external state variables") v_esv_values = numpy.asarray([1, 2, 3], dtype=numpy.float64) print(v_esv_values) mgis_bv.setExternalStateVariable(d.s1, "v_esv", v_esv_values) mgis_bv.integrate(d, b) for i in range(0, 3): self.assertTrue(abs(d.s1.external_state_variables[i + 1] - v_esv_values[i]) < eps, "invalid external state variable value") self.assertTrue(abs(d.s1.internal_state_variables[i] - v_esv_values[i]) < eps, "invalid internal state variable value") pass
def __init__(self,pts,mater,sigma=None,gravity=[0.,0.],charlen=1.): """ pts: type numpy ndarray, shape = (npts, 2), points coordinates mater: type structure, material properties sigma: type numpy ndarray, initial stress, shape = (4,) or (npts, 4) gravity: type vector, size = 2, gravity constant charlen: type double, characteristic spacing """ self.__npts = len(pts) self.__pts = pts self.__spfem = SPFEM() #SPFEM module with C++ backend and Python binding through compiled shared library compliance = 1. / mater['young'] * numpy.array([[1.,-mater['poisson'],-mater['poisson'],0.], \ [-mater['poisson'],1.,-mater['poisson'],0.], \ [-mater['poisson'],-mater['poisson'],1.,0.], \ [0.,0.,0.,numpy.sqrt(2)*(1+mater['poisson'])]]) if sigma is None: sigma = numpy.zeros(4) epsilon = numpy.dot(compliance, sigma.T).T self.__materData = mgis_bv.MaterialDataManager(behaviour, self.__npts) #material data container self.mater = mater for s in [self.__materData.s0, self.__materData.s1]: #material initialization mgis_bv.setMaterialProperty(s,"YoungModulus",mater['young']) mgis_bv.setMaterialProperty(s,"PoissonRatio",mater['poisson']) mgis_bv.setMaterialProperty(s,"InitYieldStress",mater['tau0']) mgis_bv.setMaterialProperty(s,"ResidualYieldStress",mater['taur']) mgis_bv.setMaterialProperty(s,"SoftenExponent",mater['b']) mgis_bv.setExternalStateVariable(s,"Temperature",293.15) s.internal_state_variables[:,:4] = epsilon s.thermodynamic_forces[:] = sigma self.__charlen = charlen self.__dt = self.__updateMeshBmatrixFint() self.__wavespeed = numpy.sqrt(mater['young']/mater['rho']) self.__acc = numpy.zeros(self.__npts*2) #acceleration self.__vel = numpy.zeros(self.__npts*2) #velocity self.__disp = numpy.zeros(self.__npts*2) #displacement self.__T = 0. #total elapsed time mass = numpy.multiply(self.__area, mater['rho']) #after initialization, mass will not change to guarantee mass conservation self.__fbody = numpy.outer(mass, gravity).reshape(-1) #gravity force self.__mass = numpy.repeat(mass, 2) #nodal mass
def test_pass(self): # path to the test library lib = os.environ['MGIS_TEST_MODELS_LIBRARY'] # modelling hypothesis h = mgis_bv.Hypothesis.Tridimensional # loading the behaviour model = mgis.model.load(lib, 'ode_rk54', h) # default value of parameter A A = model.getParameterDefaultValue('A') # material data manager d = mgis_bv.BehaviourData(model) # index of x in the array of state variable o = mgis_bv.getVariableOffset(model.isvs, 'x', h) # time step increment d.dt = 0.1 # type of storage mgis_bv.setExternalStateVariable(d.s1, 'Temperature', 293.15) # Initial value of x d.s1.internal_state_variables[o] = 1 # copy d.s1 in d.s0 mgis_bv.update(d) # values of x xvalues = [d.s0.internal_state_variables[o]] # integration for i in range(0, 10): mgis_bv.integrate(d, model) mgis_bv.update(d) xvalues.append(d.s1.internal_state_variables[o]) # checks # comparison criterion eps = 1.e-10 t = 0 for i in range(0, 11): x_ref = math.exp(-A * t) self.assertTrue(abs(xvalues[i] - x_ref) < eps) t = t + d.dt pass
def test_behaviour_data(self): eps = 1.e-14 e = numpy.asarray([1.3e-2, 1.2e-2, 1.4e-2, 0., 0., 0.], dtype=numpy.float64) e2 = numpy.asarray([1.2e-2, 1.3e-2, 1.4e-2, 0., 0., 0.], dtype=numpy.float64) h = mgis_bv.Hypothesis.Tridimensional b = self.__get_behaviour(h) m = mgis_bv.MaterialDataManager(b, 2) mgis_bv.setMaterialProperty(m.s1, "YoungModulus", 150e9) mgis_bv.setMaterialProperty(m.s1, "PoissonRatio", 0.3) mgis_bv.setExternalStateVariable(m.s1, "Temperature", 293.15) mgis_bv.update(m) m.s1.gradients[0:] = e m.s1.gradients[1:] = e outputs = numpy.empty(shape=(2, 3), dtype=numpy.float64) mgis_bv.executePostProcessing(outputs.reshape(6), m, "PrincipalStrain") for i in range(0, 3): self.assertTrue( abs(outputs[0, i] - e2[i]) < eps, "invalid output value") self.assertTrue( abs(outputs[1, i] - e2[i]) < eps, "invalid output value")
def initialize_external_state_variables(self): for (s, size) in zip( self.material.get_external_state_variable_names(), self.material.get_external_state_variable_sizes(), ): state_var = self.state_variables["external"][s] if isinstance(state_var, Constant): mgis_bv.setExternalStateVariable(self.material.data_manager.s0, s, float(state_var)) else: if isinstance(state_var, Var): state_var.initialize_function(self.mesh, self.quadrature_degree) values = state_var.function.vector().get_local() else: values = (compute_on_quadrature( state_var, self.mesh, self.quadrature_degree).vector().get_local()) mgis_bv.setExternalStateVariable( self.material.data_manager.s0, s, values, mgis_bv.MaterialStateManagerStorageMode.LocalStorage, )
def test_data_manager2(self): """ Call an initialize function with non uniform inputs """ pr = [-1.2e5, 0.7e5] eps = -pr[0] * 1.e-14 h = mgis_bv.Hypothesis.Tridimensional b = self.__get_behaviour(h) d = mgis_bv.MaterialDataManager(b, 2) mgis_bv.setExternalStateVariable(d.s0, "Temperature", 293.15) mgis_bv.setExternalStateVariable(d.s1, "Temperature", 293.15) inputs = numpy.asarray(pr, dtype=numpy.float64) mgis_bv.executeInitializeFunction(d, "StressFromInitialPressure", inputs) # Due to restrictions of the BehaviourDataView class (the # initial state is assumed immutable), only the state at the # end of the time step is initialized. Calling update is thus # required in most cases mgis_bv.update(d) s0 = d.s0.thermodynamic_forces s1 = d.s1.thermodynamic_forces for n in range(0, 2): for i in range(0, 3): self.assertTrue( abs(s0[n][i] - pr[n]) < eps, "invalid stress value at the beginning of the time step") self.assertTrue( abs(s1[n][i] - pr[n]) < eps, "invalid stress value at the end of the time step") for i in range(3, 6): self.assertTrue( abs(s0[n][i]) < eps, "invalid stress value at the beginning of the time step") self.assertTrue( abs(s1[n][i]) < eps, "invalid stress value at the end of the time step")
def update_external_state_variables(self, degree, mesh, external_state_variables): s = self.data_manager.s1 for (key, value) in external_state_variables.items(): if type(value) in [int, float]: mgis_bv.setExternalStateVariable(s, key, value) elif isinstance(value, dolfin.Constant): mgis_bv.setExternalStateVariable(s, key, float(value)) else: if isinstance(value, Var): value.update() values = value.function.vector().get_local() else: values = compute_on_quadrature( value, mesh, degree).vector().get_local() mgis_bv.setExternalStateVariable( s, key, values, mgis_bv.MaterialStateManagerStorageMode.LocalStorage)
def update_external_state_variables(self, external_state_variables): s = self.data_manager.s1 for (key, value) in external_state_variables.items(): if type(value) in [int, float]: mgis_bv.setExternalStateVariable(s, key, value) elif isinstance(value, dolfin.Constant): mgis_bv.setExternalStateVariable(s, key, float(value)) else: if isinstance(value, dolfin.Function): values = value.vector().get_local() elif isinstance(value, Var): value.update() values = value.function.vector().get_local() else: print(isinstance(value, Var)) print(value) raise NotImplementedError("{} type is not supported for external state variables".format(type(value))) mgis_bv.setExternalStateVariable(s, key, values, mgis_bv.MaterialStateManagerStorageMode.LocalStorage)
def test_material_data_manager(self): eps = 1.e-14 dt = 0.1 h = mgis_bv.Hypothesis.Tridimensional b = self.__get_behaviour(h) d = mgis_bv.MaterialDataManager(b, 2) mgis_bv.setMaterialProperty(d.s0, "YoungModulus", 150e9) mgis_bv.setMaterialProperty(d.s0, "PoissonRatio", 0.3) mgis_bv.setMaterialProperty(d.s1, "YoungModulus", 150e9) mgis_bv.setMaterialProperty(d.s1, "PoissonRatio", 0.3) # zeros = numpy.zeros(9) # v_esv is uniform v_esv_values = numpy.asarray([1, 2, 3], dtype=numpy.float64) mgis_bv.setExternalStateVariable(d.s0, "v_esv", zeros[0:3], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(d.s1, "v_esv", v_esv_values, mgis_bv.MaterialStateManagerStorageMode.LOCAL_STORAGE) # v2_esv[0] is not uniform v2_esv0_values = numpy.asarray([1, 2, 3, 7, 6, 5], dtype=numpy.float64) mgis_bv.setExternalStateVariable(d.s0, "v2_esv[0]",zeros[0:3], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(d.s1, "v2_esv[0]", v2_esv0_values, mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) v2_esv1_values = numpy.asarray([9, 8, 2, 3, 6, 4], dtype=numpy.float64) mgis_bv.setExternalStateVariable(d.s0, "v2_esv[1]", zeros[0:3], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(d.s1, "v2_esv[1]", v2_esv1_values, mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) for s in [d.s0, d.s1]: mgis_bv.setExternalStateVariable(s, "Temperature", zeros[0:1], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(s, "s_esv", zeros[0:6], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(s, "s2_esv[0]", zeros[0:6], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(s, "s2_esv[1]", zeros[0:6], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(s, "t_esv", zeros[0:9], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(s, "t2_esv[0]", zeros[0:9], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) mgis_bv.setExternalStateVariable(s, "t2_esv[1]", zeros[0:9], mgis_bv.MaterialStateManagerStorageMode.EXTERNAL_STORAGE) # checking if the external storage do work as expected v2_esv1_values[3] = -1 mgis_bv.integrate(d, mgis_bv.IntegrationType.INTEGRATION_NO_TANGENT_OPERATOR, dt, 0, 2) for i in range (0, 3): self.assertTrue(abs(d.s1.internal_state_variables[0, i] - v_esv_values[i]) < eps, "invalid internal state variable value") self.assertTrue(abs(d.s1.internal_state_variables[1, i] - v_esv_values[i]) < eps, "invalid internal state variable value") self.assertTrue(abs(d.s1.internal_state_variables[0, i + 3] - v2_esv0_values[i]) < eps, "invalid internal state variable value") self.assertTrue(abs(d.s1.internal_state_variables[1, i + 3] - v2_esv0_values[i + 3]) < eps, "invalid internal state variable value") self.assertTrue(abs(d.s1.internal_state_variables[0, i + 6] - v2_esv1_values[i]) < eps, "invalid internal state variable value") self.assertTrue(abs(d.s1.internal_state_variables[1, i + 6] - v2_esv1_values[i + 3]) < eps, "invalid internal state variable value")
def test_pass(self): print(dir(mgis)) # path to the test library lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY'] # reference values pref = [ 0, 1.3523277308229e-11, 1.0955374667213e-07, 5.5890770166084e-06, 3.2392193670428e-05, 6.645865307584e-05, 9.9676622883138e-05, 0.00013302758358953, 0.00016635821069889, 0.00019969195920296, 0.00023302522883648, 0.00026635857194317, 0.000299691903777, 0.0003330252373404, 0.00036635857063843, 0.00039969190397718, 0.00043302523730968, 0.00046635857064314, 0.00049969190397646, 0.00053302523730979, 0.00056635857064313 ] # modelling hypothesis h = mgis_bv.Hypothesis.Tridimensional # loading the behaviour b = mgis_bv.load(lib, 'Norton', h) # number of integration points nig = 100 # material data manager m = mgis_bv.MaterialDataManager(b, nig) # index of the equivalent viscplastic strain in the array of # state variable o = mgis_bv.getVariableOffset(b.isvs, 'EquivalentViscoplasticStrain', h) # strain increment per time step de = 5.e-5 # time step increment dt = 180 # setting the temperature mgis_bv.setExternalStateVariable(m.s1, 'Temperature', 293.15) # copy d.s1 in d.s0 mgis_bv.update(m) # index of the first integration point ni = 0 # index of the last integration point ne = nig - 1 # values of the equivalent plastic strain # for the first integration point pi = [m.s0.internal_state_variables[ni][o]] # values of the equivalent plastic strain # for the last integration point pe = [m.s0.internal_state_variables[ne][o]] # setting the gradient at the end of the first time step for i in range(0, nig): m.s1.gradients[i][0] = de # creating a thread pool for parallel integration p = mgis.ThreadPool(2) # integration for i in range(0, 20): it = mgis_bv.IntegrationType.IntegrationWithoutTangentOperator mgis_bv.integrate(p, m, it, dt) mgis_bv.update(m) for j in range(0, nig): m.s1.gradients[j][0] += de pi.append(m.s0.internal_state_variables[ni][o]) pe.append(m.s0.internal_state_variables[ne][o]) # checks # comparison criterion eps = 1.e-12 for i in range(0, 21): self.assertTrue(abs(pi[i] - pref[i]) < eps) self.assertTrue(abs(pe[i] - pref[i]) < eps) pass
b_2 = 1.0 for s in [m.s0, m.s1]: mgis_bv.setMaterialProperty(s, "lambda", llambda) mgis_bv.setMaterialProperty(s, "mu", mu) mgis_bv.setMaterialProperty(s, "mu_c", mu_c) mgis_bv.setMaterialProperty(s, "alpha", alpha) mgis_bv.setMaterialProperty(s, "beta", beta) mgis_bv.setMaterialProperty(s, "gamma", gamma) mgis_bv.setMaterialProperty(s, "a_1", a_1) mgis_bv.setMaterialProperty(s, "a_2", a_2) mgis_bv.setMaterialProperty(s, "b_1", b_1) mgis_bv.setMaterialProperty(s, "b_2", b_2) mgis_bv.setMaterialProperty(s, "HardeningSlope", H) mgis_bv.setMaterialProperty(s, "YieldStrength", sig0) mgis_bv.setExternalStateVariable(s, "Temperature", 293.15) # Boundary conditions and external loading are defined as before along with the # analytical limit load solution:: bc = [DirichletBC(VT.sub(0), Constant((0,0,0)), boundary_L), DirichletBC(VT.sub(1), Constant((0,0,0)), boundary_L)] #bc = [DirichletBC(V.sub(0), 0, facets, 38), DirichletBC(V.sub(1), 0, facets, 38), DirichletBC(V.sub(2), 0, facets, 38)] #bc = [DirichletBC(V, as_vector((0.0,0.0,0.0)), facets, 1)] eps_load = 1e-5 loadside = Expression("x[0] < 80.0 + eps && x[0] > 80.0 - eps ? 1. : 0.", eps=eps_load, degree=2) n = FacetNormal(mesh) #q_lim = float(2/sqrt(3)*ln(Re/Ri)*sig0) q_lim = 1050 #[MPa] loading = Expression("q*t", q=q_lim, t=0, degree=2)