Example #1
0
    def GetConvergenceCriteria(self, error_criteria, conv_settings):
        if "_with_adaptative_remesh" in error_criteria:
            conv_settings["convergence_criterion"].SetString(error_criteria.replace("_with_adaptative_remesh", ""))
        import contact_convergence_criteria_factory
        convergence_criterion = contact_convergence_criteria_factory.convergence_criterion(conv_settings)

        # If we just use the adaptative convergence criteria
        if missing_meshing_dependencies:
            if "adaptative_remesh" in error_criteria:
                raise NameError('The AdaptativeErrorCriteria can not be used without compiling the MeshingApplication')
        else:
            if error_criteria == "adaptative_remesh_criteria":
                adaptative_error_criteria = CSMA.ContactErrorMeshCriteria(self.adaptative_remesh_parameters["compute_error_settings"])
                convergence_criterion.mechanical_convergence_criterion = KM.AndCriteria(convergence_criterion.GetMortarCriteria(False), adaptative_error_criteria)
            elif "with_adaptative_remesh" in error_criteria: # If we combine the regular convergence criteria with adaptative
                adaptative_error_criteria = CSMA.ContactErrorMeshCriteria(self.adaptative_remesh_parameters["compute_error_settings"])
                convergence_criterion.mechanical_convergence_criterion = KM.AndCriteria(convergence_criterion.mechanical_convergence_criterion, adaptative_error_criteria)

        return convergence_criterion.mechanical_convergence_criterion

        # If we combine the regular convergence criteria with adaptative
        if not missing_meshing_dependencies:
            if "with_adaptative_remesh" in error_criteria:
                adaptative_error_criteria = CSMA.ContactErrorMeshCriteria(self.adaptative_remesh_parameters["compute_error_settings"])
                convergence_criterion.mechanical_convergence_criterion = KM.AndCriteria(convergence_criterion.mechanical_convergence_criterion, adaptative_error_criteria)
        return convergence_criterion.mechanical_convergence_criterion
    def _GenerateErrorProcess(self):
        """ This method creates an erro process to compute the metric

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

        # We compute the error
        error_compute_parameters = KratosMultiphysics.Parameters("""{}""")
        error_compute_parameters.AddValue(
            "stress_vector_variable",
            self.settings["error_strategy_parameters"]
            ["compute_error_extra_parameters"]["stress_vector_variable"])
        error_compute_parameters.AddValue(
            "penalty_normal", self.settings["error_strategy_parameters"]
            ["compute_error_extra_parameters"]["penalty_normal"])
        error_compute_parameters.AddValue(
            "penalty_tangential", self.settings["error_strategy_parameters"]
            ["compute_error_extra_parameters"]["penalty_tangential"])
        error_compute_parameters.AddValue("echo_level",
                                          self.settings["echo_level"])
        if self.domain_size == 2:
            return ContactStructuralMechanicsApplication.ContactSPRErrorProcess2D(
                self.main_model_part, error_compute_parameters)
        else:
            return ContactStructuralMechanicsApplication.ContactSPRErrorProcess3D(
                self.main_model_part, error_compute_parameters)
Example #3
0
    def _create_main_search(self, key = "0"):
        """ This method creates the search process that will be use during contact search

        Keyword arguments:
        self -- It signifies an instance of a class.
        key -- The key to identify the current pair
        """

        search_parameters = KM.Parameters("""{"condition_name": "", "final_string": "", "predefined_master_slave" : true, "id_name" : ""}""")
        search_parameters.AddValue("type_search", self.settings["search_parameters"]["type_search"])
        search_parameters.AddValue("check_gap", self.settings["search_parameters"]["check_gap"])
        search_parameters.AddValue("allocation_size", self.settings["search_parameters"]["max_number_results"])
        search_parameters.AddValue("bucket_size", self.settings["search_parameters"]["bucket_size"])
        search_parameters.AddValue("search_factor", self.settings["search_parameters"]["search_factor"])
        search_parameters.AddValue("dynamic_search", self.settings["search_parameters"]["dynamic_search"])
        search_parameters.AddValue("static_check_movement", self.settings["search_parameters"]["static_check_movement"])
        search_parameters.AddValue("consider_gap_threshold", self.settings["search_parameters"]["consider_gap_threshold"])
        search_parameters.AddValue("debug_mode", self.settings["search_parameters"]["debug_mode"])
        search_parameters["condition_name"].SetString(self._get_condition_name())
        search_parameters["final_string"].SetString(self._get_final_string())
        self.__assume_master_slave(key)
        search_parameters["predefined_master_slave"].SetBool(self.predefined_master_slave)
        search_parameters["id_name"].SetString(key)

        # We compute the number of nodes of the geometry
        number_nodes, number_nodes_master = self._compute_number_nodes()

        # We create the search process
        simple_search = self.settings["search_parameters"]["simple_search"].GetBool()
        if self.dimension == 2:
            if simple_search:
                self.search_search[key] = CSMA.SimpleContactSearch2D2N(self.computing_model_part, search_parameters)
            else:
                self.search_search[key] = CSMA.AdvancedContactSearch2D2N(self.computing_model_part, search_parameters)
        else:
            if number_nodes == 3:
                if number_nodes_master == 3:
                    if simple_search:
                        self.search_search[key] = CSMA.SimpleContactSearch3D3N(self.computing_model_part, search_parameters)
                    else:
                        self.search_search[key] = CSMA.AdvancedContactSearch3D3N(self.computing_model_part, search_parameters)
                else:
                    if simple_search:
                        self.search_search[key] = CSMA.SimpleContactSearch3D3N4N(self.computing_model_part, search_parameters)
                    else:
                        self.search_search[key] = CSMA.AdvancedContactSearch3D3N4N(self.computing_model_part, search_parameters)

            elif number_nodes == 4:
                if number_nodes_master == 3:
                    if simple_search:
                        self.search_search[key] = CSMA.SimpleContactSearch3D4N3N(self.computing_model_part, search_parameters)
                    else:
                        self.search_search[key] = CSMA.AdvancedContactSearch3D4N3N(self.computing_model_part, search_parameters)
                else:
                    if simple_search:
                        self.search_search[key] = CSMA.SimpleContactSearch3D4N(self.computing_model_part, search_parameters)
                    else:
                        self.search_search[key] = CSMA.AdvancedContactSearch3D4N(self.computing_model_part, search_parameters)
            else:
                raise Exception("Geometries not compatible. Check all the geometries are linear")
    def _create_builder_and_solver(self):
        if self.contact_settings["mortar_type"].GetString() != "":
            linear_solver = self.get_linear_solver()
            if self.settings["block_builder"].GetBool():
                if self.settings["multi_point_constraints_used"].GetBool():
                    builder_and_solver = CSMA.ContactResidualBasedBlockBuilderAndSolverWithConstraints(
                        linear_solver)
                else:
                    builder_and_solver = CSMA.ContactResidualBasedBlockBuilderAndSolver(
                        linear_solver)
            else:
                # We use the elimination builder and solver
                if self.settings["multi_point_constraints_used"].GetBool():
                    if (self.GetComputingModelPart().
                            NumberOfMasterSlaveConstraints() > 0):
                        self.GetComputingModelPart().Set(
                            KM.TO_SPLIT)  # We set the flag for some operations
                    builder_and_solver = CSMA.ContactResidualBasedEliminationBuilderAndSolverWithConstraints(
                        linear_solver)
                else:
                    builder_and_solver = CSMA.ContactResidualBasedEliminationBuilderAndSolver(
                        linear_solver)
        else:
            builder_and_solver = super(ContactStaticMechanicalSolver,
                                       self)._create_builder_and_solver()

        return builder_and_solver
    def _create_builder_and_solver(self):
        if self.contact_settings["mortar_type"].GetString() != "":
            linear_solver = self.get_linear_solver()
            if self.settings["block_builder"].GetBool():
                if self.settings["multi_point_constraints_used"].GetBool():
                    builder_and_solver = CSMA.ContactResidualBasedBlockBuilderAndSolverWithConstraints(linear_solver)
                else:
                    builder_and_solver = CSMA.ContactResidualBasedBlockBuilderAndSolver(linear_solver)
            else:
                raise Exception("Contact not compatible with EliminationBuilderAndSolver")
        else:
            builder_and_solver = super(ContactStaticMechanicalSolver, self)._create_builder_and_solver()

        return builder_and_solver
Example #6
0
    def _create_builder_and_solver(self):
        if self.contact_settings["mortar_type"].GetString() != "":
            linear_solver = self.get_linear_solver()
            if self.settings["block_builder"].GetBool():
                if self.settings["multi_point_constraints_used"].GetBool():
                    builder_and_solver = CSMA.ContactResidualBasedBlockBuilderAndSolverWithConstraints(linear_solver)
                else:
                    builder_and_solver = CSMA.ContactResidualBasedBlockBuilderAndSolver(linear_solver)
            else:
                builder_and_solver = super(ContactImplicitMechanicalSolver, self)._create_builder_and_solver()
        else:
            builder_and_solver = super(ContactImplicitMechanicalSolver, self)._create_builder_and_solver()

        return builder_and_solver
Example #7
0
    def _create_main_search(self, key="0"):
        """ This method creates the search process that will be use during contact search

        Keyword arguments:
        self -- It signifies an instance of a class.
        key -- The key to identify the current pair
        """

        search_parameters = KM.Parameters(
            """{"condition_name": "", "final_string": "", "predefined_master_slave" : true, "id_name" : ""}"""
        )
        search_parameters.AddValue(
            "type_search", self.settings["search_parameters"]["type_search"])
        search_parameters.AddValue(
            "check_gap", self.settings["search_parameters"]["check_gap"])
        search_parameters.AddValue(
            "allocation_size",
            self.settings["search_parameters"]["max_number_results"])
        search_parameters.AddValue(
            "bucket_size", self.settings["search_parameters"]["bucket_size"])
        search_parameters.AddValue(
            "search_factor",
            self.settings["search_parameters"]["search_factor"])
        search_parameters.AddValue(
            "dynamic_search",
            self.settings["search_parameters"]["dynamic_search"])
        search_parameters["condition_name"].SetString(
            self._get_condition_name())
        search_parameters["final_string"].SetString(self._get_final_string())
        self.__assume_master_slave(key)
        search_parameters["predefined_master_slave"].SetBool(
            self.predefined_master_slave)
        search_parameters["id_name"].SetString(key)

        # We compute the number of nodes of the geometry
        number_nodes = len(self.computing_model_part.Conditions[1].GetNodes())

        # We create the search process
        if (self.dimension == 2):
            self.search_search[key] = CSMA.TreeContactSearch2D2N(
                self.computing_model_part, search_parameters)
        else:
            if (number_nodes == 3):
                self.search_search[key] = CSMA.TreeContactSearch3D3N(
                    self.computing_model_part, search_parameters)
            else:
                self.search_search[key] = CSMA.TreeContactSearch3D4N(
                    self.computing_model_part, search_parameters)
Example #8
0
    def _create_main_search(self, key = "0"):
        """ This method creates the search process that will be use during contact search

        Keyword arguments:
        self -- It signifies an instance of a class.
        key -- The key to identify the current pair
        """

        search_parameters = KM.Parameters("""{"condition_name": "", "final_string": "", "predefined_master_slave" : true, "id_name" : ""}""")
        search_parameters.AddValue("simple_search", self.settings["search_parameters"]["simple_search"])
        search_parameters.AddValue("type_search", self.settings["search_parameters"]["type_search"])
        search_parameters.AddValue("check_gap", self.settings["search_parameters"]["check_gap"])
        search_parameters.AddValue("allocation_size", self.settings["search_parameters"]["max_number_results"])
        search_parameters.AddValue("bucket_size", self.settings["search_parameters"]["bucket_size"])
        search_parameters.AddValue("search_factor", self.settings["search_parameters"]["search_factor"])
        search_parameters.AddValue("dynamic_search", self.settings["search_parameters"]["dynamic_search"])
        search_parameters.AddValue("static_check_movement", self.settings["search_parameters"]["static_check_movement"])
        search_parameters.AddValue("consider_gap_threshold", self.settings["search_parameters"]["consider_gap_threshold"])
        search_parameters.AddValue("debug_mode", self.settings["search_parameters"]["debug_mode"])
        search_parameters["condition_name"].SetString(self._get_condition_name())
        search_parameters["final_string"].SetString(self._get_final_string())
        self.__assume_master_slave(key)
        search_parameters["predefined_master_slave"].SetBool(self.predefined_master_slave)
        search_parameters["id_name"].SetString(key)

        # We create the search process
        self.search_utility_list[key] = CSMA.ContactSearchProcess(self.computing_model_part, search_parameters)
Example #9
0
    def _initialize_alm_parameters(self, computing_model_part):
        """ This method initializes the ALM parameters from the process info

        Keyword arguments:
        self -- It signifies an instance of a class.
        computing_model_part -- The model part that contains the structural problem to be solved
        """

        # We call the process info
        process_info = self.main_model_part.ProcessInfo

        if (self.settings["advance_ALM_parameters"]["manual_ALM"].GetBool() is False):
            # Computing the scale factors or the penalty parameters (StiffnessFactor * E_mean/h_mean)
            alm_var_parameters = KM.Parameters("""{}""")
            alm_var_parameters.AddValue("stiffness_factor", self.settings["advance_ALM_parameters"]["stiffness_factor"])
            alm_var_parameters.AddValue("penalty_scale_factor", self.settings["advance_ALM_parameters"]["penalty_scale_factor"])
            self.alm_var_process = CSMA.ALMVariablesCalculationProcess(self.contact_model_part, KM.NODAL_H, alm_var_parameters)
            self.alm_var_process.Execute()
            # We don't consider scale factor
            if (self.settings["advance_ALM_parameters"]["use_scale_factor"].GetBool() is False):
                process_info[KM.SCALE_FACTOR] = 1.0
        else:
            # We set the values in the process info
            process_info[KM.INITIAL_PENALTY] = self.settings["advance_ALM_parameters"]["penalty"].GetDouble()
            process_info[KM.SCALE_FACTOR] = self.settings["advance_ALM_parameters"]["scale_factor"].GetDouble()

        # We set a minimum value
        if (process_info[KM.INITIAL_PENALTY] < sys.float_info.epsilon):
            process_info[KM.INITIAL_PENALTY] = 1.0e0
        if (process_info[KM.SCALE_FACTOR] < sys.float_info.epsilon):
            process_info[KM.SCALE_FACTOR] = 1.0e0
            
        # We print the parameters considered
        KM.Logger.PrintInfo("SCALE_FACTOR: ", "{:.2e}".format(process_info[KM.SCALE_FACTOR]))
        KM.Logger.PrintInfo("INITIAL_PENALTY: ", "{:.2e}".format(process_info[KM.INITIAL_PENALTY]))
    def _initialize_search_conditions(self):
        """ This method initializes some conditions values

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

        # We call to the base process
        super(MPCContactProcess, self)._initialize_search_conditions()

        # Assign the friction friction_coefficients
        if self.is_frictional:
            for key in self.settings["search_model_part"].keys():
                if self.settings["search_model_part"][key].size() > 0:
                    sub_search_model_part_name = "ContactSub"+key
                    if self._get_process_model_part().HasSubModelPart(sub_search_model_part_name):
                        sub_search_model_part = self._get_process_model_part().GetSubModelPart(sub_search_model_part_name)
                    else:
                        sub_search_model_part = self._get_process_model_part().CreateSubModelPart(sub_search_model_part_name)
                    for prop in sub_search_model_part.GetProperties():
                        if not prop.Has(KM.FRICTION_COEFFICIENT):
                            prop[KM.FRICTION_COEFFICIENT] = self.contact_settings["friction_coefficients"][key].GetDouble()
                        else:
                            KM.Logger.PrintWarning("FRICTION_COEFFICIENT: ", "{:.2e}".format(prop[KM.FRICTION_COEFFICIENT]), " already defined in Properties, please define it as a condition pair property")

        alm_init_var = CSMA.ALMFastInit(self._get_process_model_part())
        alm_init_var.Execute()
Example #11
0
    def ExecuteInitialize(self):
        """ This method is executed at the begining to initialize the process

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

        # We call to the base process
        super(ExplicitPenaltyContactProcess, self).ExecuteInitialize()

        # Setting NL_ITERATION_NUMBER (used in some utilities)
        process_info = self.main_model_part.ProcessInfo
        process_info[KM.NL_ITERATION_NUMBER] = 1

        # Setting the impact time duration
        if self.contact_settings["advance_explicit_parameters"][
                "manual_max_gap_theshold"].GetBool():
            process_info[CSMA.MAX_GAP_THRESHOLD] = self.contact_settings[
                "advance_explicit_parameters"]["max_gap_threshold"].GetDouble(
                )
        else:
            empty_settings = KM.Parameters("""{}""")
            mean_nodal_h = CSMA.ContactUtilities.CalculateMeanNodalH(
                self.computing_model_part)
            process_info[CSMA.MAX_GAP_THRESHOLD] = mean_nodal_h

        # Create the dynamic factor process
        self.dynamic_factor_process = CSMA.ComputeDynamicFactorProcess(
            self.main_model_part)
        self.dynamic_factor_process.ExecuteInitialize()
Example #12
0
 def _create_convergence_criterion(self):
     convergence_criterion = convergence_criteria_factory.convergence_criterion(
         self._get_convergence_criterion_settings())
     conv_criteria = convergence_criterion.mechanical_convergence_criterion
     contact_criteria = ContactStructuralMechanicsApplication.MPCContactCriteria(
     )
     return KratosMultiphysics.AndCriteria(conv_criteria, contact_criteria)
Example #13
0
 def test_process_factory(self):
     dummy_class = DummyClass()
     process_factory = ContactStructuralMechanicsApplication.ProcessFactoryUtility(
         dummy_class)
     #dummy_class.DummyMethod()
     process_factory.ExecuteMethod("DummyMethod")
     self.assertTrue(dummy_class.this_assert)
Example #14
0
 def _create_contact_newton_raphson_strategy(self):
     computing_model_part = self.GetComputingModelPart()
     self.mechanical_scheme = self.get_solution_scheme()
     self.linear_solver = self.get_linear_solver()
     self.mechanical_convergence_criterion = self.get_convergence_criterion(
     )
     self.builder_and_solver = self.get_builder_and_solver()
     newton_parameters = KM.Parameters("""{}""")
     newton_parameters.AddValue(
         "adaptative_strategy",
         self.contact_settings["adaptative_strategy"])
     newton_parameters.AddValue("split_factor",
                                self.contact_settings["split_factor"])
     newton_parameters.AddValue("max_number_splits",
                                self.contact_settings["max_number_splits"])
     newton_parameters.AddValue(
         "inner_loop_iterations",
         self.contact_settings["inner_loop_iterations"])
     return CSMA.ResidualBasedNewtonRaphsonContactStrategy(
         computing_model_part, self.mechanical_scheme, self.linear_solver,
         self.mechanical_convergence_criterion, self.builder_and_solver,
         self.settings["max_iteration"].GetInt(),
         self.settings["compute_reactions"].GetBool(),
         self.settings["reform_dofs_at_each_step"].GetBool(),
         self.settings["move_mesh_flag"].GetBool(), newton_parameters,
         self.processes_list, self.post_process)
Example #15
0
 def _create_linear_solver(self):
     linear_solver = super(ContactImplicitMechanicalSolver,
                           self)._create_linear_solver()
     if (self.contact_settings["rescale_linear_solver"].GetBool() is True):
         linear_solver = KM.ScalingSolver(linear_solver, False)
     mortar_type = self.contact_settings["mortar_type"].GetString()
     if (mortar_type == "ALMContactFrictional"
             or mortar_type == "ALMContactFrictionlessComponents"):
         if (self.contact_settings["use_mixed_ulm_solver"].GetBool() == True
             ):
             self.print_on_rank_zero(
                 "::[Contact Mechanical Implicit Dynamic Solver]:: ",
                 "Using MixedULMLinearSolver, definition of ALM parameters recommended"
             )
             name_mixed_solver = self.contact_settings[
                 "mixed_ulm_solver_parameters"]["solver_type"].GetString()
             if (name_mixed_solver == "mixed_ulm_linear_solver"):
                 linear_solver_name = self.settings[
                     "linear_solver_settings"]["solver_type"].GetString()
                 if (linear_solver_name == "AMGCL"
                         or linear_solver_name == "AMGCLSolver"):
                     amgcl_param = KM.Parameters("""
                     {
                         "solver_type"                    : "AMGCL",
                         "smoother_type"                  : "ilu0",
                         "krylov_type"                    : "lgmres",
                         "coarsening_type"                : "aggregation",
                         "max_iteration"                  : 100,
                         "provide_coordinates"            : false,
                         "gmres_krylov_space_dimension"   : 100,
                         "verbosity"                      : 1,
                         "tolerance"                      : 1e-6,
                         "scaling"                        : false,
                         "block_size"                     : 3,
                         "use_block_matrices_if_possible" : true,
                         "coarse_enough"                  : 500
                     }
                     """)
                     amgcl_param["block_size"].SetInt(
                         self.main_model_part.ProcessInfo[KM.DOMAIN_SIZE])
                     self.linear_solver_settings.RecursivelyValidateAndAssignDefaults(
                         amgcl_param)
                     linear_solver = KM.AMGCLSolver(
                         self.linear_solver_settings)
                 mixed_ulm_solver = CSMA.MixedULMLinearSolver(
                     linear_solver,
                     self.contact_settings["mixed_ulm_solver_parameters"])
                 return mixed_ulm_solver
             else:
                 self.print_on_rank_zero(
                     "::[Contact Mechanical Implicit Dynamic Solver]:: ",
                     "Mixed solver not available: " + name_mixed_solver +
                     ". Using not mixed linear solver")
                 return linear_solver
         else:
             return linear_solver
     else:
         return linear_solver
    def _normal_check_process_tests(self,
                                    input_filename,
                                    custom_submodel_part=""):
        KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING)

        self.model = KM.Model()
        self.main_model_part = self.model.CreateModelPart("Main", 2)

        self.main_model_part.AddNodalSolutionStepVariable(KM.NORMAL)

        self.main_model_part.CloneTimeStep(1.01)

        KM.ModelPartIO(input_filename).ReadModelPart(self.main_model_part)

        if custom_submodel_part == "":
            KM.VariableUtils().SetFlag(
                KM.INTERFACE, True,
                self.main_model_part.GetSubModelPart(
                    "CONTACT_Contact_slave_Auto1").Nodes)
            KM.VariableUtils().SetFlag(
                KM.INTERFACE, True,
                self.main_model_part.GetSubModelPart(
                    "CONTACT_Contact_master_Auto1").Nodes)
        else:
            KM.VariableUtils().SetFlag(
                KM.INTERFACE, True,
                self.main_model_part.GetSubModelPart(
                    custom_submodel_part).Nodes)

        ## DEBUG
        #KM.ComputeNodesMeanNormalModelPart(self.main_model_part, True)

        # Check normals
        check_process = CSMA.NormalCheckProcess(self.main_model_part)
        check_process.Execute()

        ## DEBUG
        #self.__post_process()

        check_parameters = KM.Parameters("""
        {
            "check_variables"      : ["NORMAL"],
            "input_file_name"      : "",
            "model_part_name"      : "Main",
            "check_for_flag"       : "INTERFACE",
            "historical_value"     : true,
            "time_frequency"       : 0.0
        }
        """)

        check_parameters["input_file_name"].SetString(input_filename +
                                                      "_check_normal.json")

        check = from_json_check_result_process.FromJsonCheckResultProcess(
            self.model, check_parameters)
        check.ExecuteInitialize()
        check.ExecuteBeforeSolutionLoop()
        check.ExecuteFinalizeSolutionStep()
    def GetMortarCriteria(self, include_table=True):
        # Adding the mortar criteria
        if (self.mortar_type == "ALMContactFrictionless"):
            if (include_table is True):
                Mortar = CSMA.ALMFrictionlessMortarConvergenceCriteria(
                    self.print_convergence_criterion, self.gidio_debug)
            else:
                Mortar = CSMA.ALMFrictionlessMortarConvergenceCriteria()
        elif (self.mortar_type == "ALMContactFrictionlessComponents"):
            if (include_table is True):
                Mortar = CSMA.ALMFrictionlessComponentsMortarConvergenceCriteria(
                    self.print_convergence_criterion, self.gidio_debug)
            else:
                Mortar = CSMA.ALMFrictionlessComponentsMortarConvergenceCriteria(
                )
        elif (self.mortar_type == "ALMContactFrictional"):
            if (include_table is True):
                Mortar = CSMA.ALMFrictionalMortarConvergenceCriteria(
                    self.print_convergence_criterion, self.gidio_debug)
            else:
                Mortar = CSMA.ALMFrictionalMortarConvergenceCriteria()
        elif ("MeshTying" in self.mortar_type):
            Mortar = CSMA.MeshTyingMortarConvergenceCriteria()

        Mortar.SetEchoLevel(self.echo_level)

        return Mortar
Example #18
0
    def ExecuteInitializeSolutionStep(self):
        """ This method is executed in order to initialize the current step

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

        # We call to the base process
        super(ExplicitPenaltyContactProcess,
              self).ExecuteInitializeSolutionStep()

        # Check if the contact is active
        active_contact = CSMA.ContactUtilities.CheckActivity(
            self.computing_model_part, False)
        if active_contact:
            self.computing_model_part.Set(KM.CONTACT, True)
        else:
            self.computing_model_part.Set(KM.CONTACT, False)

        # Specific operations for explicit contact
        if self._get_if_is_interval() and active_contact:
            # Updating value of weighted gap
            KM.VariableUtils().SetNonHistoricalVariable(
                KM.NODAL_AREA, 0.0, self.computing_model_part.Nodes)
            KM.VariableUtils().SetVariable(CSMA.WEIGHTED_GAP, 0.0,
                                           self.computing_model_part.Nodes)
            CSMA.ContactUtilities.ComputeExplicitContributionConditions(
                self.computing_model_part)

            # Calling for the active set utilities (to activate deactivate nodes)
            if self.contact_settings["contact_type"].GetString(
            ) == "Frictionless":
                CSMA.ComputePenaltyFrictionlessActiveSet(
                    self.computing_model_part)
            else:
                CSMA.ComputePenaltyFrictionalActiveSet(
                    self.computing_model_part)

            # Activate/deactivate conditions
            CSMA.ContactUtilities.ActivateConditionWithActiveNodes(
                self.computing_model_part)

            # Update the dynamic factors
            self.dynamic_factor_process.Execute()
Example #19
0
 def test_processes_list_factory(self):
     dummy_class1 = DummyClass()
     dummy_class2 = DummyClass()
     dummy_list = [dummy_class1, dummy_class2]
     process_factory = ContactStructuralMechanicsApplication.ProcessFactoryUtility(
         dummy_list)
     #dummy_class.DummyMethod()
     process_factory.ExecuteMethod("DummyMethod")
     self.assertTrue(dummy_class1.this_assert)
     self.assertTrue(dummy_class2.this_assert)
Example #20
0
    def _initialize_problem_parameters(self):
        """ This method initializes the ALM parameters from the process info

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

        # We call to the base process (in fact not, to avoid writing twice the values)
        #super(PenaltyContactProcess, self)._initialize_problem_parameters()

        # We call the process info
        process_info = self.main_model_part.ProcessInfo

        if not self.contact_settings["advance_ALM_parameters"][
                "manual_ALM"].GetBool():
            # We compute NODAL_H that can be used in the search and some values computation
            self.find_nodal_h = KM.FindNodalHProcess(self.computing_model_part)
            self.find_nodal_h.Execute()

            # Computing the scale factors or the penalty parameters (StiffnessFactor * E_mean/h_mean)
            alm_var_parameters = KM.Parameters("""{}""")
            alm_var_parameters.AddValue(
                "stiffness_factor",
                self.contact_settings["advance_ALM_parameters"]
                ["stiffness_factor"])
            alm_var_parameters.AddValue(
                "penalty_scale_factor",
                self.contact_settings["advance_ALM_parameters"]
                ["penalty_scale_factor"])
            self.alm_var_process = CSMA.ALMVariablesCalculationProcess(
                self._get_process_model_part(), KM.NODAL_H, alm_var_parameters)
            self.alm_var_process.Execute()
            # We rescale, the process is designed for ALM formulation
            process_info[
                KM.INITIAL_PENALTY] = 1.0e0 * process_info[KM.INITIAL_PENALTY]
        else:
            # We set the values in the process info
            process_info[KM.INITIAL_PENALTY] = self.contact_settings[
                "advance_ALM_parameters"]["penalty"].GetDouble()

        # We set a minimum value
        if process_info[KM.INITIAL_PENALTY] < sys.float_info.epsilon:
            process_info[KM.INITIAL_PENALTY] = 1.0e13

        # Setting on nodes
        initial_penalty = process_info[KM.INITIAL_PENALTY]
        KM.VariableUtils().SetNonHistoricalVariable(
            KM.INITIAL_PENALTY, initial_penalty,
            self.computing_model_part.Nodes)

        # We print the parameters considered
        KM.Logger.PrintInfo("INITIAL_PENALTY: ",
                            "{:.2e}".format(process_info[KM.INITIAL_PENALTY]))
    def _create_main_search(self, key = "0"):
        """ This method creates the search process that will be use during contact search

        Keyword arguments:
        self -- It signifies an instance of a class.
        key -- The key to identify the current pair
        """
        # Create main parameters
        search_parameters = self._create_search_parameters(key)

        # We create the search process
        self.search_utility_list[key] = CSMA.MPCContactSearchProcess(self.main_model_part, search_parameters)
Example #22
0
def AuxiliarLineSearch(computing_model_part, mechanical_scheme, linear_solver,
                       mechanical_convergence_criterion, builder_and_solver,
                       settings, contact_settings, processes_list,
                       post_process):
    newton_parameters = KM.Parameters("""{}""")
    return CSMA.LineSearchContactStrategy(
        computing_model_part, mechanical_scheme, linear_solver,
        mechanical_convergence_criterion, builder_and_solver,
        settings["max_iteration"].GetInt(),
        settings["compute_reactions"].GetBool(),
        settings["reform_dofs_at_each_step"].GetBool(),
        settings["move_mesh_flag"].GetBool(), newton_parameters)
Example #23
0
    def _initialize_search_conditions(self):
        """ This method initializes some conditions values

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

        # We call to the base process
        super(ALMContactProcess, self)._initialize_search_conditions()

        alm_init_var = CSMA.ALMFastInit(self._get_process_model_part())
        alm_init_var.Execute()
Example #24
0
 def _create_contact_line_search_strategy(self):
     computing_model_part = self.GetComputingModelPart()
     mechanical_scheme = self.get_solution_scheme()
     linear_solver = self.get_linear_solver()
     mechanical_convergence_criterion = self.get_convergence_criterion()
     builder_and_solver = self.get_builder_and_solver()
     newton_parameters = KratosMultiphysics.Parameters("""{}""")
     return ContactStructuralMechanicsApplication.LineSearchContactStrategy(
         computing_model_part, mechanical_scheme, linear_solver,
         mechanical_convergence_criterion, builder_and_solver,
         self.settings["max_iteration"].GetInt(),
         self.settings["compute_reactions"].GetBool(),
         self.settings["reform_dofs_at_each_step"].GetBool(),
         self.settings["move_mesh_flag"].GetBool(), newton_parameters)
Example #25
0
    def _interface_preprocess(self, partial_model_part, key = "0"):
        """ This method creates the process used to compute the contact interface

        Keyword arguments:
        self -- It signifies an instance of a class.
        partial_model_part -- The partial model part that contains the structural problem to be solved
        """

        # We create the process for creating the interface
        self.interface_preprocess = CSMA.InterfacePreprocessCondition(self.computing_model_part)

        # It should create the conditions automatically
        interface_parameters = KM.Parameters("""{"simplify_geometry": false, "contact_property_id": 0}""")
        interface_parameters["contact_property_id"].SetInt(self.settings["search_property_ids"][key].GetInt())
        self.interface_preprocess.GenerateInterfacePart(partial_model_part, interface_parameters)
Example #26
0
def  AuxiliarMPCNewton(computing_model_part, mechanical_scheme, linear_solver, mechanical_convergence_criterion, builder_and_solver, settings, contact_settings):
    newton_parameters = KM.Parameters("""{}""")
    newton_parameters.AddValue("inner_loop_iterations", contact_settings["inner_loop_iterations"])
    newton_parameters.AddValue("update_each_nl_iteration", contact_settings["update_each_nl_iteration"])
    newton_parameters.AddValue("enforce_ntn", contact_settings["enforce_ntn"])
    return CSMA.ResidualBasedNewtonRaphsonMPCContactStrategy(computing_model_part,
                                                                mechanical_scheme,
                                                                linear_solver,
                                                                mechanical_convergence_criterion,
                                                                builder_and_solver,
                                                                settings["max_iteration"].GetInt(),
                                                                settings["compute_reactions"].GetBool(),
                                                                settings["reform_dofs_at_each_step"].GetBool(),
                                                                settings["move_mesh_flag"].GetBool(),
                                                                newton_parameters
                                                                )
Example #27
0
 def _create_main_search(self, computing_model_part):
     search_parameters = KratosMultiphysics.Parameters("""{}""")
     search_parameters.AddValue("type_search", self.params["type_search"])
     search_parameters.AddValue("allocation_size",
                                self.params["max_number_results"])
     search_parameters.AddValue("bucket_size", self.params["bucket_size"])
     search_parameters.AddValue("search_factor",
                                self.params["search_factor"])
     search_parameters.AddValue("dual_search_check",
                                self.params["dual_search_check"])
     search_parameters.AddValue("strict_search_check",
                                self.params["strict_search_check"])
     search_parameters.AddValue("use_exact_integration",
                                self.params["use_exact_integration"])
     self.contact_search = ContactStructuralMechanicsApplication.TreeContactSearch(
         computing_model_part, search_parameters)
def  AuxiliarCreateLinearSolver(main_model_part, settings, contact_settings, linear_solver_settings, linear_solver):
    if contact_settings["rescale_linear_solver"].GetBool():
        linear_solver = KM.ScalingSolver(linear_solver, False)
    mortar_type = contact_settings["mortar_type"].GetString()
    if "ALMContactFrictional" in mortar_type or mortar_type == "ALMContactFrictionlessComponents":
        if contact_settings["use_mixed_ulm_solver"].GetBool():
            KM.Logger.PrintInfo("::[Contact Mechanical Solver]:: ", "Using MixedULMLinearSolver, definition of ALM parameters recommended")
            name_mixed_solver = contact_settings["mixed_ulm_solver_parameters"]["solver_type"].GetString()
            if name_mixed_solver == "mixed_ulm_linear_solver":
                if settings.Has("linear_solver_settings"):
                    if settings["linear_solver_settings"].Has("solver_type"):
                        linear_solver_name = settings["linear_solver_settings"]["solver_type"].GetString()
                        if linear_solver_name == "amgcl" or linear_solver_name == "AMGCL" or linear_solver_name == "AMGCLSolver":
                            amgcl_param = KM.Parameters("""
                            {
                                "solver_type"                    : "amgcl",
                                "smoother_type"                  : "ilu0",
                                "krylov_type"                    : "lgmres",
                                "coarsening_type"                : "aggregation",
                                "max_iteration"                  : 100,
                                "provide_coordinates"            : false,
                                "gmres_krylov_space_dimension"   : 100,
                                "verbosity"                      : 1,
                                "tolerance"                      : 1e-6,
                                "scaling"                        : false,
                                "block_size"                     : 3,
                                "use_block_matrices_if_possible" : true,
                                "coarse_enough"                  : 500
                            }
                            """)
                            amgcl_param["block_size"].SetInt(main_model_part.ProcessInfo[KM.DOMAIN_SIZE])
                            linear_solver_settings.RecursivelyValidateAndAssignDefaults(amgcl_param)
                            linear_solver = KM.AMGCLSolver(linear_solver_settings)
                        mixed_ulm_solver = CSMA.MixedULMLinearSolver(linear_solver, contact_settings["mixed_ulm_solver_parameters"])
                        return mixed_ulm_solver
                    else:
                        return linear_solver
                else:
                    return linear_solver
            else:
                KM.Logger.PrintInfo("::[Contact Mechanical Solver]:: ", "Mixed solver not available: " + name_mixed_solver + ". Using not mixed linear solver")
                return linear_solver
        else:
            return linear_solver
    else:
        return linear_solver
Example #29
0
    def _interface_preprocess(self, computing_model_part):
        """ This method creates the process used to compute the contact interface

        Keyword arguments:
        self -- It signifies an instance of a class.
        computing_model_part -- The model part that contains the structural problem to be solved
        """

        # We create the process for creating the interface
        self.interface_preprocess = CSMA.InterfacePreprocessCondition(computing_model_part)

        # It should create the conditions automatically
        interface_parameters = KM.Parameters("""{"simplify_geometry": false}""")
        if (self.dimension == 2):
            self.interface_preprocess.GenerateInterfacePart2D(self.contact_model_part, interface_parameters)
        else:
            self.interface_preprocess.GenerateInterfacePart3D(self.contact_model_part, interface_parameters)
Example #30
0
    def _interface_preprocess(self, computing_model_part):
        self.interface_preprocess = ContactStructuralMechanicsApplication.InterfacePreprocessCondition(
            computing_model_part)

        if self.params["contact_type"].GetString() == "Frictionless":
            if self.normal_variation == True:
                if self.axisymmetric == True:
                    condition_name = "ALMNVFrictionlessAxisymMortarContact"
                else:
                    condition_name = "ALMNVFrictionlessMortarContact"
            else:
                if self.axisymmetric == True:
                    condition_name = "ALMFrictionlessAxisymMortarContact"
                else:
                    condition_name = "ALMFrictionlessMortarContact"
        elif self.params["contact_type"].GetString() == "Frictional":
            if self.normal_variation == True:
                if self.axisymmetric == True:
                    condition_name = "ALMNVFrictionalAxisymMortarContact"
                else:
                    condition_name = "ALMNVFrictionalMortarContact"
            else:
                if self.axisymmetric == True:
                    condition_name = "ALMFrictionalAxisymMortarContact"
                else:
                    condition_name = "ALMFrictionalMortarContact"

        #print("MODEL PART BEFORE CREATING INTERFACE")
        #print(computing_model_part)

        # It should create the conditions automatically
        interface_parameters = KratosMultiphysics.Parameters(
            """{"condition_name": "", "final_string": "", "simplify_geometry": false}"""
        )
        interface_parameters["condition_name"].SetString(condition_name)
        if (self.dimension == 2):
            self.interface_preprocess.GenerateInterfacePart2D(
                computing_model_part, self.contact_model_part,
                interface_parameters)
        else:
            self.interface_preprocess.GenerateInterfacePart3D(
                computing_model_part, self.contact_model_part,
                interface_parameters)