vtf-logo

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