Exemple #1
0
    def __init__(self, convergence_criterion_parameters):
        # Note that all the convergence settings are introduced via a Kratos parameters object.

        D_RT = convergence_criterion_parameters[
            "displacement_relative_tolerance"].GetDouble()
        D_AT = convergence_criterion_parameters[
            "displacement_absolute_tolerance"].GetDouble()
        R_RT = convergence_criterion_parameters[
            "residual_relative_tolerance"].GetDouble()
        R_AT = convergence_criterion_parameters[
            "residual_absolute_tolerance"].GetDouble()

        echo_level = convergence_criterion_parameters["echo_level"].GetInt()

        if (echo_level >= 1):
            print(
                "::[Mechanical Solver]:: CONVERGENCE CRITERION : ",
                convergence_criterion_parameters["convergence_criterion"].
                GetString())

        rotation_dofs = False
        if (convergence_criterion_parameters.Has("rotation_dofs")):
            if (convergence_criterion_parameters["rotation_dofs"].GetBool()):
                rotation_dofs = True

        # Convergence criteria if there are rotation DOFs in the problem
        if (rotation_dofs == True):
            if (convergence_criterion_parameters["convergence_criterion"].
                    GetString() == "Displacement_criterion"):
                self.mechanical_convergence_criterion = StructuralMechanicsApplication.DisplacementAndOtherDoFCriteria(
                    D_RT, D_AT)
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif (convergence_criterion_parameters["convergence_criterion"].
                  GetString() == "Residual_criterion"):
                self.mechanical_convergence_criterion = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(
                    R_RT, R_AT)
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif (convergence_criterion_parameters["convergence_criterion"].
                  GetString() == "And_criterion"):
                Displacement = StructuralMechanicsApplication.DisplacementAndOtherDoFCriteria(
                    D_RT, D_AT)
                Displacement.SetEchoLevel(echo_level)
                Residual = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(
                    R_RT, R_AT)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.AndCriteria(
                    Residual, Displacement)

            elif (convergence_criterion_parameters["convergence_criterion"].
                  GetString() == "Or_criterion"):
                Displacement = StructuralMechanicsApplication.DisplacementAndOtherDoFCriteria(
                    D_RT, D_AT)
                Displacement.SetEchoLevel(echo_level)
                Residual = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(
                    R_RT, R_AT)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.OrCriteria(
                    Residual, Displacement)

        # Convergence criteria without rotation DOFs
        else:
            if (convergence_criterion_parameters["convergence_criterion"].
                    GetString() == "Displacement_criterion"):
                self.mechanical_convergence_criterion = KratosMultiphysics.DisplacementCriteria(
                    D_RT, D_AT)
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif (convergence_criterion_parameters["convergence_criterion"].
                  GetString() == "Residual_criterion"):
                self.mechanical_convergence_criterion = KratosMultiphysics.ResidualCriteria(
                    R_RT, R_AT)
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif (convergence_criterion_parameters["convergence_criterion"].
                  GetString() == "And_criterion"):
                Displacement = KratosMultiphysics.DisplacementCriteria(
                    D_RT, D_AT)
                Displacement.SetEchoLevel(echo_level)
                Residual = KratosMultiphysics.ResidualCriteria(R_RT, R_AT)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.AndCriteria(
                    Residual, Displacement)

            elif (convergence_criterion_parameters["convergence_criterion"].
                  GetString() == "Or_criterion"):
                Displacement = KratosMultiphysics.DisplacementCriteria(
                    D_RT, D_AT)
                Displacement.SetEchoLevel(echo_level)
                Residual = KratosMultiphysics.ResidualCriteria(R_RT, R_AT)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.OrCriteria(
                    Residual, Displacement)
 def create_constitutive_Law():
     return StructuralMechanicsApplication.LinearElasticPlaneStress2DLaw()
 def create_constitutive_Law():
     return StructuralMechanicsApplication.LinearJ2PlasticityPlaneStrain2DLaw(
     )
Exemple #4
0
 def _add_constitutive_law(self,mp,elastic_flag):
     cl = StructuralMechanicsApplication.TrussPlasticityConstitutiveLaw()
     if elastic_flag:
         cl = StructuralMechanicsApplication.TrussConstitutiveLaw()
     mp.GetProperties()[0].SetValue(KratosMultiphysics.CONSTITUTIVE_LAW,cl)
 def create_constitutive_Law():
     return StructuralMechanicsApplication.KirchhoffSaintVenant3DLaw()
Exemple #6
0
    def _CreateMetricsProcess(self):
        self.metric_processes = []
        if self.strategy == "LevelSet":
            level_set_parameters = KratosMultiphysics.Parameters("""{}""")
            level_set_parameters.AddValue("minimal_size",self.settings["minimal_size"])
            level_set_parameters.AddValue("enforce_current",self.settings["enforce_current"])
            level_set_parameters.AddValue("anisotropy_remeshing",self.settings["anisotropy_remeshing"])
            level_set_parameters.AddValue("anisotropy_parameters",self.settings["anisotropy_parameters"])
            level_set_parameters["anisotropy_parameters"].RemoveValue("boundary_layer_min_size_ratio")
            if self.dim == 2:
                self.metric_processes.append(MeshingApplication.ComputeLevelSetSolMetricProcess2D(
                    self.model_part,
                    self.gradient_variable,
                    level_set_parameters))

            else:
                self.metric_processes.append(MeshingApplication.ComputeLevelSetSolMetricProcess3D(
                    self.model_part,
                    self.gradient_variable,
                    level_set_parameters))

        elif self.strategy == "Hessian":
            hessian_parameters = KratosMultiphysics.Parameters("""{}""")
            hessian_parameters.AddValue("minimal_size",self.settings["minimal_size"])
            hessian_parameters.AddValue("maximal_size",self.settings["maximal_size"])
            hessian_parameters.AddValue("enforce_current",self.settings["enforce_current"])
            hessian_parameters.AddValue("hessian_strategy_parameters",self.settings["hessian_strategy_parameters"])
            hessian_parameters["hessian_strategy_parameters"].RemoveValue("metric_variable")
            hessian_parameters.AddValue("anisotropy_remeshing",self.settings["anisotropy_remeshing"])
            hessian_parameters.AddValue("anisotropy_parameters",self.settings["anisotropy_parameters"])
            hessian_parameters["anisotropy_parameters"].RemoveValue("boundary_layer_min_size_ratio")
            for current_metric_variable in self.metric_variable:
                self.metric_processes.append(MeshingApplication.ComputeHessianSolMetricProcess(
                    self.model_part,
                    current_metric_variable,
                    hessian_parameters))
        elif self.strategy == "superconvergent_patch_recovery":
            if not structural_dependencies:
                raise Exception("You need to compile the StructuralMechanicsApplication in order to use this criteria")

            # We compute the error
            error_compute_parameters = KratosMultiphysics.Parameters("""{}""")
            error_compute_parameters.AddValue("stress_vector_variable", self.settings["compute_error_extra_parameters"]["stress_vector_variable"])
            error_compute_parameters.AddValue("echo_level", self.settings["echo_level"])
            if self.dim == 2:
                self.error_compute = StructuralMechanicsApplication.SPRErrorProcess2D(
                    self.model_part,
                    error_compute_parameters
                    )
            else:
                self.error_compute = StructuralMechanicsApplication.SPRErrorProcess3D(
                    self.model_part,
                    error_compute_parameters
                    )

            # Now we compute the metric
            error_metric_parameters = KratosMultiphysics.Parameters("""{}""")
            error_metric_parameters.AddValue("minimal_size",self.settings["minimal_size"])
            error_metric_parameters.AddValue("maximal_size",self.settings["maximal_size"])
            error_metric_parameters.AddValue("target_error",self.settings["error_strategy_parameters"]["error_metric_parameters"]["interpolation_error"])
            error_metric_parameters.AddValue("set_target_number_of_elements", self.settings["error_strategy_parameters"]["set_target_number_of_elements"])
            error_metric_parameters.AddValue("target_number_of_elements", self.settings["error_strategy_parameters"]["target_number_of_elements"])
            error_metric_parameters.AddValue("perform_nodal_h_averaging", self.settings["error_strategy_parameters"]["perform_nodal_h_averaging"])
            error_metric_parameters.AddValue("echo_level", self.settings["echo_level"])

            if self.dim == 2:
                self.metric_process = MeshingApplication.MetricErrorProcess2D(
                    self.model_part,
                    error_metric_parameters
                    )
            else:
                self.metric_process = MeshingApplication.MetricErrorProcess3D(
                    self.model_part,
                    error_metric_parameters
                    )
Exemple #7
0
    def test_Uniaxial_HyperElastic_3D(self):
        nnodes = 4
        dim = 3

        # Define a model part and create new nodes
        model_part = KratosMultiphysics.ModelPart("test")
        node1 = model_part.CreateNewNode(1, 0.0, 0.0, 0.0)
        node2 = model_part.CreateNewNode(2, 1.0, 0.0, 0.0)
        node3 = model_part.CreateNewNode(3, 0.0, 1.0, 0.0)
        node4 = model_part.CreateNewNode(4, 0.0, 0.0, 1.0)

        # Material properties
        prop_id = 0
        properties = model_part.Properties[prop_id]
        young_modulus = 200e9
        poisson_ratio = 0.3
        properties.SetValue(KratosMultiphysics.YOUNG_MODULUS, young_modulus)
        properties.SetValue(KratosMultiphysics.POISSON_RATIO, poisson_ratio)

        # Allocate a geometry
        geom = KratosMultiphysics.Tetrahedra3D4(node1,node2,node3, node4)

        N = KratosMultiphysics.Vector(4)
        DN_DX = KratosMultiphysics.Matrix(4,3)

        # Construct a constitutive law 
        cl = StructuralMechanicsApplication.HyperElastic3DLaw()
        cl.Check(properties, geom, model_part.ProcessInfo)

        if(cl.WorkingSpaceDimension() != dim):
            raise Exception("Mismatch between the WorkingSpaceDimension of the Constitutive Law and the dimension of the space in which the test is performed")

        ## Set the parameters to be employed
        #note that here i am adding them all to check that this does not fail
        cl_options = KratosMultiphysics.Flags()
        cl_options.Set(KratosMultiphysics.ConstitutiveLaw.USE_ELEMENT_PROVIDED_STRAIN, False)
        cl_options.Set(KratosMultiphysics.ConstitutiveLaw.COMPUTE_STRESS, True)
        cl_options.Set(KratosMultiphysics.ConstitutiveLaw.COMPUTE_CONSTITUTIVE_TENSOR, True)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.COMPUTE_STRAIN_ENERGY, False)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.ISOCHORIC_TENSOR_ONLY, False)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.VOLUMETRIC_TENSOR_ONLY, False)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.FINALIZE_MATERIAL_RESPONSE, False)

        # From here below it should be an otput not an input
        cl_options.Set(KratosMultiphysics.ConstitutiveLaw.FINITE_STRAINS, True) 
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.INFINITESIMAL_STRAINS, False)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.PLANE_STRAIN_LAW, False)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.PLANE_STRESS_LAW, False)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.AXISYMMETRIC_LAW, False)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.U_P_LAW, False)
        cl_options.Set(KratosMultiphysics.ConstitutiveLaw.ISOTROPIC, True)
        #cl_options.Set(KratosMultiphysics.ConstitutiveLaw.ANISOTROPIC, False)

        F = KratosMultiphysics.Matrix(3,3)
        F[0,0] = 1.0; F[0,1] = 0.0; F[0,2] = 0.0;
        F[1,0] = 0.0; F[1,1] = 1.0; F[1,2] = 0.0;
        F[2,0] = 0.0; F[2,1] = 0.0; F[2,2] = 1.0;
        detF = 1.0

        stress_vector = KratosMultiphysics.Vector(cl.GetStrainSize())
        strain_vector = KratosMultiphysics.Vector(cl.GetStrainSize())

        constitutive_matrix = KratosMultiphysics.Matrix(cl.GetStrainSize(),cl.GetStrainSize())

        # Setting the parameters - note that a constitutive law may not need them all!
        cl_params = KratosMultiphysics.ConstitutiveLawParameters()
        cl_params.SetOptions(cl_options)
        cl_params.SetDeformationGradientF(F)
        cl_params.SetDeterminantF(detF)
        cl_params.SetStrainVector(strain_vector)
        cl_params.SetStressVector(stress_vector)
        cl_params.SetConstitutiveMatrix(constitutive_matrix)
        cl_params.SetShapeFunctionsValues(N)
        cl_params.SetShapeFunctionsDerivatives(DN_DX)
        cl_params.SetProcessInfo(model_part.ProcessInfo)
        cl_params.SetMaterialProperties(properties)
        cl_params.SetElementGeometry(geom)

        ## Do all sort of checks
        cl_params.CheckAllParameters() # Can not use this until the geometry is correctly exported to python
        cl_params.CheckMechanicalVariables()
        cl_params.CheckShapeFunctions()

        #print("The Material Response PK2")
        #cl.CalculateMaterialResponsePK2(cl_params)
        #print("Stress = ", cl_params.GetStressVector())
        #print("Strain = ", cl_params.GetStrainVector())
        #print("C      = ", cl_params.GetConstitutiveMatrix())

        #cl.FinalizeMaterialResponsePK2(cl_params)
        #cl.FinalizeSolutionStep(properties, geom, N, model_part.ProcessInfo)

        #print("\n The Material Response Kirchhoff")
        #cl.CalculateMaterialResponseKirchhoff(cl_params)
        #print("Stress = ", cl_params.GetStressVector())
        #print("Strain = ", cl_params.GetStrainVector())
        #print("C      = ", cl_params.GetConstitutiveMatrix())

        #cl.FinalizeMaterialResponseKirchhoff(cl_params)
        #cl.FinalizeSolutionStep(properties, geom, N, model_part.ProcessInfo)

        #print("\n The Material Response Cauchy")
        #cl.CalculateMaterialResponseCauchy(cl_params)
        #print("Stress = ", cl_params.GetStressVector())
        #print("Strain = ", cl_params.GetStrainVector())
        #print("C      = ", cl_params.GetConstitutiveMatrix())
        
        #cl.FinalizeMaterialResponseCauchy(cl_params)
        #cl.FinalizeSolutionStep(properties, geom, N, model_part.ProcessInfo)
        
        # Check the results
        lame_lambda = (young_modulus * poisson_ratio) / ((1.0 + poisson_ratio) * (1.0 - 2.0 * poisson_ratio))
        lame_mu = young_modulus / (2.0 * (1.0 + poisson_ratio))
        
        reference_stress = KratosMultiphysics.Vector(cl.GetStrainSize())
        for i in range(cl.GetStrainSize()):
            reference_stress[i] = 0.0
        
        for i in range(100):
            F[0,0] = 1.0 + 0.2 * i
            detF = 1.0 + 0.2 * i
            cl_params.SetDeformationGradientF(F)
            cl_params.SetDeterminantF(detF)
            
            cl.CalculateMaterialResponseCauchy(cl_params)
            cl.FinalizeMaterialResponseCauchy(cl_params)
            cl.FinalizeSolutionStep(properties, geom, N, model_part.ProcessInfo)
        
            reference_stress[0] = (lame_lambda * math.log(detF) + lame_mu * (detF ** 2.0 - 1.0)) / detF
            reference_stress[1] = (lame_lambda * math.log(detF)) / detF
            reference_stress[2] = reference_stress[1]
        
            stress = cl_params.GetStressVector()
            
            for j in range(cl.GetStrainSize()):
                self.assertAlmostEqual(reference_stress[j], stress[j], 2) 
    def test_SmallDisplacementElement_3D_hexa(self):
        dim = 3
        current_model = KratosMultiphysics.Model()
        mp = current_model.CreateModelPart("solid_part")
        self._add_variables(mp)
        self._apply_material_properties(mp, dim)

        #create nodes
        mp.CreateNewNode(1, 0.00000, 1.00000, 1.00000)
        mp.CreateNewNode(2, 0.16500, 0.74500, 0.70200)
        mp.CreateNewNode(3, 0.27300, 0.75000, 0.23000)
        mp.CreateNewNode(4, 0.78800, 0.69300, 0.64400)
        mp.CreateNewNode(5, 0.32000, 0.18600, 0.64300)
        mp.CreateNewNode(6, 0.00000, 1.00000, 0.00000)
        mp.CreateNewNode(7, 0.00000, 0.00000, 1.00000)
        mp.CreateNewNode(8, 1.00000, 1.00000, 1.00000)
        mp.CreateNewNode(9, 0.67700, 0.30500, 0.68300)
        mp.CreateNewNode(10, 0.24900, 0.34200, 0.19200)
        mp.CreateNewNode(11, 0.85000, 0.64900, 0.26300)
        mp.CreateNewNode(12, 0.82600, 0.28800, 0.28800)
        mp.CreateNewNode(13, 0.00000, 0.00000, 0.00000)
        mp.CreateNewNode(14, 1.00000, 1.00000, 0.00000)
        mp.CreateNewNode(15, 1.00000, 0.00000, 1.00000)
        mp.CreateNewNode(16, 1.00000, 0.00000, 0.00000)

        KratosMultiphysics.VariableUtils().AddDof(
            KratosMultiphysics.DISPLACEMENT_X, KratosMultiphysics.REACTION_X,
            mp)
        KratosMultiphysics.VariableUtils().AddDof(
            KratosMultiphysics.DISPLACEMENT_Y, KratosMultiphysics.REACTION_Y,
            mp)
        KratosMultiphysics.VariableUtils().AddDof(
            KratosMultiphysics.DISPLACEMENT_Z, KratosMultiphysics.REACTION_Z,
            mp)

        #create a submodelpart for boundary conditions
        bcs = mp.CreateSubModelPart("BoundaryCondtions")
        bcs.AddNodes([1, 6, 7, 8, 13, 14, 15, 16])

        #create Element
        mp.CreateNewElement("SmallDisplacementElement3D8N", 1,
                            [10, 5, 2, 3, 13, 7, 1, 6],
                            mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D8N", 2,
                            [12, 9, 5, 10, 16, 15, 7, 13],
                            mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D8N", 3,
                            [12, 11, 3, 10, 9, 4, 2, 5],
                            mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D8N", 4,
                            [9, 4, 2, 5, 15, 8, 1, 7],
                            mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D8N", 5,
                            [4, 11, 3, 2, 8, 14, 6, 1],
                            mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D8N", 6,
                            [11, 4, 9, 12, 14, 8, 15, 16],
                            mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D8N", 7,
                            [11, 12, 10, 3, 14, 16, 13, 6],
                            mp.GetProperties()[1])

        A, b = self._define_movement(dim)
        self._apply_BCs(bcs, A, b)
        self._solve(mp)
        self._check_results(mp, A, b)
        self._check_outputs(mp, A, dim)

        #self.__post_process(mp)

        # Testing explicit utilities
        empty_param = KratosMultiphysics.Parameters("""{}""")
        max_delta_time = StructuralMechanicsApplication.CalculateDeltaTime(
            mp, empty_param)
        self.assertAlmostEqual(max_delta_time, 4.764516014904737e-07)
    def test_SmallDisplacementElement_3D_tetra_user_provided_elasticity(self):
        dim = 3
        current_model = KratosMultiphysics.Model()
        mp = current_model.CreateModelPart("solid_part")
        self._add_variables(mp)

        #set the user-provided elasticity tensor
        E = 200e+9
        nu = 0.3
        c1 = E / ((1.00+nu) * (1-2*nu))
        c2 = c1 * (1-nu)
        c3 = c1 * nu
        c4 = c1 * 0.5 * (1-2*nu)
        elasticity_tensor = KratosMultiphysics.Matrix(6,6)
        for i in range(6):
            for j in range(6):
                elasticity_tensor[i,j] = 0.0
        elasticity_tensor[0, 0] = c2
        elasticity_tensor[0, 1] = c3
        elasticity_tensor[0, 2] = c3
        elasticity_tensor[1, 0] = c3
        elasticity_tensor[1, 1] = c2
        elasticity_tensor[1, 2] = c3
        elasticity_tensor[2, 0] = c3
        elasticity_tensor[2, 1] = c3
        elasticity_tensor[2, 2] = c2
        elasticity_tensor[3, 3] = c4
        elasticity_tensor[4, 4] = c4
        elasticity_tensor[5, 5] = c4

        #apply isotropic user-provided material properties
        claw = StructuralMechanicsApplication.UserProvidedLinearElastic3DLaw()
        mp.GetProperties()[1].SetValue(KratosMultiphysics.CONSTITUTIVE_LAW, claw)
        mp.GetProperties()[1].SetValue(StructuralMechanicsApplication.ELASTICITY_TENSOR, elasticity_tensor)

        #create nodes
        mp.CreateNewNode(1,0.0, 1.0, 0.0)
        mp.CreateNewNode(2,0.0, 1.0, 0.1)
        mp.CreateNewNode(3, 0.28739360416666665, 0.27808503701741405, 0.05672979583333333)
        mp.CreateNewNode(4, 0.0, 0.1, 0.0)
        mp.CreateNewNode(5, 0.1, 0.1, 0.1)
        mp.CreateNewNode(6, 1.0, 0.0, 0.0)
        mp.CreateNewNode(7, 1.2, 0.0, 0.1)

        KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.DISPLACEMENT_X, KratosMultiphysics.REACTION_X,mp)
        KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.DISPLACEMENT_Y, KratosMultiphysics.REACTION_Y,mp)
        KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.DISPLACEMENT_Z, KratosMultiphysics.REACTION_Z,mp)

        #create a submodelpart for boundary conditions
        bcs = mp.CreateSubModelPart("BoundaryCondtions")
        bcs.AddNodes([1,2,4,5,6,7])

        #create Element
        mp.CreateNewElement("SmallDisplacementElement3D4N", 1,[5,3,1,2], mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D4N", 2,[3,1,2,6], mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D4N", 3,[6,4,7,3], mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D4N", 4,[5,4,1,3], mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D4N", 5,[4,1,3,6], mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D4N", 6,[5,4,3,7], mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D4N", 7,[3,5,7,2], mp.GetProperties()[1])
        mp.CreateNewElement("SmallDisplacementElement3D4N", 8,[6,7,2,3], mp.GetProperties()[1])

        A,b = self._define_movement(dim)

        self._apply_BCs(bcs,A,b)
        self._solve(mp)
        self._check_results(mp,A,b)
        self._check_outputs(mp,A,dim)
Exemple #10
0
 def create_constitutive_Law():
     return StructuralMechanicsApplication.SmallStrainIsotropicDamagePlaneStrain2DLaw(
     )
    def __init__(self, Model, settings):
        """ The default constructor of the class

        Keyword arguments:
        self -- It signifies an instance of a class.
        Model -- the container of the different model parts.
        settings -- Kratos parameters containing solver settings.
        """
        KratosMultiphysics.Process.__init__(self)

        default_settings = KratosMultiphysics.Parameters("""
        {
            "help"                        : "This process uses LinearMasterSlaveConstraint in order to impose an unified movement in the given submodelpart. The process takes the first node from the submodelpart if no node's ID is provided. The default variable is DISPLACEMENT, and in case no variable is considered for the slave the same variable will be considered",
            "main_model_part_name"        : "Structure",
            "model_part_name"             : "please_specify_model_part_name",
            "new_model_part_name"         : "",
            "interval"                    : [0.0, 1e30],
            "master_variable_name"        : "DISPLACEMENT",
            "slave_variable_name"         : "",
            "relation"                    : 1.0,
            "constant"                    : 0.0,
            "master_node_id"              : 0
        }
        """)

        # Detect "End" as a tag and replace it by a large number
        if settings.Has("interval"):
            if settings["interval"][1].IsString():
                if settings["interval"][1].GetString() == "End":
                    settings["interval"][1].SetDouble(
                        1e30)  # = default_settings["interval"][1]
                else:
                    raise Exception(
                        "The second value of interval can be \"End\" or a number, interval currently:"
                        + settings["interval"].PrettyPrintJsonString())

        settings.ValidateAndAssignDefaults(default_settings)

        # The main model part
        self.main_model_part = Model[
            settings["main_model_part_name"].GetString()]

        # Assign this here since it will change the "interval" prior to validation
        self.interval = KratosMultiphysics.IntervalUtility(settings)

        # We get the corresponding model parts
        self.model_part = self.main_model_part.GetSubModelPart(
            settings["model_part_name"].GetString())
        new_model_part_name = settings["new_model_part_name"].GetString()
        if new_model_part_name != "":
            if self.model_part.HasSubModelPart(new_model_part_name):
                self.rigid_model_part = self.model_part.GetSubModelPart(
                    new_model_part_name)
            else:
                self.rigid_model_part = self.model_part.CreateSubModelPart(
                    new_model_part_name)
        else:
            settings["new_model_part_name"].SetString(
                settings["model_part_name"].GetString())
            self.rigid_model_part = self.model_part

        # Create the process
        rigid_parameters = KratosMultiphysics.Parameters("""{}""")
        rigid_parameters.AddValue("model_part_name",
                                  settings["model_part_name"])
        rigid_parameters.AddValue("new_model_part_name",
                                  settings["new_model_part_name"])
        rigid_parameters.AddValue("master_variable_name",
                                  settings["master_variable_name"])
        rigid_parameters.AddValue("slave_variable_name",
                                  settings["slave_variable_name"])
        rigid_parameters.AddValue("relation", settings["relation"])
        rigid_parameters.AddValue("constant", settings["constant"])
        rigid_parameters.AddValue("master_node_id", settings["master_node_id"])
        self.rigid_movement_process = StructuralMechanicsApplication.ImposeRigidMovementProcess(
            self.main_model_part, rigid_parameters)

        # Trasfering the entities
        if new_model_part_name != "":
            transfer_process = KratosMultiphysics.FastTransferBetweenModelPartsProcess(
                self.rigid_model_part, self.model_part, KratosMultiphysics.
                FastTransferBetweenModelPartsProcess.EntityTransfered.NODES)
            transfer_process.Execute()
    def test_Shear_Plus_Strech_HyperElastic_3D(self):
        nnodes = 4
        dim = 3

        # Define a model  and geometry
        model_part = KratosMultiphysics.ModelPart("test")
        geom = self._create_geometry(model_part, dim, nnodes)

        # Material properties
        young_modulus = 200e9
        poisson_ratio = 0.3
        properties = self._create_properties(model_part, young_modulus,
                                             poisson_ratio)

        N = KratosMultiphysics.Vector(nnodes)
        DN_DX = KratosMultiphysics.Matrix(nnodes, dim)

        # Construct a constitutive law
        cl = StructuralMechanicsApplication.HyperElastic3DLaw()
        self._cl_check(cl, properties, geom, model_part, dim)

        # Set the parameters to be employed
        dict_options = {
            'USE_ELEMENT_PROVIDED_STRAIN': False,
            'COMPUTE_STRESS': True,
            'COMPUTE_CONSTITUTIVE_TENSOR': True,
            'FINITE_STRAINS': True,
            'ISOTROPIC': True,
        }
        cl_options = self._set_cl_options(dict_options)

        # Define deformation gradient
        F = self._create_F()
        detF = 1.0

        stress_vector = KratosMultiphysics.Vector(cl.GetStrainSize())
        strain_vector = KratosMultiphysics.Vector(cl.GetStrainSize())
        constitutive_matrix = KratosMultiphysics.Matrix(
            cl.GetStrainSize(), cl.GetStrainSize())

        # Setting the parameters - note that a constitutive law may not need them all!
        cl_params = self._set_cl_parameters(cl_options, F, detF, strain_vector,
                                            stress_vector, constitutive_matrix,
                                            N, DN_DX, model_part, properties,
                                            geom)

        # Check the results
        lame_lambda = (young_modulus * poisson_ratio) / (
            (1.0 + poisson_ratio) * (1.0 - 2.0 * poisson_ratio))
        lame_mu = young_modulus / (2.0 * (1.0 + poisson_ratio))

        reference_stress = KratosMultiphysics.Vector(cl.GetStrainSize())
        for i in range(cl.GetStrainSize()):
            reference_stress[i] = 0.0

        x1beta = 1.0
        x2beta = 1.0
        x3beta = math.pi / 200
        for i in range(100):
            F[0, 0] = math.cos(x3beta * i)
            F[0, 1] = -math.sin(x3beta * i)
            F[1, 0] = math.sin(x3beta * i)
            F[1, 1] = math.cos(x3beta * i)
            F[0, 2] = -x1beta * math.sin(x3beta * i) - x2beta * math.cos(
                x3beta * i)
            F[1, 2] = x1beta * math.cos(x3beta * i) - x2beta * math.sin(
                x3beta * i)

            cl_params.SetDeformationGradientF(F)

            cl.CalculateMaterialResponseCauchy(cl_params)
            cl.FinalizeMaterialResponseCauchy(cl_params)
            cl.FinalizeSolutionStep(properties, geom, N,
                                    model_part.ProcessInfo)

            reference_stress[0] = (x2beta * math.cos(i * x3beta) +
                                   x1beta * math.sin(i * x3beta))**2.0
            reference_stress[1] = (x1beta * math.cos(i * x3beta) -
                                   x2beta * math.sin(i * x3beta))**2.0
            reference_stress[3] = (x2beta * math.cos(i * x3beta) +
                                   x1beta * math.sin(i * x3beta)) * (
                                       -x1beta * math.cos(i * x3beta) +
                                       x2beta * math.sin(i * x3beta))
            reference_stress[4] = x1beta * math.cos(
                i * x3beta) - x2beta * math.sin(i * x3beta)
            reference_stress[5] = -x2beta * math.cos(
                i * x3beta) - x1beta * math.sin(i * x3beta)

            reference_stress *= lame_mu

            stress = cl_params.GetStressVector()

            for j in range(cl.GetStrainSize()):
                self.assertAlmostEqual(reference_stress[j], stress[j], 2)
    def test_Uniaxial_KirchhoffSaintVenant_3D(self):
        nnodes = 4
        dim = 3

        # Define a model  and geometry
        model_part = KratosMultiphysics.ModelPart("test")

        geom = self._create_geometry(model_part, dim, nnodes)

        # Material properties
        young_modulus = 200e9
        poisson_ratio = 0.3
        properties = self._create_properties(model_part, young_modulus,
                                             poisson_ratio)

        N = KratosMultiphysics.Vector(nnodes)
        DN_DX = KratosMultiphysics.Matrix(nnodes, dim)

        # Construct a constitutive law
        cl = StructuralMechanicsApplication.KirchhoffSaintVenant3DLaw()
        self._cl_check(cl, properties, geom, model_part, dim)

        # Set the parameters to be employed
        dict_options = {
            'USE_ELEMENT_PROVIDED_STRAIN': False,
            'COMPUTE_STRESS': True,
            'COMPUTE_CONSTITUTIVE_TENSOR': True,
            'FINITE_STRAINS': True,
            'ISOTROPIC': True,
        }
        cl_options = self._set_cl_options(dict_options)

        # Define deformation gradient
        F = self._create_F()
        detF = 1.0

        stress_vector = KratosMultiphysics.Vector(cl.GetStrainSize())
        strain_vector = KratosMultiphysics.Vector(cl.GetStrainSize())
        constitutive_matrix = KratosMultiphysics.Matrix(
            cl.GetStrainSize(), cl.GetStrainSize())

        # Setting the parameters - note that a constitutive law may not need them all!
        cl_params = self._set_cl_parameters(cl_options, F, detF, strain_vector,
                                            stress_vector, constitutive_matrix,
                                            N, DN_DX, model_part, properties,
                                            geom)

        # Check the results
        lame_lambda = (young_modulus * poisson_ratio) / (
            (1.0 + poisson_ratio) * (1.0 - 2.0 * poisson_ratio))
        lame_mu = young_modulus / (2.0 * (1.0 + poisson_ratio))

        reference_stress = KratosMultiphysics.Vector(cl.GetStrainSize())
        for i in range(cl.GetStrainSize()):
            reference_stress[i] = 0.0

        for i in range(100):
            F[0, 0] = 1.0 + 0.05 * i
            detF = 1.0 + 0.05 * i
            cl_params.SetDeformationGradientF(F)
            cl_params.SetDeterminantF(detF)

            # Chauchy
            cl.CalculateMaterialResponseCauchy(cl_params)
            cl.FinalizeMaterialResponseCauchy(cl_params)
            cl.FinalizeSolutionStep(properties, geom, N,
                                    model_part.ProcessInfo)
            reference_stress[0] = ((lame_lambda * 0.5 + lame_mu) *
                                   (detF**2.0 - 1.0) * (detF**2.0)) / detF
            reference_stress[1] = 0.5 * lame_lambda * (detF**2.0 - 1.0) / detF
            reference_stress[2] = reference_stress[1]

            stress = cl_params.GetStressVector()

            for j in range(cl.GetStrainSize()):
                self.assertAlmostEqual(reference_stress[j], stress[j], 2)
    def test_J2_Plasticity_3D(self):
        nnodes = 8
        dim = 3

        # Define a model and geometry
        model_part = KratosMultiphysics.ModelPart("test")
        geom = self._create_geometry(model_part, dim, nnodes)

        # Material properties
        prop_id = 0
        properties = model_part.Properties[prop_id]
        properties.SetValue(KratosMultiphysics.YOUNG_MODULUS, 21000)
        properties.SetValue(KratosMultiphysics.POISSON_RATIO, 0.3)
        properties.SetValue(KratosMultiphysics.YIELD_STRESS, 5.5)
        properties.SetValue(KratosMultiphysics.REFERENCE_HARDENING_MODULUS,
                            1.0)
        properties.SetValue(KratosMultiphysics.ISOTROPIC_HARDENING_MODULUS,
                            0.12924)
        properties.SetValue(KratosMultiphysics.INFINITY_HARDENING_MODULUS, 0.0)
        properties.SetValue(KratosMultiphysics.HARDENING_EXPONENT, 1.0)

        N = KratosMultiphysics.Vector(nnodes)
        DN_DX = KratosMultiphysics.Matrix(nnodes, dim)

        # Construct a constitutive law
        cl = StructuralMechanicsApplication.LinearJ2Plasticity3DLaw()
        self._cl_check(cl, properties, geom, model_part, dim)

        # Set the parameters to be employed
        dict_options = {
            'USE_ELEMENT_PROVIDED_STRAIN': False,
            'COMPUTE_STRESS': True,
            'COMPUTE_CONSTITUTIVE_TENSOR': True,
        }
        cl_options = self._set_cl_options(dict_options)
        stress_vector = KratosMultiphysics.Vector(cl.GetStrainSize())
        strain_vector = KratosMultiphysics.Vector(cl.GetStrainSize())
        constitutive_matrix = KratosMultiphysics.Matrix(
            cl.GetStrainSize(), cl.GetStrainSize())

        # Setting the parameters - note that a constitutive law may not need them all!
        F = self._create_F()
        detF = 1.0
        cl_params = self._set_cl_parameters(cl_options, F, detF, strain_vector,
                                            stress_vector, constitutive_matrix,
                                            N, DN_DX, model_part, properties,
                                            geom)
        cl.InitializeMaterial(properties, geom, N)

        # Check the results
        nr_timesteps = 10
        rstress = []
        for i in range(nr_timesteps):
            rstress.append(KratosMultiphysics.Vector(cl.GetStrainSize()))
        rstress[0][0] = 4.03846
        rstress[0][1] = 4.03846
        rstress[0][2] = 2.42308
        rstress[0][3] = 0.80769
        rstress[0][4] = 0.0
        rstress[0][5] = 0.80769
        rstress[1][0] = 8.07692
        rstress[1][1] = 8.07692
        rstress[1][2] = 4.84615
        rstress[1][3] = 1.61538
        rstress[1][4] = 0.0
        rstress[1][5] = 1.61538
        rstress[2][0] = 11.6595
        rstress[2][1] = 11.6595
        rstress[2][2] = 8.18099
        rstress[2][3] = 1.73926
        rstress[2][4] = 0.0
        rstress[2][5] = 1.73926
        rstress[3][0] = 15.1595
        rstress[3][1] = 15.1595
        rstress[3][2] = 11.681
        rstress[3][3] = 1.73926
        rstress[3][4] = 0.0
        rstress[3][5] = 1.73926
        rstress[4][0] = 18.6595
        rstress[4][1] = 18.6595
        rstress[4][2] = 15.181
        rstress[4][3] = 1.73926
        rstress[4][4] = 0.0
        rstress[4][5] = 1.73926
        rstress[5][0] = 22.1595
        rstress[5][1] = 22.1595
        rstress[5][2] = 18.681
        rstress[5][3] = 1.73927
        rstress[5][4] = 0.0
        rstress[5][5] = 1.73927
        rstress[6][0] = 25.6595
        rstress[6][1] = 25.6595
        rstress[6][2] = 22.181
        rstress[6][3] = 1.73927
        rstress[6][4] = 0.0
        rstress[6][5] = 1.73927
        rstress[7][0] = 29.1595
        rstress[7][1] = 29.1595
        rstress[7][2] = 25.681
        rstress[7][3] = 1.73928
        rstress[7][4] = 0.0
        rstress[7][5] = 1.73928
        rstress[8][0] = 32.6595
        rstress[8][1] = 32.6595
        rstress[8][2] = 29.181
        rstress[8][3] = 1.73928
        rstress[8][4] = 0.0
        rstress[8][5] = 1.73928
        rstress[9][0] = 36.1595
        rstress[9][1] = 36.1595
        rstress[9][2] = 32.681
        rstress[9][3] = 1.73929
        rstress[9][4] = 0.0
        rstress[9][5] = 1.73929

        initial_strain = KratosMultiphysics.Vector(cl.GetStrainSize())
        initial_strain[0] = 0.001
        initial_strain[1] = 0.001
        initial_strain[2] = 0.0
        initial_strain[3] = 0.001
        initial_strain[4] = 0.0
        initial_strain[5] = 0.001

        t = dt = 1. / nr_timesteps
        c = 0
        while (t <= 1. + dt / 10.):
            strain = t * initial_strain
            cl_params.SetStrainVector(strain)

            # Chauchy
            cl.CalculateMaterialResponseCauchy(cl_params)
            cl.FinalizeMaterialResponseCauchy(cl_params)
            cl.FinalizeSolutionStep(properties, geom, N,
                                    model_part.ProcessInfo)
            stress = cl_params.GetStressVector()
            for j in range(cl.GetStrainSize()):
                self.assertAlmostEqual(rstress[c][j], stress[j], 4)
            t += dt
            c += 1
 def _apply_material_properties(self, mp):
     cl = StructuralMechanicsApplication.LinearElasticPlaneStress2DLaw()
     mp.GetProperties()[1].SetValue(KratosMultiphysics.CONSTITUTIVE_LAW, cl)
    def test_membrane_wrinkling_law(self):
        self.skipTestIfApplicationsNotAvailable("ConstitutiveLawsApplication")

        current_model = KratosMultiphysics.Model()
        mp = current_model.CreateModelPart("Structure")
        mp.SetBufferSize(2)
        mp.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] = 3
        self._add_variables(mp)

        # add properties and subproperties
        mp.GetProperties()[1].SetValue(KratosMultiphysics.YOUNG_MODULUS,
                                       206900000000.0)
        mp.GetProperties()[1].SetValue(KratosMultiphysics.POISSON_RATIO, 0.30)
        mp.GetProperties()[1].SetValue(KratosMultiphysics.THICKNESS, 0.0001)
        mp.GetProperties()[1].SetValue(KratosMultiphysics.DENSITY, 7850.0)
        constitutive_law = ConstitutiveLawsApplication.WrinklingLinear2DLaw()
        mp.GetProperties()[1].SetValue(KratosMultiphysics.CONSTITUTIVE_LAW,
                                       constitutive_law)
        sub_constitutive_law = StructuralMechanicsApplication.LinearElasticPlaneStress2DLaw(
        )
        mp.GetProperties()[2].SetValue(KratosMultiphysics.CONSTITUTIVE_LAW,
                                       sub_constitutive_law)
        mp.GetProperties()[1].AddSubProperties(mp.GetProperties()[2])
        mp.GetProperties()[1].SetValue(
            KratosMultiphysics.COMPUTE_LUMPED_MASS_MATRIX, True)

        # create nodes
        mp.CreateNewNode(1, 0.0000000000, 1.0000000000, 0.0000000000)
        mp.CreateNewNode(2, 0.0000000000, 0.0000000000, 0.0000000000)
        mp.CreateNewNode(3, 1.0000000000, 1.0000000000, 0.0000000000)
        mp.CreateNewNode(4, 1.0000000000, 0.0000000000, 0.0000000000)

        # add dofs
        self._add_dofs(mp)

        # create element
        element_name = "MembraneElement3D4N"
        mp.CreateNewElement(element_name, 1, [4, 3, 1, 2],
                            mp.GetProperties()[1])

        # create & apply dirichlet bcs
        bcs_dirichlet_all = mp.CreateSubModelPart(
            "BoundaryCondtionsDirichletAll")
        bcs_dirichlet_all.AddNodes([2, 4])

        bcs_dirichlet_mv = mp.CreateSubModelPart(
            "BoundaryCondtionsDirichletMove")
        bcs_dirichlet_mv.AddNodes([1, 3])

        self._apply_dirichlet_BCs(bcs_dirichlet_all)
        self._apply_dirichlet_BCs(bcs_dirichlet_mv, fix_type='YZ')

        # create & apply neumann bcs
        mp.CreateNewCondition("PointLoadCondition3D1N", 1, [1],
                              mp.GetProperties()[1])
        mp.CreateNewCondition("PointLoadCondition3D1N", 2, [3],
                              mp.GetProperties()[1])

        bcs_neumann = mp.CreateSubModelPart("BoundaryCondtionsNeumann")
        bcs_neumann.AddNodes([1, 3])
        bcs_neumann.AddConditions([1, 2])

        KratosMultiphysics.VariableUtils().SetScalarVar(
            StructuralMechanicsApplication.POINT_LOAD_X, 1000000.0,
            bcs_neumann.Nodes)

        # solve
        self._solve_static(mp)

        # check results
        self.assertAlmostEqual(
            mp.Nodes[1].GetSolutionStepValue(
                KratosMultiphysics.DISPLACEMENT_X), 0.58054148514004470, 4)
        self.assertAlmostEqual(
            mp.Nodes[3].GetSolutionStepValue(
                KratosMultiphysics.DISPLACEMENT_X), 0.15072065295319598, 4)
Exemple #17
0
 def create_constitutive_Law():
     return StructuralMechanicsApplication.SmallStrainJ2Plasticity3DLaw()
    def test_membrane_cauchy_stress_and_local_axis(self):

        current_model = KratosMultiphysics.Model()
        mp = current_model.CreateModelPart("Structure")
        mp.SetBufferSize(2)
        mp.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] = 3
        self._add_variables(mp)

        # add properties and subproperties
        thickness = 1.3
        height = 1.2
        length = 10.0

        mp.GetProperties()[1].SetValue(KratosMultiphysics.YOUNG_MODULUS, 500.0)
        mp.GetProperties()[1].SetValue(KratosMultiphysics.POISSON_RATIO, 0.00)
        mp.GetProperties()[1].SetValue(KratosMultiphysics.THICKNESS, thickness)
        mp.GetProperties()[1].SetValue(KratosMultiphysics.DENSITY, 7850.0)
        mp.GetProperties()[1].SetValue(
            KratosMultiphysics.CONSTITUTIVE_LAW,
            StructuralMechanicsApplication.LinearElasticPlaneStress2DLaw())

        # create nodes
        mp.CreateNewNode(1, -0.668004, 0.9192533, 0.3856725)
        mp.CreateNewNode(2, 0.0, 0.0, 0.0)
        mp.CreateNewNode(3, 5.966131, 7.3471293, -3.4445475)
        mp.CreateNewNode(4, 6.634135, 6.427876, -3.83022)

        # add dofs
        self._add_dofs(mp)

        # create element
        element_name = "MembraneElement3D4N"
        mp.CreateNewElement(element_name, 1, [4, 3, 1, 2],
                            mp.GetProperties()[1])

        # create & apply dirichlet bcs
        bcs_dirichlet_all = mp.CreateSubModelPart(
            "BoundaryCondtionsDirichletAll")
        bcs_dirichlet_all.AddNodes([1, 2])

        self._apply_dirichlet_BCs(bcs_dirichlet_all)

        # create & apply neumann bcs
        mp.CreateNewCondition("PointLoadCondition3D1N", 1, [3],
                              mp.GetProperties()[1])
        mp.CreateNewCondition("PointLoadCondition3D1N", 2, [4],
                              mp.GetProperties()[1])

        bcs_neumann = mp.CreateSubModelPart("BoundaryCondtionsNeumann")
        bcs_neumann.AddNodes([3, 4])
        bcs_neumann.AddConditions([1, 2])
        point_load = 5.0

        KratosMultiphysics.VariableUtils().SetScalarVar(
            StructuralMechanicsApplication.POINT_LOAD_X,
            point_load * 0.6634135, bcs_neumann.Nodes)
        KratosMultiphysics.VariableUtils().SetScalarVar(
            StructuralMechanicsApplication.POINT_LOAD_Y,
            point_load * 0.6427876, bcs_neumann.Nodes)
        KratosMultiphysics.VariableUtils().SetScalarVar(
            StructuralMechanicsApplication.POINT_LOAD_Z,
            point_load * (-0.383022), bcs_neumann.Nodes)

        ## 1.) with local axis calculated from element (dependent on node numbering)
        cauchy_stress_analytical = point_load * len(
            bcs_neumann.Nodes) / (thickness * height)

        # solve
        self._solve_static(mp)

        disp_x_i = mp.Nodes[4].GetSolutionStepValue(
            KratosMultiphysics.DISPLACEMENT_X)
        disp_y_i = mp.Nodes[4].GetSolutionStepValue(
            KratosMultiphysics.DISPLACEMENT_Y)
        disp_z_i = mp.Nodes[4].GetSolutionStepValue(
            KratosMultiphysics.DISPLACEMENT_Z)
        disp_i = (disp_x_i**2 + disp_y_i**2 + disp_z_i**2)**0.5
        det_F_inv = length / (length + disp_i)

        for element_i in mp.Elements:
            pk2 = element_i.CalculateOnIntegrationPoints(
                KratosMultiphysics.PK2_STRESS_VECTOR, mp.ProcessInfo)
            cauchy = element_i.CalculateOnIntegrationPoints(
                KratosMultiphysics.CAUCHY_STRESS_VECTOR, mp.ProcessInfo)

            # check results
            for i in range(4):
                self.assertAlmostEqual(cauchy[i][0], 0.0, 5)
                self.assertAlmostEqual(cauchy[i][1], cauchy_stress_analytical,
                                       5)
                self.assertAlmostEqual(cauchy[i][2], 0.0, 5)

                self.assertAlmostEqual(pk2[i][0], 0.0, 5)
                self.assertAlmostEqual(pk2[i][1],
                                       cauchy_stress_analytical * det_F_inv, 5)
                self.assertAlmostEqual(pk2[i][2], 0.0, 5)

        ## 2.) with local mat_axis = 0.6634135,0.6427876,-0.383022 : along forces

        projection_settings = KratosMultiphysics.Parameters("""
        {
            "model_part_name"  : "Structure",
            "projection_type"  : "planar",
            "global_direction" : [0.6634135,0.6427876,-0.383022],
            "variable_name"    : "LOCAL_MATERIAL_AXIS_1"
        }
        """)
        StructuralMechanicsApplication.ProjectVectorOnSurfaceUtility.Execute(
            mp, projection_settings)

        # solve
        self._solve_static(mp)

        disp_x_i = mp.Nodes[4].GetSolutionStepValue(
            KratosMultiphysics.DISPLACEMENT_X)
        disp_y_i = mp.Nodes[4].GetSolutionStepValue(
            KratosMultiphysics.DISPLACEMENT_Y)
        disp_z_i = mp.Nodes[4].GetSolutionStepValue(
            KratosMultiphysics.DISPLACEMENT_Z)
        disp_i = (disp_x_i**2 + disp_y_i**2 + disp_z_i**2)**0.5
        det_F_inv = length / (length + disp_i)

        for element_i in mp.Elements:
            pk2 = element_i.CalculateOnIntegrationPoints(
                KratosMultiphysics.PK2_STRESS_VECTOR, mp.ProcessInfo)
            cauchy = element_i.CalculateOnIntegrationPoints(
                KratosMultiphysics.CAUCHY_STRESS_VECTOR, mp.ProcessInfo)

            # check results
            for i in range(4):
                self.assertAlmostEqual(cauchy[i][0], cauchy_stress_analytical,
                                       5)
                self.assertAlmostEqual(cauchy[i][1], 0.0, 5)
                self.assertAlmostEqual(cauchy[i][2], 0.0, 5)

                self.assertAlmostEqual(pk2[i][0],
                                       cauchy_stress_analytical * det_F_inv, 5)
                self.assertAlmostEqual(pk2[i][1], 0.0, 5)
                self.assertAlmostEqual(pk2[i][2], 0.0, 5)

        ## 3.) with local mat_axis = 0.07537005, 0.9961943, -0.0437662 -> rotate stress state by 45°
        cauchy_stress_analytical /= 2.0

        projection_settings = KratosMultiphysics.Parameters("""
        {
            "model_part_name"  : "Structure",
            "projection_type"  : "planar",
            "global_direction" : [0.07537005, 0.9961943, -0.0437662],
            "variable_name"    : "LOCAL_MATERIAL_AXIS_1"
        }
        """)
        StructuralMechanicsApplication.ProjectVectorOnSurfaceUtility.Execute(
            mp, projection_settings)

        # solve
        self._solve_static(mp)

        disp_x_i = mp.Nodes[4].GetSolutionStepValue(
            KratosMultiphysics.DISPLACEMENT_X)
        det_F_inv = length / (length + disp_x_i)

        for element_i in mp.Elements:
            cauchy = element_i.CalculateOnIntegrationPoints(
                KratosMultiphysics.CAUCHY_STRESS_VECTOR, mp.ProcessInfo)

            # check results
            for i in range(4):
                self.assertAlmostEqual(cauchy[i][0], cauchy_stress_analytical,
                                       5)
                self.assertAlmostEqual(cauchy[i][1], cauchy_stress_analytical,
                                       5)
                self.assertAlmostEqual(abs(cauchy[i][2]),
                                       cauchy_stress_analytical, 5)
Exemple #19
0
    def _base_fall_test_dynamic_schemes(self,
                                        current_model,
                                        scheme_name="bossak",
                                        buffer_size=2,
                                        dt=1.0e-2):
        mp = current_model.CreateModelPart("sdof")
        mp.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] = 2
        add_variables(mp, scheme_name)

        if (scheme_name == "explicit"):
            # Create node
            node = mp.CreateNewNode(1, 0.0, 0.0, 0.0)
            node.AddDof(KratosMultiphysics.DISPLACEMENT_X)
            node.AddDof(KratosMultiphysics.DISPLACEMENT_Y)
            node.AddDof(KratosMultiphysics.DISPLACEMENT_Z)
            second_node = mp.CreateNewNode(2, 1.0, 0.0, 0.0)
            second_node.AddDof(KratosMultiphysics.DISPLACEMENT_X)
            second_node.AddDof(KratosMultiphysics.DISPLACEMENT_Y)
            second_node.AddDof(KratosMultiphysics.DISPLACEMENT_Z)

            #add bcs and initial values
            node.Fix(KratosMultiphysics.DISPLACEMENT_X)
            node.Fix(KratosMultiphysics.DISPLACEMENT_Z)
            node.SetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y, 0,
                                      0.0)
            second_node.Fix(KratosMultiphysics.DISPLACEMENT_X)
            second_node.Fix(KratosMultiphysics.DISPLACEMENT_Z)
            second_node.SetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y,
                                             0, 0.0)

            #create element
            prop = mp.GetProperties()[1]
            prop.SetValue(
                KratosMultiphysics.CONSTITUTIVE_LAW,
                StructuralMechanicsApplication.TrussConstitutiveLaw())
            prop.SetValue(KratosMultiphysics.DENSITY, 1.0)
            prop.SetValue(StructuralMechanicsApplication.CROSS_AREA, 1.0)
            prop.SetValue(KratosMultiphysics.YOUNG_MODULUS, 1.0)
            prop.SetValue(StructuralMechanicsApplication.TRUSS_PRESTRESS_PK2,
                          0.0)
            element = mp.CreateNewElement("TrussElement3D2N", 1, [1, 2], prop)
            gravity = -9.81
            node.SetSolutionStepValue(KratosMultiphysics.VOLUME_ACCELERATION_Y,
                                      0, gravity)
            second_node.SetSolutionStepValue(
                KratosMultiphysics.VOLUME_ACCELERATION_Y, 0, gravity)
        else:
            # Create node
            node = mp.CreateNewNode(1, 0.0, 0.0, 0.0)
            node.AddDof(KratosMultiphysics.DISPLACEMENT_X)
            node.AddDof(KratosMultiphysics.DISPLACEMENT_Y)
            node.AddDof(KratosMultiphysics.DISPLACEMENT_Z)

            #add bcs and initial values
            node.Fix(KratosMultiphysics.DISPLACEMENT_X)
            node.Fix(KratosMultiphysics.DISPLACEMENT_Z)
            node.SetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y, 0,
                                      0.0)

            #create element
            element = mp.CreateNewElement("NodalConcentratedElement3D1N", 1,
                                          [1],
                                          mp.GetProperties()[1])
            mass = 1.0
            stiffness = 0.0
            element.SetValue(KratosMultiphysics.NODAL_MASS, mass)
            element.SetValue(StructuralMechanicsApplication.NODAL_STIFFNESS,
                             [0, stiffness, 0])
            gravity = -9.81
            node.SetSolutionStepValue(KratosMultiphysics.VOLUME_ACCELERATION_Y,
                                      0, gravity)

        #time integration parameters
        time = 0.0
        end_time = 1.0e-1
        step = 0

        set_and_fill_buffer(mp, buffer_size, dt)

        #parameters for analytical solution
        self.strategy = create_solver(mp, scheme_name)

        current_analytical_displacement_y = 0.0
        current_analytical_velocity_y = 0.0
        current_analytical_acceleration_y = 0.0

        # Fill buffer solution
        for i in range(buffer_size):
            time = time + dt
            step = i + 1
            mp.CloneTimeStep(time)
            mp.ProcessInfo[KratosMultiphysics.STEP] = step

            current_analytical_displacement_y += current_analytical_velocity_y * dt + 0.25 * (
                current_analytical_acceleration_y + gravity) * dt**2
            current_analytical_velocity_y += dt * 0.5 * (
                current_analytical_acceleration_y + gravity)
            current_analytical_acceleration_y = gravity

            node.SetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y, 0,
                                      current_analytical_displacement_y)
            node.SetSolutionStepValue(KratosMultiphysics.VELOCITY_Y, 0,
                                      current_analytical_velocity_y)
            node.SetSolutionStepValue(KratosMultiphysics.ACCELERATION_Y, 0,
                                      current_analytical_acceleration_y)

        # Solve the problem
        while (time <= end_time):
            time = time + dt
            step = step + 1
            mp.CloneTimeStep(time)
            mp.ProcessInfo[KratosMultiphysics.STEP] = step

            self.strategy.Solve()
            current_analytical_displacement_y += current_analytical_velocity_y * dt + 0.25 * (
                current_analytical_acceleration_y + gravity) * dt**2
            current_analytical_velocity_y += dt * 0.5 * (
                current_analytical_acceleration_y + gravity)
            current_analytical_acceleration_y = gravity

            # ASSERT
            self.assertAlmostEqual(node.GetSolutionStepValue(
                KratosMultiphysics.ACCELERATION_Y, 0),
                                   current_analytical_acceleration_y,
                                   delta=1e-3)
            self.assertAlmostEqual(node.GetSolutionStepValue(
                KratosMultiphysics.VELOCITY_Y, 0),
                                   current_analytical_velocity_y,
                                   delta=1e-3)
            self.assertAlmostEqual(node.GetSolutionStepValue(
                KratosMultiphysics.DISPLACEMENT_Y, 0),
                                   current_analytical_displacement_y,
                                   delta=1e-3)
Exemple #20
0
 def ComputeDeltaTime(self):
     if self.dynamic_settings["time_step_prediction_level"].GetInt() > 1:
         self.delta_time = StructuralMechanicsApplication.CalculateDeltaTime(self.GetComputingModelPart(), self.delta_time_settings)
     return self.delta_time
Exemple #21
0
    def ExecuteBeforeSolutionLoop(self):
        """ This method is executed before starting the time loop

        Keyword arguments:
        self -- It signifies an instance of a class.
        """

        import KratosMultiphysics.kratos_utilities as kratos_utils
        if kratos_utils.CheckIfApplicationsAvailable(
                "ExternalSolversApplication"):
            from KratosMultiphysics import ExternalSolversApplication
        elif kratos_utils.CheckIfApplicationsAvailable(
                "EigenSolversApplication"):
            from KratosMultiphysics import EigenSolversApplication
        else:
            raise Exception(
                "ExternalSolversApplication or EigenSolversApplication not available"
            )

        # The general damping ratios
        damping_ratio_0 = self.settings["damping_ratio_0"].GetDouble()
        damping_ratio_1 = self.settings["damping_ratio_1"].GetDouble()

        # We get the model parts which divide the problem
        current_process_info = self.main_model_part.ProcessInfo
        existing_computation = current_process_info.Has(SMA.EIGENVALUE_VECTOR)

        # Create auxiliar parameters
        compute_damping_coefficients_settings = KM.Parameters("""
        {
            "echo_level"          : 0,
            "damping_ratio_0"     : 0.0,
            "damping_ratio_1"     : -1.0,
            "eigen_values_vector" : [0.0]
        }
        """)

        # Setting custom parameters
        compute_damping_coefficients_settings["echo_level"].SetInt(
            self.settings["echo_level"].GetInt())
        compute_damping_coefficients_settings["damping_ratio_0"].SetDouble(
            damping_ratio_0)
        compute_damping_coefficients_settings["damping_ratio_1"].SetDouble(
            damping_ratio_1)

        # We check if the values are previously defined
        properties = self.main_model_part.GetProperties()
        for prop in properties:
            if prop.Has(SMA.SYSTEM_DAMPING_RATIO):
                self.settings["damping_ratio_0"].SetDouble(
                    prop.GetValue(SMA.SYSTEM_DAMPING_RATIO))
                break
        for prop in properties:
            if prop.Has(SMA.SECOND_SYSTEM_DAMPING_RATIO):
                self.settings["damping_ratio_1"].SetDouble(
                    prop.GetValue(SMA.SECOND_SYSTEM_DAMPING_RATIO))
                break

        # We have computed already the eigen values
        current_process_info = self.main_model_part.ProcessInfo
        precomputed_eigen_values = self.settings[
            "eigen_values_vector"].GetVector()
        if len(precomputed_eigen_values) > 1:
            compute_damping_coefficients_settings[
                "eigen_values_vector"].SetVector(precomputed_eigen_values)
        else:
            # If not computed eigen values already
            if not existing_computation:
                KM.Logger.PrintInfo(
                    "::[MechanicalSolver]::",
                    "EIGENVALUE_VECTOR not previously computed. Computing automatically, take care"
                )
                from KratosMultiphysics import eigen_solver_factory
                eigen_linear_solver = eigen_solver_factory.ConstructSolver(
                    self.settings["eigen_system_settings"])
                builder_and_solver = KM.ResidualBasedBlockBuilderAndSolver(
                    eigen_linear_solver)
                eigen_scheme = SMA.EigensolverDynamicScheme()
                eigen_solver = SMA.EigensolverStrategy(self.main_model_part,
                                                       eigen_scheme,
                                                       builder_and_solver)
                eigen_solver.Solve()

                # Setting the variable RESET_EQUATION_IDS
                current_process_info[SMA.RESET_EQUATION_IDS] = True

            eigenvalue_vector = current_process_info.GetValue(
                SMA.EIGENVALUE_VECTOR)
            compute_damping_coefficients_settings[
                "eigen_values_vector"].SetVector(eigenvalue_vector)

        # We compute the coefficients
        coefficients_vector = SMA.ComputeDampingCoefficients(
            compute_damping_coefficients_settings)

        # We set the values
        if self.settings["write_on_properties"].GetBool():
            for prop in self.main_model_part.Properties:
                prop.SetValue(SMA.RAYLEIGH_ALPHA, coefficients_vector[0])
                if current_process_info.Has(KM.COMPUTE_LUMPED_MASS_MATRIX):
                    if current_process_info[KM.COMPUTE_LUMPED_MASS_MATRIX]:
                        prop.SetValue(SMA.RAYLEIGH_BETA, 0.0)
                    else:
                        prop.SetValue(SMA.RAYLEIGH_BETA,
                                      coefficients_vector[1])
                else:
                    prop.SetValue(SMA.RAYLEIGH_BETA, coefficients_vector[1])
        else:
            current_process_info.SetValue(SMA.RAYLEIGH_ALPHA,
                                          coefficients_vector[0])
            if current_process_info.Has(KM.COMPUTE_LUMPED_MASS_MATRIX):
                if current_process_info[KM.COMPUTE_LUMPED_MASS_MATRIX]:
                    current_process_info.SetValue(SMA.RAYLEIGH_BETA, 0.0)
                else:
                    current_process_info.SetValue(SMA.RAYLEIGH_BETA,
                                                  coefficients_vector[1])
            else:
                current_process_info.SetValue(SMA.RAYLEIGH_BETA,
                                              coefficients_vector[1])
Exemple #22
0
 def ExecuteInitialize(self):
     sprism_neighbour_search = SMA.PrismNeighboursProcess(self.model_part)
     sprism_neighbour_search.Execute()
Exemple #23
0
def _create_dynamic_explicit_strategy(mp):
    scheme = StructuralMechanicsApplication.ExplicitCentralDifferencesScheme(0.00,0.00,0.00)

    strategy = StructuralMechanicsApplication.MechanicalExplicitStrategy(mp,scheme,0,0,1)
    strategy.SetEchoLevel(0)
    return strategy
    def __init__(self, convergence_criterion_parameters):
        # Note that all the convergence settings are introduced via a Kratos parameters object.

        D_RT = convergence_criterion_parameters["displacement_relative_tolerance"].GetDouble()
        D_AT = convergence_criterion_parameters["displacement_absolute_tolerance"].GetDouble()
        R_RT = convergence_criterion_parameters["residual_relative_tolerance"].GetDouble()
        R_AT = convergence_criterion_parameters["residual_absolute_tolerance"].GetDouble()

        echo_level = convergence_criterion_parameters["echo_level"].GetInt()
        convergence_crit = convergence_criterion_parameters["convergence_criterion"].GetString()

        if(echo_level >= 1):
            KratosMultiphysics.Logger.PrintInfo("::[Mechanical Solver]:: ", "CONVERGENCE CRITERION : " +
                  convergence_criterion_parameters["convergence_criterion"].GetString())

        rotation_dofs = False
        if(convergence_criterion_parameters.Has("rotation_dofs")):
            if(convergence_criterion_parameters["rotation_dofs"].GetBool()):
                rotation_dofs = True

        volumetric_strain_dofs = False
        if convergence_criterion_parameters.Has("volumetric_strain_dofs"):
            if convergence_criterion_parameters["volumetric_strain_dofs"].GetBool():
                volumetric_strain_dofs = True

        # Convergence criteria if there are rotation DOFs in the problem
        if(rotation_dofs):
            if(convergence_crit == "displacement_criterion"):
                self.mechanical_convergence_criterion = KratosMultiphysics.MixedGenericCriteria(
                    [(KratosMultiphysics.DISPLACEMENT, D_RT, D_AT),
                    (KratosMultiphysics.ROTATION, D_RT, D_AT)])
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif(convergence_crit == "residual_criterion"):
                self.mechanical_convergence_criterion = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(R_RT, R_AT)
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif(convergence_crit == "and_criterion"):
                Displacement = KratosMultiphysics.MixedGenericCriteria(
                    [(KratosMultiphysics.DISPLACEMENT, D_RT, D_AT),
                    (KratosMultiphysics.ROTATION, D_RT, D_AT)])
                Displacement.SetEchoLevel(echo_level)
                Residual = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(R_RT, R_AT)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.AndCriteria(Residual, Displacement)

            elif(convergence_crit == "or_criterion"):
                Displacement = KratosMultiphysics.MixedGenericCriteria(
                    [(KratosMultiphysics.DISPLACEMENT, D_RT, D_AT),
                    (KratosMultiphysics.ROTATION, D_RT, D_AT)])
                Displacement.SetEchoLevel(echo_level)
                Residual = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(R_RT, R_AT)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.OrCriteria(Residual, Displacement)
            else:
                err_msg =  "The requested convergence criterion \"" + convergence_crit + "\" is not available!\n"
                err_msg += "Available options are: \"displacement_criterion\", \"residual_criterion\", \"and_criterion\", \"or_criterion\""
                raise Exception(err_msg)

        # Convergence criteria if there are volumetric strain DOFs in the problem
        elif(volumetric_strain_dofs):
            other_dof_name = "VOLUMETRIC_STRAIN"
            if(convergence_crit == "displacement_criterion"):
                self.mechanical_convergence_criterion = KratosMultiphysics.MixedGenericCriteria(
                    [(KratosMultiphysics.DISPLACEMENT, D_RT, D_AT),
                    (KratosMultiphysics.VOLUMETRIC_STRAIN, D_RT, D_AT)])
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif(convergence_crit == "residual_criterion"):
                self.mechanical_convergence_criterion = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(R_RT, R_AT, other_dof_name)
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif(convergence_crit == "and_criterion"):
                Displacement = KratosMultiphysics.MixedGenericCriteria(
                    [(KratosMultiphysics.DISPLACEMENT, D_RT, D_AT),
                    (KratosMultiphysics.VOLUMETRIC_STRAIN, D_RT, D_AT)])
                Displacement.SetEchoLevel(echo_level)
                Residual = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(R_RT, R_AT, other_dof_name)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.AndCriteria(Residual, Displacement)

            elif(convergence_crit == "or_criterion"):
                Displacement = KratosMultiphysics.MixedGenericCriteria(
                    [(KratosMultiphysics.DISPLACEMENT, D_RT, D_AT),
                    (KratosMultiphysics.VOLUMETRIC_STRAIN, D_RT, D_AT)])
                Displacement.SetEchoLevel(echo_level)
                Residual = StructuralMechanicsApplication.ResidualDisplacementAndOtherDoFCriteria(R_RT, R_AT, other_dof_name)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.OrCriteria(Residual, Displacement)
            else:
                err_msg =  "The requested convergence criterion \"" + convergence_crit + "\" is not available!\n"
                err_msg += "Available options are: \"displacement_criterion\", \"residual_criterion\", \"and_criterion\", \"or_criterion\""
                raise Exception(err_msg)

        # Convergence criteria without rotation DOFs
        else:
            if(convergence_crit == "displacement_criterion"):
                self.mechanical_convergence_criterion = KratosMultiphysics.DisplacementCriteria(D_RT, D_AT)
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif(convergence_crit == "residual_criterion"):
                self.mechanical_convergence_criterion = KratosMultiphysics.ResidualCriteria(R_RT, R_AT)
                self.mechanical_convergence_criterion.SetEchoLevel(echo_level)

            elif(convergence_crit == "and_criterion"):
                Displacement = KratosMultiphysics.DisplacementCriteria(D_RT, D_AT)
                Displacement.SetEchoLevel(echo_level)
                Residual = KratosMultiphysics.ResidualCriteria(R_RT, R_AT)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.AndCriteria(Residual, Displacement)

            elif(convergence_crit == "or_criterion"):
                Displacement = KratosMultiphysics.DisplacementCriteria(D_RT, D_AT)
                Displacement.SetEchoLevel(echo_level)
                Residual = KratosMultiphysics.ResidualCriteria(R_RT, R_AT)
                Residual.SetEchoLevel(echo_level)
                self.mechanical_convergence_criterion = KratosMultiphysics.OrCriteria(Residual, Displacement)
            else:
                err_msg =  "The requested convergence criterion \"" + convergence_crit + "\" is not available!\n"
                err_msg += "Available options are: \"displacement_criterion\", \"residual_criterion\", \"and_criterion\", \"or_criterion\""
                raise Exception(err_msg)
 def create_constitutive_Law():
     return StructuralMechanicsApplication.HyperElastic3DLaw()
Exemple #26
0
 def _create_solution_scheme(self):
     self.scheme_settings.AddValue("rotation_dofs",
                                   self.settings["rotation_dofs"])
     return StructuralMechanicsApplication.AdjointStructuralStaticScheme(
         self.scheme_settings, self.response_function)
 def create_constitutive_Law():
     return StructuralMechanicsApplication.ElasticPlaneStressUncoupledShear2DLaw(
     )
Exemple #28
0
 def _apply_material_properties(self,mp):
     cl = StructuralMechanicsApplication.LinearElasticPlaneStress2DLaw()
     mp.GetProperties()[1].SetValue(KratosMultiphysics.CONSTITUTIVE_LAW,cl)
     mp.GetProperties()[1].SetValue(KratosMultiphysics.DENSITY,2000)
     mp.GetProperties()[1].SetValue(KratosMultiphysics.YOUNG_MODULUS,10000)
     mp.GetProperties()[1].SetValue(StructuralMechanicsApplication.CROSS_AREA,1.0)
 def create_constitutive_Law():
     return StructuralMechanicsApplication.LinearIsotropicDamage3DLaw()
Exemple #30
0
 def ExecuteFinalize(self):
     StructuralMechanicsApplication.PostprocessEigenvaluesProcess(
         self.model_part, self.settings).Execute()