コード例 #1
0
    def __init__(self, model, settings ):
        """The constructor of the BaseBenchmarkProcess.

        It is intended to be called from the constructor of deriving classes.
        """
        super().__init__()

        default_settings = KM.Parameters("""
            {
                "model_part_name"      : "model_part",
                "variables_list"       : [],
                "exact_variables_list" : [],
                "error_variables_list" : [],
                "benchmark_settings"   : {}
            }
            """
            )
        default_settings["benchmark_settings"] = self._GetBenchmarkDefaultSettings()
        settings.RecursivelyValidateAndAssignDefaults(default_settings)

        self.model_part = model[settings["model_part_name"].GetString()]

        self.variables = GenerateVariableListFromInput(settings["variables_list"])
        self.exact_variables = GenerateVariableListFromInput(settings["exact_variables_list"])
        self.error_variables = GenerateVariableListFromInput(settings["error_variables_list"])
        self.benchmark_settings = settings["benchmark_settings"]
コード例 #2
0
    def __init__(self, model, settings ):
        super(BaseBenchmarkProcess, self).__init__()

        default_settings = KM.Parameters("""
            {
                "model_part_name"      : "model_part",
                "variables_list"       : [],
                "exact_variables_list" : [],
                "error_variables_list" : [],
                "benchmark_settings"   : {}
            }
            """
            )
        settings.ValidateAndAssignDefaults(default_settings)

        self.model_part = model[settings["model_part_name"].GetString()]

        self.variables = GenerateVariableListFromInput(settings["variables_list"])
        self.exact_variables = GenerateVariableListFromInput(settings["exact_variables_list"])
        self.error_variables = GenerateVariableListFromInput(settings["error_variables_list"])
        self.benchmark_settings = settings["benchmark_settings"]
コード例 #3
0
    def __init__(self, Model, settings):
        """ VisualizationMeshProcess.

        This process provides several tools for post-procesing.
        - Generation of an auxiliar model part for the topography visualization as a separate file.
        - Setting the TOPOGRAPHY and FREE_SURFACE_ELEVATION into DISPLACEMENT_Z or Z-coordinate to view the mesh deformation.
        - Duplication of the properties to use them as a dry-wet flag.
        """

        KM.Process.__init__(self)

        default_settings = KM.Parameters("""
            {
                "model_part_name"                : "model_part_name",
                "topographic_model_part_name"    : "topographic_model_part",
                "create_topographic_model_part"  : true,
                "use_properties_as_dry_wet_flag" : false,
                "mesh_deformation_mode"          : "use_nodal_displacement",
                "wet_flag"                       : "FLUID",
                "topography_variable"            : "TOPOGRAPHY",
                "free_surface_variable"          : "FREE_SURFACE_ELEVATION",
                "nodal_variables_to_transfer"    : ["TOPOGRAPHY"],
                "nonhistorical_variables_to_transfer" : []
            }
            """)
        settings.ValidateAndAssignDefaults(default_settings)

        self.computing_model_part = Model[
            settings["model_part_name"].GetString()]

        # Getting the deformation mode options and storing the variable for the free surface
        mesh_deformation_mode = settings["mesh_deformation_mode"].GetString()
        if mesh_deformation_mode == "use_z_coordinate":
            self.deform_mesh = True
        elif mesh_deformation_mode == "use_nodal_displacement":
            self.deform_mesh = False
        else:
            msg = """VisualizationMeshProcess.
            Unkown 'mesh_deformation_mode'. The possible options are:
             - use_z_coordinate
             - use_nodal_displacement
            The input is {}
            """
            raise Exception(msg.format(mesh_deformation_mode))
        self.free_surface_variable = KM.KratosGlobals.GetVariable(
            settings["free_surface_variable"].GetString())

        # Creating the utility for the topographic model part management
        self.use_topographic_model_part = settings[
            "create_topographic_model_part"].GetBool()
        if self.use_topographic_model_part:
            self.topographic_model_part = Model.CreateModelPart(
                settings["topographic_model_part_name"].GetString())
            self.topography_utility = SW.ReplicateModelPartUtility(
                self.computing_model_part, self.topographic_model_part)
            self.nodal_variables = GenerateVariableListFromInput(
                settings["nodal_variables_to_transfer"])
            self.nonhistorical_variables = GenerateVariableListFromInput(
                settings["nonhistorical_variables_to_transfer"])
            self.topography_variable = KM.KratosGlobals.GetVariable(
                settings["topography_variable"].GetString())

        # The DefineAuxiliaryProperties method duplicates the current number of properties:
        # For each property, it creates another one, which means dry state.
        # It should be called only once, otherwise, the number of properties would increase exponentially
        self.use_properties_as_dry_wet_flag = settings[
            "use_properties_as_dry_wet_flag"].GetBool()
        if self.use_properties_as_dry_wet_flag:
            self.properties_utility = SW.PostProcessUtilities(
                self.computing_model_part)
            self.properties_utility.DefineAuxiliaryProperties()
            self.wet_flag = KM.KratosGlobals.GetFlag(
                settings["wet_flag"].GetString())
コード例 #4
0
    def SolveSolutionStep(self):
        num_coupling_interfaces = self.settings["coupling_interfaces"].size()

        self.__CustomPrint(
            1,
            colors.green("Starting import") + " of CouplingInterfaceData ...")

        for i in range(num_coupling_interfaces):
            coupling_interface_settings = self.settings["coupling_interfaces"][
                i]
            if not coupling_interface_settings.Has("data_field_recv"):
                continue
            sub_model_part_name = coupling_interface_settings[
                "sub_model_part_name"].GetString()
            data_field_settings = coupling_interface_settings[
                "data_field_recv"]

            data_field_name = data_field_settings["data_field_name"].GetString(
            )

            self.__CustomPrint(
                2,
                colors.green('Importing') +
                ' data-field "{}" on ModelPart "{}"'.format(
                    data_field_name, sub_model_part_name))

            variables = GenerateVariableListFromInput(
                data_field_settings["variables"])

            if not self.dry_run:
                KratosCoSim.EMPIRE_API.EMPIRE_API_recvDataField(
                    self.model["ExtSolver." + sub_model_part_name],
                    data_field_name,
                    *variables)  # passing all varibales from the list
            else:
                self.__CustomPrint(2, colors.magenta('... skipped'))

        self.__CustomPrint(
            1,
            colors.green("Finished import") + " of CouplingInterfaceData")

        if self.echo_level > 0: print()  # newline
        self.__CustomPrint(1, colors.blue("Solving ..."))
        time.sleep(self.solving_time)
        self.__CustomPrint(2,
                           "Solving took {} [sec]".format(self.solving_time))
        if self.echo_level > 0: print()  # newline
        # TODO implement random values ... ?

        self.__CustomPrint(
            1,
            colors.cyan("Starting export") + " of CouplingInterfaceData ...")

        for i in range(num_coupling_interfaces):
            coupling_interface_settings = self.settings["coupling_interfaces"][
                i]
            if not coupling_interface_settings.Has("data_field_send"):
                continue
            sub_model_part_name = coupling_interface_settings[
                "sub_model_part_name"].GetString()
            data_field_settings = coupling_interface_settings[
                "data_field_send"]

            data_field_name = data_field_settings["data_field_name"].GetString(
            )

            self.__CustomPrint(
                2,
                colors.cyan('Exporting') +
                ' data-field "{}" on ModelPart "{}"'.format(
                    data_field_name, sub_model_part_name))

            variables = GenerateVariableListFromInput(
                data_field_settings["variables"])

            if not self.dry_run:
                KratosCoSim.EMPIRE_API.EMPIRE_API_sendDataField(
                    self.model["ExtSolver." + sub_model_part_name],
                    data_field_name,
                    *variables)  # passing all varibales from the list
            else:
                self.__CustomPrint(2, colors.magenta('... skipped'))

        self.__CustomPrint(
            1,
            colors.cyan("Finished export") + " of CouplingInterfaceData")