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