Nektar++
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:
[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=std::string())
 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 std::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::Interpreter 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, ConfigOptionm_config
 List of configuration values. More...
 

Detailed Description

Definition at line 47 of file ProcessCurve.h.

Constructor & Destructor Documentation

◆ ProcessCurve()

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

Default constructor.

Definition at line 65 of file ProcessCurve.cpp.

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

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

◆ ~ProcessCurve()

Nektar::Utilities::ProcessCurve::~ProcessCurve ( )
virtual

Destructor.

Definition at line 80 of file ProcessCurve.cpp.

81 {
82 }

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 51 of file ProcessCurve.h.

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

52  {
54  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

◆ EvaluateCoordinate()

NekDouble Nektar::Utilities::ProcessCurve::EvaluateCoordinate ( NekDouble  xCoord)
private

Definition at line 209 of file ProcessCurve.cpp.

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

Referenced by v_GenerateEdgeNodes().

210 {
211  if (m_fromFile)
212  {
213  Array<OneD, Array<OneD, NekDouble> > tmp(2);
214  tmp[0] = Array<OneD, NekDouble>(1, xCoord);
215  tmp[1] = Array<OneD, NekDouble>(1, 0.0);
216 
219 
220  LibUtilities::Interpolator interp;
221  interp.Interpolate(m_fieldPts, toPts);
222 
223  return tmp[1][0];
224  }
225  else
226  {
227  return m_fEval.Evaluate(m_fExprId, xCoord, 0.0, 0.0, 0.0);
228  }
229 }
NekDouble Evaluate(const int id)
Evaluate a function which depends only on constants and/or parameters.
LibUtilities::PtsFieldSharedPtr m_fieldPts
Definition: ProcessCurve.h:69
std::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:179
LibUtilities::Interpreter m_fEval
Definition: ProcessCurve.h:67
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

◆ v_GenerateEdgeNodes()

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 107 of file ProcessCurve.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::LibUtilities::Interpreter::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().

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

Member Data Documentation

◆ className

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

Definition at line 55 of file ProcessCurve.h.

◆ m_fEval

LibUtilities::Interpreter Nektar::Utilities::ProcessCurve::m_fEval
private

Definition at line 67 of file ProcessCurve.h.

Referenced by EvaluateCoordinate(), and v_GenerateEdgeNodes().

◆ m_fExprId

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

Definition at line 68 of file ProcessCurve.h.

Referenced by EvaluateCoordinate(), and v_GenerateEdgeNodes().

◆ m_fieldPts

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

Definition at line 69 of file ProcessCurve.h.

Referenced by EvaluateCoordinate(), and v_GenerateEdgeNodes().

◆ m_fromFile

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

Definition at line 66 of file ProcessCurve.h.

Referenced by EvaluateCoordinate(), and v_GenerateEdgeNodes().