Flow123d  jenkins-Flow123d-windows32-release-multijob-51
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 public:
49 
50  /**
51  * Use this to declare the key with filename.
52  */
53  static string flow_old_bcd_file_key() {
54  return "flow_old_bcd_file";
55  }
56  static string transport_old_bcd_file_key() {
57  return "transport_old_bcd_file";
58  }
59 
63 
67 
71 
72  shared_ptr<FieldEnum> flow_type;
73  shared_ptr<FieldScalar> flow_pressure;
74  shared_ptr<FieldScalar> flow_flux;
75  shared_ptr<FieldScalar> flow_sigma;
76  shared_ptr<FieldVector> trans_conc;
77 
78  static OldBcdInput * instance();
79 
80  // hooks
83  auto field_ptr=Field_Enum::read_field_descriptor(rec, field);
84  if (field_ptr) return field_ptr;
85  else {
86  old_bcd->read_flow_record(rec, field);
87  return old_bcd->flow_type;
88  }
89  }
92  auto field_ptr= Field_Scalar::read_field_descriptor(rec, field);
93  if (field_ptr) return field_ptr;
94  else {
95  old_bcd->read_flow_record(rec, field);
96  return old_bcd->flow_pressure;
97  }
98  }
100  OldBcdInput *old_bcd = OldBcdInput::instance();
101  auto field_ptr = Field_Scalar::read_field_descriptor(rec, field);
102  if (field_ptr) return field_ptr;
103  else {
104  old_bcd->read_flow_record(rec, field);
105  return old_bcd->flow_flux;
106  }
107  }
109  OldBcdInput *old_bcd = OldBcdInput::instance();
110  auto field_ptr = Field_Scalar::read_field_descriptor(rec, field);
111  if (field_ptr) return field_ptr;
112  else {
113  old_bcd->read_flow_record(rec, field);
114  return old_bcd->flow_sigma;
115  }
116  }
118  OldBcdInput *old_bcd = OldBcdInput::instance();
119  auto field_ptr = Field_Vector::read_field_descriptor(rec,field);
120  if (field_ptr) return field_ptr;
121  else {
122  old_bcd->read_transport_record( rec, field);
123  return old_bcd->trans_conc;
124  }
125  }
126 
127  void read_flow_record(Input::Record rec, const FieldCommon &field) {
128  FilePath bcd_file;
129  if (rec.opt_val(flow_old_bcd_file_key(), bcd_file)
130  && string(bcd_file) != flow_input_file_) {
131  ASSERT(field.mesh(),"Null mesh pointer.");
132  read_flow(*(field.mesh()), bcd_file);
133  flow_input_file_ = string(bcd_file);
134  }
135  }
136 
137 
138  inline void read_transport_record(Input::Record rec, const FieldCommon &field);
139 
140 
141  /**
142  * Create flow_* fields from given input file.
143  */
144  void read_flow(const Mesh &mesh, const FilePath &flow_bcd);
145 
146  /**
147  * Create trans_conc field from given input file.
148  */
149  void read_transport(unsigned int n_substances, const FilePath &transport_bcd);
150 
151  /// Maps ID to index of corresponding BC element.
153 
154 private:
155  const Mesh *mesh_;
157 
160 
161 
162 };
163 
164 
165 
167  FilePath bcd_file;
168  if (rec.opt_val(transport_old_bcd_file_key(), bcd_file)
169  && string(bcd_file) != transport_input_file_) {
170  ASSERT(field.mesh(),"Null mesh pointer.");
171  read_transport( field.n_comp(), bcd_file);
172  transport_input_file_ = string(bcd_file);
173  }
174 }
175 
176 #endif /* OLD_BCD_HH_ */
void read_flow_record(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:127
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:45
Field< 3, FieldValue< 3 >::Enum > Field_Enum
Definition: old_bcd.hh:65
shared_ptr< FieldScalar > flow_sigma
Definition: old_bcd.hh:75
const Mesh * mesh_
Definition: old_bcd.hh:155
Field< 3, FieldValue< 3 >::Vector > Field_Vector
Definition: old_bcd.hh:66
shared_ptr< FieldEnum > flow_type
Definition: old_bcd.hh:72
FieldElementwise< 3, FieldValue< 3 >::Scalar > FieldScalar
Definition: old_bcd.hh:60
Class template representing a field with values dependent on: point, element, and region...
Definition: field.hh:48
Field_Scalar::FieldBasePtr FieldBaseScalar
Definition: old_bcd.hh:68
???
Definition: mesh.h:108
Field_Enum::FieldBasePtr FieldBaseEnum
Definition: old_bcd.hh:69
static FieldBaseVector trans_conc_hook(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:117
FieldElementwise< 3, FieldValue< 3 >::Vector > FieldVector
Definition: old_bcd.hh:62
FieldElementwise< 3, FieldValue< 3 >::Enum > FieldEnum
Definition: old_bcd.hh:61
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:166
bool opt_val(const string &key, Ret &value) const
static FieldBaseScalar flow_pressure_hook(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:90
#define ASSERT(...)
Definition: global_defs.h:121
shared_ptr< FieldVector > trans_conc
Definition: old_bcd.hh:76
Accessor to the data with type Type::Record.
Definition: accessors.hh:308
shared_ptr< FieldScalar > flow_flux
Definition: old_bcd.hh:74
Field< 3, FieldValue< 3 >::Scalar > Field_Scalar
Definition: old_bcd.hh:64
static string flow_old_bcd_file_key()
Definition: old_bcd.hh:53
Field_Vector::FieldBasePtr FieldBaseVector
Definition: old_bcd.hh:70
shared_ptr< FieldScalar > flow_pressure
Definition: old_bcd.hh:73
static string transport_old_bcd_file_key()
Definition: old_bcd.hh:56
static FieldBaseEnum flow_type_hook(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:81
map< unsigned int, unsigned int > id_2_bcd_
Maps ID to index of corresponding BC element.
Definition: old_bcd.hh:152
Dedicated class for storing path to input and output files.
Definition: file_path.hh:32
Region some_bc_region_
Definition: old_bcd.hh:156
std::shared_ptr< FieldBaseType > FieldBasePtr
Definition: field.hh:52
static OldBcdInput * instance()
Definition: old_bcd.cc:16
string transport_input_file_
Definition: old_bcd.hh:159
string flow_input_file_
Definition: old_bcd.hh:158
const Mesh * mesh() const
unsigned int n_comp() const
static FieldBaseScalar flow_flux_hook(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:99
static FieldBaseScalar flow_sigma_hook(Input::Record rec, const FieldCommon &field)
Definition: old_bcd.hh:108