40 #include <boost/multi_index_container.hpp> 41 #include <boost/multi_index/ordered_index.hpp> 42 #include <boost/multi_index/random_access_index.hpp> 43 #include <boost/multi_index/hashed_index.hpp> 44 #include <boost/multi_index/member.hpp> 45 #include <boost/multi_index/mem_fun.hpp> 46 #include <boost/functional/hash.hpp> 48 namespace BMI=::boost::multi_index;
54 namespace Type {
class Record; }
74 {
return !(idx_ & 1); }
78 {
return idx_!=undefined;}
81 inline unsigned int idx()
const 86 OLD_ASSERT( is_boundary(),
"Try to get boundary index of a bulk region with internal idx: %d\n", idx_ );
91 OLD_ASSERT( ! is_boundary(),
"Try to get bulk index of boundary region with internal idx: %d\n", idx_ );
96 {
return idx_ == other.
idx_; }
100 {
return idx_ != other.
idx_; }
118 static const unsigned int undefined=0xffffffff;
176 std::string label()
const;
179 unsigned int id()
const;
182 unsigned int dim()
const;
192 bool is_in_region_set(
const RegionSet &
set)
const;
246 typedef std::vector<RegionIdx> RegionSet;
247 std::map<std::string, RegionSet > sets_;
250 add_to_set( const string& set_name, RegionIdx region);
253 add_set( const string& set_name, const RegionSet & set);
254 RegionSet union( const string & set_name_1, const string & set_name_2); // sort + std::set_union
255 RegionSet intersection( const string & set_name_1, const string & set_name_2);
256 RegionSet difference( const string & set_name_1, const string & set_name_2);
257 const RegionSet & get_set(const string & set_name);
258 void read_sets_from_input(Input::Record rec); // see structure of RegionDB::get_region_set_input_type()
262 region_ids=[ int ...],
263 region_labels= ["..."], // these are merger together
265 union=["set_1", "set_2"], // later overwrites previous
271 * - MODIFICATION IN MESH AND READER:
272 * Mesh reading proccess:
273 * 1) Read PhysicalNames form GMSH file, populate RegionDB (DONE in GMSH reader, may need small modifications)
274 * 2) Read region definitions from the input, see
275 * - Mesh::read_regions_from_input(Input::Array region_list);
276 * 3) Read nodes (DONE in GMSH reader)
277 * 4) Read elements, per element:
278 * - possibly modify region according map
280 * if found: add_region(ID, get_label, dim, get_boundary_flag) // possibly set dimension of the region if it is undefined
281 * not found: add_region(ID, default_label, dim, false)
282 * - if region is boundary put element into Mesh::bc_elements
283 * else put it into Mesh::element
285 * 5) Setup topology - we has to connect Boundary with existing bc_elements, and add the remaining elements,
286 * 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
302 DECLARE_INPUT_EXCEPTION( ExcAddingIntoClosed, <<
"Can not add label=" << EI_Label::qval <<
" into closed MaterialDispatch.\n");
303 DECLARE_EXCEPTION( ExcNonuniqueID, <<
"Non-unique ID during add of elementary region id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
304 <<
"other elementary region with same ID but different label: " << EI_LabelOfOtherID::qval <<
" already exists\n");
305 DECLARE_INPUT_EXCEPTION( ExcNonuniqueLabel, <<
"Non-unique label during add of elementary region id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
306 <<
"other elementary region with same label but different ID: " << EI_IDOfOtherLabel::val <<
" already exists\n");
307 DECLARE_EXCEPTION( ExcInconsistentBoundary, <<
"Inconsistent add of elementary region with id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
308 <<
"both ID and label match an existing elementary region with different boundary flag.");
310 DECLARE_INPUT_EXCEPTION( ExcCantAdd, <<
"Can not add new elementary region into DB, id: " << EI_ID::val <<
", label: " << EI_Label::qval);
327 static const unsigned int max_n_regions = 64000;
352 Region add_region(
unsigned int id,
const std::string &label,
unsigned int dim,
const std::string &address =
"implicit");
357 Region rename_region(
Region reg,
const std::string &new_label );
364 Region get_region(
unsigned int id,
unsigned int dim);
369 Region find_label(
const std::string &label)
const;
375 Region find_id(
unsigned int id,
unsigned int dim)
const;
380 Region find_id(
unsigned int id)
const;
385 const std::string &get_label(
unsigned int idx)
const;
390 unsigned int get_id(
unsigned int idx)
const;
395 unsigned int get_dim(
unsigned int idx)
const;
407 unsigned int size()
const;
412 unsigned int boundary_size()
const;
417 unsigned int bulk_size()
const;
423 Region implicit_boundary_region();
431 void add_to_set(
const string& set_name,
Region region);
439 void add_set(
const string& set_name,
const RegionSet &
set);
450 RegionSet get_region_set(
const string & set_name)
const;
461 void print_region_table(ostream& stream)
const;
468 string create_label_from_id(
unsigned int id)
const;
473 const std::string & get_region_address(
unsigned int idx)
const;
480 void mark_used_region(
unsigned int idx);
491 typedef std::pair<unsigned int, unsigned int>
DimID;
495 RegionItem(
unsigned int index,
unsigned int id,
const std::string &label,
unsigned int dim,
const std::string &address,
bool used=
false)
496 : index(index), id(dim, id), label(label), used(used), address(address) {}
498 unsigned int get_id()
const {
return id.second;}
499 unsigned int dim()
const {
return id.first;}
518 typedef BMI::multi_index_container<
527 BMI::ordered_unique< BMI::tag<Index>, BMI::member<RegionItem, unsigned int, &RegionItem::index > >,
529 BMI::hashed_unique< BMI::tag<DimId>, BMI::member<RegionItem, DimID, &RegionItem::id> >,
531 BMI::hashed_non_unique< BMI::tag<OnlyID>, BMI::const_mem_fun<RegionItem, unsigned int, &RegionItem::get_id> >,
533 BMI::ordered_unique< BMI::tag<Label>, BMI::member<RegionItem, std::string, &RegionItem::label> >
538 typedef RegionTable::index<Label>::type::iterator
LabelIter;
539 typedef RegionTable::index<DimId>::type::iterator
DimIDIter;
540 typedef RegionTable::index<OnlyID>::type::iterator
OnlyIDIter;
575 Region insert_region(
unsigned int id,
const std::string &label,
unsigned int dim,
bool boundary,
const std::string &address);
580 Region replace_region_dim(DimIDIter it_undef_dim,
unsigned int dim,
bool boundary);
585 Region find_by_dimid(DimIDIter it_id,
unsigned int id,
const std::string &label,
bool boundary);
593 void erase_from_set(
const string& set_name,
Region region);
600 void check_regions();
606 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.
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.