9 #include "GmshConfig.h"
64 #if defined(HAVE_MESH)
74 #if defined(HAVE_POST)
82 #if defined(HAVE_PLUGINS)
86 #if defined(HAVE_OPENGL)
90 #if defined(HAVE_FLTK)
94 #if defined(HAVE_PARSER)
98 #if defined(HAVE_ONELAB)
129 GMSH_API void gmsh::initialize(
int argc,
char ** argv,
130 const bool readConfigFiles,
const bool run)
145 for(
int i = 0; i < argc; i++)
_argv[i] = argv[i];
147 #if defined(HAVE_FLTK)
149 if(FlGui::available())
return;
171 Msg::Error(
"Something went wrong when initializing Gmsh");
189 Msg::Error(
"Something went wrong when finalizing Gmsh");
192 GMSH_API void gmsh::open(
const std::string &fileName)
196 Msg::Error(
"Could not open file '%s'", fileName.c_str());
199 GMSH_API void gmsh::merge(
const std::string &fileName)
203 Msg::Error(
"Could not merge file '%s'", fileName.c_str());
206 GMSH_API void gmsh::write(
const std::string &fileName)
210 Msg::Error(
"Could not write file '%s'", fileName.c_str());
221 GMSH_API void gmsh::option::setNumber(
const std::string &name,
229 Msg::Error(
"Could not set option '%s'", name.c_str());
232 GMSH_API void gmsh::option::getNumber(
const std::string &name,
double &value)
239 Msg::Error(
"Could not get option '%s'", name.c_str());
242 GMSH_API void gmsh::option::setString(
const std::string &name,
243 const std::string &value)
250 Msg::Error(
"Could not set option '%s'", name.c_str());
253 GMSH_API void gmsh::option::getString(
const std::string &name,
261 Msg::Error(
"Could not get option '%s'", name.c_str());
265 const int g,
const int b,
const int a)
275 Msg::Error(
"Could not set option '%s'", name.c_str());
278 GMSH_API void gmsh::option::getColor(
const std::string &name,
int &r,
int &g,
295 Msg::Error(
"Could not get option '%s'", name.c_str());
301 GMSH_API void gmsh::model::add(
const std::string &name)
306 if(!m)
Msg::Error(
"Could not add model '%s'", name.c_str());
319 GMSH_API void gmsh::model::list(std::vector<std::string> &names)
326 GMSH_API void gmsh::model::getCurrent(std::string &name)
332 GMSH_API void gmsh::model::setCurrent(
const std::string &name)
337 Msg::Error(
"Could not find model '%s'", name.c_str());
347 GMSH_API void gmsh::model::getFileName(std::string &fileName)
353 GMSH_API void gmsh::model::setFileName(
const std::string &fileName)
359 GMSH_API void gmsh::model::getEntities(vectorpair &dimTags,
const int dim)
363 std::vector<GEntity *> entities;
365 for(std::size_t i = 0; i < entities.size(); i++)
367 std::make_pair(entities[i]->dim(), entities[i]->tag()));
370 GMSH_API void gmsh::model::setEntityName(
const int dim,
const int tag,
371 const std::string &name)
377 GMSH_API void gmsh::model::getEntityName(
const int dim,
const int tag,
384 GMSH_API void gmsh::model::getPhysicalGroups(vectorpair &dimTags,
const int dim)
388 std::map<int, std::vector<GEntity *> > groups[4];
390 for(
int d = 0; d < 4; d++) {
391 if(dim < 0 || d == dim) {
392 for(
auto it = groups[d].begin(); it != groups[d].end(); it++)
393 dimTags.push_back(std::make_pair(d, it->first));
400 std::stringstream stream;
402 case 0: stream <<
"Point ";
break;
403 case 1: stream <<
"Curve ";
break;
404 case 2: stream <<
"Surface ";
break;
405 case 3: stream <<
"Volume ";
break;
411 GMSH_API void gmsh::model::getEntitiesForPhysicalGroup(
const int dim,
413 std::vector<int> &
tags)
417 std::map<int, std::vector<GEntity *> > groups;
419 auto it = groups.find(tag);
420 if(it != groups.end()) {
421 for(std::size_t j = 0; j < it->second.size(); j++)
422 tags.push_back(it->second[j]->tag());
430 gmsh::model::getPhysicalGroupsForEntity(
const int dim,
const int tag,
431 std::vector<int> &physicalTags)
434 physicalTags.clear();
441 if(phy.empty())
return;
442 physicalTags.resize(phy.size());
443 for(std::size_t i = 0; i < phy.size(); i++) { physicalTags[i] = phy[i]; }
446 GMSH_API int gmsh::model::addPhysicalGroup(
const int dim,
447 const std::vector<int> &
tags,
449 const std::string &name)
465 if(!
GModel::current()->getGEOInternals()->modifyPhysicalGroup(dim, outTag, 0,
475 GMSH_API void gmsh::model::removePhysicalGroups(
const vectorpair &dimTags)
478 if(dimTags.empty()) {
484 for(std::size_t i = 0; i < dimTags.size(); i++) {
485 std::vector<int>
tags;
487 dimTags[i].first, dimTags[i].second, 2,
tags);
494 GMSH_API void gmsh::model::setPhysicalName(
const int dim,
const int tag,
495 const std::string &name)
501 GMSH_API void gmsh::model::removePhysicalName(
const std::string &name)
507 GMSH_API void gmsh::model::getPhysicalName(
const int dim,
const int tag,
514 GMSH_API void gmsh::model::setTag(
const int dim,
const int tag,
const int newTag)
521 vectorpair &outDimTags,
522 const bool combined,
const bool oriented,
523 const bool recursive)
528 oriented, recursive)) {
533 GMSH_API void gmsh::model::getAdjacencies(
const int dim,
const int tag,
534 std::vector<int> &upward,
535 std::vector<int> &downward)
548 upward.push_back(e->tag());
551 for(
auto &e :
static_cast<GEdge *
>(ge)->
faces()) upward.push_back(e->tag());
552 for(
auto &e :
static_cast<GEdge *
>(ge)->vertices())
553 downward.push_back(e->tag());
556 for(
auto &e :
static_cast<GFace *
>(ge)->regions())
557 upward.push_back(e->tag());
558 for(
auto &e :
static_cast<GFace *
>(ge)->
edges())
559 downward.push_back(e->tag());
563 downward.push_back(e->tag());
568 GMSH_API void gmsh::model::getEntitiesInBoundingBox(
569 const double xmin,
const double ymin,
const double zmin,
const double xmax,
570 const double ymax,
const double zmax, vectorpair &dimTags,
const int dim)
575 std::vector<GEntity *> entities;
577 for(std::size_t i = 0; i < entities.size(); i++)
579 std::make_pair(entities[i]->dim(), entities[i]->tag()));
583 double &xmin,
double &ymin,
584 double &zmin,
double &xmax,
585 double &ymax,
double &zmax)
590 if(dim < 0 && tag < 0) {
609 xmin =
box.min().x();
610 ymin =
box.min().y();
611 zmin =
box.min().z();
612 xmax =
box.max().x();
613 ymax =
box.max().y();
614 zmax =
box.max().z();
623 GMSH_API int gmsh::model::addDiscreteEntity(
const int dim,
const int tag,
624 const std::vector<int> &boundary)
643 GVertex *v0 =
nullptr, *v1 =
nullptr;
644 if(boundary.size() >= 1)
646 if(boundary.size() >= 2)
654 std::vector<int> tagEdges, signEdges;
655 for(std::size_t i = 0; i < boundary.size(); i++) {
656 tagEdges.push_back(std::abs(boundary[i]));
657 signEdges.push_back(
gmsh_sign(boundary[i]));
659 if(!tagEdges.empty()) gf->
setBoundEdges(tagEdges, signEdges);
665 std::vector<int> tagFaces, signFaces;
666 for(std::size_t i = 0; i < boundary.size(); i++) {
667 tagFaces.push_back(std::abs(boundary[i]));
668 signFaces.push_back(
gmsh_sign(boundary[i]));
670 if(!tagFaces.empty()) gr->
setBoundFaces(tagFaces, signFaces);
678 GMSH_API void gmsh::model::removeEntities(
const vectorpair &dimTags,
679 const bool recursive)
682 std::vector<GEntity*> removed;
684 Msg::Debug(
"Destroying %lu entities in model", removed.size());
685 for(std::size_t i = 0; i < removed.size(); i++)
delete removed[i];
688 GMSH_API void gmsh::model::removeEntityName(
const std::string &name)
695 std::string &entityType)
706 GMSH_API void gmsh::model::getParent(
const int dim,
const int tag,
707 int &parentDim,
int &parentTag)
719 parentDim = parent->
dim();
720 parentTag = parent->
tag();
724 GMSH_API void gmsh::model::getPartitions(
const int dim,
const int tag,
725 std::vector<int> &partitions)
750 for(std::size_t i = 0; i < p.size(); i++) partitions.push_back(p[i]);
753 GMSH_API int gmsh::model::getNumberOfPartitions()
759 GMSH_API void gmsh::model::getValue(
const int dim,
const int tag,
760 const std::vector<double> ¶metricCoord,
761 std::vector<double> &coord)
771 coord.push_back(
static_cast<GVertex *
>(entity)->x());
772 coord.push_back(
static_cast<GVertex *
>(entity)->y());
773 coord.push_back(
static_cast<GVertex *
>(entity)->
z());
777 for(std::size_t i = 0; i < parametricCoord.size(); i++) {
779 coord.push_back(gp.
x());
780 coord.push_back(gp.
y());
781 coord.push_back(gp.
z());
785 if(parametricCoord.size() % 2) {
786 Msg::Error(
"Number of parametric coordinates should be even");
790 for(std::size_t i = 0; i < parametricCoord.size(); i += 2) {
791 SPoint2 param(parametricCoord[i], parametricCoord[i + 1]);
793 coord.push_back(gp.
x());
794 coord.push_back(gp.
y());
795 coord.push_back(gp.
z());
801 gmsh::model::getDerivative(
const int dim,
const int tag,
802 const std::vector<double> ¶metricCoord,
803 std::vector<double> &deriv)
814 for(std::size_t i = 0; i < parametricCoord.size(); i++) {
816 deriv.push_back(d.
x());
817 deriv.push_back(d.
y());
818 deriv.push_back(d.
z());
822 if(parametricCoord.size() % 2) {
823 Msg::Error(
"Number of parametric coordinates should be even");
827 for(std::size_t i = 0; i < parametricCoord.size(); i += 2) {
828 SPoint2 param(parametricCoord[i], parametricCoord[i + 1]);
830 deriv.push_back(d.
left().
x());
831 deriv.push_back(d.
left().
y());
832 deriv.push_back(d.
left().
z());
833 deriv.push_back(d.
right().
x());
834 deriv.push_back(d.
right().
y());
835 deriv.push_back(d.
right().
z());
841 gmsh::model::getSecondDerivative(
const int dim,
const int tag,
842 const std::vector<double> ¶metricCoord,
843 std::vector<double> &deriv)
854 for(std::size_t i = 0; i < parametricCoord.size(); i++) {
856 deriv.push_back(d.
x());
857 deriv.push_back(d.
y());
858 deriv.push_back(d.
z());
862 if(parametricCoord.size() % 2) {
863 Msg::Error(
"Number of parametric coordinates should be even");
867 for(std::size_t i = 0; i < parametricCoord.size(); i += 2) {
868 SPoint2 param(parametricCoord[i], parametricCoord[i + 1]);
871 deriv.push_back(dudu.
x());
872 deriv.push_back(dudu.
y());
873 deriv.push_back(dudu.
z());
874 deriv.push_back(dvdv.
x());
875 deriv.push_back(dvdv.
y());
876 deriv.push_back(dvdv.
z());
877 deriv.push_back(dudv.
x());
878 deriv.push_back(dudv.
y());
879 deriv.push_back(dudv.
z());
885 gmsh::model::getCurvature(
const int dim,
const int tag,
886 const std::vector<double> ¶metricCoord,
887 std::vector<double> &curvatures)
898 for(std::size_t i = 0; i < parametricCoord.size(); i++)
899 curvatures.push_back(ge->
curvature(parametricCoord[i]));
902 if(parametricCoord.size() % 2) {
903 Msg::Error(
"Number of parametric coordinates should be even");
907 for(std::size_t i = 0; i < parametricCoord.size(); i += 2) {
908 SPoint2 param(parametricCoord[i], parametricCoord[i + 1]);
914 GMSH_API void gmsh::model::getPrincipalCurvatures(
915 const int tag,
const std::vector<double> ¶metricCoord,
916 std::vector<double> &curvaturesMax, std::vector<double> &curvaturesMin,
917 std::vector<double> &directionsMax, std::vector<double> &directionsMin)
925 curvaturesMax.clear();
926 curvaturesMin.clear();
927 directionsMax.clear();
928 directionsMin.clear();
929 if(parametricCoord.size() % 2) {
930 Msg::Error(
"Number of parametric coordinates should be even");
933 for(std::size_t i = 0; i < parametricCoord.size(); i += 2) {
934 SPoint2 param(parametricCoord[i], parametricCoord[i + 1]);
937 gf->
curvatures(param, dmax, dmin, cmax, cmin);
938 curvaturesMax.push_back(cmax);
939 curvaturesMin.push_back(cmin);
940 directionsMax.push_back(dmax.
x());
941 directionsMax.push_back(dmax.
y());
942 directionsMax.push_back(dmax.
z());
943 directionsMin.push_back(dmin.
x());
944 directionsMin.push_back(dmin.
y());
945 directionsMin.push_back(dmin.
z());
949 GMSH_API void gmsh::model::getNormal(
const int tag,
950 const std::vector<double> ¶metricCoord,
951 std::vector<double> &normals)
960 if(parametricCoord.size() % 2) {
961 Msg::Error(
"Number of parametric coordinates should be even");
964 for(std::size_t i = 0; i < parametricCoord.size(); i += 2) {
965 SPoint2 param(parametricCoord[i], parametricCoord[i + 1]);
967 normals.push_back(n.
x());
968 normals.push_back(n.
y());
969 normals.push_back(n.
z());
974 gmsh::model::getParametrization(
const int dim,
const int tag,
975 const std::vector<double> &coord,
976 std::vector<double> ¶metricCoord)
979 parametricCoord.clear();
985 if(coord.size() % 3) {
986 Msg::Error(
"Number of coordinates should be a multiple of 3");
991 for(std::size_t i = 0; i < coord.size(); i += 3) {
992 SPoint3 p(coord[i], coord[i + 1], coord[i + 2]);
994 parametricCoord.push_back(t);
999 for(std::size_t i = 0; i < coord.size(); i += 3) {
1000 SPoint3 p(coord[i], coord[i + 1], coord[i + 2]);
1002 parametricCoord.push_back(uv.
x());
1003 parametricCoord.push_back(uv.
y());
1008 GMSH_API void gmsh::model::getParametrizationBounds(
const int dim,
1010 std::vector<double> &min,
1011 std::vector<double> &max)
1021 for(
int dim = 0; dim < entity->
dim(); dim++) {
1023 min.push_back(r.
low());
1024 max.push_back(r.
high());
1028 GMSH_API int gmsh::model::isInside(
const int dim,
const int tag,
1029 const std::vector<double> &coord,
1030 const bool parametric)
1042 for(std::size_t i = 0; i < coord.size(); i++) {
1048 if(coord.size() % 2) {
1049 Msg::Error(
"Number of parametric coordinates should be even");
1052 for(std::size_t i = 0; i < coord.size(); i += 2) {
1053 SPoint2 param(coord[i], coord[i + 1]);
1059 if(coord.size() % 3) {
1060 Msg::Error(
"Number of coordinates should be a multiple of 3");
1063 for(std::size_t i = 0; i < coord.size(); i += 3) {
1064 SPoint3 pt(coord[i], coord[i + 1], coord[i + 2]);
1072 if(e && entityTag == entity->
tag()) num++;
1083 GMSH_API void gmsh::model::reparametrizeOnSurface(
1084 const int dim,
const int tag,
const std::vector<double> ¶metricCoord,
1085 const int surfaceTag, std::vector<double> &surfaceParametricCoord,
1089 surfaceParametricCoord.clear();
1103 surfaceParametricCoord.push_back(p.
x());
1104 surfaceParametricCoord.push_back(p.
y());
1108 for(std::size_t i = 0; i < parametricCoord.size(); i++) {
1110 surfaceParametricCoord.push_back(p.
x());
1111 surfaceParametricCoord.push_back(p.
y());
1116 GMSH_API void gmsh::model::getClosestPoint(
const int dim,
const int tag,
1117 const std::vector<double> &coord,
1118 std::vector<double> &closestCoord,
1119 std::vector<double> ¶metricCoord)
1122 closestCoord.clear();
1123 parametricCoord.clear();
1129 if(coord.size() % 3) {
1130 Msg::Error(
"Number of coordinates should be a multiple of 3");
1135 for(std::size_t i = 0; i < coord.size(); i += 3) {
1136 SPoint3 p(coord[i], coord[i + 1], coord[i + 2]);
1139 closestCoord.push_back(pp.
x());
1140 closestCoord.push_back(pp.
y());
1141 closestCoord.push_back(pp.
z());
1142 parametricCoord.push_back(t);
1147 for(std::size_t i = 0; i < coord.size(); i += 3) {
1148 SPoint3 p(coord[i], coord[i + 1], coord[i + 2]);
1149 double uv[2] = {0, 0};
1151 closestCoord.push_back(pp.
x());
1152 closestCoord.push_back(pp.
y());
1153 closestCoord.push_back(pp.
z());
1154 parametricCoord.push_back(uv[0]);
1155 parametricCoord.push_back(uv[1]);
1161 const int value,
const bool recursive)
1164 for(std::size_t i = 0; i < dimTags.size(); i++) {
1166 dimTags[i].first, std::abs(dimTags[i].second));
1171 GMSH_API void gmsh::model::getVisibility(
const int dim,
const int tag,
1183 GMSH_API void gmsh::model::setVisibilityPerWindow(
const int value,
1184 const int windowIndex)
1187 #if defined(HAVE_FLTK)
1188 FlGui::instance()->setCurrentOpenglWindow(windowIndex);
1189 drawContext *ctx = FlGui::instance()->getCurrentDrawContext();
1199 const int g,
const int b,
const int a,
1200 const bool recursive)
1203 for(std::size_t i = 0; i < dimTags.size(); i++) {
1205 dimTags[i].first, std::abs(dimTags[i].second));
1213 GMSH_API void gmsh::model::getColor(
const int dim,
const int tag,
int &r,
1214 int &g,
int &b,
int &a)
1222 unsigned int value = ge->
getColor();
1229 GMSH_API void gmsh::model::setCoordinates(
const int tag,
const double x,
1230 const double y,
const double z)
1242 GMSH_API void gmsh::model::getAttributeNames(std::vector<std::string> &names)
1247 names.push_back(a.first);
1250 GMSH_API void gmsh::model::getAttribute(
const std::string &name,
1251 std::vector<std::string> &values)
1257 GMSH_API void gmsh::model::setAttribute(
const std::string &name,
1258 const std::vector<std::string> &values)
1264 GMSH_API void gmsh::model::removeAttribute(
const std::string &name)
1272 GMSH_API void gmsh::model::mesh::generate(
const int dim)
1280 gmsh::model::mesh::partition(
const int numPart,
1281 const std::vector<std::size_t> &elementTags,
1282 const std::vector<int> &partitions)
1285 std::vector<std::pair<MElement *, int> > epart;
1286 if(elementTags.size()) {
1287 if(elementTags.size() != partitions.size()) {
1288 Msg::Error(
"Number of element tags (%d) does not match number of "
1290 elementTags.size(), partitions.size());
1293 epart.reserve(elementTags.size());
1294 for(std::size_t i = 0; i < elementTags.size(); i++) {
1297 epart.push_back(std::make_pair(el, partitions[i]));
1299 Msg::Error(
"Unknown element %d", elementTags[i]);
1303 numPart >= 0 ? numPart :
CTX::instance()->mesh.numPartitions, epart);
1307 GMSH_API void gmsh::model::mesh::unpartition()
1314 GMSH_API void gmsh::model::mesh::refine()
1324 GMSH_API void gmsh::model::mesh::recombine()
1331 GMSH_API void gmsh::model::mesh::optimize(
const std::string &how,
1332 const bool force,
const int niter,
1333 const vectorpair &dimTags)
1336 if(dimTags.size()) {
1338 "Optimization of specified model entities is not interfaced yet");
1347 #if defined(HAVE_MESH)
1353 Msg::Error(
"computeCrossField requires the mesh module");
1357 GMSH_API void gmsh::model::mesh::splitQuadrangles(
const double quality,
1361 #if defined(HAVE_MESH)
1362 std::vector<GEntity *> entities;
1370 entities.push_back(ge);
1372 for(std::size_t i = 0; i < entities.size(); i++) {
1373 GFace *gf =
static_cast<GFace *
>(entities[i]);
1378 Msg::Error(
"splitQuadrangles requires the mesh module");
1382 GMSH_API void gmsh::model::mesh::setOrder(
const int order)
1391 GMSH_API void gmsh::model::mesh::getLastEntityError(vectorpair &dimTags)
1396 for(std::size_t i = 0; i < e.size(); i++)
1397 dimTags.push_back(std::make_pair(e[i]->dim(), e[i]->tag()));
1401 gmsh::model::mesh::getLastNodeError(std::vector<std::size_t> &nodeTags)
1406 for(std::size_t i = 0; i < v.size(); i++) nodeTags.push_back(v[i]->getNum());
1409 GMSH_API void gmsh::model::mesh::clear(
const vectorpair &dimTags)
1412 std::vector<GEntity *> entities;
1413 for(std::size_t i = 0; i < dimTags.size(); i++) {
1414 int dim = dimTags[i].first;
1415 int tag = dimTags[i].second;
1421 entities.push_back(ge);
1427 std::vector<GEntity *> &entities)
1431 for(
auto dimTag : dimTags) {
1432 int dim = dimTag.first, tag = dimTag.second;
1438 entities.push_back(ge);
1443 GMSH_API void gmsh::model::mesh::reverse(
const vectorpair &dimTags)
1446 std::vector<GEntity *> entities;
1448 for(
auto ge : entities) {
1457 gmsh::model::mesh::affineTransform(
const std::vector<double> &affineTransform,
1458 const vectorpair &dimTags)
1461 std::vector<GEntity *> entities;
1463 for(
auto ge : entities) {
1470 Msg::Error(
"Could not transform node %d (%g, %g, %g) on %s",
1478 std::vector<std::size_t> &nodeTags,
1479 std::vector<double> &coord,
1480 std::vector<double> ¶metricCoord,
1483 std::vector<GFace *>
f;
1484 std::vector<GEdge *> e;
1485 std::vector<GVertex *> v;
1486 if(entity->
dim() > 2)
f = entity->
faces();
1487 if(entity->
dim() > 1) e = entity->
edges();
1489 for(
auto it =
f.begin(); it !=
f.end(); it++) {
1493 nodeTags.push_back(v->
getNum());
1494 coord.push_back(v->
x());
1495 coord.push_back(v->
y());
1496 coord.push_back(v->
z());
1499 for(
auto it = e.begin(); it != e.end(); it++) {
1503 nodeTags.push_back(v->
getNum());
1504 coord.push_back(v->
x());
1505 coord.push_back(v->
y());
1506 coord.push_back(v->
z());
1507 if(entity->
dim() == 2 && parametric) {
1510 Msg::Warning(
"Failed to compute parameters of node %d on surface %d",
1512 parametricCoord.push_back(param.
x());
1513 parametricCoord.push_back(param.
y());
1517 for(
auto it = v.begin(); it != v.end(); it++) {
1521 nodeTags.push_back(v->
getNum());
1522 coord.push_back(v->
x());
1523 coord.push_back(v->
y());
1524 coord.push_back(v->
z());
1525 if(entity->
dim() == 2 && parametric) {
1528 Msg::Warning(
"Failed to compute parameters of node %d on surface %d",
1530 parametricCoord.push_back(param.
x());
1531 parametricCoord.push_back(param.
y());
1533 else if(entity->
dim() == 1 && parametric) {
1536 Msg::Warning(
"Failed to compute parameters of node %d on curve %d",
1538 parametricCoord.push_back(param);
1544 GMSH_API void gmsh::model::mesh::getNodes(std::vector<std::size_t> &nodeTags,
1545 std::vector<double> &coord,
1546 std::vector<double> ¶metricCoord,
1547 const int dim,
const int tag,
1548 const bool includeBoundary,
1549 const bool returnParametricCoord)
1554 parametricCoord.clear();
1555 std::vector<GEntity *> entities;
1556 if(dim >= 0 && tag >= 0) {
1562 entities.push_back(ge);
1567 for(std::size_t i = 0; i < entities.size(); i++) {
1571 nodeTags.push_back(v->
getNum());
1572 coord.push_back(v->
x());
1573 coord.push_back(v->
y());
1574 coord.push_back(v->
z());
1575 if(dim > 0 && returnParametricCoord) {
1577 for(
int k = 0; k < dim; k++) {
1578 if(v->
getParameter(k, par)) parametricCoord.push_back(par);
1584 dim > 0 && returnParametricCoord);
1588 GMSH_API void gmsh::model::mesh::getNodesByElementType(
1589 const int elementType, std::vector<std::size_t> &nodeTags,
1590 std::vector<double> &coord, std::vector<double> ¶metricCoord,
1591 const int tag,
const bool returnParametricCoord)
1596 parametricCoord.clear();
1597 std::vector<GEntity *> entities;
1599 if(dim >= 0 && tag >= 0) {
1605 entities.push_back(ge);
1613 std::size_t numElements = 0;
1614 for(std::size_t i = 0; i < entities.size(); ++i) {
1615 numElements += entities[i]->getNumMeshElementsByType(familyType);
1617 std::size_t numNodes = numElements * numNodesByElements;
1619 nodeTags.reserve(numNodes);
1620 coord.reserve(numNodes * 3);
1621 if(returnParametricCoord) { parametricCoord.reserve(numNodes * 3); }
1623 for(std::size_t i = 0; i < entities.size(); i++) {
1625 for(std::size_t j = 0;
1626 j < entities[i]->getNumMeshElementsByType(familyType); j++) {
1630 nodeTags.push_back(v->
getNum());
1631 coord.push_back(v->
x());
1632 coord.push_back(v->
y());
1633 coord.push_back(v->
z());
1634 if(dim > 0 && returnParametricCoord) {
1636 for(
int k = 0; k < dim; k++) {
1637 if(v->
getParameter(k, par)) parametricCoord.push_back(par);
1645 GMSH_API void gmsh::model::mesh::getNode(
const std::size_t nodeTag,
1646 std::vector<double> &coord,
1647 std::vector<double> ¶metricCoord,
1660 parametricCoord.reserve(2);
1662 if(v->
getParameter(0, u)) parametricCoord.push_back(u);
1663 if(v->
getParameter(1, u)) parametricCoord.push_back(u);
1669 Msg::Warning(
"Node %d is not classified on any entity", nodeTag);
1676 gmsh::model::mesh::setNode(
const std::size_t nodeTag,
1677 const std::vector<double> &coord,
1678 const std::vector<double> ¶metricCoord)
1686 if(coord.size() < 3) {
1687 Msg::Error(
"Less than three coordinates provided for node %d", nodeTag);
1690 v->
setXYZ(coord[0], coord[1], coord[2]);
1691 if(parametricCoord.size() >= 1) v->
setParameter(0, parametricCoord[0]);
1692 if(parametricCoord.size() >= 2) v->
setParameter(1, parametricCoord[1]);
1695 GMSH_API void gmsh::model::mesh::rebuildNodeCache(
bool onlyIfNecessary)
1701 GMSH_API void gmsh::model::mesh::rebuildElementCache(
bool onlyIfNecessary)
1708 gmsh::model::mesh::getNodesForPhysicalGroup(
const int dim,
const int tag,
1709 std::vector<std::size_t> &nodeTags,
1710 std::vector<double> &coord)
1715 std::vector<MVertex *> v;
1717 if(v.empty())
return;
1718 nodeTags.resize(v.size());
1719 coord.resize(v.size() * 3);
1720 for(std::size_t i = 0; i < v.size(); i++) {
1721 nodeTags[i] = v[i]->getNum();
1722 coord[3 * i + 0] = v[i]->x();
1723 coord[3 * i + 1] = v[i]->y();
1724 coord[3 * i + 2] = v[i]->z();
1728 GMSH_API void gmsh::model::mesh::getMaxNodeTag(std::size_t &maxTag)
1734 GMSH_API void gmsh::model::mesh::addNodes(
1735 const int dim,
const int tag,
const std::vector<std::size_t> &nodeTags,
1736 const std::vector<double> &coord,
const std::vector<double> ¶metricCoord)
1744 int numNodeTags = nodeTags.size(), numNodes = nodeTags.size();
1746 numNodes = coord.size() / 3;
1748 if((
int)coord.size() != 3 * numNodes) {
1753 if(parametricCoord.size()) {
1754 if((
int)parametricCoord.size() != dim * numNodes) {
1755 Msg::Error(
"Wrong number of parametric coordinates");
1760 for(
int i = 0; i < numNodes; i++) {
1761 std::size_t tag = (numNodeTags ? nodeTags[i] : 0);
1762 double x = coord[3 * i];
1763 double y = coord[3 * i + 1];
1764 double z = coord[3 * i + 2];
1766 if(param && dim == 1) {
1767 double u = parametricCoord[i];
1770 else if(param && dim == 2) {
1771 double u = parametricCoord[2 * i];
1772 double v = parametricCoord[2 * i + 1];
1776 vv =
new MVertex(x, y,
z, ge, tag);
1782 GMSH_API void gmsh::model::mesh::reclassifyNodes()
1788 GMSH_API void gmsh::model::mesh::relocateNodes(
const int dim,
const int tag)
1791 std::vector<GEntity *> entities;
1792 if(dim >= 0 && tag >= 0) {
1798 entities.push_back(ge);
1803 for(std::size_t i = 0; i < entities.size(); i++)
1804 entities[i]->relocateMeshVertices();
1809 std::map<
int, std::vector<GEntity *> > &typeEnt)
1811 std::vector<GEntity *> entities;
1812 if(dim >= 0 && tag >= 0) {
1818 entities.push_back(ge);
1823 for(std::size_t i = 0; i < entities.size(); i++) {
1829 typeEnt[v->
points.front()->getTypeForMSH()].push_back(ge);
1835 typeEnt[e->
lines.front()->getTypeForMSH()].push_back(ge);
1840 if(
f->triangles.size())
1841 typeEnt[
f->triangles.front()->getTypeForMSH()].push_back(ge);
1842 if(
f->quadrangles.size())
1843 typeEnt[
f->quadrangles.front()->getTypeForMSH()].push_back(ge);
1849 typeEnt[r->
tetrahedra.front()->getTypeForMSH()].push_back(ge);
1851 typeEnt[r->
hexahedra.front()->getTypeForMSH()].push_back(ge);
1853 typeEnt[r->
prisms.front()->getTypeForMSH()].push_back(ge);
1855 typeEnt[r->
pyramids.front()->getTypeForMSH()].push_back(ge);
1862 GMSH_API void gmsh::model::mesh::getElements(
1863 std::vector<int> &elementTypes,
1864 std::vector<std::vector<std::size_t> > &elementTags,
1865 std::vector<std::vector<std::size_t> > &nodeTags,
const int dim,
1869 elementTypes.clear();
1870 elementTags.clear();
1872 std::map<int, std::vector<GEntity *> > typeEnt;
1874 for(
auto it = typeEnt.begin(); it != typeEnt.end(); it++) {
1875 elementTypes.push_back(it->first);
1876 elementTags.push_back(std::vector<std::size_t>());
1877 nodeTags.push_back(std::vector<std::size_t>());
1878 int elementType = it->first;
1879 for(std::size_t i = 0; i < it->second.size(); i++) {
1884 elementTags.back().push_back(e->
getNum());
1896 std::vector<std::size_t> &nodeTags,
1903 Msg::Error(
"Unknown element %d", elementTag);
1911 Msg::Error(
"Unknown node in element %d", elementTag);
1914 nodeTags.push_back(v->
getNum());
1920 GMSH_API void gmsh::model::mesh::getElementByCoordinates(
1921 const double x,
const double y,
const double z, std::size_t &elementTag,
1922 int &elementType, std::vector<std::size_t> &nodeTags,
double &u,
double &v,
1923 double &w,
const int dim,
const bool strict)
1933 Msg::Error(
"No element found at (%g, %g, %g)", x, y,
z);
1936 elementTag = e->
getNum();
1941 Msg::Error(
"Unknown node in element %d", elementTag);
1944 nodeTags.push_back(v->
getNum());
1951 GMSH_API void gmsh::model::mesh::getElementsByCoordinates(
1952 const double x,
const double y,
const double z,
1953 std::vector<std::size_t> &elementTags,
const int dim,
const bool strict)
1957 elementTags.clear();
1958 std::vector<MElement *> e =
1961 Msg::Error(
"No element found at (%g, %g, %g)", x, y,
z);
1964 for(std::size_t i = 0; i < e.size(); i++) {
1965 elementTags.push_back(e[i]->getNum());
1969 GMSH_API void gmsh::model::mesh::getLocalCoordinatesInElement(
1970 const std::size_t elementTag,
const double x,
const double y,
const double z,
1971 double &u,
double &v,
double &w)
1976 Msg::Error(
"Unknown element %d", elementTag);
1979 double xyz[3] = {x, y,
z}, uvw[3];
1987 static void _addElements(
int dim,
int tag,
const std::vector<MElement *> &src,
1988 std::vector<T *> &dst)
1990 for(std::size_t i = 0; i < src.size(); i++)
1991 dst.push_back(
static_cast<T *
>(src[i]));
1995 const std::vector<std::size_t> &elementTags,
1996 const std::vector<std::size_t> &nodeTags)
1999 if(!numNodesPerEle)
return;
2000 std::size_t numEleTags = elementTags.size();
2001 std::size_t numEle = numEleTags;
2002 if(!numEle) { numEle = nodeTags.size() / numNodesPerEle; }
2004 if(numEle * numNodesPerEle != nodeTags.size()) {
2005 Msg::Error(
"Wrong number of node tags for element type %d", type);
2008 std::vector<MElement *> elements(numEle);
2009 std::vector<MVertex *> nodes(numNodesPerEle);
2010 for(std::size_t j = 0; j < numEle; j++) {
2011 std::size_t etag = (numEleTags ? elementTags[j] : 0);
2013 for(std::size_t k = 0; k < numNodesPerEle; k++) {
2014 std::size_t vtag = nodeTags[numNodesPerEle * j + k];
2022 elements[j] =
f.create(type, nodes, etag);
2064 GMSH_API void gmsh::model::mesh::getMaxElementTag(std::size_t &maxTag)
2070 GMSH_API void gmsh::model::mesh::addElements(
2071 const int dim,
const int tag,
const std::vector<int> &elementTypes,
2072 const std::vector<std::vector<std::size_t> > &elementTags,
2073 const std::vector<std::vector<std::size_t> > &nodeTags)
2081 if(elementTypes.size() != elementTags.size()) {
2085 if(elementTypes.size() != nodeTags.size()) {
2090 for(std::size_t i = 0; i < elementTypes.size(); i++)
2091 _addElements(dim, tag, ge, elementTypes[i], elementTags[i], nodeTags[i]);
2095 GMSH_API void gmsh::model::mesh::addElementsByType(
2096 const int tag,
const int elementType,
2097 const std::vector<std::size_t> &elementTags,
2098 const std::vector<std::size_t> &nodeTags)
2107 _addElements(dim, tag, ge, elementType, elementTags, nodeTags);
2111 GMSH_API void gmsh::model::mesh::getElementTypes(std::vector<int> &elementTypes,
2112 const int dim,
const int tag)
2115 elementTypes.clear();
2116 std::map<int, std::vector<GEntity *> > typeEnt;
2118 for(
auto it = typeEnt.begin(); it != typeEnt.end(); it++) {
2119 elementTypes.push_back(it->first);
2123 GMSH_API int gmsh::model::mesh::getElementType(
const std::string &family,
2125 const bool serendip)
2129 (family ==
"Point" || family ==
"point") ?
TYPE_PNT :
2130 (family ==
"Line" || family ==
"line") ?
TYPE_LIN :
2131 (family ==
"Triangle" || family ==
"triangle") ?
TYPE_TRI :
2132 (family ==
"Quadrangle" || family ==
"quadrangle") ?
TYPE_QUA :
2133 (family ==
"Tetrahedron" || family ==
"tetrahedron") ?
TYPE_TET :
2134 (family ==
"Pyramid" || family ==
"pyramid") ?
TYPE_PYR :
2135 (family ==
"Prism" || family ==
"prism") ?
TYPE_PRI :
2136 (family ==
"Hexahedron" || family ==
"hexahedron") ?
TYPE_HEX :
2137 (family ==
"Polygon" || family ==
"polygon") ?
TYPE_POLYG :
2138 (family ==
"Polyhedron" || family ==
"polyhedron") ?
TYPE_POLYH :
2139 (family ==
"Trihedron" || family ==
"trihedron") ?
TYPE_TRIH :
2144 GMSH_API void gmsh::model::mesh::getElementProperties(
2145 const int elementType, std::string &name,
int &dim,
int &order,
int &numNodes,
2146 std::vector<double> &localNodeCoord,
int &numPrimaryNodes)
2159 order = basis->
order;
2162 Msg::Error(
"Size of basis incompatible with element type");
2167 localNodeCoord.push_back(basis->
points(i, j));
2173 GMSH_API void gmsh::model::mesh::getElementsByType(
2174 const int elementType, std::vector<std::size_t> &elementTags,
2175 std::vector<std::size_t> &nodeTags,
const int tag,
const std::size_t task,
2176 const std::size_t numTasks)
2180 std::map<int, std::vector<GEntity *> > typeEnt;
2182 const std::vector<GEntity *> &entities(typeEnt[elementType]);
2184 std::size_t numElements = 0;
2185 for(std::size_t i = 0; i < entities.size(); i++)
2186 numElements += entities[i]->getNumMeshElementsByType(familyType);
2193 bool haveElementTags = !elementTags.empty();
2194 bool haveNodeTags = !nodeTags.empty();
2195 if((!haveElementTags && !haveNodeTags) ||
2196 (haveElementTags && (elementTags.size() != numElements)) ||
2197 (haveNodeTags && (nodeTags.size() != numElements * numNodes))) {
2199 Msg::Warning(
"ElementTags and nodeTags should be preallocated "
2201 haveElementTags = haveNodeTags =
true;
2202 preallocateElementsByType(elementType, haveElementTags, haveNodeTags,
2203 elementTags, nodeTags, tag);
2205 const std::size_t begin = (task * numElements) / numTasks;
2206 const std::size_t end = ((task + 1) * numElements) / numTasks;
2208 size_t idx = begin * numNodes;
2209 for(std::size_t i = 0; i < entities.size(); i++) {
2212 if(o >= begin && o < end) {
2214 if(haveElementTags) elementTags[o] = e->
getNum();
2226 GMSH_API void gmsh::model::mesh::preallocateElementsByType(
2227 const int elementType,
const bool elementTag,
const bool nodeTag,
2228 std::vector<std::size_t> &elementTags, std::vector<std::size_t> &nodeTags,
2233 std::map<int, std::vector<GEntity *> > typeEnt;
2235 const std::vector<GEntity *> &entities(typeEnt[elementType]);
2237 std::size_t numElements = 0;
2238 for(std::size_t i = 0; i < entities.size(); i++)
2239 numElements += entities[i]->getNumMeshElementsByType(familyType);
2241 if(!numElements)
return;
2243 elementTags.clear();
2244 elementTags.resize(numElements, 0);
2248 nodeTags.resize(numElements * numNodesPerEle, 0);
2252 GMSH_API void gmsh::model::mesh::getElementQualities(
2253 const std::vector<std::size_t> &elementTags,
2254 std::vector<double> &elementQualities,
const std::string &qualityName,
2255 const std::size_t task,
const std::size_t numTasks)
2264 std::size_t numElements = elementTags.size();
2265 bool haveElementQualities = elementQualities.size();
2266 if(!haveElementQualities ||
2267 (haveElementQualities && (elementQualities.size() < numElements))) {
2269 Msg::Warning(
"elementQualities should be preallocated "
2271 haveElementQualities =
true;
2272 elementQualities.clear();
2273 elementQualities.resize(numElements, 0.);
2276 const std::size_t begin = (task * numElements) / numTasks;
2277 const std::size_t end = ((task + 1) * numElements) / numTasks;
2278 for(
size_t k = begin; k < end; k++){
2281 Msg::Error(
"Unknown element %d", elementTags[k]);
2282 elementQualities[k] = 0.;
2285 if(qualityName ==
"minSICN"){
2288 else if(qualityName ==
"minSIGE"){
2291 else if(qualityName ==
"minSJ"){
2294 else if(qualityName ==
"gamma"){
2297 else if(qualityName ==
"eta"){
2300 else if(qualityName ==
"minIsotropy"){
2303 else if(qualityName ==
"angleShape"){
2306 else if(qualityName ==
"volume"){
2311 Msg::Error(
"Unknown quality name '%s'", qualityName.c_str());
2313 elementQualities[k] = 0.;
2319 std::string &fsName,
int &fsOrder,
2322 if(fsType.empty() || fsType ==
"None") {
2328 if(fsType.size() > 8 && fsType.substr(0,8) ==
"Lagrange") {
2329 fsName =
"Lagrange";
2330 fsOrder = atoi(fsType.substr(8).c_str());
2334 if(fsType.size() > 12 && fsType.substr(0,12) ==
"GradLagrange") {
2335 fsName =
"GradLagrange";
2336 fsOrder = atoi(fsType.substr(12).c_str());
2340 if(fsType ==
"IsoParametric" || fsType ==
"Lagrange") {
2341 fsName =
"Lagrange";
2346 if(fsType ==
"GradIsoParametric" || fsType ==
"GradLagrange") {
2347 fsName =
"GradLagrange";
2352 if(fsType.substr(0, 10) ==
"H1Legendre") {
2353 fsName =
"H1Legendre";
2354 fsOrder = atoi(fsType.substr(10).c_str());
2358 if(fsType.substr(0, 14) ==
"GradH1Legendre") {
2359 fsName =
"GradH1Legendre";
2360 fsOrder = atoi(fsType.substr(14).c_str());
2364 if(fsType.substr(0, 13) ==
"HcurlLegendre") {
2365 fsName =
"HcurlLegendre";
2366 fsOrder = atoi(fsType.substr(13).c_str());
2370 if(fsType.substr(0, 17) ==
"CurlHcurlLegendre") {
2371 fsName =
"CurlHcurlLegendre";
2372 fsOrder = atoi(fsType.substr(17).c_str());
2379 GMSH_API void gmsh::model::mesh::getJacobians(
2380 const int elementType,
const std::vector<double> &localCoord,
2381 std::vector<double> &jacobians, std::vector<double> &determinants,
2382 std::vector<double> &coord,
const int tag,
const std::size_t task,
2383 const std::size_t numTasks)
2386 int numPoints = localCoord.size() / 3;
2392 std::map<int, std::vector<GEntity *> > typeEnt;
2394 const std::vector<GEntity *> &entities(typeEnt[elementType]);
2396 std::size_t numElements = 0;
2397 for(std::size_t i = 0; i < entities.size(); i++) {
2407 bool haveJacobians = !jacobians.empty();
2408 bool haveDeterminants = !determinants.empty();
2409 bool havePoints = !coord.empty();
2410 if((!haveDeterminants && !haveJacobians && !havePoints) ||
2411 (haveDeterminants && (numElements * numPoints != determinants.size())) ||
2412 (haveJacobians && (9 * numElements * numPoints != jacobians.size())) ||
2413 (havePoints && (3 * numElements * numPoints > coord.size()))) {
2415 Msg::Warning(
"Jacobians, determinants and points should be preallocated "
2417 haveJacobians = haveDeterminants = havePoints =
true;
2418 preallocateJacobians(elementType, numPoints, haveJacobians,
2419 haveDeterminants, havePoints, jacobians, determinants,
2424 const size_t begin = (task * numElements) / numTasks;
2425 const size_t end = ((task + 1) * numElements) / numTasks;
2426 if(haveDeterminants && haveJacobians && havePoints) {
2427 std::vector<std::vector<SVector3> > gsf;
2429 size_t idx = begin * numPoints;
2430 for(std::size_t i = 0; i < entities.size(); i++) {
2434 if(o >= begin && o < end) {
2436 if(gsf.size() == 0) {
2437 gsf.resize(numPoints);
2438 for(
int k = 0; k < numPoints; k++) {
2439 double value[1256][3];
2441 localCoord[3 * k + 1],
2442 localCoord[3 * k + 2], value);
2445 gsf[k][l][0] = value[l][0];
2446 gsf[k][l][1] = value[l][1];
2447 gsf[k][l][2] = value[l][2];
2451 for(
int k = 0; k < numPoints; k++) {
2452 e->
pnt(localCoord[3 * k], localCoord[3 * k + 1],
2453 localCoord[3 * k + 2], &coord[idx * 3]);
2454 determinants[idx] = e->
getJacobian(gsf[k], &jacobians[idx * 9]);
2462 else if(haveDeterminants && haveJacobians && !havePoints) {
2463 std::vector<std::vector<SVector3> > gsf;
2465 size_t idx = begin * numPoints;
2466 for(std::size_t i = 0; i < entities.size(); i++) {
2470 if(o >= begin && o < end) {
2472 if(gsf.size() == 0) {
2473 gsf.resize(numPoints);
2474 for(
int k = 0; k < numPoints; k++) {
2475 double value[1256][3];
2477 localCoord[3 * k + 1],
2478 localCoord[3 * k + 2], value);
2481 gsf[k][l][0] = value[l][0];
2482 gsf[k][l][1] = value[l][1];
2483 gsf[k][l][2] = value[l][2];
2487 for(
int k = 0; k < numPoints; k++) {
2488 determinants[idx] = e->
getJacobian(gsf[k], &jacobians[idx * 9]);
2496 else if(haveDeterminants && !haveJacobians && havePoints) {
2497 std::vector<double> jac(9, 0.);
2498 std::vector<std::vector<SVector3> > gsf;
2500 size_t idx = begin * numPoints;
2501 for(std::size_t i = 0; i < entities.size(); i++) {
2505 if(o >= begin && o < end) {
2507 if(gsf.size() == 0) {
2508 gsf.resize(numPoints);
2509 for(
int k = 0; k < numPoints; k++) {
2510 double value[1256][3];
2512 localCoord[3 * k + 1],
2513 localCoord[3 * k + 2], value);
2516 gsf[k][l][0] = value[l][0];
2517 gsf[k][l][1] = value[l][1];
2518 gsf[k][l][2] = value[l][2];
2522 for(
int k = 0; k < numPoints; k++) {
2523 e->
pnt(localCoord[3 * k], localCoord[3 * k + 1],
2524 localCoord[3 * k + 2], &coord[idx * 3]);
2525 determinants[idx] = e->
getJacobian(gsf[k], &jac[0]);
2533 else if(haveDeterminants && !haveJacobians && !havePoints) {
2534 std::vector<double> jac(9, 0.);
2535 std::vector<std::vector<SVector3> > gsf;
2537 size_t idx = begin * numPoints;
2538 for(std::size_t i = 0; i < entities.size(); i++) {
2542 if(o >= begin && o < end) {
2544 if(gsf.size() == 0) {
2545 gsf.resize(numPoints);
2546 for(
int k = 0; k < numPoints; k++) {
2547 double value[1256][3];
2549 localCoord[3 * k + 1],
2550 localCoord[3 * k + 2], value);
2553 gsf[k][l][0] = value[l][0];
2554 gsf[k][l][1] = value[l][1];
2555 gsf[k][l][2] = value[l][2];
2559 for(
int k = 0; k < numPoints; k++) {
2560 determinants[idx] = e->
getJacobian(gsf[k], &jac[0]);
2568 else if(!haveDeterminants && haveJacobians && !havePoints) {
2569 std::vector<std::vector<SVector3> > gsf;
2571 size_t idx = begin * numPoints;
2572 for(std::size_t i = 0; i < entities.size(); i++) {
2576 if(o >= begin && o < end) {
2578 if(gsf.size() == 0) {
2579 gsf.resize(numPoints);
2580 for(
int k = 0; k < numPoints; k++) {
2581 double value[1256][3];
2583 localCoord[3 * k + 1],
2584 localCoord[3 * k + 2], value);
2587 gsf[k][l][0] = value[l][0];
2588 gsf[k][l][1] = value[l][1];
2589 gsf[k][l][2] = value[l][2];
2593 for(
int k = 0; k < numPoints; k++) {
2603 Msg::Error(
"The case with 'haveDeterminants = %s', `haveJacobians = %s` "
2604 "and 'havePoints = %s' is not yet implemented",
2605 (haveDeterminants ?
"true" :
"false"),
2606 (haveJacobians ?
"true" :
"false"),
2607 (havePoints ?
"true" :
"false"));
2614 GMSH_API void gmsh::model::mesh::preallocateJacobians(
2615 const int elementType,
const int numPoints,
const bool allocateJacobians,
2616 const bool allocateDeterminants,
const bool allocateCoord,
2617 std::vector<double> &jacobians, std::vector<double> &determinants,
2618 std::vector<double> &coord,
const int tag)
2623 std::map<int, std::vector<GEntity *> > typeEnt;
2625 const std::vector<GEntity *> &entities(typeEnt[elementType]);
2627 std::size_t numElements = 0;
2628 for(std::size_t i = 0; i < entities.size(); i++)
2629 numElements += entities[i]->getNumMeshElementsByType(familyType);
2630 if(!numElements)
return;
2631 if(allocateJacobians) {
2633 jacobians.resize(9 * numElements * numPoints);
2635 if(allocateDeterminants) {
2636 determinants.clear();
2637 determinants.resize(numElements * numPoints);
2641 coord.resize(3 * numElements * numPoints);
2645 GMSH_API void gmsh::model::mesh::getJacobian(
2646 const std::size_t elementTag,
const std::vector<double> &localCoord,
2647 std::vector<double> &jacobians, std::vector<double> &determinants,
2648 std::vector<double> &coord)
2653 Msg::Error(
"Unknown element %d", elementTag);
2656 int numPoints = localCoord.size() / 3;
2661 std::vector<std::vector<SVector3> > gsf;
2662 gsf.resize(numPoints);
2663 jacobians.resize(9 * numPoints);
2664 determinants.resize(numPoints);
2665 coord.resize(3 * numPoints);
2666 for(
int k = 0; k < numPoints; k++) {
2667 double value[1256][3];
2669 localCoord[3 * k + 2], value);
2672 gsf[k][l][0] = value[l][0];
2673 gsf[k][l][1] = value[l][1];
2674 gsf[k][l][2] = value[l][2];
2677 for(
int k = 0; k < numPoints; k++) {
2678 e->
pnt(localCoord[3 * k], localCoord[3 * k + 1], localCoord[3 * k + 2],
2680 determinants[k] = e->
getJacobian(gsf[k], &jacobians[9 * k]);
2684 GMSH_API void gmsh::model::mesh::getBasisFunctions(
2685 const int elementType,
const std::vector<double> &localCoord,
2686 const std::string &functionSpaceType,
int &numComponents,
2687 std::vector<double> &basisFunctions,
int &numOrientations,
2688 const std::vector<int> &wantedOrientations)
2692 basisFunctions.clear();
2693 std::string fsName =
"";
2697 Msg::Error(
"Unknown function space type '%s'", functionSpaceType.c_str());
2701 const std::size_t numberOfGaussPoints = localCoord.size() / 3;
2704 if(fsName ==
"Lagrange" || fsName ==
"GradLagrange") {
2706 if(wantedOrientations.size() != 0) {
2707 if(wantedOrientations.size() > 1) {
2708 Msg::Error(
"Asking for more orientation that there exist");
2712 if(wantedOrientations[0] != 0) {
2714 "Orientation %i does not exist for function stace named '%s' on %s",
2715 wantedOrientations[0], fsName.c_str(),
2733 basisFunctions.resize(n * numComponents * numberOfGaussPoints, 0.);
2734 double s[1256], ds[1256][3];
2735 for(std::size_t i = 0; i < numberOfGaussPoints; i++) {
2736 double u = localCoord[i * 3];
2737 double v = localCoord[i * 3 + 1];
2738 double w = localCoord[i * 3 + 2];
2739 switch(numComponents) {
2741 basis->
f(u, v, w, s);
2742 for(std::size_t j = 0; j < n; j++) basisFunctions[n * i + j] = s[j];
2745 basis->
df(u, v, w, ds);
2746 for(std::size_t j = 0; j < n; j++) {
2747 basisFunctions[n * 3 * i + 3 * j] = ds[j][0];
2748 basisFunctions[n * 3 * i + 3 * j + 1] = ds[j][1];
2749 basisFunctions[n * 3 * i + 3 * j + 2] = ds[j][2];
2755 numOrientations = 1;
2759 if(fsName ==
"H1Legendre" || fsName ==
"GradH1Legendre") {
2760 switch(familyType) {
2783 Msg::Error(
"Unknown familyType %i for basis function type %s",
2784 familyType, fsName.c_str());
2788 else if(fsName ==
"HcurlLegendre" || fsName ==
"CurlHcurlLegendre") {
2789 switch(familyType) {
2809 Msg::Error(
"Unknown familyType %i for basis function type %s",
2810 familyType, fsName.c_str());
2815 Msg::Error(
"Unknown function space named '%s'", fsName.c_str());
2819 const std::size_t vSize = basis->getnVertexFunction();
2820 const std::size_t bSize = basis->getnBubbleFunction();
2821 const std::size_t eSize = basis->getnEdgeFunction();
2822 const std::size_t fSize =
2823 basis->getnTriFaceFunction() + basis->getnQuadFaceFunction();
2824 const std::size_t maxOrientation = basis->getNumberOfOrientations();
2825 numOrientations = maxOrientation;
2826 const std::size_t numFunctionsPerElement = vSize + bSize + eSize + fSize;
2827 const unsigned int numVertices =
2830 basisFunctions.resize(
2831 (wantedOrientations.size() == 0 ? maxOrientation :
2832 wantedOrientations.size()) *
2833 numberOfGaussPoints * numFunctionsPerElement * numComponents);
2836 if(wantedOrientations.size() != 0) {
2837 if(wantedOrientations.size() > maxOrientation) {
2838 Msg::Error(
"Asking for more orientation that there exist");
2841 for(
unsigned int i = 0; i < wantedOrientations.size(); ++i) {
2842 if(wantedOrientations[i] >=
static_cast<int>(maxOrientation) ||
2843 wantedOrientations[i] < 0) {
2844 Msg::Error(
"Orientation %i does not exist for function stace named "
2846 wantedOrientations[i], fsName.c_str(),
2851 std::vector<int> sortedWantedOrientations = wantedOrientations;
2852 std::sort(sortedWantedOrientations.begin(),
2853 sortedWantedOrientations.end());
2854 int previousInt = sortedWantedOrientations[0];
2855 for(
unsigned int i = 1; i < sortedWantedOrientations.size(); ++i) {
2856 if(previousInt == sortedWantedOrientations[i]) {
2857 Msg::Error(
"Duplicate wanted orientation found");
2860 previousInt = sortedWantedOrientations[i];
2864 std::vector<MVertex *> vertices(numVertices);
2865 for(
unsigned int i = 0; i < numVertices; ++i) {
2866 vertices[i] =
new MVertex(0., 0., 0.,
nullptr, i + 1);
2869 switch(familyType) {
2892 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
2897 switch(numComponents) {
2899 std::vector<std::vector<double> > vTable(
2900 numberOfGaussPoints,
2901 std::vector<double>(vSize));
2902 std::vector<std::vector<double> > bTable(
2903 numberOfGaussPoints,
2904 std::vector<double>(bSize));
2905 std::vector<std::vector<double> > fTable(
2906 numberOfGaussPoints,
2907 std::vector<double>(fSize));
2908 std::vector<std::vector<double> > eTable(
2909 numberOfGaussPoints,
2910 std::vector<double>(eSize));
2912 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
2913 const double u = localCoord[3 * q];
2914 const double v = localCoord[3 * q + 1];
2915 const double w = localCoord[3 * q + 2];
2917 basis->generateBasis(u, v, w, vTable[q], eTable[q], fTable[q],
2922 std::vector<std::vector<double> > eTableNegativeFlag(eTable);
2924 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
2925 basis->orientEdgeFunctionsForNegativeFlag(eTableNegativeFlag[q]);
2931 std::vector<std::vector<double> > quadFaceFunctionsAllOrientations(
2932 numberOfGaussPoints,
2933 std::vector<double>(basis->getnQuadFaceFunction() * 8, 0));
2934 std::vector<std::vector<double> > triFaceFunctionsAllOrientations(
2935 numberOfGaussPoints,
2936 std::vector<double>(basis->getnTriFaceFunction() * 6, 0));
2938 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
2939 const double u = localCoord[3 * q];
2940 const double v = localCoord[3 * q + 1];
2941 const double w = localCoord[3 * q + 2];
2943 basis->addAllOrientedFaceFunctions(
2944 u, v, w, fTable[q], quadFaceFunctionsAllOrientations[q],
2945 triFaceFunctionsAllOrientations[q]);
2949 std::vector<std::vector<double> > eTableCopy(
2950 numberOfGaussPoints,
2951 std::vector<double>(eSize, 0));
2952 std::vector<std::vector<double> > fTableCopy(
2953 numberOfGaussPoints,
2954 std::vector<double>(fSize, 0));
2956 unsigned int iOrientationIndex = 0;
2957 for(
unsigned int iOrientation = 0; iOrientation < maxOrientation;
2959 if(wantedOrientations.size() != 0) {
2960 auto it = std::find(wantedOrientations.begin(),
2961 wantedOrientations.end(), iOrientation);
2962 if(it != wantedOrientations.end()) {
2963 iOrientationIndex = &(*it) - &wantedOrientations[0];
2967 std::next_permutation(vertices.begin(), vertices.end(), comp);
2968 for(
unsigned int i = 0; i < numVertices; ++i) {
2969 element->setVertex(i, vertices[i]);
2975 iOrientationIndex = iOrientation;
2979 for(
int iEdge = 0; iEdge < basis->getNumEdge(); ++iEdge) {
2982 const int orientationFlag =
2984 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
2985 basis->orientEdge(orientationFlag, iEdge, eTableCopy[q],
2986 eTable[q], eTableNegativeFlag[q]);
2993 iFace < basis->getNumTriFace() + basis->getNumQuadFace();
2996 std::vector<int> faceOrientationFlag(3);
2998 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
2999 basis->orientFace(faceOrientationFlag[0], faceOrientationFlag[1],
3000 faceOrientationFlag[2], iFace,
3001 quadFaceFunctionsAllOrientations[q],
3002 triFaceFunctionsAllOrientations[q],
3008 const std::size_t offsetOrientation =
3009 iOrientationIndex * numberOfGaussPoints * numFunctionsPerElement;
3010 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
3011 const std::size_t offsetGP = q * numFunctionsPerElement;
3013 for(
unsigned int i = 0; i < vSize; ++i) {
3014 basisFunctions[offsetOrientation + offsetGP + i] = vTable[q][i];
3016 unsigned int offset = vSize;
3017 for(
unsigned int i = 0; i < eSize; ++i) {
3018 basisFunctions[offsetOrientation + offsetGP + offset + i] =
3022 for(
unsigned int i = 0; i < fSize; ++i) {
3023 basisFunctions[offsetOrientation + offsetGP + offset + i] =
3027 for(
unsigned int i = 0; i < bSize; ++i) {
3028 basisFunctions[offsetOrientation + offsetGP + offset + i] =
3034 std::next_permutation(vertices.begin(), vertices.end(), comp);
3035 for(
unsigned int i = 0; i < numVertices; ++i) {
3036 element->setVertex(i, vertices[i]);
3042 std::vector<std::vector<std::vector<double> > > vTable(
3043 numberOfGaussPoints,
3044 std::vector<std::vector<double> >(
3046 std::vector<double>(3, 0.)));
3047 std::vector<std::vector<std::vector<double> > > bTable(
3048 numberOfGaussPoints,
3049 std::vector<std::vector<double> >(
3051 std::vector<double>(3, 0.)));
3052 std::vector<std::vector<std::vector<double> > > fTable(
3053 numberOfGaussPoints,
3054 std::vector<std::vector<double> >(
3055 fSize, std::vector<double>(3, 0.)));
3056 std::vector<std::vector<std::vector<double> > > eTable(
3057 numberOfGaussPoints,
3058 std::vector<std::vector<double> >(
3059 eSize, std::vector<double>(3, 0.)));
3061 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
3062 const double u = localCoord[3 * q];
3063 const double v = localCoord[3 * q + 1];
3064 const double w = localCoord[3 * q + 2];
3066 basis->generateBasis(u, v, w, vTable[q], eTable[q], fTable[q],
3071 std::vector<std::vector<std::vector<double> > > eTableNegativeFlag(
3074 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
3075 basis->orientEdgeFunctionsForNegativeFlag(eTableNegativeFlag[q]);
3081 std::vector<std::vector<std::vector<double> > >
3082 quadFaceFunctionsAllOrientations(
3083 numberOfGaussPoints,
3084 std::vector<std::vector<double> >(basis->getnQuadFaceFunction() * 8,
3085 std::vector<double>(3, 0.)));
3086 std::vector<std::vector<std::vector<double> > >
3087 triFaceFunctionsAllOrientations(
3088 numberOfGaussPoints,
3089 std::vector<std::vector<double> >(basis->getnTriFaceFunction() * 6,
3090 std::vector<double>(3, 0.)));
3092 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
3093 const double u = localCoord[3 * q];
3094 const double v = localCoord[3 * q + 1];
3095 const double w = localCoord[3 * q + 2];
3097 basis->addAllOrientedFaceFunctions(
3098 u, v, w, fTable[q], quadFaceFunctionsAllOrientations[q],
3099 triFaceFunctionsAllOrientations[q], fsName);
3103 std::vector<std::vector<std::vector<double> > > eTableCopy(
3104 numberOfGaussPoints,
3105 std::vector<std::vector<double> >(
3107 std::vector<double>(3, 0.)));
3108 std::vector<std::vector<std::vector<double> > > fTableCopy(
3109 numberOfGaussPoints,
3110 std::vector<std::vector<double> >(
3112 std::vector<double>(3, 0.)));
3114 unsigned int iOrientationIndex = 0;
3115 for(
unsigned int iOrientation = 0; iOrientation < maxOrientation;
3117 if(wantedOrientations.size() != 0) {
3118 auto it = std::find(wantedOrientations.begin(),
3119 wantedOrientations.end(), iOrientation);
3120 if(it != wantedOrientations.end()) {
3121 iOrientationIndex = &(*it) - &wantedOrientations[0];
3125 std::next_permutation(vertices.begin(), vertices.end(), comp);
3126 for(
unsigned int i = 0; i < numVertices; ++i) {
3127 element->setVertex(i, vertices[i]);
3133 iOrientationIndex = iOrientation;
3137 for(
int iEdge = 0; iEdge < basis->getNumEdge(); ++iEdge) {
3140 const int orientationFlag =
3142 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
3143 basis->orientEdge(orientationFlag, iEdge, eTableCopy[q],
3144 eTable[q], eTableNegativeFlag[q]);
3151 iFace < basis->getNumTriFace() + basis->getNumQuadFace();
3154 std::vector<int> faceOrientationFlag(3);
3156 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
3157 basis->orientFace(faceOrientationFlag[0], faceOrientationFlag[1],
3158 faceOrientationFlag[2], iFace,
3159 quadFaceFunctionsAllOrientations[q],
3160 triFaceFunctionsAllOrientations[q],
3166 const std::size_t offsetOrientation =
3167 iOrientationIndex * numberOfGaussPoints * numFunctionsPerElement * 3;
3168 for(
unsigned int q = 0; q < numberOfGaussPoints; ++q) {
3169 const std::size_t offsetGP = q * numFunctionsPerElement * 3;
3171 for(
unsigned int i = 0; i < vSize; ++i) {
3172 basisFunctions[offsetOrientation + offsetGP + 3 * i] =
3174 basisFunctions[offsetOrientation + offsetGP + 3 * i + 1] =
3176 basisFunctions[offsetOrientation + offsetGP + 3 * i + 2] =
3179 unsigned int offset = 3 * vSize;
3180 for(
unsigned int i = 0; i < eSize; ++i) {
3181 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i] =
3182 eTableCopy[q][i][0];
3183 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i + 1] =
3184 eTableCopy[q][i][1];
3185 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i + 2] =
3186 eTableCopy[q][i][2];
3188 offset += 3 * eSize;
3189 for(
unsigned int i = 0; i < fSize; ++i) {
3190 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i] =
3191 fTableCopy[q][i][0];
3192 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i + 1] =
3193 fTableCopy[q][i][1];
3194 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i + 2] =
3195 fTableCopy[q][i][2];
3197 offset += 3 * fSize;
3198 for(
unsigned int i = 0; i < bSize; ++i) {
3199 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i] =
3201 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i + 1] =
3203 basisFunctions[offsetOrientation + offsetGP + offset + 3 * i + 2] =
3209 std::next_permutation(vertices.begin(), vertices.end(), comp);
3210 for(
unsigned int i = 0; i < numVertices; ++i) {
3211 element->setVertex(i, vertices[i]);
3218 for(
unsigned int i = 0; i < numVertices; ++i) {
delete vertices[i]; }
3226 GMSH_API void gmsh::model::mesh::getBasisFunctionsOrientation(
3227 const int elementType,
const std::string &functionSpaceType,
3228 std::vector<int> &basisFunctionsOrientation,
const int tag,
3229 const std::size_t task,
const std::size_t numTasks)
3234 std::string fsName =
"";
3235 int numComponents = 0;
3238 Msg::Error(
"Unknown function space type '%s'", functionSpaceType.c_str());
3243 std::map<int, std::vector<GEntity *> > typeEnt;
3245 const std::vector<GEntity *> &entities(typeEnt[elementType]);
3247 std::size_t numElements = 0;
3248 for(std::size_t i = 0; i < entities.size(); i++) {
3249 const GEntity *ge = entities[i];
3253 if(basisFunctionsOrientation.empty() ||
3254 numElements != basisFunctionsOrientation.size()) {
3257 "basisFunctionsOrientation should be preallocated if numTasks > 1");
3259 preallocateBasisFunctionsOrientation(
3260 elementType, basisFunctionsOrientation, tag);
3263 if(fsName ==
"Lagrange" || fsName ==
"GradLagrange") {
3264 const std::size_t begin = task * numElements / numTasks;
3265 const std::size_t end = (task + 1) * numElements / numTasks;
3266 for(std::size_t iElement = begin; iElement < end; ++iElement) {
3267 basisFunctionsOrientation[iElement] = 0;
3271 const unsigned int numVertices =
3273 std::vector<MVertex *> vertices(numVertices);
3274 std::vector<unsigned int> verticesOrder(numVertices);
3275 const std::size_t factorial[8] = {1, 1, 2, 6, 24, 120, 720, 5040};
3277 std::size_t entityOffset = 0;
3279 for(std::size_t iEntity = 0; iEntity < entities.size(); ++iEntity) {
3280 const GEntity *ge = entities[iEntity];
3283 const std::size_t begin = task * localNumElements / numTasks;
3284 const std::size_t end = (task + 1) * localNumElements / numTasks;
3286 for(std::size_t iElement = begin; iElement < end; ++iElement) {
3288 for(std::size_t i = 0; i < numVertices; ++i) {
3292 for(std::size_t i = 0; i < numVertices; ++i) {
3293 std::size_t max = 0;
3294 std::size_t maxPos = 0;
3295 for(std::size_t j = 0; j < numVertices; ++j) {
3296 if(vertices[j] !=
nullptr) {
3297 if(max < vertices[j]->getNum()) {
3298 max = vertices[j]->
getNum();
3303 vertices[maxPos] =
nullptr;
3304 verticesOrder[maxPos] = numVertices - i - 1;
3307 std::size_t elementOrientation = 0;
3308 for(std::size_t i = 0; i < numVertices; ++i) {
3309 elementOrientation +=
3310 verticesOrder[i] * factorial[numVertices - i - 1];
3311 for(std::size_t j = i + 1; j < numVertices; ++j) {
3312 if(verticesOrder[j] > verticesOrder[i]) --verticesOrder[j];
3316 basisFunctionsOrientation[entityOffset + iElement] =
3317 (int)elementOrientation;
3320 entityOffset += localNumElements;
3327 GMSH_API void gmsh::model::mesh::getBasisFunctionsOrientationForElement(
3328 const std::size_t elementTag,
const std::string &functionSpaceType,
3329 int &basisFunctionsOrientation)
3334 std::string fsName =
"";
3335 int numComponents = 0;
3338 Msg::Error(
"Unknown function space type '%s'", functionSpaceType.c_str());
3346 if(fsName ==
"Lagrange" || fsName ==
"GradLagrange") {
3347 basisFunctionsOrientation = 0;
3350 const unsigned int numVertices =
3352 std::vector<MVertex *> vertices(numVertices);
3353 std::vector<unsigned int> verticesOrder(numVertices);
3354 const std::size_t factorial[8] = {1, 1, 2, 6, 24, 120, 720, 5040};
3356 for(std::size_t i = 0; i < numVertices; ++i) {
3360 for(std::size_t i = 0; i < numVertices; ++i) {
3361 std::size_t max = 0;
3362 std::size_t maxPos = 0;
3363 for(std::size_t j = 0; j < numVertices; ++j) {
3364 if(vertices[j] !=
nullptr) {
3365 if(max < vertices[j]->getNum()) {
3366 max = vertices[j]->
getNum();
3371 vertices[maxPos] =
nullptr;
3372 verticesOrder[maxPos] = numVertices - i - 1;
3375 basisFunctionsOrientation = 0;
3376 for(std::size_t i = 0; i < numVertices; ++i) {
3377 basisFunctionsOrientation +=
3378 verticesOrder[i] * factorial[numVertices - i - 1];
3379 for(std::size_t j = i + 1; j < numVertices; ++j) {
3380 if(verticesOrder[j] > verticesOrder[i]) --verticesOrder[j];
3389 gmsh::model::mesh::getNumberOfOrientations(
const int elementType,
3390 const std::string &functionSpaceType)
3395 std::string fsName =
"";
3396 int numComponents = 0;
3399 Msg::Error(
"Unknown function space type '%s'", functionSpaceType.c_str());
3403 if(fsName ==
"Lagrange" || fsName ==
"GradLagrange") {
3408 const unsigned int numVertices =
3410 const std::size_t factorial[8] = {1, 1, 2, 6, 24, 120, 720, 5040};
3411 return factorial[numVertices];
3418 gmsh::model::mesh::preallocateBasisFunctionsOrientation(
3419 const int elementType, std::vector<int> &basisFunctionsOrientation,
3425 std::map<int, std::vector<GEntity *> > typeEnt;
3427 const std::vector<GEntity *> &entities(typeEnt[elementType]);
3431 std::size_t numElements = 0;
3432 for(std::size_t i = 0; i < entities.size(); i++) {
3433 const GEntity *ge = entities[i];
3436 if(!numElements)
return;
3437 basisFunctionsOrientation.resize(numElements);
3441 gmsh::model::mesh::getEdges(
const std::vector<std::size_t> &nodeTags,
3442 std::vector<std::size_t> &edgeTags,
3443 std::vector<int> &edgeOrientations)
3446 edgeOrientations.clear();
3447 std::size_t numEdges = nodeTags.size() / 2;
3448 if(!numEdges)
return;
3449 edgeTags.resize(numEdges);
3450 edgeOrientations.resize(numEdges);
3451 for(std::size_t i = 0; i < numEdges; i++) {
3452 std::size_t n0 = nodeTags[2 * i];
3453 std::size_t n1 = nodeTags[2 * i + 1];
3460 edgeOrientations[i] = 1;
3462 edgeOrientations[i] = -1;
3464 edgeOrientations[i] = 0;
3467 Msg::Error(
"Unknown mesh node %d or %d", n0, n1);
3472 GMSH_API void gmsh::model::mesh::getFaces(
3473 const int faceType,
const std::vector<std::size_t> &nodeTags,
3474 std::vector<std::size_t> &faceTags, std::vector<int> &orientations)
3477 orientations.clear();
3478 if(faceType != 3 && faceType != 4) {
3479 Msg::Error(
"Unknown face type (should be 3 or 4)");
3482 std::size_t numFaces = nodeTags.size() / faceType;
3483 if(!numFaces)
return;
3484 faceTags.resize(numFaces);
3485 orientations.resize(numFaces, 0);
3486 for(std::size_t i = 0; i < numFaces; i++) {
3487 std::size_t n0 = nodeTags[faceType * i];
3488 std::size_t n1 = nodeTags[faceType * i + 1];
3489 std::size_t n2 = nodeTags[faceType * i + 2];
3490 std::size_t n3 = (faceType == 4) ? nodeTags[faceType * i + 3] : 0;
3496 if(v0 && v1 && v2) {
3501 Msg::Error(
"Unknown mesh node %d, %d or %d", n0, n1, n2);
3506 GMSH_API void gmsh::model::mesh::createEdges(
const vectorpair &dimTags)
3509 std::vector<GEntity *> entities;
3511 for(std::size_t i = 0; i < entities.size(); i++) {
3523 GMSH_API void gmsh::model::mesh::createFaces(
const vectorpair &dimTags)
3526 std::vector<GEntity *> entities;
3528 for(std::size_t i = 0; i < entities.size(); i++) {
3540 GMSH_API void gmsh::model::mesh::getAllEdges(std::vector<std::size_t> &edgeTags,
3541 std::vector<std::size_t> &edgeNodes)
3548 edgeTags.push_back(it->second);
3549 edgeNodes.push_back(it->first.getVertex(0)->getNum());
3550 edgeNodes.push_back(it->first.getVertex(1)->getNum());
3554 GMSH_API void gmsh::model::mesh::getAllFaces(
const int faceType,
3555 std::vector<std::size_t> &faceTags,
3556 std::vector<std::size_t> &faceNodes)
3559 if(faceType != 3 && faceType != 4) {
3560 Msg::Error(
"Unknown face type (should be 3 or 4)");
3567 if(faceType == (
int)it->first.getNumVertices()) {
3568 faceTags.push_back(it->second);
3569 for(
int j = 0; j < faceType; j++)
3570 faceNodes.push_back(it->first.getVertex(j)->getNum());
3575 GMSH_API void gmsh::model::mesh::addEdges(
const std::vector<std::size_t> &edgeTags,
3576 const std::vector<std::size_t> &edgeNodes)
3579 if(edgeTags.size() * 2 != edgeNodes.size()) {
3584 for(std::size_t i = 0; i < edgeTags.size(); i++) {
3586 for(
int j = 0; j < 2; j++) {
3589 Msg::Error(
"Unknown mesh node %lu", edgeNodes[2 * i + j]);
3593 MEdge e(v[0], v[1]);
3598 GMSH_API void gmsh::model::mesh::addFaces(
const int faceType,
3599 const std::vector<std::size_t> &faceTags,
3600 const std::vector<std::size_t> &faceNodes)
3603 if(faceType != 3 && faceType != 4) {
3604 Msg::Error(
"Unknown face type (should be 3 or 4)");
3607 if(faceTags.size() * faceType != faceNodes.size()) {
3612 for(std::size_t i = 0; i < faceTags.size(); i++) {
3613 MVertex *v[4] = {
nullptr,
nullptr,
nullptr,
nullptr};
3614 for(
int j = 0; j < faceType; j++) {
3617 Msg::Error(
"Unknown mesh node %lu", faceNodes[faceType * i + j]);
3621 MFace f(v[0], v[1], v[2], v[3]);
3626 GMSH_API void gmsh::model::mesh::getKeys(
3627 const int elementType,
const std::string &functionSpaceType,
3628 std::vector<int> &typeKeys, std::vector<std::size_t> &entityKeys,
3629 std::vector<double> &coord,
const int tag,
const bool returnCoord)
3636 int numComponents = 0;
3637 std::string fsName =
"";
3639 Msg::Error(
"Unknown function space type '%s'", functionSpaceType.c_str());
3643 std::map<int, std::vector<GEntity *> > typeEnt;
3645 const std::vector<GEntity *> &entities(typeEnt[elementType]);
3649 if(fsName ==
"H1Legendre" || fsName ==
"GradH1Legendre") {
3650 switch(familyType) {
3673 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
3678 else if(fsName ==
"HcurlLegendre" || fsName ==
"CurlHcurlLegendre") {
3679 switch(familyType) {
3699 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
3704 else if(fsName ==
"IsoParametric" || fsName ==
"Lagrange" ||
3705 fsName ==
"GradIsoParametric" || fsName ==
"GradLagrange") {
3716 for(std::size_t i = 0; i < entities.size(); ++i) {
3718 std::size_t numElementsInEntitie =
3721 coord.reserve(coord.size() + numElementsInEntitie *
3722 nodalB->getNumShapeFunctions() * 3);
3724 typeKeys.reserve(typeKeys.size() +
3725 numElementsInEntitie * nodalB->getNumShapeFunctions());
3726 entityKeys.reserve(entityKeys.size() +
3727 numElementsInEntitie * nodalB->getNumShapeFunctions());
3729 for(std::size_t j = 0; j < numElementsInEntitie; ++j) {
3732 typeKeys.push_back(0);
3745 Msg::Error(
"Unknown function space named '%s'", fsName.c_str());
3749 int vSize = basis->getnVertexFunction();
3750 int bSize = basis->getnBubbleFunction();
3751 int eSize = basis->getnEdgeFunction();
3752 int quadFSize = basis->getnQuadFaceFunction();
3753 int triFSize = basis->getnTriFaceFunction();
3754 int fSize = quadFSize + triFSize;
3755 int numDofsPerElement = vSize + bSize + eSize + fSize;
3756 int numberQuadFaces = basis->getNumQuadFace();
3757 int numberTriFaces = basis->getNumTriFace();
3758 int numTriFaceFunction = 0;
3759 if(basis->getNumTriFace() != 0) {
3760 numTriFaceFunction =
3762 basis->getNumTriFace();
3764 int numQuadFaceFunction = 0;
3765 if(basis->getNumQuadFace() != 0) {
3766 numQuadFaceFunction =
3768 basis->getNumQuadFace();
3770 int numEdgeFunction = 0;
3771 if(basis->getNumEdge() != 0) {
3773 eSize / basis->getNumEdge();
3775 int const1 = numEdgeFunction + 1;
3776 int const2 = const1 + numQuadFaceFunction;
3777 int const3 = const1 + numTriFaceFunction;
3778 int const4 = bSize + std::max(const3, const2);
3781 for(std::size_t i = 0; i < entities.size(); i++) {
3785 coord.reserve(coord.size() +
3786 numElementsInEntitie * numDofsPerElement * 3);
3788 typeKeys.reserve(typeKeys.size() +
3789 numElementsInEntitie * numDofsPerElement);
3790 entityKeys.reserve(entityKeys.size() +
3791 numElementsInEntitie * numDofsPerElement);
3793 for(std::size_t j = 0; j < numElementsInEntitie; j++) {
3796 for(
int k = 0; k < vSize; k++) {
3797 typeKeys.push_back(0);
3809 double coordEdge[3];
3814 coordEdge[0] = 0.5 * (v1->
x() + v2->
x());
3815 coordEdge[1] = 0.5 * (v1->
y() + v2->
y());
3816 coordEdge[2] = 0.5 * (v1->
z() + v2->
z());
3819 for(
int k = 1; k < const1; k++) {
3820 typeKeys.push_back(k);
3821 entityKeys.push_back(edgeGlobalIndice);
3823 coord.push_back(coordEdge[0]);
3824 coord.push_back(coordEdge[1]);
3825 coord.push_back(coordEdge[2]);
3832 for(
int jj = 0; jj < numberQuadFaces + numberTriFaces; jj++) {
3835 double coordFace[3] = {0., 0., 0.};
3849 if(jj >= numberQuadFaces) { it2 = const3; }
3850 for(
int k = const1; k < it2; k++) {
3851 typeKeys.push_back(k);
3852 entityKeys.push_back(faceGlobalIndice);
3854 coord.push_back(coordFace[0]);
3855 coord.push_back(coordFace[1]);
3856 coord.push_back(coordFace[2]);
3863 double bubbleCenterCoord[3] = {0., 0., 0.};
3865 for(
unsigned int indexV = 0; indexV < e->
getNumVertices(); ++indexV) {
3866 bubbleCenterCoord[0] += e->
getVertex(indexV)->
x();
3867 bubbleCenterCoord[1] += e->
getVertex(indexV)->
y();
3868 bubbleCenterCoord[2] += e->
getVertex(indexV)->
z();
3874 for(
int k = std::max(const3, const2); k < const4; k++) {
3875 typeKeys.push_back(k);
3876 entityKeys.push_back(e->
getNum());
3878 coord.push_back(bubbleCenterCoord[0]);
3879 coord.push_back(bubbleCenterCoord[1]);
3880 coord.push_back(bubbleCenterCoord[2]);
3888 GMSH_API void gmsh::model::mesh::getKeysForElement(
3889 const std::size_t elementTag,
const std::string &functionSpaceType,
3890 std::vector<int> &typeKeys, std::vector<std::size_t> &entityKeys,
3891 std::vector<double> &coord,
const bool returnCoord)
3898 int numComponents = 0;
3899 std::string fsName =
"";
3901 Msg::Error(
"Unknown function space type '%s'", functionSpaceType.c_str());
3909 if(fsName ==
"H1Legendre" || fsName ==
"GradH1Legendre") {
3910 switch(familyType) {
3933 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
3938 else if(fsName ==
"HcurlLegendre" || fsName ==
"CurlHcurlLegendre") {
3939 switch(familyType) {
3959 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
3964 else if(fsName ==
"IsoParametric" || fsName ==
"Lagrange" ||
3965 fsName ==
"GradIsoParametric" || fsName ==
"GradLagrange") {
3970 typeKeys.push_back(0);
3981 Msg::Error(
"Unknown function space named '%s'", fsName.c_str());
3985 int vSize = basis->getnVertexFunction();
3986 int bSize = basis->getnBubbleFunction();
3987 int eSize = basis->getnEdgeFunction();
3988 int quadFSize = basis->getnQuadFaceFunction();
3989 int triFSize = basis->getnTriFaceFunction();
3990 int fSize = quadFSize + triFSize;
3991 int numberQuadFaces = basis->getNumQuadFace();
3992 int numberTriFaces = basis->getNumTriFace();
3993 int numTriFaceFunction = 0;
3994 if(basis->getNumTriFace() != 0) {
3995 numTriFaceFunction =
3997 basis->getNumTriFace();
3999 int numQuadFaceFunction = 0;
4000 if(basis->getNumQuadFace() != 0) {
4001 numQuadFaceFunction =
4003 basis->getNumQuadFace();
4005 int numEdgeFunction = 0;
4006 if(basis->getNumEdge() != 0) {
4008 eSize / basis->getNumEdge();
4010 int const1 = numEdgeFunction + 1;
4011 int const2 = const1 + numQuadFaceFunction;
4012 int const3 = const1 + numTriFaceFunction;
4013 int const4 = bSize + std::max(const3, const2);
4014 int numDofsPerElement = vSize + bSize + eSize + fSize;
4017 typeKeys.reserve(numDofsPerElement);
4018 entityKeys.reserve(numDofsPerElement);
4019 if(returnCoord) { coord.reserve(3 * numDofsPerElement); }
4022 for(
int k = 0; k < vSize; k++) {
4023 typeKeys.push_back(0);
4035 double coordEdge[3];
4040 coordEdge[0] = 0.5 * (v1->
x() + v2->
x());
4041 coordEdge[1] = 0.5 * (v1->
y() + v2->
y());
4042 coordEdge[2] = 0.5 * (v1->
z() + v2->
z());
4045 for(
int k = 1; k < const1; k++) {
4046 typeKeys.push_back(k);
4047 entityKeys.push_back(edgeGlobalIndice);
4049 coord.push_back(coordEdge[0]);
4050 coord.push_back(coordEdge[1]);
4051 coord.push_back(coordEdge[2]);
4058 for(
int jj = 0; jj < numberQuadFaces + numberTriFaces; jj++) {
4061 double coordFace[3] = {0., 0., 0.};
4063 for(std::size_t indexV = 0; indexV < face.
getNumVertices(); ++indexV) {
4074 if(jj >= numberQuadFaces) { it2 = const3; }
4075 for(
int k = const1; k < it2; k++) {
4076 typeKeys.push_back(k);
4077 entityKeys.push_back(faceGlobalIndice);
4079 coord.push_back(coordFace[0]);
4080 coord.push_back(coordFace[1]);
4081 coord.push_back(coordFace[2]);
4088 double bubbleCenterCoord[3] = {0., 0., 0.};
4090 for(
unsigned int indexV = 0; indexV < e->
getNumVertices(); ++indexV) {
4091 bubbleCenterCoord[0] += e->
getVertex(indexV)->
x();
4092 bubbleCenterCoord[1] += e->
getVertex(indexV)->
y();
4093 bubbleCenterCoord[2] += e->
getVertex(indexV)->
z();
4099 for(
int k = std::max(const3, const2); k < const4; k++) {
4100 typeKeys.push_back(k);
4101 entityKeys.push_back(e->
getNum());
4103 coord.push_back(bubbleCenterCoord[0]);
4104 coord.push_back(bubbleCenterCoord[1]);
4105 coord.push_back(bubbleCenterCoord[2]);
4111 GMSH_API int gmsh::model::mesh::getNumberOfKeys(
4112 const int elementType,
const std::string &functionSpaceType)
4114 int numberOfKeys = 0;
4116 std::string fsName =
"";
4117 int numComponents = 0;
4120 Msg::Error(
"Unknown function space type '%s'", functionSpaceType.c_str());
4124 if(fsName ==
"H1Legendre" || fsName ==
"GradH1Legendre") {
4126 switch(familyType) {
4149 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
4153 int vSize = basis->getnVertexFunction();
4154 int bSize = basis->getnBubbleFunction();
4155 int eSize = basis->getnEdgeFunction();
4156 int quadFSize = basis->getnQuadFaceFunction();
4157 int triFSize = basis->getnTriFaceFunction();
4158 numberOfKeys = vSize + bSize + eSize + quadFSize + triFSize;
4161 else if(fsName ==
"HcurlLegendre" || fsName ==
"CurlHcurlLegendre") {
4163 switch(familyType) {
4183 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
4187 int vSize = basis->getnVertexFunction();
4188 int bSize = basis->getnBubbleFunction();
4189 int eSize = basis->getnEdgeFunction();
4190 int quadFSize = basis->getnQuadFaceFunction();
4191 int triFSize = basis->getnTriFaceFunction();
4192 numberOfKeys = vSize + bSize + eSize + quadFSize + triFSize;
4195 else if(fsName ==
"IsoParametric" || fsName ==
"Lagrange" ||
4196 fsName ==
"GradIsoParametric" || fsName ==
"GradLagrange") {
4198 if(basisOrder == -1) {
4209 Msg::Error(
"Unknown function space named '%s'", fsName.c_str());
4213 return numberOfKeys;
4216 GMSH_API void gmsh::model::mesh::getKeysInformation(
4217 const std::vector<int> &typeKeys,
const std::vector<std::size_t> &entityKeys,
4218 const int elementType,
const std::string &functionSpaceType,
4219 gmsh::vectorpair &infoKeys)
4223 std::string fsName =
"";
4224 int numComponents = 0;
4227 Msg::Error(
"Unknown function space type '%s'", functionSpaceType.c_str());
4231 if(typeKeys.size() != entityKeys.size()) {
4232 Msg::Error(
"The size of 'typeKeys' is different of the size of "
4233 "'entityKeys' ('%i', '%i')",
4234 typeKeys.size(), entityKeys.size());
4240 if(fsName ==
"H1Legendre" || fsName ==
"GradH1Legendre") {
4241 switch(familyType) {
4264 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
4269 else if(fsName ==
"HcurlLegendre" || fsName ==
"CurlHcurlLegendre") {
4270 switch(familyType) {
4290 Msg::Error(
"Unknown familyType %i for basis function type %s", familyType,
4295 else if(fsName ==
"IsoParametric" || fsName ==
"Lagrange" ||
4296 fsName ==
"GradIsoParametric" || fsName ==
"GradLagrange") {
4298 if(basisOrder == -1) {
4310 if(numberOfBubble > numberOfKeys) {
4311 Msg::Error(
"Number of bubble functions greater than number of keys");
4315 infoKeys.reserve(typeKeys.size());
4316 for(
size_t i = 0; i < typeKeys.size() / numberOfKeys; ++i) {
4317 for(
size_t j = 0; j < numberOfKeys - numberOfBubble; ++j) {
4318 infoKeys.push_back(std::make_pair(0, basisOrder));
4320 for(
size_t j = 0; j < numberOfBubble; ++j) {
4321 infoKeys.push_back(std::make_pair(dim, basisOrder));
4327 Msg::Error(
"Unknown function space named '%s'", fsName.c_str());
4331 int vSize = basis->getnVertexFunction();
4332 int bSize = basis->getnBubbleFunction();
4333 int eSize = basis->getnEdgeFunction();
4334 int quadFSize = basis->getnQuadFaceFunction();
4335 int triFSize = basis->getnTriFaceFunction();
4336 int numDofsPerElement = vSize + bSize + eSize + quadFSize + triFSize;
4337 std::vector<int> functionTypeInfo(numDofsPerElement);
4338 std::vector<int> orderInfo(numDofsPerElement);
4339 basis->getKeysInfo(functionTypeInfo, orderInfo);
4341 std::size_t keySize = typeKeys.size();
4342 if(!keySize)
return;
4343 infoKeys.resize(keySize);
4344 std::size_t it = keySize / numDofsPerElement;
4345 for(std::size_t i = 0; i < it; i++) {
4346 size_t const1 = i * numDofsPerElement;
4347 for(
int j = 0; j < numDofsPerElement; j++) {
4348 infoKeys[const1 + j] =
4349 std::make_pair(functionTypeInfo[j], orderInfo[j]);
4354 GMSH_API void gmsh::model::mesh::getBarycenters(
4355 const int elementType,
const int tag,
const bool fast,
const bool primary,
4356 std::vector<double> &barycenters,
const std::size_t task,
4357 const std::size_t numTasks)
4361 std::map<int, std::vector<GEntity *> > typeEnt;
4363 const std::vector<GEntity *> &entities(typeEnt[elementType]);
4365 std::size_t numElements = 0;
4366 for(std::size_t i = 0; i < entities.size(); i++) {
4374 if(!numElements)
return;
4376 if(3 * numElements != barycenters.size()) {
4378 Msg::Warning(
"Barycenters should be preallocated if numTasks > 1");
4379 barycenters.resize(3 * numElements);
4382 const size_t begin = (task * numElements) / numTasks;
4383 const size_t end = ((task + 1) * numElements) / numTasks;
4385 size_t idx = 3 * begin;
4387 for(std::size_t i = 0; i < entities.size(); i++) {
4391 if(o >= begin && o < end) {
4394 barycenters[idx++] = p[0];
4395 barycenters[idx++] = p[1];
4396 barycenters[idx++] = p[2];
4403 for(std::size_t i = 0; i < entities.size(); i++) {
4407 if(o >= begin && o < end) {
4410 barycenters[idx++] = p[0];
4411 barycenters[idx++] = p[1];
4412 barycenters[idx++] = p[2];
4421 std::string &intName,
int &intOrder)
4423 if(intType.substr(0, 14) ==
"CompositeGauss") {
4424 intName =
"CompositeGauss";
4425 intOrder = atoi(intType.substr(14).c_str());
4428 else if(intType.substr(0, 5) ==
"Gauss") {
4430 intOrder = atoi(intType.substr(5).c_str());
4436 GMSH_API void gmsh::model::mesh::getIntegrationPoints(
4437 const int elementType,
const std::string &integrationType,
4438 std::vector<double> &localCoord, std::vector<double> &weights)
4443 std::string intName =
"";
4446 Msg::Error(
"Unknown quadrature type '%s'", integrationType.c_str());
4454 intName ==
"Gauss" ?
false :
true);
4456 Msg::Error(
"Wrong integration point format");
4459 localCoord.resize(3 * pts.
size1());
4460 weights.resize(pts.
size1());
4461 for(
int i = 0; i < pts.
size1(); i++) {
4462 localCoord[3 * i] = pts(i, 0);
4463 localCoord[3 * i + 1] = pts(i, 1);
4464 localCoord[3 * i + 2] = pts(i, 2);
4465 weights[i] = wgs(i);
4469 GMSH_API void gmsh::model::mesh::preallocateBarycenters(
4470 const int elementType, std::vector<double> &barycenters,
const int tag)
4474 std::map<int, std::vector<GEntity *> > typeEnt;
4476 const std::vector<GEntity *> &entities(typeEnt[elementType]);
4478 std::size_t numElements = 0;
4479 for(std::size_t i = 0; i < entities.size(); i++)
4480 numElements += entities[i]->getNumMeshElementsByType(familyType);
4481 barycenters.clear();
4482 if(!numElements)
return;
4483 barycenters.resize(3 * numElements, 0);
4486 GMSH_API void gmsh::model::mesh::getElementEdgeNodes(
4487 const int elementType, std::vector<std::size_t> &nodeTags,
const int tag,
4488 const bool primary,
const std::size_t task,
const std::size_t numTasks)
4492 std::map<int, std::vector<GEntity *> > typeEnt;
4494 const std::vector<GEntity *> &entities(typeEnt[elementType]);
4496 std::size_t numElements = 0;
4497 int numEdgesPerEle = 0, numNodesPerEdge = 0;
4498 for(std::size_t i = 0; i < entities.size(); i++) {
4501 if(n && !numNodesPerEdge) {
4504 if(primary) { numNodesPerEdge = 2; }
4506 std::vector<MVertex *> v;
4510 numNodesPerEdge = v.size();
4519 if(!numElements || !numEdgesPerEle || !numNodesPerEdge)
return;
4520 if(numEdgesPerEle * numNodesPerEdge * numElements != nodeTags.size()) {
4522 Msg::Warning(
"Nodes should be preallocated if numTasks > 1");
4523 nodeTags.resize(numEdgesPerEle * numNodesPerEdge * numElements);
4525 const size_t begin = (task * numElements) / numTasks;
4526 const size_t end = ((task + 1) * numElements) / numTasks;
4528 size_t idx = numEdgesPerEle * numNodesPerEdge * begin;
4529 for(std::size_t i = 0; i < entities.size(); i++) {
4532 if(o >= begin && o < end) {
4534 for(
int k = 0; k < numEdgesPerEle; k++) {
4535 std::vector<MVertex *> v;
4539 std::size_t N = primary ? 2 : v.size();
4540 for(std::size_t l = 0; l < N; l++) {
4541 nodeTags[idx++] = v[l]->getNum();
4550 GMSH_API void gmsh::model::mesh::getElementFaceNodes(
4551 const int elementType,
const int faceType, std::vector<std::size_t> &nodeTags,
4552 const int tag,
const bool primary,
const std::size_t task,
4553 const std::size_t numTasks)
4557 std::map<int, std::vector<GEntity *> > typeEnt;
4559 const std::vector<GEntity *> &entities(typeEnt[elementType]);
4561 std::size_t numElements = 0;
4562 int numFacesPerEle = 0, numNodesPerFace = 0;
4563 for(std::size_t i = 0; i < entities.size(); i++) {
4566 if(n && !numNodesPerFace) {
4570 for(
int k = 0; k < nf; k++) {
4572 if(faceType == (
int)
f.getNumVertices()) {
4574 if(!numNodesPerFace) {
4575 if(primary) { numNodesPerFace = faceType; }
4577 std::vector<MVertex *> v;
4581 numNodesPerFace = v.size();
4594 if(!numElements || !numFacesPerEle || !numNodesPerFace)
return;
4595 if(numFacesPerEle * numNodesPerFace * numElements > nodeTags.size()) {
4597 Msg::Warning(
"Nodes should be preallocated if numTasks > 1");
4598 nodeTags.resize(numFacesPerEle * numNodesPerFace * numElements);
4600 const size_t begin = (task * numElements) / numTasks;
4601 const size_t end = ((task + 1) * numElements) / numTasks;
4603 size_t idx = numFacesPerEle * numNodesPerFace * begin;
4604 for(std::size_t i = 0; i < entities.size(); i++) {
4607 if(o >= begin && o < end) {
4610 for(
int k = 0; k < nf; k++) {
4612 if(faceType != (
int)
f.getNumVertices())
continue;
4613 std::vector<MVertex *> v;
4617 std::size_t N = primary ? faceType : v.size();
4618 for(std::size_t l = 0; l < N; l++) {
4619 nodeTags[idx++] = v[l]->getNum();
4629 gmsh::model::mesh::getGhostElements(
const int dim,
const int tag,
4630 std::vector<std::size_t> &elementTags,
4631 std::vector<int> &partitions)
4634 elementTags.clear();
4641 std::map<MElement *, int> ghostCells;
4643 ghostCells =
static_cast<ghostEdge *
>(ge)->getGhostCells();
4649 for(
auto it = ghostCells.begin(); it != ghostCells.end(); it++) {
4650 elementTags.push_back(it->first->getNum());
4651 partitions.push_back(it->second);
4655 GMSH_API void gmsh::model::mesh::setSize(
const vectorpair &dimTags,
4659 for(std::size_t i = 0; i < dimTags.size(); i++) {
4660 int dim = dimTags[i].first, tag = dimTags[i].second;
4668 GMSH_API void gmsh::model::mesh::getSizes(
const vectorpair &dimTags,
4669 std::vector<double> &sizes)
4673 if(dimTags.empty())
return;
4674 sizes.resize(dimTags.size(), 0.);
4675 for(std::size_t i = 0; i < dimTags.size(); i++) {
4676 int dim = dimTags[i].first, tag = dimTags[i].second;
4681 if(s !=
MAX_LC) sizes[i] = s;
4687 GMSH_API void gmsh::model::mesh::setSizeAtParametricPoints(
4688 const int dim,
const int tag,
const std::vector<double> ¶metricCoord,
4689 const std::vector<double> &sizes)
4698 GMSH_API void gmsh::model::mesh::setSizeCallback(
4699 std::function<
double(
int,
int,
double,
double,
double,
double)> callback)
4705 GMSH_API void gmsh::model::mesh::removeSizeCallback()
4712 gmsh::model::mesh::setTransfiniteCurve(
const int tag,
const int numNodes,
4713 const std::string &meshType,
4718 for(
int sig = -1; sig <= 1; sig += 2) {
4725 (meshType ==
"Progression" || meshType ==
"Power") ? 1 :
4726 (meshType ==
"Bump") ? 2 :
4727 (meshType ==
"Beta") ? 3 :
4743 gmsh::model::mesh::setTransfiniteSurface(
const int tag,
4744 const std::string &arrangement,
4745 const std::vector<int> &cornerTags)
4755 (arrangement ==
"Right") ? 1 :
4756 (arrangement ==
"Left") ? -1 :
4757 (arrangement ==
"AlternateRight") ? 2 :
4758 (arrangement ==
"AlternateLeft") ? -2 :
4759 (arrangement ==
"Alternate") ? 2 :
4761 if(cornerTags.empty() || cornerTags.size() == 3 || cornerTags.size() == 4) {
4762 for(std::size_t j = 0; j < cornerTags.size(); j++) {
4770 gmsh::model::mesh::setTransfiniteVolume(
const int tag,
4771 const std::vector<int> &cornerTags)
4780 if(cornerTags.empty() || cornerTags.size() == 6 || cornerTags.size() == 8) {
4781 for(std::size_t i = 0; i < cornerTags.size(); i++) {
4790 std::set<GVertex *> vertices;
4791 std::set<GEdge *>
edges;
4792 for(std::size_t _i = 0; _i < gr->
faces().size(); ++_i) {
4794 for(std::size_t j = 0; j < gf->
edges().size(); ++j) {
4801 int X = int(vertices.size()) - int(
edges.size()) + int(gr->
faces().size());
4805 GMSH_API void gmsh::model::mesh::setTransfiniteAutomatic(
4806 const vectorpair &dimTags,
const double cornerAngle,
const bool recombine)
4808 #if defined(HAVE_MESH)
4810 Msg::Debug(
"setTransfiniteAutomatic() with cornerAngle=%.3f, recombine=%i",
4811 cornerAngle,
int(recombine));
4814 std::set<GFace *>
faces;
4815 if(dimTags.size() == 0) {
4816 std::vector<GEntity *> entities;
4818 for(std::size_t i = 0; i < entities.size(); i++) {
4819 GFace *gf =
static_cast<GFace *
>(entities[i]);
4820 if(gf->
edges().size() == 4) {
faces.insert(gf); }
4824 for(std::size_t i = 0; i < dimTags.size(); ++i) {
4825 if(dimTags[i].first == 2) {
4826 int tag = dimTags[i].second;
4832 if(gf->
edges().size() == 4) {
faces.insert(gf); }
4834 else if(dimTags[i].first == 3) {
4835 int tag = dimTags[i].second;
4842 if(gf->
edges().size() == 4) {
faces.insert(gf); }
4852 Msg::Error(
"failed to automatically set transfinite faces");
4857 std::set<GRegion *> regions;
4858 if(dimTags.size() == 0) {
4859 std::vector<GEntity *> entities;
4861 for(std::size_t i = 0; i < entities.size(); i++) {
4869 for(std::size_t i = 0; i < dimTags.size(); ++i) {
4870 if(dimTags[i].first == 3) {
4871 int tag = dimTags[i].second;
4886 bool transfinite =
true;
4889 transfinite =
false;
4899 Msg::Debug(
"transfinite automatic: transfinite set on %li volumes", nr);
4901 Msg::Error(
"setTransfiniteAutomatic requires the mesh module");
4905 GMSH_API void gmsh::model::mesh::setRecombine(
const int dim,
const int tag,
4920 GMSH_API void gmsh::model::mesh::setSmoothing(
const int dim,
const int tag,
4934 GMSH_API void gmsh::model::mesh::setReverse(
const int dim,
const int tag,
4956 GMSH_API void gmsh::model::mesh::setAlgorithm(
const int dim,
const int tag,
4970 GMSH_API void gmsh::model::mesh::setSizeFromBoundary(
const int dim,
4985 GMSH_API void gmsh::model::mesh::setCompound(
const int dim,
4986 const std::vector<int> &
tags)
4989 std::vector<GEntity *> ents;
4990 for(std::size_t i = 0; i <
tags.size(); i++) {
4992 if(ent) { ents.push_back(ent); }
4997 for(std::size_t i = 0; i < ents.size(); i++) { ents[i]->compound = ents; }
5000 GMSH_API void gmsh::model::mesh::setOutwardOrientation(
const int tag)
5011 GMSH_API void gmsh::model::mesh::removeConstraints(
const vectorpair &dimTags)
5014 std::vector<GEntity *> entities;
5016 for(std::size_t i = 0; i < entities.size(); i++)
5017 entities[i]->resetMeshAttributes();
5020 GMSH_API void gmsh::model::mesh::embed(
const int dim,
5021 const std::vector<int> &
tags,
5022 const int inDim,
const int inTag)
5031 for(std::size_t i = 0; i <
tags.size(); i++) {
5050 else if(inDim == 3) {
5056 for(std::size_t i = 0; i <
tags.size(); i++) {
5089 for(std::size_t i = 0; i < dimTags.size(); i++) {
5090 int dim = dimTags[i].first, tag = dimTags[i].second;
5100 else if(dimTags[i].first == 3) {
5113 GMSH_API void gmsh::model::mesh::getEmbedded(
const int dim,
const int tag,
5114 vectorpair &dimTags)
5125 dimTags.push_back(std::make_pair(v->dim(), v->tag()));
5127 dimTags.push_back(std::make_pair(e->dim(), e->tag()));
5136 dimTags.push_back(std::make_pair(v->dim(), v->tag()));
5138 dimTags.push_back(std::make_pair(e->dim(), e->tag()));
5140 dimTags.push_back(std::make_pair(
f->dim(),
f->tag()));
5145 gmsh::model::mesh::reorderElements(
const int elementType,
const int tag,
5146 const std::vector<std::size_t> &ordering)
5150 std::map<int, std::vector<GEntity *> > typeEnt;
5152 const std::vector<GEntity *> &entities(typeEnt[elementType]);
5153 if(entities.empty()) {
5157 for(std::size_t i = 0; i < entities.size(); i++) {
5158 if(!entities[i]->reorder(elementType, ordering)) {
5165 GMSH_API void gmsh::model::mesh::renumberNodes()
5171 GMSH_API void gmsh::model::mesh::renumberElements()
5178 gmsh::model::mesh::setPeriodic(
const int dim,
const std::vector<int> &
tags,
5179 const std::vector<int> &tagsMaster,
5180 const std::vector<double> &affineTransform)
5183 if(
tags.size() != tagsMaster.size()) {
5184 Msg::Error(
"Incompatible number of tags and master tags for periodic mesh");
5187 if(affineTransform.size() != 16) {
5188 Msg::Error(
"Wrong number of elements in affine transformation (%d != 16)",
5189 (
int)affineTransform.size());
5192 for(std::size_t i = 0; i <
tags.size(); i++) {
5225 gmsh::model::mesh::getPeriodic(
const int dim,
const std::vector<int> &
tags,
5226 std::vector<int> &tagsMaster)
5230 tagsMaster.reserve(
tags.size());
5231 for(
auto i :
tags) {
5241 GMSH_API void gmsh::model::mesh::getPeriodicNodes(
5242 const int dim,
const int tag,
int &tagMaster,
5243 std::vector<std::size_t> &nodeTags, std::vector<std::size_t> &nodeTagsMaster,
5244 std::vector<double> &affineTransform,
const bool includeHighOrderNodes)
5256 nodeTags.push_back(it->first->getNum());
5257 nodeTagsMaster.push_back(it->second->getNum());
5259 if(includeHighOrderNodes) {
5262 nodeTags.push_back(it->first->getNum());
5263 nodeTagsMaster.push_back(it->second->getNum());
5271 nodeTagsMaster.clear();
5272 affineTransform.clear();
5276 GMSH_API void gmsh::model::mesh::getPeriodicKeys(
5277 const int elementType,
const std::string &functionSpaceType,
5278 const int tag,
int &tagMaster,
5279 std::vector<int> &typeKeys, std::vector<int> &typeKeysMaster,
5280 std::vector<std::size_t> &entityKeys, std::vector<std::size_t> &entityKeysMaster,
5281 std::vector<double> &coord, std::vector<double> &coordMaster,
5282 const bool returnCoord)
5294 typeKeysMaster.clear();
5296 entityKeysMaster.clear();
5301 getKeys(elementType, functionSpaceType,
5302 typeKeys, entityKeys, coord, tag, returnCoord);
5303 typeKeysMaster = typeKeys;
5304 entityKeysMaster = entityKeys;
5305 coordMaster = coord;
5310 if(functionSpaceType ==
"IsoParametric" ||
5311 functionSpaceType ==
"Lagrange") {
5312 #pragma omp parallel for num_threads(nthreads)
5313 for(std::size_t i = 0; i < entityKeys.size(); i++) {
5314 MVertex v(0., 0., 0.,
nullptr, entityKeys[i]);
5317 entityKeysMaster[i] = mv->second->getNum();
5319 coord[3 * i] = mv->second->x();
5320 coord[3 * i + 1] = mv->second->y();
5321 coord[3 * i + 2] = mv->second->z();
5327 entityKeysMaster[i] = mv2->second->getNum();
5329 coord[3 * i] = mv2->second->x();
5330 coord[3 * i + 1] = mv2->second->y();
5331 coord[3 * i + 2] = mv2->second->z();
5335 Msg::Warning(
"Unknown master node corresponding to node %d",
5342 Msg::Error(
"Periodic key generation currently only available for "
5343 "\"IsoParametric\" and \"Lagrange\" function spaces");
5347 GMSH_API void gmsh::model::mesh::getDuplicateNodes(std::vector<std::size_t> &nodeTags,
5348 const vectorpair &dimTags)
5353 double lc = bbox.
empty() ? 1. : bbox.
diag();
5355 std::vector<GEntity *> entities;
5357 std::vector<MVertex *> vertices;
5358 for(std::size_t i = 0; i < entities.size(); i++) {
5359 vertices.insert(vertices.end(), entities[i]->mesh_vertices.begin(),
5360 entities[i]->mesh_vertices.end());
5363 std::set<MVertex *, MVertexPtrLessThan> duplicates;
5364 pos.insert(vertices,
true, &duplicates);
5365 for(
auto n : duplicates) nodeTags.push_back(n->getNum());
5368 GMSH_API void gmsh::model::mesh::removeDuplicateNodes(
const vectorpair &dimTags)
5371 std::vector<GEntity *> entities;
5378 GMSH_API void gmsh::model::mesh::removeDuplicateElements(
const vectorpair &dimTags)
5381 std::vector<GEntity *> entities;
5388 const std::vector<size_t> &elementTags,
const int value)
5391 for(
auto t : elementTags) {
5397 GMSH_API void gmsh::model::mesh::importStl()
5403 (*it)->buildSTLTriangulation();
5404 (*it)->storeSTLAsMesh();
5407 (*it)->storeSTLAsMesh();
5411 GMSH_API void gmsh::model::mesh::classifySurfaces(
5412 const double angle,
const bool boundary,
const bool forReparametrization,
5413 const double curveAngle,
const bool exportDiscrete)
5418 if(exportDiscrete) {
5424 GMSH_API void gmsh::model::mesh::createGeometry(
const vectorpair &dimTags)
5431 const bool exportDiscrete)
5440 if(exportDiscrete) {
5447 gmsh::model::mesh::addHomologyRequest(
const std::string &type,
5448 const std::vector<int> &domainTags,
5449 const std::vector<int> &subdomainTags,
5450 const std::vector<int> &dims)
5458 gmsh::model::mesh::clearHomologyRequests()
5465 gmsh::model::mesh::computeHomology(vectorpair &dimTags)
5471 GMSH_API void gmsh::model::mesh::triangulate(
const std::vector<double> &coord,
5472 std::vector<std::size_t> &tri)
5476 if(coord.size() % 2) {
5477 Msg::Error(
"Number of 2D coordinates should be even");
5480 #if defined(HAVE_MESH)
5482 for(std::size_t i = 0; i < coord.size(); i += 2)
5483 bbox +=
SPoint3(coord[i], coord[i + 1], 0.);
5485 std::vector<MVertex *> verts(coord.size() / 2);
5487 for(std::size_t i = 0; i < coord.size(); i += 2) {
5488 double XX = 1.e-12 * lc * (double)rand() / (double)RAND_MAX;
5489 double YY = 1.e-12 * lc * (double)rand() / (double)RAND_MAX;
5494 std::vector<MTriangle *> tris;
5496 if(tris.empty())
return;
5497 tri.resize(3 * tris.size());
5498 for(std::size_t i = 0; i < tris.size(); i++) {
5500 for(std::size_t j = 0; j < 3; j++)
5503 for(std::size_t i = 0; i < verts.size(); i++)
delete verts[i];
5504 for(std::size_t i = 0; i < tris.size(); i++)
delete tris[i];
5506 Msg::Error(
"triangulate requires the mesh module");
5511 gmsh::model::mesh::tetrahedralize(
const std::vector<double> &coord,
5512 std::vector<std::size_t> &tetra)
5516 if(coord.size() % 3) {
5517 Msg::Error(
"Number of coordinates should be a multiple of 3");
5520 #if defined(HAVE_MESH)
5521 std::vector<MVertex *> verts(coord.size() / 3);
5523 for(std::size_t i = 0; i < coord.size(); i += 3) {
5528 std::vector<MTetrahedron *> tets;
5533 if(tets.empty())
return;
5534 tetra.resize(4 * tets.size());
5535 for(std::size_t i = 0; i < tets.size(); i++) {
5537 for(std::size_t j = 0; j < 4; j++)
5540 for(std::size_t i = 0; i < verts.size(); i++)
delete verts[i];
5541 for(std::size_t i = 0; i < tets.size(); i++)
delete tets[i];
5543 Msg::Error(
"tetrahedralize requires the mesh module");
5549 GMSH_API int gmsh::model::mesh::field::add(
const std::string &fieldType,
5554 #if defined(HAVE_MESH)
5557 Msg::Error(
"Cannot add Field %i of type '%s'", outTag, fieldType.c_str());
5560 #if defined(HAVE_FLTK)
5561 if(FlGui::available()) FlGui::instance()->updateFields();
5564 Msg::Error(
"Fields require the mesh module");
5569 GMSH_API void gmsh::model::mesh::field::remove(
const int tag)
5572 #if defined(HAVE_MESH)
5574 #if defined(HAVE_FLTK)
5575 if(FlGui::available()) FlGui::instance()->updateFields();
5578 Msg::Error(
"Fields require the mesh module");
5582 GMSH_API void gmsh::model::mesh::field::list(std::vector<int> &
tags)
5586 #if defined(HAVE_MESH)
5588 for(
auto it = fields.begin(); it != fields.end(); it++) {
5589 tags.push_back(it->first);
5592 Msg::Error(
"Fields require the mesh module");
5597 std::string &fieldType)
5600 #if defined(HAVE_MESH)
5608 Msg::Error(
"Fields require the mesh module");
5612 #if defined(HAVE_MESH)
5613 static FieldOption *_getFieldOption(
const int tag,
const std::string &option)
5622 Msg::Error(
"Unknown option '%s' in field %i of type '%s'", option.c_str(),
5630 GMSH_API void gmsh::model::mesh::field::setNumber(
const int tag,
5631 const std::string &option,
5635 #if defined(HAVE_MESH)
5641 Msg::Warning(
"Field option '%s' is not a number", option.c_str());
5645 Msg::Error(
"Fields require the mesh module");
5649 GMSH_API void gmsh::model::mesh::field::getNumber(
const int tag,
5650 const std::string &option,
5654 #if defined(HAVE_MESH)
5660 Msg::Warning(
"Field option '%s' is not a number", option.c_str());
5664 Msg::Error(
"Fields require the mesh module");
5668 GMSH_API void gmsh::model::mesh::field::setString(
const int tag,
5669 const std::string &option,
5670 const std::string &value)
5673 #if defined(HAVE_MESH)
5678 Msg::Warning(
"Field option '%s' is not a string", option.c_str());
5682 Msg::Error(
"Fields require the mesh module");
5686 GMSH_API void gmsh::model::mesh::field::getString(
const int tag,
5687 const std::string &option,
5691 #if defined(HAVE_MESH)
5696 Msg::Warning(
"Field option '%s' is not a string", option.c_str());
5700 Msg::Error(
"Fields require the mesh module");
5705 gmsh::model::mesh::field::setNumbers(
const int tag,
const std::string &option,
5706 const std::vector<double> &values)
5709 #if defined(HAVE_MESH)
5714 for(std::size_t i = 0; i < values.size(); i++) vl.push_back((
int)values[i]);
5719 Msg::Warning(
"Field option '%s' is not a list", option.c_str());
5721 std::list<double> vl;
5722 for(std::size_t i = 0; i < values.size(); i++) vl.push_back(values[i]);
5726 Msg::Error(
"Fields require the mesh module");
5731 gmsh::model::mesh::field::getNumbers(
const int tag,
const std::string &option,
5732 std::vector<double> &values)
5736 #if defined(HAVE_MESH)
5740 std::list<int> vl = o->
list();
5741 for(
auto i : vl) values.push_back(i);
5745 Msg::Warning(
"Field option '%s' is not a list", option.c_str());
5748 for(
auto d : vl) values.push_back(d);
5751 Msg::Error(
"Fields require the mesh module");
5755 GMSH_API void gmsh::model::mesh::field::setAsBackgroundMesh(
const int tag)
5758 #if defined(HAVE_MESH)
5761 Msg::Error(
"Fields require the mesh module");
5765 GMSH_API void gmsh::model::mesh::field::setAsBoundaryLayer(
const int tag)
5768 #if defined(HAVE_MESH)
5771 Msg::Error(
"Fields require the mesh module");
5777 GMSH_API int gmsh::model::geo::addPoint(
const double x,
const double y,
5778 const double z,
const double meshSize,
5791 GMSH_API int gmsh::model::geo::addLine(
const int startTag,
const int endTag,
5800 GMSH_API int gmsh::model::geo::addCircleArc(
const int startTag,
5801 const int centerTag,
5802 const int endTag,
const int tag,
5803 const double nx,
const double ny,
5809 outTag, startTag, centerTag, endTag, nx, ny, nz);
5813 GMSH_API int gmsh::model::geo::addEllipseArc(
5814 const int startTag,
const int centerTag,
const int majorTag,
const int endTag,
5815 const int tag,
const double nx,
const double ny,
const double nz)
5820 outTag, startTag, centerTag, majorTag, endTag, nx, ny, nz);
5824 GMSH_API int gmsh::model::geo::addSpline(
const std::vector<int> &pointTags,
5833 GMSH_API int gmsh::model::geo::addBSpline(
const std::vector<int> &pointTags,
5842 GMSH_API int gmsh::model::geo::addBezier(
const std::vector<int> &pointTags,
5851 GMSH_API int gmsh::model::geo::addPolyline(
const std::vector<int> &pointTags,
5861 gmsh::model::geo::addCompoundSpline(
const std::vector<int> &curveTags,
5862 const int numIntervals,
const int tag)
5872 gmsh::model::geo::addCompoundBSpline(
const std::vector<int> &curveTags,
5873 const int numIntervals,
const int tag)
5882 GMSH_API int gmsh::model::geo::addCurveLoop(
const std::vector<int> &curveTags,
5883 const int tag,
const bool reorient)
5892 GMSH_API void gmsh::model::geo::addCurveLoops(
const std::vector<int> &curveTags,
5893 std::vector<int> &
tags)
5899 GMSH_API int gmsh::model::geo::addPlaneSurface(
const std::vector<int> &wireTags,
5909 gmsh::model::geo::addSurfaceFilling(
const std::vector<int> &wireTags,
5910 const int tag,
const int sphereCenterTag)
5920 gmsh::model::geo::addSurfaceLoop(
const std::vector<int> &surfaceTags,
5929 GMSH_API int gmsh::model::geo::addVolume(
const std::vector<int> &shellTags,
5938 GMSH_API int gmsh::model::geo::addGeometry(
const std::string &geometry,
5939 const std::vector<double> &numbers,
5940 const std::vector<std::string> &strings,
5946 if(geometry ==
"ParametricSurface") {
5947 if(strings.size() == 3)
5950 strings[2].c_str());
5952 Msg::Error(
"Parametric surface definition requires 3 strings "
5953 "(3 expressions to compute the coordinates)");
5955 else if(geometry ==
"Sphere") {
5956 if(numbers.size() == 4)
5959 Msg::Error(
"Sphere definition requires 4 numbers (3 coordinates "
5960 "of the center and the radius)");
5962 else if(geometry ==
"PolarSphere") {
5963 if(numbers.size() == 4)
5965 numbers[2], numbers[3]);
5967 Msg::Error(
"Polar sphere definition requires 4 numbers (3 coordinates "
5968 "of the center and the radius)");
5971 Msg::Error(
"Unknown geometry '%s'", geometry.c_str());
5977 GMSH_API int gmsh::model::geo::addPointOnGeometry(
const int geometryTag,
5981 const double meshSize,
6001 const std::vector<double> &heights,
6002 const bool recombine)
6005 if(numElements.size()) {
6024 GMSH_API void gmsh::model::geo::extrude(
const vectorpair &dimTags,
6025 const double dx,
const double dy,
6026 const double dz, vectorpair &outDimTags,
6027 const std::vector<int> &numElements,
6028 const std::vector<double> &heights,
6029 const bool recombine)
6035 dimTags, dx, dy, dz, outDimTags, e);
6039 GMSH_API void gmsh::model::geo::revolve(
6040 const vectorpair &dimTags,
const double x,
const double y,
const double z,
6041 const double ax,
const double ay,
const double az,
const double angle,
6042 vectorpair &outDimTags,
const std::vector<int> &numElements,
6043 const std::vector<double> &heights,
const bool recombine)
6049 dimTags, x, y,
z, ax, ay, az,
angle, outDimTags, e);
6053 GMSH_API void gmsh::model::geo::twist(
6054 const vectorpair &dimTags,
const double x,
const double y,
const double z,
6055 const double dx,
const double dy,
const double dz,
const double ax,
6056 const double ay,
const double az,
const double angle, vectorpair &outDimTags,
6057 const std::vector<int> &numElements,
const std::vector<double> &heights,
6058 const bool recombine)
6064 dimTags, x, y,
z, dx, dy, dz, ax, ay, az,
angle, outDimTags, e);
6068 GMSH_API void gmsh::model::geo::extrudeBoundaryLayer(
6069 const vectorpair &dimTags, vectorpair &outDimTags,
6070 const std::vector<int> &numElements,
const std::vector<double> &heights,
6071 const bool recombine,
const bool second,
const int viewIndex)
6077 Msg::Error(
"Element layers are required for boundary layer extrusion");
6086 GMSH_API void gmsh::model::geo::translate(
const vectorpair &dimTags,
6087 const double dx,
const double dy,
6095 const double x,
const double y,
6096 const double z,
const double ax,
6097 const double ay,
const double az,
6105 GMSH_API void gmsh::model::geo::dilate(
const vectorpair &dimTags,
6106 const double x,
const double y,
6107 const double z,
const double a,
6108 const double b,
const double c)
6114 GMSH_API void gmsh::model::geo::mirror(
const vectorpair &dimTags,
6115 const double a,
const double b,
6116 const double c,
const double d)
6123 GMSH_API void gmsh::model::geo::symmetrize(
const vectorpair &dimTags,
6124 const double a,
const double b,
6125 const double c,
const double d)
6127 gmsh::model::geo::mirror(dimTags, a, b,
c, d);
6131 vectorpair &outDimTags)
6138 GMSH_API void gmsh::model::geo::remove(
const vectorpair &dimTags,
6139 const bool recursive)
6145 GMSH_API void gmsh::model::geo::removeAllDuplicates()
6151 GMSH_API void gmsh::model::geo::splitCurve(
const int tag,
6152 const std::vector<int> &pointTags,
6153 std::vector<int> &curveTags)
6159 GMSH_API int gmsh::model::geo::getMaxTag(
const int dim)
6165 GMSH_API void gmsh::model::geo::setMaxTag(
const int dim,
const int maxTag)
6171 GMSH_API int gmsh::model::geo::addPhysicalGroup(
const int dim,
6172 const std::vector<int> &
tags,
6174 const std::string &name)
6186 GMSH_API void gmsh::model::geo::removePhysicalGroups(
const vectorpair &dimTags)
6189 if(dimTags.empty()) {
6193 for(std::size_t i = 0; i < dimTags.size(); i++) {
6194 std::vector<int>
tags;
6196 dimTags[i].first, dimTags[i].second, 2,
tags);
6201 GMSH_API void gmsh::model::geo::synchronize()
6210 gmsh::model::geo::mesh::setTransfiniteCurve(
const int tag,
const int nPoints,
6211 const std::string &meshType,
6215 int type = (meshType ==
"Progression" || meshType ==
"Power") ? 1 :
6216 (meshType ==
"Bump") ? 2 :
6217 (meshType ==
"Beta") ? 3 :
6219 double c = std::abs(coef);
6221 if(coef < 0) type = -type;
6224 for(
int sig = -1; sig <= 1; sig += 2)
6229 GMSH_API void gmsh::model::geo::mesh::setTransfiniteSurface(
6230 const int tag,
const std::string &arrangement,
6231 const std::vector<int> &cornerTags)
6234 int t = (arrangement ==
"Right") ? 1 :
6235 (arrangement ==
"Left") ? -1 :
6236 (arrangement ==
"AlternateRight") ? 2 :
6237 (arrangement ==
"AlternateLeft") ? -2 :
6238 (arrangement ==
"Alternate") ? 2 :
6245 gmsh::model::geo::mesh::setTransfiniteVolume(
const int tag,
6246 const std::vector<int> &cornerTags)
6252 GMSH_API void gmsh::model::geo::mesh::setRecombine(
const int dim,
const int tag,
6259 GMSH_API void gmsh::model::geo::mesh::setSmoothing(
const int dim,
const int tag,
6266 GMSH_API void gmsh::model::geo::mesh::setReverse(
const int dim,
const int tag,
6273 GMSH_API void gmsh::model::geo::mesh::setAlgorithm(
const int dim,
const int tag,
6280 GMSH_API void gmsh::model::geo::mesh::setSizeFromBoundary(
const int dim,
6288 GMSH_API void gmsh::model::geo::mesh::setSize(
const vectorpair &dimTags,
6292 for(std::size_t i = 0; i < dimTags.size(); i++) {
6293 int dim = dimTags[i].first, tag = dimTags[i].second;
6306 GMSH_API int gmsh::model::occ::addPoint(
const double x,
const double y,
6307 const double z,
const double meshSize,
6317 GMSH_API int gmsh::model::occ::addLine(
const int startTag,
const int endTag,
6327 GMSH_API int gmsh::model::occ::addCircleArc(
const int startTag,
6328 const int centerTag,
6329 const int endTag,
const int tag)
6339 GMSH_API int gmsh::model::occ::addCircle(
const double x,
const double y,
6340 const double z,
const double r,
6341 const int tag,
const double angle1,
6342 const double angle2,
6343 const std::vector<double> &zAxis,
6344 const std::vector<double> &xAxis)
6350 angle2, zAxis, xAxis);
6354 GMSH_API int gmsh::model::occ::addEllipseArc(
const int startTag,
6355 const int centerTag,
6357 const int endTag,
const int tag)
6363 outTag, startTag, centerTag, majorTag, endTag);
6367 GMSH_API int gmsh::model::occ::addEllipse(
const double x,
const double y,
6368 const double z,
const double r1,
6369 const double r2,
const int tag,
6370 const double angle1,
6371 const double angle2,
6372 const std::vector<double> &zAxis,
6373 const std::vector<double> &xAxis)
6379 angle1, angle2, zAxis,
6384 GMSH_API int gmsh::model::occ::addSpline(
const std::vector<int> &pointTags,
6386 const std::vector<double> &tangents)
6391 std::vector<SVector3> t;
6392 if(tangents.size() % 3) {
6393 Msg::Error(
"Number of entries in tangents should be a multiple of 3");
6395 else if(!tangents.empty()) {
6396 for(std::size_t i = 0; i < tangents.size(); i += 3) {
6397 t.push_back(
SVector3(tangents[i], tangents[i + 1], tangents[i + 2]));
6404 GMSH_API int gmsh::model::occ::addBSpline(
6405 const std::vector<int> &pointTags,
const int tag,
const int degree,
6406 const std::vector<double> &weights,
const std::vector<double> &knots,
6407 const std::vector<int> &multiplicities)
6413 outTag, pointTags, degree, weights, knots, multiplicities);
6417 GMSH_API int gmsh::model::occ::addBezier(
const std::vector<int> &pointTags,
6427 GMSH_API int gmsh::model::occ::addWire(
const std::vector<int> &curveTags,
6428 const int tag,
const bool checkClosed)
6437 GMSH_API int gmsh::model::occ::addCurveLoop(
const std::vector<int> &curveTags,
6447 GMSH_API int gmsh::model::occ::addRectangle(
const double x,
const double y,
6448 const double z,
const double dx,
6449 const double dy,
const int tag,
6450 const double roundedRadius)
6460 GMSH_API int gmsh::model::occ::addDisk(
const double xc,
const double yc,
6461 const double zc,
const double rx,
6462 const double ry,
const int tag,
6463 const std::vector<double> &zAxis,
6464 const std::vector<double> &xAxis)
6474 GMSH_API int gmsh::model::occ::addPlaneSurface(
const std::vector<int> &wireTags,
6484 GMSH_API int gmsh::model::occ::addSurfaceFilling(
6485 const int wireTag,
const int tag,
const std::vector<int> &pointTags,
6486 const int degree,
const int numPointsOnCurves,
const int numIter,
6487 const bool anisotropic,
const double tol2d,
const double tol3d,
6488 const double tolAng,
const double tolCurv,
const int maxDegree,
6489 const int maxSegments)
6494 std::vector<int> surf, surfCont;
6496 outTag, wireTag, pointTags, surf, surfCont, degree, numPointsOnCurves,
6497 numIter, anisotropic, tol2d, tol3d, tolAng, tolCurv, maxDegree,
6502 GMSH_API int gmsh::model::occ::addBSplineFilling(
const int wireTag,
6504 const std::string &type)
6514 GMSH_API int gmsh::model::occ::addBezierFilling(
const int wireTag,
6516 const std::string &type)
6525 GMSH_API int gmsh::model::occ::addBSplineSurface(
6526 const std::vector<int> &pointTags,
const int numPointsU,
const int tag,
6527 const int degreeU,
const int degreeV,
const std::vector<double> &weights,
6528 const std::vector<double> &knotsU,
const std::vector<double> &knotsV,
6529 const std::vector<int> &multiplicitiesU,
6530 const std::vector<int> &multiplicitiesV,
const std::vector<int> &wireTags,
6537 outTag, pointTags, numPointsU, degreeU, degreeV, weights, knotsU, knotsV,
6538 multiplicitiesU, multiplicitiesV, wireTags, wire3D);
6542 GMSH_API int gmsh::model::occ::addBezierSurface(
6543 const std::vector<int> &pointTags,
const int numPointsU,
const int tag,
6544 const std::vector<int> &wireTags,
const bool wire3D)
6550 outTag, pointTags, numPointsU, wireTags, wire3D);
6555 gmsh::model::occ::addTrimmedSurface(
const int surfaceTag,
6556 const std::vector<int> &wireTags,
6557 const bool wire3D,
const int tag)
6568 gmsh::model::occ::addSurfaceLoop(
const std::vector<int> &surfaceTags,
6569 const int tag,
const bool sewing)
6579 GMSH_API int gmsh::model::occ::addVolume(
const std::vector<int> &shellTags,
6589 GMSH_API int gmsh::model::occ::addSphere(
const double xc,
const double yc,
6590 const double zc,
const double radius,
6591 const int tag,
const double angle1,
6592 const double angle2,
6593 const double angle3)
6599 angle1, angle2, angle3);
6603 GMSH_API int gmsh::model::occ::addBox(
const double x,
const double y,
6604 const double z,
const double dx,
6605 const double dy,
const double dz,
6615 GMSH_API int gmsh::model::occ::addCylinder(
const double x,
const double y,
6616 const double z,
const double dx,
6617 const double dy,
const double dz,
6618 const double r,
const int tag,
6629 GMSH_API int gmsh::model::occ::addCone(
const double x,
const double y,
6630 const double z,
const double dx,
6631 const double dy,
const double dz,
6632 const double r1,
const double r2,
6633 const int tag,
const double angle)
6643 GMSH_API int gmsh::model::occ::addWedge(
const double x,
const double y,
6644 const double z,
const double dx,
6645 const double dy,
const double dz,
6646 const int tag,
const double ltx,
6647 const std::vector<double> &zAxis)
6657 GMSH_API int gmsh::model::occ::addTorus(
const double x,
const double y,
6658 const double z,
const double r1,
6659 const double r2,
const int tag,
6661 const std::vector<double> &zAxis)
6671 GMSH_API void gmsh::model::occ::addThruSections(
6672 const std::vector<int> &wireTags, vectorpair &outDimTags,
const int tag,
6673 const bool makeSolid,
const bool makeRuled,
const int maxDegree,
6674 const std::string &continuity,
const std::string ¶metrization,
6675 const bool smoothing)
6681 tag, wireTags, makeSolid, makeRuled, outDimTags, maxDegree,
6682 continuity, parametrization, smoothing);
6685 GMSH_API void gmsh::model::occ::addThickSolid(
6686 const int volumeTag,
const std::vector<int> &excludeSurfaceTags,
6687 const double offset, vectorpair &outDimTags,
const int tag)
6693 tag, volumeTag, excludeSurfaceTags, offset, outDimTags);
6696 GMSH_API void gmsh::model::occ::extrude(
const vectorpair &dimTags,
6697 const double dx,
const double dy,
6698 const double dz, vectorpair &outDimTags,
6699 const std::vector<int> &numElements,
6700 const std::vector<double> &heights,
6701 const bool recombine)
6708 dimTags, dx, dy, dz, outDimTags, e);
6712 GMSH_API void gmsh::model::occ::revolve(
6713 const vectorpair &dimTags,
const double x,
const double y,
const double z,
6714 const double ax,
const double ay,
const double az,
const double angle,
6715 vectorpair &outDimTags,
const std::vector<int> &numElements,
6716 const std::vector<double> &heights,
const bool recombine)
6723 dimTags, x, y,
z, ax, ay, az,
angle, outDimTags, e);
6727 GMSH_API void gmsh::model::occ::addPipe(
const vectorpair &dimTags,
6729 vectorpair &outDimTags,
6730 const std::string &trihedron)
6739 GMSH_API void gmsh::model::occ::fillet(
const std::vector<int> &volumeTags,
6740 const std::vector<int> &curveTags,
6741 const std::vector<double> &radii,
6742 vectorpair &outDimTags,
6743 const bool removeVolume)
6749 outDimTags, removeVolume);
6752 GMSH_API void gmsh::model::occ::chamfer(
const std::vector<int> &volumeTags,
6753 const std::vector<int> &curveTags,
6754 const std::vector<int> &surfaceTags,
6755 const std::vector<double> &distances,
6756 vectorpair &outDimTags,
6757 const bool removeVolume)
6763 volumeTags, curveTags, surfaceTags, distances, outDimTags, removeVolume);
6766 GMSH_API void gmsh::model::occ::fuse(
const vectorpair &objectDimTags,
6767 const vectorpair &toolDimTags,
6768 vectorpair &outDimTags,
6769 std::vector<vectorpair> &outDimTagsMap,
6770 const int tag,
const bool removeObject,
6771 const bool removeTool)
6776 outDimTagsMap.clear();
6778 tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject,
6783 const vectorpair &objectDimTags,
const vectorpair &toolDimTags,
6784 vectorpair &outDimTags, std::vector<vectorpair> &outDimTagsMap,
const int tag,
6785 const bool removeObject,
const bool removeTool)
6790 outDimTagsMap.clear();
6792 tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject,
6796 GMSH_API void gmsh::model::occ::cut(
const vectorpair &objectDimTags,
6797 const vectorpair &toolDimTags,
6798 vectorpair &outDimTags,
6799 std::vector<vectorpair> &outDimTagsMap,
6800 const int tag,
const bool removeObject,
6801 const bool removeTool)
6806 outDimTagsMap.clear();
6808 tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject,
6812 GMSH_API void gmsh::model::occ::fragment(
const vectorpair &objectDimTags,
6813 const vectorpair &toolDimTags,
6814 vectorpair &outDimTags,
6815 std::vector<vectorpair> &outDimTagsMap,
6816 const int tag,
const bool removeObject,
6817 const bool removeTool)
6822 outDimTagsMap.clear();
6824 tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject,
6828 GMSH_API void gmsh::model::occ::translate(
const vectorpair &dimTags,
6829 const double dx,
const double dy,
6838 const double x,
const double y,
6839 const double z,
const double ax,
6840 const double ay,
const double az,
6849 GMSH_API void gmsh::model::occ::dilate(
const vectorpair &dimTags,
6850 const double x,
const double y,
6851 const double z,
const double a,
6852 const double b,
const double c)
6859 GMSH_API void gmsh::model::occ::mirror(
const vectorpair &dimTags,
6860 const double a,
const double b,
6861 const double c,
const double d)
6868 GMSH_API void gmsh::model::occ::symmetrize(
const vectorpair &dimTags,
6869 const double a,
const double b,
6870 const double c,
const double d)
6872 gmsh::model::occ::mirror(dimTags, a, b,
c, d);
6876 gmsh::model::occ::affineTransform(
const vectorpair &dimTags,
6877 const std::vector<double> &affineTransform)
6885 vectorpair &outDimTags)
6893 GMSH_API void gmsh::model::occ::remove(
const vectorpair &dimTags,
6894 const bool recursive)
6901 GMSH_API void gmsh::model::occ::removeAllDuplicates()
6908 GMSH_API void gmsh::model::occ::healShapes(
6909 vectorpair &outDimTags,
const vectorpair &inDimTags,
const double tolerance,
6910 const bool fixDegenerated,
const bool fixSmallEdges,
const bool fixSmallFaces,
6911 const bool sewFaces,
const bool makeSolids)
6917 inDimTags, outDimTags,
tolerance, fixDegenerated, fixSmallEdges,
6918 fixSmallFaces, sewFaces, makeSolids);
6921 GMSH_API void gmsh::model::occ::convertToNURBS(
const vectorpair &inDimTags)
6928 GMSH_API void gmsh::model::occ::importShapes(
const std::string &fileName,
6929 vectorpair &outDimTags,
6930 const bool highestDimOnly,
6931 const std::string &format)
6937 outDimTags, format);
6940 GMSH_API void gmsh::model::occ::importShapesNativePointer(
6941 const void *shape, vectorpair &outDimTags,
const bool highestDimOnly)
6946 #if defined(HAVE_OCC)
6948 static_cast<const TopoDS_Shape *
>(shape), highestDimOnly, outDimTags);
6950 Msg::Error(
"Gmsh requires OpenCASCADE to import native shape");
6954 GMSH_API void gmsh::model::occ::getEntities(vectorpair &dimTags,
const int dim)
6961 GMSH_API void gmsh::model::occ::getEntitiesInBoundingBox(
6962 const double xmin,
const double ymin,
const double zmin,
const double xmax,
6963 const double ymax,
const double zmax, vectorpair &dimTags,
const int dim)
6969 xmin, ymin, zmin, xmax, ymax, zmax, dimTags, dim);
6973 double &xmin,
double &ymin,
6974 double &zmin,
double &xmax,
6975 double &ymax,
double &zmax)
6980 zmin, xmax, ymax, zmax);
6983 GMSH_API void gmsh::model::occ::getCurveLoops(
6984 const int surfaceTag, std::vector<int> &curveLooptags,
6985 std::vector<std::vector<int> > &curveTags)
6994 GMSH_API void gmsh::model::occ::getSurfaceLoops(
6995 const int volumeTag, std::vector<int> &surfaceLoopTags,
6996 std::vector<std::vector<int> > &surfaceTags)
7005 GMSH_API void gmsh::model::occ::getMass(
const int dim,
const int tag,
7013 GMSH_API void gmsh::model::occ::getCenterOfMass(
const int dim,
const int tag,
7014 double &x,
double &y,
double &
z)
7021 GMSH_API void gmsh::model::occ::getMatrixOfInertia(
const int dim,
const int tag,
7022 std::vector<double> &m)
7029 GMSH_API int gmsh::model::occ::getMaxTag(
const int dim)
7036 GMSH_API void gmsh::model::occ::setMaxTag(
const int dim,
const int maxTag)
7043 GMSH_API void gmsh::model::occ::synchronize()
7052 GMSH_API void gmsh::model::occ::mesh::setSize(
const vectorpair &dimTags,
7057 for(std::size_t i = 0; i < dimTags.size(); i++) {
7058 int dim = dimTags[i].first, tag = dimTags[i].second;
7065 GMSH_API int gmsh::view::add(
const std::string &name,
const int tag)
7068 #if defined(HAVE_POST)
7071 #if defined(HAVE_FLTK)
7072 if(FlGui::available()) FlGui::instance()->updateViews(
true,
true);
7076 Msg::Error(
"Views require the post-processing module");
7081 GMSH_API void gmsh::view::remove(
const int tag)
7084 #if defined(HAVE_POST)
7091 #if defined(HAVE_FLTK)
7092 if(FlGui::available()) FlGui::instance()->updateViews(
true,
true);
7095 Msg::Error(
"Views require the post-processing module");
7099 GMSH_API int gmsh::view::getIndex(
const int tag)
7102 #if defined(HAVE_POST)
7110 Msg::Error(
"Views require the post-processing module");
7115 GMSH_API void gmsh::view::getTags(std::vector<int> &
tags)
7118 #if defined(HAVE_POST)
7120 for(std::size_t i = 0; i <
PView::list.size(); i++)
7123 Msg::Error(
"Views require the post-processing module");
7130 const std::string &dataType,
const std::vector<std::size_t> &
tags,
7131 const T &data,
const double time,
const int numComponents,
7132 const int partition)
7134 #if defined(HAVE_POST)
7141 if(modelName.size()) {
7144 Msg::Error(
"Unknown model '%s'", modelName.c_str());
7149 if(dataType ==
"NodeData")
7151 else if(dataType ==
"ElementData")
7153 else if(dataType ==
"ElementNodeData")
7155 else if(dataType ==
"GaussPointData")
7157 else if(dataType ==
"Beam")
7160 Msg::Error(
"Unknown type of view to add '%s'", dataType.c_str());
7165 bool changeType =
false;
7166 if(d && d->
getType() != type) {
7167 Msg::Warning(
"Changing type of view to '%s'", dataType.c_str());
7170 if(!d || changeType) {
7178 if(!d->
addData(model,
tags, data, step, time, partition, numComponents)) {
7188 Msg::Error(
"Views require the post-processing module");
7192 GMSH_API void gmsh::view::addModelData(
7193 const int tag,
const int step,
const std::string &modelName,
7194 const std::string &dataType,
const std::vector<std::size_t> &
tags,
7195 const std::vector<std::vector<double> > &data,
const double time,
7196 const int numComponents,
const int partition)
7199 if(
tags.size() != data.size()) {
7200 Msg::Error(
"Incompatible number of tags and data");
7207 GMSH_API void gmsh::view::addHomogeneousModelData(
7208 const int tag,
const int step,
const std::string &modelName,
7209 const std::string &dataType,
const std::vector<std::size_t> &
tags,
7210 const std::vector<double> &data,
const double time,
const int numComponents,
7211 const int partition)
7218 #if defined(HAVE_POST)
7220 std::string &dataType,
double &time,
7221 int &numComponents,
int &numEnt,
7232 Msg::Error(
"View with tag %d does not contain model data", tag);
7236 dataType =
"NodeData";
7238 dataType =
"ElementData";
7240 dataType =
"ElementNodeData";
7242 dataType =
"GaussPointData";
7246 dataType =
"Unknown";
7249 Msg::Error(
"View with tag %d does not contain model data for step %d", tag,
7257 for(std::size_t i = 0; i < s->
getNumData(); i++) {
7260 maxMult = std::max(maxMult, s->
getMult(i));
7267 GMSH_API void gmsh::view::getModelData(
const int tag,
const int step,
7268 std::string &dataType,
7269 std::vector<std::size_t> &
tags,
7270 std::vector<std::vector<double> > &data,
7271 double &time,
int &numComponents)
7276 #if defined(HAVE_POST)
7277 int numEnt, maxMult;
7279 _getModelData(tag, step, dataType, time, numComponents, numEnt, maxMult);
7280 if(!s || !numComponents || !numEnt || !maxMult)
return;
7281 data.resize(numEnt);
7282 tags.resize(numEnt);
7284 for(std::size_t i = 0; i < s->
getNumData(); i++) {
7289 data[j].resize(numComponents *
mult);
7290 for(
int k = 0; k < numComponents *
mult; k++) data[j][k] = dd[k];
7295 Msg::Error(
"Views require the post-processing module");
7299 GMSH_API void gmsh::view::getHomogeneousModelData(
7300 const int tag,
const int step, std::string &dataType,
7301 std::vector<std::size_t> &
tags, std::vector<double> &data,
double &time,
7307 #if defined(HAVE_POST)
7308 int numEnt, maxMult;
7310 _getModelData(tag, step, dataType, time, numComponents, numEnt, maxMult);
7311 if(!s || !numComponents || !numEnt || !maxMult)
return;
7312 data.resize(numEnt * numComponents * maxMult, 0.);
7313 tags.resize(numEnt);
7315 for(std::size_t i = 0; i < s->
getNumData(); i++) {
7320 for(
int k = 0; k < numComponents *
mult; k++) {
7321 data[j * numComponents * maxMult + k] = dd[k];
7327 Msg::Error(
"Views require the post-processing module");
7333 char **dataType,
size_t **
tags,
7334 size_t *tags_n,
double ***data,
7335 size_t **data_n,
size_t *data_nn,
7336 double *time,
int *numComponents,
int *ierr)
7339 if(ierr) *ierr = -1;
7342 #if defined(HAVE_POST)
7351 Msg::Error(
"View with tag %d does not contain model data", tag);
7355 *dataType = strdup(
"NodeData");
7357 *dataType = strdup(
"ElementData");
7359 *dataType = strdup(
"ElementNodeData");
7361 *dataType = strdup(
"GaussPointData");
7363 *dataType = strdup(
"Beam");
7365 *dataType = strdup(
"Unknown");
7368 Msg::Error(
"View with tag %d does not contain model data for step %d", tag,
7378 for(
size_t i = 0; i < s->
getNumData(); i++) {
7383 *
tags = (
size_t *)
Malloc(numEnt *
sizeof(
size_t));
7385 *data_n = (
size_t *)
Malloc(numEnt *
sizeof(
size_t *));
7386 *data = (
double **)
Malloc(numEnt *
sizeof(
double *));
7388 for(
size_t i = 0; i < s->
getNumData(); i++) {
7393 (*data_n)[j] = *numComponents *
mult;
7394 (*data)[j] = (
double *)
Malloc(*numComponents *
mult *
sizeof(
double));
7395 for(
int k = 0; k < *numComponents *
mult; k++) (*data)[j][k] = dd[k];
7401 Msg::Error(
"Views require the post-processing module");
7402 if(ierr) *ierr = -1;
7406 GMSH_API void gmsh::view::addListData(
const int tag,
7407 const std::string &dataType,
7408 const int numElements,
7409 const std::vector<double> &data)
7412 #if defined(HAVE_POST)
7427 const char *types[] = {
"SP",
"VP",
"TP",
"SL",
"VL",
"TL",
"ST",
"VT",
7428 "TT",
"SQ",
"VQ",
"TQ",
"SS",
"VS",
"TS",
"SH",
7429 "VH",
"TH",
"SI",
"VI",
"TI",
"SY",
"VY",
"TY"};
7430 for(
int idxtype = 0; idxtype < 24; idxtype++) {
7431 if(dataType == types[idxtype]) {
7432 d->
importList(idxtype, numElements, data,
true);
7437 Msg::Error(
"Unknown data type for list import");
7439 Msg::Error(
"Views require the post-processing module");
7443 GMSH_API void gmsh::view::getListData(
const int tag,
7444 std::vector<std::string> &dataTypes,
7445 std::vector<int> &numElements,
7446 std::vector<std::vector<double> > &data)
7449 #if defined(HAVE_POST)
7457 Msg::Error(
"View with tag %d does not contain list data", tag);
7460 const char *types[] = {
"SP",
"VP",
"TP",
"SL",
"VL",
"TL",
"ST",
"VT",
7461 "TT",
"SQ",
"VQ",
"TQ",
"SS",
"VS",
"TS",
"SH",
7462 "VH",
"TH",
"SI",
"VI",
"TI",
"SY",
"VY",
"TY"};
7463 std::vector<int> N(24);
7464 std::vector<std::vector<double> *> V(24);
7466 for(
int idxtype = 0; idxtype < 24; idxtype++) {
7468 dataTypes.push_back(types[idxtype]);
7469 numElements.push_back(N[idxtype]);
7470 data.push_back(*V[idxtype]);
7474 Msg::Error(
"Views require the post-processing module");
7478 #if defined(HAVE_POST)
7479 static double getStringStyle(
const std::vector<std::string> &style)
7481 if(style.empty())
return 0.;
7483 if(style.size() % 2) {
7484 Msg::Error(
"Number of string style attributes should be even");
7487 for(std::size_t i = 0; i < style.size(); i += 2) {
7488 std::string key = style[i], val = style[i + 1];
7489 #if defined(HAVE_OPENGL)
7492 else if(key ==
"FontSize")
7493 fontsize = atoi(val.c_str());
7494 else if(key ==
"Align")
7499 return (
double)((align << 16) | (font << 8) | (fontsize));
7504 gmsh::view::addListDataString(
const int tag,
const std::vector<double> &coord,
7505 const std::vector<std::string> &data,
7506 const std::vector<std::string> &style)
7509 #if defined(HAVE_POST)
7524 if(coord.size() == 3) {
7525 d->
T3D.push_back(coord[0]);
7526 d->
T3D.push_back(coord[1]);
7527 d->
T3D.push_back(coord[2]);
7528 d->
T3D.push_back(getStringStyle(style)), d->
T3D.push_back(d->
T3C.size());
7530 for(std::size_t i = 0; i < data.size(); i++) {
7531 for(std::size_t j = 0; j < data[i].size(); j++) {
7532 d->
T3C.push_back(data[i][j]);
7534 d->
T3C.push_back(
'\0');
7537 else if(coord.size() == 2) {
7538 d->
T2D.push_back(coord[0]);
7539 d->
T2D.push_back(coord[1]);
7540 d->
T2D.push_back(getStringStyle(style)), d->
T2D.push_back(d->
T2C.size());
7542 for(std::size_t i = 0; i < data.size(); i++) {
7543 for(std::size_t j = 0; j < data[i].size(); j++) {
7544 d->
T2C.push_back(data[i][j]);
7546 d->
T2C.push_back(
'\0');
7552 Msg::Error(
"Views require the post-processing module");
7556 GMSH_API void gmsh::view::getListDataStrings(
const int tag,
const int dim,
7557 std::vector<double> &coord,
7558 std::vector<std::string> &data,
7559 std::vector<std::string> &style)
7562 #if defined(HAVE_POST)
7570 Msg::Error(
"View with tag %d does not contain list data", tag);
7576 for(
int i = 0; i < ns; i++) {
7577 for(
int j = 0; j < nstep; j++) {
7578 double x, y,
z, styl;
7589 style.push_back(
"");
7595 for(
int i = 0; i < ns; i++) {
7596 for(
int j = 0; j < nstep; j++) {
7607 style.push_back(
"");
7612 Msg::Error(
"Views require the post-processing module");
7616 GMSH_API void gmsh::view::setInterpolationMatrices(
7617 const int tag,
const std::string &type,
const int d,
7618 const std::vector<double> &coef,
const std::vector<double> &exp,
7619 const int dGeo,
const std::vector<double> &coefGeo,
7620 const std::vector<double> &expGeo)
7623 #if defined(HAVE_POST)
7631 Msg::Error(
"View with tag %d does not contain any data", tag);
7636 if(type ==
"Line" || type ==
"line")
7638 else if(type ==
"Triangle" || type ==
"triangle")
7640 else if(type ==
"Quadrangle" || type ==
"quadrangle")
7642 else if(type ==
"Tetrahedron" || type ==
"tetrahedron")
7644 else if(type ==
"Pyramid" || type ==
"pyramid")
7646 else if(type ==
"Prism" || type ==
"prism")
7648 else if(type ==
"Hexahedron" || type ==
"hexahedron")
7651 Msg::Error(
"Unknown element family type '%s'", type.c_str());
7661 if((
int)coef.size() != d * d) {
7662 Msg::Error(
"Wrong number of coefficients (%d != %d x %d)", (
int)coef.size(),
7666 if((
int)exp.size() != d * 3) {
7667 Msg::Error(
"Wrong number of exponents (%d != %d x 3)", (
int)exp.size(), d);
7671 for(
int i = 0; i < d; i++) {
7672 for(
int j = 0; j < d; j++) {
F(i, j) = coef[d * i + j]; }
7673 for(
int j = 0; j < 3; j++) { P(i, j) = exp[3 * i + j]; }
7683 if((
int)coefGeo.size() != dGeo * dGeo) {
7684 Msg::Error(
"Wrong number of coefficients (%d != %d x %d)",
7685 (
int)coefGeo.size(), dGeo, dGeo);
7688 if((
int)expGeo.size() != dGeo * 3) {
7689 Msg::Error(
"Wrong number of exponents (%d != %d x 3)", (
int)expGeo.size(),
7694 for(
int i = 0; i < dGeo; i++) {
7695 for(
int j = 0; j < dGeo; j++) { Fg(i, j) = coefGeo[dGeo * i + j]; }
7696 for(
int j = 0; j < 3; j++) { Pg(i, j) = expGeo[3 * i + j]; }
7701 Msg::Error(
"Views require the post-processing module");
7705 GMSH_API int gmsh::view::addAlias(
const int refTag,
const bool copyOptions,
7709 #if defined(HAVE_POST)
7712 Msg::Error(
"Unknown view with tag %d", refTag);
7715 PView *view =
new PView(ref, copyOptions, tag);
7716 #if defined(HAVE_FLTK)
7717 if(FlGui::available()) FlGui::instance()->updateViews(
true,
true);
7721 Msg::Error(
"Views require the post-processing module");
7726 GMSH_API void gmsh::view::combine(
const std::string &what,
7727 const std::string &how,
const bool remove,
7728 const bool copyOptions)
7731 #if defined(HAVE_POST)
7732 bool time = (what ==
"steps") ?
true :
false;
7733 int ihow = (how ==
"all") ? 1 : (how ==
"name") ? 2 : 0;
7735 #if defined(HAVE_FLTK)
7736 if(FlGui::available()) FlGui::instance()->updateViews(
true,
true);
7739 Msg::Error(
"Views require the post-processing module");
7743 GMSH_API void gmsh::view::probe(
const int tag,
const double x,
const double y,
7744 const double z, std::vector<double> &values,
7746 const int numComp,
const bool gradient,
7747 const double distanceMax,
7748 const std::vector<double> &xElemCoord,
7749 const std::vector<double> &yElemCoord,
7750 const std::vector<double> &zElemCoord,
7754 #if defined(HAVE_POST)
7768 double *qx =
nullptr, *qy =
nullptr, *qz =
nullptr;
7769 if(xElemCoord.size() && yElemCoord.size() && zElemCoord.size() &&
7770 xElemCoord.size() == yElemCoord.size() &&
7771 xElemCoord.size() == zElemCoord.size()) {
7772 qn = xElemCoord.size();
7773 qx = (
double *)&xElemCoord[0];
7774 qy = (
double *)&yElemCoord[0];
7775 qz = (
double *)&zElemCoord[0];
7778 int mult = gradient ? 3 : 1;
7784 qn, qx, qy, qz, gradient, dim)) {
7785 numVal = numSteps *
mult * 1;
7790 qn, qx, qy, qz, gradient, dim)) {
7791 numVal = numSteps *
mult * 3;
7796 qn, qx, qy, qz, gradient, dim)) {
7797 numVal = numSteps *
mult * 9;
7802 qn, qx, qy, qz, gradient, dim)) {
7803 numVal = numSteps *
mult * 1;
7806 qn, qx, qy, qz, gradient,
7808 numVal = numSteps *
mult * 3;
7811 qn, qx, qy, qz, gradient,
7813 numVal = numSteps *
mult * 9;
7817 for(
int i = 0; i < numVal; i++) values.push_back(val[i]);
7819 Msg::Error(
"Views require the post-processing module");
7823 GMSH_API void gmsh::view::write(
const int tag,
const std::string &fileName,
7827 #if defined(HAVE_POST)
7833 view->
write(fileName, 10, append);
7835 Msg::Error(
"Views require the post-processing module");
7839 GMSH_API void gmsh::view::setVisibilityPerWindow(
const int tag,
const int value,
7840 const int windowIndex)
7843 #if defined(HAVE_POST)
7849 #if defined(HAVE_FLTK)
7850 FlGui::instance()->setCurrentOpenglWindow(windowIndex);
7851 drawContext *ctx = FlGui::instance()->getCurrentDrawContext();
7858 Msg::Error(
"Views require the post-processing module");
7864 GMSH_API void gmsh::view::option::setNumber(
int tag,
const std::string &name,
7868 #if defined(HAVE_POST)
7872 Msg::Error(
"Could not set option '%s' in view with tag %d",
7879 Msg::Error(
"Views require the post-processing module");
7883 GMSH_API void gmsh::view::option::getNumber(
int tag,
const std::string &name,
7887 #if defined(HAVE_POST)
7891 Msg::Error(
"Could not get option '%s' in view with tag %d",
7898 Msg::Error(
"Views require the post-processing module");
7902 GMSH_API void gmsh::view::option::setString(
int tag,
const std::string &name,
7903 const std::string &value)
7906 #if defined(HAVE_POST)
7910 Msg::Error(
"Could not set option '%s' in view with tag %d",
7917 Msg::Error(
"Views require the post-processing module");
7921 GMSH_API void gmsh::view::option::getString(
int tag,
const std::string &name,
7925 #if defined(HAVE_POST)
7929 Msg::Error(
"Could not get option '%s' in view with tag %d",
7936 Msg::Error(
"Views require the post-processing module");
7941 const int r,
const int g,
7942 const int b,
const int a)
7945 #if defined(HAVE_POST)
7950 Msg::Error(
"Could not set option '%s' in view with tag %d",
7957 Msg::Error(
"Views require the post-processing module");
7961 GMSH_API void gmsh::view::option::getColor(
int tag,
const std::string &name,
7962 int &r,
int &g,
int &b,
int &a)
7965 #if defined(HAVE_POST)
7976 Msg::Error(
"Could not get option '%s' in view with tag %d",
7984 Msg::Error(
"Views require the post-processing module");
7991 #if defined(HAVE_POST)
7994 Msg::Error(
"Unknown view with tag %d", refTag);
8004 #if defined(HAVE_FLTK)
8005 if(FlGui::available()) FlGui::instance()->updateViews(
true,
true);
8008 Msg::Error(
"Views require the post-processing module");
8014 GMSH_API void gmsh::plugin::setNumber(
const std::string &name,
8015 const std::string &option,
8019 #if defined(HAVE_PLUGINS)
8023 Msg::Error(
"Unknown plugin or plugin option");
8026 Msg::Error(
"Views require the post-processing and plugin modules");
8030 GMSH_API void gmsh::plugin::setString(
const std::string &name,
8031 const std::string &option,
8032 const std::string &value)
8035 #if defined(HAVE_PLUGINS)
8039 Msg::Error(
"Unknown plugin or plugin option");
8042 Msg::Error(
"Views require the post-processing and plugin modules");
8046 GMSH_API int gmsh::plugin::run(
const std::string &name)
8049 #if defined(HAVE_PLUGINS)
8053 Msg::Error(
"Unknown plugin or plugin action");
8057 Msg::Error(
"Views require the post-processing and plugin modules");
8064 GMSH_API void gmsh::graphics::draw()
8066 #if defined(HAVE_OPENGL)
8073 #if defined(HAVE_FLTK)
8074 static void _errorHandlerFltk(
const char *fmt, ...)
8078 va_start(args, fmt);
8079 vsnprintf(str,
sizeof(str), fmt, args);
8084 static void _createFltk()
8086 if(!FlGui::available())
8087 FlGui::instance(
_argc,
_argv,
false, _errorHandlerFltk);
8091 GMSH_API void gmsh::fltk::initialize()
8094 #if defined(HAVE_FLTK)
8096 FlGui::setFinishedProcessingCommandLine();
8103 GMSH_API void gmsh::fltk::finalize()
8106 #if defined(HAVE_FLTK)
8113 GMSH_API int gmsh::fltk::isAvailable()
8116 #if defined(HAVE_FLTK)
8117 return FlGui::available() ? 1 : 0;
8123 GMSH_API void gmsh::fltk::wait(
const double time)
8126 #if defined(HAVE_FLTK)
8129 FlGui::wait(time,
true);
8140 #if defined(HAVE_FLTK)
8150 #if defined(HAVE_FLTK)
8160 #if defined(HAVE_FLTK)
8162 FlGui::instance()->updateViews(
true,
true);
8168 GMSH_API void gmsh::fltk::awake(
const std::string &action)
8171 #if defined(HAVE_FLTK)
8172 FlGui::awake(action);
8181 #if defined(HAVE_FLTK)
8183 FlGui::instance()->run();
8189 #if defined(HAVE_FLTK)
8190 static int selectionCode(
char val)
8203 GMSH_API int gmsh::fltk::selectEntities(vectorpair &dimTags,
const int dim)
8207 #if defined(HAVE_FLTK)
8211 case 0: ret = FlGui::instance()->selectEntity(
ENT_POINT);
break;
8212 case 1: ret = FlGui::instance()->selectEntity(
ENT_CURVE);
break;
8213 case 2: ret = FlGui::instance()->selectEntity(
ENT_SURFACE);
break;
8214 case 3: ret = FlGui::instance()->selectEntity(
ENT_VOLUME);
break;
8215 default: ret = FlGui::instance()->selectEntity(
ENT_ALL);
break;
8217 if(!FlGui::available())
return 0;
8218 for(std::size_t i = 0; i < FlGui::instance()->selectedVertices.size(); i++)
8220 std::make_pair(0, FlGui::instance()->selectedVertices[i]->tag()));
8221 for(std::size_t i = 0; i < FlGui::instance()->selectedEdges.size(); i++)
8223 std::make_pair(1, FlGui::instance()->selectedEdges[i]->tag()));
8224 for(std::size_t i = 0; i < FlGui::instance()->selectedFaces.size(); i++)
8226 std::make_pair(2, FlGui::instance()->selectedFaces[i]->tag()));
8227 for(std::size_t i = 0; i < FlGui::instance()->selectedRegions.size(); i++)
8229 std::make_pair(3, FlGui::instance()->selectedRegions[i]->tag()));
8230 return selectionCode(ret);
8236 GMSH_API int gmsh::fltk::selectElements(std::vector<std::size_t> &elementTags)
8239 elementTags.clear();
8240 #if defined(HAVE_FLTK)
8245 char ret = FlGui::instance()->selectEntity(
ENT_ALL);
8247 if(!FlGui::available())
return 0;
8248 for(std::size_t i = 0; i < FlGui::instance()->selectedElements.size(); i++)
8249 elementTags.push_back(FlGui::instance()->selectedElements[i]->getNum());
8250 return selectionCode(ret);
8256 GMSH_API int gmsh::fltk::selectViews(std::vector<int> &viewTags)
8260 #if defined(HAVE_FLTK)
8262 char ret = FlGui::instance()->selectEntity(
ENT_ALL);
8263 if(!FlGui::available())
return 0;
8264 for(std::size_t i = 0; i < FlGui::instance()->selectedViews.size(); i++)
8265 viewTags.push_back(FlGui::instance()->selectedViews[i]->getTag());
8266 return selectionCode(ret);
8272 GMSH_API void gmsh::fltk::splitCurrentWindow(
const std::string &how,
8276 #if defined(HAVE_FLTK)
8279 FlGui::instance()->splitCurrentOpenglWindow(
'h', ratio);
8281 FlGui::instance()->splitCurrentOpenglWindow(
'v', ratio);
8283 FlGui::instance()->splitCurrentOpenglWindow(
'u');
8285 Msg::Error(
"Unknown window splitting method '%s'", how.c_str());
8290 GMSH_API void gmsh::fltk::setCurrentWindow(
const int windowIndex)
8293 #if defined(HAVE_FLTK)
8295 FlGui::instance()->setCurrentOpenglWindow(windowIndex);
8299 GMSH_API void gmsh::fltk::setStatusMessage(
const std::string &message,
8300 const bool graphics)
8303 #if defined(HAVE_FLTK)
8305 FlGui::instance()->setStatus(message, graphics);
8309 GMSH_API void gmsh::fltk::showContextWindow(
const int dim,
const int tag)
8312 #if defined(HAVE_FLTK)
8314 FlGui::instance()->showOnelabContext(dim, tag);
8318 GMSH_API void gmsh::fltk::openTreeItem(
const std::string &name)
8321 #if defined(HAVE_FLTK)
8323 FlGui::instance()->openTreeItem(name);
8327 GMSH_API void gmsh::fltk::closeTreeItem(
const std::string &name)
8330 #if defined(HAVE_FLTK)
8332 FlGui::instance()->closeTreeItem(name);
8338 GMSH_API void gmsh::parser::getNames(std::vector<std::string> &names,
8339 const std::string &search)
8342 #if defined(HAVE_PARSER)
8344 if(search.empty()) {
8351 if(std::regex_search(p.first, std::regex(search)))
8352 names.push_back(p.first);
8355 if(std::regex_search(p.first, std::regex(search)))
8356 names.push_back(p.first);
8367 GMSH_API void gmsh::parser::setNumber(
const std::string &name,
8368 const std::vector<double> &value)
8371 #if defined(HAVE_PARSER)
8373 s.list = (value.size() != 1);
8380 GMSH_API void gmsh::parser::getNumber(
const std::string &name,
8381 std::vector<double> &value)
8384 #if defined(HAVE_PARSER)
8391 GMSH_API void gmsh::parser::setString(
const std::string &name,
8392 const std::vector<std::string> &value)
8395 #if defined(HAVE_PARSER)
8402 GMSH_API void gmsh::parser::getString(
const std::string &name,
8403 std::vector<std::string> &value)
8406 #if defined(HAVE_PARSER)
8413 GMSH_API void gmsh::parser::clear(
const std::string &name)
8416 #if defined(HAVE_PARSER)
8441 #if defined(HAVE_PARSER)
8450 GMSH_API void gmsh::onelab::set(
const std::string &data,
8451 const std::string &format)
8454 #if defined(HAVE_ONELAB)
8455 if(format ==
"json") {
8457 Msg::Error(
"Could not parse json data '%s'", data.c_str());
8466 GMSH_API void gmsh::onelab::get(std::string &data,
const std::string &name,
8467 const std::string &format)
8470 #if defined(HAVE_ONELAB)
8473 if(format ==
"json")
8479 std::vector< ::onelab::number> ps;
8482 if(format ==
"json")
8483 data = ps[0].toJSON();
8485 data = ps[0].toChar();
8488 std::vector< ::onelab::string> ps2;
8491 if(format ==
"json")
8492 data = ps2[0].toJSON();
8494 data = ps2[0].toChar();
8503 GMSH_API void gmsh::onelab::getNames(std::vector<std::string> &names,
8504 const std::string &search)
8507 #if defined(HAVE_ONELAB)
8514 GMSH_API void gmsh::onelab::setNumber(
const std::string &name,
8515 const std::vector<double> &value)
8518 #if defined(HAVE_ONELAB)
8520 std::vector< ::onelab::number> ps;
8522 if(ps.size()) p = ps[0];
8530 GMSH_API void gmsh::onelab::getNumber(
const std::string &name,
8531 std::vector<double> &value)
8534 #if defined(HAVE_ONELAB)
8536 std::vector< ::onelab::number> ps;
8538 if(ps.size()) value = ps[0].getValues();
8544 GMSH_API void gmsh::onelab::setString(
const std::string &name,
8545 const std::vector<std::string> &value)
8548 #if defined(HAVE_ONELAB)
8550 std::vector< ::onelab::string> ps;
8552 if(ps.size()) p = ps[0];
8560 GMSH_API void gmsh::onelab::getString(
const std::string &name,
8561 std::vector<std::string> &value)
8564 #if defined(HAVE_ONELAB)
8566 std::vector< ::onelab::string> ps;
8568 if(ps.size()) value = ps[0].getValues();
8574 GMSH_API int gmsh::onelab::getChanged(
const std::string &name)
8577 #if defined(HAVE_ONELAB)
8578 return ::onelab::server::instance()->getChanged(name);
8585 GMSH_API void gmsh::onelab::setChanged(
const std::string &name,
const int value)
8588 #if defined(HAVE_ONELAB)
8595 GMSH_API void gmsh::onelab::clear(
const std::string &name)
8598 #if defined(HAVE_ONELAB)
8605 GMSH_API void gmsh::onelab::run(
const std::string &name,
8606 const std::string &command)
8609 #if defined(HAVE_ONELAB)
8616 GMSH_API void gmsh::logger::write(
const std::string &message,
8617 const std::string &level)
8620 if(level ==
"error")
8622 else if(level ==
"warning")
8636 #pragma omp critical
8637 _log.push_back(level +
": " + message);
8639 void get(std::vector<std::string> &log)
const { log =
_log; }
8642 GMSH_API void gmsh::logger::start()
8646 if(msg) {
Msg::Warning(
"Logger already started - ignoring"); }
8653 GMSH_API void gmsh::logger::get(std::vector<std::string> &log)
8657 if(msg) { msg->
get(log); }
8676 GMSH_API double gmsh::logger::getWallTime()
8682 GMSH_API double gmsh::logger::getCpuTime()
8688 GMSH_API void gmsh::logger::getLastError(std::string &error)