Numerial Method Interface

In order to solve the governing equation, the instance of a suitable numerical method is created. Engng model may use different numerical methods, depending, for example, on problem size or previous convergence.

Typically, each particular Engng model instance is responsible for mapping of its governing equation components to corresponding numerical components. Such mapping allows the numerical method implementation to be independent of a particular physical problem by strictly dealing with numerical components, which are mapped to corresponding physical components of governing equation, that are hidden to numerical method.

Engng model must also provide services for updating its components, if this is necessary. These are used, when the Numerical Method instance needs to update some components during solution (for example in the Newton Raphson algorithm for the solution of non-linear equations, stiffness has to be updated after each iteration). Similarly, a high-level numerical method may use the services of another low-level numerical method (solver for non-linear system of equations uses linear solver for linearized problem). Numerical method instance may also represent an interface to a procedure in C or Fortran (see Fig. [*].).

Figure 2: Engng model - Numerical method Interface.

Figure 3: Engng model - Numerical method Interface.

The derived classes from Numerical method are supposed to declare the interface for specific problem type (like solution of linear system). The interface usualy consist in declaring virtual abstract function solve, with parameters corresponding to problem under consideration. The solve method shoud return value of NM_Status type. The data are specified using parameters passed to solve method (so called mapping). (Other optional parameters can be provided via instanciateYourself service, which receives the init record of corresponding metastep).

It should be pointed out, that all numerical methods solving the same numerical problem use the same genaral interface (same mapping) - this is enforced by using the same base problem-specific class. It is therefore possible to use any suitable instance of the Numerical method class to solve the problem, and leave the whole engineering model code, including mapping, unchanged, because all instances of the Numerical method class provide the common interface.

This concept is further enhanced by the introduction of a base abstract class for all sparse matrices. This class only declares the basic required services provided by all sparse matrices (like multiplication by a vector, possible factorization, etc). The implementation is left on derived classes. Numerical methods are then implemented only using basic services declared by the Sparse Matrix class. Thus, numerical method class instances will work with any sparse matrix class, even those added in the future, without changing any code, because all derived classes of the Sparse Matrix class implement the same interface.

The declaration of SparseLinearSystem class (typical problem-specific base class defining the interface for solving sparse system of equations) is listed to illustrate the basic concepts.

//   **********************************
//   *** CLASS SparseLinearSystemNM ***
//   **********************************

#ifndef sparselinsystemnm_h

#include "nummet.h"
#include "cltypes.h"
#include "typeInfo.h"
#include <stdio.h>
class EngngModel ; class SparseMtrx; class FloatArray; 

This base class is an abstraction for all numerical methods
solving sparse linear system of equations. 
The purpose of this class is to declare the general interface
to all numerical methods solving this kind of problem. 
This interface allows to use any suitable instance of the 
Numerical method class to the solve problem,
and leave the  whole engineering model code,
including mapping, unchanged, because all instances of this class
provide the common interface.
class SparseLinearSystemNM : public NumericalMethod
	/// Constructor
	SparseLinearSystemNM (int i, Domain* d,EngngModel* m);
	/// Destructor
	~SparseLinearSystemNM ();

	// identification 
	/// Returns class name of the receiver.
	char*  giveClassName (char* s) const 
	{ return strcpy(s,"SparseLinearSystemNM") ;}
	/** Returns classType id of receiver.
		@see FEMComponent::giveClassID 
	classType giveClassID () const { return SparseLinearSystemNMClass ;}

		Solves the given sparse linear system of equations Ax=b.
		@param A coefficient matrix 
		@param b right hand side
		@param x solution array
		@return NM_Status value
	virtual NM_Status solve (SparseMtrx* A, FloatArray* b, FloatArray* x) = 0;


#define sparselinsystemnm_h

To summarize, the natural independence of the problem formulation, numerical solution of the problem, and data storage format have been obtained, which leads to a modular and extensible structure of the engineering model - numerical method frame.

Borek Patzak 2018-01-02