sandbox/larswd/mltracer2D.h
2D algorithm for transport of tracer
The general structure is:
- Initializing the linear system
- Solve linear system
- Check for convergence
- Cleanup
The initialization requires us declaring a lot of arrays, which we initialize once at the start. Some of these are likely superflous, and will be cleaned up in a future patch.
(Ml_Tracer _i_tracer){
Ml_Tracer transport_tracer// Initialization
double tol = tml().tol;
scalar c = tml().c;
double rho_c = tml().rho_c;
scalar c_0 = new scalar[nl];
scalar c_prev = new scalar[nl];
double a_c[N], a_w[N], a_e[N],b[N], c_[N];
double total_c0 = 0;
;
TDMA_fluxes cfforeach(serial){
() {
foreach_layer[] = c[];
c_0[] = c[];
c_prev+= Delta*Delta*h[]*sq(c[]);
total_c0 }
}
printf("C total before = %g\n", total_c0);
double residual = HUGE;
int iterations = 0;
for (int i = 0; i < N; i++){
[i] = 0.0;
a_c[i] = 0.0;
a_w[i] = 0.0;
a_e[i] = 0.0;
b[i] = 0.0;
c_}
while (residual > tol){
= 0;
residual foreach_point(0,0, nowarning){
for (int l = 0; l < nl; l++){
// Initializing Linear system
for (point.i = GHOSTS; point.i < point.n + GHOSTS; point.i++){
= compute_fluxes(point, l, _i_tracer, c_0);
cf int idx = point.i - GHOSTS;
[idx] = - cf.aW;
a_w[idx] = rho_c/dt + cf.aW + cf.aE + cf.aT + cf.aB + cf.div - cf.Sp;
a_c[idx] = - cf.aE;
a_e[idx] = rho_c/dt * c_0[0,0,l] + cf.Su;
bif (l < nl-1)
[idx] += cf.aT*c_prev[0,0,l+1];
bif (l > 0)
[idx] += cf.aB*c_prev[0,0,l-1];
bdouble Sdc = TVD_deferred_correction(point, c_prev, l, _i_tracer);
[idx] += Sdc/Delta;
b}
//sleep(3);
(a_w, a_c, a_e, b, c_, point.n);
TDMAfor (point.i = GHOSTS; point.i < point.n + GHOSTS; point.i++){
[0,0,l] = c_[point.i - GHOSTS];
c}
}
}
double total_c = 0;
foreach(serial){
(){
foreach_layer+= sq(c[] - c_prev[])*Delta*Delta*h[];
residual += Delta*Delta*h[]*sq(c[]);
total_c }
}
foreach(){
()
foreach_layer[] = c[];
c_prev}
printf("total_c = %g residual = %g.\n",total_c, residual);
if (nl > 1)
= sqrt(residual);
residual
else= 0;
residual ++;
iterations}
().c = c;
tmlprintf("Solution converged after %d iterations\n", iterations);
delete((scalar *){c_0, c_prev});
return _i_tracer;
}