9#include <kernel/backend.hpp>
10#include <kernel/voxel_assembly/voxel_assembly_common.hpp>
11#include <kernel/voxel_assembly/helper/data_handler.hpp>
12#include <kernel/voxel_assembly/helper/space_helper.hpp>
13#include <kernel/cubature/rule.hpp>
14#include <kernel/lafem/sparse_matrix_csr.hpp>
15#include <kernel/trafo/standard/mapping.hpp>
16#include <kernel/geometry/conformal_mesh.hpp>
17#include <kernel/util/tiny_algebra.hpp>
20#include <kernel/util/cuda_util.hpp>
25 namespace VoxelAssembly
37 template<
typename Space_,
typename DT_,
typename IT_>
46 template<
typename SpaceHelp_,
typename LocMatType_,
int dim_,
int num_verts_>
48 const typename SpaceHelp_::DomainPointType* cub_pt,
const typename SpaceHelp_::DataType* cub_wg,
const int num_cubs)
50 typedef SpaceHelp_ SpaceHelp;
52 typedef typename SpaceHelp::SpaceType SpaceType;
53 typedef typename SpaceHelp::DataType DataType;
56 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
60 typename SpaceHelp::JacobianMatrixType loc_jac, loc_jac_inv;
61 typename SpaceHelp::DomainPointType
dom_point;
62 typename SpaceHelp::EvalData basis_data;
66 for(
int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
70 SpaceHelp::calc_jac_mat(loc_jac,
dom_point, local_coeffs);
71 loc_jac_inv.set_inverse(loc_jac);
74 SpaceHelp::eval_ref_gradients(basis_data,
dom_point);
75 SpaceHelp::trans_gradients(basis_data, loc_jac_inv);
77 for(
int i = 0; i < num_loc_dofs; ++i)
79 for(
int j = 0; j < num_loc_dofs; ++j)
96 template<
typename Space_,
typename DT_,
typename IT_>
97 void assemble_poisson_csr(
const Space_& space,
98 const CSRMatrixData<DT_, IT_>& matrix_data,
99 const AssemblyCubatureData<DT_>& cubature,
100 const AssemblyMappingData<DT_, IT_>& dof_mapping,
101 const Adjacency::ColoringDataHandler& coloring_data,
106 template<
typename Space_,
typename DT_,
typename IT_>
107 void assemble_poisson_csr_host(
const Space_& space,
108 const CSRMatrixData<DT_, IT_>& matrix_data,
109 const AssemblyCubatureData<DT_>& cubature,
110 const AssemblyMappingData<DT_, IT_>& dof_mapping,
111 const Adjacency::ColoringDataHandler& coloring_data,
119 template<
int dim_,
typename DT_,
typename IT_>
127 typedef typename SpaceHelp::ShapeType ShapeType;
128 typedef typename SpaceHelp::DataType DataType;
129 typedef typename SpaceHelp::IndexType IndexType;
132 static constexpr int dim = SpaceHelp::dim;
134 typedef typename SpaceHelp::DomainPointType DomainPointType;
135 typedef typename SpaceHelp::ImagePointType ImagePointType;
136 typedef typename SpaceHelp::ValueType ValueType;
137 typedef typename SpaceHelp::JacobianMatrixType JacobianMatrixType;
142 #ifdef FEAT_HAVE_CUDA
152 template<
typename ColoringType_>
154 mesh_data(space, coloring, hint)
177 template<
typename CubatureFactory_>
180 XASSERTM(matrix.
num_rows() == space.get_num_dofs(),
"invalid matrix dimensions");
181 XASSERTM(matrix.
num_cols() == space.get_num_dofs(),
"invalid matrix dimensions");
185 CubatureRuleType cubature(Cubature::ctor_factory, cubature_factory);
188 int num_cubs = cubature.get_num_points();
189 typename CubatureRuleType::PointType* cub_pt = cubature.get_points();
190 DataType* cub_wg = cubature.get_weights();
193 assemble_matrix1_cuda(matrix, space, cub_pt, cub_wg, num_cubs, alpha);
195 assemble_matrix1_generic(matrix, space, cub_pt, cub_wg, num_cubs, alpha);
199 void assemble_matrix1_generic(LAFEM::SparseMatrixCSR<DataType, IndexType>& matrix,
const SpaceType& space,
typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt,
const DataType* cub_wg,
int num_cubs, DataType alpha)
const
201 Memory::TypedView<DataType> val_view(matrix.val_view_rw());
202 const Memory::TypedView<IndexType> row_ptr_view(matrix.row_ptr_view_r());
203 const Memory::TypedView<IndexType> col_idx_view(matrix.col_idx_view_r());
204 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()};
206 AssemblyCubatureData<DataType> cub_data = {(
void*)cub_pt, cub_wg, num_cubs};
207 AssemblyMappingData<DataType, IndexType> mapping_data = mesh_data.get_assembly_field();
210 VoxelAssembly::Arch::assemble_poisson_csr_host(space, mat_data, cub_data, mapping_data, mesh_data.
coloring_data, alpha);
213 #ifdef FEAT_HAVE_CUDA
214 void assemble_matrix1_cuda(LAFEM::SparseMatrixCSR<DataType, IndexType>& matrix,
const SpaceType& space,
typename Cubature::Rule<ShapeType, DataType, DataType>::PointType* cub_pt,
const DataType* cub_wg,
int num_cubs, DataType alpha)
const
219 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()};
224 this->_cub_cache.
update(cub_pt, cub_wg, num_cubs);
225 VoxelAssembly::AssemblyCubatureData<DataType> d_cub_data = this->_cub_cache.
device_data();
226 VoxelAssembly::AssemblyMappingData<DataType, IndexType> d_mapping_data = mesh_data.get_assembly_field();
229 VoxelAssembly::Arch::assemble_poisson_csr(space, mat_data, d_cub_data, d_mapping_data, mesh_data.
coloring_data, alpha);
233 void assemble_matrix1_cuda(LAFEM::SparseMatrixCSR<DataType, IndexType>& DOXY(matrix),
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
235 XABORTM(
"What in the nine hells are you doing here?");
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
static PreferredBackend get_preferred_backend()
get current preferred backend
Cubature Rule class template.
Index num_cols() const
Retrieve matrix column count.
Index num_rows() const
Retrieve matrix row count.
Standard Lagrange-2 Finite-Element space class template.
Tiny Matrix 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.
Q2StandardHyperCube< dim_ > SpaceType
typedefs
DataHandler mesh_data
The datahandler.
Poisson Voxel Assembly template.
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.
@ dom_point
specifies whether the trafo should supply domain point coordinates
@ jac_det
specifies whether the trafo should supply jacobian determinants