def load_behaviour(self):
     self.is_finite_strain = mgis_bv.isStandardFiniteStrainBehaviour(self.path, self.name)
     if self.is_finite_strain:
         # finite strain options
         bopts = mgis_bv.FiniteStrainBehaviourOptions()
         bopts.stress_measure = mgis_bv.FiniteStrainBehaviourOptionsStressMeasure.PK1
         bopts.tangent_operator = mgis_bv.FiniteStrainBehaviourOptionsTangentOperator.DPK1_DF
         self.behaviour = mgis_bv.load(bopts, self.path,
                                       self.name, self.hypothesis)
     else:
         self.behaviour = mgis_bv.load(self.path, self.name, self.hypothesis)
Beispiel #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
    def test_pass(self):

        stress_options = mgis_bv.FiniteStrainBehaviourOptionsStressMeasure
        to_options = mgis_bv.FiniteStrainBehaviourOptionsTangentOperator
        # path to the test library
        lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY']
        version = os.environ['MGIS_TEST_TFEL_VERSION']
        h = mgis_bv.Hypothesis.Tridimensional
        o = mgis_bv.FiniteStrainBehaviourOptions()
        o.stress_measure = stress_options.PK1
        o.tangent_operator = to_options.DPK1_DF
        b = mgis_bv.load(o, lib, 'FiniteStrainSingleCrystal', h)
        self.assertTrue(b.tfel_version == version, "invalid TFEL version")
        self.assertTrue(len(b.gradients) == 1, 'invalid number of gradients')
        self.assertTrue(b.gradients[0].name == 'DeformationGradient',
                        'invalid gradient name')
        self.assertTrue(b.gradients[0].getType() == 'Tensor',
                        'invalid gradient type')
        self.assertTrue(b.gradients[0].type == mgis_bv.VariableType.TENSOR,
                        'invalid gradient type')
        self.assertTrue(b.gradients[0].type == mgis_bv.VariableType.Tensor,
                        'invalid gradient type')
        self.assertTrue(
            len(b.thermodynamic_forces) == 1,
            'invalid number of thermodynamic_forces')
        pk1 = b.thermodynamic_forces[0]
        self.assertTrue(pk1.name == 'FirstPiolaKirchhoffStress',
                        'invalid thermodynamic force  name')
        self.assertTrue(pk1.getType() == 'Tensor',
                        'invalid thermodynamic force  type')
        self.assertTrue(pk1.type == mgis_bv.VariableType.TENSOR,
                        'invalid thermodynamic force  type')
Beispiel #4
0
 def test_pass(self):
     yg = 150e9
     nu = 0.3
     eps = 1.e-14
     # path to the test library
     lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY']
     version = os.environ['MGIS_TEST_TFEL_VERSION']
     h = mgis_bv.Hypothesis.Tridimensional
     b = mgis_bv.load(lib, 'ParameterTest', h)
     self.assertTrue(b.behaviour == "ParameterTest",
                     "invalid behaviour name")
     self.assertTrue(b.hypothesis == h, "invalid hypothesis")
     self.assertTrue(b.source == "ParameterTest.mfront", "invalid source")
     self.assertTrue(b.tfel_version == version, "invalid TFEL version")
     self.assertTrue(len(b.params) == 4, "invalid number of parameters")
     self.assertTrue(b.params[0] == "YoungModulus",
                     "invalid first parameter")
     self.assertTrue(b.params[1] == "PoissonRatio",
                     "invalid second parameter")
     self.assertTrue(b.params[2] == "minimal_time_step_scaling_factor",
                     "invalid third parameter")
     self.assertTrue(b.params[3] == "maximal_time_step_scaling_factor",
                     "invalid fourth parameter")
     self.assertTrue(
         abs(mgis_bv.getParameterDefaultValue(b, "YoungModulus") - yg) <
         eps * yg, "invalid 'YoungModulus' default value")
     self.assertTrue(
         abs(b.getParameterDefaultValue("YoungModulus") - yg) < eps * yg,
         "invalid 'YoungModulus' default value")
     self.assertTrue(
         abs(b.getParameterDefaultValue("PoissonRatio") - nu) < eps * nu,
         "invalid 'PoissonRatio' default value")
    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 __get_behaviour(self, h):
     lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY']
     return mgis_bv.load(lib, 'PostProcessingTest', h)
 def test_pass(self):
     btype = mgis_bv.BehaviourType
     bkinematic = mgis_bv.BehaviourKinematic
     # path to the test library
     lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY']
     version = os.environ['MGIS_TEST_TFEL_VERSION']
     h = mgis_bv.Hypothesis.Tridimensional
     b = mgis_bv.load(lib, 'Gurson', h)
     self.assertTrue(b.behaviour == "Gurson", "invalid behaviour name")
     self.assertTrue(b.hypothesis == h, "invalid hypothesis")
     self.assertTrue(b.source == "Gurson.mfront", "invalid source")
     self.assertTrue(b.tfel_version == version, "invalid TFEL version")
     self.assertTrue(
         len(b.mps) == 0, "invalid number of material properties")
     self.assertTrue(b.getBehaviourType() == "StandardStrainBasedBehaviour",
                     "invalid behaviour type")
     self.assertTrue(b.btype == btype.StandardStrainBasedBehaviour,
                     "invalid behaviour type")
     self.assertTrue(b.btype == btype.STANDARDSTRAINBASEDBEHAVIOUR,
                     "invalid behaviour type")
     self.assertTrue(b.getKinematic() == "SmallStrainKinematic",
                     "invalid kinematic value")
     self.assertTrue(b.kinematic == bkinematic.SmallStrainKinematic,
                     "invalid kinematic value")
     self.assertTrue(b.kinematic == bkinematic.SMALLSTRAINKINEMATIC,
                     "invalid kinematic value")
     self.assertTrue(b.symmetry == mgis_bv.BehaviourSymmetry.Isotropic,
                     "invalid behaviour symmetry")
     self.assertTrue(len(b.gradients) == 1, "invalid number of gradients")
     F = b.gradients[0]
     self.assertTrue(F.name == "Strain", "invalid gradient name")
     self.assertTrue(F.type == mgis_bv.VariableType.Stensor,
                     "invalid gradient type")
     self.assertTrue(F.type == mgis_bv.VariableType.STENSOR,
                     "invalid gradient type")
     self.assertTrue(
         len(b.thermodynamic_forces) == 1,
         "invalid number of thermodynamic_forces")
     pk1 = b.thermodynamic_forces[0]
     self.assertTrue(pk1.name == "Stress", "invalid flux name")
     self.assertTrue(pk1.type == mgis_bv.VariableType.Stensor,
                     "invalid flux type")
     self.assertTrue(pk1.type == mgis_bv.VariableType.STENSOR,
                     "invalid flux type")
     self.assertTrue(
         len(b.isvs) == 4, "invalid number of internal state variables")
     self.assertTrue(
         len(b.internal_state_variables) == 4,
         "invalid number of internal state variables")
     self.assertTrue(b.isvs[0].name == "ElasticStrain",
                     "invalid name for the first internal state variable")
     self.assertTrue(b.isvs[0].type == mgis_bv.VariableType.STENSOR,
                     "invalid type for the first internal state variable")
     self.assertTrue(b.isvs[1].name == "EquivalentPlasticStrain",
                     "invalid name for the second internal state variable")
     self.assertTrue(b.isvs[1].type == mgis_bv.VariableType.SCALAR,
                     "invalid type for the second internal state variable")
     self.assertTrue(b.isvs[1].type == mgis_bv.VariableType.Scalar,
                     "invalid type for the second internal state variable")
     self.assertTrue(b.isvs[1].getType() == 'Scalar',
                     "invalid type for the second internal state variable")
     self.assertTrue(b.isvs[2].name == "MatrixEquivalentPlasticStrain",
                     "invalid name for the third internal state variable")
     self.assertTrue(b.isvs[2].type == mgis_bv.VariableType.SCALAR,
                     "invalid type for the third internal state variable")
     self.assertTrue(b.isvs[3].name == "Porosity",
                     "invalid name for the third internal state variable")
     self.assertTrue(b.isvs[3].type == mgis_bv.VariableType.SCALAR,
                     "invalid type for the fourth internal state variable")
     # external state variables
     self.assertTrue(
         len(b.esvs) == 1, "invalid number of external state variables")
     self.assertTrue(
         len(b.external_state_variables) == 1,
         "invalid number of external state variables")
     self.assertTrue(b.esvs[0].name == "Temperature",
                     "invalid name for the first external state variable")
     self.assertTrue(b.esvs[0].type == mgis_bv.VariableType.SCALAR,
                     "invalid type for the first external state variable")
     # parameters
     params = b.parameters
     self.assertTrue(len(params) == 15, "invalid number of parameters")
     self.assertTrue('epsilon' in params, "'epsilon is not a parameter")
     self.assertTrue(
         len(b.iparams) == 0, "invalid number of integer parameters")
     self.assertTrue(
         len(b.integer_parameters) == 0,
         "invalid number of integer parameters")
     self.assertTrue(
         len(b.unsigned_short_parameters) == 1,
         "invalid number of unsigned short parameters")
     self.assertTrue(b.usparams[0] == 'iterMax',
                     "invalid name for the first unsigned short parameter")
Beispiel #8
0
 def __get_behaviour(self, h):
     lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY']
     return mgis_bv.load(lib, 'InitializeFunctionTest', h)
    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
Beispiel #10
0
#   integration points. Various overloads of this function exist. We will
#   use a version taking as argument a ``MaterialStateManager``, the time
#   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
Beispiel #11
0
from minieigen import VectorX, MatrixX
from SPFEMexp import SPFEM
import mgis.behaviour as mgis_bv
import numpy

intType = mgis_bv.IntegrationType.IntegrationWithConsistentTangentOperator
behaviour = mgis_bv.load('src/libBehaviour.so', 'Elasticity',
                         mgis_bv.Hypothesis.PlaneStrain)


class Elasticity(object):
    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
 def __get_behaviour(self, h):
     lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY']
     return mgis_bv.load(lib, 'TensorialExternalStateVariableTest', h)
Beispiel #13
0
    def test_pass(self):

        btype = mgis_bv.BehaviourType
        bkinematic = mgis_bv.BehaviourKinematic
        bsyme = mgis_bv.BehaviourSymmetry
        stress_options = mgis_bv.FiniteStrainBehaviourOptionsStressMeasure
        to_options = mgis_bv.FiniteStrainBehaviourOptionsTangentOperator
        # path to the test library
        lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY']
        version = os.environ['MGIS_TEST_TFEL_VERSION']
        h = mgis_bv.Hypothesis.Tridimensional
        o = mgis_bv.FiniteStrainBehaviourOptions()
        o.stress_measure = stress_options.PK1
        o.tangent_operator = to_options.DPK1_DF
        b = mgis_bv.load(o, lib, 'FiniteStrainSingleCrystal', h)
        self.assertTrue(b.behaviour == 'FiniteStrainSingleCrystal',
                        'invalid behaviour name')
        self.assertTrue(b.hypothesis == h, 'invalid hypothesis')
        self.assertTrue(b.source == 'FiniteStrainSingleCrystal.mfront',
                        'invalid source')
        self.assertTrue(b.tfel_version == version, 'invalid TFEL version')
        self.assertTrue(
            b.getBehaviourType() == 'StandardFiniteStrainBehaviour',
            'invalid behaviour type')
        self.assertTrue(b.btype == btype.STANDARDFINITESTRAINBEHAVIOUR,
                        'invalid behaviour type')
        self.assertTrue(b.btype == btype.StandardFiniteStrainBehaviour,
                        'invalid behaviour type')
        self.assertTrue(b.getKinematic() == 'F_CAUCHY',
                        'invalid kinematic value')
        self.assertTrue(
            b.kinematic == bkinematic.FINITESTRAINKINEMATIC_F_CAUCHY,
            'invalid kinematic value')
        self.assertTrue(
            b.kinematic == bkinematic.FiniteStrainKinematic_F_Cauchy,
            'invalid kinematic value')
        self.assertTrue(b.getSymmetry() == 'Orthotropic',
                        'invalid behaviour symmetry')
        self.assertTrue(b.symmetry == bsyme.ORTHOTROPIC,
                        'invalid behaviour symmetry')
        self.assertTrue(b.symmetry == bsyme.Orthotropic,
                        'invalid behaviour symmetry')
        self.assertTrue(len(b.gradients) == 1, 'invalid number of gradients')
        F = b.gradients[0]
        self.assertTrue(F.name == 'DeformationGradient',
                        'invalid gradient name')
        self.assertTrue(F.getType() == 'Tensor', 'invalid gradient type')
        self.assertTrue(F.type == mgis_bv.VariableType.TENSOR,
                        'invalid gradient type')
        self.assertTrue(F.type == mgis_bv.VariableType.Tensor,
                        'invalid gradient type')
        self.assertTrue(
            len(b.thermodynamic_forces) == 1,
            'invalid number of thermodynamic_forces')
        pk1 = b.thermodynamic_forces[0]
        self.assertTrue(pk1.name == 'FirstPiolaKirchhoffStress',
                        'invalid flux name')
        self.assertTrue(pk1.getType() == 'Tensor', 'invalid flux type')
        self.assertTrue(pk1.type == mgis_bv.VariableType.TENSOR,
                        'invalid flux type')
        self.assertTrue(pk1.type == mgis_bv.VariableType.Tensor,
                        'invalid flux type')
        self.assertTrue(
            len(b.mps) == 16, 'invalid number of material properties')

        def check_mp_name(mp, n):
            self.assertTrue(
                mp.name == n, "invalid material property name, "
                "expected '" + n + "'")

        for mp in b.mps:
            self.assertTrue(mp.getType() == 'Scalar',
                            "invalid material property type '" + mp.name + "'")
            self.assertTrue(mp.type == mgis_bv.VariableType.SCALAR,
                            "invalid material property type '" + mp.name + "'")
            self.assertTrue(mp.type == mgis_bv.VariableType.Scalar,
                            "invalid material property type '" + mp.name + "'")
        check_mp_name(b.mps[0], 'YoungModulus1')
        check_mp_name(b.mps[1], 'YoungModulus2')
        check_mp_name(b.mps[2], 'YoungModulus3')
        check_mp_name(b.mps[3], 'PoissonRatio12')
        check_mp_name(b.mps[4], 'PoissonRatio23')
        check_mp_name(b.mps[5], 'PoissonRatio13')
        check_mp_name(b.mps[6], 'ShearModulus12')
        check_mp_name(b.mps[7], 'ShearModulus23')
        check_mp_name(b.mps[8], 'ShearModulus13')
        check_mp_name(b.mps[9], 'm')
        check_mp_name(b.mps[10], 'K')
        check_mp_name(b.mps[11], 'C')
        check_mp_name(b.mps[12], 'R0')
        check_mp_name(b.mps[13], 'Q')
        check_mp_name(b.mps[14], 'b')
        check_mp_name(b.mps[15], 'd1')
        self.assertTrue(
            len(b.isvs) == 37, 'invalid number of internal state variables')

        def check_iv_name(iv, n, i):
            vn = n + '[' + str(i) + ']'
            self.assertTrue(
                iv.name == vn, "invalid internal state variable name, "
                "expected '" + vn + "'")
            self.assertTrue(
                iv.getType() == 'Scalar',
                'invalid type for internal ' + 'state variable \'' + vn + '\'')
            self.assertTrue(
                iv.type == mgis_bv.VariableType.SCALAR,
                'invalid type for internal ' + 'state variable \'' + vn + '\'')
            self.assertTrue(
                iv.type == mgis_bv.VariableType.Scalar,
                'invalid type for internal ' + 'state variable \'' + vn + '\'')

        for i in range(0, 12):
            check_iv_name(b.isvs[i], 'g', i)
            check_iv_name(b.isvs[13 + i], 'p', i)
            check_iv_name(b.isvs[25 + i], 'a', i)
        self.assertTrue(b.isvs[12].name == 'Fe',
                        "invalid name for internal state variable 'Fe'")
        self.assertTrue(b.isvs[12].getType() == "Tensor",
                        "invalid type for internal state variable 'Fe'")
        self.assertTrue(b.isvs[12].type == mgis_bv.VariableType.TENSOR,
                        "invalid type for internal state variable 'Fe'")
        self.assertTrue(b.isvs[12].type == mgis_bv.VariableType.Tensor,
                        "invalid type for internal state variable 'Fe'")
        self.assertTrue(
            len(b.esvs) == 1, 'invalid number of external state variables')
        self.assertTrue(b.esvs[0].name == 'Temperature',
                        'invalid name for the first external state variable')
        self.assertTrue(b.esvs[0].getType() == 'Scalar',
                        'invalid type for the first external state variable')
        self.assertTrue(b.esvs[0].type == mgis_bv.VariableType.SCALAR,
                        'invalid type for the first external state variable')
        self.assertTrue(b.esvs[0].type == mgis_bv.VariableType.Scalar,
                        'invalid type for the first external state variable')
    def test_pass(self):

        eps = 1.e-14
        yg_min = 100.e9
        yg_max = 200.e9
        nu_min = -1
        nu_max = 0.5
        iv_pmin = 0.
        iv_pmax = 0.8
        iv_min = 0.2
        iv_max = 0.5
        ev_pmin = 0.
        ev_pmax = 500.
        ev_min = 200.
        ev_max = 400.
        # path to the test library
        lib = os.environ['MGIS_TEST_BEHAVIOURS_LIBRARY']
        version = os.environ['MGIS_TEST_TFEL_VERSION']
        h = mgis_bv.Hypothesis.Tridimensional
        b = mgis_bv.load(lib, 'BoundsCheckTest', h)
        self.assertTrue(b.behaviour == "BoundsCheckTest",
                        "invalid behaviour name")
        self.assertTrue(b.hypothesis == h, "invalid hypothesis")
        self.assertTrue(b.source == "BoundsCheckTest.mfront", "invalid source")
        self.assertTrue(b.tfel_version == version, "invalid TFEL version")
        # test on material properties
        self.assertTrue(mgis_bv.hasBounds(b, "YoungModulus"),
                        "'YoungModulus' shall have bounds")
        self.assertTrue(mgis_bv.hasLowerBound(b, "YoungModulus"),
                        "'YoungModulus' shall have a lower bound")
        bound = mgis_bv.getLowerBound(b, "YoungModulus")
        self.assertTrue(
            abs(bound - yg_min) < eps * yg_min,
            "invalid value for the 'YoungModulus' lower bound")
        bound = mgis_bv.getUpperBound(b, "YoungModulus")
        self.assertTrue(
            abs(bound - yg_max) < eps * yg_max,
            "invalid value for the 'YoungModulus' upper bound")
        self.assertTrue(mgis_bv.hasUpperBound(b, "YoungModulus"),
                        "'YoungModulus' shall have an upper bound")
        self.assertTrue(mgis_bv.hasPhysicalBounds(b, "YoungModulus"),
                        "'YoungModulus' shall have physical bounds")
        self.assertTrue(mgis_bv.hasLowerPhysicalBound(b, "YoungModulus"),
                        "'YoungModulus' shall have a lower physical bound")
        bound = mgis_bv.getLowerPhysicalBound(b, "YoungModulus")
        self.assertTrue(
            abs(bound) < eps * yg_max, "invalid value for the 'YoungModulus' "
            "physical lower bound")
        self.assertTrue(
            not mgis_bv.hasUpperPhysicalBound(b, "YoungModulus"),
            "'YoungModulus' shall not have an "
            "upper physical bound")
        self.assertTrue(not mgis_bv.hasBounds(b, "PoissonRatio"),
                        "'PoissonRatio' shall not have bounds")
        self.assertTrue(not mgis_bv.hasLowerBound(b, "PoissonRatio"),
                        "'PoissonRatio' shall not have a lower bound")
        self.assertTrue(not mgis_bv.hasUpperBound(b, "PoissonRatio"),
                        "'PoissonRatio' shall not have an upper bound")
        self.assertTrue(mgis_bv.hasPhysicalBounds(b, "PoissonRatio"),
                        "'PoissonRatio' shall have physical bounds")
        self.assertTrue(mgis_bv.hasLowerPhysicalBound(b, "PoissonRatio"),
                        "'PoissonRatio' shall have a lower physical bound")
        bound = mgis_bv.getLowerPhysicalBound(b, "PoissonRatio")
        self.assertTrue(
            abs(bound - nu_min) < eps,
            "invalid value for the 'PoissonRatio' physical "
            "lower bound")
        self.assertTrue(mgis_bv.hasUpperPhysicalBound(b, "PoissonRatio"),
                        "'PoissonRatio' shall have an upper physical bound")
        bound = mgis_bv.getUpperPhysicalBound(b, "PoissonRatio")
        self.assertTrue(
            abs(bound - nu_max) < eps * nu_max,
            "invalid value for the 'PoissonRatio' "
            "physical upper bound")
        # internal state variables
        self.assertTrue(mgis_bv.hasBounds(b, "StateVariable"),
                        "'StateVariable' shall have bounds")
        self.assertTrue(mgis_bv.hasLowerBound(b, "StateVariable"),
                        "'StateVariable' shall have a lower bound")
        bound = mgis_bv.getLowerBound(b, "StateVariable")
        self.assertTrue(
            abs(bound - iv_min) < eps * iv_min,
            "invalid value for the 'StateVariable' lower bound")
        bound = mgis_bv.getUpperBound(b, "StateVariable")
        self.assertTrue(
            abs(bound - iv_max) < eps * iv_max,
            "invalid value for the 'StateVariable' upper bound")
        self.assertTrue(mgis_bv.hasUpperBound(b, "StateVariable"),
                        "'StateVariable' shall have an upper bound")
        self.assertTrue(mgis_bv.hasPhysicalBounds(b, "StateVariable"),
                        "'StateVariable' shall have physical bounds")
        self.assertTrue(mgis_bv.hasLowerPhysicalBound(b, "StateVariable"),
                        "'StateVariable' shall have a lower physical bound")
        bound = mgis_bv.getLowerPhysicalBound(b, "StateVariable")
        self.assertTrue(
            abs(bound - iv_pmin) < eps,
            "invalid value for the 'StateVariable' "
            "physical lower bound")
        self.assertTrue(
            mgis_bv.hasUpperPhysicalBound(b, "StateVariable"),
            "'StateVariable' shall not have an "
            "upper physical bound")
        bound = mgis_bv.getUpperPhysicalBound(b, "StateVariable")
        self.assertTrue(
            abs(bound - iv_pmax) < eps * iv_pmax,
            "invalid value for the 'StateVariable' "
            "physical upper bound")
        # external state variable
        ev = "ExternalStateVariable"
        self.assertTrue(mgis_bv.hasBounds(b, ev),
                        "'ExternalStateVariable' shall have bounds")
        self.assertTrue(mgis_bv.hasLowerBound(b, ev),
                        "'ExternalStateVariable' shall have a lower bound")
        bound = mgis_bv.getLowerBound(b, ev)
        self.assertTrue(
            abs(bound - ev_min) < eps * ev_min,
            "invalid value for the 'ExternalStateVariable' "
            "lower bound")
        bound = mgis_bv.getUpperBound(b, ev)
        self.assertTrue(
            abs(bound - ev_max) < eps * ev_max,
            "invalid value for the 'ExternalStateVariable' "
            "upper bound")
        self.assertTrue(mgis_bv.hasUpperBound(b, ev),
                        "'ExternalStateVariable' shall have an upper bound")
        self.assertTrue(mgis_bv.hasPhysicalBounds(b, ev),
                        "'ExternalStateVariable' shall have physical bounds")
        self.assertTrue(
            mgis_bv.hasLowerPhysicalBound(b, ev),
            "'ExternalStateVariable' shall have a "
            "lower physical bound")
        bound = mgis_bv.getLowerPhysicalBound(b, ev)
        self.assertTrue(
            abs(bound - ev_pmin) < eps,
            "invalid value for the 'ExternalStateVariable' "
            "physical lower bound")
        self.assertTrue(
            mgis_bv.hasUpperPhysicalBound(b, ev),
            "'ExternalStateVariable' shall not have an "
            "upper physical bound")
        bound = mgis_bv.getUpperPhysicalBound(b, ev)
        self.assertTrue(
            abs(bound - ev_pmax) < eps * ev_pmax,
            "invalid value for the 'ExternalStateVariable' "
            "physical upper bound")
Beispiel #15
0
from minieigen import * #Eigen for Python, publically available
from SPFEMexp import SPFEM #import compiled SPFEMexp library
import mgis #MFrontGenericInterfaceSupport
import mgis.behaviour as mgis_bv
import numpy
import optimesh #mesh optimization
from scipy.interpolate import LinearNDInterpolator

pool = mgis.ThreadPool(20) #thread pool for parallel stress integration
IT = mgis_bv.IntegrationType.IntegrationWithConsistentTangentOperator
behaviour = mgis_bv.load('src/libBehaviour.so','MisesVocePlasticity',mgis_bv.Hypothesis.PlaneStrain) #plane strain assumption

class spfem_mfront(object):
    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