FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
linear_functional_assembler.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/assembly/asm_traits.hpp>
10
11namespace FEAT
12{
13 namespace Assembly
14 {
23 {
24 public:
43 template<
44 typename Vector_,
45 typename Functional_,
46 typename CubatureFactory_,
47 typename Space_>
48 static void assemble_vector(
49 Vector_& vector,
50 const Functional_& functional,
51 const Space_& space,
52 const CubatureFactory_& cubature_factory,
53 typename Vector_::DataType alpha = typename Vector_::DataType(1))
54 {
55 // validate vector dimensions
56 XASSERTM(vector.size() == space.get_num_dofs(), "invalid vector size");
57
58 // vector type
59 typedef Vector_ VectorType;
60 // functional type
61 typedef Functional_ FunctionalType;
62 // space type
63 typedef Space_ SpaceType;
64
65 // assembly traits
66 typedef AsmTraits1<
67 typename VectorType::DataType,
68 SpaceType,
69 FunctionalType::trafo_config,
70 FunctionalType::test_config> AsmTraits;
71
72 // fetch the trafo
73 const typename AsmTraits::TrafoType& trafo = space.get_trafo();
74
75 // create a trafo evaluator
76 typename AsmTraits::TrafoEvaluator trafo_eval(trafo);
77
78 // create a space evaluator and evaluation data
79 typename AsmTraits::TestEvaluator test_eval(space);
80
81 // create a dof-mapping
82 typename AsmTraits::DofMapping dof_mapping(space);
83
84 // create a functional evaluator
85 typename FunctionalType::template Evaluator<AsmTraits> func_eval(functional);
86
87 // create trafo evaluation data
88 typename AsmTraits::TrafoEvalData trafo_data;
89
90 // create space evaluation data
91 typename AsmTraits::TestEvalData test_data;
92
93 // the value type of the functional
94 typedef typename FunctionalType::template Evaluator<AsmTraits>::ValueType ValueType;
95
96 // ensure that the functional and vector value types are compatible
97 static_assert(std::is_same<ValueType, typename VectorType::ValueType>::value,
98 "vector and linear functional have different value types!");
99
100 // create local vector data
101 typename AsmTraits::template TLocalVector<ValueType> loc_vec;
102
103 // create cubature rule
104 typename AsmTraits::CubatureRuleType cubature_rule(Cubature::ctor_factory, cubature_factory);
105
106 // create matrix scatter-axpy
107 typename VectorType::ScatterAxpy scatter_axpy(vector);
108
109 // loop over all cells of the mesh
110 for(typename AsmTraits::CellIterator cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
111 {
112 // prepare trafo evaluator
113 trafo_eval.prepare(cell);
114
115 // prepare test-space evaluator
116 test_eval.prepare(trafo_eval);
117
118 // prepare functional evaluator
119 func_eval.prepare(trafo_eval);
120
121 // fetch number of local dofs
122 int num_loc_dofs = test_eval.get_num_local_dofs();
123
124 // format local matrix
125 loc_vec.format();
126
127 // loop over all quadrature points and integrate
128 for(int k(0); k < cubature_rule.get_num_points(); ++k)
129 {
130 // compute trafo data
131 trafo_eval(trafo_data, cubature_rule.get_point(k));
132
133 // compute test basis function data
134 test_eval(test_data, trafo_data);
135
136 // prepare functional
137 func_eval.set_point(trafo_data);
138
139 // test function loop
140 for(int i(0); i < num_loc_dofs; ++i)
141 {
142 // evaluate functional and integrate
143 Tiny::axpy(loc_vec(i), func_eval.eval(test_data.phi[i]),
144 trafo_data.jac_det * cubature_rule.get_weight(k));
145 // continue with next trial function
146 }
147 // continue with next test function
148 }
149
150 // finish functional evaluator
151 func_eval.finish();
152
153 // finish evaluators
154 test_eval.finish();
155 trafo_eval.finish();
156
157 // initialize dof-mapping
158 dof_mapping.prepare(cell);
159
160 // incorporate local matrix
161 scatter_axpy(loc_vec, dof_mapping, alpha);
162
163 // finish dof-mapping
164 dof_mapping.finish();
165
166 // continue with next cell
167 }
168
169 // okay, that's it
170 }
171 }; // class LinearFunctionalAssembler
172 } // namespace Assembly
173} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Common single-space assembly traits class template.
Definition: asm_traits.hpp:83
Linear Functional Assembly class template.
static void assemble_vector(Vector_ &vector, const Functional_ &functional, const Space_ &space, const CubatureFactory_ &cubature_factory, typename Vector_::DataType alpha=typename Vector_::DataType(1))
Assembles a linear functional into a vector.
CUDA_HOST_DEVICE void axpy(T_ &y, const T_ &x, const T_ &alpha)
Performs an AXPY of two scalars.
FEAT namespace.
Definition: adjactor.hpp:12