Flow123d  release_3.0.0-1075-gba2c39a
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 /**
36  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
37  */
38 template <int spacedim, class Value>
39 typename Value::return_type const & FieldAddPotential<spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
40 {
41  this->r_value_ = inner_field_->value(p,elm);
42 
43  double potential=arma::dot(grad_ , p) + zero_level_;
44  for(unsigned int row=0; row < this->value_.n_rows(); row++)
45  for(unsigned int col=0; col < this->value_.n_cols(); col++)
46  this->value_(row,col) += potential;
47 
48  return this->r_value_;
49 }
50 
51 
52 
53 /**
54  * Returns std::vector of scalar values in several points at once.
55  */
56 template <int spacedim, class Value>
59 {
60  ASSERT_EQ( point_list.size(), value_list.size() ).error();
61  inner_field_->value_list(point_list, elm, value_list);
62  for(unsigned int i=0; i< point_list.size(); i++) {
63  double potential= arma::dot(grad_ , point_list[i]) + zero_level_;
64  Value envelope(value_list[i]);
65 
66  for(unsigned int row=0; row < this->value_.n_rows(); row++)
67  for(unsigned int col=0; col < this->value_.n_cols(); col++)
68  envelope(row,col) += potential;
69  }
70 }
71 
72 template <int spacedim, class Value>
74 {
75  ASSERT_PTR(inner_field_).error("Null data pointer.\n");
76  return inner_field_->set_time(time);
77 }
78 
79 
80 template <int spacedim, class Value>
81 void FieldAddPotential<spacedim, Value>::set_mesh(const Mesh *mesh, bool boundary_domain)
82 {
83  ASSERT_PTR(inner_field_).error("Null data pointer.\n");
84  return inner_field_->set_mesh(mesh, boundary_domain);
85 }
86 
87 
88 template <int spacedim, class Value>
90 }
91 
92 
93 #endif /* FIELD_ADD_POTENTIAL_IMPL_HH_ */
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:76
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
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.
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:459
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:335
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
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:327