Exemplo n.º 1
0
    def _create_remeshing_process(self):
        if (self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] == 2):
            remeshing_process = MeshingApplication.MmgProcess2D(self.main_model_part, self.adaptative_remesh_parameters["remeshing_parameters"])
        else:
            remeshing_process = MeshingApplication.MmgProcess3D(self.main_model_part, self.adaptative_remesh_parameters["remeshing_parameters"])

        return remeshing_process
Exemplo n.º 2
0
    def ExecuteInitialize(self):

        # NOTE: Add more model part if interested
        submodelpartslist = self.__generate_submodelparts_list_from_input(self.params["fix_contour_model_parts"])

        for submodelpart in submodelpartslist:
            for node in submodelpart.Nodes:
                node.Set(KratosMultiphysics.BLOCKED, True)

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

        if (self.dim == 2):
            self.initialize_metric = MeshingApplication.MetricFastInit2D(self.Model[self.model_part_name])
        else:
            self.initialize_metric = MeshingApplication.MetricFastInit3D(self.Model[self.model_part_name])
            
        self.initialize_metric.Execute()

        self._CreateMetricsProcess()

        mmg_parameters = KratosMultiphysics.Parameters("""{}""")
        mmg_parameters.AddValue("filename",self.params["filename"])
        mmg_parameters.AddValue("framework",self.params["framework"])
        mmg_parameters.AddValue("internal_variables_parameters",self.params["internal_variables_parameters"])
        mmg_parameters.AddValue("save_external_files",self.params["save_external_files"])
        mmg_parameters.AddValue("max_number_of_searchs",self.params["max_number_of_searchs"])
        mmg_parameters.AddValue("echo_level",self.params["echo_level"])
        if (self.dim == 2):
            self.MmgProcess = MeshingApplication.MmgProcess2D(self.Model[self.model_part_name], mmg_parameters)
        else:
            self.MmgProcess = MeshingApplication.MmgProcess3D(self.Model[self.model_part_name], mmg_parameters)

        if (self.initial_remeshing == True):
            self._ExecuteRefinement()
    def __ExecuteRefinement(self):

        if (self.domain_size == 2):
            MmgProcess = KratosMeshing.MmgProcess2D(self.main_model_part,
                                                    self.mmg_parameters)
            MmgProcess.Execute()
        elif (self.domain_size == 3):
            MmgProcess = KratosMeshing.MmgProcess3D(self.main_model_part,
                                                    self.mmg_parameters)
            MmgProcess.Execute()
Exemplo n.º 4
0
    def _create_remeshing_process(self):
        if (self.main_model_part.ProcessInfo[KM.DOMAIN_SIZE] == 2):
            remeshing_process = MA.MmgProcess2D(
                self.main_model_part,
                self.adaptative_remesh_parameters["remeshing_parameters"])
        else:
            remeshing_process = MA.MmgProcess3D(
                self.main_model_part,
                self.adaptative_remesh_parameters["remeshing_parameters"])

        return remeshing_process
def CreateRemeshingProcess(main_model_part, adaptative_remesh_parameters):
    if main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] == 2:
        remeshing_process = MeshingApplication.MmgProcess2D(main_model_part, adaptative_remesh_parameters["remeshing_parameters"])
    else:
        is_surface = False
        for elem in main_model_part.Elements:
            geom = elem.GetGeometry()
            if geom.WorkingSpaceDimension() != geom.LocalSpaceDimension():
                is_surface = True
            break
        if is_surface:
            remeshing_process = MeshingApplication.MmgProcess3DSurfaces(main_model_part, adaptative_remesh_parameters["remeshing_parameters"])
        else:
            remeshing_process = MeshingApplication.MmgProcess3D(main_model_part, adaptative_remesh_parameters["remeshing_parameters"])

    return remeshing_process
Exemplo n.º 6
0
                            "anisotropy_remeshing"                 : true, 
                            "anisotropy_parameters": 
                            {
                                "hmin_over_hmax_anisotropic_ratio"      : 0.01, 
                                "boundary_layer_max_distance"           : 0.5, 
                                "interpolation"                         : "Linear"
                            }
                        }
                        """)
metric_process = MeshingApplication.ComputeLevelSetSolMetricProcess3D(
    main_model_part, KratosMultiphysics.DISTANCE_GRADIENT, level_set_param)
metric_process.Execute()

# We create the remeshing process
remesh_param = KratosMultiphysics.Parameters("""{ }""")
MmgProcess = MeshingApplication.MmgProcess3D(main_model_part, remesh_param)
MmgProcess.Execute()

# Finally we export to GiD
from gid_output_process import GiDOutputProcess
gid_output = GiDOutputProcess(
    main_model_part, "gid_output",
    KratosMultiphysics.Parameters("""
                                {
                                    "result_file_configuration" : {
                                        "gidpost_flags": {
                                            "GiDPostMode": "GiD_PostBinary",
                                            "WriteDeformedMeshFlag": "WriteUndeformed",
                                            "WriteConditionsFlag": "WriteConditions",
                                            "MultiFileFlag": "SingleFile"
                                        },        
Exemplo n.º 7
0
    def ExecuteInitialize(self):
        # Calculate NODAL_H
        self.find_nodal_h = KratosMultiphysics.FindNodalHProcess(
            self.model_part)
        self.find_nodal_h.Execute()

        # Calculate the parameters of automatic remeshing
        if (self.settings["automatic_remesh"].GetBool() == True):
            import statistics as stat
            nodal_h_values = []
            for node in self.model_part.Nodes:
                nodal_h_values.append(
                    node.GetSolutionStepValue(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

        # Anisotropic remeshing parameters
        self.anisotropy_remeshing = self.settings[
            "anisotropy_remeshing"].GetBool()
        if (self.anisotropy_remeshing == True):
            if (self.settings["automatic_remesh"].GetBool() == True):
                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_variable = self.__generate_variable_list_from_input(
                self.settings["hessian_strategy_parameters"]
                ["metric_variable"])
            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.dim / (self.dim + 1))**2.0)

        self.internal_variable_interpolation_list = self.__generate_internal_variable_list_from_input(
            self.settings["internal_variables_parameters"]
            ["internal_variable_interpolation_list"])

        # NOTE: Add more model part if interested
        submodelpartslist = self.__generate_submodelparts_list_from_input(
            self.settings["fix_contour_model_parts"])

        for submodelpart in submodelpartslist:
            for node in submodelpart.Nodes:
                node.Set(KratosMultiphysics.BLOCKED, True)

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

        if (self.dim == 2):
            self.initialize_metric = MeshingApplication.MetricFastInit2D(
                self.model_part)
        else:
            self.initialize_metric = MeshingApplication.MetricFastInit3D(
                self.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("internal_variables_parameters",
                                self.settings["internal_variables_parameters"])
        mmg_parameters.AddValue("save_external_files",
                                self.settings["save_external_files"])
        mmg_parameters.AddValue("max_number_of_searchs",
                                self.settings["max_number_of_searchs"])
        mmg_parameters["force_sizes"].AddValue("force_min",
                                               self.settings["force_min"])
        mmg_parameters["force_sizes"].AddValue("minimal_size",
                                               self.settings["maximal_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("echo_level", self.settings["echo_level"])
        if (self.dim == 2):
            self.mmg_process = MeshingApplication.MmgProcess2D(
                self.model_part, mmg_parameters)
        else:
            self.mmg_process = MeshingApplication.MmgProcess3D(
                self.model_part, mmg_parameters)

        # We reset the step
        self.step = 0

        # We compute initial remeshing is desired
        if (self.initial_remeshing == True):
            if (self.model_part.Is(KratosMultiphysics.MODIFIED) == False):
                self._ExecuteRefinement()
            else:
                self.model_part.Set(KratosMultiphysics.MODIFIED, False)
Exemplo n.º 8
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():
            import statistics as stat
            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

        # 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_variable = self.__generate_variable_list_from_input(self.settings["hessian_strategy_parameters"]["metric_variable"])
            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":
            self.error_threshold = self.settings["error_strategy_parameters"]["error_metric_parameters"]["error_threshold"].GetDouble()
            self.estimated_error = 0
            self.remeshing_cycle = 0
            self.main_model_part.ProcessInfo[MeshingApplication.EXECUTE_REMESHING] = True

        self.internal_variable_interpolation_list = self.__generate_internal_variable_list_from_input(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("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
        self.step = 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)
Exemplo n.º 9
0
    def test_isosurface_remesh_sphere(self):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(
            KratosMultiphysics.Logger.Severity.WARNING)

        # We create the model part
        current_model = KratosMultiphysics.Model()
        main_model_part = current_model.CreateModelPart("MainModelPart")
        main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, 3)
        main_model_part.ProcessInfo.SetValue(KratosMultiphysics.TIME, 0.0)
        main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DELTA_TIME,
                                             1.0)
        #main_model_part.ProcessInfo.SetValue(KratosMultiphysics.STEP, 1)

        # We add the variables needed
        main_model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.DISTANCE)
        main_model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.DISTANCE_GRADIENT)

        # We import the model main_model_part
        file_path = os.path.dirname(os.path.realpath(__file__))
        KratosMultiphysics.ModelPartIO(
            file_path +
            "/mmg_eulerian_test/test_sphere_isosurface").ReadModelPart(
                main_model_part)

        # Set manually a distance function
        circle_radious = 0.25
        center_coordinates = [0.5, 0.5, 0.5]

        for node in main_model_part.Nodes:
            distance = (
                (node.X - center_coordinates[0])**2 +
                (node.Y - center_coordinates[1])**2 +
                (node.Z - center_coordinates[2])**2)**0.5 - circle_radious
            node.SetSolutionStepValue(KratosMultiphysics.DISTANCE, distance)

        # We calculate the gradient of the distance variable
        find_nodal_h = KratosMultiphysics.FindNodalHNonHistoricalProcess(
            main_model_part)
        find_nodal_h.Execute()

        mmg_parameters = KratosMultiphysics.Parameters("""
        {
            "discretization_type"              : "Isosurface",
            "filename"                         : "mmg_eulerian_test/test_sphere_isosurface",
            "save_external_files"              : true,
            "echo_level"                       : 0
        }
        """)

        # We create the remeshing utility
        mmg_parameters["filename"].SetString(
            file_path + "/" + mmg_parameters["filename"].GetString())
        mmg_process = MeshingApplication.MmgProcess3D(main_model_part,
                                                      mmg_parameters)

        # We remesh
        mmg_process.Execute()

        # Finally we export to GiD
        from gid_output_process import GiDOutputProcess
        gid_output = GiDOutputProcess(
            main_model_part, "gid_output",
            KratosMultiphysics.Parameters("""
                                        {
                                            "result_file_configuration" : {
                                                "gidpost_flags": {
                                                    "GiDPostMode": "GiD_PostBinary",
                                                    "WriteDeformedMeshFlag": "WriteUndeformed",
                                                    "WriteConditionsFlag": "WriteConditions",
                                                    "MultiFileFlag": "SingleFile"
                                                },
                                                "nodal_results"       : ["DISTANCE"]
                                            }
                                        }
                                        """))

        #gid_output.ExecuteInitialize()
        #gid_output.ExecuteBeforeSolutionLoop()
        #gid_output.ExecuteInitializeSolutionStep()
        #gid_output.PrintOutput()
        #gid_output.ExecuteFinalizeSolutionStep()
        #gid_output.ExecuteFinalize()

        from compare_two_files_check_process import CompareTwoFilesCheckProcess
        check_parameters = KratosMultiphysics.Parameters("""
                            {
                                "reference_file_name"   : "mmg_eulerian_test/test_sphere_isosurface_result.sol",
                                "output_file_name"      : "mmg_eulerian_test/test_sphere_isosurface_step=0.o.sol",
                                "dimension"             : 3,
                                "comparison_type"       : "sol_file"
                            }
                            """)
        check_parameters["reference_file_name"].SetString(
            file_path + "/" +
            check_parameters["reference_file_name"].GetString())
        check_parameters["output_file_name"].SetString(
            file_path + "/" + check_parameters["output_file_name"].GetString())
        check_files = CompareTwoFilesCheckProcess(check_parameters)

        check_files.ExecuteInitialize()
        check_files.ExecuteBeforeSolutionLoop()
        check_files.ExecuteInitializeSolutionStep()
        check_files.ExecuteFinalizeSolutionStep()
        check_files.ExecuteFinalize()
Exemplo n.º 10
0
    def test_remesh_sphere(self):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(
            KratosMultiphysics.Logger.Severity.WARNING)

        # We create the model part
        current_model = KratosMultiphysics.Model()
        main_model_part = current_model.CreateModelPart("MainModelPart")
        main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, 3)
        main_model_part.ProcessInfo.SetValue(KratosMultiphysics.TIME, 0.0)
        main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DELTA_TIME,
                                             1.0)
        #main_model_part.ProcessInfo.SetValue(KratosMultiphysics.STEP, 1)

        # We add the variables needed
        main_model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.DISTANCE)
        main_model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.DISTANCE_GRADIENT)

        # We import the model main_model_part
        file_path = os.path.dirname(os.path.realpath(__file__))
        KratosMultiphysics.ModelPartIO(file_path +
                                       "/mmg_eulerian_test/coarse_sphere_test"
                                       ).ReadModelPart(main_model_part)

        # We calculate the gradient of the distance variable
        find_nodal_h = KratosMultiphysics.FindNodalHNonHistoricalProcess(
            main_model_part)
        find_nodal_h.Execute()
        KratosMultiphysics.VariableUtils().SetNonHistoricalVariable(
            KratosMultiphysics.NODAL_AREA, 0.0, main_model_part.Nodes)
        local_gradient = KratosMultiphysics.ComputeNodalGradientProcess3D(
            main_model_part, KratosMultiphysics.DISTANCE,
            KratosMultiphysics.DISTANCE_GRADIENT,
            KratosMultiphysics.NODAL_AREA)
        local_gradient.Execute()

        # We set to zero the metric
        ZeroVector = KratosMultiphysics.Vector(6)
        ZeroVector[0] = 0.0
        ZeroVector[1] = 0.0
        ZeroVector[2] = 0.0
        ZeroVector[3] = 0.0
        ZeroVector[4] = 0.0
        ZeroVector[5] = 0.0

        for node in main_model_part.Nodes:
            node.SetValue(MeshingApplication.METRIC_TENSOR_3D, ZeroVector)

        # We define a metric using the ComputeLevelSetSolMetricProcess
        MetricParameters = KratosMultiphysics.Parameters("""
        {
            "minimal_size"                      : 1.0e-1,
            "enforce_current"                   : false,
            "anisotropy_remeshing"              : false,
            "anisotropy_parameters"             :{
                "hmin_over_hmax_anisotropic_ratio"  : 0.15,
                "boundary_layer_max_distance"       : 1.0e-4,
                "interpolation"                     : "Linear"
            }
        }
        """)
        metric_process = MeshingApplication.ComputeLevelSetSolMetricProcess3D(
            main_model_part, KratosMultiphysics.DISTANCE_GRADIENT,
            MetricParameters)
        metric_process.Execute()

        mmg_parameters = KratosMultiphysics.Parameters("""
        {
            "filename"                         : "mmg_eulerian_test/coarse_sphere_test",
            "save_external_files"              : true,
            "echo_level"                       : 0
        }
        """)

        # We create the remeshing utility
        mmg_parameters["filename"].SetString(
            file_path + "/" + mmg_parameters["filename"].GetString())
        mmg_process = MeshingApplication.MmgProcess3D(main_model_part,
                                                      mmg_parameters)

        # We remesh
        mmg_process.Execute()

        # Finally we export to GiD
        from gid_output_process import GiDOutputProcess
        gid_output = GiDOutputProcess(
            main_model_part, "gid_output",
            KratosMultiphysics.Parameters("""
                                        {
                                            "result_file_configuration" : {
                                                "gidpost_flags": {
                                                    "GiDPostMode": "GiD_PostBinary",
                                                    "WriteDeformedMeshFlag": "WriteUndeformed",
                                                    "WriteConditionsFlag": "WriteConditions",
                                                    "MultiFileFlag": "SingleFile"
                                                },
                                                "nodal_results"       : ["DISTANCE"]
                                            }
                                        }
                                        """))

        #gid_output.ExecuteInitialize()
        #gid_output.ExecuteBeforeSolutionLoop()
        #gid_output.ExecuteInitializeSolutionStep()
        #gid_output.PrintOutput()
        #gid_output.ExecuteFinalizeSolutionStep()
        #gid_output.ExecuteFinalize()

        from compare_two_files_check_process import CompareTwoFilesCheckProcess
        check_parameters = KratosMultiphysics.Parameters("""
                            {
                                "reference_file_name"   : "mmg_eulerian_test/coarse_sphere_test_result.sol",
                                "output_file_name"      : "mmg_eulerian_test/coarse_sphere_test_step=0.sol",
                                "dimension"             : 3,
                                "comparison_type"       : "sol_file"
                            }
                            """)
        check_parameters["reference_file_name"].SetString(
            file_path + "/" +
            check_parameters["reference_file_name"].GetString())
        check_parameters["output_file_name"].SetString(
            file_path + "/" + check_parameters["output_file_name"].GetString())
        check_files = CompareTwoFilesCheckProcess(check_parameters)

        check_files.ExecuteInitialize()
        check_files.ExecuteBeforeSolutionLoop()
        check_files.ExecuteInitializeSolutionStep()
        check_files.ExecuteFinalizeSolutionStep()
        check_files.ExecuteFinalize()

        import from_json_check_result_process

        check_parameters = KratosMultiphysics.Parameters("""
        {
            "check_variables"      : ["DISTANCE"],
            "input_file_name"      : "mmg_eulerian_test/distante_extrapolation.json",
            "model_part_name"      : "MainModelPart",
            "time_frequency"       : 0.0
        }
        """)

        check_parameters["input_file_name"].SetString(
            file_path + "/" + check_parameters["input_file_name"].GetString())
        check = from_json_check_result_process.FromJsonCheckResultProcess(
            current_model, check_parameters)
        check.ExecuteInitialize()
        check.ExecuteBeforeSolutionLoop()
        check.ExecuteFinalizeSolutionStep()
Exemplo n.º 11
0
    def test_remesh_sphere(self):
        # We create the model part
        main_model_part = KratosMultiphysics.ModelPart("MainModelPart")
        main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, 3)

        # We add the variables needed
        main_model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.DISTANCE)
        main_model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.DISTANCE_GRADIENT)
        main_model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.NODAL_H)
        main_model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.NODAL_AREA)

        for node in main_model_part.Nodes:
            node.AddDof(KratosMultiphysics.DISTANCE)

        # We import the model main_model_part
        file_path = os.path.dirname(os.path.realpath(__file__))
        KratosMultiphysics.ModelPartIO(file_path +
                                       "/mmg_eulerian_test/coarse_sphere_test"
                                       ).ReadModelPart(main_model_part)

        # We calculate the gradient of the distance variable
        find_nodal_h = KratosMultiphysics.FindNodalHProcess(main_model_part)
        find_nodal_h.Execute()
        local_gradient = KratosMultiphysics.ComputeNodalGradientProcess3D(
            main_model_part, KratosMultiphysics.DISTANCE,
            KratosMultiphysics.DISTANCE_GRADIENT,
            KratosMultiphysics.NODAL_AREA)
        local_gradient.Execute()

        # We set to zero the metric
        ZeroVector = KratosMultiphysics.Vector(6)
        ZeroVector[0] = 0.0
        ZeroVector[1] = 0.0
        ZeroVector[2] = 0.0
        ZeroVector[3] = 0.0
        ZeroVector[4] = 0.0
        ZeroVector[5] = 0.0

        for node in main_model_part.Nodes:
            node.SetValue(MeshingApplication.MMG_METRIC, ZeroVector)

        # We define a metric using the ComputeLevelSetSolMetricProcess
        MetricParameters = KratosMultiphysics.Parameters("""
        {
            "minimal_size"                      : 1.0e-1,
            "enforce_current"                   : false,
            "anisotropy_remeshing"              : false,
            "anisotropy_parameters"             :{
                "hmin_over_hmax_anisotropic_ratio"  : 0.15,
                "boundary_layer_max_distance"       : 1.0e-4,
                "interpolation"                     : "Linear"
            }
        }
        """)
        metric_process = MeshingApplication.ComputeLevelSetSolMetricProcess3D(
            main_model_part, KratosMultiphysics.DISTANCE_GRADIENT,
            MetricParameters)

        metric_process.Execute()

        mmg_parameters = KratosMultiphysics.Parameters("""
        {
            "filename"                         : "mmg_eulerian_test/coarse_sphere_test", 
            "save_external_files"              : true,
            "echo_level"                       : 0
        }
        """)

        # We create the remeshing utility
        mmg_parameters["filename"].SetString(
            file_path + "/" + mmg_parameters["filename"].GetString())
        mmg_process = MeshingApplication.MmgProcess3D(main_model_part,
                                                      mmg_parameters)

        # We remesh
        mmg_process.Execute()

        # Finally we export to GiD
        from gid_output_process import GiDOutputProcess
        gid_output = GiDOutputProcess(
            main_model_part, "gid_output",
            KratosMultiphysics.Parameters("""
                                        {
                                            "result_file_configuration" : {
                                                "gidpost_flags": {
                                                    "GiDPostMode": "GiD_PostBinary",
                                                    "WriteDeformedMeshFlag": "WriteUndeformed",
                                                    "WriteConditionsFlag": "WriteConditions",
                                                    "MultiFileFlag": "SingleFile"
                                                },        
                                                "nodal_results"       : []
                                            }
                                        }
                                        """))

        #gid_output.ExecuteInitialize()
        #gid_output.ExecuteBeforeSolutionLoop()
        #gid_output.ExecuteInitializeSolutionStep()
        #gid_output.PrintOutput()
        #gid_output.ExecuteFinalizeSolutionStep()
        #gid_output.ExecuteFinalize()

        import filecmp
        value = filecmp.cmp(
            file_path + "/mmg_eulerian_test/coarse_sphere_test_result.mesh",
            file_path + "/mmg_eulerian_test/coarse_sphere_test_step=0.o.mesh")
        self.assertTrue(value)