2#ifndef FEAT_KERNEL_VOXEL_ASSEMBLY_BURGERS_VELO_MATERIAL_HPP
3#define FEAT_KERNEL_VOXEL_ASSEMBLY_BURGERS_VELO_MATERIAL_HPP 1
6#include <kernel/backend.hpp>
8#include <kernel/voxel_assembly/voxel_assembly_common.hpp>
9#include <kernel/voxel_assembly/helper/data_handler.hpp>
10#include <kernel/voxel_assembly/helper/space_helper.hpp>
11#include <kernel/cubature/rule.hpp>
12#include <kernel/lafem/sparse_matrix_bcsr.hpp>
13#include <kernel/lafem/dense_vector_blocked.hpp>
14#include <kernel/trafo/standard/mapping.hpp>
15#include <kernel/geometry/conformal_mesh.hpp>
16#include <kernel/util/tiny_algebra.hpp>
17#include <kernel/global/vector.hpp>
18#include <kernel/lafem/vector_mirror.hpp>
19#include <kernel/voxel_assembly/burgers_assembler.hpp>
21#include <kernel/util/cuda_util.hpp>
26 namespace VoxelAssembly
29 #if defined(FEAT_HAVE_CUDA) || defined(DOXYGEN)
31 template<
typename SpaceHelp_,
bool need_streamdiff_ = true>
34 typedef SpaceHelp_ SpaceHelp;
35 static constexpr int dim = SpaceHelp::dim;
36 typedef typename SpaceHelp::SpaceType SpaceType;
37 typedef typename SpaceHelp::DataType DataType;
39 static constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
44 typename SpaceHelp::EvalData basis_data;
45 typename SpaceHelp::JacobianMatrixType loc_jac;
46 typename SpaceHelp::JacobianMatrixType loc_jac_inv;
50 typename SpaceHelp::DomainPointType dom_point;
60 template<
typename SpaceHelp_>
63 typedef SpaceHelp_ SpaceHelp;
64 static constexpr int dim = SpaceHelp::dim;
65 typedef typename SpaceHelp::SpaceType SpaceType;
66 typedef typename SpaceHelp::DataType DataType;
68 static constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
73 typename SpaceHelp::EvalData basis_data;
74 typename SpaceHelp::JacobianMatrixType loc_jac;
75 typename SpaceHelp::JacobianMatrixType loc_jac_inv;
78 typename SpaceHelp::DomainPointType dom_point;
97 template<
typename Space_,
typename DT_,
typename IT_>
130 template<
typename SpaceHelp_,
typename LocMatType_,
typename LocVecType_,
int dim_,
int num_verts_,
typename ViscFunc_,
typename ViscDerFunc_,
bool need_stream_diff_>
132 const typename SpaceHelp_::DomainPointType* cub_pt,
const typename SpaceHelp_::DataType* cub_wg,
const int num_cubs,
135 const bool need_convection,
const typename SpaceHelp_::DataType tol_eps,
136 ViscFunc_ visco_func, ViscDerFunc_ visco_d_func)
140#pragma nv_diag_suppress = 177
141#pragma nv_diag_suppress = 550
144 typedef SpaceHelp_ SpaceHelp;
145 constexpr int dim = SpaceHelp::dim;
146 typedef typename SpaceHelp::SpaceType SpaceType;
147 typedef typename SpaceHelp::DataType DataType;
149 constexpr bool need_streamline = need_stream_diff_;
153 const DataType& theta{burgers_params.theta};
154 const DataType& beta{burgers_params.beta};
155 const DataType& frechet_beta{burgers_params.frechet_beta};
156 const DataType& sd_delta{burgers_params.sd_delta};
157 const DataType& sd_nu{burgers_params.sd_nu};
158 const DataType& sd_v_norm{burgers_params.sd_v_norm};
163 const DataType& frechet_material{material_params.frechet_material};
164 const DataType& reg_eps{material_params.reg_eps};
165 const bool& need_frechet_material{material_params.need_frechet_material};
183 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
187 typename SpaceHelp::JacobianMatrixType loc_jac, loc_jac_inv;
188 typename SpaceHelp::EvalData basis_data;
193 VecValueType loc_v(DataType(0));
194 MatValueType loc_grad_v(DataType(0)), strain_rate_tensor_2(DataType(0));
195 DataType local_delta(DataType(0));
196 DataType nu_loc(DataType(0));
197 DataType gamma_dot(DataType(0));
201#pragma nv_diag_default = 550
202#pragma nv_diag_default = 177
207 if constexpr(need_streamline)
209 VecValueType mean_v(DataType(0));
211 const VecValueType barycenter(DataType(0));
214 SpaceHelp::eval_ref_values(basis_data, barycenter);
215 SpaceHelp::trans_values(basis_data);
216 for(
int i(0); i < num_loc_dofs; ++i)
218 mean_v.axpy(basis_data.phi[i].value, local_conv_dofs[i]);
220 const DataType local_norm_v = mean_v.norm_euclid();
222 if(local_norm_v > tol_eps)
228 const DataType local_h = SpaceHelp::width_directed(mean_v, local_coeffs) * local_norm_v;
229 const DataType local_re = (local_norm_v * local_h) / sd_nu;
230 local_delta = sd_delta * (local_h / sd_v_norm) * (DataType(2) * local_re) / (DataType(1) + local_re);
234 for(
int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
236 const typename SpaceHelp::DomainPointType&
dom_point = cub_pt[cub_ind];
237 SpaceHelp::eval_ref_values(basis_data,
dom_point);
238 SpaceHelp::trans_values(basis_data);
240 SpaceHelp::calc_jac_mat(loc_jac,
dom_point, local_coeffs);
241 loc_jac_inv.set_inverse(loc_jac);
243 SpaceHelp::eval_ref_gradients(basis_data,
dom_point);
244 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);
246 const DataType weight = loc_jac.vol() * cub_wg[cub_ind];
247 if(need_convection || need_streamline)
250 for(
int i = 0; i < num_loc_dofs; ++i)
252 loc_v.axpy(basis_data.phi[i].value, local_conv_dofs[i]);
258 for(
int i = 0; i < num_loc_dofs; ++i)
260 loc_grad_v.add_outer_product(local_conv_dofs[i], basis_data.phi[i].grad);
264 strain_rate_tensor_2.set_transpose(loc_grad_v);
265 strain_rate_tensor_2.axpy(DataType(1.0), loc_grad_v);
267 gamma_dot = CudaMath::cuda_sqrt(DataType(0.5))*strain_rate_tensor_2.norm_frobenius();
269 gamma_dot =
Math::sqrt(DataType(0.5))*strain_rate_tensor_2.norm_frobenius();
273 nu_loc = visco_func(gamma_dot);
277 for(
int i(0); i < num_loc_dofs; ++i)
280 for(
int j(0); j < num_loc_dofs; ++j)
283 const DataType
value = nu_loc * weight *
Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
286 loc_mat[i][j].add_scalar_main_diag(
value);
287 loc_mat[i][j].add_outer_product(basis_data.phi[j].grad, basis_data.phi[i].grad, nu_loc * weight);
291 if(need_frechet_material)
293 const DataType fac = frechet_material * visco_d_func(gamma_dot)/(gamma_dot + reg_eps);
296 for(
int i(0); i < num_loc_dofs; ++i)
302 for(
int j(0); j < num_loc_dofs; ++j)
307 loc_mat[i][j].add_outer_product(du_grad_phi, du_grad_psi, fac * weight);
315 for(
int i(0); i < num_loc_dofs; ++i)
318 for(
int j(0); j < num_loc_dofs; ++j)
321 const DataType
value = beta * weight * basis_data.phi[i].value *
Tiny::dot(loc_v, basis_data.phi[j].grad);
324 loc_mat[i][j].add_scalar_main_diag(
value);
331 if(CudaMath::cuda_abs(frechet_beta) > DataType(0))
333 if(
Math::abs(frechet_beta) > DataType(0))
337 for(
int i(0); i < num_loc_dofs; ++i)
340 for(
int j(0); j < num_loc_dofs; ++j)
343 const DataType
value = frechet_beta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
346 loc_mat[i][j].axpy(
value, loc_grad_v);
353 if(CudaMath::cuda_abs(theta) > DataType(0))
359 for(
int i(0); i < num_loc_dofs; ++i)
362 for(
int j(0); j < num_loc_dofs; ++j)
365 const DataType
value = theta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
368 loc_mat[i][j].add_scalar_main_diag(
value);
373 if constexpr(need_streamline)
376 for(
int i = 0; i < num_loc_dofs; ++i)
378 streamdiff_coeffs[i] =
Tiny::dot(loc_v, basis_data.phi[i].grad);
383 if((local_delta > tol_eps))
386 for(
int i(0); i < num_loc_dofs; ++i)
389 for(
int j(0); j < num_loc_dofs; ++j)
392 const DataType
value = local_delta * weight * streamdiff_coeffs[i] * streamdiff_coeffs[j];
395 loc_mat[i][j].add_scalar_main_diag(
value);
404 #if defined(__CUDACC__)
429 template<
typename ThreadGroup_,
typename SpaceHelp_,
typename ViscFunc_,
typename ViscDerFunc_,
bool need_stream_diff_>
431 int loc_assemble_size,
int assemble_offset,
typename SpaceHelp_::DataType* loc_mat,
const typename SpaceHelp_::DataType* local_conv_dofs,
433 const typename SpaceHelp_::DomainPointType* cub_pt,
const typename SpaceHelp_::DataType* cub_wg,
const int num_cubs,
436 const bool need_convection,
const typename SpaceHelp_::DataType tol_eps,
437 ViscFunc_ visco_func, ViscDerFunc_ visco_d_func)
440#pragma nv_diag_suppress = 177
441#pragma nv_diag_suppress = 550
443 typedef SpaceHelp_ SpaceHelp;
444 constexpr int dim = SpaceHelp::dim;
445 typedef typename SpaceHelp::SpaceType SpaceType;
446 typedef typename SpaceHelp::DataType DataType;
447 constexpr bool need_streamline = need_stream_diff_;
449 const int t_idx = tg.thread_rank();
450 const int g_size = tg.num_threads();
453 const DataType& theta{burgers_params.theta};
454 const DataType& beta{burgers_params.beta};
455 const DataType& frechet_beta{burgers_params.frechet_beta};
456 const DataType& sd_delta{burgers_params.sd_delta};
457 const DataType& sd_nu{burgers_params.sd_nu};
458 const DataType& sd_v_norm{burgers_params.sd_v_norm};
460 const DataType& frechet_material{material_params.frechet_material};
461 const DataType& reg_eps{material_params.reg_eps};
462 const bool& need_frechet_material{material_params.need_frechet_material};
480 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
482 typedef Tiny::Vector<DataType, dim> VecValueType;
483 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
488 typedef BurgersMatSharedDataKernelWrapper<SpaceHelp, need_stream_diff_> BSDKWrapper;
489 typename SpaceHelp::JacobianMatrixType& loc_jac = shared_wrapper->loc_jac;
490 typename SpaceHelp::JacobianMatrixType& loc_jac_inv = shared_wrapper->loc_jac_inv;
491 MatValueType& loc_grad_v = shared_wrapper->loc_grad_v;
492 VecValueType& loc_v = shared_wrapper->loc_v;
493 VecValueType* mean_v_p =
nullptr;
494 if constexpr(need_streamline) mean_v_p = &(shared_wrapper->mean_v);
495 typename SpaceHelp::DomainPointType&
dom_point = shared_wrapper->dom_point;
496 Tiny::Vector<DataType, num_loc_dofs>* streamdiff_coeffs_p =
nullptr;
497 if constexpr(need_streamline) streamdiff_coeffs_p = &(shared_wrapper->streamdiff_coeffs);
498 DataType& local_delta = shared_wrapper->local_delta;
499 DataType& nu_loc = shared_wrapper->nu_loc;
500 DataType& gamma_dot = shared_wrapper->gamma_dot;
501 DataType& det = shared_wrapper->det;
502 DataType& weight = shared_wrapper->weight;
503 typename SpaceHelp::EvalData& basis_data = shared_wrapper->basis_data;
504 bool& need_frechet = shared_wrapper->need_frechet;
507 MatValueType strain_rate_tensor_2(DataType(0));
509 VoxelAssembly::coalesced_format(tg, (
unsigned int*) shared_wrapper,
sizeof(BSDKWrapper)/(
sizeof(
unsigned int)));
512 cg::invoke_one(tg, [&](){need_frechet = CudaMath::cuda_abs(frechet_beta) > DataType(0);});
516#pragma nv_diag_default = 550
517#pragma nv_diag_default = 177
519 if constexpr(need_streamline)
521 cg::invoke_one(tg, [&]() {*mean_v_p = DataType(0);});
525 cg::invoke_one(tg, [&](){
const VecValueType bc(0);
526 SpaceHelp::eval_ref_values(basis_data, bc);
527 SpaceHelp::trans_values(basis_data);});
531 for(
int idx = t_idx; idx < num_loc_dofs; idx += g_size)
533 VoxelAssembly::template grouped_axpy<DataType, cg::thread_group, dim>(tg, &(*mean_v_p)[0], basis_data.phi[idx].value, &local_conv_dofs[idx*dim]);
538 DataType local_norm_v = mean_v_p->norm_euclid();
540 if(local_norm_v > tol_eps)
542 cg::invoke_one(tg, [&](){
543 const DataType local_h = SpaceHelp::width_directed(*mean_v_p, local_coeffs) * local_norm_v;
544 const DataType local_re = (local_norm_v * local_h) / sd_nu;
545 local_delta = sd_delta * (local_h / sd_v_norm) * (DataType(2) * local_re) / (DataType(1) + local_re);
550 for(
int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
553 cg::invoke_one(tg, [&](){
dom_point = cub_pt[cub_ind];
554 SpaceHelp::eval_ref_values(basis_data,
dom_point);
555 SpaceHelp::trans_values(basis_data);});
558 SpaceHelp::grouped_calc_jac_mat(tg, loc_jac,
dom_point, &local_coeffs[0][0]);
560 cg::invoke_one(tg, [&](){det = loc_jac.det();
561 weight = CudaMath::cuda_abs(det) * cub_wg[cub_ind];});
563 loc_jac_inv.grouped_set_inverse(tg, loc_jac, det);
565 cg::invoke_one(tg, [&](){
566 SpaceHelp::eval_ref_gradients(basis_data,
dom_point);
567 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);});
570 if(need_convection || need_streamline)
572 VoxelAssembly::coalesced_format(tg, &loc_v[0], dim);
575 for(
int idx = t_idx; idx < num_loc_dofs; idx += g_size)
577 VoxelAssembly::template grouped_axpy<DataType, cg::thread_group, dim>(tg, &loc_v[0], basis_data.phi[idx].value, &local_conv_dofs[idx*dim]);
583 VoxelAssembly::coalesced_format(tg, &loc_grad_v[0][0], dim*dim);
585 for(
int i = t_idx; i < num_loc_dofs; i += g_size)
587 VoxelAssembly::grouped_add_outer_product(tg, &loc_grad_v[0][0], &local_conv_dofs[i*dim], basis_data.phi[i].grad);
594 strain_rate_tensor_2.set_transpose(loc_grad_v);
595 strain_rate_tensor_2.axpy(DataType(1.0), loc_grad_v);
596 cg::invoke_one(tg, [&](){
599 gamma_dot = CudaMath::cuda_sqrt(DataType(0.5))*strain_rate_tensor_2.norm_frobenius();
600 nu_loc = visco_func(gamma_dot);
605 if constexpr(need_streamline)
608 for(
int i = t_idx; i < num_loc_dofs; i += g_size)
610 (*streamdiff_coeffs_p)[i] =
Tiny::dot(loc_v, basis_data.phi[i].grad);
617 const DataType fac = frechet_material * visco_d_func(gamma_dot)/(gamma_dot + reg_eps);
619 for(
int idx = t_idx; idx < loc_assemble_size; idx += g_size)
622 const int i = (idx+assemble_offset) / num_loc_dofs;
623 const int j = (idx+assemble_offset) % num_loc_dofs;
627 const DataType
value = nu_loc * weight *
Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
629 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(
value);
630 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_outer_product(basis_data.phi[j].grad, basis_data.phi[i].grad, nu_loc * weight);
633 if(need_frechet_material)
635 Tiny::Vector<DataType, dim> du_grad_phi;
636 du_grad_phi.set_mat_vec_mult(strain_rate_tensor_2, basis_data.phi[i].grad);
637 Tiny::Vector<DataType, dim> du_grad_psi;
638 du_grad_psi.set_mat_vec_mult(strain_rate_tensor_2, basis_data.phi[j].grad);
640 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_outer_product(du_grad_phi, du_grad_psi, fac*weight);
647 const DataType
value = beta * weight * basis_data.phi[i].value * VoxelAssembly::dot(basis_data.phi[j].grad, &loc_v[0]);
650 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(
value);
657 const DataType
value = frechet_beta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
660 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->
axpy(
value, loc_grad_v);
665 if(CudaMath::cuda_abs(theta) > DataType(0))
671 const DataType
value = theta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
674 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(
value);
678 if constexpr(need_streamline)
680 if(local_delta > tol_eps)
683 const DataType
value = local_delta * weight * (*streamdiff_coeffs_p)[i] * (*streamdiff_coeffs_p)[j];
686 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(
value);
718 template<
typename SpaceHelp_,
typename LocVecType_,
int dim_,
int num_verts_,
typename ViscFunc_>
720 const typename SpaceHelp_::DomainPointType* cub_pt,
const typename SpaceHelp_::DataType* cub_wg,
const int num_cubs,
722 const bool need_convection, ViscFunc_ visco_func)
724 typedef SpaceHelp_ SpaceHelp;
725 constexpr int dim = SpaceHelp::dim;
726 typedef typename SpaceHelp::SpaceType SpaceType;
727 typedef typename SpaceHelp::DataType DataType;
730 const DataType& theta{burgers_params.theta};
731 const DataType& beta{burgers_params.beta};
754 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
758 typename SpaceHelp::JacobianMatrixType loc_jac, loc_jac_inv;
759 typename SpaceHelp::EvalData basis_data;
765 VecValueType loc_v(DataType(0));
766 DataType nu_loc(DataType(0));
772 for(
int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
774 const typename SpaceHelp::DomainPointType&
dom_point = cub_pt[cub_ind];
775 SpaceHelp::eval_ref_values(basis_data,
dom_point);
776 SpaceHelp::trans_values(basis_data);
778 SpaceHelp::calc_jac_mat(loc_jac,
dom_point, local_coeffs);
779 loc_jac_inv.set_inverse(loc_jac);
781 SpaceHelp::eval_ref_gradients(basis_data,
dom_point);
782 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);
784 const DataType weight = loc_jac.vol() * cub_wg[cub_ind];
788 for(
int i = 0; i < num_loc_dofs; ++i)
790 loc_v.axpy(basis_data.phi[i].value, local_conv_dofs[i]);
796 MatValueType loc_grad_v(DataType(0)), strain_rate_tensor_2(DataType(0));
798 for(
int i = 0; i < num_loc_dofs; ++i)
800 loc_grad_v.add_outer_product(local_conv_dofs[i], basis_data.phi[i].grad);
803 strain_rate_tensor_2.set_transpose(loc_grad_v);
804 strain_rate_tensor_2.axpy(DataType(1.0), loc_grad_v);
806 nu_loc = visco_func(CudaMath::cuda_sqrt(DataType(0.5))*strain_rate_tensor_2.norm_frobenius());
808 nu_loc = visco_func(
Math::sqrt(DataType(0.5))*strain_rate_tensor_2.norm_frobenius());
814 for(
int i(0); i < num_loc_dofs; ++i)
817 for(
int j(0); j < num_loc_dofs; ++j)
820 const DataType value1 = nu_loc * weight *
Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
821 const DataType value2 = nu_loc * weight *
Tiny::dot(local_prim_dofs[j], basis_data.phi[i].grad);
823 loc_vec[i].axpy(value1, local_prim_dofs[j]);
824 loc_vec[i].axpy(value2, basis_data.phi[j].grad);
831 for(
int i(0); i < num_loc_dofs; ++i)
834 for(
int j(0); j < num_loc_dofs; ++j)
837 const DataType
value = beta * weight * basis_data.phi[i].value *
Tiny::dot(loc_v, basis_data.phi[j].grad);
840 loc_vec[i].axpy(
value, local_prim_dofs[j]);
847 if(CudaMath::cuda_abs(theta) > DataType(0))
853 for(
int i(0); i < num_loc_dofs; ++i)
856 for(
int j(0); j < num_loc_dofs; ++j)
859 const DataType
value = theta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
862 loc_vec[i].axpy(
value, local_prim_dofs[j]);
881 template<
typename ThreadGroup_,
typename SpaceHelp_,
typename ViscFunc_>
883 typename SpaceHelp_::DataType* loc_vec,
const typename SpaceHelp_::DataType* local_prim_dofs,
const typename SpaceHelp_::DataType* local_conv_dofs,
885 const typename SpaceHelp_::DomainPointType* cub_pt,
const typename SpaceHelp_::DataType* cub_wg,
const int num_cubs,
887 const bool need_convection, ViscFunc_ visco_func)
889 typedef SpaceHelp_ SpaceHelp;
890 constexpr int dim = SpaceHelp::dim;
891 typedef typename SpaceHelp::SpaceType SpaceType;
892 typedef typename SpaceHelp::DataType DataType;
893 const int t_idx = tg.thread_rank();
894 const int g_size = tg.num_threads();
897 const DataType& theta{burgers_params.theta};
898 const DataType& beta{burgers_params.beta};
921 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
925 typedef BurgersMatSharedDataKernelWrapper<SpaceHelp, false> BSDKWrapper;
926 typename SpaceHelp::JacobianMatrixType& loc_jac = shared_wrapper->loc_jac;
927 typename SpaceHelp::JacobianMatrixType& loc_jac_inv = shared_wrapper->loc_jac_inv;
929 DataType& det = shared_wrapper->det;
930 DataType& weight = shared_wrapper->weight;
931 DataType& nu_loc = shared_wrapper->nu_loc;
932 DataType& gamma_dot = shared_wrapper->gamma_dot;
933 typename SpaceHelp::EvalData& basis_data = shared_wrapper->basis_data;
935 typedef Tiny::Vector<DataType, dim> VecValueType;
936 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
938 MatValueType& loc_grad_v = shared_wrapper->loc_grad_v;
939 VecValueType& loc_v = shared_wrapper->loc_v;
941 typename SpaceHelp::DomainPointType&
dom_point = shared_wrapper->dom_point;
943 VoxelAssembly::coalesced_format(tg, (
unsigned int*) shared_wrapper,
sizeof(BSDKWrapper)/(
sizeof(
unsigned int)));
946 cg::thread_block_tile<4> tile4 = cg::tiled_partition<4>(tg);
948 for(
int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
951 cg::invoke_one(tg, [&](){
dom_point = cub_pt[cub_ind];
952 SpaceHelp::eval_ref_values(basis_data,
dom_point);
953 SpaceHelp::trans_values(basis_data);});
956 SpaceHelp::grouped_calc_jac_mat(tg, loc_jac,
dom_point, &local_coeffs[0][0]);
958 cg::invoke_one(tg, [&](){det = loc_jac.det();
959 weight = CudaMath::cuda_abs(det) * cub_wg[cub_ind];});
961 loc_jac_inv.grouped_set_inverse(tg, loc_jac, det);
963 cg::invoke_one(tg, [&](){
964 SpaceHelp::eval_ref_gradients(basis_data,
dom_point);
965 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);});
970 VoxelAssembly::coalesced_format(tg, &loc_v[0], dim);
973 for(
int idx = t_idx; idx < num_loc_dofs; idx += g_size)
975 VoxelAssembly::template grouped_axpy<DataType, cg::thread_group, dim>(tg, &loc_v[0], basis_data.phi[idx].value, &local_conv_dofs[idx*dim]);
981 VoxelAssembly::coalesced_format(tg, &loc_grad_v[0][0], dim*dim);
983 for(
int i = t_idx; i < num_loc_dofs; i += g_size)
985 VoxelAssembly::grouped_add_outer_product(tg, &loc_grad_v[0][0], &local_conv_dofs[i*dim], basis_data.phi[i].grad);
988 cg::invoke_one(tg, [&](){
989 MatValueType strain_rate_tensor_2(DataType(0));
990 strain_rate_tensor_2.set_transpose(loc_grad_v);
991 strain_rate_tensor_2.axpy(DataType(1.0), loc_grad_v);
992 gamma_dot = CudaMath::cuda_sqrt(DataType(0.5))*strain_rate_tensor_2.norm_frobenius();
993 nu_loc = visco_func(gamma_dot);
999 for(
int idx = tile4.meta_group_rank(); idx < loc_assemble_size*dim; idx += tile4.meta_group_size())
1002 DataType val = DataType(0);
1004 const int i = (idx/dim+assemble_offset);
1005 const int ii = idx%dim;
1007 for(
int j = tile4.thread_rank(); j < num_loc_dofs; j += tile4.size())
1010 val += nu_loc * weight * (
Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad) * local_prim_dofs[j*dim + ii]
1011 +
Tiny::dot(((Tiny::Vector<DataType, dim>*)local_prim_dofs)[j], basis_data.phi[i].grad) * basis_data.phi[j].grad[ii]);
1017 for(
int j = tile4.thread_rank(); j < num_loc_dofs; j += tile4.size())
1020 val += beta * weight * basis_data.phi[i].value *
Tiny::dot(loc_v, basis_data.phi[j].grad) * local_prim_dofs[j*dim + ii];
1026 if(CudaMath::cuda_abs(theta) > DataType(0))
1031 for(
int j = tile4.thread_rank(); j < num_loc_dofs; j += tile4.size())
1034 val += theta * weight * basis_data.phi[i].value * basis_data.phi[j].value * local_prim_dofs[j*dim + ii];
1039 cuda::atomic_ref<DataType, cuda::thread_scope_block> a_ref(*(loc_vec+idx));
1040 cg::reduce_update_async(tile4, a_ref, val, cg::plus<DataType>());
1050 #if defined(FEAT_HAVE_CUDA) || defined(DOXYGEN)
1072 template<
typename Space_,
typename DT_,
typename IT_>
1075 const DT_* conv_data,
1081 MaterialType mat_type,
const Util::RuntimeParameter& runtime_params);
1105 template<
typename Space_,
typename DT_,
typename IT_>
1108 const DT_* conv_data,
1109 const DT_* primal_data,
1116 const Util::RuntimeParameter& runtime_params);
1141 template<
typename Space_,
typename DT_,
typename IT_>
1144 const DT_* conv_data,
1174 template<
typename Space_,
typename DT_,
typename IT_>
1177 const DT_* conv_data,
1178 const DT_* primal_data,
1203 template<
int dim_,
typename DT_,
typename IT_>
1213 typedef typename SpaceHelp::ShapeType ShapeType;
1214 typedef typename SpaceHelp::DataType DataType;
1215 typedef typename SpaceHelp::IndexType IndexType;
1218 static constexpr int dim = SpaceHelp::dim;
1220 typedef typename SpaceHelp::DomainPointType DomainPointType;
1221 typedef typename SpaceHelp::ImagePointType ImagePointType;
1222 typedef typename SpaceHelp::ValueType ValueType;
1223 typedef typename SpaceHelp::JacobianMatrixType JacobianMatrixType;
1258 template<
typename ColoringType_>
1261 frechet_material(DataType(0)), reg_eps(DataType(1E-100)), material_type(
MaterialType::carreau)
1297 template<
typename CubatureFactory_>
1299 const SpaceType& space,
const CubatureFactory_& cubature_factory, DataType alpha = DataType(1))
const
1307 CubatureRuleType cubature(Cubature::ctor_factory, cubature_factory);
1310 int num_cubs = cubature.get_num_points();
1311 typename CubatureRuleType::PointType* cub_pt = cubature.get_points();
1312 DataType* cub_wg = cubature.get_weights();
1315 assemble_matrix1_cuda(matrix, convect, space, cub_pt, cub_wg, num_cubs, alpha);
1317 assemble_matrix1_generic(matrix, convect, space, cub_pt, cub_wg, num_cubs, alpha);
1332 template<
typename CubatureFactory_>
1341 CubatureRuleType cubature(Cubature::ctor_factory, cubature_factory);
1344 int num_cubs = cubature.get_num_points();
1345 typename CubatureRuleType::PointType* cub_pt = cubature.get_points();
1346 DataType* cub_wg = cubature.get_weights();
1349 assemble_vector_cuda(vector, convect, primal, space, cub_pt, cub_wg, num_cubs, alpha);
1351 assemble_vector_generic(vector, convect, primal, space, cub_pt, cub_wg, num_cubs, alpha);
1364 VoxelAssembly::AssemblyMappingData<DataType, IndexType> mapping_data = this->mesh_data.get_assembly_field();
1365 auto burgers_params = this->wrap_burgers_params();
1366 auto material_params = this->wrap_material_params();
1370 this->mesh_data.coloring_data, alpha, burgers_params, material_params, material_type);
1373 void assemble_vector_generic(LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& vector,
const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& convect,
const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& primal,
1374 const SpaceType& space,
typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt,
const DataType* cub_wg,
int num_cubs, DataType alpha)
const
1376 Memory::TypedView<DataType> vec_data = vector.elements_view_raw_rw();
1377 const Memory::TypedView<DataType> conv_data = convect.elements_view_raw_r();
1378 const Memory::TypedView<DataType> primal_data = primal.elements_view_raw_r();
1380 VoxelAssembly::AssemblyCubatureData<DataType> cub_data = {(
void*)cub_pt, cub_wg, num_cubs};
1381 VoxelAssembly::AssemblyMappingData<DataType, IndexType> mapping_data = this->mesh_data.get_assembly_field();
1382 auto burgers_params = this->wrap_burgers_params();
1383 auto material_params = wrap_material_params();
1387 this->mesh_data.coloring_data, alpha, burgers_params, material_params, material_type);
1391 #ifdef FEAT_HAVE_CUDA
1392 void assemble_matrix1_cuda(LAFEM::SparseMatrixBCSR<DataType, IndexType, dim, dim>& matrix,
const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& convect,
1393 const SpaceType& space,
typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt,
const DataType* cub_wg,
int num_cubs, DataType alpha)
const
1398 VoxelAssembly::CSRMatrixData<DataType, IndexType> mat_data = {val_view.get_w(), row_ptr_view.get_r(), col_idx_view.get_r(), matrix.num_rows(), matrix.num_cols()};
1404 this->_cub_cache.update(cub_pt, cub_wg, num_cubs);
1405 VoxelAssembly::AssemblyCubatureData<DataType> d_cub_data = this->_cub_cache.device_data();
1406 VoxelAssembly::AssemblyMappingData<DataType, IndexType> d_mapping_data = this->mesh_data.get_assembly_field();
1407 auto burgers_params = this->wrap_burgers_params();
1408 auto material_params = wrap_material_params();
1411 this->mesh_data.coloring_data, alpha, burgers_params, material_params, material_type,
1412 this->runtime_params);
1416 void assemble_vector_cuda(LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& vector,
const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& convect,
const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& primal,
1417 const SpaceType& space,
typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt,
const DataType* cub_wg,
int num_cubs, DataType alpha)
const
1426 this->_cub_cache.update(cub_pt, cub_wg, num_cubs);
1427 VoxelAssembly::AssemblyCubatureData<DataType> d_cub_data = this->_cub_cache.device_data();
1428 VoxelAssembly::AssemblyMappingData<DataType, IndexType> d_mapping_data = this->mesh_data.get_assembly_field();
1429 auto burgers_params = this->wrap_burgers_params();
1430 auto material_params = wrap_material_params();
1433 this->mesh_data.coloring_data, alpha, burgers_params, material_params, material_type,
1434 this->runtime_params);
1438 void assemble_matrix1_cuda(LAFEM::SparseMatrixBCSR<DataType, IndexType, dim, dim>& DOXY(matrix),
const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& DOXY(convect),
const SpaceType& DOXY(space),
typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* DOXY(cub_pt),
const DataType* DOXY(cub_wg),
int DOXY(num_cubs), DataType DOXY(alpha))
const
1440 XABORTM(
"What in the nine hells are you doing here?");
1443 void assemble_vector_cuda(LAFEM::DenseVectorBlocked<DataType, IndexType, dim>&,
const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>&,
const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>&,
1444 const SpaceType&,
typename Cubature::Rule<ShapeType, DataType, DataType>::PointType*,
const DataType*,
int, DataType)
const
1446 XABORTM(
"This call was logged and your local FBI agent was informed about your transgression");
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Datahandler for inverse coloring data.
static PreferredBackend get_preferred_backend()
get current preferred backend
Cubature Rule class template.
Blocked Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
CSR based blocked sparse matrix.
Index num_rows() const
Retrieve matrix row count.
Index num_cols() const
Retrieve matrix column count.
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.
Index get_num_dofs() const
Returns the number of dofs.
Tiny Matrix class template.
Tiny Vector class template.
CUDA_HOST_DEVICE Vector & set_mat_vec_mult(const Matrix< T_, n_, m_, sma_, sna_ > &a, const Vector< T_, m_, sx_ > &x)
Sets this vector to the result of a matrix-vector product.
Q2Lagrange thread parallel assembly class for the burgers operator.
Burgers Voxel Assembly template.
MaterialType material_type
material type
DataType frechet_material
Scaling factor full material jacobian.
VoxelBurgersVeloMaterialAssembler(const SpaceType &space, const ColoringType_ &coloring, int hint=-1)
Constructor for burgers velo material assembler.
void assemble_matrix1(LAFEM::SparseMatrixBCSR< DataType, IndexType, dim, dim > &matrix, const LAFEM::DenseVectorBlocked< DataType, IndexType, dim > &convect, const SpaceType &space, const CubatureFactory_ &cubature_factory, DataType alpha=DataType(1)) const
Assembles the burgers velo material operator for finitie element space with same test and trial space...
DataType mu_0
Material Parameter.
void assemble_vector(LAFEM::DenseVectorBlocked< DataType, IndexType, dim > &vector, const LAFEM::DenseVectorBlocked< DataType, IndexType, dim > &convect, const LAFEM::DenseVectorBlocked< DataType, IndexType, dim > &primal, const SpaceType &space, const CubatureFactory_ &cubature_factory, DataType alpha=DataType(1)) const
Assembles the application of the burgers operator to a given primal vector.
VoxelAssembly::AssemblyMaterialData< DataType > wrap_material_params() const
Wraps the set burgers parameter into convenient struct.
BaseClass::SpaceType SpaceType
typedefs
DataType reg_eps
regularity parameter
Burgers Velocity Material Voxel Assembly template.
T_ sqrt(T_ x)
Returns the square-root of a value.
T_ abs(T_ x)
Returns the absolute value.
T_ pow(T_ x, T_ y)
Returns x raised to the power of y.
CUDA_HOST_DEVICE T_ dot(const T_ &a, const T_ &b)
Computes the dot-product of two scalars.
CUDA_HOST_DEVICE void axpy(T_ &y, const T_ &x, const T_ &alpha)
Performs an AXPY of two scalars.
void assemble_burgers_velo_material_csr(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 mat_type, const Util::RuntimeParameter &runtime_params)
Device kernel wrapper for the full matrix burgers assembler.
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.
void assemble_burgers_velo_material_defect(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, const Util::RuntimeParameter &runtime_params)
Device kernel wrapper for the defect burgers assembler.
CUDA_HOST_DEVICE void burgers_velo_material_mat_assembly_kernel(LocMatType_ &loc_mat, const LocVecType_ &local_conv_dofs, const Tiny::Matrix< typename SpaceHelp_::DataType, dim_, num_verts_ > &local_coeffs, const typename SpaceHelp_::DomainPointType *cub_pt, const typename SpaceHelp_::DataType *cub_wg, const int num_cubs, const VoxelAssembly::AssemblyBurgersData< typename SpaceHelp_::DataType > &burgers_params, const VoxelAssembly::AssemblyMaterialData< typename SpaceHelp_::DataType > &material_params, const bool need_convection, const typename SpaceHelp_::DataType tol_eps, ViscFunc_ visco_func, ViscDerFunc_ visco_d_func)
Burgers Velo Material Matrix assembly kernel.
CUDA_HOST_DEVICE void burgers_velo_material_defect_assembly_kernel(LocVecType_ &loc_vec, const LocVecType_ &local_prim_dofs, const LocVecType_ &local_conv_dofs, const Tiny::Matrix< typename SpaceHelp_::DataType, dim_, num_verts_ > &local_coeffs, const typename SpaceHelp_::DomainPointType *cub_pt, const typename SpaceHelp_::DataType *cub_wg, const int num_cubs, const VoxelAssembly::AssemblyBurgersData< typename SpaceHelp_::DataType > &burgers_params, const bool need_convection, ViscFunc_ visco_func)
Burgers Vector assembly kernel.
MaterialType
Enum for different material types.
@ value
specifies whether the space should supply basis function values
@ dom_point
specifies whether the trafo should supply domain point coordinates
Data for burgers assembler.
A data field for a cubature rule.
A data field for all necessary values that define the dof mapping for assembly.
Data for material burgers assembler.
Helper struct wrapping the data required as shared data.