vtf-logo

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