Flow123d
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 
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 FieldCommonBase &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  /*
156  template <int spacedim, class Value>
157  void set_all( Field<spacedim,Value> &target, const Mesh *mesh);
158 
159  template <int spacedim, class Value>
160  void set_field( Field<spacedim,Value> &target, unsigned int bcd_ele_idx, typename Value::return_type &val);
161 */
162  const Mesh *mesh_;
164 
167 
168 
169 };
170 
171 
172 
174  FilePath bcd_file;
175  if (rec.opt_val(transport_old_bcd_file_key(), bcd_file)
176  && string(bcd_file) != transport_input_file_) {
177  ASSERT(field.mesh(),"Null mesh pointer.");
178  read_transport( field.n_comp(), bcd_file);
179  transport_input_file_ = string(bcd_file);
180  }
181 }
182 
183 #endif /* OLD_BCD_HH_ */