aboutsummaryrefslogtreecommitdiff
path: root/Examples/Burgers.m
blob: 3d8926188b4f956173ca5c12ea6efe0d8ad58c0d (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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
Get["KrancThorn`"];

SetEnhancedTimes[False];

(**************************************************************************************)
(* Derivatives *)
(**************************************************************************************)

derivatives =
{
(*
  PDstandard2nd[i_] -> StandardCenteredDifferenceOperator[1,1,i],
  PDstandard2nd[i_, i_] -> StandardCenteredDifferenceOperator[2,1,i],
  PDstandard2nd[i_, j_] -> StandardCenteredDifferenceOperator[1,1,i] *
    StandardCenteredDifferenceOperator[1,1,j],

  PDstandard4th[i_] -> StandardCenteredDifferenceOperator[1,2,i],
  PDstandard4th[i_, i_] -> StandardCenteredDifferenceOperator[2,2,i],
  PDstandard4th[i_, j_] -> StandardCenteredDifferenceOperator[1,2,i] *
    StandardCenteredDifferenceOperator[1,2,j],

  PDonesided2nd[1] -> dir[1] (-shift[1]^(2 dir[1]) + 4 shift[1]^dir[1] - 3 )/(2 spacing[1]),
  PDonesided2nd[2] -> dir[2] (-shift[2]^(2 dir[2]) + 4 shift[2]^dir[2] - 3 )/(2 spacing[2]),
  PDonesided2nd[3] -> dir[3] (-shift[3]^(2 dir[3]) + 4 shift[3]^dir[3] - 3 )/(2 spacing[3])
*)
  PDplus[i_] -> DPlus[i],

  DiffPlus[i_] -> DiffPlusOp[i],
  DiffMinus[i_] -> DiffMinusOp[i],
  ShiftMinus[i_] -> 1/shift[i]
};

(* PD = PDstandard2nd; *)
PD = PDplus;

(**************************************************************************************)
(* Tensors *)
(**************************************************************************************)

(* Register the tensor quantities with the TensorTools package *)
Map[DefineTensor, {u, uF, uR, uLeft}];

(**************************************************************************************)
(* Groups *)
(**************************************************************************************)

evolvedGroups = Map[CreateGroupFromTensor, {u}];
nonevolvedGroups = Map[CreateGroupFromTensor, {uF, uLeft, uR}];

declaredGroups = Join[evolvedGroups, nonevolvedGroups];
declaredGroupNames = Map[First, declaredGroups];

groups = Join[declaredGroups];

(**************************************************************************************)
(* Initial data *)
(**************************************************************************************)

initialSineCalc =
{
  Name -> "burgers_initial_sine",
  Schedule -> {"at CCTK_INITIAL as burgers_initial"},
  ConditionalOnKeyword -> {"initial_data", "sine"},
  Equations ->
  {
    u -> 1 + amp Sin[2 Pi x]
  }
};

initialShockCalc =
{
  Name -> "burgers_initial_shock",
  Schedule -> {"at CCTK_INITIAL as burgers_initial"},
  ConditionalOnKeyword -> {"initial_data", "shock"},
  Equations ->
  {
    u -> uR0 StepFunction[x-0.5] + uL0 (1-StepFunction[x-0.5])
  }
};

(**************************************************************************************)
(* Evolution equations *)
(**************************************************************************************)

(* Burger's equation is dot[u] + PD[F,x] = 0

   with F[ui] = 1/2 u^2
*)

burgersFlux[u_] := 1/2 u^2;

zeroRHSCalc[] :=
{
  Name -> "burgers_zero_rhs",
  Schedule -> {"in MoL_CalcRHS"},
  Equations -> 
  {
    dot[u] -> 0
  }
};

reconstructCalc[i_] :=
{
  Name -> "burgers_reconstruct_" <> ToString[i],
  Where -> Interior,
  Schedule -> {"in MoL_CalcRHS after " <> 
    If[i == 1, "burgers_zero_rhs", "burgers_rhs_" <> ToString[i-1]]},
  Shorthands -> {slopeL, slopeR, slope},
  ApplyBCs -> True,
  Equations -> 
  {
    slopeL -> DiffMinus[u, i],
    slopeR -> DiffPlus[u, i],
    slope -> IfThen[slopeL slopeR < 0, 0, IfThen[Abs[slopeL] < Abs[slopeR], slopeL, slopeR]],
    uLeft -> u - 0.5 slope,
    uR -> u + 0.5 slope
  }
};

fluxCalc[f_, i_] :=
{
  Name -> "burgers_flux_" <> ToString[i],
  ApplyBCs -> True,
  Where -> Interior,
  Schedule -> {"in MoL_CalcRHS after burgers_reconstruct_" <> ToString[i]},
  Equations -> 
  {
    uF -> 1/2 (f[uLeft] + f[ShiftMinus[uR,i]] + alpha (ShiftMinus[uR,i] - uLeft))
  }
};

rhs[i_] :=
{
  Name -> "burgers_rhs_" <> ToString[i],
  Schedule -> {"in MoL_CalcRHS after burgers_flux_" <> ToString[i]},
  Where -> Interior,
  Equations -> 
  {
    dot[u] -> dot[u] - PDplus[uF, i]
  }
};

makeConservationCalcs[f_] :=
({ zeroRHSCalc[]} ~Join~ Flatten[Table[
  {reconstructCalc[i],
   fluxCalc[f, i],
   rhs[i]}, {i, 1, 1}], 1]);


realParameters = {sigma, v0, amp, uL0, uR0, alpha};

keywordParameters = {
  {
    Name -> "initial_data",
    Default -> "sine",
    AllowedValues -> {"sine", "shock"}
  }
};

(**************************************************************************************)
(* Construct the thorn *)
(**************************************************************************************)

calculations = 
{
  initialSineCalc,
  initialShockCalc
} ~Join~ makeConservationCalcs[burgersFlux];

CreateKrancThornTT[groups, ".", "Burgers", 
  Calculations -> calculations,
  DeclaredGroups -> declaredGroupNames,
  PartialDerivatives -> derivatives,
  RealParameters -> realParameters,
  KeywordParameters -> keywordParameters];