00001
00002
00003
00004
00005
00006 #ifndef AMROC_F77_INITIALCONDITION_H
00007 #define AMROC_F77_INITIALCONDITION_H
00008
00016 #include "InitialCondition.h"
00017
00026 template <class VectorType, int dim>
00027 class F77InitialCondition : public InitialCondition<VectorType,dim> {
00028 typedef typename VectorType::InternalDataType DataType;
00029 typedef InitialCondition<VectorType,dim> base;
00030
00031 public:
00032 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00033 typedef typename base::vec_grid_data_type vec_grid_data_type;
00034 typedef typename base::grid_fct_type grid_fct_type;
00035 typedef typename base::grid_data_type grid_data_type;
00036
00037 typedef generic_fortran_func generic_func_type;
00038
00039 typedef void (*init_1_func_type) ( const INTEGER& maxmx,
00040 const INTEGER& meqn, const INTEGER& mbc,
00041 const INTEGER& mx,
00042 const DOUBLE x[],
00043 const DOUBLE& dx,
00044 VectorType q[]);
00045 typedef void (*init_2_func_type) ( const INTEGER& maxmx, const INTEGER& maxmy,
00046 const INTEGER& meqn, const INTEGER& mbc,
00047 const INTEGER& mx, const INTEGER& my,
00048 const DOUBLE x[], const DOUBLE y[],
00049 const DOUBLE& dx, const DOUBLE& dy,
00050 VectorType q[]);
00051 typedef void (*init_3_func_type) ( const INTEGER& maxmx, const INTEGER& maxmy, const INTEGER& maxmz,
00052 const INTEGER& meqn, const INTEGER& mbc,
00053 const INTEGER& mx, const INTEGER& my, const INTEGER& mz,
00054 const DOUBLE x[], const DOUBLE y[], const DOUBLE z[],
00055 const DOUBLE& dx, const DOUBLE& dy, const DOUBLE& dz,
00056 VectorType q[]);
00057
00058 F77InitialCondition() : base(), f_init(0) {}
00059 F77InitialCondition(generic_func_type init) : base(), f_init(init) {}
00060
00061 virtual ~F77InitialCondition() {}
00062
00063 virtual void SetGrid(vec_grid_data_type& gd, grid_data_type& gdw, const int& level) {
00064 assert(f_init != (generic_func_type) 0);
00065 Coords ex = gd.extents();
00066 DCoords lbcorner = base::GH().worldCoords(gd.lower(), gd.stepsize());
00067 DCoords dx = base::GH().worldStep(gd.stepsize());
00068 int maxm[3], mx[3], d;
00069 DataType* x[3];
00070 for (d=0; d<dim; d++) {
00071 maxm[d] = ex(d);
00072 mx[d] = ex(d)-2*base::NGhosts();
00073 x[d] = new DataType[maxm[d]];
00074 for (int i=0; i<maxm[d]; i++) x[d][i] = (i+0.5)*dx(d)+lbcorner(d);
00075 }
00076
00077 if (dim == 1)
00078 ((init_1_func_type) f_init)(AA(1,mx),base::NEquations(), base::NGhosts(),
00079 AA(1,mx), AA(1,x), AA(1,dx), gd.data());
00080 else if (dim == 2)
00081 ((init_2_func_type) f_init)(AA(2,mx),base::NEquations(), base::NGhosts(),
00082 AA(2,mx), AA(2,x), AA(2,dx), gd.data());
00083 else if (dim == 3)
00084 ((init_3_func_type) f_init)(AA(3,mx),base::NEquations(), base::NGhosts(),
00085 AA(3,mx), AA(3,x), AA(3,dx), gd.data());
00086
00087 for (d=0; d<dim; d++)
00088 delete [] x[d];
00089 }
00090
00091 inline void SetFunc(generic_func_type init) { f_init = init; }
00092 generic_func_type GetFunc() const { return f_init; }
00093
00094 protected:
00095 generic_func_type f_init;
00096 };
00097
00098
00099 #endif