Exemplo n.º 1
0
 def test_material_data_manager3(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.MaterialDataManager(b, 2)
     d.s0.thermodynamic_forces[:] = [[sxx, 0, 0, 0, 0, 0],
                                     [sxx, 0, 0, 0, 0, 0]]
     mgis_bv.setExternalStateVariable(d.s0, "Temperature", 293.15)
     mgis_bv.setExternalStateVariable(d.s1, "Temperature", 293.15)
     mgis_bv.executeInitializeFunction(d, "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 n in range(0, 2):
         for i in range(0, 6):
             self.assertTrue(
                 abs(eel0[n][i] - eel_values[i]) < eps,
                 "invalid elastic strain value at the beginning of the time step"
             )
             self.assertTrue(
                 abs(eel1[n][i] - eel_values[i]) < eps,
                 "invalid elastic strain value at the end of the time step")
Exemplo n.º 2
0
    def __init__(
        self,
        nq: int,
        library_path: str,
        library_name: str,
        hypothesis: Hypothesis,
        stabilization_parameter: float,
        lagrange_parameter: float,
        field: Field,
        parameters: Dict[str, float] = None,
        integration_type: IntegrationType = IntegrationType.
        IntegrationWithConsistentTangentOperator,
        storage_mode:
        MaterialStateManagerStorageMode = MaterialStateManagerStorageMode.
        ExternalStorage,
        temperature: float = 293.15,
    ):
        """

        Args:
            nq:
            library_path:
            library_name:
            hypothesis:
            stabilization_parameter:
            field:
            parameters:
            integration_type:
            storage_mode:
            temperature:
        """
        self.nq = nq
        self.behaviour_name = library_name
        if field.grad_type in [GradType.DISPLACEMENT_SMALL_STRAIN]:
            if field.flux_type == FluxType.STRESS_CAUCHY:
                self.behaviour = mgis_bv.load(library_path, library_name,
                                              hypothesis)
        elif field.grad_type == GradType.DISPLACEMENT_TRANSFORMATION_GRADIENT:
            if field.flux_type == FluxType.STRESS_PK1:
                opt = mgis_bv.FiniteStrainBehaviourOptions()
                opt.stress_measure = mgis_bv.FiniteStrainBehaviourOptionsStressMeasure.PK1
                opt.tangent_operator = mgis_bv.FiniteStrainBehaviourOptionsTangentOperator.DPK1_DF
                self.behaviour = mgis_bv.load(opt, library_path, library_name,
                                              hypothesis)
        self.mat_data = mgis_bv.MaterialDataManager(self.behaviour, self.nq)
        self.stabilization_parameter = stabilization_parameter
        self.lagrange_parameter = lagrange_parameter
        if not parameters is None:
            for key, val in parameters.items():
                mgis_bv.setParameter(self.behaviour, key, val)
        self.integration_type = integration_type
        self.storage_mode = storage_mode
        self.temperature = temperature
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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
     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")
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
 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 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
Exemplo n.º 9
0
#   increment and a range of integration points.
#
# In the present case, we compute a plane strain von Mises plasticity with isotropic
# linear hardening. The material behaviour is implemented in the :download:`IsotropicLinearHardeningPlasticity.mfront` file
# which must first be compiled to generate the appropriate librairies as follows::

# > mfront --obuild --interface=generic IsotropicLinearHardeningPlasticity.mfront
#
# We can then setup the ``MaterialDataManager``::

# Defining the modelling hypothesis
h = mgis_bv.Hypothesis.TRIDIMENSIONAL
# Loading the behaviour        
b = mgis_bv.load('src/libBehaviour.so','CosseratIsotropicLinearHardeningPlasticity',h)
# Setting the material data manager
m = mgis_bv.MaterialDataManager(b, ngauss)
# elastic parameters for Cosserat strain
E = 107e3
llambda = 80e3 # In [MPa]
mu = 70e3
mu_c = 100e3
# elastic parameters for Cosserat wryness
alpha = 0. # In [MPa]
beta  = 30e3
gamma = 30e3
# yield strength
sig0 = 800.
Et = E/100.
# hardening slope
H = E*Et/(E-Et)
# Cosserat plasticity coupling modules
 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 set_data_manager(self, ngauss):
     # Setting the material data manager
     self.data_manager = mgis_bv.MaterialDataManager(self.behaviour, ngauss)
     self.update_material_properties()