Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // License for the specific language governing rights and limitations under
15 // Permission is hereby granted, free of charge, to any person obtaining a
16 // copy of this software and associated documentation files (the "Software"),
17 // to deal in the Software without restriction, including without limitation
18 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 // and/or sell copies of the Software, and to permit persons to whom the
20 // Software is furnished to do so, subject to the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be included
23 // in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31 // DEALINGS IN THE SOFTWARE.
32 //
33 // Description: Pts field
34 //
35 ////////////////////////////////////////////////////////////////////////////////
36 
38 
39 using namespace std;
40 
41 namespace Nektar
42 {
43 namespace LibUtilities
44 {
45 
46 PtsField::PtsField(const int dim,
47  const Array<OneD, Array<OneD, NekDouble> > &pts)
48  : m_dim(dim), m_pts(pts), m_ptsType(ePtsFile)
49 {
50  for (int i = 0; i < GetNFields(); ++i)
51  {
52  m_fieldNames.push_back("NA");
53  }
54 }
55 
56 /**
57  * @brief Set the connectivity data for ePtsTetBlock and ePtsTriBlock
58  *
59  * @param conn Connectivity data
60  * Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with
61  * m elements each, m_ptsConn is a vector of n arrays with 3*m (ePtsTriBlock) or
62  * 4*m (ePtsTetBlock) entries.
63  */
64 void PtsField::GetConnectivity(vector< Array< OneD, int > > &conn) const
65 {
66  conn = m_ptsConn;
67 }
68 
69 /**
70  * @brief Get the connectivity data for ePtsTetBlock and ePtsTriBlock
71  *
72  * @param conn Connectivity data
73  * Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with
74  * m elements each, m_ptsConn is a vector of n arrays with 3*m (ePtsTriBlock) or
75  * 4*m (ePtsTetBlock) entries.
76  */
77 void PtsField::SetConnectivity(const vector< Array< OneD, int > > &conn)
78 {
81  "ptsType must be set before connectivity");
82 
83  m_ptsConn = conn;
84 }
85 
86 void PtsField::SetDim(const int ptsDim)
87 {
88  m_dim = ptsDim;
89 }
90 
91 int PtsField::GetDim() const
92 {
93  return m_dim;
94 }
95 
97 {
98  return m_pts.num_elements() - m_dim;
99 }
100 
101 vector<std::string> PtsField::GetFieldNames() const
102 {
103  return m_fieldNames;
104 }
105 
106 std::string PtsField::GetFieldName(const int i) const
107 {
108  return m_fieldNames[i];
109 }
110 
111 void PtsField::SetFieldNames(const vector<std::string> fieldNames)
112 {
113  ASSERTL0(fieldNames.size() == m_pts.num_elements() - m_dim,
114  "Number of given fieldNames does not match the number of stored "
115  "fields");
116 
117  m_fieldNames = fieldNames;
118 }
119 
121  const string fieldName)
122 {
123  int nTotvars = m_pts.num_elements();
124 
125  ASSERTL1(pts.num_elements() == m_pts[0].num_elements(),
126  "Field size mismatch");
127 
128  // redirect existing pts
129  Array<OneD, Array<OneD, NekDouble> > newpts(nTotvars + 1);
130  for (int i = 0; i < nTotvars; ++i)
131  {
132  newpts[i] = m_pts[i];
133  }
134  newpts[nTotvars] = pts;
135 
136  m_pts = newpts;
137 
138  m_fieldNames.push_back(fieldName);
139 }
140 
142 {
143  ASSERTL1(pts.num_elements() == m_pts.num_elements(),
144  "number of variables mismatch");
145 
146  // TODO: dont copy, dont iterate
147  for (int i = 0; i < m_pts.num_elements(); ++i)
148  {
149  Array<OneD, NekDouble> tmp(m_pts[i].num_elements() + pts[i].num_elements());
150  for (int j = 0; j < m_pts[i].num_elements(); ++j)
151  {
152  tmp[j] = m_pts[i][j];
153  }
154  for (int j = 0; j < pts[i].num_elements(); ++j)
155  {
156  tmp[m_pts[i].num_elements() + j] = pts[i][j];
157  }
158  m_pts[i] = tmp;
159  }
160 }
161 
163 {
164  return m_pts[0].num_elements();
165 }
166 
167 NekDouble PtsField::GetPointVal(const int fieldInd, const int ptInd) const
168 {
169  return m_pts[fieldInd][ptInd];
170 }
171 
172 void PtsField::SetPointVal(const int fieldInd,
173  const int ptInd,
174  const NekDouble val)
175 {
176  m_pts[fieldInd][ptInd] = val;
177 }
178 
180 {
181  pts = m_pts;
182 }
183 
185 {
186  return m_pts[fieldInd];
187 }
188 
190 {
191  ASSERTL1(pts.num_elements() == m_pts.num_elements(),
192  "Pts field count mismatch");
193 
194  m_pts = pts;
195 }
196 
197 vector<int> PtsField::GetPointsPerEdge() const
198 {
199  return m_nPtsPerEdge;
200 }
201 
202 int PtsField::GetPointsPerEdge(const int i) const
203 {
204  return m_nPtsPerEdge[i];
205 }
206 
207 /**
208  * @brief Set the number of points per edge
209  *
210  * @param nPtsPerEdge Number of points per edge. Empty if the point
211  * data has no specific shape (ePtsLine) or is a block (ePtsTetBlock,
212  * ePtsTriBlock), size=1 for ePtsLine, 2 for ePtsPlane and 3 for ePtsBox
213  */
214 void PtsField::SetPointsPerEdge(const vector< int > nPtsPerEdge)
215 {
216  ASSERTL0(
218  "SetPointsPerEdge only supported for ePtsLine, ePtsPlane and ePtsBox.");
219 
220  m_nPtsPerEdge = nPtsPerEdge;
221 }
222 
224 {
225  return m_ptsType;
226 }
227 
229 {
230  m_ptsType = type;
231 }
232 
233 vector<NekDouble> PtsField::GetBoxSize() const
234 {
235  return m_boxSize;
236 }
237 
238 void PtsField::SetBoxSize(const vector< NekDouble> boxSize)
239 {
240  m_boxSize = boxSize;
241 }
242 }
243 }
std::vector< NekDouble > m_boxSize
vector of box size xmin,xmax,ymin,ymax,zmin,zmax
Definition: PtsField.h:175
void SetPointsPerEdge(const std::vector< int > nPtsPerEdge)
Set the number of points per edge.
Definition: PtsField.cpp:214
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
NekDouble GetPointVal(const int fieldInd, const int ptInd) const
Definition: PtsField.cpp:167
std::vector< Array< OneD, int > > m_ptsConn
Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with m elements each...
Definition: PtsField.h:170
void SetDim(const int ptsDim)
Definition: PtsField.cpp:86
std::vector< int > 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:166
void AddField(const Array< OneD, NekDouble > &pts, const std::string fieldName)
Definition: PtsField.cpp:120
STL namespace.
void SetPointVal(const int fieldInd, const int ptInd, const NekDouble val)
Definition: PtsField.cpp:172
std::vector< std::string > GetFieldNames() const
Definition: PtsField.cpp:101
std::string GetFieldName(const int i) const
Definition: PtsField.cpp:106
void SetConnectivity(const std::vector< Array< OneD, int > > &conn)
Get the connectivity data for ePtsTetBlock and ePtsTriBlock.
Definition: PtsField.cpp:77
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:162
void GetPts(Array< OneD, Array< OneD, NekDouble > > &pts) const
Definition: PtsField.cpp:179
PtsType m_ptsType
Type of the PtsField.
Definition: PtsField.h:172
PtsType GetPtsType() const
Definition: PtsField.cpp:223
int m_dim
Dimension of the pts field.
Definition: PtsField.h:157
void GetConnectivity(std::vector< Array< OneD, int > > &conn) const
Set the connectivity data for ePtsTetBlock and ePtsTriBlock.
Definition: PtsField.cpp:64
void AddPoints(const Array< OneD, const Array< OneD, NekDouble > > &pts)
Definition: PtsField.cpp:141
std::vector< NekDouble > GetBoxSize() const
Definition: PtsField.cpp:233
double NekDouble
std::vector< std::string > m_fieldNames
Names of the field variables.
Definition: PtsField.h:159
void SetPtsType(const PtsType type)
Definition: PtsField.cpp:228
std::vector< int > GetPointsPerEdge() const
Definition: PtsField.cpp:197
void SetBoxSize(const std::vector< NekDouble > boxsize)
Definition: PtsField.cpp:238
void SetFieldNames(const std::vector< std::string > fieldNames)
Definition: PtsField.cpp:111
void SetPts(Array< OneD, Array< OneD, NekDouble > > &pts)
Definition: PtsField.cpp:189
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:228