SPINS User Guide: Difference between revisions

From Fluids Wiki
Jump to navigation Jump to search
Line 43: Line 43:
=== Using wave_reader.cpp ===
=== Using wave_reader.cpp ===
The case file wave_reader.cpp is a special case used for initialising the model with specified velocity and density fields. A configuration file, spins.conf, is used to hand parameters to SPINS. An example spins.conf is provided below (# are comments) for a periodic box initialised from 3D files:
The case file wave_reader.cpp is a special case used for initialising the model with specified velocity and density fields. A configuration file, spins.conf, is used to hand parameters to SPINS. An example spins.conf is provided below (# are comments) for a periodic box initialised from 3D files:
<syntaxhighlight lang="text">
<syntaxhighlight lang="text" enclose="div">
Nx = 256
  Nx = 256
Ny = 64
  Ny = 64
Nz = 128
  Nz = 128


type_x = FOURIER
  type_x = FOURIER
type_y = FOURIER
  type_y = FOURIER
type_z = FREE_SLIP
  type_z = FREE_SLIP


Lx = 20
  Lx = 20
Ly = 5
  Ly = 5
Lz = 1
  Lz = 1


min_x = 0
  min_x = 0
min_y = -1
  min_y = -1
min_z = 0
  min_z = 0


mapped_grid = false
  mapped_grid = false
# xgrid = xgrid.bin
  # xgrid = xgrid.bin
# zgrid = zgrid.bin
  # zgrid = zgrid.bin


file_type = FULL
  file_type = FULL


u_file = input_u
  u_file = input_u
v_file = input_v
  v_file = input_v
w_file = input_w
  w_file = input_w
rho_file = input_rho
  rho_file = input_rho


enable_tracer = false
  enable_tracer = false
#tracer_file = tracer.bin
  # tracer_file = tracer.bin
#tracer_kappa = kappa
  # tracer_kappa = kappa


g = 9.81
  g = 9.81
rot_f = 0.0
  rot_f = 0.0
visc = 0.0
  visc = 0.0
kappa = 0.0
  kappa = 0.0


perturbation = 0.0
  perturbation = 0.0


init_time = 0.0
  init_time = 0.0
final_time = 100
  final_time = 100
plot_interval = 1
  plot_interval = 1


restart = false
  restart = false
#restart_time = 0
  # restart_time = 0
#restart_sequence = 0
  # restart_sequence = 0
</syntaxhighlight>
</syntaxhighlight>


For a short explanation of each option, the wave_reader help is reproduced here:
For a short explanation of each option, the wave_reader help is reproduced here:
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
mpirun -np 1 ./wave_reader_x --help
  mpirun -np 1 ./wave_reader_x --help


SPINS: baseline options:
  SPINS: baseline options:
  --config arg (=spins.conf) Configuration file
    --config arg (=spins.conf) Configuration file
  --help                    Print this set of options and exit
    --help                    Print this set of options and exit


Grid Options:
  Grid Options:
  --Nx arg                Number of points in X
    --Nx arg                Number of points in X
  --Ny arg (=1)          Number of points in Y
    --Ny arg (=1)          Number of points in Y
  --Nz arg                Number of points in Z
    --Nz arg                Number of points in Z
  --type_x arg            Grid type in X.  Valid values are:
    --type_x arg            Grid type in X.  Valid values are:
                            FOURIER: Periodic
                              FOURIER: Periodic
                            FREE_SLIP: Cosine expansion
                              FREE_SLIP: Cosine expansion
                            NO_SLIP: Chebyhsev expansion
                              NO_SLIP: Chebyhsev expansion
  --type_y arg (=FOURIER) Grid type in Y
    --type_y arg (=FOURIER) Grid type in Y
  --type_z arg            Grid type in Z
    --type_z arg            Grid type in Z
  --Lx arg                X-length
    --Lx arg                X-length
  --Ly arg (=1)          Y-length
    --Ly arg (=1)          Y-length
  --Lz arg                Z-length
    --Lz arg                Z-length
  --min_x arg (=0)        Unmapped grids: Minimum X-value
    --min_x arg (=0)        Unmapped grids: Minimum X-value
  --min_y arg (=0)        Minimum Y-value
    --min_y arg (=0)        Minimum Y-value
  --min_z arg (=0)        Minimum Z-value
    --min_z arg (=0)        Minimum Z-value


Grid mapping options:
  Grid mapping options:
  --mapped_grid arg (=0) Use a mapped (2D) grid
    --mapped_grid arg (=0) Use a mapped (2D) grid
  --xgrid arg            x-grid filename
    --xgrid arg            x-grid filename
  --zgrid arg            z-grid filename
    --zgrid arg            z-grid filename


Input data:
  Input data:
  --file_type arg      Format of input data files, including that for the  
    --file_type arg      Format of input data files, including that for the  
                        mapped grid.Valid options are:
                          mapped grid.Valid options are:
                          MATLAB: Row-major 2D arrays of size Nx x Nz
                            MATLAB: Row-major 2D arrays of size Nx x Nz
                          CTYPE:  Column-major 2D arrays (including that  
                            CTYPE:  Column-major 2D arrays (including that  
                                  output by 2D SPINS runs)
                                    output by 2D SPINS runs)
                          FULL:  Column-major 3D arrays; implies CTYPE for  
                            FULL:  Column-major 3D arrays; implies CTYPE for  
                                  grid mapping if enabled
                                    grid mapping if enabled
  --u_file arg          U-velocity filename
    --u_file arg          U-velocity filename
  --v_file arg          V-velocity filename
    --v_file arg          V-velocity filename
  --w_file arg          W-velocity filename
    --w_file arg          W-velocity filename
  --rho_file arg        Rho (density) filename
    --rho_file arg        Rho (density) filename


Passive tracer:
  Passive tracer:
  --enable_tracer      Enable evolution of a passive tracer
    --enable_tracer      Enable evolution of a passive tracer
  --tracer_file arg    Tracer filename
    --tracer_file arg    Tracer filename
  --tracer_kappa arg    Diffusivity of tracer
    --tracer_kappa arg    Diffusivity of tracer


Physical parameters:
  Physical parameters:
  --g arg (=9.8100000000000005) Gravitational acceleration
    --g arg (=9.8100000000000005) Gravitational acceleration
  --rot_f arg (=0)              Coriolis force term
    --rot_f arg (=0)              Coriolis force term
  --visc arg (=0)              Kinematic viscosity
    --visc arg (=0)              Kinematic viscosity
  --kappa arg (=0)              Thermal diffusivity
    --kappa arg (=0)              Thermal diffusivity
  --perturbation arg (=0)      Velocity perturbation (multiplicative white  
    --perturbation arg (=0)      Velocity perturbation (multiplicative white  
                                    noise) applied to read-in data.
                                      noise) applied to read-in data.


Running options:
  Running options:
  --init_time arg (=0)  Initial time
    --init_time arg (=0)  Initial time
  --final_time arg      Final time
    --final_time arg      Final time
  --plot_interval arg  Interval between output times
    --plot_interval arg  Interval between output times


Restart options:
  Restart options:
  --restart              Restart from prior output time.  OVERRIDES many other
    --restart              Restart from prior output time.  OVERRIDES many other
                          values.
                            values.
  --restart_time arg (=0) Time to restart from
    --restart_time arg (=0) Time to restart from
  --restart_sequence arg  Sequence number to restart from (if plot_interval has
    --restart_sequence arg  Sequence number to restart from (if plot_interval has
                          changed)
                            changed)
</syntaxhighlight>
</syntaxhighlight>



Revision as of 14:39, 6 September 2012

Welcome to the SPINS user guide.


The basics

The SPINS model is a Navier-Stokes solver that gets parameters and initial/boundary conditions from calls to user-provided routines. The user-provided routines are encapsulated in class derived from BaseCase (see BaseCase.hpp).

Creating your own custom configuration involves supplying the user-provided routines in a derived class based on BaseCase. The case file cases/doc_minimal.cpp shows the structure of a case file. It usually makes sense to start with a similar case file and customise it.

SPINS components

SPINS consists of a bunch of C++ source files and a bunch of case files, and it requires four libraries. UMFPack, AMD and Blitz++ are supplied with SPINS, and it uses the system-installed FFTW.

Directory structure:

  • spins/src - SPINS source files
  • spins/src/cases - A few dozen example case files
  • spins/matlab - Some helper functions for MATLAB analysis

How to get SPINS running

You will need to get the code, build the dependencies, build the model and then run it.

Extracting the code from the git repository

Building the dependencies

  • Go to the spins directory.
  • Type "./make_deps.sh".

Building SPINS

  • Go to the systems directory.
  • Type "./makemake.sh". This will build the code based on the system architecture. Note that there are several files that include instructions for several systems e.g. gpc.sh. makemake.sh will try to guess which instructions to use if you do not include options in your makemake.sh call from the command line.
  • Enter the src directory.
  • Type "make cases/your_case.x".
  • This requires a file called your_case.cpp in the cases directory. There are several cases included with the code so you may want to start with one of those.
  • After successful compilation, an executable called your_case.x is created.

Running SPINS

  • Please be careful not to run in your home directory on machines like belize or winisk.
  • The code can be executed using mpirun e.g "mpirun -np 4 ./your_case.x".
  • Please note that some cases may require command line options or a configure file called spins.conf.

Examples of common operations

You can find examples of how to do various operations by digging through the case files. Some of the common operations are reproduced here.

Using wave_reader.cpp

The case file wave_reader.cpp is a special case used for initialising the model with specified velocity and density fields. A configuration file, spins.conf, is used to hand parameters to SPINS. An example spins.conf is provided below (# are comments) for a periodic box initialised from 3D files:

  Nx = 256
  Ny = 64
  Nz = 128

  type_x = FOURIER
  type_y = FOURIER
  type_z = FREE_SLIP

  Lx = 20
  Ly = 5
  Lz = 1

  min_x = 0
  min_y = -1
  min_z = 0

  mapped_grid = false
  # xgrid = xgrid.bin
  # zgrid = zgrid.bin

  file_type = FULL

  u_file = input_u
  v_file = input_v
  w_file = input_w
  rho_file = input_rho

  enable_tracer = false
  # tracer_file = tracer.bin
  # tracer_kappa = kappa

  g = 9.81
  rot_f = 0.0
  visc = 0.0
  kappa = 0.0

  perturbation = 0.0

  init_time = 0.0
  final_time = 100
  plot_interval = 1

  restart = false
  # restart_time = 0
  # restart_sequence = 0

For a short explanation of each option, the wave_reader help is reproduced here:

  mpirun -np 1 ./wave_reader_x --help

  SPINS: baseline options:
    --config arg (=spins.conf) Configuration file
    --help                     Print this set of options and exit

  Grid Options:
    --Nx arg                Number of points in X
    --Ny arg (=1)           Number of points in Y
    --Nz arg                Number of points in Z
    --type_x arg            Grid type in X.  Valid values are:
                               FOURIER: Periodic
                               FREE_SLIP: Cosine expansion
                               NO_SLIP: Chebyhsev expansion
    --type_y arg (=FOURIER) Grid type in Y
    --type_z arg            Grid type in Z
    --Lx arg                X-length
    --Ly arg (=1)           Y-length
    --Lz arg                Z-length
    --min_x arg (=0)        Unmapped grids: Minimum X-value
    --min_y arg (=0)        Minimum Y-value
    --min_z arg (=0)        Minimum Z-value

  Grid mapping options:
    --mapped_grid arg (=0) Use a mapped (2D) grid
    --xgrid arg            x-grid filename
    --zgrid arg            z-grid filename

  Input data:
    --file_type arg       Format of input data files, including that for the 
                          mapped grid.Valid options are:
                             MATLAB: Row-major 2D arrays of size Nx x Nz
                             CTYPE:  Column-major 2D arrays (including that 
                                     output by 2D SPINS runs)
                             FULL:   Column-major 3D arrays; implies CTYPE for 
                                     grid mapping if enabled
    --u_file arg          U-velocity filename
    --v_file arg          V-velocity filename
    --w_file arg          W-velocity filename
    --rho_file arg        Rho (density) filename

  Passive tracer:
    --enable_tracer       Enable evolution of a passive tracer
    --tracer_file arg     Tracer filename
    --tracer_kappa arg    Diffusivity of tracer

  Physical parameters:
    --g arg (=9.8100000000000005) Gravitational acceleration
    --rot_f arg (=0)              Coriolis force term
    --visc arg (=0)               Kinematic viscosity
    --kappa arg (=0)              Thermal diffusivity
    --perturbation arg (=0)       Velocity perturbation (multiplicative white 
                                       noise) applied to read-in data.

  Running options:
    --init_time arg (=0)  Initial time
    --final_time arg      Final time
    --plot_interval arg   Interval between output times

  Restart options:
    --restart               Restart from prior output time.  OVERRIDES many other
                            values.
    --restart_time arg (=0) Time to restart from
    --restart_sequence arg  Sequence number to restart from (if plot_interval has
                            changed)

Generating the grid files: regular grid

For an unmapped grid, include the following call in your case file's constructor to generate the grid files and grid file readers:

automatic_grid(MinX,MinY,MinZ);

where MinX, MinY and MinZ are the coordinates of the starting corner of your grid.

Using a mapped grid

Can someone write this?

Analytic initialisation

Can someone write this?

Boundary conditions

Can someone write this?

Forcing / sponge regions

Can someone write this?


Online Analysis

Some analysis can be done online, some examples are shown below.

Energy Diagnostics

If you're using a periodic grid, use this for computing kinetic energy diagnostic

double dV = (Lx/Nx)*(Ly/Ny)*(Lz/Nz);
double ke = 0.5*rho_0*pssum(sum( u*u+v*v+w*w ))*dV; // KE

If you're on a Chebyshev grid, you can use this for the KE computation

double ke = pssum(sum((*get_quad_x())(ii)*(*get_quad_y())(jj)*(*get_quad_z())(kk)*
                  (pow(u(ii,jj,kk),2)+pow(v(ii,jj,kk),2)+pow(w(ii,jj,kk),2))));

and you will need to compute the quadrature weights in the constructor

// Compute the quadrature weights
compute_quadweights(size_x(),size_y(),size_z(),
                    length_x(),length_y(),length_z(),
                    type_x(),type_y(),type_z());