| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2009 - 2024 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_vector_selector_templates_h |
| 16 |
#define dealii_vector_selector_templates_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/fe/fe_values.h> |
| 22 |
|
| 23 |
#include <deal.II/meshworker/vector_selector.h> |
| 24 |
|
| 25 |
DEAL_II_NAMESPACE_OPEN |
| 26 |
|
| 27 |
namespace MeshWorker |
| 28 |
{ |
| 29 |
template <int dim, int spacedim, typename Number> |
| 30 |
VectorDataBase<dim, spacedim, Number>::VectorDataBase(const VectorSelector &v) |
| 31 |
: VectorSelector(v) |
| 32 |
{} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
template <int dim, int spacedim, typename Number> |
| 37 |
void |
| 38 |
VectorDataBase<dim, spacedim, Number>::initialize(const AnyData &d) |
| 39 |
{ |
| 40 |
this->data = d; |
| 41 |
VectorSelector::initialize(d); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
template <int dim, int spacedim, typename Number> |
| 46 |
void |
| 47 |
VectorDataBase<dim, spacedim, Number>::fill( |
| 48 |
std::vector<std::vector<std::vector<Number>>> &, |
| 49 |
std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>> &, |
| 50 |
std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>> &, |
| 51 |
const FEValuesBase<dim, spacedim> &, |
| 52 |
const std::vector<types::global_dof_index> &, |
| 53 |
const unsigned int, |
| 54 |
const unsigned int, |
| 55 |
const unsigned int, |
| 56 |
const unsigned int) const |
| 57 |
{ |
| 58 |
DEAL_II_NOT_IMPLEMENTED(); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
template <int dim, int spacedim, typename Number> |
| 63 |
void |
| 64 |
VectorDataBase<dim, spacedim, Number>::mg_fill( |
| 65 |
std::vector<std::vector<std::vector<Number>>> &, |
| 66 |
std::vector<std::vector<std::vector<Tensor<1, spacedim, Number>>>> &, |
| 67 |
std::vector<std::vector<std::vector<Tensor<2, spacedim, Number>>>> &, |
| 68 |
const FEValuesBase<dim, spacedim> &, |
| 69 |
const unsigned int, |
| 70 |
const std::vector<types::global_dof_index> &, |
| 71 |
const unsigned int, |
| 72 |
const unsigned int, |
| 73 |
const unsigned int, |
| 74 |
const unsigned int) const |
| 75 |
{ |
| 76 |
DEAL_II_NOT_IMPLEMENTED(); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
//----------------------------------------------------------------------// |
| 81 |
|
| 82 |
template <typename VectorType, int dim, int spacedim> |
| 83 |
VectorData<VectorType, dim, spacedim>::VectorData(const VectorSelector &s) |
| 84 |
: VectorDataBase<dim, spacedim, typename VectorType::value_type>(s) |
| 85 |
{} |
| 86 |
|
| 87 |
|
| 88 |
template <typename VectorType, int dim, int spacedim> |
| 89 |
void |
| 90 |
VectorData<VectorType, dim, spacedim>::initialize(const AnyData &d) |
| 91 |
{ |
| 92 |
this->data = d; |
| 93 |
VectorSelector::initialize(d); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
template <typename VectorType, int dim, int spacedim> |
| 98 |
void |
| 99 |
VectorData<VectorType, dim, spacedim>::initialize(const VectorType *v, |
| 100 |
const std::string &name) |
| 101 |
{ |
| 102 |
ObserverPointer<const VectorType, VectorData<VectorType, dim, spacedim>> p = |
| 103 |
v; |
| 104 |
this->data.add(p, name); |
| 105 |
VectorSelector::initialize(this->data); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
template <typename VectorType, int dim, int spacedim> |
| 110 |
void |
| 111 |
VectorData<VectorType, dim, spacedim>::fill( |
| 112 |
std::vector<std::vector<std::vector<typename VectorType::value_type>>> |
| 113 |
&values, |
| 114 |
std::vector<std::vector< |
| 115 |
std::vector<Tensor<1, spacedim, typename VectorType::value_type>>>> |
| 116 |
&gradients, |
| 117 |
std::vector<std::vector< |
| 118 |
std::vector<Tensor<2, spacedim, typename VectorType::value_type>>>> |
| 119 |
&hessians, |
| 120 |
const FEValuesBase<dim, spacedim> &fe, |
| 121 |
const std::vector<types::global_dof_index> &index, |
| 122 |
const unsigned int component, |
| 123 |
const unsigned int n_comp, |
| 124 |
const unsigned int start, |
| 125 |
const unsigned int size) const |
| 126 |
{ |
| 127 |
AssertDimension(values.size(), this->n_values()); |
| 128 |
AssertDimension(gradients.size(), this->n_gradients()); |
| 129 |
AssertDimension(hessians.size(), this->n_hessians()); |
| 130 |
|
| 131 |
const AnyData &data = this->data; |
| 132 |
for (unsigned int i = 0; i < this->n_values(); ++i) |
| 133 |
{ |
| 134 |
const VectorType *src = data.read_ptr<VectorType>(this->value_index(i)); |
| 135 |
fe.get_function_values(*src, |
| 136 |
make_array_view(index, start, size), |
| 137 |
make_array_view(values[i], component, n_comp), |
| 138 |
true); |
| 139 |
} |
| 140 |
|
| 141 |
for (unsigned int i = 0; i < this->n_gradients(); ++i) |
| 142 |
{ |
| 143 |
const VectorType *src = |
| 144 |
data.read_ptr<VectorType>(this->gradient_index(i)); |
| 145 |
fe.get_function_gradients(*src, |
| 146 |
make_array_view(index, start, size), |
| 147 |
make_array_view(gradients[i], |
| 148 |
component, |
| 149 |
n_comp), |
| 150 |
true); |
| 151 |
} |
| 152 |
|
| 153 |
for (unsigned int i = 0; i < this->n_hessians(); ++i) |
| 154 |
{ |
| 155 |
const VectorType *src = |
| 156 |
data.read_ptr<VectorType>(this->hessian_index(i)); |
| 157 |
fe.get_function_hessians(*src, |
| 158 |
make_array_view(index, start, size), |
| 159 |
make_array_view(hessians[i], |
| 160 |
component, |
| 161 |
n_comp), |
| 162 |
true); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
template <typename VectorType, int dim, int spacedim> |
| 168 |
std::size_t |
| 169 |
VectorData<VectorType, dim, spacedim>::memory_consumption() const |
| 170 |
{ |
| 171 |
std::size_t mem = VectorSelector::memory_consumption(); |
| 172 |
mem += sizeof(this->data); |
| 173 |
return mem; |
| 174 |
} |
| 175 |
|
| 176 |
//----------------------------------------------------------------------// |
| 177 |
|
| 178 |
template <typename VectorType, int dim, int spacedim> |
| 179 |
MGVectorData<VectorType, dim, spacedim>::MGVectorData(const VectorSelector &s) |
| 180 |
: VectorData<VectorType, dim, spacedim>(s) |
| 181 |
{} |
| 182 |
|
| 183 |
|
| 184 |
template <typename VectorType, int dim, int spacedim> |
| 185 |
void |
| 186 |
MGVectorData<VectorType, dim, spacedim>::initialize(const AnyData &d) |
| 187 |
{ |
| 188 |
this->data = d; |
| 189 |
VectorSelector::initialize(d); |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
template <typename VectorType, int dim, int spacedim> |
| 194 |
void |
| 195 |
MGVectorData<VectorType, dim, spacedim>::initialize( |
| 196 |
const MGLevelObject<VectorType> *v, |
| 197 |
const std::string &name) |
| 198 |
{ |
| 199 |
ObserverPointer<const MGLevelObject<VectorType>, |
| 200 |
MGVectorData<VectorType, dim, spacedim>> |
| 201 |
p = v; |
| 202 |
this->data.add(p, name); |
| 203 |
VectorSelector::initialize(this->data); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
template <typename VectorType, int dim, int spacedim> |
| 208 |
void |
| 209 |
VectorData<VectorType, dim, spacedim>::mg_fill( |
| 210 |
std::vector<std::vector<std::vector<typename VectorType::value_type>>> |
| 211 |
&values, |
| 212 |
std::vector<std::vector< |
| 213 |
std::vector<Tensor<1, spacedim, typename VectorType::value_type>>>> |
| 214 |
&gradients, |
| 215 |
std::vector<std::vector< |
| 216 |
std::vector<Tensor<2, spacedim, typename VectorType::value_type>>>> |
| 217 |
&hessians, |
| 218 |
const FEValuesBase<dim, spacedim> &fe, |
| 219 |
const unsigned int level, |
| 220 |
const std::vector<types::global_dof_index> &index, |
| 221 |
const unsigned int component, |
| 222 |
const unsigned int n_comp, |
| 223 |
const unsigned int start, |
| 224 |
const unsigned int size) const |
| 225 |
{ |
| 226 |
AssertDimension(values.size(), this->n_values()); |
| 227 |
AssertDimension(gradients.size(), this->n_gradients()); |
| 228 |
AssertDimension(hessians.size(), this->n_hessians()); |
| 229 |
|
| 230 |
const AnyData &data = this->data; |
| 231 |
for (unsigned int i = 0; i < this->n_values(); ++i) |
| 232 |
{ |
| 233 |
const MGLevelObject<VectorType> *src = |
| 234 |
data.read_ptr<MGLevelObject<VectorType>>(this->value_index(i)); |
| 235 |
fe.get_function_values((*src)[level], |
| 236 |
make_array_view(index, start, size), |
| 237 |
make_array_view(values[i], component, n_comp), |
| 238 |
true); |
| 239 |
} |
| 240 |
|
| 241 |
for (unsigned int i = 0; i < this->n_gradients(); ++i) |
| 242 |
{ |
| 243 |
const MGLevelObject<VectorType> *src = |
| 244 |
data.read_ptr<MGLevelObject<VectorType>>(this->value_index(i)); |
| 245 |
fe.get_function_gradients((*src)[level], |
| 246 |
make_array_view(index, start, size), |
| 247 |
make_array_view(gradients[i], |
| 248 |
component, |
| 249 |
n_comp), |
| 250 |
true); |
| 251 |
} |
| 252 |
|
| 253 |
for (unsigned int i = 0; i < this->n_hessians(); ++i) |
| 254 |
{ |
| 255 |
const MGLevelObject<VectorType> *src = |
| 256 |
data.read_ptr<MGLevelObject<VectorType>>(this->value_index(i)); |
| 257 |
fe.get_function_hessians((*src)[level], |
| 258 |
make_array_view(index, start, size), |
| 259 |
make_array_view(hessians[i], |
| 260 |
component, |
| 261 |
n_comp), |
| 262 |
true); |
| 263 |
} |
| 264 |
} |
| 265 |
} // namespace MeshWorker |
| 266 |
|
| 267 |
DEAL_II_NAMESPACE_CLOSE |
| 268 |
|
| 269 |
#endif |