Flow123d  master-1cc3435
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 "fem/element_cache_map.hh" // for FieldValueCache
23 #include "fem/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 struct AssemblyInternals;
30 
31 namespace IT=Input::Type;
32 
33 
34 /**
35  * Specialized field represents surface depth ('d' variable) of FieldFormula.
36  */
37 class FieldDepth : public FieldCommon {
38 public:
39 
40  /// Constructor
42  : value_cache_( FieldValueCache<double>(1, 1) ), surface_depth_(nullptr)
43  {
44  this->multifield_ = false;
45  unsigned int cache_size = CacheMapElementNumber::get();
46  value_cache_.reinit(cache_size);
47  value_cache_.resize(cache_size);
48  this->set_shape(1, 1);
49  }
50 
52  ASSERT_PERMANENT(false).error("This method can't be used for FieldDepth");
53 
54  IT::Abstract abstract = IT::Abstract();
56  return inst;
57  }
58 
60  ASSERT_PERMANENT(false).error("This method can't be used for FieldDepth");
61 
62  IT::Array arr = IT::Array( IT::Integer() );
63  return arr;
64  }
65 
66  void set_mesh(const Mesh &mesh) override {
67  shared_->mesh_ = &mesh;
68  }
69 
70  bool is_constant(FMT_UNUSED Region reg) override {
71  return false;
72  }
73 
74  bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override {
75  return false;
76  }
77 
78  void copy_from(FMT_UNUSED const FieldCommon & other) override {
79  ASSERT_PERMANENT(false).error("Forbidden method for FieldCoords!");
80  }
81 
82  void field_output(FMT_UNUSED std::shared_ptr<OutputTime> stream, FMT_UNUSED OutputTime::DiscreteSpace type) override {
83  ASSERT_PERMANENT(false).error("Forbidden method for FieldCoords!");
84  }
85 
86  FieldResult field_result(FMT_UNUSED RegionSet region_set) const override {
87  return result_none;
88  }
89 
90  std::string get_value_attribute() const override {
91  double limit = std::numeric_limits<double>::max();
92  return fmt::format("{{ \"shape\": [ 1, 1 ], \"type\": \"Double\", \"limit\": [ {}, {} ] }}", -limit, +limit);
93  }
94 
96  {}
97 
98  /// Implements FieldCommon::cache_allocate
99  void cache_reallocate(FMT_UNUSED AssemblyInternals &asm_internals, FMT_UNUSED unsigned int region_idx) const override
100  {}
101 
102  /// Implements FieldCommon::cache_update
103  void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override {
104  if (surface_depth_ == nullptr) return;
105 
106  std::shared_ptr<EvalPoints> eval_points = cache_map.eval_points();
107  unsigned int reg_chunk_begin = cache_map.region_chunk_begin(region_patch_idx);
108  unsigned int reg_chunk_end = cache_map.region_chunk_end(region_patch_idx);
109  auto * coords_cache = field_coords_->value_cache();
110  arma::vec3 p; // evaluated point
111 
112  for (unsigned int i_data = reg_chunk_begin; i_data < reg_chunk_end; ++i_data) { // i_eval_point_data
113  p = coords_cache->template vec<3>(i_data);
114  value_cache_.set(i_data) = surface_depth_->compute_distance(p);
115  }
116  }
117 
118  /// Implements FieldCommon::value_cache
120  return &value_cache_;
121  }
122 
123  /// Implements FieldCommon::value_cache
124  const FieldValueCache<double> * value_cache() const override {
125  return &value_cache_;
126  }
127 
128  /// Implements FieldCommon::set_dependency().
129  std::vector<const FieldCommon *> set_dependency(FMT_UNUSED unsigned int i_reg) const override {
131  res.push_back(field_coords_);
132  return res;
133  }
134 
135  /// Setter of surface_depth data member
136  inline void set_surface_depth(std::shared_ptr<SurfaceDepth> surface_depth) {
137  surface_depth_ = surface_depth;
138  }
139 
140  /// Setter of field_coords data member
141  inline void set_field_coords(FieldCoords * field_coords) {
142  field_coords_ = field_coords;
143  }
144 
145 private:
146  /**
147  * Field value data cache
148  *
149  * See implementation of Field<spacedim, Value>::value_cache_
150  */
152 
153  /// Surface depth object calculate distance from surface.
154  std::shared_ptr<SurfaceDepth> surface_depth_;
155 
156  FieldCoords * field_coords_; ///< Pointer to coordinates field.
157 };
158 
159 #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:78
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:151
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:119
std::shared_ptr< SurfaceDepth > surface_depth_
Surface depth object calculate distance from surface.
Definition: field_depth.hh:154
IT::Array get_multifield_input_type() override
Definition: field_depth.hh:59
FieldDepth()
Constructor.
Definition: field_depth.hh:41
FieldResult field_result(FMT_UNUSED RegionSet region_set) const override
Definition: field_depth.hh:86
IT::Instance get_input_type() override
Definition: field_depth.hh:51
void cache_reallocate(FMT_UNUSED AssemblyInternals &asm_internals, FMT_UNUSED unsigned int region_idx) const override
Implements FieldCommon::cache_allocate.
Definition: field_depth.hh:99
void set_field_coords(FieldCoords *field_coords)
Setter of field_coords data member.
Definition: field_depth.hh:141
std::vector< const FieldCommon * > set_dependency(FMT_UNUSED unsigned int i_reg) const override
Implements FieldCommon::set_dependency().
Definition: field_depth.hh:129
bool is_constant(FMT_UNUSED Region reg) override
Definition: field_depth.hh:70
void field_output(FMT_UNUSED std::shared_ptr< OutputTime > stream, FMT_UNUSED OutputTime::DiscreteSpace type) override
Definition: field_depth.hh:82
const FieldValueCache< double > * value_cache() const override
Implements FieldCommon::value_cache.
Definition: field_depth.hh:124
void set_mesh(const Mesh &mesh) override
Definition: field_depth.hh:66
void set_surface_depth(std::shared_ptr< SurfaceDepth > surface_depth)
Setter of surface_depth data member.
Definition: field_depth.hh:136
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
Definition: field_depth.hh:103
void set_input_list(FMT_UNUSED const Input::Array &list, FMT_UNUSED const TimeGovernor &tg) override
Definition: field_depth.hh:95
std::string get_value_attribute() const override
Definition: field_depth.hh:90
bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override
Definition: field_depth.hh:74
FieldCoords * field_coords_
Pointer to coordinates field.
Definition: field_depth.hh:156
void copy_from(FMT_UNUSED const FieldCommon &other) override
Definition: field_depth.hh:78
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: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.