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