Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodal fields redesign #77

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
ad10273
lib/mito/fem: quadrature fields should always be named
biancagi May 23, 2024
961b550
lib/mito/fem: remove unused parameter in constructor of class {Quadra…
biancagi May 23, 2024
5d5bf6b
lib/mito/fem: constructor of class {QuadratureField} now takes packin…
biancagi May 23, 2024
63a775a
lib/mito/fem: consistency fixes in class {QuadratureField}
biancagi May 23, 2024
583110e
lib/mito/fem: consistency fixes in class {QuadratureField}
biancagi May 23, 2024
34b455e
lib/mito/fem: use default constructor for class {QuadratureField}
biancagi May 23, 2024
679e7a6
lib/mito/fem: in class {QuadratureField} remove redundant {inline} of…
biancagi May 23, 2024
f5fca26
lib/mito/fem: in class {QuadratureField} remove setter for {name} att…
biancagi May 23, 2024
fe1df66
lib/mito/fem: narrative improvements in class {QuadratureField}
biancagi May 23, 2024
552cc1c
lib/mito/fem: redesign of class {NodalField} based on {pyre::grid}
biancagi May 23, 2024
8be72ff
tests/mito.lib/fem: add test of nodal fields
biancagi May 24, 2024
bf6a896
lib/mito/fem: fix compiler error
biancagi May 24, 2024
56e323f
lib/mito/fem: remove unnecessary include
biancagi May 24, 2024
a4c00bb
lib/mito/io: draft capability to write a nodal field to vtu file
biancagi May 24, 2024
b778351
lib/mito/io: second draft implementation of writing a field to vtu file
biancagi May 25, 2024
56f47ec
lib/mito/io/vtk: remove unnecessary template specialization
biancagi May 25, 2024
0684a60
lib/mito/io/vtk: move {vtkCellPointer} to vtk cell header
biancagi May 25, 2024
f35cd45
lib/mito/fem: redesign class {NodalField} as a mapping between mesh n…
biancagi May 25, 2024
8398733
lib/mito/io/vtk: add possibility to write 1D points
biancagi May 25, 2024
8a652bb
lib/mito/fem: bugfix
biancagi May 26, 2024
204b39b
lib/mito/geometry: publish dimension of physical space in class {Poin…
biancagi May 26, 2024
616b178
lib/mito/geometry: add concepts for a coordinate system and a point c…
biancagi May 26, 2024
1f299a6
lib/mito/io/vtk: split file {writer.h} into {MeshWriter} and {PointCl…
biancagi May 26, 2024
d71cc05
lib/mito/io: move {MeshWriter} and {PointCloudWriter} out of {vtk} di…
biancagi May 27, 2024
d329058
lib/mito/io: move external packages needed from {summit} reader/write…
biancagi May 27, 2024
4895a80
lib/mito/io/summit: add {std} namespace specialization when appropriate
biancagi May 27, 2024
bf2369a
lib/mito/io/summit: use a {set} of points for internal book-keeping
biancagi May 27, 2024
03d4f3e
lib/mito/io: readability improvements
biancagi Jun 1, 2024
41ecbb8
lib/mito/io/vtk: use STL {set} instead of {map}
biancagi Jun 1, 2024
5496474
lib/mito/io/vtk: move {vtk} writers to {vtk} directories
biancagi Jun 3, 2024
f1f7440
lib/mito/io/vtk: refer to attributes in parent class with {this->}
biancagi Jun 3, 2024
bec6b7d
lib/mito/io: make {GridWriter} template with respect to the spatial d…
biancagi Jun 3, 2024
62a1003
lib/mito/io/vtk: add class {FieldWriterVTK}
biancagi Jun 3, 2024
3bbfccc
lib/mito/io/summit: reimplement {summit} mesh writer according to new…
biancagi Jun 3, 2024
b698516
lib/mito/utilities: add forgotten header
biancagi Jun 3, 2024
efe4b9a
lib/mito/io: move {unordered_set} external dependency to {io/external…
biancagi Jun 3, 2024
7d13dea
lib/mito/fem: nodal field factory now infers the space dimension from…
biancagi Jun 3, 2024
c6534c5
lib/mito/fem: use {at} instead of {operator[]} for read-only map access
biancagi Jun 3, 2024
4fb0368
lib/mito/io: readability improvement
biancagi Jun 5, 2024
6f83fef
lib/mito: add {concept} of two types having the same dimension
biancagi Jun 5, 2024
68df98c
lib/mito: draft implementation of reference counted nodes
biancagi Jun 8, 2024
a31e1aa
lib/mito/utilities: add wrapper class for {std::shared_ptr}
biancagi Jun 8, 2024
655108d
lib/mito/geometry: nodes are now wrapped into std shared pointers
biancagi Jun 8, 2024
1aabd15
lib/mito/mesh: remove unused {typedef}
biancagi Jun 8, 2024
7f7f442
lib/mito: the boundary of a mesh of segments returns now a collection…
biancagi Jun 8, 2024
cdf291f
lib/mito/geometry: remove unused type traits for 0-order {GeometricSi…
biancagi Jun 8, 2024
091e28a
lib/mito/geometry: add concept of a geometric simplex and of a geomet…
biancagi Jun 8, 2024
3297c01
lib/mito/mesh: readability improvement in class {Boundary}
biancagi Jun 8, 2024
089a4da
lib/mito: readability improvement
biancagi Jun 8, 2024
c0bb3f8
lib/mito/io/summit: in mesh reader use templates to avoid repeating t…
biancagi Jun 9, 2024
8fbcd52
lib/mito/geometry: add concept for all geometric simplices
biancagi Jun 9, 2024
5c771a9
lib/mito/io/summit: use type traits on the mesh cells
biancagi Jun 9, 2024
fb0b55c
lib/mito/geometry: publish {point_type} trait in class {CoordinateSys…
biancagi Jun 9, 2024
7366d74
lib/mito/io: redesign of summit and vtk writers
biancagi Jun 9, 2024
76ae72e
tests/mito.lib/io: add check that the number of nodes is conserved in…
biancagi Jun 9, 2024
3589a5d
lib/mito/io: add support for reading a mesh in {summit} format and re…
biancagi Jun 9, 2024
2a30890
.github/workflows: temporarily restricted {numpy} under {2.0} until i…
akoshakji Jul 5, 2024
ed60c8a
lib/mito/utilities: minor redesign of class {StdSharedPointer}
biancagi Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cmake/mito_tests_mito_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mito_test_driver(tests/mito.lib/geometry/spherical_metric_space.cc)

# fem
mito_test_driver(tests/mito.lib/fem/quadrature_field.cc)
mito_test_driver(tests/mito.lib/fem/nodal_field_sphere.cc)

# io
mito_test_driver(tests/mito.lib/io/read_mesh_summit_2D.cc)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install distro numpy pybind11 pytest vtk
pip3 install distro 'numpy<2.0' pybind11 pytest vtk

- name: checkout gtest
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install distro numpy pybind11 pytest vtk
pip3 install distro 'numpy<2.0' pybind11 pytest vtk

- name: checkout pyre
uses: actions/checkout@v3
Expand Down
110 changes: 44 additions & 66 deletions lib/mito/fem/NodalField.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,103 +9,81 @@

namespace mito::fem {

// TOFIX: order of template parameters
template <typename T, int D>
template <int D, class Y>
class NodalField {

private:
// the node type
using node_type = geometry::node_t<D>;

// a map from {key_type} to {Y} values
using map_type = std::unordered_map<node_type, Y, utilities::hash_function<node_type>>;

public:
NodalField(int nodes, std::string name = "") :
_nodes(nodes),
_name(name),
_nodalField(_nodes * D, 0.0)
{}
// constructor
NodalField(const mesh::mesh_c auto & mesh, std::string name) :
_map_nodes_to_values(),
_name(name)
{
// populate the map with the mesh nodes (map all nodes to default item {Y})
for (const auto & cell : mesh.cells()) {
for (const auto & node : cell.nodes()) {
_map_nodes_to_values[node] = Y();
}
}
}

~NodalField() {}
// destructor
~NodalField() = default;

public:
/**
* Operator()
*/
const T & operator()(const int a, const int i) const
inline auto operator()(const node_type & node) const -> const Y &
{
assert(i < D);
return _nodalField[D * a + i];
return _map_nodes_to_values.at(node);
}

T & operator()(const int a, const int i)
inline auto operator()(const node_type & node) -> Y &
{
assert(i < D);
return _nodalField[D * a + i];
return _map_nodes_to_values.at(node);
}

/**
* Iterators
* accessor for the number of nodes
*/
typename std::vector<T>::iterator begin() { return std::begin(_nodalField); }

typename std::vector<T>::iterator end() { return std::end(_nodalField); }

typename std::vector<T>::const_iterator begin() const { return std::cbegin(_nodalField); }

typename std::vector<T>::const_iterator end() const { return std::cend(_nodalField); }
inline auto n_nodes() const -> int { return _map_nodes_to_values.size(); }

/**
* Accessors
* accessor for name
*/
inline const std::string & name() const noexcept { return _name; }

inline int dim() const noexcept { return D; }

inline int nodes() const noexcept { return _nodes; }

inline int size() const noexcept { return _nodes * D; }

/**
* Set the field to zero.
*/
inline void init() { std::ranges::fill(_nodalField, 0.0); }
// support for ranged for loops (wrapping grid)
inline auto begin() const { return std::cbegin(_map_nodes_to_values); }
inline auto end() const { return std::cend(_map_nodes_to_values); }
inline auto begin() { return std::begin(_map_nodes_to_values); }
inline auto end() { return std::end(_map_nodes_to_values); }

private:
/**
* number of nodes
*/
int _nodes;
// the underlying mapping of nodes to nodal values
map_type _map_nodes_to_values;

/**
* name of the nodal field
*/
// the name of the field
std::string _name;

/**
* nodal field
*/
std::vector<T> _nodalField;
};

template <typename T, int D>
std::ostream & operator<<(std::ostream & os, const NodalField<T, D> & nodalField)
template <int D, class Y>
std::ostream & operator<<(std::ostream & os, const NodalField<D, Y> & nodalField)
{

os << "Nodal field \"" << nodalField.name() << "\" : ";
os << "Nodal field \"" << nodalField.name() << "\" : " << std::endl;

if (std::size(nodalField) == 0) {
os << "[]";
return os;
}

os << "[(" << nodalField(0, 0);
for (int d = 1; d < D; ++d) {
os << ", " << nodalField(0, d);
for (auto i = 0; i < nodalField.n_nodes(); ++i) {
os << "Node " << i << ": " << nodalField(i) << std::endl;
}
os << ")";

for (auto i = 1; i < nodalField.nodes(); ++i) {
os << ", (" << nodalField(i, 0);
for (int d = 1; d < D; ++d) {
os << ", " << nodalField(i, d);
}
os << ")";
}

os << "]";

return os;
}
Expand Down
47 changes: 19 additions & 28 deletions lib/mito/fem/QuadratureField.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ namespace mito::fem {

private:
// conventionally packed grid for {e, q}
using pack_t = pyre::grid::canonical_t<2>;
using pack_type = pyre::grid::canonical_t<2>;
// of Y on the heap
using storage_t = pyre::memory::heap_t<Y>;
using storage_type = pyre::memory::heap_t<Y>;
// putting it all together
using grid_t = pyre::grid::grid_t<pack_t, storage_t>;
using grid_type = pyre::grid::grid_t<pack_type, storage_type>;
// index
using index_t = pack_t::index_type;
using index_type = pack_type::index_type;

public:
/**
* constructor
* @param[in] elements number of elements for which data are stored
*/
inline QuadratureField(int nElements, std::string name = "") :
QuadratureField(nElements, pack_t{ { nElements, Q } }, name)
inline QuadratureField(int nElements, std::string name) :
QuadratureField(pack_type{ { nElements, Q } }, name)
{}

private:
inline QuadratureField(int /*nElements*/, const pack_t & packing, std::string name = "") :
inline QuadratureField(const pack_type && packing, std::string name) :
_grid{ packing, packing.cells() },
_name(name)
{}

public:
// destructor
~QuadratureField() {}
~QuadratureField() = default;

public:
/**
Expand All @@ -48,7 +48,7 @@ namespace mito::fem {
* @param[in] q local index of the quadrature point in the element
* @return the data
*/
inline Y & operator()(int e, int q)
inline auto operator()(int e, int q) -> Y &
{
// all done
return operator[]({ e, q });
Expand All @@ -60,19 +60,19 @@ namespace mito::fem {
* @param[in] q local index of the quadrature point in the element
* @return the data
*/
inline const Y & operator()(int e, int q) const
inline auto operator()(int e, int q) const -> const Y &
{
// all done
return operator[]({ e, q });
}

inline Y & operator[](const index_t & index)
inline auto operator[](const index_type & index) -> Y &
{
// all done
return _grid[index];
}

inline const Y & operator[](const index_t & index) const
inline auto operator[](const index_type & index) const -> const Y &
{
// all done
return _grid[index];
Expand All @@ -82,27 +82,18 @@ namespace mito::fem {
* accessor for the number of elements
* @return the number of elements
*/
inline int n_elements() const { return _grid.layout().shape()[0]; }
inline auto n_elements() const -> int { return _grid.layout().shape()[0]; }

/*
* accessor for the number of quadrature points per element
* @return the number of quadrature point per element
*/
inline constexpr int n_quad_points() const noexcept { return Q; }
constexpr auto n_quad_points() const noexcept -> int { return Q; }

/**
* const accessor for name
* accessor for name
*/
inline std::string name() const noexcept { return _name; }

/**
* setter method for name
*/
inline void name(std::string name) noexcept
{
_name = name;
return;
}
inline auto name() const noexcept -> std::string { return _name; }

// support for ranged for loops (wrapping grid)
inline auto begin() const { return std::cbegin(_grid); }
Expand All @@ -111,10 +102,10 @@ namespace mito::fem {
inline auto end() { return std::end(_grid); }

private:
// instantiate the grid
grid_t _grid;
// the underlying grid
grid_type _grid;

// name of the field
// the name of the field
std::string _name;
};

Expand Down
5 changes: 2 additions & 3 deletions lib/mito/fem/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ namespace mito::fem {
constexpr auto quadrature_field(int nElements, std::string name = "");

// nodal field factory
template <typename T, int D>
constexpr auto nodal_field(int nodes, std::string name = "");

template <class Y, int D>
constexpr auto nodal_field(const mesh::mesh_c auto & mesh, std::string name);
}


Expand Down
4 changes: 3 additions & 1 deletion lib/mito/fem/externals.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@


// externals
#define HAVE_TENSOR
#define HAVE_COMPACT_PACKINGS
#include <pyre/grid.h>
#include <string>
#include <cassert>

// support
#include "../journal.h"
#include "../tensor.h"
#include "../mesh.h"


// end of file
6 changes: 3 additions & 3 deletions lib/mito/fem/factories.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace mito::fem {
}

// nodal field factory
template <typename T, int D>
constexpr auto nodal_field(int nodes, std::string name)
template <class Y, mesh::mesh_c meshT>
constexpr auto nodal_field(const meshT & mesh, std::string name)
{
return nodal_field_t<T, D>(nodes, name);
return nodal_field_t<meshT::dim, Y>(mesh, name);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/mito/fem/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
namespace mito::fem {

// class nodal field
template <typename T, int D>
template <int D, class Y>
class NodalField;

// nodal field alias
template <typename T, int D>
using nodal_field_t = NodalField<T, D>;
template <int D, class Y>
using nodal_field_t = NodalField<D, Y>;

// class quadrature field
template <int Q, class Y>
Expand Down
3 changes: 1 addition & 2 deletions lib/mito/fields/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ namespace mito::fields {
// concept of two fields being compatible with each other (i.e. defined on the same coordinates)
template <class FIELD1, class FIELD2>
// a scalar field is a field returning a scalar
concept compatible_fields_c = requires {
concept compatible_fields_c =
std::is_same_v<typename FIELD1::coordinates_type, typename FIELD2::coordinates_type>;
};
}


Expand Down
4 changes: 2 additions & 2 deletions lib/mito/geometry/CoordinateSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ namespace mito::geometry {
using coordinates_type = coordT;
// the dimension of the physical space
static constexpr int dim = coordinates_type::dim;
// a point
using point_type = point_t<dim>;

private:
// alias {dim} for internal purposes
static constexpr int D = dim;
// a point
using point_type = point_t<D>;
// id type of point
using point_id_type = utilities::index_t<point_type>;
// a map between points and their coordinates
Expand Down
Loading
Loading