Flow123d  JS_before_hm-984-g3a19f2f
field_divide.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 field_divide.cc
15  * @brief
16  */
17 
18 #include "fields/field_divide.hh"
19 #include "fields/field_instances.hh" // for instantiation macros
20 
21 
22 template <int spacedim, class Value>
24  Field<3, FieldValue<3>::Scalar> inner_divisor, unsigned int n_comp)
25 : FieldAlgorithmBase<spacedim, Value>(n_comp),
26  inner_dividend_(inner_dividend),
27  inner_divisor_(inner_divisor)
28 {
30 }
31 
32 
33 
34 template <int spacedim, class Value>
35 typename Value::return_type const & FieldDivide<spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
36 {
37  this->r_value_ = inner_dividend_->value(p,elm);
38  double div_val = inner_divisor_.value(p,elm);
39 
40  for(unsigned int row=0; row < this->value_.n_rows(); row++)
41  for(unsigned int col=0; col < this->value_.n_cols(); col++) {
42  this->value_(row,col) /= div_val;
43  }
44 
45  return this->r_value_;
46 }
47 
48 
49 
50 /**
51  * Returns std::vector of scalar values in several points at once.
52  */
53 template <int spacedim, class Value>
56 {
57  ASSERT_EQ( point_list.size(), value_list.size() ).error();
58  ASSERT_DBG( point_list.n_rows() == spacedim && point_list.n_cols() == 1 ).error("Invalid point size.\n");
59 
60  inner_dividend_->value_list(point_list, elm, value_list);
61 
62  for(unsigned int i=0; i< point_list.size(); i++) {
63  double div_val = inner_divisor_.value(point_list.vec<spacedim>(i),elm);
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) /= div_val;
69  }
70 }
71 
72 
73 
74 template <int spacedim, class Value>
76 {
77  ASSERT_PTR(inner_dividend_).error("Null data pointer.\n");
78  bool changed = inner_divisor_.set_time(time, LimitSide::right);
79  return inner_dividend_->set_time(time) && changed;
80 }
81 
82 
83 
84 template <int spacedim, class Value>
86 }
87 
88 
89 // Instantiations of FieldConstant
91 
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Definition: field_divide.cc:35
unsigned int size() const
Definition: armor.hh:718
bool set_time(const TimeStep &time) override
Definition: field_divide.cc:75
FieldCommon & flags_add(FieldFlag::Flags::Mask mask)
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:92
FieldDivide(std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > inner_dividend, Field< 3, FieldValue< 3 >::Scalar > inner_divisor, unsigned int n_comp=0)
Definition: field_divide.cc:23
#define INSTANCE_ALL(field)
uint n_cols() const
Definition: armor.hh:710
bool set_time(const TimeStep &time, LimitSide limit_side) override
Definition: field.impl.hh:267
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:807
Value::return_type r_value_
Field< 3, FieldValue< 3 >::Scalar > inner_divisor_
Field to which we add linear potential.
Definition: field_divide.hh:64
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm) const
Definition: field.hh:434
uint n_rows() const
Definition: armor.hh:705
Space< spacedim >::Point Point
virtual void value_list(const Armor::array &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
Definition: field_divide.cc:54
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
#define ASSERT_DBG(expr)
std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > inner_dividend_
Field to which we add linear potential.
Definition: field_divide.hh:62
virtual ~FieldDivide()
Definition: field_divide.cc:85
Representation of one time step..
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328
static constexpr Mask declare_input
The field can be set from input. The key in input field descriptor is declared. (default on) ...
Definition: field_flag.hh:35