FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
defo_assembler.cpp
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#include <kernel/voxel_assembly/defo_assembler.hpp>
7#include <kernel/lafem/matrix_gather_scatter_helper.hpp>
8
9namespace FEAT
10{
11 namespace VoxelAssembly
12 {
13 namespace Kernel
14 {
15
16 template<typename Space_, typename DT_, typename IT_, FEAT::Intern::MatrixGatherScatterPolicy pol_ = FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>
17 void defo_assembler_matrix1_csr_host(DT_* matrix_data,
18 const IT_* matrix_row_ptr, const IT_* matrix_col_idx, Index matrix_num_rows, Index matrix_num_cols,
20 const DT_* cub_wg, int num_cubs, DT_ alpha,
21 const IT_* cell_to_dof, [[maybe_unused]] Index cell_num,
22 const Tiny::Vector<DT_, Space_::world_dim>* nodes, [[maybe_unused]] Index node_size,
23 const int* coloring_map, Index coloring_size,
24 const IT_* cell_to_dof_sorter, DT_ nu)
25 {
26 // define types
27 typedef Space_ SpaceType;
28 typedef DT_ DataType;
29 typedef IT_ IndexType;
30
32
33 constexpr int dim = SpaceHelp::dim;
34
35 // define local sizes
36 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
37 // get number of nodes per element
38 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
39 //our local datatypes
40 // typedef Tiny::Vector<DataType, dim> VecValueType;
41 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
42 // typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
44
45
46
47 FEAT_PRAGMA_OMP(parallel for)
48 for(Index idx = 0; idx < coloring_size; ++idx)
49 {
50 // define local coefficients
52 // and local matrix
53 LocalMatrixType loc_mat;
54 // now do work for this cell
55 IndexType cell = IndexType(coloring_map[idx]);
56 // std::cout << "Starting with cell " << cell << "\n";
57 const IndexSetWrapper<IndexType> local_dofs_w{cell_to_dof, IndexType(num_loc_dofs)};
58 const IndexType* local_dofs = cell_to_dof + cell*num_loc_dofs;
59 const IndexType* local_dof_sorter = cell_to_dof_sorter + cell*num_loc_dofs;
60
61 SpaceHelp::set_coefficients(local_coeffs, local_dofs_w, nodes, cell);
62
63 // To minimize code repetition, we call the same kernel from cuda and non cuda build...
64 VoxelAssembly::Kernel::defo_assembly_kernel<SpaceHelp, LocalMatrixType>(loc_mat, local_coeffs, cub_pt, cub_wg, num_cubs, nu);
65
66 // scatter
67 LAFEM::template MatrixGatherScatterHelper<SpaceType, DataType, IndexType, pol_>::scatter_matrix_csr(loc_mat, (MatValueType*)matrix_data, local_dofs, local_dofs, IndexType(matrix_num_rows), IndexType(matrix_num_cols), matrix_row_ptr, matrix_col_idx, alpha, local_dof_sorter);
68 }
69 }
70 }
71
72 namespace Arch
73 {
74 template<typename Space_, typename DT_, typename IT_>
75 void assemble_defo_csr_host([[maybe_unused]] const Space_& space,
76 const CSRMatrixData<DT_, IT_>& matrix_data,
77 const AssemblyCubatureData<DT_>& cubature,
78 const AssemblyMappingData<DT_, IT_>& dof_mapping,
79 const Adjacency::ColoringDataHandler& coloring_data,
80 DT_ alpha, DT_ nu)
81 {
82 const Memory::TypedView<int> coloring_view = coloring_data.color_map_view(Memory::Location::main, Memory::Access::read);
86
87 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
88 {
89 VoxelAssembly::Kernel::template defo_assembler_matrix1_csr_host<Space_, DT_, IT_, FEAT::Intern::MatrixGatherScatterPolicy::useLocalSortHelper>(
90 matrix_data.data, matrix_data.row_ptr, matrix_data.col_idx, matrix_data.num_rows, matrix_data.num_cols,
91 (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
92 cubature.cub_wg, cubature.num_cubs, alpha, cell_to_dof_view.get_r(), dof_mapping.cell_num,
93 nodes_view.get_r(), dof_mapping.node_size,
94 &coloring_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col),
95 cell_to_dof_sorter_view.get_r(), nu
96 );
97 }
98 }
99 }
100 }
101}
102
103//instantiate the templates
104using namespace FEAT;
105using namespace FEAT::VoxelAssembly;
106
107
108/*--------------------Defo Assembler Q2Quad-------------------------------------------------*/
109template void Arch::assemble_defo_csr_host(const Q2StandardQuad&, const CSRMatrixData<double, std::uint32_t>&, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
110 const Adjacency::ColoringDataHandler&, double, double);
111template void Arch::assemble_defo_csr_host(const Q2StandardQuad&, const CSRMatrixData<float, std::uint32_t>&, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
112 const Adjacency::ColoringDataHandler&, float, float);
113template void Arch::assemble_defo_csr_host(const Q2StandardQuad&, const CSRMatrixData<double, std::uint64_t>&, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
114 const Adjacency::ColoringDataHandler&, double, double);
115template void Arch::assemble_defo_csr_host(const Q2StandardQuad&, const CSRMatrixData<float, std::uint64_t>&, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
116 const Adjacency::ColoringDataHandler&, float, float);
117
118
119/*---------------------Defo Assembler Q2Hexa------------------------------------------------------*/
120template void Arch::assemble_defo_csr_host(const Q2StandardHexa&, const CSRMatrixData<double, std::uint32_t>&, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
121 const Adjacency::ColoringDataHandler&, double, double);
122template void Arch::assemble_defo_csr_host(const Q2StandardHexa&, const CSRMatrixData<float, std::uint32_t>&, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
123 const Adjacency::ColoringDataHandler&, float, float);
124template void Arch::assemble_defo_csr_host(const Q2StandardHexa&, const CSRMatrixData<double, std::uint64_t>&, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
125 const Adjacency::ColoringDataHandler&, double, double);
126template void Arch::assemble_defo_csr_host(const Q2StandardHexa&, const CSRMatrixData<float, std::uint64_t>&, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
127 const Adjacency::ColoringDataHandler&, float, float);
Datahandler for inverse coloring data.
Index get_num_colors() const
Returns the number of colors.
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
Typed memory view class.
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
Standard Lagrange-2 Finite-Element space class template.
Definition: element.hpp:39
Tiny Matrix class template.
Tiny Vector class template.
@ read
read-only access
Namespace for different voxel based assembly methods.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.
const void * cub_pt
The cubature point data array.
A data field for all necessary values that define the dof mapping for assembly.
const Memory::Arbiter & cell_to_dof
The cell to dof, where cell_to_dof[i],..., cell_to_dof[i+cell_dofs-1] are the dofs of one cell.
const Memory::Arbiter & nodes
An array of the nodes fitting to the cell_to_dof mapping.
const Memory::Arbiter & cell_to_dof_sorter
Array of sortingindices of cell_to_dof.