27 #include <boost/foreach.hpp> 34 {
return db_->get_label(idx_); }
39 {
return db_->get_id(idx_); }
44 {
return db_->get_dim(idx_); }
57 : closed_(false), n_boundary_(0), n_bulk_(0), max_id_(0) {
71 return Region(it_id->index, *
this);
95 THROW(ExcNonuniqueLabel() << EI_Label(label) << EI_ID(
id) << EI_IDOfOtherLabel(it_label->get_id()) );
103 OLD_ASSERT(reg.
is_valid(),
"Non-existing region can't be renamed to '%s'.\n", new_label.c_str());
108 if ( reg.
id() == it_label->index ) {
112 THROW(ExcNonuniqueLabel() << EI_Label(new_label) << EI_ID(reg.
id()) << EI_IDOfOtherLabel(it_label->get_id()) );
117 unsigned int index = reg.
idx();
119 std::swap(
sets_[new_label], it->second);
129 xprintf(
Warn,
"Change boundary flag of region with id %d and label %s.\n", reg.
id(), new_label.c_str());
130 if (old_boundary_flag) {
139 return Region(index, *
this);
147 return Region(it_id->index, *
this);
166 return Region(it_label->index, *
this);
177 return Region(it_id->index, *
this);
186 THROW( ExcUniqueRegionId() << EI_ID(
id ) );
190 return Region(it_id->index, *
this);
232 unsigned int index = it->index;
233 RegionItem item(index, it->get_id(), it->label, it->dim(), it->address,
true);
270 RegionSetTable::iterator
it =
sets_.find(set_name);
272 if (it ==
sets_.end()) {
274 set.push_back(region);
276 sets_.insert( std::make_pair(set_name,
set) );
279 if ( std::find(
set.begin(),
set.end(), region)==
set.end() ) {
280 set.push_back(region);
289 sets_.insert( std::make_pair(set_name,
set) );
295 RegionSetTable::iterator
it =
sets_.find(set_name);
296 OLD_ASSERT(it !=
sets_.end(),
"Region set '%s' doesn't exist.", set_name.c_str());
299 auto set_it = std::find(
set.begin(),
set.end(), region);
300 OLD_ASSERT(set_it !=
set.end(),
"Erased region was not found in set '%s'", set_name.c_str());
310 for (
string name : names) {
312 THROW( ExcUnknownSet() << EI_Label( name )
322 RegionSetTable::const_iterator
it =
sets_.find(set_name);
323 if ( it ==
sets_.end() ) {
332 ss <<
"region_" << id;
337 if (
closed_)
THROW( ExcAddingIntoClosed() << EI_Label(label) << EI_ID(
id) );
349 THROW( ExcCantAdd() << EI_Label(label) << EI_ID(
id) );
357 region_set.push_back( reg );
371 "Dimension of replaced region with id=%u must be undefined_dim, actually is: %u\n", it_undef_dim->get_id(), it_undef_dim->dim());
373 unsigned int index = it_undef_dim->index;
383 THROW(ExcInconsistentBoundary() << EI_Label(it_undef_dim->label) << EI_ID(it_undef_dim->get_id()) );
389 unsigned int index = it_id->index;
392 THROW(ExcNonuniqueID() << EI_Label(label) << EI_ID(
id) << EI_LabelOfOtherID(it_id->label) );
397 THROW(ExcInconsistentBoundary() << EI_Label(label) << EI_ID(
id) );
407 for (RegionSetTable::const_iterator
it =
sets_.begin();
it !=
sets_.end(); ++
it) {
408 string rset_label =
it->first;
411 if ( (rset_label.size() > 0) && (rset_label[0] ==
'.') ) boundaries.push_back(rset_label);
412 else bulks.push_back(rset_label);
414 sets.push_back(rset_label);
420 stream << endl <<
"----------- Table of all regions: -----------";
421 if (boundaries.size()) {
422 stream << endl <<
" - Boundary elementary regions -" << endl;
423 stream << std::setfill(
' ') <<
"name" << setw(14) <<
"" << setw(6) <<
"id" <<
" dim" << endl;
426 stream << std::left << setw(18) << (*it) << std::right << setw(6) << label_it->get_id() << setw(4) << label_it->dim() << endl;
430 stream << endl <<
" - Bulk elementary regions -" << endl;
431 stream <<
"name" << setw(14) <<
"" << setw(6) <<
"id" <<
" dim" << endl;
434 stream << std::left << setw(18) << (*it) << std::right << setw(6) << label_it->get_id() << setw(4) << label_it->dim() << endl;
438 stream << endl <<
" - Sets of regions -" << endl;
439 stream <<
"name" << setw(14) <<
"" <<
"contains regions" << endl;
441 RegionSetTable::const_iterator set_it =
sets_.find(*
it);
442 stream << std::left << setw(18) << (*it) << std::right <<
"[";
443 for (RegionSet::const_iterator r_it = set_it->second.begin(); r_it!=set_it->second.end(); ++r_it) {
444 if (r_it != set_it->second.begin()) stream <<
", ";
445 stream <<
"\"" << r_it->label() <<
"\"";
447 stream <<
"]" << endl;
450 stream << std::setfill(
'-') << setw(45) <<
"" << std::setfill(
' ') << endl << endl;
461 THROW(ExcUnusedRegion() << EI_Label(
it->label) << EI_ID(
it->get_id()) << Input::EI_Address(
it->address) );
467 std::set<Region, bool (*)(const Region&, const Region&)>
set(
Region::comp);
469 for (
string set_name : set_names) {
471 set.insert(r_set.begin(), r_set.end());
474 return RegionSet(
set.begin(),
set.end());
unsigned int size() const
const std::string & get_label(unsigned int idx) const
bool is_boundary() const
Returns true if it is a Boundary region and false if it is a Bulk region.
Region rename_region(Region reg, const std::string &new_label)
std::vector< Region > RegionSet
unsigned int bulk_size() const
RegionSet union_set(std::vector< string > set_names) const
RegionSet get_region_set(const string &set_name) const
RegionSetTable sets_
Map of region sets.
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
unsigned int max_id_
Maximal value of Region::id()
string create_label_from_id(unsigned int id) const
Region replace_region_dim(DimIDIter it_undef_dim, unsigned int dim, bool boundary)
One item in region database.
void erase_from_set(const string &set_name, Region region)
Region get_region(unsigned int id, unsigned int dim)
Region find_by_dimid(DimIDIter it_id, unsigned int id, const std::string &label, bool boundary)
Region find_id(unsigned int id, unsigned int dim) const
std::vector< string > get_and_check_operands(const Input::Array &operands) const
void add_to_set(const string &set_name, Region region)
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.
RegionTable::index< OnlyID >::type::iterator OnlyIDIter
RegionTable::index< DimId >::type::iterator DimIDIter
void mark_used_region(unsigned int idx)
void print_region_table(ostream &stream) const
Region add_region(unsigned int id, const std::string &label, unsigned int dim, const std::string &address="implicit")
const std::string & get_region_address(unsigned int idx) const
Region insert_region(unsigned int id, const std::string &label, unsigned int dim, bool boundary, const std::string &address)
static const unsigned int max_n_regions
unsigned int get_id(unsigned int idx) const
unsigned int boundary_size() const
RegionTable region_table_
Database of all regions (both boundary and bulk).
unsigned int get_dim(unsigned int idx) const
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)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
bool closed_
flag for closed database, no regions can be added, but you can add region sets
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.
unsigned int idx() const
Returns a global index of the region.