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.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(),
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.size();
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.size() == m_pts.size(),
163  "number of variables mismatch");
164 
165  // TODO: dont copy, dont iterate
166  for (size_t i = 0; i < m_pts.size(); ++i)
167  {
168  Array<OneD, NekDouble> tmp(m_pts[i].size() + pts[i].size());
169  for (size_t j = 0; j < m_pts[i].size(); ++j)
170  {
171  tmp[j] = m_pts[i][j];
172  }
173  for (size_t j = 0; j < pts[i].size(); ++j)
174  {
175  tmp[m_pts[i].size() + 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].size();
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.size() == m_pts.size(),
211  "Pts field count mismatch");
212 
213  m_pts = pts;
214 }
215 
216 void PtsField::SetPts(const int fldId, const Array< OneD, const NekDouble > &pts)
217 {
218  ASSERTL1(fldId < m_pts.size(),
219  "Pts field count mismatch");
220 
221  m_pts[fldId] = pts;
222 }
223 
224 vector<size_t> PtsField::GetPointsPerEdge() const
225 {
226  return m_nPtsPerEdge;
227 }
228 
229 size_t PtsField::GetPointsPerEdge(const size_t i) const
230 {
231  return m_nPtsPerEdge[i];
232 }
233 
234 /**
235  * @brief Set the number of points per edge
236  *
237  * @param nPtsPerEdge Number of points per edge. Empty if the point
238  * data has no specific shape (ePtsLine) or is a block (ePtsTetBlock,
239  * ePtsTriBlock), size=1 for ePtsLine, 2 for ePtsPlane and 3 for ePtsBox
240  */
241 void PtsField::SetPointsPerEdge(const vector< size_t > nPtsPerEdge)
242 {
243  ASSERTL0(
245  "SetPointsPerEdge only supported for ePtsLine, ePtsPlane and ePtsBox.");
246 
247  m_nPtsPerEdge = nPtsPerEdge;
248 }
249 
251 {
252  return m_ptsType;
253 }
254 
256 {
257  m_ptsType = type;
258 }
259 
260 vector<NekDouble> PtsField::GetBoxSize() const
261 {
262  return m_boxSize;
263 }
264 
265 void PtsField::SetBoxSize(const vector< NekDouble> boxSize)
266 {
267  m_boxSize = boxSize;
268 }
269 }
270 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:250
void SetBoxSize(const std::vector< NekDouble > boxsize)
Definition: PtsField.cpp:265
NekDouble GetPointVal(const size_t fieldInd, const size_t ptInd) const
Definition: PtsField.cpp:186
std::vector< std::string > GetFieldNames() const
Definition: PtsField.cpp:100
std::vector< size_t > GetPointsPerEdge() const
Definition: PtsField.cpp:224
void SetFieldNames(const std::vector< std::string > fieldNames)
Definition: PtsField.cpp:110
std::vector< Array< OneD, int > > m_ptsConn
Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with m elements each,...
Definition: PtsField.h:174
void SetPointVal(const size_t fieldInd, const size_t ptInd, const NekDouble val)
Definition: PtsField.cpp:191
void SetDim(const int ptsDim)
Definition: PtsField.cpp:85
std::vector< NekDouble > GetBoxSize() const
Definition: PtsField.cpp:260
size_t m_dim
Dimension of the pts field.
Definition: PtsField.h:161
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:170
std::string GetFieldName(const int i) const
Definition: PtsField.cpp:105
void GetConnectivity(std::vector< Array< OneD, int > > &conn) const
Set the connectivity data for ePtsTetBlock and ePtsTriBlock.
Definition: PtsField.cpp:63
PtsType m_ptsType
Type of the PtsField.
Definition: PtsField.h:176
std::vector< std::string > m_fieldNames
Names of the field variables.
Definition: PtsField.h:163
std::vector< NekDouble > m_boxSize
vector of box size xmin,xmax,ymin,ymax,zmin,zmax
Definition: PtsField.h:179
void SetPts(Array< OneD, Array< OneD, NekDouble > > &pts)
Definition: PtsField.cpp:208
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:166
void SetConnectivity(const std::vector< Array< OneD, int > > &conn)
Get the connectivity data for ePtsTetBlock and ePtsTriBlock.
Definition: PtsField.cpp:76
void RemoveField(const std::string fieldName)
Definition: PtsField.cpp:141
void SetPointsPerEdge(const std::vector< size_t > nPtsPerEdge)
Set the number of points per edge.
Definition: PtsField.cpp:241
void SetPtsType(const PtsType type)
Definition: PtsField.cpp:255
void AddPoints(const Array< OneD, const Array< OneD, NekDouble > > &pts)
Definition: PtsField.cpp:160
void GetPts(Array< OneD, Array< OneD, NekDouble > > &pts) const
Definition: PtsField.cpp:198
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