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