コード例 #1
0
ファイル: python_solver.py プロジェクト: yasodhar008/Kratos
    def __init__(self, model, settings):
        """The constructor of the PythonSolver-Object.

        It is intended to be called from the constructor
        of deriving classes:
        super(DerivedSolver, self).__init__(settings)

        Keyword arguments:
        self -- It signifies an instance of a class.
        model -- The Model to be used
        settings -- The solver settings used
        """
        if not isinstance(model, KratosMultiphysics.Model):
            raise Exception(
                "Input is expected to be provided as a Kratos Model object")

        if not isinstance(settings, KratosMultiphysics.Parameters):
            raise Exception(
                "Input is expected to be provided as a Kratos Parameters object"
            )

        self.model = model
        self.settings = settings

        # TODO remove the check once the derived solvers implement this
        if hasattr(self, '_validate_settings_in_baseclass'):
            self.ValidateSettings()
        else:
            from KratosMultiphysics.kratos_utilities import IssueDeprecationWarning
            IssueDeprecationWarning(
                'PythonSolver',
                'the settings are not validated in the baseclass for solver "%s", please implement it'
                % (self.__class__.__name__))

        self.echo_level = self.settings["echo_level"].GetInt()
コード例 #2
0
    def __init__(self, model, custom_settings):
        if custom_settings.Has("calculate_mesh_velocities"):
            from KratosMultiphysics.kratos_utilities import IssueDeprecationWarning
            warn_msg  = 'Yor input-settings contain "calculate_mesh_velocities". This was removed from the solver and moved to MeshMovingApplication.MeshVelocityCalculationPlease update your code'
            IssueDeprecationWarning("MeshSolverBase", warn_msg)
            custom_settings.RemoveValue("calculate_mesh_velocities")

        self._validate_settings_in_baseclass=True # To be removed eventually
        super(MeshSolverBase,self).__init__(model, custom_settings)

        # Either retrieve the model part from the model or create a new one
        model_part_name = self.settings["model_part_name"].GetString()

        if model_part_name == "":
            raise Exception('Please provide the model part name as the "model_part_name" (string) parameter!')

        if self.model.HasModelPart(model_part_name):
            self.mesh_model_part = self.model.GetModelPart(model_part_name)
        else:
            self.mesh_model_part = model.CreateModelPart(model_part_name)

        domain_size = self.settings["domain_size"].GetInt()
        if domain_size == -1:
            raise Exception('Please provide the domain size as the "domain_size" (int) parameter!')

        self.mesh_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, domain_size)

        KratosMultiphysics.Logger.PrintInfo("::[MeshSolverBase]:: Construction finished")
コード例 #3
0
def GetRegisteredMPIMapperNames(*args):
    IssueDeprecationWarning(
        "MappingApplication",
        'GetRegisteredMPIMapperNames is deprecated, please use "MappingApplication.MPIExtension.MPIMapperFactory.GetRegisteredMapperNames" instead'
    )
    from KratosMultiphysics.MappingApplication.MPIExtension import MPIMapperFactory
    return MPIMapperFactory.GetRegisteredMapperNames(*args)
コード例 #4
0
    def validate_and_transfer_matching_settings(self, origin_settings, destination_settings):
        IssueDeprecationWarning('PythonSolver', '"validate_and_transfer_matching_settings" is deprecated, please use the functionalities provided by "GetDefaultSettings"')

        """Transfer matching settings from origin to destination.

        If a name in origin matches a name in destination, then the setting is
        validated against the destination.

        The typical use is for validating and extracting settings in derived classes:

        class A:
            def __init__(self, model_part, a_settings):
                default_a_settings = Parameters('''{
                    ...
                }''')
                a_settings.ValidateAndAssignDefaults(default_a_settings)
        class B(A):
            def __init__(self, model_part, custom_settings):
                b_settings = Parameters('''{
                    ...
                }''') # Here the settings contain default values.
                self.validate_and_transfer_matching_settings(custom_settings, b_settings)
                super().__init__(model_part, custom_settings)
        """
        for name, dest_value in destination_settings.items():
            if origin_settings.Has(name): # Validate and transfer value.
                orig_value = origin_settings[name]
                if dest_value.IsDouble() and orig_value.IsDouble():
                    destination_settings[name].SetDouble(origin_settings[name].GetDouble())
                elif dest_value.IsInt() and orig_value.IsInt():
                    destination_settings[name].SetInt(origin_settings[name].GetInt())
                elif dest_value.IsBool() and orig_value.IsBool():
                    destination_settings[name].SetBool(origin_settings[name].GetBool())
                elif dest_value.IsString() and orig_value.IsString():
                    destination_settings[name].SetString(origin_settings[name].GetString())
                elif dest_value.IsArray() and orig_value.IsArray():
                    if dest_value.size() != orig_value.size():
                        raise Exception('len("' + name + '") != ' + str(dest_value.size()))
                    for i in range(dest_value.size()):
                        if dest_value[i].IsDouble() and orig_value[i].IsDouble():
                            dest_value[i].SetDouble(orig_value[i].GetDouble())
                        elif dest_value[i].IsInt() and orig_value[i].IsInt():
                            dest_value[i].SetInt(orig_value[i].GetInt())
                        elif dest_value[i].IsBool() and orig_value[i].IsBool():
                            dest_value[i].SetBool(orig_value[i].GetBool())
                        elif dest_value[i].IsString() and orig_value[i].IsString():
                            dest_value[i].SetString(orig_value[i].GetString())
                        elif dest_value[i].IsSubParameter() and orig_value[i].IsSubParameter():
                            self.validate_and_transfer_matching_settings(orig_value[i], dest_value[i])
                            if len(orig_value[i].items()) != 0:
                                raise Exception('Json settings not found in default settings: ' + orig_value[i].PrettyPrintJsonString())
                        else:
                            raise Exception('Unsupported parameter type.')
                elif dest_value.IsSubParameter() and orig_value.IsSubParameter():
                    self.validate_and_transfer_matching_settings(orig_value, dest_value)
                    if len(orig_value.items()) != 0:
                        raise Exception('Json settings not found in default settings: ' + orig_value.PrettyPrintJsonString())
                else:
                    raise Exception('Unsupported parameter type.')
                origin_settings.RemoveValue(name)
コード例 #5
0
 def print_warning_on_rank_zero(self, *args):
     IssueDeprecationWarning(
         'PythonSolver',
         '"print_warning_on_rank_zero" is deprecated, please use the Logger directly'
     )
     # This function will be overridden in the trilinos-solvers
     KratosMultiphysics.Logger.PrintWarning(" ".join(map(str, args)))
コード例 #6
0
def HasMPIMapper(*args):
    IssueDeprecationWarning(
        "MappingApplication",
        'HasMPIMapper is deprecated, please use "MappingApplication.MPIExtension.MPIMapperFactory.HasMapper" instead'
    )
    from KratosMultiphysics.MappingApplication.MPIExtension import MPIMapperFactory
    return MPIMapperFactory.HasMapper(*args)
コード例 #7
0
 def Solve(self):
     warning_msg  = 'Using "Solve" is deprecated and will be removed in the future!\n'
     warning_msg += 'Use the separate calls to "Initialize", "InitializeSolutionStep", "Predict", '
     warning_msg += '"SolveSolutionStep" and "FinalizeSolutionStep"'
     IssueDeprecationWarning('PythonSolver', warning_msg)
     self.Initialize()
     self.InitializeSolutionStep()
     self.Predict()
     self.SolveSolutionStep()
     self.FinalizeSolutionStep()
コード例 #8
0
def Factory(settings, Model):
    if not isinstance(settings, KM.Parameters):
        raise Exception("Expected input shall be a Parameters object, encapsulating a json string")
    model_part = Model[settings["Parameters"]["model_part_name"].GetString()]
    output_name = settings["Parameters"]["output_name"].GetString()
    postprocess_parameters = settings["Parameters"]["postprocess_parameters"]

    IssueDeprecationWarning("GiDOutputProcessMPI",
        "Attempting to create deprecated process \"GiDOutputProcessMPI\",",
        "please use \"DistributedGiDOutputProcess\" in module KratosMultiphysics.mpi instead.")
    return DistributedGiDOutputProcess(model_part, output_name, postprocess_parameters)
コード例 #9
0
    def __init__(self, main_model_part, custom_settings):
        if custom_settings.Has("linear_solver_settings"):
            IssueDeprecationWarning(
                'EigenSolver',
                '"linear_solver_settings" was specified which is not used in the EigenSolver. Use "eigensolver_settings"!'
            )
            custom_settings.RemoveValue("linear_solver_settings")

        # Construct the base solver.
        super().__init__(main_model_part, custom_settings)
        KratosMultiphysics.Logger.PrintInfo("::[EigenSolver]:: ",
                                            "Construction finished")
コード例 #10
0
ファイル: analysis_stage.py プロジェクト: wacyyang/Kratos
 def __CheckIfSolveSolutionStepReturnsAValue(self, is_converged):
     """In case the solver does not return the state of convergence
     (same as the SolvingStrategy does) then issue ONCE a deprecation-warning
     """
     if is_converged is None:
         if not hasattr(self, '_map_ret_val_depr_warnings'):
             self._map_ret_val_depr_warnings = []
         solver_class_name = self._GetSolver().__class__.__name__
         # used to only print the deprecation-warning once
         if not solver_class_name in self._map_ret_val_depr_warnings:
             self._map_ret_val_depr_warnings.append(solver_class_name)
             warn_msg  = 'Solver "{}" does not return '.format(solver_class_name)
             warn_msg += 'the state of convergence from "SolveSolutionStep"'
             IssueDeprecationWarning("AnalysisStage", warn_msg)
コード例 #11
0
    def __init__(self, model, custom_settings):
        super(MeshSolverBase, self).__init__(model, custom_settings)

        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type"           : "mesh_solver_structural_similarity",
            "buffer_size"           : 1,
            "echo_level"            : 0,
            "domain_size"           : -1,
            "model_part_name"       : "",
            "time_stepping"         : { },
            "model_import_settings" : {
                "input_type"     : "mdpa",
                "input_filename" : "unknown_name"
            },
            "mesh_motion_linear_solver_settings" : {
                "solver_type" : "amgcl",
                "smoother_type":"ilu0",
                "krylov_type": "gmres",
                "coarsening_type": "aggregation",
                "max_iteration": 200,
                "provide_coordinates": false,
                "gmres_krylov_space_dimension": 100,
                "verbosity" : 0,
                "tolerance": 1e-7,
                "scaling": false,
                "block_size": 1,
                "use_block_matrices_if_possible" : true,
                "coarse_enough" : 5000
            },
            "time_order" : 2,
            "reform_dofs_each_step"     : false,
            "compute_reactions"         : false,
            "calculate_mesh_velocities" : true
        }""")

        self.settings.ValidateAndAssignDefaults(default_settings)

        if custom_settings["calculate_mesh_velocities"].GetBool():
            from KratosMultiphysics.kratos_utilities import IssueDeprecationWarning
            warn_msg = '"calculate_mesh_velocities" is set to true for the Solver\n'
            warn_msg += 'This feature was moved to MeshMovingApplication.MeshVelocityCalculation and will soon be removed\n'
            warn_msg += 'from the solver. Please update your code'
            IssueDeprecationWarning("MeshSolverBase", warn_msg)

        # Either retrieve the model part from the model or create a new one
        model_part_name = self.settings["model_part_name"].GetString()

        if model_part_name == "":
            raise Exception(
                'Please provide the model part name as the "model_part_name" (string) parameter!'
            )

        if self.model.HasModelPart(model_part_name):
            self.mesh_model_part = self.model.GetModelPart(model_part_name)
        else:
            self.mesh_model_part = model.CreateModelPart(model_part_name)

        domain_size = self.settings["domain_size"].GetInt()
        if domain_size == -1:
            raise Exception(
                'Please provide the domain size as the "domain_size" (int) parameter!'
            )

        self.mesh_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE, domain_size)

        self.print_on_rank_zero("::[MeshSolverBase]:: Construction finished")
コード例 #12
0
 def __init__(self, settings, solver_wrappers, process_info):
     IssueDeprecationWarning(
         'CreatePointLoadModelPart',
         'please use CreatePointBasedEntitiesProcess" instead')
     super().__init__(settings, process_info)
     self.model = solver_wrappers[self.settings["solver"].GetString()].model
コード例 #13
0
from KratosMultiphysics.kratos_utilities import IssueDeprecationWarning

IssueDeprecationWarning('EigenSolversApplication',
                        'please use the "LinearSolversApplication" instead')

from KratosMultiphysics.LinearSolversApplication import *
from KratosMultiphysics.LinearSolversApplication import dense_linear_solver_factory