import KratosMultiphysics
import KratosMultiphysics.KratosUnittest as UnitTest
import KratosMultiphysics.ChimeraApplication
from KratosMultiphysics.ChimeraApplication.fluid_chimera_analysis import FluidChimeraAnalysis

class ChimeraAnalysisBaseTest(UnitTest.TestCase):

    def setUp(self):
        # Set to true to get post-process files for the test
        self.print_output = False

    def _run_test(self,settings_file_name):
        model = KratosMultiphysics.Model()
        with open(settings_file_name,'r') as settings_file:
            settings = KratosMultiphysics.Parameters(settings_file.read())
        # to check the results: add output settings block if needed
        if self.print_output:
            settings.AddValue("output_processes", KratosMultiphysics.Parameters(r'''{
                "vtk_output" : [{
                    "python_module" : "vtk_output_process",
                    "kratos_module" : "KratosMultiphysics",
                    "process_name"  : "VtkOutputProcess",
                    "help"          : "This process writes postprocessing files for Paraview",
                    "Parameters"    : {
                        "model_part_name"                    : "FluidModelPart.Parts_background_surface",
                        "output_control_type"                : "step",
                        "output_frequency"                   : 1,
                        "file_format"                        : "ascii",
                        "output_precision"                   : 3,
                        "output_sub_model_parts"             : false,
                       "write_deformed_configuration"        : true,
                        "folder_name"                        : "test_vtk_output",
                        "save_output_files_in_folder"        : true,
                        "nodal_solution_step_data_variables" : ["VELOCITY","PRESSURE","DISTANCE","MESH_VELOCITY"],
                        "nodal_data_value_variables"         : [],
                        "element_flags"                      : ["ACTIVE"],
                        "nodal_flags"                        : ["VISITED","CHIMERA_INTERNAL_BOUNDARY"],
                        "element_data_value_variables"       : [],
                        "condition_data_value_variables"     : []
                    }
                },{
                    "python_module" : "vtk_output_process",
                    "kratos_module" : "KratosMultiphysics",
                    "process_name"  : "VtkOutputProcess",
                    "help"          : "This process writes postprocessing files for Paraview",
                    "Parameters"    : {
                        "model_part_name"                    : "FluidModelPart.Parts_patch_surface",
                        "output_control_type"                : "step",
                        "output_frequency"                   : 1,
                        "file_format"                        : "ascii",
                        "output_precision"                   : 3,
                        "output_sub_model_parts"             : false,
                       "write_deformed_configuration"        : true,
                        "folder_name"                        : "test_vtk_output",
                        "save_output_files_in_folder"        : true,
                        "nodal_solution_step_data_variables" : ["VELOCITY","PRESSURE","DISTANCE","MESH_VELOCITY"],
                        "nodal_data_value_variables"         : [],
                        "element_flags"                      : ["ACTIVE"],
                        "nodal_flags"                        : ["VISITED","CHIMERA_INTERNAL_BOUNDARY"],
                        "element_data_value_variables"       : [],
                        "condition_data_value_variables"     : []
                    }
                }]
            }'''))

        analysis = FluidChimeraAnalysis(model,settings)
        analysis.Run()

[((13, 16, 13, 42), 'KratosMultiphysics.Model', 'KratosMultiphysics.Model', ({}, {}), '()', False, 'import KratosMultiphysics\n'), ((66, 19, 66, 55), 'KratosMultiphysics.ChimeraApplication.fluid_chimera_analysis.FluidChimeraAnalysis', 'FluidChimeraAnalysis', ({(66, 40, 66, 45): 'model', (66, 46, 66, 54): 'settings'}, {}), '(model, settings)', False, 'from KratosMultiphysics.ChimeraApplication.fluid_chimera_analysis import FluidChimeraAnalysis\n'), ((18, 50, 64, 17), 'KratosMultiphysics.Parameters', 'KratosMultiphysics.Parameters', ({(18, 80, 64, 16): '"""{\n                "vtk_output" : [{\n                    "python_module" : "vtk_output_process",\n                    "kratos_module" : "KratosMultiphysics",\n                    "process_name"  : "VtkOutputProcess",\n                    "help"          : "This process writes postprocessing files for Paraview",\n                    "Parameters"    : {\n                        "model_part_name"                    : "FluidModelPart.Parts_background_surface",\n                        "output_control_type"                : "step",\n                        "output_frequency"                   : 1,\n                        "file_format"                        : "ascii",\n                        "output_precision"                   : 3,\n                        "output_sub_model_parts"             : false,\n                       "write_deformed_configuration"        : true,\n                        "folder_name"                        : "test_vtk_output",\n                        "save_output_files_in_folder"        : true,\n                        "nodal_solution_step_data_variables" : ["VELOCITY","PRESSURE","DISTANCE","MESH_VELOCITY"],\n                        "nodal_data_value_variables"         : [],\n                        "element_flags"                      : ["ACTIVE"],\n                        "nodal_flags"                        : ["VISITED","CHIMERA_INTERNAL_BOUNDARY"],\n                        "element_data_value_variables"       : [],\n                        "condition_data_value_variables"     : []\n                    }\n                },{\n                    "python_module" : "vtk_output_process",\n                    "kratos_module" : "KratosMultiphysics",\n                    "process_name"  : "VtkOutputProcess",\n                    "help"          : "This process writes postprocessing files for Paraview",\n                    "Parameters"    : {\n                        "model_part_name"                    : "FluidModelPart.Parts_patch_surface",\n                        "output_control_type"                : "step",\n                        "output_frequency"                   : 1,\n                        "file_format"                        : "ascii",\n                        "output_precision"                   : 3,\n                        "output_sub_model_parts"             : false,\n                       "write_deformed_configuration"        : true,\n                        "folder_name"                        : "test_vtk_output",\n                        "save_output_files_in_folder"        : true,\n                        "nodal_solution_step_data_variables" : ["VELOCITY","PRESSURE","DISTANCE","MESH_VELOCITY"],\n                        "nodal_data_value_variables"         : [],\n                        "element_flags"                      : ["ACTIVE"],\n                        "nodal_flags"                        : ["VISITED","CHIMERA_INTERNAL_BOUNDARY"],\n                        "element_data_value_variables"       : [],\n                        "condition_data_value_variables"     : []\n                    }\n                }]\n            }"""'}, {}), '(\n    """{\n                "vtk_output" : [{\n                    "python_module" : "vtk_output_process",\n                    "kratos_module" : "KratosMultiphysics",\n                    "process_name"  : "VtkOutputProcess",\n                    "help"          : "This process writes postprocessing files for Paraview",\n                    "Parameters"    : {\n                        "model_part_name"                    : "FluidModelPart.Parts_background_surface",\n                        "output_control_type"                : "step",\n                        "output_frequency"                   : 1,\n                        "file_format"                        : "ascii",\n                        "output_precision"                   : 3,\n                        "output_sub_model_parts"             : false,\n                       "write_deformed_configuration"        : true,\n                        "folder_name"                        : "test_vtk_output",\n                        "save_output_files_in_folder"        : true,\n                        "nodal_solution_step_data_variables" : ["VELOCITY","PRESSURE","DISTANCE","MESH_VELOCITY"],\n                        "nodal_data_value_variables"         : [],\n                        "element_flags"                      : ["ACTIVE"],\n                        "nodal_flags"                        : ["VISITED","CHIMERA_INTERNAL_BOUNDARY"],\n                        "element_data_value_variables"       : [],\n                        "condition_data_value_variables"     : []\n                    }\n                },{\n                    "python_module" : "vtk_output_process",\n                    "kratos_module" : "KratosMultiphysics",\n                    "process_name"  : "VtkOutputProcess",\n                    "help"          : "This process writes postprocessing files for Paraview",\n                    "Parameters"    : {\n                        "model_part_name"                    : "FluidModelPart.Parts_patch_surface",\n                        "output_control_type"                : "step",\n                        "output_frequency"                   : 1,\n                        "file_format"                        : "ascii",\n                        "output_precision"                   : 3,\n                        "output_sub_model_parts"             : false,\n                       "write_deformed_configuration"        : true,\n                        "folder_name"                        : "test_vtk_output",\n                        "save_output_files_in_folder"        : true,\n                        "nodal_solution_step_data_variables" : ["VELOCITY","PRESSURE","DISTANCE","MESH_VELOCITY"],\n                        "nodal_data_value_variables"         : [],\n                        "element_flags"                      : ["ACTIVE"],\n                        "nodal_flags"                        : ["VISITED","CHIMERA_INTERNAL_BOUNDARY"],\n                        "element_data_value_variables"       : [],\n                        "condition_data_value_variables"     : []\n                    }\n                }]\n            }"""\n    )', False, 'import KratosMultiphysics\n')]