aboutsummaryrefslogtreecommitdiff
path: root/src/Courant.c
blob: 7bac44c150f6b54c80b3a7a72b81ca7b09d38563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 /*@@
   @file      Courant.c
   @date      September 4 1999
   @author    Gabrielle Allen
   @desc 
   Specification of timestep using Courant condition
   @enddesc 
 @@*/

#include <malloc.h>
#include <math.h>

#include "cctk.h"
#include "cctk_arguments.h"
#include "cctk_parameters.h"

void Time_Courant(CCTK_CARGUMENTS)
{
  DECLARE_CCTK_PARAMETERS
  DECLARE_CCTK_CARGUMENTS

  CCTK_REAL min_spacing;
  CCTK_REAL courant_speed;

  char *message;

  int min_handle,ierr;
  
  /* Get the handle for the MINIMUM operation */
  /*$ierr = CCTK_ReductionArrayHandle("minimum");$*/

  /* Calculate the minimum grid spacing */
  if (cctk_dim>=1)
  {
    min_spacing = cctk_delta_space[0];
  }

  if (cctk_dim>=2)
  {
    min_spacing = (min_spacing<cctk_delta_space[1] ?
	min_spacing : cctk_delta_space[1]);
  }
  
  if (cctk_dim>=3)
  {
    min_spacing = (min_spacing<cctk_delta_space[2] ?
	min_spacing : cctk_delta_space[2]);
  }
  
  if (cctk_dim>=4)
  {
    CCTK_WARN(0,"Time Step not defined for greater than 4 dimensions");
  }

  /* do the global minimum on local min_spacing to tmp and reassign that
     to min_spacing */

  /*$printf("Courant1: %d \n",min_spacing);
  ierr = CCTK_ReduceLocalScalar(GH,-1,min_handle,min_spacing, tmp, CCTK_VAR_REAL);
  printf("Courant2: %d \n",min_spacing,tmp);
  min_spacing = tmp;
  printf("Courant3: %d \n",min_spacing,tmp);$*/

  /* Calculate the courant timestep */
  courant_speed = *wave_speed;
  *courant_dt = courant_fac/courant_speed/sqrt((CCTK_REAL )cctk_dim);

  /* Output timestep if required */

  if (outcourant_every > 0 && cctk_iteration%outcourant_every == 0)
  { 
    CCTK_OutputVarAsByMethod(cctkGH,"time::courant_dt","Scalar","courant");
  }

  /* Set the Cactus timestep */

  if (! courant_outonly)
  {
    cctkGH->cctk_delta_time = *courant_dt;

    message = (char *)malloc(1024*sizeof(char));
    sprintf(message,"Time step set to %f",cctkGH->cctk_delta_time);
    CCTK_INFO(message);
    free(message);
  }
  else
  {
    cctkGH->cctk_delta_time = dtfac*min_spacing/courant_wave_speed;
  }

}