00001
00002
00003
00004
00005
00006 #ifndef AMROC_GFM_FILE_OUTPUT_H
00007 #define AMROC_GFM_FILE_OUTPUT_H
00008
00015 #include "FileOutput.h"
00016
00023 template <class VectorType, class FixupType, class FlagType, int dim>
00024 class GFMFileOutput : public FileOutput<VectorType,dim> {
00025 typedef FileOutput<VectorType,dim> base;
00026 typedef typename VectorType::InternalDataType DataType;
00027
00028 public:
00029 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00030 typedef typename base::grid_fct_type grid_fct_type;
00031 typedef typename base::grid_data_type grid_data_type;
00032
00033 typedef AMRGFMSolver<VectorType,FixupType,FlagType,dim> gfm_solver_type;
00034 typedef GridFunction<bool,dim> bool_grid_fct_type;
00035 typedef GhostFluidMethod<VectorType,dim> gfm_type;
00036
00037 GFMFileOutput(gfm_solver_type& solver) : base(), _solver(solver), CutOut(1), CutOutValue(-1.e37) {}
00038
00039 virtual ~GFMFileOutput() {}
00040
00041 virtual void register_at(ControlDevice& Ctrl) { base::register_at(Ctrl, ""); }
00042 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00043 base::register_at(Ctrl, prefix);
00044 RegisterAt(base::LocCtrl,"CutOut",CutOut);
00045 RegisterAt(base::LocCtrl,"CutOutValue",CutOutValue);
00046 }
00047
00048 virtual void WriteOut(vec_grid_fct_type& u, grid_fct_type& IOfunc)
00049 { base::WriteOut(u,IOfunc); }
00050
00051 virtual void WriteOut(grid_fct_type& IOfunc, const char* name)
00052 { base::WriteOut(IOfunc,name); }
00053
00054 virtual void WriteOut(grid_fct_type& IOfunc, const char* name,
00055 const int& Time, const int& Level, const double& t) {
00056 if (CutOut) {
00057 forall (IOfunc,Time,Level,c)
00058 for (int g=0; g<NGFM(); g++) {
00059 if (!GFM(g).IsUsed()) continue;
00060 if (base::Dim() == 1) {
00061 BeginFastIndex1(bf, BF()(Time,Level,c).bbox(),
00062 BF()(Time,Level,c).data(), bool);
00063 BeginFastIndex1(IO, IOfunc(Time,Level,c).bbox(),
00064 IOfunc(Time,Level,c).data(), DataType);
00065 for_1 (n, BF()(Time,Level,c).bbox(), BF()(Time,Level,c).bbox().stepsize())
00066 if (FastIndex1(bf,n))
00067 FastIndex1(IO,n) = CutOutValue;
00068 end_for
00069 EndFastIndex1(IO);
00070 EndFastIndex1(bf);
00071 }
00072 else if (base::Dim() == 2) {
00073 BeginFastIndex2(bf, BF()(Time,Level,c).bbox(),
00074 BF()(Time,Level,c).data(), bool);
00075 BeginFastIndex2(IO, IOfunc(Time,Level,c).bbox(),
00076 IOfunc(Time,Level,c).data(), DataType);
00077 for_2 (n, m, BF()(Time,Level,c).bbox(), BF()(Time,Level,c).bbox().stepsize())
00078 if (FastIndex2(bf,n,m))
00079 FastIndex2(IO,n,m) = CutOutValue;
00080 end_for
00081 EndFastIndex2(IO);
00082 EndFastIndex2(bf);
00083 }
00084 else if (base::Dim() == 3) {
00085 BeginFastIndex3(bf, BF()(Time,Level,c).bbox(),
00086 BF()(Time,Level,c).data(), bool);
00087 BeginFastIndex3(IO, IOfunc(Time,Level,c).bbox(),
00088 IOfunc(Time,Level,c).data(), DataType);
00089 for_3 (n, m, l, BF()(Time,Level,c).bbox(), BF()(Time,Level,c).bbox().stepsize())
00090 if (FastIndex3(bf,n,m,l))
00091 FastIndex3(IO,n,m,l) = CutOutValue;
00092 end_for
00093 EndFastIndex3(IO);
00094 EndFastIndex3(bf);
00095 }
00096 }
00097 end_forall
00098 }
00099 base::WritePlain(IOfunc,name,Time,Level,t);
00100 }
00101
00102 virtual void WriteOut(grid_data_type& IOdata, const char* name,
00103 const int& Time, const int& Level, const double& t) {
00104 if (CutOut) {
00105 BBox bb = IOdata.bbox();
00106 grid_data_type phi(bb);
00107 for (int g=0; g<NGFM(); g++) {
00108 if (!GFM(g).IsUsed()) continue;
00109 GFM(g).LevelSet().SetGrid(phi,Level,t);
00110 if (base::Dim() == 1) {
00111 BeginFastIndex1(phi, bb, phi.data(), DataType);
00112 BeginFastIndex1(IO, bb, IOdata.data(), DataType);
00113 for_1 (n, bb, bb.stepsize())
00114 if (FastIndex1(phi,n)<-Cutoff(g) &&
00115 FastIndex1(phi,n)>=-FarAway(g) && FastIndex1(phi,n)<=FarAway(g))
00116 FastIndex1(IO,n) = CutOutValue;
00117 end_for
00118 EndFastIndex1(IO);
00119 EndFastIndex1(phi);
00120 }
00121 else if (base::Dim() == 2) {
00122 BeginFastIndex2(phi, bb, phi.data(), DataType);
00123 BeginFastIndex2(IO, bb, IOdata.data(), DataType);
00124 for_2 (n, m, bb, bb.stepsize())
00125 if (FastIndex2(phi,n,m)<-Cutoff(g) &&
00126 FastIndex2(phi,n,m)>=-FarAway(g) && FastIndex2(phi,n,m)<=FarAway(g))
00127 FastIndex2(IO,n,m) = CutOutValue;
00128 end_for
00129 EndFastIndex2(IO);
00130 EndFastIndex2(phi);
00131 }
00132 else if (base::Dim() == 3) {
00133 BeginFastIndex3(phi, bb, phi.data(), DataType);
00134 BeginFastIndex3(IO, bb, IOdata.data(), DataType);
00135 for_3 (n, m, l, bb, bb.stepsize())
00136 if (FastIndex3(phi,n,m,l)<-Cutoff(g) &&
00137 FastIndex3(phi,n,m,l)>=-FarAway(g) && FastIndex3(phi,n,m,l)<=FarAway(g))
00138 FastIndex3(IO,n,m,l) = CutOutValue;
00139 end_for
00140 EndFastIndex3(IO);
00141 EndFastIndex3(phi);
00142 }
00143 }
00144 }
00145 base::WritePlain(IOdata,name,Time,Level,t);
00146 }
00147
00148 inline bool_grid_fct_type& BF() { return _solver.BF(); }
00149 inline const bool_grid_fct_type& BF() const { return _solver.BF(); }
00150 inline gfm_type& GFM(const int& n) { return _solver.GFM(n); }
00151 inline const int& NGFM() { return _solver.NGFM(); }
00152 inline grid_fct_type& Phi(const int& n) { return GFM(n).Phi(); }
00153 inline const grid_fct_type& Phi(const int& n) const { return GFM(n).Phi(); }
00154 inline const DataType& Cutoff(const int& n) { return GFM(n).Boundary().Cutoff(); }
00155 inline const DataType& FarAway(const int& n) { return GFM(n).Boundary().FarAway(); }
00156 protected:
00157 gfm_solver_type& _solver;
00158 int CutOut;
00159 DataType CutOutValue;
00160 };
00161
00162
00163 #endif