File MeshQuad4.h#

Generate simple meshes of 4-noded quadrilateral elements in 2d (GooseFEM::Mesh::ElementType::Quad4).

Copyright

Copyright 2017. Tom de Geus. All rights reserved.

License: This project is released under the GNU Public License (GPLv3).

namespace GooseFEM

Toolbox to perform finite element computations.

namespace Mesh

Generic mesh operations, and simple mesh definitions.

namespace Quad4#

Simple meshes of 4-noded quadrilateral elements in 2d (ElementType::Quad4).

class FineLayer : public GooseFEM::Mesh::RegularBase2d<FineLayer>
#include <GooseFEM/MeshQuad4.h>

Mesh with fine middle layer, and coarser elements towards the top and bottom.

Public Functions

FineLayer() = default#
inline FineLayer(size_t nelx, size_t nely, double h = 1.0, size_t nfine = 1)

Constructor.

Parameters
  • nelx – Number of elements (along the middle layer) in horizontal (x) direction.

  • nely – Approximate equivalent number of elements in vertical (y) direction.

  • h – Edge size (width == height) of elements along the weak layer.

  • nfine – Extra number of fine layers around the middle layer. By default the element size is kept smaller than the distance to the middle layer.

template<class C, class E, std::enable_if_t<xt::is_xexpression<C>::value, bool> = true>
inline FineLayer(const C &coor, const E &conn)

Reconstruct class for given coordinates / connectivity.

Template Parameters
Parameters
  • coor – Nodal coordinates [nnode, ndim] with ndim == 2.

  • conn – Connectivity [nne, nne] with nne == 4.

inline const array_type::tensor<size_t, 1> &elemrow_nhx() const

Edge size in x-direction of a block, in units of h, per row of blocks.

Note that a block is equal to an element except in refinement layers where it contains three elements.

Returns

List of size equal to the number of rows of blocks.

inline const array_type::tensor<size_t, 1> &elemrow_nhy() const

Edge size in y-direction of a block, in units of h, per row of blocks.

Note that a block is equal to an element except in refinement layers where it contains three elements.

Returns

List of size equal to the number of rows of blocks.

inline const array_type::tensor<int, 1> &elemrow_type() const

Per row of blocks: -1: normal layer 0: transition layer to match coarse and finer element on the previous/next row.

Returns

List of size equal to the number of rows of blocks.

inline const array_type::tensor<size_t, 1> &elemrow_nelem() const

Number of elements per row of blocks.

Note that a block is equal to an element except in refinement layers where it contains three elements.

Returns

List of size equal to the number of rows of blocks.

inline array_type::tensor<size_t, 1> elementsMiddleLayer() const

Elements in the middle (fine) layer.

Returns

List of element numbers.

inline array_type::tensor<size_t, 1> elementsLayer(size_t layer) const

Elements along a layer.

Returns

List of element numbers.

inline array_type::tensor<size_t, 1> elementgrid_ravel(std::vector<size_t> start_stop_rows, std::vector<size_t> start_stop_cols) const

Select region of elements from ‘matrix’ of element numbers.

Returns

List of element numbers.

inline array_type::tensor<size_t, 1> elementgrid_around_ravel(size_t e, size_t size, bool periodic = true)

Select region of elements from ‘matrix’ of element numbers around an element: square box with edge-size (2 * size + 1) * h, around element.

Parameters
  • e – The element around which to select elements.

  • size – Edge size of the square box encapsulating the selected element.

  • periodic – Assume the mesh periodic.

Returns

List of elements.

inline array_type::tensor<size_t, 1> elementgrid_leftright(size_t e, size_t left, size_t right, bool periodic = true)

Select region of elements from ‘matrix’ of element numbers around an element: left/right from element (on the same layer).

Parameters
  • e – The element around which to select elements.

  • left – Number of elements to select to the left.

  • right – Number of elements to select to the right.

  • periodic – Assume the mesh periodic.

Returns

List of elements.

inline array_type::tensor<size_t, 1> roll(size_t n)

Mapping to ‘roll’ periodically in the x-direction,.

Returns

element mapping, such that: new_elemvar = elemvar[elem_map]

Private Functions

inline size_t nelx_impl() const#
inline size_t nely_impl() const#
inline ElementType elementType_impl() const#
inline array_type::tensor<double, 2> coor_impl() const#
inline array_type::tensor<size_t, 2> conn_impl() const#
inline array_type::tensor<size_t, 1> nodesBottomEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesTopEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesLeftEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesRightEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesBottomOpenEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesTopOpenEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesLeftOpenEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesRightOpenEdge_impl() const#
inline size_t nodesBottomLeftCorner_impl() const#
inline size_t nodesBottomRightCorner_impl() const#
inline size_t nodesTopLeftCorner_impl() const#
inline size_t nodesTopRightCorner_impl() const#
inline void init(size_t nelx, size_t nely, double h, size_t nfine = 1)#

Constructor.

Parameters
  • nelx – Number of elements (along the middle layer) in horizontal (x) direction.

  • nely – Approximate equivalent number of elements in vertical (y) direction.

  • h – Edge size (width == height) of elements along the weak layer.

  • nfine – Extra number of fine layers around the middle layer. By default the element size is kept smaller than the distance to the middle layer.

template<class C, class E>
inline void init_by_mapping(const C &coor, const E &conn)#

Reconstruct class for given coordinates / connectivity.

Template Parameters
Parameters
  • coor – Nodal coordinates [nnode, ndim] with ndim == 2.

  • conn – Connectivity [nne, nne] with nne == 4.

Private Members

double m_h#

See h()

size_t m_nelem#

See nelem()

size_t m_nnode#

See nnode()

size_t m_nne#

See nne()

size_t m_ndim#

See ndim()

double m_Lx#

Mesh size in x-direction.

array_type::tensor<size_t, 1> m_layer_nelx#

See elemrow_nelem().

array_type::tensor<size_t, 1> m_nhx#

See elemrow_nhx().

array_type::tensor<size_t, 1> m_nhy#

See elemrow_nhy().

array_type::tensor<size_t, 1> m_nnd#

num. nodes in main node layer (per node layer in “y”)

array_type::tensor<int, 1> m_refine#

See elemrow_type().

array_type::tensor<size_t, 1> m_startElem#

start element (per element layer in “y”)

array_type::tensor<size_t, 1> m_startNode#

start node (per node layer in “y”)

Friends

friend class RegularBase< FineLayer >
friend class RegularBase2d< FineLayer >
friend class GooseFEM::Mesh::Quad4::Map::FineLayer2Regular
class Regular : public GooseFEM::Mesh::RegularBase2d<Regular>
#include <GooseFEM/MeshQuad4.h>

Regular mesh: equi-sized elements.

Public Functions

Regular() = default#
inline Regular(size_t nelx, size_t nely, double h = 1.0)

Constructor.

Parameters
  • nelx – Number of elements in horizontal (x) direction.

  • nely – Number of elements in vertical (y) direction.

  • h – Edge size (width == height).

inline array_type::tensor<size_t, 2> elementgrid() const

Element numbers as ‘matrix’.

Returns

[nely, nelx].

Private Functions

inline size_t nelx_impl() const#
inline size_t nely_impl() const#
inline ElementType elementType_impl() const#
inline array_type::tensor<double, 2> coor_impl() const#
inline array_type::tensor<size_t, 2> conn_impl() const#
inline array_type::tensor<size_t, 1> nodesBottomEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesTopEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesLeftEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesRightEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesBottomOpenEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesTopOpenEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesLeftOpenEdge_impl() const#
inline array_type::tensor<size_t, 1> nodesRightOpenEdge_impl() const#
inline size_t nodesBottomLeftCorner_impl() const#
inline size_t nodesBottomRightCorner_impl() const#
inline size_t nodesTopLeftCorner_impl() const#
inline size_t nodesTopRightCorner_impl() const#

Private Members

double m_h#

See h()

size_t m_nelx#

See nelx()

size_t m_nely#

See nely()

size_t m_nelem#

See nelem()

size_t m_nnode#

See nnode()

size_t m_nne#

See nne()

size_t m_ndim#

See ndim()

Friends

friend class RegularBase< Regular >
friend class RegularBase2d< Regular >
namespace Map#

Mesh mappings.

class FineLayer2Regular
#include <GooseFEM/MeshQuad4.h>

Map a FineLayer mesh to a Regular mesh.

The element size of the Regular corresponds to the smallest elements of the FineLayer mesh (along the middle layer).

Public Functions

FineLayer2Regular() = default#
inline FineLayer2Regular(const GooseFEM::Mesh::Quad4::FineLayer &mesh)

Constructors.

Parameters

mesh – The FineLayer mesh.

inline GooseFEM::Mesh::Quad4::Regular regularMesh() const

Obtain the Regular mesh.

Returns

mesh.

inline GooseFEM::Mesh::Quad4::FineLayer fineLayerMesh() const

Obtain the FineLayer mesh (copy of the mesh passed to the constructor).

Returns

mesh.

inline std::vector<std::vector<size_t>> map() const

Get element-mapping: elements of the Regular mesh per element of the FineLayer mesh.

The number of Regular elements varies between elements of the FineLayer mesh.

Returns

[nelem_finelayer, ?]

inline std::vector<std::vector<double>> mapFraction() const

To overlap fraction for each item in the mapping in map().

Returns

[nelem_finelayer, ?]

inline GooseFEM::Mesh::Quad4::Regular getRegularMesh() const

Obtain the Regular mesh.

Returns

mesh.

inline GooseFEM::Mesh::Quad4::FineLayer getFineLayerMesh() const

Obtain the FineLayer mesh (copy of the mesh passed to the constructor).

Returns

mesh.

inline std::vector<std::vector<size_t>> getMap() const

Get element-mapping: elements of the Regular mesh per element of the FineLayer mesh.

The number of Regular elements varies between elements of the FineLayer mesh.

Returns

[nelem_finelayer, ?]

inline std::vector<std::vector<double>> getMapFraction() const

To overlap fraction for each item in the mapping in getMap().

Returns

[nelem_finelayer, ?]

template<class T, size_t rank>
inline array_type::tensor<T, rank> mapToRegular(const array_type::tensor<T, rank> &data) const

Map element quantities to Regular.

The mapping is a bit simplistic: no interpolation is involved, the function just accounts the fraction of overlap between the FineLayer element and the Regular element. The mapping is such that::

 ret[e_regular, ...] <- arg[e_finelayer, ...]

Template Parameters
  • T – type of the data (e.g. double).

  • rank – rank of the data.

Parameters

data – data.

Returns

mapped data.

Private Members

GooseFEM::Mesh::Quad4::FineLayer m_finelayer#

the FineLayer mesh to map

GooseFEM::Mesh::Quad4::Regular m_regular#

the new Regular mesh to which to map

std::vector<std::vector<size_t>> m_elem_regular#

see getMap()

std::vector<std::vector<double>> m_frac_regular#

see getMapFraction()

class RefineRegular
#include <GooseFEM/MeshQuad4.h>

Refine a Regular mesh: subdivide elements in several smaller elements.

Public Functions

RefineRegular() = default#
inline RefineRegular(const GooseFEM::Mesh::Quad4::Regular &mesh, size_t nx, size_t ny)

Constructor.

Parameters
  • mesh – the coarse mesh.

  • nx – for each coarse element: number of fine elements in x-direction.

  • ny – for each coarse element: number of fine elements in y-direction.

inline size_t nx() const

For each coarse element: number of fine elements in x-direction.

Returns

unsigned int (same as used in constructor)

inline size_t ny() const

For each coarse element: number of fine elements in y-direction.

Returns

unsigned int (same as used in constructor)

inline GooseFEM::Mesh::Quad4::Regular coarseMesh() const

Obtain the coarse mesh (copy of the mesh passed to the constructor).

Returns

mesh

inline GooseFEM::Mesh::Quad4::Regular fineMesh() const

Obtain the fine mesh.

Returns

mesh

inline const array_type::tensor<size_t, 2> &map() const

Get element-mapping: elements of the fine mesh per element of the coarse mesh.

Returns

[nelem_coarse, nx() * ny()]

inline GooseFEM::Mesh::Quad4::Regular getCoarseMesh() const

Obtain the coarse mesh (copy of the mesh passed to the constructor).

Returns

mesh

inline GooseFEM::Mesh::Quad4::Regular getFineMesh() const

Obtain the fine mesh.

Returns

mesh

inline const array_type::tensor<size_t, 2> &getMap() const

Get element-mapping: elements of the fine mesh per element of the coarse mesh.

Returns

[nelem_coarse, nx() * ny()]

template<class T, size_t rank>
inline array_type::tensor<T, rank> meanToCoarse(const array_type::tensor<T, rank> &data) const

Compute the mean of the quantity define on the fine mesh when mapped on the coarse mesh.

Template Parameters
  • T – type of the data (e.g. double).

  • rank – rank of the data.

Parameters

data – the data [nelem_fine, …]

Returns

the average data of the coarse mesh [nelem_coarse, …]

template<class T, size_t rank, class S>
inline array_type::tensor<T, rank> averageToCoarse(const array_type::tensor<T, rank> &data, const array_type::tensor<S, rank> &weights) const

Compute the average of the quantity define on the fine mesh when mapped on the coarse mesh.

Template Parameters
  • T – type of the data (e.g. double).

  • rank – rank of the data.

  • S – type of the weights (e.g. double).

Parameters
  • data – the data [nelem_fine, …]

  • weights – the weights [nelem_fine, …]

Returns

the average data of the coarse mesh [nelem_coarse, …]

template<class T, size_t rank>
inline array_type::tensor<T, rank> mapToFine(const array_type::tensor<T, rank> &data) const

Map element quantities to the fine mesh.

The mapping is a bit simplistic: no interpolation is involved. The mapping is such that::

 ret[e_fine, ...] <- data[e_coarse, ...]

Template Parameters
  • T – type of the data (e.g. double).

  • rank – rank of the data.

Parameters

data – the data.

Returns

mapped data.

Private Members

GooseFEM::Mesh::Quad4::Regular m_coarse#

the coarse mesh

GooseFEM::Mesh::Quad4::Regular m_fine#

the fine mesh

size_t m_nx#

see nx()

size_t m_ny#

see ny()

array_type::tensor<size_t, 2> m_coarse2fine#

see getMap()