11#include <kernel/util/math.hpp>
13#include <kernel/assembly/asm_traits.hpp>
14#include <kernel/trafo/inverse_mapping.hpp>
15#include <kernel/geometry/mesh_permutation.hpp>
37 Exception(
"local mass matrix inversion error")
68 typename TargetSpace_,
69 typename SourceSpace_>
73 const TargetSpace_& target_space,
74 const SourceSpace_& source_space,
75 const String& cubature_name)
78 XASSERTM(&target_space.get_trafo() == &source_space.get_trafo(),
"source and target space must be defined on the same trafo");
81 XASSERTM(matrix.rows() == target_space.get_num_dofs(),
"invalid matrix dimensions");
82 XASSERTM(matrix.columns() == source_space.get_num_dofs(),
"invalid matrix dimensions");
83 XASSERTM(vector.size() == target_space.get_num_dofs(),
"invalid vector size");
85 typedef typename Matrix_::DataType DataType;
88 typedef typename TargetSpace_::TrafoType TrafoType;
89 typedef typename SourceSpace_::ShapeType ShapeType;
92 typedef typename TargetSpace_::DofMappingType TargetDofMapping;
93 typedef typename SourceSpace_::DofMappingType SourceDofMapping;
96 typedef typename TrafoType::template Evaluator<ShapeType, DataType>::Type TrafoEvaluator;
99 typedef typename TargetSpace_::template Evaluator<TrafoEvaluator>::Type TargetSpaceEvaluator;
100 typedef typename SourceSpace_::template Evaluator<TrafoEvaluator>::Type SourceSpaceEvaluator;
103 typedef typename TargetSpaceEvaluator::template ConfigTraits<SpaceTags::value> TargetSpaceConfigTraits;
104 typedef typename SourceSpaceEvaluator::template ConfigTraits<SpaceTags::value> SourceSpaceConfigTraits;
105 static constexpr TrafoTags trafo_config =
TrafoTags::jac_det | TargetSpaceConfigTraits::trafo_config | SourceSpaceConfigTraits::trafo_config;
108 typedef typename TrafoEvaluator::template ConfigTraits<trafo_config>::EvalDataType TrafoEvalData;
109 TrafoEvalData trafo_data;
112 typedef typename TargetSpaceEvaluator::template ConfigTraits<SpaceTags::value>::EvalDataType TargetSpaceEvalData;
113 typedef typename SourceSpaceEvaluator::template ConfigTraits<SpaceTags::value>::EvalDataType SourceSpaceEvalData;
114 TargetSpaceEvalData target_space_data;
115 SourceSpaceEvalData source_space_data;
118 typename Matrix_::ScatterAxpy scatter_maxpy(matrix);
119 typename Vector_::ScatterAxpy scatter_vaxpy(vector);
122 TargetDofMapping target_dof_mapping(target_space);
123 SourceDofMapping source_dof_mapping(source_space);
126 const TrafoType& trafo = target_space.get_trafo();
129 TrafoEvaluator trafo_eval(trafo);
132 TargetSpaceEvaluator target_space_eval(target_space);
133 SourceSpaceEvaluator source_space_eval(source_space);
137 typename Intern::CubatureTraits<TrafoEvaluator>::RuleType cubature(Cubature::ctor_factory, cubature_factory);
149 int pivot[TargetSpaceEvaluator::max_local_dofs];
152 for(
Index cell(0); cell < trafo_eval.get_num_cells(); ++cell)
155 trafo_eval.prepare(cell);
158 source_space_eval.prepare(trafo_eval);
159 target_space_eval.prepare(trafo_eval);
162 const int source_num_loc_dofs = source_space_eval.get_num_local_dofs();
163 const int target_num_loc_dofs = target_space_eval.get_num_local_dofs();
166 source_dof_mapping.prepare(cell);
167 target_dof_mapping.prepare(cell);
175 for(
int k(0); k < cubature.get_num_points(); ++k)
178 trafo_eval(trafo_data, cubature.get_point(k));
181 target_space_eval(target_space_data, trafo_data);
182 source_space_eval(source_space_data, trafo_data);
185 const DataType omega = trafo_data.jac_det * cubature.get_weight(k);
188 for(
int i(0); i < target_num_loc_dofs; ++i)
191 for(
int j(0); j < target_num_loc_dofs; ++j)
193 mass(i,j) += omega * target_space_data.phi[i].value * target_space_data.phi[j].value;
197 for(
int j(0); j < source_num_loc_dofs; ++j)
199 lmd(i,j) += omega * target_space_data.phi[i].value * source_space_data.phi[j].value;
226 scatter_maxpy(lid, target_dof_mapping, source_dof_mapping);
230 scatter_vaxpy(lvd, target_dof_mapping);
233 source_dof_mapping.finish();
234 target_dof_mapping.finish();
237 target_space_eval.finish();
238 source_space_eval.finish();
268 typename TargetSpace_,
269 typename SourceSpace_>
272 const TargetSpace_& target_space,
273 const SourceSpace_& source_space,
274 const String& cubature_name)
277 auto weight = matrix.create_vector_l();
285 weight.component_invert(weight);
286 matrix.scale_rows(matrix, weight);
323 typename TargetSpace_,
324 typename SourceSpace_>
328 const Vector_& vector_c,
329 const TargetSpace_& target_space,
330 const SourceSpace_& source_space,
331 const String& cubature_name)
334 XASSERTM(&target_space.get_trafo() == &source_space.get_trafo(),
"source and target space must be defined on the same trafo");
337 XASSERTM(vector_f.size() == vector_w.size(),
"invalid vector sizes");
338 XASSERTM(vector_f.size() == target_space.get_num_dofs(),
"invalid matrix dimensions");
339 XASSERTM(vector_c.size() == source_space.get_num_dofs(),
"invalid matrix dimensions");
340 XASSERTM(vector_f.size() == target_space.get_num_dofs(),
"invalid vector size");
342 typedef typename Vector_::DataType DataType;
343 typedef typename Vector_::ValueType ValueType;
346 typedef typename TargetSpace_::TrafoType TrafoType;
347 typedef typename SourceSpace_::ShapeType ShapeType;
350 typedef typename TargetSpace_::DofMappingType TargetDofMapping;
351 typedef typename SourceSpace_::DofMappingType SourceDofMapping;
354 typedef typename TrafoType::template Evaluator<ShapeType, DataType>::Type TrafoEvaluator;
357 typedef typename TargetSpace_::template Evaluator<TrafoEvaluator>::Type TargetSpaceEvaluator;
358 typedef typename SourceSpace_::template Evaluator<TrafoEvaluator>::Type SourceSpaceEvaluator;
361 typedef typename TargetSpaceEvaluator::template ConfigTraits<SpaceTags::value> TargetSpaceConfigTraits;
362 typedef typename SourceSpaceEvaluator::template ConfigTraits<SpaceTags::value> SourceSpaceConfigTraits;
363 static constexpr TrafoTags target_trafo_config =
TrafoTags::jac_det | TargetSpaceConfigTraits::trafo_config | SourceSpaceConfigTraits::trafo_config;
366 typedef typename TrafoEvaluator::template ConfigTraits<target_trafo_config>::EvalDataType TrafoEvalData;
367 TrafoEvalData trafo_data;
370 typedef typename TargetSpaceEvaluator::template ConfigTraits<SpaceTags::value>::EvalDataType TargetSpaceEvalData;
371 typedef typename SourceSpaceEvaluator::template ConfigTraits<SpaceTags::value>::EvalDataType SourceSpaceEvalData;
372 TargetSpaceEvalData target_space_data;
373 SourceSpaceEvalData source_space_data;
376 typedef typename Assembly::Intern::CubatureTraits<TrafoEvaluator>::RuleType CubatureRuleType;
379 typename Vector_::GatherAxpy gather_c(vector_c);
380 typename Vector_::ScatterAxpy scatter_f(vector_f);
381 typename Vector_::ScatterAxpy scatter_w(vector_w);
384 TargetDofMapping target_dof_mapping(target_space);
385 SourceDofMapping source_dof_mapping(source_space);
388 const TrafoType& trafo = target_space.get_trafo();
391 TrafoEvaluator trafo_eval(trafo);
394 TargetSpaceEvaluator target_space_eval(target_space);
395 SourceSpaceEvaluator source_space_eval(source_space);
399 CubatureRuleType cubature(Cubature::ctor_factory, cubature_factory);
412 int pivot[TargetSpaceEvaluator::max_local_dofs];
415 for(
Index ccell(0); ccell < trafo_eval.get_num_cells(); ++ccell)
418 trafo_eval.prepare(ccell);
421 source_space_eval.prepare(trafo_eval);
422 target_space_eval.prepare(trafo_eval);
425 source_dof_mapping.prepare(ccell);
426 target_dof_mapping.prepare(ccell);
429 source_dof_mapping.prepare(ccell);
432 const int source_num_loc_dofs = source_space_eval.get_num_local_dofs();
433 const int target_num_loc_dofs = target_space_eval.get_num_local_dofs();
437 gather_c(lv_c, source_dof_mapping);
446 for(
int k(0); k < cubature.get_num_points(); ++k)
449 trafo_eval(trafo_data, cubature.get_point(k));
452 target_space_eval(target_space_data, trafo_data);
453 source_space_eval(source_space_data, trafo_data);
456 const DataType omega = trafo_data.jac_det * cubature.get_weight(k);
459 for(
int i(0); i < target_num_loc_dofs; ++i)
462 for(
int j(0); j < target_num_loc_dofs; ++j)
464 mass(i,j) += omega * target_space_data.phi[i].value * target_space_data.phi[j].value;
468 for(
int j(0); j < source_num_loc_dofs; ++j)
470 lmd(i,j) += omega * target_space_data.phi[i].value * source_space_data.phi[j].value;
476 target_space_eval.finish();
502 for(
int i(0); i < target_num_loc_dofs; ++i)
503 for(
int j(0); j < source_num_loc_dofs; ++j)
504 lv_f[i] += lid[i][j] * lv_c[j];
507 target_dof_mapping.prepare(ccell);
510 scatter_f(lv_f, target_dof_mapping);
514 scatter_w(lv_w, target_dof_mapping);
517 target_dof_mapping.finish();
520 source_space_eval.finish();
524 source_dof_mapping.finish();
555 typename TargetSpace_,
556 typename SourceSpace_>
559 const Vector_& vector_c,
560 const TargetSpace_& target_space,
561 const SourceSpace_& source_space,
562 const String& cubature_name)
567 transfer_vector(vector_f, vector_w, vector_c, target_space, source_space, cubature_name);
570 vector_w.component_invert(vector_w);
571 vector_f.component_product(vector_f, vector_w);
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Exception for singular mass matrix errors.
static void assemble_transfer(Matrix_ &matrix, Vector_ &vector, const TargetSpace_ &target_space, const SourceSpace_ &source_space, const String &cubature_name)
Assembles an inter-space transfer matrix and its corresponding weight vector.
static void assemble_transfer_direct(Matrix_ &matrix, const TargetSpace_ &target_space, const SourceSpace_ &source_space, const String &cubature_name)
Assembles an inter-space transfer matrix.
static void transfer_vector(Vector_ &vector_f, Vector_ &vector_w, const Vector_ &vector_c, const TargetSpace_ &target_space, const SourceSpace_ &source_space, const String &cubature_name)
Transfers a primal vector and assembles a compatible weight vector.
static void transfer_vector_direct(Vector_ &vector_f, const Vector_ &vector_c, const TargetSpace_ &target_space, const SourceSpace_ &source_space, const String &cubature_name)
Transfers a primal vector directly.
String class implementation.
Tiny Matrix class template.
CUDA_HOST_DEVICE Matrix & set_mat_mat_mult(const Matrix< T_, m_, la_, sma_, sna_ > &a, const Matrix< T_, lb_, n_, smb_, snb_ > &b)
Sets this matrix to the algebraic matrix-product of two other matrices.
static constexpr int sn
the column stride of the matrix
RowType v[sm_]
actual matrix data; that's an array of vectors
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the matrix.
CUDA_HOST_DEVICE DataType norm_frobenius() const
Returns the Frobenius norm of the matrix.
Tiny Vector class template.
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the vector.
LAFEM common type definitions.
bool isnormal(T_ x)
Checks whether a value is normal.
DT_ invert_matrix(const IT_ n, const IT_ stride, DT_ a[], IT_ p[])
Inverts a matrix and returns its determinant.
std::uint64_t Index
Index data type.
TrafoTags
Trafo configuration tags enum.
@ jac_det
specifies whether the trafo should supply jacobian determinants