Flow123d  JB_transport-d4c8564
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_ */
result_none
@ result_none
Definition: field_algo_base.hh:71
surface_depth.hh
FieldCommon::shared_
std::shared_ptr< SharedData > shared_
Definition: field_common.hh:682
FieldCoords
Definition: field_coords.hh:36
CacheMapElementNumber::get
static unsigned int get()
Return number of stored elements.
Definition: field_value_cache.hh:94
FieldDepth::value_cache
const FieldValueCache< double > * value_cache() const override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:122
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:101
FieldCoords::value_cache
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Definition: field_coords.hh:150
FieldDepth
Definition: field_depth.hh:35
FieldCommon::set_shape
void set_shape(uint n_rows, uint n_cols)
Definition: field_common.hh:574
FieldDepth::value_cache_
FieldValueCache< double > value_cache_
Definition: field_depth.hh:149
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:152
eval_points.hh
FieldResult
FieldResult
Definition: field_algo_base.hh:70
FieldCommon::mesh
const Mesh * mesh() const
Definition: field_common.hh:287
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:273
FieldCommon::multifield_
bool multifield_
Definition: field_common.hh:728
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:154
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:194
FieldDepth::set_input_list
void set_input_list(FMT_UNUSED const Input::Array &list, FMT_UNUSED const TimeGovernor &tg) override
Definition: field_depth.hh:93
FieldCommon
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:77
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
LimitSide
LimitSide
Definition: field_common.hh:64
FieldDepth::get_value_attribute
std::string get_value_attribute() const override
Definition: field_depth.hh:88
FieldDepth::field_result
FieldResult field_result(FMT_UNUSED RegionSet region_set) const override
Definition: field_depth.hh:84
FieldDepth::set_field_coords
void set_field_coords(FieldCoords *field_coords)
Setter of field_coords data member.
Definition: field_depth.hh:139
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:267
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:134
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:117
FieldDepth::set_dependency
std::vector< const FieldCommon * > set_dependency(FMT_UNUSED unsigned int i_reg) const override
Implements FieldCommon::set_dependency().
Definition: field_depth.hh:127
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:97
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:300
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:152
FMT_UNUSED
#define FMT_UNUSED
Definition: posix.h:75