00001
00002
00003
00004
00005
00006 #ifndef AMROC_GFM_EXACT_SOLUTION_H
00007 #define AMROC_GFM_EXACT_SOLUTION_H
00008
00015 #include "ExactSolution.h"
00016
00023 template <class VectorType, class FixupType, class FlagType, int dim>
00024 class GFMExactSolution : public ExactSolution<VectorType,dim> {
00025 typedef ExactSolution<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 GhostFluidMethod<VectorType,dim> gfm_type;
00035
00036 GFMExactSolution(gfm_solver_type& solver) : base(), _solver(solver) {}
00037
00038 virtual ~GFMExactSolution() {}
00039
00040 virtual void CalculateNorm(vec_grid_fct_type& u, double*& Error) {
00041 if (NGFM()>0)
00042 for (int Level=0; Level<=FineLevel(base::GH()); Level++) {
00043 int Time = CurrentTime(base::GH(),Level);
00044 int TStep = TimeStep(u,Level);
00045 forall (u,Time+TStep,Level,c)
00046 for (int g=0; g<NGFM(); g++) {
00047 if (!GFM(g).IsUsed()) continue;
00048 if (base::Dim() == 1) {
00049 BeginFastIndex1(phi, Phi(g)(Time,Level,c).bbox(),
00050 Phi(g)(Time,Level,c).data(), DataType);
00051 BeginFastIndex1(u, u(Time+TStep,Level,c).bbox(),
00052 u(Time+TStep,Level,c).data(), VectorType);
00053 for_1 (n, Phi(g)(Time,Level,c).bbox(), Phi(g)(Time,Level,c).bbox().stepsize())
00054 if (FastIndex1(phi,n)<-Cutoff(g))
00055 FastIndex1(u,n) = static_cast<VectorType>(0.0);
00056 end_for
00057 EndFastIndex1(u);
00058 EndFastIndex1(phi);
00059 }
00060 else if (base::Dim() == 2) {
00061 BeginFastIndex2(phi, Phi(g)(Time,Level,c).bbox(),
00062 Phi(g)(Time,Level,c).data(), DataType);
00063 BeginFastIndex2(u, u(Time+TStep,Level,c).bbox(),
00064 u(Time+TStep,Level,c).data(), VectorType);
00065 for_2 (n, m, Phi(g)(Time,Level,c).bbox(), Phi(g)(Time,Level,c).bbox().stepsize())
00066 if (FastIndex2(phi,n,m)<-Cutoff(g))
00067 FastIndex2(u,n,m) = static_cast<VectorType>(0.0);
00068 end_for
00069 EndFastIndex2(u);
00070 EndFastIndex2(phi);
00071 }
00072 else if (base::Dim() == 3) {
00073 BeginFastIndex3(phi, Phi(g)(Time,Level,c).bbox(),
00074 Phi(g)(Time,Level,c).data(), DataType);
00075 BeginFastIndex3(u, u(Time+TStep,Level,c).bbox(),
00076 u(Time+TStep,Level,c).data(), VectorType);
00077 for_3 (n, m, l, Phi(g)(Time,Level,c).bbox(), Phi(g)(Time,Level,c).bbox().stepsize())
00078 if (FastIndex3(phi,n,m,l)<-Cutoff(g))
00079 FastIndex3(u,n,m,l) = static_cast<VectorType>(0.0);
00080 end_for
00081 EndFastIndex3(u);
00082 EndFastIndex3(phi);
00083 }
00084 }
00085 end_forall
00086 }
00087 base::CalculateNorm(u,Error);
00088 }
00089
00090 virtual void CalculateNorm(grid_fct_type& u, double*& Error) {
00091 if (NGFM()>0)
00092 for (int Level=0; Level<=FineLevel(base::GH()); Level++) {
00093 int Time = CurrentTime(base::GH(),Level);
00094 int TStep = TimeStep(u,Level);
00095 forall (u,Time+TStep,Level,c)
00096 for (int g=0; g<NGFM(); g++) {
00097 if (!GFM(g).IsUsed()) continue;
00098 if (base::Dim() == 1) {
00099 BeginFastIndex1(phi, Phi(g)(Time,Level,c).bbox(),
00100 Phi(g)(Time,Level,c).data(), DataType);
00101 BeginFastIndex1(u, u(Time+TStep,Level,c).bbox(),
00102 u(Time+TStep,Level,c).data(), DataType);
00103 for_1 (n, Phi(g)(Time,Level,c).bbox(), Phi(g)(Time,Level,c).bbox().stepsize())
00104 if (FastIndex1(phi,n)<-Cutoff(g))
00105 FastIndex1(u,n) = static_cast<DataType>(0.0);
00106 end_for
00107 EndFastIndex1(u);
00108 EndFastIndex1(phi);
00109 }
00110 else if (base::Dim() == 2) {
00111 BeginFastIndex2(phi, Phi(g)(Time,Level,c).bbox(),
00112 Phi(g)(Time,Level,c).data(), DataType);
00113 BeginFastIndex2(u, u(Time+TStep,Level,c).bbox(),
00114 u(Time+TStep,Level,c).data(), DataType);
00115 for_2 (n, m, Phi(g)(Time,Level,c).bbox(), Phi(g)(Time,Level,c).bbox().stepsize())
00116 if (FastIndex2(phi,n,m)<-Cutoff(g))
00117 FastIndex2(u,n,m) = static_cast<DataType>(0.0);
00118 end_for
00119 EndFastIndex2(u);
00120 EndFastIndex2(phi);
00121 }
00122 else if (base::Dim() == 3) {
00123 BeginFastIndex3(phi, Phi(g)(Time,Level,c).bbox(),
00124 Phi(g)(Time,Level,c).data(), DataType);
00125 BeginFastIndex3(u, u(Time+TStep,Level,c).bbox(),
00126 u(Time+TStep,Level,c).data(), DataType);
00127 for_3 (n, m, l, Phi(g)(Time,Level,c).bbox(), Phi(g)(Time,Level,c).bbox().stepsize())
00128 if (FastIndex3(phi,n,m,l)<-Cutoff(g))
00129 FastIndex3(u,n,m,l) = static_cast<DataType>(0.0);
00130 end_for
00131 EndFastIndex3(u);
00132 EndFastIndex3(phi);
00133 }
00134 }
00135 end_forall
00136 }
00137 base::CalculateNorm(u,Error);
00138 }
00139
00140 inline gfm_type& GFM(const int& n) { return _solver.GFM(n); }
00141 inline const int& NGFM() { return _solver.NGFM(); }
00142 inline grid_fct_type& Phi(const int& n) { return GFM(n).Phi(); }
00143 inline const DataType& Cutoff(const int& n) { return GFM(n).Boundary().Cutoff(); }
00144 protected:
00145 gfm_solver_type& _solver;
00146 };
00147
00148 #endif