### Focus Manuals: Programing Guide: Operations on structures

links from Programing Guide

#### Operations on structures

The functions and subroutines described below are used for manipulating structures without having to know how they are arranged. This paragraph will be limited to the functions related to the notion of structure itself. The traditional operations on matrices and vectors will be dealt with in Chapter A.III.

All the functions described hereafter will be naturally declared by a

statement at the beginning of subroutines. Otherwise they would have to be declared as **USE BIEF**

.
**EXTERNAL**

#### General operations on structures

##### LOGICAL FUNCTION CMPOBJ(T1,T2)

Up to now

is a vector or a block, as is **T1**

.
**T2**

indicates if the two structures are identical. A check is made to see whether these two structures are of the same type and, if so, their characteristics are compared:
**CMPOBJ**

- for vectors: discretisation.
- for blocks: the number of structures that it contains.

Nothing has been done so far for the other structures.

This function is used by subroutine

.
**OS**

#### Operations on vectors

##### SUBROUTINE CHGDIS(VEC,OLDELT,NEWELT,MESH)

changes the discretisation of a vector.
**CHGDIS**

is the vector**VEC**

the structure containing the mesh integers**MESH**

is the former vector discretisation and**OLDELT**

is the new one.**NEWELT**

A vector can thus go from a linear discretisation to a quasi-bubble discretisation, or the reverse. In the first case, the missing values are found by linear interpolation, while in the second case the superfluous values are forgotten. There are certain restrictions to the use of this subroutine:

- A vector cannot be extended if the required memory space is not provided for during allocation.
- Certain changes are impossible, for obvious reasons: changing a triangle to a quadrilateral, etc.

##### SUBROUTINE CPSTVC(T1,T2)

This subroutine copies a vector structure onto another. If

is a vector, **T1**

then becomes a vector with the same characteristics. Nevertheless, the memory allocated during allocation cannot be changed. The only data copied for the moment are:
**T2**

- Discretisation type (component

)**ELM** - The first dimension (component

)**DIM1** - The second dimension (component

)**DIM2** - The component

in case of discontinuous vectors.**DIMDISC**

This subroutine should be used when dealing with temporary all purpose

structures like **BIEF_OBJ**

, **T1**

, etc. in TELEMAC-2D and SISYPHE and **T2**

, **T3_01**

, etc. in TELEMAC-3D. As a matter of fact, these structures may have been changed by a previous use, e.g. they may have been turned into boundary vectors with a smaller size than a full domain vector, hence an initialisation like **T3_02**

may have a random effect if not secured previously by specifying what must be **CALL OS('X=0 ',X=T1)**

. Copying the structure of a known object like e.g. the depth in structure H, will do it. **T1**

will give **CALL CPSTVC(H,T1)**

the same dimension and discretisation as the depth.
**T1**

##### Operations on matrices

*Note*: all the operations on vectors may also be applied to the diagonal and the extradiagonal terms contained in the matrix structure (respectively M%D and M%X for a matrix M). The following subroutines only apply to matrices.

##### SUBROUTINE CPSTMT(M1,M2,TRANS)

Copies characteristics of the matrix

on to the matrix **M1**

, or of transposed of matrix **M2**

to **M1**

(if optional argument **M2**

is set to true).
**TRANS**

is similar to **CPSTMT**

, it carries out the following operations:
**CPSTVC**

- copies types of elements.
- copies types of diagonal and off-diagonal terms (calls CPSTVC for the diagonal and the off-diagonal terms).
- copies characteristics of the matrix (components TYPDIA and

).**TYPEXT** - checks that

has enough memory for its new characteristics : sizes of diagonal and extra-diagonal terms.**M2**

##### INTEGER FUNCTION DIM1_EXT(IELM1,IELM2,STO,TYPEXT)

The extra-diagonal terms of matrices are stored in 2-dimensional arrays.

returns the first dimension of this array, depending on:
**DIM1_EXT**

: Type of discretisation for rows (same convention as for the vectors).**IELM1**

: Type of discretisation for columns.**IELM2**

: Storage of the matrix (1: EBE, 3: edge based)**STO**

: Type of the off-diagonal terms ('0': zero, 'Q': any, 'S': symmetrical)**TYPEXT**

##### INTEGER FUNCTION DIM2_EXT(IELM1,IELM2,STO,TYPEXT)

The extra-diagonal terms of matrices are stored in 2-dimensional arrays. DIM2_EXT returns the second dimension of this array, depending on:

: Type of discretisation for rows (same convention as for the vectors).**IELM1**

: Type of discretisation for columns.**IELM2**

: Storage of the matrix (1: EBE, 3: edge based)**STO**

: Type of the off-diagonal terms ('0': zero, 'Q': any, 'S': symmetrical)**TYPEXT**

#### Operations on blocks

##### SUBROUTINE ADDBLO(BLOCK,T):

Adds the structure

to the block.
**T**

is a block and**BLOCK**

a structure.**T**

##### Reaching objects in blocks

If

is a vector stored as the second object in a block **T1**

, the address of **B**

is **T1**

. As a matter of fact, **B%ADR(2)%P**

is an array of **ADR**

structures, we take the second one, and its unique component **POINTER_TO_BIEF_OBJ**

(P would not be present if Fortran 90 were accepting the arrays of pointers).
**P**

can then be treated as a **B%ADR(2)%P**

structure, for example the third real value of **BIEF_OBJ**

is **T1**

. It is not recommended to deal directly with objects in blocks, this can be done in a subroutine by calling it with the argument (e.g.) **B%ADR(2)%P%R(3)**

. It will be then received in the subroutine as a normal **B%ADR(2)%P**

structure.
**BIEF_OBJ**

Component selectors can be piled up if blocks themselves are stored in blocks as in the
following example, where

as been stored as the second object into a block **T1**

stored as the third object in the block **C**

. **B**

is then:
**T1**

B%ADR(3)%P%ADR(2)%P

The only difficulty and common error is to forget the component P which is due to Fortran obscure reasons.