示例#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()
示例#2
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
示例#4
0
# "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")

# =======================================================================================================
示例#5
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()
示例#6
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()