AMRCore.h

00001 #ifndef gridripper_amr1d_AMRCore_h
00002 #define gridripper_amr1d_AMRCore_h
00003 
00004 #include <gridripper/lang/IllegalArgumentException.h>
00005 #include <gridripper/amr1d/io/GridBDataWriter.h>
00006 #include <gridripper/math/expr/Evaluator.h>
00007 #include "Grid.h"
00008 #include "InitCond.h"
00009 
00010 namespace gridripper { namespace amr1d {
00011 
00012 class PDE;
00013 class AMError;
00014 class Integrator;
00015 
00016 using namespace gridripper::math::expr;
00017 using namespace gridripper::amr1d::io;
00018 
00025 class AMRCore
00026 {
00027 private:
00028     bool debugMode;
00029     PDE* thePDE;
00030     AMError* amError;
00031     Integrator* integratorProto;
00032     Regridder* regridderProto;
00033     int refinementRatio;
00034     tvalarray< tvector<Grid*> > grids;
00035     Evaluator::Function* dtdxFunc;
00036     GReal_t deltaT0;
00037     GReal_t currentDeltaT0;
00038     bool currentDeltaT0Computed;
00039 //    int lastRefinedTimeStep; // last time when adaptive time step
00040                              // was smaller than the default time step
00041     int finestLevel;
00042     int maxAllowedLevel;
00043     double errorTolerance;
00044     int errorCheckFreq;
00045     int regridFreq;
00046     int bufferZoneSize;
00047     int currentLevel;
00048     bool onInitialHypersurface;
00049     bool physicalFieldUsed;
00050     bool running;
00051     bool forceConstraints;
00052     bool energyWritten;
00053 
00054 protected:
00059     AMRCore(const AMRCore& ai);
00060 
00061 public:
00080     AMRCore(PDE* pde, InitCond& ini, bool constrforced,
00081             Integrator* gi, Regridder* rgdproto,
00082             const string& dtdx, int maxi, int npabovemax,
00083             int maxl, int r,
00084             AMError* amerr, double maxerr,
00085             int errchkf, int regridf, int bufzoner)
00086                 throw(InitCond::Exception&, IllegalArgumentException&);
00087 
00088     virtual ~AMRCore();
00089 
00094     virtual AMRCore* cloneAMRCore() const =0;
00095 
00096     bool isRunning() const {
00097         return running;
00098     }
00099 
00101     void setRunning(bool r) {
00102         running = r;
00103     }
00104 
00108     virtual void output() =0;
00109 
00110     int getRefinementRatio() const {
00111         return refinementRatio;
00112     }
00113 
00114     int getMaxAllowedLevel() const {
00115         return maxAllowedLevel;
00116     }
00117 
00118     bool getDebug() const {
00119         return debugMode;
00120     }
00121 
00122     void setDebug(bool v) {
00123         debugMode = v;
00124     }
00125 
00126     bool isPhysicalFieldUsed() const {
00127         return physicalFieldUsed;
00128     }
00129 
00130     void setPhysicalFieldUsed(bool v) {
00131         physicalFieldUsed = v;
00132     }
00133 
00135     PDE& getPDE() const {
00136         return *thePDE;
00137     }
00138 
00139     double getErrorTolerance() const {
00140         return errorTolerance;
00141     }
00142 
00143     double getErrorToleranceDt(int l) const;
00144 
00145     int getErrorCheckFreq() const {
00146         return errorCheckFreq;
00147     }
00148 
00149     int getRegridFreq() const {
00150         return regridFreq;
00151     }
00152 
00153     int getBufferZoneSize() const {
00154         return bufferZoneSize;
00155     }
00156 
00161     int getCurrentLevel() const {
00162         return currentLevel;
00163     }
00164 
00165 protected:
00170     void setCurrentLevel(int l) {
00171         currentLevel = l;
00172     }
00173 
00179     virtual bool isLastTime(const Grid& g) const =0;
00180 
00181 public:
00186     Grid& getBaseGrid() const {
00187         return *grids[0][0];
00188     }
00189 
00194     GReal_t getDeltaT0() const {
00195         return deltaT0;
00196     }
00197 
00202     GReal_t getDeltaT() const {
00203         return currentDeltaT0;
00204     }
00205 
00211     bool isCurrentDeltaT0Computed() const {
00212         return currentDeltaT0Computed;
00213     }
00214 
00222     GReal_t getDeltaT(GReal_t dt, int l) const;
00223 
00224     bool isConstraintForced() const {
00225         return forceConstraints;
00226     }
00227 
00228     void setConstraintForced(bool v) {
00229         forceConstraints = v;
00230     }
00231 
00232     bool isEnergyWritten() const {
00233         return energyWritten;
00234     }
00235 
00236     void setEnergyWritten(bool v) {
00237         energyWritten = v;
00238     }
00239 
00240     GridBDataWriter* createBDataWriter() const;
00241 
00250     void integrate();
00251 
00252 protected:
00258     virtual void coarseStepped(GReal_t t);
00259 
00260 private:
00268     void evolve_hierarchy(int level, GReal_t dt, GReal_t dt_next,
00269                           int ir, int absrefinement);
00270 
00278     void evaluateEqs(Grid& g, GReal_t dt, int ir);
00279 
00285     void regrid(int level, GReal_t dt);
00286 
00293     void regrid(int level, GReal_t dt, int minLevel);
00294 
00300     GReal_t computeAdaptiveDeltaT() const;
00301 
00307     GReal_t computeExplicitDeltaT() const;
00308 };
00309 
00310 } } // namespace gridripper::amr1d
00311 
00312 #endif /* gridripper_amr1d_AMRCore_h */

Generated on Wed Jun 17 18:46:47 2009 for GridRipper by  doxygen 1.5.6