9#include <kernel/shape.hpp>
10#include <kernel/geometry/conformal_mesh.hpp>
11#include <kernel/trafo/standard/mapping.hpp>
12#include <kernel/space/lagrange2/element.hpp>
13#include <kernel/util/memory_arbiter.hpp>
20#include <cooperative_groups.h>
21#include <cooperative_groups/memcpy_async.h>
22#include <cooperative_groups/reduce.h>
24namespace cg = cooperative_groups;
40 namespace VoxelAssembly
58 template<
typename DT_,
typename IT_>
81 template<
typename DT_>
109 template<
typename DT_,
typename Po
intType_>
144 void update(
const PointType_* pts,
const DT_* wgs,
int num_cubs)
179 template<
typename DT_,
typename IT_>
194 template<
typename DT_>
207 template<
typename SpaceHelp_>
210 typedef SpaceHelp_ SpaceHelp;
211 typedef typename SpaceHelp::SpaceType SpaceType;
212 typedef typename SpaceHelp::DataType DataType;
213 typedef typename SpaceHelp::IndexType IndexType;
214 static constexpr int dim = SpaceHelp::dim;
215 static constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
216 static constexpr int num_loc_verts = SpaceHelp::num_verts;
217 DataType local_coeffs[dim*num_loc_verts];
218 DataType local_conv_dofs[dim*num_loc_dofs];
219 IndexType local_dofs[num_loc_dofs];
222 bool need_streamline;
223 bool need_convection;
226 template<
typename SpaceHelp_>
229 typedef SpaceHelp_ SpaceHelp;
230 typedef typename SpaceHelp::SpaceType SpaceType;
231 typedef typename SpaceHelp::DataType DataType;
232 typedef typename SpaceHelp::IndexType IndexType;
233 static constexpr int dim = SpaceHelp::dim;
234 static constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
235 static constexpr int num_loc_verts = SpaceHelp::num_verts;
236 DataType local_coeffs[dim*num_loc_verts];
237 DataType local_conv_dofs[dim*num_loc_dofs];
238 DataType local_prim_dofs[dim*num_loc_dofs];
239 IndexType local_dofs[num_loc_dofs];
241 bool need_convection;
245 template<
typename DT_,
int dim_>
249 for(
int k = 0; k < dim_; ++k)
251 lv += alpha *
grad[k] * conv[k];
256 template<
typename DT_,
typename TG_>
257 CUDA_DEVICE
inline void coalesced_format(
const TG_& thread_group, DT_* target,
int size)
259 for(
int i = thread_group.thread_rank(); i < size; i += thread_group.num_threads())
265 template<
typename DT_,
typename TG_,
int dim_>
266 CUDA_DEVICE
inline void grouped_special_dot(
const TG_& tg, DT_& loc_val,
const DT_ phi,
const DT_* conv, DT_ alpha = DT_(1))
268 auto coal_g = cg::coalesced_threads();
270 for(
int k = 0; k < dim_; ++k)
272 lv += alpha * phi * conv[k];
274 lv = cg::reduce(coal_g, lv, cg::plus<DT_>());
275 cg::invoke_one(coal_g, [&](){atomicAdd(&loc_val, lv);});
278 template<
typename DT_,
typename TG_,
int dim_>
279 CUDA_DEVICE
inline void grouped_dot(
const TG_& tg, DT_& loc_val,
const Tiny::Vector<DT_, dim_>&
grad,
const DT_* conv, DT_ alpha = DT_(1))
281 auto coal_g = cg::coalesced_threads();
283 for(
int k = 0; k < dim_; ++k)
285 lv += alpha *
grad[k] * conv[k];
287 lv = cg::reduce(coal_g, lv, cg::plus<DT_>());
288 cg::invoke_one(coal_g, [&](){atomicAdd(&loc_val, lv);});
291 template<
typename DT_,
typename TG_,
int dim_>
292 CUDA_DEVICE
inline void grouped_axpy(
const TG_& tg, DT_* loc_v,
const DT_ phi,
const DT_* conv, DT_ alpha = DT_(1))
294 auto coal_g = cg::coalesced_threads();
295 for(
int k = 0; k < dim_; ++k)
299 lv = cg::reduce(coal_g, alpha * phi * conv[k], cg::plus<DT_>());
300 cg::invoke_one(coal_g, [&](){atomicAdd(loc_v+k, lv);});
306 template<
typename DT_,
typename TG_,
int dim_>
307 CUDA_DEVICE
inline void grouped_add_outer_product(
const TG_& tg, DT_* loc_grad_v,
const DT_* conv,
const Tiny::Vector<DT_, dim_>&
grad, DT_ alpha = DT_(1))
309 auto coal_g = cg::coalesced_threads();
310 for(
int i(0); i < dim_; ++i)
312 for(
int j(0); j < dim_; ++j)
314 DT_ lv = cg::reduce(coal_g, alpha * conv[i] *
grad[j], cg::plus<DT_>());
315 cg::invoke_one(coal_g, [&](){atomicAdd(&loc_grad_v[i*dim_ + j], lv);});
320 template<
typename DT_>
321 CUDA_DEVICE DT_* get_aligned_address(
void* ptr)
328 constexpr std::uint64_t align =
alignof(DT_);
329 std::uint64_t ptr_a =
reinterpret_cast<std::uint64_t
>(ptr);
330 return (DT_*)((ptr_a + align - 1u)&(-align));
340 template<
typename DT_>
343 DT_ frechet_material;
351 bool need_frechet_material;
365 template<
typename DT_, MaterialType mat_type>
368 template<
typename DT_, MaterialType mat_type>
371 template<
typename DT_>
374 DT_ mu_0, exp, lambda;
376 CUDA_HOST_DEVICE DT_ operator()(DT_ gamma_dot, DT_ a_T)
const
379 return a_T * mu_0 * CudaMath::cuda_pow(DT_(1) + lambda * a_T * gamma_dot, - exp);
381 return a_T * mu_0 *
Math::pow(DT_(1) + lambda * a_T * gamma_dot, - exp);
386 template<
typename DT_>
389 DT_ mu_0, exp, lambda, a_T;
391 CUDA_HOST_DEVICE DT_ operator()(DT_ gamma_dot)
const
394 return a_T * mu_0 * CudaMath::cuda_pow(DT_(1) + lambda * a_T * gamma_dot, - exp);
396 return a_T * mu_0 *
Math::pow(DT_(1) + lambda * a_T * gamma_dot, - exp);
401 template<
typename DT_>
404 DT_ mu_0, exp, lambda, yasuda_a, mu_inf;
406 CUDA_HOST_DEVICE DT_ operator()(DT_ gamma_dot, DT_ a_T)
const
409 return a_T * mu_inf + a_T * (mu_0 - mu_inf) *
410 CudaMath::cuda_pow(DT_(1) + CudaMath::cuda_pow(lambda * a_T * gamma_dot, yasuda_a), (exp - 1) / yasuda_a);
412 return a_T * mu_inf + a_T * (mu_0 - mu_inf) *
413 Math::pow(DT_(1) +
Math::pow(lambda * a_T * gamma_dot, yasuda_a), (exp - 1) / yasuda_a);
418 template<
typename DT_>
421 DT_ mu_0, exp, lambda, a_T, yasuda_a, mu_inf;
423 CUDA_HOST_DEVICE DT_ operator()(DT_ gamma_dot)
const
426 return a_T * mu_inf + a_T * (mu_0 - mu_inf) *
427 CudaMath::cuda_pow(DT_(1) + CudaMath::cuda_pow(lambda * a_T * gamma_dot, yasuda_a), (exp - DT_(1)) / yasuda_a);
429 return a_T * mu_inf + a_T * (mu_0 - mu_inf) *
430 Math::pow(DT_(1) +
Math::pow(lambda * a_T * gamma_dot, yasuda_a), (exp - DT_(1)) / yasuda_a);
435 template<
typename DT_, MaterialType mat_type>
438 template<
typename DT_, MaterialType mat_type>
441 template<
typename DT_>
444 DT_ mu_0, exp, lambda;
446 CUDA_HOST_DEVICE DT_ operator()(DT_ gamma_dot, DT_ a_T)
const
449 return - a_T * a_T * mu_0 * lambda * exp *
450 CudaMath::cuda_pow(DT_(1) + lambda * a_T * gamma_dot, - exp - DT_(1));
452 return - a_T * a_T * mu_0 * lambda * exp *
453 Math::pow(DT_(1) + lambda * a_T * gamma_dot, - exp - DT_(1));
458 template<
typename DT_>
461 DT_ mu_0, exp, lambda, a_T;
463 CUDA_HOST_DEVICE DT_ operator()(DT_ gamma_dot)
const
466 return - a_T * a_T * mu_0 * lambda * exp *
467 CudaMath::cuda_pow(DT_(1) + lambda * a_T * gamma_dot, - exp - DT_(1));
469 return - a_T * a_T * mu_0 * lambda * exp *
470 Math::pow(DT_(1) + lambda * a_T * gamma_dot, - exp - DT_(1));
475 template<
typename DT_>
478 DT_ mu_0, exp, lambda, yasuda_a, mu_inf;
480 CUDA_HOST_DEVICE DT_ operator()(DT_ gamma_dot, DT_ a_T)
const
483 return a_T * (mu_0 - mu_inf) * ((exp-DT_(1.0)) / yasuda_a) *
484 CudaMath::cuda_pow( DT_(1.0) + CudaMath::cuda_pow(lambda * gamma_dot, yasuda_a), ((exp - DT_(1.0) - yasuda_a) / yasuda_a)) *
485 yasuda_a * lambda * a_T * CudaMath::cuda_pow(lambda * gamma_dot * a_T, yasuda_a-DT_(1.0));
487 return a_T * (mu_0 - mu_inf) * ((exp-DT_(1.0)) / yasuda_a) *
488 Math::pow( DT_(1.0) +
Math::pow(lambda * gamma_dot, yasuda_a), ((exp - DT_(1.0) - yasuda_a) / yasuda_a)) *
489 yasuda_a * lambda * a_T *
Math::pow(lambda * gamma_dot * a_T, yasuda_a-DT_(1.0));
494 template<
typename DT_>
497 DT_ mu_0, exp, lambda, a_T, yasuda_a, mu_inf;
499 CUDA_HOST_DEVICE DT_ operator()(DT_ gamma_dot)
const
502 return a_T * (mu_0 - mu_inf) * ((exp-DT_(1.0)) / yasuda_a) *
503 CudaMath::cuda_pow( DT_(1.0) + CudaMath::cuda_pow(lambda * gamma_dot, yasuda_a), ((exp - DT_(1.0) - yasuda_a) / yasuda_a)) *
504 yasuda_a * lambda * a_T * CudaMath::cuda_pow(lambda * gamma_dot * a_T, yasuda_a-DT_(1.0));
506 return a_T * (mu_0 - mu_inf) * ((exp-DT_(1.0)) / yasuda_a) *
507 Math::pow( DT_(1.0) +
Math::pow(lambda * gamma_dot, yasuda_a), ((exp - DT_(1.0) - yasuda_a) / yasuda_a)) *
508 yasuda_a * lambda * a_T *
Math::pow(lambda * gamma_dot * a_T, yasuda_a-DT_(1.0));
void copy(const Arbiter &source, Location mem_loc=Location::none)
Copies of the contents of one memory block into another one.
Standard Lagrange-2 Finite-Element space class template.
Tiny Vector class template.
Owns the device-resident cubature (points + weights) of a voxel assembler.
Memory::Arbiter _points
device/host buffer for the cubature points
int _num_cubs
number of cubature points currently cached (0 = nothing uploaded yet)
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.
Memory::Arbiter _weights
device/host buffer for the cubature weights
T_ pow(T_ x, T_ y)
Returns x raised to the power of y.
Space::Lagrange2::Element< Trafo::Standard::Mapping< Geometry::ConformalMesh< Shape::Hypercube< 3 > > > > Q2StandardHexa
Q2 hexadron space.
Space::Lagrange2::Element< Trafo::Standard::Mapping< Geometry::ConformalMesh< Shape::Hypercube< 2 > > > > Q2StandardQuad
Q2 quadliteral space.
MaterialType
Enum for different material types.
@ grad
specifies whether the space should supply basis function gradients
std::uint64_t Index
Index data type.
Data for burgers assembler.
A data field for a cubature rule.
const DT_ * cub_wg
The cubature weights.
int num_cubs
Number of cubtaure points.
const void * cub_pt
The cubature point data array.
A data field for all necessary values that define the dof mapping for assembly.
Index cell_num
The number of cells.
const Memory::Arbiter & cell_to_dof
The cell to dof, where cell_to_dof[i],..., cell_to_dof[i+cell_dofs-1] are the dofs of one cell.
const Memory::Arbiter & nodes
An array of the nodes fitting to the cell_to_dof mapping.
Index node_size
The number of nodes.
const Memory::Arbiter & cell_to_dof_sorter
Array of sortingindices of cell_to_dof.
Data for material burgers assembler.