Peano
Loading...
Searching...
No Matches
CCZ4.cpp
Go to the documentation of this file.
1#include "CCZ4.h"
2#include "exahype2/RefinementControl.h"
3#include "tarch/NonCriticalAssertions.h"
4//#include "exahype2/CellAccess.h"
5
6#include <algorithm>
7
8#include "Constants.h"
9
10#include <limits>
11
12#include <stdio.h>
13#include <string.h>
14
15#ifdef IncludeTwoPunctures
17#endif
18
19tarch::logging::Log benchmarks::exahype2::ccz4::CCZ4::_log( "benchmarks::exahype2::ccz4::CCZ4" );
20
21#ifdef IncludeTwoPunctures
22//pre-process, solve the puncture equations
24 //first we set the parameter. TODO:find a way to read parameter from python script
25 //int swi=0;//0--single black hole, 2--BBH hoc, 2--BBH rotation, 3--GW150914
26 //bbhtype=0 head on, 1-b=3, 2-b=2
27
28 if (CCZ4swi==0){
29 tp->par_b=1.0;
30 tp->center_offset[0]=-1.0; tp->center_offset[1]=0.0; tp->center_offset[2]=0.0;
31 tp->target_M_plus=1.0;//adm mass
32 tp->par_P_plus[0]=0.0; tp->par_P_plus[1]=0.0; tp->par_P_plus[2]=0.0;//linear momentum
33 tp->par_S_plus[0]=0.0; tp->par_S_plus[1]=0.0; tp->par_S_plus[2]=0.0;//spin
34 tp->target_M_minus=0.0;//adm mass
35 tp->par_P_minus[0]=0.0; tp->par_P_minus[1]=0.0; tp->par_P_minus[2]=0.0;//linear momentum
36 tp->par_S_minus[0]=0.0; tp->par_S_minus[1]=0.0; tp->par_S_minus[2]=0.0; //spin
37 tp->grid_setup_method="evaluation"; //evaluation or Taylor expansion
38 tp->TP_epsilon=1e-6;}
39
40 if (CCZ4swi==4){
41 tp->par_b=1.0;
42 tp->center_offset[0]=-3.0; tp->center_offset[1]=-2.0; tp->center_offset[2]=0.0;
43 tp->target_M_plus=1.0;//adm mass
44 tp->par_P_plus[0]=0.1; tp->par_P_plus[1]=0.1; tp->par_P_plus[2]=0.0;//linear momentum
45 tp->par_S_plus[0]=0.0; tp->par_S_plus[1]=0.0; tp->par_S_plus[2]=0.0;//spin
46 tp->target_M_minus=0.0;//adm mass
47 tp->par_P_minus[0]=0.0; tp->par_P_minus[1]=0.0; tp->par_P_minus[2]=0.0;//linear momentum
48 tp->par_S_minus[0]=0.0; tp->par_S_minus[1]=0.0; tp->par_S_minus[2]=0.0; //spin
49 tp->grid_setup_method="evaluation"; //evaluation or Taylor expansion
50 tp->TP_epsilon=1e-6;}
51
52 if (CCZ4swi==2 and CCZ4BBHType==0){
53 tp->par_b=2.0;
54 tp->center_offset[0]=0.0; tp->center_offset[1]=0.0; tp->center_offset[2]=0.0;
55 tp->target_M_plus=0.5;//adm mass
56 tp->par_P_plus[0]=0.0; tp->par_P_plus[1]=0.0; tp->par_P_plus[2]=0.0;//linear momentum
57 tp->par_S_plus[0]=0.0; tp->par_S_plus[1]=0.0; tp->par_S_plus[2]=0.0;//spin
58 tp->target_M_minus=0.5;//adm mass
59 tp->par_P_minus[0]=0.0; tp->par_P_minus[1]=0.0; tp->par_P_minus[2]=0.0;//linear momentum
60 tp->par_S_minus[0]=0.0; tp->par_S_minus[1]=0.0; tp->par_S_minus[2]=0.0; //spin
61 tp->grid_setup_method="evaluation"; //evaluation or Taylor expansion
62 tp->TP_epsilon=1e-6;}
63
64 //following data reference: https://journals.aps.org/prd/pdf/10.1103/PhysRevD.69.024006
65 if (CCZ4swi==2 and CCZ4BBHType==1){
66 tp->par_b=3.0;
67 tp->center_offset[0]=0.0; tp->center_offset[1]=0.0; tp->center_offset[2]=0.0;
68 tp->give_bare_mass=true;//use puncture mass instead of adm mass
69 tp->par_m_plus=0.47656; tp->par_m_minus=0.47656;
70 //tp->target_M_plus=999;//adm mass
71 tp->par_P_plus[0]=0.0; tp->par_P_plus[1]=0.13808; tp->par_P_plus[2]=0.0;//linear momentum
72 tp->par_S_plus[0]=0.0; tp->par_S_plus[1]=0.0; tp->par_S_plus[2]=0.0;//spin
73 //tp->target_M_minus=999;//adm mass
74 tp->par_P_minus[0]=0.0; tp->par_P_minus[1]=-0.13808; tp->par_P_minus[2]=0.0;//linear momentum
75 tp->par_S_minus[0]=0.0; tp->par_S_minus[1]=0.0; tp->par_S_minus[2]=0.0; //spin
76 tp->grid_setup_method="evaluation"; //evaluation or Taylor expansion
77 tp->TP_epsilon=1e-6;}
78
79 if (CCZ4swi==2 and CCZ4BBHType==2){
80 tp->par_b=2.0;
81 tp->center_offset[0]=0.0; tp->center_offset[1]=0.0; tp->center_offset[2]=0.0;
82 tp->give_bare_mass=true;//use puncture mass instead of adm mass
83 tp->par_m_plus=0.46477; tp->par_m_minus=0.46477;
84 //tp->target_M_plus=999;//adm mass
85 tp->par_P_plus[0]=0.0; tp->par_P_plus[1]=0.19243; tp->par_P_plus[2]=0.0;//linear momentum
86 tp->par_S_plus[0]=0.0; tp->par_S_plus[1]=0.0; tp->par_S_plus[2]=0.0;//spin
87 //tp->target_M_minus=999;//adm mass
88 tp->par_P_minus[0]=0.0; tp->par_P_minus[1]=-0.19243; tp->par_P_minus[2]=0.0;//linear momentum
89 tp->par_S_minus[0]=0.0; tp->par_S_minus[1]=0.0; tp->par_S_minus[2]=0.0; //spin
90 tp->grid_setup_method="evaluation"; //evaluation or Taylor expansion
91 tp->TP_epsilon=1e-6;}
92
93 if (CCZ4swi==3){
94 double D=10.0, q=36.0/29.0, chip=0.31, chim=-0.46, M=1.0;
95 double Pr=-0.00084541526517121, Pphi=0.09530152296974252;
96 double mp=M*q/(1+q), mm=M*1/(1+q);
97 tp->par_b=5.0;
98 tp->center_offset[0]=D*mm-D/2; tp->center_offset[1]=0.0; tp->center_offset[2]=0.0;
99 tp->target_M_plus=mp;//adm mass
100 tp->par_P_plus[0]=Pr; tp->par_P_plus[1]=Pphi; tp->par_P_plus[2]=0.0;//linear momentum
101 tp->par_S_plus[0]=0.0; tp->par_S_plus[1]=0.0; tp->par_S_plus[2]=chip*mp*mp;//spin
102 tp->target_M_minus=1/(1+q);//adm mass
103 tp->par_P_minus[0]=-Pr; tp->par_P_minus[1]=-Pphi; tp->par_P_minus[2]=0.0;//linear momentum
104 tp->par_S_minus[0]=0.0; tp->par_S_minus[1]=0.0; tp->par_S_minus[2]=chim*mm*mm; //spin
105 tp->grid_setup_method="evaluation"; //evaluation or Taylor expansion
106 tp->TP_epsilon=1e-6;}
107 tp->PrintParameters();
108
109 //then solve the equation
110 tp->Run();
111}
112#endif
113
115 if ( Scenario==0 || Scenario==1 ) {
116 const char* name = "GaugeWave";//nothing to do here for now
117 int length = strlen(name);
118 //initparameters_(&length, name);
119 }
120 #ifdef IncludeTwoPunctures
121 if ( Scenario==2 ) {
122 prepare(_tp);//we solve the puncture equation here.
123 //exit(0);
124 }
125 #endif
126 else {
127 //std::cerr << "initial scenario " << Scenario << " is not supported" << std::endl << std::endl << std::endl;
128 }
129}
130
132 double * NOALIAS Q,
133 const tarch::la::Vector<DIMENSIONS,double>& volumeX,
134 const tarch::la::Vector<DIMENSIONS,double>& volumeH,
135 bool gridIsConstructed
136) {
137 logTraceInWith3Arguments( "initialCondition(...)", volumeX, volumeH, gridIsConstructed );
138
139 if ( Scenario==0 ) {
141 }
142 else if ( Scenario==3 ) {
144 }
145 else if ( Scenario==1 ) {
147 }
148 else if ( Scenario==4 ) {
150 }
151 #ifdef IncludeTwoPunctures
152 else if ( Scenario==2 ) {
153
154 // We use the bool to trigger the hgh res interpolation once the grid is constructed
155 applications::exahype2::ccz4::ApplyTwoPunctures(Q, volumeX, 0, _tp, not gridIsConstructed); //we interpolate for real IC here.
156 }
157 #endif
158 else {
159 logError( "initialCondition(...)", "initial scenario " << Scenario << " is not supported" );
160 }
161
162 for (int i=0; i<NumberOfUnknowns; i++) {
163 assertion2( std::isfinite(Q[i]), volumeX, i );
164 }
165
166 for (int i=NumberOfUnknowns; i<NumberOfUnknowns+NumberOfAuxiliaryVariables; i++) {
167 Q[i] = 0.0;
168 }
169
170
171/*
172 else {
173 enforceCCZ4constraints(Q);
174 }
175*/
176 logTraceOut( "initialCondition(...)" );
177}
178
179
181 const double * NOALIAS Q, // Q[59+0]
182 const tarch::la::Vector<DIMENSIONS,double>& volumeX,
183 const tarch::la::Vector<DIMENSIONS,double>& volumeH,
184 double t,
185 double dt,
186 double * NOALIAS S // S[59
187) {
188 logTraceInWith4Arguments( "sourceTerm(...)", volumeX, volumeH, t, dt );
189 for(int i=0; i<NumberOfUnknowns; i++){
190 assertion3( std::isfinite(Q[i]), i, volumeX, t );
191 }
192 // for (int i=NumberOfUnknowns; i<NumberOfUnknowns+NumberOfAuxiliaryVariables; i++) {
193 // S[i] = 0.0;
194 //}
195 benchmarks::exahype2::ccz4::CCZ4::sourceTerm(Q, volumeX, volumeH, t, dt, S, Offloadable::Yes);
196 /*
197 if (CCZ4smoothing>0){// then we apply simple laplacian smoothing
198 constexpr int NumberOfRefinementLayers = 3;
199 double Radius[NumberOfRefinementLayers] = {5.0*1.8, 3.0*1.8, 1.5*1.8};
200 double radius=volumeX(0)*volumeX(0)+volumeX(1)*volumeX(1)+volumeX(2)*volumeX(2); radius=pow(radius,0.5);
201 ::exahype2::CellAccess access(
202 Q, // make it initially point to input
203 1, // halo size, which you know as user
204 NumberOfUnknowns, // defined in superclass
205 NumberOfAuxiliaryVariables // defined in superclass
206 NumberOfDoFsPerAxisInCell, // defined in superclass
207 );
208 double laplacian=0.0;
209 for (int unknown=0; unknown<NumberOfUnknowns; unknown++) {
210 laplacian = -6.0 * access.centre(unknown)
211 + 1.0 * access.left(0,unknown)+ 1.0 * access.right(0,unknown)
212 + 1.0 * access.left(1,unknown)+ 1.0 * access.right(1,unknown)
213 + 1.0 * access.left(2,unknown)+ 1.0 * access.right(2,unknown);
214 laplacian /= volumeH(0);
215 laplacian /= volumeH(0);
216 double coef=CCZ4smoothing*(std::exp(-5.0*std::abs(radius-Radius[0])) + std::exp(-5.0*std::abs(radius-Radius[1])) + std::exp(-5.0*std::abs(radius-Radius[2])) )/3.0;
217 coef=CCZ4smoothing;
218 S[unknown]+=coef*laplacian;
219 }
220 }*/
221
222 for(int i=0; i<NumberOfUnknowns; i++){
223 nonCriticalAssertion3( std::isfinite(S[i]), i, volumeX, t );
224 }
225 logTraceOut( "sourceTerm(...)" );
226}
227
228
230 const double * NOALIAS Qinside, // Qinside[59+0]
231 double * NOALIAS Qoutside, // Qoutside[59+0]
232 const tarch::la::Vector<DIMENSIONS,double>& faceCentre,
233 const tarch::la::Vector<DIMENSIONS,double>& volumeH,
234 double t,
235 int normal
236) {
237 logTraceInWith4Arguments( "boundaryConditions(...)", faceCentre, volumeH, t, normal );
238 for(int i=0; i<NumberOfUnknowns+NumberOfAuxiliaryVariables; i++) {
239 assertion4( Qinside[i]==Qinside[i], faceCentre, t, normal, i );
240 Qoutside[i]=Qinside[i];
241 }
242 logTraceOut( "boundaryConditions(...)" );
243}
244
245
247 const double * NOALIAS Q, // Q[59+0],
248 const tarch::la::Vector<DIMENSIONS,double>& faceCentre,
249 const tarch::la::Vector<DIMENSIONS,double>& volumeH,
250 double t,
251 double dt,
252 int normal
253)
254{
255 return maxEigenvalue(Q, faceCentre, volumeH, t, dt, normal, Offloadable::Yes);
256}
257
258
260 const double * NOALIAS Q, // Q[59+0],
261 const double * NOALIAS deltaQ, // [59+0]
262 const tarch::la::Vector<DIMENSIONS,double>& faceCentre,
263 const tarch::la::Vector<DIMENSIONS,double>& volumeH,
264 double t,
265 double dt,
266 int normal,
267 double * NOALIAS BgradQ // BgradQ[59]
268) {
269 logTraceInWith4Arguments( "nonconservativeProduct(...)", faceCentre, volumeH, t, normal );
270 assertion( normal>=0 );
271 assertion( normal<DIMENSIONS );
272 nonconservativeProduct(Q, deltaQ, faceCentre, volumeH, t, dt, normal, BgradQ, Offloadable::Yes);
273
274 for (int i=0; i<NumberOfUnknowns; i++) {
275 nonCriticalAssertion4( std::isfinite(BgradQ[i]), i, faceCentre, t, normal );
276 }
277 logTraceOut( "nonconservativeProduct(...)" );
278}
279
281 const double * NOALIAS Q, // Q[59+0],
282 const double * NOALIAS deltaQ, // [59+0]
283 const tarch::la::Vector<DIMENSIONS,double>& faceCentre,
284 const tarch::la::Vector<DIMENSIONS,double>& volumeH,
285 double t,
286 double dt,
287 int normal,
288 double * NOALIAS BgradQ, // BgradQ[59]
289 Offloadable
290)
291{
292 double gradQSerialised[NumberOfUnknowns*3];
293 for (int i=0; i<NumberOfUnknowns; i++) {
294 gradQSerialised[i+0*NumberOfUnknowns] = 0.0;
295 gradQSerialised[i+1*NumberOfUnknowns] = 0.0;
296 gradQSerialised[i+2*NumberOfUnknowns] = 0.0;
297
298 gradQSerialised[i+normal*NumberOfUnknowns] = deltaQ[i];
299 }
300 //for (int i=NumberOfUnknowns; i<NumberOfUnknowns+NumberOfAuxiliaryVariables; i++) {
301 // BgradQ[i] = 0.0;
302 //}
303 applications::exahype2::ccz4::ncp(BgradQ, Q, gradQSerialised, normal, CCZ4LapseType, CCZ4ds, CCZ4c, CCZ4e, CCZ4f, CCZ4bs, CCZ4sk, CCZ4xi, CCZ4mu, CCZ4SO);
304}
305
307 const double * NOALIAS Q,
308 const tarch::la::Vector<DIMENSIONS,double>& volumeCentre,
309 const tarch::la::Vector<DIMENSIONS,double>& volumeH,
310 double t
311) {
312 ::exahype2::RefinementCommand result = ::exahype2::RefinementCommand::Keep;
313
314 const double radius = tarch::la::norm2( volumeCentre );
315 //
316 // see documentation in header file
317 //
318 if (CCZ4ReSwi==1) { //radius based
319 if (radius<0.1) {
320 result=::exahype2::RefinementCommand::Refine;
321 }
322 }
323 if (CCZ4ReSwi==2) { //
324 if (tarch::la::equals(t,0.0)){ //as we use a quantity calculated in postpocessing, we need to provide criterion at the first timestep
325 constexpr int NumberOfRefinementLayers = 2;
326// current "standard" refinement pattern
327 double Radius[NumberOfRefinementLayers] = {4, 2.5};
328 double MaxH[NumberOfRefinementLayers] = {0.15,0.04};
329 result = ::exahype2::RefinementCommand::Keep;
330 for (int i=0; i<NumberOfRefinementLayers; i++) {
331 if (radius<Radius[i] and tarch::la::max(volumeH)>MaxH[i]) {
332 result=::exahype2::RefinementCommand::Refine;
333 }
334 }
335 }
336 }
337 return result;
338}
339
340
341
TP::TwoPunctures * _tp
Definition CCZ4.cpp:16
void initialCondition(double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &volumeCentre, const tarch::la::Vector< DIMENSIONS, double > &volumeH, bool gridIsConstructed) override
Definition CCZ4.cpp:17
virtual void nonconservativeProduct(const double *NOALIAS Q, const double *NOALIAS deltaQ, const tarch::la::Vector< DIMENSIONS, double > &faceCentre, const tarch::la::Vector< DIMENSIONS, double > &volumeH, double t, double dt, int normal, double *NOALIAS BgradQ) override
Definition CCZ4.cpp:259
virtual double maxEigenvalue(const double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &faceCentre, const tarch::la::Vector< DIMENSIONS, double > &volumeH, double t, double dt, int normal) override
Determine max eigenvalue over Jacobian in a given point with solution values (states) Q.
Definition CCZ4.cpp:246
::exahype2::RefinementCommand refinementCriterion(const double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &volumeCentre, const tarch::la::Vector< DIMENSIONS, double > &volumeH, double t) override
Refinement criterion.
Definition CCZ4.cpp:70
virtual void boundaryConditions(const double *NOALIAS Qinside, double *NOALIAS Qoutside, const tarch::la::Vector< DIMENSIONS, double > &faceCentre, const tarch::la::Vector< DIMENSIONS, double > &volumeH, double t, int normal) override
Definition CCZ4.cpp:56
static tarch::logging::Log _log
Definition CCZ4.h:32
void prepare(TP::TwoPunctures *tp)
Definition CCZ4.cpp:23
void sourceTerm(const double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &volumeCentre, const tarch::la::Vector< DIMENSIONS, double > &volumeH, double t, double dt, double *NOALIAS S) override
Definition CCZ4.cpp:180
void diagonal_gaugeWave(double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &x, double t)
static void ncp(double *BgradQ, const double *const Q, const double *const gradQSerialised, const int normal, const int CCZ4LapseType, const double CCZ4ds, const double CCZ4c, const double CCZ4e, const double CCZ4f, const double CCZ4bs, const double CCZ4sk, const double CCZ4xi, const double CCZ4mu, const double CCZ4SO)
void linearWave(double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &X, double t)
void ApplyTwoPunctures(double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &X, double t, TP::TwoPunctures *tp, bool low_res)
void flat(double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &X, double t)
void gaugeWave(double *NOALIAS Q, const tarch::la::Vector< DIMENSIONS, double > &x, double t)
double par_S_plus[3]
std::string grid_setup_method
double par_P_plus[3]
double par_S_minus[3]
double center_offset[3]
double target_M_minus
double par_P_minus[3]