17 #include <boost/foreach.hpp>
24 {
return db_->get_label(idx_); }
29 {
return db_->get_id(idx_); }
34 {
return db_->get_dim(idx_); }
46 IT::Record(
"Region",
"Definition of region of elements.")
48 "Label (name) of the region. Has to be unique in one mesh.\n")
50 "The ID of the region to which you assign label.")
52 "Specification of the region by the list of elements. This is not recomended")
56 IT::Record(
"RegionSet",
"Definition of one region set.")
58 "Unique name of the region set.")
60 "List of region ID numbers that has to be added to the region set.")
62 "List of labels of the regions that has to be added to the region set.")
64 "Defines region set as a union of given pair of sets. Overrides previous keys.")
66 "Defines region set as an intersection of given pair of sets. Overrides previous keys.")
68 "Defines region set as a difference of given pair of sets. Overrides previous keys.")
76 : closed_(false), n_boundary_(0), n_bulk_(0) {
90 return Region(it_id->index, *
this);
114 THROW(ExcNonuniqueLabel() << EI_Label(label) << EI_ID(
id) << EI_IDOfOtherLabel(it_label->get_id()) );
134 THROW(ExcNonuniqueLabel() << EI_Label(label) << EI_ID(
id) << EI_IDOfOtherLabel(it_label->get_id()) );
144 return Region(it_id->index, *
this);
156 ss <<
"region_" << id;
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);
223 for(
unsigned int i=0; i<
size(); i++) {
263 if (it ==
sets_.end()) {
265 set.push_back(region);
267 sets_.insert( std::make_pair(set_name, set) );
270 if ( std::find(set.begin(), set.end(), region)==set.end() ) {
271 set.push_back(region);
280 sets_.insert( std::make_pair(set_name, set) );
288 RegionSet::iterator
it;
291 set_union.resize(set_1.size() + set_2.size());
292 it = std::set_union(set_1.begin(), set_1.end(), set_2.begin(), set_2.end(), set_union.begin(),
Region::comp);
293 set_union.resize(it - set_union.begin());
302 RegionSet::iterator
it;
305 set_insec.resize(set_1.size() + set_2.size());
306 it = std::set_intersection(set_1.begin(), set_1.end(), set_2.begin(), set_2.end(), set_insec.begin(),
Region::comp);
307 set_insec.resize(it - set_insec.begin());
316 RegionSet::iterator
it;
319 set_diff.resize(set_1.size() + set_2.size());
320 it = std::set_difference(set_1.begin(), set_1.end(), set_2.begin(), set_2.end(), set_diff.begin(),
Region::comp);
321 set_diff.resize(it - set_diff.begin());
332 if ( it_1 ==
sets_.end() ) {
THROW(ExcUnknownSet() << EI_Label(set_name_1)); }
333 if ( it_2 ==
sets_.end() ) {
THROW(ExcUnknownSet() << EI_Label(set_name_2)); }
335 set_1 = (*it_1).second;
336 set_2 = (*it_2).second;
338 std::stable_sort(set_1.begin(), set_1.end(),
Region::comp);
339 std::stable_sort(set_2.begin(), set_2.end(),
Region::comp);
348 if ( names.size() != 2 )
THROW(ExcWrongOpNumber() << EI_NumOp(names.size()) << operands.
ei_address() );
349 auto ret_names = pair<string,string>(names[0], names[1]);
350 if (
sets_.find( ret_names.first ) ==
sets_.end() )
351 THROW( ExcUnknownSet() << EI_Label( ret_names.first )
353 if (
sets_.find( ret_names.second ) ==
sets_.end() )
354 THROW( ExcUnknownSet() << EI_Label( ret_names.second )
363 if ( it ==
sets_.end() ) {
378 Input::Array union_names, intersection_names, difference_names;
383 if (rec.
opt_val(
"region_ids", region_ids) ) {
385 it_ids != region_ids.
end();
390 if ( std::find(region_set.begin(), region_set.end(), reg)==region_set.end() ) {
391 region_set.push_back(reg);
394 xprintf(
Warn,
"Region with id %d doesn't exist. Skipping\n", (*it_ids));
396 }
catch(ExcUniqueRegionId &e) {
403 if (rec.
opt_val(
"region_labels", region_labels) ) {
405 it_labels != region_labels.
end();
409 if ( std::find(region_set.begin(), region_set.end(), reg)==region_set.end() ) {
410 region_set.push_back(reg);
413 xprintf(
Warn,
"Region with label %s doesn't exist. Skipping\n", (*it_labels).c_str());
421 if (region_set.size() != 0) {
422 xprintf(
Warn,
"Overwriting previous initialization of region set '%s' by union operation.\n", set_name.c_str());
426 region_set =
union_sets( set_names.first, set_names.second );
432 if (region_set.size() != 0) {
433 xprintf(
Warn,
"Overwriting previous initialization of region set '%s' by intersection operation.\n", set_name.c_str());
437 region_set =
intersection( set_names.first, set_names.second );
443 if (region_set.size() != 0) {
444 xprintf(
Warn,
"Overwriting previous initialization of region set '%s' by difference operation.\n", set_name.c_str());
448 region_set =
difference( set_names.first, set_names.second );
459 it != region_list.
end();
463 string region_name = rec.
val<
string>(
"name");
464 unsigned int region_id = rec.
val<
unsigned int>(
"id");
468 if (rec.
opt_val(
"element_list", element_list) ) {
470 it_element != element_list.
end();
474 if (it_map == map.end()) {
475 map.insert( std::make_pair((*it_element), region_id) );
477 xprintf(
Warn,
"Element with id %u can't be added more than once.\n", (*it_element));
486 ss <<
"region_" << id;
491 if (
closed_)
THROW( ExcAddingIntoClosed() << EI_Label(label) << EI_ID(
id) );
503 THROW( ExcCantAdd() << EI_Label(label) << EI_ID(
id) );
504 return Region(index, *
this);
509 "Dimension of replaced region with id=%u must be undefined_dim, actually is: %u\n", it_undef_dim->get_id(), it_undef_dim->dim());
511 unsigned int index = it_undef_dim->index;
513 RegionItem item(index, it_undef_dim->get_id(), it_undef_dim->label, dim);
521 THROW(ExcInconsistentBoundary() << EI_Label(it_undef_dim->label) << EI_ID(it_undef_dim->get_id()) );
527 unsigned int index = it_id->index;
529 if ( it_label ==
region_set_.get<
Label>().end() || index != it_label->index )
530 THROW(ExcNonuniqueID() << EI_Label(label) << EI_ID(
id) << EI_LabelOfOtherID(it_id->label) );
535 THROW(ExcInconsistentBoundary() << EI_Label(label) << EI_ID(
id) );
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)
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)
std::vector< Region > RegionSet
RegionSet union_sets(const string &set_name_1, const string &set_name_2)
unsigned int bulk_size() const
RegionSet get_region_set(const string &set_name) const
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)
One item in region database.
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.
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
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.
Region add_region(unsigned int id, const std::string &label, unsigned int dim)
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
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 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.
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
#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.