Flow123d  release_2.1.0-84-g6a13a75
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 class GmshMeshReader;
50 
51 template <int spacedim, class Value>
52 class FieldElementwise : public FieldAlgorithmBase<spacedim, Value>
53 {
54 public:
57 
58  FieldElementwise(unsigned int n_comp=0);
59 
60  /**
61  * Alternative to previous constructor.
62  */
63  FieldElementwise(std::shared_ptr< std::vector<typename Value::element_type> > data, unsigned int n_components);
64 
65  static const Input::Type::Record & get_input_type();
66 
67  virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData& init_data) override;
68 
69  /**
70  * Set row of boundary data. Used to implement old BC input.
71  */
72  //void set_data_row(unsigned int boundary_idx, typename Value::return_type &value);
73 
74  /**
75  * Update time and possibly update data from GMSH file.
76  */
77  bool set_time(const TimeStep &time) override;
78 
79  /**
80  * Has to be set before calling init_from_input. This also
81  * allocate and initialize internal buffer. Do nothing if mesh is already set.
82  *
83  * See also description of the FieldBase<...>::set_mesh.
84  */
85  void set_mesh(const Mesh *mesh, bool boundary_domain) override;
86 
87 
88  /**
89  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
90  */
91  typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm) override;
92 
93  /**
94  * Returns std::vector of scalar values in several points at once.
95  */
96  void value_list (const std::vector< Point > &point_list, const ElementAccessor<spacedim> &elm,
98 
99 
100  virtual ~FieldElementwise();
101 
102 private:
103  /// Multiply @p data_ with @p unit_conversion_coefficient_ and check limits of field
104  void scale_and_check_limits();
105  /// Is flase whne the data vector is provided at construction. Then, we disallow initialization form input
106  /// and do not delete data pointer in destructor.
108  /**
109  * Is set in set_mesh method. Value true means, that we accept only boundary element accessors in the @p value method.
110  * TODO: temporary solution until we have separate mesh for the boundary part
111  */
113  /// Raw buffer of n_entities rows each containing Value::size() doubles.
114  std::shared_ptr< std::vector<typename Value::element_type> > data_;
115  /// Number of rows in @p data_ buffer.
116  unsigned int n_entities_;
117  /// Size of Value
118  unsigned int n_components_;
119 
121  const Mesh *mesh_;
122  std::string field_name_;
123 
124  /// Accessor to Input::Record
126 
127  /**
128  * Initialization data of field. Necessary for check limits.
129  *
130  * TODO: Temporary solution will be replaced with shared_ptr to field data in FieldAlgoBase
131  */
133  std::pair<double, double> limits_;
134 
135  /// Registrar of class to factory
136  static const int registrar;
137 };
138 
139 
140 #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:95
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:286
FieldElementwise(unsigned int n_comp=0)
Space< spacedim >::Point Point
Dedicated class for storing path to input and output files.
Definition: file_path.hh:48
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:177
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