Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | List of all members
Nektar::Utilities::ProcessIsoContour Class Reference

This processing module extracts an isocontour. More...

#include <ProcessIsoContour.h>

Inheritance diagram for Nektar::Utilities::ProcessIsoContour:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::ProcessIsoContour:
Collaboration graph
[legend]

Public Member Functions

 ProcessIsoContour (FieldSharedPtr f)
 
virtual ~ProcessIsoContour ()
 
virtual void Process (po::variables_map &vm)
 Write mesh to output file. More...
 
- Public Member Functions inherited from Nektar::Utilities::ProcessEquiSpacedOutput
 ProcessEquiSpacedOutput (FieldSharedPtr f)
 
virtual ~ProcessEquiSpacedOutput ()
 
- Public Member Functions inherited from Nektar::Utilities::ProcessModule
 ProcessModule ()
 
 ProcessModule (FieldSharedPtr p_f)
 
 ProcessModule (MeshSharedPtr p_m)
 
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
 
void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
void PrintConfig ()
 Print out all configuration options for a module. More...
 
void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
bool GetRequireEquiSpaced (void)
 
void SetRequireEquiSpaced (bool pVal)
 
void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 
 Module (MeshSharedPtr p_m)
 
virtual void Process ()=0
 
void RegisterConfig (string key, string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 

Static Public Member Functions

static boost::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 
- Static Public Member Functions inherited from Nektar::Utilities::ProcessEquiSpacedOutput
static boost::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey className
 
- Static Public Attributes inherited from Nektar::Utilities::ProcessEquiSpacedOutput
static ModuleKey className
 

Protected Member Functions

 ProcessIsoContour ()
 
void ResetFieldPts (vector< IsoSharedPtr > &iso)
 
- Protected Member Functions inherited from Nektar::Utilities::ProcessEquiSpacedOutput
 ProcessEquiSpacedOutput ()
 
void SetupEquiSpacedField (void)
 
void GenOrthoModes (int n, const Array< OneD, const NekDouble > &phys, Array< OneD, NekDouble > &coeffs)
 
- Protected Member Functions inherited from Nektar::Utilities::Module
 Module ()
 
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual void ProcessElements ()
 Generate element IDs. More...
 
virtual void ProcessComposites ()
 Generate composites. More...
 
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
void PrismLines (int prism, PerMap &perFaces, set< int > &prismsDone, vector< ElementSharedPtr > &line)
 

Private Member Functions

vector< IsoSharedPtrExtractContour (const int fieldid, const NekDouble val)
 

Additional Inherited Members

- Protected Attributes inherited from Nektar::Utilities::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 
MeshSharedPtr m_mesh
 Mesh object. More...
 

Detailed Description

This processing module extracts an isocontour.

Definition at line 226 of file ProcessIsoContour.h.

Constructor & Destructor Documentation

Nektar::Utilities::ProcessIsoContour::ProcessIsoContour ( FieldSharedPtr  f)

Definition at line 59 of file ProcessIsoContour.cpp.

References Nektar::Utilities::Module::m_config.

59  :
61 {
62 
63  m_config["fieldstr"] = ConfigOption(false, "NotSet",
64  "string of isocontour to be extracted");
65  m_config["fieldname"] = ConfigOption(false, "isocon",
66  "name for isocontour if fieldstr "
67  "specified, default is isocon");
68 
69  m_config["fieldid"] = ConfigOption(false, "NotSet",
70  "field id to extract");
71  m_config["fieldvalue"] = ConfigOption(false, "NotSet",
72  "field value to extract");
73 
74  m_config["globalcondense"] = ConfigOption(true, "NotSet",
75  "Globally condense contour to unique "
76  "values");
77 
78  m_config["smooth"] = ConfigOption(true, "NotSet",
79  "Smooth isocontour (implies global "
80  "condense)");
81  m_config["smoothiter"] = ConfigOption(false, "100",
82  "Number of smoothing cycle, default = "
83  "100");
84  m_config["smoothposdiffusion"] = ConfigOption(false,"0.5",
85  "Postive diffusion coefficient "
86  "(0 < lambda < 1), default = 0.5");
87  m_config["smoothnegdiffusion"] = ConfigOption(false,"0.495",
88  "Negative diffusion coefficient "
89  "(0 < mu < 1), default = 0.495");
90 
91  m_config["removesmallcontour"] = ConfigOption(false,"0",
92  "Remove contours with less than specified number of triangles."
93  "Only valid with GlobalCondense or Smooth options.");
94 
95 
96 }
map< string, ConfigOption > m_config
List of configuration values.
Nektar::Utilities::ProcessIsoContour::~ProcessIsoContour ( void  )
virtual

Definition at line 98 of file ProcessIsoContour.cpp.

99 {
100 }
Nektar::Utilities::ProcessIsoContour::ProcessIsoContour ( )
inlineprotected

Definition at line 243 of file ProcessIsoContour.h.

243 {};

Member Function Documentation

static boost::shared_ptr<Module> Nektar::Utilities::ProcessIsoContour::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 230 of file ProcessIsoContour.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

231  {
233  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
vector< IsoSharedPtr > Nektar::Utilities::ProcessIsoContour::ExtractContour ( const int  fieldid,
const NekDouble  val 
)
private

Definition at line 292 of file ProcessIsoContour.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, ASSERTL1, Nektar::Utilities::Module::m_f, Nektar::Utilities::ThreeSimilar(), and Nektar::Utilities::TwoPairs().

Referenced by Process().

295 {
296  vector<IsoSharedPtr> returnval;
297 
298  int coordim = m_f->m_exp[0]->GetCoordim(0);
299  int nfields = m_f->m_fieldPts->GetNFields() + coordim;
300 
301  ASSERTL0(coordim == 3,
302  "This methods is currently only set up for 3D fields");
303  ASSERTL1(coordim + fieldid < nfields,
304  "field id is larger than number contained in FieldPts");
306  m_f->m_fieldPts->GetPts(fields);
307 
308  Array<OneD, NekDouble> c = fields[coordim + fieldid];
309 
310  int i, j, k, ii, jj, kk, r, s, n, counter, boolean;
311  Array<OneD, Array<OneD, NekDouble> > intfields(nfields);
312  intfields[0] = Array<OneD, NekDouble>(5*nfields);
313  for(i = 1; i < nfields; ++i)
314  {
315  intfields[i] = intfields[i-1] + 5;
316  }
317  Array<OneD, NekDouble> cx = intfields[0];
318  Array<OneD, NekDouble> cy = intfields[1];
319  Array<OneD, NekDouble> cz = intfields[2];
320 
321  vector<Array<OneD, int> > ptsConn;
322  m_f->m_fieldPts->GetConnectivity(ptsConn);
323  for(int zone = 0; zone < ptsConn.size(); ++zone)
324  {
325  IsoSharedPtr iso;
326 
327  iso = MemoryManager<Iso>::AllocateSharedPtr(nfields-3);
328 
329  int nelmt = ptsConn[zone].num_elements()
330  /(coordim+1);
331 
332  Array<OneD, int> conn = ptsConn[zone];
333 
334  for (n = 0, i = 0; i < nelmt; ++i)
335  {
336  // check to see if val is between vertex values
337  if(!(((c[conn[i*4]] >val)&&(c[conn[i*4+1]]>val)&&
338  (c[conn[i*4+2]]>val)&&(c[conn[i*4+3]]>val))||
339  ((c[conn[i*4 ]]<val)&&(c[conn[i*4+1]]<val)&&
340  (c[conn[i*4+2]]<val)&&(c[conn[i*4+3]]<val))))
341  {
342 
343  // loop over all edges and interpolate if
344  // contour is between vertex values
345  for (counter = 0, j=0; j<=2; j++)
346  {
347  for (k=j+1; k<=3; k++)
348  {
349  if (((c[conn[i*4+j]]>=val)&&
350  (val>=c[conn[i*4+k]]))||
351  ((c[conn[i*4+j]]<=val)&&
352  (val<=c[conn[i*4+k]])))
353  {
354  // linear interpolation of fields
355  // (and coords).
356  NekDouble cj = c[conn[i*4+j]];
357  NekDouble ck = c[conn[i*4+k]];
358  NekDouble factor = (val-cj)/(ck-cj);
359 
360  if(fabs(cj-ck) > 1e-12)
361  {
362  // interpolate coordinates and fields
363  for(int f = 0; f < nfields; ++f)
364  {
365  if(counter == 5)
366  {
367  ASSERTL0(false,"Counter is 5");
368  }
369  intfields[f][counter] =
370  fields[f][conn[4*i+j]] +
371  factor*(fields[f][conn[4*i+k]] -
372  fields[f][conn[4*i+j]]);
373  }
374  ++counter;
375  }
376  }
377  }
378  }
379 
380  switch(counter)
381  {
382  case 3:
383  n+=1;
384  iso->resize_fields(3*n);
385 
386  for(j = 0; j < 3; ++j)
387  {
388  iso->set_fields(3*(n-1)+j,intfields,j);
389  }
390  break;
391  case 4:
392  n+=2;
393  iso->resize_fields(3*n);
394 
395  for(j = 0; j < 3; ++j)
396  {
397  iso->set_fields(3*(n-2)+j,intfields,j);
398  iso->set_fields(3*(n-1)+j,intfields,j+1);
399  }
400  break;
401  case 5:
402  n+=1;
403  iso->resize_fields(3*n);
404 
405  boolean=0;
406  for (ii=0;ii<=2;ii++)
407  {
408  for (jj=ii+1;jj<=3;jj++)
409  {
410  for (kk=jj+1;kk<=4;kk++)
411  {
412  if((((cx[ii]-cx[jj])==0.0)&&
413  ((cy[ii]-cy[jj])==0.0)&&
414  ((cz[ii]-cz[jj])==0.0))&&
415  (((cx[ii]-cx[kk])==0.0)&&
416  ((cy[ii]-cy[kk])==0.0)&&
417  ((cz[ii]-cz[kk])==0.0)))
418  {
419  boolean+=1;
420  ThreeSimilar (ii,jj,kk,r,s);
421 
422  iso->set_fields(3*(n-1) ,intfields,ii);
423  iso->set_fields(3*(n-1)+1,intfields,r);
424  iso->set_fields(3*(n-1)+2,intfields,s);
425  }
426  else
427  {
428  boolean+=0;
429  }
430  }
431  }
432  }
433 
434  if (boolean==0)
435  {
436  TwoPairs (cx,cy,cz,r);
437 
438  iso->set_fields(3*(n-1) ,intfields,0);
439  iso->set_fields(3*(n-1)+1,intfields,2);
440  iso->set_fields(3*(n-1)+2,intfields,r);
441  }
442  break;
443  }
444  }
445  }
446  iso->set_ntris(n);
447 
448  // condense the information in this elemental extraction.
449  iso->condense();
450  returnval.push_back(iso);
451  }
452 
453  return returnval;
454 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
FieldSharedPtr m_f
Field object.
boost::shared_ptr< Iso > IsoSharedPtr
void TwoPairs(Array< OneD, NekDouble > &cx, Array< OneD, NekDouble > &cy, Array< OneD, NekDouble > &cz, int &pr)
double NekDouble
void ThreeSimilar(const int i, const int j, const int k, int &pr, int &ps)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:191
void Nektar::Utilities::ProcessIsoContour::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Reimplemented from Nektar::Utilities::ProcessEquiSpacedOutput.

Definition at line 102 of file ProcessIsoContour.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, ExtractContour(), Nektar::Utilities::Module::m_config, Nektar::Utilities::Module::m_f, ResetFieldPts(), and Nektar::Utilities::ProcessEquiSpacedOutput::SetupEquiSpacedField().

103 {
104  vector<IsoSharedPtr> iso;
105 
106  // extract all fields to equi-spaced
108 
109  int fieldid;
110  NekDouble value;
111 
112  if(m_config["fieldstr"].m_beenSet) //generate field of interest
113  {
114  fieldid = m_f->m_fieldPts->GetNFields();
115 
116  Array<OneD, NekDouble> pts(m_f->m_fieldPts->GetNpoints());
117 
118  // evaluate new function
120  string varstr = "x y z";
121  vector<Array<OneD, const NekDouble> > interpfields;
122 
123  for(int i = 0; i < m_f->m_fieldPts->GetDim(); ++i)
124  {
125  interpfields.push_back(m_f->m_fieldPts->GetPts(i));
126  }
127  for(int i = 0; i < m_f->m_fieldPts->GetNFields(); ++i)
128  {
129  varstr += " " + m_f->m_fieldPts->GetFieldName(i);
130  interpfields.push_back(m_f->m_fieldPts->GetPts(i+3));
131  }
132 
133  int ExprId = -1;
134  std::string str = m_config["fieldstr"].as<string>();
135  ExprId = strEval.DefineFunction(varstr.c_str(), str);
136 
137  strEval.Evaluate(ExprId, interpfields, pts);
138 
139  // set up field name if provided otherwise called "isocon" from default
140  string fieldName = m_config["fieldname"].as<string>();
141 
142  m_f->m_fieldPts->AddField(pts, fieldName);
143  }
144  else
145  {
146  ASSERTL0(m_config["fieldid"].as<string>() != "NotSet", "fieldid must be specified");
147  fieldid = m_config["fieldid"].as<int>();
148  }
149 
150  ASSERTL0(m_config["fieldvalue"].as<string>() != "NotSet", "fieldvalue must be specified");
151  value = m_config["fieldvalue"].as<NekDouble>();
152 
153  iso = ExtractContour(fieldid,value);
154  bool smoothing = m_config["smooth"].m_beenSet;
155  bool globalcondense = m_config["globalcondense"].m_beenSet;
156  if(smoothing||globalcondense)
157  {
158  vector<IsoSharedPtr> glob_iso;
159  int nfields = m_f->m_fieldPts->GetNFields() + m_f->m_fieldPts->GetDim();
161  int mincontour = 0;
162 
163  g_iso->globalcondense(iso);
164 
165  if(smoothing)
166  {
167  int niter = m_config["smoothiter"].as<int>();
168  NekDouble lambda = m_config["smoothposdiffusion"].as<NekDouble>();
169  NekDouble mu = m_config["smoothnegdiffusion"].as<NekDouble>();
170  g_iso->smooth(niter,lambda,-mu);
171  }
172 
173 
174  if((mincontour = m_config["removesmallcontour"].as<int>()))
175  {
176  g_iso->separate_regions(glob_iso,mincontour);
177  }
178  else
179  {
180  glob_iso.push_back(g_iso);
181  }
182  ResetFieldPts(glob_iso);
183  }
184  else
185  {
186  ResetFieldPts(iso);
187  }
188 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
map< string, ConfigOption > m_config
List of configuration values.
FieldSharedPtr m_f
Field object.
boost::shared_ptr< Iso > IsoSharedPtr
double NekDouble
This class defines evaluator of analytic (symbolic) mathematical expressions. Expressions are allowed...
vector< IsoSharedPtr > ExtractContour(const int fieldid, const NekDouble val)
void ResetFieldPts(vector< IsoSharedPtr > &iso)
void Nektar::Utilities::ProcessIsoContour::ResetFieldPts ( vector< IsoSharedPtr > &  iso)
protected

Definition at line 457 of file ProcessIsoContour.cpp.

References Nektar::LibUtilities::ePtsTriBlock, Nektar::Utilities::Module::m_f, and npts.

Referenced by Process().

458 {
459  int nfields = m_f->m_fieldPts->GetNFields() + m_f->m_fieldPts->GetDim();
460 
461  // set output to triangle block.
462  m_f->m_fieldPts->SetPtsType(LibUtilities::ePtsTriBlock);
463 
464  Array<OneD, Array<OneD, NekDouble> > newfields(nfields);
465 
466  // count up number of points
467  int npts = 0;
468  for(int i =0; i < iso.size(); ++i)
469  {
470  npts += iso[i]->get_nvert();
471  }
472 
473  // set up coordinate in new field
474  newfields[0] = Array<OneD, NekDouble>(npts);
475  newfields[1] = Array<OneD, NekDouble>(npts);
476  newfields[2] = Array<OneD, NekDouble>(npts);
477 
478  int cnt = 0;
479  for(int i =0; i < iso.size(); ++i)
480  {
481  for(int j = 0; j < iso[i]->get_nvert(); ++j,++cnt)
482  {
483  newfields[0][cnt] = iso[i]->get_x(j);
484  newfields[1][cnt] = iso[i]->get_y(j);
485  newfields[2][cnt] = iso[i]->get_z(j);
486  }
487  }
488 
489 
490  // set up fields
491  for(int f = 0; f < nfields-3; ++f)
492  {
493  newfields[f+3] = Array<OneD, NekDouble>(npts);
494 
495  cnt = 0;
496  for(int i =0; i < iso.size(); ++i)
497  {
498  for(int j = 0; j < iso[i]->get_nvert(); ++j,++cnt)
499  {
500  newfields[f+3][cnt] = iso[i]->get_fields(f,j);
501  }
502  }
503  }
504 
505  m_f->m_fieldPts->SetPts(newfields);
506 
507  // set up connectivity data.
508  vector<Array<OneD, int> > ptsConn;
509  m_f->m_fieldPts->GetConnectivity(ptsConn);
510  cnt = 0;
511  ptsConn.clear();
512  for(int i =0; i < iso.size(); ++i)
513  {
514  int ntris = iso[i]->get_ntris();
515  Array<OneD, int> conn(ntris*3);
516 
517  for(int j = 0; j < 3*ntris; ++j)
518  {
519  conn[j] = cnt + iso[i]->get_vid(j);
520  }
521  ptsConn.push_back(conn);
522  cnt += iso[i]->get_nvert();
523  }
524  m_f->m_fieldPts->SetConnectivity(ptsConn);
525 }
FieldSharedPtr m_f
Field object.
static std::string npts
Definition: InputFld.cpp:43

Member Data Documentation

ModuleKey Nektar::Utilities::ProcessIsoContour::className
static
Initial value:
=
ModuleKey(eProcessModule, "isocontour"),
"Extract an isocontour of fieldid variable and at "
"value fieldvalue, Optionally fieldstr can be "
"specified for a string defiition or smooth for "
"smoothing")

Definition at line 234 of file ProcessIsoContour.h.