Flow123d  jenkins-Flow123d-linux-release-multijob-282
field_add_potential.impl.hh
Go to the documentation of this file.
1 /*
2  * field_add_potential.impl.hh
3  *
4  * Created on: Jan 22, 2013
5  * Author: jb
6  */
7 
8 #ifndef FIELD_ADD_POTENTIAL_IMPL_HH_
9 #define FIELD_ADD_POTENTIAL_IMPL_HH_
10 
12 
13 
14 template <int spacedim, class Value>
15 FieldAddPotential<spacedim, Value>::FieldAddPotential(const arma::vec::fixed<spacedim+1> &potential, const Input::AbstractRecord &rec, unsigned int n_comp)
16 : FieldAlgorithmBase<spacedim, Value>(n_comp),
17  inner_field_( FieldAlgorithmBase<spacedim, Value>::function_factory(rec, this->value_.n_rows()) )
18 {
19  grad_=potential.subvec(0,spacedim-1);
20  zero_level_=potential[spacedim];
21 }
22 
23 
24 
25 /**
26  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
27  */
28 template <int spacedim, class Value>
29 typename Value::return_type const & FieldAddPotential<spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
30 {
31  this->r_value_ = inner_field_->value(p,elm);
32 
33  double potential=arma::dot(grad_ , p) + zero_level_;
34  for(unsigned int row=0; row < this->value_.n_rows(); row++)
35  for(unsigned int col=0; col < this->value_.n_cols(); col++)
36  this->value_(row,col) += potential;
37 
38  return this->r_value_;
39 }
40 
41 
42 
43 /**
44  * Returns std::vector of scalar values in several points at once.
45  */
46 template <int spacedim, class Value>
49 {
50  ASSERT_EQUAL( point_list.size(), value_list.size() );
51  inner_field_->value_list(point_list, elm, value_list);
52  for(unsigned int i=0; i< point_list.size(); i++) {
53  double potential= arma::dot(grad_ , point_list[i]) + zero_level_;
54  Value envelope(value_list[i]);
55 
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  envelope(row,col) += potential;
59  }
60 }
61 
62 template <int spacedim, class Value>
64 {
65  ASSERT(inner_field_, "Null data pointer.\n");
66  return inner_field_->set_time(time);
67 }
68 
69 
70 template <int spacedim, class Value>
72 }
73 
74 
75 #endif /* FIELD_ADD_POTENTIAL_IMPL_HH_ */
bool set_time(const TimeStep &time) override
arma::vec::fixed< spacedim > grad_
Potential gradient.
FieldAddPotential(const arma::vec::fixed< spacedim+1 > &potential_grad, const Input::AbstractRecord &rec, unsigned int n_comp=0)
#define ASSERT(...)
Definition: global_defs.h:121
#define ASSERT_EQUAL(a, b)
Definition: global_defs.h:136
double zero_level_
Potential constant term.
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:448
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Representation of one time step.
Space< spacedim >::Point Point