Nektar++
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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Generate isocontours from field data.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef FIELDUTILS_PROCESSISOCONTOUR
36 #define FIELDUTILS_PROCESSISOCONTOUR
37 
38 #include "../Module.h"
40 
41 namespace Nektar
42 {
43 namespace FieldUtils
44 {
45 
46 class Iso
47 {
48 public:
49  void Condense(void);
50  void GlobalCondense(std::vector<std::shared_ptr<Iso>> &iso, bool verbose);
51  void SeparateRegions(std::vector<std::shared_ptr<Iso>> &iso, int minsize,
52  bool verbose);
53 
54  void Smooth(int n_iter, NekDouble lambda, NekDouble mu);
55 
56  int GetNVert(void)
57  {
58  return m_nvert;
59  }
60 
61  void SetNVert(int n)
62  {
63  m_nvert = n;
64  }
65 
66  int GetNTris(void)
67  {
68  return m_ntris;
69  }
70 
71  void SetNTris(int n)
72  {
73  m_ntris = n;
74  }
75 
76  void SetFields(const int loc,
77  const Array<OneD, Array<OneD, NekDouble>> &intfields,
78  const int j)
79  {
80  m_x[loc] = intfields[0][j];
81  m_y[loc] = intfields[1][j];
82  m_z[loc] = intfields[2][j];
83 
84  for (int i = 0; i < intfields.size() - 3; ++i)
85  {
86  m_fields[i][loc] = intfields[i + 3][j];
87  }
88  }
89 
90  NekDouble GetFields(const int i, const int j)
91  {
92  return m_fields[i][j];
93  }
94 
95  void SetX(int loc, NekDouble val)
96  {
97  m_x[loc] = val;
98  }
99 
100  void SetY(int loc, NekDouble val)
101  {
102  m_y[loc] = val;
103  }
104 
105  void SetZ(int loc, NekDouble val)
106  {
107  m_z[loc] = val;
108  }
109 
111  {
112  return m_x[loc];
113  }
114 
116  {
117  return m_y[loc];
118  }
119 
121  {
122  return m_z[loc];
123  }
124 
125  int GetVId(int i)
126  {
127  return m_vid[i];
128  }
129 
130  void ResizeVId(int nconn)
131  {
132  m_vid = Array<OneD, int>(nconn);
133  }
134 
135  void SetVId(int i, int j)
136  {
137  m_vid[i] = j;
138  }
139 
140  void ResizeFields(int size)
141  {
142  if (size > m_x.size()) // add 1000 element to vectors
143  {
144  m_x.resize(size + 100);
145  m_y.resize(size + 100);
146  m_z.resize(size + 100);
147  ;
148  for (int i = 0; i < m_fields.size(); ++i)
149  {
150  m_fields[i].resize(size + 1000);
151  }
152  }
153  m_nvert = size;
154  }
155 
156  Iso(int nfields)
157  {
158  m_condensed = false;
159  m_nvert = 0;
160  m_fields.resize(nfields);
161  // set up initial vectors to be 1000 long
162  m_x.resize(1000);
163  m_y.resize(1000);
164  m_z.resize(1000);
165  for (int i = 0; i < m_fields.size(); ++i)
166  {
167  m_fields[i].resize(1000);
168  }
169  };
170 
171  ~Iso(void)
172  {
173  }
174 
175 private:
177  int m_nvert; // number of vertices
178  int m_ntris; // number of triangles introduced.
179  std::vector<NekDouble> m_x;
180  std::vector<NekDouble> m_y;
181  std::vector<NekDouble> m_z;
182  std::vector<std::vector<NekDouble>> m_fields;
183  Array<OneD, int> m_vid; // used when condensing field
184 };
185 
186 typedef std::shared_ptr<Iso> IsoSharedPtr;
187 
189 {
190 public:
191  friend class Iso;
192 
193  IsoVertex(void)
194  {
195  m_id = -1;
196  m_x = m_y = m_z = -99999;
197  }
198 
200 
202  {
203  return m_iso_id;
204  }
205 
207  {
208  return m_iso_vert_id;
209  }
210 
211  friend bool operator==(const IsoVertex &x, const IsoVertex &y);
212  friend bool operator!=(const IsoVertex &x, const IsoVertex &y);
213 
214 private:
215  int m_id;
216  int m_iso_id;
219  std::vector<NekDouble> m_fields;
220 };
221 
222 /**
223  * @brief This processing module extracts an isocontour
224  */
226 {
227 public:
228  /// Creates an instance of this class
229  static std::shared_ptr<Module> create(FieldSharedPtr f)
230  {
232  }
234 
236  virtual ~ProcessIsoContour();
237 
238 protected:
239  /// Write mesh to output file.
240  virtual void v_Process(po::variables_map &vm) override;
241 
242  virtual std::string v_GetModuleName() override
243  {
244  return "ProcessIsoContour";
245  }
246 
247  virtual std::string v_GetModuleDescription() override
248  {
249  return "Extracting contour";
250  }
251 
253  {
254  return eModifyPts;
255  }
256 
257 protected:
259  void ResetFieldPts(std::vector<IsoSharedPtr> &iso);
260  void SetupIsoFromFieldPts(std::vector<IsoSharedPtr> &isovec);
261 
262 private:
263  std::vector<IsoSharedPtr> ExtractContour(const int fieldid,
264  const NekDouble val);
265 };
266 
267 } // namespace FieldUtils
268 } // namespace Nektar
269 
270 #endif
NekDouble GetY(int loc)
void SetX(int loc, NekDouble val)
NekDouble GetZ(int loc)
void SetVId(int i, int j)
void SetY(int loc, NekDouble val)
std::vector< NekDouble > m_z
std::vector< std::vector< NekDouble > > m_fields
NekDouble GetFields(const int i, const int j)
Array< OneD, int > m_vid
void SetFields(const int loc, const Array< OneD, Array< OneD, NekDouble >> &intfields, const int j)
void SeparateRegions(std::vector< std::shared_ptr< Iso >> &iso, int minsize, bool verbose)
void SetZ(int loc, NekDouble val)
std::vector< NekDouble > m_y
NekDouble GetX(int loc)
std::vector< NekDouble > m_x
void GlobalCondense(std::vector< std::shared_ptr< Iso >> &iso, bool verbose)
void Smooth(int n_iter, NekDouble lambda, NekDouble mu)
friend bool operator!=(const IsoVertex &x, const IsoVertex &y)
friend bool operator==(const IsoVertex &x, const IsoVertex &y)
std::vector< NekDouble > m_fields
This processing module extracts an isocontour.
std::vector< IsoSharedPtr > ExtractContour(const int fieldid, const NekDouble val)
virtual std::string v_GetModuleDescription() override
virtual ModulePriority v_GetModulePriority() override
void SetupIsoFromFieldPts(std::vector< IsoSharedPtr > &isovec)
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
virtual std::string v_GetModuleName() override
void ResetFieldPts(std::vector< IsoSharedPtr > &iso)
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
Abstract base class for processing modules.
Definition: Module.h:292
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
std::shared_ptr< Iso > IsoSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble