gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
|
Go to the documentation of this file.
9 #include "GmshConfig.h"
22 #if defined(HAVE_MESH)
27 :
GEntity(model, tag), _length(0.), _tooSmall(false), _cp(nullptr), _v0(v0),
28 _v1(v1), masterOrientation(0), compoundCurve(nullptr)
37 :
GEntity(model, tag), _length(0.), _tooSmall(false), _cp(nullptr),
38 _v0(nullptr), _v1(nullptr), masterOrientation(0), compoundCurve(nullptr)
57 for(std::size_t i = 0; i <
lines.size(); i++)
delete lines[i];
112 if((d00.
norm() < tol) && (d11.
norm() < tol)) {
122 if((d01.
norm() < tol) && (d10.
norm() < tol)) {
132 Msg::Info(
"Error in transformation from curve %d (%d-%d) to %d (%d-%d) "
133 "(minimal transformed node distances %g %g, tolerance %g)",
135 this->tag(), this->getBeginVertex()->tag(),
136 this->getEndVertex()->tag(), fwd ? d00.
norm() : d01.
norm(),
137 fwd ? d11.
norm() : d10.
norm(), tol);
145 for(
auto l :
lines) l->reverse();
158 return line->ownsParent();
169 if(
lines.empty())
return nullptr;
180 const std::size_t index)
const
218 const int N = fast ? 3 : 10;
219 for(
int i = 0; i < N; i++) {
221 tr.
low() + (double)i / (
double)(N - 1) * (tr.
high() - tr.
low());
240 for(
int i = 0; i < N; i++) {
260 for(
int i = 0; i < N; i++) {
262 tr.
low() + (double)i / (
double)(N - 1) * (tr.
high() - tr.
low());
297 std::ostringstream sstream;
298 sstream.precision(12);
301 sstream <<
"Boundary points: " <<
_v0->
tag() <<
", " <<
_v1->
tag();
304 sstream <<
" (distance = " << p0.
distance(p1) <<
")";
312 sstream <<
"On boundary of surfaces: ";
313 for(
auto it =
_faces.begin(); it !=
_faces.end(); ++it) {
314 if(it !=
_faces.begin()) sstream <<
", ";
315 sstream << (*it)->tag();
327 sstream <<
"Mesh attributes:";
331 if(std::abs(type) == 1)
332 sstream <<
", progression "
334 else if(std::abs(type) == 2)
336 else if(std::abs(type) == 3)
338 else if(std::abs(type) == 4)
342 sstream <<
" extruded";
348 std::string str = sstream.str();
349 if(str.size() && (str[str.size() - 1] ==
'\n' || str[str.size() - 1] ==
' '))
350 str.resize(str.size() - 1);
367 double umin =
bounds.low();
368 double umax =
bounds.high();
369 fprintf(fp,
"p%d = newp;\n",
tag());
371 for(
int i = 1; i < N; i++) {
372 double u = umin + (double)i / N * (umax - umin);
374 fprintf(fp,
"Point(p%d + %d) = {%.16g, %.16g, %.16g};\n",
tag(), i, p.
x(),
378 for(
int i = 1; i < N; i++) fprintf(fp,
", p%d + %d",
tag(), i);
383 fprintf(fp,
"Transfinite Line {%d} = %d",
388 fprintf(fp,
" Using Progression ");
390 fprintf(fp,
" Using Bump ");
392 fprintf(fp,
" Using Beta ");
394 fprintf(fp,
" Using Sizemap ");
396 fprintf(fp,
" Using Unknown ");
417 fprintf(fp,
"gmsh.model.%s.addLine(%d, %d, %d)\n", factory,
449 if(!
XYZToU(pt.
x(), pt.
y(), pt.
z(), t, 1,
false))
return false;
457 return (pt >= rg.
low() && pt <= rg.
high());
465 const double eps = 1.e-3;
467 if(par - eps <= rg.
low()) {
470 return 1000 * (x2 - x1);
472 else if(par + eps >= rg.
high()) {
475 return 1000 * (x2 - x1);
479 return 500 * (x2 - x1);
500 double GEdge::length(
const double &u0,
const double &u1,
const int nbQuadPoints)
504 double *t =
nullptr, *w =
nullptr;
507 Msg::Error(
"Gauss-Legendre integration returned no points");
511 const double rapJ = (u1 - u0) * 0.5;
512 for(
int i = 0; i < nbQuadPoints; i++) {
513 const double ui = u0 * 0.5 * (1. - t[i]) + u1 * 0.5 * (1. + t[i]);
515 const double d =
norm(der);
516 L += d * w[i] * rapJ;
526 const double GOLDEN = (1.0 + std::sqrt(5.0)) / 2.0;
533 double x2,
double x3,
double tau)
536 double x4 = x2 +
GOLDEN2 * (x3 - x2);
539 if(std::abs(x3 - x1) < tau * (std::abs(x2) + std::abs(x4)))
540 return (x3 + x1) / 2;
545 const double d4 = dp4.
norm();
546 const double d2 = dp2.
norm();
559 const int nbSamples = 100;
563 double tMin = std::min(interval.
high(), interval.
low());
564 double tMax = std::max(interval.
high(), interval.
low());
568 const double DT = (
tMax -
tMin) / (nbSamples - 1.);
569 for(
int i = 0; i < nbSamples; i++) {
572 const double D = dp.
norm();
583 else if(topt ==
tMax)
605 double relax,
double tol,
double &err)
const
615 double uMin = uu.
low();
616 double uMax = uu.
high();
620 while(iter++ < MaxIter && err > maxDist) {
622 double du =
dot(dPQ, der) /
dot(der, der);
624 if(du < tol && dPQ.
norm() > maxDist) du = 1;
628 double uNew = u - relax * du;
629 uNew = std::min(uMax, std::max(uMin, uNew));
637 return err <= maxDist;
640 bool GEdge::XYZToU(
const double X,
const double Y,
const double Z,
double &u,
641 const double relax,
bool first)
const
645 const int MaxIter = 25;
646 const int NumInitGuess = 21;
648 std::map<double, double> errorVsParameter;
654 double uMin = uu.
low();
655 double uMax = uu.
high();
661 for(
int i = 0; i < NumInitGuess; i++) {
662 uTry = uMin + (uMax - uMin) / (NumInitGuess - 1) * i;
667 errorVsParameter[err] = uTry;
671 if(
XYZToU(X, Y, Z, uTry, 0.75 * relax,
false)) {
677 errorVsParameter[dPQ.
norm()] = uTry;
680 u = errorVsParameter.begin()->second;
683 "Could not converge parametrisation of (%g,%g,%g) on curve %d, "
684 "taking parameter with lowest error",
695 std::set<GRegion *> _r;
696 for(
auto it =
_faces.begin(); it !=
_faces.end(); ++it) {
697 std::list<GRegion *> temp = (*it)->regions();
698 _r.insert(temp.begin(), temp.end());
700 std::list<GRegion *> ret;
701 ret.insert(ret.begin(), _r.begin(), _r.end());
707 if(
model()->getNumRegions())
709 else if(
model()->getNumFaces())
710 return faces().empty();
750 double dt2 = std::max(0., std::max(-
dot(d, d0),
dot(d, d1)));
752 return (dt2 + dn2) / d.
normSq();
758 const int pos1 = upts[pos0].next;
759 const SPoint3 &p0 = upts[pos0].p;
760 const double t0 = upts[pos0].t;
761 const SPoint3 &p1 = upts[pos1].p;
762 const double t1 = upts[pos1].t;
763 const double tmid = 0.5 * (t0 + t1);
766 if(d2 < tol * tol)
return;
769 const int posmid = upts.size() - 1;
770 upts[pos0].next = posmid;
780 Msg::Error(
"Trying to add unsupported element in curve %d",
tag());
793 Msg::Error(
"Trying to remove unsupported element in curve %d",
tag());
802 Msg::Error(
"Trying to remove unsupported elements in curve %d",
tag());
807 std::vector<double> &ts)
809 std::vector<sortedPoint> upts;
812 upts.push_back(pnt1);
816 upts.push_back(pnt2);
820 dpts.reserve(upts.size());
822 ts.reserve(upts.size());
823 for(
int p = 0; p != -1; p = upts[p].next) {
824 dpts.push_back(upts[p].p);
825 ts.push_back(upts[p].t);
829 #if defined(HAVE_MESH)
831 static bool recreateConsecutiveElements(
GEdge *ge)
833 std::size_t ss = ge->
lines.size();
836 std::vector<MEdge> ed;
837 std::vector<std::vector<MVertex *> > vs;
838 for(std::size_t i = 0; i < ge->
lines.size(); i++) {
839 ed.push_back(
MEdge(ge->
lines[i]->getVertex(0), ge->
lines[i]->getVertex(1)));
844 Msg::Warning(
"Line elements on curve %d cannot be ordered", ge->
tag());
849 std::size_t start = 0;
850 for(; start < vs[0].size(); start++)
851 if(vs[0][start]->onWhat()->dim() == 0)
break;
853 if(start == vs[0].size())
856 std::size_t i = start;
857 while(ge->
lines.size() != ss) {
858 if(vs[0][i % vs[0].size()] != vs[0][(i + 1) % vs[0].size()])
860 new MLine(vs[0][i % vs[0].size()], vs[0][(i + 1) % vs[0].size()]));
865 for(std::size_t i = 0; i < ge->
lines.size() - 1; ++i) {
876 static void meshCompound(
GEdge *ge)
895 std::vector<int> phys;
896 for(std::size_t i = 0; i < ge->
compound.size(); i++) {
898 de->
lines.insert(de->
lines.end(),
c->lines.begin(),
c->lines.end());
899 c->compoundCurve = de;
900 phys.insert(phys.end(),
c->physicals.begin(),
c->physicals.end());
901 c->physicals.clear();
905 recreateConsecutiveElements(de);
909 for(std::size_t i = 0; i < de->
lines.size(); i++)
delete de->
lines[i];
920 #if defined(HAVE_MESH)
932 for(std::size_t i = 0; i <
compound.size(); i++) {
948 const std::vector<std::size_t> &ordering)
950 if(
lines.size() != 0) {
951 if(
lines.front()->getTypeForMSH() != elementType) {
return false; }
953 if(ordering.size() !=
lines.size())
return false;
955 for(
auto it = ordering.begin(); it != ordering.end(); ++it) {
956 if(*it >=
lines.size())
return false;
959 std::vector<MLine *> newLinesOrder(
lines.size());
960 for(std::size_t i = 0; i < ordering.size(); i++) {
961 newLinesOrder[i] =
lines[ordering[i]];
964 lines = std::move(newLinesOrder);
973 std::vector<GVertex *> res;
982 const auto &it = std::lower_bound(
_u_lc.begin(),
_u_lc.end(), u);
983 size_t i1 = std::min<size_t>(it -
_u_lc.begin(),
_u_lc.size() - 1);
984 size_t i0 = std::max<size_t>(1, i1) - 1;
986 double l0 =
_lc[i0], l1 =
_lc[i1];
987 if(i1 == i0 || u0 == u1)
return l0;
988 double alpha = (u - u0) / (u1 - u0);
989 return l0 * (1 - alpha) + l1 * (alpha);
993 const std::vector<double> &
v;
999 const std::vector<double> lc)
1001 if(u.size() != lc.size()) {
1002 Msg::Error(
"setMeshSizeParametric : number of coordinates and number of "
1003 "mesh size do not match.");
1005 std::vector<size_t> index(u.size());
1006 for(
size_t i = 0; i < u.size(); ++i) index[i] = i;
1007 std::sort(index.begin(), index.end(),
vindexsort(u));
1008 _u_lc.resize(u.size());
1009 _lc.resize(lc.size());
1010 for(
size_t i = 0; i < u.size(); ++i) {
1011 _u_lc[i] = u[index[i]];
1012 _lc[i] = lc[index[i]];
SVector3 crossprod(const SVector3 &a, const SVector3 &b)
MElement *const * getStartElementType(int type) const
void setMeshMaster(GEdge *master, const std::vector< double > &)
virtual void setVisibility(char val, bool recursive=false)
virtual std::list< GRegion * > regions() const
void gmshGaussLegendre1D(int nbQuadPoints, double **t, double **w)
bool operator()(size_t i0, size_t i1)
int gmsh_sign(T const &value)
MElement * getMeshElement(std::size_t index) const
virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const
double dot(const SVector3 &a, const SMetric3 &m, const SVector3 &b)
std::map< MVertex *, MVertex * > correspondingHighOrderVertices
void setMeshSizeParametric(const std::vector< double > u, const std::vector< double > lc)
MVertex * getMeshVertex(std::size_t index)
virtual void resetMeshAttributes()
static void Info(const char *fmt,...)
std::vector< MLine * > lines
virtual int minimumDrawSegments() const
std::vector< GFace * > _faces
static double c(int i, int j, fullMatrix< double > &CA, const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
SOrientedBoundingBox * _obb
static void Warning(const char *fmt,...)
static void Error(const char *fmt,...)
std::vector< int > physicals
void f(int n, double u, double *val)
virtual bool XYZToU(const double X, const double Y, const double Z, double &U, const double relax=1, bool first=true) const
virtual void writeGEO(FILE *fp)
virtual ModelType getNativeType() const
void addLine(MLine *line)
GEdge * getEdgeByTag(int n) const
double prescribedMeshSizeAtParam(double u)
std::size_t getNumMeshVertices()
GEntity * getMeshMaster() const
virtual std::size_t getNumVertices() const =0
virtual void discretize(double tol, std::vector< SPoint3 > &dpts, std::vector< double > &ts)
std::size_t getNumMeshParentElements()
virtual void setColor(unsigned color, bool recursive=false)
virtual void setVisibility(char val, bool recursive=false)
virtual std::string getAdditionalInfoString(bool multline=false)
static void _discretize(double tol, GEdge *edge, std::vector< sortedPoint > &upts, int pos0)
vindexsort(const std::vector< double > &vp)
virtual const MVertex * getVertex(int num) const =0
const std::vector< double > & v
std::size_t getNumMeshElementsByType(const int familyType) const
bool SortEdgeConsecutive(const std::vector< MEdge > &e, std::vector< std::vector< MVertex * > > &vs)
virtual void delFace(GFace *f)
virtual SVector3 firstDer(double par) const =0
virtual SOrientedBoundingBox getOBB()
std::vector< MVertex * > mesh_vertices
#define MESH_UNSTRUCTURED
void norm(const double *vec, double *norm)
virtual GVertex * getBeginVertex() const
virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true, bool convTestXYZ=false) const
virtual GeomType geomType() const
SPoint3 closestPointWithTol(SPoint3 &p, double tolerance)
struct GEdge::@16 meshAttributes
virtual bool refineProjection(const SVector3 &Q, double &u, int MaxIter, double relax, double tol, double &err) const
std::vector< GEntity * > compound
virtual double tolerance() const
virtual SVector3 position(double p) const
virtual void writePY(FILE *fp)
contextGeometryOptions geom
std::vector< SPoint3 > stl_vertices_xyz
virtual std::vector< GVertex * > vertices() const
virtual std::vector< GFace * > faces() const
virtual double curvature(double par) const
std::vector< double > _u_lc
virtual bool containsPoint(const SPoint3 &pt) const
double goldenSectionSearch(const GEdge *ge, const SPoint3 &q, double x1, double x2, double x3, double tau)
GEntity::MeshGenerationStatus status
virtual bool getParameter(int i, double &par) const
virtual SBoundingBox3d bounds(bool fast=false)
struct GEdge::@17 meshStatistics
virtual GPoint closestPoint(const SPoint3 &queryPoint, double ¶m) const
virtual bool reorder(const int elementType, const std::vector< std::size_t > &ordering)
virtual Range< double > parBounds(int i) const =0
virtual bool containsParam(double pt) const
virtual SPoint3 xyz() const
virtual GPoint point(double p) const =0
virtual void deleteMesh()
void relocateMeshVertices()
virtual void mesh(bool verbose)
static SOrientedBoundingBox * buildOBB(std::vector< SPoint3 > &vertices)
void setMeshMaster(GEntity *)
static double sqDistPointSegment(const SPoint3 &p, const SPoint3 &s0, const SPoint3 &s1)
std::map< GVertex *, GVertex * > vertexCounterparts
void removeElement(int type, MElement *e)
virtual void setColor(unsigned int val, bool recursive=false)
std::size_t getNumMeshElements() const
double distance(GPoint &p)
MElement * getMeshElementByType(const int familyType, const std::size_t index) const
virtual GVertex * getEndVertex() const
std::vector< double > _lc
virtual GPoint point() const =0
virtual SVector3 secondDer(double par) const
void addElement(int type, MElement *e)
GEdge(GModel *model, int tag, GVertex *v0, GVertex *v1)
void setEntity(GEntity *ge)
std::map< MVertex *, MVertex * > correspondingVertices
virtual double parFromPoint(const SPoint3 &P) const
void deleteVertexArrays()
bool transform(const std::vector< double > &tfo)
virtual void mesh(bool verbose)
void removeElements(int type)