FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
scalar_basic.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 <control/domain/deslagged_domain_control.hpp>
10#include <kernel/util/dist.hpp>
11#include <kernel/cubature/dynamic_factory.hpp>
12#include <kernel/lafem/dense_vector.hpp>
13#include <kernel/lafem/sparse_matrix_csr.hpp>
14#include <kernel/lafem/unit_filter.hpp>
15#include <kernel/lafem/mean_filter.hpp>
16#include <kernel/lafem/none_filter.hpp>
17#include <kernel/lafem/filter_chain.hpp>
18#include <kernel/lafem/filter_sequence.hpp>
19#include <kernel/lafem/vector_mirror.hpp>
20#include <kernel/lafem/transfer.hpp>
21#include <kernel/global/gate.hpp>
22#include <kernel/global/muxer.hpp>
23#include <kernel/global/vector.hpp>
24#include <kernel/global/matrix.hpp>
25#include <kernel/global/transfer.hpp>
26#include <kernel/global/splitter.hpp>
27#include <kernel/global/filter.hpp>
28#include <kernel/global/mean_filter.hpp>
29#include <kernel/assembly/common_operators.hpp>
30#include <kernel/assembly/symbolic_assembler.hpp>
31#include <kernel/assembly/domain_assembler_basic_jobs.hpp>
32#include <kernel/assembly/bilinear_operator_assembler.hpp>
33#include <kernel/assembly/grid_transfer.hpp>
34#include <kernel/assembly/mirror_assembler.hpp>
35#include <kernel/assembly/mean_filter_assembler.hpp>
36#include <kernel/assembly/unit_filter_assembler.hpp>
37#include <kernel/analytic/lambda_function.hpp>
38#include <kernel/solver/base.hpp>
39#include <kernel/solver/iterative.hpp>
40#include <kernel/util/property_map.hpp>
41#include <kernel/voxel_assembly/poisson_assembler.hpp>
42
43#include <control/domain/domain_control.hpp>
44#include <control/domain/adaptive_parti_domain_control.hpp>
45#include <control/asm/gate_asm.hpp>
46#include <control/asm/muxer_asm.hpp>
47#include <control/asm/splitter_asm.hpp>
48#include <control/asm/transfer_adaptive_asm.hpp>
49#include <control/asm/transfer_asm.hpp>
50#include <control/asm/transfer_deslagged_asm.hpp>
51#include <control/asm/mean_filter_asm.hpp>
52#include <control/asm/unit_filter_asm.hpp>
53
54#include <deque>
55
56namespace FEAT
57{
58 namespace Control
59 {
60 template<
61 typename DataType_ = Real,
62 typename IndexType_ = Index,
63 typename ScalarMatrix_ = LAFEM::SparseMatrixCSR<DataType_, IndexType_>,
64 typename TransferMatrix_ = LAFEM::SparseMatrixCSR<DataType_, IndexType_> >
66 {
67 public:
68 static_assert(std::is_same<DataType_, typename ScalarMatrix_::DataType>::value, "DataType mismatch!");
69 static_assert(std::is_same<IndexType_, typename ScalarMatrix_::IndexType>::value, "IndexType mismatch!");
70
71 // basic types
72 typedef DataType_ DataType;
73 typedef IndexType_ IndexType;
74
76 typedef ScalarMatrix_ LocalScalarMatrix;
77
79 typedef ScalarMatrix_ LocalSystemMatrix;
80
82 typedef TransferMatrix_ LocalSystemTransferMatrix;
83
85 typedef typename LocalSystemMatrix::VectorTypeR LocalSystemVector;
86
89
92
95
98
101
104
107
110
111 /* ***************************************************************************************** */
112
115
118
121
124
127
132 {
133 }
134
135 // no copies, no problems
137 ScalarBasicSystemLevel& operator=(const ScalarBasicSystemLevel&) = delete;
138
140 {
141 }
142
144 std::size_t bytes() const
145 {
146 return this->gate_sys.bytes() + this->coarse_muxer_sys.bytes() + this->base_splitter_sys.bytes()
147 + this->transfer_sys.bytes() + this->matrix_sys.local().bytes();
148 }
149
150 template<typename D_, typename I_, typename SM_>
151 void convert(const ScalarBasicSystemLevel<D_, I_, SM_> & other)
152 {
153 gate_sys.convert(other.gate_sys);
154 coarse_muxer_sys.convert(other.coarse_muxer_sys);
155 base_splitter_sys.convert(other.base_splitter_sys);
156 matrix_sys.convert(&gate_sys, &gate_sys, other.matrix_sys);
157 transfer_sys.convert(&coarse_muxer_sys, other.transfer_sys);
158 }
159
160 template<typename DomainLevel_, typename SpaceType_>
161 void assemble_gate(const Domain::VirtualLevel<DomainLevel_>& virt_dom_lvl, const SpaceType_& space)
162 {
163 Asm::asm_gate(virt_dom_lvl, space, this->gate_sys, true);
164 }
165
166 template<typename DomainLevel_>
167 void assemble_gate(const Domain::VirtualLevel<DomainLevel_>& virt_dom_lvl)
168 {
169 Asm::asm_gate(virt_dom_lvl, virt_dom_lvl->space, this->gate_sys, true);
170 }
171
172 template<typename DomainLevel_>
173 void assemble_coarse_muxer(const Domain::VirtualLevel<DomainLevel_>& virt_lvl_coarse)
174 {
175 Asm::asm_muxer(virt_lvl_coarse, [](const DomainLevel_& dl){return &dl.space;}, this->coarse_muxer_sys);
176 }
177
178 template<typename DomainLevel_>
179 void assemble_base_splitter(const Domain::VirtualLevel<DomainLevel_>& virt_lvl)
180 {
181 Asm::asm_splitter(virt_lvl, [](const DomainLevel_& dl){return &dl.space;}, this->base_splitter_sys);
182 }
183
184 template<typename DomainLevel_>
185 void assemble_transfer(
186 const ScalarBasicSystemLevel& sys_lvl_coarse,
187 const Domain::VirtualLevel<DomainLevel_>& virt_lvl_fine,
188 const Domain::VirtualLevel<DomainLevel_>& virt_lvl_coarse,
189 const String& cubature, bool trunc = false, bool shrink = true)
190 {
191 Asm::asm_transfer_scalar(virt_lvl_fine, virt_lvl_coarse, cubature, trunc, shrink,
192 [](const DomainLevel_& dl) {return &dl.space;},
193 this->transfer_sys.local(), this->coarse_muxer_sys, this->gate_sys, sys_lvl_coarse.gate_sys);
194
195 this->transfer_sys.compile();
196 }
197
198 template<typename DomainLevel_>
199 void assemble_transfer(
200 const Domain::VirtualLevel<DomainLevel_>& virt_lvl_fine,
201 const Domain::VirtualLevel<DomainLevel_>& virt_lvl_coarse,
202 const String& cubature, bool trunc = false, bool shrink = true)
203 {
204 // if the coarse level is a parent, then we need the coarse system level
205 XASSERT(!virt_lvl_coarse.is_parent());
206
207 Asm::asm_transfer_scalar(virt_lvl_fine, virt_lvl_coarse, cubature, trunc, shrink,
208 [](const DomainLevel_& dl) {return &dl.space;},
209 this->transfer_sys.local(), this->coarse_muxer_sys, this->gate_sys, this->gate_sys);
210
211 this->transfer_sys.compile();
212 }
213
214 template<typename DomainLevel_>
215 void assemble_transfer_deslagged(
216 const ScalarBasicSystemLevel& sys_lvl_coarse,
217 const Domain::VirtualLevel<Domain::DeslaggedDomainLevelWrapper<DomainLevel_>>& virt_lvl_fine,
218 const Domain::VirtualLevel<Domain::DeslaggedDomainLevelWrapper<DomainLevel_>>& virt_lvl_coarse,
219 const String& cubature, bool trunc = false, bool shrink = true)
220 {
221 Asm::asm_transfer_deslagged_scalar(virt_lvl_fine, virt_lvl_coarse, cubature, trunc, shrink,
222 [](const DomainLevel_& dl) {return &dl.space;},
223 this->transfer_sys.local(), this->coarse_muxer_sys, this->gate_sys, sys_lvl_coarse.gate_sys);
224
225 this->transfer_sys.compile();
226 }
227
228 template<typename DomainLevel_>
229 void assemble_transfer_deslagged(
230 const Domain::VirtualLevel<Domain::DeslaggedDomainLevelWrapper<DomainLevel_>>& virt_lvl_fine,
231 const Domain::VirtualLevel<Domain::DeslaggedDomainLevelWrapper<DomainLevel_>>& virt_lvl_coarse,
232 const String& cubature, bool trunc = false, bool shrink = true)
233 {
234 // if the coarse level is a parent, then we need the coarse system level
235 XASSERT(!virt_lvl_coarse.is_parent());
236
237 Asm::asm_transfer_deslagged_scalar(virt_lvl_fine, virt_lvl_coarse, cubature, trunc, shrink,
238 [](const DomainLevel_& dl) {return &dl.space;},
239 this->transfer_sys.local(), this->coarse_muxer_sys, this->gate_sys, this->gate_sys);
240
241 this->transfer_sys.compile();
242 }
243
244 template<typename DomainLevel_, typename TemplateSet_>
245 void assemble_transfer_adaptive(
246 const ScalarBasicSystemLevel& sys_lvl_coarse,
247 const Domain::VirtualLevel<Domain::AdaptiveLevelWrapper<DomainLevel_, TemplateSet_>>& virt_lvl_fine,
248 const Domain::VirtualLevel<Domain::AdaptiveLevelWrapper<DomainLevel_, TemplateSet_>>& virt_lvl_coarse,
249 const String& cubature, bool trunc = false, bool shrink = true)
250 {
251 Asm::asm_transfer_adaptive_scalar(virt_lvl_fine, virt_lvl_coarse, cubature, trunc, shrink,
252 [](const DomainLevel_& dl) {return &dl.space;},
253 this->transfer_sys.local(), this->coarse_muxer_sys, this->gate_sys, sys_lvl_coarse.gate_sys);
254
255 this->transfer_sys.compile();
256 }
257
258 template<typename DomainLevel_, typename TemplateSet_>
259 void assemble_transfer_adaptive(
260 const Domain::VirtualLevel<Domain::AdaptiveLevelWrapper<DomainLevel_, TemplateSet_>>& virt_lvl_fine,
261 const Domain::VirtualLevel<Domain::AdaptiveLevelWrapper<DomainLevel_, TemplateSet_>>& virt_lvl_coarse,
262 const String& cubature, bool trunc = false, bool shrink = true)
263 {
264 // if the coarse level is a parent, then we need the coarse system level
265 XASSERT(!virt_lvl_coarse.is_parent());
266
267 Asm::asm_transfer_adaptive_scalar(virt_lvl_fine, virt_lvl_coarse, cubature, trunc, shrink,
268 [](const DomainLevel_& dl) {return &dl.space;},
269 this->transfer_sys.local(), this->coarse_muxer_sys, this->gate_sys, this->gate_sys);
270
271 this->transfer_sys.compile();
272 }
273
274 template<typename Space_, typename Cubature_>
275 void assemble_laplace_matrix(const Space_& space, const Cubature_& cubature, const DataType nu = DataType(1))
276 {
277 // get local matrix
278 auto& loc_matrix = this->matrix_sys.local();
279
280 // assemble structure?
281 if(loc_matrix.empty())
282 {
284 }
285
286 // format and assemble Laplace
287 loc_matrix.format();
288 Assembly::Common::LaplaceOperator laplace_op;
289 Assembly::BilinearOperatorAssembler::assemble_matrix1(loc_matrix, laplace_op, space, cubature, nu);
290 }
291
292 template<typename Trafo_, typename Space_>
293 void assemble_laplace_matrix(Assembly::DomainAssembler<Trafo_>& dom_asm, const Space_& space, const String& cubature, const DataType nu = DataType(1))
294 {
295 // get local matrix
296 auto& loc_matrix = this->matrix_sys.local();
297
298 // assemble structure?
299 if(loc_matrix.empty())
300 {
302 }
303
304 // format and assemble Laplace
305 loc_matrix.format();
306 Assembly::Common::LaplaceOperator laplace_op;
307 Assembly::assemble_bilinear_operator_matrix_1(dom_asm, loc_matrix, laplace_op, space, cubature, nu);
308 }
309
310 template<typename Space_>
311 void assemble_laplace_voxel_based(const Adjacency::Coloring& coloring, const Space_& space, const String& cubature, const DataType nu = DataType(1))
312 {
313 // get local matrix
314 auto& loc_matrix = this->matrix_sys.local();
315
316 // assemble structure?
317 if(loc_matrix.empty())
318 {
320 }
321
322 // format and assemble Laplace
323 loc_matrix.format();
324 VoxelAssembly::VoxelPoissonAssembler<Space_, DataType, IndexType> voxel_assembler(space, coloring);
325 voxel_assembler.assemble_matrix1(loc_matrix, space, Cubature::DynamicFactory(cubature), nu);
326 }
327
328 template<typename Space_>
329 void symbolic_assembly_std1(const Space_& space)
330 {
331 // get local matrix
332 auto& loc_matrix = this->matrix_sys.local();
333
334 ASSERTM(loc_matrix.empty(), "Called symbolic assembly on non empty matrix");
335 // assemble structure?
337
338 }
339 }; // class ScalarBasicSystemLevel<...>
340
341 template<
342 typename DataType_ = Real,
343 typename IndexType_ = Index,
344 typename ScalarMatrix_ = LAFEM::SparseMatrixCSR<DataType_, IndexType_> >
346 public ScalarBasicSystemLevel<DataType_, IndexType_, ScalarMatrix_>
347 {
348 public:
350
351 // basic types
352 typedef DataType_ DataType;
353 typedef IndexType_ IndexType;
354
357
360
363
365 template <typename DT2_, typename IT2_, typename ScalarMatrix2_>
367
370
373 BaseClass()
374 {
375 }
376
378 std::size_t bytes() const
379 {
380 return BaseClass::bytes() + this->filter_sys.local().bytes();
381 }
382
390 template<typename D_, typename I_, typename SM_>
392 {
393 BaseClass::convert(other);
394 filter_sys.convert(other.filter_sys);
395 }
396
397 template<typename DomainLevel_, typename Space_>
398 void assemble_homogeneous_unit_filter(const DomainLevel_& dom_level, const Space_& space)
399 {
400 Asm::asm_unit_filter_scalar_homogeneous(this->filter_sys.local(), dom_level, space, "*");
401 }
402
403 }; // class ScalarUnitFilterSystemLevel<...>
404
405 template<
406 typename DataType_ = Real,
407 typename IndexType_ = Index,
408 typename ScalarMatrix_ = LAFEM::SparseMatrixCSR<DataType_, IndexType_> >
410 public ScalarBasicSystemLevel<DataType_, IndexType_, ScalarMatrix_>
411 {
412 public:
414
415 // basic types
416 typedef DataType_ DataType;
417 typedef IndexType_ IndexType;
418
421
424
427
429 template <typename DT2_, typename IT2_, typename ScalarMatrix2_>
431
434
437 BaseClass()
438 {
439 }
440
442 std::size_t bytes() const
443 {
444 return BaseClass::bytes() + this->filter_sys.local().bytes();
445 }
446
454 template<typename D_, typename I_, typename SM_>
456 {
457 BaseClass::convert(other);
458 filter_sys.convert(other.filter_sys);
459 }
460
461 template<typename Space_, typename Cubature_>
462 void assemble_mean_filter(const Space_& space, const Cubature_& cubature)
463 {
464 this->filter_sys.local() = Asm::asm_mean_filter(this->gate_sys, space, cubature);
465 }
466 }; // class ScalarMeanFilterSystemLevel<...>
467
468 template<
469 typename DataType_ = Real,
470 typename IndexType_ = Index,
471 typename ScalarMatrix_ = LAFEM::SparseMatrixCSR<DataType_, IndexType_> >
473 public ScalarBasicSystemLevel<DataType_, IndexType_, ScalarMatrix_>
474 {
475 public:
477
478 // basic types
479 typedef DataType_ DataType;
480 typedef IndexType_ IndexType;
481
484
490
493
495 template <typename DT2_, typename IT2_, typename ScalarMatrix2_>
497
500
503 BaseClass()
504 {
505 }
506
508 std::size_t bytes() const
509 {
510 return BaseClass::bytes() + this->filter_sys.local().bytes();
511 }
512
513 template<typename D_, typename I_, typename SM_>
514 void convert(const ScalarMeanFilterSystemLevel<D_, I_, SM_> & other)
515 {
516 BaseClass::convert(other);
517 filter_sys.convert(other.filter_sys);
518 }
519
520 LocalUnitFilterSeq& get_local_unit_filter_seq()
521 {
522 return this->filter_sys.local().template at<0>();
523 }
524
525 LocalUnitFilter& get_local_unit_filter(const String& name)
526 {
527 return get_local_unit_filter_seq().find_or_add(name);
528 }
529
530 LocalMeanFilter& get_local_mean_filter()
531 {
532 return this->filter_sys.local().template at<1>();
533 }
534
535 template<typename DomainLevel_, typename Space_>
536 void assemble_unit_filter(const DomainLevel_& dom_level, const Space_& space, const String& name, const String& mesh_part_names)
537 {
538 auto& loc_filter = get_local_unit_filter(name);
539 loc_filter.clear();
540 Asm::asm_unit_filter_scalar_homogeneous(loc_filter, dom_level, space, mesh_part_names);
541 }
542
543 template<typename DomainLevel_, typename Space_, typename Function_>
544 void assemble_unit_filter(const DomainLevel_& dom_level, const Space_& space, const String& name, const String& mesh_part_names, const Function_& function)
545 {
546 auto& loc_filter = get_local_unit_filter(name);
547 loc_filter.clear();
548 Asm::asm_unit_filter_scalar(loc_filter, dom_level, space, mesh_part_names, function);
549 }
550
551 template<typename Space_>
552 void assemble_mean_filter(const Space_& space, const String& cubature)
553 {
554 get_local_mean_filter() = Asm::asm_mean_filter(this->gate_sys, space, cubature);
555 }
556 }; // class ScalarCombinedSystemLevel<...>
557 } // namespace Control
558} // namespace FEAT
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
FEAT Kernel base header.
static void assemble_matrix1(Matrix_ &matrix, Operator_ &operat, const Space_ &space, const CubatureFactory_ &cubature_factory, typename Matrix_::DataType alpha=typename Matrix_::DataType(1))
Assembles a bilinear operator into a matrix.
static void assemble_matrix_std1(MatrixType_ &matrix, const Space_ &space)
Assembles a standard matrix structure from a single space.
Global::Muxer< LocalSystemVector, SystemMirror > SystemMuxer
define system muxer
LocalSystemMatrix::VectorTypeR LocalSystemVector
define local system vector type
LAFEM::Transfer< LocalSystemTransferMatrix > LocalSystemTransfer
define local system transfer operator type
SystemGate gate_sys
our system gate
Global::Transfer< LocalSystemTransfer, SystemMirror > GlobalSystemTransfer
define global system transfer operator type
std::size_t bytes() const
Returns the total amount of bytes allocated.
SystemSplitter base_splitter_sys
our base-mesh multiplexer
ScalarMatrix_ LocalScalarMatrix
define local scalar matrix type
LAFEM::VectorMirror< DataType, IndexType > SystemMirror
define system mirror type
TransferMatrix_ LocalSystemTransferMatrix
define local transfer matrix type
GlobalSystemTransfer transfer_sys
our global transfer operator
SystemMuxer coarse_muxer_sys
our coarse-level system muxer
Global::Matrix< LocalSystemMatrix, SystemMirror, SystemMirror > GlobalSystemMatrix
define global system matrix type
Global::Vector< LocalSystemVector, SystemMirror > GlobalSystemVector
define global system vector type
Global::Gate< LocalSystemVector, SystemMirror > SystemGate
define system gate
Global::Splitter< LocalSystemVector, SystemMirror > SystemSplitter
define system splitter
GlobalSystemMatrix matrix_sys
our global system matrix
ScalarMatrix_ LocalSystemMatrix
define local system matrix type
Global::Filter< LocalSystemFilter, SystemMirror > GlobalSystemFilter
define global filter types
LAFEM::VectorMirror< DataType, IndexType > SystemMirror
define system mirror type
std::size_t bytes() const
Returns the total amount of bytes allocated.
GlobalSystemFilter filter_sys
our global system filter
LAFEM::UnitFilter< DataType, IndexType > LocalUnitFilter
define local filter types
GlobalSystemFilter filter_sys
our global system filter
Global::Filter< LocalSystemFilter, SystemMirror > GlobalSystemFilter
define global filter type
Global::MeanFilter< DataType_, IndexType_ > LocalSystemFilter
define local filter type
std::size_t bytes() const
Returns the total amount of bytes allocated.
void convert(const ScalarMeanFilterSystemLevel< D_, I_, SM_ > &other)
Conversion method.
LAFEM::VectorMirror< DataType, IndexType > SystemMirror
define system mirror type
LAFEM::VectorMirror< DataType, IndexType > SystemMirror
define system mirror type
Global::Filter< LocalSystemFilter, SystemMirror > GlobalSystemFilter
define global filter type
std::size_t bytes() const
Returns the total amount of bytes allocated.
LAFEM::UnitFilter< DataType_, IndexType_ > LocalSystemFilter
define local filter type
GlobalSystemFilter filter_sys
our global system filter
void convert(const ScalarUnitFilterSystemLevel< D_, I_, SM_ > &other)
Conversion method.
Global Filter wrapper class template.
Definition: filter.hpp:21
Global gate implementation.
Definition: gate.hpp:78
void convert(const Gate< LVT2_, MT2_ > &other)
Conversion function for same vector container type but with different MDI-Type.
Definition: gate.hpp:238
std::size_t bytes() const
Returns the total amount of bytes allocated.
Definition: gate.hpp:318
Global Matrix wrapper class template.
Definition: matrix.hpp:40
LocalMatrix_ & local()
Returns a reference to the internal local LAFEM matrix object.
Definition: matrix.hpp:136
Mean Filter class template.
Definition: mean_filter.hpp:23
Global multiplexer/demultiplexer implementation.
Definition: muxer.hpp:68
std::size_t bytes() const
Returns the internal data size in bytes.
Definition: muxer.hpp:211
void convert(const Muxer< LVT2_, MT2_ > &other)
Conversion function for same vector container type but with different MDI-Type.
Definition: muxer.hpp:155
Global base-mesh vector splitter (and joiner) implementation.
Definition: splitter.hpp:59
std::size_t bytes() const
Returns the internal data size in bytes.
Definition: splitter.hpp:163
void convert(const Splitter< LVT2_, MT2_ > &other)
Conversion function for same vector container type but with different MDI-Type.
Definition: splitter.hpp:124
Global grid-transfer operator class template.
Definition: transfer.hpp:23
void convert(MuxerType *coarse_muxer, const Transfer< LocalTransfer2_, Mirror2_ > &other)
container conversion function
Definition: transfer.hpp:107
std::size_t bytes() const
Definition: transfer.hpp:143
LocalTransfer_ & local()
Definition: transfer.hpp:131
Global vector wrapper class template.
Definition: vector.hpp:68
Filter Chainclass template.
std::size_t bytes() const
Returns the total amount of bytes allocated.
Sequence of filters of the same type.
Grid-Transfer operator class template.
Definition: transfer.hpp:27
Unit Filter class template.
Definition: unit_filter.hpp:31
std::size_t bytes() const
Returns the total amount of bytes allocated.
Handles vector prolongation, restriction and serialization.
void assemble_bilinear_operator_matrix_1(DomainAssembler< Trafo_ > &dom_asm, Matrix_ &matrix, const BilOp_ &bilinear_operator, const Space_ &space, const String &cubature, const typename Matrix_::DataType alpha=typename Matrix_::DataType(1))
Assembles a bilinear operator into a matrix with identical test- and trial-spaces.
FEAT namespace.
Definition: adjactor.hpp:12
double Real
Real data type.
std::uint64_t Index
Index data type.