HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
TimeExplicitRKInitialize.c File Reference

Initialize explicit Runge-Kutta time integrators. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <timeintegration.h>

Go to the source code of this file.

Functions

int TimeExplicitRKInitialize (char *class, char *type, void *s, void *m)
 

Detailed Description

Initialize explicit Runge-Kutta time integrators.

Author
Debojyoti Ghosh

Definition in file TimeExplicitRKInitialize.c.

Function Documentation

◆ TimeExplicitRKInitialize()

int TimeExplicitRKInitialize ( char *  class,
char *  type,
void *  s,
void *  m 
)

Initialize the explicit Runge-Kutta time integrator: Depending on the specific explicit Runge-Kutta (ERK) method chosen, this function allocates memory for the Butcher tableaux and sets their coefficients.

Parameters
className of time integrator class; must match _RK_
typeType of explicit Runge-Kutta method
sObject of type ExplicitRKParameters
mUnused argument

Definition at line 17 of file TimeExplicitRKInitialize.c.

23 {
25 
26  if (!strcmp(class,_RK_)) {
27  if (!strcmp(type,_RK_1FE_)) {
28  params->nstages = 1;
29  params->A = (double*) calloc (params->nstages*params->nstages,sizeof(double));
30  params->b = (double*) calloc (params->nstages ,sizeof(double));
31  params->c = (double*) calloc (params->nstages ,sizeof(double));
32  _ArraySetValue_(params->A,params->nstages*params->nstages,0.0);
33  _ArraySetValue_(params->b,params->nstages ,0.0);
34  _ArraySetValue_(params->c,params->nstages ,0.0);
35  params->b[0] = 1.0;
36  } else if (!strcmp(type,_RK_22_)) {
37  params->nstages = 2;
38  params->A = (double*) calloc (params->nstages*params->nstages,sizeof(double));
39  params->b = (double*) calloc (params->nstages ,sizeof(double));
40  params->c = (double*) calloc (params->nstages ,sizeof(double));
41  _ArraySetValue_(params->A,params->nstages*params->nstages,0.0);
42  _ArraySetValue_(params->b,params->nstages ,0.0);
43  _ArraySetValue_(params->c,params->nstages ,0.0);
44  params->A[2] = 1.0;;
45  params->c[1] = 1.0;;
46  params->b[0] = params->b[1] = 0.5;
47  } else if (!strcmp(type,_RK_33_)) {
48  params->nstages = 3;
49  params->A = (double*) calloc (params->nstages*params->nstages,sizeof(double));
50  params->b = (double*) calloc (params->nstages ,sizeof(double));
51  params->c = (double*) calloc (params->nstages ,sizeof(double));
52  _ArraySetValue_(params->A,params->nstages*params->nstages,0.0);
53  _ArraySetValue_(params->b,params->nstages ,0.0);
54  _ArraySetValue_(params->c,params->nstages ,0.0);
55  params->A[3] = 2.0/3.0; params->A[6] = 2.0/3.0-1.0/4.0; params->A[7] = 1.0/4.0;
56  params->c[1] = 2.0/3.0; params->c[2] = 2.0/3.0;
57  params->b[0] = 1.0/4.0; params->b[1] = -1.0/4.0; params->b[2] = 1.0;
58  } else if (!strcmp(type,_RK_44_)) {
59  params->nstages = 4;
60  params->A = (double*) calloc (params->nstages*params->nstages,sizeof(double));
61  params->b = (double*) calloc (params->nstages ,sizeof(double));
62  params->c = (double*) calloc (params->nstages ,sizeof(double));
63  _ArraySetValue_(params->A,params->nstages*params->nstages,0.0);
64  _ArraySetValue_(params->b,params->nstages ,0.0);
65  _ArraySetValue_(params->c,params->nstages ,0.0);
66  params->A[4] = 0.5; params->A[9] = 0.5; params->A[14] = 1.0;
67  params->c[1] = params->c[2] = 0.5; params->c[3] = 1.0;
68  params->b[0] = 1.0/6.0; params->b[1] = 1.0/3.0; params->b[2] = 1.0/3.0; params->b[3] = 1.0/6.0;
69  } else if ((!strcmp(type,_RK_SSP3_)) || (!strcmp(type,_RK_TVD3_))) {
70  params->nstages = 3;
71  params->A = (double*) calloc (params->nstages*params->nstages,sizeof(double));
72  params->b = (double*) calloc (params->nstages ,sizeof(double));
73  params->c = (double*) calloc (params->nstages ,sizeof(double));
74  _ArraySetValue_(params->A,params->nstages*params->nstages,0.0);
75  _ArraySetValue_(params->b,params->nstages ,0.0);
76  _ArraySetValue_(params->c,params->nstages ,0.0);
77  params->A[3] = 1.0; params->A[6] = 0.25; params->A[7] = 0.25;
78  params->c[1] = 1.0; params->c[2] = 0.5;
79  params->b[0] = params->b[1] = 1.0/6.0; params->b[2] = 2.0/3.0;
80  } else {
81  fprintf(stderr,"Error in TimeExplicitRKInitialize(): %s is not a supported ",type);
82  fprintf(stderr,"multi-stage time integration scheme of class %s.\n",class);
83  return(1);
84  }
85  } else {
86  fprintf(stderr,"Error in TimeExplicitRKInitialize(): Code should not have ");
87  fprintf(stderr,"reached here for %s class of time-integrators. This is a ",class);
88  fprintf(stderr,"coding mistake.\n");
89  return(1);
90  }
91  return(0);
92 }
#define _RK_44_
#define _RK_22_
#define _ArraySetValue_(x, size, value)
#define _RK_
#define _RK_TVD3_
#define _RK_33_
Structure containing the parameters for an explicit Runge-Kutta method.
#define _RK_1FE_
#define _RK_SSP3_