Flow123d  3.9.1-60c7e5c
field_depth.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_depth.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_DEPTH_HH_
19 #define FIELD_DEPTH_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 "fields/field_coords.hh"
25 #include "fields/surface_depth.hh"
26 #include "fem/mapping_p1.hh"
27 #include "mesh/ref_element.hh"
28 
29 namespace IT=Input::Type;
30 
31 
32 /**
33  * Specialized field represents surface depth ('d' variable) of FieldFormula.
34  */
35 class FieldDepth : public FieldCommon {
36 public:
37 
38  /// Constructor
40  : value_cache_( FieldValueCache<double>(1, 1) ), surface_depth_(nullptr)
41  {
42  this->multifield_ = false;
43  unsigned int cache_size = CacheMapElementNumber::get();
44  value_cache_.reinit(cache_size);
45  value_cache_.resize(cache_size);
46  this->set_shape(1, 1);
47  }
48 
50  ASSERT_PERMANENT(false).error("This method can't be used for FieldDepth");
51 
52  IT::Abstract abstract = IT::Abstract();
54  return inst;
55  }
56 
58  ASSERT_PERMANENT(false).error("This method can't be used for FieldDepth");
59 
60  IT::Array arr = IT::Array( IT::Integer() );
61  return arr;
62  }
63 
64  void set_mesh(const Mesh &mesh) override {
65  shared_->mesh_ = &mesh;
66  }
67 
68  bool is_constant(FMT_UNUSED Region reg) override {
69  return false;
70  }
71 
72  bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override {
73  return false;
74  }
75 
76  void copy_from(FMT_UNUSED const FieldCommon & other) override {
77  ASSERT_PERMANENT(false).error("Forbidden method for FieldCoords!");
78  }
79 
80  void field_output(FMT_UNUSED std::shared_ptr<OutputTime> stream, FMT_UNUSED OutputTime::DiscreteSpace type) override {
81  ASSERT_PERMANENT(false).error("Forbidden method for FieldCoords!");
82  }
83 
84  void observe_output(FMT_UNUSED std::shared_ptr<Observe> observe) override {
85  ASSERT_PERMANENT(false).error("Forbidden method for FieldCoords!");
86  }
87 
88  FieldResult field_result(FMT_UNUSED RegionSet region_set) const override {
89  return result_none;
90  }
91 
92  std::string get_value_attribute() const override {
93  double limit = std::numeric_limits<double>::max();
94  return fmt::format("{{ \"shape\": [ 1, 1 ], \"type\": \"Double\", \"limit\": [ {}, {} ] }}", -limit, +limit);
95  }
96 
98  {}
99 
100  /// Implements FieldCommon::cache_allocate
101  void cache_reallocate(FMT_UNUSED const ElementCacheMap &cache_map, FMT_UNUSED unsigned int region_idx) const override
102  {}
103 
104  /// Implements FieldCommon::cache_update
105  void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override {
106  if (surface_depth_ == nullptr) return;
107 
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  auto * coords_cache = field_coords_->value_cache();
112  arma::vec3 p; // evaluated point
113 
114  for (unsigned int i_data = reg_chunk_begin; i_data < reg_chunk_end; ++i_data) { // i_eval_point_data
115  p = coords_cache->template vec<3>(i_data);
116  value_cache_.set(i_data) = surface_depth_->compute_distance(p);
117  }
118  }
119 
120  /// Implements FieldCommon::value_cache
122  return &value_cache_;
123  }
124 
125  /// Implements FieldCommon::value_cache
126  const FieldValueCache<double> * value_cache() const override {
127  return &value_cache_;
128  }
129 
130  /// Implements FieldCommon::set_dependency().
131  std::vector<const FieldCommon *> set_dependency(FMT_UNUSED FieldSet &field_set, FMT_UNUSED unsigned int i_reg) const override {
133  res.push_back(field_coords_);
134  return res;
135  }
136 
137  /// Setter of surface_depth data member
138  inline void set_surface_depth(std::shared_ptr<SurfaceDepth> surface_depth) {
139  surface_depth_ = surface_depth;
140  }
141 
142  /// Setter of field_coords data member
143  inline void set_field_coords(FieldCoords * field_coords) {
144  field_coords_ = field_coords;
145  }
146 
147 private:
148  /**
149  * Field value data cache
150  *
151  * See implementation of Field<spacedim, Value>::value_cache_
152  */
154 
155  /// Surface depth object calculate distance from surface.
156  std::shared_ptr<SurfaceDepth> surface_depth_;
157 
158  FieldCoords * field_coords_; ///< Pointer to coordinates field.
159 };
160 
161 #endif /* FIELD_DEPTH_HH_ */
result_none
@ result_none
Definition: field_algo_base.hh:71
surface_depth.hh
FieldCommon::shared_
std::shared_ptr< SharedData > shared_
Definition: field_common.hh:657
FieldCoords
Definition: field_coords.hh:36
CacheMapElementNumber::get
static unsigned int get()
Return number of stored elements.
Definition: field_value_cache.hh:93
FieldDepth::value_cache
const FieldValueCache< double > * value_cache() const override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:126
ref_element.hh
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
FieldDepth::get_multifield_input_type
IT::Array get_multifield_input_type() override
Definition: field_depth.hh:57
FieldDepth::cache_update
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
Definition: field_depth.hh:105
FieldCoords::value_cache
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Definition: field_coords.hh:154
FieldDepth
Definition: field_depth.hh:35
FieldCommon::set_shape
void set_shape(uint n_rows, uint n_cols)
Definition: field_common.hh:557
FieldDepth::value_cache_
FieldValueCache< double > value_cache_
Definition: field_depth.hh:153
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
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
arma::vec3
Definition: doxy_dummy_defs.hh:17
fmt::format
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
Region
Definition: region.hh:145
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:272
FieldCommon::multifield_
bool multifield_
Definition: field_common.hh:703
ASSERT_PERMANENT
#define ASSERT_PERMANENT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:348
FieldDepth::field_coords_
FieldCoords * field_coords_
Pointer to coordinates field.
Definition: field_depth.hh:158
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
ElementCacheMap::eval_points
std::shared_ptr< EvalPoints > eval_points() const
Getter of eval_points object.
Definition: field_value_cache.hh:193
FieldDepth::set_input_list
void set_input_list(FMT_UNUSED const Input::Array &list, FMT_UNUSED const TimeGovernor &tg) override
Definition: field_depth.hh:97
FieldCommon
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:76
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
FieldDepth::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_depth.hh:131
LimitSide
LimitSide
Definition: field_common.hh:63
FieldSet
Container for various descendants of FieldCommonBase.
Definition: field_set.hh:159
FieldDepth::get_value_attribute
std::string get_value_attribute() const override
Definition: field_depth.hh:92
FieldDepth::field_result
FieldResult field_result(FMT_UNUSED RegionSet region_set) const override
Definition: field_depth.hh:88
FieldDepth::set_field_coords
void set_field_coords(FieldCoords *field_coords)
Setter of field_coords data member.
Definition: field_depth.hh:143
Input::Type
Definition: balance.hh:41
FieldDepth::set_mesh
void set_mesh(const Mesh &mesh) override
Definition: field_depth.hh:64
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:266
Mesh
Definition: mesh.h:362
FieldDepth::is_constant
bool is_constant(FMT_UNUSED Region reg) override
Definition: field_depth.hh:68
FieldDepth::set_surface_depth
void set_surface_depth(std::shared_ptr< SurfaceDepth > surface_depth)
Setter of surface_depth data member.
Definition: field_depth.hh:138
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
FieldDepth::value_cache
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:121
FieldDepth::observe_output
void observe_output(FMT_UNUSED std::shared_ptr< Observe > observe) override
Definition: field_depth.hh:84
field_value_cache.hh
FieldDepth::copy_from
void copy_from(FMT_UNUSED const FieldCommon &other) override
Definition: field_depth.hh:76
Armor::Array
Definition: armor.hh:597
FieldDepth::set_time
bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override
Definition: field_depth.hh:72
FieldDepth::get_input_type
IT::Instance get_input_type() override
Definition: field_depth.hh:49
OutputTime::DiscreteSpace
DiscreteSpace
Definition: output_time.hh:108
FieldDepth::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_depth.hh:101
mapping_p1.hh
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell.
FieldDepth::field_output
void field_output(FMT_UNUSED std::shared_ptr< OutputTime > stream, FMT_UNUSED OutputTime::DiscreteSpace type) override
Definition: field_depth.hh:80
std::list
Definition: doxy_dummy_defs.hh:9
FieldDepth::FieldDepth
FieldDepth()
Constructor.
Definition: field_depth.hh:39
FieldCommon::time
double time() const
Definition: field_common.hh:299
field_common.hh
field_coords.hh
FieldDepth::surface_depth_
std::shared_ptr< SurfaceDepth > surface_depth_
Surface depth object calculate distance from surface.
Definition: field_depth.hh:156
FMT_UNUSED
#define FMT_UNUSED
Definition: posix.h:75