Flow123d  jenkins-Flow123d-windows32-release-multijob-51
old_bcd.cc
Go to the documentation of this file.
1 /*
2  * old_bcd.cc
3  *
4  * Created on: Jan 28, 2013
5  * Author: jb
6  */
7 
8 
9 #include "flow/old_bcd.hh"
11 #include "mesh/region.hh"
12 
13 #include "system/tokenizer.hh"
14 #include "boost/lexical_cast.hpp"
15 
17  static OldBcdInput *obcd = new OldBcdInput;
18  return obcd;
19 }
20 
21 #define DIRICHLET 1
22 #define NEUMANN 2
23 #define NEWTON 3
24 
25 void OldBcdInput::read_flow(const Mesh &mesh, const FilePath &flow_bcd)
26 {
27  using namespace boost;
28 
29  vector< unsigned int *> old_to_new_side_numbering;
30 
31  // in the file the sides are numbered according to opposite nodes as they appear in the MSH file
32  unsigned int sides_0 [1] = {0};
33  old_to_new_side_numbering.push_back( sides_0 );
34  unsigned int sides_1 [2] = {0,1};
35  old_to_new_side_numbering.push_back( sides_1 );
36  unsigned int sides_2 [3] = {0,1,2}; //{0,2,1};
37  old_to_new_side_numbering.push_back( sides_2 );
38  unsigned int sides_3 [4] = {0,1,2,3}; //{3,2,1,0};
39  old_to_new_side_numbering.push_back( sides_3 );
40 
41  // check that all fields has same mesh, reuse it for reader
42  mesh_=&mesh;
43  ASSERT(mesh_ , "Null mesh pointer.\n");
44 
45  /*
46  * - read one flow file, fill fields, make ID list
47  * - read second file, check IDs agains ID list, fill fields
48  */
49 
50  flow_type = std::make_shared< FieldEnum >(1);
51  flow_type->set_mesh(mesh_, true);
52  flow_pressure = std::make_shared< FieldScalar >(1);
53  flow_pressure->set_mesh(mesh_, true);
54  flow_flux = std::make_shared< FieldScalar >(1);
55  flow_flux->set_mesh(mesh_, true);
56  flow_sigma = std::make_shared< FieldScalar >(1);
57  flow_sigma->set_mesh(mesh_, true);
58 
59  Tokenizer tok(flow_bcd);
60  try {
61  double scalar, flux, sigma;
62  unsigned int id;
63 
64  xprintf(MsgLog, "Reading old BCD file for flow: %s ...", tok.f_name().c_str());
65  tok.skip_to("$BoundaryConditions");
66  tok.next_line(false);
67  unsigned int n_boundaries = lexical_cast<unsigned int>(*tok); ++tok;
68 
69  for(unsigned int i_bcd=0; i_bcd < n_boundaries; i_bcd++) {
70  tok.next_line();
71 
72  id = lexical_cast<unsigned int>(*tok); ++tok;
73 
74  unsigned int type = lexical_cast<unsigned int>(*tok); ++tok;
75 
76  switch( type ) {
77  case DIRICHLET:
78  scalar = lexical_cast<double>(*tok); ++tok;
79  flux = 0.0;
80  sigma = 0.0;
81  break;
82  case NEUMANN:
83  flux = lexical_cast<double>(*tok); ++tok;
84  sigma = 0.0;
85  scalar = 0.0;
86  break;
87  case NEWTON:
88  scalar = lexical_cast<double>(*tok); ++tok;
89  sigma = lexical_cast<double>(*tok); ++tok;
90  flux = 0.0;
91  break;
92  default :
93  xprintf(UsrErr,"Unknown type of boundary condition - cond # %d, type %c\n", id, type );
94  break;
95  }
96 
97  unsigned int where = lexical_cast<unsigned int>(*tok); ++tok;
98 
99  unsigned int eid, sid, bc_ele_idx, our_sid;
100  Element * ele;
101  Boundary * bcd;
102 
103  switch( where ) {
104  case 2: // SIDE_EL - BC given by element and its local side number
105  eid = lexical_cast<unsigned int>(*tok); ++tok;
106  sid = lexical_cast<unsigned int>(*tok); ++tok;
107 
108  // find and set the side
109  // const cast can be removed when get rid of FullIterators and whole sys_vector stuff
110  // and have correct constantness for mesh classes
111  ele = const_cast<Element *>(mesh_->element.find_id( eid ));
112  if( sid < 0 || sid >= ele->n_sides() )
113  xprintf(UsrErr,"Boundary %d has incorrect reference to side %d\n", id, sid );
114  our_sid=old_to_new_side_numbering[ele->dim()][sid];
115  bcd = ele->side(our_sid) -> cond();
116  if (bcd) {
117  bc_ele_idx = mesh_->bc_elements.index( ele->side(our_sid) -> cond()->element() );
118  id_2_bcd_[id]= bc_ele_idx;
119  if ( ! some_bc_region_.is_valid() ) some_bc_region_ = ele->side(our_sid) -> cond()->element()->region();
120 
121  flow_type->set_data_row( bc_ele_idx, type);
122  flow_pressure->set_data_row(bc_ele_idx, scalar);
123  flow_flux->set_data_row( bc_ele_idx, flux);
124  flow_sigma->set_data_row( bc_ele_idx, sigma);
125  } else {
126  xprintf(Warn, "IGNORING boundary condition %d for non-boundary side %d of element ID: %d\n", id, sid, eid);
127  }
128  break;
129  case 3: // SIDE_E - BC given only by element, apply to all its sides
130 
131  xprintf(UsrErr, "Element only BCD are not supported.\n");
132  break;
133  default:
134  xprintf(UsrErr,"Unknown entity for boundary condition - cond # %d, ent. %c\n", id, where );
135  break;
136  }
137  unsigned int n_tags = lexical_cast<unsigned int>(*tok); ++tok;
138  while (n_tags>0) ++tok, --n_tags; // skip remaining tags
139 
140  }
141  xprintf(MsgLog, "DONE\n");
142  } catch (bad_lexical_cast &) {
143  xprintf(UsrErr, "Wrong format of number, %s.\n", tok.position_msg().c_str());
144  } // flow bcd reader
145 }
146 
147 
148 
149 void OldBcdInput::read_transport(unsigned int n_substances, const FilePath &transport_bcd)
150 {
151  using namespace boost;
152 
153  ASSERT(mesh_ , "Null mesh pointer.\n");
154  trans_conc = std::make_shared< FieldVector >( n_substances );
155  trans_conc->set_mesh(mesh_, true);
156 
157  FieldValue<3>::Vector::return_type ele_value(n_substances);
158 
159  Tokenizer tok(transport_bcd);
160  try {
161  unsigned int bcd_id, boundary_id, bc_ele_idx;
162 
163  xprintf(MsgLog, "Reading old BCD file for transport: %s ...", tok.f_name().c_str());
164  if (tok.skip_to("$Transport_BCDFormat")) tok.next_line(false);
165  tok.skip_to("$Transport_BCD");
166  tok.next_line(false);
167  unsigned int n_bcd = lexical_cast<unsigned int>(*tok); ++tok;
168  for (unsigned int i_bcd = 0; i_bcd < n_bcd; i_bcd++) {
169  tok.next_line();
170  bcd_id = lexical_cast<unsigned int>(*tok); ++tok;
171  boundary_id = lexical_cast<unsigned int>(*tok); ++tok;
172 
174  if (it == id_2_bcd_.end())
175  xprintf(UsrErr,"Wrong boundary index %d for bcd id %d in transport bcd file!", boundary_id, bcd_id);
176  bc_ele_idx = it->second;
177 
178  for (unsigned int sbi = 0; sbi < n_substances; sbi++) {
179  ele_value[sbi] = lexical_cast<double>(*tok); ++tok;
180  }
181 
182  trans_conc->set_data_row(bc_ele_idx, ele_value);
183 
184  }
185 
186  xprintf(MsgLog, "DONE\n");
187 
188  } catch (bad_lexical_cast &) {
189  xprintf(UsrErr, "Wrong format of number, %s.\n", tok.position_msg().c_str());
190  } // flow bcd reader
191 }
shared_ptr< FieldScalar > flow_sigma
Definition: old_bcd.hh:75
const Mesh * mesh_
Definition: old_bcd.hh:155
#define DIRICHLET
Definition: old_bcd.cc:21
shared_ptr< FieldEnum > flow_type
Definition: old_bcd.hh:72
Definition: mesh.h:108
#define NEUMANN
Definition: old_bcd.cc:22
internal::ReturnType< NRows, NCols, ET >::return_type return_type
FullIter find_id(const int id)
Definition: sys_vector.hh:444
Definition: system.hh:72
Old BC setting system for backward compatibility.
Definition: old_bcd.hh:47
unsigned int dim() const
#define ASSERT(...)
Definition: global_defs.h:121
Definition: system.hh:72
shared_ptr< FieldVector > trans_conc
Definition: old_bcd.hh:76
shared_ptr< FieldScalar > flow_flux
Definition: old_bcd.hh:74
unsigned int n_sides() const
#define xprintf(...)
Definition: system.hh:100
#define NEWTON
Definition: old_bcd.cc:23
unsigned int index(const T *pointer) const
Definition: sys_vector.hh:383
ElementVector bc_elements
Definition: mesh.h:206
SideIter side(const unsigned int loc_index)
shared_ptr< FieldScalar > flow_pressure
Definition: old_bcd.hh:73
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
void read_flow(const Mesh &mesh, const FilePath &flow_bcd)
Definition: old_bcd.cc:25
Definition: system.hh:72
Region some_bc_region_
Definition: old_bcd.hh:156
static OldBcdInput * instance()
Definition: old_bcd.cc:16
ElementFullIter element() const
Definition: side_impl.hh:41
void read_transport(unsigned int n_substances, const FilePath &transport_bcd)
Definition: old_bcd.cc:149
bool is_valid() const
Returns false if the region has undefined/invalid value.
Definition: region.hh:67
ElementVector element
Vector of elements of the mesh.
Definition: mesh.h:198