Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
cvmix.h File Reference
#include "kinds_and_types.h"
#include "put_get.h"
Include dependency graph for cvmix.h:

Go to the source code of this file.

Data Structures

struct  dtype_type
 
struct  descriptor_dimension
 
struct  gfc_array_descriptor
 
struct  cvmix_2d
 

Macros

#define strlencheck(s)   (s != NULL ? strlen(s) : 0)
 
#define cvmix_deallocate(a)   cvmix_deallocate_(a)
 
#define cvmix_2d(c, len1, i, j)   (c).a[(i) + (j)*(len1)]
 

Typedefs

typedef int indexing
 We define a data structure describing the array descriptor of gfortran as documented here.
 
typedef double cvmix_r8
 
typedef int logical
 
typedef int integer
 
typedef struct gfc_array_descriptor cvmix_1d
 
typedef cvmix_1d cvmix_nd
 

Functions

void cvmix_redirect_stdout_ (void)
 
void allocate1d_ (const int *len, cvmix_1d *mem)
 
void deallocate1d_ (cvmix_1d *mem)
 
void allocate2d_ (const int *len1, const int *len2, cvmix_2d *mem)
 
void deallocate2d_ (cvmix_2d *mem)
 
void sizeofall_ (void)
 
void cvmix_deallocate_ (cvmix_data_type *CVmix_vars)
 
cvmix_1d cvmix_allocate_1d (int len)
 
void cvmix_deallocate_1d (cvmix_1d a)
 
void cvmix_1d_print (cvmix_1d *a)
 
cvmix_2d cvmix_allocate_2d (int len1, int len2)
 
void cvmix_deallocate_2d (cvmix_2d a)
 

Variables

cvmix_r8 cvmix_zero = 0.
 
cvmix_r8 cvmix_one = 1.
 

Macro Definition Documentation

◆ cvmix_2d

#define cvmix_2d (   c,
  len1,
  i,
  j 
)    (c).a[(i) + (j)*(len1)]

Definition at line 167 of file cvmix.h.

◆ cvmix_deallocate

#define cvmix_deallocate (   a)    cvmix_deallocate_(a)

Definition at line 166 of file cvmix.h.

◆ strlencheck

#define strlencheck (   s)    (s != NULL ? strlen(s) : 0)

Definition at line 119 of file cvmix.h.

Typedef Documentation

◆ cvmix_1d

Definition at line 106 of file cvmix.h.

◆ cvmix_nd

Definition at line 107 of file cvmix.h.

◆ cvmix_r8

Definition at line 103 of file cvmix.h.

◆ indexing

We define a data structure describing the array descriptor of gfortran as documented here.

Interface with the Community Ocean and Vertical Mixing (CVMix) project

Community Ocean Vertical Mixing (CVMix) is a software package that aims to provide transparent, robust, flexible, well documented, shared Fortran source code for use in parameterizing vertical mixing processes in numerical ocean models.

This header file provides a C-language interface for Basilisk (and other projects, since the interface does not depend on Basilisk itself).

Installation

CVMix needs to be installed first and its source code must be accessible, since the C interface is generated automatically from the Fortran sources.

Once this done the C interface can be built using this [Makefile]() and the correct location for the sources and/or Fortran compiler. For example:

cd \f$BASILISK/src/cvmix/
CVMIX=\f$HOME/local/cvmix F90=gfortran FCFLAGS="-Wall -O2" make

Interoperability with Fortran 90

Aside from standard considerations on compatibility of different types between C and Fortran (as documented here for example), the main difficulty is interoperability of ["assumed size arrays"](https://thinkingeek.com/2017/01/14/gfortran-array-descriptor/).

The approach taken here is a bit of a hack and should be replaced with a more portable way of doing things when it becomes available.

For the moment, it relies on the assumption that the "shaped array descriptor" works in a similar manner to that of gfortran. These assumptions are:

  1. The first element of the array descriptor is a pointer to the data stored in the array.
  2. The size occupied by the array descriptor is smaller than or equal to the size of the data structure below (i.e. sizeof(cvmix_1d)).
  3. The only types used by CVMix are integer, cvmix_r8, character, logical and derived types composed of these.
  4. Fortran derived types never use more memory than the corresponding C structure.

If any of these assumptions is violated, the most likely result will be a low-level memory fault (i.e. segmentation fault, stack smashing etc.). Note that the goal is only to define a cvmix_1d structure which occupies the right amount of memory so that conditions 2 and 4 above are verified. The actual members are never used, with the exception of gfc_array_descriptor.a which corresponds to assumption 1 above.

Definition at line 76 of file cvmix.h.

◆ integer

Definition at line 105 of file cvmix.h.

◆ logical

Definition at line 104 of file cvmix.h.

Function Documentation

◆ allocate1d_()

void allocate1d_ ( const int len,
cvmix_1d mem 
)
extern

Referenced by cvmix_allocate_1d().

Here is the caller graph for this function:

◆ allocate2d_()

void allocate2d_ ( const int len1,
const int len2,
cvmix_2d mem 
)
extern

Referenced by cvmix_allocate_2d().

Here is the caller graph for this function:

◆ cvmix_1d_print()

void cvmix_1d_print ( cvmix_1d a)

Definition at line 145 of file cvmix.h.

References a, and x.

◆ cvmix_allocate_1d()

cvmix_1d cvmix_allocate_1d ( int  len)

Definition at line 133 of file cvmix.h.

References a, and allocate1d_().

Here is the call graph for this function:

◆ cvmix_allocate_2d()

cvmix_2d cvmix_allocate_2d ( int  len1,
int  len2 
)

Definition at line 154 of file cvmix.h.

References a, allocate2d_(), and x.

Here is the call graph for this function:

◆ cvmix_deallocate_()

void cvmix_deallocate_ ( cvmix_data_type CVmix_vars)
extern

◆ cvmix_deallocate_1d()

void cvmix_deallocate_1d ( cvmix_1d  a)

Definition at line 140 of file cvmix.h.

References a, and deallocate1d_().

Here is the call graph for this function:

◆ cvmix_deallocate_2d()

void cvmix_deallocate_2d ( cvmix_2d  a)

Definition at line 161 of file cvmix.h.

References a, and deallocate2d_().

Here is the call graph for this function:

◆ cvmix_redirect_stdout_()

void cvmix_redirect_stdout_ ( void  )
extern

◆ deallocate1d_()

void deallocate1d_ ( cvmix_1d mem)
extern

Referenced by cvmix_deallocate_1d().

Here is the caller graph for this function:

◆ deallocate2d_()

void deallocate2d_ ( cvmix_2d mem)
extern

Referenced by cvmix_deallocate_2d().

Here is the caller graph for this function:

◆ sizeofall_()

void sizeofall_ ( void  )
extern

Variable Documentation

◆ cvmix_one

cvmix_r8 cvmix_one = 1.

Definition at line 117 of file cvmix.h.

◆ cvmix_zero

cvmix_r8 cvmix_zero = 0.

Definition at line 117 of file cvmix.h.