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  */
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  */
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.size() - 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.size() - 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.size();
123 
124  ASSERTL1(pts.size() == m_pts[0].size(), "Field size mismatch");
125 
126  // redirect existing pts
127  Array<OneD, Array<OneD, NekDouble>> newpts(nTotvars + 1);
128  for (size_t i = 0; i < nTotvars; ++i)
129  {
130  newpts[i] = m_pts[i];
131  }
132  newpts[nTotvars] = pts;
133 
134  m_pts = newpts;
135 
136  m_fieldNames.push_back(fieldName);
137 }
138 
139 void PtsField::RemoveField(const string fieldName)
140 {
141  size_t nTotvars = m_pts.size();
142 
143  // redirect existing pts
144  Array<OneD, Array<OneD, NekDouble>> newpts(nTotvars - 1);
145  for (size_t i = 0, j = 0; i < nTotvars; ++i)
146  {
147  if (i < GetDim() || m_fieldNames[i - GetDim()] != fieldName)
148  {
149  newpts[j++] = m_pts[i];
150  }
151  }
152 
153  m_pts = newpts;
154 
155  m_fieldNames.erase(
156  remove(m_fieldNames.begin(), m_fieldNames.end(), fieldName),
157  m_fieldNames.end());
158 }
159 
161 {
162  ASSERTL1(pts.size() == m_pts.size(), "number of variables mismatch");
163 
164  // TODO: dont copy, dont iterate
165  for (size_t i = 0; i < m_pts.size(); ++i)
166  {
167  Array<OneD, NekDouble> tmp(m_pts[i].size() + pts[i].size());
168  for (size_t j = 0; j < m_pts[i].size(); ++j)
169  {
170  tmp[j] = m_pts[i][j];
171  }
172  for (size_t j = 0; j < pts[i].size(); ++j)
173  {
174  tmp[m_pts[i].size() + j] = pts[i][j];
175  }
176  m_pts[i] = tmp;
177  }
178 }
179 
180 size_t PtsField::GetNpoints() const
181 {
182  return m_pts[0].size();
183 }
184 
185 NekDouble PtsField::GetPointVal(const size_t fieldInd, const size_t ptInd) const
186 {
187  return m_pts[fieldInd][ptInd];
188 }
189 
190 void PtsField::SetPointVal(const size_t fieldInd, const size_t ptInd,
191  const NekDouble val)
192 {
193  m_pts[fieldInd][ptInd] = val;
194 }
195 
197 {
198  pts = m_pts;
199 }
200 
201 Array<OneD, NekDouble> PtsField::GetPts(const int fieldInd) const
202 {
203  return m_pts[fieldInd];
204 }
205 
207 {
208  ASSERTL1(pts.size() == m_pts.size(), "Pts field count mismatch");
209 
210  m_pts = pts;
211 }
212 
213 void PtsField::SetPts(const int fldId, const Array<OneD, const NekDouble> &pts)
214 {
215  ASSERTL1(fldId < m_pts.size(), "Pts field count mismatch");
216 
217  m_pts[fldId] = pts;
218 }
219 
220 vector<size_t> PtsField::GetPointsPerEdge() const
221 {
222  return m_nPtsPerEdge;
223 }
224 
225 size_t PtsField::GetPointsPerEdge(const size_t i) const
226 {
227  return m_nPtsPerEdge[i];
228 }
229 
230 /**
231  * @brief Set the number of points per edge
232  *
233  * @param nPtsPerEdge Number of points per edge. Empty if the point
234  * data has no specific shape (ePtsLine) or is a block (ePtsTetBlock,
235  * ePtsTriBlock), size=1 for ePtsLine, 2 for ePtsPlane and 3 for ePtsBox
236  */
237 void PtsField::SetPointsPerEdge(const vector<size_t> nPtsPerEdge)
238 {
239  ASSERTL0(
241  "SetPointsPerEdge only supported for ePtsLine, ePtsPlane and ePtsBox.");
242 
243  m_nPtsPerEdge = nPtsPerEdge;
244 }
245 
246 vector<int> PtsField::GetPointsPerElement() const
247 {
248  return m_nPtsPerElement;
249 }
250 
251 void PtsField::SetPointsPerElement(const vector<int> nPtsPerElement)
252 {
253  m_nPtsPerElement = nPtsPerElement;
254 }
255 
257 {
258  return m_ptsType;
259 }
260 
262 {
263  m_ptsType = type;
264 }
265 
266 vector<NekDouble> PtsField::GetBoxSize() const
267 {
268  return m_boxSize;
269 }
270 
271 void PtsField::SetBoxSize(const vector<NekDouble> boxSize)
272 {
273  m_boxSize = boxSize;
274 }
275 } // namespace LibUtilities
276 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
void SetConnectivity(const std::vector< Array< OneD, int >> &conn)
Get the connectivity data for ePtsTetBlock and ePtsTriBlock.
Definition: PtsField.cpp:76
std::vector< int > GetPointsPerElement() const
Definition: PtsField.cpp:246
void SetBoxSize(const std::vector< NekDouble > boxsize)
Definition: PtsField.cpp:271
NekDouble GetPointVal(const size_t fieldInd, const size_t ptInd) const
Definition: PtsField.cpp:185
void AddPoints(const Array< OneD, const Array< OneD, NekDouble >> &pts)
Definition: PtsField.cpp:160
std::vector< std::string > GetFieldNames() const
Definition: PtsField.cpp:100
std::vector< size_t > GetPointsPerEdge() const
Definition: PtsField.cpp:220
void SetFieldNames(const std::vector< std::string > fieldNames)
Definition: PtsField.cpp:110
void GetConnectivity(std::vector< Array< OneD, int >> &conn) const
Set the connectivity data for ePtsTetBlock and ePtsTriBlock.
Definition: PtsField.cpp:63
std::vector< Array< OneD, int > > m_ptsConn
Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with m elements each,...
Definition: PtsField.h:182
void SetPointVal(const size_t fieldInd, const size_t ptInd, const NekDouble val)
Definition: PtsField.cpp:190
void SetPts(Array< OneD, Array< OneD, NekDouble >> &pts)
Definition: PtsField.cpp:206
void SetDim(const int ptsDim)
Definition: PtsField.cpp:85
std::vector< NekDouble > GetBoxSize() const
Definition: PtsField.cpp:266
size_t m_dim
Dimension of the pts field.
Definition: PtsField.h:168
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:177
std::vector< int > m_nPtsPerElement
Definition: PtsField.h:178
std::string GetFieldName(const int i) const
Definition: PtsField.cpp:105
void SetPointsPerElement(const std::vector< int > nPtsPerElement)
Definition: PtsField.cpp:251
PtsType m_ptsType
Type of the PtsField.
Definition: PtsField.h:184
std::vector< std::string > m_fieldNames
Names of the field variables.
Definition: PtsField.h:170
std::vector< NekDouble > m_boxSize
vector of box size xmin,xmax,ymin,ymax,zmin,zmax
Definition: PtsField.h:187
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:173
void GetPts(Array< OneD, Array< OneD, NekDouble >> &pts) const
Definition: PtsField.cpp:196
void RemoveField(const std::string fieldName)
Definition: PtsField.cpp:139
void SetPointsPerEdge(const std::vector< size_t > nPtsPerEdge)
Set the number of points per edge.
Definition: PtsField.cpp:237
void SetPtsType(const PtsType type)
Definition: PtsField.cpp:261
void AddField(const Array< OneD, NekDouble > &pts, const std::string fieldName)
Definition: PtsField.cpp:119
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble