Flow123d  master-921db77
field_mesh_step.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_mesh_step.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_MESH_STEP_HH_
19 #define FIELD_MESH_STEP_HH_
20 
21 #include "fields/field_common.hh" // for FieldCommon::T...
22 #include "fem/element_cache_map.hh" // for FieldValueCache
23 #include "mesh/mesh.h"
24 
25 struct PatchInternals;
26 template <int spacedim> class ElementAccessor;
27 
28 namespace IT=Input::Type;
29 
30 
31 /**
32  * Specialized field represents mesh step ('h') of FieldFormula.
33  */
34 class FieldMeshStep : public FieldCommon {
35 public:
36  /// Constructor
38  : value_cache_( FieldValueCache<double>(1, 1) )
39  {
40  this->multifield_ = false;
41  unsigned int cache_size = CacheMapElementNumber::get();
42  value_cache_.reinit(cache_size);
43  value_cache_.resize(cache_size);
44  this->set_shape(1, 1);
45  }
46 
48  ASSERT_PERMANENT(false).error("This method can't be used for FieldMeshStep");
49 
50  IT::Abstract abstract = IT::Abstract();
52  return inst;
53  }
54 
56  ASSERT_PERMANENT(false).error("This method can't be used for FieldMeshStep");
57 
58  IT::Array arr = IT::Array( IT::Integer() );
59  return arr;
60  }
61 
62  void set_mesh(const Mesh &mesh) override {
63  shared_->mesh_ = &mesh;
64  }
65 
66  bool is_constant(FMT_UNUSED Region reg) override {
67  return false;
68  }
69 
70  bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override {
71  return false;
72  }
73 
74  void copy_from(FMT_UNUSED const FieldCommon & other) override {
75  ASSERT_PERMANENT(false).error("Forbidden method for FieldMeshStep!");
76  }
77 
78  void field_output(FMT_UNUSED std::shared_ptr<OutputTime> stream, FMT_UNUSED OutputTime::DiscreteSpace type) override {
79  ASSERT_PERMANENT(false).error("Forbidden method for FieldMeshStep!");
80  }
81 
82  FieldResult field_result(FMT_UNUSED RegionSet region_set) const override {
83  return result_none;
84  }
85 
86  std::string get_value_attribute() const override {
87  double limit = std::numeric_limits<double>::max();
88  return fmt::format("{{ \"shape\": [ 1, 1 ], \"type\": \"Double\", \"limit\": [ {}, {} ] }}", -limit, +limit);
89  }
90 
92  {}
93 
94  /// Implements FieldCommon::cache_allocate
95  void cache_reallocate(FMT_UNUSED PatchInternals &patch_internals, FMT_UNUSED unsigned int region_idx) const override
96  {}
97 
98  /// Implements FieldCommon::cache_update
99  void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override {
100  const std::vector<double> meassure_dim_coef = {1, 1, 2, 6};
101  unsigned int reg_chunk_begin = cache_map.region_chunk_begin(region_patch_idx);
102  unsigned int reg_chunk_end = cache_map.region_chunk_end(region_patch_idx);
103  unsigned int region_idx = cache_map.eval_point_data(reg_chunk_begin).i_reg_;
104  unsigned int last_element_idx = -1;
105  ElementAccessor<3> elm;
106  double h_val = 0.0;
107 
108  const MeshBase *mesh; // Holds bulk or boundary mesh by region_idx
109  if (region_idx%2 == 1) mesh = shared_->mesh_;
110  else mesh = shared_->mesh_->bc_mesh();
111 
112  for (unsigned int i_data = reg_chunk_begin; i_data < reg_chunk_end; ++i_data) { // i_eval_point_data
113  unsigned int elm_idx = cache_map.eval_point_data(i_data).i_element_;
114  if (elm_idx != last_element_idx) {
115  elm = mesh->element_accessor( elm_idx );
116  double exp = 1.0 / elm.dim();
117  h_val = pow( (elm.measure() * meassure_dim_coef[elm.dim()]), exp );
118  last_element_idx = elm_idx;
119  }
120  value_cache_.set(i_data) = h_val;
121  }
122  }
123 
124  /// Implements FieldCommon::value_cache
126  return &value_cache_;
127  }
128 
129  /// Implements FieldCommon::value_cache
130  const FieldValueCache<double> * value_cache() const override {
131  return &value_cache_;
132  }
133 
134  /// Implements FieldCommon::set_dependency().
135  std::vector<const FieldCommon *> set_dependency(FMT_UNUSED unsigned int i_reg) const override {
137  }
138 
139 private:
140  /**
141  * Field value data cache
142  *
143  * See implementation of Field<spacedim, Value>::value_cache_
144  */
146 };
147 
148 #endif /* FIELD_MESH_STEP_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.
double measure() const
Computes the measure of the element.
unsigned int dim() const
Definition: accessors.hh:188
Directing class of FieldValueCache.
unsigned int region_chunk_end(unsigned int region_patch_idx) const
Return end position of region chunk in FieldValueCache.
unsigned int region_chunk_begin(unsigned int region_patch_idx) const
Return begin position of region chunk in FieldValueCache.
const EvalPointData & eval_point_data(unsigned int point_idx) const
Return item of eval_point_data_ specified by its position.
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
void copy_from(FMT_UNUSED const FieldCommon &other) override
IT::Array get_multifield_input_type() override
FieldValueCache< double > value_cache_
FieldMeshStep()
Constructor.
FieldResult field_result(FMT_UNUSED RegionSet region_set) const override
void set_input_list(FMT_UNUSED const Input::Array &list, FMT_UNUSED const TimeGovernor &tg) override
bool is_constant(FMT_UNUSED Region reg) override
void set_mesh(const Mesh &mesh) override
std::string get_value_attribute() const override
void cache_update(ElementCacheMap &cache_map, unsigned int region_patch_idx) const override
Implements FieldCommon::cache_update.
bool set_time(FMT_UNUSED const TimeStep &time, FMT_UNUSED LimitSide limit_side) override
FieldValueCache< double > * value_cache() override
Implements FieldCommon::value_cache.
std::vector< const FieldCommon * > set_dependency(FMT_UNUSED unsigned int i_reg) const override
Implements FieldCommon::set_dependency().
const FieldValueCache< double > * value_cache() const override
Implements FieldCommon::value_cache.
IT::Instance get_input_type() override
void cache_reallocate(FMT_UNUSED PatchInternals &patch_internals, FMT_UNUSED unsigned int region_idx) const override
Implements FieldCommon::cache_allocate.
void field_output(FMT_UNUSED std::shared_ptr< OutputTime > stream, FMT_UNUSED OutputTime::DiscreteSpace type) override
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
Base class for Mesh and BCMesh.
Definition: mesh.h:96
ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
Definition: mesh.cc:880
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
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
#define FMT_UNUSED
Definition: posix.h:75
unsigned int i_element_
mesh_idx of ElementAccessor appropriate to element
unsigned int i_reg_
region_idx of element
Holds common data shared between GenericAssemblz and Assembly<dim> classes.