Flow123d  master-e663071
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( 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_ */
FieldAddPotential::value
virtual const Value::return_type & value(const Point &p, const ElementAccessor< spacedim > &elm)
Definition: field_add_potential.impl.hh:51
FieldAddPotential::set_mesh
void set_mesh(const Mesh *mesh, bool boundary_domain) override
Implements FieldAlgirithmBase::set_mesh.
Definition: field_add_potential.impl.hh:94
field_add_potential.hh
FieldAddPotential::set_time
bool set_time(const TimeStep &time) override
Definition: field_add_potential.impl.hh:86
ASSERT
#define ASSERT(expr)
Definition: asserts.hh:351
Armor::Array::vec
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:821
FieldAddPotential::grad_
arma::vec::fixed< spacedim > grad_
Potential gradient.
Definition: field_add_potential.hh:163
std::vector
Definition: doxy_dummy_defs.hh:7
ElementAccessor
Definition: dh_cell_accessor.hh:32
Armor::Array::n_rows
uint n_rows() const
Definition: armor.hh:715
FieldAddPotential::FieldAddPotential
FieldAddPotential(const arma::vec::fixed< spacedim+1 > &potential_grad, const Input::AbstractRecord &rec, unsigned int n_comp=0)
Definition: field_add_potential.impl.hh:25
FieldAddPotential::zero_level_
double zero_level_
Potential constant term.
Definition: field_add_potential.hh:165
FieldAlgoBaseInitData
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
Definition: field_algo_base.hh:81
TimeStep
Representation of one time step..
Definition: time_governor.hh:123
Input::AbstractRecord
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:458
UnitSI
Class for representation SI units of Fields.
Definition: unit_si.hh:40
ASSERT_EQ
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
FieldAddPotential::~FieldAddPotential
virtual ~FieldAddPotential()
Definition: field_add_potential.impl.hh:102
Armor::Array::n_cols
uint n_cols() const
Definition: armor.hh:720
Armor::Array::size
unsigned int size() const
Definition: armor.hh:728
Value
@ Value
Definition: finite_element.hh:43
Mesh
Definition: mesh.h:362
FieldAddPotential::value_list
virtual void value_list(const Armor::array &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
Definition: field_add_potential.impl.hh:69
FieldAlgorithmBase
Definition: field_algo_base.hh:112
Armor::Array< double >
FieldAddPotential::Point
Space< spacedim >::Point Point
Definition: field_add_potential.hh:94
ASSERT_PTR
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR) only for debug mode.
Definition: asserts.hh:341