00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef AMROC_SOLVERBASE_H
00010 #define AMROC_SOLVERBASE_H
00011
00019 #include "DAGH.h"
00020 #include "DAGHIO.h"
00021 #include "DAGHCluster.h"
00022
00023 #include "Solver.h"
00024 #include "Timing.h"
00025 #include "Integrator.h"
00026 #include "InitialCondition.h"
00027 #include "BoundaryConditions.h"
00028 #include "LevelTransfer.h"
00029 #include "AMRFlagging.h"
00030 #include "AMRFixup.h"
00031 #include "ExactSolution.h"
00032 #include "FileOutput.h"
00033 #include "VectorGridDataOps.h"
00034
00035 #include <iostream>
00036 #include <string>
00037 #include <cstdio>
00038 #include <cstdlib>
00039 #include <cfloat>
00040 #include <stdio.h>
00041
00042 #define FixedTimeSteps (0)
00043 #define AutomaticTimeStepsNoRestart (1)
00044 #define AutomaticTimeStepsRestart (2)
00045 #define MaxCutOffRegions (10)
00046 #define MaxAMRTimeSteps (10)
00047 #define FACTOR 1.0e5
00048
00049 class AMRTimeStep : public controlable {
00050 public:
00051 AMRTimeStep() : LastTime(1.e37), VariableTimeStepping(2) {
00052 dtv[0] = 0.01;
00053 dtv[1] = 0.02;
00054 cflv[0] = 0.9;
00055 cflv[1] = 0.8;
00056 }
00057
00058 virtual ~AMRTimeStep() {}
00059
00060 virtual void register_at(ControlDevice& Ctrl) {}
00061 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00062 LocCtrl = Ctrl.getSubDevice(prefix+"TimeControl");
00063 RegisterAt(LocCtrl,"LastTime",LastTime);
00064 RegisterAt(LocCtrl,"StepMode",VariableTimeStepping);
00065 RegisterAt(LocCtrl,"TimeStep",dtv[0]);
00066 RegisterAt(LocCtrl,"TimeStepMax",dtv[1]);
00067 RegisterAt(LocCtrl,"CFLRestart",cflv[0]);
00068 RegisterAt(LocCtrl,"CFLControl",cflv[1]);
00069 }
00070
00071 public:
00072 double LastTime;
00073 int VariableTimeStepping;
00074 double dtv[2], cflv[2];
00075 ControlDevice LocCtrl;
00076 };
00077
00078
00088 template <class VectorType, class FixupType, class FlagType, int dim>
00089 class AMRSolverBase : public Solver {
00090 typedef AMRBase<VectorType,dim> base;
00091 typedef typename VectorType::InternalDataType DataType;
00092 public:
00093 typedef GridFunction<VectorType,dim> vec_grid_fct_type;
00094 typedef GridData<VectorType,dim> vec_grid_data_type;
00095 typedef GridFunction<DataType,dim> grid_fct_type;
00096 typedef GridData<DataType,dim> grid_data_type;
00097
00098 typedef Integrator<VectorType,dim> integrator_type;
00099 typedef InitialCondition<VectorType,dim> initial_condition_type;
00100 typedef BoundaryConditions<VectorType,dim> boundary_conditions_type;
00101 typedef LevelTransfer<VectorType,dim> leveltransfer_type;
00102 typedef AMRFlagging<VectorType,FixupType,FlagType,dim> flagging_type;
00103 typedef AMRFixup<VectorType,FixupType,dim> fixup_type;
00104 typedef ExactSolution<VectorType,dim> exact_solution_type;
00105 typedef FileOutput<VectorType,dim> file_output_type;
00106
00107 typedef GFBndryUpdateSpecificFunc<boundary_conditions_type,VectorType,dim> boundary_functor_type;
00108 typedef GFLevelTransferSpecificFunc<leveltransfer_type,VectorType,dim> leveltransfer_functor_type;
00109 typedef GFAdptBndryUpdateSpecificFunc<leveltransfer_type,VectorType,dim> adaptbnd_functor_type;
00110
00111 AMRSolverBase(integrator_type& integ, initial_condition_type& init, boundary_conditions_type& bc) :
00112 _Integrator(integ), _InitialCondition(init), _BoundaryConditions(bc),
00113 _Equations(VectorType::Length()), _Ghosts(2), _Dim(dim), RedistributeEvery(0),
00114 Distribution(DAGHCompositeDistribution), MaxLev(1), GuCFactor(2), MaxGridBoxSize(0), CutOffs(0),
00115 NAMRTimeSteps(1), firstnode(0), lastnode(-1), UseIOServer(0) {
00116 for (register int d=0; d<dim; d++) {
00117 shape[d] = 2;
00118 geom[2*d] = 0.0;
00119 geom[2*d+1] = 1.0;
00120 periodic[d] = DAGHFalse;
00121 }
00122 for (register int i=0; i<DAGHMaxLevels; i++)
00123 _RefineFactor[i] = DAGHDefaultRefineFactor;
00124
00125 _Hierarchy = (GridHierarchy*) 0;
00126 _u = (vec_grid_fct_type *) 0;
00127 _u_sh = (vec_grid_fct_type *) 0;
00128 _work = (grid_fct_type *) 0;
00129 _work_sh = (grid_fct_type *) 0;
00130 _LevelTransfer = (leveltransfer_type *) 0;
00131 _Flagging = (flagging_type *) 0;
00132 _Fixup = (fixup_type *) 0;
00133 _ExactSolution = (exact_solution_type *) 0;
00134 _FileOutput = (file_output_type *) 0;
00135 _BoundaryFunc = (boundary_functor_type *) 0;
00136 _ProlongFunc = (leveltransfer_functor_type *) 0;
00137 _RestrictFunc = (leveltransfer_functor_type *) 0;
00138 _AdaptBndFunc = (adaptbnd_functor_type *) 0;
00139 _LastOutputTime = -1;
00140 CheckpointName = "checkpt";
00141 CheckpointSave = 1;
00142 FinalWaitingTime = 10.;
00143 }
00144
00145 virtual ~AMRSolverBase() {
00146 if (_u) delete _u;
00147 if (_u_sh) delete _u_sh;
00148 if (_work) delete _work;
00149 if (_work_sh) delete _work_sh;
00150 if (_BoundaryFunc) delete _BoundaryFunc;
00151 if (_ProlongFunc) delete _ProlongFunc;
00152 if (_RestrictFunc) delete _RestrictFunc;
00153 if (_AdaptBndFunc) delete _AdaptBndFunc;
00154 if (_Hierarchy) delete _Hierarchy;
00155 }
00156
00157
00158
00159
00160 virtual double Tick(int VariableTimeStepping, const double dtv[], const double cflv[],
00161 int& Rejections) = 0;
00162 virtual double IntegrateLevel(vec_grid_fct_type& u, const int Time, const int Level,
00163 double t, double dt, bool DoFixup, double tc,
00164 const int which) = 0;
00165 virtual void Initialize_(const double& dt_start) = 0;
00166 virtual bool Restart_(const char* CheckpointFile) = 0;
00167 virtual void Checkpointing_(const char* CheckpointFile) = 0;
00168
00169
00170 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00171 PCtrl = Ctrl.getSubDevice("LocalGroup");
00172 RegisterAt(PCtrl,"FirstNode",firstnode);
00173 RegisterAt(PCtrl,"LastNode",lastnode);
00174 RegisterAt(PCtrl,"UseIOServer",UseIOServer);
00175
00176 GHCtrl = Ctrl.getSubDevice("GridHierarchy");
00177 char VariableName[32];
00178 for (int d=0; d<dim; d++) {
00179 std::sprintf(VariableName,"Cells(%d)",d+1);
00180 RegisterAt(GHCtrl,VariableName,shape[d]);
00181 std::sprintf(VariableName,"GeomMin(%d)",d+1);
00182 RegisterAt(GHCtrl,VariableName,geom[2*d]);
00183 std::sprintf(VariableName,"GeomMax(%d)",d+1);
00184 RegisterAt(GHCtrl,VariableName,geom[2*d+1]);
00185 std::sprintf(VariableName,"PeriodicBoundary(%d)",d+1);
00186 RegisterAt(GHCtrl,VariableName,periodic[d]);
00187 }
00188 for (int nc=0; nc<MaxCutOffRegions; nc++) {
00189 for (int d=0; d<dim; d++)
00190 for (int j=0; j<2; j++) {
00191 std::sprintf(VariableName,"CCells(%d,%d,%d)",nc+1,j+1,d+1);
00192 RegisterAt(GHCtrl,VariableName,cuts[nc*2*dim+2*d+j]);
00193 cuts[nc*2*dim+2*d+j] = -100000;
00194 }
00195 }
00196 RegisterAt(GHCtrl,"CutOffs",CutOffs);
00197 for (register int i=0; i<DAGHMaxLevels; i++) {
00198 std::sprintf(VariableName,"RefineFactor(%d)",i+1);
00199 RegisterAt(GHCtrl,VariableName,_RefineFactor[i]);
00200 }
00201 RegisterAt(GHCtrl,"RedistributeEvery",RedistributeEvery);
00202 RegisterAt(GHCtrl,"MaxLevels",MaxLev);
00203 RegisterAt(GHCtrl,"Distribution",Distribution);
00204 RegisterAt(GHCtrl,"GuCFactor",GuCFactor);
00205 RegisterAt(GHCtrl,"MaxGridBoxSize",MaxGridBoxSize);
00206 RegisterAt(GHCtrl,"GhostCells",_Ghosts);
00207 RegisterAt(GHCtrl,"CheckpointName",CheckpointName);
00208 RegisterAt(GHCtrl,"CheckpointSave",CheckpointSave);
00209 RegisterAt(GHCtrl,"FinalWaitingTime",FinalWaitingTime);
00210
00211 Step[0].register_at(Ctrl,"");
00212 for (int cs=0; cs<MaxAMRTimeSteps; cs++) {
00213 char text[5];
00214 std::sprintf(text,"%d-",cs+1);
00215 Step[cs].register_at(Ctrl,std::string(text));
00216 }
00217 RegisterAt(Ctrl,"TimeControls",NAMRTimeSteps);
00218
00219 _Integrator.register_at(Ctrl, "");
00220 _InitialCondition.register_at(Ctrl, "");
00221 _BoundaryConditions.register_at(Ctrl, "");
00222 if (_LevelTransfer) _LevelTransfer->register_at(Ctrl, "");
00223 if (_Flagging) _Flagging->register_at(Ctrl, "");
00224 if (_Fixup) _Fixup->register_at(Ctrl, "");
00225 if (_ExactSolution) _ExactSolution->register_at(Ctrl, "");
00226 if (_FileOutput) _FileOutput->register_at(Ctrl, "");
00227 }
00228 virtual void register_at(ControlDevice& Ctrl) { register_at(Ctrl, ""); }
00229
00230 virtual void init() {
00231 _Integrator.init();
00232 _InitialCondition.init();
00233 _BoundaryConditions.init();
00234 if (_LevelTransfer) _LevelTransfer->init();
00235 if (_Flagging) _Flagging->init();
00236 if (_Fixup) _Fixup->init();
00237 if (_ExactSolution) _ExactSolution->init();
00238 if (_FileOutput) _FileOutput->init();
00239 }
00240 virtual void update() {
00241 _Integrator.update();
00242 _InitialCondition.update();
00243 _BoundaryConditions.update();
00244 if (_LevelTransfer) _LevelTransfer->update();
00245 if (_Flagging) _Flagging->update();
00246 if (_Fixup) _Fixup->update();
00247 if (_ExactSolution) _ExactSolution->update();
00248 if (_FileOutput) _FileOutput->update();
00249 START_WATCH_WHOLE
00250 }
00251 virtual void finish() {
00252 END_WATCH_WHOLE
00253 #ifdef TIMING_AMR
00254 if (_Hierarchy) {
00255 Timing::collect(Comm());
00256 #ifdef DEBUG_PRINT
00257 Timing::print_local(comm_service::log());
00258 #endif
00259 if (MY_PROC == VizServer)
00260 Timing::print(std::cout);
00261 }
00262 #endif
00263 _Integrator.finish();
00264 _InitialCondition.finish();
00265 _BoundaryConditions.finish();
00266 if (_LevelTransfer) _LevelTransfer->finish();
00267 if (_Flagging) _Flagging->finish();
00268 if (_Fixup) _Fixup->finish();
00269 if (_ExactSolution) _ExactSolution->finish();
00270 if (_FileOutput) _FileOutput->finish();
00271 if (_u) {
00272 delete _u;
00273 _u = (vec_grid_fct_type *) 0;
00274 }
00275 if (_u_sh) {
00276 delete _u_sh;
00277 _u_sh = (vec_grid_fct_type *) 0;
00278 }
00279 if (_work) {
00280 delete _work;
00281 _work = (grid_fct_type *) 0;
00282 }
00283 if (_work_sh) {
00284 delete _work_sh;
00285 _work_sh = (grid_fct_type *) 0;
00286 }
00287 if (_BoundaryFunc) {
00288 delete _BoundaryFunc;
00289 _BoundaryFunc = (boundary_functor_type *) 0;
00290 }
00291 if (_ProlongFunc) {
00292 delete _ProlongFunc;
00293 _ProlongFunc = (leveltransfer_functor_type *) 0;
00294 }
00295 if (_RestrictFunc) {
00296 delete _RestrictFunc;
00297 _RestrictFunc = (leveltransfer_functor_type *) 0;
00298 }
00299 if (_AdaptBndFunc) {
00300 delete _AdaptBndFunc;
00301 _AdaptBndFunc = (adaptbnd_functor_type *) 0;
00302 }
00303 #ifndef DAGH_NO_MPI
00304 if (FinalWaitingTime>0. && (_Hierarchy!=(GridHierarchy *) 0)) {
00305 double start_finalize = MPI_Wtime();
00306 while (MPI_Wtime()-start_finalize < FinalWaitingTime) {}
00307 }
00308 #endif
00309
00310 if (_Hierarchy) delete _Hierarchy;
00311 _Hierarchy = (GridHierarchy *) 0;
00312
00313 #ifndef DAGH_NO_MPI
00314 comm_service::clean();
00315 #endif
00316 }
00317
00318 virtual bool setup() {
00319 bool ret = true;
00320
00321
00322
00323 if (UseIOServer) comm_service::set_io_enable();
00324 else comm_service::reset_io_enable();
00325
00326 #ifndef DAGH_NO_MPI
00327 int size, rank = 0;
00328 MPI_Comm_size(MPI_COMM_WORLD, &size);
00329 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00330
00331 if (firstnode<0) firstnode=0;
00332 if (lastnode>size-1 || lastnode<0) lastnode=size-1;
00333
00334 if (firstnode<=rank && rank<=lastnode) {
00335 MPI_Group GrpWorld, GrpLocal;
00336 MPI_Comm CommLocal;
00337 MPI_Comm_group(MPI_COMM_WORLD, &GrpWorld);
00338
00339 int* localranks = new int [lastnode-firstnode+1];
00340 int localcnt = 0;
00341 for (register int i=firstnode; i<=lastnode; i++)
00342 localranks[localcnt++] = i;
00343
00344 MPI_Group_incl(GrpWorld, localcnt, localranks, &GrpLocal);
00345 MPI_Comm_create(MPI_COMM_WORLD, GrpLocal, &CommLocal);
00346
00347 comm_service::init(CommLocal);
00348
00349 SetupData();
00350 ret = COMPUTE_NODE;
00351 }
00352 else
00353 ret = false;
00354 #else
00355 firstnode=0;
00356 lastnode=0;
00357 SetupData();
00358 ret = COMPUTE_NODE;
00359 #endif
00360 return ret;
00361 }
00362
00363 virtual void SetupGridHierarchy() {
00364 _Hierarchy = new GridHierarchy(dim,DAGHCellCentered,MaxLev);
00365 SetBaseGrid(GH(),geom,shape,CutOffs,cuts);
00366 for (register int l=0; l<MaxLev-1; l++) {
00367 if (_RefineFactor[l]<DAGHDefaultRefineFactor)
00368 _RefineFactor[l] = DAGHDefaultRefineFactor;
00369 if (ErrorEstimation() && _RefineFactor[l]%DAGHShadowFactor && l<MaxLev-2) {
00370 std::cout << " RefineFactor(" << l+1
00371 << ") is not dividable by Shadowfactor()."
00372 << " Can't use error estimation.\n" << std::flush;
00373 Flagging_().SetErrorEstimation(false);
00374 }
00375 SetRefineFactor(GH(),l,_RefineFactor[l]);
00376 }
00377
00378 SetBoundaryWidth(GH(),NGhosts());
00379 SetBoundaryType(GH(),DAGHBoundaryUserDef);
00380 if (ErrorEstimation())
00381 GuCFactor = Max(GuCFactor,DAGHShadowFactor);
00382 if (GuCFactor) SetGuCFactor(GH(),GuCFactor);
00383 if (MaxGridBoxSize) SetMaxGridBoxSize(GH(), MaxGridBoxSize);
00384 for (int d=0; d<dim; d++)
00385 if (periodic[d]) SetPeriodicBoundaries(GH(),d,DAGHTrue);
00386 SetDistributionType(GH(),Distribution);
00387
00388 if (_FileOutput) _FileOutput->SetupData(PGH(), NGhosts());
00389
00390 ComposeHierarchy(GH());
00391 _Integrator.SetupData(PGH(), NGhosts());
00392 _InitialCondition.SetupData(PGH(), NGhosts());
00393 _BoundaryConditions.SetupData(PGH(), NGhosts());
00394 if (_LevelTransfer) _LevelTransfer->SetupData(PGH(), NGhosts());
00395 if (_Flagging) _Flagging->SetupData(PGH(), NGhosts());
00396 if (_Fixup) _Fixup->SetupData(PGH(), NGhosts());
00397 if (_ExactSolution) _ExactSolution->SetupData(PGH(), NGhosts());
00398 }
00399
00400 virtual void SetupData() {
00401 if (_Hierarchy==(GridHierarchy *) 0)
00402 SetupGridHierarchy();
00403
00404
00405
00406
00407 _BoundaryFunc = new boundary_functor_type(&_BoundaryConditions, &boundary_conditions_type::SetBndry);
00408 if (_LevelTransfer) {
00409 _ProlongFunc = new leveltransfer_functor_type(_LevelTransfer, &leveltransfer_type::Prolong);
00410 _RestrictFunc = new leveltransfer_functor_type(_LevelTransfer, &leveltransfer_type::Restrict);
00411 if (_LevelTransfer->UseAdaptBndry())
00412 _AdaptBndFunc = new adaptbnd_functor_type(_LevelTransfer, &leveltransfer_type::SetAdaptBndry);
00413 }
00414
00415
00416
00417
00418 AllocError::SetTexts("Solver::SetupData","allocation of GridFunctions");
00419 int t_sten = 1;
00420 int s_sten = NGhosts();
00421 std::sprintf(GFName,"u");
00422 _u = new vec_grid_fct_type(GFName, t_sten, s_sten, GH(), DAGHCommSimple);
00423 SetTimeAlias(U(), -1, 1);
00424 SetBndryUpdateFunction(U(), _BoundaryFunc);
00425 if (_LevelTransfer) {
00426 SetProlongFunction(U(), _ProlongFunc);
00427 SetRestrictFunction(U(), _RestrictFunc);
00428 if (_LevelTransfer->UseAdaptBndry()) {
00429 U().GF_SetAdaptBoundaryType(_LevelTransfer->AdaptiveBoundaryType());
00430 U().GF_SetAdaptiveBndryUpdateFunc(_AdaptBndFunc);
00431 }
00432 }
00433
00434 if (ErrorEstimation()) {
00435 std::sprintf(GFNamesh,"ush");
00436 _u_sh = new vec_grid_fct_type(GFNamesh, t_sten, s_sten,
00437 DAGHShadowFactor, GH(), DAGHCommSimple);
00438 SetTimeAlias(Ush(), -1, 1);
00439 SetBndryUpdateFunction(Ush(), _BoundaryFunc);
00440 if (_LevelTransfer) {
00441 SetProlongFunction(Ush(), _ProlongFunc);
00442 SetRestrictFunction(Ush(), _RestrictFunc);
00443 if (_LevelTransfer->UseAdaptBndry()) {
00444 Ush().GF_SetAdaptBoundaryType(_LevelTransfer->AdaptiveBoundaryType());
00445 Ush().GF_SetAdaptiveBndryUpdateFunc(_AdaptBndFunc);
00446 }
00447 }
00448 }
00449
00450
00451 std::sprintf(IOName,"IOPlaceholder");
00452 _work = new grid_fct_type(IOName, t_sten, s_sten, GH(), DAGHCellCentered, DAGHCommSimple,
00453 DAGHNoBoundary, DAGHNoAdaptBoundary, DAGHNoExternalGhost);
00454 SetCheckpointFlag(Work(), DAGHFalse);
00455 Work().GF_SetMaxRecomposeLevel(DAGHNull);
00456 SetTimeAlias(Work(), -1, 1);
00457
00458 if (ErrorEstimation()) {
00459 std::sprintf(IONamesh,"IOPlaceholdersh");
00460 _work_sh = new grid_fct_type(IONamesh, t_sten, s_sten, GH(), DAGHCellCentered, 0,
00461 DAGHShadowFactor, DAGH_All, DAGHCommSimple,
00462 DAGHNoBoundary, DAGHNoAdaptBoundary, DAGHNoExternalGhost);
00463 SetCheckpointFlag(Worksh(), DAGHFalse);
00464 Worksh().GF_SetMaxRecomposeLevel(DAGHNull);
00465 SetTimeAlias(Worksh(), -1, 1);
00466 }
00467 }
00468
00469 virtual void Initialize(double& t, double &dt) {
00470 int me = MY_PROC;
00471 if (me == VizServer)
00472 std::cout << " --- Initializing --- " << std::flush;
00473 Initialize_(Step[0].dtv[0]);
00474 if (me == VizServer)
00475 std::cout << " Levels=" << FineLevel(GH())+1 << std::endl;
00476 double Current_Time, Next_Time;
00477 GH().DAGH_GetTimeSpecs(Current_Time, Next_Time);
00478 if (_ExactSolution)
00479 _ExactSolution->ErrorNorm(U(), Work(), Current_Time);
00480 t = Current_Time;
00481 dt = Next_Time-Current_Time;
00482 }
00483
00484 virtual void Restart(double& t, double &dt) {
00485 int me = MY_PROC;
00486 if (me == VizServer)
00487 std::cout << " --- Restarting from " << CheckpointName.c_str()
00488 << " --- " << std::flush;
00489 if (Restart_(CheckpointName.c_str())) {
00490 if (me == VizServer)
00491 std::cout << " Last Iteration: " << StepsTaken(GH(),0) << std::endl;
00492
00493 double Current_Time, Next_Time;
00494 GH().DAGH_GetTimeSpecs(Current_Time, Next_Time);
00495 if (_ExactSolution)
00496 _ExactSolution->ErrorNorm(U(), Work(), Current_Time);
00497 t = Current_Time;
00498 dt = Next_Time-Current_Time;
00499 }
00500 else {
00501 if (me == VizServer)
00502 std::cout << " File not found. " << std::endl;
00503 }
00504 }
00505
00506 virtual void Advance(double& t, double& dt) {
00507 int me = MY_PROC;
00508 double Current_Time, Next_Time, Final_Time;
00509 GH().DAGH_GetTimeSpecs(Current_Time, Next_Time);
00510 Final_Time = Current_Time + dt;
00511
00512 int CStepControl = 0;
00513
00514 while (Final_Time+DBL_EPSILON*FACTOR>Step[CStepControl].LastTime && CStepControl<NAMRTimeSteps)
00515 CStepControl++;
00516 if (CStepControl>=NAMRTimeSteps) CStepControl = NAMRTimeSteps-1;
00517
00518 if (Step[CStepControl].LastTime-Current_Time > DBL_EPSILON*FACTOR ||
00519 CStepControl==NAMRTimeSteps-1) {
00520
00521 if (Next_Time > Final_Time)
00522 SetTimeSpecs(GH(), Current_Time, Final_Time, 2);
00523
00524 if (me == VizServer) {
00525 std::cout << " --- Iteration: " << StepsTaken(GH(),0)+1 << " ---";
00526 std::cout << " t = " << Current_Time << std::flush;
00527 }
00528
00529 int Rejections;
00530 double cfl_max = Tick(Step[CStepControl].VariableTimeStepping,
00531 Step[CStepControl].dtv, Step[CStepControl].cflv,
00532 Rejections);
00533
00534 double Help_Time;
00535 GH().DAGH_GetTimeSpecs(Next_Time, Help_Time);
00536 if (Help_Time > Step[CStepControl].LastTime) {
00537 Help_Time = Step[CStepControl].LastTime;
00538 }
00539 if (me == VizServer) {
00540 std::cout << " dt=" << Next_Time-Current_Time
00541 << " Levels=" << FineLevel(GH())+1
00542 << " max. CFL=" << cfl_max;
00543 }
00544 Current_Time = Next_Time;
00545 Next_Time = Help_Time;
00546
00547 if (me == VizServer) {
00548 if (Rejections)
00549 std::cout << " Restarted: " << Rejections << "x";
00550 std::cout << std::endl << std::flush;
00551 }
00552 if (_ExactSolution)
00553 _ExactSolution->ErrorNorm(U(), Work(), Current_Time);
00554 }
00555
00556 t = Current_Time;
00557 dt = Next_Time-Current_Time;
00558 }
00559
00560 virtual void Output() {
00561 if (CurrentTime(GH(),0) == LastOutputTime()) return;
00562 if (_FileOutput) {
00563 START_WATCH
00564 _FileOutput->WriteOut(U(), Work());
00565 END_WATCH_OUPUT
00566 SetLastOutputTime(CurrentTime(GH(),0));
00567 }
00568 else
00569 SetLastOutputTime(-1);
00570 }
00571
00572 virtual void Checkpointing() {
00573 if (CurrentTime(GH(),0) == LastCheckpointTime()) return;
00574 int me = MY_PROC;
00575 if (me == VizServer)
00576 std::cout << " *** Checkpoint at " << CurrentTime(GH(),0)
00577 << ": " << std::flush;
00578 START_WATCH
00579 #ifndef DAGH_NO_MPI
00580 MPI_Barrier(comm_service::comm());
00581 #endif
00582 if (_FileOutput) _FileOutput->CloseIO();
00583 if (CheckpointSave) {
00584 if (me == VizServer)
00585 std::cout << "Moving..." << std::flush;
00586 std::ostringstream newName_str;
00587 GH().chkpt_filename(newName_str,CheckpointName.c_str(),me);
00588 char oldName[256], newName[256];
00589 int len = newName_str.str().size();
00590 newName_str.str().copy(newName,len);
00591 int last = -1;
00592 for (int i=0; i<len-1; i++)
00593 if (newName[i]=='/')
00594 last = i;
00595 if (last>=0) std::strncpy(oldName,newName,last+1);
00596 oldName[++last] = '.';
00597 std::strncpy(oldName+last+1,newName+last,len-last);
00598 oldName[len+1] = '\0';
00599 rename(newName,oldName);
00600 #ifndef DAGH_NO_MPI
00601 MPI_Barrier(comm_service::comm());
00602 #endif
00603 if (me == VizServer)
00604 std::cout << "done. " << std::flush;
00605 }
00606 if (me == VizServer)
00607 std::cout << "Writing..." << std::flush;
00608 Checkpointing_(CheckpointName.c_str());
00609 #ifndef DAGH_NO_MPI
00610 MPI_Barrier(comm_service::comm());
00611 #endif
00612 if (me == VizServer)
00613 std::cout << "done." << std::endl << std::flush;
00614 END_WATCH_OUPUT
00615 SetLastCheckpointTime(CurrentTime(GH(),0));
00616 }
00617
00618 virtual int NSteps() { return StepsTaken(GH(),0); }
00619
00620 GridHierarchy& GH() { return *_Hierarchy; }
00621 const GridHierarchy& GH() const { return *_Hierarchy; }
00622 inline GridHierarchy* PGH() const { return _Hierarchy; }
00623
00624 const int& NEquations() const { return _Equations; }
00625 const int& NGhosts() const { return _Ghosts; }
00626 const int& Dim() const { return _Dim; }
00627
00628 inline vec_grid_fct_type& U() { return *_u; }
00629 inline const vec_grid_fct_type& U() const { return *_u; }
00630 inline vec_grid_fct_type& Ush() { return *_u_sh; }
00631 inline const vec_grid_fct_type& Ush() const { return *_u_sh; }
00632 inline grid_fct_type& Work() { return *_work; }
00633 inline const grid_fct_type& Work() const { return *_work; }
00634 inline grid_fct_type& Worksh() { return *_work_sh; }
00635 inline const grid_fct_type& Worksh() const { return *_work_sh; }
00636
00637 inline integrator_type& Integrator_() { return _Integrator; }
00638 inline const integrator_type& Integrator_() const { return _Integrator; }
00639
00640 inline initial_condition_type& InitialCondition_() { return _InitialCondition; }
00641 inline const initial_condition_type& InitialCondition_() const
00642 { return _InitialCondition; }
00643
00644 inline boundary_conditions_type& BoundaryConditions_() { return _BoundaryConditions; }
00645 inline const boundary_conditions_type& BoundaryConditions_() const
00646 { return _BoundaryConditions; }
00647
00648 inline void SetLevelTransfer(leveltransfer_type* _leveltransfer)
00649 { _LevelTransfer = _leveltransfer; }
00650 inline leveltransfer_type& LevelTransfer_() { return *_LevelTransfer; }
00651 inline const leveltransfer_type& LevelTransfer_() const { return *_LevelTransfer; }
00652
00653 inline void SetFlagging(flagging_type* _flagging) { _Flagging = _flagging; }
00654 inline flagging_type& Flagging_() { return *_Flagging; }
00655 inline const flagging_type& Flagging_() const { return *_Flagging; }
00656 inline bool ErrorEstimation() const {
00657 if (_Flagging)
00658 return Flagging_().ErrorEstimation();
00659 else return false;
00660 }
00661
00662 inline void SetFixup(fixup_type* _fixup) { _Fixup = _fixup; }
00663 inline fixup_type& Fixup_() { return *_Fixup; }
00664 inline const fixup_type& Fixup_() const { return *_Fixup; }
00665 inline bool FixupPossible() const { return (_Fixup!=(fixup_type *)0); }
00666
00667 inline void SetExactSolution(exact_solution_type* exact) { _ExactSolution = exact; }
00668 inline exact_solution_type& ExactSolution_() { return *_ExactSolution; }
00669 inline const exact_solution_type& ExactSolution_() const { return *_ExactSolution; }
00670
00671 inline void SetFileOutput(file_output_type* output) { _FileOutput = output; }
00672 inline file_output_type& FileOutput_() { return *_FileOutput; }
00673 inline const file_output_type& FileOutput_() const { return *_FileOutput; }
00674
00675 inline void SetLastOutputTime(int Time) { _LastOutputTime = Time; }
00676 inline int LastOutputTime() const { return _LastOutputTime; }
00677 inline void SetLastCheckpointTime(int Time) { _LastCheckpointTime = Time; }
00678 inline int LastCheckpointTime() const { return _LastCheckpointTime; }
00679
00680 virtual int NMethodOrder() const { return Integrator_().NMethodOrder(); }
00681
00682 inline int FirstNode() const { return firstnode; }
00683 inline int LastNode() const { return lastnode; }
00684 inline int NNodes() const { return lastnode-firstnode+1; }
00685
00686 inline int SizeWorld() const { return comm_service::proc_world(); }
00687 inline int Size() const { return comm_service::proc_num(); }
00688
00689 inline MPI_Group GrpWorld() const { return comm_service::grp_world(); }
00690 inline MPI_Group Grp() const { return comm_service::grp(); }
00691
00692 inline MPI_Comm CommWorld() const { return comm_service::comm_world(); }
00693 inline MPI_Comm Comm() const { return comm_service::comm(); }
00694
00695 protected:
00696 integrator_type& _Integrator;
00697 initial_condition_type& _InitialCondition;
00698 boundary_conditions_type& _BoundaryConditions;
00699 int _Equations, _Ghosts, _Dim;
00700 GridHierarchy* _Hierarchy;
00701 vec_grid_fct_type *_u, *_u_sh;
00702 grid_fct_type *_work, *_work_sh;
00703 leveltransfer_type* _LevelTransfer;
00704 flagging_type* _Flagging;
00705 fixup_type* _Fixup;
00706 exact_solution_type* _ExactSolution;
00707 file_output_type* _FileOutput;
00708 boundary_functor_type* _BoundaryFunc;
00709 leveltransfer_functor_type *_ProlongFunc, *_RestrictFunc;
00710 adaptbnd_functor_type* _AdaptBndFunc;
00711 int RedistributeEvery;
00712 int Distribution;
00713 int MaxLev;
00714 int GuCFactor;
00715 int MaxGridBoxSize;
00716 int _RefineFactor[DAGHMaxLevels];
00717 int periodic[dim];
00718 int shape[dim];
00719 double geom[2*dim];
00720 int CutOffs;
00721 int cuts[2*dim*MaxCutOffRegions];
00722 int NAMRTimeSteps;
00723 AMRTimeStep Step[MaxAMRTimeSteps];
00724 int _LastOutputTime, _LastCheckpointTime;
00725 int firstnode, lastnode, UseIOServer;
00726 std::string CheckpointName;
00727 int CheckpointSave;
00728 double FinalWaitingTime;
00729 ControlDevice LocCtrl, GHCtrl, PCtrl;
00730 char GFName[DAGHBktGFNameWidth], GFNamesh[DAGHBktGFNameWidth];
00731 char IOName[DAGHBktGFNameWidth], IONamesh[DAGHBktGFNameWidth];
00732 };
00733
00734
00735 #endif