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