• English
  • Русский (Russsian)

Basic utilities library ivutils

is free C++ library for numerical applications development. ivutils was used in EMTL (electromagnetic modeling) and Microvolt (semiconductor device modeling)

To use ivutils you need to download it and compile with your code: ivutils.zip

ivutils include:

h hpp cpp
n-dimensional vectors and linear transformations
vector_set packers for vector sequences
contour contours
2D and 3D geometrical objects
gnudump plotting of geometrical objects in gnuplot and VTK
grid uniform and uniform meshes to store and interpolate data
linsolv interface to solve system of linear equations using LAPACK and PARDISO
smart pointers to manage dynamic memory
math_utils useful math functions
utiltl useful iterators, modifiers etc.
seqpack data packers
logger interface for collecting process variables identified by their symbolic names
logexc interface to process exceptions and output messages
interface to record data in binary or text files
component configuration settings
timers to measure computer time used by chosen classes or functions
components to develop numerical applications
string_utils useful functions to work with strings
alg_parser parsers of algebraic expressions
read_ini parsers of simple ini-files
interface to work with MPI
qsub.py Script to run jobs at any supercomputer
Multi-Architectural Makefile

Below we give some examples how to use ivutils.

Geometry objects

Here we show how to construct some geometry objects.

Vector is constructed by class Vector_3 initialized by x, y and z coordinates in constructor. You can add and subtract vectors, multiply vector by number, calculate scalar product (using operator *) and cross product (using operator %) of two vectors. For example,

  Vector_3 v1(1,0,0),v2(0,1,0);
  Vector_3 v0=a%b-Vector_3(0,0,1); // v0 is Vector_3(0,0,0)

If you put less then 3 coordinates in constructor, then values for not specified coordinates well be equal to last specified ones. For example, Vector_3(1) is equal toVector_3(1,1,1). Also Vector_3() is equal to Vector_3(0,0,0) since first coordinate is zero by default.

Vectors for integer coordinates are constructed by class iVector_3.

All geometry classes are derived from the class Region_3. Class Region_3 (as well as its derived classes) has the following functionality:

  • it can test, if some chosen point is inside or outside
  • it can find the point on the region surface closest to the given one
  • it can find intersection with some line
  • it can find intersection with planar contours

Below we present examples of functions which can be used to create some common regions.

  Region_3 *GetHalfSpace(const Vector_3 &n, const Vector_3 &pos);
returns half-space, n is normal to the boundary plane, pos is chosen position at this plane. For example,

  Region_3 *reg = GetHalfSpace(Vector_3(0,0,1), Vector_3(0,0,0));
returns half-space corresponding to positive side of z-axis.

  Region_3 *GetPlate(const Vector_3 &n, const Vector_3 &pos, vec_type width);
returns infinite plate (space between to parallel planes), n is normal to the planes, pos is position at some plane, width is distance between this plane and other plane.

Region_3 *getBox(const &Vector_3 a, const &Vector_3 b);
returns parallelepiped with edges parallel to coordinate axes. a and b are opposite vertexes.

Region_3 *GetSphere(vec_type R, const &Vector_3 center);
returns sphere of a chosen radius R and center position.

Region_3 *GetCylinder(const Vector_3 &origin, Vector_3 n, vec_type R, valtype h);
returns cylinder, origin is point at cylinder axis, n is axis direction, R is radius, h is cylinder height (if h=0 than cylinder is infinite).

Region *GetCone(const Vector_3 &origin, Vector_3 n, vec_type R, vec_type h);
returns cone, all parameters have the same meaning as for GetCylinder.

There are also classes for polyhedron, prism, pyramid, etc. Objects can be rotated, stretched and narrowed, you can take their intersection and sum. Sophisticated objects with curved surface can be specified by polyhedra with sufficient number of sides. See detailed reference in region.h

Script to run jobs at any supercomputer

Usually to run a job on some supercomputer you need:

  • make some job script where you specify executable file name, processors number, execution time, etc.,
  • submit this job script to a queue.

Different supercomputers use different syntax for writing and submitting job scripts. It could be annoying to create job scripts and run them manually.

To avoid this problem we made python script qsub.py. This script allows you to submit jobs to a queue at arbitrary supercomputer without specifying which supercomputer you are using at the moment. This is especially useful if you run your jobs at different supercomputers. To find which supercomputer you are using at the moment, our scripts use unix comand 'hostname'.

To use our script you should put instructions how to make job scripts and submit them on your supercomputer in function make_script. This is already done for some supercomputers: SciNet (Canada), supercomputers of Kurchatov Institute, JSCC RAS, MSU, IHED RAS (Russia)

After this you can use function qsub with following parameters:


This function creates directory workdir/worksubdir, copies executable file prog there, makes a job script SCRIPT.sh to run this executable file with arguments args at np processors for some time (in seconds).

Optional parameters of qsub:

ppn - number of processors used per each node (default value ppn=0 means that all processors at the node can be used)

task - job name (it will be displayed in submitted job list)

fname - file name or list of file names which should be copied to workdir/worksubdir

act - 1 (to submit a job script to the queue) or 0 (not do it)

skip - some name. if file with this name will be found in the worksubdir, executable will not be copied there and job will not be submitted.

For example, you have executable file 'a.out' in the current directory '.'. Copy script 'qsub.py' there and make file 'script.py':

#! /usr/bin/python
from qsub import *

Make file 'script.py' executable

chmod u+x script.py

and run it


As a result, subdirectory 'test' will be created in the current directory and executable file 'a.out' will be copied there. You will find in this subdirectory job script SCRIPT.sh to run 'a.out' at 8 processors for one hour, and file QSUB.sh to submit SCRIPT.sh.

Usually, you have different home directories (where you compile your projects) and work directories (where you run executable files and store the results of calculation) at different supercomputers.

You can specify these directories for each supercomputer and user name in function getdirs (to find which supercomputer and user name you are using at the moment, unix command 'hostname' and 'whoami' are used). Then you can use function qsub_appl, where these directories will be used automatically.


Parameters of this function have the same meaning as for function qsub. The only difference between qsub_appl and qsub is that qsub_appl creates workdir/worksubdir in your work directory, and looks for files prog and fname in your home directory.

/home/kintechlab/fdtd.kintechlab.com/docs/data/pages/en/ivutils.txt · Last modified: 2014/05/11 18:58 by deinega     Back to top