Fortran

Guide To Learn

A refresher on the Field class

Before we jump into the implementation of type-bound methods operators for the Field class, let’s refresh our memory on what this class is made of. In a nutshell, the Field class is a wrapper around the two-dimensional data array that stores the values of the field itself, and a few more components needed for the internal workings of the data structure, as shown here (and in src/ch10/mod_field.f 90):

type :: Field
  character(:), allocatable :: name            ❶
  integer(int32) :: dims(2), lb(2), ub(2)      ❷
  real(real32), allocatable :: data(:,:)       ❸
end type Field

❶ Field name

❷ The global dimensions and lower and upper bounds of a parallel tile

❸ A two-dimensional array to store the data

With a proper custom constructor, which we implemented in chapter 8 (omitted here for brevity), we declare and initialize our physical fields like this:

integer, parameter :: im = 101, jm = 101    ❶
type(Field) :: u, v, h                      ❷
 
u = Field('u', [im, jm])                    ❸
v = Field('v', [im, jm])                    ❸
h = Field('h', [im, jm])                    ❸

❶ Total grid size in the x and y dimensions

❷ Declares water velocity and height Field instances

❸ Initializes the Field instances by passing their names and total grid dimensions

The custom Field constructor is designed to allocate the data component with the appropriate range, and to store a few more internal variables mainly needed to instruct the parallel synchronization via the sync_edges subroutine. Feel free to look at the implementation of the field_constructor function in src/ch10/mod_field.f 90.

A refresher on the Field class

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top