How the GiD Graphical User Interface communicates with Kratos

From KratosWiki
Jump to: navigation, search

Contents

General Concepts

Any Graphical User Interface (GUI) for Kratos must be able to:

1- Generate the files which are necessary for Kratos to run. These files are usually .mdpa input files that contain the geometrical data, and other .py input files that contain parameters/options important for the run.

It is common to use the naming Case_nameFluid.mdpa, Case_nameStructural.mdpa for the .mdpa files, and ProjectParameters.py for the .py file.


2- Start the run by calling Python plus a main script.

It is common to have a KratosOpenMP.py as a main Python script when OpenMP parallelism has been chosen in the options, or KratosMPI.py when MPI parallelism has been chosen. Other similar options are possible.

Input files generation (GiD ProblemType language)

The GiD ProblemType language consists on a scripting language that allows the user to customize menus and templates that are able to print text files. Visit GiD's help for more information.

Input files generation (Tcl/Tk)

Tcl processes are able to gather all the information from GiD (menus and mesh entities) and print it to a set of text files.

Input files generation (CustomLib)

Since version 13, GiD features a new scripting language for cusomization. It's called CustomLib. Visit GiD's help for more information or access to the Kratos GiD Graphical User Interface Guide

Launching the calculation

When the user starts a calculation, GiD runs a .bat file located in the ProblemType folder. In Windows it will run Kratos.win.bat, in linux it will run Kratos.unix.bat

What these files do, essentially, is to set some OS environment variables to certain values, and when all these variables have been set, call python to start the calculation. Windows and linux are so different that they deserve different explanations:

In Windows

This is the usual content of Kratos.win.bat:

REM @ECHO OFF
REM Identification for arguments
REM basename                          = %1
REM Project directory                 = %2
REM Problem directory                 = %3
 
REM OutputFile: "%2\%1.info"
REM ErrorFile: "%2\%1.err"
 
DEL "%2\%1.info"
DEL "%2\%1.err"

REM Updathe PATH
set PATH=%3\\kratos;%3\\kratos\\libs;%PATH%

REM Set the number of threads for OpenMP
REM export OMP_NUM_THREADS=%5
set OMP_NUM_THREADS=%5

REM Run Python using the script KratosOpenMP.py
"%3\\kratos\\runkratos" KratosOpenMP.py > "%2\\%1.info" 2> "%2\\%1.err"

%1 is the name of the problem, like Case_name

%2 is the problem folder, like c:\My_path\Case_name.gid

%3 is the ProblemType folder, like c:\Program Files\GiD\GiD12.0.0\problemtypes\Kratos.gid

%5 is the number of processors chosen by the user for this problem


The sentence:

set OMP_NUM_THREADS=%5

sets the number of threads that OpenMP will use for this calculation. %5 is a parameter that GiD sends as an argument to Kratos.win.bat

The sentence:

"%3\\kratos\\runkratos" KratosOpenMP.py > "%2\\%1.info" 2> "%2\\%1.err"

Calls an executable called runkratos (which is Python, actually) and tells Python to use KratosOpenMP.py as the main script.

The screen output of this run will be written in %2\\%1.info and the error messages in %2\\%1.err

(%2 is the problem folder, like c:\My_path\Case_name.gid, and %1 is the name of the problem, like Case_name. So the screen output would be written in c:\My_path\Case_name.gid\Case_name.info and the errors in c:\My_path\Case_name.gid\Case_name.err)


In linux

This is the usual content of Kratos.unix.bat:

#!/bin/bash
# OutputFile: "$2/$1.info"
# ErrorFile: "$2/$1.err"
#delete previous result file 
rm -f "$2/$1*.post.bin" 
rm -f "$2/$1*.post.res" 
rm -f "$2/$1*.post.msh" 
rm -f "$2/$1.info"
rm -f "$2/$1.err"
rm -f "$2/$1.flavia.dat"

# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
fi

# gid redefines LD_LIBRARY_PATH to its own libs directory
# and maintains OLD_LD_LIBRARY_PATH with previous settings
# therefore, we use the OLD_LD_LIBRARY_PATH and prepend the path to the kratos libs
if [ "$OLD_LD_LIBRARY_PATH" != "" ]; then
    export LD_LIBRARY_PATH="$3/kratos":"$3/kratos/libs":$OLD_LD_LIBRARY_PATH
else
    # do not add the ':'
    export LD_LIBRARY_PATH="$3/kratos":"$3/kratos/libs"
fi

export PYTHONPATH="$3/kratos/python27.zip":"$3/kratos":$PYTHONPATH

# Set the number of threads for OpenMP
export OMP_NUM_THREADS=$5

# Run Python using the script KratosOpenMP.py
"$3/kratos/runkratos" KratosOpenMP.py > "$2/$1.info" 2> "$2/$1.err"

%1 is the name of the problem, like Case_name

%2 is the problem folder, like /home/my_user/My_path/Case_name.gid

%3 is the ProblemType folder, like /home/my_user/My_programs/Case_name.gid/GiD/GiD12.0.0/problemtypes/Kratos.gid

%5 is the number of processors chosen by the user for this problem


The sentence:

export LD_LIBRARY_PATH="$3/kratos":"$3/kratos/libs"

sets the value of the environment variable LD_LIBRARY_PATH. It is telling the OS where to find executable libraries that can be called from now on. These libraries will be, tipically, the Kratos C++ compiled code, which is located in "$3/kratos" and "$3/kratos/libs"

The sentence:

export PYTHONPATH="$3/kratos/python27.zip":"$3/kratos":$PYTHONPATH

sets the value of the variable PYTHONPATH. It is actually prepending two new values to the old ones (whatever they were), telling the OS that the first folders where Python must be searched must be "$3/kratos/python27.zip" and "$3/kratos". This is useful because Python can be packed inside the Problemtye in order to have no need of a preexisting installation of Python.

The sentence:

export OMP_NUM_THREADS=$5

sets the number of threads that OpenMP will use for this calculation. %5 is a parameter that GiD sends as an argument to Kratos.win.bat

The sentence:

"$3/kratos/runkratos" KratosOpenMP.py > "$2/$1.info" 2> "$2/$1.err"

Calls an executable called runkratos (which is Python, actually) and tells Python to use KratosOpenMP.py as the main script.

The screen output of this run will be written in $2/$1.info and the error messages in $2/$1.err

(%2 is the problem folder, like /home/my_user/My_path/Case_name.gid, and %1 is the name of the problem, like Case_name. So the screen output would be written in /home/my_user/My_path/Case_name.gid/Case_name.info and the errors in /home/my_user/My_path/Case_name.gid/Case_name.err)

Personal tools
Categories