Flow123d  jenkins-Flow123d-linux-release-multijob-198
old_bcd.hh
Go to the documentation of this file.
1 /*
2  * old_bcd.hh
3  *
4  * Created on: Jan 28, 2013
5  * Author: jb
6  */
7 
8 #ifndef OLD_BCD_HH_
9 #define OLD_BCD_HH_
10 
11 
12 #include <map>
13 #include <memory>
14 using namespace std;
15 
16 #include "fields/field.hh"
18 
19 #include "mesh/mesh.h"
20 #include "input/accessors.hh"
21 
22 
23 /**
24  * @brief Old BC setting system for backward compatibility.
25  *
26  * The class provides a singleton object for support of old input files with boundary conditions. The method @p read_flow,
27  * reads the flow boundary file and creates FieldElementwise objects for the BC type, the pressure, the flux and the sigma.
28  * More over it fills map that assigns boundary elements to the boundary IDs. This map si used by possible call of the
29  * @p read_transport method that reads the transport boundary file and creates the FieldElementwise for the boundary concentrations.
30  *
31  * # Flow boundary file #
32  * The boundary condition file for the flow problem contains section @p $BoundaryConditions in which the first line specifies the
33  * number of BC lines. One BC line consists of the boudary face ID, the BC type (1 - Dirichlet, 2 - Neumann, 3 - Robin) followed by
34  * the BC data: the pressure value (Dirichlet BC), or the flux value (Neumann BC), or the pressure and the coefficient (Robin BC).
35  * After the boundary data there is face specification, it consists of the specification type (the value 2 is only supported),
36  * the element ID and index of its side that corresponds to the face.
37  * Sides are numbered from zero to @p dim-1, @p i-th side opposing to the @p i-th
38  * node of the element according to the ordering in specification of the element in the mesh file.
39  *
40  * # Transport boundary file #
41  * Concentration data can be specified only on faces that appears in the flow boundary file. The file has to contain section
42  * @p $Transport_BCD which starts with number of transport BC lines. One transport BC line consists of line ID (ignored),
43  * boundary ID (the BC line ID from the flow boundary file), boundary values for all substances used by the transport module.
44  *
45  *
46  */
47 class OldBcdInput {
48 private:
49 
50 public:
51 
52  /**
53  * Use this to declare the key with filename.
54  */
55  static string flow_old_bcd_file_key() {
56  return "flow_old_bcd_file";
57  }
58  static string transport_old_bcd_file_key() {
59  return "transport_old_bcd_file";
60  }
61 
65 
66  shared_ptr<FieldEnum> flow_type;
67  shared_ptr<FieldScalar> flow_pressure;
68  shared_ptr<FieldScalar> flow_flux;
69  shared_ptr<FieldScalar> flow_sigma;
70  shared_ptr<FieldVector> trans_conc;
71 
72  static OldBcdInput * instance();
73 
74 
75  /**
76  * Factory class (descendant of @p Field<...>::FactoryBase) that is necessary
77  * for backward compatibility with old BCD input files.
78  */
79  template<int spacedim, class Value>
80  class FieldFactory : public Field<spacedim, Value>::FactoryBase {
81  public:
82 
84  typedef std::shared_ptr< FieldElementwiseType > FieldPtr;
85 
86  /**
87  * Constructor.
88  *
89  * We need pointer to std::shared_ptr. Object stored to shared_ptr
90  * doesn't exist during construction.
91  */
93  : field_(field)
94  {}
95 
98  if (rec.record_type_name() == "DarcyFlowMH_Data") {
99  old_bcd->read_flow_record(rec, field);
100  } else if (rec.record_type_name() == "TransportOperatorSplitting_Data") {
101  old_bcd->read_transport_record(rec, field);
102  }
103  return *field_;
104  }
105 
107 
108  };
109 
110  std::shared_ptr< OldBcdInput::FieldFactory<3, FieldValue<3>::Enum> > flow_type_factory;
111  std::shared_ptr< OldBcdInput::FieldFactory<3, FieldValue<3>::Scalar> > flow_pressure_factory;
112  std::shared_ptr< OldBcdInput::FieldFactory<3, FieldValue<3>::Scalar> > flow_flux_factory;
113  std::shared_ptr< OldBcdInput::FieldFactory<3, FieldValue<3>::Scalar> > flow_sigma_factory;
114  std::shared_ptr< OldBcdInput::FieldFactory<3, FieldValue<3>::Vector> > trans_conc_factory;
115 
116  void read_flow_record(Input::Record rec, const FieldCommon &field) {
117  FilePath bcd_file;
118  if (rec.opt_val(flow_old_bcd_file_key(), bcd_file)
119  && string(bcd_file) != flow_input_file_) {
120  ASSERT(field.mesh(),"Null mesh pointer.");
121  read_flow(*(field.mesh()), bcd_file);
122  flow_input_file_ = string(bcd_file);
123  }
124  }
125 
126 
127  inline void read_transport_record(Input::Record rec, const FieldCommon &field);
128 
129  /**
130  * Create flow_* fields from given input file.
131  */
132  void read_flow(const Mesh &mesh, const FilePath &flow_bcd);
133 
134  /**
135  * Create trans_conc field from given input file.
136  */
137  void read_transport(unsigned int n_substances, const FilePath &transport_bcd);
138 
139  /// Maps ID to index of corresponding BC element.
141 
142 private:
143  OldBcdInput();
144 
145  const Mesh *mesh_;
147 
150 
151 
152 };
153 
154 
155 
157  FilePath bcd_file;
158  if (rec.opt_val(transport_old_bcd_file_key(), bcd_file)
159  && string(bcd_file) != transport_input_file_) {
160  ASSERT(field.mesh(),"Null mesh pointer.");
161  read_transport( field.n_comp(), bcd_file);
162  transport_input_file_ = string(bcd_file);
163  }
164 }
165 
166 
167 #endif /* OLD_BCD_HH_ */
std::shared_ptr< OldBcdInput::FieldFactory< 3, FieldValue< 3 >::Enum > > flow_type_factory
Definition: old_bcd.hh:110
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
shared_ptr< FieldScalar > flow_sigma
Definition: old_bcd.hh:69
std::shared_ptr< OldBcdInput::FieldFactory< 3, FieldValue< 3 >::Scalar > > flow_pressure_factory
Definition: old_bcd.hh:111
const Mesh * mesh_
Definition: old_bcd.hh:145
shared_ptr< FieldEnum > flow_type
Definition: old_bcd.hh:66
virtual Field< spacedim, Value >::FieldBasePtr create_field(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:96
FieldElementwise< 3, FieldValue< 3 >::Scalar > FieldScalar
Definition: old_bcd.hh:62
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:52
???
Definition: mesh.h:109
string record_type_name()
Definition: accessors.cc:198
FieldElementwise< 3, FieldValue< 3 >::Vector > FieldVector
Definition: old_bcd.hh:64
FieldElementwise< 3, FieldValue< 3 >::Enum > FieldEnum
Definition: old_bcd.hh:63
Old BC setting system for backward compatibility.
Definition: old_bcd.hh:47
void read_transport_record(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:156
bool opt_val(const string &key, Ret &value) const
std::shared_ptr< OldBcdInput::FieldFactory< 3, FieldValue< 3 >::Scalar > > flow_flux_factory
Definition: old_bcd.hh:112
#define ASSERT(...)
Definition: global_defs.h:121
shared_ptr< FieldVector > trans_conc
Definition: old_bcd.hh:70
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
shared_ptr< FieldScalar > flow_flux
Definition: old_bcd.hh:68
std::shared_ptr< OldBcdInput::FieldFactory< 3, FieldValue< 3 >::Scalar > > flow_sigma_factory
Definition: old_bcd.hh:113
static string flow_old_bcd_file_key()
Definition: old_bcd.hh:55
std::shared_ptr< FieldElementwiseType > FieldPtr
Definition: old_bcd.hh:84
shared_ptr< FieldScalar > flow_pressure
Definition: old_bcd.hh:67
static string transport_old_bcd_file_key()
Definition: old_bcd.hh:58
map< unsigned int, unsigned int > id_2_bcd_
Maps ID to index of corresponding BC element.
Definition: old_bcd.hh:140
Dedicated class for storing path to input and output files.
Definition: file_path.hh:32
Region some_bc_region_
Definition: old_bcd.hh:146
std::shared_ptr< FieldBaseType > FieldBasePtr
Definition: field.hh:56
static OldBcdInput * instance()
Definition: old_bcd.cc:30
string transport_input_file_
Definition: old_bcd.hh:149
string flow_input_file_
Definition: old_bcd.hh:148
std::shared_ptr< OldBcdInput::FieldFactory< 3, FieldValue< 3 >::Vector > > trans_conc_factory
Definition: old_bcd.hh:114
const Mesh * mesh() const
unsigned int n_comp() const
FieldFactory(FieldPtr *field)
Definition: old_bcd.hh:92
FieldElementwise< spacedim, Value > FieldElementwiseType
Definition: old_bcd.hh:83