vtf-logo

clawpack/applications/scaling/2d/ShockTurb/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 #include "eulerznd2.h"
00010 #include "ClpProblem.h"
00011 
00012 #define OWN_GFMAMRSOLVER
00013 #include "ClpStdGFMProblem.h"
00014 #include "AMRGFMInterpolation.h"
00015 
00016 class SolverSpecific : 
00017   public AMRSolver<VectorType,FixupType,FlagType,DIM> {
00018   typedef AMRSolver<VectorType,FixupType,FlagType,DIM> base;
00019 public:
00020   SolverSpecific(IntegratorSpecific& integ, 
00021                  base::initial_condition_type& init,
00022                  base::boundary_conditions_type& bc) :
00023     AMRSolver<VectorType,FixupType,FlagType,DIM>(integ, init, bc) {
00024     SetLevelTransfer(new F77LevelTransfer<VectorType,DIM>(f_prolong, f_restrict));
00025 #ifdef f_flgout
00026     SetFileOutput(new F77FileOutput<VectorType,DIM>(f_flgout)); 
00027 #else   
00028     SetFileOutput(new FileOutput<VectorType,DIM>()); 
00029 #endif
00030     SetFixup(new FixupSpecific(integ));
00031     SetFlagging(new FlaggingSpecific(*this)); 
00032     last[0]=0.; last[1]=0.; last[2]=0.;
00033     TraceDumpEvery = 1;
00034   }
00035 
00036   ~SolverSpecific() {
00037     delete _LevelTransfer;
00038     delete _Flagging;
00039     delete _Fixup;
00040     delete _FileOutput;
00041   }
00042 
00043   virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00044     base::register_at(Ctrl,prefix);
00045     RegisterAt(base::LocCtrl,"TraceDumpEvery",TraceDumpEvery);
00046   } 
00047   virtual void register_at(ControlDevice& Ctrl) {
00048     base::register_at(Ctrl);
00049   }
00050 
00051   virtual void Initialize(double& t, double& dt) {
00052     base::Initialize(t,dt);
00053     TraceDump(0);
00054   }
00055 
00056   virtual void Advance(double& t, double& dt) {
00057     base::Advance(t,dt);
00058     int TimeZero  = CurrentTime(base::GH(),0);
00059     TimeZero /= RefinedBy(base::GH(),MaxLevel(base::GH()));
00060     if (TimeZero%TraceDumpEvery==0 && TraceDumpEvery>0) 
00061       TraceDump(TimeZero/TraceDumpEvery);
00062   }
00063 
00064   void TraceDump(int time) {
00065     int me = MY_PROC; 
00066 #ifdef TIMING_AMR
00067     double stats[3], current[3];
00068     timing.collect_timing(comm_service::comm(),Timing::INTEGRATION_MAIN,current);
00069     timing.collect_timing(comm_service::comm(),Timing::INTEGRATION_ESTIMATE,stats);
00070     if (me == VizServer) {
00071       current[0]+=stats[0]; current[1]+=stats[1]; current[2]+=stats[2];
00072     }
00073     timing.collect_timing(comm_service::comm(),Timing::INTEGRATION_SHADOW,stats);
00074     if (me == VizServer) {
00075       current[0]+=stats[0]; current[1]+=stats[1]; current[2]+=stats[2];
00076     }
00077     timing.collect_timing(comm_service::comm(),Timing::SOURCE_INTEGRATION,stats);
00078     if (me == VizServer) {
00079       current[0]+=stats[0]; current[1]+=stats[1]; current[2]+=stats[2];
00080     }
00081     if (me == VizServer) {
00082       stats[0] = current[0]-last[0]; stats[1] = current[1]-last[1]; stats[2] = current[2]-last[2]; 
00083       std::ofstream ofst("balance.txt", std::ios::out | std::ios::app);
00084       char str[128];
00085       std::sprintf(str, "\t%3.9f    %2.4f    %2.4f    %2.4f", base::t[0], 
00086                    (stats[2]>0. ? stats[0]/stats[2] : 1.),
00087                    (stats[2]>0. ? stats[1]/stats[2] : 1.),
00088                    (stats[2]>0. ? (stats[0]-stats[1])/stats[2] : 1.));
00089       ofst << time << str << std::endl;
00090       ofst.close();
00091     }
00092 #endif
00093 
00094     if (me == VizServer) {
00095       int id=0;
00096       std::ofstream ofs("trace.txt", std::ios::out | std::ios::app);
00097       for (register int l=0; l<=FineLevel(base::GH()); l++)
00098         for (GridBox *gb=base::GH().ggbl(l)->first();gb;gb=base::GH().ggbl(l)->next())
00099           dumpBox(gb->gbBBox(), l, gb->gbOwner(), time, id++, ofs);
00100       ofs.close();
00101     }
00102   }
00103 
00104   void dumpBox(const BBox &bb, int l, int proc, int time, int id, std::ofstream &ofs) {
00105     ofs << time << "\t" << proc << "\t" << l << "\t" << id <<"\t";
00106     ofs << bb.extents(0) <<"\t";
00107     if (bb.rank>1) ofs << bb.extents(1) <<"\t";
00108     else ofs << "-1\t";
00109     if (bb.rank>2) ofs << bb.extents(2) <<"\t";
00110     else ofs << "-1\t";
00111     ofs << bb.lower(0) <<"\t";
00112     if (bb.rank>1) ofs << bb.lower(1) <<"\t";
00113     else ofs << "-1\t";
00114     if (bb.rank>2) ofs << bb.lower(2) <<"\t";
00115     else ofs << "-1\t";
00116     ofs << bb.upper(0) <<"\t";
00117     if (bb.rank>1) ofs << bb.upper(1) <<"\t";
00118     else ofs << "-1\t";
00119     if (bb.rank>2) ofs << bb.upper(2) <<"\t";
00120     else ofs << "-1\t";
00121     ofs << std::endl;
00122   }
00123 
00124 protected:
00125   double last[3];
00126   int TraceDumpEvery;