FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
mirror_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/symbolic_assembler.hpp>
10
11// includes, FEAT-LAFEM
12#include <kernel/lafem/matrix_mirror.hpp>
13#include <kernel/lafem/vector_mirror.hpp>
14#include <kernel/lafem/power_mirror.hpp>
15#include <kernel/lafem/dense_vector.hpp>
16#include <kernel/lafem/sparse_matrix_csr.hpp>
17#include <kernel/lafem/sparse_matrix_banded.hpp>
18
19namespace FEAT
20{
21 namespace Assembly
22 {
24 namespace Intern
25 {
26 template<
27 typename Space_,
28 typename MeshPart_,
29 int shape_dim_>
30 struct DofMirrorHelper
31 {
32 static Index count(const Space_& space, const MeshPart_& mesh_part)
33 {
34 // fetch the target set for this dimension
35 const typename MeshPart_::template TargetSet<shape_dim_>::Type&
36 target_set(mesh_part.template get_target_set<shape_dim_>());
37 if(target_set.get_num_entities() <= 0)
38 return 0;
39
40 // create a dof-assignment object
41 typename Space_::template DofAssignment<shape_dim_>::Type dof_assign(space);
42 if(dof_assign.get_max_assigned_dofs() <= 0)
43 return 0;
44
45 // loop over all target indices
46 Index num_entities = target_set.get_num_entities();
47 Index count(0);
48 for(Index i(0); i < num_entities; ++i)
49 {
50 dof_assign.prepare(target_set[i]);
51 count += Index(dof_assign.get_num_assigned_dofs());
52 dof_assign.finish();
53 }
54
55 return count;
56 }
57
58 template<typename IT_>
59 static Index fill(IT_ idx[], Index offset, const Space_& space, const MeshPart_& mesh_part)
60 {
61 // fetch the target set for this dimension
62 const typename MeshPart_::template TargetSet<shape_dim_>::Type&
63 target_set(mesh_part.template get_target_set<shape_dim_>());
64 if(target_set.get_num_entities() <= 0)
65 return offset;
66
67 // create a dof-assignment object
68 typename Space_::template DofAssignment<shape_dim_>::Type dof_assign(space);
69 if(dof_assign.get_max_assigned_dofs() <= 0)
70 return offset;
71
72 // loop over all target indices
73 Index num_entities = target_set.get_num_entities();
74 for(Index i(0); i < num_entities; ++i)
75 {
76 dof_assign.prepare(target_set[i]);
77 int num_assign(dof_assign.get_num_assigned_dofs());
78 for(int j(0); j < num_assign; ++j, ++offset)
79 {
80 idx[offset] = IT_(dof_assign.get_index(j));
81 }
82 dof_assign.finish();
83 }
84
85 return offset;
86 }
87 };
88
89 template<
90 typename Space_,
91 typename MeshPart_,
92 int shape_dim_ = Space_::shape_dim>
93 struct DofMirrorHelpWrapper
94 {
95 static Index count(const Space_& space, const MeshPart_& mesh_part)
96 {
97 // recursive call
98 return DofMirrorHelpWrapper<Space_, MeshPart_, shape_dim_ - 1>::count(space, mesh_part) +
99 DofMirrorHelper<Space_, MeshPart_, shape_dim_>::count(space, mesh_part);
100 }
101
102 template<typename IT_>
103 static Index fill(IT_ idx[], const Space_& space, const MeshPart_& mesh_part)
104 {
105 Index offset = DofMirrorHelpWrapper<Space_, MeshPart_, shape_dim_ - 1>::fill(idx, space, mesh_part);
106 return DofMirrorHelper<Space_, MeshPart_, shape_dim_>::fill(idx, offset, space, mesh_part);
107 }
108 };
109
110 template<
111 typename Space_,
112 typename MeshPart_>
113 struct DofMirrorHelpWrapper<Space_, MeshPart_, 0>
114 {
115 static Index count(const Space_& space, const MeshPart_& mesh_part)
116 {
117 return DofMirrorHelper<Space_, MeshPart_, 0>::count(space, mesh_part);
118 }
119
120 template<typename IT_>
121 static Index fill(IT_ idx[], const Space_& space, const MeshPart_& mesh_part)
122 {
123 return DofMirrorHelper<Space_, MeshPart_, 0>::fill(idx, 0, space, mesh_part);
124 }
125 };
126 } // namespace Intern
128
135 {
136 public:
149 template<
150 typename DataType_,
151 typename IndexType_,
152 typename Space_,
153 typename MeshPart_>
154 static void assemble_mirror(
156 const Space_& space, const MeshPart_& mesh_part)
157 {
158 // count number of dofs in mirror
159 const Index count = Intern::DofMirrorHelpWrapper<Space_, MeshPart_>::count(space, mesh_part);
160
161 // allocate mirror in main memory
162 vec_mirror = LAFEM::VectorMirror<DataType_, IndexType_>(space.get_num_dofs(), count);
163
164 // fill mirror indices
165 if(count > Index(0))
166 {
167 Intern::DofMirrorHelpWrapper<Space_, MeshPart_>::fill(vec_mirror.indices(), space, mesh_part);
168 }
169 }
170
171 template<
172 typename DataType_,
173 typename IndexType_,
174 Index blocks_,
175 typename Space_,
176 typename MeshPart_>
177 static void assemble_mirror(
179 const Space_& space, const MeshPart_& mesh_part)
180 {
181 assemble_mirror(vec_mirror._sub_mirror, space, mesh_part);
182 }
183 }; // class MirrorAssembler
184 } // namespace Assembly
185} // namespace FEAT
Dof-Mirror assembler class template.
static void assemble_mirror(LAFEM::VectorMirror< DataType_, IndexType_ > &vec_mirror, const Space_ &space, const MeshPart_ &mesh_part)
Assembles a VectorMirror from a space and a mesh-part.
PowerVector meta-mirror class template.
Handles vector prolongation, restriction and serialization.
IT_ * indices()
Get a pointer to the non zero indices array.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.