Chombo + EB  3.2
Stencil.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _STENCIL_H_
12 #define _STENCIL_H_
13 
14 #include "ProblemDomain.H"
15 #include <map>
16 
17 //
18 // Classes general stencil object. Classes StencilTensor are the classes defined
19 // here along with helper classes for stencil nodes and for multilevel, multi-block indices (IndexML)
20 //
21 
22 #include "NamespaceHeader.H"
23 
24 //! \class IndexML
25 //! Encapsulate a multilevel index
26 class IndexML
27 {
28 public:
29  IndexML() : m_lev(0), m_blockID(0)
30  {
31  }
32  IndexML(const IndexML &a_ml) : m_iv(a_ml.m_iv), m_lev(a_ml.m_lev), m_blockID(0)
33  {
34  }
35  IndexML(IntVect a_iv,short a_lev) : m_iv(a_iv), m_lev(a_lev), m_blockID(0)
36  {
37  }
38  void define(IntVect a_iv,short a_lev, short a_blockid=0)
39  {
40  m_lev = a_lev; m_iv = a_iv; m_blockID = a_blockid;
41  }
42  bool operator== (const IndexML& p) const;
43  bool operator!= (const IndexML& p) const;
44  bool operator> (const IndexML& p) const;
45  bool operator< (const IndexML& p) const;
46  short level() const {return m_lev;}
47  IntVect iv()const{return m_iv;}
48  short block()const{return m_blockID;}
49  void setIV(IntVect a_iv){m_iv = a_iv;}
50  void setLevel(short a_lev){m_lev = a_lev;}
51  void setBlock(short a_bid){m_blockID = a_bid;}
52  // Print the IndexML to given output stream in ASCII.
53  friend std::ostream& operator<< (std::ostream& os,
54  const IndexML& iv);
55 protected:
57  short m_lev;
58  short m_blockID;
59 };
60 
61 #define STENCIL_MAX_DOF 3
62 #define CHECK_DOF if (m_dof<=0) MayDay::Abort("StencilTensorValue dot defined");
63 //! \class StencilTensorValue
64 //! a 2x2 array class
66 {
67 public:
68  StencilTensorValue(int a_dof=-1) : m_dof(a_dof)
69  {
70  if (m_dof > STENCIL_MAX_DOF) MayDay::Abort("StencilTensorValue::StencilTensorValue dof > MAX");
71  if (a_dof>0) for (int i=0;i<m_dof*m_dof;i++) m_val[i]=0.;
72  }
73  void define(int a_dof) {
74  if (a_dof > STENCIL_MAX_DOF) MayDay::Abort("StencilTensorValue::define dof > MAX");
75  if (a_dof <= 0) MayDay::Abort("StencilTensorValue::define dof <= 0");
76  if (m_dof==-1) for (int i=0;i<a_dof*a_dof;i++) m_val[i]=0.;
77  m_dof = a_dof;
78  }
79  void define(StencilTensorValue &a_sv) {
80  define(a_sv.m_dof);
81  }
82  bool isDefined() const{return (m_dof > 0);}
83  StencilTensorValue& operator= (const StencilTensorValue& p) { // a definer
84  if (m_dof==-1) m_dof = p.m_dof;
85  if (p.m_dof != m_dof) MayDay::Abort("StencilTensorValue::operator= DOF mismatch");
86  for (int i=0;i<m_dof*m_dof;i++) m_val[i] = p.m_val[i];
87  return *this;
88  }
89  Real value(int a_idof, int a_jdof) const {CHECK_DOF; return m_val[a_idof*m_dof + a_jdof];}
90  const Real *getVals() const {CHECK_DOF; return m_val;}
91  void addValue(int a_idof, int a_jdof, Real a_val) { CHECK_DOF; m_val[a_idof*m_dof + a_jdof] += a_val; }
92  void setValue(int a_idof, int a_jdof, Real a_val) { CHECK_DOF; m_val[a_idof*m_dof + a_jdof] = a_val; }
93  void apply(StencilTensorValue &a_scale, StencilTensorValue &a_node);
94  // scalar helpers,
95  void addValue(Real a_val) { CHECK_DOF; for (int i=0;i<m_dof;i++) m_val[i*m_dof + i] += a_val; }
96  void setValue(Real a_val) { CHECK_DOF; for (int i=0;i<m_dof;i++) m_val[i*m_dof + i] = a_val; }
97  // void axpy(Real a_alpha, StencilTensorValue &a_node) {
98  // CHECK_DOF;
99  // if (a_node.m_dof != m_dof) MayDay::Abort("StencilTensorValue::axpy DOF mismatch");
100  // for (int i=0;i<m_dof*m_dof;i++) m_val[i] += a_alpha*a_node.m_val[i];
101  // }
102  void scale(Real a_alpha) {
103  CHECK_DOF;
104  for (int i=0;i<m_dof*m_dof;i++) m_val[i] *= a_alpha;
105  }
106  // Print the StencilTensorValue to given output stream in ASCII.
107  friend std::ostream& operator<< (std::ostream& os,
108  const StencilTensorValue& iv);
109 protected:
110  int m_dof;
112 };
113 
114 //! \class StencilScalarValue
115 //! a real array class
116 // class StencilScalarValue
117 // {
118 // public:
119 // StencilScalarValue(int a_dof=-1) : m_val(0.)
120 // {}
121 // Real value() const {return m_val;}
122 // void addValue(Real a_val) { m_val += a_val; }
123 // void setValue(Real a_val) { m_val = a_val; }
124 // void axpy(Real a_alpha, StencilScalarValue &a_node) {
125 // MayDay::Abort("StencilScalarValue::axpy Used????");
126 // m_val += a_alpha*a_node.m_val;
127 // }
128 // void scale(Real a_alpha) { m_val *= a_alpha; }
129 // StencilScalarValue& operator= (const StencilScalarValue& p);
130 // // Print the StencilScalarValue to given output stream in ASCII.
131 // friend std::ostream& operator<< (std::ostream& os,
132 // const StencilScalarValue& iv);
133 // protected:
134 // Real m_val;
135 // };
136 
137 typedef std::map<IndexML,StencilTensorValue > StencilTensor;
138 // typedef std::pair<IndexML,StencilScalarValue > StenScalarNode;
139 typedef std::pair<IndexML,StencilTensorValue > StencilNode;
140 // typedef std::map<IndexML,StencilScalarValue > StencilScalar;
141 
142 // algebra
143 
144 // a_sten += a_new*a_sten[jiv]. "distributes" a_sten[jiv] with a_new. Would like to remove a_sten[jiv] but that messes up iterators.
145 void StencilProject(IndexML jiv, Vector<StencilNode> &a_new, StencilTensor &a_sten);
146 
147 #include "NamespaceFooter.H"
148 
149 #endif
void setBlock(short a_bid)
Definition: Stencil.H:51
Real m_val[STENCIL_MAX_DOF *STENCIL_MAX_DOF]
Definition: Stencil.H:111
std::pair< IndexML, StencilTensorValue > StencilNode
Definition: Stencil.H:139
void scale(Real a_alpha)
Definition: Stencil.H:102
one dimensional dynamic array
Definition: Vector.H:53
Definition: Stencil.H:65
short level() const
Definition: Stencil.H:46
void setLevel(short a_lev)
Definition: Stencil.H:50
void addValue(Real a_val)
Definition: Stencil.H:95
bool operator>(const IndexML &p) const
#define CHECK_DOF
Definition: Stencil.H:62
std::map< IndexML, StencilTensorValue > StencilTensor
Definition: Stencil.H:137
IndexML()
Definition: Stencil.H:29
void StencilProject(IndexML jiv, Vector< StencilNode > &a_new, StencilTensor &a_sten)
bool operator==(const IndexML &p) const
short m_blockID
Definition: Stencil.H:58
bool operator<(const IndexML &p) const
const Real * getVals() const
Definition: Stencil.H:90
short m_lev
Definition: Stencil.H:57
IntVect iv() const
Definition: Stencil.H:47
StencilTensorValue(int a_dof=-1)
Definition: Stencil.H:68
bool isDefined() const
Definition: Stencil.H:82
void setIV(IntVect a_iv)
Definition: Stencil.H:49
short block() const
Definition: Stencil.H:48
IntVect m_iv
Definition: Stencil.H:56
double Real
Definition: REAL.H:33
Definition: Stencil.H:26
#define STENCIL_MAX_DOF
Definition: Stencil.H:61
int m_dof
Definition: Stencil.H:110
IndexML(IntVect a_iv, short a_lev)
Definition: Stencil.H:35
IndexML(const IndexML &a_ml)
Definition: Stencil.H:32
void define(IntVect a_iv, short a_lev, short a_blockid=0)
Definition: Stencil.H:38
void addValue(int a_idof, int a_jdof, Real a_val)
Definition: Stencil.H:91
void define(int a_dof)
Definition: Stencil.H:73
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
bool operator!=(const IndexML &p) const
Real value(int a_idof, int a_jdof) const
Definition: Stencil.H:89
void setValue(int a_idof, int a_jdof, Real a_val)
Definition: Stencil.H:92
void setValue(Real a_val)
Definition: Stencil.H:96
void define(StencilTensorValue &a_sv)
Definition: Stencil.H:79
friend std::ostream & operator<<(std::ostream &os, const IndexML &iv)
static void Abort(const char *const a_msg=m_nullString)
Print out message to cerr and exit via abort() (if serial) or MPI_Abort() (if parallel).