예제 #1
0
 def tearDown(self):
     file_to_remove = os.path.join("DEM3D_contact_tests_files",
                                   "TimesPartialRelease")
     kratos_utils.DeleteFileIfExisting(GetFilePath(file_to_remove))
     file_to_remove = os.path.join("DEM3D_contact_tests_files",
                                   "flux_data_new.hdf5")
     kratos_utils.DeleteFileIfExisting(GetFilePath(file_to_remove))
     os.chdir(this_working_dir_backup)
예제 #2
0
 def tearDown(self):
     # Clean up temporary files
     kratos_utils.DeleteFileIfExisting(
         GetFilePath("test_model_part_io_write.out.mdpa"))
     kratos_utils.DeleteFileIfExisting(
         GetFilePath("test_model_part_io_write.out.time"))
     kratos_utils.DeleteFileIfExisting(
         GetFilePath("test_model_part_io_write.time"))
예제 #3
0
 def tearDown(self):
     kratos_comm = KratosMultiphysics.DataCommunicator.GetDefault()
     rank = kratos_comm.Rank()
     kratos_utilities.DeleteFileIfExisting("test_mpi_communicator.time")
     kratos_utilities.DeleteFileIfExisting("test_mpi_communicator_" +
                                           str(rank) + ".mdpa")
     kratos_utilities.DeleteFileIfExisting("test_mpi_communicator_" +
                                           str(rank) + ".time")
     kratos_comm.Barrier()
    def testALEFluidSolver(self):
        work_folder = "test_ale_fluid_solver"
        settings_file_name = "ProjectParameters.json"

        with WorkFolderScope(work_folder):
            self._runTest(settings_file_name)

            kratos_utilities.DeleteFileIfExisting("ale_fluid_test.time")
            kratos_utilities.DeleteFileIfExisting("test_ale_fluid_solver.post.lst")
예제 #5
0
    def _clean_up( self ):

        kratos_utils.DeleteFileIfExisting("FluidModelPart.post.bin")
        kratos_utils.DeleteFileIfExisting("tests.post.lst")
        kratos_utils.DeleteFileIfExisting("tests.post.bin")

        for i in range(0,100):
            file_name = "TwoFluidInletTest/test_inlet_" + str(i) + ".mdpa"
            kratos_utils.DeleteFileIfExisting(file_name)
예제 #6
0
    def tearDown(self):
        # Within this location context:
        with controlledExecutionScope(self.path):
            self.response_function.Finalize()

            kratos_utils.DeleteFileIfExisting(self.problem_name + ".post.bin")
            kratos_utils.DeleteFileIfExisting(self.problem_name + ".time")
            kratos_utils.DeleteFileIfExisting(
                "response_function_tests.post.lst")
예제 #7
0
 def tearDown(self):
     rank = self.communicator.Rank()
     if rank == 0:
         kratos_utilities.DeleteFileIfExisting("test_mpi_communicator.time")
     kratos_utilities.DeleteFileIfExisting("test_mpi_communicator_" +
                                           str(rank) + ".mdpa")
     kratos_utilities.DeleteFileIfExisting("test_mpi_communicator_" +
                                           str(rank) + ".time")
     self.communicator.Barrier()
예제 #8
0
 def tearDown(self):
     with UnitTest.WorkFolderScope(self.work_folder, __file__):
         filename_fluid = self.ProjectParameters["solver_settings"]["model_import_settings"]["input_filename"].GetString()
         filename_structure = filename_fluid + '_structure'
         KratosUtilities.DeleteFileIfExisting(filename_fluid + '.time')
         KratosUtilities.DeleteFileIfExisting(filename_structure + '.time')
         if not self.print_output:
             KratosUtilities.DeleteFileIfExisting(filename_fluid + '.post.bin')
             KratosUtilities.DeleteFileIfExisting(self.work_folder + '.post.lst')
    def tearDown(self):
        # Within this location context:
        with KratosUnittest.WorkFolderScope(_get_test_working_dir(), __file__):
            self.response_function.Finalize()

            kratos_utils.DeleteFileIfExisting(self.problem_name + ".post.bin")
            kratos_utils.DeleteFileIfExisting(self.problem_name + ".time")
            kratos_utils.DeleteFileIfExisting(self.problem_name + ".h5")
            kratos_utils.DeleteFileIfExisting(self.problem_name + "-1.0000.h5")
            kratos_utils.DeleteFileIfExisting("response_function_tests.post.lst")
 def tearDown(self):
     # Within this location context:
     with KratosUnittest.WorkFolderScope(".", __file__):
         self.adjoint_analysis.Finalize()
         kratos_utilities.DeleteFileIfExisting(self.problem_name + ".time")
         kratos_utilities.DeleteFileIfExisting(self.model_part_name + ".h5")
         kratos_utilities.DeleteFileIfExisting(self.model_part_name +
                                               "-1.0000.h5")
         kratos_utilities.DeleteFileIfExisting(self.model_part_name +
                                               "-1.1000.h5")
예제 #11
0
 def tearDown(self):
     file_to_remove = os.path.join("post_process_tests_files",
                                   "TimesPartialRelease")
     kratos_utils.DeleteFileIfExisting(GetFilePath(file_to_remove))
     file_to_remove = os.path.join("post_process_tests_files",
                                   "flux_data_new.hdf5")
     kratos_utils.DeleteFileIfExisting(GetFilePath(file_to_remove))
     file_to_remove = os.path.join("post_process_tests_files",
                                   "ringcluster3D.clu")
     kratos_utils.DeleteFileIfExisting(GetFilePath(file_to_remove))
     os.chdir(this_working_dir_backup)
예제 #12
0
    def tearDown(self):
        # Within this location context:
        with KratosUnittest.WorkFolderScope(self.work_folder, __file__):
            self.response_function.Finalize()

            kratos_utils.DeleteFileIfExisting("diffusion_test_primal.post.bin")
            kratos_utils.DeleteFileIfExisting(
                "diffusion_test_adjoint.post.bin")
            kratos_utils.DeleteFileIfExisting("adjoint_diffusion_test.time")
            kratos_utils.DeleteFileIfExisting(
                "adjoint_diffusion_test.post.lst")
예제 #13
0
    def tearDown(self):
        my_pid = self.model_part.GetCommunicator().MyPID()

        # Remove the .time file
        KratosUtils.DeleteFileIfExisting("levelset_convection_process_mesh.time")

        # Remove the Metis partitioning files
        KratosUtils.DeleteDirectoryIfExisting("levelset_convection_process_mesh_partitioned")

        # While compining in debug, in memory partitioner also writes down the mpda in plain text
        # and needs to be cleaned.
        KratosUtils.DeleteFileIfExisting("debug_modelpart_" + str(my_pid) + ".mdpa")
    def tearDown(self):
        my_pid = self.model_part.GetCommunicator().MyPID()

        # Remove the .time file
        KratosUtils.DeleteFileIfExisting("coarse_sphere.time")

        # Remove the Metis partitioning files
        KratosUtils.DeleteFileIfExisting("coarse_sphere_" + str(my_pid) + ".time")
        KratosUtils.DeleteFileIfExisting("coarse_sphere_" + str(my_pid) + ".mdpa")

        # While compining in debug, in memory partitioner also writes down the mpda in plain text
        # and needs to be cleaned.
        KratosUtils.DeleteFileIfExisting("debug_modelpart_" + str(my_pid) + ".mdpa")
    def testCylinder(self):
        with ControlledExecutionScope(os.path.dirname(os.path.realpath(__file__))):
            # solve fluid
            self.solve('AdjointVMSSensitivity2DTest/cylinder_test')
            # solve adjoint
            test = self._createAdjointTest('AdjointVMSSensitivity2DTest/cylinder_test_adjoint')
            test.Run()
            Sensitivity = [[]]
            Sensitivity[0].append(test._GetSolver().main_model_part.GetNode(1968).GetSolutionStepValue(SHAPE_SENSITIVITY_X))
            Sensitivity[0].append(test._GetSolver().main_model_part.GetNode(1968).GetSolutionStepValue(SHAPE_SENSITIVITY_Y))

            # calculate sensitivity by finite difference
            step_size = 0.00000001
            FDSensitivity = self._computeFiniteDifferenceDragSensitivity([1968],step_size,'./AdjointVMSSensitivity2DTest/cylinder_test',[1.0,0.0,0.0],'./AdjointVMSSensitivity2DTest/cylinder_test.dat')
            self.assertAlmostEqual(Sensitivity[0][0], FDSensitivity[0][0], 5)
            self.assertAlmostEqual(Sensitivity[0][1], FDSensitivity[0][1], 5)
            self._removeH5Files("MainModelPart")
            kratos_utils.DeleteFileIfExisting("./AdjointVMSSensitivity2DTest/cylinder_test.dat")
            kratos_utils.DeleteFileIfExisting("./AdjointVMSSensitivity2DTest/cylinder_test.time")
            kratos_utils.DeleteFileIfExisting("./AdjointVMSSensitivity2DTest/cylinder_test_probe1.dat")
            kratos_utils.DeleteFileIfExisting("./AdjointVMSSensitivity2DTest/cylinder_test_probe2.dat")
            kratos_utils.DeleteFileIfExisting("./AdjointVMSSensitivity2DTest/cylinder_test_adjoint_probe1.dat")
            kratos_utils.DeleteFileIfExisting("./AdjointVMSSensitivity2DTest/cylinder_test_adjoint_probe2.dat")
            kratos_utils.DeleteFileIfExisting("./AdjointVMSSensitivity2DTest/cylinder_test_adjoint_probe3.dat")
            kratos_utils.DeleteFileIfExisting("./cylinder_test.post.bin")
    def MultilevelMonteCarloTest(self):
        with KratosUnittest.WorkFolderScope(os.path.join(self.folder_name),__file__,add_to_path=True):
            import test_cmlmc_utilities as cmlmc_utilities
            from simulation_definition import SimulationScenario

            # set the ProjectParameters.json path
            project_parameters_path = "problem_settings/parameters_poisson_square_2d_coarse.json"
            # customize setting parameters of the MLMC simulation
            settings_MLMC_simulation = KratosMultiphysics.Parameters("""
            {
                "tol0"                            : 0.25,
                "tolF"                            : 0.1,
                "cphi"                            : 1.0,
                "number_samples_screening"        : 25,
                "Lscreening"                      : 2,
                "Lmax"                            : 4,
                "initial_mesh_size"               : 0.5
            }
            """)
            # customize setting parameters of the metric of the adaptive refinement utility
            custom_metric_refinement_parameters = KratosMultiphysics.Parameters("""
                {
                    "hessian_strategy_parameters"           :{
                            "metric_variable"               : ["TEMPERATURE"],
                            "estimate_interpolation_error"  : false,
                            "interpolation_error"           : 0.004
                    },
                    "anisotropy_remeshing"                  : true,
                    "anisotropy_parameters":{
                        "reference_variable_name"           : "TEMPERATURE",
                        "hmin_over_hmax_anisotropic_ratio"  : 0.15,
                        "boundary_layer_max_distance"       : 1.0,
                        "interpolation"                     : "Linear"
                    },
                    "local_gradient_variable"               : "TEMPERATURE"
                }
            """)
            # customize setting parameters of the remesh of the adaptive refinement utility
            custom_remesh_refinement_settings = KratosMultiphysics.Parameters("""
                {
                    "echo_level"                            : 0
                }
            """)
            # contruct MultilevelMonteCarlo class
            mlmc_manager = cmlmc_utilities.MultilevelMonteCarlo(settings_MLMC_simulation,project_parameters_path,custom_metric_refinement_parameters,custom_remesh_refinement_settings,SimulationScenario)
            mlmc_manager.Run()
            """delete files"""
            kratos_utilities.DeleteFileIfExisting(os.path.join(self.folder_name,"poisson_square_2d.post.bin"))
            kratos_utilities.DeleteFileIfExisting(os.path.join(self.folder_name,"poisson_square_2d.post.lst"))
    def testSingleConvergenceOutputProcessCheck(self):
        if not h5py_available:
            self.skipTest('h5py is not available')
        settings = KM.Parameters('''{
            "Parameters"         : {
                "model_part_name"            : "model_part",
                "file_name"                  : "output_file",
                "analysis_label"             : "label",
                "analysis_attributes"        : {
                    "density"                     : 1.0
                },
                "convergence_variables_list" : ["ERROR_RATIO","NODAL_ERROR"]
            }
        }''')
        variables = [KM.ERROR_RATIO, KM.NODAL_ERROR]

        values = [1e-3, 1e-4]
        self._AuxiliaryAnalysis(settings, variables, values)
        self._CheckValues(
            settings["Parameters"]["file_name"].GetString() + ".hdf5",
            "analysis_000", 0, variables, values)

        values = [2e-3, 2e-4]
        self._AuxiliaryAnalysis(settings, variables, values)
        self._CheckValues(
            settings["Parameters"]["file_name"].GetString() + ".hdf5",
            "analysis_000", 1, variables, values)

        kratos_utils.DeleteFileIfExisting(
            settings["Parameters"]["file_name"].GetString() + ".hdf5")
예제 #18
0
    def MonteCarloTest(self):
        with KratosUnittest.WorkFolderScope(os.path.join(self.folder_name),__file__,add_to_path=True):
            import KratosMultiphysics.MultilevelMonteCarloApplication.mc_utilities as mc_utilities
            from poisson_square_2d_kratos.simulation_definition import SimulationScenario

            # set the ProjectParameters.json path
            project_parameters_path = "problem_settings/parameters_poisson_square_2d_coarse.json"
            # set parameters of the MC simulation"""
            parameters_x_monte_carlo_path = "problem_settings/parameters_x_monte_carlo.json"
            # contruct MonteCarlo or MultilevelMonteCarlo class
            mc_manager = mc_utilities.MonteCarlo(parameters_x_monte_carlo_path,project_parameters_path,SimulationScenario)
            # execute algorithm
            mc_manager.Run()
            """delete files"""
            kratos_utilities.DeleteFileIfExisting(os.path.join(self.folder_name,"poisson_square_2d.post.bin"))
            kratos_utilities.DeleteFileIfExisting(os.path.join(self.folder_name,"poisson_square_2d.post.lst"))
예제 #19
0
    def tearDown(self):
        super(StructuralMechanicsTestFactoryMPI, self).tearDown()

        # Now delete the partitioned mdpa files
        for i in range(KratosMPI.mpi.size):
            partitioned_mdpa_file_name = self.input_filename + "_" + str(i) + ".mdpa"
            kratos_utils.DeleteFileIfExisting(GetFilePath(partitioned_mdpa_file_name))
    def ExecuteFinalize(self):
        """The files are compared in this function
        Please see the respective files for details on the format of the files
        """
        if kratos_utils.IsRankZero():
            if (self.comparison_type == "deterministic"):
                value = filecmp.cmp(self.reference_file_name,
                                    self.output_file_name)
                self.assertTrue(value)
            elif (self.comparison_type == "mesh_file"):
                self.__CompareMeshVerticesFile()
            elif (self.comparison_type == "sol_file"):
                self.__CompareSolMetricFile()
            elif (self.comparison_type == "post_res_file"):
                self.__ComparePostResFile()
            elif (self.comparison_type == "dat_file"):
                self.__CompareDatFile()
            else:
                raise NameError('Requested comparision type "' +
                                self.comparison_type + '" not implemented yet')

        if self.remove_output_file == True:
            kratos_utils.DeleteFileIfExisting(
                self.output_file_name
            )  # this checks internally if it is rank 0
예제 #21
0
    def test_EMPIRE_API_sendMesh(self):
        model = KM.Model()
        model_part = model.CreateModelPart("For_Sending")

        severity = KM.Logger.GetDefaultOutput().GetSeverity()
        KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING) # mute MP-IO

        model_part_io = KM.ModelPartIO(GetFilePath("generic_mdpa_files/Mok_CFD"))
        model_part_io.ReadModelPart(model_part)

        KM.Logger.GetDefaultOutput().SetSeverity(severity)

        KratosCoSim.EMPIRE_API.EMPIRE_API_sendMesh(model_part)

        params = KM.Parameters("""{
            "comparison_type"     : "vtk",
            "reference_file_name" : "",
            "output_file_name"    : ""
        }""")
        params["reference_file_name"].SetString(GetFilePath("reference_files/EMPIRE_mesh_For_Sending.vtk_ref"))
        params["output_file_name"].SetString(os.path.join(communication_folder, "EMPIRE_mesh_For_Sending.vtk"))

        CompareTwoFilesCheckProcess(params).Execute()

        kratos_utils.DeleteFileIfExisting("EMPIRE_mesh_For_Sending.vtk")
예제 #22
0
    def test_Naca0012SmallCompressible(self):
        if not eignsolver_is_available:
            self.skipTest(
                "Missing required application: EigenSolversApplication")
        file_name = "naca0012_small_compressible"
        settings_file_name = file_name + "_parameters.json"
        work_folder = "naca0012_small_compressible_test"

        with WorkFolderScope(work_folder):
            self._runTest(settings_file_name)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.LIFT_COEFFICIENT],
                0.4968313580730855, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.MOMENT_COEFFICIENT],
                -0.1631792300021498, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.LIFT_COEFFICIENT_JUMP],
                0.4876931961465126, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[
                    CPFApp.LIFT_COEFFICIENT_FAR_FIELD], 0.4953997676243705,
                0.0, 1e-9)

            for file_name in os.listdir():
                if file_name.endswith(".time"):
                    kratos_utilities.DeleteFileIfExisting(file_name)
예제 #23
0
    def test_EmbeddedCircle(self):
        settings_file_name = "embedded_circle_parameters.json"
        settings_adjoint_file_name = "embedded_circle_adjoint_parameters.json"
        settings_penalty_file_name = "embedded_circle_penalty_parameters.json"
        work_folder = "embedded_test"

        with WorkFolderScope(work_folder):
            self._runTest(settings_file_name)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.LIFT_COEFFICIENT],
                -0.08769331821378197, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.LIFT_COEFFICIENT_JUMP],
                -0.5405047994795951, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[
                    CPFApp.LIFT_COEFFICIENT_FAR_FIELD], -0.04198874676923284,
                0.0, 1e-9)
            self._runTest(settings_adjoint_file_name)
            self._runTest(settings_penalty_file_name)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.LIFT_COEFFICIENT],
                0.12976919914058177, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.LIFT_COEFFICIENT_JUMP],
                -0.4636936459965071, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[
                    CPFApp.LIFT_COEFFICIENT_FAR_FIELD], 0.08091879125682809,
                0.0, 1e-9)

            for file_name in os.listdir(os.getcwd()):
                if file_name.endswith(".h5"):
                    kratos_utilities.DeleteFileIfExisting(file_name)
예제 #24
0
    def _ExecuteMultipleConvergenceOutputProcessCheck(self):
        settings = KM.Parameters('''{
            "Parameters"         : {
                "model_part_name"            : "model_part",
                "file_name"                  : "output_file",
                "analysis_label"             : "label",
                "analysis_attributes"        : {
                    "density"                    : 1.0,
                    "dummy_flag"                 : true,
                    "dummy_string"               : "string"
                },
                "convergence_variables_list" : ["ERROR_RATIO"]
            }
        }''')
        variables = [KM.ERROR_RATIO]
        values = [1e-3]
        DummyAnalysis(settings, variables, values)

        settings["Parameters"]["analysis_attributes"]["density"].SetDouble(
            13.6)
        DummyAnalysis(settings, variables, values)

        self._CheckTwoDatasets(
            settings["Parameters"]["file_name"].GetString() + ".hdf5",
            "analysis_000", "analysis_001", "density", 1.0, 13.6)

        kratos_utils.DeleteFileIfExisting(
            settings["Parameters"]["file_name"].GetString() + ".hdf5")
예제 #25
0
    def _ExecuteBasicConvergenceOutputProcessCheck(self):
        settings = KM.Parameters('''{
            "Parameters"         : {
                "model_part_name"            : "model_part",
                "file_name"                  : "output_file",
                "analysis_label"             : "label",
                "analysis_attributes"        : {
                    "density"                     : 1.0
                },
                "convergence_variables_list" : ["ERROR_RATIO","NODAL_ERROR"]
            }
        }''')
        variables = [KM.ERROR_RATIO, KM.NODAL_ERROR]

        values = [1e-3, 1e-4]
        DummyAnalysis(settings, variables, values)
        self._CheckValues(
            settings["Parameters"]["file_name"].GetString() + ".hdf5",
            "analysis_000", 0, variables, values)

        values = [2e-3, 2e-4]
        DummyAnalysis(settings, variables, values)
        self._CheckValues(
            settings["Parameters"]["file_name"].GetString() + ".hdf5",
            "analysis_000", 1, variables, values)

        kratos_utils.DeleteFileIfExisting(
            settings["Parameters"]["file_name"].GetString() + ".hdf5")
예제 #26
0
    def test_Struct_Static_HROM_2D(self):
        with KratosUnittest.WorkFolderScope(".", __file__):
            with open("ProjectParametersHROM.json", 'r') as parameter_file:
                parameters = KratosMultiphysics.Parameters(
                    parameter_file.read())
            model = KratosMultiphysics.Model()
            Simulation = TestStructuralMechanicsStaticHROM(model, parameters)
            Simulation.Run()
            ObtainedOutput = Simulation.EvaluateQuantityOfInterest()
            ExpectedOutput = np.load('ExpectedOutputHROM.npy')
            NodalArea = Simulation.EvaluateQuantityOfInterest2()
            print(NodalArea)

            UP = 0
            DOWN = 0
            for i in range(len(ObtainedOutput)):
                if ExpectedOutput[i] != 0:
                    UP += (NodalArea[i] *
                           ((1 - (ObtainedOutput[i] / ExpectedOutput[i]))**2))
                    DOWN += NodalArea[i]
            L2 = (np.sqrt(UP / DOWN)) * 100
            self.assertLess(L2, 1e-12)  #percent
            # Cleaning
            kratos_utilities.DeleteDirectoryIfExisting("__pycache__")
            kratos_utilities.DeleteDirectoryIfExisting("vtk_output")
            for file_name in os.listdir(os.getcwd()):
                if file_name.endswith(".bin") or file_name.endswith(".lst"):
                    kratos_utilities.DeleteFileIfExisting(file_name)
예제 #27
0
    def test_Naca0012SmallAdjoint(self):
        if not hdf5_is_available:
            self.skipTest("Missing required application: HDF5Application")
        file_name = "naca0012_small_sensitivities"
        settings_file_name_primal = file_name + "_primal_parameters.json"
        settings_file_name_adjoint = file_name + "_adjoint_parameters.json"
        settings_file_name_adjoint_analytical = file_name + "_adjoint_analytical_parameters.json"
        work_folder = "naca0012_small_adjoint_test"

        with WorkFolderScope(work_folder):
            self._runTest(settings_file_name_primal)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.LIFT_COEFFICIENT],
                0.327805503865, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.MOMENT_COEFFICIENT],
                -0.105810071870, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[CPFApp.LIFT_COEFFICIENT_JUMP],
                0.3230253050805644, 0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[
                    CPFApp.LIFT_COEFFICIENT_FAR_FIELD], 0.32651526722535246,
                0.0, 1e-9)
            self._check_results(
                self.main_model_part.ProcessInfo[
                    CPFApp.DRAG_COEFFICIENT_FAR_FIELD], 0.0036897206842046205,
                0.0, 1e-9)
            self._runTest(settings_file_name_adjoint)
            self._runTest(settings_file_name_adjoint_analytical)

            for file_name in os.listdir(os.getcwd()):
                if file_name.endswith(".h5"):
                    kratos_utilities.DeleteFileIfExisting(file_name)
예제 #28
0
 def test_KratosFluidDynamicsSolver(self):
     with co_simulation_test_case.ControlledExecutionScope(
             os.path.dirname(os.path.realpath(__file__))):
         # self.createTest('test_structural_mesh_motion_2d/rectangle_2D3N_test')
         # self.runTest()
         kratos_utils.DeleteFileIfExisting(
             "./test_mdpa_files/rectangle_2D3N_test.time")
    def ExecuteFinalize(self):
        """The files are compared in this function
        Please see the respective files for details on the format of the files
        """

        KratosMultiphysics.DataCommunicator.GetDefault().Barrier()

        if (self.comparison_type == "deterministic"):
            value = filecmp.cmp(self.reference_file_name,
                                self.output_file_name)
            self.assertTrue(value, msg=self.info_msg)
        elif (self.comparison_type == "mesh_file"):
            self.__CompareMeshVerticesFile()
        elif (self.comparison_type == "sol_file"):
            self.__CompareSolMetricFile()
        elif (self.comparison_type == "post_res_file"):
            self.__ComparePostResFile()
        elif (self.comparison_type == "dat_file"):
            self.__CompareDatFile()
        elif (self.comparison_type == "dat_file_variables_time_history"):
            self.__CompareDatFileVariablesTimeHistory()
        elif (self.comparison_type == "vtk"):
            self.__CompareVtkFile()
        else:
            raise NameError('Requested comparision type "' +
                            self.comparison_type + '" not implemented yet')

        if self.remove_output_file:
            kratos_utils.DeleteFileIfExisting(self.output_file_name)
 def test_HDF5NodalSolutionStepDataIO(self):
     with ControlledExecutionScope(os.path.dirname(os.path.realpath(__file__))):
         current_model = Model()
         write_model_part = current_model.CreateModelPart("write")
         KratosMPI.ModelPartCommunicatorUtilities.SetMPICommunicator(write_model_part)
         self._initialize_model_part(write_model_part)
         hdf5_file = self._get_file()
         hdf5_model_part_io = self._get_model_part_io(hdf5_file)
         hdf5_model_part_io.WriteModelPart(write_model_part)
         read_model_part = current_model.CreateModelPart("read")
         KratosMPI.ModelPartCommunicatorUtilities.SetMPICommunicator(read_model_part)
         hdf5_model_part_io.ReadModelPart(read_model_part)
         KratosMPI.ParallelFillCommunicator(read_model_part.GetRootModelPart()).Execute()
         hdf5_nodal_solution_step_data_io = self._get_nodal_solution_step_data_io(hdf5_file)
         hdf5_nodal_solution_step_data_io.WriteNodalResults(write_model_part.Nodes, 0)
         hdf5_nodal_solution_step_data_io.ReadNodalResults(read_model_part.Nodes, read_model_part.GetCommunicator(), 0)
         read_model_part.GetCommunicator().SynchronizeNodalSolutionStepsData()
         # Check data.
         for read_node, write_node in zip(read_model_part.Nodes, write_model_part.Nodes):
             self.assertEqual(read_node.GetSolutionStepValue(DISPLACEMENT_X), write_node.GetSolutionStepValue(DISPLACEMENT_X))
             self.assertEqual(read_node.GetSolutionStepValue(DISPLACEMENT_Y), write_node.GetSolutionStepValue(DISPLACEMENT_Y))
             self.assertEqual(read_node.GetSolutionStepValue(DISPLACEMENT_Z), write_node.GetSolutionStepValue(DISPLACEMENT_Z))
             self.assertEqual(read_node.GetSolutionStepValue(VELOCITY_X), write_node.GetSolutionStepValue(VELOCITY_X))
             self.assertEqual(read_node.GetSolutionStepValue(VELOCITY_Y), write_node.GetSolutionStepValue(VELOCITY_Y))
             self.assertEqual(read_node.GetSolutionStepValue(VELOCITY_Z), write_node.GetSolutionStepValue(VELOCITY_Z))
             self.assertEqual(read_node.GetSolutionStepValue(ACCELERATION_X), write_node.GetSolutionStepValue(ACCELERATION_X))
             self.assertEqual(read_node.GetSolutionStepValue(ACCELERATION_Y), write_node.GetSolutionStepValue(ACCELERATION_Y))
             self.assertEqual(read_node.GetSolutionStepValue(ACCELERATION_Z), write_node.GetSolutionStepValue(ACCELERATION_Z))
             self.assertEqual(read_node.GetSolutionStepValue(PRESSURE), write_node.GetSolutionStepValue(PRESSURE))
             self.assertEqual(read_node.GetSolutionStepValue(VISCOSITY), write_node.GetSolutionStepValue(VISCOSITY))
             self.assertEqual(read_node.GetSolutionStepValue(DENSITY), write_node.GetSolutionStepValue(DENSITY))
             self.assertEqual(read_node.GetSolutionStepValue(ACTIVATION_LEVEL), write_node.GetSolutionStepValue(ACTIVATION_LEVEL))
             self.assertEqual(read_node.GetSolutionStepValue(PARTITION_INDEX), write_node.GetSolutionStepValue(PARTITION_INDEX))
         kratos_utilities.DeleteFileIfExisting("test_hdf5_model_part_io_mpi.h5")