00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _STENCIL_H_
00012 #define _STENCIL_H_
00013
00014 #include "ProblemDomain.H"
00015 #include <map>
00016
00017
00018
00019
00020
00021
00022 #include "NamespaceHeader.H"
00023
00024
00025
00026 class IndexML
00027 {
00028 public:
00029 IndexML() : m_lev(0), m_blockID(0)
00030 {
00031 }
00032 IndexML(const IndexML &a_ml) : m_iv(a_ml.m_iv), m_lev(a_ml.m_lev), m_blockID(0)
00033 {
00034 }
00035 IndexML(IntVect a_iv,short a_lev) : m_iv(a_iv), m_lev(a_lev), m_blockID(0)
00036 {
00037 }
00038 void define(IntVect a_iv,short a_lev, short a_blockid=0)
00039 {
00040 m_lev = a_lev; m_iv = a_iv; m_blockID = a_blockid;
00041 }
00042 bool operator== (const IndexML& p) const;
00043 bool operator!= (const IndexML& p) const;
00044 bool operator> (const IndexML& p) const;
00045 bool operator< (const IndexML& p) const;
00046 short level() const {return m_lev;}
00047 IntVect iv()const{return m_iv;}
00048 short block()const{return m_blockID;}
00049 void setIV(IntVect a_iv){m_iv = a_iv;}
00050 void setLevel(short a_lev){m_lev = a_lev;}
00051 void setBlock(short a_bid){m_blockID = a_bid;}
00052
00053 friend std::ostream& operator<< (std::ostream& os,
00054 const IndexML& iv);
00055 protected:
00056 IntVect m_iv;
00057 short m_lev;
00058 short m_blockID;
00059 };
00060
00061 #define STENCIL_MAX_DOF 3
00062 #define CHECK_DOF if (m_dof<=0) MayDay::Abort("StencilTensorValue dot defined");
00063
00064
00065 class StencilTensorValue
00066 {
00067 public:
00068 StencilTensorValue(int a_dof=-1) : m_dof(a_dof)
00069 {
00070 if (m_dof > STENCIL_MAX_DOF) MayDay::Abort("StencilTensorValue::StencilTensorValue dof > MAX");
00071 if (a_dof>0) for (int i=0;i<m_dof*m_dof;i++) m_val[i]=0.;
00072 }
00073 void define(int a_dof) {
00074 if (a_dof > STENCIL_MAX_DOF) MayDay::Abort("StencilTensorValue::define dof > MAX");
00075 if (a_dof <= 0) MayDay::Abort("StencilTensorValue::define dof <= 0");
00076 if (m_dof==-1) for (int i=0;i<a_dof*a_dof;i++) m_val[i]=0.;
00077 m_dof = a_dof;
00078 }
00079 void define(StencilTensorValue &a_sv) {
00080 define(a_sv.m_dof);
00081 }
00082 bool isDefined() const{return (m_dof > 0);}
00083 StencilTensorValue& operator= (const StencilTensorValue& p) {
00084 if (m_dof==-1) m_dof = p.m_dof;
00085 if (p.m_dof != m_dof) MayDay::Abort("StencilTensorValue::operator= DOF mismatch");
00086 for (int i=0;i<m_dof*m_dof;i++) m_val[i] = p.m_val[i];
00087 return *this;
00088 }
00089 Real value(int a_idof, int a_jdof) const {CHECK_DOF; return m_val[a_idof*m_dof + a_jdof];}
00090 const Real *getVals() const {CHECK_DOF; return m_val;}
00091 void addValue(int a_idof, int a_jdof, Real a_val) { CHECK_DOF; m_val[a_idof*m_dof + a_jdof] += a_val; }
00092 void setValue(int a_idof, int a_jdof, Real a_val) { CHECK_DOF; m_val[a_idof*m_dof + a_jdof] = a_val; }
00093 void apply(StencilTensorValue &a_scale, StencilTensorValue &a_node);
00094
00095 void addValue(Real a_val) { CHECK_DOF; for (int i=0;i<m_dof;i++) m_val[i*m_dof + i] += a_val; }
00096 void setValue(Real a_val) { CHECK_DOF; for (int i=0;i<m_dof;i++) m_val[i*m_dof + i] = a_val; }
00097
00098
00099
00100
00101
00102 void scale(Real a_alpha) {
00103 CHECK_DOF;
00104 for (int i=0;i<m_dof*m_dof;i++) m_val[i] *= a_alpha;
00105 }
00106
00107 friend std::ostream& operator<< (std::ostream& os,
00108 const StencilTensorValue& iv);
00109 protected:
00110 int m_dof;
00111 Real m_val[STENCIL_MAX_DOF*STENCIL_MAX_DOF];
00112 };
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 typedef std::map<IndexML,StencilTensorValue > StencilTensor;
00138
00139 typedef std::pair<IndexML,StencilTensorValue > StencilNode;
00140
00141
00142
00143
00144
00145 void StencilProject(IndexML jiv, Vector<StencilNode> &a_new, StencilTensor &a_sten);
00146
00147 #include "NamespaceFooter.H"
00148
00149 #endif