Flow123d  JS_before_hm-1621-g63a12c7
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 
27 namespace IT=Input::Type;
28 
29 
30 /**
31  * Specialized field represents coordinate variables ('x', 'y', 'z') of FieldFormula.
32  */
33 class FieldCoords : public FieldCommon {
34 public:
35 
36  /// Constructor
38  : value_cache_( FieldValueCache<double>(3, 1) )
39  {
40  this->multifield_ = false;
41  unsigned int cache_size = 1.1 * CacheMapElementNumber::get();
42  value_cache_.reinit(cache_size);
43  value_cache_.resize(cache_size);
44  this->set_shape(3, 1);
45  }
46 
48  ASSERT(false).error("This method can't be used for FieldCoords");
49 
50  IT::Abstract abstract = IT::Abstract();
52  return inst;
53  }
54 
56  ASSERT(false).error("This method can't be used for FieldCoords");
57 
58  IT::Array arr = IT::Array( IT::Integer() );
59  return arr;
60  }
61 
62  void set_mesh(const Mesh &mesh) override {
63  this->mesh_ = &mesh;
64  }
65 
66  bool is_constant(FMT_UNUSED Region reg) override {
67  return false;
68  }
69 
70  bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override {
71  return false;
72  }
73 
74  void copy_from(FMT_UNUSED const FieldCommon & other) override {
75  ASSERT(false).error("Forbidden method for FieldCoords!");
76  }
77 
78  void field_output(FMT_UNUSED std::shared_ptr<OutputTime> stream) override {
79  ASSERT(false).error("Forbidden method for FieldCoords!");
80  }
81 
82  void observe_output(FMT_UNUSED std::shared_ptr<Observe> observe) override {
83  ASSERT(false).error("Forbidden method for FieldCoords!");
84  }
85 
86  FieldResult field_result(FMT_UNUSED RegionSet region_set) const override {
87  return result_none;
88  }
89 
90  std::string get_value_attribute() const override {
91  double limit = std::numeric_limits<double>::max();
92  return fmt::format("{{ \"shape\": [ 3, 1 ], \"type\": \"Double\", \"limit\": [ {}, {} ] }}", -limit, +limit);
93  }
94 
96  {}
97 
98  /// Implements FieldCommon::cache_allocate
99  void cache_reallocate(FMT_UNUSED const ElementCacheMap &cache_map, FMT_UNUSED unsigned int region_idx) const override
100  {}
101 
102  /// Implements FieldCommon::cache_update
103  void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override {
104  std::shared_ptr<EvalPoints> eval_points = cache_map.eval_points();
105  unsigned int reg_chunk_begin = cache_map.region_chunk_begin(region_patch_idx);
106  unsigned int reg_chunk_end = cache_map.region_chunk_end(region_patch_idx);
107  unsigned int last_element_idx = -1;
108  ElementAccessor<3> elm;
109  arma::vec3 coords;
110  unsigned int dim = 0;
111 
112  for (unsigned int i_data = reg_chunk_begin; i_data < reg_chunk_end; ++i_data) { // i_eval_point_data
113  unsigned int elm_idx = cache_map.eval_point_data(i_data).i_element_;
114  if (elm_idx != last_element_idx) {
115  elm = mesh_->element_accessor( elm_idx );
116  dim = elm.dim();
117  last_element_idx = elm_idx;
118  }
119 
120  unsigned int i_point = cache_map.eval_point_data(i_data).i_eval_point_;
121  switch (dim) {
122  case 0:
123  coords = *elm.node(0);
124  break;
125  case 1:
126  coords = MappingP1<1,3>::project_unit_to_real(RefElement<1>::local_to_bary(eval_points->local_point<1>(i_point)),
128  break;
129  case 2:
130  coords = MappingP1<2,3>::project_unit_to_real(RefElement<2>::local_to_bary(eval_points->local_point<2>(i_point)),
132  break;
133  case 3:
134  coords = MappingP1<3,3>::project_unit_to_real(RefElement<3>::local_to_bary(eval_points->local_point<3>(i_point)),
136  break;
137  default:
138  coords = arma::vec3("0 0 0"); //Should not happen
139  }
140  value_cache_.set(i_data) = coords;
141  }
142  }
143 
144  /// Implements FieldCommon::value_cache
146  return &value_cache_;
147  }
148 
149  /// Implements FieldCommon::value_cache
150  const FieldValueCache<double> * value_cache() const override {
151  return &value_cache_;
152  }
153 
154  /// Implements FieldCommon::set_dependency().
155  std::vector<const FieldCommon *> set_dependency(FMT_UNUSED FieldSet &field_set, FMT_UNUSED unsigned int i_reg) const override {
157  }
158 
159 private:
160  /**
161  * Field value data cache
162  *
163  * See implementation of Field<spacedim, Value>::value_cache_
164  */
166 
167  const Mesh *mesh_; ///< Pointer to the mesh.
168 };
169 
170 #endif /* FIELD_COORDS_HH_ */
unsigned int region_chunk_begin(unsigned int region_patch_idx) const
Return begin position of region chunk in FieldValueCache.
void observe_output(FMT_UNUSED std::shared_ptr< Observe > observe) override
Definition: field_coords.hh:82
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:74
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
const FieldValueCache< double > * value_cache() const override
Implements FieldCommon::value_cache.
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
std::string get_value_attribute() const override
Definition: field_coords.hh:90
static unsigned int get()
Return number of stored elements.
IT::Instance get_input_type() override
Definition: field_coords.hh:47
void copy_from(FMT_UNUSED const FieldCommon &other) override
Definition: field_coords.hh:74
unsigned int i_element_
mesh_idx of ElementAccessor appropriate to element
const EvalPointData & eval_point_data(unsigned int point_idx) const
Return item of eval_point_data_ specified by its position.
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
FieldValueCache< double > value_cache_
Directing class of FieldValueCache.
Definition: mesh.h:77
Helper class that stores data of generic types.
Definition: type_generic.hh:89
FieldCoords()
Constructor.
Definition: field_coords.hh:37
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
Class for declaration of the integral input data.
Definition: type_base.hh:483
Basic time management functionality for unsteady (and steady) solvers (class Equation).
NodeAccessor< 3 > node(unsigned int ni) const
Definition: accessors.hh:200
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
Class for declaration of inputs sequences.
Definition: type_base.hh:339
virtual ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:921
void set_input_list(FMT_UNUSED const Input::Array &list, FMT_UNUSED const TimeGovernor &tg) override
Definition: field_coords.hh:95
double time() const
#define FMT_UNUSED
Definition: posix.h:75
void set_mesh(const Mesh &mesh) override
Definition: field_coords.hh:62
unsigned int region_chunk_end(unsigned int region_patch_idx) const
Return end position of region chunk in FieldValueCache.
void set_shape(uint n_rows, uint n_cols)
Affine mapping between reference and actual cell.
Definition: mapping_p1.hh:58
unsigned int i_eval_point_
index of point in EvalPoint object
Class for declaration of polymorphic Record.
IT::Array get_multifield_input_type() override
Definition: field_coords.hh:55
const Mesh * mesh_
Pointer to the mesh.
FieldResult
std::shared_ptr< EvalPoints > eval_points() const
Getter of eval_points object.
const Mesh * mesh() const
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
unsigned int dim() const
Definition: accessors.hh:157
static RealPoint project_unit_to_real(const BaryPoint &point, const ElementMap &map)
Definition: mapping_p1.cc:85
std::vector< const FieldCommon * > set_dependency(FMT_UNUSED FieldSet &field_set, FMT_UNUSED unsigned int i_reg) const override
Implements FieldCommon::set_dependency().
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:99
void field_output(FMT_UNUSED std::shared_ptr< OutputTime > stream) override
Definition: field_coords.hh:78
Representation of one time step..
bool is_constant(FMT_UNUSED Region reg) override
Definition: field_coords.hh:66
LimitSide
Definition: field_common.hh:61
FieldResult field_result(FMT_UNUSED RegionSet region_set) const override
Definition: field_coords.hh:86
bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override
Definition: field_coords.hh:70