We present here an example of use of the Parameter Data File. This powerful tool simplifies
for a user the introduction of input data specific to OFELI. The idea is very simple :
you have to write a text file following some simple rules and declare, in your code, an instance of class
IPF. Each parameter introduced in your file is then recovered from a specific member function
from your instance. We shall illustrate hereafter this through an example of a fluid flow code. Note that a precise
description of the input file can be found in this page.
An Input Data File
Consider the following text file:
#PARAM!
# Cavity test
Proj test
MaxTime 1000
TimeStep 0.01
Verbose 1
Output 0
Save 0
Tolerance 1.e-5
Plot 1000
Init 1
DoublePar 1 # Density
DoublePar 0.0001 # Viscosity
MeshFile test.m
AuxFile test.v
AuxFile test.sav
EOF
|
Let us make some comments about the structure of this file:
- A parameter file must start (first line, first column) by the string #PARAM!
- Comments are introduced between the character # and the end of a line.
- We give a project name through the keyword Proj. All input and output files will then have,
by default, this project name as a prefix, the extension depending on the nature of the file.
- An input parameter file contains two types of data: parameters which are integer and double precision numbers and
file names. There are some predefined parameters and file names, all the others must be given under a generic keyword.
For example : MaxTime, TimeStep, Verbose, ...
are predefined parameters.
- The last line of the file must be EOF.
In the program that uses such a file, we have the following lines:
IPF data(argv[1]);
double max_time = data.getMaxTime();
double deltat = data.getTimeStep();
int verbose = data.getVerbose();
int output_flag = data.getOutput();
int save_flag = data.getSave();
double tol = data.getTolerance();
int plot_flag = data.getPlot();
double dens = data.getDoublePar(1);
double visc = data.getDoublePar(2);
ms.Get(data.getMeshFile());
FDF vf(data.getAuxFile(1),"w");
FDF sf(data.getAuxFile(2),"w");
int init_flag = data.getInit();
In this way, all these parameters are retrieved in a finite element program without any
explicit i/o operation.