Flow123d  release_3.0.0-973-g92f55e826
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_ */
FieldAlgorithmBase::n_comp
unsigned int n_comp() const
Definition: field_algo_base.impl.hh:160
FieldElementwise::internal_raw_data
bool internal_raw_data
Definition: field_elementwise.hh:119
FieldElementwise::~FieldElementwise
virtual ~FieldElementwise()
Definition: field_elementwise.cc:227
time_governor.hh
Basic time management class.
field_algo_base.hh
FieldElementwise::data_
std::shared_ptr< std::vector< typename Value::element_type > > data_
Raw buffer of n_entities rows each containing Value::size() doubles.
Definition: field_elementwise.hh:126
FieldElementwise::default_value_
double default_value_
Default value of element if not set in mesh data file.
Definition: field_elementwise.hh:132
FieldElementwise::boundary_domain_
bool boundary_domain_
Definition: field_elementwise.hh:124
string.h
file_path.hh
FilePath
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
std::vector
Definition: doxy_dummy_defs.hh:7
ElementAccessor
Definition: fe_value_handler.hh:29
FieldElementwise::value
const Value::return_type & value(const Point &p, const ElementAccessor< spacedim > &elm) override
Definition: field_elementwise.cc:184
FieldElementwise::set_time
bool set_time(const TimeStep &time) override
Definition: field_elementwise.cc:128
FieldAlgorithmBase::Point
Space< spacedim >::Point Point
Definition: field_algo_base.hh:113
storage.hh
exceptions.hh
FieldElementwise::FactoryBaseType
FieldAlgorithmBase< spacedim, Value > FactoryBaseType
Definition: field_elementwise.hh:70
type_record.hh
FieldElementwise::init_from_input
virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data) override
Definition: field_elementwise.cc:93
FieldElementwise::field_name_
std::string field_name_
Definition: field_elementwise.hh:136
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
FieldElementwise::n_components_
unsigned int n_components_
Size of Value.
Definition: field_elementwise.hh:130
FieldElementwise::limits_
std::pair< double, double > limits_
Definition: field_elementwise.hh:147
FieldAlgoBaseInitData
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
Definition: field_algo_base.hh:79
FieldElementwise::n_entities_
unsigned int n_entities_
Number of rows in data_ buffer.
Definition: field_elementwise.hh:128
accessors.hh
TimeStep
Representation of one time step..
Definition: time_governor.hh:113
FieldElementwise::unit_si_
UnitSI & unit_si_
Definition: field_elementwise.hh:146
field_values.hh
UnitSI
Class for representation SI units of Fields.
Definition: unit_si.hh:40
FieldElementwise::registrar
static const int registrar
Registrar of class to factory.
Definition: field_elementwise.hh:150
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
FieldElementwise::get_input_type
static const Input::Type::Record & get_input_type()
Implementation.
Definition: field_elementwise.cc:37
Mesh
Definition: mesh.h:80
FieldAlgorithmBase
Definition: field_algo_base.hh:110
FieldElementwise
Definition: field_elementwise.hh:66
FieldElementwise::mesh_
const Mesh * mesh_
Definition: field_elementwise.hh:135
FieldElementwise::in_rec_
Input::Record in_rec_
Accessor to Input::Record.
Definition: field_elementwise.hh:139
FieldElementwise::Point
FieldAlgorithmBase< spacedim, Value >::Point Point
Definition: field_elementwise.hh:69
FieldElementwise::set_mesh
void set_mesh(const Mesh *mesh, bool boundary_domain) override
Definition: field_elementwise.cc:160
FieldElementwise::value_list
void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list) override
Definition: field_elementwise.cc:201
FieldElementwise::FieldElementwise
FieldElementwise(unsigned int n_comp=0)
Definition: field_elementwise.cc:67
FieldElementwise::reader_file_
FilePath reader_file_
Definition: field_elementwise.hh:134
accessors_impl.hh