Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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.
- 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.
void PrintConfig ()
 Print out all configuration options for a module.
void SetDefaults ()
 Sets default configuration options for those which have not been set.
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.

Static Public Member Functions

static boost::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class.

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)

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.
map< string, ConfigOptionm_config
 List of configuration values.
bool m_requireEquiSpaced
MeshSharedPtr m_mesh
 Mesh object.

Detailed Description

This processing module extracts an isocontour.

Definition at line 224 of file ProcessIsoContour.h.

Constructor & Destructor Documentation

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

Definition at line 56 of file ProcessIsoContour.cpp.

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

:
{
m_config["fieldstr"] = ConfigOption(false, "NotSet",
"string of isocontour to be extracted");
m_config["fieldname"] = ConfigOption(false, "isocon",
"name for isocontour if fieldstr "
"specified, default is isocon");
m_config["fieldid"] = ConfigOption(false, "NotSet",
"field id to extract");
m_config["fieldvalue"] = ConfigOption(false, "NotSet",
"field value to extract");
m_config["globalcondense"] = ConfigOption(true, "NotSet",
"Globally condense contour to unique "
"values");
m_config["smooth"] = ConfigOption(true, "NotSet",
"Smooth isocontour (implies global "
"condense)");
m_config["smoothiter"] = ConfigOption(false, "100",
"Number of smoothing cycle, default = "
"100");
m_config["smoothposdiffusion"] = ConfigOption(false,"0.5",
"Postive diffusion coefficient "
"(0 < lambda < 1), default = 0.5");
m_config["smoothnegdiffusion"] = ConfigOption(false,"0.495",
"Negative diffusion coefficient "
"(0 < mu < 1), default = 0.495");
}
Nektar::Utilities::ProcessIsoContour::~ProcessIsoContour ( void  )
virtual

Definition at line 90 of file ProcessIsoContour.cpp.

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

Definition at line 241 of file ProcessIsoContour.h.

{};

Member Function Documentation

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

Creates an instance of this class.

Reimplemented from Nektar::Utilities::ProcessEquiSpacedOutput.

Definition at line 228 of file ProcessIsoContour.h.

vector< IsoSharedPtr > Nektar::Utilities::ProcessIsoContour::ExtractContour ( const int  fieldid,
const NekDouble  val 
)
private

Definition at line 289 of file ProcessIsoContour.cpp.

References ASSERTL0, ASSERTL1, Nektar::Utilities::Module::m_f, Nektar::Utilities::ThreeSimilar(), and Nektar::Utilities::TwoPairs().

Referenced by Process().

{
vector<IsoSharedPtr> returnval;
Array<OneD, NekDouble> x = m_f->m_fieldPts->m_pts[0];
Array<OneD, NekDouble> y = m_f->m_fieldPts->m_pts[1];
Array<OneD, NekDouble> z = m_f->m_fieldPts->m_pts[2];
int coordim = m_f->m_exp[0]->GetCoordim(0);
int nfields = m_f->m_fieldPts->m_pts.num_elements();
ASSERTL0(coordim == 3,
"This methods is currently only set up for 3D fields");
ASSERTL1(coordim + fieldid < nfields,
"field id is larger than number contained in FieldPts");
Array<OneD, Array<OneD, NekDouble> > fields = m_f->m_fieldPts->m_pts;
Array<OneD, NekDouble> c = fields[coordim + fieldid];
int i, j, k, ii, jj, kk, r, s, n, counter, boolean;
Array<OneD, Array<OneD, NekDouble> > intfields(nfields);
intfields[0] = Array<OneD, NekDouble>(5*nfields);
for(i = 1; i < nfields; ++i)
{
intfields[i] = intfields[i-1] + 5;
}
Array<OneD, NekDouble> cx = intfields[0];
Array<OneD, NekDouble> cy = intfields[1];
Array<OneD, NekDouble> cz = intfields[2];
for(int zone = 0; zone < m_f->m_fieldPts->m_ptsConn.size(); ++zone)
{
int nelmt = m_f->m_fieldPts->m_ptsConn[zone].num_elements()
/(coordim+1);
Array<OneD, int> conn = m_f->m_fieldPts->m_ptsConn[zone];
for (n = 0, i = 0; i < nelmt; ++i)
{
// check to see if val is between vertex values
if(!(((c[conn[i*4]] >val)&&(c[conn[i*4+1]]>val)&&
(c[conn[i*4+2]]>val)&&(c[conn[i*4+3]]>val))||
((c[conn[i*4 ]]<val)&&(c[conn[i*4+1]]<val)&&
(c[conn[i*4+2]]<val)&&(c[conn[i*4+3]]<val))))
{
// loop over all edges and interpolate if
// contour is between vertex values
for (counter = 0, j=0; j<=2; j++)
{
for (k=j+1; k<=3; k++)
{
if (((c[conn[i*4+j]]>=val)&&
(val>=c[conn[i*4+k]]))||
((c[conn[i*4+j]]<=val)&&
(val<=c[conn[i*4+k]])))
{
// linear interpolation of fields
// (and coords).
NekDouble cj = c[conn[i*4+j]];
NekDouble ck = c[conn[i*4+k]];
NekDouble factor = (val-cj)/(ck-cj);
if(fabs(cj-ck) > 1e-12)
{
// interpolate coordinates and fields
for(int f = 0; f < nfields; ++f)
{
if(counter == 5)
{
ASSERTL0(false,"Counter is 5");
}
intfields[f][counter] =
fields[f][conn[4*i+j]] +
factor*(fields[f][conn[4*i+k]] -
fields[f][conn[4*i+j]]);
}
++counter;
}
}
}
}
switch(counter)
{
case 3:
n+=1;
iso->resize_fields(3*n);
for(j = 0; j < 3; ++j)
{
iso->set_fields(3*(n-1)+j,intfields,j);
}
break;
case 4:
n+=2;
iso->resize_fields(3*n);
for(j = 0; j < 3; ++j)
{
iso->set_fields(3*(n-2)+j,intfields,j);
iso->set_fields(3*(n-1)+j,intfields,j+1);
}
break;
case 5:
n+=1;
iso->resize_fields(3*n);
boolean=0;
for (ii=0;ii<=2;ii++)
{
for (jj=ii+1;jj<=3;jj++)
{
for (kk=jj+1;kk<=4;kk++)
{
if((((cx[ii]-cx[jj])==0.0)&&
((cy[ii]-cy[jj])==0.0)&&
((cz[ii]-cz[jj])==0.0))&&
(((cx[ii]-cx[kk])==0.0)&&
((cy[ii]-cy[kk])==0.0)&&
((cz[ii]-cz[kk])==0.0)))
{
boolean+=1;
ThreeSimilar (ii,jj,kk,r,s);
iso->set_fields(3*(n-1) ,intfields,ii);
iso->set_fields(3*(n-1)+1,intfields,r);
iso->set_fields(3*(n-1)+2,intfields,s);
}
else
{
boolean+=0;
}
}
}
}
if (boolean==0)
{
TwoPairs (cx,cy,cz,r);
iso->set_fields(3*(n-1) ,intfields,0);
iso->set_fields(3*(n-1)+1,intfields,2);
iso->set_fields(3*(n-1)+2,intfields,r);
}
break;
}
}
}
iso->set_ntris(n);
// condense the information in this elemental extraction.
iso->condense();
returnval.push_back(iso);
}
return returnval;
}
void Nektar::Utilities::ProcessIsoContour::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Reimplemented from Nektar::Utilities::ProcessEquiSpacedOutput.

Definition at line 94 of file ProcessIsoContour.cpp.

References Nektar::LibUtilities::AnalyticExpressionEvaluator::DefineFunction(), Nektar::LibUtilities::AnalyticExpressionEvaluator::Evaluate(), ExtractContour(), Nektar::Utilities::Module::m_config, Nektar::Utilities::Module::m_f, npts, ResetFieldPts(), and Nektar::Utilities::ProcessEquiSpacedOutput::SetupEquiSpacedField().

{
vector<IsoSharedPtr> iso;
// extract all fields to equi-spaced
int fieldid;
NekDouble value;
if(m_config["fieldstr"].m_beenSet) //generate field of interest
{
m_f->m_fieldPts->m_nFields++;
int nfields = m_f->m_fieldPts->m_nFields;
int coordim = m_f->m_fieldPts->m_ptsDim;
fieldid = nfields-1;
Array<OneD, Array<OneD, NekDouble> > newpts(nfields+coordim);
// redirect existing pts
for(int i = 0; i < nfields+coordim-1; ++i)
{
newpts[i] = m_f->m_fieldPts->m_pts[i];
}
int npts = m_f->m_fieldPts->m_pts[0].num_elements();
newpts[nfields+coordim-1] = Array<OneD, NekDouble>(npts);
m_f->m_fieldPts->m_pts = newpts;
// evaluate new function
string varstr = "x y z";
vector<Array<OneD, const NekDouble> > interpfields;
for(int i = 0; i < coordim; ++i)
{
interpfields.push_back(m_f->m_fieldPts->m_pts[i]);
}
for(int i = 0; i < nfields-1; ++i)
{
varstr += " " + m_f->m_fieldPts->m_fields[i];
interpfields.push_back(m_f->m_fieldPts->m_pts[i+3]);
}
int ExprId = -1;
std::string str = m_config["fieldstr"].as<string>();
ExprId = strEval.DefineFunction(varstr.c_str(), str);
strEval.Evaluate(ExprId, interpfields,
m_f->m_fieldPts->m_pts[nfields+coordim-1]);
// set up field name if provided otherwise called "isocon" from default
m_f->m_fieldPts->m_fields.push_back(
m_config["fieldname"].as<string>());
}
else
{
fieldid = m_config["fieldid"].as<int>();
}
value = m_config["fieldvalue"].as<NekDouble>();
iso = ExtractContour(fieldid,value);
bool smoothing = m_config["smooth"].m_beenSet;
bool globalcondense = m_config["globalcondense"].m_beenSet;
if(smoothing||globalcondense)
{
vector<IsoSharedPtr> glob_iso;
int nfields = m_f->m_fieldPts->m_pts.num_elements();
g_iso->globalcondense(iso);
if(smoothing)
{
int niter = m_config["smoothiter"].as<int>();
NekDouble lambda = m_config["smoothposdiffusion"].as<NekDouble>();
NekDouble mu = m_config["smoothnegdiffusion"].as<NekDouble>();
g_iso->smooth(niter,lambda,-mu);
}
glob_iso.push_back(g_iso);
ResetFieldPts(glob_iso);
}
else
{
}
}
void Nektar::Utilities::ProcessIsoContour::ResetFieldPts ( vector< IsoSharedPtr > &  iso)
protected

Definition at line 457 of file ProcessIsoContour.cpp.

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

Referenced by Process().

{
int nfields = m_f->m_fieldPts->m_pts.num_elements();
// set output to triangle block.
m_f->m_fieldPts->m_ptype = ePtsTriBlock;
Array<OneD, Array<OneD, NekDouble> > newfields(nfields);
// count up number of points
int npts = 0;
for(int i =0; i < iso.size(); ++i)
{
npts += iso[i]->get_nvert();
}
// set up coordinate in new field
newfields[0] = Array<OneD, NekDouble>(npts);
newfields[1] = Array<OneD, NekDouble>(npts);
newfields[2] = Array<OneD, NekDouble>(npts);
int cnt = 0;
for(int i =0; i < iso.size(); ++i)
{
for(int j = 0; j < iso[i]->get_nvert(); ++j,++cnt)
{
newfields[0][cnt] = iso[i]->get_x(j);
newfields[1][cnt] = iso[i]->get_y(j);
newfields[2][cnt] = iso[i]->get_z(j);
}
}
// set up fields
for(int f = 0; f < nfields-3; ++f)
{
newfields[f+3] = Array<OneD, NekDouble>(npts);
cnt = 0;
for(int i =0; i < iso.size(); ++i)
{
for(int j = 0; j < iso[i]->get_nvert(); ++j,++cnt)
{
newfields[f+3][cnt] = iso[i]->get_fields(f,j);
}
}
}
m_f->m_fieldPts->m_pts = newfields;
// set up connectivity data.
cnt = 0;
m_f->m_fieldPts->m_ptsConn.clear();
for(int i =0; i < iso.size(); ++i)
{
int ntris = iso[i]->get_ntris();
Array<OneD, int> conn(ntris*3);
for(int j = 0; j < 3*ntris; ++j)
{
conn[j] = cnt + iso[i]->get_vid(j);
}
m_f->m_fieldPts->m_ptsConn.push_back(conn);
cnt += iso[i]->get_nvert();
}
}

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 232 of file ProcessIsoContour.h.