Flow123d
field_elementwise.hh
Go to the documentation of this file.
1 /*
2  * field_elementwise.hh
3  *
4  * Created on: Jan 22, 2013
5  * Author: jb
6  */
7 
8 #ifndef FIELD_ELEMENTWISE_HH_
9 #define FIELD_ELEMENTWISE_HH_
10 
11 /**
12  * The simplest approximative Field. In future we want to replace it by pair: DofHandler + vector of dof values.
13  *
14  * In current setting:
15  * This should implement mapping: (ElementAccessor.INDEX) -> value
16  * Currently INDEX is global index of element (any dimension, both bulk and boundary part). In future INDEX should
17  * probably consist of MESH_LEVEL (unique mesh, dimension, bulk/boundary, level of refinement) and INDEX within this level.
18  * 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).
19  * 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.
20  *
21  * Currently, we just use one vector for bulk and one for boundary elements.
22  *
23  * TODO:
24  * - move raw access resolution functions from FieldValues_ into FieldElementwise
25  * - allow elementwise int or FieldEnum data with optimal storage buffer, this needs
26  * templated GMSH reader
27  * - allow initialization of multiple fields by one reader
28  * - allow common storage for more elementwise fields to have values for one element on one place
29  */
30 
31 #include "system/system.hh"
32 #include "fields/field_base.hh"
33 
34 class GmshMeshReader;
35 
36 template <int spacedim, class Value>
37 class FieldElementwise : public FieldBase<spacedim, Value>
38 {
39 public:
41 
42  FieldElementwise(unsigned int n_comp=0);
43 
44  /**
45  * Temporary solution (as well as the whole this class before we use DofHandlers) how to
46  * build FiledElementwise on an existing array of values on elements.
47  */
48  FieldElementwise(double *data_ptr, unsigned int n_components, unsigned int size );
49 
50  /**
51  * Alternative to previous constructor.
52  */
53  FieldElementwise(vector<double> &data, unsigned int n_components)
54  : FieldElementwise(&(data[0]), n_components, data.size() )
55  {}
56 
58 
59  static Input::Type::Record get_input_type(Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit);
60 
61  virtual void init_from_input(const Input::Record &rec);
62 
63  /**
64  * Set row of boundary data. Used to implement old BC input.
65  */
66  void set_data_row(unsigned int boundary_idx, typename Value::return_type &value);
67 
68  /**
69  * Update time and possibly update data from GMSH file.
70  */
71  virtual bool set_time(double time);
72 
73  /**
74  * Has to be set before calling init_from_input. This also
75  * allocate and initialize internal buffer. Do nothing if mesh is already set.
76  *
77  * See also description of the FieldBase<...>::set_mesh.
78  */
79  virtual void set_mesh(const Mesh *mesh, bool boundary_domain);
80 
81 
82  /**
83  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
84  */
85  virtual typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm);
86 
87  /**
88  * Returns std::vector of scalar values in several points at once.
89  */
90  virtual void value_list (const std::vector< Point > &point_list, const ElementAccessor<spacedim> &elm,
92 
93 
94  virtual ~FieldElementwise();
95 
96 private:
97  /// Is flase whne the data vector is provided at construction. Then, we disallow initialization form input
98  /// and do not delete data pointer in destructor.
100  /**
101  * Is set in set_mesh method. Value true means, that we accept only boundary element accessors in the @p value method.
102  * TODO: temporary solution until we have separate mesh for the boundary part
103  */
105  /// number of bulk data lines in the buffer
106  //unsigned int bulk_size_;
107  /// Allocated size of data_ buffer
108  unsigned int data_size_;
109  /// Raw buffer of n_entities rows each containing Value::size() doubles.
110  double *data_;
111  /// Number of rows in @p data_ buffer.
112  unsigned int n_entities_;
113  /// Size of Value
114  unsigned int n_components_;
115 
117  const Mesh *mesh_;
118  std::string field_name_;
119 };
120 
121 
122 #endif /* FIELD_ELEMENTWISE_HH_ */