Flow123d  last_with_con_2.0.0-4-g42e6930
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);
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  virtual void set_mesh(const Mesh *mesh, bool boundary_domain);
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  virtual typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm);
92 
93  /**
94  * Returns std::vector of scalar values in several points at once.
95  */
96  virtual void value_list (const std::vector< Point > &point_list, const ElementAccessor<spacedim> &elm,
98 
99 
100  virtual ~FieldElementwise();
101 
102 private:
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  /// Registrar of class to factory
122  static const int registrar;
123 };
124 
125 
126 #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
virtual void init_from_input(const Input::Record &rec)
Definition: mesh.h:95
static const Input::Type::Record & get_input_type()
Implementation.
static const int registrar
Registrar of class to factory.
void set_data_row(unsigned int boundary_idx, typename Value::return_type &value)
bool set_time(const TimeStep &time) override
FieldAlgorithmBase< spacedim, Value >::Point Point
Accessor to the data with type Type::Record.
Definition: accessors.hh:277
FieldElementwise(unsigned int n_comp=0)
Space< spacedim >::Point Point
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
Dedicated class for storing path to input and output files.
Definition: file_path.hh:48
unsigned int n_components_
Size of Value.
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
unsigned int n_entities_
Number of rows in data_ buffer.
virtual void set_mesh(const Mesh *mesh, bool boundary_domain)
Record type proxy class.
Definition: type_record.hh:171
Representation of one time step..
unsigned int n_comp() const