00001
00002
00003
00004
00005
00006 #ifndef SCHEME_BOUNDARY_CONDITIONS_H
00007 #define SCHEME_BOUNDARY_CONDITIONS_H
00008
00015 #include "BoundaryConditions.h"
00016
00017 template <class DataType>
00018 class BCSide : public controlable {
00019 public:
00020 BCSide(const int maxaux) : Type(-1), Scaling(0), NAux(0), MaxAux(maxaux)
00021 { aux = new DataType[MaxAux]; }
00022
00023 ~BCSide() { delete [] aux; }
00024
00025 virtual void register_at(ControlDevice& Ctrl) {}
00026 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00027 LocCtrl = Ctrl.getSubDevice(prefix+"Side");
00028 RegisterAt(LocCtrl,"Type",Type);
00029 RegisterAt(LocCtrl,"Scaling",Scaling);
00030 RegisterAt(LocCtrl,"NAux",NAux);
00031 char VariableName[16];
00032 for (int i=0; i<MaxAux; i++) {
00033 aux[i]=DataType(0.);
00034 std::sprintf(VariableName,"Aux(%d)",i+1);
00035 RegisterAt(LocCtrl,VariableName,aux[i]);
00036 }
00037 }
00038
00039 public:
00040 int Type, Scaling, NAux, MaxAux;
00041 DataType *aux;
00042 ControlDevice LocCtrl;
00043 };
00044
00051 template <class SchemeType, int dim>
00052 class SchemeBoundaryConditions : public BoundaryConditions<typename SchemeType::VectorType,dim> {
00053 typedef BoundaryConditions<typename SchemeType::VectorType,dim> base;
00054 public:
00055 typedef typename SchemeType::VectorType VectorType;
00056 typedef typename VectorType::InternalDataType DataType;
00057 typedef typename base::vec_grid_data_type vec_grid_data_type;
00058 typedef typename SchemeType::SideName SideName;
00059
00060 SchemeBoundaryConditions(SchemeType &scheme) : base(), _scheme(scheme) {
00061 for (int d=0; d<2*dim; d++)
00062 side[d] = new BCSide<DataType>(Scheme().NEquations());
00063 }
00064
00065 ~SchemeBoundaryConditions() {
00066 for (int d=0; d<2*dim; d++)
00067 delete side[d];
00068 }
00069
00070 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00071 base::LocCtrl = Ctrl.getSubDevice(prefix+"BoundaryConditions");
00072 side[0]->register_at(base::LocCtrl,"Left");
00073 side[1]->register_at(base::LocCtrl,"Right");
00074 if (dim>1) {
00075 side[2]->register_at(base::LocCtrl,"Bottom");
00076 side[3]->register_at(base::LocCtrl,"Top");
00077 }
00078 if (dim>2) {
00079 side[4]->register_at(base::LocCtrl,"Front");
00080 side[5]->register_at(base::LocCtrl,"Back");
00081 }
00082 }
00083
00084 virtual void SetBndry(vec_grid_data_type &fvec, const int& level, const BBox &bb,
00085 const int &dir, const double& time) {
00086
00087 BBox wholebbox = base::GH().wholebbox();
00088 if (dir==SchemeType::Left && bb.upper(0)+bb.stepsize(0)==wholebbox.lower(0))
00089 Scheme().BCStandard(fvec,bb,side[0]->Type,dir,side[0]->aux,side[0]->NAux,side[0]->Scaling);
00090 else if (dir==SchemeType::Right && bb.lower(0)==wholebbox.upper(0)+wholebbox.stepsize(0))
00091 Scheme().BCStandard(fvec,bb,side[1]->Type,dir,side[1]->aux,side[1]->NAux,side[1]->Scaling);
00092 else if (dir==SchemeType::Bottom && bb.upper(1)+bb.stepsize(1)==wholebbox.lower(1))
00093 Scheme().BCStandard(fvec,bb,side[2]->Type,dir,side[2]->aux,side[2]->NAux,side[2]->Scaling);
00094 else if (dir==SchemeType::Top && bb.lower(1)==wholebbox.upper(1)+wholebbox.stepsize(1))
00095 Scheme().BCStandard(fvec,bb,side[3]->Type,dir,side[3]->aux,side[3]->NAux,side[3]->Scaling);
00096 else if (dir==SchemeType::Front && bb.upper(2)+bb.stepsize(2)==wholebbox.lower(2))
00097 Scheme().BCStandard(fvec,bb,side[4]->Type,dir,side[4]->aux,side[4]->NAux,side[4]->Scaling);
00098 else if (dir==SchemeType::Back && bb.lower(2)==wholebbox.upper(2)+wholebbox.stepsize(2))
00099 Scheme().BCStandard(fvec,bb,side[5]->Type,dir,side[5]->aux,side[5]->NAux,side[5]->Scaling);
00100 }
00101
00102 inline SchemeType& Scheme() { return _scheme; }
00103 inline const SchemeType& Scheme() const { return _scheme; }
00104
00105 inline const BCSide<DataType>& Side(const int d) const { return *side[d]; }
00106
00107 protected:
00108 SchemeType &_scheme;
00109 BCSide<DataType> *side[2*dim];
00110 };
00111
00112
00113 #endif