gmsh::model::addPhysicalGroup() does not work when gmsh::model::occ::fragment is called
my code is very simple
#include <gmsh.h>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
gmsh::initialize();
double lc = 0;
gmsh::model::occ::addPoint(0., 0., 0., lc, 1);
gmsh::model::occ::addPoint(0., 10., 0., lc, 2);
gmsh::model::occ::addPoint(10., 10., 0., lc, 3);
gmsh::model::occ::addPoint(10., 0., 0., lc, 4);
gmsh::model::occ::addLine(1, 2, 1);
gmsh::model::occ::addLine(2, 3, 2);
gmsh::model::occ::addLine(3, 4, 3);
gmsh::model::occ::addLine(4, 1, 4);
std::vector<int> curveloop1 = {1, 2, 3, 4};
gmsh::model::occ::addCurveLoop(curveloop1, 1);
std::vector<int> surfaceloop1 = {1};
gmsh::model::occ::addPlaneSurface(surfaceloop1, 1);
gmsh::model::occ::synchronize();
gmsh::model::addPhysicalGroup(2, {1}, 1);
gmsh::model::occ::synchronize();
gmsh::model::setPhysicalName(2, {1}, "Polygon_1");
gmsh::model::occ::synchronize();
// the second 3D polygon----------------------------
gmsh::model::occ::addPoint(5., 1., -5., lc, 5);
gmsh::model::occ::addPoint(5., 11., -5., lc, 6);
gmsh::model::occ::addPoint(5., 11., 5., lc, 7);
gmsh::model::occ::addPoint(5., 1., 5., lc, 8);
gmsh::model::occ::addLine(5, 6, 5);
gmsh::model::occ::addLine(6, 7, 6);
gmsh::model::occ::addLine(7, 8, 7);
gmsh::model::occ::addLine(8, 5, 8);
std::vector<int> curveloop2 = {5, 6, 7, 8};
gmsh::model::occ::addCurveLoop(curveloop2, 2);
std::vector<int> surfaceloop2 = {2};
gmsh::model::occ::addPlaneSurface(surfaceloop2, 2);
gmsh::model::occ::synchronize();
gmsh::model::addPhysicalGroup(2, {2}, 2);
gmsh::model::occ::synchronize();
gmsh::model::setPhysicalName(2, {2}, "Polygon_2");
gmsh::model::occ::synchronize();
//-------------
std::vector<std::pair<int, int>> out;
std::vector<std::vector<std::pair<int, int>>> outmap;
gmsh::model::occ::fragment({{2, 1}}, {{2, 2}}, out, outmap);
gmsh::model::occ::synchronize();
gmsh::model::mesh::generate(2);
std::vector<int> entities_tag;
int physical_tag = 1;
gmsh::model::getEntitiesForPhysicalGroup(2, physical_tag, entities_tag);
for (size_t i = 0; i < entities_tag.size(); ++i)
cout << "Entity (Tag " << entities_tag[0] << ") belongs to Physical group " << physical_tag << endl;
//gmsh::fltk::run();
gmsh::clear();
gmsh::finalize();
return 0;
}
and error happens
Error : Unknown OpenCASCADE entity of dimension 2 with tag 2
terminate called after throwing an instance of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >'
Aborted (core dumped)
You can see I actually called gmsh::model::occ::synchronize();
before calling gmsh::model::addPhysicalGroup
.
If I comment the inputs of the 2nd polygon and the fragment
function, then getEntitiesForPhysicalGroup
worked.
#include <gmsh.h>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
gmsh::initialize();
double lc = 0;
gmsh::model::occ::addPoint(0., 0., 0., lc, 1);
gmsh::model::occ::addPoint(0., 10., 0., lc, 2);
gmsh::model::occ::addPoint(10., 10., 0., lc, 3);
gmsh::model::occ::addPoint(10., 0., 0., lc, 4);
gmsh::model::occ::addLine(1, 2, 1);
gmsh::model::occ::addLine(2, 3, 2);
gmsh::model::occ::addLine(3, 4, 3);
gmsh::model::occ::addLine(4, 1, 4);
std::vector<int> curveloop1 = {1, 2, 3, 4};
gmsh::model::occ::addCurveLoop(curveloop1, 1);
std::vector<int> surfaceloop1 = {1};
gmsh::model::occ::addPlaneSurface(surfaceloop1, 1);
gmsh::model::occ::synchronize();
gmsh::model::addPhysicalGroup(2, {1}, 1);
gmsh::model::occ::synchronize();
gmsh::model::setPhysicalName(2, {1}, "Polygon_1");
gmsh::model::occ::synchronize();
// the second 3D polygon----------------------------
/*
gmsh::model::occ::addPoint(5., 1., -5., lc, 5);
gmsh::model::occ::addPoint(5., 11., -5., lc, 6);
gmsh::model::occ::addPoint(5., 11., 5., lc, 7);
gmsh::model::occ::addPoint(5., 1., 5., lc, 8);
gmsh::model::occ::addLine(5, 6, 5);
gmsh::model::occ::addLine(6, 7, 6);
gmsh::model::occ::addLine(7, 8, 7);
gmsh::model::occ::addLine(8, 5, 8);
std::vector<int> curveloop2 = {5, 6, 7, 8};
gmsh::model::occ::addCurveLoop(curveloop2, 2);
std::vector<int> surfaceloop2 = {2};
gmsh::model::occ::addPlaneSurface(surfaceloop2, 2);
gmsh::model::occ::synchronize();
gmsh::model::addPhysicalGroup(2, {2}, 2);
gmsh::model::occ::synchronize();
gmsh::model::setPhysicalName(2, {2}, "Polygon_2");
gmsh::model::occ::synchronize();
//-------------
std::vector<std::pair<int, int>> out;
std::vector<std::vector<std::pair<int, int>>> outmap;
gmsh::model::occ::fragment({{2, 1}}, {{2, 2}}, out, outmap);
*/
gmsh::model::occ::synchronize();
gmsh::model::mesh::generate(2);
std::vector<int> entities_tag;
int physical_tag = 1;
gmsh::model::getEntitiesForPhysicalGroup(2, physical_tag, entities_tag);
for (size_t i = 0; i < entities_tag.size(); ++i)
cout << "Entity (Tag " << entities_tag[0] << ") belongs to Physical group " << physical_tag << endl;
//gmsh::fltk::run();
gmsh::clear();
gmsh::finalize();
return 0;
}
output is
Entity (Tag 1) belongs to Physical group 1
.