Flow123d  release_3.0.0-506-g34af125
field_fe.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_fe.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_FE_HH_
19 #define FIELD_FE_HH_
20 
21 #include "petscmat.h"
22 #include "system/system.hh"
24 #include "mesh/mesh.h"
25 #include "mesh/point.hh"
26 #include "mesh/bih_tree.hh"
27 #include "mesh/long_idx.hh"
28 #include "io/element_data_cache.hh"
29 #include "io/msh_basereader.hh"
30 #include "fem/dofhandler.hh"
31 #include "input/factory.hh"
32 
33 #include <memory>
34 
35 class VectorSeqDouble;
36 template<unsigned int dim, unsigned int spacedim> class MappingP1;
37 template <int elemdim, int spacedim, class Value> class FEValueHandler;
38 
39 
40 /**
41  * Class representing fields given by finite element approximation.
42  *
43  */
44 template <int spacedim, class Value>
45 class FieldFE : public FieldAlgorithmBase<spacedim, Value>
46 {
47 public:
50 
51  /**
52  * Default constructor, optionally we need number of components @p n_comp in the case of Vector valued fields.
53  */
54  FieldFE(unsigned int n_comp=0);
55 
56  /**
57  * Return Record for initialization of FieldFE that is derived from Abstract
58  */
59  static const Input::Type::Record & get_input_type();
60 
61  /**
62  * Return Input selection for discretization type (determines the section of VTK file).
63  */
65 
66  /**
67  * Setter for the finite element data. The mappings are required for computation of local coordinates.
68  * @param dh Dof handler.
69  * @param map1 1D mapping.
70  * @param map2 2D mapping.
71  * @param map3 3D mapping.
72  * @param data Vector of dof values.
73  */
74  void set_fe_data(std::shared_ptr<DOFHandlerMultiDim> dh,
75  MappingP1<1,3> *map1,
76  MappingP1<2,3> *map2,
77  MappingP1<3,3> *map3,
78  VectorSeqDouble *data);
79 
80  /**
81  * Postponed setter of Dof handler.
82  *
83  * Allow to set native Dof handler after set_mesh.
84  * @param dh Dof handler.
85  */
86  void set_native_dh(std::shared_ptr<DOFHandlerMultiDim> dh) override;
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  * Initialization from the input interface.
101  */
102  virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData& init_data);
103 
104 
105  /**
106  * Update time and possibly update data from GMSH file.
107  */
108  bool set_time(const TimeStep &time) override;
109 
110 
111  /**
112  * Set target mesh.
113  */
114  void set_mesh(const Mesh *mesh, bool boundary_domain) override;
115 
116 
117  /**
118  * Copy data vector to given output ElementDataCache
119  */
120  void fill_data_to_cache(ElementDataCache<double> &output_data_cache);
121 
122 
123  /**
124  * Return size of vector of data stored in Field
125  */
126  unsigned int data_size() const;
127 
128 
129  /// Destructor.
130  virtual ~FieldFE();
131 
132 private:
133  /// Create DofHandler object
134  void make_dof_handler(const Mesh *mesh);
135 
136  /// Interpolate data over all elements of target mesh.
138 
139  /// Calculate native data over all elements of target mesh.
141 
142  /// Ensure data setting of methods set_fe_data and set_native_dh.
143  void reinit_fe_data(MappingP1<1,3> *map1,
144  MappingP1<2,3> *map2,
145  MappingP1<3,3> *map3);
146 
147  /// DOF handler object
148  std::shared_ptr<DOFHandlerMultiDim> dh_;
149  /// Store data of Field
151  /// Array of indexes to data_vec_, used for get/set values
153 
154  /// Value handler that allows get value of 0D elements.
156  /// Value handler that allows get value of 1D elements.
158  /// Value handler that allows get value of 2D elements.
160  /// Value handler that allows get value of 3D elements.
162 
163  /**
164  * Used in DOFHandler::distribute_dofs method. Represents 0D element.
165  *
166  * For correct functionality must be created proper descendant of FiniteElement class.
167  */
169  /// Same as previous, but represents 1D element.
171  /// Same as previous, but represents 2D element.
173  /// Same as previous, but represents 3D element.
175 
176  /// mesh reader file
178 
179  /// field name read from input
180  std::string field_name_;
181 
182  /// Specify section where to find the field data in input mesh file
184 
185  /// Field flags.
187 
188  /// Default value of element if not set in mesh data file
190 
191  /// Accessor to Input::Record
193 
194  /// Is set in set_mesh method. Value true means, that we accept only boundary element accessors in the @p value method.
196 
197  /// Flag that determines if source mesh and target mesh are compatible
199 
200  /// Registrar of class to factory
201  static const int registrar;
202 
203  friend class VectorSeqDouble;
204 };
205 
206 
207 #endif /* FIELD_FE_HH_ */
virtual ~FieldFE()
Destructor.
Definition: field_fe.cc:458
Declaration of class which handles the ordering of degrees of freedom (dof) and mappings between loca...
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
Definition: field_fe.cc:181
FEValueHandler< 0, spacedim, Value > value_handler0_
Value handler that allows get value of 0D elements.
Definition: field_fe.hh:155
std::shared_ptr< std::vector< T > > ComponentDataPtr
void interpolate(ElementDataCache< double >::ComponentDataPtr data_vec)
Interpolate data over all elements of target mesh.
Definition: field_fe.cc:349
VectorSeqDouble * data_vec_
Store data of Field.
Definition: field_fe.hh:150
std::string field_name_
field name read from input
Definition: field_fe.hh:180
void fill_data_to_cache(ElementDataCache< double > &output_data_cache)
Definition: field_fe.cc:431
FEValueHandler< 2, spacedim, Value > value_handler2_
Value handler that allows get value of 2D elements.
Definition: field_fe.hh:159
FilePath reader_file_
mesh reader file
Definition: field_fe.hh:177
Definition: mesh.h:80
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
FieldAlgorithmBase< spacedim, Value >::Point Point
Definition: field_fe.hh:48
static const int registrar
Registrar of class to factory.
Definition: field_fe.hh:201
void set_mesh(const Mesh *mesh, bool boundary_domain) override
Definition: field_fe.cc:227
double default_value_
Default value of element if not set in mesh data file.
Definition: field_fe.hh:189
FEValueHandler< 3, spacedim, Value > value_handler3_
Value handler that allows get value of 3D elements.
Definition: field_fe.hh:161
bool set_time(const TimeStep &time) override
Definition: field_fe.cc:304
FiniteElement< 3 > * fe3_
Same as previous, but represents 3D element.
Definition: field_fe.hh:174
FieldAlgorithmBase< spacedim, Value > FactoryBaseType
Definition: field_fe.hh:49
unsigned int data_size() const
Definition: field_fe.cc:451
bool boundary_domain_
Is set in set_mesh method. Value true means, that we accept only boundary element accessors in the va...
Definition: field_fe.hh:195
void set_native_dh(std::shared_ptr< DOFHandlerMultiDim > dh) override
Definition: field_fe.cc:116
OutputTime::DiscreteSpace discretization_
Specify section where to find the field data in input mesh file.
Definition: field_fe.hh:183
std::shared_ptr< DOFHandlerMultiDim > dh_
DOF handler object.
Definition: field_fe.hh:148
static const Input::Type::Record & get_input_type()
Implementation.
Definition: field_fe.cc:47
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Definition: field_fe.cc:157
Affine mapping between reference and actual cell.
Definition: mapping_p1.hh:65
Space< spacedim >::Point Point
void reinit_fe_data(MappingP1< 1, 3 > *map1, MappingP1< 2, 3 > *map2, MappingP1< 3, 3 > *map3)
Ensure data setting of methods set_fe_data and set_native_dh.
Definition: field_fe.cc:125
bool has_compatible_mesh_
Flag that determines if source mesh and target mesh are compatible.
Definition: field_fe.hh:198
void set_fe_data(std::shared_ptr< DOFHandlerMultiDim > dh, MappingP1< 1, 3 > *map1, MappingP1< 2, 3 > *map2, MappingP1< 3, 3 > *map3, VectorSeqDouble *data)
Definition: field_fe.cc:102
FEValueHandler< 1, spacedim, Value > value_handler1_
Value handler that allows get value of 1D elements.
Definition: field_fe.hh:157
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
FiniteElement< 1 > * fe1_
Same as previous, but represents 1D element.
Definition: field_fe.hh:170
static const Input::Type::Selection & get_disc_selection_input_type()
Definition: field_fe.cc:72
FiniteElement< 2 > * fe2_
Same as previous, but represents 2D element.
Definition: field_fe.hh:172
Input::Record in_rec_
Accessor to Input::Record.
Definition: field_fe.hh:192
FieldFE(unsigned int n_comp=0)
Definition: field_fe.cc:91
std::vector< LongIdx > dof_indices_
Array of indexes to data_vec_, used for get/set values.
Definition: field_fe.hh:152
FiniteElement< 0 > * fe0_
Definition: field_fe.hh:168
virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data)
Definition: field_fe.cc:207
Record type proxy class.
Definition: type_record.hh:182
void calculate_native_values(ElementDataCache< double >::ComponentDataPtr data_cache)
Calculate native data over all elements of target mesh.
Definition: field_fe.cc:405
FieldFlag::Flags flags_
Field flags.
Definition: field_fe.hh:186
Representation of one time step..
Template for classes storing finite set of named values.
void make_dof_handler(const Mesh *mesh)
Create DofHandler object.
Definition: field_fe.cc:240
Definition: field.hh:56
unsigned int n_comp() const