AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

AMRPreAdaptSolver.h

Go to the documentation of this file.
00001 #ifndef AMROC_AMRPREADAPT_SOLVER_H
00002 #define AMROC_AMRPREADAPT_SOLVER_H
00003 
00011 #include "AMRSolver.h"
00012 
00013 #ifndef AMRPreAdaptSolverName
00014 #define AMRPreAdaptSolver(dim)      name2(AMRPreAdaptSolver,dim)
00015 #define AMRPreAdaptSolverName
00016 #endif
00017 
00018 
00019 #define MAXLEVELS 5
00020 
00021 class Patch : public controlable {
00022 public:
00023   Patch() {
00024     lb.rank = DIM;
00025     ub.rank = DIM;
00026     s.rank = DIM;
00027   }
00028 
00029   virtual void register_at(ControlDevice& Ctrl) {}
00030   virtual void register_at(ControlDevice& Ctrl, const string& prefix) {
00031     LocCtrl = Ctrl.getSubDevice(prefix+"Patch");
00032     for (int d=0; d<DIM; d++) {
00033       char text[8];
00034       sprintf(text,"lb(%d)",d+1);
00035       RegisterAt(LocCtrl,text,lb(d));
00036       sprintf(text,"ub(%d)",d+1);
00037       RegisterAt(LocCtrl,text,ub(d));
00038       sprintf(text,"s(%d)",d+1);
00039       RegisterAt(LocCtrl,text,s(d));
00040     }
00041   }
00042 
00043 public:
00044   Coords lb, ub, s;
00045   ControlDevice LocCtrl;
00046 };
00047 
00048 
00056 template <class VectorType, class FixupType, class FlagType>
00057 class AMRPreAdaptSolver(DIM) : 
00058   public AMRSolver(DIM)<VectorType,FixupType,FlagType> {
00059 
00060   typedef AMRSolver(DIM)<VectorType,FixupType,FlagType> amr_solver_type;
00061 
00062   typedef Integrator(DIM)<VectorType> integrator_type;
00063   typedef InitialCondition(DIM)<VectorType> initial_condition_type;
00064   typedef BoundaryConditions(DIM)<VectorType> boundary_conditions_type;
00065 
00066 public:
00067   AMRPreAdaptSolver(DIM)(integrator_type& integ, 
00068                      initial_condition_type& init,
00069                      boundary_conditions_type& bc) : 
00070     amr_solver_type(integ, init, bc), SwitchTime(0) {
00071     for (int c=0; c<MAXLEVELS; c++) {
00072       li[c] = 0;
00073       ls[c] = 0;
00074       PatchListInit[c] = (Patch*) 0;
00075       PatchListSwitch[c] = (Patch*) 0;
00076     }
00077   }
00078 
00079   ~AMRPreAdaptSolver(DIM)() {
00080     for (int c=0; c<MAXLEVELS; c++) {
00081       if (PatchListInit[c])
00082         delete [] PatchListInit[c];
00083       if (PatchListSwitch[c])
00084         delete [] PatchListSwitch[c];
00085     }
00086   }
00087 
00088   virtual void register_at(ControlDevice& Ctrl, const string& prefix) {
00089     amr_solver_type::register_at(Ctrl,prefix);
00090     ControlDevice LocCtrlInit = LocCtrl.getSubDevice(prefix+"InitialRefinement");
00091     int c;
00092     for (c=0; c<MAXLEVELS; c++) {
00093       char LevelControlsName[24];
00094       sprintf(LevelControlsName,"PatchesOnLevel%d",c+1);
00095       RegisterAt(LocCtrlInit,LevelControlsName,li[c]);
00096     }
00097     
00098     RegisterAt(LocCtrl,"SwitchTime",SwitchTime);
00099     ControlDevice LocCtrlSwitch = LocCtrl.getSubDevice(prefix+"SwitchRefinement");
00100     for (c=0; c<MAXLEVELS; c++) {
00101       char LevelControlsName[24];
00102       sprintf(LevelControlsName,"PatchesOnLevel%d",c+1);
00103       RegisterAt(LocCtrlSwitch,LevelControlsName,ls[c]);
00104     }    
00105   }
00106   virtual void register_at(ControlDevice& Ctrl) {
00107     register_at(Ctrl, "");
00108   }
00109 
00110   virtual void SetupData() {
00111     amr_solver_type::SetupData();
00112 
00113     ControlDevice PatchCtrlInit(GetFileControlDevice("patches_init.in",""));   
00114     int m;
00115     for (m=0; m<MAXLEVELS; m++) {
00116       PatchListInit[m] = new Patch[li[m]];
00117       for (int i=0; i<li[m]; i++) {
00118         char text[5];
00119         sprintf(text,"%d-%d-",m+1,i+1);
00120         (PatchListInit[m])[i].register_at(PatchCtrlInit,string(text));
00121       }
00122     }
00123     PatchCtrlInit.update();  
00124 
00125     ControlDevice PatchCtrlSwitch(GetFileControlDevice("patches_switch.in",""));   
00126     for (m=0; m<MAXLEVELS; m++) {
00127       PatchListSwitch[m] = new Patch[ls[m]];
00128       for (int i=0; i<ls[m]; i++) {
00129         char text[5];
00130         sprintf(text,"%d-%d-",m+1,i+1);
00131         (PatchListSwitch[m])[i].register_at(PatchCtrlSwitch,string(text));
00132       }
00133     }
00134     PatchCtrlSwitch.update();  
00135    }
00136 
00137   virtual void Initialize(const double dt_start) {
00138     BBoxList bblist[MAXLEVELS]; 
00139     int m;
00140     for (m=0; m<MAXLEVELS; m++)   
00141       for (int i=0; i<li[m]; i++) {
00142         cout << ((PatchListInit[m])[i].lb)*RefinedBy(GH(),MaxLevel(GH())) << "   " <<
00143           ((PatchListInit[m])[i].ub)*RefinedBy(GH(),MaxLevel(GH())) << "   " << 
00144           ((PatchListInit[m])[i].s)*StepSize(GH(),m) << endl;
00145 
00146         bblist[m].add(BBox(((PatchListInit[m])[i].lb)*RefinedBy(GH(),MaxLevel(GH())),
00147                            ((PatchListInit[m])[i].ub)*RefinedBy(GH(),MaxLevel(GH())),
00148                            ((PatchListInit[m])[i].s)*StepSize(GH(),m)));
00149       }   
00150  
00151     for (m=0; m<MaxLevel(GH());m++)  
00152       if (li[m] > 0) {
00153         Refine(GH(),bblist[m],m);        
00154         RecomposeHierarchy(GH());  
00155       }
00156 
00157     int Store = RegridEvery;
00158     RegridEvery = 0;
00159     amr_solver_type::Initialize(dt_start);
00160     RegridEvery = Store;
00161   }
00162 
00163   virtual double Tick(int VariableTimeStepping, const double dtv[], const double cflv[],
00164                       int& Rejections, int& RecomposeEvery) {
00165     if (SwitchTime>0 && 
00166         SwitchTime*RefinedBy(GH(),MaxLevel(GH())) == CurrentTime(GH(),0)) {
00167       BBoxList bblist[MAXLEVELS]; 
00168       int m;
00169       for (m=0; m<MAXLEVELS; m++)   
00170         for (int i=0; i<ls[m]; i++) {
00171           bblist[m].add(BBox(((PatchListSwitch[m])[i].lb)*RefinedBy(GH(),MaxLevel(GH())),
00172                              ((PatchListSwitch[m])[i].ub)*RefinedBy(GH(),MaxLevel(GH())),
00173                              ((PatchListSwitch[m])[i].s)*StepSize(GH(),m)));
00174         }
00175 
00176       for (m=0; m<MaxLevel(GH());m++)  
00177         if (ls[m] > 0) {
00178           Refine(GH(),bblist[m],m);    
00179           RecomposeHierarchy(GH());  
00180         }
00181     }
00182 
00183     return (amr_solver_type::Tick(VariableTimeStepping, dtv, cflv, Rejections, 
00184                                   RecomposeEvery));
00185   }
00186 
00187 protected:
00188   int SwitchTime;
00189   int li[MAXLEVELS];
00190   int ls[MAXLEVELS];
00191   Patch* PatchListInit[MAXLEVELS];
00192   Patch* PatchListSwitch[MAXLEVELS];
00193 };
00194 
00195 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04