00001
00002
00003
00004
00005
00006 #ifndef AMROC_PROBLEM_H
00007 #define AMROC_PROBLEM_H
00008
00009 #include "eulerrhok1.h"
00010
00011 #define NEQUATIONS 10
00012 #define NEQUSED 7
00013 #define NFIXUP 6
00014 #define NAUX 0
00015
00016 #include "ClpProblem.h"
00017
00018 #define OWN_FLAGGING
00019 #define OWN_AMRSOLVER
00020 #include "ClpStdProblem.h"
00021 #include "F77Interfaces/F77UpdateLevelTransfer.h"
00022
00023 class FlaggingSpecific :
00024 public AMRFlagging<VectorType,FixupType,FlagType,DIM> {
00025 typedef AMRFlagging<VectorType,FixupType,FlagType,DIM> base;
00026 public:
00027 FlaggingSpecific(base::solver_type& solver) : base(solver) {
00028 base::AddCriterion(new ScaledGradient<VectorType,FlagType,DIM>());
00029 base::AddCriterion(new LimiterType<VectorType,FlagType,DIM>());
00030 base::AddCriterion(new AbsoluteError<VectorType,FixupType,FlagType,DIM>(solver));
00031 base::AddCriterion(new RelativeError<VectorType,FixupType,FlagType,DIM>(solver));
00032 base::AddCriterion(new F77ScaledGradient<VectorType,FlagType,DIM>(f_flg));
00033 base::AddCriterion(new F77LimiterType<VectorType,FlagType,DIM>(f_flg));
00034 base::AddCriterion(new F77AbsoluteError<VectorType,FixupType,FlagType,DIM>(solver,f_flg));
00035 base::AddCriterion(new F77RelativeError<VectorType,FixupType,FlagType,DIM>(solver,f_flg));
00036 }
00037
00038 ~FlaggingSpecific() { DeleteAllCriterions(); }
00039 };
00040
00041
00042 class SolverSpecific :
00043 public AMRSolver<VectorType,FixupType,FlagType,DIM> {
00044 typedef VectorType::InternalDataType DataType;
00045 typedef AMRSolver<VectorType,FixupType,FlagType,DIM> base;
00046 typedef F77FileOutput<VectorType,DIM> output_type;
00047 public:
00048 SolverSpecific(IntegratorSpecific& integ,
00049 base::initial_condition_type& init,
00050 base::boundary_conditions_type& bc) :
00051 AMRSolver<VectorType,FixupType,FlagType,DIM>(integ, init, bc), OutputPMax(0), PThreshold(0.) {
00052 SetLevelTransfer(new F77UpdateLevelTransfer<VectorType,DIM>(f_prolong, f_restrict, f_tupdate));
00053 SetFileOutput(new output_type(f_out));
00054 SetFixup(new FixupSpecific(integ));
00055 SetFlagging(new FlaggingSpecific(*this));
00056 }
00057
00058 ~SolverSpecific() {
00059 delete _LevelTransfer;
00060 delete _Flagging;
00061 delete _Fixup;
00062 delete _FileOutput;
00063 }
00064
00065 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00066 base::register_at(Ctrl, prefix);
00067 RegisterAt(LocCtrl,"OutputPMax",OutputPMax);
00068 RegisterAt(LocCtrl,"PThreshold",PThreshold);
00069 }
00070 virtual void register_at(ControlDevice& Ctrl) {
00071 register_at(Ctrl, "");
00072 }
00073
00074 virtual void AfterLevelStep(const int Level) {
00075 if (Level<FineLevel(base::GH())) return;
00076 if (OutputPMax) {
00077 double maxp[2];
00078 for (register int l=0; l<=FineLevel(base::GH()); l++) {
00079 int Time = CurrentTime(base::GH(),l);
00080 int press_cnt = base::Dim()+4;
00081 ((output_type*) _FileOutput)->Transform(base::U(), base::Work(), Time, l,
00082 press_cnt, base::t[l]);
00083 maxp[0] = 0.0; maxp[1] = 0.0;
00084 forall (base::Work(),Time,l,c)
00085 BBox bb = base::Work()(Time,l,c).bbox();
00086 BeginFastIndex1(work, bb, base::Work()(Time,l,c).data(), DataType);
00087 for (int n=bb.upper(0)-bb.stepsize(0); n>=bb.lower(0)+bb.stepsize(0); n-=bb.stepsize(0))
00088 if (FastIndex1(work,n)>FastIndex1(work,n+bb.stepsize(0)) &&
00089 FastIndex1(work,n)>FastIndex1(work,n-bb.stepsize(0)) &&
00090 FastIndex1(work,n)>PThreshold) {
00091 if (n>maxp[0]) { maxp[0] = double(n); maxp[1] = FastIndex1(work,n); }
00092 break;
00093 }
00094 EndFastIndex1(work);
00095 end_forall
00096 }
00097 #ifdef DAGH_NO_MPI
00098 #else
00099 if (comm_service::dce() && comm_service::proc_num() > 1) {
00100 int num = comm_service::proc_num();
00101 int R;
00102 int size = 2*sizeof(double);
00103 void *values = (void *) new char[size*num];
00104 R = MPI_Allgather(&maxp, size, MPI_BYTE, values, size, MPI_BYTE,
00105 comm_service::comm());
00106 if ( MPI_SUCCESS != R )
00107 comm_service::error_die( "SolverControlSpecific::maxp", "MPI_Allgather", R );
00108 for (int i=0;i<num;i++) {
00109 double tmaxn = *((double *)values + 2*i);
00110 double tmaxp = *((double *)values + 2*i+1);
00111 if (tmaxn>maxp[0]) maxp[1] = tmaxp;
00112 }
00113 if (values) delete [] (char *)values;
00114 }
00115 #endif
00116 int me = MY_PROC;
00117 if (me == VizServer) {
00118 std::ofstream outfile;
00119 std::ostream* out;
00120 std::string fname = "pmax.dat";
00121 outfile.open(fname.c_str(), std::ios::out | std::ios::app);
00122 out = new std::ostream(outfile.rdbuf());
00123 *out << base::t[Level] << " " << maxp[1] << std::endl;
00124 outfile.close();
00125 delete out;
00126 }
00127 }
00128 }
00129
00130 protected:
00131 int OutputPMax;
00132 double PThreshold;
00133 };