Flow123d  DF_patch_fe_data_tables-92632e6
eval_points.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file eval_points.cc
15  * @brief
16  * @author David Flanderka
17  */
18 
19 #include "fields/eval_points.hh"
20 #include "fields/eval_subset.hh"
21 #include "quadrature/quadrature.hh"
22 #include "mesh/ref_element.hh"
23 #include <memory>
24 
25 
26 const unsigned int EvalPoints::undefined_dim = 10;
27 
29 : dim_eval_points_({DimEvalPoints(0), DimEvalPoints(1), DimEvalPoints(2), DimEvalPoints(3)}), max_size_(0)
30 {}
31 
32 template <unsigned int dim>
33 std::shared_ptr<BulkIntegral> EvalPoints::add_bulk(const Quadrature &quad)
34 {
35  return get_bulk_integral<dim>(quad);
36 }
37 
38 template <unsigned int dim>
39 std::shared_ptr<EdgeIntegral> EvalPoints::add_edge(const Quadrature &quad)
40 {
41  return get_edge_integral<dim>(quad);;
42 }
43 
44 template <unsigned int dim>
45 std::shared_ptr<CouplingIntegral> EvalPoints::add_coupling(const Quadrature &quad) {
46  ASSERT_EQ(dim, quad.dim()+1);
47 
48  std::shared_ptr<BulkIntegral> bulk_integral = this->get_bulk_integral<dim-1>(quad);
49  DebugOut() << "coupling bulk subset" << bulk_integral->get_subset_idx();
50  std::shared_ptr<EdgeIntegral> edge_integral = this->get_edge_integral<dim>(quad);
51  DebugOut() << "coupling edge subset" << edge_integral->get_subset_idx();
52  return std::make_shared<CouplingIntegral>(edge_integral, bulk_integral);
53 }
54 
55 template <unsigned int dim>
56 std::shared_ptr<BoundaryIntegral> EvalPoints::add_boundary(const Quadrature &quad) {
57  ASSERT_EQ(dim, quad.dim()+1);
58 
59  std::shared_ptr<BulkIntegral> bulk_integral = this->get_bulk_integral<dim-1>(quad);
60  DebugOut() << "boundary bulk subset: " << bulk_integral->get_subset_idx()
61  << "begin: " << subset_begin(dim-1, bulk_integral->get_subset_idx());
62  std::shared_ptr<EdgeIntegral> edge_integral = this->get_edge_integral<dim>(quad);
63  DebugOut() << "boundary edge subset" << edge_integral->get_subset_idx();
64  return std::make_shared<BoundaryIntegral>(edge_integral, bulk_integral);
65 }
66 
67 template <unsigned int dim>
68 std::shared_ptr<BulkIntegral> EvalPoints::get_bulk_integral(const Quadrature &quad) {
69  ASSERT_EQ(dim, quad.dim());
70 
71  if (bulk_integrals_[dim] == nullptr) {
72  dim_eval_points_[dim].add_local_points<dim>( quad.get_points() );
73  uint i_subset = dim_eval_points_[dim].add_subset();
74  bulk_integrals_[dim] = std::make_shared<BulkIntegral>(shared_from_this(), dim, i_subset);
75  this->set_max_size();
76  }
77  return bulk_integrals_[dim];
78 }
79 
80 template <>
81 std::shared_ptr<BulkIntegral> EvalPoints::get_bulk_integral<0>(const Quadrature &quad)
82 {
83  ASSERT_EQ(0, quad.dim());
84 
85  if (bulk_integrals_[0] == nullptr) {
86  uint i_subset = dim_eval_points_[0].add_subset();
87  bulk_integrals_[0] = std::make_shared<BulkIntegral>(shared_from_this(), 0, i_subset);
88  this->set_max_size();
89  }
90  return bulk_integrals_[0];
91 }
92 
93 template <unsigned int dim>
94 std::shared_ptr<EdgeIntegral> EvalPoints::get_edge_integral(const Quadrature &quad) {
95  ASSERT_EQ(dim, quad.dim()+1);
96 
97  if (edge_integrals_[dim-1] == nullptr) {
98  for (unsigned int i=0; i<dim+1; ++i) { // sides
99  Quadrature high_dim_q = quad.make_from_side<dim>(i);
100  dim_eval_points_[dim].add_local_points<dim>( high_dim_q.get_points() );
101  }
102  uint i_subset = dim_eval_points_[dim].add_subset();
103  edge_integrals_[dim-1] = std::make_shared<EdgeIntegral>(shared_from_this(), dim, i_subset);
104  this->set_max_size();
105  }
106  return edge_integrals_[dim-1];
107 }
108 
110 : local_points_(dim), n_subsets_(0), dim_(dim)
111 {
112  subset_starts_[0] = 0;
114 }
115 
116 template <unsigned int dim>
118  ASSERT_GT(dim, 0).error("Dimension 0 not supported!\n");
119  unsigned int local_points_old_size = local_points_.size();
120  local_points_.resize(quad_points.size() + local_points_old_size);
121  for (unsigned int i=0; i<quad_points.size(); ++i) {
122  //DebugOut() << "add i: " << i << " : " << quad_points.vec<dim>(i);
123 
124  local_points_.set(i+local_points_old_size) = quad_points.vec<dim>(i);
125  }
126 }
127 
128 
130  ASSERT_LT(n_subsets_, EvalPoints::max_subsets).error("Maximal number of subsets exceeded!\n");
131 
132  n_subsets_++;
133  subset_starts_[n_subsets_] = this->size();
134  return n_subsets_ - 1;
135 }
136 
137 
138 template std::shared_ptr<BulkIntegral> EvalPoints::add_bulk<0>(const Quadrature &);
139 template std::shared_ptr<BulkIntegral> EvalPoints::add_bulk<1>(const Quadrature &);
140 template std::shared_ptr<BulkIntegral> EvalPoints::add_bulk<2>(const Quadrature &);
141 template std::shared_ptr<BulkIntegral> EvalPoints::add_bulk<3>(const Quadrature &);
142 template std::shared_ptr<EdgeIntegral> EvalPoints::add_edge<1>(const Quadrature &);
143 template std::shared_ptr<EdgeIntegral> EvalPoints::add_edge<2>(const Quadrature &);
144 template std::shared_ptr<EdgeIntegral> EvalPoints::add_edge<3>(const Quadrature &);
145 template std::shared_ptr<CouplingIntegral> EvalPoints::add_coupling<2>(const Quadrature &);
146 template std::shared_ptr<CouplingIntegral> EvalPoints::add_coupling<3>(const Quadrature &);
147 template std::shared_ptr<BoundaryIntegral> EvalPoints::add_boundary<1>(const Quadrature &);
148 template std::shared_ptr<BoundaryIntegral> EvalPoints::add_boundary<2>(const Quadrature &);
149 template std::shared_ptr<BoundaryIntegral> EvalPoints::add_boundary<3>(const Quadrature &);
150 template std::shared_ptr<BulkIntegral> EvalPoints::get_bulk_integral<0>(const Quadrature &);
151 template std::shared_ptr<BulkIntegral> EvalPoints::get_bulk_integral<1>(const Quadrature &);
152 template std::shared_ptr<BulkIntegral> EvalPoints::get_bulk_integral<2>(const Quadrature &);
153 template std::shared_ptr<BulkIntegral> EvalPoints::get_bulk_integral<3>(const Quadrature &);
154 template std::shared_ptr<EdgeIntegral> EvalPoints::get_edge_integral<1>(const Quadrature &);
155 template std::shared_ptr<EdgeIntegral> EvalPoints::get_edge_integral<2>(const Quadrature &);
156 template std::shared_ptr<EdgeIntegral> EvalPoints::get_edge_integral<3>(const Quadrature &);
157 template void EvalPoints::DimEvalPoints::add_local_points<1>(const Armor::Array<double> &);
158 template void EvalPoints::DimEvalPoints::add_local_points<2>(const Armor::Array<double> &);
159 template void EvalPoints::DimEvalPoints::add_local_points<3>(const Armor::Array<double> &);
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:301
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
#define ASSERT_GT(a, b)
Definition of comparative assert macro (Greater Than) only for debug mode.
Definition: asserts.hh:317
void reinit(uint size)
Definition: armor.hh:746
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:869
unsigned int size() const
Definition: armor.hh:776
Subobject holds evaluation points data of one dimension (0,1,2,3)
Definition: eval_points.hh:120
std::array< int, EvalPoints::max_subsets+1 > subset_starts_
Indices of subsets data in local_points_ vector, used size is n_subsets_ + 1.
Definition: eval_points.hh:174
DimEvalPoints(unsigned int dim)
Constructor.
Definition: eval_points.cc:109
uint add_subset()
Adds new subset and its end size to subset_starts_ array.
Definition: eval_points.cc:129
Armor::Array< double > local_points_
Local coords of points vector.
Definition: eval_points.hh:173
void add_local_points(const Armor::Array< double > &quad_points)
Adds set of local point to local_points_ (bulk or side).
Definition: eval_points.cc:117
std::shared_ptr< BulkIntegral > get_bulk_integral(const Quadrature &quad)
Create BulkIntegral of appropriate dimension if doesn't exist and return its.
Definition: eval_points.cc:68
int subset_begin(unsigned int dim, unsigned int idx) const
Return begin index of appropriate subset data.
Definition: eval_points.hh:70
void set_max_size()
Definition: eval_points.hh:179
std::shared_ptr< CouplingIntegral > add_coupling(const Quadrature &)
The same as add_bulk but for points between side points of element of dim and bulk points of element ...
Definition: eval_points.cc:45
static const unsigned int undefined_dim
Undefined dimension of new (empty) object.
Definition: eval_points.hh:46
unsigned int size(unsigned int dim) const
Return size of evaluation points object (number of points).
Definition: eval_points.hh:58
std::shared_ptr< BoundaryIntegral > add_boundary(const Quadrature &)
The same as add_bulk but for edge points on boundary sides.
Definition: eval_points.cc:56
std::array< std::shared_ptr< EdgeIntegral >, 3 > edge_integrals_
EdgeIntegral objects of dimension 1,2,3.
Definition: eval_points.hh:199
static const unsigned int max_subset_points
Maximal average number of points hold in subset.
Definition: eval_points.hh:52
std::shared_ptr< BulkIntegral > add_bulk(const Quadrature &)
Definition: eval_points.cc:33
std::array< std::shared_ptr< BulkIntegral >, 4 > bulk_integrals_
BulkIntegral objects of dimension 0,1,2,3.
Definition: eval_points.hh:196
std::shared_ptr< EdgeIntegral > add_edge(const Quadrature &)
The same as add_bulk but for edge points on sides.
Definition: eval_points.cc:39
std::array< DimEvalPoints, 4 > dim_eval_points_
Sub objects of dimensions 0,1,2,3.
Definition: eval_points.hh:193
static constexpr unsigned int max_subsets
Maximal number of hold subsets.
Definition: eval_points.hh:49
std::shared_ptr< EdgeIntegral > get_edge_integral(const Quadrature &quad)
Create EdgeIntegral of appropriate dimension if doesn't exist and return its.
Definition: eval_points.cc:94
EvalPoints()
Constructor.
Definition: eval_points.cc:28
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
Quadrature make_from_side(unsigned int sid) const
Definition: quadrature.cc:47
const Armor::Array< double > & get_points() const
Return a reference to the whole array of quadrature points.
Definition: quadrature.hh:99
unsigned int dim() const
Definition: quadrature.hh:72
#define DebugOut()
Macro defining 'debug' record of log.
Definition: logger.hh:284
unsigned int uint
Basic definitions of numerical quadrature rules.
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.