NiHu  2.0
assembly.hpp
Go to the documentation of this file.
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 
24 #ifndef NIHU_ASSEMBLY_HPP_INCLUDED
25 #define NIHU_ASSEMBLY_HPP_INCLUDED
26 
27 #include "function_space.hpp"
28 #include "integral_operator.hpp"
29 #include "../util/matrix_block.hpp"
30 
31 namespace NiHu
32 {
33 
38 template <class TestSpace, class TrialSpace, class OnSameMesh>
39 class assembly
40 {
41 private:
48  template <class Operator, class TestField, class TrialField, bool isTrivial =
50  !std::is_same<typename TestField::elem_t, typename TrialField::elem_t>::value
51  >
52  struct eval_on_impl
53  { struct type {
61  template <class result_t>
62  void operator() (result_t &result,
64  function_space_base<TestSpace> const &test_space,
65  function_space_base<TrialSpace> const &trial_space)
66  {
68  {
69  for (auto test_it = test_space.template field_begin<TestField>();
70  test_it != test_space.template field_end<TestField>(); ++test_it)
71  for (auto trial_it = trial_space.template field_begin<TrialField>();
72  trial_it != trial_space.template field_end<TrialField>(); ++trial_it)
73  {
74  block(result, test_it->get_dofs(), trial_it->get_dofs())
75  += op.eval_on_fields(*test_it, *trial_it, OnSameMesh());
76  }
77  }
78  else // local operator
79  {
80  // we can be sure that the element types are the same and element id's are monotonic
81  auto test_it = test_space.template field_begin<TestField>();
82  auto test_end = test_space.template field_end<TestField>();
83  auto trial_it = trial_space.template field_begin<TrialField>();
84  auto trial_end = trial_space.template field_end<TrialField>();
85 
86  for (; test_it != test_end; ++test_it)
87  {
88  auto test_id = test_it->get_elem().get_id();
89  for (; trial_it != trial_end && trial_it->get_elem().get_id() < test_id; ++trial_it);
90  if (trial_it->get_elem().get_id() == test_id)
91  {
92  block(result, test_it->get_dofs(), trial_it->get_dofs())
93  += op.eval_on_fields(*test_it, *trial_it, OnSameMesh());
94  }
95  }
96  }
97  }
98  };};
99 
100 
102  template <class Operator, class TestField, class TrialField>
103  struct eval_on_impl<Operator, TestField, TrialField, true>
104  { struct type {
105  template <class result_t>
106  void operator() (
107  result_t &,
111  {
112  }
113  };};
114 
121  template <class Operator, class TestField, class TrialField>
122  struct eval_on : eval_on_impl<Operator, TestField, TrialField>
123  {
124  };
125 
126 
127 public:
136  template <class result_t, class Operator>
137  static result_t &eval_into(
138  result_t &result,
140  function_space_base<TestSpace> const &test_space,
141  function_space_base<TrialSpace> const &trial_space)
142  {
143  if(!OnSameMesh::value && integral_operator_traits<Operator>::is_local)
144  return result;
145 
146  tmp::d_call_each<
149  eval_on<Operator, tmp::_1, tmp::_2>,
150  result_t &,
154  >(result, op, test_space, trial_space);
155 
156  return result;
157  }
158 };
159 
160 }
161 
162 #endif /* NIHU_ASSEMBLY_HPP_INCLUDED */
163 
NiHu::integral_operator_base::eval_on_fields
wr_result_type< TestField, TrialField >::type eval_on_fields(field_base< TestField > const &test_field, field_base< TrialField > const &trial_field, OnSameMesh) const
sub-weighted residual on a test and a trial field
Definition: integral_operator.hpp:67
NiHu::assembly::eval_on_impl::type::operator()
void operator()(result_t &result, integral_operator_base< Operator > const &op, function_space_base< TestSpace > const &test_space, function_space_base< TrialSpace > const &trial_space)
evaluate weighted residual on homogeneous function spaces
Definition: assembly.hpp:62
NiHu::function_space_base
CRTP base class of function spaces.
Definition: function_space.hpp:44
NiHu::assembly::eval_on_impl::type
Definition: assembly.hpp:53
NiHu::block
matrix_block< Matrix, RowIndex, ColIndex > block(Matrix &matrix, RowIndex const &rows, ColIndex const &cols)
Factory function of matrix_block.
Definition: matrix_block.hpp:90
NiHu::integral_operator_traits
traits class for an integral operator
Definition: integral_operator.hpp:40
function_space.hpp
declaration of class function_space
integral_operator.hpp
declaration of class NiHu::integral_operator
NiHu::integral_operator_base
CRTP base of integral operator expressions.
Definition: integral_operator.hpp:46
NiHu::assembly::eval_into
static result_t & eval_into(result_t &result, integral_operator_base< Operator > const &op, function_space_base< TestSpace > const &test_space, function_space_base< TrialSpace > const &trial_space)
evaluate weighted residual into result matrix
Definition: assembly.hpp:137
NiHu::assembly
assemble result matrix from field wr submatrices
Definition: assembly.hpp:39
NiHu::function_space_traits
traits class of function spaces
Definition: function_space.hpp:39