Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::Utilities::ProcessPerAlign Class Reference

#include <ProcessPerAlign.h>

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

Public Member Functions

 ProcessPerAlign (MeshSharedPtr m)
 Default constructor.
virtual ~ProcessPerAlign ()
 Destructor.
virtual void Process ()
 Write mesh to output file.
- Public Member Functions inherited from Nektar::Utilities::ProcessModule
 ProcessModule (FieldSharedPtr p_f)
 ProcessModule (MeshSharedPtr p_m)
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
virtual void Process (po::variables_map &vm)=0
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)
 Module (MeshSharedPtr p_m)
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 (MeshSharedPtr m)
 Creates an instance of this class.

Static Public Attributes

static ModuleKey className

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::Module
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges.
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces.
virtual void ProcessElements ()
 Generate element IDs.
virtual void ProcessComposites ()
 Generate composites.
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly.
void PrismLines (int prism, PerMap &perFaces, set< int > &prismsDone, vector< ElementSharedPtr > &line)
- 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

Definition at line 45 of file ProcessPerAlign.h.

Constructor & Destructor Documentation

Nektar::Utilities::ProcessPerAlign::ProcessPerAlign ( MeshSharedPtr  m)

Default constructor.

Definition at line 64 of file ProcessPerAlign.cpp.

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

{
m_config["surf1"] = ConfigOption(false, "-1",
"Tag identifying first surface.");
m_config["surf2"] = ConfigOption(false, "-1",
"Tag identifying first surface.");
m_config["dir"] = ConfigOption(false, "",
"Direction in which to align (either x, y, or z)");
m_config["orient"] = ConfigOption(true, "0",
"Attempt to reorient tets and prisms");
}
Nektar::Utilities::ProcessPerAlign::~ProcessPerAlign ( )
virtual

Destructor.

Definition at line 79 of file ProcessPerAlign.cpp.

{
}

Member Function Documentation

static boost::shared_ptr<Module> Nektar::Utilities::ProcessPerAlign::create ( MeshSharedPtr  m)
inlinestatic

Creates an instance of this class.

Definition at line 49 of file ProcessPerAlign.h.

{
return MemoryManager<ProcessPerAlign>::AllocateSharedPtr(m);
}
void Nektar::Utilities::ProcessPerAlign::Process ( )
virtual

Write mesh to output file.

Implements Nektar::Utilities::Module.

Definition at line 84 of file ProcessPerAlign.cpp.

References Nektar::Utilities::Node::abs2(), ASSERTL0, ASSERTL1, Nektar::iterator, Nektar::Utilities::Module::m_config, Nektar::Utilities::Node::m_id, Nektar::Utilities::Module::m_mesh, Nektar::Utilities::Node::m_x, Nektar::Utilities::Node::m_y, Nektar::Utilities::Node::m_z, and Nektar::Utilities::Module::ReorderPrisms().

{
int surf1 = m_config["surf1"]. as<int> ();
int surf2 = m_config["surf2"]. as<int> ();
string dir = m_config["dir"]. as<string>();
bool orient = m_config["orient"].as<bool> ();
if (surf1 == -1)
{
cerr << "WARNING: surf1 must be set to a positive integer. "
<< "Skipping periodic alignment." << endl;
return;
}
if (surf2 == -1)
{
cerr << "WARNING: surf2 must be set to a positive integer. "
<< "Skipping periodic alignment." << endl;
return;
}
if (dir != "x" && dir != "y" && dir != "z")
{
cerr << "WARNING: dir must be set to either x, y or z. "
<< "Skipping periodic alignment." << endl;
return;
}
NekDouble vec[3];
vec[0] = dir == "x" ? 1.0 : 0.0;
vec[1] = dir == "y" ? 1.0 : 0.0;
vec[2] = dir == "z" ? 1.0 : 0.0;
CompositeMap::iterator it1 = m_mesh->m_composite.find(surf1);
CompositeMap::iterator it2 = m_mesh->m_composite.find(surf2);
if (it1 == m_mesh->m_composite.end())
{
cerr << "WARNING: Couldn't find surface " << surf1
<< ". Skipping periodic alignment." << endl;
return;
}
if (it2 == m_mesh->m_composite.end())
{
cerr << "WARNING: Couldn't find surface " << surf2 << ", "
<< "skipping periodic alignment." << endl;
return;
}
CompositeSharedPtr c1 = it1->second;
CompositeSharedPtr c2 = it2->second;
if (c1->m_items.size() != c2->m_items.size())
{
cerr << "WARNING: Surfaces " << surf1 << " and " << surf2
<< " have different numbers of elements. Skipping periodic"
<< " alignment." << endl;
return;
}
c1->m_reorder = false;
c2->m_reorder = false;
map<int, pair<FaceSharedPtr, vector<int> > > perFaces;
// Loop over elements, calculate centroids of elements in c2.
map<int, Node> centroidMap;
for (int i = 0; i < c2->m_items.size(); ++i)
{
Node centroid;
for (int j = 0; j < c2->m_items[i]->GetVertexCount(); ++j)
{
centroid += *(c2->m_items[i]->GetVertex(j));
}
centroid /= (NekDouble)c2->m_items[i]->GetVertexCount();
centroidMap[i] = centroid;
}
boost::unordered_set<int> elmtDone;
map<int, int> elmtPairs;
map<int, int> vertCheck;
for (int i = 0; i < c1->m_items.size(); ++i)
{
Node centroid;
for (int j = 0; j < c1->m_items[i]->GetVertexCount(); ++j)
{
centroid += *(c1->m_items[i]->GetVertex(j));
}
centroid /= (NekDouble)c1->m_items[i]->GetVertexCount();
for (it = centroidMap.begin(); it != centroidMap.end(); ++it)
{
if (elmtDone.count(it->first) > 0)
{
continue;
}
Node dx = it->second - centroid;
if (fabs(fabs(dx.m_x*vec[0] + dx.m_y*vec[1] + dx.m_z*vec[2])/
sqrt(dx.abs2()) - 1.0) < 1e-8)
{
// Found match
int id1 = c1->m_items[i] ->GetFaceLink()->m_id;
int id2 = c2->m_items[it->first]->GetFaceLink()->m_id;
elmtDone.insert(it->first);
elmtPairs[i] = it->first;
// Identify periodic vertices
int nVerts = c1->m_items[i]->GetVertexCount();
vector<int> perVerts(nVerts, 0), perVertsInv(nVerts, 0);
if (orient)
{
for (int k = 0; k < nVerts; ++k)
{
NodeSharedPtr n1 = c1->m_items[i]->GetFaceLink()->m_vertexList[k];
int l;
for (l = 0; l < nVerts; ++l)
{
c2->m_items[it->first]->GetFaceLink()->m_vertexList[l];
Node dn = *n2 - *n1;
if (fabs(fabs(dn.m_x*vec[0] + dn.m_y*vec[1] +
dn.m_z*vec[2])/
sqrt(dn.abs2()) - 1.0) < 1e-8)
{
perVerts [k] = l;
perVertsInv[l] = k;
int id1 = n1->m_id;
int id2 = n2->m_id;
if (vertCheck.count(id1) == 0)
{
vertCheck[id1] = id2;
}
else
{
ASSERTL0(vertCheck[id1] == id2,
"Periodic vertex already "
"identified!");
}
break;
}
}
ASSERTL1(l < nVerts,
"Could not identify periodic vertices.");
}
int tot1 = 0, tot2 = 0;
for (int k = 0; k < nVerts; ++k)
{
tot1 += perVerts [k];
tot2 += perVertsInv[k];
}
ASSERTL0(tot1 == nVerts*(nVerts-1)/2 &&
tot2 == nVerts*(nVerts-1)/2,
"Error identifying periodic vertices");
}
perFaces[id1] = make_pair(
c2->m_items[it->first]->GetFaceLink(), perVerts);
perFaces[id2] = make_pair(
c1->m_items[i] ->GetFaceLink(), perVertsInv);
break;
}
}
if (it == centroidMap.end())
{
cerr << "WARNING: Could not find matching edge for surface "
<< "element " << c1->m_items[i]->GetId() << ". "
<< "Skipping periodic alignment." << endl;
return;
}
}
// Reorder vectors.
vector<ElementSharedPtr> tmp = c2->m_items;
for (int i = 0; i < tmp.size(); ++i)
{
c2->m_items[i] = tmp[elmtPairs[i]];
}
if (orient)
{
ReorderPrisms(perFaces);
}
}

Member Data Documentation

ModuleKey Nektar::Utilities::ProcessPerAlign::className
static