Flow123d  JS_before_hm-2154-g185f171e0
field_coords.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_coords.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_COORDS_HH_
19 #define FIELD_COORDS_HH_
20 
21 #include "fields/field_common.hh" // for FieldCommon::T...
22 #include "fields/field_value_cache.hh" // for FieldValueCache
23 #include "fields/eval_points.hh" // for EvalPoints
24 #include "fem/mapping_p1.hh"
25 #include "mesh/ref_element.hh"
26 #include "mesh/point.hh" // for Point
27 
28 template <int spacedim> class ElementAccessor;
29 
30 namespace IT=Input::Type;
31 
32 
33 /**
34  * Specialized field represents coordinate variables ('x', 'y', 'z') of FieldFormula.
35  */
36 class FieldCoords : public FieldCommon {
37 public:
38  typedef typename Space<3>::Point Point;
39 
40  /// Constructor
42  : value_cache_( FieldValueCache<double>(3, 1) )
43  {
44  this->multifield_ = false;
45  unsigned int cache_size = 1.1 * CacheMapElementNumber::get();
46  value_cache_.reinit(cache_size);
47  value_cache_.resize(cache_size);
48  this->set_shape(3, 1);
49  }
50 
52  ASSERT(false).error("This method can't be used for FieldCoords");
53 
54  IT::Abstract abstract = IT::Abstract();
56  return inst;
57  }
58 
60  ASSERT(false).error("This method can't be used for FieldCoords");
61 
62  IT::Array arr = IT::Array( IT::Integer() );
63  return arr;
64  }
65 
66  void set_mesh(const Mesh &mesh) override {
67  shared_->mesh_ = &mesh;
68  }
69 
70  bool is_constant(FMT_UNUSED Region reg) override {
71  return false;
72  }
73 
74  bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override {
75  return false;
76  }
77 
78  void copy_from(FMT_UNUSED const FieldCommon & other) override {
79  ASSERT(false).error("Forbidden method for FieldCoords!");
80  }
81 
82  void field_output(FMT_UNUSED std::shared_ptr<OutputTime> stream, FMT_UNUSED OutputTime::DiscreteSpace type) override {
83  ASSERT(false).error("Forbidden method for FieldCoords!");
84  }
85 
86  void observe_output(FMT_UNUSED std::shared_ptr<Observe> observe) override {
87  ASSERT(false).error("Forbidden method for FieldCoords!");
88  }
89 
90  FieldResult field_result(FMT_UNUSED RegionSet region_set) const override {
91  return result_none;
92  }
93 
94  std::string get_value_attribute() const override {
95  double limit = std::numeric_limits<double>::max();
96  return fmt::format("{{ \"shape\": [ 3, 1 ], \"type\": \"Double\", \"limit\": [ {}, {} ] }}", -limit, +limit);
97  }
98 
100  {}
101 
102  /// Implements FieldCommon::cache_allocate
103  void cache_reallocate(FMT_UNUSED const ElementCacheMap &cache_map, FMT_UNUSED unsigned int region_idx) const override
104  {}
105 
106  /// Implements FieldCommon::cache_update
107  void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override {
108  std::shared_ptr<EvalPoints> eval_points = cache_map.eval_points();
109  unsigned int reg_chunk_begin = cache_map.region_chunk_begin(region_patch_idx);
110  unsigned int reg_chunk_end = cache_map.region_chunk_end(region_patch_idx);
111  unsigned int region_idx = cache_map.eval_point_data(reg_chunk_begin).i_reg_;
112  unsigned int last_element_idx = -1;
113  ElementAccessor<3> elm;
114  arma::vec3 coords;
115  unsigned int dim = 0;
116 
117  const MeshBase *mesh; // Holds bulk or boundary mesh by region_idx
118  if (region_idx%2 == 1) mesh = shared_->mesh_;
119  else mesh = shared_->mesh_->bc_mesh();
120 
121  for (unsigned int i_data = reg_chunk_begin; i_data < reg_chunk_end; ++i_data) { // i_eval_point_data
122  unsigned int elm_idx = cache_map.eval_point_data(i_data).i_element_;
123  if (elm_idx != last_element_idx) {
124  elm = mesh->element_accessor( elm_idx );
125  dim = elm.dim();
126  last_element_idx = elm_idx;
127  }
128 
129  unsigned int i_point = cache_map.eval_point_data(i_data).i_eval_point_;
130  switch (dim) {
131  case 0:
132  coords = *elm.node(0);
133  break;
134  case 1:
135  coords = MappingP1<1,3>::project_unit_to_real(RefElement<1>::local_to_bary(eval_points->local_point<1>(i_point)),
137  break;
138  case 2:
139  coords = MappingP1<2,3>::project_unit_to_real(RefElement<2>::local_to_bary(eval_points->local_point<2>(i_point)),
141  break;
142  case 3:
143  coords = MappingP1<3,3>::project_unit_to_real(RefElement<3>::local_to_bary(eval_points->local_point<3>(i_point)),
145  break;
146  default:
147  coords = arma::vec3("0 0 0"); //Should not happen
148  }
149  value_cache_.set(i_data) = coords;
150  }
151  }
152 
153  /// Implements FieldCommon::value_cache
155  return &value_cache_;
156  }
157 
158  /// Implements FieldCommon::value_cache
159  const FieldValueCache<double> * value_cache() const override {
160  return &value_cache_;
161  }
162 
163  /// Implements FieldCommon::set_dependency().
164  std::vector<const FieldCommon *> set_dependency(FMT_UNUSED FieldSet &field_set, FMT_UNUSED unsigned int i_reg) const override {
166  }
167 
168  /// Returns one value of coordinates in one given point @p.
169  inline arma::vec3 const & value(const Point &p, FMT_UNUSED const ElementAccessor<3> &elm) const
170  {
171  return p;
172  }
173 
174  inline void value_list(const Armor::array &point_list, const ElementAccessor<3> &elm,
176  {
177  ASSERT_DBG(point_list.n_rows() == 3 && point_list.n_cols() == 1).error("Invalid point size.\n");
178  ASSERT_EQ_DBG(point_list.size(), value_list.size()).error("Different size of point list and value list.\n");
179 
180  for (uint i=0; i<point_list.size(); ++i)
181  value_list[i] = this->value(point_list.template vec<3>(i), elm);
182  }
183 
184  /// Return item of @p value_cache_ given by i_cache_point.
185  arma::vec3 operator[] (unsigned int i_cache_point) const
186  {
187  return this->value_cache_.template vec<3>(i_cache_point);
188  }
189 
190 private:
191  /**
192  * Field value data cache
193  *
194  * See implementation of Field<spacedim, Value>::value_cache_
195  */
197 };
198 
199 #endif /* FIELD_COORDS_HH_ */
result_none
@ result_none
Definition: field_algo_base.hh:71
Space::Point
Armor::ArmaVec< double, spacedim > Point
Definition: point.hh:42
EvalPointData::i_element_
unsigned int i_element_
mesh_idx of ElementAccessor appropriate to element
Definition: field_value_cache.hh:74
ElementAccessor::dim
unsigned int dim() const
Definition: accessors.hh:191
FieldCommon::shared_
std::shared_ptr< SharedData > shared_
Definition: field_common.hh:657
FieldCoords::value_list
void value_list(const Armor::array &point_list, const ElementAccessor< 3 > &elm, std::vector< arma::vec3 > &value_list) const
Definition: field_coords.hh:174
FieldCoords
Definition: field_coords.hh:36
FieldCoords::value_cache
const FieldValueCache< double > * value_cache() const override
Implements FieldCommon::value_cache.
Definition: field_coords.hh:159
CacheMapElementNumber::get
static unsigned int get()
Return number of stored elements.
Definition: field_value_cache.hh:93
FieldCoords::Point
Space< 3 >::Point Point
Definition: field_coords.hh:38
EvalPointData::i_eval_point_
unsigned int i_eval_point_
index of point in EvalPoint object
Definition: field_value_cache.hh:75
ref_element.hh
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
FieldCoords::value_cache
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Definition: field_coords.hh:154
FieldCoords::cache_update
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
Definition: field_coords.hh:107
RefElement
Definition: ref_element.hh:339
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
FieldCommon::set_shape
void set_shape(uint n_rows, uint n_cols)
Definition: field_common.hh:557
FieldCoords::get_value_attribute
std::string get_value_attribute() const override
Definition: field_coords.hh:94
point.hh
Input::Type::Integer
Class for declaration of the integral input data.
Definition: type_base.hh:483
ElementCacheMap
Directing class of FieldValueCache.
Definition: field_value_cache.hh:151
eval_points.hh
ASSERT_DBG
#define ASSERT_DBG(expr)
Definition: include_fadbad.hh:28
FieldResult
FieldResult
Definition: field_algo_base.hh:70
FieldCommon::mesh
const Mesh * mesh() const
Definition: field_common.hh:286
std::vector
Definition: doxy_dummy_defs.hh:7
ElementAccessor
Definition: dh_cell_accessor.hh:32
FieldCoords::cache_reallocate
void cache_reallocate(FMT_UNUSED const ElementCacheMap &cache_map, FMT_UNUSED unsigned int region_idx) const override
Implements FieldCommon::cache_allocate.
Definition: field_coords.hh:103
arma::vec3
Definition: doxy_dummy_defs.hh:17
ASSERT_EQ_DBG
#define ASSERT_EQ_DBG(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:332
uint
unsigned int uint
Definition: mh_dofhandler.hh:101
fmt::format
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
FieldCoords::value_cache_
FieldValueCache< double > value_cache_
Definition: field_coords.hh:196
ElementCacheMap::eval_point_data
const EvalPointData & eval_point_data(unsigned int point_idx) const
Return item of eval_point_data_ specified by its position.
Definition: field_value_cache.hh:274
Armor::Array::n_rows
uint n_rows() const
Definition: armor.hh:715
Region
Definition: region.hh:146
ElementCacheMap::region_chunk_end
unsigned int region_chunk_end(unsigned int region_patch_idx) const
Return end position of region chunk in FieldValueCache.
Definition: field_value_cache.hh:257
MappingP1::project_unit_to_real
static RealPoint project_unit_to_real(const BaryPoint &point, const ElementMap &map)
Definition: mapping_p1.cc:85
FieldCoords::set_input_list
void set_input_list(FMT_UNUSED const Input::Array &list, FMT_UNUSED const TimeGovernor &tg) override
Definition: field_coords.hh:99
EvalPointData::i_reg_
unsigned int i_reg_
region_idx of element
Definition: field_value_cache.hh:73
FieldCommon::multifield_
bool multifield_
Definition: field_common.hh:703
FieldCoords::operator[]
arma::vec3 operator[](unsigned int i_cache_point) const
Return item of value_cache_ given by i_cache_point.
Definition: field_coords.hh:185
TimeStep
Representation of one time step..
Definition: time_governor.hh:123
TimeGovernor
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Definition: time_governor.hh:317
MeshBase::element_accessor
ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:866
ElementCacheMap::eval_points
std::shared_ptr< EvalPoints > eval_points() const
Getter of eval_points object.
Definition: field_value_cache.hh:193
FieldCommon
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:76
FieldCoords::FieldCoords
FieldCoords()
Constructor.
Definition: field_coords.hh:41
Input::Type::Abstract
Class for declaration of polymorphic Record.
Definition: type_abstract.hh:62
Input::Type::Instance
Helper class that stores data of generic types.
Definition: type_generic.hh:89
FieldCoords::set_mesh
void set_mesh(const Mesh &mesh) override
Definition: field_coords.hh:66
LimitSide
LimitSide
Definition: field_common.hh:63
FieldCoords::copy_from
void copy_from(FMT_UNUSED const FieldCommon &other) override
Definition: field_coords.hh:78
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
Armor::Array::n_cols
uint n_cols() const
Definition: armor.hh:720
ElementAccessor::node
NodeAccessor< 3 > node(unsigned int ni) const
Definition: accessors.hh:233
FieldCoords::field_output
void field_output(FMT_UNUSED std::shared_ptr< OutputTime > stream, FMT_UNUSED OutputTime::DiscreteSpace type) override
Definition: field_coords.hh:82
Armor::Array::size
unsigned int size() const
Definition: armor.hh:728
Input::Type
Definition: balance.hh:41
ElementCacheMap::region_chunk_begin
unsigned int region_chunk_begin(unsigned int region_patch_idx) const
Return begin position of region chunk in FieldValueCache.
Definition: field_value_cache.hh:251
Mesh
Definition: mesh.h:355
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
Input::Array
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
MeshBase
Base class for Mesh and BCMesh.
Definition: mesh.h:96
FieldCoords::field_result
FieldResult field_result(FMT_UNUSED RegionSet region_set) const override
Definition: field_coords.hh:90
field_value_cache.hh
MappingP1
Affine mapping between reference and actual cell.
Definition: mapping_p1.hh:58
FieldCoords::value
const arma::vec3 & value(const Point &p, FMT_UNUSED const ElementAccessor< 3 > &elm) const
Returns one value of coordinates in one given point .
Definition: field_coords.hh:169
FieldCoords::get_input_type
IT::Instance get_input_type() override
Definition: field_coords.hh:51
Armor::Array
Definition: armor.hh:597
FieldCoords::get_multifield_input_type
IT::Array get_multifield_input_type() override
Definition: field_coords.hh:59
OutputTime::DiscreteSpace
DiscreteSpace
Definition: output_time.hh:108
mapping_p1.hh
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell.
FieldCoords::set_dependency
std::vector< const FieldCommon * > set_dependency(FMT_UNUSED FieldSet &field_set, FMT_UNUSED unsigned int i_reg) const override
Implements FieldCommon::set_dependency().
Definition: field_coords.hh:164
std::list
Definition: doxy_dummy_defs.hh:9
FieldCoords::is_constant
bool is_constant(FMT_UNUSED Region reg) override
Definition: field_coords.hh:70
FieldCommon::time
double time() const
Definition: field_common.hh:299
FieldCoords::observe_output
void observe_output(FMT_UNUSED std::shared_ptr< Observe > observe) override
Definition: field_coords.hh:86
field_common.hh
FMT_UNUSED
#define FMT_UNUSED
Definition: posix.h:75
FieldCoords::set_time
bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override
Definition: field_coords.hh:74