00001
00002
00003
00004
00005
00006 #ifndef AMROC_PROBLEM_H
00007 #define AMROC_PROBLEM_H
00008
00009 #include "acousticsv2.h"
00010 #undef NAUX
00011 #define NAUX 4
00012
00013 #define OUTPUTPOINTSMAX 40
00014
00015 #include "ClpProblem.h"
00016
00017 #define OWN_GFMAMRSOLVER
00018 #include "ClpStdGFMProblem.h"
00019 #include "ClpF77GFMFileOutput.h"
00020 #include "AMRGFMInterpolation.h"
00021
00022 class SolverSpecific :
00023 public AMRGFMSolver<VectorType,FixupType,FlagType,DIM> {
00024 typedef AMRGFMSolver<VectorType,FixupType,FlagType,DIM> base;
00025 typedef VectorType::InternalDataType DataType;
00026 typedef AMRGFMInterpolation<VectorType,FixupType,FlagType,DIM> interpolation_type;
00027 typedef interpolation_type::point_type point_type;
00028
00029 public:
00030 SolverSpecific(IntegratorSpecific& integ,
00031 base::initial_condition_type& init,
00032 base::boundary_conditions_type& bc) : base(integ, init, bc) {
00033 SetLevelTransfer(new F77LevelTransfer<VectorType,DIM>(f_prolong, f_restrict));
00034 SetFileOutput(new ClpF77GFMFileOutput<VectorType,FixupType,FlagType,AuxType,DIM>(*this,integ,f_flgout));
00035 SetFixup(new FixupSpecific(integ));
00036 SetFlagging(new FlaggingSpecific(*this));
00037 AddGFM(new GhostFluidMethod<VectorType,DIM>(new F77GFMBoundary<VectorType,DIM>(f_ibndrfl),
00038 new F77GFMLevelSet<DataType,DIM>(f_lset)));
00039 _Interpolation = new interpolation_type(*this);
00040 }
00041
00042 ~SolverSpecific() {
00043 if (dat) delete [] dat;
00044 if (ot) delete [] ot;
00045 DeleteGFM(_GFM[0]);
00046 delete _LevelTransfer;
00047 delete _Flagging;
00048 delete _Fixup;
00049 delete _FileOutput;
00050 delete _Interpolation;
00051 }
00052
00053 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00054 base::register_at(Ctrl,prefix);
00055 SensorsCtrl = base::LocCtrl.getSubDevice("SensorsOutput");
00056 RegisterAt(SensorsCtrl,"OutputEvery",OutputEvery);
00057 RegisterAt(SensorsCtrl,"OutputLevel",OutputLevel);
00058 RegisterAt(SensorsCtrl,"NSensors",Nxc);
00059 char VariableName[32];
00060 for (register int i=0; i<OUTPUTPOINTSMAX; i++)
00061 for (register int d=0; d<base::Dim(); d++) {
00062 std::sprintf(VariableName,"xc(%d,%d)",i+1,d+1);
00063 RegisterAt(SensorsCtrl,VariableName,xc[i](d));
00064 }
00065 }
00066 virtual void register_at(ControlDevice& Ctrl) {
00067 base::register_at(Ctrl);
00068 }
00069
00070 virtual void SetupData() {
00071 base::SetupData();
00072 _Interpolation->SetupData(base::PGH(), base::NGhosts());
00073 if (OutputEvery<0) OutputEvery=0;
00074 if (Nxc<0) Nxc=0;
00075 if (Nxc>OUTPUTPOINTSMAX) Nxc=OUTPUTPOINTSMAX;
00076 if (OutputLevel<0) OutputLevel=0;
00077 if (OutputLevel>MaxLevel(base::GH()))
00078 OutputLevel=MaxLevel(base::GH());
00079 dat = new VectorType[Nxc*RefinedBy(base::GH(),OutputLevel)];
00080 ot = new double[RefinedBy(base::GH(),OutputLevel)];
00081 for (int i=0; i<RefinedBy(base::GH(),OutputLevel); i++)
00082 ot[i] = 0.;
00083 }
00084
00085 virtual double Tick(int VariableTimeStepping, const double dtv[], const double cflv[],
00086 int& Rejections) {
00087
00088 double cfl = base::Tick(VariableTimeStepping, dtv, cflv, Rejections);
00089
00090
00091 if (MY_PROC==VizServer && output) {
00092 for (int idx=0; idx<RefinedBy(base::GH(),OutputLevel); idx++) {
00093 if (ot[idx] == 0.) continue;
00094 std::ofstream outfile;
00095 std::ostream* out;
00096 std::string fname = "sensors.txt";
00097 outfile.open(fname.c_str(), std::ios::out | std::ios::app);
00098 out = new std::ostream(outfile.rdbuf());
00099 *out << ot[idx] << " ";
00100 for (register int j=0;j<Nxc; j++)
00101 for (register int i=0; i<base::NEquations(); i++)
00102 *out << " " << dat[j](i);
00103 *out << std::endl;
00104 outfile.close();
00105 delete out;
00106 ot[idx] = 0.;
00107 }
00108 output = false;
00109 }
00110
00111 return cfl;
00112 }
00113
00114 virtual void AfterLevelStep(const int Level) {
00115 if (!OutputEvery || Nxc<=0 || OutputLevel!=Level) return;
00116 int Time = CurrentTime(base::GH(),Level);
00117 Time /= TimeStep(base::GH(),Level);
00118 if (Time % OutputEvery != 0) return;
00119 int idx = Time % RefinedBy(base::GH(),Level)-1;
00120 if (idx<0) idx = RefinedBy(base::GH(),Level)-1;
00121 output = true;
00122
00123
00124 _Interpolation->PointsValues(base::U(),base::t[Level],Nxc,xc,dat);
00125 int NValues = Nxc*base::NEquations();
00126 _Interpolation->ArrayCombine(VizServer,NValues,(DataType *)dat);
00127 ot[idx] = base::t[Level];
00128 }
00129
00130 protected:
00131 int OutputEvery, OutputLevel, Nxc;
00132 point_type xc[OUTPUTPOINTSMAX];
00133 interpolation_type* _Interpolation;
00134 ControlDevice SensorsCtrl;
00135 VectorType *dat;
00136 double *ot;
00137 bool output;
00138 };
00139