vtf-logo

clawpack/applications/scaling/2d/Spheres/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 "euler2.h"
00010 #include "ClpProblem.h"
00011 
00012 #define OWN_GFMAMRSOLVER
00013 #include "ClpStdGFMProblem.h"
00014 
00015 class SolverSpecific : 
00016   public AMRGFMSolver<VectorType,FixupType,FlagType,DIM> {
00017   typedef VectorType::InternalDataType DataType;
00018   typedef AMRGFMSolver<VectorType,FixupType,FlagType,DIM> base;
00019 public:
00020   SolverSpecific(IntegratorSpecific& integ, 
00021                  base::initial_condition_type& init,
00022                  base::boundary_conditions_type& bc) : base(integ, init, bc) {
00023     SetLevelTransfer(new F77LevelTransfer<VectorType,DIM>(f_prolong, f_restrict));
00024 #ifdef f_flgout
00025     SetFileOutput(new F77GFMFileOutput<VectorType,FixupType,FlagType,DIM>(*this,f_flgout)); 
00026 #else   
00027     SetFileOutput(new GFMFileOutput<VectorType,FixupType,FlagType,DIM>(*this)); 
00028 #endif
00029     SetFixup(new FixupSpecific(integ));
00030     SetFlagging(new FlaggingSpecific(*this)); 
00031     AddGFM(new GhostFluidMethod<VectorType,DIM>(
00032               new F77GFMBoundary<VectorType,DIM>(f_ibndrfl,f_itrans),
00033               new F77GFMLevelSet<DataType,DIM>(f_lset)));
00034     last[0]=0.; last[1]=0.; last[2]=0.;
00035     TraceDumpEvery = 1;
00036   }  
00037  
00038   ~SolverSpecific() {
00039     DeleteGFM(_GFM[0]);
00040     delete _Flagging;
00041     delete _Fixup;
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;