Flow123d  jenkins-Flow123d-linux-release-multijob-282
multi_field.hh
Go to the documentation of this file.
1 /*
2  * multi_field.hh
3  *
4  * Created on: Feb 13, 2014
5  * Author: jb
6  */
7 
8 #ifndef MULTI_FIELD_HH_
9 #define MULTI_FIELD_HH_
10 
11 using namespace std;
12 
13 
14 #include "fields/field.hh"
15 #include "fields/field_common.hh"
16 
17 
18 namespace IT=Input::Type;
19 
20 /**
21  * @brief Class for representation of a vector of fields of the same physical quantity.
22  *
23  * When solving a system of same equations with the number of components given at runtime
24  * (as in the case of transport equation for runtime given number of substances) we need means how to work with the whole
25  * vector of fields at once. This is the aim of this class. It provides the interface given by the parent class @p FieldCommonBase,
26  * but principally it is just a vector of Field<Value,dim> objects. The sub-fields or components of a @p MultiField are independent
27  * objects, how ever the setters propagates the values from the MultiFields to the individual fields. The only exception is the
28  * @p set_name method which in conjunction with @p MultiField::set_subfield_names can set unique name to each component.
29  *
30  * Template parameters are used for every subfield.
31  *
32  * TODO:
33  * - general mechanism how to convert a Field< dim, Vector> to MultiField< dim, Value>
34  * - implement set_from_input
35  * - implement set_Time
36  *
37  * - problem with "input" methods, since Field works with AbstratRecord, the MultiField - However - should use Array of AbstractRecords
38  * simplest solution - test that in EqDataBase and have more methods in FieldCommonBase, or somehow detach input handling from
39  * Fields
40  *
41  * Definition of MultiField must be in separate file.
42  * In other case source file field.cc is too big and compiler can throw compile error.
43  */
44 template<int spacedim, class Value>
45 class MultiField : public FieldCommon {
46 public:
47  //typedef FieldBase<spacedim, Value> SubFieldBaseType;
50 
51  class MultiFieldFactory : public Field<spacedim, Value>::FactoryBase {
52  public:
53  /// Constructor.
54  MultiFieldFactory(unsigned int index)
55  : index_(index) {}
56 
57  virtual typename Field<spacedim, Value>::FieldBasePtr create_field(Input::Record rec, const FieldCommon &field);
58 
59  unsigned int index_;
60  };
61 
62  /**
63  * Default constructor.
64  */
65  MultiField();
66 
67  /**
68  * Returns input type of particular field instance, this is usually static member input_type of the corresponding FieldBase class (
69  * with same template parameters), however, for fields returning "Enum" we have to create whole unique Input::Type hierarchy for
70  * every instance since every such field use different Selection for initialization, even if all returns just unsigned int.
71  */
72  IT::AbstractRecord &get_input_type() override;
73 
74  IT::Record &get_multifield_input_type() override;
75 
76  /**
77  * Abstract method to update field to the new time level.
78  * Implemented by in class template Field<...>.
79  *
80  * Return true if the value of the field was changed on some region.
81  * The returned value is also stored in @p changed_during_set_time data member.
82  *
83  * In first call initialize MultiField to the number of components given by the size of @p names
84  * and use this vector to name individual components. Should be called after the setters derived from
85  * FieldCommonBase.
86  */
87  bool set_time(const TimeStep &time) override;
88 
89  /**
90  * We have to override the @p set_mesh method in order to call set_mesh method for subfields.
91  */
92  void set_mesh(const Mesh &mesh) override;
93 
94 
95  /**
96  * Polymorphic copy. Check correct type, allows copy of MultiField or Field.
97  */
98  void copy_from(const FieldCommon & other) override;
99 
100  /**
101  * Implementation of @p FieldCommonBase::output().
102  */
103  void output(OutputTime *stream) override;
104 
105  /**
106  * Implementation of @p FieldCommonBase::is_constant().
107  */
108  bool is_constant(Region reg) override;
109 
110  /**
111  * Virtual destructor.
112  */
113  inline virtual ~MultiField() {}
114 
115  /// Number of subfields that compose the multi-field.
116  inline unsigned int size() const
117  { return sub_fields_.size(); }
118 
119  /**
120  * Returns reference to the sub-field (component) of given index @p idx.
121  */
122  inline SubFieldType &operator[](unsigned int idx)
123  {
124  ASSERT(idx < sub_fields_.size(), "Index of subfield is out of range.\n");
125  return sub_fields_[idx];
126  }
127 
128  /**
129  * Initialize components of MultiField.
130  *
131  * Must be call after setting components, mesh and limit side.
132  */
133  void set_up_components();
134 
135 private:
137 
138  /// Helper class members, used only for input record
141 };
142 
143 
144 #endif /* MULTI_FIELD_HH_ */
Common abstract parent of all Field&lt;...&gt; classes.
Definition: field_common.hh:47
unsigned int size() const
Number of subfields that compose the multi-field.
Definition: multi_field.hh:116
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:52
Field< spacedim, Value > SubFieldType
Definition: multi_field.hh:48
Definition: mesh.h:109
#define ASSERT(...)
Definition: global_defs.h:121
std::vector< SubFieldType > sub_fields_
Definition: multi_field.hh:136
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
MultiFieldFactory(unsigned int index)
Constructor.
Definition: multi_field.hh:54
Class for declaration of polymorphic Record.
Definition: type_record.hh:487
The class for outputting data during time.
Definition: output_time.hh:32
Field< spacedim, typename FieldValue< spacedim >::Vector > TransposedField
Definition: multi_field.hh:49
SubFieldType sub_field_type_
Helper class members, used only for input record.
Definition: multi_field.hh:139
TransposedField transposed_field_
Definition: multi_field.hh:140
std::shared_ptr< FieldBaseType > FieldBasePtr
Definition: field.hh:56
virtual ~MultiField()
Definition: multi_field.hh:113
Record type proxy class.
Definition: type_record.hh:169
Class for representation of a vector of fields of the same physical quantity.
Definition: multi_field.hh:45
SubFieldType & operator[](unsigned int idx)
Definition: multi_field.hh:122
Representation of one time step.