/* advection_schemes.h - Two test advection algorithms from the Adept paper Copyright (C) 2014 The University of Reading Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty. */ // Use templates so that these functions can be easily compiled with // different automatic differentiation tools in order that the // performance of these tools can be compared. #ifndef ADVECTION_SCHEMES_H #define ADVECTION_SCHEMES_H 1 #include // Use a fixed problem size #include "nx.h" // Lax-Wendroff scheme applied to linear advection template void lax_wendroff(int nt, Real c, const aReal q_init[NX], aReal q[NX]) { aReal flux[NX-1]; // Fluxes between boxes for (int i=0; i void toon(int nt, Real c, const aReal q_init[NX], aReal q[NX]) { aReal flux[NX-1]; // Fluxes between boxes for (int i=0; i q[i] || bigdiff < -q[i]) { flux[i] = (exp(c*log(q[i]/q[i+1]))-1.0) * q[i]*q[i+1] / (q[i]-q[i+1]); // } // else { // flux[i] = c*q[i]; // Upwind scheme // } } for (int i=1; i struct is_active { static const bool value = false; }; template <> struct is_active { static const bool value = true; }; // Lax-Wendroff scheme applied to linear advection template void lax_wendroff_vector(int nt, Real c, const aReal q_init[NX], aReal q[NX]) { using namespace adept; typedef adept::Array<1,Real,::is_active::value> my_vector; // typedef adept::Array<1,Real,true> my_vector; my_vector Q(NX); my_vector F(NX-1); my_vector Qleft = Q(range(0,end-1)); my_vector Qright = Q(range(1,end)); my_vector Qcentre = Q(range(1,end-1)); my_vector Fleft = F(range(0,end-1)); my_vector Fright = F(range(1,end)); for (int i=0; i void toon_vector(int nt, Real c, const aReal q_init[NX], aReal q[NX]) { using namespace adept; typedef adept::Array<1,Real,::is_active::value> my_vector; my_vector Q(NX); my_vector F(NX-1); my_vector Qleft = Q(range(0,end-1)); my_vector Qright = Q(range(1,end)); my_vector Qcentre = Q(range(1,end-1)); my_vector Fleft = F(range(0,end-1)); my_vector Fright = F(range(1,end)); for (int i=0; i