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


Main Page   Class Hierarchy   Compound List   File List  

AMRSolverControl.h

Go to the documentation of this file.
00001 #ifndef AMROC_AMRSOLVER_CONTROL_H
00002 #define AMROC_AMRSOLVER_CONTROL_H
00003 
00011 #include "SolverControl.h"
00012 
00013 #ifndef AMRSolverControlName
00014 #define AMRSolverControl(dim)      name2(AMRSolverControl,dim)
00015 #define AMRSolverControlName
00016 #endif
00017 
00024 template <class VectorType, class FixupType, class FlagType>
00025 class AMRSolverControl(DIM) : 
00026   public SolverControl(DIM)<VectorType,FixupType,FlagType> {
00027   typedef SolverControl(DIM)<VectorType,FixupType,FlagType> solver_type;
00028   typedef typename VectorType::InternalDataType DataType;
00029 
00030   typedef GridFunction(DIM)<VectorType> vec_grid_fct_type;  
00031   typedef GridFunction(DIM)<DataType>   grid_fct_type;   
00032 public:
00033   AMRSolverControl(DIM)(AMRSolver(DIM)<VectorType,FixupType,FlagType>& solver) :
00034     solver_type(solver) {}
00035 
00036   virtual void init() {
00037     f_init_common();
00038     solver_type::init();
00039   }
00040 
00041   //---------------------------------------------------------------------- 
00042   // Output in primitive variables   
00043   //---------------------------------------------------------------------- 
00044   virtual void WriteOut(GridHierarchy& GH, vec_grid_fct_type& u,
00045                         grid_fct_type& IOfunc) {
00046     int Time;       
00047     int me = MY_PROC(GH); 
00048     
00049     Time = CurrentTime(GH,0); 
00050     Solver_().SetLastOutputTime(Time);
00051     char ioname[DAGHBktGFNameWidth+16];
00052     for (int i=0; i<NEquations(); i++) { 
00053       if (CompName[i].c_str()[0] == '-') 
00054         continue;
00055       sprintf(ioname,"%s_%d",CompName[i].c_str(),Time); 
00056       if (me == VizServer) 
00057         cout << " *** Writing " << ioname << endl;   
00058       for (int lev=0; lev<=FineLevel(GH); lev++) {
00059         Time = CurrentTime(GH,lev); 
00060         forall (u,Time,lev,c)           
00061           equals_from(IOfunc(Time,lev,c), u(Time,lev,c), i);
00062           if (i>=1 && i<=DIM)
00063             divide_from(IOfunc(Time,lev,c), u(Time,lev,c), 0);
00064         end_forall      
00065         SetPhysicalTime(IOfunc,Time,lev,GetPhysicalTime(u,Time,lev));
00066         Write(IOfunc,Time,lev,DAGH_Double,ioname);      
00067       }
00068       // This barrier ensures that SDsclose() is called only once!
00069 #ifndef DAGH_NO_MPI
00070       MPI_Barrier(comm_service::comm()); 
00071 #endif
00072     }
00073   } 
00074  
00075   //---------------------------------------------------------------------- 
00076   // Calculate Error Norm for primitive variables 
00077   //---------------------------------------------------------------------- 
00078   virtual void ErrorNorm(GridHierarchy& GH, vec_grid_fct_type& u, double t,
00079                          grid_fct_type& work) {
00080     if (ENorm<1 || ENorm>3) 
00081       return;
00082 
00083     int me = MY_PROC(GH);
00084     double Error;
00085     if (me == VizServer) 
00086       cout << endl << "                         Errors:";
00087     for (int lev=0; lev<=FineLevel(GH); lev++) {
00088       int Time = CurrentTime(GH,lev); 
00089       int TStep = TimeStep(u,lev);
00090       DCoords dx(DIM);
00091       for(int d=0; d<DIM; d++)
00092         dx(d) = DeltaX(u,d,lev);
00093       
00094       forall (u,Time,lev,c) 
00095         TheExactSolution().SetGrid(u(Time+TStep,lev,c), t, dx);
00096         for (int i=NEquations()-1; i>=0; i--) {
00097           equals_from(work(Time,lev,c), u(Time,lev,c), i);
00098           equals_from(work(Time+TStep,lev,c), u(Time+TStep,lev,c), i);
00099           if (i>=1 && i<=DIM) {
00100             divide_from(work(Time,lev,c), u(Time,lev,c), 0);
00101             divide_from(work(Time+TStep,lev,c), u(Time+TStep,lev,c), 0);
00102           }
00103           work(Time+TStep,lev,c).minus(work(Time,lev,c));       
00104           equals_to(u(Time+TStep,lev,c), work(Time+TStep,lev,c), i);
00105         }
00106       end_forall    
00107 
00108       for (int i=0; i<NEquations(); i++)
00109         if (i<1 || i>DIM) {
00110           forall (u,Time,lev,c) 
00111             equals_from(work(Time,lev,c), u(Time+TStep,lev,c), i);
00112           end_forall      
00113           Error = Norm(work,Time,lev,ENorm);
00114           if (me == VizServer) 
00115             cout << "   L(" << lev << "," << i << ")=" << Error;
00116           forall (u,Time,lev,c) 
00117             work(Time,lev,c) = 0.0;     
00118             equals_to(u(Time+TStep,lev,c), work(Time,lev,c), i);        
00119           end_forall
00120         }
00121       Error = Norm(u,Time+TStep,lev,ENorm);
00122       if (me == VizServer) 
00123         cout << "   L(" << lev << ",|u|" << ")=" << Error;
00124     }
00125   }  
00126 };
00127 
00128 
00129 #endif      


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



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