Download elsA Design and Implementation Tutorial
Transcript
elsA
DSNA
6.3.2
Design and Implementation Tutorial
Ref.: /ELSA/MDEV-06001
Version.Edition : 1.0
Date : Jan 10, 2006
Page :
29 / 75
Examples
If called from inside a C++ method, a Fortran subroutine has first to be declared in a prototype, such as 1 :
extern "C"
{
void
denconvec_(const E_Int& ncell, const E_Int& neqtot, const E_Int& neq,
const E_Int& ro, const E_Int& rou, const E_Int& roe,
const E_Int& rog, const E_Int& roug, const E_Int& roeg,
const E_Float* consvar, const E_Float* press,
E_Float* fdx, E_Float* fdy, E_Float* fdz);
}
It is important to note that each argument is passed by address (reference for scalar, pointer for array), not by value (see
Calling Fortran subroutine).
Then, in the C++ method, the Fortran subroutine is called by:
denconvec_(ncell, neqTot, nbEqMoyComp,
rho, mom, ene, rhoG, momG, eneG,
wCons.begin(), press.begin(),
fdx.begin(), fdy.begin(), fdz.begin() );
The use of fdX.begin() allows to point on the begining of the piece of memory where the values of the field fdX
are stored. To get this address, it is convenient to use the iterator mechanism whose member functions are begin(),
end().
Notation: fdX.begin() stands for fdX.begin(1) (1 is the default value). If it is needed to manipulate the second
field (corresponding to rou) the method begin has to be used with the argument 2: fdX.begin(2).
It is obvious to see that if we change the two-dimensional structure choice (first index increases first), the method begin() will not provide the same collection of entities. In this case, and if dimensions of fdX are: ncell x neq, values
of fdX will be stored in the following order:
fdX(
0,1), fdX(0,2), fdX(0,3),..., fdX(
0,neq),
...,
fdX(ncell-1,1), ...,
fdX(ncell-1,neq)
instead of:
fdX(0, 1), fdX(1,1),fdX(2,1),..., fdX(ncell-1, 1),
...,
fdX(0,neq),...,
fdX(ncell-1,neq)
Finally, in the Fortran subroutine, we find the following implementation:
SUBROUTINE denconvec(ncell, neqtot, neq,
&
ro, rou, roe,
&
rog, roug, roeg,
1
See also "elsA Coding Rules"