Exemplo n.º 1
0
 def checkResults(self):
     with UnitTest.WorkFolderScope(self.work_folder, __file__):
         if self.print_reference_values:
             json_output_settings = KratosMultiphysics.Parameters(r'''{
                     "output_variables": ["TEMPERATURE"],
                     "output_file_name": "",
                     "model_part_name": "MainModelPart",
                     "time_frequency": 0.0
             }''')
             json_output_settings["output_file_name"].SetString(GetFilePath("BFECCConvectionTest/" + self.reference_file + "_results.json"))
             json_output_process = JsonOutputProcess(self.model, json_output_settings)
             json_output_process.ExecuteInitialize()
             json_output_process.ExecuteBeforeSolutionLoop()
             json_output_process.ExecuteFinalizeSolutionStep()
         else:
             json_check_parameters = KratosMultiphysics.Parameters(r'''{
                 "check_variables"      : ["TEMPERATURE"],
                 "input_file_name"      : "",
                 "model_part_name"      : "MainModelPart",
                 "time_frequency"       : 0.0
             }''')
             json_check_parameters["input_file_name"].SetString(GetFilePath("BFECCConvectionTest/" + self.reference_file + "_results.json"))
             json_check_process = FromJsonCheckResultProcess(self.model, json_check_parameters)
             json_check_process.ExecuteInitialize()
             json_check_process.ExecuteBeforeSolutionLoop()
             json_check_process.ExecuteFinalizeSolutionStep()
Exemplo n.º 2
0
 def __check_results(self, model, results_filename):
     from_json_check_result_settings = KratosMultiphysics.Parameters(r"""
     {
         "check_variables": ["DISPLACEMENT_X","DISPLACEMENT_Y","VOLUMETRIC_STRAIN"],
         "input_file_name": "",
         "model_part_name": "cook_membrane.Parts_ResultsCheck"
     }""")
     from_json_check_result_settings["input_file_name"].SetString(
         results_filename)
     self.from_json_check_result = FromJsonCheckResultProcess(
         model, from_json_check_result_settings)
     self.from_json_check_result.ExecuteInitialize()
     self.from_json_check_result.ExecuteFinalizeSolutionStep()
Exemplo n.º 3
0
def RunJsonCheckProcess(model):
    parameters = KM.Parameters("""
    {
        "check_variables"  : ["SHAPE_CHANGE_X","SHAPE_CHANGE_Y","SHAPE_CHANGE_Z"],
        "input_file_name"  : "shape_change_results.json",
        "model_part_name"  : "structure.Parts_structure",
        "time_frequency"   : 0.0
    }
    """)
    process = FromJsonCheckResultProcess(model, parameters)
    process.ExecuteInitialize()
    process.ExecuteBeforeSolutionLoop()
    process.ExecuteFinalizeSolutionStep()
def _create_check_outputs(current_model):
    from KratosMultiphysics.from_json_check_result_process import FromJsonCheckResultProcess

    check_parameters = KratosMultiphysics.Parameters("""
    {
        "gauss_points_check_variables": ["VON_MISES_STRESS"],
        "input_file_name"      : "",
        "time_frequency"       : 0.01,
        "model_part_name"      : "solid_part",
        "sub_model_part_name"  : "Body"
    }
    """)

    check_parameters["input_file_name"].SetString(GetFilePath("test_perfect_plasticity_implementation_verification_reference.json"))

    check = FromJsonCheckResultProcess(current_model, check_parameters)
    check.ExecuteInitialize()
    check.ExecuteBeforeSolutionLoop()

    return check
Exemplo n.º 5
0
class TestCookMembrane(KratosUnittest.TestCase):
    def setUp(self):
        self.print_output = False
        self.print_results = False

    def test_cook_membrane_2d(self):
        results_filename = "cook_membrane_test/cook_membrane_results.json"
        parameters_filename = "cook_membrane_test/cook_membrane_parameters.json"
        with open(parameters_filename, 'r') as parameter_file:
            parameters = KratosMultiphysics.Parameters(parameter_file.read())

        model = KratosMultiphysics.Model()
        simulation = StructuralMechanicsAnalysis(model, parameters)
        simulation.Run()

        # self._check_results(model_part, A, b)
        if self.print_results:
            self.__print_results(model, results_filename)
        if self.print_output:
            self.__post_process(
                model.GetModelPart(parameters["solver_settings"]
                                   ["model_part_name"].GetString()))
        self.__check_results(model, results_filename)

    def test_cook_membrane_incompressible_2d(self):
        results_filename = "cook_membrane_test/cook_membrane_incompressible_results.json"
        parameters_filename = "cook_membrane_test/cook_membrane_parameters.json"
        with open(parameters_filename, 'r') as parameter_file:
            parameters = KratosMultiphysics.Parameters(parameter_file.read())
        parameters["solver_settings"]["material_import_settings"][
            "materials_filename"].SetString(
                "cook_membrane_test/cook_membrane_incompressible_materials.json"
            )

        model = KratosMultiphysics.Model()
        simulation = StructuralMechanicsAnalysis(model, parameters)
        simulation.Run()

        # self._check_results(model_part, A, b)
        if self.print_results:
            self.__print_results(model, results_filename)
        if self.print_output:
            self.__post_process(
                model.GetModelPart(parameters["solver_settings"]
                                   ["model_part_name"].GetString()))
        self.__check_results(model, results_filename)

    def __print_results(self, model, results_filename):
        json_output_settings = KratosMultiphysics.Parameters(r"""
        {
            "output_variables": ["DISPLACEMENT_X","DISPLACEMENT_Y","VOLUMETRIC_STRAIN"],
            "output_file_name": "",
            "time_frequency": 0.00,
            "model_part_name": "cook_membrane.Parts_ResultsCheck"
        }""")
        json_output_settings["output_file_name"].SetString(results_filename)
        self.json_output = JsonOutputProcess(model, json_output_settings)
        self.json_output.ExecuteInitialize()
        self.json_output.ExecuteBeforeSolutionLoop()
        self.json_output.ExecuteFinalizeSolutionStep()

    def __check_results(self, model, results_filename):
        from_json_check_result_settings = KratosMultiphysics.Parameters(r"""
        {
            "check_variables": ["DISPLACEMENT_X","DISPLACEMENT_Y","VOLUMETRIC_STRAIN"],
            "input_file_name": "",
            "model_part_name": "cook_membrane.Parts_ResultsCheck"
        }""")
        from_json_check_result_settings["input_file_name"].SetString(
            results_filename)
        self.from_json_check_result = FromJsonCheckResultProcess(
            model, from_json_check_result_settings)
        self.from_json_check_result.ExecuteInitialize()
        self.from_json_check_result.ExecuteFinalizeSolutionStep()

    def __post_process(self, main_model_part, post_type="gid"):
        if post_type == "gid":
            self.gid_output = GiDOutputProcess(
                main_model_part, main_model_part.Name,
                KratosMultiphysics.Parameters(r"""
                {
                    "result_file_configuration" : {
                    "gidpost_flags": {
                        "GiDPostMode": "GiD_PostBinary",
                        "WriteDeformedMeshFlag": "WriteUndeformed",
                        "WriteConditionsFlag": "WriteConditions",
                        "MultiFileFlag": "SingleFile"
                    },
                    "nodal_results"       : ["DISPLACEMENT","VOLUMETRIC_STRAIN"],
                    "gauss_point_results" : []
                    }
                }"""))

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

        elif post_type == "vtk":
            vtk_output_parameters = KratosMultiphysics.Parameters(r"""
            {
                "model_part_name": "",
                "extrapolate_gauss_points": false,
                "nodal_solution_step_data_variables" : ["DISPLACEMENT","VOLUMETRIC_STRAIN"],
                "gauss_point_variables": []
            }""")
            vtk_output_parameters["model_part_name"].SetString(
                main_model_part.Name)
            self.vtk_output_process = VtkOutputProcess(
                main_model_part.GetModel(), vtk_output_parameters)

            self.vtk_output_process.ExecuteInitialize()
            self.vtk_output_process.ExecuteBeforeSolutionLoop()
            self.vtk_output_process.ExecuteInitializeSolutionStep()
            self.vtk_output_process.PrintOutput()
            self.vtk_output_process.ExecuteFinalizeSolutionStep()
            self.vtk_output_process.ExecuteFinalize()
Exemplo n.º 6
0
#         "output_variables" : ["SHAPE_CHANGE_X","SHAPE_CHANGE_Y","SHAPE_CHANGE_Z"],
#         "output_file_name" : "shape_change_results.json",
# "model_part_name"  : \""""+optimization_model_part_name+"""\",
#         "time_frequency"   : 0.0
#     }"""))

# output_process.ExecuteInitialize()
# output_process.ExecuteBeforeSolutionLoop()
# output_process.ExecuteInitializeSolutionStep()
# output_process.ExecuteFinalizeSolutionStep()
# output_process.ExecuteFinalize()

check_process = FromJsonCheckResultProcess(
    model,
    KM.Parameters("""{
        "check_variables"  : ["SHAPE_CHANGE_X","SHAPE_CHANGE_Y","SHAPE_CHANGE_Z"],
        "input_file_name"  : "shape_change_results.json",
        "model_part_name"  : \"""" + optimization_model_part_name + """\",
        "time_frequency"   : 0.0
    }"""))
check_process.ExecuteInitialize()
check_process.ExecuteBeforeSolutionLoop()
check_process.ExecuteInitializeSolutionStep()
check_process.ExecuteFinalizeSolutionStep()
check_process.ExecuteFinalize()

# Cleaning
kratos_utilities.DeleteDirectoryIfExisting("__pycache__")
kratos_utilities.DeleteDirectoryIfExisting(output_directory)
kratos_utilities.DeleteFileIfExisting(
    os.path.basename(os.getcwd()) + ".post.lst")
Exemplo n.º 7
0
    def test_remesh_sphere_skin(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)

        # 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_skin_test").ReadModelPart(main_model_part)

        for node in main_model_part.Nodes:
            node.SetSolutionStepValue(KratosMultiphysics.DISTANCE, abs(node.X))

        # We calculate the gradient of the distance variable
        KratosMultiphysics.VariableUtils().SetNonHistoricalVariable(KratosMultiphysics.NODAL_H, 0.0, main_model_part.Nodes)
        find_nodal_h = KratosMultiphysics.FindNodalHNonHistoricalProcess(main_model_part)
        find_nodal_h.Execute()

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

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

        mmg_parameters = KratosMultiphysics.Parameters("""
        {
            "filename"                         : "mmg_eulerian_test/coarse_sphere_skin_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.MmgProcess3DSurfaces(main_model_part, mmg_parameters)

        # We remesh
        mmg_process.Execute()

        # Finally we export to GiD
        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()

        check_parameters = KratosMultiphysics.Parameters("""
                            {
                                "reference_file_name"   : "mmg_eulerian_test/coarse_sphere_skin_test_result.sol",
                                "output_file_name"      : "mmg_eulerian_test/coarse_sphere_skin_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()

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

        check_parameters["input_file_name"].SetString(os.path.join(file_path, check_parameters["input_file_name"].GetString()))
        if mmg_process.GetMmgVersion() == "5.5":
            check_parameters["input_file_name"].SetString(check_parameters["input_file_name"].GetString() + "_5_5.json")
        else:
            check_parameters["input_file_name"].SetString(check_parameters["input_file_name"].GetString() + ".json")
        check = FromJsonCheckResultProcess(current_model, check_parameters)
        check.ExecuteInitialize()
        check.ExecuteBeforeSolutionLoop()
        check.ExecuteFinalizeSolutionStep()
Exemplo n.º 8
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
        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()

        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()

        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 = FromJsonCheckResultProcess(current_model, check_parameters)
        check.ExecuteInitialize()
        check.ExecuteBeforeSolutionLoop()
        check.ExecuteFinalizeSolutionStep()