Flow123d  jenkins-Flow123d-linux-release-multijob-198
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
RegionDB Class Reference

#include <region.hh>

Collaboration diagram for RegionDB:
Collaboration graph
[legend]

Classes

struct  DimId
 
struct  Index
 
struct  Label
 
struct  OnlyID
 
struct  RegionItem
 One item in region database. More...
 

Public Types

typedef std::map< unsigned int,
unsigned int > 
MapElementIDToRegionID
 

Public Member Functions

 TYPEDEF_ERR_INFO (EI_Label, const std::string)
 
 TYPEDEF_ERR_INFO (EI_ID, unsigned int)
 
 TYPEDEF_ERR_INFO (EI_IDOfOtherLabel, unsigned int)
 
 TYPEDEF_ERR_INFO (EI_LabelOfOtherID, const std::string)
 
 DECLARE_EXCEPTION (ExcAddingIntoClosed,<< "Can not add label="<< EI_Label::qval<< " into closed MaterialDispatch.\n")
 
 DECLARE_EXCEPTION (ExcNonuniqueID,<< "Non-unique ID during add of region id: "<< EI_ID::val<< ", label: "<< EI_Label::qval<< "\n"<< "other region with same ID but different label: "<< EI_LabelOfOtherID::qval<< " already exists\n")
 
 DECLARE_EXCEPTION (ExcNonuniqueLabel,<< "Non-unique label during add of region id: "<< EI_ID::val<< ", label: "<< EI_Label::qval<< "\n"<< "other region with same label but different ID: "<< EI_IDOfOtherLabel::val<< " already exists\n")
 
 DECLARE_EXCEPTION (ExcInconsistentBoundary,<< "Inconsistent add of region with id: "<< EI_ID::val<< ", label: "<< EI_Label::qval<< "\n"<< "both ID and label match an existing region with different boundary flag.")
 
 DECLARE_EXCEPTION (ExcInconsistentDimension,<< "Inconsistent add of region with id: "<< EI_ID::val<< ", label: "<< EI_Label::qval<< "\n"<< "both ID and label match an existing region with different dimension.")
 
 DECLARE_EXCEPTION (ExcCantAdd,<< "Can not add new region into DB, id: "<< EI_ID::val<<", label: "<< EI_Label::qval)
 
 DECLARE_EXCEPTION (ExcUnknownSet,<< "Operation with unknown region set: "<< EI_Label::qval)
 
 DECLARE_INPUT_EXCEPTION (ExcUnknownSetOperand,<< "Operation with unknown region set: "<< EI_Label::qval)
 
 TYPEDEF_ERR_INFO (EI_NumOp, unsigned int)
 
 DECLARE_INPUT_EXCEPTION (ExcWrongOpNumber,<< "Wrong number of operands. Expect 2, given: "<< EI_NumOp::val)
 
 DECLARE_INPUT_EXCEPTION (ExcUniqueRegionId,<< "Id of region must be unique, id: "<< EI_ID::val)
 
 RegionDB ()
 Default constructor. More...
 
Region add_region (unsigned int id, const std::string &label, unsigned int dim)
 
Region add_region (unsigned int id, const std::string &label)
 
Region add_region (unsigned int id, unsigned int dim)
 
Region find_label (const std::string &label) const
 
Region find_id (unsigned int id, unsigned int dim) const
 
Region find_id (unsigned int id) const
 
const std::string & get_label (unsigned int idx) const
 
unsigned int get_id (unsigned int idx) const
 
unsigned int get_dim (unsigned int idx) const
 
void close ()
 
unsigned int size () const
 
unsigned int boundary_size () const
 
unsigned int bulk_size () const
 
Region implicit_boundary_region ()
 
void add_to_set (const string &set_name, Region region)
 
void add_set (const string &set_name, const RegionSet &set)
 
RegionSet union_sets (const string &set_name_1, const string &set_name_2)
 
RegionSet intersection (const string &set_name_1, const string &set_name_2)
 
RegionSet difference (const string &set_name_1, const string &set_name_2)
 
RegionSet get_region_set (const string &set_name) const
 
void read_sets_from_input (Input::Array arr)
 
void read_regions_from_input (Input::Array region_list, MapElementIDToRegionID &map)
 

Static Public Attributes

static Input::Type::Record region_input_type
 
static Input::Type::Record region_set_input_type
 
static const unsigned int max_n_regions = 64000
 
static const unsigned int undefined_dim = 10
 

Private Types

typedef std::pair< unsigned
int, unsigned int > 
DimID
 
typedef
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. More...
 
typedef RegionTable::index
< Label >::type::iterator 
LabelIter
 
typedef RegionTable::index
< DimId >::type::iterator 
DimIDIter
 
typedef RegionTable::index
< OnlyID >::type::iterator 
OnlyIDIter
 

Private Member Functions

void prepare_sets (const string &set_name_1, const string &set_name_2, RegionSet &set_1, RegionSet &set_2)
 
pair< string, string > get_and_check_operands (const Input::Array &operands)
 
void create_label_from_id (const string &label, unsigned int id)
 
Region insert_region (unsigned int id, const std::string &label, unsigned int dim, bool boundary)
 
Region replace_region_dim (DimIDIter it_undef_dim, unsigned int dim, bool boundary)
 
Region find_by_dimid (DimIDIter it_id, unsigned int id, const std::string &label, bool boundary)
 
bool is_boundary (const std::string &label)
 

Private Attributes

RegionTable region_set_
 Database of all regions (both boundary and bulk). More...
 
bool closed_
 flag for closed database, no regions can be added, but you can add region sets More...
 
unsigned int n_boundary_
 Number of boundary regions. More...
 
unsigned int n_bulk_
 Number of bulk regions. More...
 
std::map< std::string, RegionSetsets_
 Map of region sets. More...
 
RegionSet all
 Make part of general RegionSet table. More...
 
RegionSet bulk
 
RegionSet boundary
 
Region implicit_bulk_
 
Region implicit_boundary_
 

Detailed Description

Class for conversion between an index and string label of an material. Class contains only static members in order to provide globally consistent indexing of materials across various meshes and functions.

The conversion should be performed only through the input and output so that the lookup overhead could be shadowed by IO operations.

Taking sizes and creating region sets should be possible only after the database is closed. We assume that all regions are known at beginning of the program (typically after reading all meshes) however they need not be used through the whole computation.

TODO: In order to support more meshes , possibly changing during the time we need better policy for RegionDB closing. Currently we close RegionDB at first call to any of size methods. We need size information for initialization of RegionFields. However, every RegionField should be used for assembly over just one mesh (or set of meshes - supermesh?), surly this mesh has to be initialized before assembly so it could be initialized before initialization of RegionField which lives on this mesh. So the solution can be: RegionDB keeps list of meshes that has their regions registered in RegionDB. RegionField has signature of its mesh and check if the mesh is registered in the RegionDB before initialization of REgionField.

Update TODO:

/ map set name to lists of indices of its regions typedef std::vector<RegionIdx> RegionSet; std::map<std::string, RegionSet > sets_;

/ Add region to given set. Creat the set if it does not exist. add_to_set( const string& set_name, RegionIdx region); / Add a set into map, delete possible previous value, do not worry about slow copies of / the set array. add_set( const string& set_name, const RegionSet & set); RegionSet union( const string & set_name_1, const string & set_name_2); // sort + std::set_union RegionSet intersection( const string & set_name_1, const string & set_name_2); RegionSet difference( const string & set_name_1, const string & set_name_2); const RegionSet & get_set(const string & set_name); void read_sets_from_input(Input::Record rec); // see structure of RegionDB::region_set_input_type

region_sets = [ { name="set name", region_ids=[ int ...], region_labels= ["..."], // these are merger together

union=["set_1", "set_2"], // later overwrites previous intersection= difference= } ]

typedef std::map<unsigned int, unsigned int> MapElementIDToRegionID; RegionDB::read_regions_from_input(Input::Array region_list, MapElementIDToRegionID &map);

  (TODO in RegionDB, also creates (and return to Mesh) element regions modification map: std::map< unsigned int, RegionIdx>
   that maps element IDs to the new region names, GMSH reader should have setter method to accept this map
   and modify the elements during reading)

3) Read region sets - TODO in RegionDB 4) Read boundary key of the Mesh record and mark appropriate regions as boundary (TODO in RegionDB) 5) Read nodes (DONE in GMSH reader) 6) Read elements, per element:

7) Setup topology - we has to connect Boundary with existing bc_elements, and add the remaining elements, 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 BC on them.

Definition at line 284 of file region.hh.

Member Typedef Documentation

typedef std::pair<unsigned int, unsigned int> RegionDB::DimID
private

Definition at line 506 of file region.hh.

typedef RegionTable::index<DimId>::type::iterator RegionDB::DimIDIter
private

Definition at line 550 of file region.hh.

typedef RegionTable::index<Label>::type::iterator RegionDB::LabelIter
private

Definition at line 549 of file region.hh.

typedef std::map<unsigned int, unsigned int> RegionDB::MapElementIDToRegionID

Map representing the relevance of elements to regions

Definition at line 289 of file region.hh.

typedef RegionTable::index<OnlyID>::type::iterator RegionDB::OnlyIDIter
private

Definition at line 551 of file region.hh.

typedef 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> > > > RegionDB::RegionTable
private

Region database.

Definition at line 546 of file region.hh.

Constructor & Destructor Documentation

RegionDB::RegionDB ( )

Default constructor.

Definition at line 75 of file region.cc.

Member Function Documentation

Region RegionDB::add_region ( unsigned int  id,
const std::string &  label,
unsigned int  dim 
)

This method adds new region into the database and returns its index. This requires full specification of the region that is given in PhysicalNames section of the GMSH MSH format or in Mesh input record.

If ID or label are found in the DB, we distinguish following cases: 1) ID is found, label is not found : warning ID has already assigned label 2) ID is not found, label is found : report error - assigning same label to different IDs 3) both ID and label are found, in same region : check remaining data, return existing region 4) , in different : warning ID has already assigned label

Parameter id is any unique non-negative integer, parameter label is unique string identifier of the region, dim is dimension of reference elements in the region and boundary is true if the region consist of boundary elements (where one can apply boundary condition).

Definition at line 97 of file region.cc.

Here is the caller graph for this function:

Region RegionDB::add_region ( unsigned int  id,
const std::string &  label 
)

As the previous, but set the 'boundary; flag according to the label (labels starting with dot '.' are boundary). Used in read_regions_from_input ( with undefined dimension) to read regions given in 'regions' key of the 'mesh' input record.

Definition at line 121 of file region.cc.

Region RegionDB::add_region ( unsigned int  id,
unsigned int  dim 
)

As the previous, but generates automatic label of form 'region_ID' if the region with same ID is not already present. Set bulk region. Meant to be used when reading elements from MSH file. Again, if the region is defined already, we just check consistency.

Definition at line 141 of file region.cc.

void RegionDB::add_set ( const string &  set_name,
const RegionSet set 
)

Add a set into map, delete possible previous value.

Parameters
set_nameName of added set
setAdded RegionSet

Definition at line 277 of file region.cc.

Here is the caller graph for this function:

void RegionDB::add_to_set ( const string &  set_name,
Region  region 
)

Definition at line 260 of file region.cc.

Here is the caller graph for this function:

unsigned int RegionDB::boundary_size ( ) const

Returns total number boundary regions.

Definition at line 245 of file region.cc.

Here is the caller graph for this function:

unsigned int RegionDB::bulk_size ( ) const

Returns total number bulk regions.

Definition at line 252 of file region.cc.

Here is the caller graph for this function:

void RegionDB::close ( )

Close this class for adding labels. This is necessary to return correct size for material indexed arrays and vectors. After calling this method you can call method size and method idx_of_label rise an exception for any unknown label.

Definition at line 220 of file region.cc.

Here is the caller graph for this function:

void RegionDB::create_label_from_id ( const string &  label,
unsigned int  id 
)
private

Create label of region in format: "region_"+id

Use if label is not set.

Definition at line 484 of file region.cc.

Here is the caller graph for this function:

RegionDB::DECLARE_EXCEPTION ( ExcAddingIntoClosed  )
RegionDB::DECLARE_EXCEPTION ( ExcNonuniqueID  ,
<< "Non-unique ID during add of region id: "<< EI_ID::val<< "  ,
label:"<< EI_Label::qval<< "\n"<< "other region with same ID but different label:"<< EI_LabelOfOtherID::qval<< "already exists\n"   
)
RegionDB::DECLARE_EXCEPTION ( ExcNonuniqueLabel  ,
<< "Non-unique label during add of region id: "<< EI_ID::val<< "  ,
label:"<< EI_Label::qval<< "\n"<< "other region with same label but different ID:"<< EI_IDOfOtherLabel::val<< "already exists\n"   
)
RegionDB::DECLARE_EXCEPTION ( ExcInconsistentBoundary  ,
<< "Inconsistent add of region with id: "<< EI_ID::val<< "  ,
label:"<< EI_Label::qval<< "\n"<< "both ID and label match an existing region with different boundary flag."   
)
RegionDB::DECLARE_EXCEPTION ( ExcInconsistentDimension  ,
<< "Inconsistent add of region with id: "<< EI_ID::val<< "  ,
label:"<< EI_Label::qval<< "\n"<< "both ID and label match an existing region with different dimension."   
)
RegionDB::DECLARE_EXCEPTION ( ExcCantAdd  ,
<< "Can not add new region into  DB,
id:"<< EI_ID::val<<"  ,
label:"<< EI_Label::qval   
)
RegionDB::DECLARE_EXCEPTION ( ExcUnknownSet  ,
<< "Operation with unknown region set: "<< EI_Label::qval   
)
RegionDB::DECLARE_INPUT_EXCEPTION ( ExcUnknownSetOperand  ,
<< "Operation with unknown region set: "<< EI_Label::qval   
)
RegionDB::DECLARE_INPUT_EXCEPTION ( ExcWrongOpNumber  ,
<< "Wrong number of operands. Expect  2,
given:"<< EI_NumOp::val   
)
RegionDB::DECLARE_INPUT_EXCEPTION ( ExcUniqueRegionId  ,
<< "Id of region must be  unique,
id:"<< EI_ID::val   
)
RegionSet RegionDB::difference ( const string &  set_name_1,
const string &  set_name_2 
)

Get RegionSets of specified names and create their difference Throws ExcUnknownSet for invalid name.

Parameters
set_name_1Name of first RegionSet
set_name_2Name of second RegionSet
Returns
RegionSet created of difference operation

Definition at line 313 of file region.cc.

Here is the caller graph for this function:

Region RegionDB::find_by_dimid ( DimIDIter  it_id,
unsigned int  id,
const std::string &  label,
bool  boundary 
)
private

Find existing region given by pair (dim, id).

Definition at line 526 of file region.cc.

Here is the caller graph for this function:

Region RegionDB::find_id ( unsigned int  id,
unsigned int  dim 
) const

Returns a Region with given id. If it is not found it returns undefined Region. Gmsh ID numbers are unique only over one dimension, so dimension dim must be provided as well.

Definition at line 173 of file region.cc.

Here is the caller graph for this function:

Region RegionDB::find_id ( unsigned int  id) const

Slower version that tries to find region for given ID. If it is not unique it throws.

Definition at line 183 of file region.cc.

Region RegionDB::find_label ( const std::string &  label) const

Returns a Region with given label. If it is not found it returns undefined Region.

Definition at line 162 of file region.cc.

Here is the caller graph for this function:

pair< string, string > RegionDB::get_and_check_operands ( const Input::Array operands)
private

Read two operands from input array of strings and check if given names are existing sets. Return pair of checked set names.

Definition at line 344 of file region.cc.

Here is the caller graph for this function:

unsigned int RegionDB::get_dim ( unsigned int  idx) const

Return dimension of region with given index idx.

Definition at line 212 of file region.cc.

unsigned int RegionDB::get_id ( unsigned int  idx) const

Return original ID for given index idx.

Definition at line 204 of file region.cc.

const std::string & RegionDB::get_label ( unsigned int  idx) const

Return original label for given index idx.

Definition at line 196 of file region.cc.

RegionSet RegionDB::get_region_set ( const string &  set_name) const

Get region set of specified name. Three sets are defined by default: "ALL" - set of all regions both bulk and boundary. "BULK" - set of all bulk regions "BOUNDARY" - set of all boundary regions

Parameters
set_nameName of set
Returns
RegionSet of specified name. Returns Empty vector if the set of given name doesn't exist.

Definition at line 361 of file region.cc.

Here is the caller graph for this function:

Region RegionDB::implicit_boundary_region ( )

Returns implicit boundary region. Is used for boundary elements created by Flow123d itself. This region has label "IMPLICIT_BOUNDARY" and it is obsolete, the name is not consistent with boundary label notation.

Definition at line 87 of file region.cc.

Here is the caller graph for this function:

Region RegionDB::insert_region ( unsigned int  id,
const std::string &  label,
unsigned int  dim,
bool  boundary 
)
private

Insert new region into database.

Definition at line 490 of file region.cc.

Here is the caller graph for this function:

RegionSet RegionDB::intersection ( const string &  set_name_1,
const string &  set_name_2 
)

Get RegionSets of specified names and create their intersection. Throws ExcUnknownSet for invalid name.

Parameters
set_name_1Name of first RegionSet
set_name_2Name of second RegionSet
Returns
RegionSet created of intersection operation

Definition at line 299 of file region.cc.

Here is the caller graph for this function:

bool RegionDB::is_boundary ( const std::string &  label)
inlineprivate

Return boundary flag for given label. Label of boundary region must start by '.' symbol.

Definition at line 614 of file region.hh.

Here is the caller graph for this function:

void RegionDB::prepare_sets ( const string &  set_name_1,
const string &  set_name_2,
RegionSet set_1,
RegionSet set_2 
)
private

Prepare region sets for union, intersection and difference operation. Get sets of names set_name_1 and set_name_2 and sort them. Throws ExcUnknownSet if the set with given name does not exist.

Definition at line 327 of file region.cc.

Here is the caller graph for this function:

void RegionDB::read_regions_from_input ( Input::Array  region_list,
MapElementIDToRegionID map 
)

Reads elements and their affiliation to region sets defined by user in input file Format of input record is defined in variable RegionDB::region_input_type

Parameters
region_listArray input records which define region sets and elements
mapMap to which is loaded data

Definition at line 455 of file region.cc.

Here is the caller graph for this function:

void RegionDB::read_sets_from_input ( Input::Array  arr)

Reads region sets defined by user in input file Format of input record is defined in variable RegionDB::region_set_input_type

Parameters
arrArray input records which define region sets

Definition at line 370 of file region.cc.

Here is the caller graph for this function:

Region RegionDB::replace_region_dim ( DimIDIter  it_undef_dim,
unsigned int  dim,
bool  boundary 
)
private

Replace dimension of existing region with undefined_dim.

Definition at line 507 of file region.cc.

Here is the caller graph for this function:

unsigned int RegionDB::size ( ) const

Returns maximal index + 1

Definition at line 238 of file region.cc.

Here is the caller graph for this function:

RegionDB::TYPEDEF_ERR_INFO ( EI_Label  ,
const std::string   
)
RegionDB::TYPEDEF_ERR_INFO ( EI_ID  ,
unsigned  int 
)
RegionDB::TYPEDEF_ERR_INFO ( EI_IDOfOtherLabel  ,
unsigned  int 
)
RegionDB::TYPEDEF_ERR_INFO ( EI_LabelOfOtherID  ,
const std::string   
)
RegionDB::TYPEDEF_ERR_INFO ( EI_NumOp  ,
unsigned  int 
)
RegionSet RegionDB::union_sets ( const string &  set_name_1,
const string &  set_name_2 
)

Get RegionSets of specified names and create their union

Parameters
set_name_1Name of first RegionSet
set_name_2Name of second RegionSet
Returns
RegionSet created of union operation

Definition at line 285 of file region.cc.

Here is the caller graph for this function:

Member Data Documentation

RegionSet RegionDB::all
private

Make part of general RegionSet table.

Definition at line 568 of file region.hh.

RegionSet RegionDB::boundary
private

Definition at line 568 of file region.hh.

RegionSet RegionDB::bulk
private

Definition at line 568 of file region.hh.

bool RegionDB::closed_
private

flag for closed database, no regions can be added, but you can add region sets

Definition at line 558 of file region.hh.

Region RegionDB::implicit_boundary_
private

Definition at line 574 of file region.hh.

Region RegionDB::implicit_bulk_
private

Implicit bulk and boundary regions. For GMSH mesh format only implicit_boundary is used for boundary elements that are not explicitly in the mesh file.

Definition at line 574 of file region.hh.

const unsigned int RegionDB::max_n_regions = 64000
static

Introduce an artificial limit to keep all material indexed arrays of reasonable size.

Definition at line 332 of file region.hh.

unsigned int RegionDB::n_boundary_
private

Number of boundary regions.

Definition at line 560 of file region.hh.

unsigned int RegionDB::n_bulk_
private

Number of bulk regions.

Definition at line 562 of file region.hh.

IT::Record RegionDB::region_input_type
static
Initial value:
=
IT::Record("Region", "Definition of region of elements.")
"Label (name) of the region. Has to be unique in one mesh.\n")
"The ID of the region to which you assign label.")
"Specification of the region by the list of elements. This is not recomended")
.close()

Format of input record which defined elements and their affiliation to region sets

Definition at line 294 of file region.hh.

RegionTable RegionDB::region_set_
private

Database of all regions (both boundary and bulk).

Definition at line 555 of file region.hh.

IT::Record RegionDB::region_set_input_type
static
Initial value:
=
IT::Record("RegionSet", "Definition of one region set.")
"Unique name of the region set.")
.declare_key("region_ids", IT::Array( IT::Integer(0)),
"List of region ID numbers that has to be added to the region set.")
.declare_key("region_labels", IT::Array( IT::String()),
"List of labels of the regions that has to be added to the region set.")
.declare_key("union", IT::Array( IT::String(), 2,2),
"Defines region set as a union of given pair of sets. Overrides previous keys.")
.declare_key("intersection", IT::Array( IT::String(), 2,2),
"Defines region set as an intersection of given pair of sets. Overrides previous keys.")
.declare_key("difference", IT::Array( IT::String(), 2,2),
"Defines region set as a difference of given pair of sets. Overrides previous keys.")
.close()

Format of input record which defined regions and their affiliation to region sets

Definition at line 298 of file region.hh.

std::map<std::string, RegionSet > RegionDB::sets_
private

Map of region sets.

Definition at line 565 of file region.hh.

const unsigned int RegionDB::undefined_dim = 10
static

Undefined dimension for regions introduced from mesh input record. Dimensions 0,1,2,3 are valid.

Definition at line 336 of file region.hh.


The documentation for this class was generated from the following files: