NiHu  2.0
laplace_double_integral.cpp
1 // This file is a part of NiHu, a C++ BEM template library.
2 //
3 // Copyright (C) 2012-2014 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2014 Peter Rucz <rucz@hit.bme.hu>
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #include <boost/math/constants/constants.hpp>
20 
22 #include "library/lib_element.hpp"
26 
28 // dynamically resizeable double matrix
29 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> dMatrix;
30 // dynamically resizeable unsigned matrix
31 typedef Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> uMatrix;
33 
35 template <class func_space>
36 void tester(func_space const &w)
37 {
38  using namespace boost::math::double_constants;
39 
40  // compute number of DOF and allocate result matrix
41  size_t nDOF = w.get_num_dofs();
42  dMatrix I(nDOF, nDOF);
43  I.setZero();
44 
45  // create integral operator from kernel and perform weighted double integral
47  I << w * K[w];
48 
49  // Display matrix elements and their sum
50  std::cout << "WR matrix:\n" << I << std::endl;
51  std::cout << "sum of elements: " << I.sum() << std::endl;
52 
53  // Compare to analytical solution
54  double anal = 32.0 * (std::log(1.0+root_two)-(root_two-1.0)/3.0) / 4.0 / pi;
55  std::cout << "log10 error = " << std::log10(std::abs(I.sum() / anal - 1.0)) << std::endl;
56 }
58 
59 
60 int main()
61 {
63  // nodal coordinates in 3D, 3 nodes
64  dMatrix nodes(4,3);
65  nodes <<
66  -1.0, -1.0, 0.0,
67  1.0, -1.0, 0.0,
68  -1.0, 1.0, 0.0,
69  1.0, 1.0, 0.0;
70 
71  // element nodal indices
72  uMatrix elements(1, 1+4);
73  elements << NiHu::quad_1_elem::id, 0, 1, 3, 2;
74 
75  // create the mesh
76  auto msh = NiHu::create_mesh(nodes, elements, NiHu::tria_1_tag(), NiHu::quad_1_tag());
78 
80  // create a piecewise constant function space and call the tester
81  std::cout << "Testing with constant field" << std::endl;
82  tester(NiHu::constant_view(msh));
83 
84  // create a piecewise linear function space and call the tester
85  std::cout << "Testing with isoparametric field" << std::endl;
86  tester(NiHu::isoparametric_view(msh));
88 
89  return 0;
90 }
91 
NiHu::create_integral_operator
integral_operator< Kernel > create_integral_operator(Kernel &&kernel)
factory function of an integral operator
Definition: integral_operator.hpp:421
NiHu::type2tag
Metafunction assigning a tag to a type.
Definition: type2tag.hpp:17
NiHu::bessel::K
make_complex< T >::type K(T const &z)
K_nu(z) modified Bessel function.
NiHu::create_mesh
mesh< tmp::vector< typename tag2type< Args >::type... > > create_mesh(nodes_t const &nodes, elements_t const &elements, Args...)
factory function to create a mesh from nodes and elements matrices
Definition: mesh.hpp:298
laplace_kernel.hpp
implementation of kernels of the Laplace equation
weighted_residual.hpp
declaration of class NiHu::weighted_residual
NiHu::mex::real_matrix
Definition: mex_matrix_separate.hpp:133
NiHu::normal_derivative_kernel
Normal derivative of a distance dependent kernel.
Definition: normal_derivative_kernel.hpp:26
lib_element.hpp