Flow123d  JS_before_hm-1576-g4d0b70e
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 = 1.1 * CacheMapElementNumber::get();
44  value_cache_.reinit(cache_size);
45  value_cache_.resize(cache_size);
46  this->set_shape(1, 1);
47  }
48 
50  ASSERT(false).error("This method can't be used for FieldDepth");
51 
52  IT::Abstract abstract = IT::Abstract();
54  return inst;
55  }
56 
58  ASSERT(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  this->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(false).error("Forbidden method for FieldCoords!");
78  }
79 
80  void field_output(FMT_UNUSED std::shared_ptr<OutputTime> stream) override {
81  ASSERT(false).error("Forbidden method for FieldCoords!");
82  }
83 
84  void observe_output(FMT_UNUSED std::shared_ptr<Observe> observe) override {
85  ASSERT(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  const Mesh *mesh_; ///< Pointer to the mesh.
159  FieldCoords * field_coords_; ///< Pointer to coordinates field.
160 };
161 
162 #endif /* FIELD_DEPTH_HH_ */
unsigned int region_chunk_begin(unsigned int region_patch_idx) const
Return begin position of region chunk in FieldValueCache.
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
bool is_constant(FMT_UNUSED Region reg) override
Definition: field_depth.hh:68
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
void set_field_coords(FieldCoords *field_coords)
Setter of field_coords data member.
Definition: field_depth.hh:143
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
void observe_output(FMT_UNUSED std::shared_ptr< Observe > observe) override
Definition: field_depth.hh:84
static unsigned int get()
Return number of stored elements.
void set_input_list(FMT_UNUSED const Input::Array &list, FMT_UNUSED const TimeGovernor &tg) override
Definition: field_depth.hh:97
void set_mesh(const Mesh &mesh) override
Definition: field_depth.hh:64
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
Directing class of FieldValueCache.
Definition: mesh.h:77
std::string get_value_attribute() const override
Definition: field_depth.hh:92
Helper class that stores data of generic types.
Definition: type_generic.hh:89
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
const Mesh * mesh_
Pointer to the mesh.
Definition: field_depth.hh:158
void copy_from(FMT_UNUSED const FieldCommon &other) override
Definition: field_depth.hh:76
#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
std::shared_ptr< SurfaceDepth > surface_depth_
Surface depth object calculate distance from surface.
Definition: field_depth.hh:156
void set_surface_depth(std::shared_ptr< SurfaceDepth > surface_depth)
Setter of surface_depth data member.
Definition: field_depth.hh:138
Basic time management functionality for unsteady (and steady) solvers (class Equation).
IT::Instance get_input_type() override
Definition: field_depth.hh:49
bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override
Definition: field_depth.hh:72
Class for declaration of inputs sequences.
Definition: type_base.hh:339
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:121
FieldDepth()
Constructor.
Definition: field_depth.hh:39
double time() const
#define FMT_UNUSED
Definition: posix.h:75
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)
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
Definition: field_depth.hh:105
IT::Array get_multifield_input_type() override
Definition: field_depth.hh:57
Class for declaration of polymorphic Record.
FieldValueCache< double > value_cache_
Definition: field_depth.hh:153
FieldResult
const FieldValueCache< double > * value_cache() const override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:126
std::shared_ptr< EvalPoints > eval_points() const
Getter of eval_points object.
const Mesh * mesh() const
FieldCoords * field_coords_
Pointer to coordinates field.
Definition: field_depth.hh:159
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
Representation of one time step..
LimitSide
Definition: field_common.hh:61
void field_output(FMT_UNUSED std::shared_ptr< OutputTime > stream) override
Definition: field_depth.hh:80
FieldResult field_result(FMT_UNUSED RegionSet region_set) const override
Definition: field_depth.hh:88