Flow123d  JS_before_hm-1623-gd361259
field_add_potential.impl.hh
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 field_add_potential.impl.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_ADD_POTENTIAL_IMPL_HH_
19 #define FIELD_ADD_POTENTIAL_IMPL_HH_
20 
22 
23 
24 template <int spacedim, class Value>
25 FieldAddPotential<spacedim, Value>::FieldAddPotential(const arma::vec::fixed<spacedim+1> &potential, const Input::AbstractRecord &rec, unsigned int n_comp)
26 : FieldAlgorithmBase<spacedim, Value>(n_comp),
27  inner_field_( FieldAlgorithmBase<spacedim, Value>::function_factory(rec, FieldAlgoBaseInitData(rec.type().type_name(), this->value_.n_rows(), UnitSI::dimensionless())) )
28 {
29  grad_=potential.subvec(0,spacedim-1);
30  zero_level_=potential[spacedim];
31 }
32 
33 
34 
35 template <int spacedim, class Value>
36 FieldAddPotential<spacedim, Value>::FieldAddPotential(const arma::vec::fixed<spacedim+1> &potential,
37  std::shared_ptr< FieldAlgorithmBase<spacedim, Value> > inner_field, unsigned int n_comp)
38 : FieldAlgorithmBase<spacedim, Value>(n_comp),
39  inner_field_( inner_field )
40 {
41  grad_=potential.subvec(0,spacedim-1);
42  zero_level_=potential[spacedim];
43 }
44 
45 
46 
47 /**
48  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
49  */
50 template <int spacedim, class Value>
51 typename Value::return_type const & FieldAddPotential<spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
52 {
53  this->r_value_ = inner_field_->value(p,elm);
54 
55  double potential=arma::dot(grad_ , p) + zero_level_;
56  for(unsigned int row=0; row < this->value_.n_rows(); row++)
57  for(unsigned int col=0; col < this->value_.n_cols(); col++)
58  this->value_(row,col) += potential;
59 
60  return this->r_value_;
61 }
62 
63 
64 
65 /**
66  * Returns std::vector of scalar values in several points at once.
67  */
68 template <int spacedim, class Value>
71 {
72  ASSERT_EQ( point_list.size(), value_list.size() ).error();
73  ASSERT_DBG( point_list.n_rows() == spacedim && point_list.n_cols() == 1 ).error("Invalid point size.\n");
74  inner_field_->value_list(point_list, elm, value_list);
75  for(unsigned int i=0; i< point_list.size(); i++) {
76  double potential= arma::dot(grad_ , point_list.vec<spacedim>(i)) + zero_level_;
77  Value envelope(value_list[i]);
78 
79  for(unsigned int row=0; row < this->value_.n_rows(); row++)
80  for(unsigned int col=0; col < this->value_.n_cols(); col++)
81  envelope(row,col) += potential;
82  }
83 }
84 
85 template <int spacedim, class Value>
87 {
88  ASSERT_PTR(inner_field_).error("Null data pointer.\n");
89  return inner_field_->set_time(time);
90 }
91 
92 
93 template <int spacedim, class Value>
94 void FieldAddPotential<spacedim, Value>::set_mesh(const Mesh *mesh, bool boundary_domain)
95 {
96  ASSERT_PTR(inner_field_).error("Null data pointer.\n");
97  return inner_field_->set_mesh(mesh, boundary_domain);
98 }
99 
100 
101 template <int spacedim, class Value>
103 }
104 
105 
106 #endif /* FIELD_ADD_POTENTIAL_IMPL_HH_ */
unsigned int size() const
Definition: armor.hh:728
void set_mesh(const Mesh *mesh, bool boundary_domain) override
Implements FieldAlgirithmBase::set_mesh.
bool set_time(const TimeStep &time) override
arma::vec::fixed< spacedim > grad_
Potential gradient.
Definition: mesh.h:77
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
uint n_cols() const
Definition: armor.hh:720
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:821
FieldAddPotential(const arma::vec::fixed< spacedim+1 > &potential_grad, const Input::AbstractRecord &rec, unsigned int n_comp=0)
Value::return_type r_value_
double zero_level_
Potential constant term.
uint n_rows() const
Definition: armor.hh:715
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:458
Value value_
Last value, prevents passing large values (vectors) by value.
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
Definition: asserts.hh:336
virtual void value_list(const Armor::array &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
#define ASSERT_DBG(expr)
Class for representation SI units of Fields.
Definition: unit_si.hh:40
std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > inner_field_
Field to which we add linear potential.
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Representation of one time step..
Space< spacedim >::Point Point
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328
unsigned int n_comp() const