FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
burgers_velo_material_assembler.cpp
1#include <kernel/voxel_assembly/burgers_velo_material_assembler.hpp>
2#include <kernel/lafem/matrix_gather_scatter_helper.hpp>
3#include <kernel/lafem/vector_gather_scatter_helper.hpp>
4#include <kernel/util/math.hpp>
5#include <kernel/lafem/vector_mirror.hpp>
6#include <kernel/global/vector.hpp>
7
8namespace FEAT
9{
10 namespace VoxelAssembly
11 {
12 namespace Kernel
13 {
14
15 template<typename Space_, typename DT_, typename IT_, typename ViscFunc, typename ViscDFunc,
16 FEAT::Intern::MatrixGatherScatterPolicy pol_ = FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>
17 void full_burgers_vm_assembler_matrix1_bcsr_host(DT_* matrix_data, const DT_* conv_data,
18 const IT_* matrix_row_ptr, const IT_* matrix_col_idx, Index matrix_num_rows, Index matrix_num_cols,
20 const DT_* cub_wg, int num_cubs, DT_ alpha,
21 const IT_* cell_to_dof, [[maybe_unused]] Index cell_num,
22 const Tiny::Vector<DT_, Space_::world_dim>* nodes, [[maybe_unused]] Index node_size,
23 const int* coloring_map, Index coloring_size, const IT_* cell_to_dof_sorter,
24 const VoxelAssembly::AssemblyBurgersData<DT_>& burgers_params,
25 const VoxelAssembly::AssemblyMaterialData<DT_>& material_params,
26 ViscFunc visco_func, ViscDFunc visco_d_func)
27 {
28 //define types
29 typedef Space_ SpaceType;
30 typedef DT_ DataType;
31 typedef IT_ IndexType;
32
33 const DataType& beta{burgers_params.beta};
34 const DataType& sd_delta{burgers_params.sd_delta};
35 const DataType& sd_v_norm{burgers_params.sd_v_norm};
36
37 const DataType tol_eps = Math::sqrt(Math::eps<DataType>());
38 // const DataType tol_eps = CudaMath::cuda_sqrt(DBL_EPSILON);
39 // const DataType tol_eps = DBL_EPSILON;
40 const bool need_streamline = (Math::abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
41 const bool need_convection = Math::abs(beta) > DataType(0);
42
44
45 constexpr int dim = SpaceHelp::dim;
46
47 //define local sizes
48 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
49 //get number of nodes per element
50 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
51
52 //our local datatypes
53 typedef Tiny::Vector<DataType, dim> VecValueType;
54 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
55 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
57
58 FEAT_PRAGMA_OMP(parallel for)
59 for(Index idx = 0; idx < coloring_size; ++idx)
60 {
61 // define local coefficients
63 // and local matrix
64 LocalMatrixType loc_mat;
65 LocalVectorType local_conv_dofs(DataType(0));
66 // now do work for this cell
67 IndexType cell = IndexType(coloring_map[idx]);
68 // std::cout << "Starting with cell " << cell << std::endl;
69 const IndexSetWrapper<IndexType> local_dofs_w{cell_to_dof, IndexType(num_loc_dofs)};
70 const IndexType* local_dofs = cell_to_dof + cell*num_loc_dofs;
71 const IndexType* local_dof_sorter = cell_to_dof_sorter + cell*num_loc_dofs;
72
73 SpaceHelp::set_coefficients(local_coeffs, local_dofs_w, nodes, cell);
74 //always gather local conv data
75 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_conv_dofs,
76 (const VecValueType*)conv_data, IndexType(matrix_num_rows), local_dofs,DataType(1));
77 if(need_streamline)
78 {
79 VoxelAssembly::Kernel::burgers_velo_material_mat_assembly_kernel<SpaceHelp, LocalMatrixType, LocalVectorType, dim, num_loc_verts, ViscFunc, ViscDFunc, true>(
80 loc_mat, local_conv_dofs, local_coeffs, cub_pt, cub_wg, num_cubs, burgers_params, material_params, need_convection, tol_eps, visco_func, visco_d_func);
81 }
82 else
83 {
84 VoxelAssembly::Kernel::burgers_velo_material_mat_assembly_kernel<SpaceHelp, LocalMatrixType, LocalVectorType, dim, num_loc_verts, ViscFunc, ViscDFunc, false>(
85 loc_mat, local_conv_dofs, local_coeffs, cub_pt, cub_wg, num_cubs, burgers_params, material_params, need_convection, tol_eps, visco_func, visco_d_func);
86 }
87
88 //scatter
89 LAFEM::template MatrixGatherScatterHelper<SpaceType, DataType, IndexType, pol_>::scatter_matrix_csr(loc_mat, (MatValueType*)matrix_data, local_dofs, local_dofs, IndexType(matrix_num_rows), IndexType(matrix_num_cols), matrix_row_ptr, matrix_col_idx, alpha, local_dof_sorter);
90
91 }
92 }
93
94 template<typename Space_, typename DT_, typename IT_, typename ViscFunc>
95 void full_burgers_vm_assembler_vector_bd_host(DT_* vector_data,
96 const DT_* conv_data, const DT_* primal_data, Index vec_size,
98 const DT_* cub_wg, int num_cubs, DT_ alpha,
99 const IT_* cell_to_dof, [[maybe_unused]] Index cell_num,
100 const Tiny::Vector<DT_, Space_::world_dim>* nodes, [[maybe_unused]] Index node_size,
101 const int* coloring_map, Index coloring_size,
102 const VoxelAssembly::AssemblyBurgersData<DT_>& burgers_params,
103 const ViscFunc& visco_func)
104 {
105 //define types
106 typedef Space_ SpaceType;
107 typedef DT_ DataType;
108 typedef IT_ IndexType;
109
110 const DataType& beta{burgers_params.beta};
111
112 const bool need_convection = Math::abs(beta) > DataType(0);
113
115
116 constexpr int dim = SpaceHelp::dim;
117
118 //define local sizes
119 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
120 //get number of nodes per element
121 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
122
123 //our local datatypes
124 typedef Tiny::Vector<DataType, dim> VecValueType;
125 // typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
126 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
127 // typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
128
129 FEAT_PRAGMA_OMP(parallel for)
130 for(Index idx = 0; idx < coloring_size; ++idx)
131 {
132 //define local array
133 LocalVectorType loc_vec(DataType(0));
134 LocalVectorType local_conv_dofs(DataType(0));
135 LocalVectorType local_prim_dofs(DataType(0));
136 // typename NewSpaceHelp::ImagePointType img_point;
138
139 //now do work for this cell
140 IndexType cell = IndexType(coloring_map[idx]);
141 const IndexSetWrapper<IndexType> local_dofs_w{cell_to_dof, IndexType(num_loc_dofs)};
142 const IndexType* local_dofs = cell_to_dof + cell*num_loc_dofs;
143 SpaceHelp::set_coefficients(local_coeffs, local_dofs_w, nodes, cell);
144 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_prim_dofs,
145 (const VecValueType*)primal_data, IndexType(vec_size), local_dofs, DataType(1));
146
147 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_conv_dofs,
148 (const VecValueType*)conv_data, IndexType(vec_size), local_dofs, DataType(1));
149
150 VoxelAssembly::Kernel::burgers_velo_material_defect_assembly_kernel<SpaceHelp>(loc_vec, local_prim_dofs, local_conv_dofs, local_coeffs, cub_pt, cub_wg, num_cubs,
151 burgers_params, need_convection, visco_func);
152 //scatter
153 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::scatter_vector_dense(loc_vec,
154 (VecValueType*)vector_data, IndexType(vec_size), local_dofs, alpha);
155
156 }
157 }
158 }
159
160 namespace Arch
161 {
162 template<typename Space_, typename DT_, typename IT_>
163 void assemble_burgers_velo_material_csr_host([[maybe_unused]]const Space_& space,
164 const CSRMatrixData<DT_, IT_>& matrix_data,
165 const DT_* conv_data,
166 const AssemblyCubatureData<DT_>& cubature,
167 const AssemblyMappingData<DT_, IT_>& dof_mapping,
168 const std::vector<int*>& coloring_maps,
169 const std::vector<Index>& coloring_map_sizes,
170 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params,
171 const AssemblyMaterialData<DT_>& material_params, MaterialType material_type)
172 {
173 switch(material_type)
174 {
175 case MaterialType::carreau:
176 {
177 for(Index col = 0; col < Index(coloring_maps.size()); ++col)
178 {
179 VoxelAssembly::Kernel::template full_burgers_vm_assembler_matrix1_bcsr_host<Space_, DT_, IT_, Intern::ViscoFunctor<DT_, MaterialType::carreau>, Intern::ViscoDFunctor<DT_, MaterialType::carreau>,
180 FEAT::Intern::MatrixGatherScatterPolicy::useLocalSortHelper>(
181 matrix_data.data, conv_data, matrix_data.row_ptr, matrix_data.col_idx, matrix_data.num_rows, matrix_data.num_cols,
182 (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
183 cubature.cub_wg, cubature.num_cubs, alpha,
184 dof_mapping.cell_to_dof, dof_mapping.cell_num,
185 (const typename Tiny::Vector<DT_, Space_::world_dim>*) dof_mapping.nodes, dof_mapping.node_size,
186 (const int*) coloring_maps[col], coloring_map_sizes[col], dof_mapping.cell_to_dof_sorter,
187 burgers_params, material_params, Intern::ViscoFunctor<DT_, MaterialType::carreau>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T},
188 Intern::ViscoDFunctor<DT_, MaterialType::carreau>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T}
189 );
190 }
191 break;
192 }
193 case MaterialType::carreauYasuda:
194 {
195 for(Index col = 0; col < Index(coloring_maps.size()); ++col)
196 {
197 VoxelAssembly::Kernel::template full_burgers_vm_assembler_matrix1_bcsr_host<Space_, DT_, IT_, Intern::ViscoFunctor<DT_, MaterialType::carreauYasuda>, Intern::ViscoDFunctor<DT_, MaterialType::carreauYasuda>,
198 FEAT::Intern::MatrixGatherScatterPolicy::useLocalSortHelper>(
199 matrix_data.data, conv_data, matrix_data.row_ptr, matrix_data.col_idx, matrix_data.num_rows, matrix_data.num_cols,
200 (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
201 cubature.cub_wg, cubature.num_cubs, alpha,
202 dof_mapping.cell_to_dof, dof_mapping.cell_num,
203 (const typename Tiny::Vector<DT_, Space_::world_dim>*) dof_mapping.nodes, dof_mapping.node_size,
204 (const int*) coloring_maps[col], coloring_map_sizes[col], dof_mapping.cell_to_dof_sorter,
205 burgers_params, material_params, Intern::ViscoFunctor<DT_, MaterialType::carreauYasuda>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T,material_params.yasuda_a, material_params.mu_inf},
206 Intern::ViscoDFunctor<DT_, MaterialType::carreauYasuda>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T, material_params.yasuda_a, material_params.mu_inf}
207 );
208 }
209 break;
210 }
211 }
212
213 }
214
215 template<typename Space_, typename DT_, typename IT_>
216 void assemble_burgers_velo_material_defect_host([[maybe_unused]] const Space_& space,
217 DT_* vector_data,
218 const DT_* conv_data,
219 const DT_* primal_data,
220 const AssemblyCubatureData<DT_>& cubature,
221 const AssemblyMappingData<DT_, IT_>& dof_mapping,
222 const std::vector<int*>& coloring_maps,
223 const std::vector<Index>& coloring_map_sizes,
224 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params,
225 const AssemblyMaterialData<DT_>& material_params, MaterialType material_type)
226 {
227 switch(material_type)
228 {
229 case MaterialType::carreau:
230 {
231 for(Index col = 0; col < Index(coloring_maps.size()); ++col)
232 {
233 VoxelAssembly::Kernel::template full_burgers_vm_assembler_vector_bd_host<Space_, DT_, IT_, Intern::ViscoFunctor<DT_, MaterialType::carreau>>(vector_data, conv_data, primal_data,
234 space.get_num_dofs(), (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
235 cubature.cub_wg, cubature.num_cubs, alpha,
236 dof_mapping.cell_to_dof, dof_mapping.cell_num,
237 (const typename Tiny::Vector<DT_, Space_::world_dim>*) dof_mapping.nodes, dof_mapping.node_size,
238 (const int*) coloring_maps[col], coloring_map_sizes[col], burgers_params,
239 Intern::ViscoFunctor<DT_, MaterialType::carreau>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T}
240 );
241 }
242 break;
243 }
244 case MaterialType::carreauYasuda:
245 {
246 for(Index col = 0; col < Index(coloring_maps.size()); ++col)
247 {
248 VoxelAssembly::Kernel::template full_burgers_vm_assembler_vector_bd_host<Space_, DT_, IT_, Intern::ViscoFunctor<DT_, MaterialType::carreauYasuda>>(vector_data, conv_data, primal_data,
249 space.get_num_dofs(), (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
250 cubature.cub_wg, cubature.num_cubs, alpha,
251 dof_mapping.cell_to_dof, dof_mapping.cell_num,
252 (const typename Tiny::Vector<DT_, Space_::world_dim>*) dof_mapping.nodes, dof_mapping.node_size,
253 (const int*) coloring_maps[col], coloring_map_sizes[col], burgers_params,
254 Intern::ViscoFunctor<DT_, MaterialType::carreauYasuda>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T, material_params.yasuda_a, material_params.mu_inf}
255 );
256 }
257 break;
258 }
259 }
260 }
261
262 }
263 }
264}
265
266//instantiate the templates
267using namespace FEAT;
268using namespace FEAT::VoxelAssembly;
269
270
271/*******************************************************2D implementations***************************************************/
273 const std::vector<int*>&, const std::vector<Index>&, double, const AssemblyBurgersData<double>&, const AssemblyMaterialData<double>&, MaterialType);
275 const std::vector<int*>&, const std::vector<Index>&, float, const AssemblyBurgersData<float>&, const AssemblyMaterialData<float>&, MaterialType);
277 const std::vector<int*>&, const std::vector<Index>&, double, const AssemblyBurgersData<double>&, const AssemblyMaterialData<double>&, MaterialType);
279 const std::vector<int*>&, const std::vector<Index>&, float, const AssemblyBurgersData<float>&, const AssemblyMaterialData<float>&, MaterialType);
280#ifdef FEAT_HAVE_HALFMATH
282 const std::vector<int*>&, const std::vector<Index>&, Half, const AssemblyBurgersData<Half>&, const AssemblyMaterialData<Half>&, MaterialType);
284 const std::vector<int*>&, const std::vector<Index>&, Half, const AssemblyBurgersData<Half>&, const AssemblyMaterialData<Half>&, MaterialType);
285#endif
286
288 const std::vector<int*>&, const std::vector<Index>&, double, const AssemblyBurgersData<double>&, const AssemblyMaterialData<double>&, MaterialType);
290 const std::vector<int*>&, const std::vector<Index>&, float, const AssemblyBurgersData<float>&, const AssemblyMaterialData<float>&, MaterialType);
292 const std::vector<int*>&, const std::vector<Index>&, double, const AssemblyBurgersData<double>&, const AssemblyMaterialData<double>&, MaterialType);
294 const std::vector<int*>&, const std::vector<Index>&, float, const AssemblyBurgersData<float>&, const AssemblyMaterialData<float>&, MaterialType);
295#ifdef FEAT_HAVE_HALFMATH
297 const std::vector<int*>&, const std::vector<Index>&, Half, const AssemblyBurgersData<Half>&, const AssemblyMaterialData<Half>&, MaterialType);
299 const std::vector<int*>&, const std::vector<Index>&, Half, const AssemblyBurgersData<Half>&, const AssemblyMaterialData<Half>&, MaterialType);
300#endif
301
302
303/*********************************************************3D implementations**************************************************************************************/
305 const std::vector<int*>&, const std::vector<Index>&, double, const AssemblyBurgersData<double>&, const AssemblyMaterialData<double>&, MaterialType);
307 const std::vector<int*>&, const std::vector<Index>&, float, const AssemblyBurgersData<float>&, const AssemblyMaterialData<float>&, MaterialType);
309 const std::vector<int*>&, const std::vector<Index>&, double, const AssemblyBurgersData<double>&, const AssemblyMaterialData<double>&, MaterialType);
311 const std::vector<int*>&, const std::vector<Index>&, float, const AssemblyBurgersData<float>&, const AssemblyMaterialData<float>&, MaterialType);
312#ifdef FEAT_HAVE_HALFMATH
314 const std::vector<int*>&, const std::vector<Index>&, Half, const AssemblyBurgersData<Half>&, const AssemblyMaterialData<Half>&, MaterialType);
316 const std::vector<int*>&, const std::vector<Index>&, Half, const AssemblyBurgersData<Half>&, const AssemblyMaterialData<Half>&, MaterialType);
317#endif
318
320 const std::vector<int*>&, const std::vector<Index>&, double, const AssemblyBurgersData<double>&, const AssemblyMaterialData<double>&, MaterialType);
322 const std::vector<int*>&, const std::vector<Index>&, float, const AssemblyBurgersData<float>&, const AssemblyMaterialData<float>&, MaterialType);
324 const std::vector<int*>&, const std::vector<Index>&, double, const AssemblyBurgersData<double>&, const AssemblyMaterialData<double>&, MaterialType);
326 const std::vector<int*>&, const std::vector<Index>&, float, const AssemblyBurgersData<float>&, const AssemblyMaterialData<float>&, MaterialType);
327#ifdef FEAT_HAVE_HALFMATH
329 const std::vector<int*>&, const std::vector<Index>&, Half, const AssemblyBurgersData<Half>&, const AssemblyMaterialData<Half>&, MaterialType);
331 const std::vector<int*>&, const std::vector<Index>&, Half, const AssemblyBurgersData<Half>&, const AssemblyMaterialData<Half>&, MaterialType);
332#endif
Standard Lagrange-2 Finite-Element space class template.
Definition: element.hpp:39
Tiny Matrix class template.
Tiny Vector class template.
T_ sqrt(T_ x)
Returns the square-root of a value.
Definition: math.hpp:300
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
void assemble_burgers_velo_material_defect_host(const Space_ &space, DT_ *vector_data, const DT_ *conv_data, const DT_ *primal_data, const AssemblyCubatureData< DT_ > &cubature, const AssemblyMappingData< DT_, IT_ > &dof_mapping, const std::vector< int * > &coloring_maps, const std::vector< Index > &coloring_map_sizes, DT_ alpha, const AssemblyBurgersData< DT_ > &burgers_params, const AssemblyMaterialData< DT_ > &material_params, MaterialType material_type)
Host kernel wrapper for the defect burgers assembler.
void assemble_burgers_velo_material_csr_host(const Space_ &space, const CSRMatrixData< DT_, IT_ > &matrix_data, const DT_ *conv_data, const AssemblyCubatureData< DT_ > &cubature, const AssemblyMappingData< DT_, IT_ > &dof_mapping, const std::vector< int * > &coloring_maps, const std::vector< Index > &coloring_map_sizes, DT_ alpha, const AssemblyBurgersData< DT_ > &burgers_params, const AssemblyMaterialData< DT_ > &material_params, MaterialType material_type)
Host kernel wrapper for the full matrix burgers assembler.
Namespace for different voxel based assembly methods.
MaterialType
Enum for different material types.
FEAT namespace.
Definition: adjactor.hpp:12
__half Half
Half data type.
Definition: half.hpp:25
std::uint64_t Index
Index data type.
const void * cub_pt
The cubature point data array.
A data field for all necessary values that define the dof mapping for assembly.
const IT_ * cell_to_dof
The cell to dof, where cell_to_dof[i],..., cell_to_dof[i+cell_dofs-1] are the dofs of one cell.
const IT_ * cell_to_dof_sorter
Array of sortingindices of cell_to_dof.
const void * nodes
An array of the nodes fitting to the cell_to_dof mapping.
Data for material burgers assembler.