Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProcessIsoContour.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessIsoContour.h
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
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: Generate isocontours from field data.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef FIELDUTILS_PROCESSISOCONTOUR
37 #define FIELDUTILS_PROCESSISOCONTOUR
38 
39 #include "../Module.h"
41 
42 #include <boost/geometry.hpp>
43 #include <boost/geometry/geometries/point.hpp>
44 #include <boost/geometry/geometries/box.hpp>
45 #include <boost/geometry/index/rtree.hpp>
46 
47 namespace bg = boost::geometry;
48 namespace bgi = boost::geometry::index;
49 
50 
51 namespace Nektar
52 {
53 namespace FieldUtils
54 {
55 
56 const NekDouble SQ_PNT_TOL=1e-16;
57 
58 class Iso
59 {
60  public:
61  void Condense(void);
62  void GlobalCondense(vector<boost::shared_ptr<Iso> > &iso, bool verbose);
63  void SeparateRegions(vector<boost::shared_ptr<Iso> > &iso, int minsize, bool verbose);
64 
65  void Smooth(int n_iter, NekDouble lambda, NekDouble mu);
66 
67  int GetNVert(void)
68  {
69  return m_nvert;
70  }
71 
72  void SetNVert(int n)
73  {
74  m_nvert = n;
75  }
76 
77  int GetNTris(void)
78  {
79  return m_ntris;
80  }
81 
82  void SetNTris(int n)
83  {
84  m_ntris = n;
85  }
86 
87  void SetFields(const int loc,
88  const Array<OneD,Array<OneD, NekDouble> > &intfields,
89  const int j)
90  {
91  m_x[loc] = intfields[0][j];
92  m_y[loc] = intfields[1][j];
93  m_z[loc] = intfields[2][j];
94 
95  for(int i = 0; i < intfields.num_elements()-3; ++i)
96  {
97  m_fields[i][loc] = intfields[i+3][j];
98  }
99  }
100 
101  NekDouble GetFields(const int i, const int j)
102  {
103  return m_fields[i][j];
104  }
105 
106  void SetX(int loc, NekDouble val)
107  {
108  m_x[loc] = val;
109  }
110 
111  void SetY(int loc, NekDouble val)
112  {
113  m_y[loc] = val;
114  }
115 
116  void SetZ(int loc, NekDouble val)
117  {
118  m_z[loc] = val;
119  }
120 
121  NekDouble GetX(int loc)
122  {
123  return m_x[loc];
124  }
125 
126  NekDouble GetY(int loc)
127  {
128  return m_y[loc];
129  }
130 
131  NekDouble GetZ(int loc)
132  {
133  return m_z[loc];
134  }
135 
136  int GetVId(int i)
137  {
138  return m_vid[i];
139  }
140 
141  void ResizeVId(int nconn)
142  {
143  m_vid = Array<OneD, int>(nconn);
144  }
145 
146  void SetVId(int i, int j)
147  {
148  m_vid[i] = j;
149  }
150 
151  void ResizeFields(int size)
152  {
153  if(size > m_x.size()) // add 1000 element to vectors
154  {
155  m_x.resize(size+100);
156  m_y.resize(size+100);
157  m_z.resize(size+100);;
158  for(int i = 0; i < m_fields.size(); ++i)
159  {
160  m_fields[i].resize(size+1000);
161  }
162 
163  }
164  m_nvert = size;
165  }
166 
167  Iso(int nfields)
168  {
169  m_condensed = false;
170  m_nvert = 0;
171  m_fields.resize(nfields);
172  // set up initial vectors to be 10000 long
173  m_x.resize(10000);
174  m_y.resize(10000);
175  m_z.resize(10000);
176  for(int i = 0; i < m_fields.size(); ++i)
177  {
178  m_fields[i].resize(10000);
179  }
180  };
181 
182  ~Iso(void)
183  {
184  }
185 
186  private:
188  int m_nvert; // number of vertices
189  int m_ntris; // number of triangles introduced.
190  vector<NekDouble> m_x;
191  vector<NekDouble> m_y;
192  vector<NekDouble> m_z;
193  vector<vector<NekDouble> > m_fields;
194  Array<OneD, int> m_vid; // used when condensing field
195 
196 };
197 
198 typedef boost::shared_ptr<Iso> IsoSharedPtr;
199 
201 {
202  public:
203  friend class Iso;
204 
205  IsoVertex (void)
206  {
207  m_id = -1;
208  m_x = m_y = m_z = -99999;
209  }
210 
212 
214  {
215  return m_iso_id;
216  }
217 
219  {
220  return m_iso_vert_id;
221  }
222 
223  friend bool operator == (const IsoVertex& x, const IsoVertex& y);
224  friend bool operator != (const IsoVertex& x, const IsoVertex& y);
225 
226  private:
227  int m_id;
228  int m_iso_id;
231  vector<NekDouble > m_fields;
232 
233 };
234 
235 /**
236  * @brief This processing module extracts an isocontour
237  */
239 {
240  public:
241  /// Creates an instance of this class
242  static boost::shared_ptr<Module> create(FieldSharedPtr f)
243  {
245  }
247 
249  virtual ~ProcessIsoContour();
250 
251  /// Write mesh to output file.
252  virtual void Process(po::variables_map &vm);
253 
254  protected:
256  void ResetFieldPts(vector<IsoSharedPtr> &iso);
257  void SetupIsoFromFieldPts(vector<IsoSharedPtr> &isovec);
258 
259  private:
260 
261  vector<IsoSharedPtr> ExtractContour(
262  const int fieldid,
263  const NekDouble val);
264 };
265 
266 }
267 }
268 
269 #endif
NekDouble GetX(int loc)
void SetX(int loc, NekDouble val)
NekDouble GetFields(const int i, const int j)
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
NekDouble GetY(int loc)
pair< ModuleType, string > ModuleKey
void ResetFieldPts(vector< IsoSharedPtr > &iso)
void SetupIsoFromFieldPts(vector< IsoSharedPtr > &isovec)
vector< vector< NekDouble > > m_fields
void SetFields(const int loc, const Array< OneD, Array< OneD, NekDouble > > &intfields, const int j)
boost::shared_ptr< Iso > IsoSharedPtr
This processing module interpolates one field to another.
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:740
void GlobalCondense(vector< boost::shared_ptr< Iso > > &iso, bool verbose)
double NekDouble
friend bool operator!=(const IsoVertex &x, const IsoVertex &y)
void Smooth(int n_iter, NekDouble lambda, NekDouble mu)
vector< NekDouble > m_z
void SetVId(int i, int j)
virtual void Process(po::variables_map &vm)
Write mesh to output file.
void SetZ(int loc, NekDouble val)
static boost::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
vector< NekDouble > m_x
Array< OneD, int > m_vid
const NekDouble SQ_PNT_TOL
friend bool operator==(const IsoVertex &x, const IsoVertex &y)
NekDouble GetZ(int loc)
void SeparateRegions(vector< boost::shared_ptr< Iso > > &iso, int minsize, bool verbose)
void SetY(int loc, NekDouble val)
This processing module extracts an isocontour.
vector< IsoSharedPtr > ExtractContour(const int fieldid, const NekDouble val)
vector< NekDouble > m_y