30 #include <boost/multi_index_container.hpp>
31 #include <boost/multi_index/ordered_index.hpp>
32 #include <boost/multi_index/random_access_index.hpp>
33 #include <boost/multi_index/hashed_index.hpp>
34 #include <boost/multi_index/member.hpp>
36 namespace BMI=::boost::multi_index;
42 namespace Type {
class Record; }
67 {
return !(
idx_ & 1); }
74 inline unsigned int idx()
const
155 std::string
label()
const;
158 unsigned int id()
const;
161 unsigned int dim()
const;
167 //inline explicit operator RegionIdx() const {
168 // return RegionIdx(this->idx_);
242 typedef std::vector<RegionIdx> RegionSet;
243 std::map<std::string, RegionSet > sets_;
246 add_to_set( const string& set_name, RegionIdx region);
249 add_set( const string& set_name, const RegionSet & set);
250 RegionSet union( const string & set_name_1, const string & set_name_2); // sort + std::set_union
251 RegionSet intersection( const string & set_name_1, const string & set_name_2);
252 RegionSet difference( const string & set_name_1, const string & set_name_2);
253 const RegionSet & get_set(const string & set_name);
254 void read_sets_from_input(Input::Record rec); // see structure of RegionDB::region_set_input_type
258 region_ids=[ int ...],
259 region_labels= ["..."], // these are merger together
261 union=["set_1", "set_2"], // later overwrites previous
267 * - MODIFICATION IN MESH AND READER:
268 * Mesh reading proccess:
269 * 1) Read PhysicalNames form GMSH file, populate RegionDB (DONE in GMSH reader, may need small modifications)
270 * 2) Read region definitions from the input, see
272 * typedef std::map<unsigned int, unsigned int> MapElementIDToRegionID;
273 * RegionDB::read_regions_from_input(Input::Array region_list, MapElementIDToRegionID &map);
276 * (TODO in RegionDB, also creates (and return to Mesh) element regions modification map: std::map< unsigned int, RegionIdx>
277 * that maps element IDs to the new region names, GMSH reader should have setter method to accept this map
278 * and modify the elements during reading)
279 * 3) Read region sets - TODO in RegionDB
280 * 4) Read boundary key of the Mesh record and mark appropriate regions as boundary (TODO in RegionDB)
281 * 5) Read nodes (DONE in GMSH reader)
282 * 6) Read elements, per element:
283 * - possibly modify region according map
285 * if found: add_region(ID, get_label, dim, get_boundary_flag) // possibly set dimension of the region if it is undefined
286 * not found: add_region(ID, default_label, dim, false)
287 * - if region is boundary put element into Mesh::bc_elements
288 * else put it into Mesh::element
290 * 7) Setup topology - we has to connect Boundary with existing bc_elements, and add the remaining elements,
291 * after we remove support for old bCD files we may skip creation of remaining boundary elements since there will be no way how to set
316 DECLARE_EXCEPTION( ExcAddingIntoClosed, <<
"Can not add label=" << EI_Label::qval <<
" into closed MaterialDispatch.\n");
318 DECLARE_EXCEPTION( ExcNonuniqueID, <<
"Non-unique ID during add of region id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
319 <<
"other region with same ID but different label: " << EI_LabelOfOtherID::qval <<
" already exists\n");
320 DECLARE_EXCEPTION( ExcNonuniqueLabel, <<
"Non-unique label during add of region id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
321 <<
"other region with same label but different ID: " << EI_IDOfOtherLabel::val <<
" already exists\n");
322 DECLARE_EXCEPTION( ExcInconsistentBoundary, <<
"Inconsistent add of region with id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
323 <<
"both ID and label match an existing region with different boundary flag.");
324 DECLARE_EXCEPTION( ExcInconsistentDimension, <<
"Inconsistent add of region with id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
325 <<
"both ID and label match an existing region with different dimension.");
327 DECLARE_EXCEPTION( ExcCantAdd, <<
"Can not add new region into DB, id: " << EI_ID::val <<
", label: " << EI_Label::qval);
329 DECLARE_EXCEPTION( ExcUnknownSet, <<
"Operation with unknown region set: " << EI_Label::qval );
372 Region add_region(
unsigned int id,
const std::string &label,
unsigned int dim);
393 const std::string &
get_label(
unsigned int idx)
const;
398 unsigned int get_id(
unsigned int idx)
const;
403 unsigned int get_dim(
unsigned int idx)
const;
415 unsigned int size()
const;
520 : index(index), id(id), label(label),
dim_(dim) {}
536 typedef BMI::multi_index_container<
545 BMI::ordered_unique< BMI::tag<Index>, BMI::member<RegionItem, unsigned int, &RegionItem::index > >,
547 BMI::hashed_unique< BMI::tag<ID>, BMI::member<RegionItem, unsigned int, &RegionItem::id> >,
549 BMI::ordered_unique< BMI::tag<Label>, BMI::member<RegionItem, std::string, &RegionItem::label> >
554 typedef RegionTable::index<Label>::type::iterator
LabelIter;
555 typedef RegionTable::index<ID>::type::iterator
IDIter;
std::map< std::string, RegionSet > sets_
Map of region sets.
void prepare_sets(const string &set_name_1, const string &set_name_2, RegionSet &set_1, RegionSet &set_2)
unsigned int size() const
const std::string & get_label(unsigned int idx) const
pair< string, string > get_and_check_operands(const Input::Array &operands)
void read_regions_from_input(Input::Array region_list, MapElementIDToRegionID &map)
RegionIdx()
Default region is undefined/invalid.
bool is_boundary() const
Allow implicit conversion from Region. We loose information about input ID, label, dim stored in database.
void read_sets_from_input(Input::Array arr)
RegionSet union_sets(const string &set_name_1, const string &set_name_2)
std::map< unsigned int, unsigned int > MapElementIDToRegionID
unsigned int bulk_size() const
void check_dim_consistency(IDIter it_id, unsigned int dim)
Consistency check in common use by various add_region methods.
RegionSet get_region_set(const string &set_name) const
RegionItem(unsigned int index, unsigned int id, const std::string &label, unsigned int dim)
static bool comp(const Region &a, const Region &b)
Comparative method of two regions.
void add_set(const string &set_name, const RegionSet &set)
static const unsigned int undefined
index for undefined region
DECLARE_INPUT_EXCEPTION(ExcUnknownSetOperand,<< "Operation with unknown region set: "<< EI_Label::qval)
Region add_region(unsigned int id, const std::string &label, unsigned int dim, bool boundary)
One item in region database.
std::vector< Region > RegionSet
const RegionDB * db_
Global variable with information about all regions.
unsigned int boundary_idx() const
Returns index of the region in the boundary set.
Global macros to enhance readability and debugging, general constants.
RegionIdx operator()(const Region &)
Region implicit_boundary_
void add_to_set(const string &set_name, Region region)
Region find_id(unsigned int id) const
RegionTable::index< Label >::type::iterator LabelIter
Region implicit_boundary_region()
unsigned int n_bulk_
Number of bulk regions.
RegionDB()
Default constructor.
RegionIdx(unsigned int index)
bool operator!=(const RegionIdx &other) const
Equality comparison operators for regions.
BMI::multi_index_container< RegionItem, BMI::indexed_by< BMI::ordered_unique< BMI::tag< Index >, BMI::member< RegionItem, unsigned int,&RegionItem::index > >, BMI::hashed_unique< BMI::tag< ID >, BMI::member< RegionItem, unsigned int,&RegionItem::id > >, BMI::ordered_unique< BMI::tag< Label >, BMI::member< RegionItem, std::string,&RegionItem::label > > > > RegionTable
Region database.
static const unsigned int max_n_regions
unsigned int get_id(unsigned int idx) const
RegionSet difference(const string &set_name_1, const string &set_name_2)
static Input::Type::Record region_input_type
unsigned int boundary_size() const
RegionSet all
Make part of general RegionSet table.
RegionSet intersection(const string &set_name_1, const string &set_name_2)
unsigned int get_dim(unsigned int idx) const
RegionTable region_set_
Database of all regions (both boundary and bulk).
unsigned int bulk_idx() const
Returns index of the region in the bulk set.
Region(RegionIdx r_idx, const RegionDB &db)
TYPEDEF_ERR_INFO(EI_Label, const std::string)
static const unsigned int undefined_dim
Region find_label(const std::string &label) const
bool is_valid() const
Returns false if the region has undefined/invalid value.
std::string label() const
Returns label of the region (using RegionDB)
static Input::Type::Record region_set_input_type
Region(unsigned int index, const RegionDB &db)
bool closed_
flag for closed database, no regions can be added, but you can add region sets
Region()
Default region is undefined/invalid.
bool operator==(const RegionIdx &other) const
Equality comparison operators for regions.
unsigned int n_boundary_
Number of boundary regions.
RegionTable::index< ID >::type::iterator IDIter
unsigned int id() const
Returns id of the region (using RegionDB)
unsigned int dim() const
Returns dimension of the region.
DECLARE_EXCEPTION(ExcAddingIntoClosed,<< "Can not add label="<< EI_Label::qval<< " into closed MaterialDispatch.\n")
unsigned int idx() const
Returns a global index of the region.