vtf-logo

weno/applications/euler/2d/VortexRotGFM/src/Problem.h

00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2003-2007 California Institute of Technology
00004 // Ralf Deiterding, ralf@amroc.net
00005 
00006 #ifndef AMROC_PROBLEM_H
00007 #define AMROC_PROBLEM_H
00008 
00009 #define DIM  2
00010   
00011 #include "WENOProblem.h"
00012 
00013 #define f_ipvel FORTRAN_NAME(ipvel, IPVEL)
00014 
00015 extern "C" {
00016   void f_ipvel(); 
00017 }
00018 
00019 #define OWN_GFMAMRSOLVER
00020 #include "WENOStdGFMProblem.h"
00021 #include "F77Interfaces/F77GFMExactSolution.h"
00022 
00023 class SolverSpecific : 
00024   public AMRGFMSolver<VectorType,FixupType,FlagType,DIM> {
00025   typedef VectorType::InternalDataType DataType;
00026   typedef AMRGFMSolver<VectorType,FixupType,FlagType,DIM> base;
00027   typedef GhostFluidMethod<VectorType,DIM>::boundary_conditions_type gfm_bc_type;
00028 public:
00029   SolverSpecific(IntegratorSpecific& integ, 
00030                  base::initial_condition_type& init,
00031                  base::boundary_conditions_type& bc) : base(integ, init, bc) {
00032     SetLevelTransfer(new F77LevelTransfer<VectorType,DIM>(f_prolong, f_restrict));
00033 #ifdef f_flgout
00034     SetFileOutput(new F77GFMFileOutput<VectorType,FixupType,FlagType,DIM>(*this,f_flgout)); 
00035 #else   
00036     SetFileOutput(new GFMFileOutput<VectorType,FixupType,FlagType,DIM>(*this)); 
00037 #endif
00038     SetFixup(new FixupSpecific());
00039     SetFlagging(new FlaggingSpecific(*this));   
00040     AddGFM(new GhostFluidMethod<VectorType,DIM>(
00041               new F77GFMBoundary<VectorType,DIM>(f_ibndrfl,f_itrans,f_ipvel),
00042               new F77GFMLevelSet<DataType,DIM>(f_lset),
00043               (gfm_bc_type*)(new F77BoundaryConditions<Vector<DataType,1>,DIM>(f_boundary))));
00044     SetExactSolution(new F77GFMExactSolution<VectorType,FixupType,FlagType,DIM>(*this,f_exact)); 
00045   }  
00046  
00047   ~SolverSpecific() {
00048     delete _GFM[0]->GetBoundaryConditionsP();
00049     DeleteGFM(_GFM[0]);
00050     delete _Flagging;
00051     delete _Fixup;
00052   }
00053 
00054   virtual void SetupData() {
00055     base::SetupData();
00056     _GFM[0]->BoundaryConditions_().SetupData(base::PGH(), base::NGhosts());
00057   }
00058 
00059   virtual void Initialize_(const double& dt_start) {   
00060     base::Initialize_(dt_start);
00061     CalculateCurrentMass(mass_old);
00062   }
00063 
00064   virtual double Tick(int VariableTimeStepping, const double dtv[], 
00065                       const double cflv[], int& Rejections) {
00066 
00067     double cfl = base::Tick(VariableTimeStepping,dtv,cflv,Rejections);
00068 
00069     VectorType mass_new;
00070     CalculateCurrentMass(mass_new);
00071 
00072     // Append to output file only on processor VizServer
00073     int me = MY_PROC; 
00074     if (me == VizServer) {
00075       std::ofstream outfile;
00076       std::ostream* out;
00077       std::string fname = "mass.dat";
00078       outfile.open(fname.c_str(), std::ios::out | std::ios::app);
00079       out = new std::ostream(outfile.rdbuf());
00080       *out << base::t[0];
00081       for (int n=0; n<base::NEquations(); n++)
00082         *out << " " << mass_old[n]-mass_new[n];
00083       *out << std::endl;
00084       outfile.close();
00085       delete out;      
00086     }
00087 
00088     return cfl;
00089   }
00090 
00091   void CalculateCurrentMass(VectorType& mass) {
00092     int Level=0;
00093     int Time = CurrentTime(base::GH(),Level); 
00094     int TStep = TimeStep(base::U(),Level);      
00095     forall (base::U(),Time,Level,c)   
00096       base::U()(Time+TStep,Level,c).equals(base::U()(Time,Level,c));
00097     end_forall
00098 
00099     if (base::NGFM()>0) {
00100       forall (base::U(),Time+TStep,Level,c)           
00101         for (int g=0; g<base::NGFM(); g++) {
00102           if (!base::GFM(g).IsUsed()) continue;
00103             BeginFastIndex2(phi, base::GFM(g).Phi()(Time,Level,c).bbox(), 
00104                             base::GFM(g).Phi()(Time,Level,c).data(), DataType);
00105             BeginFastIndex2(u, base::U()(Time+TStep,Level,c).bbox(), 
00106                             base::U()(Time+TStep,Level,c).data(), VectorType);
00107             for_2 (n, m, base::GFM(g).Phi()(Time,Level,c).bbox(), 
00108                    base::GFM(g).Phi()(Time,Level,c).bbox().stepsize())
00109               if (FastIndex2(phi,n,m)<-base::GFM(g).Boundary().Cutoff()) 
00110                 FastIndex2(u,n,m) = static_cast<VectorType>(0.0);
00111             end_for
00112             EndFastIndex2(u);
00113             EndFastIndex2(phi);
00114           }
00115       end_forall
00116     }
00117 
00118     DCoords dx = base::GH().worldStep(base::U().GF_StepSize(Level));
00119     mass = Sum(base::U(),Time+TStep,Level);
00120     for (int d=0; d<base::Dim(); d++) mass *= dx(d);
00121   }
00122 
00123 protected:
00124   VectorType mass_old;