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

#include <ProcessCurve.h>

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

Public Member Functions

 ProcessCurve (NekMeshUtils::MeshSharedPtr m)
 Default constructor. More...
 
virtual ~ProcessCurve ()
 Destructor. More...
 
- Public Member Functions inherited from Nektar::Utilities::ProcessCurvedEdges
 ProcessCurvedEdges (NekMeshUtils::MeshSharedPtr m)
 Default constructor. More...
 
virtual ~ProcessCurvedEdges ()
 Destructor. More...
 
virtual void Process ()
 Write mesh to output file. More...
 
void GenerateEdgeNodes (NekMeshUtils::EdgeSharedPtr edge)
 
- Public Member Functions inherited from Nektar::NekMeshUtils::ProcessModule
NEKMESHUTILS_EXPORT ProcessModule (MeshSharedPtr p_m)
 
- Public Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT Module (MeshSharedPtr p_m)
 
NEKMESHUTILS_EXPORT void RegisterConfig (std::string key, std::string value)
 Register a configuration option with a module. More...
 
NEKMESHUTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
NEKMESHUTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
NEKMESHUTILS_EXPORT MeshSharedPtr GetMesh ()
 
virtual NEKMESHUTILS_EXPORT void ProcessVertices ()
 Extract element vertices. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessElements ()
 Generate element IDs. More...
 
virtual NEKMESHUTILS_EXPORT void ProcessComposites ()
 Generate composites. More...
 
virtual NEKMESHUTILS_EXPORT void ClearElementLinks ()
 

Static Public Member Functions

static boost::shared_ptr< Modulecreate (NekMeshUtils::MeshSharedPtr m)
 Creates an instance of this class. More...
 

Static Public Attributes

static NekMeshUtils::ModuleKey className
 

Protected Member Functions

void v_GenerateEdgeNodes (NekMeshUtils::EdgeSharedPtr edge)
 
- Protected Member Functions inherited from Nektar::NekMeshUtils::Module
NEKMESHUTILS_EXPORT void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
NEKMESHUTILS_EXPORT void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::vector< ElementSharedPtr > &line)
 

Private Member Functions

NekDouble EvaluateCoordinate (NekDouble xCoord)
 

Private Attributes

bool m_fromFile
 
LibUtilities::AnalyticExpressionEvaluator m_fEval
 
int m_fExprId
 
LibUtilities::PtsFieldSharedPtr m_fieldPts
 

Additional Inherited Members

- Protected Attributes inherited from Nektar::NekMeshUtils::Module
MeshSharedPtr m_mesh
 Mesh object. More...
 
std::map< std::string,
ConfigOption
m_config
 List of configuration values. More...
 

Detailed Description

Definition at line 48 of file ProcessCurve.h.

Constructor & Destructor Documentation

Nektar::Utilities::ProcessCurve::ProcessCurve ( NekMeshUtils::MeshSharedPtr  m)

Default constructor.

Definition at line 66 of file ProcessCurve.cpp.

References Nektar::NekMeshUtils::Module::m_config.

67 {
68  m_config["function"] = ConfigOption(false, "NotSet",
69  "Expression of the curve: y = f(x).");
70  m_config["file"] = ConfigOption(false, "NotSet",
71  "Pts file containing coordinates (x,y).");
72  m_config["niter"] = ConfigOption(false, "50",
73  "Number of iterations to perform to obtain evenly distribution of points.");
74  m_config["gamma"] = ConfigOption(false, "0.1",
75  "Relaxation parameter.");
76 }
ProcessCurvedEdges(NekMeshUtils::MeshSharedPtr m)
Default constructor.
Represents a command-line configuration option.
std::map< std::string, ConfigOption > m_config
List of configuration values.
Nektar::Utilities::ProcessCurve::~ProcessCurve ( )
virtual

Destructor.

Definition at line 81 of file ProcessCurve.cpp.

82 {
83 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 52 of file ProcessCurve.h.

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

53  {
55  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
NekDouble Nektar::Utilities::ProcessCurve::EvaluateCoordinate ( NekDouble  xCoord)
private

Definition at line 210 of file ProcessCurve.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::LibUtilities::AnalyticExpressionEvaluator::Evaluate(), Nektar::FieldUtils::Interpolator::Interpolate(), m_fEval, m_fExprId, m_fieldPts, and m_fromFile.

Referenced by v_GenerateEdgeNodes().

211 {
212  if (m_fromFile)
213  {
214  Array<OneD, Array<OneD, NekDouble> > tmp(2);
215  tmp[0] = Array<OneD, NekDouble>(1, xCoord);
216  tmp[1] = Array<OneD, NekDouble>(1, 0.0);
217 
220 
221  FieldUtils::Interpolator interp;
222  interp.Interpolate(m_fieldPts, toPts);
223 
224  return tmp[1][0];
225  }
226  else
227  {
228  return m_fEval.Evaluate(m_fExprId, xCoord, 0.0, 0.0, 0.0);
229  }
230 }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
LibUtilities::AnalyticExpressionEvaluator m_fEval
Definition: ProcessCurve.h:68
NekDouble Evaluate(const int AnalyticExpression_id)
Evaluation method for expressions depending on parameters only.
boost::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:178
LibUtilities::PtsFieldSharedPtr m_fieldPts
Definition: ProcessCurve.h:70
void Nektar::Utilities::ProcessCurve::v_GenerateEdgeNodes ( NekMeshUtils::EdgeSharedPtr  edge)
protectedvirtual

This function generates curved edge information in 2D, by including equispaced nodes to an edge following the prescribed function $y = f(x)$.

An approximately equispaced node distribution is obtained by initially considering a uniform distribution in the $ x$ direction, and then adjusting the interior nodes using the iteration

\[ x^{n}_{i+1} = x^{n-1}_{i+1} + \Delta x^{n}_{i+1} \]

\[ \Delta x^{n}_{i+1} = \Delta x^{n}_{i} + \gamma (\overline{\Delta s} - \Delta s^{n}_{i}) sign(\Delta x^{n}_{i}) \]

where $ x^{n}$ is the $ x$ coordinate of the $ n^{th}$ node, $ i$ is the iteration counter, $ \Delta s^{n}$ is the Cartesian distance between nodes $ n$ and $ n-1$ and $ \overline{\Delta s}$ is the average of these distances. The relaxation factor $ \gamma$ and the fixed number of iterations $ Niter$ are parameters of the module.

In case the correction to $ \Delta x$ leads to an invalid distribution (i.e. reversing directions), the relaxation parameter is successively halved until it leads to a valid distribution.

Parameters
edgeEdge which will be modified

Implements Nektar::Utilities::ProcessCurvedEdges.

Definition at line 108 of file ProcessCurve.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreateInstance(), Nektar::LibUtilities::AnalyticExpressionEvaluator::DefineFunction(), Nektar::LibUtilities::ePolyEvenlySpaced, EvaluateCoordinate(), Nektar::LibUtilities::GetCommFactory(), Nektar::NekMeshUtils::Module::m_config, m_fEval, m_fExprId, m_fieldPts, m_fromFile, class_topology::Node, and Vmath::Sadd().

109 {
110  NodeSharedPtr n1 = edge->m_n1;
111  NodeSharedPtr n2 = edge->m_n2;
112 
113  int nq = m_config["N"].as<int>();
114  int niter = m_config["niter"].as<int>();
115  NekDouble gamma = m_config["gamma"].as<double>();
116 
117  edge->m_edgeNodes.resize(nq - 2);
118 
119  // Read function defining the curve
120  if (m_config["function"].as<string>().compare("NotSet") != 0)
121  {
122  ASSERTL0(m_config["file"].as<string>().compare("NotSet") == 0,
123  "Function and file cannot be defined at the same time.");
124 
125  std::string fstr = m_config["function"].as<string>();
126  m_fExprId = m_fEval.DefineFunction("x y z", fstr);
127  m_fromFile = false;
128  }
129  else
130  {
131  ASSERTL0(m_config["file"].as<string>().compare("NotSet") != 0,
132  "Need to define either function or file.");
133  std::string inFile = m_config["file"].as<string>();
134 
139  ptsIO->Import(inFile, m_fieldPts);
140 
141  m_fromFile = true;
142  }
143 
144  // Coordinates of points
145  Array<OneD, NekDouble> x(nq,0.0);
146  Array<OneD, NekDouble> y(nq,0.0);
147  // Distances between points
148  Array<OneD, NekDouble> dx(nq-1,0.0);
149  Array<OneD, NekDouble> dy(nq-1,0.0);
150  Array<OneD, NekDouble> ds(nq-1,0.0);
151  // Average distance and deviation from average
152  Array<OneD, NekDouble> s_deviation(nq-1,0.0);
153  NekDouble s_average;
154 
155  // Fix start point
156  x[0] = n1->m_x;
157  y[0] = EvaluateCoordinate(x[0]);
158  // Start with uniform distribution along x-axis
159  Vmath::Sadd(nq-1, (n2->m_x - n1->m_x) / (nq-1), dx, 1, dx, 1);
160 
161  // Iterate a few times to make points more evenly distributed
162  for (int s = 0; s < niter; ++s)
163  {
164  s_average = 0.0;
165  for (int k = 1; k < nq; ++k)
166  {
167  x[k] = x[k-1] + dx[k-1] + gamma*s_deviation[k-1];
168  y[k] = EvaluateCoordinate(x[k]);
169 
170  dx[k-1] = x[k] - x[k-1];
171  dy[k-1] = y[k] - y[k-1];
172  ds[k-1] = sqrt(dx[k-1]*dx[k-1] + dy[k-1]*dy[k-1]);
173 
174  s_average = s_average + ds[k-1]/(nq-1);
175  }
176  // Calculate correction for next iteration
177  for (int k = 0; k < nq-1; ++k)
178  {
179  s_deviation[k] = (s_average - ds[k])*
180  ( dx[k]/abs(dx[k]));
181  }
182  // Adjust gama to make sure next partition is valid
183  // (no reversals in dx)
184  bool valid = false;
185  gamma = m_config["gamma"].as<double>();
186  while( !valid)
187  {
188  valid = true;
189  for (int k = 0; k < nq-1; ++k)
190  {
191  if( dx[k]*(dx[k]+gamma*s_deviation[k]) < 0.0)
192  {
193  gamma = gamma/2;
194  valid = false;
195  continue;
196  }
197  }
198  }
199  }
200 
201  // Write interior nodes to edge
202  for (int k = 1; k < nq-1; ++k)
203  {
204  edge->m_edgeNodes[k-1] = NodeSharedPtr(
205  new Node(0, x[k], y[k], n1->m_z));
206  }
207  edge->m_curveType = LibUtilities::ePolyEvenlySpaced;
208 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
LibUtilities::AnalyticExpressionEvaluator m_fEval
Definition: ProcessCurve.h:68
CommFactory & GetCommFactory()
Definition: Comm.cpp:61
1D Evenly-spaced points using Lagrange polynomial
Definition: PointsType.h:65
LibUtilities::PtsFieldSharedPtr m_fieldPts
Definition: ProcessCurve.h:70
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
double NekDouble
std::map< std::string, ConfigOption > m_config
List of configuration values.
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition: Vmath.cpp:315
boost::shared_ptr< PtsIO > PtsIOSharedPtr
Definition: PtsIO.h:95
int DefineFunction(const std::string &vlist, const std::string &function)
This function allows one to define a function to evaluate. The first argument (vlist) is a list of va...
NekDouble EvaluateCoordinate(NekDouble xCoord)

Member Data Documentation

ModuleKey Nektar::Utilities::ProcessCurve::className
static
Initial value:
"Creates curved edge information using a function y=f(x) (2D only).")

Definition at line 56 of file ProcessCurve.h.

LibUtilities::AnalyticExpressionEvaluator Nektar::Utilities::ProcessCurve::m_fEval
private

Definition at line 68 of file ProcessCurve.h.

Referenced by EvaluateCoordinate(), and v_GenerateEdgeNodes().

int Nektar::Utilities::ProcessCurve::m_fExprId
private

Definition at line 69 of file ProcessCurve.h.

Referenced by EvaluateCoordinate(), and v_GenerateEdgeNodes().

LibUtilities::PtsFieldSharedPtr Nektar::Utilities::ProcessCurve::m_fieldPts
private

Definition at line 70 of file ProcessCurve.h.

Referenced by EvaluateCoordinate(), and v_GenerateEdgeNodes().

bool Nektar::Utilities::ProcessCurve::m_fromFile
private

Definition at line 67 of file ProcessCurve.h.

Referenced by EvaluateCoordinate(), and v_GenerateEdgeNodes().