Peano
CCZ4Helper.py
Go to the documentation of this file.
2  return """
3  {
4  #if DIMENSIONS==2
5  constexpr int itmax = {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} * {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}};
6  #endif
7 
8  #if DIMENSIONS==3
9  constexpr int itmax = {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} * {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} * {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}};
10  #endif
11 
12  int index = 0;
13  for (int i=0;i<itmax;i++)
14  {
15  applications::exahype2::ccz4::enforceCCZ4constraints( newQ+index );
16  index += {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}};
17  }
18  }
19 """
20 
21 def get_body_of_adm_constraints(patch_size, number_of_output_variable, so_flag):
22  if so_flag:
23  extra_derivative_assign="""
24  ::exahype2::enumerator::AoSLexicographicEnumerator enumeratorWithAuxiliaryVariablesOnReconstructedPatch( 1, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}, {{HALO_SIZE}}, {{NUMBER_OF_UNKNOWNS}}, {{NUMBER_OF_AUXILIARY_VARIABLES}});
25  ::exahype2::enumerator::AoSLexicographicEnumerator enumeratorWithoutAuxiliaryVariables( {{RK_STEPS}}, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}, 0, {{NUMBER_OF_UNKNOWNS}}, 0 );
26  {{PRIMARY_VARS_INDICES}}
27  {{AUXILIARY_VARS_INDICES}}
28 
29  dfor( dof, 3 ) {
30  for (int unknown : auxiliaryVarsIndices) {
31  oldQWithHalo[ enumeratorWithAuxiliaryVariablesOnReconstructedPatch(0,dof,unknown) ] = //abuse of RHS, auxiliary variables are stored there.
32  fineGridCellCCZ4QRhsEstimates.value[ enumeratorWithoutAuxiliaryVariables(0,dof,unknown) ];
33  }
34  }
35  """
36  else:
37  extra_derivative_assign=""
38  return """
39  const int patchSize = """ + str( patch_size ) + """;
40  double volumeH = ::exahype2::fv::getVolumeLength(marker.h(),patchSize);
41 
42  const int n_a_v="""+str(number_of_output_variable)+""";
43  const int overlap=3; //make sure you are using fd4 solver!
44 
45  if (not marker.willBeRefined() and repositories::instanceOfCCZ4.getSolverState()!=CCZ4::SolverState::GridConstruction and repositories::instanceOfCCZ4.getSolverState()==CCZ4::SolverState::RungeKuttaSubStep0) {"""+extra_derivative_assign+"""
46 
47  dfor(cell,patchSize) {
48  tarch::la::Vector<DIMENSIONS,int> currentCell = cell + tarch::la::Vector<DIMENSIONS,int>(overlap);
49 
50  double gradQ[3*59]={ 0 };
51 
52  for (int d=0; d<3; d++) {
53  tarch::la::Vector<DIMENSIONS,int> leftCell = currentCell;
54  tarch::la::Vector<DIMENSIONS,int> rightCell = currentCell;
55  tarch::la::Vector<DIMENSIONS,int> DouleftCell = currentCell;
56  tarch::la::Vector<DIMENSIONS,int> DourightCell = currentCell;
57  leftCell(d) -= 1; DouleftCell(d) -= 2;
58  rightCell(d) += 1; DourightCell(d) += 2;
59  const int leftCellSerialised = peano4::utils::dLinearised(leftCell, patchSize + 2*overlap);
60  const int rightCellSerialised = peano4::utils::dLinearised(rightCell,patchSize + 2*overlap);
61  const int DouleftCellSerialised = peano4::utils::dLinearised(DouleftCell, patchSize + 2*overlap);
62  const int DourightCellSerialised = peano4::utils::dLinearised(DourightCell,patchSize + 2*overlap);
63  for(int i=0; i<59; i++) {
64  gradQ[d*59+i] = ( -1*oldQWithHalo[DourightCellSerialised*(59+n_a_v)+i] + 8*oldQWithHalo[rightCellSerialised*(59+n_a_v)+i] - 8*oldQWithHalo[leftCellSerialised*(59+n_a_v)+i] + 1*oldQWithHalo[DouleftCellSerialised*(59+n_a_v)+i]) / 12.0 / volumeH;
65  }
66  }
67 
68  const int cellSerialised = peano4::utils::dLinearised(currentCell, patchSize + 2*overlap);
69 
70  double constraints[n_a_v]={0};
71  admconstraints(constraints, oldQWithHalo+cellSerialised*(59+n_a_v), gradQ);
72  ::exahype2::enumerator::AoSLexicographicEnumerator enumeratorWithAuxiliaryVariables ( 1, patchSize, 0, 59, n_a_v);
73  for (int i=0;i<n_a_v;i++){
74  fineGridCellCCZ4Q.value[ enumeratorWithAuxiliaryVariables(0,cell,59+i) ] = constraints[i];
75  }
76  }
77  }
78 """
79 
80 def get_body_of_Psi_Calc(patch_size, number_of_output_variable, so_flag):
81  if so_flag:
82  extra_derivative_assign="""
83  ::exahype2::enumerator::AoSLexicographicEnumerator enumeratorWithAuxiliaryVariablesOnReconstructedPatch( 1, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}, {{HALO_SIZE}}, {{NUMBER_OF_UNKNOWNS}}, {{NUMBER_OF_AUXILIARY_VARIABLES}});
84  ::exahype2::enumerator::AoSLexicographicEnumerator enumeratorWithoutAuxiliaryVariables( {{RK_STEPS}}, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}, 0, {{NUMBER_OF_UNKNOWNS}}, 0 );
85  {{PRIMARY_VARS_INDICES}}
86  {{AUXILIARY_VARS_INDICES}}
87 
88  dfor( dof, 3 ) {
89  for (int unknown : auxiliaryVarsIndices) {
90  oldQWithHalo[ enumeratorWithAuxiliaryVariablesOnReconstructedPatch(0,dof,unknown) ] = //abuse of RHS, auxiliary variables are stored there.
91  fineGridCellCCZ4QRhsEstimates.value[ enumeratorWithoutAuxiliaryVariables(0,dof,unknown) ];
92  }
93  }
94  """
95  else:
96  extra_derivative_assign=""
97  return """
98  const int patchSize = """ + str( patch_size ) + """;
99  double volumeH = ::exahype2::fv::getVolumeLength(marker.h(),patchSize);
100 
101  const int n_a_v="""+str(number_of_output_variable)+""";
102  const int overlap=3; //make sure you are using fd4 solver!
103 
104  if (not marker.willBeRefined() and repositories::instanceOfCCZ4.getSolverState()!=CCZ4::SolverState::GridConstruction and repositories::instanceOfCCZ4.getSolverState()==CCZ4::SolverState::RungeKuttaSubStep0) {"""+extra_derivative_assign+"""
105 
106  dfor(cell,patchSize) {
107  tarch::la::Vector<DIMENSIONS,int> currentCell = cell + tarch::la::Vector<DIMENSIONS,int>(overlap);
108 
109  double gradQ[3*59]={ 0 };
110 
111  /*for (int d=0; d<3; d++) {
112  tarch::la::Vector<DIMENSIONS,int> leftCell = currentCell;
113  tarch::la::Vector<DIMENSIONS,int> rightCell = currentCell;
114  leftCell(d) -= 1;
115  rightCell(d) += 1;
116  const int leftCellSerialised = peano4::utils::dLinearised(leftCell, patchSize + 2*overlap);
117  const int rightCellSerialised = peano4::utils::dLinearised(rightCell,patchSize + 2*overlap);
118  for(int i=0; i<59; i++) {
119  gradQ[d*59+i] = ( oldQWithHalo[rightCellSerialised*(59+n_a_v)+i] - oldQWithHalo[leftCellSerialised*(59+n_a_v)+i] ) / 2.0 / volumeH;
120  }
121  }*/
122 
123  for (int d=0; d<3; d++) {
124  tarch::la::Vector<DIMENSIONS,int> leftCell = currentCell;
125  tarch::la::Vector<DIMENSIONS,int> rightCell = currentCell;
126  tarch::la::Vector<DIMENSIONS,int> DouleftCell = currentCell;
127  tarch::la::Vector<DIMENSIONS,int> DourightCell = currentCell;
128  leftCell(d) -= 1; DouleftCell(d) -= 2;
129  rightCell(d) += 1; DourightCell(d) += 2;
130  const int leftCellSerialised = peano4::utils::dLinearised(leftCell, patchSize + 2*overlap);
131  const int rightCellSerialised = peano4::utils::dLinearised(rightCell,patchSize + 2*overlap);
132  const int DouleftCellSerialised = peano4::utils::dLinearised(DouleftCell, patchSize + 2*overlap);
133  const int DourightCellSerialised = peano4::utils::dLinearised(DourightCell,patchSize + 2*overlap);
134  for(int i=0; i<59; i++) {
135  gradQ[d*59+i] = ( -1*oldQWithHalo[DourightCellSerialised*(59+n_a_v)+i] + 8*oldQWithHalo[rightCellSerialised*(59+n_a_v)+i] - 8*oldQWithHalo[leftCellSerialised*(59+n_a_v)+i] + 1*oldQWithHalo[DouleftCellSerialised*(59+n_a_v)+i]) / 12.0 / volumeH;
136  }
137  }
138 
139  const int cellSerialised = peano4::utils::dLinearised(currentCell, patchSize + 2*overlap);
140 
141  double Psi4[n_a_v]={0};
142  double currentPosition[3];
143  for (int d=0; d<3; d++) currentPosition[d]=marker.getOffset()(d)+(cell(d)+0.5)*volumeH;
144  Psi4Calc(Psi4, oldQWithHalo+cellSerialised*(59+n_a_v), gradQ, currentPosition);
145  ::exahype2::enumerator::AoSLexicographicEnumerator enumeratorWithAuxiliaryVariables ( 1, patchSize, 0, 59, n_a_v);
146  fineGridCellCCZ4Q.value[ enumeratorWithAuxiliaryVariables(0,cell,59+0) ] = Psi4[0];
147  fineGridCellCCZ4Q.value[ enumeratorWithAuxiliaryVariables(0,cell,59+1) ] = Psi4[1];
148  }
149  }
150 """
151 
152 def get_body_of_SommerfeldCondition(scenario, unknowns, auxiliary_variables, restart_time=-1):
153  if restart_time>0:
154  timeStamp="CheckpointTimeStamp"
155  else:
156  timeStamp="-1.0"
157 
158  if scenario=="single-puncture":
159  return """
160  ::exahype2::fd::applySommerfeldConditions(
161  [&](
162  const double * NOALIAS Q,
163  const tarch::la::Vector<DIMENSIONS,double>& faceCentre,
164  const tarch::la::Vector<DIMENSIONS,double>& gridCellH,
165  double t,
166  double dt,
167  int normal
168  ) -> double {
169  return repositories::{{SOLVER_INSTANCE}}.maxEigenvalue( Q, faceCentre, gridCellH, t, dt, normal );
170  },
171  [&](
172  double * NOALIAS Q,
173  const tarch::la::Vector<DIMENSIONS,double>& faceCentre,
174  const tarch::la::Vector<DIMENSIONS,double>& gridCellH
175  ) -> void {
176  for (int i=0; i<"""+str(unknowns + auxiliary_variables)+"""; i++) {
177  Q[i] = 0.0;
178  }
179  Q[0] = 1.0; Q[3] = 1.0; Q[5] = 1.0;
180  //const double r=tarch::la::norm2(faceCentre);
181  //Q[16] = 0.5*(1+(1-1.0/2/r)/(1+1.0/2/r));
182  //Q[54] = 1/(1+1.0/2/r)/(1+1.0/2/r);
183  Q[16] = 1.0; Q[54] = 1.0;
184  },
185  marker.x(),
186  marker.h(),
187  {{FACE_METADATA_ACCESSOR}}.getOldTimeStamp(marker.getSelectedFaceNumber()<DIMENSIONS ? 1 : 0),
188  repositories::{{SOLVER_INSTANCE}}.getMinTimeStepSize(),
189  {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
190  {{OVERLAP}},
191  {{NUMBER_OF_UNKNOWNS}},
192  {{NUMBER_OF_AUXILIARY_VARIABLES}},
193  marker.getSelectedFaceNumber(),
194  {0.0, 0.0, 0.0},
195  fineGridFace{{UNKNOWN_IDENTIFIER}}Old.value,
196  fineGridFace{{UNKNOWN_IDENTIFIER}}New.value,
197  """+timeStamp+"""
198  );
199 """
200  else:
201  return """
202  ::exahype2::fd::applySommerfeldConditions(
203  [&](
204  const double * NOALIAS Q,
205  const tarch::la::Vector<DIMENSIONS,double>& faceCentre,
206  const tarch::la::Vector<DIMENSIONS,double>& gridCellH,
207  double t,
208  double dt,
209  int normal
210  ) -> double {
211  return repositories::{{SOLVER_INSTANCE}}.maxEigenvalue( Q, faceCentre, gridCellH, t, dt, normal );
212  },
213  [&](
214  double * NOALIAS Q,
215  const tarch::la::Vector<DIMENSIONS,double>& faceCentre,
216  const tarch::la::Vector<DIMENSIONS,double>& gridCellH
217  ) -> void {
218  for (int i=0; i<"""+str(unknowns + auxiliary_variables)+"""; i++) {
219  Q[i] = 0.0;
220  }
221  Q[0] = 1.0; Q[3] = 1.0; Q[5] = 1.0;
222  Q[16] = 1.0; Q[54] = 1.0;
223  },
224  marker.x(),
225  marker.h(),
226  {{FACE_METADATA_ACCESSOR}}.getOldTimeStamp(marker.getSelectedFaceNumber()<DIMENSIONS ? 1 : 0),
227  repositories::{{SOLVER_INSTANCE}}.getMinTimeStepSize(),
228  {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}},
229  {{OVERLAP}},
230  {{NUMBER_OF_UNKNOWNS}},
231  {{NUMBER_OF_AUXILIARY_VARIABLES}},
232  marker.getSelectedFaceNumber(),
233  {0.0, 0.0, 0.0},
234  fineGridFace{{UNKNOWN_IDENTIFIER}}Old.value,
235  fineGridFace{{UNKNOWN_IDENTIFIER}}New.value,
236  """+timeStamp+"""
237  );
238 """
def get_body_of_adm_constraints(patch_size, number_of_output_variable, so_flag)
Definition: CCZ4Helper.py:21
def get_body_of_SommerfeldCondition(scenario, unknowns, auxiliary_variables, restart_time=-1)
Definition: CCZ4Helper.py:152
def get_body_of_Psi_Calc(patch_size, number_of_output_variable, so_flag)
Definition: CCZ4Helper.py:80
def get_body_of_enforceCCZ4constraint()
Definition: CCZ4Helper.py:1
str
Definition: ccz4.py:55