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 Adjacency::ColoringDataHandler& coloring_data,
169 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params,
170 const AssemblyMaterialData<DT_>& material_params, MaterialType material_type)
171 {
172 const Memory::TypedView<int> coloring_view = coloring_data.color_map_view(Memory::Location::main, Memory::Access::read);
176 switch(material_type)
177 {
178 case MaterialType::carreau:
179 {
180 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
181 {
182 VoxelAssembly::Kernel::template full_burgers_vm_assembler_matrix1_bcsr_host<Space_, DT_, IT_, Intern::ViscoFunctor<DT_, MaterialType::carreau>, Intern::ViscoDFunctor<DT_, MaterialType::carreau>,
183 FEAT::Intern::MatrixGatherScatterPolicy::useLocalSortHelper>(
184 matrix_data.data, conv_data, matrix_data.row_ptr, matrix_data.col_idx, matrix_data.num_rows, matrix_data.num_cols,
185 (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
186 cubature.cub_wg, cubature.num_cubs, alpha,
187 cell_to_dof_view.get_r(), dof_mapping.cell_num,
188 nodes_view.get_r(), dof_mapping.node_size,
189 &coloring_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col), cell_to_dof_sorter_view.get_r(),
190 burgers_params, material_params, Intern::ViscoFunctor<DT_, MaterialType::carreau>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T},
191 Intern::ViscoDFunctor<DT_, MaterialType::carreau>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T}
192 );
193 }
194 break;
195 }
196 case MaterialType::carreauYasuda:
197 {
198 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
199 {
200 VoxelAssembly::Kernel::template full_burgers_vm_assembler_matrix1_bcsr_host<Space_, DT_, IT_, Intern::ViscoFunctor<DT_, MaterialType::carreauYasuda>, Intern::ViscoDFunctor<DT_, MaterialType::carreauYasuda>,
201 FEAT::Intern::MatrixGatherScatterPolicy::useLocalSortHelper>(
202 matrix_data.data, conv_data, matrix_data.row_ptr, matrix_data.col_idx, matrix_data.num_rows, matrix_data.num_cols,
203 (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
204 cubature.cub_wg, cubature.num_cubs, alpha,
205 cell_to_dof_view.get_r(), dof_mapping.cell_num,
206 nodes_view.get_r(), dof_mapping.node_size,
207 &coloring_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col), cell_to_dof_sorter_view.get_r(),
208 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},
209 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}
210 );
211 }
212 break;
213 }
214 }
215
216 }
217
218 template<typename Space_, typename DT_, typename IT_>
219 void assemble_burgers_velo_material_defect_host([[maybe_unused]] const Space_& space,
220 DT_* vector_data,
221 const DT_* conv_data,
222 const DT_* primal_data,
223 const AssemblyCubatureData<DT_>& cubature,
224 const AssemblyMappingData<DT_, IT_>& dof_mapping,
225 const Adjacency::ColoringDataHandler& coloring_data,
226 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params,
227 const AssemblyMaterialData<DT_>& material_params, MaterialType material_type)
228 {
229 const Memory::TypedView<int> coloring_view = coloring_data.color_map_view(Memory::Location::main, Memory::Access::read);
233 switch(material_type)
234 {
235 case MaterialType::carreau:
236 {
237 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
238 {
239 VoxelAssembly::Kernel::template full_burgers_vm_assembler_vector_bd_host<Space_, DT_, IT_, Intern::ViscoFunctor<DT_, MaterialType::carreau>>(vector_data, conv_data, primal_data,
240 space.get_num_dofs(), (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
241 cubature.cub_wg, cubature.num_cubs, alpha,
242 cell_to_dof_view.get_r(), dof_mapping.cell_num,
243 nodes_view.get_r(), dof_mapping.node_size,
244 &coloring_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col), burgers_params,
245 Intern::ViscoFunctor<DT_, MaterialType::carreau>{material_params.mu_0, material_params.exp, material_params.lambda, material_params.a_T}
246 );
247 }
248 break;
249 }
250 case MaterialType::carreauYasuda:
251 {
252 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
253 {
254 VoxelAssembly::Kernel::template full_burgers_vm_assembler_vector_bd_host<Space_, DT_, IT_, Intern::ViscoFunctor<DT_, MaterialType::carreauYasuda>>(vector_data, conv_data, primal_data,
255 space.get_num_dofs(), (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
256 cubature.cub_wg, cubature.num_cubs, alpha,
257 cell_to_dof_view.get_r(), dof_mapping.cell_num,
258 nodes_view.get_r(), dof_mapping.node_size,
259 &coloring_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col), burgers_params,
260 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}
261 );
262 }
263 break;
264 }
265 }
266 }
267
268 }
269 }
270}
271
272//instantiate the templates
273using namespace FEAT;
274using namespace FEAT::VoxelAssembly;
275
276
277/*******************************************************2D implementations***************************************************/
286#ifdef FEAT_HAVE_HALFMATH
291#endif
292
301#ifdef FEAT_HAVE_HALFMATH
306#endif
307
308
309/*********************************************************3D implementations**************************************************************************************/
318#ifdef FEAT_HAVE_HALFMATH
323#endif
324
333#ifdef FEAT_HAVE_HALFMATH
338#endif
Datahandler for inverse coloring data.
Index get_num_colors() const
Returns the number of colors.
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
Typed memory view class.
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
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
@ read
read-only access
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 Adjacency::ColoringDataHandler &coloring_data, 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 Adjacency::ColoringDataHandler &coloring_data, 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 Memory::Arbiter & 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 Memory::Arbiter & nodes
An array of the nodes fitting to the cell_to_dof mapping.
const Memory::Arbiter & cell_to_dof_sorter
Array of sortingindices of cell_to_dof.
Data for material burgers assembler.