nonlinear_material.py 3.29 KB
Newer Older
1 2 3
import mgis.behaviour as mgis_bv

mgis_hypothesis = {"plane_strain": mgis_bv.Hypothesis.PlaneStrain,
Jeremy BLEYER's avatar
Jeremy BLEYER committed
4 5 6
                   "plane_stress": mgis_bv.Hypothesis.PlaneStress,
                   "3d": mgis_bv.Hypothesis.Tridimensional,
                   "axisymmetric": mgis_bv.Hypothesis.Axisymmetrical}
7 8 9 10 11 12 13 14 15


class MFrontNonlinearMaterial:
    def __init__(self, path, name, hypothesis="3d",
                 material_properties={}, external_state_variables={"Temperature": 293.15}):
        self.path = path
        self.name = name
        # Defining the modelling hypothesis
        self.hypothesis = mgis_hypothesis[hypothesis]
16 17 18 19
        if self.hypothesis == mgis_bv.Hypothesis.Tridimensional:
            self._tensorsize = 9
        else:
            self._tensorsize = 5
20 21 22 23
        self.material_properties = material_properties
        self.external_state_variables = external_state_variables
        # Loading the behaviour
        self.behaviour = mgis_bv.load(self.path, self.name, self.hypothesis)
24
        self.finite_strain = self.behaviour.getBehaviourType()=="StandardFiniteStrainBehaviour"
25 26 27 28

    def set_data_manager(self, ngauss):
        # Setting the material data manager
        self.data_manager = mgis_bv.MaterialDataManager(self.behaviour, ngauss)
Jeremy BLEYER's avatar
Jeremy BLEYER committed
29 30 31 32 33 34
        self.update_material_properties()
        self.update_external_state_variable()

    def update_material_properties(self, material_properties=None):
        if material_properties is not None:
            self.material_properties = material_properties
35 36 37
        for s in [self.data_manager.s0, self.data_manager.s1]:
            for (key, value) in self.material_properties.items():
                mgis_bv.setMaterialProperty(s, key, value)
Jeremy BLEYER's avatar
Jeremy BLEYER committed
38 39 40 41 42

    def update_external_state_variable(self, external_state_variables=None):
        if external_state_variables is not None:
            self.external_state_variables = external_state_variables
        for s in [self.data_manager.s0, self.data_manager.s1]:
43 44 45 46 47
            for (key, value) in self.external_state_variables.items():
                mgis_bv.setExternalStateVariable(s, key, value)

    def get_state_variable_names(self):
        return [svar.name for svar in self.behaviour.internal_state_variables]
48 49 50 51
    def get_gradient_names(self):
        return [svar.name for svar in self.behaviour.gradients]
    def get_flux_names(self):
        return [svar.name for svar in self.behaviour.thermodynamic_forces]
52
    def get_state_variable_sizes(self):
53 54 55 56
        return [mgis_bv.getVariableSize(svar, self.hypothesis) for svar in self.behaviour.internal_state_variables]
    def get_gradient_sizes(self):
        return [mgis_bv.getVariableSize(svar, self.hypothesis) for svar in self.behaviour.gradients]
    def get_flux_sizes(self):
57 58 59
        return [self._tensorsize if (svar.name == "Stress" and self.finite_strain) else \
                mgis_bv.getVariableSize(svar, self.hypothesis) \
                for svar in self.behaviour.thermodynamic_forces]
60 61 62
    def get_tangent_block_names(self):
        return [(t[0].name, t[1].name) for t in self.behaviour.tangent_operator_blocks]
    def get_tangent_block_sizes(self):
63 64 65
        return [tuple([self._tensorsize if (tt.name == "Stress" and self.finite_strain) \
                       else mgis_bv.getVariableSize(tt, self.hypothesis) for tt in t]) \
                for t in self.behaviour.tangent_operator_blocks]