Chombo + EB  3.0
CoordinateSystemImplem.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 _COORDINATESYSTEMIMPLEM_H_
12 #define _COORDINATESYSTEMIMPLEM_H_
13 
14 #if defined(CH_Darwin) && defined(__GNUC__) && ( __GNUC__ == 3 )
15 // deal with the broken isnan()/isinf() in GCC on MacOS
16 #include <unistd.h>
17 #define _GLIBCPP_USE_C99 1
18 #endif
19 
20 #include <iostream>
21 #include <iomanip>
22 
23 #include "NamespaceHeader.H"
24 // empty constructor
26 {
27 }
28 
29 template <int dim> CoordinateSystem<dim>::CoordinateSystem(const CoordinateSystem<dim>& a_coordinateSystem)
30  :m_origin(a_coordinateSystem.m_origin),
31  m_dx(a_coordinateSystem.m_dx)
32 {
33 }
34 
35 // Constructor from an origin and a dx
36 template <int dim> CoordinateSystem<dim>::CoordinateSystem( const RvDim & a_origin,
37  const RvDim & a_dx)
38  :m_origin(a_origin),
39  m_dx(a_dx)
40 {
41 }
42 
44  const int & a_idir)
45 {
46  CH_TIME("CoordinateSystem::ConstructorReduceInfo");
47  for (int idir = 0; idir < dim; ++idir)
48  {
49  if (idir < a_idir)
50  {
51  m_origin[idir] = a_hiCoord.m_origin[idir];
52  m_dx[idir] = a_hiCoord.m_dx[idir];
53  }
54  else
55  {
56  m_origin[idir] = a_hiCoord.m_origin[idir + 1];
57  m_dx[idir] = a_hiCoord.m_dx [idir + 1];
58  }
59  }
60 }
61 
62 // Destructor
64 {
65 }
66 
67 template <int dim> IndexTM<Real,dim> CoordinateSystem<dim>::convert(const RvDim & a_point,
68  const CoordinateSystem<dim> & a_system) const
69 {
70  RvDim retval;
71 
72  for (int idir = 0; idir < dim; ++idir)
73  {
74  // If a_point = a_system.m_origin
75  // then retval = m_origin
76  //
77  // If a_point = a_system.m_dx[idir]^-1 + a_system.m_origin
78  // then retval = m_dx[idir]^-1 + m_origin
79 
80  retval[idir] = a_point[idir];
81 
82  retval[idir] -= a_system.m_origin[idir];
83  retval[idir] /= a_system.m_dx [idir];
84  retval[idir] *= m_dx [idir];
85  retval[idir] += m_origin[idir];
86  }
87 
88  return retval;
89 }
90 
91 template <int dim> Real CoordinateSystem<dim>::convertDir(const Real & a_coord,
92  const CoordinateSystem<dim> & a_system,
93  const int & a_dir) const
94 {
95  Real retval;
96 
97  retval = a_coord;
98 
99  retval -= a_system.m_origin[a_dir];
100  retval /= a_system.m_dx [a_dir];
101  retval *= m_dx [a_dir];
102  retval += m_origin[a_dir];
103 
104  return retval;
105 }
106 
107 template <int dim> void CoordinateSystem<dim>::print(ostream& a_out) const
108 {
109  std::ios::fmtflags origFlags = a_out.flags();
110  int origWidth = a_out.width();
111  int origPrecision = a_out.precision();
112 
113  a_out << "origin = "
114  << setprecision(16)
115  << setiosflags(ios::showpoint)
116  << setiosflags(ios::scientific)
117  << m_origin << ", ";
118 
119  a_out << "dx = "
120  << setprecision(16)
121  << setiosflags(ios::showpoint)
122  << setiosflags(ios::scientific)
123  << m_dx << "\n";
124 
125  a_out.flags(origFlags);
126  a_out.width(origWidth);
127  a_out.precision(origPrecision);
128 }
129 
130 template <int dim> ostream& operator<<(ostream & a_out,
131  const CoordinateSystem<dim> & a_coordinateSystem)
132 {
133  a_coordinateSystem.print(a_out);
134  return a_out;
135 }
136 
137 // equals operator
138 template <int dim> void CoordinateSystem<dim>::operator=(const CoordinateSystem & a_coordinateSystem)
139 {
140  m_origin = a_coordinateSystem.m_origin;
141  m_dx = a_coordinateSystem.m_dx;
142 }
143 
144 #include "NamespaceFooter.H"
145 
146 #endif
Real convertDir(const Real &a_coord, const CoordinateSystem< dim > &a_system, const int &a_dir) const
Definition: CoordinateSystemImplem.H:91
Definition: CoordinateSystem.H:34
RvDim m_dx
Definition: CoordinateSystem.H:43
ostream & operator<<(ostream &a_out, const CoordinateSystem< dim > &a_coordinateSystem)
Definition: CoordinateSystemImplem.H:130
#define CH_TIME(name)
Definition: CH_Timer.H:59
RvDim m_origin
Definition: CoordinateSystem.H:42
~CoordinateSystem()
Definition: CoordinateSystemImplem.H:63
double Real
Definition: REAL.H:33
CoordinateSystem()
Definition: CoordinateSystemImplem.H:25
void print(ostream &out) const
Definition: CoordinateSystemImplem.H:107
RvDim convert(const RvDim &a_point, const CoordinateSystem< dim > &a_system) const
Definition: CoordinateSystemImplem.H:67
int dim
Definition: EBInterface.H:146
void operator=(const CoordinateSystem< dim > &a_coordinateSystem)
Definition: CoordinateSystemImplem.H:138