00001
00002
00003
00004
00005
00006 #ifndef AMROC_REGIONS_H
00007 #define AMROC_REGIONS_H
00008
00015 #include "StdCriterion.h"
00016
00017 #define MAXREGIONS (100)
00018
00025 template <class VectorType, class FlagType, int dim>
00026 class FlagRegions :
00027 public StdCriterion<VectorType,FlagType,dim> {
00028 typedef typename VectorType::InternalDataType DataType;
00029 typedef StdCriterion<VectorType,FlagType,dim> base;
00030 public:
00031 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00032 typedef typename base::grid_fct_type grid_fct_type;
00033 typedef typename base::flag_fct_type flag_fct_type;
00034
00035 FlagRegions() : base(), NRegions(0) {
00036 base::SetShadowCriterion(false);
00037 for (int i=0; i<MAXREGIONS; i++) {
00038 rmin[i] = DCoords(dim,1.e37);
00039 rmax[i] = DCoords(dim,-1.e37);
00040 rlev[i] = 10000;
00041 }
00042 base::_Ncnt = 1;
00043 }
00044
00045 virtual ~FlagRegions() {}
00046
00047 virtual void register_at(ControlDevice& Ctrl) {}
00048 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00049 base::LocCtrl = Ctrl.getSubDevice(prefix+"FlagRegions");
00050 RegisterAt(base::LocCtrl,"Regions",NRegions);
00051 char Name[24];
00052 for (int i=0; i<MAXREGIONS; i++) {
00053 for (int d=0; d<dim; d++) {
00054 std::sprintf(Name,"RCoords(%d,1,%d)",i+1,d+1);
00055 RegisterAt(base::LocCtrl,Name,rmin[i](d));
00056 std::sprintf(Name,"RCoords(%d,2,%d)",i+1,d+1);
00057 RegisterAt(base::LocCtrl,Name,rmax[i](d));
00058 std::sprintf(Name,"MaxLev(%d)",i+1);
00059 RegisterAt(base::LocCtrl,Name,rlev[i]);
00060 }
00061 }
00062 }
00063
00064 virtual void update() {
00065 base::SetIsUsed(false);
00066 if (NRegions>MAXREGIONS) NRegions=MAXREGIONS;
00067 for (int i=0; i<NRegions; i++) {
00068 int d=0;
00069 for (; d<dim; d++)
00070 if (rmin[i](d)>=rmax[i](d)) break;
00071 if (d>=dim) {
00072 base::SetIsUsed(true);
00073 break;
00074 }
00075 }
00076 }
00077
00078 virtual bool SetFlags(vec_grid_fct_type& u, grid_fct_type& work, flag_fct_type& flags,
00079 const int& cnt, const int& Time, const int& Level, const double& t,
00080 const FlagType& FlagValue) {
00081 if (NRegions <= 0) return false;
00082 for (int i=0; i<NRegions; i++)
00083 if (Level<=rlev[i]) {
00084 BBox bbox(base::GH().localCoords(rmin[i]),base::GH().localCoords(rmax[i]),1);
00085 if (bbox.empty()) continue;
00086 bbox.coarsen(StepSize(base::GH(),Level));
00087 forall (flags,Time,Level,c)
00088 flags(Time,Level,c).equals(FlagValue, bbox);
00089 end_forall
00090 }
00091 return true;
00092 }
00093
00094 virtual void OutputName(char* name, int cnt) { std::sprintf(name,"flagregion_%d",cnt+1); }
00095
00096 int NRegions;
00097 DCoords rmin[MAXREGIONS], rmax[MAXREGIONS];
00098 int rlev[MAXREGIONS];
00099 };
00100
00101
00108 template <class VectorType, class FlagType, int dim>
00109 class UnflagRegions :
00110 public StdCriterion<VectorType,FlagType,dim> {
00111 typedef typename VectorType::InternalDataType DataType;
00112 typedef StdCriterion<VectorType,FlagType,dim> base;
00113 public:
00114 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00115 typedef typename base::grid_fct_type grid_fct_type;
00116 typedef typename base::flag_fct_type flag_fct_type;
00117
00118 UnflagRegions() : base(), NRegions(0), NERegions(0) {
00119 base::SetShadowCriterion(false);
00120 for (int i=0; i<MAXREGIONS; i++) {
00121 rmin[i] = DCoords(dim,1.e37);
00122 rmax[i] = DCoords(dim,-1.e37);
00123 rlev[i] = -1;
00124 remin[i] = DCoords(dim,1.e37);
00125 remax[i] = DCoords(dim,-1.e37);
00126 relev[i] = -1;
00127 }
00128 base::_Ncnt = 1;
00129 }
00130
00131 virtual ~UnflagRegions() {}
00132
00133 virtual void register_at(ControlDevice& Ctrl) {}
00134 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00135 base::LocCtrl = Ctrl.getSubDevice(prefix+"UnflagRegions");
00136 RegisterAt(base::LocCtrl,"Regions",NRegions);
00137 char Name[24];
00138 for (int i=0; i<MAXREGIONS; i++) {
00139 for (int d=0; d<dim; d++) {
00140 std::sprintf(Name,"RCoords(%d,1,%d)",i+1,d+1);
00141 RegisterAt(base::LocCtrl,Name,rmin[i](d));
00142 std::sprintf(Name,"RCoords(%d,2,%d)",i+1,d+1);
00143 RegisterAt(base::LocCtrl,Name,rmax[i](d));
00144 std::sprintf(Name,"MinLev(%d)",i+1);
00145 RegisterAt(base::LocCtrl,Name,rlev[i]);
00146 }
00147 }
00148 base::LocCtrl = Ctrl.getSubDevice(prefix+"UnflagExceptRegions");
00149 RegisterAt(base::LocCtrl,"Regions",NERegions);
00150 for (int i=0; i<MAXREGIONS; i++) {
00151 for (int d=0; d<dim; d++) {
00152 std::sprintf(Name,"RCoords(%d,1,%d)",i+1,d+1);
00153 RegisterAt(base::LocCtrl,Name,remin[i](d));
00154 std::sprintf(Name,"RCoords(%d,2,%d)",i+1,d+1);
00155 RegisterAt(base::LocCtrl,Name,remax[i](d));
00156 std::sprintf(Name,"MinLev(%d)",i+1);
00157 RegisterAt(base::LocCtrl,Name,relev[i]);
00158 }
00159 }
00160 }
00161
00162 virtual void update() {
00163 base::SetIsUsed(false);
00164 if (NRegions>MAXREGIONS) NRegions=MAXREGIONS;
00165 for (int i=0; i<NRegions; i++) {
00166 int d=0;
00167 for (; d<dim; d++)
00168 if (rmin[i](d)>=rmax[i](d)) break;
00169 if (d>=dim) {
00170 base::SetIsUsed(true);
00171 break;
00172 }
00173 }
00174 if (NERegions>MAXREGIONS) NERegions=MAXREGIONS;
00175 for (int i=0; i<NERegions; i++) {
00176 int d=0;
00177 for (; d<dim; d++)
00178 if (remin[i](d)>=remax[i](d)) break;
00179 if (d>=dim) {
00180 base::SetIsUsed(true);
00181 break;
00182 }
00183 }
00184 }
00185
00186 virtual bool SetFlags(vec_grid_fct_type& u, grid_fct_type& work, flag_fct_type& flags,
00187 const int& cnt, const int& Time, const int& Level, const double& t,
00188 const FlagType& FlagValue) {
00189 if (!base::IsUsed()) return false;
00190 if (NERegions > 0) {
00191 BBoxList bbl_preserve;
00192 for (int i=0; i<NRegions; i++)
00193 if (Level>=relev[i]) {
00194 BBox bbox(base::GH().localCoords(remin[i]),base::GH().localCoords(remax[i]),1);
00195 if (bbox.empty()) continue;
00196 bbox.coarsen(StepSize(base::GH(),Level));
00197 bbl_preserve.add(bbox);
00198 }
00199 if (!bbl_preserve.isempty()) {
00200 forall (flags,Time,Level,c)
00201 BBoxList bbf;
00202 bbf.add(flags.interiorbbox(Time,Level,c));
00203 bbf -= bbl_preserve;
00204 for (BBox *bb = bbf.first();bb;bb=bbf.next())
00205 flags(Time,Level,c).equals(GoodPoint, *bb);
00206 end_forall
00207 }
00208 }
00209 if (NRegions > 0)
00210 for (int i=0; i<NRegions; i++)
00211 if (Level>=rlev[i]) {
00212 BBox bbox(base::GH().localCoords(rmin[i]),base::GH().localCoords(rmax[i]),1);
00213 if (bbox.empty()) continue;
00214 bbox.coarsen(StepSize(base::GH(),Level));
00215 forall (flags,Time,Level,c)
00216 flags(Time,Level,c).equals(GoodPoint, bbox);
00217 end_forall
00218 }
00219 return true;
00220 }
00221
00222 virtual void OutputName(char* name, int cnt) { std::sprintf(name,"unflagregion_%d",cnt+1); }
00223
00224 int NRegions, NERegions;
00225 DCoords rmin[MAXREGIONS], rmax[MAXREGIONS], remin[MAXREGIONS], remax[MAXREGIONS];
00226 int rlev[MAXREGIONS], relev[MAXREGIONS];
00227 };
00228
00229 #endif