35 #include <boost/exception/detail/error_info_impl.hpp> 36 #include <boost/exception/info.hpp> 37 #include <boost/multi_index/hashed_index.hpp> 38 #include <boost/multi_index/identity_fwd.hpp> 39 #include <boost/multi_index/indexed_by.hpp> 40 #include <boost/multi_index/mem_fun.hpp> 41 #include <boost/multi_index/member.hpp> 42 #include <boost/multi_index/ordered_index.hpp> 43 #include <boost/multi_index/tag.hpp> 44 #include <boost/multi_index_container.hpp> 45 #include <boost/serialization/split_member.hpp> 51 namespace BMI=::boost::multi_index;
75 {
return !(idx_ & 1); }
82 inline unsigned int idx()
const 87 OLD_ASSERT( is_boundary(),
"Try to get boundary index of a bulk region with internal idx: %d\n", idx_ );
92 OLD_ASSERT( ! is_boundary(),
"Try to get bulk index of boundary region with internal idx: %d\n", idx_ );
97 {
return idx_ == other.
idx_; }
101 {
return idx_ != other.
idx_; }
177 std::string label()
const;
180 unsigned int id()
const;
183 unsigned int dim()
const;
193 bool is_in_region_set(
const RegionSet &
set)
const;
247 typedef std::vector<RegionIdx> RegionSet;
248 std::map<std::string, RegionSet > sets_;
251 add_to_set( const string& set_name, RegionIdx region);
254 add_set( const string& set_name, const RegionSet & set);
255 RegionSet union( const string & set_name_1, const string & set_name_2); // sort + std::set_union
256 RegionSet intersection( const string & set_name_1, const string & set_name_2);
257 RegionSet difference( const string & set_name_1, const string & set_name_2);
258 const RegionSet & get_set(const string & set_name);
259 void read_sets_from_input(Input::Record rec); // see structure of RegionDB::get_region_set_input_type()
263 region_ids=[ int ...],
264 region_labels= ["..."], // these are merger together
266 union=["set_1", "set_2"], // later overwrites previous
272 * - MODIFICATION IN MESH AND READER:
273 * Mesh reading proccess:
274 * 1) Read PhysicalNames form GMSH file, populate RegionDB (DONE in GMSH reader, may need small modifications)
275 * 2) Read region definitions from the input, see
276 * - Mesh::read_regions_from_input(Input::Array region_list);
277 * 3) Read nodes (DONE in GMSH reader)
278 * 4) Read elements, per element:
279 * - possibly modify region according map
281 * if found: add_region(ID, get_label, dim, get_boundary_flag) // possibly set dimension of the region if it is undefined
282 * not found: add_region(ID, default_label, dim, false)
283 * - if region is boundary put element into Mesh::element_vec_
284 * else put it into Mesh::element
286 * 5) Setup topology - we has to connect Boundary with existing boundary elements, and add the remaining elements,
287 * 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
303 DECLARE_INPUT_EXCEPTION( ExcAddingIntoClosed, <<
"Can not add label=" << EI_Label::qval <<
" into closed MaterialDispatch.\n");
304 DECLARE_EXCEPTION( ExcNonuniqueID, <<
"Non-unique ID during add of elementary region id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
305 <<
"other elementary region with same ID but different label: " << EI_LabelOfOtherID::qval <<
" already exists\n");
306 DECLARE_INPUT_EXCEPTION( ExcNonuniqueLabel, <<
"Non-unique label during add of elementary region id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
307 <<
"other elementary region with same label but different ID: " << EI_IDOfOtherLabel::val <<
" already exists\n");
308 DECLARE_EXCEPTION( ExcInconsistentBoundary, <<
"Inconsistent add of elementary region with id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
309 <<
"both ID and label match an existing elementary region with different boundary flag.");
311 DECLARE_INPUT_EXCEPTION( ExcCantAdd, <<
"Can not add new elementary region into DB, id: " << EI_ID::val <<
", label: " << EI_Label::qval);
353 Region add_region(
unsigned int id,
const std::string &label,
unsigned int dim,
const std::string &address =
"implicit");
358 Region rename_region(
Region reg,
const std::string &new_label );
365 Region get_region(
unsigned int id,
unsigned int dim);
370 Region find_label(
const std::string &label)
const;
376 Region find_id(
unsigned int id,
unsigned int dim)
const;
381 Region find_id(
unsigned int id)
const;
386 const std::string &get_label(
unsigned int idx)
const;
391 unsigned int get_id(
unsigned int idx)
const;
396 unsigned int get_dim(
unsigned int idx)
const;
408 unsigned int size()
const;
413 unsigned int boundary_size()
const;
418 unsigned int bulk_size()
const;
424 Region implicit_boundary_region();
432 void add_to_set(
const std::string& set_name,
Region region);
440 void add_set(
const std::string& set_name,
const RegionSet &
set);
451 RegionSet get_region_set(
const std::string & set_name)
const;
462 void print_region_table(std::ostream& stream)
const;
469 std::string create_label_from_id(
unsigned int id)
const;
474 const std::string & get_region_address(
unsigned int idx)
const;
481 void mark_used_region(
unsigned int idx);
492 typedef std::pair<unsigned int, unsigned int>
DimID;
496 RegionItem(
unsigned int index,
unsigned int id,
const std::string &label,
unsigned int dim,
const std::string &address,
bool used=
false)
497 : index(index), id(dim, id), label(label), used(used), address(address) {}
499 unsigned int get_id()
const {
return id.second;}
500 unsigned int dim()
const {
return id.first;}
519 typedef BMI::multi_index_container<
528 BMI::ordered_unique< BMI::tag<Index>, BMI::member<RegionItem, unsigned int, &RegionItem::index > >,
530 BMI::hashed_unique< BMI::tag<DimId>, BMI::member<RegionItem, DimID, &RegionItem::id> >,
532 BMI::hashed_non_unique< BMI::tag<OnlyID>, BMI::const_mem_fun<RegionItem, unsigned int, &RegionItem::get_id> >,
534 BMI::ordered_unique< BMI::tag<Label>, BMI::member<RegionItem, std::string, &RegionItem::label> >
539 typedef RegionTable::index<Label>::type::iterator
LabelIter;
540 typedef RegionTable::index<DimId>::type::iterator
DimIDIter;
541 typedef RegionTable::index<OnlyID>::type::iterator
OnlyIDIter;
576 Region insert_region(
unsigned int id,
const std::string &label,
unsigned int dim,
bool boundary,
const std::string &address);
581 Region replace_region_dim(DimIDIter it_undef_dim,
unsigned int dim,
bool boundary);
586 Region find_by_dimid(DimIDIter it_id,
unsigned int id,
const std::string &label,
bool boundary);
594 void erase_from_set(
const std::string& set_name,
Region region);
601 void check_regions();
607 return (label.size() != 0) && (label[0] ==
'.');
RegionIdx()
Default region is undefined/invalid.
bool is_boundary() const
Returns true if it is a Boundary region and false if it is a Bulk region.
std::map< unsigned int, unsigned int > MapElementIDToRegionID
MapElementIDToRegionID el_to_reg_map_
RegionSetTable sets_
Map of region sets.
static bool comp(const Region &a, const Region &b)
Comparative method of two regions.
unsigned int max_id_
Maximal value of Region::id()
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.
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< DimId >, BMI::member< RegionItem, DimID,&RegionItem::id > >, BMI::hashed_non_unique< BMI::tag< OnlyID >, BMI::const_mem_fun< RegionItem, unsigned int,&RegionItem::get_id > >, BMI::ordered_unique< BMI::tag< Label >, BMI::member< RegionItem, std::string,&RegionItem::label > > > > RegionTable
Region database.
unsigned int get_id() const
RegionTable::index< Label >::type::iterator LabelIter
RegionItem(unsigned int index, unsigned int id, const std::string &label, unsigned int dim, const std::string &address, bool used=false)
bool is_boundary(const std::string &label)
unsigned int n_bulk_
Number of bulk regions.
std::pair< unsigned int, unsigned int > DimID
RegionIdx(unsigned int index)
RegionTable::index< OnlyID >::type::iterator OnlyIDIter
RegionTable::index< DimId >::type::iterator DimIDIter
std::map< std::string, RegionSet > RegionSetTable
Type representing a map of RegionSets.
bool operator!=(const RegionIdx &other) const
Equality comparison operators for regions.
static const unsigned int max_n_regions
RegionTable region_table_
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)
static const unsigned int undefined_dim
bool is_valid() const
Returns false if the region has undefined/invalid value.
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.
unsigned int idx() const
Returns a global index of the region.