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>
35 #include <boost/multi_index/mem_fun.hpp>
36 #include <boost/functional/hash.hpp>
38 namespace BMI=::boost::multi_index;
44 namespace Type {
class Record; }
64 {
return !(
idx_ & 1); }
71 inline unsigned int idx()
const
152 std::string
label()
const;
155 unsigned int id()
const;
158 unsigned int dim()
const;
230 typedef std::vector<RegionIdx> RegionSet;
231 std::map<std::string, RegionSet > sets_;
234 add_to_set( const string& set_name, RegionIdx region);
237 add_set( const string& set_name, const RegionSet & set);
238 RegionSet union( const string & set_name_1, const string & set_name_2); // sort + std::set_union
239 RegionSet intersection( const string & set_name_1, const string & set_name_2);
240 RegionSet difference( const string & set_name_1, const string & set_name_2);
241 const RegionSet & get_set(const string & set_name);
242 void read_sets_from_input(Input::Record rec); // see structure of RegionDB::region_set_input_type
246 region_ids=[ int ...],
247 region_labels= ["..."], // these are merger together
249 union=["set_1", "set_2"], // later overwrites previous
255 * - MODIFICATION IN MESH AND READER:
256 * Mesh reading proccess:
257 * 1) Read PhysicalNames form GMSH file, populate RegionDB (DONE in GMSH reader, may need small modifications)
258 * 2) Read region definitions from the input, see
260 * typedef std::map<unsigned int, unsigned int> MapElementIDToRegionID;
261 * RegionDB::read_regions_from_input(Input::Array region_list, MapElementIDToRegionID &map);
264 * (TODO in RegionDB, also creates (and return to Mesh) element regions modification map: std::map< unsigned int, RegionIdx>
265 * that maps element IDs to the new region names, GMSH reader should have setter method to accept this map
266 * and modify the elements during reading)
267 * 3) Read region sets - TODO in RegionDB
268 * 4) Read boundary key of the Mesh record and mark appropriate regions as boundary (TODO in RegionDB)
269 * 5) Read nodes (DONE in GMSH reader)
270 * 6) Read elements, per element:
271 * - possibly modify region according map
273 * if found: add_region(ID, get_label, dim, get_boundary_flag) // possibly set dimension of the region if it is undefined
274 * not found: add_region(ID, default_label, dim, false)
275 * - if region is boundary put element into Mesh::bc_elements
276 * else put it into Mesh::element
278 * 7) Setup topology - we has to connect Boundary with existing bc_elements, and add the remaining elements,
279 * 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
304 DECLARE_EXCEPTION( ExcAddingIntoClosed, <<
"Can not add label=" << EI_Label::qval <<
" into closed MaterialDispatch.\n");
305 DECLARE_EXCEPTION( ExcNonuniqueID, <<
"Non-unique ID during add of region id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
306 <<
"other region with same ID but different label: " << EI_LabelOfOtherID::qval <<
" already exists\n");
307 DECLARE_EXCEPTION( ExcNonuniqueLabel, <<
"Non-unique label during add of region id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
308 <<
"other region with same label but different ID: " << EI_IDOfOtherLabel::val <<
" already exists\n");
309 DECLARE_EXCEPTION( ExcInconsistentBoundary, <<
"Inconsistent add of region with id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
310 <<
"both ID and label match an existing region with different boundary flag.");
311 DECLARE_EXCEPTION( ExcInconsistentDimension, <<
"Inconsistent add of region with id: " << EI_ID::val <<
", label: " << EI_Label::qval <<
"\n" \
312 <<
"both ID and label match an existing region with different dimension.");
314 DECLARE_EXCEPTION( ExcCantAdd, <<
"Can not add new region into DB, id: " << EI_ID::val <<
", label: " << EI_Label::qval);
316 DECLARE_EXCEPTION( ExcUnknownSet, <<
"Operation with unknown region set: " << EI_Label::qval );
355 Region add_region(
unsigned int id,
const std::string &label,
unsigned int dim);
388 const std::string &
get_label(
unsigned int idx)
const;
393 unsigned int get_id(
unsigned int idx)
const;
398 unsigned int get_dim(
unsigned int idx)
const;
410 unsigned int size()
const;
506 typedef std::pair<unsigned int, unsigned int>
DimID;
511 : index(index), id(dim, id), label(label) {}
513 unsigned int get_id()
const {
return id.second;}
514 unsigned int dim()
const {
return id.first;}
529 typedef BMI::multi_index_container<
538 BMI::ordered_unique< BMI::tag<Index>, BMI::member<RegionItem, unsigned int, &RegionItem::index > >,
540 BMI::hashed_unique< BMI::tag<DimId>, BMI::member<RegionItem, DimID, &RegionItem::id> >,
542 BMI::hashed_non_unique< BMI::tag<OnlyID>, BMI::const_mem_fun<RegionItem, unsigned int, &RegionItem::get_id> >,
544 BMI::ordered_unique< BMI::tag<Label>, BMI::member<RegionItem, std::string, &RegionItem::label> >
549 typedef RegionTable::index<Label>::type::iterator
LabelIter;
550 typedef RegionTable::index<DimId>::type::iterator
DimIDIter;
551 typedef RegionTable::index<OnlyID>::type::iterator
OnlyIDIter;
615 return (label.size() != 0) && (label[0] ==
'.');
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
Returns true if it is a Boundary region and false if it is a Bulk region.
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
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
Region replace_region_dim(DimIDIter it_undef_dim, unsigned int dim, bool boundary)
DECLARE_INPUT_EXCEPTION(ExcUnknownSetOperand,<< "Operation with unknown region set: "<< EI_Label::qval)
One item in region database.
std::vector< Region > RegionSet
const RegionDB * db_
Global variable with information about all regions.
void create_label_from_id(const string &label, unsigned int id)
unsigned int boundary_idx() const
Returns index of the region in the boundary set.
Global macros to enhance readability and debugging, general constants.
Region find_by_dimid(DimIDIter it_id, unsigned int id, const std::string &label, bool boundary)
RegionIdx operator()(const Region &)
Region find_id(unsigned int id, unsigned int dim) const
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.
Region implicit_boundary_
void add_to_set(const string &set_name, Region region)
unsigned int get_id() const
RegionTable::index< Label >::type::iterator LabelIter
bool is_boundary(const std::string &label)
Region implicit_boundary_region()
unsigned int n_bulk_
Number of bulk regions.
std::pair< unsigned int, unsigned int > DimID
RegionDB()
Default constructor.
Region add_region(unsigned int id, const std::string &label, unsigned int dim)
RegionIdx(unsigned int index)
RegionTable::index< OnlyID >::type::iterator OnlyIDIter
Region insert_region(unsigned int id, const std::string &label, unsigned int dim, bool boundary)
RegionTable::index< DimId >::type::iterator DimIDIter
bool operator!=(const RegionIdx &other) const
Equality comparison operators for regions.
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.
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.