Beispiel #1
0
def CreateSolver(model_part, config):

    structural_solver = StructuralSolver(model_part, config.domain_size)

    # definition of the convergence criteria
    if(hasattr(config, "convergence_criterion")):
        structural_solver.convergence_criterion_type = config.convergence_criterion
    if(hasattr(config, "displacement_relative_tolerance")):
        structural_solver.rel_disp_tol = config.displacement_relative_tolerance
    if(hasattr(config, "displacement_absolute_tolerance")):
        structural_solver.abs_disp_tol = config.displacement_absolute_tolerance
    if(hasattr(config, "residual_relative_tolerance")):
        structural_solver.rel_res_tol = config.residual_relative_tolerance
    if(hasattr(config, "residual_absolute_tolerance")):
        structural_solver.abs_res_tol = config.residual_absolute_tolerance
    if(hasattr(config, "max_iteration")):
        structural_solver.max_iters = config.max_iteration

    # definition of the global solver type
    if(hasattr(config, "scheme_type")):
        structural_solver.scheme_type = config.scheme_type

    # definition of the solver parameters
    if(hasattr(config, "ComputeReactions")):
        structural_solver.compute_reactions = config.ComputeReactions  # bool
    if(hasattr(config, "ComputeContactForces")):
        structural_solver.compute_contact_forces = config.ComputeContactForces  # bool
    if(hasattr(config, "ReformDofSetAtEachStep")):
        structural_solver.reform_step_dofs = config.ReformDofSetAtEachStep  # bool
    if(hasattr(config, "RotationDofs")):
        structural_solver.rotation_dofs = config.RotationDofs  # bool
    if(hasattr(config, "PressureDofs")):
        structural_solver.pressure_dofs = config.PressureDofs  # bool
    if(hasattr(config, "LineSearch")):
        structural_solver.line_search = config.LineSearch  # bool
    if(hasattr(config, "Implex")):
        structural_solver.implex = config.Implex  # bool
    if(hasattr(config, "ComponentWise")):
        structural_solver.component_wise = config.ComponentWise  # bool

    # definition of the echo level
    if(hasattr(config, "echo_level")):
        structural_solver.echo_level = config.echo_level

    # definition of the linear solver
    import linear_solver_factory
    if(hasattr(config, "linear_solver_config")):
        print("Linear Solver Set", config.linear_solver_config.solver_type)
        structural_solver.linear_solver = linear_solver_factory.ConstructSolver(config.linear_solver_config)

        if(config.linear_solver_config.solver_type == "AMGCL"):
            structural_solver.block_builder = True
        else:
            structural_solver.block_builder = False

    return structural_solver
    def __init__(self, main_model_part, custom_settings):

        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.main_model_part = main_model_part

        ##settings string in json format
        default_settings = Parameters("""
        {
            "solver_type": "solid_mechanics_implicit_dynamic_solver",
            "model_import_settings": {
                "input_type": "mdpa",
                "input_filename": "unknown_name"
            },
            "echo_level": 0,
            "time_integration_method": "Implicit",
            "analysis_type": "nonlinear",
            "rotation_dofs": false,
            "pressure_dofs": false,
            "stabilization_factor": 1.0,
            "reform_dofs_at_each_iteration": false,
            "line_search": false,
            "compute_reactions": true,
            "compute_contact_forces": false,
            "block_builder": false,
            "component_wise": false,
            "move_mesh_flag": true,
            "solution_type": "Dynamic",
            "scheme_type": "Newmark",
            "convergence_criterion": "Residual_criteria",
            "displacement_relative_tolerance": 1.0e-4,
            "displacement_absolute_tolerance": 1.0e-9,
            "residual_relative_tolerance": 1.0e-4,
            "residual_absolute_tolerance": 1.0e-4,
            "max_iteration": 10,
            "linear_solver_settings":{
                "solver_type": "Super LU",
                "max_iteration": 500,
                "tolerance": 1e-9,
                "scaling": false,
                "verbosity": 1
            },
            "processes_sub_model_part_list": [""],
            "problem_domain_sub_model_part_list": ["solid_model_part"]
        }
        """)

        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        #construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        print("Construction of MechanicalSolver finished")
Beispiel #3
0
def CreateSolver(model_part, config):
    convection_solver = PFEM2ConvectionDiffusionSolver(model_part,
                                                       config.domain_size)
    # linear solver settings
    import linear_solver_factory
    if (hasattr(config, "convection_linear_solver_config")):
        self.linear_solver = linear_solver_factory.ConstructSolver(
            config.convection_linear_solver_config)

    return convection_solver
Beispiel #4
0
def CreateSolver(model_part, config):
    solver = LaplacianSolver(model_part, config.domain_size)


    import linear_solver_factory
    if(hasattr(config, "linear_solver_config")):
        solver.linear_solver = linear_solver_factory.ConstructSolver(
            config.linear_solver_config)

    return solver
    def __init__(self, model_part,
                 custom_settings):  # Constructor of the class
        self.model_part = model_part
        self.domain_size = self.model_part.ProcessInfo[
            KratosMultiphysics.DOMAIN_SIZE]

        ##settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type"                  : "shallow_water_base_solver",
            "model_import_settings"        : {
                "input_type"          : "mdpa",
                "input_filename"      : "unknown_name"
            },
            "echo_level"                   : 0,
            "convergence_echo_level"       : 1,
            "solver_echo_level"            : 0,
            "buffer_size"                  : 2,
            "dynamic_tau"                  : 0.005,
            "relative_tolerance"           : 1e-6,
            "absolute_tolerance"           : 1e-9,
            "maximum_iterations"           : 20,
            "compute_reactions"            : false,
            "reform_dofs_at_each_step"     : false,
            "calculate_norm_dx"            : true,
            "move_mesh_flag"               : false,
            "volume_model_part_name"       : "volume_model_part",
            "linear_solver_settings"       : {
                    "solver_type"     : "SkylineLUFactorizationSolver"
            },
            "time_stepping"                : {
                "automatic_time_step" : false,
                "time_step"           : 0.01
            },
            "pfem2_settings"               : {
                "convection_scalar_variable"    : "HEIGHT",
                "convection_vector_variable"    : "VELOCITY",
                "maximum_number_of_particles"   : 16
            }
        }""")
        default_settings["pfem2_settings"][
            "maximum_number_of_particles"].SetInt(8 * self.domain_size)

        ## Overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        ## Construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        # Initialize shallow water variables utility
        self.ShallowVariableUtils = KratosShallow.ShallowWaterVariablesUtility(
            self.model_part)
    def __init__(self, main_model_part, custom_settings):

        #TODO: shall obtain the computing_model_part from the MODEL once the object is implemented
        self.main_model_part = main_model_part

        #TODO: remove unnecessary fields for the Explicit solver from the defaults
        ##settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type": "solid_mechanics_explicit_dynamic_solver",
            "echo_level": 0,
            "buffer_size": 2,
            "solution_type": "Dynamic",
            "time_integration_method": "Explicit",
            "scheme_type": "CentralDifferences",
            "model_import_settings": {
                "input_type": "mdpa",
                "input_filename": "unknown_name",
                "input_file_label": 0
            },
            "rotation_dofs": false,
            "pressure_dofs": false,
            "stabilization_factor": 1.0,
            "reform_dofs_at_each_step": false,
            "compute_reactions": true,
            "move_mesh_flag": true,
            "clear_storage": false,
            "max_delta_time": 1.0e-5,
            "fraction_delta_time": 0.9,
            "time_step_prediction_level": 0,
            "rayleigh_damping": false,
            "linear_solver_settings":{
                "solver_type": "SuperLUSolver",
                "max_iteration": 500,
                "tolerance": 1e-9,
                "scaling": false,
                "verbosity": 1
            },
            "bodies_list": [],
            "problem_domain_sub_model_part_list": ["solid_model_part"],
            "processes_sub_model_part_list": [""]
        }
        """)

        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        #construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        print("Construction of Explicit Dynamics Mechanical Solver finished")
Beispiel #7
0
    def __init__(self, model_part, custom_settings):
        self.MoveMeshFlag = False

        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.main_model_part = model_part

        ##settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type": "potential_flow_solver",
            "echo_level": 1,
            "relative_tolerance": 1e-5,
            "absolute_tolerance": 1e-9,
            "maximum_iterations": 1,
            "compute_reactions": false,
            "compute_condition_number": false,
            "reform_dofs_at_each_step": false,
            "calculate_solution_norm" : false,
            "volume_model_part_name" : "volume_model_part",
            "skin_parts":[],
            "no_skin_parts"                : [],
            "model_import_settings": {
                    "input_type": "mdpa",
                    "input_filename": "unknown_name"
            },
            "element_replace_settings": {
                    "element_name":"CompressiblePotentialFlowElement2D3N",
                    "condition_name": "PotentialWallCondition2D2N"
            },
            "linear_solver_settings": {
                    "solver_type": "AMGCL",
                    "max_iteration": 400,
                    "gmres_krylov_space_dimension": 100,
                    "smoother_type":"ilu0",
                    "coarsening_type":"ruge_stuben",
                    "coarse_enough" : 5000,
                    "krylov_type": "lgmres",
                    "tolerance": 1e-9,
                    "verbosity": 3,
                    "scaling": false
            }
        }""")

        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        #construct the linear solvers
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        print("Construction of LaplacianSolver finished")
    def __init__(self, model_part, custom_settings):

        # default settings for structural similarity mesh solver
        default_settings = Parameters("""
        {
        "solver_type"                  : "mesh_solver_structural_similarity",
        "model_import_settings"        : {
            "input_type"     : "mdpa",
            "input_filename" : "unknown_name"
        },
        "ale_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
        },
        "volume_model_part_name"       : "volume_model_part",
        "time_order"                 : 2,
        "mesh_reform_dofs_each_step" : false,
        "mesh_compute_reactions"     : false
        }""")

        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        # set parameters
        self.model_part = model_part
        self.time_order = custom_settings["time_order"].GetInt()
        self.mesh_compute_reactions = custom_settings[
            "mesh_compute_reactions"].GetBool()
        self.mesh_reform_dofs_each_step = custom_settings[
            "mesh_reform_dofs_each_step"].GetBool()

        # neighbour search
        number_of_avg_elems = 10
        number_of_avg_nodes = 10
        self.neighbour_search = FindNodalNeighboursProcess(
            model_part, number_of_avg_elems, number_of_avg_nodes)

        # definition of the solvers
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["ale_linear_solver_settings"])
        print("Construction of MeshSolverStructuralSimilarity finished")
Beispiel #9
0
    def __init__(self, model, custom_settings):
        super(NavierStokesSolverFractionalStep,
              self).__init__(model, custom_settings)

        self.element_name = "FractionalStep"
        self.condition_name = "WallCondition"
        self.min_buffer_size = 3

        # There is only a single rank in OpenMP, we always print
        self._is_printing_rank = True

        ## Construct the linear solvers
        import linear_solver_factory
        self.pressure_linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["pressure_linear_solver_settings"])
        self.velocity_linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["velocity_linear_solver_settings"])

        self.compute_reactions = self.settings["compute_reactions"].GetBool()

        KratosMultiphysics.Logger.PrintInfo(
            "NavierStokesSolverFractionalStep",
            "Construction of NavierStokesSolverFractionalStep solver finished."
        )
Beispiel #10
0
    def __init__(self, model_part, settings):

        self.model_part = model_part

        #note that all settingsuration parameters MUST be passed.
        self.domain_size = settings.domain_size
        self.rel_vel_tol = settings.vel_tolerance
        self.abs_vel_tol = settings.abs_vel_tolerance
        self.rel_pres_tol = settings.press_tolerance
        self.abs_pres_tol = settings.abs_press_tolerance
        self.dynamic_tau = settings.dynamic_tau
        self.max_iter = settings.max_iteration
        self.echo_level = settings.echo_level
        self.compute_reactions = settings.compute_reactions
        self.reform_dofs_at_each_step = settings.reform_dofs_at_each_step

        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            settings.linear_solver_settings)

        self.bdf_process = kratoscore.ComputeBDFCoefficientsProcess(
            model_part, 2)

        self.conv_criteria = incompressibleapp.VelPrCriteria(
            self.rel_vel_tol, self.abs_vel_tol, self.rel_pres_tol,
            self.abs_pres_tol)

        (self.conv_criteria).SetEchoLevel(self.echo_level)

        self.time_scheme = kratoscore.ResidualBasedIncrementalUpdateStaticScheme(
        )

        builder_and_solver = kratoscore.ResidualBasedBlockBuilderAndSolver(
            self.linear_solver)

        move_mesh_flag = False  #user should NOT configure this
        self.fluid_solver = kratoscore.ResidualBasedNewtonRaphsonStrategy(
            self.model_part, self.time_scheme, self.linear_solver,
            self.conv_criteria, builder_and_solver, self.max_iter,
            self.compute_reactions, self.reform_dofs_at_each_step,
            move_mesh_flag)
        (self.fluid_solver).SetEchoLevel(self.echo_level)
        self.fluid_solver.Check()

        self.model_part.ProcessInfo.SetValue(kratoscore.DYNAMIC_TAU,
                                             self.dynamic_tau)

        print("Construction stokes solver finished")
Beispiel #11
0
def CreateSolver(model_part, config, periodic=False):
    fluid_solver = MonolithicSolver(model_part, config.domain_size, periodic)

    if(hasattr(config, "alpha")):
        fluid_solver.alpha = config.alpha

    # definition of the convergence criteria
    if(hasattr(config, "velocity_relative_tolerance")):
        fluid_solver.rel_vel_tol = config.velocity_relative_tolerance
    if(hasattr(config, "velocity_absolute_tolerance")):
        fluid_solver.abs_vel_tol = config.velocity_absolute_tolerance
    if(hasattr(config, "pressure_relative_tolerance")):
        fluid_solver.rel_pres_tol = config.pressure_relative_tolerance
    if(hasattr(config, "pressure_absolute_tolerance")):
        fluid_solver.abs_pres_tol = config.pressure_absolute_tolerance
    if(hasattr(config, "dynamic_tau")):
        fluid_solver.dynamic_tau = config.dynamic_tau
    if(hasattr(config, "oss_switch")):
        fluid_solver.oss_switch = config.oss_switch
    if(hasattr(config, "max_iteration")):
        fluid_solver.max_iter = config.max_iteration
    if(hasattr(config, "echo_level")):
        fluid_solver.echo_level = config.echo_level
    if(hasattr(config, "compute_reactions")):
        fluid_solver.compute_reactions = config.compute_reactions
    if(hasattr(config, "ReformDofSetAtEachStep")):
        fluid_solver.ReformDofSetAtEachStep = config.ReformDofSetAtEachStep
    if(hasattr(config, "divergence_cleareance_step")):
        fluid_solver.divergence_clearance_steps = config.divergence_cleareance_step
    if hasattr(config, "TurbulenceModel"):
        if config.TurbulenceModel == "Spalart-Allmaras":
            fluid_solver.use_spalart_allmaras = True
        elif config.TurbulenceModel == "Smagorinsky-Lilly":
            if hasattr(config, "SmagorinskyConstant"):
                fluid_solver.activate_smagorinsky(config.SmagorinskyConstant)
            else:
                msg = """Fluid solver error: Smagorinsky model requested, but
                         the value for the Smagorinsky constant is
                         undefined."""
                raise Exception(msg)

    import linear_solver_factory
    if(hasattr(config, "linear_solver_config")):
        fluid_solver.linear_solver = linear_solver_factory.ConstructSolver(
            config.linear_solver_config)

    return fluid_solver
Beispiel #12
0
    def setUpSolvers(self):

        # Building custom fluid solver
        self.fluid_solver = vms_monolithic_solver.MonolithicSolver(
            self.fluid_model_part, self.domain_size)
        rel_vel_tol = 1e-5
        abs_vel_tol = 1e-7
        rel_pres_tol = 1e-5
        abs_pres_tol = 1e-7
        self.fluid_solver.conv_criteria = VelPrCriteria(
            rel_vel_tol, abs_vel_tol, rel_pres_tol, abs_pres_tol)
        self.fluid_solver.conv_criteria.SetEchoLevel(0)

        alpha = -0.3
        move_mesh = 0
        self.fluid_solver.time_scheme = ResidualBasedPredictorCorrectorVelocityBossakSchemeTurbulent(
            alpha, move_mesh, self.domain_size)
        import linear_solver_factory
        self.fluid_solver.linear_solver = linear_solver_factory.ConstructSolver(
            Parameters(r'''{
                "solver_type" : "AMGCL"
            }'''))
        builder_and_solver = ResidualBasedBlockBuilderAndSolver(
            self.fluid_solver.linear_solver)
        self.fluid_solver.max_iter = 50
        self.fluid_solver.compute_reactions = False
        self.fluid_solver.ReformDofSetAtEachStep = False
        self.fluid_solver.MoveMeshFlag = False

        self.fluid_solver.solver = ResidualBasedNewtonRaphsonStrategy(\
                self.fluid_model_part,
                self.fluid_solver.time_scheme,
                self.fluid_solver.linear_solver,
                self.fluid_solver.conv_criteria,
                builder_and_solver,
                self.fluid_solver.max_iter,
                self.fluid_solver.compute_reactions,
                self.fluid_solver.ReformDofSetAtEachStep,
                self.fluid_solver.MoveMeshFlag)

        self.fluid_solver.solver.SetEchoLevel(0)
        self.fluid_solver.solver.Check()

        self.fluid_model_part.ProcessInfo.SetValue(OSS_SWITCH, self.oss_switch)

        self.fluid_solver.divergence_clearance_steps = 0
        self.fluid_solver.use_slip_conditions = 0
Beispiel #13
0
    def __init__(self, main_model_part, custom_settings): 
        
        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.main_model_part = main_model_part    
        
        ##settings string in json format
        default_settings = kratoscore.Parameters("""
        {
            "solver_type": "stokes_solver_monolithic",
            "force_steady_state": false,
            "velocity_tolerance": 1e-3,
            "pressure_tolerance": 1e-2,
            "absolute_velocity_tolerance": 1e-3,
            "absolute_pressure_tolerance": 1e-2,
            "maximum_iterations": 3,
            "echo_level": 1,
            "consider_periodic_conditions": false,
            "time_order": 2,
            "dynamic_tau": 0.001,
            "compute_reactions": false,
            "reform_dofs_at_each_step": false,
            "volume_model_part_name" : "volume_model_part",
            "skin_parts":[""],
            "model_import_settings": {
                    "input_type": "mdpa",
                    "input_filename": "unknown_name"
            },
            "linear_solver_settings": {
                    "solver_type": "Super LU",
                    "max_iteration": 500,
                    "tolerance": 1e-9,
                    "scaling": false,
                    "verbosity": 1
            }
        }""")
        
        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)
        
        #construct the linear solvers
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"])


        print("Construction of NavierStokesSolver_FractionalStep finished")
Beispiel #14
0
    def __init__(self, main_model_part, custom_settings):

        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.main_model_part = main_model_part

        ##settings string in json format
        default_settings = kratoscore.Parameters("""
        {
            "solver_type": "static_structural_solver",
            "problem_is_linear": false,
            "convergence_criteria_settings": {
                "criteria_type" : "DisplacementCriteria",
                "parameters" : {
                    "relative_tolerance" : 1e-6,
                    "absolute_tolerance" : 1e-9
                }
            }
            "maximum_iterations": 3,
            "echo_level": 1,
            "compute_reactions": true,
            "reform_dofs_at_each_iteration": false,
            "volume_model_part_name" : "volume_model_part",
            "skin_parts":[""],
            "model_import_settings": {
                    "input_type": "mdpa",
                    "input_filename": "unknown_name"
            },
            "linear_solver_settings": {
                    "solver_type": "Super LU",
                    "max_iteration": 500,
                    "tolerance": 1e-9,
                    "scaling": false,
                    "verbosity": 1
            }
        }""")

        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        #construct the linear solvers
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        print("Construction of NavierStokesSolver_FractionalStep finished")
    def __init__(self, model, custom_settings):
        super(NavierStokesCompressibleSolver,self).__init__(model,custom_settings)

        self.element_name = "CompressibleNavierStokes"
        self.condition_name = "Condition"
        self.min_buffer_size = 3

        # There is only a single rank in OpenMP, we always print
        self._is_printing_rank = True

        ## Construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"])

        ## Set the element replace settings
        #self._SetCompressibleElementReplaceSettings()

        print("Construction of NavierStokesCompressibleSolver finished.")
Beispiel #16
0
    def setUpSolvers(self):

        # Building custom fluid solver
        self.fluid_solver = vms_monolithic_solver.MonolithicSolver(
            self.fluid_model_part, self.domain_size)
        rel_vel_tol = 1e-5
        abs_vel_tol = 1e-7
        rel_pres_tol = 1e-5
        abs_pres_tol = 1e-7
        self.fluid_solver.conv_criteria = VelPrCriteria(
            rel_vel_tol, abs_vel_tol, rel_pres_tol, abs_pres_tol)
        self.fluid_solver.conv_criteria.SetEchoLevel(0)

        self.fluid_solver.time_scheme = ResidualBasedIncrementalUpdateStaticScheme(
        )
        import linear_solver_factory
        self.fluid_solver.linear_solver = linear_solver_factory.ConstructSolver(
            Parameters(r'''{
                "solver_type" : "AMGCL"
            }'''))
        builder_and_solver = ResidualBasedBlockBuilderAndSolver(
            self.fluid_solver.linear_solver)
        self.fluid_solver.max_iter = 50
        self.fluid_solver.compute_reactions = False
        self.fluid_solver.ReformDofSetAtEachStep = False
        self.fluid_solver.MoveMeshFlag = False

        self.fluid_solver.solver = ResidualBasedNewtonRaphsonStrategy(\
                self.fluid_model_part,
                self.fluid_solver.time_scheme,
                self.fluid_solver.linear_solver,
                self.fluid_solver.conv_criteria,
                builder_and_solver,
                self.fluid_solver.max_iter,
                self.fluid_solver.compute_reactions,
                self.fluid_solver.ReformDofSetAtEachStep,
                self.fluid_solver.MoveMeshFlag)

        self.fluid_solver.solver.SetEchoLevel(0)

        self.fluid_solver.solver.Check()

        self.fluid_solver.divergence_clearance_steps = 0
        self.fluid_solver.use_slip_conditions = 0
def CreateSolver(model_part, config):
    conv_diff_solver = ConvectionDiffusionSolver(model_part,
                                                 config.domain_size, config)

    # default settings
    if (hasattr(config, "domain_size")):
        conv_diff_solver.domain_size = config.domain_size
    if (hasattr(config, "ReformDofAtEachIteration")):
        conv_diff_solver.ReformDofAtEachIteration = config.ReformDofAtEachIteration
    if (hasattr(config, "echo_level")):
        conv_diff_solver.echo_level = config.echo_level

    # linear solver settings
    import linear_solver_factory
    if (hasattr(config, "linear_solver_config")):
        conv_diff_solver.linear_solver = linear_solver_factory.ConstructSolver(
            config.linear_solver_config)

    return conv_diff_solver
def CreateSolver(model_part, config, eul_model_part, gamma, contact_angle,
                 zeta_dissapative_JM, zeta_dissapative_BM,
                 zeta_dissapative_SM):  #FOR 3D!
    fluid_solver = STMonolithicSolver(model_part, config.domain_size,
                                      eul_model_part, gamma, contact_angle,
                                      zeta_dissapative_JM, zeta_dissapative_BM,
                                      zeta_dissapative_SM)

    if (hasattr(config, "alpha")):
        fluid_solver.alpha = config.alpha

    if (hasattr(config, "eul_model_part")):
        fluid_solver.eulerian_model_part = config.eul_model_part

    # definition of the convergence criteria
    if (hasattr(config, "velocity_relative_tolerance")):
        fluid_solver.rel_vel_tol = config.velocity_relative_tolerance
    if (hasattr(config, "velocity_absolute_tolerance")):
        fluid_solver.abs_vel_tol = config.velocity_absolute_tolerance
    if (hasattr(config, "pressure_relative_tolerance")):
        fluid_solver.rel_pres_tol = config.pressure_relative_tolerance
    if (hasattr(config, "pressure_absolute_tolerance")):
        fluid_solver.abs_pres_tol = config.pressure_absolute_tolerance
    if (hasattr(config, "dynamic_tau")):
        fluid_solver.dynamic_tau = config.dynamic_tau
    if (hasattr(config, "max_iteration")):
        fluid_solver.max_iter = config.max_iteration
    if (hasattr(config, "echo_level")):
        fluid_solver.echo_level = config.echo_level
    if (hasattr(config, "compute_reactions")):
        fluid_solver.compute_reactions = config.compute_reactions
    if (hasattr(config, "ReformDofSetAtEachStep")):
        fluid_solver.ReformDofSetAtEachStep = config.ReformDofSetAtEachStep
    if (hasattr(config, "divergence_cleareance_step")):
        fluid_solver.divergence_clearance_steps = config.divergence_cleareance_step

    import linear_solver_factory
    if (hasattr(config, "linear_solver_config")):
        fluid_solver.linear_solver = linear_solver_factory.ConstructSolver(
            config.linear_solver_config)

    return fluid_solver
Beispiel #19
0
def Analyzer(controls, response, opt_itr):

    # Create object to analyze structure response functions if required
    response_analyzer = StructureResponseFunctionUtilities(main_model_part)

    # Create object to analyze sensitivities if required (dummy linear solver for future adjoint sensitivity analysis)
    import linear_solver_factory
    linear_solver = linear_solver_factory.ConstructSolver(
        ProjectParameters["solver_settings"]["linear_solver_settings"])
    sensitivity_solver = StructureAdjointSensitivityStrategy(
        main_model_part, linear_solver,
        ProjectParameters["problem_data"]["domain_size"].GetInt())

    # Compute objective function value Call the Solid Mechanics Application to compute objective function value
    if (controls["strain_energy"]["calc_func"]):

        # Compute structure solution to get displacement field u
        print("::[START Kratos Solid Mechanics Application]::")
        solve_structure(opt_itr)

        # Calculate objective function value based on u and save into container
        print("\n::[Objective Function Calculation]::")
        response["strain_energy"][
            "func"] = response_analyzer.ComputeStrainEnergy()

    # Compute constraint function value
    if (controls["volume_fraction"]["calc_func"]):
        print("\n::[Constraint Function Calculation]::")
        target_volume_fraction = opt_parameters.initial_volume_fraction
        response["volume_fraction"][
            "func"] = response_analyzer.ComputeVolumeFraction(
            ) - target_volume_fraction

    # Compute sensitivities of objective function
    if (controls["strain_energy"]["calc_grad"]):
        print("\n::[Objective sensitivity computation]::")
        sensitivity_solver.ComputeStrainEnergySensitivities()

    # Compute sensitivities of constraint function
    if (controls["volume_fraction"]["calc_grad"]):
        print("\n::[Constraint sensitivity computation]::")
        sensitivity_solver.ComputeVolumeFractionSensitivities()
    def __init__(self, main_model_part, custom_settings):

        self.main_model_part = main_model_part

        # default settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type" : "adjoint_vmsmonolithic_solver",
            "scheme_settings" : {
                "scheme_type" : "bossak"
            },
            "response_function_settings" : {
                "response_type" : "drag"
            },
            "model_import_settings" : {
                "input_type"     : "mdpa",
                "input_filename" : "unknown_name"
            },
            "linear_solver_settings" : {
                "solver_type" : "AMGCL"
            },
            "volume_model_part_name" : "volume_model_part",
            "skin_parts"  : [""],
            "no_skin_parts"  : [""],
            "dynamic_tau" : 0.0,
            "oss_switch"  : 0,
            "echo_level"  : 0,
            "time_stepping"               : {
                "automatic_time_step" : false,
                "time_step"           : -0.1
        }
        }""")

        # overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        # construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"])

        print("Construction of AdjointVMSMonolithicSolver finished")
Beispiel #21
0
    def __init__(self, model, custom_settings):
        super(AdjointVMSMonolithicSolver,
              self).__init__(model, custom_settings)

        # There is only a single rank in OpenMP, we always print
        self._is_printing_rank = True

        self.element_name = "VMSAdjointElement"
        if self.settings["domain_size"].GetInt() == 2:
            self.condition_name = "LineCondition"
        elif self.settings["domain_size"].GetInt() == 3:
            self.condition_name = "SurfaceCondition"

        # construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        KratosMultiphysics.Logger.PrintInfo(
            self.__class__.__name__,
            "Construction of AdjointVMSMonolithicSolver finished.")
Beispiel #22
0
    def _linear_solver_predict(self):
        import linear_solver_factory
        linear_solver = linear_solver_factory.ConstructSolver(
            self.params["linear_solver_settings"])
        builder_and_solver = KratosMultiphysics.ResidualBasedBlockBuilderAndSolver(
            linear_solver)
        scheme = KratosMultiphysics.ResidualBasedIncrementalUpdateStaticScheme(
        )

        compute_reactions = True
        reform_step_dofs = True
        calculate_norm_dx = False
        move_mesh_flag = True
        strategy = KratosMultiphysics.ResidualBasedLinearStrategy(
            self.main_model_part, scheme, linear_solver, builder_and_solver,
            compute_reactions, reform_step_dofs, calculate_norm_dx,
            move_mesh_flag)
        strategy.SetEchoLevel(0)
        strategy.Check()
        strategy.Solve()
        strategy.Clear()
    def __init__(self, model_part, custom_settings):
        self.MoveMeshFlag = False

        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.main_model_part = model_part

        ##settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type": "laplacian_solver_newformat",
            "echo_level": 1,
            "relative_tolerance": 1e-5,
            "absolute_tolerance": 1e-9,
            "maximum_iterations": 10,
            "compute_reactions": false,
            "reform_dofs_at_each_iteration": false,
            "calculate_solution_norm" : false,
            "volume_model_part_name" : "volume_model_part",
            "skin_parts":[""],
            "model_import_settings": {
                    "input_type": "mdpa",
                    "input_filename": "unknown_name"
            },
            "linear_solver_settings": {
                    "solver_type": "AMGCL",
                    "max_iteration": 100,
                    "tolerance": 1e-6
            }
        }""")

        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        #construct the linear solvers
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        print("Construction of LaplacianSolver finished")
    def __init__(self, model, custom_settings):  # Constructor of the class
        settings = self._ValidateSettings(custom_settings)

        super(ShallowWaterBaseSolver, self).__init__(model, settings)

        # There is only a single rank in OpenMP, we always print
        self._is_printing_rank = True

        ## Set the element and condition names for the replace settings
        ## These should be defined in derived classes
        self.element_name = None
        self.condition_name = None
        self.min_buffer_size = 2

        # 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 specify a model_part name!')

        if self.model.HasModelPart(model_part_name):
            self.main_model_part = self.model.GetModelPart(model_part_name)
        else:
            self.main_model_part = KratosMultiphysics.ModelPart(
                model_part_name)
            self.model.AddModelPart(self.main_model_part)

        domain_size = self.settings["domain_size"].GetInt()
        self.main_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE, domain_size)

        ## Construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        # Initialize shallow water variables utility
        self.ShallowVariableUtils = Shallow.ShallowWaterVariablesUtility(
            self.main_model_part, self.settings["dry_height"].GetDouble())
Beispiel #25
0
    def Initialize(self):

        print("::[Pfem Fluid Explicit Solver]:: -START-")

        # Get the computing model part
        self.computing_model_part = self.GetComputingModelPart()

        #mechanical_scheme = KratosSolidMechanics.ExplicitCentralDifferencesScheme(self.settings["max_delta_time"].GetDouble(),
        #                                                                          self.settings["fraction_delta_time"].GetDouble(),
        #                                                                          self.settings["time_step_prediction_level"].GetDouble(),
        #                                                                          self.settings["rayleigh_damping"].GetBool())

        mechanical_scheme = KratosPfemFluid.FirstOrderForwardEulerScheme(
            1.0e-4, 1.0, 0, 0)
        import linear_solver_factory
        linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["velocity_linear_solver_settings"])
        #self.fluid_solver = KratosPfemFluid.ExplicitStrategy(self.computing_model_part,
        #                                                     mechanical_scheme,
        #                                                     linear_solver,
        #                                                     self.settings["compute_reactions"].GetBool(),
        #                                                     self.settings["reform_dofs_at_each_step"].GetBool(),
        #                                                     self.settings["move_mesh_flag"].GetBool())

        self.fluid_solver = KratosPfemFluid.ExplicitStrategy(
            self.computing_model_part, mechanical_scheme, linear_solver, False,
            True, True)
        # Set echo_level
        self.fluid_solver.SetEchoLevel(self.settings["echo_level"].GetInt())

        # Set initialize flag
        if (self.main_model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED]
                == True):
            self.mechanical_solver.SetInitializePerformedFlag(True)

        # Check if everything is assigned correctly
        self.fluid_solver.Check()

        print("::[Pfem Fluid  Explicit Solver]:: -END- ")
Beispiel #26
0
    def __init__(self, main_model_part, custom_settings):

        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.main_model_part = main_model_part

        ##settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type": "lagrangian_mpm_solver",
            "model_import_settings": {
                "input_type": "mdpa",
                "input_filename": "unknown_name"
            },
            "maximum_iterations": 10,
            "echo_level": 1,
            "compute_reactions": false,
            "reform_dofs_at_each_step": true,
            "relative_tolerance": 1e-5,
            "absolute_tolerance": 1e-7,
            "linear_solver_settings"        : {
                "solver_type" : "Super LU",
                "scaling": true
            },
            "processes_sub_model_part_list" : [""]
        }""")

        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        #self.EraseNodes = NodeEraseProcess(self.main_model_part)

        #construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        print("Construction of NavierStokesSolver_VMSMonolithic finished")
Beispiel #27
0
    def __init__(self, model, custom_settings):
        super(NavierStokesEmbeddedMonolithicSolver,
              self).__init__(model, custom_settings)

        self.element_name = "EmbeddedNavierStokes"
        self.condition_name = "NavierStokesWallCondition"
        self.min_buffer_size = 3

        # There is only a single rank in OpenMP, we always print
        self._is_printing_rank = True

        # TODO: Remove this once we finish the new implementations
        if (self.settings["solver_type"].GetString() == "EmbeddedDevelopment"):
            self.element_name = "EmbeddedSymbolicNavierStokes"

        # TODO: Remove this once we finish the new implementations
        if (self.settings["solver_type"].GetString() ==
                "EmbeddedAusasDevelopment"):
            self.settings["is_slip"].SetBool(True)
            self.element_name = "EmbeddedSymbolicNavierStokesDiscontinuous"

        ## Construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        ## Set the distance reading filename
        # TODO: remove the manual "distance_file_name" set as soon as the problem type one has been tested.
        if (self.settings["distance_reading_settings"]
            ["import_mode"].GetString() == "from_GiD_file"):
            self.settings["distance_reading_settings"][
                "distance_file_name"].SetString(
                    self.settings["model_import_settings"]
                    ["input_filename"].GetString() + ".post.res")

        KratosMultiphysics.Logger.PrintInfo(
            "NavierStokesEmbeddedMonolithicSolver",
            "Construction of NavierStokesEmbeddedMonolithicSolver finished.")
Beispiel #28
0
    def __init__(self, model_part, custom_settings):
        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.model_part = model_part

        ##settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type": "iga_structural_mechanics_solver",
            "model_import_settings": {
                "input_type": "txt",
                "input_filename": "unknown_name"
            },
            "maximum_iterations": 10,
            "echo_level": 1,
            "compute_reactions": false,
            "reform_dofs_at_each_iteration": true,
            "relative_tolerance": 1e-5,
            "absolute_tolerance": 1e-7,
            "linear_solver_settings"        : {
				"solver_type"   : "BiConjugate_gradient_stabilized",
				"max_iteration" : 500,
				"tolerance"     : 1e-9,
				"scaling"       : true,
				"verbosity"     : 0
            },
			"problem_domain_sub_model_part_list" : [],
			"processes_sub_model_part_list"      : [],
			"rotation_dofs"                      : "false"
        }""")

        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        #construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])
Beispiel #29
0
 def _create_linear_solver(self):
     import linear_solver_factory
     linear_solver = linear_solver_factory.ConstructSolver(
         self.settings["mesh_motion_linear_solver_settings"])
     return linear_solver
Beispiel #30
0
    def __init__(self, main_model_part, custom_settings):

        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.main_model_part = main_model_part

        ##settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type": "navier_stokes_solver_vmsmonolithic",
            "model_import_settings": {
                "input_type": "mdpa",
                "input_filename": "unknown_name"
            },
            "maximum_iterations": 10,
            "dynamic_tau": 0.01,
            "oss_switch": 0,
            "echo_level": 0,
            "consider_periodic_conditions": false,
            "compute_reactions": false,
            "reform_dofs_at_each_step": true,
            "relative_velocity_tolerance": 1e-3,
            "absolute_velocity_tolerance": 1e-5,
            "relative_pressure_tolerance": 1e-3,
            "absolute_pressure_tolerance": 1e-5,
            "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
            },
            "volume_model_part_name" : "volume_model_part",
            "skin_parts": [""],
            "no_skin_parts":[""],
            "time_stepping"                : {
                "automatic_time_step" : true,
                "CFL_number"          : 1,
                "minimum_delta_time"  : 1e-4,
                "maximum_delta_time"  : 0.01
            },
            "alpha":-0.3,
            "move_mesh_strategy": 0,
            "periodic": "periodic",
            "move_mesh_flag": false,
            "turbulence_model": "None",
            "reorder": false
        }""")

        ## Overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        ## Construct the linear solver
        import linear_solver_factory
        self.linear_solver = linear_solver_factory.ConstructSolver(
            self.settings["linear_solver_settings"])

        ## Set the element replace settings
        self.settings.AddEmptyValue("element_replace_settings")
        if (self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] ==
                3):
            self.settings[
                "element_replace_settings"] = KratosMultiphysics.Parameters("""
                {
                "element_name":"VMS3D4N",
                "condition_name": "MonolithicWallCondition3D"
                }
                """)
        elif (self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]
              == 2):
            self.settings[
                "element_replace_settings"] = KratosMultiphysics.Parameters("""
                {
                "element_name":"VMS2D3N",
                "condition_name": "MonolithicWallCondition2D"
                }
                """)
        else:
            raise Exception("domain size is not 2 or 3")

        print("Construction of NavierStokesSolver_VMSMonolithic finished")