Flow123d  DF_profiler_memory_monitor-6d6a629
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  FieldResult field_result(FMT_UNUSED RegionSet region_set) const override {
85  return result_none;
86  }
87 
88  std::string get_value_attribute() const override {
89  double limit = std::numeric_limits<double>::max();
90  return fmt::format("{{ \"shape\": [ 1, 1 ], \"type\": \"Double\", \"limit\": [ {}, {} ] }}", -limit, +limit);
91  }
92 
94  {}
95 
96  /// Implements FieldCommon::cache_allocate
97  void cache_reallocate(FMT_UNUSED const ElementCacheMap &cache_map, FMT_UNUSED unsigned int region_idx) const override
98  {}
99 
100  /// Implements FieldCommon::cache_update
101  void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override {
102  if (surface_depth_ == nullptr) return;
103 
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  auto * coords_cache = field_coords_->value_cache();
108  arma::vec3 p; // evaluated point
109 
110  for (unsigned int i_data = reg_chunk_begin; i_data < reg_chunk_end; ++i_data) { // i_eval_point_data
111  p = coords_cache->template vec<3>(i_data);
112  value_cache_.set(i_data) = surface_depth_->compute_distance(p);
113  }
114  }
115 
116  /// Implements FieldCommon::value_cache
118  return &value_cache_;
119  }
120 
121  /// Implements FieldCommon::value_cache
122  const FieldValueCache<double> * value_cache() const override {
123  return &value_cache_;
124  }
125 
126  /// Implements FieldCommon::set_dependency().
127  std::vector<const FieldCommon *> set_dependency(FMT_UNUSED unsigned int i_reg) const override {
129  res.push_back(field_coords_);
130  return res;
131  }
132 
133  /// Setter of surface_depth data member
134  inline void set_surface_depth(std::shared_ptr<SurfaceDepth> surface_depth) {
135  surface_depth_ = surface_depth;
136  }
137 
138  /// Setter of field_coords data member
139  inline void set_field_coords(FieldCoords * field_coords) {
140  field_coords_ = field_coords;
141  }
142 
143 private:
144  /**
145  * Field value data cache
146  *
147  * See implementation of Field<spacedim, Value>::value_cache_
148  */
150 
151  /// Surface depth object calculate distance from surface.
152  std::shared_ptr<SurfaceDepth> surface_depth_;
153 
154  FieldCoords * field_coords_; ///< Pointer to coordinates field.
155 };
156 
157 #endif /* FIELD_DEPTH_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.
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.
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:77
std::shared_ptr< SharedData > shared_
double time() const
void set_shape(uint n_rows, uint n_cols)
const Mesh * mesh() const
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
FieldValueCache< double > value_cache_
Definition: field_depth.hh:149
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:117
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:97
std::shared_ptr< SurfaceDepth > surface_depth_
Surface depth object calculate distance from surface.
Definition: field_depth.hh:152
IT::Array get_multifield_input_type() override
Definition: field_depth.hh:57
FieldDepth()
Constructor.
Definition: field_depth.hh:39
FieldResult field_result(FMT_UNUSED RegionSet region_set) const override
Definition: field_depth.hh:84
IT::Instance get_input_type() override
Definition: field_depth.hh:49
void set_field_coords(FieldCoords *field_coords)
Setter of field_coords data member.
Definition: field_depth.hh:139
std::vector< const FieldCommon * > set_dependency(FMT_UNUSED unsigned int i_reg) const override
Implements FieldCommon::set_dependency().
Definition: field_depth.hh:127
bool is_constant(FMT_UNUSED Region reg) override
Definition: field_depth.hh:68
void field_output(FMT_UNUSED std::shared_ptr< OutputTime > stream, FMT_UNUSED OutputTime::DiscreteSpace type) override
Definition: field_depth.hh:80
const FieldValueCache< double > * value_cache() const override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:122
void set_mesh(const Mesh &mesh) override
Definition: field_depth.hh:64
void set_surface_depth(std::shared_ptr< SurfaceDepth > surface_depth)
Setter of surface_depth data member.
Definition: field_depth.hh:134
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
Definition: field_depth.hh:101
void set_input_list(FMT_UNUSED const Input::Array &list, FMT_UNUSED const TimeGovernor &tg) override
Definition: field_depth.hh:93
std::string get_value_attribute() const override
Definition: field_depth.hh:88
bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override
Definition: field_depth.hh:72
FieldCoords * field_coords_
Pointer to coordinates field.
Definition: field_depth.hh:154
void copy_from(FMT_UNUSED const FieldCommon &other) override
Definition: field_depth.hh:76
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
Definition: mesh.h:362
Basic time management functionality for unsteady (and steady) solvers (class Equation).
Representation of one time step..
FieldResult
@ result_none
LimitSide
Definition: field_common.hh:64
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.