Flow123d  release_3.0.0-1025-gd4d7c13
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 <string.h> // for memcpy
46 #include <boost/exception/info.hpp> // for operator<<, error_info::er...
47 #include <memory> // for shared_ptr
48 #include <string> // for string
49 #include <utility> // for pair
50 #include <vector> // for vector
51 #include <armadillo>
52 #include "fields/field_algo_base.hh" // for FieldAlgorithmBase
53 #include "fields/field_values.hh" // for FieldValue<>::Enum, FieldV...
54 #include "input/accessors.hh" // for ExcAccessorForNullStorage
55 #include "input/accessors_impl.hh" // for Record::val
56 #include "input/storage.hh" // for ExcStorageTypeMismatch
57 #include "input/type_record.hh" // for Record::ExcRecordKeyNotFound
58 #include "system/exceptions.hh" // for ExcAssertMsg::~ExcAssertMsg
59 #include "system/file_path.hh" // for FilePath
60 #include "tools/time_governor.hh" // for TimeStep
61 class Mesh;
62 class UnitSI;
63 template <int spacedim> class ElementAccessor;
64 
65 template <int spacedim, class Value>
66 class FieldElementwise : public FieldAlgorithmBase<spacedim, Value>
67 {
68 public:
71 
72  FieldElementwise(unsigned int n_comp=0);
73 
74  /**
75  * Alternative to previous constructor.
76  */
77  FieldElementwise(std::shared_ptr< std::vector<typename Value::element_type> > data, unsigned int n_components);
78 
79  static const Input::Type::Record & get_input_type();
80 
81  virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData& init_data) override;
82 
83  /**
84  * Set row of boundary data. Used to implement old BC input.
85  */
86  //void set_data_row(unsigned int boundary_idx, typename Value::return_type &value);
87 
88  /**
89  * Update time and possibly update data from GMSH file.
90  */
91  bool set_time(const TimeStep &time) override;
92 
93  /**
94  * Has to be set before calling init_from_input. This also
95  * allocate and initialize internal buffer. Do nothing if mesh is already set.
96  *
97  * See also description of the FieldBase<...>::set_mesh.
98  */
99  void set_mesh(const Mesh *mesh, bool boundary_domain) override;
100 
101 
102  /**
103  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
104  */
105  typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm) override;
106 
107  /**
108  * Returns std::vector of scalar values in several points at once.
109  */
110  void value_list (const std::vector< Point > &point_list, const ElementAccessor<spacedim> &elm,
112 
113 
114  virtual ~FieldElementwise();
115 
116 private:
117  /// Is flase whne the data vector is provided at construction. Then, we disallow initialization form input
118  /// and do not delete data pointer in destructor.
120  /**
121  * Is set in set_mesh method. Value true means, that we accept only boundary element accessors in the @p value method.
122  * TODO: temporary solution until we have separate mesh for the boundary part
123  */
125  /// Raw buffer of n_entities rows each containing Value::size() doubles.
126  std::shared_ptr< std::vector<typename Value::element_type> > data_;
127  /// Number of rows in @p data_ buffer.
128  unsigned int n_entities_;
129  /// Size of Value
130  unsigned int n_components_;
131  /// Default value of element if not set in mesh data file
133 
135  const Mesh *mesh_;
136  std::string field_name_;
137 
138  /// Accessor to Input::Record
140 
141  /**
142  * Initialization data of field. Necessary for check limits.
143  *
144  * TODO: Temporary solution will be replaced with shared_ptr to field data in FieldAlgoBase
145  */
147  std::pair<double, double> limits_;
148 
149  /// Registrar of class to factory
150  static const int registrar;
151 };
152 
153 
154 #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:76
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
Basic time management class.
bool set_time(const TimeStep &time) override
FieldAlgorithmBase< spacedim, Value >::Point Point
double default_value_
Default value of element if not set in mesh data file.
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