Nektar++
PtsField.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File PtsField.h
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 
37 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_PTSFIELD_H
38 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_PTSFIELD_H
39 
40 #include <vector>
41 
42 #include <boost/shared_ptr.hpp>
43 #include <boost/function.hpp>
44 
48 
49 using namespace std;
50 
51 namespace Nektar
52 {
53 namespace LibUtilities
54 {
55 
56 enum PtsType{
62 };
63 
64 
65 class PtsPoint
66 {
67  public:
68 
69  int m_idx;
72 
74 
76  NekDouble distSq):
77  m_idx(idx),
78  m_coords(coords),
79  m_distSq(distSq)
80  {
81  };
82 
83  LIB_UTILITIES_EXPORT bool operator < (const PtsPoint &comp) const
84  {
85  return (m_distSq < comp.m_distSq);
86  };
87 };
88 
89 
90 class PtsField
91 {
92  public:
93 
95  const int dim,
96  const Array<OneD, Array<OneD, NekDouble> > &pts) :
97  m_dim(dim),
98  m_pts(pts),
99  m_ptsType(ePtsFile)
100  {
101  };
102 
104  const int dim,
105  const vector<std::string> fieldnames,
106  const Array<OneD, Array<OneD, NekDouble> > &pts) :
107  m_dim(dim),
108  m_fieldNames(fieldnames),
109  m_pts(pts),
110  m_ptsType(ePtsFile)
111  {
112  };
113 
115  const int dim,
116  const vector<std::string> fieldnames,
117  const Array<OneD, Array<OneD, NekDouble> > &pts,
118  const Array<OneD, Array<OneD, float> > &weights,
119  const Array<OneD, Array<OneD, unsigned int> > &neighInds) :
120  m_dim(dim),
121  m_fieldNames(fieldnames),
122  m_pts(pts),
123  m_ptsType(ePtsFile),
124  m_weights(weights),
125  m_neighInds(neighInds)
126  {
127  };
128 
129  LIB_UTILITIES_EXPORT void CalcWeights(
130  const Array< OneD, Array< OneD, NekDouble > > &physCoords,
131  short int coordId = -1);
132 
133  LIB_UTILITIES_EXPORT void Interpolate(
134  const Array< OneD, Array< OneD, NekDouble > > &physCoords,
135  Array<OneD, Array<OneD, NekDouble> > &intFields,
136  short int coordId = -1);
137 
138  LIB_UTILITIES_EXPORT void Interpolate(
140  &intFields);
141 
142  LIB_UTILITIES_EXPORT void SetWeights
143  (const Array<OneD, Array<OneD, float> >
144  &weights,
145  const Array<OneD, Array<OneD, unsigned int> > &neighbourInds);
146 
147  LIB_UTILITIES_EXPORT void GetWeights(
148  Array<OneD, Array<OneD, float> > &weights,
149  Array<OneD, Array<OneD, unsigned int> > &neighbourInds) const;
150 
151  LIB_UTILITIES_EXPORT void GetConnectivity(vector<Array<OneD, int> > &conn) const;
152 
153  LIB_UTILITIES_EXPORT void SetConnectivity(const vector<Array<OneD, int> > &conn);
154 
155  LIB_UTILITIES_EXPORT void SetDim(const int ptsDim);
156 
157  LIB_UTILITIES_EXPORT int GetDim() const;
158 
159  LIB_UTILITIES_EXPORT int GetNFields() const;
160 
161  LIB_UTILITIES_EXPORT vector<std::string> GetFieldNames() const;
162 
163  LIB_UTILITIES_EXPORT std::string GetFieldName(const int i) const;
164 
165  LIB_UTILITIES_EXPORT void SetFieldNames(
166  const vector<std::string> fieldNames);
167 
168  LIB_UTILITIES_EXPORT void AddField(const Array<OneD, NekDouble> &pts,
169  const std::string fieldName);
170 
171  LIB_UTILITIES_EXPORT int GetNpoints() const;
172 
173  LIB_UTILITIES_EXPORT NekDouble GetPointVal(const int fieldInd, const int ptInd) const;
174 
175  LIB_UTILITIES_EXPORT void GetPts(
176  Array<OneD, Array<OneD, NekDouble> > &pts) const;
177 
178  LIB_UTILITIES_EXPORT Array<OneD, NekDouble> GetPts(const int fieldInd) const;
179 
181 
182  LIB_UTILITIES_EXPORT vector<int> GetPointsPerEdge() const;
183 
184  LIB_UTILITIES_EXPORT int GetPointsPerEdge(const int i) const;
185 
186  LIB_UTILITIES_EXPORT void SetPointsPerEdge(const vector<int> nPtsPerEdge);
187 
188  LIB_UTILITIES_EXPORT PtsType GetPtsType() const;
189 
190  LIB_UTILITIES_EXPORT void SetPtsType(const PtsType type);
191 
192  template<typename FuncPointerT, typename ObjectPointerT>
193  void setProgressCallback(FuncPointerT func,
194  ObjectPointerT obj)
195  {
196  m_progressCallback = boost::bind(func, obj, _1, _2);
197  }
198 
199  private:
200 
201  /// Dimension of the pts field
202  int m_dim;
203  /// Names of the field variables
204  vector<std::string> m_fieldNames;
205  /// Point data. For a n-dimensional field, the first n fields are the
206  /// points spatial coordinates. Structure: m_pts[fieldIdx][ptIdx]
208  /// Number of points per edge. Empty if the point data has no
209  /// specific shape (ePtsLine) or is a block (ePtsTetBlock,
210  /// ePtsTriBlock), size=1 for ePtsLine and 2 for a ePtsPlane
211  vector<int> m_nPtsPerEdge;
212  /// Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n
213  /// Blocks with m elements each, m_ptsConn is a vector of n arrays with
214  /// 3*m (ePtsTriBlock) or 4*m (ePtsTetBlock) entries.
215  vector<Array<OneD, int> > m_ptsConn;
216  /// Type of the PtsField
218  /// Interpolation weights for each neighbour.
219  /// Structure: m_weights[physPtIdx][neighbourIdx]
221  /// Indices of the relevant neighbours for each physical point.
222  /// Structure: m_neighInds[ptIdx][neighbourIdx]
224 
225  boost::function<void (const int position, const int goal)> m_progressCallback;
226 
227  LIB_UTILITIES_EXPORT void CalcW_Linear(const int physPtIdx,
228  const NekDouble coord);
229 
230  LIB_UTILITIES_EXPORT void CalcW_Shepard(
231  const int physPtIdx,
232  const Array< OneD, NekDouble > &physPtCoords);
233 
234  LIB_UTILITIES_EXPORT void CalcW_Quadratic(const int physPtIdx,
235  const NekDouble coord);
236 
238  const Array<OneD, NekDouble > &point1,
239  const Array<OneD, NekDouble > &point2) const;
240 
241  LIB_UTILITIES_EXPORT void FindNeighbours(const Array<OneD, NekDouble>
242  &physPtCoords,
243  vector<PtsPoint> &neighbourPts,
244  const unsigned int numPts = 1);
245 
246 };
247 
248 typedef boost::shared_ptr<PtsField> PtsFieldSharedPtr;
249 static PtsFieldSharedPtr NullPtsField;
250 
251 
252 }
253 }
254 #endif
Array< OneD, Array< OneD, unsigned int > > m_neighInds
Indices of the relevant neighbours for each physical point. Structure: m_neighInds[ptIdx][neighbourId...
Definition: PtsField.h:223
PtsField(const int dim, const vector< std::string > fieldnames, const Array< OneD, Array< OneD, NekDouble > > &pts)
Definition: PtsField.h:103
Array< OneD, Array< OneD, float > > m_weights
Interpolation weights for each neighbour. Structure: m_weights[physPtIdx][neighbourIdx].
Definition: PtsField.h:220
PtsField(const int dim, const Array< OneD, Array< OneD, NekDouble > > &pts)
Definition: PtsField.h:94
PtsPoint(int idx, Array< OneD, NekDouble > coords, NekDouble distSq)
Definition: PtsField.h:75
STL namespace.
vector< Array< OneD, int > > m_ptsConn
Connectivity data needed for ePtsTetBlock and ePtsTriBlock. For n Blocks with m elements each...
Definition: PtsField.h:215
boost::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:248
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:211
Array< OneD, Array< OneD, NekDouble > > m_pts
Point data. For a n-dimensional field, the first n fields are the points spatial coordinates. Structure: m_pts[fieldIdx][ptIdx].
Definition: PtsField.h:207
PtsType m_ptsType
Type of the PtsField.
Definition: PtsField.h:217
#define LIB_UTILITIES_EXPORT
int m_dim
Dimension of the pts field.
Definition: PtsField.h:202
vector< std::string > m_fieldNames
Names of the field variables.
Definition: PtsField.h:204
void setProgressCallback(FuncPointerT func, ObjectPointerT obj)
Definition: PtsField.h:193
double NekDouble
Array< OneD, NekDouble > m_coords
Definition: PtsField.h:70
bool operator<(const BasisKey &lhs, const BasisKey &rhs)
Definition: Basis.cpp:49
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:249
PtsField(const int dim, const vector< std::string > fieldnames, const Array< OneD, Array< OneD, NekDouble > > &pts, const Array< OneD, Array< OneD, float > > &weights, const Array< OneD, Array< OneD, unsigned int > > &neighInds)
Definition: PtsField.h:114
boost::function< void(const int position, const int goal)> m_progressCallback
Definition: PtsField.h:225