00001
00002
00003
00004
00005
00006 #ifndef AMROC_F77_LEVELSETINITIALCONDITION_H
00007 #define AMROC_F77_LEVELSETINITIALCONDITION_H
00008
00016 #include "InitialCondition.h"
00017 #include "GFMLevelSet.h"
00018
00027 template <class VectorType, int dim>
00028 class F77LevelSetInitialCondition : public InitialCondition<VectorType,dim> {
00029 typedef typename VectorType::InternalDataType DataType;
00030 typedef InitialCondition<VectorType,dim> base;
00031
00032 public:
00033 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00034 typedef typename base::vec_grid_data_type vec_grid_data_type;
00035 typedef typename base::grid_fct_type grid_fct_type;
00036 typedef typename base::grid_data_type grid_data_type;
00037 typedef GFMLevelSet<DataType,dim> levelset_type;
00038
00039 typedef generic_fortran_func generic_func_type;
00040
00041 typedef void (*init_1_func_type) ( const INTEGER& maxmx,
00042 const INTEGER& meqn, const INTEGER& mbc,
00043 const INTEGER& mx,
00044 const DOUBLE x[],
00045 const DOUBLE& dx,
00046 VectorType q[], DataType phi[]);
00047 typedef void (*init_2_func_type) ( const INTEGER& maxmx, const INTEGER& maxmy,
00048 const INTEGER& meqn, const INTEGER& mbc,
00049 const INTEGER& mx, const INTEGER& my,
00050 const DOUBLE x[], const DOUBLE y[],
00051 const DOUBLE& dx, const DOUBLE& dy,
00052 VectorType q[], DataType phi[]);
00053 typedef void (*init_3_func_type) ( const INTEGER& maxmx, const INTEGER& maxmy, const INTEGER& maxmz,
00054 const INTEGER& meqn, const INTEGER& mbc,
00055 const INTEGER& mx, const INTEGER& my, const INTEGER& mz,
00056 const DOUBLE x[], const DOUBLE y[], const DOUBLE z[],
00057 const DOUBLE& dx, const DOUBLE& dy, const DOUBLE& dz,
00058 VectorType q[], DataType phi[]);
00059
00060 F77LevelSetInitialCondition() : base(), _LevelSet(0), f_init(0) {}
00061 F77LevelSetInitialCondition(generic_func_type init) : base(),
00062 _LevelSet(0), f_init(init) {}
00063
00064 virtual ~F77LevelSetInitialCondition() {
00065 if (_LevelSet) delete _LevelSet;
00066 }
00067
00068 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00069 base::LocCtrl = Ctrl.getSubDevice(prefix+"InitialCondition");
00070 if (_LevelSet) LevelSet().register_at(base::LocCtrl,"");
00071 }
00072 virtual void register_at(ControlDevice& Ctrl) {
00073 register_at(Ctrl, "");
00074 }
00075
00076 virtual void SetupData(GridHierarchy* gh, const int& ghosts) {
00077 base::SetupData(gh,ghosts);
00078 if (_LevelSet) LevelSet().SetupData(gh,ghosts);
00079 }
00080
00081 virtual void SetGrid(vec_grid_data_type& gd, grid_data_type& gdw, const int& level) {
00082 assert(f_init != (generic_func_type) 0);
00083 Coords ex = gd.extents();
00084 DCoords lbcorner = base::GH().worldCoords(gd.lower(), gd.stepsize());
00085 DCoords dx = base::GH().worldStep(gd.stepsize());
00086 int maxm[3], mx[3], d;
00087 DataType* x[3];
00088 for (d=0; d<dim; d++) {
00089 maxm[d] = ex(d);
00090 mx[d] = ex(d)-2*base::NGhosts();
00091 x[d] = new DataType[maxm[d]];
00092 for (int i=0; i<maxm[d]; i++) x[d][i] = (i+0.5)*dx(d)+lbcorner(d);
00093 }
00094
00095 if (dim == 1)
00096 ((init_1_func_type) f_init)(AA(1,mx),base::NEquations(), base::NGhosts(),
00097 AA(1,mx), AA(1,x), AA(1,dx), gd.data(), gdw.data());
00098 else if (dim == 2)
00099 ((init_2_func_type) f_init)(AA(2,mx),base::NEquations(), base::NGhosts(),
00100 AA(2,mx), AA(2,x), AA(2,dx), gd.data(), gdw.data());
00101 else if (dim == 3)
00102 ((init_3_func_type) f_init)(AA(3,mx),base::NEquations(), base::NGhosts(),
00103 AA(3,mx), AA(3,x), AA(3,dx), gd.data(), gdw.data());
00104
00105 for (d=0; d<dim; d++)
00106 delete [] x[d];
00107 }
00108
00109 virtual void Set(vec_grid_fct_type& u, grid_fct_type& work, const int Level) {
00110 if (_LevelSet) LevelSet().SetPhi(work,0,Level,0.0);
00111 base::Set(u,work,Level);
00112 }
00113
00114 inline void SetLevelSet(levelset_type* _levelset) { _LevelSet = _levelset; }
00115 inline levelset_type& LevelSet() { assert (_LevelSet!=0); return *_LevelSet; }
00116 inline const levelset_type& LevelSet() const { assert (_LevelSet!=0); return *_LevelSet; }
00117
00118 inline void SetFunc(generic_func_type init) { f_init = init; }
00119 generic_func_type GetFunc() const { return f_init; }
00120
00121 protected:
00122 levelset_type* _LevelSet;
00123 generic_func_type f_init;
00124 };
00125
00126
00127 #endif