4#ifndef TWOD_NODE_MESH_H
5#define TWOD_NODE_MESH_H
18 template <
typename _Type>
27 const std::size_t nvars) :
34 TwoD_Node_Mesh(
const double left,
const double right,
const double bottom,
const double top,
35 const std::size_t nx,
const std::size_t ny,
const std::size_t nvars) :
39 const double delta = (right - left) / (
m_nx - 1);
40 for(std::size_t i = 0; i <
m_nx; ++i) {
46 const double delta = (top - bottom) / (
m_ny - 1);
47 for(std::size_t i = 0; i <
m_ny; ++i) {
56 TwoD_Node_Mesh(std::string filename,
const std::size_t nx,
const std::size_t ny,
const std::size_t nv) :
81 _Type&
operator()(
const std::size_t nodex,
const std::size_t nodey,
const std::size_t var);
87 const _Type&
operator()(
const std::size_t nodex,
const std::size_t nodey,
const std::size_t var)
const;
93 std::pair<double, double>
coord(
const std::size_t nodex,
const std::size_t nodey)
const;
98 double&
xcoord(
const std::size_t nodex ){
105 double&
ycoord(
const std::size_t nodey ){
138 for(
unsigned i = 0; i<
m_nx-1; ++i) {
139 if((
m_X[i]< x) && (
m_X[i+1]>x)) {
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) {
154 void assign(
const _Type elt);
158 std::pair< std::size_t, std::size_t >
get_nnodes()
const;
192 void dump(std::string filename)
const;
197 void dump_var(std::string filename,
const unsigned var)
const;
202 void read(std::string filename,
const bool reset =
false);
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) {
256 const double tol(1.e-10);
258 if((x <
m_X[0] - tol) || (x >
m_X[
m_nx-1] + tol)) {
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";
265 if((y <
m_Y[0] - tol) || (y >
m_Y[
m_ny-1] + tol)) {
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";
272 for(
unsigned j = 0; j <
m_ny-1; ++j) {
273 if((y >=
m_Y[j] - tol) && (y <=
m_Y[j+1] + tol)) {
288 problem =
" The TwoD_Node_Mesh.get_interpolated_vars method is broken.\n";
294 const double y1 =
m_Y[ bottom_j ];
295 const double y2 =
m_Y[ bottom_j+1 ];
316 template <
typename _Type>
319 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
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";
326 return get_nodes_vars(nodex, nodey);
330 template <
typename _Type>
333 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
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";
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";
346 return m_vars[(nodex * m_ny + nodey) * m_nv + var ];
349 template <
typename _Type>
352 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
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";
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";
365 return m_vars[(nodex * m_ny + nodey) * m_nv + var ];
368 template <
typename _Type>
371 if(nodex > m_nx - 1 || nodey > m_ny - 1) {
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";
378 std::pair< double, double > pos;
379 pos.first = m_X[ nodex ];
380 pos.second = m_Y[ nodey ];
A matrix class that constructs a DENSE matrix as an STL Vector of DenseVectors.
Specification for a templated DenseVector class – a dense, dynamic, vector object.
A specification for a one dimensional mesh object.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
An DenseVector class – a dense vector object.
void push_back(const _Type &fill)
A pass-thru definition of push_back.
void reserve(const std::size_t &n)
Reserve space for the vector.
std::size_t size() const
A pass-thru definition to get the size of the vector.
An exception to indicate that a CppNoddy container has been accessed with index/indices outside the m...
A generic runtime exception.
A one dimensional mesh utility object.
DenseVector< _Type > get_interpolated_vars(const _Xtype &pos) const
Get the variable data at an interpolated position using a first order scheme.
A two dimensional mesh utility object.
std::pair< std::size_t, std::size_t > get_nnodes() const
Get the number of nodes in the two directions of the 2D mesh.
DenseVector< double > m_Y
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.
DenseVector< _Type > m_vars
virtual ~TwoD_Node_Mesh()
dtor
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 spec...
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,...
DenseVector< _Type > operator()(const std::size_t nodex, const std::size_t nodey)
Access operator for a nodal point that returns a vector.
TwoD_Node_Mesh(std::string filename, const std::size_t nx, const std::size_t ny, const std::size_t nv)
const DenseVector< double > & xnodes() const
Access the vector of x-nodal positions.
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.
void assign(const _Type elt)
Assign an element to all entries in the mesh.
double max_abs_real_part(unsigned var)
Find the maximum stored absolute value in the mesh for a given variable – no interpolation is used.
void read(std::string filename, const bool reset=false)
A simple method for reading data from a file.
void normalise(const std::size_t &var)
Normalise all data in the mesh based on one variable.
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).
std::size_t get_nvars() const
Get the number of variables that are stored at each node.
const DenseVector< double > & ynodes() const
Access the vector of y-nodal positions.
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 lis...
void dump_gnu(std::string filename) const
A simple method for dumping data to a file for gnuplot surface plotting.
double & xcoord(const std::size_t nodex)
Access the x-nodal (first index) position.
void scale(const _Type &value)
Calls the vector "scale" method for the whole mesh data.
TwoD_Node_Mesh(const DenseVector< double > &x_nodes, const DenseVector< double > &y_nodes, const std::size_t nvars)
ctor
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.
void dump() const
A simple method for dumping data to std::cout.
double & ycoord(const std::size_t nodey)
Access the y-nodal (second index) position.
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
DenseVector< _Type > get_interpolated_vars(const double &x, const double &y)
Get a bilinearly interpolated value at a specified point.
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.
double max_abs(unsigned var)
Find the maximum stored absolute value in the mesh for a given variable – no interpolation is used.
DenseVector< double > m_X
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.
std::pair< double, double > coord(const std::size_t nodex, const std::size_t nodey) const
Access the nodal position - as a pair.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...