Commit a36fe4ef authored by Christophe Geuzaine's avatar Christophe Geuzaine

new gmsh::model::removePhysicalGroups() in api

parent 35ad32f3
......@@ -547,6 +547,21 @@ GMSH_API void gmsh::model::removeEntities(const vectorpair &dimTags,
GModel::current()->remove(dimTags, recursive);
}
GMSH_API void gmsh::model::removePhysicalGroups(const vectorpair &dimTags)
{
if(!_isInitialized()) {
throw -1;
}
if(dimTags.empty()){
GModel::current()->removePhysicalGroups();
}
else{
// TODO: rewrite the unerlying code: it's slow
for(unsigned int i = 0; i < dimTags.size(); i++)
GModel::current()->removePhysicalGroup(dimTags[i].first, dimTags[i].second);
}
}
GMSH_API void gmsh::model::getType(const int dim, const int tag,
std::string &entityType)
{
......
......@@ -525,7 +525,7 @@ FlGui::FlGui(int argc, char **argv)
graph[0]->getWindow()->show(argc > 0 ? 1 : 0, argv);
if(graph[0]->getMenuWindow()) graph[0]->getMenuWindow()->show();
#if 0
#if 1
// FIXME temporary hack for macOS Mojave: resize GL window to get it to
// display
graph[0]->getWindow()->resize(graph[0]->getWindow()->x(),
......
......@@ -712,20 +712,23 @@ void GModel::removePhysicalGroups()
getEntities(entities);
for(unsigned int i = 0; i < entities.size(); i++)
entities[i]->physicals.clear();
physicalNames.clear();
}
void GModel::removePhysicalGroup(int dim, int num)
void GModel::removePhysicalGroup(int dim, int tag)
{
// FIXME: this is very inefficient - needs to be rewriten (and we should
// generalize the function by taking a list of dim, tag pairs)
std::vector<GEntity *> entities;
getEntities(entities, dim);
for(unsigned int i = 0; i < entities.size(); i++) {
std::vector<int> p;
for(unsigned int j = 0; j < entities[i]->physicals.size(); j++)
if(entities[i]->physicals[j] != num)
if(entities[i]->physicals[j] != tag)
p.push_back(entities[i]->physicals[j]);
entities[i]->physicals = p;
}
physicalNames.erase(std::pair<int, int>(dim, num));
physicalNames.erase(std::pair<int, int>(dim, tag));
}
int GModel::getMaxPhysicalNumber(int dim)
......@@ -2244,6 +2247,22 @@ int GModel::removeDuplicateMeshVertices(double tolerance)
return num;
}
/*
struct ElementSort{
MElement *ele;
std::vector<int> sortedVertexNum;
};
struct Less_ElementSort{
return a->sortedVertexNum < b->sortedVertexNum;
};
int GModel::removeDuplicateMeshElements()
{
}
*/
static void recurConnectMElementsByMFace(
const MFace &f, std::multimap<MFace, MElement *, Less_Face> &e2f,
std::set<MElement *> &group, std::set<MFace, Less_Face> &touched,
......
......@@ -132,6 +132,9 @@ model.add('addDiscreteEntity',doc,oint,iint('dim'),iint('tag','-1'),ivectorint('
doc = '''Remove the entities `dimTags' of the current model. If `recursive' is true, remove all the entities on their boundaries, down to dimension 0.'''
model.add('removeEntities',doc,None,ivectorpair('dimTags'),ibool('recursive','false','False'))
doc = '''Remove the physical groups `dimTags' of the current model. If `dimTags' is empty, remove all groups.'''
model.add('removePhysicalGroups',doc,None,ivectorpair('dimTags','gmsh::vectorpair()',"[]","[]"))
doc = '''Get the type of the entity of dimension `dim' and tag `tag'.'''
model.add('getType',doc,None,iint('dim'),iint('tag'),ostring('entityType'))
......
......@@ -205,6 +205,10 @@ namespace gmsh { // Top-level functions
GMSH_API void removeEntities(const gmsh::vectorpair & dimTags,
const bool recursive = false);
// Remove the physical groups `dimTags' of the current model. If `dimTags' is
// empty, remove all groups.
GMSH_API void removePhysicalGroups(const gmsh::vectorpair & dimTags = gmsh::vectorpair());
// Get the type of the entity of dimension `dim' and tag `tag'.
GMSH_API void getType(const int dim,
const int tag,
......
......@@ -403,6 +403,17 @@ namespace gmsh { // Top-level functions
gmshFree(api_dimTags_);
}
// Remove the physical groups `dimTags' of the current model. If `dimTags' is
// empty, remove all groups.
GMSH_API void removePhysicalGroups(const gmsh::vectorpair & dimTags = gmsh::vectorpair())
{
int ierr = 0;
int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
gmshModelRemovePhysicalGroups(api_dimTags_, api_dimTags_n_, &ierr);
if(ierr) throw ierr;
gmshFree(api_dimTags_);
}
// Get the type of the entity of dimension `dim' and tag `tag'.
GMSH_API void getType(const int dim,
const int tag,
......
......@@ -514,6 +514,21 @@ function removeEntities(dimTags, recursive = false)
return nothing
end
"""
gmsh.model.removePhysicalGroups(dimTags = Tuple{Cint,Cint}[])
Remove the physical groups `dimTags` of the current model. If `dimTags` is
empty, remove all groups.
"""
function removePhysicalGroups(dimTags = Tuple{Cint,Cint}[])
ierr = Ref{Cint}()
ccall((:gmshModelRemovePhysicalGroups, gmsh.lib), Nothing,
(Ptr{Cint}, Csize_t, Ptr{Cint}),
convert(Vector{Cint}, collect(Cint, Iterators.flatten(dimTags))), 2 * length(dimTags), ierr)
ierr[] != 0 && error("gmshModelRemovePhysicalGroups returned non-zero error code: $(ierr[])")
return nothing
end
"""
gmsh.model.getType(dim, tag)
......
......@@ -657,6 +657,22 @@ class model:
"gmshModelRemoveEntities returned non-zero error code: ",
ierr.value)
@staticmethod
def removePhysicalGroups(dimTags=[]):
"""
Remove the physical groups `dimTags' of the current model. If `dimTags' is
empty, remove all groups.
"""
api_dimTags_, api_dimTags_n_ = _ivectorpair(dimTags)
ierr = c_int()
lib.gmshModelRemovePhysicalGroups(
api_dimTags_, api_dimTags_n_,
byref(ierr))
if ierr.value != 0:
raise ValueError(
"gmshModelRemovePhysicalGroups returned non-zero error code: ",
ierr.value)
@staticmethod
def getType(dim, tag):
"""
......
......@@ -402,6 +402,22 @@ GMSH_API void gmshModelRemoveEntities(int * dimTags, size_t dimTags_n, const int
}
}
GMSH_API void gmshModelRemovePhysicalGroups(int * dimTags, size_t dimTags_n, int * ierr)
{
if(ierr) *ierr = 0;
try {
gmsh::vectorpair api_dimTags_(dimTags_n/2);
for(size_t i = 0; i < dimTags_n/2; ++i){
api_dimTags_[i].first = dimTags[i * 2 + 0];
api_dimTags_[i].second = dimTags[i * 2 + 1];
}
gmsh::model::removePhysicalGroups(api_dimTags_);
}
catch(int api_ierr_){
if(ierr) *ierr = api_ierr_;
}
}
GMSH_API void gmshModelGetType(const int dim, const int tag, char ** entityType, int * ierr)
{
if(ierr) *ierr = 0;
......
......@@ -210,6 +210,11 @@ GMSH_API void gmshModelRemoveEntities(int * dimTags, size_t dimTags_n,
const int recursive,
int * ierr);
/* Remove the physical groups `dimTags' of the current model. If `dimTags' is
* empty, remove all groups. */
GMSH_API void gmshModelRemovePhysicalGroups(int * dimTags, size_t dimTags_n,
int * ierr);
/* Get the type of the entity of dimension `dim' and tag `tag'. */
GMSH_API void gmshModelGetType(const int dim,
const int tag,
......
......@@ -368,6 +368,19 @@ true, remove all the entities on their boundaries, down to dimension 0.
-
@end table
@item removePhysicalGroups
Remove the physical groups @code{dimTags} of the current model. If
@code{dimTags} is empty, remove all groups.
@table @asis
@item Input:
@code{dimTags}
@item Output:
-
@item Return:
-
@end table
@item getType
Get the type of the entity of dimension @code{dim} and tag @code{tag}.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment