Flow123d  jenkins-Flow123d-linux-release-multijob-282
field_add_potential.hh
Go to the documentation of this file.
1 /*
2  * field_add_potential.hh
3  *
4  * Created on: Jan 19, 2013
5  * Author: jb
6  */
7 
8 #ifndef FIELD_ADD_POTENTIAL_HH_
9 #define FIELD_ADD_POTENTIAL_HH_
10 
11 #include <armadillo>
12 #include <memory>
13 
14 #include "fields/field.hh"
15 #include "flow/old_bcd.hh"
16 
17 
18 /**
19  * This field is meant to be used to implement two possibilities for initialization of pressure fields in
20  * Darcy flows. You can either use pressure of piezo-metric head which are related by adding gravity potential.
21  * For various reasons we use pressure as the primary variable, so if the user enters piezo-head we need to add the potential to
22  * the field he/she has provided. This is done by this class. Unfortunately it introduce one more level of indirection,
23  * namely one more virtual call for getting the field value.
24  *
25  * - The field can not be initialized form the input.
26  * - We allow only Scalar Value with element_type double.
27  */
28 template <int spacedim, class Value>
29 class FieldAddPotential : public FieldAlgorithmBase<spacedim, Value> {
30 public:
32  typedef typename Space<spacedim>::Point Point;
33  /**
34  *
35  */
36  FieldAddPotential( const arma::vec::fixed<spacedim+1> &potential_grad, const Input::AbstractRecord &rec, unsigned int n_comp=0);
37 
38 
39  /**
40  * Factory class (descendant of @p Field<...>::FactoryBase) that is necessary
41  * for setting pressure values are piezometric head values.
42  */
43  class FieldFactory : public FactoryBaseType {
44  public:
45  /// Constructor.
46  FieldFactory(arma::vec::fixed<spacedim+1> potential, std::string field_name)
47  : potential_(potential),
48  field_name_(field_name)
49  {}
50 
53  old_bcd->read_flow_record(rec, field);
54  auto field_ptr = old_bcd->flow_pressure;
55 
56  Input::AbstractRecord field_a_rec;
57  if (! field_ptr && rec.opt_val(field_name_, field_a_rec)) {
58  return std::make_shared< FieldAddPotential<3, FieldValue<3>::Scalar > >( potential_, field_a_rec);
59  } else {
60  return field_ptr;
61  }
62  }
63 
64  arma::vec::fixed<spacedim+1> potential_;
65  std::string field_name_;
66  };
67 
68 
69  /**
70  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
71  */
72  virtual typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm);
73 
74  /**
75  * Returns std::vector of scalar values in several points at once.
76  */
77  virtual void value_list (const std::vector< Point > &point_list, const ElementAccessor<spacedim> &elm,
79 
80 
81  /**
82  * Update time and possibly update data.
83  */
84  bool set_time(const TimeStep &time) override;
85 
86 
87  virtual ~FieldAddPotential();
88 
89 private:
90  /// Field to which we add linear potential.
91  std::shared_ptr< FieldAlgorithmBase<spacedim, Value> > inner_field_;
92  /// Potential gradient.
93  arma::vec::fixed<spacedim> grad_;
94  /// Potential constant term.
95  double zero_level_;
96 };
97 
98 
99 #endif /* FIELD_ADD_POTENTIAL_HH_ */
void read_flow_record(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:116
Common abstract parent of all Field&lt;...&gt; classes.
Definition: field_common.hh:47
bool set_time(const TimeStep &time) override
arma::vec::fixed< spacedim > grad_
Potential gradient.
FieldAddPotential(const arma::vec::fixed< spacedim+1 > &potential_grad, const Input::AbstractRecord &rec, unsigned int n_comp=0)
Old BC setting system for backward compatibility.
Definition: old_bcd.hh:47
bool opt_val(const string &key, Ret &value) const
virtual Field< spacedim, Value >::FieldBasePtr create_field(Input::Record rec, const FieldCommon &field)
FieldFactory(arma::vec::fixed< spacedim+1 > potential, std::string field_name)
Constructor.
arma::vec::fixed< spacedim > Point
Definition: point.hh:23
double zero_level_
Potential constant term.
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
shared_ptr< FieldScalar > flow_pressure
Definition: old_bcd.hh:67
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:448
std::shared_ptr< FieldBaseType > FieldBasePtr
Definition: field.hh:56
static OldBcdInput * instance()
Definition: old_bcd.cc:30
Field< spacedim, Value >::FactoryBase FactoryBaseType
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)
arma::vec::fixed< spacedim+1 > potential_
std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > inner_field_
Field to which we add linear potential.
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Representation of one time step.
Space< spacedim >::Point Point
unsigned int n_comp() const