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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*@@
@file WaveToy.c
@date
@author Tom Goodale
@desc
Evolution routines for the wave equation solver
@enddesc
@@*/
static char *rcsid = "$Header$";
#include "cctk.h"
#include "cctk_parameters.h"
#include "cctk_arguments.h"
#include "cctk_Flesh.h"
#include "cctk_Misc.h"
#include "cctk_Comm.h"
#include "Boundary.h"
#include "Symmetry.h"
static void WaveToyC_Boundaries(CCTK_CARGUMENTS);
/*@@
@routine WaveToyC_Evolution
@date
@author Tom Goodale
@desc
Evolution for the wave equation
@enddesc
@calls CCTK_SyncGroup, WaveToyC_Boundaries
@calledby
@history
@endhistory
@@*/
void WaveToyC_Evolution(CCTK_CARGUMENTS)
{
DECLARE_CCTK_CARGUMENTS
int i,j,k;
int index;
int istart, jstart, kstart, iend, jend, kend;
CCTK_REAL dx,dy,dz,dt,dx2,dy2,dz2,dt2;
/* Set up shorthands */
dx = CCTK_DELTA_SPACE(0);
dy = CCTK_DELTA_SPACE(1);
dz = CCTK_DELTA_SPACE(2);
dt = CCTK_DELTA_TIME;
dx2=dx*dx;
dy2=dy*dy;
dz2=dz*dz;
dt2=dt*dt;
istart = 1;
jstart = 1;
kstart = 1;
iend = cctk_lsh[0]-1;
jend = cctk_lsh[1]-1;
kend = cctk_lsh[2]-1;
/* Do the evolution */
for (k=kstart; k<kend; k++)
{
for (j=jstart; j<jend; j++)
{
for (i=istart; i<iend; i++)
{
phi_new[CCTK_GFINDEX3D(cctkGH,i,j,k)] =
2*(1 - (dt2)*(1/dx2 + 1/dy2 + 1/dz2))*
phi[CCTK_GFINDEX3D(cctkGH,i,j,k)] -
phi_old[CCTK_GFINDEX3D(cctkGH,i,j,k)]
+ (dt2) *
( ( phi[CCTK_GFINDEX3D(cctkGH,i+1,j,k)]
+phi[CCTK_GFINDEX3D(cctkGH,i-1,j,k)] )/dx2
+( phi[CCTK_GFINDEX3D(cctkGH,i,j+1,k)]
+phi[CCTK_GFINDEX3D(cctkGH,i,j-1,k)] )/dy2
+( phi[CCTK_GFINDEX3D(cctkGH,i,j,k+1)]
+phi[CCTK_GFINDEX3D(cctkGH,i,j,k-1)] )/dz2);
}
}
}
/* Synchronize before applying boundary conditions */
CCTK_SyncGroup(cctkGH,"wavetoyc::scalartmps");
/* Apply boundary conditions */
WaveToyC_Boundaries(CCTK_PASS_CTOC);
/* Update timeslices */
for (k=0; k<cctk_lsh[2]; k++)
{
for (j=0; j<cctk_lsh[1]; j++)
{
for (i=0; i<cctk_lsh[0]; i++)
{
index = CCTK_GFINDEX3D(cctkGH,i,j,k);
phi_old[index] = phi[index];
phi[index] = phi_new[index];
}
}
}
}
/*@@
@routine WaveToyC_Boundaries
@date
@author Tom Goodale
@desc
Boundary conditions for the wave equation
@enddesc
@calls CartSymBCGroupI,FlatBC,RadiativeBC
@calledby
@history
@endhistory
@@*/
static void WaveToyC_Boundaries(CCTK_CARGUMENTS)
{
DECLARE_CCTK_CARGUMENTS
DECLARE_CCTK_PARAMETERS
int ierr;
int sw[3];
/* Set the stencil width */
sw[0]=1;
sw[1]=1;
sw[2]=1;
ierr = CartSymBCGroup(cctkGH,"wavetoyc::scalartmps");
if (CCTK_EQUALS(bound,"flat"))
{
ierr = FlatBCVar(cctkGH,sw,"wavetoyc::phi_new");
}
else if (CCTK_Equals(bound,"radiation"))
{
ierr = RadiativeBCVar(cctkGH,0.0,1.0,sw,"wavetoyc::phi_new","wavetoy::phi");
}
if (ierr < 0)
{
CCTK_WARN(0,"Boundary conditions not applied - giving up!");
}
}
|