vtf-logo

ByValue.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2003-2007 California Institute of Technology
00004 // Ralf Deiterding, ralf@amroc.net
00005 
00006 #ifndef AMROC_BYVALUE_H
00007 #define AMROC_BYVALUE_H
00008 
00015 #include "StdCriterion.h"
00016 
00023 template <class VectorType, class FlagType, int dim>
00024 class ByValue : 
00025   public StdCriterion<VectorType,FlagType,dim> {
00026   typedef typename VectorType::InternalDataType DataType;
00027   typedef StdCriterion<VectorType,FlagType,dim> base;
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::flag_fct_type flag_fct_type;
00032   typedef typename base::max_vector_type max_vector_type;
00033 
00034   ByValue() : base() {
00035     base::SetShadowCriterion(false);
00036     Tol = static_cast<DataType>(0.0);
00037     for (register int i=0; i<MAXCOMPONENTS; i++)
00038       _Comparison[i] = 0;
00039   }
00040 
00041   virtual ~ByValue() {}
00042 
00043   virtual void register_at(ControlDevice& Ctrl) {}
00044   virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00045     base::LocCtrl = Ctrl.getSubDevice(prefix+"ByValue");
00046     char Name[16];
00047     for (int d=0; d<max_vector_type::Length(); d++) {
00048       std::sprintf(Name,"Tol(%d)",d+1);
00049       RegisterAt(base::LocCtrl,Name,Tol(d));
00050       std::sprintf(Name,"MaxLev(%d)",d+1);
00051       RegisterAt(base::LocCtrl,Name,base::_MaxLevel[d]);
00052       std::sprintf(Name,"Type(%d)",d+1);
00053       RegisterAt(base::LocCtrl,Name,_Comparison[d]);
00054     }    
00055     RegisterAt(base::LocCtrl,"Output",base::_Output);
00056   }
00057 
00058   virtual void update() { 
00059     int d=max_vector_type::Length();
00060     for (; d>0; d--) 
00061       if (Tol(d-1) > static_cast<DataType>(0.0)) 
00062         break;
00063     if (d>0) {
00064       base::SetNcnt(d);
00065       base::SetIsUsed(true);
00066     }
00067     else 
00068       base::SetIsUsed(false);
00069   }
00070 
00071   virtual bool SetFlags(vec_grid_fct_type& u, grid_fct_type& work, flag_fct_type& flags, 
00072                         const int& cnt, const int& Time, const int& Level, const double& t, 
00073                         const FlagType& FlagValue) {
00074     if (Tol(cnt) <= 0.0) return false;
00075     int TStep = TimeStep(work,Level);
00076     if (base::MaxLevel(cnt)<Level && base::MaxLevel(cnt)>=0) {
00077       if (base::OutputFlags()) {
00078         forall(work,Time,Level,c)
00079           work(Time+TStep,Level,c) = static_cast<DataType>(0.0);
00080         end_forall 
00081       }
00082       return true;
00083     }
00084 
00085     forall(work,Time+TStep,Level,c)
00086       equals_from(work(Time+TStep,Level,c), u(Time,Level,c), cnt);
00087     end_forall 
00088     base::FlagByValue(work, flags, Time, Level, Tol(cnt), FlagValue, _Comparison[cnt]);
00089     return true;
00090   }
00091 
00092   virtual void OutputName(char* name, int cnt) { std::sprintf(name,"value_%d",cnt+1); }
00093 
00094   max_vector_type Tol;
00095   int _Comparison[MAXCOMPONENTS];
00096 };
00097 
00098 #endif

Generated on Fri Aug 24 13:00:47 2007 for AMROC Fluid-solver Framework - by  doxygen 1.4.7