Skip to content

Python Script Tutorial: Reading ProjectParameters

Rubén Zorrilla edited this page May 30, 2018 · 12 revisions

The Kratos Parameters object is a container based on the well known JavaScript Object Notation (JSON) standard. Even though it can contain any type of key-value information, in Kratos it is used to contain configuration settings for solvers, processes or utilities.

In this tutorial, the use of the JSON format together with the Kratos Parameters class is reviewed using a standard Kratos simulation configuration file (ProjectParameters.json), in this case coming from the FluidDynamicsApplication, as example.

Setup

First of all we need to create a python file with following code to import the Kratos:

from KratosMultiphysics import *

Reading a JSON file

In this subsection we will try to parse the ProjectParameters.json file to construct the Kratos Parameters object. The ProjectParameters.json file reads as follows

{
    "problem_data"                     : {
        "problem_name"    : "parameters_tutorial",
        "model_part_name" : "MainModelPart",
        "domain_size"     : 2,
        "parallel_type"   : "OpenMP",
        "echo_level"      : 0,
        "start_time"      : 0.0,
        "end_time"        : 45
    },
    "output_configuration"             : {
        "result_file_configuration" : {
            "gidpost_flags"       : {
                "GiDPostMode"           : "GiD_PostBinary",
                "WriteDeformedMeshFlag" : "WriteDeformed",
                "WriteConditionsFlag"   : "WriteConditions",
                "MultiFileFlag"         : "SingleFile"
            },
            "file_label"          : "time",
            "output_control_type" : "step",
            "output_frequency"    : 1,
            "body_output"         : true,
            "node_output"         : false,
            "skin_output"         : false,
            "plane_output"        : [],
            "nodal_results"       : ["VELOCITY","PRESSURE"],
            "gauss_point_results" : []
        },
        "point_data_configuration"  : []
    },
    "restart_options"                  : {
        "SaveRestart"      : "False",
        "RestartFrequency" : 0,
        "LoadRestart"      : "False",
        "Restart_Step"     : 0
    },
    "solver_settings"                  : {
        "solver_type"                 : "Monolithic",
        "model_import_settings"       : {
            "input_type"     : "mdpa",
            "input_filename" : "parameters_tuto"
        },
        "echo_level"                  : 0,
        "compute_reactions"           : false,
        "dynamic_tau"                 : 1.0,
        "oss_switch"                  : 0,
        "maximum_iterations"          : 10,
        "relative_velocity_tolerance" : 0.001,
        "absolute_velocity_tolerance" : 1e-5,
        "relative_pressure_tolerance" : 0.001,
        "absolute_pressure_tolerance" : 1e-5,
        "volume_model_part_name"      : "Parts_Fluid",
        "skin_parts"                  : ["AutomaticInlet2D_Inlet","Outlet2D_Outlet","NoSlip2D_No_Slip_Walls","NoSlip2D_No_Slip_Cylinder"],
        "no_skin_parts"               : [],
        "time_stepping"               : {
            "automatic_time_step" : false,
            "time_step"           : 0.1
        }
    },
    "initial_conditions_process_list"  : [],
    "boundary_conditions_process_list" : [{
        "python_module" : "apply_inlet_process",
        "kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
        "Parameters"    : {
            "model_part_name" : "AutomaticInlet2D_Inlet",
            "variable_name"   : "VELOCITY",
            "modulus"         : "6*y*(1-y)*sin(pi*t*0.5)",
            "direction"       : "automatic_inwards_normal",
            "interval"        : [0,1]
        }
    },{
        "python_module" : "apply_inlet_process",
        "kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
        "Parameters"    : {
            "model_part_name" : "AutomaticInlet2D_Inlet",
            "variable_name"   : "VELOCITY",
            "modulus"         : "6*y*(1-y)",
            "direction"       : "automatic_inwards_normal",
            "interval"        : [1,"End"]
        }
    },{
        "python_module" : "apply_outlet_process",
        "kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
        "Parameters"    : {
            "model_part_name"    : "Outlet2D_Outlet",
            "variable_name"      : "PRESSURE",
            "constrained"        : true,
            "value"              : 0.0,
            "hydrostatic_outlet" : false,
            "h_top"              : 0.0
        }
    },{
        "python_module" : "apply_noslip_process",
        "kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
        "Parameters"    : {
            "model_part_name" : "NoSlip2D_No_Slip_Walls"
        }
    },{
        "python_module" : "apply_noslip_process",
        "kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
        "Parameters"    : {
            "model_part_name" : "NoSlip2D_No_Slip_Cylinder"
        }
    }],
    "gravity"                          : [{
        "python_module" : "assign_vector_by_direction_process",
        "kratos_module" : "KratosMultiphysics",
        "process_name"  : "AssignVectorByDirectionProcess",
        "Parameters"    : {
            "model_part_name" : "Parts_Fluid",
            "variable_name"   : "BODY_FORCE",
            "modulus"         : 0.0,
            "constrained"     : false,
            "direction"       : [0.0,-1.0,0.0]
        }
    }],
    "auxiliar_process_list"            : []
}

and can be parsed to construct a Kratos Parameters object with the next two lines of code

json_file = open("ProjectParameters.json",'r')
ProjectParameters = Parameters(json_file.read())

Project information

Getting Started

Tutorials

Developers

Kratos structure

Conventions

Solvers

Debugging, profiling and testing

HOW TOs

Utilities

Kratos API

Kratos Structural Mechanics API

Clone this wiki locally