Flow123d  release_2.2.0-22-g936454a
field_elementwise.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_elementwise.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_ELEMENTWISE_HH_
19 #define FIELD_ELEMENTWISE_HH_
20 
21 /**
22  * The simplest approximative Field. In future we want to replace it by pair: DofHandler + vector of dof values.
23  *
24  * In current setting:
25  * This should implement mapping: (ElementAccessor.INDEX) -> value
26  * Currently INDEX is global index of element (any dimension, both bulk and boundary part). In future INDEX should
27  * probably consist of MESH_LEVEL (unique mesh, dimension, bulk/boundary, level of refinement) and INDEX within this level.
28  * We want to make memory optimization since usually field lives either on boundary or on bulk part and some bulk fields live only on some dimension(s).
29  * This can be achieved by two level indirection table of mesh_levelscontaining tables for indexes. We should test if the performance penalty is not to big.
30  *
31  * Currently, we just use one vector for bulk and one for boundary elements.
32  *
33  * TODO:
34  * - move raw access resolution functions from FieldValues_ into FieldElementwise
35  * - allow elementwise int or FieldEnum data with optimal storage buffer, this needs
36  * templated GMSH reader
37  * - After this do following cleanup:
38  * Partitioning::subdomain_id_field_data should return vector<int>
39  * pertitioning_test.cpp should make correct test.
40  *
41  * - allow initialization of multiple fields by one reader
42  * - allow common storage for more elementwise fields to have values for one element on one place
43  */
44 
45 #include "system/system.hh"
47 #include "input/factory.hh"
48 
49 template <int spacedim, class Value>
50 class FieldElementwise : public FieldAlgorithmBase<spacedim, Value>
51 {
52 public:
55 
56  FieldElementwise(unsigned int n_comp=0);
57 
58  /**
59  * Alternative to previous constructor.
60  */
61  FieldElementwise(std::shared_ptr< std::vector<typename Value::element_type> > data, unsigned int n_components);
62 
63  static const Input::Type::Record & get_input_type();
64 
65  virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData& init_data) override;
66 
67  /**
68  * Set row of boundary data. Used to implement old BC input.
69  */
70  //void set_data_row(unsigned int boundary_idx, typename Value::return_type &value);
71 
72  /**
73  * Update time and possibly update data from GMSH file.
74  */
75  bool set_time(const TimeStep &time) override;
76 
77  /**
78  * Has to be set before calling init_from_input. This also
79  * allocate and initialize internal buffer. Do nothing if mesh is already set.
80  *
81  * See also description of the FieldBase<...>::set_mesh.
82  */
83  void set_mesh(const Mesh *mesh, bool boundary_domain) override;
84 
85 
86  /**
87  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
88  */
89  typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm) override;
90 
91  /**
92  * Returns std::vector of scalar values in several points at once.
93  */
94  void value_list (const std::vector< Point > &point_list, const ElementAccessor<spacedim> &elm,
96 
97 
98  virtual ~FieldElementwise();
99 
100 private:
101  /// Multiply @p data_ with @p unit_conversion_coefficient_ and check limits of field
102  void scale_and_check_limits();
103  /// Is flase whne the data vector is provided at construction. Then, we disallow initialization form input
104  /// and do not delete data pointer in destructor.
106  /**
107  * Is set in set_mesh method. Value true means, that we accept only boundary element accessors in the @p value method.
108  * TODO: temporary solution until we have separate mesh for the boundary part
109  */
111  /// Raw buffer of n_entities rows each containing Value::size() doubles.
112  std::shared_ptr< std::vector<typename Value::element_type> > data_;
113  /// Number of rows in @p data_ buffer.
114  unsigned int n_entities_;
115  /// Size of Value
116  unsigned int n_components_;
117 
119  const Mesh *mesh_;
120  std::string field_name_;
121 
122  /// Accessor to Input::Record
124 
125  /**
126  * Initialization data of field. Necessary for check limits.
127  *
128  * TODO: Temporary solution will be replaced with shared_ptr to field data in FieldAlgoBase
129  */
131  std::pair<double, double> limits_;
132 
133  /// Registrar of class to factory
134  static const int registrar;
135 };
136 
137 
138 #endif /* FIELD_ELEMENTWISE_HH_ */
std::shared_ptr< std::vector< typename Value::element_type > > data_
Raw buffer of n_entities rows each containing Value::size() doubles.
FieldAlgorithmBase< spacedim, Value > FactoryBaseType
std::pair< double, double > limits_
Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm) override
Definition: mesh.h:97
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
static const Input::Type::Record & get_input_type()
Implementation.
static const int registrar
Registrar of class to factory.
virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data) override
bool set_time(const TimeStep &time) override
void scale_and_check_limits()
Multiply data_ with unit_conversion_coefficient_ and check limits of field.
FieldAlgorithmBase< spacedim, Value >::Point Point
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
FieldElementwise(unsigned int n_comp=0)
Space< spacedim >::Point Point
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
unsigned int n_components_
Size of Value.
void set_mesh(const Mesh *mesh, bool boundary_domain) override
unsigned int n_entities_
Number of rows in data_ buffer.
void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list) override
Record type proxy class.
Definition: type_record.hh:182
Input::Record in_rec_
Accessor to Input::Record.
Class for representation SI units of Fields.
Definition: unit_si.hh:40
Representation of one time step..
unsigned int n_comp() const