17 #include <boost/foreach.hpp>
24 {
return db_->get_label(idx_); }
29 {
return db_->get_id(idx_); }
34 {
return db_->get_dim(idx_); }
41 namespace IT=Input::Type;
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.")
74 : closed_(false), n_boundary_(0), n_bulk_(0) {
92 if (it_id->dim_ != dim) {
96 RegionItem item(it_id->index, it_id->id, it_id->label, dim);
101 else THROW(ExcInconsistentDimension() << EI_Label(it_id->label) << EI_ID(it_id->id) );
114 unsigned int index = it_id->index;
115 if (it_id->dim_ !=
undefined_dim && index != it_label->index)
THROW(ExcNonuniqueID() << EI_Label(label) << EI_ID(
id) << EI_LabelOfOtherID(it_id->label) );
122 THROW(ExcInconsistentBoundary() << EI_Label(label) << EI_ID(
id) );
128 THROW(ExcNonuniqueLabel() << EI_Label(label) << EI_ID(
id) << EI_IDOfOtherLabel(it_label->id) );
132 THROW( ExcAddingIntoClosed() << EI_Label(label) <<EI_ID(
id) );
144 THROW( ExcCantAdd() << EI_Label(label) <<EI_ID(
id) );
145 return Region(index, *
this);
153 if (label.size() != 0) {
159 ss <<
"region_" << id;
165 RegionTable::index<ID>::type::iterator it_id =
region_set_.get<
ID>().find(
id);
169 return Region(it_id->index, *
this);
173 ss <<
"region_" << id;
183 return Region(it_label->index, *
this);
194 return Region(it_id->index, *
this);
201 RegionTable::index<Index>::type::iterator it =
region_set_.get<
Index>().find(idx);
209 RegionTable::index<Index>::type::iterator it =
region_set_.get<
Index>().find(idx);
217 RegionTable::index<Index>::type::iterator it =
region_set_.get<
Index>().find(idx);
227 for(
unsigned int i=0; i<
size(); i++) {
267 if (it ==
sets_.end()) {
269 set.push_back(region);
271 sets_.insert( std::make_pair(set_name, set) );
274 if ( std::find(set.begin(), set.end(), region)==set.end() ) {
275 set.push_back(region);
284 sets_.insert( std::make_pair(set_name, set) );
292 RegionSet::iterator it;
295 set_union.resize(set_1.size() + set_2.size());
296 it = std::set_union(set_1.begin(), set_1.end(), set_2.begin(), set_2.end(), set_union.begin(),
Region::comp);
297 set_union.resize(it - set_union.begin());
306 RegionSet::iterator it;
309 set_insec.resize(set_1.size() + set_2.size());
310 it = std::set_intersection(set_1.begin(), set_1.end(), set_2.begin(), set_2.end(), set_insec.begin(),
Region::comp);
311 set_insec.resize(it - set_insec.begin());
320 RegionSet::iterator it;
323 set_diff.resize(set_1.size() + set_2.size());
324 it = std::set_difference(set_1.begin(), set_1.end(), set_2.begin(), set_2.end(), set_diff.begin(),
Region::comp);
325 set_diff.resize(it - set_diff.begin());
336 if ( it_1 ==
sets_.end() ) {
THROW(ExcUnknownSet() << EI_Label(set_name_1)); }
337 if ( it_2 ==
sets_.end() ) {
THROW(ExcUnknownSet() << EI_Label(set_name_2)); }
339 set_1 = (*it_1).second;
340 set_2 = (*it_2).second;
342 std::stable_sort(set_1.begin(), set_1.end(),
Region::comp);
343 std::stable_sort(set_2.begin(), set_2.end(),
Region::comp);
352 if ( names.size() != 2 )
THROW(ExcWrongOpNumber() << EI_NumOp(names.size()) << operands.
ei_address() );
353 auto ret_names = pair<string,string>(names[0], names[1]);
354 if (
sets_.find( ret_names.first ) ==
sets_.end() )
355 THROW( ExcUnknownSet() << EI_Label( ret_names.first )
357 if (
sets_.find( ret_names.second ) ==
sets_.end() )
358 THROW( ExcUnknownSet() << EI_Label( ret_names.second )
367 if ( it ==
sets_.end() ) {
382 Input::Array union_names, intersection_names, difference_names;
387 if (rec.
opt_val(
"region_ids", region_ids) ) {
389 it_ids != region_ids.
end();
393 if ( std::find(region_set.begin(), region_set.end(), reg)==region_set.end() ) {
394 region_set.push_back(reg);
397 xprintf(
Warn,
"Region with id %d doesn't exist. Skipping\n", (*it_ids));
402 if (rec.
opt_val(
"region_labels", region_labels) ) {
404 it_labels != region_labels.
end();
408 if ( std::find(region_set.begin(), region_set.end(), reg)==region_set.end() ) {
409 region_set.push_back(reg);
412 xprintf(
Warn,
"Region with label %s doesn't exist. Skipping\n", (*it_labels).c_str());
420 if (region_set.size() != 0) {
421 xprintf(
Warn,
"Overwriting previous initialization of region set '%s' by union operation.\n", set_name.c_str());
425 region_set =
union_sets( set_names.first, set_names.second );
431 if (region_set.size() != 0) {
432 xprintf(
Warn,
"Overwriting previous initialization of region set '%s' by intersection operation.\n", set_name.c_str());
436 region_set =
intersection( set_names.first, set_names.second );
442 if (region_set.size() != 0) {
443 xprintf(
Warn,
"Overwriting previous initialization of region set '%s' by difference operation.\n", set_name.c_str());
447 region_set =
difference( set_names.first, set_names.second );
478 it != region_list.
end();
482 string region_name = rec.
val<
string>(
"name");
483 unsigned int region_id = rec.
val<
unsigned int>(
"id");
487 if (rec.
opt_val(
"element_list", element_list) ) {
489 it_element != element_list.
end();
493 if (it_map == map.end()) {
494 map.insert( std::make_pair((*it_element), region_id) );
496 xprintf(
Warn,
"Element with id %u can't be added more than once.\n", (*it_element));
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
Allow implicit conversion from Region. We loose information about input ID, label, dim stored in database.
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
void check_dim_consistency(IDIter it_id, unsigned int dim)
Consistency check in common use by various add_region methods.
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 add_region(unsigned int id, const std::string &label, unsigned int dim, bool boundary)
One item in region database.
unsigned int boundary_idx() const
Returns index of the region in the boundary set.
void add_to_set(const string &set_name, Region region)
Region find_id(unsigned int id) const
RegionTable::index< Label >::type::iterator LabelIter
Region implicit_boundary_region()
unsigned int n_bulk_
Number of bulk regions.
RegionDB()
Default constructor.
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.
RegionTable::index< ID >::type::iterator IDIter
unsigned int id() const
Returns id of the region (using RegionDB)
unsigned int dim() const
Returns dimension of the region.