CppNoddy  0.92
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
CppNoddy::TwoD_Node_Mesh< _Type > Class Template Reference

A two dimensional mesh utility object. More...

#include <TwoD_Node_Mesh.h>

Public Member Functions

 TwoD_Node_Mesh ()
 
 TwoD_Node_Mesh (const DenseVector< double > &x_nodes, const DenseVector< double > &y_nodes, const std::size_t nvars)
 ctor More...
 
 TwoD_Node_Mesh (const double left, const double right, const double bottom, const double top, const std::size_t nx, const std::size_t ny, const std::size_t nvars)
 ctor More...
 
 TwoD_Node_Mesh (std::string filename, const std::size_t nx, const std::size_t ny, const std::size_t nv)
 
virtual ~TwoD_Node_Mesh ()
 dtor More...
 
DenseVector< _Type > operator() (const std::size_t nodex, const std::size_t nodey)
 Access operator for a nodal point that returns a vector. More...
 
_Type & operator() (const std::size_t nodex, const std::size_t nodey, const std::size_t var)
 Access operator for a nodal point/variable in the mesh. More...
 
const _Type & operator() (const std::size_t nodex, const std::size_t nodey, const std::size_t var) const
 Const access operator for a nodal point/variable in the mesh. More...
 
std::pair< double, double > coord (const std::size_t nodex, const std::size_t nodey) const
 Access the nodal position - as a pair. More...
 
double & xcoord (const std::size_t nodex)
 Access the x-nodal (first index) position. More...
 
double & ycoord (const std::size_t nodey)
 Access the y-nodal (second index) position. More...
 
void set_nodes_vars (const std::size_t nodex, const std::size_t nodey, const DenseVector< _Type > &U)
 Set the variables stored at A SPECIFIED node. More...
 
DenseVector< _Type > get_nodes_vars (const std::size_t nodex, const std::size_t nodey) const
 Get the variables stored at A SPECIFIED node – equivalent to mesh(nodex,nodey). More...
 
OneD_Node_Mesh< _Type > get_xsection_at_xnode (const std::size_t nodex) const
 Get a cross section of the 2D mesh at a specified (constant) x node. More...
 
OneD_Node_Mesh< _Type > get_xsection_at_ynode (const std::size_t nodey) const
 Get a cross section of the 2D mesh at a specified (constant) y node. More...
 
OneD_Node_Mesh< _Type > get_xsection_at_x1 (const double x) const
 Get a cross section of the 2D mesh at a specified (constant) x node. More...
 
void assign (const _Type elt)
 Assign an element to all entries in the mesh. More...
 
std::pair< std::size_t, std::size_t > get_nnodes () const
 Get the number of nodes in the two directions of the 2D mesh. More...
 
std::size_t get_nvars () const
 Get the number of variables that are stored at each node. More...
 
const DenseVector< double > & xnodes () const
 Access the vector of x-nodal positions. More...
 
const DenseVector< double > & ynodes () const
 Access the vector of y-nodal positions. More...
 
DenseMatrix< _Type > get_var_as_matrix (std::size_t var) const
 Return a matrix corresponding to each nodal point in the mesh Each matrix element will contain a specified variable number. More...
 
void remesh1 (const DenseVector< double > &newX, const DenseVector< double > &newY)
 Interpolate this mesh data (bilinearly) into a new mesh with nodal points defined in the argument list. More...
 
void dump () const
 A simple method for dumping data to std::cout. More...
 
void dump (std::string filename) const
 A simple method for dumping data to a file. More...
 
void dump_var (std::string filename, const unsigned var) const
 A simple method for dumping a single variable to a file with no nodal information. More...
 
void read (std::string filename, const bool reset=false)
 A simple method for reading data from a file. More...
 
void dump_gnu (std::string filename) const
 A simple method for dumping data to a file for gnuplot surface plotting. More...
 
void normalise (const std::size_t &var)
 Normalise all data in the mesh based on one variable. More...
 
void scale (const _Type &value)
 Calls the vector "scale" method for the whole mesh data. More...
 
void normalise_real_part (const std::size_t &var)
 Normalise the mesh such that the real part of variable 'var' has a real part of unity, and is then the largest real part across the whole mesh. More...
 
double max_abs_real_part (unsigned var)
 Find the maximum stored absolute value in the mesh for a given variable – no interpolation is used. More...
 
double max_abs (unsigned var)
 Find the maximum stored absolute value in the mesh for a given variable – no interpolation is used. More...
 
DenseVector< _Type > get_interpolated_vars (const double &x, const double &y)
 Get a bilinearly interpolated value at a specified point. More...
 
void normalise (const std::size_t &var)
 
void normalise (const std::size_t &var)
 
double max_abs_real_part (unsigned var)
 
double max_abs_real_part (unsigned var)
 
void dump_gnu (std::string filename) const
 
void dump_gnu (std::string filename) const
 
void read (std::string filename, bool reset)
 
void read (std::string filename, bool reset)
 

Protected Attributes

std::size_t m_nx
 
std::size_t m_ny
 
std::size_t m_nv
 
DenseVector< double > m_X
 
DenseVector< double > m_Y
 
DenseVector< _Type > m_vars
 

Detailed Description

template<typename _Type>
class CppNoddy::TwoD_Node_Mesh< _Type >

A two dimensional mesh utility object.

Definition at line 19 of file TwoD_Node_Mesh.h.

Constructor & Destructor Documentation

◆ TwoD_Node_Mesh() [1/4]

template<typename _Type >
CppNoddy::TwoD_Node_Mesh< _Type >::TwoD_Node_Mesh ( )
inline

Definition at line 22 of file TwoD_Node_Mesh.h.

23 {}

◆ TwoD_Node_Mesh() [2/4]

template<typename _Type >
CppNoddy::TwoD_Node_Mesh< _Type >::TwoD_Node_Mesh ( const DenseVector< double > &  x_nodes,
const DenseVector< double > &  y_nodes,
const std::size_t  nvars 
)
inline

ctor

Definition at line 26 of file TwoD_Node_Mesh.h.

27 :
28 m_nx(x_nodes.size()), m_ny(y_nodes.size()), m_nv(nvars), m_X(x_nodes), m_Y(y_nodes) {
29 // we'll store the data as ( x, y, v ) -> x * ny * nv + y * nv + v
30 m_vars = DenseVector<_Type>(m_nx * m_ny * m_nv, 0.0);
31 }
std::size_t size() const
A pass-thru definition to get the size of the vector.
Definition: DenseVector.h:330
DenseVector< double > m_Y
DenseVector< _Type > m_vars
DenseVector< double > m_X

References CppNoddy::TwoD_Node_Mesh< _Type >::m_nv, CppNoddy::TwoD_Node_Mesh< _Type >::m_nx, CppNoddy::TwoD_Node_Mesh< _Type >::m_ny, and CppNoddy::TwoD_Node_Mesh< _Type >::m_vars.

◆ TwoD_Node_Mesh() [3/4]

template<typename _Type >
CppNoddy::TwoD_Node_Mesh< _Type >::TwoD_Node_Mesh ( const double  left,
const double  right,
const double  bottom,
const double  top,
const std::size_t  nx,
const std::size_t  ny,
const std::size_t  nvars 
)
inline

ctor

Definition at line 34 of file TwoD_Node_Mesh.h.

35 :
36 m_nx(nx), m_ny(ny), m_nv(nvars) {
37 {
39 const double delta = (right - left) / (m_nx - 1);
40 for(std::size_t i = 0; i < m_nx; ++i) {
41 m_X.push_back(left + delta * i);
42 }
43 }
44 {
46 const double delta = (top - bottom) / (m_ny - 1);
47 for(std::size_t i = 0; i < m_ny; ++i) {
48 m_Y.push_back(bottom + delta * i);
49 }
50 }
51 // we'll store the data as ( x, y, v ) -> x * ny * nv + y * nv + v
52 m_vars = DenseVector<_Type>(m_nx * m_ny * m_nv, 0.0);
53 }
void push_back(const _Type &fill)
A pass-thru definition of push_back.
Definition: DenseVector.h:310
void reserve(const std::size_t &n)
Reserve space for the vector.
Definition: DenseVector.h:340
const double delta(0.5)

References CppNoddy::TwoD_Node_Mesh< _Type >::m_nv, CppNoddy::TwoD_Node_Mesh< _Type >::m_nx, CppNoddy::TwoD_Node_Mesh< _Type >::m_ny, CppNoddy::TwoD_Node_Mesh< _Type >::m_vars, CppNoddy::TwoD_Node_Mesh< _Type >::m_X, CppNoddy::TwoD_Node_Mesh< _Type >::m_Y, CppNoddy::DenseVector< _Type >::push_back(), and CppNoddy::DenseVector< _Type >::reserve().

◆ TwoD_Node_Mesh() [4/4]

template<typename _Type >
CppNoddy::TwoD_Node_Mesh< _Type >::TwoD_Node_Mesh ( std::string  filename,
const std::size_t  nx,
const std::size_t  ny,
const std::size_t  nv 
)
inline

Definition at line 56 of file TwoD_Node_Mesh.h.

56 :
57 m_nx(nx), m_ny(ny), m_nv(nv) {
58 // need storage for the coordinates
59 m_X = DenseVector<double>(nx, 0.0);
60 m_Y = DenseVector<double>(ny, 0.0);
61 // we'll store the data as ( x, y, v ) -> x * ny * nv + y * nv + v
62 m_vars = DenseVector<_Type>(nx * ny * nv, 0.0);
63 // now read the mesh from the given filename
64 read(filename, true);
65 }
void read(std::string filename, const bool reset=false)
A simple method for reading data from a file.

References CppNoddy::TwoD_Node_Mesh< _Type >::m_vars, CppNoddy::TwoD_Node_Mesh< _Type >::m_X, CppNoddy::TwoD_Node_Mesh< _Type >::m_Y, and CppNoddy::TwoD_Node_Mesh< _Type >::read().

◆ ~TwoD_Node_Mesh()

template<typename _Type >
virtual CppNoddy::TwoD_Node_Mesh< _Type >::~TwoD_Node_Mesh ( )
inlinevirtual

dtor

Definition at line 68 of file TwoD_Node_Mesh.h.

69 {}

Member Function Documentation

◆ assign()

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::assign ( const _Type  elt)

Assign an element to all entries in the mesh.

Parameters
eltThe element to be assigned to the mesh

Definition at line 52 of file TwoD_Node_Mesh.cpp.

52 {
53 m_vars.assign(m_nx * m_ny * m_nv, elt);
54 }

◆ coord()

template<typename _Type >
std::pair< double, double > CppNoddy::TwoD_Node_Mesh< _Type >::coord ( const std::size_t  nodex,
const std::size_t  nodey 
) const
inline

Access the nodal position - as a pair.

Parameters
nodexThe x nodal position to return
nodeyThe y nodal position to return
Returns
The spatial position of this node as a pair

Definition at line 369 of file TwoD_Node_Mesh.h.

369 {
370#ifdef PARANOID
371 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
372 std::string problem;
373 problem = " The TwoD_Node_Mesh.coord method is trying to \n";
374 problem += " access a nodal point that is not in the mesh. \n";
375 throw ExceptionRange(problem, m_nx, nodex, m_ny, nodey);
376 }
377#endif
378 std::pair< double, double > pos;
379 pos.first = m_X[ nodex ];
380 pos.second = m_Y[ nodey ];
381 return pos;
382 }

Referenced by main().

◆ dump() [1/2]

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::dump

A simple method for dumping data to std::cout.

Definition at line 318 of file TwoD_Node_Mesh.cpp.

318 {
319 for(std::size_t var = 0; var < m_nv; ++var) {
320 std::cout << "Variable : " << var << "\n";
321 std::cout << " x = ";
322 for(std::size_t i = 0; i < m_nx; ++i) {
323 std::cout << m_X[ i ] << ", ";
324 }
325
326 std::cout << "\n";
327 for(std::size_t j = 0; j < m_ny; ++j) {
328 std::cout << " y = " << m_Y[ j ] << "\n";
329 for(std::size_t i = 0; i < m_nx; ++i) {
330 std::cout << m_vars[(i * m_ny + j) * m_nv + var ] << ", ";
331 }
332 std::cout << "\n";
333 }
334 }
335 }

◆ dump() [2/2]

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::dump ( std::string  filename) const

A simple method for dumping data to a file.

Parameters
filenameThe filename to write the data to (will overwrite)

Definition at line 461 of file TwoD_Node_Mesh.cpp.

461 {
462 std::ofstream dump;
463 dump.open(filename.c_str());
464 dump.precision(15);
465 dump.setf(std::ios::showpoint);
466 dump.setf(std::ios::showpos);
467 dump.setf(std::ios::scientific);
468 //dump << m_nx << " " << m_ny << " " << m_nv << "\n";
469 dump.precision(9);
470 for(std::size_t i = 0; i < m_nx; ++i) {
471 for(std::size_t j = 0; j < m_ny; ++j) {
472 dump << m_X[ i ] << " " << m_Y[ j ] << " ";
473 for(std::size_t var = 0; var < m_nv; ++var) {
474 dump << m_vars[(i * m_ny + j) * m_nv + var ] << " ";
475 }
476 dump << "\n";
477 }
478 }
479 }
void dump() const
A simple method for dumping data to std::cout.

◆ dump_gnu() [1/3]

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::dump_gnu ( std::string  filename) const

A simple method for dumping data to a file for gnuplot surface plotting.

Parameters
filenameThe filename to write the data to (will overwrite)

Referenced by main().

◆ dump_gnu() [2/3]

void CppNoddy::TwoD_Node_Mesh< double >::dump_gnu ( std::string  filename) const

Definition at line 401 of file TwoD_Node_Mesh.cpp.

401 {
402 std::ofstream dump;
403 dump.open(filename.c_str());
404 dump.precision(15);
405 dump.setf(std::ios::showpoint);
406 dump.setf(std::ios::showpos);
407 dump.setf(std::ios::scientific);
408 //
409 for(std::size_t i = 0; i < m_nx; ++i) {
410 for(std::size_t j = 0; j < m_ny; ++j) {
411 dump << m_X[ i ] << " " << m_Y[ j ] << " ";
412 for(std::size_t var = 0; var < m_nv; ++var) {
413 dump << m_vars[(i * m_ny + j) * m_nv + var ] << " ";
414 }
415 dump << "\n";
416 }
417 dump << "\n";
418 }
419 dump.close();
420 }

◆ dump_gnu() [3/3]

void CppNoddy::TwoD_Node_Mesh< D_complex >::dump_gnu ( std::string  filename) const

Definition at line 423 of file TwoD_Node_Mesh.cpp.

423 {
424 std::ofstream dump;
425 dump.open(filename.c_str());
426 dump.precision(15);
427 dump.setf(std::ios::showpoint);
428 dump.setf(std::ios::showpos);
429 dump.setf(std::ios::scientific);
430 //
431 for(std::size_t i = 0; i < m_nx; ++i) {
432 for(std::size_t j = 0; j < m_ny; ++j) {
433 dump << m_X[ i ] << " " << m_Y[ j ] << " ";
434 for(std::size_t var = 0; var < m_nv; ++var) {
435 dump << real(m_vars[(i * m_ny + j) * m_nv + var ]) << " ";
436 dump << imag(m_vars[(i * m_ny + j) * m_nv + var ]) << " ";
437 }
438 dump << "\n";
439 }
440 dump << "\n";
441 }
442 dump.close();
443 }
DenseVector< double > real(const DenseVector< D_complex > &X)
Return a double DENSE vector containing the real part of a complex DENSE vector.
Definition: Utility.cpp:177
DenseVector< double > imag(const DenseVector< D_complex > &X)
Return a double DENSE vector containing the imaginary part of a complex DENSE vector.
Definition: Utility.cpp:185

◆ dump_var()

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::dump_var ( std::string  filename,
const unsigned  var 
) const

A simple method for dumping a single variable to a file with no nodal information.

Parameters
filenameThe filename to write the data to (will overwrite)
varThe index of the variable to be dumped to output

Definition at line 446 of file TwoD_Node_Mesh.cpp.

446 {
447 std::ofstream dump;
448 dump.open(filename.c_str());
449 dump.precision(15);
450 dump.setf(std::ios::showpoint);
451 dump.setf(std::ios::showpos);
452 dump.setf(std::ios::scientific);
453 for(std::size_t i = 0; i < m_nx; ++i) {
454 for(std::size_t j = 0; j < m_ny; ++j) {
455 dump << m_vars[(i * m_ny + j) * m_nv + var ] << "\n";
456 }
457 }
458 }

◆ get_interpolated_vars()

template<typename _Type >
DenseVector< _Type > CppNoddy::TwoD_Node_Mesh< _Type >::get_interpolated_vars ( const double &  x,
const double &  y 
)
inline

Get a bilinearly interpolated value at a specified point.

Parameters
xx-coordinate in the 2D mesh
yy-coordinate in the 2D mesh
Returns
A vector of bilinearly interpolated values

Definition at line 255 of file TwoD_Node_Mesh.h.

255 {
256 const double tol(1.e-10);
257 // check start and end
258 if((x < m_X[0] - tol) || (x > m_X[m_nx-1] + tol)) {
259 std::string problem;
260 problem = " The TwoD_Node_Mesh.get_interpolated_vars method has been called with \n";
261 problem += " an x coordinate that lies outside the mesh. \n";
262 throw ExceptionRuntime(problem);
263 }
264 // check start and end
265 if((y < m_Y[0] - tol) || (y > m_Y[m_ny-1] + tol)) {
266 std::string problem;
267 problem = " The TwoD_Node_Mesh.get_interpolated_vars method has been called with \n";
268 problem += " a y coordinate that lies outside the mesh. \n";
269 throw ExceptionRuntime(problem);
270 }
271 int bottom_j(-1);
272 for(unsigned j = 0; j < m_ny-1; ++j) {
273 if((y >= m_Y[j] - tol) && (y <= m_Y[j+1] + tol)) {
274 bottom_j = j;
275 }
276 //if ( abs(y-Y[j]) < tol )
277 //{
278 //bottom_j = j;
279 //}
280 //if ( abs(y-m_Y[j+1]) < tol )
281 //{
282 //bottom_j = j+1;
283 //}
284 }
285 //std::cout << y << " " << m_Y[bottom_j] << " " << m_Y[bottom_j+1] << "\n";
286 if(bottom_j == -1) {
287 std::string problem;
288 problem = " The TwoD_Node_Mesh.get_interpolated_vars method is broken.\n";
289 throw ExceptionRuntime(problem);
290 }
291 //
292 OneD_Node_Mesh<_Type> bottom_row = get_xsection_at_ynode(bottom_j);
293 OneD_Node_Mesh<_Type> top_row = get_xsection_at_ynode(bottom_j+1);
294 const double y1 = m_Y[ bottom_j ];
295 const double y2 = m_Y[ bottom_j+1 ];
296 DenseVector<_Type> result = top_row.get_interpolated_vars(x)*(y-y1)/(y2-y1)
297 + bottom_row.get_interpolated_vars(x)*(y2-y)/(y2-y1);
298 //std::cout << "x,y,interp: " << x << " " << y << " " << result[0] << "\n";
299 return result;
300 }
OneD_Node_Mesh< _Type > get_xsection_at_ynode(const std::size_t nodey) const
Get a cross section of the 2D mesh at a specified (constant) y node.

References CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::get_interpolated_vars(), CppNoddy::TwoD_Node_Mesh< _Type >::get_xsection_at_ynode(), CppNoddy::TwoD_Node_Mesh< _Type >::m_nx, CppNoddy::TwoD_Node_Mesh< _Type >::m_ny, CppNoddy::TwoD_Node_Mesh< _Type >::m_X, and CppNoddy::TwoD_Node_Mesh< _Type >::m_Y.

◆ get_nnodes()

template<typename _Type >
std::pair< std::size_t, std::size_t > CppNoddy::TwoD_Node_Mesh< _Type >::get_nnodes

Get the number of nodes in the two directions of the 2D mesh.

Returns
A pair consisting of the number of nodes in the 2 directions

Definition at line 57 of file TwoD_Node_Mesh.cpp.

57 {
58 std::pair< std::size_t, std::size_t > nodes;
59 nodes.first = m_nx;
60 nodes.second = m_ny;
61 return nodes;
62 }

Referenced by CppNoddy::FT::idft_with_ishift().

◆ get_nodes_vars()

template<typename _Type >
DenseVector< _Type > CppNoddy::TwoD_Node_Mesh< _Type >::get_nodes_vars ( const std::size_t  nodex,
const std::size_t  nodey 
) const

Get the variables stored at A SPECIFIED node – equivalent to mesh(nodex,nodey).

Parameters
nodexThe x nodal index to be returned
nodeyThe y nodal index to be returned
Returns
The vector of VARIABLES stored at this nodal point

Definition at line 37 of file TwoD_Node_Mesh.cpp.

37 {
38#ifdef PARANOID
39 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
40 std::string problem;
41 problem = " The TwoD_Node_Mesh.get_nodes_vars method is trying to \n";
42 problem += " access a nodal point that is not in the mesh. \n";
43 throw ExceptionRange(problem, m_nx, nodex, m_ny, nodey);
44 }
45#endif
46 // construct a vector with m_nv elements starting from a pointer
47 DenseVector<_Type> nodes_vars(m_nv, &m_vars[(nodex * m_ny + nodey) * m_nv ]);
48 return nodes_vars;
49 }

◆ get_nvars()

template<typename _Type >
std::size_t CppNoddy::TwoD_Node_Mesh< _Type >::get_nvars

Get the number of variables that are stored at each node.

Returns
The number of variables that have data stored at each nodal point

Definition at line 65 of file TwoD_Node_Mesh.cpp.

65 {
66 return m_nv;
67 }

Referenced by CppNoddy::FT::idft_with_ishift().

◆ get_var_as_matrix()

template<typename _Type >
DenseMatrix< _Type > CppNoddy::TwoD_Node_Mesh< _Type >::get_var_as_matrix ( std::size_t  var) const

Return a matrix corresponding to each nodal point in the mesh Each matrix element will contain a specified variable number.

Parameters
varThe variable number to be accessed
Returns
A dense matrix of the specified variable

Definition at line 80 of file TwoD_Node_Mesh.cpp.

80 {
81#ifdef PARANOID
82 if(var > m_nv - 1) {
83 std::string problem;
84 problem = " The TwoD_Node_Mesh.get_var_as_matrix method is trying to use a \n";
85 problem += " variable index bigger than the number of variables in the mesh. \n";
86 throw ExceptionRange(problem, m_nv, var);
87 }
88#endif
89 DenseMatrix<_Type> temp(m_nx, m_ny, 0.0);
90 for(std::size_t i = 0; i < m_nx; ++i) {
91 for(std::size_t j = 0; j < m_ny; ++j) {
92 temp(i, j) = m_vars[(i * m_ny + j) * m_nv + var ];
93 }
94 }
95 return temp;
96 }

Referenced by main().

◆ get_xsection_at_x1()

template<typename _Type >
OneD_Node_Mesh< _Type > CppNoddy::TwoD_Node_Mesh< _Type >::get_xsection_at_x1 ( const double  x) const
inline

Get a cross section of the 2D mesh at a specified (constant) x node.

Parameters
nodexThe x nodal index at which the cross section is to be taken
Returns
A 1D nodal mesh

Definition at line 135 of file TwoD_Node_Mesh.h.

135 {
136 unsigned I(0);
137 OneD_Node_Mesh<_Type> xsection(m_Y, m_nv);
138 for(unsigned i = 0; i<m_nx-1; ++i) {
139 if((m_X[i]< x) && (m_X[i+1]>x)) {
140 I=i;
141 }
142 }
143 double dx_ratio((x-m_X[I])/(m_X[I+1]-m_X[I]));
144 for(unsigned j = 0; j<m_ny; ++j) {
145 for(unsigned var = 0; var<m_nv; ++var) {
146 xsection(j,var) = this->operator()(I,j,var)+(this->operator()(I+1,j,var)-this->operator()(I,j,var))*dx_ratio;
147 }
148 }
149 return xsection;
150 }
DenseVector< _Type > operator()(const std::size_t nodex, const std::size_t nodey)
Access operator for a nodal point that returns a vector.

References CppNoddy::TwoD_Node_Mesh< _Type >::m_nv, CppNoddy::TwoD_Node_Mesh< _Type >::m_nx, CppNoddy::TwoD_Node_Mesh< _Type >::m_ny, CppNoddy::TwoD_Node_Mesh< _Type >::m_X, CppNoddy::TwoD_Node_Mesh< _Type >::m_Y, and CppNoddy::TwoD_Node_Mesh< _Type >::operator()().

◆ get_xsection_at_xnode()

template<typename _Type >
OneD_Node_Mesh< _Type > CppNoddy::TwoD_Node_Mesh< _Type >::get_xsection_at_xnode ( const std::size_t  nodex) const

Get a cross section of the 2D mesh at a specified (constant) x node.

Parameters
nodexThe x nodal index at which the cross section is to be taken
Returns
A 1D nodal mesh

Definition at line 299 of file TwoD_Node_Mesh.cpp.

299 {
300 OneD_Node_Mesh<_Type> xsection(m_Y, m_nv);
301 for(std::size_t nodey = 0; nodey < m_ny; ++nodey) {
302 xsection.set_nodes_vars(nodey, this -> get_nodes_vars(nodex, nodey));
303 }
304 return xsection;
305 }
DenseVector< _Type > get_nodes_vars(const std::size_t nodex, const std::size_t nodey) const
Get the variables stored at A SPECIFIED node – equivalent to mesh(nodex,nodey).

References CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::set_nodes_vars().

◆ get_xsection_at_ynode()

template<typename _Type >
OneD_Node_Mesh< _Type > CppNoddy::TwoD_Node_Mesh< _Type >::get_xsection_at_ynode ( const std::size_t  nodey) const

Get a cross section of the 2D mesh at a specified (constant) y node.

Parameters
nodeyThe y nodal index at which the cross section is to be taken
Returns
A 1D nodal mesh

Definition at line 308 of file TwoD_Node_Mesh.cpp.

308 {
309 OneD_Node_Mesh<_Type> xsection(m_X, m_nv);
310 for(std::size_t nodex = 0; nodex < m_nx; ++nodex) {
311 xsection.set_nodes_vars(nodex, this -> get_nodes_vars(nodex, nodey));
312 }
313 return xsection;
314 }

References CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::set_nodes_vars().

Referenced by CppNoddy::TwoD_Node_Mesh< _Type >::get_interpolated_vars(), and CppNoddy::FT::idft_with_ishift().

◆ max_abs()

template<typename _Type >
double CppNoddy::TwoD_Node_Mesh< _Type >::max_abs ( unsigned  var)
inline

Find the maximum stored absolute value in the mesh for a given variable – no interpolation is used.

Parameters
varThe variable index whose maximum is being asked for
Returns
The value of the maximum (abs value)

Definition at line 237 of file TwoD_Node_Mesh.h.

237 {
238 double max(0.0);
239 // step through the nodes
240 for(unsigned nodex = 0; nodex < m_X.size(); ++nodex) {
241 for(unsigned nodey = 0; nodey < m_Y.size(); ++nodey) {
242 if(std::abs(m_vars[(nodex * m_ny + nodey) * m_nv + var ]) > max) {
243 max = std::abs(m_vars[(nodex * m_ny + nodey) * m_nv + var ]);
244 }
245 }
246 }
247 return max;
248 }

References CppNoddy::TwoD_Node_Mesh< _Type >::m_nv, CppNoddy::TwoD_Node_Mesh< _Type >::m_ny, CppNoddy::TwoD_Node_Mesh< _Type >::m_vars, CppNoddy::TwoD_Node_Mesh< _Type >::m_X, CppNoddy::TwoD_Node_Mesh< _Type >::m_Y, and CppNoddy::DenseVector< _Type >::size().

Referenced by main().

◆ max_abs_real_part() [1/3]

template<typename _Type >
double CppNoddy::TwoD_Node_Mesh< _Type >::max_abs_real_part ( unsigned  var)

Find the maximum stored absolute value in the mesh for a given variable – no interpolation is used.

Parameters
varThe variable index whose maximum is being asked for
Returns
The value of the maximum (abs value)

Referenced by CppNoddy::TwoD_Node_Mesh< _Type >::normalise_real_part().

◆ max_abs_real_part() [2/3]

double CppNoddy::TwoD_Node_Mesh< D_complex >::max_abs_real_part ( unsigned  var)

Definition at line 374 of file TwoD_Node_Mesh.cpp.

374 {
375 double max(0.0);
376 // step through the nodes
377 for(unsigned nodex = 0; nodex < m_X.size(); ++nodex) {
378 for(unsigned nodey = 0; nodey < m_Y.size(); ++nodey) {
379 if(std::abs(m_vars[(nodex * m_ny + nodey) * m_nv + var ].real()) > max) {
380 max = std::abs(m_vars[(nodex * m_ny + nodey) * m_nv + var ].real());
381 }
382 }
383 }
384 return max;
385 }

◆ max_abs_real_part() [3/3]

double CppNoddy::TwoD_Node_Mesh< double >::max_abs_real_part ( unsigned  var)

Definition at line 388 of file TwoD_Node_Mesh.cpp.

388 {
389#ifdef PARANOID
390 // check start & end
391 std::string problem;
392 problem = " The TwoD_Node_Mesh.max_abs_real_part method has been called for \n";
393 problem += " a mesh with element type of double (rather than D_complex).";
394 throw ExceptionRuntime(problem);
395#endif
396 // just call the max_abs
397 return max_abs(var);
398 }
double max_abs(unsigned var)
Find the maximum stored absolute value in the mesh for a given variable – no interpolation is used.

◆ normalise() [1/3]

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::normalise ( const std::size_t &  var)

Normalise all data in the mesh based on one variable.

Parameters
varThis var will have its peak (absolute) value as +/-unity following the normalisation. All other variables will also be rescaled by the same amount.

◆ normalise() [2/3]

void CppNoddy::TwoD_Node_Mesh< double >::normalise ( const std::size_t &  var)

Definition at line 339 of file TwoD_Node_Mesh.cpp.

339 {
340 double maxval(max_abs(var));
341 m_vars.scale(1./maxval);
342 }

◆ normalise() [3/3]

void CppNoddy::TwoD_Node_Mesh< D_complex >::normalise ( const std::size_t &  var)

Definition at line 345 of file TwoD_Node_Mesh.cpp.

345 {
346 unsigned max_nx(0);
347 unsigned max_ny(0);
348 double max(0.0);
349 // step through the nodes
350 for(unsigned nodex = 0; nodex < m_X.size(); ++nodex) {
351 for(unsigned nodey = 0; nodey < m_Y.size(); ++nodey) {
352 if(std::abs(m_vars[(nodex * m_ny + nodey) * m_nv + var ]) > max) {
353 max = std::abs(m_vars[(nodex * m_ny + nodey) * m_nv + var ]);
354 max_nx = nodex;
355 max_ny = nodey;
356 }
357 }
358 }
359 D_complex factor(m_vars[(max_nx * m_ny + max_ny) * m_nv + var ]);
360 std::cout << "[DEBUG] Normalise factor = " << factor << "\n";
361 m_vars.scale(1./factor);
362 // D_complex max_elt = m_vars[(max_nx * m_ny + max_ny) * m_nv + var ];
363 // std::cout << "[DEBUG] Normalise max_elt = " << max_elt << "\n";
364 // // to here will give |variable|=1 but in general v_r and v+i .ne. 0
365 // // additionally we can scale by a factor of unit magnitude
366 // // in order to make v_r=1 and v_i=0.
367 // m_vars.scale( std::conj(max_elt) );
368 // std::cout << "[DEBUG] Normalise max_elt = " << m_vars[(max_nx * m_ny + max_ny) * m_nv + var ] << "\n";
369 }
std::complex< double > D_complex
A complex double precision number using std::complex.
Definition: Types.h:98

◆ normalise_real_part()

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::normalise_real_part ( const std::size_t &  var)
inline

Normalise the mesh such that the real part of variable 'var' has a real part of unity, and is then the largest real part across the whole mesh.

Parameters
varThe variable to be normalised

Definition at line 224 of file TwoD_Node_Mesh.h.

224 {
225 double maxval(max_abs_real_part(var));
226 m_vars.scale(1./maxval);
227 }
double max_abs_real_part(unsigned var)
Find the maximum stored absolute value in the mesh for a given variable – no interpolation is used.

References CppNoddy::TwoD_Node_Mesh< _Type >::m_vars, and CppNoddy::TwoD_Node_Mesh< _Type >::max_abs_real_part().

◆ operator()() [1/3]

template<typename _Type >
DenseVector< _Type > CppNoddy::TwoD_Node_Mesh< _Type >::operator() ( const std::size_t  nodex,
const std::size_t  nodey 
)
inline

Access operator for a nodal point that returns a vector.

Parameters
nodexThe nodal index value in the first direction
nodeyThe nodal index value in the second direction
Returns
The vector of variables stored at the node

Definition at line 317 of file TwoD_Node_Mesh.h.

317 {
318#ifdef PARANOID
319 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
320 std::string problem;
321 problem = " The TwoD_Node_Mesh.operator() method is trying to \n";
322 problem += " access a nodal point that is not in the mesh. \n";
323 throw ExceptionRange(problem, m_nx, nodex, m_ny, nodey);
324 }
325#endif
326 return get_nodes_vars(nodex, nodey);
327 }

Referenced by CppNoddy::TwoD_Node_Mesh< _Type >::get_xsection_at_x1().

◆ operator()() [2/3]

template<typename _Type >
_Type & CppNoddy::TwoD_Node_Mesh< _Type >::operator() ( const std::size_t  nodex,
const std::size_t  nodey,
const std::size_t  var 
)
inline

Access operator for a nodal point/variable in the mesh.

Parameters
nodexThe nodal index value in the first direction
nodeyThe nodal index value in the second direction
varThe variable index to be accessed

Definition at line 331 of file TwoD_Node_Mesh.h.

331 {
332#ifdef PARANOID
333 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
334 std::string problem;
335 problem = " The TwoD_Node_Mesh.operator() method is trying to \n";
336 problem += " access a nodal point that is not in the mesh. \n";
337 throw ExceptionRange(problem, m_nx, nodex, m_ny, nodey);
338 }
339 if(var > m_nv - 1) {
340 std::string problem;
341 problem = " The TwoD_Node_Mesh.operator() method is trying to \n";
342 problem += " access a variable index that is not in the mesh. \n";
343 throw ExceptionRange(problem, m_nv, var);
344 }
345#endif
346 return m_vars[(nodex * m_ny + nodey) * m_nv + var ];
347 }

◆ operator()() [3/3]

template<typename _Type >
const _Type & CppNoddy::TwoD_Node_Mesh< _Type >::operator() ( const std::size_t  nodex,
const std::size_t  nodey,
const std::size_t  var 
) const
inline

Const access operator for a nodal point/variable in the mesh.

Parameters
nodexThe nodal index value in the first direction
nodeyThe nodal index value in the second direction
varThe variable index to be accessed

Definition at line 350 of file TwoD_Node_Mesh.h.

350 {
351#ifdef PARANOID
352 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
353 std::string problem;
354 problem = " The TwoD_Node_Mesh.operator() method is trying to \n";
355 problem += " access a nodal point that is not in the mesh. \n";
356 throw ExceptionRange(problem, m_nx, nodex, m_ny, nodey);
357 }
358 if(var > m_nv - 1) {
359 std::string problem;
360 problem = " The TwoD_Node_Mesh.operator() method is trying to \n";
361 problem += " access a variable index that is not in the mesh. \n";
362 throw ExceptionRange(problem, m_nv, var);
363 }
364#endif
365 return m_vars[(nodex * m_ny + nodey) * m_nv + var ];
366 }

◆ read() [1/3]

void CppNoddy::TwoD_Node_Mesh< double >::read ( std::string  filename,
bool  reset 
)

Definition at line 482 of file TwoD_Node_Mesh.cpp.

482 {
483 std::ifstream dump;
484 dump.open(filename.c_str());
485 if(dump.good() != true) {
486 std::string problem;
487 problem = " The TwoD_Node_Mesh.read method is trying to read a \n";
488 problem += " file (" + filename + ") that doesn't exist.\n";
489 throw ExceptionRuntime(problem);
490 }
491 dump.precision(15);
492 dump.setf(std::ios::showpoint);
493 dump.setf(std::ios::showpos);
494 dump.setf(std::ios::scientific);
495 for(std::size_t i = 0; i < m_nx; ++i) {
496 for(std::size_t j = 0; j < m_ny; ++j) {
497 double x, y;
498 dump >> x;
499 dump >> y;
500 for(std::size_t var = 0; var < m_nv; ++var) {
501 double value;
502 dump >> value;
503 m_vars[(i * m_ny + j) * m_nv + var ] = value;
504 }
505 if(reset != true) {
506 // if not reseting the mesh we should check the node positions
507 if((std::fabs(x - m_X[ i ]) > 1.e-6) || (std::fabs(y - m_Y[ j ]) > 1.e-6)) {
508 std::cout << " Read x = " << x << " Expected x = " << m_X[ i ] << "; Read y = " << y << " Expected y = " << m_Y[ j ] << " \n";
509 std::cout << " Absolute differences are " << fabs(x - m_X[i]) << " and " << fabs(y - m_Y[j]) << "\n";
510 std::string problem;
511 problem = " The TwoD_Node_Mesh.read method is trying to read a \n";
512 problem += " file whose nodal points are in a different position. \n";
513 throw ExceptionRuntime(problem);
514 }
515 } else {
516 m_X[ i ] = x;
517 m_Y[ j ] = y;
518 }
519 }
520 }
521 }

◆ read() [2/3]

void CppNoddy::TwoD_Node_Mesh< D_complex >::read ( std::string  filename,
bool  reset 
)

Definition at line 525 of file TwoD_Node_Mesh.cpp.

525 {
526 std::ifstream dump;
527 dump.open(filename.c_str());
528 dump.precision(15);
529 dump.setf(std::ios::showpoint);
530 dump.setf(std::ios::showpos);
531 dump.setf(std::ios::scientific);
532 //
533 // 18/06/2017: switched i and j below for consistency with double
534 //
535 for(std::size_t i = 0; i < m_nx; ++i) {
536 for(std::size_t j = 0; j < m_ny; ++j) {
537 double x, y;
538 dump >> x;
539 dump >> y;
540 for(std::size_t var = 0; var < m_nv; ++var) {
541 double value_r, value_i;
542 dump >> value_r;
543 dump >> value_i;
544 m_vars[(i * m_ny + j) * m_nv + var ] = D_complex(value_r, value_i);
545 }
546 if(reset != true) {
547 // if not reseting the mesh we should check the node positions
548 if((std::fabs(x - m_X[ i ]) > 1.e-6) || (std::fabs(y - m_Y[ j ]) > 1.e-6)) {
549 std::cout << " Read x = " << x << " Expected x = " << m_X[ i ] << "; Read y = " << y << " Expected y = " << m_Y[ j ] << " \n";
550 std::cout << " Absolute differences are " << fabs(x - m_X[i]) << " and " << fabs(y - m_Y[j]) << "\n";
551 std::string problem;
552 problem = " The TwoD_Node_Mesh.read method is trying to read a \n";
553 problem += " file whose nodal points are in a different position. \n";
554 throw ExceptionRuntime(problem);
555 }
556 } else {
557 m_X[ i ] = x;
558 m_Y[ j ] = y;
559 }
560 }
561 }
562 }

◆ read() [3/3]

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::read ( std::string  filename,
const bool  reset = false 
)

A simple method for reading data from a file.

Parameters
filenameThe filename to write the data to (will overwrite)
resetWill reset the nodal positions using those from the file

Referenced by CppNoddy::TwoD_Node_Mesh< _Type >::TwoD_Node_Mesh().

◆ remesh1()

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::remesh1 ( const DenseVector< double > &  newX,
const DenseVector< double > &  newY 
)

Interpolate this mesh data (bilinearly) into a new mesh with nodal points defined in the argument list.

Not written to be efficient, so you probably don't want to do any repeated calls with this method.

Parameters
newXThe x-nodal coordinates to be used in the new mesh.
newYThe y-nodal coordinates to be used in the new mesh.

Definition at line 99 of file TwoD_Node_Mesh.cpp.

99 {
100#ifdef PARANOID
101 // check start & end
102 if(std::abs(m_X[ 0 ] - newX[ 0 ]) > 1.e-10 ||
103 std::abs(m_X[ m_X.size() - 1 ] - newX[ newX.size() - 1 ]) > 1.e-10) {
104 std::string problem;
105 problem = " The TwoD_Node_Mesh.remesh1 method has been called with \n";
106 problem += " a passed X coordinate vector that has different start and/or \n";
107 problem += " end points from the instantiated object. \n";
108 throw ExceptionRuntime(problem);
109 }
110 // check monotonic node positions
111 for(std::size_t i = 0; i < newX.size() - 1; ++i) {
112 if(newX[ i ] >= newX[ i + 1 ]) {
113 std::string problem;
114 problem = " The TwoD_Node_Mesh.remesh1 method has been passed \n";
115 problem += " a non-monotonic X coordinate vector. \n";
116 problem += Utility::stringify(newX[ i ], 6) + " vs. " + Utility::stringify(newX[ i + 1 ], 6);
117 throw ExceptionRuntime(problem);
118 }
119 }
120 // check start and end
121 if(std::abs(m_Y[ 0 ] - newY[ 0 ]) > 1.e-10 ||
122 std::abs(m_Y[ m_Y.size() - 1 ] - newY[ newY.size() - 1 ]) > 1.e-10) {
123 std::string problem;
124 problem = " The TwoD_Node_Mesh.remesh1 method has been called with \n";
125 problem += " a passed Y coordinate vector that has different start and/or \n";
126 problem += " end points from the instantiated object. \n";
127 throw ExceptionRuntime(problem);
128 }
129 // check monotonic node positions
130 for(std::size_t i = 0; i < newY.size() - 1; ++i) {
131 if(newY[ i ] >= newY[ i + 1 ]) {
132 std::string problem;
133 problem = " The TwoD_Node_Mesh.remesh1 method has been passed \n";
134 problem += " a non-monotonic Y coordinate vector. \n";
135 problem += Utility::stringify(newY[ i ], 6) + " vs. " + Utility::stringify(newY[ i + 1 ], 6);
136 throw ExceptionRuntime(problem);
137 }
138 }
139#endif
140
141 // new variables storage
142 DenseVector<_Type> newvars(newX.size() * newY.size() * m_nv, 0.0);
143
144 // left boundary
145 {
146 std::size_t xnode(0);
147 // bottom left corner copy
148 for(unsigned var = 0; var < m_nv; ++var) {
149 newvars[(xnode * newY.size() + 0) * m_nv + var ] = get_nodes_vars(0, 0)[ var ];
150 }
151 for(std::size_t ynode = 1; ynode < newY.size() - 1; ++ynode) {
152 std::size_t left_i(0); // bracketing index
153 std::size_t below_j(0); // bracketing index
154 double deltaY(0.0);
155 // loop through the source mesh and find the bracket-nodes
156 for(std::size_t j = 0; j < m_Y.size() - 1; ++j) {
157 if((m_Y[ j ] <= newY[ ynode ]) && (newY[ ynode ] < m_Y[ j + 1 ])) {
158 below_j = j;
159 deltaY = newY[ ynode ] - m_Y[ j ];
160 }
161 }
162 DenseVector<_Type> dvarsdY = (get_nodes_vars(left_i, below_j + 1) - get_nodes_vars(left_i, below_j))
163 / (coord(left_i, below_j + 1).second - coord(left_i, below_j).second);
164 DenseVector<_Type> interpolated_vars = get_nodes_vars(left_i, below_j) + dvarsdY * deltaY;
165 for(unsigned var = 0; var < m_nv; ++var) {
166 newvars[(xnode * newY.size() + ynode) * m_nv + var ] = interpolated_vars[ var ];
167 }
168 }
169 // top left corner copy
170 for(unsigned var = 0; var < m_nv; ++var) {
171 newvars[(xnode * newY.size() + newY.size() - 1) * m_nv + var ] = get_nodes_vars(0, m_ny - 1)[ var ];
172 }
173 }
174 // right boundary
175 {
176 std::size_t xnode(newX.size() - 1);
177 // bottom right corner copy
178 for(unsigned var = 0; var < m_nv; ++var) {
179 newvars[(xnode * newY.size() + 0) * m_nv + var ] = get_nodes_vars(m_nx - 1, 0)[ var ];
180 }
181 for(std::size_t ynode = 1; ynode < newY.size() - 1; ++ynode) {
182 std::size_t left_i(m_X.size() - 1); // bracketing index
183 std::size_t below_j(0); // bracketing index
184 double deltaY(0.0);
185 // loop through the source mesh and find the bracket-nodes
186 for(std::size_t j = 0; j < m_Y.size() - 1; ++j) {
187 if((m_Y[ j ] <= newY[ ynode ]) && (newY[ ynode ] < m_Y[ j + 1 ])) {
188 below_j = j;
189 deltaY = newY[ ynode ] - m_Y[ j ];
190 }
191 }
192 DenseVector<_Type> dvarsdY = (get_nodes_vars(left_i, below_j + 1) - get_nodes_vars(left_i, below_j))
193 / (coord(left_i, below_j + 1).second - coord(left_i, below_j).second);
194 DenseVector<_Type> interpolated_vars = get_nodes_vars(left_i, below_j) + dvarsdY * deltaY;
195 for(unsigned var = 0; var < m_nv; ++var) {
196 newvars[(xnode * newY.size() + ynode) * m_nv + var ] = interpolated_vars[ var ];
197 }
198 }
199 // bottom right corner copy
200 for(unsigned var = 0; var < m_nv; ++var) {
201 newvars[(xnode * newY.size() + newY.size() - 1) * m_nv + var ] = get_nodes_vars(m_nx - 1, m_ny - 1)[ var ];
202 }
203 }
204 // bottom boundary
205 {
206 std::size_t ynode(0);
207 for(std::size_t xnode = 1; xnode < newX.size() - 1; ++xnode) {
208 std::size_t left_i(0); // bracketing index
209 std::size_t below_j(0); // bracketing index
210 double deltaX(0.0);
211 // loop through the source mesh and find the bracket-nodes
212 for(std::size_t i = 0; i < m_X.size() - 1; ++i) {
213 if((m_X[ i ] <= newX[ xnode ]) && (newX[ xnode ] < m_X[ i + 1 ])) {
214 left_i = i;
215 deltaX = newX[ xnode ] - m_X[ i ];
216 }
217 }
218 DenseVector<_Type> dvarsdX = (get_nodes_vars(left_i + 1, below_j) - get_nodes_vars(left_i, below_j))
219 / (coord(left_i + 1, below_j).first - coord(left_i, below_j).first);
220 DenseVector<_Type> interpolated_vars = get_nodes_vars(left_i, below_j) + dvarsdX * deltaX;
221 for(unsigned var = 0; var < m_nv; ++var) {
222 newvars[(xnode * newY.size() + ynode) * m_nv + var ] = interpolated_vars[ var ];
223 }
224 }
225 }
226 // top boundary
227 {
228 std::size_t ynode(newY.size() - 1);
229 for(std::size_t xnode = 1; xnode < newX.size() - 1; ++xnode) {
230 std::size_t left_i(0); // bracketing index
231 std::size_t below_j(m_Y.size() - 1); // bracketing index
232 double deltaX(0.0);
233 // loop through the source mesh and find the bracket-nodes
234 for(std::size_t i = 0; i < m_X.size() - 1; ++i) {
235 if((m_X[ i ] <= newX[ xnode ]) && (newX[ xnode ] < m_X[ i + 1 ])) {
236 left_i = i;
237 deltaX = newX[ xnode ] - m_X[ i ];
238 }
239 }
240 DenseVector<_Type> dvarsdX = (get_nodes_vars(left_i + 1, below_j) - get_nodes_vars(left_i, below_j))
241 / (coord(left_i + 1, below_j).first - coord(left_i, below_j).first);
242 DenseVector<_Type> interpolated_vars = get_nodes_vars(left_i, below_j) + dvarsdX * deltaX;
243 for(unsigned var = 0; var < m_nv; ++var) {
244 newvars[(xnode * newY.size() + ynode) * m_nv + var ] = interpolated_vars[ var ];
245 }
246 }
247 }
248 // loop thru interior nodes of the destination mesh one node at a time
249 for(std::size_t xnode = 1; xnode < newX.size() - 1; ++xnode) {
250 for(std::size_t ynode = 1; ynode < newY.size() - 1; ++ynode) {
251 std::size_t left_i(0); // bracketing index
252 std::size_t below_j(0); // bracketing index
253 // loop through the source mesh and find the bracket-nodes
254 for(std::size_t i = 0; i < m_X.size() - 1; ++i) {
255 if((m_X[ i ] <= newX[ xnode ]) && (newX[ xnode ] < m_X[ i + 1 ])) {
256 left_i = i;
257 }
258 }
259 // loop through the source mesh and find the bracket-nodes
260 for(std::size_t j = 0; j < m_Y.size() - 1; ++j) {
261 if((m_Y[ j ] <= newY[ ynode ]) && (newY[ ynode ] < m_Y[ j + 1 ])) {
262 below_j = j;
263 }
264 }
265 DenseVector<_Type> dvarsdX = (get_nodes_vars(left_i + 1, below_j) - get_nodes_vars(left_i, below_j))
266 / (coord(left_i + 1, below_j).first - coord(left_i, below_j).first);
267 DenseVector<_Type> dvarsdY = (get_nodes_vars(left_i, below_j + 1) - get_nodes_vars(left_i, below_j))
268 / (coord(left_i, below_j + 1).second - coord(left_i, below_j).second);
269
270 DenseVector<_Type> interpolated_vars_bottom =
271 (get_nodes_vars(left_i, below_j) * (coord(left_i + 1, below_j).first - newX[ xnode ])
272 + get_nodes_vars(left_i + 1, below_j) * (newX[ xnode ] - coord(left_i, below_j).first)) /
273 (coord(left_i + 1, below_j).first - coord(left_i, below_j).first);
274
275 DenseVector<_Type> interpolated_vars_top =
276 (get_nodes_vars(left_i, below_j + 1) * (coord(left_i + 1, below_j + 1).first - newX[ xnode ])
277 + get_nodes_vars(left_i + 1, below_j + 1) * (newX[ xnode ] - coord(left_i, below_j + 1).first)) /
278 (coord(left_i + 1, below_j + 1).first - coord(left_i, below_j + 1).first);
279
280 DenseVector<_Type> interpolated_vars =
281 (interpolated_vars_bottom * (coord(left_i, below_j + 1).second - newY[ ynode ])
282 + interpolated_vars_top * (newY[ ynode ] - coord(left_i, below_j).second)) /
283 (coord(left_i, below_j + 1).second - coord(left_i, below_j).second);
284
285 for(unsigned var = 0; var < m_nv; ++var) {
286 newvars[(xnode * newY.size() + ynode) * m_nv + var ] = interpolated_vars[ var ];
287 }
288 }
289 }
290 // finally replace the old nodes with the new ones
291 m_X = newX;
292 m_Y = newY;
293 m_nx = newX.size();
294 m_ny = newY.size();
295 m_vars = newvars;
296 }
std::pair< double, double > coord(const std::size_t nodex, const std::size_t nodey) const
Access the nodal position - as a pair.
std::string stringify(const int &val)
Return an integer value as a string - useful for file naming.
Definition: Utility.cpp:193

References CppNoddy::DenseVector< _Type >::size(), and CppNoddy::Utility::stringify().

Referenced by main().

◆ scale()

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::scale ( const _Type &  value)
inline

Calls the vector "scale" method for the whole mesh data.

Parameters
valueThe value to be used in the scale operation

Definition at line 216 of file TwoD_Node_Mesh.h.

216 {
217 m_vars.scale(value);
218 }

References CppNoddy::TwoD_Node_Mesh< _Type >::m_vars.

◆ set_nodes_vars()

template<typename _Type >
void CppNoddy::TwoD_Node_Mesh< _Type >::set_nodes_vars ( const std::size_t  nodex,
const std::size_t  nodey,
const DenseVector< _Type > &  U 
)

Set the variables stored at A SPECIFIED node.

Parameters
nodexThe x nodal index to be set
nodeyThe y nodal index to be set
UThe vector of VARIABLES to be written to this nodal point

Definition at line 20 of file TwoD_Node_Mesh.cpp.

20 {
21#ifdef PARANOID
22 if(U.size() > m_nv) {
23 std::string problem;
24 problem = " The TwoD_Node_Mesh.set_nodes_vars method is trying to use a \n";
25 problem += " vector that has more entries than variables stored in the mesh. \n";
26 throw ExceptionRuntime(problem);
27 }
28#endif
29 // assign contents of U to the member data
30 std::size_t offset((nodex * m_ny + nodey) * m_nv);
31 for(std::size_t var = 0; var < m_nv; ++var) {
32 m_vars[ offset++ ] = U[ var ];
33 }
34 }
@ U
Definition: BVPKarman.cpp:20

References U.

Referenced by CppNoddy::FT::dft_with_shift(), and CppNoddy::FT::idft_with_ishift().

◆ xcoord()

template<typename _Type >
double & CppNoddy::TwoD_Node_Mesh< _Type >::xcoord ( const std::size_t  nodex)
inline

Access the x-nodal (first index) position.

Parameters
nodexThe x nodal index
Returns
The x-coordinate of the node

Definition at line 98 of file TwoD_Node_Mesh.h.

98 {
99 return m_X[nodex];
100 }

References CppNoddy::TwoD_Node_Mesh< _Type >::m_X.

Referenced by CppNoddy::FT::dft_with_shift(), and CppNoddy::FT::idft_with_ishift().

◆ xnodes()

template<typename _Type >
const DenseVector< double > & CppNoddy::TwoD_Node_Mesh< _Type >::xnodes

Access the vector of x-nodal positions.

Returns
A vector of the nodal positions for this mesh

Definition at line 70 of file TwoD_Node_Mesh.cpp.

70 {
71 return m_X;
72 }

Referenced by CppNoddy::FT::idft_with_ishift().

◆ ycoord()

template<typename _Type >
double & CppNoddy::TwoD_Node_Mesh< _Type >::ycoord ( const std::size_t  nodey)
inline

Access the y-nodal (second index) position.

Parameters
nodexThe y nodal index
Returns
The y-coordinate of the node

Definition at line 105 of file TwoD_Node_Mesh.h.

105 {
106 return m_Y[nodey];
107 }

References CppNoddy::TwoD_Node_Mesh< _Type >::m_Y.

◆ ynodes()

template<typename _Type >
const DenseVector< double > & CppNoddy::TwoD_Node_Mesh< _Type >::ynodes

Access the vector of y-nodal positions.

Returns
A vector of the nodal positions for this mesh

Definition at line 75 of file TwoD_Node_Mesh.cpp.

75 {
76 return m_Y;
77 }

Referenced by CppNoddy::FT::idft_with_ishift().

Member Data Documentation

◆ m_nv

template<typename _Type >
std::size_t CppNoddy::TwoD_Node_Mesh< _Type >::m_nv
protected

◆ m_nx

template<typename _Type >
std::size_t CppNoddy::TwoD_Node_Mesh< _Type >::m_nx
protected

◆ m_ny

template<typename _Type >
std::size_t CppNoddy::TwoD_Node_Mesh< _Type >::m_ny
protected

◆ m_vars

template<typename _Type >
DenseVector<_Type> CppNoddy::TwoD_Node_Mesh< _Type >::m_vars
protected

◆ m_X

template<typename _Type >
DenseVector<double> CppNoddy::TwoD_Node_Mesh< _Type >::m_X
protected

◆ m_Y

template<typename _Type >
DenseVector<double> CppNoddy::TwoD_Node_Mesh< _Type >::m_Y
protected

The documentation for this class was generated from the following files:

© 2012

R.E. Hewitt