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_AMRSOLVER
00018 #include "ClpStdProblem.h"
00019 #include "ClpF77FileOutput.h"
00020 #include "AMRInterpolation.h"
00021
00022 class SolverSpecific :
00023 public AMRSolver<VectorType,FixupType,FlagType,DIM> {
00024 typedef AMRSolver<VectorType,FixupType,FlagType,DIM> base;
00025 typedef VectorType::InternalDataType DataType;
00026 typedef AMRInterpolation<VectorType,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 ClpF77FileOutput<VectorType,AuxType,DIM>(integ,f_flgout));
00035 SetFixup(new FixupSpecific(integ));
00036 SetFlagging(new FlaggingSpecific(*this));
00037 _Interpolation = new interpolation_type();
00038 }
00039
00040 ~SolverSpecific() {
00041 if (dat) delete [] dat;
00042 if (ot) delete [] ot;
00043 delete _LevelTransfer;
00044 delete _Flagging;
00045 delete _Fixup;
00046 delete _FileOutput;
00047 delete _Interpolation;
00048 }
00049
00050 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00051 base::register_at(Ctrl,prefix);
00052 SensorsCtrl = base::LocCtrl.getSubDevice("SensorsOutput");
00053 RegisterAt(SensorsCtrl,"OutputEvery",OutputEvery);
00054 RegisterAt(SensorsCtrl,"OutputLevel",OutputLevel);
00055 RegisterAt(SensorsCtrl,"NSensors",Nxc);
00056 char VariableName[32];
00057 for (register int i=0; i<OUTPUTPOINTSMAX; i++)
00058 for (register int d=0; d<base::Dim(); d++) {
00059 std::sprintf(VariableName,"xc(%d,%d)",i+1,d+1);
00060 RegisterAt(SensorsCtrl,VariableName,xc[i](d));
00061 }
00062 }
00063 virtual void register_at(ControlDevice& Ctrl) {
00064 base::register_at(Ctrl);
00065 }
00066
00067 virtual void SetupData() {
00068 base::SetupData();
00069 _Interpolation->SetupData(base::PGH(), base::NGhosts());
00070 if (OutputEvery<0) OutputEvery=0;
00071 if (Nxc<0) Nxc=0;
00072 if (Nxc>OUTPUTPOINTSMAX) Nxc=OUTPUTPOINTSMAX;
00073 if (OutputLevel<0) OutputLevel=0;
00074 if (OutputLevel>MaxLevel(base::GH()))
00075 OutputLevel=MaxLevel(base::GH());
00076 dat = new VectorType[Nxc*RefinedBy(base::GH(),OutputLevel)];
00077 ot = new double[RefinedBy(base::GH(),OutputLevel)];
00078 for (int i=0; i<RefinedBy(base::GH(),OutputLevel); i++)
00079 ot[i] = 0.;
00080 }
00081
00082 virtual double Tick(int VariableTimeStepping, const double dtv[], const double cflv[],
00083 int& Rejections) {
00084
00085 double cfl = base::Tick(VariableTimeStepping, dtv, cflv, Rejections);
00086
00087
00088 if (MY_PROC==VizServer && output) {
00089 for (int idx=0; idx<RefinedBy(base::GH(),OutputLevel); idx++) {
00090 if (ot[idx] == 0.) continue;
00091 std::ofstream outfile;
00092 std::ostream* out;
00093 std::string fname = "sensors.txt";
00094 outfile.open(fname.c_str(), std::ios::out | std::ios::app);
00095 out = new std::ostream(outfile.rdbuf());
00096 *out << ot[idx] << " ";
00097 for (register int j=0;j<Nxc; j++)
00098 for (register int i=0; i<base::NEquations(); i++)
00099 *out << " " << dat[j](i);
00100 *out << std::endl;
00101 outfile.close();
00102 delete out;
00103 ot[idx] = 0.;
00104 }
00105 output = false;
00106 }
00107
00108 return cfl;
00109 }
00110
00111 virtual void AfterLevelStep(const int Level) {
00112 if (!OutputEvery || Nxc<=0 || OutputLevel!=Level) return;
00113 int Time = CurrentTime(base::GH(),Level);
00114 Time /= TimeStep(base::GH(),Level);
00115 if (Time % OutputEvery != 0) return;
00116 int idx = Time % RefinedBy(base::GH(),Level)-1;
00117 if (idx<0) idx = RefinedBy(base::GH(),Level)-1;
00118 output = true;
00119
00120
00121 _Interpolation->PointsValues(base::U(),base::t[Level],Nxc,xc,dat);
00122 int NValues = Nxc*base::NEquations();
00123 _Interpolation->ArrayCombine(VizServer,NValues,(DataType *)dat);
00124 ot[idx] = base::t[Level];
00125 }
00126
00127 protected:
00128 int OutputEvery, OutputLevel, Nxc;
00129 point_type xc[OUTPUTPOINTSMAX];
00130 interpolation_type* _Interpolation;
00131 ControlDevice SensorsCtrl;
00132 VectorType *dat;
00133 double *ot;
00134 bool output;
00135 };
00136