FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
burgers_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
9#include <kernel/backend.hpp>
11#include <kernel/voxel_assembly/voxel_assembly_common.hpp>
12#include <kernel/voxel_assembly/helper/data_handler.hpp>
13#include <kernel/voxel_assembly/helper/space_helper.hpp>
14#include <kernel/cubature/rule.hpp>
15#include <kernel/lafem/sparse_matrix_bcsr.hpp>
16#include <kernel/lafem/dense_vector_blocked.hpp>
17#include <kernel/trafo/standard/mapping.hpp>
18#include <kernel/geometry/conformal_mesh.hpp>
19#include <kernel/util/tiny_algebra.hpp>
20#include <kernel/global/vector.hpp>
21#include <kernel/lafem/vector_mirror.hpp>
22
23#ifdef FEAT_HAVE_CUDA
24#include <kernel/util/cuda_util.hpp>
25#endif
26
27#ifdef __CUDACC__
28#include <cooperative_groups.h>
29#include <cooperative_groups/reduce.h>
30namespace cg = cooperative_groups;
31#endif
32
33namespace FEAT
34{
35 namespace VoxelAssembly
36 {
46 template<typename Space_, typename DT_, typename IT_>
47 class VoxelBurgersAssembler DOXY({});
48
49 #if defined(FEAT_HAVE_CUDA) || defined(DOXYGEN)
51 template<typename SpaceHelp_>
53 {
54 typedef SpaceHelp_ SpaceHelp;
55 static constexpr int dim = SpaceHelp::dim;
56 typedef typename SpaceHelp::SpaceType SpaceType;
57 typedef typename SpaceHelp::DataType DataType;
58 //define local sizes
59 static constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
60 // local vector and matrix defines
63
64 typename SpaceHelp::EvalData basis_data;
65 typename SpaceHelp::JacobianMatrixType loc_jac;
66 typename SpaceHelp::JacobianMatrixType loc_jac_inv;
67 MatValueType loc_grad_v;
68 VecValueType loc_v;
69 VecValueType mean_v;
70 typename SpaceHelp::DomainPointType dom_point;
72 DataType local_delta;
73 DataType det;
74 DataType weight;
75 bool need_frechet;
76 };
77 #endif
78
79 namespace Kernel
80 {
81
104 template<typename SpaceHelp_, typename LocMatType_, typename LocVecType_, int dim_, int num_verts_>
105 CUDA_HOST_DEVICE void burgers_mat_assembly_kernel(LocMatType_& loc_mat, const LocVecType_& local_conv_dofs, const Tiny::Matrix<typename SpaceHelp_::DataType, dim_, num_verts_>& local_coeffs,
106 const typename SpaceHelp_::DomainPointType* cub_pt, const typename SpaceHelp_::DataType* cub_wg, const int num_cubs,
108 const bool need_streamline, const bool need_convection, const typename SpaceHelp_::DataType tol_eps)
109 {
110 typedef SpaceHelp_ SpaceHelp;
111 constexpr int dim = SpaceHelp::dim;
112 typedef typename SpaceHelp::SpaceType SpaceType;
113 typedef typename SpaceHelp::DataType DataType;
114
115 const DataType& nu{burgers_params.nu};
116 const DataType& theta{burgers_params.theta};
117 const DataType& beta{burgers_params.beta};
118 const DataType& frechet_beta{burgers_params.frechet_beta};
119 const DataType& sd_delta{burgers_params.sd_delta};
120 const DataType& sd_nu{burgers_params.sd_nu};
121 const DataType& sd_v_norm{burgers_params.sd_v_norm};
122 const bool& deformation{burgers_params.deformation};
123
124 // #ifdef __CUDACC__
125 // const DataType tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
126 // #else
127 // const DataType tol_eps = Math::sqrt(Math::eps<DataType>());
128 // #endif
129
130 // #ifdef __CUDACC__
131 // const bool need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
132 // const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
133 // #else
134 // const bool need_streamline = (Math::abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
135 // const bool need_convection = Math::abs(beta) > DataType(0);
136 // #endif
137
138
139 //define local sizes
140 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
141 //get number of nodes per element
142 // constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
143 // define local arrays
144 typename SpaceHelp::JacobianMatrixType loc_jac, loc_jac_inv;
145 typename SpaceHelp::EvalData basis_data;
146
147 // local vector and matrix defines
148 typedef Tiny::Vector<DataType, dim> VecValueType;
149 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
150
151 VecValueType loc_v(DataType(0)), mean_v(DataType(0));
152 MatValueType loc_grad_v(DataType(0));
153 DataType local_delta(DataType(0));
154
155 loc_mat.format();
156
157 Tiny::Vector<DataType, num_loc_dofs> streamdiff_coeffs(DataType(0));
158
159 if(need_streamline) //need streamdiff?
160 {
161 //set domain point to barycenter, which is zero for Hypercubes
162 const VecValueType barycenter(DataType(0));
163 // NewSpaceHelp::_map_point(img_point, barycenter, local_coeffs);
164 //only reserve memory for reference values
165 SpaceHelp::eval_ref_values(basis_data, barycenter);
166 SpaceHelp::trans_values(basis_data);
167 for(int i(0); i < num_loc_dofs; ++i)
168 {
169 mean_v.axpy(basis_data.phi[i].value, local_conv_dofs[i]);
170 }
171 const DataType local_norm_v = mean_v.norm_euclid();
172
173 if(local_norm_v > tol_eps)
174 {
175 const DataType local_h = SpaceHelp::width_directed(mean_v, local_coeffs) * local_norm_v;
176 const DataType local_re = (local_norm_v * local_h) / sd_nu;
177 local_delta = sd_delta * (local_h / sd_v_norm) * (DataType(2) * local_re) / (DataType(1) + local_re);
178 }
179 }
180
181 for(int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
182 {
183 const typename SpaceHelp::DomainPointType& dom_point = cub_pt[cub_ind];
184 SpaceHelp::eval_ref_values(basis_data, dom_point);
185 SpaceHelp::trans_values(basis_data);
186 // NewSpaceHelp::_map_point(img_point, dom_point, local_coeffs);//not needed?
187 SpaceHelp::calc_jac_mat(loc_jac, dom_point, local_coeffs);
188 loc_jac_inv.set_inverse(loc_jac);
189
190 SpaceHelp::eval_ref_gradients(basis_data, dom_point);
191 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);
192
193 const DataType weight = loc_jac.vol() * cub_wg[cub_ind];
194 if(need_convection || need_streamline) // need streamdiff or convection?
195 {
196 loc_v.format();
197 for(int i = 0; i < num_loc_dofs; ++i)
198 {
199 loc_v.axpy(basis_data.phi[i].value, local_conv_dofs[i]);
200 }
201 }
202 #ifdef __CUDACC__
203 if(CudaMath::cuda_abs(frechet_beta) > DataType(0)) // need frechet beta?
204 #else
205 if(Math::abs(frechet_beta) > DataType(0)) // need frechet beta?
206 #endif
207 {
208 loc_grad_v.format();
209 for(int i = 0; i < num_loc_dofs; ++i)
210 {
211 loc_grad_v.add_outer_product(local_conv_dofs[i], basis_data.phi[i].grad);
212 }
213 }
214
215 if(need_streamline) // need streamdiff?
216 {
217 for(int i = 0; i < num_loc_dofs; ++i)
218 {
219 streamdiff_coeffs[i] = Tiny::dot(loc_v, basis_data.phi[i].grad);
220 }
221 }
222
223 if(deformation)
224 {
225 for(int i(0); i < num_loc_dofs; ++i)
226 {
227 // trial function loop
228 for(int j(0); j < num_loc_dofs; ++j)
229 {
230 // compute scalar value
231 const DataType value = nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
232
233 // update local matrix
234 loc_mat[i][j].add_scalar_main_diag(value);
235 loc_mat[i][j].add_outer_product(basis_data.phi[j].grad, basis_data.phi[i].grad, nu * weight);
236 }
237 }
238 }
239 else
240 {
241 for(int i(0); i < num_loc_dofs; ++i)
242 {
243 // trial function loop
244 for(int j(0); j < num_loc_dofs; ++j)
245 {
246 // compute scalar value
247 const DataType value = nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
248
249 // update local matrix
250 loc_mat[i][j].add_scalar_main_diag(value);
251 }
252 }
253 }
254
255 if(need_convection) // assemble convection?
256 {
257 // test function loop
258 for(int i(0); i < num_loc_dofs; ++i)
259 {
260 // trial function loop
261 for(int j(0); j < num_loc_dofs; ++j)
262 {
263 // compute scalar value
264 const DataType value = beta * weight * basis_data.phi[i].value * Tiny::dot(loc_v, basis_data.phi[j].grad);
265
266 // update local matrix
267 loc_mat[i][j].add_scalar_main_diag(value);
268 }
269 }
270 }
271
272 // assemble convection Frechet?
273 #ifdef __CUDACC__
274 if(CudaMath::cuda_abs(frechet_beta) > DataType(0))
275 #else
276 if(Math::abs(frechet_beta) > DataType(0))
277 #endif
278 {
279 // test function loop
280 for(int i(0); i < num_loc_dofs; ++i)
281 {
282 // trial function loop
283 for(int j(0); j < num_loc_dofs; ++j)
284 {
285 // compute scalar value
286 const DataType value = frechet_beta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
287
288 // update local matrix
289 loc_mat[i][j].axpy(value, loc_grad_v);
290 }
291 }
292 }
293
294 // assemble reaction?
295 #ifdef __CUDACC__
296 if(CudaMath::cuda_abs(theta) > DataType(0))
297 #else
298 if(Math::abs(theta) > DataType(0))
299 #endif
300 {
301 // test function loop
302 for(int i(0); i < num_loc_dofs; ++i)
303 {
304 // trial function loop
305 for(int j(0); j < num_loc_dofs; ++j)
306 {
307 // compute scalar value
308 const DataType value = theta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
309
310 // update local matrix
311 loc_mat[i][j].add_scalar_main_diag(value);
312 }
313 }
314 }
315
316 // assemble streamline diffusion?
317 if((need_streamline) && (local_delta > tol_eps))
318 {
319 // test function loop
320 for(int i(0); i < num_loc_dofs; ++i)
321 {
322 // trial function loop
323 for(int j(0); j < num_loc_dofs; ++j)
324 {
325 // compute scalar value
326 const DataType value = local_delta * weight * streamdiff_coeffs[i] * streamdiff_coeffs[j];
327
328 // update local matrix
329 loc_mat[i][j].add_scalar_main_diag(value);
330 }
331 }
332 }
333 // next cubature point
334 }
335 }
336
337 #if defined(__CUDACC__) || defined(DOXYGEN)
338
339
340 template<typename ThreadGroup_, typename SpaceHelp_>
341 CUDA_DEVICE __forceinline__ void grouped_burgers_mat_alt_prepare_assembly_kernel(const ThreadGroup_& tg, BurgersSharedDataKernelWrapper<SpaceHelp_>* shared_wrapper,
342 int loc_assemble_size, int assemble_offset, typename SpaceHelp_::DataType* loc_mat, const typename SpaceHelp_::DataType* local_conv_dofs,
344 const typename SpaceHelp_::DomainPointType* cub_pt, const typename SpaceHelp_::DataType* cub_wg, const int cub_ind,
346 const bool need_streamline, const bool need_convection, const typename SpaceHelp_::DataType tol_eps)
347 {
348 typedef SpaceHelp_ SpaceHelp;
349 constexpr int dim = SpaceHelp::dim;
350 typedef typename SpaceHelp::SpaceType SpaceType;
351 typedef typename SpaceHelp::DataType DataType;
352 // constexpr int num_loc_verts = SpaceHelp::num_verts;
353 const int t_idx = tg.thread_rank();
354 const int g_size = tg.num_threads();
355
356 const DataType& nu{burgers_params.nu};
357 const DataType& theta{burgers_params.theta};
358 const DataType& beta{burgers_params.beta};
359 const DataType& frechet_beta{burgers_params.frechet_beta};
360 const DataType& sd_delta{burgers_params.sd_delta};
361 const DataType& sd_nu{burgers_params.sd_nu};
362 const DataType& sd_v_norm{burgers_params.sd_v_norm};
363 const bool& deformation{burgers_params.deformation};
364
365 // #ifdef __CUDACC__
366 // const DataType tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
367 // #else
368 // const DataType tol_eps = Math::sqrt(Math::eps<DataType>());
369 // #endif
370
371 // #ifdef __CUDACC__
372 // const bool need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
373 // const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
374 // #else
375 // const bool need_streamline = (Math::abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
376 // const bool need_convection = Math::abs(beta) > DataType(0);
377 // #endif
378
379
380 //define local sizes
381 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
382 // local vector and matrix defines
383 typedef Tiny::Vector<DataType, dim> VecValueType;
384 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
385 //get number of nodes per element
386 // constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
387 // define local arrays
388 // use extern shared for this?!
389 // TODO: get initiliziaztion into outside loop...
390 typedef BurgersSharedDataKernelWrapper<SpaceHelp> BSDKWrapper;
391 typename SpaceHelp::JacobianMatrixType& loc_jac = shared_wrapper->loc_jac;
392 typename SpaceHelp::JacobianMatrixType& loc_jac_inv = shared_wrapper->loc_jac_inv;
393 MatValueType& loc_grad_v = shared_wrapper->loc_grad_v;
394 VecValueType& loc_v = shared_wrapper->loc_v;
395 VecValueType& mean_v = shared_wrapper->mean_v;
396 typename SpaceHelp::DomainPointType& dom_point = shared_wrapper->dom_point;
397 Tiny::Vector<DataType, num_loc_dofs>& streamdiff_coeffs = shared_wrapper->streamdiff_coeffs;
398 DataType& local_delta = shared_wrapper->local_delta;
399 DataType& det = shared_wrapper->det;
400 DataType& weight = shared_wrapper->weight;
401 typename SpaceHelp::EvalData& basis_data = shared_wrapper->basis_data;
402 bool& need_frechet = shared_wrapper->need_frechet;
403
404 VoxelAssembly::coalesced_format(tg, (unsigned int*) shared_wrapper, sizeof(BSDKWrapper)/(sizeof(unsigned int)));
405 tg.sync();
406
407 cg::invoke_one(tg, [&](){need_frechet = CudaMath::cuda_abs(frechet_beta) > DataType(0);});
408 tg.sync();
409
410
411 if(need_streamline) //need streamdiff?
412 {
413 cg::invoke_one(tg, [&]() {mean_v = DataType(0);});
414 //set domain point to barycenter, which is zero for Hypercubes
415 // NewSpaceHelp::_map_point(img_point, barycenter, local_coeffs);
416 //only reserve memory for reference values
417 cg::invoke_one(tg, [&](){ const VecValueType bc(0);
418 SpaceHelp::eval_ref_values(basis_data, bc);
419 SpaceHelp::trans_values(basis_data);});
420
421 tg.sync();
422
423 for(int idx = t_idx; idx < num_loc_dofs; idx += g_size)
424 {
425 VoxelAssembly::template grouped_axpy<DataType, cg::thread_group, dim>(tg, &mean_v[0], basis_data.phi[idx].value, &local_conv_dofs[idx*dim]);
426 }
427
428 tg.sync();
429
430 DataType local_norm_v = mean_v.norm_euclid();
431
432 if(local_norm_v > tol_eps)
433 {
434 cg::invoke_one(tg, [&](){
435 const DataType local_h = SpaceHelp::width_directed(mean_v, local_coeffs) * local_norm_v;
436 const DataType local_re = (local_norm_v * local_h) / sd_nu;
437 local_delta = sd_delta * (local_h / sd_v_norm) * (DataType(2) * local_re) / (DataType(1) + local_re);
438 });
439 }
440 }
441
442 tg.sync();
443 {
444 cg::invoke_one(tg, [&](){dom_point = cub_pt[cub_ind];
445 SpaceHelp::eval_ref_values(basis_data, dom_point);
446 SpaceHelp::trans_values(basis_data);});
447 // NewSpaceHelp::_map_point(img_point, dom_point, local_coeffs);//not needed?
448 tg.sync();
449 SpaceHelp::grouped_calc_jac_mat(tg, loc_jac, dom_point, &local_coeffs[0][0]);
450 tg.sync();
451 cg::invoke_one(tg, [&](){det = loc_jac.det();
452 weight = CudaMath::cuda_abs(det) * cub_wg[cub_ind];});
453 tg.sync();
454 loc_jac_inv.grouped_set_inverse(tg, loc_jac, det);
455 tg.sync();
456 cg::invoke_one(tg, [&](){
457 SpaceHelp::eval_ref_gradients(basis_data, dom_point);
458 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);});
459
460 tg.sync();
461 if(need_convection || need_streamline) // need streamdiff or convection?
462 {
463 VoxelAssembly::coalesced_format(tg, &loc_v[0], dim);
464 tg.sync();
465
466 for(int idx = t_idx; idx < num_loc_dofs; idx += g_size)
467 {
468 VoxelAssembly::template grouped_axpy<DataType, cg::thread_group, dim>(tg, &loc_v[0], basis_data.phi[idx].value, &local_conv_dofs[idx*dim]);
469 }
470 // tg.sync();
471 }
472
473 if(need_frechet)
474 {
475 VoxelAssembly::coalesced_format(tg, &loc_grad_v[0][0], dim*dim);
476 tg.sync();
477 for(int i = t_idx; i < num_loc_dofs; i += g_size)
478 {
479 VoxelAssembly::grouped_add_outer_product(tg, &loc_grad_v[0][0], &local_conv_dofs[i*dim], basis_data.phi[i].grad);
480 }
481 // tg.sync();
482 }
483
484 if(need_streamline) // need streamdiff?
485 {
486 tg.sync();
487 for(int i = t_idx; i < num_loc_dofs; i += g_size)
488 {
489 streamdiff_coeffs[i] = Tiny::dot(loc_v, basis_data.phi[i].grad);
490 }
491 // tg.sync();
492 }
493
494 tg.sync();
495 }
496 }
497
499 template<typename ThreadGroup_, typename SpaceHelp_>
500 CUDA_DEVICE __forceinline__ void grouped_burgers_mat_alt_assembly_kernel(const ThreadGroup_& tg, BurgersSharedDataKernelWrapper<SpaceHelp_>* shared_wrapper,
501 int loc_assemble_size, int assemble_offset, typename SpaceHelp_::DataType* loc_mat,
503 const bool need_streamline, const bool need_convection, const typename SpaceHelp_::DataType tol_eps)
504 {
505 typedef SpaceHelp_ SpaceHelp;
506 constexpr int dim = SpaceHelp::dim;
507 typedef typename SpaceHelp::SpaceType SpaceType;
508 typedef typename SpaceHelp::DataType DataType;
509 // constexpr int num_loc_verts = SpaceHelp::num_verts;
510 const int t_idx = tg.thread_rank();
511 const int g_size = tg.num_threads();
512
513 const DataType& nu{burgers_params.nu};
514 const DataType& theta{burgers_params.theta};
515 const DataType& beta{burgers_params.beta};
516 const DataType& frechet_beta{burgers_params.frechet_beta};
517 const DataType& sd_delta{burgers_params.sd_delta};
518 const DataType& sd_nu{burgers_params.sd_nu};
519 const DataType& sd_v_norm{burgers_params.sd_v_norm};
520 const bool& deformation{burgers_params.deformation};
521
522 // #ifdef __CUDACC__
523 // const DataType tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
524 // #else
525 // const DataType tol_eps = Math::sqrt(Math::eps<DataType>());
526 // #endif
527
528 // #ifdef __CUDACC__
529 // const bool need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
530 // const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
531 // #else
532 // const bool need_streamline = (Math::abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
533 // const bool need_convection = Math::abs(beta) > DataType(0);
534 // #endif
535
536
537 //define local sizes
538 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
539 // local vector and matrix defines
540 typedef Tiny::Vector<DataType, dim> VecValueType;
541 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
542 //get number of nodes per element
543 // constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
544 // define local arrays
545 // use extern shared for this?!
546 // TODO: get initiliziaztion into outside loop...
548 typename SpaceHelp::JacobianMatrixType& loc_jac = shared_wrapper->loc_jac;
549 typename SpaceHelp::JacobianMatrixType& loc_jac_inv = shared_wrapper->loc_jac_inv;
550 MatValueType& loc_grad_v = shared_wrapper->loc_grad_v;
551 VecValueType& loc_v = shared_wrapper->loc_v;
552 VecValueType& mean_v = shared_wrapper->mean_v;
553 typename SpaceHelp::DomainPointType& dom_point = shared_wrapper->dom_point;
554 Tiny::Vector<DataType, num_loc_dofs>& streamdiff_coeffs = shared_wrapper->streamdiff_coeffs;
555 DataType& local_delta = shared_wrapper->local_delta;
556 DataType& det = shared_wrapper->det;
557 DataType& weight = shared_wrapper->weight;
558 typename SpaceHelp::EvalData& basis_data = shared_wrapper->basis_data;
559 bool& need_frechet = shared_wrapper->need_frechet;
560
561
562 for(int idx = t_idx; idx < loc_assemble_size; idx += g_size)
563 {
564 const int i = (idx+assemble_offset) / num_loc_dofs;
565 const int j = (idx+assemble_offset) % num_loc_dofs;
566 if(deformation)
567 {
568 // compute scalar value
569 const DataType value = nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
570
571 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
572 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_outer_product(basis_data.phi[j].grad, basis_data.phi[i].grad, nu * weight);
573 }
574 else
575 {
576 // compute scalar value
577 const DataType value = nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
578
579 // update local matrix
580 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
581 }
582
583 if(need_convection) // assemble convection?
584 {
585 // compute scalar value
586 const DataType value = beta * weight * basis_data.phi[i].value * VoxelAssembly::dot(basis_data.phi[j].grad, &loc_v[0]);
587
588 // update local matrix
589 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
590 }
591
592 // assemble convection Frechet?
593 if(need_frechet)
594 {
595 // compute scalar value
596 const DataType value = frechet_beta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
597
598 // update local matrix
599 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->axpy(value, loc_grad_v);
600 }
601
602 // assemble reaction?
603 #ifdef __CUDACC__
604 if(CudaMath::cuda_abs(theta) > DataType(0))
605 #else
606 if(Math::abs(theta) > DataType(0))
607 #endif
608 {
609 // compute scalar value
610 const DataType value = theta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
611
612 // update local matrix
613 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
614 }
615
616 // assemble streamline diffusion?
617 if((need_streamline) && (local_delta > tol_eps))
618 {
619 // compute scalar value
620 const DataType value = local_delta * weight * streamdiff_coeffs[i] * streamdiff_coeffs[j];
621
622 // update local matrix
623 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
624 }
625 // next cubature point
626 }
627 }
628
651 template<typename ThreadGroup_, typename SpaceHelp_>
652 CUDA_DEVICE __forceinline__ void grouped_burgers_mat_assembly_kernel(const ThreadGroup_& tg, BurgersSharedDataKernelWrapper<SpaceHelp_>* shared_wrapper, int loc_assemble_size, int assemble_offset, typename SpaceHelp_::DataType* loc_mat, const typename SpaceHelp_::DataType* local_conv_dofs,
654 const typename SpaceHelp_::DomainPointType* cub_pt, const typename SpaceHelp_::DataType* cub_wg, const int num_cubs,
656 const bool need_streamline, const bool need_convection, const typename SpaceHelp_::DataType tol_eps)
657 {
658 typedef SpaceHelp_ SpaceHelp;
659 constexpr int dim = SpaceHelp::dim;
660 typedef typename SpaceHelp::SpaceType SpaceType;
661 typedef typename SpaceHelp::DataType DataType;
662 // constexpr int num_loc_verts = SpaceHelp::num_verts;
663 const int t_idx = tg.thread_rank();
664 const int g_size = tg.num_threads();
665
666 const DataType& nu{burgers_params.nu};
667 const DataType& theta{burgers_params.theta};
668 const DataType& beta{burgers_params.beta};
669 const DataType& frechet_beta{burgers_params.frechet_beta};
670 const DataType& sd_delta{burgers_params.sd_delta};
671 const DataType& sd_nu{burgers_params.sd_nu};
672 const DataType& sd_v_norm{burgers_params.sd_v_norm};
673 const bool& deformation{burgers_params.deformation};
674
675 // #ifdef __CUDACC__
676 // const DataType tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
677 // #else
678 // const DataType tol_eps = Math::sqrt(Math::eps<DataType>());
679 // #endif
680
681 // #ifdef __CUDACC__
682 // const bool need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
683 // const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
684 // #else
685 // const bool need_streamline = (Math::abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
686 // const bool need_convection = Math::abs(beta) > DataType(0);
687 // #endif
688
689
690 //define local sizes
691 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
692 // local vector and matrix defines
693 typedef Tiny::Vector<DataType, dim> VecValueType;
694 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
695 //get number of nodes per element
696 // constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
697 // define local arrays
698 // use extern shared for this?!
700 typename SpaceHelp::JacobianMatrixType& loc_jac = shared_wrapper->loc_jac;
701 typename SpaceHelp::JacobianMatrixType& loc_jac_inv = shared_wrapper->loc_jac_inv;
702 MatValueType& loc_grad_v = shared_wrapper->loc_grad_v;
703 VecValueType& loc_v = shared_wrapper->loc_v;
704 VecValueType& mean_v = shared_wrapper->mean_v;
705 typename SpaceHelp::DomainPointType& dom_point = shared_wrapper->dom_point;
706 Tiny::Vector<DataType, num_loc_dofs>& streamdiff_coeffs = shared_wrapper->streamdiff_coeffs;
707 DataType& local_delta = shared_wrapper->local_delta;
708 DataType& det = shared_wrapper->det;
709 DataType& weight = shared_wrapper->weight;
710 typename SpaceHelp::EvalData& basis_data = shared_wrapper->basis_data;
711 bool& need_frechet = shared_wrapper->need_frechet;
712
713 VoxelAssembly::coalesced_format(tg, (unsigned int*) shared_wrapper, sizeof(BSDKWrapper)/(sizeof(unsigned int)));
714 tg.sync();
715
716 cg::invoke_one(tg, [&](){need_frechet = CudaMath::cuda_abs(frechet_beta) > DataType(0);});
717 tg.sync();
718
719
720 if(need_streamline) //need streamdiff?
721 {
722 cg::invoke_one(tg, [&]() {mean_v = DataType(0);});
723 //set domain point to barycenter, which is zero for Hypercubes
724 // NewSpaceHelp::_map_point(img_point, barycenter, local_coeffs);
725 //only reserve memory for reference values
726 cg::invoke_one(tg, [&](){ const VecValueType bc(0);
727 SpaceHelp::eval_ref_values(basis_data, bc);
728 SpaceHelp::trans_values(basis_data);});
729
730 tg.sync();
731
732 for(int idx = t_idx; idx < num_loc_dofs; idx += g_size)
733 {
734 VoxelAssembly::template grouped_axpy<DataType, cg::thread_group, dim>(tg, &mean_v[0], basis_data.phi[idx].value, &local_conv_dofs[idx*dim]);
735 }
736
737 tg.sync();
738
739 DataType local_norm_v = mean_v.norm_euclid();
740
741 if(local_norm_v > tol_eps)
742 {
743 cg::invoke_one(tg, [&](){
744 const DataType local_h = SpaceHelp::width_directed(mean_v, local_coeffs) * local_norm_v;
745 const DataType local_re = (local_norm_v * local_h) / sd_nu;
746 local_delta = sd_delta * (local_h / sd_v_norm) * (DataType(2) * local_re) / (DataType(1) + local_re);
747 });
748 }
749 }
750
751
752 for(int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
753 {
754 tg.sync();
755 cg::invoke_one(tg, [&](){dom_point = cub_pt[cub_ind];
756 SpaceHelp::eval_ref_values(basis_data, dom_point);
757 SpaceHelp::trans_values(basis_data);});
758 // NewSpaceHelp::_map_point(img_point, dom_point, local_coeffs);//not needed?
759 tg.sync();
760 SpaceHelp::grouped_calc_jac_mat(tg, loc_jac, dom_point, &local_coeffs[0][0]);
761 tg.sync();
762 cg::invoke_one(tg, [&](){det = loc_jac.det();
763 weight = CudaMath::cuda_abs(det) * cub_wg[cub_ind];});
764 tg.sync();
765 loc_jac_inv.grouped_set_inverse(tg, loc_jac, det);
766 tg.sync();
767 cg::invoke_one(tg, [&](){
768 SpaceHelp::eval_ref_gradients(basis_data, dom_point);
769 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);});
770
771 tg.sync();
772 if(need_convection || need_streamline) // need streamdiff or convection?
773 {
774 VoxelAssembly::coalesced_format(tg, &loc_v[0], dim);
775 tg.sync();
776
777 for(int idx = t_idx; idx < num_loc_dofs; idx += g_size)
778 {
779 VoxelAssembly::template grouped_axpy<DataType, cg::thread_group, dim>(tg, &loc_v[0], basis_data.phi[idx].value, &local_conv_dofs[idx*dim]);
780 }
781 // tg.sync();
782 }
783
784 if(need_frechet)
785 {
786 VoxelAssembly::coalesced_format(tg, &loc_grad_v[0][0], dim*dim);
787 tg.sync();
788 for(int i = t_idx; i < num_loc_dofs; i += g_size)
789 {
790 VoxelAssembly::grouped_add_outer_product(tg, &loc_grad_v[0][0], &local_conv_dofs[i*dim], basis_data.phi[i].grad);
791 }
792 // tg.sync();
793 }
794
795 if(need_streamline) // need streamdiff?
796 {
797 tg.sync();
798 for(int i = t_idx; i < num_loc_dofs; i += g_size)
799 {
800 streamdiff_coeffs[i] = Tiny::dot(loc_v, basis_data.phi[i].grad);
801 }
802 // tg.sync();
803 }
804
805 tg.sync();
806
807 for(int idx = t_idx; idx < loc_assemble_size; idx += g_size)
808 {
809 // the thread local test and trial function indices
810 const int i = (idx+assemble_offset) / num_loc_dofs;
811 const int j = (idx+assemble_offset) % num_loc_dofs;
812
813 if(deformation)
814 {
815 // compute scalar value
816 const DataType value = nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
817
818 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
819 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_outer_product(basis_data.phi[j].grad, basis_data.phi[i].grad, nu * weight);
820 }
821 else
822 {
823 // compute scalar value
824 const DataType value = nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
825
826 // update local matrix
827 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
828 }
829
830 if(need_convection) // assemble convection?
831 {
832 // compute scalar value
833 const DataType value = beta * weight * basis_data.phi[i].value * VoxelAssembly::dot(basis_data.phi[j].grad, &loc_v[0]);
834
835 // update local matrix
836 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
837 }
838
839 // assemble convection Frechet?
840 if(need_frechet)
841 {
842 // compute scalar value
843 const DataType value = frechet_beta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
844
845 // update local matrix
846 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->axpy(value, loc_grad_v);
847 }
848
849 // assemble reaction?
850 #ifdef __CUDACC__
851 if(CudaMath::cuda_abs(theta) > DataType(0))
852 #else
853 if(Math::abs(theta) > DataType(0))
854 #endif
855 {
856 // compute scalar value
857 const DataType value = theta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
858
859 // update local matrix
860 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
861 }
862
863 // assemble streamline diffusion?
864 if((need_streamline) && (local_delta > tol_eps))
865 {
866 // compute scalar value
867 const DataType value = local_delta * weight * streamdiff_coeffs[i] * streamdiff_coeffs[j];
868
869 // update local matrix
870 ((Tiny::Matrix<DataType, dim, dim>*)(loc_mat + dim*dim*idx))->add_scalar_main_diag(value);
871 }
872 }
873 // next cubature point
874 }
875 }
876 #endif
877
899 template<typename SpaceHelp_, typename LocVecType_, int dim_, int num_verts_>
900 CUDA_HOST_DEVICE void burgers_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,
901 const typename SpaceHelp_::DomainPointType* cub_pt, const typename SpaceHelp_::DataType* cub_wg, const int num_cubs,
903 const bool need_convection)
904 {
905 typedef SpaceHelp_ SpaceHelp;
906 constexpr int dim = SpaceHelp::dim;
907 typedef typename SpaceHelp::SpaceType SpaceType;
908 typedef typename SpaceHelp::DataType DataType;
909
910 const DataType& nu{burgers_params.nu};
911 const DataType& theta{burgers_params.theta};
912 const DataType& beta{burgers_params.beta};
913 // const DataType& frechet_beta{burgers_params.frechet_beta};
914 // const DataType& sd_delta{burgers_params.sd_delta};
915 // const DataType& sd_nu{burgers_params.sd_nu};
916 // const DataType& sd_v_norm{burgers_params.sd_v_norm};
917 const bool& deformation{burgers_params.deformation};
918
919 // #ifdef __CUDACC__
920 // const DataType tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
921 // #else
922 // const DataType tol_eps = Math::sqrt(Math::eps<DataType>());
923 // #endif
924
925 // #ifdef __CUDACC__
926 // const bool need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
927 // const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
928 // #else
929 // const bool need_streamline = (Math::abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
930 // const bool need_convection = Math::abs(beta) > DataType(0);
931 // #endif
932
933
934 //define local sizes
935 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
936 //get number of nodes per element
937 // constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
938 // define local arrays
939 typename SpaceHelp::JacobianMatrixType loc_jac, loc_jac_inv;
940 typename SpaceHelp::EvalData basis_data;
941
942 // local vector and matrix defines
943 typedef Tiny::Vector<DataType, dim> VecValueType;
944 // typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
945
946 VecValueType loc_v(DataType(0));
947
948 loc_vec.format();
949
950 Tiny::Vector<DataType, num_loc_dofs> streamdiff_coeffs(DataType(0));
951
952 for(int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
953 {
954 const typename SpaceHelp::DomainPointType& dom_point = cub_pt[cub_ind];
955 SpaceHelp::eval_ref_values(basis_data, dom_point);
956 SpaceHelp::trans_values(basis_data);
957 // NewSpaceHelp::_map_point(img_point, dom_point, local_coeffs);//not needed?
958 SpaceHelp::calc_jac_mat(loc_jac, dom_point, local_coeffs);
959 loc_jac_inv.set_inverse(loc_jac);
960
961 SpaceHelp::eval_ref_gradients(basis_data, dom_point);
962 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);
963
964 const DataType weight = loc_jac.vol() * cub_wg[cub_ind];
965 if(need_convection) // need streamdiff or convection?
966 {
967 loc_v.format();
968 for(int i = 0; i < num_loc_dofs; ++i)
969 {
970 loc_v.axpy(basis_data.phi[i].value, local_conv_dofs[i]);
971 }
972 }
973
974 if(deformation)
975 {
976 for(int i(0); i < num_loc_dofs; ++i)
977 {
978 // trial function loop
979 for(int j(0); j < num_loc_dofs; ++j)
980 {
981 // compute scalar values
982 const DataType value1 = nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
983 const DataType value2 = nu * weight * Tiny::dot(local_prim_dofs[j], basis_data.phi[i].grad);
984 // update local vector
985 loc_vec[i].axpy(value1, local_prim_dofs[j]);
986 loc_vec[i].axpy(value2, basis_data.phi[j].grad);
987 }
988 }
989 }
990 else
991 {
992 for(int i(0); i < num_loc_dofs; ++i)
993 {
994 // trial function loop
995 for(int j(0); j < num_loc_dofs; ++j)
996 {
997 // compute scalar value
998 const DataType value = nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad);
999
1000 // update local matrix
1001 loc_vec[i].axpy(value, local_prim_dofs[j]);
1002 }
1003 }
1004 }
1005
1006 if(need_convection) // assemble convection?
1007 {
1008 // test function loop
1009 for(int i(0); i < num_loc_dofs; ++i)
1010 {
1011 // trial function loop
1012 for(int j(0); j < num_loc_dofs; ++j)
1013 {
1014 // compute scalar value
1015 const DataType value = beta * weight * basis_data.phi[i].value * Tiny::dot(loc_v, basis_data.phi[j].grad);
1016
1017 // update local matrix
1018 loc_vec[i].axpy(value, local_prim_dofs[j]);
1019 }
1020 }
1021 }
1022
1023 // assemble reaction?
1024 #ifdef __CUDACC__
1025 if(CudaMath::cuda_abs(theta) > DataType(0))
1026 #else
1027 if(Math::abs(theta) > DataType(0))
1028 #endif
1029 {
1030 // test function loop
1031 for(int i(0); i < num_loc_dofs; ++i)
1032 {
1033 // trial function loop
1034 for(int j(0); j < num_loc_dofs; ++j)
1035 {
1036 // compute scalar value
1037 const DataType value = theta * weight * basis_data.phi[i].value * basis_data.phi[j].value;
1038
1039 // update local matrix
1040 loc_vec[i].axpy(value, local_prim_dofs[j]);
1041 }
1042 }
1043 }
1044 // next cubature point
1045 }
1046 }
1047
1048 #ifdef __CUDACC__
1049 template<typename ThreadGroup_, typename SpaceHelp_>
1050 CUDA_DEVICE void grouped_burgers_defect_assembly_kernel(const ThreadGroup_& tg, BurgersSharedDataKernelWrapper<SpaceHelp_>* shared_wrapper, int loc_assemble_size, int assemble_offset,
1051 typename SpaceHelp_::DataType* loc_vec, const typename SpaceHelp_::DataType* local_prim_dofs, const typename SpaceHelp_::DataType* local_conv_dofs,
1053 const typename SpaceHelp_::DomainPointType* cub_pt, const typename SpaceHelp_::DataType* cub_wg, const int num_cubs,
1055 const bool need_convection)
1056 {
1057 typedef SpaceHelp_ SpaceHelp;
1058 constexpr int dim = SpaceHelp::dim;
1059 typedef typename SpaceHelp::SpaceType SpaceType;
1060 typedef typename SpaceHelp::DataType DataType;
1061 const int t_idx = tg.thread_rank();
1062 const int g_size = tg.num_threads();
1063
1064 const DataType& nu{burgers_params.nu};
1065 const DataType& theta{burgers_params.theta};
1066 const DataType& beta{burgers_params.beta};
1067 // const DataType& frechet_beta{burgers_params.frechet_beta};
1068 // const DataType& sd_delta{burgers_params.sd_delta};
1069 // const DataType& sd_nu{burgers_params.sd_nu};
1070 // const DataType& sd_v_norm{burgers_params.sd_v_norm};
1071 const bool& deformation{burgers_params.deformation};
1072
1073 // #ifdef __CUDACC__
1074 // const DataType tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
1075 // #else
1076 // const DataType tol_eps = Math::sqrt(Math::eps<DataType>());
1077 // #endif
1078
1079 // #ifdef __CUDACC__
1080 // const bool need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
1081 // const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
1082 // #else
1083 // const bool need_streamline = (Math::abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
1084 // const bool need_convection = Math::abs(beta) > DataType(0);
1085 // #endif
1086
1087
1088 //define local sizes
1089 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
1090 //get number of nodes per element
1091 // constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
1092 // define local arrays
1093 typedef BurgersSharedDataKernelWrapper<SpaceHelp> BSDKWrapper;
1094 typename SpaceHelp::JacobianMatrixType& loc_jac = shared_wrapper->loc_jac;
1095 typename SpaceHelp::JacobianMatrixType& loc_jac_inv = shared_wrapper->loc_jac_inv;
1096
1097 DataType& det = shared_wrapper->det;
1098 DataType& weight = shared_wrapper->weight;
1099 typename SpaceHelp::EvalData& basis_data = shared_wrapper->basis_data;
1100 // local vector and matrix defines
1101 typedef Tiny::Vector<DataType, dim> VecValueType;
1102 // typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
1103
1104 VecValueType& loc_v = shared_wrapper->loc_v;
1105
1106 typename SpaceHelp::DomainPointType& dom_point = shared_wrapper->dom_point;
1107
1108 VoxelAssembly::coalesced_format(tg, (unsigned int*) shared_wrapper, sizeof(BSDKWrapper)/(sizeof(unsigned int)));
1109 tg.sync();
1110 // 4 threads should work on one entry, requires block size to be mutliple of 4
1111 cg::thread_block_tile<4> tile4 = cg::tiled_partition<4>(tg);
1112
1113 for(int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
1114 {
1115 tg.sync();
1116 cg::invoke_one(tg, [&](){dom_point = cub_pt[cub_ind];
1117 SpaceHelp::eval_ref_values(basis_data, dom_point);
1118 SpaceHelp::trans_values(basis_data);});
1119 // NewSpaceHelp::_map_point(img_point, dom_point, local_coeffs);//not needed?
1120 tg.sync();
1121 SpaceHelp::grouped_calc_jac_mat(tg, loc_jac, dom_point, &local_coeffs[0][0]);
1122 tg.sync();
1123 cg::invoke_one(tg, [&](){det = loc_jac.det();
1124 weight = CudaMath::cuda_abs(det) * cub_wg[cub_ind];});
1125 tg.sync();
1126 loc_jac_inv.grouped_set_inverse(tg, loc_jac, det);
1127 tg.sync();
1128 cg::invoke_one(tg, [&](){
1129 SpaceHelp::eval_ref_gradients(basis_data, dom_point);
1130 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);});
1131
1132 tg.sync();
1133 if(need_convection) // need streamdiff or convection?
1134 {
1135 VoxelAssembly::coalesced_format(tg, &loc_v[0], dim);
1136 tg.sync();
1137
1138 for(int idx = t_idx; idx < num_loc_dofs; idx += g_size)
1139 {
1140 VoxelAssembly::template grouped_axpy<DataType, cg::thread_group, dim>(tg, &loc_v[0], basis_data.phi[idx].value, &local_conv_dofs[idx*dim]);
1141 }
1142 }
1143 tg.sync();
1144
1145
1146 for(int idx = tile4.meta_group_rank(); idx < loc_assemble_size*dim; idx += tile4.meta_group_size())
1147 {
1148 // compute scalar value
1149 DataType val = DataType(0);
1150 // the thread local test function index
1151 const int i = (idx/dim+assemble_offset);
1152 const int ii = idx%dim;
1153 if(deformation)
1154 {
1155 for(int j = tile4.thread_rank(); j < num_loc_dofs; j += tile4.size())
1156 {
1157 // compute scalar values
1158 val += nu * weight * (Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad) * local_prim_dofs[j*dim + ii]
1159 + Tiny::dot(((Tiny::Vector<DataType, dim>*)local_prim_dofs)[j], basis_data.phi[i].grad) * basis_data.phi[j].grad[ii]);
1160 }
1161 }
1162 else
1163 {
1164 for(int j = tile4.thread_rank(); j < num_loc_dofs; j += tile4.size())
1165 {
1166 // compute scalar values
1167 val += nu * weight * Tiny::dot(basis_data.phi[i].grad, basis_data.phi[j].grad) * local_prim_dofs[j*dim + ii];
1168 }
1169 }
1170
1171 if(need_convection) // assemble convection?
1172 {
1173 for(int j = tile4.thread_rank(); j < num_loc_dofs; j += tile4.size())
1174 {
1175 // compute scalar values
1176 val += beta * weight * basis_data.phi[i].value * Tiny::dot(loc_v, basis_data.phi[j].grad) * local_prim_dofs[j*dim + ii];
1177 }
1178 }
1179
1180 // assemble reaction?
1181 #ifdef __CUDACC__
1182 if(CudaMath::cuda_abs(theta) > DataType(0))
1183 #else
1184 if(Math::abs(theta) > DataType(0))
1185 #endif
1186 {
1187 for(int j = tile4.thread_rank(); j < num_loc_dofs; j += tile4.size())
1188 {
1189 // compute scalar values
1190 val += theta * weight * basis_data.phi[i].value * basis_data.phi[j].value * local_prim_dofs[j*dim + ii];
1191 }
1192 }
1193 // reduce result and store value with async call
1194 // tile4.sync();
1195 cuda::atomic_ref<DataType, cuda::thread_scope_block> a_ref(*(loc_vec+idx));
1196 cg::reduce_update_async(tile4, a_ref, val, cg::plus<DataType>());
1197 }
1198 // next cubature point
1199 }
1200 }
1201 #endif
1202 } // namespace Kernel
1203
1204 namespace Arch
1205 {
1206 #if defined(FEAT_HAVE_CUDA) || defined(DOXYGEN)
1227 template<typename Space_, typename DT_, typename IT_>
1228 void assemble_burgers_csr(const Space_& space,
1229 const CSRMatrixData<DT_, IT_>& matrix_data,
1230 const DT_* conv_data,
1231 const AssemblyCubatureData<DT_>& cubature,
1232 const AssemblyMappingData<DT_, IT_>& dof_mapping,
1233 const Adjacency::ColoringDataHandler& coloring_data,
1234 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params,
1235 const Util::RuntimeParameter& runtime_params);
1236
1258 template<typename Space_, typename DT_, typename IT_>
1259 void assemble_burgers_defect(const Space_& space,
1260 DT_* vector_data,
1261 const DT_* conv_data,
1262 const DT_* primal_data,
1263 const AssemblyCubatureData<DT_>& cubature,
1264 const AssemblyMappingData<DT_, IT_>& dof_mapping,
1265 const Adjacency::ColoringDataHandler& coloring_data,
1266 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params,
1267 const Util::RuntimeParameter& runtime_params);
1268
1282 template<typename DT_, typename IT_, int dim_>
1284
1297 template<typename DT_, typename IT_, int dim_>
1299 #endif
1300
1320 template<typename Space_, typename DT_, typename IT_>
1321 void assemble_burgers_csr_host(const Space_& space,
1322 const CSRMatrixData<DT_, IT_>& matrix_data,
1323 const DT_* conv_data,
1324 const AssemblyCubatureData<DT_>& cubature,
1325 const AssemblyMappingData<DT_, IT_>& dof_mapping,
1326 const Adjacency::ColoringDataHandler& coloring_data,
1327 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params);
1328
1349 template<typename Space_, typename DT_, typename IT_>
1350 void assemble_burgers_defect_host(const Space_& space,
1351 DT_* vector_data,
1352 const DT_* conv_data,
1353 const DT_* primal_data,
1354 const AssemblyCubatureData<DT_>& cubature,
1355 const AssemblyMappingData<DT_, IT_>& dof_mapping,
1356 const Adjacency::ColoringDataHandler& coloring_data,
1357 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params);
1358
1372 template<typename DT_, typename IT_, int dim_>
1374
1388 template<typename DT_, typename IT_, int dim_>
1390
1391 }
1392
1393
1394#ifndef __CUDACC__
1407 template<int dim_, typename DT_, typename IT_>
1409 {
1410 public:
1415 typedef typename SpaceHelp::ShapeType ShapeType;
1416 typedef typename SpaceHelp::DataType DataType;
1417 typedef typename SpaceHelp::IndexType IndexType;
1418
1420 static constexpr int dim = SpaceHelp::dim;
1421
1422 typedef typename SpaceHelp::DomainPointType DomainPointType;
1423 typedef typename SpaceHelp::ImagePointType ImagePointType;
1424 typedef typename SpaceHelp::ValueType ValueType;
1425 typedef typename SpaceHelp::JacobianMatrixType JacobianMatrixType;
1426
1429
1431 DataType nu;
1432
1434 DataType theta;
1435
1437 DataType beta;
1438
1441
1443 DataType sd_delta;
1444
1446 DataType sd_nu;
1447
1449 DataType sd_v_norm;
1450
1451 #ifdef FEAT_HAVE_CUDA
1453 Util::RuntimeParameter runtime_params;
1454
1459 #endif
1460
1463
1464
1465 public:
1466 explicit VoxelBurgersAssembler() = default;
1467
1479 template<typename ColoringType_>
1480 explicit VoxelBurgersAssembler(const SpaceType& space, const ColoringType_& coloring, int hint = -1) :
1481 mesh_data(space, coloring, hint),
1482 nu(DataType(0)), theta(DataType(0)), beta(DataType(0)), frechet_beta(DataType(0)), sd_delta(DataType(0)),
1483 sd_nu(DataType(0)), sd_v_norm(DataType(0)), deformation(true)
1484 {
1485 #ifdef FEAT_HAVE_CUDA
1486 runtime_params = Util::RuntimeParameter{0, 32, 1, false, true};
1487 // #ifdef DEBUG
1488 // const std::size_t stack_limit = Util::cuda_get_max_cache_thread();
1489 // const std::size_t stack_limit_target = sizeof(DataType) * (dim == 3 ? 8096u : 1012u);
1490 // if(stack_limit < stack_limit_target)
1491 // Util::cuda_set_max_cache_thread(stack_limit_target);
1492 // #endif
1493 // set kernel launch parameters
1494 int target_elements = SpaceType::DofMappingType::dof_count * (dim == 3 ? (SpaceType::DofMappingType::dof_count/2+1) : SpaceType::DofMappingType::dof_count);
1495 set_kernel_launch_params(target_elements, runtime_params.blocksize);
1496 #endif
1497 // printf("Time to init: mesh %f, color %f\n", mesh_data.time_init_mesh, mesh_data.time_init_color);
1498 }
1499
1500 // rule of 5
1502
1503 VoxelBurgersAssembler& operator=(const VoxelBurgersAssembler&) = delete;
1504
1506
1507 VoxelBurgersAssembler& operator=(VoxelBurgersAssembler&&) = default;
1508
1510
1517 {
1518 return VoxelAssembly::AssemblyBurgersData<DataType>{nu, theta, beta, frechet_beta, sd_delta, sd_nu, sd_v_norm, deformation};
1519 }
1520
1532 template<typename CubatureFactory_>
1534 const SpaceType& space, const CubatureFactory_& cubature_factory, DataType alpha = DataType(1)) const
1535 {
1536 XASSERTM(matrix.num_rows() == space.get_num_dofs(), "invalid matrix dimensions");
1537 XASSERTM(matrix.num_cols() == space.get_num_dofs(), "invalid matrix dimensions");
1538 XASSERTM(convect.size() == space.get_num_dofs(), "invalid vector size");
1539
1540 //define cubature
1541 typedef Cubature::Rule<ShapeType, DataType, DataType> CubatureRuleType;
1542 CubatureRuleType cubature(Cubature::ctor_factory, cubature_factory);
1543
1544 //get cubature points and weights
1545 int num_cubs = cubature.get_num_points();
1546 typename CubatureRuleType::PointType* cub_pt = cubature.get_points();
1547 DataType* cub_wg = cubature.get_weights();
1548
1550 assemble_matrix1_cuda(matrix, convect, space, cub_pt, cub_wg, num_cubs, alpha);
1551 else
1552 assemble_matrix1_generic(matrix, convect, space, cub_pt, cub_wg, num_cubs, alpha);
1553 }
1554
1567 template<typename CubatureFactory_>
1569 const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& primal, const SpaceType& space, const CubatureFactory_& cubature_factory, DataType alpha = DataType(1)) const
1570 {
1571 XASSERTM(vector.size() == space.get_num_dofs(), "invalid vector size");
1572 XASSERTM(convect.size() == space.get_num_dofs(), "invalid vector size");
1573
1574 //define cubature
1575 typedef Cubature::Rule<ShapeType, DataType, DataType> CubatureRuleType;
1576 CubatureRuleType cubature(Cubature::ctor_factory, cubature_factory);
1577
1578 //get cubature points and weights
1579 int num_cubs = cubature.get_num_points();
1580 typename CubatureRuleType::PointType* cub_pt = cubature.get_points();
1581 DataType* cub_wg = cubature.get_weights();
1582
1584 assemble_vector_cuda(vector, convect, primal, space, cub_pt, cub_wg, num_cubs, alpha);
1585 else
1586 assemble_vector_generic(vector, convect, primal, space, cub_pt, cub_wg, num_cubs, alpha);
1587 }
1588
1595 {
1597 set_sd_v_norm_cuda(convect);
1598 else
1599 set_sd_v_norm_generic(convect);
1600 }
1601
1608 {
1610 set_sd_v_norm_cuda(convect);
1611 else
1612 set_sd_v_norm_generic(convect);
1613 }
1614
1616 const SpaceType& space, typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt, const DataType* cub_wg, int num_cubs, DataType alpha) const
1617 {
1618 //VoxelAssembly::CSRMatrixData<DataType, IndexType> mat_data = {matrix.template val<LAFEM::Perspective::pod>(), matrix.row_ptr(), matrix.col_idx(), matrix.num_rows(), matrix.num_cols()};
1619 //const DataType* vec_data = convect.template elements<LAFEM::Perspective::pod>();
1620
1621 Memory::TypedView<DataType> val_view(matrix.val_view_raw_rw());
1622 const Memory::TypedView<IndexType> row_ptr_view(matrix.row_ptr_view_r());
1623 const Memory::TypedView<IndexType> col_idx_view(matrix.col_idx_view_r());
1624 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()};
1625
1626 const Memory::TypedView<DataType> vec_view = convect.elements_view_raw_r();
1627 const DataType* vec_data = vec_view.get_r();
1628
1629 VoxelAssembly::AssemblyCubatureData<DataType> cub_data = {(void*)cub_pt, cub_wg, num_cubs};
1630 VoxelAssembly::AssemblyMappingData<DataType, IndexType> mapping_data = mesh_data.get_assembly_field();
1631 auto burgers_params = wrap_burgers_params();
1632
1633
1634 VoxelAssembly::Arch::assemble_burgers_csr_host(space, mat_data, vec_data, cub_data, mapping_data, mesh_data.coloring_data, alpha, burgers_params);
1635 }
1636
1637 void assemble_vector_generic(LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& vector, const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& convect, const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& primal,
1638 const SpaceType& space, typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt, const DataType* cub_wg, int num_cubs, DataType alpha) const
1639 {
1640 //DataType* vec_data = vector.template elements<LAFEM::Perspective::pod>();
1641 //const DataType* conv_data = convect.template elements<LAFEM::Perspective::pod>();
1642 //const DataType* primal_data = primal.template elements<LAFEM::Perspective::pod>();
1643
1644 Memory::TypedView<DataType> vec_view = vector.elements_view_raw_rw();
1645 const Memory::TypedView<DataType> conv_view = convect.elements_view_raw_r();
1646 const Memory::TypedView<DataType> primal_view = primal.elements_view_raw_r();
1647 DataType* vec_data = vec_view.get_w();
1648 const DataType* conv_data = conv_view.get_r();
1649 const DataType* primal_data = primal_view.get_r();
1650
1651 VoxelAssembly::AssemblyCubatureData<DataType> cub_data = {(void*)cub_pt, cub_wg, num_cubs};
1652 VoxelAssembly::AssemblyMappingData<DataType, IndexType> mapping_data = mesh_data.get_assembly_field();
1653 auto burgers_params = wrap_burgers_params();
1654
1655
1656 VoxelAssembly::Arch::assemble_burgers_defect_host(space, vec_data, conv_data, primal_data, cub_data, mapping_data, mesh_data.coloring_data, alpha, burgers_params);
1657 //free resources
1658 }
1659
1660 void set_sd_v_norm_generic(const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& convect)
1661 {
1662 this->sd_v_norm = VoxelAssembly::Arch::get_sd_v_norm_host(convect);
1663 }
1664
1665
1666 void set_sd_v_norm_generic(const Global::Vector<LAFEM::DenseVectorBlocked<DataType, IndexType, dim>, LAFEM::VectorMirror<DataType, IndexType>>& convect)
1667 {
1668 this->sd_v_norm = VoxelAssembly::Arch::get_sd_v_norm_host(convect);
1669 }
1670
1671 #ifdef FEAT_HAVE_CUDA
1672 void assemble_matrix1_cuda(LAFEM::SparseMatrixBCSR<DataType, IndexType, dim, dim>& matrix, const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& convect,
1673 const SpaceType& space, typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt, const DataType* cub_wg, int num_cubs, DataType alpha) const
1674 {
1675 //VoxelAssembly::CSRMatrixData<DataType, IndexType> mat_data = {matrix.template val<LAFEM::Perspective::pod>(), matrix.row_ptr(), matrix.col_idx(), matrix.num_rows(), matrix.num_cols()};
1676 //const DataType* vec_data = convect.template elements<LAFEM::Perspective::pod>();
1677 Memory::TypedView<DataType> val_view(matrix.val_view_raw_rw(Memory::Location::cuda));
1678 const Memory::TypedView<IndexType> row_ptr_view(matrix.row_ptr_view_r(Memory::Location::cuda));
1679 const Memory::TypedView<IndexType> col_idx_view(matrix.col_idx_view_r(Memory::Location::cuda));
1680 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()};
1681
1682 const Memory::TypedView<DataType> vec_view = convect.elements_view_raw_r(Memory::Location::cuda);
1683 const DataType* vec_data = vec_view.get_r();
1684
1685 // upload the cubature into the cached device buffers (if it changed) and fetch the device view;
1686 // the arbiter sources the host->device copy from its own persistent host memory, so this is
1687 // safe even though the assembly kernel below runs asynchronously (no end-of-kernel sync)
1688 this->_cub_cache.update(cub_pt, cub_wg, num_cubs);
1689 VoxelAssembly::AssemblyCubatureData<DataType> d_cub_data = this->_cub_cache.device_data();
1690 VoxelAssembly::AssemblyMappingData<DataType, IndexType> d_mapping_data = mesh_data.get_assembly_field();
1691 auto burgers_params = wrap_burgers_params();
1692
1693 VoxelAssembly::Arch::assemble_burgers_csr(space, mat_data, vec_data, d_cub_data,
1694 d_mapping_data, mesh_data.coloring_data, alpha, burgers_params,
1695 runtime_params);
1696 }
1697
1698
1699 void assemble_vector_cuda(LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& vector, const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& convect, const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& primal,
1700 const SpaceType& space, typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt, const DataType* cub_wg, int num_cubs, DataType alpha) const
1701 {
1702 //DataType* vec_data = vector.template elements<LAFEM::Perspective::pod>();
1703 //const DataType* conv_data = convect.template elements<LAFEM::Perspective::pod>();
1704 //const DataType* primal_data = primal.template elements<LAFEM::Perspective::pod>();
1705
1706 Memory::TypedView<DataType> vec_view = vector.elements_view_raw_rw(Memory::Location::cuda);
1707 const Memory::TypedView<DataType> conv_view = convect.elements_view_raw_r(Memory::Location::cuda);
1708 const Memory::TypedView<DataType> primal_view = primal.elements_view_raw_r(Memory::Location::cuda);
1709 DataType* vec_data = vec_view.get_w();
1710 const DataType* conv_data = conv_view.get_r();
1711 const DataType* primal_data = primal_view.get_r();
1712
1713 // upload the cubature into the cached device buffers (if it changed) and fetch the device view;
1714 // the arbiter sources the host->device copy from its own persistent host memory, so this is
1715 // safe even though the assembly kernel below runs asynchronously (no end-of-kernel sync)
1716 this->_cub_cache.update(cub_pt, cub_wg, num_cubs);
1717 VoxelAssembly::AssemblyCubatureData<DataType> d_cub_data = this->_cub_cache.device_data();
1718 VoxelAssembly::AssemblyMappingData<DataType, IndexType> d_mapping_data = mesh_data.get_assembly_field();
1719 auto burgers_params = wrap_burgers_params();
1720
1721 VoxelAssembly::Arch::assemble_burgers_defect(space, vec_data, conv_data, primal_data, d_cub_data, d_mapping_data,
1722 mesh_data.coloring_data, alpha, burgers_params,
1723 runtime_params);
1724 }
1725
1726 void set_sd_v_norm_cuda(const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>& convect)
1727 {
1728 this->sd_v_norm = VoxelAssembly::Arch::get_sd_v_norm(convect);
1729 }
1730
1731
1732 void set_sd_v_norm_cuda(const Global::Vector<LAFEM::DenseVectorBlocked<DataType, IndexType, dim>, LAFEM::VectorMirror<DataType, IndexType>>& convect)
1733 {
1734 this->sd_v_norm = VoxelAssembly::Arch::get_sd_v_norm(convect);
1735 }
1736
1738 void set_kernel_launch_params(int target_elements, int blocksize_)
1739 {
1740 const int max_shared_mem = int(Util::cuda_get_shared_mem_per_sm());
1741 const int max_blocks_per_sm = int(Util::cuda_get_max_blocks_per_sm());
1742 const int max_sm_per_device = int(Util::cuda_get_sm_count());
1743
1744 // const int max_shared_mem_per_block = max_shared_mem/max_blocks_per_sm;
1745
1746 // get the size of all necessary shared memory
1747 // constexpr int dim = SpaceType::ShapeType::dimension;
1748 // constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
1749 constexpr int element_size = dim*dim*int(sizeof(DataType));
1750 // TODO: this only works for simple burgers...
1751 constexpr int shared_size_nec = sizeof(VoxelAssembly::BurgersSharedDataGlobalWrapper<VoxelAssembly::SpaceHelper<SpaceType, DataType, IndexType>>) + sizeof(VoxelAssembly::BurgersSharedDataKernelWrapper<VoxelAssembly::SpaceHelper<SpaceType, DataType, IndexType>>);
1752
1753 // our kernel gets the maximal number of local blocks itself, so we just provide the best feasible memory
1754 runtime_params.shared_mem = Math::max(runtime_params.shared_mem, shared_size_nec + target_elements * element_size);
1755 // XASSERTM(runtime_params.shared_mem < 48000, "Shared mem per block to large without special opt in. To be implemented yet.");
1756 XASSERTM(runtime_params.shared_mem < max_shared_mem, "Targeted shared memory is " + stringify(runtime_params.shared_mem) + "B but Hardware only supports " + stringify(max_shared_mem) + " shared memory.");
1757 runtime_params.blocksize = blocksize_;
1758 const int max_color_sizes = int(mesh_data.coloring_data.get_max_color_size());
1759 // spawn enough thread blocks to either handle all elements of a color simultaneously or to have enough
1760 // thread blocks to have all sms working
1761 // this should be minimal, due to overhead of thread spawning...
1762 runtime_params.gridsize = std::min(int(max_color_sizes), 2*max_sm_per_device*(max_blocks_per_sm/(int(runtime_params.blocksize)/32)));
1763 }
1764
1765
1766 #else //FEAT_HAVE_CUDA
1767 void assemble_matrix1_cuda(LAFEM::SparseMatrixBCSR<DataType, IndexType, dim, dim>& DOXY(matrix), const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>&, 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
1768 {
1769 XABORTM("What in the nine hells are you doing here?");
1770 }
1771
1772 void assemble_vector_cuda(LAFEM::DenseVectorBlocked<DataType, IndexType, dim>&, const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>&, const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>&,
1773 const SpaceType&, typename Cubature::Rule<ShapeType, DataType, DataType>::PointType*, const DataType*, int, DataType) const
1774 {
1775 XABORTM("This call was logged and your local FBI agent was informed about your transgressions");
1776 }
1777
1778 void set_sd_v_norm_cuda(const LAFEM::DenseVectorBlocked<DataType, IndexType, dim>&)
1779 {
1780 XABORTM("Should not have called that....");
1781 }
1782
1783
1784 void set_sd_v_norm_cuda(const Global::Vector<LAFEM::DenseVectorBlocked<DataType, IndexType, dim>, LAFEM::VectorMirror<DataType, IndexType>>&)
1785 {
1786 XABORTM("Should not have called that....");
1787 }
1788
1789 #endif
1790
1791 }; // class VoxelBurgersAssembler<Q2StandardCube>
1792#endif
1793 }
1794}
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Datahandler for inverse coloring data.
Index get_max_color_size() const
Get max size of all colors.
static PreferredBackend get_preferred_backend()
get current preferred backend
Definition: backend.cpp:32
Cubature Rule class template.
Definition: rule.hpp:38
Global vector wrapper class template.
Definition: vector.hpp:68
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.
Handles vector prolongation, restriction and serialization.
Typed memory view class.
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
Standard Lagrange-2 Finite-Element space class template.
Definition: element.hpp:39
Index get_num_dofs() const
Returns the number of dofs.
Definition: element.hpp:121
Tiny Matrix class template.
Tiny Vector class template.
Owns the device-resident cubature (points + weights) of a voxel assembler.
AssemblyCubatureData< DT_ > device_data() const
Returns the device-side view of the cached cubature.
void update(const PointType_ *pts, const DT_ *wgs, int num_cubs)
Uploads the cubature into the cached host buffers if it changed.
Data handler for Lagrange based FE spaces.
Adjacency::ColoringDataHandler coloring_data
Datahandler for the coloring data.
void set_sd_v_norm(const LAFEM::DenseVectorBlocked< DataType, IndexType, dim > &convect)
Sets the internal maximum streamline diffusion velocity norm.
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 operator for finitie element space with same test and trial space.
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.
DataType sd_nu
Streamline diffosuion viscosity. Generally equal to nu.
VoxelBurgersAssembler(const SpaceType &space, const ColoringType_ &coloring, int hint=-1)
Constructor for burgers assembler.
void set_sd_v_norm(const Global::Vector< LAFEM::DenseVectorBlocked< DataType, IndexType, dim >, LAFEM::VectorMirror< DataType, IndexType > > &convect)
Sets the internal maximum streamline diffusion velocity norm.
VoxelAssembly::AssemblyBurgersData< DataType > wrap_burgers_params() const
Wraps the set burgers parameter into convenient struct.
DataType frechet_beta
Scaling parameter for full jacobian convection part.
Burgers Voxel Assembly template.
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
std::size_t element_size(const Pack::Type type)
Returns the size of a Pack::Type element in bytes.
Definition: pack.hpp:256
CUDA_HOST_DEVICE T_ dot(const T_ &a, const T_ &b)
Computes the dot-product of two scalars.
void assemble_burgers_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)
Host kernel wrapper for the full matrix burgers assembler.
void assemble_burgers_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)
Host kernel wrapper for the defect burgers assembler.
DT_ get_sd_v_norm_host(const LAFEM::DenseVectorBlocked< DT_, IT_, dim_ > &convect)
Host kernel wrapper for the local sd_v_norm calculation.
void assemble_burgers_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 Util::RuntimeParameter &runtime_params)
Device kernel wrapper for the defect burgers assembler.
void assemble_burgers_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 Util::RuntimeParameter &runtime_params)
Device kernel wrapper for the full matrix burgers assembler.
DT_ get_sd_v_norm(const LAFEM::DenseVectorBlocked< DT_, IT_, dim_ > &convect)
Device kernel wrapper for the local sd_v_norm calculation.
CUDA_DEVICE __forceinline__ void grouped_burgers_mat_assembly_kernel(const ThreadGroup_ &tg, BurgersSharedDataKernelWrapper< SpaceHelp_ > *shared_wrapper, int loc_assemble_size, int assemble_offset, typename SpaceHelp_::DataType *loc_mat, const typename SpaceHelp_::DataType *local_conv_dofs, const Tiny::Matrix< typename SpaceHelp_::DataType, SpaceHelp_::dim, SpaceHelp_::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_streamline, const bool need_convection, const typename SpaceHelp_::DataType tol_eps)
Burgers Matrix assembly kernel.
CUDA_HOST_DEVICE void burgers_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)
Burgers Vector assembly kernel.
CUDA_DEVICE __forceinline__ void grouped_burgers_mat_alt_assembly_kernel(const ThreadGroup_ &tg, BurgersSharedDataKernelWrapper< SpaceHelp_ > *shared_wrapper, int loc_assemble_size, int assemble_offset, typename SpaceHelp_::DataType *loc_mat, const VoxelAssembly::AssemblyBurgersData< typename SpaceHelp_::DataType > &burgers_params, const bool need_streamline, const bool need_convection, const typename SpaceHelp_::DataType tol_eps)
appears to not work better... compiler optimizes this sufficiently?
CUDA_HOST_DEVICE void burgers_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 bool need_streamline, const bool need_convection, const typename SpaceHelp_::DataType tol_eps)
Burgers Matrix assembly kernel.
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:993
@ value
specifies whether the space should supply basis function values
@ dom_point
specifies whether the trafo should supply domain point coordinates
A data field for all necessary values that define the dof mapping for assembly.
Helper struct wrapping the data required as shared data.