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
41namespace Nektar::FieldUtils
42{
43
44class Iso
45{
46public:
47 void Condense(void);
48 void GlobalCondense(std::vector<std::shared_ptr<Iso>> &iso, bool verbose);
49 void SeparateRegions(std::vector<std::shared_ptr<Iso>> &iso, int minsize,
50 bool verbose);
51
52 void Smooth(int n_iter, NekDouble lambda, NekDouble mu);
53
54 int GetNVert(void)
55 {
56 return m_nvert;
57 }
58
59 void SetNVert(int n)
60 {
61 m_nvert = n;
62 }
63
64 int GetNTris(void)
65 {
66 return m_ntris;
67 }
68
69 void SetNTris(int n)
70 {
71 m_ntris = n;
72 }
73
74 void SetFields(const int loc,
75 const Array<OneD, Array<OneD, NekDouble>> &intfields,
76 const int j)
77 {
78 m_x[loc] = intfields[0][j];
79 m_y[loc] = intfields[1][j];
80 m_z[loc] = intfields[2][j];
81
82 for (int i = 0; i < intfields.size() - 3; ++i)
83 {
84 m_fields[i][loc] = intfields[i + 3][j];
85 }
86 }
87
88 NekDouble GetFields(const int i, const int j)
89 {
90 return m_fields[i][j];
91 }
92
93 void SetX(int loc, NekDouble val)
94 {
95 m_x[loc] = val;
96 }
97
98 void SetY(int loc, NekDouble val)
99 {
100 m_y[loc] = val;
101 }
102
103 void SetZ(int loc, NekDouble val)
104 {
105 m_z[loc] = val;
106 }
107
109 {
110 return m_x[loc];
111 }
112
114 {
115 return m_y[loc];
116 }
117
119 {
120 return m_z[loc];
121 }
122
123 int GetVId(int i)
124 {
125 return m_vid[i];
126 }
127
128 void ResizeVId(int nconn)
129 {
130 m_vid = Array<OneD, int>(nconn);
131 }
132
133 void SetVId(int i, int j)
134 {
135 m_vid[i] = j;
136 }
137
138 void ResizeFields(int size)
139 {
140 if (size > m_x.size()) // add 1000 element to vectors
141 {
142 m_x.resize(size + 100);
143 m_y.resize(size + 100);
144 m_z.resize(size + 100);
145 ;
146 for (int i = 0; i < m_fields.size(); ++i)
147 {
148 m_fields[i].resize(size + 1000);
149 }
150 }
151 m_nvert = size;
152 }
153
154 Iso(int nfields)
155 {
156 m_condensed = false;
157 m_nvert = 0;
158 m_fields.resize(nfields);
159 // set up initial vectors to be 1000 long
160 m_x.resize(1000);
161 m_y.resize(1000);
162 m_z.resize(1000);
163 for (int i = 0; i < m_fields.size(); ++i)
164 {
165 m_fields[i].resize(1000);
166 }
167 };
168
169 ~Iso(void)
170 {
171 }
172
173private:
175 int m_nvert; // number of vertices
176 int m_ntris; // number of triangles introduced.
177 std::vector<NekDouble> m_x;
178 std::vector<NekDouble> m_y;
179 std::vector<NekDouble> m_z;
180 std::vector<std::vector<NekDouble>> m_fields;
181 Array<OneD, int> m_vid; // used when condensing field
182};
183
184typedef std::shared_ptr<Iso> IsoSharedPtr;
185
187{
188public:
189 friend class Iso;
190
192 {
193 m_id = -1;
194 m_x = m_y = m_z = -99999;
195 }
196
198
200 {
201 return m_iso_id;
202 }
203
205 {
206 return m_iso_vert_id;
207 }
208
209 friend bool operator==(const IsoVertex &x, const IsoVertex &y);
210 friend bool operator!=(const IsoVertex &x, const IsoVertex &y);
211
212private:
213 int m_id;
217 std::vector<NekDouble> m_fields;
218};
219
220/**
221 * @brief This processing module extracts an isocontour
222 */
224{
225public:
226 /// Creates an instance of this class
227 static std::shared_ptr<Module> create(FieldSharedPtr f)
228 {
230 }
232
234 ~ProcessIsoContour() override;
235
236protected:
237 /// Write mesh to output file.
238 void v_Process(po::variables_map &vm) override;
239
240 std::string v_GetModuleName() override
241 {
242 return "ProcessIsoContour";
243 }
244
245 std::string v_GetModuleDescription() override
246 {
247 return "Extracting contour";
248 }
249
251 {
252 return eModifyPts;
253 }
254
255protected:
257 void ResetFieldPts(std::vector<IsoSharedPtr> &iso);
258 void SetupIsoFromFieldPts(std::vector<IsoSharedPtr> &isovec);
259
260private:
261 std::vector<IsoSharedPtr> ExtractContour(const int fieldid,
262 const NekDouble val);
263};
264
265} // namespace Nektar::FieldUtils
266
267#endif
NekDouble GetY(int loc)
void SeparateRegions(std::vector< std::shared_ptr< Iso > > &iso, int minsize, bool verbose)
void SetFields(const int loc, const Array< OneD, Array< OneD, NekDouble > > &intfields, const int j)
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
void GlobalCondense(std::vector< std::shared_ptr< Iso > > &iso, bool verbose)
std::vector< std::vector< NekDouble > > m_fields
NekDouble GetFields(const int i, const int j)
Array< OneD, int > m_vid
void SetZ(int loc, NekDouble val)
std::vector< NekDouble > m_y
NekDouble GetX(int loc)
std::vector< NekDouble > m_x
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)
std::string v_GetModuleDescription() override
void SetupIsoFromFieldPts(std::vector< IsoSharedPtr > &isovec)
ModulePriority v_GetModulePriority() override
void ResetFieldPts(std::vector< IsoSharedPtr > &iso)
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
void v_Process(po::variables_map &vm) override
Write mesh to output file.
Abstract base class for processing modules.
Definition: Module.h:301
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:1026
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
std::shared_ptr< Iso > IsoSharedPtr
double NekDouble