1 #ifndef POLYNOMIAL_BASIS_HPP
2 #define POLYNOMIAL_BASIS_HPP
10 View<double***, CLayout, Device>
f;
13 :
f(
"f", n_poly, n_poly, n){}
18 template<
class Device>
25 View<double***, CLayout, Device>
bases;
26 View<double***, CLayout, HostType>
bases_h;
27 View<double****, CLayout, Device>
matrix;
74 int nnode = dist_in.extent(0);
75 View<double***, CLayout, Device> inner_prod_matrix(
"inner_prod_matrix",
n_poly,
n_poly, nnode);
79 Kokkos::parallel_for(
"inner_product", Kokkos::RangePolicy<exec_space>(0,nnode), KOKKOS_LAMBDA(
const int inode ){
80 for (
int iy = 0; iy < pb.
yrange.
n; iy++) {
81 for (
int ix = 0; ix < pb.
xrange.
n; ix++) {
82 double w = dist_in(inode, ix, iy);
84 for(
int ip = 0; ip<pb.
n_poly; ip++){
85 for(
int jp=ip; jp<pb.
n_poly; jp++){
86 inner_prod_matrix(ip, jp, inode) += w*pb.
matrix(ip, jp, ix, iy);
93 for(
int ip = 0; ip<pb.
n_poly; ip++){
94 for(
int jp=ip+1; jp<pb.
n_poly; jp++){
95 inner_prod_matrix(jp, ip, inode) = inner_prod_matrix(ip, jp, inode);
100 double den = inner_prod_matrix(0,0,inode);
101 for(
int i=0; i<pb.
n_poly; i++){
102 for(
int j=0; j<pb.
n_poly; j++){
103 inner_prod_matrix(i,j,inode) /= den;
108 return inner_prod_matrix;
116 int nnode = inner_prod_matrix.extent(2);
119 View<double**, CLayout, Device> norm(
"norm",
n_poly, nnode);
122 Kokkos::parallel_for(
"get_coeffs", Kokkos::RangePolicy<exec_space>(0,nnode), KOKKOS_LAMBDA(
const int inode ){
124 polynom.
f(0, 0, inode) = 1.0;
125 for (
int j=0; j<pb.
n_poly; j++) {
126 double sum_value = 0.0;
127 for (
int k = 0; k < pb.
n_poly; k++) {
128 sum_value += polynom.
f(k, 0, inode) * inner_prod_matrix(k, j, inode);
130 norm(0, inode) += polynom.
f(j, 0, inode) * sum_value;
134 for (
int i = 1; i<pb.
n_poly; i++){
135 polynom.
f(i, i, inode) = 1.0;
136 for (
int j = i-1; j >= 0; j--) {
137 double sum_value = 0.0;
138 for (
int k = 0; k < pb.
n_poly; ++k) {
139 sum_value += inner_prod_matrix(k, i, inode) * polynom.
f(k, j, inode);
141 for (
int l = 0; l < pb.
n_poly; ++l) {
142 polynom.
f(l, i, inode) -= sum_value / norm(j, inode) * polynom.
f(l, j, inode);
145 for (
int j = 0; j < pb.
n_poly; j++) {
146 double sum_value = 0.0;
147 for (
int k = 0; k < pb.
n_poly; ++k) {
148 sum_value += polynom.
f(k, i, inode) * inner_prod_matrix(k, j, inode);
150 norm(i, inode) += polynom.
f(j, i, inode) * sum_value;
154 for (
int i = 0; i < pb.
n_poly; i++) {
155 double norm_sqrt = sqrt(norm(i, inode));
156 for (
int j = 0; j < pb.
n_poly; j++) {
157 polynom.
f(j, i, inode) /= norm_sqrt;
177 bases_h(basis_ind, i, j) = func(x, y);
191 template<
typename... Fs>
205 View<double****, CLayout, HostType> matrix_h(
NoInit(
"matrix_h"),
matrix.layout());
206 for(
int ip=0; ip<
n_poly; ip++){
207 for(
int jp=ip; jp<
n_poly; jp++){
216 Kokkos::deep_copy(
matrix, matrix_h);
235 inline View<double**, CLayout, Device>
get_moments(
const int nnode, F lambda_func)
const{
236 const View<double**, CLayout, Device> g_mom(
NoInit(
"g_mom"),
n_poly, nnode);
238 Kokkos::parallel_for(
"get_moments", Kokkos::RangePolicy<exec_space>(0,nnode), KOKKOS_LAMBDA(
const int inode ){
239 lambda_func(inode, g_mom);
259 int nnode = polynom.
f.extent(2);
260 View<double***, CLayout, Device> scaling(
"scaling", nnode,
xrange.
n,
yrange.
n);
261 View<double**, CLayout, Device> D_k(
"D_k",
n_poly, nnode);
264 Kokkos::parallel_for(
"get_scaling", Kokkos::RangePolicy<exec_space>(0,nnode), KOKKOS_LAMBDA(
const int inode ){
266 for (
int i = 0; i < pb.
n_poly; i++) {
267 for (
int j = 0; j < pb.
n_poly; j++) {
268 for (
int k = 0; k < pb.
n_poly; k++) {
269 double c2 = polynom.
f(j,i,inode)*polynom.
f(k,i,inode);
270 D_k(k,inode) += g_mom(j,inode)*c2;
277 for (
int iy = 0; iy < pb.
yrange.
n; iy++) {
278 for (
int ix = 0; ix < pb.
xrange.
n; ix++) {
280 for(
int ip=0; ip<pb.
n_poly; ip++){
281 fac += D_k(ip,inode)*pb.
bases(ip,ix,iy);
283 scaling(inode, ix, iy) = fac;
PolynomialBasisDistribution< Device > get_distribution(const View< double ***, CLayout, Device > &dist_in) const
Definition: poly_basis.hpp:223
PolynomialBasis(const UniformRange &xrange_in, const UniformRange &yrange_in, Fs...funcs)
Definition: poly_basis.hpp:192
View< double ***, CLayout, Device > f
Definition: poly_basis.hpp:10
View< double ***, CLayout, Device > get_scaling(const PolynomialBasisDistribution< Device > &polynom, const View< double **, CLayout, Device > &g_mom) const
Definition: poly_basis.hpp:258
typename Device::execution_space exec_space
Definition: poly_basis.hpp:20
View< double ***, CLayout, Device > bases
Definition: poly_basis.hpp:25
PolynomialBasisDistribution(int n_poly, int n)
Definition: poly_basis.hpp:12
View< double **, CLayout, Device > get_moments(const int nnode, F lambda_func) const
Definition: poly_basis.hpp:235
int n_poly
Definition: poly_basis.hpp:22
PolynomialBasisDistribution< Device > get_coefficients(const View< double ***, CLayout, Device > &inner_prod_matrix) const
Definition: poly_basis.hpp:115
void add_basis(int &basis_ind, F func)
Definition: poly_basis.hpp:171
View< double ***, CLayout, Device > compute_inner_product(const View< double ***, CLayout, Device > &dist_in) const
Definition: poly_basis.hpp:73
Definition: poly_basis.hpp:19
Definition: poly_basis.hpp:9
UniformRange yrange
Definition: poly_basis.hpp:24
UniformRange xrange
Definition: poly_basis.hpp:23
void parallel_for(const std::string name, int n_ptl, Function func, Option option, HostAoSoA aosoa_h, DeviceAoSoA aosoa_d)
Definition: streamed_parallel_for.hpp:252
View< double ****, CLayout, Device > matrix
Definition: poly_basis.hpp:27
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:69
View< double ***, CLayout, HostType > bases_h
Definition: poly_basis.hpp:26