Nektar++
DBUtils.hpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File DBUtils.hpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: output function for use in debugging
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_LIBUTILITIES_DBUTILS_HPP
37 #define NEKTAR_LIB_LIBUTILITIES_DBUTILS_HPP
38 
40 
41 using namespace std;
42 
43 namespace DBUtils
44 {
45  using namespace Nektar;
46  const int StopDefault = -99;
47 
48  template<class T> void Output1DArray(const Array<OneD, const T> &in, const int start = 0,
49  const int stop = StopDefault)
50  {
51  int i;
52 
53  ASSERTL1(start < in.num_elements(), "Start value is outside array range ");
54 
55  if(stop == StopDefault)
56  {
57 
58  for(i = start; i < in.num_elements(); ++i)
59  {
60  cout << in[i] << endl;
61  }
62  }
63  else
64  {
65  ASSERTL1(stop <= in.num_elements(), "Stop value is outside array range ");
66 
67  for(i = start; i < stop; ++i)
68  {
69  cout << in[i] << endl;
70  }
71  }
72  }
73 
74  template<class T> void Output1DArray(const Array<OneD, const T> &in, std::string outfile,
75  const int start = 0,
76  const int stop = StopDefault)
77  {
78  int i;
79 
80  ASSERTL1(start < in.num_elements(), "Start value is outside array range ");
81 
82  ofstream ofile(outfile.c_str());
83 
84  if(stop == StopDefault)
85  {
86 
87  for(i = start; i < in.num_elements(); ++i)
88  {
89  ofile << in[i] << endl;
90  }
91  }
92  else
93  {
94  ASSERTL1(stop <= in.num_elements(), "Stop value is outside array range ");
95 
96  for(i = start; i < stop; ++i)
97  {
98  ofile << in[i] << endl;
99  }
100  }
101 
102  }
103 
104  template<class T> void Output1DArray(const Array<OneD, const T> &in, ofstream &ofile,
105  const int start = 0,
106  const int stop = StopDefault)
107  {
108  int i;
109 
110  ASSERTL1(start < in.num_elements(), "Start value is outside array range ");
111 
112  if(stop == StopDefault)
113  {
114 
115  for(i = start; i < in.num_elements(); ++i)
116  {
117  ofile << in[i] << endl;
118  }
119  }
120  else
121  {
122  ASSERTL1(stop <= in.num_elements(), "Stop value is outside array range ");
123 
124  for(i = start; i < stop; ++i)
125  {
126  ofile << in[i] << endl;
127  }
128  }
129 
130  }
131 
132  template<class T> void Output1DArray(const NekVector<T> &in, ofstream &ofile,
133  const int start = 0,
134  const int stop = StopDefault)
135  {
136  int i;
137 
138  ASSERTL1(start < in.GetDimension(), "Start value is outside array range ");
139 
140  if(stop == StopDefault)
141  {
142 
143  for(i = start; i < in.GetDimension(); ++i)
144  {
145  ofile << in[i] << endl;
146  }
147  }
148  else
149  {
150  ASSERTL1(stop <= in.GetDimension(), "Stop value is outside array range ");
151 
152  for(i = start; i < stop; ++i)
153  {
154  ofile << in[i] << endl;
155  }
156  }
157  }
158 
159  template<class T> void NormGlobalVector(
160  const int n,
162  std::ostream &out,
164  {
165  Array<OneD, NekDouble> vExchange(1);
166  Array<OneD, int> m_map = map->GetGlobalToUniversalMapUnique();
167  vExchange[0] = Vmath::Dot2(n, in, in, m_map);
168  map->GetComm()->AllReduce(vExchange, Nektar::LibUtilities::ReduceSum);
169  out << "Norm: " << vExchange[0] << endl;
170  }
171 }
172 #endif
STL namespace.
const int StopDefault
Definition: DBUtils.hpp:46
void NormGlobalVector(const int n, Array< OneD, const T > &in, std::ostream &out, MultiRegions::AssemblyMapCGSharedPtr &map)
Definition: DBUtils.hpp:159
unsigned int GetDimension() const
Returns the number of dimensions for the point.
Definition: NekVector.cpp:212
void Output1DArray(const NekVector< T > &in, ofstream &ofile, const int start=0, const int stop=StopDefault)
Definition: DBUtils.hpp:132
T Dot2(int n, const T *w, const T *x, const int *y)
vvtvp (vector times vector times vector): z = w*x*y
Definition: Vmath.cpp:931
boost::shared_ptr< AssemblyMapCG > AssemblyMapCGSharedPtr
Definition: AssemblyMapCG.h:52
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:191