An Object-Oriented Environment For Developing Finite Element Codes For Multi-Disciplinary Applications
An Object-Oriented Environment For Developing Finite Element Codes For Multi-Disciplinary Applications
An Object-Oriented Environment For Developing Finite Element Codes For Multi-Disciplinary Applications
DOI 10.1007/s11831-010-9045-2
O R I G I N A L PA P E R
Received: 15 December 2009 / Accepted: 15 December 2009 / Published online: 22 July 2010
© CIMNE, Barcelona, Spain 2010
Abstract The objective of this work is to describe the de- multidisciplinary problems are presented in order to demon-
sign and implementation of a framework for building multi- strate the applicability and efficiency of the new object ori-
disciplinary finite element programs. The main goals are ented environment.
generality, reusability, extendibility, good performance and
memory efficiency. Another objective is preparing the code
structure for team development to ensure the easy collab- 1 Introduction
oration of experts in different fields in the development of
multi-disciplinary applications. One of the open topics in the finite element method (FEM),
Kratos, the framework described in this work, contains is the combination of solvers in different fields (thermal,
several tools for the easy implementation of finite element fluid dynamics, structural, etc.) in order to solve multi-
applications and also provides a common platform for the disciplinary problems. The ideal approach to achieve this
natural interaction of different applications. To achieve this, goal is to develop a unified software environment. This re-
an innovative variable base interface is designed and imple- quires however a high investment in terms of software de-
mented. This interface is used at different levels of abstrac- velopment.
tion and showed to be very clear and extendible. A very Kratos, the object oriented framework described in cur-
efficient and flexible data structure and an extensible IO rent paper, has been designed from scratch to address such a
are created to overcome difficulties in dealing with multi- challenge.
disciplinary problems. Several other concepts in existing
works are also collected and adapted to coupled problems. 1.1 Problem
The use of an interpreter, of different data layouts and vari-
able number of dofs per node are examples of such ap- Conventional finite element codes encounter several diffi-
proach. culties in dealing with multi-disciplinary problems involv-
In order to minimize the possible conflicts arising in the ing the coupled solution of two or more different fields.
development, a kernel and application approach is used. The Many of these codes are designed and implemented for solv-
code is structured in layers to reflect the working space ing a certain type of problems, generally involving a single
of developers with different fields of expertise. Details are field. For example, to solve just structural, fluid mechanic,
given on the approach chosen to increase performance and or electromagnetic problems. Extending these codes to deal
efficiency. Examples of application of Kratos to different with another field of analysis usually requires large amounts
of modifications.
A common approach is to connect different solvers via
P. Dadvand () · R. Rossi · E. Oñate a master program which implements the interaction algo-
International Center for Numerical Methods in Engineering rithms and also transfers data from one solver to another.
(CIMNE), Technical University of Catalonia, Campus Norte
This approach has been used successfully in practice but
UPC, 08034 Barcelona, Spain
e-mail: [email protected] has its own problems. First of all having completely sepa-
url: http://www.cimne.com rate programs results in many duplicated implementations,
254 P. Dadvand et al.
which causes an additional cost in code maintenance. In code clarity. Let us consider as an example a thermal prob-
many cases the data transfer between different solvers is not lem for this purpose. In a classical approach one would de-
trivial and, depending on the data structure of each program, fine a variable, possibly named Conductivity to allow
may cause a redundant overhead of copying data from one the element to access its conductivity. This leads to follow-
data structure to another. Finally, this method can be used ing interface:
only for master and slave coupling and not for monolithic
coupling approaches. c = Conductivity()
is very useful for the implementation of optimization and Constrain are added to them in order to handle boundary
multi-disciplinary interaction algorithms. conditions. He also defines a Material class with ability
An automatic configurable IO module is added to these to handle both linear and nonlinear materials. The Assem-
components providing the complete set of solutions neces- blage class holds all these components and encapsulates
sary for dealing with multi-disciplinary problems. This IO the time history modeling of structure.
module uses different component lists to adjust itself when Zimmermann et al. [24, 25, 90] designed a structure for
reading and writing new concepts originating from different linear dynamic finite element analysis. Their structure con-
fields of analysis. sists of three categories of objects. First the FEM objects
which are: Node, Element, Load, LoadTimeFunc-
tion, Material, Dof, Domain, and LinearSolver.
2 Background The second includes some tools like GaussPoint, and
Polynomial. The third category refers to the collection
The history of object-oriented design for finite element pro- classes like: Array, Matrix, String, etc. They imple-
grams turns back to the early 1990’s or even earlier. In 1990, mented first a prototype of this structure in Smalltalk and
Forde et al. [33] published one of the first detailed descrip- after that an efficient one in C++. The latter version pro-
tions of applying object-oriented design to finite element vides a comparable performance versus to a Fortran code.
programs. They used the essential components of FEM to In their structure Element calculates the stiffness ma-
trix K e , the mass matrix M e , and the load vector f e in
design the main objects. Their structure consists of Node,
global coordinates for each element. It also assembles its
Element, DispBC, ForcedBC, Material, and Dof as
components in the global system of equations and updates
finite element components and some additional objects like
itself after its solution. Node holds its position and manages
Gauss, and ShapeFunction for assisting in numerical
dofs. It also computes and assembles the load vector and fi-
analysis. They also introduced the element group and the list
nally updates the time dependent data after the solution. Dof
of nodes and elements for managing the mesh and construct-
holds the unknown information and also the dofs values. It
ing system. Their approach has been reused by several au-
stores also its position in the global system and provides
thors in organizing their object-oriented finite element pro-
information about boundary conditions. TimeStep imple-
gram structures. This approach focused on structural analy-
ments the time discretization. Domain is a general manager
sis only and the objects’ interfaces reflect this fact.
for components like nodes and elements and also manages
In those years other authors started to write about the the solution process. It also provides the input-output fea-
object-oriented paradigm and its applications in finite ele- tures for reading the data and writing the results. Finally
ment programming. Filho and Devloo [32] introduced ob- LinearSystem holds the system of equation components:
ject oriented design in FEM codes and applied it to element left hand side, right hand side and solution. It also performs
design. Mackie [53] gave another introduction to the object- the equation numbering and implements the solver for solv-
oriented design of finite element programs by designing a ing the global system of equations.
brief hierarchial element. Later he published a more detailed They also developed a nonlinear extension to their struc-
structure for a finite element program providing a data struc- ture which made them redefined some of their original
ture for entities and also introduced the use of iterators [54]. classes like Domain, Element, Material, and some
Pidaparti and Hudli [69] published a more detailed object LinearSystems [57].
oriented structure with objects for different algorithms in dy- Lu et al. [49, 50] presented a different structure in their
namic analysis of structures. Raphael and Krishnamoorthy finite element code FE++. Their structure consists of small
[71] also used object-oriented programming and provided number of finite element components like Node, Element,
a sophisticated hierarchy of elements for structural applica- Material, and Assemble designed over a sophisticated
tions. They also designed some numerical expressions for numerical library. In their design the Assemble is the cen-
handling the common numerical operations in FEM. The tral object and not only implements the normal assembling
common point of all these authors was their awareness about procedure but also is in charge of coordinate transforma-
the advantages of object oriented programming with respect tion which in other approaches was one of the element’s
to traditional Fortran approaches and their intention to use responsibilities. It also assigns the equation numbers. The
these advantages in their finite element codes. Element is their extension point to new formulations.
Miller [58–60] published an object-oriented structure for Their effort in implementing the numerical part lead to an
a nonlinear dynamic finite element program. He introduced object-oriented linear algebra library equivalent to LAPACK
a coordinate free approach to his design by defining the [8]. This library provides a high level interface using object-
geometry class which handles all transformations from local oriented language features.
to global coordinates. The principal objects in his design are Archer et al. [10, 11] presented another object-oriented
Dof, Joint, and Element. TimeDependentLoad and structure for a finite element program dedicated to linear and
256 P. Dadvand et al.
nonlinear analysis structures under static and dynamic loads. based on the FEM and can be used for developing finite el-
They reviewed features provided by other designs on that ement programs for different fields like heat transfer, fluid
time and combined them in a new structure adding also some flow, solid mechanics and electromagnetics.
new concepts. Node, Element, Side, Material, Shape and Mesh
Their design consists of two level of abstractions. In are the main components of its structure and different prob-
the top level, Analysis encapsulates the algorithms and lem solver classes implement the algorithms. This library
Model represents the finite element components. Map re- also provides different classes to form a FEEqua class
lates the dofs in the model, to unknowns in the analysis which implements formulations for different fields of analy-
and removes the dependency between these objects. It also sis. It uses a static Material class in which each parameter
transforms the stiffness matrix from the element’s local co- is stored as a member variable. Element just provides the
ordinate to the global one and calculates the responses. Ad- geometrical information and the finite element implemen-
tation is encapsulated via FEEqua classes. Element pro-
ditional to these three objects, different handlers are used
vides several features which makes it useful for even com-
to handle model dependent parts of algorithm. Reorder-
plex formulations but keeping all these members data makes
Handler optimizes the order of the unknowns. Matrix-
it too heavy for industrial implementations.
Handler provides different matrices and construct them
Bangerth et al. [12, 14, 15] created a library for imple-
over a given model. Finally ConstraintHandler pro-
menting adaptive meshing finite element solution of partial
vides the initial mapping between the unknowns of analysis differential equations called Differential Equations Analysis
and the dofs in the model. Library (DEAL) II [13]. They were concerned with flexibil-
In another level there are different finite element com- ity, efficiency and type-safety of the library and also wanted
ponents representing the model. Node encapsulates a usual to implement a high level of abstraction. All these require-
finite element node, its position and its dofs. ScalarDof ments made them to use advanced features of C++ lan-
and VectorDof are derived from the Dof class and guage to achieve all their objectives together.
represent the different dof’s types. Element uses the Their methodology is to solve a partial differential
ConstitutiveModel and ElementLoad to calculate equation over a domain. Triangulation, Finite-
the stiffness matrix K e , the mass matrix M e and the damp- Element, DoFHandler, Quadrature, Mapping, and
ing matrix C e in the local coordinate system. LoadCase FEValues are the main classes in this structure.
includes loads, prescribed displacements and initial element Triangulation, despite its name, is a mesh generator
state objects and calculates the load vector in the local coor- which can create line segments, quadrilaterals and hexahe-
dinate system. dra depending on given dimensions as its template parame-
Cardona et al. [17, 42, 43] developed the Object Ori- ter. It also provides a regular refinement of cells and keeps
ented Finite Elements method Led by Interactive Execu- the hierarchical history of the mesh. FiniteElement en-
tor (OOFELIE) [66]. They designed a high level language capsulates the shape function space. It computes the shape
and also implemented an interpreter to execute inputs given function values for FEValues. Quadrature provides
in that language. This approach enabled them to develop a different orders of quadratures over cells. Mapping is in
very flexible tool to deal with different finite element prob- charge of the coordinate transformation. DoFHandler
lems. In their structure a Domain class holds data sets like: manages the layout of dofs and also their numbering in
a triangulation. FEValues encapsulates the formulation
Nodeset, Elemset, Fixaset, Loadset, Materset,
to be used over the domain. It uses FiniteElement,
and Dofset. Element provides methods to calculate the
Quadrature and Mapping to perform the calculations
stiffness matrix K e , the mass matrix M e , etc. Fixaset and
and provides the local components to be assembled into the
Loadset which hold Fixations and Loads handle the
global solver.
boundary conditions and the loads.
Extensive use of templates and other advanced features of
They used this flexible tool also for solving coupled prob- C++ language increases the flexibility of this library with-
lems where their high level language interpreting mech- out sacrificing its performance. They created abstract classes
anism provides an extra flexibility in handling different in order to handle uniformly geometries with different di-
algorithms for coupled problems. They also added mensions. In this way, they let users create their formulation
Partition and Connection classes to their structure in in a dimension independent way. Their approach also con-
order to increase the functionality of their code in handling sists of implementing the formulation and algorithms and
and organizing data for coupled problems. Partition is sometimes the model itself in C++. In this way the library
defined to handle a part of domain and Connection pro- configures itself better to the problem and gains better per-
vides the graph of dofs and also sorts them out. formance but reduces the flexibility of the program by re-
Touzani [83] developed the Object Finite Element Li- quiring it to be used as a closed package. In their struc-
brary (OFELI) [82]. This library has an intuitive structure ture there is no trace of usual finite element components like
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 257
node, element, condition, etc. This makes it less familiar for their code. However the structure results from this design
developers with usual finite element background. can be unfamiliar to usual finite element programmers. For
Patzák et al. [68] published an structure used in the instance, in the latter design there are no objects to repre-
Object Oriented Finite Element Modeling (OOFEM) [67] sent nodes and elements, which are the usual components
program. In this structure Domain contains the complete for finite element programmers.
problem description which can be divided into several In this work the standard finite element objects like
Engineering Models which prepare the system of nodes, elements, conditions, etc. are reused from previous
equations for solving. Numerical Method encapsulates designs but modified and adapted to the multi-disciplinary
the solution algorithm. Node, Element, DOF, Boundary analysis perspective. There are also some new components
condition, Initial condition, and Material like model part, process, kernel and application which are
are other main object of this structure. This program is ori- added to account for new concepts mainly arising in multi-
ented to structural analysis. disciplinary problems. A new variable base interface is de-
signed providing a uniform interface between fields and in-
2.1 Discussion creasing the reusability of the code. The idea of using an in-
terpreter is applied by using an existing interpreter. A large
A large effort has been done to organize finite element codes effort has also been invested to design and implement a fast
trying to increase their flexibility and reducing the mainte- and very flexible data structure enabling to store any type
nance cost. Two ways of designing finite element program of data coming from different fields and guarantee the uni-
can be traced in literature. One consists of using the finite form transformation of data. An extendible IO is also created
element methodology for the design which leads to objects to complete the tools for dealing with the usual bottlenecks
like element, node, mesh, etc. Another approach is to deal when working with multi-disciplinary problems.
with partial differential equations which results in object In the following sections we start with a brief descrip-
functions working with matrices and vectors over domains. tion of FEM in Sect. 3 and continues in Sect. 4 with a
The work of Zimmermann et al. [24, 25, 90] is one of short presentation of common techniques for the solution of
the classical approaches in designing the code structure on multi-disciplinary problems. Section 5 gives an overview of
the basis of the finite element methodology. However there the Kratos environment and its general structure. The new
is no geometry in their design and new components like Variable Base Interface is described in Sect. 6. Section 7
processes, command interpreter etc. are not addressed. is dedicated to the data structures. The next two sections
The effort of Miller et al. to encapsulate the coordinate describe the parts related to finite element method and the
transformation in geometry is useful for relaxing the depen- input output. Finally some validation examples of the pos-
dency of elemental formulation to an specific geometry. sibility of Kratos for solving multidisciplinary are presented
Cardona et al. [17, 42, 43] added an interpreter to manage in Sect. 11.
the global flow of the code in a very flexible way. The inter-
preter was used for introducing new solving algorithms to
the program without changing it internally. This code is also 3 Finite Element Method
extended to solve coupled problems using the interpreter for
introducing interaction algorithms which gives a great flexi- 3.1 Basic Concepts of FEM Discretization
bility to it. The drawback of their approach is the implemen-
tation of a new interpreter with a newly defined language The finite element method typically solves problems gov-
beside binding to an existing one. This increases the main- erned by differential equations with the appropriate bound-
tenance cost of the interpreter itself and makes it difficult to ary conditions. The more general setting can be expressed
using other libraries which may have interfaces to chosen as:
script languages.
Touzani [83] designed an structure for multi-disciplinary – Solve the set of different equations
finite element programs. His design is clear and easy to
understand but uses field specific interfaces for its compo- A(u) = 0 in (1)
nents which are not uniform for all fields. This reduces the
subjected to the boundary conditions
reusability of the algorithm from one field to the other.
The approach of Lu et al. [49, 50] is in line with design- B(u) = 0 in (2)
ing a partial differential solver with emphasizes on numer-
ical components. Archer et al. [10, 11] extended this ap- where A and B are matrices of differential operators defined
proach to make it more flexible and extendible. More re- over the analysis domain and its boundary and u(x, t) is
cently Bangerth et al. used the same approach for designing the vector of problem unknowns which may depend on the
258 P. Dadvand et al.
space dimension and the time. Indeed, for multidisciplinary we will focus in describing the details of the implementa-
problems A and B define the equations in the different in- tion of the FEM equations into an object-oriented environ-
teracting domains and their boundaries. Details of the form ment with the aim of solving problems of multidisciplinary
of the operators A and B for each particular problem can be nature, where the differential operators A and B are defined
found in standard FEM books [89]. over adjacent or overlapping domain, therefore leading to
The FEM solution is found by approximating the un- a coupled solution strategy. Typical examples of these situa-
known polynomial expansions defined within each element tions are thermal-mechanical problems, fluid-structure inter-
discretizing the analysis domain , i.e. action problems, electro-magnetic problems, aeroacoustic,
etc.
N
u uh = N i ui (3) 3.2 Solution of FEM Equations
i=1
3.2.1 Calculating Components
where N is the number of nodes in the mesh, Ni is the shape
functions matrix and ui are the approximate values of u at This step consist of calculating the elemental integrals usu-
each node. Typically, (3) is written on an element by element ally using the Gaussian Quadrature method. The integrand
form. function contains the shape functions and their derivatives,
The matrix system of equation is obtained by substituting which should be computed for each element. A common
(3) into (1) and (2) and using the Galerkin weighted residual technique is to calculate these functions in local coordinates
form which can be written as of the element and transform the result to global coordinates.
3.2.2 Creating the Global System
Ni r d + Ni r d = 0, i = 1, N (4)
Once the elemental matrices and vectors Ke and f e have
where been computed, they are assembled in the global system of
equations. This requires finding the position of each elemen-
r = A(uh ), r = B(uh ) (5) tal component in the global equations system and adding its
value to its position.
are the so called “residuals” of the governing equations over This procedure first assigns a sequential numbering to all
the domain and the boundary, respectively. Indeed (4) can dofs. Sometimes is useful to separate the prescribed dofs,
be adequately transformed by integration by parts of many those with Dirichlet conditions, from the others. This can be
terms over the analysis domain, to give the so called weak done easily at the time of assigning indices to dofs. After
integrals form which is more convenient for some prob- that, the procedure goes element by element and adds their
lems [89]. In any case, the element structure of the FEM local matrices and vectors to the global equations system
allows computing and assembling the integrals of (4) on an using the assembly operator , i.e.:
element by element manner. The resulting system of dis-
Kij Keij = KIei Iej + Keij (8)
cretized equation can be written (for the static case) as
Ie
Ka = f (6) fi fie = fIei + fie (9)
Ie
where
where Ie is the vector containing the global position, which
is the index of the corresponding dof, of each row or col-
K = AK(e) , f = Af(e) (7)
umn.
Another task to be done when building the global sys-
where A denotes the assembly operation which allows to
tem of equations is the application of essential boundary
obtaining the global stiffness matrix K and the equivalent conditions by eliminating prescribed dofs or using a penalty
nodal force vector f from the element contributions. In (7) a method [74].
is the vector of unknowns which lists the values of ui at all The global system matrix obtained in the FEM typically
the nodes in the mesh. has many zeros in it. So it is convenient to use structures
The solution of the system of (6) requires prescribing the which hold a useful portion of the matrix to be solved like
value of the unknown variables ui at specific points (the so compressed sparse row (CSR) [80]. Another common struc-
called Dirichlet boundary condition). ture is the symmetric matrix structure that uses the symme-
It is not the objective of this paper to explain the basis try property of the matrix to hold approximately half of the
of the FEM which can be found in many text books. Instead elements.
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 259
There are two categories of solvers: direct solvers and itera- In this work a multi-disciplinary problem, also called cou-
pled problem, is defined as solving a model which consists
tive solvers.
of components with different formulations and algorithms
Direct solvers solve the equation system by transform-
interacting together. It is important to mention that this dif-
ing the coefficient matrix in an upper triangular form, lower
ference may come not only from the different physical na-
triangular, a diagonal form. Solvers like Gaussian elimina-
ture of the problems, but also from their different type of
tion [70], frontal solution [16], LU decomposition [70] are
mathematical modeling or discretization.
examples of this category.
A field is a subsystem of a multi-disciplinary model rep-
Iterative solvers start with some initial values for the un- resenting a certain mathematical model. Typical examples
known and find the correct solution by calculating the resid- are a fluid field and a structure field in a fluid-structure inter-
ual and minimize it over a number of iterations. Conjugate action problem. In a coupled system a domain is the part of a
gradient (CG) [80], Biconjugate gradient (BCG) [80], Gen- modeled space governed by a field equation, i.e. a structure
eralized minimal residual method (GMRES) [80] are exam- domain and a fluid domain.
ples of this category of solvers.
It is common to use a reordering procedure for reduc- 4.1 Categories
ing the bandwidth of the system matrix or make it more
cache efficient. In practice these algorithms can be applied One may classify multi-disciplinary problems by the type
to renumber the dofs in an optimum way once they are cre- of coupling between the different subsystems. Consider a
ated and then solve the system as usual. The Cuthill McKee problem with two interacting subsystem as shown in Fig. 1.
[80] algorithm is a classical example of this type of algo- The problem is calculating the solutions u1 and u2 of sub-
rithms. systems S1 and S2 under applied forces F (t). There are two
Sometimes it is recommended to transform the system of types of dependency between the subsystems:
equations to and equivalent but better conditioned one for Weak Coupling Also called one-way coupling where one
using iterative solvers. This procedure is called precondi- subsystem depends on the other but this can be solved in-
tioning. Diagonal and Incomplete LU preconditioners [80] dependently. Figure 2 shows this type of coupling.
are examples of preconditioners. Unfortunately, finding the Strong Coupling Also referred as two-way coupling when
best combination of solver and preconditioner for a certain each system depends on the other and hence none of them
problem is a matter of experience and there is not a single can be solved separately. Figure 3 shows this type of cou-
best combination for all problems. pling.
3.2.5 Iterating
combining these templates and their relative variables. This Finally it has to provide different levels for developers
technique is also used in high performance linear algebra to contribute to the Kratos system, and match their require-
libraries to evaluate vectorial expressions [85]. In this way ments and difficulties in the way they extend it. Developers
expressions consisting of operations over matrices and vec- may not want to make a plug-in extension, create an appli-
tors can be evaluated without creating any temporary object cation over it, or using IO scripts to make Kratos perform a
and in a single loop. certain algorithm. Some potential profiles for Kratos users
Templates were added to C++ for a better alternative to are:
existing macros in old C. Eventually they did not eliminate
Finite Element Developers These developers are consid-
the use of macros but performed much better than anyone
ered to be more experts in FEM, from the physical and
could expect. An example is template meta programming.
mathematical points of view, than C++ programmers.
Everything began when Erwin Unruh tricked the compiler
For them, Kratos has to provide solution to their require-
to print a list of prime numbers at compile time. This ex-
ments without involving them in advanced programming
tends the algorithm writing from standard form in C++ to a
concepts.
new form which makes the compiler run the algorithm and
Application Developers These users are less interested in fi-
results in a new specific implementation to run.
nite element programming and their programming knowl-
The Template Metaprogramming technique can be used
edge may vary from very expert to higher than basic. They
to create an specialized algorithm at the time of compil-
may use not only Kratos itself but also any other appli-
ing. This technique makes the compiler interpret a subset
cations provided by finite element developers, or other
of the C++ code in order to generate this specialized algo-
application developers. Developers of optimization pro-
rithm. Different methods are used to simulate different pro-
grams or design tools are typical users of this kind.
gramming statements, like loops or conditional statements,
Package Users Engineers and designers are other users of
at compiling time. These statements are used to tell the com-
Kratos. They use the complete Kratos package and its ap-
piler how to generate the code for an specific case.
plications to model and solve their problem without get-
This technique uses recursive templates to encourage the
ting involved in internal programming of this package. For
compiler into making a loop. When a template calls itself
these users, Kratos has to provide a flexible external inter-
recursively, the compiler has to make a loop for instantiat-
face to enable them use different features of Kratos with-
ing templates until a specialized version used as stop rule is
out changing its implementation.
reached.
Template specialization can also be used to make com- Kratos has to provide a framework such that a team of
piler simulate conditional statements or switch and cases. developers with completely different fields of expertise as
These statements can be used to generate different codes ac- mentioned before, can work on it in order to create multi-
cording to some conditions. For example an assignment op- disciplinary finite element applications.
erator for matrices may change its algorithm depending on
the row or column majority of a given matrix. 6.1 Object Oriented Design
methodology. This approach was selected because our goal Element encapsulates the elemental formulation in one
was to create a finite element environment for multidiscipli- object and provides an interface for calculating the local
nary problems. Also our colleagues were, in general, more matrices and vectors necessary for assembling the global
familiar with this methodology. In addition, this approach system of equations. It holds its geometry that meanwhile
has given us the necessary generality in the objectives of is its array of Nodes. Also stores the elemental data and
Kratos mentioned above. Within this scope main objects are the interface to access it.
taken from various parts of the FEM structure. Then, some
Condition encapsulates data and operations necessary
abstract objects are defined for implementation purposes. Fi-
for calculating the local contributions of Condition to
nally their relations are defined and their responsibilities are
the global system of equations. Neumann conditions are
balanced. Figure 4 shows the main classes in Kratos.
Vector, Matrix, and Quadrature are designed by example of Conditions which can be encapsulated by
basic numerical concepts. Node, Element, Condition, derivatives of this class.
and Dof are defined directly from finite element con- Dof represents a degree of freedom (dof). It is a lightweight
cepts. Model, Mesh, and Properties are coming from object which holds its variable, like TEMPERATURE, its
practical methodology used in finite element modeling. state of freedom, and a reference to its value in the data
These classes are completed by ModelPart, and structure. This class enables the system to work with dif-
SpatialContainer, for organizing better all data nec- ferent set of dofs and also represents the Dirichlet condi-
essary for analysis. IO, LinearSolver, Process, and tion assigned to each dof.
Strategy are representing the different steps of finite el- Properties encapsulates data shared by different
ement program flow. Finally, Kernel and Application Elements or Conditions. It can store any type of data
are defined for library management and defining its inter- and provides a variable base access to them.
face.
Model stores the whole model to be analyzed. All Nodes,
These main objects are described below:
Properties, Elements, Conditions and solution
Vector represents the algebraic vector and defines usual data. It also provides an access interface to these data.
operators over vectors. ModelPart holds all data related to an arbitrary part of
Matrix encapsulate matrix and its operators. Different model. It stores all existing components and data like
matrix classes are necessary. The most typical ones are
Nodes, Properties, Elements, Conditions and
dense matrix and compressed row matrix.
solution data related to a part of model and provides inter-
Quadrature implements the quadrature methods used in
face to access them in different ways.
finite element method. For example the Gaussian integra-
tion with different number of integration points. Mesh, Node, Properties, Elements, Conditions
Geometry defines a geometry over a list of points or and represents a part of model but without additional so-
Nodes and provides basic parameters, like area or center lution parameters. It provides access interface to its data.
point, to shape functions and coordinate transformation SpatialContainer includes associated with spacial
routines. search algorithms. This algorithms are useful for finding
Node It is a point with additional facilities. Stores the nodal the nearest Node or Element to some point or other spa-
data, historical nodal data, and list of degrees of freedom. cial searches. Quadtree and Octree are example of these
It provides also an interface to access all its data. containers.
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 263
IO provides different implementation of input output pro- Basic Tools Layer Holds all basic tools used in Kratos. In
cedures which can be used to read and write with different this layer the use of advanced C++ techniques is essen-
formats and characteristics. tial in order to maximize the performance of these tools.
LinearSolver encapsulates the algorithms used for This layer is designed to be implemented by an expert
solving a linear system of equations. Different direct programmer and with less knowledge of FEM. This layer
solvers and iterative solvers can be implemented in Kratos may also provide interfaces with other libraries to benefit
as a derivatives of this class. from existing work in the field.
Strategy encapsulates the solving algorithm and general Base Finite Element Layer This layer holds the objects that
flow of a solving process. Strategy manages the building are necessary to implement a finite element formulation.
of equation system and then solve it using a linear solver It also defines the structure to be extended for new formu-
and finally is in charge of updating the results in the data lations. This layer hides the difficult implementations of
structure. nodal and data structure and other common features from
Process is the place for adding new algorithms to Kratos. the finite element developers.
Mapping algorithms, Optimization procedures and many Finite Element Layer The extension layer for finite element
other type of algorithms can be implemented as a new developers. The finite element layer is restricted to use the
process in Kratos.
basic and average features of language and uses the com-
Kernel manages the whole Kratos by initializing different
ponent base finite element layer and basic tools to opti-
parts of it and provides the necessary interface to commu-
mize the performance without entering into optimization
nicate with applications.
details.
Application provides all the information necessary for
Data Structure Layer contains all objects organizing the
adding an application to Kratos. A derived class from it
data structure. This layer has no restriction in implemen-
is necessary to give a kernel its required information, like
tation. Advanced language features are used to maximize
new Variables, Elements, Conditions, etc.
the flexibility of the data structure.
The main intention here was to hide all difficult but com- Base Algorithms Layer provides the components building
mon finite element implementations, like data structure and the extendible structure for algorithms. Generic algo-
IO programming, from developers. rithms can also be implemented to help developer in their
implementation by reusing them.
6.2 Multi-layers Design User’s Algorithms Layer This is another layer to be used
by finite element programmers but at a higher level. This
Kratos uses a multi-layer approach in its design. In this ap- layer contains all classes implementing the different al-
proach each object only interfaces with other objects in its gorithms in Kratos. Implementation in this layer requires
layer or in layers below its layer. There are some other lay- medium level of programming experience but a higher
ering approaches that limit the interface between objects of knowledge of the program structure than the finite ele-
two layers but in Kratos this limitation is not applied. ment layer.
Layering reduces the dependency inside the program. It Applications’ Interface Layer This layer holds all objects
helps in the maintenance of the code and also helps devel- that manage Kratos and its relation with other applica-
opers in understanding the code and clarifies their tasks. tions. Components in this layer are implemented using
In designing the layers of the structure different users high level programming techniques in order to provide the
mentioned before are considered. The layering is done in required flexibility.
a way that each user has to work in the less number of lay- Applications Layer A simple layer which contains the inter-
ers as possible. In this way the amount of the code to be face of certain applications with Kratos.
known by each user is minimized and the chance of conflict Scripts Layer holds a set of IO scripts which can be used
between users in different categories is reduced. This layer- to implement different algorithms from outside Kratos.
ing also lets Kratos to tune the implementation difficulties Package users can use modules in this layer or create
needed for each layer to the knowledge of users working their own extension without having knowledge of C++
in it. For example, the finite element layer uses only basic programming or the internal structure of Kratos. Via this
to average features of C++ programming, but the main de- layer they can activate and deactivate certain functionali-
veloper layer uses advanced language features in order to ties or implement a new global algorithm without entering
provide the desirable performance. into Kratos implementation details.
Following the design mentioned before, Kratos is orga-
nized in the following layers: Figure 5 shows the multi-layer nature of Kratos.
264 P. Dadvand et al.
6.3 Kernel and Applications minimized. The Application class provides the inter-
face for introducing an application to the kernel of Kratos.
In the first implementation of Kratos all applications were Kernel uses the information given by Application
implemented in Kratos and also were compiled together. through this interface to mange its components, configure
This approach at that time produced several conflicts be- different part of Kratos, and synchronize the application
tween applications and was requiring many unnecessary re- with other ones. The Application class is very sim-
compiling of the code for changes in other applications. All ple and consists of registering the new components like:
these problems lead to a change in the strategy and to sepa- Variables, Elements, Conditions, etc. defined in
rating each application, not only from others, but also from Application. The following code shows a typical
Kratos itself. Application class definition:
In the current structure of Kratos each application is cre-
ated and compiled separately and just uses a standard inter- // Variables definition
KRATOS_DEFINE_VARIABLE(Matrix, MY_NEW_VARIABLE)
face to communicate with the kernel of Kratos. In this way
the conflicts are reduced and the compilation time is also class KratosNewApplication
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 265
: public KratosApplication
{
public:
virtual void Register();
private:
// Creating variables
KRATOS_CREATE_VARIABLE(MY_NEW_VARIABLE)
void KratosR1StructuralApplication::Register()
{
// calling base class register
// to register Kratos components Fig. 6 Structure of the variable classes
KratosApplication::Register();
In many connecting points between different parts of a fi- VariableData is the base class which contains two ba-
nite element program we are asking for the value of some sic informations about the variable it represents; Its name
variable or the mapping of some variables and so on. The mName, and its key number mKey. VariableData has
methodology to design this interface is sending each request trivial access methods for these two attributes while also
with the variable or variables it involves. has virtual and empty methods for raw pointer manipula-
In this variable base interface (VBI): tion. The reason of not implementing these methods here
266 P. Dadvand et al.
is the fact that VariableData has not any information with the memory allocated to it. So it is very useful in
about the variable type it represents. Lack of type informa- case of reallocating a part of the memory.
tion in VariableData makes it unsuitable and less us- • Print is an auxiliary method to produce output of given
able to pass it in many parts of the interface. The idea of variable knowing its address. For example writing an het-
this class, however, is to provide a lower level of informa- erogenous container in an output stream can be done us-
tion which is common to all types of variables and their ing this method. Point assumes that the streaming opera-
components, and use it as a place holder when there is no tor is defined for the variable type.
distinction between variables and their components. Also in
All these methods are available for low level use. They
this implementation we use a virtual method base to dis-
are useful because they can be called by a VariableData
patch various operations on raw pointers. This may result
pointer and equally for all type of data arranged in memory.
in a poor performance for some cases as the function call
However, maintaining typesafety using these methods is not
overhead may be considerable.
straightforward and needs special attention.
Zero value is another attribute of Variable, stored in
7.2.2 Variable
mZero. This value is important specially when a generic al-
gorithm needs to initialize a variable without losing general-
Variable is the most important class in this structure. It
ity. For example an algorithm to calculate the norm of a vari-
has information represented by VariableData which is
able for some Elements must return a zero value if there
derived from it plus the type of the variable it represents.
is no Element at all. In case of double values there is no
Variable has its data type as a template parameter. In this
problem to call default constructor of variable type but ap-
manner, the interface can be specialized for each type of data
plying same algorithm to vector or matrix values can cause
and also type-safety can be achieved. Another important ad-
a problem because default constructor of this types will not
vantage of having variable in template form with its data
have the correct size. Returning a zero value instead of a
type as template parameter is to have a restriction form in the
default constructed value keeps generality of the algorithms
interface. If we want to restrict a method to accept just matri-
even for vectors and matrices, assuming that variables are
ces for instance, then by passing a variable<Matrix>
defined properly.
as its argument we can prevent users from passing another
A method is StaticObject. This method just returns
type by mistake. This feature is particularly important for
None which is an static variable that can be used in case of
cases when there are different types representing the same
undefined variable (like null for pointers). It is just an auxil-
variable. The constitutive matrix and its corresponding vec-
iary variable to help managing undefined, no initialized, or
tor is a good example of this situation.
exceptional cases.
In Variable by knowing the data type raw pointer ma-
nipulating methods are implemented. These methods use
7.2.3 VariableComponent
raw pointers to perform basic operations over its type:
• Clone creates a copy of the object using a copy con- As mentioned before, there are situations that we want to
structor of the class. It is useful to avoid shallow copying deal with just component of a variable but not all of them.
of complex objects and also without actually having in- VariableComponent is implemented to help in these
formation about the variable type. situations.
• Copy is very similar to Clone except that it also the des- VariableComponent is a template taking an adaptor
tination pointer also passed to it. It is a helpful method as its argument. An adaptor is the extending point of a com-
specially to create a copy of heterogeneous data arrays . ponent mechanism. For any new component a new adaptor
• Assign is very similar to Copy. It just differs in using an (see Fig. 7) needs to be implemented. The adaptor type re-
assignment operator besides the copy constructor. Copy quirements are:
creates a new object while Assign does the assignment
• GetSourceVariable method to retrieve parent vari-
for two existing objects.
able.
• AssignZero is a special case of Assign for which
• GetValue method to convert extract a component value
variable zero value used as source. This method is use-
from a source variable value.
ful for initializing arrays or resetting values in memory.
• StaticObject is used to create none component.
• Delete removes an object of variable type from mem-
ory. It calls a destructor of objects to prevent memory leak Unlike Variable, VariableComponent has not
and frees the memory allocated for this object assuming been implemented to have zero value or raw pointer ma-
that the object is allocated in heap. nipulators. A zero value can be extracted from the source
• Destruct eliminates an object maintaining the memory value so there is no need implement it. Operations over raw
it is using. However, the unlike Delete it does nothing pointers are not allowed on purpose. This interface manages
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 267
double
CalculateError(const VariableType& ThisVariable,
Element& rElement) types is to take different containers and put them together
{ as a new container. Figure 8 shows an example of this con-
typedef typename VariableType::type data_type;
tainer.
// initializing ...
for(i_node = element_nodes.begin() ;
Advantages for Combining Containers
i_node != element_nodes.end() ; ++i_node)
{ • Fast and easy implementation. Standard containers can be
error = i_node->GetValue(ThisVariable) - reused.
rElement.Calculate(ThisVariable, *i_node);
• Very rigid and errorless structure. Everything relies on
result += sqrt(error * error); C++ static type checking without dangerous type cast-
}
return result * area / element_nodes.size();
ing and raw pointer manipulation.
} • Keeping separated different types of data allows more
specialization for each case. For example in time of copy-
In this manner the error estimator is not depending on the ing the containers for built in types.
domain and can work in the same way for a thermal flow or • Less searching time as the number of data in each con-
a pressure gradient. tainer is less than the total number of data in container.
our approach the variables are used as the handlers to help Implementation The first step to implement a data value
the container in its data operations. The data value container container is designing the structure of data in memory. One
uses the Variable class not only to understand the type of approach is to group each data with a reference to its variable
data but also to operate over it via its raw pointer methods. and put them in a dynamic array as shown in Fig. 11.
Figure 10 shows the relationship between a container and Having a pointer to each variable and not copying it is
the Variable class. necessary for eliminating the unnecessary overhead of du-
plicated variables.
Data Value Container Advantages Another approach is to allocate each data separately and
keep the pointer to its location in the container. Figure 12
• Extendibility to store any type of data without any imple-
shows a container with this structure in memory.
mentation cost. One can store virtually any type of data,
The first approach is typically more efficient in use of
from simple data like an integer to a complex one like a
cache but adding new data to it may invalidate all the ref-
dynamic array of pointers to neighbor elements.
erences to its elements. The second approach lets user to
• Usually extensive use of void pointers and down casting
get a reference of its data once and use it several times
make heterogeneous container open to type crashing. Us-
ing the VBI protects users from unwanted type conversion without worrying about its validness. In this work the sec-
and guarantees the type-safety of this container. ond approach is used because of its advantage in reducing
the repeated accesses to the container which can increase
significantly its overall performance in practice. Finally, a
Data Value Container Disadvantages
brute-force search over unsorted containers has been used
• Heterogeneous containers are typically slower than ho- for searching the keys as this has given the best performance
mogeneous ones, at least in some of their operations. in practice (Fig. 13).
270 P. Dadvand et al.
Fig. 13 Time comparison for different searching algorithms over vector<double> with binary search. (b) Comparing performance
sorted and unsorted small containers. (a) Comparing perfor- of vector<pair<int,double> > with brute-force key finding,
mance of vector<double> with brute-force, list<double> list<pair<int, double> > with brute-force key finding and
with brute-force, set<double> binary tree search and sorted map<int,double> binary tree search
Fig. 15 The
VariablesList class
provides the list of variables and
their local positions for the
VariablesListData-
ValueContainer
in another thread just after a reference is taken. So finally the can be stored in different categories representing domains or
inserting feature was removed from this container to reduce other model complexities. In this section the global distrib-
problems using it. ution of data in Kratos will be discussed.
In a finite element program several categories of data has to Kratos is designed to support an element-based formulation
be stored. Nodal data, elemental data with their time histo- for multi-disciplinary finite element applications. Also han-
ries and process data are examples of these categories. Also dling mesh adaptivity is one of its goals. So the entity based
in a multi-disciplinary applications, Nodes and Elements data structure becomes the best choice. First because ele-
272 P. Dadvand et al.
Fig. 16 ModelPartholds
Mesh with some additional data
referred as ProcessInfo
mental algorithms are usually entity based and can be opti- The next container is ModelPart which is a complete
mized better using this type of structure. The second reason set of all entities and all categories of data in the data struc-
is the good performance and flexibility this structure offers, ture. It holds Mesh with some additional data referred as
in order to add or remove Nodes and Elements. Beside ProcessInfo. Any global parameter related to this part
this entity base structure, Kratos also offers different levels of the model or data related to processes like time step, iter-
of containers to organize and group geometrical and analy- ation number, current time, etc. can be stored in Process-
sis data. These containers are helpful in grouping all the data Info. Each ModelPart can hold more than one Mesh
necessary to solve some problems and for simplifying the which can be used to keep trace of different categories of
task of applying a proper algorithm to each part of the model entities like interface, local, ghost etc. ModelPart also
in multi-disciplinary applications. Figure 16 shows the con- manages the variables to be hold in Nodes. For example, all
tainers in the Kratos data structure. the Nodes belonging to one ModelPart sharing its nodal
Nodal, elemental and conditional data containers are the variables list. ModelPart is the nearest container to the
basic units of this entity base structure. In Kratos each Node domain concept in the multi-disciplinary FEM.
and Element has its own data. In this manner an Element Finally Model is a group of ModelPart’s and repre-
can access easily the nodal information just by having sents the finite element model to be analyzed. It can be use-
a reference to its Node and without any complications. ful for some procedures that require the whole data structure
Properties is also a block of this structure, as a shared like saving and loading procedures. As processes in Kratos
data between Elements or Conditions. use ModelPart as their work domain, this container is not
Separate containers for Nodes, Properties, implemented yet but it is necessary to complete the data
Elements and Conditions are the first level of contain- structure of Kratos.
ers defined in Kratos. These containers are just for grouping Spatial containers are separated so can be used just when
one type of entity without any additional data associated to they are needed. This strategy also allows Kratos to use ex-
them. These containers can be used not only to work over ternal libraries implementing general spatial containers like
a group or entities but also to modify their data while each Approximate Nearest Neighbor (ANN) library [62].
entity has access to its own data. These containers are useful
when we want to select a set of entities and process them. 8.2.2 Nodal Data
For example giving a set of Nodes to a nodal data initializa-
tion procedure, sending a set of Elements to assembling The first implementation of Kratos had a buffer of data value
functions, or getting a set of Conditions from a contact containers to hold all the nodal variables. This nodal con-
procedure. tainer was very flexible but with considerable memory over-
Mesh is the second level of abstraction in the data struc- head for nonhistorical variables. For example for saving two
ture which hold Nodes, Elements and Conditions and time steps in history (a buffer with size 3) there were two
their Properties. In other words, Mesh is a complete redundant copies of all nonhistorical variables in memory as
pack of all type of entities without any additional data as- shown in Fig. 17. It also had fair access performance due to
sociated with them. So a set of Elements and Condi- the searching process of the container. All these made us to
tions with their Nodes and Properties can be grouped redesign the way data are stored in Nodes.
together as a Mesh and send to procedures like mesh refine- The new structure is divided into two different con-
ment, material optimization, mesh movement or any other tainers: nodal data and solution step nodal
procedure which works on entities without needing addi- data. A data value container is used for the nodal data
tional data for their processes. (no historical data) and a buffered variables list container is
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 273
used for the solution step nodal data (historical data). In this do not need to search in the data value container and also
way the memory overhead is eliminated because no redun- give error for logical errors in the code.
dant copy is produced. Also accessing to historical variables • Methods for accessing no historical data only. Another
is much faster than before due to the indirecting process of set of methods are implemented to give access only to
accessing the variables list container instead of the search- no historical data. Due to the flexibility of the data value
ing process in the data value container. This structure of- container any variable can be added at any time as a nodal
fers good performance and also is memory efficient, but is variable using these methods.
slightly less robust and somehow less flexible to use. • Hybrid accessing also can be done using another set of
Using the variables list container for historical variables, methods. These methods try to find the variable in the so-
requires the user to define its historical variables in order lution steps container and if it does not exist, then they
to construct the nodal data container. For example a fluid provide access to the nodal data container. These methods
application must define velocity and pressure as its historical are helpful for accessing to some input variables that may
variables at the program startup. The rest of variables can come from input files as nodal data, or variables which are
be added any time during the program execution, as a no calculated in another domain and stored as a solution step
historical variable, but not as a historical one. variable. For example temperature for structural problem
In this implementation the buffer was introduced inside can be a parameter coming from the input data or calcu-
the variables list data value container instead of using a lated by the thermal elements and stored in Node. This
buffer of this containers. In this way cache misses are re- method guarantees the access to the proper temperature
duced and the data array can be given to other application
stored at each Node.
without any conversion. Figure 18 shows this structure.
Dividing the nodal data in two categories also changes
8.2.3 Elemental Data
the access interface to data. Now the user has to know were
to put each variable, and more important, where to retrieve
them from afterwards. A sophisticate interface is needed in Another basic unit of Kratos data structure is the elemen-
order to provide a clear and complete control over these two tal data. Elemental data is divided into three different cate-
categories of data. In general, three type of accessing meth- gories:
ods are necessary: properties These are all parameters that can be shared be-
• Methods for accessing only historical data. These meth- tween Element. Usually material parameters are com-
ods guarantee to give the value of the variable if and only mon for a set of element, so this category of data is re-
if it is defined as a historical variable and produce error if ferred as properties. But in general it can be any common
it is not defined. These methods are very fast because they parameter for a group of Elements. Sharing these data
274 P. Dadvand et al.
as properties reduces the memory used by the application For Conditions, historical data is considered to be an
and also helps updating them if necessary. internal data as is related to its formulation and usually is
data includes all variables related to an Element and used only by formulation inside and not from outside. So
without history keeping. Analysis parameters and some to minimize unnecessary overhead and also to increase the
inputs are elemental but there is no need to keep their his- performance, no general container is provided for historical
tory. These variables can be added any time during the data and each Condition has to implement one for itself
analysis. if necessary.
historical data are data stored with historical information
which may be needed to be retrieved. Historical data in
8.2.5 Properties
integration points are fall in this category. These data must
be stored with a specific size buffer.
As mentioned before Properties is a shared data con-
As mentioned above Properties are shared between tainer between Elements or Conditions. In finite ele-
elements. For this reason Element keeps a pointer to its ment problems there are several parameters which are the
Properties. This connection lets several elements to use same for a set of elements and conditions. Thermal conduc-
the same properties. tivity, elasticity of the material and viscosity of the fluid are
A DataValueContainer holds no historical data examples of these parameters. Properties holds these
in Element. Using a DataValueContainer provides
data and is shared by elements or Conditions. This elim-
flexibility and robustness which is useful in transferring el-
inates memory overhead due to redundant copies of these
emental data from one domain to another. As an example,
data for each element and Condition as shown in Fig. 19.
one may want to set a flag over elements say active or inac-
Properties also can be used to access nodal data if
tive. The DataValueContainer can be used easily for
it is necessary. It is important to mention that accessing the
this purpose. On the other hand a damage function may need
nodal data via Properties is not the same as accessing
history of some internal variable. This second result is best
achieved by implementing an application specific data base it via Node. When user asks Properties for a variable
inside Element. data in a Node, the process starts with finding the variable
in the Properties data container and if it does not exist
8.2.4 Conditional Data then get it from Node. This means that the priority of data
is with the one stored in Properties and then in Node.
Conditional data is very similar to elemental data and is
also divided into three different categories: properties, data 8.2.6 Entities Containers
and historical data. It is also keeps a pointer to its shared
Properties and uses a DataValueContainer to
Let us go one level higher in the Kratos data structure. The
hold all data without keeping its history. Any Condition
next level consists of four entities containers:
derived from this class can use this container to hold its data
without any additional implementation. This base class also • Nodes Container
provides an standard interface to these data which helps for • Properties Container
transferring some data from one Condition to another, • Elements Container
for example in the interaction between two domains. • Conditions Container
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 275
Fig. 20 Iterating time for 109 steps of iterations with different paring the performance of vector<pair<int,double> >,
containers. (a) Comparing the performance of double*, vec- list<pair<int, double> > and map<int,double>
tor<double>, list<double> and set<double>. (b) Com-
These containers are created to help users in grouping a anymore will be deallocated from memory automatically. So
set of entities and work with them. For example to put all a container of smart pointers to entities is used.
Nodes in the boundary into a Nodes container and change Arrays are very efficient in time of iterating as shown in
some of their data in each step. As mentioned earlier, each Fig. 20. So using an array to hold pointers to entities can
entity has access to its data, so having a set of entities in a increase the iteration speed. In contrary, trees are very slow
container also gives access to their data which make these in time of iterating but efficient for searching by index and
containers more useful in practice. a suitable container for using them can increase the searching performance of the
holding entities must provide the following features: code. A good solution to this conflict can be an ordered ar-
ray. It is fast in iteration like an array and also fast in search-
Sharing Entities There are some situations when an entity
ing like a tree as shown in Fig. 21. Its only draw back is that
may belong to more than one set of entities. For exam-
its less robust and its construction it can take considerable
ple a boundary Node belongs to the list of all Nodes
time depending on the order of input data. For example con-
and also to the list of boundary Nodes. So the Nodes
structing an array of Nodes with Nodes given by inverse or-
Container has to share some its data with other Nodes
der can take a very long time. However a buffer of unordered
Containers. In general, sharing entities is an important
data can significantly reduce the construction overhead. So
feature of these containers.
an ordered array can fit properly into our problem.
Fast Iterating Several procedures have to make a loop over
PointerVectorSet is a template implementation of
all the elements of a given container and use each element
an ordered array of pointers to entities. This template is used
or its data in some algorithms. So these containers must
to create different containers to hold different type of enti-
provide a fast iterating mechanism in order to reduce the
ties.
time of element by element iteration.
Search by Index Finding an entity by an index is a usual
8.2.7 Mesh
task in finite element programs. So entities containers
must provide an efficient searching mechanism to reduce
The next level in Kratos’ data structure is Mesh. It contains
the time of these tasks.
all the entities containers mentioned before. This structure
Sharing entities is the first feature to be provided by makes it a good argument for procedures that work with dif-
these containers. Holding pointers to entities and not entities ferent entities and their data. For example an optimizer pro-
themselves can solve this problem. Different lists can point cedure can take a Mesh as its argument and change geome-
to the same entity without problem. Using an smart pointer tries, nodal data or properties. Mesh is a container of con-
[26] instead of a normal pointer increases the robustness of tainers with a large interface that helps users to access each
the code. In this way entities that do not belong to any list container separately.
276 P. Dadvand et al.
Fig. 21 Time comparison for different searching algorithms vector<double> with binary search. (b) Comparing the perfor-
over sorted and unsorted containers. (a) Comparing the perfor- mance of vector<pair<int,double> > with brute-force key
mance of vector<double> with brute-force, list<double> finding, list<pair<int, double> > with brute-force key find-
with brute-force, set<double> binary tree search and sorted ing and map<int,double> binary tree search
Fig. 23 ProcessInfo’s
linked list mechanism for
holding the history of solution
ModelPart can store the same set of variables in their so- In Kratos an Element is an object which holds its data
lution steps container. It is important to mention that this and calculates elemental matrices and vectors to be assem-
variables list is assigned to the entities which belong to the bled and also can be used to calculate local results after the
model part and is not changed when that model part share analysis. For example a thermal element calculates the lo-
them with other model parts. Figure 25 shows this scheme. cal stiffness matrix and the mass matrix (if necessary) and
give it to Kratos for assembly process. Also it can be used
8.2.9 Model to calculate a thermal flow after solving the problem. This
definition provides a good isolation for Element related to
Model is the representation of the whole physical model to rest of the code which is helpful for the proper encapsulation
be analyzed with the FEM. The main purpose of defining of Element.
Model is to complete the levels of abstraction in the data The strategy [34] pattern is used to design Element
structure and a place to gather all data and also hold global structure as can be seen in Fig. 26. Using this pattern each
information. This definition makes it useful for performing Element encapsulates one algorithm separately and lets
global operations like save and loading. It holds references new algorithms to be added easily to Kratos without chang-
to model parts and provides some global information like ing other parts. Also this pattern keeps them compatible with
the total number of entities and so on. each other in order to let users interchange them, or even mix
them together in a complex model.
In Kratos Geometry holds a set of points or Nodes and
9 Finite Element Implementation provides a set of common operations to ease the implemen-
tation of Elements and Conditions. The bridge pattern
9.1 Elements is used to connect Geometry with Elements. Introducing
this pattern to our Element’s structure design results in the
Elements and Conditions are the main extension points structure shown in Fig. 27.
of Kratos. New formulations can be introduced into Kratos This pattern allows each Element to combine its for-
by implementing a new Element and its corresponding mulation with any geometry. In this way less implementa-
Conditions. This makes Element an special object in tion is needed. Also having a pointer to geometry allows an
our design. Element to share its geometry with other ones. The only
278 P. Dadvand et al.
drawback of this structure is the time overhead comes from pattern. However this structure is not implemented yet in
pointer redirection in memory. Having a pointer to geometry Kratos.
beside deriving from it creates a small overhead in accessing The finite element methodology is used for designing
geometrical data respect to an Element derived directly. a generic interface for Element. According to the fi-
Though efficiency in Element is crucial, the complexity nite element procedure, the Strategy asks Element to
of the first approach which one’s the first and which one is provide its local matrices and vectors, its connectivity in
the second approach imposes accepting the small different in form of equation id, and after solving also calls Element
to calculate the elemental results. So Element
performance and therefore we have implemented this second
provides three sets of methods. Calculate-
approach. A better solution is to make Element a template
LocalSystem, CalculateLeftHandSide and
of its geometry. Using templates provides good performance
CalculateRightHandSide for calculating local sys-
and also enough flexibility but it was considered to be too
tem matrices and vectors. EquationIdVector and
complex to be used by finite element users. As mentioned GetDofList are designed to provide assembling informa-
earlier an Element has to be easy to program with the less tion for Strategy. Finally, Calculate and
possible advanced features of programming language. So fi- CalculateOnIntegrationPoints are devoted to
nally the bridge pattern structure was selected. calculating elemental variable which are used mainly for
There are some designs in which different Elements calculating post-analysis results.
can be composed to create a more complex Element [58]. A VBI is used to provide a clear but flexible interface
This approach can be simulated here using a Composite for these methods.To ensure the extensibility of these meth-
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 279
BuildAndSolve and CalculateReactions are pro- order to automatize this process can be found in literature
vided for this purpose. There are also several other meth- [27–29, 48, 91].
ods for initializing the internal system matrices and vectors Nowadays several computer algebra systems like Matlab
and also to remove them from memory if it is necessary. [56], Mathematica [88], and Maple [55] can do this type of
Strategy can use this interface to implement its algo- symbolic derivations. In Kratos the first part of changing the
rithm using any of the procedures defined above. variational equation to weak form is dedicated to previous
tools and only a set of tools is designed and implemented
9.4.2 Scheme to help users converting their weak form to matrix form as
elemental contributions.
Scheme is designed to be the configurable part of Elemental expressions are designed and implemented
Strategy. It encapsulates all operations over the local to help users in writing their weak form expressions in
system components before assembling and updating of re- Element. The main idea is to create a set of classes and
sults after solution. This definition is compatible with time overloaded operator to understand a weak form formulation
integration schemes, so Scheme can be used for example to and calculate the local matrices and vectors according to it.
encapsulate the Newmark scheme. The definition of scheme For example in a simple heat conduction problem with
is quote general and can be used to encapsulate other similar isotropic coordinates, the elemental stiffness matrix S e can
operation over a solution component. be calculated as follows:
According to the template method pattern the impor-
tant steps of the solving procedure in standard finite ele- S ij = k (∇Ni )T I∇Nj d
e
ment strategies is used to design the interface of scheme.
Usually a finite element solving strategy consists of several or:
steps like: initializing, initializing and finalizing solution
S e ij = k(∇i Nl , ∇j Nl )
steps, initializing and finalizing non linear iterations, pre-
diction, update and calculating output data. Initialize, This equation can be implemented in Element by the
InitializeSolutionStep, FinalizeSolution- following code:
Step, InitializeNonLinIter-ation, Finalize-
NonLinIteration and Update represent these main for(int i=0 ; i < nodes_number ; i++)
for(int j=0 ; j < nodes_number ; j++)
steps. for(int l=0 ; l < gauss_points_number ; l++)
{
Matrix const& gn=shape_functions_gradients[l];
9.5 Elemental Expressions
for(int d=0 ; d < dimension ; d++)
The finite element methodology usually consists of first rLeftHandSideMatrix(i,j) += k*gn(i,d)
*gn(j,d)*wdj;
converting the governing differential equation to its weak }
form. This is discretized over an appropriate approximation
space, and finally global system of matrix equation is built Using elemental expressions the same formulation can be
from the elemental contributions. Different approaches in written in a simpler form as:
282 P. Dadvand et al.
KRATOS_ELEMENTAL_GRAD_N(i,l) grad_Nil(data); with new variables and data types. Also providing some ad-
KRATOS_ELEMENTAL_GRAD_N(j,l) grad_Njl(data);
ditional features like multi format and media support, seri-
rLeftHandSideMatrix = k*(grad_Nil, grad_Njl)*wdj; alization [1] and script language support are very useful.
It can be seen that the later form is conforming with the 10.1 IO Structure Design
symbolic notation of equations which makes it much easier
to implement. The overloading operators provided in C++ The Strategy pattern is used to encapsulate each format sep-
is the start point for implementing the code. Simple over- arately and make it extensible to any new format easily. The
loading results in poor performance due to the redundant same structure can be used for supporting different media
temporary objects that creates. Expression template tech- separately. Then the Bridge pattern can be used to
nique can be used to convert above expression to previous connect them to the format structure. However a simpler ap-
hand written form automatically. Template metaprogram- proach is to treat the media like formats and use the same
ming also is used to impose the tensorial notation. All these structure for both and enrich it via templates or several lev-
techniques are used to evaluate the symbolic notation and els of hierarchy as shown in Fig. 31.
generate an specialized code for each case. There are different concepts (like temperature, displace-
In the current version of Kratos, element expressions are ment, viscosity, etc.) and data types in a FEM data. Support-
still in experimental phase. However some benchmarks have ing different concepts and data type is very important for a
shown that their efficiency is comparable with hand coded multi-disciplinary code. Here the VBI comes handy and it is
Elements as supposed to be. used to generalize the IO.
The first step is providing IO extendibility to new con-
9.6 Formulations cepts. This can be done by introducing a lookup table which
relates the concept names and their internal handlers. A sim-
Kratos has been designed to support element approaches in ple list of Variables is enough for IO to take as its
finite element methods. For some problems an element ap- lookup table. Each Variable knows its name and also
proach is less suitable than other approaches like nodal for- its reference number. In time of reading IO reads a tag and
mulations. Formulation is defined as a place for imple- searches in the list for the Variable whose name coin-
menting all these approaches. Formulation is not imple- cides with the tag. Then use the variable to store the tagged
mented yet, but will be one of the future features of Kratos. value in the data structure. For example, when IO reads
a "NODES[29](TEMPERATURE,0)=418.651" state-
ment from input, it takes the "TEMPERATURE" tag and
10 Input-Output searches in the list to find the TEMPERATURE variable.
Having this variable is enough to use the variable base in-
In general most finite element applications have to commu- terface of the data structure to store the value in it. For writ-
nicate with pre and post processors, except in some special ing results there is no need to search in the table. IO can use
cases for which the application generates its own input. This the variable to get its value in the database and use its name
makes the input-output (IO) operation an essential part of as the tag. Here is an example of WriteNodalResults
the application. For a multi-disciplinary code IO must deal method.
Fig. 32 Using
KratosComponents in IO
to distinguish them in the time of search. Doing this also Table 1 Some typical tokens with examples of matching sequences
eliminates unnecessary type casting and makes the imple- Token’s Type Examples
mentation easier and clearer. Figure 32 shows the resulting
structure. INTEGER 1 34 610
Finally an interpreter is necessary to provide the script REAL 4.57 2e-4
language input feature for this module. This feature provides IF if
a high level of extensibility in algorithms which is very use- FOR for
ful in order to deal with different algorithms as is typical in LPARENTHESES (
multi-disciplinary applications. RPARENTHESES )
There are various ways to implement a lexical analyzer From the long list of languages first some of more pop-
and a parser in the literature [5, 6, 9]. Also there are some ular ones were selected: Lisp, Perl, Ruby, Tcl and Python.
tools to generate them. Some classical ones are Lex and Python was finally selected due to some details and also our
Yacc, and their derivatives like Fast lexical analyzer genera- background. Tcl was a good choice as it is already used at
tor (Flex) and Bison and their C++ variations Flex++ and CIMNE for example in GiD [72, 73] and a large amount of
Bison++. experience was available. Lack of object-oriented features
The first interpreter for Kratos was implemented using however prevented this choice. Perl also was considered for
Flex++ and Bison++. They are great tools to generate an its maturity and performance, but again it is less object-
interpreter but they have been put aside from this work for oriented than Python and does not support multi-threading.
mainly two reasons. The first was changes in the strategy Ruby at that time was completely new to us and also was
of code development creating a sophisticated interpreter to considered to be somehow young. An existing well designed
using an existing one. For reading data still a simple parser interface to Python and some practical use of Python in finite
was necessary, but these tools were too heavy to be used for element applications [3, 4] were another reasons for choos-
this case. The other reason was portability and maintainabil- ing Python.
ity issues, specially in Windows, due to the incompatibili- Binding Kratos to Python makes it extremely flexible and
ties between the Linux and Windows compilations of these extendible. New algorithms can be implemented using ex-
tools. The current interpreter is implemented using Spirit. isting Kratos tools and methods without even recompiling
Spirit is an object-oriented parser generator framework the code. Interaction between domains and planning differ-
implemented in C++ using template meta-programming ent staggered strategies to solve a coupled problem also can
techniques which enable us to write the context free gram- be performed easily at this level without changing Kratos
mar directly in C++ code and compile it with a C++ code or its applications. Also Python it can be used as a small
to generate the parser. In this way the translation step from lab for testing new algorithms and formulations before pro-
context free grammar to a parser implemented in C++ by gramming it into the Kratos. The list of added features is
an external tool is omitted. This interpreter can be used to unlimited and many complex tasks can be done easily using
read a data file containing nodes, elements, properties, con- this interface.
ditions, and initial values and automatically reads any new
variable in the variables list. 10.3.1 Binding to Python
10.3 Using Python as Interpreter
Boost Python library is used for binding Kratos to Python.
Implementing an interpreter is a hard work. From the man- This library provides an easy but powerful way to connect a
agement point of view, it introduces a significant overhead C++ code to Python.
to project cost and time. Maintaining it is even harder and re-
sults in more overhead in the code cost. Also implementing
an interpreter requires knowledge of different concepts like 11 Validation Examples
grammar notations, some tools and libraries usage and com-
piler implementation techniques. Finite element program- In this chapter some applications developed using Kratos are
mers usually are not familiar with most of these concepts presented to test the desired flexibility and extensibility of
and in many cases even do not like to deal with them. So in the framework.
developing a finite element program it is not easy to share
the implementation and maintenance of an interpreter with 11.1 Incompressible Fluid Solver
others due to this lack of experience. In practice, this can
lead to longer implementation times and extra cost. The Kratos features an incompressible CFD solver, im-
During the development of Kratos all these facts affected plemented in an “incompressible fluid application”. Both
the implementation of an interpreter and made its develop- monolithic and fractional step solvers (see [22]) are imple-
ment more and more difficult to the point that it became one mented in the same application. Most of the examples de-
of the bottlenecks of the project. Consequently, the strategy scribed in the following section were run using a Fractional-
changed by stop writing an interpreter and looking for an Step type approach, in order to achieve maximal efficiency.
existing one.
For selecting a script language, the following require- 11.1.1 Implementation in Kratos
ments are used as selection criteria: interface to C++ or
at least to C. Portability. To be object-oriented. Language The main CFD solvers of the Kratos are based on an Ar-
syntaxes and its readability. Flexibility and extendibility and bitrary Lagrangian Eulerian (ALE) formulation. The solver
popularity used in the examples is based on a fractional step method
286 P. Dadvand et al.
steps. The strategy was hard coded in C++, however the //correct velocities
implementation was such that all the different steps could SolveStep4();
KRATOS_CATCH("")
double FracStepSolution() }
{
// setting the fractional velocity to
// the value of the velocity Where Stage1 and Stage2 are private methods.
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 287
def SolutionStep1(self):
normDx = Array3(); normDx[0] = 0.00; normDx[1] = 0.00; normDx[2] = 0.00;
is_converged = False
iteration = 0
def Solve(self):
if(self.ReformDofAtEachIteration == True):
(self.neighbour_search).Execute()
(self.solver).InitializeFractionalStep(self.step, self.time_order);
(self.solver).InitializeProjections(self.step);
(self.solver).AssignInitialStepValues();
self.SolutionStep1()
(self.solver).SolveStep2();
(self.solver).ActOnLonelyNodes();
(self.solver).SolveStep3();
(self.solver).SolveStep4();
self.step = self.step + 1
11.1.2 Benchmark for the cylinder. Figure 36 shows a view of velocity field
obtained.
Kratos is a general purpose code. Therefore, it is expected to The results showed an excellent agreement with the val-
show a slightly lower performance than codes optimized for ues calculated by FEFLO both in term of peak values and of
a single purpose. A well optimized implementation can re- shedding frequency, as can be seen in Fig. 37. Note that the
duce the performance overhead to the amount introduced by initiation of the shedding is not deterministic and may hap-
Kratos. An effort was made to optimize the implementation pen at any time which justifies the phase difference between
mentioned above, so it is interesting to compare its perfor- the two codes.
mance against existing fluid solvers in order to estimate the The timing results are interesting. FEFLO appeared to be
order of performance overhead introduced by Kratos. 50% faster than Kratos. This is considered a good result tak-
As usual it is not trivial to perform a good benchmark ing in account that FEFLO features a highly optimized edge
as each program implements a slightly different formula- based data structure while Kratos is purely element based.
tion. Nevertheless a comparison was possible here with the On the other hand, Zephyr features an element based for-
code Zephyr, an in house program developed at UPC, and mulation and implements the same fractional method step.
with FEFLO a highly optimized fluid solver developed at The main difference was the treatment of the projection
the Laboratory for Computational Physics and Fluid Dy- terms and the use of four integration points for the calcu-
namics (LCPFD) in George Washington University at Wash- lation of the element contributions in Zephyr. The results
ington, DC [45]. For the first case the formulation is exactly showed that Kratos is about twice as faster than Zephyr.
the same with only minor differences in the implementation.
The second solver is an edge based formulation and the only 11.2 Fluid-structure Interaction
possible comparison was with a predictor corrector scheme.
The benchmark represents the analysis of a three dimen- Coupled problems can be naturally implemented inside
sional cylinder at Reynolds number Re = 190. Figure 35 Kratos via the Python interface. The fluid solver and the
shows the model used. The no slip boundary condition is structural solver can be implemented separately and coupled
used at the walls of the cylinder, while slip conditions are using this interface. The first action required to solve a fluid
used everywhere else. The inflow velocity is set to 1 m/s. structure interaction (FSI) problem is to load the different
The mesh generated by FEFLO has a resolved boundary applications involved. The code in Table 3 shows this step
layer and contains 30000 nodes and 108000k tetrahedral el- in Python. Then a very simple explicit coupling procedure
ements. The values computed were the lift and drag history can be expressed by a Python script as shown in Table 4.
288 P. Dadvand et al.
Fig. 37 (Color online) The comparison of results obtained by Kratos (red line) using a predictor corrector scheme and FEFLO (blue line). (a) Lift
calculated for the cylinder. (b) Drag calculated for the cylinder
Table 3 Importing different applications involved in solving the FSI coupled problem
#importing applications
import applications_interface
applications_interface.Import_ALEApplication = True
applications_interface.Import_IncompressibleFluidApplication = True
applications_interface.Import_StructuralApplication = True
applications_interface.Import_FSIApplication = True
applications_interface.ImportApplications(kernel, kratos_applications_path)
class ExplicitCoupling:
def Solve(self):
works, of which the multilayer perceptron is an important training algorithm will evaluate the performance function
one [81]. Neural networks provide a direct method for the f (a) many times.
solution of general variational problems and, consequently,
This algorithm provides an example of how Kratos can be
inverse problems [20].
embedded into an optimization application in which differ-
In this example neural networks are used to solve thermal ent steps of finite element analysis are necessary to achieve
inverse problems. In order to solve this problem we need to the solution.
solve the heat transfer equation. The Flood library [51] de- Kratos has been embedded inside the Flood library as its
veloped at CIMNE is an open source neural networks library solving engine in order to calculate the solution of partial
written in C++. Flood was used to create the neural network differential equations.
necessary for solving this problem. While the Flood library Here this methodology is applied to solve two different
does not include utilities for solving partial differential equa- thermal inverse problems.
tions, it uses Kratos and its thermal application to solve the
thermal problem. This example validates the integrability of 11.4.2 Implementation
Kratos as a library into another project. It also demonstrates
its robustness due to the fact that the Neural Network algo- The Flood library uses Kratos to solve a thermal problem
rithm runs Kratos to analyze the same model several times. several times with different properties and boundary condi-
In this situation any small problem (for example, in memory tions. In order to do this it access the internal data of Kratos
management) might cause an execution error. and change the boundary conditions assigned to the different
Nodes. This is done without any file interface which would
11.4.1 Methodology dramatically reduce the performance. The first task is imple-
ment the interface for the direct solution using Kratos. The
The general solution of variational problems using Neural following code shows the main part of this interface:
networks consists of three steps [20]:
// Initializing Kratos kernel
Kernel kernel;
• Definition of the functional space. The solution here is kernel.Initialize();
represented by a multilayer perceptron.
// Initializing Kratos thermal application
• Formulation of the variational problem. For this perfor- KratosThermalApplication thermal_application;
mance functional F (y(x, a)) must be defined. In order kernel.AddApplication(thermal_application);
to evaluate the functional we solve a partial differential // Read mesh
equation using the FEM within Kratos. GidIO gidIO("thermal_problem");
• Solution of the reduced function optimization problem gidIO >> mesh;
f (a). This is achieved by the training algorithm. The // Set properties to optimization values d,c,k
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 291
Fig. 38 Flag flatter simulation using fluid structure interaction with mesh movement
Table 5 Implementation in Kratos of particle finite element method ible but clear and intuitive interface that Kratos provides
(PFEM)
for other applications to communicate with it. First, applica-
tion changes the Element properties to its prescribed val-
def Solve(self,time,gid_io):
ues. Then, it changes the temperature value for all Nodes
self.PredictionStep(time) to some initial value. Afterwards it tries to solve the FEM
self.FluidSolver.Solve()
problem using different boundary conditions assigning fixed
def PredictionStep(self,time): values of temperature to Nodes. Finally it retrieves the tem-
domain_size = self.domain_size
perature at a specific Node. It can be seen that some steps
# performing a first order prediction are directly inside the time loop. This restrict us from solv-
# of the fluid displacement
(self.PfemUtils).Predict(self.model_part)
ing the problem using usual time integration algorithms.
self.LagrangianCorrection() The inverse problem also involves similar steps but in the
(self.MeshMover).Execute();
form of performance functions of the Flood library. In this
(self.PfemUtils).MoveLonelyNodes(self.model_part) case Kratos is adapted to the working methodology of Flood
(self.MeshMover).Execute();
without any problem.
## ensure that no node gets too close to the walls The tool obtained by combining these two application has
(self.ActOnWalls).Execute();
been successfully used for solving boundary temperature es-
## move the mesh timation problems and diffusion coefficient estimation prob-
(self.MeshMover).Execute(); lems [20, 52].
## smooth the final position of the nodes to Some results can be seen in Fig. 41 which shows the
## homogenize the mesh distribution agreement between the estimated diffusion coefficient and
(self.CoordinateSmoother).Execute();
the diffusion coefficient estimated by the neural network for
## move the mesh a square domain problem.
(self.MeshMover).Execute();
The results of a different inverse problem are shown in
# regenerate the mesh Fig. 42. The graphs shown distribution a comparison of the
self.Remesh()
actual boundary temperature and the one estimated by the
neural network for a square domain.
Full details of the examples, as well as a complete de-
scription of the theory used can be found in [52].
Further applications and other class of problems imple-
mented in Kratos can be found in [2, 61, 74–76, 79].
12.1 Conclusions
Fig. 40 Impact of wedges with different shapes on the surface of the water
the application development not only faster, but also ensures tainers are used alternatively in places where performance or
compatibility with other tools for solving multi-disciplinary flexibility are more important. Being able to store even the
problems. list of neighbor Nodes or Elements shows their flexibility
Kratos is also extensible at different levels of implemen- in practice.
tation. Each application can add its variables, degrees of An entity base data structure has been developed in
freedom, Properties, Elements, Conditions, and Kratos. This approach gives more freedom in partition-
solution algorithms to Kratos. The object-oriented structure ing the domain or in creating and removing Nodes and
and appropriate patterns used in its design make these ex- Elements. Several levels of abstraction like Mesh,
tensions easy while reducing the need for modifications. MoldePart and Model are provided to help users group
Last but not least, the performance of Kratos is compa- model and data information in different ways. These objects
rable even to single purpose programs and different bench- are effectively used for separating domains information in
marks has shown this in practice. This makes Kratos a prac- multi-disciplinary problems or sending a single part to a
tical tool for solving industrial multi-disciplinary problems. process.
All these objectives were achieved not only by a num- The Element and Condition classes are designed
ber of innovative development, but also by collecting and as the extension points of Kratos. Their generic interfaces
reusing several existing works. Some of these aspects are as provide all information necessary for calculating their local
follow: components and also are flexible enough for handling new
Kratos has an object-oriented and multi-layer structure arguments in the future.
which reduces the dependency between different parts of Several processes and strategies has been developed to
program. It helps in maintenance of the code and also helps handle standard procedures in finite element programming.
developers in understanding the code. These layers are de- These components increase the reusability of the code and
fined in a way such as each user has to work in the smallest decrease the effort needed to implement new finite element
number of layers as possible. The implementation difficul- application using Kratos.
ties needed for each layer are also tuned for the knowledge Some experimental work has been done to handle ele-
of users. mental expression using a higher level of abstraction. In this
A new variable base interface has been designed and im- way elemental expressions can be written in C++ but with
plemented. This interface is used at different levels of ab- a meta language very similar to mathematical notations and
straction and has proven to be clear, flexible, and extensible. then can be compiled with the rest of the code using the
New heterogeneous containers have been implemented C++ compiler. These expressions have been successfully
in order to hold different types of data without any modi- tested and their performance is comparable to manually im-
fications. The DataValueContainer is designed to be plemented codes.
very flexible while the VariablesListContainer is A flexible and extensible IO module for finite element
designed to be fast but less robust. In Kratos these two con- programs has been developed. Any application built with
294 P. Dadvand et al.
Kratos can use IO for reading and writing its own concepts 12.2 Future Work
without making any change to it. An interpreter is also im-
plemented to handle Kratos data files but the major inter- Parallelization of Kratos framework is the main task to be
preting task is given to the Python interpreter. This flexi- undertaken in the future. The growing size of problems and
ble interpreter with its object-oriented high level language the increase of available parallel computing machines (even
can be used to implement and execute new algorithms us- in the personal computers sector), stress the importance for
ing Kratos. In this way the implementation and maintenance parallelization of numerical codes. Fortunately, several as-
cost of a new sophisticated interpreter is eliminated. pects of Kratos become useful in this process.
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 295
28. Eyheramendy D, Zimmermann T (1996) Object-oriented finite el- 53. Mackie RI (1992) Object oriented programming of the finite ele-
ements ii. a symbolic environment for automatic programming. ment method. Int J Numer Methods Eng 35(2):425–436
Comput Methods Appl Mech Eng 132(3):277–304(28) 54. Mackie RI (1997) Using objects to handle complexity in finite el-
29. Eyheramendy D, Zimmermann T (1998) Object-oriented finite ement software. Eng Comput 13(2):99–111
elements iii. theory and application of automatic programming. 55. Maplesoft. Maple’s documentation
Comput Methods Appl Mech Eng 154(1):41–68(28) 56. MathWorks. Matlab’s documentation
30. Felippa CA, Geers TL (1988) Partitioned analysis of coupled me- 57. Menetrey P, Zimmermann T (1993) Object-oriented non-linear fi-
chanical systems. Eng Comput 5:123–133 nite element analysis: application to j2 plasticity. Comput Struct
31. Felippa CA, Park KC, Farhat C (2001) Partitioned analysis of 49(5):767–773
coupled mechanical systems. Comput Methods Appl Mech Eng 58. Miller G (1991) An object-oriented approach to structural analysis
190:3247–3270 and design. Comput Struct 40(1):75–82
32. Filho JRA, Devloo PRB (1991) Object oriented programming in 59. Miller G (1994) Coordinate-free isoparametric elements. Comput
scientific computations: the beginning of a new era. Eng Comput Struct 49(6):1027–1035
8(1):81–87 60. Miller GR, Banerjee S, Sribalaskandarajah K (1995) A framework
33. Forde BWR, Foschi RO, Stiemer SF (1990) Object-oriented finite for interactive computational analysis in geomechanics. Comput
element analysis. Comput Struct 34(3):355–374 Geotech 17(1):17–37
34. Gamma E, Helm R, Johnson R, Vlissides J (1995) Design patterns: 61. Mora J, Otín R, Dadvand P, Escolano E, Pasenau MA, Oñate E
elements of reusable object-oriented software. Addison-Wesley, (2006) Open tools for electromagnetic simulation programs.
Reading COMPEL 25(3):551–564
35. Gonnet GH, Baeza-Yates R (1991) Handbook of algorithms and 62. Mount D, Arya S (1997) Ann: A library for approximate nearest
data structures: in Pascal and C, 2nd edn. Addison-Wesley, Read- neighbor searching. citeseer.ist.psu.edu/mount97ann.html
ing 63. Oñate E (2004) Possibilities of finite calculus in computational
36. Haykin S (1994) Neural networks: A comprehensive fundation. mechanics. Int J Numer Methods Eng 60(1):255–281
Prentice Hall, New York 64. Oñate E, Idelsohn S, Celigueta M, Rossi R (2008) Advances in the
37. Idelshon SR, Oñate E (2006) To mesh or not to mesh. That is the particle finite element method for the analysis of fluid-multibody
question. Comput Methods Appl Mech Eng 195:4681–4696 interaction and bed erosion in free surface flows. Comput Methods
38. Idelsohn SR, Oñate E, Calvo N, Pin FD (2003) The meshless finite Appl Mech Eng 197:1777–1800
element method. Int J Numer Methods Eng 58:893–912 65. Oñate E, Idelsohn S, Pin FD, Aubry R (2004) The particle finite
39. Idelsohn SR, Oñate E, Pin FD (2004) The particle finite element
element method. An overview. Int J Comput Methods 1(2):267–
method: a powerful tool to solve incompressible flows with free-
307
surfaces and breaking waves. Int J Numer Methods Eng 61:964–
66. Open Engineering. OOFELIE
989
67. Patzák B. OOFEM documentation. Czech Technical University,
40. Idelsohn SR, Pin FD, Rossi R, Oñate E (2009) Fluid-structure in-
Faculty of Civil Engineering, Department of Structural Mechan-
teraction problems with strong added-mass effect. Int J Numer
ics
Methods Eng 80:1261–1294. doi:10.1002/nme.2659
68. Patzák B, Bittnar Z (1999) Object oriented finite element model-
41. Kirsch A (1996) An introduction to the mathematical theory of
ing. Acta Polytech 39(2):99–113
inverse problems. Springer, Berlin
69. Pidaparti RMV, Hudli AV (1993) Dynamic analysis of structures
42. Klapka I, Cardona A, Geradin M (1998) An object oriented im-
using object-oriented techniques. Comput Struct 49(1):149–156
plementation of the finite element method for coupled problems.
Rev Eur Elements Finis 7(5):469–504 70. Press WH, Vetterling WT, Teukolsky SA, Flannery BP (2002) Nu-
43. Klapka I, Cardona A, Geradin M (2000) Interpreter oofelie for merical recipes in C++: the art of scientific computing. Cam-
pdes. In: European congress on computational methods in applied bridge University Press, Cambridge
sciences and engineering (ECCOMAS 2000), Barcelona 71. Raphael B, Krishnamoorthy CS (1993) Automating finite ele-
44. Knuth DE (1998) The art of computer programming: sorting and ment development using object oriented techniques. Eng Comput
searching, vol 3, 2nd edn. Addison-Wesley, Reading 10(3):267–278
45. Laboratory for Computational Physics and Fluid Dynamics 72. Ribó R, Pasenau M, Escolano E, Ronda JSP. GiD user manual.
(LCP&FD). FEFLO project CIMNE, Barcelona
46. Larese A, Rossi R, Oñate E, Idelsohn SR (2008) Validation of 73. Ribó R, Pasenau M, Escolano E, Ronda JSP, González LF. GiD
the particle finite element method (pfem) for simulation of free reference manual. CIMNE, Barcelona
surface flows. Eng Comput 25:385–425 74. Rossi R (2005) Light weight structures: structural analysis and
47. Lindemann J, Dahlblom O, Sandberg G (2006) Using Corba mid- coupling issues. PhD thesis, University of Bologna
dleware in finite element software. Future Gener Comput Syst 75. Rossi R, Idelsohn SR, Oñate E (2006) On the possibilities and
22(1–2):158–193 validation of the particle finite element method (pfem) for complex
48. Logg A (2007) Automating the finite element method. Arch Com- engineering fluid flow problems. In: Proceedings of ECCOMAS
put Methods Eng 14(2):93–138 CFD 2006, Egmond aan Zee, The Netherlands
49. Lu J, White D, Chen W-F (1993) Applying object-oriented de- 76. Rossi R, Oñate E (2010) Validation of a fsi simulation
sign to finite element programming. In: SAC ’93: proceedings of procedure—bridge aerodynamics modelproblem. Eng Comput
the 1993 ACM/SIGAPP symposium on applied computing. ACM, (to appear)
New York, pp 424–429 77. Rossi R, Oñate E (2010) Analysis of some partitioned algo-
50. Lu J, White DW, Chen W-F, Dunsmore HE (1995) A matrix class rithms for fluid-structure interaction. Eng Comput 27:20–56.
library in C++ for structural engineering computing. Comput doi:10.1108/02644401011008513
Struct 55(1):95–111 78. Rossi R, Ryzhakov P, Oñate E (2009) A monolithic fe formula-
51. López R. Flood: an open source neural networks C++ library. tion for the analysis of membranes in fluids. Int J Space Struct
CIMNE 24(4):205–210
52. López R, Balsa-Canto E, Oñate E (2008) Neural networks for 79. Rossi R, Vitaliani R (2004) Numerical coupled analysis of flexible
variational problems in engineering. Int J Numer Methods Eng structures subjected to the fluid action. In: 5th PhD symposium in
75(11):1341–1360 civil engineering, Delft
An Object-oriented Environment for Developing Finite Element Codes for Multi-disciplinary Applications 297
80. Saad Y (2003) Iterative methods for sparse linear systems. Society in object-oriented parallel environments (ISCOPE’97). Springer,
for Industrial and Applied Mathematics, Philadelphia Berlin, Heidelberg, New York, Tokyo
81. Šíma J, Orponen P (2003) General-purpose computation with 87. Vinoski S (1997) CORBA: integrating diverse applications within
neural networks: A survey of complexity theoretic results. Neural distributed heterogeneous environments. IEEE Commun Mag,
Comput 15(12):2727–2778 14(2)
82. Touzani R. OFELI documentation 88. Wolfram Research. Mathematica’s documentation
83. Touzani R (2002) An object oriented finite element toolkit. In: 89. Zienkiewicz OC, Taylor RL, Zhu JZ (2007) Finite element
Proceedings of the fifth world congress on computational mechan- method: its basis and fundamentals. Butterworth-Heinemann,
ics (WCCM V) Stoneham
84. Veldhuizen TL (1995) Expression templates. C++ Rep 7(5):26– 90. Zimmermann T, Dubois-Pèlerin Y, Bomme P (1992) Object-
31 oriented finite element programming: I: Governing principles.
85. Veldhuizen TL (1998) Arrays in blitz++. In: Proceedings of the Comput Methods Appl Mech Eng 98(2):291–303
2nd international scientific computing in object-oriented parallel 91. Zimmermann T, Eyheramendy D (1996) Object-oriented finite el-
environments (ISCOPE’98). Lecture notes in computer science. ements i. principles of symbolic derivations and automatic pro-
Springer, Berlin gramming. Comput Methods Appl Mech Eng 132(3):259–276
86. Veldhuizen TL, Jernigan ME (1997) Will C++ be faster than For- (18)
tran? In: Proceedings of the 1st international scientific computing