9#include <kernel/assembly/asm_traits.hpp>
10#include <kernel/assembly/symbolic_assembler.hpp>
11#include <kernel/lafem/sparse_matrix_bcsr.hpp>
66 template<
typename DT_,
typename IT_,
int dim_,
67 typename SpaceTest_,
typename SpaceTrial_,
68 typename CubatureFactory_>
71 const SpaceTest_& test_space,
72 const SpaceTrial_& trial_space,
73 const CubatureFactory_& cubature_factory,
74 const DT_ scale = DT_(1)
78 typedef IT_ IndexType;
79 static constexpr int dim = dim_;
82 static_assert(SpaceTest_::shape_dim == dim_,
"invalid matrix block sizes");
85 XASSERTM((&test_space.get_trafo()) == (&trial_space.get_trafo()),
86 "Trial and test spaces must be defined on the same trafo!");
100 const typename AsmTraits::TrafoType& trafo = test_space.get_trafo();
103 typename AsmTraits::TrafoEvaluator trafo_eval(trafo);
106 typename AsmTraits::TestEvaluator test_eval(test_space);
107 typename AsmTraits::TrialEvaluator trial_eval(trial_space);
110 typename AsmTraits::TestDofMapping test_dof_mapping(test_space);
111 typename AsmTraits::TrialDofMapping trial_dof_mapping(trial_space);
114 typename AsmTraits::TrafoEvalData trafo_data;
117 typename AsmTraits::TestEvalData test_data;
118 typename AsmTraits::TrialEvalData trial_data;
121 static constexpr int max_test_dofs = AsmTraits::max_local_test_dofs;
122 static constexpr int max_trial_dofs = AsmTraits::max_local_trial_dofs;
130 typename AsmTraits::CubatureRuleType cubature_rule(Cubature::ctor_factory, cubature_factory);
136 matrix_g = MatrixG(graph_g);
141 typename MatrixG::ScatterAxpy scatter_matrix(matrix_g);
144 for(
typename AsmTraits::CellIterator cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
147 trafo_eval.prepare(cell);
150 test_eval.prepare(trafo_eval);
151 trial_eval.prepare(trafo_eval);
154 const int num_loc_test_dofs = test_eval.get_num_local_dofs();
155 const int num_loc_trial_dofs = trial_eval.get_num_local_dofs();
161 for(
int pt(0); pt < cubature_rule.get_num_points(); ++pt)
164 trafo_eval(trafo_data, cubature_rule.get_point(pt));
167 test_eval(test_data, trafo_data);
168 trial_eval(trial_data, trafo_data);
171 for(
int i(0); i < num_loc_test_dofs; ++i)
174 for(
int j(0); j < num_loc_trial_dofs; ++j)
176 const DataType pv = trafo_data.jac_det * cubature_rule.get_weight(pt) * test_data.phi[i].value;
179 for(
int k(0); k < dim; ++k)
181 local_matrix[i][j][k][0] += trial_data.phi[j].grad[k] * pv;
197 test_dof_mapping.prepare(cell);
198 trial_dof_mapping.prepare(cell);
201 scatter_matrix(local_matrix, test_dof_mapping, trial_dof_mapping, scale);
204 trial_dof_mapping.finish();
205 test_dof_mapping.finish();
250 template<
typename DT_,
typename IT_,
int dim_,
251 typename SpaceTest_,
typename SpaceTrial_,
252 typename CubatureFactory_>
256 const SpaceTest_& test_space,
257 const SpaceTrial_& trial_space,
258 const CubatureFactory_& cubature_factory,
259 const DT_ scale = DT_(1)
262 typedef DT_ DataType;
263 typedef IT_ IndexType;
264 static constexpr int dim = dim_;
267 static_assert(SpaceTest_::shape_dim == dim,
"invalid matrix block sizes");
270 XASSERTM((&test_space.get_trafo()) == (&trial_space.get_trafo()),
271 "Trial and test spaces must be defined on the same trafo!");
286 const typename AsmTraits::TrafoType& trafo = test_space.get_trafo();
289 typename AsmTraits::TrafoEvaluator trafo_eval(trafo);
292 typename AsmTraits::TestEvaluator test_eval(test_space);
293 typename AsmTraits::TrialEvaluator trial_eval(trial_space);
296 typename AsmTraits::TestDofMapping test_dof_mapping(test_space);
297 typename AsmTraits::TrialDofMapping trial_dof_mapping(trial_space);
300 typename AsmTraits::TrafoEvalData trafo_data;
303 typename AsmTraits::TestEvalData test_data;
304 typename AsmTraits::TrialEvalData trial_data;
307 static constexpr int max_test_dofs = AsmTraits::max_local_test_dofs;
308 static constexpr int max_trial_dofs = AsmTraits::max_local_trial_dofs;
313 LocalVectorType local_vector;
316 LocalVecInType local_vec_in_dofs;
322 typename AsmTraits::CubatureRuleType cubature_rule(Cubature::ctor_factory, cubature_factory);
325 typename VectorAsm::ScatterAxpy scatter_vector(vec_asm);
327 typename VectorIn::GatherAxpy gather_vec_in(vec_in);
330 for(
typename AsmTraits::CellIterator cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
333 trafo_eval.prepare(cell);
336 test_eval.prepare(trafo_eval);
337 trial_eval.prepare(trafo_eval);
340 trial_dof_mapping.prepare(cell);
343 local_vec_in_dofs.format();
344 gather_vec_in(local_vec_in_dofs, trial_dof_mapping);
347 const int num_loc_test_dofs = test_eval.get_num_local_dofs();
348 const int num_loc_trial_dofs = trial_eval.get_num_local_dofs();
351 local_vector.format();
354 for(
int pt(0); pt < cubature_rule.get_num_points(); ++pt)
357 trafo_eval(trafo_data, cubature_rule.get_point(pt));
360 test_eval(test_data, trafo_data);
361 trial_eval(trial_data, trafo_data);
365 for(
int i(0); i < num_loc_trial_dofs; ++i)
367 for(
int k(0); k < dim; ++k)
369 loc_grad_trial[k] += local_vec_in_dofs[i] * trial_data.phi[i].grad[k];
374 for(
int i(0); i < num_loc_test_dofs; ++i)
376 const DataType v(trafo_data.jac_det * cubature_rule.get_weight(pt) * test_data.phi[i].value);
379 for(
int k(0); k < dim; ++k)
383 local_vector[i][k] += v * loc_grad_trial[k];
395 test_dof_mapping.prepare(cell);
398 scatter_vector(local_vector, test_dof_mapping, scale);
401 trial_dof_mapping.finish();
402 test_dof_mapping.finish();
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Adjacency Graph implementation.
Common test-/trial-space assembly traits class template.
Assembles the gradient operator.
static void assemble(LAFEM::SparseMatrixBCSR< DT_, IT_, dim_, 1 > &matrix_g, const SpaceTest_ &test_space, const SpaceTrial_ &trial_space, const CubatureFactory_ &cubature_factory, const DT_ scale=DT_(1))
Assembles the bilinear form into a matrix.
static void assemble(LAFEM::DenseVectorBlocked< DT_, IT_, dim_ > &vec_asm, const LAFEM::DenseVector< DT_, IT_ > &vec_in, const SpaceTest_ &test_space, const SpaceTrial_ &trial_space, const CubatureFactory_ &cubature_factory, const DT_ scale=DT_(1))
Assembles the application of the bilinear form to a vector into a vector.
static Adjacency::Graph assemble_graph_std2(const TestSpace_ &test_space, const TrialSpace_ &trial_space)
Assembles the standard Dof-Adjacency graph for different test- and trial-spaces.
bool empty() const
Checks whether the container is empty.
void format(DT_ value=DT_(0))
Reset all elements of the container to a given value or zero if missing.
Blocked Dense data vector class template.
Dense data vector class template.
CSR based blocked sparse matrix.
Tiny Matrix class template.
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the matrix.
Tiny Vector class template.
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the vector.
@ value
specifies whether the space should supply basis function values
@ grad
specifies whether the space should supply basis function gradients
@ jac_det
specifies whether the trafo should supply jacobian determinants