FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
gpdv_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#include <kernel/assembly/asm_traits.hpp>
9#include <kernel/assembly/symbolic_assembler.hpp>
10#include <kernel/lafem/sparse_matrix_bcsr.hpp>
11
12namespace FEAT
13{
14 namespace Assembly
15 {
32 {
33 public:
53 template<
54 typename DataType_, typename IndexType_, int dim_,
55 typename SpaceVelo_, typename SpacePres_>
56 static void assemble(
59 const SpaceVelo_& space_velo,
60 const SpacePres_& space_pres,
61 const String& cubature_name,
62 const DataType_ scale_b = -DataType_(1),
63 const DataType_ scale_d = -DataType_(1)
64 )
65 {
66 Cubature::DynamicFactory cubature_factory(cubature_name);
67 assemble(matrix_b, matrix_d, space_velo, space_pres, cubature_factory, scale_b, scale_d);
68 }
69
89 template<
90 typename DataType_, typename IndexType_, int dim_,
91 typename SpaceVelo_, typename SpacePres_>
92 static void assemble(
95 const SpaceVelo_& space_velo,
96 const SpacePres_& space_pres,
97 const Cubature::DynamicFactory& cubature_factory,
98 const DataType_ scale_b = -DataType_(1),
99 const DataType_ scale_d = -DataType_(1)
100 )
101 {
102 typedef DataType_ DataType;
103
104 // ensure that the matrices have the correct dimensions
105 static_assert(SpaceVelo_::shape_dim == dim_, "invalid matrix block sizes");
106
107 // make sure that velocity and pressure have the same trafo
108 XASSERTM((&space_velo.get_trafo()) == (&space_pres.get_trafo()),
109 "Velocity and Pressure spaces must be defined on the same trafo!");
110
113
114 // assembly traits
115 typedef AsmTraits2<
116 DataType,
117 SpaceVelo_,
118 SpacePres_,
121 SpaceTags::value> AsmTraits;
122
123 // fetch the trafo
124 const typename AsmTraits::TrafoType& trafo = space_velo.get_trafo();
125
126 // create a trafo evaluator
127 typename AsmTraits::TrafoEvaluator trafo_eval(trafo);
128
129 // create space evaluators
130 typename AsmTraits::TestEvaluator velo_eval(space_velo);
131 typename AsmTraits::TrialEvaluator pres_eval(space_pres);
132
133 // create dof-mappings
134 typename AsmTraits::TestDofMapping velo_dof_mapping(space_velo);
135 typename AsmTraits::TrialDofMapping pres_dof_mapping(space_pres);
136
137 // create trafo evaluation data
138 typename AsmTraits::TrafoEvalData trafo_data;
139
140 // create space evaluation data
141 typename AsmTraits::TestEvalData velo_data;
142 typename AsmTraits::TrialEvalData pres_data;
143
144 // maximum number of dofs
145 static constexpr int max_velo_dofs = AsmTraits::max_local_test_dofs;
146 static constexpr int max_pres_dofs = AsmTraits::max_local_trial_dofs;
147
148 // create local matrix data
149 //typename AsmTraits::LocalMatrixType lmd;
150 typedef Tiny::Matrix<DataType, dim_, 1> BEntryType;
151 typedef Tiny::Matrix<DataType, 1, dim_> DEntryType;
154
155 // create cubature rule
156 typename AsmTraits::CubatureRuleType cubature_rule(Cubature::ctor_factory, cubature_factory);
157
158 // first of all, check whether we need to assemble the matrix structures
159 if(matrix_b.empty())
160 {
161 Adjacency::Graph graph_b(SymbolicAssembler::assemble_graph_std2(space_velo, space_pres));
162 matrix_b = MatrixB(graph_b);
163 }
164 matrix_b.format();
165 if(matrix_d.empty())
166 {
167 Adjacency::Graph graph_d(SymbolicAssembler::assemble_graph_std2(space_pres, space_velo));
168 matrix_d = MatrixD(graph_d);
169 matrix_d.format();
170 }
171 matrix_d.format();
172
173 // create matrix scatter-axpy
174 typename MatrixB::ScatterAxpy scatter_b(matrix_b);
175 typename MatrixD::ScatterAxpy scatter_d(matrix_d);
176
177 // loop over all cells of the mesh
178 for(typename AsmTraits::CellIterator cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
179 {
180 // prepare trafo evaluator
181 trafo_eval.prepare(cell);
182
183 // prepare space evaluators
184 velo_eval.prepare(trafo_eval);
185 pres_eval.prepare(trafo_eval);
186
187 // fetch number of local dofs
188 const int num_loc_velo_dofs = velo_eval.get_num_local_dofs();
189 const int num_loc_pres_dofs = pres_eval.get_num_local_dofs();
190
191 // format local matrix
192 local_b.format();
193 local_d.format();
194
195 // loop over all quadrature points and integrate
196 for(int pt(0); pt < cubature_rule.get_num_points(); ++pt)
197 {
198 // compute trafo data
199 trafo_eval(trafo_data, cubature_rule.get_point(pt));
200
201 // compute basis function data
202 velo_eval(velo_data, trafo_data);
203 pres_eval(pres_data, trafo_data);
204
205 // test function loop
206 for(int i(0); i < num_loc_velo_dofs; ++i)
207 {
208 // trial function loop
209 for(int j(0); j < num_loc_pres_dofs; ++j)
210 {
211 const DataType pv = trafo_data.jac_det * cubature_rule.get_weight(pt) * pres_data.phi[j].value;
212
213 // dimension loop
214 for(int k(0); k < dim_; ++k)
215 {
216 local_b[i][j][k][0] += velo_data.phi[i].grad[k] * pv;
217 local_d[j][i][0][k] += velo_data.phi[i].grad[k] * pv;
218 }
219
220 // continue with next trial function
221 }
222 // continue with next test function
223 }
224 // continue with next cubature point
225 }
226
227 // finish evaluators
228 pres_eval.finish();
229 velo_eval.finish();
230 trafo_eval.finish();
231
232 // initialize dof-mappings
233 velo_dof_mapping.prepare(cell);
234 pres_dof_mapping.prepare(cell);
235
236 // incorporate local matrix
237 scatter_b(local_b, velo_dof_mapping, pres_dof_mapping, scale_b);
238 scatter_d(local_d, pres_dof_mapping, velo_dof_mapping, scale_d);
239
240 // finish dof mapping
241 pres_dof_mapping.finish();
242 velo_dof_mapping.finish();
243
244 // continue with next cell
245 }
246 }
247 };
248 } // namespace Assembly
249} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Adjacency Graph implementation.
Definition: graph.hpp:34
Common test-/trial-space assembly traits class template.
Definition: asm_traits.hpp:227
Grad(P)/Div(V) assembler class.
static void assemble(LAFEM::SparseMatrixBCSR< DataType_, IndexType_, dim_, 1 > &matrix_b, LAFEM::SparseMatrixBCSR< DataType_, IndexType_, 1, dim_ > &matrix_d, const SpaceVelo_ &space_velo, const SpacePres_ &space_pres, const String &cubature_name, const DataType_ scale_b=-DataType_(1), const DataType_ scale_d=-DataType_(1))
Assembles the B and D matrices.
static void assemble(LAFEM::SparseMatrixBCSR< DataType_, IndexType_, dim_, 1 > &matrix_b, LAFEM::SparseMatrixBCSR< DataType_, IndexType_, 1, dim_ > &matrix_d, const SpaceVelo_ &space_velo, const SpacePres_ &space_pres, const Cubature::DynamicFactory &cubature_factory, const DataType_ scale_b=-DataType_(1), const DataType_ scale_d=-DataType_(1))
Assembles the B and D matrices.
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.
Definition: container.hpp:1165
void format(DT_ value=DT_(0))
Reset all elements of the container to a given value or zero if missing.
Definition: container.hpp:851
CSR based blocked sparse matrix.
String class implementation.
Definition: string.hpp:46
Tiny Matrix class template.
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the matrix.
FEAT namespace.
Definition: adjactor.hpp:12
@ 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