OGS
DOFTableUtil.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <Eigen/Core>
7#include <range/v3/algorithm/fill.hpp>
8
12
13namespace NumLib
14{
18 MeshLib::Location const& location,
19 NumLib::LocalToGlobalIndexMap const& dof_table,
20 std::size_t const global_component_id);
21
24double getNodalValue(GlobalVector const& x, MeshLib::Location const& location,
25 NumLib::LocalToGlobalIndexMap const& dof_table,
26 std::size_t const global_component_id);
27
30std::vector<GlobalIndexType> getIndices(
31 std::size_t const mesh_item_id,
32 NumLib::LocalToGlobalIndexMap const& dof_table);
33
36std::vector<GlobalIndexType> getIndices(
37 std::size_t const variable_id,
38 std::size_t const component_id,
39 std::size_t const bulk_element_id,
40 NumLib::LocalToGlobalIndexMap const& dof_table);
41
45 std::size_t const id,
46 NumLib::LocalToGlobalIndexMap const& dof_table,
47 std::vector<GlobalIndexType>& indices);
48
52double norm(GlobalVector const& x, unsigned const global_component,
53 MathLib::VecNormType norm_type,
54 LocalToGlobalIndexMap const& dof_table);
55
61template <typename Functor>
63 GlobalVector const& input_vector, int const variable_id,
64 NumLib::LocalToGlobalIndexMap const& local_to_global_index_map,
65 MeshLib::PropertyVector<double>& output_vector, Functor map_function)
66{
68
69 // We fill the output with zeroes, because filling with NaN
70 // "breaks" visualization, e.g. of heat or mass flow rate
71 // with Taylor-Hood elements. I.e., all lower order
72 // properties would have NaN on the higher order nodes.
73 ranges::fill(output_vector, 0);
74
75 int const n_components =
76 local_to_global_index_map.getNumberOfVariableComponents(variable_id);
77 for (int component = 0; component < n_components; ++component)
78 {
79 auto const& mesh_subset =
80 local_to_global_index_map.getMeshSubset(variable_id, component);
81 for (auto const& l : MeshLib::views::meshLocations(
82 mesh_subset, MeshLib::MeshItemType::Node))
83 {
84 auto const node_id = l.item_id;
85 auto const input_index = local_to_global_index_map.getGlobalIndex(
86 l, variable_id, component);
87 double const value = input_vector[input_index];
88
89 output_vector.getComponent(node_id, component) =
90 map_function(value);
91 }
92 }
93}
94
97template <typename Functor>
99 GlobalVector const& input_vector_on_bulk_mesh, int const variable_id,
100 NumLib::LocalToGlobalIndexMap const& local_to_global_index_map,
101 MeshLib::PropertyVector<double>& output_vector_on_submesh,
102 std::span<std::size_t const> const&
103 map_submesh_node_id_to_bulk_mesh_node_id,
104 Functor map_function)
105{
106 MathLib::LinAlg::setLocalAccessibleVector(input_vector_on_bulk_mesh);
107
108 // We fill the output with zeroes, because filling with NaN
109 // "breaks" visualization, e.g. of heat or mass flow rate
110 // with Taylor-Hood elements. I.e., all lower order
111 // properties would have NaN on the higher order nodes.
112 ranges::fill(output_vector_on_submesh, 0);
113
114 int const n_components =
115 local_to_global_index_map.getNumberOfVariableComponents(variable_id);
116 for (int component = 0; component < n_components; ++component)
117 {
118 auto const& mesh_subset =
119 local_to_global_index_map.getMeshSubset(variable_id, component);
120 auto const mesh_id = mesh_subset.getMeshID();
121
122 for (std::size_t submesh_node_id = 0;
123 submesh_node_id < map_submesh_node_id_to_bulk_mesh_node_id.size();
124 ++submesh_node_id)
125 {
126 std::size_t const bulk_node_id =
127 map_submesh_node_id_to_bulk_mesh_node_id[submesh_node_id];
129 bulk_node_id);
130 auto const input_index = local_to_global_index_map.getGlobalIndex(
131 l, variable_id, component);
132
133 // On higher-order meshes some d.o.f.s might not be defined on all
134 // nodes. We silently ignore the d.o.f.s we cannot find.
135 [[unlikely]] if (input_index == NumLib::MeshComponentMap::nop)
136 {
137 continue;
138 }
139
140 double const value = input_vector_on_bulk_mesh[input_index];
141
142 output_vector_on_submesh.getComponent(submesh_node_id, component) =
143 map_function(value);
144 }
145 }
146}
147
148Eigen::VectorXd getLocalX(
149 std::size_t const mesh_item_id,
150 std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_tables,
151 std::vector<GlobalVector*> const& x);
152} // namespace NumLib
MathLib::EigenVector GlobalVector
std::size_t getMeshID() const
return this mesh ID
Definition MeshSubset.h:67
PROP_VAL_TYPE & getComponent(std::size_t tuple_index, int component)
Returns the value for the given component stored in the given tuple.
MathLib::RowColumnIndices< GlobalIndexType > RowColumnIndices
GlobalIndexType getGlobalIndex(MeshLib::Location const &l, int const variable_id, int const component_id) const
int getNumberOfVariableComponents(int variable_id) const
MeshLib::MeshSubset const & getMeshSubset(int const variable_id, int const component_id) const
static constexpr NUMLIB_EXPORT GlobalIndexType const nop
void setLocalAccessibleVector(PETScVector const &x)
Definition LinAlg.cpp:20
auto meshLocations(Mesh const &mesh, MeshItemType const item_type)
Definition Mesh.h:227
void transformVariableFromGlobalVector(GlobalVector const &input_vector, int const variable_id, NumLib::LocalToGlobalIndexMap const &local_to_global_index_map, MeshLib::PropertyVector< double > &output_vector, Functor map_function)
double getNodalValue(GlobalVector const &x, MeshLib::Location const &location, NumLib::LocalToGlobalIndexMap const &dof_table, std::size_t const global_component_id)
std::vector< GlobalIndexType > getIndices(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
NumLib::LocalToGlobalIndexMap::RowColumnIndices getRowColumnIndices(std::size_t const id, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< GlobalIndexType > &indices)
Eigen::VectorXd getLocalX(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x)
double getNonGhostNodalValue(GlobalVector const &x, MeshLib::Location const &location, NumLib::LocalToGlobalIndexMap const &dof_table, std::size_t const global_component_id)
double norm(GlobalVector const &x, unsigned const global_component, MathLib::VecNormType norm_type, LocalToGlobalIndexMap const &dof_table)