Peano
Loading...
Searching...
No Matches
DynamicRuptureElastic.py
Go to the documentation of this file.
1def initial(pointwise_initial_conditions):
2 return """
3 std::fill_n(Q, (NumberOfAuxiliaryVariables + NumberOfUnknowns) * (Order + 1) * (Order + 1) * (Order + 1), 0);
4
5 context->initUnknownsPatch(Q, x, h, 0.0, 0.0,
6 [&](
7 const {{SOLUTION_STORAGE_PRECISION}}* const x,
8 const tarch::la::Vector<DIMENSIONS,double>& center,
9 const double t,
10 const double dt,
11 {{SOLUTION_STORAGE_PRECISION}}* Q
12 ) -> void { """ + pointwise_initial_conditions + """
13 }
14 );
15"""
16
17def flux():
18 return """
19 auto sigma_xx = Q[Shortcuts::sigma + 0];
20 auto sigma_yy = Q[Shortcuts::sigma + 1];
21 auto sigma_zz = Q[Shortcuts::sigma + 2];
22 auto sigma_xy = Q[Shortcuts::sigma + 3];
23 auto sigma_xz = Q[Shortcuts::sigma + 4];
24 auto sigma_yz = Q[Shortcuts::sigma + 5];
25
26 auto jacobian = Q[Shortcuts::jacobian];
27
28 std::fill_n(F, NumberOfUnknowns, 0.);
29
30 switch (normal) {
31 case 0: {
32 auto q_x = Q[Shortcuts::metric_derivative + 0];
33 auto q_y = Q[Shortcuts::metric_derivative + 1];
34 auto q_z = Q[Shortcuts::metric_derivative + 2];
35 F[0] = -jacobian * (q_x * sigma_xx + q_y * sigma_xy + q_z * sigma_xz);
36 F[1] = -jacobian * (q_x * sigma_xy + q_y * sigma_yy + q_z * sigma_yz);
37 F[2] = -jacobian * (q_x * sigma_xz + q_y * sigma_yz + q_z * sigma_zz);
38 } break;
39 case 1: {
40 auto r_x = Q[Shortcuts::metric_derivative + 3];
41 auto r_y = Q[Shortcuts::metric_derivative + 4];
42 auto r_z = Q[Shortcuts::metric_derivative + 5];
43 F[0] = -jacobian * (r_x * sigma_xx + r_y * sigma_xy + r_z * sigma_xz);
44 F[1] = -jacobian * (r_x * sigma_xy + r_y * sigma_yy + r_z * sigma_yz);
45 F[2] = -jacobian * (r_x * sigma_xz + r_y * sigma_yz + r_z * sigma_zz);
46 } break;
47 case 2: {
48 auto s_x = Q[Shortcuts::metric_derivative + 6];
49 auto s_y = Q[Shortcuts::metric_derivative + 7];
50 auto s_z = Q[Shortcuts::metric_derivative + 8];
51 F[0] = -jacobian * (s_x * sigma_xx + s_y * sigma_xy + s_z * sigma_xz);
52 F[1] = -jacobian * (s_x * sigma_xy + s_y * sigma_yy + s_z * sigma_yz);
53 F[2] = -jacobian * (s_x * sigma_xz + s_y * sigma_yz + s_z * sigma_zz);
54 }
55 }
56"""
57
58def ncp():
59 return """
60 auto rho = Q[Shortcuts::rho];
61 auto cp = Q[Shortcuts::cp];
62 auto cs = Q[Shortcuts::cs];
63 auto jacobian = Q[Shortcuts::jacobian];
64 auto mu = rho * cs * cs;
65 auto lambda = rho * cp * cp - 2 * mu;
66 auto rho_inv = 1.0 / (rho * jacobian);
67
68 std::fill_n(BTimesDeltaQ, NumberOfUnknowns, 0.0);
69
70 switch (normal) {
71 case 0: {
72 auto u_q = deltaQ[Shortcuts::v + 0];
73 auto v_q = deltaQ[Shortcuts::v + 1];
74 auto w_q = deltaQ[Shortcuts::v + 2];
75 auto q_x = Q[Shortcuts::metric_derivative + 0];
76 auto q_y = Q[Shortcuts::metric_derivative + 1];
77 auto q_z = Q[Shortcuts::metric_derivative + 2];
78 BTimesDeltaQ[Shortcuts::sigma + 0] = -q_x*u_q;
79 BTimesDeltaQ[Shortcuts::sigma + 1] = -q_y*v_q;
80 BTimesDeltaQ[Shortcuts::sigma + 2] = -q_z*w_q;
81 BTimesDeltaQ[Shortcuts::sigma + 3] = -(q_y*u_q+q_x*v_q); //sigma_xy
82 BTimesDeltaQ[Shortcuts::sigma + 4] = -(q_z*u_q+q_x*w_q); //sigma_xz
83 BTimesDeltaQ[Shortcuts::sigma + 5] = -(q_z*v_q+q_y*w_q); //sigma_yz
84 } break;
85 case 1: {
86 auto u_r = deltaQ[Shortcuts::v + 0];
87 auto v_r = deltaQ[Shortcuts::v + 1];
88 auto w_r = deltaQ[Shortcuts::v + 2];
89 auto r_x = Q[Shortcuts::metric_derivative + 3];
90 auto r_y = Q[Shortcuts::metric_derivative + 4];
91 auto r_z = Q[Shortcuts::metric_derivative + 5];
92 BTimesDeltaQ[Shortcuts::sigma + 0] = -r_x*u_r;
93 BTimesDeltaQ[Shortcuts::sigma + 1] = -r_y*v_r;
94 BTimesDeltaQ[Shortcuts::sigma + 2] = -r_z*w_r;
95 BTimesDeltaQ[Shortcuts::sigma + 3] = -(r_y*u_r+r_x*v_r); //sigma_xy
96 BTimesDeltaQ[Shortcuts::sigma + 4] = -(r_z*u_r+r_x*w_r); //sigma_xz
97 BTimesDeltaQ[Shortcuts::sigma + 5] = -(r_z*v_r+r_y*w_r); //sigma_yz
98 } break;
99 case 2: {
100 auto u_s = deltaQ[Shortcuts::v + 0];
101 auto v_s = deltaQ[Shortcuts::v + 1];
102 auto w_s = deltaQ[Shortcuts::v + 2];
103 auto s_x = Q[Shortcuts::metric_derivative + 6];
104 auto s_y = Q[Shortcuts::metric_derivative + 7];
105 auto s_z = Q[Shortcuts::metric_derivative + 8];
106 BTimesDeltaQ[Shortcuts::sigma + 0] = -s_x*u_s;
107 BTimesDeltaQ[Shortcuts::sigma + 1] = -s_y*v_s;
108 BTimesDeltaQ[Shortcuts::sigma + 2] = -s_z*w_s;
109 BTimesDeltaQ[Shortcuts::sigma + 3] = -(s_y*u_s+s_x*v_s); //sigma_xy
110 BTimesDeltaQ[Shortcuts::sigma + 4] = -(s_z*u_s+s_x*w_s); //sigma_xz
111 BTimesDeltaQ[Shortcuts::sigma + 5] = -(s_z*v_s+s_y*w_s); //sigma_yz
112 }
113 }
114"""
115
117 return """
118 std::fill_n(S, NumberOfAuxiliaryVariables, 0);
119
120 S[9] = -Q[0];
121 S[10] = -Q[1];
122 S[11] = -Q[2];
123"""
124
126 return """
127 auto rho = Q[Shortcuts::rho];
128 auto cp = Q[Shortcuts::cp];
129 auto cs = Q[Shortcuts::cs];
130 auto jacobian = Q[Shortcuts::jacobian];
131
132 auto mu = rho * cs * cs;
133 auto lambda = rho * cp * cp - 2 * mu;
134 auto rho_inv=1.0/(rho*jacobian);
135
136 // Rhs uses the same formula regardless of dimension, hence no switch necessary
137
138 rhs[Shortcuts::v + 0] = rho_inv * rhs[Shortcuts::v + 0];
139 rhs[Shortcuts::v + 1] = rho_inv * rhs[Shortcuts::v + 1];
140 rhs[Shortcuts::v + 2] = rho_inv * rhs[Shortcuts::v + 2];
141
142 double lam_temp = lambda * (rhs[3] + rhs[4] + rhs[5]);
143
144 rhs[3]=(2*mu) * rhs[3] +lam_temp;
145 rhs[4]=(2*mu) * rhs[4] +lam_temp;
146 rhs[5]=(2*mu) * rhs[5] +lam_temp;
147
148 rhs[6]= mu*rhs[6];
149 rhs[7]= mu*rhs[7];
150 rhs[8]= mu*rhs[8];
151
152 rhs[9]= rhs[9];
153 rhs[10]= rhs[10];
154 rhs[11]= rhs[11];
155
156
157"""
158
160 return """
161 context->riemannSolver(
162 FL, FR,
163 QL, QR,
164 t, dt,
165 h,
166 direction,
167 isBoundaryFace,
168 faceIndex,
169 1 //surface
170 );
171"""
172
174 return """
175#define _CUSTOM_COORDINATES
176#define ASAGI_NOMPI
177#define _TOP 1
178
179#include "../ExaSeis_core/Curvilinear/ContextDynamicRupture.h"
180#include "../ExaSeis_core/Numerics/riemannsolverDynamicRupture.h"
181
182#include "peano4/datamanagement/CellMarker.h"
183"""
184
186 return """
187ContextDynamicRupture<{{NAMESPACE | join("::")}}::VariableShortcuts{{SOLVER_NAME}},
188 {{NAMESPACE | join("::")}}::{{CLASSNAME}}::Order + 1,
189 {{NAMESPACE | join("::")}}::{{CLASSNAME}}::NumberOfUnknowns,
190 {{NAMESPACE | join("::")}}::{{CLASSNAME}}::NumberOfAuxiliaryVariables,
191 {{SOLUTION_STORAGE_PRECISION}}>* {{NAMESPACE | join("::")}}::{{CLASSNAME}}::context;
192
193tarch::la::Vector<DIMENSIONS,double> {{NAMESPACE | join("::")}}::{{CLASSNAME}}::invertProjection(const tarch::la::Vector<DIMENSIONS,double> coordinates){
194
195 if(peano4::datamanagement::CellMarker::isContained(
196 coordinates, DomainOffset+0.5*DomainSize, DomainSize, 0.
197 )){
198 double fixedCoords[3];
199 fixedCoords[toolbox::curvi::Coordinate::X] = coordinates[0];
200 fixedCoords[toolbox::curvi::Coordinate::Y] = coordinates[1];
201 fixedCoords[toolbox::curvi::Coordinate::Z] = coordinates[2];
202
203 tarch::la::Vector<DIMENSIONS,double> result;
204 toolbox::curvi::Interface* curviInterface = context->getInterface();
205 result[0] = curviInterface->invertProjection(toolbox::curvi::Coordinate::X, fixedCoords);
206 result[1] = curviInterface->invertProjection(toolbox::curvi::Coordinate::Y, fixedCoords);
207 result[2] = curviInterface->invertProjection(toolbox::curvi::Coordinate::Z, fixedCoords);
208
209 return result;
210 }
211 return coordinates;
212}
213"""
214
216 return """
217public:
218 double QuadraturePoints1d[Order+1];
219
220 tarch::la::Vector<DIMENSIONS,double> invertProjection(const tarch::la::Vector<DIMENSIONS,double> coordinates);
221
222protected:
223 static ContextDynamicRupture<VariableShortcuts{{SOLVER_NAME}}, Order + 1, NumberOfUnknowns, NumberOfAuxiliaryVariables, {{SOLUTION_STORAGE_PRECISION}}>* context;
224"""
225
226def init_grid_step_implementation(scenario_string):
227 return """
228 std::copy_n(
229 kernels::{{SOLVER_NAME}}::Quadrature<{{SOLUTION_STORAGE_PRECISION}}>::nodes,
230 (Order+1),
231 QuadraturePoints1d
232 );
233
234 std::string topography_string = \"""" + scenario_string + """.yaml";
235
236 //setting coarsestMeshLevel and maxAdaptiveMeshLevel
237 double maxDSize = std::numeric_limits<double>::min();
238 double minDSize = std::numeric_limits<double>::max();
239 tarch::la::Vector<DIMENSIONS, double> sizes = DomainSize;
240
241 for(int i=0; i<DIMENSIONS; i++){
242 if(sizes[i]>maxDSize){
243 maxDSize = sizes[i];
244 }
245 if(sizes[i]<minDSize){
246 minDSize = sizes[i];
247 }
248 }
249
250 int depth = 0;
251
252 //finding coarsest possible Mesh level
253 while(maxDSize>MaxAdmissibleCellH){
254 depth += 1;
255 maxDSize /= 3.0;
256 }
257
258 double realCoarsestMeshSize = maxDSize;
259 double coarsestMeshLevel = depth;
260
261 depth = 0;
262 while(minDSize>MinAdmissibleCellH){
263 depth += 1;
264 minDSize /= 3.0;
265 }
266
267 logTraceOutWith1Argument("Freesurface set at ", std::to_string(_TOP * 2));
268
269 context = new ContextDynamicRupture<VariableShortcuts{{SOLVER_NAME}}, Order + 1, NumberOfUnknowns, NumberOfAuxiliaryVariables, {{SOLUTION_STORAGE_PRECISION}}>(
270 topography_string,
271 // filename_rupture_model,
272 coarsestMeshLevel,
273 realCoarsestMeshSize,
274 depth,
275 DomainOffset, DomainSize,
276 kernels::{{SOLVER_NAME}}::Quadrature<{{SOLUTION_STORAGE_PRECISION}}>::nodes,
277 kernels::{{SOLVER_NAME}}::DGMatrices<{{SOLUTION_STORAGE_PRECISION}}>::dudx
278 );
279
280 std::cout << "Freesurface set at " << _TOP * 2 << std::endl;
281"""
282
284 return """
285 delete context;
286"""
287
289 return """
290 if (_solverState==SolverState::GridInitialisation) {
291 std::string filename_rupture_model = \"""" + scenario_string + """_fault.yaml";
292 context->initRuptureModel(filename_rupture_model);
293 }
294"""
init_grid_step_implementation(scenario_string)
initial(pointwise_initial_conditions)
finish_time_step_implementation(scenario_string)