Nektar++
PtsField.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: PtsField.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2014 Kilian Lackhove
10 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
11 // Department of Aeronautics, Imperial College London (UK), and Scientific
12 // Computing and Imaging Institute, University of Utah (USA).
13 //
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: Pts field
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42 namespace LibUtilities
43 {
44 
45 PtsField::PtsField(const int dim,
46  const Array<OneD, Array<OneD, NekDouble> > &pts)
47  : m_dim(dim), m_pts(pts), m_ptsType(ePtsFile)
48 {
49  for (int i = 0; i < GetNFields(); ++i)
50  {
51  m_fieldNames.push_back("NA");
52  }
53 }
54 
55 /**
56  * @brief Set the connectivity data for ePtsTetBlock and ePtsTriBlock
57  *
58  * @param conn Connectivity data
59  * Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with
60  * m elements each, m_ptsConn is a vector of n arrays with 3*m (ePtsTriBlock) or
61  * 4*m (ePtsTetBlock) entries.
62  */
63 void PtsField::GetConnectivity(vector< Array< OneD, int > > &conn) const
64 {
65  conn = m_ptsConn;
66 }
67 
68 /**
69  * @brief Get the connectivity data for ePtsTetBlock and ePtsTriBlock
70  *
71  * @param conn Connectivity data
72  * Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with
73  * m elements each, m_ptsConn is a vector of n arrays with 3*m (ePtsTriBlock) or
74  * 4*m (ePtsTetBlock) entries.
75  */
76 void PtsField::SetConnectivity(const vector< Array< OneD, int > > &conn)
77 {
80  "ptsType must be set before connectivity");
81 
82  m_ptsConn = conn;
83 }
84 
85 void PtsField::SetDim(const int ptsDim)
86 {
87  m_dim = ptsDim;
88 }
89 
90 size_t PtsField::GetDim() const
91 {
92  return m_dim;
93 }
94 
95 size_t PtsField::GetNFields() const
96 {
97  return m_pts.num_elements() - m_dim;
98 }
99 
100 vector<std::string> PtsField::GetFieldNames() const
101 {
102  return m_fieldNames;
103 }
104 
105 std::string PtsField::GetFieldName(const int i) const
106 {
107  return m_fieldNames[i];
108 }
109 
110 void PtsField::SetFieldNames(const vector<std::string> fieldNames)
111 {
112  ASSERTL0(fieldNames.size() == m_pts.num_elements() - m_dim,
113  "Number of given fieldNames does not match the number of stored "
114  "fields");
115 
116  m_fieldNames = fieldNames;
117 }
118 
120  const string fieldName)
121 {
122  size_t nTotvars = m_pts.num_elements();
123 
124  ASSERTL1(pts.num_elements() == m_pts[0].num_elements(),
125  "Field size mismatch");
126 
127  // redirect existing pts
128  Array<OneD, Array<OneD, NekDouble> > newpts(nTotvars + 1);
129  for (size_t i = 0; i < nTotvars; ++i)
130  {
131  newpts[i] = m_pts[i];
132  }
133  newpts[nTotvars] = pts;
134 
135  m_pts = newpts;
136 
137  m_fieldNames.push_back(fieldName);
138 }
139 
140 
141 void PtsField::RemoveField(const string fieldName)
142 {
143  size_t nTotvars = m_pts.num_elements();
144 
145  // redirect existing pts
146  Array<OneD, Array<OneD, NekDouble> > newpts(nTotvars - 1);
147  for (size_t i = 0, j = 0; i < nTotvars; ++i)
148  {
149  if (i < GetDim() || m_fieldNames[i - GetDim()] != fieldName)
150  {
151  newpts[j++] = m_pts[i];
152  }
153  }
154 
155  m_pts = newpts;
156 
157  m_fieldNames.erase(remove(m_fieldNames.begin(), m_fieldNames.end(), fieldName), m_fieldNames.end());
158 }
159 
161 {
162  ASSERTL1(pts.num_elements() == m_pts.num_elements(),
163  "number of variables mismatch");
164 
165  // TODO: dont copy, dont iterate
166  for (size_t i = 0; i < m_pts.num_elements(); ++i)
167  {
168  Array<OneD, NekDouble> tmp(m_pts[i].num_elements() + pts[i].num_elements());
169  for (size_t j = 0; j < m_pts[i].num_elements(); ++j)
170  {
171  tmp[j] = m_pts[i][j];
172  }
173  for (size_t j = 0; j < pts[i].num_elements(); ++j)
174  {
175  tmp[m_pts[i].num_elements() + j] = pts[i][j];
176  }
177  m_pts[i] = tmp;
178  }
179 }
180 
181 size_t PtsField::GetNpoints() const
182 {
183  return m_pts[0].num_elements();
184 }
185 
186 NekDouble PtsField::GetPointVal(const size_t fieldInd, const size_t ptInd) const
187 {
188  return m_pts[fieldInd][ptInd];
189 }
190 
191 void PtsField::SetPointVal(const size_t fieldInd,
192  const size_t ptInd,
193  const NekDouble val)
194 {
195  m_pts[fieldInd][ptInd] = val;
196 }
197 
199 {
200  pts = m_pts;
201 }
202 
204 {
205  return m_pts[fieldInd];
206 }
207 
209 {
210  ASSERTL1(pts.num_elements() == m_pts.num_elements(),
211  "Pts field count mismatch");
212 
213  m_pts = pts;
214 }
215 
216 vector<size_t> PtsField::GetPointsPerEdge() const
217 {
218  return m_nPtsPerEdge;
219 }
220 
221 size_t PtsField::GetPointsPerEdge(const size_t i) const
222 {
223  return m_nPtsPerEdge[i];
224 }
225 
226 /**
227  * @brief Set the number of points per edge
228  *
229  * @param nPtsPerEdge Number of points per edge. Empty if the point
230  * data has no specific shape (ePtsLine) or is a block (ePtsTetBlock,
231  * ePtsTriBlock), size=1 for ePtsLine, 2 for ePtsPlane and 3 for ePtsBox
232  */
233 void PtsField::SetPointsPerEdge(const vector< size_t > nPtsPerEdge)
234 {
235  ASSERTL0(
237  "SetPointsPerEdge only supported for ePtsLine, ePtsPlane and ePtsBox.");
238 
239  m_nPtsPerEdge = nPtsPerEdge;
240 }
241 
243 {
244  return m_ptsType;
245 }
246 
248 {
249  m_ptsType = type;
250 }
251 
252 vector<NekDouble> PtsField::GetBoxSize() const
253 {
254  return m_boxSize;
255 }
256 
257 void PtsField::SetBoxSize(const vector< NekDouble> boxSize)
258 {
259  m_boxSize = boxSize;
260 }
261 }
262 }
std::vector< NekDouble > m_boxSize
vector of box size xmin,xmax,ymin,ymax,zmin,zmax
Definition: PtsField.h:176
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::vector< Array< OneD, int > > m_ptsConn
Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with m elements each...
Definition: PtsField.h:171
void SetDim(const int ptsDim)
Definition: PtsField.cpp:85
size_t m_dim
Dimension of the pts field.
Definition: PtsField.h:158
void RemoveField(const std::string fieldName)
Definition: PtsField.cpp:141
void AddField(const Array< OneD, NekDouble > &pts, const std::string fieldName)
Definition: PtsField.cpp:119
STL namespace.
std::vector< std::string > GetFieldNames() const
Definition: PtsField.cpp:100
NekDouble GetPointVal(const size_t fieldInd, const size_t ptInd) const
Definition: PtsField.cpp:186
void SetConnectivity(const std::vector< Array< OneD, int > > &conn)
Get the connectivity data for ePtsTetBlock and ePtsTriBlock.
Definition: PtsField.cpp:76
Array< OneD, Array< OneD, NekDouble > > m_pts
Point data. For a n-dimensional field, the first m_dim fields are the points spatial coordinates...
Definition: PtsField.h:163
PtsType m_ptsType
Type of the PtsField.
Definition: PtsField.h:173
void AddPoints(const Array< OneD, const Array< OneD, NekDouble > > &pts)
Definition: PtsField.cpp:160
std::vector< size_t > m_nPtsPerEdge
Number of points per edge. Empty if the point data has no specific shape (ePtsLine) or is a block (eP...
Definition: PtsField.h:167
std::vector< NekDouble > GetBoxSize() const
Definition: PtsField.cpp:252
double NekDouble
void SetPointsPerEdge(const std::vector< size_t > nPtsPerEdge)
Set the number of points per edge.
Definition: PtsField.cpp:233
std::vector< size_t > GetPointsPerEdge() const
Definition: PtsField.cpp:216
void GetPts(Array< OneD, Array< OneD, NekDouble > > &pts) const
Definition: PtsField.cpp:198
std::vector< std::string > m_fieldNames
Names of the field variables.
Definition: PtsField.h:160
void SetPtsType(const PtsType type)
Definition: PtsField.cpp:247
std::string GetFieldName(const int i) const
Definition: PtsField.cpp:105
void SetBoxSize(const std::vector< NekDouble > boxsize)
Definition: PtsField.cpp:257
void SetFieldNames(const std::vector< std::string > fieldNames)
Definition: PtsField.cpp:110
void SetPts(Array< OneD, Array< OneD, NekDouble > > &pts)
Definition: PtsField.cpp:208
void GetConnectivity(std::vector< Array< OneD, int > > &conn) const
Set the connectivity data for ePtsTetBlock and ePtsTriBlock.
Definition: PtsField.cpp:63
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
void SetPointVal(const size_t fieldInd, const size_t ptInd, const NekDouble val)
Definition: PtsField.cpp:191