FEM: add methods to to edit mesh groups:
- add addGroup, addGroupElements, removeGroup to C++ mesh class - expose the methods to Python - add a unit test class - update test commands file - add test to fem test app module
This commit is contained in:
@@ -2053,3 +2053,69 @@ Base::Quantity FemMesh::getVolume(void)const
|
||||
|
||||
|
||||
}
|
||||
|
||||
int FemMesh::addGroup(const std::string TypeString, const std::string Name, const int theId)
|
||||
{
|
||||
// define mapping between typestring and ElementType
|
||||
// TODO: remove code doubling by providing mappings for all FemMesh functions
|
||||
typedef std::map<std::string, SMDSAbs_ElementType> string_eltype_map;
|
||||
string_eltype_map mapping;
|
||||
mapping["All"] = SMDSAbs_All;
|
||||
mapping["Node"] = SMDSAbs_Node;
|
||||
mapping["Edge"] = SMDSAbs_Edge;
|
||||
mapping["Face"] = SMDSAbs_Face;
|
||||
mapping["Volume"] = SMDSAbs_Volume;
|
||||
mapping["0DElement"] = SMDSAbs_0DElement;
|
||||
mapping["Ball"] = SMDSAbs_Ball;
|
||||
|
||||
int aId = theId;
|
||||
|
||||
// check whether typestring is valid
|
||||
bool typeStringValid = false;
|
||||
for (string_eltype_map::const_iterator it = mapping.begin(); it != mapping.end(); ++it)
|
||||
{
|
||||
std::string key = it->first;
|
||||
if (key == TypeString)
|
||||
typeStringValid = true;
|
||||
}
|
||||
if (!typeStringValid)
|
||||
throw std::runtime_error("AddGroup: Invalid type string! Allowed: All, Node, Edge, Face, Volume, 0DElement, Ball");
|
||||
// add group to mesh
|
||||
SMESH_Group* group = this->getSMesh()->AddGroup(mapping[TypeString], Name.c_str(), aId);
|
||||
if (!group)
|
||||
throw std::runtime_error("AddGroup: Failed to create new group.");
|
||||
return aId;
|
||||
}
|
||||
|
||||
void FemMesh::addGroupElements(const int GroupId, const std::set<int> ElementIds)
|
||||
{
|
||||
SMESH_Group* group = this->getSMesh()->GetGroup(GroupId);
|
||||
if (!group) {
|
||||
throw std::runtime_error("AddGroupElements: No group for given id.");
|
||||
}
|
||||
SMESHDS_Group* groupDS = dynamic_cast<SMESHDS_Group*>(group->GetGroupDS());
|
||||
// TODO: is this dynamic_cast OK?
|
||||
|
||||
// Traverse the full mesh and add elements to group if id is in set 'ids'
|
||||
// and if group type is compatible with element
|
||||
SMDSAbs_ElementType aElementType = groupDS->GetType();
|
||||
|
||||
SMDS_ElemIteratorPtr aElemIter = this->getSMesh()->GetMeshDS()->elementsIterator(aElementType);
|
||||
while (aElemIter->more()) {
|
||||
const SMDS_MeshElement* aElem = aElemIter->next();
|
||||
std::set<int>::iterator it;
|
||||
it = ElementIds.find(aElem->GetID());
|
||||
if (it != ElementIds.end())
|
||||
{
|
||||
// the element was in the list
|
||||
if (!groupDS->Contains(aElem)) // check whether element is already in group
|
||||
groupDS->Add(aElem); // if not, add it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FemMesh::removeGroup(int GroupId)
|
||||
{
|
||||
return this->getSMesh()->RemoveGroup(GroupId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user