Example #1
0
    def ExecuteInitialize(self):
        if self.output_control == "time":
            self.next_output = self.model_part.ProcessInfo[KratosMultiphysics.TIME]
        else:
            self.next_output = self.model_part.ProcessInfo[KratosMultiphysics.STEP]

        self.nodal_variables = kratos_utilities.GenerateVariableListFromInput(self.settings["nodal_results"])
Example #2
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.
        """

        # Calculate NODAL_H
        KratosMultiphysics.VariableUtils().SetNonHistoricalVariable(KratosMultiphysics.NODAL_H, 0.0, self.main_model_part.Nodes)
        KratosMultiphysics.VariableUtils().SetNonHistoricalVariable(KratosMultiphysics.NODAL_AREA, 0.0, self.main_model_part.Nodes)
        self.find_nodal_h = KratosMultiphysics.FindNodalHNonHistoricalProcess(self.main_model_part)
        self.find_nodal_h.Execute()

        # Calculate the parameters of automatic remeshing
        if self.settings["automatic_remesh"].GetBool():
            nodal_h_values = []
            for node in self.main_model_part.Nodes:
                nodal_h_values.append(node.GetValue(KratosMultiphysics.NODAL_H))

            # Calculate the minimum size
            if self.settings["automatic_remesh_parameters"]["automatic_remesh_type"].GetString() == "Ratio":
                # NOTE: For mode: https://docs.python.org/3/library/statistics.html
                if self.settings["automatic_remesh_parameters"]["refer_type"].GetString() == "Mean":
                    ref = stat.mean(nodal_h_values)
                elif self.settings["automatic_remesh_parameters"]["refer_type"].GetString() == "Median":
                    ref = stat.median(nodal_h_values)

                self.settings["minimal_size"].SetDouble(ref * (self.settings["automatic_remesh_parameters"]["min_size_ratio"].GetDouble()))
                self.settings["maximal_size"].SetDouble(ref * (self.settings["automatic_remesh_parameters"]["max_size_ratio"].GetDouble()))
            elif self.settings["automatic_remesh_parameters"]["automatic_remesh_type"].GetString() == "Percentage":
                mean = stat.mean(nodal_h_values)
                stdev = stat.stdev(nodal_h_values)
                prob = (self.settings["automatic_remesh_parameters"]["min_size_current_percentage"].GetDouble())/100
                self.settings["minimal_size"].SetDouble(_normvalf(prob, mean, stdev)) # Using normal normal distribution to get the minimal size as a stadistical meaninful value

                prob = (self.settings["automatic_remesh_parameters"]["max_size_current_percentage"].GetDouble())/100
                self.settings["maximal_size"].SetDouble(_normvalf(prob, mean, stdev)) # Using normal normal distribution to get the maximal size as a stadistical meaninful value

            # We deactivate, so it doesn't recalculate each initialization
            self.settings["automatic_remesh"].SetBool(False)

        ## We print the parameters considered
        KratosMultiphysics.Logger.PrintInfo("MINIMAL SIZE: ", "{:.2e}".format(self.settings["minimal_size"].GetDouble()))
        KratosMultiphysics.Logger.PrintInfo("MAXIMAL SIZE: ", "{:.2e}".format(self.settings["maximal_size"].GetDouble()))

        # Anisotropic remeshing parameters
        self.anisotropy_remeshing = self.settings["anisotropy_remeshing"].GetBool()
        if self.anisotropy_remeshing:
            if self.settings["automatic_remesh"].GetBool():
                self.settings["anisotropy_parameters"]["boundary_layer_max_distance"].SetDouble(self.settings["minimal_size"].GetDouble() * self.settings["anisotropy_parameters"]["boundary_layer_min_size_ratio"].GetDouble())

        # Select the remeshing strategy
        self.strategy = self.settings["strategy"].GetString()
        if self.strategy == "LevelSet":
            self.scalar_variable = KratosMultiphysics.KratosGlobals.GetVariable( self.settings["level_set_strategy_parameters"]["scalar_variable"].GetString() )
            self.gradient_variable = KratosMultiphysics.KratosGlobals.GetVariable( self.settings["level_set_strategy_parameters"]["gradient_variable"].GetString() )
        elif self.strategy == "Hessian":
            self.metric_variables, variable_types = self.__generate_variable_list_from_input(self.settings["hessian_strategy_parameters"]["metric_variable"])
            self.non_historical_metric_variable = self.__generate_boolean_list_from_input(self.settings["hessian_strategy_parameters"]["non_historical_metric_variable"])
            self.non_historical_metric_variable = self.__list_extender(self.non_historical_metric_variable, variable_types)
            self.normalization_factor = self.__generate_double_list_from_input(self.settings["hessian_strategy_parameters"]["normalization_factor"])
            self.normalization_factor = self.__list_extender(self.normalization_factor, variable_types)
            self.normalization_alpha = self.__generate_double_list_from_input(self.settings["hessian_strategy_parameters"]["normalization_alpha"])
            self.normalization_alpha = self.__list_extender(self.normalization_alpha, variable_types)
            self.normalization_method = self.__generate_string_list_from_input(self.settings["hessian_strategy_parameters"]["normalization_method"])
            self.normalization_method = self.__list_extender(self.normalization_method, variable_types)
            len_metric_variables = len(self.metric_variables)
            len_non_historical_metric_variable = len(self.non_historical_metric_variable)
            if len_metric_variables > len_non_historical_metric_variable:
                for i in range(len_non_historical_metric_variable, len_metric_variables):
                    self.non_historical_metric_variable.append(False)
            len_normalization_factor = len(self.normalization_factor)
            if len_metric_variables > len_normalization_factor:
                for i in range(len_normalization_factor, len_metric_variables):
                    self.normalization_factor.append(1.0)
            len_normalization_alpha = len(self.normalization_alpha)
            if len_metric_variables > len_normalization_alpha:
                for i in range(len_normalization_alpha, len_metric_variables):
                    self.normalization_alpha.append(0.0)
            len_normalization_method = len(self.normalization_method)
            if len_metric_variables > len_normalization_method:
                for i in range(len_normalization_method, len_metric_variables):
                    self.normalization_method.append("constant")
            mesh_dependent_constant = self.settings["hessian_strategy_parameters"]["mesh_dependent_constant"].GetDouble()
            if mesh_dependent_constant == 0.0:
                self.settings["hessian_strategy_parameters"]["mesh_dependent_constant"].SetDouble(0.5 * (self.domain_size/(self.domain_size + 1))**2.0)
        elif self.strategy == "superconvergent_patch_recovery" or self.strategy == "SPR":
            self.error_threshold = self.settings["error_strategy_parameters"]["error_metric_parameters"]["error_threshold"].GetDouble()
            self.error_ratio = 0

        self.internal_variable_interpolation_list = kratos_utilities.GenerateVariableListFromInput(self.settings["internal_variables_parameters"]["internal_variable_interpolation_list"])

        # Model parts to fix the nodes
        fix_contour_model_parts = self.__generate_submodelparts_list_from_input(self.settings["fix_contour_model_parts"])

        # Setting flag BLOCKED to the non nodes
        for submodelpart in fix_contour_model_parts:
            KratosMultiphysics.VariableUtils().SetFlag(KratosMultiphysics.BLOCKED, True, submodelpart.Nodes)

        # Model parts to fix the conditions
        fix_conditions_model_parts = self.__generate_submodelparts_list_from_input(self.settings["fix_conditions_model_parts"])

        # Setting flag BLOCKED to the non conditions
        for submodelpart in fix_conditions_model_parts:
            KratosMultiphysics.VariableUtils().SetFlag(KratosMultiphysics.BLOCKED, True, submodelpart.Conditions)

        # Model parts to fix the nodes
        fix_elements_model_parts = self.__generate_submodelparts_list_from_input(self.settings["fix_elements_model_parts"])

        # Setting flag BLOCKED to the non elements
        for submodelpart in fix_elements_model_parts:
            KratosMultiphysics.VariableUtils().SetFlag(KratosMultiphysics.BLOCKED, True, submodelpart.Elements)

        if self.strategy == "LevelSet":
            self._CreateGradientProcess()

        if self.domain_size == 2:
            self.initialize_metric = MeshingApplication.MetricFastInit2D(self.main_model_part)
        else:
            self.initialize_metric = MeshingApplication.MetricFastInit3D(self.main_model_part)

        self.initialize_metric.Execute()

        self._CreateMetricsProcess()

        mmg_parameters = KratosMultiphysics.Parameters("""{"force_sizes":{}}""")
        mmg_parameters.AddValue("filename",self.settings["filename"])
        mmg_parameters.AddValue("framework",self.settings["framework"])
        mmg_parameters.AddValue("discretization_type",self.settings["discretization_type"])
        mmg_parameters.AddValue("isosurface_parameters",self.settings["isosurface_parameters"])
        mmg_parameters.AddValue("internal_variables_parameters",self.settings["internal_variables_parameters"])
        mmg_parameters.AddValue("collapse_prisms_elements",self.settings["collapse_prisms_elements"])
        mmg_parameters.AddValue("save_external_files",self.settings["save_external_files"])
        mmg_parameters.AddValue("save_colors_files",self.settings["save_colors_files"])
        mmg_parameters.AddValue("save_mdpa_file",self.settings["save_mdpa_file"])
        mmg_parameters.AddValue("max_number_of_searchs",self.settings["max_number_of_searchs"])
        mmg_parameters.AddValue("preserve_flags",self.settings["preserve_flags"])
        mmg_parameters.AddValue("interpolate_non_historical",self.settings["interpolate_non_historical"])
        mmg_parameters.AddValue("extrapolate_contour_values",self.settings["extrapolate_contour_values"])
        mmg_parameters.AddValue("search_parameters",self.settings["search_parameters"])
        mmg_parameters["force_sizes"].AddValue("force_min",self.settings["force_min"])
        mmg_parameters["force_sizes"].AddValue("minimal_size",self.settings["minimal_size"])
        mmg_parameters["force_sizes"].AddValue("force_max",self.settings["force_max"])
        mmg_parameters["force_sizes"].AddValue("maximal_size",self.settings["maximal_size"])
        mmg_parameters.AddValue("advanced_parameters",self.settings["advanced_parameters"])
        mmg_parameters.AddValue("debug_result_mesh",self.settings["debug_result_mesh"])
        mmg_parameters.AddValue("initialize_entities",self.settings["initialize_entities"])
        mmg_parameters.AddValue("echo_level",self.settings["echo_level"])
        if self.domain_size == 2:
            self.mmg_process = MeshingApplication.MmgProcess2D(self.main_model_part, mmg_parameters)
        else:
            # Differentiate between 3D volumes and 3D surfaces
            if self.is_surface:
                self.mmg_process = MeshingApplication.MmgProcess3DSurfaces(self.main_model_part, mmg_parameters)
            else:
                self.mmg_process = MeshingApplication.MmgProcess3D(self.main_model_part, mmg_parameters)

        # We reset the step and time
        self.step = 0
        self.time = 0.0

        # We compute initial remeshing is desired
        if self.initial_remeshing:
            if not self.main_model_part.Is(KratosMultiphysics.MODIFIED):
                self._ExecuteRefinement()
            else:
                self.main_model_part.Set(KratosMultiphysics.MODIFIED, False)
Example #3
0
    def ExecuteInitialize(self):
        result_file_configuration = self.param["result_file_configuration"]
        result_file_configuration.ValidateAndAssignDefaults(
            self.defaults["result_file_configuration"])

        # If either of these is True, we will have a volume output file
        self.body_output = result_file_configuration["body_output"].GetBool()
        self.node_output = result_file_configuration["node_output"].GetBool()

        # If skin_output is True or we have output planes, we will have a cut output file
        self.skin_output = result_file_configuration["skin_output"].GetBool()
        plane_output_configuration = result_file_configuration[
            "plane_output"]  # should be of array type
        self.num_planes = plane_output_configuration.size()

        # Generate the cuts and store them in self.cut_model_part
        if self.skin_output or self.num_planes > 0:
            model = self.model_part.GetModel()
            self.cut_model_part = model.CreateModelPart("CutPart")
            self.cut_manager = self._CreateCuttingUtility()
            self._initialize_cut_output(plane_output_configuration)

        # Retrieve gidpost flags and setup GiD output tool
        gidpost_flags = result_file_configuration["gidpost_flags"]
        gidpost_flags.ValidateAndAssignDefaults(
            self.defaults["result_file_configuration"]["gidpost_flags"])

        self._InitializeGiDIO(gidpost_flags, gidpost_flags)

        # Process nodal and gauss point output
        self.nodal_variables = kratos_utilities.GenerateVariableListFromInput(
            result_file_configuration["nodal_results"])
        self.gauss_point_variables = kratos_utilities.GenerateVariableListFromInput(
            result_file_configuration["gauss_point_results"])
        self.nodal_nonhistorical_variables = kratos_utilities.GenerateVariableListFromInput(
            result_file_configuration["nodal_nonhistorical_results"])
        self.nodal_flags = kratos_utilities.GenerateFlagsListFromInput(
            result_file_configuration["nodal_flags_results"])
        self.nodal_flags_names = []
        for i in range(
                result_file_configuration["nodal_flags_results"].size()):
            self.nodal_flags_names.append(
                result_file_configuration["nodal_flags_results"]
                [i].GetString())
        self.elemental_conditional_flags = kratos_utilities.GenerateFlagsListFromInput(
            result_file_configuration["elemental_conditional_flags_results"])
        self.elemental_conditional_flags_names = []
        for i in range(result_file_configuration[
                "elemental_conditional_flags_results"].size()):
            self.elemental_conditional_flags_names.append(
                result_file_configuration[
                    "elemental_conditional_flags_results"][i].GetString())

        # Set up output frequency and format
        output_file_label = result_file_configuration["file_label"].GetString()
        if output_file_label == "time":
            self.output_label_is_time = True
        elif output_file_label == "step":
            self.output_label_is_time = False
        else:
            msg = "{0} Error: Unknown value \"{1}\" read for parameter \"{2}\"".format(
                self.__class__.__name__, output_file_label, "file_label")
            raise Exception(msg)

        output_control_type = result_file_configuration[
            "output_control_type"].GetString()
        if output_control_type == "time":
            self.output_control_is_time = True
        elif output_control_type == "step":
            self.output_control_is_time = False
        else:
            msg = "{0} Error: Unknown value \"{1}\" read for parameter \"{2}\"".format(
                self.__class__.__name__, output_file_label, "file_label")
            raise Exception(msg)

        self.output_interval = result_file_configuration[
            "output_interval"].GetDouble()

        self.flush_after_output = result_file_configuration[
            "flush_after_output"].GetBool()

        # get .post.lst files
        additional_list_file_data = result_file_configuration[
            "additional_list_files"]
        additional_list_files = [
            additional_list_file_data[i].GetInt()
            for i in range(0, additional_list_file_data.size())
        ]

        # Set current time parameters
        if self.model_part.ProcessInfo[KM.IS_RESTARTED]:
            self._SetCurrentTimeParameters(additional_list_files)
        else:
            # Create .post.lst files
            self._InitializeListFiles(additional_list_files)

        # Process point recording data
        if self.point_output_process is not None:
            self.point_output_process.ExecuteInitialize()