AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

AMRFlagging3.h

Go to the documentation of this file.
00001 #ifndef AMROC_AMRFLAGGING3_H
00002 #define AMROC_AMRFLAGGING3_H
00003 
00011 #include "AMRFlaggingBase.h"
00012 
00013 #ifndef AMRFlaggingName
00014 #define AMRFlagging(dim)      name2(AMRFlagging,dim)
00015 #define AMRFlaggingName
00016 #endif
00017 
00024 template <class VectorType, class FixupType, class FlagType>
00025 class AMRFlagging(3) : 
00026   public AMRFlaggingBase(3)<VectorType,FixupType,FlagType> {
00027   typedef Solver(3)<VectorType,FixupType,FlagType> solver_type;    
00028   typedef typename VectorType::InternalDataType DataType;
00029   typedef GridFunction(3)<DataType> gr_fct_type;
00030 public:
00031   AMRFlagging(3)(solver_type& solver) :
00032     AMRFlaggingBase(3)<VectorType,FixupType,FlagType>(solver) {}
00033 
00034 protected:  
00035   void FlagInDirection(const int Time, const int Level, gr_fct_type &u,
00036                        int* Offset1, int* Offset2, DataType TolSp, FlagType FlagValue) {
00037    
00038     if (TolSp <= 0.0) return;
00039     int TStep = TimeStep(u,Level);
00040     forall(Flags(), Time, Level, c)
00041       BBox OpBox = u.interiorbbox(Time,Level,c);
00042       Coords& OpBox_stepsize = OpBox.stepsize();
00043       BeginFastIndex3(u, u(Time,Level,c).bbox(), 
00044                       u(Time,Level,c).data(), DataType);
00045       BeginFastIndex3(uout, u(Time+TStep,Level,c).bbox(), 
00046                       u(Time+TStep,Level,c).data(), DataType);
00047       BeginFastIndex3(Flags, Flags()(Time,Level,c).bbox(), 
00048                       Flags()(Time,Level,c).data(), FlagType);
00049 
00050       Coords o1 = Coords(3,Offset1)*OpBox_stepsize;
00051       Coords o2 = Coords(3,Offset2)*OpBox_stepsize;
00052       DataType value;
00053       for_3 (n, m, l, OpBox, OpBox_stepsize)
00054         value = fabs(FastIndex3(u,n+o1(0),m+o1(1),l+o1(2))-
00055                      FastIndex3(u,n+o2(0),m+o2(1),l+o2(2)));
00056         if (value >= TolSp) 
00057           FastIndex3(Flags,n,m,l) = FlagValue; 
00058         if (value > FastIndex3(uout,n,m,l))
00059           FastIndex3(uout,n,m,l) = value;
00060       end_for
00061 
00062       EndFastIndex3(u);
00063       EndFastIndex3(uout);
00064       EndFastIndex3(Flags);
00065     end_forall
00066   }
00067 
00068   void FlagByDifference(const int Time, const int Level, gr_fct_type &u, 
00069                         DataType TolSp, FlagType FlagValue) { 
00070     if (TolSp <= 0.0) return;
00071     int East[3]  = { 1, 0, 0 }; int West[3]   = {-1,  0, 0 };
00072     int North[3] = { 0, 1, 0 }; int South[3]  = { 0, -1, 0 };
00073     int Top[3]   = { 0, 0, 1 }; int Bottom[3] = { 0,  0,-1 };
00074     FlagInDirection(Time, Level, u, East, West, TolSp, FlagValue);
00075     FlagInDirection(Time, Level, u, North, South, TolSp, FlagValue);
00076     FlagInDirection(Time, Level, u, Top, Bottom, TolSp, FlagValue);
00077 
00078     int NorthEastTop[3]    = {  1, 1,  1}; int SouthWestBottom[3] = { -1, -1, -1};
00079     int NorthEastBottom[3] = {  1, 1, -1}; int SouthWestTop[3]    = { -1, -1,  1};
00080     int NorthWestTop[3]    = { -1, 1,  1}; int SouthEastBottom[3] = {  1, -1, -1};
00081     int NorthWestBottom[3] = { -1, 1, -1}; int SouthEastTop[3]    = {  1, -1,  1};
00082     FlagInDirection(Time, Level, u, NorthEastTop, SouthWestBottom, TolSp, FlagValue);
00083     FlagInDirection(Time, Level, u, NorthEastBottom, SouthWestTop, TolSp, FlagValue);
00084     FlagInDirection(Time, Level, u, NorthWestTop, SouthEastBottom, TolSp, FlagValue);
00085     FlagInDirection(Time, Level, u, NorthWestBottom, SouthEastTop, TolSp, FlagValue);
00086   }
00087 
00088   virtual void FlagByErrorEstimation(const int Time, const int Level, gr_fct_type &ush, 
00089                                      DataType Tol, FlagType FlagValue) {
00090 
00091     if (Tol <= 0.0) return;
00092     int ShTStep = TimeStep(ush,Level);
00093     forall(Flags(), Time, Level, c)
00094       BeginFastIndex3(ush, ush(Time+ShTStep,Level,c).bbox(), 
00095                       ush(Time+ShTStep,Level,c).data(), DataType);        
00096       BeginFastIndex3(Flags, Flags()(Time,Level,c).bbox(), 
00097                       Flags()(Time,Level,c).data(), FlagType);
00098       BBox OpBox = ush.interiorbbox(Time+ShTStep,Level,c);
00099       Coords& Os = OpBox.stepsize();
00100       Coords Os2 = Os/2;
00101 
00102       for_3 (n, m, l, OpBox, Os)
00103         FastIndex3(ush,n,m,l) = fabs(FastIndex3(ush,n,m,l));
00104         if (FastIndex3(ush,n,m,l) >= Tol) { 
00105           FastIndex3(Flags,n       ,m       ,l       ) = FlagValue;
00106           FastIndex3(Flags,n+Os2(0),m       ,l       ) = FlagValue; 
00107           FastIndex3(Flags,n       ,m+Os2(1),l       ) = FlagValue; 
00108           FastIndex3(Flags,n+Os2(0),m+Os2(1),l       ) = FlagValue; 
00109           FastIndex3(Flags,n       ,m       ,l+Os2(2)) = FlagValue;
00110           FastIndex3(Flags,n+Os2(0),m       ,l+Os2(2)) = FlagValue; 
00111           FastIndex3(Flags,n       ,m+Os2(1),l+Os2(2)) = FlagValue; 
00112           FastIndex3(Flags,n+Os2(0),m+Os2(1),l+Os2(2)) = FlagValue; 
00113         }
00114       end_for
00115 
00116       EndFastIndex3(ush);
00117       EndFastIndex3(Flags);
00118     end_forall
00119   } 
00120 
00121 };
00122 
00123 
00124 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04