operator_references.h
Go to the documentation of this file.
1 /*
2  This file is part of the Ristra portage project.
3  Please see the license file at the root of this repository, or at:
4  https://github.com/laristra/portage/blob/master/LICENSE
5 */
6 
7 #ifndef PORTAGE_SUPPORT_OPERATOR_REFERENCES_H_
8 #define PORTAGE_SUPPORT_OPERATOR_REFERENCES_H_
9 
10 #include <vector>
11 #include <cmath>
12 #include "gtest/gtest.h"
13 
15 #include "wonton/support/Point.h"
16 
17 using Wonton::Point;
18 
19 namespace Portage { namespace Meshfree { namespace reference {
20 
21 // avoid compiler confusion on 'Operator'
22 template<oper::Type type,
23  basis::Type basis_type,
24  oper::Domain domain_type>
26 
27 // reference points for different domains
28 template<oper::Domain domain>
29 constexpr std::vector<Point<oper::dimension(domain)>> points() {
30  switch (domain) {
31  case oper::Interval: return {{0}, {1}};
32  case oper::Quadrilateral: return {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
33  case oper::Triangle: return {{0, 0}, {1, 0}, {0, 1}};
34  case oper::Tetrahedron: return {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
35  case oper::Wedge: return {{0, 0, 0}, {1, 0, 0}, {0, 1, 0},
36  {0, 0, 1}, {1, 0, 1}, {0, 1, 1}};
37  case oper::Hexahedron: return {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0},
38  {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}};
39  default:
40  throw std::runtime_error("invalid domain");
41  }
42 };
43 
44 // function to shift reference points
45 template<int dim>
46 std::vector<Point<dim>> shift_points(const std::vector<Point<dim>>& points,
47  const Point<dim>& shift) {
48  auto result(points);
49  int const num_points = points.size();
50  for (int i = 0; i < num_points; i++) {
51  for (int j = 0; j < dim; j++) {
52  result[i][j] = points[i][j] + shift[j];
53  }
54  }
55  return result;
56 }
57 
58 // standard shift vectors
59 Point<1> const shift1d = {1.e8};
60 Point<2> const shift2d = {1.e8, 2.e8};
61 Point<3> const shift3d = {1.e8, 2.e8, 3.e8};
62 
63 // standard deformation vectors
64 std::vector<std::vector<double>> const matrix2 =
65  {{2.8549186535902855, -4.346198279115005},
66  {0.14208725143260595, 0.0933338790596824}};
67 
68 std::vector<std::vector<double>> const matrix3 =
69  {{3.1611889909865836, -3.1727215693209625, -2.6421056009990864},
70  {0.0636728533375156, 0.13338461548842906, -0.0839899523685015},
71  {1.4212135017018008, 0.22338659728810717, 1.4321838606591486}};
72 
73 double const determinant2 = 0.884;
74 double const determinant3 = 1.79452;
75 
76 // function to deform reference points
77 template<int dim>
78 std::vector<Point<dim>> deform_points(const std::vector<Point<dim>>& points,
79  const std::vector<std::vector<double>>& matrix) {
80  auto result(points);
81  int const num_points = points.size();
82  for (int i = 0; i < num_points; i++) {
83  for (int j = 0; j < dim; j++) {
84  result[i][j] = 0.;
85  for (int k = 0; k < dim; k++) {
86  result[i][j] += matrix[j][k] * points[i][k];
87  }
88  }
89  }
90  return result;
91 }
92 
93 // exact results for integrations of bases over different domains
94 template<int dim> using B0 = typename basis::Traits<basis::Unitary, dim>::array_t;
95 template<int dim> using B1 = typename basis::Traits<basis::Linear, dim>::array_t;
96 template<int dim> using B2 = typename basis::Traits<basis::Quadratic, dim>::array_t;
97 
98 B0<1> const unitary_interval = {1.0};
100 B0<2> const unitary_triangle = {0.5};
101 B0<3> const unitary_hexahedron = {1.0};
102 B0<3> const unitary_wedge = {0.5};
103 B0<3> const unitary_tetrahedron = {1./6.};
104 B1<1> const linear_interval = {1.0, 0.5};
105 B1<2> const linear_quadrilateral = {1.0, 0.5, 0.5};
106 B1<2> const linear_triangle = {0.5, 1./6., 1./6.};
107 B1<3> const linear_hexahedron = {1.0, 0.5, 0.5, 0.5};
108 B1<3> const linear_wedge = {0.5, 1./6., 1./6., 1./4.};
109 B1<3> const linear_tetrahedron = {1./6., 1./24., 1./24., 1./24.};
110 B2<1> const quadratic_interval = {1.0, 0.5, 1./6.};
111 B2<2> const quadratic_quadrilateral = {1.0, 0.5, 0.5, 1./6., 1./4., 1./6.};
112 B2<2> const quadratic_triangle = {0.5, 1./6., 1./6., 1./24., 1./24., 1./24.};
113 B2<3> const quadratic_tetrahedron = {1./6., 1./24., 1./24., 1./24., 1./120.,
114  1./120., 1./120., 1./120, 1./120., 1./120.};
115 
116 // apply translation operator to exact results
117 template<basis::Type type, size_t dim>
120  Point<dim> const& point) {
121  typename basis::Traits<type, dim>::array_t tex {};
122  auto tf = basis::transfactor<dim>(type, point);
123  int const num_tf = tf.size();
124 
125  for (int i = 0; i < num_tf; i++) {
126  tex[i] = 0.;
127  for (int j = 0; j < num_tf; j++) {
128  tex[i] += tf[i][j] * values[j];
129  }
130  }
131  return tex;
132 }
133 
134 }}} // namespace Portage::Meshfree::reference
135 
136 #endif
B1< 2 > const linear_triangle
Definition: operator_references.h:106
std::vector< Point< dim > > deform_points(const std::vector< Point< dim >> &points, const std::vector< std::vector< double >> &matrix)
Definition: operator_references.h:78
Definition: operator.h:26
Definition: basis.h:29
std::array< double, Traits< type, dim >::function_size > shift(Wonton::Point< dim > x, Wonton::Point< dim > y)
Definition: basis.h:116
std::vector< T > vector
Definition: portage.h:238
B0< 3 > const unitary_tetrahedron
Definition: operator_references.h:103
Point< 1 > const shift1d
Definition: operator_references.h:59
B1< 3 > const linear_wedge
Definition: operator_references.h:108
double const determinant2
Definition: operator_references.h:73
Definition: operator.h:27
double const determinant3
Definition: operator_references.h:74
B2< 1 > const quadratic_interval
Definition: operator_references.h:110
Definition: operator.h:108
Domain
Definition: operator.h:26
B0< 2 > const unitary_quadrilateral
Definition: operator_references.h:99
B0< 3 > const unitary_hexahedron
Definition: operator_references.h:101
B1< 2 > const linear_quadrilateral
Definition: operator_references.h:105
typename basis::Traits< basis::Unitary, dim >::array_t B0
Definition: operator_references.h:94
B0< 2 > const unitary_triangle
Definition: operator_references.h:100
B2< 3 > const quadratic_tetrahedron
Definition: operator_references.h:113
B0< 1 > const unitary_interval
Definition: operator_references.h:98
B0< 3 > const unitary_wedge
Definition: operator_references.h:102
std::vector< std::vector< double > > const matrix3
Definition: operator_references.h:68
Type
Definition: basis.h:20
basis::Traits< type, dim >::array_t make_translated_exact(typename basis::Traits< type, dim >::array_t const &values, Point< dim > const &point)
Definition: operator_references.h:119
B1< 3 > const linear_tetrahedron
Definition: operator_references.h:109
B1< 3 > const linear_hexahedron
Definition: operator_references.h:107
typename basis::Traits< basis::Quadratic, dim >::array_t B2
Definition: operator_references.h:96
Type
Definition: operator.h:30
std::vector< Point< dim > > shift_points(const std::vector< Point< dim >> &points, const Point< dim > &shift)
Definition: operator_references.h:46
Definition: operator.h:28
Definition: coredriver.h:42
typename basis::Traits< basis::Linear, dim >::array_t B1
Definition: operator_references.h:95
Definition: operator.h:28
constexpr std::vector< Point< oper::dimension(domain)> > points()
Definition: operator_references.h:29
Point< 2 > const shift2d
Definition: operator_references.h:60
std::vector< std::vector< double > > const matrix2
Definition: operator_references.h:64
B2< 2 > const quadratic_quadrilateral
Definition: operator_references.h:111
Point< 3 > const shift3d
Definition: operator_references.h:61
B1< 1 > const linear_interval
Definition: operator_references.h:104
Definition: operator.h:28
B2< 2 > const quadratic_triangle
Definition: operator_references.h:112