00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef AMROC_F77_EXACT_SOLUTION_H
00010 #define AMROC_F77_EXACT_SOLUTION_H
00011
00019 #include "ExactSolution.h"
00020
00021 template <class VectorType, int dim>
00022 class F77ExactBase {
00023 typedef typename VectorType::InternalDataType DataType;
00024 typedef GridData<VectorType,dim> vec_grid_data_type;
00025 typedef GridData<DataType,dim> grid_data_type;
00026
00027 public:
00028 typedef generic_fortran_func generic_func_type;
00029
00030 typedef void (*exact_1_func_type) ( const INTEGER& maxmx,
00031 const INTEGER& meqn, const INTEGER& mbc,
00032 const INTEGER& mx,
00033 const DOUBLE x[],
00034 const DOUBLE& dx,
00035 const DOUBLE& t, VectorType q[]);
00036 typedef void (*exact_2_func_type) ( const INTEGER& maxmx, const INTEGER& maxmy,
00037 const INTEGER& meqn, const INTEGER& mbc,
00038 const INTEGER& mx, const INTEGER& my,
00039 const DOUBLE x[], const DOUBLE y[],
00040 const DOUBLE& dx, const DOUBLE& dy,
00041 const DOUBLE& t, VectorType q[]);
00042 typedef void (*exact_3_func_type) ( const INTEGER& maxmx, const INTEGER& maxmy, const INTEGER& maxmz,
00043 const INTEGER& meqn, const INTEGER& mbc,
00044 const INTEGER& mx, const INTEGER& my, const INTEGER& mz,
00045 const DOUBLE x[], const DOUBLE y[], const DOUBLE z[],
00046 const DOUBLE& dx, const DOUBLE& dy, const DOUBLE& dz,
00047 const DOUBLE& t, VectorType q[]);
00048
00049 F77ExactBase() : f_exact(0), _Equations(VectorType::Length()) {}
00050 F77ExactBase(generic_func_type exact) : f_exact(exact), _Equations(VectorType::Length()) {}
00051
00052 void SetGrid(GridHierarchy& GH, const int& NGhosts, vec_grid_data_type& gd,
00053 grid_data_type& gdw, const int& level, double t) {
00054 assert(f_exact != (generic_func_type) 0);
00055 Coords ex = gd.extents();
00056 DCoords lbcorner = GH.worldCoords(gd.lower(), gd.stepsize());
00057 DCoords dx = GH.worldStep(gd.stepsize());
00058 int maxm[3], mx[3], d;
00059 DataType* x[3];
00060 for (d=0; d<dim; d++) {
00061 maxm[d] = ex(d);
00062 mx[d] = ex(d)-2*NGhosts;
00063 x[d] = new DataType[maxm[d]];
00064 for (int i=0; i<maxm[d]; i++) x[d][i] = (i+0.5)*dx(d)+lbcorner(d);
00065 }
00066
00067 if (dim == 1)
00068 ((exact_1_func_type) f_exact)(AA(1,mx),_Equations, NGhosts,
00069 AA(1,mx), AA(1,x), AA(1,dx), t, gd.data());
00070 else if (dim == 2)
00071 ((exact_2_func_type) f_exact)(AA(2,mx),_Equations, NGhosts,
00072 AA(2,mx), AA(2,x), AA(2,dx), t, gd.data());
00073 else if (dim == 3)
00074 ((exact_3_func_type) f_exact)(AA(3,mx),_Equations, NGhosts,
00075 AA(3,mx), AA(3,x), AA(3,dx), t, gd.data());
00076
00077 for (d=0; d<dim; d++)
00078 delete [] x[d];
00079 }
00080
00081 inline void SetFunc(generic_func_type exact) { f_exact = exact; }
00082 generic_func_type GetFunc() const { return f_exact; }
00083
00084 protected:
00085 generic_func_type f_exact;
00086 int _Equations;
00087 };
00088
00095 template <class VectorType, int dim>
00096 class F77ExactSolution : public F77ExactBase<VectorType,dim>,
00097 public ExactSolution<VectorType,dim> {
00098 typedef typename VectorType::InternalDataType DataType;
00099 typedef ExactSolution<VectorType,dim> base;
00100 typedef F77ExactBase<VectorType,dim> exact_base;
00101
00102 public:
00103 typedef typename base::vec_grid_data_type vec_grid_data_type;
00104 typedef typename base::grid_data_type grid_data_type;
00105 typedef typename exact_base::generic_func_type generic_func_type;
00106
00107 F77ExactSolution() : exact_base(), base() {}
00108 F77ExactSolution(generic_func_type exact) : exact_base(exact), base() {}
00109
00110 virtual ~F77ExactSolution() {}
00111
00112 virtual void SetGrid(vec_grid_data_type& gd, grid_data_type& gdw,
00113 const int& level, const double& t) {
00114 exact_base::SetGrid(base::GH(),base::NGhosts(),gd,gdw,level,t);
00115 }
00116 };
00117
00118
00119 #endif