diff --git a/Geo/ACISEdge.cpp b/Geo/ACISEdge.cpp index 32103a03afa94fdfb6ad41f6aa24d68ba989d298..c29c892c00be170de7841daf6f8bcb97c67496b1 100644 --- a/Geo/ACISEdge.cpp +++ b/Geo/ACISEdge.cpp @@ -21,160 +21,175 @@ #include <loop.hxx> #include <surdef.hxx> -GEdge *getACISEdgeByNativePtr(GModel *model, EDGE * toFind) +GEdge *getACISEdgeByNativePtr(GModel *model, EDGE *toFind) { - GModel::eiter it =model->firstEdge(); - for (; it !=model->lastEdge(); it++){ - ACISEdge *ed = dynamic_cast<ACISEdge*>(*it); - if (ed){ - if (toFind == ed->getEDGE()){ - return *it; + GModel::eiter it = model->firstEdge(); + for(; it != model->lastEdge(); it++) { + ACISEdge *ed = dynamic_cast<ACISEdge *>(*it); + if(ed) { + if(toFind == ed->getEDGE()) { + return *it; } } } return 0; } -ACISEdge::ACISEdge(GModel *model, EDGE* edge, int num, GVertex *v1, GVertex *v2) +ACISEdge::ACISEdge(GModel *model, EDGE *edge, int num, GVertex *v1, GVertex *v2) : GEdge(model, num, v1, v2), _e(edge) { CURVE *_cur = _e->geometry(); - // SPAinterval interval=_cur->equation().param_range(); - SPAinterval interval=_e->param_range(); + // SPAinterval interval=_cur->equation().param_range(); + SPAinterval interval = _e->param_range(); s0 = interval.start_pt(); s1 = interval.end_pt(); - if (_cur->equation().periodic()){ + if(_cur->equation().periodic()) { // s0 += _cur->equation().param_period()/2; // s1 += _cur->equation().param_period()/2; } - Msg::Info("ACIS Edge %d is %s goes from %g to %g",tag(),getTypeString().c_str(),s0,s1); + Msg::Info("ACIS Edge %d is %s goes from %g to %g", tag(), + getTypeString().c_str(), s0, s1); } -Range<double> ACISEdge::parBounds(int i) const -{ - return Range<double>(s0, s1); -} +Range<double> ACISEdge::parBounds(int i) const { return Range<double>(s0, s1); } SPoint2 ACISEdge::reparamOnFace(const GFace *face, double epar, int dir) const { CURVE *c = _e->geometry(); SPAposition vpos = c->equation().eval_position(epar); - SPApar_pos fpar = ((FACE*)(face->getNativePtr()))->geometry()->equation().param(vpos); + SPApar_pos fpar = + ((FACE *)(face->getNativePtr()))->geometry()->equation().param(vpos); SPoint2 pt2(fpar.u, fpar.v); face->moveToValidRange(pt2); return pt2; } -GPoint ACISEdge::closestPoint(const SPoint3 &qp, double ¶m) const -{ - throw; -} +GPoint ACISEdge::closestPoint(const SPoint3 &qp, double ¶m) const { throw; } // True if the edge is a seam for the given face bool ACISEdge::isSeam(const GFace *face) const { CURVE *_cur = _e->geometry(); - if (!(((FACE*)face->getNativePtr())->geometry()->equation().periodic_u()) && - !(((FACE*)face->getNativePtr())->geometry()->equation().periodic_v())) + if(!(((FACE *)face->getNativePtr())->geometry()->equation().periodic_u()) && + !(((FACE *)face->getNativePtr())->geometry()->equation().periodic_v())) + return 0; + else if((((FACE *)face->getNativePtr()) + ->geometry() + ->equation() + .periodic_u()) && + !(((FACE *)face->getNativePtr()) + ->geometry() + ->equation() + .periodic_v())) { + SPAinterval cur_rang = _cur->equation().param_range(); + SPAinterval sur_rang_u = + ((FACE *)face->getNativePtr())->geometry()->equation().param_range_u(); + SPAposition p1, p2; + p1 = _cur->equation().eval_position(cur_rang.start_pt()); + p2 = _cur->equation().eval_position(cur_rang.end_pt()); + SPApar_pos p1_par, p2_par; + p1_par = ((FACE *)face->getNativePtr())->geometry()->equation().param(p1); + p2_par = ((FACE *)face->getNativePtr())->geometry()->equation().param(p2); + + if(((p1_par.u == sur_rang_u.start_pt() || + p1_par.u == sur_rang_u.end_pt()) && + (p2_par.u == sur_rang_u.start_pt() || p2_par.u == sur_rang_u.end_pt()))) + return 1; + else return 0; - else if ( (((FACE*)face->getNativePtr())->geometry()->equation().periodic_u()) && - !(((FACE*)face->getNativePtr())->geometry()->equation().periodic_v())) - { - SPAinterval cur_rang = _cur->equation().param_range(); - SPAinterval sur_rang_u = - ((FACE*)face->getNativePtr())->geometry()->equation().param_range_u(); - SPAposition p1, p2; - p1 = _cur->equation().eval_position(cur_rang.start_pt()); - p2 = _cur->equation().eval_position(cur_rang.end_pt()); - SPApar_pos p1_par, p2_par; - p1_par = ((FACE*)face->getNativePtr())->geometry()->equation().param(p1); - p2_par = ((FACE*)face->getNativePtr())->geometry()->equation().param(p2); - - if(((p1_par.u == sur_rang_u.start_pt() || p1_par.u == sur_rang_u.end_pt()) && - (p2_par.u == sur_rang_u.start_pt() || p2_par.u == sur_rang_u.end_pt()))) - return 1; - else - return 0; } - else if (!(((FACE*)face->getNativePtr())->geometry()->equation().periodic_u()) && - (((FACE*)face->getNativePtr())->geometry()->equation().periodic_v())) - { - SPAinterval cur_rang = _cur->equation().param_range(); - SPAinterval sur_rang_v = - ((FACE*)face->getNativePtr())->geometry()->equation().param_range_v(); - SPAposition p1, p2; - p1 = _cur->equation().eval_position(cur_rang.start_pt()); - p2 = _cur->equation().eval_position(cur_rang.end_pt()); - SPApar_pos p1_par, p2_par; - p1_par = ((FACE*)face->getNativePtr())->geometry()->equation().param(p1); - p2_par = ((FACE*)face->getNativePtr())->geometry()->equation().param(p2); - - if(((p1_par.v == sur_rang_v.start_pt() || p1_par.v == sur_rang_v.end_pt()) && - (p2_par.v == sur_rang_v.start_pt() || p2_par.v == sur_rang_v.end_pt())) ) - return 1; - else - return 0; + else if(!(((FACE *)face->getNativePtr()) + ->geometry() + ->equation() + .periodic_u()) && + (((FACE *)face->getNativePtr()) + ->geometry() + ->equation() + .periodic_v())) { + SPAinterval cur_rang = _cur->equation().param_range(); + SPAinterval sur_rang_v = + ((FACE *)face->getNativePtr())->geometry()->equation().param_range_v(); + SPAposition p1, p2; + p1 = _cur->equation().eval_position(cur_rang.start_pt()); + p2 = _cur->equation().eval_position(cur_rang.end_pt()); + SPApar_pos p1_par, p2_par; + p1_par = ((FACE *)face->getNativePtr())->geometry()->equation().param(p1); + p2_par = ((FACE *)face->getNativePtr())->geometry()->equation().param(p2); + + if(((p1_par.v == sur_rang_v.start_pt() || + p1_par.v == sur_rang_v.end_pt()) && + (p2_par.v == sur_rang_v.start_pt() || p2_par.v == sur_rang_v.end_pt()))) + return 1; + else + return 0; } - else if ((((FACE*)face->getNativePtr())->geometry()->equation().periodic_u()) && - (((FACE*)face->getNativePtr())->geometry()->equation().periodic_v())) - { - SPAinterval cur_rang = _cur->equation().param_range(); - SPAinterval sur_rang_u = - ((FACE*)face->getNativePtr())->geometry()->equation().param_range_u(); - SPAinterval sur_rang_v = - ((FACE*)face->getNativePtr())->geometry()->equation().param_range_v(); - SPAposition p1, p2; - p1 = _cur->equation().eval_position(cur_rang.start_pt()); - p2 = _cur->equation().eval_position(cur_rang.end_pt()); - SPApar_pos p1_par, p2_par; - p1_par = ((FACE*)face->getNativePtr())->geometry()->equation().param(p1); - p2_par = ((FACE*)face->getNativePtr())->geometry()->equation().param(p2); - - if ( ((p1_par.u == sur_rang_u.start_pt() || p1_par.u == sur_rang_u.end_pt()) && - (p2_par.u == sur_rang_u.start_pt() || p2_par.u == sur_rang_u.end_pt())) || - ((p1_par.v == sur_rang_v.start_pt() || p1_par.v == sur_rang_v.end_pt()) && - (p2_par.v == sur_rang_v.start_pt() || p2_par.v == sur_rang_v.end_pt())) ) - return 1; - else - return 0; + else if((((FACE *)face->getNativePtr()) + ->geometry() + ->equation() + .periodic_u()) && + (((FACE *)face->getNativePtr()) + ->geometry() + ->equation() + .periodic_v())) { + SPAinterval cur_rang = _cur->equation().param_range(); + SPAinterval sur_rang_u = + ((FACE *)face->getNativePtr())->geometry()->equation().param_range_u(); + SPAinterval sur_rang_v = + ((FACE *)face->getNativePtr())->geometry()->equation().param_range_v(); + SPAposition p1, p2; + p1 = _cur->equation().eval_position(cur_rang.start_pt()); + p2 = _cur->equation().eval_position(cur_rang.end_pt()); + SPApar_pos p1_par, p2_par; + p1_par = ((FACE *)face->getNativePtr())->geometry()->equation().param(p1); + p2_par = ((FACE *)face->getNativePtr())->geometry()->equation().param(p2); + + if(((p1_par.u == sur_rang_u.start_pt() || + p1_par.u == sur_rang_u.end_pt()) && + (p2_par.u == sur_rang_u.start_pt() || + p2_par.u == sur_rang_u.end_pt())) || + ((p1_par.v == sur_rang_v.start_pt() || + p1_par.v == sur_rang_v.end_pt()) && + (p2_par.v == sur_rang_v.start_pt() || p2_par.v == sur_rang_v.end_pt()))) + return 1; + else + return 0; } } -bool ACISEdge::degenerate(int) const -{ - return _e->length() == 0.0; -} +bool ACISEdge::degenerate(int) const { return _e->length() == 0.0; } GPoint ACISEdge::point(double par) const { CURVE *c = _e->geometry(); const curve &equ = c->equation(); - if (&equ){ + if(&equ) { SPAposition pos; - equ.eval(par,pos); - return GPoint(pos.coordinate(0),pos.coordinate(1),pos.coordinate(2),this,par); + equ.eval(par, pos); + return GPoint(pos.coordinate(0), pos.coordinate(1), pos.coordinate(2), this, + par); } Msg::Error("Unable to evaluate a point on a curve"); - return GPoint(0,0,0,this,par); + return GPoint(0, 0, 0, this, par); } SVector3 ACISEdge::firstDer(double par) const -{ +{ CURVE *c = _e->geometry(); const curve &equ = c->equation(); SPAvector first_deriv; SPAposition pos; - equ.eval (par, pos,first_deriv); - return SVector3(first_deriv.component(0),first_deriv.component(1),first_deriv.component(2)); + equ.eval(par, pos, first_deriv); + return SVector3(first_deriv.component(0), first_deriv.component(1), + first_deriv.component(2)); } GEntity::GeomType ACISEdge::geomType() const { CURVE *c = _e->geometry(); - if (!strcmp(c->type_name(),"circle"))return Circle; - if (!strcmp(c->type_name(),"straight"))return Line; - if (!strcmp(c->type_name(),"ellipse"))return Ellipse; - if (!strcmp(c->type_name(),"bezier"))return Bezier; + if(!strcmp(c->type_name(), "circle")) return Circle; + if(!strcmp(c->type_name(), "straight")) return Line; + if(!strcmp(c->type_name(), "ellipse")) return Ellipse; + if(!strcmp(c->type_name(), "bezier")) return Bezier; return Unknown; } @@ -183,13 +198,13 @@ int ACISEdge::minimumMeshSegments() const int np; if(geomType() == Line) np = GEdge::minimumMeshSegments(); - else + else np = CTX::instance()->mesh.minCurvPoints - 1; - + // if the edge is closed, ensure that at least 3 points are // generated in the 1D mesh (4 segments, one of which is // degenerated) - if (getBeginVertex() == getEndVertex()) np = std::max(4, np); + if(getBeginVertex() == getEndVertex()) np = std::max(4, np); return std::max(np, meshAttributes.minimumMeshSegments); } @@ -202,14 +217,12 @@ int ACISEdge::minimumDrawSegments() const return CTX::instance()->geom.numSubEdges * GEdge::minimumDrawSegments(); } -double ACISEdge::curvature(double par) const +double ACISEdge::curvature(double par) const { const double Crv = 1.e-15; return Crv; } -void ACISEdge::writeGEO(FILE *fp) -{ -} +void ACISEdge::writeGEO(FILE *fp) {} #endif diff --git a/Geo/ACISEdge.h b/Geo/ACISEdge.h index c74d237db51884c4b7b1a2b607757ae0ad416b71..2ca171548e8696aff00ed8421f4e1023dfc6443f 100644 --- a/Geo/ACISEdge.h +++ b/Geo/ACISEdge.h @@ -22,7 +22,8 @@ class ACISFace; class ACISEdge : public GEdge { EDGE *_e; double s0, s1; - public: + +public: ACISEdge(GModel *model, EDGE *e, int num, GVertex *v1, GVertex *v2); virtual ~ACISEdge() {} virtual Range<double> parBounds(int i) const; @@ -30,16 +31,16 @@ class ACISEdge : public GEdge { virtual bool degenerate(int) const; virtual GPoint point(double p) const; virtual SVector3 firstDer(double par) const; - virtual double curvature (double par) const; + virtual double curvature(double par) const; virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const; virtual GPoint closestPoint(const SPoint3 &queryPoint, double ¶m) const; ModelType getNativeType() const { return AcisModel; } - void * getNativePtr() const { return (void*)_e; } - virtual int minimumMeshSegments () const; - virtual int minimumDrawSegments () const; + void *getNativePtr() const { return (void *)_e; } + virtual int minimumMeshSegments() const; + virtual int minimumDrawSegments() const; bool isSeam(const GFace *) const; virtual void writeGEO(FILE *fp); - EDGE* getEDGE() const {return _e;} + EDGE *getEDGE() const { return _e; } }; GEdge *getACISEdgeByNativePtr(GModel *model, EDGE *toFind); diff --git a/Geo/ACISFace.cpp b/Geo/ACISFace.cpp index 1823549de68e1dcc7b684d08fdb9e1e2561a1cca..e5756f84b7d875d060228dabb4cf20a99c43410b 100644 --- a/Geo/ACISFace.cpp +++ b/Geo/ACISFace.cpp @@ -24,44 +24,43 @@ #include <kernapi.hxx> #include <af_api.hxx> -ACISFace::ACISFace(GModel *m, FACE *f, int num) - : GFace(m, num), _f(f) +ACISFace::ACISFace(GModel *m, FACE *f, int num) : GFace(m, num), _f(f) { edgeLoops.clear(); l_edges.clear(); l_dirs.clear(); LOOP *myLoop = _f->loop(); - do{ - std::list<GEdge*> l_wire; + do { + std::list<GEdge *> l_wire; COEDGE *start = myLoop->start(); - COEDGE *_current = start; + COEDGE *_current = start; do { EDGE *e = _current->edge(); - GEdge *ge = getACISEdgeByNativePtr(m,e); + GEdge *ge = getACISEdgeByNativePtr(m, e); l_wire.push_back(ge); _current = _current->next(); - }while (_current && _current != start); + } while(_current && _current != start); GEdgeLoop el(l_wire); - for(GEdgeLoop::citer it = el.begin(); it != el.end(); ++it){ + for(GEdgeLoop::citer it = el.begin(); it != el.end(); ++it) { l_edges.push_back(it->ge); l_dirs.push_back(it->_sign); - if (el.count() == 2){ + if(el.count() == 2) { it->ge->meshAttributes.minimumMeshSegments = - std::max(it->ge->meshAttributes.minimumMeshSegments,2); + std::max(it->ge->meshAttributes.minimumMeshSegments, 2); } - if (el.count() == 1){ + if(el.count() == 1) { it->ge->meshAttributes.minimumMeshSegments = - std::max(it->ge->meshAttributes.minimumMeshSegments,3); + std::max(it->ge->meshAttributes.minimumMeshSegments, 3); } } edgeLoops.push_back(el); - }while (myLoop = myLoop->next()); + } while(myLoop = myLoop->next()); SURFACE *Surf = _f->geometry(); const surface &surf = Surf->equation(); - SPAinterval _u,_v; + SPAinterval _u, _v; _u = surf.param_range_u(); _v = surf.param_range_v(); @@ -71,8 +70,8 @@ ACISFace::ACISFace(GModel *m, FACE *f, int num) vmin = _v.start_pt(); vmax = _v.end_pt(); - if ( surf.closed_u() || surf.closed_v() ) { - printf("%d %g %g -- %g %g\n",tag(),umin,umax,vmin,vmax); + if(surf.closed_u() || surf.closed_v()) { + printf("%d %g %g -- %g %g\n", tag(), umin, umax, vmin, vmax); } _periodic[0] = surf.periodic_u(); @@ -88,8 +87,7 @@ ACISFace::ACISFace(GModel *m, FACE *f, int num) Range<double> ACISFace::parBounds(int i) const { - if(i == 0) - return Range<double>(umin, umax); + if(i == 0) return Range<double>(umin, umax); return Range<double>(vmin, vmax); } @@ -98,26 +96,26 @@ SVector3 ACISFace::normal(const SPoint2 ¶m) const SURFACE *Surf = _f->geometry(); const surface &surf = Surf->equation(); - const SPAunit_vector n = surf.eval_normal (SPApar_pos (param.x(),param.y())); - return SVector3(n.component(0),n.component(1),n.component(2)); + const SPAunit_vector n = surf.eval_normal(SPApar_pos(param.x(), param.y())); + return SVector3(n.component(0), n.component(1), n.component(2)); } -Pair<SVector3,SVector3> ACISFace::firstDer(const SPoint2 ¶m) const +Pair<SVector3, SVector3> ACISFace::firstDer(const SPoint2 ¶m) const { SURFACE *Surf = _f->geometry(); const surface &surf = Surf->equation(); SPAposition pos; SPAvector first_derivs[2]; - surf.eval (SPApar_pos(param.x(),param.y()), pos,first_derivs); - return Pair<SVector3,SVector3> - (SVector3(first_derivs[0].component(0), first_derivs[0].component(1), - first_derivs[0].component(2)), - SVector3(first_derivs[1].component(0), first_derivs[1].component(1), - first_derivs[1].component(2))); + surf.eval(SPApar_pos(param.x(), param.y()), pos, first_derivs); + return Pair<SVector3, SVector3>( + SVector3(first_derivs[0].component(0), first_derivs[0].component(1), + first_derivs[0].component(2)), + SVector3(first_derivs[1].component(0), first_derivs[1].component(1), + first_derivs[1].component(2))); } -void ACISFace::secondDer(const SPoint2 ¶m, - SVector3 &dudu, SVector3 &dvdv, SVector3 &dudv) const +void ACISFace::secondDer(const SPoint2 ¶m, SVector3 &dudu, SVector3 &dvdv, + SVector3 &dudv) const { SURFACE *Surf = _f->geometry(); const surface &surf = Surf->equation(); @@ -128,79 +126,77 @@ GPoint ACISFace::point(double par1, double par2) const SURFACE *Surf = _f->geometry(); const surface &surf = Surf->equation(); SPAposition pos; - surf.eval (SPApar_pos(par1,par2), pos); - double pp[2] = {par1,par2}; - return GPoint(pos.coordinate(0),pos.coordinate(1),pos.coordinate(2),this,pp); + surf.eval(SPApar_pos(par1, par2), pos); + double pp[2] = {par1, par2}; + return GPoint(pos.coordinate(0), pos.coordinate(1), pos.coordinate(2), this, + pp); } -GPoint ACISFace::closestPoint(const SPoint3 &qp, const double initialGuess[2]) const +GPoint ACISFace::closestPoint(const SPoint3 &qp, + const double initialGuess[2]) const { - SPAposition pt(qp.x(),qp.y(),qp.z()); + SPAposition pt(qp.x(), qp.y(), qp.z()); SPAposition fpt; SPApar_pos ppt; SURFACE *Surf = _f->geometry(); - Surf->equation().point_perp(pt,fpt,*(SPApar_pos *)NULL_REF,ppt); - SPoint2 pt2(ppt.u,ppt.v); + Surf->equation().point_perp(pt, fpt, *(SPApar_pos *)NULL_REF, ppt); + SPoint2 pt2(ppt.u, ppt.v); - return GPoint(fpt.x(),fpt.y(),fpt.z(),this,pt2); + return GPoint(fpt.x(), fpt.y(), fpt.z(), this, pt2); } SPoint2 ACISFace::parFromPoint(const SPoint3 &qp, bool onSurface) const { SURFACE *Surf = _f->geometry(); - SPAposition pt(qp.x(),qp.y(),qp.z()); + SPAposition pt(qp.x(), qp.y(), qp.z()); SPApar_pos ppt = Surf->equation().param(pt); - SPoint2 pt2(ppt.u,ppt.v); - GPoint sp = point(ppt.u,ppt.v); + SPoint2 pt2(ppt.u, ppt.v); + GPoint sp = point(ppt.u, ppt.v); return pt2; } GEntity::GeomType ACISFace::geomType() const { SURFACE *Surf = _f->geometry(); - if (!strcmp(Surf->type_name(),"plane"))return Plane; - if (!strcmp(Surf->type_name(),"sphere"))return Sphere; - if (!strcmp(Surf->type_name(),"cone"))return Cone; - if (!strcmp(Surf->type_name(),"torus"))return Torus; - if (!strcmp(Surf->type_name(),"cylinder"))return Cylinder; + if(!strcmp(Surf->type_name(), "plane")) return Plane; + if(!strcmp(Surf->type_name(), "sphere")) return Sphere; + if(!strcmp(Surf->type_name(), "cone")) return Cone; + if(!strcmp(Surf->type_name(), "torus")) return Torus; + if(!strcmp(Surf->type_name(), "cylinder")) return Cylinder; return Unknown; } -double ACISFace::curvatureMax(const SPoint2 ¶m) const -{ - return 1.e22; -} +double ACISFace::curvatureMax(const SPoint2 ¶m) const { return 1.e22; } -double ACISFace::curvatures(const SPoint2 ¶m, - SVector3 &dirMax, - SVector3 &dirMin, - double &curvMax, - double &curvMin) const +double ACISFace::curvatures(const SPoint2 ¶m, SVector3 &dirMax, + SVector3 &dirMin, double &curvMax, + double &curvMin) const { return 1.e22; } bool ACISFace::containsPoint(const SPoint3 &pt) const { - SPAposition ps(pt.x(),pt.y(),pt.z()); - if (_f->geometry()->equation().test_point(ps)) + SPAposition ps(pt.x(), pt.y(), pt.z()); + if(_f->geometry()->equation().test_point(ps)) return 1; else return 0; } -double ACISFace::period(int dir) const { - if (dir == 0) +double ACISFace::period(int dir) const +{ + if(dir == 0) return _f->geometry()->equation().param_period_u(); - else if (dir == 1) + else if(dir == 1) return _f->geometry()->equation().param_period_v(); } bool ACISFace::buildSTLTriangulation(bool force) { - if(stl_triangles.size()){ - if(force){ + if(stl_triangles.size()) { + if(force) { stl_vertices.clear(); stl_triangles.clear(); } @@ -208,17 +204,17 @@ bool ACISFace::buildSTLTriangulation(bool force) return true; } outcome out = api_facet_entity(_f); - if (!out.ok())return false; + if(!out.ok()) return false; return true; } GFace *getACISFaceByNativePtr(GModel *model, FACE *f) { - GModel::fiter it =model->firstFace(); - for (; it !=model->lastFace(); ++it){ - ACISFace *gf = dynamic_cast<ACISFace*>(*it); - if (gf){ - if (f == (FACE*)gf->getNativePtr())return gf; + GModel::fiter it = model->firstFace(); + for(; it != model->lastFace(); ++it) { + ACISFace *gf = dynamic_cast<ACISFace *>(*it); + if(gf) { + if(f == (FACE *)gf->getNativePtr()) return gf; } } return 0; diff --git a/Geo/ACISFace.h b/Geo/ACISFace.h index 7b5aa70325bececf9746513bebb6754b93e2da34..c18e65cb01ae0adcc9dc7aacd50fc00e8fadfdd2 100644 --- a/Geo/ACISFace.h +++ b/Geo/ACISFace.h @@ -17,32 +17,35 @@ #include <face.hxx> #include <surface.hxx> class ACISFace : public GFace { - protected: +protected: FACE *_f; double umin, umax, vmin, vmax; bool _periodic[2]; - public: + +public: ACISFace(GModel *m, FACE *f, int num); - virtual ~ACISFace(){} + virtual ~ACISFace() {} virtual bool periodic(int dir) const { return _periodic[dir]; } virtual double period(int dir) const; - Range<double> parBounds(int i) const; - virtual GPoint point(double par1, double par2) const; - virtual GPoint closestPoint(const SPoint3 & queryPoint, - const double initialGuess[2]) const; - virtual bool containsPoint(const SPoint3 &pt) const; - virtual SVector3 normal(const SPoint2 ¶m) const; - virtual Pair<SVector3,SVector3> firstDer(const SPoint2 ¶m) const; - virtual void secondDer(const SPoint2 &, SVector3 *, SVector3 *, SVector3 *) const; - virtual GEntity::GeomType geomType() const; + Range<double> parBounds(int i) const; + virtual GPoint point(double par1, double par2) const; + virtual GPoint closestPoint(const SPoint3 &queryPoint, + const double initialGuess[2]) const; + virtual bool containsPoint(const SPoint3 &pt) const; + virtual SVector3 normal(const SPoint2 ¶m) const; + virtual Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m) const; + virtual void secondDer(const SPoint2 &, SVector3 *, SVector3 *, + SVector3 *) const; + virtual GEntity::GeomType geomType() const; ModelType getNativeType() const { return AcisModel; } - void *getNativePtr() const { return (void*)_f; } - virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const; + void *getNativePtr() const { return (void *)_f; } + virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface = true) const; virtual double curvatureMax(const SPoint2 ¶m) const; - virtual double curvatures(const SPoint2 ¶m, SVector3 *dirMax, SVector3 *dirMin, - double *curvMax, double *curvMin) const; + virtual double curvatures(const SPoint2 ¶m, SVector3 *dirMax, + SVector3 *dirMin, double *curvMax, + double *curvMin) const; bool buildSTLTriangulation(bool force); - FACE* getFACE () {return _f;} + FACE *getFACE() { return _f; } }; GFace *getACISFaceByNativePtr(GModel *model, FACE *); diff --git a/Geo/ACISVertex.cpp b/Geo/ACISVertex.cpp index 84d0c76083026584a751c80ef39eaac77dcbbeb3..ee7a3ca78acb40c64250bbfc1715442420b88979 100644 --- a/Geo/ACISVertex.cpp +++ b/Geo/ACISVertex.cpp @@ -9,8 +9,7 @@ #if defined(HAVE_ACIS) #include <point.hxx> -ACISVertex::ACISVertex(GModel *m, int num, VERTEX *v) - : GVertex(m, num), _v(v) +ACISVertex::ACISVertex(GModel *m, int num, VERTEX *v) : GVertex(m, num), _v(v) { APOINT *p = _v->geometry(); const SPAposition &pos = p->coords(); @@ -24,7 +23,7 @@ void ACISVertex::setPosition(GPoint &p) _x = p.x(); _y = p.y(); _z = p.z(); - if(mesh_vertices.size()){ + if(mesh_vertices.size()) { mesh_vertices[0]->x() = p.x(); mesh_vertices[0]->y() = p.y(); mesh_vertices[0]->z() = p.z(); @@ -33,18 +32,19 @@ void ACISVertex::setPosition(GPoint &p) SPoint2 ACISVertex::reparamOnFace(const GFace *gf, int dir) const { - // FIXME there is definitively a fastest way to do it and this is wring for seams! - return gf->parFromPoint(SPoint3(x(),y(),z())); + // FIXME there is definitively a fastest way to do it and this is wring for + // seams! + return gf->parFromPoint(SPoint3(x(), y(), z())); } -GVertex *getACISVertexByNativePtr(GModel *model, VERTEX* toFind) +GVertex *getACISVertexByNativePtr(GModel *model, VERTEX *toFind) { - GModel::viter it =model->firstVertex(); - for (; it != model->lastVertex(); it++){ - ACISVertex *av = dynamic_cast<ACISVertex*>(*it); - if (av){ - if (toFind == av->getVERTEX()){ - return *it; + GModel::viter it = model->firstVertex(); + for(; it != model->lastVertex(); it++) { + ACISVertex *av = dynamic_cast<ACISVertex *>(*it); + if(av) { + if(toFind == av->getVERTEX()) { + return *it; } } } diff --git a/Geo/ACISVertex.h b/Geo/ACISVertex.h index 99e91a396238b50ebbd60512ca179c47b1206f54..b6b43c30d197a5e58467a42506e3f9432cb98481 100644 --- a/Geo/ACISVertex.h +++ b/Geo/ACISVertex.h @@ -15,10 +15,11 @@ #include <vertex.hxx> class ACISVertex : public GVertex { - protected: - VERTEX* _v; +protected: + VERTEX *_v; double _x, _y, _z; - public: + +public: ACISVertex(GModel *m, int num, VERTEX *_v); virtual ~ACISVertex() {} virtual GPoint point() const { return GPoint(x(), y(), z()); } @@ -27,11 +28,11 @@ class ACISVertex : public GVertex { virtual double z() const { return _z; } virtual void setPosition(GPoint &p); ModelType getNativeType() const { return AcisModel; } - void * getNativePtr() const { return (void*)_v; } + void *getNativePtr() const { return (void *)_v; } virtual SPoint2 reparamOnFace(const GFace *gf, int) const; - VERTEX* getVERTEX() { return _v; } + VERTEX *getVERTEX() { return _v; } }; -GVertex *getACISVertexByNativePtr(GModel *model, VERTEX*); +GVertex *getACISVertexByNativePtr(GModel *model, VERTEX *); #endif diff --git a/Geo/CGNSFunctions.cpp b/Geo/CGNSFunctions.cpp index 351aabe547c59164f527641435f9944896a15bda..1bc9525d2dc1631a2c976b901efd457c47534dd3 100644 --- a/Geo/CGNSFunctions.cpp +++ b/Geo/CGNSFunctions.cpp @@ -30,32 +30,59 @@ using namespace CGNS; int parentFromCGNSType(ElementType_t cgnsType) { - switch(cgnsType){ - case NODE: - return TYPE_PNT; - case BAR_2: case BAR_3: case BAR_4: case BAR_5: - return TYPE_LIN; - case TRI_3: case TRI_6: case TRI_9: case TRI_10: case TRI_12: case TRI_15: - return TYPE_TRI; - case QUAD_4: case QUAD_9: case QUAD_16: case QUAD_25: - case QUAD_8: case QUAD_12: case QUAD_P4_16: - return TYPE_QUA; - case TETRA_4: case TETRA_10: case TETRA_20: case TETRA_35: - case TETRA_16: case TETRA_22: - case TETRA_34: - return TYPE_TET; - case PYRA_5: case PYRA_14: case PYRA_30: case PYRA_55: - case PYRA_13: case PYRA_21: case PYRA_P4_29: - case PYRA_29: case PYRA_50: - return TYPE_PYR; - case PENTA_6: case PENTA_18: case PENTA_40: case PENTA_75: - case PENTA_15: case PENTA_24: case PENTA_33: - case PENTA_38: case PENTA_66: - return TYPE_PRI; - case HEXA_8: case HEXA_27: case HEXA_64: case HEXA_125: - case HEXA_20: case HEXA_32: case HEXA_44: - case HEXA_56: case HEXA_98: - return TYPE_HEX; + switch(cgnsType) { + case NODE: return TYPE_PNT; + case BAR_2: + case BAR_3: + case BAR_4: + case BAR_5: return TYPE_LIN; + case TRI_3: + case TRI_6: + case TRI_9: + case TRI_10: + case TRI_12: + case TRI_15: return TYPE_TRI; + case QUAD_4: + case QUAD_9: + case QUAD_16: + case QUAD_25: + case QUAD_8: + case QUAD_12: + case QUAD_P4_16: return TYPE_QUA; + case TETRA_4: + case TETRA_10: + case TETRA_20: + case TETRA_35: + case TETRA_16: + case TETRA_22: + case TETRA_34: return TYPE_TET; + case PYRA_5: + case PYRA_14: + case PYRA_30: + case PYRA_55: + case PYRA_13: + case PYRA_21: + case PYRA_P4_29: + case PYRA_29: + case PYRA_50: return TYPE_PYR; + case PENTA_6: + case PENTA_18: + case PENTA_40: + case PENTA_75: + case PENTA_15: + case PENTA_24: + case PENTA_33: + case PENTA_38: + case PENTA_66: return TYPE_PRI; + case HEXA_8: + case HEXA_27: + case HEXA_64: + case HEXA_125: + case HEXA_20: + case HEXA_32: + case HEXA_44: + case HEXA_56: + case HEXA_98: return TYPE_HEX; case MIXED: case NGON_n: case NFACE_n: @@ -70,29 +97,66 @@ int parentFromCGNSType(ElementType_t cgnsType) int orderFromCGNSType(ElementType_t cgnsType) { - - switch(cgnsType){ - case NODE: - return 0; - case BAR_2: case TRI_3: case QUAD_4: case TETRA_4: case PYRA_5: case PENTA_6: case HEXA_8: - return 1; - case BAR_3: case TRI_6: case QUAD_9: case TETRA_10: case PYRA_14: case PENTA_18: case HEXA_27: - case QUAD_8: case PYRA_13: case PENTA_15: case HEXA_20: - return 2; - case BAR_4: case TRI_10: case QUAD_16: case TETRA_20: case PYRA_30: case PENTA_40: case HEXA_64: - case TRI_9: case QUAD_12: case TETRA_16: case PYRA_21: case PENTA_24: case HEXA_32: - case PYRA_29: case PENTA_38: case HEXA_56: - return 3; - case BAR_5: case TRI_15: case QUAD_25: case TETRA_35: case PYRA_55: case PENTA_75: case HEXA_125: - case TRI_12: case QUAD_P4_16: case TETRA_22: case PYRA_P4_29: case PENTA_33: case HEXA_44: - case TETRA_34: case PYRA_50: case PENTA_66: case HEXA_98: - return 4; + switch(cgnsType) { + case NODE: return 0; + case BAR_2: + case TRI_3: + case QUAD_4: + case TETRA_4: + case PYRA_5: + case PENTA_6: + case HEXA_8: return 1; + case BAR_3: + case TRI_6: + case QUAD_9: + case TETRA_10: + case PYRA_14: + case PENTA_18: + case HEXA_27: + case QUAD_8: + case PYRA_13: + case PENTA_15: + case HEXA_20: return 2; + case BAR_4: + case TRI_10: + case QUAD_16: + case TETRA_20: + case PYRA_30: + case PENTA_40: + case HEXA_64: + case TRI_9: + case QUAD_12: + case TETRA_16: + case PYRA_21: + case PENTA_24: + case HEXA_32: + case PYRA_29: + case PENTA_38: + case HEXA_56: return 3; + case BAR_5: + case TRI_15: + case QUAD_25: + case TETRA_35: + case PYRA_55: + case PENTA_75: + case HEXA_125: + case TRI_12: + case QUAD_P4_16: + case TETRA_22: + case PYRA_P4_29: + case PENTA_33: + case HEXA_44: + case TETRA_34: + case PYRA_50: + case PENTA_66: + case HEXA_98: return 4; case MIXED: case NGON_n: case NFACE_n: case ElementTypeUserDefined: case ElementTypeNull: - Msg::Warning("Finding order for unsupported CGNS element type %i",cgnsType); + Msg::Warning("Finding order for unsupported CGNS element type %i", + cgnsType); return -1; } return -1; @@ -100,25 +164,64 @@ int orderFromCGNSType(ElementType_t cgnsType) bool completeCGNSType(ElementType_t cgnsType) { - - switch(cgnsType){ + switch(cgnsType) { // complete elements case NODE: - case BAR_2: case TRI_3: case QUAD_4: case TETRA_4: case PYRA_5: case PENTA_6: case HEXA_8: - case BAR_3: case TRI_6: case QUAD_9: case TETRA_10: case PYRA_14: case PENTA_18: case HEXA_27: - case BAR_4: case TRI_10: case QUAD_16: case TETRA_20: case PYRA_30: case PENTA_40: case HEXA_64: - case BAR_5: case TRI_15: case QUAD_25: case TETRA_35: case PYRA_55: case PENTA_75: case HEXA_125: + case BAR_2: + case TRI_3: + case QUAD_4: + case TETRA_4: + case PYRA_5: + case PENTA_6: + case HEXA_8: + case BAR_3: + case TRI_6: + case QUAD_9: + case TETRA_10: + case PYRA_14: + case PENTA_18: + case HEXA_27: + case BAR_4: + case TRI_10: + case QUAD_16: + case TETRA_20: + case PYRA_30: + case PENTA_40: + case HEXA_64: + case BAR_5: + case TRI_15: + case QUAD_25: + case TETRA_35: + case PYRA_55: + case PENTA_75: + case HEXA_125: return true; // serendipity edge elements - case QUAD_8: case PYRA_13: case PENTA_15: case HEXA_20: - case QUAD_12: case TETRA_16: case PYRA_21: case PENTA_24: case HEXA_32: - case TRI_12: case QUAD_P4_16: case TETRA_22: case PYRA_P4_29: case PENTA_33: case HEXA_44: + case QUAD_8: + case PYRA_13: + case PENTA_15: + case HEXA_20: + case QUAD_12: + case TETRA_16: + case PYRA_21: + case PENTA_24: + case HEXA_32: + case TRI_12: + case QUAD_P4_16: + case TETRA_22: + case PYRA_P4_29: + case PENTA_33: + case HEXA_44: return false; // serendipity elements - case PYRA_29: case PENTA_38: case HEXA_56: - case TETRA_34: case PYRA_50: case PENTA_66: case HEXA_98: - default: - return false; + case PYRA_29: + case PENTA_38: + case HEXA_56: + case TETRA_34: + case PYRA_50: + case PENTA_66: + case HEXA_98: + default: return false; } return false; } @@ -130,329 +233,315 @@ int tagFromCGNSType(ElementType_t cgnsType) !completeCGNSType(cgnsType)); } -std::vector<SVector3> generatePointsCGNS(int,int,bool,bool); +std::vector<SVector3> generatePointsCGNS(int, int, bool, bool); -void addEdgePointsCGNS(const SVector3 p0, - const SVector3 p1, - int order, - std::vector<SVector3>& points) +void addEdgePointsCGNS(const SVector3 p0, const SVector3 p1, int order, + std::vector<SVector3> &points) { - double ds = 1./order; - for (int i=1;i<order;i++) { - double f = ds*i; - points.push_back(p0*(1.-f) + p1*f); + double ds = 1. / order; + for(int i = 1; i < order; i++) { + double f = ds * i; + points.push_back(p0 * (1. - f) + p1 * f); } } -void addTriPointsCGNS(const SVector3 p0, - const SVector3 p1, - const SVector3 p2, - int order, - bool equidistant, - std::vector<SVector3>& points) +void addTriPointsCGNS(const SVector3 p0, const SVector3 p1, const SVector3 p2, + int order, bool equidistant, + std::vector<SVector3> &points) { - std::vector<SVector3> triPoints = generatePointsCGNS(TYPE_TRI, - order-3, - true,true); + std::vector<SVector3> triPoints = + generatePointsCGNS(TYPE_TRI, order - 3, true, true); - double scale = double (order-3) / double(order); - SVector3 offset(1./order,1./order,0); + double scale = double(order - 3) / double(order); + SVector3 offset(1. / order, 1. / order, 0); - for (size_t i=0;i<triPoints.size();i++) { + for(size_t i = 0; i < triPoints.size(); i++) { SVector3 ip = triPoints[i]; - double u = ip[0] * scale + 1./order; - double v = ip[1] * scale + 1./order; + double u = ip[0] * scale + 1. / order; + double v = ip[1] * scale + 1. / order; - SVector3 pt = (1.-u-v) * p0 + u * p1 + v*p2; + SVector3 pt = (1. - u - v) * p0 + u * p1 + v * p2; points.push_back(pt); } } -void addQuaPointsCGNS(int order,std::vector<SVector3>& points) +void addQuaPointsCGNS(int order, std::vector<SVector3> &points) { - if (order > 2) { + if(order > 2) { + double scale = double(order - 2) / double(order); - double scale = double (order -2) / double(order); + SVector3 corner[4] = {SVector3(-1, -1, 0), SVector3(1, -1, 0), + SVector3(1, 1, 0), SVector3(-1, 1, 0)}; - SVector3 corner[4] = {SVector3(-1,-1,0), - SVector3( 1,-1,0), - SVector3( 1, 1,0), - SVector3(-1, 1,0)}; - - for (int i=0;i<4;i++) { + for(int i = 0; i < 4; i++) { SVector3 c1 = corner[i]; - SVector3 c2 = corner[(i+1)%4]; - double ds = 1./(order-2); - for (int i=0;i<order-2;i++) points.push_back((c1*(1.-i*ds) + c2*(i*ds))*scale); + SVector3 c2 = corner[(i + 1) % 4]; + double ds = 1. / (order - 2); + for(int i = 0; i < order - 2; i++) + points.push_back((c1 * (1. - i * ds) + c2 * (i * ds)) * scale); } } - if (order == 2 || order == 4) points.push_back(SVector3(0,0,0)); + if(order == 2 || order == 4) points.push_back(SVector3(0, 0, 0)); } -void addQuaPointsCGNS(const SVector3 p0, - const SVector3 p1, - const SVector3 p2, - const SVector3 p3, - int order, - std::vector<SVector3>& points) +void addQuaPointsCGNS(const SVector3 p0, const SVector3 p1, const SVector3 p2, + const SVector3 p3, int order, + std::vector<SVector3> &points) { std::vector<SVector3> quaPoints; - addQuaPointsCGNS(order,quaPoints); + addQuaPointsCGNS(order, quaPoints); - for (size_t i=0;i<quaPoints.size();i++) { + for(size_t i = 0; i < quaPoints.size(); i++) { SVector3 ip = quaPoints[i]; double u = ip[0]; double v = ip[1]; - SVector3 pt = ((1.-u)*(1.-v)*p0 + - (1.+u)*(1.-v)*p1 + - (1.+u)*(1.+v)*p2 + - (1.-u)*(1.+v)*p3)*0.25; + SVector3 pt = ((1. - u) * (1. - v) * p0 + (1. + u) * (1. - v) * p1 + + (1. + u) * (1. + v) * p2 + (1. - u) * (1. + v) * p3) * + 0.25; points.push_back(pt); } } -void print(std::vector<SVector3>& points,const char* title,int iStart,int iEnd=-1) +void print(std::vector<SVector3> &points, const char *title, int iStart, + int iEnd = -1) { iEnd = iEnd == -1 ? points.size() : iEnd; std::cout << title << std::endl; - for (int i=iStart;i<iEnd;i++) { + for(int i = iStart; i < iEnd; i++) { std::cout << i << " :"; - for (int d=0;d<3;d++) std::cout << " " << points[i][d]; + for(int d = 0; d < 3; d++) std::cout << " " << points[i][d]; std::cout << std::endl; } } -std::vector<SVector3> generatePointsCGNS(int parentType, - int order, - bool complete, - bool equidistant) +std::vector<SVector3> generatePointsCGNS(int parentType, int order, + bool complete, bool equidistant) { std::vector<SVector3> pp; - if (order == 0) pp.push_back(SVector3(0,0,0)); - if (order > 0) { - - switch (parentType) { - - case TYPE_LIN: - { - // principal vertices - pp.push_back(SVector3(-1,0,0)); - pp.push_back(SVector3(1,0,0)); + if(order == 0) pp.push_back(SVector3(0, 0, 0)); + if(order > 0) { + switch(parentType) { + case TYPE_LIN: { + // principal vertices + pp.push_back(SVector3(-1, 0, 0)); + pp.push_back(SVector3(1, 0, 0)); - // internal points - addEdgePointsCGNS(pp[0],pp[1],order,pp); + // internal points + addEdgePointsCGNS(pp[0], pp[1], order, pp); - break; + break; + } + case TYPE_TRI: { + // principal vertices + pp.push_back(SVector3(0, 0, 0)); + pp.push_back(SVector3(1, 0, 0)); + pp.push_back(SVector3(0, 1, 0)); + + // internal points of edges + for(int i = 0; i < 3; i++) + addEdgePointsCGNS(pp[i], pp[(i + 1) % 3], order, pp); + + // internal points + if(complete && order > 2) { + addTriPointsCGNS(pp[0], pp[1], pp[2], order, equidistant, pp); } - case TYPE_TRI: - { - // principal vertices - pp.push_back(SVector3(0,0,0)); - pp.push_back(SVector3(1,0,0)); - pp.push_back(SVector3(0,1,0)); - - // internal points of edges - for (int i=0;i<3;i++) addEdgePointsCGNS(pp[i],pp[(i+1)%3],order,pp); - - // internal points - if (complete && order > 2) { - addTriPointsCGNS(pp[0],pp[1],pp[2],order,equidistant,pp); - } - break; + break; + } + case TYPE_QUA: { + // principal vertices + pp.push_back(SVector3(-1, -1, 0)); + pp.push_back(SVector3(1, -1, 0)); + pp.push_back(SVector3(1, 1, 0)); + pp.push_back(SVector3(-1, 1, 0)); + + // internal points of edges + for(int i = 0; i < 4; i++) { + addEdgePointsCGNS(pp[i], pp[(i + 1) % 4], order, pp); } - case TYPE_QUA: - { - // principal vertices - pp.push_back(SVector3(-1,-1,0)); - pp.push_back(SVector3( 1,-1,0)); - pp.push_back(SVector3( 1, 1,0)); - pp.push_back(SVector3(-1, 1,0)); - - // internal points of edges - for (int i=0;i<4;i++) { - addEdgePointsCGNS(pp[i],pp[(i+1)%4],order,pp); - } - // internal points - if (complete && order > 1) { - addQuaPointsCGNS(pp[0],pp[1],pp[2],pp[3],order,pp); - } - break; + // internal points + if(complete && order > 1) { + addQuaPointsCGNS(pp[0], pp[1], pp[2], pp[3], order, pp); } - case TYPE_TET: - { - // principal vertices - pp.push_back(SVector3(0,0,0)); - pp.push_back(SVector3(1,0,0)); - pp.push_back(SVector3(0,1,0)); - pp.push_back(SVector3(0,0,1)); - - // internal points in edges of base triangle - for (int i=0;i<3;i++) addEdgePointsCGNS(pp[i],pp[(i+1)%3],order,pp); - - // internal points in upstanding edges - for (int i=0;i<3;i++) addEdgePointsCGNS(pp[i],pp[3],order,pp); - - if (complete && order > 2) { - - // internal points of base triangle - addTriPointsCGNS(pp[0],pp[1],pp[2],order,equidistant,pp); - - // internal points of upstanding triangles - for (int i=0;i<3;i++) { - addTriPointsCGNS(pp[i],pp[(i+1)%3],pp[3],order,equidistant,pp); - } + break; + } + case TYPE_TET: { + // principal vertices + pp.push_back(SVector3(0, 0, 0)); + pp.push_back(SVector3(1, 0, 0)); + pp.push_back(SVector3(0, 1, 0)); + pp.push_back(SVector3(0, 0, 1)); + + // internal points in edges of base triangle + for(int i = 0; i < 3; i++) + addEdgePointsCGNS(pp[i], pp[(i + 1) % 3], order, pp); + + // internal points in upstanding edges + for(int i = 0; i < 3; i++) addEdgePointsCGNS(pp[i], pp[3], order, pp); + + if(complete && order > 2) { + // internal points of base triangle + addTriPointsCGNS(pp[0], pp[1], pp[2], order, equidistant, pp); + + // internal points of upstanding triangles + for(int i = 0; i < 3; i++) { + addTriPointsCGNS(pp[i], pp[(i + 1) % 3], pp[3], order, equidistant, + pp); + } - // internal points as a tet of order p-3 - if (order > 3) { - std::vector<SVector3> tetPp = generatePointsCGNS(TYPE_TET,order-4, - true,true); - - double scale = (order-4)/order; - SVector3 offset(1./order,1./order,1./order); - for (size_t i=0;i<tetPp.size();i++) { - SVector3 volumePoint = tetPp[i]; - volumePoint *= scale; - volumePoint += offset; - pp.push_back(volumePoint); - } + // internal points as a tet of order p-3 + if(order > 3) { + std::vector<SVector3> tetPp = + generatePointsCGNS(TYPE_TET, order - 4, true, true); + + double scale = (order - 4) / order; + SVector3 offset(1. / order, 1. / order, 1. / order); + for(size_t i = 0; i < tetPp.size(); i++) { + SVector3 volumePoint = tetPp[i]; + volumePoint *= scale; + volumePoint += offset; + pp.push_back(volumePoint); } } - - break; } - case TYPE_HEX: - { - - // principal vertices - pp.push_back(SVector3(-1,-1,-1)); - pp.push_back(SVector3( 1,-1,-1)); - pp.push_back(SVector3( 1, 1,-1)); - pp.push_back(SVector3(-1, 1,-1)); - pp.push_back(SVector3(-1,-1, 1)); - pp.push_back(SVector3( 1,-1, 1)); - pp.push_back(SVector3( 1, 1, 1)); - pp.push_back(SVector3(-1, 1, 1)); - - // internal points of base quadrangle edges - for (int i=0;i<4;i++) addEdgePointsCGNS(pp[i],pp[(i+1)%4],order,pp); - - std::vector<SVector3> up[4]; - // internal points of mounting edges - for (int i=0;i<4;i++) { - addEdgePointsCGNS(pp[i],pp[i+4],order,up[i]); - pp.insert(pp.end(),up[i].begin(),up[i].end()); - } - // internal points of top quadrangle edges - for (int i=0;i<4;i++) addEdgePointsCGNS(pp[i+4],pp[(i+1)%4+4],order,pp); + break; + } + case TYPE_HEX: { + // principal vertices + pp.push_back(SVector3(-1, -1, -1)); + pp.push_back(SVector3(1, -1, -1)); + pp.push_back(SVector3(1, 1, -1)); + pp.push_back(SVector3(-1, 1, -1)); + pp.push_back(SVector3(-1, -1, 1)); + pp.push_back(SVector3(1, -1, 1)); + pp.push_back(SVector3(1, 1, 1)); + pp.push_back(SVector3(-1, 1, 1)); + + // internal points of base quadrangle edges + for(int i = 0; i < 4; i++) + addEdgePointsCGNS(pp[i], pp[(i + 1) % 4], order, pp); + + std::vector<SVector3> up[4]; + // internal points of mounting edges + for(int i = 0; i < 4; i++) { + addEdgePointsCGNS(pp[i], pp[i + 4], order, up[i]); + pp.insert(pp.end(), up[i].begin(), up[i].end()); + } - if (complete && order > 1) { + // internal points of top quadrangle edges + for(int i = 0; i < 4; i++) + addEdgePointsCGNS(pp[i + 4], pp[(i + 1) % 4 + 4], order, pp); - // internal points of base quadrangle - addQuaPointsCGNS(pp[0],pp[1],pp[2],pp[3],order,pp); + if(complete && order > 1) { + // internal points of base quadrangle + addQuaPointsCGNS(pp[0], pp[1], pp[2], pp[3], order, pp); - // internal points of upstanding faces - for (int i=0;i<4;i++) { - addQuaPointsCGNS(pp[i],pp[(i+1)%4],pp[(i+1)%4+4],pp[i+4],order,pp); - } + // internal points of upstanding faces + for(int i = 0; i < 4; i++) { + addQuaPointsCGNS(pp[i], pp[(i + 1) % 4], pp[(i + 1) % 4 + 4], + pp[i + 4], order, pp); + } - // internal points of top quadrangle - addQuaPointsCGNS(pp[4],pp[5],pp[6],pp[7],order,pp); + // internal points of top quadrangle + addQuaPointsCGNS(pp[4], pp[5], pp[6], pp[7], order, pp); - // internal volume points as a succession of internal planes - for (int i=0;i<=order-2;i++) { - addQuaPointsCGNS(up[0][i],up[1][i],up[2][i],up[3][i],order,pp); - } + // internal volume points as a succession of internal planes + for(int i = 0; i <= order - 2; i++) { + addQuaPointsCGNS(up[0][i], up[1][i], up[2][i], up[3][i], order, pp); } - - break; } - case TYPE_PRI: - { - - // principal vertices - pp.push_back(SVector3(0,0,-1)); - pp.push_back(SVector3(1,0,-1)); - pp.push_back(SVector3(0,1,-1)); - pp.push_back(SVector3(0,0,1)); - pp.push_back(SVector3(1,0,1)); - pp.push_back(SVector3(0,1,1)); - - // internal points in edges of base triangle - for (int i=0;i<3;i++) addEdgePointsCGNS(pp[i],pp[(i+1)%3],order,pp); - - // internal points in upstanding edges - std::vector<SVector3> edge[3]; // keep for definition of volume pp - for (int i=0;i<3;i++) { - addEdgePointsCGNS(pp[i],pp[i+3],order,edge[i]); - pp.insert(pp.end(),edge[i].begin(),edge[i].end()); - } - // internal points in edges of top triangle - for (int i=0;i<3;i++) addEdgePointsCGNS(pp[i+3],pp[(i+1)%3+3],order,pp); + break; + } + case TYPE_PRI: { + // principal vertices + pp.push_back(SVector3(0, 0, -1)); + pp.push_back(SVector3(1, 0, -1)); + pp.push_back(SVector3(0, 1, -1)); + pp.push_back(SVector3(0, 0, 1)); + pp.push_back(SVector3(1, 0, 1)); + pp.push_back(SVector3(0, 1, 1)); + + // internal points in edges of base triangle + for(int i = 0; i < 3; i++) + addEdgePointsCGNS(pp[i], pp[(i + 1) % 3], order, pp); + + // internal points in upstanding edges + std::vector<SVector3> edge[3]; // keep for definition of volume pp + for(int i = 0; i < 3; i++) { + addEdgePointsCGNS(pp[i], pp[i + 3], order, edge[i]); + pp.insert(pp.end(), edge[i].begin(), edge[i].end()); + } - if (complete) { + // internal points in edges of top triangle + for(int i = 0; i < 3; i++) + addEdgePointsCGNS(pp[i + 3], pp[(i + 1) % 3 + 3], order, pp); - // internal vertices for base triangle - addTriPointsCGNS(pp[0],pp[1],pp[2],order,true,pp); + if(complete) { + // internal vertices for base triangle + addTriPointsCGNS(pp[0], pp[1], pp[2], order, true, pp); - // internal vertices for upstanding quadrilaterals - for (int i=0;i<3;i++) { - addQuaPointsCGNS(pp[i],pp[(i+1)%3],pp[(i+1)%3+3],pp[i+3],order,pp); - } + // internal vertices for upstanding quadrilaterals + for(int i = 0; i < 3; i++) { + addQuaPointsCGNS(pp[i], pp[(i + 1) % 3], pp[(i + 1) % 3 + 3], + pp[i + 3], order, pp); + } - // internal points for top triangle - addTriPointsCGNS(pp[3],pp[4],pp[5],order,true,pp); + // internal points for top triangle + addTriPointsCGNS(pp[3], pp[4], pp[5], order, true, pp); - // internal points in the volume as a succession of "triangles" - for (int o=0;o<order-1;o++) { - addTriPointsCGNS(edge[0][o],edge[1][o],edge[2][o],order,true,pp); - } + // internal points in the volume as a succession of "triangles" + for(int o = 0; o < order - 1; o++) { + addTriPointsCGNS(edge[0][o], edge[1][o], edge[2][o], order, true, pp); } - break; } - case TYPE_PYR: - { - // principal vertices - pp.push_back(SVector3(-1,-1,0)); - pp.push_back(SVector3( 1,-1,0)); - pp.push_back(SVector3( 1, 1,0)); - pp.push_back(SVector3(-1, 1,0)); - pp.push_back(SVector3( 0, 0,1)); - - // internal points in edges of base quadrilateral - for (int i=0;i<4;i++) addEdgePointsCGNS(pp[i],pp[(i+1)%4],order,pp); + break; + } + case TYPE_PYR: { + // principal vertices + pp.push_back(SVector3(-1, -1, 0)); + pp.push_back(SVector3(1, -1, 0)); + pp.push_back(SVector3(1, 1, 0)); + pp.push_back(SVector3(-1, 1, 0)); + pp.push_back(SVector3(0, 0, 1)); - // internal points in upstanding edges - for (int i=0;i<4;i++) addEdgePointsCGNS(pp[i],pp[4],order,pp); + // internal points in edges of base quadrilateral + for(int i = 0; i < 4; i++) + addEdgePointsCGNS(pp[i], pp[(i + 1) % 4], order, pp); - // internal points in base quadrilateral - addQuaPointsCGNS(pp[0],pp[1],pp[2],pp[3],order,pp); + // internal points in upstanding edges + for(int i = 0; i < 4; i++) addEdgePointsCGNS(pp[i], pp[4], order, pp); - // internal points in upstanding triangles - for (int i=0;i<4;i++) addTriPointsCGNS(pp[i],pp[(i+1)%4],pp[4],order,true,pp); + // internal points in base quadrilateral + addQuaPointsCGNS(pp[0], pp[1], pp[2], pp[3], order, pp); - // internal points as an internal pyramid of order p-3 - std::vector<SVector3> pyr = generatePointsCGNS(TYPE_PYR,order-3,true,true); + // internal points in upstanding triangles + for(int i = 0; i < 4; i++) + addTriPointsCGNS(pp[i], pp[(i + 1) % 4], pp[4], order, true, pp); - SVector3 offset(0,0,1./order); - double scale = double (order-3) / double(order); + // internal points as an internal pyramid of order p-3 + std::vector<SVector3> pyr = + generatePointsCGNS(TYPE_PYR, order - 3, true, true); - for (size_t i=0;i<pyr.size();++i) pp.push_back((pyr[i]*scale)+offset); + SVector3 offset(0, 0, 1. / order); + double scale = double(order - 3) / double(order); + for(size_t i = 0; i < pyr.size(); ++i) + pp.push_back((pyr[i] * scale) + offset); - break; - } + break; + } default: - Msg::Error("%s (%i) : Error CGNS element %i of order %i not yet implemented", - __FILE__,__LINE__,ElementType::nameOfParentType(parentType).c_str(),order); - + Msg::Error( + "%s (%i) : Error CGNS element %i of order %i not yet implemented", + __FILE__, __LINE__, ElementType::nameOfParentType(parentType).c_str(), + order); } } @@ -462,58 +551,60 @@ std::vector<SVector3> generatePointsCGNS(int parentType, fullMatrix<double> getTransformationToGmsh(ElementType_t cgnsType) { int parent = parentFromCGNSType(cgnsType); - int order = orderFromCGNSType(cgnsType); + int order = orderFromCGNSType(cgnsType); bool complete = completeCGNSType(cgnsType); int gmshType = tagFromCGNSType(cgnsType); - std::vector<SVector3> points = generatePointsCGNS(parent,order,complete,true); + std::vector<SVector3> points = + generatePointsCGNS(parent, order, complete, true); - fullMatrix<double> cgnsPoints(points.size(),3); + fullMatrix<double> cgnsPoints(points.size(), 3); - for (size_t i=0;i<points.size();i++) { - for (size_t d=0;d<3;d++) cgnsPoints(i,d) = points[i][d]; + for(size_t i = 0; i < points.size(); i++) { + for(size_t d = 0; d < 3; d++) cgnsPoints(i, d) = points[i][d]; } // cgnsPoints.print("Point locations in transformation","%.1f"); - static const nodalBasis* nb = BasisFactory::getNodalBasis(gmshType); + static const nodalBasis *nb = BasisFactory::getNodalBasis(gmshType); - fullMatrix<double> tfo(points.size(),points.size()); + fullMatrix<double> tfo(points.size(), points.size()); - nb->forwardTransformation(cgnsPoints,tfo); + nb->forwardTransformation(cgnsPoints, tfo); // tfo.print("Transformation matrix in transformation","%.1f"); return tfo; } -int* getRenumberingToGmsh(ElementType_t cgnsType) +int *getRenumberingToGmsh(ElementType_t cgnsType) { int parent = parentFromCGNSType(cgnsType); - int order = orderFromCGNSType(cgnsType); + int order = orderFromCGNSType(cgnsType); bool complete = completeCGNSType(cgnsType); int gmshType = tagFromCGNSType(cgnsType); - std::vector<SVector3> points = generatePointsCGNS(parent,order,complete,true); - fullMatrix<double> cgnsPoints(points.size(),3); + std::vector<SVector3> points = + generatePointsCGNS(parent, order, complete, true); + fullMatrix<double> cgnsPoints(points.size(), 3); - for (size_t i=0;i<points.size();i++) { - for (size_t d=0;d<3;d++) cgnsPoints(i,d) = points[i][d]; + for(size_t i = 0; i < points.size(); i++) { + for(size_t d = 0; d < 3; d++) cgnsPoints(i, d) = points[i][d]; } // cgnsPoints.print("Point location in renumberings","%.1f"); - const nodalBasis* nb = BasisFactory::getNodalBasis(gmshType); - - int* renum = new int[points.size()]; - nb->forwardRenumbering(cgnsPoints,renum); + const nodalBasis *nb = BasisFactory::getNodalBasis(gmshType); + int *renum = new int[points.size()]; + nb->forwardRenumbering(cgnsPoints, renum); // std::ostringstream filename; - // filename << ElementType::nameOfParentType(parent) << "_p" << order << ".dat"; - // std::ofstream checkFile(filename.str().c_str()); + // filename << ElementType::nameOfParentType(parent) << "_p" << order << + // ".dat"; std::ofstream checkFile(filename.str().c_str()); - // checkFile << "CGNS Control points in a " << ElementType::nameOfParentType(parent) + // checkFile << "CGNS Control points in a " << + // ElementType::nameOfParentType(parent) // << " of order " << order << std::endl; // for (size_t i=0;i<points.size();i++) { // checkFile << std::setw(2) << i+1 @@ -530,45 +621,27 @@ int* getRenumberingToGmsh(ElementType_t cgnsType) int gridLocationDimCGNS(GridLocation_t lt) { - switch (lt) { - case CellCenter: - return 3; - break; + switch(lt) { + case CellCenter: return 3; break; case FaceCenter: case IFaceCenter: case JFaceCenter: - case KFaceCenter: - return 2; - break; - case EdgeCenter: - return 1; - break; - case Vertex: - return 0; - break; + case KFaceCenter: return 2; break; + case EdgeCenter: return 1; break; + case Vertex: return 0; break; case GridLocationNull: - case GridLocationUserDefined: - return -1; - break; + case GridLocationUserDefined: return -1; break; } return -1; } GridLocation_t unstructuredGridLocationCGNS(int dim) { - switch (dim) { - case 3: - return CellCenter; - break; - case 2: - return FaceCenter; - break; - case 1: - return EdgeCenter; - break; - case 0: - return Vertex; - break; + switch(dim) { + case 3: return CellCenter; break; + case 2: return FaceCenter; break; + case 1: return EdgeCenter; break; + case 0: return Vertex; break; } return GridLocationNull; } diff --git a/Geo/CGNSOptions.h b/Geo/CGNSOptions.h index 95c4f4e0f2d2bf8ddf2b705dc74759396782fc57..cf620b664346f7573633d0c9714e705b0e8ca0a3 100644 --- a/Geo/CGNSOptions.h +++ b/Geo/CGNSOptions.h @@ -10,34 +10,30 @@ #include <string> -class CGNSOptions -{ - public: - enum CGNSLocationType { - LocVertex = 0, - LocFace = 1 - }; +class CGNSOptions { +public: + enum CGNSLocationType { LocVertex = 0, LocFace = 1 }; std::string baseName; std::string zoneName; std::string interfaceName; std::string patchName; - int gridConnectivityLocation; // Location of connectivity(values - // CGNSLocationType) - int bocoLocation; // Location of BC (values - // CGNSLocationType) - int normalSource; // Source for BC normal data - // 0 - do not write normals - // 1 - geometry - // 2 - elements - int vectorDim; // Number of dimensions in a vector - // (only relevant for a 2D mesh) + int gridConnectivityLocation; // Location of connectivity(values + // CGNSLocationType) + int bocoLocation; // Location of BC (values + // CGNSLocationType) + int normalSource; // Source for BC normal data + // 0 - do not write normals + // 1 - geometry + // 2 - elements + int vectorDim; // Number of dimensions in a vector + // (only relevant for a 2D mesh) bool writeBC; - bool writeUserDef; // T - write user-defined elements for - // element types unsupported by CGNS + bool writeUserDef; // T - write user-defined elements for + // element types unsupported by CGNS - CGNSOptions(){ setDefaults(); } - ~CGNSOptions(){} + CGNSOptions() { setDefaults(); } + ~CGNSOptions() {} void setDefaults() { baseName = "Base_1"; diff --git a/Geo/Cell.cpp b/Geo/Cell.cpp index c74e673775181327f4965151826a3117c3ba8388..0dee3a4bfa98d0adaf904daa33af3f31a117a481 100644 --- a/Geo/Cell.cpp +++ b/Geo/Cell.cpp @@ -13,35 +13,38 @@ #include "MHexahedron.h" #include "MPrism.h" -bool Less_Cell::operator()(const Cell* c1, const Cell* c2) const +bool Less_Cell::operator()(const Cell *c1, const Cell *c2) const { // If cell complex is done use enumeration (same as vertex order) if(c1->getNum() != 0) return (c1->getNum() < c2->getNum()); // Otherwise order by vertex numbering (good heuristic for reduction) - if(c1->getNumSortedVertices() != c2->getNumSortedVertices()){ + if(c1->getNumSortedVertices() != c2->getNumSortedVertices()) { return (c1->getNumSortedVertices() < c2->getNumSortedVertices()); } - for(int i=0; i < c1->getNumSortedVertices();i++){ - if(c1->getSortedVertex(i) < c2->getSortedVertex(i)) return true; - else if (c1->getSortedVertex(i) > c2->getSortedVertex(i)) return false; + for(int i = 0; i < c1->getNumSortedVertices(); i++) { + if(c1->getSortedVertex(i) < c2->getSortedVertex(i)) + return true; + else if(c1->getSortedVertex(i) > c2->getSortedVertex(i)) + return false; } return false; } -bool equalVertices(const std::vector<MVertex*>& v1, - const std::vector<MVertex*>& v2) { +bool equalVertices(const std::vector<MVertex *> &v1, + const std::vector<MVertex *> &v2) +{ if(v1.size() != v2.size()) return false; for(unsigned int i = 0; i < v1.size(); i++) - if(v1[i]->getNum() != v2[i]->getNum()) return false; + if(v1[i]->getNum() != v2[i]->getNum()) return false; return true; } int Cell::_globalNum = 0; -std::pair<Cell*, bool> Cell::createCell(MElement* element, int domain) +std::pair<Cell *, bool> Cell::createCell(MElement *element, int domain) { - Cell* cell = new Cell(); + Cell *cell = new Cell(); cell->_dim = element->getDim(); cell->_domain = domain; cell->_combined = false; @@ -54,10 +57,10 @@ std::pair<Cell*, bool> Cell::createCell(MElement* element, int domain) return std::make_pair(cell, cell->_sortVertexIndices()); } -std::pair<Cell*, bool> Cell::createCell(Cell* parent, int i) +std::pair<Cell *, bool> Cell::createCell(Cell *parent, int i) { - Cell* cell = new Cell(); - cell->_dim = parent->getDim()-1; + Cell *cell = new Cell(); + cell->_dim = parent->getDim() - 1; cell->_domain = parent->getDomain(); cell->_combined = false; cell->_immune = false; @@ -67,7 +70,7 @@ std::pair<Cell*, bool> Cell::createCell(Cell* parent, int i) return std::make_pair(cell, cell->_sortVertexIndices()); } -Cell::Cell(MElement* element, int domain) +Cell::Cell(MElement *element, int domain) { _dim = element->getDim(); _domain = domain; @@ -81,9 +84,9 @@ Cell::Cell(MElement* element, int domain) _sortVertexIndices(); } -Cell::Cell(Cell* parent, int i) +Cell::Cell(Cell *parent, int i) { - _dim = parent->getDim()-1; + _dim = parent->getDim() - 1; _domain = parent->getDomain(); _combined = false; _immune = false; @@ -95,7 +98,7 @@ Cell::Cell(Cell* parent, int i) bool Cell::_sortVertexIndices() { - std::map<MVertex*, int, MVertexLessThanNum> si; + std::map<MVertex *, int, MVertexLessThanNum> si; bool noinsert = false; for(unsigned int i = 0; i < _v.size(); i++) @@ -106,9 +109,8 @@ bool Cell::_sortVertexIndices() return false; } - std::map<MVertex*, int, MVertexLessThanNum>::iterator it; - for(it = si.begin(); it != si.end(); it++) - _si.push_back(it->second); + std::map<MVertex *, int, MVertexLessThanNum>::iterator it; + for(it = si.begin(); it != si.end(); it++) _si.push_back(it->second); return true; } @@ -118,15 +120,13 @@ inline int Cell::getSortedVertex(int vertex) const return _v[(int)_si[vertex]]->getNum(); } -void Cell::findBdElement(int i, std::vector<MVertex*>& vertices) const +void Cell::findBdElement(int i, std::vector<MVertex *> &vertices) const { vertices.clear(); - switch (_dim) { - case 1: - vertices.push_back(_v[i]); - return; + switch(_dim) { + case 1: vertices.push_back(_v[i]); return; case 2: - switch (getNumVertices()) { + switch(getNumVertices()) { case 3: for(int j = 0; j < 2; j++) vertices.push_back(_v[MTriangle::edges_tri(i, j)]); @@ -138,7 +138,7 @@ void Cell::findBdElement(int i, std::vector<MVertex*>& vertices) const default: return; } case 3: - switch (getNumVertices()) { + switch(getNumVertices()) { case 4: for(int j = 0; j < 3; j++) vertices.push_back(_v[MTetrahedron::faces_tetra(i, j)]); @@ -171,17 +171,17 @@ void Cell::findBdElement(int i, std::vector<MVertex*>& vertices) const int Cell::getNumBdElements() const { - switch (_dim) { + switch(_dim) { case 0: return 0; case 1: return 2; case 2: - switch (getNumVertices()) { + switch(getNumVertices()) { case 3: return 3; case 4: return 4; default: return 0; } case 3: - switch (getNumVertices()) { + switch(getNumVertices()) { case 4: return 4; case 5: return 5; case 6: return 5; @@ -192,7 +192,7 @@ int Cell::getNumBdElements() const } } -int Cell::findBdCellOrientation(Cell* cell, int i) const +int Cell::findBdCellOrientation(Cell *cell, int i) const { /*std::vector<MVertex*> v1; std::vector<MVertex*> v2; @@ -213,16 +213,18 @@ int Cell::findBdCellOrientation(Cell* cell, int i) const } return 0;*/ - std::vector<MVertex*> v; + std::vector<MVertex *> v; cell->getMeshVertices(v); - switch (_dim) { + switch(_dim) { case 0: return 0; case 1: - if(v[0]->getNum() == _v[0]->getNum()) return -1; - else if(v[0]->getNum() == _v[1]->getNum()) return 1; + if(v[0]->getNum() == _v[0]->getNum()) + return -1; + else if(v[0]->getNum() == _v[1]->getNum()) + return 1; return 0; case 2: - switch (getNumVertices()) { + switch(getNumVertices()) { case 3: if(_v[MTriangle::edges_tri(i, 0)]->getNum() == v[0]->getNum() && _v[MTriangle::edges_tri(i, 1)]->getNum() == v[1]->getNum()) @@ -242,7 +244,7 @@ int Cell::findBdCellOrientation(Cell* cell, int i) const default: return 0; } case 3: - switch (getNumVertices()) { + switch(getNumVertices()) { case 4: if(_v[MTetrahedron::faces_tetra(i, 0)]->getNum() == v[0]->getNum() && _v[MTetrahedron::faces_tetra(i, 1)]->getNum() == v[1]->getNum() && @@ -460,17 +462,17 @@ int Cell::findBdCellOrientation(Cell* cell, int i) const int Cell::getTypeMSH() const { - switch (_dim) { + switch(_dim) { case 0: return MSH_PNT; case 1: return MSH_LIN_2; case 2: - switch (getNumVertices()) { + switch(getNumVertices()) { case 3: return MSH_TRI_3; case 4: return MSH_QUA_4; default: return 0; } case 3: - switch (getNumVertices()) { + switch(getNumVertices()) { case 4: return MSH_TET_4; case 5: return MSH_PYR_5; case 6: return MSH_PRI_6; @@ -487,16 +489,17 @@ bool Cell::hasVertex(int vertex) const for(unsigned int i = 0; i < _v.size(); i++) { v.push_back(_v[(int)_si[i]]->getNum()); } - std::vector<int>::const_iterator it = std::find(v.begin(), v.end(), - vertex); - if (it != v.end()) return true; - else return false; + std::vector<int>::const_iterator it = std::find(v.begin(), v.end(), vertex); + if(it != v.end()) + return true; + else + return false; } bool CombinedCell::hasVertex(int vertex) const { - for(std::map<Cell*, int, Less_Cell>::const_iterator cit = _cells.begin(); - cit != _cells.end(); cit++){ + for(std::map<Cell *, int, Less_Cell>::const_iterator cit = _cells.begin(); + cit != _cells.end(); cit++) { if(cit->first->hasVertex(vertex)) return true; } return false; @@ -504,119 +507,121 @@ bool CombinedCell::hasVertex(int vertex) const void Cell::printCell() { - printf("%d-cell %d: \n" , getDim(), getNum()); + printf("%d-cell %d: \n", getDim(), getNum()); printf(" Vertices:"); - for(int i = 0; i < this->getNumVertices(); i++){ + for(int i = 0; i < this->getNumVertices(); i++) { printf(" %d", this->getMeshVertex(i)->getNum()); } printf(", in subdomain: %d, ", inSubdomain()); - printf("combined: %d. \n" , isCombined() ); + printf("combined: %d. \n", isCombined()); }; void Cell::saveCellBoundary() { - for(biter it = firstCoboundary(); it != lastCoboundary(); it++){ + for(biter it = firstCoboundary(); it != lastCoboundary(); it++) { it->second.init(); } - for(biter it = firstBoundary(); it != lastBoundary(); it++){ + for(biter it = firstBoundary(); it != lastBoundary(); it++) { it->second.init(); } } void Cell::restoreCellBoundary() { - std::vector<Cell*> toRemove; - for(biter it = firstCoboundary(true); it != lastCoboundary(); it++){ + std::vector<Cell *> toRemove; + for(biter it = firstCoboundary(true); it != lastCoboundary(); it++) { it->second.reset(); if(it->second.get() == 0) toRemove.push_back(it->first); } for(unsigned int i = 0; i < toRemove.size(); i++) _cbd.erase(toRemove[i]); toRemove.clear(); - for(biter it = firstBoundary(true); it != lastBoundary(); it++){ + for(biter it = firstBoundary(true); it != lastBoundary(); it++) { it->second.reset(); if(it->second.get() == 0) toRemove.push_back(it->first); } for(unsigned int i = 0; i < toRemove.size(); i++) _bd.erase(toRemove[i]); } -void Cell::addBoundaryCell(int orientation, Cell* cell, bool other) +void Cell::addBoundaryCell(int orientation, Cell *cell, bool other) { biter it = _bd.find(cell); - if(it != _bd.end()){ + if(it != _bd.end()) { int newOrientation = it->second.get() + orientation; it->second.set(newOrientation); - if(newOrientation == 0){ + if(newOrientation == 0) { it->first->removeCoboundaryCell(this, false); if(it->second.geto() == 0) { - _bd.erase(it); + _bd.erase(it); } return; } } - else _bd.insert( std::make_pair(cell, BdInfo(orientation) ) ); + else + _bd.insert(std::make_pair(cell, BdInfo(orientation))); if(other) cell->addCoboundaryCell(orientation, this, false); } -void Cell::addCoboundaryCell(int orientation, Cell* cell, bool other) +void Cell::addCoboundaryCell(int orientation, Cell *cell, bool other) { biter it = _cbd.find(cell); - if(it != _cbd.end()){ + if(it != _cbd.end()) { int newOrientation = it->second.get() + orientation; it->second.set(newOrientation); if(newOrientation == 0) { it->first->removeBoundaryCell(this, false); if(it->second.geto() == 0) { - _cbd.erase(it); + _cbd.erase(it); } return; } } - else _cbd.insert( std::make_pair(cell, BdInfo(orientation) ) ); + else + _cbd.insert(std::make_pair(cell, BdInfo(orientation))); if(other) cell->addBoundaryCell(orientation, this, false); } -void Cell::removeBoundaryCell(Cell* cell, bool other) +void Cell::removeBoundaryCell(Cell *cell, bool other) { biter it = _bd.find(cell); - if(it != _bd.end()){ + if(it != _bd.end()) { it->second.set(0); if(other) it->first->removeCoboundaryCell(this, false); if(it->second.geto() == 0) _bd.erase(it); } } -void Cell::removeCoboundaryCell(Cell* cell, bool other) +void Cell::removeCoboundaryCell(Cell *cell, bool other) { biter it = _cbd.find(cell); - if(it != _cbd.end()){ + if(it != _cbd.end()) { it->second.set(0); if(other) it->first->removeBoundaryCell(this, false); if(it->second.geto() == 0) _cbd.erase(it); } } -bool Cell::hasBoundary(Cell* cell, bool orig) +bool Cell::hasBoundary(Cell *cell, bool orig) { - if(!orig){ + if(!orig) { biter it = _bd.find(cell); if(it != _bd.end() && it->second.get() != 0) return true; return false; } - else{ + else { biter it = _bd.find(cell); if(it != _bd.end() && it->second.geto() != 0) return true; return false; } } -bool Cell::hasCoboundary(Cell* cell, bool orig) +bool Cell::hasCoboundary(Cell *cell, bool orig) { - if(!orig){ + if(!orig) { biter it = _cbd.find(cell); if(it != _cbd.end() && it->second.get() != 0) return true; return false; } - else{ + else { biter it = _cbd.find(cell); if(it != _cbd.end() && it->second.geto() != 0) return true; return false; @@ -626,35 +631,35 @@ bool Cell::hasCoboundary(Cell* cell, bool orig) Cell::biter Cell::firstBoundary(bool orig) { biter it = _bd.begin(); - if(!orig) while(it->second.get() == 0 && it != _bd.end()) it++; - else while(it->second.geto() == 0 && it != _bd.end()) it++; + if(!orig) + while(it->second.get() == 0 && it != _bd.end()) it++; + else + while(it->second.geto() == 0 && it != _bd.end()) it++; return it; } -Cell::biter Cell::lastBoundary() -{ - return _bd.end(); -} +Cell::biter Cell::lastBoundary() { return _bd.end(); } Cell::biter Cell::firstCoboundary(bool orig) { biter it = _cbd.begin(); - if(!orig) while(it->second.get() == 0 && it != _cbd.end()) it++; - else while(it->second.geto() == 0 && it != _cbd.end()) it++; + if(!orig) + while(it->second.get() == 0 && it != _cbd.end()) it++; + else + while(it->second.geto() == 0 && it != _cbd.end()) it++; return it; } -Cell::biter Cell::lastCoboundary() -{ - return _cbd.end(); -} +Cell::biter Cell::lastCoboundary() { return _cbd.end(); } int Cell::getBoundarySize(bool orig) { int size = 0; - for(biter bit = _bd.begin(); bit != _bd.end(); bit++){ - if(!orig && bit->second.get() != 0) size++; - else if(orig && bit->second.geto() != 0) size++; + for(biter bit = _bd.begin(); bit != _bd.end(); bit++) { + if(!orig && bit->second.get() != 0) + size++; + else if(orig && bit->second.geto() != 0) + size++; } return size; } @@ -662,30 +667,32 @@ int Cell::getBoundarySize(bool orig) int Cell::getCoboundarySize(bool orig) { int size = 0; - for(biter bit = _cbd.begin(); bit != _cbd.end(); bit++){ - if(!orig && bit->second.get() != 0) size++; - else if(orig && bit->second.geto() != 0) size++; + for(biter bit = _cbd.begin(); bit != _cbd.end(); bit++) { + if(!orig && bit->second.get() != 0) + size++; + else if(orig && bit->second.geto() != 0) + size++; } return size; } -void Cell::getBoundary(std::map<Cell*, short int, Less_Cell>& boundary, +void Cell::getBoundary(std::map<Cell *, short int, Less_Cell> &boundary, bool orig) { boundary.clear(); - for(biter it = firstBoundary(); it != lastBoundary(); it++){ - Cell* cell = it->first; + for(biter it = firstBoundary(); it != lastBoundary(); it++) { + Cell *cell = it->first; if(!orig && it->second.get() != 0) boundary[cell] = it->second.get(); if(orig && it->second.geto() != 0) boundary[cell] = it->second.geto(); } } -void Cell::getCoboundary(std::map<Cell*, short int, Less_Cell>& coboundary, +void Cell::getCoboundary(std::map<Cell *, short int, Less_Cell> &coboundary, bool orig) { coboundary.clear(); - for(biter it = firstCoboundary(); it != lastCoboundary(); it++){ - Cell* cell = it->first; + for(biter it = firstCoboundary(); it != lastCoboundary(); it++) { + Cell *cell = it->first; if(!orig && it->second.get() != 0) coboundary[cell] = it->second.get(); if(orig && it->second.geto() != 0) coboundary[cell] = it->second.geto(); } @@ -693,33 +700,33 @@ void Cell::getCoboundary(std::map<Cell*, short int, Less_Cell>& coboundary, void Cell::printBoundary() { - for(biter it = firstBoundary(); it != lastBoundary(); it++){ + for(biter it = firstBoundary(); it != lastBoundary(); it++) { printf("Boundary cell orientation: %d ", it->second.get()); - Cell* cell2 = it->first; + Cell *cell2 = it->first; cell2->printCell(); } - if(firstBoundary() == lastBoundary()){ + if(firstBoundary() == lastBoundary()) { printf("Cell boundary is empty. \n"); } } void Cell::printCoboundary() { - for(biter it = firstCoboundary(); it != lastCoboundary(); it++){ + for(biter it = firstCoboundary(); it != lastCoboundary(); it++) { printf("Coboundary cell orientation: %d, ", it->second.get()); - Cell* cell2 = it->first; + Cell *cell2 = it->first; cell2->printCell(); - if(firstCoboundary() == lastCoboundary()){ + if(firstCoboundary() == lastCoboundary()) { printf("Cell coboundary is empty. \n"); } } } -CombinedCell::CombinedCell(Cell* c1, Cell* c2, bool orMatch, bool co) +CombinedCell::CombinedCell(Cell *c1, Cell *c2, bool orMatch, bool co) { // use "smaller" cell as c2 - if(c1->getNumCells() < c2->getNumCells()){ - Cell* temp = c1; + if(c1->getNumCells() < c2->getNumCells()) { + Cell *temp = c1; c1 = c2; c2 = temp; } @@ -731,56 +738,57 @@ CombinedCell::CombinedCell(Cell* c1, Cell* c2, bool orMatch, bool co) // cells c1->getCells(_cells); - std::map< Cell*, int, Less_Cell > c2Cells; + std::map<Cell *, int, Less_Cell> c2Cells; c2->getCells(c2Cells); - for(citer cit = c2Cells.begin(); cit != c2Cells.end(); cit++){ - if(!orMatch) (*cit).second = -1*(*cit).second; + for(citer cit = c2Cells.begin(); cit != c2Cells.end(); cit++) { + if(!orMatch) (*cit).second = -1 * (*cit).second; _cells.insert(*cit); } // boundary cells - for(biter it = c1->firstBoundary(); it != c1->lastBoundary(); it++){ - Cell* cell = it->first; + for(biter it = c1->firstBoundary(); it != c1->lastBoundary(); it++) { + Cell *cell = it->first; int ori = it->second.get(); if(ori == 0) continue; cell->removeCoboundaryCell(c1, false); this->addBoundaryCell(ori, cell, true); } - for(biter it = c2->firstBoundary(); it != c2->lastBoundary(); it++){ - Cell* cell = it->first; - if(!orMatch) it->second.set(-1*it->second.get()); + for(biter it = c2->firstBoundary(); it != c2->lastBoundary(); it++) { + Cell *cell = it->first; + if(!orMatch) it->second.set(-1 * it->second.get()); int ori = it->second.get(); if(ori == 0) continue; cell->removeCoboundaryCell(c2, false); - if(co && !c1->hasBoundary(cell)){ + if(co && !c1->hasBoundary(cell)) { this->addBoundaryCell(ori, cell, true); } - else if(!co) this->addBoundaryCell(ori, cell, true); + else if(!co) + this->addBoundaryCell(ori, cell, true); } // coboundary cells - for(biter it = c1->firstCoboundary(); it != c1->lastCoboundary(); it++){ - Cell* cell = it->first; + for(biter it = c1->firstCoboundary(); it != c1->lastCoboundary(); it++) { + Cell *cell = it->first; int ori = it->second.get(); if(ori == 0) continue; cell->removeBoundaryCell(c1, false); this->addCoboundaryCell(ori, cell, true); } - for(biter it = c2->firstCoboundary(); it != c2->lastCoboundary(); it++){ - Cell* cell = it->first; - if(!orMatch) it->second.set(-1*it->second.get()); + for(biter it = c2->firstCoboundary(); it != c2->lastCoboundary(); it++) { + Cell *cell = it->first; + if(!orMatch) it->second.set(-1 * it->second.get()); int ori = it->second.get(); if(ori == 0) continue; cell->removeBoundaryCell(c2, false); - if(!co && !c1->hasCoboundary(cell)){ + if(!co && !c1->hasCoboundary(cell)) { this->addCoboundaryCell(ori, cell, true); } - else if(co) this->addCoboundaryCell(ori, cell, true); + else if(co) + this->addCoboundaryCell(ori, cell, true); } - } -CombinedCell::CombinedCell(std::vector<Cell*>& cells) +CombinedCell::CombinedCell(std::vector<Cell *> &cells) { _num = ++_globalNum; _domain = cells.at(0)->getDomain(); @@ -788,8 +796,8 @@ CombinedCell::CombinedCell(std::vector<Cell*>& cells) _immune = false; // cells - for(unsigned int i = 0; i < cells.size(); i++){ - Cell* c = cells.at(i); + for(unsigned int i = 0; i < cells.size(); i++) { + Cell *c = cells.at(i); if(c->getImmune()) _immune = true; _cells[c] = 1; } diff --git a/Geo/Cell.h b/Geo/Cell.h index 06a8290fc1ba182738915e33f39d9d20992e4d44..66b40ec610a993db2ecd5c39d39f797b80905bef 100644 --- a/Geo/Cell.h +++ b/Geo/Cell.h @@ -16,31 +16,31 @@ class Cell; class Less_Cell { public: - bool operator()(const Cell* c1, const Cell* c2) const; + bool operator()(const Cell *c1, const Cell *c2) const; }; // Class to save cell boundary orientation information class BdInfo { - private: +private: signed char _ori[2]; - public: - BdInfo(int ori) { _ori[0] = ori; _ori[1] = 0; } +public: + BdInfo(int ori) + { + _ori[0] = ori; + _ori[1] = 0; + } int get() const { return _ori[0]; } void reset() { _ori[0] = _ori[1]; } void init() { _ori[1] = _ori[0]; } void set(int ori) { _ori[0] = ori; } int geto() const { return _ori[1]; } - }; - // Class representing an elementary cell of a cell complex. class Cell { - - protected: - +protected: static int _globalNum; int _num; @@ -52,29 +52,27 @@ class Cell { bool _immune; // list of cells on the boundary and on the coboundary of this cell - std::map<Cell*, BdInfo, Less_Cell> _bd; - std::map<Cell*, BdInfo, Less_Cell> _cbd; + std::map<Cell *, BdInfo, Less_Cell> _bd; + std::map<Cell *, BdInfo, Less_Cell> _cbd; Cell() {} - private: - +private: char _dim; - std::vector<MVertex*> _v; + std::vector<MVertex *> _v; // sorted vertices of this cell (used for ordering of the cells) std::vector<char> _si; inline bool _sortVertexIndices(); - public: - - static std::pair<Cell*, bool> createCell(MElement* element, int domain); - static std::pair<Cell*, bool> createCell(Cell* parent, int i); +public: + static std::pair<Cell *, bool> createCell(MElement *element, int domain); + static std::pair<Cell *, bool> createCell(Cell *parent, int i); - Cell(MElement* element, int domain); - Cell(Cell* parent, int i); + Cell(MElement *element, int domain); + Cell(Cell *parent, int i); - virtual ~Cell(){} + virtual ~Cell() {} int getDomain() const { return _domain; } void setDomain(int domain) { _domain = domain; } @@ -83,7 +81,7 @@ class Cell { int getTypeMSH() const; virtual int getDim() const { return _dim; } bool inSubdomain() const { return _domain ? true : false; } - void getMeshVertices(std::vector<MVertex*>& v) const { v = _v; } + void getMeshVertices(std::vector<MVertex *> &v) const { v = _v; } void setImmune(bool immune) { _immune = immune; }; bool getImmune() const { return _immune; }; @@ -91,11 +89,11 @@ class Cell { int getNumSortedVertices() const { return _si.size(); } inline int getSortedVertex(int vertex) const; int getNumVertices() const { return _v.size(); } - MVertex* getMeshVertex(int vertex) const { return _v.at(vertex); } + MVertex *getMeshVertex(int vertex) const { return _v.at(vertex); } - void findBdElement(int i, std::vector<MVertex*>& vertices) const; + void findBdElement(int i, std::vector<MVertex *> &vertices) const; int getNumBdElements() const; - int findBdCellOrientation(Cell* cell, int i) const; + int findBdCellOrientation(Cell *cell, int i) const; void increaseGlobalNum() { _globalNum++; } @@ -107,37 +105,38 @@ class Cell { virtual bool hasVertex(int vertex) const; // (co)boundary cell iterator - typedef std::map<Cell*, BdInfo, Less_Cell>::iterator biter; + typedef std::map<Cell *, BdInfo, Less_Cell>::iterator biter; // iterators to (first/last (co)boundary cells of this cell // (orig: to original (co)boundary cells of this cell) - biter firstBoundary(bool orig=false); + biter firstBoundary(bool orig = false); biter lastBoundary(); - biter firstCoboundary(bool orig=false); + biter firstCoboundary(bool orig = false); biter lastCoboundary(); - int getBoundarySize(bool orig=false); - int getCoboundarySize(bool orig=false); + int getBoundarySize(bool orig = false); + int getCoboundarySize(bool orig = false); // get the (orig: original) cell boundary - void getBoundary(std::map<Cell*, short int, Less_Cell>& boundary, - bool orig=false); - void getCoboundary(std::map<Cell*, short int, Less_Cell>& coboundary, - bool orig=false); + void getBoundary(std::map<Cell *, short int, Less_Cell> &boundary, + bool orig = false); + void getCoboundary(std::map<Cell *, short int, Less_Cell> &coboundary, + bool orig = false); // add (co)boundary cell // (other: reciprocally also add this cell from the other cell's (co)boundary) - void addBoundaryCell(int orientation, Cell* cell, bool other); - void addCoboundaryCell(int orientation, Cell* cell, bool other); + void addBoundaryCell(int orientation, Cell *cell, bool other); + void addCoboundaryCell(int orientation, Cell *cell, bool other); // remove (co)boundary cell - // (other: reciprocally also revove this cell from the other cell's (co)boundary) - void removeBoundaryCell(Cell* cell, bool other); - void removeCoboundaryCell(Cell* cell, bool other); + // (other: reciprocally also revove this cell from the other cell's + // (co)boundary) + void removeBoundaryCell(Cell *cell, bool other); + void removeCoboundaryCell(Cell *cell, bool other); // true if has given cell on (orig: original) (co)boundary - bool hasBoundary(Cell* cell, bool orig=false); - bool hasCoboundary(Cell* cell, bool orig=false); + bool hasBoundary(Cell *cell, bool orig = false); + bool hasCoboundary(Cell *cell, bool orig = false); // print cell debug info virtual void printCell(); @@ -147,42 +146,40 @@ class Cell { // tools for combined cells bool isCombined() const { return _combined; } - typedef std::map<Cell*, int, Less_Cell>::iterator citer; - virtual void getCells(std::map<Cell*, int, Less_Cell>& cells) { + typedef std::map<Cell *, int, Less_Cell>::iterator citer; + virtual void getCells(std::map<Cell *, int, Less_Cell> &cells) + { cells.clear(); cells[this] = 1; } virtual int getNumCells() const { return 1; } - bool operator==(const Cell& c2) const { + bool operator==(const Cell &c2) const + { return (this->getNum() == c2.getNum()); } - }; - // A cell that is a combination of cells of same dimension -class CombinedCell : public Cell{ - - private: +class CombinedCell : public Cell { +private: // list of cells this cell is a combination of - std::map< Cell*, int, Less_Cell > _cells; + std::map<Cell *, int, Less_Cell> _cells; - public: - - CombinedCell(Cell* c1, Cell* c2, bool orMatch, bool co=false); - CombinedCell(std::vector<Cell*>& cells); +public: + CombinedCell(Cell *c1, Cell *c2, bool orMatch, bool co = false); + CombinedCell(std::vector<Cell *> &cells); ~CombinedCell() {} int getDim() const { return _cells.begin()->first->getDim(); } - void getCells(std::map< Cell*, int, Less_Cell >& cells) { cells = _cells; } - int getNumCells() const {return _cells.size();} + void getCells(std::map<Cell *, int, Less_Cell> &cells) { cells = _cells; } + int getNumCells() const { return _cells.size(); } bool hasVertex(int vertex) const; - bool operator==(const Cell& c2) const { + bool operator==(const Cell &c2) const + { return (this->getNum() == c2.getNum()); } }; - #endif diff --git a/Geo/CellComplex.cpp b/Geo/CellComplex.cpp index 50d44c32e935f4eb9146a30daaaaeb56a7b137f9..64467d34bb16a719b42565a26ae77000da44ad8b 100644 --- a/Geo/CellComplex.cpp +++ b/Geo/CellComplex.cpp @@ -11,15 +11,14 @@ double CellComplex::_patience = 10; -CellComplex::CellComplex(GModel* model, - std::vector<MElement*>& domainElements, - std::vector<MElement*>& subdomainElements, - std::vector<MElement*>& nondomainElements, - std::vector<MElement*>& nonsubdomainElements, - std::vector<MElement*>& immuneElements, - bool saveOriginalComplex) : - _model(model), _dim(0), _simplicial(true), _saveorig(saveOriginalComplex), - _relative(false) +CellComplex::CellComplex(GModel *model, std::vector<MElement *> &domainElements, + std::vector<MElement *> &subdomainElements, + std::vector<MElement *> &nondomainElements, + std::vector<MElement *> &nonsubdomainElements, + std::vector<MElement *> &immuneElements, + bool saveOriginalComplex) + : _model(model), _dim(0), _simplicial(true), _saveorig(saveOriginalComplex), + _relative(false) { _smallestCell.second = -1.; _biggestCell.second = -1.; @@ -37,11 +36,11 @@ CellComplex::CellComplex(GModel* model, _removeCells(nondomainElements, 0); _immunizeCells(immuneElements); int num = 0; - for(int dim = 0; dim < 4; dim++){ + for(int dim = 0; dim < 4; dim++) { if(getSize(dim) != 0) _dim = dim; if(_saveorig) _ocells[dim] = _cells[dim]; - for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){ - Cell* cell = *cit; + for(citer cit = firstCell(dim); cit != lastCell(dim); cit++) { + Cell *cell = *cit; cell->setNum(++num); cell->increaseGlobalNum(); cell->saveCellBoundary(); @@ -52,23 +51,22 @@ CellComplex::CellComplex(GModel* model, Msg::Debug("Cells in domain:"); Msg::Debug(" %d volumes, %d faces %d edges, and %d vertices", - getNumCells(3, 1), getNumCells(2, 1), - getNumCells(1, 1), getNumCells(0, 1)); + getNumCells(3, 1), getNumCells(2, 1), getNumCells(1, 1), + getNumCells(0, 1)); Msg::Debug("Cells in subdomain:"); Msg::Debug(" %d volumes, %d faces %d edges, and %d vertices", - getNumCells(3, 2), getNumCells(2, 2), - getNumCells(1, 2), getNumCells(0, 2)); + getNumCells(3, 2), getNumCells(2, 2), getNumCells(1, 2), + getNumCells(0, 2)); Msg::Debug("Cells in relative domain:"); Msg::Debug(" %d volumes, %d faces %d edges, and %d vertices", - getNumCells(3, 0), getNumCells(2, 0), - getNumCells(1, 0), getNumCells(0, 0)); + getNumCells(3, 0), getNumCells(2, 0), getNumCells(1, 0), + getNumCells(0, 0)); } -bool CellComplex::_insertCells(std::vector<MElement*>& elements, - int domain) +bool CellComplex::_insertCells(std::vector<MElement *> &elements, int domain) { - std::pair<Cell*, double> smallestElement[4]; - std::pair<Cell*, double> biggestElement[4]; + std::pair<Cell *, double> smallestElement[4]; + std::pair<Cell *, double> biggestElement[4]; for(int i = 0; i < 4; i++) { smallestElement[i].second = -1.; biggestElement[i].second = -1.; @@ -77,33 +75,33 @@ bool CellComplex::_insertCells(std::vector<MElement*>& elements, double t1 = Cpu(); - for(unsigned int i=0; i < elements.size(); i++){ - - MElement* element = elements.at(i); + for(unsigned int i = 0; i < elements.size(); i++) { + MElement *element = elements.at(i); int dim = element->getDim(); int type = element->getType(); if(type == TYPE_POLYG || type == TYPE_POLYH) { - Msg::Error("Mesh element type %d not implemented in homology solver", type); + Msg::Error("Mesh element type %d not implemented in homology solver", + type); } - if(type == TYPE_QUA || type == TYPE_HEX || - type == TYPE_PYR || type == TYPE_PRI) + if(type == TYPE_QUA || type == TYPE_HEX || type == TYPE_PYR || + type == TYPE_PRI) _simplicial = false; - std::pair<Cell*, bool> maybeCell = Cell::createCell(element, domain); + std::pair<Cell *, bool> maybeCell = Cell::createCell(element, domain); if(!maybeCell.second) { delete maybeCell.first; continue; } if(_dim < dim) _dim = dim; - Cell* cell = maybeCell.first; - std::pair<citer, bool> insert = - _cells[cell->getDim()].insert(cell); + Cell *cell = maybeCell.first; + std::pair<citer, bool> insert = _cells[cell->getDim()].insert(cell); if(!insert.second) { delete cell; cell = *(insert.first); if(domain) cell->setDomain(domain); } - else _createCount++; + else + _createCount++; if(domain == 0) { double size = fabs(element->getVolume()); @@ -116,104 +114,107 @@ bool CellComplex::_insertCells(std::vector<MElement*>& elements, _smallestCell = smallestElement[_dim]; _biggestCell = biggestElement[_dim]; - for (int dim = 3; dim > 0; dim--){ - + for(int dim = 3; dim > 0; dim--) { double t2 = Cpu(); - if(t2-t1 > CellComplex::_patience && dim > 1) { + if(t2 - t1 > CellComplex::_patience && dim > 1) { if(domain == 0) Msg::Info(" ... creating domain %d-cells", dim); else if(domain == 1) Msg::Info(" ... creating subdomain %d-cells", dim); } - for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){ - Cell* cell = *cit; - for(int i = 0; i < cell->getNumBdElements(); i++){ - std::pair<Cell*, bool> maybeCell = Cell::createCell(cell, i); + for(citer cit = firstCell(dim); cit != lastCell(dim); cit++) { + Cell *cell = *cit; + for(int i = 0; i < cell->getNumBdElements(); i++) { + std::pair<Cell *, bool> maybeCell = Cell::createCell(cell, i); if(!maybeCell.second) { delete maybeCell.first; continue; } - Cell* newCell = maybeCell.first; - std::pair<citer, bool> insert = - _cells[newCell->getDim()].insert(newCell); - if(!insert.second) { - delete newCell; - newCell = *(insert.first); + Cell *newCell = maybeCell.first; + std::pair<citer, bool> insert = + _cells[newCell->getDim()].insert(newCell); + if(!insert.second) { + delete newCell; + newCell = *(insert.first); if(domain) newCell->setDomain(domain); - } - else _createCount++; - if(domain == 0) { - int ori = cell->findBdCellOrientation(newCell, i); - cell->addBoundaryCell( ori, newCell, true); + } + else + _createCount++; + if(domain == 0) { + int ori = cell->findBdCellOrientation(newCell, i); + cell->addBoundaryCell(ori, newCell, true); if(_smallestCell.first == cell) _smallestCell = std::make_pair(newCell, _smallestCell.second); if(_biggestCell.first == cell) _biggestCell = std::make_pair(newCell, _biggestCell.second); - } + } } } } return true; } -bool CellComplex::_removeCells(std::vector<MElement*>& elements, - int domain) +bool CellComplex::_removeCells(std::vector<MElement *> &elements, int domain) { if(elements.empty()) return true; Msg::Debug("Removing %d elements and their subcells from the cell complex.", (int)elements.size()); - std::set<Cell*, Less_Cell> removed[4]; + std::set<Cell *, Less_Cell> removed[4]; - for(unsigned int i=0; i < elements.size(); i++){ - MElement* element = elements.at(i); + for(unsigned int i = 0; i < elements.size(); i++) { + MElement *element = elements.at(i); int type = element->getType(); - if(type == TYPE_PYR || type == TYPE_PRI || - type == TYPE_POLYG || type == TYPE_POLYH) { - Msg::Error("Mesh element type %d not implemented in homology solver", type); + if(type == TYPE_PYR || type == TYPE_PRI || type == TYPE_POLYG || + type == TYPE_POLYH) { + Msg::Error("Mesh element type %d not implemented in homology solver", + type); return false; } - Cell* cell = new Cell(element, domain); + Cell *cell = new Cell(element, domain); int dim = cell->getDim(); citer cit = _cells[dim].find(cell); if(cit != lastCell(dim)) { removeCell(*cit); removed[dim].insert(cell); } - else delete cell; + else + delete cell; } - for (int dim = 3; dim > 0; dim--){ - for(citer cit = removed[dim].begin(); cit != removed[dim].end(); cit++){ - Cell* cell = *cit; - for(int i = 0; i < cell->getNumBdElements(); i++){ - Cell* newCell = new Cell(cell, i); + for(int dim = 3; dim > 0; dim--) { + for(citer cit = removed[dim].begin(); cit != removed[dim].end(); cit++) { + Cell *cell = *cit; + for(int i = 0; i < cell->getNumBdElements(); i++) { + Cell *newCell = new Cell(cell, i); - citer cit2 = _cells[dim-1].find(newCell); - if(cit2 != lastCell(dim-1)) { + citer cit2 = _cells[dim - 1].find(newCell); + if(cit2 != lastCell(dim - 1)) { removeCell(*cit2); - removed[dim-1].insert(newCell); + removed[dim - 1].insert(newCell); } - else delete newCell; + else + delete newCell; } } } - for (int dim = 3; dim >= 0; dim--){ - for(citer cit = removed[dim].begin(); cit != removed[dim].end(); cit++){ + for(int dim = 3; dim >= 0; dim--) { + for(citer cit = removed[dim].begin(); cit != removed[dim].end(); cit++) { delete *cit; } } - Msg::Debug("Removed %d volumes, %d faces, %d edges, and %d vertices from the cell complex.", + Msg::Debug("Removed %d volumes, %d faces, %d edges, and %d vertices from the " + "cell complex.", (int)removed[3].size(), (int)removed[2].size(), (int)removed[1].size(), (int)removed[0].size()); return true; } -bool CellComplex::_immunizeCells(std::vector<MElement*>& elements) +bool CellComplex::_immunizeCells(std::vector<MElement *> &elements) { - for(unsigned int i=0; i < elements.size(); i++){ - MElement* element = elements.at(i); - Cell* cell = new Cell(element, 0); + for(unsigned int i = 0; i < elements.size(); i++) { + MElement *element = elements.at(i); + Cell *cell = new Cell(element, 0); int dim = cell->getDim(); citer cit = _cells[dim].find(cell); if(cit != lastCell(dim)) (*cit)->setImmune(true); @@ -224,9 +225,9 @@ bool CellComplex::_immunizeCells(std::vector<MElement*>& elements) CellComplex::~CellComplex() { - for(int i = 0; i < 4; i++){ - for(citer cit = _cells[i].begin(); cit != _cells[i].end(); cit++){ - Cell* cell = *cit; + for(int i = 0; i < 4; i++) { + for(citer cit = _cells[i].begin(); cit != _cells[i].end(); cit++) { + Cell *cell = *cit; delete cell; _deleteCount++; } @@ -241,95 +242,99 @@ CellComplex::~CellComplex() Msg::Debug("Total number of cells deleted: %d", _deleteCount); } -void CellComplex::insertCell(Cell* cell) +void CellComplex::insertCell(Cell *cell) { std::pair<citer, bool> insertInfo = _cells[cell->getDim()].insert(cell); - if(!insertInfo.second){ + if(!insertInfo.second) { Msg::Debug("Cell not inserted"); - Cell* oldCell = (*insertInfo.first); + Cell *oldCell = (*insertInfo.first); cell->printCell(); oldCell->printCell(); } } -void CellComplex::removeCell(Cell* cell, bool other, bool del) +void CellComplex::removeCell(Cell *cell, bool other, bool del) { - std::map<Cell*, short int, Less_Cell > coboundary; + std::map<Cell *, short int, Less_Cell> coboundary; cell->getCoboundary(coboundary); - std::map<Cell*, short int, Less_Cell > boundary; + std::map<Cell *, short int, Less_Cell> boundary; cell->getBoundary(boundary); - for(std::map<Cell*, short int, Less_Cell>::iterator it = - coboundary.begin(); it != coboundary.end(); it++){ - Cell* cbdCell = (*it).first; + for(std::map<Cell *, short int, Less_Cell>::iterator it = coboundary.begin(); + it != coboundary.end(); it++) { + Cell *cbdCell = (*it).first; cbdCell->removeBoundaryCell(cell, other); } - for(std::map<Cell*, short int, Less_Cell>::iterator it = - boundary.begin(); it != boundary.end(); it++){ - Cell* bdCell = (*it).first; + for(std::map<Cell *, short int, Less_Cell>::iterator it = boundary.begin(); + it != boundary.end(); it++) { + Cell *bdCell = (*it).first; bdCell->removeCoboundaryCell(cell, other); } int dim = cell->getDim(); int erased = _cells[dim].erase(cell); if(relative()) { - if(cell->inSubdomain()) _numSubdomainCells[dim] -= 1; - else _numRelativeCells[dim] -= 1; + if(cell->inSubdomain()) + _numSubdomainCells[dim] -= 1; + else + _numRelativeCells[dim] -= 1; } - if(!erased) Msg::Debug("Tried to remove a cell from the cell complex \n"); - else if(!del) _removedcells.push_back(cell); + if(!erased) + Msg::Debug("Tried to remove a cell from the cell complex \n"); + else if(!del) + _removedcells.push_back(cell); } -void CellComplex::enqueueCells(std::map<Cell*, short int, Less_Cell>& cells, - std::queue<Cell*>& Q, - std::set<Cell*, Less_Cell>& Qset) +void CellComplex::enqueueCells(std::map<Cell *, short int, Less_Cell> &cells, + std::queue<Cell *> &Q, + std::set<Cell *, Less_Cell> &Qset) { - for(std::map<Cell*, short int, Less_Cell>::iterator cit = cells.begin(); - cit != cells.end(); cit++){ - Cell* cell = (*cit).first; + for(std::map<Cell *, short int, Less_Cell>::iterator cit = cells.begin(); + cit != cells.end(); cit++) { + Cell *cell = (*cit).first; citer it = Qset.find(cell); - if(it == Qset.end()){ + if(it == Qset.end()) { Qset.insert(cell); Q.push(cell); } } } -int CellComplex::coreduction(Cell* startCell, int omit, - std::vector<Cell*>& omittedCells) +int CellComplex::coreduction(Cell *startCell, int omit, + std::vector<Cell *> &omittedCells) { int coreductions = 0; - std::queue<Cell*> Q; - std::set<Cell*, Less_Cell> Qset; + std::queue<Cell *> Q; + std::set<Cell *, Less_Cell> Qset; Q.push(startCell); Qset.insert(startCell); - std::map<Cell*, short int, Less_Cell > bd_s; - std::map<Cell*, short int, Less_Cell > cbd_c; + std::map<Cell *, short int, Less_Cell> bd_s; + std::map<Cell *, short int, Less_Cell> cbd_c; - Cell* s; - while( !Q.empty() ){ + Cell *s; + while(!Q.empty()) { s = Q.front(); Q.pop(); Qset.erase(s); if(s->getBoundarySize() == 1 && - inSameDomain(s, s->firstBoundary()->first) && - !s->getImmune() && !s->firstBoundary()->first->getImmune() && - abs(s->firstBoundary()->second.get()) < 2){ + inSameDomain(s, s->firstBoundary()->first) && !s->getImmune() && + !s->firstBoundary()->first->getImmune() && + abs(s->firstBoundary()->second.get()) < 2) { s->getBoundary(bd_s); removeCell(s); bd_s.begin()->first->getCoboundary(cbd_c); enqueueCells(cbd_c, Q, Qset); removeCell(bd_s.begin()->first); - if(bd_s.begin()->first->getDim() == omit){ - omittedCells.push_back(bd_s.begin()->first); + if(bd_s.begin()->first->getDim() == omit) { + omittedCells.push_back(bd_s.begin()->first); } coreductions++; } - else if(s->getBoundarySize() == 0){ + else if(s->getBoundarySize() == 0) { s->getCoboundary(cbd_c); enqueueCells(cbd_c, Q, Qset); } @@ -338,8 +343,7 @@ int CellComplex::coreduction(Cell* startCell, int omit, return coreductions; } -int CellComplex::reduction(int dim, int omit, - std::vector<Cell*>& omittedCells) +int CellComplex::reduction(int dim, int omit, std::vector<Cell *> &omittedCells) { if(dim < 1 || dim > 3) return 0; @@ -349,40 +353,39 @@ int CellComplex::reduction(int dim, int omit, int count = 0; bool reduced = true; - while (reduced){ - + while(reduced) { reduced = false; - citer cit = firstCell(dim-1); - while(cit != lastCell(dim-1)){ - Cell* cell = *cit; + citer cit = firstCell(dim - 1); + while(cit != lastCell(dim - 1)) { + Cell *cell = *cit; if(cell->getCoboundarySize() == 1 && inSameDomain(cell, cell->firstCoboundary()->first) && !cell->getImmune() && !cell->firstCoboundary()->first->getImmune() && !cell->firstCoboundary()->first->getImmune() && - abs(cell->firstCoboundary()->second.get()) < 2){ - cit++; - if(dim == omit){ - omittedCells.push_back(cell->firstCoboundary()->first); - } - removeCell(cell->firstCoboundary()->first); - removeCell(cell); - count++; - reduced = true; + abs(cell->firstCoboundary()->second.get()) < 2) { + cit++; + if(dim == omit) { + omittedCells.push_back(cell->firstCoboundary()->first); + } + removeCell(cell->firstCoboundary()->first); + removeCell(cell); + count++; + reduced = true; } - if(getSize(dim) == 0 || getSize(dim-1) == 0) break; - if(cit != lastCell(dim-1)) cit++; + if(getSize(dim) == 0 || getSize(dim - 1) == 0) break; + if(cit != lastCell(dim - 1)) cit++; } } _reduced = true; Msg::Debug("Cell complex %d-reduction removed %dv, %df, %de, %dn", dim, - numCells[3]-getSize(3), numCells[2]-getSize(2), - numCells[1]-getSize(1), numCells[0]-getSize(0)); + numCells[3] - getSize(3), numCells[2] - getSize(2), + numCells[1] - getSize(1), numCells[0] - getSize(0)); return count; } int CellComplex::coreduction(int dim, int omit, - std::vector<Cell*>& omittedCells) + std::vector<Cell *> &omittedCells) { if(dim < 1 || dim > 3) return 0; @@ -392,49 +395,53 @@ int CellComplex::coreduction(int dim, int omit, int count = 0; bool reduced = true; - while (reduced){ - + while(reduced) { reduced = false; citer cit = firstCell(dim); - while(cit != lastCell(dim)){ - Cell* cell = *cit; + while(cit != lastCell(dim)) { + Cell *cell = *cit; if(cell->getBoundarySize() == 1 && inSameDomain(cell, cell->firstBoundary()->first) && !cell->getImmune() && !cell->firstBoundary()->first->getImmune() && abs(cell->firstBoundary()->second.get()) < 2) { ++cit; - if(dim-1 == omit){ - omittedCells.push_back(cell->firstBoundary()->first); - } + if(dim - 1 == omit) { + omittedCells.push_back(cell->firstBoundary()->first); + } removeCell(cell->firstBoundary()->first); removeCell(cell); count++; reduced = true; } - if(getSize(dim) == 0 || getSize(dim-1) == 0) break; + if(getSize(dim) == 0 || getSize(dim - 1) == 0) break; if(cit != lastCell(dim)) cit++; } } _reduced = true; Msg::Debug("Cell complex %d-coreduction removed %dv, %df, %de, %dn", dim, - numCells[3]-getSize(3), numCells[2]-getSize(2), - numCells[1]-getSize(1), numCells[0]-getSize(0)); + numCells[3] - getSize(3), numCells[2] - getSize(2), + numCells[1] - getSize(1), numCells[0] - getSize(0)); return count; } -int CellComplex::getSize(int dim, bool orig) { +int CellComplex::getSize(int dim, bool orig) +{ if(dim == -1) { unsigned int size = 0; - if(!orig) for(int i = 0; i < 4; i++) size += _cells[i].size(); - else for(int i = 0; i < 4; i++) size += _ocells[i].size(); + if(!orig) + for(int i = 0; i < 4; i++) size += _cells[i].size(); + else + for(int i = 0; i < 4; i++) size += _ocells[i].size(); return size; } - if(!orig) return _cells[dim].size(); - else return _ocells[dim].size(); + if(!orig) + return _cells[dim].size(); + else + return _ocells[dim].size(); } -int CellComplex::getDomain(Cell* cell, std::string& str) +int CellComplex::getDomain(Cell *cell, std::string &str) { int domain = 0; if(cell->inSubdomain()) { @@ -454,11 +461,11 @@ int CellComplex::getDomain(Cell* cell, std::string& str) return domain; } -Cell* CellComplex::_omitCell(Cell* cell, bool dual) +Cell *CellComplex::_omitCell(Cell *cell, bool dual) { Msg::Debug("Omitting %d-cell from the cell complex", cell->getDim()); removeCell(cell, false); - std::vector<Cell*> omittedCells; + std::vector<Cell *> omittedCells; omittedCells.push_back(cell); int count = 0; @@ -475,19 +482,17 @@ Cell* CellComplex::_omitCell(Cell* cell, bool dual) count += coreduction(j, cell->getDim(), omittedCells); } - CombinedCell* newcell = new CombinedCell(omittedCells); + CombinedCell *newcell = new CombinedCell(omittedCells); _createCount++; std::string domainstr = ""; int domain = getDomain(cell, domainstr); - Msg::Debug("Cell complex %d-omit removed %dv, %df, %de, %dn", - cell->getDim(), - numCells[3]-getSize(3), numCells[2]-getSize(2), - numCells[1]-getSize(1), numCells[0]-getSize(0)); - Msg::Debug(" - number of %d-cells left in %s: %d", - cell->getDim(), domainstr.c_str(), - getNumCells(cell->getDim(), domain)); + Msg::Debug("Cell complex %d-omit removed %dv, %df, %de, %dn", cell->getDim(), + numCells[3] - getSize(3), numCells[2] - getSize(2), + numCells[1] - getSize(1), numCells[0] - getSize(0)); + Msg::Debug(" - number of %d-cells left in %s: %d", cell->getDim(), + domainstr.c_str(), getNumCells(cell->getDim(), domain)); return newcell; } @@ -499,46 +504,50 @@ int CellComplex::reduceComplex(int combine, bool omit, bool homseq) double t1 = Cpu(); int count = 0; if(relative() && !homseq) removeSubdomain(); - std::vector<Cell*> empty; + std::vector<Cell *> empty; for(int i = 3; i > 0; i--) count = count + reduction(i, -1, empty); - if(omit && !homseq){ - - std::vector<Cell*> newCells; - - while (getSize(getDim()) != 0){ + if(omit && !homseq) { + std::vector<Cell *> newCells; + while(getSize(getDim()) != 0) { citer cit = firstCell(getDim()); - Cell* cell = *cit; + Cell *cell = *cit; newCells.push_back(_omitCell(cell, false)); } - for(unsigned int i = 0; i < newCells.size(); i++){ + for(unsigned int i = 0; i < newCells.size(); i++) { insertCell(newCells.at(i)); } } double t2 = Cpu(); - if(t2-t1 > CellComplex::_patience) { - Msg::Info(" .. %d volumes, %d faces, %d edges, and %d vertices", - getSize(3), getSize(2), getSize(1), getSize(0)); + if(t2 - t1 > CellComplex::_patience) { + Msg::Info(" .. %d volumes, %d faces, %d edges, and %d vertices", getSize(3), + getSize(2), getSize(1), getSize(0)); } if(combine > 0) this->combine(3); - if(combine > 2) for(int i = 3; i > 0; i--) reduction(i, -1, empty); - else if(combine > 1) reduction(2, -1, empty); + if(combine > 2) + for(int i = 3; i > 0; i--) reduction(i, -1, empty); + else if(combine > 1) + reduction(2, -1, empty); if(combine > 0) this->combine(2); - if(combine > 2) for(int i = 3; i > 0; i--) reduction(i, -1, empty); - else if(combine > 1) reduction(1, -1, empty); + if(combine > 2) + for(int i = 3; i > 0; i--) reduction(i, -1, empty); + else if(combine > 1) + reduction(1, -1, empty); if(combine > 0) this->combine(1); - if(combine > 2) for(int i = 3; i > 0; i--) reduction(i, -1, empty); - else if(combine > 1) reduction(0, -1, empty); + if(combine > 2) + for(int i = 3; i > 0; i--) reduction(i, -1, empty); + else if(combine > 1) + reduction(0, -1, empty); _reduced = true; return count; @@ -546,9 +555,9 @@ int CellComplex::reduceComplex(int combine, bool omit, bool homseq) void CellComplex::removeSubdomain() { - std::vector<Cell*> toRemove; - for(int i = 0; i < 4; i++){ - for(citer cit = firstCell(i); cit != lastCell(i); ++cit){ + std::vector<Cell *> toRemove; + for(int i = 0; i < 4; i++) { + for(citer cit = firstCell(i); cit != lastCell(i); ++cit) { Cell *cell = *cit; if(cell->inSubdomain()) toRemove.push_back(cell); } @@ -560,8 +569,8 @@ void CellComplex::removeSubdomain() void CellComplex::removeCells(int dim) { if(dim < 0 || dim > 3) return; - std::vector<Cell*> toRemove; - for(citer cit = firstCell(dim); cit != lastCell(dim); ++cit){ + std::vector<Cell *> toRemove; + for(citer cit = firstCell(dim); cit != lastCell(dim); ++cit) { toRemove.push_back(*cit); } for(unsigned int i = 0; i < toRemove.size(); i++) removeCell(toRemove[i]); @@ -576,27 +585,24 @@ int CellComplex::coreduceComplex(int combine, bool omit, int heuristic) int count = 0; if(relative()) removeSubdomain(); - std::vector<Cell*> empty; - for(int dim = 0; dim < 4; dim++){ + std::vector<Cell *> empty; + for(int dim = 0; dim < 4; dim++) { citer cit = firstCell(dim); - while(cit != lastCell(dim)){ - Cell* cell = *cit; - int count =+ coreduction(cell, -1, empty); + while(cit != lastCell(dim)) { + Cell *cell = *cit; + int count = +coreduction(cell, -1, empty); if(count != 0) break; cit++; } } - for(int j = 1; j <= getDim(); j++) - count += coreduction(j, -1, empty); - - if(omit){ - - std::vector<Cell*> newCells; - while (getSize(0) != 0){ + for(int j = 1; j <= getDim(); j++) count += coreduction(j, -1, empty); + if(omit) { + std::vector<Cell *> newCells; + while(getSize(0) != 0) { citer cit = firstCell(0); - Cell* cell = *cit; + Cell *cell = *cit; if(heuristic == -1 && _smallestCell.second != 0. && hasCell(_smallestCell.first)) { @@ -613,32 +619,37 @@ int CellComplex::coreduceComplex(int combine, bool omit, int heuristic) newCells.push_back(_omitCell(cell, true)); } - for(unsigned int i = 0; i < newCells.size(); i++){ + for(unsigned int i = 0; i < newCells.size(); i++) { insertCell(newCells.at(i)); } - } double t2 = Cpu(); - if(t2-t1 > CellComplex::_patience) { - Msg::Info(" .. %d volumes, %d faces, %d edges, and %d vertices", - getSize(3), getSize(2), getSize(1), getSize(0)); + if(t2 - t1 > CellComplex::_patience) { + Msg::Info(" .. %d volumes, %d faces, %d edges, and %d vertices", getSize(3), + getSize(2), getSize(1), getSize(0)); } if(combine > 0) this->cocombine(0); - if(combine > 2) for(int i = 1; i < 4; i++) coreduction(i, -1, empty); - else if(combine > 1) coreduction(1, -1, empty); + if(combine > 2) + for(int i = 1; i < 4; i++) coreduction(i, -1, empty); + else if(combine > 1) + coreduction(1, -1, empty); if(combine > 0) this->cocombine(1); - if(combine > 2) for(int i = 1; i < 4; i++) coreduction(i, -1, empty); - else if(combine > 1) coreduction(2, -1, empty); + if(combine > 2) + for(int i = 1; i < 4; i++) coreduction(i, -1, empty); + else if(combine > 1) + coreduction(2, -1, empty); if(combine > 0) this->cocombine(2); - if(combine > 2) for(int i = 1; i < 4; i++) coreduction(i, -1, empty); - else if(combine > 1) coreduction(3, -1, empty); + if(combine > 2) + for(int i = 1; i < 4; i++) coreduction(i, -1, empty); + else if(combine > 1) + coreduction(3, -1, empty); coherent(); @@ -649,7 +660,7 @@ int CellComplex::coreduceComplex(int combine, bool omit, int heuristic) void CellComplex::bettiReduceComplex() { reduceComplex(3, true); - for(int i = 1; i <= 3; i++) cocombine(i-1); + for(int i = 1; i <= 3; i++) cocombine(i - 1); return; } @@ -662,41 +673,38 @@ int CellComplex::combine(int dim) double t1 = Cpu(); - std::queue<Cell*> Q; - std::set<Cell*, Less_Cell> Qset; - std::map<Cell*, short int, Less_Cell> bd_c; + std::queue<Cell *> Q; + std::set<Cell *, Less_Cell> Qset; + std::map<Cell *, short int, Less_Cell> bd_c; int count = 0; - for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){ - + for(citer cit = firstCell(dim); cit != lastCell(dim); cit++) { double t2 = Cpu(); - if(t2-t1 > CellComplex::_patience) { + if(t2 - t1 > CellComplex::_patience) { t1 = Cpu(); Msg::Info(" ... %d volumes, %d faces, %d edges, and %d vertices", getSize(3), getSize(2), getSize(1), getSize(0)); } - Cell* cell = *cit; + Cell *cell = *cit; cell->getBoundary(bd_c); enqueueCells(bd_c, Q, Qset); - while(Q.size() != 0){ - Cell* s = Q.front(); + while(Q.size() != 0) { + Cell *s = Q.front(); Q.pop(); - if(s->getCoboundarySize() == 2 && !s->getImmune()){ - Cell::biter it = s->firstCoboundary(); + if(s->getCoboundarySize() == 2 && !s->getImmune()) { + Cell::biter it = s->firstCoboundary(); int or1 = it->second.get(); - Cell* c1 = it->first; - it++; - while (it->second.get() == 0) it++; + Cell *c1 = it->first; + it++; + while(it->second.get() == 0) it++; int or2 = it->second.get(); - Cell* c2 = it->first; - - if(!(*c1 == *c2) && abs(or1) == abs(or2) && - inSameDomain(s, c1) && inSameDomain(s, c2) && - c1->getImmune() == c2->getImmune() ) { + Cell *c2 = it->first; + if(!(*c1 == *c2) && abs(or1) == abs(or2) && inSameDomain(s, c1) && + inSameDomain(s, c2) && c1->getImmune() == c2->getImmune()) { removeCell(s, true, false); c1->getBoundary(bd_c); @@ -704,7 +712,7 @@ int CellComplex::combine(int dim) c2->getBoundary(bd_c); enqueueCells(bd_c, Q, Qset); - CombinedCell* newCell = new CombinedCell(c1, c2, (or1 != or2)); + CombinedCell *newCell = new CombinedCell(c1, c2, (or1 != or2)); _createCount++; removeCell(c1, true, c1->isCombined()); removeCell(c2, true, c2->isCombined()); @@ -721,7 +729,6 @@ int CellComplex::combine(int dim) delete c2; _deleteCount++; } - } } Qset.erase(s); @@ -729,8 +736,8 @@ int CellComplex::combine(int dim) } Msg::Debug("Cell complex %d-combine removed %dv, %df, %de, %dn", dim, - numCells[3]-getSize(3), numCells[2]-getSize(2), - numCells[1]-getSize(1), numCells[0]-getSize(0)); + numCells[3] - getSize(3), numCells[2] - getSize(2), + numCells[1] - getSize(1), numCells[0] - getSize(0)); _reduced = true; return count; } @@ -744,42 +751,38 @@ int CellComplex::cocombine(int dim) double t1 = Cpu(); - std::queue<Cell*> Q; - std::set<Cell*, Less_Cell> Qset; - std::map<Cell*, short int, Less_Cell> cbd_c; + std::queue<Cell *> Q; + std::set<Cell *, Less_Cell> Qset; + std::map<Cell *, short int, Less_Cell> cbd_c; int count = 0; - for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){ - + for(citer cit = firstCell(dim); cit != lastCell(dim); cit++) { double t2 = Cpu(); - if(t2-t1 > CellComplex::_patience) { + if(t2 - t1 > CellComplex::_patience) { t1 = Cpu(); Msg::Info(" ... %d volumes, %d faces, %d edges, and %d vertices", getSize(3), getSize(2), getSize(1), getSize(0)); } - Cell* cell = *cit; + Cell *cell = *cit; cell->getCoboundary(cbd_c); enqueueCells(cbd_c, Q, Qset); - while(Q.size() != 0){ - Cell* s = Q.front(); + while(Q.size() != 0) { + Cell *s = Q.front(); Q.pop(); - if(s->getBoundarySize() == 2){ - - Cell::biter it = s->firstBoundary(); + if(s->getBoundarySize() == 2) { + Cell::biter it = s->firstBoundary(); int or1 = it->second.get(); - Cell* c1 = it->first; - it++; - while (it->second.get() == 0) it++; + Cell *c1 = it->first; + it++; + while(it->second.get() == 0) it++; int or2 = it->second.get(); - Cell* c2 = it->first; - - if(!(*c1 == *c2) && abs(or1) == abs(or2) - && inSameDomain(s, c1) && inSameDomain(s, c2) - && c1->getImmune() == c2->getImmune()){ + Cell *c2 = it->first; + if(!(*c1 == *c2) && abs(or1) == abs(or2) && inSameDomain(s, c1) && + inSameDomain(s, c2) && c1->getImmune() == c2->getImmune()) { removeCell(s, true, false); c1->getCoboundary(cbd_c); @@ -787,8 +790,7 @@ int CellComplex::cocombine(int dim) c2->getCoboundary(cbd_c); enqueueCells(cbd_c, Q, Qset); - CombinedCell* newCell = new CombinedCell(c1, c2, - (or1 != or2), true ); + CombinedCell *newCell = new CombinedCell(c1, c2, (or1 != or2), true); _createCount++; removeCell(c1, true, c1->isCombined()); removeCell(c2, true, c2->isCombined()); @@ -805,7 +807,6 @@ int CellComplex::cocombine(int dim) delete c2; _deleteCount++; } - } } Qset.erase(s); @@ -813,8 +814,8 @@ int CellComplex::cocombine(int dim) } Msg::Debug("Cell complex %d-cocombine removed %dv, %df, %de, %dn", dim, - numCells[3]-getSize(3), numCells[2]-getSize(2), - numCells[1]-getSize(1), numCells[0]-getSize(0)); + numCells[3] - getSize(3), numCells[2] - getSize(2), + numCells[1] - getSize(1), numCells[0] - getSize(0)); _reduced = true; return count; } @@ -822,69 +823,73 @@ int CellComplex::cocombine(int dim) bool CellComplex::coherent() { bool coherent = true; - for(int i = 0; i < 4; i++){ - for(citer cit = firstCell(i); cit != lastCell(i); cit++){ - Cell* cell = *cit; - std::map<Cell*, short int, Less_Cell> boundary; + for(int i = 0; i < 4; i++) { + for(citer cit = firstCell(i); cit != lastCell(i); cit++) { + Cell *cell = *cit; + std::map<Cell *, short int, Less_Cell> boundary; cell->getBoundary(boundary); - for(std::map<Cell*, short int, Less_Cell>::iterator it = boundary.begin(); - it != boundary.end(); it++){ - Cell* bdCell = (*it).first; + for(std::map<Cell *, short int, Less_Cell>::iterator it = + boundary.begin(); + it != boundary.end(); it++) { + Cell *bdCell = (*it).first; int ori = (*it).second; citer cit = _cells[bdCell->getDim()].find(bdCell); - if(cit == lastCell(bdCell->getDim())){ + if(cit == lastCell(bdCell->getDim())) { Msg::Debug("Boundary cell not in cell complex! Boundary removed"); cell->removeBoundaryCell(bdCell, false); coherent = false; } - if(!bdCell->hasCoboundary(cell)){ + if(!bdCell->hasCoboundary(cell)) { Msg::Debug("Incoherent boundary/coboundary pair! Fixed"); - bdCell->addCoboundaryCell(ori, cell, false); + bdCell->addCoboundaryCell(ori, cell, false); coherent = false; } - } - std::map<Cell*, short int, Less_Cell> coboundary; + std::map<Cell *, short int, Less_Cell> coboundary; cell->getCoboundary(coboundary); - for(std::map<Cell*, short int, Less_Cell>::iterator it = coboundary.begin(); - it != coboundary.end(); it++){ - Cell* cbdCell = (*it).first; + for(std::map<Cell *, short int, Less_Cell>::iterator it = + coboundary.begin(); + it != coboundary.end(); it++) { + Cell *cbdCell = (*it).first; int ori = (*it).second; citer cit = _cells[cbdCell->getDim()].find(cbdCell); - if(cit == lastCell(cbdCell->getDim())){ + if(cit == lastCell(cbdCell->getDim())) { Msg::Debug("Coboundary cell not in cell complex! Coboundary removed"); cell->removeCoboundaryCell(cbdCell, false); coherent = false; } - if(!cbdCell->hasBoundary(cell)){ + if(!cbdCell->hasBoundary(cell)) { Msg::Debug("Incoherent coboundary/boundary pair! Fixed"); - cbdCell->addBoundaryCell(ori, cell, false); + cbdCell->addBoundaryCell(ori, cell, false); coherent = false; } - } - } } return coherent; } -bool CellComplex::hasCell(Cell* cell, bool orig) +bool CellComplex::hasCell(Cell *cell, bool orig) { citer cit; - if(!orig) cit = _cells[cell->getDim()].find(cell); - else cit = _ocells[cell->getDim()].find(cell); - if( cit == lastCell(cell->getDim(), orig) ) return false; - else return true; + if(!orig) + cit = _cells[cell->getDim()].find(cell); + else + cit = _ocells[cell->getDim()].find(cell); + if(cit == lastCell(cell->getDim(), orig)) + return false; + else + return true; } -void CellComplex::getCells(std::set<Cell*, Less_Cell>& cells, - int dim, int domain){ +void CellComplex::getCells(std::set<Cell *, Less_Cell> &cells, int dim, + int domain) +{ cells.clear(); - for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){ - Cell* cell = *cit; - if( (domain == 0 && !cell->inSubdomain()) || domain == 1 - || (domain == 2 && cell->inSubdomain()) ){ + for(citer cit = firstCell(dim); cit != lastCell(dim); cit++) { + Cell *cell = *cit; + if((domain == 0 && !cell->inSubdomain()) || domain == 1 || + (domain == 2 && cell->inSubdomain())) { cells.insert(cell); } } @@ -892,29 +897,35 @@ void CellComplex::getCells(std::set<Cell*, Less_Cell>& cells, int CellComplex::getNumCells(int dim, int domain) { - if(domain == 0) return _numRelativeCells[dim]; - else if(domain == 1) return getSize(dim); - else if(domain == 2) return _numSubdomainCells[dim]; + if(domain == 0) + return _numRelativeCells[dim]; + else if(domain == 1) + return getSize(dim); + else if(domain == 2) + return _numSubdomainCells[dim]; return 0; } -Cell* CellComplex::getACell(int dim, int domain) +Cell *CellComplex::getACell(int dim, int domain) { int num = getNumCells(dim, domain); if(num < 0) Msg::Debug("Domain cell counts not in sync."); if(num <= 0) { - if(domain == 0) Msg::Warning("%d cells in relative domain", num); - else if(domain == 1) Msg::Warning("%d cells in domain", num); - else if(domain == 2) Msg::Warning("%d cells in subdomain", num); + if(domain == 0) + Msg::Warning("%d cells in relative domain", num); + else if(domain == 1) + Msg::Warning("%d cells in domain", num); + else if(domain == 2) + Msg::Warning("%d cells in subdomain", num); return NULL; } - for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){ - Cell* cell = *cit; - if( (domain == 1) || - (domain == 0 && !cell->inSubdomain()) || - (domain == 2 && cell->inSubdomain()) ) return cell; + for(citer cit = firstCell(dim); cit != lastCell(dim); cit++) { + Cell *cell = *cit; + if((domain == 1) || (domain == 0 && !cell->inSubdomain()) || + (domain == 2 && cell->inSubdomain())) + return cell; } Msg::Debug("Domain cell counts not in sync."); return NULL; @@ -922,10 +933,9 @@ Cell* CellComplex::getACell(int dim, int domain) bool CellComplex::restoreComplex() { - if(_saveorig){ - + if(_saveorig) { for(unsigned int i = 0; i < _removedcells.size(); i++) { - Cell* cell = _removedcells.at(i); + Cell *cell = _removedcells.at(i); if(cell->isCombined()) { delete cell; _deleteCount++; @@ -933,10 +943,9 @@ bool CellComplex::restoreComplex() } _removedcells.clear(); - for(int i = 0; i < 4; i++){ - - for(citer cit = _cells[i].begin(); cit != _cells[i].end(); cit++){ - Cell* cell = *cit; + for(int i = 0; i < 4; i++) { + for(citer cit = _cells[i].begin(); cit != _cells[i].end(); cit++) { + Cell *cell = *cit; if(cell->isCombined()) { delete cell; _deleteCount++; @@ -944,19 +953,21 @@ bool CellComplex::restoreComplex() } _cells[i] = _ocells[i]; - for(citer cit = firstCell(i); cit != lastCell(i); cit++){ - Cell* cell = *cit; - cell->restoreCellBoundary(); + for(citer cit = firstCell(i); cit != lastCell(i); cit++) { + Cell *cell = *cit; + cell->restoreCellBoundary(); if(relative()) { - if(cell->inSubdomain()) _numSubdomainCells[i] += 1; - else _numRelativeCells[i] += 1; + if(cell->inSubdomain()) + _numSubdomainCells[i] += 1; + else + _numRelativeCells[i] += 1; } } } Msg::Info("Restored Cell Complex:"); - Msg::Info("%d volumes, %d faces, %d edges, and %d vertices", - getSize(3), getSize(2), getSize(1), getSize(0)); + Msg::Info("%d volumes, %d faces, %d edges, and %d vertices", getSize(3), + getSize(2), getSize(1), getSize(0)); _reduced = false; return true; } @@ -968,10 +979,9 @@ bool CellComplex::restoreComplex() void CellComplex::printComplex(int dim) { - if(getSize(dim) == 0) - Msg::Info("Cell complex dimension %d is empty", dim); - for (citer cit = firstCell(dim); cit != lastCell(dim); cit++){ - Cell* cell = *cit; + if(getSize(dim) == 0) Msg::Info("Cell complex dimension %d is empty", dim); + for(citer cit = firstCell(dim); cit != lastCell(dim); cit++) { + Cell *cell = *cit; cell->printCell(); cell->printBoundary(); cell->printCoboundary(); @@ -994,19 +1004,19 @@ int CellComplex::saveComplex(const std::string &filename) for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){ Cell* cell = *cit; fprintf(fp, "%d %d %d %d %d", cell->getNum(), cell->getType(), - 1, cell->getDomain(), cell->getNumVertices()); + 1, cell->getDomain(), cell->getNumVertices()); for(int i = 0; i < cell->getNumVertices(); i++){ - fprintf(fp, " %d", cell->getVertex(i)); + fprintf(fp, " %d", cell->getVertex(i)); } fprintf(fp, " %d", cell->getBoundarySize()); for(Cell::biter bit = cell->firstBoundary(); - bit != cell->lastBoundary(); bit++){ - fprintf(fp, " %d %d", bit->first->getNum(), bit->second); + bit != cell->lastBoundary(); bit++){ + fprintf(fp, " %d %d", bit->first->getNum(), bit->second); } fprintf(fp, " %d", cell->getCoboundarySize()); for(Cell::biter bit = cell->firstCoboundary(); - bit != cell->lastCoboundary(); bit++){ - fprintf(fp, " %d %d", bit->first->getNum(), bit->second); + bit != cell->lastCoboundary(); bit++){ + fprintf(fp, " %d %d", bit->first->getNum(), bit->second); } fprintf(fp, "\n"); } @@ -1015,7 +1025,7 @@ int CellComplex::saveComplex(const std::string &filename) fclose(fp); printf("Wrote %d cells to '%s' \n", - getSize(0)+getSize(1)+getSize(2)+getSize(3), filename.c_str()); + getSize(0)+getSize(1)+getSize(2)+getSize(3), filename.c_str()); */ return 1; } @@ -1046,42 +1056,42 @@ int CellComplex::loadComplex(const std::string &filename) int numCells; sscanf(str, "%d", &numCells); for(int i = 0; i < numCells; i++) { - int num, type, numTags; - std::vector<int> domain; - int tag; - if(fscanf(fp, "%d %d %d", &num, &type, &numTags) != 3) return 0; - for(int j = 0; j < numTags; j++){ - if(fscanf(fp, "%d", &tag) != 1) return 0; - domain.push_back(tag); - } - - std::vector<int> vertices; - if(fscanf(fp, "%d", &numTags) != 1) return 0; - for(int j = 0; j < numTags; j++){ - if(fscanf(fp, "%d", &tag) != 1) return 0; - vertices.push_back(tag); - } - - int dim = 0; - if(type == 1){ - if(vertices.size() == 2) dim = 1; - else if(vertices.size() == 3) dim = 2; - else if(vertices.size() == 4) dim = 3; - } - - Cell* cell = new Cell(num, dim, type, domain, vertices); - numToCell[num] = cell; - - - int numCell; - if(fscanf(fp, "%d", &numTags) != 1) return 0; - for(int j = 0; j < numTags; j++){ - if(fscanf(fp, "%d %d", &numCell, &tag) != 1) return 0; - } - if(fscanf(fp, "%d", &numTags) != 1) return 0; - for(int j = 0; j < numTags; j++){ - if(fscanf(fp, "%d %d", &numCell, &tag) != 1) return 0; - } + int num, type, numTags; + std::vector<int> domain; + int tag; + if(fscanf(fp, "%d %d %d", &num, &type, &numTags) != 3) return 0; + for(int j = 0; j < numTags; j++){ + if(fscanf(fp, "%d", &tag) != 1) return 0; + domain.push_back(tag); + } + + std::vector<int> vertices; + if(fscanf(fp, "%d", &numTags) != 1) return 0; + for(int j = 0; j < numTags; j++){ + if(fscanf(fp, "%d", &tag) != 1) return 0; + vertices.push_back(tag); + } + + int dim = 0; + if(type == 1){ + if(vertices.size() == 2) dim = 1; + else if(vertices.size() == 3) dim = 2; + else if(vertices.size() == 4) dim = 3; + } + + Cell* cell = new Cell(num, dim, type, domain, vertices); + numToCell[num] = cell; + + + int numCell; + if(fscanf(fp, "%d", &numTags) != 1) return 0; + for(int j = 0; j < numTags; j++){ + if(fscanf(fp, "%d %d", &numCell, &tag) != 1) return 0; + } + if(fscanf(fp, "%d", &numTags) != 1) return 0; + for(int j = 0; j < numTags; j++){ + if(fscanf(fp, "%d %d", &numCell, &tag) != 1) return 0; + } } } diff --git a/Geo/CellComplex.h b/Geo/CellComplex.h index 44f6514f309dc570ee712c1abd70964d63e0fda6..d1bba299263e7ac6fb1da94cb9d2112833afa3b1 100644 --- a/Geo/CellComplex.h +++ b/Geo/CellComplex.h @@ -21,25 +21,22 @@ class Cell; class BdInfo; -class CellComplex -{ - private: +class CellComplex { +private: + std::pair<Cell *, double> _smallestCell; + std::pair<Cell *, double> _biggestCell; - - std::pair<Cell*, double> _smallestCell; - std::pair<Cell*, double> _biggestCell; - - GModel* _model; + GModel *_model; // sorted containers of unique cells in this cell complex // one for each dimension - std::set<Cell*, Less_Cell> _cells[4]; + std::set<Cell *, Less_Cell> _cells[4]; // original cells of this cell complex - std::set<Cell*, Less_Cell> _ocells[4]; + std::set<Cell *, Less_Cell> _ocells[4]; // original cells removed during reductions - std::vector<Cell*> _removedcells; + std::vector<Cell *> _removedcells; // cell complex dimension int _dim; @@ -62,79 +59,81 @@ class CellComplex int _numRelativeCells[4]; int _numSubdomainCells[4]; - // for constructor - bool _insertCells(std::vector<MElement*>& elements, int domain); - bool _removeCells(std::vector<MElement*>& elements, int domain); + bool _insertCells(std::vector<MElement *> &elements, int domain); + bool _removeCells(std::vector<MElement *> &elements, int domain); - bool _immunizeCells(std::vector<MElement*>& elements); + bool _immunizeCells(std::vector<MElement *> &elements); - Cell* _omitCell(Cell* cell, bool dual); + Cell *_omitCell(Cell *cell, bool dual); // enqueue cells in queue if they are not there already - void enqueueCells(std::map<Cell*, short int, Less_Cell>& cells, - std::queue<Cell*>& Q, std::set<Cell*, Less_Cell>& Qset); + void enqueueCells(std::map<Cell *, short int, Less_Cell> &cells, + std::queue<Cell *> &Q, std::set<Cell *, Less_Cell> &Qset); // insert/remove a cell from this cell complex - void removeCell(Cell* cell, bool other=true, bool del=false); - void insertCell(Cell* cell); + void removeCell(Cell *cell, bool other = true, bool del = false); + void insertCell(Cell *cell); // queued coreduction - int coreduction(Cell* startCell, int omit, - std::vector<Cell*>& omittedCells); + int coreduction(Cell *startCell, int omit, std::vector<Cell *> &omittedCells); static double _patience; - public: - CellComplex(GModel* model, - std::vector<MElement*>& domainElements, - std::vector<MElement*>& subdomainElements, - std::vector<MElement*>& nondomainElements, - std::vector<MElement*>& nonsubdomainElements, - std::vector<MElement*>& immuneElements, - bool saveOriginalComplex=true); +public: + CellComplex(GModel *model, std::vector<MElement *> &domainElements, + std::vector<MElement *> &subdomainElements, + std::vector<MElement *> &nondomainElements, + std::vector<MElement *> &nonsubdomainElements, + std::vector<MElement *> &immuneElements, + bool saveOriginalComplex = true); ~CellComplex(); - - GModel* getModel() const { return _model; } + GModel *getModel() const { return _model; } int getDim() const { return _dim; } bool simplicial() const { return _simplicial; } bool relative() const { return _relative; } // get the number of certain dimensional cells // if dim = -1 return the number of all cells - int getSize(int dim, bool orig=false); + int getSize(int dim, bool orig = false); // get domain of a cell // cell in domain relative to subdomain -> domain = 0 // cell in domain -> domain = 1 // cell in subdomain -> domain = 2 - int getDomain(Cell* cell, std::string& str); + int getDomain(Cell *cell, std::string &str); // get dim-dimensional cells // domain = 0: cells in domain relative to subdomain // domain = 1: cells in domain // domain = 2: cells in subdomain - void getCells(std::set<Cell*, Less_Cell>& cells, int dim, int domain=0); - int getNumCells(int dim, int domain=0); - Cell* getACell(int dim, int domain=0); - //std::set<Cell*, Less_Cell> getOrigCells(int dim){ return _ocells[dim]; } + void getCells(std::set<Cell *, Less_Cell> &cells, int dim, int domain = 0); + int getNumCells(int dim, int domain = 0); + Cell *getACell(int dim, int domain = 0); + // std::set<Cell*, Less_Cell> getOrigCells(int dim){ return _ocells[dim]; } // iterator for the cells of same dimension - typedef std::set<Cell*, Less_Cell>::iterator citer; + typedef std::set<Cell *, Less_Cell>::iterator citer; // iterators to the first and last cells of certain dimension - citer firstCell(int dim, bool orig=false) { - return orig ? _ocells[dim].begin() : _cells[dim].begin(); } - citer lastCell(int dim, bool orig=false) { - return orig ? _ocells[dim].end() : _cells[dim].end(); } + citer firstCell(int dim, bool orig = false) + { + return orig ? _ocells[dim].begin() : _cells[dim].begin(); + } + citer lastCell(int dim, bool orig = false) + { + return orig ? _ocells[dim].end() : _cells[dim].end(); + } // true if cell complex has given cell - bool hasCell(Cell* cell, bool orig=false); + bool hasCell(Cell *cell, bool orig = false); // check whether two cells both belong to subdomain or if neither one does - bool inSameDomain(Cell* c1, Cell* c2) const { - return (c1->getDomain() == c2->getDomain()); } + bool inSameDomain(Cell *c1, Cell *c2) const + { + return (c1->getDomain() == c2->getDomain()); + } // remove cells in subdomain from this cell complex void removeSubdomain(); @@ -144,8 +143,8 @@ class CellComplex // (co)reduction of this cell complex // removes (co)reduction pairs of cell of dimension dim and dim-1 - int reduction(int dim, int omit, std::vector<Cell*>& omittedCells); - int coreduction(int dim, int omit, std::vector<Cell*>& omittedCells); + int reduction(int dim, int omit, std::vector<Cell *> &omittedCells); + int coreduction(int dim, int omit, std::vector<Cell *> &omittedCells); // Cell combining for reduction and coreduction int combine(int dim); @@ -164,18 +163,22 @@ class CellComplex // (heuristic = 0 -> no heuristic, let mesh indexing determine // 1 -> omit 0-cell in biggest element // -1 -> omit 0-cell in smallest element) - int reduceComplex(int combine=1, bool omit=true, bool homseq=false); - int coreduceComplex(int combine=1, bool omit=true, int heuristic=0); + int reduceComplex(int combine = 1, bool omit = true, bool homseq = false); + int coreduceComplex(int combine = 1, bool omit = true, int heuristic = 0); // reduce cell complex for Betti number computation void bettiReduceComplex(); bool isReduced() const { return _reduced; } - int eulerCharacteristic() { - return getSize(0) - getSize(1) + getSize(2) - getSize(3); } - void printEuler() { - printf("Euler characteristic: %d. \n", eulerCharacteristic()); } + int eulerCharacteristic() + { + return getSize(0) - getSize(1) + getSize(2) - getSize(3); + } + void printEuler() + { + printf("Euler characteristic: %d. \n", eulerCharacteristic()); + } // restore the cell complex to its original state before (co)reduction bool restoreComplex(); @@ -183,7 +186,6 @@ class CellComplex // print the vertices of cells of certain dimension void printComplex(int dim); - // experimental int saveComplex(const std::string &filename); int loadComplex(const std::string &filename); diff --git a/Geo/Chain.cpp b/Geo/Chain.cpp index 805c5dd2fede4b807e7f5de99e06f3dc7fe4e9d1..97644601e7668c9dc437a7ef0efbdfeae1ba06bf 100644 --- a/Geo/Chain.cpp +++ b/Geo/Chain.cpp @@ -34,55 +34,53 @@ std::string convertInt(int number) return stream.str(); } -std::map<GEntity*, std::set<MVertex*, MVertexLessThanNum>, - GEntityLessThan> ElemChain::_vertexCache; +std::map<GEntity *, std::set<MVertex *, MVertexLessThanNum>, GEntityLessThan> + ElemChain::_vertexCache; inline void ElemChain::_sortVertexIndices() { - std::map<MVertex*, int, MVertexLessThanNum> si; + std::map<MVertex *, int, MVertexLessThanNum> si; - for(unsigned int i = 0; i < _v.size(); i++) - si[_v[i]] = i; + for(unsigned int i = 0; i < _v.size(); i++) si[_v[i]] = i; - std::map<MVertex*, int, MVertexLessThanNum>::iterator it; - for(it = si.begin(); it != si.end(); it++) - _si.push_back(it->second); + std::map<MVertex *, int, MVertexLessThanNum>::iterator it; + for(it = si.begin(); it != si.end(); it++) _si.push_back(it->second); } -void findEntitiesInPhysicalGroups -(GModel* m, const std::vector<int>& physicalGroups, std::vector<GEntity*>& entities) +void findEntitiesInPhysicalGroups(GModel *m, + const std::vector<int> &physicalGroups, + std::vector<GEntity *> &entities) { - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; m->getPhysicalGroups(groups); - std::map<int, std::vector<GEntity*> >::iterator it; - for(unsigned int i = 0; i < physicalGroups.size(); i++){ + std::map<int, std::vector<GEntity *> >::iterator it; + for(unsigned int i = 0; i < physicalGroups.size(); i++) { bool found = false; - for(int j = 0; j < 4; j++){ + for(int j = 0; j < 4; j++) { it = groups[j].find(physicalGroups.at(i)); - if(it != groups[j].end()){ + if(it != groups[j].end()) { found = true; - std::vector<GEntity*> physicalGroup = it->second; - for(unsigned int k = 0; k < physicalGroup.size(); k++){ + std::vector<GEntity *> physicalGroup = it->second; + for(unsigned int k = 0; k < physicalGroup.size(); k++) { entities.push_back(physicalGroup.at(k)); } } } if(!found) { - Msg::Error("Physical group %d does not exist", - physicalGroups.at(i)); + Msg::Error("Physical group %d does not exist", physicalGroups.at(i)); } } } - -bool ElemChain::_equalVertices(const std::vector<MVertex*>& v2) const { +bool ElemChain::_equalVertices(const std::vector<MVertex *> &v2) const +{ if(_v.size() != v2.size()) return false; for(unsigned int i = 0; i < _v.size(); i++) if(_v[i]->getNum() != v2[i]->getNum()) return false; return true; } -ElemChain::ElemChain(MElement* e) +ElemChain::ElemChain(MElement *e) { _dim = e->getDim(); for(int i = 0; i < e->getNumPrimaryVertices(); i++) @@ -90,7 +88,7 @@ ElemChain::ElemChain(MElement* e) _sortVertexIndices(); } -ElemChain::ElemChain(int dim, std::vector<MVertex*>& v) : _dim(dim), _v(v) +ElemChain::ElemChain(int dim, std::vector<MVertex *> &v) : _dim(dim), _v(v) { _sortVertexIndices(); } @@ -102,17 +100,17 @@ inline int ElemChain::getSortedVertex(int i) const int ElemChain::getTypeMSH(int dim, int numVertices) { - switch (dim) { + switch(dim) { case 0: return MSH_PNT; case 1: return MSH_LIN_2; case 2: - switch (numVertices) { + switch(numVertices) { case 3: return MSH_TRI_3; case 4: return MSH_QUA_4; default: return 0; } case 3: - switch (numVertices) { + switch(numVertices) { case 4: return MSH_TET_4; case 5: return MSH_PYR_5; case 6: return MSH_PRI_6; @@ -128,16 +126,16 @@ int ElemChain::getTypeMSH() const return ElemChain::getTypeMSH(_dim, this->getNumVertices()); } -MElement* ElemChain::createMeshElement() const +MElement *ElemChain::createMeshElement() const { MElementFactory factory; - std::vector<MVertex*> v(_v); + std::vector<MVertex *> v(_v); return factory.create(this->getTypeMSH(), v); } -int ElemChain::compareOrientation(const ElemChain& c2) const +int ElemChain::compareOrientation(const ElemChain &c2) const { - std::vector<MVertex*> v2; + std::vector<MVertex *> v2; c2.getMeshVertices(v2); int perm = 1; @@ -155,30 +153,32 @@ int ElemChain::compareOrientation(const ElemChain& c2) const return 0; } -bool ElemChain::lessThan(const ElemChain& c2) const +bool ElemChain::lessThan(const ElemChain &c2) const { if(this->getNumSortedVertices() != c2.getNumSortedVertices()) return (this->getNumSortedVertices() < c2.getNumSortedVertices()); - for(int i = 0; i < this->getNumSortedVertices(); i++){ - if(this->getSortedVertex(i) < c2.getSortedVertex(i)) return true; - else if (this->getSortedVertex(i) > c2.getSortedVertex(i)) return false; + for(int i = 0; i < this->getNumSortedVertices(); i++) { + if(this->getSortedVertex(i) < c2.getSortedVertex(i)) + return true; + else if(this->getSortedVertex(i) > c2.getSortedVertex(i)) + return false; } return false; } int ElemChain::getNumBoundaries(int dim, int numVertices) { - switch (dim) { + switch(dim) { case 0: return 0; case 1: return 2; case 2: - switch (numVertices) { + switch(numVertices) { case 3: return 3; case 4: return 4; default: return 0; } case 3: - switch (numVertices) { + switch(numVertices) { case 4: return 4; case 5: return 5; case 6: return 5; @@ -195,16 +195,14 @@ int ElemChain::getNumBoundaryElemChains() const } void ElemChain::getBoundaryVertices(int i, int dim, int numVertices, - const std::vector<MVertex*>& v, - std::vector<MVertex*>& vertices) + const std::vector<MVertex *> &v, + std::vector<MVertex *> &vertices) { vertices.clear(); - switch (dim) { - case 1: - vertices.push_back(v[i]); - return; + switch(dim) { + case 1: vertices.push_back(v[i]); return; case 2: - switch (numVertices) { + switch(numVertices) { case 3: for(int j = 0; j < 2; j++) vertices.push_back(v[MTriangle::edges_tri(i, j)]); @@ -216,7 +214,7 @@ void ElemChain::getBoundaryVertices(int i, int dim, int numVertices, default: return; } case 3: - switch (numVertices) { + switch(numVertices) { case 4: for(int j = 0; j < 3; j++) vertices.push_back(v[MTetrahedron::faces_tetra(i, j)]); @@ -249,13 +247,12 @@ void ElemChain::getBoundaryVertices(int i, int dim, int numVertices, ElemChain ElemChain::getBoundaryElemChain(int i) const { - std::vector<MVertex*> vertices; - ElemChain::getBoundaryVertices(i, _dim, this->getNumVertices(), - _v, vertices); - return ElemChain(_dim-1, vertices); + std::vector<MVertex *> vertices; + ElemChain::getBoundaryVertices(i, _dim, this->getNumVertices(), _v, vertices); + return ElemChain(_dim - 1, vertices); } -bool ElemChain::inEntity(GEntity* e) const +bool ElemChain::inEntity(GEntity *e) const { if(_vertexCache[e].empty()) { for(unsigned int i = 0; i < e->getNumMeshElements(); i++) diff --git a/Geo/Chain.h b/Geo/Chain.h index f89994892c474f6d12a6c7561e6a6ee8ce2220b5..dcd9632bf6b838abac664420bc702a02a365bc3a 100644 --- a/Geo/Chain.h +++ b/Geo/Chain.h @@ -24,78 +24,76 @@ void updateFltk(); std::string convertInt(int number); // Class whose derivative classes are to have partial or total order -template <class Type> -class PosetCat -{ +template <class Type> class PosetCat { public: - virtual ~PosetCat(){} + virtual ~PosetCat() {} /// instantiated in derived classes - virtual bool lessThan(const Type& t2) const = 0; + virtual bool lessThan(const Type &t2) const = 0; - friend bool operator<(const Type& t1, const Type& t2) + friend bool operator<(const Type &t1, const Type &t2) { return t1.lessThan(t2); } - friend bool operator>(const Type& t1, const Type& t2) + friend bool operator>(const Type &t1, const Type &t2) { return !t1.lessThan(t2); } - friend bool operator==(const Type& t1, const Type& t2) { + friend bool operator==(const Type &t1, const Type &t2) + { if(t1.lessThan(t2) && t2.lessThan(t1)) return true; return false; } - friend bool operator!=(const Type& t1, const Type& t2) { + friend bool operator!=(const Type &t1, const Type &t2) + { if(t1.lessThan(t2) && t2.lessThan(t1)) return false; return true; } - friend bool operator<=(const Type& t1, const Type& t2) + friend bool operator<=(const Type &t1, const Type &t2) { - if(t1.lessThan(t2) || t1==t2) return true; + if(t1.lessThan(t2) || t1 == t2) return true; return false; } - friend bool operator>=(const Type& t1, const Type& t2) + friend bool operator>=(const Type &t1, const Type &t2) { - if(!t1.lessThan(t2) || t1==t2) return true; + if(!t1.lessThan(t2) || t1 == t2) return true; return false; } - }; // Class whose derivative classes are to have vector space structure -template <class V, class S> -class VectorSpaceCat -{ +template <class V, class S> class VectorSpaceCat { public: - - virtual ~VectorSpaceCat(){} + virtual ~VectorSpaceCat() {} /// instantiated in derived classes - virtual V& operator+=(const V& v) = 0; - virtual V& operator*=(const S& s) = 0; - //virtual V& zero() = 0; + virtual V &operator+=(const V &v) = 0; + virtual V &operator*=(const S &s) = 0; + // virtual V& zero() = 0; /// --------------------- - friend V operator+(const V& v1, const V& v2) { + friend V operator+(const V &v1, const V &v2) + { V temp(v1); temp += v2; return temp; } - friend V operator-(const V& v1, const V& v2) { + friend V operator-(const V &v1, const V &v2) + { V temp(v1); temp -= v2; return temp; } - friend V operator*(const S& s, const V& v) { + friend V operator*(const S &s, const V &v) + { V temp(v); - temp*=s; + temp *= s; return temp; } - friend V operator*(const V& v, const S& s) { - return s*v; - } - friend V operator/(const V& v, const S& s) { - S invs = 1./s; - return invs*v; + friend V operator*(const V &v, const S &s) { return s * v; } + friend V operator/(const V &v, const S &s) + { + S invs = 1. / s; + return invs * v; } // Warning: assummes that the multiplicative @@ -104,74 +102,69 @@ public: // (true e.g. for double and std::complex<double>), // otherwise these need to be overridden by the user - virtual V& operator-() { - return (*this)*=(-1.); - } - virtual V& operator/=(const S& s) { - S temp = 1./s; - return (*this*=temp); + virtual V &operator-() { return (*this) *= (-1.); } + virtual V &operator/=(const S &s) + { + S temp = 1. / s; + return (*this *= temp); } - virtual V& operator-=(const V& v) { + virtual V &operator-=(const V &v) + { V temp(v); temp = -temp; - return (*this+=temp); + return (*this += temp); } }; // Class to represent an 'elementary chain', a mesh cell -class ElemChain : public PosetCat<ElemChain> -{ - private: - +class ElemChain : public PosetCat<ElemChain> { +private: char _dim; - std::vector<MVertex*> _v; + std::vector<MVertex *> _v; std::vector<char> _si; inline void _sortVertexIndices(); - bool _equalVertices(const std::vector<MVertex*>& v2) const; - - static std::map<GEntity*, std::set<MVertex*, MVertexLessThanNum>, - GEntityLessThan> _vertexCache; + bool _equalVertices(const std::vector<MVertex *> &v2) const; - public: + static std::map<GEntity *, std::set<MVertex *, MVertexLessThanNum>, + GEntityLessThan> + _vertexCache; - ElemChain(MElement* e); - ElemChain(int dim, std::vector<MVertex*>& v); +public: + ElemChain(MElement *e); + ElemChain(int dim, std::vector<MVertex *> &v); int getDim() const { return _dim; } int getNumVertices() const { return _v.size(); } - MVertex* getMeshVertex(int i) const { return _v.at(i); } - void getMeshVertices(std::vector<MVertex*>& v) const { v = _v; } + MVertex *getMeshVertex(int i) const { return _v.at(i); } + void getMeshVertices(std::vector<MVertex *> &v) const { v = _v; } int getNumSortedVertices() const { return _v.size(); } inline int getSortedVertex(int i) const; int getTypeMSH() const; - MElement* createMeshElement() const; + MElement *createMeshElement() const; - int compareOrientation(const ElemChain& c2) const; - bool lessThan(const ElemChain& c2) const; + int compareOrientation(const ElemChain &c2) const; + bool lessThan(const ElemChain &c2) const; int getNumBoundaryElemChains() const; ElemChain getBoundaryElemChain(int i) const; - bool inEntity(GEntity* e) const; + bool inEntity(GEntity *e) const; static void clearVertexCache() { _vertexCache.clear(); } static int getTypeMSH(int dim, int numVertices); static int getNumBoundaries(int dim, int numVertices); static void getBoundaryVertices(int i, int dim, int numVertices, - const std::vector<MVertex*>& v, - std::vector<MVertex*>& vertices); - + const std::vector<MVertex *> &v, + std::vector<MVertex *> &vertices); }; -void findEntitiesInPhysicalGroups -(GModel* m, const std::vector<int>& physicalGroups, -std::vector<GEntity*>& entities); +void findEntitiesInPhysicalGroups(GModel *m, + const std::vector<int> &physicalGroups, + std::vector<GEntity *> &entities); // Class to represent a chain, formal sum of elementary chains -template <class C> -class Chain : public VectorSpaceCat<Chain<C>, C> -{ +template <class C> class Chain : public VectorSpaceCat<Chain<C>, C> { private: // Dimension of the chain int _dim; @@ -180,7 +173,7 @@ private: // A name for the chain std::string _name; - Chain<C> _getTraceOrProject(const std::vector<GEntity*>& entities, + Chain<C> _getTraceOrProject(const std::vector<GEntity *> &entities, bool trace) const; public: @@ -194,7 +187,7 @@ public: // Create chain from Gmsh model physical group // (all mesh elements in the physical group are treated as // elementary chains with coefficient 1) - Chain(GModel* m, int physicalGroup); + Chain(GModel *m, int physicalGroup); // Get/set the chain name std::string getName() const { return _name; } @@ -211,89 +204,86 @@ public: cecit lastElemChain() const { return _elemChains.end(); } // Add mesh element or elementary chain with given coefficient to the chain - void addMeshElement(MElement* e, C coeff=1); - void addElemChain(const ElemChain& c, C coeff=1); + void addMeshElement(MElement *e, C coeff = 1); + void addElemChain(const ElemChain &c, C coeff = 1); // Vector space operations for chains (these two induce the rest) - Chain<C>& operator+=(const Chain<C>& chain); - Chain<C>& operator*=(const C& coeff); + Chain<C> &operator+=(const Chain<C> &chain); + Chain<C> &operator*=(const C &coeff); // Get elementary chain coefficient the chain - C getCoefficient(const ElemChain& c2) const; + C getCoefficient(const ElemChain &c2) const; // Get mesh element (or its indicated face, edge, or vertex) // coefficient in the chain, interpreted as a elementary chain - C getCoefficient(MElement* e, int subElement=-1) const; + C getCoefficient(MElement *e, int subElement = -1) const; // Get the boundary chain of this chain Chain<C> getBoundary() const; // Get a chain which contains elementary chains that are // in the given physical group or elementary entities - Chain<C> getTrace(GModel* m, int physicalGroup) const; - Chain<C> getTrace(GModel* m, const std::vector<int>& physicalGroups) const; - Chain<C> getTrace(const std::vector<GEntity*>& entities) const; + Chain<C> getTrace(GModel *m, int physicalGroup) const; + Chain<C> getTrace(GModel *m, const std::vector<int> &physicalGroups) const; + Chain<C> getTrace(const std::vector<GEntity *> &entities) const; // Get a chain which contains elementary chains that are *not* // in the given physical group or elementary entities - Chain<C> getProject(GModel* m, int physicalGroup) const; - Chain<C> getProject(GModel* m, const std::vector<int>& physicalGroups) const; - Chain<C> getProject(const std::vector<GEntity*>& entities) const; + Chain<C> getProject(GModel *m, int physicalGroup) const; + Chain<C> getProject(GModel *m, const std::vector<int> &physicalGroups) const; + Chain<C> getProject(const std::vector<GEntity *> &entities) const; // The above two methods decompose a chain c so that // (c - c.getTrace(...) - c.getProject(...)).isZero() == true // holds - // Add chain to Gmsh model as a physical group, // elementary chains are turned into mesh elements with // orientation and multiplicity given by elementary chain coefficient // (and create a post-processing view) // (and request a physical group number) // returns physical group number of the chain - int addToModel(GModel* m, bool post=true, int physicalNumRequest=-1) const; + int addToModel(GModel *m, bool post = true, + int physicalNumRequest = -1) const; }; -template <class C> -Chain<C>::Chain(GModel* m, int physicalGroup) +template <class C> Chain<C>::Chain(GModel *m, int physicalGroup) { _dim = 0; std::vector<int> groups(1, physicalGroup); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; findEntitiesInPhysicalGroups(m, groups, entities); for(unsigned int i = 0; i < entities.size(); i++) { - GEntity* e = entities.at(i); + GEntity *e = entities.at(i); _dim = e->dim(); for(unsigned int j = 0; j < e->getNumMeshElements(); j++) { this->addMeshElement(e->getMeshElement(j)); } - this->setName(m->getPhysicalName(this->getDim(), - physicalGroup)); + this->setName(m->getPhysicalName(this->getDim(), physicalGroup)); } } -template <class C> -C Chain<C>::getCoefficient(const ElemChain& c2) const +template <class C> C Chain<C>::getCoefficient(const ElemChain &c2) const { cecit it = _elemChains.find(c2); if(it != _elemChains.end()) - return it->second*c2.compareOrientation(it->first); - else return 0; + return it->second * c2.compareOrientation(it->first); + else + return 0; } -template <class C> -C Chain<C>::getCoefficient(MElement* e, int subElement) const +template <class C> C Chain<C>::getCoefficient(MElement *e, int subElement) const { if(this->getDim() == e->getDim()) { ElemChain ec(e); return this->getCoefficient(ec); } if(subElement == -1) return 0; - std::vector<MVertex*> v; + std::vector<MVertex *> v; if(this->getDim() == 0) { if(subElement >= e->getNumVertices()) return 0; - v = std::vector<MVertex*>(1, e->getVertex(subElement)); + v = std::vector<MVertex *>(1, e->getVertex(subElement)); } else if(this->getDim() == 1) { if(subElement >= e->getNumEdges()) return 0; @@ -307,31 +297,29 @@ C Chain<C>::getCoefficient(MElement* e, int subElement) const (e->getType() == TYPE_PRI && subElement < 4) || (e->getType() == TYPE_PYR && subElement < 2)) v.resize(3); - else v.resize(4); + else + v.resize(4); } ElemChain ec(this->getDim(), v); return this->getCoefficient(ec); } -template <class C> -C incidence(const Chain<C>& c1, const Chain<C>& c2) +template <class C> C incidence(const Chain<C> &c1, const Chain<C> &c2) { C incidence = 0; if(c1.getDim() != c2.getDim()) return incidence; for(typename Chain<C>::cecit it = c1.firstElemChain(); it != c1.lastElemChain(); it++) { - incidence += it->second*c2.getCoefficient(it->first); + incidence += it->second * c2.getCoefficient(it->first); } if(incidence != 0) { Msg::Debug("%d-chains \'%s\' and \'%s\' have incidence %d", c1.getDim(), c1.getName().c_str(), c2.getName().c_str(), incidence); - } return incidence; } -template <class C> -Chain<C> boundary(const ElemChain& c) +template <class C> Chain<C> boundary(const ElemChain &c) { Chain<C> result; for(int i = 0; i < c.getNumBoundaryElemChains(); i++) { @@ -342,13 +330,12 @@ Chain<C> boundary(const ElemChain& c) return result; } -template <class C> -Chain<C> Chain<C>::getBoundary() const +template <class C> Chain<C> Chain<C>::getBoundary() const { Chain<C> result; for(cecit it = _elemChains.begin(); it != _elemChains.end(); it++) { C coeff = it->second; - result += boundary<C>(it->first)*coeff; + result += boundary<C>(it->first) * coeff; } if(result.isZero()) Msg::Info("The boundary chain is zero element in C%d", result.getDim()); @@ -356,42 +343,42 @@ Chain<C> Chain<C>::getBoundary() const } template <class C> -Chain<C> Chain<C>::getTrace(GModel* m, int physicalGroup) const +Chain<C> Chain<C>::getTrace(GModel *m, int physicalGroup) const { std::vector<int> groups(1, physicalGroup); return this->getTrace(m, groups); } template <class C> -Chain<C> Chain<C>::getProject(GModel* m, int physicalGroup) const +Chain<C> Chain<C>::getProject(GModel *m, int physicalGroup) const { std::vector<int> groups(1, physicalGroup); return this->getProject(m, groups); } template <class C> -Chain<C> Chain<C>::getTrace(GModel* m, - const std::vector<int>& physicalGroups) const +Chain<C> Chain<C>::getTrace(GModel *m, + const std::vector<int> &physicalGroups) const { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; findEntitiesInPhysicalGroups(m, physicalGroups, entities); if(entities.empty()) return Chain<C>(); return this->_getTraceOrProject(entities, true); } template <class C> -Chain<C> Chain<C>::getProject(GModel* m, - const std::vector<int>& physicalGroups) const +Chain<C> Chain<C>::getProject(GModel *m, + const std::vector<int> &physicalGroups) const { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; findEntitiesInPhysicalGroups(m, physicalGroups, entities); if(entities.empty()) return Chain<C>(); return this->_getTraceOrProject(entities, false); } template <class C> -Chain<C> Chain<C>::_getTraceOrProject -(const std::vector<GEntity*>& entities, bool trace) const +Chain<C> Chain<C>::_getTraceOrProject(const std::vector<GEntity *> &entities, + bool trace) const { Chain<C> result; for(cecit it = _elemChains.begin(); it != _elemChains.end(); it++) { @@ -409,52 +396,46 @@ Chain<C> Chain<C>::_getTraceOrProject } template <class C> -Chain<C> Chain<C>::getTrace(const std::vector<GEntity*>& entities) const +Chain<C> Chain<C>::getTrace(const std::vector<GEntity *> &entities) const { return this->_getTraceOrProject(entities, true); } template <class C> -Chain<C> Chain<C>::getProject(const std::vector<GEntity*>& entities) const +Chain<C> Chain<C>::getProject(const std::vector<GEntity *> &entities) const { return this->_getTraceOrProject(entities, false); } -template <class C> -void Chain<C>::addMeshElement(MElement* e, C coeff) +template <class C> void Chain<C>::addMeshElement(MElement *e, C coeff) { ElemChain ce(e); this->addElemChain(ce, coeff); } -template <class C> -void Chain<C>::addElemChain(const ElemChain& c, C coeff) +template <class C> void Chain<C>::addElemChain(const ElemChain &c, C coeff) { if(coeff == 0) return; if(_dim != -1 && _dim != c.getDim()) { - Msg::Error("Cannot add elementrary %d-chain to %d-chain", - c.getDim(), _dim); + Msg::Error("Cannot add elementrary %d-chain to %d-chain", c.getDim(), _dim); return; } if(_dim == -1) _dim = c.getDim(); - std::pair<ecit, bool> ii = _elemChains.insert( std::make_pair(c, coeff) ); + std::pair<ecit, bool> ii = _elemChains.insert(std::make_pair(c, coeff)); if(!ii.second) { - ii.first->second += coeff*c.compareOrientation(ii.first->first); + ii.first->second += coeff * c.compareOrientation(ii.first->first); if(ii.first->second == 0) _elemChains.erase(ii.first); } } -template <class C> -Chain<C>& Chain<C>::operator+=(const Chain<C>& chain) +template <class C> Chain<C> &Chain<C>::operator+=(const Chain<C> &chain) { - for(cecit it = chain.firstElemChain(); - it != chain.lastElemChain(); it++) + for(cecit it = chain.firstElemChain(); it != chain.lastElemChain(); it++) this->addElemChain(it->first, it->second); return *this; } -template <class C> -Chain<C>& Chain<C>::operator*=(const C& coeff) +template <class C> Chain<C> &Chain<C>::operator*=(const C &coeff) { if(coeff == 0) _elemChains.clear(); @@ -465,7 +446,7 @@ Chain<C>& Chain<C>::operator*=(const C& coeff) } template <class C> -int Chain<C>::addToModel(GModel* m, bool post, int physicalNumRequest) const +int Chain<C>::addToModel(GModel *m, bool post, int physicalNumRequest) const { if(this->isZero()) { Msg::Info("A chain is zero element of C%d, not added to the model", @@ -477,12 +458,12 @@ int Chain<C>::addToModel(GModel* m, bool post, int physicalNumRequest) const // avoid too long names, which screw up the GUI and the msh file if(name.size() > 128) name.resize(128); - std::vector<MElement*> elements; + std::vector<MElement *> elements; std::map<int, std::vector<double> > data; int dim = this->getDim(); for(cecit it = this->firstElemChain(); it != this->lastElemChain(); it++) { - MElement* e = it->first.createMeshElement(); + MElement *e = it->first.createMeshElement(); C coeff = it->second; elements.push_back(e); if(dim > 0 && coeff < 0) e->reverse(); @@ -490,7 +471,7 @@ int Chain<C>::addToModel(GModel* m, bool post, int physicalNumRequest) const // if elementary chain coefficient is other than -1 or 1, // add multiple identical MElements to the physical group for(int i = 1; i < abs(coeff); i++) { - MElement* ecopy = it->first.createMeshElement(); + MElement *ecopy = it->first.createMeshElement(); if(dim > 0 && coeff < 0) ecopy->reverse(); elements.push_back(ecopy); } @@ -500,18 +481,17 @@ int Chain<C>::addToModel(GModel* m, bool post, int physicalNumRequest) const data[e->getNum()] = coeffs; } int max[4]; - for(int i = 0; i < 4; i++) - max[i] = m->getMaxElementaryNumber(i); - int entityNum = *std::max_element(max,max+4) + 1; - for(int i = 0; i < 4; i++) - max[i] = m->getMaxPhysicalNumber(i); - int physicalNum = *std::max_element(max,max+4) + 1; + for(int i = 0; i < 4; i++) max[i] = m->getMaxElementaryNumber(i); + int entityNum = *std::max_element(max, max + 4) + 1; + for(int i = 0; i < 4; i++) max[i] = m->getMaxPhysicalNumber(i); + int physicalNum = *std::max_element(max, max + 4) + 1; if(physicalNumRequest > -1 && physicalNumRequest < physicalNum) - Msg::Warning("Requested chain physical group number already taken. Using next available."); + Msg::Warning("Requested chain physical group number already taken. Using " + "next available."); else if(physicalNumRequest > -1 && physicalNumRequest >= physicalNum) physicalNum = physicalNumRequest; - std::map<int, std::vector<MElement*> > entityMap; + std::map<int, std::vector<MElement *> > entityMap; entityMap[entityNum] = elements; std::map<int, std::map<int, std::string> > physicalMap; std::map<int, std::string> physicalInfo; @@ -525,10 +505,10 @@ int Chain<C>::addToModel(GModel* m, bool post, int physicalNumRequest) const // create PView for instant visualization std::string pnum = convertInt(physicalNum); std::string postname = pnum + "=" + name; - PView* view = new PView(postname, "ElementData", m, data, 0., 1); + PView *view = new PView(postname, "ElementData", m, data, 0., 1); // the user should be interested about the orientations int size = 30; - PViewOptions* opt = view->getOptions(); + PViewOptions *opt = view->getOptions(); opt->visible = 0; if(opt->tangents == 0) opt->tangents = size; if(opt->normals == 0) opt->normals = size; diff --git a/Geo/ChainComplex.cpp b/Geo/ChainComplex.cpp index ce6438aade5b7533dcd65e783c242a52aecd9b34..a20f13d6d6f5b06cbf146f881de36fb695f2895d 100644 --- a/Geo/ChainComplex.cpp +++ b/Geo/ChainComplex.cpp @@ -10,12 +10,12 @@ #include "ChainComplex.h" -ChainComplex::ChainComplex(CellComplex* cellComplex, int domain) +ChainComplex::ChainComplex(CellComplex *cellComplex, int domain) { _dim = cellComplex->getDim(); _cellComplex = cellComplex; - for(int i = 0; i < 5; i++){ + for(int i = 0; i < 5; i++) { _HMatrix[i] = NULL; _kerH[i] = NULL; _codH[i] = NULL; @@ -25,69 +25,71 @@ ChainComplex::ChainComplex(CellComplex* cellComplex, int domain) } int lastCols = 0; - for(int dim = 0; dim < 4; dim++){ + for(int dim = 0; dim < 4; dim++) { unsigned int cols = cellComplex->getSize(dim); unsigned int rows = 0; int index = 1; // ignore cells depending on domain for(CellComplex::citer cit = cellComplex->firstCell(dim); - cit != cellComplex->lastCell(dim); cit++){ - Cell* cell = *cit; + cit != cellComplex->lastCell(dim); cit++) { + Cell *cell = *cit; cols--; - if((domain == 0 && !cell->inSubdomain()) || domain == 1 - || (domain == 2 && cell->inSubdomain()) ){ + if((domain == 0 && !cell->inSubdomain()) || domain == 1 || + (domain == 2 && cell->inSubdomain())) { cols++; _cellIndices[dim][cell] = index; index++; } - else _cellIndices[dim][cell] = 0; + else + _cellIndices[dim][cell] = 0; } if(dim > 0) rows = lastCols; lastCols = cols; - if(cols == 0){ // no dim-cells, no map + if(cols == 0) { // no dim-cells, no map _HMatrix[dim] = NULL; } - else if(rows == 0){ // no dim-1-cells, maps everything to zero + else if(rows == 0) { // no dim-1-cells, maps everything to zero _HMatrix[dim] = create_gmp_matrix_zero(1, cols); } - else{ + else { mpz_t elem; mpz_init(elem); _HMatrix[dim] = create_gmp_matrix_zero(rows, cols); - for( std::set<Cell*, Less_Cell>::iterator cit = - cellComplex->firstCell(dim); - cit != cellComplex->lastCell(dim); cit++){ - Cell* cell = *cit; - if( (domain == 0 && !cell->inSubdomain()) || domain == 1 - || (domain == 2 && cell->inSubdomain()) ){ + for(std::set<Cell *, Less_Cell>::iterator cit = + cellComplex->firstCell(dim); + cit != cellComplex->lastCell(dim); cit++) { + Cell *cell = *cit; + if((domain == 0 && !cell->inSubdomain()) || domain == 1 || + (domain == 2 && cell->inSubdomain())) { for(Cell::biter it = cell->firstBoundary(); - it != cell->lastBoundary(); it++){ - Cell* bdCell = it->first; - if(it->second.get() == 0) continue; - if((domain == 0 && !bdCell->inSubdomain()) || domain == 1 - || (domain == 2 && cell->inSubdomain()) ){ + it != cell->lastBoundary(); it++) { + Cell *bdCell = it->first; + if(it->second.get() == 0) continue; + if((domain == 0 && !bdCell->inSubdomain()) || domain == 1 || + (domain == 2 && cell->inSubdomain())) { int old_elem = 0; int bdCellIndex = getCellIndex(bdCell); int cellIndex = getCellIndex(cell); - if(bdCellIndex > (int)gmp_matrix_rows( _HMatrix[dim]) - || bdCellIndex < 1 - || cellIndex > (int)gmp_matrix_cols( _HMatrix[dim]) - || cellIndex < 1){ + if(bdCellIndex > (int)gmp_matrix_rows(_HMatrix[dim]) || + bdCellIndex < 1 || + cellIndex > (int)gmp_matrix_cols(_HMatrix[dim]) || + cellIndex < 1) { Msg::Debug("Index out of bound! HMatrix: %d", dim); } - else{ - gmp_matrix_get_elem(elem, bdCellIndex, - cellIndex, _HMatrix[dim]); + else { + gmp_matrix_get_elem(elem, bdCellIndex, cellIndex, + _HMatrix[dim]); old_elem = mpz_get_si(elem); mpz_set_si(elem, old_elem + it->second.get()); - if( abs((old_elem + it->second.get())) > 1){ - //printf("Incidence index: %d, in HMatrix: %d. \n", (old_elem + (*it).second), dim); + if(abs((old_elem + it->second.get())) > 1) { + // printf("Incidence index: %d, in HMatrix: %d. \n", (old_elem + // + (*it).second), dim); } - gmp_matrix_set_elem(elem, bdCellIndex, - cellIndex, _HMatrix[dim]); + gmp_matrix_set_elem(elem, bdCellIndex, cellIndex, + _HMatrix[dim]); } } } @@ -105,7 +107,7 @@ ChainComplex::ChainComplex(CellComplex* cellComplex, int domain) ChainComplex::~ChainComplex() { - for(int i = 0; i < 5; i++){ + for(int i = 0; i < 5; i++) { destroy_gmp_matrix(_HMatrix[i]); destroy_gmp_matrix(_kerH[i]); destroy_gmp_matrix(_codH[i]); @@ -130,42 +132,39 @@ void ChainComplex::KerCod(int dim) { if(dim < 0 || dim > 3 || _HMatrix[dim] == NULL) return; - gmp_matrix* HMatrix - = copy_gmp_matrix(_HMatrix[dim], 1, 1, - gmp_matrix_rows(_HMatrix[dim]), - gmp_matrix_cols(_HMatrix[dim])); + gmp_matrix *HMatrix = + copy_gmp_matrix(_HMatrix[dim], 1, 1, gmp_matrix_rows(_HMatrix[dim]), + gmp_matrix_cols(_HMatrix[dim])); - gmp_normal_form* normalForm - = create_gmp_Hermite_normal_form(HMatrix, NOT_INVERTED, INVERTED); - //printMatrix(normalForm->left); - //printMatrix(normalForm->canonical); - //printMatrix(normalForm->right); + gmp_normal_form *normalForm = + create_gmp_Hermite_normal_form(HMatrix, NOT_INVERTED, INVERTED); + // printMatrix(normalForm->left); + // printMatrix(normalForm->canonical); + // printMatrix(normalForm->right); int minRowCol = std::min(gmp_matrix_rows(normalForm->canonical), - gmp_matrix_cols(normalForm->canonical)); + gmp_matrix_cols(normalForm->canonical)); int rank = 0; mpz_t elem; mpz_init(elem); // find the rank - while(rank < minRowCol){ - gmp_matrix_get_elem(elem, rank+1, rank+1, normalForm->canonical); - if(mpz_cmp_si(elem,0) == 0) break; + while(rank < minRowCol) { + gmp_matrix_get_elem(elem, rank + 1, rank + 1, normalForm->canonical); + if(mpz_cmp_si(elem, 0) == 0) break; rank++; } - if(rank != (int)gmp_matrix_cols(normalForm->canonical)){ - _kerH[dim] - = copy_gmp_matrix(normalForm->right, 1, rank+1, - gmp_matrix_rows(normalForm->right), - gmp_matrix_cols(normalForm->right)); + if(rank != (int)gmp_matrix_cols(normalForm->canonical)) { + _kerH[dim] = copy_gmp_matrix(normalForm->right, 1, rank + 1, + gmp_matrix_rows(normalForm->right), + gmp_matrix_cols(normalForm->right)); } - if(rank > 0){ - _codH[dim] = - copy_gmp_matrix(normalForm->canonical, 1, 1, - gmp_matrix_rows(normalForm->canonical), rank); - gmp_matrix_left_mult(normalForm->left, _codH[dim]); + if(rank > 0) { + _codH[dim] = copy_gmp_matrix(normalForm->canonical, 1, 1, + gmp_matrix_rows(normalForm->canonical), rank); + gmp_matrix_left_mult(normalForm->left, _codH[dim]); } mpz_clear(elem); @@ -174,22 +173,19 @@ void ChainComplex::KerCod(int dim) return; } -//j:B_k->Z_k +// j:B_k->Z_k void ChainComplex::Inclusion(int lowDim, int highDim) { - if(getKerHMatrix(lowDim) == NULL - || getCodHMatrix(highDim) == NULL - || abs(lowDim-highDim) != 1) return; - - gmp_matrix* Zbasis = - copy_gmp_matrix(_kerH[lowDim], 1, 1, - gmp_matrix_rows(_kerH[lowDim]), - gmp_matrix_cols(_kerH[lowDim])); - gmp_matrix* Bbasis - = copy_gmp_matrix(_codH[highDim], 1, 1, - gmp_matrix_rows(_codH[highDim]), - gmp_matrix_cols(_codH[highDim])); + if(getKerHMatrix(lowDim) == NULL || getCodHMatrix(highDim) == NULL || + abs(lowDim - highDim) != 1) + return; + gmp_matrix *Zbasis = + copy_gmp_matrix(_kerH[lowDim], 1, 1, gmp_matrix_rows(_kerH[lowDim]), + gmp_matrix_cols(_kerH[lowDim])); + gmp_matrix *Bbasis = + copy_gmp_matrix(_codH[highDim], 1, 1, gmp_matrix_rows(_codH[highDim]), + gmp_matrix_cols(_codH[highDim])); int rows = gmp_matrix_rows(Bbasis); int cols = gmp_matrix_cols(Bbasis); @@ -208,16 +204,15 @@ void ChainComplex::Inclusion(int lowDim, int highDim) } // inv(U)*A*inv(V) = S - gmp_normal_form* normalForm - = create_gmp_Smith_normal_form(Zbasis, INVERTED, INVERTED); + gmp_normal_form *normalForm = + create_gmp_Smith_normal_form(Zbasis, INVERTED, INVERTED); mpz_t elem; mpz_init(elem); - for(int i = 1; i <= cols; i++){ - + for(int i = 1; i <= cols; i++) { gmp_matrix_get_elem(elem, i, i, normalForm->canonical); - if(mpz_cmp_si(elem,0) == 0){ + if(mpz_cmp_si(elem, 0) == 0) { destroy_gmp_matrix(Bbasis); destroy_gmp_normal_form(normalForm); return; @@ -226,9 +221,8 @@ void ChainComplex::Inclusion(int lowDim, int highDim) gmp_matrix_left_mult(normalForm->left, Bbasis); - gmp_matrix* LB = copy_gmp_matrix(Bbasis, 1, 1, - gmp_matrix_cols(Zbasis), - gmp_matrix_cols(Bbasis)); + gmp_matrix *LB = copy_gmp_matrix(Bbasis, 1, 1, gmp_matrix_cols(Zbasis), + gmp_matrix_cols(Bbasis)); destroy_gmp_matrix(Bbasis); rows = gmp_matrix_rows(LB); @@ -241,12 +235,12 @@ void ChainComplex::Inclusion(int lowDim, int highDim) mpz_t result; mpz_init(result); - for(int i = 1; i <= rows; i++){ + for(int i = 1; i <= rows; i++) { gmp_matrix_get_elem(divisor, i, i, normalForm->canonical); - for(int j = 1; j <= cols; j++){ + for(int j = 1; j <= cols; j++) { gmp_matrix_get_elem(elem, i, j, LB); mpz_cdiv_qr(result, remainder, elem, divisor); - if(mpz_cmp_si(remainder, 0) == 0){ + if(mpz_cmp_si(remainder, 0) == 0) { gmp_matrix_set_elem(result, i, j, LB); } else { @@ -273,38 +267,37 @@ void ChainComplex::Quotient(int dim, int setDim) if(dim < 0 || dim > 4 || _JMatrix[dim] == NULL) return; if(setDim < 0 || setDim > 4) return; - gmp_matrix* JMatrix = - copy_gmp_matrix(_JMatrix[dim], 1, 1, - gmp_matrix_rows(_JMatrix[dim]), - gmp_matrix_cols(_JMatrix[dim])); + gmp_matrix *JMatrix = + copy_gmp_matrix(_JMatrix[dim], 1, 1, gmp_matrix_rows(_JMatrix[dim]), + gmp_matrix_cols(_JMatrix[dim])); int rows = gmp_matrix_rows(JMatrix); int cols = gmp_matrix_cols(JMatrix); - gmp_normal_form* normalForm = + gmp_normal_form *normalForm = create_gmp_Smith_normal_form(JMatrix, NOT_INVERTED, NOT_INVERTED); - //printMatrix(normalForm->left); - //printMatrix(normalForm->canonical); - //printMatrix(normalForm->right); + // printMatrix(normalForm->left); + // printMatrix(normalForm->canonical); + // printMatrix(normalForm->right); mpz_t elem; mpz_init(elem); - for(int i = 1; i <= cols; i++){ + for(int i = 1; i <= cols; i++) { gmp_matrix_get_elem(elem, i, i, normalForm->canonical); - if(mpz_cmp_si(elem,0) == 0){ + if(mpz_cmp_si(elem, 0) == 0) { destroy_gmp_normal_form(normalForm); return; } - if(mpz_cmp_si(elem,1) > 0) { + if(mpz_cmp_si(elem, 1) > 0) { _torsion[setDim].push_back(mpz_get_si(elem)); } } int rank = cols - _torsion[setDim].size(); - if(rows - rank > 0){ - gmp_matrix* Hbasis = - copy_gmp_matrix(normalForm->left, 1, rank+1, rows, rows); + if(rows - rank > 0) { + gmp_matrix *Hbasis = + copy_gmp_matrix(normalForm->left, 1, rank + 1, rows, rows); _QMatrix[dim] = Hbasis; } @@ -321,76 +314,71 @@ void ChainComplex::computeHomology(bool dual) if(dual) transposeHMatrices(); - for(int i=-1; i < 4; i++){ - - if(dual){ - lowDim = getDim()+1-i; - highDim = getDim()+1-(i+1); + for(int i = -1; i < 4; i++) { + if(dual) { + lowDim = getDim() + 1 - i; + highDim = getDim() + 1 - (i + 1); setDim = highDim; } - else{ + else { lowDim = i; - highDim = i+1; + highDim = i + 1; setDim = lowDim; } KerCod(highDim); // 1) no edges, but zero cells - if(lowDim == 0 && !dual - && gmp_matrix_cols(getHMatrix(lowDim)) > 0 - && getHMatrix(highDim) == NULL) { - setHbasis( setDim, - create_gmp_matrix_identity(gmp_matrix_cols(getHMatrix(lowDim))) ); + if(lowDim == 0 && !dual && gmp_matrix_cols(getHMatrix(lowDim)) > 0 && + getHMatrix(highDim) == NULL) { + setHbasis(setDim, create_gmp_matrix_identity( + gmp_matrix_cols(getHMatrix(lowDim)))); } - else if(highDim == 0 && dual - && gmp_matrix_rows(getHMatrix(highDim)) > 0 - && getHMatrix(lowDim) == NULL) { - setHbasis( setDim, - create_gmp_matrix_identity(gmp_matrix_rows(getHMatrix(highDim))) ); + else if(highDim == 0 && dual && gmp_matrix_rows(getHMatrix(highDim)) > 0 && + getHMatrix(lowDim) == NULL) { + setHbasis(setDim, create_gmp_matrix_identity( + gmp_matrix_rows(getHMatrix(highDim)))); } // 2) this dimension is empty - else if(getHMatrix(setDim) == NULL){ + else if(getHMatrix(setDim) == NULL) { setHbasis(setDim, NULL); } // 3) No higher dimension cells -> none of the cycles are boundaries - else if(getHMatrix(highDim) == NULL){ - setHbasis( setDim, - copy_gmp_matrix(getKerHMatrix(lowDim), 1, 1, - gmp_matrix_rows(getKerHMatrix(lowDim)), - gmp_matrix_cols(getKerHMatrix(lowDim))) ); + else if(getHMatrix(highDim) == NULL) { + setHbasis(setDim, + copy_gmp_matrix(getKerHMatrix(lowDim), 1, 1, + gmp_matrix_rows(getKerHMatrix(lowDim)), + gmp_matrix_cols(getKerHMatrix(lowDim)))); } - // 5) General case: // 1) Find the bases of boundaries B and cycles Z // 2) find j: B -> Z and // 3) find quotient Z/j(B) else { - // 4) No lower dimension cells -> all chains are cycles - if(getHMatrix(lowDim) == NULL){ - setKerHMatrix(lowDim, - create_gmp_matrix_identity(gmp_matrix_rows(getHMatrix(highDim))) ); + if(getHMatrix(lowDim) == NULL) { + setKerHMatrix(lowDim, create_gmp_matrix_identity( + gmp_matrix_rows(getHMatrix(highDim)))); } Inclusion(lowDim, highDim); Quotient(lowDim, setDim); - if(getCodHMatrix(highDim) == NULL){ + if(getCodHMatrix(highDim) == NULL) { setHbasis(setDim, - copy_gmp_matrix(getKerHMatrix(lowDim), 1, 1, - gmp_matrix_rows(getKerHMatrix(lowDim)), - gmp_matrix_cols(getKerHMatrix(lowDim))) ); + copy_gmp_matrix(getKerHMatrix(lowDim), 1, 1, + gmp_matrix_rows(getKerHMatrix(lowDim)), + gmp_matrix_cols(getKerHMatrix(lowDim)))); } - else if(getJMatrix(lowDim) == NULL || getQMatrix(lowDim) == NULL){ + else if(getJMatrix(lowDim) == NULL || getQMatrix(lowDim) == NULL) { setHbasis(setDim, NULL); } - else{ + else { setHbasis(setDim, - copy_gmp_matrix(getKerHMatrix(lowDim), 1, 1, - gmp_matrix_rows(getKerHMatrix(lowDim)), - gmp_matrix_cols(getKerHMatrix(lowDim))) ); + copy_gmp_matrix(getKerHMatrix(lowDim), 1, 1, + gmp_matrix_rows(getKerHMatrix(lowDim)), + gmp_matrix_cols(getKerHMatrix(lowDim)))); gmp_matrix_right_mult(getHbasis(setDim), getQMatrix(lowDim)); } @@ -410,11 +398,11 @@ void ChainComplex::matrixTest() const int rows = 3; const int cols = 6; - long int elems[rows*cols]; - for(int i = 1; i<=rows*cols; i++) elems[i-1] = i; + long int elems[rows * cols]; + for(int i = 1; i <= rows * cols; i++) elems[i - 1] = i; - gmp_matrix* matrix = create_gmp_matrix_int(rows, cols, elems); - gmp_matrix* copymatrix = copy_gmp_matrix(matrix, 3, 2, 3, 5); + gmp_matrix *matrix = create_gmp_matrix_int(rows, cols, elems); + gmp_matrix *copymatrix = copy_gmp_matrix(matrix, 3, 2, 3, 5); printMatrix(matrix); printMatrix(copymatrix); destroy_gmp_matrix(matrix); @@ -426,8 +414,8 @@ std::vector<int> ChainComplex::getCoeffVector(int dim, int chainNumber) std::vector<int> coeffVector; if(dim < 0 || dim > 4) return coeffVector; - if(_Hbasis[dim] == NULL - || (int)gmp_matrix_cols(_Hbasis[dim]) < chainNumber) return coeffVector; + if(_Hbasis[dim] == NULL || (int)gmp_matrix_cols(_Hbasis[dim]) < chainNumber) + return coeffVector; int rows = gmp_matrix_rows(_Hbasis[dim]); @@ -436,36 +424,40 @@ std::vector<int> ChainComplex::getCoeffVector(int dim, int chainNumber) mpz_t elem; mpz_init(elem); - for(int i = 1; i <= rows; i++){ + for(int i = 1; i <= rows; i++) { gmp_matrix_get_elem(elem, i, chainNumber, _Hbasis[dim]); elemli = mpz_get_si(elem); elemi = elemli; coeffVector.push_back(elemi); - //printf("coeff: %d \n", coeffVector.at(i-1)); + // printf("coeff: %d \n", coeffVector.at(i-1)); } mpz_clear(elem); return coeffVector; } -gmp_matrix* ChainComplex::getBasis(int dim, int basis) +gmp_matrix *ChainComplex::getBasis(int dim, int basis) { - if(dim > -2 && dim < 4 && basis == 2) return _codH[dim+1]; - if(dim < 0 || dim > 4) return NULL; - else if(basis == 1) return _kerH[dim]; - else if(basis == 3) return _Hbasis[dim]; - else return NULL; + if(dim > -2 && dim < 4 && basis == 2) return _codH[dim + 1]; + if(dim < 0 || dim > 4) + return NULL; + else if(basis == 1) + return _kerH[dim]; + else if(basis == 3) + return _Hbasis[dim]; + else + return NULL; } -void ChainComplex::getBasisChain(std::map<Cell*, int, Less_Cell>& chain, - int num, int dim, int basis, bool deform) +void ChainComplex::getBasisChain(std::map<Cell *, int, Less_Cell> &chain, + int num, int dim, int basis, bool deform) { if(basis < 0 || basis > 3) return; - gmp_matrix* basisMatrix = getBasis(dim, basis); + gmp_matrix *basisMatrix = getBasis(dim, basis); chain.clear(); if(dim < 0 || dim > 3) return; - if(basisMatrix == NULL || (int)gmp_matrix_cols(basisMatrix) < num){ + if(basisMatrix == NULL || (int)gmp_matrix_cols(basisMatrix) < num) { return; } @@ -477,64 +469,68 @@ void ChainComplex::getBasisChain(std::map<Cell*, int, Less_Cell>& chain, int torsion = 1; if(basis == 3) torsion = getTorsion(dim, num); - for(citer cit = this->firstCell(dim); cit != this->lastCell(dim); cit++){ - Cell* cell = cit->first; + for(citer cit = this->firstCell(dim); cit != this->lastCell(dim); cit++) { + Cell *cell = cit->first; int index = cit->second; gmp_matrix_get_elem(elem, index, num, basisMatrix); elemli = mpz_get_si(elem); elemi = elemli; - if(elemli != 0){ - std::map<Cell*, int, Less_Cell > subCells; + if(elemli != 0) { + std::map<Cell *, int, Less_Cell> subCells; cell->getCells(subCells); - for(Cell::citer it = subCells.begin(); it != subCells.end(); it++){ - Cell* subCell = it->first; - int coeff = it->second*elemi*torsion; + for(Cell::citer it = subCells.begin(); it != subCells.end(); it++) { + Cell *subCell = it->first; + int coeff = it->second * elemi * torsion; if(coeff == 0) continue; - chain[subCell] = coeff; + chain[subCell] = coeff; } } } mpz_clear(elem); - if(deform && basis == 3 && (dim == 1 || dim == 2) ) smoothenChain(chain); + if(deform && basis == 3 && (dim == 1 || dim == 2)) smoothenChain(chain); } int ChainComplex::getBasisSize(int dim, int basis) { - gmp_matrix* basisMatrix; - if(basis == 0 && _HMatrix[dim] != NULL){ - return gmp_matrix_cols(_HMatrix[dim]); - } - else if(basis == 1) basisMatrix = getBasis(dim, 1); - else if(basis == 2) basisMatrix = getBasis(dim, 2); - else if(basis == 3) basisMatrix = getBasis(dim, 3); - else return 0; - - if(basisMatrix != NULL && gmp_matrix_rows(basisMatrix) != 0) - return gmp_matrix_cols(basisMatrix); - else return 0; + gmp_matrix *basisMatrix; + if(basis == 0 && _HMatrix[dim] != NULL) { + return gmp_matrix_cols(_HMatrix[dim]); + } + else if(basis == 1) + basisMatrix = getBasis(dim, 1); + else if(basis == 2) + basisMatrix = getBasis(dim, 2); + else if(basis == 3) + basisMatrix = getBasis(dim, 3); + else + return 0; + + if(basisMatrix != NULL && gmp_matrix_rows(basisMatrix) != 0) + return gmp_matrix_cols(basisMatrix); + else + return 0; } - int ChainComplex::getTorsion(int dim, int num) { if(dim < 0 || dim > 4) return 0; - if(_Hbasis[dim] == NULL - || (int)gmp_matrix_cols(_Hbasis[dim]) < num) return 0; - if(_torsion[dim].empty() - || (int)_torsion[dim].size() < num) return 1; - else return _torsion[dim].at(num-1); + if(_Hbasis[dim] == NULL || (int)gmp_matrix_cols(_Hbasis[dim]) < num) return 0; + if(_torsion[dim].empty() || (int)_torsion[dim].size() < num) + return 1; + else + return _torsion[dim].at(num - 1); } -bool ChainComplex::deform(std::map<Cell*, int, Less_Cell>& cells, - std::map<Cell*, int, Less_Cell>& cellsInChain, - std::map<Cell*, int, Less_Cell>& cellsNotInChain) +bool ChainComplex::deform(std::map<Cell *, int, Less_Cell> &cells, + std::map<Cell *, int, Less_Cell> &cellsInChain, + std::map<Cell *, int, Less_Cell> &cellsNotInChain) { std::vector<int> cc; std::vector<int> bc; - for(citer cit = cellsInChain.begin(); cit != cellsInChain.end(); cit++){ - Cell* c = (*cit).first; + for(citer cit = cellsInChain.begin(); cit != cellsInChain.end(); cit++) { + Cell *c = (*cit).first; c->setImmune(false); if(!c->inSubdomain()) { int coeff = 0; @@ -545,31 +541,33 @@ bool ChainComplex::deform(std::map<Cell*, int, Less_Cell>& cells, } } - if(cc.empty() || (getDim() == 2 && cc.size() < 2) ) return false; - int inout = cc[0]*bc[0]; - for(unsigned int i = 0; i < cc.size(); i++){ - if(cc[i]*bc[i] != inout) return false; + if(cc.empty() || (getDim() == 2 && cc.size() < 2)) return false; + int inout = cc[0] * bc[0]; + for(unsigned int i = 0; i < cc.size(); i++) { + if(cc[i] * bc[i] != inout) return false; } - for(citer cit = cellsInChain.begin(); cit != cellsInChain.end(); cit++){ - Cell* cell = cit->first; + for(citer cit = cellsInChain.begin(); cit != cellsInChain.end(); cit++) { + Cell *cell = cit->first; citer it = cells.find(cell); if(it != cells.end()) cells[cell] = 0; } int n = 1; for(citer cit = cellsNotInChain.begin(); cit != cellsNotInChain.end(); - cit++){ - Cell* cell = (*cit).first; - if(n == 2) cell->setImmune(true); - else cell->setImmune(false); - int coeff = -1*inout*(*cit).second; - - std::pair<citer,bool> insert = cells.insert( std::make_pair( cell, coeff)); - if(!insert.second && (*insert.first).second == 0){ + cit++) { + Cell *cell = (*cit).first; + if(n == 2) + cell->setImmune(true); + else + cell->setImmune(false); + int coeff = -1 * inout * (*cit).second; + + std::pair<citer, bool> insert = cells.insert(std::make_pair(cell, coeff)); + if(!insert.second && (*insert.first).second == 0) { (*insert.first).second = coeff; } - else if (!insert.second && (*insert.first).second != 0){ + else if(!insert.second && (*insert.first).second != 0) { Msg::Error("Invalid chain smoothening add!"); } n++; @@ -577,34 +575,34 @@ bool ChainComplex::deform(std::map<Cell*, int, Less_Cell>& cells, return true; } -bool ChainComplex::deformChain(std::map<Cell*, int, Less_Cell>& cells, - std::pair<Cell*, int> cell, bool bend) +bool ChainComplex::deformChain(std::map<Cell *, int, Less_Cell> &cells, + std::pair<Cell *, int> cell, bool bend) { - Cell* c1 = cell.first; + Cell *c1 = cell.first; int dim = c1->getDim(); for(Cell::biter cit = c1->firstCoboundary(true); cit != c1->lastCoboundary(); - cit++){ - - std::map<Cell*, int, Less_Cell> cellsInChain; - std::map<Cell*, int, Less_Cell> cellsNotInChain; - Cell* c1CbdCell = cit->first; + cit++) { + std::map<Cell *, int, Less_Cell> cellsInChain; + std::map<Cell *, int, Less_Cell> cellsNotInChain; + Cell *c1CbdCell = cit->first; for(Cell::biter cit2 = c1CbdCell->firstBoundary(true); - cit2 != c1CbdCell->lastBoundary(); cit2++){ - Cell* c1CbdBdCell = cit2->first; + cit2 != c1CbdCell->lastBoundary(); cit2++) { + Cell *c1CbdBdCell = cit2->first; int coeff = cit2->second.geto(); if(coeff == 0) continue; - if( (cells.find(c1CbdBdCell) != cells.end() && cells[c1CbdBdCell] != 0) - || c1CbdBdCell->inSubdomain()){ - cellsInChain.insert(std::make_pair(c1CbdBdCell, coeff)); + if((cells.find(c1CbdBdCell) != cells.end() && cells[c1CbdBdCell] != 0) || + c1CbdBdCell->inSubdomain()) { + cellsInChain.insert(std::make_pair(c1CbdBdCell, coeff)); } - else cellsNotInChain.insert(std::make_pair(c1CbdBdCell, coeff)); + else + cellsNotInChain.insert(std::make_pair(c1CbdBdCell, coeff)); } bool next = false; - for(citer cit2 = cellsInChain.begin(); cit2 != cellsInChain.end(); cit2++){ - Cell* c = (*cit2).first; + for(citer cit2 = cellsInChain.begin(); cit2 != cellsInChain.end(); cit2++) { + Cell *c = (*cit2).first; int coeff = 0; citer it = cells.find(c); if(it != cells.end()) coeff = it->second; @@ -614,31 +612,29 @@ bool ChainComplex::deformChain(std::map<Cell*, int, Less_Cell>& cells, } for(citer cit2 = cellsNotInChain.begin(); cit2 != cellsNotInChain.end(); - cit2++){ - Cell* c = (*cit2).first; + cit2++) { + Cell *c = (*cit2).first; if(c->inSubdomain()) next = true; } if(next) continue; - if( (dim == 1 && cellsInChain.size() == 2 - && cellsNotInChain.size() == 1) || - (dim == 2 && cellsInChain.size() == 3 - && cellsNotInChain.size() == 1)){ - //printf("straighten \n"); + if((dim == 1 && cellsInChain.size() == 2 && cellsNotInChain.size() == 1) || + (dim == 2 && cellsInChain.size() == 3 && cellsNotInChain.size() == 1)) { + // printf("straighten \n"); return deform(cells, cellsInChain, cellsNotInChain); } - else if ( (dim == 1 && cellsInChain.size() == 1 - && cellsNotInChain.size() == 2 && bend) || - (dim == 2 && cellsInChain.size() == 2 - && cellsNotInChain.size() == 2 && bend)){ - //printf("bend \n"); + else if((dim == 1 && cellsInChain.size() == 1 && + cellsNotInChain.size() == 2 && bend) || + (dim == 2 && cellsInChain.size() == 2 && + cellsNotInChain.size() == 2 && bend)) { + // printf("bend \n"); return deform(cells, cellsInChain, cellsNotInChain); } - else if ((dim == 1 && cellsInChain.size() == 3 - && cellsNotInChain.size() == 0) || - (dim == 2 && cellsInChain.size() == 4 - && cellsNotInChain.size() == 0)){ - //printf("remove boundary \n"); + else if((dim == 1 && cellsInChain.size() == 3 && + cellsNotInChain.size() == 0) || + (dim == 2 && cellsInChain.size() == 4 && + cellsNotInChain.size() == 0)) { + // printf("remove boundary \n"); return deform(cells, cellsInChain, cellsNotInChain); } } @@ -646,16 +642,16 @@ bool ChainComplex::deformChain(std::map<Cell*, int, Less_Cell>& cells, return false; } -void ChainComplex::smoothenChain(std::map<Cell*, int, Less_Cell>& cells) +void ChainComplex::smoothenChain(std::map<Cell *, int, Less_Cell> &cells) { if(!_cellComplex->simplicial() || cells.size() < 2) return; int dim = cells.begin()->first->getDim(); int start = cells.size(); int useless = 0; - for(int i = 0; i < 20; i++){ + for(int i = 0; i < 20; i++) { int size = cells.size(); - for(citer cit = cells.begin(); cit != cells.end(); cit++){ + for(citer cit = cells.begin(); cit != cells.end(); cit++) { if(dim == 2) deformChain(cells, *cit, true); deformChain(cells, *cit, false); } @@ -663,34 +659,36 @@ void ChainComplex::smoothenChain(std::map<Cell*, int, Less_Cell>& cells) deImmuneCells(cells); eraseNullCells(cells); - if (size >= (int)cells.size()) useless++; - else useless = 0; - if (useless > 5) break; + if(size >= (int)cells.size()) + useless++; + else + useless = 0; + if(useless > 5) break; } deImmuneCells(cells); - for(citer cit = cells.begin(); cit != cells.end(); cit++){ + for(citer cit = cells.begin(); cit != cells.end(); cit++) { deformChain(cells, *cit, false); } eraseNullCells(cells); int size = cells.size(); - Msg::Debug("Simplified a %d-chain from %d cells to %d cells", - dim, start, size); + Msg::Debug("Simplified a %d-chain from %d cells to %d cells", dim, start, + size); } -void ChainComplex::eraseNullCells(std::map<Cell*, int, Less_Cell>& cells) +void ChainComplex::eraseNullCells(std::map<Cell *, int, Less_Cell> &cells) { - std::vector<Cell*> toRemove; - for(citer cit = cells.begin(); cit != cells.end(); cit++){ + std::vector<Cell *> toRemove; + for(citer cit = cells.begin(); cit != cells.end(); cit++) { if(cit->second == 0) toRemove.push_back(cit->first); } for(unsigned int i = 0; i < toRemove.size(); i++) cells.erase(toRemove[i]); } -void ChainComplex::deImmuneCells(std::map<Cell*, int, Less_Cell>& cells) +void ChainComplex::deImmuneCells(std::map<Cell *, int, Less_Cell> &cells) { - for(citer cit = cells.begin(); cit != cells.end(); cit++){ - Cell* cell = (*cit).first; + for(citer cit = cells.begin(); cit != cells.end(); cit++) { + Cell *cell = (*cit).first; cell->setImmune(false); } } diff --git a/Geo/ChainComplex.h b/Geo/ChainComplex.h index 866bfcdc919e335e5f3b34b64c53c8979f863a79..549daf9fbdc85e9baf846b15827762aeca79290a 100644 --- a/Geo/ChainComplex.h +++ b/Geo/ChainComplex.h @@ -19,11 +19,11 @@ #include "CellComplex.h" #if defined(HAVE_GMP) - #include "gmp.h" - #include "gmp_normal_form.h" +#include "gmp.h" +#include "gmp_normal_form.h" #else - #include "mpz.h" - #include "gmp_normal_form.h" +#include "mpz.h" +#include "gmp_normal_form.h" #endif class CellComplex; @@ -32,80 +32,120 @@ class CellComplex; // This should only be constructed for a reduced cell complex because of // dense matrix representations and great computational complexity in // its methods. -class ChainComplex -{ - private: +class ChainComplex { +private: // boundary operator matrices for this chain complex // h_k: C_k -> C_(k-1) - gmp_matrix* _HMatrix[5]; + gmp_matrix *_HMatrix[5]; // Basis matrices for the kernels and codomains of the boundary operator // matrices - gmp_matrix* _kerH[5]; - gmp_matrix* _codH[5]; + gmp_matrix *_kerH[5]; + gmp_matrix *_codH[5]; // matrix of the mapping B_k -> Z_k - gmp_matrix* _JMatrix[5]; + gmp_matrix *_JMatrix[5]; // matrix of the mapping H_k -> Z_k - gmp_matrix* _QMatrix[5]; + gmp_matrix *_QMatrix[5]; // bases for homology groups - gmp_matrix* _Hbasis[5]; + gmp_matrix *_Hbasis[5]; // torsion coefficients of homology generators // corresponding the columns of _Hbasis std::vector<long int> _torsion[5]; int _dim; - CellComplex* _cellComplex; + CellComplex *_cellComplex; // index to cell map // matrix indices correspond to these cells in _cellComplex - std::map<Cell*, int, Less_Cell> _cellIndices[4]; + std::map<Cell *, int, Less_Cell> _cellIndices[4]; // set the matrices - void setHMatrix(int dim, gmp_matrix* matrix) { - if(dim > -1 && dim < 5) _HMatrix[dim] = matrix;} - void setKerHMatrix(int dim, gmp_matrix* matrix) { - if(dim > -1 && dim < 5) _kerH[dim] = matrix;} - void setCodHMatrix(int dim, gmp_matrix* matrix) { - if(dim > -1 && dim < 5) _codH[dim] = matrix;} - void setJMatrix(int dim, gmp_matrix* matrix) { - if(dim > -1 && dim < 5) _JMatrix[dim] = matrix;} - void setQMatrix(int dim, gmp_matrix* matrix) { - if(dim > -1 && dim < 5) _QMatrix[dim] = matrix;} - void setHbasis(int dim, gmp_matrix* matrix) { - if(dim > -1 && dim < 5) _Hbasis[dim] = matrix;} - + void setHMatrix(int dim, gmp_matrix *matrix) + { + if(dim > -1 && dim < 5) _HMatrix[dim] = matrix; + } + void setKerHMatrix(int dim, gmp_matrix *matrix) + { + if(dim > -1 && dim < 5) _kerH[dim] = matrix; + } + void setCodHMatrix(int dim, gmp_matrix *matrix) + { + if(dim > -1 && dim < 5) _codH[dim] = matrix; + } + void setJMatrix(int dim, gmp_matrix *matrix) + { + if(dim > -1 && dim < 5) _JMatrix[dim] = matrix; + } + void setQMatrix(int dim, gmp_matrix *matrix) + { + if(dim > -1 && dim < 5) _QMatrix[dim] = matrix; + } + void setHbasis(int dim, gmp_matrix *matrix) + { + if(dim > -1 && dim < 5) _Hbasis[dim] = matrix; + } // get the boundary operator matrix dim->dim-1 - gmp_matrix* getHMatrix(int dim) const { - if(dim > -1 && dim < 5) return _HMatrix[dim]; else return NULL;} - gmp_matrix* getKerHMatrix(int dim) const { - if(dim > -1 && dim < 5) return _kerH[dim]; else return NULL;} - gmp_matrix* getCodHMatrix(int dim) const { - if(dim > -1 && dim < 5) return _codH[dim]; else return NULL;} - gmp_matrix* getJMatrix(int dim) const { - if(dim > -1 && dim < 5) return _JMatrix[dim]; else return NULL;} - gmp_matrix* getQMatrix(int dim) const { - if(dim > -1 && dim < 5) return _QMatrix[dim]; else return NULL;} - gmp_matrix* getHbasis(int dim) const { - if(dim > -1 && dim < 5) return _Hbasis[dim]; else return NULL;} + gmp_matrix *getHMatrix(int dim) const + { + if(dim > -1 && dim < 5) + return _HMatrix[dim]; + else + return NULL; + } + gmp_matrix *getKerHMatrix(int dim) const + { + if(dim > -1 && dim < 5) + return _kerH[dim]; + else + return NULL; + } + gmp_matrix *getCodHMatrix(int dim) const + { + if(dim > -1 && dim < 5) + return _codH[dim]; + else + return NULL; + } + gmp_matrix *getJMatrix(int dim) const + { + if(dim > -1 && dim < 5) + return _JMatrix[dim]; + else + return NULL; + } + gmp_matrix *getQMatrix(int dim) const + { + if(dim > -1 && dim < 5) + return _QMatrix[dim]; + else + return NULL; + } + gmp_matrix *getHbasis(int dim) const + { + if(dim > -1 && dim < 5) + return _Hbasis[dim]; + else + return NULL; + } // local deformation tools for chains - bool deformChain(std::map<Cell*, int, Less_Cell>& cells, - std::pair<Cell*, int> cell, bool bend); - bool deform(std::map<Cell*, int, Less_Cell>& cells, - std::map<Cell*, int, Less_Cell>& cellsInChain, - std::map<Cell*, int, Less_Cell>& cellsNotInChain); - void smoothenChain(std::map<Cell*, int, Less_Cell>& cells); - void eraseNullCells(std::map<Cell*, int, Less_Cell>& cells); - void deImmuneCells(std::map<Cell*, int, Less_Cell>& cells); - - public: + bool deformChain(std::map<Cell *, int, Less_Cell> &cells, + std::pair<Cell *, int> cell, bool bend); + bool deform(std::map<Cell *, int, Less_Cell> &cells, + std::map<Cell *, int, Less_Cell> &cellsInChain, + std::map<Cell *, int, Less_Cell> &cellsNotInChain); + void smoothenChain(std::map<Cell *, int, Less_Cell> &cells); + void eraseNullCells(std::map<Cell *, int, Less_Cell> &cells); + void deImmuneCells(std::map<Cell *, int, Less_Cell> &cells); + +public: // domain = 0 : relative chain space // domain = 1 : absolute chain space of all cells in cellComplex // domain = 2 : absolute chain space of cells in subdomain - ChainComplex(CellComplex* cellComplex, int domain=0); + ChainComplex(CellComplex *cellComplex, int domain = 0); ~ChainComplex(); int getDim() const { return _dim; } @@ -114,16 +154,21 @@ class ChainComplex // 2 : B basis (boundaries) // 3 : H basis (homology) // get the bases for various spaces - gmp_matrix* getBasis(int dim, int basis); - gmp_matrix* getBoundaryOp(int dim) { - if(dim > -1 && dim < 5) return _HMatrix[dim]; else return NULL;} + gmp_matrix *getBasis(int dim, int basis); + gmp_matrix *getBoundaryOp(int dim) + { + if(dim > -1 && dim < 5) + return _HMatrix[dim]; + else + return NULL; + } // compute basis for kernel and codomain of boundary operator matrix // of dimension dim (ie. ker(h_dim) and cod(h_dim) ) void KerCod(int dim); - // compute matrix representation J for inclusion relation from dim-cells - // who are boundary of dim+1-cells to cycles of dim-cells - // (ie. j: cod(h_(dim+1)) -> ker(h_dim) ) + // compute matrix representation J for inclusion relation from dim-cells + // who are boundary of dim+1-cells to cycles of dim-cells + // (ie. j: cod(h_(dim+1)) -> ker(h_dim) ) void Inclusion(int lowDim, int highDim); // compute quotient problem for given inclusion relation j to find // representatives of homology group generators and possible @@ -136,17 +181,19 @@ class ChainComplex void transposeHMatrix(int dim); // Compute bases for the homology groups of this chain complex - void computeHomology(bool dual=false); - + void computeHomology(bool dual = false); - typedef std::map<Cell*, int, Less_Cell>::iterator citer; - citer firstCell(int dim){ return _cellIndices[dim].begin(); } - citer lastCell(int dim){ return _cellIndices[dim].end(); } + typedef std::map<Cell *, int, Less_Cell>::iterator citer; + citer firstCell(int dim) { return _cellIndices[dim].begin(); } + citer lastCell(int dim) { return _cellIndices[dim].end(); } // get the cell index - int getCellIndex(Cell* cell){ + int getCellIndex(Cell *cell) + { citer cit = _cellIndices[cell->getDim()].find(cell); - if(cit != lastCell(cell->getDim())) return cit->second; - else return 0; + if(cit != lastCell(cell->getDim())) + return cit->second; + else + return 0; } // get coefficient vector for dim-dimensional Hbasis chain chainNumber @@ -155,29 +202,31 @@ class ChainComplex // (deform: with local deformations to make chain smoother and to have // smaller support, deformed chain is homologous to the old one, // only works for chains of the primary chain complex) - void getBasisChain(std::map<Cell*, int, Less_Cell>& chain, - int num, int dim, int basis, bool deform=false); + void getBasisChain(std::map<Cell *, int, Less_Cell> &chain, int num, int dim, + int basis, bool deform = false); // get rank of a basis int getBasisSize(int dim, int basis); // homology torsion coefficient for dim-dimensional chain num int getTorsion(int dim, int num); // apply a transformation T to a basis (T should be unimodular) - void transformBasis(gmp_matrix* T, int dim, int basis){ + void transformBasis(gmp_matrix *T, int dim, int basis) + { if(basis == 3 && _Hbasis[dim] != NULL) { gmp_matrix_right_mult(_Hbasis[dim], T); } } - //void printBasisChain(std::map<Cell*, int, Less_Cell>& chain); + // void printBasisChain(std::map<Cell*, int, Less_Cell>& chain); // debugging aid - int printMatrix(gmp_matrix* matrix){ - printf("%d rows and %d columns\n", - (int)gmp_matrix_rows(matrix), (int)gmp_matrix_cols(matrix)); - return gmp_matrix_printf(matrix); } + int printMatrix(gmp_matrix *matrix) + { + printf("%d rows and %d columns\n", (int)gmp_matrix_rows(matrix), + (int)gmp_matrix_cols(matrix)); + return gmp_matrix_printf(matrix); + } void matrixTest(); }; #endif #endif - diff --git a/Geo/CustomContainer.h b/Geo/CustomContainer.h index 804480116fe44848a751b88aedba2d0b3fe772a6..6fbc42f87c9ef52c53665d6134f4f83b1af7a1c6 100644 --- a/Geo/CustomContainer.h +++ b/Geo/CustomContainer.h @@ -50,585 +50,496 @@ struct Box * ******************************************************************************/ -namespace CCon // "Custom Container" +namespace CCon // "Custom Container" { -template <typename T> -class Block; - - -/*============================================================================== - * - * Class Pool - * - * Purpose - * ======= - * - * Interface to the pool - * - *============================================================================*/ - -template <typename T> -class Pool -{ - - public: - - // Constructor - Pool(const unsigned _blockSize = 128) - : tailBlock(0), tailElement(0), blockSize(_blockSize), numUsedElement(0) - { } - - // Destructor - ~Pool() - { - delete_all_blocks(); - } - - // Get an element - void *get() - { - if(!tailElement) create_block(); - void *const rval = tailElement; - tailElement = static_cast<T*>(tailElement->get_pool_prev()); - ++numUsedElement; - return rval; - } - - // Return an element - void remit(T *const elem) - { - elem->set_pool_prev(tailElement); - tailElement = elem; - --numUsedElement; - } - - // Free memory used by the pool - void free_memory() - { - if(numUsedElement == 0) delete_all_blocks(); - else Msg::Debug("Request to delete pool with used elements in " - "CustomContainer.h"); - } - - private: - - // Data - Block<T> *tailBlock; - T *tailElement; - unsigned blockSize; - unsigned numUsedElement; - - // Create a new block - void create_block() - { - tailBlock = new Block<T>(tailBlock, blockSize); - const unsigned back = blockSize - 1; - tailBlock->array[back].set_pool_prev(tailElement); - tailElement = &tailBlock->array[back]; - for(int n = back; n--; ) { - T *const prev = tailElement--; - tailElement->set_pool_prev(prev); - } - } - - // Delete all blocks - void delete_all_blocks() - { - while(tailBlock) { - Block<T> *const block = tailBlock; - tailBlock = block->prev; - delete block; + template <typename T> class Block; + + /*============================================================================== + * + * Class Pool + * + * Purpose + * ======= + * + * Interface to the pool + * + *============================================================================*/ + + template <typename T> class Pool { + public: + // Constructor + Pool(const unsigned _blockSize = 128) + : tailBlock(0), tailElement(0), blockSize(_blockSize), numUsedElement(0) + { } - tailElement = 0; - } - - // Copy and assignment are not permitted - Pool(const Pool&); - Pool &operator=(const Pool&); - -}; - - -/*============================================================================== - * - * Class Block - * - * Purpose - * ======= - * - * Implements a block of uninitialized memory for type T - * - *============================================================================*/ - -template <typename T> -class Block -{ - - // Data - Block *const prev; - T *array; - - // Constructor - Block(Block *const _prev, const unsigned blockSize) - : prev(_prev) - { - array = static_cast<T*>(std::malloc(sizeof(T)*blockSize)); - } - - // Destructor - ~Block() - { - std::free(array); - } - - friend class Pool<T>; - -}; - - -/******************************************************************************* - * - * This allocator-like class is used to implement many small vectors which are - * sized according to the number of boundary vertices commonly expected to - * connect to a vertex in 2D and 3D zones: - * 2 - expected faces for vertex on zone edge in 2D - * 6 - expected faces for vertex on zone face in 3D - * 8 - overflow faces for vertex on zone face in 3D - * 16 - approximate faces for vertices on zone edges and corners in 3D - * Memory for the above sizes are pooled for reuse. Larger sizes are permitted - * and will be allocated using 'new' and 'delete'. - * - ******************************************************************************/ - -/*============================================================================== - * - * Class FaceAllocator - * - * Purpose - * ======= - * - * Lightweight allocator for class FaceVector - * - * Notes - * ===== - * - * - This lightweight allocator expects only primitive types. Constructors - * and destructors are not called for type T. - * - The memory is encapsulated in the Face* structures. Handles to these - * structures use the data array. A pointer to the structure is regained - * using the handle and an offset. This is mostly cautionary as the offset - * is normally expected to be zero. - * - No per-object data is stored as per normal requirements for allocators. - * Critical OpenMP sections are defined since multiple threads can access - * the allocator. - * - If set_offsets is to be used, T must have a default constructor. - * - *============================================================================*/ - -template <typename T> -class FaceAllocator -{ - public: + // Destructor + ~Pool() { delete_all_blocks(); } - // Memory structures - struct Face2 - { - T faces[2]; - void set_pool_prev(void *const p) + // Get an element + void *get() { - *reinterpret_cast<void**>(faces) = p; + if(!tailElement) create_block(); + void *const rval = tailElement; + tailElement = static_cast<T *>(tailElement->get_pool_prev()); + ++numUsedElement; + return rval; } - void *get_pool_prev() - { - return *reinterpret_cast<void**>(faces); - } - ptrdiff_t get_offset() const + + // Return an element + void remit(T *const elem) { - return reinterpret_cast<const char*>(this) - - reinterpret_cast<const char*>(faces); + elem->set_pool_prev(tailElement); + tailElement = elem; + --numUsedElement; } - }; - struct Face6 - { - T faces[6]; - void set_pool_prev(void *const p) + + // Free memory used by the pool + void free_memory() { - *reinterpret_cast<void**>(faces) = p; + if(numUsedElement == 0) + delete_all_blocks(); + else + Msg::Debug("Request to delete pool with used elements in " + "CustomContainer.h"); } - void *get_pool_prev() + + private: + // Data + Block<T> *tailBlock; + T *tailElement; + unsigned blockSize; + unsigned numUsedElement; + + // Create a new block + void create_block() { - return *reinterpret_cast<void**>(faces); + tailBlock = new Block<T>(tailBlock, blockSize); + const unsigned back = blockSize - 1; + tailBlock->array[back].set_pool_prev(tailElement); + tailElement = &tailBlock->array[back]; + for(int n = back; n--;) { + T *const prev = tailElement--; + tailElement->set_pool_prev(prev); + } } - ptrdiff_t get_offset() const + + // Delete all blocks + void delete_all_blocks() { - return reinterpret_cast<const char*>(this) - - reinterpret_cast<const char*>(faces); + while(tailBlock) { + Block<T> *const block = tailBlock; + tailBlock = block->prev; + delete block; + } + tailElement = 0; } + + // Copy and assignment are not permitted + Pool(const Pool &); + Pool &operator=(const Pool &); }; - struct Face8 - { - T faces[8]; - void set_pool_prev(void *const p) - { - *reinterpret_cast<void**>(faces) = p; - } - void *get_pool_prev() - { - return *reinterpret_cast<void**>(faces); - } - ptrdiff_t get_offset() const + + /*============================================================================== + * + * Class Block + * + * Purpose + * ======= + * + * Implements a block of uninitialized memory for type T + * + *============================================================================*/ + + template <typename T> class Block { + // Data + Block *const prev; + T *array; + + // Constructor + Block(Block *const _prev, const unsigned blockSize) : prev(_prev) { - return reinterpret_cast<const char*>(this) - - reinterpret_cast<const char*>(faces); + array = static_cast<T *>(std::malloc(sizeof(T) * blockSize)); } + + // Destructor + ~Block() { std::free(array); } + + friend class Pool<T>; }; - struct Face16 - { - T faces[16]; - void set_pool_prev(void *const p) - { - *reinterpret_cast<void**>(faces) = p; - } - void *get_pool_prev() + + /******************************************************************************* + * + * This allocator-like class is used to implement many small vectors which are + * sized according to the number of boundary vertices commonly expected to + * connect to a vertex in 2D and 3D zones: + * 2 - expected faces for vertex on zone edge in 2D + * 6 - expected faces for vertex on zone face in 3D + * 8 - overflow faces for vertex on zone face in 3D + * 16 - approximate faces for vertices on zone edges and corners in 3D + * Memory for the above sizes are pooled for reuse. Larger sizes are + *permitted and will be allocated using 'new' and 'delete'. + * + ******************************************************************************/ + + /*============================================================================== + * + * Class FaceAllocator + * + * Purpose + * ======= + * + * Lightweight allocator for class FaceVector + * + * Notes + * ===== + * + * - This lightweight allocator expects only primitive types. Constructors + * and destructors are not called for type T. + * - The memory is encapsulated in the Face* structures. Handles to these + * structures use the data array. A pointer to the structure is regained + * using the handle and an offset. This is mostly cautionary as the + *offset is normally expected to be zero. + * - No per-object data is stored as per normal requirements for allocators. + * Critical OpenMP sections are defined since multiple threads can access + * the allocator. + * - If set_offsets is to be used, T must have a default constructor. + * + *============================================================================*/ + + template <typename T> class FaceAllocator { + public: + // Memory structures + struct Face2 { + T faces[2]; + void set_pool_prev(void *const p) + { + *reinterpret_cast<void **>(faces) = p; + } + void *get_pool_prev() { return *reinterpret_cast<void **>(faces); } + ptrdiff_t get_offset() const + { + return reinterpret_cast<const char *>(this) - + reinterpret_cast<const char *>(faces); + } + }; + struct Face6 { + T faces[6]; + void set_pool_prev(void *const p) + { + *reinterpret_cast<void **>(faces) = p; + } + void *get_pool_prev() { return *reinterpret_cast<void **>(faces); } + ptrdiff_t get_offset() const + { + return reinterpret_cast<const char *>(this) - + reinterpret_cast<const char *>(faces); + } + }; + struct Face8 { + T faces[8]; + void set_pool_prev(void *const p) + { + *reinterpret_cast<void **>(faces) = p; + } + void *get_pool_prev() { return *reinterpret_cast<void **>(faces); } + ptrdiff_t get_offset() const + { + return reinterpret_cast<const char *>(this) - + reinterpret_cast<const char *>(faces); + } + }; + struct Face16 { + T faces[16]; + void set_pool_prev(void *const p) + { + *reinterpret_cast<void **>(faces) = p; + } + void *get_pool_prev() { return *reinterpret_cast<void **>(faces); } + ptrdiff_t get_offset() const + { + return reinterpret_cast<const char *>(this) - + reinterpret_cast<const char *>(faces); + } + }; + + // Set offsets + static void set_offsets() { - return *reinterpret_cast<void**>(faces); + Face2 f2; + offset2 = f2.get_offset(); + Face6 f6; + offset6 = f6.get_offset(); + Face8 f8; + offset8 = f8.get_offset(); + Face16 f16; + offset16 = f16.get_offset(); } - ptrdiff_t get_offset() const + + // Release memory used by the pools + static void free_pool_memory() { - return reinterpret_cast<const char*>(this) - - reinterpret_cast<const char*>(faces); + face2Pool.free_memory(); + face6Pool.free_memory(); + face8Pool.free_memory(); + face16Pool.free_memory(); } - }; - // Set offsets - static void set_offsets() - { - Face2 f2; - offset2 = f2.get_offset(); - Face6 f6; - offset6 = f6.get_offset(); - Face8 f8; - offset8 = f8.get_offset(); - Face16 f16; - offset16 = f16.get_offset(); - } - - // Release memory used by the pools - static void free_pool_memory() - { - face2Pool.free_memory(); - face6Pool.free_memory(); - face8Pool.free_memory(); - face16Pool.free_memory(); - } - - // Allocate the array - void allocate(const unsigned short nCapacity, T *&faces) - { -#if defined (_OPENMP) -#pragma omp critical (FaceAllocator_allocate) -#endif + // Allocate the array + void allocate(const unsigned short nCapacity, T *&faces) { - switch(nCapacity) { - case 0: - faces = 0; - break; - case 2: - { - Face2 *f2 = static_cast<Face2*>(face2Pool.get()); +#if defined(_OPENMP) +#pragma omp critical(FaceAllocator_allocate) +#endif + { + switch(nCapacity) { + case 0: faces = 0; break; + case 2: { + Face2 *f2 = static_cast<Face2 *>(face2Pool.get()); faces = f2->faces; - } - break; - case 6: - { - Face6 *f6 = static_cast<Face6*>(face6Pool.get()); + } break; + case 6: { + Face6 *f6 = static_cast<Face6 *>(face6Pool.get()); faces = f6->faces; - } - break; - case 8: - { - Face8 *f8 = static_cast<Face8*>(face8Pool.get()); + } break; + case 8: { + Face8 *f8 = static_cast<Face8 *>(face8Pool.get()); faces = f8->faces; - } - break; - case 16: - { - Face16 *f16 = static_cast<Face16*>(face16Pool.get()); + } break; + case 16: { + Face16 *f16 = static_cast<Face16 *>(face16Pool.get()); faces = f16->faces; + } break; + default: { + faces = static_cast<T *>( + std::malloc(sizeof(T) * nCapacity + sizeof(void *))); + } break; } - break; - default: - { - faces = static_cast<T*>(std::malloc(sizeof(T)*nCapacity + - sizeof(void*))); - } - break; } + // omp: end critical } -//omp: end critical - } - - // Grow the array of faces by 2, 6, 8, and then 2*nUsed. Pools are used for - // arrays with size 2, 6, and 8. - void grow(unsigned short &nCapacity, T *&faces) - { -#if defined (_OPENMP) -#pragma omp critical (FaceAllocator_grow) -#endif + + // Grow the array of faces by 2, 6, 8, and then 2*nUsed. Pools are used for + // arrays with size 2, 6, and 8. + void grow(unsigned short &nCapacity, T *&faces) { - switch(nCapacity) { - case 0: - { - Face2 *f2 = static_cast<Face2*>(face2Pool.get()); +#if defined(_OPENMP) +#pragma omp critical(FaceAllocator_grow) +#endif + { + switch(nCapacity) { + case 0: { + Face2 *f2 = static_cast<Face2 *>(face2Pool.get()); faces = f2->faces; nCapacity = 2; - } - break; - case 2: - { - Face6 *f6 = static_cast<Face6*>(face6Pool.get()); - std::memcpy(f6->faces, faces, 2*sizeof(T)); - Face2 *f2 = reinterpret_cast<Face2*>(faces + offset2); + } break; + case 2: { + Face6 *f6 = static_cast<Face6 *>(face6Pool.get()); + std::memcpy(f6->faces, faces, 2 * sizeof(T)); + Face2 *f2 = reinterpret_cast<Face2 *>(faces + offset2); face2Pool.remit(f2); faces = f6->faces; nCapacity = 6; - } - break; - case 6: - { - Face8 *f8 = static_cast<Face8*>(face8Pool.get()); - std::memcpy(f8->faces, faces, 6*sizeof(T)); - Face6 *f6 = reinterpret_cast<Face6*>(faces + offset6); + } break; + case 6: { + Face8 *f8 = static_cast<Face8 *>(face8Pool.get()); + std::memcpy(f8->faces, faces, 6 * sizeof(T)); + Face6 *f6 = reinterpret_cast<Face6 *>(faces + offset6); face6Pool.remit(f6); faces = f8->faces; nCapacity = 8; - } - break; - case 8: - { - Face16 *f16 = static_cast<Face16*>(face16Pool.get()); - std::memcpy(f16->faces, faces, 8*sizeof(T)); - Face8 *f8 = reinterpret_cast<Face8*>(faces + offset8); + } break; + case 8: { + Face16 *f16 = static_cast<Face16 *>(face16Pool.get()); + std::memcpy(f16->faces, faces, 8 * sizeof(T)); + Face8 *f8 = reinterpret_cast<Face8 *>(faces + offset8); face8Pool.remit(f8); faces = f16->faces; nCapacity = 16; - } - break; - // Allocate outside pool for more than 16 faces - case 16: - { - Face16 *f16 = reinterpret_cast<Face16*>(faces + offset16); - faces = static_cast<T*>(std::malloc(sizeof(T)*32 + sizeof(void*))); - std::memcpy(faces, f16->faces, 16*sizeof(T)); + } break; + // Allocate outside pool for more than 16 faces + case 16: { + Face16 *f16 = reinterpret_cast<Face16 *>(faces + offset16); + faces = + static_cast<T *>(std::malloc(sizeof(T) * 32 + sizeof(void *))); + std::memcpy(faces, f16->faces, 16 * sizeof(T)); face16Pool.remit(f16); nCapacity = 32; - } - break; - default: - { - T *newFace = static_cast<T*>(std::malloc(sizeof(T)*2*nCapacity + - sizeof(void*))); - std::memcpy(newFace, faces, nCapacity*sizeof(T)); + } break; + default: { + T *newFace = static_cast<T *>( + std::malloc(sizeof(T) * 2 * nCapacity + sizeof(void *))); + std::memcpy(newFace, faces, nCapacity * sizeof(T)); std::free(faces); faces = newFace; nCapacity *= 2; + } break; } - break; } + // omp: end critical } -//omp: end critical - } - - // Deallocate an array - void deallocate(unsigned short &nCapacity, T *const faces) - { -#if defined (_OPENMP) -#pragma omp critical (FaceAllocator_deallocate) -#endif + + // Deallocate an array + void deallocate(unsigned short &nCapacity, T *const faces) { - switch(nCapacity) { - case 0: - break; - case 2: - { - Face2 *const f2 = reinterpret_cast<Face2*>(faces + offset2); +#if defined(_OPENMP) +#pragma omp critical(FaceAllocator_deallocate) +#endif + { + switch(nCapacity) { + case 0: break; + case 2: { + Face2 *const f2 = reinterpret_cast<Face2 *>(faces + offset2); face2Pool.remit(f2); - } - break; - case 6: - { - Face6 *const f6 = reinterpret_cast<Face6*>(faces + offset6); + } break; + case 6: { + Face6 *const f6 = reinterpret_cast<Face6 *>(faces + offset6); face6Pool.remit(f6); - } - break; - case 8: - { - Face8 *const f8 = reinterpret_cast<Face8*>(faces + offset8); + } break; + case 8: { + Face8 *const f8 = reinterpret_cast<Face8 *>(faces + offset8); face8Pool.remit(f8); - } - break; - case 16: - { - Face16 *const f16 = reinterpret_cast<Face16*>(faces + offset16); + } break; + case 16: { + Face16 *const f16 = reinterpret_cast<Face16 *>(faces + offset16); face16Pool.remit(f16); - } - break; - default: - { + } break; + default: { std::free(faces); + } break; } - break; } + // omp: end critical + nCapacity = 0; } -//omp: end critical - nCapacity = 0; - } - - private: - - // Data - static Pool<Face2> face2Pool; - static Pool<Face6> face6Pool; - static Pool<Face8> face8Pool; - static Pool<Face16> face16Pool; - static ptrdiff_t offset2; - static ptrdiff_t offset6; - static ptrdiff_t offset8; - static ptrdiff_t offset16; -}; + private: + // Data + static Pool<Face2> face2Pool; + static Pool<Face6> face6Pool; + static Pool<Face8> face8Pool; + static Pool<Face16> face16Pool; + static ptrdiff_t offset2; + static ptrdiff_t offset6; + static ptrdiff_t offset8; + static ptrdiff_t offset16; + }; -// Definitions for static data members of class FaceAllocator -template <typename T> -Pool<typename FaceAllocator<T>::Face2> FaceAllocator<T>::face2Pool; -template <typename T> -Pool<typename FaceAllocator<T>::Face6> FaceAllocator<T>::face6Pool; -template <typename T> -Pool<typename FaceAllocator<T>::Face8> FaceAllocator<T>::face8Pool; -template <typename T> -Pool<typename FaceAllocator<T>::Face16> FaceAllocator<T>::face16Pool; -template <typename T> -ptrdiff_t FaceAllocator<T>::offset2 = 0; -template <typename T> -ptrdiff_t FaceAllocator<T>::offset6 = 0; -template <typename T> -ptrdiff_t FaceAllocator<T>::offset8 = 0; -template <typename T> -ptrdiff_t FaceAllocator<T>::offset16 = 0; + // Definitions for static data members of class FaceAllocator + template <typename T> + Pool<typename FaceAllocator<T>::Face2> FaceAllocator<T>::face2Pool; + template <typename T> + Pool<typename FaceAllocator<T>::Face6> FaceAllocator<T>::face6Pool; + template <typename T> + Pool<typename FaceAllocator<T>::Face8> FaceAllocator<T>::face8Pool; + template <typename T> + Pool<typename FaceAllocator<T>::Face16> FaceAllocator<T>::face16Pool; + template <typename T> ptrdiff_t FaceAllocator<T>::offset2 = 0; + template <typename T> ptrdiff_t FaceAllocator<T>::offset6 = 0; + template <typename T> ptrdiff_t FaceAllocator<T>::offset8 = 0; + template <typename T> ptrdiff_t FaceAllocator<T>::offset16 = 0; + + /******************************************************************************* + * + * This class is like a std::vector but optimized for small vectors containing + * elements with only primitive data. + * + ******************************************************************************/ + + /*============================================================================== + * + * Class FaceVector + * + * Purpose + * ======= + * + * Lightweight small vectors + * + * Notes + * ===== + * + * - The only way to add elements is by 'push_back' + * - Erasing may reorder the elements. + * - T must only contain primitive types + * - init_memory() should be called before constructing any class + * FaceVector<T> and release_memory() should be called after all classes + * FaceVector<T> have been destroyed. These routines explictly manage + * memory used by pools in the allocator. + * + *============================================================================*/ + + template <typename T> class FaceVector : public FaceAllocator<T> { + protected: + using FaceAllocator<T>::deallocate; + using FaceAllocator<T>::grow; + + public: + // Constructor + FaceVector() : _size(0), _capacity(0) {} + // Unlike std::vector, the following sets the capacity to 'n'. The size is + // still 0. + FaceVector(const unsigned short n) : _size(0) + { + _capacity = valid_capacity(n); + allocate(_capacity, faces); + } + // Destructor + ~FaceVector() { deallocate(_capacity, faces); } -/******************************************************************************* - * - * This class is like a std::vector but optimized for small vectors containing - * elements with only primitive data. - * - ******************************************************************************/ + // Index the vector + const T &operator[](const int i) const { return faces[i]; } + T &operator[](const int i) { return faces[i]; } -/*============================================================================== - * - * Class FaceVector - * - * Purpose - * ======= - * - * Lightweight small vectors - * - * Notes - * ===== - * - * - The only way to add elements is by 'push_back' - * - Erasing may reorder the elements. - * - T must only contain primitive types - * - init_memory() should be called before constructing any class - * FaceVector<T> and release_memory() should be called after all classes - * FaceVector<T> have been destroyed. These routines explictly manage - * memory used by pools in the allocator. - * - *============================================================================*/ - -template <typename T> -class FaceVector : public FaceAllocator<T> -{ + // Add element to end + T &push_back(const T val) + { + if(_size == _capacity) grow(_capacity, faces); + return faces[_size++] = val; + } - protected: - - using FaceAllocator<T>::deallocate; - using FaceAllocator<T>::grow; - - public: - - // Constructor - FaceVector() : _size(0), _capacity(0) { } - // Unlike std::vector, the following sets the capacity to 'n'. The size is - // still 0. - FaceVector(const unsigned short n) : _size(0) - { - _capacity = valid_capacity(n); - allocate(_capacity, faces); - } - - // Destructor - ~FaceVector() { deallocate(_capacity, faces); } - - // Index the vector - const T &operator[](const int i) const { return faces[i]; } - T &operator[](const int i) { return faces[i]; } - - // Add element to end - T &push_back(const T val) - { - if(_size == _capacity) grow(_capacity, faces); - return faces[_size++] = val; - } - - // Just increment the size (push an empty element) - T &push_empty() - { - if(_size == _capacity) grow(_capacity, faces); - return faces[_size++]; - } - - // Erase an element - void erase(const int i) - { - faces[i] = faces[--_size]; - } - - // Vector size and capacity - unsigned size() const { return _size; } - unsigned capacity() const { return _capacity; } - - // Memory managment - // Init sets offsets to ensure pointers can be recovered. It should be called - // once before using FaceVector<T> - static void init_memory() { FaceAllocator<T>::set_offsets(); } - // This releases memory used by the pools if no pool elements are in use. It - // should be called after use of FaceVector<T> is finished and all - // FaceVector<T> classes have been destroyed. - static void release_memory() { FaceAllocator<T>::free_pool_memory(); } - - private: - - // Data - T *faces; - unsigned short _size; - unsigned short _capacity; - - // Get a valid capacity size (returns n above 16) - unsigned valid_capacity(unsigned n) const - { - if(n == 0) return 0; - if(n <= 2) return 2; - if(n <= 6) return 6; - if(n <= 8) return 8; - if(n <= 16) return 16; - return n; - } + // Just increment the size (push an empty element) + T &push_empty() + { + if(_size == _capacity) grow(_capacity, faces); + return faces[_size++]; + } -}; + // Erase an element + void erase(const int i) { faces[i] = faces[--_size]; } + + // Vector size and capacity + unsigned size() const { return _size; } + unsigned capacity() const { return _capacity; } + + // Memory managment + // Init sets offsets to ensure pointers can be recovered. It should be + // called once before using FaceVector<T> + static void init_memory() { FaceAllocator<T>::set_offsets(); } + // This releases memory used by the pools if no pool elements are in use. It + // should be called after use of FaceVector<T> is finished and all + // FaceVector<T> classes have been destroyed. + static void release_memory() { FaceAllocator<T>::free_pool_memory(); } + + private: + // Data + T *faces; + unsigned short _size; + unsigned short _capacity; + + // Get a valid capacity size (returns n above 16) + unsigned valid_capacity(unsigned n) const + { + if(n == 0) return 0; + if(n <= 2) return 2; + if(n <= 6) return 6; + if(n <= 8) return 8; + if(n <= 16) return 16; + return n; + } + }; -} // End of namespace CCon +} // End of namespace CCon #endif diff --git a/Geo/ExtrudeParams.cpp b/Geo/ExtrudeParams.cpp index 9ff043e0fb3ba3c49c4c1ed3f8f9e0c65fc24065..ae762c6c6bcbc645861bfbad2069fc42bdf7265e 100644 --- a/Geo/ExtrudeParams.cpp +++ b/Geo/ExtrudeParams.cpp @@ -7,7 +7,7 @@ #include "Geo.h" #include "ExtrudeParams.h" -smooth_data* ExtrudeParams::normals[2] = {0, 0}; +smooth_data *ExtrudeParams::normals[2] = {0, 0}; std::vector<SPoint3> ExtrudeParams::normalsCoherence; // Scale last layer size locally If one section of the boundary layer index = 0 @@ -41,10 +41,9 @@ ExtrudeParams::ExtrudeParams(int ModeEx) mesh.BoundaryLayerIndex = 0; } -void ExtrudeParams::fill(int type, - double T0, double T1, double T2, - double A0, double A1, double A2, - double X0, double X1, double X2, double angle) +void ExtrudeParams::fill(int type, double T0, double T1, double T2, double A0, + double A1, double A2, double X0, double X1, double X2, + double angle) { geo.trans[0] = T0; geo.trans[1] = T1; @@ -59,26 +58,27 @@ void ExtrudeParams::fill(int type, geo.Type = type; } -void ExtrudeParams::Extrude(int iLayer, int iElemLayer, - double &x, double &y, double &z) +void ExtrudeParams::Extrude(int iLayer, int iElemLayer, double &x, double &y, + double &z) { double t = u(iLayer, iElemLayer); // This definitely relies on fixing lateral boundary extruded surfaces if // mesh.ScaleLast is changed by ReplaceDuplicates. This is done in // BoundaryLayers.cpp right now. - if(geo.Type == BOUNDARY_LAYER && iLayer == mesh.NbLayer-1 && + if(geo.Type == BOUNDARY_LAYER && iLayer == mesh.NbLayer - 1 && mesh.BoundaryLayerIndex >= 0 && mesh.BoundaryLayerIndex <= 1 && calcLayerScaleFactor[mesh.BoundaryLayerIndex] && - normals[mesh.BoundaryLayerIndex]){ + normals[mesh.BoundaryLayerIndex]) { double scale = 1.0; normals[mesh.BoundaryLayerIndex]->get_scale(x, y, z, &scale); - if(fabs(scale-1.0) <= xyzv::eps) + if(fabs(scale - 1.0) <= xyzv::eps) scale = 1.0; - else{ + else { if(mesh.NbLayer <= 1) - t = t * scale; + t = t * scale; else - t = (t-mesh.hLayer[mesh.NbLayer-2])*scale + mesh.hLayer[mesh.NbLayer-2]; + t = (t - mesh.hLayer[mesh.NbLayer - 2]) * scale + + mesh.hLayer[mesh.NbLayer - 2]; } } @@ -98,7 +98,7 @@ void ExtrudeParams::Extrude(double t, double &x, double &y, double &z) double dx, dy, dz, angle; double n[3] = {0., 0., 0.}; - switch (geo.Type) { + switch(geo.Type) { case TRANSLATE: dx = geo.trans[0] * t; dy = geo.trans[1] * t; @@ -133,9 +133,7 @@ void ExtrudeParams::Extrude(double t, double &x, double &y, double &z) y += n[1] * t; z += n[2] * t; break; - default: - Msg::Error("Unknown extrusion type"); - break; + default: Msg::Error("Unknown extrusion type"); break; } } diff --git a/Geo/ExtrudeParams.h b/Geo/ExtrudeParams.h index d81861855c3c2d074d9f3fbd5dc0dfed49beaf7d..c291660d61ef1396e43e19708ad75cba51784205 100644 --- a/Geo/ExtrudeParams.h +++ b/Geo/ExtrudeParams.h @@ -23,19 +23,16 @@ #define TRANSLATE_ROTATE 3 #define BOUNDARY_LAYER 4 -class ExtrudeParams{ -public : +class ExtrudeParams { +public: ExtrudeParams(int Mode = EXTRUDED_ENTITY); - void fill(int type, - double T0, double T1, double T2, - double A0, double A1, double A2, - double X0, double X1, double X2, double angle); + void fill(int type, double T0, double T1, double T2, double A0, double A1, + double A2, double X0, double X1, double X2, double angle); double u(int iLayer, int iElemLayer); - void Extrude(int iLayer, int iElemLayer, - double &dx, double &dy, double &dz); + void Extrude(int iLayer, int iElemLayer, double &dx, double &dy, double &dz); void Extrude(double t, double &x, double &y, double &z); void Rotate(double matr[3][3]); - struct{ + struct { bool ExtrudeMesh; bool Recombine; int QuadToTri; @@ -47,14 +44,14 @@ public : bool ScaleLast; std::map<int, std::pair<double, std::vector<int> > > Holes; int ViewIndex, BoundaryLayerIndex; - }mesh; - struct{ + } mesh; + struct { int Mode; int Type; int Source; double trans[3]; double axe[3], pt[3], angle; - }geo; + } geo; // Added by Trevor Strickler: to scale last layer size locally. If one section // of the boundary layer index = 0 or 1 is not supposed to be scaled...that @@ -62,8 +59,8 @@ public : // ...however, if that non-scaled section borders a scaled section, the // boundary normals will extrude consistently (an average of scaled and // non-scaled heights). - static bool calcLayerScaleFactor[2]; // give a global awareness of whether - // last layer scaling is to be used. + static bool calcLayerScaleFactor[2]; // give a global awareness of whether + // last layer scaling is to be used. static smooth_data *normals[2]; static std::vector<SPoint3> normalsCoherence; }; diff --git a/Geo/GEdgeLoop.cpp b/Geo/GEdgeLoop.cpp index 2833a3a4033ff691ad05da78d001f4c67b4c0160..c8b27338ea7df4cf02de92edf7edfe313546653b 100644 --- a/Geo/GEdgeLoop.cpp +++ b/Geo/GEdgeLoop.cpp @@ -10,8 +10,8 @@ void GEdgeSigned::print() const { - Msg::Info("GEdgeSigned : Edge %d sign %d Ordered Vertices %d,%d", - ge->tag(), _sign, getBeginVertex()->tag(), getEndVertex()->tag()); + Msg::Info("GEdgeSigned : Edge %d sign %d Ordered Vertices %d,%d", ge->tag(), + _sign, getBeginVertex()->tag(), getEndVertex()->tag()); } int countInList(std::list<GEdge *> &wire, GEdge *ge) @@ -19,9 +19,9 @@ int countInList(std::list<GEdge *> &wire, GEdge *ge) return std::count(wire.begin(), wire.end(), ge); } -GEdgeSigned nextOne(GEdgeSigned *thisOne, std::list<GEdge*> &wire) +GEdgeSigned nextOne(GEdgeSigned *thisOne, std::list<GEdge *> &wire) { - if(!thisOne){ + if(!thisOne) { GEdge *ge = *(wire.begin()); wire.erase(wire.begin()); return GEdgeSigned(1, ge); @@ -29,11 +29,11 @@ GEdgeSigned nextOne(GEdgeSigned *thisOne, std::list<GEdge*> &wire) GVertex *gv = thisOne->getEndVertex(); - std::list<GEdge*> possibleChoices; + std::list<GEdge *> possibleChoices; - std::list<GEdge*>::iterator it = wire.begin(); - std::list<GEdge*>::iterator ite = wire.end(); - while(it != ite){ + std::list<GEdge *>::iterator it = wire.begin(); + std::list<GEdge *>::iterator ite = wire.end(); + while(it != ite) { GEdge *ge = *it; GVertex *v1 = ge->getBeginVertex(); GVertex *v2 = ge->getEndVertex(); @@ -42,11 +42,11 @@ GEdgeSigned nextOne(GEdgeSigned *thisOne, std::list<GEdge*> &wire) } it = possibleChoices.begin(); ite = possibleChoices.end(); - while(it != ite){ + while(it != ite) { GEdge *ge = *it; - if(countInList(possibleChoices, ge) == 2){ + if(countInList(possibleChoices, ge) == 2) { wire.erase(std::remove_if(wire.begin(), wire.end(), - std::bind2nd(std::equal_to<GEdge*>(), ge)), + std::bind2nd(std::equal_to<GEdge *>(), ge)), wire.end()); wire.push_back(ge); GVertex *v1 = ge->getBeginVertex(); @@ -60,11 +60,11 @@ GEdgeSigned nextOne(GEdgeSigned *thisOne, std::list<GEdge*> &wire) } it = possibleChoices.begin(); ite = possibleChoices.end(); - while(it != ite){ + while(it != ite) { GEdge *ge = *it; - if(ge != thisOne->ge){ - wire.erase(std::remove_if(wire.begin(),wire.end(), - std::bind2nd(std::equal_to<GEdge*>(), ge)), + if(ge != thisOne->ge) { + wire.erase(std::remove_if(wire.begin(), wire.end(), + std::bind2nd(std::equal_to<GEdge *>(), ge)), wire.end()); GVertex *v1 = ge->getBeginVertex(); GVertex *v2 = ge->getEndVertex(); @@ -80,40 +80,43 @@ GEdgeSigned nextOne(GEdgeSigned *thisOne, std::list<GEdge*> &wire) return GEdgeSigned(0, 0); } -int GEdgeLoop::count(GEdge* ge) const +int GEdgeLoop::count(GEdge *ge) const { GEdgeLoop::citer it = begin(); GEdgeLoop::citer ite = end(); int count = 0; - while(it != ite){ + while(it != ite) { if(it->ge == ge) count++; ++it; } return count; } -static void loopTheLoop(std::list<GEdge*> &wire, - std::list<GEdgeSigned> &loop, - GEdge **degeneratedToInsert) +static void loopTheLoop(std::list<GEdge *> &wire, std::list<GEdgeSigned> &loop, + GEdge **degeneratedToInsert) { GEdgeSigned *prevOne = 0; - GEdgeSigned ges(0,0); + GEdgeSigned ges(0, 0); - while(wire.size()){ - if (prevOne && (*degeneratedToInsert) && - (*degeneratedToInsert)->getBeginVertex () == prevOne->getEndVertex()){ - ges = GEdgeSigned(1,*degeneratedToInsert); + while(wire.size()) { + if(prevOne && (*degeneratedToInsert) && + (*degeneratedToInsert)->getBeginVertex() == prevOne->getEndVertex()) { + ges = GEdgeSigned(1, *degeneratedToInsert); *degeneratedToInsert = 0; // printf("second degenerated edge inserted\n"); } - else ges = nextOne(prevOne, wire); - if(ges.getSign() == 0){ // oops - if (0){ - Msg::Error("Something wrong in edge loop of size=%d, no sign !", wire.size()); - for (std::list<GEdge* >::iterator it = wire.begin(); it != wire.end(); it++){ - Msg::Error("GEdge=%d begin=%d end =%d", (*it)->tag(), - (*it)->getBeginVertex()->tag(), (*it)->getEndVertex()->tag()); - } + else + ges = nextOne(prevOne, wire); + if(ges.getSign() == 0) { // oops + if(0) { + Msg::Error("Something wrong in edge loop of size=%d, no sign !", + wire.size()); + for(std::list<GEdge *>::iterator it = wire.begin(); it != wire.end(); + it++) { + Msg::Error("GEdge=%d begin=%d end =%d", (*it)->tag(), + (*it)->getBeginVertex()->tag(), + (*it)->getEndVertex()->tag()); + } } break; } @@ -123,33 +126,36 @@ static void loopTheLoop(std::list<GEdge*> &wire, } } - -GEdgeLoop::GEdgeLoop(const std::vector<GEdge*> &cwire) +GEdgeLoop::GEdgeLoop(const std::vector<GEdge *> &cwire) { // Sometimes OCC puts a nasty degenerated edge in the middle of the // wire ... pushing it to front fixes the problem as it concerns // gmsh - std::list<GEdge*> wire; - std::vector<GEdge*> degenerated; + std::list<GEdge *> wire; + std::vector<GEdge *> degenerated; GEdge *degeneratedToInsert = 0; - for (std::vector<GEdge*>::const_iterator it = cwire.begin(); it != cwire.end(); ++it){ + for(std::vector<GEdge *>::const_iterator it = cwire.begin(); + it != cwire.end(); ++it) { GEdge *ed = *it; - if (ed->degenerate(0)) degenerated.push_back(ed); - else wire.push_back(ed); + if(ed->degenerate(0)) + degenerated.push_back(ed); + else + wire.push_back(ed); } - if(degenerated.size() == 1){ + if(degenerated.size() == 1) { wire.push_front(degenerated[0]); } - else if(degenerated.size() == 2){ + else if(degenerated.size() == 2) { degeneratedToInsert = degenerated[1]; wire.push_front(degenerated[0]); } - else if (degenerated.size() > 2){ - Msg::Warning("More than two degenerated edges in one model face of an OCC model"); + else if(degenerated.size() > 2) { + Msg::Warning( + "More than two degenerated edges in one model face of an OCC model"); } - while(!wire.empty()){ + while(!wire.empty()) { loopTheLoop(wire, loop, °eneratedToInsert); } } diff --git a/Geo/GEdgeLoop.h b/Geo/GEdgeLoop.h index 39880cb0bd89c258c69b17ae7c635605fc73009b..5ed90f875f0d404abd454a93e410ba1b219491ef 100644 --- a/Geo/GEdgeLoop.h +++ b/Geo/GEdgeLoop.h @@ -8,9 +8,8 @@ #include "GEdge.h" -class GEdgeSigned -{ - public: +class GEdgeSigned { +public: int _sign; GEdge *ge; GEdgeSigned(int i, GEdge *g) : _sign(i), ge(g) {} @@ -26,20 +25,20 @@ class GEdgeSigned int getSign() const { return _sign; } }; -class GEdgeLoop -{ - private: +class GEdgeLoop { +private: std::list<GEdgeSigned> loop; - public: + +public: typedef std::list<GEdgeSigned>::iterator iter; typedef std::list<GEdgeSigned>::const_iterator citer; - GEdgeLoop(const std::vector<GEdge*> &); + GEdgeLoop(const std::vector<GEdge *> &); inline iter begin() { return loop.begin(); } inline iter end() { return loop.end(); } inline citer begin() const { return loop.begin(); } inline citer end() const { return loop.end(); } - inline void erase(iter it){ loop.erase(it); } - int count(GEdge*) const; + inline void erase(iter it) { loop.erase(it); } + int count(GEdge *) const; int count() const { return (int)loop.size(); } }; diff --git a/Geo/GEntity.cpp b/Geo/GEntity.cpp index 5b08778c1ca317d1b911a8e667413f7d893e365e..6e596fdd03de2f61fb8b63e24ab1e3e6ffe2d6a6 100644 --- a/Geo/GEntity.cpp +++ b/Geo/GEntity.cpp @@ -16,8 +16,8 @@ #include "GRegion.h" #include "closestVertex.h" -GEntity::GEntity(GModel *m,int t) - : _model(m), _tag(t),_meshMaster(this),_visible(1), _selection(0), +GEntity::GEntity(GModel *m, int t) + : _model(m), _tag(t), _meshMaster(this), _visible(1), _selection(0), _allElementsVisible(1), _obb(0), va_lines(0), va_triangles(0) { _color = CTX::instance()->packColor(0, 0, 255, 0); @@ -25,8 +25,10 @@ GEntity::GEntity(GModel *m,int t) void GEntity::deleteVertexArrays() { - if(va_lines) delete va_lines; va_lines = 0; - if(va_triangles) delete va_triangles; va_triangles = 0; + if(va_lines) delete va_lines; + va_lines = 0; + if(va_triangles) delete va_triangles; + va_triangles = 0; } char GEntity::getVisibility() @@ -43,8 +45,7 @@ bool GEntity::useColor() int g = CTX::instance()->unpackGreen(_color); int b = CTX::instance()->unpackBlue(_color); int a = CTX::instance()->unpackAlpha(_color); - if(r == 0 && g == 0 && b == 255 && a == 0) - return false; + if(r == 0 && g == 0 && b == 255 && a == 0) return false; return true; } @@ -53,21 +54,25 @@ std::string GEntity::getInfoString(bool additional, bool multiline) std::ostringstream sstream; sstream << getTypeString() << " " << tag(); - if(additional){ + if(additional) { std::string info = getAdditionalInfoString(multiline); - if(info.size()){ - if(multiline) sstream << "\n"; - else sstream << " "; + if(info.size()) { + if(multiline) + sstream << "\n"; + else + sstream << " "; sstream << info; } } - if(physicals.size()){ - if(multiline) sstream << "\n"; - else sstream << " "; - for(unsigned int i = 0; i < physicals.size(); i++){ + if(physicals.size()) { + if(multiline) + sstream << "\n"; + else + sstream << " "; + for(unsigned int i = 0; i < physicals.size(); i++) { sstream << "Physical "; - switch(dim()){ + switch(dim()) { case 0: sstream << "Point"; break; case 1: sstream << "Curve"; break; case 2: sstream << "Surface"; break; @@ -75,9 +80,11 @@ std::string GEntity::getInfoString(bool additional, bool multiline) } sstream << " " << physicals[i]; std::string name = model()->getPhysicalName(dim(), physicals[i]); - if(name.size()){ - if(multiline) sstream << "\n"; - else sstream << ", "; + if(name.size()) { + if(multiline) + sstream << "\n"; + else + sstream << ", "; sstream << name; } } @@ -89,41 +96,42 @@ std::string GEntity::getInfoString(bool additional, bool multiline) // removes a MeshVertex void GEntity::removeMeshVertex(MVertex *v) { - std::vector<MVertex*>::iterator it = std::find - (mesh_vertices.begin(), mesh_vertices.end(), v); + std::vector<MVertex *>::iterator it = + std::find(mesh_vertices.begin(), mesh_vertices.end(), v); if(it != mesh_vertices.end()) mesh_vertices.erase(it); } -GVertex *GEntity::cast2Vertex() { return dynamic_cast<GVertex*>(this); } -GEdge *GEntity::cast2Edge() { return dynamic_cast<GEdge*>(this); } -GFace *GEntity::cast2Face() { return dynamic_cast<GFace*>(this); } -GRegion *GEntity::cast2Region() { return dynamic_cast<GRegion*>(this); } +GVertex *GEntity::cast2Vertex() { return dynamic_cast<GVertex *>(this); } +GEdge *GEntity::cast2Edge() { return dynamic_cast<GEdge *>(this); } +GFace *GEntity::cast2Face() { return dynamic_cast<GFace *>(this); } +GRegion *GEntity::cast2Region() { return dynamic_cast<GRegion *>(this); } // sets the entity m from which the mesh will be copied -void GEntity::setMeshMaster(GEntity* gMaster) +void GEntity::setMeshMaster(GEntity *gMaster) { - if (gMaster->dim() != dim()){ + if(gMaster->dim() != dim()) { Msg::Error("Model entity %d of dimension %d cannot" "be the mesh master of entity %d of dimension %d", - gMaster->tag(),gMaster->dim(),tag(),dim()); + gMaster->tag(), gMaster->dim(), tag(), dim()); return; } _meshMaster = gMaster; } -void GEntity::setMeshMaster(GEntity* gMaster,const std::vector<double>& tfo) +void GEntity::setMeshMaster(GEntity *gMaster, const std::vector<double> &tfo) { - if (gMaster->dim() != dim()){ + if(gMaster->dim() != dim()) { Msg::Error("Model entity %d of dimension %d cannot" "be the mesh master of entity %d of dimension %d", - gMaster->tag(),gMaster->dim(),tag(),dim()); + gMaster->tag(), gMaster->dim(), tag(), dim()); return; } - if (tfo.size() != 16) { - Msg::Error("Periodicity transformation from entity %d to %d (dim %d) has %d components" + if(tfo.size() != 16) { + Msg::Error("Periodicity transformation from entity %d to %d (dim %d) has " + "%d components" ", while 16 are required", - gMaster->tag(),tag(),gMaster->dim(),tfo.size()); + gMaster->tag(), tag(), gMaster->dim(), tfo.size()); return; } @@ -133,33 +141,34 @@ void GEntity::setMeshMaster(GEntity* gMaster,const std::vector<double>& tfo) } // gets the entity from which the mesh will be copied -GEntity* GEntity::meshMaster() const { return _meshMaster; } +GEntity *GEntity::meshMaster() const { return _meshMaster; } -void GEntity::updateVertices(const std::map<MVertex*,MVertex*>& old2new) +void GEntity::updateVertices(const std::map<MVertex *, MVertex *> &old2new) { // update the list of the vertices - std::vector<MVertex*> newMeshVertices; - std::vector<MVertex*>::iterator mIter = mesh_vertices.begin(); - for (;mIter != mesh_vertices.end(); ++mIter) { - MVertex* vtx = *mIter; - std::map<MVertex*,MVertex*>::const_iterator cIter = old2new.find(vtx); - if (cIter!=old2new.end()) vtx = cIter->second; + std::vector<MVertex *> newMeshVertices; + std::vector<MVertex *>::iterator mIter = mesh_vertices.begin(); + for(; mIter != mesh_vertices.end(); ++mIter) { + MVertex *vtx = *mIter; + std::map<MVertex *, MVertex *>::const_iterator cIter = old2new.find(vtx); + if(cIter != old2new.end()) vtx = cIter->second; newMeshVertices.push_back(vtx); } mesh_vertices.clear(); mesh_vertices = newMeshVertices; // update the periodic vertex lists - std::map<MVertex*,MVertex*> newCorrespondingVertices; - std::map<MVertex*,MVertex*>::iterator cIter = correspondingVertices.begin(); - for (;cIter!=correspondingVertices.end();++cIter) { - MVertex* tgt = cIter->first; - MVertex* src = cIter->second; - std::map<MVertex*,MVertex*>::const_iterator tIter = old2new.find(tgt); - if (tIter!=old2new.end()) tgt = tIter->second; - std::map<MVertex*,MVertex*>::const_iterator sIter = old2new.find(src); - if (sIter!=old2new.end()) src = sIter->second; - newCorrespondingVertices.insert(std::make_pair(tgt,src)); + std::map<MVertex *, MVertex *> newCorrespondingVertices; + std::map<MVertex *, MVertex *>::iterator cIter = + correspondingVertices.begin(); + for(; cIter != correspondingVertices.end(); ++cIter) { + MVertex *tgt = cIter->first; + MVertex *src = cIter->second; + std::map<MVertex *, MVertex *>::const_iterator tIter = old2new.find(tgt); + if(tIter != old2new.end()) tgt = tIter->second; + std::map<MVertex *, MVertex *>::const_iterator sIter = old2new.find(src); + if(sIter != old2new.end()) src = sIter->second; + newCorrespondingVertices.insert(std::make_pair(tgt, src)); } correspondingVertices.clear(); @@ -167,15 +176,16 @@ void GEntity::updateVertices(const std::map<MVertex*,MVertex*>& old2new) newCorrespondingVertices.clear(); - std::map<MVertex*,MVertex*>::iterator hIter = correspondingHOPoints.begin(); - for (;hIter!=correspondingHOPoints.end();++hIter) { - MVertex* tgt = hIter->first; - MVertex* src = hIter->second; - std::map<MVertex*,MVertex*>::const_iterator tIter = old2new.find(tgt); - if (tIter!=old2new.end()) tgt = tIter->second; - std::map<MVertex*,MVertex*>::const_iterator sIter = old2new.find(src); - if (sIter!=old2new.end()) src = sIter->second; - newCorrespondingVertices.insert(std::make_pair(tgt,src)); + std::map<MVertex *, MVertex *>::iterator hIter = + correspondingHOPoints.begin(); + for(; hIter != correspondingHOPoints.end(); ++hIter) { + MVertex *tgt = hIter->first; + MVertex *src = hIter->second; + std::map<MVertex *, MVertex *>::const_iterator tIter = old2new.find(tgt); + if(tIter != old2new.end()) tgt = tIter->second; + std::map<MVertex *, MVertex *>::const_iterator sIter = old2new.find(src); + if(sIter != old2new.end()) src = sIter->second; + newCorrespondingVertices.insert(std::make_pair(tgt, src)); } correspondingHOPoints.clear(); @@ -184,69 +194,70 @@ void GEntity::updateVertices(const std::map<MVertex*,MVertex*>& old2new) copyMasterCoordinates(); } -void GEntity::addVerticesInSet(std::set<MVertex*>&vtcs,bool closure) const +void GEntity::addVerticesInSet(std::set<MVertex *> &vtcs, bool closure) const { - vtcs.insert(mesh_vertices.begin(),mesh_vertices.end()); - - if (closure) { - switch (dim()) { - case 3: - { - std::vector<GFace*> clos = faces(); - std::vector<GFace*>::iterator cIter = clos.begin(); - for (;cIter!=clos.end();++cIter) (*cIter)->addVerticesInSet(vtcs,true); - break; - } - case 2: - { - std::vector<GEdge*> clos = edges(); - std::vector<GEdge*>::iterator cIter = clos.begin(); - for (;cIter!=clos.end();++cIter) (*cIter)->addVerticesInSet(vtcs,true); - break; - } - case 1: - { - std::vector<GVertex*> clos = vertices(); - std::vector<GVertex*>::iterator cIter = clos.begin(); - for (;cIter!=clos.end();++cIter) (*cIter)->addVerticesInSet(vtcs,true); - break; - } + vtcs.insert(mesh_vertices.begin(), mesh_vertices.end()); + + if(closure) { + switch(dim()) { + case 3: { + std::vector<GFace *> clos = faces(); + std::vector<GFace *>::iterator cIter = clos.begin(); + for(; cIter != clos.end(); ++cIter) + (*cIter)->addVerticesInSet(vtcs, true); + break; + } + case 2: { + std::vector<GEdge *> clos = edges(); + std::vector<GEdge *>::iterator cIter = clos.begin(); + for(; cIter != clos.end(); ++cIter) + (*cIter)->addVerticesInSet(vtcs, true); + break; + } + case 1: { + std::vector<GVertex *> clos = vertices(); + std::vector<GVertex *>::iterator cIter = clos.begin(); + for(; cIter != clos.end(); ++cIter) + (*cIter)->addVerticesInSet(vtcs, true); + break; + } } } } void GEntity::updateCorrespondingVertices() { - if (_meshMaster != this && affineTransform.size() == 16) { + if(_meshMaster != this && affineTransform.size() == 16) { correspondingVertices.clear(); - closestVertexFinder cvf(_meshMaster,true); + closestVertexFinder cvf(_meshMaster, true); - if (cvf.getNbVtcs()) { + if(cvf.getNbVtcs()) { std::vector<double> tfo = affineTransform; std::vector<double> inv; - invertAffineTransformation(tfo,inv); + invertAffineTransformation(tfo, inv); - std::set<MVertex*> vtcs; - this->addVerticesInSet(vtcs,true); + std::set<MVertex *> vtcs; + this->addVerticesInSet(vtcs, true); - std::set<MVertex*>::iterator vIter = vtcs.begin(); - for (;vIter!=vtcs.end();++vIter) { - MVertex* tv = *vIter; + std::set<MVertex *>::iterator vIter = vtcs.begin(); + for(; vIter != vtcs.end(); ++vIter) { + MVertex *tv = *vIter; // double tgt[4] = {tv->x(),tv->y(),tv->z(),1}; // double xyz[4] = {0,0,0,0}; // int idx = 0; - // for (int i=0;i<3;i++) for (int j=0;j<4;j++) tgt[i] += inv[idx++] * ori[j]; - MVertex* sv = cvf(tv->point(),inv); + // for (int i=0;i<3;i++) for (int j=0;j<4;j++) tgt[i] += inv[idx++] * + // ori[j]; + MVertex *sv = cvf(tv->point(), inv); correspondingVertices[tv] = sv; - double src[4] = {sv->x(),sv->y(),sv->z(),1}; - double xyz[4] = {0,0,0,0}; + double src[4] = {sv->x(), sv->y(), sv->z(), 1}; + double xyz[4] = {0, 0, 0, 0}; int idx = 0; - for (int i=0;i<3;i++) { + for(int i = 0; i < 3; i++) { xyz[i] = 0; - for (int j=0;j<4;j++) xyz[i] += tfo[idx++] * src[j]; + for(int j = 0; j < 4; j++) xyz[i] += tfo[idx++] * src[j]; } tv->x() = xyz[0]; @@ -259,16 +270,18 @@ void GEntity::updateCorrespondingVertices() void GEntity::copyMasterCoordinates() { - if (_meshMaster != this && affineTransform.size() == 16) { - std::map<MVertex*,MVertex*>::iterator cvIter = correspondingVertices.begin(); - - for (;cvIter!=correspondingVertices.end();++cvIter) { - MVertex* tv = cvIter->first; - MVertex* sv = cvIter->second; - double src[4] = {sv->x(),sv->y(),sv->z(),1}; - double tgt[3] = {0,0,0}; + if(_meshMaster != this && affineTransform.size() == 16) { + std::map<MVertex *, MVertex *>::iterator cvIter = + correspondingVertices.begin(); + + for(; cvIter != correspondingVertices.end(); ++cvIter) { + MVertex *tv = cvIter->first; + MVertex *sv = cvIter->second; + double src[4] = {sv->x(), sv->y(), sv->z(), 1}; + double tgt[3] = {0, 0, 0}; int idx = 0; - for (int i=0;i<3;i++) for (int j=0;j<4;j++) tgt[i] += affineTransform[idx++] * src[j]; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 4; j++) tgt[i] += affineTransform[idx++] * src[j]; tv->x() = tgt[0]; tv->y() = tgt[1]; tv->z() = tgt[2]; @@ -276,15 +289,16 @@ void GEntity::copyMasterCoordinates() cvIter = correspondingHOPoints.begin(); - for (;cvIter!=correspondingHOPoints.end();++cvIter) { - MVertex* tv = cvIter->first; - MVertex* sv = cvIter->second; + for(; cvIter != correspondingHOPoints.end(); ++cvIter) { + MVertex *tv = cvIter->first; + MVertex *sv = cvIter->second; - double src[4] = {sv->x(),sv->y(),sv->z(),1}; - double tgt[3] = {0,0,0}; + double src[4] = {sv->x(), sv->y(), sv->z(), 1}; + double tgt[3] = {0, 0, 0}; int idx = 0; - for (int i=0;i<3;i++) for (int j=0;j<4;j++) tgt[i] += affineTransform[idx++] * src[j]; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 4; j++) tgt[i] += affineTransform[idx++] * src[j]; tv->x() = tgt[0]; tv->y() = tgt[1]; diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index b9155347acb05b3f86ad3b2f2e4492b8680a0026..7b9d7ff688d56cb9bef4a2054a31180eb4cb72f5 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -63,31 +63,18 @@ static const float EDGE_ANGLE_THRESHOLD = 0.698132; #include "Homology.h" #endif -std::vector<GModel*> GModel::list; +std::vector<GModel *> GModel::list; int GModel::_current = -1; GModel::GModel(const std::string &name) - : _maxVertexNum(0) - , _maxElementNum(0) - , _checkPointedMaxVertexNum(0) - , _checkPointedMaxElementNum(0) - , _destroying(false) - , _name(name) - , _visible(1) - , _elementOctree(0) - , _geo_internals(0) - , _occ_internals(0) - , _acis_internals(0) - , _fm_internals(0) - , _fields(0) - , _currentMeshEntity(0) - , _numPartitions(0) - , normals(0) + : _maxVertexNum(0), _maxElementNum(0), _checkPointedMaxVertexNum(0), + _checkPointedMaxElementNum(0), _destroying(false), _name(name), _visible(1), + _elementOctree(0), _geo_internals(0), _occ_internals(0), _acis_internals(0), + _fm_internals(0), _fields(0), _currentMeshEntity(0), _numPartitions(0), + normals(0) { - // hide all other models - for(unsigned int i = 0; i < list.size(); i++) - list[i]->setVisibility(0); + for(unsigned int i = 0; i < list.size(); i++) list[i]->setVisibility(0); // push new one into the list list.push_back(this); @@ -103,17 +90,17 @@ GModel::GModel(const std::string &name) GModel::~GModel() { - std::vector<GModel*>::iterator it = std::find(list.begin(), list.end(), this); + std::vector<GModel *>::iterator it = + std::find(list.begin(), list.end(), this); if(it != list.end()) list.erase(it); - if(getVisibility()){ + if(getVisibility()) { // if no other model is visible, make the last one visible bool othervisible = false; - for(unsigned int i = 0; i < list.size(); i++){ + for(unsigned int i = 0; i < list.size(); i++) { if(list[i]->getVisibility()) othervisible = true; } - if(!othervisible && list.size()) - list.back()->setVisibility(1); + if(!othervisible && list.size()) list.back()->setVisibility(1); } destroy(); @@ -131,15 +118,15 @@ void GModel::setFileName(const std::string &fileName) Msg::SetOnelabString("Gmsh/Model name", fileName, Msg::GetNumOnelabClients() > 1, false, true, 0, "file"); - Msg::SetOnelabString - ("Gmsh/Model absolute path", SplitFileName(GetAbsolutePath(fileName))[0], - false, false, true, 0); + Msg::SetOnelabString("Gmsh/Model absolute path", + SplitFileName(GetAbsolutePath(fileName))[0], false, + false, true, 0); Msg::SetWindowTitle(fileName); } GModel *GModel::current(int index) { - if(list.empty()){ + if(list.empty()) { Msg::Info("No current model available: creating one"); new GModel(); } @@ -150,8 +137,8 @@ GModel *GModel::current(int index) int GModel::setCurrent(GModel *m) { - for(unsigned int i = 0; i < list.size(); i++){ - if(list[i] == m){ + for(unsigned int i = 0; i < list.size(); i++) { + if(list[i] == m) { _current = i; break; } @@ -164,7 +151,8 @@ GModel *GModel::findByName(const std::string &name, const std::string &fileName) // return last mesh with given name for(int i = list.size() - 1; i >= 0; i--) if(list[i]->getName() == name && - (fileName.empty() || !list[i]->hasFileName(fileName))) return list[i]; + (fileName.empty() || !list[i]->hasFileName(fileName))) + return list[i]; return 0; } @@ -173,7 +161,7 @@ void GModel::destroy(bool keepName) Msg::Debug("Destroying model %s", getName().c_str()); _destroying = true; - if(!keepName){ + if(!keepName) { _name.clear(); _fileNames.clear(); } @@ -184,13 +172,12 @@ void GModel::destroy(bool keepName) _lastMeshEntityError.clear(); _lastMeshVertexError.clear(); - for(riter it = firstRegion(); it != lastRegion(); ++it) - delete *it; + for(riter it = firstRegion(); it != lastRegion(); ++it) delete *it; regions.clear(); - std::set<GRegion*, GEntityLessThan>().swap(regions); + std::set<GRegion *, GEntityLessThan>().swap(regions); - std::vector<GFace*> to_keep; - for(fiter it = firstFace(); it != lastFace(); ++it){ + std::vector<GFace *> to_keep; + for(fiter it = firstFace(); it != lastFace(); ++it) { // projection faces are persistent if((*it)->getNativeType() == GEntity::UnknownModel && (*it)->geomType() == GEntity::ProjectionFace) @@ -199,18 +186,16 @@ void GModel::destroy(bool keepName) delete *it; } faces.clear(); - std::set<GFace*, GEntityLessThan>().swap(faces); + std::set<GFace *, GEntityLessThan>().swap(faces); faces.insert(to_keep.begin(), to_keep.end()); - for(eiter it = firstEdge(); it != lastEdge(); ++it) - delete *it; + for(eiter it = firstEdge(); it != lastEdge(); ++it) delete *it; edges.clear(); - std::set<GEdge*, GEntityLessThan>().swap(edges); + std::set<GEdge *, GEntityLessThan>().swap(edges); - for(viter it = firstVertex(); it != lastVertex(); ++it) - delete *it; + for(viter it = firstVertex(); it != lastVertex(); ++it) delete *it; vertices.clear(); - std::set<GVertex*, GEntityLessThan>().swap(vertices); + std::set<GVertex *, GEntityLessThan>().swap(vertices); destroyMeshCaches(); @@ -230,13 +215,13 @@ void GModel::destroy(bool keepName) void GModel::destroyMeshCaches() { _vertexVectorCache.clear(); - std::vector<MVertex*>().swap(_vertexVectorCache); + std::vector<MVertex *>().swap(_vertexVectorCache); _vertexMapCache.clear(); - std::map<int, MVertex*>().swap(_vertexMapCache); + std::map<int, MVertex *>().swap(_vertexMapCache); _elementVectorCache.clear(); - std::vector<MElement*>().swap(_elementVectorCache); + std::vector<MElement *>().swap(_elementVectorCache); _elementMapCache.clear(); - std::map<int, MElement*>().swap(_elementMapCache); + std::map<int, MElement *>().swap(_elementMapCache); _elementIndexCache.clear(); std::map<int, int>().swap(_elementIndexCache); delete _elementOctree; @@ -245,13 +230,13 @@ void GModel::destroyMeshCaches() void GModel::deleteMesh(bool deleteOnlyElements) { - for(riter it = firstRegion(); it != lastRegion();++it) + for(riter it = firstRegion(); it != lastRegion(); ++it) (*it)->deleteMesh(deleteOnlyElements); - for(fiter it = firstFace(); it != lastFace();++it) + for(fiter it = firstFace(); it != lastFace(); ++it) (*it)->deleteMesh(deleteOnlyElements); - for(eiter it = firstEdge(); it != lastEdge();++it) + for(eiter it = firstEdge(); it != lastEdge(); ++it) (*it)->deleteMesh(deleteOnlyElements); - for(viter it = firstVertex(); it != lastVertex();++it) + for(viter it = firstVertex(); it != lastVertex(); ++it) (*it)->deleteMesh(deleteOnlyElements); destroyMeshCaches(); _currentMeshEntity = 0; @@ -266,8 +251,9 @@ bool GModel::empty() const GRegion *GModel::getRegionByTag(int n) const { - GEntity tmp((GModel*)this, n); - std::set<GRegion*, GEntityLessThan>::const_iterator it = regions.find((GRegion*)&tmp); + GEntity tmp((GModel *)this, n); + std::set<GRegion *, GEntityLessThan>::const_iterator it = + regions.find((GRegion *)&tmp); if(it != regions.end()) return *it; else @@ -276,8 +262,9 @@ GRegion *GModel::getRegionByTag(int n) const GFace *GModel::getFaceByTag(int n) const { - GEntity tmp((GModel*)this, n); - std::set<GFace*, GEntityLessThan>::const_iterator it = faces.find((GFace*)&tmp); + GEntity tmp((GModel *)this, n); + std::set<GFace *, GEntityLessThan>::const_iterator it = + faces.find((GFace *)&tmp); if(it != faces.end()) return *it; else @@ -286,8 +273,9 @@ GFace *GModel::getFaceByTag(int n) const GEdge *GModel::getEdgeByTag(int n) const { - GEntity tmp((GModel*)this, n); - std::set<GEdge*, GEntityLessThan>::const_iterator it = edges.find((GEdge*)&tmp); + GEntity tmp((GModel *)this, n); + std::set<GEdge *, GEntityLessThan>::const_iterator it = + edges.find((GEdge *)&tmp); if(it != edges.end()) return *it; else @@ -296,8 +284,9 @@ GEdge *GModel::getEdgeByTag(int n) const GVertex *GModel::getVertexByTag(int n) const { - GEntity tmp((GModel*)this, n); - std::set<GVertex*, GEntityLessThan>::const_iterator it = vertices.find((GVertex*)&tmp); + GEntity tmp((GModel *)this, n); + std::set<GVertex *, GEntityLessThan>::const_iterator it = + vertices.find((GVertex *)&tmp); if(it != vertices.end()) return *it; else @@ -306,7 +295,7 @@ GVertex *GModel::getVertexByTag(int n) const GEntity *GModel::getEntityByTag(int dim, int n) const { - switch(dim){ + switch(dim) { case 0: return getVertexByTag(n); case 1: return getEdgeByTag(n); case 2: return getFaceByTag(n); @@ -315,13 +304,16 @@ GEntity *GModel::getEntityByTag(int dim, int n) const return 0; } -std::vector<int> GModel::getTagsForPhysicalName(int dim, const std::string &name) +std::vector<int> GModel::getTagsForPhysicalName(int dim, + const std::string &name) { std::vector<int> tags; - std::map<int, std::vector<GEntity*> > physicalGroups; + std::map<int, std::vector<GEntity *> > physicalGroups; getPhysicalGroups(dim, physicalGroups); - std::vector<GEntity*> entities = physicalGroups[getPhysicalNumber(dim, name)]; - for(std::vector<GEntity*>::iterator it = entities.begin(); it != entities.end(); it++){ + std::vector<GEntity *> entities = + physicalGroups[getPhysicalNumber(dim, name)]; + for(std::vector<GEntity *>::iterator it = entities.begin(); + it != entities.end(); it++) { GEntity *ge = *it; tags.push_back(ge->tag()); } @@ -355,77 +347,79 @@ void GModel::remove(GVertex *v) void GModel::remove(int dim, int tag, bool recursive) { // TODO: we should also check dependencies in embedded entities - if(dim == 3){ + if(dim == 3) { GRegion *gr = getRegionByTag(tag); - if(gr){ + if(gr) { remove(gr); - if(recursive){ - std::vector<GFace*> f = gr->faces(); - for(std::vector<GFace*>::iterator it = f.begin(); it != f.end(); it++) + if(recursive) { + std::vector<GFace *> f = gr->faces(); + for(std::vector<GFace *>::iterator it = f.begin(); it != f.end(); it++) remove(2, (*it)->tag(), recursive); } } } - else if(dim == 2){ + else if(dim == 2) { GFace *gf = getFaceByTag(tag); - if(gf){ + if(gf) { bool skip = false; - for(riter it = firstRegion(); it != lastRegion(); it++){ - std::vector<GFace*> f = (*it)->faces(); - if(std::find(f.begin(), f.end(), gf) != f.end()){ + for(riter it = firstRegion(); it != lastRegion(); it++) { + std::vector<GFace *> f = (*it)->faces(); + if(std::find(f.begin(), f.end(), gf) != f.end()) { skip = true; break; } } - if(!skip){ + if(!skip) { remove(gf); - if(recursive){ - std::vector<GEdge*> const& e = gf->edges(); - for(std::vector<GEdge*>::const_iterator it = e.begin(); it != e.end(); it++) + if(recursive) { + std::vector<GEdge *> const &e = gf->edges(); + for(std::vector<GEdge *>::const_iterator it = e.begin(); + it != e.end(); it++) remove(1, (*it)->tag(), recursive); } } } } - else if(dim == 1){ + else if(dim == 1) { GEdge *ge = getEdgeByTag(tag); - if(ge){ + if(ge) { bool skip = false; - for(fiter it = firstFace(); it != lastFace(); it++){ - std::vector<GEdge*> const& e = (*it)->edges(); - if(std::find(e.begin(), e.end(), ge) != e.end()){ + for(fiter it = firstFace(); it != lastFace(); it++) { + std::vector<GEdge *> const &e = (*it)->edges(); + if(std::find(e.begin(), e.end(), ge) != e.end()) { skip = true; break; } } - if(!skip){ + if(!skip) { remove(ge); - if(recursive){ + if(recursive) { if(ge->getBeginVertex()) remove(0, ge->getBeginVertex()->tag()); if(ge->getEndVertex()) remove(0, ge->getEndVertex()->tag()); } } } } - else if(dim == 0){ + else if(dim == 0) { GVertex *gv = getVertexByTag(tag); - if(gv){ + if(gv) { bool skip = false; - for(eiter it = firstEdge(); it != lastEdge(); it++){ + for(eiter it = firstEdge(); it != lastEdge(); it++) { GEdge *ge = *it; - if(ge->getBeginVertex() == gv || ge->getEndVertex() == gv){ + if(ge->getBeginVertex() == gv || ge->getEndVertex() == gv) { skip = true; break; } } - if(!skip){ + if(!skip) { remove(gv); } } } } -void GModel::remove(const std::vector<std::pair<int, int> > &dimTags, bool recursive) +void GModel::remove(const std::vector<std::pair<int, int> > &dimTags, + bool recursive) { for(unsigned int i = 0; i < dimTags.size(); i++) remove(dimTags[i].first, dimTags[i].second, recursive); @@ -445,18 +439,19 @@ void GModel::snapVertices() double tol = CTX::instance()->geom.tolerance; - while(vit != lastVertex()){ - std::vector<GEdge*> const& edges = (*vit)->edges(); - for(std::vector<GEdge*>::const_iterator it = edges.begin(); it != edges.end(); ++it){ + while(vit != lastVertex()) { + std::vector<GEdge *> const &edges = (*vit)->edges(); + for(std::vector<GEdge *>::const_iterator it = edges.begin(); + it != edges.end(); ++it) { Range<double> parb = (*it)->parBounds(0); double t; - if((*it)->getBeginVertex() == *vit){ + if((*it)->getBeginVertex() == *vit) { t = parb.low(); } - else if((*it)->getEndVertex() == *vit){ + else if((*it)->getEndVertex() == *vit) { t = parb.high(); } - else{ + else { Msg::Error("Weird vertex: impossible to snap"); break; } @@ -464,29 +459,26 @@ void GModel::snapVertices() double d = sqrt((gp.x() - (*vit)->x()) * (gp.x() - (*vit)->x()) + (gp.y() - (*vit)->y()) * (gp.y() - (*vit)->y()) + (gp.z() - (*vit)->z()) * (gp.z() - (*vit)->z())); - if(d > tol){ + if(d > tol) { (*vit)->setPosition(gp); - Msg::Info("Snapping geometry vertex %d to curve control point (dist = %g)", - (*vit)->tag(), d); + Msg::Info( + "Snapping geometry vertex %d to curve control point (dist = %g)", + (*vit)->tag(), d); } } vit++; } } -void GModel::getEntities(std::vector<GEntity*> &entities, int dim) const +void GModel::getEntities(std::vector<GEntity *> &entities, int dim) const { entities.clear(); switch(dim) { case 0: entities.insert(entities.end(), vertices.begin(), vertices.end()); break; - case 1: - entities.insert(entities.end(), edges.begin(), edges.end()); - break; - case 2: - entities.insert(entities.end(), faces.begin(), faces.end()); - break; + case 1: entities.insert(entities.end(), edges.begin(), edges.end()); break; + case 2: entities.insert(entities.end(), faces.begin(), faces.end()); break; case 3: entities.insert(entities.end(), regions.begin(), regions.end()); break; @@ -503,10 +495,10 @@ void GModel::getEntitiesInBox(std::vector<GEntity *> &entities, const SBoundingBox3d &box, int dim) const { entities.clear(); - std::vector<GEntity*> all; + std::vector<GEntity *> all; getEntities(all, dim); // if we use this often, create an rtree to avoid the linear search - for(unsigned int i = 0; i < all.size(); i++){ + for(unsigned int i = 0; i < all.size(); i++) { SBoundingBox3d bbox = all[i]->bounds(); if(bbox.min().x() >= box.min().x() && bbox.max().x() <= box.max().x() && bbox.min().y() >= box.min().y() && bbox.max().y() <= box.max().y() && @@ -515,8 +507,8 @@ void GModel::getEntitiesInBox(std::vector<GEntity *> &entities, } } -class AbsIntLessThan{ - public: +class AbsIntLessThan { +public: bool operator()(const int &i1, const int &i2) const { if(std::abs(i1) < std::abs(i2)) return true; @@ -529,25 +521,27 @@ bool GModel::getBoundaryTags(const std::vector<std::pair<int, int> > &inDimTags, bool combined, bool oriented, bool recursive) { bool ret = true; - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { int dim = inDimTags[i].first; int tag = std::abs(inDimTags[i].second); // abs for backward compatibility bool reverse = (inDimTags[i].second < 0); - if(dim == 3){ + if(dim == 3) { GRegion *gr = getRegionByTag(tag); - if(gr){ - if(recursive){ - std::vector<GVertex*> const& vert = gr->vertices(); - for(std::vector<GVertex*>::const_iterator it = vert.begin(); it != vert.end(); it++) + if(gr) { + if(recursive) { + std::vector<GVertex *> const &vert = gr->vertices(); + for(std::vector<GVertex *>::const_iterator it = vert.begin(); + it != vert.end(); it++) outDimTags.push_back(std::pair<int, int>(0, (*it)->tag())); } - else{ - std::vector<GFace*> faces(gr->faces()); - std::vector<int> const& orientations = gr->faceOrientations(); + else { + std::vector<GFace *> faces(gr->faces()); + std::vector<int> const &orientations = gr->faceOrientations(); std::vector<int>::const_iterator ito = orientations.begin(); - for(std::vector<GFace*>::iterator it = faces.begin(); it != faces.end(); it++){ + for(std::vector<GFace *>::iterator it = faces.begin(); + it != faces.end(); it++) { int t = (*it)->tag(); - if(oriented && ito != orientations.end()){ + if(oriented && ito != orientations.end()) { t *= *ito; ito++; } @@ -555,26 +549,28 @@ bool GModel::getBoundaryTags(const std::vector<std::pair<int, int> > &inDimTags, } } } - else{ + else { Msg::Error("Unknown model region with tag %d", tag); ret = false; } } - else if(dim == 2){ + else if(dim == 2) { GFace *gf = getFaceByTag(tag); - if(gf){ - if(recursive){ - std::vector<GVertex*> const& vert = gf->vertices(); - for(std::vector<GVertex*>::const_iterator it = vert.begin(); it != vert.end(); it++) + if(gf) { + if(recursive) { + std::vector<GVertex *> const &vert = gf->vertices(); + for(std::vector<GVertex *>::const_iterator it = vert.begin(); + it != vert.end(); it++) outDimTags.push_back(std::pair<int, int>(0, (*it)->tag())); } - else{ - std::vector<GEdge*> const& edges = gf->edges(); + else { + std::vector<GEdge *> const &edges = gf->edges(); std::vector<int> orientations(gf->edgeOrientations()); std::vector<int>::iterator ito = orientations.begin(); - for(std::vector<GEdge*>::const_iterator it = edges.begin(); it != edges.end(); it++){ + for(std::vector<GEdge *>::const_iterator it = edges.begin(); + it != edges.end(); it++) { int t = (*it)->tag(); - if(oriented && ito != orientations.end()){ + if(oriented && ito != orientations.end()) { t *= *ito; ito++; } @@ -582,57 +578,61 @@ bool GModel::getBoundaryTags(const std::vector<std::pair<int, int> > &inDimTags, } } } - else{ + else { Msg::Error("Unknown model face with tag %d", tag); ret = false; } } - else if(dim == 1){ + else if(dim == 1) { GEdge *ge = getEdgeByTag(tag); - if(ge){ - if(reverse){ // for backward compatibility + if(ge) { + if(reverse) { // for backward compatibility if(ge->getEndVertex()) - outDimTags.push_back(std::pair<int, int>(0, ge->getEndVertex()->tag())); + outDimTags.push_back( + std::pair<int, int>(0, ge->getEndVertex()->tag())); if(ge->getBeginVertex()) - outDimTags.push_back(std::pair<int, int>(0, ge->getBeginVertex()->tag())); + outDimTags.push_back( + std::pair<int, int>(0, ge->getBeginVertex()->tag())); } - else{ + else { if(ge->getBeginVertex()) - outDimTags.push_back(std::pair<int, int>(0, ge->getBeginVertex()->tag())); + outDimTags.push_back( + std::pair<int, int>(0, ge->getBeginVertex()->tag())); if(ge->getEndVertex()) - outDimTags.push_back(std::pair<int, int>(0, ge->getEndVertex()->tag())); + outDimTags.push_back( + std::pair<int, int>(0, ge->getEndVertex()->tag())); } } - else{ + else { Msg::Error("Unknown model edge with tag %d", tag); ret = false; } } - else if(dim == 0){ + else if(dim == 0) { GVertex *gv = getVertexByTag(tag); - if(gv && recursive){ + if(gv && recursive) { outDimTags.push_back(std::pair<int, int>(0, gv->tag())); } } } - if(combined){ + if(combined) { // compute boundary of the combined shapes std::set<int, AbsIntLessThan> c[3]; - for(unsigned int i = 0; i < outDimTags.size(); i++){ + for(unsigned int i = 0; i < outDimTags.size(); i++) { int dim = outDimTags[i].first; int tag = outDimTags[i].second; - if(dim >= 0 && dim < 3){ + if(dim >= 0 && dim < 3) { std::set<int>::iterator it = c[dim].find(tag); if(it == c[dim].end()) c[dim].insert(tag); - else{ + else { c[dim].erase(it); } } } outDimTags.clear(); - for(int dim = 0; dim < 3; dim++){ + for(int dim = 0; dim < 3; dim++) { for(std::set<int>::iterator it = c[dim].begin(); it != c[dim].end(); it++) outDimTags.push_back(std::pair<int, int>(dim, *it)); } @@ -642,7 +642,7 @@ bool GModel::getBoundaryTags(const std::vector<std::pair<int, int> > &inDimTags, int GModel::getMaxElementaryNumber(int dim) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); int num = 0; for(unsigned int i = 0; i < entities.size(); i++) @@ -653,52 +653,54 @@ int GModel::getMaxElementaryNumber(int dim) bool GModel::noPhysicalGroups() { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) if(entities[i]->physicals.size()) return false; return true; } -void GModel::getPhysicalGroups(std::map<int, std::vector<GEntity*> > groups[4]) const +void GModel::getPhysicalGroups( + std::map<int, std::vector<GEntity *> > groups[4]) const { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ - std::map<int, std::vector<GEntity*> > &group(groups[entities[i]->dim()]); - for(unsigned int j = 0; j < entities[i]->physicals.size(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + std::map<int, std::vector<GEntity *> > &group(groups[entities[i]->dim()]); + for(unsigned int j = 0; j < entities[i]->physicals.size(); j++) { // physicals can be stored with negative signs when the entity should be // "reversed" int p = std::abs(entities[i]->physicals[j]); group[p].push_back(entities[i]); } } - for(int dim = 0; dim < 4; ++dim){ - std::map<int, std::vector<GEntity*> > &group(groups[dim]); - for(std::map<int, std::vector<GEntity*> >::iterator it = group.begin(); - it != group.end(); ++it){ - std::vector<GEntity*> &v = it->second; + for(int dim = 0; dim < 4; ++dim) { + std::map<int, std::vector<GEntity *> > &group(groups[dim]); + for(std::map<int, std::vector<GEntity *> >::iterator it = group.begin(); + it != group.end(); ++it) { + std::vector<GEntity *> &v = it->second; std::sort(v.begin(), v.end()); std::unique(v.begin(), v.end()); } } } -void GModel::getPhysicalGroups(int dim, std::map<int, std::vector<GEntity*> > &groups) const +void GModel::getPhysicalGroups( + int dim, std::map<int, std::vector<GEntity *> > &groups) const { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities, dim); - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->physicals.size(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->physicals.size(); j++) { // physicals can be stored with negative signs when the entity should be // "reversed" int p = std::abs(entities[i]->physicals[j]); groups[p].push_back(entities[i]); } } - for(std::map<int, std::vector<GEntity*> >::iterator it = groups.begin(); - it != groups.end(); ++it){ - std::vector<GEntity*> &v = it->second; + for(std::map<int, std::vector<GEntity *> >::iterator it = groups.begin(); + it != groups.end(); ++it) { + std::vector<GEntity *> &v = it->second; std::sort(v.begin(), v.end()); std::unique(v.begin(), v.end()); } @@ -706,7 +708,7 @@ void GModel::getPhysicalGroups(int dim, std::map<int, std::vector<GEntity*> > &g void GModel::removePhysicalGroups() { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) entities[i]->physicals.clear(); @@ -714,21 +716,21 @@ void GModel::removePhysicalGroups() void GModel::removePhysicalGroup(int dim, int num) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities, dim); - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { std::vector<int> p; for(unsigned int j = 0; j < entities[i]->physicals.size(); j++) if(entities[i]->physicals[j] != num) p.push_back(entities[i]->physicals[j]); entities[i]->physicals = p; } - physicalNames.erase(std::pair<int,int>(dim, num)); + physicalNames.erase(std::pair<int, int>(dim, num)); } int GModel::getMaxPhysicalNumber(int dim) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); int num = 0; for(unsigned int i = 0; i < entities.size(); i++) @@ -742,7 +744,8 @@ void GModel::getInnerPhysicalNamesIterators(std::vector<piter> &iterators) { iterators.resize(4, firstPhysicalName()); - for(piter physIt = firstPhysicalName(); physIt != lastPhysicalName(); ++physIt) + for(piter physIt = firstPhysicalName(); physIt != lastPhysicalName(); + ++physIt) iterators[physIt->first.first] = physIt; } @@ -754,8 +757,8 @@ int GModel::setPhysicalName(const std::string &name, int dim, int number) // if no number is given, find the next available one if(!number) number = getMaxPhysicalNumber(dim) + 1; - physicalNames.insert(std::pair<std::pair<int, int>, std::string> - (std::pair<int, int>(dim, number), name)); + physicalNames.insert(std::pair<std::pair<int, int>, std::string>( + std::pair<int, int>(dim, number), name)); return number; } @@ -768,13 +771,13 @@ GModel::piter GModel::setPhysicalName(piter pos, const std::string &name, // Insertion complexity in O(1) if position points to // the element that will FOLLOW the inserted element. if(pos != lastPhysicalName()) ++pos; - return physicalNames.insert(pos, std::pair<std::pair<int, int>, std::string> - (std::pair<int, int>(dim, number), name)); + return physicalNames.insert(pos, std::pair<std::pair<int, int>, std::string>( + std::pair<int, int>(dim, number), name)); #else // Insertion complexity in O(1) if position points to // the element that will PRECEDE the inserted element. - return physicalNames.insert(pos, std::pair<std::pair<int, int>, std::string> - (std::pair<int, int>(dim, number), name)); + return physicalNames.insert(pos, std::pair<std::pair<int, int>, std::string>( + std::pair<int, int>(dim, number), name)); #endif } @@ -788,7 +791,8 @@ std::string GModel::getPhysicalName(int dim, int number) const int GModel::getPhysicalNumber(const int &dim, const std::string &name) { - for(piter physIt = firstPhysicalName(); physIt != lastPhysicalName(); ++physIt) + for(piter physIt = firstPhysicalName(); physIt != lastPhysicalName(); + ++physIt) if(dim == physIt->first.first && name == physIt->second) return physIt->first.second; @@ -814,14 +818,14 @@ std::string GModel::getElementaryName(int dim, int number) void GModel::setSelection(int val) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { entities[i]->setSelection(val); // reset selection in elements (stored in the visibility flag to // save space) - if(val == 0){ + if(val == 0) { for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) if(entities[i]->getMeshElement(j)->getVisibility() == 2) entities[i]->getMeshElement(j)->setVisibility(1); @@ -831,18 +835,18 @@ void GModel::setSelection(int val) SBoundingBox3d GModel::bounds(bool aroundVisible) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); SBoundingBox3d bb; - for(unsigned int i = 0; i < entities.size(); i++){ - if(!aroundVisible || entities[i]->getVisibility()){ - if(entities[i]->getNativeType() == GEntity::OpenCascadeModel){ + for(unsigned int i = 0; i < entities.size(); i++) { + if(!aroundVisible || entities[i]->getVisibility()) { + if(entities[i]->getNativeType() == GEntity::OpenCascadeModel) { bb += entities[i]->bounds(); } - else{ + else { // using the mesh vertices for now if(entities[i]->dim() == 0) - bb += static_cast<GVertex*>(entities[i])->xyz(); + bb += static_cast<GVertex *>(entities[i])->xyz(); else for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) bb += entities[i]->mesh_vertices[j]->point(); @@ -868,39 +872,42 @@ bool GModel::setAllVolumesPositive() bool ok = true; for(riter it = regions.begin(); it != regions.end(); ++it) for(unsigned int i = 0; i < (*it)->getNumMeshElements(); ++i) - if(!(*it)->getMeshElement(i)->setVolumePositive()) - ok = false; + if(!(*it)->getMeshElement(i)->setVolumePositive()) ok = false; return ok; } -static void addToMap - (std::multimap< MFace , MElement *, Less_Face> &faceToElement, - std::map< MElement *, std::vector < std::pair <MElement *, bool> > > &elToNeighbors, - const MFace &face, MElement *el) -{ - std::map< MFace , MElement *, Less_Face>::iterator fit = faceToElement.find(face); - if(fit == faceToElement.end()){ - faceToElement.insert(std::pair< MFace , MElement *>(face, el)); - } - else { //We found the neighbor face outFace - faceToElement.insert(std::pair< MFace , MElement *>(face, el)); - if(faceToElement.count(face) > 2){ - Msg::Error("Topological fault: Face sharing two other faces. Element %i. " - "Number of nodes %i. Count of faces: %i Three first nodes %i %i %i", - el->getNum(),face.getNumVertices(),faceToElement.count(face), - face.getVertex(0)->getNum(),face.getVertex(1)->getNum(), - face.getVertex(2)->getNum()); +static void +addToMap(std::multimap<MFace, MElement *, Less_Face> &faceToElement, + std::map<MElement *, std::vector<std::pair<MElement *, bool> > > + &elToNeighbors, + const MFace &face, MElement *el) +{ + std::map<MFace, MElement *, Less_Face>::iterator fit = + faceToElement.find(face); + if(fit == faceToElement.end()) { + faceToElement.insert(std::pair<MFace, MElement *>(face, el)); + } + else { // We found the neighbor face outFace + faceToElement.insert(std::pair<MFace, MElement *>(face, el)); + if(faceToElement.count(face) > 2) { + Msg::Error( + "Topological fault: Face sharing two other faces. Element %i. " + "Number of nodes %i. Count of faces: %i Three first nodes %i %i %i", + el->getNum(), face.getNumVertices(), faceToElement.count(face), + face.getVertex(0)->getNum(), face.getVertex(1)->getNum(), + face.getVertex(2)->getNum()); return; } MFace outFace = fit->first; std::vector<std::pair<MElement *, bool> > &neigh = elToNeighbors[el]; for(size_t iN = 0; iN < neigh.size(); iN++) - if(neigh[iN].first == fit->second) //Neigbor is already in the map + if(neigh[iN].first == fit->second) // Neigbor is already in the map return; int i0 = -1; - while (face.getVertex(0) != outFace.getVertex(++i0)); + while(face.getVertex(0) != outFace.getVertex(++i0)) + ; bool sameOrientation = - face.getVertex(1) == outFace.getVertex((i0+1)%face.getNumVertices()); + face.getVertex(1) == outFace.getVertex((i0 + 1) % face.getNumVertices()); neigh.push_back(std::make_pair(fit->second, !sameOrientation)); elToNeighbors[fit->second].push_back(std::make_pair(el, !sameOrientation)); } @@ -913,23 +920,25 @@ checkConformity(std::multimap<MFace, MElement *, Less_Face> &faceToElement, const MFace &face, MElement *el) { int connectivity = faceToElement.count(face); - if(ElementType::getParentType(el->getType()) == TYPE_TRIH){ - //Each face of a trihedron should exist twice (no face on the boundary) + if(ElementType::getParentType(el->getType()) == TYPE_TRIH) { + // Each face of a trihedron should exist twice (no face on the boundary) if(connectivity != 2) Msg::Error("Non conforming trihedron %i (nb connections for a face %i)", el->getNum(), faceToElement.count(face)); } - else{ - //A face can exist twice (inside) or once (boundary) - if(connectivity != 2){ + else { + // A face can exist twice (inside) or once (boundary) + if(connectivity != 2) { for(std::size_t iV = 0; iV < face.getNumVertices(); iV++) - if(face.getVertex(iV)->onWhat()->dim() == 3 || connectivity != 1){ + if(face.getVertex(iV)->onWhat()->dim() == 3 || connectivity != 1) { for(std::size_t jV = 0; jV < face.getNumVertices(); jV++) - Msg::Info("Vertex %i dim %i",face.getVertex(jV)->getNum(), + Msg::Info("Vertex %i dim %i", face.getVertex(jV)->getNum(), face.getVertex(iV)->onWhat()->dim()); Msg::Error("Non conforming element %i (%i connection(s) for a face " - "located on dim %i (vertex %i))",el->getNum(), connectivity, - face.getVertex(iV)->onWhat()->dim(), face.getVertex(iV)->getNum()); + "located on dim %i (vertex %i))", + el->getNum(), connectivity, + face.getVertex(iV)->onWhat()->dim(), + face.getVertex(iV)->getNum()); } } } @@ -938,92 +947,101 @@ checkConformity(std::multimap<MFace, MElement *, Less_Face> &faceToElement, void GModel::setAllVolumesPositiveTopology() { Msg::Info("Orienting volumes according to topology"); - std::map< MElement *, std::vector < std::pair < MElement *, bool> > > elToNeighbors; - std::multimap< MFace , MElement *, Less_Face> faceToElement; + std::map<MElement *, std::vector<std::pair<MElement *, bool> > > + elToNeighbors; + std::multimap<MFace, MElement *, Less_Face> faceToElement; MElement *el; - for(riter it = regions.begin(); it != regions.end(); ++it){ + for(riter it = regions.begin(); it != regions.end(); ++it) { for(unsigned int iEl = 0; iEl < (*it)->getNumMeshElements(); ++iEl) { el = (*it)->getMeshElement(iEl); - for(int iFace = 0; iFace < el->getNumFaces(); iFace++){ + for(int iFace = 0; iFace < el->getNumFaces(); iFace++) { addToMap(faceToElement, elToNeighbors, el->getFace(iFace), el); } } } - for(riter it = regions.begin(); it != regions.end(); ++it){ + for(riter it = regions.begin(); it != regions.end(); ++it) { for(unsigned int iEl = 0; iEl < (*it)->getNumMeshElements(); ++iEl) { el = (*it)->getMeshElement(iEl); - for(int iFace = 0; iFace < el->getNumFaces(); iFace++){ + for(int iFace = 0; iFace < el->getNumFaces(); iFace++) { checkConformity(faceToElement, elToNeighbors, el->getFace(iFace), el); } } } - std::vector< std::pair <MElement *, bool > > queue; - std::set<MElement*> queued; - if((*regions.begin())->tetrahedra.size() == 0){ - Msg::Error("setAllVolumePositiveTopology needs at least one tetrahedron to start"); + std::vector<std::pair<MElement *, bool> > queue; + std::set<MElement *> queued; + if((*regions.begin())->tetrahedra.size() == 0) { + Msg::Error( + "setAllVolumePositiveTopology needs at least one tetrahedron to start"); return; } el = (*regions.begin())->tetrahedra[0]; queue.push_back(std::make_pair(el, true)); - for(size_t i = 0; i < queue.size(); i++){ + for(size_t i = 0; i < queue.size(); i++) { el = queue[i].first; - if(!queue[i].second){ + if(!queue[i].second) { el->reverse(); - // Msg::Info("Reverted element %i of type %i", el->getNum(), el->getType()); + // Msg::Info("Reverted element %i of type %i", el->getNum(), + // el->getType()); } - const std::vector < std::pair <MElement *, bool> > &neigh = elToNeighbors[el]; + const std::vector<std::pair<MElement *, bool> > &neigh = elToNeighbors[el]; for(size_t iN = 0; iN < neigh.size(); iN++) - if(queued.count(neigh[iN].first) == 0){ - queue.push_back(std::make_pair(neigh[iN].first, neigh[iN].second == queue[i].second)); + if(queued.count(neigh[iN].first) == 0) { + queue.push_back( + std::make_pair(neigh[iN].first, neigh[iN].second == queue[i].second)); // if(!(neigh[iN].second == queue[i].second)) // Msg::Info("Queuing element %i (%i) from el %i (%i)", - // neigh[iN].first->getNum(), neigh[iN].second, el->getNum(), - // queue[i].second); + // neigh[iN].first->getNum(), neigh[iN].second, + // el->getNum(), queue[i].second); queued.insert(neigh[iN].first); } } } int GModel::adaptMesh(std::vector<int> technique, - std::vector<simpleFunction<double>* > f, - std::vector<std::vector<double> > parameters, - int niter, bool meshAll) -{ - // For all algorithms: - // - // parameters[1] = lcmin (default : in global gmsh options - // CTX::instance()->mesh.lcMin) - // parameters[2] = lcmax (default : in global gmsh options - // CTX::instance()->mesh.lcMax) niter is the maximum number of iterations - - // Available algorithms: - // - // 1) Assume that the function is a levelset -> adapt using Coupez - // technique (technique = 1) - // parameters[0] = thickness of the interface (mandatory) - // 2) Assume that the function is a physical quantity -> adapt using the - // Hessian (technique = 2) - // parameters[0] = N, the final number of elements - // 3) A variant of 1) by P. Frey (= Coupez + takes curvature function into account) - // parameters[0] = thickness of the interface (mandatory) - // parameters[3] = the required minimum number of elements to - // represent a circle - used for curvature-based metric (default: = - // 15) - // 4) A variant (3), direct implementation in the metric eigendirections, - // assuming a level set (ls): - // - hmin is imposed in the ls gradient, - // - hmax is imposed in the two eigendirections of the ls hessian that are - // (almost ?) tangent to the iso-zero plane - // + the latter eigenvalues (1/hmax^2) are modified if necessary to capture - // the iso-zero curvature - // parameters[0] = thickness of the interface in the positive ls direction (mandatory) - // parameters[4] = thickness of the interface in the negative ls direction - // (=parameters[0] if not specified) - // parameters[3] = the required minimum number of elements to represent a circle - // - used for curvature-based metric (default: = 15) - // 5) Same as 4, except that the transition in band E uses linear interpolation - // of h, instead of linear interpolation of metric + std::vector<simpleFunction<double> *> f, + std::vector<std::vector<double> > parameters, int niter, + bool meshAll) +{ +// For all algorithms: +// +// parameters[1] = lcmin (default : in global gmsh options +// CTX::instance()->mesh.lcMin) +// parameters[2] = lcmax (default : in global gmsh options +// CTX::instance()->mesh.lcMax) niter is the maximum number of iterations + +// Available algorithms: +// +// 1) Assume that the function is a levelset -> adapt using Coupez +// technique (technique = 1) +// parameters[0] = thickness of the interface (mandatory) +// 2) Assume that the function is a physical quantity -> adapt using the +// Hessian (technique = 2) +// parameters[0] = N, the final number of elements +// 3) A variant of 1) by P. Frey (= Coupez + takes curvature function into +// account) +// parameters[0] = thickness of the interface (mandatory) +// parameters[3] = the required minimum number of elements to +// represent a circle - used for curvature-based metric (default: = +// 15) +// 4) A variant (3), direct implementation in the metric eigendirections, +// assuming a level set (ls): +// - hmin is imposed in the ls gradient, +// - hmax is imposed in the two eigendirections of the ls hessian that +// are +// (almost ?) tangent to the iso-zero plane +// + the latter eigenvalues (1/hmax^2) are modified if necessary to +// capture the iso-zero curvature +// parameters[0] = thickness of the interface in the positive ls direction +// (mandatory) parameters[4] = thickness of the interface in the negative +// ls direction +// (=parameters[0] if not specified) +// parameters[3] = the required minimum number of elements to represent a +// circle +// - used for curvature-based metric (default: = 15) +// 5) Same as 4, except that the transition in band E uses linear +// interpolation +// of h, instead of linear interpolation of metric #if defined(HAVE_MESH) // copy context (in order to allow multiple calls) @@ -1037,20 +1055,20 @@ int GModel::adaptMesh(std::vector<int> technique, fields->reset(); int ITER = 0; - if(meshAll){ - while(1){ + if(meshAll) { + while(1) { Msg::Info("-- adaptMesh (allDim) ITER =%d ", ITER); fields->reset(); meshMetric *metric = new meshMetric(this); - for(unsigned int imetric = 0; imetric < technique.size(); imetric++){ + for(unsigned int imetric = 0; imetric < technique.size(); imetric++) { metric->addMetric(technique[imetric], f[imetric], parameters[imetric]); } fields->setBackgroundField(metric); opt_mesh_lc_integration_precision(0, GMSH_SET, 1.e-4); - opt_mesh_algo2d(0, GMSH_SET, 7.0); //bamg - opt_mesh_algo3d(0, GMSH_SET, 7.0); //mmg3d - opt_mesh_lc_from_points(0, GMSH_SET, 0.0); //do not mesh lines with lc + opt_mesh_algo2d(0, GMSH_SET, 7.0); // bamg + opt_mesh_algo3d(0, GMSH_SET, 7.0); // mmg3d + opt_mesh_lc_from_points(0, GMSH_SET, 0.0); // do not mesh lines with lc std::for_each(firstRegion(), lastRegion(), deMeshGRegion()); std::for_each(firstFace(), lastFace(), deMeshGFace()); @@ -1062,31 +1080,32 @@ int GModel::adaptMesh(std::vector<int> technique, char name[256]; sprintf(name, "meshAdapt-%d.msh", ITER); writeMSH(name); - //metric->exportInfo(name); + // metric->exportInfo(name); - if(ITER++ >= niter) break; - if(ITER > 3 && fabs((double)(nbElems - nbElemsOld)) < 0.01 * nbElemsOld) break; + if(ITER++ >= niter) break; + if(ITER > 3 && fabs((double)(nbElems - nbElemsOld)) < 0.01 * nbElemsOld) + break; nbElemsOld = nbElems; } } - else{ //adapt only upper most dimension + else { // adapt only upper most dimension while(1) { Msg::Info("-- adaptMesh ITER =%d ", ITER); - std::vector<MElement*> elements; + std::vector<MElement *> elements; - if(getDim() == 2){ - for(fiter fit = firstFace(); fit != lastFace(); ++fit){ - if((*fit)->quadrangles.size())return -1; - for(unsigned i=0;i<(*fit)->triangles.size();i++){ + if(getDim() == 2) { + for(fiter fit = firstFace(); fit != lastFace(); ++fit) { + if((*fit)->quadrangles.size()) return -1; + for(unsigned i = 0; i < (*fit)->triangles.size(); i++) { elements.push_back((*fit)->triangles[i]); } } } - else if(getDim() == 3){ - for(riter rit = firstRegion(); rit != lastRegion(); ++rit){ - if((*rit)->hexahedra.size())return -1; - for(unsigned i=0;i<(*rit)->tetrahedra.size();i++){ + else if(getDim() == 3) { + for(riter rit = firstRegion(); rit != lastRegion(); ++rit) { + if((*rit)->hexahedra.size()) return -1; + for(unsigned i = 0; i < (*rit)->tetrahedra.size(); i++) { elements.push_back((*rit)->tetrahedra[i]); } } @@ -1096,23 +1115,23 @@ int GModel::adaptMesh(std::vector<int> technique, fields->reset(); meshMetric *metric = new meshMetric(this); - for(unsigned int imetric = 0; imetric < technique.size(); imetric++){ + for(unsigned int imetric = 0; imetric < technique.size(); imetric++) { metric->addMetric(technique[imetric], f[imetric], parameters[imetric]); } fields->setBackgroundField(metric); - if(getDim() == 2){ - for(fiter fit = firstFace(); fit != lastFace(); ++fit){ - if((*fit)->geomType() != GEntity::DiscreteSurface){ + if(getDim() == 2) { + for(fiter fit = firstFace(); fit != lastFace(); ++fit) { + if((*fit)->geomType() != GEntity::DiscreteSurface) { meshGFaceBamg(*fit); - laplaceSmoothing(*fit,CTX::instance()->mesh.nbSmoothing); + laplaceSmoothing(*fit, CTX::instance()->mesh.nbSmoothing); } if(_elementOctree) delete _elementOctree; _elementOctree = 0; } } - else if(getDim() == 3){ - for(riter rit = firstRegion(); rit != lastRegion(); ++rit){ + else if(getDim() == 3) { + for(riter rit = firstRegion(); rit != lastRegion(); ++rit) { refineMeshMMG(*rit); if(_elementOctree) delete _elementOctree; _elementOctree = 0; @@ -1125,7 +1144,8 @@ int GModel::adaptMesh(std::vector<int> technique, nbElems = getNumMeshElements(); if(++ITER >= niter) break; - if(ITER > 3 && fabs((double)(nbElems - nbElemsOld)) < 0.01 * nbElemsOld) break; + if(ITER > 3 && fabs((double)(nbElems - nbElemsOld)) < 0.01 * nbElemsOld) + break; nbElemsOld = nbElems; } @@ -1133,7 +1153,7 @@ int GModel::adaptMesh(std::vector<int> technique, fields->reset(); // copy context (in order to allow multiple calls) - *(CTX::instance()) = _backup ; + *(CTX::instance()) = _backup; return 0; #else @@ -1183,18 +1203,21 @@ int GModel::getMeshStatus(bool countDiscrete) for(riter it = firstRegion(); it != lastRegion(); ++it) if((countDiscrete || ((*it)->geomType() != GEntity::DiscreteVolume && (*it)->meshAttributes.method != MESH_NONE)) && - ((*it)->tetrahedra.size() ||(*it)->hexahedra.size() || + ((*it)->tetrahedra.size() || (*it)->hexahedra.size() || (*it)->prisms.size() || (*it)->pyramids.size() || - (*it)->polyhedra.size() || (*it)->trihedra.size())) return 3; + (*it)->polyhedra.size() || (*it)->trihedra.size())) + return 3; for(fiter it = firstFace(); it != lastFace(); ++it) if((countDiscrete || ((*it)->geomType() != GEntity::DiscreteSurface && (*it)->meshAttributes.method != MESH_NONE)) && ((*it)->triangles.size() || (*it)->quadrangles.size() || - (*it)->polygons.size())) return 2; + (*it)->polygons.size())) + return 2; for(eiter it = firstEdge(); it != lastEdge(); ++it) if((countDiscrete || ((*it)->geomType() != GEntity::DiscreteCurve && (*it)->meshAttributes.method != MESH_NONE)) && - (*it)->lines.size()) return 1; + (*it)->lines.size()) + return 1; for(viter it = firstVertex(); it != lastVertex(); ++it) if((*it)->mesh_vertices.size()) return 0; return -1; @@ -1202,7 +1225,7 @@ int GModel::getMeshStatus(bool countDiscrete) int GModel::getNumMeshVertices(int dim) const { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); unsigned int n = 0; for(unsigned int i = 0; i < entities.size(); i++) @@ -1213,7 +1236,7 @@ int GModel::getNumMeshVertices(int dim) const int GModel::getNumMeshElements(int dim) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); unsigned int n = 0; for(unsigned int i = 0; i < entities.size(); i++) @@ -1224,7 +1247,7 @@ int GModel::getNumMeshElements(int dim) int GModel::getNumMeshParentElements() { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); unsigned int n = 0; for(unsigned int i = 0; i < entities.size(); i++) @@ -1236,12 +1259,12 @@ void GModel::renumberMeshVertices() { destroyMeshCaches(); setMaxVertexNumber(0); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); unsigned int n = 0; - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { GEntity *ge = entities[i]; - for(unsigned int j = 0; j < ge->getNumMeshVertices(); j++){ + for(unsigned int j = 0; j < ge->getNumMeshVertices(); j++) { ge->getMeshVertex(j)->forceNum(++n); } } @@ -1251,12 +1274,12 @@ void GModel::renumberMeshElements() { destroyMeshCaches(); setMaxElementNumber(0); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); unsigned int n = 0; - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { GEntity *ge = entities[i]; - for(unsigned int j = 0; j < ge->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < ge->getNumMeshElements(); j++) { ge->getMeshElement(j)->forceNum(++n); } } @@ -1264,7 +1287,12 @@ void GModel::renumberMeshElements() int GModel::getNumMeshElements(unsigned c[6]) { - c[0] = 0; c[1] = 0; c[2] = 0; c[3] = 0; c[4] = 0; c[5] = 0; + c[0] = 0; + c[1] = 0; + c[2] = 0; + c[3] = 0; + c[4] = 0; + c[5] = 0; for(riter it = firstRegion(); it != lastRegion(); ++it) (*it)->getNumMeshElements(c); if(c[0] + c[1] + c[2] + c[3] + c[4] + c[5]) return 3; @@ -1279,16 +1307,17 @@ int GModel::getNumMeshElements(unsigned c[6]) MElement *GModel::getMeshElementByCoord(SPoint3 &p, int dim, bool strict) { - if(!_elementOctree){ + if(!_elementOctree) { Msg::Debug("Rebuilding mesh element octree"); _elementOctree = new MElementOctree(this); } return _elementOctree->find(p.x(), p.y(), p.z(), dim, strict); } -std::vector<MElement*> GModel::getMeshElementsByCoord(SPoint3 &p, int dim, bool strict) +std::vector<MElement *> GModel::getMeshElementsByCoord(SPoint3 &p, int dim, + bool strict) { - if(!_elementOctree){ + if(!_elementOctree) { Msg::Debug("Rebuilding mesh element octree"); _elementOctree = new MElementOctree(this); } @@ -1297,29 +1326,31 @@ std::vector<MElement*> GModel::getMeshElementsByCoord(SPoint3 &p, int dim, bool void GModel::rebuildMeshVertexCache(bool onlyIfNecessary) { - if(!onlyIfNecessary || (_vertexVectorCache.empty() && _vertexMapCache.empty())){ + if(!onlyIfNecessary || + (_vertexVectorCache.empty() && _vertexMapCache.empty())) { _vertexVectorCache.clear(); _vertexMapCache.clear(); bool dense = false; - if(_maxVertexNum == getNumMeshVertices()){ + if(_maxVertexNum == getNumMeshVertices()) { Msg::Debug("We have a dense vertex numbering in the cache"); dense = true; } - else if(_maxVertexNum < 10 * getNumMeshVertices()){ - Msg::Debug("We have a fairly dense vertex numbering - still using cache vector"); + else if(_maxVertexNum < 10 * getNumMeshVertices()) { + Msg::Debug( + "We have a fairly dense vertex numbering - still using cache vector"); dense = true; } - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - if(dense){ + if(dense) { // numbering starts at 1 - _vertexVectorCache.resize(_maxVertexNum + 1, (MVertex*)0); + _vertexVectorCache.resize(_maxVertexNum + 1, (MVertex *)0); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) _vertexVectorCache[entities[i]->mesh_vertices[j]->getNum()] = entities[i]->mesh_vertices[j]; } - else{ + else { for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) _vertexMapCache[entities[i]->mesh_vertices[j]->getNum()] = @@ -1330,7 +1361,7 @@ void GModel::rebuildMeshVertexCache(bool onlyIfNecessary) MVertex *GModel::getMeshVertexByTag(int n) { - if(_vertexVectorCache.empty() && _vertexMapCache.empty()){ + if(_vertexVectorCache.empty() && _vertexMapCache.empty()) { Msg::Debug("Rebuilding mesh vertex cache"); rebuildMeshVertexCache(); } @@ -1341,22 +1372,23 @@ MVertex *GModel::getMeshVertexByTag(int n) return _vertexMapCache[n]; } -void GModel::getMeshVerticesForPhysicalGroup(int dim, int num, std::vector<MVertex*> &v) +void GModel::getMeshVerticesForPhysicalGroup(int dim, int num, + std::vector<MVertex *> &v) { v.clear(); - std::map<int, std::vector<GEntity*> > groups; + std::map<int, std::vector<GEntity *> > groups; getPhysicalGroups(dim, groups); - std::map<int, std::vector<GEntity*> >::const_iterator it = groups.find(num); + std::map<int, std::vector<GEntity *> >::const_iterator it = groups.find(num); if(it == groups.end()) return; const std::vector<GEntity *> &entities = it->second; - std::set<MVertex*> sv; - for(unsigned int i = 0; i < entities.size(); i++){ - if(dim == 0){ - GVertex *g = (GVertex*)entities[i]; + std::set<MVertex *> sv; + for(unsigned int i = 0; i < entities.size(); i++) { + if(dim == 0) { + GVertex *g = (GVertex *)entities[i]; sv.insert(g->mesh_vertices[0]); } - else{ - for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++){ + else { + for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); for(std::size_t k = 0; k < e->getNumVertices(); k++) sv.insert(e->getVertex(k)); @@ -1368,33 +1400,34 @@ void GModel::getMeshVerticesForPhysicalGroup(int dim, int num, std::vector<MVert MElement *GModel::getMeshElementByTag(int n) { - if(_elementVectorCache.empty() && _elementMapCache.empty()){ + if(_elementVectorCache.empty() && _elementMapCache.empty()) { Msg::Debug("Rebuilding mesh element cache"); _elementVectorCache.clear(); _elementMapCache.clear(); bool dense = false; - if(_maxElementNum == getNumMeshElements()){ + if(_maxElementNum == getNumMeshElements()) { Msg::Debug("We have a dense element numbering in the cache"); dense = true; } - else if(_maxElementNum < 10 * getNumMeshElements()){ - Msg::Debug("We have a fairly dense element numbering - still using cache vector"); + else if(_maxElementNum < 10 * getNumMeshElements()) { + Msg::Debug( + "We have a fairly dense element numbering - still using cache vector"); dense = true; } - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - if(dense){ + if(dense) { // numbering starts at 1 - _elementVectorCache.resize(_maxElementNum + 1, (MElement*)0); + _elementVectorCache.resize(_maxElementNum + 1, (MElement *)0); for(unsigned int i = 0; i < entities.size(); i++) - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); _elementVectorCache[e->getNum()] = e; } } - else{ + else { for(unsigned int i = 0; i < entities.size(); i++) - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); _elementMapCache[e->getNum()] = e; } @@ -1422,10 +1455,10 @@ void GModel::setMeshElementIndex(MElement *e, int index) } template <class T> -static void removeInvisible(std::vector<T*> &elements, bool all) +static void removeInvisible(std::vector<T *> &elements, bool all) { - std::vector<T*> tmp; - for(unsigned int i = 0; i < elements.size(); i++){ + std::vector<T *> tmp; + for(unsigned int i = 0; i < elements.size(); i++) { if(all || !elements[i]->getVisibility()) delete elements[i]; else @@ -1437,7 +1470,7 @@ static void removeInvisible(std::vector<T*> &elements, bool all) void GModel::removeInvisibleElements() { - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { bool all = !(*it)->getVisibility(); removeInvisible((*it)->tetrahedra, all); removeInvisible((*it)->hexahedra, all); @@ -1447,14 +1480,14 @@ void GModel::removeInvisibleElements() removeInvisible((*it)->polyhedra, all); (*it)->deleteVertexArrays(); } - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { bool all = !(*it)->getVisibility(); removeInvisible((*it)->triangles, all); removeInvisible((*it)->quadrangles, all); removeInvisible((*it)->polygons, all); (*it)->deleteVertexArrays(); } - for(eiter it = firstEdge(); it != lastEdge(); ++it){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { bool all = !(*it)->getVisibility(); removeInvisible((*it)->lines, all); (*it)->deleteVertexArrays(); @@ -1464,7 +1497,7 @@ void GModel::removeInvisibleElements() int GModel::indexMeshVertices(bool all, int singlePartition, bool renumber) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); // tag all mesh vertices with -1 (negative vertices will not be @@ -1477,12 +1510,13 @@ int GModel::indexMeshVertices(bool all, int singlePartition, bool renumber) // or with -2 if they need to be taken into account in the numbering but need // not to be saved (because we save a single partition and they are not used // in that partition) - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { if(all || entities[i]->physicals.size() || - (entities[i]->getParentEntity() && entities[i]->getParentEntity()->physicals.size())){ - for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++){ + (entities[i]->getParentEntity() && + entities[i]->getParentEntity()->physicals.size())) { + for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); - for(std::size_t k = 0; k < e->getNumVertices(); k++){ + for(std::size_t k = 0; k < e->getNumVertices(); k++) { if(singlePartition <= 0 || e->getPartition() == singlePartition) e->getVertex(k)->setIndex(0); else if(e->getVertex(k)->getIndex() == -1) @@ -1494,10 +1528,10 @@ int GModel::indexMeshVertices(bool all, int singlePartition, bool renumber) // renumber all the mesh vertices tagged with 0 int numVertices = 0, index = 0; - for(std::size_t i = 0; i < entities.size(); i++){ - for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++){ + for(std::size_t i = 0; i < entities.size(); i++) { + for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++) { MVertex *v = entities[i]->mesh_vertices[j]; - if(!v->getIndex()){ + if(!v->getIndex()) { index++; numVertices++; if(renumber) @@ -1505,7 +1539,7 @@ int GModel::indexMeshVertices(bool all, int singlePartition, bool renumber) else v->setIndex(v->getNum()); } - else if(v->getIndex() == -2){ + else if(v->getIndex() == -2) { index++; } } @@ -1516,10 +1550,10 @@ int GModel::indexMeshVertices(bool all, int singlePartition, bool renumber) void GModel::scaleMesh(double factor) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(std::size_t i = 0; i < entities.size(); i++) - for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++){ + for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++) { MVertex *v = entities[i]->mesh_vertices[j]; v->x() *= factor; v->y() *= factor; @@ -1541,12 +1575,12 @@ int GModel::partitionMesh(int numPart) { #if defined(HAVE_MESH) && (defined(HAVE_METIS)) opt_mesh_partition_num(0, GMSH_SET, numPart); - if(numPart > 0){ + if(numPart > 0) { if(_numPartitions > 0) UnpartitionMesh(this); int ier = PartitionMesh(this); return ier; } - else{ + else { return 1; } #else @@ -1566,8 +1600,8 @@ int GModel::convertOldPartitioningToNewOne() #endif } -void GModel::store(std::vector<MVertex*> &vertices, int dim, - std::map<int, std::vector<MElement*> > &entityMap, +void GModel::store(std::vector<MVertex *> &vertices, int dim, + std::map<int, std::vector<MElement *> > &entityMap, std::map<int, std::map<int, std::string> > &physicalMap) { _storeVerticesInEntities(vertices); @@ -1577,92 +1611,106 @@ void GModel::store(std::vector<MVertex*> &vertices, int dim, } void GModel::storeChain(int dim, - std::map<int, std::vector<MElement*> > &entityMap, + std::map<int, std::vector<MElement *> > &entityMap, std::map<int, std::map<int, std::string> > &physicalMap) { _storeElementsInEntities(entityMap); _storePhysicalTagsInEntities(dim, physicalMap); - std::map<int, std::vector<MElement*> >::iterator it; + std::map<int, std::vector<MElement *> >::iterator it; for(it = entityMap.begin(); it != entityMap.end(); it++) { - if(dim == 0) _chainVertices.insert(getVertexByTag(it->first)); - else if(dim == 1) _chainEdges.insert(getEdgeByTag(it->first)); - else if(dim == 2) _chainFaces.insert(getFaceByTag(it->first)); - else if(dim == 3) _chainRegions.insert(getRegionByTag(it->first)); + if(dim == 0) + _chainVertices.insert(getVertexByTag(it->first)); + else if(dim == 1) + _chainEdges.insert(getEdgeByTag(it->first)); + else if(dim == 2) + _chainFaces.insert(getFaceByTag(it->first)); + else if(dim == 3) + _chainRegions.insert(getRegionByTag(it->first)); } } -template<class T> -static void _addElements(std::vector<T*> &dst, const std::vector<MElement*> &src) +template <class T> +static void _addElements(std::vector<T *> &dst, + const std::vector<MElement *> &src) { - for(unsigned int i = 0; i < src.size(); i++) dst.push_back((T*)src[i]); + for(unsigned int i = 0; i < src.size(); i++) dst.push_back((T *)src[i]); } -void GModel::_storeElementsInEntities(std::map< int, std::vector<MElement* > >& map) +void GModel::_storeElementsInEntities( + std::map<int, std::vector<MElement *> > &map) { - std::map<int, std::vector<MElement*> >::const_iterator it = map.begin(); - for(; it != map.end(); ++it){ + std::map<int, std::vector<MElement *> >::const_iterator it = map.begin(); + for(; it != map.end(); ++it) { if(!it->second.size()) continue; int type = it->second[0]->getType(); - switch(type){ - case TYPE_PNT: - { - GVertex *v = getVertexByTag(it->first); - if(!v){ - v = new discreteVertex(this, it->first); - add(v); - } - if(!v->points.empty()) { // CAD points already have one by default - v->points.clear(); - v->mesh_vertices.clear(); - } - _addElements(v->points, it->second); - } - break; - case TYPE_LIN: - { - GEdge *e = getEdgeByTag(it->first); - if(!e){ - e = new discreteEdge(this, it->first, 0, 0); - add(e); - } - _addElements(e->lines, it->second); - } - break; - case TYPE_TRI: case TYPE_QUA: case TYPE_POLYG: - { - GFace *f = getFaceByTag(it->first); - if(!f){ - f = new discreteFace(this, it->first); - add(f); - } - if(type == TYPE_TRI) _addElements(f->triangles, it->second); - else if(type == TYPE_QUA) _addElements(f->quadrangles, it->second); - else _addElements(f->polygons, it->second); - } - break; - case TYPE_TET: case TYPE_HEX: case TYPE_PYR: - case TYPE_TRIH: case TYPE_PRI: case TYPE_POLYH: - { - GRegion *r = getRegionByTag(it->first); - if(!r){ - r = new discreteRegion(this, it->first); - add(r); - } - if(type == TYPE_TET) _addElements(r->tetrahedra, it->second); - else if(type == TYPE_HEX) _addElements(r->hexahedra, it->second); - else if(type == TYPE_PRI) _addElements(r->prisms, it->second); - else if(type == TYPE_PYR) _addElements(r->pyramids, it->second); - else if(type == TYPE_TRIH) _addElements(r->trihedra, it->second); - else _addElements(r->polyhedra, it->second); - } - break; + switch(type) { + case TYPE_PNT: { + GVertex *v = getVertexByTag(it->first); + if(!v) { + v = new discreteVertex(this, it->first); + add(v); + } + if(!v->points.empty()) { // CAD points already have one by default + v->points.clear(); + v->mesh_vertices.clear(); + } + _addElements(v->points, it->second); + } break; + case TYPE_LIN: { + GEdge *e = getEdgeByTag(it->first); + if(!e) { + e = new discreteEdge(this, it->first, 0, 0); + add(e); + } + _addElements(e->lines, it->second); + } break; + case TYPE_TRI: + case TYPE_QUA: + case TYPE_POLYG: { + GFace *f = getFaceByTag(it->first); + if(!f) { + f = new discreteFace(this, it->first); + add(f); + } + if(type == TYPE_TRI) + _addElements(f->triangles, it->second); + else if(type == TYPE_QUA) + _addElements(f->quadrangles, it->second); + else + _addElements(f->polygons, it->second); + } break; + case TYPE_TET: + case TYPE_HEX: + case TYPE_PYR: + case TYPE_TRIH: + case TYPE_PRI: + case TYPE_POLYH: { + GRegion *r = getRegionByTag(it->first); + if(!r) { + r = new discreteRegion(this, it->first); + add(r); + } + if(type == TYPE_TET) + _addElements(r->tetrahedra, it->second); + else if(type == TYPE_HEX) + _addElements(r->hexahedra, it->second); + else if(type == TYPE_PRI) + _addElements(r->prisms, it->second); + else if(type == TYPE_PYR) + _addElements(r->pyramids, it->second); + else if(type == TYPE_TRIH) + _addElements(r->trihedra, it->second); + else + _addElements(r->polyhedra, it->second); + } break; } } } -void GModel::_storeParentsInSubElements(std::map<int, std::vector<MElement*> > &map) +void GModel::_storeParentsInSubElements( + std::map<int, std::vector<MElement *> > &map) { - std::map<int, std::vector<MElement*> >::const_iterator it; + std::map<int, std::vector<MElement *> >::const_iterator it; for(it = map.begin(); it != map.end(); ++it) for(unsigned int i = 0; i < it->second.size(); ++i) it->second[i]->updateParent(this); @@ -1684,26 +1732,26 @@ static void _associateEntityWithElementVertices(GEntity *ge, void GModel::_createGeometryOfDiscreteEntities(bool force) { - if(CTX::instance()->meshDiscrete){ + if(CTX::instance()->meshDiscrete) { createTopologyFromMeshNew(); exportDiscreteGEOInternals(); } // return; - if (CTX::instance()->meshDiscrete){ + if(CTX::instance()->meshDiscrete) { Msg::Info("Creating the geometry of discrete surfaces"); - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { if((*it)->geomType() == GEntity::DiscreteSurface) { - discreteFace *df = dynamic_cast<discreteFace*> (*it); - if(df) df->createGeometry(); + discreteFace *df = dynamic_cast<discreteFace *>(*it); + if(df) df->createGeometry(); } } } - if (force || CTX::instance()->meshDiscrete){ + if(force || CTX::instance()->meshDiscrete) { Msg::Info("Creating the geometry of discrete curves"); - for(eiter it = firstEdge(); it != lastEdge(); ++it){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { if((*it)->geomType() == GEntity::DiscreteCurve) { - discreteEdge *de = dynamic_cast<discreteEdge*> (*it); - if(de) de->createGeometry(); + discreteEdge *de = dynamic_cast<discreteEdge *>(*it); + if(de) de->createGeometry(); } } } @@ -1714,7 +1762,7 @@ void GModel::_associateEntityWithMeshVertices() // loop on regions, then on faces, edges and vertices and store the entity // pointer in the the elements' vertices (this way we associate the entity of // lowest geometrical degree with each vertex) - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { _associateEntityWithElementVertices(*it, (*it)->tetrahedra); _associateEntityWithElementVertices(*it, (*it)->hexahedra); _associateEntityWithElementVertices(*it, (*it)->prisms); @@ -1722,41 +1770,43 @@ void GModel::_associateEntityWithMeshVertices() _associateEntityWithElementVertices(*it, (*it)->trihedra); _associateEntityWithElementVertices(*it, (*it)->polyhedra); } - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { _associateEntityWithElementVertices(*it, (*it)->triangles); _associateEntityWithElementVertices(*it, (*it)->quadrangles); _associateEntityWithElementVertices(*it, (*it)->polygons); } - for(eiter it = firstEdge(); it != lastEdge(); ++it){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { _associateEntityWithElementVertices(*it, (*it)->lines); } - for(viter it = firstVertex(); it != lastVertex(); ++it){ + for(viter it = firstVertex(); it != lastVertex(); ++it) { _associateEntityWithElementVertices(*it, (*it)->points); } } -void GModel::_storeVerticesInEntities(std::map<int, MVertex*> &vertices) +void GModel::_storeVerticesInEntities(std::map<int, MVertex *> &vertices) { - std::map<int, MVertex*>::iterator it = vertices.begin(); - for(; it != vertices.end(); ++it){ + std::map<int, MVertex *>::iterator it = vertices.begin(); + for(; it != vertices.end(); ++it) { MVertex *v = it->second; GEntity *ge = v->onWhat(); - if(ge) ge->mesh_vertices.push_back(v); - else{ + if(ge) + ge->mesh_vertices.push_back(v); + else { delete v; // we delete all unused vertices it->second = 0; } } } -void GModel::_storeVerticesInEntities(std::vector<MVertex*> &vertices) +void GModel::_storeVerticesInEntities(std::vector<MVertex *> &vertices) { - for(unsigned int i = 0; i < vertices.size(); i++){ + for(unsigned int i = 0; i < vertices.size(); i++) { MVertex *v = vertices[i]; - if(v){ // the vector is allowed to have null entries + if(v) { // the vector is allowed to have null entries GEntity *ge = v->onWhat(); - if(ge) ge->mesh_vertices.push_back(v); - else{ + if(ge) + ge->mesh_vertices.push_back(v); + else { delete v; // we delete all unused vertices vertices[i] = 0; } @@ -1766,12 +1816,12 @@ void GModel::_storeVerticesInEntities(std::vector<MVertex*> &vertices) void GModel::pruneMeshVertexAssociations() { - std::vector<GEntity*> entities; - std::vector<MVertex*> vertices; + std::vector<GEntity *> entities; + std::vector<MVertex *> vertices; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) { for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) { - MVertex* v = entities[i]->mesh_vertices[j]; + MVertex *v = entities[i]->mesh_vertices[j]; v->setEntity(0); vertices.push_back(v); } @@ -1779,7 +1829,7 @@ void GModel::pruneMeshVertexAssociations() } _associateEntityWithMeshVertices(); // associate mesh vertices primarily with chain entities - for(riter it = _chainRegions.begin(); it != _chainRegions.end(); ++it){ + for(riter it = _chainRegions.begin(); it != _chainRegions.end(); ++it) { _associateEntityWithElementVertices(*it, (*it)->tetrahedra, true); _associateEntityWithElementVertices(*it, (*it)->hexahedra, true); _associateEntityWithElementVertices(*it, (*it)->prisms, true); @@ -1787,38 +1837,38 @@ void GModel::pruneMeshVertexAssociations() _associateEntityWithElementVertices(*it, (*it)->trihedra, true); _associateEntityWithElementVertices(*it, (*it)->polyhedra, true); } - for(fiter it = _chainFaces.begin(); it != _chainFaces.end(); ++it){ + for(fiter it = _chainFaces.begin(); it != _chainFaces.end(); ++it) { _associateEntityWithElementVertices(*it, (*it)->triangles, true); _associateEntityWithElementVertices(*it, (*it)->quadrangles, true); _associateEntityWithElementVertices(*it, (*it)->polygons, true); } - for(eiter it = _chainEdges.begin(); it != _chainEdges.end(); ++it){ + for(eiter it = _chainEdges.begin(); it != _chainEdges.end(); ++it) { _associateEntityWithElementVertices(*it, (*it)->lines, true); } - for(viter it = _chainVertices.begin(); it != _chainVertices.end(); ++it){ + for(viter it = _chainVertices.begin(); it != _chainVertices.end(); ++it) { _associateEntityWithElementVertices(*it, (*it)->points, true); } _storeVerticesInEntities(vertices); } -void GModel::_storePhysicalTagsInEntities(int dim, - std::map<int, std::map<int, std::string> > &map) +void GModel::_storePhysicalTagsInEntities( + int dim, std::map<int, std::map<int, std::string> > &map) { std::map<int, std::map<int, std::string> >::const_iterator it = map.begin(); - for(; it != map.end(); ++it){ + for(; it != map.end(); ++it) { GEntity *ge = 0; - switch(dim){ + switch(dim) { case 0: ge = getVertexByTag(it->first); break; case 1: ge = getEdgeByTag(it->first); break; case 2: ge = getFaceByTag(it->first); break; case 3: ge = getRegionByTag(it->first); break; } - if(ge){ + if(ge) { std::map<int, std::string>::const_iterator it2 = it->second.begin(); - for(; it2 != it->second.end(); ++it2){ + for(; it2 != it->second.end(); ++it2) { if(std::find(ge->physicals.begin(), ge->physicals.end(), it2->first) == - ge->physicals.end()){ + ge->physicals.end()) { ge->physicals.push_back(it2->first); } } @@ -1826,11 +1876,12 @@ void GModel::_storePhysicalTagsInEntities(int dim, } } -static bool getMeshVertices(int num, int *indices, std::map<int, MVertex*> &map, - std::vector<MVertex*> &vertices) +static bool getMeshVertices(int num, int *indices, + std::map<int, MVertex *> &map, + std::vector<MVertex *> &vertices) { - for(int i = 0; i < num; i++){ - if(!map.count(indices[i])){ + for(int i = 0; i < num; i++) { + if(!map.count(indices[i])) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -1840,11 +1891,12 @@ static bool getMeshVertices(int num, int *indices, std::map<int, MVertex*> &map, return true; } -static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, - std::vector<MVertex*> &vertices, int minVertex = 0) +static bool getMeshVertices(int num, int *indices, std::vector<MVertex *> &vec, + std::vector<MVertex *> &vertices, int minVertex = 0) { - for(int i = 0; i < num; i++){ - if(indices[i] < minVertex || indices[i] > (int)(vec.size() - 1 + minVertex)){ + for(int i = 0; i < num; i++) { + if(indices[i] < minVertex || + indices[i] > (int)(vec.size() - 1 + minVertex)) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -1854,7 +1906,7 @@ static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, return true; } -GModel *GModel::createGModel(std::map<int, MVertex*> &vertexMap, +GModel *GModel::createGModel(std::map<int, MVertex *> &vertexMap, std::vector<int> &elementNum, std::vector<std::vector<int> > &vertexIndices, std::vector<int> &elementType, @@ -1865,40 +1917,40 @@ GModel *GModel::createGModel(std::map<int, MVertex*> &vertexMap, int numVertices = (int)vertexMap.size(); int numElement = (int)elementNum.size(); - if(numElement != (int)vertexIndices.size()){ + if(numElement != (int)vertexIndices.size()) { Msg::Error("Dimension in vertices numbers"); return 0; } - if(numElement != (int)elementType.size()){ + if(numElement != (int)elementType.size()) { Msg::Error("Dimension in elementType numbers"); return 0; } - if(numElement != (int)physical.size()){ + if(numElement != (int)physical.size()) { Msg::Error("Dimension in physical numbers"); return 0; } - if(numElement != (int)elementary.size()){ + if(numElement != (int)elementary.size()) { Msg::Error("Dimension in elementary numbers"); return 0; } - if(numElement != (int)partition.size()){ + if(numElement != (int)partition.size()) { Msg::Error("Dimension in partition numbers"); return 0; } GModel *gm = new GModel(); - std::map<int, std::vector<MElement*> > elements[11]; + std::map<int, std::vector<MElement *> > elements[11]; std::map<int, std::map<int, std::string> > physicals[4]; - std::vector<MVertex*> vertexVector; + std::vector<MVertex *> vertexVector; - std::map<int, MVertex*>::const_iterator it = vertexMap.begin(); - std::map<int, MVertex*>::const_iterator end = vertexMap.end(); + std::map<int, MVertex *>::const_iterator it = vertexMap.begin(); + std::map<int, MVertex *>::const_iterator end = vertexMap.end(); int maxVertex = std::numeric_limits<int>::min(); int minVertex = std::numeric_limits<int>::max(); int num; - for(; it != end; ++it){ + for(; it != end; ++it) { num = it->first; minVertex = std::min(minVertex, num); maxVertex = std::max(maxVertex, num); @@ -1909,35 +1961,34 @@ GModel *GModel::createGModel(std::map<int, MVertex*> &vertexMap, // if the vertex numbering is dense, transfer the map into a vector to speed // up element creation if((minVertex == 1 && maxVertex == numVertices) || - (minVertex == 0 && maxVertex == numVertices - 1)){ + (minVertex == 0 && maxVertex == numVertices - 1)) { Msg::Info("Vertex numbering is dense"); vertexVector.resize(vertexMap.size() + 1); if(minVertex == 1) vertexVector[0] = 0; else vertexVector[numVertices] = 0; - std::map<int, MVertex*>::const_iterator it = vertexMap.begin(); - for(; it != vertexMap.end(); ++it) - vertexVector[it->first] = it->second; + std::map<int, MVertex *>::const_iterator it = vertexMap.begin(); + for(; it != vertexMap.end(); ++it) vertexVector[it->first] = it->second; vertexMap.clear(); } int *indices; int nbVertices; - for(int i = 0; i < numElement; ++i){ + for(int i = 0; i < numElement; ++i) { num = elementNum[i]; - std::vector<MVertex*> vertices; + std::vector<MVertex *> vertices; nbVertices = (int)vertexIndices[i].size(); indices = &vertexIndices[i][0]; - if(vertexVector.size()){ - if(!getMeshVertices(nbVertices, indices, vertexVector, vertices)){ + if(vertexVector.size()) { + if(!getMeshVertices(nbVertices, indices, vertexVector, vertices)) { Msg::Error("Vertex not found aborting"); delete gm; return 0; } } - else{ - if(!getMeshVertices(nbVertices, indices, vertexMap, vertices)){ + else { + if(!getMeshVertices(nbVertices, indices, vertexMap, vertices)) { Msg::Error("Vertex not found aborting"); delete gm; return 0; @@ -1946,24 +1997,27 @@ GModel *GModel::createGModel(std::map<int, MVertex*> &vertexMap, MElementFactory f; MElement *e = f.create(elementType[i], vertices, num, partition[i]); - if(!e){ + if(!e) { Msg::Error("Unknown type of element %d", elementType[i]); delete gm; return 0; } - switch(e->getType()){ - case TYPE_PNT : elements[0][elementary[i]].push_back(e); break; - case TYPE_LIN : elements[1][elementary[i]].push_back(e); break; - case TYPE_TRI : elements[2][elementary[i]].push_back(e); break; - case TYPE_QUA : elements[3][elementary[i]].push_back(e); break; - case TYPE_TET : elements[4][elementary[i]].push_back(e); break; - case TYPE_HEX : elements[5][elementary[i]].push_back(e); break; - case TYPE_PRI : elements[6][elementary[i]].push_back(e); break; - case TYPE_PYR : elements[7][elementary[i]].push_back(e); break; - case TYPE_TRIH : elements[8][elementary[i]].push_back(e); break; + switch(e->getType()) { + case TYPE_PNT: elements[0][elementary[i]].push_back(e); break; + case TYPE_LIN: elements[1][elementary[i]].push_back(e); break; + case TYPE_TRI: elements[2][elementary[i]].push_back(e); break; + case TYPE_QUA: elements[3][elementary[i]].push_back(e); break; + case TYPE_TET: elements[4][elementary[i]].push_back(e); break; + case TYPE_HEX: elements[5][elementary[i]].push_back(e); break; + case TYPE_PRI: elements[6][elementary[i]].push_back(e); break; + case TYPE_PYR: elements[7][elementary[i]].push_back(e); break; + case TYPE_TRIH: elements[8][elementary[i]].push_back(e); break; case TYPE_POLYG: elements[9][elementary[i]].push_back(e); break; case TYPE_POLYH: elements[10][elementary[i]].push_back(e); break; - default : Msg::Error("Wrong type of element"); delete gm; return 0; + default: + Msg::Error("Wrong type of element"); + delete gm; + return 0; } int dim = e->getDim(); if(physical[i] && (!physicals[dim].count(elementary[i]) || @@ -1986,26 +2040,25 @@ GModel *GModel::createGModel(std::map<int, MVertex*> &vertexMap, gm->_storeVerticesInEntities(vertexMap); // store the physical tags - for(int i = 0; i < 4; i++) - gm->_storePhysicalTagsInEntities(i, physicals[i]); + for(int i = 0; i < 4; i++) gm->_storePhysicalTagsInEntities(i, physicals[i]); return gm; } -GModel *GModel::createGModel -(std::map<int, std::vector<MElement*> > &entityToElementsMap, - std::map<int, std::vector<int> > &entityToPhysicalsMap) +GModel *GModel::createGModel( + std::map<int, std::vector<MElement *> > &entityToElementsMap, + std::map<int, std::vector<int> > &entityToPhysicalsMap) { - GModel* gm = new GModel(); + GModel *gm = new GModel(); - std::map<int, MVertex*> vertexMap; + std::map<int, MVertex *> vertexMap; std::map<int, std::map<int, std::string> > physicals[4]; - for(std::map<int, std::vector<MElement*> >::iterator it = - entityToElementsMap.begin(); it != entityToElementsMap.end(); - it++) { + for(std::map<int, std::vector<MElement *> >::iterator it = + entityToElementsMap.begin(); + it != entityToElementsMap.end(); it++) { int entity = it->first; for(std::size_t iE = 0; iE < it->second.size(); iE++) { - MElement* me = it->second[iE]; + MElement *me = it->second[iE]; for(std::size_t iV = 0; iV < me->getNumVertices(); iV++) { vertexMap[me->getVertex(iV)->getNum()] = me->getVertex(iV); } @@ -2019,8 +2072,7 @@ GModel *GModel::createGModel gm->_storeElementsInEntities(entityToElementsMap); gm->_associateEntityWithMeshVertices(); gm->_storeVerticesInEntities(vertexMap); - for(int i = 0; i < 4; i++) - gm->_storePhysicalTagsInEntities(i, physicals[i]); + for(int i = 0; i < 4; i++) gm->_storePhysicalTagsInEntities(i, physicals[i]); return gm; } @@ -2036,29 +2088,30 @@ void GModel::checkMeshCoherence(double tolerance) double lc = bbox.empty() ? 1. : norm(SVector3(bbox.max(), bbox.min())); double eps = lc * tolerance; - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); // check for duplicate mesh vertices { Msg::Info("Checking for duplicate vertices..."); - std::vector<MVertex*> vertices; + std::vector<MVertex *> vertices; for(unsigned int i = 0; i < entities.size(); i++) vertices.insert(vertices.end(), entities[i]->mesh_vertices.begin(), entities[i]->mesh_vertices.end()); MVertexRTree pos(eps); - std::set<MVertex*> duplicates; + std::set<MVertex *> duplicates; int num = pos.insert(vertices, true, &duplicates); - if(num){ - Msg::Error("%d duplicate vert%s: see `duplicate_vertices.pos'", - num, num > 1 ? "ices" : "ex"); + if(num) { + Msg::Error("%d duplicate vert%s: see `duplicate_vertices.pos'", num, + num > 1 ? "ices" : "ex"); FILE *fp = Fopen("duplicate_vertices.pos", "w"); - if(fp){ + if(fp) { fprintf(fp, "View \"duplicate vertices\"{\n"); - for(std::set<MVertex*>::iterator it = duplicates.begin(); - it != duplicates.end(); it++){ + for(std::set<MVertex *>::iterator it = duplicates.begin(); + it != duplicates.end(); it++) { MVertex *v = *it; - fprintf(fp, "SP(%.16g,%.16g,%.16g){%d};\n", v->x(), v->y(), v->z(), v->getNum()); + fprintf(fp, "SP(%.16g,%.16g,%.16g){%d};\n", v->x(), v->y(), v->z(), + v->getNum()); } fprintf(fp, "};\n"); fclose(fp); @@ -2069,9 +2122,9 @@ void GModel::checkMeshCoherence(double tolerance) // check for duplicate elements { Msg::Info("Checking for duplicate elements..."); - std::vector<MVertex*> vertices; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + std::vector<MVertex *> vertices; + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); double vol = e->getVolume(); if(vol < 0) @@ -2084,8 +2137,7 @@ void GModel::checkMeshCoherence(double tolerance) } MVertexRTree pos(eps); int num = pos.insert(vertices, true); - for(unsigned int i = 0; i < vertices.size(); i++) - delete vertices[i]; + for(unsigned int i = 0; i < vertices.size(); i++) delete vertices[i]; if(num) Msg::Error("%d duplicate element%s", num, num > 1 ? "s" : ""); } @@ -2100,27 +2152,27 @@ int GModel::removeDuplicateMeshVertices(double tolerance) double lc = bbox.empty() ? 1. : norm(SVector3(bbox.max(), bbox.min())); double eps = lc * tolerance; - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); // re-index all vertices (don't use MVertex::getNum(), as we want to be able // to remove diplicate vertices from "incorrect" meshes, where vertices with // the same number are duplicated) int n = 0; - for(unsigned int i = 0; i < entities.size(); i++){ - GEntity* ge = entities[i]; - for(unsigned int j = 0; j < ge->mesh_vertices.size(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + GEntity *ge = entities[i]; + for(unsigned int j = 0; j < ge->mesh_vertices.size(); j++) { MVertex *v = ge->mesh_vertices[j]; v->setIndex(++n); } } MVertexRTree pos(eps); - std::map<int, MVertex*> vertices; - std::map<MVertex*,MVertex*> duplicates; - for(unsigned int i = 0; i < entities.size(); i++){ - GEntity* ge = entities[i]; - for(unsigned int j = 0; j < ge->mesh_vertices.size(); j++){ + std::map<int, MVertex *> vertices; + std::map<MVertex *, MVertex *> duplicates; + for(unsigned int i = 0; i < entities.size(); i++) { + GEntity *ge = entities[i]; + for(unsigned int j = 0; j < ge->mesh_vertices.size(); j++) { MVertex *v = ge->mesh_vertices[j]; MVertex *v2 = pos.insert(v); if(v2) @@ -2133,44 +2185,45 @@ int GModel::removeDuplicateMeshVertices(double tolerance) int num = (int)duplicates.size(); Msg::Info("Found %d duplicate vertices ", num); - if(!num){ + if(!num) { Msg::Info("No duplicate vertices found"); return 0; } - for(std::size_t i = 0; i < entities.size(); i++){ - GEntity* ge = entities[i]; + for(std::size_t i = 0; i < entities.size(); i++) { + GEntity *ge = entities[i]; // clear list of vertices owned by entity ge->mesh_vertices.clear(); // replace vertices in element - for(std::size_t j = 0; j < ge->getNumMeshElements(); j++){ + for(std::size_t j = 0; j < ge->getNumMeshElements(); j++) { MElement *e = ge->getMeshElement(j); - for(std::size_t k = 0; k < e->getNumVertices(); k++){ - std::map<MVertex*, MVertex*>::iterator it = duplicates.find(e->getVertex(k)); - if(it != duplicates.end()) - e->setVertex(k, it->second); + for(std::size_t k = 0; k < e->getNumVertices(); k++) { + std::map<MVertex *, MVertex *>::iterator it = + duplicates.find(e->getVertex(k)); + if(it != duplicates.end()) e->setVertex(k, it->second); } } // replace vertices in periodic copies - std::map<MVertex*,MVertex*>& corrVtcs = ge->correspondingVertices; - if(corrVtcs.size()){ - std::map<MVertex*,MVertex*>::iterator cIter; + std::map<MVertex *, MVertex *> &corrVtcs = ge->correspondingVertices; + if(corrVtcs.size()) { + std::map<MVertex *, MVertex *>::iterator cIter; for(cIter = duplicates.begin(); cIter != duplicates.end(); ++cIter) { - MVertex* oldTgt = cIter->first; - MVertex* newTgt = cIter->second; - std::map<MVertex*, MVertex*>::iterator cvIter = corrVtcs.find(oldTgt); + MVertex *oldTgt = cIter->first; + MVertex *newTgt = cIter->second; + std::map<MVertex *, MVertex *>::iterator cvIter = corrVtcs.find(oldTgt); if(cvIter != corrVtcs.end()) { - MVertex* src = cvIter->second; + MVertex *src = cvIter->second; corrVtcs.erase(cvIter); corrVtcs[newTgt] = src; } } for(cIter = corrVtcs.begin(); cIter != corrVtcs.end(); ++cIter) { - MVertex* oldSrc = cIter->second; - std::map<MVertex*,MVertex*>::iterator nIter = duplicates.find(oldSrc); + MVertex *oldSrc = cIter->second; + std::map<MVertex *, MVertex *>::iterator nIter = + duplicates.find(oldSrc); if(nIter != duplicates.end()) { - MVertex* tgt = cIter->first; - MVertex* newSrc = nIter->second; + MVertex *tgt = cIter->first; + MVertex *newSrc = nIter->second; corrVtcs[tgt] = newSrc; } } @@ -2182,39 +2235,39 @@ int GModel::removeDuplicateMeshVertices(double tolerance) _storeVerticesInEntities(vertices); // delete duplicates - std::vector<MVertex*> to_delete; - for(std::map<MVertex *, MVertex*>::iterator it = duplicates.begin(); + std::vector<MVertex *> to_delete; + for(std::map<MVertex *, MVertex *>::iterator it = duplicates.begin(); it != duplicates.end(); it++) to_delete.push_back(it->first); - for(unsigned int i = 0; i < to_delete.size(); i++) - delete to_delete[i]; + for(unsigned int i = 0; i < to_delete.size(); i++) delete to_delete[i]; if(num) - Msg::Info("Removed %d duplicate mesh %s", num, num > 1 ? "vertices" : "vertex"); + Msg::Info("Removed %d duplicate mesh %s", num, + num > 1 ? "vertices" : "vertex"); Msg::StatusBar(true, "Done removing duplicate mesh vertices"); return num; } -static void recurConnectMElementsByMFace(const MFace &f, - std::multimap<MFace, MElement*, Less_Face> &e2f, - std::set<MElement*> &group, - std::set<MFace, Less_Face> &touched, - int recur_level) +static void recurConnectMElementsByMFace( + const MFace &f, std::multimap<MFace, MElement *, Less_Face> &e2f, + std::set<MElement *> &group, std::set<MFace, Less_Face> &touched, + int recur_level) { // this is very slow... std::stack<MFace> _stack; _stack.push(f); - while(!_stack.empty()){ + while(!_stack.empty()) { MFace ff = _stack.top(); _stack.pop(); - if(touched.find(ff) == touched.end()){ + if(touched.find(ff) == touched.end()) { touched.insert(ff); - for(std::multimap<MFace, MElement*, Less_Face>::iterator it = e2f.lower_bound(ff); - it != e2f.upper_bound(ff); ++it){ + for(std::multimap<MFace, MElement *, Less_Face>::iterator it = + e2f.lower_bound(ff); + it != e2f.upper_bound(ff); ++it) { group.insert(it->second); - for(int i = 0; i < it->second->getNumFaces(); ++i){ + for(int i = 0; i < it->second->getNumFaces(); ++i) { _stack.push(it->second->getFace(i)); } } @@ -2222,20 +2275,20 @@ static void recurConnectMElementsByMFace(const MFace &f, } } -static int connectedVolumes(std::vector<MElement*> &elements, - std::vector<std::vector<MElement*> > ®s) +static int connectedVolumes(std::vector<MElement *> &elements, + std::vector<std::vector<MElement *> > ®s) { - std::multimap<MFace, MElement*, Less_Face> e2f; - for(unsigned int i = 0; i < elements.size(); ++i){ - for(int j = 0; j < elements[i]->getNumFaces(); j++){ + std::multimap<MFace, MElement *, Less_Face> e2f; + for(unsigned int i = 0; i < elements.size(); ++i) { + for(int j = 0; j < elements[i]->getNumFaces(); j++) { e2f.insert(std::make_pair(elements[i]->getFace(j), elements[i])); } } - while(!e2f.empty()){ - std::set<MElement*> group; + while(!e2f.empty()) { + std::set<MElement *> group; std::set<MFace, Less_Face> touched; recurConnectMElementsByMFace(e2f.begin()->first, e2f, group, touched, 0); - std::vector<MElement*> temp; + std::vector<MElement *> temp; temp.insert(temp.begin(), group.begin(), group.end()); regs.push_back(temp); for(std::set<MFace, Less_Face>::iterator it = touched.begin(); @@ -2245,36 +2298,36 @@ static int connectedVolumes(std::vector<MElement*> &elements, return regs.size(); } -static void recurConnectMElementsByMEdge(const MEdge &e, - std::multimap<MEdge, MElement*, Less_Edge> &e2e, - std::set<MElement*> &group, - std::set<MEdge, Less_Edge> &touched) +static void recurConnectMElementsByMEdge( + const MEdge &e, std::multimap<MEdge, MElement *, Less_Edge> &e2e, + std::set<MElement *> &group, std::set<MEdge, Less_Edge> &touched) { if(touched.find(e) != touched.end()) return; touched.insert(e); - for(std::multimap <MEdge, MElement*, Less_Edge>::iterator it = e2e.lower_bound(e); - it != e2e.upper_bound(e); ++it){ + for(std::multimap<MEdge, MElement *, Less_Edge>::iterator it = + e2e.lower_bound(e); + it != e2e.upper_bound(e); ++it) { group.insert(it->second); - for(int i = 0; i < it->second->getNumEdges(); ++i){ + for(int i = 0; i < it->second->getNumEdges(); ++i) { recurConnectMElementsByMEdge(it->second->getEdge(i), e2e, group, touched); } } } -static int connectedSurfaces(std::vector<MElement*> &elements, - std::vector<std::vector<MElement*> > &faces) +static int connectedSurfaces(std::vector<MElement *> &elements, + std::vector<std::vector<MElement *> > &faces) { - std::multimap<MEdge, MElement*, Less_Edge> e2e; - for(unsigned int i = 0; i < elements.size(); ++i){ - for(int j = 0; j < elements[i]->getNumEdges(); j++){ + std::multimap<MEdge, MElement *, Less_Edge> e2e; + for(unsigned int i = 0; i < elements.size(); ++i) { + for(int j = 0; j < elements[i]->getNumEdges(); j++) { e2e.insert(std::make_pair(elements[i]->getEdge(j), elements[i])); } } - while(!e2e.empty()){ - std::set<MElement*> group; + while(!e2e.empty()) { + std::set<MElement *> group; std::set<MEdge, Less_Edge> touched; recurConnectMElementsByMEdge(e2e.begin()->first, e2e, group, touched); - std::vector<MElement*> temp; + std::vector<MElement *> temp; temp.insert(temp.begin(), group.begin(), group.end()); faces.push_back(temp); for(std::set<MEdge, Less_Edge>::iterator it = touched.begin(); @@ -2290,25 +2343,22 @@ void GModel::alignPeriodicBoundaries() // realigning edges - for(eiter it = firstEdge();it!=lastEdge();++it) { - - GEdge* tgt = *it; - GEdge* src = dynamic_cast<GEdge*>(tgt->meshMaster()); + for(eiter it = firstEdge(); it != lastEdge(); ++it) { + GEdge *tgt = *it; + GEdge *src = dynamic_cast<GEdge *>(tgt->meshMaster()); if(src != NULL && src != tgt) { - // compose a search list on master edge - std::map<MEdge, MLine*, Less_Edge> srcLines; - for(unsigned int i = 0; i < src->getNumMeshElements(); i++) { - MLine* srcLine = dynamic_cast<MLine*>(src->getMeshElement(i)); - if(!srcLine){ + std::map<MEdge, MLine *, Less_Edge> srcLines; + for(unsigned int i = 0; i < src->getNumMeshElements(); i++) { + MLine *srcLine = dynamic_cast<MLine *>(src->getMeshElement(i)); + if(!srcLine) { Msg::Error("Master element %d is not an edge ", src->getMeshElement(i)->getNum()); return; } - srcLines[MEdge(srcLine->getVertex(0), - srcLine->getVertex(1))] = srcLine; + srcLines[MEdge(srcLine->getVertex(0), srcLine->getVertex(1))] = srcLine; } // run through slave edge elements @@ -2316,54 +2366,56 @@ void GModel::alignPeriodicBoundaries() // - check orientation and reorient if necessary for(unsigned int i = 0; i < tgt->getNumMeshElements(); ++i) { + MLine *tgtLine = dynamic_cast<MLine *>(tgt->getMeshElement(i)); - MLine* tgtLine = dynamic_cast<MLine*> (tgt->getMeshElement(i)); - - if(!tgtLine){ + if(!tgtLine) { Msg::Error("Slave element %d is not an edge ", tgt->getMeshElement(i)->getNum()); return; } - MVertex* tgtVtcs[2]; + MVertex *tgtVtcs[2]; for(int iVtx = 0; iVtx < 2; iVtx++) { - MVertex* tgtVtx = tgtLine->getVertex(iVtx); - GEntity* ge = tgtVtx->onWhat(); - std::map<MVertex*,MVertex*>& geV2v = ge->correspondingVertices; - std::map<MVertex*,MVertex*>& v2v = tgt->correspondingVertices; - std::map<MVertex*,MVertex*>::iterator srcIter = v2v.find(tgtVtx); + MVertex *tgtVtx = tgtLine->getVertex(iVtx); + GEntity *ge = tgtVtx->onWhat(); + std::map<MVertex *, MVertex *> &geV2v = ge->correspondingVertices; + std::map<MVertex *, MVertex *> &v2v = tgt->correspondingVertices; + std::map<MVertex *, MVertex *>::iterator srcIter = v2v.find(tgtVtx); if(srcIter == v2v.end() || !srcIter->second) { - // Msg::Info("Cannot find periodic counterpart of vertex %d on edge %d" + // Msg::Info("Cannot find periodic counterpart of vertex %d on edge + // %d" // ", looking on entity %d of dimension %d", // tgtVtx->getNum(),tgt->tag(),ge->tag(),ge->dim()); srcIter = geV2v.find(tgtVtx); if(srcIter == geV2v.end() || !srcIter->second) { - Msg::Error("Cannot find periodic counterpart of vertex %d on edge %d" - " nor on %d",tgtVtx->getNum(),tgt->tag(),ge->tag()); + Msg::Error( + "Cannot find periodic counterpart of vertex %d on edge %d" + " nor on %d", + tgtVtx->getNum(), tgt->tag(), ge->tag()); return; } - else tgtVtcs[iVtx] = srcIter->second; + else + tgtVtcs[iVtx] = srcIter->second; } - else tgtVtcs[iVtx] = srcIter->second; + else + tgtVtcs[iVtx] = srcIter->second; } MEdge tgtEdge(tgtVtcs[0], tgtVtcs[1]); - std::map<MEdge, MLine*, Less_Edge>::iterator sIter = srcLines.find(tgtEdge); + std::map<MEdge, MLine *, Less_Edge>::iterator sIter = + srcLines.find(tgtEdge); if(sIter == srcLines.end() || !sIter->second) { Msg::Error("Can't find periodic counterpart of edge %d-%d on edge %d" ", connected to edge %d-%d on %d", tgtLine->getVertex(0)->getNum(), - tgtLine->getVertex(1)->getNum(), - tgt->tag(), - tgtVtcs[0]->getNum(), - tgtVtcs[1]->getNum(), - src->tag()); + tgtLine->getVertex(1)->getNum(), tgt->tag(), + tgtVtcs[0]->getNum(), tgtVtcs[1]->getNum(), src->tag()); return; } else { - MLine* srcLine = sIter->second; + MLine *srcLine = sIter->second; MEdge srcEdge(srcLine->getVertex(0), srcLine->getVertex(1)); if(tgtEdge.computeCorrespondence(srcEdge) == -1) tgtLine->reverse(); } @@ -2374,19 +2426,17 @@ void GModel::alignPeriodicBoundaries() // run through all model faces for(GModel::fiter it = firstFace(); it != lastFace(); ++it) { - GFace *tgt = *it; - GFace *src = dynamic_cast<GFace*>(tgt->meshMaster()); + GFace *src = dynamic_cast<GFace *>(tgt->meshMaster()); if(src != NULL && src != tgt) { - - std::map<MFace,MElement*,Less_Face> srcElmts; + std::map<MFace, MElement *, Less_Face> srcElmts; for(unsigned int i = 0; i < src->getNumMeshElements(); ++i) { - MElement* srcElmt = src->getMeshElement(i); + MElement *srcElmt = src->getMeshElement(i); int nbVtcs = 0; - if(dynamic_cast<MTriangle*> (srcElmt)) nbVtcs = 3; - if(dynamic_cast<MQuadrangle*> (srcElmt)) nbVtcs = 4; - std::vector<MVertex*> vtcs; + if(dynamic_cast<MTriangle *>(srcElmt)) nbVtcs = 3; + if(dynamic_cast<MQuadrangle *>(srcElmt)) nbVtcs = 4; + std::vector<MVertex *> vtcs; vtcs.reserve(nbVtcs); for(int iVtx = 0; iVtx < nbVtcs; iVtx++) { vtcs.push_back(srcElmt->getVertex(iVtx)); @@ -2395,76 +2445,74 @@ void GModel::alignPeriodicBoundaries() } for(unsigned int i = 0; i < tgt->getNumMeshElements(); ++i) { - - MElement* tgtElmt = tgt->getMeshElement(i); - MTriangle* tgtTri = dynamic_cast<MTriangle*>(tgtElmt); - MQuadrangle* tgtQua = dynamic_cast<MQuadrangle*>(tgtElmt); + MElement *tgtElmt = tgt->getMeshElement(i); + MTriangle *tgtTri = dynamic_cast<MTriangle *>(tgtElmt); + MQuadrangle *tgtQua = dynamic_cast<MQuadrangle *>(tgtElmt); int nbVtcs = 0; if(tgtTri) nbVtcs = 3; if(tgtQua) nbVtcs = 4; - std::vector<MVertex*> vtcs; + std::vector<MVertex *> vtcs; for(int iVtx = 0; iVtx < nbVtcs; iVtx++) { - MVertex* vtx = tgtElmt->getVertex(iVtx); - GEntity* ge = vtx->onWhat(); + MVertex *vtx = tgtElmt->getVertex(iVtx); + GEntity *ge = vtx->onWhat(); - std::map<MVertex*, MVertex*>& geV2v = ge->correspondingVertices; - std::map<MVertex*, MVertex*>& v2v = tgt->correspondingVertices; + std::map<MVertex *, MVertex *> &geV2v = ge->correspondingVertices; + std::map<MVertex *, MVertex *> &v2v = tgt->correspondingVertices; - std::map<MVertex*,MVertex*>::iterator vIter = v2v.find(vtx); + std::map<MVertex *, MVertex *>::iterator vIter = v2v.find(vtx); if(vIter == v2v.end() || !vIter->second) { Msg::Info("Could not find copy of vertex %d in face %d" ", looking in entity %d of dimension %d", - vtx->getNum(),tgt->tag(),ge->tag(), ge->dim()); + vtx->getNum(), tgt->tag(), ge->tag(), ge->dim()); vIter = geV2v.find(vtx); if(vIter == geV2v.end() || !vIter->second) { Msg::Error("Could not find copy of vertex %d in %d nor in %d", - vtx->getNum(),tgt->tag(),ge->tag()); + vtx->getNum(), tgt->tag(), ge->tag()); return; } - else vtcs.push_back(vIter->second); + else + vtcs.push_back(vIter->second); } - else vtcs.push_back(vIter->second); + else + vtcs.push_back(vIter->second); } MFace tgtFace(vtcs); - std::map<MFace, MElement*>::iterator mIter = srcElmts.find(tgtFace); + std::map<MFace, MElement *>::iterator mIter = srcElmts.find(tgtFace); if(mIter == srcElmts.end()) { std::ostringstream faceDef; for(int iVtx = 0; iVtx < nbVtcs; iVtx++) { faceDef << vtcs[iVtx]->getNum() << " "; } Msg::Error("Cannot find periodic counterpart of face %s in face %d " - "connected to %d",faceDef.str().c_str(), - tgt->tag(),src->tag()); + "connected to %d", + faceDef.str().c_str(), tgt->tag(), src->tag()); return; } else { + const MFace &srcFace = mIter->first; + MElement *srcElmt = mIter->second; + std::vector<MVertex *> srcVtcs; - const MFace& srcFace = mIter->first; - MElement* srcElmt = mIter->second; - std::vector<MVertex*> srcVtcs; - - if(tgtTri && !dynamic_cast<MTriangle*>(srcElmt)) throw; - if(tgtQua && !dynamic_cast<MQuadrangle*>(srcElmt)) throw; + if(tgtTri && !dynamic_cast<MTriangle *>(srcElmt)) throw; + if(tgtQua && !dynamic_cast<MQuadrangle *>(srcElmt)) throw; int rotation = 0; bool swap = false; if(!tgtFace.computeCorrespondence(srcFace, rotation, swap)) { - Msg::Error("Non-corresponding face %d-%d-%d (slave) %d-%d-%d (master)", - tgtElmt->getVertex(0)->getNum(), - tgtElmt->getVertex(1)->getNum(), - tgtElmt->getVertex(2)->getNum(), - srcElmt->getVertex(0)->getNum(), - srcElmt->getVertex(1)->getNum(), - srcElmt->getVertex(2)->getNum()); + Msg::Error( + "Non-corresponding face %d-%d-%d (slave) %d-%d-%d (master)", + tgtElmt->getVertex(0)->getNum(), tgtElmt->getVertex(1)->getNum(), + tgtElmt->getVertex(2)->getNum(), srcElmt->getVertex(0)->getNum(), + srcElmt->getVertex(1)->getNum(), srcElmt->getVertex(2)->getNum()); return; } - if(tgtTri) tgtTri->reorient(rotation,swap); - if(tgtQua) tgtQua->reorient(rotation,swap); + if(tgtTri) tgtTri->reorient(rotation, swap); + if(tgtQua) tgtQua->reorient(rotation, swap); } } } @@ -2476,37 +2524,37 @@ void GModel::makeDiscreteRegionsSimplyConnected() { Msg::Debug("Making discrete regions simply connected..."); - std::vector<discreteRegion*> discRegions; + std::vector<discreteRegion *> discRegions; for(riter it = firstRegion(); it != lastRegion(); it++) if((*it)->geomType() == GEntity::DiscreteVolume) - discRegions.push_back((discreteRegion*) *it); - - std::set<MVertex*> touched; + discRegions.push_back((discreteRegion *)*it); - for(std::vector<discreteRegion*>::iterator itR = discRegions.begin(); - itR != discRegions.end(); itR++){ + std::set<MVertex *> touched; - std::vector<MElement*> allElements((*itR)->getNumMeshElements()); + for(std::vector<discreteRegion *>::iterator itR = discRegions.begin(); + itR != discRegions.end(); itR++) { + std::vector<MElement *> allElements((*itR)->getNumMeshElements()); for(unsigned int i = 0; i < (*itR)->getNumMeshElements(); i++) allElements[i] = (*itR)->getMeshElement(i); - std::vector<std::vector<MElement*> > conRegions; + std::vector<std::vector<MElement *> > conRegions; int nbRegions = connectedVolumes(allElements, conRegions); if(nbRegions > 1) remove(*itR); - for(int ire = 0; ire < nbRegions; ire++){ - int numR = (nbRegions == 1) ? (*itR)->tag() : getMaxElementaryNumber(3) + 1; + for(int ire = 0; ire < nbRegions; ire++) { + int numR = + (nbRegions == 1) ? (*itR)->tag() : getMaxElementaryNumber(3) + 1; discreteRegion *r = new discreteRegion(this, numR); add(r); - std::vector<MElement*> myElements = conRegions[ire]; - std::set<MVertex*> myVertices; + std::vector<MElement *> myElements = conRegions[ire]; + std::set<MVertex *> myVertices; for(unsigned int i = 0; i < myElements.size(); i++) { MElement *e = myElements[i]; - std::vector<MVertex*> verts; + std::vector<MVertex *> verts; e->getVertices(verts); - for(unsigned int k = 0; k < verts.size(); k++){ - if(verts[k]->onWhat() && verts[k]->onWhat()->dim() == 3){ - if(touched.find(verts[k]) == touched.end()){ + for(unsigned int k = 0; k < verts.size(); k++) { + if(verts[k]->onWhat() && verts[k]->onWhat()->dim() == 3) { + if(touched.find(verts[k]) == touched.end()) { verts[k]->setEntity(r); myVertices.insert(verts[k]); touched.insert(verts[k]); @@ -2516,16 +2564,16 @@ void GModel::makeDiscreteRegionsSimplyConnected() MElementFactory factory; MElement *e2 = factory.create(e->getTypeForMSH(), verts, e->getNum(), e->getPartition()); - switch(e2->getType()){ - case TYPE_TET: r->tetrahedra.push_back((MTetrahedron*)e2); break; - case TYPE_HEX: r->hexahedra.push_back((MHexahedron*)e2); break; - case TYPE_PRI: r->prisms.push_back((MPrism*)e2); break; - case TYPE_PYR: r->pyramids.push_back((MPyramid*)e2); break; - case TYPE_TRIH: r->trihedra.push_back((MTrihedron*)e2); break; + switch(e2->getType()) { + case TYPE_TET: r->tetrahedra.push_back((MTetrahedron *)e2); break; + case TYPE_HEX: r->hexahedra.push_back((MHexahedron *)e2); break; + case TYPE_PRI: r->prisms.push_back((MPrism *)e2); break; + case TYPE_PYR: r->pyramids.push_back((MPyramid *)e2); break; + case TYPE_TRIH: r->trihedra.push_back((MTrihedron *)e2); break; } } - r->mesh_vertices.insert - (r->mesh_vertices.begin(), myVertices.begin(), myVertices.end()); + r->mesh_vertices.insert(r->mesh_vertices.begin(), myVertices.begin(), + myVertices.end()); } } @@ -2536,37 +2584,36 @@ void GModel::makeDiscreteFacesSimplyConnected() { Msg::Debug("Making discrete faces simply connected..."); - std::vector<discreteFace*> discFaces; + std::vector<discreteFace *> discFaces; for(fiter it = firstFace(); it != lastFace(); it++) if((*it)->geomType() == GEntity::DiscreteSurface) - discFaces.push_back((discreteFace*) *it); + discFaces.push_back((discreteFace *)*it); - std::set<MVertex*> touched; + std::set<MVertex *> touched; - for(std::vector<discreteFace*>::iterator itF = discFaces.begin(); - itF != discFaces.end(); itF++){ - - std::vector<MElement*> allElements((*itF)->getNumMeshElements()); + for(std::vector<discreteFace *>::iterator itF = discFaces.begin(); + itF != discFaces.end(); itF++) { + std::vector<MElement *> allElements((*itF)->getNumMeshElements()); for(unsigned int i = 0; i < (*itF)->getNumMeshElements(); i++) allElements[i] = (*itF)->getMeshElement(i); - std::vector<std::vector<MElement*> > conFaces; + std::vector<std::vector<MElement *> > conFaces; int nbFaces = connectedSurfaces(allElements, conFaces); if(nbFaces > 1) remove(*itF); - for(int ifa = 0; ifa < nbFaces; ifa++){ + for(int ifa = 0; ifa < nbFaces; ifa++) { int numF = (nbFaces == 1) ? (*itF)->tag() : getMaxElementaryNumber(2) + 1; discreteFace *f = new discreteFace(this, numF); add(f); - std::vector<MElement*> myElements = conFaces[ifa]; - std::set<MVertex*> myVertices; + std::vector<MElement *> myElements = conFaces[ifa]; + std::set<MVertex *> myVertices; for(unsigned int i = 0; i < myElements.size(); i++) { MElement *e = myElements[i]; - std::vector<MVertex*> verts; + std::vector<MVertex *> verts; e->getVertices(verts); - for(unsigned int k = 0; k < verts.size(); k++){ - if(verts[k]->onWhat() && verts[k]->onWhat()->dim() == 2){ - if(touched.find(verts[k]) == touched.end()){ + for(unsigned int k = 0; k < verts.size(); k++) { + if(verts[k]->onWhat() && verts[k]->onWhat()->dim() == 2) { + if(touched.find(verts[k]) == touched.end()) { verts[k]->setEntity(f); myVertices.insert(verts[k]); touched.insert(verts[k]); @@ -2577,12 +2624,12 @@ void GModel::makeDiscreteFacesSimplyConnected() MElement *e2 = factory.create(e->getTypeForMSH(), verts, e->getNum(), e->getPartition()); if(e2->getType() == TYPE_TRI) - f->triangles.push_back((MTriangle*)e2); + f->triangles.push_back((MTriangle *)e2); else - f->quadrangles.push_back((MQuadrangle*)e2); + f->quadrangles.push_back((MQuadrangle *)e2); } - f->mesh_vertices.insert - (f->mesh_vertices.begin(), myVertices.begin(), myVertices.end()); + f->mesh_vertices.insert(f->mesh_vertices.begin(), myVertices.begin(), + myVertices.end()); } } @@ -2602,65 +2649,67 @@ void GModel::createTopologyFromMesh() Msg::StatusBar(true, "Done creating topology from mesh (%g s)", t2 - t1); } -static void makeSimplyConnected(std::map<int, std::vector<MElement*> > elements[11]) +static void +makeSimplyConnected(std::map<int, std::vector<MElement *> > elements[11]) { - //only for tetras and triangles + // only for tetras and triangles Msg::Info("Make simply connected regions and surfaces"); std::vector<int> regs; - for(std::map<int, std::vector<MElement*> >::iterator it = elements[4].begin(); + for(std::map<int, std::vector<MElement *> >::iterator it = + elements[4].begin(); it != elements[4].end(); it++) regs.push_back(it->first); - std::multimap<MFace, MElement*, Less_Face> f2e; - if(regs.size() > 2){ - for(unsigned int i = 0; i < regs.size(); i++){ - for(unsigned int j = 0; j < elements[4][regs[i]].size(); j++){ + std::multimap<MFace, MElement *, Less_Face> f2e; + if(regs.size() > 2) { + for(unsigned int i = 0; i < regs.size(); i++) { + for(unsigned int j = 0; j < elements[4][regs[i]].size(); j++) { MElement *el = elements[4][regs[i]][j]; for(int k = 0; k < el->getNumFaces(); k++) f2e.insert(std::make_pair(el->getFace(k), el)); } } } - for(unsigned int i = 0; i < regs.size(); i++){ + for(unsigned int i = 0; i < regs.size(); i++) { int ri = regs[i]; - std::vector<MElement*> allElements; + std::vector<MElement *> allElements; for(unsigned int j = 0; j < elements[4][ri].size(); j++) allElements.push_back(elements[4][ri][j]); - std::vector<std::vector<MElement*> > conRegions; + std::vector<std::vector<MElement *> > conRegions; int nbConRegions = connectedVolumes(allElements, conRegions); Msg::Info("%d connected regions (reg=%d)", nbConRegions, ri); unsigned int maxNumEl = 1; for(int j = 0; j < nbConRegions; j++) - if(conRegions[j].size() > maxNumEl) - maxNumEl = conRegions[j].size(); - for(int j = 0; j < nbConRegions; j++){ - //remove conRegions containing few elements - if(conRegions[j].size() < maxNumEl * 1.e-4){ - //find adjacent region + if(conRegions[j].size() > maxNumEl) maxNumEl = conRegions[j].size(); + for(int j = 0; j < nbConRegions; j++) { + // remove conRegions containing few elements + if(conRegions[j].size() < maxNumEl * 1.e-4) { + // find adjacent region int r2 = ri; if(regs.size() == 2) r2 = (ri + 1) % 2; - else{ - for(unsigned int k = 0; k < conRegions[j].size(); k++){ + else { + for(unsigned int k = 0; k < conRegions[j].size(); k++) { MElement *el = conRegions[j][k]; - for(int l = 0; l < el->getNumFaces(); l++){ + for(int l = 0; l < el->getNumFaces(); l++) { MFace mf = el->getFace(l); - std::multimap<MFace, MElement*, Less_Face>::iterator itl = + std::multimap<MFace, MElement *, Less_Face>::iterator itl = f2e.lower_bound(mf); - for(; itl != f2e.upper_bound(mf); itl++){ + for(; itl != f2e.upper_bound(mf); itl++) { if(itl->second != el) break; } MElement *el2 = itl->second; bool sameRegion = false; for(unsigned int m = 0; m < conRegions[j].size(); m++) if(conRegions[j][m] == el2) { - sameRegion = true; break; + sameRegion = true; + break; } if(sameRegion) continue; - for(unsigned int m = 0; m < regs.size(); m++){ + for(unsigned int m = 0; m < regs.size(); m++) { int rm = regs[m]; if(rm == ri) continue; for(unsigned int n = 0; n < elements[4][rm].size(); n++) - if(elements[4][rm][n] == el2){ + if(elements[4][rm][n] == el2) { r2 = rm; break; } @@ -2670,10 +2719,11 @@ static void makeSimplyConnected(std::map<int, std::vector<MElement*> > elements[ } if(r2 != ri) break; } - if(r2 == ri) Msg::Warning("Element not found for simply connected regions"); + if(r2 == ri) + Msg::Warning("Element not found for simply connected regions"); } - for(unsigned int k = 0; k < conRegions[j].size(); k++){ + for(unsigned int k = 0; k < conRegions[j].size(); k++) { MElement *el = conRegions[j][k]; unsigned int l = 0; for(; l < elements[4][ri].size(); l++) @@ -2686,59 +2736,61 @@ static void makeSimplyConnected(std::map<int, std::vector<MElement*> > elements[ } std::vector<int> faces; - for(std::map<int, std::vector<MElement*> >::iterator it = elements[2].begin(); + for(std::map<int, std::vector<MElement *> >::iterator it = + elements[2].begin(); it != elements[2].end(); it++) faces.push_back(it->first); - std::multimap<MEdge, MElement*, Less_Edge> e2e; - if(faces.size() > 2){ - for(unsigned int i = 0; i < faces.size(); i++){ - for(unsigned int j = 0; j < elements[2][faces[i]].size(); j++){ + std::multimap<MEdge, MElement *, Less_Edge> e2e; + if(faces.size() > 2) { + for(unsigned int i = 0; i < faces.size(); i++) { + for(unsigned int j = 0; j < elements[2][faces[i]].size(); j++) { MElement *el = elements[2][faces[i]][j]; for(int k = 0; k < el->getNumEdges(); k++) e2e.insert(std::make_pair(el->getEdge(k), el)); } } } - for(unsigned int i = 0; i < faces.size(); i++){ + for(unsigned int i = 0; i < faces.size(); i++) { int fi = faces[i]; - std::vector<MElement*> allElements; + std::vector<MElement *> allElements; for(unsigned int j = 0; j < elements[2][fi].size(); j++) allElements.push_back(elements[2][fi][j]); - std::vector<std::vector<MElement*> > conSurfaces; + std::vector<std::vector<MElement *> > conSurfaces; int nbConSurfaces = connectedSurfaces(allElements, conSurfaces); Msg::Info("%d connected surfaces (reg=%d)", nbConSurfaces, fi); unsigned int maxNumEl = 1; for(int j = 0; j < nbConSurfaces; j++) - if(conSurfaces[j].size() > maxNumEl) - maxNumEl = conSurfaces[j].size(); - for(int j = 0; j < nbConSurfaces; j++){ - //remove conSurfaces containing few elements - if(conSurfaces[j].size() < maxNumEl * 1.e-4){ - //find adjacent surface + if(conSurfaces[j].size() > maxNumEl) maxNumEl = conSurfaces[j].size(); + for(int j = 0; j < nbConSurfaces; j++) { + // remove conSurfaces containing few elements + if(conSurfaces[j].size() < maxNumEl * 1.e-4) { + // find adjacent surface int f2 = fi; if(faces.size() == 2) f2 = (fi + 1) % 2; - else{ - for(unsigned int k = 0; k < conSurfaces[j].size(); k++){ + else { + for(unsigned int k = 0; k < conSurfaces[j].size(); k++) { MElement *el = conSurfaces[j][k]; - for(int l = 0; l < el->getNumEdges(); l++){ + for(int l = 0; l < el->getNumEdges(); l++) { MEdge me = el->getEdge(l); - std::multimap<MEdge, MElement*, Less_Edge>::iterator itl = e2e.lower_bound(me); - for(; itl != e2e.upper_bound(me); itl++){ + std::multimap<MEdge, MElement *, Less_Edge>::iterator itl = + e2e.lower_bound(me); + for(; itl != e2e.upper_bound(me); itl++) { if(itl->second != el) break; } MElement *el2 = itl->second; bool sameSurface = false; for(unsigned int m = 0; m < conSurfaces[j].size(); m++) if(conSurfaces[j][m] == el2) { - sameSurface = true; break; + sameSurface = true; + break; } if(sameSurface) continue; - for(unsigned int m = 0; m < faces.size(); m++){ + for(unsigned int m = 0; m < faces.size(); m++) { int fm = faces[m]; if(fm == fi) continue; for(unsigned int n = 0; n < elements[2][fm].size(); n++) - if(elements[2][fm][n] == el2){ + if(elements[2][fm][n] == el2) { f2 = fm; break; } @@ -2748,9 +2800,10 @@ static void makeSimplyConnected(std::map<int, std::vector<MElement*> > elements[ } if(f2 != fi) break; } - if(f2 == fi) Msg::Warning("Element not found for simply connected surfaces"); + if(f2 == fi) + Msg::Warning("Element not found for simply connected surfaces"); } - for(unsigned int k = 0; k < conSurfaces[j].size(); k++){ + for(unsigned int k = 0; k < conSurfaces[j].size(); k++) { MElement *el = conSurfaces[j][k]; unsigned int l = 0; for(; l < elements[2][fi].size(); l++) @@ -2770,28 +2823,31 @@ GModel *GModel::buildCutGModel(gLevelset *ls, bool cutElem, bool saveTri) else CTX::instance()->mesh.saveTri = 0; - std::map<int, std::vector<MElement*> > elements[11]; + std::map<int, std::vector<MElement *> > elements[11]; std::map<int, std::map<int, std::string> > physicals[4]; - std::map<int, MVertex*> vertexMap; + std::map<int, MVertex *> vertexMap; - if(cutElem) Msg::Info("Cutting mesh..."); - else Msg::Info("Splitting mesh..."); + if(cutElem) + Msg::Info("Cutting mesh..."); + else + Msg::Info("Splitting mesh..."); double t1 = Cpu(); - GModel *cutGM = buildCutMesh(this, ls, elements, vertexMap, physicals, cutElem); + GModel *cutGM = + buildCutMesh(this, ls, elements, vertexMap, physicals, cutElem); - if(!cutElem) - makeSimplyConnected(elements); + if(!cutElem) makeSimplyConnected(elements); for(int i = 0; i < (int)(sizeof(elements) / sizeof(elements[0])); i++) cutGM->_storeElementsInEntities(elements[i]); cutGM->_associateEntityWithMeshVertices(); cutGM->_storeVerticesInEntities(vertexMap); - for(int i = 0; i < 4; i++){ + for(int i = 0; i < 4; i++) { cutGM->_storePhysicalTagsInEntities(i, physicals[i]); - std::map<int, std::map<int, std::string> >::iterator it = physicals[i].begin(); - for(; it != physicals[i].end(); it++){ + std::map<int, std::map<int, std::string> >::iterator it = + physicals[i].begin(); + for(; it != physicals[i].end(); it++) { std::map<int, std::string>::iterator it2 = it->second.begin(); for(; it2 != it->second.end(); it2++) if(it2->second != "") @@ -2799,8 +2855,10 @@ GModel *GModel::buildCutGModel(gLevelset *ls, bool cutElem, bool saveTri) } } - if(cutElem) Msg::Info("Mesh cutting completed (%g s)", Cpu() - t1); - else Msg::Info("Mesh splitting completed (%g s)", Cpu() - t1); + if(cutElem) + Msg::Info("Mesh cutting completed (%g s)", Cpu() - t1); + else + Msg::Info("Mesh splitting completed (%g s)", Cpu() - t1); return cutGM; } @@ -2833,26 +2891,28 @@ int GModel::readGEO(const std::string &name) return true; } -void GModel::setPhysicalNumToEntitiesInBox(int EntityDimension, int PhysicalNumber, +void GModel::setPhysicalNumToEntitiesInBox(int EntityDimension, + int PhysicalNumber, SBoundingBox3d box) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntitiesInBox(entities, box, EntityDimension); for(unsigned int i = 0; i < entities.size(); i++) entities[i]->addPhysicalEntity(PhysicalNumber); } -void GModel::setPhysicalNumToEntitiesInBox(int EntityDimension, int PhysicalNumber, - std::vector<double> p1, std::vector<double> p2) +void GModel::setPhysicalNumToEntitiesInBox(int EntityDimension, + int PhysicalNumber, + std::vector<double> p1, + std::vector<double> p2) { if(p1.size() != 3 || p2.size() != 3) return; SBoundingBox3d box(p1[0], p1[2], p1[2], p2[0], p2[1], p2[3]); setPhysicalNumToEntitiesInBox(EntityDimension, PhysicalNumber, box); } - GEdge *getNewModelEdge(GFace *gf1, GFace *gf2, - std::map<std::pair<int, int>, GEdge*> &newEdges) + std::map<std::pair<int, int>, GEdge *> &newEdges) { int t1 = gf1 ? gf1->tag() : -1; int t2 = gf2 ? gf2->tag() : -1; @@ -2861,11 +2921,12 @@ GEdge *getNewModelEdge(GFace *gf1, GFace *gf2, if(i1 == i2) return 0; - std::map<std::pair<int, int>, GEdge*>::iterator it = + std::map<std::pair<int, int>, GEdge *>::iterator it = newEdges.find(std::make_pair(i1, i2)); - if(it == newEdges.end()){ - discreteEdge *ge = new discreteEdge - (GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, 0, 0); + if(it == newEdges.end()) { + discreteEdge *ge = + new discreteEdge(GModel::current(), + GModel::current()->getMaxElementaryNumber(1) + 1, 0, 0); GModel::current()->add(ge); newEdges[std::make_pair(i1, i2)] = ge; return ge; @@ -2878,25 +2939,25 @@ GEdge *getNewModelEdge(GFace *gf1, GFace *gf2, void GModel::classifyAllFaces() { - std::set<GFace*> faces; - std::vector<MElement*> elements; + std::set<GFace *> faces; + std::vector<MElement *> elements; for(GModel::fiter it = this->firstFace(); it != this->lastFace(); ++it) { faces.insert(*it); elements.insert(elements.end(), (*it)->triangles.begin(), - (*it)->triangles.end()); + (*it)->triangles.end()); elements.insert(elements.end(), (*it)->quadrangles.begin(), - (*it)->quadrangles.end()); + (*it)->quadrangles.end()); } - discreteEdge* edge = new discreteEdge - (GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, 0, 0); + discreteEdge *edge = new discreteEdge( + GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, 0, 0); GModel::current()->add(edge); e2t_cont adj; buildEdgeToElements(elements, adj); std::vector<edge_angle> edges_detected, edges_lonly; buildListOfEdgeAngle(adj, edges_detected, edges_lonly); - for(unsigned int i = 0; i < edges_detected.size(); i++){ + for(unsigned int i = 0; i < edges_detected.size(); i++) { edge_angle ea = edges_detected[i]; if(ea.angle <= EDGE_ANGLE_THRESHOLD) break; edge->lines.push_back(new MLine(ea.v1, ea.v2)); @@ -2912,52 +2973,53 @@ void GModel::classifyAllFaces() edges_lonly.clear(); } -void recurClassifyEdges(MTri3 *t, std::map<MTriangle*, GFace*> &reverse, - std::map<MLine*, GEdge*, compareMLinePtr> &lines, - std::set<MLine*> &touched, std::set<MTri3*> &trisTouched, - std::map<std::pair<int, int>, GEdge*> &newEdges) +void recurClassifyEdges(MTri3 *t, std::map<MTriangle *, GFace *> &reverse, + std::map<MLine *, GEdge *, compareMLinePtr> &lines, + std::set<MLine *> &touched, + std::set<MTri3 *> &trisTouched, + std::map<std::pair<int, int>, GEdge *> &newEdges) { - if(!t->isDeleted()){ + if(!t->isDeleted()) { trisTouched.erase(t); t->setDeleted(true); GFace *gf1 = reverse[t->tri()]; - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { GFace *gf2 = 0; MTri3 *tn = t->getNeigh(i); - if(tn) - gf2 = reverse[tn->tri()]; + if(tn) gf2 = reverse[tn->tri()]; edgeXface exf(t, i); MLine ml(exf._v(0), exf._v(1)); - std::map<MLine*, GEdge*, compareMLinePtr>::iterator it = lines.find(&ml); - if(it != lines.end()){ - if(touched.find(it->first) == touched.end()){ - GEdge *ge = getNewModelEdge(gf1, gf2, newEdges); + std::map<MLine *, GEdge *, compareMLinePtr>::iterator it = + lines.find(&ml); + if(it != lines.end()) { + if(touched.find(it->first) == touched.end()) { + GEdge *ge = getNewModelEdge(gf1, gf2, newEdges); if(ge) ge->lines.push_back(it->first); touched.insert(it->first); } } if(tn) - recurClassifyEdges(tn, reverse, lines, touched, trisTouched,newEdges); + recurClassifyEdges(tn, reverse, lines, touched, trisTouched, newEdges); } } } void recurClassify(MTri3 *t, GFace *gf, - std::map<MLine*, GEdge*, compareMLinePtr> &lines, - std::map<MTriangle*, GFace*> &reverse) + std::map<MLine *, GEdge *, compareMLinePtr> &lines, + std::map<MTriangle *, GFace *> &reverse) { - if(!t->isDeleted()){ + if(!t->isDeleted()) { gf->triangles.push_back(t->tri()); reverse[t->tri()] = gf; t->setDeleted(true); - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { MTri3 *tn = t->getNeigh(i); - if(tn){ + if(tn) { edgeXface exf(t, i); MLine ml(exf._v(0), exf._v(1)); - std::map<MLine*, GEdge*, compareMLinePtr>::iterator it = lines.find(&ml); - if(it == lines.end()) - recurClassify(tn, gf, lines, reverse); + std::map<MLine *, GEdge *, compareMLinePtr>::iterator it = + lines.find(&ml); + if(it == lines.end()) recurClassify(tn, gf, lines, reverse); } } } @@ -2965,24 +3027,24 @@ void recurClassify(MTri3 *t, GFace *gf, #endif -void GModel::classifyFaces(std::set<GFace*> &_faces) +void GModel::classifyFaces(std::set<GFace *> &_faces) { #if defined(HAVE_MESH) - std::map<MLine*, GEdge*, compareMLinePtr> lines; + std::map<MLine *, GEdge *, compareMLinePtr> lines; for(GModel::eiter it = GModel::current()->firstEdge(); - it != GModel::current()->lastEdge(); ++it){ - for(unsigned int i = 0; i < (*it)->lines.size();i++) + it != GModel::current()->lastEdge(); ++it) { + for(unsigned int i = 0; i < (*it)->lines.size(); i++) lines[(*it)->lines[i]] = *it; } - std::map<MTriangle*, GFace*> reverse_old; - std::list<MTri3*> tris; + std::map<MTriangle *, GFace *> reverse_old; + std::list<MTri3 *> tris; { - std::set<GFace*>::iterator it = _faces.begin(); - while(it != _faces.end()){ + std::set<GFace *>::iterator it = _faces.begin(); + while(it != _faces.end()) { GFace *gf = *it; - for(unsigned int i = 0; i < gf->triangles.size(); i++){ + for(unsigned int i = 0; i < gf->triangles.size(); i++) { tris.push_back(new MTri3(gf->triangles[i], 0)); reverse_old[gf->triangles[i]] = gf; } @@ -2995,21 +3057,21 @@ void GModel::classifyFaces(std::set<GFace*> &_faces) connectTriangles(tris); - std::map<MTriangle*, GFace*> reverse; - std::multimap<GFace*, GFace*> replacedBy; + std::map<MTriangle *, GFace *> reverse; + std::multimap<GFace *, GFace *> replacedBy; // color all triangles - std::list<MTri3*> ::iterator it = tris.begin(); - std::list<GFace*> newf; - while(it != tris.end()){ - if(!(*it)->isDeleted()){ - discreteFace *gf = new discreteFace - (GModel::current(), GModel::current()->getMaxElementaryNumber(2) + 1); + std::list<MTri3 *>::iterator it = tris.begin(); + std::list<GFace *> newf; + while(it != tris.end()) { + if(!(*it)->isDeleted()) { + discreteFace *gf = new discreteFace( + GModel::current(), GModel::current()->getMaxElementaryNumber(2) + 1); recurClassify(*it, gf, lines, reverse); GModel::current()->add(gf); newf.push_back(gf); - for(unsigned int i = 0; i < gf->triangles.size(); i++){ - replacedBy.insert(std::make_pair(reverse_old[gf->triangles[i]],gf)); + for(unsigned int i = 0; i < gf->triangles.size(); i++) { + replacedBy.insert(std::make_pair(reverse_old[gf->triangles[i]], gf)); } } ++it; @@ -3018,63 +3080,65 @@ void GModel::classifyFaces(std::set<GFace*> &_faces) // now we have all faces coloured. If some regions were existing, replace // their faces by the new ones - for(riter rit = firstRegion(); rit != lastRegion(); ++rit){ + for(riter rit = firstRegion(); rit != lastRegion(); ++rit) { std::vector<GFace *> _xfaces = (*rit)->faces(); std::set<GFace *> _newFaces; - for(std::vector<GFace *>::iterator itf = _xfaces.begin(); itf != _xfaces.end(); ++itf){ + for(std::vector<GFace *>::iterator itf = _xfaces.begin(); + itf != _xfaces.end(); ++itf) { + std::multimap<GFace *, GFace *>::iterator itLow = + replacedBy.lower_bound(*itf); + std::multimap<GFace *, GFace *>::iterator itUp = + replacedBy.upper_bound(*itf); - std::multimap<GFace*, GFace*>::iterator itLow = replacedBy.lower_bound(*itf); - std::multimap<GFace*, GFace*>::iterator itUp = replacedBy.upper_bound(*itf); - - for(; itLow != itUp; ++itLow) - _newFaces.insert(itLow->second); + for(; itLow != itUp; ++itLow) _newFaces.insert(itLow->second); } - (*rit)->set(std::vector<GFace *>(_newFaces.begin(),_newFaces.end())); + (*rit)->set(std::vector<GFace *>(_newFaces.begin(), _newFaces.end())); } // color some lines it = tris.begin(); - while(it != tris.end()){ + while(it != tris.end()) { (*it)->setDeleted(false); ++it; } // classify edges that are bound by different GFaces - std::map<std::pair<int, int>, GEdge*> newEdges; - std::set<MLine*> touched; - std::set<MTri3*> trisTouched; + std::map<std::pair<int, int>, GEdge *> newEdges; + std::set<MLine *> touched; + std::set<MTri3 *> trisTouched; // bug fix : multiply connected domains - trisTouched.insert(tris.begin(),tris.end()); + trisTouched.insert(tris.begin(), tris.end()); while(!trisTouched.empty()) - recurClassifyEdges(*trisTouched.begin(), reverse, lines, touched, trisTouched,newEdges); + recurClassifyEdges(*trisTouched.begin(), reverse, lines, touched, + trisTouched, newEdges); - std::map<discreteFace*,std::vector<int> > newFaceTopology; + std::map<discreteFace *, std::vector<int> > newFaceTopology; // check if new edges should not be splitted // splitted if composed of several open or closed edges - std::map<MVertex*,GVertex*> modelVertices; + std::map<MVertex *, GVertex *> modelVertices; - for(std::map<std::pair<int, int>, GEdge*>::iterator ite = newEdges.begin(); - ite != newEdges.end() ; ++ite){ - std::list<MLine*> allSegments; + for(std::map<std::pair<int, int>, GEdge *>::iterator ite = newEdges.begin(); + ite != newEdges.end(); ++ite) { + std::list<MLine *> allSegments; for(unsigned int i = 0; i < ite->second->lines.size(); i++) allSegments.push_back(ite->second->lines[i]); - while (!allSegments.empty()) { - std::list<MLine*> segmentsForThisDiscreteEdge; + while(!allSegments.empty()) { + std::list<MLine *> segmentsForThisDiscreteEdge; MVertex *vB = (*allSegments.begin())->getVertex(0); MVertex *vE = (*allSegments.begin())->getVertex(1); segmentsForThisDiscreteEdge.push_back(*allSegments.begin()); allSegments.erase(allSegments.begin()); - while(1){ + while(1) { bool found = false; - for(std::list<MLine*>::iterator it = allSegments.begin(); - it != allSegments.end(); ++it){ + for(std::list<MLine *>::iterator it = allSegments.begin(); + it != allSegments.end(); ++it) { MVertex *v1 = (*it)->getVertex(0); MVertex *v2 = (*it)->getVertex(1); - if(v1 == vE || v2 == vE){ + if(v1 == vE || v2 == vE) { segmentsForThisDiscreteEdge.push_back(*it); if(v2 == vE) (*it)->reverse(); vE = (v1 == vE) ? v2 : v1; @@ -3082,7 +3146,7 @@ void GModel::classifyFaces(std::set<GFace*> &_faces) allSegments.erase(it); break; } - if(v1 == vB || v2 == vB){ + if(v1 == vB || v2 == vB) { segmentsForThisDiscreteEdge.push_front(*it); if(v1 == vB) (*it)->reverse(); vB = (v1 == vB) ? v2 : v1; @@ -3091,14 +3155,14 @@ void GModel::classifyFaces(std::set<GFace*> &_faces) break; } } - if(vE == vB)break; - if(!found)break; + if(vE == vB) break; + if(!found) break; } - std::map<MVertex*,GVertex*>::iterator itMV = modelVertices.find(vB); - if(itMV == modelVertices.end()){ - GVertex *newGv = new discreteVertex - (GModel::current(), GModel::current()->getMaxElementaryNumber(0) + 1); + std::map<MVertex *, GVertex *>::iterator itMV = modelVertices.find(vB); + if(itMV == modelVertices.end()) { + GVertex *newGv = new discreteVertex( + GModel::current(), GModel::current()->getMaxElementaryNumber(0) + 1); newGv->mesh_vertices.push_back(vB); vB->setEntity(newGv); newGv->points.push_back(new MPoint(vB)); @@ -3106,9 +3170,9 @@ void GModel::classifyFaces(std::set<GFace*> &_faces) modelVertices[vB] = newGv; } itMV = modelVertices.find(vE); - if(itMV == modelVertices.end()){ - GVertex *newGv = new discreteVertex - (GModel::current(), GModel::current()->getMaxElementaryNumber(0) + 1); + if(itMV == modelVertices.end()) { + GVertex *newGv = new discreteVertex( + GModel::current(), GModel::current()->getMaxElementaryNumber(0) + 1); newGv->mesh_vertices.push_back(vE); newGv->points.push_back(new MPoint(vE)); vE->setEntity(newGv); @@ -3116,56 +3180,59 @@ void GModel::classifyFaces(std::set<GFace*> &_faces) modelVertices[vE] = newGv; } - GEdge *newGe = new discreteEdge - (GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, - modelVertices[vB], modelVertices[vE]); - newGe->lines.insert(newGe->lines.end(), segmentsForThisDiscreteEdge.begin(), + GEdge *newGe = new discreteEdge( + GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, + modelVertices[vB], modelVertices[vE]); + newGe->lines.insert(newGe->lines.end(), + segmentsForThisDiscreteEdge.begin(), segmentsForThisDiscreteEdge.end()); - for(std::list<MLine*>::iterator itL = segmentsForThisDiscreteEdge.begin(); - itL != segmentsForThisDiscreteEdge.end(); ++itL){ - if((*itL)->getVertex(0)->onWhat()->dim() != 0){ + for(std::list<MLine *>::iterator itL = + segmentsForThisDiscreteEdge.begin(); + itL != segmentsForThisDiscreteEdge.end(); ++itL) { + if((*itL)->getVertex(0)->onWhat()->dim() != 0) { newGe->mesh_vertices.push_back((*itL)->getVertex(0)); (*itL)->getVertex(0)->setEntity(newGe); } } GModel::current()->add(newGe); - discreteFace *gf1 = dynamic_cast<discreteFace*> - (GModel::current()->getFaceByTag(ite->first.first)); - discreteFace *gf2 = dynamic_cast<discreteFace*> - (GModel::current()->getFaceByTag(ite->first.second)); - if(gf1)newFaceTopology[gf1].push_back(newGe->tag()); - if(gf2)newFaceTopology[gf2].push_back(newGe->tag()); + discreteFace *gf1 = dynamic_cast<discreteFace *>( + GModel::current()->getFaceByTag(ite->first.first)); + discreteFace *gf2 = dynamic_cast<discreteFace *>( + GModel::current()->getFaceByTag(ite->first.second)); + if(gf1) newFaceTopology[gf1].push_back(newGe->tag()); + if(gf2) newFaceTopology[gf2].push_back(newGe->tag()); } } - std::map<discreteFace*,std::vector<int> >::iterator itFT = newFaceTopology.begin(); - for(;itFT != newFaceTopology.end();++itFT){ + std::map<discreteFace *, std::vector<int> >::iterator itFT = + newFaceTopology.begin(); + for(; itFT != newFaceTopology.end(); ++itFT) { itFT->first->setBoundEdges(itFT->second); } - for(std::map<std::pair<int, int>, GEdge*>::iterator it = newEdges.begin(); - it != newEdges.end(); ++it){ + for(std::map<std::pair<int, int>, GEdge *>::iterator it = newEdges.begin(); + it != newEdges.end(); ++it) { GEdge *ge = it->second; GModel::current()->remove(ge); // delete ge; } it = tris.begin(); - while(it != tris.end()){ + while(it != tris.end()) { delete *it; ++it; } // delete empty mesh faces and reclasssify - std::set<GFace*, GEntityLessThan> fac = faces; - for(fiter fit = fac.begin() ; fit !=fac.end() ; ++fit){ + std::set<GFace *, GEntityLessThan> fac = faces; + for(fiter fit = fac.begin(); fit != fac.end(); ++fit) { std::set<MVertex *> _verts; (*fit)->mesh_vertices.clear(); - for(unsigned int i = 0; i < (*fit)->triangles.size(); i++){ - for(int j = 0; j < 3; j++){ - if((*fit)->triangles[i]->getVertex(j)->onWhat()->dim() > 1){ + for(unsigned int i = 0; i < (*fit)->triangles.size(); i++) { + for(int j = 0; j < 3; j++) { + if((*fit)->triangles[i]->getVertex(j)->onWhat()->dim() > 1) { (*fit)->triangles[i]->getVertex(j)->setEntity(*fit); _verts.insert((*fit)->triangles[i]->getVertex(j)); } @@ -3208,22 +3275,24 @@ void GModel::computeHomology() domains.insert(it->first); Msg::Info("Number of cell complexes to construct: %d", domains.size()); - for(std::set<dpair>::iterator it = domains.begin(); it != domains.end(); it++){ + for(std::set<dpair>::iterator it = domains.begin(); it != domains.end(); + it++) { std::pair<std::multimap<dpair, tpair>::iterator, - std::multimap<dpair, tpair>::iterator> itp = - _homologyRequests.equal_range(*it); + std::multimap<dpair, tpair>::iterator> + itp = _homologyRequests.equal_range(*it); bool prepareToRestore = (itp.first != --itp.second); itp.second++; std::vector<int> imdomain; - Homology* homology = new Homology(this, itp.first->first.first, - itp.first->first.second, imdomain, - prepareToRestore); + Homology *homology = + new Homology(this, itp.first->first.first, itp.first->first.second, + imdomain, prepareToRestore); for(std::multimap<dpair, tpair>::iterator itt = itp.first; - itt != itp.second; itt++){ + itt != itp.second; itt++) { std::string type = itt->second.first; std::vector<int> dim0 = itt->second.second; - if(dim0.empty()) for(int i = 0; i < getDim(); i++) dim0.push_back(i); + if(dim0.empty()) + for(int i = 0; i < getDim(); i++) dim0.push_back(i); std::vector<int> dim; std::stringstream ss; @@ -3235,7 +3304,8 @@ void GModel::computeHomology() if(type == "Homology") ss << "_"; if(type == "Cohomology") ss << "^"; ss << d; - if(i < dim0.size()-1 && dim0.at(i+1) >=0 && dim0.at(i+1) <= getDim()) + if(i < dim0.size() - 1 && dim0.at(i + 1) >= 0 && + dim0.at(i + 1) <= getDim()) ss << ", "; } } @@ -3245,7 +3315,7 @@ void GModel::computeHomology() Msg::Error("Unknown type of homology computation: %s", type.c_str()); } else if(dim.empty()) { - Msg::Error("Invalid homology computation dimensions given"); + Msg::Error("Invalid homology computation dimensions given"); } else if(type == "Betti") { homology->findBettiNumbers(); diff --git a/Geo/GModelCreateTopologyFromMesh.cpp b/Geo/GModelCreateTopologyFromMesh.cpp index 6dd8c5d03a33c697e8b4724e984ac566fde0d046..49d4414b66dde92de10064cf50c29a998009baec 100644 --- a/Geo/GModelCreateTopologyFromMesh.cpp +++ b/Geo/GModelCreateTopologyFromMesh.cpp @@ -29,78 +29,79 @@ bool topoExists(GModel *gm) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; gm->getEntities(entities); - std::set<MVertex*> vs; - for(unsigned int i = 0; i < entities.size(); i++){ - if (entities[i]->vertices().empty()) return false; + std::set<MVertex *> vs; + for(unsigned int i = 0; i < entities.size(); i++) { + if(entities[i]->vertices().empty()) return false; } return true; } - // FIXME : To TIMES THE SAME MLINE IN EACH CONNECTED PART IF PERIODIC -std::vector<GEdge*> ensureSimplyConnectedEdge(GEdge *ge) +std::vector<GEdge *> ensureSimplyConnectedEdge(GEdge *ge) { - std::vector<GEdge*> _all; - std::set<MLine*> _lines; - std::map<MVertex*, std::pair<MLine*,MLine*> > _conn; + std::vector<GEdge *> _all; + std::set<MLine *> _lines; + std::map<MVertex *, std::pair<MLine *, MLine *> > _conn; _all.push_back(ge); // create vertex to edge connectivity : only To neighbors are considered ... - for (unsigned int i = 0; i < ge->lines.size(); i++){ + for(unsigned int i = 0; i < ge->lines.size(); i++) { _lines.insert(ge->lines[i]); - for (int j=0;j<2;j++){ - std::map<MVertex*, std::pair<MLine*,MLine*> >::iterator it = + for(int j = 0; j < 2; j++) { + std::map<MVertex *, std::pair<MLine *, MLine *> >::iterator it = _conn.find(ge->lines[i]->getVertex(j)); - if (it == _conn.end()) - _conn[ge->lines[i]->getVertex(j)]= std::make_pair (ge->lines[i], (MLine*)NULL); + if(it == _conn.end()) + _conn[ge->lines[i]->getVertex(j)] = + std::make_pair(ge->lines[i], (MLine *)NULL); else - it->second.second = ge->lines[i]; + it->second.second = ge->lines[i]; } } - std::vector <std::vector <MLine*> > _parts; - while (!_lines.empty()){ - std::stack<MLine*> _stack; + std::vector<std::vector<MLine *> > _parts; + while(!_lines.empty()) { + std::stack<MLine *> _stack; _stack.push(*_lines.begin()); - std::vector<MLine*> _part; - while (!_stack.empty()){ + std::vector<MLine *> _part; + while(!_stack.empty()) { MLine *l = _stack.top(); _stack.pop(); - _lines.erase (l); + _lines.erase(l); // avoid adding twice the last one - if (!_part.size() || _part[_part.size() - 1] != l){ + if(!_part.size() || _part[_part.size() - 1] != l) { _part.push_back(l); } - for (int j=0;j<2;j++){ - std::map<MVertex*, std::pair<MLine*,MLine*> >::iterator it = + for(int j = 0; j < 2; j++) { + std::map<MVertex *, std::pair<MLine *, MLine *> >::iterator it = _conn.find(l->getVertex(j)); - if (it->second.first == l && it->second.second != NULL && - _lines.find (it->second.second) != _lines.end()){ - _stack.push (it->second.second); - } - else if (it->second.second == l && - _lines.find (it->second.first) != _lines.end()){ - _stack.push (it->second.first); - } + if(it->second.first == l && it->second.second != NULL && + _lines.find(it->second.second) != _lines.end()) { + _stack.push(it->second.second); + } + else if(it->second.second == l && + _lines.find(it->second.first) != _lines.end()) { + _stack.push(it->second.first); + } } } _parts.push_back(_part); } - if (_parts.size() <= 1) return _all; + if(_parts.size() <= 1) return _all; - Msg::Info ("Edge %d is not simply connected: splitting it in %d parts", - ge->tag(),_parts.size()); + Msg::Info("Edge %d is not simply connected: splitting it in %d parts", + ge->tag(), _parts.size()); - for (size_t i = 0; i < _parts.size() ; i++){ - if (i == 0)ge->lines = _parts[i]; + for(size_t i = 0; i < _parts.size(); i++) { + if(i == 0) + ge->lines = _parts[i]; else { - discreteEdge *newE = new discreteEdge - (ge->model(), ge->model()->getMaxElementaryNumber(1) + 1, NULL, NULL); - ge->model()->add (newE); + discreteEdge *newE = new discreteEdge( + ge->model(), ge->model()->getMaxElementaryNumber(1) + 1, NULL, NULL); + ge->model()->add(newE); newE->lines = _parts[i]; _all.push_back(newE); } @@ -108,116 +109,118 @@ std::vector<GEdge*> ensureSimplyConnectedEdge(GEdge *ge) return _all; } -void assignFace (GFace *gf, std::set<MElement*> &_f) +void assignFace(GFace *gf, std::set<MElement *> &_f) { gf->triangles.clear(); gf->quadrangles.clear(); - for (std::set<MElement*> :: iterator it = _f.begin() ; it != _f.end() ; ++it) { - if ((*it)->getNumVertices () == 3) gf->triangles.push_back ((MTriangle*) *it); - else if ((*it)->getNumVertices () == 4) gf->quadrangles.push_back ((MQuadrangle*) *it); + for(std::set<MElement *>::iterator it = _f.begin(); it != _f.end(); ++it) { + if((*it)->getNumVertices() == 3) + gf->triangles.push_back((MTriangle *)*it); + else if((*it)->getNumVertices() == 4) + gf->quadrangles.push_back((MQuadrangle *)*it); } } void ensureManifoldFace(GFace *gf) { - std::map<MEdge, std::pair<MElement*,MElement*>, Less_Edge > _pairs; - std::set<MEdge,Less_Edge> _nonManifold; + std::map<MEdge, std::pair<MElement *, MElement *>, Less_Edge> _pairs; + std::set<MEdge, Less_Edge> _nonManifold; - std::set<MElement*> _allFaces; + std::set<MElement *> _allFaces; - for (unsigned int i = 0; i < gf->getNumMeshElements(); i++){ + for(unsigned int i = 0; i < gf->getNumMeshElements(); i++) { MElement *e = gf->getMeshElement(i); _allFaces.insert(e); - for (int j = 0; j < e->getNumEdges(); j++){ + for(int j = 0; j < e->getNumEdges(); j++) { MEdge ed = e->getEdge(j); - if (_nonManifold.find (ed) == _nonManifold.end() ){ - std::map<MEdge, std::pair<MElement*,MElement*>, Less_Edge >::iterator it = - _pairs.find (ed); - if (it == _pairs.end()){ - _pairs[ed] = std::make_pair ( e , (MElement*) NULL); - } - else { - if (it->second.second == NULL){ - it->second.second = e; - } - else { - _nonManifold.insert (ed); - _pairs.erase (it); - } - } + if(_nonManifold.find(ed) == _nonManifold.end()) { + std::map<MEdge, std::pair<MElement *, MElement *>, Less_Edge>::iterator + it = _pairs.find(ed); + if(it == _pairs.end()) { + _pairs[ed] = std::make_pair(e, (MElement *)NULL); + } + else { + if(it->second.second == NULL) { + it->second.second = e; + } + else { + _nonManifold.insert(ed); + _pairs.erase(it); + } + } } } } - if (_nonManifold.empty())return; + if(_nonManifold.empty()) return; std::vector<std::set<MElement *> > _sub; - while (!_allFaces.empty()) { - std::stack <MElement*> _stack; - _stack.push (*_allFaces.begin()); - std::set<MElement*> _f; - while (!_stack.empty()){ + while(!_allFaces.empty()) { + std::stack<MElement *> _stack; + _stack.push(*_allFaces.begin()); + std::set<MElement *> _f; + while(!_stack.empty()) { MElement *e = _stack.top(); _allFaces.erase(e); _stack.pop(); - _f.insert (e); - for (int j=0;j<e->getNumEdges();j++){ - MEdge ed = e->getEdge(j); - if (_nonManifold.find (ed) == _nonManifold.end() ){ - std::map<MEdge, std::pair<MElement*,MElement*>, Less_Edge >::iterator it = - _pairs.find (ed); - if (it->second.second != NULL){ - MElement *other = it->second.second == e ? - it->second.first : it->second.second; - if (_f.find (other) == _f.end())_stack.push(other); - } - } + _f.insert(e); + for(int j = 0; j < e->getNumEdges(); j++) { + MEdge ed = e->getEdge(j); + if(_nonManifold.find(ed) == _nonManifold.end()) { + std::map<MEdge, std::pair<MElement *, MElement *>, + Less_Edge>::iterator it = _pairs.find(ed); + if(it->second.second != NULL) { + MElement *other = + it->second.second == e ? it->second.first : it->second.second; + if(_f.find(other) == _f.end()) _stack.push(other); + } + } } } - _sub.push_back (_f); + _sub.push_back(_f); } - Msg::Info ("Face %d is non-manifold: splitting it in %d parts", - gf->tag(), _sub.size()); + Msg::Info("Face %d is non-manifold: splitting it in %d parts", gf->tag(), + _sub.size()); - for (unsigned int i=0 ; i<_sub.size() ; i++){ - if (i == 0) assignFace (gf, _sub[i]); + for(unsigned int i = 0; i < _sub.size(); i++) { + if(i == 0) + assignFace(gf, _sub[i]); else { - discreteFace *newF = new discreteFace - (gf->model(), gf->model()->getMaxElementaryNumber(2) + 1); - gf->model()->add (newF); - assignFace (newF, _sub[i]); + discreteFace *newF = new discreteFace( + gf->model(), gf->model()->getMaxElementaryNumber(2) + 1); + gf->model()->add(newF); + assignFace(newF, _sub[i]); } } } void ensureManifoldFaces(GModel *gm) { - std::vector<GFace*> f; + std::vector<GFace *> f; for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); it++) f.push_back(*it); - for(unsigned int i = 0; i < f.size(); i++) - ensureManifoldFace (f[i]); + for(unsigned int i = 0; i < f.size(); i++) ensureManifoldFace(f[i]); } -typedef std::map<MVertex*,std::set<GEdge*> > MVertexToGEdgesMap; -typedef std::map<MVertex*,GVertex*> MVertexToGVertexMap; -typedef std::map<GEdge*,std::set<GVertex*> > GEdgeToGVerticesMap; -typedef std::map<std::set<GEdge*> , GVertex* > GEdgesToGVertexMap; +typedef std::map<MVertex *, std::set<GEdge *> > MVertexToGEdgesMap; +typedef std::map<MVertex *, GVertex *> MVertexToGVertexMap; +typedef std::map<GEdge *, std::set<GVertex *> > GEdgeToGVerticesMap; +typedef std::map<std::set<GEdge *>, GVertex *> GEdgesToGVertexMap; void createTopologyFromMesh1D(GModel *gm, int &num) { - // list all existing GVertex MVertexToGVertexMap mVertexToGVertex; for(GModel::viter it = gm->firstVertex(); it != gm->lastVertex(); it++) { - GVertex* gv = *it; - if (gv->mesh_vertices.size()) { - MVertex* mv = gv->mesh_vertices[0]; + GVertex *gv = *it; + if(gv->mesh_vertices.size()) { + MVertex *mv = gv->mesh_vertices[0]; mVertexToGVertex[mv] = gv; - Msg::Info("The mesh contains already topological vertex %i containing vertex %i", - gv->tag(),mv->getNum()); + Msg::Info( + "The mesh contains already topological vertex %i containing vertex %i", + gv->tag(), mv->getNum()); } } @@ -228,14 +231,16 @@ void createTopologyFromMesh1D(GModel *gm, int &num) GEdgeToGVerticesMap gEdgeToGVertices; for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); it++) { - GEdge* ge = *it; - for (unsigned int i=0;i<(*it)->lines.size();i++){ + GEdge *ge = *it; + for(unsigned int i = 0; i < (*it)->lines.size(); i++) { MLine *e = (*it)->lines[i]; - for (int j=0;j<2;j++){ - MVertex* mv = e->getVertex(j); + for(int j = 0; j < 2; j++) { + MVertex *mv = e->getVertex(j); MVertexToGVertexMap::iterator gIter = mVertexToGVertex.find(mv); - if (gIter != mVertexToGVertex.end()) gEdgeToGVertices[ge].insert(gIter->second); - else mVertexToGEdges[mv].insert(ge); + if(gIter != mVertexToGVertex.end()) + gEdgeToGVertices[ge].insert(gIter->second); + else + mVertexToGEdges[mv].insert(ge); } } } @@ -244,19 +249,17 @@ void createTopologyFromMesh1D(GModel *gm, int &num) GEdgesToGVertexMap gEdgesToGVertex; - for (MVertexToGEdgesMap::iterator mvIter=mVertexToGEdges.begin(); - mvIter!=mVertexToGEdges.end();++mvIter) { - - MVertex* mv = mvIter->first; - std::set<GEdge*>& gEdges = mvIter->second; - - if (gEdges.size() > 1) { + for(MVertexToGEdgesMap::iterator mvIter = mVertexToGEdges.begin(); + mvIter != mVertexToGEdges.end(); ++mvIter) { + MVertex *mv = mvIter->first; + std::set<GEdge *> &gEdges = mvIter->second; - - if (gEdgesToGVertex.find(gEdges) == gEdgesToGVertex.end()) { + if(gEdges.size() > 1) { + if(gEdgesToGVertex.find(gEdges) == gEdgesToGVertex.end()) { num++; - discreteVertex *dv = new discreteVertex(gm, gm->getMaxElementaryNumber(0) + 1); + discreteVertex *dv = + new discreteVertex(gm, gm->getMaxElementaryNumber(0) + 1); gm->add(dv); mVertexToGVertex[mv] = dv; @@ -266,8 +269,9 @@ void createTopologyFromMesh1D(GModel *gm, int &num) gEdgesToGVertex[gEdges] = dv; - for (std::set<GEdge*>::iterator gEIter = gEdges.begin();gEIter!=gEdges.end();++gEIter) { - GEdge* ge = *gEIter; + for(std::set<GEdge *>::iterator gEIter = gEdges.begin(); + gEIter != gEdges.end(); ++gEIter) { + GEdge *ge = *gEIter; gEdgeToGVertices[ge].insert(dv); } } @@ -277,16 +281,14 @@ void createTopologyFromMesh1D(GModel *gm, int &num) // link all GEdge to GVertex and vice versa // we expect to see two GVertex per GEdge - for (GEdgeToGVerticesMap::iterator gEIter = gEdgeToGVertices.begin(); - gEIter != gEdgeToGVertices.end();++gEIter) { - - GEdge* ge = gEIter->first; - std::set<GVertex*> gVerts = gEIter->second; - - if (gVerts.size() == 2) { + for(GEdgeToGVerticesMap::iterator gEIter = gEdgeToGVertices.begin(); + gEIter != gEdgeToGVertices.end(); ++gEIter) { + GEdge *ge = gEIter->first; + std::set<GVertex *> gVerts = gEIter->second; - GVertex* gv1 = *(gVerts.begin()); - GVertex* gv2 = *(gVerts.rbegin()); + if(gVerts.size() == 2) { + GVertex *gv1 = *(gVerts.begin()); + GVertex *gv2 = *(gVerts.rbegin()); ge->setBeginVertex(gv1); ge->setEndVertex(gv2); @@ -296,18 +298,17 @@ void createTopologyFromMesh1D(GModel *gm, int &num) } else { + std::vector<GEdge *> splits = ensureSimplyConnectedEdge(ge); - std::vector<GEdge*> splits = ensureSimplyConnectedEdge(ge); - - if (splits.size() == 1) { - + if(splits.size() == 1) { std::ostringstream gVertexList; - for (std::set<GVertex*>::iterator gvIter=gVerts.begin();gvIter!=gVerts.end();++gvIter){ + for(std::set<GVertex *>::iterator gvIter = gVerts.begin(); + gvIter != gVerts.end(); ++gvIter) { gVertexList << " " << (*gvIter)->tag(); } - Msg::Error("Found single/multiply ended GEdge %i in model (GVertices:%s)", - ge->tag(),gVertexList.str().c_str()); - + Msg::Error( + "Found single/multiply ended GEdge %i in model (GVertices:%s)", + ge->tag(), gVertexList.str().c_str()); } } } @@ -316,14 +317,15 @@ void createTopologyFromMesh1D(GModel *gm, int &num) // we still need to check this is actually the case ... for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); it++) { - if (!(*it)->getBeginVertex() && !(*it)->getEndVertex()){ + if(!(*it)->getBeginVertex() && !(*it)->getEndVertex()) { num++; - discreteVertex *dv = new discreteVertex(gm, gm->getMaxElementaryNumber(0) + 1); + discreteVertex *dv = + new discreteVertex(gm, gm->getMaxElementaryNumber(0) + 1); gm->add(dv); MVertex *v = (*it)->lines[0]->getVertex(0); MPoint *mp = new MPoint(v); dv->points.push_back(mp); - dv->addEdge (*it); + dv->addEdge(*it); (*it)->setBeginVertex(dv); (*it)->setEndVertex(dv); gEdgeToGVertices[*it].insert(dv); @@ -332,30 +334,21 @@ void createTopologyFromMesh1D(GModel *gm, int &num) } class topoEdge { - protected: - - MElement* parent; + MElement *parent; int edgeIndex; - std::pair<int,int> ids; + std::pair<int, int> ids; public: + const MElement *getParent() const { return parent; } + const int getIndex() const { return edgeIndex; } + const int getType() const { return TYPE_LIN; } - const MElement* getParent() const {return parent;} - const int getIndex() const {return edgeIndex;} - const int getType() const {return TYPE_LIN;} + inline bool operator==(const topoEdge &f) const { return ids == f.ids; } + inline bool operator<(const topoEdge &f) const { return ids < f.ids; } - inline bool operator == (const topoEdge &f) const - { - return ids == f.ids; - } - inline bool operator < (const topoEdge &f) const + topoEdge(MElement *elt, int num) { - return ids < f.ids; - } - - topoEdge (MElement* elt,int num) { - parent = elt; edgeIndex = num; MEdge edge = elt->getEdge(num); @@ -363,31 +356,28 @@ public: int id0 = edge.getVertex(0)->getNum(); int id1 = edge.getVertex(1)->getNum(); - if (id0 > id1) std::swap(id0,id1); + if(id0 > id1) std::swap(id0, id1); ids.first = id0; ids.second = id1; - } }; -typedef std::map<topoEdge,std::set<GFace*> > TEdgeToGFacesMap; -typedef std::map<topoEdge,GEdge* > TEdgeToGEdgeMap; -typedef std::map<GFace*,std::set<GEdge*> > GFaceToGEdgesMap; -typedef std::map<std::set<GFace*>,GEdge* > GFacesToGEdgeMap; +typedef std::map<topoEdge, std::set<GFace *> > TEdgeToGFacesMap; +typedef std::map<topoEdge, GEdge *> TEdgeToGEdgeMap; +typedef std::map<GFace *, std::set<GEdge *> > GFaceToGEdgesMap; +typedef std::map<std::set<GFace *>, GEdge *> GFacesToGEdgeMap; void createTopologyFromMesh2D(GModel *gm, int &num) { - - // create an inverse dictionnary for existing edges TEdgeToGEdgeMap tEdgeToGEdge; for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); it++) { - GEdge* ge = *it; - for (unsigned int i = 0; i < (*it)->lines.size(); i++) { - topoEdge te(ge->lines[i],0); + GEdge *ge = *it; + for(unsigned int i = 0; i < (*it)->lines.size(); i++) { + topoEdge te(ge->lines[i], 0); tEdgeToGEdge[te] = ge; } } @@ -398,43 +388,44 @@ void createTopologyFromMesh2D(GModel *gm, int &num) GFaceToGEdgesMap gFaceToGEdges; for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); it++) { - GFace* gf = *it; - for (unsigned int i=0;i<(*it)->getNumMeshElements();i++){ + GFace *gf = *it; + for(unsigned int i = 0; i < (*it)->getNumMeshElements(); i++) { MElement *e = (*it)->getMeshElement(i); - if (e->getDim() == 2) { - for (int j=0;j<e->getNumEdges();j++){ - topoEdge te(e,j); + if(e->getDim() == 2) { + for(int j = 0; j < e->getNumEdges(); j++) { + topoEdge te(e, j); TEdgeToGEdgeMap::iterator eIter = tEdgeToGEdge.find(te); - if (eIter != tEdgeToGEdge.end()) gFaceToGEdges[gf].insert(eIter->second); - else tEdgeToGFaces[te].insert(gf); + if(eIter != tEdgeToGEdge.end()) + gFaceToGEdges[gf].insert(eIter->second); + else + tEdgeToGFaces[te].insert(gf); } } } } - // create a GEdge for each face boundary, ie. for which edges have been visited once - + // create a GEdge for each face boundary, ie. for which edges have been + // visited once // create a GEdge for each bundle of GFaces GFacesToGEdgeMap gFacesToGEdge; TEdgeToGFacesMap::iterator it; - for (it = tEdgeToGFaces.begin();it!=tEdgeToGFaces.end();++it) { - - std::set<GFace*>& gfaces = it->second; - - if (gfaces.size() > 1) { + for(it = tEdgeToGFaces.begin(); it != tEdgeToGFaces.end(); ++it) { + std::set<GFace *> &gfaces = it->second; + if(gfaces.size() > 1) { GFacesToGEdgeMap::iterator gfIter = gFacesToGEdge.find(gfaces); - if (gfIter == gFacesToGEdge.end()) { - - discreteEdge *de = new discreteEdge(gm,gm->getMaxElementaryNumber(1)+1,NULL,NULL); + if(gfIter == gFacesToGEdge.end()) { + discreteEdge *de = + new discreteEdge(gm, gm->getMaxElementaryNumber(1) + 1, NULL, NULL); num++; gm->add(de); - std::set<GFace*>::iterator gfIter = gfaces.begin(); - for (;gfIter!=gfaces.end();++gfIter) gFaceToGEdges[*gfIter].insert(de); + std::set<GFace *>::iterator gfIter = gfaces.begin(); + for(; gfIter != gfaces.end(); ++gfIter) + gFaceToGEdges[*gfIter].insert(de); gFacesToGEdge[gfaces] = de; } } @@ -444,141 +435,131 @@ void createTopologyFromMesh2D(GModel *gm, int &num) MElementFactory eltFactory; - for (it = tEdgeToGFaces.begin();it!=tEdgeToGFaces.end();++it) { - - const topoEdge& te = it->first; - std::set<GFace*>& gfaces = it->second; + for(it = tEdgeToGFaces.begin(); it != tEdgeToGFaces.end(); ++it) { + const topoEdge &te = it->first; + std::set<GFace *> &gfaces = it->second; GFacesToGEdgeMap::iterator gfIter = gFacesToGEdge.find(gfaces); - if (gfIter != gFacesToGEdge.end()) { + if(gfIter != gFacesToGEdge.end()) { + GEdge *ge = gfIter->second; - GEdge* ge = gfIter->second; - - const MElement* parent = te.getParent(); + const MElement *parent = te.getParent(); int edgeIndex = te.getIndex(); - std::vector<MVertex*> vtcs; - parent->getEdgeVertices(edgeIndex,vtcs); + std::vector<MVertex *> vtcs; + parent->getEdgeVertices(edgeIndex, vtcs); int type = te.getType(); int order = parent->getPolynomialOrder(); bool serendipity = parent->getIsOnlySerendipity(); - int tag = ElementType::getType(type,order,serendipity); + int tag = ElementType::getType(type, order, serendipity); - MLine* edge = dynamic_cast<MLine*> (eltFactory.create(tag,vtcs)); + MLine *edge = dynamic_cast<MLine *>(eltFactory.create(tag, vtcs)); ge->lines.push_back(edge); } } - std::map<GEdge*, std::vector<GEdge*> > splitEdge; + std::map<GEdge *, std::vector<GEdge *> > splitEdge; for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); it++) { - std::vector<GEdge*> split = ensureSimplyConnectedEdge (*it); - if (split.size() != 1) splitEdge[*it] = split; + std::vector<GEdge *> split = ensureSimplyConnectedEdge(*it); + if(split.size() != 1) splitEdge[*it] = split; } GFaceToGEdgesMap::iterator gfToge; // add split edges to face map - for (gfToge = gFaceToGEdges.begin();gfToge!=gFaceToGEdges.end();++gfToge) { - std::set<GEdge*>& edgeSet = gfToge->second; - std::set<GEdge*> newEdgeSet; - std::set<GEdge*>::iterator eIter = edgeSet.begin(); - for (;eIter!=edgeSet.end();++eIter) { - std::map<GEdge*,std::vector<GEdge*> >::iterator pIter = splitEdge.find(*eIter); - if (pIter!=splitEdge.end()) { - std::vector<GEdge*>& edges = pIter->second; - newEdgeSet.insert(edges.begin(),edges.end()); + for(gfToge = gFaceToGEdges.begin(); gfToge != gFaceToGEdges.end(); ++gfToge) { + std::set<GEdge *> &edgeSet = gfToge->second; + std::set<GEdge *> newEdgeSet; + std::set<GEdge *>::iterator eIter = edgeSet.begin(); + for(; eIter != edgeSet.end(); ++eIter) { + std::map<GEdge *, std::vector<GEdge *> >::iterator pIter = + splitEdge.find(*eIter); + if(pIter != splitEdge.end()) { + std::vector<GEdge *> &edges = pIter->second; + newEdgeSet.insert(edges.begin(), edges.end()); } } - edgeSet.insert(newEdgeSet.begin(),newEdgeSet.end()); + edgeSet.insert(newEdgeSet.begin(), newEdgeSet.end()); } // connect GEdges and GFaces - for (gfToge = gFaceToGEdges.begin();gfToge!=gFaceToGEdges.end();++gfToge) { - - GFace* gf = gfToge->first; - std::set<GEdge*>& gEdgeSet = gfToge->second; + for(gfToge = gFaceToGEdges.begin(); gfToge != gFaceToGEdges.end(); ++gfToge) { + GFace *gf = gfToge->first; + std::set<GEdge *> &gEdgeSet = gfToge->second; - std::vector<GEdge*> gEdges; - gEdges.insert(gEdges.begin(),gEdgeSet.begin(),gEdgeSet.end()); + std::vector<GEdge *> gEdges; + gEdges.insert(gEdges.begin(), gEdgeSet.begin(), gEdgeSet.end()); gf->set(gEdges); - std::set<GEdge*>::iterator eIter = gEdgeSet.begin(); - for (;eIter!=gEdgeSet.end();eIter++) (*eIter)->addFace(gf); + std::set<GEdge *>::iterator eIter = gEdgeSet.begin(); + for(; eIter != gEdgeSet.end(); eIter++) (*eIter)->addFace(gf); } } class topoFace { - protected: - - MElement* parent; + MElement *parent; int faceIndex; std::set<int> vtcs; public: + const std::set<int> &getVertices() const { return vtcs; } - const std::set<int>& getVertices() const {return vtcs;} - - const MElement* getParent() const {return parent;} - const int getIndex() const {return faceIndex;} - const int getType() const { - switch (vtcs.size()) { - case 3: - return TYPE_TRI; - break; - case 4: - return TYPE_QUA; - break; - default: - return vtcs.size() > 4 ? TYPE_POLYG : -1; - break; + const MElement *getParent() const { return parent; } + const int getIndex() const { return faceIndex; } + const int getType() const + { + switch(vtcs.size()) { + case 3: return TYPE_TRI; break; + case 4: return TYPE_QUA; break; + default: return vtcs.size() > 4 ? TYPE_POLYG : -1; break; } } - inline bool operator == (const topoFace &f) const {return vtcs == f.vtcs;} - inline bool operator < (const topoFace &f) const {return vtcs < f.vtcs;} - - topoFace (MElement* elt,int num) { + inline bool operator==(const topoFace &f) const { return vtcs == f.vtcs; } + inline bool operator<(const topoFace &f) const { return vtcs < f.vtcs; } + topoFace(MElement *elt, int num) + { parent = elt; faceIndex = num; - std::vector<MVertex*> tmp; + std::vector<MVertex *> tmp; MFace face = elt->getFace(num); - for (std::size_t i=0;i<face.getNumVertices();i++) { + for(std::size_t i = 0; i < face.getNumVertices(); i++) { vtcs.insert(face.getVertex(i)->getNum()); } } }; -typedef std::map<topoFace,GFace*> TFaceToGFaceMap; -typedef std::map<topoFace,std::pair<GRegion*,GRegion*> > TFaceToGRegionPairMap; -typedef std::map<GRegion*, std::set<GFace*> > GRegionToGFacesMap; -typedef std::set<std::pair<GRegion*,GRegion*> > GRegionPairSet; -typedef std::map<std::pair<GRegion*,GRegion*>,GFace *> GRegionPairToGFaceMap; +typedef std::map<topoFace, GFace *> TFaceToGFaceMap; +typedef std::map<topoFace, std::pair<GRegion *, GRegion *> > + TFaceToGRegionPairMap; +typedef std::map<GRegion *, std::set<GFace *> > GRegionToGFacesMap; +typedef std::set<std::pair<GRegion *, GRegion *> > GRegionPairSet; +typedef std::map<std::pair<GRegion *, GRegion *>, GFace *> + GRegionPairToGFaceMap; void createTopologyFromMesh3D(GModel *gm, int &num) { - // create an inverse dictionary for existing faces - TFaceToGFaceMap tFaceToGFace; + TFaceToGFaceMap tFaceToGFace; for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); it++) { - - for (unsigned i=0; i<(*it)->triangles.size();i++) { - topoFace tf((*it)->triangles[i],0); - tFaceToGFace.insert(std::make_pair(tf,*it)); + for(unsigned i = 0; i < (*it)->triangles.size(); i++) { + topoFace tf((*it)->triangles[i], 0); + tFaceToGFace.insert(std::make_pair(tf, *it)); } - for (unsigned i=0; i<(*it)->quadrangles.size(); i++) { - topoFace tf((*it)->quadrangles[i],0); - tFaceToGFace.insert(std::make_pair(tf,*it)); + for(unsigned i = 0; i < (*it)->quadrangles.size(); i++) { + topoFace tf((*it)->quadrangles[i], 0); + tFaceToGFace.insert(std::make_pair(tf, *it)); } } @@ -586,22 +567,24 @@ void createTopologyFromMesh3D(GModel *gm, int &num) // This is the most time consuming part ! TFaceToGRegionPairMap tFaceToGRegionPair; - GRegionToGFacesMap gRegionToGFaces; + GRegionToGFacesMap gRegionToGFaces; for(GModel::riter it = gm->firstRegion(); it != gm->lastRegion(); it++) { - GRegion* gr = *it; - for (unsigned i=0;i<gr->getNumMeshElements();i++){ + GRegion *gr = *it; + for(unsigned i = 0; i < gr->getNumMeshElements(); i++) { MElement *e = gr->getMeshElement(i); - for (int j=0;j<e->getNumFaces();j++){ - topoFace f(e,j); + for(int j = 0; j < e->getNumFaces(); j++) { + topoFace f(e, j); TFaceToGFaceMap::iterator ffIter = tFaceToGFace.find(f); - if (ffIter != tFaceToGFace.end()) gRegionToGFaces[gr].insert(ffIter->second); - else { + if(ffIter != tFaceToGFace.end()) + gRegionToGFaces[gr].insert(ffIter->second); + else { TFaceToGRegionPairMap::iterator frIter = tFaceToGRegionPair.find(f); - if (frIter == tFaceToGRegionPair.end()) { - tFaceToGRegionPair[f] = std::make_pair((GRegion*) NULL,*it); + if(frIter == tFaceToGRegionPair.end()) { + tFaceToGRegionPair[f] = std::make_pair((GRegion *)NULL, *it); } - else frIter->second.first = gr; + else + frIter->second.first = gr; } } } @@ -612,29 +595,30 @@ void createTopologyFromMesh3D(GModel *gm, int &num) GRegionPairToGFaceMap gRegionPairToGFace; TFaceToGRegionPairMap::iterator it = tFaceToGRegionPair.begin(); - for (;it!=tFaceToGRegionPair.end();++it) { - GRegion* r1 = it->second.first; - GRegion* r2 = it->second.second; + for(; it != tFaceToGRegionPair.end(); ++it) { + GRegion *r1 = it->second.first; + GRegion *r2 = it->second.second; - if (!r1) { - const std::set<int>& vtx = it->first.getVertices(); + if(!r1) { + const std::set<int> &vtx = it->first.getVertices(); std::ostringstream faceVtcs; - std::set<int>::const_iterator vIt=vtx.begin(); - for (;vIt!=vtx.end();++vIt) faceVtcs << " " << *vIt; + std::set<int>::const_iterator vIt = vtx.begin(); + for(; vIt != vtx.end(); ++vIt) faceVtcs << " " << *vIt; Msg::Error("Could not find pair of regions for face %s", faceVtcs.str().c_str()); - } - else if (r1 != r2) { - - std::pair<GRegion*,GRegion*> gRegionPair(std::min(r1,r2),std::max(r1,r2)); + else if(r1 != r2) { + std::pair<GRegion *, GRegion *> gRegionPair(std::min(r1, r2), + std::max(r1, r2)); - GRegionPairToGFaceMap::iterator iter = gRegionPairToGFace.find(gRegionPair); - if (iter == gRegionPairToGFace.end()) { - discreteFace *df = new discreteFace(gm, gm->getMaxElementaryNumber(2) + 1); + GRegionPairToGFaceMap::iterator iter = + gRegionPairToGFace.find(gRegionPair); + if(iter == gRegionPairToGFace.end()) { + discreteFace *df = + new discreteFace(gm, gm->getMaxElementaryNumber(2) + 1); num++; - gm->add (df); + gm->add(df); gRegionToGFaces[r1].insert(df); gRegionToGFaces[r2].insert(df); gRegionPairToGFace[gRegionPair] = df; @@ -645,33 +629,32 @@ void createTopologyFromMesh3D(GModel *gm, int &num) // create elements on new geometric faces MElementFactory eltFactory; - for (it=tFaceToGRegionPair.begin();it!=tFaceToGRegionPair.end();++it) { - - const topoFace& tf = it->first; - std::pair<GRegion*,GRegion*> grPair = it->second; + for(it = tFaceToGRegionPair.begin(); it != tFaceToGRegionPair.end(); ++it) { + const topoFace &tf = it->first; + std::pair<GRegion *, GRegion *> grPair = it->second; - GRegionPairToGFaceMap::iterator grTogfIter = gRegionPairToGFace.find(grPair); + GRegionPairToGFaceMap::iterator grTogfIter = + gRegionPairToGFace.find(grPair); - if (grTogfIter != gRegionPairToGFace.end()) { + if(grTogfIter != gRegionPairToGFace.end()) { + GFace *gf = grTogfIter->second; - GFace* gf = grTogfIter->second; - - const MElement* parent = tf.getParent(); + const MElement *parent = tf.getParent(); int faceIndex = tf.getIndex(); - std::vector<MVertex*> vtcs; - parent->getFaceVertices(faceIndex,vtcs); + std::vector<MVertex *> vtcs; + parent->getFaceVertices(faceIndex, vtcs); - int type = tf.getType(); - int order = parent->getPolynomialOrder(); + int type = tf.getType(); + int order = parent->getPolynomialOrder(); bool serendipity = parent->getIsOnlySerendipity(); - int tag = ElementType::getType(type,order,serendipity); + int tag = ElementType::getType(type, order, serendipity); - MElement* face = eltFactory.create(tag,vtcs); + MElement *face = eltFactory.create(tag, vtcs); - if (parent->getType() != TYPE_PYR) { - if (type == TYPE_TRI) gf->triangles .push_back((MTriangle*) face); - if (type == TYPE_QUA) gf->quadrangles.push_back((MQuadrangle*) face); + if(parent->getType() != TYPE_PYR) { + if(type == TYPE_TRI) gf->triangles.push_back((MTriangle *)face); + if(type == TYPE_QUA) gf->quadrangles.push_back((MQuadrangle *)face); } } } @@ -679,12 +662,13 @@ void createTopologyFromMesh3D(GModel *gm, int &num) // now connect GFaces to GRegions and vice versa GRegionToGFacesMap::iterator itTo = gRegionToGFaces.begin(); - for (;itTo !=gRegionToGFaces.end();++itTo) { - GRegion* gr = itTo->first; - std::vector<GFace*> faces; - faces.insert (faces.begin(), itTo->second.begin(), itTo->second.end()); + for(; itTo != gRegionToGFaces.end(); ++itTo) { + GRegion *gr = itTo->first; + std::vector<GFace *> faces; + faces.insert(faces.begin(), itTo->second.begin(), itTo->second.end()); gr->set(faces); - for (std::vector<GFace*>::iterator it3 = faces.begin() ; it3 != faces.end() ; ++it3) + for(std::vector<GFace *>::iterator it3 = faces.begin(); it3 != faces.end(); + ++it3) (*it3)->addRegion(itTo->first); } } @@ -693,35 +677,38 @@ void createTopologyFromMesh3D(GModel *gm, int &num) void GModel::createTopologyFromMeshNew() { - const int dim = getDim (); + const int dim = getDim(); double t1 = Cpu(); - if (topoExists (this)) { + if(topoExists(this)) { Msg::Info("Topology exists: createTopoFromMeshNew is a noop"); return; } Msg::Info("createTopologyFromMeshNew --> creating a topology from the mesh"); - int numF=0,numE=0,numV=0; - if (dim >= 3) createTopologyFromMesh3D (this,numF); - else ensureManifoldFaces ( this ); - if (dim >= 2) createTopologyFromMesh2D (this,numE); - if (dim >= 1) createTopologyFromMesh1D (this,numV); + int numF = 0, numE = 0, numV = 0; + if(dim >= 3) + createTopologyFromMesh3D(this, numF); + else + ensureManifoldFaces(this); + if(dim >= 2) createTopologyFromMesh2D(this, numE); + if(dim >= 1) createTopologyFromMesh1D(this, numV); _associateEntityWithMeshVertices(); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - std::set<MVertex*> vs; - for(unsigned int i = 0; i < entities.size(); i++){ - vs.insert (entities[i]->mesh_vertices.begin(), entities[i]->mesh_vertices.end()); + std::set<MVertex *> vs; + for(unsigned int i = 0; i < entities.size(); i++) { + vs.insert(entities[i]->mesh_vertices.begin(), + entities[i]->mesh_vertices.end()); entities[i]->mesh_vertices.clear(); } - std::vector<MVertex*> cc; + std::vector<MVertex *> cc; cc.insert(cc.begin(), vs.begin(), vs.end()); _storeVerticesInEntities(cc); double t2 = Cpu(); - Msg::Info("createTopologyFromMeshNew done in %3.f sec.)",t2-t1); + Msg::Info("createTopologyFromMeshNew done in %3.f sec.)", t2 - t1); } diff --git a/Geo/GModelIO_ACIS.cpp b/Geo/GModelIO_ACIS.cpp index 831cf8acb32f735a21724c864b3981cf25c5ef8e..2a17ed728d07000d238eedac144e71af6a2186f8 100644 --- a/Geo/GModelIO_ACIS.cpp +++ b/Geo/GModelIO_ACIS.cpp @@ -38,66 +38,60 @@ class GMSH_MESH_MANAGER : public MESH_MANAGER { GModel *_gm; GFace *_current; - public: - GMSH_MESH_MANAGER(GModel *gm) - : _gm(gm) - { - } - virtual ~GMSH_MESH_MANAGER() - { - } - virtual void begin_mesh_output(ENTITY *entity, ENTITY *app_ref, ENTITY *format) + +public: + GMSH_MESH_MANAGER(GModel *gm) : _gm(gm) {} + virtual ~GMSH_MESH_MANAGER() {} + virtual void begin_mesh_output(ENTITY *entity, ENTITY *app_ref, + ENTITY *format) { - FACE *acisFace = dynamic_cast<FACE*>(entity); - if (!acisFace) return; - _current = getACISFaceByNativePtr (_gm,acisFace); + FACE *acisFace = dynamic_cast<FACE *>(entity); + if(!acisFace) return; + _current = getACISFaceByNativePtr(_gm, acisFace); } virtual void announce_counts(int npoly, int nnode, int nref) { _current->stl_vertices.resize(nnode); _current->stl_triangles.resize(nref); } - virtual logical need_indexed_polygons() - { - return 1; - } + virtual logical need_indexed_polygons() { return 1; } virtual void announce_indexed_polynode(int ipoly, int i, void *pnode); virtual void *announce_indexed_node(int inode, const SPApar_pos &pos, - const SPAposition &X, const SPAunit_vector &N) + const SPAposition &X, + const SPAunit_vector &N) { - SPoint2 p(pos.u,pos.v); + SPoint2 p(pos.u, pos.v); _current->stl_vertices[inode] = p; // printf("node %d pos %g %g\n",inode,p.x(),p.y()); - return (void*)inode; // bad idea, but... + return (void *)inode; // bad idea, but... } - virtual void announce_indexed_polynode(ENTITY *E, int ipoly, int i, - void *id, const double &edge_tpar, - const SPApar_pos &uv, const SPAposition &iX, - const SPAunit_vector &N) + virtual void announce_indexed_polynode(ENTITY *E, int ipoly, int i, void *id, + const double &edge_tpar, + const SPApar_pos &uv, + const SPAposition &iX, + const SPAunit_vector &N) { } virtual void *announce_indexed_polyedge(int ipoly, int i, void *mate) { return 0; } - virtual void start_indexed_polygon(int polygonIndex,int _polygonNodeCount, - int ishare = -2) - { - } - virtual void announce_indexed_polynode(ENTITY *,int,int,void*) + virtual void start_indexed_polygon(int polygonIndex, int _polygonNodeCount, + int ishare = -2) { } - virtual void end_mesh_output(ENTITY *entity, ENTITY *app_ref,ENTITY *format) + virtual void announce_indexed_polynode(ENTITY *, int, int, void *) {} + virtual void end_mesh_output(ENTITY *entity, ENTITY *app_ref, ENTITY *format) { } - virtual void save_mesh_output(ENTITY *entity,ENTITY *app_ref,ENTITY *format) + virtual void save_mesh_output(ENTITY *entity, ENTITY *app_ref, ENTITY *format) { } }; -void GMSH_MESH_MANAGER::announce_indexed_polynode (int ipoly, int i, void *pnode) +void GMSH_MESH_MANAGER::announce_indexed_polynode(int ipoly, int i, void *pnode) { - _current->stl_triangles[ipoly*3+i] = (int)(long)pnode; + _current->stl_triangles[ipoly * 3 + i] = (int)(long)pnode; } class ACIS_Internals { @@ -106,7 +100,7 @@ public: GMSH_MESH_MANAGER *_mm; ACIS_Internals(GModel *gm); ~ACIS_Internals(); - void loadSAT(std::string fileName, GModel*); + void loadSAT(std::string fileName, GModel *); void addVertices(GModel *gm, ENTITY_LIST &l); void addEdges(GModel *gm, ENTITY_LIST &l); void addFaces(GModel *gm, ENTITY_LIST &l); @@ -114,20 +108,19 @@ public: ACIS_Internals::ACIS_Internals(GModel *gm) { - // put your acis unlock string here... +// put your acis unlock string here... #include "ACISLICENSE.h" spa_unlock_result out = spa_unlock_products(unlock_str); outcome prout = api_start_modeller(0); - if (!prout.ok()){ + if(!prout.ok()) { Msg::Error("Unable to start ACIS"); } - option_header* seam_option = NULL; + option_header *seam_option = NULL; seam_option = find_option("periodic_no_seam"); - if (seam_option != NULL) - seam_option->push(FALSE); + if(seam_option != NULL) seam_option->push(FALSE); api_initialize_booleans(); api_initialize_euler_ops(); @@ -154,53 +147,53 @@ ACIS_Internals::ACIS_Internals(GModel *gm) ACIS_Internals::~ACIS_Internals() { outcome prout = api_stop_modeller(); - if (!prout.ok()){ + if(!prout.ok()) { Msg::Error("Unable to stop ACIS"); } delete _mm; } -void ACIS_Internals::addVertices (GModel *gm, ENTITY_LIST &l) +void ACIS_Internals::addVertices(GModel *gm, ENTITY_LIST &l) { l.init(); ENTITY *e; - while((e = l.next())){ - VERTEX *av = dynamic_cast<VERTEX*>(e); - if (av){ + while((e = l.next())) { + VERTEX *av = dynamic_cast<VERTEX *>(e); + if(av) { GVertex *v = getACISVertexByNativePtr(gm, av); - if (!v) - gm->add(new ACISVertex (gm, gm->getMaxElementaryNumber(0) + 1, av)); + if(!v) gm->add(new ACISVertex(gm, gm->getMaxElementaryNumber(0) + 1, av)); } } } -void ACIS_Internals::addEdges (GModel *gm, ENTITY_LIST &l) +void ACIS_Internals::addEdges(GModel *gm, ENTITY_LIST &l) { l.init(); ENTITY *e; - while((e = l.next())){ - EDGE *av = dynamic_cast<EDGE*>(e); - if (av){ + while((e = l.next())) { + EDGE *av = dynamic_cast<EDGE *>(e); + if(av) { GEdge *v = getACISEdgeByNativePtr(gm, av); - if (!v){ - GVertex *v1 = getACISVertexByNativePtr(gm, av->start()); - GVertex *v2 = getACISVertexByNativePtr(gm, av->end()); - gm->add(new ACISEdge(gm, av, gm->getMaxElementaryNumber(1) + 1, v1, v2)); + if(!v) { + GVertex *v1 = getACISVertexByNativePtr(gm, av->start()); + GVertex *v2 = getACISVertexByNativePtr(gm, av->end()); + gm->add( + new ACISEdge(gm, av, gm->getMaxElementaryNumber(1) + 1, v1, v2)); } } } } -void ACIS_Internals::addFaces (GModel *gm, ENTITY_LIST &l) +void ACIS_Internals::addFaces(GModel *gm, ENTITY_LIST &l) { l.init(); ENTITY *e; - while((e = l.next())){ - FACE *av = dynamic_cast<FACE*>(e); - if (av){ - GFace *v = getACISFaceByNativePtr(gm,av); - if (!v){ - gm->add(new ACISFace(gm, av, gm->getMaxElementaryNumber(2) + 1)); + while((e = l.next())) { + FACE *av = dynamic_cast<FACE *>(e); + if(av) { + GFace *v = getACISFaceByNativePtr(gm, av); + if(!v) { + gm->add(new ACISFace(gm, av, gm->getMaxElementaryNumber(2) + 1)); } } } @@ -208,44 +201,44 @@ void ACIS_Internals::addFaces (GModel *gm, ENTITY_LIST &l) void ACIS_Internals::loadSAT(std::string fileName, GModel *gm) { - FILE *f = Fopen (fileName.c_str(), "r"); - if (!f){ + FILE *f = Fopen(fileName.c_str(), "r"); + if(!f) { return; } - outcome prout = api_restore_entity_list(f,1,entities); - if (!prout.ok()){ - Msg::Error("Unable to load ACIS FILE %d",fileName.c_str()); + outcome prout = api_restore_entity_list(f, 1, entities); + if(!prout.ok()) { + Msg::Error("Unable to load ACIS FILE %d", fileName.c_str()); fclose(f); return; } - Msg::Info("ACIS FILE %d Loaded",fileName.c_str()); + Msg::Info("ACIS FILE %d Loaded", fileName.c_str()); ENTITY *e; entities.init(); - while((e = entities.next())){ + while((e = entities.next())) { // printf("an entity\n"); - if (is_VERTEX(e)){ + if(is_VERTEX(e)) { // printf("VERTEX FOUND\n"); } - if (is_BODY(e)){ + if(is_BODY(e)) { api_split_periodic_faces(e); { - ENTITY_LIST vertex_list; - outcome prout = api_get_vertices (e,vertex_list); - addVertices (gm,vertex_list); - printf("BODY COUNT %d !\n",vertex_list.count()); + ENTITY_LIST vertex_list; + outcome prout = api_get_vertices(e, vertex_list); + addVertices(gm, vertex_list); + printf("BODY COUNT %d !\n", vertex_list.count()); } { - ENTITY_LIST edge_list; - outcome prout = api_get_edges (e,edge_list); - addEdges (gm,edge_list); - printf("BODY COUNT %d !\n",edge_list.count()); + ENTITY_LIST edge_list; + outcome prout = api_get_edges(e, edge_list); + addEdges(gm, edge_list); + printf("BODY COUNT %d !\n", edge_list.count()); } { - ENTITY_LIST face_list; - outcome prout = api_get_faces(e,face_list); - addFaces (gm,face_list); - printf("BODY COUNT %d !\n",face_list.count()); + ENTITY_LIST face_list; + outcome prout = api_get_faces(e, face_list); + addFaces(gm, face_list); + printf("BODY COUNT %d !\n", face_list.count()); } } } @@ -254,7 +247,7 @@ void ACIS_Internals::loadSAT(std::string fileName, GModel *gm) int GModel::readACISSAT(const std::string &fn) { _acis_internals = new ACIS_Internals(this); - _acis_internals->loadSAT(fn,this); + _acis_internals->loadSAT(fn, this); return 1; } diff --git a/Geo/GModelIO_ACTRAN.cpp b/Geo/GModelIO_ACTRAN.cpp index fd10ceb1902b2d0a4aa569d2298880769f78ec17..975b5315fb0552821b54b7c509a814d01da3effe 100644 --- a/Geo/GModelIO_ACTRAN.cpp +++ b/Geo/GModelIO_ACTRAN.cpp @@ -14,11 +14,12 @@ #include "MHexahedron.h" #include "Context.h" -static bool getMeshVertices(GModel *m, int num, int *n, std::vector<MVertex*> &vec) +static bool getMeshVertices(GModel *m, int num, int *n, + std::vector<MVertex *> &vec) { - for(int i = 0; i < num; i++){ + for(int i = 0; i < num; i++) { MVertex *v = m->getMeshVertexByTag(n[i]); - if(!v){ + if(!v) { Msg::Error("Wrong vertex number %d", n[i]); return false; } @@ -31,38 +32,42 @@ static bool getMeshVertices(GModel *m, int num, int *n, std::vector<MVertex*> &v int GModel::readACTRAN(const std::string &name) { FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } char buffer[256]; - if(!fgets(buffer, sizeof(buffer), fp)){ fclose(fp); return 0; } + if(!fgets(buffer, sizeof(buffer), fp)) { + fclose(fp); + return 0; + } - if(strncmp(buffer, "BEGIN ACTRAN", 12)){ + if(strncmp(buffer, "BEGIN ACTRAN", 12)) { Msg::Error("Did not find ACTRAN header"); - fclose(fp); return 0; + fclose(fp); + return 0; } _vertexMapCache.clear(); - std::map<int, std::vector<MElement*> > elements[3]; + std::map<int, std::vector<MElement *> > elements[3]; int nbv = 0, nbe = 0, dim = 0; while(!feof(fp)) { if(!fgets(buffer, 256, fp)) break; char str[256], str2[256]; sscanf(buffer, "%s %s", str, str2); - if(!strcmp(str, "BEGIN") && !strcmp(str2, "MESH")){ + if(!strcmp(str, "BEGIN") && !strcmp(str2, "MESH")) { if(!fgets(buffer, sizeof(buffer), fp)) break; sscanf(buffer, "%d %d %d", &nbv, &nbe, &dim); if(dim == 3 || dim == 2) Msg::Info("ACTRAN mesh dimension %d", dim); - else{ + else { Msg::Error("Cannot read ACTRAN mesh of dimension %d", dim); break; } } - else if(!strcmp(str, "BEGIN") && !strcmp(str2, "NODE")){ + else if(!strcmp(str, "BEGIN") && !strcmp(str2, "NODE")) { Msg::Info("%d vertices", nbv); for(int i = 0; i < nbv; i++) { if(!fgets(buffer, sizeof(buffer), fp)) break; @@ -75,32 +80,31 @@ int GModel::readACTRAN(const std::string &name) _vertexMapCache[num] = new MVertex(x, y, z, 0, num); } } - else if(!strcmp(str, "BEGIN") && !strcmp(str2, "ELEMENT")){ + else if(!strcmp(str, "BEGIN") && !strcmp(str2, "ELEMENT")) { Msg::Info("%d elements", nbe); for(int i = 0; i < nbe; i++) { if(!fgets(buffer, sizeof(buffer), fp)) break; int num, type, reg, n[8]; sscanf(buffer, "%d %d %d", &num, &type, ®); - std::vector<MVertex*> vertices; - if(type == 2){ - sscanf(buffer, "%d %d %d %d %d", &num, &type, ®, - &n[0], &n[1]); + std::vector<MVertex *> vertices; + if(type == 2) { + sscanf(buffer, "%d %d %d %d %d", &num, &type, ®, &n[0], &n[1]); if(!getMeshVertices(this, 2, n, vertices)) break; elements[0][reg].push_back(new MLine(vertices, num)); } - else if(type == 4){ - sscanf(buffer, "%d %d %d %d %d %d", &num, &type, ®, - &n[0], &n[1], &n[2]); + else if(type == 4) { + sscanf(buffer, "%d %d %d %d %d %d", &num, &type, ®, &n[0], &n[1], + &n[2]); if(!getMeshVertices(this, 3, n, vertices)) break; elements[0][reg].push_back(new MTriangle(vertices, num)); } - else if(type == 8){ - sscanf(buffer, "%d %d %d %d %d %d %d", &num, &type, ®, - &n[0], &n[1], &n[2], &n[3]); + else if(type == 8) { + sscanf(buffer, "%d %d %d %d %d %d %d", &num, &type, ®, &n[0], + &n[1], &n[2], &n[3]); if(!getMeshVertices(this, 4, n, vertices)) break; elements[1][reg].push_back(new MTetrahedron(vertices, num)); } - else{ + else { Msg::Error("Unknown type %d for element %d", type, num); } } diff --git a/Geo/GModelIO_BDF.cpp b/Geo/GModelIO_BDF.cpp index e52be1f8ffb40dcdf7bd47fff78fbe88ca14eafb..f367216dc222f5489afe96ca52dc85c38989120f 100644 --- a/Geo/GModelIO_BDF.cpp +++ b/Geo/GModelIO_BDF.cpp @@ -17,19 +17,22 @@ static int getFormatBDF(char *buffer, int &keySize) { - for(unsigned int i = 0; i < strlen(buffer); i++){ - if(buffer[i] == ','){ // free fields - if(buffer[keySize] == '*'){ // will contine on next line + for(unsigned int i = 0; i < strlen(buffer); i++) { + if(buffer[i] == ',') { // free fields + if(buffer[keySize] == '*') { // will contine on next line keySize = i; return -1; } - else{ + else { keySize = i; return 0; } } } - if(buffer[keySize] == '*'){ keySize++; return 2; } // long fields + if(buffer[keySize] == '*') { + keySize++; + return 2; + } // long fields return 1; // small fields; } @@ -37,11 +40,11 @@ static double atofBDF(char *str) { int len = strlen(str); // classic numbers with E or D exponent notation - for(int i = 0; i < len; i++){ + for(int i = 0; i < len; i++) { if(str[i] == 'E' || str[i] == 'e') { return atof(str); } - else if(str[i] == 'D' || str[i] == 'd'){ + else if(str[i] == 'D' || str[i] == 'd') { str[i] = 'E'; return atof(str); } @@ -50,8 +53,8 @@ static double atofBDF(char *str) // "-7.E-01" or "2.3+2" instead of "2.3E+02") char tmp[32]; int j = 0, leading_minus = 1; - for(int i = 0; i < len; i++){ - if(leading_minus && str[i] != ' ' && str[i] != '-') leading_minus = 0; + for(int i = 0; i < len; i++) { + if(leading_minus && str[i] != ' ' && str[i] != '-') leading_minus = 0; if(!leading_minus && str[i] == '-') tmp[j++] = 'E'; if(str[i] == '+') tmp[j++] = 'E'; tmp[j++] = str[i]; @@ -60,23 +63,25 @@ static double atofBDF(char *str) return atof(tmp); } -static int readVertexBDF(FILE *fp, char *buffer, int keySize, - int *num, double *x, double *y, double *z) +static int readVertexBDF(FILE *fp, char *buffer, int keySize, int *num, + double *x, double *y, double *z) { char tmp[5][32]; int format = getFormatBDF(buffer, keySize); int j = keySize; - switch(format){ + switch(format) { case 0: // free field case -1: // free field with continuation - for(int i = 0; i < 5; i++){ + for(int i = 0; i < 5; i++) { tmp[i][16] = '\0'; strncpy(tmp[i], &buffer[j + 1], 16); - for(int k = 0; k < 16; k++){ if(tmp[i][k] == ',') tmp[i][k] = '\0'; } + for(int k = 0; k < 16; k++) { + if(tmp[i][k] == ',') tmp[i][k] = '\0'; + } j++; while(j < (int)strlen(buffer) && buffer[j] != ',') j++; } - if(format == -1){ // continued on next line + if(format == -1) { // continued on next line char buffer2[256]; if(!fgets(buffer2, sizeof(buffer2), fp)) return 0; j = 0; @@ -113,23 +118,24 @@ static int readVertexBDF(FILE *fp, char *buffer, int keySize, static bool emptyFieldBDF(char *field, int length) { for(int i = 0; i < length; i++) - if(field[i] != '\0' && field[i] != ' ' && field[i] != '\n' && field[i] != '\r') + if(field[i] != '\0' && field[i] != ' ' && field[i] != '\n' && + field[i] != '\r') return false; return true; } -static void readLineBDF(char *buffer, int format, std::vector<char*> &fields) +static void readLineBDF(char *buffer, int format, std::vector<char *> &fields) { int cmax = (format == 2) ? 16 : 8; // max char per (center) field int nmax = (format == 2) ? 4 : 8; // max num of (center) fields per line - if(format <= 0){ // free fields - for(unsigned int i = 0; i < strlen(buffer); i++){ + if(format <= 0) { // free fields + for(unsigned int i = 0; i < strlen(buffer); i++) { if(buffer[i] == ',') fields.push_back(&buffer[i + 1]); } } - else{ // small or long fields - for(int i = 0; i < nmax + 1; i++){ + else { // small or long fields + for(int i = 0; i < nmax + 1; i++) { if(!emptyFieldBDF(&buffer[8 + cmax * i], cmax)) fields.push_back(&buffer[8 + cmax * i]); } @@ -137,33 +143,35 @@ static void readLineBDF(char *buffer, int format, std::vector<char*> &fields) } static int readElementBDF(FILE *fp, char *buffer, int keySize, int numVertices, - int &num, int ®ion, std::vector<MVertex*> &vertices, - std::map<int, MVertex*> &vertexMap) + int &num, int ®ion, + std::vector<MVertex *> &vertices, + std::map<int, MVertex *> &vertexMap) { char buffer2[256], buffer3[256]; - std::vector<char*> fields; + std::vector<char *> fields; int format = getFormatBDF(buffer, keySize); - for(unsigned int i = 0; i < sizeof(buffer2); i++) buffer2[i] = buffer3[i] = '\0'; + for(unsigned int i = 0; i < sizeof(buffer2); i++) + buffer2[i] = buffer3[i] = '\0'; readLineBDF(buffer, format, fields); if(((int)fields.size() - 2 < abs(numVertices)) || - (numVertices < 0 && (fields.size() == 9))){ + (numVertices < 0 && (fields.size() == 9))) { if(fields.size() == 9) fields.pop_back(); if(!fgets(buffer2, sizeof(buffer2), fp)) return 0; readLineBDF(buffer2, format, fields); } if(((int)fields.size() - 2 < abs(numVertices)) || - (numVertices < 0 && (fields.size() == 17))){ + (numVertices < 0 && (fields.size() == 17))) { if(fields.size() == 17) fields.pop_back(); if(!fgets(buffer3, sizeof(buffer3), fp)) return 0; readLineBDF(buffer3, format, fields); } // negative 'numVertices' gives the minimum required number of vertices - if((int)fields.size() - 2 < abs(numVertices)){ + if((int)fields.size() - 2 < abs(numVertices)) { Msg::Error("Wrong number of vertices %d for element", fields.size() - 2); return 0; } @@ -171,18 +179,21 @@ static int readElementBDF(FILE *fp, char *buffer, int keySize, int numVertices, int n[30], cmax = (format == 2) ? 16 : 8; // max char per (center) field char tmp[32]; tmp[cmax] = '\0'; - strncpy(tmp, fields[0], cmax); num = atoi(tmp); - strncpy(tmp, fields[1], cmax); region = atoi(tmp); - for(unsigned int i = 2; i < fields.size(); i++){ - strncpy(tmp, fields[i], cmax); n[i - 2] = atoi(tmp); + strncpy(tmp, fields[0], cmax); + num = atoi(tmp); + strncpy(tmp, fields[1], cmax); + region = atoi(tmp); + for(unsigned int i = 2; i < fields.size(); i++) { + strncpy(tmp, fields[i], cmax); + n[i - 2] = atoi(tmp); } // ignore the extra fields when we know how many vertices we need int numCheck = (numVertices > 0) ? numVertices : fields.size() - 2; - for(int i = 0; i < numCheck; i++){ - std::map<int, MVertex*>::iterator it = vertexMap.find(n[i]); - if(it == vertexMap.end()){ + for(int i = 0; i < numCheck; i++) { + std::map<int, MVertex *>::iterator it = vertexMap.find(n[i]); + if(it == vertexMap.end()) { Msg::Error("Wrong vertex index %d", n[i]); return 0; } @@ -194,22 +205,22 @@ static int readElementBDF(FILE *fp, char *buffer, int keySize, int numVertices, int GModel::readBDF(const std::string &name) { FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } char buffer[256]; - std::map<int, MVertex*> vertexMap; - std::map<int, std::vector<MElement*> > elements[7]; + std::map<int, MVertex *> vertexMap; + std::map<int, std::vector<MElement *> > elements[7]; // nodes can be defined after elements, so parse the file twice while(!feof(fp)) { for(unsigned int i = 0; i < sizeof(buffer); i++) buffer[i] = '\0'; if(!fgets(buffer, sizeof(buffer), fp)) break; - if(buffer[0] != '$'){ // skip comments - if(!strncmp(buffer, "GRID", 4)){ + if(buffer[0] != '$') { // skip comments + if(!strncmp(buffer, "GRID", 4)) { int num; double x, y, z; if(!readVertexBDF(fp, buffer, 4, &num, &x, &y, &z)) break; @@ -223,39 +234,40 @@ int GModel::readBDF(const std::string &name) while(!feof(fp)) { for(unsigned int i = 0; i < sizeof(buffer); i++) buffer[i] = '\0'; if(!fgets(buffer, sizeof(buffer), fp)) break; - if(buffer[0] != '$'){ // skip comments + if(buffer[0] != '$') { // skip comments int num, region; - std::vector<MVertex*> vertices; - if(!strncmp(buffer, "CBAR", 4)){ + std::vector<MVertex *> vertices; + if(!strncmp(buffer, "CBAR", 4)) { if(readElementBDF(fp, buffer, 4, 2, num, region, vertices, vertexMap)) elements[0][region].push_back(new MLine(vertices, num)); } - else if(!strncmp(buffer, "CROD", 4)){ + else if(!strncmp(buffer, "CROD", 4)) { if(readElementBDF(fp, buffer, 4, 2, num, region, vertices, vertexMap)) elements[0][region].push_back(new MLine(vertices, num)); } - else if(!strncmp(buffer, "CBEAM", 5)){ + else if(!strncmp(buffer, "CBEAM", 5)) { if(readElementBDF(fp, buffer, 5, 2, num, region, vertices, vertexMap)) elements[0][region].push_back(new MLine(vertices, num)); } - else if(!strncmp(buffer, "CTRIA3", 6)){ + else if(!strncmp(buffer, "CTRIA3", 6)) { if(readElementBDF(fp, buffer, 6, 3, num, region, vertices, vertexMap)) elements[1][region].push_back(new MTriangle(vertices, num)); } - else if(!strncmp(buffer, "CTRIA6", 6)){ + else if(!strncmp(buffer, "CTRIA6", 6)) { if(readElementBDF(fp, buffer, 6, 6, num, region, vertices, vertexMap)) elements[1][region].push_back(new MTriangle6(vertices, num)); } - else if(!strncmp(buffer, "CQUAD4", 6)){ + else if(!strncmp(buffer, "CQUAD4", 6)) { if(readElementBDF(fp, buffer, 6, 4, num, region, vertices, vertexMap)) elements[2][region].push_back(new MQuadrangle(vertices, num)); } - else if(!strncmp(buffer, "CQUAD8", 6)){ + else if(!strncmp(buffer, "CQUAD8", 6)) { if(readElementBDF(fp, buffer, 6, 8, num, region, vertices, vertexMap)) elements[2][region].push_back(new MQuadrangle8(vertices, num)); } - else if(!strncmp(buffer, "CQUAD", 5)){ - if(readElementBDF(fp, buffer, 5, -4, num, region, vertices, vertexMap)){ + else if(!strncmp(buffer, "CQUAD", 5)) { + if(readElementBDF(fp, buffer, 5, -4, num, region, vertices, + vertexMap)) { if(vertices.size() == 9) elements[2][region].push_back(new MQuadrangle9(vertices, num)); else if(vertices.size() == 8) @@ -264,44 +276,46 @@ int GModel::readBDF(const std::string &name) elements[2][region].push_back(new MQuadrangle(vertices, num)); } } - else if(!strncmp(buffer, "CTETRA", 6)){ - if(readElementBDF(fp, buffer, 6, -4, num, region, vertices, vertexMap)){ + else if(!strncmp(buffer, "CTETRA", 6)) { + if(readElementBDF(fp, buffer, 6, -4, num, region, vertices, + vertexMap)) { if(vertices.size() == 10) - elements[3][region].push_back - (new MTetrahedron10(vertices[0], vertices[1], vertices[2], vertices[3], - vertices[4], vertices[5], vertices[6], vertices[7], - vertices[9], vertices[8], num)); + elements[3][region].push_back(new MTetrahedron10( + vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], + vertices[5], vertices[6], vertices[7], vertices[9], vertices[8], + num)); else elements[3][region].push_back(new MTetrahedron(vertices, num)); } } - else if(!strncmp(buffer, "CHEXA", 5)){ - if(readElementBDF(fp, buffer, 5, -8, num, region, vertices, vertexMap)){ + else if(!strncmp(buffer, "CHEXA", 5)) { + if(readElementBDF(fp, buffer, 5, -8, num, region, vertices, + vertexMap)) { if(vertices.size() == 20) - elements[4][region].push_back - (new MHexahedron20(vertices[0], vertices[1], vertices[2], vertices[3], - vertices[4], vertices[5], vertices[6], vertices[7], - vertices[8], vertices[11], vertices[12], vertices[9], - vertices[13], vertices[10], vertices[14], vertices[15], - vertices[16], vertices[19], vertices[17], vertices[18], - num)); + elements[4][region].push_back(new MHexahedron20( + vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], + vertices[5], vertices[6], vertices[7], vertices[8], vertices[11], + vertices[12], vertices[9], vertices[13], vertices[10], + vertices[14], vertices[15], vertices[16], vertices[19], + vertices[17], vertices[18], num)); else elements[4][region].push_back(new MHexahedron(vertices, num)); } } - else if(!strncmp(buffer, "CPENTA", 6)){ - if(readElementBDF(fp, buffer, 6, -6, num, region, vertices, vertexMap)){ + else if(!strncmp(buffer, "CPENTA", 6)) { + if(readElementBDF(fp, buffer, 6, -6, num, region, vertices, + vertexMap)) { if(vertices.size() == 15) - elements[5][region].push_back - (new MPrism15(vertices[0], vertices[1], vertices[2], vertices[3], - vertices[4], vertices[5], vertices[6], vertices[8], - vertices[9], vertices[7], vertices[10], vertices[11], - vertices[12], vertices[14], vertices[13], num)); + elements[5][region].push_back( + new MPrism15(vertices[0], vertices[1], vertices[2], vertices[3], + vertices[4], vertices[5], vertices[6], vertices[8], + vertices[9], vertices[7], vertices[10], vertices[11], + vertices[12], vertices[14], vertices[13], num)); else elements[5][region].push_back(new MPrism(vertices, num)); } } - else if(!strncmp(buffer, "CPYRAM", 6)){ + else if(!strncmp(buffer, "CPYRAM", 6)) { if(readElementBDF(fp, buffer, 6, 5, num, region, vertices, vertexMap)) elements[6][region].push_back(new MPyramid(vertices, num)); } @@ -321,7 +335,7 @@ int GModel::writeBDF(const std::string &name, int format, int elementTagType, bool saveAll, double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -332,7 +346,7 @@ int GModel::writeBDF(const std::string &name, int format, int elementTagType, fprintf(fp, "$ Created by Gmsh\n"); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); // nodes @@ -342,12 +356,12 @@ int GModel::writeBDF(const std::string &name, int format, int elementTagType, // elements for(unsigned int i = 0; i < entities.size(); i++) - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { int numPhys = entities[i]->physicals.size(); if(saveAll || numPhys) - entities[i]->getMeshElement(j)->writeBDF - (fp, format, elementTagType, entities[i]->tag(), - numPhys ? entities[i]->physicals[0] : 0); + entities[i]->getMeshElement(j)->writeBDF( + fp, format, elementTagType, entities[i]->tag(), + numPhys ? entities[i]->physicals[0] : 0); } fprintf(fp, "ENDDATA\n"); diff --git a/Geo/GModelIO_CELUM.cpp b/Geo/GModelIO_CELUM.cpp index f895dc9e50cd309022a5efd368de591ac3c2898e..56a2b475c458bf5b00ca9a06615856b04eac7b74 100644 --- a/Geo/GModelIO_CELUM.cpp +++ b/Geo/GModelIO_CELUM.cpp @@ -8,7 +8,7 @@ #include "MTriangle.h" #include "MQuadrangle.h" -class CelumInfo{ +class CelumInfo { public: SVector3 normal, dirMax, dirMin; double curvMax, curvMin; @@ -19,14 +19,14 @@ int GModel::writeCELUM(const std::string &name, bool saveAll, { std::string namef = name + "_f"; FILE *fpf = Fopen(namef.c_str(), "w"); - if(!fpf){ + if(!fpf) { Msg::Error("Unable to open file '%s'", namef.c_str()); return 0; } std::string names = name + "_s"; FILE *fps = Fopen(names.c_str(), "w"); - if(!fps){ + if(!fps) { Msg::Error("Unable to open file '%s'", names.c_str()); fclose(fpf); return 0; @@ -37,14 +37,13 @@ int GModel::writeCELUM(const std::string &name, bool saveAll, // count faces and vertices; the CELUM format duplicates vertices on the // boundary of CAD patches int numf = 0, nums = 0; - for(fiter it = firstFace(); it != lastFace(); it++){ + for(fiter it = firstFace(); it != lastFace(); it++) { GFace *f = *it; if(!saveAll && f->physicals.empty()) continue; numf += f->triangles.size(); - std::set<MVertex*> vset; - for(unsigned int i = 0; i < f->triangles.size(); i++){ - for(int j = 0; j < 3; j++) - vset.insert(f->triangles[i]->getVertex(j)); + std::set<MVertex *> vset; + for(unsigned int i = 0; i < f->triangles.size(); i++) { + for(int j = 0; j < 3; j++) vset.insert(f->triangles[i]->getVertex(j)); } nums += vset.size(); } @@ -79,16 +78,16 @@ int GModel::writeCELUM(const std::string &name, bool saveAll, */ fprintf(fpf, "%d\n\n", numf); fprintf(fps, "%d %g\n\n", nums, 1.0); - for(fiter it = firstFace(); it != lastFace(); it++){ + for(fiter it = firstFace(); it != lastFace(); it++) { GFace *f = *it; if(!saveAll && f->physicals.empty()) continue; - std::vector<MVertex*> vvec; - std::map<MVertex*, CelumInfo> vmap; - for(unsigned int i = 0; i < f->triangles.size(); i++){ + std::vector<MVertex *> vvec; + std::map<MVertex *, CelumInfo> vmap; + for(unsigned int i = 0; i < f->triangles.size(); i++) { fprintf(fpf, "%d \"face %d\"", idf++, f->tag()); - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { MVertex *v = f->triangles[i]->getVertex(j); - if(!vmap.count(v)){ + if(!vmap.count(v)) { v->setIndex(ids++); SPoint2 param; bool ok = reparamMeshVertexOnFace(v, f, param); @@ -97,8 +96,8 @@ int GModel::writeCELUM(const std::string &name, bool saveAll, v->getNum(), f->tag()); CelumInfo info; info.normal = f->normal(param); - f->curvatures(param, info.dirMax, info.dirMin, - info.curvMax, info.curvMin); + f->curvatures(param, info.dirMax, info.dirMin, info.curvMax, + info.curvMin); vmap[v] = info; vvec.push_back(v); } @@ -106,15 +105,16 @@ int GModel::writeCELUM(const std::string &name, bool saveAll, } fprintf(fpf, "\n\n"); } - for(unsigned int i = 0; i < vvec.size(); i++){ + for(unsigned int i = 0; i < vvec.size(); i++) { MVertex *v = vvec[i]; std::map<MVertex *, CelumInfo>::iterator it = vmap.find(v); fprintf(fps, "%d %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n\n", - it->first->getIndex(), it->first->x(), it->first->y(), it->first->z(), - it->second.normal.x(), it->second.normal.y(), + it->first->getIndex(), it->first->x(), it->first->y(), + it->first->z(), it->second.normal.x(), it->second.normal.y(), it->second.normal.z(), it->second.curvMin, it->second.curvMax, - it->second.dirMin.x(), it->second.dirMin.y(), it->second.dirMin.z(), - it->second.dirMax.x(), it->second.dirMax.y(), it->second.dirMax.z()); + it->second.dirMin.x(), it->second.dirMin.y(), + it->second.dirMin.z(), it->second.dirMax.x(), + it->second.dirMax.y(), it->second.dirMax.z()); } } diff --git a/Geo/GModelIO_CGNS.cpp b/Geo/GModelIO_CGNS.cpp index 6612edbc47e71521f3d7c28c3fc0bcc16f619754..fcaed8a967f1d855e364a8aaf47fe8982041588e 100644 --- a/Geo/GModelIO_CGNS.cpp +++ b/Geo/GModelIO_CGNS.cpp @@ -63,19 +63,20 @@ using namespace CGNS; #define maxLenCGNS 32 -// --- encoding the CGNS element conventions, implementation in cgnsConventions.cpp +// --- encoding the CGNS element conventions, implementation in +// cgnsConventions.cpp // get gmsh parent tag -extern int parentFromCGNSType(ElementType_t cgnsType); +extern int parentFromCGNSType(ElementType_t cgnsType); // get mapping order -extern int orderFromCGNSType (ElementType_t cgnsType); +extern int orderFromCGNSType(ElementType_t cgnsType); // is the element complete ? -extern bool completeCGNSType (ElementType_t cgnsType); +extern bool completeCGNSType(ElementType_t cgnsType); // get the gmsh tag for this element type -extern int tagFromCGNSType (ElementType_t cgnsType); +extern int tagFromCGNSType(ElementType_t cgnsType); // get the dimension for a grid location extern int gridLocationDimCGNS(GridLocation_t location); @@ -93,7 +94,7 @@ extern GridLocation_t unstructuredGridLocationCGNS(int d); // generate the index renumbering from cgns to gmsh control points // equidistant corresponds to gmsh/equidistant, else strict cgns standard // will fail in case non-equidistant points are used (NULL pointer). -extern int* getRenumberingToGmsh(ElementType_t); +extern int *getRenumberingToGmsh(ElementType_t); extern fullMatrix<double> getTransformationToGmsh(ElementType_t); //--Error function for the CGNS library @@ -109,8 +110,8 @@ int cgnsErr(const int cgIndexFile = -1) // --- read length scale in the file -double readCGNSScale() { - +double readCGNSScale() +{ double scale = 1; MassUnits_t mass; @@ -119,10 +120,9 @@ double readCGNSScale() { TemperatureUnits_t temperature; AngleUnits_t angle; - cg_units_read(&mass,&length,&time,&temperature,&angle); - - switch (length) { + cg_units_read(&mass, &length, &time, &temperature, &angle); + switch(length) { case Centimeter: Msg::Info("Length unit in CGNS file is cm, rescaling"); scale = 0.01; @@ -152,12 +152,11 @@ double readCGNSScale() { return scale; } - /*============================================================================== * Required types *============================================================================*/ -typedef std::map<int, std::vector<GEntity*> > PhysGroupMap; +typedef std::map<int, std::vector<GEntity *> > PhysGroupMap; // Type providing a vector of entities // for a physical group index @@ -166,33 +165,25 @@ typedef std::map<int, std::vector<GEntity*> > PhysGroupMap; class DummyPartitionEntity : public GEntity { public: - DummyPartitionEntity() - : GEntity(0, 0) - { } + DummyPartitionEntity() : GEntity(0, 0) {} // number of types of elements int getNumElementTypes() const { return 1; } - void getNumMeshElements(unsigned *const c) const - { - c[0] += elements.size(); - } + void getNumMeshElements(unsigned *const c) const { c[0] += elements.size(); } // get the start of the array of a type of element - MElement *const *getStartElementType(int type) const - { - return &elements[0]; - } + MElement *const *getStartElementType(int type) const { return &elements[0]; } - std::vector<MElement*> elements; + std::vector<MElement *> elements; }; //--Class to make C style CGNS name strings act like C++ types -class CGNSNameStr -{ - private: +class CGNSNameStr { +private: char name[33]; - public: + +public: // Constructors CGNSNameStr() { name[0] = '\0'; } CGNSNameStr(const char *const cstr) @@ -209,11 +200,11 @@ class CGNSNameStr { std::sprintf(name, fmt, d); } - CGNSNameStr(const CGNSNameStr& cgs) { std::strcpy(name, cgs.name); } + CGNSNameStr(const CGNSNameStr &cgs) { std::strcpy(name, cgs.name); } // Assignment - CGNSNameStr &operator=(const CGNSNameStr& cgs) + CGNSNameStr &operator=(const CGNSNameStr &cgs) { - if ( &cgs != this ) { + if(&cgs != this) { std::strcpy(name, cgs.name); } return *this; @@ -239,48 +230,45 @@ class CGNSNameStr // 1D second-order elements // MSH_NUM_TYPE+1 is used to place non-cgns elements last. static const int msh2cgns[MSH_NUM_TYPE][2] = { - {BAR_2, 16}, - {TRI_3, 11}, - {QUAD_4, 12}, - {TETRA_4, 1}, - {HEXA_8, 4}, - {PENTA_6, 3}, - {PYRA_5, 2}, - {BAR_3, 17}, - {TRI_6, 13}, - {QUAD_9, 15}, - {TETRA_10, 5}, - {HEXA_27, 10}, - {PENTA_18, 8}, - {PYRA_14, 6}, - {-1, MSH_NUM_TYPE+1}, // MSH_PNT (NODE in CGNS but not used herein) - {QUAD_8, 14}, - {HEXA_20, 9}, - {PENTA_15, 7}, - {-1, MSH_NUM_TYPE+1}, // MSH_PYR_13 - {-1, MSH_NUM_TYPE+1}, // MSH_TRI_9 - {-1, MSH_NUM_TYPE+1}, // MSH_TRI_10 - {-1, MSH_NUM_TYPE+1}, // MSH_TRI_12 - {-1, MSH_NUM_TYPE+1}, // MSH_TRI_15 - {-1, MSH_NUM_TYPE+1}, // MSH_TRI_15I - {-1, MSH_NUM_TYPE+1}, // MSH_TRI_21 - {-1, MSH_NUM_TYPE+1}, // MSH_LIN_4 - {-1, MSH_NUM_TYPE+1}, // MSH_LIN_5 - {-1, MSH_NUM_TYPE+1}, // MSH_LIN_6 - {-1, MSH_NUM_TYPE+1}, // MSH_TET_20 - {-1, MSH_NUM_TYPE+1}, // MSH_TET_35 - {-1, MSH_NUM_TYPE+1}, // MSH_TET_56 - {-1, MSH_NUM_TYPE+1}, // MSH_TET_22 - {-1, MSH_NUM_TYPE+1} // MSH_TET_28 + {BAR_2, 16}, + {TRI_3, 11}, + {QUAD_4, 12}, + {TETRA_4, 1}, + {HEXA_8, 4}, + {PENTA_6, 3}, + {PYRA_5, 2}, + {BAR_3, 17}, + {TRI_6, 13}, + {QUAD_9, 15}, + {TETRA_10, 5}, + {HEXA_27, 10}, + {PENTA_18, 8}, + {PYRA_14, 6}, + {-1, MSH_NUM_TYPE + 1}, // MSH_PNT (NODE in CGNS but not used herein) + {QUAD_8, 14}, + {HEXA_20, 9}, + {PENTA_15, 7}, + {-1, MSH_NUM_TYPE + 1}, // MSH_PYR_13 + {-1, MSH_NUM_TYPE + 1}, // MSH_TRI_9 + {-1, MSH_NUM_TYPE + 1}, // MSH_TRI_10 + {-1, MSH_NUM_TYPE + 1}, // MSH_TRI_12 + {-1, MSH_NUM_TYPE + 1}, // MSH_TRI_15 + {-1, MSH_NUM_TYPE + 1}, // MSH_TRI_15I + {-1, MSH_NUM_TYPE + 1}, // MSH_TRI_21 + {-1, MSH_NUM_TYPE + 1}, // MSH_LIN_4 + {-1, MSH_NUM_TYPE + 1}, // MSH_LIN_5 + {-1, MSH_NUM_TYPE + 1}, // MSH_LIN_6 + {-1, MSH_NUM_TYPE + 1}, // MSH_TET_20 + {-1, MSH_NUM_TYPE + 1}, // MSH_TET_35 + {-1, MSH_NUM_TYPE + 1}, // MSH_TET_56 + {-1, MSH_NUM_TYPE + 1}, // MSH_TET_22 + {-1, MSH_NUM_TYPE + 1} // MSH_TET_28 }; - - //--This functor allows for sorting of the element types according to the //--"write-order" in array 'msh2cgns' -struct ElemSortCGNSType -{ +struct ElemSortCGNSType { bool operator()(const int t0, const int t1) { if(zoneElemConn[t0].numElem > 0 && zoneElemConn[t1].numElem > 0) @@ -292,12 +280,13 @@ struct ElemSortCGNSType } ElemSortCGNSType(const ElementConnectivity *const _zoneElemConn) : zoneElemConn(_zoneElemConn) - { } - private: + { + } + +private: const ElementConnectivity *const zoneElemConn; }; - /*============================================================================== * Forward declarations *============================================================================*/ @@ -308,12 +297,10 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, const int vectorDim, const PhysGroupMap &group, const int cgIndexFile, const int cgIndexBase); - static MElement * -createElementMSH(GModel *m, int num, - int typeMSH, int reg, int part, - std::vector<MVertex*> &v, - std::map<int, std::vector<MElement*> > elements[10]) +createElementMSH(GModel *m, int num, int typeMSH, int reg, int part, + std::vector<MVertex *> &v, + std::map<int, std::vector<MElement *> > elements[10]) { /* if(CTX::instance()->mesh.switchElementTags) { @@ -325,108 +312,109 @@ createElementMSH(GModel *m, int num, MElementFactory factory; MElement *e = factory.create(typeMSH, v, num, part, false, 0, 0, 0); - if(!e){ + if(!e) { Msg::Error("Unknown type of element %d", typeMSH); return NULL; } - switch(e->getType()){ - case TYPE_PNT : - elements[0][reg].push_back(e); break; - case TYPE_LIN : - elements[1][reg].push_back(e); break; - case TYPE_TRI : - elements[2][reg].push_back(e); break; - case TYPE_QUA : - elements[3][reg].push_back(e); break; - case TYPE_TET : - elements[4][reg].push_back(e); break; - case TYPE_HEX : - elements[5][reg].push_back(e); break; - case TYPE_PRI : - elements[6][reg].push_back(e); break; - case TYPE_PYR : - elements[7][reg].push_back(e); break; - case TYPE_POLYG : - elements[8][reg].push_back(e); break; - case TYPE_POLYH : - elements[9][reg].push_back(e); break; - default : Msg::Error("Wrong type of element"); return NULL; + switch(e->getType()) { + case TYPE_PNT: elements[0][reg].push_back(e); break; + case TYPE_LIN: elements[1][reg].push_back(e); break; + case TYPE_TRI: elements[2][reg].push_back(e); break; + case TYPE_QUA: elements[3][reg].push_back(e); break; + case TYPE_TET: elements[4][reg].push_back(e); break; + case TYPE_HEX: elements[5][reg].push_back(e); break; + case TYPE_PRI: elements[6][reg].push_back(e); break; + case TYPE_PYR: elements[7][reg].push_back(e); break; + case TYPE_POLYG: elements[8][reg].push_back(e); break; + case TYPE_POLYH: elements[9][reg].push_back(e); break; + default: Msg::Error("Wrong type of element"); return NULL; } /* int dim = e->getDim(); - if(physical && (!physicals[dim].count(reg) || !physicals[dim][reg].count(physical))) - physicals[dim][reg][physical] = "unnamed"; + if(physical && (!physicals[dim].count(reg) || + !physicals[dim][reg].count(physical))) physicals[dim][reg][physical] = + "unnamed"; */ - //if(part) m->getMeshPartitions().insert(part); + // if(part) m->getMeshPartitions().insert(part); return e; } -static int to1D(int i, int j, int k, int max_i, int max_j, int max_k) { - return k*max_i*max_j + j*max_i + i; +static int to1D(int i, int j, int k, int max_i, int max_j, int max_k) +{ + return k * max_i * max_j + j * max_i + i; } -static int getIndicesQuad(int i1, int i2, int i3, int i4, - int j1, int j2, int j3, int j4, - int k1, int k2, int k3, int k4, - std::vector<int>& ind_i, std::vector<int>& ind_j, std::vector<int>& ind_k, int order, int f) { - +static int getIndicesQuad(int i1, int i2, int i3, int i4, int j1, int j2, + int j3, int j4, int k1, int k2, int k3, int k4, + std::vector<int> &ind_i, std::vector<int> &ind_j, + std::vector<int> &ind_k, int order, int f) +{ static const int offset[6][4][3] = { - {{ 1, 1, 0}, { 1,-1, 0}, {-1,-1, 0}, {-1, 1, 0}}, - {{ 1, 1 ,0}, {-1, 1, 0}, {-1,-1, 0}, { 1,-1, 0}}, - {{ 1, 0, 1}, {-1, 0, 1}, {-1, 0,-1}, { 1, 0,-1}}, - {{ 1, 0, 1}, { 1, 0,-1}, {-1, 0,-1}, {-1, 0, 1}}, - {{ 0, 1, 1}, { 0, 1,-1}, { 0,-1,-1}, { 0,-1, 1}}, - {{ 0, 1, 1}, { 0,-1, 1}, { 0,-1,-1}, { 0, 1,-1}} - }; + {{1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {-1, 1, 0}}, + {{1, 1, 0}, {-1, 1, 0}, {-1, -1, 0}, {1, -1, 0}}, + {{1, 0, 1}, {-1, 0, 1}, {-1, 0, -1}, {1, 0, -1}}, + {{1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, {-1, 0, 1}}, + {{0, 1, 1}, {0, 1, -1}, {0, -1, -1}, {0, -1, 1}}, + {{0, 1, 1}, {0, -1, 1}, {0, -1, -1}, {0, 1, -1}}}; int added = 0; - if (order == 0) { - ind_i.push_back(i1); ind_j.push_back(j1); ind_k.push_back(k1); + if(order == 0) { + ind_i.push_back(i1); + ind_j.push_back(j1); + ind_k.push_back(k1); return 1; } // corners - ind_i.push_back(i1); ind_j.push_back(j1); ind_k.push_back(k1); - ind_i.push_back(i2); ind_j.push_back(j2); ind_k.push_back(k2); - ind_i.push_back(i3); ind_j.push_back(j3); ind_k.push_back(k3); - ind_i.push_back(i4); ind_j.push_back(j4); ind_k.push_back(k4); + ind_i.push_back(i1); + ind_j.push_back(j1); + ind_k.push_back(k1); + ind_i.push_back(i2); + ind_j.push_back(j2); + ind_k.push_back(k2); + ind_i.push_back(i3); + ind_j.push_back(j3); + ind_k.push_back(k3); + ind_i.push_back(i4); + ind_j.push_back(j4); + ind_k.push_back(k4); added += 4; // edge points - if (order > 1) { + if(order > 1) { // edge 1 - for (int v = 1; v < order; v++) { - ind_i.push_back(i1+v*(i2-i1)/order); - ind_j.push_back(j1+v*(j2-j1)/order); - ind_k.push_back(k1+v*(k2-k1)/order); + for(int v = 1; v < order; v++) { + ind_i.push_back(i1 + v * (i2 - i1) / order); + ind_j.push_back(j1 + v * (j2 - j1) / order); + ind_k.push_back(k1 + v * (k2 - k1) / order); added++; } // edge 2 - for (int v = 1; v < order; v++) { - ind_i.push_back(i2+v*(i3-i2)/order); - ind_j.push_back(j2+v*(j3-j2)/order); - ind_k.push_back(k2+v*(k3-k2)/order); + for(int v = 1; v < order; v++) { + ind_i.push_back(i2 + v * (i3 - i2) / order); + ind_j.push_back(j2 + v * (j3 - j2) / order); + ind_k.push_back(k2 + v * (k3 - k2) / order); added++; } // edge 3 - for (int v = 1; v < order; v++) { - ind_i.push_back(i3+v*(i4-i3)/order); - ind_j.push_back(j3+v*(j4-j3)/order); - ind_k.push_back(k3+v*(k4-k3)/order); + for(int v = 1; v < order; v++) { + ind_i.push_back(i3 + v * (i4 - i3) / order); + ind_j.push_back(j3 + v * (j4 - j3) / order); + ind_k.push_back(k3 + v * (k4 - k3) / order); added++; } // edge 4 - for (int v = 1; v < order; v++) { - ind_i.push_back(i4+v*(i1-i4)/order); - ind_j.push_back(j4+v*(j1-j4)/order); - ind_k.push_back(k4+v*(k1-k4)/order); + for(int v = 1; v < order; v++) { + ind_i.push_back(i4 + v * (i1 - i4) / order); + ind_j.push_back(j4 + v * (j1 - j4) / order); + ind_k.push_back(k4 + v * (k1 - k4) / order); added++; } @@ -435,10 +423,12 @@ static int getIndicesQuad(int i1, int i2, int i3, int i4, int joffset = (j3-j1)/abs(j2-j1); int koffset = (k3-k1)/abs(k2-k1); */ - added += getIndicesQuad(i1+offset[f][0][0], i2+offset[f][1][0], i3+offset[f][2][0], i4+offset[f][3][0], - j1+offset[f][0][1], j2+offset[f][1][1], j3+offset[f][2][1], j4+offset[f][3][1], - k1+offset[f][0][2], k2+offset[f][1][2], k3+offset[f][2][2], k4+offset[f][3][2], - ind_i, ind_j, ind_k, order-2, f); + added += getIndicesQuad( + i1 + offset[f][0][0], i2 + offset[f][1][0], i3 + offset[f][2][0], + i4 + offset[f][3][0], j1 + offset[f][0][1], j2 + offset[f][1][1], + j3 + offset[f][2][1], j4 + offset[f][3][1], k1 + offset[f][0][2], + k2 + offset[f][1][2], k3 + offset[f][2][2], k4 + offset[f][3][2], ind_i, + ind_j, ind_k, order - 2, f); /**/ } return added; @@ -446,68 +436,75 @@ static int getIndicesQuad(int i1, int i2, int i3, int i4, // --- get ijk indices for a high order face defined by principal vertices 1-4 -static int getIndicesFace(int i1, int i2, int i3, int i4, - int j1, int j2, int j3, int j4, - int k1, int k2, int k3, int k4, - std::vector<int>& ind_i, - std::vector<int>& ind_j, - std::vector<int>& ind_k, int order, int f) { - +static int getIndicesFace(int i1, int i2, int i3, int i4, int j1, int j2, + int j3, int j4, int k1, int k2, int k3, int k4, + std::vector<int> &ind_i, std::vector<int> &ind_j, + std::vector<int> &ind_k, int order, int f) +{ static const int offset[6][4][3] = { - {{ 1, 1, 0}, { 1,-1, 0}, {-1,-1, 0}, {-1, 1, 0}}, - {{ 1, 0, 1}, {-1, 0, 1}, {-1, 0,-1}, { 1, 0,-1}}, - {{ 0, 1, 1}, { 0, 1,-1}, { 0,-1,-1}, { 0,-1, 1}}, - {{ 0, 1, 1}, { 0,-1, 1}, { 0,-1,-1}, { 0, 1,-1}}, - {{-1, 0, 1}, { 1, 0, 1}, { 1, 0,-1}, {-1, 0,-1}}, - {{ 1, 1 ,0}, {-1, 1, 0}, {-1,-1, 0}, { 1,-1, 0}} - }; + {{1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {-1, 1, 0}}, + {{1, 0, 1}, {-1, 0, 1}, {-1, 0, -1}, {1, 0, -1}}, + {{0, 1, 1}, {0, 1, -1}, {0, -1, -1}, {0, -1, 1}}, + {{0, 1, 1}, {0, -1, 1}, {0, -1, -1}, {0, 1, -1}}, + {{-1, 0, 1}, {1, 0, 1}, {1, 0, -1}, {-1, 0, -1}}, + {{1, 1, 0}, {-1, 1, 0}, {-1, -1, 0}, {1, -1, 0}}}; int added = 0; - if (order == 0) { - ind_i.push_back(i1); ind_j.push_back(j1); ind_k.push_back(k1); + if(order == 0) { + ind_i.push_back(i1); + ind_j.push_back(j1); + ind_k.push_back(k1); return 1; } // corners - ind_i.push_back(i1); ind_j.push_back(j1); ind_k.push_back(k1); - ind_i.push_back(i2); ind_j.push_back(j2); ind_k.push_back(k2); - ind_i.push_back(i3); ind_j.push_back(j3); ind_k.push_back(k3); - ind_i.push_back(i4); ind_j.push_back(j4); ind_k.push_back(k4); + ind_i.push_back(i1); + ind_j.push_back(j1); + ind_k.push_back(k1); + ind_i.push_back(i2); + ind_j.push_back(j2); + ind_k.push_back(k2); + ind_i.push_back(i3); + ind_j.push_back(j3); + ind_k.push_back(k3); + ind_i.push_back(i4); + ind_j.push_back(j4); + ind_k.push_back(k4); added += 4; // edge points - if (order > 1) { + if(order > 1) { // edge 1 - for (int v = 1; v < order; v++) { - ind_i.push_back(i1+(i2-i1)/order); - ind_j.push_back(j1+(j2-j1)/order); - ind_k.push_back(k1+(k2-k1)/order); + for(int v = 1; v < order; v++) { + ind_i.push_back(i1 + (i2 - i1) / order); + ind_j.push_back(j1 + (j2 - j1) / order); + ind_k.push_back(k1 + (k2 - k1) / order); added++; } // edge 2 - for (int v = 1; v < order; v++) { - ind_i.push_back(i2+(i3-i2)/order); - ind_j.push_back(j2+(j3-j2)/order); - ind_k.push_back(k2+(k3-k2)/order); + for(int v = 1; v < order; v++) { + ind_i.push_back(i2 + (i3 - i2) / order); + ind_j.push_back(j2 + (j3 - j2) / order); + ind_k.push_back(k2 + (k3 - k2) / order); added++; } // edge 3 - for (int v = 1; v < order; v++) { - ind_i.push_back(i3+(i4-i3)/order); - ind_j.push_back(j3+(j4-j3)/order); - ind_k.push_back(k3+(k4-k3)/order); + for(int v = 1; v < order; v++) { + ind_i.push_back(i3 + (i4 - i3) / order); + ind_j.push_back(j3 + (j4 - j3) / order); + ind_k.push_back(k3 + (k4 - k3) / order); added++; } // edge 4 - for (int v = 1; v < order; v++) { - ind_i.push_back(i4+(i1-i4)/order); - ind_j.push_back(j4+(j1-j4)/order); - ind_k.push_back(k4+(k1-k4)/order); + for(int v = 1; v < order; v++) { + ind_i.push_back(i4 + (i1 - i4) / order); + ind_j.push_back(j4 + (j1 - j4) / order); + ind_k.push_back(k4 + (k1 - k4) / order); added++; } } @@ -516,117 +513,113 @@ static int getIndicesFace(int i1, int i2, int i3, int i4, int joffset = (j3-j1)/abs(j2-j1); int koffset = (k3-k1)/abs(k2-k1); */ - added += getIndicesFace(i1+offset[f][0][0], i2-offset[f][1][0], i3-offset[f][2][0], i4+offset[f][3][0], - j1+offset[f][0][1], j2-offset[f][1][1], j3-offset[f][2][1], j4+offset[f][3][1], - k1+offset[f][0][2], k2-offset[f][1][2], k3-offset[f][2][2], k4+offset[f][3][2], - ind_i, ind_j, ind_k, order-2, f); + added += getIndicesFace( + i1 + offset[f][0][0], i2 - offset[f][1][0], i3 - offset[f][2][0], + i4 + offset[f][3][0], j1 + offset[f][0][1], j2 - offset[f][1][1], + j3 - offset[f][2][1], j4 + offset[f][3][1], k1 + offset[f][0][2], + k2 - offset[f][1][2], k3 - offset[f][2][2], k4 + offset[f][3][2], ind_i, + ind_j, ind_k, order - 2, f); /**/ return added; } // --- get ijk indices for a high order hexahedral element -static void getIndices(int i, int j, int k, - std::vector<int>& ind_i, - std::vector<int>& ind_j, - std::vector<int>& ind_k, - int order, int startpoint=0) { - - static const int edges[12][2] = { - {0, 1}, - {0, 3}, - {0, 4}, - {1, 2}, - {1, 5}, - {2, 3}, - {2, 6}, - {3, 7}, - {4, 5}, - {4, 7}, - {5, 6}, - {6, 7} - }; - static const int faces[6][4] = { - {0, 3, 2, 1}, - {0, 1, 5, 4}, - {0, 4, 7, 3}, - {1, 2, 6, 5}, - {2, 3, 7, 6}, - {4, 5, 6, 7} - }; +static void getIndices(int i, int j, int k, std::vector<int> &ind_i, + std::vector<int> &ind_j, std::vector<int> &ind_k, + int order, int startpoint = 0) +{ + static const int edges[12][2] = {{0, 1}, {0, 3}, {0, 4}, {1, 2}, + {1, 5}, {2, 3}, {2, 6}, {3, 7}, + {4, 5}, {4, 7}, {5, 6}, {6, 7}}; + static const int faces[6][4] = {{0, 3, 2, 1}, {0, 1, 5, 4}, {0, 4, 7, 3}, + {1, 2, 6, 5}, {2, 3, 7, 6}, {4, 5, 6, 7}}; static const int offset[6][4][3] = { - {{ 1, 1, 0}, { 1,-1, 0}, {-1,-1, 0}, {-1, 1, 0}}, - {{ 1, 0, 1}, {-1, 0, 1}, {-1, 0,-1}, { 1, 0,-1}}, - {{ 0, 1, 1}, { 0, 1,-1}, { 0,-1,-1}, { 0,-1, 1}}, - {{ 0, 1, 1}, { 0,-1, 1}, { 0,-1,-1}, { 0, 1,-1}}, - {{-1, 0, 1}, { 1, 0, 1}, { 1, 0,-1}, {-1, 0,-1}}, - {{ 1, 1 ,0}, {-1, 1, 0}, {-1,-1, 0}, { 1,-1, 0}} - }; - - - if (order == 0) { - ind_i.push_back(i); ind_j.push_back(j); ind_k.push_back(k); + {{1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {-1, 1, 0}}, + {{1, 0, 1}, {-1, 0, 1}, {-1, 0, -1}, {1, 0, -1}}, + {{0, 1, 1}, {0, 1, -1}, {0, -1, -1}, {0, -1, 1}}, + {{0, 1, 1}, {0, -1, 1}, {0, -1, -1}, {0, 1, -1}}, + {{-1, 0, 1}, {1, 0, 1}, {1, 0, -1}, {-1, 0, -1}}, + {{1, 1, 0}, {-1, 1, 0}, {-1, -1, 0}, {1, -1, 0}}}; + + if(order == 0) { + ind_i.push_back(i); + ind_j.push_back(j); + ind_k.push_back(k); return; } // 8 principal points - ind_i.push_back(i); ind_j.push_back(j); ind_k.push_back(k); - ind_i.push_back(i+order); ind_j.push_back(j); ind_k.push_back(k); - ind_i.push_back(i+order); ind_j.push_back(j+order); ind_k.push_back(k); - ind_i.push_back(i); ind_j.push_back(j+order); ind_k.push_back(k); - ind_i.push_back(i); ind_j.push_back(j); ind_k.push_back(k+order); - ind_i.push_back(i+order); ind_j.push_back(j); ind_k.push_back(k+order); - ind_i.push_back(i+order); ind_j.push_back(j+order); ind_k.push_back(k+order); - ind_i.push_back(i); ind_j.push_back(j+order); ind_k.push_back(k+order); + ind_i.push_back(i); + ind_j.push_back(j); + ind_k.push_back(k); + ind_i.push_back(i + order); + ind_j.push_back(j); + ind_k.push_back(k); + ind_i.push_back(i + order); + ind_j.push_back(j + order); + ind_k.push_back(k); + ind_i.push_back(i); + ind_j.push_back(j + order); + ind_k.push_back(k); + ind_i.push_back(i); + ind_j.push_back(j); + ind_k.push_back(k + order); + ind_i.push_back(i + order); + ind_j.push_back(j); + ind_k.push_back(k + order); + ind_i.push_back(i + order); + ind_j.push_back(j + order); + ind_k.push_back(k + order); + ind_i.push_back(i); + ind_j.push_back(j + order); + ind_k.push_back(k + order); int initial_point = startpoint + 8; - if (order > 1) { - + if(order > 1) { // edges - for (int e = 0; e < 12; e++) { - int p0_i = ind_i[startpoint+edges[e][0]]; - int p0_j = ind_j[startpoint+edges[e][0]]; - int p0_k = ind_k[startpoint+edges[e][0]]; - int p1_i = ind_i[startpoint+edges[e][1]]; - int p1_j = ind_j[startpoint+edges[e][1]]; - int p1_k = ind_k[startpoint+edges[e][1]]; - - for (int v = 1; v < order; v++) { - ind_i.push_back(p0_i + v*((p1_i-p0_i)/order)); - ind_j.push_back(p0_j + v*((p1_j-p0_j)/order)); - ind_k.push_back(p0_k + v*((p1_k-p0_k)/order)); + for(int e = 0; e < 12; e++) { + int p0_i = ind_i[startpoint + edges[e][0]]; + int p0_j = ind_j[startpoint + edges[e][0]]; + int p0_k = ind_k[startpoint + edges[e][0]]; + int p1_i = ind_i[startpoint + edges[e][1]]; + int p1_j = ind_j[startpoint + edges[e][1]]; + int p1_k = ind_k[startpoint + edges[e][1]]; + + for(int v = 1; v < order; v++) { + ind_i.push_back(p0_i + v * ((p1_i - p0_i) / order)); + ind_j.push_back(p0_j + v * ((p1_j - p0_j) / order)); + ind_k.push_back(p0_k + v * ((p1_k - p0_k) / order)); initial_point++; } } // faces - for (int f = 0; f < 6; f++) { - int i1 = ind_i[startpoint+faces[f][0]] + offset[f][0][0]; - int i2 = ind_i[startpoint+faces[f][1]] + offset[f][1][0]; - int i3 = ind_i[startpoint+faces[f][2]] + offset[f][2][0]; - int i4 = ind_i[startpoint+faces[f][3]] + offset[f][3][0]; - - int j1 = ind_j[startpoint+faces[f][0]] + offset[f][0][1]; - int j2 = ind_j[startpoint+faces[f][1]] + offset[f][1][1]; - int j3 = ind_j[startpoint+faces[f][2]] + offset[f][2][1]; - int j4 = ind_j[startpoint+faces[f][3]] + offset[f][3][1]; - - int k1 = ind_k[startpoint+faces[f][0]] + offset[f][0][2]; - int k2 = ind_k[startpoint+faces[f][1]] + offset[f][1][2]; - int k3 = ind_k[startpoint+faces[f][2]] + offset[f][2][2]; - int k4 = ind_k[startpoint+faces[f][3]] + offset[f][3][2]; - initial_point+= getIndicesFace(i1, i2, i3, i4, - j1, j2, j3, j4, - k1, k2, k3, k4, - ind_i, ind_j, ind_k, - order-2, f); + for(int f = 0; f < 6; f++) { + int i1 = ind_i[startpoint + faces[f][0]] + offset[f][0][0]; + int i2 = ind_i[startpoint + faces[f][1]] + offset[f][1][0]; + int i3 = ind_i[startpoint + faces[f][2]] + offset[f][2][0]; + int i4 = ind_i[startpoint + faces[f][3]] + offset[f][3][0]; + + int j1 = ind_j[startpoint + faces[f][0]] + offset[f][0][1]; + int j2 = ind_j[startpoint + faces[f][1]] + offset[f][1][1]; + int j3 = ind_j[startpoint + faces[f][2]] + offset[f][2][1]; + int j4 = ind_j[startpoint + faces[f][3]] + offset[f][3][1]; + + int k1 = ind_k[startpoint + faces[f][0]] + offset[f][0][2]; + int k2 = ind_k[startpoint + faces[f][1]] + offset[f][1][2]; + int k3 = ind_k[startpoint + faces[f][2]] + offset[f][2][2]; + int k4 = ind_k[startpoint + faces[f][3]] + offset[f][3][2]; + initial_point += + getIndicesFace(i1, i2, i3, i4, j1, j2, j3, j4, k1, k2, k3, k4, ind_i, + ind_j, ind_k, order - 2, f); } // interior - getIndices(i+1,j+1,k+1, ind_i, ind_j, ind_k, order-2, initial_point); - + getIndices(i + 1, j + 1, k + 1, ind_i, ind_j, ind_k, order - 2, + initial_point); } } @@ -648,23 +641,24 @@ static void getIndices(int i, int j, int k, // --- compute the face index in the block from the index range ---------------- - -int computeCGNSFace(const cgsize_t* range) { - +int computeCGNSFace(const cgsize_t *range) +{ int face = -1; - if (range[0] == range[3]) { - if (range[0] == 1) + if(range[0] == range[3]) { + if(range[0] == 1) face = 4; else face = 5; - } else if (range[1] == range[4]) { - if (range[1] == 1) + } + else if(range[1] == range[4]) { + if(range[1] == 1) face = 2; else face = 3; - } else if (range[2] == range[5]) { - if (range[2] == 1) + } + else if(range[2] == range[5]) { + if(range[2] == 1) face = 0; else face = 1; @@ -675,8 +669,8 @@ int computeCGNSFace(const cgsize_t* range) { // --- structure for storing periodic connections ------------------------------ struct CGNSStruPeriodic { - - // the data that are modified on the fly by looping on the CGNSStruPeriodic set + // the data that are modified on the fly by looping on the CGNSStruPeriodic + // set // // - should not affect the ordering in CGNSStruPeriodicLess // - should be modified with a const operation (STL only returns const data) @@ -689,146 +683,140 @@ struct CGNSStruPeriodic { friend class CGNSStruPeriodicLess; public: - struct IJK { + IJK() + { + for(int k = 0; k < 3; k++) ijk[k] = -1; + } + IJK(int i, int j, int k) + { + ijk[0] = i; + ijk[1] = j; + ijk[2] = k; + } + IJK(const IJK &other) { std::memcpy(ijk, other.ijk, 3 * sizeof(int)); } - IJK() {for (int k=0;k<3;k++) ijk[k] = -1;} - IJK(int i,int j,int k){ijk[0]=i;ijk[1]=j;ijk[2]=k;} - IJK(const IJK& other) {std::memcpy(ijk,other.ijk,3*sizeof(int));} - - int& operator[](int k) {return ijk[k];} - int operator[](int k) const {return ijk[k];} + int &operator[](int k) { return ijk[k]; } + int operator[](int k) const { return ijk[k]; } int ijk[3]; - string print() const { + string print() const + { std::ostringstream printout; printout << "(" << ijk[0] << "," << ijk[1] << "," << ijk[2] << ")"; return printout.str(); } - }; - string tgtZone; // cgns name of the block - int tgtFace; // index of the face in the block - mutable int tgtFaceId; // elementary tag corresponding to the face - mutable - vector<MVertex*> tgtVertices; // ordered vertices in the tgt - vector<IJK> tgtIJK; // ijk indices of the face points in the block - + string tgtZone; // cgns name of the block + int tgtFace; // index of the face in the block + mutable int tgtFaceId; // elementary tag corresponding to the face + mutable vector<MVertex *> tgtVertices; // ordered vertices in the tgt + vector<IJK> tgtIJK; // ijk indices of the face points in the block - string srcName; // cgns name of the block - int srcFace; // index of the face in the block - mutable int srcFaceId; // elementary tag corresponding to the face - mutable - vector<MVertex*> srcVertices; // ordered vertices in the src - vector<IJK> srcIJK; // ijk indices in the source face, ordered following tgt + string srcName; // cgns name of the block + int srcFace; // index of the face in the block + mutable int srcFaceId; // elementary tag corresponding to the face + mutable vector<MVertex *> srcVertices; // ordered vertices in the src + vector<IJK> srcIJK; // ijk indices in the source face, ordered following tgt - std::vector<double> tfo; // transformation + std::vector<double> tfo; // transformation public: - - void print(ostream& out) const { - + void print(ostream &out) const + { out << "Connection of face " << tgtFace << " (" << tgtFaceId << ")" - << " of domain " << tgtZone << " to " - << srcFace << " (" << srcFaceId << ")" << " of " - << srcName << std::endl; + << " of domain " << tgtZone << " to " << srcFace << " (" << srcFaceId + << ")" + << " of " << srcName << std::endl; } - public: // constructors - - // -- empty constructor CGNSStruPeriodic() { setUnitAffineTransformation(tfo); } // -- standard constructor - CGNSStruPeriodic(const char* tn,const cgsize_t* tr, - const char* sn,const cgsize_t* sr,const int* iTfo,int o, - int tfid, - const float* rotationCenter, - const float* rotationAngle, - const float* translation): - - tgtZone(tn),tgtFace(computeCGNSFace(tr)),tgtFaceId(tfid), - srcName(sn),srcFace(computeCGNSFace(sr)),srcFaceId(-1) { + CGNSStruPeriodic(const char *tn, const cgsize_t *tr, const char *sn, + const cgsize_t *sr, const int *iTfo, int o, int tfid, + const float *rotationCenter, const float *rotationAngle, + const float *translation) + : + tgtZone(tn), tgtFace(computeCGNSFace(tr)), tgtFaceId(tfid), srcName(sn), + srcFace(computeCGNSFace(sr)), srcFaceId(-1) + { // compute the structured grid indices - int dIJKTgt[3] = {(tr[3] > tr[0] ? o : - o), - (tr[4] > tr[1] ? o : - o), - (tr[5] > tr[2] ? o : - o)}; + int dIJKTgt[3] = {(tr[3] > tr[0] ? o : -o), (tr[4] > tr[1] ? o : -o), + (tr[5] > tr[2] ? o : -o)}; - int dIJKSrc[3] = {(sr[3] > sr[0] ? o : - o), - (sr[4] > sr[1] ? o : - o), - (sr[5] > sr[2] ? o : - o)}; + int dIJKSrc[3] = {(sr[3] > sr[0] ? o : -o), (sr[4] > sr[1] ? o : -o), + (sr[5] > sr[2] ? o : -o)}; - int idx[3] = {abs(iTfo[0])-1,abs(iTfo[1])-1,abs(iTfo[2])-1}; + int idx[3] = {abs(iTfo[0]) - 1, abs(iTfo[1]) - 1, abs(iTfo[2]) - 1}; int nbPoints = 1; IJK nbIJK; - for (int k=0;k<3;k++) nbIJK[k] = (tr[k]==tr[k+3])?1:((abs(tr[k]-tr[k+3]))/o +1); - for (int k=0;k<3;k++) nbPoints *= nbIJK[k]; + for(int k = 0; k < 3; k++) + nbIJK[k] = (tr[k] == tr[k + 3]) ? 1 : ((abs(tr[k] - tr[k + 3])) / o + 1); + for(int k = 0; k < 3; k++) nbPoints *= nbIJK[k]; tgtIJK.reserve(nbPoints); srcIJK.reserve(nbPoints); - tgtVertices.resize(nbPoints,NULL); - srcVertices.resize(nbPoints,NULL); - - IJK src(sr[idx[0]],sr[idx[1]],sr[idx[2]]); - IJK tgt(tr[0],tr[1],tr[2]); + tgtVertices.resize(nbPoints, NULL); + srcVertices.resize(nbPoints, NULL); - for (int i=0;i<nbIJK[0];i++) { + IJK src(sr[idx[0]], sr[idx[1]], sr[idx[2]]); + IJK tgt(tr[0], tr[1], tr[2]); + for(int i = 0; i < nbIJK[0]; i++) { tgt[1] = tr[1]; src[1] = sr[idx[1]]; - for (int j=0;j<nbIJK[1];j++) { - + for(int j = 0; j < nbIJK[1]; j++) { tgt[2] = tr[2]; src[2] = sr[idx[2]]; - for (int k=0;k<nbIJK[2];k++) { - + for(int k = 0; k < nbIJK[2]; k++) { tgtIJK.push_back(tgt); srcIJK.push_back(src); - tgt[2] += dIJKTgt[2]; + tgt[2] += dIJKTgt[2]; src[idx[2]] += dIJKSrc[idx[2]]; } - tgt[1] += dIJKTgt[1]; + tgt[1] += dIJKTgt[1]; src[idx[1]] += dIJKSrc[idx[1]]; } - tgt[0] += dIJKTgt[0]; + tgt[0] += dIJKTgt[0]; src[idx[0]] += dIJKSrc[idx[0]]; } // now compute the transformation - computeAffineTransformation(rotationCenter,rotationAngle,translation,tfo); + computeAffineTransformation(rotationCenter, rotationAngle, translation, + tfo); } - // -- copy constructor - CGNSStruPeriodic(const CGNSStruPeriodic& old) { - - tgtVertices.resize(old.getNbPoints(),NULL); - srcVertices.resize(old.getNbPoints(),NULL); + CGNSStruPeriodic(const CGNSStruPeriodic &old) + { + tgtVertices.resize(old.getNbPoints(), NULL); + srcVertices.resize(old.getNbPoints(), NULL); - tgtZone = old.tgtZone; - tgtFace = old.tgtFace; - tgtFaceId = old.tgtFaceId; - tgtIJK = old.tgtIJK; + tgtZone = old.tgtZone; + tgtFace = old.tgtFace; + tgtFaceId = old.tgtFaceId; + tgtIJK = old.tgtIJK; tgtVertices = old.tgtVertices; - srcName = old.srcName; - srcFace = old.srcFace; - srcFaceId = old.srcFaceId; - srcIJK = old.srcIJK; + srcName = old.srcName; + srcFace = old.srcFace; + srcFaceId = old.srcFaceId; + srcIJK = old.srcIJK; srcVertices = old.srcVertices; tfo = old.tfo; @@ -836,78 +824,77 @@ public: // constructors // -- constructor of the inverse connection - CGNSStruPeriodic getInverse() const { - + CGNSStruPeriodic getInverse() const + { CGNSStruPeriodic inv; - inv.tgtVertices.resize(getNbPoints(),NULL); - inv.srcVertices.resize(getNbPoints(),NULL); + inv.tgtVertices.resize(getNbPoints(), NULL); + inv.srcVertices.resize(getNbPoints(), NULL); - inv.tgtZone = srcName; - inv.tgtFace = srcFace; - inv.tgtFaceId = srcFaceId; - inv.tgtIJK = srcIJK; + inv.tgtZone = srcName; + inv.tgtFace = srcFace; + inv.tgtFaceId = srcFaceId; + inv.tgtIJK = srcIJK; inv.tgtVertices = srcVertices; - inv.srcName = tgtZone; - inv.srcFace = tgtFace; - inv.srcFaceId = tgtFaceId; - inv.srcIJK = tgtIJK; + inv.srcName = tgtZone; + inv.srcFace = tgtFace; + inv.srcFaceId = tgtFaceId; + inv.srcIJK = tgtIJK; inv.srcVertices = tgtVertices; inv.tfo = tfo; - invertAffineTransformation(tfo,inv.tfo); + invertAffineTransformation(tfo, inv.tfo); return inv; } public: // vertex functions + size_t getNbPoints() const { return tgtIJK.size(); } - - size_t getNbPoints() const {return tgtIJK.size();} - - - bool getTgtIJK(size_t ip,int& i,int& j,int& k) const { - if (ip > tgtIJK.size()) return false; + bool getTgtIJK(size_t ip, int &i, int &j, int &k) const + { + if(ip > tgtIJK.size()) return false; i = tgtIJK[ip][0] - 1; j = tgtIJK[ip][1] - 1; k = tgtIJK[ip][2] - 1; return true; } - bool getSrcIJK(size_t ip,int& i,int& j,int& k) const { - if (ip > srcIJK.size()) return false; + bool getSrcIJK(size_t ip, int &i, int &j, int &k) const + { + if(ip > srcIJK.size()) return false; i = srcIJK[ip][0] - 1; j = srcIJK[ip][1] - 1; k = srcIJK[ip][2] - 1; return true; } - bool insertTgtVertex(size_t ip,MVertex* v) const { - if (ip > tgtVertices.size()) return false; + bool insertTgtVertex(size_t ip, MVertex *v) const + { + if(ip > tgtVertices.size()) return false; tgtVertices[ip] = v; return true; } - bool insertSrcVertex(size_t ip,MVertex* v) const { - if (ip > srcVertices.size()) return false; + bool insertSrcVertex(size_t ip, MVertex *v) const + { + if(ip > srcVertices.size()) return false; srcVertices[ip] = v; return true; } - public: // transformation operations - - }; // --- definition of a set for storing periodic connections -------------------- class CGNSStruPeriodicLess { public: - bool operator() (const CGNSStruPeriodic& f,const CGNSStruPeriodic& d) const { + bool operator()(const CGNSStruPeriodic &f, const CGNSStruPeriodic &d) const + { int s = f.srcName.compare(d.srcName); - if (s != 0) return (s < 0); + if(s != 0) return (s < 0); return (f.srcFace < d.srcFace); } }; @@ -915,8 +902,8 @@ public: // --- structure for storing periodic connections ------------------------------ class CGNSUnstPeriodic { - - // the data that are modified on the fly by looping on the CGNSUnstPeriodic set + // the data that are modified on the fly by looping on the CGNSUnstPeriodic + // set // // - should not affect the ordering in CGNSUnstPeriodicLess // - should be modified with a const operation (STL only returns const data) @@ -929,74 +916,65 @@ class CGNSUnstPeriodic { friend class CGNSUnstPeriodicLess; public: - - std::string name; // cgns name of the connection + std::string name; // cgns name of the connection std::string tgtZone; // cgns name of the unstructured zone std::string srcZone; // cgns name of the unstructured zone - std::map<int,int> srcToTgtPts; - std::map<int,int> tgtToSrcPts; + std::map<int, int> srcToTgtPts; + std::map<int, int> tgtToSrcPts; - std::vector<double> tfo; // transformation + std::vector<double> tfo; // transformation - std::map<std::set<int>,GEntity*> tgtEnts[3]; - std::map<std::set<int>,GEntity*> srcEnts[3]; + std::map<std::set<int>, GEntity *> tgtEnts[3]; + std::map<std::set<int>, GEntity *> srcEnts[3]; - std::map<GEntity*,GEntity*> tgtToSrcEnts[3]; + std::map<GEntity *, GEntity *> tgtToSrcEnts[3]; protected: - - void addPoints(PointSetType_t setType,cgsize_t size, - const cgsize_t* ptsList, - std::vector<int>& pts) { - - switch (setType) { + void addPoints(PointSetType_t setType, cgsize_t size, const cgsize_t *ptsList, + std::vector<int> &pts) + { + switch(setType) { case PointRange: case PointRangeDonor: - for (int i=ptsList[0];i<=ptsList[1];i++) pts.push_back(i-1); + for(int i = ptsList[0]; i <= ptsList[1]; i++) pts.push_back(i - 1); break; case PointList: case PointListDonor: - for (int i=0;i<size;i++) pts.push_back(ptsList[i]-1); - break; - default: + for(int i = 0; i < size; i++) pts.push_back(ptsList[i] - 1); break; + default: break; } - } - public: // constructors - // -- empty constructor CGNSUnstPeriodic() { setUnitAffineTransformation(tfo); } // -- standard constructor - CGNSUnstPeriodic(const char* n, - const char* tn,const cgsize_t* tPts, - PointSetType_t tType,cgsize_t tSize, - const char* sn,const cgsize_t* sPts, - PointSetType_t sType,cgsize_t sSize, - const float* rotationCenter, - const float* rotationAngle, - const float* translation): - name(n),tgtZone(tn),srcZone(sn) { - + CGNSUnstPeriodic(const char *n, const char *tn, const cgsize_t *tPts, + PointSetType_t tType, cgsize_t tSize, const char *sn, + const cgsize_t *sPts, PointSetType_t sType, cgsize_t sSize, + const float *rotationCenter, const float *rotationAngle, + const float *translation) + : name(n), tgtZone(tn), srcZone(sn) + { // compute the structured grid indices - computeAffineTransformation(rotationCenter,rotationAngle,translation,tfo); + computeAffineTransformation(rotationCenter, rotationAngle, translation, + tfo); std::vector<int> srcPts; - addPoints(sType,sSize,sPts,srcPts); + addPoints(sType, sSize, sPts, srcPts); std::vector<int> tgtPts; - addPoints(tType,tSize,tPts,tgtPts); + addPoints(tType, tSize, tPts, tgtPts); - if (tgtPts.size() == srcPts.size()) { - for (unsigned i=0;i<tgtPts.size();i++) { + if(tgtPts.size() == srcPts.size()) { + for(unsigned i = 0; i < tgtPts.size(); i++) { tgtToSrcPts[tgtPts[i]] = srcPts[i]; srcToTgtPts[srcPts[i]] = tgtPts[i]; } @@ -1004,25 +982,22 @@ public: // constructors } public: // vertex functions - - size_t nbPoints() const {return tgtToSrcPts.size();} - + size_t nbPoints() const { return tgtToSrcPts.size(); } }; // ----------------------------------------------------------------------------- class CGNSUnstPeriodicLess { - public: - bool operator() (const CGNSUnstPeriodic& f,const CGNSUnstPeriodic& d) const { - - if (f.nbPoints() == d.nbPoints()) { - - if (f.tgtZone == d.tgtZone) { - if (f.srcZone == d.srcZone) return f.tgtToSrcPts < d.tgtToSrcPts; +public: + bool operator()(const CGNSUnstPeriodic &f, const CGNSUnstPeriodic &d) const + { + if(f.nbPoints() == d.nbPoints()) { + if(f.tgtZone == d.tgtZone) { + if(f.srcZone == d.srcZone) return f.tgtToSrcPts < d.tgtToSrcPts; return (f.srcZone.compare(d.srcZone) < 0); } - if (f.tgtZone == d.srcZone) { - if (f.srcZone == d.tgtZone) return f.tgtToSrcPts < d.srcToTgtPts; + if(f.tgtZone == d.srcZone) { + if(f.srcZone == d.tgtZone) return f.tgtToSrcPts < d.srcToTgtPts; return (f.srcZone.compare(d.tgtZone) < 0); } return (f.srcZone.compare(d.srcZone) < 0); @@ -1033,13 +1008,13 @@ class CGNSUnstPeriodicLess { // ----------------------------------------------------------------------------- -int openCGNSFile(const std::string& fileName,int& fileIndex,int& nbBasis, - double& scale) { - +int openCGNSFile(const std::string &fileName, int &fileIndex, int &nbBasis, + double &scale) +{ // Open the CGNS file - if (cg_open(fileName.c_str(), CG_MODE_READ, &fileIndex)) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_open(fileName.c_str(), CG_MODE_READ, &fileIndex)) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, __LINE__, + fileName.c_str(), cg_get_error()); return 0; } @@ -1051,22 +1026,17 @@ int openCGNSFile(const std::string& fileName,int& fileIndex,int& nbBasis, // ------------------------------------------------------------------------------ -bool readCGNSBoundaryConditions(int fileIndex, - int baseIndex, - int zoneIndex, - int classIndex, - int meshDim, - std::map<int,int>& eltToClass, - std::map<int,std::string>& classToName) { - - - +bool readCGNSBoundaryConditions(int fileIndex, int baseIndex, int zoneIndex, + int classIndex, int meshDim, + std::map<int, int> &eltToClass, + std::map<int, std::string> &classToName) +{ int nbBoCos; - if (cg_nbocos(fileIndex,baseIndex,zoneIndex,&nbBoCos) != CG_OK) return false; - - for (int boCoIndex=1;boCoIndex<=nbBoCos;boCoIndex++,classIndex++) { + if(cg_nbocos(fileIndex, baseIndex, zoneIndex, &nbBoCos) != CG_OK) + return false; + for(int boCoIndex = 1; boCoIndex <= nbBoCos; boCoIndex++, classIndex++) { PointSetType_t ptSetType; int normalIndex; cgsize_t normalSize; @@ -1078,92 +1048,84 @@ bool readCGNSBoundaryConditions(int fileIndex, cgsize_t nbElts; int ierr; - ierr = cg_boco_info(fileIndex,baseIndex,zoneIndex,boCoIndex, - bcName,&bcType,&ptSetType,&nbElts, - &normalIndex,&normalSize, + ierr = cg_boco_info(fileIndex, baseIndex, zoneIndex, boCoIndex, bcName, + &bcType, &ptSetType, &nbElts, &normalIndex, &normalSize, &normalType, &nbDataSet); - if (ierr != CG_OK ) { - Msg::Error("%s (%i) : %s",__FILE__,__LINE__,cg_get_error()); + if(ierr != CG_OK) { + Msg::Error("%s (%i) : %s", __FILE__, __LINE__, cg_get_error()); return false; } GridLocation_t location; - ierr = cg_boco_gridlocation_read(fileIndex,baseIndex,zoneIndex, - boCoIndex,&location); - if (ierr != CG_OK) { - Msg::Error("%s (%i) : %s",__FILE__,__LINE__,cg_get_error()); + ierr = cg_boco_gridlocation_read(fileIndex, baseIndex, zoneIndex, boCoIndex, + &location); + if(ierr != CG_OK) { + Msg::Error("%s (%i) : %s", __FILE__, __LINE__, cg_get_error()); return false; } - Msg::Info("Boundary conditions %s specified on %s and set type %s", - bcName,cg_GridLocationName(location),cg_PointSetTypeName(ptSetType)); + Msg::Info("Boundary conditions %s specified on %s and set type %s", bcName, + cg_GridLocationName(location), cg_PointSetTypeName(ptSetType)); - if (meshDim == 2 && - location != CGNS::EdgeCenter && - location != CGNS::Vertex) { + if(meshDim == 2 && location != CGNS::EdgeCenter && + location != CGNS::Vertex) { Msg::Error("Boundary condition %s should be specified on edges " "for 2D zone and not on %s", - bcName,cg_GridLocationName(location)); + bcName, cg_GridLocationName(location)); return false; } - if (meshDim == 3 && - location != CGNS::FaceCenter && - location != CGNS::Vertex) { + if(meshDim == 3 && location != CGNS::FaceCenter && + location != CGNS::Vertex) { Msg::Error("Boundary condition %s should be specified on faces " "for 3D zones and not on %s", - bcName,cg_GridLocationName(location)); + bcName, cg_GridLocationName(location)); return false; } + cgsize_t *elt = new cgsize_t[nbElts]; - cgsize_t* elt = new cgsize_t[nbElts]; - - - - ierr = cg_boco_read(fileIndex,baseIndex,zoneIndex,boCoIndex,elt,NULL); - if (ierr != CG_OK) { - Msg::Error("%s (%i) : %s",__FILE__,__LINE__,cg_get_error()); + ierr = cg_boco_read(fileIndex, baseIndex, zoneIndex, boCoIndex, elt, NULL); + if(ierr != CG_OK) { + Msg::Error("%s (%i) : %s", __FILE__, __LINE__, cg_get_error()); return false; } - ierr = cg_goto(fileIndex,baseIndex,"Zone_t",zoneIndex, - "ZoneBC_t",1,"BC_t",boCoIndex,"end"); + ierr = cg_goto(fileIndex, baseIndex, "Zone_t", zoneIndex, "ZoneBC_t", 1, + "BC_t", boCoIndex, "end"); - if (ierr !=CG_OK) { - Msg::Error("%s (%i) : %s",__FILE__,__LINE__,cg_get_error()); + if(ierr != CG_OK) { + Msg::Error("%s (%i) : %s", __FILE__, __LINE__, cg_get_error()); return false; } char family[maxLenCGNS]; ierr = cg_famname_read(family); - if (ierr == CG_ERROR) { - Msg::Error("%s (%i) : %s",__FILE__,__LINE__,cg_get_error()); + if(ierr == CG_ERROR) { + Msg::Error("%s (%i) : %s", __FILE__, __LINE__, cg_get_error()); return false; } - if (ierr == CG_OK) { - Msg::Info("Boundary condition is linked to family %s",family); + if(ierr == CG_OK) { + Msg::Info("Boundary condition is linked to family %s", family); } - - classToName[classIndex] = bcName; - switch (ptSetType) { + switch(ptSetType) { case ElementRange: case PointRange: case PointRangeDonor: - Msg::Info("Boundary condition %s is defined on %i %s", - bcName,elt[1]-elt[0]+1,cg_GridLocationName(location)); - for (cgsize_t i=elt[0];i<=elt[1];i++) eltToClass[i] = classIndex; + Msg::Info("Boundary condition %s is defined on %i %s", bcName, + elt[1] - elt[0] + 1, cg_GridLocationName(location)); + for(cgsize_t i = elt[0]; i <= elt[1]; i++) eltToClass[i] = classIndex; break; case ElementList: case PointList: case PointListDonor: - Msg::Info("Boundary condition %s is defined on %i %s", - bcName,nbElts,cg_GridLocationName(location)); - for (cgsize_t i=0;i<nbElts;i++) eltToClass[elt[i]] = classIndex; + Msg::Info("Boundary condition %s is defined on %i %s", bcName, nbElts, + cg_GridLocationName(location)); + for(cgsize_t i = 0; i < nbElts; i++) eltToClass[elt[i]] = classIndex; break; default: Msg::Error("Point set type %s is currently not supported " @@ -1175,19 +1137,15 @@ bool readCGNSBoundaryConditions(int fileIndex, return true; } -bool readCGNSPeriodicConnections - (int fileIndex, - int baseIndex, - int zoneIndex, - char* zoneName, - ZoneType_t zoneType, - std::set<CGNSUnstPeriodic, CGNSUnstPeriodicLess> &connections) +bool readCGNSPeriodicConnections( + int fileIndex, int baseIndex, int zoneIndex, char *zoneName, + ZoneType_t zoneType, + std::set<CGNSUnstPeriodic, CGNSUnstPeriodicLess> &connections) { int nbConn(0); - cg_nconns(fileIndex,baseIndex,zoneIndex,&nbConn); - - for (int connIndex=0;connIndex<nbConn;connIndex++){ + cg_nconns(fileIndex, baseIndex, zoneIndex, &nbConn); + for(int connIndex = 0; connIndex < nbConn; connIndex++) { GridLocation_t tgtLocation; GridConnectivityType_t connType; @@ -1201,118 +1159,109 @@ bool readCGNSPeriodicConnections char connName[maxLenCGNS]; char tgtName[maxLenCGNS]; - std::memcpy(tgtName,zoneName,maxLenCGNS*sizeof(char)); + std::memcpy(tgtName, zoneName, maxLenCGNS * sizeof(char)); char srcName[maxLenCGNS]; - cg_conn_info(fileIndex,baseIndex,zoneIndex,connIndex, - connName,&tgtLocation,&connType,&tgtSetType,&tgtSize, - srcName,&srcZoneType,&srcSetType,&srcDataType,&srcSize); + cg_conn_info(fileIndex, baseIndex, zoneIndex, connIndex, connName, + &tgtLocation, &connType, &tgtSetType, &tgtSize, srcName, + &srcZoneType, &srcSetType, &srcDataType, &srcSize); - if (connType != Abutting1to1) { + if(connType != Abutting1to1) { Msg::Error("Non-conformal connection not supported"); return false; } - cgsize_t* tgtPts = new cgsize_t[tgtSize]; - cgsize_t* srcPts = new cgsize_t[srcSize]; - - cg_conn_read(fileIndex,baseIndex,zoneIndex,connIndex,tgtPts,srcDataType,srcPts); + cgsize_t *tgtPts = new cgsize_t[tgtSize]; + cgsize_t *srcPts = new cgsize_t[srcSize]; - if (srcZoneType == Structured) break; + cg_conn_read(fileIndex, baseIndex, zoneIndex, connIndex, tgtPts, + srcDataType, srcPts); - float center[3] = {0,0,0}; - float angle[3] = {0,0,0}; - float disp[3] = {0,0,0}; + if(srcZoneType == Structured) break; - cg_conn_periodic_read(fileIndex,baseIndex,zoneIndex,connIndex, - center,angle,disp); + float center[3] = {0, 0, 0}; + float angle[3] = {0, 0, 0}; + float disp[3] = {0, 0, 0}; - connections.insert(CGNSUnstPeriodic(connName, - srcName,srcPts,srcSetType,srcSize, - tgtName,tgtPts,tgtSetType,tgtSize, - center,angle,disp)); + cg_conn_periodic_read(fileIndex, baseIndex, zoneIndex, connIndex, center, + angle, disp); + connections.insert(CGNSUnstPeriodic(connName, srcName, srcPts, srcSetType, + srcSize, tgtName, tgtPts, tgtSetType, + tgtSize, center, angle, disp)); - delete [] tgtPts; - delete [] srcPts; - + delete[] tgtPts; + delete[] srcPts; } return true; } // ----------------------------------------------------------------------------- -int addCGNSPoints(const string& fileName, - int fileIndex, - int baseIndex, - int zoneIndex, - cgsize_t nbPoints,int dim, - double scale, - GEntity* entity, - int& index, - std::vector<MVertex*>& vertices) +int addCGNSPoints(const string &fileName, int fileIndex, int baseIndex, + int zoneIndex, cgsize_t nbPoints, int dim, double scale, + GEntity *entity, int &index, std::vector<MVertex *> &vertices) { - int nbDim; - if (cg_ncoords(fileIndex,baseIndex,zoneIndex,&nbDim) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_ncoords(fileIndex, baseIndex, zoneIndex, &nbDim) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, __LINE__, + fileName.c_str(), cg_get_error()); return 0; } - if (nbDim != dim) { - Msg::Error("%s (%i) : Error reading CGNS file %s: incoherent coordinate count", - __FILE__,__LINE__,fileName.c_str()); + if(nbDim != dim) { + Msg::Error( + "%s (%i) : Error reading CGNS file %s: incoherent coordinate count", + __FILE__, __LINE__, fileName.c_str()); return 0; } - double* xyz = new double[nbPoints*3]; - for (int i=0;i<3*nbPoints;i++) xyz[i] = 0; - - for (int iCoord=0;iCoord<dim;iCoord++) { + double *xyz = new double[nbPoints * 3]; + for(int i = 0; i < 3 * nbPoints; i++) xyz[i] = 0; + for(int iCoord = 0; iCoord < dim; iCoord++) { char coordName[maxLenCGNS]; cgsize_t indBeg(1); DataType_t dataType; - if (cg_coord_info(fileIndex,baseIndex,zoneIndex, - iCoord+1, &dataType, coordName) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); - delete [] xyz; + if(cg_coord_info(fileIndex, baseIndex, zoneIndex, iCoord + 1, &dataType, + coordName) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); + delete[] xyz; return 0; } - if(cg_coord_read(fileIndex,baseIndex,zoneIndex,coordName, - RealDouble,&indBeg,&nbPoints,xyz+iCoord*nbPoints) != CG_OK ) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); - delete [] xyz; + if(cg_coord_read(fileIndex, baseIndex, zoneIndex, coordName, RealDouble, + &indBeg, &nbPoints, xyz + iCoord * nbPoints) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); + delete[] xyz; return 0; } } - const double* x = xyz; - const double* y = xyz + nbPoints; - const double* z = xyz + nbPoints*2; + const double *x = xyz; + const double *y = xyz + nbPoints; + const double *z = xyz + nbPoints * 2; - for (int i=0;i<nbPoints;i++) { - vertices.push_back(new MVertex(x[i]*scale,y[i]*scale,z[i]*scale,entity,index)); + for(int i = 0; i < nbPoints; i++) { + vertices.push_back( + new MVertex(x[i] * scale, y[i] * scale, z[i] * scale, entity, index)); index++; } - delete [] xyz; + delete[] xyz; return 1; } // ----------------------------------------------------------------------------- -int GModel::_readCGNSUnstructured(const std::string& fileName) +int GModel::_readCGNSUnstructured(const std::string &fileName) { - // --- global containers and indices for points and elements - std::map<int, std::vector<MElement*> > eltMap[10]; - std::vector<MVertex*> vertices; + std::map<int, std::vector<MElement *> > eltMap[10]; + std::vector<MVertex *> vertices; // --- keep connectivity information @@ -1324,42 +1273,44 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) int nbBases(0); double scale; - if (!openCGNSFile(fileName,fileIndex,nbBases,scale)) return 0; - + if(!openCGNSFile(fileName, fileIndex, nbBases, scale)) return 0; int baseIndex = 1; int topoDim(0); int meshDim(0); char baseName[maxLenCGNS]; - if (cg_base_read(fileIndex,baseIndex,baseName,&topoDim,&meshDim) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_base_read(fileIndex, baseIndex, baseName, &topoDim, &meshDim) != + CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, __LINE__, + fileName.c_str(), cg_get_error()); return 0; } // --- read boundary conditions to retain name for physical classification int nbFamilies(0); - if (cg_nfamilies(fileIndex,baseIndex,&nbFamilies) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_nfamilies(fileIndex, baseIndex, &nbFamilies) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, __LINE__, + fileName.c_str(), cg_get_error()); return 0; } - map<string,int> family; + map<string, int> family; - for (int familyIndex = 1;familyIndex<=nbFamilies;familyIndex++) { + for(int familyIndex = 1; familyIndex <= nbFamilies; familyIndex++) { char familyName[maxLenCGNS]; int nbBC; int nbGeo; - int ierr = cg_family_read(fileIndex,baseIndex,familyIndex,familyName,&nbBC,&nbGeo); - if (ierr != CG_OK) { + int ierr = cg_family_read(fileIndex, baseIndex, familyIndex, familyName, + &nbBC, &nbGeo); + if(ierr != CG_OK) { Msg::Error("%s (%i) : Error reading family %i in CGNS file %s : %s", - __FILE__,__LINE__,familyIndex,fileName.c_str(),cg_get_error()); + __FILE__, __LINE__, familyIndex, fileName.c_str(), + cg_get_error()); return 0; } - Msg::Info("Read family %s with index %i",familyName,familyIndex); + Msg::Info("Read family %s with index %i", familyName, familyIndex); family[familyName] = familyIndex; } @@ -1370,19 +1321,19 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) // keep renumbering table once generated - std::map<ElementType_t,int*> renumbering; + std::map<ElementType_t, int *> renumbering; // --- read mesh zones ------------------------------------------------------- int nbZones(0); - if (cg_nzones(fileIndex,baseIndex,&nbZones) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_nzones(fileIndex, baseIndex, &nbZones) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, __LINE__, + fileName.c_str(), cg_get_error()); return 0; } - - // --- node and element numbering is implicit in the zone, therefore offset required + // --- node and element numbering is implicit in the zone, therefore offset + // required // provide a global numbering @@ -1390,22 +1341,21 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) // classify zones following their index, and start new numbering beyond - std::map<int,std::string> classNames; + std::map<int, std::string> classNames; // retain global zone information - std::map<std::string,int> zoneIndices; - std::map<std::string,int> zoneOffsets; + std::map<std::string, int> zoneIndices; + std::map<std::string, int> zoneOffsets; // retain boundary conditions - std::map<int,std::string> bcToName; - std::map<int,std::string> zoneToName; + std::map<int, std::string> bcToName; + std::map<int, std::string> zoneToName; int classIndex = nbZones + 1; - for (int zoneIndex=1;zoneIndex<=nbZones;zoneIndex++) { - + for(int zoneIndex = 1; zoneIndex <= nbZones; zoneIndex++) { // --- using an offset to translate zone local numbering to global numbering int vtxOffset = vertices.size(); @@ -1414,22 +1364,23 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) // we can later add ijk here to allow for mixed meshes ZoneType_t zoneType; - if (cg_zone_type(fileIndex,baseIndex,zoneIndex,&zoneType) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_zone_type(fileIndex, baseIndex, zoneIndex, &zoneType) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } - if (zoneType != Unstructured) return 0; + if(zoneType != Unstructured) return 0; // --- get element counts cgsize_t sizes[3]; char zoneName[maxLenCGNS]; - if (cg_zone_read(fileIndex,baseIndex,zoneIndex,zoneName,sizes) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_zone_read(fileIndex, baseIndex, zoneIndex, zoneName, sizes) != + CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } @@ -1437,15 +1388,15 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) zoneIndices[zoneName] = zoneIndex; zoneOffsets[zoneName] = vtxOffset; - Msg::Info("Reading unstructured zone %s",zoneName); + Msg::Info("Reading unstructured zone %s", zoneName); cgsize_t nbPoints = sizes[0]; // --- read the family attached to the zone - if(cg_goto(fileIndex, baseIndex, "Zone_t", zoneIndex, "end") != CG_OK ) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_goto(fileIndex, baseIndex, "Zone_t", zoneIndex, "end") != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } @@ -1454,58 +1405,49 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) int ierr = cg_famname_read(zoneFamilyName); - if (ierr == CG_ERROR) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(ierr == CG_ERROR) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } - if (ierr == CG_OK) { - Msg::Info("Zone %i has family name %s",zoneIndex,zoneFamilyName); - map<string,int>::iterator fIter = family.find(zoneFamilyName); - if (fIter != family.end()) zoneFamilyIndex = fIter->second; - else Msg::Error("%s (%i) : Error reading CGNS file %s : " - "cannot find CGNS family in available list", - __FILE__,__LINE__,fileName.c_str()); - + if(ierr == CG_OK) { + Msg::Info("Zone %i has family name %s", zoneIndex, zoneFamilyName); + map<string, int>::iterator fIter = family.find(zoneFamilyName); + if(fIter != family.end()) + zoneFamilyIndex = fIter->second; + else + Msg::Error("%s (%i) : Error reading CGNS file %s : " + "cannot find CGNS family in available list", + __FILE__, __LINE__, fileName.c_str()); } // --- read coordinates and create vertices - addCGNSPoints(fileName, - fileIndex, - baseIndex, - zoneIndex, - nbPoints, - meshDim, - scale, - NULL, - vtxIndex, - vertices); + addCGNSPoints(fileName, fileIndex, baseIndex, zoneIndex, nbPoints, meshDim, + scale, NULL, vtxIndex, vertices); - Msg::Info("Read %i points",nbPoints); + Msg::Info("Read %i points", nbPoints); // --- provide a finer classification based on boundary conditions - std::map<int,int> eltToBC; + std::map<int, int> eltToBC; - bool topologyDefined = readCGNSBoundaryConditions(fileIndex,baseIndex, - zoneIndex,classIndex, - meshDim,eltToBC,bcToName); + bool topologyDefined = readCGNSBoundaryConditions( + fileIndex, baseIndex, zoneIndex, classIndex, meshDim, eltToBC, bcToName); // --- create element using the sections int nbSections; - if (cg_nsections(fileIndex,baseIndex,zoneIndex,&nbSections) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_nsections(fileIndex, baseIndex, zoneIndex, &nbSections) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } size_t eltIndex = 1; - for (int sectIndex=1;sectIndex<=nbSections;sectIndex++) { - + for(int sectIndex = 1; sectIndex <= nbSections; sectIndex++) { char sectName[maxLenCGNS]; ElementType_t cgnsType; cgsize_t eltBeg; @@ -1513,14 +1455,15 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) int nbBound; int parentFlag; - std::map<ElementType_t,int> elementCount; + std::map<ElementType_t, int> elementCount; // --- read connection block size - if (cg_section_read(fileIndex,baseIndex,zoneIndex,sectIndex,sectName, - &cgnsType,&eltBeg,&eltEnd,&nbBound,&parentFlag) != CG_OK ){ - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_section_read(fileIndex, baseIndex, zoneIndex, sectIndex, sectName, + &cgnsType, &eltBeg, &eltEnd, &nbBound, + &parentFlag) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } @@ -1529,107 +1472,105 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) // --- read connections cgsize_t sectSize; - if(cg_ElementDataSize(fileIndex,baseIndex,zoneIndex, - sectIndex,§Size)!=CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_ElementDataSize(fileIndex, baseIndex, zoneIndex, sectIndex, + §Size) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } // --- read elements - cgsize_t* elts = new cgsize_t[sectSize]; - + cgsize_t *elts = new cgsize_t[sectSize]; - if(cg_elements_read(fileIndex,baseIndex,zoneIndex,sectIndex, - elts,NULL)!=CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_elements_read(fileIndex, baseIndex, zoneIndex, sectIndex, elts, + NULL) != CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } // --- create elements - cgsize_t* pElt = elts; - for (int iElt=0;iElt<nbElt;iElt++,eltIndex++) { - - vector<MVertex*> vtcs; + cgsize_t *pElt = elts; + for(int iElt = 0; iElt < nbElt; iElt++, eltIndex++) { + vector<MVertex *> vtcs; ElementType_t myType = cgnsType; - if (cgnsType == MIXED) myType = (ElementType_t) *pElt++; + if(cgnsType == MIXED) myType = (ElementType_t)*pElt++; - if (elementCount.find(myType) == elementCount.end()) elementCount[myType] = 0; + if(elementCount.find(myType) == elementCount.end()) + elementCount[myType] = 0; elementCount[myType]++; - int eltType = tagFromCGNSType(myType); int eltSize = ElementType::getNumVertices(eltType); - int* renum = NULL; + int *renum = NULL; - std::map<ElementType_t,int*>::iterator rIter = renumbering.find(myType); - if (rIter == renumbering.end()) { + std::map<ElementType_t, int *>::iterator rIter = + renumbering.find(myType); + if(rIter == renumbering.end()) { renum = getRenumberingToGmsh(myType); renumbering[myType] = renum; } - else renum = rIter->second; + else + renum = rIter->second; - for (int iVtx=0;iVtx<eltSize;iVtx++) { - int num = vtxOffset + pElt[renum[iVtx]]-1; + for(int iVtx = 0; iVtx < eltSize; iVtx++) { + int num = vtxOffset + pElt[renum[iVtx]] - 1; vtcs.push_back(vertices[num]); } int topoIndex = zoneIndex; - std::map<int,int>::iterator tIter = eltToBC.find(eltIndex); - if (tIter!=eltToBC.end() && topologyDefined) topoIndex = tIter->second; + std::map<int, int>::iterator tIter = eltToBC.find(eltIndex); + if(tIter != eltToBC.end() && topologyDefined) topoIndex = tIter->second; pElt += eltSize; int partition(0); - createElementMSH(this, - eltIndex, - eltType, - topoIndex, - partition, - vtcs,eltMap); + createElementMSH(this, eltIndex, eltType, topoIndex, partition, vtcs, + eltMap); } std::ostringstream elementList; - std::map<ElementType_t,int>::iterator ecIter = elementCount.begin(); - for (;ecIter!=elementCount.end();++ecIter) { + std::map<ElementType_t, int>::iterator ecIter = elementCount.begin(); + for(; ecIter != elementCount.end(); ++ecIter) { elementList << ecIter->second << " " - << ElementType::nameOfParentType(parentFromCGNSType(ecIter->first)) + << ElementType::nameOfParentType( + parentFromCGNSType(ecIter->first)) << "s "; } - Msg::Info("Section %i of zone %i has %s", - sectIndex,zoneIndex,elementList.str().c_str()); + Msg::Info("Section %i of zone %i has %s", sectIndex, zoneIndex, + elementList.str().c_str()); - delete [] elts; + delete[] elts; } // readCGNSPeriodicConnections(fileIndex,baseIndex,zoneIndex,zoneName,zoneType,periodic); } - for (std::map<ElementType_t,int*>::iterator rIter=renumbering.begin(); - rIter!=renumbering.end();++rIter) delete [] rIter->second; + for(std::map<ElementType_t, int *>::iterator rIter = renumbering.begin(); + rIter != renumbering.end(); ++rIter) + delete[] rIter->second; removeDuplicateMeshVertices(1e-8); - for(int i = 0; i < 10 ; i++) _storeElementsInEntities(eltMap[i]); + for(int i = 0; i < 10; i++) _storeElementsInEntities(eltMap[i]); - if(CTX::instance()->mesh.cgnsConstructTopology) - createTopologyFromMeshNew(); + if(CTX::instance()->mesh.cgnsConstructTopology) createTopologyFromMeshNew(); - for (int zoneIndex=1;zoneIndex<=nbZones;zoneIndex++) { + for(int zoneIndex = 1; zoneIndex <= nbZones; zoneIndex++) { cgsize_t sizes[3]; char zoneName[maxLenCGNS]; - if (cg_zone_read(fileIndex,baseIndex,zoneIndex,zoneName,sizes) != CG_OK) { - Msg::Error("%s (%i) : Error reading CGNS file %s : %s", - __FILE__,__LINE__,fileName.c_str(),cg_get_error()); + if(cg_zone_read(fileIndex, baseIndex, zoneIndex, zoneName, sizes) != + CG_OK) { + Msg::Error("%s (%i) : Error reading CGNS file %s : %s", __FILE__, + __LINE__, fileName.c_str(), cg_get_error()); return 0; } - readCGNSPeriodicConnections(fileIndex,baseIndex, - zoneIndex,zoneName,Unstructured,periodic); + readCGNSPeriodicConnections(fileIndex, baseIndex, zoneIndex, zoneName, + Unstructured, periodic); } _associateEntityWithMeshVertices(); @@ -1637,56 +1578,54 @@ int GModel::_readCGNSUnstructured(const std::string& fileName) // add physical entities corresponding to the bc and zones - std::map<int,std::map<int,std::string> > physicalSurfaces; + std::map<int, std::map<int, std::string> > physicalSurfaces; - std::map<int,std::string>::iterator bIter = bcToName.begin(); - for (;bIter!=bcToName.end();bIter++) { + std::map<int, std::string>::iterator bIter = bcToName.begin(); + for(; bIter != bcToName.end(); bIter++) { int tag = bIter->first; std::string name = bIter->second; physicalSurfaces[tag][tag] = name; - physicalNames[std::make_pair(meshDim-1,tag)] = name; + physicalNames[std::make_pair(meshDim - 1, tag)] = name; } - _storePhysicalTagsInEntities(meshDim-1,physicalSurfaces); + _storePhysicalTagsInEntities(meshDim - 1, physicalSurfaces); - std::map<int,std::map<int,std::string> > physicalZones; + std::map<int, std::map<int, std::string> > physicalZones; - std::map<int,std::string>::iterator zIter = zoneToName.begin(); - for (;zIter!=zoneToName.end();zIter++) { + std::map<int, std::string>::iterator zIter = zoneToName.begin(); + for(; zIter != zoneToName.end(); zIter++) { int tag = zIter->first; std::string name = zIter->second; physicalZones[tag][tag] = name; - physicalNames[std::make_pair(meshDim,tag)] = name; + physicalNames[std::make_pair(meshDim, tag)] = name; } - _storePhysicalTagsInEntities(meshDim,physicalZones); + _storePhysicalTagsInEntities(meshDim, physicalZones); //_createGeometryOfDiscreteEntities(); return 1; } - // ----------------------------------------------------------------------------- int GModel::_readCGNSStructured(const std::string &name) { - // cgsize_t isize[9]; // char basename[33],zonename[33]; - std::map<int, std::vector<MElement*> > elements[10]; + std::map<int, std::vector<MElement *> > elements[10]; int index_file(-1); int nBases(0); double scale; - if (!openCGNSFile(name,index_file,nBases,scale)) return 0; - + if(!openCGNSFile(name, index_file, nBases, scale)) return 0; Msg::Debug("Found %i base(s).", nBases); - if (nBases > 1) { + if(nBases > 1) { Msg::Warning("Found %i bases in the file, " - "but only the first one will be used to build mesh.", nBases); + "but only the first one will be used to build mesh.", + nBases); } int index_base = 1; @@ -1699,20 +1638,19 @@ int GModel::_readCGNSStructured(const std::string &name) int max_order = 8; // Creating MVertex - std::map<int, MVertex*> vertexMap; + std::map<int, MVertex *> vertexMap; int minVertex = 1; int maxVertex = 0; int vnum = 1; - int* sizeIJK = new int[nZones*3]; - - for (int index_zone = 1; index_zone <= nZones; index_zone++) { + int *sizeIJK = new int[nZones * 3]; + for(int index_zone = 1; index_zone <= nZones; index_zone++) { Msg::Debug("Reading zone to compute MG level %i.", index_zone); ZoneType_t zoneType; cg_zone_type(index_file, index_base, index_zone, &zoneType); - if ( zoneType == Unstructured ) { + if(zoneType == Unstructured) { Msg::Info("Unstructured zone detected"); return 0; } @@ -1728,7 +1666,7 @@ int GModel::_readCGNSStructured(const std::string &name) irmax[0] = zoneSizes[0]; // irmin[1] = 1; irmax[1] = zoneSizes[1]; - //irmin[2] = 1; + // irmin[2] = 1; irmax[2] = zoneSizes[2]; // Compute max multigrid level @@ -1736,7 +1674,7 @@ int GModel::_readCGNSStructured(const std::string &name) double jelem = irmax[1] - 1; double kelem = irmax[2] - 1; - int * ijk = sizeIJK + (index_zone-1)*3; + int *ijk = sizeIJK + (index_zone - 1) * 3; ijk[0] = ielem; ijk[1] = jelem; @@ -1744,10 +1682,9 @@ int GModel::_readCGNSStructured(const std::string &name) // printf("Elems %g %g %g\n", ielem, jelem, kelem); int order = 1; - while(fmod(ielem / 2.0, 1.0) == 0.0 && - fmod(jelem / 2.0, 1.0) == 0.0 && + while(fmod(ielem / 2.0, 1.0) == 0.0 && fmod(jelem / 2.0, 1.0) == 0.0 && fmod(kelem / 2.0, 1.0) == 0.0 and order < 5) { - order*=2; + order *= 2; ielem = ielem / 2.0; jelem = jelem / 2.0; kelem = kelem / 2.0; @@ -1755,40 +1692,38 @@ int GModel::_readCGNSStructured(const std::string &name) max_order = min(order, max_order); } - opt_mesh_cgns_import_order(0, GMSH_SET, max_order); int order = CTX::instance()->mesh.cgnsImportOrder; #if defined(HAVE_FLTK) - if (CTX::instance()->batch == 0 && - FlGui::instance()->available() && - CTX::instance()->expertMode) { + if(CTX::instance()->batch == 0 && FlGui::instance()->available() && + CTX::instance()->expertMode) { order = cgnsImport(); CTX::instance()->mesh.order = order; } - else order = CTX::instance()->mesh.order; + else + order = CTX::instance()->mesh.order; #endif // check for the order bool checkAllDim = true; - for (int index_zone=1;index_zone<=nZones;index_zone++) { - int* ijk = sizeIJK + (index_zone-1)*3; + for(int index_zone = 1; index_zone <= nZones; index_zone++) { + int *ijk = sizeIJK + (index_zone - 1) * 3; bool checkDim = true; - for (int i=0;i<3;i++) checkDim = checkDim && (ijk[i] % order == 0); - if (!checkDim) { + for(int i = 0; i < 3; i++) checkDim = checkDim && (ijk[i] % order == 0); + if(!checkDim) { Msg::Error("Zone %d in CGNS file has size %dx%dx%d" "and can therefore not be coarsened to order %d", - index_zone,ijk[0],ijk[1],ijk[2],order); + index_zone, ijk[0], ijk[1], ijk[2], order); } checkAllDim = checkAllDim && checkDim; } - if (checkAllDim) { - + if(checkAllDim) { // determine the element types - int type_hex = ElementType::getType(TYPE_HEX,order); - int type_quad = ElementType::getType(TYPE_QUA,order); + int type_hex = ElementType::getType(TYPE_HEX, order); + int type_quad = ElementType::getType(TYPE_QUA, order); // for entity numbering int elementary_region = getNumRegions(); @@ -1796,17 +1731,17 @@ int GModel::_readCGNSStructured(const std::string &name) // int elementary_edge = getNumEdges(); // int elementary_vertex = getNumVertices(); - set<CGNSStruPeriodic,CGNSStruPeriodicLess> periodicConnections; + set<CGNSStruPeriodic, CGNSStruPeriodicLess> periodicConnections; // Read the zones - for (int index_zone = 1; index_zone <= nZones ; index_zone++) { + for(int index_zone = 1; index_zone <= nZones; index_zone++) { Msg::Debug("Reading zone %i.", index_zone); int offset = vnum; ZoneType_t zoneType; cg_zone_type(index_file, index_base, index_zone, &zoneType); - if ( zoneType == Unstructured ) { + if(zoneType == Unstructured) { Msg::Debug("Unstructured zone detected, skipping."); continue; } @@ -1819,9 +1754,12 @@ int GModel::_readCGNSStructured(const std::string &name) Msg::Debug("Zone name : %s.", zoneName); // Index bounds - irmin[0] = 1; irmax[0] = zoneSizes[0]; - irmin[1] = 1; irmax[1] = zoneSizes[1]; - irmin[2] = 1; irmax[2] = zoneSizes[2]; + irmin[0] = 1; + irmax[0] = zoneSizes[0]; + irmin[1] = 1; + irmax[1] = zoneSizes[1]; + irmin[2] = 1; + irmax[2] = zoneSizes[2]; // Compute max multigrid level // double ielem = irmax[0] - 1; @@ -1831,9 +1769,9 @@ int GModel::_readCGNSStructured(const std::string &name) int nnodesZone; int nelements; int nBoundaryVertices; - nnodesZone = zoneSizes[0]*zoneSizes[1]*zoneSizes[2]; - nelements = zoneSizes[3]*zoneSizes[4]*zoneSizes[5]; - nBoundaryVertices = zoneSizes[6]*zoneSizes[7]*zoneSizes[8]; + nnodesZone = zoneSizes[0] * zoneSizes[1] * zoneSizes[2]; + nelements = zoneSizes[3] * zoneSizes[4] * zoneSizes[5]; + nBoundaryVertices = zoneSizes[6] * zoneSizes[7] * zoneSizes[8]; Msg::Debug("%i nodes, %i elements, and %i vertices on the zone boundary.", nnodesZone, nelements, nBoundaryVertices); @@ -1843,47 +1781,47 @@ int GModel::_readCGNSStructured(const std::string &name) DataType_t dataType; char coordName[35]; - void* coord; + void *coord; double nodes[nnodesZone][nCoords]; - for ( int iCoord = 0; iCoord < nCoords; iCoord++ ) { - if ( cg_coord_info(index_file, index_base, index_zone, - iCoord+1, &dataType, coordName) ) { - Msg::Error("Could not read coordinate %i.", iCoord+1); - cg_close (index_file); + for(int iCoord = 0; iCoord < nCoords; iCoord++) { + if(cg_coord_info(index_file, index_base, index_zone, iCoord + 1, + &dataType, coordName)) { + Msg::Error("Could not read coordinate %i.", iCoord + 1); + cg_close(index_file); return 0; } - Msg::Debug("Reading coordinate %i : %s.", iCoord+1, coordName); + Msg::Debug("Reading coordinate %i : %s.", iCoord + 1, coordName); switch(dataType) { case RealSingle: Msg::Debug(" [Type is float]"); coord = new float[nnodesZone]; - if ( cg_coord_read(index_file, index_base, index_zone, - coordName, dataType, irmin, irmax, coord)) { - Msg::Error("Could not read coordinate %i.", iCoord+1); + if(cg_coord_read(index_file, index_base, index_zone, coordName, + dataType, irmin, irmax, coord)) { + Msg::Error("Could not read coordinate %i.", iCoord + 1); cg_close(index_file); return 0; } - for (int iNode = 0; iNode < nnodesZone; iNode++) { - nodes[iNode][iCoord] = (double)((float*)coord)[iNode] * scale; + for(int iNode = 0; iNode < nnodesZone; iNode++) { + nodes[iNode][iCoord] = (double)((float *)coord)[iNode] * scale; } - delete [] (float*)coord; + delete[](float *) coord; break; case RealDouble: Msg::Debug(" [Type is double]"); coord = new double[nnodesZone]; - if ( cg_coord_read(index_file, index_base, index_zone, - coordName, dataType, irmin, irmax, coord)) { - Msg::Error("Could not read coordinate %i.", iCoord+1); + if(cg_coord_read(index_file, index_base, index_zone, coordName, + dataType, irmin, irmax, coord)) { + Msg::Error("Could not read coordinate %i.", iCoord + 1); cg_close(index_file); return 0; } - for (int iNode = 0; iNode < nnodesZone; iNode++) { - nodes[iNode][iCoord] = ((double*) coord)[iNode] * scale; + for(int iNode = 0; iNode < nnodesZone; iNode++) { + nodes[iNode][iCoord] = ((double *)coord)[iNode] * scale; } - delete [] (double*)coord; + delete[](double *) coord; break; default: Msg::Error("Wrong data type for reading coordinates in CGNS file"); @@ -1891,34 +1829,34 @@ int GModel::_readCGNSStructured(const std::string &name) } } - for (int iNode = 0; iNode < nnodesZone; iNode++) { - MVertex* mv = new MVertex(nodes[iNode][0], nodes[iNode][1], + for(int iNode = 0; iNode < nnodesZone; iNode++) { + MVertex *mv = new MVertex(nodes[iNode][0], nodes[iNode][1], nodes[iNode][2], 0, vnum); minVertex = std::min(minVertex, vnum); maxVertex = std::max(maxVertex, vnum); vertexMap[vnum] = mv; - vnum ++; + vnum++; } - int num = 1; int num_elements = 0; - elementary_region ++; + elementary_region++; int partition = 0; - for (int i = 0; i < zoneSizes[3]; i+=order) { - for (int j = 0; j < zoneSizes[4]; j+=order) { - for (int k = 0; k < zoneSizes[5]; k+=order) { - std::vector<MVertex*> vertices; + for(int i = 0; i < zoneSizes[3]; i += order) { + for(int j = 0; j < zoneSizes[4]; j += order) { + for(int k = 0; k < zoneSizes[5]; k += order) { + std::vector<MVertex *> vertices; std::vector<int> ind_i, ind_j, ind_k; getIndices(i, j, k, ind_i, ind_j, ind_k, order); - for (size_t v = 0; v < ind_i.size(); v++) { - vertices.push_back(vertexMap[offset+to1D(ind_i[v],ind_j[v],ind_k[v], - irmax[0],irmax[1],irmax[2])]); + for(size_t v = 0; v < ind_i.size(); v++) { + vertices.push_back( + vertexMap[offset + to1D(ind_i[v], ind_j[v], ind_k[v], irmax[0], + irmax[1], irmax[2])]); } - createElementMSH(this, num, type_hex, elementary_region, - partition, vertices, elements); + createElementMSH(this, num, type_hex, elementary_region, partition, + vertices, elements); num_elements++; num++; } @@ -1927,26 +1865,25 @@ int GModel::_readCGNSStructured(const std::string &name) // Create surface mesh, remove internal connections and encode periodicity - - std::map<int, std::vector<int*> > forbidden; + std::map<int, std::vector<int *> > forbidden; int nconnectivity; cg_n1to1(index_file, index_base, index_zone, &nconnectivity); Msg::Debug("Found %i connectivity zones.", nconnectivity); - for (int index_section = 1; index_section <= nconnectivity; index_section++) { - + for(int index_section = 1; index_section <= nconnectivity; + index_section++) { char ConnectionName[30]; char DonorName[30]; cgsize_t range[6]; cgsize_t donor_range[6]; int transform[3]; - cg_1to1_read(index_file, index_base, index_zone,index_section, + cg_1to1_read(index_file, index_base, index_zone, index_section, ConnectionName, DonorName, range, donor_range, transform); // --- face indices in the block and in the global geometry - int face = computeCGNSFace(range); - int faceIndex = elementary_face + face + 1; + int face = computeCGNSFace(range); + int faceIndex = elementary_face + face + 1; // --- encode periodic boundary transformation / connection information @@ -1954,43 +1891,37 @@ int GModel::_readCGNSStructured(const std::string &name) float RotationAngle[3]; float Translation[3]; - if (cg_1to1_periodic_read(index_file, - index_base, - index_zone, - index_section, - RotationCenter, - RotationAngle, - Translation) != CG_NODE_NOT_FOUND) { - CGNSStruPeriodic pnew(zoneName,range, - DonorName,donor_range,transform,order,faceIndex, - RotationCenter,RotationAngle,Translation); + if(cg_1to1_periodic_read(index_file, index_base, index_zone, + index_section, RotationCenter, RotationAngle, + Translation) != CG_NODE_NOT_FOUND) { + CGNSStruPeriodic pnew(zoneName, range, DonorName, donor_range, + transform, order, faceIndex, RotationCenter, + RotationAngle, Translation); CGNSStruPeriodic pinv(pnew.getInverse()); - set<CGNSStruPeriodic,CGNSStruPeriodicLess>::iterator pIter = + set<CGNSStruPeriodic, CGNSStruPeriodicLess>::iterator pIter = periodicConnections.find(pinv); // create a new connection if inverse not found - if (pIter == periodicConnections.end()) { - for (size_t ip=0;ip<pnew.getNbPoints();ip++) { - int i(0),j(0),k(0); - pnew.getTgtIJK(ip,i,j,k); - pnew.insertTgtVertex(ip,vertexMap[offset+to1D(i,j,k, - irmax[0], - irmax[1], - irmax[2])]); + if(pIter == periodicConnections.end()) { + for(size_t ip = 0; ip < pnew.getNbPoints(); ip++) { + int i(0), j(0), k(0); + pnew.getTgtIJK(ip, i, j, k); + pnew.insertTgtVertex( + ip, vertexMap[offset + + to1D(i, j, k, irmax[0], irmax[1], irmax[2])]); } periodicConnections.insert(pnew); } // if inverse is found, we need to complete else { pIter->srcFaceId = faceIndex; - for (size_t ip=0;ip<pIter->getNbPoints();ip++) { - int i(0),j(0),k(0); - pIter->getSrcIJK(ip,i,j,k); - pIter->insertSrcVertex(ip,vertexMap[offset+to1D(i,j,k, - irmax[0], - irmax[1], - irmax[2])]); + for(size_t ip = 0; ip < pIter->getNbPoints(); ip++) { + int i(0), j(0), k(0); + pIter->getSrcIJK(ip, i, j, k); + pIter->insertSrcVertex( + ip, vertexMap[offset + + to1D(i, j, k, irmax[0], irmax[1], irmax[2])]); } } } @@ -1998,8 +1929,8 @@ int GModel::_readCGNSStructured(const std::string &name) // --- ignore internal connections else { - int* range_int = new int[6]; - for (int r = 0; r < 6; r++) range_int[r] = (int)range[r]; + int *range_int = new int[6]; + for(int r = 0; r < 6; r++) range_int[r] = (int)range[r]; forbidden[face].push_back(range_int); } } @@ -2009,105 +1940,190 @@ int GModel::_readCGNSStructured(const std::string &name) int igrow = order; int jgrow = order; int kgrow = order; - int move[3][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0}}; + int move[3][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}; switch(face) { case 0: - imin = 0; imax = zoneSizes[3]; - jmin = 0; jmax = zoneSizes[4]; - kmin = 0; kmax = 1; kgrow = 0; - move[0][0] = 0; move[0][1] = 0; move[0][2] = igrow; move[0][3] = igrow; - move[1][0] = 0; move[1][1] = jgrow; move[1][2] = jgrow; move[1][3] = 0; - move[2][0] = 0; move[2][1] = 0; move[2][2] = 0; move[2][3] = 0; + imin = 0; + imax = zoneSizes[3]; + jmin = 0; + jmax = zoneSizes[4]; + kmin = 0; + kmax = 1; + kgrow = 0; + move[0][0] = 0; + move[0][1] = 0; + move[0][2] = igrow; + move[0][3] = igrow; + move[1][0] = 0; + move[1][1] = jgrow; + move[1][2] = jgrow; + move[1][3] = 0; + move[2][0] = 0; + move[2][1] = 0; + move[2][2] = 0; + move[2][3] = 0; break; case 1: - imin = 0; imax = zoneSizes[3]; - jmin = 0; jmax = zoneSizes[4]; - kmin = zoneSizes[2]-1; kmax = zoneSizes[2]; kgrow = 0; - move[0][0] = 0; move[0][1] = igrow; move[0][2] = igrow; move[0][3] = 0; - move[1][0] = 0; move[1][1] = 0; move[1][2] = jgrow; move[1][3] = jgrow; - move[2][0] = 0; move[2][1] = 0; move[2][2] = 0; move[2][3] = 0; + imin = 0; + imax = zoneSizes[3]; + jmin = 0; + jmax = zoneSizes[4]; + kmin = zoneSizes[2] - 1; + kmax = zoneSizes[2]; + kgrow = 0; + move[0][0] = 0; + move[0][1] = igrow; + move[0][2] = igrow; + move[0][3] = 0; + move[1][0] = 0; + move[1][1] = 0; + move[1][2] = jgrow; + move[1][3] = jgrow; + move[2][0] = 0; + move[2][1] = 0; + move[2][2] = 0; + move[2][3] = 0; break; case 2: - imin = 0; imax = zoneSizes[3]; - jmin = 0; jmax = 1; jgrow = 0; - kmin = 0; kmax = zoneSizes[5]; - move[0][0] = 0; move[0][1] = igrow; move[0][2] = igrow; move[0][3] = 0; - move[1][0] = 0; move[1][1] = 0; move[1][2] = 0; move[1][3] = 0; - move[2][0] = 0; move[2][1] = 0; move[2][2] = kgrow; move[2][3] = kgrow; + imin = 0; + imax = zoneSizes[3]; + jmin = 0; + jmax = 1; + jgrow = 0; + kmin = 0; + kmax = zoneSizes[5]; + move[0][0] = 0; + move[0][1] = igrow; + move[0][2] = igrow; + move[0][3] = 0; + move[1][0] = 0; + move[1][1] = 0; + move[1][2] = 0; + move[1][3] = 0; + move[2][0] = 0; + move[2][1] = 0; + move[2][2] = kgrow; + move[2][3] = kgrow; break; case 3: - imin = 0; imax = zoneSizes[3]; - jmin = zoneSizes[1]-1; jmax = zoneSizes[1]; jgrow = 0; - kmin = 0; kmax = zoneSizes[5]; - move[0][0] = 0; move[0][1] = 0; move[0][2] = igrow; move[0][3] = igrow; - move[1][0] = 0; move[1][1] = 0; move[1][2] = 0; move[1][3] = 0; - move[2][0] = 0; move[2][1] = kgrow; move[2][2] = kgrow; move[2][3] = 0; + imin = 0; + imax = zoneSizes[3]; + jmin = zoneSizes[1] - 1; + jmax = zoneSizes[1]; + jgrow = 0; + kmin = 0; + kmax = zoneSizes[5]; + move[0][0] = 0; + move[0][1] = 0; + move[0][2] = igrow; + move[0][3] = igrow; + move[1][0] = 0; + move[1][1] = 0; + move[1][2] = 0; + move[1][3] = 0; + move[2][0] = 0; + move[2][1] = kgrow; + move[2][2] = kgrow; + move[2][3] = 0; break; case 4: - imin = 0; imax = 1; igrow = 0; - jmin = 0; jmax = zoneSizes[4]; - kmin = 0; kmax = zoneSizes[5]; - move[0][0] = 0; move[0][1] = 0; move[0][2] = 0; move[0][3] = 0; - move[1][0] = 0; move[1][1] = 0; move[1][2] = jgrow; move[1][3] = jgrow; - move[2][0] = 0; move[2][1] = kgrow; move[2][2] = kgrow; move[2][3] = 0; + imin = 0; + imax = 1; + igrow = 0; + jmin = 0; + jmax = zoneSizes[4]; + kmin = 0; + kmax = zoneSizes[5]; + move[0][0] = 0; + move[0][1] = 0; + move[0][2] = 0; + move[0][3] = 0; + move[1][0] = 0; + move[1][1] = 0; + move[1][2] = jgrow; + move[1][3] = jgrow; + move[2][0] = 0; + move[2][1] = kgrow; + move[2][2] = kgrow; + move[2][3] = 0; break; case 5: - imin = zoneSizes[0]-1; imax = zoneSizes[0]; igrow = 0; - jmin = 0; jmax = zoneSizes[4]; - kmin = 0; kmax = zoneSizes[5]; - move[0][0] = 0; move[0][1] = 0; move[0][2] = 0; move[0][3] = 0; - move[1][0] = 0; move[1][1] = jgrow; move[1][2] = jgrow; move[1][3] = 0; - move[2][0] = 0; move[2][1] = 0; move[2][2] = kgrow; move[2][3] = kgrow; + imin = zoneSizes[0] - 1; + imax = zoneSizes[0]; + igrow = 0; + jmin = 0; + jmax = zoneSizes[4]; + kmin = 0; + kmax = zoneSizes[5]; + move[0][0] = 0; + move[0][1] = 0; + move[0][2] = 0; + move[0][3] = 0; + move[1][0] = 0; + move[1][1] = jgrow; + move[1][2] = jgrow; + move[1][3] = 0; + move[2][0] = 0; + move[2][1] = 0; + move[2][2] = kgrow; + move[2][3] = kgrow; break; } - GRegion* gr = getRegionByTag(elementary_region); + GRegion *gr = getRegionByTag(elementary_region); elementary_face++; num = 1; - for (int i = imin; i < imax; i += order) { - for (int j = jmin; j < jmax; j += order) { - for (int k = kmin; k < kmax; k += order) { + for(int i = imin; i < imax; i += order) { + for(int j = jmin; j < jmax; j += order) { + for(int k = kmin; k < kmax; k += order) { bool ok = true; - for (size_t ff=0; ff < forbidden[face].size(); ff++) { - int* lim = forbidden[face][ff]; - - if ((i >= fmin(lim[0], lim[3])-1 && i < fmax(lim[0], lim[3])-1) || (igrow == 0) ) { - if ((j >= fmin(lim[1], lim[4])-1 && j < fmax(lim[1],lim[4])-1) || (jgrow == 0) ) { - if ((k >= fmin(lim[2], lim[5])-1 && k < fmax(lim[2], lim[5])-1) || (kgrow == 0) ) { + for(size_t ff = 0; ff < forbidden[face].size(); ff++) { + int *lim = forbidden[face][ff]; + + if((i >= fmin(lim[0], lim[3]) - 1 && + i < fmax(lim[0], lim[3]) - 1) || + (igrow == 0)) { + if((j >= fmin(lim[1], lim[4]) - 1 && + j < fmax(lim[1], lim[4]) - 1) || + (jgrow == 0)) { + if((k >= fmin(lim[2], lim[5]) - 1 && + k < fmax(lim[2], lim[5]) - 1) || + (kgrow == 0)) { ok = false; } } } - //if (!ok) continue; - + // if (!ok) continue; } - if (!ok) continue; + if(!ok) continue; - std::vector<MVertex*> vertices; + std::vector<MVertex *> vertices; std::vector<int> ind_i, ind_j, ind_k; - getIndicesQuad(i+move[0][0],i+move[0][1], i+move[0][2], i+move[0][3], - j+move[1][0],j+move[1][1], j+move[1][2], j+move[1][3], - k+move[2][0],k+move[2][1], k+move[2][2], k+move[2][3], + getIndicesQuad(i + move[0][0], i + move[0][1], i + move[0][2], + i + move[0][3], j + move[1][0], j + move[1][1], + j + move[1][2], j + move[1][3], k + move[2][0], + k + move[2][1], k + move[2][2], k + move[2][3], ind_i, ind_j, ind_k, order, face); - for (size_t v = 0; v < ind_i.size(); v++) { - vertices.push_back(vertexMap[offset+to1D(ind_i[v], ind_j[v], ind_k[v], - irmax[0], irmax[1], irmax[2])]); + for(size_t v = 0; v < ind_i.size(); v++) { + vertices.push_back( + vertexMap[offset + to1D(ind_i[v], ind_j[v], ind_k[v], + irmax[0], irmax[1], irmax[2])]); } - createElementMSH(this, num, type_quad, elementary_face, - partition, vertices, elements); + createElementMSH(this, num, type_quad, elementary_face, partition, + vertices, elements); num_elements++; num++; } } } - GFace* gf = getFaceByTag(elementary_face); - if (gf) gf->addRegion(gr); + GFace *gf = getFaceByTag(elementary_face); + if(gf) gf->addRegion(gr); - for (size_t ff = 0; ff < forbidden[face].size(); ff++) + for(size_t ff = 0; ff < forbidden[face].size(); ff++) delete[] forbidden[face][ff]; } } @@ -2124,28 +2140,27 @@ int GModel::_readCGNSStructured(const std::string &name) // --- now encode the periodic boundaries - set<CGNSStruPeriodic,CGNSStruPeriodicLess>::iterator pIter = + set<CGNSStruPeriodic, CGNSStruPeriodicLess>::iterator pIter = periodicConnections.begin(); - for (;pIter!=periodicConnections.end();++pIter) { - - GFace* tgt = getFaceByTag(pIter->tgtFaceId); - GFace* src = getFaceByTag(pIter->srcFaceId); + for(; pIter != periodicConnections.end(); ++pIter) { + GFace *tgt = getFaceByTag(pIter->tgtFaceId); + GFace *src = getFaceByTag(pIter->srcFaceId); - tgt->setMeshMaster(src,pIter->tfo); + tgt->setMeshMaster(src, pIter->tfo); - std::vector<MVertex*>::const_iterator tIter = pIter->tgtVertices.begin(); - std::vector<MVertex*>::const_iterator sIter = pIter->srcVertices.begin(); + std::vector<MVertex *>::const_iterator tIter = pIter->tgtVertices.begin(); + std::vector<MVertex *>::const_iterator sIter = pIter->srcVertices.begin(); - for (;tIter!=pIter->tgtVertices.end();++tIter,++sIter) { + for(; tIter != pIter->tgtVertices.end(); ++tIter, ++sIter) { tgt->correspondingVertices[*tIter] = *sIter; } } removeDuplicateMeshVertices(1e-8); - //createTopologyFromMesh(); + // createTopologyFromMesh(); - if ( cg_close (index_file) ) { + if(cg_close(index_file)) { Msg::Error("Couldn't close the file !"); return 0; } @@ -2154,16 +2169,13 @@ int GModel::_readCGNSStructured(const std::string &name) return 0; } - - -int GModel::readCGNS(const std::string &name) { - +int GModel::readCGNS(const std::string &name) +{ int structured = _readCGNSStructured(name); - if (structured) return structured; + if(structured) return structured; return _readCGNSUnstructured(name); } - /******************************************************************************* * * Routine writeCGNS @@ -2186,14 +2198,9 @@ int GModel::readCGNS(const std::string &name) { int GModel::writeCGNS(const std::string &name, int zoneDefinition, const CGNSOptions &options, double scalingFactor) { - enum { - vertex = 0, - edge = 1, - face = 2, - region = 3 - }; + enum { vertex = 0, edge = 1, face = 2, region = 3 }; - PhysGroupMap groups[4]; // vector of entities that belong to + PhysGroupMap groups[4]; // vector of entities that belong to // each physical group (in each // dimension) std::vector<DummyPartitionEntity> partitions; @@ -2205,14 +2212,16 @@ int GModel::writeCGNS(const std::string &name, int zoneDefinition, Msg::Warning("CGNS I/O is at an \"alpha\" software stage"); switch(zoneDefinition) { - case 1: // By partition + case 1: // By partition - //--Group the elements of each partition into a dummy entity. Pointers to the + //--Group the elements of each partition into a dummy entity. Pointers to + //the //--entities are then made available in groups[DIM][0]. { numZone = _numPartitions; - if(numZone == 0) zoneDefinition = 0; + if(numZone == 0) + zoneDefinition = 0; else { partitions.resize(numZone); unsigned numElem[5]; @@ -2221,7 +2230,10 @@ int GModel::writeCGNS(const std::string &name, int zoneDefinition, switch(meshDim) { case 3: for(riter it = firstRegion(); it != lastRegion(); ++it) { - numElem[0] = 0; numElem[1] = 0; numElem[2] = 0; numElem[3] = 0; + numElem[0] = 0; + numElem[1] = 0; + numElem[2] = 0; + numElem[3] = 0; numElem[4] = 0; (*it)->getNumMeshElements(numElem); const int nType = (*it)->getNumElementTypes(); @@ -2229,15 +2241,18 @@ int GModel::writeCGNS(const std::string &name, int zoneDefinition, MElement *const *element = (*it)->getStartElementType(iType); const int nElem = numElem[iType]; for(int iElem = 0; iElem != nElem; ++iElem) { - partitions[element[iElem]->getPartition() - 1].elements - .push_back(element[iElem]); + partitions[element[iElem]->getPartition() - 1] + .elements.push_back(element[iElem]); } } } break; case 2: for(fiter it = firstFace(); it != lastFace(); ++it) { - numElem[0] = 0; numElem[1] = 0; numElem[2] = 0; numElem[3] = 0; + numElem[0] = 0; + numElem[1] = 0; + numElem[2] = 0; + numElem[3] = 0; numElem[4] = 0; (*it)->getNumMeshElements(numElem); const int nType = (*it)->getNumElementTypes(); @@ -2245,25 +2260,23 @@ int GModel::writeCGNS(const std::string &name, int zoneDefinition, MElement *const *element = (*it)->getStartElementType(iType); const int nElem = numElem[iType]; for(int iElem = 0; iElem != nElem; ++iElem) { - partitions[element[iElem]->getPartition() - 1].elements - .push_back(element[iElem]); + partitions[element[iElem]->getPartition() - 1] + .elements.push_back(element[iElem]); } } } break; - default: - Msg::Error("No mesh elements were found"); - return 0; + default: Msg::Error("No mesh elements were found"); return 0; } // Place pointers to the entities in the 'groups' object - std::vector<GEntity*> &ents = groups[meshDim][0]; + std::vector<GEntity *> &ents = groups[meshDim][0]; ents.resize(numZone); for(int iPart = 0; iPart != numZone; ++iPart) ents[iPart] = &partitions[iPart]; } } break; - case 2: // By physical + case 2: // By physical //--Get a list of groups in each dimension and each of the entities in that //--group. @@ -2278,42 +2291,40 @@ int GModel::writeCGNS(const std::string &name, int zoneDefinition, meshDim = 2; } else { - zoneDefinition = 0; // Use single zone + zoneDefinition = 0; // Use single zone } break; } - //--For a single zone, put all the entities for a dimension into groups[DIM][0] + //--For a single zone, put all the entities for a dimension into + //groups[DIM][0] if(zoneDefinition == 0) { numZone = 1; unsigned numElem[5]; - numElem[0] = 0; numElem[1] = 0; numElem[2] = 0; numElem[3] = 0; numElem[4] = 0; + numElem[0] = 0; + numElem[1] = 0; + numElem[2] = 0; + numElem[3] = 0; + numElem[4] = 0; meshDim = getNumMeshElements(numElem); switch(meshDim) { - case 3: - { - groups[region].clear(); - std::vector<GEntity*> &ents = groups[region][0]; - ents.resize(getNumRegions()); - int iEnt = 0; - for(riter it = firstRegion(); it != lastRegion(); ++it) - ents[iEnt++] = *it; - } - break; - case 2: - { - groups[face].clear(); - std::vector<GEntity*> &ents = groups[face][0]; - ents.resize(getNumFaces()); - int iEnt = 0; - for(fiter it = firstFace(); it != lastFace(); ++it) - ents[iEnt++] = *it; - } - break; - default: - Msg::Error("No mesh elements were found"); - return 0; + case 3: { + groups[region].clear(); + std::vector<GEntity *> &ents = groups[region][0]; + ents.resize(getNumRegions()); + int iEnt = 0; + for(riter it = firstRegion(); it != lastRegion(); ++it) + ents[iEnt++] = *it; + } break; + case 2: { + groups[face].clear(); + std::vector<GEntity *> &ents = groups[face][0]; + ents.resize(getNumFaces()); + int iEnt = 0; + for(fiter it = firstFace(); it != lastFace(); ++it) ents[iEnt++] = *it; + } break; + default: Msg::Error("No mesh elements were found"); return 0; } } @@ -2334,35 +2345,33 @@ int GModel::writeCGNS(const std::string &name, int zoneDefinition, if(meshDim == 2) vectorDim = options.vectorDim; // open the file - int cgIndexFile=0; + int cgIndexFile = 0; if(cg_open(name.c_str(), CG_MODE_WRITE, &cgIndexFile)) return cgnsErr(); // write the base node - int cgIndexBase=0; + int cgIndexBase = 0; if(cg_base_write(cgIndexFile, options.baseName.c_str(), meshDim, meshDim, &cgIndexBase)) return cgnsErr(); // write information about who generated the mesh - if(cg_goto(cgIndexFile, cgIndexBase, "end")) return(cgnsErr()); + if(cg_goto(cgIndexFile, cgIndexBase, "end")) return (cgnsErr()); if(cg_descriptor_write("About", "Created by Gmsh")) return cgnsErr(); switch(meshDim) { case 2: MZone<2>::preInit(); MZoneBoundary<2>::preInit(); - write_CGNS_zones<2>(*this, zoneDefinition, numZone, options, - scalingFactor, vectorDim, groups[face], - cgIndexFile, cgIndexBase); + write_CGNS_zones<2>(*this, zoneDefinition, numZone, options, scalingFactor, + vectorDim, groups[face], cgIndexFile, cgIndexBase); MZone<2>::postDestroy(); MZoneBoundary<2>::postDestroy(); break; case 3: MZone<3>::preInit(); MZoneBoundary<3>::preInit(); - write_CGNS_zones<3>(*this, zoneDefinition, numZone, options, - scalingFactor, vectorDim, groups[region], - cgIndexFile, cgIndexBase); + write_CGNS_zones<3>(*this, zoneDefinition, numZone, options, scalingFactor, + vectorDim, groups[region], cgIndexFile, cgIndexBase); MZone<3>::postDestroy(); MZoneBoundary<3>::postDestroy(); break; @@ -2375,7 +2384,6 @@ int GModel::writeCGNS(const std::string &name, int zoneDefinition, return 0; } - /******************************************************************************* * * Routine tranlateElementMSH2CGNS @@ -2398,38 +2406,26 @@ void translateElementMSH2CGNS(ElementConnectivity *const zoneElemConn) { const int maxVPE = 27; // Location to write a MSH_TET_10 vertex to get a CGNS TETRA_10 - static const int trTET10[10] = { - 0, 1, 2, 3, 4, 5, 6, 7, 9, 8 - }; + static const int trTET10[10] = {0, 1, 2, 3, 4, 5, 6, 7, 9, 8}; // Location to write a MSH_HEX_20 vertex to get a CGNS HEXA_20 - static const int trHEX20[20] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 9, 13, 10, 14, 15, 16, 19, 17, 18 - }; + static const int trHEX20[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, + 12, 9, 13, 10, 14, 15, 16, 19, 17, 18}; // Location to write a MSH_HEX_27 vertex to get a CGNS HEXA_27 - static const int trHEX27[27] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 9, 13, 10, 14, 15, 16, 19, 17, 18, - 20, 21, 24, 22, 23, 25, 26 - }; + static const int trHEX27[27] = {0, 1, 2, 3, 4, 5, 6, 7, 8, + 11, 12, 9, 13, 10, 14, 15, 16, 19, + 17, 18, 20, 21, 24, 22, 23, 25, 26}; // Location to write a MSH_PRI_15 vertex to get a CGNS PENTA_15 - static const int trPRI15[15] = { - 0, 1, 2, 3, 4, 5, 6, 8, 9, 7, 10, 11, 12, 14, 13 - }; + static const int trPRI15[15] = {0, 1, 2, 3, 4, 5, 6, 8, + 9, 7, 10, 11, 12, 14, 13}; // Location to write a MSH_PRI_18 vertex to get a CGNS PENTA_18 - static const int trPRI18[18] = { - 0, 1, 2, 3, 4, 5, 6, 8, 9, 7, 10, 11, 12, 14, 13, - 15, 17, 16 - }; + static const int trPRI18[18] = {0, 1, 2, 3, 4, 5, 6, 8, 9, + 7, 10, 11, 12, 14, 13, 15, 17, 16}; // Location to write a MSH_PYR_13 vertex to get a CGNS PYRA_13 // PYRA_13 are not in the CGNS standard but if ever added they would have the // same ordering as PYRA_14 - static const int trPYR13[13] = { - 0, 1, 2, 3, 4, 5, 8, 9, 6, 10, 7, 11, 12 - }; + static const int trPYR13[13] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 10, 7, 11, 12}; // Location to write a MSH_PYR_14 vertex to get a CGNS PYRA_14 - static const int trPYR14[14] = { - 0, 1, 2, 3, 4, 5, 8, 9, 6, 10, 7, 11, 12, - 13 - }; + static const int trPYR14[14] = {0, 1, 2, 3, 4, 5, 8, 9, 6, 10, 7, 11, 12, 13}; int tmp[maxVPE]; for(int iElemType = 0; iElemType != MSH_NUM_TYPE; ++iElemType) { @@ -2438,33 +2434,33 @@ void translateElementMSH2CGNS(ElementConnectivity *const zoneElemConn) if(zoneElemConn[iElemType].numElem > 0) { switch(iElemType + 1) { case MSH_TET_10: - numVPE = 10; - tr = trTET10; + numVPE = 10; + tr = trTET10; break; case MSH_HEX_20: - numVPE = 20; - tr = trHEX20; + numVPE = 20; + tr = trHEX20; break; case MSH_HEX_27: - numVPE = 27; - tr = trHEX27; + numVPE = 27; + tr = trHEX27; break; case MSH_PRI_15: - numVPE = 15; - tr = trPRI15; + numVPE = 15; + tr = trPRI15; break; case MSH_PRI_18: - numVPE = 18; - tr = trPRI18; + numVPE = 18; + tr = trPRI18; break; - case MSH_PYR_13: // Although not in the CGNS standard, I assume it would - // be the same as PYRA_14 if ever added - numVPE = 13; - tr = trPYR13; + case MSH_PYR_13: // Although not in the CGNS standard, I assume it would + // be the same as PYRA_14 if ever added + numVPE = 13; + tr = trPYR13; break; case MSH_PYR_14: - numVPE = 14; - tr = trPYR14; + numVPE = 14; + tr = trPYR14; break; default: numVPE = 0; @@ -2473,8 +2469,8 @@ void translateElementMSH2CGNS(ElementConnectivity *const zoneElemConn) } if(numVPE > 0) { int *aConn = &zoneElemConn[iElemType].connectivity[0]; - for(int n = zoneElemConn[iElemType].numElem; n--; ) { - std::memcpy(tmp, aConn, numVPE*sizeof(int)); + for(int n = zoneElemConn[iElemType].numElem; n--;) { + std::memcpy(tmp, aConn, numVPE * sizeof(int)); for(int iV = 0; iV != numVPE; ++iV) aConn[tr[iV]] = tmp[iV]; aConn += numVPE; } @@ -2506,42 +2502,39 @@ void expand_name(std::string &s, const int index, const char *const name) std::string::size_type r1 = s.find('&'); // Look for and replace "&-&" sub-strings while(r1 != std::string::npos) { - const std::string::size_type r2 = s.find('&', r1+1); + const std::string::size_type r2 = s.find('&', r1 + 1); if(r2 == std::string::npos) { - s.replace(r1, s.length()-r1, ""); + s.replace(r1, s.length() - r1, ""); } else { const int rn = r2 - r1 + 1; - switch(s[r1+1]) { + switch(s[r1 + 1]) { case 'I': // &I[0][%width]& { int iplus = 1; - if(s[r1+2] == '0') iplus = 0; + if(s[r1 + 2] == '0') iplus = 0; char fmt[6] = "%d"; - const std::string::size_type f = s.find('%', r1+1); + const std::string::size_type f = s.find('%', r1 + 1); if(f != std::string::npos && f < r2) { - int w = std::atoi(s.substr(f+1, r2-f-1).c_str()); + int w = std::atoi(s.substr(f + 1, r2 - f - 1).c_str()); if(w > 0 && w < 33) std::sprintf(fmt, "%%0%dd", w); } - s.replace(r1, rn, CGNSNameStr(index+iplus, fmt).c_str()); + s.replace(r1, rn, CGNSNameStr(index + iplus, fmt).c_str()); break; } case 'N': // &N& s.replace(r1, rn, name); break; - default: - s.replace(r1, rn, ""); + default: s.replace(r1, rn, ""); } } - if(s.length() > 1024) s = ""; // idiot/recursive check + if(s.length() > 1024) s = ""; // idiot/recursive check r1 = s.find('&'); } - } - /******************************************************************************* * * Routine get_zone_definition @@ -2571,46 +2564,44 @@ void expand_name(std::string &s, const int index, const char *const name) * ******************************************************************************/ -int get_zone_definition(GModel &model, const int zoneDefinition, - const int numZone, const CGNSOptions &options, - const int meshDim, - const PhysGroupMap &group, int &globalZoneIndex, - PhysGroupMap::const_iterator &globalPhysicalIt, - int &zoneIndex, int &partition, - PhysGroupMap::const_iterator &physicalItBegin, - PhysGroupMap::const_iterator &physicalItEnd, - CGNSNameStr &zoneName) +int get_zone_definition( + GModel &model, const int zoneDefinition, const int numZone, + const CGNSOptions &options, const int meshDim, const PhysGroupMap &group, + int &globalZoneIndex, PhysGroupMap::const_iterator &globalPhysicalIt, + int &zoneIndex, int &partition, PhysGroupMap::const_iterator &physicalItBegin, + PhysGroupMap::const_iterator &physicalItEnd, CGNSNameStr &zoneName) { - int status = 0; const char *_zoneName = "Partition"; // NBN: pass name to expand_name(): Zone_&N& ==> Zone_Fluid std::string zn; -//--Get indices for the zonex + //--Get indices for the zonex #ifdef _OPENMP -#pragma omp critical (get_zone_definition) +#pragma omp critical(get_zone_definition) #endif { - if(globalZoneIndex >= numZone) status = 1; + if(globalZoneIndex >= numZone) + status = 1; else { switch(zoneDefinition) { - case 0: // Single zone + case 0: // Single zone partition = -1; physicalItBegin = group.begin(); physicalItEnd = group.end(); break; - case 1: // Zone defined by partition + case 1: // Zone defined by partition partition = globalZoneIndex; physicalItBegin = group.begin(); physicalItEnd = group.end(); break; - case 2: // Zone defined by physical + case 2: // Zone defined by physical partition = -1; - //_zoneName = model.getPhysicalName(meshDim, globalPhysicalIt->first).c_str(); - zn = model.getPhysicalName(meshDim, globalPhysicalIt->first); // NBN: - _zoneName = zn.c_str(); // NBN: + //_zoneName = model.getPhysicalName(meshDim, + //globalPhysicalIt->first).c_str(); + zn = model.getPhysicalName(meshDim, globalPhysicalIt->first); // NBN: + _zoneName = zn.c_str(); // NBN: physicalItBegin = globalPhysicalIt++; physicalItEnd = globalPhysicalIt; break; @@ -2618,25 +2609,23 @@ int get_zone_definition(GModel &model, const int zoneDefinition, zoneIndex = globalZoneIndex++; } } -//omp: end critical + // omp: end critical -//--Set the name for the zone + //--Set the name for the zone if(status == 0) { std::string s = options.zoneName; expand_name(s, zoneIndex, _zoneName); - if(s.length() == 0) { // If empty + if(s.length() == 0) { // If empty s = "Zone_"; - s += CGNSNameStr(zoneIndex+1).c_str(); + s += CGNSNameStr(zoneIndex + 1).c_str(); } zoneName = s.c_str(); } return status; - } - /******************************************************************************* * * Routine write_CGNS_zone @@ -2668,19 +2657,17 @@ int get_zone_definition(GModel &model, const int zoneDefinition, //--A task for a thread -template <unsigned DIM> -struct ZoneTask -{ +template <unsigned DIM> struct ZoneTask { MZone<DIM> zone; CGNSNameStr zoneName; int zoneIndex; - int status; // 0 - free - // 1 - zone processed and waiting in - // queue to be written - // 2 - zone defined and boundaries - // processed + int status; // 0 - free + // 1 - zone processed and waiting in + // queue to be written + // 2 - zone defined and boundaries + // processed int indexInOwner; - ZoneTask() : status(0), indexInOwner(0) { } + ZoneTask() : status(0), indexInOwner(0) {} void change_status(const int _status) { #ifdef _OPENMP @@ -2692,11 +2679,10 @@ struct ZoneTask //--Information about a zone -struct ZoneInfo -{ +struct ZoneInfo { CGNSNameStr name; int cgIndex; - ZoneInfo() : cgIndex(-1) { } + ZoneInfo() : cgIndex(-1) {} }; template <unsigned DIM> @@ -2705,66 +2691,66 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, const int vectorDim, const PhysGroupMap &group, const int cgIndexFile, const int cgIndexBase) { - -//--Shared data + //--Shared data int threadsWorking = omp_get_num_threads(); - // Semaphore for working threads + // Semaphore for working threads // ** omp_lock_t threadWLock; - std::queue<ZoneTask<DIM>*> zoneQueue; // Queue for zones that have been - // defined and are ready to be written + std::queue<ZoneTask<DIM> *> zoneQueue; // Queue for zones that have been + // defined and are ready to be written // ** omp_lock_t queueLock; // Next two are locked by an omp critical int globalZoneIndex = 0; PhysGroupMap::const_iterator globalPhysicalIt = group.begin(); -//--Initialize omp locks + //--Initialize omp locks omp_init_lock(&threadWLock); omp_init_lock(&queueLock); -//**Spawn threads + //**Spawn threads { - -//--Master thread (primary task is to define boundary connections and perform -//--I/O but can also process a zone if idle) + //--Master thread (primary task is to define boundary connections and + //perform + //--I/O but can also process a zone if idle) if(omp_get_thread_num() == 0) { ZoneTask<DIM> zoneTask; MZoneBoundary<DIM> mZoneBoundary; - ZoneConnMap zoneConnMap; // Zone connectivity that is generated - // whenever a zone is added to - // mZoneBoundary - std::vector<ZoneInfo> zoneInfo; zoneInfo.resize(16); - std::vector<double> dBuffer; // Buffer for double-precision data + ZoneConnMap zoneConnMap; // Zone connectivity that is generated + // whenever a zone is added to + // mZoneBoundary + std::vector<ZoneInfo> zoneInfo; + zoneInfo.resize(16); + std::vector<double> dBuffer; // Buffer for double-precision data std::vector<cgsize_t> iBuffer1, iBuffer2; - // Buffers for integer data - int interfaceIndex = 0; // Index for interfaces + // Buffers for integer data + int interfaceIndex = 0; // Index for interfaces - while (threadsWorking || zoneQueue.size()) { - if (zoneQueue.size()) { - -/*--------------------------------------------------------------------* - * Write the zone in the queue - *--------------------------------------------------------------------*/ + while(threadsWorking || zoneQueue.size()) { + if(zoneQueue.size()) { + /*--------------------------------------------------------------------* + * Write the zone in the queue + *--------------------------------------------------------------------*/ ZoneTask<DIM> *const writeTask = zoneQueue.front(); MZone<DIM> *const writeZone = &writeTask->zone; -//--Write the zone + //--Write the zone // Write the zone node - int cgIndexZone=0; - cgsize_t cgZoneSize[3]={0}; - cgZoneSize[0] = writeZone->zoneVertVec.size(); // Number of vertices + int cgIndexZone = 0; + cgsize_t cgZoneSize[3] = {0}; + cgZoneSize[0] = writeZone->zoneVertVec.size(); // Number of vertices #ifdef CGNS_TEST1 // Count all the sub-elements in a Triangle 10 cgZoneSize[1] = 0; for(int iElemType = 0; iElemType != MSH_NUM_TYPE; ++iElemType) { switch(iElemType) { - case MSH_TRI_10-1: - cgZoneSize[1] += writeZone->zoneElemConn[MSH_TRI_10-1].numElem*9; + case MSH_TRI_10 - 1: + cgZoneSize[1] += + writeZone->zoneElemConn[MSH_TRI_10 - 1].numElem * 9; break; default: cgZoneSize[1] += writeZone->zoneElemConn[iElemType].numElem; @@ -2772,37 +2758,36 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, } } #else - cgZoneSize[1] = writeZone->totalElements(); // Number of elements + cgZoneSize[1] = writeZone->totalElements(); // Number of elements #endif - cgZoneSize[2] = writeZone->numBoVert; // Number of boundary vertices + cgZoneSize[2] = writeZone->numBoVert; // Number of boundary vertices if(cg_zone_write(cgIndexFile, cgIndexBase, writeTask->zoneName.c_str(), cgZoneSize, - Unstructured, &cgIndexZone)) - { + Unstructured, &cgIndexZone)) { return cgnsErr(); } // Manually maintain the size of the 'zoneInfo vector'. 'push_back' // is not used because the elements are in order of 'zoneIndex' if(writeTask->zoneIndex >= zoneInfo.size()) { - zoneInfo.resize(std::max(2*static_cast<int>(zoneInfo.size()), - writeTask->zoneIndex)); + zoneInfo.resize(std::max(2 * static_cast<int>(zoneInfo.size()), + writeTask->zoneIndex)); } zoneInfo[writeTask->zoneIndex].name = writeTask->zoneName; zoneInfo[writeTask->zoneIndex].cgIndex = cgIndexZone; // Write the grid node - int cgIndexGrid=0; + int cgIndexGrid = 0; if(cg_grid_write(cgIndexFile, cgIndexBase, cgIndexZone, "GridCoordinates", &cgIndexGrid)) return cgnsErr(); // Write the grid coordinates - int cgIndexCoord=0; + int cgIndexCoord = 0; dBuffer.resize(cgZoneSize[0]); // x-coordinates for this zone - for (int i = 0; i != cgZoneSize[0]; ++i) { - dBuffer[i] = writeZone->zoneVertVec[i]->x()*scalingFactor; + for(int i = 0; i != cgZoneSize[0]; ++i) { + dBuffer[i] = writeZone->zoneVertVec[i]->x() * scalingFactor; } if(cg_coord_write(cgIndexFile, cgIndexBase, cgIndexZone, RealDouble, "CoordinateX", &dBuffer[0], &cgIndexCoord)) @@ -2810,7 +2795,7 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, // y-coordinates for this zone for(int i = 0; i != cgZoneSize[0]; ++i) { - dBuffer[i] = writeZone->zoneVertVec[i]->y()*scalingFactor; + dBuffer[i] = writeZone->zoneVertVec[i]->y() * scalingFactor; } if(cg_coord_write(cgIndexFile, cgIndexBase, cgIndexZone, RealDouble, "CoordinateY", &dBuffer[0], &cgIndexCoord)) @@ -2819,7 +2804,7 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, // z-coordinates for this zone if(vectorDim == 3) { for(int i = 0; i != cgZoneSize[0]; ++i) { - dBuffer[i] = writeZone->zoneVertVec[i]->z()*scalingFactor; + dBuffer[i] = writeZone->zoneVertVec[i]->z() * scalingFactor; } if(cg_coord_write(cgIndexFile, cgIndexBase, cgIndexZone, RealDouble, "CoordinateZ", &dBuffer[0], &cgIndexCoord)) @@ -2830,27 +2815,27 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, // written int indexElemType[MSH_NUM_TYPE]; for(int i = 0; i != MSH_NUM_TYPE; ++i) indexElemType[i] = i; - std::sort<int*, ElemSortCGNSType> - (indexElemType, indexElemType + MSH_NUM_TYPE, - ElemSortCGNSType(writeZone->zoneElemConn)); + std::sort<int *, ElemSortCGNSType>( + indexElemType, indexElemType + MSH_NUM_TYPE, + ElemSortCGNSType(writeZone->zoneElemConn)); // Write the element connectivity const int numElemType = writeZone->numElementTypes(); int iElemSection = 0; for(int iElemType = 0; iElemType != numElemType; ++iElemType) { - const int typeMSHm1 = indexElemType[iElemType]; // typeMSH-1 + const int typeMSHm1 = indexElemType[iElemType]; // typeMSH-1 const int typeCGNS = msh2cgns[typeMSHm1][0]; const char *elemName; - MElement::getInfoMSH(typeMSHm1+1, &elemName); + MElement::getInfoMSH(typeMSHm1 + 1, &elemName); #ifdef CGNS_TEST1 - if(typeMSHm1 == MSH_TRI_10-1) { + if(typeMSHm1 == MSH_TRI_10 - 1) { const int nElem3o = writeZone->zoneElemConn[20].numElem; - const int nElem1o = nElem3o*9; - std::vector<int> subConn(nElem1o*3); + const int nElem1o = nElem3o * 9; + std::vector<int> subConn(nElem1o * 3); int iV = 0; for(int iElem3o = 0; iElem3o != nElem3o; ++iElem3o) { int *elem3o = - &writeZone->zoneElemConn[20].connectivity[iElem3o*10]; + &writeZone->zoneElemConn[20].connectivity[iElem3o * 10]; subConn[iV++] = elem3o[9]; subConn[iV++] = elem3o[8]; subConn[iV++] = elem3o[3]; @@ -2881,47 +2866,46 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, } elemName = "Sub-Triangle 10"; cgsize_t cgIndexSection; - if(cg_section_write - (cgIndexFile, cgIndexBase, cgIndexZone, elemName, - TRI_3, iElemSection + 1, - nElem1o + iElemSection, - writeZone->zoneElemConn[20].numBoElem*9 + iElemSection, - &subConn[0], &cgIndexSection)) + if(cg_section_write( + cgIndexFile, cgIndexBase, cgIndexZone, elemName, TRI_3, + iElemSection + 1, nElem1o + iElemSection, + writeZone->zoneElemConn[20].numBoElem * 9 + iElemSection, + &subConn[0], &cgIndexSection)) return cgnsErr(); ++iElemSection; } else #endif - if(typeCGNS == -1) { + if(typeCGNS == -1) { // This type is not supported in CGNS Msg::Warning("Element type %s is not supported in CGNS and " - "has not been written to the file", elemName); + "has not been written to the file", + elemName); } else { int cgIndexSection; - if(cg_section_write - (cgIndexFile, cgIndexBase, cgIndexZone, elemName, - static_cast<ElementType_t>(typeCGNS), iElemSection + 1, - writeZone->zoneElemConn[typeMSHm1].numElem + iElemSection, - writeZone->zoneElemConn[typeMSHm1].numBoElem + iElemSection, - (cgsize_t*)&writeZone->zoneElemConn[typeMSHm1].connectivity[0], - &cgIndexSection)) - { + if(cg_section_write( + cgIndexFile, cgIndexBase, cgIndexZone, elemName, + static_cast<ElementType_t>(typeCGNS), iElemSection + 1, + writeZone->zoneElemConn[typeMSHm1].numElem + iElemSection, + writeZone->zoneElemConn[typeMSHm1].numBoElem + iElemSection, + (cgsize_t *)&writeZone->zoneElemConn[typeMSHm1] + .connectivity[0], + &cgIndexSection)) { return cgnsErr(); } ++iElemSection; } } -//--Process interior connectivity + //--Process interior connectivity mZoneBoundary.interiorBoundaryVertices(writeTask->zoneIndex, *writeZone, zoneConnMap); // Write the connectivity for each zone pair const ZoneConnMap::const_iterator gCEnd = zoneConnMap.end(); for(ZoneConnMap::const_iterator gCIt = zoneConnMap.begin(); - gCIt != gCEnd; ++gCIt) - { + gCIt != gCEnd; ++gCIt) { const int nVert = gCIt->second.vertexPairVec.size(); iBuffer1.resize(nVert); iBuffer2.resize(nVert); @@ -2939,52 +2923,49 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, interfaceName += CGNSNameStr(interfaceIndex).c_str(); } // In the first zone - if(cg_conn_write - (cgIndexFile, cgIndexBase, zoneInfo[gCIt->first.zone1].cgIndex, - interfaceName.c_str(), CGNS::Vertex, Abutting1to1, PointList, nVert, - &iBuffer1[0], zoneInfo[gCIt->first.zone2].name.c_str(), - Unstructured, PointListDonor, Integer, nVert, &iBuffer2[0], - &cgIndexInterface)) - { + if(cg_conn_write( + cgIndexFile, cgIndexBase, zoneInfo[gCIt->first.zone1].cgIndex, + interfaceName.c_str(), CGNS::Vertex, Abutting1to1, PointList, + nVert, &iBuffer1[0], zoneInfo[gCIt->first.zone2].name.c_str(), + Unstructured, PointListDonor, Integer, nVert, &iBuffer2[0], + &cgIndexInterface)) { return cgnsErr(); } // In the second zone - if(cg_conn_write - (cgIndexFile, cgIndexBase, zoneInfo[gCIt->first.zone2].cgIndex, - interfaceName.c_str(), CGNS::Vertex, Abutting1to1, PointList, nVert, - &iBuffer2[0], zoneInfo[gCIt->first.zone1].name.c_str(), - Unstructured, PointListDonor, Integer, nVert, &iBuffer1[0], - &cgIndexInterface)) - { + if(cg_conn_write( + cgIndexFile, cgIndexBase, zoneInfo[gCIt->first.zone2].cgIndex, + interfaceName.c_str(), CGNS::Vertex, Abutting1to1, PointList, + nVert, &iBuffer2[0], zoneInfo[gCIt->first.zone1].name.c_str(), + Unstructured, PointListDonor, Integer, nVert, &iBuffer1[0], + &cgIndexInterface)) { return cgnsErr(); } } -//--Pop from the queue + //--Pop from the queue omp_set_lock(&queueLock); zoneQueue.pop(); omp_unset_lock(&queueLock); -//--Task finished + //--Task finished writeTask->change_status(0); } -/*--------------------------------------------------------------------* - * No zones waiting in the queue, process a zone - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * No zones waiting in the queue, process a zone + *--------------------------------------------------------------------*/ else { PhysGroupMap::const_iterator physicalItBegin; PhysGroupMap::const_iterator physicalItEnd; // --- int zoneIndex; int partition; - if(get_zone_definition - (model, zoneDefinition, numZone, options, DIM, group, - globalZoneIndex, globalPhysicalIt, zoneTask.zoneIndex, partition, - physicalItBegin, physicalItEnd, zoneTask.zoneName)) - { + if(get_zone_definition(model, zoneDefinition, numZone, options, DIM, + group, globalZoneIndex, globalPhysicalIt, + zoneTask.zoneIndex, partition, physicalItBegin, + physicalItEnd, zoneTask.zoneName)) { omp_set_lock(&threadWLock); --threadsWorking; omp_unset_lock(&threadWLock); @@ -2993,20 +2974,19 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, zoneTask.zone.clear(); // Loop through all physical in the zone definition for(PhysGroupMap::const_iterator physicalIt = physicalItBegin; - physicalIt != physicalItEnd; ++physicalIt) - { + physicalIt != physicalItEnd; ++physicalIt) { // Add elements from all entities in the physical with defined // partition number if(partition == -1) { - zoneTask.zone.template add_elements_in_entities - <typename std::vector<GEntity*>::const_iterator> - (physicalIt->second.begin(), physicalIt->second.end()); + zoneTask.zone.template add_elements_in_entities< + typename std::vector<GEntity *>::const_iterator>( + physicalIt->second.begin(), physicalIt->second.end()); } else { - zoneTask.zone.template add_elements_in_entities - <typename std::vector<GEntity*>::const_iterator> - (physicalIt->second.begin() + partition, - physicalIt->second.begin() + (partition+1)); + zoneTask.zone.template add_elements_in_entities< + typename std::vector<GEntity *>::const_iterator>( + physicalIt->second.begin() + partition, + physicalIt->second.begin() + (partition + 1)); } } // Process the zone @@ -3019,28 +2999,25 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, omp_unset_lock(&queueLock); } } - } // End master thread loop + } // End master thread loop -/*--------------------------------------------------------------------* - * Write the remaining unconnected vertices as boundary conditions - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * Write the remaining unconnected vertices as boundary conditions + *--------------------------------------------------------------------*/ - if(options.writeBC) - { - ZoneBoVec zoneBoVec; // from 'MZoneBoundary.h' - if(mZoneBoundary.exteriorBoundaryVertices - (options.normalSource, zoneBoVec) == 0) - { + if(options.writeBC) { + ZoneBoVec zoneBoVec; // from 'MZoneBoundary.h' + if(mZoneBoundary.exteriorBoundaryVertices(options.normalSource, + zoneBoVec) == 0) { // Sort by zone index and then entity index const int numBoVert = zoneBoVec.size(); - if (numBoVert>=1) - { + if(numBoVert >= 1) { Msg::Info("writing BoVerts..."); std::vector<int> iZBV(numBoVert); for(int i = 0; i != numBoVert; ++i) iZBV[i] = i; - std::sort<int*, ZoneBoVecSort>(&iZBV[0], &iZBV[numBoVert-1], - ZoneBoVecSort(zoneBoVec)); + std::sort<int *, ZoneBoVecSort>(&iZBV[0], &iZBV[numBoVert - 1], + ZoneBoVecSort(zoneBoVec)); dBuffer.reserve(1024); iBuffer1.reserve(1024); @@ -3053,8 +3030,7 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, const int iVertStart = iVert; while(iVert != numBoVert && zoneBoVec[iZBV[iVert]].zoneIndex == zoneIndex && - zoneBoVec[iZBV[iVert]].bcPatchIndex == patchIndex) - { + zoneBoVec[iZBV[iVert]].bcPatchIndex == patchIndex) { VertexBoundary &vertBo = zoneBoVec[iZBV[iVert]]; dBuffer.push_back(vertBo.normal[0]); dBuffer.push_back(vertBo.normal[1]); @@ -3069,22 +3045,20 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, expand_name(patchName, patchIndex, "Patch"); if(patchName.length() == 0) { patchName = "Patch_"; - patchName += CGNSNameStr(patchIndex+1).c_str(); + patchName += CGNSNameStr(patchIndex + 1).c_str(); } if(cg_boco_write(cgIndexFile, cgIndexBase, zoneInfo[zoneIndex].cgIndex, patchName.c_str(), BCTypeNull, PointList, numBCVert, &iBuffer1[0], - &cgIndexBoco)) - { + &cgIndexBoco)) { return cgnsErr(); } if(options.normalSource) { int normalIndex; - if(cg_boco_normal_write(cgIndexFile, cgIndexBase, - zoneInfo[zoneIndex].cgIndex, cgIndexBoco, - &normalIndex, 1, RealDouble, &dBuffer[0])) - { + if(cg_boco_normal_write( + cgIndexFile, cgIndexBase, zoneInfo[zoneIndex].cgIndex, + cgIndexBoco, &normalIndex, 1, RealDouble, &dBuffer[0])) { return cgnsErr(); } } @@ -3096,12 +3070,12 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, // NBN: MZoneBoundary defines no destructor, so force // the deallocation of the new pointers with clear() mZoneBoundary.clear(); - Msg::Info("Leaving master thread"); // DBG + Msg::Info("Leaving master thread"); // DBG - } // End master thread instructions - } // End omp parallel section + } // End master thread instructions + } // End omp parallel section -//--Destroy omp locks + //--Destroy omp locks omp_destroy_lock(&threadWLock); omp_destroy_lock(&queueLock); @@ -3111,9 +3085,9 @@ int write_CGNS_zones(GModel &model, const int zoneDefinition, const int numZone, #else -int GModel::_readCGNSUnstructured(const std::string& fileName){ return 0; } +int GModel::_readCGNSUnstructured(const std::string &fileName) { return 0; } -int GModel::_readCGNSStructured(const std::string &name){ return 0; } +int GModel::_readCGNSStructured(const std::string &name) { return 0; } int GModel::readCGNS(const std::string &name) { diff --git a/Geo/GModelIO_DIFF.cpp b/Geo/GModelIO_DIFF.cpp index d0e9434bebadc881f07931b65e8658f779fd8d86..64549abaeceea14cb7eecc975fd4de079f597a4e 100644 --- a/Geo/GModelIO_DIFF.cpp +++ b/Geo/GModelIO_DIFF.cpp @@ -9,11 +9,12 @@ #include "OS.h" #include "MElement.h" -static bool getMeshVertices(int num, int *indices, std::map<int, MVertex*> &map, - std::vector<MVertex*> &vertices) +static bool getMeshVertices(int num, int *indices, + std::map<int, MVertex *> &map, + std::vector<MVertex *> &vertices) { - for(int i = 0; i < num; i++){ - if(!map.count(indices[i])){ + for(int i = 0; i < num; i++) { + if(!map.count(indices[i])) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -23,11 +24,12 @@ static bool getMeshVertices(int num, int *indices, std::map<int, MVertex*> &map, return true; } -static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, - std::vector<MVertex*> &vertices, int minVertex = 0) +static bool getMeshVertices(int num, int *indices, std::vector<MVertex *> &vec, + std::vector<MVertex *> &vertices, int minVertex = 0) { - for(int i = 0; i < num; i++){ - if(indices[i] < minVertex || indices[i] > (int)(vec.size() - 1 + minVertex)){ + for(int i = 0; i < num; i++) { + if(indices[i] < minVertex || + indices[i] > (int)(vec.size() - 1 + minVertex)) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -40,66 +42,84 @@ static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, int GModel::readDIFF(const std::string &name) { FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } char str[256] = "XXX"; - std::map<int, std::vector<MElement*> > elements[10]; + std::map<int, std::vector<MElement *> > elements[10]; std::map<int, std::map<int, std::string> > physicals[4]; - std::map<int, MVertex*> vertexMap; - std::vector<MVertex*> vertexVector; + std::map<int, MVertex *> vertexMap; + std::vector<MVertex *> vertexVector; { - while(strstr(str, "Number of space dim. =") == NULL){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(strstr(str, "Number of space dim. =") == NULL) { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } int dim; - if(sscanf(str, "%*s %*s %*s %*s %*s %d", &dim) != 1){ fclose(fp); return 0; } + if(sscanf(str, "%*s %*s %*s %*s %*s %d", &dim) != 1) { + fclose(fp); + return 0; + } Msg::Info("dimension %d", dim); int numElements; - if(!fgets(str, sizeof(str), fp) || feof(fp)){ fclose(fp); return 0; } - while(strstr(str, "Number of elements =") == NULL){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) { + fclose(fp); + return 0; + } + while(strstr(str, "Number of elements =") == NULL) { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; + } + if(sscanf(str, "%*s %*s %*s %*s %d", &numElements) != 1) { + fclose(fp); + return 0; } - if(sscanf(str, "%*s %*s %*s %*s %d", &numElements) != 1){ fclose(fp); return 0; } Msg::Info("%d elements", numElements); int numVertices; - if(!fgets(str, sizeof(str), fp) || feof(fp)){ fclose(fp); return 0; } - while(strstr(str, "Number of nodes =") == NULL){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) { + fclose(fp); + return 0; + } + while(strstr(str, "Number of nodes =") == NULL) { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; + } + if(sscanf(str, "%*s %*s %*s %*s %d", &numVertices) != 1) { + fclose(fp); + return 0; } - if(sscanf(str, "%*s %*s %*s %*s %d", &numVertices) != 1){ fclose(fp); return 0; } Msg::Info("%d vertices", numVertices); int numVerticesPerElement; - if(!fgets(str, sizeof(str), fp) || feof(fp)){ fclose(fp); return 0; } - while(strstr(str, "Max number of nodes in an element:")==NULL){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) { + fclose(fp); + return 0; + } + while(strstr(str, "Max number of nodes in an element:") == NULL) { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } - if(sscanf(str, "%*s %*s %*s %*s %*s %*s %*s %d", &numVerticesPerElement) != 1){ + if(sscanf(str, "%*s %*s %*s %*s %*s %*s %*s %d", &numVerticesPerElement) != + 1) { fclose(fp); return 0; } Msg::Info("numVerticesPerElement %d", numVerticesPerElement); bool several_subdomains; - if(!fgets(str, sizeof(str), fp) || feof(fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp) || feof(fp)) { + fclose(fp); + return 0; + } if(!strncmp(&str[2], "Only one material", 17) || - !strncmp(&str[2], "Only one subdomain", 18)){ + !strncmp(&str[2], "Only one subdomain", 18)) { if(!strncmp(&str[37], "dpTRUE", 6) || !strncmp(&str[37], "true", 4) || - !strncmp(&str[36], "dpTRUE", 6) || !strncmp(&str[36], "true", 4)){ + !strncmp(&str[36], "dpTRUE", 6) || !strncmp(&str[36], "true", 4)) { several_subdomains = false; } - else{ + else { several_subdomains = true; } Msg::Info("several_subdomains %x %s", several_subdomains, str); @@ -107,31 +127,37 @@ int GModel::readDIFF(const std::string &name) int nbi; std::vector<int> bi; - if(!fgets(str, sizeof(str), fp) || feof(fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp) || feof(fp)) { + fclose(fp); + return 0; + } while(strstr(str, "Boundary indicators:") == NULL && - strstr(str, "boundary indicators:") == NULL){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + strstr(str, "boundary indicators:") == NULL) { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; + } + if(sscanf(str, "%d %*s %*s", &nbi) != 1) { + fclose(fp); + return 0; } - if(sscanf(str, "%d %*s %*s", &nbi) != 1){ fclose(fp); return 0; } Msg::Info("nbi %d", nbi); - if(nbi != 0) - bi.resize(nbi); + if(nbi != 0) bi.resize(nbi); std::string format_read_bi = "%*d %*s %*s"; - for(int i = 0; i < nbi; i++){ - if(format_read_bi[format_read_bi.size()-1] == 'd') { - format_read_bi[format_read_bi.size()-1] = '*'; + for(int i = 0; i < nbi; i++) { + if(format_read_bi[format_read_bi.size() - 1] == 'd') { + format_read_bi[format_read_bi.size() - 1] = '*'; format_read_bi += "d %d"; } else format_read_bi += " %d"; - if(sscanf(str, format_read_bi.c_str(), &bi[i]) != 1){ fclose(fp); return 0; } + if(sscanf(str, format_read_bi.c_str(), &bi[i]) != 1) { + fclose(fp); + return 0; + } Msg::Info("bi[%d]=%d", i, bi[i]); } - while(str[0] != '#'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(str[0] != '#') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } vertexVector.clear(); vertexMap.clear(); @@ -140,12 +166,18 @@ int GModel::readDIFF(const std::string &name) std::vector<std::vector<int> > elementary(numVertices); Msg::ResetProgressMeter(); - for(int i = 0; i < numVertices; i++){ - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + for(int i = 0; i < numVertices; i++) { + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } double xyz[3]; int tmp; - if(sscanf(str, "%d ( %lf , %lf , %lf ) [%d]", &num, - &xyz[0], &xyz[1], &xyz[2], &tmp) != 5){ fclose(fp); return 0; } + if(sscanf(str, "%d ( %lf , %lf , %lf ) [%d]", &num, &xyz[0], &xyz[1], + &xyz[2], &tmp) != 5) { + fclose(fp); + return 0; + } elementary[i].resize(tmp + 1); elementary[i][0] = tmp; minVertex = std::min(minVertex, num); @@ -160,149 +192,156 @@ int GModel::readDIFF(const std::string &name) // vector to speed up element creation if((int)vertexMap.size() == numVertices && ((minVertex == 1 && maxVertex == numVertices) || - (minVertex == 0 && maxVertex == numVertices - 1))){ + (minVertex == 0 && maxVertex == numVertices - 1))) { Msg::Info("Vertex numbering is dense"); vertexVector.resize(vertexMap.size() + 1); if(minVertex == 1) vertexVector[0] = 0; else vertexVector[numVertices] = 0; - std::map<int, MVertex*>::const_iterator it = vertexMap.begin(); - for(; it != vertexMap.end(); ++it) - vertexVector[it->first] = it->second; + std::map<int, MVertex *>::const_iterator it = vertexMap.begin(); + for(; it != vertexMap.end(); ++it) vertexVector[it->first] = it->second; vertexMap.clear(); } - Msg::Info("%d ( %lf , %lf , %lf ) [%d]",i, xyz[0], xyz[1], xyz[2], + Msg::Info("%d ( %lf , %lf , %lf ) [%d]", i, xyz[0], xyz[1], xyz[2], elementary[i][0]); std::string format_read_bi = "%*d ( %*lf , %*lf , %*lf ) [%*d]"; - for(int j = 0; j < elementary[i][0]; j++){ + for(int j = 0; j < elementary[i][0]; j++) { if(format_read_bi[format_read_bi.size() - 1] == 'd') { format_read_bi[format_read_bi.size() - 1] = '*'; format_read_bi += "d %d"; } else format_read_bi += " %d"; - if(sscanf(str, format_read_bi.c_str(), &(elementary[i][j + 1])) != 1){ + if(sscanf(str, format_read_bi.c_str(), &(elementary[i][j + 1])) != 1) { fclose(fp); return 0; } Msg::Info("elementary[%d][%d]=%d", i + 1, j + 1, elementary[i][j + 1]); } } - while(str[0] != '#'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(str[0] != '#') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } std::vector<int> material(numElements); std::vector<std::vector<int> > ElementsNodes(numElements); - for(int i = 0; i < numElements; i++){ + for(int i = 0; i < numElements; i++) { ElementsNodes[i].resize(numVerticesPerElement); } - char eleTypec[20]=""; + char eleTypec[20] = ""; std::string eleType; Msg::ResetProgressMeter(); std::vector<int> mapping; - for(int i = 1; i <= numElements; i++){ - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + for(int i = 1; i <= numElements; i++) { + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int num = 0, type, physical = 0; unsigned int partition = 0; int indices[60]; - if(sscanf(str, "%*d %s %d", eleTypec, &material[i-1]) != 2){ fclose(fp); return 0; } + if(sscanf(str, "%*d %s %d", eleTypec, &material[i - 1]) != 2) { + fclose(fp); + return 0; + } eleType = std::string(eleTypec); int k2; // local number for the element int NoVertices; // number of vertices per element - if(eleType == "ElmT3n2D"){ + if(eleType == "ElmT3n2D") { NoVertices = 3; static int map[3] = {0, 1, 2}; // identical to gmsh - mapping=std::vector<int>(map, map + sizeof(map) / sizeof(int)); + mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_TRI_3; } - else if(eleType == "ElmT6n2D"){ + else if(eleType == "ElmT6n2D") { NoVertices = 6; static int map[6] = {0, 1, 2, 3, 4, 5}; // identical to gmsh mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_TRI_6; } - else if(eleType == "ElmB4n2D"){ + else if(eleType == "ElmB4n2D") { NoVertices = 4; static int map[4] = {0, 1, 3, 2}; // local numbering mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_QUA_4; } - else if(eleType == "ElmB8n2D"){ + else if(eleType == "ElmB8n2D") { NoVertices = 8; static int map[8] = {0, 1, 3, 2, 4, 6, 7, 5}; // local numbering mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_QUA_8; } - else if(eleType == "ElmB9n2D"){ + else if(eleType == "ElmB9n2D") { NoVertices = 9; static int map[9] = {0, 4, 1, 7, 8, 5, 3, 6, 2}; // local numbering mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_QUA_9; } - else if(eleType == "ElmT4n3D"){ + else if(eleType == "ElmT4n3D") { NoVertices = 4; static int map[4] = {0, 1, 2, 3}; // identical to gmsh mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_TET_4; } - else if(eleType == "ElmT10n3D"){ + else if(eleType == "ElmT10n3D") { NoVertices = 10; static int map[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // local numbering mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_TET_10; } - else if(eleType == "ElmB8n3D"){ + else if(eleType == "ElmB8n3D") { NoVertices = 8; static int map[8] = {4, 5, 0, 1, 7, 6, 3, 2}; mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_HEX_8; } - else if(eleType == "ElmB20n3D"){ + else if(eleType == "ElmB20n3D") { NoVertices = 20; - static int map[20] = {4, 5, 0, 1, 7, 6, 3, 2, 16, 8, 19, 13, 15, 12, - 14, 17, 18, 9, 11}; + static int map[20] = {4, 5, 0, 1, 7, 6, 3, 2, 16, 8, + 19, 13, 15, 12, 14, 17, 18, 9, 11}; mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_HEX_20; } - else if(eleType == "ElmB27n3D"){ + else if(eleType == "ElmB27n3D") { NoVertices = 27; - static int map[27] = {4, 16, 5, 10, 21, 12, 0, 8, 1, 17, 25, 18, 22, - 26, 23, 9, 20, 11, 7, 19, 6, 15, 24, 14, 3, 13, 2}; + static int map[27] = {4, 16, 5, 10, 21, 12, 0, 8, 1, + 17, 25, 18, 22, 26, 23, 9, 20, 11, + 7, 19, 6, 15, 24, 14, 3, 13, 2}; mapping = std::vector<int>(map, map + sizeof(map) / sizeof(int)); type = MSH_HEX_27; } - else{ + else { fclose(fp); return 0; } std::string format_read_vertices = "%*d %*s %*d"; - for(int k = 0; k < NoVertices; k++){ - if(format_read_vertices[format_read_vertices.size()-2] != '*') { - format_read_vertices[format_read_vertices.size()-1] = '*'; + for(int k = 0; k < NoVertices; k++) { + if(format_read_vertices[format_read_vertices.size() - 2] != '*') { + format_read_vertices[format_read_vertices.size() - 1] = '*'; format_read_vertices += "d %d"; } else format_read_vertices += " %d"; k2 = mapping[k]; - if(sscanf(str, format_read_vertices.c_str(), &ElementsNodes[i-1][k2]) != 1){ + if(sscanf(str, format_read_vertices.c_str(), + &ElementsNodes[i - 1][k2]) != 1) { fclose(fp); return 0; } } mapping.clear(); - for(int j = 0; j < NoVertices; j++) - indices[j] = ElementsNodes[i - 1][j]; - std::vector<MVertex*> vertices; - if(vertexVector.size()){ - if(!getMeshVertices(numVerticesPerElement, indices, vertexVector, vertices)){ + for(int j = 0; j < NoVertices; j++) indices[j] = ElementsNodes[i - 1][j]; + std::vector<MVertex *> vertices; + if(vertexVector.size()) { + if(!getMeshVertices(numVerticesPerElement, indices, vertexVector, + vertices)) { fclose(fp); return 0; } } - else{ - if(!getMeshVertices(numVerticesPerElement, indices, vertexMap, vertices)){ + else { + if(!getMeshVertices(numVerticesPerElement, indices, vertexMap, + vertices)) { fclose(fp); return 0; } @@ -310,26 +349,29 @@ int GModel::readDIFF(const std::string &name) MElementFactory f; MElement *e = f.create(type, vertices, num, partition); - if(!e){ + if(!e) { Msg::Error("Unknown type of element %d", type); fclose(fp); return 0; } - int reg = elementary[i-1][1]; - switch(e->getType()){ - case TYPE_PNT : elements[0][reg].push_back(e); break; - case TYPE_LIN : elements[1][reg].push_back(e); break; - case TYPE_TRI : elements[2][reg].push_back(e); break; - case TYPE_QUA : elements[3][reg].push_back(e); break; - case TYPE_TET : elements[4][reg].push_back(e); break; - case TYPE_HEX : elements[5][reg].push_back(e); break; - case TYPE_PRI : elements[6][reg].push_back(e); break; - case TYPE_PYR : elements[7][reg].push_back(e); break; - default : Msg::Error("Wrong type of element"); fclose(fp); return 0; + int reg = elementary[i - 1][1]; + switch(e->getType()) { + case TYPE_PNT: elements[0][reg].push_back(e); break; + case TYPE_LIN: elements[1][reg].push_back(e); break; + case TYPE_TRI: elements[2][reg].push_back(e); break; + case TYPE_QUA: elements[3][reg].push_back(e); break; + case TYPE_TET: elements[4][reg].push_back(e); break; + case TYPE_HEX: elements[5][reg].push_back(e); break; + case TYPE_PRI: elements[6][reg].push_back(e); break; + case TYPE_PYR: elements[7][reg].push_back(e); break; + default: + Msg::Error("Wrong type of element"); + fclose(fp); + return 0; } int dim = e->getDim(); - if(physical && (!physicals[dim].count(reg) || - !physicals[dim][reg].count(physical))) + if(physical && + (!physicals[dim].count(reg) || !physicals[dim][reg].count(physical))) physicals[dim][reg][physical] = "unnamed"; if(partition > getNumPartitions()) setNumPartitions(partition); @@ -353,8 +395,7 @@ int GModel::readDIFF(const std::string &name) _storeVerticesInEntities(vertexMap); // store the physical tags - for(int i = 0; i < 4; i++) - _storePhysicalTagsInEntities(i, physicals[i]); + for(int i = 0; i < 4; i++) _storePhysicalTagsInEntities(i, physicals[i]); fclose(fp); return 1; @@ -363,13 +404,13 @@ int GModel::readDIFF(const std::string &name) int GModel::writeDIFF(const std::string &name, bool binary, bool saveAll, double scalingFactor) { - if(binary){ + if(binary) { Msg::Error("Binary DIFF output is not implemented"); return 0; } FILE *fp = Fopen(name.c_str(), binary ? "wb" : "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -387,14 +428,15 @@ int GModel::writeDIFF(const std::string &name, bool binary, bool saveAll, // faces, and the vertices would end up categorized on either one.) std::vector<std::list<int> > vertexTags(numVertices); std::list<int> boundaryIndicators; - for(riter it = firstRegion(); it != lastRegion(); it++){ - std::vector<GFace*> faces = (*it)->faces(); - for(std::vector<GFace*>::iterator itf = faces.begin(); itf != faces.end(); itf++){ + for(riter it = firstRegion(); it != lastRegion(); it++) { + std::vector<GFace *> faces = (*it)->faces(); + for(std::vector<GFace *>::iterator itf = faces.begin(); itf != faces.end(); + itf++) { GFace *gf = *itf; boundaryIndicators.push_back(gf->tag()); - for(unsigned int i = 0; i < gf->getNumMeshElements(); i++){ + for(unsigned int i = 0; i < gf->getNumMeshElements(); i++) { MElement *e = gf->getMeshElement(i); - for(std::size_t j = 0; j < e->getNumVertices(); j++){ + for(std::size_t j = 0; j < e->getNumVertices(); j++) { MVertex *v = e->getVertex(j); if(v->getIndex() > 0) vertexTags[v->getIndex() - 1].push_back(gf->tag()); @@ -404,13 +446,13 @@ int GModel::writeDIFF(const std::string &name, bool binary, bool saveAll, } boundaryIndicators.sort(); boundaryIndicators.unique(); - for(int i = 0; i < numVertices; i++){ + for(int i = 0; i < numVertices; i++) { vertexTags[i].sort(); vertexTags[i].unique(); } // get all the entities in the model - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); // find max dimension of mesh elements we need to save @@ -422,13 +464,14 @@ int GModel::writeDIFF(const std::string &name, bool binary, bool saveAll, // loop over all elements we need to save std::size_t numElements = 0, maxNumNodesPerElement = 0; - for(unsigned int i = 0; i < entities.size(); i++){ - if(entities[i]->physicals.size() || saveAll){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + if(entities[i]->physicals.size() || saveAll) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); - if(e->getStringForDIFF() && e->getDim() == dim){ + if(e->getStringForDIFF() && e->getDim() == dim) { numElements++; - maxNumNodesPerElement = std::max(maxNumNodesPerElement, e->getNumVertices()); + maxNumNodesPerElement = + std::max(maxNumNodesPerElement, e->getNumVertices()); } } } @@ -440,7 +483,8 @@ int GModel::writeDIFF(const std::string &name, bool binary, bool saveAll, fprintf(fp, " Number of elements = %lu\n", numElements); fprintf(fp, " Number of nodes = %d\n\n", numVertices); fprintf(fp, " All elements are of the same type : dpTRUE\n"); - fprintf(fp, " Max number of nodes in an element: %lu \n", maxNumNodesPerElement); + fprintf(fp, " Max number of nodes in an element: %lu \n", + maxNumNodesPerElement); fprintf(fp, " Only one subdomain : dpFALSE\n"); fprintf(fp, " Lattice data ? 0\n\n\n\n"); fprintf(fp, " %d Boundary indicators: ", (int)boundaryIndicators.size()); @@ -449,44 +493,44 @@ int GModel::writeDIFF(const std::string &name, bool binary, bool saveAll, fprintf(fp, " %d", *it); fprintf(fp, "\n\n\n"); - fprintf(fp," Nodal coordinates and nodal boundary indicators,\n"); - fprintf(fp," the columns contain:\n"); - fprintf(fp," - node number\n"); - fprintf(fp," - coordinates\n"); - fprintf(fp," - no of boundary indicators that are set (ON)\n"); - fprintf(fp," - the boundary indicators that are set (ON) if any.\n"); - fprintf(fp,"#\n"); + fprintf(fp, " Nodal coordinates and nodal boundary indicators,\n"); + fprintf(fp, " the columns contain:\n"); + fprintf(fp, " - node number\n"); + fprintf(fp, " - coordinates\n"); + fprintf(fp, " - no of boundary indicators that are set (ON)\n"); + fprintf(fp, " - the boundary indicators that are set (ON) if any.\n"); + fprintf(fp, "#\n"); // write mesh vertices - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) { MVertex *v = entities[i]->mesh_vertices[j]; - if(v->getIndex() > 0){ + if(v->getIndex() > 0) { v->writeDIFF(fp, binary, scalingFactor); fprintf(fp, " [%d] ", (int)vertexTags[v->getIndex() - 1].size()); for(std::list<int>::iterator it = vertexTags[v->getIndex() - 1].begin(); it != vertexTags[v->getIndex() - 1].end(); it++) - fprintf(fp," %d ", *it); - fprintf(fp,"\n"); + fprintf(fp, " %d ", *it); + fprintf(fp, "\n"); } } } fprintf(fp, "\n"); fprintf(fp, "\n"); - fprintf(fp, " Element types and connectivity\n"); - fprintf(fp, " the columns contain:\n"); - fprintf(fp, " - element number\n"); - fprintf(fp, " - element type\n"); - fprintf(fp, " - subdomain number \n"); - fprintf(fp, " - the global node numbers of the nodes in the element.\n"); - fprintf(fp, "#\n"); + fprintf(fp, " Element types and connectivity\n"); + fprintf(fp, " the columns contain:\n"); + fprintf(fp, " - element number\n"); + fprintf(fp, " - element type\n"); + fprintf(fp, " - subdomain number \n"); + fprintf(fp, " - the global node numbers of the nodes in the element.\n"); + fprintf(fp, "#\n"); // write mesh elements int num = 0; - for(unsigned int i = 0; i < entities.size(); i++){ - if(entities[i]->physicals.size() || saveAll){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + if(entities[i]->physicals.size() || saveAll) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); if(e->getStringForDIFF() && e->getDim() == dim) e->writeDIFF(fp, ++num, binary, entities[i]->tag()); diff --git a/Geo/GModelIO_Fourier.cpp b/Geo/GModelIO_Fourier.cpp index 39e6ddaf5f7071bc0c801ef28c7b8ace009eda46..51cec792294bcd409d9a3664d42ea0c0d5117b49 100644 --- a/Geo/GModelIO_Fourier.cpp +++ b/Geo/GModelIO_Fourier.cpp @@ -20,89 +20,91 @@ #include "FM_TopoEdge.h" #include "FM_TopoFace.h" -void FM_Internals::makeGFace(FM::Patch* patch, GModel* model) +void FM_Internals::makeGFace(FM::Patch *patch, GModel *model) { double LL[2], LR[2], UL[2], UR[2]; - LL[0] = 0.0; LL[1] = 0.0; - LR[0] = 1.0; LR[1] = 0.0; - UL[0] = 0.0; UL[1] = 1.0; - UR[0] = 1.0; UR[1] = 1.0; - + LL[0] = 0.0; + LL[1] = 0.0; + LR[0] = 1.0; + LR[1] = 0.0; + UL[0] = 0.0; + UL[1] = 1.0; + UR[0] = 1.0; + UR[1] = 1.0; + int i1, i2; - double xx,yy,zz; + double xx, yy, zz; int tagVertex = model->getNumVertices(); patch->F(LL[0], LL[1], xx, yy, zz); - FM::TopoVertex* vLL = new FM::TopoVertex(++tagVertex, xx, yy, zz); + FM::TopoVertex *vLL = new FM::TopoVertex(++tagVertex, xx, yy, zz); model->add(new fourierVertex(model, vLL->GetTag(), vLL)); patch->F(LR[0], LR[1], xx, yy, zz); - FM::TopoVertex* vLR = new FM::TopoVertex(++tagVertex, xx, yy, zz); + FM::TopoVertex *vLR = new FM::TopoVertex(++tagVertex, xx, yy, zz); model->add(new fourierVertex(model, vLR->GetTag(), vLR)); patch->F(UL[0], UL[1], xx, yy, zz); - FM::TopoVertex* vUL = new FM::TopoVertex(++tagVertex, xx, yy, zz); + FM::TopoVertex *vUL = new FM::TopoVertex(++tagVertex, xx, yy, zz); model->add(new fourierVertex(model, vUL->GetTag(), vUL)); patch->F(UR[0], UR[1], xx, yy, zz); - FM::TopoVertex* vUR = new FM::TopoVertex(++tagVertex, xx, yy, zz); + FM::TopoVertex *vUR = new FM::TopoVertex(++tagVertex, xx, yy, zz); model->add(new fourierVertex(model, vUR->GetTag(), vUR)); - - FM::Curve* curveB = new FM::PCurve(LL, LR, patch); - FM::Curve* curveR = new FM::PCurve(LR, UR, patch); - FM::Curve* curveT = new FM::PCurve(UR, UL, patch); - FM::Curve* curveL = new FM::PCurve(UL, LL, patch); - + + FM::Curve *curveB = new FM::PCurve(LL, LR, patch); + FM::Curve *curveR = new FM::PCurve(LR, UR, patch); + FM::Curve *curveT = new FM::PCurve(UR, UL, patch); + FM::Curve *curveL = new FM::PCurve(UL, LL, patch); + int tagEdge = model->getNumEdges(); - FM::TopoEdge* eB = new FM::TopoEdge(++tagEdge, curveB, vLL, vLR); + FM::TopoEdge *eB = new FM::TopoEdge(++tagEdge, curveB, vLL, vLR); i1 = eB->GetStartPoint()->GetTag(); i2 = eB->GetEndPoint()->GetTag(); model->add(new fourierEdge(model, eB, eB->GetTag(), model->getVertexByTag(i1), - model->getVertexByTag(i2))); - FM::TopoEdge* eR = new FM::TopoEdge(++tagEdge, curveR, vLR, vUR); + model->getVertexByTag(i2))); + FM::TopoEdge *eR = new FM::TopoEdge(++tagEdge, curveR, vLR, vUR); i1 = eR->GetStartPoint()->GetTag(); i2 = eR->GetEndPoint()->GetTag(); model->add(new fourierEdge(model, eR, eR->GetTag(), model->getVertexByTag(i1), - model->getVertexByTag(i2))); - FM::TopoEdge* eT = new FM::TopoEdge(++tagEdge, curveT, vUR, vUL); + model->getVertexByTag(i2))); + FM::TopoEdge *eT = new FM::TopoEdge(++tagEdge, curveT, vUR, vUL); i1 = eT->GetStartPoint()->GetTag(); i2 = eT->GetEndPoint()->GetTag(); model->add(new fourierEdge(model, eT, eT->GetTag(), model->getVertexByTag(i1), - model->getVertexByTag(i2))); - FM::TopoEdge* eL = new FM::TopoEdge(++tagEdge, curveL, vUL, vLL); + model->getVertexByTag(i2))); + FM::TopoEdge *eL = new FM::TopoEdge(++tagEdge, curveL, vUL, vLL); i1 = eL->GetStartPoint()->GetTag(); i2 = eL->GetEndPoint()->GetTag(); model->add(new fourierEdge(model, eL, eL->GetTag(), model->getVertexByTag(i1), - model->getVertexByTag(i2))); - - FM::TopoFace* face = new FM::TopoFace(model->getNumFaces() + 1, patch); - face->AddEdge(eB); face->AddEdge(eR); - face->AddEdge(eT); face->AddEdge(eL); - std::list<GEdge*> l_edges; - for (int j = 0; j < face->GetNumEdges(); j++) { - int tag = face->GetEdge(j)->GetTag(); + model->getVertexByTag(i2))); + + FM::TopoFace *face = new FM::TopoFace(model->getNumFaces() + 1, patch); + face->AddEdge(eB); + face->AddEdge(eR); + face->AddEdge(eT); + face->AddEdge(eL); + std::list<GEdge *> l_edges; + for(int j = 0; j < face->GetNumEdges(); j++) { + int tag = face->GetEdge(j)->GetTag(); l_edges.push_back(model->getEdgeByTag(tag)); } model->add(new fourierFace(model, face, face->GetTag(), l_edges)); } -void FM_Internals::loadFM() -{ - reader.push_back(new FM::Reader()); -} +void FM_Internals::loadFM() { reader.push_back(new FM::Reader()); } -void FM_Internals::loadFM(const char* filename) +void FM_Internals::loadFM(const char *filename) { reader.push_back(new FM::Reader(filename)); } -void FM_Internals::buildGModel(FM::Reader* reader, GModel* model) +void FM_Internals::buildGModel(FM::Reader *reader, GModel *model) { - for (int i = 0; i < reader->GetNumPatches(); i++) + for(int i = 0; i < reader->GetNumPatches(); i++) makeGFace(reader->GetPatch(i), model); } void GModel::_createFMInternals() { - if (!_fm_internals) - _fm_internals = new FM_Internals; + if(!_fm_internals) _fm_internals = new FM_Internals; } void GModel::_deleteFMInternals() @@ -122,36 +124,30 @@ int GModel::readFourier(const std::string &filename) { _createFMInternals(); getFMInternals()->loadFM(filename.c_str()); - getFMInternals()->buildGModel(getFMInternals()->current(),this); + getFMInternals()->buildGModel(getFMInternals()->current(), this); return 1; } -int GModel::writeFourier(const std::string &filename) -{ - return 0; -} +int GModel::writeFourier(const std::string &filename) { return 0; } #else -void GModel::_createFMInternals() -{ -} +void GModel::_createFMInternals() {} -void GModel::_deleteFMInternals() -{ -} +void GModel::_deleteFMInternals() {} int GModel::readFourier() { - Msg::Error("Gmsh must be compiled with Fourier Model support toad fourier Model"); + Msg::Error( + "Gmsh must be compiled with Fourier Model support toad fourier Model"); return 0; } int GModel::readFourier(const std::string &fn) { Msg::Error("Gmsh must be compiled with Fourier Model support to load '%s'", - fn.c_str()); + fn.c_str()); return 0; } diff --git a/Geo/GModelIO_Fourier.h b/Geo/GModelIO_Fourier.h index 8c5b233721ae4bbd908413eec6e345a59640fd4f..7375be76df2b60f6df894bd4911a2a5bd5135459 100644 --- a/Geo/GModelIO_Fourier.h +++ b/Geo/GModelIO_Fourier.h @@ -15,24 +15,24 @@ #include "FM_Reader.h" class FM_Internals { - private: - std::vector<FM::Reader*> reader; +private: + std::vector<FM::Reader *> reader; - public: +public: FM_Internals() {} ~FM_Internals() {} void loadFM(); - void loadFM(const char* filename); - void makeGFace(FM::Patch* patch, GModel* model); - void buildGModel(FM::Reader* reater, GModel* model); + void loadFM(const char *filename); + void makeGFace(FM::Patch *patch, GModel *model); + void buildGModel(FM::Reader *reater, GModel *model); - FM::Reader* getReader(int tag) - { + FM::Reader *getReader(int tag) + { if(tag < (int)reader.size()) return reader[tag]; } int getSize() { return reader.size(); } - FM::Reader* current() { return reader[reader.size() - 1]; } + FM::Reader *current() { return reader[reader.size() - 1]; } }; #endif diff --git a/Geo/GModelIO_GEO.cpp b/Geo/GModelIO_GEO.cpp index 068f3006e250c6b6e34709da7538798f742177df..3c9ef2df758622a9d10a1cda1b2d6dbf07ee9c5d 100644 --- a/Geo/GModelIO_GEO.cpp +++ b/Geo/GModelIO_GEO.cpp @@ -53,27 +53,39 @@ void GEO_Internals::_freeAll() _maxPointNum = _maxLineNum = _maxLineLoopNum = _maxSurfaceNum = 0; _maxSurfaceLoopNum = _maxVolumeNum = _maxPhysicalNum = 0; - Tree_Action(Points, FreeVertex); Tree_Delete(Points); - Tree_Action(Curves, FreeCurve); Tree_Delete(Curves); - Tree_Action(EdgeLoops, FreeEdgeLoop); Tree_Delete(EdgeLoops); - Tree_Action(Surfaces, FreeSurface); Tree_Delete(Surfaces); - Tree_Action(SurfaceLoops, FreeSurfaceLoop); Tree_Delete(SurfaceLoops); - Tree_Action(Volumes, FreeVolume); Tree_Delete(Volumes); + Tree_Action(Points, FreeVertex); + Tree_Delete(Points); + Tree_Action(Curves, FreeCurve); + Tree_Delete(Curves); + Tree_Action(EdgeLoops, FreeEdgeLoop); + Tree_Delete(EdgeLoops); + Tree_Action(Surfaces, FreeSurface); + Tree_Delete(Surfaces); + Tree_Action(SurfaceLoops, FreeSurfaceLoop); + Tree_Delete(SurfaceLoops); + Tree_Action(Volumes, FreeVolume); + Tree_Delete(Volumes); + + Tree_Action(DelPoints, FreeVertex); + Tree_Delete(DelPoints); + Tree_Action(DelCurves, FreeCurve); + Tree_Delete(DelCurves); + Tree_Action(DelSurfaces, FreeSurface); + Tree_Delete(DelSurfaces); + Tree_Action(DelVolumes, FreeVolume); + Tree_Delete(DelVolumes); - Tree_Action(DelPoints, FreeVertex); Tree_Delete(DelPoints); - Tree_Action(DelCurves, FreeCurve); Tree_Delete(DelCurves); - Tree_Action(DelSurfaces, FreeSurface); Tree_Delete(DelSurfaces); - Tree_Action(DelVolumes, FreeVolume); Tree_Delete(DelVolumes); - - List_Action(PhysicalGroups, FreePhysicalGroup); List_Delete(PhysicalGroups); - List_Action(DelPhysicalGroups, FreePhysicalGroup); List_Delete(DelPhysicalGroups); + List_Action(PhysicalGroups, FreePhysicalGroup); + List_Delete(PhysicalGroups); + List_Action(DelPhysicalGroups, FreePhysicalGroup); + List_Delete(DelPhysicalGroups); _changed = true; } void GEO_Internals::setMaxTag(int dim, int val) { - switch(dim){ + switch(dim) { case 0: _maxPointNum = val; break; case 1: _maxLineNum = val; break; case -1: _maxLineLoopNum = val; break; @@ -85,7 +97,7 @@ void GEO_Internals::setMaxTag(int dim, int val) int GEO_Internals::getMaxTag(int dim) const { - switch(dim){ + switch(dim) { case 0: return _maxPointNum; case 1: return _maxLineNum; case -1: return _maxLineLoopNum; @@ -98,7 +110,7 @@ int GEO_Internals::getMaxTag(int dim) const bool GEO_Internals::addVertex(int &tag, double x, double y, double z, double lc) { - if(tag >= 0 && FindPoint(tag)){ + if(tag >= 0 && FindPoint(tag)) { Msg::Error("GEO point with tag %d already exists", tag); return false; } @@ -110,10 +122,10 @@ bool GEO_Internals::addVertex(int &tag, double x, double y, double z, double lc) return true; } -bool GEO_Internals::addVertex(int &tag, double x, double y, gmshSurface *surface, - double lc) +bool GEO_Internals::addVertex(int &tag, double x, double y, + gmshSurface *surface, double lc) { - if(tag >= 0 && FindPoint(tag)){ + if(tag >= 0 && FindPoint(tag)) { Msg::Error("GEO point with tag %d already exists", tag); return false; } @@ -134,17 +146,17 @@ bool GEO_Internals::addLine(int &tag, int startTag, int endTag) bool GEO_Internals::addLine(int &tag, const std::vector<int> &pointTags) { - if(tag >= 0 && FindCurve(tag)){ + if(tag >= 0 && FindCurve(tag)) { Msg::Error("GEO curve with tag %d already exists", tag); return false; } - if(pointTags.size() < 2){ + if(pointTags.size() < 2) { Msg::Error("Line curve requires 2 points"); return false; } if(tag < 0) tag = getMaxTag(1) + 1; List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < pointTags.size(); i++){ + for(unsigned int i = 0; i < pointTags.size(); i++) { int t = pointTags[i]; List_Add(tmp, &t); } @@ -156,10 +168,10 @@ bool GEO_Internals::addLine(int &tag, const std::vector<int> &pointTags) return true; } -bool GEO_Internals::addCircleArc(int &tag, int startTag, int centerTag, int endTag, - double nx, double ny, double nz) +bool GEO_Internals::addCircleArc(int &tag, int startTag, int centerTag, + int endTag, double nx, double ny, double nz) { - if(tag >= 0 && FindCurve(tag)){ + if(tag >= 0 && FindCurve(tag)) { Msg::Error("GEO curve with tag %d already exists", tag); return false; } @@ -169,7 +181,7 @@ bool GEO_Internals::addCircleArc(int &tag, int startTag, int centerTag, int endT List_Add(tmp, ¢erTag); List_Add(tmp, &endTag); Curve *c = CreateCurve(tag, MSH_SEGM_CIRC, 2, tmp, NULL, -1, -1, 0., 1.); - if(nx || ny || nz){ + if(nx || ny || nz) { c->Circle.n[0] = nx; c->Circle.n[1] = ny; c->Circle.n[2] = nz; @@ -177,7 +189,7 @@ bool GEO_Internals::addCircleArc(int &tag, int startTag, int centerTag, int endT } Tree_Add(Curves, &c); Curve *rc = CreateReversedCurve(c); - if(nx || ny || nz){ + if(nx || ny || nz) { rc->Circle.n[0] = nx; rc->Circle.n[1] = ny; rc->Circle.n[2] = nz; @@ -188,10 +200,11 @@ bool GEO_Internals::addCircleArc(int &tag, int startTag, int centerTag, int endT return true; } -bool GEO_Internals::addEllipseArc(int &tag, int startTag, int centerTag, int majorTag, - int endTag, double nx, double ny, double nz) +bool GEO_Internals::addEllipseArc(int &tag, int startTag, int centerTag, + int majorTag, int endTag, double nx, + double ny, double nz) { - if(tag >= 0 && FindCurve(tag)){ + if(tag >= 0 && FindCurve(tag)) { Msg::Error("GEO curve with tag %d already exists", tag); return false; } @@ -202,7 +215,7 @@ bool GEO_Internals::addEllipseArc(int &tag, int startTag, int centerTag, int maj List_Add(tmp, &majorTag); List_Add(tmp, &endTag); Curve *c = CreateCurve(tag, MSH_SEGM_ELLI, 2, tmp, NULL, -1, -1, 0., 1.); - if(nx || ny || nz){ + if(nx || ny || nz) { c->Circle.n[0] = nx; c->Circle.n[1] = ny; c->Circle.n[2] = nz; @@ -210,7 +223,7 @@ bool GEO_Internals::addEllipseArc(int &tag, int startTag, int centerTag, int maj } Tree_Add(Curves, &c); Curve *rc = CreateReversedCurve(c); - if(nx || ny || nz){ + if(nx || ny || nz) { rc->Circle.n[0] = nx; rc->Circle.n[1] = ny; rc->Circle.n[2] = nz; @@ -223,17 +236,17 @@ bool GEO_Internals::addEllipseArc(int &tag, int startTag, int centerTag, int maj bool GEO_Internals::addSpline(int &tag, const std::vector<int> &pointTags) { - if(tag >= 0 && FindCurve(tag)){ + if(tag >= 0 && FindCurve(tag)) { Msg::Error("GEO curve with tag %d already exists", tag); return false; } - if(pointTags.size() < 2){ + if(pointTags.size() < 2) { Msg::Error("Spline curve requires at least 2 control points"); return false; } if(tag < 0) tag = getMaxTag(1) + 1; List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < pointTags.size(); i++){ + for(unsigned int i = 0; i < pointTags.size(); i++) { int t = pointTags[i]; List_Add(tmp, &t); } @@ -247,17 +260,17 @@ bool GEO_Internals::addSpline(int &tag, const std::vector<int> &pointTags) bool GEO_Internals::addBezier(int &tag, const std::vector<int> &pointTags) { - if(tag >= 0 && FindCurve(tag)){ + if(tag >= 0 && FindCurve(tag)) { Msg::Error("GEO curve with tag %d already exists", tag); return false; } if(tag < 0) tag = getMaxTag(1) + 1; - if(pointTags.size() < 2){ + if(pointTags.size() < 2) { Msg::Error("Bezier curve requires at least 2 control points"); return false; } List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < pointTags.size(); i++){ + for(unsigned int i = 0; i < pointTags.size(); i++) { int t = pointTags[i]; List_Add(tmp, &t); } @@ -272,28 +285,28 @@ bool GEO_Internals::addBezier(int &tag, const std::vector<int> &pointTags) bool GEO_Internals::addBSpline(int &tag, const std::vector<int> &pointTags, const std::vector<double> &seqknots) { - if(tag >= 0 && FindCurve(tag)){ + if(tag >= 0 && FindCurve(tag)) { Msg::Error("GEO curve with tag %d already exists", tag); return false; } - if(pointTags.size() < 2){ + if(pointTags.size() < 2) { Msg::Error("BSpline curve requires at least 2 control points"); return false; } if(tag < 0) tag = getMaxTag(1) + 1; List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < pointTags.size(); i++){ + for(unsigned int i = 0; i < pointTags.size(); i++) { int t = pointTags[i]; List_Add(tmp, &t); } Curve *c; - if(seqknots.empty()){ + if(seqknots.empty()) { c = CreateCurve(tag, MSH_SEGM_BSPLN, 2, tmp, NULL, -1, -1, 0., 1.); } - else{ + else { int order = seqknots.size() - pointTags.size() - 1; List_T *knotsList = List_Create(2, 2, sizeof(double)); - for(unsigned int i = 0; i < seqknots.size(); i++){ + for(unsigned int i = 0; i < seqknots.size(); i++) { double d = seqknots[i]; List_Add(knotsList, &d); } @@ -308,13 +321,13 @@ bool GEO_Internals::addBSpline(int &tag, const std::vector<int> &pointTags, bool GEO_Internals::addLineLoop(int &tag, const std::vector<int> &curveTags) { - if(tag >= 0 && FindEdgeLoop(tag)){ + if(tag >= 0 && FindEdgeLoop(tag)) { Msg::Error("GEO line loop with tag %d already exists", tag); return false; } if(tag < 0) tag = getMaxTag(-1) + 1; List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < curveTags.size(); i++){ + for(unsigned int i = 0; i < curveTags.size(); i++) { int t = curveTags[i]; List_Add(tmp, &t); } @@ -328,17 +341,17 @@ bool GEO_Internals::addLineLoop(int &tag, const std::vector<int> &curveTags) bool GEO_Internals::addPlaneSurface(int &tag, const std::vector<int> &wireTags) { - if(tag >= 0 && FindSurface(tag)){ + if(tag >= 0 && FindSurface(tag)) { Msg::Error("GEO surface with tag %d already exists", tag); return false; } if(tag < 0) tag = getMaxTag(2) + 1; - if(wireTags.empty()){ + if(wireTags.empty()) { Msg::Error("Plane surface requires at least one line loop"); return false; } List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < wireTags.size(); i++){ + for(unsigned int i = 0; i < wireTags.size(); i++) { int t = wireTags[i]; List_Add(tmp, &t); } @@ -353,7 +366,7 @@ bool GEO_Internals::addPlaneSurface(int &tag, const std::vector<int> &wireTags) bool GEO_Internals::addDiscreteSurface(int &tag) { - if(tag >= 0 && FindSurface(tag)){ + if(tag >= 0 && FindSurface(tag)) { Msg::Error("GEO surface with tag %d already exists", tag); return false; } @@ -364,21 +377,22 @@ bool GEO_Internals::addDiscreteSurface(int &tag) return true; } -bool GEO_Internals::addSurfaceFilling(int &tag, const std::vector<int> &wireTags, +bool GEO_Internals::addSurfaceFilling(int &tag, + const std::vector<int> &wireTags, int sphereCenterTag) { - if(tag >= 0 && FindSurface(tag)){ + if(tag >= 0 && FindSurface(tag)) { Msg::Error("GEO surface with tag %d already exists", tag); return false; } if(tag < 0) tag = getMaxTag(2) + 1; - if(wireTags.empty()){ + if(wireTags.empty()) { Msg::Error("Surface requires at least one line loop"); return false; } int ll = (int)std::abs(wireTags[0]); EdgeLoop *el = FindEdgeLoop(ll); - if(!el){ + if(!el) { Msg::Error("Unknown line loop %d", ll); return false; } @@ -387,13 +401,13 @@ bool GEO_Internals::addSurfaceFilling(int &tag, const std::vector<int> &wireTags type = MSH_SURF_REGL; else if(j == 3) type = MSH_SURF_TRIC; - else{ + else { Msg::Error("Wrong definition of surface %d: %d borders instead of 3 or 4", tag, j); return false; } List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < wireTags.size(); i++){ + for(unsigned int i = 0; i < wireTags.size(); i++) { int t = wireTags[i]; List_Add(tmp, &t); } @@ -401,9 +415,9 @@ bool GEO_Internals::addSurfaceFilling(int &tag, const std::vector<int> &wireTags SetSurfaceGeneratrices(s, tmp); List_Delete(tmp); EndSurface(s); - if(sphereCenterTag >= 0){ + if(sphereCenterTag >= 0) { s->InSphereCenter = FindPoint(sphereCenterTag); - if(!s->InSphereCenter){ + if(!s->InSphereCenter) { Msg::Error("Unknown sphere center vertex %d", sphereCenterTag); } } @@ -412,16 +426,17 @@ bool GEO_Internals::addSurfaceFilling(int &tag, const std::vector<int> &wireTags return true; } -bool GEO_Internals::addSurfaceLoop(int &tag, const std::vector<int> &surfaceTags) +bool GEO_Internals::addSurfaceLoop(int &tag, + const std::vector<int> &surfaceTags) { - if(tag >= 0 && FindSurfaceLoop(tag)){ + if(tag >= 0 && FindSurfaceLoop(tag)) { Msg::Error("GEO surface loop with tag %d already exists", tag); return false; } if(tag < 0) tag = getMaxTag(-2) + 1; List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < surfaceTags.size(); i++){ + for(unsigned int i = 0; i < surfaceTags.size(); i++) { int t = surfaceTags[i]; List_Add(tmp, &t); } @@ -434,14 +449,14 @@ bool GEO_Internals::addSurfaceLoop(int &tag, const std::vector<int> &surfaceTags bool GEO_Internals::addVolume(int &tag, const std::vector<int> &shellTags) { - if(tag >= 0 && FindVolume(tag)){ + if(tag >= 0 && FindVolume(tag)) { Msg::Error("GEO volume with tag %d already exists", tag); return false; } if(tag < 0) tag = getMaxTag(3) + 1; List_T *tmp = List_Create(2, 2, sizeof(int)); - for(unsigned int i = 0; i < shellTags.size(); i++){ + for(unsigned int i = 0; i < shellTags.size(); i++) { int t = shellTags[i]; List_Add(tmp, &t); } @@ -455,43 +470,48 @@ bool GEO_Internals::addVolume(int &tag, const std::vector<int> &shellTags) bool GEO_Internals::_extrude(int mode, const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double dx, double dy, double dz, - double ax, double ay, double az, double angle, + double x, double y, double z, double dx, double dy, + double dz, double ax, double ay, double az, + double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e) { List_T *in = List_Create(inDimTags.size() + 1, 10, sizeof(Shape)); List_T *out = List_Create(3 * inDimTags.size() + 1, 10, sizeof(Shape)); - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { int dim = inDimTags[i].first; int tag = inDimTags[i].second; Shape s; - s.Type = (dim == 3) ? MSH_VOLUME : (dim == 2) ? MSH_SURF_PLAN : - (dim == 1) ? MSH_SEGM_LINE : MSH_POINT; + s.Type = (dim == 3) ? MSH_VOLUME : + (dim == 2) ? MSH_SURF_PLAN : + (dim == 1) ? MSH_SEGM_LINE : MSH_POINT; s.Num = tag; List_Add(in, &s); } - if(mode == 0){ // extrude - ExtrudeShapes(TRANSLATE, in, dx, dy, dz, 0., 0., 0., 0., 0., 0., 0., e, out); + if(mode == 0) { // extrude + ExtrudeShapes(TRANSLATE, in, dx, dy, dz, 0., 0., 0., 0., 0., 0., 0., e, + out); } - else if(mode == 1){ // revolve + else if(mode == 1) { // revolve ExtrudeShapes(ROTATE, in, 0., 0., 0., ax, ay, az, x, y, z, angle, e, out); } - else if(mode == 2){ // extrude+revolve - ExtrudeShapes(TRANSLATE_ROTATE, in, dx, dy, dz, ax, ay, az, x, y, z, angle, e, out); + else if(mode == 2) { // extrude+revolve + ExtrudeShapes(TRANSLATE_ROTATE, in, dx, dy, dz, ax, ay, az, x, y, z, angle, + e, out); } - else if(mode == 3){ // boundary layer - ExtrudeShapes(BOUNDARY_LAYER, in, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., e, out); + else if(mode == 3) { // boundary layer + ExtrudeShapes(BOUNDARY_LAYER, in, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., e, + out); } - for(int i = 0; i < List_Nbr(out); i++){ + for(int i = 0; i < List_Nbr(out); i++) { Shape s; List_Read(out, i, &s); int dim = s.Type / 100 - 1; - if(dim >= 0 && dim <= 3) outDimTags.push_back(std::pair<int, int>(dim, s.Num)); + if(dim >= 0 && dim <= 3) + outDimTags.push_back(std::pair<int, int>(dim, s.Num)); } _changed = true; return true; @@ -507,8 +527,8 @@ bool GEO_Internals::extrude(const std::vector<std::pair<int, int> > &inDimTags, } bool GEO_Internals::revolve(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double ax, double ay, double az, double angle, + double x, double y, double z, double ax, double ay, + double az, double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e) { @@ -517,9 +537,9 @@ bool GEO_Internals::revolve(const std::vector<std::pair<int, int> > &inDimTags, } bool GEO_Internals::twist(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double dx, double dy, double dz, - double ax, double ay, double az, double angle, + double x, double y, double z, double dx, double dy, + double dz, double ax, double ay, double az, + double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e) { @@ -527,9 +547,9 @@ bool GEO_Internals::twist(const std::vector<std::pair<int, int> > &inDimTags, outDimTags, e); } -bool GEO_Internals::boundaryLayer(const std::vector<std::pair<int, int> > &inDimTags, - std::vector<std::pair<int, int> > &outDimTags, - ExtrudeParams *e) +bool GEO_Internals::boundaryLayer( + const std::vector<std::pair<int, int> > &inDimTags, + std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e) { return _extrude(3, inDimTags, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., outDimTags, e); @@ -537,21 +557,22 @@ bool GEO_Internals::boundaryLayer(const std::vector<std::pair<int, int> > &inDim bool GEO_Internals::_transform(int mode, const std::vector<std::pair<int, int> > &dimTags, - double x, double y, double z, - double dx, double dy, double dz, - double a, double b, double c, double d) + double x, double y, double z, double dx, + double dy, double dz, double a, double b, + double c, double d) { List_T *list = List_Create(dimTags.size() + 1, 10, sizeof(Shape)); - for(unsigned int i = 0; i < dimTags.size(); i++){ + for(unsigned int i = 0; i < dimTags.size(); i++) { int dim = dimTags[i].first; int tag = dimTags[i].second; Shape s; - s.Type = (dim == 3) ? MSH_VOLUME : (dim == 2) ? MSH_SURF_PLAN : - (dim == 1) ? MSH_SEGM_LINE : MSH_POINT; + s.Type = (dim == 3) ? MSH_VOLUME : + (dim == 2) ? MSH_SURF_PLAN : + (dim == 1) ? MSH_SEGM_LINE : MSH_POINT; s.Num = tag; List_Add(list, &s); } - switch(mode){ + switch(mode) { case 0: TranslateShapes(dx, dy, dz, list); break; case 1: RotateShapes(dx, dy, dz, x, y, z, a, list); break; case 2: DilatShapes(x, y, z, a, b, c, list); break; @@ -568,15 +589,15 @@ bool GEO_Internals::translate(const std::vector<std::pair<int, int> > &dimTags, } bool GEO_Internals::rotate(const std::vector<std::pair<int, int> > &dimTags, - double x, double y, double z, - double ax, double ay, double az, double angle) + double x, double y, double z, double ax, double ay, + double az, double angle) { return _transform(1, dimTags, x, y, z, ax, ay, az, angle, 0, 0, 0); } bool GEO_Internals::dilate(const std::vector<std::pair<int, int> > &dimTags, - double x, double y, double z, - double a, double b, double c) + double x, double y, double z, double a, double b, + double c) { return _transform(2, dimTags, x, y, z, 0, 0, 0, a, b, c, 0); } @@ -591,13 +612,13 @@ bool GEO_Internals::splitCurve(int tag, const std::vector<int> &pointTags, std::vector<int> &curveTags) { List_T *tmp = List_Create(10, 10, sizeof(int)); - for(unsigned int i = 0; i < pointTags.size(); i++){ + for(unsigned int i = 0; i < pointTags.size(); i++) { int t = pointTags[i]; List_Add(tmp, &t); } List_T *curves = List_Create(10, 10, sizeof(Curve *)); SplitCurve(tag, tmp, curves); - for(int i = 0; i < List_Nbr(curves); i++){ + for(int i = 0; i < List_Nbr(curves); i++) { Curve *c; List_Read(curves, i, &c); curveTags.push_back(c->Num); @@ -608,24 +629,24 @@ bool GEO_Internals::splitCurve(int tag, const std::vector<int> &pointTags, return true; } -bool GEO_Internals::intersectCurvesWithSurface(const std::vector<int> &curveTags, - int surfaceTag, - std::vector<int> &pointTags) +bool GEO_Internals::intersectCurvesWithSurface( + const std::vector<int> &curveTags, int surfaceTag, + std::vector<int> &pointTags) { List_T *curves = List_Create(10, 10, sizeof(double)); List_T *shapes = List_Create(10, 10, sizeof(Shape)); - for(unsigned int i = 0; i < curveTags.size(); i++){ + for(unsigned int i = 0; i < curveTags.size(); i++) { double d = curveTags[i]; List_Add(curves, &d); } IntersectCurvesWithSurface(curves, surfaceTag, shapes); - for(int i = 0; i < List_Nbr(shapes); i++){ + for(int i = 0; i < List_Nbr(shapes); i++) { Shape s; List_Read(shapes, i, &s); - if(s.Type == MSH_POINT){ + if(s.Type == MSH_POINT) { pointTags.push_back(s.Num); } - else{ + else { Msg::Error("Degenerated curve-surface intersection not implemented"); return false; } @@ -638,49 +659,49 @@ bool GEO_Internals::copy(const std::vector<std::pair<int, int> > &inDimTags, std::vector<std::pair<int, int> > &outDimTags) { bool ret = true; - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { int dim = inDimTags[i].first; int tag = inDimTags[i].second; - if(dim == 0){ + if(dim == 0) { Vertex *v = FindPoint(tag); - if(!v){ + if(!v) { Msg::Error("Unknown GEO point with tag %d", tag); ret = false; } - else{ + else { Vertex *newv = DuplicateVertex(v); outDimTags.push_back(std::pair<int, int>(0, newv->Num)); } } - else if(dim == 1){ + else if(dim == 1) { Curve *c = FindCurve(tag); - if(!c){ + if(!c) { Msg::Error("Unknown GEO curve with tag %d", tag); ret = false; } - else{ + else { Curve *newc = DuplicateCurve(c); outDimTags.push_back(std::pair<int, int>(1, newc->Num)); } } - else if(dim == 2){ + else if(dim == 2) { Surface *s = FindSurface(tag); - if(!s){ + if(!s) { Msg::Error("Unknown GEO surface with tag %d", tag); ret = false; } - else{ + else { Surface *news = DuplicateSurface(s); outDimTags.push_back(std::pair<int, int>(2, news->Num)); } } - else if(dim == 3){ + else if(dim == 3) { Volume *v = FindVolume(tag); - if(!v){ + if(!v) { Msg::Error("Unknown GEO volume with tag %d", tag); ret = false; } - else{ + else { Volume *newv = DuplicateVolume(v); outDimTags.push_back(std::pair<int, int>(3, newv->Num)); } @@ -692,9 +713,12 @@ bool GEO_Internals::copy(const std::vector<std::pair<int, int> > &inDimTags, bool GEO_Internals::remove(int dim, int tag, bool recursive) { - switch(dim){ + switch(dim) { case 0: DeletePoint(tag, recursive); break; - case 1: DeleteCurve(tag, recursive); DeleteCurve(-tag, recursive); break; + case 1: + DeleteCurve(tag, recursive); + DeleteCurve(-tag, recursive); + break; case 2: DeleteSurface(tag, recursive); break; case 3: DeleteVolume(tag, recursive); break; } @@ -723,26 +747,38 @@ bool GEO_Internals::modifyPhysicalGroup(int dim, int tag, int op, { int type; std::string str; - switch(dim){ - case 0: type = MSH_PHYSICAL_POINT; str = "point"; break; - case 1: type = MSH_PHYSICAL_LINE; str = "line"; break; - case 2: type = MSH_PHYSICAL_SURFACE; str = "surface"; break; - case 3: type = MSH_PHYSICAL_VOLUME; str = "volume"; break; + switch(dim) { + case 0: + type = MSH_PHYSICAL_POINT; + str = "point"; + break; + case 1: + type = MSH_PHYSICAL_LINE; + str = "line"; + break; + case 2: + type = MSH_PHYSICAL_SURFACE; + str = "surface"; + break; + case 3: + type = MSH_PHYSICAL_VOLUME; + str = "volume"; + break; default: return false; } PhysicalGroup *p = FindPhysicalGroup(tag, type); - if(p && op == 0){ + if(p && op == 0) { Msg::Error("Physical %s %d already exists", str.c_str(), tag); return false; } - else if(!p && op > 0){ + else if(!p && op > 0) { Msg::Error("Physical %s %d does not exist", str.c_str(), tag); return false; } - else if(op == 0){ + else if(op == 0) { List_T *tmp = List_Create(10, 10, sizeof(int)); - for(unsigned int i = 0; i < tags.size(); i++){ + for(unsigned int i = 0; i < tags.size(); i++) { int t = tags[i]; List_Add(tmp, &t); } @@ -750,19 +786,19 @@ bool GEO_Internals::modifyPhysicalGroup(int dim, int tag, int op, List_Delete(tmp); List_Add(PhysicalGroups, &p); } - else if(op == 1){ - for(unsigned int i = 0; i < tags.size(); i++){ + else if(op == 1) { + for(unsigned int i = 0; i < tags.size(); i++) { int t = tags[i]; List_Add(p->Entities, &t); } } - else if(op == 2){ - for(unsigned int i = 0; i < tags.size(); i++){ + else if(op == 2) { + for(unsigned int i = 0; i < tags.size(); i++) { int t = tags[i]; List_Suppress(p->Entities, &t, fcmp_int); } - if(!List_Nbr(p->Entities)){ - switch(dim){ + if(!List_Nbr(p->Entities)) { + switch(dim) { case 0: DeletePhysicalPoint(tag); break; case 1: DeletePhysicalLine(tag); break; case 2: DeletePhysicalSurface(tag); break; @@ -770,7 +806,7 @@ bool GEO_Internals::modifyPhysicalGroup(int dim, int tag, int op, } } } - else{ + else { Msg::Error("Unsupported operation on physical %s %d", str.c_str(), tag); return false; } @@ -788,15 +824,15 @@ bool GEO_Internals::mergeVertices(const std::vector<int> &tags) { if(tags.size() < 2) return true; Vertex *target = FindPoint(tags[0]); - if(!target){ + if(!target) { Msg::Error("Could not find GEO point with tag %d", tags[0]); return false; } double x = target->Pos.X, y = target->Pos.Y, z = target->Pos.Z; - for(unsigned int i = 1; i < tags.size(); i++){ + for(unsigned int i = 1; i < tags.size(); i++) { Vertex *source = FindPoint(tags[i]); - if(!source){ + if(!source) { Msg::Error("Could not find GEO point with tag %d", tags[i]); return false; } @@ -820,7 +856,7 @@ void GEO_Internals::setCompoundMesh(int dim, const std::vector<int> &tags) void GEO_Internals::setMeshSize(int dim, int tag, double size) { - if(dim != 0){ + if(dim != 0) { Msg::Error("Setting mesh size only available on GEO points"); return; } @@ -837,11 +873,12 @@ void GEO_Internals::setDegenerated(int dim, int tag) _changed = true; } -void GEO_Internals::setTransfiniteLine(int tag, int nPoints, int type, double coef) +void GEO_Internals::setTransfiniteLine(int tag, int nPoints, int type, + double coef) { - if(!tag){ + if(!tag) { List_T *tmp = Tree2List(Curves); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Curve *c; List_Read(tmp, i, &c); c->Method = MESH_TRANSFINITE; @@ -851,9 +888,9 @@ void GEO_Internals::setTransfiniteLine(int tag, int nPoints, int type, double co } List_Delete(tmp); } - else{ + else { Curve *c = FindCurve(tag); - if(c){ + if(c) { c->Method = MESH_TRANSFINITE; c->nbPointsTransfinite = (nPoints > 2) ? nPoints : 2; c->typeTransfinite = type; @@ -866,9 +903,9 @@ void GEO_Internals::setTransfiniteLine(int tag, int nPoints, int type, double co void GEO_Internals::setTransfiniteSurface(int tag, int arrangement, const std::vector<int> &cornerTags) { - if(!tag){ + if(!tag) { List_T *tmp = Tree2List(Surfaces); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Surface *s; List_Read(tmp, i, &s); s->Method = MESH_TRANSFINITE; @@ -877,14 +914,15 @@ void GEO_Internals::setTransfiniteSurface(int tag, int arrangement, } List_Delete(tmp); } - else{ + else { Surface *s = FindSurface(tag); - if(s){ + if(s) { s->Method = MESH_TRANSFINITE; s->Recombine_Dir = arrangement; List_Reset(s->TrsfPoints); - if(cornerTags.empty() || cornerTags.size() == 3 || cornerTags.size() == 4){ - for(unsigned int j = 0; j < cornerTags.size(); j++){ + if(cornerTags.empty() || cornerTags.size() == 3 || + cornerTags.size() == 4) { + for(unsigned int j = 0; j < cornerTags.size(); j++) { Vertex *v = FindPoint(std::abs(cornerTags[j])); if(v) List_Add(s->TrsfPoints, &v); @@ -892,7 +930,7 @@ void GEO_Internals::setTransfiniteSurface(int tag, int arrangement, Msg::Error("Unknown GEO point with tag %d", cornerTags[j]); } } - else{ + else { Msg::Error("Transfinite surface requires 3 or 4 corner points"); } } @@ -900,11 +938,12 @@ void GEO_Internals::setTransfiniteSurface(int tag, int arrangement, _changed = true; } -void GEO_Internals::setTransfiniteVolume(int tag, const std::vector<int> &cornerTags) +void GEO_Internals::setTransfiniteVolume(int tag, + const std::vector<int> &cornerTags) { - if(!tag){ + if(!tag) { List_T *tmp = Tree2List(Volumes); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Volume *v; List_Read(tmp, i, &v); v->Method = MESH_TRANSFINITE; @@ -912,13 +951,14 @@ void GEO_Internals::setTransfiniteVolume(int tag, const std::vector<int> &corner } List_Delete(tmp); } - else{ + else { Volume *v = FindVolume(tag); - if(v){ + if(v) { v->Method = MESH_TRANSFINITE; List_Reset(v->TrsfPoints); - if(cornerTags.empty() || cornerTags.size() == 6 || cornerTags.size() == 8){ - for(unsigned int i = 0; i < cornerTags.size(); i++){ + if(cornerTags.empty() || cornerTags.size() == 6 || + cornerTags.size() == 8) { + for(unsigned int i = 0; i < cornerTags.size(); i++) { Vertex *vert = FindPoint(std::abs(cornerTags[i])); if(vert) List_Add(v->TrsfPoints, &vert); @@ -933,29 +973,28 @@ void GEO_Internals::setTransfiniteVolume(int tag, const std::vector<int> &corner void GEO_Internals::setTransfiniteVolumeQuadTri(int tag) { - if(!tag){ + if(!tag) { List_T *tmp = Tree2List(Volumes); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Volume *v; List_Read(tmp, i, &v); v->QuadTri = TRANSFINITE_QUADTRI_1; } List_Delete(tmp); } - else{ + else { Volume *v = FindVolume(tag); - if(v) - v->QuadTri = TRANSFINITE_QUADTRI_1; + if(v) v->QuadTri = TRANSFINITE_QUADTRI_1; } _changed = true; } void GEO_Internals::setRecombine(int dim, int tag, double angle) { - if(dim == 2){ - if(!tag){ + if(dim == 2) { + if(!tag) { List_T *tmp = Tree2List(Surfaces); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Surface *s; List_Read(tmp, i, &s); s->Recombine = 1; @@ -963,27 +1002,27 @@ void GEO_Internals::setRecombine(int dim, int tag, double angle) } List_Delete(tmp); } - else{ + else { Surface *s = FindSurface(tag); - if(s){ + if(s) { s->Recombine = 1; s->RecombineAngle = angle; } } } - else if(dim == 3){ - if(!tag){ + else if(dim == 3) { + if(!tag) { List_T *tmp = Tree2List(Volumes); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Volume *v; List_Read(tmp, i, &v); v->Recombine3D = 1; } List_Delete(tmp); } - else{ + else { Volume *v = FindVolume(tag); - if(v){ + if(v) { v->Recombine3D = 1; } } @@ -993,16 +1032,16 @@ void GEO_Internals::setRecombine(int dim, int tag, double angle) void GEO_Internals::setSmoothing(int tag, int val) { - if(!tag){ + if(!tag) { List_T *tmp = Tree2List(Surfaces); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Surface *s; List_Read(tmp, i, &s); s->TransfiniteSmoothing = val; } List_Delete(tmp); } - else{ + else { Surface *s = FindSurface(tag); if(s) s->TransfiniteSmoothing = val; } @@ -1011,32 +1050,32 @@ void GEO_Internals::setSmoothing(int tag, int val) void GEO_Internals::setReverseMesh(int dim, int tag, bool val) { - if(dim == 1){ - if(!tag){ + if(dim == 1) { + if(!tag) { List_T *tmp = Tree2List(Curves); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Curve *c; List_Read(tmp, i, &c); c->ReverseMesh = val ? 1 : 0; } List_Delete(tmp); } - else{ + else { Curve *c = FindCurve(tag); if(c) c->ReverseMesh = val ? 1 : 0; } } - else if(dim == 2){ - if(!tag){ + else if(dim == 2) { + if(!tag) { List_T *tmp = Tree2List(Surfaces); - for(int i = 0; i < List_Nbr(tmp); i++){ + for(int i = 0; i < List_Nbr(tmp); i++) { Surface *s; List_Read(tmp, i, &s); s->ReverseMesh = val ? 1 : 0; } List_Delete(tmp); } - else{ + else { Surface *s = FindSurface(tag); if(s) s->ReverseMesh = val ? 1 : 0; } @@ -1056,30 +1095,32 @@ void GEO_Internals::synchronize(GModel *model) // keeping the same tag), due e.g. to ReplaceDuplicates. std::vector<std::pair<int, int> > toRemove; - for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); ++it){ + for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); + ++it) { GVertex *gv = *it; - if(gv->getNativeType() == GEntity::GmshModel){ + if(gv->getNativeType() == GEntity::GmshModel) { if(!FindPoint(gv->tag())) toRemove.push_back(std::pair<int, int>(0, gv->tag())); } } - for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it){ + for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it) { GEdge *ge = *it; - if(ge->getNativeType() == GEntity::GmshModel){ + if(ge->getNativeType() == GEntity::GmshModel) { if(!FindCurve(ge->tag())) toRemove.push_back(std::pair<int, int>(1, ge->tag())); } } - for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it){ + for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it) { GFace *gf = *it; - if(gf->getNativeType() == GEntity::GmshModel){ + if(gf->getNativeType() == GEntity::GmshModel) { if(!FindSurface(gf->tag())) toRemove.push_back(std::pair<int, int>(2, gf->tag())); } } - for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); ++it){ + for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); + ++it) { GRegion *gr = *it; - if(gr->getNativeType() == GEntity::GmshModel){ + if(gr->getNativeType() == GEntity::GmshModel) { if(!FindVolume(gr->tag())) toRemove.push_back(std::pair<int, int>(3, gr->tag())); } @@ -1089,17 +1130,17 @@ void GEO_Internals::synchronize(GModel *model) if(Tree_Nbr(Points)) { List_T *points = Tree2List(Points); - for(int i = 0; i < List_Nbr(points); i++){ + for(int i = 0; i < List_Nbr(points); i++) { Vertex *p; List_Read(points, i, &p); GVertex *v = model->getVertexByTag(p->Num); - if(!v){ + if(!v) { v = new gmshVertex(model, p); model->add(v); } - else{ + else { if(v->getNativeType() == GEntity::GmshModel) - ((gmshVertex*)v)->resetNativePtr(p); + ((gmshVertex *)v)->resetNativePtr(p); v->resetMeshAttributes(); } } @@ -1109,27 +1150,28 @@ void GEO_Internals::synchronize(GModel *model) if(Tree_Nbr(Curves)) { List_T *curves = Tree2List(Curves); // generate all curves except compounds - for(int i = 0; i < List_Nbr(curves); i++){ + for(int i = 0; i < List_Nbr(curves); i++) { Curve *c; List_Read(curves, i, &c); - if(c->Num >= 0){ + if(c->Num >= 0) { GEdge *e = model->getEdgeByTag(c->Num); - if(!e && c->beg && c->end){ + if(!e && c->beg && c->end) { e = new gmshEdge(model, c, model->getVertexByTag(c->beg->Num), model->getVertexByTag(c->end->Num)); model->add(e); } - else if(!e){ + else if(!e) { e = new gmshEdge(model, c, 0, 0); model->add(e); } - else{ - if(e->getNativeType() == GEntity::GmshModel){ + else { + if(e->getNativeType() == GEntity::GmshModel) { if(c->beg && c->end) - ((gmshEdge*)e)->resetNativePtr(c, model->getVertexByTag(c->beg->Num), - model->getVertexByTag(c->end->Num)); + ((gmshEdge *)e) + ->resetNativePtr(c, model->getVertexByTag(c->beg->Num), + model->getVertexByTag(c->end->Num)); else - ((gmshEdge*)e)->resetNativePtr(c, 0, 0); + ((gmshEdge *)e)->resetNativePtr(c, 0, 0); } e->resetMeshAttributes(); } @@ -1141,17 +1183,17 @@ void GEO_Internals::synchronize(GModel *model) if(Tree_Nbr(Surfaces)) { List_T *surfaces = Tree2List(Surfaces); - for(int i = 0; i < List_Nbr(surfaces); i++){ + for(int i = 0; i < List_Nbr(surfaces); i++) { Surface *s; List_Read(surfaces, i, &s); GFace *f = model->getFaceByTag(s->Num); - if(!f){ + if(!f) { f = new gmshFace(model, s); model->add(f); } - else{ + else { if(f->getNativeType() == GEntity::GmshModel) - ((gmshFace*)f)->resetNativePtr(s); + ((gmshFace *)f)->resetNativePtr(s); f->resetMeshAttributes(); } } @@ -1160,17 +1202,17 @@ void GEO_Internals::synchronize(GModel *model) if(Tree_Nbr(Volumes)) { List_T *volumes = Tree2List(Volumes); - for(int i = 0; i < List_Nbr(volumes); i++){ + for(int i = 0; i < List_Nbr(volumes); i++) { Volume *v; List_Read(volumes, i, &v); GRegion *r = model->getRegionByTag(v->Num); - if(!r){ + if(!r) { r = new gmshRegion(model, v); model->add(r); } - else{ + else { if(r->getNativeType() == GEntity::GmshModel) - ((gmshRegion*)r)->resetNativePtr(v); + ((gmshRegion *)r)->resetNativePtr(v); r->resetMeshAttributes(); } } @@ -1181,26 +1223,27 @@ void GEO_Internals::synchronize(GModel *model) // for now. Note that we only sync physicals if there are some to sync, in // order not to destroy groups that would have been stored directly in a // GModel, e.g. by reading a mesh file - if(List_Nbr(PhysicalGroups)){ + if(List_Nbr(PhysicalGroups)) { model->removePhysicalGroups(); - for(int i = 0; i < List_Nbr(PhysicalGroups); i++){ + for(int i = 0; i < List_Nbr(PhysicalGroups); i++) { PhysicalGroup *p; List_Read(PhysicalGroups, i, &p); - for(int j = 0; j < List_Nbr(p->Entities); j++){ + for(int j = 0; j < List_Nbr(p->Entities); j++) { int num; List_Read(p->Entities, j, &num); GEntity *ge = 0; int tag = CTX::instance()->geom.orientedPhysicals ? abs(num) : num; - switch(p->Typ){ - case MSH_PHYSICAL_POINT: ge = model->getVertexByTag(tag); break; - case MSH_PHYSICAL_LINE: ge = model->getEdgeByTag(tag); break; + switch(p->Typ) { + case MSH_PHYSICAL_POINT: ge = model->getVertexByTag(tag); break; + case MSH_PHYSICAL_LINE: ge = model->getEdgeByTag(tag); break; case MSH_PHYSICAL_SURFACE: ge = model->getFaceByTag(tag); break; - case MSH_PHYSICAL_VOLUME: ge = model->getRegionByTag(tag); break; + case MSH_PHYSICAL_VOLUME: ge = model->getRegionByTag(tag); break; } int pnum = CTX::instance()->geom.orientedPhysicals ? - (gmsh_sign(num) * p->Num) : p->Num; + (gmsh_sign(num) * p->Num) : + p->Num; if(ge && std::find(ge->physicals.begin(), ge->physicals.end(), pnum) == - ge->physicals.end()) + ge->physicals.end()) ge->physicals.push_back(pnum); } } @@ -1208,23 +1251,24 @@ void GEO_Internals::synchronize(GModel *model) // we might want to store mesh compounds directly in GModel; but this is OK // for now. - for(std::multimap<int, std::vector<int> >::iterator it = _meshCompounds.begin(); - it != _meshCompounds.end(); ++it){ + for(std::multimap<int, std::vector<int> >::iterator it = + _meshCompounds.begin(); + it != _meshCompounds.end(); ++it) { int dim = it->first; std::vector<int> compound = it->second; - std::vector<GEntity*> ents; - for (unsigned int i = 0; i < compound.size(); i++){ + std::vector<GEntity *> ents; + for(unsigned int i = 0; i < compound.size(); i++) { int tag = compound[i]; GEntity *ent = NULL; switch(dim) { case 1: ent = model->getEdgeByTag(tag); break; case 2: ent = model->getFaceByTag(tag); break; case 3: ent = model->getRegionByTag(tag); break; - default : Msg::Error("compound mesh with dimension %d",dim); + default: Msg::Error("compound mesh with dimension %d", dim); } if(ent) ents.push_back(ent); } - for (unsigned int i=0;i<ents.size();i++){ + for(unsigned int i = 0; i < ents.size(); i++) { ents[i]->_compound = ents; } } @@ -1244,7 +1288,7 @@ void GEO_Internals::synchronize(GModel *model) bool GEO_Internals::getVertex(int tag, double &x, double &y, double &z) { Vertex *v = FindPoint(tag); - if(v){ + if(v) { x = v->Pos.X; y = v->Pos.Y; z = v->Pos.Z; @@ -1253,50 +1297,49 @@ bool GEO_Internals::getVertex(int tag, double &x, double &y, double &z) return false; } -gmshSurface *GEO_Internals::newGeometrySphere(int tag, int centerTag, int pointTag) +gmshSurface *GEO_Internals::newGeometrySphere(int tag, int centerTag, + int pointTag) { Vertex *v1 = FindPoint(centerTag); - if(!v1){ + if(!v1) { Msg::Error("Unknown sphere center point %d", centerTag); return 0; } Vertex *v2 = FindPoint(pointTag); - if(!v2){ + if(!v2) { Msg::Error("Unknown sphere point %d", pointTag); return 0; } - return gmshSphere::NewSphere - (tag, v1->Pos.X, v1->Pos.Y, v1->Pos.Z, - sqrt((v2->Pos.X - v1->Pos.X) * (v2->Pos.X - v1->Pos.X) + - (v2->Pos.Y - v1->Pos.Y) * (v2->Pos.Y - v1->Pos.Y) + - (v2->Pos.Z - v1->Pos.Z) * (v2->Pos.Z - v1->Pos.Z))); + return gmshSphere::NewSphere( + tag, v1->Pos.X, v1->Pos.Y, v1->Pos.Z, + sqrt((v2->Pos.X - v1->Pos.X) * (v2->Pos.X - v1->Pos.X) + + (v2->Pos.Y - v1->Pos.Y) * (v2->Pos.Y - v1->Pos.Y) + + (v2->Pos.Z - v1->Pos.Z) * (v2->Pos.Z - v1->Pos.Z))); } -gmshSurface *GEO_Internals::newGeometryPolarSphere(int tag, int centerTag, int pointTag) +gmshSurface *GEO_Internals::newGeometryPolarSphere(int tag, int centerTag, + int pointTag) { Vertex *v1 = FindPoint(centerTag); - if(!v1){ + if(!v1) { Msg::Error("Unknown polar sphere center point %d", centerTag); return 0; } Vertex *v2 = FindPoint(pointTag); - if(!v2){ + if(!v2) { Msg::Error("Unknown polar sphere point %d", pointTag); return 0; } - return gmshPolarSphere::NewPolarSphere - (tag, v1->Pos.X, v1->Pos.Y, v1->Pos.Z, - sqrt((v2->Pos.X - v1->Pos.X) * (v2->Pos.X - v1->Pos.X) + - (v2->Pos.Y - v1->Pos.Y) * (v2->Pos.Y - v1->Pos.Y) + - (v2->Pos.Z - v1->Pos.Z) * (v2->Pos.Z - v1->Pos.Z))); + return gmshPolarSphere::NewPolarSphere( + tag, v1->Pos.X, v1->Pos.Y, v1->Pos.Z, + sqrt((v2->Pos.X - v1->Pos.X) * (v2->Pos.X - v1->Pos.X) + + (v2->Pos.Y - v1->Pos.Y) * (v2->Pos.Y - v1->Pos.Y) + + (v2->Pos.Z - v1->Pos.Z) * (v2->Pos.Z - v1->Pos.Z))); } // GModel interface -void GModel::_createGEOInternals() -{ - _geo_internals = new GEO_Internals; -} +void GModel::_createGEOInternals() { _geo_internals = new GEO_Internals; } void GModel::_deleteGEOInternals() { @@ -1307,85 +1350,89 @@ void GModel::_deleteGEOInternals() #if defined(HAVE_MESH) class writeFieldOptionGEO { - private : +private: FILE *geo; Field *field; - public : + +public: writeFieldOptionGEO(FILE *fp, Field *_field) { geo = fp ? fp : stdout; field = _field; } - void operator() (std::pair<std::string, FieldOption *> it) + void operator()(std::pair<std::string, FieldOption *> it) { std::string v; it.second->getTextRepresentation(v); - fprintf(geo, "Field[%i].%s = %s;\n", field->id, it.first.c_str(), v.c_str()); + fprintf(geo, "Field[%i].%s = %s;\n", field->id, it.first.c_str(), + v.c_str()); } }; class writeFieldGEO { - private : - FILE *geo; - public : - writeFieldGEO(FILE *fp) { geo = fp ? fp : stdout; } - void operator() (std::pair<const int, Field *> it) - { - fprintf(geo, "Field[%i] = %s;\n", it.first, it.second->getName()); - std::for_each(it.second->options.begin(), it.second->options.end(), - writeFieldOptionGEO(geo, it.second)); - } +private: + FILE *geo; + +public: + writeFieldGEO(FILE *fp) { geo = fp ? fp : stdout; } + void operator()(std::pair<const int, Field *> it) + { + fprintf(geo, "Field[%i] = %s;\n", it.first, it.second->getName()); + std::for_each(it.second->options.begin(), it.second->options.end(), + writeFieldOptionGEO(geo, it.second)); + } }; #endif class writePhysicalGroupGEO { - private : - FILE *geo; - int dim; - bool printLabels; - std::map<int, std::string> &oldLabels; - std::map<std::pair<int, int>, std::string> &newLabels; - public : - writePhysicalGroupGEO(FILE *fp, int i, bool labels, - std::map<int, std::string> &o, - std::map<std::pair<int, int>, std::string> &n) - : dim(i), printLabels(labels), oldLabels(o), newLabels(n) - { - geo = fp ? fp : stdout; - } - void operator () (std::pair<const int, std::vector<GEntity *> > &g) - { - std::string oldName, newName; - if(printLabels){ - if(newLabels.count(std::pair<int, int>(dim, g.first))) { - newName = newLabels[std::pair<int, int>(dim, g.first)]; - } - else if(oldLabels.count(g.first)) { - oldName = oldLabels[g.first]; - fprintf(geo, "%s = %d;\n", oldName.c_str(), g.first); - } +private: + FILE *geo; + int dim; + bool printLabels; + std::map<int, std::string> &oldLabels; + std::map<std::pair<int, int>, std::string> &newLabels; + +public: + writePhysicalGroupGEO(FILE *fp, int i, bool labels, + std::map<int, std::string> &o, + std::map<std::pair<int, int>, std::string> &n) + : dim(i), printLabels(labels), oldLabels(o), newLabels(n) + { + geo = fp ? fp : stdout; + } + void operator()(std::pair<const int, std::vector<GEntity *> > &g) + { + std::string oldName, newName; + if(printLabels) { + if(newLabels.count(std::pair<int, int>(dim, g.first))) { + newName = newLabels[std::pair<int, int>(dim, g.first)]; } - - switch (dim) { - case 0: fprintf(geo, "Physical Point"); break; - case 1: fprintf(geo, "Physical Line"); break; - case 2: fprintf(geo, "Physical Surface"); break; - case 3: fprintf(geo, "Physical Volume"); break; + else if(oldLabels.count(g.first)) { + oldName = oldLabels[g.first]; + fprintf(geo, "%s = %d;\n", oldName.c_str(), g.first); } + } - if(oldName.size()) - fprintf(geo, "(%s) = {", oldName.c_str()); - else if(newName.size()) - fprintf(geo, "(\"%s\") = {", newName.c_str()); - else - fprintf(geo, "(%d) = {", g.first); - for(unsigned int i = 0; i < g.second.size(); i++) { - if(i) fprintf(geo, ", "); - fprintf(geo, "%d", g.second[i]->tag()); - } - fprintf(geo, "};\n"); + switch(dim) { + case 0: fprintf(geo, "Physical Point"); break; + case 1: fprintf(geo, "Physical Line"); break; + case 2: fprintf(geo, "Physical Surface"); break; + case 3: fprintf(geo, "Physical Volume"); break; } + + if(oldName.size()) + fprintf(geo, "(%s) = {", oldName.c_str()); + else if(newName.size()) + fprintf(geo, "(\"%s\") = {", newName.c_str()); + else + fprintf(geo, "(%d) = {", g.first); + for(unsigned int i = 0; i < g.second.size(); i++) { + if(i) fprintf(geo, ", "); + fprintf(geo, "%d", g.second[i]->tag()); + } + fprintf(geo, "};\n"); + } }; static bool skipRegion(GRegion *gr) @@ -1397,8 +1444,9 @@ static bool skipRegion(GRegion *gr) static bool skipFace(GFace *gf) { if(gf->physicals.size()) return false; - std::list<GRegion*> regions(gf->regions()); - for(std::list<GRegion*>::iterator itr = regions.begin(); itr != regions.end(); itr++){ + std::list<GRegion *> regions(gf->regions()); + for(std::list<GRegion *>::iterator itr = regions.begin(); + itr != regions.end(); itr++) { if(!skipRegion(*itr)) return false; } return true; @@ -1407,8 +1455,9 @@ static bool skipFace(GFace *gf) static bool skipEdge(GEdge *ge) { if(ge->physicals.size()) return false; - std::vector<GFace*> faces(ge->faces()); - for(std::vector<GFace*>::iterator itf = faces.begin(); itf != faces.end(); itf++){ + std::vector<GFace *> faces(ge->faces()); + for(std::vector<GFace *>::iterator itf = faces.begin(); itf != faces.end(); + itf++) { if(!skipFace(*itf)) return false; } return true; @@ -1417,26 +1466,28 @@ static bool skipEdge(GEdge *ge) static bool skipVertex(GVertex *gv) { if(gv->physicals.size()) return false; - std::vector<GEdge*> const& edges = gv->edges(); - for(std::vector<GEdge*>::const_iterator ite = edges.begin(); ite != edges.end(); ite++){ + std::vector<GEdge *> const &edges = gv->edges(); + for(std::vector<GEdge *>::const_iterator ite = edges.begin(); + ite != edges.end(); ite++) { if(!skipEdge(*ite)) return false; } return true; } -int GModel::writeGEO(const std::string &name, bool printLabels, bool onlyPhysicals) +int GModel::writeGEO(const std::string &name, bool printLabels, + bool onlyPhysicals) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Could not open file '%s'", name.c_str()); return 0; } std::map<double, std::string> meshSizeParameters; int cpt = 0; - for(viter it = firstVertex(); it != lastVertex(); it++){ + for(viter it = firstVertex(); it != lastVertex(); it++) { double val = (*it)->prescribedMeshSizeAtVertex(); - if(meshSizeParameters.find(val) == meshSizeParameters.end()){ + if(meshSizeParameters.find(val) == meshSizeParameters.end()) { std::ostringstream paramName; paramName << "cl__" << ++cpt; fprintf(fp, "%s = %.16g;\n", paramName.str().c_str(), val); @@ -1444,38 +1495,37 @@ int GModel::writeGEO(const std::string &name, bool printLabels, bool onlyPhysica } } - for(viter it = firstVertex(); it != lastVertex(); it++){ + for(viter it = firstVertex(); it != lastVertex(); it++) { double val = (*it)->prescribedMeshSizeAtVertex(); if(!onlyPhysicals || !skipVertex(*it)) (*it)->writeGEO(fp, meshSizeParameters[val]); } - for(eiter it = firstEdge(); it != lastEdge(); it++){ - if(!onlyPhysicals || !skipEdge(*it)) - (*it)->writeGEO(fp); + for(eiter it = firstEdge(); it != lastEdge(); it++) { + if(!onlyPhysicals || !skipEdge(*it)) (*it)->writeGEO(fp); } - for(fiter it = firstFace(); it != lastFace(); it++){ - if(!onlyPhysicals || !skipFace(*it)) - (*it)->writeGEO(fp); + for(fiter it = firstFace(); it != lastFace(); it++) { + if(!onlyPhysicals || !skipFace(*it)) (*it)->writeGEO(fp); } - for(riter it = firstRegion(); it != lastRegion(); it++){ - if(!onlyPhysicals || !skipRegion(*it)) - (*it)->writeGEO(fp); + for(riter it = firstRegion(); it != lastRegion(); it++) { + if(!onlyPhysicals || !skipRegion(*it)) (*it)->writeGEO(fp); } std::map<int, std::string> labels; #if defined(HAVE_PARSER) // get "old-style" labels from parser - for(std::map<std::string, gmsh_yysymbol>::iterator it = gmsh_yysymbols.begin(); + for(std::map<std::string, gmsh_yysymbol>::iterator it = + gmsh_yysymbols.begin(); it != gmsh_yysymbols.end(); ++it) for(unsigned int i = 0; i < it->second.value.size(); i++) labels[(int)it->second.value[i]] = it->first; #endif - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; getPhysicalGroups(groups); for(int i = 0; i < 4; i++) - std::for_each(groups[i].begin(), groups[i].end(), - writePhysicalGroupGEO(fp, i, printLabels, labels, physicalNames)); + std::for_each( + groups[i].begin(), groups[i].end(), + writePhysicalGroupGEO(fp, i, printLabels, labels, physicalNames)); #if defined(HAVE_MESH) std::for_each(getFields()->begin(), getFields()->end(), writeFieldGEO(fp)); @@ -1491,35 +1541,35 @@ int GModel::exportDiscreteGEOInternals() { int maxv = 1; // FIXME: temorary - see TODO below - if(_geo_internals){ + if(_geo_internals) { maxv = _geo_internals->getMaxTag(3); delete _geo_internals; } _geo_internals = new GEO_Internals; - for(viter it = firstVertex(); it != lastVertex(); it++){ + for(viter it = firstVertex(); it != lastVertex(); it++) { Vertex *v = CreateVertex((*it)->tag(), (*it)->x(), (*it)->y(), (*it)->z(), - (*it)->prescribedMeshSizeAtVertex(), 1.0); + (*it)->prescribedMeshSizeAtVertex(), 1.0); Tree_Add(_geo_internals->Points, &v); } - for(eiter it = firstEdge(); it != lastEdge(); it++){ - if((*it)->geomType() == GEntity::DiscreteCurve){ - Curve *c = CreateCurve((*it)->tag(), MSH_SEGM_DISCRETE, 1, - NULL, NULL, -1, -1, 0., 1.); + for(eiter it = firstEdge(); it != lastEdge(); it++) { + if((*it)->geomType() == GEntity::DiscreteCurve) { + Curve *c = CreateCurve((*it)->tag(), MSH_SEGM_DISCRETE, 1, NULL, NULL, -1, + -1, 0., 1.); List_T *points = Tree2List(_geo_internals->Points); GVertex *gvb = (*it)->getBeginVertex(); GVertex *gve = (*it)->getEndVertex(); - int nb = 2 ; + int nb = 2; c->Control_Points = List_Create(nb, 1, sizeof(Vertex *)); for(int i = 0; i < List_Nbr(points); i++) { Vertex *v; List_Read(points, i, &v); - if (v->Num == gvb->tag()) { + if(v->Num == gvb->tag()) { List_Add(c->Control_Points, &v); c->beg = v; } - if (v->Num == gve->tag()) { + if(v->Num == gve->tag()) { List_Add(c->Control_Points, &v); c->end = v; } @@ -1531,17 +1581,18 @@ int GModel::exportDiscreteGEOInternals() } } - for(fiter it = firstFace(); it != lastFace(); it++){ - if((*it)->geomType() == GEntity::DiscreteSurface){ + for(fiter it = firstFace(); it != lastFace(); it++) { + if((*it)->geomType() == GEntity::DiscreteSurface) { Surface *s = CreateSurface((*it)->tag(), MSH_SURF_DISCRETE); - std::vector<GEdge*> const& edges = (*it)->edges(); + std::vector<GEdge *> const &edges = (*it)->edges(); s->Generatrices = List_Create(edges.size(), 1, sizeof(Curve *)); List_T *curves = Tree2List(_geo_internals->Curves); Curve *c; - for(std::vector<GEdge*>::const_iterator ite = edges.begin(); ite != edges.end(); ite++){ + for(std::vector<GEdge *>::const_iterator ite = edges.begin(); + ite != edges.end(); ite++) { for(int i = 0; i < List_Nbr(curves); i++) { List_Read(curves, i, &c); - if (c->Num == (*ite)->tag()) { + if(c->Num == (*ite)->tag()) { List_Add(s->Generatrices, &c); } } diff --git a/Geo/GModelIO_GEO.h b/Geo/GModelIO_GEO.h index 75632d4e4aeabd103e0001c8814fa7244e3c6266..1bb240a14dfcc780078b86fda8df12e616fab0e3 100644 --- a/Geo/GModelIO_GEO.h +++ b/Geo/GModelIO_GEO.h @@ -12,13 +12,14 @@ class gmshSurface; class List_T; class Tree_T; -class GEO_Internals{ - public: +class GEO_Internals { +public: // this will become private Tree_T *Points, *Curves, *EdgeLoops, *Surfaces, *SurfaceLoops, *Volumes; Tree_T *DelPoints, *DelCurves, *DelSurfaces, *DelVolumes; List_T *PhysicalGroups, *DelPhysicalGroups; - private: + +private: std::multimap<int, std::vector<int> > _meshCompounds; int _maxPointNum, _maxLineNum, _maxLineLoopNum, _maxSurfaceNum; int _maxSurfaceLoopNum, _maxVolumeNum, _maxPhysicalNum; @@ -26,19 +27,22 @@ class GEO_Internals{ void _freeAll(); bool _changed; bool _transform(int mode, const std::vector<std::pair<int, int> > &dimTags, - double x, double y, double z, - double dx, double dy, double dz, + double x, double y, double z, double dx, double dy, double dz, double a, double b, double c, double d); bool _extrude(int mode, const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double dx, double dy, double dz, + double x, double y, double z, double dx, double dy, double dz, double ax, double ay, double az, double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e = 0); - public: - GEO_Internals(){ _allocateAll(); } - ~GEO_Internals(){ _freeAll(); } - void destroy(){ _freeAll(); _allocateAll(); } + +public: + GEO_Internals() { _allocateAll(); } + ~GEO_Internals() { _freeAll(); } + void destroy() + { + _freeAll(); + _allocateAll(); + } // have the internals changed since the last synchronisation? bool getChanged() const { return _changed; } @@ -56,7 +60,8 @@ class GEO_Internals{ bool addCircleArc(int &tag, int startTag, int centerTag, int endTag, double nx = 0., double ny = 0., double nz = 0.); bool addEllipseArc(int &tag, int startTag, int centerTag, int majorTag, - int endTag, double nx = 0., double ny = 0., double nz = 0.); + int endTag, double nx = 0., double ny = 0., + double nz = 0.); bool addSpline(int &tag, const std::vector<int> &pointTags); bool addBezier(int &tag, const std::vector<int> &pointTags); bool addBSpline(int &tag, const std::vector<int> &pointTags, @@ -70,19 +75,17 @@ class GEO_Internals{ bool addVolume(int &tag, const std::vector<int> &shellTags); // extrude and revolve - bool extrude(const std::vector<std::pair<int, int> > &inDimTags, - double dx, double dy, double dz, + bool extrude(const std::vector<std::pair<int, int> > &inDimTags, double dx, + double dy, double dz, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e = 0); - bool revolve(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double ax, double ay, double az, double angle, - std::vector<std::pair<int, int> > &outDimTags, + bool revolve(const std::vector<std::pair<int, int> > &inDimTags, double x, + double y, double z, double ax, double ay, double az, + double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e = 0); - bool twist(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double dx, double dy, double dz, - double ax, double ay, double az, double angle, + bool twist(const std::vector<std::pair<int, int> > &inDimTags, double x, + double y, double z, double dx, double dy, double dz, double ax, + double ay, double az, double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e = 0); bool boundaryLayer(const std::vector<std::pair<int, int> > &inDimTags, @@ -90,16 +93,15 @@ class GEO_Internals{ ExtrudeParams *e = 0); // apply transformations - bool translate(const std::vector<std::pair<int, int> > &dimTags, - double dx, double dy, double dz); - bool rotate(const std::vector<std::pair<int, int> > &dimTags, - double x, double y, double z, double ax, double ay, double az, + bool translate(const std::vector<std::pair<int, int> > &dimTags, double dx, + double dy, double dz); + bool rotate(const std::vector<std::pair<int, int> > &dimTags, double x, + double y, double z, double ax, double ay, double az, double angle); - bool dilate(const std::vector<std::pair<int, int> > &dimTags, - double x, double y, double z, - double a, double b, double c); - bool symmetry(const std::vector<std::pair<int, int> > &dimTags, - double a, double b, double c, double d); + bool dilate(const std::vector<std::pair<int, int> > &dimTags, double x, + double y, double z, double a, double b, double c); + bool symmetry(const std::vector<std::pair<int, int> > &dimTags, double a, + double b, double c, double d); // split entities bool splitCurve(int tag, const std::vector<int> &pointTags, @@ -111,11 +113,13 @@ class GEO_Internals{ bool copy(const std::vector<std::pair<int, int> > &inDimTags, std::vector<std::pair<int, int> > &outDimTags); bool remove(int dim, int tag, bool recursive = false); - bool remove(const std::vector<std::pair<int, int> > &dimTags, bool recursive = false); + bool remove(const std::vector<std::pair<int, int> > &dimTags, + bool recursive = false); // manipulate physical groups void resetPhysicalGroups(); - bool modifyPhysicalGroup(int dim, int tag, int op, const std::vector<int> &tags); + bool modifyPhysicalGroup(int dim, int tag, int op, + const std::vector<int> &tags); int getMaxPhysicalTag() const { return _maxPhysicalNum; } void setMaxPhysicalTag(int val) { _maxPhysicalNum = val; } diff --git a/Geo/GModelIO_GEOM.cpp b/Geo/GModelIO_GEOM.cpp index c9366b8e8f680dba3a6372592b5774843db6a70a..b0df3541de010874db00779552faa2a4eb3a1c81 100644 --- a/Geo/GModelIO_GEOM.cpp +++ b/Geo/GModelIO_GEOM.cpp @@ -7,11 +7,11 @@ #include "OS.h" #include "MTriangle.h" -static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, - std::vector<MVertex*> &vertices) +static bool getMeshVertices(int num, int *indices, std::vector<MVertex *> &vec, + std::vector<MVertex *> &vertices) { - for(int i = 0; i < num; i++){ - if(indices[i] < 0 || indices[i] > (int)(vec.size() - 1)){ + for(int i = 0; i < num; i++) { + if(indices[i] < 0 || indices[i] > (int)(vec.size() - 1)) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -26,18 +26,18 @@ int GModel::readGEOM(const std::string &name) // this is a format (from geomview?) that Bruno Levy's Graphite code // can write FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } int numNodes, numElements, dummy; - if(fscanf(fp, "%d %d %d", &numNodes, &numElements, &dummy) != 3){ + if(fscanf(fp, "%d %d %d", &numNodes, &numElements, &dummy) != 3) { fclose(fp); return 0; } - if(!numNodes || !numElements){ + if(!numNodes || !numElements) { Msg::Warning("No vertices or elements found"); fclose(fp); return 0; @@ -45,8 +45,8 @@ int GModel::readGEOM(const std::string &name) Msg::Info("%d vertices, %d elements", numNodes, numElements); - std::vector<MVertex*> vertexVector; - std::map<int, std::vector<MElement*> > elements[1]; + std::vector<MVertex *> vertexVector; + std::map<int, std::vector<MElement *> > elements[1]; vertexVector.resize(numNodes); for(int i = 0; i < numNodes; i++) { @@ -58,19 +58,15 @@ int GModel::readGEOM(const std::string &name) for(int i = 0; i < numElements; i++) { int N, n[3]; if(fscanf(fp, "%d", &N) != 1) break; - switch(N){ - case 3: - { - if(fscanf(fp, "%d %d %d", &n[0], &n[1], &n[2]) != 3) break; - for(int i = 0; i < 3; i++) n[i]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(3, n, vertexVector, vertices)) break; - elements[0][1].push_back(new MTriangle(vertices)); - } - break; - default: - Msg::Error("Unknown element type in .geom reader"); - break; + switch(N) { + case 3: { + if(fscanf(fp, "%d %d %d", &n[0], &n[1], &n[2]) != 3) break; + for(int i = 0; i < 3; i++) n[i]--; + std::vector<MVertex *> vertices; + if(!getMeshVertices(3, n, vertexVector, vertices)) break; + elements[0][1].push_back(new MTriangle(vertices)); + } break; + default: Msg::Error("Unknown element type in .geom reader"); break; } } diff --git a/Geo/GModelIO_INP.cpp b/Geo/GModelIO_INP.cpp index 40474a6de7b438f571f6192f7f9b1d56c1c1b882..c31f1dff4d539bedd6356b47c27d69ae427c1ace 100644 --- a/Geo/GModelIO_INP.cpp +++ b/Geo/GModelIO_INP.cpp @@ -15,14 +15,16 @@ #include "MPyramid.h" template <class T> -static void writeElementsINP(FILE *fp, GEntity *ge, std::vector<T*> &elements, +static void writeElementsINP(FILE *fp, GEntity *ge, std::vector<T *> &elements, bool saveAll) { - if(elements.size() && (saveAll || ge->physicals.size())){ + if(elements.size() && (saveAll || ge->physicals.size())) { const char *typ = elements[0]->getStringForINP(); - if(typ){ - const char *str = (ge->dim() == 3) ? "Volume" : (ge->dim() == 2) ? - "Surface" : (ge->dim() == 1) ? "Line" : "Point"; + if(typ) { + const char *str = + (ge->dim() == 3) ? + "Volume" : + (ge->dim() == 2) ? "Surface" : (ge->dim() == 1) ? "Line" : "Point"; fprintf(fp, "*ELEMENT, type=%s, ELSET=%s%d\n", typ, str, ge->tag()); for(unsigned int i = 0; i < elements.size(); i++) elements[i]->writeINP(fp, elements[i]->getNum()); @@ -33,10 +35,12 @@ static void writeElementsINP(FILE *fp, GEntity *ge, std::vector<T*> &elements, static std::string physicalName(GModel *m, int dim, int num) { std::string name = m->getPhysicalName(dim, num); - if(name.empty()){ + if(name.empty()) { char tmp[256]; - sprintf(tmp, "%s%d", (dim == 3) ? "PhysicalVolume" : - (dim == 2) ? "PhysicalSurface" : "PhysicalLine", num); + sprintf(tmp, "%s%d", + (dim == 3) ? "PhysicalVolume" : + (dim == 2) ? "PhysicalSurface" : "PhysicalLine", + num); name = tmp; } for(unsigned int i = 0; i < name.size(); i++) @@ -44,11 +48,11 @@ static std::string physicalName(GModel *m, int dim, int num) return name; } -int GModel::writeINP(const std::string &name, bool saveAll, bool saveGroupsOfNodes, - double scalingFactor) +int GModel::writeINP(const std::string &name, bool saveAll, + bool saveGroupsOfNodes, double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -56,7 +60,7 @@ int GModel::writeINP(const std::string &name, bool saveAll, bool saveGroupsOfNod if(noPhysicalGroups()) saveAll = true; indexMeshVertices(saveAll); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); fprintf(fp, "*Heading\n"); @@ -68,35 +72,37 @@ int GModel::writeINP(const std::string &name, bool saveAll, bool saveGroupsOfNod entities[i]->mesh_vertices[j]->writeINP(fp, scalingFactor); fprintf(fp, "******* E L E M E N T S *************\n"); - for(viter it = firstVertex(); it != lastVertex(); ++it){ + for(viter it = firstVertex(); it != lastVertex(); ++it) { writeElementsINP(fp, *it, (*it)->points, saveAll); } - for(eiter it = firstEdge(); it != lastEdge(); ++it){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { writeElementsINP(fp, *it, (*it)->lines, saveAll); } - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { writeElementsINP(fp, *it, (*it)->triangles, saveAll); writeElementsINP(fp, *it, (*it)->quadrangles, saveAll); } - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { writeElementsINP(fp, *it, (*it)->tetrahedra, saveAll); writeElementsINP(fp, *it, (*it)->hexahedra, saveAll); writeElementsINP(fp, *it, (*it)->prisms, saveAll); writeElementsINP(fp, *it, (*it)->pyramids, saveAll); } - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; getPhysicalGroups(groups); // save elements sets for each physical group - for(int dim = 0; dim <= 3; dim++){ - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); - it != groups[dim].end(); it++){ + for(int dim = 0; dim <= 3; dim++) { + for(std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].begin(); + it != groups[dim].end(); it++) { std::vector<GEntity *> &entities = it->second; - fprintf(fp, "*ELSET,ELSET=%s\n", physicalName(this, dim, it->first).c_str()); + fprintf(fp, "*ELSET,ELSET=%s\n", + physicalName(this, dim, it->first).c_str()); int n = 0; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); if(n && !(n % 10)) fprintf(fp, "\n"); fprintf(fp, "%d, ", e->getNum()); @@ -108,22 +114,25 @@ int GModel::writeINP(const std::string &name, bool saveAll, bool saveGroupsOfNod } // save node sets for each physical group - if(saveGroupsOfNodes){ - for(int dim = 1; dim <= 3; dim++){ - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); - it != groups[dim].end(); it++){ - std::set<MVertex*> nodes; + if(saveGroupsOfNodes) { + for(int dim = 1; dim <= 3; dim++) { + for(std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].begin(); + it != groups[dim].end(); it++) { + std::set<MVertex *> nodes; std::vector<GEntity *> &entities = it->second; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); - for (std::size_t k = 0; k < e->getNumVertices(); k++) + for(std::size_t k = 0; k < e->getNumVertices(); k++) nodes.insert(e->getVertex(k)); } } - fprintf(fp, "*NSET,NSET=%s\n", physicalName(this, dim, it->first).c_str()); + fprintf(fp, "*NSET,NSET=%s\n", + physicalName(this, dim, it->first).c_str()); int n = 0; - for(std::set<MVertex*>::iterator it2 = nodes.begin(); it2 != nodes.end(); it2++){ + for(std::set<MVertex *>::iterator it2 = nodes.begin(); + it2 != nodes.end(); it2++) { if(n && !(n % 10)) fprintf(fp, "\n"); fprintf(fp, "%d, ", (*it2)->getIndex()); n++; diff --git a/Geo/GModelIO_IR3.cpp b/Geo/GModelIO_IR3.cpp index 003eefc581ae6ed97eb9884dac1ce891da63e8f5..673ccfc6a27d40ccf193167b9063484e237cf349 100644 --- a/Geo/GModelIO_IR3.cpp +++ b/Geo/GModelIO_IR3.cpp @@ -7,11 +7,11 @@ #include "OS.h" #include "MElement.h" -int GModel::writeIR3(const std::string &name, int elementTagType, - bool saveAll, double scalingFactor) +int GModel::writeIR3(const std::string &name, int elementTagType, bool saveAll, + double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -20,50 +20,48 @@ int GModel::writeIR3(const std::string &name, int elementTagType, int numVertices = indexMeshVertices(saveAll), num2D = 0, num3D = 0; for(fiter it = firstFace(); it != lastFace(); ++it) - if(saveAll || (*it)->physicals.size()) - num2D += (*it)->getNumMeshElements(); + if(saveAll || (*it)->physicals.size()) num2D += (*it)->getNumMeshElements(); for(riter it = firstRegion(); it != lastRegion(); ++it) - if(saveAll || (*it)->physicals.size()) - num3D += (*it)->getNumMeshElements(); + if(saveAll || (*it)->physicals.size()) num3D += (*it)->getNumMeshElements(); - fprintf(fp,"33\n"); + fprintf(fp, "33\n"); if(num2D && num3D) - fprintf(fp,"%d %d %d\n", numVertices, num2D, num3D); + fprintf(fp, "%d %d %d\n", numVertices, num2D, num3D); else - fprintf(fp,"%d %d\n", numVertices, num2D ? num2D : num3D); + fprintf(fp, "%d %d\n", numVertices, num2D ? num2D : num3D); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) if(entities[i]->mesh_vertices[j]->getIndex() >= 0) - fprintf(fp,"%d %.16g %.16g %.16g\n", entities[i]->mesh_vertices[j]->getIndex(), + fprintf(fp, "%d %.16g %.16g %.16g\n", + entities[i]->mesh_vertices[j]->getIndex(), entities[i]->mesh_vertices[j]->x() * scalingFactor, entities[i]->mesh_vertices[j]->y() * scalingFactor, entities[i]->mesh_vertices[j]->z() * scalingFactor); int iElement = 1; - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { int numPhys = (*it)->physicals.size(); if(saveAll || numPhys) for(unsigned int i = 0; i < (*it)->getNumMeshElements(); i++) - (*it)->getMeshElement(i)->writeIR3 - (fp, elementTagType, iElement++, (*it)->tag(), - numPhys ? (*it)->physicals[0] : 0); + (*it)->getMeshElement(i)->writeIR3(fp, elementTagType, iElement++, + (*it)->tag(), + numPhys ? (*it)->physicals[0] : 0); } iElement = 1; - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { int numPhys = (*it)->physicals.size(); if(saveAll || numPhys) for(unsigned int i = 0; i < (*it)->getNumMeshElements(); i++) - (*it)->getMeshElement(i)->writeIR3 - (fp, elementTagType, iElement++, (*it)->tag(), - numPhys ? (*it)->physicals[0] : 0); + (*it)->getMeshElement(i)->writeIR3(fp, elementTagType, iElement++, + (*it)->tag(), + numPhys ? (*it)->physicals[0] : 0); } fclose(fp); return 1; } - diff --git a/Geo/GModelIO_KEY.cpp b/Geo/GModelIO_KEY.cpp index 5401536f76a494c18cab933046249fbb10e17f91..5ac38a88a8c5f759b19ac7869abffa8ade41cbe5 100644 --- a/Geo/GModelIO_KEY.cpp +++ b/Geo/GModelIO_KEY.cpp @@ -17,10 +17,12 @@ static std::string physicalName(GModel *m, int dim, int num) { std::string name = m->getPhysicalName(dim, num); - if(name.empty()){ + if(name.empty()) { char tmp[256]; - sprintf(tmp, "%s%d", (dim == 3) ? "PhysicalVolume" : - (dim == 2) ? "PhysicalSurface" : "PhysicalLine", num); + sprintf(tmp, "%s%d", + (dim == 3) ? "PhysicalVolume" : + (dim == 2) ? "PhysicalSurface" : "PhysicalLine", + num); name = tmp; } for(unsigned int i = 0; i < name.size(); i++) @@ -28,32 +30,30 @@ static std::string physicalName(GModel *m, int dim, int num) return name; } -static int partID(int dim, int num) -{ - return dim*1000000+num; -} +static int partID(int dim, int num) { return dim * 1000000 + num; } template <class T> -static void writeElementsKEY(FILE *fp, GEntity *ge, std::vector<T*> &elements, +static void writeElementsKEY(FILE *fp, GEntity *ge, std::vector<T *> &elements, bool saveAll) { - if(elements.size() && (saveAll || ge->physicals.size())){ + if(elements.size() && (saveAll || ge->physicals.size())) { const char *typ = elements[0]->getStringForKEY(); - int pid = partID(ge->dim(),ge->tag()); - if(typ){ - fprintf(fp, "*ELEMENT%s\n$#SET_ELEMENT=%s%d\n", typ, - physicalName(ge->model(), ge->dim(), ge->tag()).c_str(), ge->tag()); + int pid = partID(ge->dim(), ge->tag()); + if(typ) { + fprintf(fp, "*ELEMENT%s\n$#SET_ELEMENT=%s%d\n", typ, + physicalName(ge->model(), ge->dim(), ge->tag()).c_str(), + ge->tag()); for(unsigned int i = 0; i < elements.size(); i++) elements[i]->writeKEY(fp, pid, elements[i]->getNum()); } } } -int GModel::writeKEY(const std::string &name, int saveAll, int saveGroupsOfNodes, - double scalingFactor) +int GModel::writeKEY(const std::string &name, int saveAll, + int saveGroupsOfNodes, double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -61,7 +61,7 @@ int GModel::writeKEY(const std::string &name, int saveAll, int saveGroupsOfNodes if(noPhysicalGroups()) saveAll = 0x51; indexMeshVertices(saveAll & 0x51); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); fprintf(fp, "$# LS-DYNA Keyword file created by Gmsh\n*KEYWORD\n*TITLE\n"); @@ -73,47 +73,50 @@ int GModel::writeKEY(const std::string &name, int saveAll, int saveGroupsOfNodes entities[i]->mesh_vertices[j]->writeKEY(fp, scalingFactor); if(!(saveAll & 0x2)) /* save or ignore Vertex, not in GUI */ - for(viter it = firstVertex(); it != lastVertex(); ++it){ - writeElementsKEY(fp, *it, (*it)->points, saveAll & 0x1); - } + for(viter it = firstVertex(); it != lastVertex(); ++it) { + writeElementsKEY(fp, *it, (*it)->points, saveAll & 0x1); + } if(!(saveAll & 0x8)) /* save or ignore line */ - for(eiter it = firstEdge(); it != lastEdge(); ++it){ - writeElementsKEY(fp, *it, (*it)->lines, saveAll & 0x4); - } + for(eiter it = firstEdge(); it != lastEdge(); ++it) { + writeElementsKEY(fp, *it, (*it)->lines, saveAll & 0x4); + } if(!(saveAll & 0x20)) /* save or ignore surface */ - for(fiter it = firstFace(); it != lastFace(); ++it){ - writeElementsKEY(fp, *it, (*it)->triangles, saveAll & 0x10); - writeElementsKEY(fp, *it, (*it)->quadrangles, saveAll & 0x10); - } + for(fiter it = firstFace(); it != lastFace(); ++it) { + writeElementsKEY(fp, *it, (*it)->triangles, saveAll & 0x10); + writeElementsKEY(fp, *it, (*it)->quadrangles, saveAll & 0x10); + } if(!(saveAll & 0x80)) /* save or ignore surface */ - for(riter it = firstRegion(); it != lastRegion(); ++it){ - writeElementsKEY(fp, *it, (*it)->tetrahedra, saveAll & 0x40); - writeElementsKEY(fp, *it, (*it)->hexahedra, saveAll & 0x40); - writeElementsKEY(fp, *it, (*it)->prisms, saveAll & 0x40); - writeElementsKEY(fp, *it, (*it)->pyramids, saveAll & 0x40); - } + for(riter it = firstRegion(); it != lastRegion(); ++it) { + writeElementsKEY(fp, *it, (*it)->tetrahedra, saveAll & 0x40); + writeElementsKEY(fp, *it, (*it)->hexahedra, saveAll & 0x40); + writeElementsKEY(fp, *it, (*it)->prisms, saveAll & 0x40); + writeElementsKEY(fp, *it, (*it)->pyramids, saveAll & 0x40); + } - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; getPhysicalGroups(groups); - int setid=0; + int setid = 0; // save elements sets for each physical group - if(saveGroupsOfNodes & 0x2){ - for(int dim = 0; dim <= 3; dim++){ - if(saveAll & (0x2<<(2*dim))) continue; /* elements are ignored*/ - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); - it != groups[dim].end(); it++){ + if(saveGroupsOfNodes & 0x2) { + for(int dim = 0; dim <= 3; dim++) { + if(saveAll & (0x2 << (2 * dim))) continue; /* elements are ignored*/ + for(std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].begin(); + it != groups[dim].end(); it++) { std::vector<GEntity *> &entities = it->second; int n = 0; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); if(!n) { - const char *str = (e->getDim() == 3) ? "SOLID" : - (e->getDim() == 2) ? "SHELL" : - (e->getDim() == 1) ? "BEAM" : "NODE"; - fprintf(fp, "*SET_%s_LIST\n$# %s\n%d",str, - physicalName(this, dim, it->first).c_str(),++setid); + const char *str = (e->getDim() == 3) ? + "SOLID" : + (e->getDim() == 2) ? + "SHELL" : + (e->getDim() == 1) ? "BEAM" : "NODE"; + fprintf(fp, "*SET_%s_LIST\n$# %s\n%d", str, + physicalName(this, dim, it->first).c_str(), ++setid); } if(!(n % 8)) fprintf(fp, "\n%d", e->getNum()); @@ -122,35 +125,38 @@ int GModel::writeKEY(const std::string &name, int saveAll, int saveGroupsOfNodes n++; } } - if(n)fprintf(fp, "\n"); + if(n) fprintf(fp, "\n"); } } } // save node sets for each physical group, for easier load/b.c. - if(saveGroupsOfNodes & 0x1){ - for(int dim = 1; dim <= 3; dim++){ - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); - it != groups[dim].end(); it++){ - std::set<MVertex*> nodes; + if(saveGroupsOfNodes & 0x1) { + for(int dim = 1; dim <= 3; dim++) { + for(std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].begin(); + it != groups[dim].end(); it++) { + std::set<MVertex *> nodes; std::vector<GEntity *> &entities = it->second; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); - for (std::size_t k = 0; k < e->getNumVertices(); k++) + for(std::size_t k = 0; k < e->getNumVertices(); k++) nodes.insert(e->getVertex(k)); } } - fprintf(fp, "*SET_NODE_LIST\n$# %s\n%d", physicalName(this, dim, it->first).c_str(),++setid); + fprintf(fp, "*SET_NODE_LIST\n$# %s\n%d", + physicalName(this, dim, it->first).c_str(), ++setid); int n = 0; - for(std::set<MVertex*>::iterator it2 = nodes.begin(); it2 != nodes.end(); it2++){ + for(std::set<MVertex *>::iterator it2 = nodes.begin(); + it2 != nodes.end(); it2++) { if(!(n % 8)) fprintf(fp, "\n%d", (*it2)->getIndex()); else fprintf(fp, ", %d", (*it2)->getIndex()); n++; } - if(n)fprintf(fp, "\n"); + if(n) fprintf(fp, "\n"); } } } diff --git a/Geo/GModelIO_MAIL.cpp b/Geo/GModelIO_MAIL.cpp index ea968de27dff910e069ff2b3bff1268972058400..92a92ad4311de25273397a0ac701bce90896c81c 100644 --- a/Geo/GModelIO_MAIL.cpp +++ b/Geo/GModelIO_MAIL.cpp @@ -7,13 +7,14 @@ #include "OS.h" #include "MTriangle.h" -int GModel::writeMAIL(const std::string &name, bool saveAll, double scalingFactor) +int GModel::writeMAIL(const std::string &name, bool saveAll, + double scalingFactor) { // CEA triangulation (.mail format) for Eric Darrigrand. Note that // we currently don't save the edges of the triangulation (the last // part of the file). FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -27,19 +28,19 @@ int GModel::writeMAIL(const std::string &name, bool saveAll, double scalingFacto fprintf(fp, " %d %d\n", numVertices, numTriangles); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) { MVertex *v = entities[i]->mesh_vertices[j]; fprintf(fp, " %19.10E %19.10E %19.10E\n", v->x() * scalingFactor, v->y() * scalingFactor, v->z() * scalingFactor); } } - for(fiter it = firstFace(); it != lastFace(); ++it){ - if(saveAll || (*it)->physicals.size()){ - for(unsigned int i = 0; i < (*it)->triangles.size(); i++){ + for(fiter it = firstFace(); it != lastFace(); ++it) { + if(saveAll || (*it)->physicals.size()) { + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) { MTriangle *t = (*it)->triangles[i]; fprintf(fp, " %d %d %d\n", t->getVertex(0)->getIndex(), t->getVertex(1)->getIndex(), t->getVertex(2)->getIndex()); @@ -48,10 +49,10 @@ int GModel::writeMAIL(const std::string &name, bool saveAll, double scalingFacto } // TODO write edges (with signs) - for(fiter it = firstFace(); it != lastFace(); ++it){ - if(saveAll || (*it)->physicals.size()){ - for(unsigned int i = 0; i < (*it)->triangles.size(); i++){ - //MTriangle *t = (*it)->triangles[i]; + for(fiter it = firstFace(); it != lastFace(); ++it) { + if(saveAll || (*it)->physicals.size()) { + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) { + // MTriangle *t = (*it)->triangles[i]; fprintf(fp, " %d %d %d\n", 0, 0, 0); } } diff --git a/Geo/GModelIO_MATLAB.cpp b/Geo/GModelIO_MATLAB.cpp index fc4513c22ab4f70d17a89d4d6cf73a7a2b1b4f42..94a74ec78ae2c7a96e9c86cb372a001975f9d91b 100644 --- a/Geo/GModelIO_MATLAB.cpp +++ b/Geo/GModelIO_MATLAB.cpp @@ -17,58 +17,58 @@ #include "MPyramid.h" #include "StringUtils.h" - std::string getMATLABName(int type); -void writeElementsMATLAB(FILE *fp, const GEntity* entity, - int filetype, bool binary, int physical) +void writeElementsMATLAB(FILE *fp, const GEntity *entity, int filetype, + bool binary, int physical) { - if(filetype !=0) return; - for(unsigned int j = 0; j < entity->getNumMeshElements(); j++){ - if(entity->getMeshElement(j)-> getTypeForMSH()) - entity->getMeshElement(j)->writeMATLAB(fp, filetype, entity->tag(), physical, binary); + if(filetype != 0) return; + for(unsigned int j = 0; j < entity->getNumMeshElements(); j++) { + if(entity->getMeshElement(j)->getTypeForMSH()) + entity->getMeshElement(j)->writeMATLAB(fp, filetype, entity->tag(), + physical, binary); } return; } - -void storePairMATLAB(const GEntity* entity, int physical, - std::vector<std::vector<std::pair<MElement*, int > > > &elems) +void storePairMATLAB( + const GEntity *entity, int physical, + std::vector<std::vector<std::pair<MElement *, int> > > &elems) { - for(unsigned int j = 0; j < entity->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < entity->getNumMeshElements(); j++) { int elemtype = entity->getMeshElement(j)->getTypeForMSH(); if(elemtype) - elems[elemtype - 1].push_back(std::make_pair(entity->getMeshElement(j), physical)); + elems[elemtype - 1].push_back( + std::make_pair(entity->getMeshElement(j), physical)); } return; } - -int GModel::writeMATLAB(const std::string &name, bool binary, bool saveAll, double scalingFactor, int filetype) +int GModel::writeMATLAB(const std::string &name, bool binary, bool saveAll, + double scalingFactor, int filetype) { - //File type + // File type int SIMPLE = 0; // very simple with only triangles int LOAD_GMSH2 = 1; // structure same as utils/converters/matlab/load_gmsh2.m - //Hardcoded... + // Hardcoded... filetype = LOAD_GMSH2; - - if(binary) - { - //TODO - Msg::Warning("Binary format not available for Matlab, saving into ASCII format"); - binary = false; - } - FILE *fp = Fopen(name.c_str(), binary ? "wb":"w"); - if(!fp){ + if(binary) { + // TODO + Msg::Warning( + "Binary format not available for Matlab, saving into ASCII format"); + binary = false; + } + + FILE *fp = Fopen(name.c_str(), binary ? "wb" : "w"); + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } // if there are no physicals we save all the elements - if(noPhysicalGroups()) - saveAll = true; + if(noPhysicalGroups()) saveAll = true; // get the number of vertices and index the vertices in a continuous // sequence @@ -82,221 +82,222 @@ int GModel::writeMATLAB(const std::string &name, bool binary, bool saveAll, doub fprintf(fp, "\%\% ASCII\n"); // get all the entities in the model - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); // Print mesh vertices - if(filetype == SIMPLE) - { - fprintf(fp, "gVertices = %d;\n", numVertices); - fprintf(fp, "gXYZ = [\n"); - for(unsigned int i = 0; i < entities.size(); i++) - for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) - entities[i]->mesh_vertices[j]->writeMATLAB(fp, filetype, binary, scalingFactor); - fprintf(fp, "];\n"); - //triangles - fprintf(fp, "\%\%\n"); - fprintf(fp, "gTri=[\n"); - for(unsigned int i = 0; i < entities.size(); i++){ - if(saveAll) - writeElementsMATLAB(fp, entities[i], filetype, binary, 0); - else if(entities[i]->getPhysicalEntities().size()){ - for (unsigned k = 0; k < entities[i]->getPhysicalEntities().size(); k++){ - int physical = entities[i]->getPhysicalEntities()[k]; - writeElementsMATLAB(fp, entities[i], filetype, binary, physical); - } - } - } - fprintf(fp, "];\n"); - fprintf(fp, "nTri=size(gTri,1);\n"); + if(filetype == SIMPLE) { + fprintf(fp, "gVertices = %d;\n", numVertices); + fprintf(fp, "gXYZ = [\n"); + for(unsigned int i = 0; i < entities.size(); i++) + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) + entities[i]->mesh_vertices[j]->writeMATLAB(fp, filetype, binary, + scalingFactor); + fprintf(fp, "];\n"); + // triangles + fprintf(fp, "\%\%\n"); + fprintf(fp, "gTri=[\n"); + for(unsigned int i = 0; i < entities.size(); i++) { + if(saveAll) + writeElementsMATLAB(fp, entities[i], filetype, binary, 0); + else if(entities[i]->getPhysicalEntities().size()) { + for(unsigned k = 0; k < entities[i]->getPhysicalEntities().size(); + k++) { + int physical = entities[i]->getPhysicalEntities()[k]; + writeElementsMATLAB(fp, entities[i], filetype, binary, physical); + } + } } + fprintf(fp, "];\n"); + fprintf(fp, "nTri=size(gTri,1);\n"); + } // int nelemtype = 0; //number of element type - if(filetype == LOAD_GMSH2) - { - fprintf(fp, "clear msh;\n"); - fprintf(fp, "msh.nbNod = %d;\n", numVertices); - fprintf(fp, "msh.POS = [\n"); - for(unsigned int i = 0; i < entities.size(); i++) - for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) - entities[i]->mesh_vertices[j]->writeMATLAB(fp, filetype, binary, scalingFactor); - fprintf(fp, "];\n"); - fprintf(fp, "msh.MAX = max(msh.POS);\n"); - fprintf(fp, "msh.MIN = min(msh.POS);\n"); - //We have to store every element in an array and then store them in the file. - std::vector<std::vector<std::pair<MElement*, int > > > elems(MSH_NUM_TYPE); - //loop on each element and fill the vectors of connectivity - for(unsigned int i = 0; i < entities.size(); i++){ - if(saveAll) - storePairMATLAB(entities[i], 0, elems); - else{ - for (unsigned int iphys = 0; iphys < entities[i]->getPhysicalEntities().size(); iphys++){ - int physical = entities[i]->getPhysicalEntities()[iphys]; - storePairMATLAB(entities[i], physical, elems); - } - } + if(filetype == LOAD_GMSH2) { + fprintf(fp, "clear msh;\n"); + fprintf(fp, "msh.nbNod = %d;\n", numVertices); + fprintf(fp, "msh.POS = [\n"); + for(unsigned int i = 0; i < entities.size(); i++) + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) + entities[i]->mesh_vertices[j]->writeMATLAB(fp, filetype, binary, + scalingFactor); + fprintf(fp, "];\n"); + fprintf(fp, "msh.MAX = max(msh.POS);\n"); + fprintf(fp, "msh.MIN = min(msh.POS);\n"); + // We have to store every element in an array and then store them in the + // file. + std::vector<std::vector<std::pair<MElement *, int> > > elems(MSH_NUM_TYPE); + // loop on each element and fill the vectors of connectivity + for(unsigned int i = 0; i < entities.size(); i++) { + if(saveAll) + storePairMATLAB(entities[i], 0, elems); + else { + for(unsigned int iphys = 0; + iphys < entities[i]->getPhysicalEntities().size(); iphys++) { + int physical = entities[i]->getPhysicalEntities()[iphys]; + storePairMATLAB(entities[i], physical, elems); + } + } + } + // Store in Matlab structure + for(int elemtype = 1; elemtype < MSH_NUM_TYPE + 1; elemtype++) { + if(elems[elemtype - 1].empty()) continue; + fprintf(fp, "msh.%s =[\n", getMATLABName(elemtype).c_str()); + // writes + for(unsigned int i = 0; i < elems[elemtype - 1].size(); i++) { + elems[elemtype - 1][i].first->writeMATLAB( + fp, filetype, elems[elemtype - 1][i].second, binary); } - //Store in Matlab structure - for (int elemtype = 1; elemtype < MSH_NUM_TYPE+1; elemtype++) - { - if(elems[elemtype-1].empty()) - continue; - fprintf(fp, "msh.%s =[\n", getMATLABName(elemtype).c_str()); - //writes - for (unsigned int i = 0; i < elems[elemtype-1].size(); i++){ - elems[elemtype-1][i].first->writeMATLAB(fp, filetype, elems[elemtype-1][i].second, binary); - } - fprintf(fp, "];\n"); - } + fprintf(fp, "];\n"); } - + } + fclose(fp); return 1; } -//This should be updated whenever a new element is available in GMSH -//See Common/GmshDefines.h +// This should be updated whenever a new element is available in GMSH +// See Common/GmshDefines.h std::string getMATLABName(int type) { - switch(type){ - case MSH_LIN_2 : return "LINES"; - case MSH_TRI_3 : return "TRIANGLES"; - case MSH_QUA_4 : return "QUADS"; - case MSH_TET_4 : return "TETS"; - case MSH_HEX_8 : return "HEXAS"; - case MSH_PRI_6 : return "PRISMS"; - case MSH_PYR_5 : return "PYRAMIDS"; - case MSH_LIN_3 : return "LINES3"; - case MSH_TRI_6 : return "TRIANGLES6"; - case MSH_QUA_9 : return "QUADS9"; - case MSH_TET_10 : return "TETS10"; - case MSH_HEX_27 : return "HEXAS27"; - case MSH_PRI_18 : return "PRISMS18"; - case MSH_PYR_14 : return "PYRAMIDS14"; - case MSH_PNT : return "PNT"; - case MSH_QUA_8 : return "QUADS8"; - case MSH_HEX_20 : return "HEXAS20"; - case MSH_PRI_15 : return "PRISMS15"; - case MSH_PYR_13 : return "PYRAMIDS13"; - case MSH_TRI_9 : return "TRIANGLES9"; - case MSH_TRI_10 : return "TRIANGLES10"; - case MSH_TRI_12 : return "TRIANGLES12"; - case MSH_TRI_15 : return "TRIANGLES15"; - case MSH_TRI_15I : return "TRIANGLES15I"; - case MSH_TRI_21 : return "TRIANGLES21"; - case MSH_LIN_4 : return "LINES4"; - case MSH_LIN_5 : return "LINES5"; - case MSH_LIN_6 : return "LINES6"; - case MSH_TET_20 : return "TETS20"; - case MSH_TET_35 : return "TETS35"; - case MSH_TET_56 : return "TETS56"; - case MSH_TET_22 : return "TETS22"; - case MSH_TET_28 : return "TETS28"; - case MSH_POLYG_ : return "POLYG_"; - case MSH_POLYH_ : return "POLYH_"; - case MSH_QUA_16 : return "QUADS16"; - case MSH_QUA_25 : return "QUADS25"; - case MSH_QUA_36 : return "QUADS36"; - case MSH_QUA_12 : return "QUADS12"; - case MSH_QUA_16I : return "QUADS16I"; - case MSH_QUA_20 : return "QUADS20"; - case MSH_TRI_28 : return "TRIANGLES28"; - case MSH_TRI_36 : return "TRIANGLES36"; - case MSH_TRI_45 : return "TRIANGLES45"; - case MSH_TRI_55 : return "TRIANGLES55"; - case MSH_TRI_66 : return "TRIANGLES66"; - case MSH_QUA_49 : return "QUADS49"; - case MSH_QUA_64 : return "QUADS64"; - case MSH_QUA_81 : return "QUADS81"; - case MSH_QUA_100 : return "QUADS100"; - case MSH_QUA_121 : return "QUADS121"; - case MSH_TRI_18 : return "TRIANGLES18"; - case MSH_TRI_21I : return "TRIANGLES21I"; - case MSH_TRI_24 : return "TRIANGLES24"; - case MSH_TRI_27 : return "TRIANGLES27"; - case MSH_TRI_30 : return "TRIANGLES30"; - case MSH_QUA_24 : return "QUADS24"; - case MSH_QUA_28 : return "QUADS28"; - case MSH_QUA_32 : return "QUADS32"; - case MSH_QUA_36I : return "QUADS36I"; - case MSH_QUA_40 : return "QUADS40"; - case MSH_LIN_7 : return "LINES7"; - case MSH_LIN_8 : return "LINES8"; - case MSH_LIN_9 : return "LINES9"; - case MSH_LIN_10 : return "LINES10"; - case MSH_LIN_11 : return "LINES11"; - case MSH_LIN_B : return "LINESB"; - case MSH_TRI_B : return "TRIANGLESB"; - case MSH_POLYG_B : return "POLYG_B"; - case MSH_LIN_C : return "LINESC"; - case MSH_TET_84 : return "TETS84"; - case MSH_TET_120 : return "TETS120"; - case MSH_TET_165 : return "TETS165"; - case MSH_TET_220 : return "TETS220"; - case MSH_TET_286 : return "TETS286"; - case MSH_TET_34 : return "TETS34"; - case MSH_TET_40 : return "TETS40"; - case MSH_TET_46 : return "TETS46"; - case MSH_TET_52 : return "TETS52"; - case MSH_TET_58 : return "TETS58"; - case MSH_LIN_1 : return "LINES1"; - case MSH_TRI_1 : return "TRIANGLES1"; - case MSH_QUA_1 : return "QUADS1"; - case MSH_TET_1 : return "TETS1"; - case MSH_HEX_1 : return "HEXAS1"; - case MSH_PRI_1 : return "PRISMS1"; - case MSH_PRI_40 : return "PRISMS40"; - case MSH_PRI_75 : return "PRISMS75"; - case MSH_HEX_64 : return "HEXAS64"; - case MSH_HEX_125 : return "HEXAS125"; - case MSH_HEX_216 : return "HEXAS216"; - case MSH_HEX_343 : return "HEXAS343"; - case MSH_HEX_512 : return "HEXAS512"; - case MSH_HEX_729 : return "HEXAS729"; - case MSH_HEX_1000: return "HEXAS1000"; - case MSH_HEX_32 : return "HEXAS32"; - case MSH_HEX_44 : return "HEXAS44"; - case MSH_HEX_56 : return "HEXAS56"; - case MSH_HEX_68 : return "HEXAS68"; - case MSH_HEX_80 : return "HEXAS80"; - case MSH_HEX_92 : return "HEXAS92"; - case MSH_HEX_104 : return "HEXAS104"; - case MSH_PRI_126 : return "PRISMS126"; - case MSH_PRI_196 : return "PRISMS196"; - case MSH_PRI_288 : return "PRISMS288"; - case MSH_PRI_405 : return "PRISMS405"; - case MSH_PRI_550 : return "PRISMS550"; - case MSH_PRI_24 : return "PRISMS24"; - case MSH_PRI_33 : return "PRISMS33"; - case MSH_PRI_42 : return "PRISMS42"; - case MSH_PRI_51 : return "PRISMS51"; - case MSH_PRI_60 : return "PRISMS60"; - case MSH_PRI_69 : return "PRISMS69"; - case MSH_PRI_78 : return "PRISMS78"; - case MSH_PYR_30 : return "PYRAMIDS30"; - case MSH_PYR_55 : return "PYRAMIDS55"; - case MSH_PYR_91 : return "PYRAMIDS91"; - case MSH_PYR_140 : return "PYRAMIDS140"; - case MSH_PYR_204 : return "PYRAMIDS204"; - case MSH_PYR_285 : return "PYRAMIDS285"; - case MSH_PYR_385 : return "PYRAMIDS385"; - case MSH_PYR_21 : return "PYRAMIDS21"; - case MSH_PYR_29 : return "PYRAMIDS29"; - case MSH_PYR_37 : return "PYRAMIDS37"; - case MSH_PYR_45 : return "PYRAMIDS45"; - case MSH_PYR_53 : return "PYRAMIDS53"; - case MSH_PYR_61 : return "PYRAMIDS61"; - case MSH_PYR_69 : return "PYRAMIDS69"; - case MSH_PYR_1 : return "PYRAMIDS1"; - case MSH_PNT_SUB : return "PNT_SUB"; - case MSH_LIN_SUB : return "LINESSUB"; - case MSH_TRI_SUB : return "TRIANGLESSUB"; - case MSH_TET_SUB : return "TETSSUB"; - case MSH_TET_16 : return "TETS16"; - case MSH_TRI_MINI: return "TRIANGLESMINI"; - case MSH_TET_MINI: return "TETSMINI"; - case MSH_TRIH_4 : return "TRIH_4"; + switch(type) { + case MSH_LIN_2: return "LINES"; + case MSH_TRI_3: return "TRIANGLES"; + case MSH_QUA_4: return "QUADS"; + case MSH_TET_4: return "TETS"; + case MSH_HEX_8: return "HEXAS"; + case MSH_PRI_6: return "PRISMS"; + case MSH_PYR_5: return "PYRAMIDS"; + case MSH_LIN_3: return "LINES3"; + case MSH_TRI_6: return "TRIANGLES6"; + case MSH_QUA_9: return "QUADS9"; + case MSH_TET_10: return "TETS10"; + case MSH_HEX_27: return "HEXAS27"; + case MSH_PRI_18: return "PRISMS18"; + case MSH_PYR_14: return "PYRAMIDS14"; + case MSH_PNT: return "PNT"; + case MSH_QUA_8: return "QUADS8"; + case MSH_HEX_20: return "HEXAS20"; + case MSH_PRI_15: return "PRISMS15"; + case MSH_PYR_13: return "PYRAMIDS13"; + case MSH_TRI_9: return "TRIANGLES9"; + case MSH_TRI_10: return "TRIANGLES10"; + case MSH_TRI_12: return "TRIANGLES12"; + case MSH_TRI_15: return "TRIANGLES15"; + case MSH_TRI_15I: return "TRIANGLES15I"; + case MSH_TRI_21: return "TRIANGLES21"; + case MSH_LIN_4: return "LINES4"; + case MSH_LIN_5: return "LINES5"; + case MSH_LIN_6: return "LINES6"; + case MSH_TET_20: return "TETS20"; + case MSH_TET_35: return "TETS35"; + case MSH_TET_56: return "TETS56"; + case MSH_TET_22: return "TETS22"; + case MSH_TET_28: return "TETS28"; + case MSH_POLYG_: return "POLYG_"; + case MSH_POLYH_: return "POLYH_"; + case MSH_QUA_16: return "QUADS16"; + case MSH_QUA_25: return "QUADS25"; + case MSH_QUA_36: return "QUADS36"; + case MSH_QUA_12: return "QUADS12"; + case MSH_QUA_16I: return "QUADS16I"; + case MSH_QUA_20: return "QUADS20"; + case MSH_TRI_28: return "TRIANGLES28"; + case MSH_TRI_36: return "TRIANGLES36"; + case MSH_TRI_45: return "TRIANGLES45"; + case MSH_TRI_55: return "TRIANGLES55"; + case MSH_TRI_66: return "TRIANGLES66"; + case MSH_QUA_49: return "QUADS49"; + case MSH_QUA_64: return "QUADS64"; + case MSH_QUA_81: return "QUADS81"; + case MSH_QUA_100: return "QUADS100"; + case MSH_QUA_121: return "QUADS121"; + case MSH_TRI_18: return "TRIANGLES18"; + case MSH_TRI_21I: return "TRIANGLES21I"; + case MSH_TRI_24: return "TRIANGLES24"; + case MSH_TRI_27: return "TRIANGLES27"; + case MSH_TRI_30: return "TRIANGLES30"; + case MSH_QUA_24: return "QUADS24"; + case MSH_QUA_28: return "QUADS28"; + case MSH_QUA_32: return "QUADS32"; + case MSH_QUA_36I: return "QUADS36I"; + case MSH_QUA_40: return "QUADS40"; + case MSH_LIN_7: return "LINES7"; + case MSH_LIN_8: return "LINES8"; + case MSH_LIN_9: return "LINES9"; + case MSH_LIN_10: return "LINES10"; + case MSH_LIN_11: return "LINES11"; + case MSH_LIN_B: return "LINESB"; + case MSH_TRI_B: return "TRIANGLESB"; + case MSH_POLYG_B: return "POLYG_B"; + case MSH_LIN_C: return "LINESC"; + case MSH_TET_84: return "TETS84"; + case MSH_TET_120: return "TETS120"; + case MSH_TET_165: return "TETS165"; + case MSH_TET_220: return "TETS220"; + case MSH_TET_286: return "TETS286"; + case MSH_TET_34: return "TETS34"; + case MSH_TET_40: return "TETS40"; + case MSH_TET_46: return "TETS46"; + case MSH_TET_52: return "TETS52"; + case MSH_TET_58: return "TETS58"; + case MSH_LIN_1: return "LINES1"; + case MSH_TRI_1: return "TRIANGLES1"; + case MSH_QUA_1: return "QUADS1"; + case MSH_TET_1: return "TETS1"; + case MSH_HEX_1: return "HEXAS1"; + case MSH_PRI_1: return "PRISMS1"; + case MSH_PRI_40: return "PRISMS40"; + case MSH_PRI_75: return "PRISMS75"; + case MSH_HEX_64: return "HEXAS64"; + case MSH_HEX_125: return "HEXAS125"; + case MSH_HEX_216: return "HEXAS216"; + case MSH_HEX_343: return "HEXAS343"; + case MSH_HEX_512: return "HEXAS512"; + case MSH_HEX_729: return "HEXAS729"; + case MSH_HEX_1000: return "HEXAS1000"; + case MSH_HEX_32: return "HEXAS32"; + case MSH_HEX_44: return "HEXAS44"; + case MSH_HEX_56: return "HEXAS56"; + case MSH_HEX_68: return "HEXAS68"; + case MSH_HEX_80: return "HEXAS80"; + case MSH_HEX_92: return "HEXAS92"; + case MSH_HEX_104: return "HEXAS104"; + case MSH_PRI_126: return "PRISMS126"; + case MSH_PRI_196: return "PRISMS196"; + case MSH_PRI_288: return "PRISMS288"; + case MSH_PRI_405: return "PRISMS405"; + case MSH_PRI_550: return "PRISMS550"; + case MSH_PRI_24: return "PRISMS24"; + case MSH_PRI_33: return "PRISMS33"; + case MSH_PRI_42: return "PRISMS42"; + case MSH_PRI_51: return "PRISMS51"; + case MSH_PRI_60: return "PRISMS60"; + case MSH_PRI_69: return "PRISMS69"; + case MSH_PRI_78: return "PRISMS78"; + case MSH_PYR_30: return "PYRAMIDS30"; + case MSH_PYR_55: return "PYRAMIDS55"; + case MSH_PYR_91: return "PYRAMIDS91"; + case MSH_PYR_140: return "PYRAMIDS140"; + case MSH_PYR_204: return "PYRAMIDS204"; + case MSH_PYR_285: return "PYRAMIDS285"; + case MSH_PYR_385: return "PYRAMIDS385"; + case MSH_PYR_21: return "PYRAMIDS21"; + case MSH_PYR_29: return "PYRAMIDS29"; + case MSH_PYR_37: return "PYRAMIDS37"; + case MSH_PYR_45: return "PYRAMIDS45"; + case MSH_PYR_53: return "PYRAMIDS53"; + case MSH_PYR_61: return "PYRAMIDS61"; + case MSH_PYR_69: return "PYRAMIDS69"; + case MSH_PYR_1: return "PYRAMIDS1"; + case MSH_PNT_SUB: return "PNT_SUB"; + case MSH_LIN_SUB: return "LINESSUB"; + case MSH_TRI_SUB: return "TRIANGLESSUB"; + case MSH_TET_SUB: return "TETSSUB"; + case MSH_TET_16: return "TETS16"; + case MSH_TRI_MINI: return "TRIANGLESMINI"; + case MSH_TET_MINI: return "TETSMINI"; + case MSH_TRIH_4: return "TRIH_4"; } return ""; } - diff --git a/Geo/GModelIO_MED.cpp b/Geo/GModelIO_MED.cpp index 2ceea1a52293728823b45b866a3c53cc6bf265cf..ddb44f4db2ad8a41ef1ca4fe86a862d21eb6bd05 100644 --- a/Geo/GModelIO_MED.cpp +++ b/Geo/GModelIO_MED.cpp @@ -29,7 +29,7 @@ extern "C" { #include <med.h> } -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) // To avoid too many ifdefs below we use defines for the bits of the // API that did not change too much between MED2 and MED3. If we remove // MED2 support at some point, please remove these defines and replace @@ -69,7 +69,7 @@ med_geometrie_element msh2medElementType(int msh) case MSH_HEX_20: return MED_HEXA20; case MSH_PRI_15: return MED_PENTA15; case MSH_PYR_13: return MED_PYRA13; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) case MSH_QUA_9: return MED_QUAD9; case MSH_HEX_27: return MED_HEXA27; #endif @@ -95,7 +95,7 @@ int med2mshElementType(med_geometrie_element med) case MED_HEXA20: return MSH_HEX_20; case MED_PENTA15: return MSH_PRI_15; case MED_PYRA13: return MSH_PYR_13; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) case MED_QUAD9: return MSH_QUA_9; case MED_HEXA27: return MSH_HEX_27; #endif @@ -113,7 +113,7 @@ int med2mshNodeIndex(med_geometrie_element med, int k) case MED_TRIA6: case MED_QUAD4: case MED_QUAD8: -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) case MED_QUAD9: #endif return k; // same node numbering as in Gmsh @@ -130,13 +130,15 @@ int med2mshNodeIndex(med_geometrie_element med, int k) return map[k]; } case MED_HEXA20: { - static const int map[20] = {0,1,3,2,4,5,6,7,8,9,10,11,16,17,18,19,12,13,14,15}; + static const int map[20] = {0, 1, 3, 2, 4, 5, 6, 7, 8, 9, + 10, 11, 16, 17, 18, 19, 12, 13, 14, 15}; return map[k]; } -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) case MED_HEXA27: { - static const int map[27] = {0,1,3,2,4,5,6,7,8,9,10,11,16,17,18,19,12,13,14,15, - 20, 22, 21, 23, 24, 25, 26}; + static const int map[27] = {0, 1, 3, 2, 4, 5, 6, 7, 8, + 9, 10, 11, 16, 17, 18, 19, 12, 13, + 14, 15, 20, 22, 21, 23, 24, 25, 26}; return map[k]; } #endif @@ -145,7 +147,8 @@ int med2mshNodeIndex(med_geometrie_element med, int k) return map[k]; } case MED_PENTA15: { - static const int map[15] = {0, 2, 1, 3, 5, 4, 8, 6, 12, 7, 14, 13, 11, 9, 10}; + static const int map[15] = {0, 2, 1, 3, 5, 4, 8, 6, + 12, 7, 14, 13, 11, 9, 10}; return map[k]; } case MED_PYRA5: { @@ -156,15 +159,13 @@ int med2mshNodeIndex(med_geometrie_element med, int k) static const int map[13] = {0, 3, 2, 1, 4, 8, 5, 9, 7, 12, 6, 11, 10}; return map[k]; } - default: - Msg::Error("Unknown MED element type"); - return k; + default: Msg::Error("Unknown MED element type"); return k; } } int GModel::readMED(const std::string &name) { - med_idt fid = MEDouvrir((char*)name.c_str(), MED_LECTURE); + med_idt fid = MEDouvrir((char *)name.c_str(), MED_LECTURE); if(fid < 0) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; @@ -173,28 +174,29 @@ int GModel::readMED(const std::string &name) med_int v[3], vf[3]; MEDversionDonner(&v[0], &v[1], &v[2]); MEDversionLire(fid, &vf[0], &vf[1], &vf[2]); - Msg::Info("Reading MED file V%d.%d.%d using MED library V%d.%d.%d", - vf[0], vf[1], vf[2], v[0], v[1], v[2]); - if(vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)){ + Msg::Info("Reading MED file V%d.%d.%d using MED library V%d.%d.%d", vf[0], + vf[1], vf[2], v[0], v[1], v[2]); + if(vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)) { Msg::Error("Cannot read MED file older than V2.2"); return 0; } std::vector<std::string> meshNames; - for(int i = 0; i < MEDnMaa(fid); i++){ + for(int i = 0; i < MEDnMaa(fid); i++) { char meshName[MED_TAILLE_NOM + 1], meshDesc[MED_TAILLE_DESC + 1]; med_int spaceDim; med_maillage meshType; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_int meshDim, nStep; char dtUnit[MED_SNAME_SIZE + 1]; char axisName[3 * MED_SNAME_SIZE + 1], axisUnit[3 * MED_SNAME_SIZE + 1]; med_sorting_type sortingType; med_axis_type axisType; - if(MEDmeshInfo(fid, i + 1, meshName, &spaceDim, &meshDim, &meshType, meshDesc, - dtUnit, &sortingType, &nStep, &axisType, axisName, axisUnit) < 0){ + if(MEDmeshInfo(fid, i + 1, meshName, &spaceDim, &meshDim, &meshType, + meshDesc, dtUnit, &sortingType, &nStep, &axisType, axisName, + axisUnit) < 0) { #else - if(MEDmaaInfo(fid, i + 1, meshName, &spaceDim, &meshType, meshDesc) < 0){ + if(MEDmaaInfo(fid, i + 1, meshName, &spaceDim, &meshType, meshDesc) < 0) { #endif Msg::Error("Unable to read mesh information"); return 0; @@ -202,13 +204,13 @@ int GModel::readMED(const std::string &name) meshNames.push_back(meshName); } - if(MEDfermer(fid) < 0){ - Msg::Error("Unable to close file '%s'", (char*)name.c_str()); + if(MEDfermer(fid) < 0) { + Msg::Error("Unable to close file '%s'", (char *)name.c_str()); return 0; } int ret = 1; - for(unsigned int i = 0; i < meshNames.size(); i++){ + for(unsigned int i = 0; i < meshNames.size(); i++) { // we use the filename as a kind of "partition" indicator, allowing to // complete a model part by part (used e.g. in DDM, since MED does not store // a partition index) @@ -222,14 +224,14 @@ int GModel::readMED(const std::string &name) int GModel::readMED(const std::string &name, int meshIndex) { - med_idt fid = MEDouvrir((char*)name.c_str(), MED_LECTURE); - if(fid < 0){ + med_idt fid = MEDouvrir((char *)name.c_str(), MED_LECTURE); + if(fid < 0) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } int numMeshes = MEDnMaa(fid); - if(meshIndex >= numMeshes){ + if(meshIndex >= numMeshes) { Msg::Info("Could not find mesh %d in MED file", meshIndex); return 0; } @@ -241,16 +243,18 @@ int GModel::readMED(const std::string &name, int meshIndex) char meshName[MED_TAILLE_NOM + 1], meshDesc[MED_TAILLE_DESC + 1]; med_int spaceDim, nStep = 1; med_maillage meshType; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_int meshDim; char dtUnit[MED_SNAME_SIZE + 1]; char axisName[3 * MED_SNAME_SIZE + 1], axisUnit[3 * MED_SNAME_SIZE + 1]; med_sorting_type sortingType; med_axis_type axisType; - if(MEDmeshInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshDim, &meshType, meshDesc, - dtUnit, &sortingType, &nStep, &axisType, axisName, axisUnit) < 0){ + if(MEDmeshInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshDim, &meshType, + meshDesc, dtUnit, &sortingType, &nStep, &axisType, axisName, + axisUnit) < 0) { #else - if(MEDmaaInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshType, meshDesc) < 0){ + if(MEDmaaInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshType, meshDesc) < + 0) { #endif Msg::Error("Unable to read mesh information"); return 0; @@ -265,10 +269,10 @@ int GModel::readMED(const std::string &name, int meshIndex) setName(meshName); setFileName(name); - if(meshType == MED_NON_STRUCTURE){ + if(meshType == MED_NON_STRUCTURE) { Msg::Info("Reading %d-D unstructured mesh <<%s>>", spaceDim, meshName); } - else{ + else { Msg::Error("Reading structured MED meshes is not supported"); return 0; } @@ -276,41 +280,41 @@ int GModel::readMED(const std::string &name, int meshIndex) MEDversionLire(fid, &vf[0], &vf[1], &vf[2]); // read nodes -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_bool changeOfCoord, geoTransform; - med_int numNodes = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE, - MED_NO_GEOTYPE, MED_COORDINATE, MED_NO_CMODE, - &changeOfCoord, &geoTransform); + med_int numNodes = MEDmeshnEntity( + fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE, + MED_COORDINATE, MED_NO_CMODE, &changeOfCoord, &geoTransform); #else - med_int numNodes = MEDnEntMaa(fid, meshName, MED_COOR, MED_NOEUD, MED_NONE, - MED_NOD); + med_int numNodes = + MEDnEntMaa(fid, meshName, MED_COOR, MED_NOEUD, MED_NONE, MED_NOD); #endif - if(numNodes < 0){ + if(numNodes < 0) { Msg::Error("Could not read number of MED nodes"); return 0; } - if(numNodes == 0){ + if(numNodes == 0) { Msg::Error("No nodes in MED mesh"); return 0; } - std::vector<MVertex*> verts(numNodes); + std::vector<MVertex *> verts(numNodes); std::vector<med_float> coord(spaceDim * numNodes); -#if (MED_MAJOR_NUM == 3) - if(MEDmeshNodeCoordinateRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE, - &coord[0]) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDmeshNodeCoordinateRd(fid, meshName, MED_NO_DT, MED_NO_IT, + MED_FULL_INTERLACE, &coord[0]) < 0) { #else std::vector<char> coordName(spaceDim * MED_TAILLE_PNOM + 1); std::vector<char> coordUnit(spaceDim * MED_TAILLE_PNOM + 1); med_repere rep; if(MEDcoordLire(fid, meshName, spaceDim, &coord[0], MED_FULL_INTERLACE, - MED_ALL, 0, 0, &rep, &coordName[0], &coordUnit[0]) < 0){ + MED_ALL, 0, 0, &rep, &coordName[0], &coordUnit[0]) < 0) { #endif Msg::Error("Could not read MED node coordinates"); return 0; } std::vector<med_int> nodeTags(numNodes); -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE, &nodeTags[0]) < 0) #else @@ -321,72 +325,76 @@ int GModel::readMED(const std::string &name, int meshIndex) for(int i = 0; i < numNodes; i++) verts[i] = new MVertex(coord[spaceDim * i], (spaceDim > 1) ? coord[spaceDim * i + 1] : 0., - (spaceDim > 2) ? coord[spaceDim * i + 2] : 0., - 0, nodeTags.empty() ? 0 : nodeTags[i]); + (spaceDim > 2) ? coord[spaceDim * i + 2] : 0., 0, + nodeTags.empty() ? 0 : nodeTags[i]); // read elements (loop over all possible MSH element types) - for(int mshType = 0; mshType < MSH_NUM_TYPE; mshType++){ + for(int mshType = 0; mshType < MSH_NUM_TYPE; mshType++) { med_geometrie_element type = msh2medElementType(mshType); if(type == MED_NONE) continue; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_bool changeOfCoord; med_bool geoTransform; - med_int numEle = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, - type, MED_CONNECTIVITY, MED_NODAL, &changeOfCoord, - &geoTransform); + med_int numEle = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, + MED_CELL, type, MED_CONNECTIVITY, MED_NODAL, + &changeOfCoord, &geoTransform); #else - med_int numEle = MEDnEntMaa(fid, meshName, MED_CONN, MED_MAILLE, type, MED_NOD); + med_int numEle = + MEDnEntMaa(fid, meshName, MED_CONN, MED_MAILLE, type, MED_NOD); #endif if(numEle <= 0) continue; int numNodPerEle = type % 100; std::vector<med_int> conn(numEle * numNodPerEle); -#if (MED_MAJOR_NUM == 3) - if(MEDmeshElementConnectivityRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, - type, MED_NODAL, MED_FULL_INTERLACE, &conn[0]) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDmeshElementConnectivityRd(fid, meshName, MED_NO_DT, MED_NO_IT, + MED_CELL, type, MED_NODAL, + MED_FULL_INTERLACE, &conn[0]) < 0) { #else - if(MEDconnLire(fid, meshName, spaceDim, &conn[0], MED_FULL_INTERLACE, 0, MED_ALL, - MED_MAILLE, type, MED_NOD) < 0){ + if(MEDconnLire(fid, meshName, spaceDim, &conn[0], MED_FULL_INTERLACE, 0, + MED_ALL, MED_MAILLE, type, MED_NOD) < 0) { #endif Msg::Error("Could not read MED elements"); return 0; } std::vector<med_int> fam(numEle, 0); -#if (MED_MAJOR_NUM == 3) - if(MEDmeshEntityFamilyNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, - type, &fam[0]) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDmeshEntityFamilyNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, + MED_CELL, type, &fam[0]) < 0) { #else - if(MEDfamLire(fid, meshName, &fam[0], numEle, MED_MAILLE, type) < 0){ + if(MEDfamLire(fid, meshName, &fam[0], numEle, MED_MAILLE, type) < 0) { #endif - Msg::Info("No family number for elements: using 0 as default family number"); + Msg::Info( + "No family number for elements: using 0 as default family number"); } std::vector<med_int> eleTags(numEle); -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, &eleTags[0]) < 0) #else if(MEDnumLire(fid, meshName, &eleTags[0], numEle, MED_MAILLE, type) < 0) #endif eleTags.clear(); - std::map<int, std::vector<MElement*> > elements; + std::map<int, std::vector<MElement *> > elements; MElementFactory factory; - for(int j = 0; j < numEle; j++){ - std::vector<MVertex*> v(numNodPerEle); + for(int j = 0; j < numEle; j++) { + std::vector<MVertex *> v(numNodPerEle); bool ok = true; - for(int k = 0; k < numNodPerEle; k++){ + for(int k = 0; k < numNodPerEle; k++) { int idx = conn[numNodPerEle * j + med2mshNodeIndex(type, k)] - 1; - if(idx < 0 || idx > verts.size() - 1){ + if(idx < 0 || idx > verts.size() - 1) { Msg::Error("Wrong node index %d in MED file", idx); ok = false; } - else{ + else { v[k] = verts[idx]; } } - if(ok){ - MElement *e = factory.create(mshType, v, eleTags.empty() ? 0 : eleTags[j]); + if(ok) { + MElement *e = + factory.create(mshType, v, eleTags.empty() ? 0 : eleTags[j]); // according to the MED documentation, fam[j] should be negative; still, - // accept all family ids, even positive, as some code do not export valid - // MED files + // accept all family ids, even positive, as some code do not export + // valid MED files if(e) elements[std::abs(fam[j])].push_back(e); } } @@ -397,19 +405,20 @@ int GModel::readMED(const std::string &name, int meshIndex) // read family info med_int numFamilies = MEDnFam(fid, meshName); - if(numFamilies < 0){ + if(numFamilies < 0) { Msg::Error("Could not read MED families"); return 0; } - for(int i = 0; i < numFamilies; i++){ -#if (MED_MAJOR_NUM == 3) - med_int numAttrib = (vf[0] == 2) ? MEDnFamily23Attribute(fid, meshName, i + 1) : 0; + for(int i = 0; i < numFamilies; i++) { +#if(MED_MAJOR_NUM == 3) + med_int numAttrib = + (vf[0] == 2) ? MEDnFamily23Attribute(fid, meshName, i + 1) : 0; med_int numGroups = MEDnFamilyGroup(fid, meshName, i + 1); #else med_int numAttrib = MEDnAttribut(fid, meshName, i + 1); med_int numGroups = MEDnGroupe(fid, meshName, i + 1); #endif - if(numAttrib < 0 || numGroups < 0){ + if(numAttrib < 0 || numGroups < 0) { Msg::Error("Could not read MED groups or attributes"); return 0; } @@ -419,18 +428,18 @@ int GModel::readMED(const std::string &name, int meshIndex) std::vector<char> groupNames(MED_TAILLE_LNOM * numGroups + 1); char familyName[MED_TAILLE_NOM + 1]; med_int familyNum; -#if (MED_MAJOR_NUM == 3) - if(vf[0] == 2){ // MED2 file +#if(MED_MAJOR_NUM == 3) + if(vf[0] == 2) { // MED2 file if(MEDfamily23Info(fid, meshName, i + 1, familyName, &attribId[0], &attribVal[0], &attribDes[0], &familyNum, - &groupNames[0]) < 0){ + &groupNames[0]) < 0) { Msg::Error("Could not read info for MED2 family %d", i + 1); continue; } } - else{ + else { if(MEDfamilyInfo(fid, meshName, i + 1, familyName, &familyNum, - &groupNames[0]) < 0){ + &groupNames[0]) < 0) { Msg::Error("Could not read info for MED3 family %d", i + 1); continue; } @@ -438,7 +447,7 @@ int GModel::readMED(const std::string &name, int meshIndex) #else if(MEDfamInfo(fid, meshName, i + 1, familyName, &familyNum, &attribId[0], &attribVal[0], &attribDes[0], &numAttrib, &groupNames[0], - &numGroups) < 0){ + &numGroups) < 0) { Msg::Error("Could not read info for MED family %d", i + 1); continue; } @@ -447,20 +456,25 @@ int GModel::readMED(const std::string &name, int meshIndex) // family tags are positive - these will simply never match any Gmsh GEntity // tag and will be ignored) GEntity *ge; - if((ge = getRegionByTag(-familyNum))){} - else if((ge = getFaceByTag(-familyNum))){} - else if((ge = getEdgeByTag(-familyNum))){} - else ge = getVertexByTag(-familyNum); - if(ge){ + if((ge = getRegionByTag(-familyNum))) { + } + else if((ge = getFaceByTag(-familyNum))) { + } + else if((ge = getEdgeByTag(-familyNum))) { + } + else + ge = getVertexByTag(-familyNum); + if(ge) { elementaryNames[std::pair<int, int>(ge->dim(), -familyNum)] = familyName; - if(numGroups > 0){ - for(int j = 0; j < numGroups; j++){ + if(numGroups > 0) { + for(int j = 0; j < numGroups; j++) { char tmp[MED_TAILLE_LNOM + 1]; strncpy(tmp, &groupNames[j * MED_TAILLE_LNOM], MED_TAILLE_LNOM); tmp[MED_TAILLE_LNOM] = '\0'; // don't use same physical number across dimensions, as e.g. getdp // does not support this - int pnum = setPhysicalName(tmp, ge->dim(), getMaxPhysicalNumber(-1) + 1); + int pnum = + setPhysicalName(tmp, ge->dim(), getMaxPhysicalNumber(-1) + 1); if(std::find(ge->physicals.begin(), ge->physicals.end(), pnum) == ge->physicals.end()) ge->physicals.push_back(pnum); @@ -469,83 +483,90 @@ int GModel::readMED(const std::string &name, int meshIndex) } } - // check if we need to read some post-processing data later -#if (MED_MAJOR_NUM == 3) + // check if we need to read some post-processing data later +#if(MED_MAJOR_NUM == 3) bool postpro = (MEDnField(fid) > 0) ? true : false; #else bool postpro = (MEDnChamp(fid, 0) > 0) ? true : false; #endif - if(MEDfermer(fid) < 0){ - Msg::Error("Unable to close file '%s'", (char*)name.c_str()); + if(MEDfermer(fid) < 0) { + Msg::Error("Unable to close file '%s'", (char *)name.c_str()); return 0; } return postpro ? 2 : 1; } -template<class T> -static void fillElementsMED(med_int family, std::vector<T*> &elements, - std::vector<med_int> &conn, std::vector<med_int> &fam, +template <class T> +static void fillElementsMED(med_int family, std::vector<T *> &elements, + std::vector<med_int> &conn, + std::vector<med_int> &fam, med_geometrie_element &type) { if(elements.empty()) return; type = msh2medElementType(elements[0]->getTypeForMSH()); - if(type == MED_NONE){ + if(type == MED_NONE) { Msg::Warning("Unsupported element type in MED format"); return; } - for(unsigned int i = 0; i < elements.size(); i++){ + for(unsigned int i = 0; i < elements.size(); i++) { elements[i]->setVolumePositive(); for(int j = 0; j < elements[i]->getNumVertices(); j++) - conn.push_back(elements[i]->getVertex(med2mshNodeIndex(type, j))->getIndex()); + conn.push_back( + elements[i]->getVertex(med2mshNodeIndex(type, j))->getIndex()); fam.push_back(family); } } -static void writeElementsMED(med_idt &fid, char *meshName, std::vector<med_int> &conn, - std::vector<med_int> &fam, med_geometrie_element type) +static void writeElementsMED(med_idt &fid, char *meshName, + std::vector<med_int> &conn, + std::vector<med_int> &fam, + med_geometrie_element type) { if(fam.empty()) return; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) if(MEDmeshElementWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., MED_CELL, type, MED_NODAL, MED_FULL_INTERLACE, (med_int)fam.size(), - &conn[0], MED_FALSE, 0, MED_FALSE, 0, MED_TRUE, &fam[0]) < 0) + &conn[0], MED_FALSE, 0, MED_FALSE, 0, MED_TRUE, + &fam[0]) < 0) #else - if(MEDelementsEcr(fid, meshName, (med_int)3, &conn[0], MED_FULL_INTERLACE, - 0, MED_FAUX, 0, MED_FAUX, &fam[0], (med_int)fam.size(), + if(MEDelementsEcr(fid, meshName, (med_int)3, &conn[0], MED_FULL_INTERLACE, 0, + MED_FAUX, 0, MED_FAUX, &fam[0], (med_int)fam.size(), MED_MAILLE, type, MED_NOD) < 0) #endif Msg::Error("Could not write MED elements"); } -int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor) +int GModel::writeMED(const std::string &name, bool saveAll, + double scalingFactor) { - med_idt fid = MEDouvrir((char*)name.c_str(), MED_CREATION); - if(fid < 0){ + med_idt fid = MEDouvrir((char *)name.c_str(), MED_CREATION); + if(fid < 0) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } // write header - if(MEDfichDesEcr(fid, (char*)"MED file generated by Gmsh") < 0){ + if(MEDfichDesEcr(fid, (char *)"MED file generated by Gmsh") < 0) { Msg::Error("Unable to write MED descriptor"); return 0; } std::string strMeshName = getName(); - char *meshName = (char*)strMeshName.c_str(); + char *meshName = (char *)strMeshName.c_str(); // Gmsh always writes 3D unstructured meshes -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) char dtUnit[MED_SNAME_SIZE + 1] = ""; char axisName[3 * MED_SNAME_SIZE + 1] = ""; char axisUnit[3 * MED_SNAME_SIZE + 1] = ""; - if(MEDmeshCr(fid, meshName, 3, 3, MED_UNSTRUCTURED_MESH, "Mesh created with Gmsh", - dtUnit, MED_SORT_DTIT, MED_CARTESIAN, axisName, axisUnit) < 0){ + if(MEDmeshCr(fid, meshName, 3, 3, MED_UNSTRUCTURED_MESH, + "Mesh created with Gmsh", dtUnit, MED_SORT_DTIT, MED_CARTESIAN, + axisName, axisUnit) < 0) { #else if(MEDmaaCr(fid, meshName, 3, MED_NON_STRUCTURE, - (char*)"Mesh created with Gmsh") < 0){ + (char *)"Mesh created with Gmsh") < 0) { #endif Msg::Error("Could not create MED mesh"); return 0; @@ -561,34 +582,34 @@ int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor // get a vector containing all the geometrical entities in the // model (the ordering of the entities must be the same as the one // used during the indexing of the vertices) - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - std::map<GEntity*, int> families; + std::map<GEntity *, int> families; // write the families { - // always create a "0" family, with no groups or attributes -#if (MED_MAJOR_NUM == 3) + // always create a "0" family, with no groups or attributes +#if(MED_MAJOR_NUM == 3) if(MEDfamilyCr(fid, meshName, "F_0", 0, 0, "") < 0) #else - if(MEDfamCr(fid, meshName, (char*)"F_0", 0, 0, 0, 0, 0, 0, 0) < 0) + if(MEDfamCr(fid, meshName, (char *)"F_0", 0, 0, 0, 0, 0, 0, 0) < 0) #endif Msg::Error("Could not create MED family 0"); // create one family per elementary entity, with one group per // physical entity and no attributes - for(unsigned int i = 0; i < entities.size(); i++){ - if(saveAll || entities[i]->physicals.size()){ - int num = - ((int)families.size() + 1); + for(unsigned int i = 0; i < entities.size(); i++) { + if(saveAll || entities[i]->physicals.size()) { + int num = -((int)families.size() + 1); families[entities[i]] = num; std::ostringstream fs; fs << entities[i]->dim() << "D_" << entities[i]->tag(); std::string familyName = "F_" + fs.str(); std::string groupName; - for(unsigned j = 0; j < entities[i]->physicals.size(); j++){ - std::string tmp = getPhysicalName - (entities[i]->dim(), entities[i]->physicals[j]); - if(tmp.empty()){ // create unique name + for(unsigned j = 0; j < entities[i]->physicals.size(); j++) { + std::string tmp = + getPhysicalName(entities[i]->dim(), entities[i]->physicals[j]); + if(tmp.empty()) { // create unique name std::ostringstream gs; gs << entities[i]->dim() << "D_" << entities[i]->physicals[j]; groupName += "G_" + gs.str(); @@ -597,13 +618,13 @@ int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor groupName += tmp; groupName.resize((j + 1) * MED_TAILLE_LNOM, ' '); } -#if (MED_MAJOR_NUM == 3) - if(MEDfamilyCr(fid, meshName, familyName.c_str(), - (med_int)num, (med_int)entities[i]->physicals.size(), +#if(MED_MAJOR_NUM == 3) + if(MEDfamilyCr(fid, meshName, familyName.c_str(), (med_int)num, + (med_int)entities[i]->physicals.size(), groupName.c_str()) < 0) #else - if(MEDfamCr(fid, meshName, (char*)familyName.c_str(), - (med_int)num, 0, 0, 0, 0, (char*)groupName.c_str(), + if(MEDfamCr(fid, meshName, (char *)familyName.c_str(), (med_int)num, 0, + 0, 0, 0, (char *)groupName.c_str(), (med_int)entities[i]->physicals.size()) < 0) #endif Msg::Error("Could not create MED family %d", num); @@ -615,10 +636,10 @@ int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor { std::vector<med_float> coord; std::vector<med_int> fam; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) { MVertex *v = entities[i]->mesh_vertices[j]; - if(v->getIndex() >= 0){ + if(v->getIndex() >= 0) { coord.push_back(v->x() * scalingFactor); coord.push_back(v->y() * scalingFactor); coord.push_back(v->z() * scalingFactor); @@ -626,14 +647,14 @@ int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor } } } - if(fam.empty()){ + if(fam.empty()) { Msg::Error("No nodes to write in MED mesh"); return 0; } -#if (MED_MAJOR_NUM == 3) - if(MEDmeshNodeWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., MED_FULL_INTERLACE, - (med_int)fam.size(), &coord[0], MED_FALSE, "", MED_FALSE, 0, - MED_TRUE, &fam[0]) < 0) +#if(MED_MAJOR_NUM == 3) + if(MEDmeshNodeWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., + MED_FULL_INTERLACE, (med_int)fam.size(), &coord[0], + MED_FALSE, "", MED_FALSE, 0, MED_TRUE, &fam[0]) < 0) #else char coordName[3 * MED_TAILLE_PNOM + 1] = "x y z "; @@ -714,8 +735,8 @@ int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor } } - if(MEDfermer(fid) < 0){ - Msg::Error("Unable to close file '%s'", (char*)name.c_str()); + if(MEDfermer(fid) < 0) { + Msg::Error("Unable to close file '%s'", (char *)name.c_str()); return 0; } @@ -738,7 +759,8 @@ int GModel::readMED(const std::string &name, int meshIndex) return 0; } -int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor) +int GModel::writeMED(const std::string &name, bool saveAll, + double scalingFactor) { Msg::Error("Gmsh must be compiled with MED support to write '%s'", name.c_str()); diff --git a/Geo/GModelIO_MESH.cpp b/Geo/GModelIO_MESH.cpp index 68d849b73b354ce3f0ed2a32a17d72dc21653d26..916f6e6d2f3699c40d8a4029e9efabb928928d93 100644 --- a/Geo/GModelIO_MESH.cpp +++ b/Geo/GModelIO_MESH.cpp @@ -14,11 +14,11 @@ #include "MHexahedron.h" #include "Context.h" -static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, - std::vector<MVertex*> &vertices) +static bool getMeshVertices(int num, int *indices, std::vector<MVertex *> &vec, + std::vector<MVertex *> &vertices) { - for(int i = 0; i < num; i++){ - if(indices[i] < 0 || indices[i] > (int)(vec.size() - 1)){ + for(int i = 0; i < num; i++) { + if(indices[i] < 0 || indices[i] > (int)(vec.size() - 1)) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -31,38 +31,41 @@ static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, int GModel::readMESH(const std::string &name) { FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } char buffer[256]; - if(!fgets(buffer, sizeof(buffer), fp)){ fclose(fp); return 0; } + if(!fgets(buffer, sizeof(buffer), fp)) { + fclose(fp); + return 0; + } char str[256]; int format; sscanf(buffer, "%s %d", str, &format); - if(format == 3){ + if(format == 3) { Msg::Error("Medit mesh import only available for ASCII files"); fclose(fp); return 0; } - std::vector<MVertex*> vertexVector; - std::map<int, std::vector<MElement*> > elements[5]; + std::vector<MVertex *> vertexVector; + std::map<int, std::vector<MElement *> > elements[5]; while(!feof(fp)) { if(!fgets(buffer, 256, fp)) break; - if(buffer[0] != '#'){ // skip comments and empty lines - str[0]='\0'; + if(buffer[0] != '#') { // skip comments and empty lines + str[0] = '\0'; sscanf(buffer, "%s", str); - if(!strncmp(buffer, "Dimension 3", 11)){ + if(!strncmp(buffer, "Dimension 3", 11)) { // alternative single-line 'Dimension' field used by CGAL } - else if(!strcmp(str, "Dimension")){ + else if(!strcmp(str, "Dimension")) { if(!fgets(buffer, sizeof(buffer), fp)) break; } - else if(!strcmp(str, "Vertices")){ + else if(!strcmp(str, "Vertices")) { if(!fgets(buffer, sizeof(buffer), fp)) break; int nbv; sscanf(buffer, "%d", &nbv); @@ -76,7 +79,7 @@ int GModel::readMESH(const std::string &name) vertexVector[i] = new MVertex(x, y, z); } } - else if(!strcmp(str, "Edges")){ + else if(!strcmp(str, "Edges")) { if(!fgets(buffer, sizeof(buffer), fp)) break; int nbe; sscanf(buffer, "%d", &nbe); @@ -86,12 +89,15 @@ int GModel::readMESH(const std::string &name) int n[2], cl; sscanf(buffer, "%d %d %d", &n[0], &n[1], &cl); for(int j = 0; j < 2; j++) n[j]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(2, n, vertexVector, vertices)){ fclose(fp); return 0; } + std::vector<MVertex *> vertices; + if(!getMeshVertices(2, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } elements[0][cl].push_back(new MLine(vertices)); } } - else if(!strcmp(str, "EdgesP2")){ + else if(!strcmp(str, "EdgesP2")) { if(!fgets(buffer, sizeof(buffer), fp)) break; int nbe; sscanf(buffer, "%d", &nbe); @@ -101,12 +107,15 @@ int GModel::readMESH(const std::string &name) int n[3], cl; sscanf(buffer, "%d %d %d %d", &n[0], &n[1], &n[2], &cl); for(int j = 0; j < 3; j++) n[j]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(3, n, vertexVector, vertices)){ fclose(fp); return 0; } + std::vector<MVertex *> vertices; + if(!getMeshVertices(3, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } elements[0][cl].push_back(new MLine3(vertices)); } } - else if(!strcmp(str, "Triangles")){ + else if(!strcmp(str, "Triangles")) { if(!fgets(buffer, sizeof(buffer), fp)) break; int nbe; sscanf(buffer, "%d", &nbe); @@ -116,12 +125,15 @@ int GModel::readMESH(const std::string &name) int n[3], cl; sscanf(buffer, "%d %d %d %d", &n[0], &n[1], &n[2], &cl); for(int j = 0; j < 3; j++) n[j]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(3, n, vertexVector, vertices)){ fclose(fp); return 0; } + std::vector<MVertex *> vertices; + if(!getMeshVertices(3, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } elements[1][cl].push_back(new MTriangle(vertices)); } } - else if(!strcmp(str, "TrianglesP2")){ + else if(!strcmp(str, "TrianglesP2")) { if(!fgets(buffer, sizeof(buffer), fp)) break; int nbe; sscanf(buffer, "%d", &nbe); @@ -129,11 +141,14 @@ int GModel::readMESH(const std::string &name) for(int i = 0; i < nbe; i++) { if(!fgets(buffer, sizeof(buffer), fp)) break; int n[6], cl; - sscanf(buffer, "%d %d %d %d %d %d %d", - &n[0], &n[1], &n[2], &n[3], &n[4], &n[5], &cl); + sscanf(buffer, "%d %d %d %d %d %d %d", &n[0], &n[1], &n[2], &n[3], + &n[4], &n[5], &cl); for(int j = 0; j < 6; j++) n[j]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(6, n, vertexVector, vertices)){ fclose(fp); return 0; } + std::vector<MVertex *> vertices; + if(!getMeshVertices(6, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } elements[1][cl].push_back(new MTriangle6(vertices)); } } @@ -147,8 +162,11 @@ int GModel::readMESH(const std::string &name) int n[4], cl; sscanf(buffer, "%d %d %d %d %d", &n[0], &n[1], &n[2], &n[3], &cl); for(int j = 0; j < 4; j++) n[j]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(4, n, vertexVector, vertices)){ fclose(fp); return 0; } + std::vector<MVertex *> vertices; + if(!getMeshVertices(4, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } elements[2][cl].push_back(new MQuadrangle(vertices)); } } @@ -162,8 +180,11 @@ int GModel::readMESH(const std::string &name) int n[4], cl; sscanf(buffer, "%d %d %d %d %d", &n[0], &n[1], &n[2], &n[3], &cl); for(int j = 0; j < 4; j++) n[j]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(4, n, vertexVector, vertices)){ fclose(fp); return 0; } + std::vector<MVertex *> vertices; + if(!getMeshVertices(4, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } elements[3][cl].push_back(new MTetrahedron(vertices)); } } @@ -175,11 +196,14 @@ int GModel::readMESH(const std::string &name) for(int i = 0; i < nbe; i++) { if(!fgets(buffer, sizeof(buffer), fp)) break; int n[10], cl; - sscanf(buffer, "%d %d %d %d %d %d %d %d %d %d %d", &n[0], &n[1], &n[2], - &n[3],&n[4], &n[5], &n[6], &n[7], &n[9], &n[8], &cl); + sscanf(buffer, "%d %d %d %d %d %d %d %d %d %d %d", &n[0], &n[1], + &n[2], &n[3], &n[4], &n[5], &n[6], &n[7], &n[9], &n[8], &cl); for(int j = 0; j < 10; j++) n[j]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(10, n, vertexVector, vertices)){ fclose(fp); return 0; } + std::vector<MVertex *> vertices; + if(!getMeshVertices(10, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } elements[3][cl].push_back(new MTetrahedron10(vertices)); } } @@ -191,11 +215,14 @@ int GModel::readMESH(const std::string &name) for(int i = 0; i < nbe; i++) { if(!fgets(buffer, sizeof(buffer), fp)) break; int n[8], cl; - sscanf(buffer, "%d %d %d %d %d %d %d %d %d", &n[0], &n[1], &n[2], &n[3], - &n[4], &n[5], &n[6], &n[7], &cl); + sscanf(buffer, "%d %d %d %d %d %d %d %d %d", &n[0], &n[1], &n[2], + &n[3], &n[4], &n[5], &n[6], &n[7], &cl); for(int j = 0; j < 8; j++) n[j]--; - std::vector<MVertex*> vertices; - if(!getMeshVertices(8, n, vertexVector, vertices)){ fclose(fp); return 0; } + std::vector<MVertex *> vertices; + if(!getMeshVertices(8, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } elements[4][cl].push_back(new MHexahedron(vertices)); } } @@ -206,17 +233,17 @@ int GModel::readMESH(const std::string &name) _storeElementsInEntities(elements[i]); _associateEntityWithMeshVertices(); _storeVerticesInEntities(vertexVector); - _createGeometryOfDiscreteEntities() ; + _createGeometryOfDiscreteEntities(); fclose(fp); return 1; } -int GModel::writeMESH(const std::string &name, int elementTagType, - bool saveAll, double scalingFactor) +int GModel::writeMESH(const std::string &name, int elementTagType, bool saveAll, + double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -231,7 +258,7 @@ int GModel::writeMESH(const std::string &name, int elementTagType, fprintf(fp, " Vertices\n"); fprintf(fp, " %d\n", numVertices); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) @@ -239,87 +266,87 @@ int GModel::writeMESH(const std::string &name, int elementTagType, int numEdges = 0, numTriangles = 0, numQuadrangles = 0; int numTetrahedra = 0, numHexahedra = 0; - for(eiter it = firstEdge(); it != lastEdge(); ++it){ - if(saveAll || (*it)->physicals.size()){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { + if(saveAll || (*it)->physicals.size()) { numEdges += (*it)->lines.size(); } } - for(fiter it = firstFace(); it != lastFace(); ++it){ - if(saveAll || (*it)->physicals.size()){ + for(fiter it = firstFace(); it != lastFace(); ++it) { + if(saveAll || (*it)->physicals.size()) { numTriangles += (*it)->triangles.size(); numQuadrangles += (*it)->quadrangles.size(); } } - for(riter it = firstRegion(); it != lastRegion(); ++it){ - if(saveAll || (*it)->physicals.size()){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { + if(saveAll || (*it)->physicals.size()) { numTetrahedra += (*it)->tetrahedra.size(); numHexahedra += (*it)->hexahedra.size(); } } - if(numEdges){ + if(numEdges) { if(CTX::instance()->mesh.order == 2) // FIXME (check getPolynomialOrder()) fprintf(fp, " EdgesP2\n"); else fprintf(fp, " Edges\n"); fprintf(fp, " %d\n", numEdges); - for(eiter it = firstEdge(); it != lastEdge(); ++it){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { int numPhys = (*it)->physicals.size(); - if(saveAll || numPhys){ + if(saveAll || numPhys) { for(unsigned int i = 0; i < (*it)->lines.size(); i++) (*it)->lines[i]->writeMESH(fp, elementTagType, (*it)->tag(), numPhys ? (*it)->physicals[0] : 0); } } } - if(numTriangles){ + if(numTriangles) { if(CTX::instance()->mesh.order == 2) // FIXME (check getPolynomialOrder()) fprintf(fp, " TrianglesP2\n"); else fprintf(fp, " Triangles\n"); fprintf(fp, " %d\n", numTriangles); - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { int numPhys = (*it)->physicals.size(); - if(saveAll || numPhys){ + if(saveAll || numPhys) { for(unsigned int i = 0; i < (*it)->triangles.size(); i++) (*it)->triangles[i]->writeMESH(fp, elementTagType, (*it)->tag(), numPhys ? (*it)->physicals[0] : 0); } } } - if(numQuadrangles){ + if(numQuadrangles) { fprintf(fp, " Quadrilaterals\n"); fprintf(fp, " %d\n", numQuadrangles); - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { int numPhys = (*it)->physicals.size(); - if(saveAll || numPhys){ + if(saveAll || numPhys) { for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) (*it)->quadrangles[i]->writeMESH(fp, elementTagType, (*it)->tag(), numPhys ? (*it)->physicals[0] : 0); } } } - if(numTetrahedra){ + if(numTetrahedra) { if(CTX::instance()->mesh.order == 2) fprintf(fp, " TetrahedraP2\n"); // FIXME (check getPolynomialOrder()) else fprintf(fp, " Tetrahedra\n"); fprintf(fp, " %d\n", numTetrahedra); - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { int numPhys = (*it)->physicals.size(); - if(saveAll || numPhys){ + if(saveAll || numPhys) { for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) (*it)->tetrahedra[i]->writeMESH(fp, elementTagType, (*it)->tag(), numPhys ? (*it)->physicals[0] : 0); } } } - if(numHexahedra){ + if(numHexahedra) { fprintf(fp, " Hexahedra\n"); fprintf(fp, " %d\n", numHexahedra); - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { int numPhys = (*it)->physicals.size(); - if(saveAll || numPhys){ + if(saveAll || numPhys) { for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++) (*it)->hexahedra[i]->writeMESH(fp, elementTagType, (*it)->tag(), numPhys ? (*it)->physicals[0] : 0); diff --git a/Geo/GModelIO_MSH.cpp b/Geo/GModelIO_MSH.cpp index 1a41b382a9fbda02c6c285675a8f2188a523280d..79f13589da4673d1d0fc95611e281ecdf8b3e24b 100644 --- a/Geo/GModelIO_MSH.cpp +++ b/Geo/GModelIO_MSH.cpp @@ -12,15 +12,18 @@ int GModel::readMSH(const std::string &name) { FILE *fp = Fopen(name.c_str(), "rb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } // detect prehistoric MSH files (without MeshFormat header) char str[256] = ""; - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } - if(!strncmp(&str[1], "NOD", 3) || !strncmp(&str[1], "NOE", 3)){ + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } + if(!strncmp(&str[1], "NOD", 3) || !strncmp(&str[1], "NOE", 3)) { fclose(fp); return _readMSH2(name); } @@ -28,37 +31,37 @@ int GModel::readMSH(const std::string &name) rewind(fp); while(1) { - - while(str[0] != '$'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(str[0] != '$') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } - if(feof(fp)) - break; + if(feof(fp)) break; // $MeshFormat section if(!strncmp(&str[1], "MeshFormat", 10)) { - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } double version = 0.; int format, size; - if(sscanf(str, "%lf %d %d", &version, &format, &size) != 3){ + if(sscanf(str, "%lf %d %d", &version, &format, &size) != 3) { fclose(fp); return 0; } - if(version < 3.0){ + if(version < 3.0) { fclose(fp); return _readMSH2(name); } - else if(version < 4.0){ + else if(version < 4.0) { fclose(fp); return _readMSH3(name); } - else if(version < 5.0){ + else if(version < 5.0) { fclose(fp); return _readMSH4(name); } - else{ + else { Msg::Error("Unknown MSH file version %g", version); fclose(fp); return 0; @@ -66,8 +69,7 @@ int GModel::readMSH(const std::string &name) } do { - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } while(str[0] != '$'); } @@ -77,25 +79,28 @@ int GModel::readMSH(const std::string &name) } int GModel::writeMSH(const std::string &name, double version, bool binary, - bool saveAll, bool saveParametric, - double scalingFactor, int elementStartNum, - int saveSinglePartition, bool multipleView) + bool saveAll, bool saveParametric, double scalingFactor, + int elementStartNum, int saveSinglePartition, + bool multipleView) { - if(version < 4.0 && getNumPartitions() > 0){ + if(version < 4.0 && getNumPartitions() > 0) { Msg::Warning("Saving a partitioned mesh in a format older than 4.0 may " "cause information loss"); } - if(version < 3.0){ - return _writeMSH2(name, version, binary, saveAll, saveParametric, scalingFactor, - elementStartNum, saveSinglePartition, multipleView, true); + if(version < 3.0) { + return _writeMSH2(name, version, binary, saveAll, saveParametric, + scalingFactor, elementStartNum, saveSinglePartition, + multipleView, true); } - else if(version < 4.0){ - return _writeMSH3(name, version, binary, saveAll, saveParametric, scalingFactor, - elementStartNum, saveSinglePartition, multipleView); + else if(version < 4.0) { + return _writeMSH3(name, version, binary, saveAll, saveParametric, + scalingFactor, elementStartNum, saveSinglePartition, + multipleView); } - else if(version < 5.0){ - return _writeMSH4(name, version, binary, saveAll, saveParametric, scalingFactor); + else if(version < 5.0) { + return _writeMSH4(name, version, binary, saveAll, saveParametric, + scalingFactor); } Msg::Error("Unknown MSH file version %g", version); @@ -106,20 +111,20 @@ int GModel::writePartitionedMSH(const std::string &baseName, double version, bool binary, bool saveAll, bool saveParametric, double scalingFactor) { - if(version < 4.0 && getNumPartitions() > 0){ + if(version < 4.0 && getNumPartitions() > 0) { Msg::Warning("Saving a partitioned mesh in a format older than 4.0 may " "cause information loss"); } - if(version < 3.0){ - return _writePartitionedMSH2(baseName, binary, saveAll, - saveParametric, scalingFactor); + if(version < 3.0) { + return _writePartitionedMSH2(baseName, binary, saveAll, saveParametric, + scalingFactor); } - else if(version < 4.0){ + else if(version < 4.0) { return _writePartitionedMSH3(baseName, version, binary, saveAll, saveParametric, scalingFactor); } - else if(version < 5.0){ + else if(version < 5.0) { return _writePartitionedMSH4(baseName, version, binary, saveAll, saveParametric, scalingFactor); } diff --git a/Geo/GModelIO_MSH2.cpp b/Geo/GModelIO_MSH2.cpp index 7df2c96281524580d305c109b135e1f44194bdbd..4c66bfde8e378b3b94f5ef69da4d9b62ca72c0fe 100644 --- a/Geo/GModelIO_MSH2.cpp +++ b/Geo/GModelIO_MSH2.cpp @@ -28,16 +28,17 @@ #include "OS.h" // periodic nodes and entities backported from MSH3 format -extern void writeMSHPeriodicNodes(FILE *fp, std::vector<GEntity*> &entities, +extern void writeMSHPeriodicNodes(FILE *fp, std::vector<GEntity *> &entities, bool renumber); extern void readMSHPeriodicNodes(FILE *fp, GModel *gm); extern void writeMSHEntities(FILE *fp, GModel *gm); -static bool getMeshVertices(int num, int *indices, std::map<int, MVertex*> &map, - std::vector<MVertex*> &vertices) +static bool getMeshVertices(int num, int *indices, + std::map<int, MVertex *> &map, + std::vector<MVertex *> &vertices) { - for(int i = 0; i < num; i++){ - if(!map.count(indices[i])){ + for(int i = 0; i < num; i++) { + if(!map.count(indices[i])) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -47,11 +48,12 @@ static bool getMeshVertices(int num, int *indices, std::map<int, MVertex*> &map, return true; } -static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, - std::vector<MVertex*> &vertices, int minVertex = 0) +static bool getMeshVertices(int num, int *indices, std::vector<MVertex *> &vec, + std::vector<MVertex *> &vertices, int minVertex = 0) { - for(int i = 0; i < num; i++){ - if(indices[i] < minVertex || indices[i] > (int)(vec.size() - 1 + minVertex)){ + for(int i = 0; i < num; i++) { + if(indices[i] < minVertex || + indices[i] > (int)(vec.size() - 1 + minVertex)) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -61,12 +63,13 @@ static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, return true; } -static MElement *createElementMSH2(GModel *m, int num, int typeMSH, int physical, - int reg, unsigned int part, std::vector<MVertex*> &v, - std::map<int, std::vector<MElement*> > elements[10], - std::map<int, std::map<int, std::string> > physicals[4], - bool owner=false, MElement *parent=0, - MElement *d1=0, MElement *d2=0) +static MElement * +createElementMSH2(GModel *m, int num, int typeMSH, int physical, int reg, + unsigned int part, std::vector<MVertex *> &v, + std::map<int, std::vector<MElement *> > elements[10], + std::map<int, std::map<int, std::string> > physicals[4], + bool owner = false, MElement *parent = 0, MElement *d1 = 0, + MElement *d2 = 0) { if(CTX::instance()->mesh.switchElementTags) { int tmp = reg; @@ -77,13 +80,14 @@ static MElement *createElementMSH2(GModel *m, int num, int typeMSH, int physical MElementFactory factory; MElement *e = factory.create(typeMSH, v, num, part, owner, 0, parent, d1, d2); - if(!e){ + if(!e) { Msg::Error("Unknown type of element %d", typeMSH); return NULL; } int dim = e->getDim(); - if(physical && (!physicals[dim].count(reg) || !physicals[dim][reg].count(physical))) + if(physical && + (!physicals[dim].count(reg) || !physicals[dim][reg].count(physical))) physicals[dim][reg][physical] = "unnamed"; if(part > m->getNumPartitions()) m->setNumPartitions(part); @@ -93,7 +97,7 @@ static MElement *createElementMSH2(GModel *m, int num, int typeMSH, int physical int GModel::_readMSH2(const std::string &name) { FILE *fp = Fopen(name.c_str(), "rb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -101,66 +105,85 @@ int GModel::_readMSH2(const std::string &name) char str[256] = "XXX"; double version = 1.0; bool binary = false, swap = false, postpro = false; - std::map<int, std::vector<MElement*> > elements[10]; + std::map<int, std::vector<MElement *> > elements[10]; std::map<int, std::map<int, std::string> > physicals[4]; - std::map<int, MVertex*> vertexMap; - std::vector<MVertex*> vertexVector; + std::map<int, MVertex *> vertexMap; + std::vector<MVertex *> vertexVector; int minVertex = 0; while(1) { - - while(str[0] != '$'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(str[0] != '$') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } - if(feof(fp)) - break; + if(feof(fp)) break; if(!strncmp(&str[1], "MeshFormat", 10)) { - - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int format, size; - if(sscanf(str, "%lf %d %d", &version, &format, &size) != 3){ + if(sscanf(str, "%lf %d %d", &version, &format, &size) != 3) { fclose(fp); return 0; } - if(format){ + if(format) { binary = true; Msg::Debug("Mesh is in binary format"); int one; - if(fread(&one, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(one != 1){ + if(fread(&one, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(one != 1) { swap = true; Msg::Debug("Swapping bytes from binary file"); } } - } else if(!strncmp(&str[1], "PhysicalNames", 13)) { - - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int numNames; - if(sscanf(str, "%d", &numNames) != 1){ fclose(fp); return 0; } + if(sscanf(str, "%d", &numNames) != 1) { + fclose(fp); + return 0; + } for(int i = 0; i < numNames; i++) { int dim = -1, num; - if(version > 2.0){ - if(fscanf(fp, "%d", &dim) != 1){ fclose(fp); return 0; } + if(version > 2.0) { + if(fscanf(fp, "%d", &dim) != 1) { + fclose(fp); + return 0; + } + } + if(fscanf(fp, "%d", &num) != 1) { + fclose(fp); + return 0; + } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; } - if(fscanf(fp, "%d", &num) != 1){ fclose(fp); return 0; } - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } std::string name = ExtractDoubleQuotedString(str, 256); if(name.size()) setPhysicalName(name, dim, num); } - } else if(!strncmp(&str[1], "NO", 2) || !strncmp(&str[1], "Nodes", 5) || !strncmp(&str[1], "ParametricNodes", 15)) { - const bool parametric = !strncmp(&str[1], "ParametricNodes", 15); - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int numVertices = -1; - if(sscanf(str, "%d", &numVertices) != 1){ fclose(fp); return 0; } + if(sscanf(str, "%d", &numVertices) != 1) { + fclose(fp); + return 0; + } Msg::Info("%d vertices", numVertices); Msg::ResetProgressMeter(); vertexVector.clear(); @@ -171,68 +194,100 @@ int GModel::_readMSH2(const std::string &name) int num; double xyz[3], uv[2]; MVertex *newVertex = 0; - if (!parametric){ - if(!binary){ - if (fscanf(fp, "%d %lf %lf %lf", &num, &xyz[0], &xyz[1], &xyz[2]) != 4){ + if(!parametric) { + if(!binary) { + if(fscanf(fp, "%d %lf %lf %lf", &num, &xyz[0], &xyz[1], &xyz[2]) != + 4) { fclose(fp); return 0; } } - else{ - if(fread(&num, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&num, sizeof(int), 1); - if(fread(xyz, sizeof(double), 3, fp) != 3){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)xyz, sizeof(double), 3); + else { + if(fread(&num, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&num, sizeof(int), 1); + if(fread(xyz, sizeof(double), 3, fp) != 3) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)xyz, sizeof(double), 3); } newVertex = new MVertex(xyz[0], xyz[1], xyz[2], 0, num); } - else{ + else { int iClasDim, iClasTag; - if(!binary){ - if (fscanf(fp, "%d %lf %lf %lf %d %d", &num, &xyz[0], &xyz[1], &xyz[2], - &iClasDim, &iClasTag) != 6){ + if(!binary) { + if(fscanf(fp, "%d %lf %lf %lf %d %d", &num, &xyz[0], &xyz[1], + &xyz[2], &iClasDim, &iClasTag) != 6) { fclose(fp); return 0; } } - else{ - if(fread(&num, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&num, sizeof(int), 1); - if(fread(xyz, sizeof(double), 3, fp) != 3){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)xyz, sizeof(double), 3); - if(fread(&iClasDim, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&iClasDim, sizeof(int), 1); - if(fread(&iClasTag, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&iClasTag, sizeof(int), 1); + else { + if(fread(&num, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&num, sizeof(int), 1); + if(fread(xyz, sizeof(double), 3, fp) != 3) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)xyz, sizeof(double), 3); + if(fread(&iClasDim, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&iClasDim, sizeof(int), 1); + if(fread(&iClasTag, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&iClasTag, sizeof(int), 1); } - if (iClasDim == 0){ + if(iClasDim == 0) { GVertex *gv = getVertexByTag(iClasTag); - if (gv) gv->mesh_vertices.clear(); + if(gv) gv->mesh_vertices.clear(); newVertex = new MVertex(xyz[0], xyz[1], xyz[2], gv, num); } - else if (iClasDim == 1){ + else if(iClasDim == 1) { GEdge *ge = getEdgeByTag(iClasTag); - if(!binary){ - if (fscanf(fp, "%lf", &uv[0]) != 1){ fclose(fp); return 0; } + if(!binary) { + if(fscanf(fp, "%lf", &uv[0]) != 1) { + fclose(fp); + return 0; + } } - else{ - if(fread(uv, sizeof(double), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)uv, sizeof(double), 1); + else { + if(fread(uv, sizeof(double), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)uv, sizeof(double), 1); } newVertex = new MEdgeVertex(xyz[0], xyz[1], xyz[2], ge, uv[0], num); } - else if (iClasDim == 2){ + else if(iClasDim == 2) { GFace *gf = getFaceByTag(iClasTag); - if(!binary){ - if (fscanf(fp, "%lf %lf", &uv[0], &uv[1]) != 2){ fclose(fp); return 0; } + if(!binary) { + if(fscanf(fp, "%lf %lf", &uv[0], &uv[1]) != 2) { + fclose(fp); + return 0; + } } - else{ - if(fread(uv, sizeof(double), 2, fp) != 2){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)uv, sizeof(double), 2); + else { + if(fread(uv, sizeof(double), 2, fp) != 2) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)uv, sizeof(double), 2); } - newVertex = new MFaceVertex(xyz[0], xyz[1], xyz[2], gf, uv[0], uv[1], num); + newVertex = + new MFaceVertex(xyz[0], xyz[1], xyz[2], gf, uv[0], uv[1], num); } - else if (iClasDim == 3){ + else if(iClasDim == 3) { GRegion *gr = getRegionByTag(iClasTag); newVertex = new MVertex(xyz[0], xyz[1], xyz[2], gr, num); } @@ -249,95 +304,121 @@ int GModel::_readMSH2(const std::string &name) // vector to speed up element creation if((int)vertexMap.size() == numVertices && ((minVertex == 1 && maxVertex == numVertices) || - (minVertex == 0 && maxVertex == numVertices - 1))){ + (minVertex == 0 && maxVertex == numVertices - 1))) { Msg::Debug("Vertex numbering is dense"); vertexVector.resize(vertexMap.size() + 1); if(minVertex == 1) vertexVector[0] = 0; else vertexVector[numVertices] = 0; - std::map<int, MVertex*>::const_iterator it = vertexMap.begin(); - for(; it != vertexMap.end(); ++it) - vertexVector[it->first] = it->second; + std::map<int, MVertex *>::const_iterator it = vertexMap.begin(); + for(; it != vertexMap.end(); ++it) vertexVector[it->first] = it->second; vertexMap.clear(); } - } else if(!strncmp(&str[1], "ELM", 3) || !strncmp(&str[1], "Elements", 8)) { - - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int numElements; - std::map<int, MElement*> elems; - std::map<int, MElement*> parents; - std::map<int, MElement*> domains; + std::map<int, MElement *> elems; + std::map<int, MElement *> parents; + std::map<int, MElement *> domains; std::map<int, int> elemreg; std::map<int, int> elemphy; - std::set<MElement*> parentsOwned; + std::set<MElement *> parentsOwned; sscanf(str, "%d", &numElements); Msg::Info("%d elements", numElements); Msg::ResetProgressMeter(); - if(!binary){ + if(!binary) { for(int i = 0; i < numElements; i++) { - int num, type, physical = 0, elementary = 0, partition = 0, parent = 0; + int num, type, physical = 0, elementary = 0, partition = 0, + parent = 0; int dom1 = 0, dom2 = 0, numVertices; std::vector<short> ghosts; - if(version <= 1.0){ + if(version <= 1.0) { if(fscanf(fp, "%d %d %d %d %d", &num, &type, &physical, &elementary, - &numVertices) != 5){ + &numVertices) != 5) { + fclose(fp); + return 0; + } + if(numVertices != (int)MElement::getInfoMSH(type)) { fclose(fp); return 0; } - if(numVertices != (int)MElement::getInfoMSH(type)){ fclose(fp); return 0; } } - else{ + else { int numTags; - if(fscanf(fp, "%d %d %d", &num, &type, &numTags) != 3){ fclose(fp); return 0; } + if(fscanf(fp, "%d %d %d", &num, &type, &numTags) != 3) { + fclose(fp); + return 0; + } int numPartitions = 0; - for(int j = 0; j < numTags; j++){ + for(int j = 0; j < numTags; j++) { int tag; - if(fscanf(fp, "%d", &tag) != 1){ fclose(fp); return 0; } - if(j == 0) physical = tag; - else if(j == 1) elementary = tag; - else if(version < 2.2 && j == 2) partition = tag; - else if(version >= 2.2 && j == 2 && numTags > 3) numPartitions = tag; - else if(version >= 2.2 && j == 3) partition = tag; - else if(j >= 4 && j < 4 + numPartitions - 1) ghosts.push_back(-tag); + if(fscanf(fp, "%d", &tag) != 1) { + fclose(fp); + return 0; + } + if(j == 0) + physical = tag; + else if(j == 1) + elementary = tag; + else if(version < 2.2 && j == 2) + partition = tag; + else if(version >= 2.2 && j == 2 && numTags > 3) + numPartitions = tag; + else if(version >= 2.2 && j == 3) + partition = tag; + else if(j >= 4 && j < 4 + numPartitions - 1) + ghosts.push_back(-tag); else if(j == 3 + numPartitions && (numTags == 4 + numPartitions)) parent = tag; - else if(j == 3 + numPartitions && (numTags == 5 + numPartitions)) { - dom1 = tag; j++; - if(fscanf(fp, "%d", &dom2) != 1){ fclose(fp); return 0; } + else if(j == 3 + numPartitions && + (numTags == 5 + numPartitions)) { + dom1 = tag; + j++; + if(fscanf(fp, "%d", &dom2) != 1) { + fclose(fp); + return 0; + } } } if(!(numVertices = MElement::getInfoMSH(type))) { - if(type != MSH_POLYG_ && type != MSH_POLYH_ && type != MSH_POLYG_B){ + if(type != MSH_POLYG_ && type != MSH_POLYH_ && + type != MSH_POLYG_B) { + fclose(fp); + return 0; + } + if(fscanf(fp, "%d", &numVertices) != 1) { fclose(fp); return 0; } - if(fscanf(fp, "%d", &numVertices) != 1){ fclose(fp); return 0; } } } int *indices = new int[numVertices]; - for(int j = 0; j < numVertices; j++){ - if(fscanf(fp, "%d", &indices[j]) != 1){ - delete [] indices; + for(int j = 0; j < numVertices; j++) { + if(fscanf(fp, "%d", &indices[j]) != 1) { + delete[] indices; fclose(fp); return 0; } } - std::vector<MVertex*> vertices; - if(vertexVector.size()){ - if(!getMeshVertices(numVertices, indices, vertexVector, vertices, minVertex)){ - delete [] indices; + std::vector<MVertex *> vertices; + if(vertexVector.size()) { + if(!getMeshVertices(numVertices, indices, vertexVector, vertices, + minVertex)) { + delete[] indices; fclose(fp); return 0; } } - else{ - if(!getMeshVertices(numVertices, indices, vertexMap, vertices)){ - delete [] indices; + else { + if(!getMeshVertices(numVertices, indices, vertexMap, vertices)) { + delete[] indices; fclose(fp); return 0; } @@ -345,63 +426,69 @@ int GModel::_readMSH2(const std::string &name) MElement *p = NULL; bool own = false; - // search parent element - if (parent != 0){ - std::map<int, MElement* >::iterator ite = elems.find(parent); - if (ite == elems.end()) - Msg::Error("Parent element (ascii) %d not found for element %d of type %d", - parent, num, type); - else{ + // search parent element + if(parent != 0) { + std::map<int, MElement *>::iterator ite = elems.find(parent); + if(ite == elems.end()) + Msg::Error( + "Parent element (ascii) %d not found for element %d of type %d", + parent, num, type); + else { p = ite->second; parents[parent] = p; } - std::set<MElement* >::iterator itpo = parentsOwned.find(p); - if (itpo == parentsOwned.end()){ + std::set<MElement *>::iterator itpo = parentsOwned.find(p); + if(itpo == parentsOwned.end()) { own = true; parentsOwned.insert(p); } assert(p != NULL); - } + } // search domains MElement *doms[2] = {NULL, NULL}; - if(dom1){ - std::map<int, MElement* >::iterator ite = elems.find(dom1); - if (ite == elems.end()) - Msg::Error("Domain element %d not found for element %d", dom1, num); + if(dom1) { + std::map<int, MElement *>::iterator ite = elems.find(dom1); + if(ite == elems.end()) + Msg::Error("Domain element %d not found for element %d", dom1, + num); else doms[0] = ite->second; - ite = elems.find(dom2); - if (ite != elems.end()) - doms[1] = ite->second; + ite = elems.find(dom2); + if(ite != elems.end()) doms[1] = ite->second; if(!doms[0]) - Msg::Error("Domain element %d not found for element %d", dom1, num); + Msg::Error("Domain element %d not found for element %d", dom1, + num); if(dom2 && !doms[1]) - Msg::Error("Domain element %d not found for element %d", dom2, num); - } - delete [] indices; + Msg::Error("Domain element %d not found for element %d", dom2, + num); + } + delete[] indices; - if (elementary<0) continue; + if(elementary < 0) continue; MElement *e = createElementMSH2(this, num, type, physical, elementary, - partition, vertices, elements, physicals, - own, p, doms[0], doms[1]); - elems[num] = e; - elemreg[num] = elementary; - elemphy[num] = physical; + partition, vertices, elements, + physicals, own, p, doms[0], doms[1]); + elems[num] = e; + elemreg[num] = elementary; + elemphy[num] = physical; for(unsigned int j = 0; j < ghosts.size(); j++) - _ghostCells.insert(std::pair<MElement*, short>(e, ghosts[j])); + _ghostCells.insert(std::pair<MElement *, short>(e, ghosts[j])); if(numElements > 100000) Msg::ProgressMeter(i + 1, numElements, true, "Reading elements"); } } - else{ + else { int numElementsPartial = 0; - while(numElementsPartial < numElements){ + while(numElementsPartial < numElements) { int header[3]; - if(fread(header, sizeof(int), 3, fp) != 3){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)header, sizeof(int), 3); + if(fread(header, sizeof(int), 3, fp) != 3) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)header, sizeof(int), 3); int type = header[0]; int numElms = header[1]; int numTags = header[2]; @@ -409,100 +496,105 @@ int GModel::_readMSH2(const std::string &name) unsigned int n = 1 + numTags + numVertices; int *data = new int[n]; for(int i = 0; i < numElms; i++) { - if(fread(data, sizeof(int), n, fp) != n){ - delete [] data; + if(fread(data, sizeof(int), n, fp) != n) { + delete[] data; fclose(fp); return 0; } - if(swap) SwapBytes((char*)data, sizeof(int), n); + if(swap) SwapBytes((char *)data, sizeof(int), n); int num = data[0]; int physical = (numTags > 0) ? data[1] : 0; int elementary = (numTags > 1) ? data[2] : 0; int numPartitions = (version >= 2.2 && numTags > 3) ? data[3] : 0; - int partition = (version < 2.2 && numTags > 2) ? data[3] : - (version >= 2.2 && numTags > 3) ? data[4] : 0; + int partition = (version < 2.2 && numTags > 2) ? + data[3] : + (version >= 2.2 && numTags > 3) ? data[4] : 0; int parent = (version < 2.2 && numTags > 3) || - (version >= 2.2 && numPartitions && numTags > 3 + numPartitions) || - (version >= 2.2 && !numPartitions && numTags > 2) ? - data[numTags] : 0; + (version >= 2.2 && numPartitions && + numTags > 3 + numPartitions) || + (version >= 2.2 && !numPartitions && numTags > 2) ? + data[numTags] : + 0; int *indices = &data[numTags + 1]; - std::vector<MVertex*> vertices; - if(vertexVector.size()){ - if(!getMeshVertices(numVertices, indices, vertexVector, vertices, minVertex)){ - delete [] data; + std::vector<MVertex *> vertices; + if(vertexVector.size()) { + if(!getMeshVertices(numVertices, indices, vertexVector, vertices, + minVertex)) { + delete[] data; fclose(fp); return 0; } } - else{ - if(!getMeshVertices(numVertices, indices, vertexMap, vertices)){ - delete [] data; + else { + if(!getMeshVertices(numVertices, indices, vertexMap, vertices)) { + delete[] data; fclose(fp); return 0; } } MElement *p = NULL; bool own = false; - if(parent){ - std::map<int, MElement* >::iterator ite = elems.find(parent); - if (ite == elems.end()) - Msg::Error("Parent (binary) element %d not found for element %d", - parent, num); - else{ + if(parent) { + std::map<int, MElement *>::iterator ite = elems.find(parent); + if(ite == elems.end()) + Msg::Error( + "Parent (binary) element %d not found for element %d", parent, + num); + else { p = ite->second; parents[parent] = p; - } - std::set<MElement* >::iterator itpo = parentsOwned.find(p); - if (itpo == parentsOwned.end()){ + } + std::set<MElement *>::iterator itpo = parentsOwned.find(p); + if(itpo == parentsOwned.end()) { own = true; parentsOwned.insert(p); - } - assert(p != NULL); + } + assert(p != NULL); } - MElement *e = createElementMSH2(this, num, type, physical, elementary, - partition, vertices, elements, physicals, - own, p); + MElement *e = createElementMSH2(this, num, type, physical, + elementary, partition, vertices, + elements, physicals, own, p); elems[num] = e; elemreg[num] = elementary; elemphy[num] = physical; if(numPartitions > 1) for(int j = 0; j < numPartitions - 1; j++) - _ghostCells.insert(std::pair<MElement*, short>(e, -data[5 + j])); + _ghostCells.insert( + std::pair<MElement *, short>(e, -data[5 + j])); if(numElements > 100000) Msg::ProgressMeter(numElementsPartial + i + 1, numElements, true, "Reading elements"); } - delete [] data; + delete[] data; numElementsPartial += numElms; } } - for(int i = 0; i < 10; i++) - elements[i].clear(); + for(int i = 0; i < 10; i++) elements[i].clear(); - std::map<int, MElement* >::iterator ite; - for (ite = elems.begin(); ite != elems.end(); ite++){ + std::map<int, MElement *>::iterator ite; + for(ite = elems.begin(); ite != elems.end(); ite++) { int num = ite->first; MElement *e = ite->second; - if (parents.find(num) == parents.end()){ + if(parents.find(num) == parents.end()) { int reg; - if (CTX::instance()->mesh.switchElementTags) { + if(CTX::instance()->mesh.switchElementTags) { reg = elemphy[num]; } - else{ + else { reg = elemreg[num]; } - switch (e->getType()){ - case TYPE_PNT : elements[0][reg].push_back(e); break; - case TYPE_LIN : elements[1][reg].push_back(e); break; - case TYPE_TRI : elements[2][reg].push_back(e); break; - case TYPE_QUA : elements[3][reg].push_back(e); break; - case TYPE_TET : elements[4][reg].push_back(e); break; - case TYPE_HEX : elements[5][reg].push_back(e); break; - case TYPE_PRI : elements[6][reg].push_back(e); break; - case TYPE_PYR : elements[7][reg].push_back(e); break; - case TYPE_POLYG : elements[8][reg].push_back(e); break; - case TYPE_POLYH : elements[9][reg].push_back(e); break; - default : + switch(e->getType()) { + case TYPE_PNT: elements[0][reg].push_back(e); break; + case TYPE_LIN: elements[1][reg].push_back(e); break; + case TYPE_TRI: elements[2][reg].push_back(e); break; + case TYPE_QUA: elements[3][reg].push_back(e); break; + case TYPE_TET: elements[4][reg].push_back(e); break; + case TYPE_HEX: elements[5][reg].push_back(e); break; + case TYPE_PRI: elements[6][reg].push_back(e); break; + case TYPE_PYR: elements[7][reg].push_back(e); break; + case TYPE_POLYG: elements[8][reg].push_back(e); break; + case TYPE_POLYH: elements[9][reg].push_back(e); break; + default: Msg::Error("Wrong type of element"); fclose(fp); return 0; @@ -511,7 +603,6 @@ int GModel::_readMSH2(const std::string &name) } } else if(!strncmp(&str[1], "NodeData", 8)) { - // there's some nodal post-processing data to read later on, so // cache the vertex indexing data if(vertexVector.size()) @@ -523,15 +614,13 @@ int GModel::_readMSH2(const std::string &name) } else if(!strncmp(&str[1], "ElementData", 11) || !strncmp(&str[1], "ElementNodeData", 15)) { - // there's some element post-processing data to read later on postpro = true; break; } do { - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } while(str[0] != '$'); } @@ -550,33 +639,28 @@ int GModel::_readMSH2(const std::string &name) _storeVerticesInEntities(vertexMap); // store the physical tags - for(int i = 0; i < 4; i++) - _storePhysicalTagsInEntities(i, physicals[i]); + for(int i = 0; i < 4; i++) _storePhysicalTagsInEntities(i, physicals[i]); - _createGeometryOfDiscreteEntities() ; + _createGeometryOfDiscreteEntities(); // copying periodic information from the mesh if(!CTX::instance()->mesh.ignorePeriodicity) { - rewind(fp); while(1) { - - while(str[0] != '$'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(str[0] != '$') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } - if(feof(fp)) - break; + if(feof(fp)) break; - if(!strncmp(&str[1], "Periodic",8) && strncmp(&str[1],"PeriodicNodes",13)) { - readMSHPeriodicNodes(fp,this); + if(!strncmp(&str[1], "Periodic", 8) && + strncmp(&str[1], "PeriodicNodes", 13)) { + readMSHPeriodicNodes(fp, this); break; } do { - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } while(str[0] != '$'); } } @@ -588,28 +672,28 @@ int GModel::_readMSH2(const std::string &name) return postpro ? 2 : 1; } -template<class T> +template <class T> static void writeElementMSH(FILE *fp, GModel *model, T *ele, bool saveAll, - double version, bool binary, int &num, int elementary, - std::vector<int> &physicals, int parentNum = 0, - int dom1Num = 0, int dom2Num = 0) + double version, bool binary, int &num, + int elementary, std::vector<int> &physicals, + int parentNum = 0, int dom1Num = 0, int dom2Num = 0) { std::vector<short> ghosts; - if(model->getGhostCells().size()){ - std::pair<std::multimap<MElement*, short>::iterator, - std::multimap<MElement*, short>::iterator> itp = - model->getGhostCells().equal_range(ele); - for(std::multimap<MElement*, short>::iterator it = itp.first; + if(model->getGhostCells().size()) { + std::pair<std::multimap<MElement *, short>::iterator, + std::multimap<MElement *, short>::iterator> + itp = model->getGhostCells().equal_range(ele); + for(std::multimap<MElement *, short>::iterator it = itp.first; it != itp.second; it++) ghosts.push_back(it->second); } if(saveAll) - ele->writeMSH2(fp, version, binary, ++num, elementary, 0, - parentNum, dom1Num, dom2Num, &ghosts); - else{ + ele->writeMSH2(fp, version, binary, ++num, elementary, 0, parentNum, + dom1Num, dom2Num, &ghosts); + else { if(parentNum) parentNum = parentNum - physicals.size() + 1; - for(unsigned int j = 0; j < physicals.size(); j++){ + for(unsigned int j = 0; j < physicals.size(); j++) { ele->writeMSH2(fp, version, binary, ++num, elementary, physicals[j], parentNum, dom1Num, dom2Num, &ghosts); if(parentNum) parentNum++; @@ -622,26 +706,27 @@ static void writeElementMSH(FILE *fp, GModel *model, T *ele, bool saveAll, num += ele->getNumChildren() - 1; } -template<class T> -static void writeElementsMSH(FILE *fp, GModel *model, std::vector<T*> &ele, - bool saveAll, int saveSinglePartition, double version, - bool binary, int &num, int elementary, - std::vector<int> &physicals) +template <class T> +static void writeElementsMSH(FILE *fp, GModel *model, std::vector<T *> &ele, + bool saveAll, int saveSinglePartition, + double version, bool binary, int &num, + int elementary, std::vector<int> &physicals) { // Hack to save each partition as a separate physical entity - if(saveSinglePartition < 0){ + if(saveSinglePartition < 0) { if(ele.empty()) return; int offset = -saveSinglePartition; int maxPhysical = model->getMaxPhysicalNumber(ele[0]->getDim()); - for(unsigned int i = 0; i < ele.size(); i++){ + for(unsigned int i = 0; i < ele.size(); i++) { std::vector<int> newPhysicals; int newElementary = elementary; - if(elementary > 0){ // classical entity + if(elementary > 0) { // classical entity newElementary = elementary * offset + ele[i]->getPartition(); for(unsigned int j = 0; j < physicals.size(); j++) - newPhysicals.push_back(physicals[j] * offset + ele[i]->getPartition()); + newPhysicals.push_back(physicals[j] * offset + + ele[i]->getPartition()); } - else if(elementary < 0){ // partition boundary + else if(elementary < 0) { // partition boundary newPhysicals.push_back((maxPhysical - elementary) * offset); } ele[i]->setPartition(0); @@ -651,15 +736,13 @@ static void writeElementsMSH(FILE *fp, GModel *model, std::vector<T*> &ele, return; } - for(unsigned int i = 0; i < ele.size(); i++){ + for(unsigned int i = 0; i < ele.size(); i++) { if(saveSinglePartition && ele[i]->getPartition() != saveSinglePartition) continue; - if(ele[i]->getDomain(0)) - continue; + if(ele[i]->getDomain(0)) continue; int parentNum = 0; MElement *parent = ele[i]->getParent(); - if(parent) - parentNum = model->getMeshElementIndex(parent); + if(parent) parentNum = model->getMeshElementIndex(parent); writeElementMSH(fp, model, ele[i], saveAll, version, binary, num, elementary, physicals, parentNum); } @@ -675,39 +758,38 @@ static int getNumElementsMSH(GEntity *ge, bool saveAll, int saveSinglePartition) n = p * ge->getNumMeshElements(); else for(unsigned int i = 0; i < ge->getNumMeshElements(); i++) - if(ge->getMeshElement(i)->getPartition() == saveSinglePartition) - n += p; + if(ge->getMeshElement(i)->getPartition() == saveSinglePartition) n += p; return n; } static int getNumElementsMSH(GModel *m, bool saveAll, int saveSinglePartition) { int n = 0; - for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); ++it){ + for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); ++it) { n += getNumElementsMSH(*it, saveAll, saveSinglePartition); - if(!CTX::instance()->mesh.saveTri){ + if(!CTX::instance()->mesh.saveTri) { for(unsigned int i = 0; i < (*it)->points.size(); i++) if((*it)->points[i]->ownsParent()) n += (saveAll ? 1 : (*it)->physicals.size()); } } - for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it){ + for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it) { n += getNumElementsMSH(*it, saveAll, saveSinglePartition); - if(!CTX::instance()->mesh.saveTri){ + if(!CTX::instance()->mesh.saveTri) { for(unsigned int i = 0; i < (*it)->lines.size(); i++) if((*it)->lines[i]->ownsParent()) n += (saveAll ? 1 : (*it)->physicals.size()); } } - for(GModel::fiter it = m->firstFace(); it != m->lastFace(); ++it){ + for(GModel::fiter it = m->firstFace(); it != m->lastFace(); ++it) { n += getNumElementsMSH(*it, saveAll, saveSinglePartition); - if(CTX::instance()->mesh.saveTri){ - for(unsigned int i = 0; i < (*it)->polygons.size(); i++){ - int nbC = (*it)->polygons[i]->getNumChildren()-1; + if(CTX::instance()->mesh.saveTri) { + for(unsigned int i = 0; i < (*it)->polygons.size(); i++) { + int nbC = (*it)->polygons[i]->getNumChildren() - 1; n += (saveAll ? nbC : nbC * (*it)->physicals.size()); } } - else{ + else { for(unsigned int i = 0; i < (*it)->triangles.size(); i++) if((*it)->triangles[i]->ownsParent()) n += (saveAll ? 1 : (*it)->physicals.size()); @@ -716,15 +798,15 @@ static int getNumElementsMSH(GModel *m, bool saveAll, int saveSinglePartition) n += (saveAll ? 1 : (*it)->physicals.size()); } } - for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){ + for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it) { n += getNumElementsMSH(*it, saveAll, saveSinglePartition); - if(CTX::instance()->mesh.saveTri){ - for(unsigned int i = 0; i < (*it)->polyhedra.size(); i++){ - int nbC = (*it)->polyhedra[i]->getNumChildren()-1; + if(CTX::instance()->mesh.saveTri) { + for(unsigned int i = 0; i < (*it)->polyhedra.size(); i++) { + int nbC = (*it)->polyhedra[i]->getNumChildren() - 1; n += (saveAll ? nbC : nbC * (*it)->physicals.size()); } } - else{ + else { for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) if((*it)->tetrahedra[i]->ownsParent()) n += (saveAll ? 1 : (*it)->physicals.size()); @@ -739,29 +821,29 @@ static int getNumElementsMSH(GModel *m, bool saveAll, int saveSinglePartition) static int _getElementary(GEntity *ge) { - if(CTX::instance()->mesh.partitionOldStyleMsh2 && - ge->getParentEntity() && ge->getParentEntity()->dim() == ge->dim()){ + if(CTX::instance()->mesh.partitionOldStyleMsh2 && ge->getParentEntity() && + ge->getParentEntity()->dim() == ge->dim()) { // hack for backward compatibility of partitioned meshes in MSH2 format: use // elementary tag of parent entity if they are of the same dimension // (i.e. if they are not partition boundaries) return ge->getParentEntity()->tag(); } - else{ + else { return ge->tag(); } } int GModel::_writeMSH2(const std::string &name, double version, bool binary, bool saveAll, bool saveParametric, double scalingFactor, - int elementStartNum, int saveSinglePartition, bool multipleView, - bool renumberVertices) + int elementStartNum, int saveSinglePartition, + bool multipleView, bool renumberVertices) { FILE *fp; if(multipleView) fp = Fopen(name.c_str(), binary ? "ab" : "a"); else fp = Fopen(name.c_str(), binary ? "wb" : "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -778,25 +860,26 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary, // get the number of vertices and index the vertices in a continuous // sequence - int numVertices = indexMeshVertices(saveAll, saveSinglePartition, renumberVertices); + int numVertices = + indexMeshVertices(saveAll, saveSinglePartition, renumberVertices); // get the number of elements we need to save int numElements = getNumElementsMSH(this, saveAll, saveSinglePartition); - if(version >= 2.0){ + if(version >= 2.0) { fprintf(fp, "$MeshFormat\n"); fprintf(fp, "%g %d %d\n", version, binary ? 1 : 0, (int)sizeof(double)); - if(binary){ + if(binary) { int one = 1; fwrite(&one, sizeof(int), 1, fp); fprintf(fp, "\n"); } fprintf(fp, "$EndMeshFormat\n"); - if(numPhysicalNames()){ + if(numPhysicalNames()) { fprintf(fp, "$PhysicalNames\n"); fprintf(fp, "%d\n", numPhysicalNames()); - for(piter it = firstPhysicalName(); it != lastPhysicalName(); it++){ + for(piter it = firstPhysicalName(); it != lastPhysicalName(); it++) { std::string name = it->second; if(name.size() > 128) name.resize(128); fprintf(fp, "%d %d \"%s\"\n", it->first.first, it->first.second, @@ -805,10 +888,9 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary, fprintf(fp, "$EndPhysicalNames\n"); } - if (CTX::instance()->mesh.saveTopology) - writeMSHEntities(fp, this); + if(CTX::instance()->mesh.saveTopology) writeMSHEntities(fp, this); - if (saveParametric) + if(saveParametric) fprintf(fp, "$ParametricNodes\n"); else fprintf(fp, "$Nodes\n"); @@ -818,7 +900,7 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary, fprintf(fp, "%d\n", numVertices); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) @@ -827,14 +909,14 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary, if(binary) fprintf(fp, "\n"); - if(version >= 2.0){ + if(version >= 2.0) { if(saveParametric) fprintf(fp, "$EndParametricNodes\n"); else fprintf(fp, "$EndNodes\n"); fprintf(fp, "$Elements\n"); } - else{ + else { fprintf(fp, "$ENDNOD\n"); fprintf(fp, "$ELM\n"); } @@ -844,110 +926,110 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary, _elementIndexCache.clear(); - //parents - if (!CTX::instance()->mesh.saveTri){ - for(viter it = firstVertex(); it != lastVertex(); ++it){ + // parents + if(!CTX::instance()->mesh.saveTri) { + for(viter it = firstVertex(); it != lastVertex(); ++it) { for(unsigned int i = 0; i < (*it)->points.size(); i++) if((*it)->points[i]->ownsParent()) - writeElementMSH(fp, this, (*it)->points[i]->getParent(), - saveAll, version, binary, num, - _getElementary(*it), (*it)->physicals); + writeElementMSH(fp, this, (*it)->points[i]->getParent(), saveAll, + version, binary, num, _getElementary(*it), + (*it)->physicals); } - for(eiter it = firstEdge(); it != lastEdge(); ++it){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { for(unsigned int i = 0; i < (*it)->lines.size(); i++) if((*it)->lines[i]->ownsParent()) - writeElementMSH(fp, this, (*it)->lines[i]->getParent(), - saveAll, version, binary, num, - _getElementary(*it), (*it)->physicals); + writeElementMSH(fp, this, (*it)->lines[i]->getParent(), saveAll, + version, binary, num, _getElementary(*it), + (*it)->physicals); } - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { for(unsigned int i = 0; i < (*it)->triangles.size(); i++) if((*it)->triangles[i]->ownsParent()) - writeElementMSH(fp, this, (*it)->triangles[i]->getParent(), - saveAll, version, binary, num, - _getElementary(*it), (*it)->physicals); + writeElementMSH(fp, this, (*it)->triangles[i]->getParent(), saveAll, + version, binary, num, _getElementary(*it), + (*it)->physicals); } - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) if((*it)->tetrahedra[i]->ownsParent()) - writeElementMSH(fp, this, (*it)->tetrahedra[i]->getParent(), - saveAll, version, binary, num, - _getElementary(*it), (*it)->physicals); + writeElementMSH(fp, this, (*it)->tetrahedra[i]->getParent(), saveAll, + version, binary, num, _getElementary(*it), + (*it)->physicals); } - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { for(unsigned int i = 0; i < (*it)->polygons.size(); i++) if((*it)->polygons[i]->ownsParent()) - writeElementMSH(fp, this, (*it)->polygons[i]->getParent(), - saveAll, version, binary, num, - _getElementary(*it), (*it)->physicals); + writeElementMSH(fp, this, (*it)->polygons[i]->getParent(), saveAll, + version, binary, num, _getElementary(*it), + (*it)->physicals); } - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { for(unsigned int i = 0; i < (*it)->polyhedra.size(); i++) if((*it)->polyhedra[i]->ownsParent()) - writeElementMSH(fp, this, (*it)->polyhedra[i]->getParent(), - saveAll, version, binary, num, - _getElementary(*it), (*it)->physicals); + writeElementMSH(fp, this, (*it)->polyhedra[i]->getParent(), saveAll, + version, binary, num, _getElementary(*it), + (*it)->physicals); } } // points - for(viter it = firstVertex(); it != lastVertex(); ++it){ + for(viter it = firstVertex(); it != lastVertex(); ++it) { writeElementsMSH(fp, this, (*it)->points, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // lines - for(eiter it = firstEdge(); it != lastEdge(); ++it){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { writeElementsMSH(fp, this, (*it)->lines, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // triangles - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { writeElementsMSH(fp, this, (*it)->triangles, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // quads - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { writeElementsMSH(fp, this, (*it)->quadrangles, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // polygons - for(fiter it = firstFace(); it != lastFace(); it++){ + for(fiter it = firstFace(); it != lastFace(); it++) { writeElementsMSH(fp, this, (*it)->polygons, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // tets - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { writeElementsMSH(fp, this, (*it)->tetrahedra, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // hexas - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { writeElementsMSH(fp, this, (*it)->hexahedra, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // prisms - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { writeElementsMSH(fp, this, (*it)->prisms, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // pyramids - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { writeElementsMSH(fp, this, (*it)->pyramids, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // polyhedra - for(riter it = firstRegion(); it != lastRegion(); ++it){ + for(riter it = firstRegion(); it != lastRegion(); ++it) { writeElementsMSH(fp, this, (*it)->polyhedra, saveAll, saveSinglePartition, - version, binary, num, - _getElementary(*it), (*it)->physicals); + version, binary, num, _getElementary(*it), + (*it)->physicals); } // level set faces for(fiter it = firstFace(); it != lastFace(); ++it) { @@ -982,10 +1064,10 @@ int GModel::_writeMSH2(const std::string &name, double version, bool binary, if(binary) fprintf(fp, "\n"); - if(version >= 2.0){ + if(version >= 2.0) { fprintf(fp, "$EndElements\n"); } - else{ + else { fprintf(fp, "$ENDELM\n"); } @@ -1002,15 +1084,17 @@ int GModel::_writePartitionedMSH2(const std::string &baseName, bool binary, { int numElements; int startNum = 0; - for(unsigned int partition = 1; partition <= getNumPartitions(); partition++){ - + for(unsigned int partition = 1; partition <= getNumPartitions(); + partition++) { std::ostringstream sstream; sstream << baseName << "_" << partition << ".msh"; numElements = getNumElementsMSH(this, saveAll, partition); - Msg::Info("Writing partition %d in file '%s'", partition, sstream.str().c_str()); + Msg::Info("Writing partition %d in file '%s'", partition, + sstream.str().c_str()); _writeMSH2(sstream.str(), 2.2, binary, saveAll, saveParametric, - scalingFactor, startNum, partition, false, false); // NO RENUMBERING! + scalingFactor, startNum, partition, false, + false); // NO RENUMBERING! startNum += numElements; // update for next iteration in the loop } diff --git a/Geo/GModelIO_MSH3.cpp b/Geo/GModelIO_MSH3.cpp index e1f35f4e8e3062645b330af0657a577a230232b4..59f224d70509d749a8a98a3e823be878dbbfb6cb 100644 --- a/Geo/GModelIO_MSH3.cpp +++ b/Geo/GModelIO_MSH3.cpp @@ -29,7 +29,7 @@ static int readMSHPhysicals(FILE *fp, GEntity *ge) { int nump; if(fscanf(fp, "%d", &nump) != 1) return 0; - for(int i = 0; i < nump; i++){ + for(int i = 0; i < nump; i++) { int tag; if(fscanf(fp, "%d", &tag) != 1) return 0; ge->physicals.push_back(tag); @@ -42,26 +42,26 @@ static void readMSHEntities(FILE *fp, GModel *gm) int nv, ne, nf, nr; int tag; if(fscanf(fp, "%d %d %d %d", &nv, &ne, &nf, &nr) != 4) return; - for (int i = 0; i < nv; i++){ + for(int i = 0; i < nv; i++) { if(fscanf(fp, "%d", &tag) != 1) return; GVertex *gv = gm->getVertexByTag(tag); - if (!gv){ + if(!gv) { gv = new discreteVertex(gm, tag); gm->add(gv); } if(!readMSHPhysicals(fp, gv)) return; } - for (int i = 0; i < ne; i++){ + for(int i = 0; i < ne; i++) { int n; if(fscanf(fp, "%d %d", &tag, &n) != 2) return; GEdge *ge = gm->getEdgeByTag(tag); - if (!ge){ + if(!ge) { GVertex *v1 = 0, *v2 = 0; - for(int j = 0; j < n; j++){ + for(int j = 0; j < n; j++) { int tagv; if(fscanf(fp, "%d", &tagv) != 1) return; GVertex *v = gm->getVertexByTag(tagv); - if (!v) Msg::Error("Unknown GVertex %d", tagv); + if(!v) Msg::Error("Unknown GVertex %d", tagv); if(j == 0) v1 = v; if(j == 1) v2 = v; } @@ -70,17 +70,17 @@ static void readMSHEntities(FILE *fp, GModel *gm) } if(!readMSHPhysicals(fp, ge)) return; } - for (int i = 0; i < nf; i++){ + for(int i = 0; i < nf; i++) { int n; if(fscanf(fp, "%d %d", &tag, &n) != 2) return; GFace *gf = gm->getFaceByTag(tag); - if (!gf){ + if(!gf) { discreteFace *df = new discreteFace(gm, tag); std::vector<int> edges, signs; - for (int j = 0; j < n; j++){ - int tage; - if(fscanf(fp, "%d", &tage) != 1) return; - edges.push_back(std::abs(tage)); + for(int j = 0; j < n; j++) { + int tage; + if(fscanf(fp, "%d", &tage) != 1) return; + edges.push_back(std::abs(tage)); int sign = tage > 0 ? 1 : -1; signs.push_back(sign); } @@ -90,17 +90,17 @@ static void readMSHEntities(FILE *fp, GModel *gm) } if(!readMSHPhysicals(fp, gf)) return; } - for (int i = 0; i < nr; i++){ + for(int i = 0; i < nr; i++) { int n; if(fscanf(fp, "%d %d", &tag, &n) != 2) return; GRegion *gr = gm->getRegionByTag(tag); - if (!gr){ + if(!gr) { discreteRegion *dr = new discreteRegion(gm, tag); std::vector<int> faces, signs; - for (int j = 0; j < n; j++){ - int tagf; - if(fscanf(fp, "%d", &tagf) != 1) return; - faces.push_back(std::abs(tagf)); + for(int j = 0; j < n; j++) { + int tagf; + if(fscanf(fp, "%d", &tagf) != 1) return; + faces.push_back(std::abs(tagf)); int sign = tagf > 0 ? 1 : -1; signs.push_back(sign); } @@ -116,19 +116,29 @@ void readMSHPeriodicNodes(FILE *fp, GModel *gm) // also used in MSH2 { int count; if(fscanf(fp, "%d", &count) != 1) return; - for(int i = 0; i < count; i++){ + for(int i = 0; i < count; i++) { int dim, slave, master; if(fscanf(fp, "%d %d %d", &dim, &slave, &master) != 3) continue; GEntity *s = 0, *m = 0; - switch(dim){ - case 0 : s = gm->getVertexByTag(slave); m = gm->getVertexByTag(master); break; - case 1 : s = gm->getEdgeByTag(slave); m = gm->getEdgeByTag(master); break; - case 2 : s = gm->getFaceByTag(slave); m = gm->getFaceByTag(master); break; + switch(dim) { + case 0: + s = gm->getVertexByTag(slave); + m = gm->getVertexByTag(master); + break; + case 1: + s = gm->getEdgeByTag(slave); + m = gm->getEdgeByTag(master); + break; + case 2: + s = gm->getFaceByTag(slave); + m = gm->getFaceByTag(master); + break; } - // we need to continue parsing, otherwise we end up reading on the wrong position + // we need to continue parsing, otherwise we end up reading on the wrong + // position bool completePer = s && m; @@ -138,7 +148,7 @@ void readMSHPeriodicNodes(FILE *fp, GModel *gm) // also used in MSH2 if(fscanf(fp, "%s", token) != 1) return; if(strcmp(token, "Affine") == 0) { std::vector<double> tfo(16); - for(int i = 0; i < 16; i++){ + for(int i = 0; i < 16; i++) { if(fscanf(fp, "%lf", &tfo[i]) != 1) return; } if(completePer) s->setMeshMaster(m, tfo); @@ -149,18 +159,18 @@ void readMSHPeriodicNodes(FILE *fp, GModel *gm) // also used in MSH2 } int numv; if(fscanf(fp, "%d", &numv) != 1) numv = 0; - for(int j = 0; j < numv; j++){ + for(int j = 0; j < numv; j++) { int v1, v2; if(fscanf(fp, "%d %d", &v1, &v2) != 2) continue; MVertex *mv1 = gm->getMeshVertexByTag(v1); MVertex *mv2 = gm->getMeshVertexByTag(v2); if(completePer) s->correspondingVertices[mv1] = mv2; } - if (!completePer) { - if (!s) + if(!completePer) { + if(!s) Msg::Info("Could not find periodic slave entity %d of dimension %d", - slave, dim); - if (!m) + slave, dim); + if(!m) Msg::Info("Could not find periodic master entity %d of dimension %d", master, dim); } @@ -170,7 +180,7 @@ void readMSHPeriodicNodes(FILE *fp, GModel *gm) // also used in MSH2 int GModel::_readMSH3(const std::string &name) { FILE *fp = Fopen(name.c_str(), "rb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -179,37 +189,40 @@ int GModel::_readMSH3(const std::string &name) double version = 0.; bool binary = false, swap = false, postpro = false; int minVertex = 0; - std::map<int, std::vector<MElement*> > elements[11]; + std::map<int, std::vector<MElement *> > elements[11]; while(1) { - - while(str[0] != '$'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(str[0] != '$') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } - if(feof(fp)) - break; + if(feof(fp)) break; // $MeshFormat section if(!strncmp(&str[1], "MeshFormat", 10)) { - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int format, size; - if(sscanf(str, "%lf %d %d", &version, &format, &size) != 3){ + if(sscanf(str, "%lf %d %d", &version, &format, &size) != 3) { fclose(fp); return 0; } - if(version < 3. || version >= 4.){ + if(version < 3. || version >= 4.) { Msg::Error("Wrong MSH file version %g for MSH3 reader", version); fclose(fp); return 0; } - if(format){ + if(format) { binary = true; Msg::Debug("Mesh is in binary format"); int one; - if(fread(&one, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(one != 1){ + if(fread(&one, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(one != 1) { swap = true; Msg::Debug("Swapping bytes from binary file"); } @@ -218,14 +231,29 @@ int GModel::_readMSH3(const std::string &name) // $PhysicalNames section else if(!strncmp(&str[1], "PhysicalNames", 13)) { - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int numNames; - if(sscanf(str, "%d", &numNames) != 1){ fclose(fp); return 0; } + if(sscanf(str, "%d", &numNames) != 1) { + fclose(fp); + return 0; + } for(int i = 0; i < numNames; i++) { int dim, num; - if(fscanf(fp, "%d", &dim) != 1){ fclose(fp); return 0; } - if(fscanf(fp, "%d", &num) != 1){ fclose(fp); return 0; } - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(fscanf(fp, "%d", &dim) != 1) { + fclose(fp); + return 0; + } + if(fscanf(fp, "%d", &num) != 1) { + fclose(fp); + return 0; + } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } std::string name = ExtractDoubleQuotedString(str, 256); if(name.size()) setPhysicalName(name, dim, num); } @@ -238,9 +266,15 @@ int GModel::_readMSH3(const std::string &name) // $Nodes section else if(!strncmp(&str[1], "Nodes", 5)) { - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int numVertices; - if(sscanf(str, "%d", &numVertices) != 1){ fclose(fp); return 0; } + if(sscanf(str, "%d", &numVertices) != 1) { + fclose(fp); + return 0; + } Msg::Info("%d vertices", numVertices); Msg::ResetProgressMeter(); _vertexMapCache.clear(); @@ -251,86 +285,109 @@ int GModel::_readMSH3(const std::string &name) int num, entity, dim; double xyz[3]; MVertex *vertex = 0; - if(!binary){ + if(!binary) { if(fscanf(fp, "%d %lf %lf %lf %d", &num, &xyz[0], &xyz[1], &xyz[2], &entity) != 5) { fclose(fp); return 0; } } - else{ - if(fread(&num, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&num, sizeof(int), 1); - if(fread(xyz, sizeof(double), 3, fp) != 3){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)xyz, sizeof(double), 3); - if(fread(&entity, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&entity, sizeof(int), 1); + else { + if(fread(&num, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&num, sizeof(int), 1); + if(fread(xyz, sizeof(double), 3, fp) != 3) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)xyz, sizeof(double), 3); + if(fread(&entity, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&entity, sizeof(int), 1); } - if(!entity){ + if(!entity) { vertex = new MVertex(xyz[0], xyz[1], xyz[2], 0, num); } - else{ - if(!binary){ - if(fscanf(fp, "%d", &dim) != 1){ fclose(fp); return 0; } - } - else{ - if(fread(&dim, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&dim, sizeof(int), 1); + else { + if(!binary) { + if(fscanf(fp, "%d", &dim) != 1) { + fclose(fp); + return 0; + } } - switch(dim){ - case 0: - { - GVertex *gv = getVertexByTag(entity); - // FIXME -- cannot call this: it destroys _vertexMapCache - //if(gv) gv->deleteMesh(); - vertex = new MVertex(xyz[0], xyz[1], xyz[2], gv, num); + else { + if(fread(&dim, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; } - break; - case 1: - { - GEdge *ge = getEdgeByTag(entity); - double u; - if(!binary){ - if(fscanf(fp, "%lf", &u) != 1){ fclose(fp); return 0; } + if(swap) SwapBytes((char *)&dim, sizeof(int), 1); + } + switch(dim) { + case 0: { + GVertex *gv = getVertexByTag(entity); + // FIXME -- cannot call this: it destroys _vertexMapCache + // if(gv) gv->deleteMesh(); + vertex = new MVertex(xyz[0], xyz[1], xyz[2], gv, num); + } break; + case 1: { + GEdge *ge = getEdgeByTag(entity); + double u; + if(!binary) { + if(fscanf(fp, "%lf", &u) != 1) { + fclose(fp); + return 0; } - else{ - if(fread(&u, sizeof(double), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&u, sizeof(double), 1); + } + else { + if(fread(&u, sizeof(double), 1, fp) != 1) { + fclose(fp); + return 0; } - vertex = new MEdgeVertex(xyz[0], xyz[1], xyz[2], ge, u, num); + if(swap) SwapBytes((char *)&u, sizeof(double), 1); } - break; - case 2: - { - GFace *gf = getFaceByTag(entity); - double uv[2]; - if(!binary){ - if(fscanf(fp, "%lf %lf", &uv[0], &uv[1]) != 2){ fclose(fp); return 0; } + vertex = new MEdgeVertex(xyz[0], xyz[1], xyz[2], ge, u, num); + } break; + case 2: { + GFace *gf = getFaceByTag(entity); + double uv[2]; + if(!binary) { + if(fscanf(fp, "%lf %lf", &uv[0], &uv[1]) != 2) { + fclose(fp); + return 0; } - else{ - if(fread(uv, sizeof(double), 2, fp) != 2){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)uv, sizeof(double), 2); + } + else { + if(fread(uv, sizeof(double), 2, fp) != 2) { + fclose(fp); + return 0; } - vertex = new MFaceVertex(xyz[0], xyz[1], xyz[2], gf, uv[0], uv[1], num); + if(swap) SwapBytes((char *)uv, sizeof(double), 2); } - break; - case 3: - { - GRegion *gr = getRegionByTag(entity); - double uvw[3]; - if(!binary){ - if(fscanf(fp, "%lf %lf %lf", &uvw[0], &uvw[1], &uvw[2]) != 3){ - fclose(fp); - return 0; - } + vertex = + new MFaceVertex(xyz[0], xyz[1], xyz[2], gf, uv[0], uv[1], num); + } break; + case 3: { + GRegion *gr = getRegionByTag(entity); + double uvw[3]; + if(!binary) { + if(fscanf(fp, "%lf %lf %lf", &uvw[0], &uvw[1], &uvw[2]) != 3) { + fclose(fp); + return 0; } - else{ - if(fread(uvw, sizeof(double), 3, fp) != 3){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)uvw, sizeof(double), 3); + } + else { + if(fread(uvw, sizeof(double), 3, fp) != 3) { + fclose(fp); + return 0; } - vertex = new MVertex(xyz[0], xyz[1], xyz[2], gr, num); + if(swap) SwapBytes((char *)uvw, sizeof(double), 3); } - break; + vertex = new MVertex(xyz[0], xyz[1], xyz[2], gr, num); + } break; default: Msg::Error("Wrong entity dimension for vertex %d", num); fclose(fp); @@ -349,14 +406,15 @@ int GModel::_readMSH3(const std::string &name) // speed up element creation if((int)_vertexMapCache.size() == numVertices && ((minVertex == 1 && maxVertex == numVertices) || - (minVertex == 0 && maxVertex == numVertices - 1))){ + (minVertex == 0 && maxVertex == numVertices - 1))) { Msg::Debug("Vertex numbering is dense"); _vertexVectorCache.resize(_vertexMapCache.size() + 1); if(minVertex == 1) _vertexVectorCache[0] = 0; else _vertexVectorCache[numVertices] = 0; - for(std::map<int, MVertex*>::const_iterator it = _vertexMapCache.begin(); + for(std::map<int, MVertex *>::const_iterator it = + _vertexMapCache.begin(); it != _vertexMapCache.end(); ++it) _vertexVectorCache[it->first] = it->second; _vertexMapCache.clear(); @@ -365,49 +423,73 @@ int GModel::_readMSH3(const std::string &name) // $Elements section else if(!strncmp(&str[1], "Elements", 8)) { - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return 0; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return 0; + } int numElements; - if(sscanf(str, "%d", &numElements) != 1){ fclose(fp); return 0; } + if(sscanf(str, "%d", &numElements) != 1) { + fclose(fp); + return 0; + } Msg::Info("%d elements", numElements); Msg::ResetProgressMeter(); for(int i = 0; i < numElements; i++) { int num, type, entity, numData; - if(!binary){ - if(fscanf(fp, "%d %d %d %d", &num, &type, &entity, &numData) != 4){ + if(!binary) { + if(fscanf(fp, "%d %d %d %d", &num, &type, &entity, &numData) != 4) { fclose(fp); return 0; } } - else{ - if(fread(&num, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&num, sizeof(int), 1); - if(fread(&type, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&type, sizeof(int), 1); - if(fread(&entity, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&entity, sizeof(int), 1); - if(fread(&numData, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(swap) SwapBytes((char*)&numData, sizeof(int), 1); + else { + if(fread(&num, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&num, sizeof(int), 1); + if(fread(&type, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&type, sizeof(int), 1); + if(fread(&entity, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&entity, sizeof(int), 1); + if(fread(&numData, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(swap) SwapBytes((char *)&numData, sizeof(int), 1); } std::vector<int> data; - if(numData > 0){ + if(numData > 0) { data.resize(numData); - if(!binary){ - for(int j = 0; j < numData; j++){ - if(fscanf(fp, "%d", &data[j]) != 1){ fclose(fp); return 0; } + if(!binary) { + for(int j = 0; j < numData; j++) { + if(fscanf(fp, "%d", &data[j]) != 1) { + fclose(fp); + return 0; + } } } - else{ - if((int) fread(&data[0], sizeof(int), numData, fp) != numData){ + else { + if((int)fread(&data[0], sizeof(int), numData, fp) != numData) { fclose(fp); return 0; } - if(swap) SwapBytes((char*)&data[0], sizeof(int), numData); + if(swap) SwapBytes((char *)&data[0], sizeof(int), numData); } } MElementFactory f; MElement *element = f.create(num, type, data, this); - if(!element){ fclose(fp); return 0; } - switch(element->getType()){ + if(!element) { + fclose(fp); + return 0; + } + switch(element->getType()) { case TYPE_PNT: elements[0][entity].push_back(element); break; case TYPE_LIN: elements[1][entity].push_back(element); break; case TYPE_TRI: elements[2][entity].push_back(element); break; @@ -439,13 +521,10 @@ int GModel::_readMSH3(const std::string &name) } do { - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } while(str[0] != '$'); } - - // store the elements in their associated elementary entity. If the // entity does not exist, create a new (discrete) one. for(int i = 0; i < (int)(sizeof(elements) / sizeof(elements[0])); i++) @@ -460,7 +539,7 @@ int GModel::_readMSH3(const std::string &name) else _storeVerticesInEntities(_vertexMapCache); - _createGeometryOfDiscreteEntities() ; + _createGeometryOfDiscreteEntities(); for(int i = 0; i < (int)(sizeof(elements) / sizeof(elements[0])); i++) _storeParentsInSubElements(elements[i]); @@ -478,61 +557,63 @@ static void writeMSHPhysicals(FILE *fp, GEntity *ge) fprintf(fp, "%d ", *itp); } -void writeMSHEntities(FILE *fp, GModel *gm) // also used in MSH2 +void writeMSHEntities(FILE *fp, GModel *gm) // also used in MSH2 { fprintf(fp, "$Entities\n"); - fprintf (fp, "%lu %d %d %d\n", gm->getNumVertices(), gm->getNumEdges(), - gm->getNumFaces(), gm->getNumRegions()); - for (GModel::viter it = gm->firstVertex(); it != gm->lastVertex(); ++it) { + fprintf(fp, "%lu %d %d %d\n", gm->getNumVertices(), gm->getNumEdges(), + gm->getNumFaces(), gm->getNumRegions()); + for(GModel::viter it = gm->firstVertex(); it != gm->lastVertex(); ++it) { fprintf(fp, "%d ", (*it)->tag()); writeMSHPhysicals(fp, *it); fprintf(fp, "\n"); } - for (GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); ++it) { - std::list<GVertex*> vertices; + for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); ++it) { + std::list<GVertex *> vertices; if((*it)->getBeginVertex()) vertices.push_back((*it)->getBeginVertex()); if((*it)->getEndVertex()) vertices.push_back((*it)->getEndVertex()); fprintf(fp, "%d %d ", (*it)->tag(), (int)vertices.size()); - for(std::list<GVertex*>::iterator itv = vertices.begin(); itv != vertices.end(); itv++){ + for(std::list<GVertex *>::iterator itv = vertices.begin(); + itv != vertices.end(); itv++) { fprintf(fp, "%d ", (*itv)->tag()); } writeMSHPhysicals(fp, *it); fprintf(fp, "\n"); } - for (GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) { - std::vector<GEdge*> const& edges = (*it)->edges(); - std::vector<int> const& ori = (*it)->edgeOrientations(); + for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) { + std::vector<GEdge *> const &edges = (*it)->edges(); + std::vector<int> const &ori = (*it)->edgeOrientations(); fprintf(fp, "%d %d ", (*it)->tag(), (int)edges.size()); std::vector<int> tags; - for(std::vector<GEdge*>::const_iterator ite = edges.begin(); ite != edges.end(); ite++) + for(std::vector<GEdge *>::const_iterator ite = edges.begin(); + ite != edges.end(); ite++) tags.push_back((*ite)->tag()); std::vector<int> signs(ori.begin(), ori.end()); - if(tags.size() == signs.size()){ + if(tags.size() == signs.size()) { for(unsigned int i = 0; i < tags.size(); i++) tags[i] *= (signs[i] > 0 ? 1 : -1); } - for(unsigned int i = 0; i < tags.size(); i++) - fprintf(fp, "%d ", tags[i]); + for(unsigned int i = 0; i < tags.size(); i++) fprintf(fp, "%d ", tags[i]); writeMSHPhysicals(fp, *it); fprintf(fp, "\n"); } - for (GModel::riter it = gm->firstRegion(); it != gm->lastRegion(); ++it) { - std::vector<GFace*> faces = (*it)->faces(); + for(GModel::riter it = gm->firstRegion(); it != gm->lastRegion(); ++it) { + std::vector<GFace *> faces = (*it)->faces(); std::vector<int> ori = (*it)->faceOrientations(); fprintf(fp, "%d %d ", (*it)->tag(), (int)faces.size()); std::vector<int> tags, signs; - for(std::vector<GFace*>::iterator itf = faces.begin(); itf != faces.end(); itf++) + for(std::vector<GFace *>::iterator itf = faces.begin(); itf != faces.end(); + itf++) tags.push_back((*itf)->tag()); - for(std::vector<int>::const_iterator itf = ori.begin(); itf != ori.end(); itf++) + for(std::vector<int>::const_iterator itf = ori.begin(); itf != ori.end(); + itf++) signs.push_back(*itf); - if(tags.size() == signs.size()){ + if(tags.size() == signs.size()) { for(unsigned int i = 0; i < tags.size(); i++) tags[i] *= (signs[i] > 0 ? 1 : -1); } - for(unsigned int i = 0; i < tags.size(); i++) - fprintf(fp, "%d ", tags[i]); + for(unsigned int i = 0; i < tags.size(); i++) fprintf(fp, "%d ", tags[i]); writeMSHPhysicals(fp, *it); fprintf(fp, "\n"); } @@ -542,13 +623,12 @@ void writeMSHEntities(FILE *fp, GModel *gm) // also used in MSH2 static int getNumElementsMSH(GEntity *ge, bool saveAll, int saveSinglePartition) { int n = 0; - if(saveAll || ge->physicals.size()){ + if(saveAll || ge->physicals.size()) { if(saveSinglePartition <= 0) n = ge->getNumMeshElements(); else for(unsigned int i = 0; i < ge->getNumMeshElements(); i++) - if(ge->getMeshElement(i)->getPartition() == saveSinglePartition) - n++; + if(ge->getMeshElement(i)->getPartition() == saveSinglePartition) n++; } return n; } @@ -556,12 +636,12 @@ static int getNumElementsMSH(GEntity *ge, bool saveAll, int saveSinglePartition) static void writeElementMSH(FILE *fp, GModel *model, MElement *ele, bool binary, int elementary) { - if(model->getGhostCells().size()){ + if(model->getGhostCells().size()) { std::vector<short> ghosts; - std::pair<std::multimap<MElement*, short>::iterator, - std::multimap<MElement*, short>::iterator> itp = - model->getGhostCells().equal_range(ele); - for(std::multimap<MElement*, short>::iterator it = itp.first; + std::pair<std::multimap<MElement *, short>::iterator, + std::multimap<MElement *, short>::iterator> + itp = model->getGhostCells().equal_range(ele); + for(std::multimap<MElement *, short>::iterator it = itp.first; it != itp.second; it++) ghosts.push_back(it->second); ele->writeMSH(fp, binary, elementary, &ghosts); @@ -570,12 +650,13 @@ static void writeElementMSH(FILE *fp, GModel *model, MElement *ele, bool binary, ele->writeMSH(fp, binary, elementary); } -template<class T> -static void writeElementsMSH(FILE *fp, GModel *model, GEntity *ge, std::vector<T*> &ele, - bool saveAll, int saveSinglePartition, bool binary) +template <class T> +static void writeElementsMSH(FILE *fp, GModel *model, GEntity *ge, + std::vector<T *> &ele, bool saveAll, + int saveSinglePartition, bool binary) { - if(saveAll || ge->physicals.size()){ - for(unsigned int i = 0; i < ele.size(); i++){ + if(saveAll || ge->physicals.size()) { + for(unsigned int i = 0; i < ele.size(); i++) { if(saveSinglePartition && ele[i]->getPartition() != saveSinglePartition) continue; writeElementMSH(fp, model, ele[i], binary, ge->tag()); @@ -583,30 +664,33 @@ static void writeElementsMSH(FILE *fp, GModel *model, GEntity *ge, std::vector<T } } -void writeMSHPeriodicNodes(FILE *fp, std::vector<GEntity*> &entities, - bool renumber) // also used in MSH2 +void writeMSHPeriodicNodes(FILE *fp, std::vector<GEntity *> &entities, + bool renumber) // also used in MSH2 { int count = 0; - for (unsigned int i = 0; i < entities.size(); i++) - if (entities[i]->meshMaster() != entities[i]) count++; - if (!count) return; + for(unsigned int i = 0; i < entities.size(); i++) + if(entities[i]->meshMaster() != entities[i]) count++; + if(!count) return; fprintf(fp, "$Periodic\n"); fprintf(fp, "%d\n", count); - for(unsigned int i = 0; i < entities.size(); i++){ - GEntity *g_slave = entities[i]; + for(unsigned int i = 0; i < entities.size(); i++) { + GEntity *g_slave = entities[i]; GEntity *g_master = g_slave->meshMaster(); - if (g_slave != g_master){ - fprintf(fp, "%d %d %d\n", g_slave->dim(), g_slave->tag(), g_master->tag()); + if(g_slave != g_master) { + fprintf(fp, "%d %d %d\n", g_slave->dim(), g_slave->tag(), + g_master->tag()); - if (g_slave->affineTransform.size() == 16) { + if(g_slave->affineTransform.size() == 16) { fprintf(fp, "Affine"); - for (int i = 0; i < 16;i++) fprintf(fp, " %.16g", g_slave->affineTransform[i]); + for(int i = 0; i < 16; i++) + fprintf(fp, " %.16g", g_slave->affineTransform[i]); fprintf(fp, "\n"); } - fprintf(fp, "%d\n", (int) g_slave->correspondingVertices.size()); - for (std::map<MVertex*,MVertex*>::iterator it = g_slave->correspondingVertices.begin(); - it != g_slave->correspondingVertices.end(); it++){ + fprintf(fp, "%d\n", (int)g_slave->correspondingVertices.size()); + for(std::map<MVertex *, MVertex *>::iterator it = + g_slave->correspondingVertices.begin(); + it != g_slave->correspondingVertices.end(); it++) { MVertex *v1 = it->first; MVertex *v2 = it->second; if(renumber) @@ -620,11 +704,11 @@ void writeMSHPeriodicNodes(FILE *fp, std::vector<GEntity*> &entities, } int GModel::_writeMSH3(const std::string &name, double version, bool binary, - bool saveAll, bool saveParametric, - double scalingFactor, int elementStartNum, - int saveSinglePartition, bool multipleView) + bool saveAll, bool saveParametric, double scalingFactor, + int elementStartNum, int saveSinglePartition, + bool multipleView) { - if(version < 3. || version >= 4.){ + if(version < 3. || version >= 4.) { Msg::Error("Wrong MSH file version %g for MSH3 writer", version); return 0; } @@ -634,7 +718,7 @@ int GModel::_writeMSH3(const std::string &name, double version, bool binary, fp = Fopen(name.c_str(), binary ? "ab" : "a"); else fp = Fopen(name.c_str(), binary ? "wb" : "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -651,7 +735,7 @@ int GModel::_writeMSH3(const std::string &name, double version, bool binary, int numVertices = indexMeshVertices(saveAll, saveSinglePartition, renumber); // get the number of elements we need to save - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); int numElements = 0; for(unsigned int i = 0; i < entities.size(); i++) @@ -659,17 +743,17 @@ int GModel::_writeMSH3(const std::string &name, double version, bool binary, fprintf(fp, "$MeshFormat\n"); fprintf(fp, "%g %d %d\n", version, binary ? 1 : 0, (int)sizeof(double)); - if(binary){ + if(binary) { int one = 1; fwrite(&one, sizeof(int), 1, fp); fprintf(fp, "\n"); } fprintf(fp, "$EndMeshFormat\n"); - if(numPhysicalNames()){ + if(numPhysicalNames()) { fprintf(fp, "$PhysicalNames\n"); fprintf(fp, "%d\n", numPhysicalNames()); - for(piter it = firstPhysicalName(); it != lastPhysicalName(); it++){ + for(piter it = firstPhysicalName(); it != lastPhysicalName(); it++) { std::string name = it->second; if(name.size() > 254) name.resize(254); fprintf(fp, "%d %d \"%s\"\n", it->first.first, it->first.second, @@ -684,7 +768,8 @@ int GModel::_writeMSH3(const std::string &name, double version, bool binary, fprintf(fp, "%d\n", numVertices); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) - entities[i]->mesh_vertices[j]->writeMSH(fp, binary, saveParametric, scalingFactor); + entities[i]->mesh_vertices[j]->writeMSH(fp, binary, saveParametric, + scalingFactor); if(binary) fprintf(fp, "\n"); fprintf(fp, "$EndNodes\n"); @@ -695,26 +780,26 @@ int GModel::_writeMSH3(const std::string &name, double version, bool binary, _elementIndexCache.clear(); for(riter it = firstRegion(); it != lastRegion(); ++it) - writeElementsMSH(fp, this, *it, (*it)->tetrahedra, saveAll, saveSinglePartition, - binary); + writeElementsMSH(fp, this, *it, (*it)->tetrahedra, saveAll, + saveSinglePartition, binary); for(riter it = firstRegion(); it != lastRegion(); ++it) - writeElementsMSH(fp, this, *it, (*it)->hexahedra, saveAll, saveSinglePartition, - binary); + writeElementsMSH(fp, this, *it, (*it)->hexahedra, saveAll, + saveSinglePartition, binary); for(riter it = firstRegion(); it != lastRegion(); ++it) writeElementsMSH(fp, this, *it, (*it)->prisms, saveAll, saveSinglePartition, binary); for(riter it = firstRegion(); it != lastRegion(); ++it) - writeElementsMSH(fp, this, *it, (*it)->pyramids, saveAll, saveSinglePartition, - binary); + writeElementsMSH(fp, this, *it, (*it)->pyramids, saveAll, + saveSinglePartition, binary); for(riter it = firstRegion(); it != lastRegion(); ++it) - writeElementsMSH(fp, this, *it, (*it)->trihedra, saveAll, saveSinglePartition, - binary); + writeElementsMSH(fp, this, *it, (*it)->trihedra, saveAll, + saveSinglePartition, binary); for(fiter it = firstFace(); it != lastFace(); ++it) - writeElementsMSH(fp, this, *it, (*it)->triangles, saveAll, saveSinglePartition, - binary); + writeElementsMSH(fp, this, *it, (*it)->triangles, saveAll, + saveSinglePartition, binary); for(fiter it = firstFace(); it != lastFace(); ++it) - writeElementsMSH(fp, this, *it, (*it)->quadrangles, saveAll, saveSinglePartition, - binary); + writeElementsMSH(fp, this, *it, (*it)->quadrangles, saveAll, + saveSinglePartition, binary); for(eiter it = firstEdge(); it != lastEdge(); ++it) writeElementsMSH(fp, this, *it, (*it)->lines, saveAll, saveSinglePartition, binary); @@ -726,7 +811,7 @@ int GModel::_writeMSH3(const std::string &name, double version, bool binary, fprintf(fp, "$EndElements\n"); - //save periodic nodes + // save periodic nodes writeMSHPeriodicNodes(fp, entities, renumber); fclose(fp); @@ -735,18 +820,20 @@ int GModel::_writeMSH3(const std::string &name, double version, bool binary, } int GModel::_writePartitionedMSH3(const std::string &baseName, double version, - bool binary, bool saveAll, bool saveParametric, - double scalingFactor) + bool binary, bool saveAll, + bool saveParametric, double scalingFactor) { - if(version < 3. || version >= 4.){ + if(version < 3. || version >= 4.) { Msg::Error("Wrong MSH file version %g for MSH3 writer", version); return 0; } - for(unsigned int partition = 0; partition < getNumPartitions(); partition++){ + for(unsigned int partition = 0; partition < getNumPartitions(); partition++) { std::ostringstream sstream; - sstream << baseName << "_" << std::setw(6) << std::setfill('0') << partition; - Msg::Info("Writing partition %d in file '%s'", partition, sstream.str().c_str()); + sstream << baseName << "_" << std::setw(6) << std::setfill('0') + << partition; + Msg::Info("Writing partition %d in file '%s'", partition, + sstream.str().c_str()); _writeMSH3(sstream.str(), version, binary, saveAll, saveParametric, scalingFactor, 0, partition, false); } diff --git a/Geo/GModelIO_MSH4.cpp b/Geo/GModelIO_MSH4.cpp index e3052441b227f8c740acfb64efbcba444cc70b93..ecaf292fac883780e3dda1e7b8b2269107d0a73a 100644 --- a/Geo/GModelIO_MSH4.cpp +++ b/Geo/GModelIO_MSH4.cpp @@ -37,39 +37,40 @@ #include "MTrihedron.h" #include "StringUtils.h" -static bool readMSH4Physicals(GModel *const model, FILE* fp, GEntity *const entity, - bool binary, char *str, bool swap) +static bool readMSH4Physicals(GModel *const model, FILE *fp, + GEntity *const entity, bool binary, char *str, + bool swap) { unsigned long numPhy = 0; - if(binary){ - if(fread(&numPhy, sizeof(unsigned long), 1, fp) != 1){ + if(binary) { + if(fread(&numPhy, sizeof(unsigned long), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&numPhy, sizeof(unsigned long), 1); + if(swap) SwapBytes((char *)&numPhy, sizeof(unsigned long), 1); int *phyTags = new int[numPhy]; - if(fread(phyTags, sizeof(int), numPhy, fp) != numPhy){ + if(fread(phyTags, sizeof(int), numPhy, fp) != numPhy) { return false; } - if(swap) SwapBytes((char*)phyTags, sizeof(int), numPhy); + if(swap) SwapBytes((char *)phyTags, sizeof(int), numPhy); - for(unsigned int i = 0; i < numPhy; i++){ + for(unsigned int i = 0; i < numPhy; i++) { entity->addPhysicalEntity(phyTags[i]); } delete[] phyTags; } - else{ + else { sscanf(str, "%lu %[0-9- ]", &numPhy, str); - for(unsigned int i = 0; i < numPhy; i++){ + for(unsigned int i = 0; i < numPhy; i++) { int phyTag = 0; - if(i == numPhy-1 && entity->dim() == 0){ - if(sscanf(str, "%d", &phyTag) != 1){ + if(i == numPhy - 1 && entity->dim() == 0) { + if(sscanf(str, "%d", &phyTag) != 1) { return false; } } - else{ - if(sscanf(str, "%d %[0-9- ]", &phyTag, str) != 2){ + else { + if(sscanf(str, "%d %[0-9- ]", &phyTag, str) != 2) { return false; } } @@ -80,29 +81,30 @@ static bool readMSH4Physicals(GModel *const model, FILE* fp, GEntity *const enti return true; } -static bool readMSH4BoundingEntities(GModel *const model, FILE* fp, +static bool readMSH4BoundingEntities(GModel *const model, FILE *fp, GEntity *const entity, bool binary, char *str, bool swap) { unsigned long numBrep = 0; - std::vector<GEntity*> boundingEntities; + std::vector<GEntity *> boundingEntities; std::vector<int> boundingSign; - if(binary){ - if(fread(&numBrep, sizeof(unsigned long), 1, fp) != 1){ + if(binary) { + if(fread(&numBrep, sizeof(unsigned long), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&numBrep, sizeof(unsigned long), 1); + if(swap) SwapBytes((char *)&numBrep, sizeof(unsigned long), 1); int *brepTags = new int[numBrep]; - if(fread(brepTags, sizeof(int), numBrep, fp) != numBrep){ + if(fread(brepTags, sizeof(int), numBrep, fp) != numBrep) { return false; } - if(swap) SwapBytes((char*)brepTags, sizeof(int), numBrep); + if(swap) SwapBytes((char *)brepTags, sizeof(int), numBrep); - for(unsigned int i = 0; i < numBrep; i++){ - GEntity *brep = model->getEntityByTag(entity->dim()-1, std::abs(brepTags[i])); - if(!brep){ + for(unsigned int i = 0; i < numBrep; i++) { + GEntity *brep = + model->getEntityByTag(entity->dim() - 1, std::abs(brepTags[i])); + if(!brep) { Msg::Warning("Entity %d not found in the Brep of entity %d", brepTags[i], entity->tag()); return false; @@ -112,26 +114,27 @@ static bool readMSH4BoundingEntities(GModel *const model, FILE* fp, } delete[] brepTags; } - else{ + else { sscanf(str, "%lu %[0-9- ]", &numBrep, str); - for(unsigned int i = 0; i < numBrep; i++){ + for(unsigned int i = 0; i < numBrep; i++) { int entityTag = 0; - if(i != numBrep - 1){ - if(sscanf(str, "%d %[0-9- ]", &entityTag, str) != 2){ + if(i != numBrep - 1) { + if(sscanf(str, "%d %[0-9- ]", &entityTag, str) != 2) { return false; } } - else{ - if(sscanf(str, "%d", &entityTag) != 1){ + else { + if(sscanf(str, "%d", &entityTag) != 1) { return false; } } - GEntity *brep = model->getEntityByTag(entity->dim()-1, std::abs(entityTag)); - if(!brep){ - Msg::Warning("Entity %d not found in the Brep of entity %d", - entityTag, entity->tag()); + GEntity *brep = + model->getEntityByTag(entity->dim() - 1, std::abs(entityTag)); + if(!brep) { + Msg::Warning("Entity %d not found in the Brep of entity %d", entityTag, + entity->tag()); return false; } boundingEntities.push_back(brep); @@ -139,43 +142,39 @@ static bool readMSH4BoundingEntities(GModel *const model, FILE* fp, } } - switch(entity->dim()){ - case 1: - if(boundingEntities.size() == 2){ - reinterpret_cast<discreteEdge*>(entity)->setBeginVertex - (reinterpret_cast<GVertex*>(boundingEntities[0])); - reinterpret_cast<discreteEdge*>(entity)->setEndVertex - (reinterpret_cast<GVertex*>(boundingEntities[1])); - } - else if(boundingEntities.size() == 1){ - if(boundingSign[0] == 1){ - reinterpret_cast<discreteEdge*>(entity)->setBeginVertex - (reinterpret_cast<GVertex*>(boundingEntities[0])); - } - else{ - reinterpret_cast<discreteEdge*>(entity)->setEndVertex - (reinterpret_cast<GVertex*>(boundingEntities[0])); - } - } - break; - case 2: - { - std::vector<int> tags(boundingEntities.size()); - for(unsigned int i = 0; i < boundingEntities.size(); i++) - tags[i] = std::abs(boundingEntities[i]->tag()); - reinterpret_cast<discreteFace*>(entity)->setBoundEdges(tags, boundingSign); - } - break; - case 3: - { - std::vector<int> tags(boundingEntities.size()); - for(unsigned int i = 0; i < boundingEntities.size(); i++) - tags[i] = std::abs(boundingEntities[i]->tag()); - reinterpret_cast<discreteRegion*>(entity)->setBoundFaces(tags, boundingSign); - } - break; - default: - break; + switch(entity->dim()) { + case 1: + if(boundingEntities.size() == 2) { + reinterpret_cast<discreteEdge *>(entity)->setBeginVertex( + reinterpret_cast<GVertex *>(boundingEntities[0])); + reinterpret_cast<discreteEdge *>(entity)->setEndVertex( + reinterpret_cast<GVertex *>(boundingEntities[1])); + } + else if(boundingEntities.size() == 1) { + if(boundingSign[0] == 1) { + reinterpret_cast<discreteEdge *>(entity)->setBeginVertex( + reinterpret_cast<GVertex *>(boundingEntities[0])); + } + else { + reinterpret_cast<discreteEdge *>(entity)->setEndVertex( + reinterpret_cast<GVertex *>(boundingEntities[0])); + } + } + break; + case 2: { + std::vector<int> tags(boundingEntities.size()); + for(unsigned int i = 0; i < boundingEntities.size(); i++) + tags[i] = std::abs(boundingEntities[i]->tag()); + reinterpret_cast<discreteFace *>(entity)->setBoundEdges(tags, boundingSign); + } break; + case 3: { + std::vector<int> tags(boundingEntities.size()); + for(unsigned int i = 0; i < boundingEntities.size(); i++) + tags[i] = std::abs(boundingEntities[i]->tag()); + reinterpret_cast<discreteRegion *>(entity)->setBoundFaces(tags, + boundingSign); + } break; + default: break; } return true; } @@ -187,28 +186,29 @@ static bool readMSH4EntityInfo(FILE *fp, bool binary, char *str, int sizeofstr, double &minX, double &minY, double &minZ, double &maxX, double &maxY, double &maxZ) { - if(partition){ - if(binary){ + if(partition) { + if(binary) { int dataInt[4]; double dataDouble[6]; - if(fread(dataInt, sizeof(int), 4, fp) != 4){ + if(fread(dataInt, sizeof(int), 4, fp) != 4) { return false; } - if(swap) SwapBytes((char*)dataInt, sizeof(int), 4); + if(swap) SwapBytes((char *)dataInt, sizeof(int), 4); tag = dataInt[0]; parentDim = dataInt[1]; parentTag = dataInt[2]; partitions.resize(dataInt[3], 0); if(fread(&partitions[0], sizeof(unsigned int), partitions.size(), fp) != - partitions.size()){ + partitions.size()) { return false; } - if(swap) SwapBytes((char*)&partitions[0], sizeof(unsigned int), - partitions.size()); - if(fread(dataDouble, sizeof(double), 6, fp) != 6){ + if(swap) + SwapBytes((char *)&partitions[0], sizeof(unsigned int), + partitions.size()); + if(fread(dataDouble, sizeof(double), 6, fp) != 6) { return false; } - if(swap) SwapBytes((char*)dataDouble, sizeof(double), 6); + if(swap) SwapBytes((char *)dataDouble, sizeof(double), 6); minX = dataDouble[0]; minY = dataDouble[1]; minZ = dataDouble[2]; @@ -216,38 +216,39 @@ static bool readMSH4EntityInfo(FILE *fp, bool binary, char *str, int sizeofstr, maxY = dataDouble[4]; maxZ = dataDouble[5]; } - else{ + else { int numPart = 0; - if(fscanf(fp, "%d %d %d %d", &tag, &parentDim, &parentTag, &numPart) != 4){ + if(fscanf(fp, "%d %d %d %d", &tag, &parentDim, &parentTag, &numPart) != + 4) { return false; } partitions.resize(numPart, 0); - for(int i = 0; i < numPart; i++){ - if(fscanf(fp, "%d", &partitions[i]) != 1){ + for(int i = 0; i < numPart; i++) { + if(fscanf(fp, "%d", &partitions[i]) != 1) { return false; } } - if(fscanf(fp, "%lf %lf %lf %lf %lf %lf", - &minX, &minY, &minZ, &maxX, &maxY, &maxZ) != 6){ + if(fscanf(fp, "%lf %lf %lf %lf %lf %lf", &minX, &minY, &minZ, &maxX, + &maxY, &maxZ) != 6) { return false; } - if(!fgets(str, sizeofstr, fp)){ + if(!fgets(str, sizeofstr, fp)) { return false; } } } - else{ - if(binary){ + else { + if(binary) { int dataInt; double dataDouble[6]; - if(fread(&dataInt, sizeof(int), 1, fp) != 1){ + if(fread(&dataInt, sizeof(int), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&dataInt, sizeof(int), 1); - if(fread(dataDouble, sizeof(double), 6, fp) != 6){ + if(swap) SwapBytes((char *)&dataInt, sizeof(int), 1); + if(fread(dataDouble, sizeof(double), 6, fp) != 6) { return false; } - if(swap) SwapBytes((char*)dataDouble, sizeof(double), 6); + if(swap) SwapBytes((char *)dataDouble, sizeof(double), 6); tag = dataInt; minX = dataDouble[0]; minY = dataDouble[1]; @@ -256,12 +257,12 @@ static bool readMSH4EntityInfo(FILE *fp, bool binary, char *str, int sizeofstr, maxY = dataDouble[4]; maxZ = dataDouble[5]; } - else{ - if(fscanf(fp, "%d %lf %lf %lf %lf %lf %lf", - &tag, &minX, &minY, &minZ, &maxX, &maxY, &maxZ) != 7){ + else { + if(fscanf(fp, "%d %lf %lf %lf %lf %lf %lf", &tag, &minX, &minY, &minZ, + &maxX, &maxY, &maxZ) != 7) { return false; } - if(!fgets(str, sizeofstr, fp)){ + if(!fgets(str, sizeofstr, fp)) { return false; } } @@ -269,48 +270,48 @@ static bool readMSH4EntityInfo(FILE *fp, bool binary, char *str, int sizeofstr, return true; } -static bool readMSH4Entities(GModel *const model, FILE* fp, bool partition, +static bool readMSH4Entities(GModel *const model, FILE *fp, bool partition, bool binary, bool swap) { // max length of line for ascii input file (should large enough to handle // entities with many entities on their boundary) char str[4096]; - if(partition){ + if(partition) { int numPartitions = 0; unsigned int ghostSize = 0; int *ghostTags = 0; - if(binary){ - if(fread(&numPartitions, sizeof(int), 1, fp) != 1){ + if(binary) { + if(fread(&numPartitions, sizeof(int), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&numPartitions, sizeof(int), 1); + if(swap) SwapBytes((char *)&numPartitions, sizeof(int), 1); - if(fread(&ghostSize, sizeof(int), 1, fp) != 1){ + if(fread(&ghostSize, sizeof(int), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&ghostSize, sizeof(int), 1); - if(ghostSize){ - ghostTags = new int[2*ghostSize]; - if(fread(ghostTags, sizeof(int), 2*ghostSize, fp) != 2*ghostSize){ + if(swap) SwapBytes((char *)&ghostSize, sizeof(int), 1); + if(ghostSize) { + ghostTags = new int[2 * ghostSize]; + if(fread(ghostTags, sizeof(int), 2 * ghostSize, fp) != 2 * ghostSize) { return false; } - if(swap) SwapBytes((char*)ghostTags, sizeof(int), 2*ghostSize); + if(swap) SwapBytes((char *)ghostTags, sizeof(int), 2 * ghostSize); } } - else{ - if(fscanf(fp, "%d", &numPartitions) != 1){ + else { + if(fscanf(fp, "%d", &numPartitions) != 1) { return false; } - if(fscanf(fp, "%d", &ghostSize) != 1){ + if(fscanf(fp, "%d", &ghostSize) != 1) { return false; } - if(ghostSize){ - ghostTags = new int[2*ghostSize]; - for(unsigned int i = 0; i < 2*ghostSize; i+=2){ - if(fscanf(fp, "%d %d", &ghostTags[i], &ghostTags[i+1]) != 2){ + if(ghostSize) { + ghostTags = new int[2 * ghostSize]; + for(unsigned int i = 0; i < 2 * ghostSize; i += 2) { + if(fscanf(fp, "%d %d", &ghostTags[i], &ghostTags[i + 1]) != 2) { return false; } } @@ -319,328 +320,313 @@ static bool readMSH4Entities(GModel *const model, FILE* fp, bool partition, model->setNumPartitions(numPartitions); Msg::Info("%d partitions", model->getNumPartitions()); - for(unsigned int i = 0; i < 2*ghostSize; i+=2){ - switch(model->getDim()){ - case 1: - { - ghostEdge *ghostEntities = new ghostEdge(model, ghostTags[i], ghostTags[i+1]); - model->add(ghostEntities); - } - break; - case 2: - { - ghostFace *ghostEntities = new ghostFace(model, ghostTags[i], ghostTags[i+1]); - model->add(ghostEntities); - } - break; - case 3: - { - ghostRegion *ghostEntities = new ghostRegion(model, ghostTags[i], ghostTags[i+1]); - model->add(ghostEntities); - } - break; - default: - break; + for(unsigned int i = 0; i < 2 * ghostSize; i += 2) { + switch(model->getDim()) { + case 1: { + ghostEdge *ghostEntities = + new ghostEdge(model, ghostTags[i], ghostTags[i + 1]); + model->add(ghostEntities); + } break; + case 2: { + ghostFace *ghostEntities = + new ghostFace(model, ghostTags[i], ghostTags[i + 1]); + model->add(ghostEntities); + } break; + case 3: { + ghostRegion *ghostEntities = + new ghostRegion(model, ghostTags[i], ghostTags[i + 1]); + model->add(ghostEntities); + } break; + default: break; } } } unsigned long numEntities[4] = {0, 0, 0, 0}; - if(binary){ - if(fread(numEntities, sizeof(unsigned long), 4, fp) != 4){ + if(binary) { + if(fread(numEntities, sizeof(unsigned long), 4, fp) != 4) { return false; } - if(swap) SwapBytes((char*)numEntities, sizeof(unsigned long), 4); + if(swap) SwapBytes((char *)numEntities, sizeof(unsigned long), 4); } - else{ + else { if(fscanf(fp, "%lu %lu %lu %lu", &numEntities[0], &numEntities[1], - &numEntities[2], &numEntities[3]) != 4){ + &numEntities[2], &numEntities[3]) != 4) { return false; } } - for(int dim = 0; dim < 4; dim++){ - for(unsigned int i = 0; i < numEntities[dim]; i++){ + for(int dim = 0; dim < 4; dim++) { + for(unsigned int i = 0; i < numEntities[dim]; i++) { int tag = 0, parentDim = 0, parentTag = 0; std::vector<unsigned int> partitions; double minX = 0., minY = 0., minZ = 0., maxX = 0., maxY = 0., maxZ = 0.; - if(!readMSH4EntityInfo(fp, binary, str, sizeof(str), swap, - partition, tag, parentDim, parentTag, partitions, - minX, minY, minZ, maxX, maxY, maxZ)) + if(!readMSH4EntityInfo(fp, binary, str, sizeof(str), swap, partition, tag, + parentDim, parentTag, partitions, minX, minY, minZ, + maxX, maxY, maxZ)) return false; - switch(dim){ - case 0: - { - GVertex *gv = model->getVertexByTag(tag); - if(!gv){ - if(partition){ - gv = new partitionVertex(model, tag, partitions); - if(parentTag) - static_cast<partitionVertex*>(gv)->setParentEntity - (model->getEntityByTag(parentDim, parentTag)); - } - else{ - gv = new discreteVertex(model, tag); - } - model->add(gv); + switch(dim) { + case 0: { + GVertex *gv = model->getVertexByTag(tag); + if(!gv) { + if(partition) { + gv = new partitionVertex(model, tag, partitions); + if(parentTag) + static_cast<partitionVertex *>(gv)->setParentEntity( + model->getEntityByTag(parentDim, parentTag)); } - if(!readMSH4Physicals(model, fp, gv, binary, str, swap)) - return false; - } - break; - case 1: - { - GEdge *ge = model->getEdgeByTag(tag); - if(!ge){ - if(partition){ - ge = new partitionEdge(model, tag, 0, 0, partitions); - if(parentTag) - static_cast<partitionEdge*>(ge)->setParentEntity - (model->getEntityByTag(parentDim, parentTag)); - } - else{ - ge = new discreteEdge(model, tag, 0, 0); - } - model->add(ge); + else { + gv = new discreteVertex(model, tag); } - if(!readMSH4Physicals(model, fp, ge, binary, str, swap)) - return false; - if(!readMSH4BoundingEntities(model, fp, ge, binary, str, swap)) - return false; + model->add(gv); + } + if(!readMSH4Physicals(model, fp, gv, binary, str, swap)) return false; + } break; + case 1: { + GEdge *ge = model->getEdgeByTag(tag); + if(!ge) { + if(partition) { + ge = new partitionEdge(model, tag, 0, 0, partitions); + if(parentTag) + static_cast<partitionEdge *>(ge)->setParentEntity( + model->getEntityByTag(parentDim, parentTag)); + } + else { + ge = new discreteEdge(model, tag, 0, 0); + } + model->add(ge); } - break; - case 2: - { - GFace *gf = model->getFaceByTag(tag); - if(!gf){ - if(partition){ - gf = new partitionFace(model, tag, partitions); - if(parentTag) - static_cast<partitionFace*>(gf)->setParentEntity - (model->getEntityByTag(parentDim, parentTag)); - } - else{ - gf = new discreteFace(model, tag); - } - model->add(gf); + if(!readMSH4Physicals(model, fp, ge, binary, str, swap)) return false; + if(!readMSH4BoundingEntities(model, fp, ge, binary, str, swap)) + return false; + } break; + case 2: { + GFace *gf = model->getFaceByTag(tag); + if(!gf) { + if(partition) { + gf = new partitionFace(model, tag, partitions); + if(parentTag) + static_cast<partitionFace *>(gf)->setParentEntity( + model->getEntityByTag(parentDim, parentTag)); } - if(!readMSH4Physicals(model, fp, gf, binary, str, swap)) - return false; - if(!readMSH4BoundingEntities(model, fp, gf, binary, str, swap)) - return false; + else { + gf = new discreteFace(model, tag); + } + model->add(gf); } - break; - case 3: - { - GRegion *gr = model->getRegionByTag(tag); - if(!gr){ - if(partition){ - gr = new partitionRegion(model, tag, partitions); - if(parentTag) - static_cast<partitionRegion*>(gr)->setParentEntity - (model->getEntityByTag(parentDim, parentTag)); - } - else{ - gr = new discreteRegion(model, tag); - } - model->add(gr); + if(!readMSH4Physicals(model, fp, gf, binary, str, swap)) return false; + if(!readMSH4BoundingEntities(model, fp, gf, binary, str, swap)) + return false; + } break; + case 3: { + GRegion *gr = model->getRegionByTag(tag); + if(!gr) { + if(partition) { + gr = new partitionRegion(model, tag, partitions); + if(parentTag) + static_cast<partitionRegion *>(gr)->setParentEntity( + model->getEntityByTag(parentDim, parentTag)); } - if(!readMSH4Physicals(model, fp, gr, binary, str, swap)) - return false; - if(!readMSH4BoundingEntities(model, fp, gr, binary, str, swap)) - return false; + else { + gr = new discreteRegion(model, tag); + } + model->add(gr); } - break; + if(!readMSH4Physicals(model, fp, gr, binary, str, swap)) return false; + if(!readMSH4BoundingEntities(model, fp, gr, binary, str, swap)) + return false; + } break; } } } return true; } -static std::pair<int, MVertex*> *readMSH4Nodes(GModel *const model, FILE* fp, - bool binary, bool &dense, - unsigned long &nbrNodes, - unsigned long &maxNodeNum, - bool swap) +static std::pair<int, MVertex *> * +readMSH4Nodes(GModel *const model, FILE *fp, bool binary, bool &dense, + unsigned long &nbrNodes, unsigned long &maxNodeNum, bool swap) { unsigned long numBlock = 0; nbrNodes = 0; maxNodeNum = 0; - if(binary){ + if(binary) { unsigned long data[2]; - if(fread(data, sizeof(unsigned long), 2, fp) != 2){ + if(fread(data, sizeof(unsigned long), 2, fp) != 2) { return 0; } - if(swap) SwapBytes((char*)data, sizeof(unsigned long), 2); + if(swap) SwapBytes((char *)data, sizeof(unsigned long), 2); numBlock = data[0]; nbrNodes = data[1]; } - else{ - if(fscanf(fp, "%lu %lu", &numBlock, &nbrNodes) != 2){ + else { + if(fscanf(fp, "%lu %lu", &numBlock, &nbrNodes) != 2) { return 0; } } unsigned long nodeRead = 0; unsigned long minNodeNum = nbrNodes + 1; - std::pair<int, MVertex*> *vertexCache = new std::pair<int, MVertex*>[nbrNodes]; + std::pair<int, MVertex *> *vertexCache = + new std::pair<int, MVertex *>[nbrNodes]; Msg::Info("%lu vertices", nbrNodes); - for(unsigned int i = 0; i < numBlock; i++){ + for(unsigned int i = 0; i < numBlock; i++) { int parametric = 0; int entityTag = 0, entityDim = 0; unsigned long numNodes = 0; - if(binary){ + if(binary) { int data[3]; - if(fread(data, sizeof(int), 3, fp) != 3){ + if(fread(data, sizeof(int), 3, fp) != 3) { return 0; } - if(swap) SwapBytes((char*)data, sizeof(int), 3); + if(swap) SwapBytes((char *)data, sizeof(int), 3); entityTag = data[0]; entityDim = data[1]; parametric = data[2]; unsigned long dataLong; - if(fread(&dataLong, sizeof(unsigned long), 1, fp) != 1){ + if(fread(&dataLong, sizeof(unsigned long), 1, fp) != 1) { return 0; } - if(swap) SwapBytes((char*)&dataLong, sizeof(unsigned long), 1); + if(swap) SwapBytes((char *)&dataLong, sizeof(unsigned long), 1); numNodes = dataLong; } - else{ - if(fscanf(fp, "%d %d %d %lu", &entityTag, &entityDim, ¶metric, &numNodes) != 4){ + else { + if(fscanf(fp, "%d %d %d %lu", &entityTag, &entityDim, ¶metric, + &numNodes) != 4) { return 0; } } GEntity *entity = model->getEntityByTag(entityDim, entityTag); - if(!entity){ + if(!entity) { Msg::Error("Unknown entity %d of dimension %d", entityTag, entityDim); return 0; } - for(unsigned int j = 0; j < numNodes; j++){ + for(unsigned int j = 0; j < numNodes; j++) { double xyz[3]; int nodeTag = 0; MVertex *vertex = 0; - if(parametric){ + if(parametric) { double u = 0., v = 0.; - switch(entityDim){ - case 0: - if(binary){ - if(fread(&nodeTag, sizeof(int), 1, fp) != 1){ - return 0; - } - if(swap) SwapBytes((char*)&nodeTag, sizeof(int), 1); - - if(fread(xyz, sizeof(double), 3, fp) != 3){ - return 0; - } - if(swap) SwapBytes((char*)xyz, sizeof(double), 3); + switch(entityDim) { + case 0: + if(binary) { + if(fread(&nodeTag, sizeof(int), 1, fp) != 1) { + return 0; } - else{ - if(fscanf(fp, "%d %lf %lf %lf", - &nodeTag, &xyz[0], &xyz[1], &xyz[2]) != 4){ - return 0; - } + if(swap) SwapBytes((char *)&nodeTag, sizeof(int), 1); + + if(fread(xyz, sizeof(double), 3, fp) != 3) { + return 0; } - vertex = new MVertex(xyz[0], xyz[1], xyz[2], entity, nodeTag); - break; - case 1: - if(binary){ - if(fread(&nodeTag, sizeof(int), 1, fp) != 1){ - return 0; - } - if(swap) SwapBytes((char*)&nodeTag, sizeof(int), 1); - - if(fread(xyz, sizeof(double), 3, fp) != 3){ - return 0; - } - if(swap) SwapBytes((char*)xyz, sizeof(double), 3); - - if(fread(&u, sizeof(double), 1, fp) != 1){ - return 0; - } - if(swap) SwapBytes((char*)&u, sizeof(double), 1); + if(swap) SwapBytes((char *)xyz, sizeof(double), 3); + } + else { + if(fscanf(fp, "%d %lf %lf %lf", &nodeTag, &xyz[0], &xyz[1], + &xyz[2]) != 4) { + return 0; } - else{ - if(fscanf(fp, "%d %lf %lf %lf %lf", - &nodeTag, &xyz[0], &xyz[1], &xyz[2], &u) != 5){ - return 0; - } + } + vertex = new MVertex(xyz[0], xyz[1], xyz[2], entity, nodeTag); + break; + case 1: + if(binary) { + if(fread(&nodeTag, sizeof(int), 1, fp) != 1) { + return 0; } - vertex = new MEdgeVertex(xyz[0], xyz[1], xyz[2], entity, u, -1.0, nodeTag); - break; - case 2: - if(binary){ - if(fread(&nodeTag, sizeof(int), 1, fp) != 1){ - return 0; - } - if(swap) SwapBytes((char*)&nodeTag, sizeof(int), 1); - - if(fread(xyz, sizeof(double), 3, fp) != 3){ - return 0; - } - if(swap) SwapBytes((char*)xyz, sizeof(double), 3); - - double uv[2]; - if(fread(uv, sizeof(double), 2, fp) != 2){ - return 0; - } - if(swap) SwapBytes((char*)uv, sizeof(double), 2); - - u = uv[0]; - v = uv[1]; + if(swap) SwapBytes((char *)&nodeTag, sizeof(int), 1); + + if(fread(xyz, sizeof(double), 3, fp) != 3) { + return 0; } - else{ - if(fscanf(fp, "%d %lf %lf %lf %lf %lf", - &nodeTag, &xyz[0], &xyz[1], &xyz[2], &u, &v) != 6){ - return 0; - } + if(swap) SwapBytes((char *)xyz, sizeof(double), 3); + + if(fread(&u, sizeof(double), 1, fp) != 1) { + return 0; } - vertex = new MFaceVertex(xyz[0], xyz[1], xyz[2], entity, u, v, nodeTag); - break; - case 3: - if(binary){ - if(fread(&nodeTag, sizeof(int), 1, fp) != 1){ - return 0; - } - if(swap) SwapBytes((char*)&nodeTag, sizeof(int), 1); - - if(fread(xyz, sizeof(double), 3, fp) != 3){ - return 0; - } - if(swap) SwapBytes((char*)xyz, sizeof(double), 3); + if(swap) SwapBytes((char *)&u, sizeof(double), 1); + } + else { + if(fscanf(fp, "%d %lf %lf %lf %lf", &nodeTag, &xyz[0], &xyz[1], + &xyz[2], &u) != 5) { + return 0; } - else{ - if(fscanf(fp, "%d %lf %lf %lf", &nodeTag, &xyz[0], &xyz[1], &xyz[2]) != 4){ - return 0; - } + } + vertex = + new MEdgeVertex(xyz[0], xyz[1], xyz[2], entity, u, -1.0, nodeTag); + break; + case 2: + if(binary) { + if(fread(&nodeTag, sizeof(int), 1, fp) != 1) { + return 0; } - vertex = new MVertex(xyz[0], xyz[1], xyz[2], entity, nodeTag); - break; - default: - return 0; - break; + if(swap) SwapBytes((char *)&nodeTag, sizeof(int), 1); + + if(fread(xyz, sizeof(double), 3, fp) != 3) { + return 0; + } + if(swap) SwapBytes((char *)xyz, sizeof(double), 3); + + double uv[2]; + if(fread(uv, sizeof(double), 2, fp) != 2) { + return 0; + } + if(swap) SwapBytes((char *)uv, sizeof(double), 2); + + u = uv[0]; + v = uv[1]; + } + else { + if(fscanf(fp, "%d %lf %lf %lf %lf %lf", &nodeTag, &xyz[0], &xyz[1], + &xyz[2], &u, &v) != 6) { + return 0; + } + } + vertex = + new MFaceVertex(xyz[0], xyz[1], xyz[2], entity, u, v, nodeTag); + break; + case 3: + if(binary) { + if(fread(&nodeTag, sizeof(int), 1, fp) != 1) { + return 0; + } + if(swap) SwapBytes((char *)&nodeTag, sizeof(int), 1); + + if(fread(xyz, sizeof(double), 3, fp) != 3) { + return 0; + } + if(swap) SwapBytes((char *)xyz, sizeof(double), 3); + } + else { + if(fscanf(fp, "%d %lf %lf %lf", &nodeTag, &xyz[0], &xyz[1], + &xyz[2]) != 4) { + return 0; + } + } + vertex = new MVertex(xyz[0], xyz[1], xyz[2], entity, nodeTag); + break; + default: return 0; break; } } - else{ - if(binary){ - if(fread(&nodeTag, sizeof(int), 1, fp) != 1){ + else { + if(binary) { + if(fread(&nodeTag, sizeof(int), 1, fp) != 1) { return 0; } - if(swap) SwapBytes((char*)&nodeTag, sizeof(int), 1); + if(swap) SwapBytes((char *)&nodeTag, sizeof(int), 1); - if(fread(xyz, sizeof(double), 3, fp) != 3){ + if(fread(xyz, sizeof(double), 3, fp) != 3) { return 0; } - if(swap) SwapBytes((char*)xyz, sizeof(double), 3); + if(swap) SwapBytes((char *)xyz, sizeof(double), 3); } - else{ - if(fscanf(fp, "%d %lf %lf %lf", - &nodeTag, &xyz[0], &xyz[1], &xyz[2]) != 4){ + else { + if(fscanf(fp, "%d %lf %lf %lf", &nodeTag, &xyz[0], &xyz[1], + &xyz[2]) != 4) { return 0; } } @@ -651,23 +637,25 @@ static std::pair<int, MVertex*> *readMSH4Nodes(GModel *const model, FILE* fp, minNodeNum = std::min(minNodeNum, (unsigned long)nodeTag); maxNodeNum = std::max(maxNodeNum, (unsigned long)nodeTag); - vertexCache[nodeRead] = std::pair<int, MVertex*>(nodeTag, vertex); - nodeRead ++; + vertexCache[nodeRead] = std::pair<int, MVertex *>(nodeTag, vertex); + nodeRead++; - if(nbrNodes > 100000) Msg::ProgressMeter(nodeRead, nbrNodes, true, "Reading nodes"); + if(nbrNodes > 100000) + Msg::ProgressMeter(nodeRead, nbrNodes, true, "Reading nodes"); } } // if the vertex numbering is (fairly) dense, we fill the vector cache, // otherwise we fill the map cache - if(minNodeNum == 1 && maxNodeNum == nbrNodes){ + if(minNodeNum == 1 && maxNodeNum == nbrNodes) { Msg::Debug("Vertex numbering is dense"); dense = true; } - else if(maxNodeNum < 10 * nbrNodes){ // - Msg::Debug("Vertex numbering is fairly dense - still caching with a vector"); + else if(maxNodeNum < 10 * nbrNodes) { // + Msg::Debug( + "Vertex numbering is fairly dense - still caching with a vector"); dense = true; } - else{ + else { Msg::Debug("Vertex numbering is not dense"); dense = false; } @@ -675,185 +663,192 @@ static std::pair<int, MVertex*> *readMSH4Nodes(GModel *const model, FILE* fp, return vertexCache; } -static std::pair<int, MElement*> *readMSH4Elements(GModel *const model, FILE* fp, - bool binary, bool &dense, - unsigned long &nbrElements, - unsigned long &maxElementNum, - bool swap) +static std::pair<int, MElement *> * +readMSH4Elements(GModel *const model, FILE *fp, bool binary, bool &dense, + unsigned long &nbrElements, unsigned long &maxElementNum, + bool swap) { char str[1024]; unsigned long numBlock = 0; nbrElements = 0; maxElementNum = 0; - if(binary){ + if(binary) { unsigned long data[2]; - if(fread(data, sizeof(unsigned long), 2, fp) != 2){ + if(fread(data, sizeof(unsigned long), 2, fp) != 2) { return 0; } - if(swap) SwapBytes((char*)data, sizeof(unsigned long), 2); + if(swap) SwapBytes((char *)data, sizeof(unsigned long), 2); numBlock = data[0]; nbrElements = data[1]; } - else{ - if(fscanf(fp, "%lu %lu", &numBlock, &nbrElements) != 2){ + else { + if(fscanf(fp, "%lu %lu", &numBlock, &nbrElements) != 2) { return 0; } } unsigned long elementRead = 0; unsigned long minElementNum = nbrElements + 1; - std::pair<int, MElement*> *elementCache = new std::pair<int, MElement*>[nbrElements]; + std::pair<int, MElement *> *elementCache = + new std::pair<int, MElement *>[nbrElements]; Msg::Info("%lu elements", nbrElements); - for(unsigned int i = 0; i < numBlock; i++){ + for(unsigned int i = 0; i < numBlock; i++) { int entityTag = 0, entityDim = 0, elmType = 0; unsigned long numElements = 0; - if(binary){ + if(binary) { int data[3]; - if(fread(data, sizeof(int), 3, fp) != 3){ + if(fread(data, sizeof(int), 3, fp) != 3) { return 0; } - if(swap) SwapBytes((char*)data, sizeof(int), 3); + if(swap) SwapBytes((char *)data, sizeof(int), 3); entityTag = data[0]; entityDim = data[1]; elmType = data[2]; unsigned long dataLong; - if(fread(&dataLong, sizeof(unsigned long), 1, fp) != 1){ + if(fread(&dataLong, sizeof(unsigned long), 1, fp) != 1) { return 0; } - if(swap) SwapBytes((char*)&dataLong, sizeof(unsigned long), 1); + if(swap) SwapBytes((char *)&dataLong, sizeof(unsigned long), 1); numElements = dataLong; } - else{ - if(fscanf(fp, "%d %d %d %lu", - &entityTag, &entityDim, &elmType, &numElements) != 4){ + else { + if(fscanf(fp, "%d %d %d %lu", &entityTag, &entityDim, &elmType, + &numElements) != 4) { return 0; } } GEntity *entity = model->getEntityByTag(entityDim, entityTag); - if(!entity){ + if(!entity) { Msg::Error("Unknown entity %d of dimension %d", entityTag, entityDim); return 0; } - if(entity->geomType() == GEntity::GhostCurve){ - static_cast<ghostEdge*>(entity)->haveMesh(true); + if(entity->geomType() == GEntity::GhostCurve) { + static_cast<ghostEdge *>(entity)->haveMesh(true); } - else if(entity->geomType() == GEntity::GhostSurface){ - static_cast<ghostFace*>(entity)->haveMesh(true); + else if(entity->geomType() == GEntity::GhostSurface) { + static_cast<ghostFace *>(entity)->haveMesh(true); } - else if(entity->geomType() == GEntity::GhostVolume){ - static_cast<ghostRegion*>(entity)->haveMesh(true); + else if(entity->geomType() == GEntity::GhostVolume) { + static_cast<ghostRegion *>(entity)->haveMesh(true); } int nbrVertices = MElement::getInfoMSH(elmType); - if(binary){ - int *data = new int[numElements*(nbrVertices+1)]; - if(fread(data, sizeof(int), numElements*(nbrVertices+1), fp) != - numElements*(nbrVertices+1)){ + if(binary) { + int *data = new int[numElements * (nbrVertices + 1)]; + if(fread(data, sizeof(int), numElements * (nbrVertices + 1), fp) != + numElements * (nbrVertices + 1)) { return 0; } - if(swap) SwapBytes((char*)data, sizeof(int), numElements*(nbrVertices+1)); - - std::vector<MVertex*> vertices(nbrVertices+1, (MVertex*)0); - for(unsigned int j = 0; j < numElements*(nbrVertices+1); j += (nbrVertices+1)){ - for(int k = 0; k < nbrVertices; k++){ - vertices[k] = model->getMeshVertexByTag(data[j+k+1]); - if(!vertices[k]){ - Msg::Error("Unknown vertex %d in element %d", data[j+k+1], data[j]); + if(swap) + SwapBytes((char *)data, sizeof(int), numElements * (nbrVertices + 1)); + + std::vector<MVertex *> vertices(nbrVertices + 1, (MVertex *)0); + for(unsigned int j = 0; j < numElements * (nbrVertices + 1); + j += (nbrVertices + 1)) { + for(int k = 0; k < nbrVertices; k++) { + vertices[k] = model->getMeshVertexByTag(data[j + k + 1]); + if(!vertices[k]) { + Msg::Error("Unknown vertex %d in element %d", data[j + k + 1], + data[j]); return 0; } } MElementFactory elementFactory; - MElement *element = elementFactory.create(elmType, vertices, data[j], - 0, false, 0, 0, 0, 0); + MElement *element = elementFactory.create(elmType, vertices, data[j], 0, + false, 0, 0, 0, 0); if(entity->geomType() != GEntity::GhostCurve && entity->geomType() != GEntity::GhostSurface && - entity->geomType() != GEntity::GhostVolume){ + entity->geomType() != GEntity::GhostVolume) { entity->addElement(element->getType(), element); } minElementNum = std::min(minElementNum, (unsigned long)data[j]); maxElementNum = std::max(maxElementNum, (unsigned long)data[j]); - elementCache[elementRead] = std::pair<int, MElement*>(data[j], element); - elementRead ++; + elementCache[elementRead] = + std::pair<int, MElement *>(data[j], element); + elementRead++; if(nbrElements > 100000) - Msg::ProgressMeter(elementRead, nbrElements, true, "Reading elements"); + Msg::ProgressMeter(elementRead, nbrElements, true, + "Reading elements"); } delete[] data; } - else{ - for(unsigned int j = 0; j < numElements; j++){ + else { + for(unsigned int j = 0; j < numElements; j++) { int elmTag = 0; - if(fscanf(fp, "%d", &elmTag) != 1){ + if(fscanf(fp, "%d", &elmTag) != 1) { return 0; } - if(!fgets(str, sizeof(str), fp)){ + if(!fgets(str, sizeof(str), fp)) { return 0; } - std::vector<MVertex*> vertices(nbrVertices+1, (MVertex*)0); + std::vector<MVertex *> vertices(nbrVertices + 1, (MVertex *)0); - for(int k = 0; k < nbrVertices; k++){ + for(int k = 0; k < nbrVertices; k++) { int vertexTag = 0; - if(k != nbrVertices-1){ - if(sscanf(str, "%d %[0-9- ]", &vertexTag, str) != 2){ + if(k != nbrVertices - 1) { + if(sscanf(str, "%d %[0-9- ]", &vertexTag, str) != 2) { return 0; } } - else{ - if(sscanf(str, "%d", &vertexTag) != 1){ + else { + if(sscanf(str, "%d", &vertexTag) != 1) { return 0; } } vertices[k] = model->getMeshVertexByTag(vertexTag); - if(!vertices[k]){ + if(!vertices[k]) { Msg::Error("Unknown vertex %d in element %d", vertexTag, elmTag); return 0; } } MElementFactory elementFactory; - MElement *element = elementFactory.create(elmType, vertices, elmTag, - 0, false, 0, 0, 0, 0); + MElement *element = elementFactory.create(elmType, vertices, elmTag, 0, + false, 0, 0, 0, 0); if(entity->geomType() != GEntity::GhostCurve && entity->geomType() != GEntity::GhostSurface && - entity->geomType() != GEntity::GhostVolume){ + entity->geomType() != GEntity::GhostVolume) { entity->addElement(element->getType(), element); } minElementNum = std::min(minElementNum, (unsigned long)elmTag); maxElementNum = std::max(maxElementNum, (unsigned long)elmTag); - elementCache[elementRead] = std::pair<int, MElement*>(elmTag, element); - elementRead ++; + elementCache[elementRead] = std::pair<int, MElement *>(elmTag, element); + elementRead++; if(nbrElements > 100000) - Msg::ProgressMeter(elementRead, nbrElements, true, "Reading elements"); + Msg::ProgressMeter(elementRead, nbrElements, true, + "Reading elements"); } } } // if the vertex numbering is dense, we fill the vector cache, otherwise we // fill the map cache - if(minElementNum == 1 && maxElementNum == nbrElements){ + if(minElementNum == 1 && maxElementNum == nbrElements) { Msg::Debug("Element numbering is dense"); dense = true; } - else if(maxElementNum < 10 * nbrElements){ - Msg::Debug("Element numbering is fairly dense - still caching with a vector"); + else if(maxElementNum < 10 * nbrElements) { + Msg::Debug( + "Element numbering is fairly dense - still caching with a vector"); dense = true; } - else{ + else { Msg::Debug("Element numbering is not dense"); dense = false; } @@ -861,147 +856,149 @@ static std::pair<int, MElement*> *readMSH4Elements(GModel *const model, FILE* fp return elementCache; } -static bool readMSH4PeriodicNodes(GModel *const model, FILE* fp, - bool binary, bool swap) +static bool readMSH4PeriodicNodes(GModel *const model, FILE *fp, bool binary, + bool swap) { int numPeriodicLinks = 0; - if(binary){ - if(fread(&numPeriodicLinks, sizeof(int), 1, fp) != 1){ + if(binary) { + if(fread(&numPeriodicLinks, sizeof(int), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&numPeriodicLinks, sizeof(int), 1); + if(swap) SwapBytes((char *)&numPeriodicLinks, sizeof(int), 1); } - else{ - if(fscanf(fp, "%d", &numPeriodicLinks) != 1){ + else { + if(fscanf(fp, "%d", &numPeriodicLinks) != 1) { return false; } } - for(int i = 0; i < numPeriodicLinks; i++){ + for(int i = 0; i < numPeriodicLinks; i++) { int slaveDim = 0, slaveTag = 0, masterTag = 0; - if(binary){ + if(binary) { int data[3]; - if(fread(&data, sizeof(int), 3, fp) != 3){ + if(fread(&data, sizeof(int), 3, fp) != 3) { return false; } - if(swap) SwapBytes((char*)data, sizeof(int), 3); + if(swap) SwapBytes((char *)data, sizeof(int), 3); slaveDim = data[0]; slaveTag = data[1]; masterTag = data[2]; } - else{ - if(fscanf(fp, "%d %d %d", &slaveDim, &slaveTag, &masterTag) != 3){ + else { + if(fscanf(fp, "%d %d %d", &slaveDim, &slaveTag, &masterTag) != 3) { return false; } } GEntity *slave = 0, *master = 0; - switch(slaveDim){ - case 0 : + switch(slaveDim) { + case 0: slave = model->getVertexByTag(slaveTag); master = model->getVertexByTag(masterTag); break; - case 1 : + case 1: slave = model->getEdgeByTag(slaveTag); master = model->getEdgeByTag(masterTag); break; - case 2 : + case 2: slave = model->getFaceByTag(masterTag); master = model->getFaceByTag(masterTag); break; } - if(!slave){ + if(!slave) { Msg::Error("Could not find periodic slave entity %d of dimension %d", slaveTag, slaveDim); return false; } - if(!master){ + if(!master) { Msg::Error("Could not find periodic master entity %d of dimension %d", masterTag, slaveDim); return false; } long correspondingVertexSize = 0; - if(binary){ - if(fread(&correspondingVertexSize, sizeof(long), 1, fp) != 1){ + if(binary) { + if(fread(&correspondingVertexSize, sizeof(long), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&correspondingVertexSize, sizeof(long), 1); + if(swap) SwapBytes((char *)&correspondingVertexSize, sizeof(long), 1); - if(correspondingVertexSize < 0){ //If there is an affine parameter + if(correspondingVertexSize < 0) { // If there is an affine parameter double data[16]; - if(fread(&data, sizeof(double), 16, fp) != 16){ + if(fread(&data, sizeof(double), 16, fp) != 16) { return false; } - if(swap) SwapBytes((char*)data, sizeof(double), 16); + if(swap) SwapBytes((char *)data, sizeof(double), 16); std::vector<double> tfo(16); - for(int j = 0; j < 16; j++){ + for(int j = 0; j < 16; j++) { tfo[j] = data[j]; } slave->setMeshMaster(master, tfo); - if(fread(&correspondingVertexSize, sizeof(long), 1, fp) != 1){ + if(fread(&correspondingVertexSize, sizeof(long), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&correspondingVertexSize, sizeof(long), 1); + if(swap) SwapBytes((char *)&correspondingVertexSize, sizeof(long), 1); } } - else{ + else { char affine[256]; - if(!fscanf(fp, "%s", affine)){ + if(!fscanf(fp, "%s", affine)) { return false; } - if(!strncmp(affine, "Affine", 6)){ - if(!fgets(affine, sizeof(affine), fp)){ + if(!strncmp(affine, "Affine", 6)) { + if(!fgets(affine, sizeof(affine), fp)) { return false; } std::vector<double> tfo(16); - if(sscanf(affine, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf " - "%lf %lf %lf %lf", &tfo[0], &tfo[1], &tfo[2], &tfo[3], &tfo[4], - &tfo[5], &tfo[6], &tfo[7], &tfo[8], &tfo[9], &tfo[10], &tfo[11], - &tfo[12], &tfo[13], &tfo[14], &tfo[15]) != 16){ + if(sscanf(affine, + "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf " + "%lf %lf %lf %lf", + &tfo[0], &tfo[1], &tfo[2], &tfo[3], &tfo[4], &tfo[5], &tfo[6], + &tfo[7], &tfo[8], &tfo[9], &tfo[10], &tfo[11], &tfo[12], + &tfo[13], &tfo[14], &tfo[15]) != 16) { return false; } slave->setMeshMaster(master, tfo); - if(fscanf(fp, "%lu", &correspondingVertexSize) != 1){ + if(fscanf(fp, "%lu", &correspondingVertexSize) != 1) { return false; } } - else{ + else { slave->setMeshMaster(master); - if(sscanf(affine, "%lu", &correspondingVertexSize) != 1){ + if(sscanf(affine, "%lu", &correspondingVertexSize) != 1) { return false; } } } - for(long j = 0; j < correspondingVertexSize; j++){ + for(long j = 0; j < correspondingVertexSize; j++) { int v1 = 0, v2 = 0; - if(binary){ + if(binary) { int data[2]; - if(fread(&data, sizeof(int), 2, fp) != 2){ + if(fread(&data, sizeof(int), 2, fp) != 2) { return false; } - if(swap) SwapBytes((char*)data, sizeof(int), 2); + if(swap) SwapBytes((char *)data, sizeof(int), 2); v1 = data[0]; v2 = data[1]; } - else{ - if(fscanf(fp, "%d %d", &v1, &v2) != 2){ + else { + if(fscanf(fp, "%d %d", &v1, &v2) != 2) { return false; } } MVertex *mv1 = model->getMeshVertexByTag(v1); MVertex *mv2 = model->getMeshVertexByTag(v2); - if(!mv1){ + if(!mv1) { Msg::Error("Could not find periodic vertex %d", v1); } - if(!mv2){ + if(!mv2) { Msg::Error("Could not find periodic vertex %d", v2); } @@ -1011,109 +1008,116 @@ static bool readMSH4PeriodicNodes(GModel *const model, FILE* fp, return true; } -static bool readMSH4GhostElements(GModel *const model, FILE* fp, - bool binary, bool swap) +static bool readMSH4GhostElements(GModel *const model, FILE *fp, bool binary, + bool swap) { int numGhostCells = 0; - if(binary){ - if(fread(&numGhostCells, sizeof(int), 1, fp) != 1){ + if(binary) { + if(fread(&numGhostCells, sizeof(int), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&numGhostCells, sizeof(int), 1); + if(swap) SwapBytes((char *)&numGhostCells, sizeof(int), 1); } - else{ - if(fscanf(fp, "%d", &numGhostCells) != 1){ + else { + if(fscanf(fp, "%d", &numGhostCells) != 1) { return false; } } - std::multimap< std::pair<MElement*, unsigned int> , unsigned int> ghostCells; - for(int i = 0; i < numGhostCells; i++){ + std::multimap<std::pair<MElement *, unsigned int>, unsigned int> ghostCells; + for(int i = 0; i < numGhostCells; i++) { int numElm = 0; int numPart = 0; unsigned int numGhost = 0; char str[1024]; - if(binary){ + if(binary) { int data[3]; - if(fread(&data, sizeof(int), 3, fp) != 3){ + if(fread(&data, sizeof(int), 3, fp) != 3) { return false; } - if(swap) SwapBytes((char*)data, sizeof(int), 3); + if(swap) SwapBytes((char *)data, sizeof(int), 3); numElm = data[0]; numPart = data[1]; numGhost = data[2]; } - else{ - if(fscanf(fp, "%d %d %d", &numElm, &numPart, &numGhost) != 3){ + else { + if(fscanf(fp, "%d %d %d", &numElm, &numPart, &numGhost) != 3) { return false; } - if(!fgets(str, sizeof(str), fp)){ + if(!fgets(str, sizeof(str), fp)) { return false; } } MElement *elm = model->getMeshElementByTag(numElm); - if(!elm){ + if(!elm) { Msg::Error("No element with tag %d", numElm); continue; } - for(unsigned int j = 0; j < numGhost; j++){ + for(unsigned int j = 0; j < numGhost; j++) { int ghostPartition = 0; - if(binary){ - if(fread(&ghostPartition, sizeof(int), 1, fp) != 1){ + if(binary) { + if(fread(&ghostPartition, sizeof(int), 1, fp) != 1) { return false; } - if(swap) SwapBytes((char*)&ghostPartition, sizeof(int), 1); + if(swap) SwapBytes((char *)&ghostPartition, sizeof(int), 1); } - else{ - if(j == numGhost-1){ - if(sscanf(str, "%d", &ghostPartition) != 1){ + else { + if(j == numGhost - 1) { + if(sscanf(str, "%d", &ghostPartition) != 1) { return false; } } - else{ - if(sscanf(str, "%d %[0-9- ]", &ghostPartition, str) != 2){ + else { + if(sscanf(str, "%d %[0-9- ]", &ghostPartition, str) != 2) { return false; } } } - ghostCells.insert(std::pair< std::pair<MElement*, unsigned int> , unsigned int> - ( std::pair<MElement*, unsigned int>(elm, numPart) , ghostPartition)); + ghostCells.insert( + std::pair<std::pair<MElement *, unsigned int>, unsigned int>( + std::pair<MElement *, unsigned int>(elm, numPart), ghostPartition)); } } - std::vector<GEntity*> ghostEntities(model->getNumPartitions() + 1, 0); - std::vector<GEntity*> entities; + std::vector<GEntity *> ghostEntities(model->getNumPartitions() + 1, 0); + std::vector<GEntity *> entities; model->getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ - if(entities[i]->geomType() == GEntity::GhostCurve){ - ghostEntities[static_cast<ghostEdge*>(entities[i])->getPartition()] = entities[i]; + for(unsigned int i = 0; i < entities.size(); i++) { + if(entities[i]->geomType() == GEntity::GhostCurve) { + ghostEntities[static_cast<ghostEdge *>(entities[i])->getPartition()] = + entities[i]; } - else if(entities[i]->geomType() == GEntity::GhostSurface){ - ghostEntities[static_cast<ghostFace*>(entities[i])->getPartition()] = entities[i]; + else if(entities[i]->geomType() == GEntity::GhostSurface) { + ghostEntities[static_cast<ghostFace *>(entities[i])->getPartition()] = + entities[i]; } - else if(entities[i]->geomType() == GEntity::GhostVolume){ - ghostEntities[static_cast<ghostRegion*>(entities[i])->getPartition()] = entities[i]; + else if(entities[i]->geomType() == GEntity::GhostVolume) { + ghostEntities[static_cast<ghostRegion *>(entities[i])->getPartition()] = + entities[i]; } } - for(std::multimap< std::pair<MElement*, unsigned int>, unsigned int>::iterator it = - ghostCells.begin(); it != ghostCells.end(); ++it){ - if(ghostEntities[it->first.second]->geomType() == GEntity::GhostCurve){ - static_cast<ghostEdge*>(ghostEntities[it->first.second])->addElement - (it->first.first->getType(), it->first.first, it->second); + for(std::multimap<std::pair<MElement *, unsigned int>, unsigned int>::iterator + it = ghostCells.begin(); + it != ghostCells.end(); ++it) { + if(ghostEntities[it->first.second]->geomType() == GEntity::GhostCurve) { + static_cast<ghostEdge *>(ghostEntities[it->first.second]) + ->addElement(it->first.first->getType(), it->first.first, it->second); } - else if(ghostEntities[it->first.second]->geomType() == GEntity::GhostSurface){ - static_cast<ghostFace*>(ghostEntities[it->first.second])->addElement - (it->first.first->getType(), it->first.first, it->second); + else if(ghostEntities[it->first.second]->geomType() == + GEntity::GhostSurface) { + static_cast<ghostFace *>(ghostEntities[it->first.second]) + ->addElement(it->first.first->getType(), it->first.first, it->second); } - else if(ghostEntities[it->first.second]->geomType() == GEntity::GhostVolume){ - static_cast<ghostRegion*>(ghostEntities[it->first.second])->addElement - (it->first.first->getType(), it->first.first, it->second); + else if(ghostEntities[it->first.second]->geomType() == + GEntity::GhostVolume) { + static_cast<ghostRegion *>(ghostEntities[it->first.second]) + ->addElement(it->first.first->getType(), it->first.first, it->second); } } return true; @@ -1123,7 +1127,7 @@ int GModel::_readMSH4(const std::string &name) { bool partitioned = false; FILE *fp = Fopen(name.c_str(), "rb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -1132,178 +1136,180 @@ int GModel::_readMSH4(const std::string &name) double version = 1.0; bool binary = false, swap = false, postpro = false; - while(1){ - while(str[0] != '$'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(1) { + while(str[0] != '$') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } std::string sectionName(&str[1]); std::string endSectionName = "End" + sectionName; - if(feof(fp)) - break; + if(feof(fp)) break; - if(!strncmp(&str[1], "MeshFormat", 10)){ - if(!fgets(str, sizeof(str), fp) || feof(fp)){ + if(!strncmp(&str[1], "MeshFormat", 10)) { + if(!fgets(str, sizeof(str), fp) || feof(fp)) { fclose(fp); return 0; } int format; unsigned long size; - if(sscanf(str, "%lf %d %lu", &version, &format, &size) != 3){ + if(sscanf(str, "%lf %d %lu", &version, &format, &size) != 3) { fclose(fp); return 0; } - if(format){ + if(format) { binary = true; Msg::Debug("Mesh is in binary format"); int one; - if(fread(&one, sizeof(int), 1, fp) != 1){ + if(fread(&one, sizeof(int), 1, fp) != 1) { fclose(fp); return 0; } - if(one != 1){ + if(one != 1) { swap = true; Msg::Debug("Swapping bytes from binary file"); } } } - else if(!strncmp(&str[1], "PhysicalNames", 13)){ - if(!fgets(str, sizeof(str), fp) || feof(fp)){ + else if(!strncmp(&str[1], "PhysicalNames", 13)) { + if(!fgets(str, sizeof(str), fp) || feof(fp)) { fclose(fp); return 0; } int numPhysicalNames = 0; - if(sscanf(str, "%d", &numPhysicalNames) != 1){ + if(sscanf(str, "%d", &numPhysicalNames) != 1) { fclose(fp); return 0; } std::vector<GModel::piter> iterators; getInnerPhysicalNamesIterators(iterators); - for(int i = 0; i < numPhysicalNames; i++){ + for(int i = 0; i < numPhysicalNames; i++) { int dim = 0, tag = 0; - if(fscanf(fp, "%d %d", &dim, &tag) != 2){ + if(fscanf(fp, "%d %d", &dim, &tag) != 2) { fclose(fp); return 0; } char name[128]; - if(!fgets(name, sizeof(name), fp)){ + if(!fgets(name, sizeof(name), fp)) { fclose(fp); return 0; } std::string physicalName = ExtractDoubleQuotedString(name, 128); if(physicalName.size()) - iterators[dim] = setPhysicalName(iterators[dim], physicalName, dim, tag); + iterators[dim] = + setPhysicalName(iterators[dim], physicalName, dim, tag); } } - else if(!strncmp(&str[1], "Entities", 8)){ - if(!readMSH4Entities(this, fp, false, binary, swap)){ + else if(!strncmp(&str[1], "Entities", 8)) { + if(!readMSH4Entities(this, fp, false, binary, swap)) { Msg::Error("Could not read entities"); fclose(fp); return 0; } } - else if(!strncmp(&str[1], "PartitionedEntities", 19)){ - if(!readMSH4Entities(this, fp, true, binary, swap)){ + else if(!strncmp(&str[1], "PartitionedEntities", 19)) { + if(!readMSH4Entities(this, fp, true, binary, swap)) { Msg::Error("Could not read partitioned entities"); fclose(fp); return 0; } partitioned = true; } - else if(!strncmp(&str[1], "Nodes", 5)){ + else if(!strncmp(&str[1], "Nodes", 5)) { _vertexVectorCache.clear(); _vertexMapCache.clear(); Msg::ResetProgressMeter(); bool dense = false; unsigned long nbrNodes = 0, maxNodeNum; - std::pair<int, MVertex*> *vertexCache = readMSH4Nodes - (this, fp, binary, dense, nbrNodes, maxNodeNum, swap); - if(!vertexCache){ + std::pair<int, MVertex *> *vertexCache = + readMSH4Nodes(this, fp, binary, dense, nbrNodes, maxNodeNum, swap); + if(!vertexCache) { Msg::Error("Could not read vertices"); fclose(fp); return false; } - if(dense){ + if(dense) { _vertexVectorCache.resize(maxNodeNum + 1, 0); - for(unsigned int i = 0; i < nbrNodes; i++){ - if(!_vertexVectorCache[vertexCache[i].first]){ + for(unsigned int i = 0; i < nbrNodes; i++) { + if(!_vertexVectorCache[vertexCache[i].first]) { _vertexVectorCache[vertexCache[i].first] = vertexCache[i].second; } - else{ + else { Msg::Warning("Skipping duplicate vertex %d", vertexCache[i].first); } } } - else{ - for(unsigned int i = 0; i < nbrNodes; i++){ - if(_vertexMapCache.count(vertexCache[i].first) == 0){ + else { + for(unsigned int i = 0; i < nbrNodes; i++) { + if(_vertexMapCache.count(vertexCache[i].first) == 0) { _vertexMapCache[vertexCache[i].first] = vertexCache[i].second; } - else{ + else { Msg::Warning("Skipping duplicate vertex %d", vertexCache[i].first); } } } delete[] vertexCache; } - else if(!strncmp(&str[1], "Elements", 8)){ + else if(!strncmp(&str[1], "Elements", 8)) { Msg::ResetProgressMeter(); bool dense = false; unsigned long nbrElements = 0, maxElementNum = 0; - std::pair<int, MElement*> *elementCache = readMSH4Elements - (this, fp, binary, dense, nbrElements, maxElementNum, swap); - if(!elementCache){ + std::pair<int, MElement *> *elementCache = readMSH4Elements( + this, fp, binary, dense, nbrElements, maxElementNum, swap); + if(!elementCache) { Msg::Error("Could not read elements"); fclose(fp); return 0; } - if(dense){ - _elementVectorCache.resize(maxElementNum + 1, (MElement*)0); - for(unsigned int i = 0; i < nbrElements; i++){ - if(!_elementVectorCache[elementCache[i].first]){ + if(dense) { + _elementVectorCache.resize(maxElementNum + 1, (MElement *)0); + for(unsigned int i = 0; i < nbrElements; i++) { + if(!_elementVectorCache[elementCache[i].first]) { _elementVectorCache[elementCache[i].first] = elementCache[i].second; } - else{ - Msg::Warning("Skipping duplicate element %d", elementCache[i].first); + else { + Msg::Warning("Skipping duplicate element %d", + elementCache[i].first); } } } - else{ - for(unsigned int i = 0; i < nbrElements; i++){ - if(_elementMapCache.count(elementCache[i].first) == 0){ + else { + for(unsigned int i = 0; i < nbrElements; i++) { + if(_elementMapCache.count(elementCache[i].first) == 0) { _elementMapCache[elementCache[i].first] = elementCache[i].second; } - else{ - Msg::Warning("Skipping duplicate element %d", elementCache[i].first); + else { + Msg::Warning("Skipping duplicate element %d", + elementCache[i].first); } } } delete[] elementCache; } - else if(!strncmp(&str[1], "Periodic", 8)){ - if(!readMSH4PeriodicNodes(this, fp, binary, swap)){ + else if(!strncmp(&str[1], "Periodic", 8)) { + if(!readMSH4PeriodicNodes(this, fp, binary, swap)) { Msg::Error("Could not read periodic section"); fclose(fp); return 0; } } - else if(!strncmp(&str[1], "GhostElements", 13)){ - if(!readMSH4GhostElements(this, fp, binary, swap)){ + else if(!strncmp(&str[1], "GhostElements", 13)) { + if(!readMSH4GhostElements(this, fp, binary, swap)) { Msg::Error("Could not read ghost elements"); fclose(fp); return 0; } } - else if(!strncmp(&str[1], "NodeData", 8) || !strncmp(&str[1], "ElementData", 11) || - !strncmp(&str[1], "ElementNodeData", 15)){ + else if(!strncmp(&str[1], "NodeData", 8) || + !strncmp(&str[1], "ElementData", 11) || + !strncmp(&str[1], "ElementNodeData", 15)) { postpro = true; break; } - while(strncmp(&str[1], endSectionName.c_str(), endSectionName.size())){ - if(!fgets(str, sizeof(str), fp) || feof(fp)){ + while(strncmp(&str[1], endSectionName.c_str(), endSectionName.size())) { + if(!fgets(str, sizeof(str), fp) || feof(fp)) { break; } } @@ -1312,44 +1318,44 @@ int GModel::_readMSH4(const std::string &name) fclose(fp); - if(partitioned){ + if(partitioned) { // This part is added to ensure the compatibility between the new // partitioning and the old one. - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ - if(entities[i]->geomType() == GEntity::PartitionVertex){ - partitionVertex *pv = static_cast<partitionVertex*>(entities[i]); - if(pv->numPartitions() == 1){ + for(unsigned int i = 0; i < entities.size(); i++) { + if(entities[i]->geomType() == GEntity::PartitionVertex) { + partitionVertex *pv = static_cast<partitionVertex *>(entities[i]); + if(pv->numPartitions() == 1) { const unsigned int part = pv->getPartition(0); - for(unsigned int j = 0; j < pv->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < pv->getNumMeshElements(); j++) { pv->getMeshElement(j)->setPartition(part); } } } - else if(entities[i]->geomType() == GEntity::PartitionCurve){ - partitionEdge *pe = static_cast<partitionEdge*>(entities[i]); - if(pe->numPartitions() == 1){ + else if(entities[i]->geomType() == GEntity::PartitionCurve) { + partitionEdge *pe = static_cast<partitionEdge *>(entities[i]); + if(pe->numPartitions() == 1) { const unsigned int part = pe->getPartition(0); - for(unsigned int j = 0; j < pe->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < pe->getNumMeshElements(); j++) { pe->getMeshElement(j)->setPartition(part); } } } - else if(entities[i]->geomType() == GEntity::PartitionSurface){ - partitionFace *pf = static_cast<partitionFace*>(entities[i]); - if(pf->numPartitions() == 1){ + else if(entities[i]->geomType() == GEntity::PartitionSurface) { + partitionFace *pf = static_cast<partitionFace *>(entities[i]); + if(pf->numPartitions() == 1) { const unsigned int part = pf->getPartition(0); - for(unsigned int j = 0; j < pf->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < pf->getNumMeshElements(); j++) { pf->getMeshElement(j)->setPartition(part); } } } - else if(entities[i]->geomType() == GEntity::PartitionVolume){ - partitionRegion *pr = static_cast<partitionRegion*>(entities[i]); - if(pr->numPartitions() == 1){ + else if(entities[i]->geomType() == GEntity::PartitionVolume) { + partitionRegion *pr = static_cast<partitionRegion *>(entities[i]); + if(pr->numPartitions() == 1) { const unsigned int part = pr->getPartition(0); - for(unsigned int j = 0; j < pr->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < pr->getNumMeshElements(); j++) { pr->getMeshElement(j)->setPartition(part); } } @@ -1362,19 +1368,19 @@ int GModel::_readMSH4(const std::string &name) static void writeMSH4Physicals(FILE *fp, GEntity *const entity, bool binary) { - if(binary){ + if(binary) { std::vector<int> phys = entity->getPhysicalEntities(); unsigned long phySize = phys.size(); fwrite(&phySize, sizeof(unsigned long), 1, fp); - for(unsigned int i = 0; i < phys.size(); i++){ + for(unsigned int i = 0; i < phys.size(); i++) { int phy = phys[i]; fwrite(&phy, sizeof(int), 1, fp); } } - else{ + else { std::vector<int> phys = entity->getPhysicalEntities(); fprintf(fp, "%lu", phys.size()); - for(unsigned int i = 0; i < phys.size(); i++){ + for(unsigned int i = 0; i < phys.size(); i++) { fprintf(fp, " %d", phys[i]); } fprintf(fp, " "); @@ -1385,7 +1391,7 @@ static void writeMSH4BoundingBox(SBoundingBox3d boundBox, FILE *fp, double scalingFactor, bool binary) { double bb[6] = {0., 0., 0., 0., 0., 0.}; - if(!boundBox.empty()){ + if(!boundBox.empty()) { boundBox *= scalingFactor; bb[0] = boundBox.min().x(); bb[1] = boundBox.min().y(); @@ -1394,10 +1400,10 @@ static void writeMSH4BoundingBox(SBoundingBox3d boundBox, FILE *fp, bb[4] = boundBox.max().y(); bb[5] = boundBox.max().z(); } - if(binary){ + if(binary) { fwrite(bb, sizeof(double), 6, fp); } - else{ + else { for(int i = 0; i < 6; i++) fprintf(fp, "%.16g ", bb[i]); } } @@ -1405,55 +1411,51 @@ static void writeMSH4BoundingBox(SBoundingBox3d boundBox, FILE *fp, static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, bool binary, double scalingFactor) { - std::set<GEntity*, GEntityLessThan> ghost; - std::set<GRegion*, GEntityLessThan> regions; - std::set<GFace*, GEntityLessThan> faces; - std::set<GEdge*, GEntityLessThan> edges; - std::set<GVertex*, GEntityLessThan> vertices; - - if(partition){ - for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); ++it){ - if((*it)->geomType() == GEntity::PartitionVertex) - vertices.insert(*it); - } - for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it){ - if((*it)->geomType() == GEntity::PartitionCurve) - edges.insert(*it); - if((*it)->geomType() == GEntity::GhostCurve) - ghost.insert(*it); - } - for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it){ - if((*it)->geomType() == GEntity::PartitionSurface) - faces.insert(*it); - if((*it)->geomType() == GEntity::GhostSurface) - ghost.insert(*it); - } - for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); ++it){ - if((*it)->geomType() == GEntity::PartitionVolume) - regions.insert(*it); - if((*it)->geomType() == GEntity::GhostVolume) - ghost.insert(*it); - } - } - else{ - for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); ++it) - if((*it)->geomType() != GEntity::PartitionVertex) - vertices.insert(*it); + std::set<GEntity *, GEntityLessThan> ghost; + std::set<GRegion *, GEntityLessThan> regions; + std::set<GFace *, GEntityLessThan> faces; + std::set<GEdge *, GEntityLessThan> edges; + std::set<GVertex *, GEntityLessThan> vertices; + + if(partition) { + for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); + ++it) { + if((*it)->geomType() == GEntity::PartitionVertex) vertices.insert(*it); + } + for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it) { + if((*it)->geomType() == GEntity::PartitionCurve) edges.insert(*it); + if((*it)->geomType() == GEntity::GhostCurve) ghost.insert(*it); + } + for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it) { + if((*it)->geomType() == GEntity::PartitionSurface) faces.insert(*it); + if((*it)->geomType() == GEntity::GhostSurface) ghost.insert(*it); + } + for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); + ++it) { + if((*it)->geomType() == GEntity::PartitionVolume) regions.insert(*it); + if((*it)->geomType() == GEntity::GhostVolume) ghost.insert(*it); + } + } + else { + for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); + ++it) + if((*it)->geomType() != GEntity::PartitionVertex) vertices.insert(*it); for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it) - if((*it)->geomType() != GEntity::PartitionCurve && (*it)->geomType() != - GEntity::GhostCurve) + if((*it)->geomType() != GEntity::PartitionCurve && + (*it)->geomType() != GEntity::GhostCurve) edges.insert(*it); for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it) - if((*it)->geomType() != GEntity::PartitionSurface && (*it)->geomType() != - GEntity::GhostSurface) + if((*it)->geomType() != GEntity::PartitionSurface && + (*it)->geomType() != GEntity::GhostSurface) faces.insert(*it); - for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); ++it) - if((*it)->geomType() != GEntity::PartitionVolume && (*it)->geomType() != - GEntity::GhostVolume) + for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); + ++it) + if((*it)->geomType() != GEntity::PartitionVolume && + (*it)->geomType() != GEntity::GhostVolume) regions.insert(*it); } - if(binary){ + if(binary) { if(partition) { unsigned int nparts = model->getNumPartitions(); fwrite(&nparts, sizeof(unsigned int), 1, fp); @@ -1461,30 +1463,30 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, // write the ghostentities' tag unsigned int ghostSize = ghost.size(); int *tags = 0; - if(ghostSize){ + if(ghostSize) { tags = new int[2 * ghostSize]; int index = 0; - for(std::set<GEntity*, GEntityLessThan>::iterator it = ghost.begin(); - it != ghost.end(); ++it){ - if((*it)->geomType() == GEntity::GhostCurve){ + for(std::set<GEntity *, GEntityLessThan>::iterator it = ghost.begin(); + it != ghost.end(); ++it) { + if((*it)->geomType() == GEntity::GhostCurve) { tags[index] = (*it)->tag(); - tags[++index] = static_cast<ghostEdge*>(*it)->getPartition(); + tags[++index] = static_cast<ghostEdge *>(*it)->getPartition(); } - else if((*it)->geomType() == GEntity::GhostSurface){ + else if((*it)->geomType() == GEntity::GhostSurface) { tags[index] = (*it)->tag(); - tags[++index] = static_cast<ghostFace*>(*it)->getPartition(); + tags[++index] = static_cast<ghostFace *>(*it)->getPartition(); } - else if((*it)->geomType() == GEntity::GhostVolume){ + else if((*it)->geomType() == GEntity::GhostVolume) { tags[index] = (*it)->tag(); - tags[++index] = static_cast<ghostRegion*>(*it)->getPartition(); + tags[++index] = static_cast<ghostRegion *>(*it)->getPartition(); } index++; } } fwrite(&ghostSize, sizeof(int), 1, fp); - if(tags){ - fwrite(tags, sizeof(int), 2*ghostSize, fp); - delete [] tags; + if(tags) { + fwrite(tags, sizeof(int), 2 * ghostSize, fp); + delete[] tags; } } unsigned long verticesSize = vertices.size(); @@ -1496,13 +1498,13 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, fwrite(&facesSize, sizeof(unsigned long), 1, fp); fwrite(®ionsSize, sizeof(unsigned long), 1, fp); - for(GModel::viter it = vertices.begin(); it != vertices.end(); ++it){ + for(GModel::viter it = vertices.begin(); it != vertices.end(); ++it) { int entityTag = (*it)->tag(); fwrite(&entityTag, sizeof(int), 1, fp); - if(partition){ - partitionVertex *pv = static_cast<partitionVertex*>(*it); + if(partition) { + partitionVertex *pv = static_cast<partitionVertex *>(*it); int parentEntityDim = 0, parentEntityTag = 0; - if(pv->getParentEntity()){ + if(pv->getParentEntity()) { parentEntityDim = pv->getParentEntity()->dim(); parentEntityTag = pv->getParentEntity()->tag(); } @@ -1516,10 +1518,10 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, writeMSH4Physicals(fp, *it, binary); } - for(GModel::eiter it = edges.begin(); it != edges.end(); ++it){ - std::vector<GVertex*> vertices; + for(GModel::eiter it = edges.begin(); it != edges.end(); ++it) { + std::vector<GVertex *> vertices; std::vector<int> ori; - if((*it)->getBeginVertex()){ + if((*it)->getBeginVertex()) { vertices.push_back((*it)->getBeginVertex()); ori.push_back(1); } @@ -1530,10 +1532,10 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, unsigned long verticesSize = vertices.size(); int entityTag = (*it)->tag(); fwrite(&entityTag, sizeof(int), 1, fp); - if(partition){ - partitionEdge *pe = static_cast<partitionEdge*>(*it); + if(partition) { + partitionEdge *pe = static_cast<partitionEdge *>(*it); int parentEntityDim = 0, parentEntityTag = 0; - if(pe->getParentEntity()){ + if(pe->getParentEntity()) { parentEntityDim = pe->getParentEntity()->dim(); parentEntityTag = pe->getParentEntity()->tag(); } @@ -1547,24 +1549,24 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, writeMSH4Physicals(fp, *it, binary); fwrite(&verticesSize, sizeof(unsigned long), 1, fp); int oriI = 0; - for(std::vector<GVertex*>::const_iterator itv = vertices.begin(); - itv != vertices.end(); itv++){ + for(std::vector<GVertex *>::const_iterator itv = vertices.begin(); + itv != vertices.end(); itv++) { int brepTag = ori[oriI] * (*itv)->tag(); fwrite(&brepTag, sizeof(int), 1, fp); oriI++; } } - for(GModel::fiter it = faces.begin(); it != faces.end(); ++it){ - std::vector<GEdge*> const& edges = (*it)->edges(); - std::vector<int> const& ori = (*it)->edgeOrientations(); + for(GModel::fiter it = faces.begin(); it != faces.end(); ++it) { + std::vector<GEdge *> const &edges = (*it)->edges(); + std::vector<int> const &ori = (*it)->edgeOrientations(); unsigned long edgesSize = edges.size(); int entityTag = (*it)->tag(); fwrite(&entityTag, sizeof(int), 1, fp); - if(partition){ - partitionFace *pf = static_cast<partitionFace*>(*it); + if(partition) { + partitionFace *pf = static_cast<partitionFace *>(*it); int parentEntityDim = 0, parentEntityTag = 0; - if(pf->getParentEntity()){ + if(pf->getParentEntity()) { parentEntityDim = pf->getParentEntity()->dim(); parentEntityTag = pf->getParentEntity()->tag(); } @@ -1578,31 +1580,32 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, writeMSH4Physicals(fp, *it, binary); fwrite(&edgesSize, sizeof(unsigned long), 1, fp); std::vector<int> tags, signs; - for(std::vector<GEdge*>::const_iterator ite = edges.begin(); ite != edges.end(); ite++) + for(std::vector<GEdge *>::const_iterator ite = edges.begin(); + ite != edges.end(); ite++) tags.push_back((*ite)->tag()); signs.insert(signs.end(), ori.begin(), ori.end()); - if(tags.size() == signs.size()){ + if(tags.size() == signs.size()) { for(unsigned int i = 0; i < tags.size(); i++) tags[i] *= (signs[i] > 0 ? 1 : -1); } - for(unsigned int i = 0; i < tags.size(); i++){ + for(unsigned int i = 0; i < tags.size(); i++) { int brepTag = tags[i]; fwrite(&brepTag, sizeof(int), 1, fp); } } - for(GModel::riter it = regions.begin(); it != regions.end(); ++it){ - std::vector<GFace*> faces = (*it)->faces(); - std::vector<int> const& ori = (*it)->faceOrientations(); + for(GModel::riter it = regions.begin(); it != regions.end(); ++it) { + std::vector<GFace *> faces = (*it)->faces(); + std::vector<int> const &ori = (*it)->faceOrientations(); unsigned long facesSize = faces.size(); int entityTag = (*it)->tag(); fwrite(&entityTag, sizeof(int), 1, fp); - if(partition){ - partitionRegion *pr = static_cast<partitionRegion*>(*it); + if(partition) { + partitionRegion *pr = static_cast<partitionRegion *>(*it); int parentEntityDim = 0, parentEntityTag = 0; - if(pr->getParentEntity()){ + if(pr->getParentEntity()) { parentEntityDim = pr->getParentEntity()->dim(); parentEntityTag = pr->getParentEntity()->tag(); } @@ -1616,65 +1619,67 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, writeMSH4Physicals(fp, *it, binary); fwrite(&facesSize, sizeof(unsigned long), 1, fp); std::vector<int> tags, signs; - for(std::vector<GFace*>::iterator itf = faces.begin(); itf != faces.end(); itf++) + for(std::vector<GFace *>::iterator itf = faces.begin(); + itf != faces.end(); itf++) tags.push_back((*itf)->tag()); - for(std::vector<int>::const_iterator itf = ori.begin(); itf != ori.end(); itf++) + for(std::vector<int>::const_iterator itf = ori.begin(); itf != ori.end(); + itf++) signs.push_back(*itf); - if(tags.size() == signs.size()){ + if(tags.size() == signs.size()) { for(unsigned int i = 0; i < tags.size(); i++) tags[i] *= (signs[i] > 0 ? 1 : -1); } - for(unsigned int i = 0; i < tags.size(); i++){ + for(unsigned int i = 0; i < tags.size(); i++) { int brepTag = tags[i]; fwrite(&brepTag, sizeof(int), 1, fp); } } fprintf(fp, "\n"); } - else{ - if(partition){ + else { + if(partition) { fprintf(fp, "%d\n", model->getNumPartitions()); // write the ghostentities' tag unsigned int ghostSize = ghost.size(); int *tags = 0; - if(ghostSize){ - tags = new int[2*ghostSize]; + if(ghostSize) { + tags = new int[2 * ghostSize]; int index = 0; - for(std::set<GEntity*, GEntityLessThan>::iterator it = ghost.begin(); - it != ghost.end(); ++it){ - if((*it)->geomType() == GEntity::GhostCurve){ + for(std::set<GEntity *, GEntityLessThan>::iterator it = ghost.begin(); + it != ghost.end(); ++it) { + if((*it)->geomType() == GEntity::GhostCurve) { tags[index] = (*it)->tag(); - tags[++index] = static_cast<ghostEdge*>(*it)->getPartition(); + tags[++index] = static_cast<ghostEdge *>(*it)->getPartition(); } - else if((*it)->geomType() == GEntity::GhostSurface){ + else if((*it)->geomType() == GEntity::GhostSurface) { tags[index] = (*it)->tag(); - tags[++index] = static_cast<ghostFace*>(*it)->getPartition(); + tags[++index] = static_cast<ghostFace *>(*it)->getPartition(); } - else if((*it)->geomType() == GEntity::GhostVolume){ + else if((*it)->geomType() == GEntity::GhostVolume) { tags[index] = (*it)->tag(); - tags[++index] = static_cast<ghostRegion*>(*it)->getPartition(); + tags[++index] = static_cast<ghostRegion *>(*it)->getPartition(); } index++; } } fprintf(fp, "%d\n", ghostSize); - if(tags){ - for(unsigned int i = 0; i < 2 * ghostSize; i += 2){ - fprintf(fp, "%d %d\n", tags[i], tags[i+1]); + if(tags) { + for(unsigned int i = 0; i < 2 * ghostSize; i += 2) { + fprintf(fp, "%d %d\n", tags[i], tags[i + 1]); } - delete [] tags; + delete[] tags; } } - fprintf(fp, "%lu %lu %lu %lu\n", - vertices.size(), edges.size(), faces.size(), regions.size()); + fprintf(fp, "%lu %lu %lu %lu\n", vertices.size(), edges.size(), + faces.size(), regions.size()); - for(GModel::viter it = vertices.begin(); it != vertices.end(); ++it){ + for(GModel::viter it = vertices.begin(); it != vertices.end(); ++it) { fprintf(fp, "%d ", (*it)->tag()); - if(partition){ - partitionVertex *pv = static_cast<partitionVertex*>(*it); + if(partition) { + partitionVertex *pv = static_cast<partitionVertex *>(*it); int parentEntityDim = 0, parentEntityTag = 0; - if(pv->getParentEntity()){ + if(pv->getParentEntity()) { parentEntityDim = pv->getParentEntity()->dim(); parentEntityTag = pv->getParentEntity()->tag(); } @@ -1689,22 +1694,23 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, fprintf(fp, "\n"); } - for(GModel::eiter it = edges.begin(); it != edges.end(); ++it){ - std::vector<GVertex*> vertices; + for(GModel::eiter it = edges.begin(); it != edges.end(); ++it) { + std::vector<GVertex *> vertices; std::vector<int> ori; - if((*it)->getBeginVertex()){ + if((*it)->getBeginVertex()) { vertices.push_back((*it)->getBeginVertex()); ori.push_back(1); } - if((*it)->getEndVertex()) { // I use the convention that the end vertex is negative + if((*it)->getEndVertex()) { // I use the convention that the end vertex is + // negative vertices.push_back((*it)->getEndVertex()); ori.push_back(-1); } fprintf(fp, "%d ", (*it)->tag()); - if(partition){ - partitionEdge *pe = static_cast<partitionEdge*>(*it); + if(partition) { + partitionEdge *pe = static_cast<partitionEdge *>(*it); int parentEntityDim = 0, parentEntityTag = 0; - if(pe->getParentEntity()){ + if(pe->getParentEntity()) { parentEntityDim = pe->getParentEntity()->dim(); parentEntityTag = pe->getParentEntity()->tag(); } @@ -1718,22 +1724,22 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, writeMSH4Physicals(fp, *it, binary); fprintf(fp, "%lu ", vertices.size()); int oriI = 0; - for(std::vector<GVertex*>::iterator itv = vertices.begin(); - itv != vertices.end(); itv++){ - fprintf(fp, "%d ", ori[oriI]*(*itv)->tag()); + for(std::vector<GVertex *>::iterator itv = vertices.begin(); + itv != vertices.end(); itv++) { + fprintf(fp, "%d ", ori[oriI] * (*itv)->tag()); oriI++; } fprintf(fp, "\n"); } - for(GModel::fiter it = faces.begin(); it != faces.end(); ++it){ - std::vector<GEdge*> const& edges = (*it)->edges(); - std::vector<int> const& ori = (*it)->edgeOrientations(); + for(GModel::fiter it = faces.begin(); it != faces.end(); ++it) { + std::vector<GEdge *> const &edges = (*it)->edges(); + std::vector<int> const &ori = (*it)->edgeOrientations(); fprintf(fp, "%d ", (*it)->tag()); - if(partition){ - partitionFace *pf = static_cast<partitionFace*>(*it); + if(partition) { + partitionFace *pf = static_cast<partitionFace *>(*it); int parentEntityDim = 0, parentEntityTag = 0; - if(pf->getParentEntity()){ + if(pf->getParentEntity()) { parentEntityDim = pf->getParentEntity()->dim(); parentEntityTag = pf->getParentEntity()->tag(); } @@ -1747,27 +1753,28 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, writeMSH4Physicals(fp, *it, binary); fprintf(fp, "%lu ", edges.size()); std::vector<int> tags, signs; - for(std::vector<GEdge*>::const_iterator ite = edges.begin(); ite != edges.end(); ite++) + for(std::vector<GEdge *>::const_iterator ite = edges.begin(); + ite != edges.end(); ite++) tags.push_back((*ite)->tag()); - for(std::vector<int>::const_iterator ite = ori.begin(); ite != ori.end(); ite++) + for(std::vector<int>::const_iterator ite = ori.begin(); ite != ori.end(); + ite++) signs.push_back(*ite); - if(tags.size() == signs.size()){ + if(tags.size() == signs.size()) { for(unsigned int i = 0; i < tags.size(); i++) tags[i] *= (signs[i] > 0 ? 1 : -1); } - for(unsigned int i = 0; i < tags.size(); i++) - fprintf(fp, "%d ", tags[i]); + for(unsigned int i = 0; i < tags.size(); i++) fprintf(fp, "%d ", tags[i]); fprintf(fp, "\n"); } - for(GModel::riter it = regions.begin(); it != regions.end(); ++it){ - std::vector<GFace*> const& faces = (*it)->faces(); - std::vector<int> const& ori = (*it)->faceOrientations(); + for(GModel::riter it = regions.begin(); it != regions.end(); ++it) { + std::vector<GFace *> const &faces = (*it)->faces(); + std::vector<int> const &ori = (*it)->faceOrientations(); fprintf(fp, "%d ", (*it)->tag()); - if(partition){ - partitionRegion *pr = static_cast<partitionRegion*>(*it); + if(partition) { + partitionRegion *pr = static_cast<partitionRegion *>(*it); int parentEntityDim = 0, parentEntityTag = 0; - if(pr->getParentEntity()){ + if(pr->getParentEntity()) { parentEntityDim = pr->getParentEntity()->dim(); parentEntityTag = pr->getParentEntity()->tag(); } @@ -1783,151 +1790,155 @@ static void writeMSH4Entities(GModel *const model, FILE *fp, bool partition, // TODO C++11 std::transform or similiar std::vector<int> tags; tags.reserve(faces.size()); - for(std::vector<GFace*>::const_iterator itf = faces.begin(); itf != faces.end(); itf++) + for(std::vector<GFace *>::const_iterator itf = faces.begin(); + itf != faces.end(); itf++) tags.push_back((*itf)->tag()); - std::vector<int> signs(ori.begin(), ori.end()); + std::vector<int> signs(ori.begin(), ori.end()); - if(tags.size() == signs.size()){ + if(tags.size() == signs.size()) { for(unsigned int i = 0; i < tags.size(); i++) tags[i] *= (signs[i] > 0 ? 1 : -1); } - for(unsigned int i = 0; i < tags.size(); i++) - fprintf(fp, "%d ", tags[i]); + for(unsigned int i = 0; i < tags.size(); i++) fprintf(fp, "%d ", tags[i]); fprintf(fp, "\n"); } } } -static unsigned long getAdditionalEntities(std::set<GRegion*, GEntityLessThan> ®ions, - std::set<GFace*, GEntityLessThan> &faces, - std::set<GEdge*, GEntityLessThan> &edges, - std::set<GVertex*, GEntityLessThan> &vertices) +static unsigned long +getAdditionalEntities(std::set<GRegion *, GEntityLessThan> ®ions, + std::set<GFace *, GEntityLessThan> &faces, + std::set<GEdge *, GEntityLessThan> &edges, + std::set<GVertex *, GEntityLessThan> &vertices) { unsigned long numVertices = 0; - for(std::set<GVertex*, GEntityLessThan>::iterator it = vertices.begin(); - it != vertices.end(); ++it){ + for(std::set<GVertex *, GEntityLessThan>::iterator it = vertices.begin(); + it != vertices.end(); ++it) { numVertices += (*it)->getNumMeshVertices(); } - for(std::set<GEdge*, GEntityLessThan>::iterator it = edges.begin(); - it != edges.end(); ++it){ + for(std::set<GEdge *, GEntityLessThan>::iterator it = edges.begin(); + it != edges.end(); ++it) { numVertices += (*it)->getNumMeshVertices(); - for(GFace::size_type i = 0; i < (*it)->getNumMeshElements(); i++){ - for(GFace::size_type j = 0; j < (*it)->getMeshElement(i)->getNumVertices(); j++){ - if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)){ + for(GFace::size_type i = 0; i < (*it)->getNumMeshElements(); i++) { + for(GFace::size_type j = 0; + j < (*it)->getMeshElement(i)->getNumVertices(); j++) { + if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)) { GEntity *entity = (*it)->getMeshElement(i)->getVertex(j)->onWhat(); - switch (entity->dim()){ - case 0: - if(vertices.find(static_cast<GVertex*>(entity)) == vertices.end()){ - vertices.insert(static_cast<GVertex*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 1: - if(edges.find(static_cast<GEdge*>(entity)) == edges.end()){ - edges.insert(static_cast<GEdge*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 2: - if(faces.find(static_cast<GFace*>(entity)) == faces.end()){ - faces.insert(static_cast<GFace*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 3: - if(regions.find(static_cast<GRegion*>(entity)) == regions.end()){ - regions.insert(static_cast<GRegion*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - default: - break; + switch(entity->dim()) { + case 0: + if(vertices.find(static_cast<GVertex *>(entity)) == + vertices.end()) { + vertices.insert(static_cast<GVertex *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 1: + if(edges.find(static_cast<GEdge *>(entity)) == edges.end()) { + edges.insert(static_cast<GEdge *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 2: + if(faces.find(static_cast<GFace *>(entity)) == faces.end()) { + faces.insert(static_cast<GFace *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 3: + if(regions.find(static_cast<GRegion *>(entity)) == regions.end()) { + regions.insert(static_cast<GRegion *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + default: break; } } } } } - for(std::set<GFace*, GEntityLessThan>::iterator it = faces.begin(); - it != faces.end(); ++it){ + for(std::set<GFace *, GEntityLessThan>::iterator it = faces.begin(); + it != faces.end(); ++it) { numVertices += (*it)->getNumMeshVertices(); - for(GFace::size_type i = 0; i < (*it)->getNumMeshElements(); i++){ - for(GFace::size_type j = 0; j < (*it)->getMeshElement(i)->getNumVertices(); j++){ - if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)){ + for(GFace::size_type i = 0; i < (*it)->getNumMeshElements(); i++) { + for(GFace::size_type j = 0; + j < (*it)->getMeshElement(i)->getNumVertices(); j++) { + if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)) { GEntity *entity = (*it)->getMeshElement(i)->getVertex(j)->onWhat(); - switch (entity->dim()){ - case 0: - if(vertices.find(static_cast<GVertex*>(entity)) == vertices.end()){ - vertices.insert(static_cast<GVertex*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 1: - if(edges.find(static_cast<GEdge*>(entity)) == edges.end()){ - edges.insert(static_cast<GEdge*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 2: - if(faces.find(static_cast<GFace*>(entity)) == faces.end()){ - faces.insert(static_cast<GFace*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 3: - if(regions.find(static_cast<GRegion*>(entity)) == regions.end()){ - regions.insert(static_cast<GRegion*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - default: - break; + switch(entity->dim()) { + case 0: + if(vertices.find(static_cast<GVertex *>(entity)) == + vertices.end()) { + vertices.insert(static_cast<GVertex *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 1: + if(edges.find(static_cast<GEdge *>(entity)) == edges.end()) { + edges.insert(static_cast<GEdge *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 2: + if(faces.find(static_cast<GFace *>(entity)) == faces.end()) { + faces.insert(static_cast<GFace *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 3: + if(regions.find(static_cast<GRegion *>(entity)) == regions.end()) { + regions.insert(static_cast<GRegion *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + default: break; } } } } } - for(std::set<GRegion*, GEntityLessThan>::iterator it = regions.begin(); - it != regions.end(); ++it){ + for(std::set<GRegion *, GEntityLessThan>::iterator it = regions.begin(); + it != regions.end(); ++it) { numVertices += (*it)->getNumMeshVertices(); - for(GFace::size_type i = 0; i < (*it)->getNumMeshElements(); i++){ - for(GFace::size_type j = 0; j < (*it)->getMeshElement(i)->getNumVertices(); j++){ - if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)){ + for(GFace::size_type i = 0; i < (*it)->getNumMeshElements(); i++) { + for(GFace::size_type j = 0; + j < (*it)->getMeshElement(i)->getNumVertices(); j++) { + if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)) { GEntity *entity = (*it)->getMeshElement(i)->getVertex(j)->onWhat(); - switch (entity->dim()){ - case 0: - if(vertices.find(static_cast<GVertex*>(entity)) == vertices.end()){ - vertices.insert(static_cast<GVertex*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 1: - if(edges.find(static_cast<GEdge*>(entity)) == edges.end()){ - edges.insert(static_cast<GEdge*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 2: - if(faces.find(static_cast<GFace*>(entity)) == faces.end()){ - faces.insert(static_cast<GFace*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - case 3: - if(regions.find(static_cast<GRegion*>(entity)) == regions.end()){ - regions.insert(static_cast<GRegion*>(entity)); - numVertices += entity->getNumMeshVertices(); - } - break; - default: - break; + switch(entity->dim()) { + case 0: + if(vertices.find(static_cast<GVertex *>(entity)) == + vertices.end()) { + vertices.insert(static_cast<GVertex *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 1: + if(edges.find(static_cast<GEdge *>(entity)) == edges.end()) { + edges.insert(static_cast<GEdge *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 2: + if(faces.find(static_cast<GFace *>(entity)) == faces.end()) { + faces.insert(static_cast<GFace *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + case 3: + if(regions.find(static_cast<GRegion *>(entity)) == regions.end()) { + regions.insert(static_cast<GRegion *>(entity)); + numVertices += entity->getNumMeshVertices(); + } + break; + default: break; } } } @@ -1937,42 +1948,42 @@ static unsigned long getAdditionalEntities(std::set<GRegion*, GEntityLessThan> & return numVertices; } -static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, bool binary, - int saveParametric, double scalingFactor, bool saveAll) +static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, + bool binary, int saveParametric, + double scalingFactor, bool saveAll) { - std::set<GRegion*, GEntityLessThan> regions; - std::set<GFace*, GEntityLessThan> faces; - std::set<GEdge*, GEntityLessThan> edges; - std::set<GVertex*, GEntityLessThan> vertices; - - if(partitioned){ - for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); ++it) - if((*it)->geomType() == GEntity::PartitionVertex) - vertices.insert(*it); - for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it){ + std::set<GRegion *, GEntityLessThan> regions; + std::set<GFace *, GEntityLessThan> faces; + std::set<GEdge *, GEntityLessThan> edges; + std::set<GVertex *, GEntityLessThan> vertices; + + if(partitioned) { + for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); + ++it) + if((*it)->geomType() == GEntity::PartitionVertex) vertices.insert(*it); + for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it) { if((*it)->geomType() == GEntity::PartitionCurve) edges.insert(*it); else if((*it)->geomType() == GEntity::GhostCurve) - if(static_cast<ghostEdge*>(*it)->saveMesh()) - edges.insert(*it); + if(static_cast<ghostEdge *>(*it)->saveMesh()) edges.insert(*it); } - for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it){ + for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it) { if((*it)->geomType() == GEntity::PartitionSurface) faces.insert(*it); else if((*it)->geomType() == GEntity::GhostSurface) - if(static_cast<ghostFace*>(*it)->saveMesh()) - faces.insert(*it); + if(static_cast<ghostFace *>(*it)->saveMesh()) faces.insert(*it); } - for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); ++it){ + for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); + ++it) { if((*it)->geomType() == GEntity::PartitionVolume) regions.insert(*it); else if((*it)->geomType() == GEntity::GhostVolume) - if(static_cast<ghostRegion*>(*it)->saveMesh()) - regions.insert(*it); + if(static_cast<ghostRegion *>(*it)->saveMesh()) regions.insert(*it); } } - else{ - for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); ++it) + else { + for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); + ++it) if((*it)->geomType() != GEntity::PartitionVertex && (saveAll || (!saveAll && (*it)->getPhysicalEntities().size() != 0))) vertices.insert(*it); @@ -1986,7 +1997,8 @@ static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, bool (saveAll || (!saveAll && (*it)->getPhysicalEntities().size() != 0) || (*it)->geomType() == GEntity::GhostSurface)) faces.insert(*it); - for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); ++it) + for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); + ++it) if((*it)->geomType() != GEntity::PartitionVolume && (saveAll || (!saveAll && (*it)->getPhysicalEntities().size() != 0) || (*it)->geomType() == GEntity::GhostVolume)) @@ -1994,23 +2006,24 @@ static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, bool } unsigned long numVertices = model->getNumMeshVertices(); - if(!saveAll && !partitioned){ + if(!saveAll && !partitioned) { numVertices = getAdditionalEntities(regions, faces, edges, vertices); } - if(binary){ - unsigned long numSection = vertices.size() + edges.size() + - faces.size() + regions.size(); + if(binary) { + unsigned long numSection = + vertices.size() + edges.size() + faces.size() + regions.size(); fwrite(&numSection, sizeof(unsigned long), 1, fp); fwrite(&numVertices, sizeof(unsigned long), 1, fp); } - else{ - fprintf(fp, "%lu %lu\n", vertices.size() + edges.size() + faces.size() + - regions.size(), numVertices); + else { + fprintf(fp, "%lu %lu\n", + vertices.size() + edges.size() + faces.size() + regions.size(), + numVertices); } - for(GModel::viter it = vertices.begin(); it != vertices.end(); ++it){ - if(binary){ + for(GModel::viter it = vertices.begin(); it != vertices.end(); ++it) { + if(binary) { int entityTag = (*it)->tag(); int entityDim = (*it)->dim(); unsigned long numVerts = (*it)->getNumMeshVertices(); @@ -2019,17 +2032,18 @@ static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, bool fwrite(&saveParametric, sizeof(int), 1, fp); fwrite(&numVerts, sizeof(unsigned long), 1, fp); } - else{ + else { fprintf(fp, "%d %d %d %lu\n", (*it)->tag(), (*it)->dim(), saveParametric, (unsigned long)(*it)->getNumMeshVertices()); } for(unsigned int i = 0; i < (*it)->getNumMeshVertices(); i++) - (*it)->getMeshVertex(i)->writeMSH4(fp, binary, saveParametric, scalingFactor); + (*it)->getMeshVertex(i)->writeMSH4(fp, binary, saveParametric, + scalingFactor); } - for(GModel::eiter it = edges.begin(); it != edges.end(); ++it){ - if(binary){ + for(GModel::eiter it = edges.begin(); it != edges.end(); ++it) { + if(binary) { int entityTag = (*it)->tag(); int entityDim = (*it)->dim(); unsigned long numVerts = (*it)->getNumMeshVertices(); @@ -2038,17 +2052,18 @@ static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, bool fwrite(&saveParametric, sizeof(int), 1, fp); fwrite(&numVerts, sizeof(unsigned long), 1, fp); } - else{ + else { fprintf(fp, "%d %d %d %lu\n", (*it)->tag(), (*it)->dim(), saveParametric, (unsigned long)(*it)->getNumMeshVertices()); } for(unsigned int i = 0; i < (*it)->getNumMeshVertices(); i++) - (*it)->getMeshVertex(i)->writeMSH4(fp, binary, saveParametric, scalingFactor); + (*it)->getMeshVertex(i)->writeMSH4(fp, binary, saveParametric, + scalingFactor); } - for(GModel::fiter it = faces.begin(); it != faces.end(); ++it){ - if(binary){ + for(GModel::fiter it = faces.begin(); it != faces.end(); ++it) { + if(binary) { int entityTag = (*it)->tag(); int entityDim = (*it)->dim(); unsigned long numVerts = (*it)->getNumMeshVertices(); @@ -2057,17 +2072,18 @@ static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, bool fwrite(&saveParametric, sizeof(int), 1, fp); fwrite(&numVerts, sizeof(unsigned long), 1, fp); } - else{ + else { fprintf(fp, "%d %d %d %lu\n", (*it)->tag(), (*it)->dim(), saveParametric, (unsigned long)(*it)->getNumMeshVertices()); } for(unsigned int i = 0; i < (*it)->getNumMeshVertices(); i++) - (*it)->getMeshVertex(i)->writeMSH4(fp, binary, saveParametric, scalingFactor); + (*it)->getMeshVertex(i)->writeMSH4(fp, binary, saveParametric, + scalingFactor); } - for(GModel::riter it = regions.begin(); it != regions.end(); ++it){ - if(binary){ + for(GModel::riter it = regions.begin(); it != regions.end(); ++it) { + if(binary) { int entityTag = (*it)->tag(); int entityDim = (*it)->dim(); unsigned long numVerts = (*it)->getNumMeshVertices(); @@ -2076,13 +2092,14 @@ static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, bool fwrite(&saveParametric, sizeof(int), 1, fp); fwrite(&numVerts, sizeof(unsigned long), 1, fp); } - else{ + else { fprintf(fp, "%d %d %d %lu\n", (*it)->tag(), (*it)->dim(), saveParametric, (unsigned long)(*it)->getNumMeshVertices()); } for(unsigned int i = 0; i < (*it)->getNumMeshVertices(); i++) - (*it)->getMeshVertex(i)->writeMSH4(fp, binary, saveParametric, scalingFactor); + (*it)->getMeshVertex(i)->writeMSH4(fp, binary, saveParametric, + scalingFactor); } if(binary) fprintf(fp, "\n"); @@ -2091,170 +2108,177 @@ static void writeMSH4Nodes(GModel *const model, FILE *fp, bool partitioned, bool static void writeMSH4Elements(GModel *const model, FILE *fp, bool partitioned, bool binary, bool saveAll) { - std::set<GRegion*, GEntityLessThan> regions; - std::set<GFace*, GEntityLessThan> faces; - std::set<GEdge*, GEntityLessThan> edges; - std::set<GVertex*, GEntityLessThan> vertices; - - if(partitioned){ - for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); ++it) - if((*it)->geomType() == GEntity::PartitionVertex) - vertices.insert(*it); - for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it){ + std::set<GRegion *, GEntityLessThan> regions; + std::set<GFace *, GEntityLessThan> faces; + std::set<GEdge *, GEntityLessThan> edges; + std::set<GVertex *, GEntityLessThan> vertices; + + if(partitioned) { + for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); + ++it) + if((*it)->geomType() == GEntity::PartitionVertex) vertices.insert(*it); + for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it) { if((*it)->geomType() == GEntity::PartitionCurve) edges.insert(*it); else if((*it)->geomType() == GEntity::GhostCurve) - if(static_cast<ghostEdge*>(*it)->saveMesh()) - edges.insert(*it); + if(static_cast<ghostEdge *>(*it)->saveMesh()) edges.insert(*it); } - for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it){ + for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it) { if((*it)->geomType() == GEntity::PartitionSurface) faces.insert(*it); else if((*it)->geomType() == GEntity::GhostSurface) - if(static_cast<ghostFace*>(*it)->saveMesh()) - faces.insert(*it); + if(static_cast<ghostFace *>(*it)->saveMesh()) faces.insert(*it); } - for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); ++it){ + for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); + ++it) { if((*it)->geomType() == GEntity::PartitionVolume) regions.insert(*it); else if((*it)->geomType() == GEntity::GhostVolume) - if(static_cast<ghostRegion*>(*it)->saveMesh()) - regions.insert(*it); + if(static_cast<ghostRegion *>(*it)->saveMesh()) regions.insert(*it); } } - else{ - for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); ++it) - if((*it)->geomType() != GEntity::PartitionVertex) - vertices.insert(*it); + else { + for(GModel::viter it = model->firstVertex(); it != model->lastVertex(); + ++it) + if((*it)->geomType() != GEntity::PartitionVertex) vertices.insert(*it); for(GModel::eiter it = model->firstEdge(); it != model->lastEdge(); ++it) - if((*it)->geomType() != GEntity::PartitionCurve && (*it)->geomType() != - GEntity::GhostCurve) + if((*it)->geomType() != GEntity::PartitionCurve && + (*it)->geomType() != GEntity::GhostCurve) edges.insert(*it); for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it) - if((*it)->geomType() != GEntity::PartitionSurface && (*it)->geomType() != - GEntity::GhostSurface) + if((*it)->geomType() != GEntity::PartitionSurface && + (*it)->geomType() != GEntity::GhostSurface) faces.insert(*it); - for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); ++it) - if((*it)->geomType() != GEntity::PartitionVolume && (*it)->geomType() != - GEntity::GhostVolume) + for(GModel::riter it = model->firstRegion(); it != model->lastRegion(); + ++it) + if((*it)->geomType() != GEntity::PartitionVolume && + (*it)->geomType() != GEntity::GhostVolume) regions.insert(*it); } - std::map<std::pair<int, int>, std::vector<MElement*> > elementsByDegree[4]; + std::map<std::pair<int, int>, std::vector<MElement *> > elementsByDegree[4]; unsigned long numElements = 0; - for(GModel::viter it = vertices.begin(); it != vertices.end(); ++it){ + for(GModel::viter it = vertices.begin(); it != vertices.end(); ++it) { if(!saveAll && (*it)->physicals.size() == 0) continue; numElements += (*it)->points.size(); - for(unsigned int i = 0; i < (*it)->points.size(); i++){ + for(unsigned int i = 0; i < (*it)->points.size(); i++) { std::pair<int, int> p((*it)->tag(), (*it)->points[i]->getTypeForMSH()); elementsByDegree[0][p].push_back((*it)->points[i]); } } - for(GModel::eiter it = edges.begin(); it != edges.end(); ++it){ + for(GModel::eiter it = edges.begin(); it != edges.end(); ++it) { if(!saveAll && (*it)->physicals.size() == 0 && - (*it)->geomType() != GEntity::GhostCurve) continue; + (*it)->geomType() != GEntity::GhostCurve) + continue; numElements += (*it)->lines.size(); - for(unsigned int i = 0; i < (*it)->lines.size(); i++){ + for(unsigned int i = 0; i < (*it)->lines.size(); i++) { std::pair<int, int> p((*it)->tag(), (*it)->lines[i]->getTypeForMSH()); elementsByDegree[1][p].push_back((*it)->lines[i]); } } - for(GModel::fiter it = faces.begin(); it != faces.end(); ++it){ + for(GModel::fiter it = faces.begin(); it != faces.end(); ++it) { if(!saveAll && (*it)->physicals.size() == 0 && - (*it)->geomType() != GEntity::GhostSurface) continue; + (*it)->geomType() != GEntity::GhostSurface) + continue; numElements += (*it)->triangles.size(); - for(unsigned int i = 0; i < (*it)->triangles.size(); i++){ + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) { std::pair<int, int> p((*it)->tag(), (*it)->triangles[i]->getTypeForMSH()); elementsByDegree[2][p].push_back((*it)->triangles[i]); } numElements += (*it)->quadrangles.size(); - for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++){ - std::pair<int, int> p((*it)->tag(), (*it)->quadrangles[i]->getTypeForMSH()); + for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) { + std::pair<int, int> p((*it)->tag(), + (*it)->quadrangles[i]->getTypeForMSH()); elementsByDegree[2][p].push_back((*it)->quadrangles[i]); } } - for(GModel::riter it = regions.begin(); it != regions.end(); ++it){ + for(GModel::riter it = regions.begin(); it != regions.end(); ++it) { if(!saveAll && (*it)->physicals.size() == 0 && - (*it)->geomType() != GEntity::GhostVolume) continue; + (*it)->geomType() != GEntity::GhostVolume) + continue; numElements += (*it)->tetrahedra.size(); - for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++){ - std::pair<int, int> p((*it)->tag(), (*it)->tetrahedra[i]->getTypeForMSH()); + for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++) { + std::pair<int, int> p((*it)->tag(), + (*it)->tetrahedra[i]->getTypeForMSH()); elementsByDegree[3][p].push_back((*it)->tetrahedra[i]); } numElements += (*it)->hexahedra.size(); - for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++){ + for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++) { std::pair<int, int> p((*it)->tag(), (*it)->hexahedra[i]->getTypeForMSH()); elementsByDegree[3][p].push_back((*it)->hexahedra[i]); } numElements += (*it)->prisms.size(); - for(unsigned int i = 0; i < (*it)->prisms.size(); i++){ + for(unsigned int i = 0; i < (*it)->prisms.size(); i++) { std::pair<int, int> p((*it)->tag(), (*it)->prisms[i]->getTypeForMSH()); elementsByDegree[3][p].push_back((*it)->prisms[i]); } numElements += (*it)->pyramids.size(); - for(unsigned int i = 0; i < (*it)->pyramids.size(); i++){ + for(unsigned int i = 0; i < (*it)->pyramids.size(); i++) { std::pair<int, int> p((*it)->tag(), (*it)->pyramids[i]->getTypeForMSH()); elementsByDegree[3][p].push_back((*it)->pyramids[i]); } numElements += (*it)->trihedra.size(); - for(unsigned int i = 0; i < (*it)->trihedra.size(); i++){ + for(unsigned int i = 0; i < (*it)->trihedra.size(); i++) { std::pair<int, int> p((*it)->tag(), (*it)->trihedra[i]->getTypeForMSH()); elementsByDegree[3][p].push_back((*it)->trihedra[i]); } } unsigned long numSection = 0; - for(int dim = 0; dim <= 3; dim++) - numSection += elementsByDegree[dim].size(); + for(int dim = 0; dim <= 3; dim++) numSection += elementsByDegree[dim].size(); - if(binary){ + if(binary) { fwrite(&numSection, sizeof(unsigned long), 1, fp); fwrite(&numElements, sizeof(unsigned long), 1, fp); } - else{ + else { fprintf(fp, "%lu %lu\n", numSection, numElements); } - for(int dim = 0; dim <= 3; dim++){ - for(std::map<std::pair<int, int>, std::vector<MElement*> >::iterator it = - elementsByDegree[dim].begin(); it != elementsByDegree[dim].end(); ++it){ + for(int dim = 0; dim <= 3; dim++) { + for(std::map<std::pair<int, int>, std::vector<MElement *> >::iterator it = + elementsByDegree[dim].begin(); + it != elementsByDegree[dim].end(); ++it) { int entityTag = it->first.first; int elmType = it->first.second; unsigned long numElm = it->second.size(); - if(binary){ + if(binary) { fwrite(&entityTag, sizeof(int), 1, fp); fwrite(&dim, sizeof(int), 1, fp); fwrite(&elmType, sizeof(int), 1, fp); fwrite(&numElm, sizeof(unsigned long), 1, fp); } - else{ + else { fprintf(fp, "%d %d %d %lu\n", entityTag, dim, elmType, numElm); } - if(binary){ + if(binary) { const int nbrVertices = MElement::getInfoMSH(elmType); int indexElement = 0; - int *elementData = new int[it->second.size()*(nbrVertices+1)]; - for(unsigned int i = 0; i < it->second.size()*(nbrVertices+1); i+=(nbrVertices+1)){ + int *elementData = new int[it->second.size() * (nbrVertices + 1)]; + for(unsigned int i = 0; i < it->second.size() * (nbrVertices + 1); + i += (nbrVertices + 1)) { elementData[i] = it->second[indexElement]->getNum(); - for(int j = 0; j < nbrVertices; j++){ - elementData[i+1+j] = it->second[indexElement]->getVertex(j)->getNum(); + for(int j = 0; j < nbrVertices; j++) { + elementData[i + 1 + j] = + it->second[indexElement]->getVertex(j)->getNum(); } indexElement++; } - fwrite(elementData, sizeof(int), it->second.size()*(nbrVertices+1), fp); + fwrite(elementData, sizeof(int), it->second.size() * (nbrVertices + 1), + fp); delete[] elementData; } - else{ - for(unsigned int i = 0; i < it->second.size(); i++){ + else { + for(unsigned int i = 0; i < it->second.size(); i++) { it->second[i]->writeMSH4(fp, binary); } } @@ -2264,11 +2288,11 @@ static void writeMSH4Elements(GModel *const model, FILE *fp, bool partitioned, if(binary) fprintf(fp, "\n"); } -static void writeMSH4PeriodicNodes(GModel *const model, FILE *fp, bool partitioned, - bool binary) +static void writeMSH4PeriodicNodes(GModel *const model, FILE *fp, + bool partitioned, bool binary) { int count = 0; - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; model->getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) if(entities[i]->meshMaster() != entities[i]) count++; @@ -2277,19 +2301,19 @@ static void writeMSH4PeriodicNodes(GModel *const model, FILE *fp, bool partition fprintf(fp, "$Periodic\n"); - if(binary){ + if(binary) { fwrite(&count, sizeof(int), 1, fp); } - else{ + else { fprintf(fp, "%d\n", count); } - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { GEntity *g_slave = entities[i]; GEntity *g_master = g_slave->meshMaster(); - if(g_slave != g_master){ - if(binary){ + if(g_slave != g_master) { + if(binary) { int gSlaveDim = g_slave->dim(); int gSlaveTag = g_slave->tag(); int gMasterTag = g_master->tag(); @@ -2297,10 +2321,10 @@ static void writeMSH4PeriodicNodes(GModel *const model, FILE *fp, bool partition fwrite(&gSlaveTag, sizeof(int), 1, fp); fwrite(&gMasterTag, sizeof(int), 1, fp); - if(g_slave->affineTransform.size() == 16){ + if(g_slave->affineTransform.size() == 16) { long AffineTag = -1; fwrite(&AffineTag, sizeof(long), 1, fp); - for(int j = 0; j < 16; j++){ + for(int j = 0; j < 16; j++) { double value = g_slave->affineTransform[j]; fwrite(&value, sizeof(double), 1, fp); } @@ -2309,19 +2333,20 @@ static void writeMSH4PeriodicNodes(GModel *const model, FILE *fp, bool partition long corrVertSize = g_slave->correspondingVertices.size(); fwrite(&corrVertSize, sizeof(long), 1, fp); - for (std::map<MVertex*,MVertex*>::iterator it = - g_slave->correspondingVertices.begin(); - it != g_slave->correspondingVertices.end(); ++it){ + for(std::map<MVertex *, MVertex *>::iterator it = + g_slave->correspondingVertices.begin(); + it != g_slave->correspondingVertices.end(); ++it) { int numFirst = it->first->getNum(); int numSecond = it->second->getNum(); fwrite(&numFirst, sizeof(int), 1, fp); fwrite(&numSecond, sizeof(int), 1, fp); } } - else{ - fprintf(fp, "%d %d %d\n", g_slave->dim(), g_slave->tag(), g_master->tag()); + else { + fprintf(fp, "%d %d %d\n", g_slave->dim(), g_slave->tag(), + g_master->tag()); - if(g_slave->affineTransform.size() == 16){ + if(g_slave->affineTransform.size() == 16) { fprintf(fp, "Affine"); for(int j = 0; j < 16; j++) fprintf(fp, " %.16g", g_slave->affineTransform[j]); @@ -2330,9 +2355,9 @@ static void writeMSH4PeriodicNodes(GModel *const model, FILE *fp, bool partition fprintf(fp, "%lu\n", g_slave->correspondingVertices.size()); - for (std::map<MVertex*,MVertex*>::iterator it = - g_slave->correspondingVertices.begin(); - it != g_slave->correspondingVertices.end(); ++it){ + for(std::map<MVertex *, MVertex *>::iterator it = + g_slave->correspondingVertices.begin(); + it != g_slave->correspondingVertices.end(); ++it) { fprintf(fp, "%d %d\n", it->first->getNum(), it->second->getNum()); } } @@ -2345,61 +2370,65 @@ static void writeMSH4PeriodicNodes(GModel *const model, FILE *fp, bool partition static void writeMSH4GhostCells(GModel *const model, FILE *fp, bool binary) { - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; model->getEntities(entities); - std::map<MElement*, std::vector<unsigned int> > ghostCells; + std::map<MElement *, std::vector<unsigned int> > ghostCells; - for(unsigned int i = 0; i < entities.size(); i++){ - std::map<MElement*, unsigned int> ghostElements; + for(unsigned int i = 0; i < entities.size(); i++) { + std::map<MElement *, unsigned int> ghostElements; unsigned int partition; - if(entities[i]->geomType() == GEntity::GhostCurve){ - ghostElements = static_cast<ghostEdge*>(entities[i])->getGhostCells(); - partition = static_cast<ghostEdge*>(entities[i])->getPartition(); + if(entities[i]->geomType() == GEntity::GhostCurve) { + ghostElements = static_cast<ghostEdge *>(entities[i])->getGhostCells(); + partition = static_cast<ghostEdge *>(entities[i])->getPartition(); } - else if(entities[i]->geomType() == GEntity::GhostSurface){ - ghostElements = static_cast<ghostFace*>(entities[i])->getGhostCells(); - partition = static_cast<ghostFace*>(entities[i])->getPartition(); + else if(entities[i]->geomType() == GEntity::GhostSurface) { + ghostElements = static_cast<ghostFace *>(entities[i])->getGhostCells(); + partition = static_cast<ghostFace *>(entities[i])->getPartition(); } - else if(entities[i]->geomType() == GEntity::GhostVolume){ - ghostElements = static_cast<ghostRegion*>(entities[i])->getGhostCells(); - partition = static_cast<ghostRegion*>(entities[i])->getPartition(); + else if(entities[i]->geomType() == GEntity::GhostVolume) { + ghostElements = static_cast<ghostRegion *>(entities[i])->getGhostCells(); + partition = static_cast<ghostRegion *>(entities[i])->getPartition(); } - for(std::map<MElement*, unsigned int>::iterator it = ghostElements.begin(); - it != ghostElements.end(); ++it){ - if(ghostCells[it->first].size() == 0) ghostCells[it->first].push_back(partition); + for(std::map<MElement *, unsigned int>::iterator it = ghostElements.begin(); + it != ghostElements.end(); ++it) { + if(ghostCells[it->first].size() == 0) + ghostCells[it->first].push_back(partition); ghostCells[it->first].push_back(it->second); } } - if(ghostCells.size() != 0){ + if(ghostCells.size() != 0) { fprintf(fp, "$GhostElements\n"); - if(binary){ + if(binary) { int ghostCellsSize = ghostCells.size(); fwrite(&ghostCellsSize, sizeof(int), 1, fp); - for(std::map<MElement*, std::vector<unsigned int> >::iterator it = ghostCells.begin(); - it != ghostCells.end(); ++it){ + for(std::map<MElement *, std::vector<unsigned int> >::iterator it = + ghostCells.begin(); + it != ghostCells.end(); ++it) { int elmNum = it->first->getNum(); unsigned int part = it->second[0]; - unsigned int numGhost = it->second.size()-1; + unsigned int numGhost = it->second.size() - 1; fwrite(&elmNum, sizeof(int), 1, fp); fwrite(&part, sizeof(unsigned int), 1, fp); fwrite(&numGhost, sizeof(unsigned int), 1, fp); - for(unsigned int i = 1; i < it->second.size(); i++){ + for(unsigned int i = 1; i < it->second.size(); i++) { fwrite(&it->second[i], sizeof(int), 1, fp); } } fprintf(fp, "\n"); } - else{ + else { fprintf(fp, "%ld\n", ghostCells.size()); - for(std::map<MElement*, std::vector<unsigned int> >::iterator it = ghostCells.begin(); - it != ghostCells.end(); ++it){ - fprintf(fp, "%d %d %ld", it->first->getNum(), it->second[0], it->second.size()-1); - for(unsigned int i = 1; i < it->second.size(); i++){ + for(std::map<MElement *, std::vector<unsigned int> >::iterator it = + ghostCells.begin(); + it != ghostCells.end(); ++it) { + fprintf(fp, "%d %d %ld", it->first->getNum(), it->second[0], + it->second.size() - 1); + for(unsigned int i = 1; i < it->second.size(); i++) { fprintf(fp, " %d", it->second[i]); } fprintf(fp, "\n"); @@ -2414,7 +2443,7 @@ int GModel::_writeMSH4(const std::string &name, double version, bool binary, { FILE *fp = Fopen(name.c_str(), binary ? "wb" : "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -2425,21 +2454,22 @@ int GModel::_writeMSH4(const std::string &name, double version, bool binary, // header fprintf(fp, "$MeshFormat\n"); fprintf(fp, "%g %d %lu\n", version, (binary ? 1 : 0), sizeof(double)); - if(binary){ + if(binary) { int one = 1; - fwrite(&one, sizeof(int), 1, fp);//swapping byte + fwrite(&one, sizeof(int), 1, fp); // swapping byte fprintf(fp, "\n"); } fprintf(fp, "$EndMeshFormat\n"); // physicals - if(numPhysicalNames() > 0){ + if(numPhysicalNames() > 0) { fprintf(fp, "$PhysicalNames\n"); fprintf(fp, "%d\n", numPhysicalNames()); - for(piter it = firstPhysicalName(); it != lastPhysicalName(); ++it){ + for(piter it = firstPhysicalName(); it != lastPhysicalName(); ++it) { std::string name = it->second; if(name.size() > 128) name.resize(128); - fprintf(fp, "%d %d \"%s\"\n", it->first.first, it->first.second, name.c_str()); + fprintf(fp, "%d %d \"%s\"\n", it->first.first, it->first.second, + name.c_str()); } fprintf(fp, "$EndPhysicalNames\n"); } @@ -2450,7 +2480,7 @@ int GModel::_writeMSH4(const std::string &name, double version, bool binary, fprintf(fp, "$EndEntities\n"); // partitioned entities - if(getNumPartitions() > 0){ + if(getNumPartitions() > 0) { fprintf(fp, "$PartitionedEntities\n"); writeMSH4Entities(this, fp, true, binary, scalingFactor); fprintf(fp, "$EndPartitionedEntities\n"); @@ -2459,18 +2489,20 @@ int GModel::_writeMSH4(const std::string &name, double version, bool binary, // nodes fprintf(fp, "$Nodes\n"); writeMSH4Nodes(this, fp, getNumPartitions() == 0 ? false : true, binary, - saveParametric ? 1:0, scalingFactor, saveAll); + saveParametric ? 1 : 0, scalingFactor, saveAll); fprintf(fp, "$EndNodes\n"); // elements fprintf(fp, "$Elements\n"); - writeMSH4Elements(this, fp, getNumPartitions() == 0 ? false : true, binary, saveAll); + writeMSH4Elements(this, fp, getNumPartitions() == 0 ? false : true, binary, + saveAll); fprintf(fp, "$EndElements\n"); // periodic - writeMSH4PeriodicNodes(this, fp, getNumPartitions() == 0 ? false : true, binary); + writeMSH4PeriodicNodes(this, fp, getNumPartitions() == 0 ? false : true, + binary); - //ghostCells + // ghostCells writeMSH4GhostCells(this, fp, binary); fclose(fp); @@ -2480,75 +2512,95 @@ int GModel::_writeMSH4(const std::string &name, double version, bool binary, static void associateVertices(GModel *model) { - for(GModel::const_viter it = model->firstVertex(); it != model->lastVertex(); ++it){ - for(GFace::size_type j = 0; j < (*it)->getNumMeshElements(); j++){ - for(GFace::size_type k = 0; k < (*it)->getMeshElement(j)->getNumVertices(); k++){ + for(GModel::const_viter it = model->firstVertex(); it != model->lastVertex(); + ++it) { + for(GFace::size_type j = 0; j < (*it)->getNumMeshElements(); j++) { + for(GFace::size_type k = 0; + k < (*it)->getMeshElement(j)->getNumVertices(); k++) { (*it)->getMeshElement(j)->getVertex(k)->setEntity(0); } } (*it)->mesh_vertices.clear(); } - for(GModel::const_eiter it = model->firstEdge(); it != model->lastEdge(); ++it){ - for(GFace::size_type j = 0; j < (*it)->getNumMeshElements(); j++){ - for(GFace::size_type k = 0; k < (*it)->getMeshElement(j)->getNumVertices(); k++){ + for(GModel::const_eiter it = model->firstEdge(); it != model->lastEdge(); + ++it) { + for(GFace::size_type j = 0; j < (*it)->getNumMeshElements(); j++) { + for(GFace::size_type k = 0; + k < (*it)->getMeshElement(j)->getNumVertices(); k++) { (*it)->getMeshElement(j)->getVertex(k)->setEntity(0); } } (*it)->mesh_vertices.clear(); } - for(GModel::const_fiter it = model->firstFace(); it != model->lastFace(); ++it){ - for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++){ - for(GModel::size_type k = 0; k < (*it)->getMeshElement(j)->getNumVertices(); k++){ + for(GModel::const_fiter it = model->firstFace(); it != model->lastFace(); + ++it) { + for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++) { + for(GModel::size_type k = 0; + k < (*it)->getMeshElement(j)->getNumVertices(); k++) { (*it)->getMeshElement(j)->getVertex(k)->setEntity(0); } } (*it)->mesh_vertices.clear(); } - for(GModel::const_riter it = model->firstRegion(); it != model->lastRegion(); ++it){ - for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++){ - for(GModel::size_type k = 0; k < (*it)->getMeshElement(j)->getNumVertices(); k++){ + for(GModel::const_riter it = model->firstRegion(); it != model->lastRegion(); + ++it) { + for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++) { + for(GModel::size_type k = 0; + k < (*it)->getMeshElement(j)->getNumVertices(); k++) { (*it)->getMeshElement(j)->getVertex(k)->setEntity(0); } } (*it)->mesh_vertices.clear(); } - for(GModel::const_viter it = model->firstVertex(); it != model->lastVertex(); ++it){ - for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++){ - for(GModel::size_type k = 0; k < (*it)->getMeshElement(j)->getNumVertices(); k++){ - if((*it)->getMeshElement(j)->getVertex(k)->onWhat() == 0){ + for(GModel::const_viter it = model->firstVertex(); it != model->lastVertex(); + ++it) { + for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++) { + for(GModel::size_type k = 0; + k < (*it)->getMeshElement(j)->getNumVertices(); k++) { + if((*it)->getMeshElement(j)->getVertex(k)->onWhat() == 0) { (*it)->getMeshElement(j)->getVertex(k)->setEntity(*it); - (*it)->mesh_vertices.push_back((*it)->getMeshElement(j)->getVertex(k)); + (*it)->mesh_vertices.push_back( + (*it)->getMeshElement(j)->getVertex(k)); } } } } - for(GModel::const_eiter it = model->firstEdge(); it != model->lastEdge(); ++it){ - for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++){ - for(GModel::size_type k = 0; k < (*it)->getMeshElement(j)->getNumVertices(); k++){ - if((*it)->getMeshElement(j)->getVertex(k)->onWhat() == 0){ + for(GModel::const_eiter it = model->firstEdge(); it != model->lastEdge(); + ++it) { + for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++) { + for(GModel::size_type k = 0; + k < (*it)->getMeshElement(j)->getNumVertices(); k++) { + if((*it)->getMeshElement(j)->getVertex(k)->onWhat() == 0) { (*it)->getMeshElement(j)->getVertex(k)->setEntity(*it); - (*it)->mesh_vertices.push_back((*it)->getMeshElement(j)->getVertex(k)); + (*it)->mesh_vertices.push_back( + (*it)->getMeshElement(j)->getVertex(k)); } } } } - for(GModel::const_fiter it = model->firstFace(); it != model->lastFace(); ++it){ - for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++){ - for(GModel::size_type k = 0; k < (*it)->getMeshElement(j)->getNumVertices(); k++){ - if((*it)->getMeshElement(j)->getVertex(k)->onWhat() == 0){ + for(GModel::const_fiter it = model->firstFace(); it != model->lastFace(); + ++it) { + for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++) { + for(GModel::size_type k = 0; + k < (*it)->getMeshElement(j)->getNumVertices(); k++) { + if((*it)->getMeshElement(j)->getVertex(k)->onWhat() == 0) { (*it)->getMeshElement(j)->getVertex(k)->setEntity(*it); - (*it)->mesh_vertices.push_back((*it)->getMeshElement(j)->getVertex(k)); + (*it)->mesh_vertices.push_back( + (*it)->getMeshElement(j)->getVertex(k)); } } } } - for(GModel::const_riter it = model->firstRegion(); it != model->lastRegion(); ++it){ - for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++){ - for(GModel::size_type k = 0; k < (*it)->getMeshElement(j)->getNumVertices(); k++){ - if((*it)->getMeshElement(j)->getVertex(k)->onWhat() == 0){ + for(GModel::const_riter it = model->firstRegion(); it != model->lastRegion(); + ++it) { + for(GModel::size_type j = 0; j < (*it)->getNumMeshElements(); j++) { + for(GModel::size_type k = 0; + k < (*it)->getMeshElement(j)->getNumVertices(); k++) { + if((*it)->getMeshElement(j)->getVertex(k)->onWhat() == 0) { (*it)->getMeshElement(j)->getVertex(k)->setEntity(*it); - (*it)->mesh_vertices.push_back((*it)->getMeshElement(j)->getVertex(k)); + (*it)->mesh_vertices.push_back( + (*it)->getMeshElement(j)->getVertex(k)); } } } @@ -2556,16 +2608,16 @@ static void associateVertices(GModel *model) } int GModel::_writePartitionedMSH4(const std::string &baseName, double version, - bool binary, bool saveAll, bool saveParametric, - double scalingFactor) + bool binary, bool saveAll, + bool saveParametric, double scalingFactor) { - std::vector<GEntity*> ghostEntities; - std::vector<GEntity*> entities; + std::vector<GEntity *> ghostEntities; + std::vector<GEntity *> entities; getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { if(entities[i]->geomType() == GEntity::GhostCurve || - entities[i]->geomType() == GEntity::GhostSurface|| - entities[i]->geomType() == GEntity::GhostVolume){ + entities[i]->geomType() == GEntity::GhostSurface || + entities[i]->geomType() == GEntity::GhostVolume) { ghostEntities.push_back(entities[i]); } } @@ -2575,108 +2627,104 @@ int GModel::_writePartitionedMSH4(const std::string &baseName, double version, tmp->setPhysicalNames(getPhysicalNames()); tmp->setNumPartitions(getNumPartitions()); - for(unsigned int i = 1; i <= getNumPartitions(); i++){ - std::set<GEntity*> entitiesSet; + for(unsigned int i = 1; i <= getNumPartitions(); i++) { + std::set<GEntity *> entitiesSet; GEntity *ghostEntity = 0; - for(unsigned int j = 0; j < entities.size(); j++){ - switch(entities[j]->geomType()){ - case GEntity::PartitionVolume: - { - partitionRegion *pr = static_cast<partitionRegion*>(entities[j]); - if(std::find(pr->getPartitions().begin(), pr->getPartitions().end(), i) != - pr->getPartitions().end()){ - tmp->add(pr); - if(ghostEntities.size()) entitiesSet.insert(pr); - } - } - break; - case GEntity::PartitionSurface: - { - partitionFace *pf = static_cast<partitionFace*>(entities[j]); - if(std::find(pf->getPartitions().begin(), pf->getPartitions().end(), i) != - pf->getPartitions().end()){ - tmp->add(pf); - if(ghostEntities.size()) entitiesSet.insert(pf); - } - } - break; - case GEntity::PartitionCurve: - { - partitionEdge *pe = static_cast<partitionEdge*>(entities[j]); - if(std::find(pe->getPartitions().begin(), pe->getPartitions().end(), i) != - pe->getPartitions().end()){ - tmp->add(pe); - if(ghostEntities.size()) entitiesSet.insert(pe); - } - } - break; - case GEntity::PartitionVertex: - { - partitionVertex *pv = static_cast<partitionVertex*>(entities[j]); - if(std::find(pv->getPartitions().begin(), pv->getPartitions().end(), i) != - pv->getPartitions().end()){ - tmp->add(pv); - if(ghostEntities.size()) entitiesSet.insert(pv); - } - } - break; + for(unsigned int j = 0; j < entities.size(); j++) { + switch(entities[j]->geomType()) { + case GEntity::PartitionVolume: { + partitionRegion *pr = static_cast<partitionRegion *>(entities[j]); + if(std::find(pr->getPartitions().begin(), pr->getPartitions().end(), + i) != pr->getPartitions().end()) { + tmp->add(pr); + if(ghostEntities.size()) entitiesSet.insert(pr); + } + } break; + case GEntity::PartitionSurface: { + partitionFace *pf = static_cast<partitionFace *>(entities[j]); + if(std::find(pf->getPartitions().begin(), pf->getPartitions().end(), + i) != pf->getPartitions().end()) { + tmp->add(pf); + if(ghostEntities.size()) entitiesSet.insert(pf); + } + } break; + case GEntity::PartitionCurve: { + partitionEdge *pe = static_cast<partitionEdge *>(entities[j]); + if(std::find(pe->getPartitions().begin(), pe->getPartitions().end(), + i) != pe->getPartitions().end()) { + tmp->add(pe); + if(ghostEntities.size()) entitiesSet.insert(pe); + } + } break; + case GEntity::PartitionVertex: { + partitionVertex *pv = static_cast<partitionVertex *>(entities[j]); + if(std::find(pv->getPartitions().begin(), pv->getPartitions().end(), + i) != pv->getPartitions().end()) { + tmp->add(pv); + if(ghostEntities.size()) entitiesSet.insert(pv); + } + } break; case GEntity::GhostCurve: - if(i == static_cast<ghostEdge*>(entities[j])->getPartition()){ - static_cast<ghostEdge*>(entities[j])->saveMesh(true); - tmp->add(static_cast<ghostEdge*>(entities[j])); - if(ghostEntities.size()) entitiesSet.insert(entities[j]); - ghostEntity = entities[j]; - } + if(i == static_cast<ghostEdge *>(entities[j])->getPartition()) { + static_cast<ghostEdge *>(entities[j])->saveMesh(true); + tmp->add(static_cast<ghostEdge *>(entities[j])); + if(ghostEntities.size()) entitiesSet.insert(entities[j]); + ghostEntity = entities[j]; + } break; case GEntity::GhostSurface: - if(i == static_cast<ghostFace*>(entities[j])->getPartition()){ - static_cast<ghostFace*>(entities[j])->saveMesh(true); - tmp->add(static_cast<ghostFace*>(entities[j])); - if(ghostEntities.size()) entitiesSet.insert(entities[j]); - ghostEntity = entities[j]; - } + if(i == static_cast<ghostFace *>(entities[j])->getPartition()) { + static_cast<ghostFace *>(entities[j])->saveMesh(true); + tmp->add(static_cast<ghostFace *>(entities[j])); + if(ghostEntities.size()) entitiesSet.insert(entities[j]); + ghostEntity = entities[j]; + } break; case GEntity::GhostVolume: - if(i == static_cast<ghostRegion*>(entities[j])->getPartition()){ - static_cast<ghostRegion*>(entities[j])->saveMesh(true); - tmp->add(static_cast<ghostRegion*>(entities[j])); - if(ghostEntities.size()) entitiesSet.insert(entities[j]); - ghostEntity = entities[j]; - } + if(i == static_cast<ghostRegion *>(entities[j])->getPartition()) { + static_cast<ghostRegion *>(entities[j])->saveMesh(true); + tmp->add(static_cast<ghostRegion *>(entities[j])); + if(ghostEntities.size()) entitiesSet.insert(entities[j]); + ghostEntity = entities[j]; + } break; default: - if(entities[j]->dim() == 0){ - tmp->add(static_cast<GVertex*>(entities[j])); - if(ghostEntities.size()) entitiesSet.insert(entities[j]); - } - else if(entities[j]->dim() == 1){ - tmp->add(static_cast<GEdge*>(entities[j])); - if(ghostEntities.size()) entitiesSet.insert(entities[j]); - } - else if(entities[j]->dim() == 2){ - tmp->add(static_cast<GFace*>(entities[j])); - if(ghostEntities.size()) entitiesSet.insert(entities[j]); - } - else if(entities[j]->dim() == 3){ - tmp->add(static_cast<GRegion*>(entities[j])); - if(ghostEntities.size()) entitiesSet.insert(entities[j]); - } + if(entities[j]->dim() == 0) { + tmp->add(static_cast<GVertex *>(entities[j])); + if(ghostEntities.size()) entitiesSet.insert(entities[j]); + } + else if(entities[j]->dim() == 1) { + tmp->add(static_cast<GEdge *>(entities[j])); + if(ghostEntities.size()) entitiesSet.insert(entities[j]); + } + else if(entities[j]->dim() == 2) { + tmp->add(static_cast<GFace *>(entities[j])); + if(ghostEntities.size()) entitiesSet.insert(entities[j]); + } + else if(entities[j]->dim() == 3) { + tmp->add(static_cast<GRegion *>(entities[j])); + if(ghostEntities.size()) entitiesSet.insert(entities[j]); + } break; } } - if(!CTX::instance()->mesh.partitionCreateTopology){ + if(!CTX::instance()->mesh.partitionCreateTopology) { associateVertices(tmp); } - if(ghostEntity){ - for(unsigned int j = 0; j < ghostEntity->getNumMeshElements(); j++){ - for(unsigned int k = 0; k < ghostEntity->getMeshElement(j)->getNumVertices(); k++){ - if(entitiesSet.find(ghostEntity->getMeshElement(j)->getVertex(k)->onWhat()) == - entitiesSet.end()){ - ghostEntity->addMeshVertex(ghostEntity->getMeshElement(j)->getVertex(k)); - ghostEntity->getMeshElement(j)->getVertex(k)->setEntity(ghostEntity); + if(ghostEntity) { + for(unsigned int j = 0; j < ghostEntity->getNumMeshElements(); j++) { + for(unsigned int k = 0; + k < ghostEntity->getMeshElement(j)->getNumVertices(); k++) { + if(entitiesSet.find( + ghostEntity->getMeshElement(j)->getVertex(k)->onWhat()) == + entitiesSet.end()) { + ghostEntity->addMeshVertex( + ghostEntity->getMeshElement(j)->getVertex(k)); + ghostEntity->getMeshElement(j)->getVertex(k)->setEntity( + ghostEntity); } } } @@ -2685,13 +2733,13 @@ int GModel::_writePartitionedMSH4(const std::string &baseName, double version, std::ostringstream sstream; sstream << baseName << "_" << i << ".msh"; - if(getNumPartitions() > 100){ - if (i % 100 == 1){ + if(getNumPartitions() > 100) { + if(i % 100 == 1) { Msg::Info("Writing partition %d/%d in file '%s'", i, getNumPartitions(), sstream.str().c_str()); } } - else{ + else { Msg::Info("Writing partition %d in file '%s'", i, sstream.str().c_str()); } @@ -2701,7 +2749,7 @@ int GModel::_writePartitionedMSH4(const std::string &baseName, double version, } delete tmp; - if(!CTX::instance()->mesh.partitionCreateTopology){ + if(!CTX::instance()->mesh.partitionCreateTopology) { associateVertices(this); } @@ -2716,21 +2764,22 @@ static bool getPhyscialNameInfo(const std::string &name, int &parentPhysicalTag, const std::string part = "_part{"; const std::string physical = "_physical{"; - size_t firstPart = name.find(part)+part.size(); + size_t firstPart = name.find(part) + part.size(); size_t lastPart = name.find_first_of('}', firstPart); - const std::string partString = name.substr(firstPart, lastPart-firstPart); + const std::string partString = name.substr(firstPart, lastPart - firstPart); - size_t firstPhysical = name.find(physical)+physical.size(); + size_t firstPhysical = name.find(physical) + physical.size(); size_t lastPhysical = name.find_first_of('}', firstPhysical); - const std::string physicalString = name.substr(firstPhysical, lastPhysical-firstPhysical); + const std::string physicalString = + name.substr(firstPhysical, lastPhysical - firstPhysical); std::string number; - for(size_t i = 0; i < partString.size(); ++i){ - if(partString[i] == ','){ + for(size_t i = 0; i < partString.size(); ++i) { + if(partString[i] == ',') { partitions.push_back(atoi(number.c_str())); number.clear(); } - else{ + else { number += partString[i]; } } @@ -2745,26 +2794,27 @@ int GModel::writePartitionedTopology(std::string &name) { Msg::Info("Writing '%s'", name.c_str()); - std::vector< std::map<int, std::pair<int, std::vector<int> > > > allParts(4); - std::vector<GEntity*> entities; + std::vector<std::map<int, std::pair<int, std::vector<int> > > > allParts(4); + std::vector<GEntity *> entities; getEntities(entities); - for(size_t i = 0; i < entities.size(); i++){ + for(size_t i = 0; i < entities.size(); i++) { std::vector<int> physicals = entities[i]->getPhysicalEntities(); - for(size_t j = 0; j < physicals.size(); ++j){ - const std::string phyName = this->getPhysicalName(entities[i]->dim(), physicals[j]); + for(size_t j = 0; j < physicals.size(); ++j) { + const std::string phyName = + this->getPhysicalName(entities[i]->dim(), physicals[j]); int parentPhysicalTag; std::vector<int> partitions; - if(getPhyscialNameInfo(phyName, parentPhysicalTag, partitions)){ - allParts[entities[i]->dim()].insert - (std::pair<int, std::pair<int, std::vector<int> > > - (physicals[j], std::pair<int, std::vector<int> >(parentPhysicalTag, - partitions))); + if(getPhyscialNameInfo(phyName, parentPhysicalTag, partitions)) { + allParts[entities[i]->dim()].insert( + std::pair<int, std::pair<int, std::vector<int> > >( + physicals[j], + std::pair<int, std::vector<int> >(parentPhysicalTag, partitions))); } } } FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Could not open file '%s'", name.c_str()); return 0; } @@ -2774,25 +2824,26 @@ int GModel::writePartitionedTopology(std::string &name) #endif fprintf(fp, "Group{\n"); fprintf(fp, " // Part~{dim}~{parentPhysicalTag}~{part1}~{part2}~...\n\n"); - std::vector< std::map<int, std::string> > tagToString(4); - for(size_t i = 4; i > 0; --i){ - fprintf(fp, " // Dim %lu\n", i-1); + std::vector<std::map<int, std::string> > tagToString(4); + for(size_t i = 4; i > 0; --i) { + fprintf(fp, " // Dim %lu\n", i - 1); for(std::multimap<int, std::pair<int, std::vector<int> > >::iterator it = - allParts[i-1].begin(); it != allParts[i-1].end(); ++it){ + allParts[i - 1].begin(); + it != allParts[i - 1].end(); ++it) { #if __cplusplus >= 201103L - std::string partName = "Part~{" + std::to_string(i-1) + "}~{" + - std::to_string(it->second.first) + "}"; + std::string partName = "Part~{" + std::to_string(i - 1) + "}~{" + + std::to_string(it->second.first) + "}"; #else std::string partName = "Part~{"; - sprintf(intToChar, "%lu", i-1); + sprintf(intToChar, "%lu", i - 1); partName += intToChar; partName += "}~{"; sprintf(intToChar, "%d", it->second.first); partName += intToChar; partName += "}"; #endif - fprintf(fp, " Part~{%lu}~{%d}", i-1, it->second.first); - for(size_t j = 0; j < it->second.second.size(); ++j){ + fprintf(fp, " Part~{%lu}~{%d}", i - 1, it->second.first); + for(size_t j = 0; j < it->second.second.size(); ++j) { #if __cplusplus >= 201103L partName += "~{" + std::to_string(it->second.second[j]) + "}"; #else @@ -2803,7 +2854,8 @@ int GModel::writePartitionedTopology(std::string &name) #endif fprintf(fp, "~{%d}", it->second.second[j]); } - tagToString[i-1].insert(std::pair<int, std::string>(it->first, partName)); + tagToString[i - 1].insert( + std::pair<int, std::string>(it->first, partName)); fprintf(fp, " = Region[{%d}];\n", it->first); } fprintf(fp, "\n"); @@ -2811,68 +2863,79 @@ int GModel::writePartitionedTopology(std::string &name) fprintf(fp, " // Global names\n\n"); std::map<int, std::vector<int> > omegas; - std::map< std::pair<int, int> , std::vector<int> > sigmasij; + std::map<std::pair<int, int>, std::vector<int> > sigmasij; std::map<int, std::vector<int> > sigmas; std::map<int, std::set<int> > neighbors; unsigned int omegaDim = 0; - for(size_t i = 4; i > 0; --i){ - if(allParts[i-1].size() != 0){ - omegaDim = i-1; + for(size_t i = 4; i > 0; --i) { + if(allParts[i - 1].size() != 0) { + omegaDim = i - 1; break; } } - // omega for(std::multimap<int, std::pair<int, std::vector<int> > >::iterator it = - allParts[omegaDim].begin(); it != allParts[omegaDim].end(); ++it){ - if(it->second.second.size() == 1){ + allParts[omegaDim].begin(); + it != allParts[omegaDim].end(); ++it) { + if(it->second.second.size() == 1) { omegas[it->second.second[0]].push_back(it->first); } } fprintf(fp, " // Omega\n"); for(std::map<int, std::vector<int> >::iterator it = omegas.begin(); - it != omegas.end(); ++it){ + it != omegas.end(); ++it) { fprintf(fp, " Omega~{%d} = Region[{", it->first); - for(size_t j = 0; j < it->second.size(); ++j){ - if(j == 0) fprintf(fp, "%s", tagToString[omegaDim][it->second[j]].c_str()); - else fprintf(fp, ", %s", tagToString[omegaDim][it->second[j]].c_str()); + for(size_t j = 0; j < it->second.size(); ++j) { + if(j == 0) + fprintf(fp, "%s", tagToString[omegaDim][it->second[j]].c_str()); + else + fprintf(fp, ", %s", tagToString[omegaDim][it->second[j]].c_str()); } fprintf(fp, "}];\n"); } fprintf(fp, "\n"); - if(omegaDim > 0){ + if(omegaDim > 0) { // sigma for(std::multimap<int, std::pair<int, std::vector<int> > >::iterator it = - allParts[omegaDim-1].begin(); it != allParts[omegaDim-1].end(); ++it){ - if(it->second.second.size() == 2){ - sigmasij[std::pair<int, int>(it->second.second[0], it->second.second[1])]. - push_back(it->first); - sigmasij[std::pair<int, int>(it->second.second[1], it->second.second[0])]. - push_back(it->first); + allParts[omegaDim - 1].begin(); + it != allParts[omegaDim - 1].end(); ++it) { + if(it->second.second.size() == 2) { + sigmasij[std::pair<int, int>(it->second.second[0], + it->second.second[1])] + .push_back(it->first); + sigmasij[std::pair<int, int>(it->second.second[1], + it->second.second[0])] + .push_back(it->first); sigmas[it->second.second[0]].push_back(it->first); sigmas[it->second.second[1]].push_back(it->first); } } fprintf(fp, " // Sigma\n"); - for(std::map< std::pair<int, int> , std::vector<int> >::iterator it = - sigmasij.begin(); it != sigmasij.end(); ++it){ - fprintf(fp, " Sigma~{%d}~{%d} = Region[{", it->first.first, it->first.second); - for(size_t j = 0; j < it->second.size(); ++j){ - if(j == 0) fprintf(fp, "%s", tagToString[omegaDim-1][it->second[j]].c_str()); - else fprintf(fp, ", %s", tagToString[omegaDim-1][it->second[j]].c_str()); + for(std::map<std::pair<int, int>, std::vector<int> >::iterator it = + sigmasij.begin(); + it != sigmasij.end(); ++it) { + fprintf(fp, " Sigma~{%d}~{%d} = Region[{", it->first.first, + it->first.second); + for(size_t j = 0; j < it->second.size(); ++j) { + if(j == 0) + fprintf(fp, "%s", tagToString[omegaDim - 1][it->second[j]].c_str()); + else + fprintf(fp, ", %s", tagToString[omegaDim - 1][it->second[j]].c_str()); } fprintf(fp, "}];\n"); } fprintf(fp, "\n"); for(std::map<int, std::vector<int> >::iterator it = sigmas.begin(); - it != sigmas.end(); ++it){ + it != sigmas.end(); ++it) { fprintf(fp, " Sigma~{%d} = Region[{", it->first); - for(size_t j = 0; j < it->second.size(); ++j){ - if(j == 0) fprintf(fp, "%s", tagToString[omegaDim-1][it->second[j]].c_str()); - else fprintf(fp, ", %s", tagToString[omegaDim-1][it->second[j]].c_str()); + for(size_t j = 0; j < it->second.size(); ++j) { + if(j == 0) + fprintf(fp, "%s", tagToString[omegaDim - 1][it->second[j]].c_str()); + else + fprintf(fp, ", %s", tagToString[omegaDim - 1][it->second[j]].c_str()); } fprintf(fp, "}];\n"); } @@ -2881,24 +2944,26 @@ int GModel::writePartitionedTopology(std::string &name) // D fprintf(fp, " D() = {"); - for(size_t i = 1; i <= getNumPartitions(); ++i){ + for(size_t i = 1; i <= getNumPartitions(); ++i) { if(i != 1) fprintf(fp, ", "); fprintf(fp, "%lu", i); } fprintf(fp, "};\n"); - if(omegaDim > 0){ + if(omegaDim > 0) { // D~{i} for(std::multimap<int, std::pair<int, std::vector<int> > >::iterator it = - allParts[omegaDim-1].begin(); it != allParts[omegaDim-1].end(); ++it){ - if(it->second.second.size() == 2){ + allParts[omegaDim - 1].begin(); + it != allParts[omegaDim - 1].end(); ++it) { + if(it->second.second.size() == 2) { neighbors[it->second.second[0]].insert(it->second.second[1]); neighbors[it->second.second[1]].insert(it->second.second[0]); } } - for(size_t i = 1; i <= getNumPartitions(); ++i){ + for(size_t i = 1; i <= getNumPartitions(); ++i) { fprintf(fp, " D~{%lu}() = {", i); - for(std::set<int>::iterator it = neighbors[i].begin(); it != neighbors[i].end(); ++it){ + for(std::set<int>::iterator it = neighbors[i].begin(); + it != neighbors[i].end(); ++it) { if(it != neighbors[i].begin()) fprintf(fp, ", "); fprintf(fp, "%d", *it); } diff --git a/Geo/GModelIO_NEU.cpp b/Geo/GModelIO_NEU.cpp index c6daca23db92baebd3af5f0e8dd47ac9a0aa727c..d3234fb8a8c731e87573d3270d1ff883be3c155c 100644 --- a/Geo/GModelIO_NEU.cpp +++ b/Geo/GModelIO_NEU.cpp @@ -18,17 +18,15 @@ #include "MTriangle.h" #include "MTetrahedron.h" -namespace -{ - //static const unsigned GAMBIT_TYPE_EDGE = 1; - //static const unsigned GAMBIT_TYPE_QUAD = 2; - //static const unsigned GAMBIT_TYPE_TRI = 3; - static const unsigned GAMBIT_TYPE_TET = 6; +namespace { + // static const unsigned GAMBIT_TYPE_EDGE = 1; + // static const unsigned GAMBIT_TYPE_QUAD = 2; + // static const unsigned GAMBIT_TYPE_TRI = 3; + static const unsigned GAMBIT_TYPE_TET = 6; // This struct allows us to take advantage of C++11 unordered_map while // maintaining backwards compatibility with C++03 - template<typename Key, typename Value> - struct hashMap { + template <typename Key, typename Value> struct hashMap { #if __cplusplus >= 201103L typedef std::unordered_map<Key, Value> _; #else @@ -91,35 +89,36 @@ namespace hashMap<std::string, unsigned>::_::value_type("WALL", 51), hashMap<std::string, unsigned>::_::value_type("SPRING", 52), }; - static const hashMap<std::string, unsigned>::_ boundaryCodeMap - (rawData, rawData + (sizeof rawData / sizeof rawData[0])); + static const hashMap<std::string, unsigned>::_ + boundaryCodeMap(rawData, rawData + (sizeof rawData / sizeof rawData[0])); // Gambit numbers its faces slightly differently - static const unsigned GAMBIT_FACE_MAP[4] = {1,2,4,3}; + static const unsigned GAMBIT_FACE_MAP[4] = {1, 2, 4, 3}; unsigned const gambitBoundaryCode(std::string name) { - std::transform(name.begin(), name.end(),name.begin(), ::toupper); - hashMap<std::string, unsigned>::_::const_iterator code = boundaryCodeMap.find(name); + std::transform(name.begin(), name.end(), name.begin(), ::toupper); + hashMap<std::string, unsigned>::_::const_iterator code = + boundaryCodeMap.find(name); return code == boundaryCodeMap.end() ? 0 : code->second; } typedef std::pair<unsigned, unsigned> TetFacePair; typedef hashMap<unsigned, std::vector<TetFacePair> >::_ IDTetFaceMap; - bool const sortBCs(TetFacePair const& lhs, TetFacePair const& rhs) + bool const sortBCs(TetFacePair const &lhs, TetFacePair const &rhs) { return lhs.first < rhs.first; } - IDTetFaceMap const gatherBC(GModel* gm) + IDTetFaceMap const gatherBC(GModel *gm) { // create association map for vertices and faces hashMap<unsigned, std::vector<unsigned> >::_ vertmap; - for (GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) { - for (unsigned i = 0; i < (*it)->triangles.size(); ++i) { - MTriangle* tri = (*it)->triangles[i]; - for (std::size_t j = 0; j < tri->getNumVertices(); ++j) { + for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) { + for(unsigned i = 0; i < (*it)->triangles.size(); ++i) { + MTriangle *tri = (*it)->triangles[i]; + for(std::size_t j = 0; j < tri->getNumVertices(); ++j) { vertmap[tri->getVertex(j)->getNum()].push_back(tri->getNum()); } } @@ -127,15 +126,15 @@ namespace // determine which faces belong to which tetrahedra by comparing vertices IDTetFaceMap tetfacemap; - for (GModel::riter it = gm->firstRegion(); it != gm->lastRegion(); ++it) { - for (unsigned i = 0; i < (*it)->tetrahedra.size(); ++i) { - MTetrahedron* tet = (*it)->tetrahedra[i]; - for (int faceNum = 0; faceNum < tet->getNumFaces(); ++faceNum) { - std::vector<MVertex*> verts; + for(GModel::riter it = gm->firstRegion(); it != gm->lastRegion(); ++it) { + for(unsigned i = 0; i < (*it)->tetrahedra.size(); ++i) { + MTetrahedron *tet = (*it)->tetrahedra[i]; + for(int faceNum = 0; faceNum < tet->getNumFaces(); ++faceNum) { + std::vector<MVertex *> verts; tet->getFaceVertices(faceNum, verts); std::vector<unsigned> current = vertmap[verts[0]->getNum()]; - for (unsigned j = 1; j < verts.size() && current.size() != 0; ++j) { + for(unsigned j = 1; j < verts.size() && current.size() != 0; ++j) { std::vector<unsigned> common_data; set_intersection(current.begin(), current.end(), vertmap[verts[j]->getNum()].begin(), @@ -143,9 +142,9 @@ namespace std::back_inserter(common_data)); current = common_data; } - if (current.size() == 1) { + if(current.size() == 1) { tetfacemap[current[0]].push_back( - TetFacePair(tet->getNum(), GAMBIT_FACE_MAP[faceNum])); + TetFacePair(tet->getNum(), GAMBIT_FACE_MAP[faceNum])); } } } @@ -153,15 +152,15 @@ namespace // populate boundary conditions for tetrahedra given triangle physicals IDTetFaceMap boundaryConditions; - for (GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) { - if ((*it)->physicals.size()) { - for (unsigned i = 0; i < (*it)->physicals.size(); ++i) { + for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) { + if((*it)->physicals.size()) { + for(unsigned i = 0; i < (*it)->physicals.size(); ++i) { unsigned phys = (*it)->physicals[i]; - for (unsigned j = 0; j < (*it)->triangles.size(); ++j) { - MTriangle* tri = (*it)->triangles[j]; + for(unsigned j = 0; j < (*it)->triangles.size(); ++j) { + MTriangle *tri = (*it)->triangles[j]; IDTetFaceMap::iterator tets = tetfacemap.find(tri->getNum()); - if (tets != tetfacemap.end()) { - for (unsigned tet = 0; tet < tets->second.size(); ++tet) { + if(tets != tetfacemap.end()) { + for(unsigned tet = 0; tet < tets->second.size(); ++tet) { boundaryConditions[phys].push_back(tets->second[tet]); } } @@ -172,15 +171,15 @@ namespace return boundaryConditions; } -} +} // namespace // for a specification of the GAMBIT neutral format: // http://web.stanford.edu/class/me469b/handouts/gambit_write.pdf int GModel::writeNEU(const std::string &name, bool saveAll, double scalingFactor) { - FILE* fp = Fopen(name.c_str(), "w"); - if (!fp) { + FILE *fp = Fopen(name.c_str(), "w"); + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -189,16 +188,16 @@ int GModel::writeNEU(const std::string &name, bool saveAll, unsigned numTetrahedra = 0; int lowestId = std::numeric_limits<int>::max(); hashMap<unsigned, std::vector<unsigned> >::_ elementGroups; - for (riter it = firstRegion(); it != lastRegion(); ++it) { - if (saveAll || (*it)->physicals.size()) { + for(riter it = firstRegion(); it != lastRegion(); ++it) { + if(saveAll || (*it)->physicals.size()) { numTetrahedra += (*it)->tetrahedra.size(); - for (unsigned phys = 0; phys < (*it)->physicals.size(); ++phys) { - for (unsigned i = 0; i < (*it)->tetrahedra.size(); ++i) { - MTetrahedron* tet = (*it)->tetrahedra[i]; + for(unsigned phys = 0; phys < (*it)->physicals.size(); ++phys) { + for(unsigned i = 0; i < (*it)->tetrahedra.size(); ++i) { + MTetrahedron *tet = (*it)->tetrahedra[i]; elementGroups[(*it)->physicals[phys]].push_back(tet->getNum()); - if (tet->getNum() < lowestId) lowestId = tet->getNum()-1; + if(tet->getNum() < lowestId) lowestId = tet->getNum() - 1; } } } @@ -217,17 +216,17 @@ int GModel::writeNEU(const std::string &name, bool saveAll, fprintf(fp, "%s", ctime(&rawtime)); fprintf(fp, " NUMNP NELEM NGRPS NBSETS NDFCD NDFVL\n"); - fprintf(fp, " %9d %9d %9lu %9lu %9d %9d\n", indexMeshVertices(saveAll), numTetrahedra, - elementGroups.size(), boundaryConditions.size(), getDim(), - getDim()); + fprintf(fp, " %9d %9d %9lu %9lu %9d %9d\n", indexMeshVertices(saveAll), + numTetrahedra, elementGroups.size(), boundaryConditions.size(), + getDim(), getDim()); fprintf(fp, "ENDOFSECTION\n"); // Nodes fprintf(fp, " NODAL COORDINATES 2.0.0\n"); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); - for (unsigned i = 0; i < entities.size(); ++i) { - for (unsigned j = 0; j < entities[i]->mesh_vertices.size(); ++j) { + for(unsigned i = 0; i < entities.size(); ++i) { + for(unsigned j = 0; j < entities[i]->mesh_vertices.size(); ++j) { entities[i]->mesh_vertices[j]->writeNEU(fp, getDim(), scalingFactor); } } @@ -235,12 +234,12 @@ int GModel::writeNEU(const std::string &name, bool saveAll, // Elements fprintf(fp, " ELEMENTS/CELLS 2.0.0\n"); - for (riter it = firstRegion(); it != lastRegion(); ++it) { + for(riter it = firstRegion(); it != lastRegion(); ++it) { unsigned numPhys = (*it)->physicals.size(); - if (saveAll || numPhys) { - for (unsigned i = 0; i < (*it)->tetrahedra.size(); ++i) { + if(saveAll || numPhys) { + for(unsigned i = 0; i < (*it)->tetrahedra.size(); ++i) { (*it)->tetrahedra[i]->writeNEU(fp, GAMBIT_TYPE_TET, lowestId, - numPhys ? (*it)->physicals[0] : 0); + numPhys ? (*it)->physicals[0] : 0); } } } @@ -248,16 +247,17 @@ int GModel::writeNEU(const std::string &name, bool saveAll, // Element Groups - for (hashMap<unsigned, std::vector<unsigned> >::_::const_iterator - it = elementGroups.begin(); it != elementGroups.end(); ++it) { + for(hashMap<unsigned, std::vector<unsigned> >::_::const_iterator it = + elementGroups.begin(); + it != elementGroups.end(); ++it) { fprintf(fp, " ELEMENT GROUP 2.0.0\n"); fprintf(fp, "GROUP: %10d ELEMENTS: %10lu MATERIAL: 0 NFLAGS: %10d\n", it->first, it->second.size(), 1); fprintf(fp, "Material group %d\n", it->first); fprintf(fp, " 0"); - for (unsigned i = 0; i < it->second.size(); ++i) { - if (i % 10 == 0) { + for(unsigned i = 0; i < it->second.size(); ++i) { + if(i % 10 == 0) { fprintf(fp, "\n"); } fprintf(fp, "%8d", it->second[i] - lowestId); @@ -267,17 +267,18 @@ int GModel::writeNEU(const std::string &name, bool saveAll, } // Boundary Conditions - for (IDTetFaceMap::iterator it = boundaryConditions.begin(); - it != boundaryConditions.end(); ++it) { + for(IDTetFaceMap::iterator it = boundaryConditions.begin(); + it != boundaryConditions.end(); ++it) { fprintf(fp, " BOUNDARY CONDITIONS 2.0.0\n"); std::string const regionName = getPhysicalName(2, it->first); - fprintf(fp, "%32s%8d%8lu%8d%8d\n", regionName.c_str(), 1, it->second.size(), 0, - gambitBoundaryCode(regionName)); + fprintf(fp, "%32s%8d%8lu%8d%8d\n", regionName.c_str(), 1, it->second.size(), + 0, gambitBoundaryCode(regionName)); std::sort(it->second.begin(), it->second.end(), sortBCs); - for (std::vector<TetFacePair>::iterator tfp = it->second.begin(); - tfp != it->second.end(); ++tfp) { - fprintf(fp, "%10d %5d %5d\n", tfp->first-lowestId, GAMBIT_TYPE_TET, tfp->second); + for(std::vector<TetFacePair>::iterator tfp = it->second.begin(); + tfp != it->second.end(); ++tfp) { + fprintf(fp, "%10d %5d %5d\n", tfp->first - lowestId, GAMBIT_TYPE_TET, + tfp->second); } fprintf(fp, "ENDOFSECTION\n"); diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp index 362f14062273cc0af1cd8486e6dfea020da0fd79..1d68222cb7d3c3dc7bfe47bf17f9e4bd725246b4 100644 --- a/Geo/GModelIO_OCC.cpp +++ b/Geo/GModelIO_OCC.cpp @@ -118,21 +118,30 @@ OCC_Internals::OCC_Internals() _meshAttributes = new OCCMeshAttributesRTree(CTX::instance()->geom.tolerance); } -OCC_Internals::~OCC_Internals() -{ - delete _meshAttributes; -} +OCC_Internals::~OCC_Internals() { delete _meshAttributes; } void OCC_Internals::reset() { for(int i = 0; i < 6; i++) _maxTag[i] = 0; _meshAttributes->clear(); - _somap.Clear(); _shmap.Clear(); _fmap.Clear(); _wmap.Clear(); _emap.Clear(); + _somap.Clear(); + _shmap.Clear(); + _fmap.Clear(); + _wmap.Clear(); + _emap.Clear(); _vmap.Clear(); - _vertexTag.Clear(); _edgeTag.Clear(); _faceTag.Clear(); _solidTag.Clear(); - _tagVertex.Clear(); _tagEdge.Clear(); _tagFace.Clear(); _tagSolid.Clear(); - _wireTag.Clear(); _shellTag.Clear(); - _tagWire.Clear(); _tagShell.Clear(); + _vertexTag.Clear(); + _edgeTag.Clear(); + _faceTag.Clear(); + _solidTag.Clear(); + _tagVertex.Clear(); + _tagEdge.Clear(); + _tagFace.Clear(); + _tagSolid.Clear(); + _wireTag.Clear(); + _shellTag.Clear(); + _tagWire.Clear(); + _tagShell.Clear(); _changed = true; } @@ -153,7 +162,7 @@ void OCC_Internals::_recomputeMaxTag(int dim) if(dim < -2 || dim > 3) return; _maxTag[dim + 2] = 0; TopTools_DataMapIteratorOfDataMapOfIntegerShape exp; - switch(dim){ + switch(dim) { case 0: exp.Initialize(_tagVertex); break; case 1: exp.Initialize(_tagEdge); break; case 2: exp.Initialize(_tagFace); break; @@ -168,14 +177,14 @@ void OCC_Internals::_recomputeMaxTag(int dim) void OCC_Internals::bind(const TopoDS_Vertex &vertex, int tag, bool recursive) { if(vertex.IsNull()) return; - if(_vertexTag.IsBound(vertex)){ - if(_vertexTag.Find(vertex) != tag){ + if(_vertexTag.IsBound(vertex)) { + if(_vertexTag.Find(vertex) != tag) { Msg::Info("Cannot bind existing OpenCASCADE point %d to second tag %d", _vertexTag.Find(vertex), tag); } } - else{ - if(_tagVertex.IsBound(tag)){ + else { + if(_tagVertex.IsBound(tag)) { // this leaves the old vertex bound in _vertexTag, but we cannot remove it Msg::Info("Rebinding OpenCASCADE point %d", tag); } @@ -190,14 +199,14 @@ void OCC_Internals::bind(const TopoDS_Vertex &vertex, int tag, bool recursive) void OCC_Internals::bind(const TopoDS_Edge &edge, int tag, bool recursive) { if(edge.IsNull()) return; - if(_edgeTag.IsBound(edge)){ - if(_edgeTag.Find(edge) != tag){ + if(_edgeTag.IsBound(edge)) { + if(_edgeTag.Find(edge) != tag) { Msg::Info("Cannot bind existing OpenCASCADE curve %d to second tag %d", _edgeTag.Find(edge), tag); } } - else{ - if(_tagEdge.IsBound(tag)){ + else { + if(_tagEdge.IsBound(tag)) { // this leaves the old edge bound in _edgeTag, but we cannot remove it Msg::Info("Rebinding OpenCASCADE curve %d", tag); } @@ -207,11 +216,11 @@ void OCC_Internals::bind(const TopoDS_Edge &edge, int tag, bool recursive) _changed = true; _meshAttributes->insert(new OCCMeshAttributes(1, edge)); } - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(edge, TopAbs_VERTEX); exp0.More(); exp0.Next()){ + for(exp0.Init(edge, TopAbs_VERTEX); exp0.More(); exp0.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp0.Current()); - if(!_vertexTag.IsBound(vertex)){ + if(!_vertexTag.IsBound(vertex)) { int t = getMaxTag(0) + 1; bind(vertex, t, recursive); } @@ -222,14 +231,14 @@ void OCC_Internals::bind(const TopoDS_Edge &edge, int tag, bool recursive) void OCC_Internals::bind(const TopoDS_Wire &wire, int tag, bool recursive) { if(wire.IsNull()) return; - if(_wireTag.IsBound(wire)){ - if(_wireTag.Find(wire) != tag){ + if(_wireTag.IsBound(wire)) { + if(_wireTag.Find(wire) != tag) { Msg::Info("Cannot bind existing OpenCASCADE wire %d to second tag %d", _wireTag.Find(wire), tag); } } - else{ - if(_tagWire.IsBound(tag)){ + else { + if(_tagWire.IsBound(tag)) { // this leaves the old wire bound in _wireTag, but we cannot remove it Msg::Info("Rebinding OpenCASCADE wire %d", tag); } @@ -238,11 +247,11 @@ void OCC_Internals::bind(const TopoDS_Wire &wire, int tag, bool recursive) setMaxTag(-1, tag); _changed = true; } - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(wire, TopAbs_EDGE); exp0.More(); exp0.Next()){ + for(exp0.Init(wire, TopAbs_EDGE); exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Current()); - if(!_edgeTag.IsBound(edge)){ + if(!_edgeTag.IsBound(edge)) { int t = getMaxTag(1) + 1; bind(edge, t, recursive); } @@ -253,14 +262,14 @@ void OCC_Internals::bind(const TopoDS_Wire &wire, int tag, bool recursive) void OCC_Internals::bind(const TopoDS_Face &face, int tag, bool recursive) { if(face.IsNull()) return; - if(_faceTag.IsBound(face)){ - if(_faceTag.Find(face) != tag){ + if(_faceTag.IsBound(face)) { + if(_faceTag.Find(face) != tag) { Msg::Info("Cannot bind existing OpenCASCADE surface %d to second tag %d", _faceTag.Find(face), tag); } } - else{ - if(_tagFace.IsBound(tag)){ + else { + if(_tagFace.IsBound(tag)) { // this leaves the old face bound in _faceTag, but we cannot remove it Msg::Info("Rebinding OpenCASCADE surface %d", tag); } @@ -270,18 +279,18 @@ void OCC_Internals::bind(const TopoDS_Face &face, int tag, bool recursive) _changed = true; _meshAttributes->insert(new OCCMeshAttributes(2, face)); } - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(face, TopAbs_WIRE); exp0.More(); exp0.Next()){ + for(exp0.Init(face, TopAbs_WIRE); exp0.More(); exp0.Next()) { TopoDS_Wire wire = TopoDS::Wire(exp0.Current()); - if(!_wireTag.IsBound(wire)){ + if(!_wireTag.IsBound(wire)) { int t = getMaxTag(-1) + 1; bind(wire, t, recursive); } } - for(exp0.Init(face, TopAbs_EDGE); exp0.More(); exp0.Next()){ + for(exp0.Init(face, TopAbs_EDGE); exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Current()); - if(!_edgeTag.IsBound(edge)){ + if(!_edgeTag.IsBound(edge)) { int t = getMaxTag(1) + 1; bind(edge, t, recursive); } @@ -292,14 +301,14 @@ void OCC_Internals::bind(const TopoDS_Face &face, int tag, bool recursive) void OCC_Internals::bind(const TopoDS_Shell &shell, int tag, bool recursive) { if(shell.IsNull()) return; - if(_shellTag.IsBound(shell)){ - if(_shellTag.Find(shell) != tag){ + if(_shellTag.IsBound(shell)) { + if(_shellTag.Find(shell) != tag) { Msg::Info("Cannot bind existing OpenCASCADE shell %d to second tag %d", _shellTag.Find(shell), tag); } } - else{ - if(_tagShell.IsBound(tag)){ + else { + if(_tagShell.IsBound(tag)) { // this leaves the old shell bound in _faceTag, but we cannot remove it Msg::Info("Rebinding OpenCASCADE shell %d", tag); } @@ -308,11 +317,11 @@ void OCC_Internals::bind(const TopoDS_Shell &shell, int tag, bool recursive) setMaxTag(-2, tag); _changed = true; } - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(shell, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(shell, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); - if(!_faceTag.IsBound(face)){ + if(!_faceTag.IsBound(face)) { int t = getMaxTag(2) + 1; bind(face, t, recursive); } @@ -323,14 +332,14 @@ void OCC_Internals::bind(const TopoDS_Shell &shell, int tag, bool recursive) void OCC_Internals::bind(const TopoDS_Solid &solid, int tag, bool recursive) { if(solid.IsNull()) return; - if(_solidTag.IsBound(solid)){ - if(_solidTag.Find(solid) != tag){ + if(_solidTag.IsBound(solid)) { + if(_solidTag.Find(solid) != tag) { Msg::Info("Cannot bind existing OpenCASCADE volume %d to second tag %d", _solidTag.Find(solid), tag); } } - else{ - if(_tagSolid.IsBound(tag)){ + else { + if(_tagSolid.IsBound(tag)) { // this leaves the old solid bound in _faceTag, but we cannot remove it Msg::Info("Rebinding OpenCASCADE volume %d", tag); } @@ -340,18 +349,18 @@ void OCC_Internals::bind(const TopoDS_Solid &solid, int tag, bool recursive) _changed = true; _meshAttributes->insert(new OCCMeshAttributes(3, solid)); } - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(solid, TopAbs_SHELL); exp0.More(); exp0.Next()){ + for(exp0.Init(solid, TopAbs_SHELL); exp0.More(); exp0.Next()) { TopoDS_Shell shell = TopoDS::Shell(exp0.Current()); - if(!_shellTag.IsBound(shell)){ + if(!_shellTag.IsBound(shell)) { int t = getMaxTag(-2) + 1; bind(shell, t, recursive); } } - for(exp0.Init(solid, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(solid, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); - if(!_faceTag.IsBound(face)){ + if(!_faceTag.IsBound(face)) { int t = getMaxTag(3) + 1; bind(face, t, recursive); } @@ -361,7 +370,7 @@ void OCC_Internals::bind(const TopoDS_Solid &solid, int tag, bool recursive) void OCC_Internals::bind(TopoDS_Shape shape, int dim, int tag, bool recursive) { - switch(dim){ + switch(dim) { case 0: bind(TopoDS::Vertex(shape), tag, recursive); break; case 1: bind(TopoDS::Edge(shape), tag, recursive); break; case 2: bind(TopoDS::Face(shape), tag, recursive); break; @@ -375,10 +384,10 @@ void OCC_Internals::bind(TopoDS_Shape shape, int dim, int tag, bool recursive) void OCC_Internals::unbind(const TopoDS_Vertex &vertex, int tag, bool recursive) { TopTools_DataMapIteratorOfDataMapOfIntegerShape exp0(_tagEdge); - for(; exp0.More(); exp0.Next()){ + for(; exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Value()); TopExp_Explorer exp1; - for(exp1.Init(edge, TopAbs_VERTEX); exp1.More(); exp1.Next()){ + for(exp1.Init(edge, TopAbs_VERTEX); exp1.More(); exp1.Next()) { if(exp1.Current().IsSame(vertex)) return; } } @@ -394,10 +403,10 @@ void OCC_Internals::unbind(const TopoDS_Vertex &vertex, int tag, bool recursive) void OCC_Internals::unbind(const TopoDS_Edge &edge, int tag, bool recursive) { TopTools_DataMapIteratorOfDataMapOfIntegerShape exp2(_tagFace); - for(; exp2.More(); exp2.Next()){ + for(; exp2.More(); exp2.Next()) { TopoDS_Face face = TopoDS::Face(exp2.Value()); TopExp_Explorer exp1; - for(exp1.Init(face, TopAbs_EDGE); exp1.More(); exp1.Next()){ + for(exp1.Init(face, TopAbs_EDGE); exp1.More(); exp1.Next()) { if(exp1.Current().IsSame(edge)) return; } } @@ -407,11 +416,11 @@ void OCC_Internals::unbind(const TopoDS_Edge &edge, int tag, bool recursive) _tagEdge.UnBind(tag); _toRemove.insert(dimTag); _recomputeMaxTag(1); - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(edge, TopAbs_VERTEX); exp0.More(); exp0.Next()){ + for(exp0.Init(edge, TopAbs_VERTEX); exp0.More(); exp0.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp0.Current()); - if(_vertexTag.IsBound(vertex)){ + if(_vertexTag.IsBound(vertex)) { int t = _vertexTag.Find(vertex); unbind(vertex, t, recursive); } @@ -423,10 +432,10 @@ void OCC_Internals::unbind(const TopoDS_Edge &edge, int tag, bool recursive) void OCC_Internals::unbind(const TopoDS_Wire &wire, int tag, bool recursive) { TopTools_DataMapIteratorOfDataMapOfIntegerShape exp0(_tagFace); - for(; exp0.More(); exp0.Next()){ + for(; exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Value()); TopExp_Explorer exp1; - for(exp1.Init(face, TopAbs_WIRE); exp1.More(); exp1.Next()){ + for(exp1.Init(face, TopAbs_WIRE); exp1.More(); exp1.Next()) { if(exp1.Current().IsSame(wire)) return; } } @@ -436,11 +445,11 @@ void OCC_Internals::unbind(const TopoDS_Wire &wire, int tag, bool recursive) _tagWire.UnBind(tag); _toRemove.insert(dimTag); _recomputeMaxTag(-1); - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(wire, TopAbs_EDGE); exp0.More(); exp0.Next()){ + for(exp0.Init(wire, TopAbs_EDGE); exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Current()); - if(_edgeTag.IsBound(edge)){ + if(_edgeTag.IsBound(edge)) { int t = _edgeTag.Find(edge); unbind(edge, t, recursive); } @@ -452,10 +461,10 @@ void OCC_Internals::unbind(const TopoDS_Wire &wire, int tag, bool recursive) void OCC_Internals::unbind(const TopoDS_Face &face, int tag, bool recursive) { TopTools_DataMapIteratorOfDataMapOfIntegerShape exp2(_tagSolid); - for(; exp2.More(); exp2.Next()){ + for(; exp2.More(); exp2.Next()) { TopoDS_Solid solid = TopoDS::Solid(exp2.Value()); TopExp_Explorer exp1; - for(exp1.Init(solid, TopAbs_FACE); exp1.More(); exp1.Next()){ + for(exp1.Init(solid, TopAbs_FACE); exp1.More(); exp1.Next()) { if(exp1.Current().IsSame(face)) return; } } @@ -465,18 +474,18 @@ void OCC_Internals::unbind(const TopoDS_Face &face, int tag, bool recursive) _tagFace.UnBind(tag); _toRemove.insert(dimTag); _recomputeMaxTag(2); - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(face, TopAbs_WIRE); exp0.More(); exp0.Next()){ + for(exp0.Init(face, TopAbs_WIRE); exp0.More(); exp0.Next()) { TopoDS_Wire wire = TopoDS::Wire(exp0.Current()); - if(_wireTag.IsBound(wire)){ + if(_wireTag.IsBound(wire)) { int t = _wireTag.Find(wire); unbind(wire, t, recursive); } } - for(exp0.Init(face, TopAbs_EDGE); exp0.More(); exp0.Next()){ + for(exp0.Init(face, TopAbs_EDGE); exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Current()); - if(_edgeTag.IsBound(edge)){ + if(_edgeTag.IsBound(edge)) { int t = _edgeTag.Find(edge); unbind(edge, t, recursive); } @@ -488,10 +497,10 @@ void OCC_Internals::unbind(const TopoDS_Face &face, int tag, bool recursive) void OCC_Internals::unbind(const TopoDS_Shell &shell, int tag, bool recursive) { TopTools_DataMapIteratorOfDataMapOfIntegerShape exp0(_tagSolid); - for(; exp0.More(); exp0.Next()){ + for(; exp0.More(); exp0.Next()) { TopoDS_Solid solid = TopoDS::Solid(exp0.Value()); TopExp_Explorer exp1; - for(exp1.Init(solid, TopAbs_SHELL); exp1.More(); exp1.Next()){ + for(exp1.Init(solid, TopAbs_SHELL); exp1.More(); exp1.Next()) { if(exp1.Current().IsSame(shell)) return; } } @@ -501,11 +510,11 @@ void OCC_Internals::unbind(const TopoDS_Shell &shell, int tag, bool recursive) _tagShell.UnBind(tag); _toRemove.insert(dimTag); _recomputeMaxTag(-2); - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(shell, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(shell, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); - if(_faceTag.IsBound(face)){ + if(_faceTag.IsBound(face)) { int t = _faceTag.Find(face); unbind(face, t, recursive); } @@ -522,18 +531,18 @@ void OCC_Internals::unbind(const TopoDS_Solid &solid, int tag, bool recursive) _tagSolid.UnBind(tag); _toRemove.insert(dimTag); _recomputeMaxTag(3); - if(recursive){ + if(recursive) { TopExp_Explorer exp0; - for(exp0.Init(solid, TopAbs_SHELL); exp0.More(); exp0.Next()){ + for(exp0.Init(solid, TopAbs_SHELL); exp0.More(); exp0.Next()) { TopoDS_Shell shell = TopoDS::Shell(exp0.Current()); - if(_shellTag.IsBound(shell)){ + if(_shellTag.IsBound(shell)) { int t = _shellTag.Find(shell); unbind(shell, t, recursive); } } - for(exp0.Init(solid, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(solid, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); - if(_faceTag.IsBound(face)){ + if(_faceTag.IsBound(face)) { int t = _faceTag.Find(face); unbind(face, t, recursive); } @@ -544,7 +553,7 @@ void OCC_Internals::unbind(const TopoDS_Solid &solid, int tag, bool recursive) void OCC_Internals::unbind(TopoDS_Shape shape, int dim, int tag, bool recursive) { - switch(dim){ + switch(dim) { case 0: unbind(TopoDS::Vertex(shape), tag, recursive); break; case 1: unbind(TopoDS::Edge(shape), tag, recursive); break; case 2: unbind(TopoDS::Face(shape), tag, recursive); break; @@ -562,92 +571,88 @@ void OCC_Internals::_multiBind(const TopoDS_Shape &shape, int tag, { TopExp_Explorer exp0; int count = 0; - for(exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next()){ + for(exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next()) { TopoDS_Solid solid = TopoDS::Solid(exp0.Current()); bool exists = false; int t = tag; - if(t <= 0){ - if(_solidTag.IsBound(solid)){ + if(t <= 0) { + if(_solidTag.IsBound(solid)) { t = _solidTag.Find(solid); exists = true; } else t = getMaxTag(3) + 1; } - else if(count){ + else if(count) { Msg::Error("Cannot bind multiple volumes to single tag %d", t); return; } - if(!exists) - bind(solid, t, recursive); + if(!exists) bind(solid, t, recursive); if(!exists || !returnNewOnly) outDimTags.push_back(std::pair<int, int>(3, t)); count++; } if(highestDimOnly && count) return; - for(exp0.Init(shape, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(shape, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); bool exists = false; int t = tag; - if(t <= 0){ - if(_faceTag.IsBound(face)){ + if(t <= 0) { + if(_faceTag.IsBound(face)) { t = _faceTag.Find(face); exists = true; } else t = getMaxTag(2) + 1; } - else if(count){ + else if(count) { Msg::Error("Cannot bind multiple surfaces to single tag %d", t); return; } - if(!exists) - bind(face, t, recursive); + if(!exists) bind(face, t, recursive); if(!exists || !returnNewOnly) outDimTags.push_back(std::pair<int, int>(2, t)); count++; } if(highestDimOnly && count) return; - for(exp0.Init(shape, TopAbs_EDGE); exp0.More(); exp0.Next()){ + for(exp0.Init(shape, TopAbs_EDGE); exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Current()); bool exists = false; int t = tag; - if(t <= 0){ - if(_edgeTag.IsBound(edge)){ + if(t <= 0) { + if(_edgeTag.IsBound(edge)) { t = _edgeTag.Find(edge); exists = true; } else t = getMaxTag(1) + 1; } - else if(count){ + else if(count) { Msg::Error("Cannot bind multiple curves to single tag %d", t); return; } - if(!exists) - bind(edge, t, recursive); + if(!exists) bind(edge, t, recursive); if(!exists || !returnNewOnly) outDimTags.push_back(std::pair<int, int>(1, t)); count++; } if(highestDimOnly && count) return; - for(exp0.Init(shape, TopAbs_VERTEX); exp0.More(); exp0.Next()){ + for(exp0.Init(shape, TopAbs_VERTEX); exp0.More(); exp0.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp0.Current()); bool exists = false; int t = tag; - if(t <= 0){ - if(_vertexTag.IsBound(vertex)){ + if(t <= 0) { + if(_vertexTag.IsBound(vertex)) { t = _vertexTag.Find(vertex); exists = true; } t = getMaxTag(0) + 1; } - else if(count){ + else if(count) { Msg::Error("Cannot bind multiple points to single tag %d", t); return; } - if(!exists) - bind(vertex, t, recursive); + if(!exists) bind(vertex, t, recursive); if(!exists || !returnNewOnly) outDimTags.push_back(std::pair<int, int>(0, t)); count++; @@ -656,33 +661,33 @@ void OCC_Internals::_multiBind(const TopoDS_Shape &shape, int tag, bool OCC_Internals::_isBound(int dim, int tag) { - switch(dim){ - case 0 : return _tagVertex.IsBound(tag); - case 1 : return _tagEdge.IsBound(tag); - case 2 : return _tagFace.IsBound(tag); - case 3 : return _tagSolid.IsBound(tag); - case -1 : return _tagWire.IsBound(tag); - case -2 : return _tagShell.IsBound(tag); + switch(dim) { + case 0: return _tagVertex.IsBound(tag); + case 1: return _tagEdge.IsBound(tag); + case 2: return _tagFace.IsBound(tag); + case 3: return _tagSolid.IsBound(tag); + case -1: return _tagWire.IsBound(tag); + case -2: return _tagShell.IsBound(tag); default: return false; } } bool OCC_Internals::_isBound(int dim, const TopoDS_Shape &shape) { - switch(dim){ - case 0 : return _vertexTag.IsBound(shape); - case 1 : return _edgeTag.IsBound(shape); - case 2 : return _faceTag.IsBound(shape); - case 3 : return _solidTag.IsBound(shape); - case -1 : return _wireTag.IsBound(shape); - case -2 : return _shellTag.IsBound(shape); + switch(dim) { + case 0: return _vertexTag.IsBound(shape); + case 1: return _edgeTag.IsBound(shape); + case 2: return _faceTag.IsBound(shape); + case 3: return _solidTag.IsBound(shape); + case -1: return _wireTag.IsBound(shape); + case -2: return _shellTag.IsBound(shape); default: return false; } } TopoDS_Shape OCC_Internals::_find(int dim, int tag) { - switch(dim){ + switch(dim) { case 0: return _tagVertex.Find(tag); case 1: return _tagEdge.Find(tag); case 2: return _tagFace.Find(tag); @@ -695,36 +700,35 @@ TopoDS_Shape OCC_Internals::_find(int dim, int tag) int OCC_Internals::_find(int dim, const TopoDS_Shape &shape) { - switch(dim){ - case 0 : return _vertexTag.Find(shape); - case 1 : return _edgeTag.Find(shape); - case 2 : return _faceTag.Find(shape); - case 3 : return _solidTag.Find(shape); - case -1 : return _wireTag.Find(shape); - case -2 : return _shellTag.Find(shape); - default : return -1; + switch(dim) { + case 0: return _vertexTag.Find(shape); + case 1: return _edgeTag.Find(shape); + case 2: return _faceTag.Find(shape); + case 3: return _solidTag.Find(shape); + case -1: return _wireTag.Find(shape); + case -2: return _shellTag.Find(shape); + default: return -1; } } bool OCC_Internals::addVertex(int &tag, double x, double y, double z, double meshSize) { - if(tag >= 0 && _tagVertex.IsBound(tag)){ + if(tag >= 0 && _tagVertex.IsBound(tag)) { Msg::Error("OpenCASCADE point with tag %d already exists", tag); return false; } TopoDS_Vertex result; - try{ + try { gp_Pnt aPnt(x, y, z); BRepBuilderAPI_MakeVertex v(aPnt); v.Build(); - if(!v.IsDone()){ + if(!v.IsDone()) { Msg::Error("Could not create point"); return false; } result = v.Vertex(); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -737,35 +741,34 @@ bool OCC_Internals::addVertex(int &tag, double x, double y, double z, bool OCC_Internals::addLine(int &tag, int startTag, int endTag) { - if(tag >= 0 && _tagEdge.IsBound(tag)){ + if(tag >= 0 && _tagEdge.IsBound(tag)) { Msg::Error("OpenCASCADE curve with tag %d already exists", tag); return false; } - if(!_tagVertex.IsBound(startTag)){ + if(!_tagVertex.IsBound(startTag)) { Msg::Error("Unknown OpenCASCADE point with tag %d", startTag); return false; } - if(!_tagVertex.IsBound(endTag)){ + if(!_tagVertex.IsBound(endTag)) { Msg::Error("Unknown OpenCASCADE point with tag %d", endTag); return false; } - if(startTag == endTag){ + if(startTag == endTag) { Msg::Error("Start and end points of line should be different"); return false; } TopoDS_Edge result; - try{ + try { TopoDS_Vertex start = TopoDS::Vertex(_tagVertex.Find(startTag)); TopoDS_Vertex end = TopoDS::Vertex(_tagVertex.Find(endTag)); BRepBuilderAPI_MakeEdge e(start, end); e.Build(); - if(!e.IsDone()){ + if(!e.IsDone()) { Msg::Error("Could not create line"); return false; } result = e.Edge(); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -776,8 +779,7 @@ bool OCC_Internals::addLine(int &tag, int startTag, int endTag) bool OCC_Internals::addLine(int &tag, const std::vector<int> &pointTags) { - if(pointTags.size() == 2) - return addLine(tag, pointTags[0], pointTags[1]); + if(pointTags.size() == 2) return addLine(tag, pointTags[0], pointTags[1]); // FIXME: if tag < 0 we could create multiple lines Msg::Error("OpenCASCADE polyline currently not supported"); @@ -787,25 +789,25 @@ bool OCC_Internals::addLine(int &tag, const std::vector<int> &pointTags) bool OCC_Internals::_addArc(int &tag, int startTag, int centerTag, int endTag, int mode) { - if(tag >= 0 && _tagEdge.IsBound(tag)){ + if(tag >= 0 && _tagEdge.IsBound(tag)) { Msg::Error("OpenCASCADE curve with tag %d already exists", tag); return false; } - if(!_tagVertex.IsBound(startTag)){ + if(!_tagVertex.IsBound(startTag)) { Msg::Error("Unknown OpenCASCADE point with tag %d", startTag); return false; } - if(!_tagVertex.IsBound(centerTag)){ + if(!_tagVertex.IsBound(centerTag)) { Msg::Error("Unknown OpenCASCADE point with tag %d", centerTag); return false; } - if(!_tagVertex.IsBound(endTag)){ + if(!_tagVertex.IsBound(endTag)) { Msg::Error("Unknown OpenCASCADE point with tag %d", endTag); return false; } TopoDS_Edge result; - try{ + try { TopoDS_Vertex start = TopoDS::Vertex(_tagVertex.Find(startTag)); TopoDS_Vertex center = TopoDS::Vertex(_tagVertex.Find(centerTag)); TopoDS_Vertex end = TopoDS::Vertex(_tagVertex.Find(endTag)); @@ -813,10 +815,10 @@ bool OCC_Internals::_addArc(int &tag, int startTag, int centerTag, int endTag, gp_Pnt aP2 = BRep_Tool::Pnt(center); gp_Pnt aP3 = BRep_Tool::Pnt(end); Handle(Geom_TrimmedCurve) arc; - if(mode == 0){ // circle + if(mode == 0) { // circle Standard_Real Radius = aP1.Distance(aP2); gce_MakeCirc MC(aP2, gce_MakePln(aP1, aP2, aP3).Value(), Radius); - if(!MC.IsDone()){ + if(!MC.IsDone()) { Msg::Error("Could not build circle"); return false; } @@ -826,9 +828,9 @@ bool OCC_Internals::_addArc(int &tag, int startTag, int centerTag, int endTag, Handle(Geom_Circle) C = new Geom_Circle(Circ); arc = new Geom_TrimmedCurve(C, Alpha1, Alpha2, false); } - else{ + else { gce_MakeElips ME(aP1, aP3, aP2); - if(!ME.IsDone()){ + if(!ME.IsDone()) { Msg::Error("Could not build ellipse"); return false; } @@ -840,13 +842,12 @@ bool OCC_Internals::_addArc(int &tag, int startTag, int centerTag, int endTag, } BRepBuilderAPI_MakeEdge e(arc, start, end); e.Build(); - if(!e.IsDone()){ + if(!e.IsDone()) { Msg::Error("Could not create %s arc", mode ? "ellipse" : "circle"); return false; } result = e.Edge(); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -855,12 +856,14 @@ bool OCC_Internals::_addArc(int &tag, int startTag, int centerTag, int endTag, return true; } -bool OCC_Internals::addCircleArc(int &tag, int startTag, int centerTag, int endTag) +bool OCC_Internals::addCircleArc(int &tag, int startTag, int centerTag, + int endTag) { return _addArc(tag, startTag, centerTag, endTag, 0); } -bool OCC_Internals::addEllipseArc(int &tag, int startTag, int centerTag, int endTag) +bool OCC_Internals::addEllipseArc(int &tag, int startTag, int centerTag, + int endTag) { return _addArc(tag, startTag, centerTag, endTag, 1); } @@ -868,37 +871,37 @@ bool OCC_Internals::addEllipseArc(int &tag, int startTag, int centerTag, int end bool OCC_Internals::addCircle(int &tag, double x, double y, double z, double r, double angle1, double angle2) { - if(tag >= 0 && _tagEdge.IsBound(tag)){ + if(tag >= 0 && _tagEdge.IsBound(tag)) { Msg::Error("OpenCASCADE curve with tag %d already exists", tag); return false; } - if(r <= 0){ + if(r <= 0) { Msg::Error("Circle radius should be positive"); return false; } TopoDS_Edge result; - try{ + try { gp_Dir N_dir(0., 0., 1.); gp_Dir x_dir(1., 0., 0.); gp_Pnt center(x, y, z); gp_Ax2 axis(center, N_dir, x_dir); gp_Circ circ(axis, r); - if(angle1 == 0. && angle2 == 2 * M_PI){ + if(angle1 == 0. && angle2 == 2 * M_PI) { result = BRepBuilderAPI_MakeEdge(circ); } - else{ + else { Handle(Geom_Circle) C = new Geom_Circle(circ); - Handle(Geom_TrimmedCurve) arc = new Geom_TrimmedCurve(C, angle1, angle2, false); + Handle(Geom_TrimmedCurve) arc = + new Geom_TrimmedCurve(C, angle1, angle2, false); BRepBuilderAPI_MakeEdge e(arc); - if(!e.IsDone()){ + if(!e.IsDone()) { Msg::Error("Could not create circle arc"); return false; } result = e.Edge(); } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -907,44 +910,45 @@ bool OCC_Internals::addCircle(int &tag, double x, double y, double z, double r, return true; } -bool OCC_Internals::addEllipse(int &tag, double x, double y, double z, double rx, - double ry, double angle1, double angle2) +bool OCC_Internals::addEllipse(int &tag, double x, double y, double z, + double rx, double ry, double angle1, + double angle2) { - if(tag >= 0 && _tagEdge.IsBound(tag)){ + if(tag >= 0 && _tagEdge.IsBound(tag)) { Msg::Error("OpenCASCADE curve with tag %d already exists", tag); return false; } - if(ry > rx){ + if(ry > rx) { Msg::Error("Major radius rx should be larger than minor radius ry"); return false; } - if(ry <= 0 || rx <= 0){ + if(ry <= 0 || rx <= 0) { Msg::Error("Ellipse radii should be positive"); return false; } TopoDS_Edge result; - try{ + try { gp_Dir N_dir(0., 0., 1.); gp_Dir x_dir(1., 0., 0.); gp_Pnt center(x, y, z); gp_Ax2 axis(center, N_dir, x_dir); gp_Elips elips(axis, rx, ry); - if(angle1 == 0 && angle2 == 2 * M_PI){ + if(angle1 == 0 && angle2 == 2 * M_PI) { result = BRepBuilderAPI_MakeEdge(elips); } - else{ + else { Handle(Geom_Ellipse) E = new Geom_Ellipse(elips); - Handle(Geom_TrimmedCurve) arc = new Geom_TrimmedCurve(E, angle1, angle2, true); + Handle(Geom_TrimmedCurve) arc = + new Geom_TrimmedCurve(E, angle1, angle2, true); BRepBuilderAPI_MakeEdge e(arc); - if(!e.IsDone()){ + if(!e.IsDone()) { Msg::Error("Could not create ellipse arc"); return false; } result = e.Edge(); } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -953,7 +957,7 @@ bool OCC_Internals::addEllipse(int &tag, double x, double y, double z, double rx return true; } -void debugBSpline(const Handle(Geom_BSplineCurve) &curve) +void debugBSpline(const Handle(Geom_BSplineCurve) & curve) { int degree = curve->Degree(); bool periodic = curve->IsPeriodic(); @@ -990,21 +994,21 @@ bool OCC_Internals::_addBSpline(int &tag, const std::vector<int> &pointTags, const std::vector<double> &knots, const std::vector<int> &multiplicities) { - if(tag >= 0 && _tagEdge.IsBound(tag)){ + if(tag >= 0 && _tagEdge.IsBound(tag)) { Msg::Error("OpenCASCADE curve with tag %d already exists", tag); return false; } - if(pointTags.size() < 2){ + if(pointTags.size() < 2) { Msg::Error("Number of control points should be at least 2"); return false; } TopoDS_Edge result; - try{ + try { TColgp_Array1OfPnt ctrlPoints(1, pointTags.size()); TopoDS_Vertex start, end; - for(unsigned int i = 0; i < pointTags.size(); i++){ - if(!_tagVertex.IsBound(pointTags[i])){ + for(unsigned int i = 0; i < pointTags.size(); i++) { + if(!_tagVertex.IsBound(pointTags[i])) { Msg::Error("Unknown OpenCASCADE point with tag %d", pointTags[i]); return false; } @@ -1014,7 +1018,7 @@ bool OCC_Internals::_addBSpline(int &tag, const std::vector<int> &pointTags, if(i == pointTags.size() - 1) end = vertex; } bool periodic = (pointTags.front() == pointTags.back()); - if(mode == 0){ + if(mode == 0) { // BSpline through points (called "Spline" in Gmsh; will be C2, whereas it // is only C1 in the GEO kernel; also works for the periodic case, // contrary to GEO kernel) @@ -1023,94 +1027,102 @@ bool OCC_Internals::_addBSpline(int &tag, const std::vector<int> &pointTags, for(int i = 1; i <= np; i++) p->SetValue(i, ctrlPoints(i)); GeomAPI_Interpolate intp(p, periodic, CTX::instance()->geom.tolerance); intp.Perform(); - if(!intp.IsDone()){ + if(!intp.IsDone()) { Msg::Error("Could not interpolate spline"); return false; } Handle(Geom_BSplineCurve) curve = intp.Curve(); BRepBuilderAPI_MakeEdge e(curve, start, end); - if(!e.IsDone()){ + if(!e.IsDone()) { Msg::Error("Could not create spline"); return false; } result = e.Edge(); } - else if(mode == 1){ + else if(mode == 1) { // Bezier curve Handle(Geom_BezierCurve) curve = new Geom_BezierCurve(ctrlPoints); BRepBuilderAPI_MakeEdge e(curve, start, end); - if(!e.IsDone()){ + if(!e.IsDone()) { Msg::Error("Could not create Bezier curve"); return false; } result = e.Edge(); } - else if(mode == 2){ + else if(mode == 2) { // General BSpline curve, polynomial or rational, with explicit degree, // weights, knots and multiplicities - if(degree < 0){ + if(degree < 0) { Msg::Error("BSpline degree (%d) should be >= 0", degree); return false; } - if(weights.size() != pointTags.size()){ + if(weights.size() != pointTags.size()) { Msg::Error("Number of BSpline weights (%d) and control points (%d) " - "should equal", weights.size(), pointTags.size()); + "should equal", + weights.size(), pointTags.size()); return false; } - if(knots.size() != multiplicities.size()){ - Msg::Error("Number of BSpline knots (%d) and multiplicities (%d) should " - "equal", knots.size(), multiplicities.size()); + if(knots.size() != multiplicities.size()) { + Msg::Error( + "Number of BSpline knots (%d) and multiplicities (%d) should " + "equal", + knots.size(), multiplicities.size()); return false; } - if(knots.size() < 2){ + if(knots.size() < 2) { Msg::Error("Number of BSpline knots (%d) should be >= 2", knots.size()); return false; } - for(unsigned int i = 0; i < knots.size() - 1; i++){ - if(knots[i] >= knots[i+1]){ + for(unsigned int i = 0; i < knots.size() - 1; i++) { + if(knots[i] >= knots[i + 1]) { Msg::Error("BSpline knots should be increasing: knot %d (%g) > " - "knot %d (%g)", i, knots[i], i + 1, knots[i + 1]); + "knot %d (%g)", + i, knots[i], i + 1, knots[i + 1]); return false; } } - for(unsigned int i = 0; i < multiplicities.size(); i++){ - if(multiplicities[i] < 1){ + for(unsigned int i = 0; i < multiplicities.size(); i++) { + if(multiplicities[i] < 1) { Msg::Error("BSpline multiplicities should be >= 1"); return false; } if(i != 0 && i != multiplicities.size() - 1 && - multiplicities[i] > degree){ - Msg::Error("BSpline interior knot multiplicities should be <= degree"); + multiplicities[i] > degree) { + Msg::Error( + "BSpline interior knot multiplicities should be <= degree"); return false; } if((i == 0 || i == multiplicities.size() - 1) && - multiplicities[i] > degree + 1){ + multiplicities[i] > degree + 1) { Msg::Error("BSpline end knot multiplicities should be <= degree + 1"); return false; } } - if(periodic){ - if(multiplicities.front() != multiplicities.back()){ - Msg::Error("Periodic BSpline end knot multiplicies (%d and %d) should " - "be equal", multiplicities.front(), multiplicities.back()); + if(periodic) { + if(multiplicities.front() != multiplicities.back()) { + Msg::Error( + "Periodic BSpline end knot multiplicies (%d and %d) should " + "be equal", + multiplicities.front(), multiplicities.back()); return false; } // TODO C++11 std::accumulate std::size_t sum = 0; for(unsigned int i = 0; i < multiplicities.size() - 1; i++) sum += multiplicities[i]; - if(pointTags.size() - 1 != sum){ - Msg::Error("Number of control points - 1 for periodic BSpline should " - "be equal to the sum of multiplicities for all knots except " - "the first (or last)"); + if(pointTags.size() - 1 != sum) { + Msg::Error( + "Number of control points - 1 for periodic BSpline should " + "be equal to the sum of multiplicities for all knots except " + "the first (or last)"); return false; } } - else{ + else { std::size_t sum = 0; for(unsigned int i = 0; i < multiplicities.size(); i++) sum += multiplicities[i]; - if(pointTags.size() != sum - degree - 1){ + if(pointTags.size() != sum - degree - 1) { Msg::Error("Number of control points for non-periodic BSpline should " "be equal to the sum of multiplicities - degree - 1"); return false; @@ -1119,40 +1131,39 @@ bool OCC_Internals::_addBSpline(int &tag, const std::vector<int> &pointTags, int np = (periodic ? ctrlPoints.Length() - 1 : ctrlPoints.Length()); TColgp_Array1OfPnt p(1, np); TColStd_Array1OfReal w(1, np); - for(int i = 1; i <= np; i++){ + for(int i = 1; i <= np; i++) { p.SetValue(i, ctrlPoints(i)); w.SetValue(i, weights[i - 1]); } TColStd_Array1OfReal k(1, knots.size()); - for(unsigned int i = 0; i < knots.size(); i++) + for(unsigned int i = 0; i < knots.size(); i++) k.SetValue(i + 1, knots[i]); TColStd_Array1OfInteger m(1, multiplicities.size()); - for(unsigned int i = 0; i < multiplicities.size(); i++) + for(unsigned int i = 0; i < multiplicities.size(); i++) m.SetValue(i + 1, multiplicities[i]); Handle(Geom_BSplineCurve) curve = new Geom_BSplineCurve(p, w, k, m, degree, periodic); - if(curve->StartPoint().IsEqual - (BRep_Tool::Pnt(start), CTX::instance()->geom.tolerance) && - curve->EndPoint().IsEqual - (BRep_Tool::Pnt(end), CTX::instance()->geom.tolerance)){ + if(curve->StartPoint().IsEqual(BRep_Tool::Pnt(start), + CTX::instance()->geom.tolerance) && + curve->EndPoint().IsEqual(BRep_Tool::Pnt(end), + CTX::instance()->geom.tolerance)) { BRepBuilderAPI_MakeEdge e(curve, start, end); - if(!e.IsDone()){ + if(!e.IsDone()) { Msg::Error("Could not create BSpline curve (with end points)"); return false; } result = e.Edge(); } - else{ // will create new topo vertices as necessary + else { // will create new topo vertices as necessary BRepBuilderAPI_MakeEdge e(curve); - if(!e.IsDone()){ + if(!e.IsDone()) { Msg::Error("Could not create BSpline curve (without end points)"); return false; } result = e.Edge(); } } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1177,7 +1188,7 @@ bool OCC_Internals::addBSpline(int &tag, const std::vector<int> &pointTags, const std::vector<double> &knots, const std::vector<int> &multiplicities) { - if(pointTags.size() < 2){ + if(pointTags.size() < 2) { Msg::Error("BSpline curve requires at least 2 control points"); return false; } @@ -1191,26 +1202,25 @@ bool OCC_Internals::addBSpline(int &tag, const std::vector<int> &pointTags, // automatic default weights if not provided: if(w.empty()) w.resize(pointTags.size(), 1); // automatic default knots and multiplicities if not provided: - if(k.empty()){ + if(k.empty()) { bool periodic = (pointTags.front() == pointTags.back()); - if(!periodic){ + if(!periodic) { int sum_of_all_mult = pointTags.size() + d + 1; int num_knots = sum_of_all_mult - 2 * d; - if(num_knots < 2){ - Msg::Error("Not enough control points for building BSpline of degree %d", d); + if(num_knots < 2) { + Msg::Error( + "Not enough control points for building BSpline of degree %d", d); return false; } k.resize(num_knots); - for(unsigned int i = 0; i < k.size(); i++) - k[i] = i; + for(unsigned int i = 0; i < k.size(); i++) k[i] = i; m.resize(num_knots, 1); m.front() = d + 1; m.back() = d + 1; } - else{ + else { k.resize(pointTags.size() - 1); - for(unsigned int i = 0; i < k.size(); i++) - k[i] = i; + for(unsigned int i = 0; i < k.size(); i++) k[i] = i; m.resize(k.size(), 1); m.front() = d - 1; m.back() = d - 1; @@ -1222,16 +1232,16 @@ bool OCC_Internals::addBSpline(int &tag, const std::vector<int> &pointTags, bool OCC_Internals::addWire(int &tag, const std::vector<int> &curveTags, bool checkClosed) { - if(tag >= 0 && _tagWire.IsBound(tag)){ + if(tag >= 0 && _tagWire.IsBound(tag)) { Msg::Error("OpenCASCADE wire or line loop with tag %d already exists", tag); return false; } TopoDS_Wire result; - try{ + try { BRepBuilderAPI_MakeWire w; - for (unsigned int i = 0; i < curveTags.size(); i++) { - if(!_tagEdge.IsBound(curveTags[i])){ + for(unsigned int i = 0; i < curveTags.size(); i++) { + if(!_tagEdge.IsBound(curveTags[i])) { Msg::Error("Unknown OpenCASCADE curve with tag %d", curveTags[i]); return false; } @@ -1239,12 +1249,11 @@ bool OCC_Internals::addWire(int &tag, const std::vector<int> &curveTags, w.Add(edge); } result = w.Wire(); - if(checkClosed && !result.Closed()){ + if(checkClosed && !result.Closed()) { Msg::Error("Line Loop is not closed"); return false; } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1258,21 +1267,20 @@ bool OCC_Internals::addLineLoop(int &tag, const std::vector<int> &curveTags) std::vector<int> tags(curveTags); // all edge tags > 0 for OCC : to improve compatibility between GEO and OCC // factories, allow negative tags - and simply ignore the sign here - for(unsigned int i = 0; i < tags.size(); i++) - tags[i] = std::abs(tags[i]); + for(unsigned int i = 0; i < tags.size(); i++) tags[i] = std::abs(tags[i]); return addWire(tag, tags, true); } static bool makeRectangle(TopoDS_Face &result, double x, double y, double z, double dx, double dy, double roundedRadius) { - if(!dx || !dy){ + if(!dx || !dy) { Msg::Error("Rectangle with zero width or height"); return false; } - try{ + try { TopoDS_Wire wire; - if(roundedRadius <= 0.){ + if(roundedRadius <= 0.) { double x1 = x, y1 = y, z1 = z, x2 = x1 + dx, y2 = y1 + dy; TopoDS_Vertex v1 = BRepBuilderAPI_MakeVertex(gp_Pnt(x1, y1, z1)); TopoDS_Vertex v2 = BRepBuilderAPI_MakeVertex(gp_Pnt(x2, y1, z1)); @@ -1284,11 +1292,25 @@ static bool makeRectangle(TopoDS_Face &result, double x, double y, double z, TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(v4, v1); wire = BRepBuilderAPI_MakeWire(e1, e2, e3, e4); } - else{ + else { double x1, y1, z1 = z, x2, y2; double r = roundedRadius; - if(dx > 0.){ x1 = x; x2 = x1 + dx; } else{ x2 = x; x1 = x2 + dx; } - if(dy > 0.){ y1 = y; y2 = y1 + dy; } else{ y2 = y; y1 = y2 + dy; } + if(dx > 0.) { + x1 = x; + x2 = x1 + dx; + } + else { + x2 = x; + x1 = x2 + dx; + } + if(dy > 0.) { + y1 = y; + y2 = y1 + dy; + } + else { + y2 = y; + y1 = y2 + dy; + } TopoDS_Vertex v1 = BRepBuilderAPI_MakeVertex(gp_Pnt(x1 + r, y1, z1)); TopoDS_Vertex v2 = BRepBuilderAPI_MakeVertex(gp_Pnt(x2 - r, y1, z1)); TopoDS_Vertex v3 = BRepBuilderAPI_MakeVertex(gp_Pnt(x2, y1 + r, z1)); @@ -1314,22 +1336,31 @@ static bool makeRectangle(TopoDS_Face &result, double x, double y, double z, Handle(Geom_Circle) circle2 = new Geom_Circle(circ2); Handle(Geom_Circle) circle3 = new Geom_Circle(circ3); Handle(Geom_Circle) circle4 = new Geom_Circle(circ4); - Handle(Geom_TrimmedCurve) arc1 = new Geom_TrimmedCurve(circle1, -M_PI, -M_PI/2., true); - Handle(Geom_TrimmedCurve) arc2 = new Geom_TrimmedCurve(circle2, -M_PI/2, 0, true); - Handle(Geom_TrimmedCurve) arc3 = new Geom_TrimmedCurve(circle3, 0, M_PI/2, true); - Handle(Geom_TrimmedCurve) arc4 = new Geom_TrimmedCurve(circle4, M_PI/2, M_PI, true); + Handle(Geom_TrimmedCurve) arc1 = + new Geom_TrimmedCurve(circle1, -M_PI, -M_PI / 2., true); + Handle(Geom_TrimmedCurve) arc2 = + new Geom_TrimmedCurve(circle2, -M_PI / 2, 0, true); + Handle(Geom_TrimmedCurve) arc3 = + new Geom_TrimmedCurve(circle3, 0, M_PI / 2, true); + Handle(Geom_TrimmedCurve) arc4 = + new Geom_TrimmedCurve(circle4, M_PI / 2, M_PI, true); TopoDS_Edge ce1 = BRepBuilderAPI_MakeEdge(arc1, v8, v1); TopoDS_Edge ce2 = BRepBuilderAPI_MakeEdge(arc2, v2, v3); TopoDS_Edge ce3 = BRepBuilderAPI_MakeEdge(arc3, v4, v5); TopoDS_Edge ce4 = BRepBuilderAPI_MakeEdge(arc4, v6, v7); BRepBuilderAPI_MakeWire w; - w.Add(e1); w.Add(ce2); w.Add(e2); w.Add(ce3); - w.Add(e3); w.Add(ce4); w.Add(e4); w.Add(ce1); + w.Add(e1); + w.Add(ce2); + w.Add(e2); + w.Add(ce3); + w.Add(e3); + w.Add(ce4); + w.Add(e4); + w.Add(ce1); wire = w.Wire(); } result = BRepBuilderAPI_MakeFace(wire); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1339,13 +1370,12 @@ static bool makeRectangle(TopoDS_Face &result, double x, double y, double z, bool OCC_Internals::addRectangle(int &tag, double x, double y, double z, double dx, double dy, double roundedRadius) { - if(tag >= 0 && _tagFace.IsBound(tag)){ + if(tag >= 0 && _tagFace.IsBound(tag)) { Msg::Error("OpenCASCADE surface with tag %d already exists", tag); return false; } TopoDS_Face result; - if(!makeRectangle(result, x, y, z, dx, dy, roundedRadius)) - return false; + if(!makeRectangle(result, x, y, z, dx, dy, roundedRadius)) return false; if(tag < 0) tag = getMaxTag(2) + 1; bind(result, tag, true); return true; @@ -1354,15 +1384,15 @@ bool OCC_Internals::addRectangle(int &tag, double x, double y, double z, static bool makeDisk(TopoDS_Face &result, double xc, double yc, double zc, double rx, double ry) { - if(ry > rx){ + if(ry > rx) { Msg::Error("Major radius rx should be larger than minor radius ry"); return false; } - if(ry <= 0 || rx <= 0){ + if(ry <= 0 || rx <= 0) { Msg::Error("Disk radius should be positive"); return false; } - try{ + try { gp_Dir N_dir(0., 0., 1.); gp_Dir x_dir(1., 0., 0.); gp_Pnt center(xc, yc, zc); @@ -1371,8 +1401,7 @@ static bool makeDisk(TopoDS_Face &result, double xc, double yc, double zc, TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(ellipse); TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edge); result = BRepBuilderAPI_MakeFace(wire); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1382,13 +1411,12 @@ static bool makeDisk(TopoDS_Face &result, double xc, double yc, double zc, bool OCC_Internals::addDisk(int &tag, double xc, double yc, double zc, double rx, double ry) { - if(tag >= 0 && _tagFace.IsBound(tag)){ + if(tag >= 0 && _tagFace.IsBound(tag)) { Msg::Error("OpenCASCADE surface with tag %d already exists", tag); return false; } TopoDS_Face result; - if(!makeDisk(result, xc, yc, zc, rx, ry)) - return false; + if(!makeDisk(result, xc, yc, zc, rx, ry)) return false; if(tag < 0) tag = getMaxTag(2) + 1; bind(result, tag, true); return true; @@ -1396,14 +1424,14 @@ bool OCC_Internals::addDisk(int &tag, double xc, double yc, double zc, bool OCC_Internals::addPlaneSurface(int &tag, const std::vector<int> &wireTags) { - if(tag >= 0 && _tagFace.IsBound(tag)){ + if(tag >= 0 && _tagFace.IsBound(tag)) { Msg::Error("OpenCASCADE surface with tag %d already exists", tag); return false; } std::vector<TopoDS_Wire> wires; - for (unsigned int i = 0; i < wireTags.size(); i++) { - if(!_tagWire.IsBound(wireTags[i])){ + for(unsigned int i = 0; i < wireTags.size(); i++) { + if(!_tagWire.IsBound(wireTags[i])) { Msg::Error("Unknown OpenCASCADE line loop with tag %d", wireTags[i]); return false; } @@ -1412,33 +1440,32 @@ bool OCC_Internals::addPlaneSurface(int &tag, const std::vector<int> &wireTags) } TopoDS_Face result; - if(wires.size() == 0){ + if(wires.size() == 0) { Msg::Error("Plane surface requires at least one line loop"); return false; } - try{ + try { BRepBuilderAPI_MakeFace f(wires[0]); - for(unsigned int i = 1; i < wires.size(); i++){ + for(unsigned int i = 1; i < wires.size(); i++) { // holes TopoDS_Wire w = wires[i]; w.Orientation(TopAbs_REVERSED); f.Add(w); } f.Build(); - if(!f.IsDone()){ + if(!f.IsDone()) { Msg::Error("Could not create face"); return false; } result = f.Face(); - if(CTX::instance()->geom.occAutoFix){ + if(CTX::instance()->geom.occAutoFix) { // make sure wires are oriented correctly ShapeFix_Face fix(result); fix.Perform(); result = fix.Face(); } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1453,26 +1480,28 @@ bool OCC_Internals::addSurfaceFilling(int &tag, int wireTag, const std::vector<int> &surfaceTags, const std::vector<int> &surfaceContinuity) { - if(tag >= 0 && _tagFace.IsBound(tag)){ + if(tag >= 0 && _tagFace.IsBound(tag)) { Msg::Error("OpenCASCADE surface with tag %d already exists", tag); return false; } TopoDS_Face result; - try{ + try { BRepOffsetAPI_MakeFilling f; // bounding edge constraints - if(!_tagWire.IsBound(wireTag)){ + if(!_tagWire.IsBound(wireTag)) { Msg::Error("Unknown OpenCASCADE line loop with tag %d", wireTag); return false; } TopoDS_Wire wire = TopoDS::Wire(_tagWire.Find(wireTag)); TopExp_Explorer exp0; std::size_t i = 0; - for(exp0.Init(wire, TopAbs_EDGE); exp0.More(); exp0.Next()){ + for(exp0.Init(wire, TopAbs_EDGE); exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Current()); - if(i < surfaceTags.size()){ // associated face constraint (does not seem to work...) - if(!_tagFace.IsBound(surfaceTags[i])){ + if(i < + surfaceTags + .size()) { // associated face constraint (does not seem to work...) + if(!_tagFace.IsBound(surfaceTags[i])) { Msg::Error("Unknown OpenCASCADE surface with tag %d", surfaceTags[i]); return false; } @@ -1482,14 +1511,14 @@ bool OCC_Internals::addSurfaceFilling(int &tag, int wireTag, else f.Add(edge, face, GeomAbs_G1); } - else{ + else { f.Add(edge, GeomAbs_C0); } i++; } // point constraints - for(unsigned int i = 0; i < pointTags.size(); i++){ - if(!_tagVertex.IsBound(pointTags[i])){ + for(unsigned int i = 0; i < pointTags.size(); i++) { + if(!_tagVertex.IsBound(pointTags[i])) { Msg::Error("Unknown OpenCASCADE point with tag %d", pointTags[i]); return false; } @@ -1497,7 +1526,7 @@ bool OCC_Internals::addSurfaceFilling(int &tag, int wireTag, f.Add(BRep_Tool::Pnt(vertex)); } f.Build(); - if(!f.IsDone()){ + if(!f.IsDone()) { Msg::Error("Could not build surface filling"); return false; } @@ -1510,8 +1539,7 @@ bool OCC_Internals::addSurfaceFilling(int &tag, int wireTag, ShapeFix_Face fix(result); fix.Perform(); result = fix.Face(); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1521,18 +1549,19 @@ bool OCC_Internals::addSurfaceFilling(int &tag, int wireTag, return true; } -bool OCC_Internals::addSurfaceLoop(int &tag, const std::vector<int> &surfaceTags) +bool OCC_Internals::addSurfaceLoop(int &tag, + const std::vector<int> &surfaceTags) { - if(tag >= 0 && _tagShell.IsBound(tag)){ + if(tag >= 0 && _tagShell.IsBound(tag)) { Msg::Error("OpenCASCADE surface loop with tag %d already exists", tag); return false; } TopoDS_Shape result; - try{ + try { BRepBuilderAPI_Sewing s; - for (unsigned int i = 0; i < surfaceTags.size(); i++) { - if(!_tagFace.IsBound(surfaceTags[i])){ + for(unsigned int i = 0; i < surfaceTags.size(); i++) { + if(!_tagFace.IsBound(surfaceTags[i])) { Msg::Error("Unknown OpenCASCADE surface with tag %d", surfaceTags[i]); return false; } @@ -1541,27 +1570,26 @@ bool OCC_Internals::addSurfaceLoop(int &tag, const std::vector<int> &surfaceTags } s.Perform(); result = s.SewedShape(); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } bool first = true; TopExp_Explorer exp0; - for(exp0.Init(result, TopAbs_SHELL); exp0.More(); exp0.Next()){ + for(exp0.Init(result, TopAbs_SHELL); exp0.More(); exp0.Next()) { TopoDS_Shell shell = TopoDS::Shell(exp0.Current()); - if(CTX::instance()->geom.occAutoFix){ + if(CTX::instance()->geom.occAutoFix) { // make sure faces in shell are oriented correctly ShapeFix_Shell fix(shell); fix.Perform(); shell = fix.Shell(); } int t = tag; - if(first){ + if(first) { first = false; } - else{ + else { t = getMaxTag(-2) + 1; Msg::Warning("Creating additional surface loop %d", t); } @@ -1572,31 +1600,31 @@ bool OCC_Internals::addSurfaceLoop(int &tag, const std::vector<int> &surfaceTags bool OCC_Internals::addVolume(int &tag, const std::vector<int> &shellTags) { - if(tag >= 0 && _tagSolid.IsBound(tag)){ + if(tag >= 0 && _tagSolid.IsBound(tag)) { Msg::Error("OpenCASCADE volume with tag %d already exists", tag); return false; } TopoDS_Solid result; - try{ + try { BRepBuilderAPI_MakeSolid s; - for (unsigned int i = 0; i < shellTags.size(); i++) { - if(!_tagShell.IsBound(shellTags[i])){ - Msg::Error("Unknown OpenCASCADE surface loop with tag %d", shellTags[i]); + for(unsigned int i = 0; i < shellTags.size(); i++) { + if(!_tagShell.IsBound(shellTags[i])) { + Msg::Error("Unknown OpenCASCADE surface loop with tag %d", + shellTags[i]); return false; } TopoDS_Shell shell = TopoDS::Shell(_tagShell.Find(shellTags[i])); s.Add(shell); } result = s.Solid(); - if(CTX::instance()->geom.occAutoFix){ + if(CTX::instance()->geom.occAutoFix) { // make sure the volume is finite ShapeFix_Solid fix(result); fix.Perform(); result = TopoDS::Solid(fix.Solid()); } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1609,25 +1637,24 @@ static bool makeSphere(TopoDS_Solid &result, double xc, double yc, double zc, double radius, double angle1, double angle2, double angle3) { - if(radius <= 0){ + if(radius <= 0) { Msg::Error("Sphere radius should be positive"); return false; } - if(angle3 <= 0 || angle3 > 2 * M_PI){ + if(angle3 <= 0 || angle3 > 2 * M_PI) { Msg::Error("Cannot build sphere with angle <= 0 or angle > 2*Pi"); return false; } - try{ + try { gp_Pnt p(xc, yc, zc); BRepPrimAPI_MakeSphere s(p, radius, angle1, angle2, angle3); s.Build(); - if(!s.IsDone()){ + if(!s.IsDone()) { Msg::Error("Could not create sphere"); return false; } result = TopoDS::Solid(s.Shape()); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1638,7 +1665,7 @@ bool OCC_Internals::addSphere(int &tag, double xc, double yc, double zc, double radius, double angle1, double angle2, double angle3) { - if(tag >= 0 && _tagSolid.IsBound(tag)){ + if(tag >= 0 && _tagSolid.IsBound(tag)) { Msg::Error("OpenCASCADE volume with tag %d already exists", tag); return false; } @@ -1653,68 +1680,66 @@ bool OCC_Internals::addSphere(int &tag, double xc, double yc, double zc, static bool makeBox(TopoDS_Solid &result, double x, double y, double z, double dx, double dy, double dz) { - if(!dx || !dy || !dz){ + if(!dx || !dy || !dz) { Msg::Error("Degenerate box"); return false; } - try{ + try { gp_Pnt P1(x, y, z); gp_Pnt P2(x + dx, y + dy, z + dz); BRepPrimAPI_MakeBox b(P1, P2); b.Build(); - if(!b.IsDone()){ + if(!b.IsDone()) { Msg::Error("Could not create box"); return false; } result = TopoDS::Solid(b.Shape()); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } return true; } -bool OCC_Internals::addBox(int &tag, double x, double y, double z, - double dx, double dy, double dz) +bool OCC_Internals::addBox(int &tag, double x, double y, double z, double dx, + double dy, double dz) { - if(tag >= 0 && _tagSolid.IsBound(tag)){ + if(tag >= 0 && _tagSolid.IsBound(tag)) { Msg::Error("OpenCASCADE volume with tag %d already exists", tag); return false; } TopoDS_Solid result; - if(!makeBox(result, x, y, z, dx, dy, dz)) - return false; + if(!makeBox(result, x, y, z, dx, dy, dz)) return false; if(tag < 0) tag = getMaxTag(3) + 1; bind(result, tag, true); return true; } static bool makeCylinder(TopoDS_Solid &result, double x, double y, double z, - double dx, double dy, double dz, double r, double angle) + double dx, double dy, double dz, double r, + double angle) { const double H = sqrt(dx * dx + dy * dy + dz * dz); - if(!H){ + if(!H) { Msg::Error("Cannot build cylinder of zero height"); return false; } - if(angle <= 0 || angle > 2 * M_PI){ + if(angle <= 0 || angle > 2 * M_PI) { Msg::Error("Cannot build cylinder with angle <= 0 or angle > 2*Pi"); return false; } - try{ + try { gp_Pnt aP(x, y, z); gp_Vec aV(dx / H, dy / H, dz / H); gp_Ax2 anAxes(aP, aV); BRepPrimAPI_MakeCylinder c(anAxes, r, H, angle); c.Build(); - if(!c.IsDone()){ + if(!c.IsDone()) { Msg::Error("Could not create cylinder"); return false; } result = TopoDS::Solid(c.Shape()); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1725,13 +1750,12 @@ bool OCC_Internals::addCylinder(int &tag, double x, double y, double z, double dx, double dy, double dz, double r, double angle) { - if(tag >= 0 && _tagSolid.IsBound(tag)){ + if(tag >= 0 && _tagSolid.IsBound(tag)) { Msg::Error("OpenCASCADE volume with tag %d already exists", tag); return false; } TopoDS_Solid result; - if(!makeCylinder(result, x, y, z, dx, dy, dz, r, angle)) - return false; + if(!makeCylinder(result, x, y, z, dx, dy, dz, r, angle)) return false; if(tag < 0) tag = getMaxTag(3) + 1; bind(result, tag, true); return true; @@ -1740,39 +1764,37 @@ bool OCC_Internals::addCylinder(int &tag, double x, double y, double z, static bool makeTorus(TopoDS_Solid &result, double x, double y, double z, double r1, double r2, double angle) { - if(r1 <= 0 || r2 <= 0){ + if(r1 <= 0 || r2 <= 0) { Msg::Error("Torus radii should be positive"); return false; } - try{ + try { gp_Pnt aP(x, y, z); gp_Vec aV(0, 0, 1); gp_Ax2 anAxes(aP, aV); BRepPrimAPI_MakeTorus t(anAxes, r1, r2, angle); t.Build(); - if (!t.IsDone()) { + if(!t.IsDone()) { Msg::Error("Could not create torus"); return false; } result = TopoDS::Solid(t.Shape()); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } return true; } -bool OCC_Internals::addTorus(int &tag, double x, double y, double z, - double r1, double r2, double angle) +bool OCC_Internals::addTorus(int &tag, double x, double y, double z, double r1, + double r2, double angle) { - if(tag >= 0 && _tagSolid.IsBound(tag)){ + if(tag >= 0 && _tagSolid.IsBound(tag)) { Msg::Error("OpenCASCADE volume with tag %d already exists", tag); return false; } TopoDS_Solid result; - if(!makeTorus(result, x, y, z, r1, r2, angle)) - return false; + if(!makeTorus(result, x, y, z, r1, r2, angle)) return false; if(tag < 0) tag = getMaxTag(3) + 1; bind(result, tag, true); return true; @@ -1783,44 +1805,42 @@ static bool makeCone(TopoDS_Solid &result, double x, double y, double z, double angle) { const double H = sqrt(dx * dx + dy * dy + dz * dz); - if(!H){ + if(!H) { Msg::Error("Cannot build cone of zero height"); return false; } - if(angle <= 0){ + if(angle <= 0) { Msg::Error("Cone angle should be positive"); return false; } - try{ + try { gp_Pnt aP(x, y, z); gp_Vec aV(dx / H, dy / H, dz / H); gp_Ax2 anAxes(aP, aV); BRepPrimAPI_MakeCone c(anAxes, r1, r2, H, angle); c.Build(); - if(!c.IsDone()){ + if(!c.IsDone()) { Msg::Error("Could not create cone"); return false; } result = TopoDS::Solid(c.Shape()); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } return true; } -bool OCC_Internals::addCone(int &tag, double x, double y, double z, - double dx, double dy, double dz, double r1, - double r2, double angle) +bool OCC_Internals::addCone(int &tag, double x, double y, double z, double dx, + double dy, double dz, double r1, double r2, + double angle) { - if(tag >= 0 && _tagSolid.IsBound(tag)){ + if(tag >= 0 && _tagSolid.IsBound(tag)) { Msg::Error("OpenCASCADE volume with tag %d already exists", tag); return false; } TopoDS_Solid result; - if(!makeCone(result, x, y, z, dx, dy, dz, r1, r2, angle)) - return false; + if(!makeCone(result, x, y, z, dx, dy, dz, r1, r2, angle)) return false; if(tag < 0) tag = getMaxTag(3) + 1; bind(result, tag, true); return true; @@ -1829,64 +1849,63 @@ bool OCC_Internals::addCone(int &tag, double x, double y, double z, static bool makeWedge(TopoDS_Solid &result, double x, double y, double z, double dx, double dy, double dz, double ltx) { - try{ + try { gp_Pnt aP(x, y, z); gp_Vec aV(0, 0, 1); gp_Ax2 anAxes(aP, aV); BRepPrimAPI_MakeWedge w(anAxes, dx, dy, dz, ltx); w.Build(); - if(!w.IsDone()){ + if(!w.IsDone()) { Msg::Error("Could not create wedge"); return false; } result = TopoDS::Solid(w.Shape()); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } return true; } -bool OCC_Internals::addWedge(int &tag, double x, double y, double z, - double dx, double dy, double dz, double ltx) +bool OCC_Internals::addWedge(int &tag, double x, double y, double z, double dx, + double dy, double dz, double ltx) { - if(tag >= 0 && _tagSolid.IsBound(tag)){ + if(tag >= 0 && _tagSolid.IsBound(tag)) { Msg::Error("OpenCASCADE volume with tag %d already exists", tag); return false; } TopoDS_Solid result; - if(!makeWedge(result, x, y, z, dx, dy, dz, ltx)) - return false; + if(!makeWedge(result, x, y, z, dx, dy, dz, ltx)) return false; if(tag < 0) tag = getMaxTag(3) + 1; bind(result, tag, true); return true; } -bool OCC_Internals::addThruSections(int tag, const std::vector<int> &wireTags, - bool makeSolid, bool makeRuled, - std::vector<std::pair<int, int> > &outDimTags) +bool OCC_Internals::addThruSections( + int tag, const std::vector<int> &wireTags, bool makeSolid, bool makeRuled, + std::vector<std::pair<int, int> > &outDimTags) { int dim = makeSolid ? 3 : 2; - if(tag >= 0 && _isBound(dim, tag)){ + if(tag >= 0 && _isBound(dim, tag)) { Msg::Error("OpenCASCADE entity of dimension %d with tag %d already exists", dim, tag); return false; } - if(wireTags.size() < 2){ + if(wireTags.size() < 2) { Msg::Error("ThruSections require at least 2 wires"); return false; } TopoDS_Shape result; - try{ + try { BRepOffsetAPI_ThruSections ts(makeSolid, makeRuled); - for (unsigned int i = 0; i < wireTags.size(); i++) { - if(!_tagWire.IsBound(wireTags[i])){ - Msg::Error("Unknown OpenCASCADE wire or line loop with tag %d", wireTags[i]); + for(unsigned int i = 0; i < wireTags.size(); i++) { + if(!_tagWire.IsBound(wireTags[i])) { + Msg::Error("Unknown OpenCASCADE wire or line loop with tag %d", + wireTags[i]); return false; } TopoDS_Wire wire = TopoDS::Wire(_tagWire.Find(wireTags[i])); - if(makeSolid && !wire.Closed()){ + if(makeSolid && !wire.Closed()) { Msg::Error("Making solid requires closed wires"); return false; } @@ -1894,13 +1913,12 @@ bool OCC_Internals::addThruSections(int tag, const std::vector<int> &wireTags, } ts.CheckCompatibility(Standard_False); ts.Build(); - if(!ts.IsDone()){ + if(!ts.IsDone()) { Msg::Error("Could not create ThruSection"); return false; } result = ts.Shape(); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1913,21 +1931,22 @@ bool OCC_Internals::addThickSolid(int tag, int solidTag, double offset, std::vector<std::pair<int, int> > &outDimTags) { - if(tag >= 0 && _isBound(3, tag)){ + if(tag >= 0 && _isBound(3, tag)) { Msg::Error("OpenCASCADE volume with tag %d already exists", tag); return false; } - if(!_isBound(3, solidTag)){ + if(!_isBound(3, solidTag)) { Msg::Error("Unknown OpenCASCADE volume with tag %d", solidTag); return false; } TopoDS_Shape result; - try{ + try { TopoDS_Shape shape = _find(3, solidTag); TopTools_ListOfShape exclude; - for(unsigned int i = 0; i < excludeFaceTags.size(); i++){ - if(!_tagFace.IsBound(excludeFaceTags[i])){ - Msg::Error("Unknown OpenCASCADE surface with tag %d", excludeFaceTags[i]); + for(unsigned int i = 0; i < excludeFaceTags.size(); i++) { + if(!_tagFace.IsBound(excludeFaceTags[i])) { + Msg::Error("Unknown OpenCASCADE surface with tag %d", + excludeFaceTags[i]); return false; } exclude.Append(_tagFace.Find(excludeFaceTags[i])); @@ -1935,13 +1954,12 @@ bool OCC_Internals::addThickSolid(int tag, int solidTag, BRepOffsetAPI_MakeThickSolid ts(shape, exclude, offset, CTX::instance()->geom.tolerance); ts.Build(); - if(!ts.IsDone()){ + if(!ts.IsDone()) { Msg::Error("Could not build thick solid"); return false; } result = ts.Shape(); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -1949,18 +1967,14 @@ bool OCC_Internals::addThickSolid(int tag, int solidTag, return true; } -void OCC_Internals::_setExtrudedMeshAttributes(const TopoDS_Compound &c, - BRepSweep_Prism *p, - BRepSweep_Revol *r, - ExtrudeParams *e, - double x, double y, double z, - double dx, double dy, double dz, - double ax, double ay, double az, - double angle) +void OCC_Internals::_setExtrudedMeshAttributes( + const TopoDS_Compound &c, BRepSweep_Prism *p, BRepSweep_Revol *r, + ExtrudeParams *e, double x, double y, double z, double dx, double dy, + double dz, double ax, double ay, double az, double angle) { if(!p && !r) return; - if(r && angle >= 2 * M_PI){ + if(r && angle >= 2 * M_PI) { // OCC removes the origin edge from e.g. disks, which makes it impossible to // generate the 2D surface mesh by extrusion of the 1D edge mesh Msg::Warning("Extruded meshes by revolution only for angle < 2*Pi"); @@ -1969,18 +1983,18 @@ void OCC_Internals::_setExtrudedMeshAttributes(const TopoDS_Compound &c, TopExp_Explorer exp0; - for(exp0.Init(c, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(c, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); TopoDS_Shape bot = p ? p->FirstShape(face) : r->FirstShape(face); TopoDS_Shape top = p ? p->LastShape(face) : r->LastShape(face); - if(e){ + if(e) { ExtrudeParams *ee = new ExtrudeParams(COPIED_ENTITY); ee->fill(p ? TRANSLATE : ROTATE, dx, dy, dz, ax, ay, az, x, y, z, angle); ee->mesh = e->mesh; _meshAttributes->insert(new OCCMeshAttributes(2, top, ee, 2, bot)); } TopoDS_Shape vol = p ? p->Shape(face) : r->Shape(face); - if(e){ + if(e) { ExtrudeParams *ee = new ExtrudeParams(EXTRUDED_ENTITY); ee->fill(p ? TRANSLATE : ROTATE, dx, dy, dz, ax, ay, az, x, y, z, angle); ee->mesh = e->mesh; @@ -1988,18 +2002,18 @@ void OCC_Internals::_setExtrudedMeshAttributes(const TopoDS_Compound &c, } } - for(exp0.Init(c, TopAbs_EDGE); exp0.More(); exp0.Next()){ + for(exp0.Init(c, TopAbs_EDGE); exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Current()); TopoDS_Shape bot = p ? p->FirstShape(edge) : r->FirstShape(edge); TopoDS_Shape top = p ? p->LastShape(edge) : r->LastShape(edge); - if(e){ + if(e) { ExtrudeParams *ee = new ExtrudeParams(COPIED_ENTITY); ee->fill(p ? TRANSLATE : ROTATE, dx, dy, dz, ax, ay, az, x, y, z, angle); ee->mesh = e->mesh; _meshAttributes->insert(new OCCMeshAttributes(1, top, ee, 1, bot)); } TopoDS_Shape sur = p ? p->Shape(edge) : r->Shape(edge); - if(e){ + if(e) { ExtrudeParams *ee = new ExtrudeParams(EXTRUDED_ENTITY); ee->fill(p ? TRANSLATE : ROTATE, dx, dy, dz, ax, ay, az, x, y, z, angle); ee->mesh = e->mesh; @@ -2007,12 +2021,12 @@ void OCC_Internals::_setExtrudedMeshAttributes(const TopoDS_Compound &c, } } - for(exp0.Init(c, TopAbs_VERTEX); exp0.More(); exp0.Next()){ + for(exp0.Init(c, TopAbs_VERTEX); exp0.More(); exp0.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp0.Current()); TopoDS_Shape bot = p ? p->FirstShape(vertex) : r->FirstShape(vertex); TopoDS_Shape top = p ? p->LastShape(vertex) : r->LastShape(vertex); TopoDS_Shape lin = p ? p->Shape(vertex) : r->Shape(vertex); - if(e){ + if(e) { ExtrudeParams *ee = new ExtrudeParams(EXTRUDED_ENTITY); ee->fill(p ? TRANSLATE : ROTATE, dx, dy, dz, ax, ay, az, x, y, z, angle); ee->mesh = e->mesh; @@ -2028,22 +2042,22 @@ void OCC_Internals::_setExtrudedMeshAttributes(const TopoDS_Compound &c, int OCC_Internals::_getFuzzyTag(int dim, const TopoDS_Shape &s) { - if(_isBound(dim, s)) - return _find(dim, s); + if(_isBound(dim, s)) return _find(dim, s); std::vector<TopoDS_Shape> candidates; _meshAttributes->getSimilarShapes(dim, s, candidates); int num = 0; - for(unsigned int i = 0; i < candidates.size(); i++){ - if(_isBound(dim, candidates[i])){ + for(unsigned int i = 0; i < candidates.size(); i++) { + if(_isBound(dim, candidates[i])) { num++; } } - Msg::Info("Extruded mesh constraint fuzzy search: found %d candidates (dim=%d, %d bound)", + Msg::Info("Extruded mesh constraint fuzzy search: found %d candidates " + "(dim=%d, %d bound)", (int)candidates.size(), dim, num); - for(unsigned int i = 0; i < candidates.size(); i++){ - if(_isBound(dim, candidates[i])){ + for(unsigned int i = 0; i < candidates.size(); i++) { + if(_isBound(dim, candidates[i])) { return _find(dim, candidates[i]); } } @@ -2054,16 +2068,17 @@ void OCC_Internals::_copyExtrudedMeshAttributes(TopoDS_Edge edge, GEdge *ge) { int sourceDim = -1; TopoDS_Shape sourceShape; - ExtrudeParams *e = _meshAttributes->getExtrudeParams(1, edge, - sourceDim, sourceShape); + ExtrudeParams *e = + _meshAttributes->getExtrudeParams(1, edge, sourceDim, sourceShape); if(!e) return; ge->meshAttributes.extrude = e; - if(ge->meshAttributes.extrude->geo.Mode == EXTRUDED_ENTITY){ + if(ge->meshAttributes.extrude->geo.Mode == EXTRUDED_ENTITY) { ge->meshAttributes.extrude->geo.Source = _getFuzzyTag(0, sourceShape); } - else if(ge->meshAttributes.extrude->geo.Mode == COPIED_ENTITY){ + else if(ge->meshAttributes.extrude->geo.Mode == COPIED_ENTITY) { ge->meshAttributes.extrude->geo.Source = _getFuzzyTag(1, sourceShape); - if(ge->meshAttributes.extrude->geo.Source == ge->tag()) // degenerate extrusion + if(ge->meshAttributes.extrude->geo.Source == + ge->tag()) // degenerate extrusion ge->meshAttributes.extrude = 0; } } @@ -2072,16 +2087,17 @@ void OCC_Internals::_copyExtrudedMeshAttributes(TopoDS_Face face, GFace *gf) { int sourceDim = -1; TopoDS_Shape sourceShape; - ExtrudeParams *e = _meshAttributes->getExtrudeParams(2, face, - sourceDim, sourceShape); + ExtrudeParams *e = + _meshAttributes->getExtrudeParams(2, face, sourceDim, sourceShape); if(!e) return; gf->meshAttributes.extrude = e; - if(gf->meshAttributes.extrude->geo.Mode == EXTRUDED_ENTITY){ + if(gf->meshAttributes.extrude->geo.Mode == EXTRUDED_ENTITY) { gf->meshAttributes.extrude->geo.Source = _getFuzzyTag(1, sourceShape); } - else if(gf->meshAttributes.extrude->geo.Mode == COPIED_ENTITY){ + else if(gf->meshAttributes.extrude->geo.Mode == COPIED_ENTITY) { gf->meshAttributes.extrude->geo.Source = _getFuzzyTag(2, sourceShape); - if(gf->meshAttributes.extrude->geo.Source == gf->tag()) // degenerate extrusion + if(gf->meshAttributes.extrude->geo.Source == + gf->tag()) // degenerate extrusion gf->meshAttributes.extrude = 0; } } @@ -2090,45 +2106,45 @@ void OCC_Internals::_copyExtrudedMeshAttributes(TopoDS_Solid solid, GRegion *gr) { int sourceDim = -1; TopoDS_Shape sourceShape; - ExtrudeParams *e = _meshAttributes->getExtrudeParams(3, solid, - sourceDim, sourceShape); + ExtrudeParams *e = + _meshAttributes->getExtrudeParams(3, solid, sourceDim, sourceShape); if(!e) return; gr->meshAttributes.extrude = e; - if(gr->meshAttributes.extrude->geo.Mode == EXTRUDED_ENTITY){ + if(gr->meshAttributes.extrude->geo.Mode == EXTRUDED_ENTITY) { gr->meshAttributes.extrude->geo.Source = _getFuzzyTag(2, sourceShape); } } -template<class T> +template <class T> static int getReturnedShapes(const TopoDS_Compound &c, T *sweep, std::vector<TopoDS_Shape> &top, std::vector<TopoDS_Shape> &body, std::vector<std::vector<TopoDS_Shape> > &lateral) { TopExp_Explorer exp0, exp1; - for(exp0.Init(c, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(c, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); top.push_back(sweep->LastShape(face)); body.push_back(sweep->Shape(face)); lateral.push_back(std::vector<TopoDS_Shape>()); - for(exp1.Init(face, TopAbs_EDGE); exp1.More(); exp1.Next()){ + for(exp1.Init(face, TopAbs_EDGE); exp1.More(); exp1.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); lateral.back().push_back(sweep->Shape(edge)); } } if(top.size()) return 3; - for(exp0.Init(c, TopAbs_EDGE); exp0.More(); exp0.Next()){ + for(exp0.Init(c, TopAbs_EDGE); exp0.More(); exp0.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp0.Current()); top.push_back(sweep->LastShape(edge)); body.push_back(sweep->Shape(edge)); lateral.push_back(std::vector<TopoDS_Shape>()); - for(exp1.Init(edge, TopAbs_VERTEX); exp1.More(); exp1.Next()){ + for(exp1.Init(edge, TopAbs_VERTEX); exp1.More(); exp1.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp1.Current()); lateral.back().push_back(sweep->Shape(vertex)); } } if(top.size()) return 2; - for(exp0.Init(c, TopAbs_VERTEX); exp0.More(); exp0.Next()){ + for(exp0.Init(c, TopAbs_VERTEX); exp0.More(); exp0.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp0.Current()); top.push_back(sweep->LastShape(vertex)); body.push_back(sweep->Shape(vertex)); @@ -2139,10 +2155,9 @@ static int getReturnedShapes(const TopoDS_Compound &c, T *sweep, bool OCC_Internals::_extrude(int mode, const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double dx, double dy, double dz, - double ax, double ay, double az, double angle, - int wireTag, + double x, double y, double z, double dx, double dy, + double dz, double ax, double ay, double az, + double angle, int wireTag, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e) { @@ -2151,11 +2166,12 @@ bool OCC_Internals::_extrude(int mode, BRep_Builder b; TopoDS_Compound c; b.MakeCompound(c); - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { int dim = inDimTags[i].first; int tag = inDimTags[i].second; - if(!_isBound(dim, tag)){ - Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, tag); + if(!_isBound(dim, tag)) { + Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, + tag); return false; } TopoDS_Shape shape = _find(dim, tag); @@ -2165,36 +2181,36 @@ bool OCC_Internals::_extrude(int mode, std::vector<TopoDS_Shape> top, body; std::vector<std::vector<TopoDS_Shape> > lateral; int dim = -1; - try{ - if(mode == 0){ // extrude + try { + if(mode == 0) { // extrude BRepPrimAPI_MakePrism p(c, gp_Vec(dx, dy, dz), Standard_False); p.Build(); - if(!p.IsDone()){ + if(!p.IsDone()) { Msg::Error("Could not extrude"); return false; } result = p.Shape(); const BRepSweep_Prism &prism(p.Prism()); - _setExtrudedMeshAttributes(c, (BRepSweep_Prism*)&prism, 0, e, - 0., 0., 0., dx, dy, dz, 0., 0., 0., 0.); - dim = getReturnedShapes(c, (BRepSweep_Prism*)&prism, top, body, lateral); + _setExtrudedMeshAttributes(c, (BRepSweep_Prism *)&prism, 0, e, 0., 0., 0., + dx, dy, dz, 0., 0., 0., 0.); + dim = getReturnedShapes(c, (BRepSweep_Prism *)&prism, top, body, lateral); } - else if(mode == 1){ // revolve + else if(mode == 1) { // revolve gp_Ax1 axisOfRevolution(gp_Pnt(x, y, z), gp_Dir(ax, ay, az)); BRepPrimAPI_MakeRevol r(c, axisOfRevolution, angle, Standard_False); r.Build(); - if(!r.IsDone()){ + if(!r.IsDone()) { Msg::Error("Could not revolve"); return false; } result = r.Shape(); const BRepSweep_Revol &revol(r.Revol()); - _setExtrudedMeshAttributes(c, 0, (BRepSweep_Revol*)&revol, e, - x, y, z, 0., 0., 0., ax, ay, az, angle); - dim = getReturnedShapes(c, (BRepSweep_Revol*)&revol, top, body, lateral); + _setExtrudedMeshAttributes(c, 0, (BRepSweep_Revol *)&revol, e, x, y, z, + 0., 0., 0., ax, ay, az, angle); + dim = getReturnedShapes(c, (BRepSweep_Revol *)&revol, top, body, lateral); } - else if(mode == 2){ // pipe - if(!_tagWire.IsBound(wireTag)){ + else if(mode == 2) { // pipe + if(!_tagWire.IsBound(wireTag)) { Msg::Error("Unknown OpenCASCADE wire with tag %d", wireTag); return false; } @@ -2209,19 +2225,19 @@ bool OCC_Internals::_extrude(int mode, // very simple cases with straight extrusions. We might want to make this // an option. p.Build(); - if(!p.IsDone()){ + if(!p.IsDone()) { Msg::Error("Could not create pipe"); return false; } result = p.Shape(); - //const BRepFill_Pipe &pipe(p.Pipe()); + // const BRepFill_Pipe &pipe(p.Pipe()); if(e) - Msg::Warning("Structured meshes not yet available with OpenCASCADE pipe"); + Msg::Warning( + "Structured meshes not yet available with OpenCASCADE pipe"); // TODO - need to pass the profile, too - //dim = getReturnedShapes(c, (BRepFill_Pipe*)&pipe, top, body, lateral); + // dim = getReturnedShapes(c, (BRepFill_Pipe*)&pipe, top, body, lateral); } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -2229,20 +2245,21 @@ bool OCC_Internals::_extrude(int mode, _multiBind(result, -1, outDimTags, true, true); // return entities in the same order as the built-in kernel extrusion - if(dim >= 1 && dim <= 3 && - top.size() == inDimTags.size() && top.size() == body.size()){ + if(dim >= 1 && dim <= 3 && top.size() == inDimTags.size() && + top.size() == body.size()) { outDimTags.clear(); - for(unsigned int i = 0; i < top.size(); i++){ + for(unsigned int i = 0; i < top.size(); i++) { if(_isBound(dim - 1, top[i])) - outDimTags.push_back(std::pair<int, int>(dim - 1, _find(dim - 1, top[i]))); + outDimTags.push_back( + std::pair<int, int>(dim - 1, _find(dim - 1, top[i]))); if(_isBound(dim, body[i])) outDimTags.push_back(std::pair<int, int>(dim, _find(dim, body[i]))); if(CTX::instance()->geom.extrudeReturnLateral && - top.size() == lateral.size()){ - for(unsigned int j = 0; j < lateral[i].size(); j++){ + top.size() == lateral.size()) { + for(unsigned int j = 0; j < lateral[i].size(); j++) { if(_isBound(dim - 1, lateral[i][j])) - outDimTags.push_back - (std::pair<int, int>(dim - 1, _find(dim - 1, lateral[i][j]))); + outDimTags.push_back( + std::pair<int, int>(dim - 1, _find(dim - 1, lateral[i][j]))); } } } @@ -2260,8 +2277,8 @@ bool OCC_Internals::extrude(const std::vector<std::pair<int, int> > &inDimTags, } bool OCC_Internals::revolve(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double ax, double ay, double az, double angle, + double x, double y, double z, double ax, double ay, + double az, double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e) { @@ -2270,7 +2287,8 @@ bool OCC_Internals::revolve(const std::vector<std::pair<int, int> > &inDimTags, } bool OCC_Internals::addPipe(const std::vector<std::pair<int, int> > &inDimTags, - int wireTag, std::vector<std::pair<int, int> > &outDimTags) + int wireTag, + std::vector<std::pair<int, int> > &outDimTags) { return _extrude(2, inDimTags, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., wireTag, outDimTags); @@ -2284,8 +2302,8 @@ bool OCC_Internals::_fillet(int mode, const std::vector<int> &volumeTags, bool removeVolume) { std::vector<TopoDS_Edge> edges; - for(unsigned int i = 0; i < curveTags.size(); i++){ - if(!_tagEdge.IsBound(curveTags[i])){ + for(unsigned int i = 0; i < curveTags.size(); i++) { + if(!_tagEdge.IsBound(curveTags[i])) { Msg::Error("Unknown OpenCASCADE curve with tag %d", curveTags[i]); return false; } @@ -2293,14 +2311,14 @@ bool OCC_Internals::_fillet(int mode, const std::vector<int> &volumeTags, } std::vector<TopoDS_Face> faces; - for(unsigned int i = 0; i < surfaceTags.size(); i++){ - if(!_tagFace.IsBound(surfaceTags[i])){ + for(unsigned int i = 0; i < surfaceTags.size(); i++) { + if(!_tagFace.IsBound(surfaceTags[i])) { Msg::Error("Unknown OpenCASCADE surface with tag %d", surfaceTags[i]); return false; } faces.push_back(TopoDS::Face(_tagFace.Find(surfaceTags[i]))); } - if(mode && edges.size() != faces.size()){ + if(mode && edges.size() != faces.size()) { Msg::Error("Different number of curves and surfaces for chamfer"); return false; } @@ -2309,14 +2327,14 @@ bool OCC_Internals::_fillet(int mode, const std::vector<int> &volumeTags, BRep_Builder b; TopoDS_Compound c; b.MakeCompound(c); - for(unsigned int i = 0; i < volumeTags.size(); i++){ - if(!_isBound(3, volumeTags[i])){ + for(unsigned int i = 0; i < volumeTags.size(); i++) { + if(!_isBound(3, volumeTags[i])) { Msg::Error("Unknown OpenCASCADE volume with tag %d", volumeTags[i]); return false; } TopoDS_Shape shape = _find(3, volumeTags[i]); if(removeVolume) unbind(shape, 3, volumeTags[i], true); - if(CTX::instance()->geom.occAutoFix){ + if(CTX::instance()->geom.occAutoFix) { // make sure the volume is finite ShapeFix_Solid fix(TopoDS::Solid(shape)); fix.Perform(); @@ -2325,10 +2343,10 @@ bool OCC_Internals::_fillet(int mode, const std::vector<int> &volumeTags, b.Add(c, shape); } TopoDS_Shape result; - try{ - if(mode == 0){ // fillet + try { + if(mode == 0) { // fillet BRepFilletAPI_MakeFillet f(c); - for(unsigned int i = 0; i < edges.size(); i++){ + for(unsigned int i = 0; i < edges.size(); i++) { if(param.size() == 1) f.Add(param[0], edges[i]); else if(param.size() == edges.size()) @@ -2343,9 +2361,9 @@ bool OCC_Internals::_fillet(int mode, const std::vector<int> &volumeTags, } result = f.Shape(); } - else{ // chamfer + else { // chamfer BRepFilletAPI_MakeChamfer f(c); - for(unsigned int i = 0; i < edges.size(); i++){ + for(unsigned int i = 0; i < edges.size(); i++) { if(param.size() == 1) f.Add(param[0], param[0], edges[i], faces[i]); else if(param.size() == edges.size()) @@ -2360,13 +2378,12 @@ bool OCC_Internals::_fillet(int mode, const std::vector<int> &volumeTags, } result = f.Shape(); } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } - if(result.IsNull()){ + if(result.IsNull()) { Msg::Error("%s produces empty shape", mode ? "Chamfer" : "Fillet"); return false; } @@ -2374,7 +2391,6 @@ bool OCC_Internals::_fillet(int mode, const std::vector<int> &volumeTags, return true; } - bool OCC_Internals::fillet(const std::vector<int> &volumeTags, const std::vector<int> &curveTags, const std::vector<double> &radii, @@ -2382,7 +2398,8 @@ bool OCC_Internals::fillet(const std::vector<int> &volumeTags, bool removeVolume) { std::vector<int> dummy; - return _fillet(0, volumeTags, curveTags, dummy, radii, outDimTags, removeVolume); + return _fillet(0, volumeTags, curveTags, dummy, radii, outDimTags, + removeVolume); } bool OCC_Internals::chamfer(const std::vector<int> &volumeTags, @@ -2392,25 +2409,27 @@ bool OCC_Internals::chamfer(const std::vector<int> &volumeTags, std::vector<std::pair<int, int> > &outDimTags, bool removeVolume) { - return _fillet(1, volumeTags, curveTags, surfaceTags, distances, outDimTags, removeVolume); + return _fillet(1, volumeTags, curveTags, surfaceTags, distances, outDimTags, + removeVolume); } -static void _filterTags(std::vector<std::pair<int, int> > &outDimTags, int minDim) +static void _filterTags(std::vector<std::pair<int, int> > &outDimTags, + int minDim) { std::vector<std::pair<int, int> > tmp(outDimTags); outDimTags.clear(); - for(unsigned int i = 0; i < tmp.size(); i++){ - if(tmp[i].first >= minDim) - outDimTags.push_back(tmp[i]); + for(unsigned int i = 0; i < tmp.size(); i++) { + if(tmp[i].first >= minDim) outDimTags.push_back(tmp[i]); } } -bool OCC_Internals::booleanOperator(int tag, BooleanOperator op, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) +bool OCC_Internals::booleanOperator( + int tag, BooleanOperator op, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { double tolerance = CTX::instance()->geom.toleranceBoolean; bool parallel = CTX::instance()->geom.occParallel; @@ -2418,34 +2437,36 @@ bool OCC_Internals::booleanOperator(int tag, BooleanOperator op, if(objectDimTags.empty()) return true; - if(tag >= 0 && _isBound(objectDimTags[0].first, tag)){ + if(tag >= 0 && _isBound(objectDimTags[0].first, tag)) { Msg::Error("OpenCASCADE entity with tag %d already exists", tag); return false; } int minDim = 3; TopTools_ListOfShape objectShapes, toolShapes; - for(unsigned int i = 0; i < objectDimTags.size(); i++){ + for(unsigned int i = 0; i < objectDimTags.size(); i++) { int dim = objectDimTags[i].first; int t = objectDimTags[i].second; - if(!_isBound(dim, t)){ - Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, t); + if(!_isBound(dim, t)) { + Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, + t); return false; } - else{ + else { TopoDS_Shape object = _find(dim, t); objectShapes.Append(object); } minDim = std::min(minDim, dim); } - for(unsigned int i = 0; i < toolDimTags.size(); i++){ + for(unsigned int i = 0; i < toolDimTags.size(); i++) { int dim = toolDimTags[i].first; int t = toolDimTags[i].second; - if(!_isBound(dim, t)){ - Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, t); + if(!_isBound(dim, t)) { + Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, + t); return false; } - else{ + else { TopoDS_Shape tool = _find(dim, t); toolShapes.Append(tool); } @@ -2456,128 +2477,115 @@ bool OCC_Internals::booleanOperator(int tag, BooleanOperator op, std::vector<TopoDS_Shape> mapOriginal; std::vector<TopTools_ListOfShape> mapModified, mapGenerated; std::vector<bool> mapDeleted; - try{ - switch(op){ - case OCC_Internals::Union : - { - BRepAlgoAPI_Fuse fuse; - fuse.SetRunParallel(parallel); - fuse.SetArguments(objectShapes); - fuse.SetTools(toolShapes); - if(tolerance > 0.0) - fuse.SetFuzzyValue(tolerance); - fuse.Build(); - if(!fuse.IsDone()){ - Msg::Error("Fuse operation cannot be performed"); - return false; - } - result = fuse.Shape(); - TopTools_ListIteratorOfListOfShape it(objectShapes); - for(; it.More(); it.Next()){ - mapOriginal.push_back(it.Value()); - mapModified.push_back(fuse.Modified(it.Value())); - mapDeleted.push_back(fuse.IsDeleted(it.Value())); - mapGenerated.push_back(fuse.Generated(it.Value())); - } - TopTools_ListIteratorOfListOfShape it2(toolShapes); - for(; it2.More(); it2.Next()){ - mapOriginal.push_back(it2.Value()); - mapModified.push_back(fuse.Modified(it2.Value())); - mapDeleted.push_back(fuse.IsDeleted(it2.Value())); - mapGenerated.push_back(fuse.Generated(it2.Value())); - } + try { + switch(op) { + case OCC_Internals::Union: { + BRepAlgoAPI_Fuse fuse; + fuse.SetRunParallel(parallel); + fuse.SetArguments(objectShapes); + fuse.SetTools(toolShapes); + if(tolerance > 0.0) fuse.SetFuzzyValue(tolerance); + fuse.Build(); + if(!fuse.IsDone()) { + Msg::Error("Fuse operation cannot be performed"); + return false; } - break; - case OCC_Internals::Intersection : - { - BRepAlgoAPI_Common common; - common.SetRunParallel(parallel); - common.SetArguments(objectShapes); - common.SetTools(toolShapes); - if(tolerance > 0.0) - common.SetFuzzyValue(tolerance); - common.Build(); - if(!common.IsDone()){ - Msg::Error("Intersection operation cannot be performed"); - return false; - } - result = common.Shape(); - TopTools_ListIteratorOfListOfShape it(objectShapes); - for(; it.More(); it.Next()){ - mapOriginal.push_back(it.Value()); - mapModified.push_back(common.Modified(it.Value())); - mapDeleted.push_back(common.IsDeleted(it.Value())); - mapGenerated.push_back(common.Generated(it.Value())); - } - TopTools_ListIteratorOfListOfShape it2(toolShapes); - for(; it2.More(); it2.Next()){ - mapOriginal.push_back(it2.Value()); - mapModified.push_back(common.Modified(it2.Value())); - mapDeleted.push_back(common.IsDeleted(it2.Value())); - mapGenerated.push_back(common.Generated(it2.Value())); - } + result = fuse.Shape(); + TopTools_ListIteratorOfListOfShape it(objectShapes); + for(; it.More(); it.Next()) { + mapOriginal.push_back(it.Value()); + mapModified.push_back(fuse.Modified(it.Value())); + mapDeleted.push_back(fuse.IsDeleted(it.Value())); + mapGenerated.push_back(fuse.Generated(it.Value())); } - break; - - case OCC_Internals::Difference : - { - BRepAlgoAPI_Cut cut; - cut.SetRunParallel(parallel); - cut.SetArguments(objectShapes); - cut.SetTools(toolShapes); - if(tolerance > 0.0) - cut.SetFuzzyValue(tolerance); - cut.Build(); - if(!cut.IsDone()){ - Msg::Error("Intersection operation cannot be performed"); - return false; - } - result = cut.Shape(); - TopTools_ListIteratorOfListOfShape it(objectShapes); - for(; it.More(); it.Next()){ - mapOriginal.push_back(it.Value()); - mapModified.push_back(cut.Modified(it.Value())); - mapDeleted.push_back(cut.IsDeleted(it.Value())); - mapGenerated.push_back(cut.Generated(it.Value())); - } - TopTools_ListIteratorOfListOfShape it2(toolShapes); - for(; it2.More(); it2.Next()){ - mapOriginal.push_back(it2.Value()); - mapModified.push_back(cut.Modified(it2.Value())); - mapDeleted.push_back(cut.IsDeleted(it2.Value())); - mapGenerated.push_back(cut.Generated(it2.Value())); - } + TopTools_ListIteratorOfListOfShape it2(toolShapes); + for(; it2.More(); it2.Next()) { + mapOriginal.push_back(it2.Value()); + mapModified.push_back(fuse.Modified(it2.Value())); + mapDeleted.push_back(fuse.IsDeleted(it2.Value())); + mapGenerated.push_back(fuse.Generated(it2.Value())); } - break; - - case OCC_Internals::Fragments : - default: - { - BRepAlgoAPI_BuilderAlgo fragments; - fragments.SetRunParallel(parallel); - objectShapes.Append(toolShapes); - toolShapes.Clear(); - fragments.SetArguments(objectShapes); - if(tolerance > 0.0) - fragments.SetFuzzyValue(tolerance); - fragments.Build(); - if(!fragments.IsDone()){ - Msg::Error("Boolean fragments failed"); - return false; - } - result = fragments.Shape(); - TopTools_ListIteratorOfListOfShape it(objectShapes); - for(; it.More(); it.Next()){ - mapOriginal.push_back(it.Value()); - mapModified.push_back(fragments.Modified(it.Value())); - mapDeleted.push_back(fragments.IsDeleted(it.Value())); - mapGenerated.push_back(fragments.Generated(it.Value())); - } + } break; + case OCC_Internals::Intersection: { + BRepAlgoAPI_Common common; + common.SetRunParallel(parallel); + common.SetArguments(objectShapes); + common.SetTools(toolShapes); + if(tolerance > 0.0) common.SetFuzzyValue(tolerance); + common.Build(); + if(!common.IsDone()) { + Msg::Error("Intersection operation cannot be performed"); + return false; + } + result = common.Shape(); + TopTools_ListIteratorOfListOfShape it(objectShapes); + for(; it.More(); it.Next()) { + mapOriginal.push_back(it.Value()); + mapModified.push_back(common.Modified(it.Value())); + mapDeleted.push_back(common.IsDeleted(it.Value())); + mapGenerated.push_back(common.Generated(it.Value())); } - break; + TopTools_ListIteratorOfListOfShape it2(toolShapes); + for(; it2.More(); it2.Next()) { + mapOriginal.push_back(it2.Value()); + mapModified.push_back(common.Modified(it2.Value())); + mapDeleted.push_back(common.IsDeleted(it2.Value())); + mapGenerated.push_back(common.Generated(it2.Value())); + } + } break; + + case OCC_Internals::Difference: { + BRepAlgoAPI_Cut cut; + cut.SetRunParallel(parallel); + cut.SetArguments(objectShapes); + cut.SetTools(toolShapes); + if(tolerance > 0.0) cut.SetFuzzyValue(tolerance); + cut.Build(); + if(!cut.IsDone()) { + Msg::Error("Intersection operation cannot be performed"); + return false; + } + result = cut.Shape(); + TopTools_ListIteratorOfListOfShape it(objectShapes); + for(; it.More(); it.Next()) { + mapOriginal.push_back(it.Value()); + mapModified.push_back(cut.Modified(it.Value())); + mapDeleted.push_back(cut.IsDeleted(it.Value())); + mapGenerated.push_back(cut.Generated(it.Value())); + } + TopTools_ListIteratorOfListOfShape it2(toolShapes); + for(; it2.More(); it2.Next()) { + mapOriginal.push_back(it2.Value()); + mapModified.push_back(cut.Modified(it2.Value())); + mapDeleted.push_back(cut.IsDeleted(it2.Value())); + mapGenerated.push_back(cut.Generated(it2.Value())); + } + } break; + + case OCC_Internals::Fragments: + default: { + BRepAlgoAPI_BuilderAlgo fragments; + fragments.SetRunParallel(parallel); + objectShapes.Append(toolShapes); + toolShapes.Clear(); + fragments.SetArguments(objectShapes); + if(tolerance > 0.0) fragments.SetFuzzyValue(tolerance); + fragments.Build(); + if(!fragments.IsDone()) { + Msg::Error("Boolean fragments failed"); + return false; + } + result = fragments.Shape(); + TopTools_ListIteratorOfListOfShape it(objectShapes); + for(; it.More(); it.Next()) { + mapOriginal.push_back(it.Value()); + mapModified.push_back(fragments.Modified(it.Value())); + mapDeleted.push_back(fragments.IsDeleted(it.Value())); + mapGenerated.push_back(fragments.Generated(it.Value())); + } + } break; } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -2587,12 +2595,12 @@ bool OCC_Internals::booleanOperator(int tag, BooleanOperator op, inDimTags.insert(inDimTags.end(), toolDimTags.begin(), toolDimTags.end()); unsigned int numObjects = objectDimTags.size(); - if(tag >= 0 || !preserveNumbering){ + if(tag >= 0 || !preserveNumbering) { // if we specify the tag explicitly, or if we don't care about preserving // the numering, just go ahead and bind the resulting shape (and sub-shapes) - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { bool remove = (i < numObjects) ? removeObject : removeTool; - if(remove){ + if(remove) { int d = inDimTags[i].first; int t = inDimTags[i].second; if(_isBound(d, t)) unbind(_find(d, t), d, t, true); @@ -2601,38 +2609,39 @@ bool OCC_Internals::booleanOperator(int tag, BooleanOperator op, _multiBind(result, tag, outDimTags, true, true); _filterTags(outDimTags, minDim); } - else{ + else { // otherwise, try to preserve the numbering of the input shapes that did not // change, or that were replaced by a single shape. Note that to preserve // the numbering of smaller dimension entities (on boundaries) they should // appear *before* higher dimensional entities in the object/tool lists. _toPreserve.clear(); - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { int dim = inDimTags[i].first; int tag = inDimTags[i].second; bool remove = (i < numObjects) ? removeObject : removeTool; - if(mapDeleted[i]){ // deleted + if(mapDeleted[i]) { // deleted if(remove) unbind(mapOriginal[i], dim, tag, true); Msg::Debug("BOOL (%d,%d) deleted", dim, tag); } - else if(mapModified[i].Extent() == 0){ // not modified + else if(mapModified[i].Extent() == 0) { // not modified outDimTags.push_back(std::pair<int, int>(dim, tag)); _toPreserve.insert(std::pair<int, int>(dim, tag)); Msg::Debug("BOOL (%d,%d) not modified", dim, tag); } - else if(mapModified[i].Extent() == 1){ // replaced by single one - if(remove){ + else if(mapModified[i].Extent() == 1) { // replaced by single one + if(remove) { unbind(mapOriginal[i], dim, tag, true); bind(mapModified[i].First(), dim, tag, false); // not recursive! int t = _find(dim, mapModified[i].First()); if(tag != t) - Msg::Info("Could not preserve tag of %dD object %d (->%d)", dim, tag, t); + Msg::Info("Could not preserve tag of %dD object %d (->%d)", dim, + tag, t); outDimTags.push_back(std::pair<int, int>(dim, t)); _toPreserve.insert(std::pair<int, int>(dim, t)); } Msg::Debug("BOOL (%d,%d) replaced by 1", dim, tag); } - else{ + else { if(remove) unbind(mapOriginal[i], dim, tag, true); Msg::Debug("BOOL (%d,%d) other", dim, tag); } @@ -2645,27 +2654,27 @@ bool OCC_Internals::booleanOperator(int tag, BooleanOperator op, } // return input/output correspondance maps - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { int dim = inDimTags[i].first; int tag = inDimTags[i].second; std::pair<int, int> dimTag(dim, tag); std::vector<std::pair<int, int> > dimTags; - if(mapDeleted[i]){ // deleted + if(mapDeleted[i]) { // deleted } - else if(mapModified[i].Extent() == 0){ // not modified + else if(mapModified[i].Extent() == 0) { // not modified dimTags.push_back(dimTag); } - else{ + else { TopTools_ListIteratorOfListOfShape it(mapModified[i]); - for(; it.More(); it.Next()){ - if(_isBound(dim, it.Value())){ + for(; it.More(); it.Next()) { + if(_isBound(dim, it.Value())) { int t = _find(dim, it.Value()); dimTags.push_back(std::pair<int, int>(dim, t)); } } TopTools_ListIteratorOfListOfShape it2(mapGenerated[i]); - for(; it2.More(); it2.Next()){ - if(_isBound(dim, it2.Value())){ + for(; it2.More(); it2.Next()) { + if(_isBound(dim, it2.Value())) { int t = _find(dim, it2.Value()); dimTags.push_back(std::pair<int, int>(dim, t)); } @@ -2682,48 +2691,51 @@ bool OCC_Internals::booleanOperator(int tag, BooleanOperator op, return true; } -bool OCC_Internals::booleanUnion(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) +bool OCC_Internals::booleanUnion( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { return booleanOperator(tag, OCC_Internals::Union, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject, removeTool); } -bool OCC_Internals::booleanIntersection(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) +bool OCC_Internals::booleanIntersection( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { - return booleanOperator(tag, OCC_Internals::Intersection, objectDimTags, toolDimTags, - outDimTags, outDimTagsMap, removeObject, removeTool); + return booleanOperator(tag, OCC_Internals::Intersection, objectDimTags, + toolDimTags, outDimTags, outDimTagsMap, removeObject, + removeTool); } -bool OCC_Internals::booleanDifference(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) +bool OCC_Internals::booleanDifference( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { - return booleanOperator(tag, OCC_Internals::Difference, objectDimTags, toolDimTags, - outDimTags, outDimTagsMap, removeObject, removeTool); + return booleanOperator(tag, OCC_Internals::Difference, objectDimTags, + toolDimTags, outDimTags, outDimTagsMap, removeObject, + removeTool); } -bool OCC_Internals::booleanFragments(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) +bool OCC_Internals::booleanFragments( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { - return booleanOperator(tag, OCC_Internals::Fragments, objectDimTags, toolDimTags, - outDimTags, outDimTagsMap, removeObject, removeTool); + return booleanOperator(tag, OCC_Internals::Fragments, objectDimTags, + toolDimTags, outDimTags, outDimTagsMap, removeObject, + removeTool); } int OCC_Internals::_getMaxDim() @@ -2734,12 +2746,13 @@ int OCC_Internals::_getMaxDim() return 0; } -void OCC_Internals::_getAllDimTags(std::vector<std::pair<int, int> > &dimTags, int dim) +void OCC_Internals::_getAllDimTags(std::vector<std::pair<int, int> > &dimTags, + int dim) { - for(int d = -2; d < 4; d++){ + for(int d = -2; d < 4; d++) { if(dim != 99 && dim != d) continue; TopTools_DataMapIteratorOfDataMapOfIntegerShape exp; - switch(d){ + switch(d) { case 0: exp.Initialize(_tagVertex); break; case 1: exp.Initialize(_tagEdge); break; case 2: exp.Initialize(_tagFace); break; @@ -2767,8 +2780,8 @@ bool OCC_Internals::mergeVertices(const std::vector<int> &tags) std::vector<std::vector<std::pair<int, int> > > outDimTagsMap; for(unsigned int i = 0; i < tags.size(); i++) objectDimTags.push_back(std::pair<int, int>(0, tags[i])); - return booleanFragments(-1, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, - true, true); + return booleanFragments(-1, objectDimTags, toolDimTags, outDimTags, + outDimTagsMap, true, true); } void _addSimpleShapes(const TopoDS_Shape &shape, @@ -2797,20 +2810,21 @@ void _addSimpleShapes(const TopoDS_Shape &shape, } } -bool OCC_Internals::_transform(const std::vector<std::pair<int, int> > &inDimTags, - BRepBuilderAPI_Transform *tfo, - BRepBuilderAPI_GTransform *gtfo) +bool OCC_Internals::_transform( + const std::vector<std::pair<int, int> > &inDimTags, + BRepBuilderAPI_Transform *tfo, BRepBuilderAPI_GTransform *gtfo) { // build a single compound shape, so that we won't duplicate internal // boundaries BRep_Builder b; TopoDS_Compound c; b.MakeCompound(c); - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { int dim = inDimTags[i].first; int tag = inDimTags[i].second; - if(!_isBound(dim, tag)){ - Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, tag); + if(!_isBound(dim, tag)) { + Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, + tag); return false; } TopoDS_Shape shape = _find(dim, tag); @@ -2821,17 +2835,17 @@ bool OCC_Internals::_transform(const std::vector<std::pair<int, int> > &inDimTag _addSimpleShapes(c, inShapes); TopoDS_Shape result; - if(tfo){ + if(tfo) { tfo->Perform(c, Standard_False); - if(!tfo->IsDone()){ + if(!tfo->IsDone()) { Msg::Error("Could not apply transformation"); return false; } result = tfo->Shape(); } - else if(gtfo){ + else if(gtfo) { gtfo->Perform(c, Standard_False); - if(!gtfo->IsDone()){ + if(!gtfo->IsDone()) { Msg::Error("Could not apply transformation"); return false; } @@ -2840,14 +2854,14 @@ bool OCC_Internals::_transform(const std::vector<std::pair<int, int> > &inDimTag // copy vertex-based meshing attributes TopExp_Explorer exp0; - for(exp0.Init(c, TopAbs_VERTEX); exp0.More(); exp0.Next()){ + for(exp0.Init(c, TopAbs_VERTEX); exp0.More(); exp0.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp0.Current()); TopoDS_Shape transformed; if(tfo) transformed = tfo->ModifiedShape(vertex); else if(gtfo) transformed = gtfo->ModifiedShape(vertex); - if(!transformed.IsNull()){ + if(!transformed.IsNull()) { double lc = _meshAttributes->getMeshSize(0, vertex); if(lc > 0 && lc < MAX_LC) _meshAttributes->insert(new OCCMeshAttributes(0, transformed, lc)); @@ -2858,11 +2872,12 @@ bool OCC_Internals::_transform(const std::vector<std::pair<int, int> > &inDimTag std::vector<TopoDS_Shape> outShapes; _addSimpleShapes(result, outShapes); - if(inShapes.size() != inDimTags.size() || inShapes.size() != outShapes.size()){ + if(inShapes.size() != inDimTags.size() || + inShapes.size() != outShapes.size()) { Msg::Error("OpenCASCADE transform changed the number of shapes"); return false; } - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { // FIXME we should implement rebind(object, result, dim) which would // unbind/bind all subshapes to the same tags int dim = inDimTags[i].first; @@ -2874,8 +2889,9 @@ bool OCC_Internals::_transform(const std::vector<std::pair<int, int> > &inDimTag return true; } -bool OCC_Internals::translate(const std::vector<std::pair<int, int> > &inDimTags, - double dx, double dy, double dz) +bool OCC_Internals::translate( + const std::vector<std::pair<int, int> > &inDimTags, double dx, double dy, + double dz) { gp_Trsf t; t.SetTranslation(gp_Pnt(0, 0, 0), gp_Pnt(dx, dy, dz)); @@ -2884,8 +2900,8 @@ bool OCC_Internals::translate(const std::vector<std::pair<int, int> > &inDimTags } bool OCC_Internals::rotate(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double ax, double ay, double az, double angle) + double x, double y, double z, double ax, double ay, + double az, double angle) { gp_Trsf t; gp_Ax1 axisOfRevolution(gp_Pnt(x, y, z), gp_Dir(ax, ay, az)); @@ -2895,8 +2911,8 @@ bool OCC_Internals::rotate(const std::vector<std::pair<int, int> > &inDimTags, } bool OCC_Internals::dilate(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double a, double b, double c) + double x, double y, double z, double a, double b, + double c) { gp_GTrsf gt; gt.SetVectorialPart(gp_Mat(a, 0, 0, 0, b, 0, 0, 0, c)); @@ -2912,9 +2928,9 @@ bool OCC_Internals::symmetry(const std::vector<std::pair<int, int> > &inDimTags, double p = (a * a + b * b + c * c); if(!p) p = 1e-12; double f = -2.0 / p; - gt.SetVectorialPart(gp_Mat(1 + a * a * f, a * b * f, a * c * f, - a * b * f, 1. + b * b * f, b * c * f, - a * c * f, b * c * f, 1. + c * c * f)); + gt.SetVectorialPart(gp_Mat(1 + a * a * f, a * b * f, a * c * f, a * b * f, + 1. + b * b * f, b * c * f, a * c * f, b * c * f, + 1. + c * c * f)); gt.SetTranslationPart(gp_XYZ(a * d * f, b * d * f, c * d * f)); BRepBuilderAPI_GTransform gtfo(gt); return _transform(inDimTags, 0, >fo); @@ -2924,12 +2940,12 @@ bool OCC_Internals::copy(const std::vector<std::pair<int, int> > &inDimTags, std::vector<std::pair<int, int> > &outDimTags) { bool ret = true; - for(unsigned int i = 0; i < inDimTags.size(); i++){ + for(unsigned int i = 0; i < inDimTags.size(); i++) { int dim = inDimTags[i].first; int tag = inDimTags[i].second; - if(!_isBound(dim, tag)){ - Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", - dim, tag); + if(!_isBound(dim, tag)) { + Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, + tag); ret = false; continue; } @@ -2943,9 +2959,9 @@ bool OCC_Internals::copy(const std::vector<std::pair<int, int> > &inDimTags, bool OCC_Internals::remove(int dim, int tag, bool recursive) { - if(!_isBound(dim, tag)){ - Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", - dim, tag); + if(!_isBound(dim, tag)) { + Msg::Error("Unknown OpenCASCADE entity of dimension %d with tag %d", dim, + tag); return false; } unbind(_find(dim, tag), dim, tag, recursive); @@ -2956,9 +2972,8 @@ bool OCC_Internals::remove(const std::vector<std::pair<int, int> > &dimTags, bool recursive) { bool ret = true; - for(unsigned int i = 0; i < dimTags.size(); i++){ - if(!remove(dimTags[i].first, dimTags[i].second, recursive)) - ret = false; + for(unsigned int i = 0; i < dimTags.size(); i++) { + if(!remove(dimTags[i].first, dimTags[i].second, recursive)) ret = false; } return ret; } @@ -2970,36 +2985,36 @@ static void setTargetUnit(const std::string &unit) Msg::Error("Could not set OpenCASCADE target unit '%s'", unit.c_str()); } -bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnly, +bool OCC_Internals::importShapes(const std::string &fileName, + bool highestDimOnly, std::vector<std::pair<int, int> > &outDimTags, const std::string &format) { std::vector<std::string> split = SplitFileName(fileName); TopoDS_Shape result; - try{ - if(format == "brep" || - split[2] == ".brep" || split[2] == ".BREP"){ + try { + if(format == "brep" || split[2] == ".brep" || split[2] == ".BREP") { BRep_Builder aBuilder; BRepTools::Read(result, fileName.c_str(), aBuilder); } - else if(format == "step" || - split[2] == ".step" || split[2] == ".stp" || - split[2] == ".STEP" || split[2] == ".STP"){ + else if(format == "step" || split[2] == ".step" || split[2] == ".stp" || + split[2] == ".STEP" || split[2] == ".STP") { #if defined(HAVE_OCC_CAF) // Initiate a dummy XCAF Application to handle the STEP XCAF Document - static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication(); + static Handle_XCAFApp_Application dummy_app = + XCAFApp_Application::GetApplication(); // Create an XCAF Document to contain the STEP file itself Handle_TDocStd_Document step_doc; // Check if a STEP File is already open under this handle, if so, close it // to prevent Segmentation Faults when trying to create a new document - if(dummy_app->NbDocuments() > 0){ - dummy_app->GetDocument(1, step_doc); - dummy_app->Close(step_doc); + if(dummy_app->NbDocuments() > 0) { + dummy_app->GetDocument(1, step_doc); + dummy_app->Close(step_doc); } dummy_app->NewDocument("STEP-XCAF", step_doc); STEPCAFControl_Reader reader; setTargetUnit(CTX::instance()->geom.occTargetUnit); - if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone){ + if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone) { Msg::Error("Could not read file '%s'", fileName.c_str()); return false; } @@ -3011,7 +3026,7 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl XCAFDoc_DocumentTool::ColorTool(step_doc->Main()); TDF_LabelSequence step_shapes; step_shape_contents->GetShapes(step_shapes); - for(int i = 1; i <= step_shapes.Length(); i++){ + for(int i = 1; i <= step_shapes.Length(); i++) { printf("step shape %d: \n", i); TDF_Label label = step_shapes.Value(i); Handle(TDataStd_Name) N; @@ -3031,8 +3046,9 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl Quantity_Color col; std::stringstream col_rgb; step_colour_contents->GetColor(all_colours.Value(i),col); - col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")"; - Msg::Info("Colour [", i, "] = ", col.StringName(col.Name()), col_rgb.str().c_str()); + col_rgb << " : (" << col.Red() << "," << col.Green() << "," << + col.Blue() << ")"; Msg::Info("Colour [", i, "] = ", + col.StringName(col.Name()), col_rgb.str().c_str()); } // For the STEP File Reader in OCC, the 1st Shape contains the entire */ @@ -3041,7 +3057,7 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl #else STEPControl_Reader reader; setTargetUnit(CTX::instance()->geom.occTargetUnit); - if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone){ + if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone) { Msg::Error("Could not read file '%s'", fileName.c_str()); return false; } @@ -3050,12 +3066,11 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl result = reader.OneShape(); #endif } - else if(format == "iges" || - split[2] == ".iges" || split[2] == ".igs" || - split[2] == ".IGES" || split[2] == ".IGS"){ + else if(format == "iges" || split[2] == ".iges" || split[2] == ".igs" || + split[2] == ".IGES" || split[2] == ".IGS") { IGESControl_Reader reader; setTargetUnit(CTX::instance()->geom.occTargetUnit); - if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone){ + if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone) { Msg::Error("Could not read file '%s'", fileName.c_str()); return false; } @@ -3063,12 +3078,11 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl reader.TransferRoots(); result = reader.OneShape(); } - else{ + else { Msg::Error("Unknown file type '%s'", fileName.c_str()); return false; } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -3078,8 +3092,8 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl CTX::instance()->geom.occFixDegenerated, CTX::instance()->geom.occFixSmallEdges, CTX::instance()->geom.occFixSmallFaces, - CTX::instance()->geom.occSewFaces, - false, CTX::instance()->geom.occScaling); + CTX::instance()->geom.occSewFaces, false, + CTX::instance()->geom.occScaling); _multiBind(result, -1, outDimTags, highestDimOnly, true); return true; } @@ -3092,11 +3106,11 @@ bool OCC_Internals::importShapes(const TopoDS_Shape *shape, bool highestDimOnly, return true; } - bool OCC_Internals::exportShapes(const std::string &fileName, const std::string &format) { - // iterate over all shapes with tags, and import them into the (sub)shape _maps + // iterate over all shapes with tags, and import them into the (sub)shape + // _maps TopTools_DataMapIteratorOfDataMapOfIntegerShape exp0(_tagVertex); for(; exp0.More(); exp0.Next()) _addShapeToMaps(exp0.Value()); TopTools_DataMapIteratorOfDataMapOfIntegerShape exp1(_tagEdge); @@ -3120,28 +3134,25 @@ bool OCC_Internals::exportShapes(const std::string &fileName, std::vector<std::string> split = SplitFileName(fileName); try { - if(format == "brep" || - split[2] == ".brep" || split[2] == ".BREP"){ + if(format == "brep" || split[2] == ".brep" || split[2] == ".BREP") { BRepTools::Write(c, fileName.c_str()); } - else if(format == "step" || - split[2] == ".step" || split[2] == ".stp" || - split[2] == ".STEP" || split[2] == ".STP"){ + else if(format == "step" || split[2] == ".step" || split[2] == ".stp" || + split[2] == ".STEP" || split[2] == ".STP") { STEPControl_Writer writer; setTargetUnit(CTX::instance()->geom.occTargetUnit); - if(writer.Transfer(c, STEPControl_AsIs) == IFSelect_RetDone){ - if(writer.Write(fileName.c_str()) != IFSelect_RetDone){ + if(writer.Transfer(c, STEPControl_AsIs) == IFSelect_RetDone) { + if(writer.Write(fileName.c_str()) != IFSelect_RetDone) { Msg::Error("Could not create file '%s'", fileName.c_str()); return false; } } - else{ + else { Msg::Error("Could not create STEP data"); return false; } } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return false; } @@ -3151,14 +3162,15 @@ bool OCC_Internals::exportShapes(const std::string &fileName, void OCC_Internals::setMeshSize(int dim, int tag, double size) { if(dim != 0) return; - if(_tagVertex.IsBound(tag)){ - _meshAttributes->insert(new OCCMeshAttributes(0, _tagVertex.Find(tag), size)); + if(_tagVertex.IsBound(tag)) { + _meshAttributes->insert( + new OCCMeshAttributes(0, _tagVertex.Find(tag), size)); } } bool OCC_Internals::getVertex(int tag, double &x, double &y, double &z) { - if(_tagVertex.IsBound(tag)){ + if(_tagVertex.IsBound(tag)) { gp_Pnt pnt = BRep_Tool::Pnt(TopoDS::Vertex(_tagVertex.Find(tag))); x = pnt.X(); y = pnt.Y(); @@ -3168,7 +3180,8 @@ bool OCC_Internals::getVertex(int tag, double &x, double &y, double &z) return false; } -bool const sortByInvDim(std::pair<int, int> const &lhs, std::pair<int, int> const &rhs) +bool const sortByInvDim(std::pair<int, int> const &lhs, + std::pair<int, int> const &rhs) { return lhs.first > rhs.first; } @@ -3188,7 +3201,8 @@ void OCC_Internals::synchronize(GModel *model) model->remove(toRemove); _toRemove.clear(); - // iterate over all shapes with tags, and import them into the (sub)shape _maps + // iterate over all shapes with tags, and import them into the (sub)shape + // _maps _somap.Clear(); _shmap.Clear(); _fmap.Clear(); @@ -3209,14 +3223,14 @@ void OCC_Internals::synchronize(GModel *model) int eTagMax = std::max(model->getMaxElementaryNumber(1), getMaxTag(1)); int fTagMax = std::max(model->getMaxElementaryNumber(2), getMaxTag(2)); int rTagMax = std::max(model->getMaxElementaryNumber(3), getMaxTag(3)); - for(int i = 1; i <= _vmap.Extent(); i++){ + for(int i = 1; i <= _vmap.Extent(); i++) { TopoDS_Vertex vertex = TopoDS::Vertex(_vmap(i)); GVertex *occv = getVertexForOCCShape(model, vertex); - if(!occv){ + if(!occv) { int tag; if(_vertexTag.IsBound(vertex)) tag = _vertexTag.Find(vertex); - else{ + else { tag = ++vTagMax; Msg::Info("Binding unbound OpenCASCADE point to tag %d", tag); } @@ -3225,16 +3239,16 @@ void OCC_Internals::synchronize(GModel *model) model->add(occv); } } - for(int i = 1; i <= _emap.Extent(); i++){ + for(int i = 1; i <= _emap.Extent(); i++) { TopoDS_Edge edge = TopoDS::Edge(_emap(i)); GEdge *occe = getEdgeForOCCShape(model, edge); - if(!occe){ + if(!occe) { GVertex *v1 = getVertexForOCCShape(model, TopExp::FirstVertex(edge)); GVertex *v2 = getVertexForOCCShape(model, TopExp::LastVertex(edge)); int tag; if(_edgeTag.IsBound(edge)) tag = _edgeTag.Find(edge); - else{ + else { tag = ++eTagMax; Msg::Info("Binding unbound OpenCASCADE curve to tag %d", tag); } @@ -3243,14 +3257,14 @@ void OCC_Internals::synchronize(GModel *model) } _copyExtrudedMeshAttributes(edge, occe); } - for(int i = 1; i <= _fmap.Extent(); i++){ + for(int i = 1; i <= _fmap.Extent(); i++) { TopoDS_Face face = TopoDS::Face(_fmap(i)); GFace *occf = getFaceForOCCShape(model, face); - if(!occf){ + if(!occf) { int tag; if(_faceTag.IsBound(face)) tag = _faceTag.Find(face); - else{ + else { tag = ++fTagMax; Msg::Info("Binding unbound OpenCASCADE surface to tag %d", tag); } @@ -3259,14 +3273,14 @@ void OCC_Internals::synchronize(GModel *model) } _copyExtrudedMeshAttributes(face, occf); } - for(int i = 1; i <= _somap.Extent(); i++){ + for(int i = 1; i <= _somap.Extent(); i++) { TopoDS_Solid region = TopoDS::Solid(_somap(i)); GRegion *occr = getRegionForOCCShape(model, region); - if(!occr){ + if(!occr) { int tag; if(_solidTag.IsBound(region)) tag = _solidTag(region); - else{ + else { tag = ++rTagMax; Msg::Info("Binding unbound OpenCASCADE volume to tag %d", tag); } @@ -3323,38 +3337,36 @@ void OCC_Internals::_addShapeToMaps(const TopoDS_Shape &shape) { // Solids TopExp_Explorer exp0, exp1, exp2, exp3, exp4, exp5; - for(exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next()){ + for(exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next()) { TopoDS_Solid solid = TopoDS::Solid(exp0.Current()); - if(_somap.FindIndex(solid) < 1){ + if(_somap.FindIndex(solid) < 1) { _somap.Add(solid); - for(exp1.Init(solid, TopAbs_SHELL); exp1.More(); exp1.Next()){ + for(exp1.Init(solid, TopAbs_SHELL); exp1.More(); exp1.Next()) { TopoDS_Shell shell = TopoDS::Shell(exp1.Current()); - if(_shmap.FindIndex(shell) < 1){ + if(_shmap.FindIndex(shell) < 1) { _shmap.Add(shell); - for(exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next()){ + for(exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next()) { TopoDS_Face face = TopoDS::Face(exp2.Current()); - if(_fmap.FindIndex(face) < 1){ + if(_fmap.FindIndex(face) < 1) { _fmap.Add(face); for(exp3.Init(face.Oriented(TopAbs_FORWARD), TopAbs_WIRE); - exp3.More(); exp3.Next()){ - //for(exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()){ + exp3.More(); exp3.Next()) { + // for(exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()){ TopoDS_Wire wire = TopoDS::Wire(exp3.Current()); - if(_wmap.FindIndex(wire) < 1){ + if(_wmap.FindIndex(wire) < 1) { _wmap.Add(wire); - for(exp4.Init(wire, TopAbs_EDGE); exp4.More(); - exp4.Next()){ + for(exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if(_emap.FindIndex(edge) < 1){ + if(_emap.FindIndex(edge) < 1) { _emap.Add(edge); for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); - exp5.Next()){ + exp5.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if(_vmap.FindIndex(vertex) < 1) - _vmap.Add(vertex); + if(_vmap.FindIndex(vertex) < 1) _vmap.Add(vertex); } } } @@ -3368,30 +3380,30 @@ void OCC_Internals::_addShapeToMaps(const TopoDS_Shape &shape) } // Free Shells - for(exp1.Init(shape, TopAbs_SHELL, TopAbs_SOLID); exp1.More(); exp1.Next()){ + for(exp1.Init(shape, TopAbs_SHELL, TopAbs_SOLID); exp1.More(); exp1.Next()) { const TopoDS_Shape &shell = exp1.Current(); - if(_shmap.FindIndex(shell) < 1){ + if(_shmap.FindIndex(shell) < 1) { _shmap.Add(shell); - for(exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next()){ + for(exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next()) { TopoDS_Face face = TopoDS::Face(exp2.Current()); - if(_fmap.FindIndex(face) < 1){ + if(_fmap.FindIndex(face) < 1) { _fmap.Add(face); - for(exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()){ + for(exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()) { TopoDS_Wire wire = TopoDS::Wire(exp3.Current()); - if(_wmap.FindIndex(wire) < 1){ + if(_wmap.FindIndex(wire) < 1) { _wmap.Add(wire); - for(exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()){ + for(exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if(_emap.FindIndex(edge) < 1){ + if(_emap.FindIndex(edge) < 1) { _emap.Add(edge); - for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()){ + for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); + exp5.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if(_vmap.FindIndex(vertex) < 1) - _vmap.Add(vertex); + if(_vmap.FindIndex(vertex) < 1) _vmap.Add(vertex); } } } @@ -3403,25 +3415,24 @@ void OCC_Internals::_addShapeToMaps(const TopoDS_Shape &shape) } // Free Faces - for(exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL); exp2.More(); exp2.Next()){ + for(exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL); exp2.More(); exp2.Next()) { TopoDS_Face face = TopoDS::Face(exp2.Current()); - if(_fmap.FindIndex(face) < 1){ + if(_fmap.FindIndex(face) < 1) { _fmap.Add(face); - for(exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()){ + for(exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()) { TopoDS_Wire wire = TopoDS::Wire(exp3.Current()); - if(_wmap.FindIndex(wire) < 1){ + if(_wmap.FindIndex(wire) < 1) { _wmap.Add(wire); - for(exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()){ + for(exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if(_emap.FindIndex(edge) < 1){ + if(_emap.FindIndex(edge) < 1) { _emap.Add(edge); - for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()){ + for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if(_vmap.FindIndex(vertex) < 1) - _vmap.Add(vertex); + if(_vmap.FindIndex(vertex) < 1) _vmap.Add(vertex); } } } @@ -3431,20 +3442,19 @@ void OCC_Internals::_addShapeToMaps(const TopoDS_Shape &shape) } // Free Wires - for(exp3.Init(shape, TopAbs_WIRE, TopAbs_FACE); exp3.More(); exp3.Next()){ + for(exp3.Init(shape, TopAbs_WIRE, TopAbs_FACE); exp3.More(); exp3.Next()) { TopoDS_Wire wire = TopoDS::Wire(exp3.Current()); - if(_wmap.FindIndex(wire) < 1){ + if(_wmap.FindIndex(wire) < 1) { _wmap.Add(wire); - for(exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()){ + for(exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if(_emap.FindIndex(edge) < 1){ + if(_emap.FindIndex(edge) < 1) { _emap.Add(edge); - for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()){ + for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if(_vmap.FindIndex(vertex) < 1) - _vmap.Add(vertex); + if(_vmap.FindIndex(vertex) < 1) _vmap.Add(vertex); } } } @@ -3452,23 +3462,22 @@ void OCC_Internals::_addShapeToMaps(const TopoDS_Shape &shape) } // Free Edges - for(exp4.Init(shape, TopAbs_EDGE, TopAbs_WIRE); exp4.More(); exp4.Next()){ + for(exp4.Init(shape, TopAbs_EDGE, TopAbs_WIRE); exp4.More(); exp4.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if(_emap.FindIndex(edge) < 1){ + if(_emap.FindIndex(edge) < 1) { _emap.Add(edge); - for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()){ + for(exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if(_vmap.FindIndex(vertex) < 1) - _vmap.Add(vertex); + if(_vmap.FindIndex(vertex) < 1) _vmap.Add(vertex); } } } // Free Vertices - for(exp5.Init(shape, TopAbs_VERTEX, TopAbs_EDGE); exp5.More(); exp5.Next()){ + for(exp5.Init(shape, TopAbs_VERTEX, TopAbs_EDGE); exp5.More(); exp5.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if(_vmap.FindIndex(vertex) < 1){ + if(_vmap.FindIndex(vertex) < 1) { _vmap.Add(vertex); } } @@ -3479,7 +3488,7 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, bool fixspotstripfaces, bool sewfaces, bool makesolids, double scaling) { - if(scaling != 1.0){ + if(scaling != 1.0) { Msg::Info("Scaling geometry by factor %g", scaling); gp_Trsf t; t.SetScaleFactor(scaling); @@ -3487,8 +3496,9 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, myshape = trsf.Shape(); } - if(!fixdegenerated && !fixsmalledges && !fixspotstripfaces && - !sewfaces && !makesolids) return; + if(!fixdegenerated && !fixsmalledges && !fixspotstripfaces && !sewfaces && + !makesolids) + return; Msg::Info("Starting shape healing (tolerance: %g)", tolerance); @@ -3508,23 +3518,22 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, for(exp0.Init(myshape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nrcs++; double surfacecont = 0; - for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); GProp_GProps system; BRepGProp::SurfaceProperties(face, system); surfacecont += system.Mass(); } - if(fixdegenerated){ + if(fixdegenerated) { Msg::Info("- fix degenerated edges and faces"); { Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; rebuild->Apply(myshape); - for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()){ + for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if(BRep_Tool::Degenerated(edge)) - rebuild->Remove(edge); + if(BRep_Tool::Degenerated(edge)) rebuild->Remove(edge); } myshape = rebuild->Apply(myshape); } @@ -3541,7 +3550,7 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; rebuild->Apply(myshape); - for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); sff = new ShapeFix_Face(face); @@ -3549,27 +3558,24 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, sff->FixSmallAreaWireMode() = Standard_True; sff->Perform(); - if(sff->Status(ShapeExtend_DONE1) || - sff->Status(ShapeExtend_DONE2) || - sff->Status(ShapeExtend_DONE3) || - sff->Status(ShapeExtend_DONE4) || - sff->Status(ShapeExtend_DONE5)) - { - Msg::Info(" repaired face %d", _fmap.FindIndex(face)); - if(sff->Status(ShapeExtend_DONE1)) - Msg::Info(" (some wires are fixed)"); - else if(sff->Status(ShapeExtend_DONE2)) - Msg::Info(" (orientation of wires fixed)"); - else if(sff->Status(ShapeExtend_DONE3)) - Msg::Info(" (missing seam added)"); - else if(sff->Status(ShapeExtend_DONE4)) - Msg::Info(" (small area wire removed)"); - else if(sff->Status(ShapeExtend_DONE5)) - Msg::Info(" (natural bounds added)"); - TopoDS_Face newface = sff->Face(); - - rebuild->Replace(face, newface); - } + if(sff->Status(ShapeExtend_DONE1) || sff->Status(ShapeExtend_DONE2) || + sff->Status(ShapeExtend_DONE3) || sff->Status(ShapeExtend_DONE4) || + sff->Status(ShapeExtend_DONE5)) { + Msg::Info(" repaired face %d", _fmap.FindIndex(face)); + if(sff->Status(ShapeExtend_DONE1)) + Msg::Info(" (some wires are fixed)"); + else if(sff->Status(ShapeExtend_DONE2)) + Msg::Info(" (orientation of wires fixed)"); + else if(sff->Status(ShapeExtend_DONE3)) + Msg::Info(" (missing seam added)"); + else if(sff->Status(ShapeExtend_DONE4)) + Msg::Info(" (small area wire removed)"); + else if(sff->Status(ShapeExtend_DONE5)) + Msg::Info(" (natural bounds added)"); + TopoDS_Face newface = sff->Face(); + + rebuild->Replace(face, newface); + } } myshape = rebuild->Apply(myshape); } @@ -3577,28 +3583,27 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, { Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; rebuild->Apply(myshape); - for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()){ + for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if(BRep_Tool::Degenerated(edge)) - rebuild->Remove(edge); + if(BRep_Tool::Degenerated(edge)) rebuild->Remove(edge); } myshape = rebuild->Apply(myshape); } } - if(fixsmalledges){ + if(fixsmalledges) { Msg::Info("- fixing small edges"); Handle(ShapeFix_Wire) sfw; Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; rebuild->Apply(myshape); - for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); - for(exp1.Init(face, TopAbs_WIRE); exp1.More(); exp1.Next()){ + for(exp1.Init(face, TopAbs_WIRE); exp1.More(); exp1.Next()) { TopoDS_Wire oldwire = TopoDS::Wire(exp1.Current()); - sfw = new ShapeFix_Wire(oldwire, face ,tolerance); + sfw = new ShapeFix_Wire(oldwire, face, tolerance); sfw->ModifyTopologyMode() = Standard_True; sfw->ClosedWireMode() = Standard_True; @@ -3608,29 +3613,33 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, replace = sfw->FixConnected() || replace; if(sfw->FixSmall(Standard_False, tolerance) && - ! (sfw->StatusSmall(ShapeExtend_FAIL1) || - sfw->StatusSmall(ShapeExtend_FAIL2) || - sfw->StatusSmall(ShapeExtend_FAIL3))){ + !(sfw->StatusSmall(ShapeExtend_FAIL1) || + sfw->StatusSmall(ShapeExtend_FAIL2) || + sfw->StatusSmall(ShapeExtend_FAIL3))) { Msg::Info(" fixed small edge in wire %d", _wmap.FindIndex(oldwire)); replace = true; } else if(sfw->StatusSmall(ShapeExtend_FAIL1)) - Msg::Warning("Failed to fix small edge in wire %d, edge cannot be checked " - "(no 3d curve and no pcurve)", _wmap.FindIndex(oldwire)); + Msg::Warning( + "Failed to fix small edge in wire %d, edge cannot be checked " + "(no 3d curve and no pcurve)", + _wmap.FindIndex(oldwire)); else if(sfw->StatusSmall(ShapeExtend_FAIL2)) - Msg::Warning("Failed to fix small edge in wire %d, " - "edge is null-length and has different vertives at begin and " - "end, and lockvtx is True or ModifiyTopologyMode is False", - _wmap.FindIndex(oldwire)); + Msg::Warning( + "Failed to fix small edge in wire %d, " + "edge is null-length and has different vertives at begin and " + "end, and lockvtx is True or ModifiyTopologyMode is False", + _wmap.FindIndex(oldwire)); else if(sfw->StatusSmall(ShapeExtend_FAIL3)) - Msg::Warning("Failed to fix small edge in wire, CheckConnected has failed", - _wmap.FindIndex(oldwire)); + Msg::Warning( + "Failed to fix small edge in wire, CheckConnected has failed", + _wmap.FindIndex(oldwire)); replace = sfw->FixEdgeCurves() || replace; replace = sfw->FixDegenerated() || replace; replace = sfw->FixSelfIntersection() || replace; replace = sfw->FixLacking(Standard_True) || replace; - if(replace){ + if(replace) { TopoDS_Wire newwire = sfw->Wire(); rebuild->Replace(oldwire, newwire); } @@ -3650,16 +3659,17 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; rebuild->Apply(myshape); - for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()){ + for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); if(_vmap.FindIndex(TopExp::FirstVertex(edge)) == - _vmap.FindIndex(TopExp::LastVertex(edge))){ + _vmap.FindIndex(TopExp::LastVertex(edge))) { GProp_GProps system; BRepGProp::LinearProperties(edge, system); - if(system.Mass() < tolerance){ - Msg::Info(" removing degenerated edge %d from vertex %d to vertex %d", - _emap.FindIndex(edge), _vmap.FindIndex(TopExp::FirstVertex(edge)), - _vmap.FindIndex(TopExp::LastVertex(edge))); + if(system.Mass() < tolerance) { + Msg::Info( + " removing degenerated edge %d from vertex %d to vertex %d", + _emap.FindIndex(edge), _vmap.FindIndex(TopExp::FirstVertex(edge)), + _vmap.FindIndex(TopExp::LastVertex(edge))); rebuild->Remove(edge); } } @@ -3670,10 +3680,9 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, { Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; rebuild->Apply(myshape); - for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()){ + for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if(BRep_Tool::Degenerated(edge)) - rebuild->Remove(edge); + if(BRep_Tool::Degenerated(edge)) rebuild->Remove(edge); } myshape = rebuild->Apply(myshape); } @@ -3683,10 +3692,9 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, sfwf->Load(myshape); sfwf->ModeDropSmallEdges() = Standard_True; - if(sfwf->FixWireGaps()){ + if(sfwf->FixWireGaps()) { Msg::Info("- fixing wire gaps"); - if(sfwf->StatusWireGaps(ShapeExtend_OK)) - Msg::Info(" no gaps found"); + if(sfwf->StatusWireGaps(ShapeExtend_OK)) Msg::Info(" no gaps found"); if(sfwf->StatusWireGaps(ShapeExtend_DONE1)) Msg::Info(" some 2D gaps fixed"); if(sfwf->StatusWireGaps(ShapeExtend_DONE2)) @@ -3699,7 +3707,7 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, sfwf->SetPrecision(tolerance); - if(sfwf->FixSmallEdges()){ + if(sfwf->FixSmallEdges()) { Msg::Info("- fixing wire frames"); if(sfwf->StatusSmallEdges(ShapeExtend_OK)) Msg::Info(" no small edges found"); @@ -3712,7 +3720,7 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, myshape = sfwf->Shape(); } - if(fixspotstripfaces){ + if(fixspotstripfaces) { Msg::Info("- fixing spot and strip faces"); Handle(ShapeFix_FixSmallFace) sffsm = new ShapeFix_FixSmallFace(); sffsm->Init(myshape); @@ -3722,12 +3730,12 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, myshape = sffsm->FixShape(); } - if(sewfaces){ + if(sewfaces) { Msg::Info("- sewing faces"); BRepOffsetAPI_Sewing sewedObj(tolerance); - for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); sewedObj.Add(face); } @@ -3743,30 +3751,29 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, { Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; rebuild->Apply(myshape); - for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()){ + for(exp1.Init(myshape, TopAbs_EDGE); exp1.More(); exp1.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); - if(BRep_Tool::Degenerated(edge)) - rebuild->Remove(edge); + if(BRep_Tool::Degenerated(edge)) rebuild->Remove(edge); } myshape = rebuild->Apply(myshape); } - if(makesolids){ + if(makesolids) { Msg::Info("- making solids"); BRepBuilderAPI_MakeSolid ms; int count = 0; - for(exp0.Init(myshape, TopAbs_SHELL); exp0.More(); exp0.Next()){ + for(exp0.Init(myshape, TopAbs_SHELL); exp0.More(); exp0.Next()) { count++; ms.Add(TopoDS::Shell(exp0.Current())); } - if(!count){ + if(!count) { Msg::Info(" not possible (no shells)"); } - else{ + else { BRepCheck_Analyzer ba(ms); - if(ba.IsValid()){ + if(ba.IsValid()) { Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape; sfs->Init(ms); sfs->SetPrecision(tolerance); @@ -3774,14 +3781,15 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, sfs->Perform(); myshape = sfs->Shape(); - for(exp0.Init(myshape, TopAbs_SOLID); exp0.More(); exp0.Next()){ + for(exp0.Init(myshape, TopAbs_SOLID); exp0.More(); exp0.Next()) { TopoDS_Solid solid = TopoDS::Solid(exp0.Current()); TopoDS_Solid newsolid = solid; BRepLib::OrientClosedSolid(newsolid); Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape; // rebuild->Apply(myshape); rebuild->Replace(solid, newsolid); - TopoDS_Shape newshape = rebuild->Apply(myshape, TopAbs_COMPSOLID);//, 1); + TopoDS_Shape newshape = + rebuild->Apply(myshape, TopAbs_COMPSOLID); //, 1); // TopoDS_Shape newshape = rebuild->Apply(myshape); myshape = newshape; } @@ -3792,7 +3800,7 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, } double newsurfacecont = 0; - for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(myshape, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); GProp_GProps system; BRepGProp::SurfaceProperties(face, system); @@ -3820,7 +3828,7 @@ void OCC_Internals::_healShape(TopoDS_Shape &myshape, double tolerance, Msg::Info("Wires : %d (%d)", nnrw, nrw); Msg::Info("Faces : %d (%d)", nnrf, nrf); Msg::Info("Edges : %d (%d)", nnre, nre); - Msg::Info("Vertices : %d (%d)", nnrv, nrv ); + Msg::Info("Vertices : %d (%d)", nnrv, nrv); Msg::Info("Totol surface area : %g (%g)", newsurfacecont, surfacecont); Msg::Info("-----------------------------------"); } @@ -3836,11 +3844,11 @@ static bool makeSTL(const TopoDS_Face &s, std::vector<SPoint2> *verticesUV, Bnd_Box aBox; BRepBndLib::Add(s, aBox); -#if (OCC_VERSION_MAJOR >= 7) +#if(OCC_VERSION_MAJOR >= 7) double fact = 1; BRepMesh_FastDiscret::Parameters parameters; - parameters.Deflection = fact*0.1; - parameters.Angle = fact*0.35; + parameters.Deflection = fact * 0.1; + parameters.Angle = fact * 0.35; // parameters.InternalVerticesMode = Standard_False; parameters.Relative = Standard_False; BRepMesh_FastDiscret aMesher(aBox, parameters); @@ -3853,30 +3861,27 @@ static bool makeSTL(const TopoDS_Face &s, std::vector<SPoint2> *verticesUV, TopLoc_Location loc; Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(s, loc); - if(triangulation.IsNull()) - return false; + if(triangulation.IsNull()) return false; - if(verticesUV && !triangulation->HasUVNodes()) - return false; + if(verticesUV && !triangulation->HasUVNodes()) return false; - if(normals && !triangulation->HasUVNodes()) - return false; + if(normals && !triangulation->HasUVNodes()) return false; int start = 0; if(verticesUV) start = verticesUV->size(); if(verticesXYZ) start = verticesXYZ->size(); - for(int i = 1; i <= triangulation->NbNodes(); i++){ - if(verticesUV){ + for(int i = 1; i <= triangulation->NbNodes(); i++) { + if(verticesUV) { gp_Pnt2d p = (triangulation->UVNodes())(i); verticesUV->push_back(SPoint2(p.X(), p.Y())); } - if(verticesXYZ){ + if(verticesXYZ) { gp_Pnt pp = (triangulation->Nodes())(i); double x = pp.X(), y = pp.Y(), z = pp.Z(); loc.Transformation().Transforms(x, y, z); verticesXYZ->push_back(SPoint3(x, y, z)); } - if(normals){ + if(normals) { gp_Pnt2d p = (triangulation->UVNodes())(i); Handle(Geom_Surface) sur = BRep_Tool::Surface(s); gp_Pnt pnt; @@ -3891,31 +3896,30 @@ static bool makeSTL(const TopoDS_Face &s, std::vector<SPoint2> *verticesUV, } } bool reverse = false; - for(int i = 1; i <= triangulation->NbTriangles(); i++){ + for(int i = 1; i <= triangulation->NbTriangles(); i++) { Poly_Triangle triangle = (triangulation->Triangles())(i); int p1, p2, p3; triangle.Get(p1, p2, p3); - if(i == 1 && normals){ // verify orientation + if(i == 1 && normals) { // verify orientation SVector3 nn = (*normals)[start + p1 - 1]; gp_Pnt pp1 = (triangulation->Nodes())(p1); gp_Pnt pp2 = (triangulation->Nodes())(p2); gp_Pnt pp3 = (triangulation->Nodes())(p3); double n[3]; - normal3points(pp1.X(), pp1.Y(), pp1.Z(), - pp2.X(), pp2.Y(), pp2.Z(), + normal3points(pp1.X(), pp1.Y(), pp1.Z(), pp2.X(), pp2.Y(), pp2.Z(), pp3.X(), pp3.Y(), pp3.Z(), n); SVector3 ne(n[0], n[1], n[2]); - if(dot(ne, nn) < 0){ + if(dot(ne, nn) < 0) { Msg::Debug("Reversing orientation of STL mesh"); reverse = true; } } triangles.push_back(start + p1 - 1); - if(!reverse){ + if(!reverse) { triangles.push_back(start + p2 - 1); triangles.push_back(start + p3 - 1); } - else{ + else { triangles.push_back(start + p3 - 1); triangles.push_back(start + p2 - 1); } @@ -3923,13 +3927,15 @@ static bool makeSTL(const TopoDS_Face &s, std::vector<SPoint2> *verticesUV, return true; } -bool OCC_Internals::makeFaceSTL(TopoDS_Face s, std::vector<SPoint2> &vertices_uv, +bool OCC_Internals::makeFaceSTL(TopoDS_Face s, + std::vector<SPoint2> &vertices_uv, std::vector<int> &triangles) { return makeSTL(s, &vertices_uv, 0, 0, triangles); } -bool OCC_Internals::makeFaceSTL(TopoDS_Face s, std::vector<SPoint2> &vertices_uv, +bool OCC_Internals::makeFaceSTL(TopoDS_Face s, + std::vector<SPoint2> &vertices_uv, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) @@ -3951,125 +3957,109 @@ bool OCC_Internals::makeSolidSTL(const TopoDS_Solid &s, { bool ret = true; TopExp_Explorer exp0; - for(exp0.Init(s, TopAbs_FACE); exp0.More(); exp0.Next()){ + for(exp0.Init(s, TopAbs_FACE); exp0.More(); exp0.Next()) { TopoDS_Face face = TopoDS::Face(exp0.Current()); - bool tmp = makeSTL(TopoDS::Face(face.Oriented(TopAbs_FORWARD)), - 0, &vertices, &normals, triangles); + bool tmp = makeSTL(TopoDS::Face(face.Oriented(TopAbs_FORWARD)), 0, + &vertices, &normals, triangles); if(!tmp) ret = false; } return ret; } -bool OCC_Internals::makeRectangleSTL(double x, double y, double z, double dx, double dy, - double roundedRadius, +bool OCC_Internals::makeRectangleSTL(double x, double y, double z, double dx, + double dy, double roundedRadius, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { TopoDS_Face result; - if(!makeRectangle(result, x, y, z, dx, dy, roundedRadius)) - return false; - if(!makeFaceSTL(result, vertices, normals, triangles)) - return false; + if(!makeRectangle(result, x, y, z, dx, dy, roundedRadius)) return false; + if(!makeFaceSTL(result, vertices, normals, triangles)) return false; return true; } -bool OCC_Internals::makeDiskSTL(double xc, double yc, double zc, double rx, double ry, - std::vector<SPoint3> &vertices, +bool OCC_Internals::makeDiskSTL(double xc, double yc, double zc, double rx, + double ry, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { TopoDS_Face result; - if(!makeDisk(result, xc, yc, zc, rx, ry)) - return false; - if(!makeFaceSTL(result, vertices, normals, triangles)) - return false; + if(!makeDisk(result, xc, yc, zc, rx, ry)) return false; + if(!makeFaceSTL(result, vertices, normals, triangles)) return false; return true; } -bool OCC_Internals::makeSphereSTL(double xc, double yc, double zc, double radius, - double angle1, double angle2, double angle3, - std::vector<SPoint3> &vertices, +bool OCC_Internals::makeSphereSTL(double xc, double yc, double zc, + double radius, double angle1, double angle2, + double angle3, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { TopoDS_Solid result; if(!makeSphere(result, xc, yc, zc, radius, angle1, angle2, angle3)) return false; - if(!makeSolidSTL(result, vertices, normals, triangles)) - return false; + if(!makeSolidSTL(result, vertices, normals, triangles)) return false; return true; } -bool OCC_Internals::makeBoxSTL(double x, double y, double z, - double dx, double dy, double dz, +bool OCC_Internals::makeBoxSTL(double x, double y, double z, double dx, + double dy, double dz, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { TopoDS_Solid result; - if(!makeBox(result, x, y, z, dx, dy, dz)) - return false; - if(!makeSolidSTL(result, vertices, normals, triangles)) - return false; + if(!makeBox(result, x, y, z, dx, dy, dz)) return false; + if(!makeSolidSTL(result, vertices, normals, triangles)) return false; return true; } -bool OCC_Internals::makeCylinderSTL(double x, double y, double z, - double dx, double dy, double dz, - double r, double angle, +bool OCC_Internals::makeCylinderSTL(double x, double y, double z, double dx, + double dy, double dz, double r, + double angle, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { TopoDS_Solid result; - if(!makeCylinder(result, x, y, z, dx, dy, dz, r, angle)) - return false; - if(!makeSolidSTL(result, vertices, normals, triangles)) - return false; + if(!makeCylinder(result, x, y, z, dx, dy, dz, r, angle)) return false; + if(!makeSolidSTL(result, vertices, normals, triangles)) return false; return true; } -bool OCC_Internals::makeConeSTL(double x, double y, double z, - double dx, double dy, double dz, - double r1, double r2, double angle, - std::vector<SPoint3> &vertices, +bool OCC_Internals::makeConeSTL(double x, double y, double z, double dx, + double dy, double dz, double r1, double r2, + double angle, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { TopoDS_Solid result; - if(!makeCone(result, x, y, z, dx, dy, dz, r1, r2, angle)) - return false; - if(!makeSolidSTL(result, vertices, normals, triangles)) - return false; + if(!makeCone(result, x, y, z, dx, dy, dz, r1, r2, angle)) return false; + if(!makeSolidSTL(result, vertices, normals, triangles)) return false; return true; } -bool OCC_Internals::makeWedgeSTL(double x, double y, double z, - double dx, double dy, double dz, double ltx, +bool OCC_Internals::makeWedgeSTL(double x, double y, double z, double dx, + double dy, double dz, double ltx, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { TopoDS_Solid result; - if(!makeWedge(result, x, y, z, dx, dy, dz, ltx)) - return false; - if(!makeSolidSTL(result, vertices, normals, triangles)) - return false; + if(!makeWedge(result, x, y, z, dx, dy, dz, ltx)) return false; + if(!makeSolidSTL(result, vertices, normals, triangles)) return false; return true; } -bool OCC_Internals::makeTorusSTL(double x, double y, double z, - double r1, double r2, double angle, +bool OCC_Internals::makeTorusSTL(double x, double y, double z, double r1, + double r2, double angle, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { TopoDS_Solid result; - if(!makeTorus(result, x, y, z, r1, r2, angle)) - return false; - if(!makeSolidSTL(result, vertices, normals, triangles)) - return false; + if(!makeTorus(result, x, y, z, r1, r2, angle)) return false; + if(!makeSolidSTL(result, vertices, normals, triangles)) return false; return true; } @@ -4095,8 +4085,7 @@ void GModel::_resetOCCInternals() int GModel::readOCCBREP(const std::string &fn) { - if(!_occ_internals) - _occ_internals = new OCC_Internals; + if(!_occ_internals) _occ_internals = new OCC_Internals; std::vector<std::pair<int, int> > outDimTags; _occ_internals->importShapes(fn, false, outDimTags, "brep"); _occ_internals->synchronize(this); @@ -4106,8 +4095,7 @@ int GModel::readOCCBREP(const std::string &fn) int GModel::readOCCSTEP(const std::string &fn) { - if(!_occ_internals) - _occ_internals = new OCC_Internals; + if(!_occ_internals) _occ_internals = new OCC_Internals; std::vector<std::pair<int, int> > outDimTags; _occ_internals->importShapes(fn, false, outDimTags, "step"); _occ_internals->synchronize(this); @@ -4116,8 +4104,7 @@ int GModel::readOCCSTEP(const std::string &fn) int GModel::readOCCIGES(const std::string &fn) { - if(!_occ_internals) - _occ_internals = new OCC_Internals; + if(!_occ_internals) _occ_internals = new OCC_Internals; std::vector<std::pair<int, int> > outDimTags; _occ_internals->importShapes(fn, false, outDimTags, "iges"); _occ_internals->synchronize(this); @@ -4126,7 +4113,7 @@ int GModel::readOCCIGES(const std::string &fn) int GModel::writeOCCBREP(const std::string &fn) { - if(!_occ_internals){ + if(!_occ_internals) { Msg::Error("No OpenCASCADE model found"); return 0; } @@ -4136,7 +4123,7 @@ int GModel::writeOCCBREP(const std::string &fn) int GModel::writeOCCSTEP(const std::string &fn) { - if(!_occ_internals){ + if(!_occ_internals) { Msg::Error("No OpenCASCADE model found"); return 0; } @@ -4146,11 +4133,10 @@ int GModel::writeOCCSTEP(const std::string &fn) int GModel::importOCCShape(const void *shape) { - if(!_occ_internals) - _occ_internals = new OCC_Internals; + if(!_occ_internals) _occ_internals = new OCC_Internals; #if defined(HAVE_OCC) std::vector<std::pair<int, int> > outDimTags; - _occ_internals->importShapes((TopoDS_Shape*)shape, false, outDimTags); + _occ_internals->importShapes((TopoDS_Shape *)shape, false, outDimTags); #else Msg::Error("Gmsh requires OpenCASCADE to import TopoDS_Shape"); #endif @@ -4159,41 +4145,41 @@ int GModel::importOCCShape(const void *shape) return 1; } -GVertex* GModel::getVertexForOCCShape(const void *shape) +GVertex *GModel::getVertexForOCCShape(const void *shape) { if(!_occ_internals) return 0; #if defined(HAVE_OCC) - return _occ_internals->getVertexForOCCShape(this, *(TopoDS_Vertex*)shape); + return _occ_internals->getVertexForOCCShape(this, *(TopoDS_Vertex *)shape); #else return 0; #endif } -GEdge* GModel::getEdgeForOCCShape(const void *shape) +GEdge *GModel::getEdgeForOCCShape(const void *shape) { if(!_occ_internals) return 0; #if defined(HAVE_OCC) - return _occ_internals->getEdgeForOCCShape(this, *(TopoDS_Edge*)shape); + return _occ_internals->getEdgeForOCCShape(this, *(TopoDS_Edge *)shape); #else return 0; #endif } -GFace* GModel::getFaceForOCCShape(const void *shape) +GFace *GModel::getFaceForOCCShape(const void *shape) { if(!_occ_internals) return 0; #if defined(HAVE_OCC) - return _occ_internals->getFaceForOCCShape(this, *(TopoDS_Face*)shape); + return _occ_internals->getFaceForOCCShape(this, *(TopoDS_Face *)shape); #else return 0; #endif } -GRegion* GModel::getRegionForOCCShape(const void *shape) +GRegion *GModel::getRegionForOCCShape(const void *shape) { if(!_occ_internals) return 0; #if defined(HAVE_OCC) - return _occ_internals->getRegionForOCCShape(this, *(TopoDS_Solid*)shape); + return _occ_internals->getRegionForOCCShape(this, *(TopoDS_Solid *)shape); #else return 0; #endif diff --git a/Geo/GModelIO_OCC.h b/Geo/GModelIO_OCC.h index 23f11bcc46e7f8e06b98168065df1f81abc2e933..9f04b036192ebd97223ac7cdf864a944adb91045 100644 --- a/Geo/GModelIO_OCC.h +++ b/Geo/GModelIO_OCC.h @@ -35,10 +35,10 @@ class BRepBuilderAPI_GTransform; class OCCMeshAttributesRTree; class OCC_Internals { - public: +public: enum BooleanOperator { Union, Intersection, Difference, Section, Fragments }; - private : +private: // have the internals changed since the last synchronisation? bool _changed; @@ -114,7 +114,8 @@ class OCC_Internals { // apply a geometrical transformation bool _transform(const std::vector<std::pair<int, int> > &inDimTags, - BRepBuilderAPI_Transform *tfo, BRepBuilderAPI_GTransform *gtfo); + BRepBuilderAPI_Transform *tfo, + BRepBuilderAPI_GTransform *gtfo); // add circle or ellipse arc bool _addArc(int &tag, int startTag, int centerTag, int endTag, int mode); @@ -144,13 +145,14 @@ class OCC_Internals { // set extruded mesh attributes void _setExtrudedMeshAttributes(const TopoDS_Compound &c, BRepSweep_Prism *p, BRepSweep_Revol *r, ExtrudeParams *e, - double x, double y, double z, - double dx, double dy, double dz, - double ax, double ay, double az, double angle); + double x, double y, double z, double dx, + double dy, double dz, double ax, double ay, + double az, double angle); void _copyExtrudedMeshAttributes(TopoDS_Edge edge, GEdge *ge); void _copyExtrudedMeshAttributes(TopoDS_Face face, GFace *gf); void _copyExtrudedMeshAttributes(TopoDS_Solid solid, GRegion *gr); - public: + +public: OCC_Internals(); ~OCC_Internals(); @@ -183,41 +185,44 @@ class OCC_Internals { int getMaxTag(int dim) const; // add shapes (if tag is < 0, a new tag is automatically created and returned) - bool addVertex(int &tag, double x, double y, double z, double meshSize = MAX_LC); + bool addVertex(int &tag, double x, double y, double z, + double meshSize = MAX_LC); bool addLine(int &tag, int startTag, int endTag); bool addLine(int &tag, const std::vector<int> &pointTags); bool addCircleArc(int &tag, int startTag, int centerTag, int endTag); - bool addCircle(int &tag, double x, double y, double z, double r, double angle1, - double angle2); + bool addCircle(int &tag, double x, double y, double z, double r, + double angle1, double angle2); bool addEllipseArc(int &tag, int startTag, int centerTag, int endTag); bool addEllipse(int &tag, double x, double y, double z, double r1, double r2, double angle1, double angle2); bool addSpline(int &tag, const std::vector<int> &pointTags); bool addBezier(int &tag, const std::vector<int> &pointTags); - bool addBSpline(int &tag, const std::vector<int> &pointTags, const int degree = -1, - const std::vector<double> &weights = std::vector<double>(), - const std::vector<double> &knots = std::vector<double>(), - const std::vector<int> &multiplicities = std::vector<int>()); + bool addBSpline(int &tag, const std::vector<int> &pointTags, + const int degree = -1, + const std::vector<double> &weights = std::vector<double>(), + const std::vector<double> &knots = std::vector<double>(), + const std::vector<int> &multiplicities = std::vector<int>()); bool addWire(int &tag, const std::vector<int> &curveTags, bool checkClosed); bool addLineLoop(int &tag, const std::vector<int> &curveTags); - bool addRectangle(int &tag, double x, double y, double z, - double dx, double dy, double roundedRadius = 0.); + bool addRectangle(int &tag, double x, double y, double z, double dx, + double dy, double roundedRadius = 0.); bool addDisk(int &tag, double xc, double yc, double zc, double rx, double ry); bool addPlaneSurface(int &tag, const std::vector<int> &wireTags); - bool addSurfaceFilling(int &tag, int wireTag, - const std::vector<int> &pointTags = std::vector<int>(), - const std::vector<int> &surfaceTags = std::vector<int>(), - const std::vector<int> &surfaceContinuity = std::vector<int>()); + bool addSurfaceFilling( + int &tag, int wireTag, + const std::vector<int> &pointTags = std::vector<int>(), + const std::vector<int> &surfaceTags = std::vector<int>(), + const std::vector<int> &surfaceContinuity = std::vector<int>()); bool addSurfaceLoop(int &tag, const std::vector<int> &surfaceTags); bool addVolume(int &tag, const std::vector<int> &shellTags); bool addSphere(int &tag, double xc, double yc, double zc, double radius, double angle1, double angle2, double angle3); - bool addBox(int &tag, double x, double y, double z, - double dx, double dy, double dz); - bool addCylinder(int &tag, double x, double y, double z, - double dx, double dy, double dz, double r, double angle); - bool addCone(int &tag, double x, double y, double z, - double dx, double dy, double dz, double r1, double r2, double angle); + bool addBox(int &tag, double x, double y, double z, double dx, double dy, + double dz); + bool addCylinder(int &tag, double x, double y, double z, double dx, double dy, + double dz, double r, double angle); + bool addCone(int &tag, double x, double y, double z, double dx, double dy, + double dz, double r1, double r2, double angle); bool addWedge(int &tag, double x, double y, double z, double dx, double dy, double dz, double ltx); bool addTorus(int &tag, double x, double y, double z, double r1, double r2, @@ -227,16 +232,17 @@ class OCC_Internals { bool addThruSections(int tag, const std::vector<int> &wireTags, bool makeSolid, bool makeRuled, std::vector<std::pair<int, int> > &outDimTags); - bool addThickSolid(int tag, int solidTag, const std::vector<int> &excludeFaceTags, - double offset, std::vector<std::pair<int, int> > &outDimTags); + bool addThickSolid(int tag, int solidTag, + const std::vector<int> &excludeFaceTags, double offset, + std::vector<std::pair<int, int> > &outDimTags); // extrude and revolve - bool extrude(const std::vector<std::pair<int, int> > &inDimTags, - double dx, double dy, double dz, + bool extrude(const std::vector<std::pair<int, int> > &inDimTags, double dx, + double dy, double dz, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e = 0); - bool revolve(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, double ax, double ay, double az, + bool revolve(const std::vector<std::pair<int, int> > &inDimTags, double x, + double y, double z, double ax, double ay, double az, double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e = 0); bool addPipe(const std::vector<std::pair<int, int> > &inDimTags, int wireTag, @@ -246,8 +252,7 @@ class OCC_Internals { bool fillet(const std::vector<int> &volumeTags, const std::vector<int> &curveTags, const std::vector<double> &radii, - std::vector<std::pair<int, int> > &outDimTags, - bool removeVolume); + std::vector<std::pair<int, int> > &outDimTags, bool removeVolume); // chamfer bool chamfer(const std::vector<int> &volumeTags, @@ -258,58 +263,59 @@ class OCC_Internals { bool removeVolume); // apply boolean operator - bool booleanOperator(int tag, BooleanOperator op, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool); - bool booleanUnion(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool); - bool booleanIntersection(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool); - bool booleanDifference(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool); - bool booleanFragments(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool); + bool booleanOperator( + int tag, BooleanOperator op, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool); + bool + booleanUnion(int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool); + bool booleanIntersection( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool); + bool booleanDifference( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool); + bool booleanFragments( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool); // coherence (shortcut for booleanFragments) void removeAllDuplicates(); bool mergeVertices(const std::vector<int> &tags); // apply transformations - bool translate(const std::vector<std::pair<int, int> > &inDimTags, - double dx, double dy, double dz); - bool rotate(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, double ax, double ay, double az, + bool translate(const std::vector<std::pair<int, int> > &inDimTags, double dx, + double dy, double dz); + bool rotate(const std::vector<std::pair<int, int> > &inDimTags, double x, + double y, double z, double ax, double ay, double az, double angle); - bool dilate(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double a, double b, double c); - bool symmetry(const std::vector<std::pair<int, int> > &inDimTags, - double a, double b, double c, double d); + bool dilate(const std::vector<std::pair<int, int> > &inDimTags, double x, + double y, double z, double a, double b, double c); + bool symmetry(const std::vector<std::pair<int, int> > &inDimTags, double a, + double b, double c, double d); // copy and remove bool copy(const std::vector<std::pair<int, int> > &inDimTags, std::vector<std::pair<int, int> > &outDimTags); bool remove(int dim, int tag, bool recursive = false); - bool remove(const std::vector<std::pair<int, int> > &dimTags, bool recursive = false); + bool remove(const std::vector<std::pair<int, int> > &dimTags, + bool recursive = false); // import shapes from file bool importShapes(const std::string &fileName, bool highestDimOnly, @@ -321,7 +327,8 @@ class OCC_Internals { std::vector<std::pair<int, int> > &outDimTags); // export all bound shapes to file - bool exportShapes(const std::string &fileName, const std::string &format = ""); + bool exportShapes(const std::string &fileName, + const std::string &format = ""); // set meshing constraints void setMeshSize(int dim, int tag, double size); @@ -340,8 +347,8 @@ class OCC_Internals { bool makeFaceSTL(TopoDS_Face s, std::vector<SPoint2> &vertices_uv, std::vector<int> &triangles); bool makeFaceSTL(TopoDS_Face s, std::vector<SPoint2> &vertices_uv, - std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, - std::vector<int> &triangles); + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, std::vector<int> &triangles); bool makeFaceSTL(TopoDS_Face s, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles); bool makeSolidSTL(const TopoDS_Solid &s, std::vector<SPoint3> &vertices, @@ -349,27 +356,35 @@ class OCC_Internals { std::vector<int> &triangles); bool makeRectangleSTL(double x, double y, double z, double dx, double dy, double roundedRadius, std::vector<SPoint3> &vertices, - std::vector<SVector3> &normals, std::vector<int> &triangles); + std::vector<SVector3> &normals, + std::vector<int> &triangles); bool makeDiskSTL(double xc, double yc, double zc, double rx, double ry, - std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, - std::vector<int> &triangles); - bool makeSphereSTL(double xc, double yc, double zc, double radius, double angle1, - double angle2, double angle3, std::vector<SPoint3> &vertices, - std::vector<SVector3> &normals, std::vector<int> &triangles); + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, std::vector<int> &triangles); + bool makeSphereSTL(double xc, double yc, double zc, double radius, + double angle1, double angle2, double angle3, + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, + std::vector<int> &triangles); bool makeBoxSTL(double x, double y, double z, double dx, double dy, double dz, - std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, - std::vector<int> &triangles); - bool makeCylinderSTL(double x, double y, double z, double dx, double dy, double dz, - double r, double angle, std::vector<SPoint3> &vertices, - std::vector<SVector3> &normals, std::vector<int> &triangles); - bool makeConeSTL(double x, double y, double z, double dx, double dy, double dz, - double r1, double r2, double angle, std::vector<SPoint3> &vertices, + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, std::vector<int> &triangles); + bool makeCylinderSTL(double x, double y, double z, double dx, double dy, + double dz, double r, double angle, + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, + std::vector<int> &triangles); + bool makeConeSTL(double x, double y, double z, double dx, double dy, + double dz, double r1, double r2, double angle, + std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles); - bool makeWedgeSTL(double x, double y, double z, double dx, double dy, double dz, - double ltx, std::vector<SPoint3> &vertices, - std::vector<SVector3> &normals, std::vector<int> &triangles); - bool makeTorusSTL(double x, double y, double z, double r1, double r2, double angle, - std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, + bool makeWedgeSTL(double x, double y, double z, double dx, double dy, + double dz, double ltx, std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, + std::vector<int> &triangles); + bool makeTorusSTL(double x, double y, double z, double r1, double r2, + double angle, std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, std::vector<int> &triangles); }; @@ -382,14 +397,16 @@ private: Msg::Error("Gmsh requires OpenCASCADE to %s", what.c_str()); return false; } + public: enum BooleanOperator { Union, Intersection, Difference, Section, Fragments }; - OCC_Internals(){} + OCC_Internals() {} bool getChanged() const { return false; } - void reset(){} - void setMaxTag(int dim, int val){} + void reset() {} + void setMaxTag(int dim, int val) {} int getMaxTag(int dim) const { return 0; } - bool addVertex(int &tag, double x, double y, double z, double meshSize = MAX_LC) + bool addVertex(int &tag, double x, double y, double z, + double meshSize = MAX_LC) { return _error("add vertex"); } @@ -405,8 +422,8 @@ public: { return _error("add circle arc"); } - bool addCircle(int &tag, double x, double y, double z, double r, double angle1, - double angle2) + bool addCircle(int &tag, double x, double y, double z, double r, + double angle1, double angle2) { return _error("add circle"); } @@ -427,10 +444,11 @@ public: { return _error("add Bezier"); } - bool addBSpline(int &tag, const std::vector<int> &pointTags, const int degree = -1, - const std::vector<double> &weights = std::vector<double>(), - const std::vector<double> &knots = std::vector<double>(), - const std::vector<int> &multiplicities = std::vector<int>()) + bool addBSpline(int &tag, const std::vector<int> &pointTags, + const int degree = -1, + const std::vector<double> &weights = std::vector<double>(), + const std::vector<double> &knots = std::vector<double>(), + const std::vector<int> &multiplicities = std::vector<int>()) { return _error("add BSpline"); } @@ -442,8 +460,8 @@ public: { return _error("add line loop"); } - bool addRectangle(int &tag, double x, double y, double z, - double dx, double dy, double roundedRadius = 0.) + bool addRectangle(int &tag, double x, double y, double z, double dx, + double dy, double roundedRadius = 0.) { return _error("add rectangle"); } @@ -455,10 +473,11 @@ public: { return _error("add plane surface"); } - bool addSurfaceFilling(int &tag, int wireTag, - const std::vector<int> &pointTags = std::vector<int>(), - const std::vector<int> &surfaceTags = std::vector<int>(), - const std::vector<int> &surfaceContinuity = std::vector<int>()) + bool addSurfaceFilling( + int &tag, int wireTag, + const std::vector<int> &pointTags = std::vector<int>(), + const std::vector<int> &surfaceTags = std::vector<int>(), + const std::vector<int> &surfaceContinuity = std::vector<int>()) { return _error("add surface filling"); } @@ -475,25 +494,26 @@ public: { return _error("add sphere"); } - bool addBox(int &tag, double x, double y, double z, - double dx, double dy, double dz) + bool addBox(int &tag, double x, double y, double z, double dx, double dy, + double dz) { return _error("add block"); } - bool addCylinder(int &tag, double x, double y, double z, - double dx, double dy, double dz, double r, double angle) + bool addCylinder(int &tag, double x, double y, double z, double dx, double dy, + double dz, double r, double angle) { return _error("add cylinder"); } - bool addCone(int &tag, double x, double y, double z, - double dx, double dy, double dz, double r1, double r2, double angle) + bool addCone(int &tag, double x, double y, double z, double dx, double dy, + double dz, double r1, double r2, double angle) { return _error("add cone"); } bool addWedge(int &tag, double x, double y, double z, double dx, double dy, double dz, double ltx) - { return _error("add wedge"); + { + return _error("add wedge"); } bool addTorus(int &tag, double x, double y, double z, double r1, double r2, double angle) @@ -506,20 +526,21 @@ public: { return _error("add thrusection"); } - bool addThickSolid(int tag, int solidTag, const std::vector<int> &excludeFaceTags, - double offset, std::vector<std::pair<int, int> > &outDimTags) + bool addThickSolid(int tag, int solidTag, + const std::vector<int> &excludeFaceTags, double offset, + std::vector<std::pair<int, int> > &outDimTags) { return _error("add thick solid"); } - bool extrude(const std::vector<std::pair<int, int> > &inDimTags, - double dx, double dy, double dz, + bool extrude(const std::vector<std::pair<int, int> > &inDimTags, double dx, + double dy, double dz, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e = 0) { return _error("extrude"); } - bool revolve(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, double ax, double ay, double az, + bool revolve(const std::vector<std::pair<int, int> > &inDimTags, double x, + double y, double z, double ax, double ay, double az, double angle, std::vector<std::pair<int, int> > &outDimTags, ExtrudeParams *e = 0) { @@ -533,8 +554,7 @@ public: bool fillet(const std::vector<int> &volumeTags, const std::vector<int> &curveTags, const std::vector<double> &radii, - std::vector<std::pair<int, int> > &outDimTags, - bool removeVolume) + std::vector<std::pair<int, int> > &outDimTags, bool removeVolume) { return _error("create fillet"); } @@ -542,83 +562,78 @@ public: const std::vector<int> &curveTags, const std::vector<int> &surfaceTags, const std::vector<double> &distances, - std::vector<std::pair<int, int> > &outDimTags, - bool removeVolume) + std::vector<std::pair<int, int> > &outDimTags, bool removeVolume) { return _error("create chamfer"); } - bool booleanOperator(int tag, BooleanOperator op, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) + bool booleanOperator( + int tag, BooleanOperator op, + const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { return _error("apply boolean operator"); } - bool booleanUnion(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) + bool + booleanUnion(int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { return _error("apply boolean union"); } - bool booleanIntersection(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) + bool booleanIntersection( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { return _error("apply boolean intersection"); } - bool booleanDifference(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) + bool booleanDifference( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { return _error("apply boolean difference"); } - bool booleanFragments(int tag, - const std::vector<std::pair<int, int> > &objectDimTags, - const std::vector<std::pair<int, int> > &toolDimTags, - std::vector<std::pair<int, int> > &outDimTags, - std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, - bool removeObject, bool removeTool) + bool booleanFragments( + int tag, const std::vector<std::pair<int, int> > &objectDimTags, + const std::vector<std::pair<int, int> > &toolDimTags, + std::vector<std::pair<int, int> > &outDimTags, + std::vector<std::vector<std::pair<int, int> > > &outDimTagsMap, + bool removeObject, bool removeTool) { return _error("apply boolean fragments"); } - void removeAllDuplicates() - { - _error("remove all duplicates"); - } + void removeAllDuplicates() { _error("remove all duplicates"); } bool mergeVertices(const std::vector<int> &tags) { return _error("merge vertices"); } - bool translate(const std::vector<std::pair<int, int> > &inDimTags, - double dx, double dy, double dz) + bool translate(const std::vector<std::pair<int, int> > &inDimTags, double dx, + double dy, double dz) { return _error("apply translation"); } - bool rotate(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, double ax, double ay, double az, - double angle) + bool rotate(const std::vector<std::pair<int, int> > &inDimTags, double x, + double y, double z, double ax, double ay, double az, double angle) { return _error("apply rotation"); } - bool dilate(const std::vector<std::pair<int, int> > &inDimTags, - double x, double y, double z, - double a, double b, double c) + bool dilate(const std::vector<std::pair<int, int> > &inDimTags, double x, + double y, double z, double a, double b, double c) { return _error("apply dilatation"); } - bool symmetry(const std::vector<std::pair<int, int> > &inDimTags, - double a, double b, double c, double d) + bool symmetry(const std::vector<std::pair<int, int> > &inDimTags, double a, + double b, double c, double d) { return _error("apply symmetry"); } @@ -627,11 +642,9 @@ public: { return _error("copy shape"); } - bool remove(int dim, int tag, bool recursive = false) - { - return false; - } - bool remove(const std::vector<std::pair<int, int> > &dimTags, bool recursive = false) + bool remove(int dim, int tag, bool recursive = false) { return false; } + bool remove(const std::vector<std::pair<int, int> > &dimTags, + bool recursive = false) { return false; } @@ -645,54 +658,60 @@ public: { return _error("export shape"); } - void setMeshSize(int dim, int tag, double size){} - void synchronize(GModel *model){} - bool getVertex(int tag, double &x, double &y, double &z){ return false; } + void setMeshSize(int dim, int tag, double size) {} + void synchronize(GModel *model) {} + bool getVertex(int tag, double &x, double &y, double &z) { return false; } bool makeRectangleSTL(double x, double y, double z, double dx, double dy, double roundedRadius, std::vector<SPoint3> &vertices, - std::vector<SVector3> &normals, std::vector<int> &triangles) + std::vector<SVector3> &normals, + std::vector<int> &triangles) { return false; } bool makeDiskSTL(double xc, double yc, double zc, double rx, double ry, - std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, - std::vector<int> &triangles) + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, std::vector<int> &triangles) { return false; } - bool makeSphereSTL(double xc, double yc, double zc, double radius, double angle1, - double angle2, double angle3, std::vector<SPoint3> &vertices, - std::vector<SVector3> &normals, std::vector<int> &triangles) + bool makeSphereSTL(double xc, double yc, double zc, double radius, + double angle1, double angle2, double angle3, + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, + std::vector<int> &triangles) { return false; } bool makeBoxSTL(double x, double y, double z, double dx, double dy, double dz, - std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, - std::vector<int> &triangles) + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, std::vector<int> &triangles) { return false; } - bool makeCylinderSTL(double x, double y, double z, double dx, double dy, double dz, - double r, double angle, std::vector<SPoint3> &vertices, - std::vector<SVector3> &normals, std::vector<int> &triangles) + bool makeCylinderSTL(double x, double y, double z, double dx, double dy, + double dz, double r, double angle, + std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, + std::vector<int> &triangles) { return false; } - bool makeConeSTL(double x, double y, double z, double dx, double dy, double dz, - double r1, double r2, double angle, std::vector<SPoint3> &vertices, + bool makeConeSTL(double x, double y, double z, double dx, double dy, + double dz, double r1, double r2, double angle, + std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { return false; } - bool makeWedgeSTL(double x, double y, double z, double dx, double dy, double dz, - double ltx, std::vector<SPoint3> &vertices, + bool makeWedgeSTL(double x, double y, double z, double dx, double dy, + double dz, double ltx, std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, std::vector<int> &triangles) { return false; } - bool makeTorusSTL(double x, double y, double z, double r1, double r2, double angle, - std::vector<SPoint3> &vertices, std::vector<SVector3> &normals, - std::vector<int> &triangles) + bool makeTorusSTL(double x, double y, double z, double r1, double r2, + double angle, std::vector<SPoint3> &vertices, + std::vector<SVector3> &normals, std::vector<int> &triangles) { return false; } diff --git a/Geo/GModelIO_P3D.cpp b/Geo/GModelIO_P3D.cpp index 38e5c44dec0325854fd2e12305cb6d350db3e509..1827f5d0dc26f72f9a2cb6780edee87bdd3adf47 100644 --- a/Geo/GModelIO_P3D.cpp +++ b/Geo/GModelIO_P3D.cpp @@ -13,39 +13,47 @@ int GModel::readP3D(const std::string &name) { FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } int numBlocks = 0; - if(fscanf(fp, "%d", &numBlocks) != 1 || numBlocks <= 0){ fclose(fp); return 0; } + if(fscanf(fp, "%d", &numBlocks) != 1 || numBlocks <= 0) { + fclose(fp); + return 0; + } std::vector<int> Ni(numBlocks), Nj(numBlocks), Nk(numBlocks); for(int n = 0; n < numBlocks; n++) - if(fscanf(fp, "%d %d %d", &Ni[n], &Nj[n], &Nk[n]) != 3){ fclose(fp); return 0; } + if(fscanf(fp, "%d %d %d", &Ni[n], &Nj[n], &Nk[n]) != 3) { + fclose(fp); + return 0; + } - for(int n = 0; n < numBlocks; n++){ - if(Nk[n] == 1){ + for(int n = 0; n < numBlocks; n++) { + if(Nk[n] == 1) { GFace *gf = new discreteFace(this, getMaxElementaryNumber(2) + 1); add(gf); gf->transfinite_vertices.resize(Ni[n]); - for(int i = 0; i < Ni[n]; i++) - gf->transfinite_vertices[i].resize(Nj[n]); - for(int coord = 0; coord < 3; coord++){ - for(int j = 0; j < Nj[n]; j++){ - for(int i = 0; i < Ni[n]; i++){ + for(int i = 0; i < Ni[n]; i++) gf->transfinite_vertices[i].resize(Nj[n]); + for(int coord = 0; coord < 3; coord++) { + for(int j = 0; j < Nj[n]; j++) { + for(int i = 0; i < Ni[n]; i++) { double d; - if(fscanf(fp, "%lf", &d) != 1){ fclose(fp); return 0; } - if(coord == 0){ + if(fscanf(fp, "%lf", &d) != 1) { + fclose(fp); + return 0; + } + if(coord == 0) { MVertex *v = new MVertex(d, 0., 0., gf); gf->transfinite_vertices[i][j] = v; gf->mesh_vertices.push_back(v); } - else if(coord == 1){ + else if(coord == 1) { gf->transfinite_vertices[i][j]->y() = d; } - else if(coord == 2){ + else if(coord == 2) { gf->transfinite_vertices[i][j]->z() = d; } } @@ -53,37 +61,39 @@ int GModel::readP3D(const std::string &name) } for(unsigned int i = 0; i < gf->transfinite_vertices.size() - 1; i++) for(unsigned int j = 0; j < gf->transfinite_vertices[0].size() - 1; j++) - gf->quadrangles.push_back - (new MQuadrangle(gf->transfinite_vertices[i ][j ], - gf->transfinite_vertices[i + 1][j ], - gf->transfinite_vertices[i + 1][j + 1], - gf->transfinite_vertices[i ][j + 1])); + gf->quadrangles.push_back(new MQuadrangle( + gf->transfinite_vertices[i][j], gf->transfinite_vertices[i + 1][j], + gf->transfinite_vertices[i + 1][j + 1], + gf->transfinite_vertices[i][j + 1])); } - else{ - GRegion *gr = new discreteRegion(this, getMaxElementaryNumber(3) + 1); + else { + GRegion *gr = new discreteRegion(this, getMaxElementaryNumber(3) + 1); add(gr); gr->transfinite_vertices.resize(Ni[n]); - for(int i = 0; i < Ni[n]; i++){ + for(int i = 0; i < Ni[n]; i++) { gr->transfinite_vertices[i].resize(Nj[n]); - for(int j = 0; j < Nj[n]; j++){ + for(int j = 0; j < Nj[n]; j++) { gr->transfinite_vertices[i][j].resize(Nk[n]); } } - for(int coord = 0; coord < 3; coord++){ - for(int k = 0; k < Nk[n]; k++){ - for(int j = 0; j < Nj[n]; j++){ - for(int i = 0; i < Ni[n]; i++){ + for(int coord = 0; coord < 3; coord++) { + for(int k = 0; k < Nk[n]; k++) { + for(int j = 0; j < Nj[n]; j++) { + for(int i = 0; i < Ni[n]; i++) { double d; - if(fscanf(fp, "%lf", &d) != 1){ fclose(fp); return 0; } - if(coord == 0){ + if(fscanf(fp, "%lf", &d) != 1) { + fclose(fp); + return 0; + } + if(coord == 0) { MVertex *v = new MVertex(d, 0., 0., gr); gr->transfinite_vertices[i][j][k] = v; gr->mesh_vertices.push_back(v); } - else if(coord == 1){ + else if(coord == 1) { gr->transfinite_vertices[i][j][k]->y() = d; } - else if(coord == 2){ + else if(coord == 2) { gr->transfinite_vertices[i][j][k]->z() = d; } } @@ -92,16 +102,17 @@ int GModel::readP3D(const std::string &name) } for(unsigned int i = 0; i < gr->transfinite_vertices.size() - 1; i++) for(unsigned int j = 0; j < gr->transfinite_vertices[0].size() - 1; j++) - for(unsigned int k = 0; k < gr->transfinite_vertices[0][0].size() - 1; k++) - gr->hexahedra.push_back - (new MHexahedron(gr->transfinite_vertices[i ][j ][k ], - gr->transfinite_vertices[i + 1][j ][k ], - gr->transfinite_vertices[i + 1][j + 1][k ], - gr->transfinite_vertices[i ][j + 1][k ], - gr->transfinite_vertices[i ][j ][k + 1], - gr->transfinite_vertices[i + 1][j ][k + 1], - gr->transfinite_vertices[i + 1][j + 1][k + 1], - gr->transfinite_vertices[i ][j + 1][k + 1])); + for(unsigned int k = 0; k < gr->transfinite_vertices[0][0].size() - 1; + k++) + gr->hexahedra.push_back( + new MHexahedron(gr->transfinite_vertices[i][j][k], + gr->transfinite_vertices[i + 1][j][k], + gr->transfinite_vertices[i + 1][j + 1][k], + gr->transfinite_vertices[i][j + 1][k], + gr->transfinite_vertices[i][j][k + 1], + gr->transfinite_vertices[i + 1][j][k + 1], + gr->transfinite_vertices[i + 1][j + 1][k + 1], + gr->transfinite_vertices[i][j + 1][k + 1])); } } @@ -109,30 +120,33 @@ int GModel::readP3D(const std::string &name) return 1; } -int GModel::writeP3D(const std::string &name, bool saveAll, double scalingFactor) +int GModel::writeP3D(const std::string &name, bool saveAll, + double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } if(noPhysicalGroups()) saveAll = true; - std::vector<GFace*> faces; + std::vector<GFace *> faces; for(fiter it = firstFace(); it != lastFace(); ++it) if((*it)->transfinite_vertices.size() && (*it)->transfinite_vertices[0].size() && - ((*it)->physicals.size() || saveAll)) faces.push_back(*it); + ((*it)->physicals.size() || saveAll)) + faces.push_back(*it); - std::vector<GRegion*> regions; + std::vector<GRegion *> regions; for(riter it = firstRegion(); it != lastRegion(); ++it) if((*it)->transfinite_vertices.size() && (*it)->transfinite_vertices[0].size() && (*it)->transfinite_vertices[0][0].size() && - ((*it)->physicals.size() || saveAll)) regions.push_back(*it); + ((*it)->physicals.size() || saveAll)) + regions.push_back(*it); - if(faces.empty() && regions.empty()){ + if(faces.empty() && regions.empty()) { Msg::Warning("No structured grids to save"); fclose(fp); return 0; @@ -141,21 +155,19 @@ int GModel::writeP3D(const std::string &name, bool saveAll, double scalingFactor fprintf(fp, "%d\n", (int)(faces.size() + regions.size())); for(unsigned int i = 0; i < faces.size(); i++) - fprintf(fp, "%d %d 1\n", - (int)faces[i]->transfinite_vertices.size(), + fprintf(fp, "%d %d 1\n", (int)faces[i]->transfinite_vertices.size(), (int)faces[i]->transfinite_vertices[0].size()); for(unsigned int i = 0; i < regions.size(); i++) - fprintf(fp, "%d %d %d\n", - (int)regions[i]->transfinite_vertices.size(), + fprintf(fp, "%d %d %d\n", (int)regions[i]->transfinite_vertices.size(), (int)regions[i]->transfinite_vertices[0].size(), (int)regions[i]->transfinite_vertices[0][0].size()); - for(unsigned int i = 0; i < faces.size(); i++){ + for(unsigned int i = 0; i < faces.size(); i++) { GFace *gf = faces[i]; - for(int coord = 0; coord < 3; coord++){ - for(unsigned int k = 0; k < gf->transfinite_vertices[0].size(); k++){ - for(unsigned int j = 0; j < gf->transfinite_vertices.size(); j++){ + for(int coord = 0; coord < 3; coord++) { + for(unsigned int k = 0; k < gf->transfinite_vertices[0].size(); k++) { + for(unsigned int j = 0; j < gf->transfinite_vertices.size(); j++) { MVertex *v = gf->transfinite_vertices[j][k]; double d = (coord == 0) ? v->x() : (coord == 1) ? v->y() : v->z(); fprintf(fp, "%.16g ", d * scalingFactor); @@ -165,12 +177,12 @@ int GModel::writeP3D(const std::string &name, bool saveAll, double scalingFactor } } - for(unsigned int i = 0; i < regions.size(); i++){ + for(unsigned int i = 0; i < regions.size(); i++) { GRegion *gr = regions[i]; - for(int coord = 0; coord < 3; coord++){ - for(unsigned int l = 0; l < gr->transfinite_vertices[0][0].size(); l++){ - for(unsigned int k = 0; k < gr->transfinite_vertices[0].size(); k++){ - for(unsigned int j = 0; j < gr->transfinite_vertices.size(); j++){ + for(int coord = 0; coord < 3; coord++) { + for(unsigned int l = 0; l < gr->transfinite_vertices[0][0].size(); l++) { + for(unsigned int k = 0; k < gr->transfinite_vertices[0].size(); k++) { + for(unsigned int j = 0; j < gr->transfinite_vertices.size(); j++) { MVertex *v = gr->transfinite_vertices[j][k][l]; double d = (coord == 0) ? v->x() : (coord == 1) ? v->y() : v->z(); fprintf(fp, "%.16g ", d * scalingFactor); @@ -184,4 +196,3 @@ int GModel::writeP3D(const std::string &name, bool saveAll, double scalingFactor fclose(fp); return 1; } - diff --git a/Geo/GModelIO_PLY.cpp b/Geo/GModelIO_PLY.cpp index 67b66ff1a7f3ebe2d04eccbc0892e5d389d13cc7..8ad3ef8ab051f87822740a937d192475bb4a0abc 100644 --- a/Geo/GModelIO_PLY.cpp +++ b/Geo/GModelIO_PLY.cpp @@ -15,11 +15,11 @@ #include "PViewDataList.h" #endif -static bool getMeshVertices(int num, int *indices, std::vector<MVertex*> &vec, - std::vector<MVertex*> &vertices) +static bool getMeshVertices(int num, int *indices, std::vector<MVertex *> &vec, + std::vector<MVertex *> &vertices) { - for(int i = 0; i < num; i++){ - if(indices[i] < 0 || indices[i] > (int)(vec.size() - 1)){ + for(int i = 0; i < num; i++) { + if(indices[i] < 0 || indices[i] > (int)(vec.size() - 1)) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -39,10 +39,10 @@ static void replaceCommaByDot(const std::string &name) } static bool getProperties(int num, int *indices, std::vector<double> &vec, - std::vector<double> &properties) + std::vector<double> &properties) { - for(int i = 0; i < num; i++){ - if(indices[i] < 0 || indices[i] > (int)(vec.size() - 1)){ + for(int i = 0; i < num; i++) { + if(indices[i] < 0 || indices[i] > (int)(vec.size() - 1)) { Msg::Error("Wrong vertex index %d", indices[i]); return false; } @@ -58,13 +58,13 @@ int GModel::readPLY(const std::string &name) replaceCommaByDot(name); FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } - std::vector<MVertex*> vertexVector; - std::map<int, std::vector<MElement*> > elements[5]; + std::vector<MVertex *> vertexVector; + std::map<int, std::vector<MElement *> > elements[5]; std::map<int, std::vector<double> > properties; char buffer[256], str[256], str2[256], str3[256]; @@ -76,60 +76,64 @@ int GModel::readPLY(const std::string &name) std::vector<std::string> propName; while(!feof(fp)) { if(!fgets(buffer, sizeof(buffer), fp)) break; - if(buffer[0] != '#'){ // skip comments + if(buffer[0] != '#') { // skip comments sscanf(buffer, "%s %s", str, str2); - if(!strcmp(str, "element") && !strcmp(str2, "vertex")){ - sscanf(buffer, "%s %s %d", str, str2, &nbv); + if(!strcmp(str, "element") && !strcmp(str2, "vertex")) { + sscanf(buffer, "%s %s %d", str, str2, &nbv); } - if(!strcmp(str, "format") && strcmp(str2, "ascii")){ - Msg::Error("Only reading of ascii PLY files implemented"); + if(!strcmp(str, "format") && strcmp(str2, "ascii")) { + Msg::Error("Only reading of ascii PLY files implemented"); fclose(fp); - return 0; + return 0; } - if(!strcmp(str, "property") && strcmp(str2, "list")){ - nbprop++; - sscanf(buffer, "%s %s %s", str, str2, str3); - if (nbprop > 3) propName.push_back(s1+str3); + if(!strcmp(str, "property") && strcmp(str2, "list")) { + nbprop++; + sscanf(buffer, "%s %s %s", str, str2, str3); + if(nbprop > 3) propName.push_back(s1 + str3); } - if(!strcmp(str, "element") && !strcmp(str2, "face")){ - sscanf(buffer, "%s %s %d", str, str2, &nbf); + if(!strcmp(str, "element") && !strcmp(str2, "face")) { + sscanf(buffer, "%s %s %d", str, str2, &nbf); } - if(!strcmp(str, "end_header")){ - nbView = nbprop -3; - Msg::Info("%d elements", nbv); - Msg::Info("%d triangles", nbf); - Msg::Info("%d properties", nbView); + if(!strcmp(str, "end_header")) { + nbView = nbprop - 3; + Msg::Info("%d elements", nbv); + Msg::Info("%d triangles", nbf); + Msg::Info("%d properties", nbView); - vertexVector.resize(nbv); - for(int i = 0; i < nbv; i++) { - double x,y,z; - char line[10000], *pEnd, *pEnd2, *pEnd3; - if(!fgets(line, sizeof(line), fp)){ fclose(fp); return 0; } - x = strtod(line, &pEnd); - y = strtod(pEnd, &pEnd2); - z = strtod(pEnd2, &pEnd3); - vertexVector[i] = new MVertex(x, y, z); + vertexVector.resize(nbv); + for(int i = 0; i < nbv; i++) { + double x, y, z; + char line[10000], *pEnd, *pEnd2, *pEnd3; + if(!fgets(line, sizeof(line), fp)) { + fclose(fp); + return 0; + } + x = strtod(line, &pEnd); + y = strtod(pEnd, &pEnd2); + z = strtod(pEnd2, &pEnd3); + vertexVector[i] = new MVertex(x, y, z); - pEnd = pEnd3; + pEnd = pEnd3; std::vector<double> prop(nbView); - for (int k = 0; k < nbView; k++){ - prop[k]=strtod(pEnd, &pEnd2); - pEnd = pEnd2; - properties[k].push_back(prop[k]); - } - } - - for(int i = 0; i < nbf; i++) { - if(!fgets(buffer, sizeof(buffer), fp)) break; - int n[3], nbe; - sscanf(buffer, "%d %d %d %d", &nbe, &n[0], &n[1], &n[2]); - std::vector<MVertex*> vertices; - if(!getMeshVertices(3, n, vertexVector, vertices)){ fclose(fp); return 0; } - elements[0][elementary].push_back(new MTriangle(vertices)); - } + for(int k = 0; k < nbView; k++) { + prop[k] = strtod(pEnd, &pEnd2); + pEnd = pEnd2; + properties[k].push_back(prop[k]); + } + } + for(int i = 0; i < nbf; i++) { + if(!fgets(buffer, sizeof(buffer), fp)) break; + int n[3], nbe; + sscanf(buffer, "%d %d %d %d", &nbe, &n[0], &n[1], &n[2]); + std::vector<MVertex *> vertices; + if(!getMeshVertices(3, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } + elements[0][elementary].push_back(new MTriangle(vertices)); + } } - } } @@ -140,28 +144,34 @@ int GModel::readPLY(const std::string &name) #if defined(HAVE_POST) // create PViews here - std::vector<GEntity*> _entities; + std::vector<GEntity *> _entities; getEntities(_entities); - for (int iV=0; iV< nbView; iV++){ + for(int iV = 0; iV < nbView; iV++) { PView *view = new PView(); - PViewDataList *data = dynamic_cast<PViewDataList*>(view->getData()); - for(unsigned int ii = 0; ii < _entities.size(); ii++){ - for(unsigned int i = 0; i < _entities[ii]->getNumMeshElements(); i++){ - MElement *e = _entities[ii]->getMeshElement(i); - int numNodes = e->getNumVertices(); - std::vector<double> x(numNodes), y(numNodes), z(numNodes); - std::vector<double> *out = data->incrementList(1, e->getType()); - for(int nod = 0; nod < numNodes; nod++) out->push_back((e->getVertex(nod))->x()); - for(int nod = 0; nod < numNodes; nod++) out->push_back((e->getVertex(nod))->y()); - for(int nod = 0; nod < numNodes; nod++) out->push_back((e->getVertex(nod))->z()); - std::vector<double> props; - int n[3]; - n[0] = e->getVertex(0)->getNum()-1; - n[1] = e->getVertex(1)->getNum()-1; - n[2] = e->getVertex(2)->getNum()-1; - if(!getProperties(3, n, properties[iV], props)){ fclose(fp); return 0; } - for(int nod = 0; nod < numNodes; nod++) out->push_back(props[nod]); - } + PViewDataList *data = dynamic_cast<PViewDataList *>(view->getData()); + for(unsigned int ii = 0; ii < _entities.size(); ii++) { + for(unsigned int i = 0; i < _entities[ii]->getNumMeshElements(); i++) { + MElement *e = _entities[ii]->getMeshElement(i); + int numNodes = e->getNumVertices(); + std::vector<double> x(numNodes), y(numNodes), z(numNodes); + std::vector<double> *out = data->incrementList(1, e->getType()); + for(int nod = 0; nod < numNodes; nod++) + out->push_back((e->getVertex(nod))->x()); + for(int nod = 0; nod < numNodes; nod++) + out->push_back((e->getVertex(nod))->y()); + for(int nod = 0; nod < numNodes; nod++) + out->push_back((e->getVertex(nod))->z()); + std::vector<double> props; + int n[3]; + n[0] = e->getVertex(0)->getNum() - 1; + n[1] = e->getVertex(1)->getNum() - 1; + n[2] = e->getVertex(2)->getNum() - 1; + if(!getProperties(3, n, properties[iV], props)) { + fclose(fp); + return 0; + } + for(int nod = 0; nod < numNodes; nod++) out->push_back(props[nod]); + } } data->setName(propName[iV]); data->Time.push_back(0); @@ -178,20 +188,20 @@ int GModel::readPLY(const std::string &name) int GModel::readPLY2(const std::string &name) { FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } - std::vector<MVertex*> vertexVector; - std::map<int, std::vector<MElement*> > elements[5]; + std::vector<MVertex *> vertexVector; + std::map<int, std::vector<MElement *> > elements[5]; char buffer[256]; int elementary = getMaxElementaryNumber(-1) + 1; int nbv, nbf; while(!feof(fp)) { if(!fgets(buffer, sizeof(buffer), fp)) break; - if(buffer[0] != '#'){ // skip comments + if(buffer[0] != '#') { // skip comments sscanf(buffer, "%d", &nbv); if(!fgets(buffer, sizeof(buffer), fp)) break; sscanf(buffer, "%d", &nbf); @@ -199,32 +209,35 @@ int GModel::readPLY2(const std::string &name) Msg::Info("%d triangles", nbf); vertexVector.resize(nbv); for(int i = 0; i < nbv; i++) { - if(!fgets(buffer, sizeof(buffer), fp)) break; - double x, y, z; - int nb = sscanf(buffer, "%lf %lf %lf", &x, &y, &z); - if (nb !=3){ - if(!fgets(buffer, sizeof(buffer), fp)) break; - sscanf(buffer, "%lf", &y); - if(!fgets(buffer, sizeof(buffer), fp)) break; - sscanf(buffer, "%lf", &z); - } - vertexVector[i] = new MVertex(x, y, z); + if(!fgets(buffer, sizeof(buffer), fp)) break; + double x, y, z; + int nb = sscanf(buffer, "%lf %lf %lf", &x, &y, &z); + if(nb != 3) { + if(!fgets(buffer, sizeof(buffer), fp)) break; + sscanf(buffer, "%lf", &y); + if(!fgets(buffer, sizeof(buffer), fp)) break; + sscanf(buffer, "%lf", &z); + } + vertexVector[i] = new MVertex(x, y, z); } for(int i = 0; i < nbf; i++) { - if(!fgets(buffer, sizeof(buffer), fp)) break; - int n[3], nbe; - int nb = sscanf(buffer, "%d %d %d %d", &nbe, &n[0], &n[1], &n[2]); - if (nb !=4){ - if(!fgets(buffer, sizeof(buffer), fp)) break; - sscanf(buffer, "%d", &n[0]); - if(!fgets(buffer, sizeof(buffer), fp)) break; - sscanf(buffer, "%d", &n[1]); - if(!fgets(buffer, sizeof(buffer), fp)) break; - sscanf(buffer, "%d", &n[2]); - } - std::vector<MVertex*> vertices; - if(!getMeshVertices(3, n, vertexVector, vertices)){ fclose(fp); return 0; } - elements[0][elementary].push_back(new MTriangle(vertices)); + if(!fgets(buffer, sizeof(buffer), fp)) break; + int n[3], nbe; + int nb = sscanf(buffer, "%d %d %d %d", &nbe, &n[0], &n[1], &n[2]); + if(nb != 4) { + if(!fgets(buffer, sizeof(buffer), fp)) break; + sscanf(buffer, "%d", &n[0]); + if(!fgets(buffer, sizeof(buffer), fp)) break; + sscanf(buffer, "%d", &n[1]); + if(!fgets(buffer, sizeof(buffer), fp)) break; + sscanf(buffer, "%d", &n[2]); + } + std::vector<MVertex *> vertices; + if(!getMeshVertices(3, n, vertexVector, vertices)) { + fclose(fp); + return 0; + } + elements[0][elementary].push_back(new MTriangle(vertices)); } } } @@ -241,29 +254,29 @@ int GModel::readPLY2(const std::string &name) int GModel::writePLY2(const std::string &name) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } int numVertices = indexMeshVertices(true); int numTriangles = 0; - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { numTriangles += (*it)->triangles.size(); } fprintf(fp, "%d\n", numVertices); fprintf(fp, "%d\n", numTriangles); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) entities[i]->mesh_vertices[j]->writePLY2(fp); - for(fiter it = firstFace(); it != lastFace(); ++it){ - for(unsigned int i = 0; i < (*it)->triangles.size(); i++) - (*it)->triangles[i]->writePLY2(fp); + for(fiter it = firstFace(); it != lastFace(); ++it) { + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) + (*it)->triangles[i]->writePLY2(fp); } fclose(fp); diff --git a/Geo/GModelIO_POS.cpp b/Geo/GModelIO_POS.cpp index 7559f89c7fcfda77fb5b46d4f28d07cd30661f3d..7235cc76b0613da2f63ba730401f2490485a15bd 100644 --- a/Geo/GModelIO_POS.cpp +++ b/Geo/GModelIO_POS.cpp @@ -10,11 +10,11 @@ int GModel::writePOS(const std::string &name, bool printElementary, bool printElementNumber, bool printSICN, bool printSIGE, - bool printGamma, bool printDisto, - bool saveAll, double scalingFactor) + bool printGamma, bool printDisto, bool saveAll, + double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -38,49 +38,69 @@ int GModel::writePOS(const std::string &name, bool printElementary, bool first = true; std::string names; - if(printElementary){ - if(first) first = false; else names += ","; + if(printElementary) { + if(first) + first = false; + else + names += ","; names += "\"Elementary Entity\""; } - if(printElementNumber){ - if(first) first = false; else names += ","; + if(printElementNumber) { + if(first) + first = false; + else + names += ","; names += "\"Element Number\""; } - if(printSICN){ - if(first) first = false; else names += ","; + if(printSICN) { + if(first) + first = false; + else + names += ","; names += "\"SICN\""; } - if(printSIGE){ - if(first) first = false; else names += ","; + if(printSIGE) { + if(first) + first = false; + else + names += ","; names += "\"SIGE\""; } - if(printGamma){ - if(first) first = false; else names += ","; + if(printGamma) { + if(first) + first = false; + else + names += ","; names += "\"Gamma\""; } - if(printDisto){ - if(first) first = false; else names += ","; + if(printDisto) { + if(first) + first = false; + else + names += ","; names += "\"Disto\""; } - if(names.empty()){ fclose(fp); return 0; } + if(names.empty()) { + fclose(fp); + return 0; + } if(noPhysicalGroups()) saveAll = true; fprintf(fp, "View \"Statistics\" {\n"); - fprintf(fp, "T2(1.e5,30,%d){%s};\n", (1<<16)|(4<<8), names.c_str()); + fprintf(fp, "T2(1.e5,30,%d){%s};\n", (1 << 16) | (4 << 8), names.c_str()); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) if(saveAll || entities[i]->physicals.size()) for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) - entities[i]->getMeshElement(j)->writePOS - (fp, printElementary, printElementNumber, printSICN, printSIGE, - printGamma, printDisto, scalingFactor, entities[i]->tag()); + entities[i]->getMeshElement(j)->writePOS( + fp, printElementary, printElementNumber, printSICN, printSIGE, + printGamma, printDisto, scalingFactor, entities[i]->tag()); fprintf(fp, "};\n"); fclose(fp); return 1; } - diff --git a/Geo/GModelIO_SAMCEF.cpp b/Geo/GModelIO_SAMCEF.cpp index b5b558c0a805a81de49146de48a86a4bed86d7b3..d727d93dfd8924fab45853d5d816748857fac912 100644 --- a/Geo/GModelIO_SAMCEF.cpp +++ b/Geo/GModelIO_SAMCEF.cpp @@ -15,11 +15,12 @@ #include "MHexahedron.h" #include "Context.h" -static bool getMeshVertices(GModel *m, int num, int *n, std::vector<MVertex*> &vec) +static bool getMeshVertices(GModel *m, int num, int *n, + std::vector<MVertex *> &vec) { - for(int i = 0; i < num; i++){ + for(int i = 0; i < num; i++) { MVertex *v = m->getMeshVertexByTag(n[i]); - if(!v){ + if(!v) { Msg::Error("Wrong vertex number %d", n[i]); return false; } @@ -32,32 +33,32 @@ static bool getMeshVertices(GModel *m, int num, int *n, std::vector<MVertex*> &v int GModel::readSAMCEF(const std::string &name) { FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } _vertexMapCache.clear(); - std::map<int, std::vector<MElement*> > elements[2]; + std::map<int, std::vector<MElement *> > elements[2]; char buffer[256], dummy[256]; while(!feof(fp)) { if(!fgets(buffer, 256, fp)) break; - if(!strncmp(buffer, ".NOE", 4)){ + if(!strncmp(buffer, ".NOE", 4)) { while(!feof(fp)) { if(!fgets(buffer, 256, fp)) break; if(buffer[0] == '!') continue; if(buffer[0] == ';') break; int num; double x, y, z; - if(sscanf(buffer, "%s %d %s %lf %s %lf %s %lf", dummy, &num, - dummy, &x, dummy, &y, dummy, &z) != 8) + if(sscanf(buffer, "%s %d %s %lf %s %lf %s %lf", dummy, &num, dummy, &x, + dummy, &y, dummy, &z) != 8) return 0; _vertexMapCache[num] = new MVertex(x, y, z, 0, num); } Msg::Info("Read %d mesh vertices", (int)_vertexMapCache.size()); } - else if(!strncmp(buffer, ".MAI", 4)){ + else if(!strncmp(buffer, ".MAI", 4)) { while(!feof(fp)) { if(!fgets(buffer, 256, fp)) break; if(buffer[0] == '!') continue; @@ -67,17 +68,17 @@ int GModel::readSAMCEF(const std::string &name) int nn = 0; while(s >> word) nn++; int num, reg, n[4]; - std::vector<MVertex*> vertices; - if(nn == 8){ // TRIA3 - if(sscanf(buffer, "%s %d %s %d %s %d %d %d", dummy, &num, - dummy, ®, dummy, &n[0], &n[1], &n[2]) != 8) + std::vector<MVertex *> vertices; + if(nn == 8) { // TRIA3 + if(sscanf(buffer, "%s %d %s %d %s %d %d %d", dummy, &num, dummy, ®, + dummy, &n[0], &n[1], &n[2]) != 8) return 0; if(!getMeshVertices(this, 3, n, vertices)) break; elements[0][reg].push_back(new MTriangle(vertices, num)); } - else if(nn == 9){ // QUAD4 - if(sscanf(buffer, "%s %d %s %d %s %d %d %d %d", dummy, &num, - dummy, ®, dummy, &n[0], &n[1], &n[2], &n[3]) != 9) + else if(nn == 9) { // QUAD4 + if(sscanf(buffer, "%s %d %s %d %s %d %d %d %d", dummy, &num, dummy, + ®, dummy, &n[0], &n[1], &n[2], &n[3]) != 9) return 0; if(!getMeshVertices(this, 4, n, vertices)) break; elements[1][reg].push_back(new MQuadrangle(vertices, num)); diff --git a/Geo/GModelIO_STL.cpp b/Geo/GModelIO_STL.cpp index 4ca2e224363a043c54c83a83e72366fbb3349526..1a667f26773236b2aa047613334e75f0237b1b67 100644 --- a/Geo/GModelIO_STL.cpp +++ b/Geo/GModelIO_STL.cpp @@ -16,7 +16,7 @@ int GModel::readSTL(const std::string &name, double tolerance) { FILE *fp = Fopen(name.c_str(), "rb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -27,22 +27,23 @@ int GModel::readSTL(const std::string &name, double tolerance) // "solid", or binary data header char buffer[256]; - if(!fgets(buffer, sizeof(buffer), fp)){ fclose(fp); return 0; } + if(!fgets(buffer, sizeof(buffer), fp)) { + fclose(fp); + return 0; + } bool binary = strncmp(buffer, "solid", 5) && strncmp(buffer, "SOLID", 5); // ASCII STL - if(!binary){ + if(!binary) { points.resize(1); while(!feof(fp)) { // "facet normal x y z" or "endsolid" if(!fgets(buffer, sizeof(buffer), fp)) break; - if(!strncmp(buffer, "endsolid", 8) || - !strncmp(buffer, "ENDSOLID", 8)){ + if(!strncmp(buffer, "endsolid", 8) || !strncmp(buffer, "ENDSOLID", 8)) { // "solid" if(!fgets(buffer, sizeof(buffer), fp)) break; - if(!strncmp(buffer, "solid", 5) || - !strncmp(buffer, "SOLID", 5)){ + if(!strncmp(buffer, "solid", 5) || !strncmp(buffer, "SOLID", 5)) { points.resize(points.size() + 1); // "facet normal x y z" if(!fgets(buffer, sizeof(buffer), fp)) break; @@ -51,7 +52,7 @@ int GModel::readSTL(const std::string &name, double tolerance) // "outer loop" if(!fgets(buffer, sizeof(buffer), fp)) break; // "vertex x y z" - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { if(!fgets(buffer, sizeof(buffer), fp)) break; char s1[256]; double x, y, z; @@ -65,12 +66,12 @@ int GModel::readSTL(const std::string &name, double tolerance) // "endfacet" if(!fgets(buffer, sizeof(buffer), fp)) break; } - } + } // check if we could parse something bool empty = true; - for(unsigned int i = 0; i < points.size(); i++){ - if(points[i].size()){ + for(unsigned int i = 0; i < points.size(); i++) { + if(points[i].size()) { empty = false; break; } @@ -79,7 +80,7 @@ int GModel::readSTL(const std::string &name, double tolerance) // binary STL (we also try to read in binary mode if the header told // us the format was ASCII but we could not read any vertices) - if(binary || empty){ + if(binary || empty) { if(binary) Msg::Info("Mesh is in binary format"); else @@ -91,39 +92,39 @@ int GModel::readSTL(const std::string &name, double tolerance) unsigned int nfacets = 0; size_t ret = fread(&nfacets, sizeof(unsigned int), 1, fp); bool swap = false; - if(nfacets > 100000000){ + if(nfacets > 100000000) { Msg::Info("Swapping bytes from binary file"); swap = true; - SwapBytes((char*)&nfacets, sizeof(unsigned int), 1); + SwapBytes((char *)&nfacets, sizeof(unsigned int), 1); } - if(ret && nfacets){ + if(ret && nfacets) { points.resize(points.size() + 1); char *data = new char[nfacets * 50 * sizeof(char)]; ret = fread(data, sizeof(char), nfacets * 50, fp); - if(ret == nfacets * 50){ + if(ret == nfacets * 50) { for(unsigned int i = 0; i < nfacets; i++) { float *xyz = (float *)&data[i * 50 * sizeof(char)]; - if(swap) SwapBytes((char*)xyz, sizeof(float), 12); - for(int j = 0; j < 3; j++){ + if(swap) SwapBytes((char *)xyz, sizeof(float), 12); + for(int j = 0; j < 3; j++) { SPoint3 p(xyz[3 + 3 * j], xyz[3 + 3 * j + 1], xyz[3 + 3 * j + 2]); points.back().push_back(p); bbox += p; } } } - delete [] data; + delete[] data; } } } - std::vector<GFace*> faces; - for(unsigned int i = 0; i < points.size(); i++){ - if(points[i].empty()){ + std::vector<GFace *> faces; + for(unsigned int i = 0; i < points.size(); i++) { + if(points[i].empty()) { Msg::Error("No facets found in STL file for solid %d", i); fclose(fp); return 0; } - if(points[i].size() % 3){ + if(points[i].size() % 3) { Msg::Error("Wrong number of points (%d) in STL file for solid %d", points[i].size(), i); fclose(fp); @@ -138,20 +139,20 @@ int GModel::readSTL(const std::string &name, double tolerance) // create triangles using unique vertices double eps = norm(SVector3(bbox.max(), bbox.min())) * tolerance; - std::vector<MVertex*> vertices; + std::vector<MVertex *> vertices; for(unsigned int i = 0; i < points.size(); i++) for(unsigned int j = 0; j < points[i].size(); j++) - vertices.push_back(new MVertex(points[i][j].x(), points[i][j].y(), - points[i][j].z())); + vertices.push_back( + new MVertex(points[i][j].x(), points[i][j].y(), points[i][j].z())); MVertexRTree pos(eps); pos.insert(vertices); std::set<MFace, Less_Face> unique; int nbDuplic = 0; - for(unsigned int i = 0; i < points.size(); i ++){ - for(unsigned int j = 0; j < points[i].size(); j += 3){ + for(unsigned int i = 0; i < points.size(); i++) { + for(unsigned int j = 0; j < points[i].size(); j += 3) { MVertex *v[3]; - for(int k = 0; k < 3; k++){ + for(int k = 0; k < 3; k++) { double x = points[i][j + k].x(); double y = points[i][j + k].y(); double z = points[i][j + k].z(); @@ -161,23 +162,22 @@ int GModel::readSTL(const std::string &name, double tolerance) // reads. It would be better to provide an API to detect/remove duplicate // elements MFace mf(v[0], v[1], v[2]); - if (unique.find(mf) == unique.end()){ - faces[i]->triangles.push_back(new MTriangle(v[0], v[1], v[2])); - unique.insert(mf); + if(unique.find(mf) == unique.end()) { + faces[i]->triangles.push_back(new MTriangle(v[0], v[1], v[2])); + unique.insert(mf); } - else{ - nbDuplic++; + else { + nbDuplic++; } } } - if(nbDuplic) - Msg::Warning("%d duplicate triangles in STL file", nbDuplic); + if(nbDuplic) Msg::Warning("%d duplicate triangles in STL file", nbDuplic); _associateEntityWithMeshVertices(); _storeVerticesInEntities(vertices); // will delete unused vertices - _createGeometryOfDiscreteEntities() ; + _createGeometryOfDiscreteEntities(); fclose(fp); return 1; @@ -187,7 +187,7 @@ int GModel::writeSTL(const std::string &name, bool binary, bool saveAll, double scalingFactor) { FILE *fp = Fopen(name.c_str(), binary ? "wb" : "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -196,25 +196,25 @@ int GModel::writeSTL(const std::string &name, bool binary, bool saveAll, bool useGeoSTL = false; unsigned int nfacets = 0; - for(fiter it = firstFace(); it != lastFace(); ++it){ - if(saveAll || (*it)->physicals.size()){ + for(fiter it = firstFace(); it != lastFace(); ++it) { + if(saveAll || (*it)->physicals.size()) { nfacets += (*it)->triangles.size() + 2 * (*it)->quadrangles.size(); } } - if(!nfacets){ // use CAD STL if there is no mesh + if(!nfacets) { // use CAD STL if there is no mesh useGeoSTL = true; - for(fiter it = firstFace(); it != lastFace(); ++it){ + for(fiter it = firstFace(); it != lastFace(); ++it) { (*it)->buildSTLTriangulation(); - if(saveAll || (*it)->physicals.size()){ + if(saveAll || (*it)->physicals.size()) { nfacets += (*it)->stl_triangles.size() / 3; } } } - if(!binary){ + if(!binary) { fprintf(fp, "solid Created by Gmsh\n"); } - else{ + else { char header[80]; strncpy(header, "Created by Gmsh", 80); fwrite(header, sizeof(char), 80, fp); @@ -222,9 +222,9 @@ int GModel::writeSTL(const std::string &name, bool binary, bool saveAll, } for(fiter it = firstFace(); it != lastFace(); ++it) { - if(saveAll || (*it)->physicals.size()){ - if(useGeoSTL && (*it)->stl_vertices_uv.size()){ - for (unsigned int i = 0; i < (*it)->stl_triangles.size(); i += 3){ + if(saveAll || (*it)->physicals.size()) { + if(useGeoSTL && (*it)->stl_vertices_uv.size()) { + for(unsigned int i = 0; i < (*it)->stl_triangles.size(); i += 3) { SPoint2 &p1((*it)->stl_vertices_uv[(*it)->stl_triangles[i]]); SPoint2 &p2((*it)->stl_vertices_uv[(*it)->stl_triangles[i + 1]]); SPoint2 &p3((*it)->stl_vertices_uv[(*it)->stl_triangles[i + 2]]); @@ -235,25 +235,24 @@ int GModel::writeSTL(const std::string &name, bool binary, bool saveAll, double y[3] = {gp1.y(), gp2.y(), gp3.y()}; double z[3] = {gp1.z(), gp2.z(), gp3.z()}; double n[3]; - normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], n); - if(!binary){ + normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], + n); + if(!binary) { fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]); fprintf(fp, " outer loop\n"); for(int j = 0; j < 3; j++) - fprintf(fp, " vertex %g %g %g\n", - x[j] * scalingFactor, - y[j] * scalingFactor, - z[j] * scalingFactor); + fprintf(fp, " vertex %g %g %g\n", x[j] * scalingFactor, + y[j] * scalingFactor, z[j] * scalingFactor); fprintf(fp, " endloop\n"); fprintf(fp, "endfacet\n"); } - else{ + else { char data[50]; - float *coords = (float*)data; + float *coords = (float *)data; coords[0] = (float)n[0]; coords[1] = (float)n[1]; coords[2] = (float)n[2]; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { coords[3 + 3 * j] = (float)(x[j] * scalingFactor); coords[3 + 3 * j + 1] = (float)(y[j] * scalingFactor); coords[3 + 3 * j + 2] = (float)(z[j] * scalingFactor); @@ -263,7 +262,7 @@ int GModel::writeSTL(const std::string &name, bool binary, bool saveAll, } } } - else{ + else { for(unsigned int i = 0; i < (*it)->triangles.size(); i++) (*it)->triangles[i]->writeSTL(fp, binary, scalingFactor); for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) @@ -272,8 +271,7 @@ int GModel::writeSTL(const std::string &name, bool binary, bool saveAll, } } - if(!binary) - fprintf(fp, "endsolid Created by Gmsh\n"); + if(!binary) fprintf(fp, "endsolid Created by Gmsh\n"); fclose(fp); return 1; diff --git a/Geo/GModelIO_SU2.cpp b/Geo/GModelIO_SU2.cpp index a0e68548a8d4d7fb360b16d066974553a6ea9e3e..3b87842e306ce9e329d543870d5c1d19665a89d2 100644 --- a/Geo/GModelIO_SU2.cpp +++ b/Geo/GModelIO_SU2.cpp @@ -12,10 +12,12 @@ static std::string physicalName(GModel *m, int dim, int num) { std::string name = m->getPhysicalName(dim, num); - if(name.empty()){ + if(name.empty()) { char tmp[256]; - sprintf(tmp, "%s%d", (dim == 3) ? "PhysicalVolume" : - (dim == 2) ? "PhysicalSurface" : "PhysicalLine", num); + sprintf(tmp, "%s%d", + (dim == 3) ? "PhysicalVolume" : + (dim == 2) ? "PhysicalSurface" : "PhysicalLine", + num); name = tmp; } for(unsigned int i = 0; i < name.size(); i++) @@ -23,17 +25,19 @@ static std::string physicalName(GModel *m, int dim, int num) return name; } -int GModel::writeSU2(const std::string &name, bool saveAll, double scalingFactor) +int GModel::writeSU2(const std::string &name, bool saveAll, + double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } int ndime = getDim(); - if(ndime != 2 && ndime != 3){ - Msg::Error("SU2 mesh output valid only for 2D or 3D models (not %dD)", ndime); + if(ndime != 2 && ndime != 3) { + Msg::Error("SU2 mesh output valid only for 2D or 3D models (not %dD)", + ndime); fclose(fp); return 0; } @@ -45,13 +49,15 @@ int GModel::writeSU2(const std::string &name, bool saveAll, double scalingFactor // all interior elements are printed in a single section; indices start at 0; // node ordering is the same as VTK int nelem = 0; - if(ndime == 2){ + if(ndime == 2) { for(fiter it = firstFace(); it != lastFace(); it++) - if(saveAll || (*it)->physicals.size()) nelem += (*it)->getNumMeshElements(); + if(saveAll || (*it)->physicals.size()) + nelem += (*it)->getNumMeshElements(); } - else{ + else { for(riter it = firstRegion(); it != lastRegion(); it++) - if(saveAll || (*it)->physicals.size()) nelem += (*it)->getNumMeshElements(); + if(saveAll || (*it)->physicals.size()) + nelem += (*it)->getNumMeshElements(); } int npoin = indexMeshVertices(saveAll); @@ -60,13 +66,13 @@ int GModel::writeSU2(const std::string &name, bool saveAll, double scalingFactor // elements fprintf(fp, "NELEM= %d\n", nelem); int num = 0; - if(ndime == 2){ + if(ndime == 2) { for(fiter it = firstFace(); it != lastFace(); it++) if(saveAll || (*it)->physicals.size()) for(unsigned int i = 0; i < (*it)->getNumMeshElements(); i++) (*it)->getMeshElement(i)->writeSU2(fp, num++); } - else{ + else { for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) for(unsigned int i = 0; i < (*it)->getNumMeshElements(); i++) @@ -75,26 +81,28 @@ int GModel::writeSU2(const std::string &name, bool saveAll, double scalingFactor // vertices fprintf(fp, "NPOIN= %d\n", npoin); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) entities[i]->mesh_vertices[j]->writeSU2(fp, ndime, scalingFactor); // markers for physical groups of dimension (ndime - 1) - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; getPhysicalGroups(groups); int nmark = groups[ndime - 1].size(); - if(nmark){ + if(nmark) { fprintf(fp, "NMARK= %d\n", nmark); - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[ndime - 1].begin(); - it != groups[ndime - 1].end(); it++){ + for(std::map<int, std::vector<GEntity *> >::iterator it = + groups[ndime - 1].begin(); + it != groups[ndime - 1].end(); it++) { std::vector<GEntity *> &entities = it->second; int n = 0; for(unsigned int i = 0; i < entities.size(); i++) n += entities[i]->getNumMeshElements(); - if(n){ - fprintf(fp, "MARKER_TAG= %s\n", physicalName(this, ndime - 1, it->first).c_str()); + if(n) { + fprintf(fp, "MARKER_TAG= %s\n", + physicalName(this, ndime - 1, it->first).c_str()); fprintf(fp, "MARKER_ELEMS= %d\n", n); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) diff --git a/Geo/GModelIO_TOCHNOG.cpp b/Geo/GModelIO_TOCHNOG.cpp index 1948a00bb4431a020826d78ff7552c5e54d17e34..757921ee7c6db95fbe404d64966436474996725e 100644 --- a/Geo/GModelIO_TOCHNOG.cpp +++ b/Geo/GModelIO_TOCHNOG.cpp @@ -18,15 +18,15 @@ int dimension; template <class T> -static void writeElementsTOCHNOG(FILE *fp, GEntity *ge, std::vector<T*> &elements, - bool saveAll) +static void writeElementsTOCHNOG(FILE *fp, GEntity *ge, + std::vector<T *> &elements, bool saveAll) { - if(elements.size() && (saveAll || ge->physicals.size())){ + if(elements.size() && (saveAll || ge->physicals.size())) { const char *typ = elements[0]->getStringForTOCHNOG(); - if(typ){ - //const char *str = (ge->dim() == 3) ? " 3 " : (ge->dim() == 2) ? + if(typ) { + // const char *str = (ge->dim() == 3) ? " 3 " : (ge->dim() == 2) ? // " 2 " : (ge->dim() == 1) ? " 1 " : "Point"; - //fprintf(fp, "( 'number_of_space_dimensions %s)\n", str); + // fprintf(fp, "( 'number_of_space_dimensions %s)\n", str); for(unsigned int i = 0; i < elements.size(); i++) elements[i]->writeTOCHNOG(fp, elements[i]->getNum()); } @@ -36,10 +36,12 @@ static void writeElementsTOCHNOG(FILE *fp, GEntity *ge, std::vector<T*> &element static std::string physicalName(GModel *m, int dim, int num) { std::string name = m->getPhysicalName(dim, num); - if(name.empty()){ + if(name.empty()) { char tmp[256]; - sprintf(tmp, "%s%d", (dim == 3) ? "PhysicalVolume" : - (dim == 2) ? "PhysicalSurface" : "PhysicalLine", num); + sprintf(tmp, "%s%d", + (dim == 3) ? "PhysicalVolume" : + (dim == 2) ? "PhysicalSurface" : "PhysicalLine", + num); name = tmp; } for(unsigned int i = 0; i < name.size(); i++) @@ -47,29 +49,29 @@ static std::string physicalName(GModel *m, int dim, int num) return name; } -int GModel::writeTOCHNOG(const std::string &name, bool saveAll, bool saveGroupsOfNodes, - double scalingFactor) +int GModel::writeTOCHNOG(const std::string &name, bool saveAll, + bool saveGroupsOfNodes, double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } fprintf(fp, "(----Tochnog Input File Created by Gmsh Version 2.13.1 ----)\n"); fprintf(fp, " \n"); - fprintf(fp, "(**EDIT OR MODIFY THE ENTRIES BELOW AS REQUIRED**)\n" - "echo -yes \n" - "number of space dimensions (add number here) \n" - "derivatives \n" - "materi_velocity \n" - "materi_displacement \n" - "materi_strain_total \n" - "materi_stress \n" - "condif_temperature \n" - "number_of_integration_points (add number here) \n" - "end_initia \n" - "options_element_dof -yes \n"); + fprintf(fp, "(**EDIT OR MODIFY THE ENTRIES BELOW AS REQUIRED**)\n" + "echo -yes \n" + "number of space dimensions (add number here) \n" + "derivatives \n" + "materi_velocity \n" + "materi_displacement \n" + "materi_strain_total \n" + "materi_stress \n" + "condif_temperature \n" + "number_of_integration_points (add number here) \n" + "end_initia \n" + "options_element_dof -yes \n"); fprintf(fp, "\n"); // Nodes @@ -80,7 +82,7 @@ int GModel::writeTOCHNOG(const std::string &name, bool saveAll, bool saveGroupsO if(noPhysicalGroups()) saveAll = true; indexMeshVertices(saveAll); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++) @@ -91,24 +93,24 @@ int GModel::writeTOCHNOG(const std::string &name, bool saveAll, bool saveGroupsO // Elements fprintf(fp, "(++++++++++++++ E L E M E N T S ++++++++++++++)\n"); fprintf(fp, "\n"); - for(viter it = firstVertex(); it != lastVertex(); ++it){ + for(viter it = firstVertex(); it != lastVertex(); ++it) { writeElementsTOCHNOG(fp, *it, (*it)->points, saveAll); } - if (dim ==3) { - for(riter it = firstRegion(); it != lastRegion(); ++it){ + if(dim == 3) { + for(riter it = firstRegion(); it != lastRegion(); ++it) { writeElementsTOCHNOG(fp, *it, (*it)->tetrahedra, saveAll); writeElementsTOCHNOG(fp, *it, (*it)->hexahedra, saveAll); } } - else if (dim ==2) { - for(fiter it = firstFace(); it != lastFace(); ++it){ + else if(dim == 2) { + for(fiter it = firstFace(); it != lastFace(); ++it) { writeElementsTOCHNOG(fp, *it, (*it)->triangles, saveAll); writeElementsTOCHNOG(fp, *it, (*it)->quadrangles, saveAll); } } - else if (dim ==1) { - for(eiter it = firstEdge(); it != lastEdge(); ++it){ + else if(dim == 1) { + for(eiter it = firstEdge(); it != lastEdge(); ++it) { writeElementsTOCHNOG(fp, *it, (*it)->lines, saveAll); } } @@ -117,32 +119,45 @@ int GModel::writeTOCHNOG(const std::string &name, bool saveAll, bool saveGroupsO // Elements - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; getPhysicalGroups(groups); - fprintf(fp, "( +------------+---------Physical Groups Section----------+------------+\n"); + fprintf(fp, "( +------------+---------Physical Groups " + "Section----------+------------+\n"); fprintf(fp, "\n"); - fprintf(fp, "- In Tochnog use Physical Groups to define 'element_group' entities to -\n"); - fprintf(fp, "- identify materials, and groups of nodes to apply boundary conditions -)\n"); + fprintf(fp, "- In Tochnog use Physical Groups to define 'element_group' " + "entities to -\n"); + fprintf(fp, "- identify materials, and groups of nodes to apply boundary " + "conditions -)\n"); fprintf(fp, "\n"); - fprintf(fp, "(- For example, groups of ELEMENTS chosen using gmsh 'physical groups' can be used as follows)\n"); - fprintf(fp, "(- element_group -ra INSERT HERE GROUP OF ELEMENTS SAVED WITH GMSH -ra Material number)\n"); + fprintf(fp, "(- For example, groups of ELEMENTS chosen using gmsh 'physical " + "groups' can be used as follows)\n"); + fprintf(fp, "(- element_group -ra INSERT HERE GROUP OF ELEMENTS SAVED WITH " + "GMSH -ra Material number)\n"); fprintf(fp, "\n"); - fprintf(fp, "(- For example, groups of nodes chosen using gmsh 'physical groups' can be used as follows)\n"); - fprintf(fp, "(- bounda_unknown 0 -ra INSERT HERE GROUP OF NODES SAVED WITH GMSH -ra -velx -vely )\n"); - fprintf(fp, "(- bounda_time 0 0.000 0.000 1000000.000 0.000 )\n"); + fprintf(fp, "(- For example, groups of nodes chosen using gmsh 'physical " + "groups' can be used as follows)\n"); + fprintf(fp, "(- bounda_unknown 0 -ra INSERT HERE GROUP OF NODES SAVED WITH " + "GMSH -ra -velx -vely )\n"); + fprintf(fp, + "(- bounda_time 0 0.000 0.000 1000000.000 0.000 )\n"); fprintf(fp, "\n"); - fprintf(fp, "( +------------+---------Physical Groups Section----------+------------+\n"); + fprintf(fp, "( +------------+---------Physical Groups " + "Section----------+------------+\n"); // Save elements sets for each physical group - for(int dim = 1; dim <= 3; dim++){ - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); - it != groups[dim].end(); it++){ + for(int dim = 1; dim <= 3; dim++) { + for(std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].begin(); + it != groups[dim].end(); it++) { std::vector<GEntity *> &entities = it->second; fprintf(fp, "\n"); - fprintf(fp, "(Element sets ===> 'element_group' to identify DIFFERENT MATERIALS =%s)\n", physicalName(this, dim, it->first).c_str()); + fprintf(fp, + "(Element sets ===> 'element_group' to identify DIFFERENT " + "MATERIALS =%s)\n", + physicalName(this, dim, it->first).c_str()); int n = 0; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); if(n && !(n % 10)) fprintf(fp, "\n"); fprintf(fp, "%d ", e->getNum()); @@ -154,24 +169,29 @@ int GModel::writeTOCHNOG(const std::string &name, bool saveAll, bool saveGroupsO } // Save node sets for each physical group - if(saveGroupsOfNodes){ - for(int dim = 1; dim <= 3; dim++){ - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); - it != groups[dim].end(); it++){ - std::set<MVertex*> nodes; + if(saveGroupsOfNodes) { + for(int dim = 1; dim <= 3; dim++) { + for(std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].begin(); + it != groups[dim].end(); it++) { + std::set<MVertex *> nodes; std::vector<GEntity *> &entities = it->second; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); - for (std::size_t k = 0; k < e->getNumVertices(); k++) + for(std::size_t k = 0; k < e->getNumVertices(); k++) nodes.insert(e->getVertex(k)); } } fprintf(fp, "\n"); - fprintf(fp, "(Node sets ===> Used to set BOUNDARY CONDITIONS in Tochnog =%s)\n", physicalName(this, dim, it->first).c_str()); + fprintf( + fp, + "(Node sets ===> Used to set BOUNDARY CONDITIONS in Tochnog =%s)\n", + physicalName(this, dim, it->first).c_str()); fprintf(fp, "\n"); int n = 0; - for(std::set<MVertex*>::iterator it2 = nodes.begin(); it2 != nodes.end(); it2++){ + for(std::set<MVertex *>::iterator it2 = nodes.begin(); + it2 != nodes.end(); it2++) { if(n && !(n % 10)) fprintf(fp, "\n"); fprintf(fp, "%d ", (*it2)->getIndex()); n++; diff --git a/Geo/GModelIO_UNV.cpp b/Geo/GModelIO_UNV.cpp index 8975384dfea8480dc87dbc61c6acd32fb046e9f3..18d02e1fc897b7a2479c187aadb8f11bd840aec5 100644 --- a/Geo/GModelIO_UNV.cpp +++ b/Geo/GModelIO_UNV.cpp @@ -22,7 +22,7 @@ #include <zlib.h> typedef gzFile gmshFILE; #define gmshopen gzopen -#define gmshgets(a,b,c) gzgets((c),(a),(b)) +#define gmshgets(a, b, c) gzgets((c), (a), (b)) #define gmshclose gzclose #define gmsheof gzeof #else @@ -36,28 +36,28 @@ typedef FILE *gmshFILE; int GModel::readUNV(const std::string &name) { gmshFILE fp = gmshopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } char buffer[256]; - std::map<int, std::vector<MElement*> > elements[7]; + std::map<int, std::vector<MElement *> > elements[7]; std::map<int, std::map<int, std::string> > physicals[4]; _vertexMapCache.clear(); while(!gmsheof(fp)) { if(!gmshgets(buffer, sizeof(buffer), fp)) break; - if(!strncmp(buffer, " -1", 6)){ + if(!strncmp(buffer, " -1", 6)) { if(!gmshgets(buffer, sizeof(buffer), fp)) break; if(!strncmp(buffer, " -1", 6)) if(!gmshgets(buffer, sizeof(buffer), fp)) break; int record = 0; sscanf(buffer, "%d", &record); - if(record == 2411){ // nodes + if(record == 2411) { // nodes Msg::Info("Reading nodes"); - while(gmshgets(buffer, sizeof(buffer), fp)){ + while(gmshgets(buffer, sizeof(buffer), fp)) { if(!strncmp(buffer, " -1", 6)) break; int num, dum; if(sscanf(buffer, "%d %d %d %d", &num, &dum, &dum, &dum) != 4) break; @@ -69,86 +69,133 @@ int GModel::readUNV(const std::string &name) _vertexMapCache[num] = new MVertex(x, y, z, 0, num); } } - else if(record == 2412){ // elements + else if(record == 2412) { // elements Msg::Info("Reading elements"); std::map<int, int> warn; - while(gmshgets(buffer, sizeof(buffer), fp)){ - if(strlen(buffer) < 3) continue; // possible line ending after last fscanf + while(gmshgets(buffer, sizeof(buffer), fp)) { + if(strlen(buffer) < 3) + continue; // possible line ending after last fscanf if(!strncmp(buffer, " -1", 6)) break; int num, type, elementary, physical, color, numNodes; - if(!CTX::instance()->mesh.switchElementTags) { - if(sscanf(buffer, "%d %d %d %d %d %d", &num, &type, &elementary, &physical, - &color, &numNodes) != 6) break; - } + if(!CTX::instance()->mesh.switchElementTags) { + if(sscanf(buffer, "%d %d %d %d %d %d", &num, &type, &elementary, + &physical, &color, &numNodes) != 6) + break; + } else { - if(sscanf(buffer, "%d %d %d %d %d %d", &num, &type, &physical, &elementary, - &color, &numNodes) != 6) break; - } + if(sscanf(buffer, "%d %d %d %d %d %d", &num, &type, &physical, + &elementary, &color, &numNodes) != 6) + break; + } if(elementary < 0) elementary = getMaxElementaryNumber(-1) + 1; if(physical < 0) physical = 0; - if(!type){ + if(!type) { if(warn[type]++ == 1) Msg::Warning("No element type: guessing from number of nodes"); - switch(numNodes){ - case 2: type = 11; break; // line - case 3: type = 41; break; // tri - case 4: type = 111; break; // tet + switch(numNodes) { + case 2: + type = 11; + break; // line + case 3: + type = 41; + break; // tri + case 4: + type = 111; + break; // tet } } - switch(type){ - case 11: case 21: case 22: case 31: - case 23: case 24: case 32: + switch(type) { + case 11: + case 21: + case 22: + case 31: + case 23: + case 24: + case 32: // beam elements if(!gmshgets(buffer, sizeof(buffer), fp)) break; int dum; if(sscanf(buffer, "%d %d %d", &dum, &dum, &dum) != 3) break; break; } - std::vector<MVertex*> vertices(numNodes); - for(int i = 0; i < numNodes; i++){ + std::vector<MVertex *> vertices(numNodes); + for(int i = 0; i < numNodes; i++) { int n; - if(!gmshgets(buffer, 11, fp)){ gmshclose(fp); return 0; } + if(!gmshgets(buffer, 11, fp)) { + gmshclose(fp); + return 0; + } if(strlen(buffer) < 10) - if(!gmshgets(buffer, 11, fp)){ gmshclose(fp); return 0; } - if(!sscanf(buffer, "%d", &n)){ gmshclose(fp); return 0; } + if(!gmshgets(buffer, 11, fp)) { + gmshclose(fp); + return 0; + } + if(!sscanf(buffer, "%d", &n)) { + gmshclose(fp); + return 0; + } vertices[i] = getMeshVertexByTag(n); - if(!vertices[i]){ + if(!vertices[i]) { Msg::Error("Wrong vertex index %d", n); gmshclose(fp); return 0; } } int dim = -1; - switch(type){ - case 11: case 21: case 22: case 31: + switch(type) { + case 11: + case 21: + case 22: + case 31: elements[0][elementary].push_back(new MLine(vertices, num)); dim = 1; break; - case 23: case 24: case 32: - elements[0][elementary].push_back - (new MLine3(vertices[0], vertices[2], vertices[1], num)); + case 23: + case 24: + case 32: + elements[0][elementary].push_back( + new MLine3(vertices[0], vertices[2], vertices[1], num)); dim = 1; break; - case 41: case 51: case 61: case 74: case 81: case 91: + case 41: + case 51: + case 61: + case 74: + case 81: + case 91: elements[1][elementary].push_back(new MTriangle(vertices, num)); dim = 2; break; - case 42: case 52: case 62: case 72: case 82: case 92: - elements[1][elementary].push_back - (new MTriangle6(vertices[0], vertices[2], vertices[4], vertices[1], - vertices[3], vertices[5], num)); + case 42: + case 52: + case 62: + case 72: + case 82: + case 92: + elements[1][elementary].push_back( + new MTriangle6(vertices[0], vertices[2], vertices[4], vertices[1], + vertices[3], vertices[5], num)); dim = 2; break; - case 44: case 54: case 64: case 71: case 84: case 94: + case 44: + case 54: + case 64: + case 71: + case 84: + case 94: elements[2][elementary].push_back(new MQuadrangle(vertices, num)); dim = 2; break; - case 45: case 55: case 65: case 75: case 85: case 95: - elements[2][elementary].push_back - (new MQuadrangle8(vertices[0], vertices[2], vertices[4], vertices[6], - vertices[1], vertices[3], vertices[5], vertices[7], - num)); + case 45: + case 55: + case 65: + case 75: + case 85: + case 95: + elements[2][elementary].push_back(new MQuadrangle8( + vertices[0], vertices[2], vertices[4], vertices[6], vertices[1], + vertices[3], vertices[5], vertices[7], num)); dim = 2; break; case 111: @@ -156,36 +203,39 @@ int GModel::readUNV(const std::string &name) dim = 3; break; case 118: - elements[3][elementary].push_back - (new MTetrahedron10(vertices[0], vertices[2], vertices[4], vertices[9], - vertices[1], vertices[3], vertices[5], vertices[6], - vertices[8], vertices[7], num)); + elements[3][elementary].push_back(new MTetrahedron10( + vertices[0], vertices[2], vertices[4], vertices[9], vertices[1], + vertices[3], vertices[5], vertices[6], vertices[8], vertices[7], + num)); dim = 3; break; - case 104: case 115: + case 104: + case 115: elements[4][elementary].push_back(new MHexahedron(vertices, num)); dim = 3; break; - case 105: case 116: - elements[4][elementary].push_back - (new MHexahedron20(vertices[0], vertices[2], vertices[4], vertices[6], - vertices[12], vertices[14], vertices[16], vertices[18], - vertices[1], vertices[7], vertices[8], vertices[3], - vertices[9], vertices[5], vertices[10], vertices[11], - vertices[13], vertices[19], vertices[15], vertices[17], - num)); + case 105: + case 116: + elements[4][elementary].push_back(new MHexahedron20( + vertices[0], vertices[2], vertices[4], vertices[6], vertices[12], + vertices[14], vertices[16], vertices[18], vertices[1], + vertices[7], vertices[8], vertices[3], vertices[9], vertices[5], + vertices[10], vertices[11], vertices[13], vertices[19], + vertices[15], vertices[17], num)); dim = 3; break; - case 101: case 112: + case 101: + case 112: elements[5][elementary].push_back(new MPrism(vertices, num)); dim = 3; break; - case 102: case 113: - elements[5][elementary].push_back - (new MPrism15(vertices[0], vertices[2], vertices[4], vertices[9], - vertices[11], vertices[13], vertices[1], vertices[5], - vertices[6], vertices[3], vertices[7], vertices[8], - vertices[10], vertices[14], vertices[12], num)); + case 102: + case 113: + elements[5][elementary].push_back( + new MPrism15(vertices[0], vertices[2], vertices[4], vertices[9], + vertices[11], vertices[13], vertices[1], vertices[5], + vertices[6], vertices[3], vertices[7], vertices[8], + vertices[10], vertices[14], vertices[12], num)); dim = 3; break; default: @@ -194,14 +244,16 @@ int GModel::readUNV(const std::string &name) break; } - if(dim >= 0 && physical && (!physicals[dim].count(elementary) || - !physicals[dim][elementary].count(physical))) + if(dim >= 0 && physical && + (!physicals[dim].count(elementary) || + !physicals[dim][elementary].count(physical))) physicals[dim][elementary][physical] = "unnamed"; } } - else if(record == 2477){ // groups elements - Msg::Info("Discarding element/node groups: currently still reading physical " - "tags directly from elements"); + else if(record == 2477) { // groups elements + Msg::Info( + "Discarding element/node groups: currently still reading physical " + "tags directly from elements"); } } } @@ -211,8 +263,7 @@ int GModel::readUNV(const std::string &name) _associateEntityWithMeshVertices(); _storeVerticesInEntities(_vertexMapCache); - for(int i = 0; i < 4; i++) - _storePhysicalTagsInEntities(i, physicals[i]); + for(int i = 0; i < 4; i++) _storePhysicalTagsInEntities(i, physicals[i]); gmshclose(fp); return 1; @@ -221,10 +272,12 @@ int GModel::readUNV(const std::string &name) static std::string physicalName(GModel *m, int dim, int num) { std::string name = m->getPhysicalName(dim, num); - if(name.empty()){ + if(name.empty()) { char tmp[256]; - sprintf(tmp, "%s%d", (dim == 3) ? "PhysicalVolume" : - (dim == 2) ? "PhysicalSurface" : "PhysicalLine", num); + sprintf(tmp, "%s%d", + (dim == 3) ? "PhysicalVolume" : + (dim == 2) ? "PhysicalSurface" : "PhysicalLine", + num); name = tmp; } for(unsigned int i = 0; i < name.size(); i++) @@ -232,11 +285,11 @@ static std::string physicalName(GModel *m, int dim, int num) return name; } -int GModel::writeUNV(const std::string &name, bool saveAll, bool saveGroupsOfNodes, - double scalingFactor) +int GModel::writeUNV(const std::string &name, bool saveAll, + bool saveGroupsOfNodes, double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -245,7 +298,7 @@ int GModel::writeUNV(const std::string &name, bool saveAll, bool saveGroupsOfNod indexMeshVertices(saveAll); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); // nodes @@ -259,9 +312,9 @@ int GModel::writeUNV(const std::string &name, bool saveAll, bool saveGroupsOfNod // elements fprintf(fp, "%6d\n", -1); fprintf(fp, "%6d\n", 2412); - for(unsigned int i = 0; i < entities.size(); i++){ - if(saveAll || entities[i]->physicals.size()){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + if(saveAll || entities[i]->physicals.size()) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); e->writeUNV(fp, e->getNum(), entities[i]->tag(), 0); } @@ -269,24 +322,25 @@ int GModel::writeUNV(const std::string &name, bool saveAll, bool saveGroupsOfNod } fprintf(fp, "%6d\n", -1); - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; getPhysicalGroups(groups); // save groups of elements (and groups of nodes if requested) for each // physical fprintf(fp, "%6d\n", -1); fprintf(fp, "%6d\n", 2477); - for(int dim = 0; dim <= 3; dim++){ - for(std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].begin(); - it != groups[dim].end(); it++){ + for(int dim = 0; dim <= 3; dim++) { + for(std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].begin(); + it != groups[dim].end(); it++) { std::vector<GEntity *> &entities = it->second; - std::set<MVertex*> nodes; - if(saveGroupsOfNodes){ - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + std::set<MVertex *> nodes; + if(saveGroupsOfNodes) { + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); - for (std::size_t k = 0; k < e->getNumVertices(); k++) + for(std::size_t k = 0; k < e->getNumVertices(); k++) nodes.insert(e->getVertex(k)); } } @@ -296,13 +350,14 @@ int GModel::writeUNV(const std::string &name, bool saveAll, bool saveGroupsOfNod for(unsigned int i = 0; i < entities.size(); i++) nele += entities[i]->getNumMeshElements(); - fprintf(fp, "%10d%10d%10d%10d%10d%10d%10d%10d\n", - it->first, 0, 0, 0, 0, 0, 0, (int)nodes.size() + nele); + fprintf(fp, "%10d%10d%10d%10d%10d%10d%10d%10d\n", it->first, 0, 0, 0, 0, + 0, 0, (int)nodes.size() + nele); fprintf(fp, "%s\n", physicalName(this, dim, it->first).c_str()); - if(saveGroupsOfNodes){ + if(saveGroupsOfNodes) { int row = 0; - for(std::set<MVertex*>::iterator it2 = nodes.begin(); it2 != nodes.end(); it2++){ + for(std::set<MVertex *>::iterator it2 = nodes.begin(); + it2 != nodes.end(); it2++) { if(row == 2) { fprintf(fp, "\n"); row = 0; @@ -315,8 +370,8 @@ int GModel::writeUNV(const std::string &name, bool saveAll, bool saveGroupsOfNod { int row = 0; - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); if(row == 2) { fprintf(fp, "\n"); diff --git a/Geo/GModelIO_VRML.cpp b/Geo/GModelIO_VRML.cpp index 268eaa19068d52cb586b24a187b5d91cb7b30aa6..fc7c2c128f11ef948301b15dacab3f8142fd260b 100644 --- a/Geo/GModelIO_VRML.cpp +++ b/Geo/GModelIO_VRML.cpp @@ -16,20 +16,21 @@ static int skipUntil(FILE *fp, const char *key) char str[256], key_bracket[256]; strcpy(key_bracket, key); strcat(key_bracket, "["); - while(fscanf(fp, "%s", str)){ - if(!strcmp(str, key)){ - while(!feof(fp) && fgetc(fp) != '['){} + while(fscanf(fp, "%s", str)) { + if(!strcmp(str, key)) { + while(!feof(fp) && fgetc(fp) != '[') { + } return 1; } - if(!strcmp(str, key_bracket)){ + if(!strcmp(str, key_bracket)) { return 1; } } return 0; } -static int readVerticesVRML(FILE *fp, std::vector<MVertex*> &vertexVector, - std::vector<MVertex*> &allVertexVector) +static int readVerticesVRML(FILE *fp, std::vector<MVertex *> &vertexVector, + std::vector<MVertex *> &allVertexVector) { double x, y, z; if(fscanf(fp, "%lf %lf %lf", &x, &y, &z) != 3) return 0; @@ -42,9 +43,10 @@ static int readVerticesVRML(FILE *fp, std::vector<MVertex*> &vertexVector, return 1; } -static int readElementsVRML(FILE *fp, std::vector<MVertex*> &vertexVector, int region, - std::map<int, std::vector<MElement*> > elements[3], - bool strips=false) +static int readElementsVRML(FILE *fp, std::vector<MVertex *> &vertexVector, + int region, + std::map<int, std::vector<MElement *> > elements[3], + bool strips = false) { int i; std::vector<int> idx; @@ -63,14 +65,14 @@ static int readElementsVRML(FILE *fp, std::vector<MVertex*> &vertexVector, int r else format = " %d"; - while(fscanf(fp, format, &i) == 1){ - if(i != -1){ + while(fscanf(fp, format, &i) == 1) { + if(i != -1) { idx.push_back(i); } - else{ - std::vector<MVertex*> vertices; - for(unsigned int j = 0; j < idx.size(); j++){ - if(idx[j] < 0 || idx[j] > (int)(vertexVector.size() - 1)){ + else { + std::vector<MVertex *> vertices; + for(unsigned int j = 0; j < idx.size(); j++) { + if(idx[j] < 0 || idx[j] > (int)(vertexVector.size() - 1)) { Msg::Error("Wrong vertex index %d", idx[j]); return 0; } @@ -78,49 +80,50 @@ static int readElementsVRML(FILE *fp, std::vector<MVertex*> &vertexVector, int r vertices.push_back(vertexVector[idx[j]]); } idx.clear(); - if(vertices.size() < 2){ + if(vertices.size() < 2) { Msg::Info("Skipping %d-vertex element", (int)vertices.size()); } - else if(vertices.size() == 2){ + else if(vertices.size() == 2) { elements[0][region].push_back(new MLine(vertices)); } - else if(vertices.size() == 3){ + else if(vertices.size() == 3) { elements[1][region].push_back(new MTriangle(vertices)); } - else if(!strips && vertices.size() == 4){ + else if(!strips && vertices.size() == 4) { elements[2][region].push_back(new MQuadrangle(vertices)); } - else if(strips){ // triangle strip - for(unsigned int j = 2; j < vertices.size(); j++){ + else if(strips) { // triangle strip + for(unsigned int j = 2; j < vertices.size(); j++) { if(j % 2) - elements[1][region].push_back - (new MTriangle(vertices[j], vertices[j - 1], vertices[j - 2])); + elements[1][region].push_back( + new MTriangle(vertices[j], vertices[j - 1], vertices[j - 2])); else - elements[1][region].push_back - (new MTriangle(vertices[j - 2], vertices[j - 1], vertices[j])); + elements[1][region].push_back( + new MTriangle(vertices[j - 2], vertices[j - 1], vertices[j])); } } - else{ // import polygon as triangle fan - for(unsigned int j = 2; j < vertices.size(); j++){ - elements[1][region].push_back - (new MTriangle(vertices[0], vertices[j-1], vertices[j])); + else { // import polygon as triangle fan + for(unsigned int j = 2; j < vertices.size(); j++) { + elements[1][region].push_back( + new MTriangle(vertices[0], vertices[j - 1], vertices[j])); } } } } - if(idx.size()){ + if(idx.size()) { Msg::Error("Prematured end of VRML file"); return 0; } Msg::Info("%d elements", elements[0][region].size() + - elements[1][region].size() + elements[2][region].size()); + elements[1][region].size() + + elements[2][region].size()); return 1; } int GModel::readVRML(const std::string &name) { FILE *fp = Fopen(name.c_str(), "r"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -128,20 +131,20 @@ int GModel::readVRML(const std::string &name) // This is by NO means a complete VRML/Inventor parser (but it's // sufficient for reading simple Inventor files... which is all I // need) - std::vector<MVertex*> vertexVector, allVertexVector; - std::map<int, std::vector<MElement*> > elements[3]; + std::vector<MVertex *> vertexVector, allVertexVector; + std::map<int, std::vector<MElement *> > elements[3]; int region = getMaxElementaryNumber(-1); char buffer[256], str[256]; while(!feof(fp)) { if(!fgets(buffer, sizeof(buffer), fp)) break; - if(buffer[0] != '#'){ // skip comments + if(buffer[0] != '#') { // skip comments sscanf(buffer, "%s", str); - if(!strcmp(str, "Coordinate3")){ + if(!strcmp(str, "Coordinate3")) { vertexVector.clear(); if(!skipUntil(fp, "point")) break; if(!readVerticesVRML(fp, vertexVector, allVertexVector)) break; } - else if(!strcmp(str, "coord")){ + else if(!strcmp(str, "coord")) { region++; vertexVector.clear(); if(!skipUntil(fp, "point")) break; @@ -149,7 +152,7 @@ int GModel::readVRML(const std::string &name) if(!skipUntil(fp, "coordIndex")) break; if(!readElementsVRML(fp, vertexVector, region, elements, true)) break; } - else if(!strcmp(str, "IndexedTriangleStripSet")){ + else if(!strcmp(str, "IndexedTriangleStripSet")) { region++; vertexVector.clear(); if(!skipUntil(fp, "vertex")) break; @@ -157,20 +160,22 @@ int GModel::readVRML(const std::string &name) if(!skipUntil(fp, "coordIndex")) break; if(!readElementsVRML(fp, vertexVector, region, elements, true)) break; } - else if(!strcmp(str, "IndexedFaceSet") || !strcmp(str, "IndexedLineSet")){ + else if(!strcmp(str, "IndexedFaceSet") || + !strcmp(str, "IndexedLineSet")) { region++; if(!skipUntil(fp, "coordIndex")) break; if(!readElementsVRML(fp, vertexVector, region, elements)) break; } - else if(!strcmp(str, "DEF")){ + else if(!strcmp(str, "DEF")) { char str1[256], str2[256]; if(!sscanf(buffer, "%s %s %s", str1, str2, str)) break; - if(!strcmp(str, "Coordinate")){ + if(!strcmp(str, "Coordinate")) { vertexVector.clear(); if(!skipUntil(fp, "point")) break; if(!readVerticesVRML(fp, vertexVector, allVertexVector)) break; } - else if(!strcmp(str, "IndexedFaceSet") || !strcmp(str, "IndexedLineSet")){ + else if(!strcmp(str, "IndexedFaceSet") || + !strcmp(str, "IndexedLineSet")) { region++; if(!skipUntil(fp, "coordIndex")) break; if(!readElementsVRML(fp, vertexVector, region, elements)) break; @@ -188,10 +193,11 @@ int GModel::readVRML(const std::string &name) return 1; } -int GModel::writeVRML(const std::string &name, bool saveAll, double scalingFactor) +int GModel::writeVRML(const std::string &name, bool saveAll, + double scalingFactor) { FILE *fp = Fopen(name.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -218,8 +224,8 @@ int GModel::writeVRML(const std::string &name, bool saveAll, double scalingFacto fprintf(fp, " ]\n"); fprintf(fp, "}\n"); - for(eiter it = firstEdge(); it != lastEdge(); ++it){ - if(saveAll || (*it)->physicals.size()){ + for(eiter it = firstEdge(); it != lastEdge(); ++it) { + if(saveAll || (*it)->physicals.size()) { fprintf(fp, "DEF Curve%d IndexedLineSet {\n", (*it)->tag()); fprintf(fp, " coordIndex [\n"); for(unsigned int i = 0; i < (*it)->lines.size(); i++) @@ -229,8 +235,8 @@ int GModel::writeVRML(const std::string &name, bool saveAll, double scalingFacto } } - for(fiter it = firstFace(); it != lastFace(); ++it){ - if(saveAll || (*it)->physicals.size()){ + for(fiter it = firstFace(); it != lastFace(); ++it) { + if(saveAll || (*it)->physicals.size()) { fprintf(fp, "DEF Surface%d IndexedFaceSet {\n", (*it)->tag()); fprintf(fp, " coordIndex [\n"); for(unsigned int i = 0; i < (*it)->triangles.size(); i++) diff --git a/Geo/GModelIO_VTK.cpp b/Geo/GModelIO_VTK.cpp index 342630746453426ad5f8beeccf70b1097ce6e772..d2f2952684e50f0eb272fcc5455be5b44a197e05 100644 --- a/Geo/GModelIO_VTK.cpp +++ b/Geo/GModelIO_VTK.cpp @@ -19,7 +19,7 @@ int GModel::writeVTK(const std::string &name, bool binary, bool saveAll, double scalingFactor, bool bigEndian) { FILE *fp = Fopen(name.c_str(), binary ? "wb" : "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -39,22 +39,23 @@ int GModel::writeVTK(const std::string &name, bool binary, bool saveAll, fprintf(fp, "DATASET UNSTRUCTURED_GRID\n"); // get all the entities in the model - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; getEntities(entities); // write mesh vertices fprintf(fp, "POINTS %d double\n", numVertices); for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) - entities[i]->mesh_vertices[j]->writeVTK(fp, binary, scalingFactor, bigEndian); + entities[i]->mesh_vertices[j]->writeVTK(fp, binary, scalingFactor, + bigEndian); fprintf(fp, "\n"); // loop over all elements we need to save and count vertices int numElements = 0, totalNumInt = 0; - for(unsigned int i = 0; i < entities.size(); i++){ - if(entities[i]->physicals.size() || saveAll){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ - if(entities[i]->getMeshElement(j)->getTypeForVTK()){ + for(unsigned int i = 0; i < entities.size(); i++) { + if(entities[i]->physicals.size() || saveAll) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { + if(entities[i]->getMeshElement(j)->getTypeForVTK()) { numElements++; totalNumInt += entities[i]->getMeshElement(j)->getNumVertices() + 1; } @@ -64,9 +65,9 @@ int GModel::writeVTK(const std::string &name, bool binary, bool saveAll, // print vertex indices in ascii or binary fprintf(fp, "CELLS %d %d\n", numElements, totalNumInt); - for(unsigned int i = 0; i < entities.size(); i++){ - if(entities[i]->physicals.size() || saveAll){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + if(entities[i]->physicals.size() || saveAll) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { if(entities[i]->getMeshElement(j)->getTypeForVTK()) entities[i]->getMeshElement(j)->writeVTK(fp, binary, bigEndian); } @@ -76,14 +77,14 @@ int GModel::writeVTK(const std::string &name, bool binary, bool saveAll, // print element types in ascii or binary fprintf(fp, "CELL_TYPES %d\n", numElements); - for(unsigned int i = 0; i < entities.size(); i++){ - if(entities[i]->physicals.size() || saveAll){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + if(entities[i]->physicals.size() || saveAll) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { int type = entities[i]->getMeshElement(j)->getTypeForVTK(); - if(type){ - if(binary){ + if(type) { + if(binary) { // VTK always expects big endian binary data - if(!bigEndian) SwapBytes((char*)&type, sizeof(int), 1); + if(!bigEndian) SwapBytes((char *)&type, sizeof(int), 1); fwrite(&type, sizeof(int), 1, fp); } else @@ -100,7 +101,7 @@ int GModel::writeVTK(const std::string &name, bool binary, bool saveAll, int GModel::readVTK(const std::string &name, bool bigEndian) { FILE *fp = Fopen(name.c_str(), "rb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } @@ -108,22 +109,31 @@ int GModel::readVTK(const std::string &name, bool bigEndian) char buffer[256], buffer2[256]; std::map<int, std::map<int, std::string> > physicals[4]; - if(!fgets(buffer, sizeof(buffer), fp)){ fclose(fp); return 0; } // version line - if(!fgets(buffer, sizeof(buffer), fp)){ fclose(fp); return 0; } // title + if(!fgets(buffer, sizeof(buffer), fp)) { + fclose(fp); + return 0; + } // version line + if(!fgets(buffer, sizeof(buffer), fp)) { + fclose(fp); + return 0; + } // title if(fscanf(fp, "%s", buffer) != 1) // ASCII or BINARY Msg::Error("Failed reading buffer"); bool binary = false; if(!strcmp(buffer, "BINARY")) binary = true; - if(fscanf(fp, "%s %s", buffer, buffer2) != 2){ fclose(fp); return 0; } + if(fscanf(fp, "%s %s", buffer, buffer2) != 2) { + fclose(fp); + return 0; + } bool unstructured = false; if(!strcmp(buffer, "DATASET") && !strcmp(buffer2, "UNSTRUCTURED_GRID")) unstructured = true; - if((strcmp(buffer, "DATASET") && strcmp(buffer2, "UNSTRUCTURED_GRID")) || - (strcmp(buffer, "DATASET") && strcmp(buffer2, "POLYDATA"))){ + if((strcmp(buffer, "DATASET") && strcmp(buffer2, "UNSTRUCTURED_GRID")) || + (strcmp(buffer, "DATASET") && strcmp(buffer2, "POLYDATA"))) { Msg::Error("VTK reader can only read unstructured or polydata datasets"); fclose(fp); return 0; @@ -132,7 +142,7 @@ int GModel::readVTK(const std::string &name, bool bigEndian) // read mesh vertices int numVertices; if(fscanf(fp, "%s %d %s\n", buffer, &numVertices, buffer2) != 3) return 0; - if(strcmp(buffer, "POINTS") || !numVertices){ + if(strcmp(buffer, "POINTS") || !numVertices) { Msg::Warning("No points in dataset"); fclose(fp); return 0; @@ -142,29 +152,35 @@ int GModel::readVTK(const std::string &name, bool bigEndian) datasize = sizeof(double); else if(!strcmp(buffer2, "float")) datasize = sizeof(float); - else{ + else { Msg::Warning("VTK reader only accepts float or double datasets"); fclose(fp); return 0; } Msg::Info("Reading %d points", numVertices); - std::vector<MVertex*> vertices(numVertices); - for(int i = 0 ; i < numVertices; i++){ + std::vector<MVertex *> vertices(numVertices); + for(int i = 0; i < numVertices; i++) { double xyz[3]; - if(binary){ - if(datasize == sizeof(float)){ + if(binary) { + if(datasize == sizeof(float)) { float f[3]; - if(fread(f, sizeof(float), 3, fp) != 3){ fclose(fp); return 0; } - if(!bigEndian) SwapBytes((char*)f, sizeof(float), 3); + if(fread(f, sizeof(float), 3, fp) != 3) { + fclose(fp); + return 0; + } + if(!bigEndian) SwapBytes((char *)f, sizeof(float), 3); for(int j = 0; j < 3; j++) xyz[j] = f[j]; } - else{ - if(fread(xyz, sizeof(double), 3, fp) != 3){ fclose(fp); return 0; } - if(!bigEndian) SwapBytes((char*)xyz, sizeof(double), 3); + else { + if(fread(xyz, sizeof(double), 3, fp) != 3) { + fclose(fp); + return 0; + } + if(!bigEndian) SwapBytes((char *)xyz, sizeof(double), 3); } } - else{ - if(fscanf(fp, "%lf %lf %lf", &xyz[0], &xyz[1], &xyz[2]) != 3){ + else { + if(fscanf(fp, "%lf %lf %lf", &xyz[0], &xyz[1], &xyz[2]) != 3) { fclose(fp); return 0; } @@ -174,7 +190,7 @@ int GModel::readVTK(const std::string &name, bool bigEndian) // read mesh elements int numElements, totalNumInt; - if(fscanf(fp, "%s %d %d\n", buffer, &numElements, &totalNumInt) != 3){ + if(fscanf(fp, "%s %d %d\n", buffer, &numElements, &totalNumInt) != 3) { fclose(fp); return 0; } @@ -183,122 +199,148 @@ int GModel::readVTK(const std::string &name, bool bigEndian) bool haveLines = false; if(!strcmp(buffer, "CELLS") && numElements > 0) Msg::Info("Reading %d cells", numElements); - else if (!strcmp(buffer, "POLYGONS") && numElements > 0) + else if(!strcmp(buffer, "POLYGONS") && numElements > 0) Msg::Info("Reading %d polygons", numElements); - else if (!strcmp(buffer, "LINES") && numElements > 0){ + else if(!strcmp(buffer, "LINES") && numElements > 0) { haveCells = false; haveLines = true; Msg::Info("Reading %d lines", numElements); } - else{ + else { Msg::Warning("No cells or polygons in dataset"); fclose(fp); return 0; } - std::map<int, std::vector<MElement*> > elements[8]; + std::map<int, std::vector<MElement *> > elements[8]; - if (haveCells){ - std::vector<std::vector<MVertex*> > cells(numElements); - for(unsigned int i = 0; i < cells.size(); i++){ + if(haveCells) { + std::vector<std::vector<MVertex *> > cells(numElements); + for(unsigned int i = 0; i < cells.size(); i++) { int numVerts, n[100]; - if(binary){ - if(fread(&numVerts, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(!bigEndian) SwapBytes((char*)&numVerts, sizeof(int), 1); - if((int)fread(n, sizeof(int), numVerts, fp) != numVerts){ fclose(fp); return 0; } - if(!bigEndian) SwapBytes((char*)n, sizeof(int), numVerts); + if(binary) { + if(fread(&numVerts, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(!bigEndian) SwapBytes((char *)&numVerts, sizeof(int), 1); + if((int)fread(n, sizeof(int), numVerts, fp) != numVerts) { + fclose(fp); + return 0; + } + if(!bigEndian) SwapBytes((char *)n, sizeof(int), numVerts); } - else{ - if(fscanf(fp, "%d", &numVerts) != 1){ fclose(fp); return 0; } - for(int j = 0; j < numVerts; j++){ - if(fscanf(fp, "%d", &n[j]) != 1){ fclose(fp); return 0; } - } + else { + if(fscanf(fp, "%d", &numVerts) != 1) { + fclose(fp); + return 0; + } + for(int j = 0; j < numVerts; j++) { + if(fscanf(fp, "%d", &n[j]) != 1) { + fclose(fp); + return 0; + } + } } - for(int j = 0; j < numVerts; j++){ - if(n[j] >= 0 && n[j] < (int)vertices.size()) - cells[i].push_back(vertices[n[j]]); - else - Msg::Error("Bad vertex index"); + for(int j = 0; j < numVerts; j++) { + if(n[j] >= 0 && n[j] < (int)vertices.size()) + cells[i].push_back(vertices[n[j]]); + else + Msg::Error("Bad vertex index"); } } - if (unstructured){ - if(fscanf(fp, "%s %d\n", buffer, &numElements) != 2 ){ fclose(fp); return 0; } - if(strcmp(buffer, "CELL_TYPES") || numElements != (int)cells.size()){ - Msg::Error("No or invalid number of cells types"); + if(unstructured) { + if(fscanf(fp, "%s %d\n", buffer, &numElements) != 2) { fclose(fp); - return 0; + return 0; } - for(unsigned int i = 0; i < cells.size(); i++){ - int type; - if(binary){ - if(fread(&type, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(!bigEndian) SwapBytes((char*)&type, sizeof(int), 1); - } - else{ - if(fscanf(fp, "%d", &type) != 1){ fclose(fp); return 0; } - } - switch(type){ - case 1: elements[0][1].push_back(new MPoint(cells[i])); break; - // first order elements - case 3: elements[1][1].push_back(new MLine(cells[i])); break; - case 5: elements[2][1].push_back(new MTriangle(cells[i])); break; - case 9: elements[3][1].push_back(new MQuadrangle(cells[i])); break; - case 10: elements[4][1].push_back(new MTetrahedron(cells[i])); break; - case 12: elements[5][1].push_back(new MHexahedron(cells[i])); break; - case 13: elements[6][1].push_back(new MPrism(cells[i])); break; - case 14: elements[7][1].push_back(new MPyramid(cells[i])); break; - // second order elements - case 21: elements[1][1].push_back(new MLine3(cells[i])); break; - case 22: elements[2][1].push_back(new MTriangle6(cells[i])); break; - case 23: elements[3][1].push_back(new MQuadrangle8(cells[i])); break; - case 28: elements[3][1].push_back(new MQuadrangle9(cells[i])); break; - case 24: elements[4][1].push_back(new MTetrahedron10(cells[i])); break; - case 25: elements[5][1].push_back(new MHexahedron20(cells[i])); break; + if(strcmp(buffer, "CELL_TYPES") || numElements != (int)cells.size()) { + Msg::Error("No or invalid number of cells types"); + fclose(fp); + return 0; + } + for(unsigned int i = 0; i < cells.size(); i++) { + int type; + if(binary) { + if(fread(&type, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(!bigEndian) SwapBytes((char *)&type, sizeof(int), 1); + } + else { + if(fscanf(fp, "%d", &type) != 1) { + fclose(fp); + return 0; + } + } + switch(type) { + case 1: + elements[0][1].push_back(new MPoint(cells[i])); + break; + // first order elements + case 3: elements[1][1].push_back(new MLine(cells[i])); break; + case 5: elements[2][1].push_back(new MTriangle(cells[i])); break; + case 9: elements[3][1].push_back(new MQuadrangle(cells[i])); break; + case 10: elements[4][1].push_back(new MTetrahedron(cells[i])); break; + case 12: elements[5][1].push_back(new MHexahedron(cells[i])); break; + case 13: elements[6][1].push_back(new MPrism(cells[i])); break; + case 14: + elements[7][1].push_back(new MPyramid(cells[i])); + break; + // second order elements + case 21: elements[1][1].push_back(new MLine3(cells[i])); break; + case 22: elements[2][1].push_back(new MTriangle6(cells[i])); break; + case 23: elements[3][1].push_back(new MQuadrangle8(cells[i])); break; + case 28: elements[3][1].push_back(new MQuadrangle9(cells[i])); break; + case 24: elements[4][1].push_back(new MTetrahedron10(cells[i])); break; + case 25: elements[5][1].push_back(new MHexahedron20(cells[i])); break; case 29: elements[5][1].push_back(new MHexahedron27(cells[i])); break; - default: - Msg::Error("Unknown type of cell %d", type); - break; - } + default: Msg::Error("Unknown type of cell %d", type); break; + } } } - else{ - for(unsigned int i = 0; i < cells.size(); i++){ - int nbNodes = (int)cells[i].size(); - switch(nbNodes){ - case 1: elements[0][1].push_back(new MPoint(cells[i])); break; - case 2: elements[1][1].push_back(new MLine(cells[i])); break; - case 3: elements[2][1].push_back(new MTriangle(cells[i])); break; - case 4: elements[3][1].push_back(new MQuadrangle(cells[i])); break; - default: - Msg::Error("Unknown type of mesh element with %d nodes", nbNodes); - break; - } + else { + for(unsigned int i = 0; i < cells.size(); i++) { + int nbNodes = (int)cells[i].size(); + switch(nbNodes) { + case 1: elements[0][1].push_back(new MPoint(cells[i])); break; + case 2: elements[1][1].push_back(new MLine(cells[i])); break; + case 3: elements[2][1].push_back(new MTriangle(cells[i])); break; + case 4: elements[3][1].push_back(new MQuadrangle(cells[i])); break; + default: + Msg::Error("Unknown type of mesh element with %d nodes", nbNodes); + break; + } } } } - else if (haveLines){ - if(!binary){ + else if(haveLines) { + if(!binary) { int v0, v1; char line[100000], *p, *pEnd, *pEnd2; int iLine = 1; - for (int k= 0; k < numElements; k++){ - physicals[1][iLine][1] = "centerline"; - if(!fgets(line, sizeof(line), fp)){ fclose(fp); return 0; } - v0 = (int)strtol(line, &pEnd, 10); //ignore first line - v0 = (int)strtol(pEnd, &pEnd2, 10); - p=pEnd2; - while(1){ - v1 = strtol(p, &pEnd, 10); - if (p == pEnd ) break; - elements[1][iLine].push_back(new MLine(vertices[v0],vertices[v1])); - p = pEnd; - v0 = v1; - } - iLine++; + for(int k = 0; k < numElements; k++) { + physicals[1][iLine][1] = "centerline"; + if(!fgets(line, sizeof(line), fp)) { + fclose(fp); + return 0; + } + v0 = (int)strtol(line, &pEnd, 10); // ignore first line + v0 = (int)strtol(pEnd, &pEnd2, 10); + p = pEnd2; + while(1) { + v1 = strtol(p, &pEnd, 10); + if(p == pEnd) break; + elements[1][iLine].push_back(new MLine(vertices[v0], vertices[v1])); + p = pEnd; + v0 = v1; + } + iLine++; } } - else{ + else { Msg::Error("Line import not done for binary VTK files"); } } @@ -309,8 +351,7 @@ int GModel::readVTK(const std::string &name, bool bigEndian) _storeVerticesInEntities(vertices); // store the physical tags - for(int i = 0; i < 4; i++) - _storePhysicalTagsInEntities(i, physicals[i]); + for(int i = 0; i < 4; i++) _storePhysicalTagsInEntities(i, physicals[i]); fclose(fp); return 1; diff --git a/Geo/GModelVertexArrays.cpp b/Geo/GModelVertexArrays.cpp index 59d32c81d93215185c750f0237bbbb27c5ec0956..d3fe630c25a993f258d6946208f3275fd8f51dbc 100644 --- a/Geo/GModelVertexArrays.cpp +++ b/Geo/GModelVertexArrays.cpp @@ -24,32 +24,32 @@ static const double curvedRepTol = 1.e-5; unsigned int getColorByEntity(GEntity *e) { - if(e->getSelection()){ // selection + if(e->getSelection()) { // selection return CTX::instance()->color.geom.selection; } - else if(e->useColor()){ // forced from a script + else if(e->useColor()) { // forced from a script return e->getColor(); } - else if(CTX::instance()->mesh.colorCarousel == 1){ // by elementary entity + else if(CTX::instance()->mesh.colorCarousel == 1) { // by elementary entity return CTX::instance()->color.mesh.carousel[abs(e->tag() % 20)]; } - else if(CTX::instance()->mesh.colorCarousel == 2){ // by physical entity + else if(CTX::instance()->mesh.colorCarousel == 2) { // by physical entity int np = e->physicals.size(); int p = np ? e->physicals[np - 1] : 0; return CTX::instance()->color.mesh.carousel[abs(p % 20)]; } - else{ + else { return CTX::instance()->color.fg; } } static unsigned int getColorByElement(MElement *ele) { - if(ele->getVisibility() > 1){ // selection + if(ele->getVisibility() > 1) { // selection return CTX::instance()->color.geom.selection; } - else if(CTX::instance()->mesh.colorCarousel == 0){ // by element type - switch(ele->getType()){ + else if(CTX::instance()->mesh.colorCarousel == 0) { // by element type + switch(ele->getType()) { case TYPE_LIN: return CTX::instance()->color.mesh.line; case TYPE_TRI: return CTX::instance()->color.mesh.triangle; case TYPE_QUA: return CTX::instance()->color.mesh.quadrangle; @@ -61,18 +61,18 @@ static unsigned int getColorByElement(MElement *ele) default: return CTX::instance()->color.mesh.node; } } - else if(CTX::instance()->mesh.colorCarousel == 3){ // by partition - return CTX::instance()->color.mesh.carousel[std::abs(ele->getPartition() % 20)]; + else if(CTX::instance()->mesh.colorCarousel == 3) { // by partition + return CTX::instance() + ->color.mesh.carousel[std::abs(ele->getPartition() % 20)]; } - else{ + else { // by elementary or physical entity (this is not perfect (since // e.g. a triangle can have no vertices categorized on a surface), // but it's the best we can do "fast" since we don't store the // associated entity in the element - for(std::size_t i = 0; i < ele->getNumVertices(); i++){ + for(std::size_t i = 0; i < ele->getNumVertices(); i++) { GEntity *e = ele->getVertex(i)->onWhat(); - if(e && (e->dim() == ele->getDim())) - return getColorByEntity(e); + if(e && (e->dim() == ele->getDim())) return getColorByEntity(e); } } return CTX::instance()->color.fg; @@ -81,16 +81,16 @@ static unsigned int getColorByElement(MElement *ele) static double evalClipPlane(int clip, double x, double y, double z) { return CTX::instance()->clipPlane[clip][0] * x + - CTX::instance()->clipPlane[clip][1] * y + - CTX::instance()->clipPlane[clip][2] * z + - CTX::instance()->clipPlane[clip][3]; + CTX::instance()->clipPlane[clip][1] * y + + CTX::instance()->clipPlane[clip][2] * z + + CTX::instance()->clipPlane[clip][3]; } static double intersectClipPlane(int clip, MElement *ele) { MVertex *v = ele->getVertex(0); double val = evalClipPlane(clip, v->x(), v->y(), v->z()); - for(std::size_t i = 1; i < ele->getNumVertices(); i++){ + for(std::size_t i = 1; i < ele->getNumVertices(); i++) { v = ele->getVertex(i); if(val * evalClipPlane(clip, v->x(), v->y(), v->z()) <= 0) return 0.; // the element intersects the cut plane @@ -112,27 +112,29 @@ bool isElementVisible(MElement *ele) else q = ele->minSICNShapeMeasure(); if(q < CTX::instance()->mesh.qualityInf || - q > CTX::instance()->mesh.qualitySup) return false; + q > CTX::instance()->mesh.qualitySup) + return false; } if(CTX::instance()->mesh.radiusSup) { double r = ele->maxEdge(); if(r < CTX::instance()->mesh.radiusInf || - r > CTX::instance()->mesh.radiusSup) return false; + r > CTX::instance()->mesh.radiusSup) + return false; } - if(CTX::instance()->clipWholeElements){ + if(CTX::instance()->clipWholeElements) { bool hidden = false; - for(int clip = 0; clip < 6; clip++){ - if(CTX::instance()->mesh.clip & (1 << clip)){ - if(ele->getDim() < 3 && CTX::instance()->clipOnlyVolume){ + for(int clip = 0; clip < 6; clip++) { + if(CTX::instance()->mesh.clip & (1 << clip)) { + if(ele->getDim() < 3 && CTX::instance()->clipOnlyVolume) { } - else{ + else { double d = intersectClipPlane(clip, ele); if(ele->getDim() == 3 && - CTX::instance()->clipOnlyDrawIntersectingVolume && d){ + CTX::instance()->clipOnlyDrawIntersectingVolume && d) { hidden = true; break; } - else if(d < 0){ + else if(d < 0) { hidden = true; break; } @@ -144,37 +146,36 @@ bool isElementVisible(MElement *ele) return true; } -template<class T> -static bool areAllElementsVisible(std::vector<T*> &elements) +template <class T> static bool areAllElementsVisible(std::vector<T *> &elements) { for(unsigned int i = 0; i < elements.size(); i++) if(!isElementVisible(elements[i])) return false; return true; } -template<class T> -static bool areSomeElementsCurved(std::vector<T*> &elements) +template <class T> static bool areSomeElementsCurved(std::vector<T *> &elements) { for(unsigned int i = 0; i < elements.size(); i++) if(elements[i]->getPolynomialOrder() > 1) return true; return false; } -template<class T> -static void addSmoothNormals(GEntity *e, std::vector<T*> &elements) +template <class T> +static void addSmoothNormals(GEntity *e, std::vector<T *> &elements) { - for(unsigned int i = 0; i < elements.size(); i++){ + for(unsigned int i = 0; i < elements.size(); i++) { MElement *ele = elements[i]; - const bool curved = (ele->getPolynomialOrder() > 1) && - (ele->maxDistToStraight() > curvedRepTol*ele->getInnerRadius()); + const bool curved = + (ele->getPolynomialOrder() > 1) && + (ele->maxDistToStraight() > curvedRepTol * ele->getInnerRadius()); SPoint3 pc(0., 0., 0.); if(CTX::instance()->mesh.explode != 1.) pc = ele->barycenter(); - for(int j = 0; j < ele->getNumFacesRep(curved); j++){ + for(int j = 0; j < ele->getNumFacesRep(curved); j++) { double x[3], y[3], z[3]; SVector3 n[3]; ele->getFaceRep(curved, j, x, y, z, n); - for(int k = 0; k < 3; k++){ - if(CTX::instance()->mesh.explode != 1.){ + for(int k = 0; k < 3; k++) { + if(CTX::instance()->mesh.explode != 1.) { x[k] = pc[0] + CTX::instance()->mesh.explode * (x[k] - pc[0]); y[k] = pc[1] + CTX::instance()->mesh.explode * (y[k] - pc[1]); z[k] = pc[2] + CTX::instance()->mesh.explode * (z[k] - pc[2]); @@ -185,11 +186,11 @@ static void addSmoothNormals(GEntity *e, std::vector<T*> &elements) } } -template<class T> -static void addElementsInArrays(GEntity *e, std::vector<T*> &elements, +template <class T> +static void addElementsInArrays(GEntity *e, std::vector<T *> &elements, bool edges, bool faces) { - for(unsigned int i = 0; i < elements.size(); i++){ + for(unsigned int i = 0; i < elements.size(); i++) { MElement *ele = elements[i]; if(!isElementVisible(ele) || ele->getDim() < 1) continue; @@ -197,20 +198,21 @@ static void addElementsInArrays(GEntity *e, std::vector<T*> &elements, unsigned int c = getColorByElement(ele); unsigned int col[4] = {c, c, c, c}; - const bool curved = (ele->getPolynomialOrder() > 1) && - (ele->maxDistToStraight() > curvedRepTol*ele->getInnerRadius()); + const bool curved = + (ele->getPolynomialOrder() > 1) && + (ele->maxDistToStraight() > curvedRepTol * ele->getInnerRadius()); SPoint3 pc(0., 0., 0.); if(CTX::instance()->mesh.explode != 1.) pc = ele->barycenter(); - if(edges){ + if(edges) { bool unique = e->dim() > 1 && !CTX::instance()->pickElements; - for(int j = 0; j < ele->getNumEdgesRep(curved); j++){ + for(int j = 0; j < ele->getNumEdgesRep(curved); j++) { double x[2], y[2], z[2]; SVector3 n[2]; ele->getEdgeRep(curved, j, x, y, z, n); - if(CTX::instance()->mesh.explode != 1.){ - for(int k = 0; k < 2; k++){ + if(CTX::instance()->mesh.explode != 1.) { + for(int k = 0; k < 2; k++) { x[k] = pc[0] + CTX::instance()->mesh.explode * (x[k] - pc[0]); y[k] = pc[1] + CTX::instance()->mesh.explode * (y[k] - pc[1]); z[k] = pc[2] + CTX::instance()->mesh.explode * (z[k] - pc[2]); @@ -218,20 +220,21 @@ static void addElementsInArrays(GEntity *e, std::vector<T*> &elements, } if(e->dim() == 2 && CTX::instance()->mesh.smoothNormals) for(int k = 0; k < 2; k++) - e->model()->normals->get(x[k], y[k], z[k], n[k][0], n[k][1], n[k][2]); + e->model()->normals->get(x[k], y[k], z[k], n[k][0], n[k][1], + n[k][2]); e->va_lines->add(x, y, z, n, col, ele, unique); } } - if(faces){ + if(faces) { bool unique = e->dim() > 2 && !CTX::instance()->pickElements; bool skin = e->dim() > 2 && CTX::instance()->mesh.drawSkinOnly; - for(int j = 0; j < ele->getNumFacesRep(curved); j++){ + for(int j = 0; j < ele->getNumFacesRep(curved); j++) { double x[3], y[3], z[3]; SVector3 n[3]; ele->getFaceRep(curved, j, x, y, z, n); - if(CTX::instance()->mesh.explode != 1.){ - for(int k = 0; k < 3; k++){ + if(CTX::instance()->mesh.explode != 1.) { + for(int k = 0; k < 3; k++) { x[k] = pc[0] + CTX::instance()->mesh.explode * (x[k] - pc[0]); y[k] = pc[1] + CTX::instance()->mesh.explode * (y[k] - pc[1]); z[k] = pc[2] + CTX::instance()->mesh.explode * (z[k] - pc[2]); @@ -239,7 +242,8 @@ static void addElementsInArrays(GEntity *e, std::vector<T*> &elements, } if(e->dim() == 2 && CTX::instance()->mesh.smoothNormals) for(int k = 0; k < 3; k++) - e->model()->normals->get(x[k], y[k], z[k], n[k][0], n[k][1], n[k][2]); + e->model()->normals->get(x[k], y[k], z[k], n[k][0], n[k][1], + n[k][2]); e->va_triangles->add(x, y, z, n, col, ele, unique, skin); } } @@ -247,25 +251,26 @@ static void addElementsInArrays(GEntity *e, std::vector<T*> &elements, } class initMeshGEdge { - private: +private: int _estimateNumLines(GEdge *e) { int num = 0; - if(CTX::instance()->mesh.lines){ + if(CTX::instance()->mesh.lines) { num += e->lines.size(); if(areSomeElementsCurved(e->lines)) num *= 2; } return num + 100; } - public: - void operator () (GEdge *e) + +public: + void operator()(GEdge *e) { e->deleteVertexArrays(); if(!e->getVisibility()) return; e->setAllElementsVisible(CTX::instance()->mesh.lines && areAllElementsVisible(e->lines)); - if(CTX::instance()->mesh.lines){ + if(CTX::instance()->mesh.lines) { e->va_lines = new VertexArray(2, _estimateNumLines(e)); addElementsInArrays(e, e->lines, CTX::instance()->mesh.lines, false); e->va_lines->finalize(); @@ -274,8 +279,8 @@ class initMeshGEdge { }; class initSmoothNormalsGFace { - public: - void operator () (GFace *f) +public: + void operator()(GFace *f) { addSmoothNormals(f, f->triangles); addSmoothNormals(f, f->quadrangles); @@ -284,14 +289,15 @@ class initSmoothNormalsGFace { }; class initMeshGFace { - private: +private: bool _curved; int _estimateNumLines(GFace *f) { int num = 0; - if(CTX::instance()->mesh.surfacesEdges){ + if(CTX::instance()->mesh.surfacesEdges) { num += (3 * f->triangles.size() + 4 * f->quadrangles.size() + - 4 * f->polygons.size()) / 2; + 4 * f->polygons.size()) / + 2; if(CTX::instance()->mesh.explode != 1.) num *= 2; if(_curved) num *= 2; } @@ -300,31 +306,35 @@ class initMeshGFace { int _estimateNumTriangles(GFace *f) { int num = 0; - if(CTX::instance()->mesh.surfacesFaces){ + if(CTX::instance()->mesh.surfacesFaces) { num += (f->triangles.size() + 2 * f->quadrangles.size() + 2 * f->polygons.size()); if(_curved) num *= 4; } return num + 100; } - public: - void operator () (GFace *f) + +public: + void operator()(GFace *f) { f->deleteVertexArrays(); if(!f->getVisibility()) return; - f->setAllElementsVisible - (CTX::instance()->mesh.triangles && areAllElementsVisible(f->triangles) && - CTX::instance()->mesh.quadrangles && areAllElementsVisible(f->quadrangles)); + f->setAllElementsVisible(CTX::instance()->mesh.triangles && + areAllElementsVisible(f->triangles) && + CTX::instance()->mesh.quadrangles && + areAllElementsVisible(f->quadrangles)); bool edg = CTX::instance()->mesh.surfacesEdges; bool fac = CTX::instance()->mesh.surfacesFaces; - if(edg || fac){ + if(edg || fac) { _curved = (areSomeElementsCurved(f->triangles) || areSomeElementsCurved(f->quadrangles)); f->va_lines = new VertexArray(2, _estimateNumLines(f)); f->va_triangles = new VertexArray(3, _estimateNumTriangles(f)); - if(CTX::instance()->mesh.triangles) addElementsInArrays(f, f->triangles, edg, fac); - if(CTX::instance()->mesh.quadrangles) addElementsInArrays(f, f->quadrangles, edg, fac); + if(CTX::instance()->mesh.triangles) + addElementsInArrays(f, f->triangles, edg, fac); + if(CTX::instance()->mesh.quadrangles) + addElementsInArrays(f, f->quadrangles, edg, fac); addElementsInArrays(f, f->polygons, edg, fac); f->va_lines->finalize(); f->va_triangles->finalize(); @@ -333,13 +343,13 @@ class initMeshGFace { }; class initMeshGRegion { - private: +private: bool _curved; int _estimateIfClipped(int num) { if(CTX::instance()->clipWholeElements && - CTX::instance()->clipOnlyDrawIntersectingVolume){ - for(int clip = 0; clip < 6; clip++){ + CTX::instance()->clipOnlyDrawIntersectingVolume) { + for(int clip = 0; clip < 6; clip++) { if(CTX::instance()->mesh.clip & (1 << clip)) return (int)sqrt((double)num); } @@ -349,14 +359,15 @@ class initMeshGRegion { int _estimateNumLines(GRegion *r) { int num = 0; - if(CTX::instance()->mesh.volumesEdges){ + if(CTX::instance()->mesh.volumesEdges) { // suppose edge shared by 4 elements on averge (pessmistic) int numLP = 0; for(unsigned int i = 0; i < r->polyhedra.size(); i++) numLP += 2 * r->polyhedra[i]->getNumEdges(); num += (12 * r->tetrahedra.size() + 24 * r->hexahedra.size() + 18 * r->prisms.size() + 16 * r->pyramids.size() + - 10 * r->trihedra.size() + numLP) / 4; + 10 * r->trihedra.size() + numLP) / + 4; num = _estimateIfClipped(num); if(CTX::instance()->mesh.explode != 1.) num *= 4; if(_curved) num *= 2; @@ -366,34 +377,37 @@ class initMeshGRegion { int _estimateNumTriangles(GRegion *r) { int num = 0; - if(CTX::instance()->mesh.volumesFaces){ + if(CTX::instance()->mesh.volumesFaces) { int numFP = 0; for(unsigned int i = 0; i < r->polyhedra.size(); i++) numFP += r->polyhedra[i]->getNumFaces(); num += (4 * r->tetrahedra.size() + 12 * r->hexahedra.size() + 8 * r->prisms.size() + 6 * r->pyramids.size() + - 4 * r->trihedra.size() + numFP) / 2; + 4 * r->trihedra.size() + numFP) / + 2; num = _estimateIfClipped(num); if(CTX::instance()->mesh.explode != 1.) num *= 2; if(_curved) num *= 4; } return num + 100; } - public: - void operator () (GRegion *r) + +public: + void operator()(GRegion *r) { r->deleteVertexArrays(); if(!r->getVisibility()) return; - r->setAllElementsVisible - (CTX::instance()->mesh.tetrahedra && areAllElementsVisible(r->tetrahedra) && - CTX::instance()->mesh.hexahedra && areAllElementsVisible(r->hexahedra) && - CTX::instance()->mesh.prisms && areAllElementsVisible(r->prisms) && - CTX::instance()->mesh.pyramids && areAllElementsVisible(r->pyramids) && - CTX::instance()->mesh.trihedra && areAllElementsVisible(r->trihedra)); + r->setAllElementsVisible( + CTX::instance()->mesh.tetrahedra && + areAllElementsVisible(r->tetrahedra) && CTX::instance()->mesh.hexahedra && + areAllElementsVisible(r->hexahedra) && CTX::instance()->mesh.prisms && + areAllElementsVisible(r->prisms) && CTX::instance()->mesh.pyramids && + areAllElementsVisible(r->pyramids) && CTX::instance()->mesh.trihedra && + areAllElementsVisible(r->trihedra)); bool edg = CTX::instance()->mesh.volumesEdges; bool fac = CTX::instance()->mesh.volumesFaces; - if(edg || fac){ + if(edg || fac) { _curved = (areSomeElementsCurved(r->tetrahedra) || areSomeElementsCurved(r->hexahedra) || areSomeElementsCurved(r->prisms) || @@ -401,11 +415,16 @@ class initMeshGRegion { areSomeElementsCurved(r->trihedra)); r->va_lines = new VertexArray(2, _estimateNumLines(r)); r->va_triangles = new VertexArray(3, _estimateNumTriangles(r)); - if(CTX::instance()->mesh.tetrahedra) addElementsInArrays(r, r->tetrahedra, edg, fac); - if(CTX::instance()->mesh.hexahedra) addElementsInArrays(r, r->hexahedra, edg, fac); - if(CTX::instance()->mesh.prisms) addElementsInArrays(r, r->prisms, edg, fac); - if(CTX::instance()->mesh.pyramids) addElementsInArrays(r, r->pyramids, edg, fac); - if(CTX::instance()->mesh.trihedra) addElementsInArrays(r, r->trihedra, edg, fac); + if(CTX::instance()->mesh.tetrahedra) + addElementsInArrays(r, r->tetrahedra, edg, fac); + if(CTX::instance()->mesh.hexahedra) + addElementsInArrays(r, r->hexahedra, edg, fac); + if(CTX::instance()->mesh.prisms) + addElementsInArrays(r, r->prisms, edg, fac); + if(CTX::instance()->mesh.pyramids) + addElementsInArrays(r, r->pyramids, edg, fac); + if(CTX::instance()->mesh.trihedra) + addElementsInArrays(r, r->trihedra, edg, fac); addElementsInArrays(r, r->polyhedra, edg, fac); r->va_lines->finalize(); r->va_triangles->finalize(); @@ -424,7 +443,7 @@ bool GModel::fillVertexArrays() if(status >= 1 && CTX::instance()->mesh.changed & ENT_CURVE) std::for_each(firstEdge(), lastEdge(), initMeshGEdge()); - if(status >= 2 && CTX::instance()->mesh.changed & ENT_SURFACE){ + if(status >= 2 && CTX::instance()->mesh.changed & ENT_SURFACE) { if(normals) delete normals; normals = new smooth_normals(CTX::instance()->mesh.angleSmoothNormals); if(CTX::instance()->mesh.smoothNormals) diff --git a/Geo/GPoint.h b/Geo/GPoint.h index c3185ff4eb5675849bdd547260e9cce27896dbbc..1be11f4e967ae04948a79e16b5034c7d84d6a84e 100644 --- a/Geo/GPoint.h +++ b/Geo/GPoint.h @@ -10,14 +10,14 @@ class GEntity; -class GPoint -{ - private: +class GPoint { +private: double X, Y, Z; const GEntity *e; double par[2]; bool success; - public: + +public: inline double x() const { return X; } inline double y() const { return Y; } inline double z() const { return Z; } @@ -26,26 +26,27 @@ class GPoint inline double &z() { return Z; } inline double u() const { return par[0]; } inline double v() const { return par[1]; } - inline const GEntity* g() const { return e; } - GPoint (double _x=0, double _y=0, double _z=0, const GEntity *onwhat=0) + inline const GEntity *g() const { return e; } + GPoint(double _x = 0, double _y = 0, double _z = 0, const GEntity *onwhat = 0) : X(_x), Y(_y), Z(_z), e(onwhat), success(true) { par[0] = -1.; par[1] = -1.; } - GPoint (double _x, double _y, double _z, const GEntity *onwhat, double p) + GPoint(double _x, double _y, double _z, const GEntity *onwhat, double p) : X(_x), Y(_y), Z(_z), e(onwhat), success(true) { par[0] = p; par[1] = -1.; } - GPoint (double _x, double _y, double _z, const GEntity *onwhat, double p[2]) + GPoint(double _x, double _y, double _z, const GEntity *onwhat, double p[2]) : X(_x), Y(_y), Z(_z), e(onwhat), success(true) { par[0] = p[0]; par[1] = p[1]; } - GPoint (double _x, double _y, double _z, const GEntity *onwhat, double p1,double p2) + GPoint(double _x, double _y, double _z, const GEntity *onwhat, double p1, + double p2) : X(_x), Y(_y), Z(_z), e(onwhat), success(true) { par[0] = p1; @@ -58,8 +59,12 @@ class GPoint double dz = Z - p.z(); return sqrt(dx * dx + dy * dy + dz * dz); } - bool succeeded() const{ return success; } - bool setNoSuccess(){ success = false; return success; } + bool succeeded() const { return success; } + bool setNoSuccess() + { + success = false; + return success; + } }; #endif diff --git a/Geo/GRegion.cpp b/Geo/GRegion.cpp index 83bfcd748cc66b8e86df4aef955cda78826d59fc..71861d9ddbf5331c9bd608dd8970800a8121eaf6 100644 --- a/Geo/GRegion.cpp +++ b/Geo/GRegion.cpp @@ -18,16 +18,15 @@ #include "boundaryLayersData.h" #include "GmshDefines.h" -GRegion::GRegion(GModel *model, int tag) - : GEntity (model, tag) +GRegion::GRegion(GModel *model, int tag) : GEntity(model, tag) { resetMeshAttributes(); } GRegion::~GRegion() { - std::vector<GFace*>::iterator it = l_faces.begin(); - while(it != l_faces.end()){ + std::vector<GFace *>::iterator it = l_faces.begin(); + while(it != l_faces.end()) { (*it)->delRegion(this); ++it; } @@ -36,8 +35,9 @@ GRegion::~GRegion() void GRegion::deleteMesh(bool onlyDeleteElements) { - if(!onlyDeleteElements){ - for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i]; + if(!onlyDeleteElements) { + for(unsigned int i = 0; i < mesh_vertices.size(); i++) + delete mesh_vertices[i]; mesh_vertices.clear(); transfinite_vertices.clear(); } @@ -59,18 +59,24 @@ void GRegion::deleteMesh(bool onlyDeleteElements) GRegion::size_type GRegion::getNumMeshElements() const { - return tetrahedra.size() + hexahedra.size() + prisms.size() + pyramids.size() + - trihedra.size() + polyhedra.size(); + return tetrahedra.size() + hexahedra.size() + prisms.size() + + pyramids.size() + trihedra.size() + polyhedra.size(); } unsigned int GRegion::getNumMeshElementsByType(const int familyType) const { - if(familyType == TYPE_TET) return tetrahedra.size(); - else if(familyType == TYPE_HEX) return hexahedra.size(); - else if(familyType == TYPE_PRI) return prisms.size(); - else if(familyType == TYPE_PYR) return pyramids.size(); - else if(familyType == TYPE_TRIH) return trihedra.size(); - else if(familyType == TYPE_POLYH) return polyhedra.size(); + if(familyType == TYPE_TET) + return tetrahedra.size(); + else if(familyType == TYPE_HEX) + return hexahedra.size(); + else if(familyType == TYPE_PRI) + return prisms.size(); + else if(familyType == TYPE_PYR) + return pyramids.size(); + else if(familyType == TYPE_TRIH) + return trihedra.size(); + else if(familyType == TYPE_POLYH) + return polyhedra.size(); return 0; } @@ -79,8 +85,7 @@ unsigned int GRegion::getNumMeshParentElements() { unsigned int n = 0; for(unsigned int i = 0; i < polyhedra.size(); i++) - if(polyhedra[i]->ownsParent()) - n++; + if(polyhedra[i]->ownsParent()) n++; return n; } @@ -128,28 +133,36 @@ MElement *GRegion::getMeshElement(unsigned int index) const else if(index < tetrahedra.size() + hexahedra.size() + prisms.size()) return prisms[index - tetrahedra.size() - hexahedra.size()]; else if(index < tetrahedra.size() + hexahedra.size() + prisms.size() + - pyramids.size()) - return pyramids[index - tetrahedra.size() - hexahedra.size() - prisms.size()]; + pyramids.size()) + return pyramids[index - tetrahedra.size() - hexahedra.size() - + prisms.size()]; else if(index < tetrahedra.size() + hexahedra.size() + prisms.size() + - pyramids.size() + trihedra.size()) - return trihedra[index - tetrahedra.size() - hexahedra.size() - prisms.size() - - pyramids.size()]; + pyramids.size() + trihedra.size()) + return trihedra[index - tetrahedra.size() - hexahedra.size() - + prisms.size() - pyramids.size()]; else if(index < tetrahedra.size() + hexahedra.size() + prisms.size() + - pyramids.size() + trihedra.size() + polyhedra.size()) - return polyhedra[index - tetrahedra.size() - hexahedra.size() - prisms.size() - - pyramids.size() - trihedra.size()]; + pyramids.size() + trihedra.size() + polyhedra.size()) + return polyhedra[index - tetrahedra.size() - hexahedra.size() - + prisms.size() - pyramids.size() - trihedra.size()]; return 0; } -MElement *GRegion::getMeshElementByType(const int familyType, const unsigned int index) const +MElement *GRegion::getMeshElementByType(const int familyType, + const unsigned int index) const { - if(familyType == TYPE_TET) return tetrahedra[index]; - else if(familyType == TYPE_HEX) return hexahedra[index]; - else if(familyType == TYPE_PRI) return prisms[index]; - else if(familyType == TYPE_PYR) return pyramids[index]; - else if(familyType == TYPE_TRIH) return trihedra[index]; - else if(familyType == TYPE_POLYH) return polyhedra[index]; + if(familyType == TYPE_TET) + return tetrahedra[index]; + else if(familyType == TYPE_HEX) + return hexahedra[index]; + else if(familyType == TYPE_PRI) + return prisms[index]; + else if(familyType == TYPE_PYR) + return pyramids[index]; + else if(familyType == TYPE_TRIH) + return trihedra[index]; + else if(familyType == TYPE_POLYH) + return polyhedra[index]; return 0; } @@ -165,12 +178,11 @@ void GRegion::resetMeshAttributes() SBoundingBox3d GRegion::bounds(bool fast) const { SBoundingBox3d res; - if(geomType() != DiscreteVolume && geomType() != PartitionVolume){ - std::vector<GFace*>::const_iterator it = l_faces.begin(); - for(; it != l_faces.end(); it++) - res += (*it)->bounds(fast); + if(geomType() != DiscreteVolume && geomType() != PartitionVolume) { + std::vector<GFace *>::const_iterator it = l_faces.begin(); + for(; it != l_faces.end(); it++) res += (*it)->bounds(fast); } - else{ + else { int ipp = getNumMeshElements() / 20; if(ipp < 1) ipp = 1; for(unsigned int i = 0; i < getNumMeshElements(); i += ipp) @@ -182,46 +194,47 @@ SBoundingBox3d GRegion::bounds(bool fast) const SOrientedBoundingBox GRegion::getOBB() { - if (!_obb) { + if(!_obb) { std::vector<SPoint3> vertices; - std::vector<GFace*> b_faces = faces(); - for (std::vector<GFace*>::iterator b_face = b_faces.begin(); - b_face != b_faces.end(); b_face++) { + std::vector<GFace *> b_faces = faces(); + for(std::vector<GFace *>::iterator b_face = b_faces.begin(); + b_face != b_faces.end(); b_face++) { if((*b_face)->getNumMeshVertices() > 0) { int N = (*b_face)->getNumMeshVertices(); - for (int i = 0; i < N; i++) { - MVertex* mv = (*b_face)->getMeshVertex(i); + for(int i = 0; i < N; i++) { + MVertex *mv = (*b_face)->getMeshVertex(i); vertices.push_back(mv->point()); } - std::vector<GEdge*> eds = (*b_face)->edges(); - for(std::vector<GEdge*>::iterator ed = eds.begin(); ed != eds.end(); ed++) { + std::vector<GEdge *> eds = (*b_face)->edges(); + for(std::vector<GEdge *>::iterator ed = eds.begin(); ed != eds.end(); + ed++) { int N2 = (*ed)->getNumMeshVertices(); - for (int i = 0; i < N2; i++) { - MVertex* mv = (*ed)->getMeshVertex(i); + for(int i = 0; i < N2; i++) { + MVertex *mv = (*ed)->getMeshVertex(i); vertices.push_back(mv->point()); } // Don't forget to add the first and last vertices... SPoint3 pt1((*ed)->getBeginVertex()->x(), (*ed)->getBeginVertex()->y(), (*ed)->getBeginVertex()->z()); - SPoint3 pt2((*ed)->getEndVertex()->x(), - (*ed)->getEndVertex()->y(), + SPoint3 pt2((*ed)->getEndVertex()->x(), (*ed)->getEndVertex()->y(), (*ed)->getEndVertex()->z()); vertices.push_back(pt1); vertices.push_back(pt2); } } - else if ((*b_face)->buildSTLTriangulation()) { + else if((*b_face)->buildSTLTriangulation()) { vertices = (*b_face)->stl_vertices_xyz; } else { int N = 10; - std::vector<GEdge*> b_edges = (*b_face)->edges(); - for (std::vector<GEdge*>::iterator b_edge = b_edges.begin(); - b_edge != b_edges.end(); b_edge++) { + std::vector<GEdge *> b_edges = (*b_face)->edges(); + for(std::vector<GEdge *>::iterator b_edge = b_edges.begin(); + b_edge != b_edges.end(); b_edge++) { Range<double> tr = (*b_edge)->parBounds(0); - for (int j = 0; j < N; j++) { - double t = tr.low() + (double)j / (double)(N - 1) * (tr.high() - tr.low()); + for(int j = 0; j < N; j++) { + double t = + tr.low() + (double)j / (double)(N - 1) * (tr.high() - tr.low()); GPoint p = (*b_edge)->point(t); SPoint3 pt(p.x(), p.y(), p.z()); vertices.push_back(pt); @@ -237,9 +250,9 @@ SOrientedBoundingBox GRegion::getOBB() void GRegion::setVisibility(char val, bool recursive) { GEntity::setVisibility(val); - if(recursive){ - std::vector<GFace*>::iterator it = l_faces.begin(); - while(it != l_faces.end()){ + if(recursive) { + std::vector<GFace *>::iterator it = l_faces.begin(); + while(it != l_faces.end()) { (*it)->setVisibility(val, recursive); ++it; } @@ -249,21 +262,21 @@ void GRegion::setVisibility(char val, bool recursive) void GRegion::setColor(unsigned int val, bool recursive) { GEntity::setColor(val); - if(recursive){ - std::vector<GFace*>::iterator it = l_faces.begin(); - while(it != l_faces.end()){ + if(recursive) { + std::vector<GFace *>::iterator it = l_faces.begin(); + while(it != l_faces.end()) { (*it)->setColor(val, recursive); ++it; } } } -int GRegion::delFace(GFace* face) +int GRegion::delFace(GFace *face) { // TODO C++11 fix the UB if deleting at it == .end() - std::vector<GFace*>::iterator it; + std::vector<GFace *>::iterator it; int pos = 0; - for(it = l_faces.begin(); it != l_faces.end(); ++it){ + for(it = l_faces.begin(); it != l_faces.end(); ++it) { if(*it == face) break; pos++; } @@ -271,8 +284,8 @@ int GRegion::delFace(GFace* face) std::vector<int>::iterator itOri; int posOri = 0, orientation = 0; - for(itOri = l_dirs.begin(); itOri != l_dirs.end(); ++itOri){ - if(posOri == pos){ + for(itOri = l_dirs.begin(); itOri != l_dirs.end(); ++itOri) { + if(posOri == pos) { orientation = *itOri; break; } @@ -286,57 +299,63 @@ int GRegion::delFace(GFace* face) std::string GRegion::getAdditionalInfoString(bool multline) { std::ostringstream sstream; - if(l_faces.size()){ + if(l_faces.size()) { sstream << "Boundary surfaces: "; - for(std::vector<GFace*>::iterator it = l_faces.begin(); - it != l_faces.end(); ++it){ + for(std::vector<GFace *>::iterator it = l_faces.begin(); + it != l_faces.end(); ++it) { if(it != l_faces.begin()) sstream << ", "; sstream << (*it)->tag(); } - if(multline) sstream << "\n"; - else sstream << " "; + if(multline) + sstream << "\n"; + else + sstream << " "; } - if(embedded_faces.size()){ + if(embedded_faces.size()) { sstream << "Embedded surfaces: "; - for(std::vector<GFace*>::iterator it = embedded_faces.begin(); - it != embedded_faces.end(); ++it){ + for(std::vector<GFace *>::iterator it = embedded_faces.begin(); + it != embedded_faces.end(); ++it) { if(it != embedded_faces.begin()) sstream << ", "; sstream << (*it)->tag(); } - if(multline) sstream << "\n"; - else sstream << " "; + if(multline) + sstream << "\n"; + else + sstream << " "; } - if(embedded_edges.size()){ + if(embedded_edges.size()) { sstream << "Embedded curves: "; - for(std::vector<GEdge*>::iterator it = embedded_edges.begin(); - it != embedded_edges.end(); ++it){ + for(std::vector<GEdge *>::iterator it = embedded_edges.begin(); + it != embedded_edges.end(); ++it) { if(it != embedded_edges.begin()) sstream << ", "; sstream << (*it)->tag(); } - if(multline) sstream << "\n"; - else sstream << " "; + if(multline) + sstream << "\n"; + else + sstream << " "; } - if(embedded_vertices.size()){ + if(embedded_vertices.size()) { sstream << "Embedded points: "; - for(std::vector<GVertex*>::iterator it = embedded_vertices.begin(); - it != embedded_vertices.end(); ++it){ + for(std::vector<GVertex *>::iterator it = embedded_vertices.begin(); + it != embedded_vertices.end(); ++it) { if(it != embedded_vertices.begin()) sstream << ", "; sstream << (*it)->tag(); } - if(multline) sstream << "\n"; - else sstream << " "; + if(multline) + sstream << "\n"; + else + sstream << " "; } - if(meshAttributes.method == MESH_TRANSFINITE || meshAttributes.extrude){ + if(meshAttributes.method == MESH_TRANSFINITE || meshAttributes.extrude) { sstream << "Mesh attributes:"; - if(meshAttributes.method == MESH_TRANSFINITE) - sstream << " transfinite"; - if(meshAttributes.extrude) - sstream << " extruded"; + if(meshAttributes.method == MESH_TRANSFINITE) sstream << " transfinite"; + if(meshAttributes.extrude) sstream << " extruded"; } std::string str = sstream.str(); - if(str.size() && (str[str.size()-1] == '\n' || str[str.size()-1] == ' ')) - str.resize(str.size() - 1); + if(str.size() && (str[str.size() - 1] == '\n' || str[str.size() - 1] == ' ')) + str.resize(str.size() - 1); return str; } @@ -344,9 +363,10 @@ void GRegion::writeGEO(FILE *fp) { if(geomType() == DiscreteVolume) return; - if(l_faces.size()){ + if(l_faces.size()) { fprintf(fp, "Surface Loop(%d) = ", tag()); - for(std::vector<GFace*>::iterator it = l_faces.begin(); it != l_faces.end(); it++) { + for(std::vector<GFace *>::iterator it = l_faces.begin(); + it != l_faces.end(); it++) { if(it != l_faces.begin()) fprintf(fp, ", %d", (*it)->tag()); else @@ -356,23 +376,23 @@ void GRegion::writeGEO(FILE *fp) fprintf(fp, "Volume(%d) = {%d};\n", tag(), tag()); } - for(std::vector<GFace*>::iterator it = embedded_faces.begin(); + for(std::vector<GFace *>::iterator it = embedded_faces.begin(); it != embedded_faces.end(); it++) fprintf(fp, "Surface {%d} In Volume {%d};\n", (*it)->tag(), tag()); - for(std::vector<GEdge*>::iterator it = embedded_edges.begin(); + for(std::vector<GEdge *>::iterator it = embedded_edges.begin(); it != embedded_edges.end(); it++) fprintf(fp, "Line {%d} In Volume {%d};\n", (*it)->tag(), tag()); - for(std::vector<GVertex*>::iterator it = embedded_vertices.begin(); + for(std::vector<GVertex *>::iterator it = embedded_vertices.begin(); it != embedded_vertices.end(); it++) fprintf(fp, "Point {%d} In Volume {%d};\n", (*it)->tag(), tag()); - if(meshAttributes.method == MESH_TRANSFINITE){ + if(meshAttributes.method == MESH_TRANSFINITE) { fprintf(fp, "Transfinite Volume {%d}", tag()); - if(meshAttributes.corners.size()){ + if(meshAttributes.corners.size()) { fprintf(fp, " = {"); - for(unsigned int i = 0; i < meshAttributes.corners.size(); i++){ + for(unsigned int i = 0; i < meshAttributes.corners.size(); i++) { if(i) fprintf(fp, ","); fprintf(fp, "%d", meshAttributes.corners[i]->tag()); } @@ -380,24 +400,23 @@ void GRegion::writeGEO(FILE *fp) } fprintf(fp, ";\n"); - if(meshAttributes.QuadTri != NO_QUADTRI ) + if(meshAttributes.QuadTri != NO_QUADTRI) fprintf(fp, "TransfQuadTri {%d};\n", tag()); } } -std::vector<GEdge*> const &GRegion::edges() const +std::vector<GEdge *> const &GRegion::edges() const { // TODO C++11 clean this up - static std::vector<GEdge*> e; + static std::vector<GEdge *> e; e.clear(); - std::vector<GFace*>::const_iterator it = l_faces.begin(); - while(it != l_faces.end()){ - std::vector<GEdge*> const &e2 = (*it)->edges(); - std::vector<GEdge*>::const_iterator it2 = e2.begin(); - while (it2 != e2.end()){ + std::vector<GFace *>::const_iterator it = l_faces.begin(); + while(it != l_faces.end()) { + std::vector<GEdge *> const &e2 = (*it)->edges(); + std::vector<GEdge *>::const_iterator it2 = e2.begin(); + while(it2 != e2.end()) { GEdge *const edge = *it2; - if(std::find(e.begin(), e.end(), edge) == e.end()) - e.push_back(edge); + if(std::find(e.begin(), e.end(), edge) == e.end()) e.push_back(edge); ++it2; } ++it; @@ -407,12 +426,11 @@ std::vector<GEdge*> const &GRegion::edges() const bool GRegion::edgeConnected(GRegion *r) const { - std::vector<GEdge*> e = edges(), e2 = r->edges(); + std::vector<GEdge *> e = edges(), e2 = r->edges(); - std::vector<GEdge*>::const_iterator it = e.begin(); - while(it != e.end()){ - if(std::find(e2.begin(), e2.end(), *it) != e2.end()) - return true; + std::vector<GEdge *>::const_iterator it = e.begin(); + while(it != e.end()) { + if(std::find(e2.begin(), e2.end(), *it) != e2.end()) return true; ++it; } return false; @@ -421,36 +439,38 @@ bool GRegion::edgeConnected(GRegion *r) const double GRegion::computeSolidProperties(std::vector<double> cg, std::vector<double> inertia) { - std::vector<GFace*>::iterator it = l_faces.begin(); + std::vector<GFace *>::iterator it = l_faces.begin(); std::vector<int>::iterator itdir = l_dirs.begin(); double volumex = 0; double volumey = 0; double volumez = 0; double surface = 0; cg[0] = cg[1] = cg[2] = 0.0; - for ( ; it != l_faces.end(); ++it,++itdir){ - for (unsigned int i = 0; i < (*it)->triangles.size(); ++i){ + for(; it != l_faces.end(); ++it, ++itdir) { + for(unsigned int i = 0; i < (*it)->triangles.size(); ++i) { MTriangle *e = (*it)->triangles[i]; int npt; IntPt *pts; - e->getIntegrationPoints (2*(e->getPolynomialOrder()-1)+3, &npt, &pts); - for (int j=0;j<npt;j++){ - SPoint3 pt; - // compute x,y,z of the integration point - e->pnt(pts[j].pt[0], pts[j].pt[1], pts[j].pt[2], pt); - double jac[3][3]; - // compute normal - double detJ = e->getJacobian(pts[j].pt[0], pts[j].pt[1], pts[j].pt[2], jac); - SVector3 n(jac[2][0], jac[2][1], jac[2][2]); - n.normalize(); - n *= (double)*itdir; - surface += detJ* pts[j].weight; - volumex += detJ * n.x() * pt.x() * pts[j].weight; - volumey += detJ * n.y() * pt.y() * pts[j].weight; - volumez += detJ * n.z() * pt.z() * pts[j].weight; - cg[0] += detJ * n.x() * (pt.x() * pt.x()) * pts[j].weight * 0.5; - cg[1] += detJ * n.y() * (pt.y() * pt.y()) * pts[j].weight * 0.5; - cg[2] += detJ * n.z() * (pt.z() * pt.z()) * pts[j].weight * 0.5; + e->getIntegrationPoints(2 * (e->getPolynomialOrder() - 1) + 3, &npt, + &pts); + for(int j = 0; j < npt; j++) { + SPoint3 pt; + // compute x,y,z of the integration point + e->pnt(pts[j].pt[0], pts[j].pt[1], pts[j].pt[2], pt); + double jac[3][3]; + // compute normal + double detJ = + e->getJacobian(pts[j].pt[0], pts[j].pt[1], pts[j].pt[2], jac); + SVector3 n(jac[2][0], jac[2][1], jac[2][2]); + n.normalize(); + n *= (double)*itdir; + surface += detJ * pts[j].weight; + volumex += detJ * n.x() * pt.x() * pts[j].weight; + volumey += detJ * n.y() * pt.y() * pts[j].weight; + volumez += detJ * n.z() * pt.z() * pts[j].weight; + cg[0] += detJ * n.x() * (pt.x() * pt.x()) * pts[j].weight * 0.5; + cg[1] += detJ * n.y() * (pt.y() * pt.y()) * pts[j].weight * 0.5; + cg[2] += detJ * n.z() * (pt.z() * pt.z()) * pts[j].weight * 0.5; } } } @@ -465,139 +485,119 @@ double GRegion::computeSolidProperties(std::vector<double> cg, it = l_faces.begin(); itdir = l_dirs.begin(); - inertia[0] = inertia[1] = inertia[2] = inertia[3] = inertia[4] = inertia[5] = 0.0; + inertia[0] = inertia[1] = inertia[2] = inertia[3] = inertia[4] = inertia[5] = + 0.0; - for ( ; it != l_faces.end(); ++it,++itdir){ - for (unsigned int i = 0; i < (*it)->getNumMeshElements(); ++i){ + for(; it != l_faces.end(); ++it, ++itdir) { + for(unsigned int i = 0; i < (*it)->getNumMeshElements(); ++i) { MElement *e = (*it)->getMeshElement(i); int npt; IntPt *pts; - e->getIntegrationPoints(2 * (e->getPolynomialOrder() - 1) + 3, &npt, &pts); - for (int j = 0; j < npt; j++){ - SPoint3 pt; - // compute x,y,z of the integration point - e->pnt(pts[j].pt[0], pts[j].pt[1], pts[j].pt[2], pt); - double jac[3][3]; - // compute normal - double detJ = e->getJacobian(pts[j].pt[0], pts[j].pt[1], pts[j].pt[2], jac); - SVector3 n(jac[2][0], jac[2][1], jac[2][2]); - n *= (double)*itdir; - inertia[0] += pts[j].weight * detJ * n.x() * - (pt.x() - cg[0]) * (pt.x() - cg[0]) * (pt.x() - cg[0]) / 3.0; - inertia[1] += pts[j].weight * detJ * n.y() * - (pt.y() - cg[1]) * (pt.y() - cg[1]) * (pt.y() - cg[1]) / 3.0; - inertia[2] += pts[j].weight * detJ * n.z() * - (pt.z() - cg[2]) * (pt.z() - cg[2]) * (pt.z() - cg[2]) / 3.0; - inertia[3] += pts[j].weight * detJ * n.x() * - (pt.y() - cg[1]) * (pt.x() - cg[0]) * (pt.x() - cg[0]) / 3.0; - inertia[4] += pts[j].weight * detJ * n.x() * - (pt.z() - cg[2]) * (pt.x() - cg[0]) * (pt.x() - cg[0]) / 3.0; - inertia[5] += pts[j].weight * detJ * n.y() * - (pt.z() - cg[2]) * (pt.y() - cg[1]) * (pt.y() - cg[1]) / 3.0; + e->getIntegrationPoints(2 * (e->getPolynomialOrder() - 1) + 3, &npt, + &pts); + for(int j = 0; j < npt; j++) { + SPoint3 pt; + // compute x,y,z of the integration point + e->pnt(pts[j].pt[0], pts[j].pt[1], pts[j].pt[2], pt); + double jac[3][3]; + // compute normal + double detJ = + e->getJacobian(pts[j].pt[0], pts[j].pt[1], pts[j].pt[2], jac); + SVector3 n(jac[2][0], jac[2][1], jac[2][2]); + n *= (double)*itdir; + inertia[0] += pts[j].weight * detJ * n.x() * (pt.x() - cg[0]) * + (pt.x() - cg[0]) * (pt.x() - cg[0]) / 3.0; + inertia[1] += pts[j].weight * detJ * n.y() * (pt.y() - cg[1]) * + (pt.y() - cg[1]) * (pt.y() - cg[1]) / 3.0; + inertia[2] += pts[j].weight * detJ * n.z() * (pt.z() - cg[2]) * + (pt.z() - cg[2]) * (pt.z() - cg[2]) / 3.0; + inertia[3] += pts[j].weight * detJ * n.x() * (pt.y() - cg[1]) * + (pt.x() - cg[0]) * (pt.x() - cg[0]) / 3.0; + inertia[4] += pts[j].weight * detJ * n.x() * (pt.z() - cg[2]) * + (pt.x() - cg[0]) * (pt.x() - cg[0]) / 3.0; + inertia[5] += pts[j].weight * detJ * n.y() * (pt.z() - cg[2]) * + (pt.y() - cg[1]) * (pt.y() - cg[1]) / 3.0; } } } return volume; } -std::vector<GVertex*> GRegion::vertices() const +std::vector<GVertex *> GRegion::vertices() const { - std::set<GVertex*> v; - for (std::vector<GFace*>::const_iterator it = l_faces.begin(); it != l_faces.end() ; ++it){ - GFace const* const gf = *it; - std::vector<GVertex*> const& vs = gf->vertices(); + std::set<GVertex *> v; + for(std::vector<GFace *>::const_iterator it = l_faces.begin(); + it != l_faces.end(); ++it) { + GFace const *const gf = *it; + std::vector<GVertex *> const &vs = gf->vertices(); v.insert(vs.begin(), vs.end()); } - return std::vector<GVertex*>(v.begin(), v.end()); + return std::vector<GVertex *>(v.begin(), v.end()); } void GRegion::addElement(int type, MElement *e) { - switch (type){ - case TYPE_TET: - addTetrahedron(reinterpret_cast<MTetrahedron*>(e)); - break; - case TYPE_HEX: - addHexahedron(reinterpret_cast<MHexahedron*>(e)); - break; - case TYPE_PRI: - addPrism(reinterpret_cast<MPrism*>(e)); - break; - case TYPE_PYR: - addPyramid(reinterpret_cast<MPyramid*>(e)); - break; - case TYPE_TRIH: - addTrihedron(reinterpret_cast<MTrihedron*>(e)); - break; - case TYPE_POLYH: - addPolyhedron(reinterpret_cast<MPolyhedron*>(e)); - break; - default: - Msg::Error("Trying to add unsupported element in region"); + switch(type) { + case TYPE_TET: addTetrahedron(reinterpret_cast<MTetrahedron *>(e)); break; + case TYPE_HEX: addHexahedron(reinterpret_cast<MHexahedron *>(e)); break; + case TYPE_PRI: addPrism(reinterpret_cast<MPrism *>(e)); break; + case TYPE_PYR: addPyramid(reinterpret_cast<MPyramid *>(e)); break; + case TYPE_TRIH: addTrihedron(reinterpret_cast<MTrihedron *>(e)); break; + case TYPE_POLYH: addPolyhedron(reinterpret_cast<MPolyhedron *>(e)); break; + default: Msg::Error("Trying to add unsupported element in region"); } } void GRegion::removeElement(int type, MElement *e) { - switch (type){ - case TYPE_TET: - { - std::vector<MTetrahedron*>::iterator it = std::find - (tetrahedra.begin(), tetrahedra.end(), reinterpret_cast<MTetrahedron*>(e)); - if(it != tetrahedra.end()) tetrahedra.erase(it); - } - break; - case TYPE_HEX: - { - std::vector<MHexahedron*>::iterator it = std::find - (hexahedra.begin(), hexahedra.end(), reinterpret_cast<MHexahedron*>(e)); - if(it != hexahedra.end()) hexahedra.erase(it); - } - break; - case TYPE_PRI: - { - std::vector<MPrism*>::iterator it = std::find - (prisms.begin(), prisms.end(), reinterpret_cast<MPrism*>(e)); - if(it != prisms.end()) prisms.erase(it); - } - break; - case TYPE_PYR: - { - std::vector<MPyramid*>::iterator it = std::find - (pyramids.begin(), pyramids.end(), reinterpret_cast<MPyramid*>(e)); - if(it != pyramids.end()) pyramids.erase(it); - } - break; - case TYPE_TRIH: - { - std::vector<MTrihedron*>::iterator it = std::find - (trihedra.begin(), trihedra.end(), reinterpret_cast<MTrihedron*>(e)); - if(it != trihedra.end()) trihedra.erase(it); - } - break; - case TYPE_POLYH: - { - std::vector<MPolyhedron*>::iterator it = std::find - (polyhedra.begin(), polyhedra.end(), reinterpret_cast<MPolyhedron*>(e)); - if(it != polyhedra.end()) polyhedra.erase(it); - } - break; - default: - Msg::Error("Trying to remove unsupported element in region"); + switch(type) { + case TYPE_TET: { + std::vector<MTetrahedron *>::iterator it = + std::find(tetrahedra.begin(), tetrahedra.end(), + reinterpret_cast<MTetrahedron *>(e)); + if(it != tetrahedra.end()) tetrahedra.erase(it); + } break; + case TYPE_HEX: { + std::vector<MHexahedron *>::iterator it = std::find( + hexahedra.begin(), hexahedra.end(), reinterpret_cast<MHexahedron *>(e)); + if(it != hexahedra.end()) hexahedra.erase(it); + } break; + case TYPE_PRI: { + std::vector<MPrism *>::iterator it = + std::find(prisms.begin(), prisms.end(), reinterpret_cast<MPrism *>(e)); + if(it != prisms.end()) prisms.erase(it); + } break; + case TYPE_PYR: { + std::vector<MPyramid *>::iterator it = std::find( + pyramids.begin(), pyramids.end(), reinterpret_cast<MPyramid *>(e)); + if(it != pyramids.end()) pyramids.erase(it); + } break; + case TYPE_TRIH: { + std::vector<MTrihedron *>::iterator it = std::find( + trihedra.begin(), trihedra.end(), reinterpret_cast<MTrihedron *>(e)); + if(it != trihedra.end()) trihedra.erase(it); + } break; + case TYPE_POLYH: { + std::vector<MPolyhedron *>::iterator it = std::find( + polyhedra.begin(), polyhedra.end(), reinterpret_cast<MPolyhedron *>(e)); + if(it != polyhedra.end()) polyhedra.erase(it); + } break; + default: Msg::Error("Trying to remove unsupported element in region"); } } bool GRegion::reorder(const int elementType, const std::vector<int> &ordering) { - if(tetrahedra.front()->getTypeForMSH() == elementType){ + if(tetrahedra.front()->getTypeForMSH() == elementType) { if(ordering.size() != tetrahedra.size()) return false; - for(std::vector<int>::const_iterator it = ordering.begin(); it != ordering.end(); ++it){ + for(std::vector<int>::const_iterator it = ordering.begin(); + it != ordering.end(); ++it) { if(*it < 0 || *it >= static_cast<int>(tetrahedra.size())) return false; } - std::vector<MTetrahedron*> newTetrahedraOrder(tetrahedra.size()); - for(unsigned int i = 0; i < ordering.size(); i++){ + std::vector<MTetrahedron *> newTetrahedraOrder(tetrahedra.size()); + for(unsigned int i = 0; i < ordering.size(); i++) { newTetrahedraOrder[i] = tetrahedra[ordering[i]]; } #if __cplusplus >= 201103L @@ -609,15 +609,16 @@ bool GRegion::reorder(const int elementType, const std::vector<int> &ordering) return true; } - if(hexahedra.front()->getTypeForMSH() == elementType){ + if(hexahedra.front()->getTypeForMSH() == elementType) { if(ordering.size() != hexahedra.size()) return false; - for(std::vector<int>::const_iterator it = ordering.begin(); it != ordering.end(); ++it){ + for(std::vector<int>::const_iterator it = ordering.begin(); + it != ordering.end(); ++it) { if(*it < 0 || *it >= static_cast<int>(hexahedra.size())) return false; } - std::vector<MHexahedron*> newHexahedraOrder(hexahedra.size()); - for(unsigned int i = 0; i < ordering.size(); i++){ + std::vector<MHexahedron *> newHexahedraOrder(hexahedra.size()); + for(unsigned int i = 0; i < ordering.size(); i++) { newHexahedraOrder[i] = hexahedra[ordering[i]]; } #if __cplusplus >= 201103L @@ -629,16 +630,16 @@ bool GRegion::reorder(const int elementType, const std::vector<int> &ordering) return true; } - if(prisms.front()->getTypeForMSH() == elementType){ + if(prisms.front()->getTypeForMSH() == elementType) { if(ordering.size() != prisms.size()) return false; for(std::vector<int>::const_iterator it = ordering.begin(); - it != ordering.end(); ++it){ + it != ordering.end(); ++it) { if(*it < 0 || *it >= static_cast<int>(prisms.size())) return false; } - std::vector<MPrism*> newPrismsOrder(prisms.size()); - for(unsigned int i = 0; i < ordering.size(); i++){ + std::vector<MPrism *> newPrismsOrder(prisms.size()); + for(unsigned int i = 0; i < ordering.size(); i++) { newPrismsOrder[i] = prisms[ordering[i]]; } #if __cplusplus >= 201103L @@ -650,16 +651,16 @@ bool GRegion::reorder(const int elementType, const std::vector<int> &ordering) return true; } - if(pyramids.front()->getTypeForMSH() == elementType){ + if(pyramids.front()->getTypeForMSH() == elementType) { if(ordering.size() != pyramids.size()) return false; for(std::vector<int>::const_iterator it = ordering.begin(); - it != ordering.end(); ++it){ + it != ordering.end(); ++it) { if(*it < 0 || *it >= static_cast<int>(pyramids.size())) return false; } - std::vector<MPyramid*> newPyramidsOrder(pyramids.size()); - for(unsigned int i = 0; i < ordering.size(); i++){ + std::vector<MPyramid *> newPyramidsOrder(pyramids.size()); + for(unsigned int i = 0; i < ordering.size(); i++) { newPyramidsOrder[i] = pyramids[ordering[i]]; } #if __cplusplus >= 201103L @@ -671,16 +672,16 @@ bool GRegion::reorder(const int elementType, const std::vector<int> &ordering) return true; } - if(polyhedra.front()->getTypeForMSH() == elementType){ + if(polyhedra.front()->getTypeForMSH() == elementType) { if(ordering.size() != polyhedra.size()) return false; for(std::vector<int>::const_iterator it = ordering.begin(); - it != ordering.end(); ++it){ + it != ordering.end(); ++it) { if(*it < 0 || *it >= static_cast<int>(polyhedra.size())) return false; } - std::vector<MPolyhedron*> newPolyhedraOrder(polyhedra.size()); - for(unsigned int i = 0; i < ordering.size(); i++){ + std::vector<MPolyhedron *> newPolyhedraOrder(polyhedra.size()); + for(unsigned int i = 0; i < ordering.size(); i++) { newPolyhedraOrder[i] = polyhedra[ordering[i]]; } #if __cplusplus >= 201103L @@ -692,16 +693,16 @@ bool GRegion::reorder(const int elementType, const std::vector<int> &ordering) return true; } - if(trihedra.front()->getTypeForMSH() == elementType){ + if(trihedra.front()->getTypeForMSH() == elementType) { if(ordering.size() != trihedra.size()) return false; for(std::vector<int>::const_iterator it = ordering.begin(); - it != ordering.end(); ++it){ + it != ordering.end(); ++it) { if(*it < 0 || *it >= static_cast<int>(trihedra.size())) return false; } - std::vector<MTrihedron*> newTrihedraOrder(trihedra.size()); - for(unsigned int i = 0; i < ordering.size(); i++){ + std::vector<MTrihedron *> newTrihedraOrder(trihedra.size()); + for(unsigned int i = 0; i < ordering.size(); i++) { newTrihedraOrder[i] = trihedra[ordering[i]]; } #if __cplusplus >= 201103L @@ -726,8 +727,9 @@ static void setRand(double r[6]) // Y_1 (1-u-v) + Y_2 u + Y_3 v = P_y + t N_y // Z_1 (1-u-v) + Z_2 u + Z_3 v = P_z + t N_z -static int intersectLineTriangle(double X[3], double Y[3], double Z[3] , - double P[3], double N[3], const double eps_prec) +static int intersectLineTriangle(double X[3], double Y[3], double Z[3], + double P[3], double N[3], + const double eps_prec) { double mat[3][3], det; double b[3], res[3]; @@ -748,22 +750,22 @@ static int intersectLineTriangle(double X[3], double Y[3], double Z[3] , b[1] = P[1] - Y[0]; b[2] = P[2] - Z[0]; - if(!sys3x3_with_tol(mat, b, res, &det)){ + if(!sys3x3_with_tol(mat, b, res, &det)) { return 0; } - if(res[0] >= eps_prec && res[0] <= 1.0 - eps_prec && - res[1] >= eps_prec && res[1] <= 1.0 - eps_prec && - 1 - res[0] - res[1] >= eps_prec && 1 - res[0] - res[1] <= 1.0 - eps_prec){ + if(res[0] >= eps_prec && res[0] <= 1.0 - eps_prec && res[1] >= eps_prec && + res[1] <= 1.0 - eps_prec && 1 - res[0] - res[1] >= eps_prec && + 1 - res[0] - res[1] <= 1.0 - eps_prec) { // the line clearly intersects the triangle return (res[2] > 0) ? 1 : 0; } - else if(res[0] < -eps_prec || res[0] > 1.0 + eps_prec || - res[1] < -eps_prec || res[1] > 1.0 + eps_prec || - 1 - res[0] - res[1] < -eps_prec || 1 - res[0] - res[1] > 1.0 + eps_prec){ + else if(res[0] < -eps_prec || res[0] > 1.0 + eps_prec || res[1] < -eps_prec || + res[1] > 1.0 + eps_prec || 1 - res[0] - res[1] < -eps_prec || + 1 - res[0] - res[1] > 1.0 + eps_prec) { // the line clearly does NOT intersect the triangle return 0; } - else{ + else { // the intersection is not robust, try another triangle return -10000; } @@ -774,37 +776,36 @@ bool GRegion::setOutwardOrientationMeshConstraint() // perform intersection check in normalized coordinates SBoundingBox3d bbox = bounds(); double scaling = norm(SVector3(bbox.max(), bbox.min())); - if(!scaling){ + if(!scaling) { Msg::Warning("Bad scaling in GRegion::setOutwardOrientationMeshConstraint"); scaling = 1.; } double rrr[6]; setRand(rrr); - std::vector<GFace*> f = faces(); - std::vector<GFace*>::iterator it = f.begin(); - while(it != f.end()){ + std::vector<GFace *> f = faces(); + std::vector<GFace *>::iterator it = f.begin(); + while(it != f.end()) { GFace *gf = (*it); gf->buildSTLTriangulation(); - if(gf->stl_triangles.size() < 3){ + if(gf->stl_triangles.size() < 3) { Msg::Error("No valid STL triangulation found for surface %d", gf->tag()); return false; } int nb_intersect = 0; - for(unsigned int i = 0; i < gf->stl_triangles.size(); i += 3){ + for(unsigned int i = 0; i < gf->stl_triangles.size(); i += 3) { SPoint3 p1 = gf->stl_vertices_xyz[gf->stl_triangles[i]]; SPoint3 p2 = gf->stl_vertices_xyz[gf->stl_triangles[i + 1]]; SPoint3 p3 = gf->stl_vertices_xyz[gf->stl_triangles[i + 2]]; double X[3] = {p1.x(), p2.x(), p3.x()}; double Y[3] = {p1.y(), p2.y(), p3.y()}; double Z[3] = {p1.z(), p2.z(), p3.z()}; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { X[j] /= scaling; Y[j] /= scaling; Z[j] /= scaling; } - double P[3] = {(X[0] + X[1] + X[2]) / 3., - (Y[0] + Y[1] + Y[2]) / 3., + double P[3] = {(X[0] + X[1] + X[2]) / 3., (Y[0] + Y[1] + Y[2]) / 3., (Z[0] + Z[1] + Z[2]) / 3.}; double v1[3] = {X[0] - X[1], Y[0] - Y[1], Z[0] - Z[1]}; double v2[3] = {X[2] - X[1], Y[2] - Y[1], Z[2] - Z[1]}; @@ -817,22 +818,23 @@ bool GRegion::setOutwardOrientationMeshConstraint() N[1] += rrr[2] * v1[1] + rrr[3] * v2[1]; N[2] += rrr[4] * v1[2] + rrr[5] * v2[2]; norme(N); - std::vector<GFace*>::iterator it_b = f.begin(); - while(it_b != f.end()){ + std::vector<GFace *>::iterator it_b = f.begin(); + while(it_b != f.end()) { GFace *gf_b = (*it_b); gf_b->buildSTLTriangulation(); - if(gf_b->stl_triangles.size() < 3){ - Msg::Error("No valid STL triangulation found for surface %d", gf_b->tag()); + if(gf_b->stl_triangles.size() < 3) { + Msg::Error("No valid STL triangulation found for surface %d", + gf_b->tag()); return false; } - for(unsigned int i_b = 0; i_b < gf_b->stl_triangles.size(); i_b += 3){ + for(unsigned int i_b = 0; i_b < gf_b->stl_triangles.size(); i_b += 3) { SPoint3 p1 = gf_b->stl_vertices_xyz[gf_b->stl_triangles[i_b]]; SPoint3 p2 = gf_b->stl_vertices_xyz[gf_b->stl_triangles[i_b + 1]]; SPoint3 p3 = gf_b->stl_vertices_xyz[gf_b->stl_triangles[i_b + 2]]; double X_b[3] = {p1.x(), p2.x(), p3.x()}; double Y_b[3] = {p1.y(), p2.y(), p3.y()}; double Z_b[3] = {p1.z(), p2.z(), p3.z()}; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { X_b[j] /= scaling; Y_b[j] /= scaling; Z_b[j] /= scaling; @@ -845,22 +847,24 @@ bool GRegion::setOutwardOrientationMeshConstraint() std::abs(Y[2] - Y_b[2]) < 1e-12 && std::abs(Z[0] - Z_b[0]) < 1e-12 && std::abs(Z[1] - Z_b[1]) < 1e-12 && - std::abs(Z[2] - Z_b[2]) < 1e-12)){ + std::abs(Z[2] - Z_b[2]) < 1e-12)) { int inters = intersectLineTriangle(X_b, Y_b, Z_b, P, N, 1.e-9); nb_intersect += inters; } } ++it_b; } - Msg::Info("Region %d Face %d, %d intersect", tag(), gf->tag(), nb_intersect); - if(nb_intersect >= 0) break; // negative value means intersection is not "robust" + Msg::Info("Region %d Face %d, %d intersect", tag(), gf->tag(), + nb_intersect); + if(nb_intersect >= 0) + break; // negative value means intersection is not "robust" } - if(nb_intersect < 0){ + if(nb_intersect < 0) { setRand(rrr); } - else{ - if(nb_intersect % 2 == 1){ + else { + if(nb_intersect % 2 == 1) { // odd nb of intersections: the normal points inside the region gf->meshAttributes.reverseMesh = true; Msg::Info("Setting reverse mesh attribute on surface %d", gf->tag()); diff --git a/Geo/GVertex.cpp b/Geo/GVertex.cpp index 54c6cfd514dadec77e6d1f91d6c43ddec9f14809..c363f685592bf6cc327d33406cecfdc6f7e11d71 100644 --- a/Geo/GVertex.cpp +++ b/Geo/GVertex.cpp @@ -15,15 +15,13 @@ GVertex::GVertex(GModel *m, int tag, double ms) : GEntity(m, tag), meshSize(ms) { } -GVertex::~GVertex() -{ - deleteMesh(); -} +GVertex::~GVertex() { deleteMesh(); } void GVertex::deleteMesh(bool onlyDeleteElements) { - if(!onlyDeleteElements){ - for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i]; + if(!onlyDeleteElements) { + for(unsigned int i = 0; i < mesh_vertices.size(); i++) + delete mesh_vertices[i]; mesh_vertices.clear(); } for(unsigned int i = 0; i < points.size(); i++) delete points[i]; @@ -32,10 +30,7 @@ void GVertex::deleteMesh(bool onlyDeleteElements) model()->destroyMeshCaches(); } -void GVertex::resetMeshAttributes() -{ - meshSize = MAX_LC; -} +void GVertex::resetMeshAttributes() { meshSize = MAX_LC; } void GVertex::setPosition(GPoint &p) { @@ -50,7 +45,8 @@ void GVertex::addEdge(GEdge *e) void GVertex::delEdge(GEdge *const e) { - std::vector<GEdge*>::iterator it = std::find(l_edges.begin(), l_edges.end(), e); + std::vector<GEdge *>::iterator it = + std::find(l_edges.begin(), l_edges.end(), e); if(it != l_edges.end()) l_edges.erase(it); } @@ -65,9 +61,11 @@ std::string GVertex::getAdditionalInfoString(bool multline) sstream.precision(12); sstream << "Position (" << x() << ", " << y() << ", " << z() << ")"; double lc = prescribedMeshSizeAtVertex(); - if(lc < MAX_LC){ - if(multline) sstream << "\n"; - else sstream << " "; + if(lc < MAX_LC) { + if(multline) + sstream << "\n"; + else + sstream << " "; sstream << "Mesh attributes: size " << lc; } return sstream.str(); @@ -76,14 +74,13 @@ std::string GVertex::getAdditionalInfoString(bool multline) void GVertex::writeGEO(FILE *fp, const std::string &meshSizeParameter) { if(meshSizeParameter.size()) - fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %s};\n", - tag(), x(), y(), z(), meshSizeParameter.c_str()); + fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %s};\n", tag(), x(), y(), + z(), meshSizeParameter.c_str()); else if(prescribedMeshSizeAtVertex() != MAX_LC) - fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %.16g};\n", - tag(), x(), y(), z(), prescribedMeshSizeAtVertex()); + fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %.16g};\n", tag(), x(), y(), + z(), prescribedMeshSizeAtVertex()); else - fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g};\n", - tag(), x(), y(), z()); + fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g};\n", tag(), x(), y(), z()); } unsigned int GVertex::getNumMeshElementsByType(const int familyType) const @@ -100,12 +97,12 @@ void GVertex::getNumMeshElements(unsigned *const c) const MElement *GVertex::getMeshElement(unsigned int index) const { - if(index < points.size()) - return points[index]; + if(index < points.size()) return points[index]; return 0; } -MElement *GVertex::getMeshElementByType(const int familyType, const unsigned int index) const +MElement *GVertex::getMeshElementByType(const int familyType, + const unsigned int index) const { if(familyType == TYPE_PNT) return points[index]; @@ -115,9 +112,9 @@ MElement *GVertex::getMeshElementByType(const int familyType, const unsigned int bool GVertex::isOnSeam(const GFace *gf) const { // TODO C++11 std::find_if - std::vector<GEdge*>::const_iterator eIter = l_edges.begin(); - for (; eIter != l_edges.end(); eIter++) { - if ( (*eIter)->isSeam(gf) ) return true; + std::vector<GEdge *>::const_iterator eIter = l_edges.begin(); + for(; eIter != l_edges.end(); eIter++) { + if((*eIter)->isSeam(gf)) return true; } return false; } @@ -129,7 +126,7 @@ std::vector<GFace *> GVertex::faces() const for(std::vector<GEdge *>::const_iterator it = l_edges.begin(); it != l_edges.end(); ++it) { - std::vector<GFace *> const& temp = (*it)->faces(); + std::vector<GFace *> const &temp = (*it)->faces(); faces.insert(faces.end(), temp.begin(), temp.end()); } std::sort(faces.begin(), faces.end()); @@ -139,23 +136,23 @@ std::vector<GFace *> GVertex::faces() const } // regions that bound this entity or that this entity bounds. -std::list<GRegion*> GVertex::regions() const +std::list<GRegion *> GVertex::regions() const { - std::vector<GFace*> const _faces = faces(); - std::vector<GFace*>::const_iterator it = _faces.begin(); - std::set<GRegion*> _r; - for ( ; it != _faces.end() ; ++it){ - std::list<GRegion*> temp = (*it)->regions(); + std::vector<GFace *> const _faces = faces(); + std::vector<GFace *>::const_iterator it = _faces.begin(); + std::set<GRegion *> _r; + for(; it != _faces.end(); ++it) { + std::list<GRegion *> temp = (*it)->regions(); _r.insert(temp.begin(), temp.end()); } - std::list<GRegion*> ret; + std::list<GRegion *> ret; ret.insert(ret.begin(), _r.begin(), _r.end()); return ret; } void GVertex::relocateMeshVertices() { - for(unsigned int i = 0; i < mesh_vertices.size(); i++){ + for(unsigned int i = 0; i < mesh_vertices.size(); i++) { MVertex *v = mesh_vertices[i]; v->x() = x(); v->y() = y(); @@ -165,42 +162,36 @@ void GVertex::relocateMeshVertices() void GVertex::addElement(int type, MElement *e) { - switch (type){ - case TYPE_PNT: - addPoint(reinterpret_cast<MPoint*>(e)); - break; - default: - Msg::Error("Trying to add unsupported element in vertex"); + switch(type) { + case TYPE_PNT: addPoint(reinterpret_cast<MPoint *>(e)); break; + default: Msg::Error("Trying to add unsupported element in vertex"); } } void GVertex::removeElement(int type, MElement *e) { - switch (type){ - case TYPE_PNT: - { - std::vector<MPoint*>::iterator it = std::find - (points.begin(), points.end(), reinterpret_cast<MPoint*>(e)); - if(it != points.end()) points.erase(it); - } - break; - default: - Msg::Error("Trying to remove unsupported element in vertex"); + switch(type) { + case TYPE_PNT: { + std::vector<MPoint *>::iterator it = + std::find(points.begin(), points.end(), reinterpret_cast<MPoint *>(e)); + if(it != points.end()) points.erase(it); + } break; + default: Msg::Error("Trying to remove unsupported element in vertex"); } } bool GVertex::reorder(const int elementType, const std::vector<int> &ordering) { - if(points.front()->getTypeForMSH() == elementType){ + if(points.front()->getTypeForMSH() == elementType) { if(ordering.size() != points.size()) return false; for(std::vector<int>::const_iterator it = ordering.begin(); - it != ordering.end(); ++it){ + it != ordering.end(); ++it) { if(*it < 0 || *it >= static_cast<int>(points.size())) return false; } - std::vector<MPoint*> newPointsOrder(points.size()); - for(unsigned int i = 0; i < ordering.size(); i++){ + std::vector<MPoint *> newPointsOrder(points.size()); + for(unsigned int i = 0; i < ordering.size(); i++) { newPointsOrder[i] = points[ordering[i]]; } #if __cplusplus >= 201103L diff --git a/Geo/GenericEdge.cpp b/Geo/GenericEdge.cpp index 637f9366aa59e64c02a780d4297efd186d08fa0b..f338be144d18e8ef8c45c375740d0f7ada19a676 100644 --- a/Geo/GenericEdge.cpp +++ b/Geo/GenericEdge.cpp @@ -13,27 +13,33 @@ #include "GenericFace.h" #include "Context.h" -GenericEdge::ptrfunction_int_double_refvector GenericEdge::EdgeEvalXYZFromT = NULL; -GenericEdge::ptrfunction_int_refdouble_refdouble GenericEdge::EdgeEvalParBounds = NULL; +GenericEdge::ptrfunction_int_double_refvector GenericEdge::EdgeEvalXYZFromT = + NULL; +GenericEdge::ptrfunction_int_refdouble_refdouble + GenericEdge::EdgeEvalParBounds = NULL; GenericEdge::ptrfunction_int_refstring GenericEdge::EdgeGeomType = NULL; GenericEdge::ptrfunction_int_refbool GenericEdge::EdgeDegenerated = NULL; -GenericEdge::ptrfunction_int_double_refvector GenericEdge::EdgeEvalFirstDer = NULL; -GenericEdge::ptrfunction_int_double_refdouble GenericEdge::EdgeEvalCurvature = NULL; -GenericEdge::ptrfunction_int_refvector_refdouble_refvector_refbool GenericEdge::EdgeClosestPoint = NULL; +GenericEdge::ptrfunction_int_double_refvector GenericEdge::EdgeEvalFirstDer = + NULL; +GenericEdge::ptrfunction_int_double_refdouble GenericEdge::EdgeEvalCurvature = + NULL; +GenericEdge::ptrfunction_int_refvector_refdouble_refvector_refbool + GenericEdge::EdgeClosestPoint = NULL; GenericEdge::ptrfunction_int_refbool GenericEdge::EdgeIs3D = NULL; -GenericEdge::ptrfunction_int_int_double_int_refvector GenericEdge::EdgeReparamOnFace = NULL; +GenericEdge::ptrfunction_int_int_double_int_refvector + GenericEdge::EdgeReparamOnFace = NULL; -GenericEdge::GenericEdge(GModel *m, int num, int _native_id, GVertex *v1, GVertex *v2, bool _isseam) - : GEdge(m, num, v1, v2), id(_native_id),is_seam(_isseam) +GenericEdge::GenericEdge(GModel *m, int num, int _native_id, GVertex *v1, + GVertex *v2, bool _isseam) + : GEdge(m, num, v1, v2), id(_native_id), is_seam(_isseam) { - if ((!EdgeEvalParBounds)||(!EdgeEvalXYZFromT)) Msg::Error("GenericEdge::ERROR: Callback not set"); - bool ok = EdgeEvalParBounds(id,s0,s1); - if (!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalParBounds ! " ); + if((!EdgeEvalParBounds) || (!EdgeEvalXYZFromT)) + Msg::Error("GenericEdge::ERROR: Callback not set"); + bool ok = EdgeEvalParBounds(id, s0, s1); + if(!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalParBounds ! "); } -GenericEdge::~GenericEdge() -{ -} +GenericEdge::~GenericEdge() {} Range<double> GenericEdge::parBounds(int i) const { @@ -42,81 +48,89 @@ Range<double> GenericEdge::parBounds(int i) const SPoint2 GenericEdge::reparamOnFace(const GFace *face, double par, int dir) const { - std::vector<double> res(2,0.); - if (!EdgeReparamOnFace) Msg::Error("GenericEdge::ERROR: Callback EdgeReparamOnFace not set"); - bool ok = EdgeReparamOnFace(id,face->getNativeInt(),par, dir,res); - if (!ok){ - Msg::Error("GenericEdge::ERROR from EdgeReparamOnFace ! Edge Native id %d",getNativeInt() ); + std::vector<double> res(2, 0.); + if(!EdgeReparamOnFace) + Msg::Error("GenericEdge::ERROR: Callback EdgeReparamOnFace not set"); + bool ok = EdgeReparamOnFace(id, face->getNativeInt(), par, dir, res); + if(!ok) { + Msg::Error("GenericEdge::ERROR from EdgeReparamOnFace ! Edge Native id %d", + getNativeInt()); } - return SPoint2(res[0],res[1]);; + return SPoint2(res[0], res[1]); + ; } GPoint GenericEdge::closestPoint(const SPoint3 &qp, double ¶m) const { - std::vector<double> queryPoint(3,0.); - for (int i=0;i<3;i++) queryPoint[i] = qp[i]; - std::vector<double> res(3,0.); + std::vector<double> queryPoint(3, 0.); + for(int i = 0; i < 3; i++) queryPoint[i] = qp[i]; + std::vector<double> res(3, 0.); bool is_on_edge; - if (!EdgeClosestPoint) Msg::Error("GenericEdge::ERROR: Callback EdgeClosestPoint not set"); - bool ok = EdgeClosestPoint(id,queryPoint,param,res,is_on_edge); - if (!ok) Msg::Error("GenericEdge::ERROR from EdgeClosestPoint ! " ); - if (!is_on_edge) Msg::Warning("WARNING:GenericEdge::closestPoint closest point NOT on edge, out of bounds ! " ); + if(!EdgeClosestPoint) + Msg::Error("GenericEdge::ERROR: Callback EdgeClosestPoint not set"); + bool ok = EdgeClosestPoint(id, queryPoint, param, res, is_on_edge); + if(!ok) Msg::Error("GenericEdge::ERROR from EdgeClosestPoint ! "); + if(!is_on_edge) + Msg::Warning("WARNING:GenericEdge::closestPoint closest point NOT on edge, " + "out of bounds ! "); return GPoint(res[0], res[1], res[2], this, param); } -bool GenericEdge::isSeam(const GFace *face) const -{ - return is_seam; -} +bool GenericEdge::isSeam(const GFace *face) const { return is_seam; } GPoint GenericEdge::point(double par) const { - std::vector<double> res(3,0.); - if (!EdgeEvalXYZFromT) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalXYZFromT not set"); - bool ok = EdgeEvalXYZFromT(id,par,res); - if (!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalXYZFromT ! " ); + std::vector<double> res(3, 0.); + if(!EdgeEvalXYZFromT) + Msg::Error("GenericEdge::ERROR: Callback EdgeEvalXYZFromT not set"); + bool ok = EdgeEvalXYZFromT(id, par, res); + if(!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalXYZFromT ! "); return GPoint(res[0], res[1], res[2], this, par); } SVector3 GenericEdge::firstDer(double par) const { - std::vector<double> res(3,0.); - if (!EdgeEvalFirstDer) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalFirstDer not set"); - bool ok = EdgeEvalFirstDer(id,par,res); - if (!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalFirstDer ! " ); - return SVector3(res[0],res[1],res[2]); + std::vector<double> res(3, 0.); + if(!EdgeEvalFirstDer) + Msg::Error("GenericEdge::ERROR: Callback EdgeEvalFirstDer not set"); + bool ok = EdgeEvalFirstDer(id, par, res); + if(!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalFirstDer ! "); + return SVector3(res[0], res[1], res[2]); } GEntity::GeomType GenericEdge::geomType() const { std::string s; - if (!EdgeGeomType) Msg::Error("GenericEdge::ERROR: Callback EdgeGeomType not set"); - bool ok = EdgeGeomType(id,s); - if (!ok){ - Msg::Error("GenericEdge::ERROR from EdgeGeomType ! Edge Native id %d",getNativeInt() ); + if(!EdgeGeomType) + Msg::Error("GenericEdge::ERROR: Callback EdgeGeomType not set"); + bool ok = EdgeGeomType(id, s); + if(!ok) { + Msg::Error("GenericEdge::ERROR from EdgeGeomType ! Edge Native id %d", + getNativeInt()); return Unknown; } - if(s.compare("Line")==0) + if(s.compare("Line") == 0) return Line; - else if(s.compare("Circle")==0) + else if(s.compare("Circle") == 0) return Circle; - else if(s.compare("Ellipse")==0) + else if(s.compare("Ellipse") == 0) return Ellipse; - else if(s.compare("Parabola")==0) + else if(s.compare("Parabola") == 0) return Parabola; - else if(s.compare("Hyperbola")==0) + else if(s.compare("Hyperbola") == 0) return Hyperbola; - else if(s.compare("Bezier")==0) + else if(s.compare("Bezier") == 0) return Bezier; - else if(s.compare("BSpline")==0) + else if(s.compare("BSpline") == 0) return BSpline; - else if(s.compare("TrimmedCurve")==0) + else if(s.compare("TrimmedCurve") == 0) return TrimmedCurve; - else if(s.compare("Intersection curve")==0) + else if(s.compare("Intersection curve") == 0) return BSpline; - Msg::Warning("GenericEdge::geomType:: unknown type from callback: %s", s.c_str()); + Msg::Warning("GenericEdge::geomType:: unknown type from callback: %s", + s.c_str()); return Unknown; } @@ -124,27 +138,29 @@ GEntity::GeomType GenericEdge::geomType() const double GenericEdge::curvature(double par) const { double res; - if (!EdgeEvalCurvature) Msg::Error("GenericEdge::ERROR: Callback EdgeEvalCurvature not set"); - bool ok = EdgeEvalCurvature(id,par,res); - if (!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalCurvature ! " ); + if(!EdgeEvalCurvature) + Msg::Error("GenericEdge::ERROR: Callback EdgeEvalCurvature not set"); + bool ok = EdgeEvalCurvature(id, par, res); + if(!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalCurvature ! "); return res; } bool GenericEdge::is3D() const { bool res; - if (!EdgeIs3D) Msg::Error("GenericEdge::ERROR: Callback EdgeIs3D not set"); - bool ok = EdgeIs3D(id,res); - if (!ok) Msg::Error("GenericEdge::ERROR from EdgeIs3D ! " ); + if(!EdgeIs3D) Msg::Error("GenericEdge::ERROR: Callback EdgeIs3D not set"); + bool ok = EdgeIs3D(id, res); + if(!ok) Msg::Error("GenericEdge::ERROR from EdgeIs3D ! "); return res; } bool GenericEdge::degenerate(int) const { - bool res=false; - if (!EdgeDegenerated) Msg::Error("GenericEdge::ERROR: Callback EdgeDegenerated not set"); - bool ok = EdgeDegenerated(id,res); - if (!ok) Msg::Error("GenericEdge::ERROR from EdgeDegenerated ! " ); + bool res = false; + if(!EdgeDegenerated) + Msg::Error("GenericEdge::ERROR: Callback EdgeDegenerated not set"); + bool ok = EdgeDegenerated(id, res); + if(!ok) Msg::Error("GenericEdge::ERROR from EdgeDegenerated ! "); return res; } @@ -156,17 +172,16 @@ int GenericEdge::minimumDrawSegments() const return CTX::instance()->geom.numSubEdges * GEdge::minimumDrawSegments(); } -LinearSeamEdge::LinearSeamEdge(GModel *m, int num, GVertex *v1, GVertex *v2):GEdge(m, num, v1, v2) +LinearSeamEdge::LinearSeamEdge(GModel *m, int num, GVertex *v1, GVertex *v2) + : GEdge(m, num, v1, v2) { - s0=0.; - s1=v1->xyz().distance(v2->xyz()); - first_der = SVector3(v1->xyz(),v2->xyz()); + s0 = 0.; + s1 = v1->xyz().distance(v2->xyz()); + first_der = SVector3(v1->xyz(), v2->xyz()); first_der.normalize(); } -LinearSeamEdge::~LinearSeamEdge() -{ -} +LinearSeamEdge::~LinearSeamEdge() {} Range<double> LinearSeamEdge::parBounds(int i) const { @@ -175,36 +190,21 @@ Range<double> LinearSeamEdge::parBounds(int i) const GPoint LinearSeamEdge::point(double par) const { - SVector3 res = v0->xyz() + par*first_der; + SVector3 res = v0->xyz() + par * first_der; return GPoint(res[0], res[1], res[2], this, par); } -SVector3 LinearSeamEdge::firstDer(double par) const -{ - return first_der; -} +SVector3 LinearSeamEdge::firstDer(double par) const { return first_der; } -GEntity::GeomType LinearSeamEdge::geomType() const -{ - return Line; -} +GEntity::GeomType LinearSeamEdge::geomType() const { return Line; } -double LinearSeamEdge::curvature(double par) const -{ - return 0.; -} +double LinearSeamEdge::curvature(double par) const { return 0.; } -bool LinearSeamEdge::is3D() const -{ - return false; -} +bool LinearSeamEdge::is3D() const { return false; } -bool LinearSeamEdge::degenerate(int) const -{ - return false; -} +bool LinearSeamEdge::degenerate(int) const { return false; } GPoint LinearSeamEdge::closestPoint(const SPoint3 &q, double &t) const { - return GEdge::closestPoint(q,t); + return GEdge::closestPoint(q, t); } diff --git a/Geo/GenericEdge.h b/Geo/GenericEdge.h index aec73664850ea8ea6c1fc811bb80dae666063bd8..c889e9865bcfce7a360d97df52d7106bd6df5af2 100644 --- a/Geo/GenericEdge.h +++ b/Geo/GenericEdge.h @@ -26,17 +26,22 @@ protected: double s0, s1; int id; const bool is_seam; + public: // callbacks typedef - typedef bool (*ptrfunction_int_double_refvector)(int, double, std::vector<double>&); - typedef bool (*ptrfunction_int_refdouble_refdouble)(int, double&, double&); - typedef bool (*ptrfunction_int_double_refdouble)(int, double, double&); - typedef bool (*ptrfunction_int_refstring)(int, std::string&); - typedef bool (*ptrfunction_int_refbool)(int, bool&); - typedef bool (*ptrfunction_int_refvector_refdouble_refvector_refbool)(int, const std::vector<double> &, double &, std::vector<double>&, bool &); - typedef bool (*ptrfunction_int_int_double_int_refvector)(int, int, double, int, std::vector<double> &); - - GenericEdge(GModel *model, int num,int _native_id, GVertex *v1, GVertex *v2, bool _isseam=false); + typedef bool (*ptrfunction_int_double_refvector)(int, double, + std::vector<double> &); + typedef bool (*ptrfunction_int_refdouble_refdouble)(int, double &, double &); + typedef bool (*ptrfunction_int_double_refdouble)(int, double, double &); + typedef bool (*ptrfunction_int_refstring)(int, std::string &); + typedef bool (*ptrfunction_int_refbool)(int, bool &); + typedef bool (*ptrfunction_int_refvector_refdouble_refvector_refbool)( + int, const std::vector<double> &, double &, std::vector<double> &, bool &); + typedef bool (*ptrfunction_int_int_double_int_refvector)( + int, int, double, int, std::vector<double> &); + + GenericEdge(GModel *model, int num, int _native_id, GVertex *v1, GVertex *v2, + bool _isseam = false); virtual ~GenericEdge(); virtual Range<double> parBounds(int i) const; @@ -44,28 +49,53 @@ public: virtual bool degenerate(int) const; virtual GPoint point(double p) const; virtual SVector3 firstDer(double par) const; - virtual double curvature (double par) const; + virtual double curvature(double par) const; virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const; virtual GPoint closestPoint(const SPoint3 &queryPoint, double ¶m) const; ModelType getNativeType() const { return GenericModel; } - virtual int getNativeInt()const{return id;}; + virtual int getNativeInt() const { return id; }; - virtual int minimumDrawSegments () const;// for output + virtual int minimumDrawSegments() const; // for output bool is3D() const; bool isSeam(const GFace *) const; // sets the callbacks, to be given by the user - static void setEdgeEvalXYZFromT(ptrfunction_int_double_refvector fct){EdgeEvalXYZFromT = fct;}; - static void setEdgeEvalParBounds(ptrfunction_int_refdouble_refdouble fct){EdgeEvalParBounds = fct;}; - static void setEdgeGeomType(ptrfunction_int_refstring fct){EdgeGeomType = fct;}; - static void setEdgeDegenerated(ptrfunction_int_refbool fct){EdgeDegenerated = fct;}; - static void setEdgeEvalFirstDer(ptrfunction_int_double_refvector fct){EdgeEvalFirstDer = fct;}; - static void setEdgeEvalCurvature(ptrfunction_int_double_refdouble fct){EdgeEvalCurvature = fct;}; - static void setEdgeClosestPoint(ptrfunction_int_refvector_refdouble_refvector_refbool fct){EdgeClosestPoint = fct;}; - static void setEdgeIs3D(ptrfunction_int_refbool fct){EdgeIs3D = fct;}; - static void setEdgeReparamOnFace(ptrfunction_int_int_double_int_refvector fct){EdgeReparamOnFace = fct;}; + static void setEdgeEvalXYZFromT(ptrfunction_int_double_refvector fct) + { + EdgeEvalXYZFromT = fct; + }; + static void setEdgeEvalParBounds(ptrfunction_int_refdouble_refdouble fct) + { + EdgeEvalParBounds = fct; + }; + static void setEdgeGeomType(ptrfunction_int_refstring fct) + { + EdgeGeomType = fct; + }; + static void setEdgeDegenerated(ptrfunction_int_refbool fct) + { + EdgeDegenerated = fct; + }; + static void setEdgeEvalFirstDer(ptrfunction_int_double_refvector fct) + { + EdgeEvalFirstDer = fct; + }; + static void setEdgeEvalCurvature(ptrfunction_int_double_refdouble fct) + { + EdgeEvalCurvature = fct; + }; + static void + setEdgeClosestPoint(ptrfunction_int_refvector_refdouble_refvector_refbool fct) + { + EdgeClosestPoint = fct; + }; + static void setEdgeIs3D(ptrfunction_int_refbool fct) { EdgeIs3D = fct; }; + static void setEdgeReparamOnFace(ptrfunction_int_int_double_int_refvector fct) + { + EdgeReparamOnFace = fct; + }; private: // the callbacks: @@ -76,19 +106,19 @@ private: static ptrfunction_int_refbool EdgeDegenerated; static ptrfunction_int_double_refvector EdgeEvalFirstDer; static ptrfunction_int_double_refdouble EdgeEvalCurvature; - // the first vector is a query point xyz, fills the second vector with closest point - // on edge using orthogonal projection. Fills double param with parametric coordinate of end point projection. + // the first vector is a query point xyz, fills the second vector with closest + // point on edge using orthogonal projection. Fills double param with + // parametric coordinate of end point projection. static ptrfunction_int_refvector_refdouble_refvector_refbool EdgeClosestPoint; static ptrfunction_int_refbool EdgeIs3D; static ptrfunction_int_int_double_int_refvector EdgeReparamOnFace; - - }; class LinearSeamEdge : public GEdge { protected: double s0, s1; SVector3 first_der; + public: LinearSeamEdge(GModel *model, int num, GVertex *v1, GVertex *v2); virtual ~LinearSeamEdge(); @@ -98,14 +128,12 @@ public: virtual bool degenerate(int) const; virtual GPoint point(double p) const; virtual SVector3 firstDer(double par) const; - virtual double curvature (double par) const; + virtual double curvature(double par) const; virtual bool isSeam(const GFace *face) const { return true; } bool is3D() const; virtual GPoint closestPoint(const SPoint3 &queryPoint, double ¶m) const; ModelType getNativeType() const { return GenericModel; } - - }; #endif diff --git a/Geo/GenericFace.cpp b/Geo/GenericFace.cpp index 4574f776c6770152bedd3986e2b78457e5c894f0..4bfe68ce49f011338f9403fe58460892d035fe25 100644 --- a/Geo/GenericFace.cpp +++ b/Geo/GenericFace.cpp @@ -16,32 +16,43 @@ #include "Context.h" GenericFace::ptrfunction_int_refstring GenericFace::FaceGeomType = NULL; -GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceUVFromXYZ = NULL; -GenericFace::ptrfunction_int_refvector_refvector_refvector GenericFace::FaceClosestPoint = NULL; -GenericFace::ptrfunction_int_refvector_refbool GenericFace::FaceContainsPointFromXYZ = NULL; -GenericFace::ptrfunction_int_refvector_refbool GenericFace::FaceContainsPointFromUV = NULL; -GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceXYZFromUV = NULL; -GenericFace::ptrfunction_int_int_refdouble_refdouble GenericFace::FaceParBounds = NULL; -GenericFace::ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble GenericFace::FaceCurvatures = NULL; -GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceEvalNormal = NULL; -GenericFace::ptrfunction_int_refvector_refvector_refvector GenericFace::FaceFirstDer = NULL; -GenericFace::ptrfunction_int_refvector_refvector_refvector_refvector GenericFace::FaceSecondDer = NULL; -GenericFace::ptrfunction_int_refbool_refbool_refdouble_refdouble GenericFace::FacePeriodicInfo = NULL; +GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceUVFromXYZ = + NULL; +GenericFace::ptrfunction_int_refvector_refvector_refvector + GenericFace::FaceClosestPoint = NULL; +GenericFace::ptrfunction_int_refvector_refbool + GenericFace::FaceContainsPointFromXYZ = NULL; +GenericFace::ptrfunction_int_refvector_refbool + GenericFace::FaceContainsPointFromUV = NULL; +GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceXYZFromUV = + NULL; +GenericFace::ptrfunction_int_int_refdouble_refdouble + GenericFace::FaceParBounds = NULL; +GenericFace::ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble + GenericFace::FaceCurvatures = NULL; +GenericFace::ptrfunction_int_refvector_refvector GenericFace::FaceEvalNormal = + NULL; +GenericFace::ptrfunction_int_refvector_refvector_refvector + GenericFace::FaceFirstDer = NULL; +GenericFace::ptrfunction_int_refvector_refvector_refvector_refvector + GenericFace::FaceSecondDer = NULL; +GenericFace::ptrfunction_int_refbool_refbool_refdouble_refdouble + GenericFace::FacePeriodicInfo = NULL; -GenericFace::GenericFace(GModel *m, int num, int _native_id):GFace(m, num), id(_native_id) +GenericFace::GenericFace(GModel *m, int num, int _native_id) + : GFace(m, num), id(_native_id) { - if (!FaceParBounds) Msg::Fatal("Genericface::ERROR: Callback FaceParBounds not set"); + if(!FaceParBounds) + Msg::Fatal("Genericface::ERROR: Callback FaceParBounds not set"); - bool ok = FaceParBounds(id,0,umin,umax); - if (!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalParBounds ! " ); - ok = FaceParBounds(id,1,vmin,vmax); + bool ok = FaceParBounds(id, 0, umin, umax); + if(!ok) Msg::Error("GenericEdge::ERROR from EdgeEvalParBounds ! "); + ok = FaceParBounds(id, 1, vmin, vmax); computePeriodicity(); } -GenericFace::~GenericFace() -{ -} +GenericFace::~GenericFace() {} Range<double> GenericFace::parBounds(int i) const { @@ -51,54 +62,59 @@ Range<double> GenericFace::parBounds(int i) const SVector3 GenericFace::normal(const SPoint2 ¶m) const { - std::vector<double> res(3,0.); - std::vector<double> par(2,0.); - for (int i = 0; i < 2; i++) par[i] = param[i]; - if (!FaceEvalNormal) Msg::Fatal("Genericface::ERROR: Callback FaceEvalNormal not set"); - bool ok = FaceEvalNormal(id,par,res); - if (!ok) Msg::Error("GenericFace::ERROR from FaceEvalNormal ! " ); - return SVector3(res[0],res[1],res[2]); + std::vector<double> res(3, 0.); + std::vector<double> par(2, 0.); + for(int i = 0; i < 2; i++) par[i] = param[i]; + if(!FaceEvalNormal) + Msg::Fatal("Genericface::ERROR: Callback FaceEvalNormal not set"); + bool ok = FaceEvalNormal(id, par, res); + if(!ok) Msg::Error("GenericFace::ERROR from FaceEvalNormal ! "); + return SVector3(res[0], res[1], res[2]); } -Pair<SVector3,SVector3> GenericFace::firstDer(const SPoint2 ¶m) const +Pair<SVector3, SVector3> GenericFace::firstDer(const SPoint2 ¶m) const { - if (!FaceFirstDer) Msg::Fatal("Genericface::ERROR: Callback FaceFirstDer not set"); - std::vector<double> deru(3,0.); - std::vector<double> derv(3,0.); - std::vector<double> par(2,0.); - for (int i = 0; i < 2; i++) par[i] = param[i]; - bool ok = FaceFirstDer(id,par,deru,derv); - if (!ok) Msg::Error("GenericFace::ERROR from FaceFirstDer ! " ); - return Pair<SVector3,SVector3>(SVector3(deru[0],deru[1],deru[2]), - SVector3(derv[0],derv[1],derv[2])); + if(!FaceFirstDer) + Msg::Fatal("Genericface::ERROR: Callback FaceFirstDer not set"); + std::vector<double> deru(3, 0.); + std::vector<double> derv(3, 0.); + std::vector<double> par(2, 0.); + for(int i = 0; i < 2; i++) par[i] = param[i]; + bool ok = FaceFirstDer(id, par, deru, derv); + if(!ok) Msg::Error("GenericFace::ERROR from FaceFirstDer ! "); + return Pair<SVector3, SVector3>(SVector3(deru[0], deru[1], deru[2]), + SVector3(derv[0], derv[1], derv[2])); } -void GenericFace::secondDer(const SPoint2 ¶m, SVector3 &dudu, SVector3 &dvdv, SVector3 &dudv) const +void GenericFace::secondDer(const SPoint2 ¶m, SVector3 &dudu, + SVector3 &dvdv, SVector3 &dudv) const { - std::vector<double> deruu(3,0.); - std::vector<double> dervv(3,0.); - std::vector<double> deruv(3,0.); - std::vector<double> par(2,0.); + std::vector<double> deruu(3, 0.); + std::vector<double> dervv(3, 0.); + std::vector<double> deruv(3, 0.); + std::vector<double> par(2, 0.); for(int i = 0; i < 2; i++) par[i] = param[i]; - if (!FaceSecondDer) Msg::Fatal("Genericface::ERROR: Callback FaceSecondDer not set"); + if(!FaceSecondDer) + Msg::Fatal("Genericface::ERROR: Callback FaceSecondDer not set"); bool ok = FaceSecondDer(id, par, deruu, dervv, deruv); - if(!ok) Msg::Error("GenericFace::ERROR from FaceSecondDer ! " ); - dudu = SVector3(deruu[0],deruu[1],deruu[2]); - dvdv = SVector3(dervv[0],dervv[1],dervv[2]); - dudv = SVector3(deruv[0],deruv[1],deruv[2]); + if(!ok) Msg::Error("GenericFace::ERROR from FaceSecondDer ! "); + dudu = SVector3(deruu[0], deruu[1], deruu[2]); + dvdv = SVector3(dervv[0], dervv[1], dervv[2]); + dudv = SVector3(deruv[0], deruv[1], deruv[2]); } GPoint GenericFace::point(double par1, double par2) const { - std::vector<double> uv(2,0.); + std::vector<double> uv(2, 0.); uv[0] = par1; uv[1] = par2; - std::vector<double> xyz(3,0.); + std::vector<double> xyz(3, 0.); double pp[2] = {par1, par2}; - if (!FaceXYZFromUV) Msg::Fatal("Genericface::ERROR: Callback FaceXYZFromUV not set"); - bool ok = FaceXYZFromUV(id,uv,xyz); - if (!ok){ - Msg::Error("GenericFace::ERROR from FaceXYZFromUV ! " ); + if(!FaceXYZFromUV) + Msg::Fatal("Genericface::ERROR: Callback FaceXYZFromUV not set"); + bool ok = FaceXYZFromUV(id, uv, xyz); + if(!ok) { + Msg::Error("GenericFace::ERROR from FaceXYZFromUV ! "); GPoint p(xyz[0], xyz[1], xyz[2], this, pp); p.setNoSuccess(); return p; @@ -106,78 +122,95 @@ GPoint GenericFace::point(double par1, double par2) const return GPoint(xyz[0], xyz[1], xyz[2], this, pp); } - -GPoint GenericFace::closestPoint(const SPoint3 &qp, const double initialGuess[2]) const +GPoint GenericFace::closestPoint(const SPoint3 &qp, + const double initialGuess[2]) const { - std::vector<double> uvres(2,0.); - std::vector<double> xyzres(3,0.); - std::vector<double> queryPoint(3,0.); - for (int i=0;i<3;i++) queryPoint[i] = qp[i]; - if (!FaceClosestPoint) Msg::Fatal("Genericface::ERROR: Callback FaceClosestPoint not set"); - bool ok = FaceClosestPoint(id,queryPoint,xyzres,uvres);// orthogonal projection - if (!ok) Msg::Error("GenericFace::ERROR from FaceClosestPoint ! " ); + std::vector<double> uvres(2, 0.); + std::vector<double> xyzres(3, 0.); + std::vector<double> queryPoint(3, 0.); + for(int i = 0; i < 3; i++) queryPoint[i] = qp[i]; + if(!FaceClosestPoint) + Msg::Fatal("Genericface::ERROR: Callback FaceClosestPoint not set"); + bool ok = + FaceClosestPoint(id, queryPoint, xyzres, uvres); // orthogonal projection + if(!ok) Msg::Error("GenericFace::ERROR from FaceClosestPoint ! "); // check if the projected point lies on the face... bool on_the_face; - if (!FaceContainsPointFromUV) Msg::Fatal("Genericface::ERROR: Callback FaceContainsPointFromUV not set"); - ok = FaceContainsPointFromUV(id,uvres,on_the_face); - if (!ok) Msg::Error("GenericFace::ERROR from FaceContainsPointFromUV ! " ); - if (!on_the_face) Msg::Warning("GenericFace::closestPoint::Warning (using UV) !!!! The returned point does not lies on the face ! " ); + if(!FaceContainsPointFromUV) + Msg::Fatal("Genericface::ERROR: Callback FaceContainsPointFromUV not set"); + ok = FaceContainsPointFromUV(id, uvres, on_the_face); + if(!ok) Msg::Error("GenericFace::ERROR from FaceContainsPointFromUV ! "); + if(!on_the_face) + Msg::Warning("GenericFace::closestPoint::Warning (using UV) !!!! The " + "returned point does not lies on the face ! "); double pp[2] = {uvres[0], uvres[1]}; return GPoint(xyzres[0], xyzres[1], xyzres[2], this, pp); } SPoint2 GenericFace::parFromPoint(const SPoint3 &qp, bool onSurface) const { - std::vector<double> uvres(2,0.); - std::vector<double> xyzres(3,0.); - std::vector<double> queryPoint(3,0.); - for (int i=0;i<3;i++) queryPoint[i] = qp[i]; - bool ok=true; - if (onSurface){ - if (!FaceUVFromXYZ) Msg::Fatal("Genericface::ERROR: Callback FaceUVFromXYZ not set"); - ok = FaceUVFromXYZ(id,queryPoint,uvres);// assuming point is on surface - if (!ok) Msg::Error("GenericFace::ERROR from FaceUVFromXYZ ! " ); + std::vector<double> uvres(2, 0.); + std::vector<double> xyzres(3, 0.); + std::vector<double> queryPoint(3, 0.); + for(int i = 0; i < 3; i++) queryPoint[i] = qp[i]; + bool ok = true; + if(onSurface) { + if(!FaceUVFromXYZ) + Msg::Fatal("Genericface::ERROR: Callback FaceUVFromXYZ not set"); + ok = FaceUVFromXYZ(id, queryPoint, uvres); // assuming point is on surface + if(!ok) Msg::Error("GenericFace::ERROR from FaceUVFromXYZ ! "); } - if ((!onSurface)||(!ok)){// if not on surface - if (!FaceClosestPoint) Msg::Fatal("Genericface::ERROR: Callback FaceClosestPoint not set"); - ok = FaceClosestPoint(id,queryPoint,xyzres,uvres);// orthogonal projection - if (!ok) Msg::Error("GenericFace::ERROR from FaceClosestPoint ! " ); + if((!onSurface) || (!ok)) { // if not on surface + if(!FaceClosestPoint) + Msg::Fatal("Genericface::ERROR: Callback FaceClosestPoint not set"); + ok = + FaceClosestPoint(id, queryPoint, xyzres, uvres); // orthogonal projection + if(!ok) Msg::Error("GenericFace::ERROR from FaceClosestPoint ! "); bool on_the_face; - if (!FaceContainsPointFromXYZ) Msg::Fatal("Genericface::ERROR: Callback FaceContainsPointFromXYZ not set"); - ok = FaceContainsPointFromXYZ(id,xyzres,on_the_face);// check if the projected point lies on the face... - if (!ok) Msg::Error("GenericFace::parFromPoint::ERROR from FaceContainsPointFromXYZ ! " ); - if (!on_the_face) Msg::Warning("GenericFace::parFromPoint::Warning !!!! The returned point does not lies on the face ! " ); + if(!FaceContainsPointFromXYZ) + Msg::Fatal( + "Genericface::ERROR: Callback FaceContainsPointFromXYZ not set"); + ok = FaceContainsPointFromXYZ( + id, xyzres, + on_the_face); // check if the projected point lies on the face... + if(!ok) + Msg::Error( + "GenericFace::parFromPoint::ERROR from FaceContainsPointFromXYZ ! "); + if(!on_the_face) + Msg::Warning("GenericFace::parFromPoint::Warning !!!! The returned point " + "does not lies on the face ! "); } - return SPoint2(uvres[0],uvres[1]); + return SPoint2(uvres[0], uvres[1]); } GEntity::GeomType GenericFace::geomType() const { std::string s; - if (!FaceGeomType) Msg::Fatal("Genericface::ERROR: Callback FaceGeomType not set"); - bool ok = FaceGeomType(id,s); - if (!ok){ - Msg::Error("GenericFace::ERROR from FaceGeomType ! " ); + if(!FaceGeomType) + Msg::Fatal("Genericface::ERROR: Callback FaceGeomType not set"); + bool ok = FaceGeomType(id, s); + if(!ok) { + Msg::Error("GenericFace::ERROR from FaceGeomType ! "); return Unknown; } - if(s.compare("Plane")==0) + if(s.compare("Plane") == 0) return Plane; - else if(s.compare("Cylinder")==0) + else if(s.compare("Cylinder") == 0) return Cylinder; - else if(s.compare("Cone")==0) + else if(s.compare("Cone") == 0) return Cone; - else if(s.compare("Sphere")==0) + else if(s.compare("Sphere") == 0) return Sphere; - else if(s.compare("Torus")==0) + else if(s.compare("Torus") == 0) return Torus; - else if(s.compare("BezierSurface")==0) + else if(s.compare("BezierSurface") == 0) return BezierSurface; - else if(s.compare("BSplineSurface")==0) + else if(s.compare("BSplineSurface") == 0) return BSplineSurface; - else if(s.compare("SurfaceOfRevolution")==0) + else if(s.compare("SurfaceOfRevolution") == 0) return SurfaceOfRevolution; return Unknown; @@ -185,50 +218,58 @@ GEntity::GeomType GenericFace::geomType() const double GenericFace::curvatureMax(const SPoint2 ¶m) const { - std::vector<double> dirMax(3,0.); - std::vector<double> dirMin(3,0.); - double curvMax,curvMin; - std::vector<double> par(2,0.); - for (int i = 0; i < 2; i++) par[i] = param[i]; - if (!FaceCurvatures) Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set"); - bool ok = FaceCurvatures(id,par,dirMax,dirMin,curvMax,curvMin); - if (!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! " ); + std::vector<double> dirMax(3, 0.); + std::vector<double> dirMin(3, 0.); + double curvMax, curvMin; + std::vector<double> par(2, 0.); + for(int i = 0; i < 2; i++) par[i] = param[i]; + if(!FaceCurvatures) + Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set"); + bool ok = FaceCurvatures(id, par, dirMax, dirMin, curvMax, curvMin); + if(!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! "); return std::max(fabs(curvMax), fabs(curvMin)); } -double GenericFace::curvatures(const SPoint2 &_param, SVector3 &_dirMax, SVector3 &_dirMin, - double &curvMax, double &curvMin) const +double GenericFace::curvatures(const SPoint2 &_param, SVector3 &_dirMax, + SVector3 &_dirMin, double &curvMax, + double &curvMin) const { - std::vector<double> param(2,0.); - for (int i = 0; i < 2; i++) param[i] = _param[i]; - std::vector<double> dirMax(3,0.); - std::vector<double> dirMin(3,0.); + std::vector<double> param(2, 0.); + for(int i = 0; i < 2; i++) param[i] = _param[i]; + std::vector<double> dirMax(3, 0.); + std::vector<double> dirMin(3, 0.); - if (!FaceCurvatures) Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set"); - bool ok = FaceCurvatures(id,param,dirMax,dirMin,curvMax,curvMin); - if (!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! " ); + if(!FaceCurvatures) + Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set"); + bool ok = FaceCurvatures(id, param, dirMax, dirMin, curvMax, curvMin); + if(!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! "); - _dirMax = SVector3(dirMax[0],dirMax[1],dirMax[2]); - _dirMin = SVector3(dirMin[0],dirMin[1],dirMin[2]); + _dirMax = SVector3(dirMax[0], dirMax[1], dirMax[2]); + _dirMin = SVector3(dirMin[0], dirMin[1], dirMin[2]); return curvMax; } bool GenericFace::containsPoint(const SPoint3 &pt) const { bool res; - std::vector<double> queryPoint(3,0.); - for (int i = 0; i < 3; i++) queryPoint[i] = pt[i]; - if (!FaceContainsPointFromXYZ) Msg::Fatal("Genericface::ERROR: Callback FaceContainsPointFromXYZ not set"); - bool ok = FaceContainsPointFromXYZ(id,queryPoint,res); - if (!ok) Msg::Error("GenericFace::containsPoint::ERROR from FaceContainsPointFromXYZ ! " ); + std::vector<double> queryPoint(3, 0.); + for(int i = 0; i < 3; i++) queryPoint[i] = pt[i]; + if(!FaceContainsPointFromXYZ) + Msg::Fatal("Genericface::ERROR: Callback FaceContainsPointFromXYZ not set"); + bool ok = FaceContainsPointFromXYZ(id, queryPoint, res); + if(!ok) + Msg::Error( + "GenericFace::containsPoint::ERROR from FaceContainsPointFromXYZ ! "); return res; } void GenericFace::computePeriodicity() { - if (!FacePeriodicInfo) Msg::Fatal("Genericface::ERROR: Callback FacePeriodicInfo not set"); - bool ok = FacePeriodicInfo(id,_periodic[0], _periodic[1],_period[0],_period[1]); - if (!ok) Msg::Error("GenericFace::ERROR from FacePeriodicInfo ! " ); + if(!FacePeriodicInfo) + Msg::Fatal("Genericface::ERROR: Callback FacePeriodicInfo not set"); + bool ok = + FacePeriodicInfo(id, _periodic[0], _periodic[1], _period[0], _period[1]); + if(!ok) Msg::Error("GenericFace::ERROR from FacePeriodicInfo ! "); } void GenericFace::createLoops() @@ -237,27 +278,27 @@ void GenericFace::createLoops() l_edges.clear(); l_dirs.clear(); - for (std::set<int>::iterator it_loop = loopsnumber.begin(); - it_loop != loopsnumber.end(); it_loop++){// for each loop - std::pair<std::multimap<int, std::pair<GEdge*,int> >::iterator, - std::multimap<int, std::pair<GEdge*,int> >::iterator> + for(std::set<int>::iterator it_loop = loopsnumber.begin(); + it_loop != loopsnumber.end(); it_loop++) { // for each loop + std::pair<std::multimap<int, std::pair<GEdge *, int> >::iterator, + std::multimap<int, std::pair<GEdge *, int> >::iterator> range = bnd.equal_range(*it_loop); - std::vector<GEdge*> l_wire; - for (std::multimap<int, std::pair<GEdge*,int> >::iterator it = range.first; - it!=range.second;it++){// for all edges + std::vector<GEdge *> l_wire; + for(std::multimap<int, std::pair<GEdge *, int> >::iterator it = range.first; + it != range.second; it++) { // for all edges l_wire.push_back(it->second.first); } GEdgeLoop el(l_wire); - for(GEdgeLoop::citer it = el.begin(); it != el.end(); ++it){ + for(GEdgeLoop::citer it = el.begin(); it != el.end(); ++it) { l_edges.push_back(it->ge); l_dirs.push_back(it->_sign); - if (el.count() == 2){ + if(el.count() == 2) { it->ge->meshAttributes.minimumMeshSegments = - std::max(it->ge->meshAttributes.minimumMeshSegments,2); + std::max(it->ge->meshAttributes.minimumMeshSegments, 2); } - if (el.count() == 1){ + if(el.count() == 1) { it->ge->meshAttributes.minimumMeshSegments = - std::max(it->ge->meshAttributes.minimumMeshSegments,3); + std::max(it->ge->meshAttributes.minimumMeshSegments, 3); } } edgeLoops.push_back(el); diff --git a/Geo/GenericFace.h b/Geo/GenericFace.h index 6c9342087c72d658f8c21b29eed7dbe19ddd7e44..93485469b7a0d5270ab8f830bf33d6088d1e176c 100644 --- a/Geo/GenericFace.h +++ b/Geo/GenericFace.h @@ -23,20 +23,32 @@ class GenericFace : public GFace { protected: int id; - double umin, umax, vmin, vmax;// face uv bounds - bool _periodic[2];// is periodic in u, v + double umin, umax, vmin, vmax; // face uv bounds + bool _periodic[2]; // is periodic in u, v double _period[2]; public: // callbacks typedef - typedef bool (*ptrfunction_int_refstring)(int, std::string&); - typedef bool (*ptrfunction_int_refbool_refbool_refdouble_refdouble)(int, bool&, bool&, double&, double&); - typedef bool (*ptrfunction_int_refvector_refvector)(const int , const std::vector<double> &, std::vector<double> &); - typedef bool (*ptrfunction_int_refvector_refvector_refvector)(const int , const std::vector<double> &, std::vector<double> &, std::vector<double> &); - typedef bool (*ptrfunction_int_refvector_refbool)(const int , const std::vector<double> &, bool &); - typedef bool (*ptrfunction_int_int_refdouble_refdouble)(const int, const int, double &, double &); - typedef bool (*ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble)(const int, const std::vector<double> &, std::vector<double> &, std::vector<double> &, double &, double &); - typedef bool (*ptrfunction_int_refvector_refvector_refvector_refvector)(const int , const std::vector<double> &, std::vector<double> &, std::vector<double> &, std::vector<double> &); + typedef bool (*ptrfunction_int_refstring)(int, std::string &); + typedef bool (*ptrfunction_int_refbool_refbool_refdouble_refdouble)( + int, bool &, bool &, double &, double &); + typedef bool (*ptrfunction_int_refvector_refvector)( + const int, const std::vector<double> &, std::vector<double> &); + typedef bool (*ptrfunction_int_refvector_refvector_refvector)( + const int, const std::vector<double> &, std::vector<double> &, + std::vector<double> &); + typedef bool (*ptrfunction_int_refvector_refbool)(const int, + const std::vector<double> &, + bool &); + typedef bool (*ptrfunction_int_int_refdouble_refdouble)(const int, const int, + double &, double &); + typedef bool ( + *ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble)( + const int, const std::vector<double> &, std::vector<double> &, + std::vector<double> &, double &, double &); + typedef bool (*ptrfunction_int_refvector_refvector_refvector_refvector)( + const int, const std::vector<double> &, std::vector<double> &, + std::vector<double> &, std::vector<double> &); GenericFace(GModel *m, int num, int _native_id); virtual ~GenericFace(); @@ -44,26 +56,31 @@ public: Range<double> parBounds(int i) const; using GFace::point; virtual GPoint point(double par1, double par2) const; - virtual GPoint closestPoint(const SPoint3 & queryPoint, + virtual GPoint closestPoint(const SPoint3 &queryPoint, const double initialGuess[2]) const; virtual bool containsPoint(const SPoint3 &pt) const; virtual SVector3 normal(const SPoint2 ¶m) const; - virtual Pair<SVector3,SVector3> firstDer(const SPoint2 ¶m) const; - virtual void secondDer(const SPoint2 &, SVector3 &, SVector3 &, SVector3 &) const; + virtual Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m) const; + virtual void secondDer(const SPoint2 &, SVector3 &, SVector3 &, + SVector3 &) const; virtual GEntity::GeomType geomType() const; - virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const; + virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface = true) const; virtual double curvatureMax(const SPoint2 ¶m) const; - virtual double curvatures(const SPoint2 ¶m, SVector3 &dirMax, SVector3 &dirMin, - double &curvMax, double &curvMin) const; - virtual bool periodic(int dir) const { return false;}//_periodic[dir]; }// TODO ? - virtual double period(int dir) const{ return _period[dir]; }; + virtual double curvatures(const SPoint2 ¶m, SVector3 &dirMax, + SVector3 &dirMin, double &curvMax, + double &curvMin) const; + virtual bool periodic(int dir) const + { + return false; + } //_periodic[dir]; }// TODO ? + virtual double period(int dir) const { return _period[dir]; }; ModelType getNativeType() const { return GenericModel; } - virtual int getNativeInt()const{return id;}; + virtual int getNativeInt() const { return id; }; void addBndInfo(int loop, GEdge *ptr, int sign) { - bnd.insert(std::make_pair(loop, std::make_pair(ptr,sign))); + bnd.insert(std::make_pair(loop, std::make_pair(ptr, sign))); l_dirs.push_back(sign); l_edges.push_back(ptr); loopsnumber.insert(loop); @@ -74,30 +91,74 @@ public: void computePeriodicity(); // sets callbacks - static void setFaceGeomType(ptrfunction_int_refstring fct){FaceGeomType = fct;}; - static void setFaceUVFromXYZ(ptrfunction_int_refvector_refvector fct){FaceUVFromXYZ = fct;}; - static void setFaceClosestPoint(ptrfunction_int_refvector_refvector_refvector fct){FaceClosestPoint = fct;}; - static void setFaceContainsPointFromXYZ(ptrfunction_int_refvector_refbool fct){FaceContainsPointFromXYZ = fct;}; - static void setFaceContainsPointFromUV(ptrfunction_int_refvector_refbool fct){FaceContainsPointFromUV = fct;}; - static void setFaceXYZFromUV(ptrfunction_int_refvector_refvector fct){FaceXYZFromUV = fct;}; - static void setFaceParBounds(ptrfunction_int_int_refdouble_refdouble fct){FaceParBounds = fct;}; - static void setFaceCurvatures(ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble fct){FaceCurvatures = fct;}; - static void setFaceEvalNormal(ptrfunction_int_refvector_refvector fct){FaceEvalNormal = fct;}; - static void setFaceFirstDer(ptrfunction_int_refvector_refvector_refvector fct){FaceFirstDer = fct;}; - static void setFaceSecondDer(ptrfunction_int_refvector_refvector_refvector_refvector fct){FaceSecondDer = fct;}; - static void setFacePeriodicInfo(ptrfunction_int_refbool_refbool_refdouble_refdouble fct){FacePeriodicInfo = fct;}; + static void setFaceGeomType(ptrfunction_int_refstring fct) + { + FaceGeomType = fct; + }; + static void setFaceUVFromXYZ(ptrfunction_int_refvector_refvector fct) + { + FaceUVFromXYZ = fct; + }; + static void + setFaceClosestPoint(ptrfunction_int_refvector_refvector_refvector fct) + { + FaceClosestPoint = fct; + }; + static void setFaceContainsPointFromXYZ(ptrfunction_int_refvector_refbool fct) + { + FaceContainsPointFromXYZ = fct; + }; + static void setFaceContainsPointFromUV(ptrfunction_int_refvector_refbool fct) + { + FaceContainsPointFromUV = fct; + }; + static void setFaceXYZFromUV(ptrfunction_int_refvector_refvector fct) + { + FaceXYZFromUV = fct; + }; + static void setFaceParBounds(ptrfunction_int_int_refdouble_refdouble fct) + { + FaceParBounds = fct; + }; + static void setFaceCurvatures( + ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble fct) + { + FaceCurvatures = fct; + }; + static void setFaceEvalNormal(ptrfunction_int_refvector_refvector fct) + { + FaceEvalNormal = fct; + }; + static void setFaceFirstDer(ptrfunction_int_refvector_refvector_refvector fct) + { + FaceFirstDer = fct; + }; + static void + setFaceSecondDer(ptrfunction_int_refvector_refvector_refvector_refvector fct) + { + FaceSecondDer = fct; + }; + static void + setFacePeriodicInfo(ptrfunction_int_refbool_refbool_refdouble_refdouble fct) + { + FacePeriodicInfo = fct; + }; private: - std::multimap<int, std::pair<GEdge*,int> > bnd; + std::multimap<int, std::pair<GEdge *, int> > bnd; std::set<int> loopsnumber; // the callbacks: static ptrfunction_int_refstring FaceGeomType; - static ptrfunction_int_refvector_refvector FaceUVFromXYZ,FaceXYZFromUV,FaceEvalNormal; - static ptrfunction_int_refvector_refvector_refvector FaceClosestPoint,FaceFirstDer; - static ptrfunction_int_refvector_refbool FaceContainsPointFromXYZ,FaceContainsPointFromUV; + static ptrfunction_int_refvector_refvector FaceUVFromXYZ, FaceXYZFromUV, + FaceEvalNormal; + static ptrfunction_int_refvector_refvector_refvector FaceClosestPoint, + FaceFirstDer; + static ptrfunction_int_refvector_refbool FaceContainsPointFromXYZ, + FaceContainsPointFromUV; static ptrfunction_int_int_refdouble_refdouble FaceParBounds; - static ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble FaceCurvatures; + static ptrfunction_int_refvector_refvector_refvector_refdouble_refdouble + FaceCurvatures; static ptrfunction_int_refvector_refvector_refvector_refvector FaceSecondDer; static ptrfunction_int_refbool_refbool_refdouble_refdouble FacePeriodicInfo; }; diff --git a/Geo/GenericRegion.cpp b/Geo/GenericRegion.cpp index 90293c40b486336865f0d70d729b63fef07e1516..6bda19b8e25f27fb43c2e8eb6d65c58ef8f9629d 100644 --- a/Geo/GenericRegion.cpp +++ b/Geo/GenericRegion.cpp @@ -12,17 +12,10 @@ #include "GenericRegion.h" GenericRegion::GenericRegion(GModel *m, int num, int _native_id) - : GRegion(m, num), id(_native_id) + : GRegion(m, num), id(_native_id) { } -GenericRegion::~GenericRegion() -{ -} - -GEntity::GeomType GenericRegion::geomType() const -{ - return Unknown; -} - +GenericRegion::~GenericRegion() {} +GEntity::GeomType GenericRegion::geomType() const { return Unknown; } diff --git a/Geo/GenericRegion.h b/Geo/GenericRegion.h index 267f6cda7d6933e7aa68e61bc38f044ce8e3883a..643090e4911ea644e87124c12fa5f001f3122654 100644 --- a/Geo/GenericRegion.h +++ b/Geo/GenericRegion.h @@ -23,12 +23,13 @@ public: virtual GeomType geomType() const; ModelType getNativeType() const { return GenericModel; } - virtual int getNativeInt()const{return id;}; + virtual int getNativeInt() const { return id; }; // TODO: When using GRegion->l_dirs and l_faces, what is the convention for // l_dirs ? For now, assuming positive value for normals pointing inside the // region. - void addFace(GenericFace *ptr, int sign){ + void addFace(GenericFace *ptr, int sign) + { l_dirs.push_back(sign); l_faces.push_back(ptr); ptr->addRegion(this); diff --git a/Geo/GenericVertex.cpp b/Geo/GenericVertex.cpp index ed81318dee107fb096da4ec9d70fa392f19767ad..485b710d15f09ff98674cbef21622e4d1d89247b 100644 --- a/Geo/GenericVertex.cpp +++ b/Geo/GenericVertex.cpp @@ -14,40 +14,38 @@ #include "GenericFace.h" GenericVertex::ptrfunction_int_vector GenericVertex::VertexXYZ = NULL; -GenericVertex::ptrfunction_int_doubleptr_voidptr GenericVertex::VertexMeshSize = NULL; +GenericVertex::ptrfunction_int_doubleptr_voidptr GenericVertex::VertexMeshSize = + NULL; GenericVertex::GenericVertex(GModel *m, int num, int _native_id) - : GVertex(m, num), id(_native_id) + : GVertex(m, num), id(_native_id) { - if (!VertexXYZ) - Msg::Fatal("GenericVertex::ERROR: Callback not set"); - - std::vector<double> vec(3,0.); - bool ok = VertexXYZ(id,vec); - if (!ok) Msg::Error("GenericVertex::ERROR from callback VertexXYZ "); - _x=vec[0]; - _y=vec[1]; - _z=vec[2]; + if(!VertexXYZ) Msg::Fatal("GenericVertex::ERROR: Callback not set"); + + std::vector<double> vec(3, 0.); + bool ok = VertexXYZ(id, vec); + if(!ok) Msg::Error("GenericVertex::ERROR from callback VertexXYZ "); + _x = vec[0]; + _y = vec[1]; + _z = vec[2]; } -GenericVertex::GenericVertex(GModel *m, int num, int _native_id, const std::vector<double> &vec) - : GVertex(m, num), id(_native_id) +GenericVertex::GenericVertex(GModel *m, int num, int _native_id, + const std::vector<double> &vec) + : GVertex(m, num), id(_native_id) { - if (!VertexXYZ) - Msg::Fatal("GenericVertex::ERROR: Callback not set"); - _x=vec[0]; - _y=vec[1]; - _z=vec[2]; + if(!VertexXYZ) Msg::Fatal("GenericVertex::ERROR: Callback not set"); + _x = vec[0]; + _y = vec[1]; + _z = vec[2]; } -GenericVertex::~GenericVertex(){ - -} +GenericVertex::~GenericVertex() {} SPoint2 GenericVertex::reparamOnFace(const GFace *gf, int dir) const { - SPoint3 pt(_x,_y,_z); - return gf->parFromPoint(pt,true); + SPoint3 pt(_x, _y, _z); + return gf->parFromPoint(pt, true); } void GenericVertex::setPosition(GPoint &p) @@ -55,10 +53,9 @@ void GenericVertex::setPosition(GPoint &p) _x = p.x(); _y = p.y(); _z = p.z(); - if(mesh_vertices.size()){ + if(mesh_vertices.size()) { mesh_vertices[0]->x() = p.x(); mesh_vertices[0]->y() = p.y(); mesh_vertices[0]->z() = p.z(); } } - diff --git a/Geo/GenericVertex.h b/Geo/GenericVertex.h index 1b5d756d8c4e2f94c9d44891750958a6e36eaa1e..e4748fc5d00c896ed856133d3eeba059a78cfdcf 100644 --- a/Geo/GenericVertex.h +++ b/Geo/GenericVertex.h @@ -22,13 +22,15 @@ class GenericVertex : public GVertex { protected: int id; double _x, _y, _z; + public: // callbacks typedef - typedef bool (*ptrfunction_int_vector)(int, std::vector<double>&); - typedef bool (*ptrfunction_int_doubleptr_voidptr)(int, double*, void*); + typedef bool (*ptrfunction_int_vector)(int, std::vector<double> &); + typedef bool (*ptrfunction_int_doubleptr_voidptr)(int, double *, void *); GenericVertex(GModel *m, int num, int _native_id); - GenericVertex(GModel *m, int num, int _native_id, const std::vector<double> &vec); + GenericVertex(GModel *m, int num, int _native_id, + const std::vector<double> &vec); virtual ~GenericVertex(); virtual GPoint point() const { return GPoint(x(), y(), z()); } @@ -40,11 +42,14 @@ public: virtual SPoint2 reparamOnFace(const GFace *gf, int) const; ModelType getNativeType() const { return GenericModel; } - virtual int getNativeInt()const{return id;}; + virtual int getNativeInt() const { return id; }; // sets the callbacks - static void setVertexXYZ(ptrfunction_int_vector fct){VertexXYZ = fct;}; - static void setVertexMeshSize(ptrfunction_int_doubleptr_voidptr fct){VertexMeshSize = fct;}; + static void setVertexXYZ(ptrfunction_int_vector fct) { VertexXYZ = fct; }; + static void setVertexMeshSize(ptrfunction_int_doubleptr_voidptr fct) + { + VertexMeshSize = fct; + }; // meshing-related methods: virtual void setPrescribedMeshSizeAtVertex(double l) @@ -55,7 +60,7 @@ public: { double size; void *chose = NULL; - if (!VertexMeshSize(id,&size,chose)){ + if(!VertexMeshSize(id, &size, chose)) { Msg::Error("GenericVertex::ERROR from callback VertexMeshSize"); return CTX::instance()->lc; } diff --git a/Geo/Geo.cpp b/Geo/Geo.cpp index 951e892231fc1925e47d30d8f06dc8f42a426614..f381c2df059055b86b2a93c3467c8abe15e85ac8 100644 --- a/Geo/Geo.cpp +++ b/Geo/Geo.cpp @@ -287,7 +287,9 @@ void EndCurve(Curve *c) double n[3]; prodve(dir12, dir32, n); bool isValid = true; - if(norm3(n) < 1.e-15) { isValid = false; } + if(norm3(n) < 1.e-15) { + isValid = false; + } else { norme(n); if((fabs(n[0]) < 1.e-5 && fabs(n[1]) < 1.e-5 && fabs(n[2]) < 1.e-5)) { @@ -652,7 +654,9 @@ static Vertex *FindPoint(int inum, Tree_T *t) Vertex C, *pc; pc = &C; pc->Num = inum; - if(Tree_Query(t, &pc)) { return pc; } + if(Tree_Query(t, &pc)) { + return pc; + } return NULL; } @@ -666,7 +670,9 @@ static Curve *FindCurve(int inum, Tree_T *t) Curve C, *pc; pc = &C; pc->Num = inum; - if(Tree_Query(t, &pc)) { return pc; } + if(Tree_Query(t, &pc)) { + return pc; + } return NULL; } @@ -680,7 +686,9 @@ static Surface *FindSurface(int inum, Tree_T *t) Surface S, *ps; ps = &S; ps->Num = inum; - if(Tree_Query(t, &ps)) { return ps; } + if(Tree_Query(t, &ps)) { + return ps; + } return NULL; } @@ -1157,7 +1165,9 @@ int RecognizeSurfaceLoop(List_T *liste, int *loop) static void SetTranslationMatrix(double matrix[4][4], double T[3]) { for(int i = 0; i < 4; i++) { - for(int j = 0; j < 4; j++) { matrix[i][j] = (i == j) ? 1.0 : 0.0; } + for(int j = 0; j < 4; j++) { + matrix[i][j] = (i == j) ? 1.0 : 0.0; + } } for(int i = 0; i < 3; i++) matrix[i][3] = T[i]; } @@ -1289,7 +1299,9 @@ static void vecmat4x4(double mat[4][4], double vec[4], double res[4]) { for(int i = 0; i < 4; i++) { res[i] = 0.0; - for(int j = 0; j < 4; j++) { res[i] += mat[i][j] * vec[j]; } + for(int j = 0; j < 4; j++) { + res[i] += mat[i][j] * vec[j]; + } } } @@ -1705,7 +1717,9 @@ static void ReplaceDuplicatePointsNew(double tol = -1.) Tree_Add(GModel::current()->getGEOInternals()->DelPoints, &V); delete unused[i]; } - for(unsigned int i = 0; i < used.size(); i++) { delete used[i]; } + for(unsigned int i = 0; i < used.size(); i++) { + delete used[i]; + } int end = Tree_Nbr(GModel::current()->getGEOInternals()->Points); Msg::Info("Done new Coherence (removed %d additional points)", start - end); } @@ -2581,7 +2595,9 @@ int ExtrudeCurve(int type, int ic, double T0, double T1, double T2, double A0, revpc = FindCurve(-ic); *ps = NULL; - if(!pc || !revpc) { return 0; } + if(!pc || !revpc) { + return 0; + } if(!pc->beg || !pc->end) { Msg::Error("Cannot extrude curve with no begin/end points"); @@ -2678,7 +2694,9 @@ int ExtrudeCurve(int type, int ic, double T0, double T1, double T2, double A0, ExtrudePoint(type, pc->end->Num, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha, &CurveEnd, &ReverseEnd, 0, e); - if(!CurveBeg && !CurveEnd) { return pc->Num; } + if(!CurveBeg && !CurveEnd) { + return pc->Num; + } // FIXME: if we extrude by rotation a (non-straight) curve defined by 2 end // points, with a rotation axis going through the end points, the resulting @@ -3428,7 +3446,9 @@ void SetSurfaceGeneratrices(Surface *s, List_T *loops) for(unsigned int j = 0; j < fromModel.size(); j++) { ic = fromModel[j]; GEdge *ge = GModel::current()->getEdgeByTag(abs(ic)); - if(ge) { List_Add(s->GeneratricesByTag, &ic); } + if(ge) { + List_Add(s->GeneratricesByTag, &ic); + } else { Msg::Error("Unknown curve %d", ic); return; @@ -3466,7 +3486,9 @@ void SetVolumeSurfaces(Volume *v, List_T *loops) } else { GFace *gf = GModel::current()->getFaceByTag(abs(is)); - if(gf) { List_Add(v->SurfacesByTag, &is); } + if(gf) { + List_Add(v->SurfacesByTag, &is); + } else { Msg::Error("Unknown surface %d", is); return; diff --git a/Geo/Geo.h b/Geo/Geo.h index 31d02d8aa2d602a56b5dbde56f1acb426c6eacf2..c488f9ef6f99da9c9cce97ff5139eaf0ee287032 100644 --- a/Geo/Geo.h +++ b/Geo/Geo.h @@ -41,12 +41,7 @@ public: int boundaryLayerIndex; Vertex(double X = 0., double Y = 0., double Z = 0., double l = 1., double W = 1.) - : Num(0) - , lc(l) - , u(0.) - , w(W) - , geometry(0) - , boundaryLayerIndex(0) + : Num(0), lc(l), u(0.), w(W), geometry(0), boundaryLayerIndex(0) { Typ = MSH_POINT; Pos.X = X; diff --git a/Geo/GeoDefines.h b/Geo/GeoDefines.h index f6ce8c26b0199cc6dc16a018c6511fb1acbf59b7..4569bb4c9d759bf17a6ebb07d7991ef974bd7820 100644 --- a/Geo/GeoDefines.h +++ b/Geo/GeoDefines.h @@ -6,47 +6,47 @@ #ifndef _GEO_DEFINES_H_ #define _GEO_DEFINES_H_ -class Shape{ - public: +class Shape { +public: int Type; int Num; }; // type/100 gives (dimension+1) -#define MSH_POINT 100 -#define MSH_POINT_BND_LAYER 101 -#define MSH_POINT_DISCRETE 102 -#define MSH_POINT_FROM_GMODEL 103 - -#define MSH_SEGM_LINE 200 -#define MSH_SEGM_SPLN 201 -#define MSH_SEGM_CIRC 202 -#define MSH_SEGM_CIRC_INV 203 -#define MSH_SEGM_ELLI 204 -#define MSH_SEGM_ELLI_INV 205 -#define MSH_SEGM_LOOP 206 -#define MSH_SEGM_BSPLN 207 -#define MSH_SEGM_NURBS 208 -#define MSH_SEGM_BEZIER 209 -#define MSH_SEGM_BND_LAYER 211 -#define MSH_SEGM_DISCRETE 212 -#define MSH_SEGM_FROM_GMODEL 213 - -#define MSH_SURF_PLAN 300 -#define MSH_SURF_REGL 301 -#define MSH_SURF_TRIC 302 -#define MSH_SURF_BND_LAYER 303 -#define MSH_SURF_LOOP 304 -#define MSH_SURF_DISCRETE 305 -#define MSH_SURF_FROM_GMODEL 306 - -#define MSH_VOLUME 400 -#define MSH_VOLUME_DISCRETE 401 +#define MSH_POINT 100 +#define MSH_POINT_BND_LAYER 101 +#define MSH_POINT_DISCRETE 102 +#define MSH_POINT_FROM_GMODEL 103 + +#define MSH_SEGM_LINE 200 +#define MSH_SEGM_SPLN 201 +#define MSH_SEGM_CIRC 202 +#define MSH_SEGM_CIRC_INV 203 +#define MSH_SEGM_ELLI 204 +#define MSH_SEGM_ELLI_INV 205 +#define MSH_SEGM_LOOP 206 +#define MSH_SEGM_BSPLN 207 +#define MSH_SEGM_NURBS 208 +#define MSH_SEGM_BEZIER 209 +#define MSH_SEGM_BND_LAYER 211 +#define MSH_SEGM_DISCRETE 212 +#define MSH_SEGM_FROM_GMODEL 213 + +#define MSH_SURF_PLAN 300 +#define MSH_SURF_REGL 301 +#define MSH_SURF_TRIC 302 +#define MSH_SURF_BND_LAYER 303 +#define MSH_SURF_LOOP 304 +#define MSH_SURF_DISCRETE 305 +#define MSH_SURF_FROM_GMODEL 306 + +#define MSH_VOLUME 400 +#define MSH_VOLUME_DISCRETE 401 #define MSH_VOLUME_FROM_GMODEL 402 -#define MSH_PHYSICAL_POINT 500 -#define MSH_PHYSICAL_LINE 501 -#define MSH_PHYSICAL_SURFACE 502 -#define MSH_PHYSICAL_VOLUME 503 +#define MSH_PHYSICAL_POINT 500 +#define MSH_PHYSICAL_LINE 501 +#define MSH_PHYSICAL_SURFACE 502 +#define MSH_PHYSICAL_VOLUME 503 #endif diff --git a/Geo/GeoInterpolation.cpp b/Geo/GeoInterpolation.cpp index 7ff3a32e7b3378475c96aba228c6af5154cf2b14..fd25b284f8ab7a97ec4372c4d128a37def1eb673 100644 --- a/Geo/GeoInterpolation.cpp +++ b/Geo/GeoInterpolation.cpp @@ -58,11 +58,15 @@ static Vertex InterpolateCubicSpline(Vertex *v[4], double t, double mat[4][4], T[0] = t * t * t; } - for(i = 0; i < 4; i++) { vec[i] = 0.0; } + for(i = 0; i < 4; i++) { + vec[i] = 0.0; + } // X for(i = 0; i < 4; i++) { - for(j = 0; j < 4; j++) { vec[i] += mat[i][j] * v[j]->Pos.X; } + for(j = 0; j < 4; j++) { + vec[i] += mat[i][j] * v[j]->Pos.X; + } } for(j = 0; j < 4; j++) { @@ -72,7 +76,9 @@ static Vertex InterpolateCubicSpline(Vertex *v[4], double t, double mat[4][4], // Y for(i = 0; i < 4; i++) { - for(j = 0; j < 4; j++) { vec[i] += mat[i][j] * v[j]->Pos.Y; } + for(j = 0; j < 4; j++) { + vec[i] += mat[i][j] * v[j]->Pos.Y; + } } for(j = 0; j < 4; j++) { @@ -82,7 +88,9 @@ static Vertex InterpolateCubicSpline(Vertex *v[4], double t, double mat[4][4], // Z for(i = 0; i < 4; i++) { - for(j = 0; j < 4; j++) { vec[i] += mat[i][j] * v[j]->Pos.Z; } + for(j = 0; j < 4; j++) { + vec[i] += mat[i][j] * v[j]->Pos.Z; + } } for(j = 0; j < 4; j++) { V.Pos.Z += T[j] * vec[j]; @@ -134,10 +142,14 @@ SPoint2 InterpolateCubicSpline(Vertex *v[4], double t, double mat[4][4], SPoint2 coord[4], p; for(i = 0; i < 4; i++) { - for(j = 0; j < 4; j++) { coord[i] += v[j]->pntOnGeometry * mat[i][j]; } + for(j = 0; j < 4; j++) { + coord[i] += v[j]->pntOnGeometry * mat[i][j]; + } } - for(j = 0; j < 4; j++) { p += coord[j] * T[j]; } + for(j = 0; j < 4; j++) { + p += coord[j] * T[j]; + } return p; } @@ -578,7 +590,9 @@ Vertex InterpolateCurve(Curve *c, double u, int const derivee) List_Read(c->Control_Points, i, &v[1]); List_Read(c->Control_Points, i + 1, &v[2]); if(!i) { - if(c->beg == c->end) { List_Read(c->Control_Points, N - 2, &v[0]); } + if(c->beg == c->end) { + List_Read(c->Control_Points, N - 2, &v[0]); + } else { v[0] = &temp1; v[0]->Pos.X = 2. * v[1]->Pos.X - v[2]->Pos.X; @@ -591,7 +605,9 @@ Vertex InterpolateCurve(Curve *c, double u, int const derivee) List_Read(c->Control_Points, i - 1, &v[0]); } if(i == N - 2) { - if(c->beg == c->end) { List_Read(c->Control_Points, 1, &v[3]); } + if(c->beg == c->end) { + List_Read(c->Control_Points, 1, &v[3]); + } else { v[3] = &temp2; v[3]->Pos.X = 2. * v[2]->Pos.X - v[1]->Pos.X; @@ -840,7 +856,9 @@ static Vertex InterpolateRuledSurface(Surface *s, double u, double v) isSphere = false; } else if(isSphere) { - if(!i) { List_Read(C[i]->Control_Points, 1, &O); } + if(!i) { + List_Read(C[i]->Control_Points, 1, &O); + } else { Vertex *tmp; List_Read(C[i]->Control_Points, 1, &tmp); @@ -920,7 +938,9 @@ static Vertex InterpolateRuledSurface(Surface *s, double u, double v) T = TransfiniteTriB(V[0], VB[0], V[1], VB[1], V[2], VB[2], *S[0], *S[1], *S[2], u, v); } - if(isSphere) { TransfiniteSph(*S[0], *O, &T); } + if(isSphere) { + TransfiniteSph(*S[0], *O, &T); + } } return T; diff --git a/Geo/GeoInterpolation.h b/Geo/GeoInterpolation.h index 4bbff1c1401b7847d774569191020e0bf8874e75..d45ba858c743a3b98bd5b894690a47cf4232df8a 100644 --- a/Geo/GeoInterpolation.h +++ b/Geo/GeoInterpolation.h @@ -16,6 +16,7 @@ class gmshSurface; bool IsRuledSurfaceASphere(Surface *s, SPoint3 ¢er, double &radius); Vertex InterpolateCurve(Curve *Curve, double u, int derivee); Vertex InterpolateSurface(Surface *s, double u, double v, int derivee, int u_v); -SPoint2 InterpolateCubicSpline(Vertex * v[4], double t, double mat[4][4], - double t1, double t2, gmshSurface *s, int derivee); +SPoint2 InterpolateCubicSpline(Vertex *v[4], double t, double mat[4][4], + double t1, double t2, gmshSurface *s, + int derivee); #endif diff --git a/Geo/GeoStringInterface.cpp b/Geo/GeoStringInterface.cpp index 9e808275186508ae6c86b120205e9ac0b2c01fb8..d084df84ba8c50e3d7badd91e36fa42bf6ff3f0d 100644 --- a/Geo/GeoStringInterface.cpp +++ b/Geo/GeoStringInterface.cpp @@ -26,7 +26,7 @@ void add_infile(const std::string &text, const std::string &fileNameOrEmpty) { const std::string &fileName = fileNameOrEmpty; - if(fileName.empty()){ + if(fileName.empty()) { std::string base = (getenv("PWD") ? "" : CTX::instance()->homeDir); GModel::current()->setFileName(base + CTX::instance()->defaultFileName); GModel::current()->setName(""); @@ -37,7 +37,7 @@ void add_infile(const std::string &text, const std::string &fileNameOrEmpty) std::string noExt = split[0] + split[1], ext = split[2]; #if defined(HAVE_COMPRESSED_IO) && defined(HAVE_LIBZ) bool compressed = false; - if(ext == ".gz"){ + if(ext == ".gz") { ext = SplitFileName(noExt)[2]; compressed = true; } @@ -45,24 +45,29 @@ void add_infile(const std::string &text, const std::string &fileNameOrEmpty) // make sure we don't add stuff in a non-geo file static bool proceed = false; if(!CTX::instance()->expertMode && !proceed) { - if(ext.size() && ext != ".geo" && ext != ".GEO" ){ + if(ext.size() && ext != ".geo" && ext != ".GEO") { std::ostringstream sstream; - sstream << - "A scripting command is going to be appended to a non-`.geo' file. Are\n" - "you sure you want to proceed?\n\n" - "You probably want to create a new `.geo' file containing the command\n" - "`Merge \"" << split[1] + split[2] << "\";' and use that file instead.\n\n" - "(To disable this warning in the future, select `Enable expert mode'\n" - "in the option dialog.)"; - int ret = Msg::GetAnswer(sstream.str().c_str(), 2, "Cancel", "Proceed as is", - "Create new `.geo' file"); - if(ret == 2){ + sstream << "A scripting command is going to be appended to a non-`.geo' " + "file. Are\n" + "you sure you want to proceed?\n\n" + "You probably want to create a new `.geo' file containing the " + "command\n" + "`Merge \"" + << split[1] + split[2] + << "\";' and use that file instead.\n\n" + "(To disable this warning in the future, select `Enable " + "expert mode'\n" + "in the option dialog.)"; + int ret = Msg::GetAnswer(sstream.str().c_str(), 2, "Cancel", + "Proceed as is", "Create new `.geo' file"); + if(ret == 2) { std::string newFileName = split[0] + split[1] + ".geo"; if(CTX::instance()->confirmOverwrite) { - if(!StatFile(newFileName)){ + if(!StatFile(newFileName)) { std::ostringstream sstream; - sstream << "File '" << newFileName << "' already exists.\n\n" - "Do you want to replace it?"; + sstream << "File '" << newFileName + << "' already exists.\n\n" + "Do you want to replace it?"; if(!Msg::GetAnswer(sstream.str().c_str(), 0, "Cancel", "Replace")) return; } @@ -72,7 +77,8 @@ void add_infile(const std::string &text, const std::string &fileNameOrEmpty) Msg::Error("Unable to open file '%s'", newFileName.c_str()); return; } - fprintf(fp, "Merge \"%s\";\n%s\n", (split[1] + split[2]).c_str(), text.c_str()); + fprintf(fp, "Merge \"%s\";\n%s\n", (split[1] + split[2]).c_str(), + text.c_str()); fclose(fp); OpenProject(newFileName); return; @@ -85,7 +91,8 @@ void add_infile(const std::string &text, const std::string &fileNameOrEmpty) } #if defined(HAVE_PARSER) - std::string tmpFileName = CTX::instance()->homeDir + CTX::instance()->tmpFileName; + std::string tmpFileName = + CTX::instance()->homeDir + CTX::instance()->tmpFileName; FILE *gmsh_yyin_old = gmsh_yyin; FILE *tmp_file; if(!(tmp_file = Fopen(tmpFileName.c_str(), "w"))) { @@ -119,16 +126,16 @@ void add_infile(const std::string &text, const std::string &fileNameOrEmpty) #endif // mark Gmsh data as changed in onelab - if(text.find("Physical") != std::string::npos){ + if(text.find("Physical") != std::string::npos) { // re-import the physical groups in onelab, and only ask to re-save the mesh Msg::ImportPhysicalGroupsInOnelab(); Msg::SetOnelabChanged(1); } - else if(text.find("Characteristic") != std::string::npos){ + else if(text.find("Characteristic") != std::string::npos) { // only ask to remesh and re-save Msg::SetOnelabChanged(2); } - else{ + else { // ask to reload the geometry, remesh and re-save Msg::SetOnelabChanged(3); } @@ -137,7 +144,7 @@ void add_infile(const std::string &text, const std::string &fileNameOrEmpty) static std::string list2String(List_T *list) { std::ostringstream sstream; - for(int i = 0; i < List_Nbr(list); i++){ + for(int i = 0; i < List_Nbr(list); i++) { int num; List_Read(list, i, &num); if(i) sstream << ", "; @@ -149,7 +156,7 @@ static std::string list2String(List_T *list) static std::string vector2String(const std::vector<int> &v) { std::ostringstream sstream; - for(unsigned int i = 0; i < v.size(); i++){ + for(unsigned int i = 0; i < v.size(); i++) { if(i) sstream << ", "; sstream << v[i]; } @@ -159,8 +166,8 @@ static std::string vector2String(const std::vector<int> &v) static std::string dimTags2String(const std::vector<std::pair<int, int> > &l) { std::ostringstream sstream; - for(unsigned int i = 0; i < l.size(); i++){ - switch(l[i].first){ + for(unsigned int i = 0; i < l.size(); i++) { + switch(l[i].first) { case 0: sstream << "Point{" << l[i].second << "}; "; break; case 1: sstream << "Curve{" << l[i].second << "}; "; break; case 2: sstream << "Surface{" << l[i].second << "}; "; break; @@ -173,7 +180,8 @@ static std::string dimTags2String(const std::vector<std::pair<int, int> > &l) static void check_occ(std::ostringstream &sstream) { #if defined(HAVE_PARSER) - if(gmsh_yyfactory != "OpenCASCADE") sstream << "SetFactory(\"OpenCASCADE\");\n"; + if(gmsh_yyfactory != "OpenCASCADE") + sstream << "SetFactory(\"OpenCASCADE\");\n"; #endif } @@ -181,7 +189,8 @@ void add_charlength(const std::string &fileName, const std::vector<int> &l, const std::string &lc) { std::ostringstream sstream; - sstream << "Characteristic Length {" << vector2String(l) << "} = " << lc << ";"; + sstream << "Characteristic Length {" << vector2String(l) << "} = " << lc + << ";"; add_infile(sstream.str(), fileName); } @@ -198,7 +207,7 @@ void add_trsfline(std::vector<int> &l, const std::string &fileName, { std::ostringstream sstream; sstream << "Transfinite Curve {"; - for(unsigned int i = 0; i < l.size(); i++){ + for(unsigned int i = 0; i < l.size(); i++) { if(i) sstream << ", "; sstream << l[i]; } @@ -213,7 +222,7 @@ void add_trsfsurf(std::vector<int> &l, const std::string &fileName, { std::ostringstream sstream; sstream << "Transfinite Surface {" << l[0] << "}"; - if(l.size() > 1){ + if(l.size() > 1) { sstream << " = {"; for(unsigned int i = 1; i < l.size(); i++) { if(i > 1) sstream << ", "; @@ -221,8 +230,7 @@ void add_trsfsurf(std::vector<int> &l, const std::string &fileName, } sstream << "}"; } - if(dir != "Left") - sstream << " " << dir; + if(dir != "Left") sstream << " " << dir; sstream << ";"; add_infile(sstream.str(), fileName); } @@ -244,8 +252,10 @@ void add_embedded(const std::string &fileName, const std::string &what, { std::ostringstream sstream; sstream << what << "{" << vector2String(l) << "} In "; - if(dim == 2) sstream << "Surface{"; - else sstream << "Volume{"; + if(dim == 2) + sstream << "Surface{"; + else + sstream << "Volume{"; sstream << tag << "};"; add_infile(sstream.str(), fileName); } @@ -269,8 +279,9 @@ void add_param(const std::string &par, const std::string &value, add_infile(sstream.str(), fileName); } -void add_point(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &lc) +void add_point(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &lc) { std::ostringstream sstream; sstream << "Point(" << GModel::current()->getMaxElementaryNumber(0) + 1 @@ -281,7 +292,8 @@ void add_point(const std::string &fileName, const std::string &x, const std::str } void add_field_option(int field_id, const std::string &option_name, - const std::string &option_value, const std::string &fileName) + const std::string &option_value, + const std::string &fileName) { std::ostringstream sstream; sstream << "Field[" << field_id << "]." << option_name << " = " @@ -289,7 +301,8 @@ void add_field_option(int field_id, const std::string &option_name, add_infile(sstream.str(), fileName); } -void add_field(int field_id, const std::string &type_name, const std::string &fileName) +void add_field(int field_id, const std::string &type_name, + const std::string &fileName) { std::ostringstream sstream; sstream << "Field[" << field_id << "] = " << type_name << ";"; @@ -332,12 +345,12 @@ void add_circle_arc(int p1, int p2, int p3, const std::string &fileName) add_infile(sstream.str(), fileName); } -void add_ellipse_arc(int p1, int p2, int p3, int p4, const std::string &fileName) +void add_ellipse_arc(int p1, int p2, int p3, int p4, + const std::string &fileName) { std::ostringstream sstream; sstream << "Ellipse(" << GModel::current()->getMaxElementaryNumber(1) + 1 - << ") = {" << p1 << ", " << p2 << ", " - << p3 << ", " << p4 << "};"; + << ") = {" << p1 << ", " << p2 << ", " << p3 << ", " << p4 << "};"; add_infile(sstream.str(), fileName); } @@ -346,14 +359,15 @@ void add_lineloop(List_T *list, const std::string &fileName, int *numloop) if(RecognizeLineLoop(list, numloop)) return; *numloop = GModel::current()->getGEOInternals()->getMaxTag(-1) + 1; if(GModel::current()->getOCCInternals()) - *numloop = std::max - (*numloop, GModel::current()->getOCCInternals()->getMaxTag(-1) + 1); + *numloop = std::max( + *numloop, GModel::current()->getOCCInternals()->getMaxTag(-1) + 1); std::ostringstream sstream; sstream << "Curve Loop(" << *numloop << ") = {" << list2String(list) << "};"; add_infile(sstream.str(), fileName); } -void add_surf(const std::string &type, List_T *list, const std::string &fileName) +void add_surf(const std::string &type, List_T *list, + const std::string &fileName) { std::ostringstream sstream; sstream << type << "(" << GModel::current()->getMaxElementaryNumber(2) + 1 @@ -366,10 +380,11 @@ void add_surfloop(List_T *list, const std::string &fileName, int *numloop) if(RecognizeSurfaceLoop(list, numloop)) return; *numloop = GModel::current()->getGEOInternals()->getMaxTag(-2) + 1; if(GModel::current()->getOCCInternals()) - *numloop = std::max - (*numloop, GModel::current()->getOCCInternals()->getMaxTag(-2) + 1); + *numloop = std::max( + *numloop, GModel::current()->getOCCInternals()->getMaxTag(-2) + 1); std::ostringstream sstream; - sstream << "Surface Loop(" << *numloop << ") = {" << list2String(list) << "};"; + sstream << "Surface Loop(" << *numloop << ") = {" << list2String(list) + << "};"; add_infile(sstream.str(), fileName); } @@ -387,14 +402,15 @@ void add_remove_physical(const std::string &fileName, const std::string &what, { std::ostringstream sstream; sstream << "Physical " << what << "("; - if(name.size()){ + if(name.size()) { sstream << "\"" << name << "\""; - if(forceTag) - sstream << ", " << forceTag; + if(forceTag) sstream << ", " << forceTag; } - else{ - sstream << (forceTag ? forceTag : - GModel::current()->getGEOInternals()->getMaxPhysicalTag() + 1); + else { + sstream << (forceTag ? + forceTag : + GModel::current()->getGEOInternals()->getMaxPhysicalTag() + + 1); } sstream << ") "; if(mode == "Remove") @@ -410,157 +426,157 @@ void add_compound(const std::string &fileName, const std::string &type, { std::ostringstream sstream; if(SplitFileName(fileName)[2] != ".geo") sstream << "CreateTopology;\n"; - if (type == "Surface"){ + if(type == "Surface") { sstream << "Compound " << type << "(" << GModel::current()->getMaxElementaryNumber(2) + 1 << ") = {" - << vector2String(l) << "};"; + << vector2String(l) << "};"; } - else if (type == "Curve"){ + else if(type == "Curve") { sstream << "Compound " << type << "(" << GModel::current()->getMaxElementaryNumber(1) + 1 << ") = {" - << vector2String(l) << "};"; + << vector2String(l) << "};"; } - else{ + else { sstream << "Compound " << type << "(" << GModel::current()->getMaxElementaryNumber(3) + 1 << ") = {" - << vector2String(l) << "};"; + << vector2String(l) << "};"; } add_infile(sstream.str(), fileName); } -void add_circle(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &r, const std::string &alpha1, +void add_circle(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &r, const std::string &alpha1, const std::string &alpha2) { std::ostringstream sstream; check_occ(sstream); sstream << "Circle(" << GModel::current()->getMaxElementaryNumber(1) + 1 << ") = {" << x << ", " << y << ", " << z << ", " << r; - if(alpha1.size()) - sstream << ", " << alpha1; - if(alpha1.size() && alpha2.size()) - sstream << ", " << alpha2; + if(alpha1.size()) sstream << ", " << alpha1; + if(alpha1.size() && alpha2.size()) sstream << ", " << alpha2; sstream << "};"; add_infile(sstream.str(), fileName); } -void add_ellipse(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &rx, const std::string &ry, +void add_ellipse(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &rx, const std::string &ry, const std::string &alpha1, const std::string &alpha2) { std::ostringstream sstream; check_occ(sstream); sstream << "Ellipse(" << GModel::current()->getMaxElementaryNumber(1) + 1 << ") = {" << x << ", " << y << ", " << z << ", " << rx << ", " << ry; - if(alpha1.size()) - sstream << ", " << alpha1; - if(alpha1.size() && alpha2.size()) - sstream << ", " << alpha2; + if(alpha1.size()) sstream << ", " << alpha1; + if(alpha1.size() && alpha2.size()) sstream << ", " << alpha2; sstream << "};"; add_infile(sstream.str(), fileName); } -void add_disk(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &rx, const std::string &ry) +void add_disk(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, const std::string &rx, + const std::string &ry) { std::ostringstream sstream; check_occ(sstream); sstream << "Disk(" << GModel::current()->getMaxElementaryNumber(2) + 1 - << ") = {" << x << ", " << y << ", " << z << ", " << rx << ", " << ry << "};"; + << ") = {" << x << ", " << y << ", " << z << ", " << rx << ", " << ry + << "};"; add_infile(sstream.str(), fileName); } -void add_rectangle(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, +void add_rectangle(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &dx, const std::string &dy, const std::string &roundedRadius) { std::ostringstream sstream; check_occ(sstream); sstream << "Rectangle(" << GModel::current()->getMaxElementaryNumber(2) + 1 << ") = {" << x << ", " << y << ", " << z << ", " << dx << ", " << dy; - if(roundedRadius.size()) - sstream << ", " << roundedRadius; + if(roundedRadius.size()) sstream << ", " << roundedRadius; sstream << "};"; add_infile(sstream.str(), fileName); } -void add_sphere(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &r, const std::string &alpha1, +void add_sphere(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &r, const std::string &alpha1, const std::string &alpha2, const std::string &alpha3) { std::ostringstream sstream; check_occ(sstream); sstream << "Sphere(" << GModel::current()->getMaxElementaryNumber(3) + 1 << ") = {" << x << ", " << y << ", " << z << ", " << r; - if(alpha1.size()) - sstream << ", " << alpha1; - if(alpha1.size() && alpha2.size()) - sstream << ", " << alpha2; - if(alpha1.size() && alpha2.size() && alpha3.size()) - sstream << ", " << alpha3; + if(alpha1.size()) sstream << ", " << alpha1; + if(alpha1.size() && alpha2.size()) sstream << ", " << alpha2; + if(alpha1.size() && alpha2.size() && alpha3.size()) sstream << ", " << alpha3; sstream << "};"; add_infile(sstream.str(), fileName); } -void add_cylinder(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, - const std::string &dz, const std::string &r, const std::string &alpha) +void add_cylinder(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &dx, const std::string &dy, + const std::string &dz, const std::string &r, + const std::string &alpha) { std::ostringstream sstream; check_occ(sstream); sstream << "Cylinder(" << GModel::current()->getMaxElementaryNumber(3) + 1 << ") = {" << x << ", " << y << ", " << z << ", " << dx << ", " << dy << ", " << dz << ", " << r; - if(alpha.size()) - sstream << ", " << alpha; + if(alpha.size()) sstream << ", " << alpha; sstream << "};"; add_infile(sstream.str(), fileName); } -void add_box(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, - const std::string &dz) +void add_box(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, const std::string &dx, + const std::string &dy, const std::string &dz) { std::ostringstream sstream; check_occ(sstream); sstream << "Box(" << GModel::current()->getMaxElementaryNumber(3) + 1 - << ") = {" << x << ", " << y << ", " << z << ", " << dx << ", " - << dy << ", " << dz << "};"; + << ") = {" << x << ", " << y << ", " << z << ", " << dx << ", " << dy + << ", " << dz << "};"; add_infile(sstream.str(), fileName); } -void add_torus(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &r1, const std::string &r2, +void add_torus(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &r1, const std::string &r2, const std::string &alpha) { std::ostringstream sstream; check_occ(sstream); sstream << "Torus(" << GModel::current()->getMaxElementaryNumber(3) + 1 << ") = {" << x << ", " << y << ", " << z << ", " << r1 << ", " << r2; - if(alpha.size()) - sstream << ", " << alpha; + if(alpha.size()) sstream << ", " << alpha; sstream << "};"; add_infile(sstream.str(), fileName); } -void add_cone(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, - const std::string &dz, const std::string &r1, const std::string &r2, +void add_cone(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, const std::string &dx, + const std::string &dy, const std::string &dz, + const std::string &r1, const std::string &r2, const std::string &alpha) { std::ostringstream sstream; check_occ(sstream); sstream << "Cone(" << GModel::current()->getMaxElementaryNumber(3) + 1 - << ") = {" << x << ", " << y << ", " << z << ", " << dx << ", " - << dy << ", " << dz << ", " << r1 << ", " << r2; - if(alpha.size()) - sstream << ", " << alpha; + << ") = {" << x << ", " << y << ", " << z << ", " << dx << ", " << dy + << ", " << dz << ", " << r1 << ", " << r2; + if(alpha.size()) sstream << ", " << alpha; sstream << "};"; add_infile(sstream.str(), fileName); } -void add_wedge(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, +void add_wedge(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &dx, const std::string &dy, const std::string &dz, const std::string <x) { std::ostringstream sstream; @@ -571,9 +587,10 @@ void add_wedge(const std::string &fileName, const std::string &x, const std::str add_infile(sstream.str(), fileName); } -void translate(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &tx, const std::string &ty, const std::string &tz, - bool duplicata) +void translate(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, + const std::string &tx, const std::string &ty, + const std::string &tz, bool duplicata) { std::ostringstream sstream; sstream << "Translate {" << tx << ", " << ty << ", " << tz << "} {\n "; @@ -584,14 +601,15 @@ void translate(const std::string &fileName, const std::vector<std::pair<int, int add_infile(sstream.str(), fileName); } -void rotate(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &ax, const std::string &ay, const std::string &az, - const std::string &px, const std::string &py, const std::string &pz, +void rotate(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &ax, + const std::string &ay, const std::string &az, const std::string &px, + const std::string &py, const std::string &pz, const std::string &angle, bool duplicata) { std::ostringstream sstream; - sstream << "Rotate {{" << ax << ", " << ay << ", " << az << "}, {" - << px << ", " << py << ", " << pz << "}, " << angle << "} {\n "; + sstream << "Rotate {{" << ax << ", " << ay << ", " << az << "}, {" << px + << ", " << py << ", " << pz << "}, " << angle << "} {\n "; if(duplicata) sstream << "Duplicata { "; sstream << dimTags2String(l); if(duplicata) sstream << "}"; @@ -599,14 +617,14 @@ void rotate(const std::string &fileName, const std::vector<std::pair<int, int> > add_infile(sstream.str(), fileName); } -void dilate(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &cx, const std::string &cy, const std::string &cz, - const std::string &sx, const std::string &sy, const std::string &sz, - bool duplicata) +void dilate(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &cx, + const std::string &cy, const std::string &cz, const std::string &sx, + const std::string &sy, const std::string &sz, bool duplicata) { std::ostringstream sstream; - sstream << "Dilate {{" << cx << ", " << cy << ", " << cz << "}, {" - << sx << ", " << sy << ", " << sz << "}} {\n "; + sstream << "Dilate {{" << cx << ", " << cy << ", " << cz << "}, {" << sx + << ", " << sy << ", " << sz << "}} {\n "; if(duplicata) sstream << "Duplicata { "; sstream << dimTags2String(l); if(duplicata) sstream << "}"; @@ -614,12 +632,14 @@ void dilate(const std::string &fileName, const std::vector<std::pair<int, int> > add_infile(sstream.str(), fileName); } -void symmetry(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &sa, const std::string &sb, const std::string &sc, +void symmetry(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &sa, + const std::string &sb, const std::string &sc, const std::string &sd, bool duplicata) { std::ostringstream sstream; - sstream << "Symmetry {" << sa << ", " << sb << ", " << sc << ", " << sd << "} {\n "; + sstream << "Symmetry {" << sa << ", " << sb << ", " << sc << ", " << sd + << "} {\n "; if(duplicata) sstream << "Duplicata { "; sstream << dimTags2String(l); if(duplicata) sstream << "}"; @@ -627,14 +647,15 @@ void symmetry(const std::string &fileName, const std::vector<std::pair<int, int> add_infile(sstream.str(), fileName); } -void extrude(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &tx, const std::string &ty, const std::string &tz, - bool extrudeMesh, const std::string &layers, bool recombineMesh) +void extrude(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &tx, + const std::string &ty, const std::string &tz, bool extrudeMesh, + const std::string &layers, bool recombineMesh) { std::ostringstream sstream; sstream << "Extrude {" << tx << ", " << ty << ", " << tz << "} {\n " << dimTags2String(l); - if(extrudeMesh){ + if(extrudeMesh) { sstream << "Layers{" << layers << "}; "; if(recombineMesh) sstream << "Recombine;"; } @@ -642,17 +663,18 @@ void extrude(const std::string &fileName, const std::vector<std::pair<int, int> add_infile(sstream.str(), fileName); } -void protude(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &ax, const std::string &ay, const std::string &az, - const std::string &px, const std::string &py, const std::string &pz, - const std::string &angle, bool extrudeMesh, const std::string &layers, - bool recombineMesh) +void protude(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &ax, + const std::string &ay, const std::string &az, + const std::string &px, const std::string &py, + const std::string &pz, const std::string &angle, bool extrudeMesh, + const std::string &layers, bool recombineMesh) { std::ostringstream sstream; - sstream << "Extrude {{" << ax << ", " << ay << ", " << az << "}, {" - << px << ", " << py << ", " << pz << "}, " << angle << "} {\n " + sstream << "Extrude {{" << ax << ", " << ay << ", " << az << "}, {" << px + << ", " << py << ", " << pz << "}, " << angle << "} {\n " << dimTags2String(l); - if(extrudeMesh){ + if(extrudeMesh) { sstream << "Layers{" << layers << "}; "; if(recombineMesh) sstream << "Recombine;"; } @@ -660,23 +682,27 @@ void protude(const std::string &fileName, const std::vector<std::pair<int, int> add_infile(sstream.str(), fileName); } -void add_pipe(const std::string &fileName, const std::vector<std::pair<int, int> > &l, +void add_pipe(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::vector<int> &l2) { std::ostringstream sstream; check_occ(sstream); int wire = GModel::current()->getGEOInternals()->getMaxTag(-1) + 1; if(GModel::current()->getOCCInternals()) - wire = std::max(wire, GModel::current()->getOCCInternals()->getMaxTag(-1) + 1); + wire = + std::max(wire, GModel::current()->getOCCInternals()->getMaxTag(-1) + 1); sstream << "Wire(" << wire << ") = {" << vector2String(l2) << "};\n"; - sstream << "Extrude { " << dimTags2String(l) << "} Using Wire {" << wire << "}\n"; + sstream << "Extrude { " << dimTags2String(l) << "} Using Wire {" << wire + << "}\n"; add_infile(sstream.str(), fileName); } void split_edge(int edge_id, List_T *vertices, const std::string &fileName) { std::ostringstream sstream; - sstream << "Split Curve(" << edge_id << ") {" << list2String(vertices) << "};"; + sstream << "Split Curve(" << edge_id << ") {" << list2String(vertices) + << "};"; add_infile(sstream.str(), fileName); } @@ -700,8 +726,8 @@ void apply_fillet(const std::string &fileName, const std::vector<int> ®ions, { std::ostringstream sstream; check_occ(sstream); - sstream << "Fillet{" << vector2String(regions) << "}{" - << vector2String(edges) << "}{" << radius << "}"; + sstream << "Fillet{" << vector2String(regions) << "}{" << vector2String(edges) + << "}{" << radius << "}"; add_infile(sstream.str(), fileName); } diff --git a/Geo/GeoStringInterface.h b/Geo/GeoStringInterface.h index c75c7fde499099f90c36dea98054dea5e4441419..662297ca62ef0994e7b4f1db736e50c203d9b232 100644 --- a/Geo/GeoStringInterface.h +++ b/Geo/GeoStringInterface.h @@ -26,19 +26,23 @@ void add_param(const std::string &par, const std::string &value, const std::string &label, const std::string &path, const std::string &fileName); void add_point(const std::string &fileName, const std::string &x, - const std::string &y, const std::string &z, const std::string &lc); + const std::string &y, const std::string &z, + const std::string &lc); void add_multline(const std::string &type, std::vector<int> &p, const std::string &fileName); void add_circle_arc(int p1, int p2, int p3, const std::string &fileName); -void add_ellipse_arc(int p1, int p2, int p3, int p4, const std::string &fileName); +void add_ellipse_arc(int p1, int p2, int p3, int p4, + const std::string &fileName); void add_field_option(int field_id, const std::string &option_name, - const std::string &option_value, const std::string &fileName); + const std::string &option_value, + const std::string &fileName); void add_field(int field_id, const std::string &type_name, const std::string &fileName); void delete_field(int field_id, const std::string &fileName); -void set_background_field(int field_id,const std::string &fileName); +void set_background_field(int field_id, const std::string &fileName); void add_lineloop(List_T *list, const std::string &fileName, int *numloop); -void add_surf(const std::string &type, List_T *list, const std::string &fileName); +void add_surf(const std::string &type, List_T *list, + const std::string &fileName); void add_surfloop(List_T *list, const std::string &fileName, int *numvol); void add_vol(List_T *list, const std::string &fileName); void add_remove_physical(const std::string &fileName, const std::string &what, @@ -47,59 +51,74 @@ void add_remove_physical(const std::string &fileName, const std::string &what, void add_compound(const std::string &fileName, const std::string &type, const std::vector<int> &l); void add_circle(const std::string &fileName, const std::string &x, - const std::string &y, const std::string &z, const std::string &r, - const std::string &alpha1, const std::string &alpha2); -void add_ellipse(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &rx, const std::string &ry, + const std::string &y, const std::string &z, + const std::string &r, const std::string &alpha1, + const std::string &alpha2); +void add_ellipse(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &rx, const std::string &ry, const std::string &alpha1, const std::string &alpha2); -void add_disk(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &rx, const std::string &ry); -void add_rectangle(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, +void add_disk(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, const std::string &rx, + const std::string &ry); +void add_rectangle(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &dx, const std::string &dy, const std::string &roundedRadius); void add_sphere(const std::string &fileName, const std::string &x, - const std::string &y, const std::string &z, const std::string &r, - const std::string &alpha1, const std::string &alpha2, - const std::string &alpha3); -void add_cylinder(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, - const std::string &dz, const std::string &r, const std::string &alpha); -void add_box(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, - const std::string &dz); -void add_torus(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &r1, const std::string &r2, + const std::string &y, const std::string &z, + const std::string &r, const std::string &alpha1, + const std::string &alpha2, const std::string &alpha3); +void add_cylinder(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &dx, const std::string &dy, + const std::string &dz, const std::string &r, + const std::string &alpha); +void add_box(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, const std::string &dx, + const std::string &dy, const std::string &dz); +void add_torus(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &r1, const std::string &r2, const std::string &alpha); -void add_cone(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, - const std::string &dz, const std::string &r1, const std::string &r2, +void add_cone(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, const std::string &dx, + const std::string &dy, const std::string &dz, + const std::string &r1, const std::string &r2, const std::string &alpha); -void add_wedge(const std::string &fileName, const std::string &x, const std::string &y, - const std::string &z, const std::string &dx, const std::string &dy, +void add_wedge(const std::string &fileName, const std::string &x, + const std::string &y, const std::string &z, + const std::string &dx, const std::string &dy, const std::string &dz, const std::string <x); -void translate(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &tx, const std::string &ty, const std::string &tz, - bool duplicata); -void rotate(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &ax, const std::string &ay, const std::string &az, - const std::string &px, const std::string &py, const std::string &pz, +void translate(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, + const std::string &tx, const std::string &ty, + const std::string &tz, bool duplicata); +void rotate(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &ax, + const std::string &ay, const std::string &az, const std::string &px, + const std::string &py, const std::string &pz, const std::string &angle, bool duplicata); -void dilate(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &cx, const std::string &cy, const std::string &cz, - const std::string &sx, const std::string &sy, const std::string &sz, - bool duplicata); -void symmetry(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &sa, const std::string &sb, const std::string &sc, +void dilate(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &cx, + const std::string &cy, const std::string &cz, const std::string &sx, + const std::string &sy, const std::string &sz, bool duplicata); +void symmetry(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &sa, + const std::string &sb, const std::string &sc, const std::string &sd, bool duplicata); -void extrude(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &tx, const std::string &ty, const std::string &tz, - bool extrudeMesh, const std::string &layers, bool recombineMesh); -void protude(const std::string &fileName, const std::vector<std::pair<int, int> > &l, - const std::string &ax, const std::string &ay, const std::string &az, - const std::string &px, const std::string &py, const std::string &pz, - const std::string &angle, bool extrudeMesh, const std::string &layers, - bool recombineMesh); -void add_pipe(const std::string &fileName, const std::vector<std::pair<int, int> > &l, +void extrude(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &tx, + const std::string &ty, const std::string &tz, bool extrudeMesh, + const std::string &layers, bool recombineMesh); +void protude(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::string &ax, + const std::string &ay, const std::string &az, + const std::string &px, const std::string &py, + const std::string &pz, const std::string &angle, bool extrudeMesh, + const std::string &layers, bool recombineMesh); +void add_pipe(const std::string &fileName, + const std::vector<std::pair<int, int> > &l, const std::vector<int> &l2); void split_edge(int edge_id, List_T *vertices, const std::string &fileName); void apply_boolean(const std::string &fileName, const std::string &op, diff --git a/Geo/GeomMeshMatcher.cpp b/Geo/GeomMeshMatcher.cpp index 728c2f1c73c4a429b993878eb71cf648e8dbb6fd..373ba4366983c72cb2e50e3e45fd54e5eec44cc4 100644 --- a/Geo/GeomMeshMatcher.cpp +++ b/Geo/GeomMeshMatcher.cpp @@ -39,7 +39,7 @@ void getIntersection(std::vector<T> &res, std::vector<container> &lists) { res.clear(); - container const& first_list = lists[0]; + container const &first_list = lists[0]; bool allsame = true; for(typename container::const_iterator item = first_list.begin(); item != first_list.end(); item++) { @@ -59,137 +59,142 @@ void getIntersection(std::vector<T> &res, std::vector<container> &lists) } } } - if(found || allsame) { res.push_back(*item); } + if(found || allsame) { + res.push_back(*item); + } } } -template <class T> T findMatching(std::vector<Pair<T,T> >& matching, T& entity) +template <class T> T findMatching(std::vector<Pair<T, T> > &matching, T &entity) { - for (typename std::vector<Pair<T,T> >::iterator pair = matching.begin(); - pair != matching.end(); pair++) { - if ( (*pair).left() == entity) return((*pair).right()); + for(typename std::vector<Pair<T, T> >::iterator pair = matching.begin(); + pair != matching.end(); pair++) { + if((*pair).left() == entity) return ((*pair).right()); } return (0); } - // Private -// ------------------------------------------------------------[ Matching vertices ] +// ------------------------------------------------------------[ Matching +// vertices ] -std::vector<Pair<GVertex*,GVertex*> >* -GeomMeshMatcher::matchVertices(GModel* m1, GModel *m2, bool& ok) +std::vector<Pair<GVertex *, GVertex *> > * +GeomMeshMatcher::matchVertices(GModel *m1, GModel *m2, bool &ok) { - // Vector that will be returned. - std::vector<Pair<GVertex*,GVertex*> >* coresp_v = new std::vector<Pair<GVertex*, - GVertex*> >; + std::vector<Pair<GVertex *, GVertex *> > *coresp_v = + new std::vector<Pair<GVertex *, GVertex *> >; int num_matched_vertices = 0; int num_total_vertices = m2->getNumVertices(); - std::vector<GVertex*> vertices; + std::vector<GVertex *> vertices; - for(GModel::viter vit = m1->firstVertex(); vit != m1->lastVertex(); vit++) { - - GVertex* v1 = (GVertex*) *vit; + for(GModel::viter vit = m1->firstVertex(); vit != m1->lastVertex(); vit++) { + GVertex *v1 = (GVertex *)*vit; // FIXME: need a *much* better way to fix the tolerance... double tol = CTX::instance()->geom.matchMeshTolerance; - discreteVertex* best_candidate = 0; - GEntity* best_candidate_ge = 0; + discreteVertex *best_candidate = 0; + GEntity *best_candidate_ge = 0; double best_score = DBL_MAX; - for(GModel::viter vit2 = m2->firstVertex(); vit2 != m2->lastVertex(); vit2++) { - - discreteVertex* v2 = (discreteVertex*) *vit2; + for(GModel::viter vit2 = m2->firstVertex(); vit2 != m2->lastVertex(); + vit2++) { + discreteVertex *v2 = (discreteVertex *)*vit2; // We match the vertices if their coordinates are the same under the // specified tolerance. - double score = std::max(fabs(v1->x() - v2->x()), - std::max(fabs(v1->y() - v2->y()), - fabs(v1->z() - v2->z()))); - if (score < tol && score < best_score) { + double score = + std::max(fabs(v1->x() - v2->x()), + std::max(fabs(v1->y() - v2->y()), fabs(v1->z() - v2->z()))); + if(score < tol && score < best_score) { best_candidate = v2; best_candidate_ge = (*vit2); best_score = score; } } - if (best_score != DBL_MAX) { - Msg::Debug("Model Vertex %i (geom) and %i (mesh) match", - v1->tag(), + if(best_score != DBL_MAX) { + Msg::Debug("Model Vertex %i (geom) and %i (mesh) match", v1->tag(), best_candidate_ge->tag()); - coresp_v->push_back(Pair<GVertex*,GVertex*>(v1, best_candidate)); + coresp_v->push_back(Pair<GVertex *, GVertex *>(v1, best_candidate)); num_matched_vertices++; } } if(num_matched_vertices != num_total_vertices) ok = false; - Msg::Info("Matched %i vertices out of %i.", num_matched_vertices, num_total_vertices); + Msg::Info("Matched %i vertices out of %i.", num_matched_vertices, + num_total_vertices); return (coresp_v); } -// ------------------------------------------------------------[ Matching edges ] +// ------------------------------------------------------------[ Matching edges +// ] -std::vector<Pair<GEdge*,GEdge*> >* -GeomMeshMatcher::matchEdges(GModel* m1, GModel* m2, - std::vector<Pair<GVertex*,GVertex*> >* coresp_v, bool& ok) +std::vector<Pair<GEdge *, GEdge *> > * +GeomMeshMatcher::matchEdges(GModel *m1, GModel *m2, + std::vector<Pair<GVertex *, GVertex *> > *coresp_v, + bool &ok) { - int num_matched_edges = 0; int num_total_edges = m2->getNumEdges(); // Vector that will be returned. - std::vector<Pair<GEdge*,GEdge*> >* coresp_e = new std::vector<Pair<GEdge*,GEdge*> >; - - std::vector<GEdge*> closed_curves; + std::vector<Pair<GEdge *, GEdge *> > *coresp_e = + new std::vector<Pair<GEdge *, GEdge *> >; - for(GModel::eiter eit = m1->firstEdge(); eit != m1->lastEdge(); eit++) { + std::vector<GEdge *> closed_curves; - GEdge* e1 = (GEdge*) *eit; + for(GModel::eiter eit = m1->firstEdge(); eit != m1->lastEdge(); eit++) { + GEdge *e1 = (GEdge *)*eit; - GVertex* v1 = e1->getBeginVertex(); - GVertex* v2 = e1->getEndVertex(); + GVertex *v1 = e1->getBeginVertex(); + GVertex *v2 = e1->getEndVertex(); - std::vector<GEdge*> common_edges; - std::vector<std::vector<GEdge*> > lists; + std::vector<GEdge *> common_edges; + std::vector<std::vector<GEdge *> > lists; - if (v1 == v2) { + if(v1 == v2) { Msg::Debug("Found a closed curve"); closed_curves.push_back(e1); - for (GModel::eiter eit2 = m2->firstEdge(); eit2 != m2->lastEdge(); eit2++) { - GEdge* e2 = (GEdge*)*eit2; - GVertex* v3 = e2->getBeginVertex(); - GVertex* v4 = e2->getEndVertex(); - if (v3 == v4) { - Msg::Debug("Found a loop (%i) in the mesh %i %i", e2->tag(), v3->tag(), v3->tag()); + for(GModel::eiter eit2 = m2->firstEdge(); eit2 != m2->lastEdge(); + eit2++) { + GEdge *e2 = (GEdge *)*eit2; + GVertex *v3 = e2->getBeginVertex(); + GVertex *v4 = e2->getEndVertex(); + if(v3 == v4) { + Msg::Debug("Found a loop (%i) in the mesh %i %i", e2->tag(), + v3->tag(), v3->tag()); common_edges.push_back(e2); } } - } else { - //if (coresp_v->count(vfindMatching<GVertex*>(*coresp_v,v1)1) > 0 && coresp_v->count(v2) > 0) { + } + else { + // if (coresp_v->count(vfindMatching<GVertex*>(*coresp_v,v1)1) > 0 && + // coresp_v->count(v2) > 0) { bool ok1 = false; bool ok2 = false; - if (findMatching<GVertex*>(*coresp_v,v1) != 0) { + if(findMatching<GVertex *>(*coresp_v, v1) != 0) { ok1 = true; - lists.push_back((findMatching<GVertex*>(*coresp_v,v1))->edges()); + lists.push_back((findMatching<GVertex *>(*coresp_v, v1))->edges()); } - if (findMatching<GVertex*>(*coresp_v,v2) != 0) { + if(findMatching<GVertex *>(*coresp_v, v2) != 0) { ok2 = true; - lists.push_back((findMatching<GVertex*>(*coresp_v,v2))->edges()); + lists.push_back((findMatching<GVertex *>(*coresp_v, v2))->edges()); } - if (ok1 && ok2) - getIntersection<GEdge*>(common_edges, lists); + if(ok1 && ok2) getIntersection<GEdge *>(common_edges, lists); } - GEdge* choice = 0; - if (common_edges.size() == 0) continue; - if (common_edges.size() == 1) { + GEdge *choice = 0; + if(common_edges.size() == 0) continue; + if(common_edges.size() == 1) { choice = common_edges[0]; - } else { + } + else { // More than one edge between the two points ? No worries, let // us use those bounding boxes ! // So, first step is to build an array of points taken on the geo entity @@ -198,22 +203,21 @@ GeomMeshMatcher::matchEdges(GModel* m1, GModel* m2, double best_score = DBL_MAX; // Next, let's iterate over the mesh entities. - for (std::vector<GEdge*>::iterator candidate = common_edges.begin(); - candidate != common_edges.end(); candidate++) { + for(std::vector<GEdge *>::iterator candidate = common_edges.begin(); + candidate != common_edges.end(); candidate++) { SOrientedBoundingBox mesh_obb = (*candidate)->getOBB(); - double score = SOrientedBoundingBox::compare(geo_obb,mesh_obb); - if (score < best_score) { + double score = SOrientedBoundingBox::compare(geo_obb, mesh_obb); + if(score < best_score) { best_score = score; choice = (*candidate); } } } - Msg::Debug("Edges %i (geom) and %i (mesh) match.", - e1->tag(), + Msg::Debug("Edges %i (geom) and %i (mesh) match.", e1->tag(), choice->tag()); - coresp_e->push_back(Pair<GEdge*,GEdge*>(e1, choice)); - //choice->setTag(e1->tag()); + coresp_e->push_back(Pair<GEdge *, GEdge *>(e1, choice)); + // choice->setTag(e1->tag()); num_matched_edges++; } @@ -223,75 +227,77 @@ GeomMeshMatcher::matchEdges(GModel* m1, GModel* m2, return (coresp_e); } -// ------------------------------------------------------------[ Matching faces ] +// ------------------------------------------------------------[ Matching faces +// ] - -std::vector<Pair<GFace*,GFace*> >* -GeomMeshMatcher:: matchFaces(GModel* m1, GModel* m2, - std::vector<Pair<GEdge*,GEdge*> >* coresp_e, bool& ok) +std::vector<Pair<GFace *, GFace *> > * +GeomMeshMatcher::matchFaces(GModel *m1, GModel *m2, + std::vector<Pair<GEdge *, GEdge *> > *coresp_e, + bool &ok) { int num_matched_faces = 0; int num_total_faces = m2->getNumFaces(); - std::vector<Pair<GFace*,GFace*> >* coresp_f = new std::vector<Pair<GFace*,GFace*> >; - - for(GModel::fiter fit = m1->firstFace(); fit != m1->lastFace(); fit++) { + std::vector<Pair<GFace *, GFace *> > *coresp_f = + new std::vector<Pair<GFace *, GFace *> >; - GFace* f1 = (GFace*) *fit; + for(GModel::fiter fit = m1->firstFace(); fit != m1->lastFace(); fit++) { + GFace *f1 = (GFace *)*fit; - std::vector<std::vector<GFace*> > lists; + std::vector<std::vector<GFace *> > lists; - std::vector<GEdge*> boundary_edges = f1->edges(); + std::vector<GEdge *> boundary_edges = f1->edges(); - for (std::vector<GEdge*>::iterator boundary_edge = boundary_edges.begin(); - boundary_edge != boundary_edges.end(); boundary_edge++) { - - // if (boundary_edge->getBeginVertex() == boundary_edge->getEndVertex() && - if (!(*boundary_edge)->isSeam(f1)) { - GEdge* ge = findMatching<GEdge*>(*coresp_e,*boundary_edge); - if (!ge) { - Msg::Error("Could not find matching edge %i in face %i during matching", - (*boundary_edge)->tag(),f1->tag()); + for(std::vector<GEdge *>::iterator boundary_edge = boundary_edges.begin(); + boundary_edge != boundary_edges.end(); boundary_edge++) { + // if (boundary_edge->getBeginVertex() == + // boundary_edge->getEndVertex() && + if(!(*boundary_edge)->isSeam(f1)) { + GEdge *ge = findMatching<GEdge *>(*coresp_e, *boundary_edge); + if(!ge) { + Msg::Error( + "Could not find matching edge %i in face %i during matching", + (*boundary_edge)->tag(), f1->tag()); } lists.push_back(ge->faces()); } } - std::vector<GFace*> common_faces; - getIntersection<GFace*>(common_faces, lists); - GFace* choice = 0; - + std::vector<GFace *> common_faces; + getIntersection<GFace *>(common_faces, lists); + GFace *choice = 0; - if (common_faces.size() == 0) { - Msg::Debug("Could not match face %i (geom).",f1->tag()); + if(common_faces.size() == 0) { + Msg::Debug("Could not match face %i (geom).", f1->tag()); continue; } - if (common_faces.size() == 1) { + if(common_faces.size() == 1) { choice = common_faces[0]; - - } else { - + } + else { // Then, compute the minimal bounding box SOrientedBoundingBox geo_obb = f1->getOBB(); double best_score = DBL_MAX; // Next, let's iterate over the mesh entities. - for (std::vector<GFace*>::iterator candidate = common_faces.begin(); - candidate != common_faces.end(); candidate++) { + for(std::vector<GFace *>::iterator candidate = common_faces.begin(); + candidate != common_faces.end(); candidate++) { SOrientedBoundingBox mesh_obb = (*candidate)->getOBB(); - Msg::Info("Comparing score : %f", SOrientedBoundingBox::compare(geo_obb,mesh_obb)); - double score = SOrientedBoundingBox::compare(geo_obb,mesh_obb); + Msg::Info("Comparing score : %f", + SOrientedBoundingBox::compare(geo_obb, mesh_obb)); + double score = SOrientedBoundingBox::compare(geo_obb, mesh_obb); - if (score < best_score) { + if(score < best_score) { best_score = score; choice = (*candidate); } } } - if (choice) { - Msg::Debug("Faces %i (geom) and %i (mesh) match.",f1->tag(),choice->tag()); - coresp_f->push_back(Pair<GFace*,GFace*>(f1,choice)); + if(choice) { + Msg::Debug("Faces %i (geom) and %i (mesh) match.", f1->tag(), + choice->tag()); + coresp_f->push_back(Pair<GFace *, GFace *>(f1, choice)); choice->setTag(f1->tag()); num_matched_faces++; } @@ -300,120 +306,119 @@ GeomMeshMatcher:: matchFaces(GModel* m1, GModel* m2, Msg::Info("Matched %i faces out of %i.", num_matched_faces, num_total_faces); return coresp_f; - } -// ------------------------------------------------------------[ Matching regions ] +// ------------------------------------------------------------[ Matching +// regions ] -std::vector<Pair<GRegion*,GRegion*> >* -GeomMeshMatcher::matchRegions(GModel* m1, GModel* m2, - std::vector<Pair<GFace*,GFace*> >* coresp_f, bool& ok) +std::vector<Pair<GRegion *, GRegion *> > * +GeomMeshMatcher::matchRegions(GModel *m1, GModel *m2, + std::vector<Pair<GFace *, GFace *> > *coresp_f, + bool &ok) { int num_matched_regions = 0; int num_total_regions = 0; - std::vector<Pair<GRegion*,GRegion*> >* coresp_r = new std::vector<Pair<GRegion*,GRegion*> >; + std::vector<Pair<GRegion *, GRegion *> > *coresp_r = + new std::vector<Pair<GRegion *, GRegion *> >; - std::vector<GEntity*> m1_entities; - m1->getEntities(m1_entities,3); - std::vector<GEntity*> m2_entities; - m2->getEntities(m2_entities,3); + std::vector<GEntity *> m1_entities; + m1->getEntities(m1_entities, 3); + std::vector<GEntity *> m2_entities; + m2->getEntities(m2_entities, 3); - if (m1_entities.empty() || m2_entities.empty()) { - Msg::Info("No regions could be matched since one of the models doesn't have any"); + if(m1_entities.empty() || m2_entities.empty()) { + Msg::Info( + "No regions could be matched since one of the models doesn't have any"); return coresp_r; } + for(std::vector<GEntity *>::iterator entity1 = m1_entities.begin(); + entity1 != m1_entities.end(); entity1++) { + // if ((*entity1)->dim() != 3) continue; + num_total_regions++; - for (std::vector<GEntity*>::iterator entity1 = m1_entities.begin(); - entity1 != m1_entities.end(); - entity1++) - { - // if ((*entity1)->dim() != 3) continue; - num_total_regions++; - - //std::vector<list<GRegion*> > lists; - std::vector<GFace*> boundary_faces = ((GFace*)(*entity1))->faces(); - std::vector<GFace*> coresp_bound_faces; - std::vector<GRegion*> common_regions; + // std::vector<list<GRegion*> > lists; + std::vector<GFace *> boundary_faces = ((GFace *)(*entity1))->faces(); + std::vector<GFace *> coresp_bound_faces; + std::vector<GRegion *> common_regions; - for (std::vector<GFace*>::iterator boundary_face = boundary_faces.begin(); - boundary_face != boundary_faces.end(); boundary_face++) { - coresp_bound_faces.push_back(findMatching<GFace*>(*coresp_f,*boundary_face)); + for(std::vector<GFace *>::iterator boundary_face = boundary_faces.begin(); + boundary_face != boundary_faces.end(); boundary_face++) { + coresp_bound_faces.push_back( + findMatching<GFace *>(*coresp_f, *boundary_face)); + } + for(std::vector<GEntity *>::iterator entity2 = m2_entities.begin(); + entity2 != m2_entities.end(); entity2++) { + if((*entity2)->dim() != 3) continue; + std::vector<std::vector<GFace *> > lists; + lists.push_back(coresp_bound_faces); + lists.push_back(((GRegion *)*entity2)->faces()); + std::vector<GFace *> common_faces; + getIntersection<GFace *>(common_faces, lists); + if(common_faces.size() == coresp_bound_faces.size()) { + common_regions.push_back((GRegion *)*entity2); } - for (std::vector<GEntity*>::iterator entity2 = m2_entities.begin(); - entity2 != m2_entities.end(); - entity2++) - { - if((*entity2)->dim() != 3) continue; - std::vector<std::vector<GFace*> > lists; - lists.push_back(coresp_bound_faces); - lists.push_back(((GRegion*)*entity2)->faces()); - std::vector<GFace*> common_faces; - getIntersection<GFace*>(common_faces, lists); - if (common_faces.size() == coresp_bound_faces.size()) { - common_regions.push_back((GRegion*)*entity2); - } + } - } + if(common_regions.size() == 1) { + coresp_r->push_back( + Pair<GRegion *, GRegion *>((GRegion *)*entity1, common_regions[0])); + common_regions[0]->setTag(((GRegion *)*entity1)->tag()); + num_matched_regions++; + } + else if(common_regions.size() > 1) { + // So, first step is to build an array of points taken on the geo entity - if (common_regions.size() == 1) { - coresp_r->push_back(Pair<GRegion*,GRegion*> ((GRegion*) *entity1, common_regions[0])); - common_regions[0]->setTag(((GRegion*) *entity1)->tag()); - num_matched_regions++; - } else if (common_regions.size() > 1) { - - // So, first step is to build an array of points taken on the geo entity - - /* - This is made in a backward fashion compared to the other entities... - */ - std::vector<GEdge*> boundaries = ((GRegion*) *entity1)->edges(); - - // Then, compute the minimal bounding box - SOrientedBoundingBox geo_obb = ((GRegion*) *entity1)->getOBB(); - - GRegion* choice = 0; - double best_score = DBL_MAX; - // Next, let's iterate over the mesh entities. - for (std::vector<GRegion*>::iterator candidate = common_regions.begin(); - candidate != common_regions.end(); candidate++) { - // Again, build an array with the vertices. - SOrientedBoundingBox mesh_obb = (*candidate)->getOBB(); - Msg::Info("Comparing score : %f", - SOrientedBoundingBox::compare(geo_obb,mesh_obb)); - double score = SOrientedBoundingBox::compare(geo_obb,mesh_obb); - - - if (score < best_score) { - best_score = score; - choice = (*candidate); - } + /* + This is made in a backward fashion compared to the other entities... + */ + std::vector<GEdge *> boundaries = ((GRegion *)*entity1)->edges(); + + // Then, compute the minimal bounding box + SOrientedBoundingBox geo_obb = ((GRegion *)*entity1)->getOBB(); + + GRegion *choice = 0; + double best_score = DBL_MAX; + // Next, let's iterate over the mesh entities. + for(std::vector<GRegion *>::iterator candidate = common_regions.begin(); + candidate != common_regions.end(); candidate++) { + // Again, build an array with the vertices. + SOrientedBoundingBox mesh_obb = (*candidate)->getOBB(); + Msg::Info("Comparing score : %f", + SOrientedBoundingBox::compare(geo_obb, mesh_obb)); + double score = SOrientedBoundingBox::compare(geo_obb, mesh_obb); + + if(score < best_score) { + best_score = score; + choice = (*candidate); } - coresp_r->push_back(Pair<GRegion*,GRegion*>((GRegion*) *entity1 , - choice)); - choice->setTag(((GRegion*) *entity1)->tag()); - - //for (unsigned int v = 0; v < ((GRegion*) choice)->getNumMeshVertices(); v++) { - // if ( ((GRegion*) choice)->getMeshVertex(v)->onWhat()->dim() > 2) - // ((GRegion*) choice)->getMeshVertex(v)->setEntity((GRegion*) *entity1); - //} - num_matched_regions++; } + coresp_r->push_back( + Pair<GRegion *, GRegion *>((GRegion *)*entity1, choice)); + choice->setTag(((GRegion *)*entity1)->tag()); + + // for (unsigned int v = 0; v < ((GRegion*) choice)->getNumMeshVertices(); + // v++) { + // if ( ((GRegion*) choice)->getMeshVertex(v)->onWhat()->dim() > 2) + // ((GRegion*) choice)->getMeshVertex(v)->setEntity((GRegion*) + // *entity1); + //} + num_matched_regions++; } + } - Msg::Info("Regions matched : %i / %i", num_matched_regions, num_total_regions); + Msg::Info("Regions matched : %i / %i", num_matched_regions, + num_total_regions); if(num_matched_regions != num_total_regions) ok = false; return coresp_r; - } - // Public -GeomMeshMatcher* GeomMeshMatcher::instance() +GeomMeshMatcher *GeomMeshMatcher::instance() { - if (!GeomMeshMatcher::_gmm_instance) { + if(!GeomMeshMatcher::_gmm_instance) { GeomMeshMatcher::_gmm_instance = new GeomMeshMatcher(); } return (GeomMeshMatcher::_gmm_instance); @@ -421,78 +426,82 @@ GeomMeshMatcher* GeomMeshMatcher::instance() void GeomMeshMatcher::destroy() { - if (GeomMeshMatcher::_gmm_instance) - delete GeomMeshMatcher::_gmm_instance; + if(GeomMeshMatcher::_gmm_instance) delete GeomMeshMatcher::_gmm_instance; } -static GVertex *getGVertex (MVertex *v1, GModel *gm, const double TOL){ +static GVertex *getGVertex(MVertex *v1, GModel *gm, const double TOL) +{ GVertex *best = 0; double bestScore = TOL; - for (GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); ++it){ + for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); ++it) { { GVertex *v2 = (*it)->getBeginVertex(); - double score = sqrt((v1->x() - v2->x())*(v1->x() - v2->x()) + - (v1->y() - v2->y())*(v1->y() - v2->y()) + - (v1->z() - v2->z())*(v1->z() - v2->z())); - if (score < bestScore){ + double score = sqrt((v1->x() - v2->x()) * (v1->x() - v2->x()) + + (v1->y() - v2->y()) * (v1->y() - v2->y()) + + (v1->z() - v2->z()) * (v1->z() - v2->z())); + if(score < bestScore) { bestScore = score; - best = v2; + best = v2; } } { GVertex *v2 = (*it)->getEndVertex(); - double score = sqrt((v1->x() - v2->x())*(v1->x() - v2->x()) + - (v1->y() - v2->y())*(v1->y() - v2->y()) + - (v1->z() - v2->z())*(v1->z() - v2->z())); - if (score < bestScore){ + double score = sqrt((v1->x() - v2->x()) * (v1->x() - v2->x()) + + (v1->y() - v2->y()) * (v1->y() - v2->y()) + + (v1->z() - v2->z()) * (v1->z() - v2->z())); + if(score < bestScore) { bestScore = score; - best = v2; + best = v2; } } } - // if (best)printf("getting point %g %g on vertices best score is %12.5E\n",v1->x(),v1->y(),bestScore); + // if (best)printf("getting point %g %g on vertices best score is + // %12.5E\n",v1->x(),v1->y(),bestScore); return best; } -static GPoint getGEdge (MVertex *v1, GModel *gm, const double TOL){ +static GPoint getGEdge(MVertex *v1, GModel *gm, const double TOL) +{ GPoint gpBest; double bestScore = TOL; - - for (GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); ++it){ + for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); ++it) { GEdge *e = *it; double pp; - GPoint gp = e->closestPoint(SPoint3(v1->x(),v1->y(),v1->z()), pp); - double score = sqrt((v1->x() - gp.x())*(v1->x() - gp.x()) + - (v1->y() - gp.y())*(v1->y() - gp.y()) + - (v1->z() - gp.z())*(v1->z() - gp.z())); - if (score < bestScore){ + GPoint gp = e->closestPoint(SPoint3(v1->x(), v1->y(), v1->z()), pp); + double score = sqrt((v1->x() - gp.x()) * (v1->x() - gp.x()) + + (v1->y() - gp.y()) * (v1->y() - gp.y()) + + (v1->z() - gp.z()) * (v1->z() - gp.z())); + if(score < bestScore) { bestScore = score; - gpBest = gp; + gpBest = gp; } } - // printf("getting point %g %g (%g %g) on edges best score is %12.5E\n",v1->x(),v1->y(),gpBest.x(),gpBest.y(),bestScore); + // printf("getting point %g %g (%g %g) on edges best score is + // %12.5E\n",v1->x(),v1->y(),gpBest.x(),gpBest.y(),bestScore); return gpBest; } -static GPoint getGFace (MVertex *v1, GModel *gm, const double TOL){ +static GPoint getGFace(MVertex *v1, GModel *gm, const double TOL) +{ GPoint gpBest; double bestScore = TOL; - for (GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it){ + for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) { GFace *gf = *it; SPoint2 pp; - double guess[2] = {0,0}; - GPoint gp = gf->closestPoint(SPoint3(v1->x(),v1->y(),v1->z()), guess); - double score = sqrt((v1->x() - gp.x())*(v1->x() - gp.x()) + - (v1->y() - gp.y())*(v1->y() - gp.y()) + - (v1->z() - gp.z())*(v1->z() - gp.z())); - if (score < bestScore){ + double guess[2] = {0, 0}; + GPoint gp = gf->closestPoint(SPoint3(v1->x(), v1->y(), v1->z()), guess); + double score = sqrt((v1->x() - gp.x()) * (v1->x() - gp.x()) + + (v1->y() - gp.y()) * (v1->y() - gp.y()) + + (v1->z() - gp.z()) * (v1->z() - gp.z())); + if(score < bestScore) { bestScore = score; - gpBest = gp; + gpBest = gp; } } - // printf("getting point %g %g (%g %g) on faces best score is %12.5E\n",v1->x(),v1->y(),gpBest.x(),gpBest.y(),bestScore); + // printf("getting point %g %g (%g %g) on faces best score is + // %12.5E\n",v1->x(),v1->y(),gpBest.x(),gpBest.y(),bestScore); return gpBest; } @@ -500,145 +509,178 @@ int GeomMeshMatcher::forceTomatch(GModel *geom, GModel *mesh, const double TOL) { // assume that the geometry is the right one - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; mesh->getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) { MVertex *v = entities[i]->mesh_vertices[j]; - GVertex *gv = getGVertex (v, geom, TOL); + GVertex *gv = getGVertex(v, geom, TOL); bool found = 0; - if (gv){ - printf("vertex %d matches GVertex %d\n",v->getNum(),gv->tag()); - found=1; - MVertex *vvv = new MVertex (v->x(),v->y(),v->z(),gv,v->getNum()); + if(gv) { + printf("vertex %d matches GVertex %d\n", v->getNum(), gv->tag()); + found = 1; + MVertex *vvv = new MVertex(v->x(), v->y(), v->z(), gv, v->getNum()); gv->mesh_vertices.push_back(vvv); - gv->points.push_back(new MPoint(vvv,v->getNum())); - + gv->points.push_back(new MPoint(vvv, v->getNum())); } - else if (v->onWhat()->dim() == 1){ - GPoint gp = getGEdge (v, geom, 1.e22); - if(gp.g()){ - GEntity *gg = (GEntity*)gp.g(); - found=1; - // printf("vertex %d matches GEdge %d on position %g\n",v->getNum(),gg->tag(),gp.u()); - gg->mesh_vertices.push_back(new MEdgeVertex (gp.x(),gp.y(),gp.z(), - gg,gp.u(),-1.,v->getNum())); + else if(v->onWhat()->dim() == 1) { + GPoint gp = getGEdge(v, geom, 1.e22); + if(gp.g()) { + GEntity *gg = (GEntity *)gp.g(); + found = 1; + // printf("vertex %d matches GEdge %d on position + //%g\n",v->getNum(),gg->tag(),gp.u()); + gg->mesh_vertices.push_back(new MEdgeVertex( + gp.x(), gp.y(), gp.z(), gg, gp.u(), -1., v->getNum())); } } - if (!found && v->onWhat()->dim() <= 2){ - GPoint gp = getGFace (v, geom, TOL); - if(gp.g()){ - GEntity *gg = (GEntity*)gp.g(); + if(!found && v->onWhat()->dim() <= 2) { + GPoint gp = getGFace(v, geom, TOL); + if(gp.g()) { + GEntity *gg = (GEntity *)gp.g(); found = 1; // printf("vertex %d matches GFace %d\n",v->getNum(),gg->tag()); - gg->mesh_vertices.push_back(new MFaceVertex (gp.x(),gp.y(),gp.z(), - gg,gp.u(),gp.v(),v->getNum())); + gg->mesh_vertices.push_back(new MFaceVertex( + gp.x(), gp.y(), gp.z(), gg, gp.u(), gp.v(), v->getNum())); } } - if (!found) Msg::Error("vertex %d classified on %d %d not matched",v->getNum(),v->onWhat()->dim(),v->onWhat()->tag()); + if(!found) + Msg::Error("vertex %d classified on %d %d not matched", v->getNum(), + v->onWhat()->dim(), v->onWhat()->tag()); } } // printf("creating edges\n"); - for (GModel::eiter it = mesh->firstEdge(); it != mesh->lastEdge(); ++it){ + for(GModel::eiter it = mesh->firstEdge(); it != mesh->lastEdge(); ++it) { // printf("edge %d\n",(*it)->tag()); - for (unsigned int i=0;i<(*it)->lines.size();i++){ - // printf("medge %d %d\n",(*it)->lines[i]->getVertex(0)->getNum(),(*it)->lines[i]->getVertex(1)->getNum()); - MVertex *v1 = geom->getMeshVertexByTag((*it)->lines[i]->getVertex(0)->getNum()); - MVertex *v2 = geom->getMeshVertexByTag((*it)->lines[i]->getVertex(1)->getNum()); - if (v1 && v2){ - GEdge *ge= 0; - if (v1->onWhat()->dim() == 1)ge = (GEdge*)v1->onWhat(); - if (v2->onWhat()->dim() == 1)ge = (GEdge*)v2->onWhat(); - if (ge){ - double u1,u2; + for(unsigned int i = 0; i < (*it)->lines.size(); i++) { + // printf("medge %d + // %d\n",(*it)->lines[i]->getVertex(0)->getNum(),(*it)->lines[i]->getVertex(1)->getNum()); + MVertex *v1 = + geom->getMeshVertexByTag((*it)->lines[i]->getVertex(0)->getNum()); + MVertex *v2 = + geom->getMeshVertexByTag((*it)->lines[i]->getVertex(1)->getNum()); + if(v1 && v2) { + GEdge *ge = 0; + if(v1->onWhat()->dim() == 1) ge = (GEdge *)v1->onWhat(); + if(v2->onWhat()->dim() == 1) ge = (GEdge *)v2->onWhat(); + if(ge) { + double u1, u2; reparamMeshVertexOnEdge(v1, ge, u1); reparamMeshVertexOnEdge(v2, ge, u2); - if (u1< u2)ge->lines.push_back(new MLine(v1,v2)); - else ge->lines.push_back(new MLine(v2,v1)); + if(u1 < u2) + ge->lines.push_back(new MLine(v1, v2)); + else + ge->lines.push_back(new MLine(v2, v1)); } - else printf("argh !\n"); + else + printf("argh !\n"); } - else{ - if (!v1)printf("Vertex %d has not been found\n", (*it)->lines[i]->getVertex(0)->getNum()); - if (!v2)printf("Vertex %d has not been found\n", (*it)->lines[i]->getVertex(1)->getNum()); + else { + if(!v1) + printf("Vertex %d has not been found\n", + (*it)->lines[i]->getVertex(0)->getNum()); + if(!v2) + printf("Vertex %d has not been found\n", + (*it)->lines[i]->getVertex(1)->getNum()); } } } // printf("creating faces\n"); - for (GModel::fiter it = mesh->firstFace(); it != mesh->lastFace(); ++it){ - for (unsigned int i=0;i<(*it)->triangles.size();i++){ - MVertex *v1 = geom->getMeshVertexByTag((*it)->triangles[i]->getVertex(0)->getNum()); - MVertex *v2 = geom->getMeshVertexByTag((*it)->triangles[i]->getVertex(1)->getNum()); - MVertex *v3 = geom->getMeshVertexByTag((*it)->triangles[i]->getVertex(2)->getNum()); - if (v1->onWhat()->dim() == 2)((GFace*)v1->onWhat())->triangles.push_back(new MTriangle(v1,v2,v3)); - else if (v2->onWhat()->dim() == 2)((GFace*)v2->onWhat())->triangles.push_back(new MTriangle(v1,v2,v3)); - else if (v3->onWhat()->dim() == 2)((GFace*)v3->onWhat())->triangles.push_back(new MTriangle(v1,v2,v3)); + for(GModel::fiter it = mesh->firstFace(); it != mesh->lastFace(); ++it) { + for(unsigned int i = 0; i < (*it)->triangles.size(); i++) { + MVertex *v1 = + geom->getMeshVertexByTag((*it)->triangles[i]->getVertex(0)->getNum()); + MVertex *v2 = + geom->getMeshVertexByTag((*it)->triangles[i]->getVertex(1)->getNum()); + MVertex *v3 = + geom->getMeshVertexByTag((*it)->triangles[i]->getVertex(2)->getNum()); + if(v1->onWhat()->dim() == 2) + ((GFace *)v1->onWhat())->triangles.push_back(new MTriangle(v1, v2, v3)); + else if(v2->onWhat()->dim() == 2) + ((GFace *)v2->onWhat())->triangles.push_back(new MTriangle(v1, v2, v3)); + else if(v3->onWhat()->dim() == 2) + ((GFace *)v3->onWhat())->triangles.push_back(new MTriangle(v1, v2, v3)); } - for (unsigned int i=0;i<(*it)->quadrangles.size();i++){ - MVertex *v1 = geom->getMeshVertexByTag((*it)->quadrangles[i]->getVertex(0)->getNum()); - MVertex *v2 = geom->getMeshVertexByTag((*it)->quadrangles[i]->getVertex(1)->getNum()); - MVertex *v3 = geom->getMeshVertexByTag((*it)->quadrangles[i]->getVertex(2)->getNum()); - MVertex *v4 = geom->getMeshVertexByTag((*it)->quadrangles[i]->getVertex(3)->getNum()); + for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++) { + MVertex *v1 = + geom->getMeshVertexByTag((*it)->quadrangles[i]->getVertex(0)->getNum()); + MVertex *v2 = + geom->getMeshVertexByTag((*it)->quadrangles[i]->getVertex(1)->getNum()); + MVertex *v3 = + geom->getMeshVertexByTag((*it)->quadrangles[i]->getVertex(2)->getNum()); + MVertex *v4 = + geom->getMeshVertexByTag((*it)->quadrangles[i]->getVertex(3)->getNum()); // printf("quad %p %p %p %p\n",v1,v2,v3,v4); - if (v1->onWhat()->dim() == 2)((GFace*)v1->onWhat())->quadrangles.push_back(new MQuadrangle(v1,v2,v3,v4)); - else if (v2->onWhat()->dim() == 2)((GFace*)v2->onWhat())->quadrangles.push_back(new MQuadrangle(v1,v2,v3,v4)); - else if (v3->onWhat()->dim() == 2)((GFace*)v3->onWhat())->quadrangles.push_back(new MQuadrangle(v1,v2,v3,v4)); - else if (v4->onWhat()->dim() == 2)((GFace*)v4->onWhat())->quadrangles.push_back(new MQuadrangle(v1,v2,v3,v4)); + if(v1->onWhat()->dim() == 2) + ((GFace *)v1->onWhat()) + ->quadrangles.push_back(new MQuadrangle(v1, v2, v3, v4)); + else if(v2->onWhat()->dim() == 2) + ((GFace *)v2->onWhat()) + ->quadrangles.push_back(new MQuadrangle(v1, v2, v3, v4)); + else if(v3->onWhat()->dim() == 2) + ((GFace *)v3->onWhat()) + ->quadrangles.push_back(new MQuadrangle(v1, v2, v3, v4)); + else if(v4->onWhat()->dim() == 2) + ((GFace *)v4->onWhat()) + ->quadrangles.push_back(new MQuadrangle(v1, v2, v3, v4)); } } - geom->writeMSH("hopla.msh",2.2,false,false,true); + geom->writeMSH("hopla.msh", 2.2, false, false, true); return 0; } template <class GEType> -static void copy_periodicity (std::vector<Pair<GEType*, GEType*> >& eCor, - std::map<MVertex*,MVertex*>& mesh_to_geom) +static void copy_periodicity(std::vector<Pair<GEType *, GEType *> > &eCor, + std::map<MVertex *, MVertex *> &mesh_to_geom) { - - typename std::multimap<GEType*,GEType*> eMap; // (eCor.begin(),eCor.end()); - typename std::vector<Pair<GEType*,GEType*> >::iterator eIter = eCor.begin(); - for (;eIter!=eCor.end();++eIter) { - eMap.insert(std::make_pair(eIter->second(),eIter->first())); + typename std::multimap<GEType *, GEType *> eMap; // (eCor.begin(),eCor.end()); + typename std::vector<Pair<GEType *, GEType *> >::iterator eIter = + eCor.begin(); + for(; eIter != eCor.end(); ++eIter) { + eMap.insert(std::make_pair(eIter->second(), eIter->first())); } - typename std::multimap<GEType*,GEType*>::iterator srcIter = eMap.begin(); + typename std::multimap<GEType *, GEType *>::iterator srcIter = eMap.begin(); - for (;srcIter!=eMap.end();++srcIter) { - GEType* oldTgt = srcIter->first; - GEType* oldSrc = dynamic_cast<GEType*> (oldTgt->meshMaster()); + for(; srcIter != eMap.end(); ++srcIter) { + GEType *oldTgt = srcIter->first; + GEType *oldSrc = dynamic_cast<GEType *>(oldTgt->meshMaster()); - if (oldSrc != NULL && oldSrc != oldTgt) { - - GEType* newTgt = srcIter->second; - typename std::map<GEType*,GEType*>::iterator tgtIter = eMap.find(oldSrc); - if (tgtIter == eMap.end()) { + if(oldSrc != NULL && oldSrc != oldTgt) { + GEType *newTgt = srcIter->second; + typename std::map<GEType *, GEType *>::iterator tgtIter = + eMap.find(oldSrc); + if(tgtIter == eMap.end()) { Msg::Error("Could not find matched entity for %d", - "which has a matched periodic counterpart %d", - oldSrc->tag(),oldTgt->tag()); + "which has a matched periodic counterpart %d", oldSrc->tag(), + oldTgt->tag()); } - GEType* newSrc = tgtIter->second; - newTgt->setMeshMaster(newSrc,oldTgt->affineTransform); - - std::map<MVertex*,MVertex*>& oldV2v = oldTgt->correspondingVertices; - std::map<MVertex*,MVertex*>& newV2v = newTgt->correspondingVertices; - - std::map<MVertex*,MVertex*>::iterator vIter = oldV2v.begin(); - for (;vIter!=oldV2v.end();++vIter) { - - MVertex* oldTgtV = vIter->first; - MVertex* oldSrcV = vIter->second; - - std::map<MVertex*,MVertex*>::iterator newTvIter = mesh_to_geom.find(oldTgtV); - std::map<MVertex*,MVertex*>::iterator newSvIter = mesh_to_geom.find(oldSrcV); - - if (newTvIter == mesh_to_geom.end()) { - Msg::Error("Could not find copy of target vertex %d in entity %d of dim", - oldTgtV->getIndex(),oldTgt->tag(),oldTgt->dim()); + GEType *newSrc = tgtIter->second; + newTgt->setMeshMaster(newSrc, oldTgt->affineTransform); + + std::map<MVertex *, MVertex *> &oldV2v = oldTgt->correspondingVertices; + std::map<MVertex *, MVertex *> &newV2v = newTgt->correspondingVertices; + + std::map<MVertex *, MVertex *>::iterator vIter = oldV2v.begin(); + for(; vIter != oldV2v.end(); ++vIter) { + MVertex *oldTgtV = vIter->first; + MVertex *oldSrcV = vIter->second; + + std::map<MVertex *, MVertex *>::iterator newTvIter = + mesh_to_geom.find(oldTgtV); + std::map<MVertex *, MVertex *>::iterator newSvIter = + mesh_to_geom.find(oldSrcV); + + if(newTvIter == mesh_to_geom.end()) { + Msg::Error( + "Could not find copy of target vertex %d in entity %d of dim", + oldTgtV->getIndex(), oldTgt->tag(), oldTgt->dim()); } - if (newSvIter == mesh_to_geom.end()) { - Msg::Error("Could not find copy of source vertex %d in entity %d of dim", - oldSrcV->getIndex(),oldSrc->tag(),oldSrc->dim()); + if(newSvIter == mesh_to_geom.end()) { + Msg::Error( + "Could not find copy of source vertex %d in entity %d of dim", + oldSrcV->getIndex(), oldSrc->tag(), oldSrc->dim()); } newV2v[newTvIter->second] = newSvIter->second; } @@ -646,31 +688,30 @@ static void copy_periodicity (std::vector<Pair<GEType*, GEType*> >& eCor, } } - template <class GEType> -static bool apply_periodicity (std::vector<Pair<GEType*, GEType*> >& eCor) +static bool apply_periodicity(std::vector<Pair<GEType *, GEType *> > &eCor) { - - typename std::multimap<GEType*,GEType*> eMap; // (eCor.begin(),eCor.end()); - typename std::vector<Pair<GEType*,GEType*> >::iterator eIter = eCor.begin(); - for (;eIter!=eCor.end();++eIter) { - eMap.insert(std::make_pair(eIter->second(),eIter->first())); + typename std::multimap<GEType *, GEType *> eMap; // (eCor.begin(),eCor.end()); + typename std::vector<Pair<GEType *, GEType *> >::iterator eIter = + eCor.begin(); + for(; eIter != eCor.end(); ++eIter) { + eMap.insert(std::make_pair(eIter->second(), eIter->first())); } - typename std::multimap<GEType*,GEType*>::iterator srcIter = eMap.begin(); + typename std::multimap<GEType *, GEType *>::iterator srcIter = eMap.begin(); int dim = -1; - for (;srcIter!=eMap.end();++srcIter) { - GEType* newTgt = srcIter->second; + for(; srcIter != eMap.end(); ++srcIter) { + GEType *newTgt = srcIter->second; newTgt->updateCorrespondingVertices(); newTgt->alignElementsWithMaster(); - if (dim == -1) dim = newTgt->dim(); + if(dim == -1) dim = newTgt->dim(); } - if (dim<2) { // required for multiple periodic directions - for (srcIter=eMap.begin();srcIter!=eMap.end();++srcIter) { - GEType* newTgt = srcIter->second; + if(dim < 2) { // required for multiple periodic directions + for(srcIter = eMap.begin(); srcIter != eMap.end(); ++srcIter) { + GEType *newTgt = srcIter->second; newTgt->copyMasterCoordinates(); newTgt->alignElementsWithMaster(); } @@ -679,159 +720,184 @@ static bool apply_periodicity (std::vector<Pair<GEType*, GEType*> >& eCor) return false; } - - -static void copy_vertices (GVertex *to, GVertex *from, std::map<MVertex*,MVertex*> &_mesh_to_geom){ +static void copy_vertices(GVertex *to, GVertex *from, + std::map<MVertex *, MVertex *> &_mesh_to_geom) +{ to->deleteMesh(); - if (from) { - //to->deleteMesh(); - for (unsigned int i=0;i<1;i++){ + if(from) { + // to->deleteMesh(); + for(unsigned int i = 0; i < 1; i++) { MVertex *v_from = from->mesh_vertices[i]; - MVertex *v_to = new MVertex (v_from->x(),v_from->y(),v_from->z(), to); + MVertex *v_to = new MVertex(v_from->x(), v_from->y(), v_from->z(), to); to->mesh_vertices.push_back(v_to); _mesh_to_geom[v_from] = v_to; } } } -static void copy_vertices (GRegion *to, GRegion *from, std::map<MVertex*,MVertex*> &_mesh_to_geom){ - +static void copy_vertices(GRegion *to, GRegion *from, + std::map<MVertex *, MVertex *> &_mesh_to_geom) +{ to->deleteMesh(); - if (from) { - for (unsigned int i=0;i<from->mesh_vertices.size();i++){ + if(from) { + for(unsigned int i = 0; i < from->mesh_vertices.size(); i++) { MVertex *v_from = from->mesh_vertices[i]; - MVertex *v_to = new MVertex (v_from->x(),v_from->y(),v_from->z(), to); + MVertex *v_to = new MVertex(v_from->x(), v_from->y(), v_from->z(), to); to->mesh_vertices.push_back(v_to); _mesh_to_geom[v_from] = v_to; } } } -static void copy_vertices (GEdge* to, GEdge* from, std::map<MVertex*,MVertex*> &_mesh_to_geom){ +static void copy_vertices(GEdge *to, GEdge *from, + std::map<MVertex *, MVertex *> &_mesh_to_geom) +{ to->deleteMesh(); - if (!from){ - Msg::Warning("Edge %d in the mesh do not match any edge of the model",to->tag()); + if(!from) { + Msg::Warning("Edge %d in the mesh do not match any edge of the model", + to->tag()); return; } - if (!to){ - Msg::Warning("Edge %d in the geometry do not match any edge of the mesh",from->tag()); + if(!to) { + Msg::Warning("Edge %d in the geometry do not match any edge of the mesh", + from->tag()); return; } - for (unsigned int i=0;i<from->mesh_vertices.size();i++){ + for(unsigned int i = 0; i < from->mesh_vertices.size(); i++) { MVertex *v_from = from->mesh_vertices[i]; double t; - GPoint gp = to->closestPoint(SPoint3(v_from->x(),v_from->y(),v_from->z()), t); - MEdgeVertex *v_to = new MEdgeVertex(gp.x(),gp.y(),gp.z(), to, gp.u()); + GPoint gp = + to->closestPoint(SPoint3(v_from->x(), v_from->y(), v_from->z()), t); + MEdgeVertex *v_to = new MEdgeVertex(gp.x(), gp.y(), gp.z(), to, gp.u()); to->mesh_vertices.push_back(v_to); _mesh_to_geom[v_from] = v_to; } - // printf("Ending Edge %d %d vertices to match\n",from->tag(),from->mesh_vertices.size()); + // printf("Ending Edge %d %d vertices to + // match\n",from->tag(),from->mesh_vertices.size()); } -static void copy_vertices (GFace *geom, GFace *mesh, std::map<MVertex*,MVertex*> &_mesh_to_geom){ - // printf("Starting Face %d, with %d vertices\n", geom->tag(), mesh->mesh_vertices.size()); - for (unsigned int i=0;i<mesh->mesh_vertices.size();i++){ +static void copy_vertices(GFace *geom, GFace *mesh, + std::map<MVertex *, MVertex *> &_mesh_to_geom) +{ + // printf("Starting Face %d, with %d vertices\n", geom->tag(), + // mesh->mesh_vertices.size()); + for(unsigned int i = 0; i < mesh->mesh_vertices.size(); i++) { MVertex *v_from = mesh->mesh_vertices[i]; double uv[2]; - GPoint gp = geom->closestPoint ( SPoint3(v_from->x(),v_from->y(),v_from->z()), uv ); - double DDD = ( v_from->x() - gp.x()) * ( v_from->x() - gp.x()) + - ( v_from->y() - gp.y()) * ( v_from->y() - gp.y()) + - ( v_from->z() - gp.z()) * ( v_from->z() - gp.z()) ; - if (sqrt(DDD) > 1.e-1)Msg::Error("Impossible to match one point Original point %f %f %f New point %f %f %f", - v_from->x(), v_from->y(), v_from->z(),gp.x(), gp.y(), gp.z()); - else if (sqrt(DDD) > 1.e-3)Msg::Warning("One mesh vertex %f %f %f of GFace %d \n is difficult to match : closest point %f %f %f", - v_from->x(), v_from->y(), v_from->z(),geom->tag(),gp.x(), gp.y(), gp.z()); - MFaceVertex *v_to = new MFaceVertex (v_from->x(),v_from->y(),v_from->z(), geom, gp.u(),gp.v() ); + GPoint gp = + geom->closestPoint(SPoint3(v_from->x(), v_from->y(), v_from->z()), uv); + double DDD = (v_from->x() - gp.x()) * (v_from->x() - gp.x()) + + (v_from->y() - gp.y()) * (v_from->y() - gp.y()) + + (v_from->z() - gp.z()) * (v_from->z() - gp.z()); + if(sqrt(DDD) > 1.e-1) + Msg::Error("Impossible to match one point Original point %f %f %f New " + "point %f %f %f", + v_from->x(), v_from->y(), v_from->z(), gp.x(), gp.y(), gp.z()); + else if(sqrt(DDD) > 1.e-3) + Msg::Warning("One mesh vertex %f %f %f of GFace %d \n is difficult to " + "match : closest point %f %f %f", + v_from->x(), v_from->y(), v_from->z(), geom->tag(), gp.x(), + gp.y(), gp.z()); + MFaceVertex *v_to = new MFaceVertex(v_from->x(), v_from->y(), v_from->z(), + geom, gp.u(), gp.v()); geom->mesh_vertices.push_back(v_to); - //SPoint2 param; - //reparamMeshVertexOnFace(v_to, to, param, true); - //printf("PARAMS : %g %g\n", param.x(), param.y()); + // SPoint2 param; + // reparamMeshVertexOnFace(v_to, to, param, true); + // printf("PARAMS : %g %g\n", param.x(), param.y()); _mesh_to_geom[v_from] = v_to; } - // printf("Ending Face %d %d vertices to match\n",geom->tag(),geom->mesh_vertices.size()); + // printf("Ending Face %d %d vertices to + // match\n",geom->tag(),geom->mesh_vertices.size()); } template <class ELEMENT> -static void copy_elements (std::vector<ELEMENT*> &to, - std::vector<ELEMENT*> &from, - std::map<MVertex*,MVertex*> &_mesh_to_geom){ +static void copy_elements(std::vector<ELEMENT *> &to, + std::vector<ELEMENT *> &from, + std::map<MVertex *, MVertex *> &_mesh_to_geom) +{ MElementFactory toto; to.clear(); - for (unsigned int i=0;i < from.size();i++){ + for(unsigned int i = 0; i < from.size(); i++) { ELEMENT *e = from[i]; - std::vector<MVertex*> nodes; - for(std::size_t j=0;j<e->getNumVertices();j++) { + std::vector<MVertex *> nodes; + for(std::size_t j = 0; j < e->getNumVertices(); j++) { nodes.push_back(_mesh_to_geom[e->getVertex(j)]); - if (_mesh_to_geom[e->getVertex(j)] == 0) { + if(_mesh_to_geom[e->getVertex(j)] == 0) { printf("Error vertex %i\n", e->getVertex(j)->getNum()); } } - to.push_back( (ELEMENT*)(toto.create(e->getTypeForMSH(), nodes) )); + to.push_back((ELEMENT *)(toto.create(e->getTypeForMSH(), nodes))); } } - -void copy_vertices (GModel *geom, GModel *mesh, - std::map<MVertex*,MVertex*> &_mesh_to_geom, - std::vector<Pair<GVertex*, GVertex*> > *coresp_v, - std::vector<Pair<GEdge* , GEdge* > > *coresp_e, - std::vector<Pair<GFace* , GFace* > > *coresp_f, - std::vector<Pair<GRegion*, GRegion*> > *coresp_r){ - +void copy_vertices(GModel *geom, GModel *mesh, + std::map<MVertex *, MVertex *> &_mesh_to_geom, + std::vector<Pair<GVertex *, GVertex *> > *coresp_v, + std::vector<Pair<GEdge *, GEdge *> > *coresp_e, + std::vector<Pair<GFace *, GFace *> > *coresp_f, + std::vector<Pair<GRegion *, GRegion *> > *coresp_r) +{ // copy all elements - for (unsigned int i=0;i<coresp_v->size();++i) - copy_vertices((*coresp_v)[i].first(),(*coresp_v)[i].second(),_mesh_to_geom); - for (unsigned int i=0;i<coresp_e->size();++i) - copy_vertices((*coresp_e)[i].first(),(*coresp_e)[i].second(),_mesh_to_geom); - for (unsigned int i=0;i<coresp_f->size();++i) - copy_vertices((*coresp_f)[i].first(),(*coresp_f)[i].second(),_mesh_to_geom); - for (unsigned int i=0;i<coresp_r->size();++i) - copy_vertices((*coresp_r)[i].first(),(*coresp_r)[i].second(),_mesh_to_geom); - - // for (GModel::riter rit = geom->firstRegion() ; rit != geom->lastRegion(); rit++) + for(unsigned int i = 0; i < coresp_v->size(); ++i) + copy_vertices((*coresp_v)[i].first(), (*coresp_v)[i].second(), + _mesh_to_geom); + for(unsigned int i = 0; i < coresp_e->size(); ++i) + copy_vertices((*coresp_e)[i].first(), (*coresp_e)[i].second(), + _mesh_to_geom); + for(unsigned int i = 0; i < coresp_f->size(); ++i) + copy_vertices((*coresp_f)[i].first(), (*coresp_f)[i].second(), + _mesh_to_geom); + for(unsigned int i = 0; i < coresp_r->size(); ++i) + copy_vertices((*coresp_r)[i].first(), (*coresp_r)[i].second(), + _mesh_to_geom); + + // for (GModel::riter rit = geom->firstRegion() ; rit != geom->lastRegion(); + // rit++) // copy_vertices(*rit,mesh->getRegionByTag((*rit)->tag()),_mesh_to_geom); } -void copy_elements (GModel *geom, GModel *mesh, std::map<MVertex*,MVertex*> &_mesh_to_geom, - std::vector<Pair<GVertex*, GVertex*> > *coresp_v, - std::vector<Pair<GEdge* , GEdge* > > *coresp_e, - std::vector<Pair<GFace* , GFace* > > *coresp_f, - std::vector<Pair<GRegion*, GRegion*> > *coresp_r){ - +void copy_elements(GModel *geom, GModel *mesh, + std::map<MVertex *, MVertex *> &_mesh_to_geom, + std::vector<Pair<GVertex *, GVertex *> > *coresp_v, + std::vector<Pair<GEdge *, GEdge *> > *coresp_e, + std::vector<Pair<GFace *, GFace *> > *coresp_f, + std::vector<Pair<GRegion *, GRegion *> > *coresp_r) +{ // copy all elements - for (unsigned int i=0;i<coresp_v->size();++i) { - GVertex* dest = (*coresp_v)[i].first(); - GVertex* orig = (*coresp_v)[i].second(); - copy_elements<MPoint>(dest->points,orig->points,_mesh_to_geom); + for(unsigned int i = 0; i < coresp_v->size(); ++i) { + GVertex *dest = (*coresp_v)[i].first(); + GVertex *orig = (*coresp_v)[i].second(); + copy_elements<MPoint>(dest->points, orig->points, _mesh_to_geom); } - for (unsigned int i=0;i<coresp_e->size();++i) { - GEdge* dest = (*coresp_e)[i].first(); - GEdge* orig = (*coresp_e)[i].second(); - copy_elements<MLine>(dest->lines,orig->lines,_mesh_to_geom); + for(unsigned int i = 0; i < coresp_e->size(); ++i) { + GEdge *dest = (*coresp_e)[i].first(); + GEdge *orig = (*coresp_e)[i].second(); + copy_elements<MLine>(dest->lines, orig->lines, _mesh_to_geom); } - for (unsigned int i=0;i<coresp_f->size();++i){ - GFace* dest = (*coresp_f)[i].first(); - GFace* orig = (*coresp_f)[i].second(); - copy_elements<MTriangle> (dest->triangles ,orig->triangles ,_mesh_to_geom); - copy_elements<MQuadrangle>(dest->quadrangles,orig->quadrangles,_mesh_to_geom); + for(unsigned int i = 0; i < coresp_f->size(); ++i) { + GFace *dest = (*coresp_f)[i].first(); + GFace *orig = (*coresp_f)[i].second(); + copy_elements<MTriangle>(dest->triangles, orig->triangles, _mesh_to_geom); + copy_elements<MQuadrangle>(dest->quadrangles, orig->quadrangles, + _mesh_to_geom); } - for (unsigned int i=0;i<coresp_r->size();++i){ - GRegion* dest = (*coresp_r)[i].first(); - GRegion* orig = (*coresp_r)[i].second(); - copy_elements<MTetrahedron>(dest->tetrahedra,orig->tetrahedra,_mesh_to_geom); - copy_elements<MHexahedron> (dest->hexahedra ,orig->hexahedra ,_mesh_to_geom); - copy_elements<MPrism> (dest->prisms ,orig->prisms ,_mesh_to_geom); - copy_elements<MPyramid> (dest->pyramids ,orig->pyramids ,_mesh_to_geom); - copy_elements<MTrihedron> (dest->trihedra ,orig->trihedra ,_mesh_to_geom); + for(unsigned int i = 0; i < coresp_r->size(); ++i) { + GRegion *dest = (*coresp_r)[i].first(); + GRegion *orig = (*coresp_r)[i].second(); + copy_elements<MTetrahedron>(dest->tetrahedra, orig->tetrahedra, + _mesh_to_geom); + copy_elements<MHexahedron>(dest->hexahedra, orig->hexahedra, _mesh_to_geom); + copy_elements<MPrism>(dest->prisms, orig->prisms, _mesh_to_geom); + copy_elements<MPyramid>(dest->pyramids, orig->pyramids, _mesh_to_geom); + copy_elements<MTrihedron>(dest->trihedra, orig->trihedra, _mesh_to_geom); } } int GeomMeshMatcher::match(GModel *geom, GModel *mesh) { - - Msg::StatusBar(true,"Matching discrete mesh to actual CAD ..."); + Msg::StatusBar(true, "Matching discrete mesh to actual CAD ..."); double t1 = Cpu(); mesh->createTopologyFromMesh(); @@ -839,55 +905,66 @@ int GeomMeshMatcher::match(GModel *geom, GModel *mesh) bool ok = true; - std::vector<Pair<GVertex*,GVertex*> > *coresp_v(NULL); - std::vector<Pair<GEdge* ,GEdge* > > *coresp_e(NULL); - std::vector<Pair<GFace* ,GFace* > > *coresp_f(NULL); - std::vector<Pair<GRegion*,GRegion*> > *coresp_r(NULL); - - coresp_v = matchVertices(geom,mesh,ok); - if (ok) { - coresp_e = matchEdges(geom,mesh,coresp_v,ok); - if (ok) { - coresp_f = matchFaces(geom,mesh,coresp_e,ok); - if (ok) { - coresp_r = matchRegions (geom, mesh,coresp_f,ok); + std::vector<Pair<GVertex *, GVertex *> > *coresp_v(NULL); + std::vector<Pair<GEdge *, GEdge *> > *coresp_e(NULL); + std::vector<Pair<GFace *, GFace *> > *coresp_f(NULL); + std::vector<Pair<GRegion *, GRegion *> > *coresp_r(NULL); + + coresp_v = matchVertices(geom, mesh, ok); + if(ok) { + coresp_e = matchEdges(geom, mesh, coresp_v, ok); + if(ok) { + coresp_f = matchFaces(geom, mesh, coresp_e, ok); + if(ok) { + coresp_r = matchRegions(geom, mesh, coresp_f, ok); } - else Msg::Error("Could only match %i faces out of %i ... stopping match", - coresp_f->size(),mesh->getNumFaces()); + else + Msg::Error("Could only match %i faces out of %i ... stopping match", + coresp_f->size(), mesh->getNumFaces()); } - else Msg::Error("Could only match %i edges out of %i ... stopping match", - coresp_e->size(),mesh->getNumEdges()); + else + Msg::Error("Could only match %i edges out of %i ... stopping match", + coresp_e->size(), mesh->getNumEdges()); } - else Msg::Error("Could only match %i nodes out of %i ... " - "check mesh/CAD or increase Geom.MatchMeshTolerance (now %g)", - coresp_v->size(),mesh->getNumVertices(), - CTX::instance()->geom.matchMeshTolerance); + else + Msg::Error("Could only match %i nodes out of %i ... " + "check mesh/CAD or increase Geom.MatchMeshTolerance (now %g)", + coresp_v->size(), mesh->getNumVertices(), + CTX::instance()->geom.matchMeshTolerance); - std::map<MVertex*,MVertex*> _mesh_to_geom; + std::map<MVertex *, MVertex *> _mesh_to_geom; - if (ok) { - - copy_vertices(geom,mesh,_mesh_to_geom,coresp_v,coresp_e,coresp_f,coresp_r); + if(ok) { + copy_vertices(geom, mesh, _mesh_to_geom, coresp_v, coresp_e, coresp_f, + coresp_r); double t00 = Cpu(); - copy_elements(geom,mesh,_mesh_to_geom,coresp_v,coresp_e,coresp_f,coresp_r); - Msg::Info("Copying mesh elements to CAD model entities took %g s",Cpu()-t00); + copy_elements(geom, mesh, _mesh_to_geom, coresp_v, coresp_e, coresp_f, + coresp_r); + Msg::Info("Copying mesh elements to CAD model entities took %g s", + Cpu() - t00); t00 = Cpu(); - if (!apply_periodicity(*coresp_v)) copy_periodicity(*coresp_v,_mesh_to_geom); - if (!apply_periodicity(*coresp_e)) copy_periodicity(*coresp_e,_mesh_to_geom); - if (!apply_periodicity(*coresp_f)) copy_periodicity(*coresp_f,_mesh_to_geom); - Msg::Info("Applying periodicity to CAD model entities took %g s",Cpu()-t00); + if(!apply_periodicity(*coresp_v)) + copy_periodicity(*coresp_v, _mesh_to_geom); + if(!apply_periodicity(*coresp_e)) + copy_periodicity(*coresp_e, _mesh_to_geom); + if(!apply_periodicity(*coresp_f)) + copy_periodicity(*coresp_f, _mesh_to_geom); + Msg::Info("Applying periodicity to CAD model entities took %g s", + Cpu() - t00); } - if (coresp_v) delete coresp_v; - if (coresp_e) delete coresp_e; - if (coresp_f) delete coresp_f; - if (coresp_r) delete coresp_r; - - if (ok) Msg::StatusBar(true,"Matched successfully mesh to CAD in %g s",Cpu()-t1); - else Msg::Error("Failed to match mesh to CAD, please check"); + if(coresp_v) delete coresp_v; + if(coresp_e) delete coresp_e; + if(coresp_f) delete coresp_f; + if(coresp_r) delete coresp_r; + if(ok) + Msg::StatusBar(true, "Matched successfully mesh to CAD in %g s", + Cpu() - t1); + else + Msg::Error("Failed to match mesh to CAD, please check"); - return ok ? 1:0; + return ok ? 1 : 0; } diff --git a/Geo/GeomMeshMatcher.h b/Geo/GeomMeshMatcher.h index 6d6caf9eea8e910de88eb6b27af97668b1a27f12..09a7b70d921ec5830a1e73bb0939ed3f6d8fd31c 100644 --- a/Geo/GeomMeshMatcher.h +++ b/Geo/GeomMeshMatcher.h @@ -19,24 +19,27 @@ #include "Pair.h" class GeomMeshMatcher { - private: - std::vector<Pair<GVertex*, GVertex*> > *matchVertices(GModel *m1, GModel *m2, bool& ok); - std::vector<Pair<GEdge*, GEdge*> > *matchEdges - (GModel* m1, GModel* m2, std::vector<Pair<GVertex*, GVertex*> > *coresp_v, bool& ok); - std::vector<Pair<GFace*, GFace*> > *matchFaces - (GModel* m1, GModel* m2, std::vector<Pair<GEdge*,GEdge*> > *coresp_e, bool& ok); - std::vector<Pair<GRegion*, GRegion*> > *matchRegions - (GModel *m1, GModel *m2, std::vector<Pair<GFace*,GFace*> > *coresp_f, bool& ok); +private: + std::vector<Pair<GVertex *, GVertex *> > *matchVertices(GModel *m1, + GModel *m2, bool &ok); + std::vector<Pair<GEdge *, GEdge *> > * + matchEdges(GModel *m1, GModel *m2, + std::vector<Pair<GVertex *, GVertex *> > *coresp_v, bool &ok); + std::vector<Pair<GFace *, GFace *> > * + matchFaces(GModel *m1, GModel *m2, + std::vector<Pair<GEdge *, GEdge *> > *coresp_e, bool &ok); + std::vector<Pair<GRegion *, GRegion *> > * + matchRegions(GModel *m1, GModel *m2, + std::vector<Pair<GFace *, GFace *> > *coresp_f, bool &ok); static GeomMeshMatcher *_gmm_instance; GeomMeshMatcher() {} ~GeomMeshMatcher() {} - public: +public: static GeomMeshMatcher *instance(); static void destroy(); - int match(GModel* geom, GModel* mesh); + int match(GModel *geom, GModel *mesh); int forceTomatch(GModel *geom, GModel *mesh, const double TOL); - }; #endif diff --git a/Geo/Homology.cpp b/Geo/Homology.cpp index 227e6028b0ec7003317493e53a80fcf24d0633dd..93f24fd7e55a5a753f9e22568308385de1f94c3f 100644 --- a/Geo/Homology.cpp +++ b/Geo/Homology.cpp @@ -18,26 +18,19 @@ Homology::Homology(GModel *model, const std::vector<int> &physicalDomain, const std::vector<int> &physicalSubdomain, const std::vector<int> &physicalImdomain, bool saveOrig, int combine, bool omit, bool smoothen, int heuristic) - : _model(model) - , _domain(physicalDomain) - , _subdomain(physicalSubdomain) - , _imdomain(physicalImdomain) - , _saveOrig(saveOrig) - , _combine(combine) - , _omit(omit) - , _smoothen(smoothen) - , _heuristic(heuristic) - , _cellComplex(NULL) + : _model(model), _domain(physicalDomain), _subdomain(physicalSubdomain), + _imdomain(physicalImdomain), _saveOrig(saveOrig), _combine(combine), + _omit(omit), _smoothen(smoothen), _heuristic(heuristic), _cellComplex(NULL) { _fileName = ""; // default to the whole model - if(_domain.empty()){ + if(_domain.empty()) { int dim = _model->getDim(); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; _model->getEntities(entities); - for(std::vector<GEntity*>::iterator it = entities.begin(); - it != entities.end(); it++){ + for(std::vector<GEntity *>::iterator it = entities.begin(); + it != entities.end(); it++) { if((*it)->dim() == dim) _domainEntities.push_back(*it); } } @@ -56,7 +49,6 @@ Homology::Homology(GModel *model, const std::vector<int> &physicalDomain, } if(abs(_heuristic) > 1) _heuristic = 0; - } std::vector<int> vecN0(int n) @@ -67,34 +59,34 @@ std::vector<int> vecN0(int n) return v; } -void Homology::_getEntities(const std::vector<int>& physicalGroups, - std::vector<GEntity*>& entities) +void Homology::_getEntities(const std::vector<int> &physicalGroups, + std::vector<GEntity *> &entities) { entities.clear(); - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; _model->getPhysicalGroups(groups); - std::map<int, std::vector<GEntity*> >::iterator it; + std::map<int, std::vector<GEntity *> >::iterator it; - for(unsigned int i = 0; i < physicalGroups.size(); i++){ - for(int j = 0; j < 4; j++){ + for(unsigned int i = 0; i < physicalGroups.size(); i++) { + for(int j = 0; j < 4; j++) { it = groups[j].find(physicalGroups.at(i)); - if(it != groups[j].end()){ - std::vector<GEntity*> physicalGroup = (*it).second; - for(unsigned int k = 0; k < physicalGroup.size(); k++){ - entities.push_back(physicalGroup.at(k)); - } + if(it != groups[j].end()) { + std::vector<GEntity *> physicalGroup = (*it).second; + for(unsigned int k = 0; k < physicalGroup.size(); k++) { + entities.push_back(physicalGroup.at(k)); + } } } } } -void Homology::_getElements(const std::vector<GEntity*>& entities, - std::vector<MElement*>& elements) +void Homology::_getElements(const std::vector<GEntity *> &entities, + std::vector<MElement *> &elements) { elements.clear(); - for(unsigned int j=0; j < entities.size(); j++) { - for(unsigned int i=0; i < entities.at(j)->getNumMeshElements(); i++){ - MElement* element = entities.at(j)->getMeshElement(i); + for(unsigned int j = 0; j < entities.size(); j++) { + for(unsigned int i = 0; i < entities.at(j)->getNumMeshElements(); i++) { + MElement *element = entities.at(j)->getMeshElement(i); elements.push_back(element); } } @@ -108,11 +100,11 @@ void Homology::_createCellComplex() if(_domainEntities.empty()) Msg::Error("Domain is empty"); if(_subdomainEntities.empty()) Msg::Info("Subdomain is empty"); - std::vector<MElement*> domainElements; - std::vector<MElement*> subdomainElements; - std::vector<MElement*> nondomainElements; - std::vector<MElement*> nonsubdomainElements; - std::vector<MElement*> immuneElements; + std::vector<MElement *> domainElements; + std::vector<MElement *> subdomainElements; + std::vector<MElement *> nondomainElements; + std::vector<MElement *> nonsubdomainElements; + std::vector<MElement *> immuneElements; _getElements(_domainEntities, domainElements); _getElements(_subdomainEntities, subdomainElements); @@ -121,13 +113,9 @@ void Homology::_createCellComplex() _getElements(_immuneEntities, immuneElements); if(_cellComplex != NULL) delete _cellComplex; - _cellComplex = new CellComplex(_model, - domainElements, - subdomainElements, - nondomainElements, - nonsubdomainElements, - immuneElements, - _saveOrig); + _cellComplex = new CellComplex(_model, domainElements, subdomainElements, + nondomainElements, nonsubdomainElements, + immuneElements, _saveOrig); if(_cellComplex->getSize(0) == 0) { Msg::Error("Cell Complex is empty: check the domain and the mesh"); @@ -136,12 +124,12 @@ void Homology::_createCellComplex() Msg::StatusBar(true, "Done creating cell complex (%g s)", t2 - t1); Msg::Info("%d volumes, %d faces, %d edges, and %d vertices", _cellComplex->getSize(3), _cellComplex->getSize(2), - _cellComplex->getSize(1), _cellComplex->getSize(0)); + _cellComplex->getSize(1), _cellComplex->getSize(0)); } void Homology::_deleteChains(std::vector<int> dim) { - for(unsigned int j = 0; j < dim.size(); j ++) { + for(unsigned int j = 0; j < dim.size(); j++) { int d = dim.at(j); if(d < 0 || d > 3) continue; for(unsigned int i = 0; i < _chains[d].size(); i++) { @@ -154,7 +142,7 @@ void Homology::_deleteChains(std::vector<int> dim) void Homology::_deleteCochains(std::vector<int> dim) { - for(unsigned int j = 0; j < dim.size(); j ++) { + for(unsigned int j = 0; j < dim.size(); j++) { int d = dim.at(j); if(d < 0 || d > 3) continue; for(unsigned int i = 0; i < _cochains[d].size(); i++) { @@ -194,20 +182,20 @@ void Homology::findHomologyBasis(std::vector<int> dim) _cellComplex->reduceComplex(_combine, _omit); if(_combine > 1 && !_smoothen) { - for(int i = 1; i <= 3; i++) { + for(int i = 1; i <= 3; i++) { if(!std::binary_search(dim.begin(), dim.end(), i)) { - _cellComplex->cocombine(i-1); + _cellComplex->cocombine(i - 1); } } } double t2 = Cpu(); double size2 = _cellComplex->getSize(-1); - Msg::StatusBar(true, "Done reducing cell complex (%g s, %g %%)", - t2 - t1, (1.-size2/size1)*100.); + Msg::StatusBar(true, "Done reducing cell complex (%g s, %g %%)", t2 - t1, + (1. - size2 / size1) * 100.); Msg::Info("%d volumes, %d faces, %d edges, and %d vertices", _cellComplex->getSize(3), _cellComplex->getSize(2), - _cellComplex->getSize(1), _cellComplex->getSize(0)); + _cellComplex->getSize(1), _cellComplex->getSize(0)); Msg::StatusBar(true, "Computing homology space bases ..."); t1 = Cpu(); @@ -217,23 +205,21 @@ void Homology::findHomologyBasis(std::vector<int> dim) Msg::StatusBar(true, "Done computing homology space bases (%g s)", t2 - t1); _deleteChains(dim); - for(int j = 0; j < 4; j++){ + for(int j = 0; j < 4; j++) { _betti[j] = 0; std::string dimension = convertInt(j); - for(int i = 1; i <= chainComplex.getBasisSize(j, 3); i++){ - + for(int i = 1; i <= chainComplex.getBasisSize(j, 3); i++) { std::string generator = convertInt(i); std::string name = "H_" + dimension + domain + generator; - std::map<Cell*, int, Less_Cell> chain; + std::map<Cell *, int, Less_Cell> chain; chainComplex.getBasisChain(chain, i, j, 3, _smoothen); - int torsion = chainComplex.getTorsion(j,i); + int torsion = chainComplex.getTorsion(j, i); if(!chain.empty()) { _createChain(chain, name, false); _betti[j] = _betti[j] + 1; - if(torsion != 1){ - Msg::Warning("H_%d %d has torsion coefficient %d!", - j, i, torsion); + if(torsion != 1) { + Msg::Warning("H_%d %d has torsion coefficient %d!", j, i, torsion); } } } @@ -248,10 +234,10 @@ void Homology::findHomologyBasis(std::vector<int> dim) Msg::Info("H_3 = %d", _betti[3]); double t3 = Cpu(); - Msg::Info("Done computing (%s) homology spaces (%g s)", - domain.c_str(), t3 - t0); - Msg::StatusBar(false, "H_0: %d, H_1: %d, H_2: %d, H_3: %d", - _betti[0], _betti[1], _betti[2], _betti[3]); + Msg::Info("Done computing (%s) homology spaces (%g s)", domain.c_str(), + t3 - t0); + Msg::StatusBar(false, "H_0: %d, H_1: %d, H_2: %d, H_3: %d", _betti[0], + _betti[1], _betti[2], _betti[3]); for(unsigned int i = 0; i < dim.size(); i++) { int d = dim.at(i); @@ -274,7 +260,7 @@ void Homology::findCohomologyBasis(std::vector<int> dim) if(_cellComplex == NULL) _createCellComplex(); if(_cellComplex->isReduced()) _cellComplex->restoreComplex(); - Msg::StatusBar(true, "Reducing cell complex..."); + Msg::StatusBar(true, "Reducing cell complex..."); double t1 = Cpu(); double size1 = _cellComplex->getSize(-1); @@ -283,9 +269,9 @@ void Homology::findCohomologyBasis(std::vector<int> dim) std::sort(dim.begin(), dim.end()); if(_combine > 1) { - for(int i = 2; i >= 0; i--) { + for(int i = 2; i >= 0; i--) { if(!std::binary_search(dim.begin(), dim.end(), i)) { - _cellComplex->combine(i+1); + _cellComplex->combine(i + 1); } } } @@ -293,36 +279,35 @@ void Homology::findCohomologyBasis(std::vector<int> dim) double t2 = Cpu(); double size2 = _cellComplex->getSize(-1); - Msg::StatusBar(true, "Done reducing cell complex (%g s, %g %%)", - t2 - t1, (1.-size2/size1)*100.); + Msg::StatusBar(true, "Done reducing cell complex (%g s, %g %%)", t2 - t1, + (1. - size2 / size1) * 100.); Msg::Info("%d volumes, %d faces, %d edges, and %d vertices", _cellComplex->getSize(3), _cellComplex->getSize(2), - _cellComplex->getSize(1), _cellComplex->getSize(0)); + _cellComplex->getSize(1), _cellComplex->getSize(0)); Msg::StatusBar(true, "Computing cohomology space bases ..."); t1 = Cpu(); ChainComplex chainComplex = ChainComplex(_cellComplex); chainComplex.computeHomology(true); t2 = Cpu(); - Msg::StatusBar(true, "Done computing cohomology space bases (%g s)", t2- t1); + Msg::StatusBar(true, "Done computing cohomology space bases (%g s)", t2 - t1); _deleteCochains(dim); for(int i = 0; i < 4; i++) _betti[i] = 0; - for(int j = 3; j > -1; j--){ + for(int j = 3; j > -1; j--) { std::string dimension = convertInt(j); - for(int i = 1; i <= chainComplex.getBasisSize(j, 3); i++){ - + for(int i = 1; i <= chainComplex.getBasisSize(j, 3); i++) { std::string generator = convertInt(i); std::string name = "H^" + dimension + domain + generator; - std::map<Cell*, int, Less_Cell> chain; + std::map<Cell *, int, Less_Cell> chain; chainComplex.getBasisChain(chain, i, j, 3, false); - int torsion = chainComplex.getTorsion(j,i); + int torsion = chainComplex.getTorsion(j, i); if(!chain.empty()) { _createChain(chain, name, true); _betti[j] = _betti[j] + 1; - if(torsion != 1){ + if(torsion != 1) { Msg::Warning("H^%d %d has torsion coefficient %d!", j, i, torsion); } } @@ -338,10 +323,10 @@ void Homology::findCohomologyBasis(std::vector<int> dim) Msg::Info("H^3 = %d", _betti[3]); double t3 = Cpu(); - Msg::Info("Done computing (%s) cohomology spaces (%g s)", - domain.c_str(), t3 - t0); - Msg::StatusBar(false, "H^0: %d, H^1: %d, H^2: %d, H^3: %d", - _betti[0], _betti[1], _betti[2], _betti[3]); + Msg::Info("Done computing (%s) cohomology spaces (%g s)", domain.c_str(), + t3 - t0); + Msg::StatusBar(false, "H^0: %d, H^1: %d, H^2: %d, H^3: %d", _betti[0], + _betti[1], _betti[2], _betti[3]); for(unsigned int i = 0; i < dim.size(); i++) { int d = dim.at(i); @@ -384,7 +369,7 @@ void Homology::findCompatibleBasisPair(int master, std::vector<int> dim) { if(!this->isHomologyComputed(dim)) this->findHomologyBasis(dim); if(!this->isCohomologyComputed(dim)) this->findCohomologyBasis(dim); - for(unsigned int idim = 0 ; idim < dim.size(); idim++) { + for(unsigned int idim = 0; idim < dim.size(); idim++) { int d = dim.at(idim); if(d < 1 || d > 2) continue; int n = this->betti(d); @@ -395,11 +380,13 @@ void Homology::findCompatibleBasisPair(int master, std::vector<int> dim) (int)_chains[d].size(), d, (int)_cochains[d].size(), d); continue; } - fullMatrix<double> m(n,n); + fullMatrix<double> m(n, n); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { - if(master==0) m(i,j) = incidence(*_cochains[d].at(i), *_chains[d].at(j)); - else m(i,j) = incidence(*_chains[d].at(i), *_cochains[d].at(j)); + if(master == 0) + m(i, j) = incidence(*_cochains[d].at(i), *_chains[d].at(j)); + else + m(i, j) = incidence(*_chains[d].at(i), *_cochains[d].at(j)); } } @@ -408,18 +395,17 @@ void Homology::findCompatibleBasisPair(int master, std::vector<int> dim) Msg::Warning("Cannot produce compatible %d-(co)homology bases.", d); Msg::Debug("Incidence matrix: "); for(int i = 0; i < n; i++) - for(int j = 0; j < n; j++) - Msg::Debug("(%d, %d) = %d", i, j, m(i,j)); + for(int j = 0; j < n; j++) Msg::Debug("(%d, %d) = %d", i, j, m(i, j)); continue; } - std::vector<Chain<int>*> newBasis(n); + std::vector<Chain<int> *> newBasis(n); - if(master==0) { + if(master == 0) { for(int i = 0; i < n; i++) { newBasis.at(i) = new Chain<int>(); for(int j = 0; j < n; j++) { - *newBasis.at(i) += (int)m(i,j)*(*_cochains[d].at(j)); + *newBasis.at(i) += (int)m(i, j) * (*_cochains[d].at(j)); } } for(int i = 0; i < n; i++) { @@ -432,7 +418,7 @@ void Homology::findCompatibleBasisPair(int master, std::vector<int> dim) for(int i = 0; i < n; i++) { newBasis.at(i) = new Chain<int>(); for(int j = 0; j < n; j++) { - *newBasis.at(i) += (int)m(i,j)*(*_chains[d].at(j)); + *newBasis.at(i) += (int)m(i, j) * (*_chains[d].at(j)); } } for(int i = 0; i < n; i++) { @@ -444,38 +430,46 @@ void Homology::findCompatibleBasisPair(int master, std::vector<int> dim) } } -std::vector<int> Homology::_addToModel(int dim, bool co, bool post, int physicalNumRequest) const +std::vector<int> Homology::_addToModel(int dim, bool co, bool post, + int physicalNumRequest) const { std::vector<int> physicals; if(dim < 0 || dim > 3) return physicals; int pgnum = -1; if(!co) { for(unsigned int i = 0; i < _chains[dim].size(); i++) { - if(physicalNumRequest != -1) pgnum = physicalNumRequest + i; - else pgnum = -1; - physicals.push_back(_chains[dim].at(i)->addToModel(this->getModel(), post, pgnum)); + if(physicalNumRequest != -1) + pgnum = physicalNumRequest + i; + else + pgnum = -1; + physicals.push_back( + _chains[dim].at(i)->addToModel(this->getModel(), post, pgnum)); } } else { for(unsigned int i = 0; i < _cochains[dim].size(); i++) { - if(physicalNumRequest != -1) pgnum = physicalNumRequest + i; - else pgnum = -1; - physicals.push_back(_cochains[dim].at(i)->addToModel(this->getModel(), post, pgnum)); + if(physicalNumRequest != -1) + pgnum = physicalNumRequest + i; + else + pgnum = -1; + physicals.push_back( + _cochains[dim].at(i)->addToModel(this->getModel(), post, pgnum)); } } if(!physicals.empty()) { std::vector<int> empty; std::string span = _getDomainString(physicals, empty); std::string domain = _getDomainString(_domain, _subdomain); - if(!co) Msg::Info("Span H_%d(%s) = %s", - dim, domain.c_str(), span.c_str()); - else Msg::Info("Span H^%d(%s) = %s", - dim, domain.c_str(), span.c_str()); + if(!co) + Msg::Info("Span H_%d(%s) = %s", dim, domain.c_str(), span.c_str()); + else + Msg::Info("Span H^%d(%s) = %s", dim, domain.c_str(), span.c_str()); } return physicals; } -std::vector<int> Homology::addChainsToModel(int dim, bool post, int physicalNumRequest) const +std::vector<int> Homology::addChainsToModel(int dim, bool post, + int physicalNumRequest) const { std::vector<int> physicals; if(dim > -1 && !_homologyComputed[dim]) @@ -486,13 +480,14 @@ std::vector<int> Homology::addChainsToModel(int dim, bool post, int physicalNumR physicals.insert(physicals.end(), p.begin(), p.end()); } } - else if (dim > -1 && dim < 4) { + else if(dim > -1 && dim < 4) { physicals = _addToModel(dim, false, post, physicalNumRequest); } return physicals; } -std::vector<int> Homology::addCochainsToModel(int dim, bool post, int physicalNumRequest) const +std::vector<int> Homology::addCochainsToModel(int dim, bool post, + int physicalNumRequest) const { std::vector<int> physicals; if(dim > -1 && !_cohomologyComputed[dim]) @@ -503,13 +498,13 @@ std::vector<int> Homology::addCochainsToModel(int dim, bool post, int physicalNu physicals.insert(physicals.end(), p.begin(), p.end()); } } - else if (dim > -1 && dim < 4) { + else if(dim > -1 && dim < 4) { physicals = _addToModel(dim, true, post, physicalNumRequest); } return physicals; } -void Homology::getHomologyBasis(int dim, std::vector<Chain<int> >& hom) +void Homology::getHomologyBasis(int dim, std::vector<Chain<int> > &hom) { if(dim < 0 || dim > 3) return; if(!_homologyComputed[dim]) findHomologyBasis(); @@ -519,7 +514,7 @@ void Homology::getHomologyBasis(int dim, std::vector<Chain<int> >& hom) hom[i] = *_chains[dim].at(i); } -void Homology::getCohomologyBasis(int dim, std::vector<Chain<int> >& coh) +void Homology::getCohomologyBasis(int dim, std::vector<Chain<int> > &coh) { if(dim < 0 || dim > 3) return; if(!_cohomologyComputed[dim]) findCohomologyBasis(); @@ -532,7 +527,6 @@ void Homology::getCohomologyBasis(int dim, std::vector<Chain<int> >& coh) void Homology::findBettiNumbers() { if(!isBettiComputed()) { - if(_cellComplex == NULL) _createCellComplex(); if(_cellComplex->isReduced()) _cellComplex->restoreComplex(); @@ -545,13 +539,12 @@ void Homology::findBettiNumbers() double t2 = Cpu(); double size2 = _cellComplex->getSize(-1); - Msg::StatusBar(true, "Done reducing cell complex (%g s, %g %%)", - t2 - t1, (1.-size2/size1)*100.); + Msg::StatusBar(true, "Done reducing cell complex (%g s, %g %%)", t2 - t1, + (1. - size2 / size1) * 100.); Msg::Info("%d volumes, %d faces, %d edges, and %d vertices", _cellComplex->getSize(3), _cellComplex->getSize(2), _cellComplex->getSize(1), _cellComplex->getSize(0)); - Msg::StatusBar(true, "Computing betti numbers..."); t1 = Cpu(); ChainComplex chainComplex = ChainComplex(_cellComplex); @@ -570,8 +563,8 @@ void Homology::findBettiNumbers() Msg::Info("b2 = %d", _betti[2]); Msg::Info("b3 = %d", _betti[3]); - Msg::StatusBar(false, "b0: %d, b1: %d, b2: %d, b3: %d", - _betti[0], _betti[1], _betti[2], _betti[3]); + Msg::StatusBar(false, "b0: %d, b1: %d, b2: %d, b3: %d", _betti[0], _betti[1], + _betti[2], _betti[3]); } int Homology::betti(int dim) @@ -592,44 +585,47 @@ int Homology::eulerCharacteristic() void Homology::_createChain(std::map<Cell *, int, Less_Cell> &preChain, const std::string &name, bool co) { - Chain<int>* chain = new Chain<int>(); + Chain<int> *chain = new Chain<int>(); chain->setName(name); - for(citer cit = preChain.begin(); cit != preChain.end(); cit++){ - Cell* cell = cit->first; + for(citer cit = preChain.begin(); cit != preChain.end(); cit++) { + Cell *cell = cit->first; int coeff = cit->second; if(coeff == 0) continue; - std::vector<MVertex*> v; + std::vector<MVertex *> v; cell->getMeshVertices(v); chain->addElemChain(ElemChain(cell->getDim(), v), coeff); } - if(co) _cochains[chain->getDim()].push_back(chain); - else _chains[chain->getDim()].push_back(chain); + if(co) + _cochains[chain->getDim()].push_back(chain); + else + _chains[chain->getDim()].push_back(chain); } -std::string Homology::_getDomainString(const std::vector<int>& domain, - const std::vector<int>& subdomain) const +std::string Homology::_getDomainString(const std::vector<int> &domain, + const std::vector<int> &subdomain) const { std::string domainString = "{"; - if(domain.empty()) domainString += "0"; - else{ - for(unsigned int i = 0; i < domain.size(); i++){ + if(domain.empty()) + domainString += "0"; + else { + for(unsigned int i = 0; i < domain.size(); i++) { std::string temp = convertInt(domain.at(i)); domainString += temp; - if (domain.size()-1 > i){ - domainString += ","; + if(domain.size() - 1 > i) { + domainString += ","; } } } domainString += "}"; - if(!subdomain.empty()){ + if(!subdomain.empty()) { domainString += ",{"; - for(unsigned int i = 0; i < subdomain.size(); i++){ + for(unsigned int i = 0; i < subdomain.size(); i++) { std::string temp = convertInt(subdomain.at(i)); domainString += temp; - if (subdomain.size()-1 > i){ + if(subdomain.size() - 1 > i) { domainString += ","; } } @@ -647,37 +643,37 @@ bool Homology::writeBasisMSH(bool binary) return true; } -void Homology::storeCells(CellComplex* cellComplex, int dim) +void Homology::storeCells(CellComplex *cellComplex, int dim) { - std::vector<MElement*> elements; + std::vector<MElement *> elements; MElementFactory factory; for(CellComplex::citer cit = cellComplex->firstCell(dim); - cit != cellComplex->lastCell(dim); cit++){ - Cell* cell = *cit; - std::map<Cell*, int, Less_Cell > cells; + cit != cellComplex->lastCell(dim); cit++) { + Cell *cell = *cit; + std::map<Cell *, int, Less_Cell> cells; cell->getCells(cells); - for(Cell::citer it = cells.begin(); it != cells.end(); it++){ - Cell* subCell = it->first; - std::vector<MVertex*> v; + for(Cell::citer it = cells.begin(); it != cells.end(); it++) { + Cell *subCell = it->first; + std::vector<MVertex *> v; subCell->getMeshVertices(v); - MElement* e = factory.create(subCell->getTypeMSH(), v); + MElement *e = factory.create(subCell->getTypeMSH(), v); elements.push_back(e); } } int max[4]; for(int i = 0; i < 4; i++) max[i] = _model->getMaxElementaryNumber(i); - int entityNum = *std::max_element(max,max+4) + 1; + int entityNum = *std::max_element(max, max + 4) + 1; for(int i = 0; i < 4; i++) max[i] = _model->getMaxPhysicalNumber(i); - int physicalNum = *std::max_element(max,max+4) + 1; + int physicalNum = *std::max_element(max, max + 4) + 1; - std::map<int, std::vector<MElement*> > entityMap; + std::map<int, std::vector<MElement *> > entityMap; entityMap[entityNum] = elements; std::map<int, std::map<int, std::string> > physicalMap; std::map<int, std::string> physicalInfo; - physicalInfo[physicalNum]="Cell Complex"; + physicalInfo[physicalNum] = "Cell Complex"; physicalMap[entityNum] = physicalInfo; _model->storeChain(dim, entityMap, physicalMap); diff --git a/Geo/Homology.h b/Geo/Homology.h index d18a610dc42bffa1a5c877c6f7408d816232dfb6..839eee7ce128987f197f76f41c2ab0941592bb64 100644 --- a/Geo/Homology.h +++ b/Geo/Homology.h @@ -21,12 +21,10 @@ std::vector<int> vecN0(int n); // Interface class for homology computation in Gmsh -class Homology -{ - private: - +class Homology { +private: // the Gmsh model for homology computation - GModel* _model; + GModel *_model; // domain and the relative subdomain of the homology computation // physical group IDs @@ -36,11 +34,11 @@ class Homology std::vector<int> _nonsubdomain; std::vector<int> _imdomain; // corresponding geometrical entities - std::vector<GEntity*> _domainEntities; - std::vector<GEntity*> _subdomainEntities; - std::vector<GEntity*> _nondomainEntities; - std::vector<GEntity*> _nonsubdomainEntities; - std::vector<GEntity*> _immuneEntities; + std::vector<GEntity *> _domainEntities; + std::vector<GEntity *> _subdomainEntities; + std::vector<GEntity *> _nondomainEntities; + std::vector<GEntity *> _nonsubdomainEntities; + std::vector<GEntity *> _immuneEntities; // save original cell complex bool _saveOrig; @@ -58,7 +56,7 @@ class Homology std::string _fileName; // cell complex of the domain - CellComplex* _cellComplex; + CellComplex *_cellComplex; // whether representatives of (co)homology bases are available bool _homologyComputed[4]; @@ -66,19 +64,19 @@ class Homology // resulting betti numbers and chains int _betti[4]; - std::vector<Chain<int>*> _chains[4]; - std::vector<Chain<int>*> _cochains[4]; + std::vector<Chain<int> *> _chains[4]; + std::vector<Chain<int> *> _cochains[4]; - typedef std::map<Cell*, int, Less_Cell>::iterator citer; + typedef std::map<Cell *, int, Less_Cell>::iterator citer; - void _getEntities(const std::vector<int>& physicalGroups, - std::vector<GEntity*>& entities); - void _getElements(const std::vector<GEntity*>& entities, - std::vector<MElement*>& elements); + void _getEntities(const std::vector<int> &physicalGroups, + std::vector<GEntity *> &entities); + void _getElements(const std::vector<GEntity *> &entities, + std::vector<MElement *> &elements); // create a string describing the generator - std::string _getDomainString(const std::vector<int>& domain, - const std::vector<int>& subdomain) const; + std::string _getDomainString(const std::vector<int> &domain, + const std::vector<int> &subdomain) const; // construct the cell complex void _createCellComplex(); @@ -87,59 +85,61 @@ class Homology void _createChain(std::map<Cell *, int, Less_Cell> &preChain, const std::string &name, bool co); - void _deleteChains(std::vector<int> dim=vecN0(4)); - void _deleteCochains(std::vector<int> dim=vecN0(4)); - - std::vector<int> _addToModel(int dim, bool co, bool post, int physicalNumRequest) const; + void _deleteChains(std::vector<int> dim = vecN0(4)); + void _deleteCochains(std::vector<int> dim = vecN0(4)); - public: + std::vector<int> _addToModel(int dim, bool co, bool post, + int physicalNumRequest) const; +public: // Determine domain and relative subdomain of (co)homology computation - Homology(GModel *model, const std::vector<int> &physicalDomain, - const std::vector<int> &physicalSubdomain, - const std::vector<int> &physicalIm, bool saveOrig = true, - int combine = 3, bool omit = true, bool smoothen = true, - int heuristic = 1); - ~Homology(); - - GModel *getModel() const { return _model; } - void setFileName(const std::string &fileName) { _fileName = fileName; } - - void getDomain(std::vector<int> &domain) const { domain = _domain; } - void getSubdomain(std::vector<int> &subdomain) const - { - subdomain = _subdomain; } + Homology(GModel *model, const std::vector<int> &physicalDomain, + const std::vector<int> &physicalSubdomain, + const std::vector<int> &physicalIm, bool saveOrig = true, + int combine = 3, bool omit = true, bool smoothen = true, + int heuristic = 1); + ~Homology(); + + GModel *getModel() const { return _model; } + void setFileName(const std::string &fileName) { _fileName = fileName; } + + void getDomain(std::vector<int> &domain) const { domain = _domain; } + void getSubdomain(std::vector<int> &subdomain) const + { + subdomain = _subdomain; + } // find the bases of (co)homology spaces // if dim is not provided,, find 0-,1-,2-,3-(co)homology spaces bases // otherwise only find those indicated in dim - void findHomologyBasis(std::vector<int> dim=vecN0(4)); - void findCohomologyBasis(std::vector<int> dim=vecN0(4)); + void findHomologyBasis(std::vector<int> dim = vecN0(4)); + void findCohomologyBasis(std::vector<int> dim = vecN0(4)); // find a homology and cohomology basis pair such that // the incidence matrix of the bases is an identity matrix // if master==0, homology basis determines the cohomology basis // if dim is not provided, find 0-,1-,2-,3-(co)homology spaces bases // otherwise only find those indicated in dim - void findCompatibleBasisPair(int master=0, std::vector<int> dim=vecN0(4)); + void findCompatibleBasisPair(int master = 0, std::vector<int> dim = vecN0(4)); // is the (co)homology in given dimensions already compited // if dim is not provided, return true only if computed in all dimensions - bool isHomologyComputed(std::vector<int> dim=vecN0(4)) const; - bool isCohomologyComputed(std::vector<int> dim=vecN0(4)) const; + bool isHomologyComputed(std::vector<int> dim = vecN0(4)) const; + bool isCohomologyComputed(std::vector<int> dim = vecN0(4)) const; // add chains to Gmsh model // dim: only add dim-chains if dim != -1 // post: create a post-processing view // physicalNumRequest: number the chains starting from this if available // returns physical group numbers - std::vector<int> addChainsToModel(int dim=-1, bool post=true, int physicalNumRequest=-1) const; - std::vector<int> addCochainsToModel(int dim=-1, bool post=true, int physicalNumRequest=-1) const; + std::vector<int> addChainsToModel(int dim = -1, bool post = true, + int physicalNumRequest = -1) const; + std::vector<int> addCochainsToModel(int dim = -1, bool post = true, + int physicalNumRequest = -1) const; // get representative chains of a (co)homology space basis - void getHomologyBasis(int dim, std::vector<Chain<int> >& hom); - void getCohomologyBasis(int dim, std::vector<Chain<int> >& coh); - + void getHomologyBasis(int dim, std::vector<Chain<int> > &hom); + void getCohomologyBasis(int dim, std::vector<Chain<int> > &coh); // find Betti numbers // faster than finding bases for (co)homology spaces @@ -155,11 +155,11 @@ class Homology int eulerCharacteristic(); // write the generators to a file - bool writeBasisMSH(bool binary=false); + bool writeBasisMSH(bool binary = false); // store dim-dimensional cells of cellComplex as a physical group // in _model, for debugging - void storeCells(CellComplex* cellComplex, int dim); + void storeCells(CellComplex *cellComplex, int dim); }; #endif diff --git a/Geo/MEdge.cpp b/Geo/MEdge.cpp index 009a74d196fd1d5cc932a0ddd44b59082764fcf1..69cdc84a104ca26c79eedae2eeca3038d5797941 100644 --- a/Geo/MEdge.cpp +++ b/Geo/MEdge.cpp @@ -19,8 +19,9 @@ bool MEdge::isInside(MVertex *v) const MVertex *v0 = _v[0]; MVertex *v1 = _v[1]; MVertexLessThanLexicographic lt; - if(lt(v0, v1)){ - v0 = _v[1]; v1 = _v[0]; + if(lt(v0, v1)) { + v0 = _v[1]; + v1 = _v[0]; } double x = v->x(), y = v->y(), z = v->z(); double x0 = v0->x(), y0 = v0->y(), z0 = v0->z(); @@ -29,39 +30,35 @@ bool MEdge::isInside(MVertex *v) const return true; if(fabs(x - x1) < tol && fabs(y - y1) < tol && fabs(z - z1) < tol) return true; - if(x < x0 - tol || x > x1 + tol || - y < std::min(y0, y1) - tol || y > std::max(y0, y1) + tol || - z < std::min(z0, z1) - tol || z > std::max(z0, z1) + tol) + if(x < x0 - tol || x > x1 + tol || y < std::min(y0, y1) - tol || + y > std::max(y0, y1) + tol || z < std::min(z0, z1) - tol || + z > std::max(z0, z1) + tol) return false; - if(fabs(x1 - x0) > tol){ + if(fabs(x1 - x0) > tol) { double tx = (x - x0) / (x1 - x0); - if(fabs(y1 - y0) > tol){ + if(fabs(y1 - y0) > tol) { double ty = (y - y0) / (y1 - y0); - if(fabs(z1 - z0) > tol){ + if(fabs(z1 - z0) > tol) { double tz = (z - z0) / (z1 - z0); - if(fabs(tx - ty) > tol || fabs(tx - tz) > tol) - return false; + if(fabs(tx - ty) > tol || fabs(tx - tz) > tol) return false; } - else{ - if(fabs(tx - ty) > tol) - return false; + else { + if(fabs(tx - ty) > tol) return false; } } - else{ - if(fabs(z1 - z0) > tol){ + else { + if(fabs(z1 - z0) > tol) { double tz = (z - z0) / (z1 - z0); - if(fabs(tx - tz) > tol) - return false; + if(fabs(tx - tz) > tol) return false; } } } - else{ - if(fabs(y1 - y0) > tol){ + else { + if(fabs(y1 - y0) > tol) { double ty = (y - y0) / (y1 - y0); - if(fabs(z1 - z0) > tol){ + if(fabs(z1 - z0) > tol) { double tz = (z - z0) / (z1 - z0); - if(fabs(ty - tz) > tol) - return false; + if(fabs(ty - tz) > tol) return false; } } } @@ -69,71 +66,79 @@ bool MEdge::isInside(MVertex *v) const } bool SortEdgeConsecutive(const std::vector<MEdge> &e, - std::vector<std::vector<MVertex*> >&vs) + std::vector<std::vector<MVertex *> > &vs) { if(e.empty()) return true; - std::map<MVertex*, std::pair<MVertex*, MVertex*> > c; - for (size_t i = 0; i<e.size();i++){ + std::map<MVertex *, std::pair<MVertex *, MVertex *> > c; + for(size_t i = 0; i < e.size(); i++) { MVertex *v0 = e[i].getVertex(0); MVertex *v1 = e[i].getVertex(1); - std::map<MVertex*, std::pair<MVertex*,MVertex*> >::iterator it0 = c.find(v0); - std::map<MVertex*, std::pair<MVertex*,MVertex*> >::iterator it1 = c.find(v1); - if (it0 == c.end()) c[v0] = std::make_pair(v1,(MVertex*)NULL); - else it0->second.second = v1; - if (it1 == c.end()) c[v1] = std::make_pair(v0,(MVertex*)NULL); - else it1->second.second = v0; + std::map<MVertex *, std::pair<MVertex *, MVertex *> >::iterator it0 = + c.find(v0); + std::map<MVertex *, std::pair<MVertex *, MVertex *> >::iterator it1 = + c.find(v1); + if(it0 == c.end()) + c[v0] = std::make_pair(v1, (MVertex *)NULL); + else + it0->second.second = v1; + if(it1 == c.end()) + c[v1] = std::make_pair(v0, (MVertex *)NULL); + else + it1->second.second = v0; } - while (!c.empty()){ - std::vector<MVertex*> v; + while(!c.empty()) { + std::vector<MVertex *> v; MVertex *start = NULL; { - std::map<MVertex*, std::pair<MVertex*,MVertex*> >::iterator it = c.begin(); + std::map<MVertex *, std::pair<MVertex *, MVertex *> >::iterator it = + c.begin(); start = it->first; - for (; it != c.end(); ++it) { - if (it->second.second == NULL){ + for(; it != c.end(); ++it) { + if(it->second.second == NULL) { start = it->first; break; } } } - std::map<MVertex*, std::pair<MVertex*,MVertex*> >::iterator it = c.find(start); - MVertex *prev = (it->second.second == start) ? it->second.first : it->second.second; + std::map<MVertex *, std::pair<MVertex *, MVertex *> >::iterator it = + c.find(start); + MVertex *prev = + (it->second.second == start) ? it->second.first : it->second.second; MVertex *current = start; do { v.push_back(current); - std::map<MVertex*, std::pair<MVertex*,MVertex*> >::iterator it = c.find(current); + std::map<MVertex *, std::pair<MVertex *, MVertex *> >::iterator it = + c.find(current); c.erase(it); MVertex *v1 = it->second.first; MVertex *v2 = it->second.second; MVertex *temp = current; - if (v1 == prev)current = v2; - else if (v2 == prev)current = v1; + if(v1 == prev) + current = v2; + else if(v2 == prev) + current = v1; else { break; } prev = temp; - if (current == start) { + if(current == start) { v.push_back(current); } - } while (current != start && current != NULL); + } while(current != start && current != NULL); vs.push_back(v); } return true; } -MEdgeN::MEdgeN(const std::vector<MVertex*> &v) +MEdgeN::MEdgeN(const std::vector<MVertex *> &v) { _v.resize(v.size()); - for(unsigned int i = 0; i < v.size(); i++) - _v[i] = v[i]; + for(unsigned int i = 0; i < v.size(); i++) _v[i] = v[i]; } -MEdge MEdgeN::getEdge() const -{ - return MEdge(_v[0], _v[1]); -} +MEdge MEdgeN::getEdge() const { return MEdge(_v[0], _v[1]); } SPoint3 MEdgeN::pnt(double u) const { @@ -144,7 +149,7 @@ SPoint3 MEdgeN::pnt(double u) const fs->f(u, 0, 0, f); double x = 0, y = 0, z = 0; - for (int i = 0; i < fs->getNumShapeFunctions(); i++) { + for(int i = 0; i < fs->getNumShapeFunctions(); i++) { x += f[i] * _v[i]->x(); y += f[i] * _v[i]->y(); z += f[i] * _v[i]->z(); @@ -161,7 +166,7 @@ SVector3 MEdgeN::tangent(double u) const fs->df(u, 0, 0, sf); double dx = 0, dy = 0, dz = 0; - for (int i = 0; i < fs->getNumShapeFunctions(); i++) { + for(int i = 0; i < fs->getNumShapeFunctions(); i++) { dx += sf[i][0] * _v[i]->x(); dy += sf[i][0] * _v[i]->y(); dz += sf[i][0] * _v[i]->z(); @@ -178,7 +183,7 @@ double MEdgeN::interpolate(const double val[], double u, int stride) const fs->f(u, 0, 0, f); double sum = 0; - for (int i = 0, k = 0; i < fs->getNumShapeFunctions(); i++, k += stride) { + for(int i = 0, k = 0; i < fs->getNumShapeFunctions(); i++, k += stride) { sum += f[i] * val[k]; } return sum; diff --git a/Geo/MEdge.h b/Geo/MEdge.h index ac160af9ef7b7adc9798748847fa41b54dc52179..b6467c686cab13561bfe990797fdd4738b48cb11 100644 --- a/Geo/MEdge.h +++ b/Geo/MEdge.h @@ -16,7 +16,7 @@ private: char _si[2]; // sorted indices public: - typedef std::vector<int>::size_type size_type; + typedef std::vector<int>::size_type size_type; public: MEdge() diff --git a/Geo/MEdgeHash.h b/Geo/MEdgeHash.h index 29d2e914490322ec94ec83ebd414e6a2ba90d305..a85b70bcfdd3554e044329ddd57f4a27f491612e 100644 --- a/Geo/MEdgeHash.h +++ b/Geo/MEdgeHash.h @@ -15,7 +15,7 @@ struct Hash_Edge : public std::unary_function<MEdge, size_t> { const MVertex *v[2]; v[0] = e.getMinVertex(); v[1] = e.getMaxVertex(); - return HashFNV1a<sizeof(MVertex*[2])>::eval(v); + return HashFNV1a<sizeof(MVertex * [2])>::eval(v); } }; diff --git a/Geo/MElement.cpp b/Geo/MElement.cpp index 566c89497771cc6b425a13ab62dfa2da13c74697..9bff300f9964c6c3d416cb4b68985ebc6081d4af 100644 --- a/Geo/MElement.cpp +++ b/Geo/MElement.cpp @@ -31,7 +31,7 @@ #include "qualityMeasuresJacobian.h" #endif -#define SQU(a) ((a)*(a)) +#define SQU(a) ((a) * (a)) double MElement::_isInsideTolerance = 1.e-6; @@ -43,11 +43,11 @@ MElement::MElement(int num, int part) : _visible(1) { // we should make GModel a mandatory argument to the constructor GModel *m = GModel::current(); - if(num){ + if(num) { _num = num; m->setMaxElementNumber(std::max(m->getMaxElementNumber(), _num)); } - else{ + else { m->setMaxElementNumber(m->getMaxElementNumber() + 1); _num = m->getMaxElementNumber(); } @@ -67,19 +67,12 @@ void MElement::forceNum(int num) } } +void MElement::setTolerance(const double tol) { _isInsideTolerance = tol; } -void MElement::setTolerance(const double tol) -{ - _isInsideTolerance = tol; -} +double MElement::getTolerance() { return _isInsideTolerance; } -double MElement::getTolerance() -{ - return _isInsideTolerance; -} - -bool MElement::_getFaceInfo(const MFace &face, const MFace &other, - int &sign, int &rot) +bool MElement::_getFaceInfo(const MFace &face, const MFace &other, int &sign, + int &rot) { // Looks how is 'other' compared to 'face'. We suppose that 'face' // is the reference. @@ -94,24 +87,24 @@ bool MElement::_getFaceInfo(const MFace &face, const MFace &other, sign = 0; rot = -1; - if (face.getNumVertices() != other.getNumVertices()) return false; + if(face.getNumVertices() != other.getNumVertices()) return false; sign = 1; - for (rot = 0; rot < N; ++rot) { + for(rot = 0; rot < N; ++rot) { int i; - for (i = 0; i < N; ++i) { - if (other.getVertex(i) != face.getVertex((i+rot)%N)) break; + for(i = 0; i < N; ++i) { + if(other.getVertex(i) != face.getVertex((i + rot) % N)) break; } - if (i == N) return true; + if(i == N) return true; } sign = -1; - for (rot = 0; rot < N; ++rot) { + for(rot = 0; rot < N; ++rot) { int i; - for (i = 0; i < N; ++i) { - if (other.getVertex(i) != face.getVertex((N+rot-i)%N)) break; + for(i = 0; i < N; ++i) { + if(other.getVertex(i) != face.getVertex((N + rot - i) % N)) break; } - if (i == N) return true; + if(i == N) return true; } sign = 0; @@ -119,28 +112,39 @@ bool MElement::_getFaceInfo(const MFace &face, const MFace &other, return false; } -void MElement::_getEdgeRep(MVertex *v0, MVertex *v1, - double *x, double *y, double *z, SVector3 *n, - int faceIndex) +void MElement::_getEdgeRep(MVertex *v0, MVertex *v1, double *x, double *y, + double *z, SVector3 *n, int faceIndex) { - x[0] = v0->x(); y[0] = v0->y(); z[0] = v0->z(); - x[1] = v1->x(); y[1] = v1->y(); z[1] = v1->z(); - if(faceIndex >= 0){ + x[0] = v0->x(); + y[0] = v0->y(); + z[0] = v0->z(); + x[1] = v1->x(); + y[1] = v1->y(); + z[1] = v1->z(); + if(faceIndex >= 0) { n[0] = n[1] = getFace(faceIndex).normal(); } - else{ + else { MEdge e(v0, v1); n[0] = n[1] = e.normal(); } } #if defined(HAVE_VISUDEV) -void MElement::_getFaceRepQuad(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, - double *x, double *y, double *z, SVector3 *n) -{ - x[0] = v0->x(); x[1] = v1->x(); x[2] = (x[0]+x[1]+v2->x()+v3->x())/4; - y[0] = v0->y(); y[1] = v1->y(); y[2] = (y[0]+y[1]+v2->y()+v3->y())/4; - z[0] = v0->z(); z[1] = v1->z(); z[2] = (z[0]+z[1]+v2->z()+v3->z())/4;; +void MElement::_getFaceRepQuad(MVertex *v0, MVertex *v1, MVertex *v2, + MVertex *v3, double *x, double *y, double *z, + SVector3 *n) +{ + x[0] = v0->x(); + x[1] = v1->x(); + x[2] = (x[0] + x[1] + v2->x() + v3->x()) / 4; + y[0] = v0->y(); + y[1] = v1->y(); + y[2] = (y[0] + y[1] + v2->y() + v3->y()) / 4; + z[0] = v0->z(); + z[1] = v1->z(); + z[2] = (z[0] + z[1] + v2->z() + v3->z()) / 4; + ; SVector3 t1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); SVector3 t2(x[2] - x[0], y[2] - y[0], z[2] - z[0]); SVector3 normal = crossprod(t1, t2); @@ -149,12 +153,18 @@ void MElement::_getFaceRepQuad(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v } #endif -void MElement::_getFaceRep(MVertex *v0, MVertex *v1, MVertex *v2, - double *x, double *y, double *z, SVector3 *n) -{ - x[0] = v0->x(); x[1] = v1->x(); x[2] = v2->x(); - y[0] = v0->y(); y[1] = v1->y(); y[2] = v2->y(); - z[0] = v0->z(); z[1] = v1->z(); z[2] = v2->z(); +void MElement::_getFaceRep(MVertex *v0, MVertex *v1, MVertex *v2, double *x, + double *y, double *z, SVector3 *n) +{ + x[0] = v0->x(); + x[1] = v1->x(); + x[2] = v2->x(); + y[0] = v0->y(); + y[1] = v1->y(); + y[2] = v2->y(); + z[0] = v0->z(); + z[1] = v1->z(); + z[2] = v2->z(); SVector3 t1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); SVector3 t2(x[2] - x[0], y[2] - y[0], z[2] - z[0]); SVector3 normal = crossprod(t1, t2); @@ -171,19 +181,19 @@ char MElement::getVisibility() const MEdgeN MElement::getHighOrderEdge(int num, int sign) { const int order = getPolynomialOrder(); - std::vector<MVertex*> vertices((unsigned int) order + 1); + std::vector<MVertex *> vertices((unsigned int)order + 1); vertices[0] = getVertex(numEdge2numVertex(num, sign > 0 ? 0 : 1)); vertices[1] = getVertex(numEdge2numVertex(num, sign > 0 ? 1 : 0)); const int start = getNumPrimaryVertices() + num * (order - 1); const int end = getNumPrimaryVertices() + (num + 1) * (order - 1); int k = 1; - if (sign > 0) { - for (int i = start; i < end; ++i) { + if(sign > 0) { + for(int i = start; i < end; ++i) { vertices[++k] = getVertex(i); } } else { - for (int i = end - 1; i >= start; --i) { + for(int i = end - 1; i >= start; --i) { vertices[++k] = getVertex(i); } } @@ -192,14 +202,16 @@ MEdgeN MElement::getHighOrderEdge(int num, int sign) bool MElement::getEdgeInfo(const MEdge &edge, int &ithEdge, int &sign) const { - for (ithEdge = 0; ithEdge < getNumEdges(); ithEdge++) { + for(ithEdge = 0; ithEdge < getNumEdges(); ithEdge++) { const MVertex *v0 = getVertex(numEdge2numVertex(ithEdge, 0)); const MVertex *v1 = getVertex(numEdge2numVertex(ithEdge, 1)); - if (v0 == edge.getVertex(0) && v1 == edge.getVertex(1)){ - sign = 1; return true; + if(v0 == edge.getVertex(0) && v1 == edge.getVertex(1)) { + sign = 1; + return true; } - if (v1 == edge.getVertex(0) && v0 == edge.getVertex(1)){ - sign = -1; return true; + if(v1 == edge.getVertex(0) && v0 == edge.getVertex(1)) { + sign = -1; + return true; } } Msg::Error("Could not get edge information for element %d", getNum()); @@ -208,12 +220,12 @@ bool MElement::getEdgeInfo(const MEdge &edge, int &ithEdge, int &sign) const MFaceN MElement::getHighOrderFace(int num, int sign, int rot) { - if (getDim() < 2 || getDim() > 3) { + if(getDim() < 2 || getDim() > 3) { Msg::Error("Wrong dimension for getHighOrderFace"); return MFaceN(); } - if (getDim() == 2) { + if(getDim() == 2) { std::vector<MVertex *> vertices(getNumVertices()); getVertices(vertices); return MFaceN(getType(), getPolynomialOrder(), vertices); @@ -224,13 +236,13 @@ MFaceN MElement::getHighOrderFace(int num, int sign, int rot) const std::vector<int> &closure = fs->getClosure(id); std::vector<MVertex *> vertices(closure.size()); - for (unsigned int i = 0; i < closure.size(); ++i) { + for(unsigned int i = 0; i < closure.size(); ++i) { vertices[i] = getVertex(closure[i]); } static int type2numTriFaces[9] = {0, 0, 0, 1, 0, 4, 4, 2, 0}; int typeFace = TYPE_TRI; - if (num >= type2numTriFaces[getType()]) typeFace = TYPE_QUA; + if(num >= type2numTriFaces[getType()]) typeFace = TYPE_QUA; return MFaceN(typeFace, getPolynomialOrder(), vertices); } @@ -238,7 +250,7 @@ MFaceN MElement::getHighOrderFace(int num, int sign, int rot) double MElement::minEdge() { double m = 1.e25; - for(int i = 0; i < getNumEdges(); i++){ + for(int i = 0; i < getNumEdges(); i++) { MEdge e = getEdge(i); m = std::min(m, e.getVertex(0)->distance(e.getVertex(1))); } @@ -248,7 +260,7 @@ double MElement::minEdge() double MElement::maxEdge() { double m = 0.; - for(int i = 0; i < getNumEdges(); i++){ + for(int i = 0; i < getNumEdges(); i++) { MEdge e = getEdge(i); m = std::max(m, e.getVertex(0)->distance(e.getVertex(1))); } @@ -264,16 +276,17 @@ double MElement::maxDistToStraight() const const nodalBasis *lagBasis1 = getFunctionSpace(1); const int &nV1 = lagBasis1->points.size1(); std::vector<SPoint3> xyz1(nV1); - for (int iV = 0; iV < nV1; ++iV) xyz1[iV] = getVertex(iV)->point(); + for(int iV = 0; iV < nV1; ++iV) xyz1[iV] = getVertex(iV)->point(); double maxdx = 0.; - for (int iV = nV1; iV < nV; ++iV) { + for(int iV = nV1; iV < nV; ++iV) { double f[256]; - lagBasis1->f(uvw(iV, 0), (dim > 1) ? uvw(iV, 1) : 0., (dim > 2) ? uvw(iV, 2) : 0., f); - SPoint3 xyzS(0.,0.,0.); - for (int iSF = 0; iSF < nV1; ++iSF) xyzS += xyz1[iSF]*f[iSF]; - SVector3 vec(xyzS,getVertex(iV)->point()); + lagBasis1->f(uvw(iV, 0), (dim > 1) ? uvw(iV, 1) : 0., + (dim > 2) ? uvw(iV, 2) : 0., f); + SPoint3 xyzS(0., 0., 0.); + for(int iSF = 0; iSF < nV1; ++iSF) xyzS += xyz1[iSF] * f[iSF]; + SVector3 vec(xyzS, getVertex(iV)->point()); double dx = vec.norm(); - if (dx > maxdx) maxdx = dx; + if(dx > maxdx) maxdx = dx; } return maxdx; } @@ -301,9 +314,9 @@ double MElement::specialQuality() #if defined(HAVE_MESH) double minJ, maxJ; jacobianBasedQuality::minMaxJacobianDeterminant(this, minJ, maxJ); - if (minJ <= 0.) return minJ; -// if (minJ < 0 && maxJ >= 0) return minJ/maxJ; // accept -inf as an answer -// if (minJ < 0 && maxJ < 0) return -std::numeric_limits<double>::infinity(); + if(minJ <= 0.) return minJ; + // if (minJ < 0 && maxJ >= 0) return minJ/maxJ; // accept -inf as an answer + // if (minJ < 0 && maxJ < 0) return -std::numeric_limits<double>::infinity(); return jacobianBasedQuality::minICNMeasure(this, true); #else return 0; @@ -315,9 +328,9 @@ double MElement::specialQuality2() #if defined(HAVE_MESH) double minJ, maxJ; jacobianBasedQuality::minMaxJacobianDeterminant(this, minJ, maxJ); - if (minJ <= 0.) return minJ; -// if (minJ < 0 && maxJ >= 0) return minJ/maxJ; // accept -inf as an answer -// if (minJ < 0 && maxJ < 0) return -std::numeric_limits<double>::infinity(); + if(minJ <= 0.) return minJ; + // if (minJ < 0 && maxJ >= 0) return minJ/maxJ; // accept -inf as an answer + // if (minJ < 0 && maxJ < 0) return -std::numeric_limits<double>::infinity(); return jacobianBasedQuality::minIGEMeasure(this, true); #else return 0; @@ -330,37 +343,37 @@ void MElement::scaledJacRange(double &jmin, double &jmax, GEntity *ge) const #if defined(HAVE_MESH) const JacobianBasis *jac = getJacobianFuncSpace(); const int numJacNodes = jac->getNumJacNodes(); - fullMatrix<double> nodesXYZ(jac->getNumMapNodes(),3); + fullMatrix<double> nodesXYZ(jac->getNumMapNodes(), 3); getNodesCoord(nodesXYZ); fullVector<double> SJi(numJacNodes), Bi(numJacNodes); - jac->getScaledJacobian(nodesXYZ,SJi); - if (ge && (ge->dim() == 2) && ge->haveParametrization()) { + jac->getScaledJacobian(nodesXYZ, SJi); + if(ge && (ge->dim() == 2) && ge->haveParametrization()) { // If parametrized surface entity provided... - SVector3 geoNorm(0.,0.,0.); + SVector3 geoNorm(0., 0., 0.); // ... correct Jacobian sign with geometrical normal - for (int i=0; i<jac->getNumPrimMapNodes(); i++) { + for(int i = 0; i < jac->getNumPrimMapNodes(); i++) { const MVertex *vert = getVertex(i); - if (vert->onWhat() == ge) { + if(vert->onWhat() == ge) { double u, v; - vert->getParameter(0,u); - vert->getParameter(1,v); - geoNorm += ((GFace*)ge)->normal(SPoint2(u,v)); + vert->getParameter(0, u); + vert->getParameter(1, v); + geoNorm += ((GFace *)ge)->normal(SPoint2(u, v)); } } - if (geoNorm.normSq() == 0.) { + if(geoNorm.normSq() == 0.) { // If no vertex on surface or average is zero, take normal at barycenter - SPoint2 param = ((GFace*)ge)->parFromPoint(barycenter(true),false); - geoNorm = ((GFace*)ge)->normal(param); - } - fullMatrix<double> elNorm(1,3); - jac->getPrimNormal2D(nodesXYZ,elNorm); - const double scal = geoNorm(0) * elNorm(0,0) + geoNorm(1) * elNorm(0,1) + - geoNorm(2) * elNorm(0,2); - if (scal < 0.) SJi.scale(-1.); - } - jac->lag2Bez(SJi,Bi); - jmin = *std::min_element(Bi.getDataPtr(),Bi.getDataPtr()+Bi.size()); - jmax = *std::max_element(Bi.getDataPtr(),Bi.getDataPtr()+Bi.size()); + SPoint2 param = ((GFace *)ge)->parFromPoint(barycenter(true), false); + geoNorm = ((GFace *)ge)->normal(param); + } + fullMatrix<double> elNorm(1, 3); + jac->getPrimNormal2D(nodesXYZ, elNorm); + const double scal = geoNorm(0) * elNorm(0, 0) + geoNorm(1) * elNorm(0, 1) + + geoNorm(2) * elNorm(0, 2); + if(scal < 0.) SJi.scale(-1.); + } + jac->lag2Bez(SJi, Bi); + jmin = *std::min_element(Bi.getDataPtr(), Bi.getDataPtr() + Bi.size()); + jmax = *std::max_element(Bi.getDataPtr(), Bi.getDataPtr() + Bi.size()); #endif } @@ -370,54 +383,57 @@ void MElement::idealJacRange(double &jmin, double &jmax, GEntity *ge) #if defined(HAVE_MESH) const JacobianBasis *jac = getJacobianFuncSpace(); const int numJacNodes = jac->getNumJacNodes(); - fullMatrix<double> nodesXYZ(jac->getNumMapNodes(),3); + fullMatrix<double> nodesXYZ(jac->getNumMapNodes(), 3); getNodesCoord(nodesXYZ); fullVector<double> iJi(numJacNodes), Bi(numJacNodes); - jac->getSignedIdealJacobian(nodesXYZ,iJi); + jac->getSignedIdealJacobian(nodesXYZ, iJi); const int nEd = getNumEdges(), dim = getDim(); double sumEdLength = 0.; - for(int iEd = 0; iEd < nEd; iEd++) - sumEdLength += getEdge(iEd).length(); - const double invMeanEdLength = double(nEd)/sumEdLength; - if (sumEdLength == 0.) { - jmin = 0.; jmax = 0.; + for(int iEd = 0; iEd < nEd; iEd++) sumEdLength += getEdge(iEd).length(); + const double invMeanEdLength = double(nEd) / sumEdLength; + if(sumEdLength == 0.) { + jmin = 0.; + jmax = 0.; return; } - double scale = (dim == 1.) ? invMeanEdLength : - (dim == 2.) ? invMeanEdLength*invMeanEdLength : - invMeanEdLength*invMeanEdLength*invMeanEdLength; - if (ge && (ge->dim() == 2) && ge->haveParametrization()) { + double scale = (dim == 1.) ? + invMeanEdLength : + (dim == 2.) ? + invMeanEdLength * invMeanEdLength : + invMeanEdLength * invMeanEdLength * invMeanEdLength; + if(ge && (ge->dim() == 2) && ge->haveParametrization()) { // If parametrized surface entity provided... - SVector3 geoNorm(0.,0.,0.); + SVector3 geoNorm(0., 0., 0.); // ... correct Jacobian sign with geometrical normal - for (int i=0; i<jac->getNumPrimMapNodes(); i++) { + for(int i = 0; i < jac->getNumPrimMapNodes(); i++) { const MVertex *vert = getVertex(i); - if (vert->onWhat() == ge) { + if(vert->onWhat() == ge) { double u, v; - vert->getParameter(0,u); - vert->getParameter(1,v); - geoNorm += ((GFace*)ge)->normal(SPoint2(u,v)); + vert->getParameter(0, u); + vert->getParameter(1, v); + geoNorm += ((GFace *)ge)->normal(SPoint2(u, v)); } } - if (geoNorm.normSq() == 0.) { + if(geoNorm.normSq() == 0.) { // If no vertex on surface or average is zero, take normal at barycenter - SPoint2 param = ((GFace*)ge)->parFromPoint(barycenter(true),false); - geoNorm = ((GFace*)ge)->normal(param); + SPoint2 param = ((GFace *)ge)->parFromPoint(barycenter(true), false); + geoNorm = ((GFace *)ge)->normal(param); } - fullMatrix<double> elNorm(1,3); + fullMatrix<double> elNorm(1, 3); jac->getPrimNormal2D(nodesXYZ, elNorm, true); - const double dp = geoNorm(0) * elNorm(0,0) + geoNorm(1) * elNorm(0,1) + - geoNorm(2) * elNorm(0,2); - if (dp < 0.) scale = -scale; + const double dp = geoNorm(0) * elNorm(0, 0) + geoNorm(1) * elNorm(0, 1) + + geoNorm(2) * elNorm(0, 2); + if(dp < 0.) scale = -scale; } iJi.scale(scale); - jac->lag2Bez(iJi,Bi); - jmin = *std::min_element(Bi.getDataPtr(),Bi.getDataPtr()+Bi.size()); - jmax = *std::max_element(Bi.getDataPtr(),Bi.getDataPtr()+Bi.size()); + jac->lag2Bez(iJi, Bi); + jmin = *std::min_element(Bi.getDataPtr(), Bi.getDataPtr() + Bi.size()); + jmax = *std::max_element(Bi.getDataPtr(), Bi.getDataPtr() + Bi.size()); #endif } -void MElement::signedInvCondNumRange(double &iCNMin, double &iCNMax, GEntity *ge) +void MElement::signedInvCondNumRange(double &iCNMin, double &iCNMax, + GEntity *ge) { iCNMin = iCNMax = 1.0; #if defined(HAVE_MESH) @@ -425,49 +441,53 @@ void MElement::signedInvCondNumRange(double &iCNMin, double &iCNMax, GEntity *ge const int numCNNodes = cnb->getNumCondNumNodes(); fullMatrix<double> nodesXYZ(cnb->getNumMapNodes(), 3), normals; getNodesCoord(nodesXYZ); - if (getDim() == 2.) { + if(getDim() == 2.) { SVector3 nVec = getFace(0).normal(); normals.resize(1, 3); - normals(0, 0) = nVec[0]; normals(0, 1) = nVec[1]; normals(0, 2) = nVec[2]; + normals(0, 0) = nVec[0]; + normals(0, 1) = nVec[1]; + normals(0, 2) = nVec[2]; } - if (ge && (ge->dim() == 2) && ge->haveParametrization()) { + if(ge && (ge->dim() == 2) && ge->haveParametrization()) { // If parametrized surface entity provided... SVector3 geoNorm(0., 0., 0.); // ... correct Jacobian sign with geometrical normal - for (int i=0; i<getNumPrimaryVertices(); i++) { + for(int i = 0; i < getNumPrimaryVertices(); i++) { const MVertex *vert = getVertex(i); - if (vert->onWhat() == ge) { + if(vert->onWhat() == ge) { double u, v; vert->getParameter(0, u); vert->getParameter(1, v); - geoNorm += ((GFace*)ge)->normal(SPoint2(u, v)); + geoNorm += ((GFace *)ge)->normal(SPoint2(u, v)); } } - if (geoNorm.normSq() == 0.) { + if(geoNorm.normSq() == 0.) { // If no vertex on surface or average is zero, take normal at barycenter - SPoint2 param = ((GFace*)ge)->parFromPoint(barycenter(true), false); - geoNorm = ((GFace*)ge)->normal(param); + SPoint2 param = ((GFace *)ge)->parFromPoint(barycenter(true), false); + geoNorm = ((GFace *)ge)->normal(param); } - const double dp = geoNorm(0) * normals(0, 0) + geoNorm(1) * normals(0, 1) - + geoNorm(2) * normals(0, 2); - if (dp < 0.) { - normals(0, 0) = -normals(0, 0); - normals(0, 1) = -normals(0, 1); - normals(0, 2) = -normals(0, 2); + const double dp = geoNorm(0) * normals(0, 0) + geoNorm(1) * normals(0, 1) + + geoNorm(2) * normals(0, 2); + if(dp < 0.) { + normals(0, 0) = -normals(0, 0); + normals(0, 1) = -normals(0, 1); + normals(0, 2) = -normals(0, 2); } } fullVector<double> invCondNum(numCNNodes); cnb->getSignedInvCondNum(nodesXYZ, normals, invCondNum); - iCNMin = *std::min_element(invCondNum.getDataPtr(), invCondNum.getDataPtr()+numCNNodes); - iCNMax = *std::max_element(invCondNum.getDataPtr(), invCondNum.getDataPtr()+numCNNodes); + iCNMin = *std::min_element(invCondNum.getDataPtr(), + invCondNum.getDataPtr() + numCNNodes); + iCNMax = *std::max_element(invCondNum.getDataPtr(), + invCondNum.getDataPtr() + numCNNodes); #endif } void MElement::signedInvGradErrorRange(double &minSIGE, double &maxSIGE) { #if defined(HAVE_MESH) - jacobianBasedQuality::sampleIGEMeasure(this, getPolynomialOrder(), - minSIGE, maxSIGE); + jacobianBasedQuality::sampleIGEMeasure(this, getPolynomialOrder(), minSIGE, + maxSIGE); #endif } @@ -481,55 +501,66 @@ void MElement::getNode(int num, double &u, double &v, double &w) const w = getDim() > 2 ? refpnts(num, 2) : 0; } -void MElement::getShapeFunctions(double u, double v, double w, double s[], int o) const +void MElement::getShapeFunctions(double u, double v, double w, double s[], + int o) const { - const nodalBasis* fs = getFunctionSpace(o); - if(fs) fs->f(u, v, w, s); - else Msg::Error("Function space not implemented for this type of element"); + const nodalBasis *fs = getFunctionSpace(o); + if(fs) + fs->f(u, v, w, s); + else + Msg::Error("Function space not implemented for this type of element"); } -void MElement::getGradShapeFunctions(double u, double v, double w, double s[][3],int o) const +void MElement::getGradShapeFunctions(double u, double v, double w, + double s[][3], int o) const { - const nodalBasis* fs = getFunctionSpace(o); - if(fs) fs->df(u, v, w, s); - else Msg::Error("Function space not implemented for this type of element"); + const nodalBasis *fs = getFunctionSpace(o); + if(fs) + fs->df(u, v, w, s); + else + Msg::Error("Function space not implemented for this type of element"); } -void MElement::getHessShapeFunctions(double u, double v, double w, double s[][3][3], - int o) const +void MElement::getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int o) const { - const nodalBasis* fs = getFunctionSpace(o); - if(fs) fs->ddf(u, v, w, s); - else Msg::Error("Function space not implemented for this type of element"); + const nodalBasis *fs = getFunctionSpace(o); + if(fs) + fs->ddf(u, v, w, s); + else + Msg::Error("Function space not implemented for this type of element"); } void MElement::getThirdDerivativeShapeFunctions(double u, double v, double w, - double s[][3][3][3], int o) const + double s[][3][3][3], + int o) const { - const nodalBasis* fs = getFunctionSpace(o); - if(fs) fs->dddf(u, v, w, s); - else Msg::Error("Function space not implemented for this type of element"); + const nodalBasis *fs = getFunctionSpace(o); + if(fs) + fs->dddf(u, v, w, s); + else + Msg::Error("Function space not implemented for this type of element"); } -SPoint3 MElement::barycenter_infty () const +SPoint3 MElement::barycenter_infty() const { - double xmin = getVertex(0)->x(); + double xmin = getVertex(0)->x(); double xmax = xmin; - double ymin = getVertex(0)->y(); + double ymin = getVertex(0)->y(); double ymax = ymin; - double zmin = getVertex(0)->z(); + double zmin = getVertex(0)->z(); double zmax = zmin; int n = getNumVertices(); for(int i = 0; i < n; i++) { const MVertex *v = getVertex(i); - xmin = std::min(xmin,v->x()); - xmax = std::max(xmax,v->x()); - ymin = std::min(ymin,v->y()); - ymax = std::max(ymax,v->y()); - zmin = std::min(zmin,v->z()); - zmax = std::max(zmax,v->z()); + xmin = std::min(xmin, v->x()); + xmax = std::max(xmax, v->x()); + ymin = std::min(ymin, v->y()); + ymax = std::max(ymax, v->y()); + zmin = std::min(zmin, v->z()); + zmax = std::max(zmax, v->z()); } - return SPoint3(0.5*(xmin+xmax),0.5*(ymin+ymax),0.5*(zmin+zmax)); + return SPoint3(0.5 * (xmin + xmax), 0.5 * (ymin + ymax), 0.5 * (zmin + zmax)); } SPoint3 MElement::barycenter(bool primary) const @@ -585,9 +616,9 @@ double MElement::getVolume() IntPt *pts; getIntegrationPoints(getDim() * (getPolynomialOrder() - 1), &npts, &pts); double vol = 0.; - for (int i = 0; i < npts; i++){ - vol += getJacobianDeterminant(pts[i].pt[0], pts[i].pt[1], pts[i].pt[2]) - * pts[i].weight; + for(int i = 0; i < npts; i++) { + vol += getJacobianDeterminant(pts[i].pt[0], pts[i].pt[1], pts[i].pt[2]) * + pts[i].weight; } return vol; } @@ -595,9 +626,12 @@ double MElement::getVolume() int MElement::getVolumeSign() { double v = getVolume(); - if(v < 0.) return -1; - else if(v > 0.) return 1; - else return 0; + if(v < 0.) + return -1; + else if(v > 0.) + return 1; + else + return 0; } bool MElement::setVolumePositive() @@ -614,8 +648,8 @@ int MElement::getValidity() #if defined(HAVE_MESH) double jmin, jmax; jacobianBasedQuality::minMaxJacobianDeterminant(this, jmin, jmax); - if (jmin > .0) return 1; // valid - if (jmax >= .0) return 0; // invalid + if(jmin > .0) return 1; // valid + if(jmax >= .0) return 0; // invalid // Here, jmax < 0 (and jmin < 0). The element validity is quite indeterminate. // It can be valid but with a wrong numbering of the nodes, // or it can be invalid, i.e. with nodes that are incorrectly located. @@ -635,12 +669,9 @@ std::string MElement::getInfoString(bool multline) const char *name; MElement::getInfoMSH(getTypeForMSH(), &name); - sstream << " " << name - << " (MSH type " << getTypeForMSH() - << ", dimension "<< getDim() - << ", order "<< getPolynomialOrder() - << ", partition " << getPartition() - << ")"; + sstream << " " << name << " (MSH type " << getTypeForMSH() << ", dimension " + << getDim() << ", order " << getPolynomialOrder() << ", partition " + << getPartition() << ")"; if(multline) sstream << "\n"; sstream << " Nodes:"; @@ -671,88 +702,95 @@ std::string MElement::getInfoString(bool multline) sstream << " SIGE range: " << sIGEMin << " " << sIGEMax; if(multline) sstream << "\n"; - sstream << " Inner / outer radius: " - << getInnerRadius() << " / " << getOuterRadius(); + sstream << " Inner / outer radius: " << getInnerRadius() << " / " + << getOuterRadius(); return sstream.str(); } -const nodalBasis* MElement::getFunctionSpace(int order, bool serendip) const +const nodalBasis *MElement::getFunctionSpace(int order, bool serendip) const { - if (order == -1) return BasisFactory::getNodalBasis(getTypeForMSH()); + if(order == -1) return BasisFactory::getNodalBasis(getTypeForMSH()); int type = ElementType::getType(getType(), order, serendip); return type ? BasisFactory::getNodalBasis(type) : NULL; } -const JacobianBasis* MElement::getJacobianFuncSpace(int order) const +const JacobianBasis *MElement::getJacobianFuncSpace(int order) const { - if (order == -1) return BasisFactory::getJacobianBasis(getTypeForMSH()); + if(order == -1) return BasisFactory::getJacobianBasis(getTypeForMSH()); int tag = ElementType::getType(getType(), order); return BasisFactory::getJacobianBasis(tag); } -static double _computeDeterminantAndRegularize(const MElement *ele, double jac[3][3]) +static double _computeDeterminantAndRegularize(const MElement *ele, + double jac[3][3]) { double dJ = 0; - switch (ele->getDim()) { + switch(ele->getDim()) { + case 0: { + dJ = 1.0; + jac[0][0] = jac[1][1] = jac[2][2] = 1.0; + jac[0][1] = jac[1][0] = jac[2][0] = 0.0; + jac[0][2] = jac[1][2] = jac[2][1] = 0.0; + break; + } + case 1: { + dJ = sqrt(SQU(jac[0][0]) + SQU(jac[0][1]) + SQU(jac[0][2])); - case 0: - { - dJ = 1.0; - jac[0][0] = jac[1][1] = jac[2][2] = 1.0; - jac[0][1] = jac[1][0] = jac[2][0] = 0.0; - jac[0][2] = jac[1][2] = jac[2][1] = 0.0; - break; + // regularize matrix + double a[3], b[3], c[3]; + a[0] = jac[0][0]; + a[1] = jac[0][1]; + a[2] = jac[0][2]; + if((fabs(a[0]) >= fabs(a[1]) && fabs(a[0]) >= fabs(a[2])) || + (fabs(a[1]) >= fabs(a[0]) && fabs(a[1]) >= fabs(a[2]))) { + b[0] = a[1]; + b[1] = -a[0]; + b[2] = 0.; } - case 1: - { - dJ = sqrt(SQU(jac[0][0]) + SQU(jac[0][1]) + SQU(jac[0][2])); - - // regularize matrix - double a[3], b[3], c[3]; - a[0] = jac[0][0]; - a[1] = jac[0][1]; - a[2] = jac[0][2]; - if((fabs(a[0]) >= fabs(a[1]) && fabs(a[0]) >= fabs(a[2])) || - (fabs(a[1]) >= fabs(a[0]) && fabs(a[1]) >= fabs(a[2]))) { - b[0] = a[1]; b[1] = -a[0]; b[2] = 0.; - } - else { - b[0] = 0.; b[1] = a[2]; b[2] = -a[1]; - } - norme(b); - prodve(a, b, c); - norme(c); - jac[1][0] = b[0]; jac[1][1] = b[1]; jac[1][2] = b[2]; - jac[2][0] = c[0]; jac[2][1] = c[1]; jac[2][2] = c[2]; - break; - } - case 2: - { - dJ = sqrt(SQU(jac[0][0] * jac[1][1] - jac[0][1] * jac[1][0]) + - SQU(jac[0][2] * jac[1][0] - jac[0][0] * jac[1][2]) + - SQU(jac[0][1] * jac[1][2] - jac[0][2] * jac[1][1])); - - // regularize matrix - double a[3], b[3], c[3]; - a[0] = jac[0][0]; - a[1] = jac[0][1]; - a[2] = jac[0][2]; - b[0] = jac[1][0]; - b[1] = jac[1][1]; - b[2] = jac[1][2]; - prodve(a, b, c); - norme(c); - jac[2][0] = c[0]; jac[2][1] = c[1]; jac[2][2] = c[2]; - break; - } - case 3: - { - dJ = (jac[0][0] * jac[1][1] * jac[2][2] + jac[0][2] * jac[1][0] * jac[2][1] + - jac[0][1] * jac[1][2] * jac[2][0] - jac[0][2] * jac[1][1] * jac[2][0] - - jac[0][0] * jac[1][2] * jac[2][1] - jac[0][1] * jac[1][0] * jac[2][2]); - break; + else { + b[0] = 0.; + b[1] = a[2]; + b[2] = -a[1]; } + norme(b); + prodve(a, b, c); + norme(c); + jac[1][0] = b[0]; + jac[1][1] = b[1]; + jac[1][2] = b[2]; + jac[2][0] = c[0]; + jac[2][1] = c[1]; + jac[2][2] = c[2]; + break; + } + case 2: { + dJ = sqrt(SQU(jac[0][0] * jac[1][1] - jac[0][1] * jac[1][0]) + + SQU(jac[0][2] * jac[1][0] - jac[0][0] * jac[1][2]) + + SQU(jac[0][1] * jac[1][2] - jac[0][2] * jac[1][1])); + + // regularize matrix + double a[3], b[3], c[3]; + a[0] = jac[0][0]; + a[1] = jac[0][1]; + a[2] = jac[0][2]; + b[0] = jac[1][0]; + b[1] = jac[1][1]; + b[2] = jac[1][2]; + prodve(a, b, c); + norme(c); + jac[2][0] = c[0]; + jac[2][1] = c[1]; + jac[2][2] = c[2]; + break; + } + case 3: { + dJ = + (jac[0][0] * jac[1][1] * jac[2][2] + jac[0][2] * jac[1][0] * jac[2][1] + + jac[0][1] * jac[1][2] * jac[2][0] - jac[0][2] * jac[1][1] * jac[2][0] - + jac[0][0] * jac[1][2] * jac[2][1] - jac[0][1] * jac[1][0] * jac[2][2]); + break; + } } return dJ; } @@ -770,18 +808,15 @@ static double _computeDeterminantAndRegularize(const MElement *ele, double *jac) * */ - switch (ele->getDim()) { - - case 0: - { + switch(ele->getDim()) { + case 0: { dJ = 1.0; jac[0] = jac[4] = jac[8] = 1.0; jac[1] = jac[2] = jac[3] = 0.0; jac[5] = jac[6] = jac[7] = 0.0; break; - } - case 1: - { + } + case 1: { dJ = sqrt(SQU(jac[0]) + SQU(jac[1]) + SQU(jac[2])); // regularize matrix @@ -791,20 +826,27 @@ static double _computeDeterminantAndRegularize(const MElement *ele, double *jac) a[2] = jac[2]; if((fabs(a[0]) >= fabs(a[1]) && fabs(a[0]) >= fabs(a[2])) || (fabs(a[1]) >= fabs(a[0]) && fabs(a[1]) >= fabs(a[2]))) { - b[0] = a[1]; b[1] = -a[0]; b[2] = 0.; + b[0] = a[1]; + b[1] = -a[0]; + b[2] = 0.; } else { - b[0] = 0.; b[1] = a[2]; b[2] = -a[1]; + b[0] = 0.; + b[1] = a[2]; + b[2] = -a[1]; } norme(b); prodve(a, b, c); norme(c); - jac[3] = b[0]; jac[4] = b[1]; jac[5] = b[2]; - jac[6] = c[0]; jac[7] = c[1]; jac[8] = c[2]; + jac[3] = b[0]; + jac[4] = b[1]; + jac[5] = b[2]; + jac[6] = c[0]; + jac[7] = c[1]; + jac[8] = c[2]; break; - } - case 2: - { + } + case 2: { dJ = sqrt(SQU(jac[0] * jac[4] - jac[1] * jac[3]) + SQU(jac[2] * jac[3] - jac[0] * jac[5]) + SQU(jac[1] * jac[5] - jac[2] * jac[4])); @@ -819,21 +861,23 @@ static double _computeDeterminantAndRegularize(const MElement *ele, double *jac) b[2] = jac[5]; prodve(a, b, c); norme(c); - jac[6] = c[0]; jac[7] = c[1]; jac[8] = c[2]; + jac[6] = c[0]; + jac[7] = c[1]; + jac[8] = c[2]; break; - } - case 3: - { + } + case 3: { dJ = (jac[0] * jac[4] * jac[8] + jac[2] * jac[3] * jac[7] + jac[1] * jac[5] * jac[6] - jac[2] * jac[4] * jac[6] - jac[0] * jac[5] * jac[7] - jac[1] * jac[3] * jac[8]); break; - } + } } return dJ; } -double MElement::getJacobian(double u, double v, double w, double jac[3][3]) const +double MElement::getJacobian(double u, double v, double w, + double jac[3][3]) const { jac[0][0] = jac[0][1] = jac[0][2] = 0.; jac[1][0] = jac[1][1] = jac[1][2] = 0.; @@ -841,10 +885,10 @@ double MElement::getJacobian(double u, double v, double w, double jac[3][3]) con double gsf[1256][3]; getGradShapeFunctions(u, v, w, gsf); - for (int i = 0; i < getNumShapeFunctions(); i++) { + for(int i = 0; i < getNumShapeFunctions(); i++) { const MVertex *ver = getShapeFunctionNode(i); - double* gg = gsf[i]; - for (int j = 0; j < getDim(); j++) { + double *gg = gsf[i]; + for(int j = 0; j < getDim(); j++) { jac[j][0] += ver->x() * gg[j]; jac[j][1] += ver->y() * gg[j]; jac[j][2] += ver->z() * gg[j]; @@ -854,16 +898,17 @@ double MElement::getJacobian(double u, double v, double w, double jac[3][3]) con return _computeDeterminantAndRegularize(this, jac); } -double MElement::getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const +double MElement::getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const { jac[0][0] = jac[0][1] = jac[0][2] = 0.; jac[1][0] = jac[1][1] = jac[1][2] = 0.; jac[2][0] = jac[2][1] = jac[2][2] = 0.; const int numShapeFunctions = getNumShapeFunctions(); - for (int i = 0; i < numShapeFunctions; i++) { + for(int i = 0; i < numShapeFunctions; i++) { const MVertex *v = getShapeFunctionNode(i); - for (int j = 0; j < gsf.size2(); j++) { + for(int j = 0; j < gsf.size2(); j++) { jac[j][0] += v->x() * gsf(i, j); jac[j][1] += v->y() * gsf(i, j); jac[j][2] += v->z() * gsf(i, j); @@ -872,16 +917,17 @@ double MElement::getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) co return _computeDeterminantAndRegularize(this, jac); } -double MElement::getJacobian(const std::vector<SVector3> &gsf, double jac[3][3]) const +double MElement::getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const { jac[0][0] = jac[0][1] = jac[0][2] = 0.; jac[1][0] = jac[1][1] = jac[1][2] = 0.; jac[2][0] = jac[2][1] = jac[2][2] = 0.; const int numShapeFunctions = getNumVertices(); - for (int i = 0; i < numShapeFunctions; i++) { + for(int i = 0; i < numShapeFunctions; i++) { const MVertex *v = getShapeFunctionNode(i); - for (int j = 0; j < 3; j++) { + for(int j = 0; j < 3; j++) { const double mult = gsf[i][j]; jac[j][0] += v->x() * mult; jac[j][1] += v->y() * mult; @@ -891,26 +937,28 @@ double MElement::getJacobian(const std::vector<SVector3> &gsf, double jac[3][3]) return _computeDeterminantAndRegularize(this, jac); } -double MElement::getJacobian(const std::vector<SVector3> &gsf, double *jac) const +double MElement::getJacobian(const std::vector<SVector3> &gsf, + double *jac) const { - for(unsigned int i = 0; i < 9; i++){ + for(unsigned int i = 0; i < 9; i++) { jac[i] = 0.; } const int numShapeFunctions = getNumVertices(); - for (int i = 0; i < numShapeFunctions; i++) { + for(int i = 0; i < numShapeFunctions; i++) { const MVertex *v = getShapeFunctionNode(i); - for (int j = 0; j < 3; j++) { + for(int j = 0; j < 3; j++) { const double mult = gsf[i][j]; - jac[3*j+0] += v->x() * mult; - jac[3*j+1] += v->y() * mult; - jac[3*j+2] += v->z() * mult; + jac[3 * j + 0] += v->x() * mult; + jac[3 * j + 1] += v->y() * mult; + jac[3 * j + 2] += v->z() * mult; } } return _computeDeterminantAndRegularize(this, jac); } -double MElement::getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const +double MElement::getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const { jac[0][0] = jac[0][1] = jac[0][2] = 0.; jac[1][0] = jac[1][1] = jac[1][2] = 0.; @@ -920,8 +968,8 @@ double MElement::getPrimaryJacobian(double u, double v, double w, double jac[3][ getGradShapeFunctions(u, v, w, gsf, 1); for(int i = 0; i < getNumPrimaryShapeFunctions(); i++) { const MVertex *v = getShapeFunctionNode(i); - double* gg = gsf[i]; - for (int j = 0; j < 3; j++) { + double *gg = gsf[i]; + for(int j = 0; j < 3; j++) { jac[j][0] += v->x() * gg[j]; jac[j][1] += v->y() * gg[j]; jac[j][2] += v->z() * gg[j]; @@ -934,44 +982,42 @@ double MElement::getPrimaryJacobian(double u, double v, double w, double jac[3][ void MElement::getSignedJacobian(fullVector<double> &jacobian, int o) const { const int numNodes = getNumVertices(); - fullMatrix<double> nodesXYZ(numNodes,3); + fullMatrix<double> nodesXYZ(numNodes, 3); getNodesCoord(nodesXYZ); - getJacobianFuncSpace(o)->getSignedJacobian(nodesXYZ,jacobian); + getJacobianFuncSpace(o)->getSignedJacobian(nodesXYZ, jacobian); } void MElement::getNodesCoord(fullMatrix<double> &nodesXYZ) const { const int numNodes = getNumVertices(); - for (int i = 0; i < numNodes; i++) { + for(int i = 0; i < numNodes; i++) { const MVertex *v = getShapeFunctionNode(i); - nodesXYZ(i,0) = v->x(); - nodesXYZ(i,1) = v->y(); - nodesXYZ(i,2) = v->z(); + nodesXYZ(i, 0) = v->x(); + nodesXYZ(i, 1) = v->y(); + nodesXYZ(i, 2) = v->z(); } } -double MElement::getEigenvaluesMetric(double u, double v, double w, double values[3]) const +double MElement::getEigenvaluesMetric(double u, double v, double w, + double values[3]) const { double jac[3][3]; getJacobian(u, v, w, jac); GradientBasis::mapFromIdealElement(getType(), jac); - switch (getDim()) { + switch(getDim()) { case 1: values[0] = 0; values[1] = -1; values[2] = -1; - for (int d = 0; d < 3; ++d) - values[0] += jac[d][0] * jac[d][0]; + for(int d = 0; d < 3; ++d) values[0] += jac[d][0] * jac[d][0]; return 1; - case 2: - { + case 2: { fullMatrix<double> metric(2, 2); - for (int i = 0; i < 2; ++i) { - for (int j = 0; j < 2; ++j) { - for (int d = 0; d < 3; ++d) - metric(i, j) += jac[d][i] * jac[d][j]; + for(int i = 0; i < 2; ++i) { + for(int j = 0; j < 2; ++j) { + for(int d = 0; d < 3; ++d) metric(i, j) += jac[d][i] * jac[d][j]; } } fullVector<double> valReal(values, 2), valImag(2); @@ -981,13 +1027,11 @@ double MElement::getEigenvaluesMetric(double u, double v, double w, double value return std::sqrt(valReal(0) / valReal(1)); } - case 3: - { + case 3: { fullMatrix<double> metric(3, 3); - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) { - for (int d = 0; d < 3; ++d) - metric(i, j) += jac[d][i] * jac[d][j]; + for(int i = 0; i < 3; ++i) { + for(int j = 0; j < 3; ++j) { + for(int d = 0; d < 3; ++d) metric(i, j) += jac[d][i] * jac[d][j]; } } @@ -1009,7 +1053,7 @@ void MElement::pnt(double u, double v, double w, SPoint3 &p) const double x = 0., y = 0., z = 0.; double sf[1256]; getShapeFunctions(u, v, w, sf); - for (int j = 0; j < getNumShapeFunctions(); j++) { + for(int j = 0; j < getNumShapeFunctions(); j++) { const MVertex *v = getShapeFunctionNode(j); x += sf[j] * v->x(); y += sf[j] * v->y(); @@ -1023,7 +1067,7 @@ void MElement::pnt(double u, double v, double w, double *p) const double x = 0., y = 0., z = 0.; double sf[1256]; getShapeFunctions(u, v, w, sf); - for (int j = 0; j < getNumShapeFunctions(); j++) { + for(int j = 0; j < getNumShapeFunctions(); j++) { const MVertex *v = getShapeFunctionNode(j); x += sf[j] * v->x(); y += sf[j] * v->y(); @@ -1037,7 +1081,7 @@ void MElement::pnt(double u, double v, double w, double *p) const void MElement::pnt(const std::vector<double> &sf, SPoint3 &p) const { double x = 0., y = 0., z = 0.; - for (int j = 0; j < getNumShapeFunctions(); j++) { + for(int j = 0; j < getNumShapeFunctions(); j++) { const MVertex *v = getShapeFunctionNode(j); x += sf[j] * v->x(); y += sf[j] * v->y(); @@ -1051,13 +1095,13 @@ void MElement::primaryPnt(double u, double v, double w, SPoint3 &p) double x = 0., y = 0., z = 0.; double sf[1256]; getShapeFunctions(u, v, w, sf, 1); - for (int j = 0; j < getNumPrimaryShapeFunctions(); j++) { + for(int j = 0; j < getNumPrimaryShapeFunctions(); j++) { const MVertex *v = getShapeFunctionNode(j); x += sf[j] * v->x(); y += sf[j] * v->y(); z += sf[j] * v->z(); } - p = SPoint3(x,y,z); + p = SPoint3(x, y, z); } void MElement::xyz2uvw(double xyz[3], double uvw[3]) const @@ -1068,25 +1112,25 @@ void MElement::xyz2uvw(double xyz[3], double uvw[3]) const uvw[0] = uvw[1] = uvw[2] = 0.; // For high order elements, start from the nearer point - if (getPolynomialOrder() > 2) { + if(getPolynomialOrder() > 2) { int numNearer = 0; const MVertex *v = getShapeFunctionNode(0); - double distNearer = (v->x()-xyz[0])*(v->x()-xyz[0]) + - (v->y()-xyz[1])*(v->y()-xyz[1]) + - (v->z()-xyz[2])*(v->z()-xyz[2]); - for (int i = 1; i < getNumShapeFunctions(); i++) { + double distNearer = (v->x() - xyz[0]) * (v->x() - xyz[0]) + + (v->y() - xyz[1]) * (v->y() - xyz[1]) + + (v->z() - xyz[2]) * (v->z() - xyz[2]); + for(int i = 1; i < getNumShapeFunctions(); i++) { const MVertex *v = getShapeFunctionNode(i); - double dist = (v->x()-xyz[0])*(v->x()-xyz[0]) + - (v->y()-xyz[1])*(v->y()-xyz[1]) + - (v->z()-xyz[2])*(v->z()-xyz[2]); - if (dist < distNearer) { + double dist = (v->x() - xyz[0]) * (v->x() - xyz[0]) + + (v->y() - xyz[1]) * (v->y() - xyz[1]) + + (v->z() - xyz[2]) * (v->z() - xyz[2]); + if(dist < distNearer) { numNearer = i; distNearer = dist; } } const nodalBasis *nb = getFunctionSpace(); fullMatrix<double> refpnts = nb->getReferenceNodes(); - for (int i=0; i < getDim(); i++){ + for(int i = 0; i < getDim(); i++) { uvw[i] = refpnts(numNearer, i); } } @@ -1094,13 +1138,13 @@ void MElement::xyz2uvw(double xyz[3], double uvw[3]) const int iter = 1, maxiter = 20; double error = 1., tol = 1.e-6; - while (error > tol && iter < maxiter){ + while(error > tol && iter < maxiter) { double jac[3][3]; if(!getJacobian(uvw[0], uvw[1], uvw[2], jac)) break; double xn = 0., yn = 0., zn = 0.; double sf[1256]; getShapeFunctions(uvw[0], uvw[1], uvw[2], sf); - for (int i = 0; i < getNumShapeFunctions(); i++) { + for(int i = 0; i < getNumShapeFunctions(); i++) { const MVertex *v = getShapeFunctionNode(i); xn += v->x() * sf[i]; yn += v->y() * sf[i]; @@ -1108,24 +1152,22 @@ void MElement::xyz2uvw(double xyz[3], double uvw[3]) const } double inv[3][3]; inv3x3(jac, inv); - double un = uvw[0] + inv[0][0] * (xyz[0] - xn) - + inv[1][0] * (xyz[1] - yn) - + inv[2][0] * (xyz[2] - zn); - double vn = uvw[1] + inv[0][1] * (xyz[0] - xn) - + inv[1][1] * (xyz[1] - yn) - + inv[2][1] * (xyz[2] - zn); - double wn = uvw[2] + inv[0][2] * (xyz[0] - xn) - + inv[1][2] * (xyz[1] - yn) - + inv[2][2] * (xyz[2] - zn); + double un = uvw[0] + inv[0][0] * (xyz[0] - xn) + inv[1][0] * (xyz[1] - yn) + + inv[2][0] * (xyz[2] - zn); + double vn = uvw[1] + inv[0][1] * (xyz[0] - xn) + inv[1][1] * (xyz[1] - yn) + + inv[2][1] * (xyz[2] - zn); + double wn = uvw[2] + inv[0][2] * (xyz[0] - xn) + inv[1][2] * (xyz[1] - yn) + + inv[2][2] * (xyz[2] - zn); error = sqrt(SQU(un - uvw[0]) + SQU(vn - uvw[1]) + SQU(wn - uvw[2])); uvw[0] = un; uvw[1] = vn; uvw[2] = wn; - iter++ ; + iter++; } } -void MElement::movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const +void MElement::movePointFromParentSpaceToElementSpace(double &u, double &v, + double &w) const { if(!getParent()) return; SPoint3 p; @@ -1133,10 +1175,13 @@ void MElement::movePointFromParentSpaceToElementSpace(double &u, double &v, doub double xyz[3] = {p.x(), p.y(), p.z()}; double uvwE[3]; xyz2uvw(xyz, uvwE); - u = uvwE[0]; v = uvwE[1]; w = uvwE[2]; + u = uvwE[0]; + v = uvwE[1]; + w = uvwE[2]; } -void MElement::movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const +void MElement::movePointFromElementSpaceToParentSpace(double &u, double &v, + double &w) const { if(!getParent()) return; SPoint3 p; @@ -1144,40 +1189,43 @@ void MElement::movePointFromElementSpaceToParentSpace(double &u, double &v, doub double xyz[3] = {p.x(), p.y(), p.z()}; double uvwP[3]; getParent()->xyz2uvw(xyz, uvwP); - u = uvwP[0]; v = uvwP[1]; w = uvwP[2]; + u = uvwP[0]; + v = uvwP[1]; + w = uvwP[2]; } -double MElement::interpolate(double val[], double u, double v, double w, int stride, - int order) +double MElement::interpolate(double val[], double u, double v, double w, + int stride, int order) { double sum = 0; int j = 0; double sf[1256]; getShapeFunctions(u, v, w, sf, order); - for(int i = 0; i < getNumShapeFunctions(); i++){ + for(int i = 0; i < getNumShapeFunctions(); i++) { sum += val[j] * sf[i]; j += stride; } return sum; } -void MElement::interpolateGrad(double val[], double u, double v, double w, double f[], - int stride, double invjac[3][3], int order) +void MElement::interpolateGrad(double val[], double u, double v, double w, + double f[], int stride, double invjac[3][3], + int order) { double dfdu[3] = {0., 0., 0.}; int j = 0; double gsf[1256][3]; getGradShapeFunctions(u, v, w, gsf, order); - for(int i = 0; i < getNumShapeFunctions(); i++){ + for(int i = 0; i < getNumShapeFunctions(); i++) { dfdu[0] += val[j] * gsf[i][0]; dfdu[1] += val[j] * gsf[i][1]; dfdu[2] += val[j] * gsf[i][2]; j += stride; } - if(invjac){ + if(invjac) { matvec(invjac, dfdu, f); } - else{ + else { double jac[3][3], inv[3][3]; getJacobian(u, v, w, jac); inv3x3(jac, inv); @@ -1185,8 +1233,8 @@ void MElement::interpolateGrad(double val[], double u, double v, double w, doubl } } -void MElement::interpolateCurl(double val[], double u, double v, double w, double f[], - int stride, int order) +void MElement::interpolateCurl(double val[], double u, double v, double w, + double f[], int stride, int order) { double fx[3], fy[3], fz[3], jac[3][3], inv[3][3]; getJacobian(u, v, w, jac); @@ -1213,40 +1261,42 @@ double MElement::interpolateDiv(double val[], double u, double v, double w, double MElement::integrate(double val[], int pOrder, int stride, int order) { - int npts; IntPt *gp; + int npts; + IntPt *gp; getIntegrationPoints(pOrder, &npts, &gp); double sum = 0; - for (int i = 0; i < npts; i++){ + for(int i = 0; i < npts; i++) { double u = gp[i].pt[0]; double v = gp[i].pt[1]; double w = gp[i].pt[2]; double weight = gp[i].weight; double detuvw = getJacobianDeterminant(u, v, w); - sum += interpolate(val, u, v, w, stride, order)*weight*detuvw; + sum += interpolate(val, u, v, w, stride, order) * weight * detuvw; } return sum; } double MElement::integrateCirc(double val[], int edge, int pOrder, int order) { - if(edge > getNumEdges() - 1){ + if(edge > getNumEdges() - 1) { Msg::Error("No edge %d for this element", edge); return 0; } - std::vector<MVertex*> v; + std::vector<MVertex *> v; getEdgeVertices(edge, v); MElementFactory f; int type = ElementType::getType(TYPE_LIN, getPolynomialOrder()); - MElement* ee = f.create(type, v); + MElement *ee = f.create(type, v); double intv[3]; - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { intv[i] = ee->integrate(&val[i], pOrder, 3, order); } delete ee; - double t[3] = {v[1]->x() - v[0]->x(), v[1]->y() - v[0]->y(), v[1]->z() - v[0]->z()}; + double t[3] = {v[1]->x() - v[0]->x(), v[1]->y() - v[0]->y(), + v[1]->z() - v[0]->z()}; norme(t); return prosca(t, intv); @@ -1254,43 +1304,46 @@ double MElement::integrateCirc(double val[], int edge, int pOrder, int order) double MElement::integrateFlux(double val[], int face, int pOrder, int order) { - if(face > getNumFaces() - 1){ + if(face > getNumFaces() - 1) { Msg::Error("No face %d for this element", face); return 0; } - std::vector<MVertex*> v; + std::vector<MVertex *> v; getFaceVertices(face, v); MElementFactory f; int type = 0; switch(getType()) { - case TYPE_TRI : - case TYPE_TET : - case TYPE_QUA : - case TYPE_HEX : - type = ElementType::getType(getType(), getPolynomialOrder()); - break; - case TYPE_PYR : - if(face < 4) type = ElementType::getType(TYPE_TRI, getPolynomialOrder()); - else type = ElementType::getType(TYPE_QUA, getPolynomialOrder()); - break; - case TYPE_PRI : - if(face < 2) type = ElementType::getType(TYPE_TRI, getPolynomialOrder()); - else type = ElementType::getType(TYPE_QUA, getPolynomialOrder()); - break; - default: type = 0; break; - } - MElement* fe = f.create(type, v); + case TYPE_TRI: + case TYPE_TET: + case TYPE_QUA: + case TYPE_HEX: + type = ElementType::getType(getType(), getPolynomialOrder()); + break; + case TYPE_PYR: + if(face < 4) + type = ElementType::getType(TYPE_TRI, getPolynomialOrder()); + else + type = ElementType::getType(TYPE_QUA, getPolynomialOrder()); + break; + case TYPE_PRI: + if(face < 2) + type = ElementType::getType(TYPE_TRI, getPolynomialOrder()); + else + type = ElementType::getType(TYPE_QUA, getPolynomialOrder()); + break; + default: type = 0; break; + } + MElement *fe = f.create(type, v); double intv[3]; - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { intv[i] = fe->integrate(&val[i], pOrder, 3, order); } delete fe; double n[3]; - normal3points(v[0]->x(), v[0]->y(), v[0]->z(), - v[1]->x(), v[1]->y(), v[1]->z(), - v[2]->x(), v[2]->y(), v[2]->z(), n); + normal3points(v[0]->x(), v[0]->y(), v[0]->z(), v[1]->x(), v[1]->y(), + v[1]->z(), v[2]->x(), v[2]->y(), v[2]->z(), n); return prosca(n, intv); } @@ -1309,28 +1362,26 @@ void MElement::writeMSH(FILE *fp, bool binary, int entity, // should move this also into each element base class std::vector<int> data; data.insert(data.end(), verts.begin(), verts.end()); - if(getParent()) - data.push_back(getParent()->getNum()); - if(getPartition()){ - if(ghosts){ + if(getParent()) data.push_back(getParent()->getNum()); + if(getPartition()) { + if(ghosts) { data.push_back(1 + ghosts->size()); data.push_back(getPartition()); data.insert(data.end(), ghosts->begin(), ghosts->end()); } - else{ + else { data.push_back(1); data.push_back(getPartition()); } } int numData = data.size(); - if(!binary){ + if(!binary) { fprintf(fp, "%d %d %d %d", num, type, entity, numData); - for(int i = 0; i < numData; i++) - fprintf(fp, " %d", data[i]); + for(int i = 0; i < numData; i++) fprintf(fp, " %d", data[i]); fprintf(fp, "\n"); } - else{ + else { fwrite(&num, sizeof(int), 1, fp); fwrite(&type, sizeof(int), 1, fp); fwrite(&entity, sizeof(int), 1, fp); @@ -1353,23 +1404,26 @@ void MElement::writeMSH2(FILE *fp, double version, bool binary, int num, bool poly = (type == MSH_POLYG_ || type == MSH_POLYH_ || type == MSH_POLYG_B); // if polygon loop over children (triangles and tets) - if(CTX::instance()->mesh.saveTri){ - if(poly){ - for (int i = 0; i < getNumChildren() ; i++){ - MElement *t = getChild(i); - t->writeMSH2(fp, version, binary, num++, elementary, physical, 0, 0, 0, ghosts); + if(CTX::instance()->mesh.saveTri) { + if(poly) { + for(int i = 0; i < getNumChildren(); i++) { + MElement *t = getChild(i); + t->writeMSH2(fp, version, binary, num++, elementary, physical, 0, 0, 0, + ghosts); } return; } - if(type == MSH_TRI_B){ + if(type == MSH_TRI_B) { MTriangle *t = new MTriangle(getVertex(0), getVertex(1), getVertex(2)); - t->writeMSH2(fp, version, binary, num++, elementary, physical, 0, 0, 0, ghosts); + t->writeMSH2(fp, version, binary, num++, elementary, physical, 0, 0, 0, + ghosts); delete t; return; } - if(type == MSH_LIN_B || type == MSH_LIN_C){ + if(type == MSH_LIN_B || type == MSH_LIN_C) { MLine *l = new MLine(getVertex(0), getVertex(1)); - l->writeMSH2(fp, version, binary, num++, elementary, physical, 0, 0, 0, ghosts); + l->writeMSH2(fp, version, binary, num++, elementary, physical, 0, 0, 0, + ghosts); delete l; return; } @@ -1377,35 +1431,35 @@ void MElement::writeMSH2(FILE *fp, double version, bool binary, int num, if(CTX::instance()->mesh.preserveNumberingMsh2) num = _num; - if(!binary){ + if(!binary) { fprintf(fp, "%d %d", num ? num : _num, type); if(version < 2.0) fprintf(fp, " %d %d %d", abs(physical), elementary, n); - else if (version < 2.2) + else if(version < 2.2) fprintf(fp, " %d %d %d", abs(physical), elementary, _partition); else if(!_partition && !par && !dom) fprintf(fp, " %d %d %d", 2 + par + dom, abs(physical), elementary); else if(!ghosts) - fprintf(fp, " %d %d %d 1 %d", 4 + par + dom, abs(physical), elementary, _partition); - else{ + fprintf(fp, " %d %d %d 1 %d", 4 + par + dom, abs(physical), elementary, + _partition); + else { int numGhosts = ghosts->size(); fprintf(fp, " %d %d %d %d %d", 4 + numGhosts + par + dom, abs(physical), elementary, 1 + numGhosts, _partition); for(unsigned int i = 0; i < ghosts->size(); i++) fprintf(fp, " %d", -(*ghosts)[i]); } - if(version >= 2.0 && par) - fprintf(fp, " %d", parentNum); - if(version >= 2.0 && dom) - fprintf(fp, " %d %d", dom1Num, dom2Num); - if(version >= 2.0 && poly) - fprintf(fp, " %d", n); + if(version >= 2.0 && par) fprintf(fp, " %d", parentNum); + if(version >= 2.0 && dom) fprintf(fp, " %d %d", dom1Num, dom2Num); + if(version >= 2.0 && poly) fprintf(fp, " %d", n); } - else{ + else { int numTags, numGhosts = 0; - if(!_partition) numTags = 2; - else if(!ghosts) numTags = 4; - else{ + if(!_partition) + numTags = 2; + else if(!ghosts) + numTags = 4; + else { numGhosts = ghosts->size(); numTags = 4 + numGhosts; } @@ -1415,8 +1469,8 @@ void MElement::writeMSH2(FILE *fp, double version, bool binary, int num, // tags change from element to element (third-party codes can // still write MSH file optimized for reading speed, by grouping // elements with the same number of tags in blobs) - int blob[60] = {type, 1, numTags, num ? num : _num, abs(physical), elementary, - 1 + numGhosts, _partition}; + int blob[60] = {type, 1, numTags, num ? num : _num, + abs(physical), elementary, 1 + numGhosts, _partition}; if(ghosts) for(int i = 0; i < numGhosts; i++) blob[8 + i] = -(*ghosts)[i]; if(par) blob[8 + numGhosts] = parentNum; @@ -1429,12 +1483,11 @@ void MElement::writeMSH2(FILE *fp, double version, bool binary, int num, std::vector<int> verts; getVerticesIdForMSH(verts); - if(!binary){ - for(int i = 0; i < n; i++) - fprintf(fp, " %d", verts[i]); + if(!binary) { + for(int i = 0; i < n; i++) fprintf(fp, " %d", verts[i]); fprintf(fp, "\n"); } - else{ + else { fwrite(&verts[0], sizeof(int), n, fp); } @@ -1443,20 +1496,20 @@ void MElement::writeMSH2(FILE *fp, double version, bool binary, int num, void MElement::writeMSH4(FILE *fp, bool binary) { - std::vector<MVertex*> verts; + std::vector<MVertex *> verts; getVertices(verts); - if(binary){ //Implemented but not used in practice + if(binary) { // Implemented but not used in practice fwrite(&_num, sizeof(int), 1, fp); - for(unsigned int i = 0; i < verts.size(); i++){ + for(unsigned int i = 0; i < verts.size(); i++) { int vertNum = verts[i]->getNum(); fwrite(&vertNum, sizeof(int), 1, fp); } } - else{ + else { fprintf(fp, "%d ", _num); - for(unsigned int i = 0; i < verts.size(); i++){ - fprintf(fp, "%d ", verts[i]->getNum()); + for(unsigned int i = 0; i < verts.size(); i++) { + fprintf(fp, "%d ", verts[i]->getNum()); } fprintf(fp, "\n"); } @@ -1471,51 +1524,70 @@ void MElement::writePOS(FILE *fp, bool printElementary, bool printElementNumber, int n = getNumVertices(); fprintf(fp, "%s(", str); - for(int i = 0; i < n; i++){ + for(int i = 0; i < n; i++) { if(i) fprintf(fp, ","); fprintf(fp, "%g,%g,%g", getVertex(i)->x() * scalingFactor, - getVertex(i)->y() * scalingFactor, getVertex(i)->z() * scalingFactor); + getVertex(i)->y() * scalingFactor, + getVertex(i)->z() * scalingFactor); } fprintf(fp, "){"); bool first = true; - if(printElementary){ - for(int i = 0; i < n; i++){ - if(first) first = false; else fprintf(fp, ","); + if(printElementary) { + for(int i = 0; i < n; i++) { + if(first) + first = false; + else + fprintf(fp, ","); fprintf(fp, "%d", elementary); } } - if(printElementNumber){ - for(int i = 0; i < n; i++){ - if(first) first = false; else fprintf(fp, ","); + if(printElementNumber) { + for(int i = 0; i < n; i++) { + if(first) + first = false; + else + fprintf(fp, ","); fprintf(fp, "%d", getNum()); } } - if(printSICN){ + if(printSICN) { double sICNMin = minSICNShapeMeasure(); - for(int i = 0; i < n; i++){ - if(first) first = false; else fprintf(fp, ","); + for(int i = 0; i < n; i++) { + if(first) + first = false; + else + fprintf(fp, ","); fprintf(fp, "%g", sICNMin); } } - if(printSIGE){ + if(printSIGE) { double sIGEMin = minSIGEShapeMeasure(); - for(int i = 0; i < n; i++){ - if(first) first = false; else fprintf(fp, ","); + for(int i = 0; i < n; i++) { + if(first) + first = false; + else + fprintf(fp, ","); fprintf(fp, "%g", sIGEMin); } } - if(printGamma){ + if(printGamma) { double gamma = gammaShapeMeasure(); - for(int i = 0; i < n; i++){ - if(first) first = false; else fprintf(fp, ","); + for(int i = 0; i < n; i++) { + if(first) + first = false; + else + fprintf(fp, ","); fprintf(fp, "%g", gamma); - //fprintf(fp, "%d", getVertex(i)->getNum()); + // fprintf(fp, "%d", getVertex(i)->getNum()); } } - if(printDisto){ + if(printDisto) { double disto = distoShapeMeasure(); - for(int i = 0; i < n; i++){ - if(first) first = false; else fprintf(fp, ","); + for(int i = 0; i < n; i++) { + if(first) + first = false; + else + fprintf(fp, ","); fprintf(fp, "%g", disto); } } @@ -1527,17 +1599,16 @@ void MElement::writeSTL(FILE *fp, bool binary, double scalingFactor) if(getType() != TYPE_TRI && getType() != TYPE_QUA) return; int qid[3] = {0, 2, 3}; SVector3 n = getFace(0).normal(); - if(!binary){ + if(!binary) { fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]); fprintf(fp, " outer loop\n"); for(int j = 0; j < 3; j++) - fprintf(fp, " vertex %g %g %g\n", - getVertex(j)->x() * scalingFactor, + fprintf(fp, " vertex %g %g %g\n", getVertex(j)->x() * scalingFactor, getVertex(j)->y() * scalingFactor, getVertex(j)->z() * scalingFactor); fprintf(fp, " endloop\n"); fprintf(fp, "endfacet\n"); - if(getNumVertices() == 4){ + if(getNumVertices() == 4) { fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]); fprintf(fp, " outer loop\n"); for(int j = 0; j < 3; j++) @@ -1549,21 +1620,21 @@ void MElement::writeSTL(FILE *fp, bool binary, double scalingFactor) fprintf(fp, "endfacet\n"); } } - else{ + else { char data[50]; - float *coords = (float*)data; + float *coords = (float *)data; coords[0] = (float)n[0]; coords[1] = (float)n[1]; coords[2] = (float)n[2]; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { coords[3 + 3 * j] = (float)(getVertex(j)->x() * scalingFactor); coords[3 + 3 * j + 1] = (float)(getVertex(j)->y() * scalingFactor); coords[3 + 3 * j + 2] = (float)(getVertex(j)->z() * scalingFactor); } data[48] = data[49] = 0; fwrite(data, sizeof(char), 50, fp); - if(getNumVertices() == 4){ - for(int j = 0; j < 3; j++){ + if(getNumVertices() == 4) { + for(int j = 0; j < 3; j++) { coords[3 + 3 * j] = (float)(getVertex(qid[j])->x() * scalingFactor); coords[3 + 3 * j + 1] = (float)(getVertex(qid[j])->y() * scalingFactor); coords[3 + 3 * j + 2] = (float)(getVertex(qid[j])->z() * scalingFactor); @@ -1606,16 +1677,15 @@ void MElement::writeVTK(FILE *fp, bool binary, bool bigEndian) if(!getTypeForVTK()) return; int n = getNumVertices(); - if(binary){ + if(binary) { int verts[60]; verts[0] = n; - for(int i = 0; i < n; i++) - verts[i + 1] = getVertexVTK(i)->getIndex() - 1; + for(int i = 0; i < n; i++) verts[i + 1] = getVertexVTK(i)->getIndex() - 1; // VTK always expects big endian binary data - if(!bigEndian) SwapBytes((char*)verts, sizeof(int), n + 1); + if(!bigEndian) SwapBytes((char *)verts, sizeof(int), n + 1); fwrite(verts, sizeof(int), n + 1, fp); } - else{ + else { fprintf(fp, "%d", n); for(int i = 0; i < n; i++) fprintf(fp, " %d", getVertexVTK(i)->getIndex() - 1); @@ -1623,42 +1693,43 @@ void MElement::writeVTK(FILE *fp, bool binary, bool bigEndian) } } -void MElement::writeMATLAB(FILE *fp, int filetype, int elementary, int physical, bool binary) +void MElement::writeMATLAB(FILE *fp, int filetype, int elementary, int physical, + bool binary) { - //Matlab use the same names as MSH + // Matlab use the same names as MSH if(!getTypeForMSH()) return; - if(binary){ - Msg::Warning("Binary format not available for Matlab, saving into ASCII format"); + if(binary) { + Msg::Warning( + "Binary format not available for Matlab, saving into ASCII format"); binary = false; } - //Simple version - if(filetype == 0) - { - int n = getNumVertices(); - for(int i = 0; i < n; i++) - fprintf(fp, " %d", getVertexMATLAB(i)->getIndex()); - fprintf(fp, ";\n"); - } - //same as load_gmsh2.m - if(filetype==1) - { - if(physical < 0) reverse(); + // Simple version + if(filetype == 0) { + int n = getNumVertices(); + for(int i = 0; i < n; i++) + fprintf(fp, " %d", getVertexMATLAB(i)->getIndex()); + fprintf(fp, ";\n"); + } + // same as load_gmsh2.m + if(filetype == 1) { + if(physical < 0) reverse(); - for(std::size_t i = 0; i < getNumVertices(); i++) - fprintf(fp, " %d", getVertex(i)->getIndex()); - fprintf(fp, " %d\n", physical ? abs(physical) : elementary); + for(std::size_t i = 0; i < getNumVertices(); i++) + fprintf(fp, " %d", getVertex(i)->getIndex()); + fprintf(fp, " %d\n", physical ? abs(physical) : elementary); - if(physical < 0) reverse(); - } + if(physical < 0) reverse(); + } } void MElement::writeUNV(FILE *fp, int num, int elementary, int physical) { int type = getTypeForUNV(); - if(!type){ + if(!type) { Msg::Warning("Unknown element type for UNV export (MSH type %d) - " - "output file might be invalid", getTypeForMSH()); + "output file might be invalid", + getTypeForMSH()); return; } @@ -1666,8 +1737,8 @@ void MElement::writeUNV(FILE *fp, int num, int elementary, int physical) int physical_property = elementary; int material_property = abs(physical); int color = 7; - fprintf(fp, "%10d%10d%10d%10d%10d%10d\n", - num ? num : _num, type, physical_property, material_property, color, n); + fprintf(fp, "%10d%10d%10d%10d%10d%10d\n", num ? num : _num, type, + physical_property, material_property, color, n); if(type == 21 || type == 24) // linear beam or parabolic beam fprintf(fp, "%10d%10d%10d\n", 0, 0, 0); @@ -1675,11 +1746,9 @@ void MElement::writeUNV(FILE *fp, int num, int elementary, int physical) for(int k = 0; k < n; k++) { fprintf(fp, "%10d", getVertexUNV(k)->getIndex()); - if(k % 8 == 7) - fprintf(fp, "\n"); + if(k % 8 == 7) fprintf(fp, "\n"); } - if(n - 1 % 8 != 7) - fprintf(fp, "\n"); + if(n - 1 % 8 != 7) fprintf(fp, "\n"); if(physical < 0) reverse(); } @@ -1690,14 +1759,16 @@ void MElement::writeMESH(FILE *fp, int elementTagType, int elementary, if(physical < 0) reverse(); for(std::size_t i = 0; i < getNumVertices(); i++) - if (getTypeForMSH() == MSH_TET_10 && i == 8) + if(getTypeForMSH() == MSH_TET_10 && i == 8) fprintf(fp, " %d", getVertex(9)->getIndex()); - else if (getTypeForMSH() == MSH_TET_10 && i == 9) + else if(getTypeForMSH() == MSH_TET_10 && i == 9) fprintf(fp, " %d", getVertex(8)->getIndex()); else fprintf(fp, " %d", getVertex(i)->getIndex()); - fprintf(fp, " %d\n", (elementTagType == 3) ? _partition : - (elementTagType == 2) ? abs(physical) : elementary); + fprintf(fp, " %d\n", + (elementTagType == 3) ? + _partition : + (elementTagType == 2) ? abs(physical) : elementary); if(physical < 0) reverse(); } @@ -1706,7 +1777,7 @@ void MElement::writeNEU(FILE *fp, unsigned gambitType, int idAdjust, int phys) { if(phys < 0) reverse(); - fprintf(fp, "%8d %2d %2lu ", _num-idAdjust, gambitType, getNumVertices()); + fprintf(fp, "%8d %2d %2lu ", _num - idAdjust, gambitType, getNumVertices()); for(std::size_t i = 0; i < getNumVertices(); ++i) { fprintf(fp, "%8d", getVertex(i)->getIndex()); } @@ -1721,17 +1792,19 @@ void MElement::writeIR3(FILE *fp, int elementTagType, int num, int elementary, if(physical < 0) reverse(); int numVert = getNumVertices(); - fprintf(fp, "%d %d %d", num, (elementTagType == 3) ? _partition : - (elementTagType == 2) ? abs(physical) : elementary, numVert); - for(int i = 0; i < numVert; i++) - fprintf(fp, " %d", getVertex(i)->getIndex()); + fprintf(fp, "%d %d %d", num, + (elementTagType == 3) ? + _partition : + (elementTagType == 2) ? abs(physical) : elementary, + numVert); + for(int i = 0; i < numVert; i++) fprintf(fp, " %d", getVertex(i)->getIndex()); fprintf(fp, "\n"); if(physical < 0) reverse(); } -void MElement::writeBDF(FILE *fp, int format, int elementTagType, int elementary, - int physical) +void MElement::writeBDF(FILE *fp, int format, int elementTagType, + int elementary, int physical) { const char *str = getStringForBDF(); if(!str) return; @@ -1742,14 +1815,15 @@ void MElement::writeBDF(FILE *fp, int format, int elementTagType, int elementary if(physical < 0) reverse(); - int tag = (elementTagType == 3) ? _partition : (elementTagType == 2) ? - abs(physical) : elementary; + int tag = (elementTagType == 3) ? + _partition : + (elementTagType == 2) ? abs(physical) : elementary; - if(format == 0){ // free field format + if(format == 0) { // free field format fprintf(fp, "%s,%d,%d", str, _num, tag); - for(int i = 0; i < n; i++){ + for(int i = 0; i < n; i++) { fprintf(fp, ",%d", getVertexBDF(i)->getIndex()); - if(i != n - 1 && !((i + 3) % 8)){ + if(i != n - 1 && !((i + 3) % 8)) { fprintf(fp, ",+%s%d\n+%s%d", cont[ncont], _num, cont[ncont], _num); ncont++; } @@ -1758,11 +1832,11 @@ void MElement::writeBDF(FILE *fp, int format, int elementTagType, int elementary fprintf(fp, ",0.,0.,0."); fprintf(fp, "\n"); } - else{ // small or large field format + else { // small or large field format fprintf(fp, "%-8s%-8d%-8d", str, _num, tag); - for(int i = 0; i < n; i++){ + for(int i = 0; i < n; i++) { fprintf(fp, "%-8d", getVertexBDF(i)->getIndex()); - if(i != n - 1 && !((i + 3) % 8)){ + if(i != n - 1 && !((i + 3) % 8)) { fprintf(fp, "+%s%-6d\n+%s%-6d", cont[ncont], _num, cont[ncont], _num); ncont++; } @@ -1783,13 +1857,12 @@ void MElement::writeDIFF(FILE *fp, int num, bool binary, int physical) if(physical < 0) reverse(); int n = getNumVertices(); - if(binary){ + if(binary) { // TODO } - else{ + else { fprintf(fp, "%d %s %d ", num, str, abs(physical)); - for(int i = 0; i < n; i++) - fprintf(fp, " %d", getVertexDIFF(i)->getIndex()); + for(int i = 0; i < n; i++) fprintf(fp, " %d", getVertexDIFF(i)->getIndex()); fprintf(fp, "\n"); } @@ -1800,11 +1873,11 @@ void MElement::writeINP(FILE *fp, int num) { fprintf(fp, "%d, ", num); int n = getNumVertices(); - for(int i = 0; i < n; i++){ + for(int i = 0; i < n; i++) { fprintf(fp, "%d", getVertexINP(i)->getIndex()); - if(i != n - 1){ + if(i != n - 1) { fprintf(fp, ", "); - if(i && !((i+2) % 16)) fprintf(fp, "\n"); + if(i && !((i + 2) % 16)) fprintf(fp, "\n"); } } fprintf(fp, "\n"); @@ -1816,43 +1889,42 @@ void MElement::writeKEY(FILE *fp, int pid, int num) int n = getNumVertices(); int nid[64]; int i; - for(i = 0; i < n; i++) - nid[i]=getVertexKEY(i)->getIndex(); - if(getDim()==3){ - if(n==4){ /* tet4, repeating n4 */ - nid[7]=nid[6]=nid[5]=nid[4]=nid[3]; + for(i = 0; i < n; i++) nid[i] = getVertexKEY(i)->getIndex(); + if(getDim() == 3) { + if(n == 4) { /* tet4, repeating n4 */ + nid[7] = nid[6] = nid[5] = nid[4] = nid[3]; } - else if(n==6){ /* penta6, n8=n7 & n4=n3 */ - nid[7]=nid[6]=nid[5]; - nid[5]=nid[4]; + else if(n == 6) { /* penta6, n8=n7 & n4=n3 */ + nid[7] = nid[6] = nid[5]; + nid[5] = nid[4]; } - if(n<8)n=8; + if(n < 8) n = 8; } - else if(getDim()==2){ - if(n==3){ /* 3-node shell */ - nid[3]=nid[2]; + else if(getDim() == 2) { + if(n == 3) { /* 3-node shell */ + nid[3] = nid[2]; n++; } - else if(n==6){ /* 6-node shell */ - nid[7]=nid[6]=nid[5]; - nid[5]=nid[4]; - nid[4]=nid[3]; - nid[3]=nid[2]; - n=8; + else if(n == 6) { /* 6-node shell */ + nid[7] = nid[6] = nid[5]; + nid[5] = nid[4]; + nid[4] = nid[3]; + nid[3] = nid[2]; + n = 8; } } - else if(getDim()==1){ - if(n==3){ /* elbow, write the third node on the next line */ - nid[8]=nid[2]; - for(i=2;i<8;i++)nid[i]=0; - n=9; + else if(getDim() == 1) { + if(n == 3) { /* elbow, write the third node on the next line */ + nid[8] = nid[2]; + for(i = 2; i < 8; i++) nid[i] = 0; + n = 9; } } - for(i = 0; i < n; i++){ + for(i = 0; i < n; i++) { fprintf(fp, "%d", nid[i]); - if(i != n - 1){ + if(i != n - 1) { fprintf(fp, ", "); - if(!((i+2) % 10)) fprintf(fp, "\n"); + if(!((i + 2) % 10)) fprintf(fp, "\n"); } } fprintf(fp, "\n"); @@ -1863,148 +1935,420 @@ void MElement::writeSU2(FILE *fp, int num) fprintf(fp, "%d ", getTypeForVTK()); for(std::size_t i = 0; i < getNumVertices(); i++) fprintf(fp, "%d ", getVertexVTK(i)->getIndex() - 1); - if(num >= 0) fprintf(fp, "%d\n", num); - else fprintf(fp, "\n"); + if(num >= 0) + fprintf(fp, "%d\n", num); + else + fprintf(fp, "\n"); } unsigned int MElement::getInfoMSH(const int typeMSH, const char **const name) { - switch(typeMSH){ - case MSH_PNT : if(name) *name = "Point"; return 1; - case MSH_LIN_1 : if(name) *name = "Line 1"; return 1; - case MSH_LIN_2 : if(name) *name = "Line 2"; return 2; - case MSH_LIN_3 : if(name) *name = "Line 3"; return 2 + 1; - case MSH_LIN_4 : if(name) *name = "Line 4"; return 2 + 2; - case MSH_LIN_5 : if(name) *name = "Line 5"; return 2 + 3; - case MSH_LIN_6 : if(name) *name = "Line 6"; return 2 + 4; - case MSH_LIN_7 : if(name) *name = "Line 7"; return 2 + 5; - case MSH_LIN_8 : if(name) *name = "Line 8"; return 2 + 6; - case MSH_LIN_9 : if(name) *name = "Line 9"; return 2 + 7; - case MSH_LIN_10 : if(name) *name = "Line 10"; return 2 + 8; - case MSH_LIN_11 : if(name) *name = "Line 11"; return 2 + 9; - case MSH_LIN_B : if(name) *name = "Line Border"; return 2; - case MSH_LIN_C : if(name) *name = "Line Child"; return 2; - case MSH_TRI_1 : if(name) *name = "Triangle 1"; return 1; - case MSH_TRI_3 : if(name) *name = "Triangle 3"; return 3; - case MSH_TRI_6 : if(name) *name = "Triangle 6"; return 3 + 3; - case MSH_TRI_9 : if(name) *name = "Triangle 9"; return 3 + 6; - case MSH_TRI_10 : if(name) *name = "Triangle 10"; return 3 + 6 + 1; - case MSH_TRI_12 : if(name) *name = "Triangle 12"; return 3 + 9; - case MSH_TRI_15 : if(name) *name = "Triangle 15"; return 3 + 9 + 3; - case MSH_TRI_15I : if(name) *name = "Triangle 15I"; return 3 + 12; - case MSH_TRI_21 : if(name) *name = "Triangle 21"; return 3 + 12 + 6; - case MSH_TRI_28 : if(name) *name = "Triangle 28"; return 3 + 15 + 10; - case MSH_TRI_36 : if(name) *name = "Triangle 36"; return 3 + 18 + 15; - case MSH_TRI_45 : if(name) *name = "Triangle 45"; return 3 + 21 + 21; - case MSH_TRI_55 : if(name) *name = "Triangle 55"; return 3 + 24 + 28; - case MSH_TRI_66 : if(name) *name = "Triangle 66"; return 3 + 27 + 36; - case MSH_TRI_18 : if(name) *name = "Triangle 18"; return 3 + 15; - case MSH_TRI_21I : if(name) *name = "Triangle 21I"; return 3 + 18; - case MSH_TRI_24 : if(name) *name = "Triangle 24"; return 3 + 21; - case MSH_TRI_27 : if(name) *name = "Triangle 27"; return 3 + 24; - case MSH_TRI_30 : if(name) *name = "Triangle 30"; return 3 + 27; - case MSH_TRI_B : if(name) *name = "Triangle Border"; return 3; - case MSH_QUA_1 : if(name) *name = "Quadrilateral 1"; return 1; - case MSH_QUA_4 : if(name) *name = "Quadrilateral 4"; return 4; - case MSH_QUA_8 : if(name) *name = "Quadrilateral 8"; return 4 + 4; - case MSH_QUA_9 : if(name) *name = "Quadrilateral 9"; return 9; - case MSH_QUA_16 : if(name) *name = "Quadrilateral 16"; return 16; - case MSH_QUA_25 : if(name) *name = "Quadrilateral 25"; return 25; - case MSH_QUA_36 : if(name) *name = "Quadrilateral 36"; return 36; - case MSH_QUA_49 : if(name) *name = "Quadrilateral 49"; return 49; - case MSH_QUA_64 : if(name) *name = "Quadrilateral 64"; return 64; - case MSH_QUA_81 : if(name) *name = "Quadrilateral 81"; return 81; - case MSH_QUA_100 : if(name) *name = "Quadrilateral 100";return 100; - case MSH_QUA_121 : if(name) *name = "Quadrilateral 121";return 121; - case MSH_QUA_12 : if(name) *name = "Quadrilateral 12"; return 12; - case MSH_QUA_16I : if(name) *name = "Quadrilateral 16I";return 16; - case MSH_QUA_20 : if(name) *name = "Quadrilateral 20"; return 20; - case MSH_QUA_24 : if(name) *name = "Quadrilateral 24"; return 24; - case MSH_QUA_28 : if(name) *name = "Quadrilateral 28"; return 28; - case MSH_QUA_32 : if(name) *name = "Quadrilateral 32"; return 32; - case MSH_QUA_36I : if(name) *name = "Quadrilateral 36I";return 36; - case MSH_QUA_40 : if(name) *name = "Quadrilateral 40"; return 40; - case MSH_POLYG_ : if(name) *name = "Polygon"; return 0; - case MSH_POLYG_B : if(name) *name = "Polygon Border"; return 0; - case MSH_TET_1 : if(name) *name = "Tetrahedron 1"; return 1; - case MSH_TET_4 : if(name) *name = "Tetrahedron 4"; return 4; - case MSH_TET_10 : if(name) *name = "Tetrahedron 10"; return 4 + 6; - case MSH_TET_20 : if(name) *name = "Tetrahedron 20"; return 4 + 12 + 4; - case MSH_TET_35 : if(name) *name = "Tetrahedron 35"; return 4 + 18 + 12 + 1; - case MSH_TET_56 : if(name) *name = "Tetrahedron 56"; return 4 + 24 + 24 + 4; - case MSH_TET_84 : if(name) *name = "Tetrahedron 84"; return (7*8*9)/6; - case MSH_TET_120 : if(name) *name = "Tetrahedron 120"; return (8*9*10)/6; - case MSH_TET_165 : if(name) *name = "Tetrahedron 165"; return (9*10*11)/6; - case MSH_TET_220 : if(name) *name = "Tetrahedron 220"; return (10*11*12)/6; - case MSH_TET_286 : if(name) *name = "Tetrahedron 286"; return (11*12*13)/6; - case MSH_TET_16 : if(name) *name = "Tetrahedron 16"; return 4 + 6*2; - case MSH_TET_22 : if(name) *name = "Tetrahedron 22"; return 4 + 6*3; - case MSH_TET_28 : if(name) *name = "Tetrahedron 28"; return 4 + 6*4; - case MSH_TET_34 : if(name) *name = "Tetrahedron 34"; return 4 + 6*5; - case MSH_TET_40 : if(name) *name = "Tetrahedron 40"; return 4 + 6*6; - case MSH_TET_46 : if(name) *name = "Tetrahedron 46"; return 4 + 6*7; - case MSH_TET_52 : if(name) *name = "Tetrahedron 52"; return 4 + 6*8; - case MSH_TET_58 : if(name) *name = "Tetrahedron 58"; return 4 + 6*9; - case MSH_HEX_1 : if(name) *name = "Hexahedron 1"; return 1; - case MSH_HEX_8 : if(name) *name = "Hexahedron 8"; return 8; - case MSH_HEX_20 : if(name) *name = "Hexahedron 20"; return 8 + 12; - case MSH_HEX_27 : if(name) *name = "Hexahedron 27"; return 8 + 12 + 6 + 1; - case MSH_HEX_64 : if(name) *name = "Hexahedron 64"; return 64; - case MSH_HEX_125 : if(name) *name = "Hexahedron 125"; return 125; - case MSH_HEX_216 : if(name) *name = "Hexahedron 216"; return 216; - case MSH_HEX_343 : if(name) *name = "Hexahedron 343"; return 343; - case MSH_HEX_512 : if(name) *name = "Hexahedron 512"; return 512; - case MSH_HEX_729 : if(name) *name = "Hexahedron 729"; return 729; - case MSH_HEX_1000: if(name) *name = "Hexahedron 1000"; return 1000; - case MSH_HEX_32 : if(name) *name = "Hexahedron 32"; return 8 + 12*2; - case MSH_HEX_44 : if(name) *name = "Hexahedron 44"; return 8 + 12*3; - case MSH_HEX_56 : if(name) *name = "Hexahedron 56"; return 8 + 12*4; - case MSH_HEX_68 : if(name) *name = "Hexahedron 68"; return 8 + 12*5; - case MSH_HEX_80 : if(name) *name = "Hexahedron 80"; return 8 + 12*6; - case MSH_HEX_92 : if(name) *name = "Hexahedron 92"; return 8 + 12*7; - case MSH_HEX_104 : if(name) *name = "Hexahedron 104"; return 8 + 12*8; - case MSH_PRI_1 : if(name) *name = "Prism 1"; return 1; - case MSH_PRI_6 : if(name) *name = "Prism 6"; return 6; - case MSH_PRI_15 : if(name) *name = "Prism 15"; return 6 + 9; - case MSH_PRI_18 : if(name) *name = "Prism 18"; return 6 + 9 + 3; - case MSH_PRI_40 : if(name) *name = "Prism 40"; return 6 + 18 + 12+2 + 2*1; - case MSH_PRI_75 : if(name) *name = "Prism 75"; return 6 + 27 + 27+6 + 3*3; - case MSH_PRI_126 : if(name) *name = "Prism 126"; return 6 + 36 + 48+12 + 4*6; - case MSH_PRI_196 : if(name) *name = "Prism 196"; return 6 + 45 + 75+20 + 5*10; - case MSH_PRI_288 : if(name) *name = "Prism 288"; return 6 + 54 + 108+30 + 6*15; - case MSH_PRI_405 : if(name) *name = "Prism 405"; return 6 + 63 + 147+42 + 7*21; - case MSH_PRI_550 : if(name) *name = "Prism 550"; return 6 + 72 + 192+56 + 8*28; - case MSH_PRI_24 : if(name) *name = "Prism 24"; return 6 + 9*2; - case MSH_PRI_33 : if(name) *name = "Prism 33"; return 6 + 9*3; - case MSH_PRI_42 : if(name) *name = "Prism 42"; return 6 + 9*4; - case MSH_PRI_51 : if(name) *name = "Prism 51"; return 6 + 9*5; - case MSH_PRI_60 : if(name) *name = "Prism 60"; return 6 + 9*6; - case MSH_PRI_69 : if(name) *name = "Prism 69"; return 6 + 9*7; - case MSH_PRI_78 : if(name) *name = "Prism 78"; return 6 + 9*8; - case MSH_PYR_1 : if(name) *name = "Pyramid 1"; return 1; - case MSH_PYR_5 : if(name) *name = "Pyramid 5"; return 5; - case MSH_PYR_13 : if(name) *name = "Pyramid 13"; return 5 + 8; - case MSH_PYR_14 : if(name) *name = "Pyramid 14"; return 5 + 8 + 1; - case MSH_PYR_30 : if(name) *name = "Pyramid 30"; return 5 + 8*2 + 4*1 + 1*4 + 1; - case MSH_PYR_55 : if(name) *name = "Pyramid 55"; return 5 + 8*3 + 4*3 + 1*9 + 5; - case MSH_PYR_91 : if(name) *name = "Pyramid 91"; return 5 + 8*4 + 4*6 + 1*16 + 14; - case MSH_PYR_140 : if(name) *name = "Pyramid 140"; return 5 + 8*5 + 4*10 + 1*25 + 30; - case MSH_PYR_204 : if(name) *name = "Pyramid 204"; return 5 + 8*6 + 4*15 + 1*36 + 55; - case MSH_PYR_285 : if(name) *name = "Pyramid 285"; return 5 + 8*7 + 4*21 + 1*49 + 91; - case MSH_PYR_385 : if(name) *name = "Pyramid 385"; return 5 + 8*8 + 4*28 + 1*64 + 140; - case MSH_PYR_21 : if(name) *name = "Pyramid 21"; return 5 + 8*2; - case MSH_PYR_29 : if(name) *name = "Pyramid 29"; return 5 + 8*3; - case MSH_PYR_37 : if(name) *name = "Pyramid 37"; return 5 + 8*4; - case MSH_PYR_45 : if(name) *name = "Pyramid 45"; return 5 + 8*5; - case MSH_PYR_53 : if(name) *name = "Pyramid 53"; return 5 + 8*6; - case MSH_PYR_61 : if(name) *name = "Pyramid 61"; return 5 + 8*7; - case MSH_PYR_69 : if(name) *name = "Pyramid 69"; return 5 + 8*8; - case MSH_TRIH_4 : if(name) *name = "Trihedron 4"; return 4; - case MSH_POLYH_ : if(name) *name = "Polyhedron"; return 0; - case MSH_PNT_SUB : if(name) *name = "Point Xfem"; return 1; - case MSH_LIN_SUB : if(name) *name = "Line Xfem"; return 2; - case MSH_TRI_SUB : if(name) *name = "Triangle Xfem"; return 3; - case MSH_TET_SUB : if(name) *name = "Tetrahedron Xfem"; return 4; + switch(typeMSH) { + case MSH_PNT: + if(name) *name = "Point"; + return 1; + case MSH_LIN_1: + if(name) *name = "Line 1"; + return 1; + case MSH_LIN_2: + if(name) *name = "Line 2"; + return 2; + case MSH_LIN_3: + if(name) *name = "Line 3"; + return 2 + 1; + case MSH_LIN_4: + if(name) *name = "Line 4"; + return 2 + 2; + case MSH_LIN_5: + if(name) *name = "Line 5"; + return 2 + 3; + case MSH_LIN_6: + if(name) *name = "Line 6"; + return 2 + 4; + case MSH_LIN_7: + if(name) *name = "Line 7"; + return 2 + 5; + case MSH_LIN_8: + if(name) *name = "Line 8"; + return 2 + 6; + case MSH_LIN_9: + if(name) *name = "Line 9"; + return 2 + 7; + case MSH_LIN_10: + if(name) *name = "Line 10"; + return 2 + 8; + case MSH_LIN_11: + if(name) *name = "Line 11"; + return 2 + 9; + case MSH_LIN_B: + if(name) *name = "Line Border"; + return 2; + case MSH_LIN_C: + if(name) *name = "Line Child"; + return 2; + case MSH_TRI_1: + if(name) *name = "Triangle 1"; + return 1; + case MSH_TRI_3: + if(name) *name = "Triangle 3"; + return 3; + case MSH_TRI_6: + if(name) *name = "Triangle 6"; + return 3 + 3; + case MSH_TRI_9: + if(name) *name = "Triangle 9"; + return 3 + 6; + case MSH_TRI_10: + if(name) *name = "Triangle 10"; + return 3 + 6 + 1; + case MSH_TRI_12: + if(name) *name = "Triangle 12"; + return 3 + 9; + case MSH_TRI_15: + if(name) *name = "Triangle 15"; + return 3 + 9 + 3; + case MSH_TRI_15I: + if(name) *name = "Triangle 15I"; + return 3 + 12; + case MSH_TRI_21: + if(name) *name = "Triangle 21"; + return 3 + 12 + 6; + case MSH_TRI_28: + if(name) *name = "Triangle 28"; + return 3 + 15 + 10; + case MSH_TRI_36: + if(name) *name = "Triangle 36"; + return 3 + 18 + 15; + case MSH_TRI_45: + if(name) *name = "Triangle 45"; + return 3 + 21 + 21; + case MSH_TRI_55: + if(name) *name = "Triangle 55"; + return 3 + 24 + 28; + case MSH_TRI_66: + if(name) *name = "Triangle 66"; + return 3 + 27 + 36; + case MSH_TRI_18: + if(name) *name = "Triangle 18"; + return 3 + 15; + case MSH_TRI_21I: + if(name) *name = "Triangle 21I"; + return 3 + 18; + case MSH_TRI_24: + if(name) *name = "Triangle 24"; + return 3 + 21; + case MSH_TRI_27: + if(name) *name = "Triangle 27"; + return 3 + 24; + case MSH_TRI_30: + if(name) *name = "Triangle 30"; + return 3 + 27; + case MSH_TRI_B: + if(name) *name = "Triangle Border"; + return 3; + case MSH_QUA_1: + if(name) *name = "Quadrilateral 1"; + return 1; + case MSH_QUA_4: + if(name) *name = "Quadrilateral 4"; + return 4; + case MSH_QUA_8: + if(name) *name = "Quadrilateral 8"; + return 4 + 4; + case MSH_QUA_9: + if(name) *name = "Quadrilateral 9"; + return 9; + case MSH_QUA_16: + if(name) *name = "Quadrilateral 16"; + return 16; + case MSH_QUA_25: + if(name) *name = "Quadrilateral 25"; + return 25; + case MSH_QUA_36: + if(name) *name = "Quadrilateral 36"; + return 36; + case MSH_QUA_49: + if(name) *name = "Quadrilateral 49"; + return 49; + case MSH_QUA_64: + if(name) *name = "Quadrilateral 64"; + return 64; + case MSH_QUA_81: + if(name) *name = "Quadrilateral 81"; + return 81; + case MSH_QUA_100: + if(name) *name = "Quadrilateral 100"; + return 100; + case MSH_QUA_121: + if(name) *name = "Quadrilateral 121"; + return 121; + case MSH_QUA_12: + if(name) *name = "Quadrilateral 12"; + return 12; + case MSH_QUA_16I: + if(name) *name = "Quadrilateral 16I"; + return 16; + case MSH_QUA_20: + if(name) *name = "Quadrilateral 20"; + return 20; + case MSH_QUA_24: + if(name) *name = "Quadrilateral 24"; + return 24; + case MSH_QUA_28: + if(name) *name = "Quadrilateral 28"; + return 28; + case MSH_QUA_32: + if(name) *name = "Quadrilateral 32"; + return 32; + case MSH_QUA_36I: + if(name) *name = "Quadrilateral 36I"; + return 36; + case MSH_QUA_40: + if(name) *name = "Quadrilateral 40"; + return 40; + case MSH_POLYG_: + if(name) *name = "Polygon"; + return 0; + case MSH_POLYG_B: + if(name) *name = "Polygon Border"; + return 0; + case MSH_TET_1: + if(name) *name = "Tetrahedron 1"; + return 1; + case MSH_TET_4: + if(name) *name = "Tetrahedron 4"; + return 4; + case MSH_TET_10: + if(name) *name = "Tetrahedron 10"; + return 4 + 6; + case MSH_TET_20: + if(name) *name = "Tetrahedron 20"; + return 4 + 12 + 4; + case MSH_TET_35: + if(name) *name = "Tetrahedron 35"; + return 4 + 18 + 12 + 1; + case MSH_TET_56: + if(name) *name = "Tetrahedron 56"; + return 4 + 24 + 24 + 4; + case MSH_TET_84: + if(name) *name = "Tetrahedron 84"; + return (7 * 8 * 9) / 6; + case MSH_TET_120: + if(name) *name = "Tetrahedron 120"; + return (8 * 9 * 10) / 6; + case MSH_TET_165: + if(name) *name = "Tetrahedron 165"; + return (9 * 10 * 11) / 6; + case MSH_TET_220: + if(name) *name = "Tetrahedron 220"; + return (10 * 11 * 12) / 6; + case MSH_TET_286: + if(name) *name = "Tetrahedron 286"; + return (11 * 12 * 13) / 6; + case MSH_TET_16: + if(name) *name = "Tetrahedron 16"; + return 4 + 6 * 2; + case MSH_TET_22: + if(name) *name = "Tetrahedron 22"; + return 4 + 6 * 3; + case MSH_TET_28: + if(name) *name = "Tetrahedron 28"; + return 4 + 6 * 4; + case MSH_TET_34: + if(name) *name = "Tetrahedron 34"; + return 4 + 6 * 5; + case MSH_TET_40: + if(name) *name = "Tetrahedron 40"; + return 4 + 6 * 6; + case MSH_TET_46: + if(name) *name = "Tetrahedron 46"; + return 4 + 6 * 7; + case MSH_TET_52: + if(name) *name = "Tetrahedron 52"; + return 4 + 6 * 8; + case MSH_TET_58: + if(name) *name = "Tetrahedron 58"; + return 4 + 6 * 9; + case MSH_HEX_1: + if(name) *name = "Hexahedron 1"; + return 1; + case MSH_HEX_8: + if(name) *name = "Hexahedron 8"; + return 8; + case MSH_HEX_20: + if(name) *name = "Hexahedron 20"; + return 8 + 12; + case MSH_HEX_27: + if(name) *name = "Hexahedron 27"; + return 8 + 12 + 6 + 1; + case MSH_HEX_64: + if(name) *name = "Hexahedron 64"; + return 64; + case MSH_HEX_125: + if(name) *name = "Hexahedron 125"; + return 125; + case MSH_HEX_216: + if(name) *name = "Hexahedron 216"; + return 216; + case MSH_HEX_343: + if(name) *name = "Hexahedron 343"; + return 343; + case MSH_HEX_512: + if(name) *name = "Hexahedron 512"; + return 512; + case MSH_HEX_729: + if(name) *name = "Hexahedron 729"; + return 729; + case MSH_HEX_1000: + if(name) *name = "Hexahedron 1000"; + return 1000; + case MSH_HEX_32: + if(name) *name = "Hexahedron 32"; + return 8 + 12 * 2; + case MSH_HEX_44: + if(name) *name = "Hexahedron 44"; + return 8 + 12 * 3; + case MSH_HEX_56: + if(name) *name = "Hexahedron 56"; + return 8 + 12 * 4; + case MSH_HEX_68: + if(name) *name = "Hexahedron 68"; + return 8 + 12 * 5; + case MSH_HEX_80: + if(name) *name = "Hexahedron 80"; + return 8 + 12 * 6; + case MSH_HEX_92: + if(name) *name = "Hexahedron 92"; + return 8 + 12 * 7; + case MSH_HEX_104: + if(name) *name = "Hexahedron 104"; + return 8 + 12 * 8; + case MSH_PRI_1: + if(name) *name = "Prism 1"; + return 1; + case MSH_PRI_6: + if(name) *name = "Prism 6"; + return 6; + case MSH_PRI_15: + if(name) *name = "Prism 15"; + return 6 + 9; + case MSH_PRI_18: + if(name) *name = "Prism 18"; + return 6 + 9 + 3; + case MSH_PRI_40: + if(name) *name = "Prism 40"; + return 6 + 18 + 12 + 2 + 2 * 1; + case MSH_PRI_75: + if(name) *name = "Prism 75"; + return 6 + 27 + 27 + 6 + 3 * 3; + case MSH_PRI_126: + if(name) *name = "Prism 126"; + return 6 + 36 + 48 + 12 + 4 * 6; + case MSH_PRI_196: + if(name) *name = "Prism 196"; + return 6 + 45 + 75 + 20 + 5 * 10; + case MSH_PRI_288: + if(name) *name = "Prism 288"; + return 6 + 54 + 108 + 30 + 6 * 15; + case MSH_PRI_405: + if(name) *name = "Prism 405"; + return 6 + 63 + 147 + 42 + 7 * 21; + case MSH_PRI_550: + if(name) *name = "Prism 550"; + return 6 + 72 + 192 + 56 + 8 * 28; + case MSH_PRI_24: + if(name) *name = "Prism 24"; + return 6 + 9 * 2; + case MSH_PRI_33: + if(name) *name = "Prism 33"; + return 6 + 9 * 3; + case MSH_PRI_42: + if(name) *name = "Prism 42"; + return 6 + 9 * 4; + case MSH_PRI_51: + if(name) *name = "Prism 51"; + return 6 + 9 * 5; + case MSH_PRI_60: + if(name) *name = "Prism 60"; + return 6 + 9 * 6; + case MSH_PRI_69: + if(name) *name = "Prism 69"; + return 6 + 9 * 7; + case MSH_PRI_78: + if(name) *name = "Prism 78"; + return 6 + 9 * 8; + case MSH_PYR_1: + if(name) *name = "Pyramid 1"; + return 1; + case MSH_PYR_5: + if(name) *name = "Pyramid 5"; + return 5; + case MSH_PYR_13: + if(name) *name = "Pyramid 13"; + return 5 + 8; + case MSH_PYR_14: + if(name) *name = "Pyramid 14"; + return 5 + 8 + 1; + case MSH_PYR_30: + if(name) *name = "Pyramid 30"; + return 5 + 8 * 2 + 4 * 1 + 1 * 4 + 1; + case MSH_PYR_55: + if(name) *name = "Pyramid 55"; + return 5 + 8 * 3 + 4 * 3 + 1 * 9 + 5; + case MSH_PYR_91: + if(name) *name = "Pyramid 91"; + return 5 + 8 * 4 + 4 * 6 + 1 * 16 + 14; + case MSH_PYR_140: + if(name) *name = "Pyramid 140"; + return 5 + 8 * 5 + 4 * 10 + 1 * 25 + 30; + case MSH_PYR_204: + if(name) *name = "Pyramid 204"; + return 5 + 8 * 6 + 4 * 15 + 1 * 36 + 55; + case MSH_PYR_285: + if(name) *name = "Pyramid 285"; + return 5 + 8 * 7 + 4 * 21 + 1 * 49 + 91; + case MSH_PYR_385: + if(name) *name = "Pyramid 385"; + return 5 + 8 * 8 + 4 * 28 + 1 * 64 + 140; + case MSH_PYR_21: + if(name) *name = "Pyramid 21"; + return 5 + 8 * 2; + case MSH_PYR_29: + if(name) *name = "Pyramid 29"; + return 5 + 8 * 3; + case MSH_PYR_37: + if(name) *name = "Pyramid 37"; + return 5 + 8 * 4; + case MSH_PYR_45: + if(name) *name = "Pyramid 45"; + return 5 + 8 * 5; + case MSH_PYR_53: + if(name) *name = "Pyramid 53"; + return 5 + 8 * 6; + case MSH_PYR_61: + if(name) *name = "Pyramid 61"; + return 5 + 8 * 7; + case MSH_PYR_69: + if(name) *name = "Pyramid 69"; + return 5 + 8 * 8; + case MSH_TRIH_4: + if(name) *name = "Trihedron 4"; + return 4; + case MSH_POLYH_: + if(name) *name = "Polyhedron"; + return 0; + case MSH_PNT_SUB: + if(name) *name = "Point Xfem"; + return 1; + case MSH_LIN_SUB: + if(name) *name = "Line Xfem"; + return 2; + case MSH_TRI_SUB: + if(name) *name = "Triangle Xfem"; + return 3; + case MSH_TET_SUB: + if(name) *name = "Tetrahedron Xfem"; + return 4; default: Msg::Error("Unknown type of element %d", typeMSH); if(name) *name = "Unknown"; @@ -2016,23 +2360,21 @@ void MElement::getVerticesIdForMSH(std::vector<int> &verts) { int n = getNumVerticesForMSH(); verts.resize(n); - for(int i = 0; i < n; i++) - verts[i] = getVertex(i)->getIndex(); + for(int i = 0; i < n; i++) verts[i] = getVertex(i)->getIndex(); } -MElement *MElement::copy(std::map<int, MVertex*> &vertexMap, - std::map<MElement*, MElement*> &newParents, - std::map<MElement*, MElement*> &newDomains) +MElement *MElement::copy(std::map<int, MVertex *> &vertexMap, + std::map<MElement *, MElement *> &newParents, + std::map<MElement *, MElement *> &newDomains) { - if(newDomains.count(this)) - return newDomains.find(this)->second; - std::vector<MVertex*> vmv; + if(newDomains.count(this)) return newDomains.find(this)->second; + std::vector<MVertex *> vmv; int eType = getTypeForMSH(); MElement *eParent = getParent(); if(getNumChildren() == 0) { for(std::size_t i = 0; i < getNumVertices(); i++) { MVertex *v = getVertex(i); - int numV = v->getNum(); //Index(); + int numV = v->getNum(); // Index(); if(vertexMap.count(numV)) vmv.push_back(vertexMap[numV]); else { @@ -2046,7 +2388,7 @@ MElement *MElement::copy(std::map<int, MVertex*> &vertexMap, for(int i = 0; i < getNumChildren(); i++) { for(std::size_t j = 0; j < getChild(i)->getNumVertices(); j++) { MVertex *v = getChild(i)->getVertex(j); - int numV = v->getNum(); //Index(); + int numV = v->getNum(); // Index(); if(vertexMap.count(numV)) vmv.push_back(vertexMap[numV]); else { @@ -2058,9 +2400,9 @@ MElement *MElement::copy(std::map<int, MVertex*> &vertexMap, } } - MElement *parent=0; + MElement *parent = 0; if(eParent && !getDomain(0) && !getDomain(1)) { - std::map<MElement*, MElement*>::iterator it = newParents.find(eParent); + std::map<MElement *, MElement *>::iterator it = newParents.find(eParent); MElement *newParent; if(it == newParents.end()) { newParent = eParent->copy(vertexMap, newParents, newDomains); @@ -2072,12 +2414,13 @@ MElement *MElement::copy(std::map<int, MVertex*> &vertexMap, } MElementFactory f; - MElement *newEl = f.create(eType, vmv, getNum(), _partition, ownsParent(), 0, parent); + MElement *newEl = + f.create(eType, vmv, getNum(), _partition, ownsParent(), 0, parent); for(int i = 0; i < 2; i++) { MElement *dom = getDomain(i); if(!dom) continue; - std::map<MElement*, MElement*>::iterator it = newDomains.find(dom); + std::map<MElement *, MElement *>::iterator it = newDomains.find(dom); MElement *newDom; if(it == newDomains.end()) { newDom = dom->copy(vertexMap, newParents, newDomains); @@ -2090,164 +2433,168 @@ MElement *MElement::copy(std::map<int, MVertex*> &vertexMap, return newEl; } -MElement *MElementFactory::create(int type, std::vector<MVertex*> &v, - int num, int part, bool owner, - int parent, MElement* parent_ptr, - MElement *d1, MElement *d2) -{ - switch (type) { - case MSH_PNT: return new MPoint(v, num, part); - case MSH_LIN_2: return new MLine(v, num, part); - case MSH_LIN_3: return new MLine3(v, num, part); - case MSH_LIN_4: return new MLineN(v, num, part); - case MSH_LIN_5: return new MLineN(v, num, part); - case MSH_LIN_6: return new MLineN(v, num, part); - case MSH_LIN_7: return new MLineN(v, num, part); - case MSH_LIN_8: return new MLineN(v, num, part); - case MSH_LIN_9: return new MLineN(v, num, part); - case MSH_LIN_10: return new MLineN(v, num, part); - case MSH_LIN_11: return new MLineN(v, num, part); - case MSH_LIN_B: return new MLineBorder(v, num, part, d1, d2); - case MSH_LIN_C: return new MLineChild(v, num, part, owner, parent_ptr); - case MSH_TRI_3: return new MTriangle(v, num, part); - case MSH_TRI_6: return new MTriangle6(v, num, part); - case MSH_TRI_10: return new MTriangleN(v, 3, num, part); - case MSH_TRI_15: return new MTriangleN(v, 4, num, part); - case MSH_TRI_21: return new MTriangleN(v, 5, num, part); - case MSH_TRI_28: return new MTriangleN(v, 6, num, part); - case MSH_TRI_36: return new MTriangleN(v, 7, num, part); - case MSH_TRI_45: return new MTriangleN(v, 8, num, part); - case MSH_TRI_55: return new MTriangleN(v, 9, num, part); - case MSH_TRI_66: return new MTriangleN(v,10, num, part); - case MSH_TRI_9: return new MTriangleN(v, 3, num, part); - case MSH_TRI_12: return new MTriangleN(v, 4, num, part); +MElement *MElementFactory::create(int type, std::vector<MVertex *> &v, int num, + int part, bool owner, int parent, + MElement *parent_ptr, MElement *d1, + MElement *d2) +{ + switch(type) { + case MSH_PNT: return new MPoint(v, num, part); + case MSH_LIN_2: return new MLine(v, num, part); + case MSH_LIN_3: return new MLine3(v, num, part); + case MSH_LIN_4: return new MLineN(v, num, part); + case MSH_LIN_5: return new MLineN(v, num, part); + case MSH_LIN_6: return new MLineN(v, num, part); + case MSH_LIN_7: return new MLineN(v, num, part); + case MSH_LIN_8: return new MLineN(v, num, part); + case MSH_LIN_9: return new MLineN(v, num, part); + case MSH_LIN_10: return new MLineN(v, num, part); + case MSH_LIN_11: return new MLineN(v, num, part); + case MSH_LIN_B: return new MLineBorder(v, num, part, d1, d2); + case MSH_LIN_C: return new MLineChild(v, num, part, owner, parent_ptr); + case MSH_TRI_3: return new MTriangle(v, num, part); + case MSH_TRI_6: return new MTriangle6(v, num, part); + case MSH_TRI_10: return new MTriangleN(v, 3, num, part); + case MSH_TRI_15: return new MTriangleN(v, 4, num, part); + case MSH_TRI_21: return new MTriangleN(v, 5, num, part); + case MSH_TRI_28: return new MTriangleN(v, 6, num, part); + case MSH_TRI_36: return new MTriangleN(v, 7, num, part); + case MSH_TRI_45: return new MTriangleN(v, 8, num, part); + case MSH_TRI_55: return new MTriangleN(v, 9, num, part); + case MSH_TRI_66: return new MTriangleN(v, 10, num, part); + case MSH_TRI_9: return new MTriangleN(v, 3, num, part); + case MSH_TRI_12: return new MTriangleN(v, 4, num, part); case MSH_TRI_15I: return new MTriangleN(v, 5, num, part); - case MSH_TRI_18: return new MTriangleN(v, 6, num, part); + case MSH_TRI_18: return new MTriangleN(v, 6, num, part); case MSH_TRI_21I: return new MTriangleN(v, 7, num, part); - case MSH_TRI_24: return new MTriangleN(v, 8, num, part); - case MSH_TRI_27: return new MTriangleN(v, 9, num, part); - case MSH_TRI_30: return new MTriangleN(v,10, num, part); - case MSH_TRI_B: return new MTriangleBorder(v, num, part, d1, d2); - case MSH_QUA_4: return new MQuadrangle(v, num, part); - case MSH_QUA_9: return new MQuadrangle9(v, num, part); - case MSH_QUA_16: return new MQuadrangleN(v, 3, num, part); - case MSH_QUA_25: return new MQuadrangleN(v, 4, num, part); - case MSH_QUA_36: return new MQuadrangleN(v, 5, num, part); - case MSH_QUA_49: return new MQuadrangleN(v, 6, num, part); - case MSH_QUA_64: return new MQuadrangleN(v, 7, num, part); - case MSH_QUA_81: return new MQuadrangleN(v, 8, num, part); + case MSH_TRI_24: return new MTriangleN(v, 8, num, part); + case MSH_TRI_27: return new MTriangleN(v, 9, num, part); + case MSH_TRI_30: return new MTriangleN(v, 10, num, part); + case MSH_TRI_B: return new MTriangleBorder(v, num, part, d1, d2); + case MSH_QUA_4: return new MQuadrangle(v, num, part); + case MSH_QUA_9: return new MQuadrangle9(v, num, part); + case MSH_QUA_16: return new MQuadrangleN(v, 3, num, part); + case MSH_QUA_25: return new MQuadrangleN(v, 4, num, part); + case MSH_QUA_36: return new MQuadrangleN(v, 5, num, part); + case MSH_QUA_49: return new MQuadrangleN(v, 6, num, part); + case MSH_QUA_64: return new MQuadrangleN(v, 7, num, part); + case MSH_QUA_81: return new MQuadrangleN(v, 8, num, part); case MSH_QUA_100: return new MQuadrangleN(v, 9, num, part); case MSH_QUA_121: return new MQuadrangleN(v, 10, num, part); - case MSH_QUA_8: return new MQuadrangle8(v, num, part); - case MSH_QUA_12: return new MQuadrangleN(v, 3, num, part); + case MSH_QUA_8: return new MQuadrangle8(v, num, part); + case MSH_QUA_12: return new MQuadrangleN(v, 3, num, part); case MSH_QUA_16I: return new MQuadrangleN(v, 4, num, part); - case MSH_QUA_20: return new MQuadrangleN(v, 5, num, part); - case MSH_QUA_24: return new MQuadrangleN(v, 6, num, part); - case MSH_QUA_28: return new MQuadrangleN(v, 7, num, part); - case MSH_QUA_32: return new MQuadrangleN(v, 8, num, part); + case MSH_QUA_20: return new MQuadrangleN(v, 5, num, part); + case MSH_QUA_24: return new MQuadrangleN(v, 6, num, part); + case MSH_QUA_28: return new MQuadrangleN(v, 7, num, part); + case MSH_QUA_32: return new MQuadrangleN(v, 8, num, part); case MSH_QUA_36I: return new MQuadrangleN(v, 9, num, part); - case MSH_QUA_40: return new MQuadrangleN(v,10, num, part); - case MSH_POLYG_: return new MPolygon(v, num, part, owner, parent_ptr); + case MSH_QUA_40: return new MQuadrangleN(v, 10, num, part); + case MSH_POLYG_: return new MPolygon(v, num, part, owner, parent_ptr); case MSH_POLYG_B: return new MPolygonBorder(v, num, part, d1, d2); - case MSH_TET_4: return new MTetrahedron(v, num, part); - case MSH_TET_10: return new MTetrahedron10(v, num, part); - case MSH_HEX_8: return new MHexahedron(v, num, part); - case MSH_HEX_20: return new MHexahedron20(v, num, part); - case MSH_HEX_27: return new MHexahedron27(v, num, part); - case MSH_PRI_6: return new MPrism(v, num, part); - case MSH_PRI_15: return new MPrism15(v, num, part); - case MSH_PRI_18: return new MPrism18(v, num, part); - case MSH_PRI_40: return new MPrismN(v, 3, num, part); - case MSH_PRI_75: return new MPrismN(v, 4, num, part); + case MSH_TET_4: return new MTetrahedron(v, num, part); + case MSH_TET_10: return new MTetrahedron10(v, num, part); + case MSH_HEX_8: return new MHexahedron(v, num, part); + case MSH_HEX_20: return new MHexahedron20(v, num, part); + case MSH_HEX_27: return new MHexahedron27(v, num, part); + case MSH_PRI_6: return new MPrism(v, num, part); + case MSH_PRI_15: return new MPrism15(v, num, part); + case MSH_PRI_18: return new MPrism18(v, num, part); + case MSH_PRI_40: return new MPrismN(v, 3, num, part); + case MSH_PRI_75: return new MPrismN(v, 4, num, part); case MSH_PRI_126: return new MPrismN(v, 5, num, part); case MSH_PRI_196: return new MPrismN(v, 6, num, part); case MSH_PRI_288: return new MPrismN(v, 7, num, part); case MSH_PRI_405: return new MPrismN(v, 8, num, part); case MSH_PRI_550: return new MPrismN(v, 9, num, part); - case MSH_PRI_24: return new MPrismN(v, 3, num, part); - case MSH_PRI_33: return new MPrismN(v, 4, num, part); - case MSH_PRI_42: return new MPrismN(v, 5, num, part); - case MSH_PRI_51: return new MPrismN(v, 6, num, part); - case MSH_PRI_60: return new MPrismN(v, 7, num, part); - case MSH_PRI_69: return new MPrismN(v, 8, num, part); - case MSH_PRI_78: return new MPrismN(v, 9, num, part); - case MSH_PRI_1: return new MPrismN(v, 0, num, part); - case MSH_TET_20: return new MTetrahedronN(v, 3, num, part); - case MSH_TET_35: return new MTetrahedronN(v, 4, num, part); - case MSH_TET_56: return new MTetrahedronN(v, 5, num, part); - case MSH_TET_84: return new MTetrahedronN(v, 6, num, part); + case MSH_PRI_24: return new MPrismN(v, 3, num, part); + case MSH_PRI_33: return new MPrismN(v, 4, num, part); + case MSH_PRI_42: return new MPrismN(v, 5, num, part); + case MSH_PRI_51: return new MPrismN(v, 6, num, part); + case MSH_PRI_60: return new MPrismN(v, 7, num, part); + case MSH_PRI_69: return new MPrismN(v, 8, num, part); + case MSH_PRI_78: return new MPrismN(v, 9, num, part); + case MSH_PRI_1: return new MPrismN(v, 0, num, part); + case MSH_TET_20: return new MTetrahedronN(v, 3, num, part); + case MSH_TET_35: return new MTetrahedronN(v, 4, num, part); + case MSH_TET_56: return new MTetrahedronN(v, 5, num, part); + case MSH_TET_84: return new MTetrahedronN(v, 6, num, part); case MSH_TET_120: return new MTetrahedronN(v, 7, num, part); case MSH_TET_165: return new MTetrahedronN(v, 8, num, part); case MSH_TET_220: return new MTetrahedronN(v, 9, num, part); case MSH_TET_286: return new MTetrahedronN(v, 10, num, part); - case MSH_TET_16: return new MTetrahedronN(v, 3, num, part); - case MSH_TET_22: return new MTetrahedronN(v, 4, num, part); - case MSH_TET_28: return new MTetrahedronN(v, 5, num, part); - case MSH_TET_34: return new MTetrahedronN(v, 6, num, part); - case MSH_TET_40: return new MTetrahedronN(v, 7, num, part); - case MSH_TET_46: return new MTetrahedronN(v, 8, num, part); - case MSH_TET_52: return new MTetrahedronN(v, 9, num, part); - case MSH_TET_58: return new MTetrahedronN(v, 10, num, part); - case MSH_POLYH_: return new MPolyhedron(v, num, part, owner, parent_ptr); - case MSH_HEX_32: return new MHexahedronN(v, 3, num, part); - case MSH_HEX_64: return new MHexahedronN(v, 3, num, part); + case MSH_TET_16: return new MTetrahedronN(v, 3, num, part); + case MSH_TET_22: return new MTetrahedronN(v, 4, num, part); + case MSH_TET_28: return new MTetrahedronN(v, 5, num, part); + case MSH_TET_34: return new MTetrahedronN(v, 6, num, part); + case MSH_TET_40: return new MTetrahedronN(v, 7, num, part); + case MSH_TET_46: return new MTetrahedronN(v, 8, num, part); + case MSH_TET_52: return new MTetrahedronN(v, 9, num, part); + case MSH_TET_58: return new MTetrahedronN(v, 10, num, part); + case MSH_POLYH_: return new MPolyhedron(v, num, part, owner, parent_ptr); + case MSH_HEX_32: return new MHexahedronN(v, 3, num, part); + case MSH_HEX_64: return new MHexahedronN(v, 3, num, part); case MSH_HEX_125: return new MHexahedronN(v, 4, num, part); case MSH_HEX_216: return new MHexahedronN(v, 5, num, part); case MSH_HEX_343: return new MHexahedronN(v, 6, num, part); case MSH_HEX_512: return new MHexahedronN(v, 7, num, part); case MSH_HEX_729: return new MHexahedronN(v, 8, num, part); - case MSH_HEX_1000:return new MHexahedronN(v, 9, num, part); - case MSH_PNT_SUB: return (parent_ptr) ? new MSubPoint(v, num, part, owner, parent_ptr) - : new MSubPoint(v, num, part, owner, parent); - case MSH_LIN_SUB: return (parent_ptr) ? new MSubLine(v, num, part, owner, parent_ptr) - : new MSubLine(v, num, part, owner, parent); - case MSH_TRI_SUB: return (parent_ptr) ? new MSubTriangle(v, num, part, owner, parent_ptr) - : new MSubTriangle(v, num, part, owner, parent); - case MSH_TET_SUB: return (parent_ptr) ? new MSubTetrahedron(v, num, part, owner, parent_ptr) - : new MSubTetrahedron(v, num, part, owner, parent); - case MSH_PYR_5: return new MPyramid(v, num, part); - case MSH_PYR_13: return new MPyramidN(v, 2, num, part); - case MSH_PYR_14: return new MPyramidN(v, 2, num, part); - case MSH_PYR_30: return new MPyramidN(v, 3, num, part); - case MSH_PYR_55: return new MPyramidN(v, 4, num, part); - case MSH_PYR_91: return new MPyramidN(v, 5, num, part); + case MSH_HEX_1000: return new MHexahedronN(v, 9, num, part); + case MSH_PNT_SUB: + return (parent_ptr) ? new MSubPoint(v, num, part, owner, parent_ptr) : + new MSubPoint(v, num, part, owner, parent); + case MSH_LIN_SUB: + return (parent_ptr) ? new MSubLine(v, num, part, owner, parent_ptr) : + new MSubLine(v, num, part, owner, parent); + case MSH_TRI_SUB: + return (parent_ptr) ? new MSubTriangle(v, num, part, owner, parent_ptr) : + new MSubTriangle(v, num, part, owner, parent); + case MSH_TET_SUB: + return (parent_ptr) ? new MSubTetrahedron(v, num, part, owner, parent_ptr) : + new MSubTetrahedron(v, num, part, owner, parent); + case MSH_PYR_5: return new MPyramid(v, num, part); + case MSH_PYR_13: return new MPyramidN(v, 2, num, part); + case MSH_PYR_14: return new MPyramidN(v, 2, num, part); + case MSH_PYR_30: return new MPyramidN(v, 3, num, part); + case MSH_PYR_55: return new MPyramidN(v, 4, num, part); + case MSH_PYR_91: return new MPyramidN(v, 5, num, part); case MSH_PYR_140: return new MPyramidN(v, 6, num, part); case MSH_PYR_204: return new MPyramidN(v, 7, num, part); case MSH_PYR_285: return new MPyramidN(v, 8, num, part); case MSH_PYR_385: return new MPyramidN(v, 9, num, part); case MSH_TRIH_4: return new MTrihedron(v, num, part); - default: return 0; + default: return 0; } } -MElement *MElementFactory::create(int num, int type, const std::vector<int> &data, - GModel *model) +MElement *MElementFactory::create(int num, int type, + const std::vector<int> &data, GModel *model) { // This should be rewritten: each element should register itself in a static // factory owned e.g. directly by MElement, and interpret its data by // itself. This would remove the ugly switch in the routine above. int numVertices = MElement::getInfoMSH(type), startVertices = 0; - if(data.size() && !numVertices){ + if(data.size() && !numVertices) { startVertices = 1; numVertices = data[0]; } - std::vector<MVertex*> vertices(numVertices); - if((int) data.size() > startVertices + numVertices - 1){ - for(int i = 0; i < numVertices; i++){ + std::vector<MVertex *> vertices(numVertices); + if((int)data.size() > startVertices + numVertices - 1) { + for(int i = 0; i < numVertices; i++) { int numVertex = data[startVertices + i]; MVertex *v = model->getMeshVertexByTag(numVertex); - if(v){ + if(v) { vertices[i] = v; } - else{ + else { Msg::Error("Unknown vertex %d in element %d", numVertex, num); return 0; } } } - else{ + else { Msg::Error("Missing data in element %d", num); return 0; } @@ -2255,17 +2602,18 @@ MElement *MElementFactory::create(int num, int type, const std::vector<int> &dat unsigned int part = 0; int startPartitions = startVertices + numVertices; - int parent = 0; - if((type == MSH_PNT_SUB || type == MSH_LIN_SUB || - type == MSH_TRI_SUB || type == MSH_TET_SUB)){ + int parent = 0; + if((type == MSH_PNT_SUB || type == MSH_LIN_SUB || type == MSH_TRI_SUB || + type == MSH_TET_SUB)) { parent = data[startPartitions]; startPartitions += 1; } std::vector<short> ghosts; - if((int) data.size() > startPartitions){ + if((int)data.size() > startPartitions) { int numPartitions = data[startPartitions]; - if(numPartitions > 0 && (int) data.size() > startPartitions + numPartitions - 1){ + if(numPartitions > 0 && + (int)data.size() > startPartitions + numPartitions - 1) { part = data[startPartitions + 1]; for(int i = 1; i < numPartitions; i++) ghosts.push_back(data[startPartitions + 1 + i]); @@ -2274,8 +2622,9 @@ MElement *MElementFactory::create(int num, int type, const std::vector<int> &dat MElement *element = create(type, vertices, num, part, false, parent); - for(unsigned int j = 0; j < ghosts.size(); j++){ - //model->getGhostCells().insert(std::pair<MElement*, short>(element, ghosts[j])); + for(unsigned int j = 0; j < ghosts.size(); j++) { + // model->getGhostCells().insert(std::pair<MElement*, short>(element, + // ghosts[j])); } if(part > model->getNumPartitions()) model->setNumPartitions(part); @@ -2285,15 +2634,16 @@ MElement *MElementFactory::create(int num, int type, const std::vector<int> &dat double MElement::skewness() { double minsk = 1.0; - for (int i = 0; i < getNumFaces(); i++){ + for(int i = 0; i < getNumFaces(); i++) { MFace f = getFace(i); - if (f.getNumVertices() == 3){ + if(f.getNumVertices() == 3) { // MTriangle t (f.getVertex(0),f.getVertex(1),f.getVertex(2)); // minsk = std::min(minsk, t.etaShapeMeasure ()); } - else if (f.getNumVertices() == 4){ - MQuadrangle q (f.getVertex(0),f.getVertex(1),f.getVertex(2),f.getVertex(3)); - minsk = std::min(minsk, q.etaShapeMeasure ()); + else if(f.getNumVertices() == 4) { + MQuadrangle q(f.getVertex(0), f.getVertex(1), f.getVertex(2), + f.getVertex(3)); + minsk = std::min(minsk, q.etaShapeMeasure()); } } return minsk; diff --git a/Geo/MElementCut.cpp b/Geo/MElementCut.cpp index 170354c90f270a0fab2eab41dc7d9c73db770ae2..32572306c05b815540519586585b13e99d6756aa 100644 --- a/Geo/MElementCut.cpp +++ b/Geo/MElementCut.cpp @@ -19,7 +19,8 @@ #include "Integration3D.h" #endif -//---------------------------------------- MPolyhedron ---------------------------- +//---------------------------------------- MPolyhedron +//---------------------------- void MPolyhedron::_init() { @@ -31,8 +32,7 @@ void MPolyhedron::_init() for(int j = 0; j < 4; j++) { int k; for(k = _faces.size() - 1; k >= 0; k--) - if(_parts[i]->getFace(j) == _faces[k]) - break; + if(_parts[i]->getFace(j) == _faces[k]) break; if(k < 0) _faces.push_back(_parts[i]->getFace(j)); else @@ -42,18 +42,14 @@ void MPolyhedron::_init() for(int j = 0; j < 6; j++) { int k; for(k = _edges.size() - 1; k >= 0; k--) - if(_parts[i]->getEdge(j) == _edges[k]) - break; - if(k < 0) - _edges.push_back(_parts[i]->getEdge(j)); + if(_parts[i]->getEdge(j) == _edges[k]) break; + if(k < 0) _edges.push_back(_parts[i]->getEdge(j)); } for(int j = 0; j < 4; j++) { int k; for(k = _vertices.size() - 1; k >= 0; k--) - if(_parts[i]->getVertex(j) == _vertices[k]) - break; - if(k < 0) - _vertices.push_back(_parts[i]->getVertex(j)); + if(_parts[i]->getVertex(j) == _vertices[k]) break; + if(k < 0) _vertices.push_back(_parts[i]->getVertex(j)); } } } @@ -63,18 +59,14 @@ void MPolyhedron::_init() for(int j = 0; j < 3; j++) { int k; for(k = _edges.size() - 1; k >= 0; k--) - if(_faces[i].getEdge(j) == _edges[k]) - break; - if(k < 0) - _edges.push_back(_faces[i].getEdge(j)); + if(_faces[i].getEdge(j) == _edges[k]) break; + if(k < 0) _edges.push_back(_faces[i].getEdge(j)); } for(int j = 0; j < 3; j++) { int k; for(k = _vertices.size() - 1; k >= 0; k--) - if(_faces[i].getVertex(j) == _vertices[k]) - break; - if(k < 0) - _vertices.push_back(_faces[i].getVertex(j)); + if(_faces[i].getVertex(j) == _vertices[k]) break; + if(k < 0) _vertices.push_back(_faces[i].getVertex(j)); } } } @@ -82,12 +74,11 @@ void MPolyhedron::_init() // innerVertices for(unsigned int i = 0; i < _parts.size(); i++) { for(int j = 0; j < 4; j++) { - if(std::find(_vertices.begin(), _vertices.end(), _parts[i]->getVertex(j)) == - _vertices.end()) + if(std::find(_vertices.begin(), _vertices.end(), + _parts[i]->getVertex(j)) == _vertices.end()) _innerVertices.push_back(_parts[i]->getVertex(j)); } } - } bool MPolyhedron::isInside(double u, double v, double w) const @@ -108,8 +99,7 @@ bool MPolyhedron::isInside(double u, double v, double w) const MTetrahedron t(&v0, &v1, &v2, &v3); double ksi[3]; t.xyz2uvw(uvw, ksi); - if(t.isInside(ksi[0], ksi[1], ksi[2])) - return true; + if(t.isInside(ksi[0], ksi[1], ksi[2])) return true; } return false; } @@ -117,7 +107,7 @@ bool MPolyhedron::isInside(double u, double v, double w) const void MPolyhedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { *npts = 0; - if(_intpt) delete [] _intpt; + if(_intpt) delete[] _intpt; if(!_orig) return; double jac[3][3]; _intpt = new IntPt[getNGQTetPts(pOrder) * _parts.size()]; @@ -138,11 +128,12 @@ void MPolyhedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) MVertex v3(uvw[3][0], uvw[3][1], uvw[3][2]); MTetrahedron tt(&v0, &v1, &v2, &v3); - for(int ip = 0; ip < nptsi; ip++){ + for(int ip = 0; ip < nptsi; ip++) { const double u = ptsi[ip].pt[0]; const double v = ptsi[ip].pt[1]; const double w = ptsi[ip].pt[2]; - SPoint3 p; tt.pnt(u, v, w, p); + SPoint3 p; + tt.pnt(u, v, w, p); _intpt[*npts + ip].pt[0] = p.x(); _intpt[*npts + ip].pt[1] = p.y(); _intpt[*npts + ip].pt[2] = p.z(); @@ -155,7 +146,8 @@ void MPolyhedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) *pts = _intpt; } -//------------------------------------------- MPolygon ------------------------------ +//------------------------------------------- MPolygon +//------------------------------ void MPolygon::_initVertices() { @@ -163,8 +155,10 @@ void MPolygon::_initVertices() // reorient the parts SVector3 n; - if(_orig) n = _orig->getFace(0).normal(); - else n = _parts[0]->getFace(0).normal(); + if(_orig) + n = _orig->getFace(0).normal(); + else + n = _parts[0]->getFace(0).normal(); for(unsigned int i = 0; i < _parts.size(); i++) { SVector3 ni = _parts[i]->getFace(0).normal(); if(dot(n, ni) < 0.) _parts[i]->reverse(); @@ -180,31 +174,36 @@ void MPolygon::_initVertices() bool found = false; MEdge ed = _parts[i]->getEdge(j); int k; - for(k = edg.size() - 1; k >= 0; k--){ - if(ed == edg[k]){ + for(k = edg.size() - 1; k >= 0; k--) { + if(ed == edg[k]) { edg.erase(edg.begin() + k); - found = true; break; + found = true; + break; } } - if(!found){ + if(!found) { for(k = 0; k < (int)multiEdges.size(); k++) if(multiEdges[k].isInside(ed.getVertex(0)) && - multiEdges[k].isInside(ed.getVertex(1))){ - found = true; break; + multiEdges[k].isInside(ed.getVertex(1))) { + found = true; + break; } } - if(!found){ - for(k = edg.size() - 1; k >= 0; k--){ - if(edg[k].isInside(ed.getVertex(0)) && edg[k].isInside(ed.getVertex(1))){ + if(!found) { + for(k = edg.size() - 1; k >= 0; k--) { + if(edg[k].isInside(ed.getVertex(0)) && + edg[k].isInside(ed.getVertex(1))) { multiEdges.push_back(edg[k]); edg.erase(edg.begin() + k); - found = true; break; + found = true; + break; } } } - if(!found){ - for(k = edg.size() - 1; k >= 0; k--){ - if(ed.isInside(edg[k].getVertex(0)) && ed.isInside(edg[k].getVertex(1))){ + if(!found) { + for(k = edg.size() - 1; k >= 0; k--) { + if(ed.isInside(edg[k].getVertex(0)) && + ed.isInside(edg[k].getVertex(1))) { edg.erase(edg.begin() + k); int nbME = multiEdges.size(); if(nbME == 0 || multiEdges[nbME - 1] != ed) @@ -213,8 +212,7 @@ void MPolygon::_initVertices() } } } - if(!found) - edg.push_back(ed); + if(!found) edg.push_back(ed); } } @@ -249,8 +247,8 @@ void MPolygon::_initVertices() // innerVertices for(unsigned int i = 0; i < _parts.size(); i++) { for(int j = 0; j < 3; j++) { - if(std::find(_vertices.begin(), _vertices.end(), _parts[i]->getVertex(j)) == - _vertices.end()) + if(std::find(_vertices.begin(), _vertices.end(), + _parts[i]->getVertex(j)) == _vertices.end()) _innerVertices.push_back(_parts[i]->getVertex(j)); } } @@ -273,8 +271,7 @@ bool MPolygon::isInside(double u, double v, double w) const MTriangle t(&v0, &v1, &v2); double ksi[3]; t.xyz2uvw(uvw, ksi); - if(t.isInside(ksi[0], ksi[1], ksi[2])) - return true; + if(t.isInside(ksi[0], ksi[1], ksi[2])) return true; } return false; } @@ -282,7 +279,7 @@ bool MPolygon::isInside(double u, double v, double w) const void MPolygon::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { *npts = 0; - if(_intpt) delete [] _intpt; + if(_intpt) delete[] _intpt; if(!getParent()) return; double jac[3][3]; _intpt = new IntPt[getNGQTPts(pOrder) * _parts.size()]; @@ -292,7 +289,8 @@ void MPolygon::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) _parts[i]->getIntegrationPoints(pOrder, &nptsi, &ptsi); double uvw[3][3]; for(int j = 0; j < 3; j++) { - double xyz[3] = {_parts[i]->getVertex(j)->x(), _parts[i]->getVertex(j)->y(), + double xyz[3] = {_parts[i]->getVertex(j)->x(), + _parts[i]->getVertex(j)->y(), _parts[i]->getVertex(j)->z()}; getParent()->xyz2uvw(xyz, uvw[j]); } @@ -300,11 +298,12 @@ void MPolygon::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) MVertex v1(uvw[1][0], uvw[1][1], uvw[1][2]); MVertex v2(uvw[2][0], uvw[2][1], uvw[2][2]); MTriangle tt(&v0, &v1, &v2); - for(int ip = 0; ip < nptsi; ip++){ + for(int ip = 0; ip < nptsi; ip++) { const double u = ptsi[ip].pt[0]; const double v = ptsi[ip].pt[1]; const double w = ptsi[ip].pt[2]; - SPoint3 p; tt.pnt(u, v, w, p); + SPoint3 p; + tt.pnt(u, v, w, p); _intpt[*npts + ip].pt[0] = p.x(); _intpt[*npts + ip].pt[1] = p.y(); _intpt[*npts + ip].pt[2] = p.z(); @@ -334,15 +333,14 @@ bool MLineChild::isInside(double u, double v, double w) const MLine l(&v0, &v1); double ksi[3]; l.xyz2uvw(uvw, ksi); - if(l.isInside(ksi[0], ksi[1], ksi[2])) - return true; + if(l.isInside(ksi[0], ksi[1], ksi[2])) return true; return false; } void MLineChild::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { *npts = 0; - if(_intpt) delete [] _intpt; + if(_intpt) delete[] _intpt; if(!_orig) return; _intpt = new IntPt[getNGQLPts(pOrder)]; int nptsi; @@ -357,11 +355,12 @@ void MLineChild::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) MVertex v1(v_uvw[1][0], v_uvw[1][1], v_uvw[1][2]); MLine l(&v0, &v1); l.getIntegrationPoints(pOrder, &nptsi, &ptsi); - for(int ip = 0; ip < nptsi; ip++){ + for(int ip = 0; ip < nptsi; ip++) { const double u = ptsi[ip].pt[0]; const double v = ptsi[ip].pt[1]; const double w = ptsi[ip].pt[2]; - SPoint3 p; l.pnt(u, v, w, p); + SPoint3 p; + l.pnt(u, v, w, p); _intpt[*npts + ip].pt[0] = p.x(); _intpt[*npts + ip].pt[1] = p.y(); _intpt[*npts + ip].pt[2] = p.z(); @@ -371,7 +370,8 @@ void MLineChild::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) *pts = _intpt; } -//----------------------------------- MTriangleBorder ------------------------------ +//----------------------------------- MTriangleBorder +//------------------------------ bool MTriangleBorder::isInside(double u, double v, double w) const { @@ -389,15 +389,14 @@ bool MTriangleBorder::isInside(double u, double v, double w) const MTriangle t(&v0, &v1, &v2); double ksi[3]; t.xyz2uvw(uvw, ksi); - if(t.isInside(ksi[0], ksi[1], ksi[2])) - return true; + if(t.isInside(ksi[0], ksi[1], ksi[2])) return true; return false; } void MTriangleBorder::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { *npts = 0; - if(_intpt) delete [] _intpt; + if(_intpt) delete[] _intpt; if(!getParent()) return; _intpt = new IntPt[getNGQTPts(pOrder)]; int nptsi; @@ -414,12 +413,13 @@ void MTriangleBorder::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) MTriangle tt(&v0, &v1, &v2); tt.getIntegrationPoints(pOrder, &nptsi, &ptsi); double jac[3][3]; - for(int ip = 0; ip < nptsi; ip++){ + for(int ip = 0; ip < nptsi; ip++) { const double u = ptsi[ip].pt[0]; const double v = ptsi[ip].pt[1]; const double w = ptsi[ip].pt[2]; tt.getJacobian(u, v, w, jac); - SPoint3 p; tt.pnt(u, v, w, p); + SPoint3 p; + tt.pnt(u, v, w, p); _intpt[ip].pt[0] = p.x(); _intpt[ip].pt[1] = p.y(); _intpt[ip].pt[2] = p.z(); @@ -429,7 +429,8 @@ void MTriangleBorder::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) *pts = _intpt; } -//-------------------------------------- MLineBorder ------------------------------ +//-------------------------------------- MLineBorder +//------------------------------ bool MLineBorder::isInside(double u, double v, double w) const { @@ -446,15 +447,14 @@ bool MLineBorder::isInside(double u, double v, double w) const MLine l(&v0, &v1); double ksi[3]; l.xyz2uvw(uvw, ksi); - if(l.isInside(ksi[0], ksi[1], ksi[2])) - return true; + if(l.isInside(ksi[0], ksi[1], ksi[2])) return true; return false; } void MLineBorder::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { *npts = 0; - if(_intpt) delete [] _intpt; + if(_intpt) delete[] _intpt; if(!getParent()) return; _intpt = new IntPt[getNGQLPts(pOrder)]; int nptsi; @@ -469,11 +469,12 @@ void MLineBorder::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) MVertex v1(uvw[1][0], uvw[1][1], uvw[1][2]); MLine ll(&v0, &v1); ll.getIntegrationPoints(pOrder, &nptsi, &ptsi); - for(int ip = 0; ip < nptsi; ip++){ + for(int ip = 0; ip < nptsi; ip++) { const double u = ptsi[ip].pt[0]; const double v = ptsi[ip].pt[1]; const double w = ptsi[ip].pt[2]; - SPoint3 p; ll.pnt(u, v, w, p); + SPoint3 p; + ll.pnt(u, v, w, p); _intpt[ip].pt[0] = p.x(); _intpt[ip].pt[1] = p.y(); _intpt[ip].pt[2] = p.z(); @@ -483,24 +484,28 @@ void MLineBorder::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) *pts = _intpt; } -//---------------------------------------- CutMesh ---------------------------- + //---------------------------------------- CutMesh + //---------------------------- #if defined(HAVE_DINTEGRATION) -static void assignPhysicals(GModel *GM, std::vector<int> &gePhysicals, int reg, int dim, - std::map<int, std::map<int, std::string> > physicals[4], - std::map<int, int> &newPhysTags, int lsTag) +static void +assignPhysicals(GModel *GM, std::vector<int> &gePhysicals, int reg, int dim, + std::map<int, std::map<int, std::string> > physicals[4], + std::map<int, int> &newPhysTags, int lsTag) { - for(unsigned int i = 0; i < gePhysicals.size(); i++){ + for(unsigned int i = 0; i < gePhysicals.size(); i++) { int phys = gePhysicals[i]; - if(lsTag > 0 && newPhysTags.count(phys)){ + if(lsTag > 0 && newPhysTags.count(phys)) { int phys2 = newPhysTags[phys]; - if(phys2 && (!physicals[dim].count(reg) || !physicals[dim][reg].count(phys2))){ + if(phys2 && + (!physicals[dim].count(reg) || !physicals[dim][reg].count(phys2))) { std::string name = GM->getPhysicalName(dim, phys); - if(name != "" && newPhysTags.count(-phys)){ - std::map<int, std::map<int, std::string> >::iterator it = physicals[dim].begin(); - for(; it != physicals[dim].end(); it++){ + if(name != "" && newPhysTags.count(-phys)) { + std::map<int, std::map<int, std::string> >::iterator it = + physicals[dim].begin(); + for(; it != physicals[dim].end(); it++) { std::map<int, std::string>::iterator it2 = it->second.begin(); for(; it2 != it->second.end(); it2++) if(it2->second == name) @@ -511,13 +516,15 @@ static void assignPhysicals(GModel *GM, std::vector<int> &gePhysicals, int reg, physicals[dim][reg][phys2] = name; } } - else if(lsTag < 0 && newPhysTags.count(-phys)){ + else if(lsTag < 0 && newPhysTags.count(-phys)) { int phys2 = newPhysTags[-phys]; - if(phys2 && (!physicals[dim].count(reg) || !physicals[dim][reg].count(phys2))){ + if(phys2 && + (!physicals[dim].count(reg) || !physicals[dim][reg].count(phys2))) { std::string name = GM->getPhysicalName(dim, phys); - if(name != "" && newPhysTags.count(phys)){ - std::map<int, std::map<int, std::string> >::iterator it = physicals[dim].begin(); - for(; it != physicals[dim].end(); it++){ + if(name != "" && newPhysTags.count(phys)) { + std::map<int, std::map<int, std::string> >::iterator it = + physicals[dim].begin(); + for(; it != physicals[dim].end(); it++) { std::map<int, std::string>::iterator it2 = it->second.begin(); for(; it2 != it->second.end(); it2++) if(it2->second == name) @@ -531,11 +538,12 @@ static void assignPhysicals(GModel *GM, std::vector<int> &gePhysicals, int reg, } } -static void assignLsPhysical(GModel *GM, int reg, int dim, - std::map<int, std::map<int, std::string> > physicals[4], - int physTag, int lsTag) +static void +assignLsPhysical(GModel *GM, int reg, int dim, + std::map<int, std::map<int, std::string> > physicals[4], + int physTag, int lsTag) { - if(!physicals[dim][reg].count(physTag)){ + if(!physicals[dim][reg].count(physTag)) { std::stringstream strs; strs << lsTag; std::string sdim = (dim == 2) ? "S" : "L"; @@ -545,12 +553,13 @@ static void assignLsPhysical(GModel *GM, int reg, int dim, } } -static int getElementaryTag(int lsTag, int elementary, std::map<int, int> &newElemTags) +static int getElementaryTag(int lsTag, int elementary, + std::map<int, int> &newElemTags) { - if(lsTag < 0){ + if(lsTag < 0) { if(newElemTags.count(elementary)) return newElemTags[elementary]; - else{ + else { int reg = ++newElemTags[0]; newElemTags[elementary] = reg; return reg; @@ -561,11 +570,10 @@ static int getElementaryTag(int lsTag, int elementary, std::map<int, int> &newEl static void getPhysicalTag(int lsTag, const std::vector<int> &physicals, std::map<int, int> &newPhysTags) { - for(unsigned int i = 0; i < physicals.size(); i++){ + for(unsigned int i = 0; i < physicals.size(); i++) { int phys = physicals[i]; - if(lsTag < 0){ - if(!newPhysTags.count(-phys)) - newPhysTags[-phys] = ++newPhysTags[0]; + if(lsTag < 0) { + if(!newPhysTags.count(-phys)) newPhysTags[-phys] = ++newPhysTags[0]; phys = newPhysTags[-phys]; } else if(!newPhysTags.count(phys)) @@ -573,10 +581,10 @@ static void getPhysicalTag(int lsTag, const std::vector<int> &physicals, } } -static int getBorderTag(int lsTag, int count, int &maxTag, std::map<int, int> &borderTags) +static int getBorderTag(int lsTag, int count, int &maxTag, + std::map<int, int> &borderTags) { - if(borderTags.count(lsTag)) - return borderTags[lsTag]; + if(borderTags.count(lsTag)) return borderTags[lsTag]; if(count || lsTag < 0) { int tag = ++maxTag; borderTags[lsTag] = tag; @@ -587,18 +595,15 @@ static int getBorderTag(int lsTag, int count, int &maxTag, std::map<int, int> &b return lsTag; } -static void elementSplitMesh(MElement *e, std::vector<gLevelset *> &RPN, - fullMatrix<double> &verticesLs, - GEntity *ge, GModel *GM, int &numEle, - std::map<int, MVertex*> &vertexMap, - std::map<MElement*, MElement*> &newParents, - std::map<MElement*, MElement*> &newDomains, - std::map<int, std::vector<MElement*> > elements[10], - std::map<int, std::map<int, std::string> > physicals[4], - std::map<int, int> newElemTags[4], - std::map<int, int> newPhysTags[4], - std::map<int, int> borderElemTags[2], - std::map<int, int> borderPhysTags[2]) +static void elementSplitMesh( + MElement *e, std::vector<gLevelset *> &RPN, fullMatrix<double> &verticesLs, + GEntity *ge, GModel *GM, int &numEle, std::map<int, MVertex *> &vertexMap, + std::map<MElement *, MElement *> &newParents, + std::map<MElement *, MElement *> &newDomains, + std::map<int, std::vector<MElement *> > elements[10], + std::map<int, std::map<int, std::string> > physicals[4], + std::map<int, int> newElemTags[4], std::map<int, int> newPhysTags[4], + std::map<int, int> borderElemTags[2], std::map<int, int> borderPhysTags[2]) { int elementary = ge->tag(); int eType = e->getType(); @@ -610,29 +615,31 @@ static void elementSplitMesh(MElement *e, std::vector<gLevelset *> &RPN, double eps = 1.e-10; bool splitElem = false; - //split acording to center of gravity + // split acording to center of gravity // double lsMean = 0.0; // int lsTag = 1; // for(int k = 0; k < e->getNumVertices(); k++) // lsMean += verticesLs(iLs, e->getVertex(k)->getIndex()) - eps; // if (lsMean > 0) lsTag = -1; - //EMI : better for embedded dirichlet with smoothed properties - //split according to values of vertices (keep +) + // EMI : better for embedded dirichlet with smoothed properties + // split according to values of vertices (keep +) int lsTag = (verticesLs(iLs, e->getVertex(0)->getIndex()) > eps) ? -1 : 1; int ils = 0; - for(std::size_t k = 1; k < e->getNumVertices(); k++){ + for(std::size_t k = 1; k < e->getNumVertices(); k++) { int lsTag2 = (verticesLs(iLs, e->getVertex(k)->getIndex()) > eps) ? -1 : 1; - if (lsTag * lsTag2 < 0) { + if(lsTag * lsTag2 < 0) { lsTag = -1; splitElem = true; - if(RPN.size() > 1){ - for(; ils < verticesLs.size1() - 1; ils++){ - int lsT1 = (verticesLs(ils, e->getVertex(0)->getIndex()) > eps) ? -1 : 1; - int lsT2 = (verticesLs(ils, e->getVertex(k)->getIndex()) > eps) ? -1 : 1; + if(RPN.size() > 1) { + for(; ils < verticesLs.size1() - 1; ils++) { + int lsT1 = + (verticesLs(ils, e->getVertex(0)->getIndex()) > eps) ? -1 : 1; + int lsT2 = + (verticesLs(ils, e->getVertex(k)->getIndex()) > eps) ? -1 : 1; if(lsT1 * lsT2 < 0) break; } - for(int i = 0; i <= ils; i++) + for(int i = 0; i <= ils; i++) if(!RPN[i]->isPrimitive()) ils++; gLsTag = RPN[ils]->getTag(); } @@ -640,75 +647,65 @@ static void elementSplitMesh(MElement *e, std::vector<gLevelset *> &RPN, } } - //invert tag - //lsTag = 1; //negative ls - //for(int k = 0; k < e->getNumVertices(); k++){ + // invert tag + // lsTag = 1; //negative ls + // for(int k = 0; k < e->getNumVertices(); k++){ // double val = verticesLs(iLs, e->getVertex(k)->getIndex()); // if (val > 0.0) { lsTag = -1; break; } //} - switch (eType) { - case TYPE_TET : - case TYPE_HEX : - case TYPE_PYR : - case TYPE_PRI : - case TYPE_POLYH : - { - int reg = getElementaryTag(lsTag, elementary, newElemTags[3]); - getPhysicalTag(lsTag, gePhysicals, newPhysTags[3]); - if(eType == TYPE_TET) - elements[4][reg].push_back(copy); - else if(eType == TYPE_HEX) - elements[5][reg].push_back(copy); - else if(eType == TYPE_PRI) - elements[6][reg].push_back(copy); - else if(eType == TYPE_PYR) - elements[7][reg].push_back(copy); - else if(eType == TYPE_POLYH) - elements[9][reg].push_back(copy); - assignPhysicals(GM, gePhysicals, reg, 3, physicals, newPhysTags[3], lsTag); - } - break; - case TYPE_TRI : - case TYPE_QUA : - case TYPE_POLYG : - { - int reg = getElementaryTag(lsTag, elementary, newElemTags[2]); - getPhysicalTag(lsTag, gePhysicals, newPhysTags[2]); - if(eType == TYPE_TRI) - elements[2][reg].push_back(copy); - else if(eType == TYPE_QUA) - elements[3][reg].push_back(copy); - else if(eType == TYPE_POLYG) - elements[8][reg].push_back(copy); - assignPhysicals(GM, gePhysicals, reg, 2, physicals, newPhysTags[2], lsTag); - } - break; - case TYPE_LIN : - { - int reg = getElementaryTag(lsTag, elementary, newElemTags[1]); - getPhysicalTag(lsTag, gePhysicals, newPhysTags[1]); - elements[1][reg].push_back(copy); - assignPhysicals(GM, gePhysicals, reg, 1, physicals, newPhysTags[1], lsTag); - } - break; - case TYPE_PNT : - { - int reg = getElementaryTag(lsTag, elementary, newElemTags[0]); - getPhysicalTag(lsTag, gePhysicals, newPhysTags[0]); - elements[0][reg].push_back(copy); - assignPhysicals(GM, gePhysicals, reg, 0, physicals, newPhysTags[0], lsTag); - } - break; - default : - Msg::Error("This type of element cannot be split."); - return; + switch(eType) { + case TYPE_TET: + case TYPE_HEX: + case TYPE_PYR: + case TYPE_PRI: + case TYPE_POLYH: { + int reg = getElementaryTag(lsTag, elementary, newElemTags[3]); + getPhysicalTag(lsTag, gePhysicals, newPhysTags[3]); + if(eType == TYPE_TET) + elements[4][reg].push_back(copy); + else if(eType == TYPE_HEX) + elements[5][reg].push_back(copy); + else if(eType == TYPE_PRI) + elements[6][reg].push_back(copy); + else if(eType == TYPE_PYR) + elements[7][reg].push_back(copy); + else if(eType == TYPE_POLYH) + elements[9][reg].push_back(copy); + assignPhysicals(GM, gePhysicals, reg, 3, physicals, newPhysTags[3], lsTag); + } break; + case TYPE_TRI: + case TYPE_QUA: + case TYPE_POLYG: { + int reg = getElementaryTag(lsTag, elementary, newElemTags[2]); + getPhysicalTag(lsTag, gePhysicals, newPhysTags[2]); + if(eType == TYPE_TRI) + elements[2][reg].push_back(copy); + else if(eType == TYPE_QUA) + elements[3][reg].push_back(copy); + else if(eType == TYPE_POLYG) + elements[8][reg].push_back(copy); + assignPhysicals(GM, gePhysicals, reg, 2, physicals, newPhysTags[2], lsTag); + } break; + case TYPE_LIN: { + int reg = getElementaryTag(lsTag, elementary, newElemTags[1]); + getPhysicalTag(lsTag, gePhysicals, newPhysTags[1]); + elements[1][reg].push_back(copy); + assignPhysicals(GM, gePhysicals, reg, 1, physicals, newPhysTags[1], lsTag); + } break; + case TYPE_PNT: { + int reg = getElementaryTag(lsTag, elementary, newElemTags[0]); + getPhysicalTag(lsTag, gePhysicals, newPhysTags[0]); + elements[0][reg].push_back(copy); + assignPhysicals(GM, gePhysicals, reg, 0, physicals, newPhysTags[0], lsTag); + } break; + default: Msg::Error("This type of element cannot be split."); return; } - //create level set interface (pt in 1D, line in 2D or face in 3D) - if(splitElem && e->getDim() == 2){ - for(int k = 0; k < e->getNumEdges(); k++){ - MEdge me = e->getEdge(k); + // create level set interface (pt in 1D, line in 2D or face in 3D) + if(splitElem && e->getDim() == 2) { + for(int k = 0; k < e->getNumEdges(); k++) { + MEdge me = e->getEdge(k); MVertex *v0 = me.getVertex(0); MVertex *v1 = me.getVertex(1); MVertex *v0N = vertexMap[v0->getNum()]; @@ -719,21 +716,23 @@ static void elementSplitMesh(MElement *e, std::vector<gLevelset *> &RPN, getPhysicalTag(-1, gePhysicals, newPhysTags[1]); int c = elements[1].count(gLsTag); int reg = getBorderTag(gLsTag, c, newElemTags[1][0], borderElemTags[0]); - int physTag = (!gePhysicals.size()) ? 0 : - getBorderTag(gLsTag, c, newPhysTags[1][0], borderPhysTags[0]); + int physTag = + (!gePhysicals.size()) ? + 0 : + getBorderTag(gLsTag, c, newPhysTags[1][0], borderPhysTags[0]); int i; - for(i = elements[1][reg].size() - 1; i >= 0; i--){ + for(i = elements[1][reg].size() - 1; i >= 0; i--) { MElement *el = elements[1][reg][i]; if((el->getVertex(0) == v0N && el->getVertex(1) == v1N) || (el->getVertex(0) == v1N && el->getVertex(1) == v0N)) break; } - if(i < 0){ + if(i < 0) { MLine *lin = new MLine(v0N, v1N); elements[1][reg].push_back(lin); if(physTag) assignLsPhysical(GM, reg, 1, physicals, physTag, gLsTag); } - else{ + else { MElement *el = elements[1][reg][i]; elements[1][reg].erase(elements[1][reg].begin() + i); delete el; @@ -741,61 +740,70 @@ static void elementSplitMesh(MElement *e, std::vector<gLevelset *> &RPN, } } } - else if(splitElem && e->getDim() == 3){ - for(int k = 0; k < e->getNumFaces(); k++){ + else if(splitElem && e->getDim() == 3) { + for(int k = 0; k < e->getNumFaces(); k++) { MFace mf = e->getFace(k); bool sameSign = true; - double val0 = (verticesLs(iLs, mf.getVertex(0)->getIndex()) > eps) ? 1 : -1; - for (std::size_t j = 1; j < mf.getNumVertices(); j++){ - double valj = (verticesLs(iLs, mf.getVertex(j)->getIndex()) > eps) ? 1 : -1; - if (val0*valj < 0.0){ sameSign = false; break;} + double val0 = + (verticesLs(iLs, mf.getVertex(0)->getIndex()) > eps) ? 1 : -1; + for(std::size_t j = 1; j < mf.getNumVertices(); j++) { + double valj = + (verticesLs(iLs, mf.getVertex(j)->getIndex()) > eps) ? 1 : -1; + if(val0 * valj < 0.0) { + sameSign = false; + break; + } } if(sameSign && val0 < 0.0) { getPhysicalTag(-1, gePhysicals, newPhysTags[2]); int c = elements[2].count(gLsTag) + elements[3].count(gLsTag) + elements[8].count(gLsTag); int reg = getBorderTag(gLsTag, c, newElemTags[2][0], borderElemTags[1]); - int physTag = (!gePhysicals.size()) ? 0 : - getBorderTag(gLsTag, c, newPhysTags[2][0], borderPhysTags[1]); - if(mf.getNumVertices() == 3){ + int physTag = + (!gePhysicals.size()) ? + 0 : + getBorderTag(gLsTag, c, newPhysTags[2][0], borderPhysTags[1]); + if(mf.getNumVertices() == 3) { MFace f1 = MFace(vertexMap[mf.getVertex(0)->getNum()], vertexMap[mf.getVertex(1)->getNum()], vertexMap[mf.getVertex(2)->getNum()]); int i = elements[2][reg].size() - 1; - for(; i >= 0; i--){ + for(; i >= 0; i--) { MElement *el = elements[2][reg][i]; - MFace f2 = MFace(el->getVertex(0), el->getVertex(1), el->getVertex(2)); + MFace f2 = + MFace(el->getVertex(0), el->getVertex(1), el->getVertex(2)); if(f1 == f2) break; } - if(i < 0){ - MTriangle *tri = new MTriangle(f1.getVertex(0), f1.getVertex(1), - f1.getVertex(2)); + if(i < 0) { + MTriangle *tri = + new MTriangle(f1.getVertex(0), f1.getVertex(1), f1.getVertex(2)); elements[2][reg].push_back(tri); } - else{ + else { MElement *el = elements[2][reg][i]; elements[2][reg].erase(elements[2][reg].begin() + i); delete el; } } - else if(mf.getNumVertices() == 4){ + else if(mf.getNumVertices() == 4) { MFace f1 = MFace(vertexMap[mf.getVertex(0)->getNum()], vertexMap[mf.getVertex(1)->getNum()], vertexMap[mf.getVertex(2)->getNum()], vertexMap[mf.getVertex(3)->getNum()]); int i; - for(i = elements[3][reg].size() - 1; i >= 0; i--){ + for(i = elements[3][reg].size() - 1; i >= 0; i--) { MElement *el = elements[3][reg][i]; MFace f2 = MFace(el->getVertex(0), el->getVertex(1), el->getVertex(2), el->getVertex(3)); if(f1 == f2) break; } - if(i < 0){ - MQuadrangle *quad = new MQuadrangle(f1.getVertex(0), f1.getVertex(1), - f1.getVertex(2), f1.getVertex(2)); + if(i < 0) { + MQuadrangle *quad = + new MQuadrangle(f1.getVertex(0), f1.getVertex(1), f1.getVertex(2), + f1.getVertex(2)); elements[3][reg].push_back(quad); } - else{ + else { MElement *el = elements[3][reg][i]; elements[3][reg].erase(elements[3][reg].begin() + i); delete el; @@ -809,45 +817,37 @@ static void elementSplitMesh(MElement *e, std::vector<gLevelset *> &RPN, static bool equalV(MVertex *v, const DI_Point *p) { - return (fabs(v->x() - p->x()) < 1.e-15 && - fabs(v->y() - p->y()) < 1.e-15 && + return (fabs(v->x() - p->x()) < 1.e-15 && fabs(v->y() - p->y()) < 1.e-15 && fabs(v->z() - p->z()) < 1.e-15); } static int getElementVertexNum(DI_Point *p, MElement *e) { for(std::size_t i = 0; i < e->getNumVertices(); i++) - if(equalV(e->getVertex(i), p)) - return e->getVertex(i)->getNum(); + if(equalV(e->getVertex(i), p)) return e->getVertex(i)->getNum(); return -1; } -typedef std::set<MVertex*, MVertexLessThanLexicographic> newVerticesContainer; - -static void elementCutMesh(MElement *e, std::vector<gLevelset *> &RPN, - fullMatrix<double> &verticesLs, - GEntity *ge, GModel *GM, int &numEle, - std::map<int, MVertex*> &vertexMap, - newVerticesContainer &newVertices, - std::map<MElement*, MElement*> &newParents, - std::map<MElement*, MElement*> &newDomains, - std::multimap<MElement*, MElement*> borders[2], - std::map<int, std::vector<MElement*> > elements[10], - std::map<int, std::map<int, std::string> > physicals[4], - std::map<int, int> newElemTags[4], - std::map<int, int> newPhysTags[4], - std::map<int, int> borderElemTags[2], - std::map<int, int> borderPhysTags[2], - DI_Point::Container &cp, - std::vector<DI_Line *> &lines, - std::vector<DI_Triangle *> &triangles, - std::vector<DI_Quad *> &quads, - std::vector<DI_Tetra *> &tetras, - std::vector<DI_Hexa *> &hexas) +typedef std::set<MVertex *, MVertexLessThanLexicographic> newVerticesContainer; + +static void elementCutMesh( + MElement *e, std::vector<gLevelset *> &RPN, fullMatrix<double> &verticesLs, + GEntity *ge, GModel *GM, int &numEle, std::map<int, MVertex *> &vertexMap, + newVerticesContainer &newVertices, + std::map<MElement *, MElement *> &newParents, + std::map<MElement *, MElement *> &newDomains, + std::multimap<MElement *, MElement *> borders[2], + std::map<int, std::vector<MElement *> > elements[10], + std::map<int, std::map<int, std::string> > physicals[4], + std::map<int, int> newElemTags[4], std::map<int, int> newPhysTags[4], + std::map<int, int> borderElemTags[2], std::map<int, int> borderPhysTags[2], + DI_Point::Container &cp, std::vector<DI_Line *> &lines, + std::vector<DI_Triangle *> &triangles, std::vector<DI_Quad *> &quads, + std::vector<DI_Tetra *> &tetras, std::vector<DI_Hexa *> &hexas) { int elementary = ge->tag(); int eType = e->getType(); - int recur = e->getPolynomialOrder()-1; + int recur = e->getPolynomialOrder() - 1; int ePart = e->getPartition(); MElement *eParent = e->getParent(); std::vector<int> gePhysicals = ge->physicals; @@ -858,576 +858,637 @@ static void elementCutMesh(MElement *e, std::vector<gLevelset *> &RPN, bool isCut = false; unsigned int nbL = lines.size(); unsigned int nbTr = triangles.size(); - unsigned int nbQ = quads.size(); + unsigned int nbQ = quads.size(); unsigned int nbTe = tetras.size(); unsigned int nbH = hexas.size(); MElement *copy = e->copy(vertexMap, newParents, newDomains); MElement *parent = eParent ? copy->getParent() : copy; - double **nodeLs = new double*[e->getNumVertices()]; - - switch (eType) { - case TYPE_TET : - case TYPE_HEX : - case TYPE_PYR : - case TYPE_PRI : - case TYPE_POLYH : - { - if(eType == TYPE_TET) { - DI_Tetra T(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), - e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), - e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z()); - T.setPolynomialOrder(recur+1); - for(std::size_t i = 0; i < e->getNumVertices(); i++) - nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); - isCut = T.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, - tetras, quads, triangles, recur, nodeLs); - } - else if(eType == TYPE_HEX){ - DI_Hexa H(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), - e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), - e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z(), - e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z(), - e->getVertex(5)->x(), e->getVertex(5)->y(), e->getVertex(5)->z(), - e->getVertex(6)->x(), e->getVertex(6)->y(), e->getVertex(6)->z(), - e->getVertex(7)->x(), e->getVertex(7)->y(), e->getVertex(7)->z()); - H.setPolynomialOrder(recur+1); - for(std::size_t i = 0; i < e->getNumVertices(); i++) - nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); - isCut = H.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, integOrder, - hexas, tetras, quads, triangles, lines, recur, nodeLs); - } - else if(eType == TYPE_PRI){ - DI_Tetra T1(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), - e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), - e->getVertex(5)->x(), e->getVertex(5)->y(), e->getVertex(5)->z()); - //T1.setPolynomialOrder(recur+1); - for(int i = 0; i < 3; i++) nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); - nodeLs[3] = &verticesLs(0, e->getVertex(5)->getIndex()); - bool iC1 = T1.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, - tetras, quads, triangles, recur, nodeLs); - DI_Tetra T2(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z(), - e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), - e->getVertex(5)->x(), e->getVertex(5)->y(), e->getVertex(5)->z()); - //T2.setPolynomialOrder(recur+1); - nodeLs[0] = &verticesLs(0, e->getVertex(0)->getIndex()); - nodeLs[1] = &verticesLs(0, e->getVertex(4)->getIndex()); - nodeLs[2] = &verticesLs(0, e->getVertex(1)->getIndex()); - nodeLs[3] = &verticesLs(0, e->getVertex(5)->getIndex()); - bool iC2 = T2.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, - tetras, quads, triangles, recur, nodeLs); - DI_Tetra T3(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z(), - e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z(), - e->getVertex(5)->x(), e->getVertex(5)->y(), e->getVertex(5)->z()); - //T3.setPolynomialOrder(recur+1); - for(int i = 1; i < 4; i++) - nodeLs[i] = &verticesLs(0, e->getVertex(i+2)->getIndex()); - bool iC3 = T3.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, - tetras, quads, triangles, recur, nodeLs); - isCut = iC1 || iC2 || iC3; - } - else if(eType == TYPE_PYR){ - DI_Tetra T1(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), - e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), - e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z()); - //T1.setPolynomialOrder(recur+1); - for(int i = 0; i < 3; i++) nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); - nodeLs[3] = &verticesLs(0, e->getVertex(4)->getIndex()); - bool iC1 = T1.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, - tetras, quads, triangles, recur, nodeLs); - DI_Tetra T2(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), - e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z(), - e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z()); - //T2.setPolynomialOrder(recur+1); - nodeLs[0] = &verticesLs(0, e->getVertex(0)->getIndex()); - for(int i = 1; i < 4; i++) - nodeLs[i] = &verticesLs(0, e->getVertex(i+1)->getIndex()); - bool iC2 = T2.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + double **nodeLs = new double *[e->getNumVertices()]; + + switch(eType) { + case TYPE_TET: + case TYPE_HEX: + case TYPE_PYR: + case TYPE_PRI: + case TYPE_POLYH: { + if(eType == TYPE_TET) { + DI_Tetra T( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), + e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), + e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z()); + T.setPolynomialOrder(recur + 1); + for(std::size_t i = 0; i < e->getNumVertices(); i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); + isCut = T.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + tetras, quads, triangles, recur, nodeLs); + } + else if(eType == TYPE_HEX) { + DI_Hexa H( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), + e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), + e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z(), + e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z(), + e->getVertex(5)->x(), e->getVertex(5)->y(), e->getVertex(5)->z(), + e->getVertex(6)->x(), e->getVertex(6)->y(), e->getVertex(6)->z(), + e->getVertex(7)->x(), e->getVertex(7)->y(), e->getVertex(7)->z()); + H.setPolynomialOrder(recur + 1); + for(std::size_t i = 0; i < e->getNumVertices(); i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); + isCut = + H.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, integOrder, + hexas, tetras, quads, triangles, lines, recur, nodeLs); + } + else if(eType == TYPE_PRI) { + DI_Tetra T1( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), + e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), + e->getVertex(5)->x(), e->getVertex(5)->y(), e->getVertex(5)->z()); + // T1.setPolynomialOrder(recur+1); + for(int i = 0; i < 3; i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); + nodeLs[3] = &verticesLs(0, e->getVertex(5)->getIndex()); + bool iC1 = T1.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + tetras, quads, triangles, recur, nodeLs); + DI_Tetra T2( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z(), + e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), + e->getVertex(5)->x(), e->getVertex(5)->y(), e->getVertex(5)->z()); + // T2.setPolynomialOrder(recur+1); + nodeLs[0] = &verticesLs(0, e->getVertex(0)->getIndex()); + nodeLs[1] = &verticesLs(0, e->getVertex(4)->getIndex()); + nodeLs[2] = &verticesLs(0, e->getVertex(1)->getIndex()); + nodeLs[3] = &verticesLs(0, e->getVertex(5)->getIndex()); + bool iC2 = T2.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + tetras, quads, triangles, recur, nodeLs); + DI_Tetra T3( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z(), + e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z(), + e->getVertex(5)->x(), e->getVertex(5)->y(), e->getVertex(5)->z()); + // T3.setPolynomialOrder(recur+1); + for(int i = 1; i < 4; i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i + 2)->getIndex()); + bool iC3 = T3.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + tetras, quads, triangles, recur, nodeLs); + isCut = iC1 || iC2 || iC3; + } + else if(eType == TYPE_PYR) { + DI_Tetra T1( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), + e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), + e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z()); + // T1.setPolynomialOrder(recur+1); + for(int i = 0; i < 3; i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); + nodeLs[3] = &verticesLs(0, e->getVertex(4)->getIndex()); + bool iC1 = T1.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + tetras, quads, triangles, recur, nodeLs); + DI_Tetra T2( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), + e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z(), + e->getVertex(4)->x(), e->getVertex(4)->y(), e->getVertex(4)->z()); + // T2.setPolynomialOrder(recur+1); + nodeLs[0] = &verticesLs(0, e->getVertex(0)->getIndex()); + for(int i = 1; i < 4; i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i + 1)->getIndex()); + bool iC2 = T2.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + tetras, quads, triangles, recur, nodeLs); + isCut = iC1 || iC2; + } + else if(eType == TYPE_POLYH) { + for(int i = 0; i < e->getNumChildren(); i++) { + MTetrahedron *t = (MTetrahedron *)e->getChild(i); + DI_Tetra Tet( + t->getVertex(0)->x(), t->getVertex(0)->y(), t->getVertex(0)->z(), + t->getVertex(1)->x(), t->getVertex(1)->y(), t->getVertex(1)->z(), + t->getVertex(2)->x(), t->getVertex(2)->y(), t->getVertex(2)->z(), + t->getVertex(3)->x(), t->getVertex(3)->y(), t->getVertex(3)->z()); + Tet.setPolynomialOrder(recur + 1); + for(std::size_t i = 0; i < t->getNumVertices(); i++) + nodeLs[i] = &verticesLs(0, t->getVertex(i)->getIndex()); + bool iC = Tet.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, tetras, quads, triangles, recur, nodeLs); - isCut = iC1 || iC2; - } - else if(eType == TYPE_POLYH){ - for(int i = 0; i < e->getNumChildren(); i++) { - MTetrahedron *t = (MTetrahedron*) e->getChild(i); - DI_Tetra Tet(t->getVertex(0)->x(), t->getVertex(0)->y(), t->getVertex(0)->z(), - t->getVertex(1)->x(), t->getVertex(1)->y(), t->getVertex(1)->z(), - t->getVertex(2)->x(), t->getVertex(2)->y(), t->getVertex(2)->z(), - t->getVertex(3)->x(), t->getVertex(3)->y(), t->getVertex(3)->z()); - Tet.setPolynomialOrder(recur+1); - for(std::size_t i = 0; i < t->getNumVertices(); i++) - nodeLs[i] = &verticesLs(0, t->getVertex(i)->getIndex()); - bool iC = Tet.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, - tetras, quads, triangles, recur, nodeLs); - isCut = (isCut || iC); - } + isCut = (isCut || iC); } - MPolyhedron *p1 = NULL, *p2 = NULL; - if(isCut) { - std::vector<MTetrahedron*> poly[2]; - - for (unsigned int i = nbTe; i < tetras.size(); i++){ - MVertex *mv[4] = {NULL, NULL, NULL, NULL}; - for(int j = 0; j < 4; j++){ - int numV = getElementVertexNum(tetras[i]->pt(j), e); - if (numV == -1){ - MVertex *newv = new MVertex(tetras[i]->x(j), tetras[i]->y(j), - tetras[i]->z(j)); - std::pair<newVerticesContainer::iterator, bool> it = - newVertices.insert(newv); - mv[j] = *(it.first); - if (!it.second) newv->deleteLast(); - } - else { - std::map<int, MVertex*>::iterator it = vertexMap.find(numV); - if(it == vertexMap.end()) { - mv[j] = new MVertex(tetras[i]->x(j), tetras[i]->y(j), - tetras[i]->z(j), 0, numV); - vertexMap[numV] = mv[j]; - } - else mv[j] = it->second; + } + MPolyhedron *p1 = NULL, *p2 = NULL; + if(isCut) { + std::vector<MTetrahedron *> poly[2]; + + for(unsigned int i = nbTe; i < tetras.size(); i++) { + MVertex *mv[4] = {NULL, NULL, NULL, NULL}; + for(int j = 0; j < 4; j++) { + int numV = getElementVertexNum(tetras[i]->pt(j), e); + if(numV == -1) { + MVertex *newv = + new MVertex(tetras[i]->x(j), tetras[i]->y(j), tetras[i]->z(j)); + std::pair<newVerticesContainer::iterator, bool> it = + newVertices.insert(newv); + mv[j] = *(it.first); + if(!it.second) newv->deleteLast(); + } + else { + std::map<int, MVertex *>::iterator it = vertexMap.find(numV); + if(it == vertexMap.end()) { + mv[j] = new MVertex(tetras[i]->x(j), tetras[i]->y(j), + tetras[i]->z(j), 0, numV); + vertexMap[numV] = mv[j]; } + else + mv[j] = it->second; } - MTetrahedron *mt = new MTetrahedron(mv[0], mv[1], mv[2], mv[3], 0, 0); - if(tetras[i]->lsTag() < 0) - poly[0].push_back(mt); - else - poly[1].push_back(mt); } - bool own = (eParent && !e->ownsParent()) ? false : true; - if(poly[0].size()) { - int n = (e->getParent()) ? e->getNum() : ++numEle; - p1 = new MPolyhedron(poly[0], n, ePart, own, parent); - own = false; - int reg = getElementaryTag(-1, elementary, newElemTags[3]); - getPhysicalTag(-1, gePhysicals, newPhysTags[3]); - elements[9][reg].push_back(p1); - assignPhysicals(GM, gePhysicals, reg, 3, physicals, newPhysTags[3], -1); + MTetrahedron *mt = new MTetrahedron(mv[0], mv[1], mv[2], mv[3], 0, 0); + if(tetras[i]->lsTag() < 0) + poly[0].push_back(mt); + else + poly[1].push_back(mt); + } + bool own = (eParent && !e->ownsParent()) ? false : true; + if(poly[0].size()) { + int n = (e->getParent()) ? e->getNum() : ++numEle; + p1 = new MPolyhedron(poly[0], n, ePart, own, parent); + own = false; + int reg = getElementaryTag(-1, elementary, newElemTags[3]); + getPhysicalTag(-1, gePhysicals, newPhysTags[3]); + elements[9][reg].push_back(p1); + assignPhysicals(GM, gePhysicals, reg, 3, physicals, newPhysTags[3], -1); + } + if(poly[1].size()) { + int n = + (e->getParent() && poly[0].size() == 0) ? e->getNum() : ++numEle; + p2 = new MPolyhedron(poly[1], n, ePart, own, parent); + getPhysicalTag(1, gePhysicals, newPhysTags[3]); + elements[9][elementary].push_back(p2); + assignPhysicals(GM, gePhysicals, elementary, 3, physicals, + newPhysTags[3], 1); + } + // check for border surfaces cut earlier along the polyhedra + std::pair<std::multimap<MElement *, MElement *>::iterator, + std::multimap<MElement *, MElement *>::iterator> + itr = borders[1].equal_range(copy); + std::vector<std::pair<MElement *, MElement *> > bords; + for(std::multimap<MElement *, MElement *>::iterator it = itr.first; + it != itr.second; it++) { + MElement *tb = it->second; + int match = 0; + for(int i = 0; i < p1->getNumPrimaryVertices(); i++) { + if(tb->getVertex(0) == p1->getVertex(i) || + tb->getVertex(1) == p1->getVertex(i) || + tb->getVertex(2) == p1->getVertex(i)) + match++; + if(match == 3) break; } - if(poly[1].size()) { - int n = (e->getParent() && poly[0].size() == 0) ? e->getNum() : ++numEle; - p2 = new MPolyhedron(poly[1], n, ePart, own, parent); - getPhysicalTag(1, gePhysicals, newPhysTags[3]); - elements[9][elementary].push_back(p2); - assignPhysicals(GM, gePhysicals, elementary, 3, physicals, newPhysTags[3], 1); + MElement *dom = (match == 3) ? p1 : p2; + tb->setDomain(dom, (tb->getDomain(0) == copy) ? 0 : 1); + bords.push_back(std::pair<MElement *, MElement *>(dom, tb)); + } + borders[1].erase(itr.first, itr.second); + for(unsigned int i = 0; i < bords.size(); i++) + borders[1].insert(bords[i]); + if(eParent) { + copy->setParent(NULL, false); + delete copy; + } + } + else { // no cut + int lsTag; + if(eType == TYPE_HEX) + lsTag = hexas[nbH]->lsTag(); + else + lsTag = tetras[nbTe]->lsTag(); + int reg = getElementaryTag(lsTag, elementary, newElemTags[3]); + getPhysicalTag(lsTag, gePhysicals, newPhysTags[3]); + if(eType == TYPE_TET) + elements[4][reg].push_back(copy); + else if(eType == TYPE_HEX) + elements[5][reg].push_back(copy); + else if(eType == TYPE_PRI) + elements[6][reg].push_back(copy); + else if(eType == TYPE_PYR) + elements[7][reg].push_back(copy); + else if(eType == TYPE_POLYH) + elements[9][reg].push_back(copy); + assignPhysicals(GM, gePhysicals, reg, 3, physicals, newPhysTags[3], + lsTag); + } + + for(unsigned int i = nbTr; i < triangles.size(); i++) { + MVertex *mv[3] = {NULL, NULL, NULL}; + for(int j = 0; j < 3; j++) { + int numV = getElementVertexNum(triangles[i]->pt(j), e); + if(numV == -1) { + MVertex *newv = new MVertex(triangles[i]->x(j), triangles[i]->y(j), + triangles[i]->z(j)); + std::pair<newVerticesContainer::iterator, bool> it = + newVertices.insert(newv); + mv[j] = *(it.first); + if(!it.second) newv->deleteLast(); } - // check for border surfaces cut earlier along the polyhedra - std::pair<std::multimap<MElement*, MElement*>::iterator, - std::multimap<MElement*, MElement*>::iterator> itr = - borders[1].equal_range(copy); - std::vector<std::pair<MElement*, MElement*> > bords; - for(std::multimap<MElement*, MElement*>::iterator it = itr.first; - it != itr.second; it++) { - MElement *tb = it->second; - int match = 0; - for(int i = 0; i < p1->getNumPrimaryVertices(); i++) { - if(tb->getVertex(0) == p1->getVertex(i) || - tb->getVertex(1) == p1->getVertex(i) || - tb->getVertex(2) == p1->getVertex(i)) match++; - if(match == 3) break; + else { + std::map<int, MVertex *>::iterator it = vertexMap.find(numV); + if(it == vertexMap.end()) { + mv[j] = new MVertex(triangles[i]->x(j), triangles[i]->y(j), + triangles[i]->z(j), 0, numV); + vertexMap[numV] = mv[j]; } - MElement *dom = (match == 3) ? p1 : p2; - tb->setDomain(dom, (tb->getDomain(0) == copy) ? 0 : 1); - bords.push_back(std::pair<MElement*, MElement*>(dom, tb)); + else + mv[j] = it->second; } - borders[1].erase(itr.first, itr.second); - for(unsigned int i = 0; i < bords.size(); i++) - borders[1].insert(bords[i]); - if(eParent) {copy->setParent(NULL, false); delete copy;} } - else { // no cut - int lsTag; - if(eType == TYPE_HEX) - lsTag = hexas[nbH]->lsTag(); + MTriangle *tri; + if(p1 || p2) { + if(!p1) + tri = + new MTriangleBorder(mv[0], mv[1], mv[2], ++numEle, ePart, p2, p1); else - lsTag = tetras[nbTe]->lsTag(); - int reg = getElementaryTag(lsTag, elementary, newElemTags[3]); - getPhysicalTag(lsTag, gePhysicals, newPhysTags[3]); - if(eType == TYPE_TET) - elements[4][reg].push_back(copy); - else if(eType == TYPE_HEX) - elements[5][reg].push_back(copy); - else if(eType == TYPE_PRI) - elements[6][reg].push_back(copy); - else if(eType == TYPE_PYR) - elements[7][reg].push_back(copy); - else if(eType == TYPE_POLYH) - elements[9][reg].push_back(copy); - assignPhysicals(GM, gePhysicals, reg, 3, physicals, newPhysTags[3], lsTag); + tri = + new MTriangleBorder(mv[0], mv[1], mv[2], ++numEle, ePart, p1, p2); + } + else + tri = new MTriangle(mv[0], mv[1], mv[2], ++numEle, ePart); + int lsTag = triangles[i]->lsTag(); + int cR = elements[2].count(lsTag) + elements[3].count(lsTag) + + elements[8].count(lsTag); + int cP = 0; + for(std::map<int, std::map<int, std::string> >::iterator it = + physicals[2].begin(); + it != physicals[2].end(); it++) + for(std::map<int, std::string>::iterator it2 = it->second.begin(); + it2 != it->second.end(); it2++) + if(it2->first == lsTag) { + cP = 1; + break; + } + // the surfaces are cut before the volumes! + int reg = getBorderTag(lsTag, cR, newElemTags[2][0], borderElemTags[1]); + int physTag = + (!gePhysicals.size()) ? + 0 : + getBorderTag(lsTag, cP, newPhysTags[2][0], borderPhysTags[1]); + elements[2][reg].push_back(tri); + if(physTag) assignLsPhysical(GM, reg, 2, physicals, physTag, lsTag); + for(int i = 0; i < 2; i++) + if(tri->getDomain(i)) + borders[1].insert( + std::pair<MElement *, MElement *>(tri->getDomain(i), tri)); + } + } break; + case TYPE_TRI: + case TYPE_QUA: + case TYPE_POLYG: { + if(eType == TYPE_TRI) { + DI_Triangle T( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), + e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z()); + T.setPolynomialOrder(recur + 1); + for(std::size_t i = 0; i < e->getNumVertices(); i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); + isCut = T.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + quads, triangles, lines, recur, nodeLs); + } + else if(eType == TYPE_QUA) { + DI_Quad Q( + e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), + e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), + e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z()); + Q.setPolynomialOrder(recur + 1); + for(std::size_t i = 0; i < e->getNumVertices(); i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); + isCut = Q.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + quads, triangles, lines, recur, nodeLs); + } + else if(eType == TYPE_POLYG) { + for(int i = 0; i < e->getNumChildren(); i++) { + MElement *t = e->getChild(i); + DI_Triangle Tri( + t->getVertex(0)->x(), t->getVertex(0)->y(), t->getVertex(0)->z(), + t->getVertex(1)->x(), t->getVertex(1)->y(), t->getVertex(1)->z(), + t->getVertex(2)->x(), t->getVertex(2)->y(), t->getVertex(2)->z()); + Tri.setPolynomialOrder(recur + 1); + for(std::size_t i = 0; i < t->getNumVertices(); i++) + nodeLs[i] = &verticesLs(0, t->getVertex(i)->getIndex()); + bool iC = Tri.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, + quads, triangles, lines, recur, nodeLs); + isCut = (isCut || iC); } + } - for (unsigned int i = nbTr; i < triangles.size(); i++){ + MPolygon *p1 = NULL, *p2 = NULL; + if(isCut) { + std::vector<MTriangle *> poly[2]; + + for(unsigned int i = nbTr; i < triangles.size(); i++) { MVertex *mv[3] = {NULL, NULL, NULL}; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { int numV = getElementVertexNum(triangles[i]->pt(j), e); if(numV == -1) { MVertex *newv = new MVertex(triangles[i]->x(j), triangles[i]->y(j), triangles[i]->z(j)); - std::pair<newVerticesContainer::iterator, bool> it = newVertices.insert(newv); + std::pair<newVerticesContainer::iterator, bool> it = + newVertices.insert(newv); mv[j] = *(it.first); - if (!it.second) newv->deleteLast(); + if(!it.second) newv->deleteLast(); } else { - std::map<int, MVertex*>::iterator it = vertexMap.find(numV); + std::map<int, MVertex *>::iterator it = vertexMap.find(numV); if(it == vertexMap.end()) { mv[j] = new MVertex(triangles[i]->x(j), triangles[i]->y(j), triangles[i]->z(j), 0, numV); vertexMap[numV] = mv[j]; } - else mv[j] = it->second; + else + mv[j] = it->second; } } - MTriangle *tri; - if(p1 || p2){ - if(!p1) tri = new MTriangleBorder(mv[0], mv[1], mv[2], ++numEle, ePart, p2, p1); - else tri = new MTriangleBorder(mv[0], mv[1], mv[2], ++numEle, ePart, p1, p2); - } - else tri = new MTriangle(mv[0], mv[1], mv[2], ++numEle, ePart); - int lsTag = triangles[i]->lsTag(); - int cR = elements[2].count(lsTag) + elements[3].count(lsTag) + - elements[8].count(lsTag); - int cP = 0; - for(std::map<int, std::map<int, std::string> >::iterator it = physicals[2].begin(); - it != physicals[2].end(); it++) - for(std::map<int, std::string>::iterator it2 = it->second.begin(); - it2 != it->second.end(); it2++) - if(it2->first == lsTag) - {cP = 1; break;} - // the surfaces are cut before the volumes! - int reg = getBorderTag(lsTag, cR, newElemTags[2][0], borderElemTags[1]); - int physTag = (!gePhysicals.size()) ? 0 : - getBorderTag(lsTag, cP, newPhysTags[2][0], borderPhysTags[1]); - elements[2][reg].push_back(tri); - if(physTag) - assignLsPhysical(GM, reg, 2, physicals, physTag, lsTag); - for(int i = 0; i < 2; i++) - if(tri->getDomain(i)) - borders[1].insert(std::pair<MElement*, MElement*>(tri->getDomain(i), tri)); - } - } - break; - case TYPE_TRI : - case TYPE_QUA : - case TYPE_POLYG : - { - if( eType == TYPE_TRI ) { - DI_Triangle T(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), - e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z()); - T.setPolynomialOrder(recur+1); - for(std::size_t i = 0; i < e->getNumVertices(); i++) - nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); - isCut = T.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, - quads, triangles, lines, recur, nodeLs); - } - else if(eType == TYPE_QUA){ - DI_Quad Q(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z(), - e->getVertex(2)->x(), e->getVertex(2)->y(), e->getVertex(2)->z(), - e->getVertex(3)->x(), e->getVertex(3)->y(), e->getVertex(3)->z()); - Q.setPolynomialOrder(recur+1); - for(std::size_t i = 0; i < e->getNumVertices(); i++) - nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); - isCut = Q.cut(RPN, ipV, ipS, cp, integOrder,integOrder,integOrder, - quads, triangles, lines, recur, nodeLs); - } - else if(eType == TYPE_POLYG){ - for(int i = 0; i < e->getNumChildren(); i++) { - MElement *t = e->getChild(i); - DI_Triangle Tri(t->getVertex(0)->x(), t->getVertex(0)->y(), t->getVertex(0)->z(), - t->getVertex(1)->x(), t->getVertex(1)->y(), t->getVertex(1)->z(), - t->getVertex(2)->x(), t->getVertex(2)->y(), t->getVertex(2)->z()); - Tri.setPolynomialOrder(recur+1); - for(std::size_t i = 0; i < t->getNumVertices(); i++) - nodeLs[i] = &verticesLs(0, t->getVertex(i)->getIndex()); - bool iC = Tri.cut(RPN, ipV, ipS, cp, integOrder, integOrder, integOrder, - quads, triangles, lines, recur, nodeLs); - isCut = (isCut || iC); - } + MTriangle *mt = new MTriangle(mv[0], mv[1], mv[2], 0, 0); + if(triangles[i]->lsTag() < 0) + poly[0].push_back(mt); + else + poly[1].push_back(mt); } - - MPolygon *p1 = NULL, *p2 = NULL; - if(isCut) { - std::vector<MTriangle*> poly[2]; - - for (unsigned int i = nbTr; i < triangles.size(); i++){ - MVertex *mv[3] = {NULL, NULL, NULL}; - for(int j = 0; j < 3; j++){ - int numV = getElementVertexNum(triangles[i]->pt(j), e); - if(numV == -1) { - MVertex *newv = new MVertex(triangles[i]->x(j), triangles[i]->y(j), - triangles[i]->z(j)); - std::pair<newVerticesContainer::iterator, bool> it = - newVertices.insert(newv); - mv[j] = *(it.first); - if (!it.second) newv->deleteLast(); - } - else { - std::map<int, MVertex*>::iterator it = vertexMap.find(numV); - if(it == vertexMap.end()) { - mv[j] = new MVertex(triangles[i]->x(j), triangles[i]->y(j), - triangles[i]->z(j), 0, numV); - vertexMap[numV] = mv[j]; - } - else mv[j] = it->second; - } - } - MTriangle *mt = new MTriangle(mv[0], mv[1], mv[2], 0, 0); - if(triangles[i]->lsTag() < 0) - poly[0].push_back(mt); - else - poly[1].push_back(mt); - } - //if quads - for (unsigned int i = nbQ; i < quads.size(); i++){ - MVertex *mv[4] = {NULL, NULL, NULL, NULL}; - for(int j = 0; j < 4; j++){ + // if quads + for(unsigned int i = nbQ; i < quads.size(); i++) { + MVertex *mv[4] = {NULL, NULL, NULL, NULL}; + for(int j = 0; j < 4; j++) { int numV = getElementVertexNum(quads[i]->pt(j), e); - if(numV == -1) { - MVertex *newv = new MVertex(quads[i]->x(j), quads[i]->y(j), quads[i]->z(j)); - std::pair<newVerticesContainer::iterator, bool> it = - newVertices.insert(newv); - mv[j] = *(it.first); - if (!it.second) newv->deleteLast(); - } - else { - std::map<int, MVertex*>::iterator it = vertexMap.find(numV); - if(it == vertexMap.end()) { - mv[j] = new MVertex(quads[i]->x(j), quads[i]->y(j), - quads[i]->z(j), 0, numV); - vertexMap[numV] = mv[j]; - } - else mv[j] = it->second; - } - } - MTriangle *mt0 = new MTriangle(mv[0], mv[1], mv[2], 0, 0); - MTriangle *mt1 = new MTriangle(mv[0], mv[2], mv[3], 0, 0); - if(quads[i]->lsTag() < 0){ - poly[0].push_back(mt0); - poly[0].push_back(mt1); + if(numV == -1) { + MVertex *newv = + new MVertex(quads[i]->x(j), quads[i]->y(j), quads[i]->z(j)); + std::pair<newVerticesContainer::iterator, bool> it = + newVertices.insert(newv); + mv[j] = *(it.first); + if(!it.second) newv->deleteLast(); } - else{ - poly[1].push_back(mt0); - poly[1].push_back(mt1); + else { + std::map<int, MVertex *>::iterator it = vertexMap.find(numV); + if(it == vertexMap.end()) { + mv[j] = new MVertex(quads[i]->x(j), quads[i]->y(j), + quads[i]->z(j), 0, numV); + vertexMap[numV] = mv[j]; + } + else + mv[j] = it->second; } } + MTriangle *mt0 = new MTriangle(mv[0], mv[1], mv[2], 0, 0); + MTriangle *mt1 = new MTriangle(mv[0], mv[2], mv[3], 0, 0); + if(quads[i]->lsTag() < 0) { + poly[0].push_back(mt0); + poly[0].push_back(mt1); + } + else { + poly[1].push_back(mt0); + poly[1].push_back(mt1); + } + } - bool own = (eParent && !e->ownsParent()) ? false : true; - if(poly[0].size()) { - int n = (e->getParent()) ? e->getNum() : ++numEle; - if(eType == MSH_TRI_B || eType == MSH_POLYG_B) - p1 = new MPolygonBorder(poly[0], n, ePart, own, parent, - copy->getDomain(0), copy->getDomain(1)); - else p1 = new MPolygon(poly[0], n, ePart, own, parent); - own = false; - int reg = getElementaryTag(-1, elementary, newElemTags[2]); - getPhysicalTag(-1, gePhysicals, newPhysTags[2]); - elements[8][reg].push_back(p1); - assignPhysicals(GM, gePhysicals, reg, 2, physicals, newPhysTags[2], -1); - for(int i = 0; i < 2; i++) - if(p1->getDomain(i)) - borders[1].insert(std::pair<MElement*, MElement*>(p1->getDomain(i), p1)); + bool own = (eParent && !e->ownsParent()) ? false : true; + if(poly[0].size()) { + int n = (e->getParent()) ? e->getNum() : ++numEle; + if(eType == MSH_TRI_B || eType == MSH_POLYG_B) + p1 = new MPolygonBorder(poly[0], n, ePart, own, parent, + copy->getDomain(0), copy->getDomain(1)); + else + p1 = new MPolygon(poly[0], n, ePart, own, parent); + own = false; + int reg = getElementaryTag(-1, elementary, newElemTags[2]); + getPhysicalTag(-1, gePhysicals, newPhysTags[2]); + elements[8][reg].push_back(p1); + assignPhysicals(GM, gePhysicals, reg, 2, physicals, newPhysTags[2], -1); + for(int i = 0; i < 2; i++) + if(p1->getDomain(i)) + borders[1].insert( + std::pair<MElement *, MElement *>(p1->getDomain(i), p1)); + } + if(poly[1].size()) { + int n = + (e->getParent() && poly[0].size() == 0) ? e->getNum() : ++numEle; + if(eType == MSH_TRI_B || eType == MSH_POLYG_B) + p2 = new MPolygonBorder(poly[1], n, ePart, own, parent, + copy->getDomain(0), copy->getDomain(1)); + else + p2 = new MPolygon(poly[1], n, ePart, own, parent); + getPhysicalTag(1, gePhysicals, newPhysTags[2]); + elements[8][elementary].push_back(p2); + assignPhysicals(GM, gePhysicals, elementary, 2, physicals, + newPhysTags[2], 1); + for(int i = 0; i < 2; i++) + if(p2->getDomain(i)) + borders[1].insert( + std::pair<MElement *, MElement *>(p2->getDomain(i), p2)); + } + // check for border lines cut earlier along the polygons + std::pair<std::multimap<MElement *, MElement *>::iterator, + std::multimap<MElement *, MElement *>::iterator> + itr = borders[0].equal_range(copy); + std::vector<std::pair<MElement *, MElement *> > bords; + for(std::multimap<MElement *, MElement *>::iterator it = itr.first; + it != itr.second; ++it) { + MElement *lb = it->second; + int match = 0; + for(int i = 0; i < p1->getNumPrimaryVertices(); i++) { + if(lb->getVertex(0) == p1->getVertex(i) || + lb->getVertex(1) == p1->getVertex(i)) + match++; + if(match == 2) break; } - if(poly[1].size()) { - int n = (e->getParent() && poly[0].size() == 0) ? e->getNum() : ++numEle; - if(eType == MSH_TRI_B || eType == MSH_POLYG_B) - p2 = new MPolygonBorder(poly[1], n, ePart, own, parent, - copy->getDomain(0), copy->getDomain(1)); - else p2 = new MPolygon(poly[1], n, ePart, own, parent); - getPhysicalTag(1, gePhysicals, newPhysTags[2]); - elements[8][elementary].push_back(p2); - assignPhysicals(GM, gePhysicals, elementary, 2, physicals, newPhysTags[2], 1); - for(int i = 0; i < 2; i++) - if(p2->getDomain(i)) - borders[1].insert(std::pair<MElement*, MElement*>(p2->getDomain(i), p2)); + MElement *dom = (match == 2) ? p1 : p2; + lb->setDomain(dom, (lb->getDomain(0) == copy) ? 0 : 1); + bords.push_back(std::pair<MElement *, MElement *>(dom, lb)); + } + borders[0].erase(itr.first, itr.second); + for(unsigned int i = 0; i < bords.size(); i++) + borders[0].insert(bords[i]); + if(eParent) { + copy->setParent(NULL, false); + delete copy; + } + } + else { // no cut + int lsTag; + if(eType == TYPE_QUA) + lsTag = quads[nbQ]->lsTag(); + else + lsTag = triangles[nbTr]->lsTag(); + int reg = getElementaryTag(lsTag, elementary, newElemTags[2]); + getPhysicalTag(lsTag, gePhysicals, newPhysTags[2]); + if(eType == TYPE_TRI) + elements[2][reg].push_back(copy); + else if(eType == TYPE_QUA) + elements[3][reg].push_back(copy); + else if(eType == TYPE_POLYG) + elements[8][reg].push_back(copy); + assignPhysicals(GM, gePhysicals, reg, 2, physicals, newPhysTags[2], + lsTag); + for(int i = 0; i < 2; i++) + if(copy->getDomain(i)) + borders[1].insert( + std::pair<MElement *, MElement *>(copy->getDomain(i), copy)); + } + + for(unsigned int i = nbL; i < lines.size(); i++) { + MVertex *mv[2] = {NULL, NULL}; + for(int j = 0; j < 2; j++) { + int numV = getElementVertexNum(lines[i]->pt(j), e); + if(numV == -1) { + MVertex *newv = + new MVertex(lines[i]->x(j), lines[i]->y(j), lines[i]->z(j)); + std::pair<newVerticesContainer::iterator, bool> it = + newVertices.insert(newv); + mv[j] = *(it.first); + if(!it.second) newv->deleteLast(); } - // check for border lines cut earlier along the polygons - std::pair<std::multimap<MElement*, MElement*>::iterator, - std::multimap<MElement*, MElement*>::iterator> itr = - borders[0].equal_range(copy); - std::vector<std::pair<MElement*, MElement*> > bords; - for(std::multimap<MElement*, MElement*>::iterator it = itr.first; - it != itr.second; ++it) { - MElement *lb = it->second; - int match = 0; - for(int i = 0; i < p1->getNumPrimaryVertices(); i++) { - if(lb->getVertex(0) == p1->getVertex(i) || - lb->getVertex(1) == p1->getVertex(i)) match++; - if(match == 2) break; + else { + std::map<int, MVertex *>::iterator it = vertexMap.find(numV); + if(it == vertexMap.end()) { + mv[j] = new MVertex(lines[i]->x(j), lines[i]->y(j), lines[i]->z(j), + 0, numV); + vertexMap[numV] = mv[j]; } - MElement *dom = (match == 2) ? p1 : p2; - lb->setDomain(dom, (lb->getDomain(0) == copy) ? 0 : 1); - bords.push_back(std::pair<MElement*, MElement*>(dom, lb)); + else + mv[j] = it->second; } - borders[0].erase(itr.first, itr.second); - for(unsigned int i = 0; i < bords.size(); i++) - borders[0].insert(bords[i]); - if(eParent) {copy->setParent(NULL, false); delete copy;} } - else { // no cut - int lsTag; - if(eType == TYPE_QUA) - lsTag = quads[nbQ]->lsTag(); + MLine *lin; + if(p1 || p2) { + if(!p1) + lin = new MLineBorder(mv[0], mv[1], ++numEle, ePart, p2, p1); else - lsTag = triangles[nbTr]->lsTag(); - int reg = getElementaryTag(lsTag, elementary, newElemTags[2]); - getPhysicalTag(lsTag, gePhysicals, newPhysTags[2]); - if(eType == TYPE_TRI) - elements[2][reg].push_back(copy); - else if(eType == TYPE_QUA) - elements[3][reg].push_back(copy); - else if(eType == TYPE_POLYG) - elements[8][reg].push_back(copy); - assignPhysicals(GM, gePhysicals, reg, 2, physicals, newPhysTags[2], lsTag); - for(int i = 0; i < 2; i++) - if(copy->getDomain(i)) - borders[1].insert(std::pair<MElement*, MElement*>(copy->getDomain(i), copy)); + lin = new MLineBorder(mv[0], mv[1], ++numEle, ePart, p1, p2); } - - for (unsigned int i = nbL; i < lines.size(); i++){ + else + lin = new MLine(mv[0], mv[1], ++numEle, ePart); + int lsTag = lines[i]->lsTag(); + int cR = elements[1].count(lsTag); + int cP = 0; + for(std::map<int, std::map<int, std::string> >::iterator it = + physicals[1].begin(); + it != physicals[1].end(); it++) + for(std::map<int, std::string>::iterator it2 = it->second.begin(); + it2 != it->second.end(); it2++) + if(it2->first == lsTag) { + cP = 1; + break; + } + // the lines are cut before the surfaces! + int reg = getBorderTag(lsTag, cR, newElemTags[1][0], borderElemTags[0]); + int physTag = + (!gePhysicals.size()) ? + 0 : + getBorderTag(lsTag, cP, newPhysTags[1][0], borderPhysTags[0]); + elements[1][reg].push_back(lin); + if(physTag) assignLsPhysical(GM, reg, 1, physicals, physTag, lsTag); + for(int i = 0; i < 2; i++) + if(lin->getDomain(i)) + borders[0].insert( + std::pair<MElement *, MElement *>(lin->getDomain(i), lin)); + } + } break; + case TYPE_LIN: { + DI_Line L(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), + e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z()); + L.setPolynomialOrder(recur + 1); + for(std::size_t i = 0; i < e->getNumVertices(); i++) + nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); + isCut = L.cut(RPN, ipV, cp, integOrder, lines, recur, nodeLs); + + if(isCut) { + bool own = (eParent && !e->ownsParent()) ? false : true; + for(unsigned int i = nbL; i < lines.size(); i++) { MVertex *mv[2] = {NULL, NULL}; - for(int j = 0; j < 2; j++){ + for(int j = 0; j < 2; j++) { int numV = getElementVertexNum(lines[i]->pt(j), e); if(numV == -1) { - MVertex *newv = new MVertex(lines[i]->x(j), lines[i]->y(j), lines[i]->z(j)); - std::pair<newVerticesContainer::iterator, bool> it = newVertices.insert(newv); + MVertex *newv = + new MVertex(lines[i]->x(j), lines[i]->y(j), lines[i]->z(j)); + std::pair<newVerticesContainer::iterator, bool> it = + newVertices.insert(newv); mv[j] = *(it.first); - if (!it.second) newv->deleteLast(); + if(!it.second) newv->deleteLast(); } else { - std::map<int, MVertex*>::iterator it = vertexMap.find(numV); + std::map<int, MVertex *>::iterator it = vertexMap.find(numV); if(it == vertexMap.end()) { mv[j] = new MVertex(lines[i]->x(j), lines[i]->y(j), lines[i]->z(j), 0, numV); vertexMap[numV] = mv[j]; } - else mv[j] = it->second; + else + mv[j] = it->second; } } - MLine *lin; - if(p1 || p2){ - if(!p1) lin = new MLineBorder(mv[0], mv[1], ++numEle, ePart, p2, p1); - else lin = new MLineBorder(mv[0], mv[1], ++numEle, ePart, p1, p2); - } - else lin = new MLine(mv[0], mv[1], ++numEle, ePart); + MLine *ml; + int n = (e->getParent() && i == nbL) ? e->getNum() : ++numEle; + if(eType != MSH_LIN_B) + ml = new MLineChild(mv[0], mv[1], n, ePart, own, parent); + else + ml = new MLineBorder(mv[0], mv[1], n, ePart, copy->getDomain(0), + copy->getDomain(1)); + own = false; + int reg = + getElementaryTag(lines[i]->lsTag(), elementary, newElemTags[1]); int lsTag = lines[i]->lsTag(); - int cR = elements[1].count(lsTag); - int cP = 0; - for(std::map<int, std::map<int, std::string> >::iterator it = physicals[1].begin(); - it != physicals[1].end(); it++) - for(std::map<int, std::string>::iterator it2 = it->second.begin(); - it2 != it->second.end(); it2++) - if(it2->first == lsTag) - {cP = 1; break;} - // the lines are cut before the surfaces! - int reg = getBorderTag(lsTag, cR, newElemTags[1][0], borderElemTags[0]); - int physTag = (!gePhysicals.size()) ? 0 : - getBorderTag(lsTag, cP, newPhysTags[1][0], borderPhysTags[0]); - elements[1][reg].push_back(lin); - if(physTag) - assignLsPhysical(GM, reg, 1, physicals, physTag, lsTag); - for(int i = 0; i < 2; i++) - if(lin->getDomain(i)) - borders[0].insert(std::pair<MElement*, MElement*>(lin->getDomain(i), lin)); - } - } - break; - case TYPE_LIN : - { - DI_Line L(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z(), - e->getVertex(1)->x(), e->getVertex(1)->y(), e->getVertex(1)->z()); - L.setPolynomialOrder(recur+1); - for(std::size_t i = 0; i < e->getNumVertices(); i++) - nodeLs[i] = &verticesLs(0, e->getVertex(i)->getIndex()); - isCut = L.cut(RPN, ipV, cp, integOrder, lines, recur, nodeLs); - - if(isCut) { - bool own = (eParent && !e->ownsParent()) ? false : true; - for (unsigned int i = nbL; i < lines.size(); i++){ - MVertex *mv[2] = {NULL, NULL}; - for(int j = 0; j < 2; j++){ - int numV = getElementVertexNum(lines[i]->pt(j), e); - if(numV == -1) { - MVertex *newv = new MVertex(lines[i]->x(j), lines[i]->y(j), lines[i]->z(j)); - std::pair<newVerticesContainer::iterator, bool> it = - newVertices.insert(newv); - mv[j] = *(it.first); - if (!it.second) newv->deleteLast(); - } - else { - std::map<int, MVertex*>::iterator it = vertexMap.find(numV); - if(it == vertexMap.end()) { - mv[j] = new MVertex(lines[i]->x(j), lines[i]->y(j), lines[i]->z(j), - 0, numV); - vertexMap[numV] = mv[j]; - } - else mv[j] = it->second; - } - } - MLine *ml; - int n = (e->getParent() && i == nbL) ? e->getNum() : ++numEle; - if(eType != MSH_LIN_B) ml = new MLineChild(mv[0], mv[1], n, ePart, own, parent); - else ml = new MLineBorder(mv[0], mv[1], n, ePart, - copy->getDomain(0), copy->getDomain(1)); - own = false; - int reg = getElementaryTag(lines[i]->lsTag(), elementary, newElemTags[1]); - int lsTag = lines[i]->lsTag(); - getPhysicalTag(lsTag, gePhysicals, newPhysTags[1]); - elements[1][reg].push_back(ml); - assignPhysicals(GM, gePhysicals, reg, 1, physicals, newPhysTags[1], lsTag); - for(int i = 0; i < 2; i++) - if(ml->getDomain(i)) - borders[0].insert(std::pair<MElement*, MElement*>(ml->getDomain(i), ml)); - } - if(eParent) {copy->setParent(NULL, false); delete copy;} - } - else { // no cut - int lsTag = lines[nbL]->lsTag(); - int reg = getElementaryTag(lsTag, elementary, newElemTags[1]); getPhysicalTag(lsTag, gePhysicals, newPhysTags[1]); - elements[1][reg].push_back(copy); - assignPhysicals(GM, gePhysicals, reg, 1, physicals, newPhysTags[1], lsTag); + elements[1][reg].push_back(ml); + assignPhysicals(GM, gePhysicals, reg, 1, physicals, newPhysTags[1], + lsTag); for(int i = 0; i < 2; i++) - if(copy->getDomain(i)) - borders[0].insert(std::pair<MElement*, MElement*>(copy->getDomain(i), copy)); + if(ml->getDomain(i)) + borders[0].insert( + std::pair<MElement *, MElement *>(ml->getDomain(i), ml)); + } + if(eParent) { + copy->setParent(NULL, false); + delete copy; } } - break; - case TYPE_PNT : - { - DI_Point P(e->getVertex(0)->x(), e->getVertex(0)->y(), e->getVertex(0)->z()); - P.computeLs(RPN.back()); - int lsTag = P.lsTag(); - int reg = getElementaryTag(lsTag, elementary, newElemTags[0]); - getPhysicalTag(lsTag, gePhysicals, newPhysTags[0]); - elements[0][reg].push_back(copy); - assignPhysicals(GM, gePhysicals, reg, 0, physicals, newPhysTags[0], lsTag); + else { // no cut + int lsTag = lines[nbL]->lsTag(); + int reg = getElementaryTag(lsTag, elementary, newElemTags[1]); + getPhysicalTag(lsTag, gePhysicals, newPhysTags[1]); + elements[1][reg].push_back(copy); + assignPhysicals(GM, gePhysicals, reg, 1, physicals, newPhysTags[1], + lsTag); + for(int i = 0; i < 2; i++) + if(copy->getDomain(i)) + borders[0].insert( + std::pair<MElement *, MElement *>(copy->getDomain(i), copy)); } - break; - default : - Msg::Error("This type of element cannot be cut %d.",eType); - break; + } break; + case TYPE_PNT: { + DI_Point P(e->getVertex(0)->x(), e->getVertex(0)->y(), + e->getVertex(0)->z()); + P.computeLs(RPN.back()); + int lsTag = P.lsTag(); + int reg = getElementaryTag(lsTag, elementary, newElemTags[0]); + getPhysicalTag(lsTag, gePhysicals, newPhysTags[0]); + elements[0][reg].push_back(copy); + assignPhysicals(GM, gePhysicals, reg, 0, physicals, newPhysTags[0], lsTag); + } break; + default: Msg::Error("This type of element cannot be cut %d.", eType); break; } - for(unsigned int i = 0; i < ipS.size(); i++) - delete ipS[i]; - for(unsigned int i = 0; i < ipV.size(); i++) - delete ipV[i]; - delete [] nodeLs; + for(unsigned int i = 0; i < ipS.size(); i++) delete ipS[i]; + for(unsigned int i = 0; i < ipV.size(); i++) delete ipV[i]; + delete[] nodeLs; } -#endif //HAVE_DINTEGRATION +#endif // HAVE_DINTEGRATION GModel *buildCutMesh(GModel *gm, gLevelset *ls, - std::map<int, std::vector<MElement*> > elements[10], - std::map<int, MVertex*> &vertexMap, + std::map<int, std::vector<MElement *> > elements[10], + std::map<int, MVertex *> &vertexMap, std::map<int, std::map<int, std::string> > physicals[4], bool cutElem) { @@ -1436,7 +1497,7 @@ GModel *buildCutMesh(GModel *gm, gLevelset *ls, GModel *cutGM = new GModel(gm->getName() + "_cut"); cutGM->setFileName(cutGM->getName()); - std::vector<GEntity*> gmEntities; + std::vector<GEntity *> gmEntities; gm->getEntities(gmEntities); std::vector<gLevelset *> primitives; @@ -1448,32 +1509,36 @@ GModel *buildCutMesh(GModel *gm, gLevelset *ls, int nbLs = (primS > 1) ? primS + 1 : 1; fullMatrix<double> verticesLs(nbLs, numVert + 1); - //compute all at once for ls POINTS (type = 11) + // compute all at once for ls POINTS (type = 11) bool lsPoints = false; for(int i = 0; i < primS; i++) - if(primitives[i]->type() == LSPOINTS) {lsPoints = true; break;} - if(lsPoints){ + if(primitives[i]->type() == LSPOINTS) { + lsPoints = true; + break; + } + if(lsPoints) { std::vector<MVertex *> vert; for(unsigned int i = 0; i < gmEntities.size(); i++) { for(unsigned int j = 0; j < gmEntities[i]->getNumMeshVertices(); j++) { vert.push_back(gmEntities[i]->getMeshVertex(j)); } } - for(int k = 0; k < primS; k++){ - if (primitives[k]->type() == LSPOINTS){ - ((gLevelsetPoints*)primitives[k])->computeLS(vert); + for(int k = 0; k < primS; k++) { + if(primitives[k]->type() == LSPOINTS) { + ((gLevelsetPoints *)primitives[k])->computeLS(vert); } } } - //compute and store levelset values + create new nodes + // compute and store levelset values + create new nodes for(unsigned int i = 0; i < gmEntities.size(); i++) { for(unsigned int j = 0; j < gmEntities[i]->getNumMeshVertices(); j++) { MVertex *vi = gmEntities[i]->getMeshVertex(j); if(vi->getIndex() < 0) continue; int k = 0; for(; k < primS; k++) - verticesLs(k, vi->getIndex()) = (*primitives[k])(vi->x(), vi->y(), vi->z()); + verticesLs(k, vi->getIndex()) = + (*primitives[k])(vi->x(), vi->y(), vi->z()); if(primS > 1) verticesLs(k, vi->getIndex()) = (*ls)(vi->x(), vi->y(), vi->z()); @@ -1482,52 +1547,52 @@ GModel *buildCutMesh(GModel *gm, gLevelset *ls, } } - //element number increment + // element number increment int numEle = gm->getNumMeshElements() + gm->getNumMeshParentElements(); for(unsigned int i = 0; i < gmEntities.size(); i++) { for(unsigned int j = 0; j < gmEntities[i]->getNumMeshElements(); j++) { MElement *e = gmEntities[i]->getMeshElement(j); - if(e->getNum() > numEle) - numEle = e->getNum(); + if(e->getNum() > numEle) numEle = e->getNum(); if(e->getParent()) - if(e->getParent()->getNum() > numEle) - numEle = e->getParent()->getNum(); + if(e->getParent()->getNum() > numEle) numEle = e->getParent()->getNum(); } } - std::map<int, int> newElemTags[4]; //map<oldElementary,newElementary>[dim] - std::map<int, int> newPhysTags[4]; //map<oldPhysical,newPhysical>[dim] - for(int d = 0; d < 4; d++){ - newElemTags[d][0] = gm->getMaxElementaryNumber(d); //max value at [dim][0] - newPhysTags[d][0] = gm->getMaxPhysicalNumber(d); //max value at [dim][0] + std::map<int, int> newElemTags[4]; // map<oldElementary,newElementary>[dim] + std::map<int, int> newPhysTags[4]; // map<oldPhysical,newPhysical>[dim] + for(int d = 0; d < 4; d++) { + newElemTags[d][0] = gm->getMaxElementaryNumber(d); // max value at [dim][0] + newPhysTags[d][0] = gm->getMaxPhysicalNumber(d); // max value at [dim][0] } - std::map<MElement*, MElement*> newParents; //map<oldParent, newParent> - std::map<MElement*, MElement*> newDomains; //map<oldDomain, newDomain> - std::map<int, int> borderElemTags[2]; //map<lsTag,elementary>[line=0,surface=1] - std::map<int, int> borderPhysTags[2]; //map<lstag,physical>[line=0,surface=1] + std::map<MElement *, MElement *> newParents; // map<oldParent, newParent> + std::map<MElement *, MElement *> newDomains; // map<oldDomain, newDomain> + std::map<int, int> + borderElemTags[2]; // map<lsTag,elementary>[line=0,surface=1] + std::map<int, int> borderPhysTags[2]; // map<lstag,physical>[line=0,surface=1] - //SplitMesh + // SplitMesh if(!cutElem) { for(unsigned int i = 0; i < gmEntities.size(); i++) { for(unsigned int j = 0; j < gmEntities[i]->getNumMeshElements(); j++) { MElement *e = gmEntities[i]->getMeshElement(j); e->setVolumePositive(); - elementSplitMesh(e, RPN, verticesLs, gmEntities[i], gm, numEle, vertexMap, - newParents, newDomains, elements, physicals, newElemTags, - newPhysTags, borderElemTags, borderPhysTags); + elementSplitMesh(e, RPN, verticesLs, gmEntities[i], gm, numEle, + vertexMap, newParents, newDomains, elements, physicals, + newElemTags, newPhysTags, borderElemTags, + borderPhysTags); if(e->getPartition() > static_cast<int>(cutGM->getNumPartitions())) { - cutGM->setNumPartitions(e->getPartition()); + cutGM->setNumPartitions(e->getPartition()); } } } return cutGM; } - //CutMesh + // CutMesh newVerticesContainer newVertices; - //multimap<domain,border>[polyg=0,polyh=1] - std::multimap<MElement*, MElement*> borders[2]; + // multimap<domain,border>[polyg=0,polyh=1] + std::multimap<MElement *, MElement *> borders[2]; DI_Point::Container cp; std::vector<DI_Line *> lines; std::vector<DI_Triangle *> triangles; @@ -1537,58 +1602,65 @@ GModel *buildCutMesh(GModel *gm, gLevelset *ls, std::vector<int> lsLineRegs; for(unsigned int i = 0; i < gmEntities.size(); i++) { std::vector<int> oldLineRegs; - for (std::map<int, std::vector<MElement*> >::iterator it = elements[1].begin(); - it != elements[1].end(); it++) + for(std::map<int, std::vector<MElement *> >::iterator it = + elements[1].begin(); + it != elements[1].end(); it++) oldLineRegs.push_back(it->first); int nbBorders = borders[0].size(); for(unsigned int j = 0; j < gmEntities[i]->getNumMeshElements(); j++) { MElement *e = gmEntities[i]->getMeshElement(j); e->setVolumePositive(); elementCutMesh(e, RPN, verticesLs, gmEntities[i], gm, numEle, vertexMap, - newVertices, newParents, newDomains, borders, elements, physicals, - newElemTags, newPhysTags, borderElemTags, borderPhysTags, cp, - lines, triangles, quads, tetras, hexas); + newVertices, newParents, newDomains, borders, elements, + physicals, newElemTags, newPhysTags, borderElemTags, + borderPhysTags, cp, lines, triangles, quads, tetras, + hexas); if(e->getPartition() > static_cast<int>(cutGM->getNumPartitions())) { - cutGM->setNumPartitions(e->getPartition()); + cutGM->setNumPartitions(e->getPartition()); } } // Create elementary and physical for non connected border lines if((int)borders[0].size() > nbBorders && gmEntities[i]->dim() == 2 && - i == gm->getNumVertices() + gm->getNumEdges() + gm->getNumFaces() - 1){ + i == gm->getNumVertices() + gm->getNumEdges() + gm->getNumFaces() - 1) { int k = 0; - for (std::map<int, std::vector<MElement*> >::iterator it = elements[1].begin(); - it != elements[1].end(); it++){ + for(std::map<int, std::vector<MElement *> >::iterator it = + elements[1].begin(); + it != elements[1].end(); it++) { if(oldLineRegs.size() && it->first == oldLineRegs[k]) k++; else lsLineRegs.push_back(it->first); } - for(unsigned int j = 0; j < lsLineRegs.size(); j++){ + for(unsigned int j = 0; j < lsLineRegs.size(); j++) { int nLR = lsLineRegs[j]; bool havePhys = physicals[1][nLR].size(); - while(1){ - std::vector<MElement*> conLines; + while(1) { + std::vector<MElement *> conLines; conLines.push_back(elements[1][nLR][0]); elements[1][nLR].erase(elements[1][nLR].begin()); MVertex *v1 = conLines[0]->getVertex(0); MVertex *v2 = conLines[0]->getVertex(1); - for(unsigned int k = 0; k < elements[1][nLR].size(); ){ + for(unsigned int k = 0; k < elements[1][nLR].size();) { MVertex *va = elements[1][nLR][k]->getVertex(0); MVertex *vb = elements[1][nLR][k]->getVertex(1); - if(va == v1 || vb == v1 || va == v2 || vb == v2){ + if(va == v1 || vb == v1 || va == v2 || vb == v2) { conLines.push_back(elements[1][nLR][k]); elements[1][nLR].erase(elements[1][nLR].begin() + k); - if(v1 == va) v1 = vb; - else if(v1 == vb) v1 = va; - else if(v2 == va) v2 = vb; - else if(v2 == vb) v2 = va; + if(v1 == va) + v1 = vb; + else if(v1 == vb) + v1 = va; + else if(v2 == va) + v2 = vb; + else if(v2 == vb) + v2 = va; k = 0; } else k++; } - if(!elements[1][nLR].empty()){ + if(!elements[1][nLR].empty()) { int newReg = ++newElemTags[1][0]; int newPhys = (!havePhys) ? 0 : ++newPhysTags[1][0]; if(newPhys) @@ -1606,14 +1678,19 @@ GModel *buildCutMesh(GModel *gm, gLevelset *ls, } } - for(DI_Point::Container::iterator it = cp.begin(); it != cp.end(); it++) delete *it; + for(DI_Point::Container::iterator it = cp.begin(); it != cp.end(); it++) + delete *it; for(unsigned int k = 0; k < lines.size(); k++) delete lines[k]; for(unsigned int k = 0; k < triangles.size(); k++) delete triangles[k]; for(unsigned int k = 0; k < quads.size(); k++) delete quads[k]; for(unsigned int k = 0; k < tetras.size(); k++) delete tetras[k]; for(unsigned int k = 0; k < hexas.size(); k++) delete hexas[k]; - cp.clear(); lines.clear(); triangles.clear(); quads.clear(); - tetras.clear(); hexas.clear(); + cp.clear(); + lines.clear(); + triangles.clear(); + quads.clear(); + tetras.clear(); + hexas.clear(); } #if 0 @@ -1642,7 +1719,7 @@ GModel *buildCutMesh(GModel *gm, gLevelset *ls, #endif for(newVerticesContainer::iterator it = newVertices.begin(); - it != newVertices.end(); ++it){ + it != newVertices.end(); ++it) { vertexMap[(*it)->getNum()] = *it; } diff --git a/Geo/MElementCut.h b/Geo/MElementCut.h index af41bc2f054c7df0761d0b83851da61d0caa35ee..cc085681cc8025a287d375fbe8b2d93a9799dfec 100644 --- a/Geo/MElementCut.h +++ b/Geo/MElementCut.h @@ -19,22 +19,23 @@ class gLevelset; class GModel; class MPolyhedron : public MElement { - protected: +protected: bool _owner; - MElement* _orig; + MElement *_orig; IntPt *_intpt; - std::vector<MTetrahedron*> _parts; - std::vector<MVertex*> _vertices; - std::vector<MVertex*> _innerVertices; + std::vector<MTetrahedron *> _parts; + std::vector<MVertex *> _vertices; + std::vector<MVertex *> _innerVertices; std::vector<MEdge> _edges; std::vector<MFace> _faces; void _init(); - public: - MPolyhedron(std::vector<MVertex*> v, int num = 0, int part = 0, - bool owner = false, MElement* orig = NULL) + +public: + MPolyhedron(std::vector<MVertex *> v, int num = 0, int part = 0, + bool owner = false, MElement *orig = NULL) : MElement(num, part), _owner(owner), _orig(orig), _intpt(0) { - if(v.size() % 4){ + if(v.size() % 4) { Msg::Error("Got %d vertices for polyhedron", (int)v.size()); return; } @@ -42,38 +43,42 @@ class MPolyhedron : public MElement { _parts.push_back(new MTetrahedron(v[i], v[i + 1], v[i + 2], v[i + 3])); _init(); } - MPolyhedron(std::vector<MTetrahedron*> vT, int num = 0, int part = 0, - bool owner = false, MElement* orig = NULL) + MPolyhedron(std::vector<MTetrahedron *> vT, int num = 0, int part = 0, + bool owner = false, MElement *orig = NULL) : MElement(num, part), _owner(owner), _orig(orig), _intpt(0) { - for(unsigned int i = 0; i < vT.size(); i++) - _parts.push_back(vT[i]); + for(unsigned int i = 0; i < vT.size(); i++) _parts.push_back(vT[i]); _init(); } ~MPolyhedron() { - if(_owner) - delete _orig; - for(unsigned int i = 0; i < _parts.size(); i++) - delete _parts[i]; - if(_intpt) delete [] _intpt; + if(_owner) delete _orig; + for(unsigned int i = 0; i < _parts.size(); i++) delete _parts[i]; + if(_intpt) delete[] _intpt; } virtual int getDim() const { return 3; } - virtual std::size_t getNumVertices() const { return _vertices.size() + _innerVertices.size(); } + virtual std::size_t getNumVertices() const + { + return _vertices.size() + _innerVertices.size(); + } virtual int getNumVolumeVertices() const { return _innerVertices.size(); } virtual MVertex *getVertex(int num) { return (num < (int)_vertices.size()) ? - _vertices[num] : _innerVertices[num - _vertices.size()]; + _vertices[num] : + _innerVertices[num - _vertices.size()]; } virtual const MVertex *getVertex(int num) const { - return (num < (int)_vertices.size()) ? _vertices[num] : _innerVertices[num - _vertices.size()]; + return (num < (int)_vertices.size()) ? + _vertices[num] : + _innerVertices[num - _vertices.size()]; } - virtual int getNumEdges()const { return _edges.size(); } - virtual MEdge getEdge(int num) const{ return _edges[num]; } + virtual int getNumEdges() const { return _edges.size(); } + virtual MEdge getEdge(int num) const { return _edges[num]; } virtual int getNumEdgesRep(bool curved) { return _edges.size(); } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { MEdge e(getEdge(num)); for(unsigned int i = 0; i < _faces.size(); i++) @@ -81,7 +86,7 @@ class MPolyhedron : public MElement { if(_faces[i].getEdge(j) == e) _getEdgeRep(e.getVertex(0), e.getVertex(1), x, y, z, n, i); } - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); v[0] = _edges[num].getVertex(0); @@ -90,12 +95,13 @@ class MPolyhedron : public MElement { virtual int getNumFaces() { return _faces.size(); } virtual MFace getFace(int num) const { return _faces[num]; } virtual int getNumFacesRep(bool curved) { return _faces.size(); } - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { _getFaceRep(_faces[num].getVertex(0), _faces[num].getVertex(1), _faces[num].getVertex(2), x, y, z, n); } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); v[0] = _faces[num].getVertex(0); @@ -106,8 +112,7 @@ class MPolyhedron : public MElement { virtual int getTypeForMSH() const { return MSH_POLYH_; } virtual void reverse() { - for(unsigned int i = 0; i < _parts.size(); i++) - _parts[i]->reverse(); + for(unsigned int i = 0; i < _parts.size(); i++) _parts[i]->reverse(); _vertices.clear(); _innerVertices.clear(); _edges.clear(); @@ -121,23 +126,27 @@ class MPolyhedron : public MElement { vol += _parts[i]->getVolume(); return vol; } - virtual const nodalBasis* getFunctionSpace(int order=-1, bool serendip=false) const + virtual const nodalBasis *getFunctionSpace(int order = -1, + bool serendip = false) const { return (_orig ? _orig->getFunctionSpace(order, serendip) : 0); } - virtual const JacobianBasis* getJacobianFuncSpace(int order=-1) const + virtual const JacobianBasis *getJacobianFuncSpace(int order = -1) const { return (_orig ? _orig->getJacobianFuncSpace(order) : 0); } - virtual void getShapeFunctions(double u, double v, double w, double s[], int o) const + virtual void getShapeFunctions(double u, double v, double w, double s[], + int o) const { if(_orig) _orig->getShapeFunctions(u, v, w, s, o); } - virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int o) const + virtual void getGradShapeFunctions(double u, double v, double w, + double s[][3], int o) const { if(_orig) _orig->getGradShapeFunctions(u, v, w, s, o); } - virtual void getHessShapeFunctions(double u, double v, double w, double s[][3][3], int o) const + virtual void getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int o) const { if(_orig) _orig->getHessShapeFunctions(u, v, w, s, o); } @@ -163,11 +172,15 @@ class MPolyhedron : public MElement { virtual bool isInside(double u, double v, double w) const; virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); virtual MElement *getParent() const { return _orig; } - virtual void setParent(MElement *p, bool owner = false) { _orig = p; _owner = owner; } + virtual void setParent(MElement *p, bool owner = false) + { + _orig = p; + _owner = owner; + } virtual int getNumChildren() const { return _parts.size(); } virtual MElement *getChild(int i) const { return _parts[i]; } virtual bool ownsParent() const { return _owner; } - virtual int getNumVerticesForMSH() {return _parts.size() * 4;} + virtual int getNumVerticesForMSH() { return _parts.size() * 4; } virtual void getVerticesIdForMSH(std::vector<int> &verts) { int n = getNumVerticesForMSH(); @@ -183,63 +196,69 @@ class MPolyhedron : public MElement { }; class MPolygon : public MElement { - protected: +protected: bool _owner; - MElement* _orig; + MElement *_orig; IntPt *_intpt; - std::vector<MTriangle*> _parts; - std::vector<MVertex*> _vertices; - std::vector<MVertex*> _innerVertices; + std::vector<MTriangle *> _parts; + std::vector<MVertex *> _vertices; + std::vector<MVertex *> _innerVertices; std::vector<MEdge> _edges; void _initVertices(); - public: - MPolygon(std::vector<MVertex*> v, int num = 0, int part = 0, - bool owner = false, MElement* orig = NULL) + +public: + MPolygon(std::vector<MVertex *> v, int num = 0, int part = 0, + bool owner = false, MElement *orig = NULL) : MElement(num, part), _owner(owner), _orig(orig), _intpt(0) { for(unsigned int i = 0; i < v.size() / 3; i++) _parts.push_back(new MTriangle(v[i * 3], v[i * 3 + 1], v[i * 3 + 2])); _initVertices(); } - MPolygon(std::vector<MTriangle*> vT, int num = 0, int part = 0, - bool owner = false, MElement* orig = NULL) + MPolygon(std::vector<MTriangle *> vT, int num = 0, int part = 0, + bool owner = false, MElement *orig = NULL) : MElement(num, part), _owner(owner), _orig(orig), _intpt(0) { - for(unsigned int i = 0; i < vT.size(); i++){ - MTriangle *t = (MTriangle*) vT[i]; + for(unsigned int i = 0; i < vT.size(); i++) { + MTriangle *t = (MTriangle *)vT[i]; _parts.push_back(t); } _initVertices(); } ~MPolygon() { - if(_owner) - delete _orig; - for(unsigned int i = 0; i < _parts.size(); i++) - delete _parts[i]; - if(_intpt) delete [] _intpt; + if(_owner) delete _orig; + for(unsigned int i = 0; i < _parts.size(); i++) delete _parts[i]; + if(_intpt) delete[] _intpt; } virtual int getDim() const { return 2; } - virtual std::size_t getNumVertices() const { return _vertices.size() + _innerVertices.size(); } + virtual std::size_t getNumVertices() const + { + return _vertices.size() + _innerVertices.size(); + } virtual int getNumFaceVertices() const { return _innerVertices.size(); } virtual MVertex *getVertex(int num) { return (num < (int)_vertices.size()) ? - _vertices[num] : _innerVertices[num - _vertices.size()]; + _vertices[num] : + _innerVertices[num - _vertices.size()]; } virtual const MVertex *getVertex(int num) const { - return (num < (int)_vertices.size()) ? _vertices[num] : _innerVertices[num - _vertices.size()]; + return (num < (int)_vertices.size()) ? + _vertices[num] : + _innerVertices[num - _vertices.size()]; } - virtual int getNumEdges()const { return _edges.size(); } - virtual MEdge getEdge(int num) const{ return _edges[num]; } + virtual int getNumEdges() const { return _edges.size(); } + virtual MEdge getEdge(int num) const { return _edges[num]; } virtual int getNumEdgesRep(bool curved) { return getNumEdges(); } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { MEdge e(getEdge(num)); _getEdgeRep(e.getVertex(0), e.getVertex(1), x, y, z, n, 0); } - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); v[0] = _edges[num].getVertex(0); @@ -248,50 +267,59 @@ class MPolygon : public MElement { virtual int getNumFaces() { return 1; } virtual MFace getFace(int num) const { return MFace(_vertices); } virtual int getNumFacesRep(bool curved) { return _parts.size(); } - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { _getFaceRep(_parts[num]->getVertex(0), _parts[num]->getVertex(1), _parts[num]->getVertex(2), x, y, z, n); } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(_vertices.size() + _innerVertices.size()); - for (unsigned int i = 0; i < _vertices.size() + _innerVertices.size(); i++) - v[i] = (i < _vertices.size()) ? _vertices[i] : _innerVertices[i - _vertices.size()]; + for(unsigned int i = 0; i < _vertices.size() + _innerVertices.size(); i++) + v[i] = (i < _vertices.size()) ? _vertices[i] : + _innerVertices[i - _vertices.size()]; } virtual int getType() const { return TYPE_POLYG; } virtual int getTypeForMSH() const { return MSH_POLYG_; } virtual void reverse() { - for(unsigned int i = 0; i < _parts.size(); i++) - _parts[i]->reverse(); + for(unsigned int i = 0; i < _parts.size(); i++) _parts[i]->reverse(); _vertices.clear(); _innerVertices.clear(); _edges.clear(); _initVertices(); } virtual MElement *getParent() const { return _orig; } - virtual void setParent(MElement *p, bool owner = false) { _orig = p; _owner = owner; } + virtual void setParent(MElement *p, bool owner = false) + { + _orig = p; + _owner = owner; + } virtual int getNumChildren() const { return _parts.size(); } virtual MElement *getChild(int i) const { return _parts[i]; } virtual bool ownsParent() const { return _owner; } - virtual const nodalBasis* getFunctionSpace(int order=-1, bool serendip=false) const + virtual const nodalBasis *getFunctionSpace(int order = -1, + bool serendip = false) const { return (_orig ? _orig->getFunctionSpace(order, serendip) : 0); } - virtual const JacobianBasis* getJacobianFuncSpace(int order=-1) const + virtual const JacobianBasis *getJacobianFuncSpace(int order = -1) const { return (_orig ? _orig->getJacobianFuncSpace(order) : 0); } - virtual void getShapeFunctions(double u, double v, double w, double s[], int o) const + virtual void getShapeFunctions(double u, double v, double w, double s[], + int o) const { if(_orig) _orig->getShapeFunctions(u, v, w, s, o); } - virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int o) const + virtual void getGradShapeFunctions(double u, double v, double w, + double s[][3], int o) const { if(_orig) _orig->getGradShapeFunctions(u, v, w, s, o); } - virtual void getHessShapeFunctions(double u, double v, double w, double s[][3][3], int o) const + virtual void getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int o) const { if(_orig) _orig->getHessShapeFunctions(u, v, w, s, o); } @@ -316,7 +344,7 @@ class MPolygon : public MElement { // the coordinates in the local parent element. virtual bool isInside(double u, double v, double w) const; virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); - virtual int getNumVerticesForMSH() {return _parts.size() * 3;} + virtual int getNumVerticesForMSH() { return _parts.size() * 3; } virtual void getVerticesIdForMSH(std::vector<int> &verts) { int n = getNumVerticesForMSH(); @@ -332,47 +360,50 @@ class MPolygon : public MElement { }; class MLineChild : public MLine { - protected: +protected: bool _owner; - MElement* _orig; + MElement *_orig; IntPt *_intpt; - public: + +public: MLineChild(MVertex *v0, MVertex *v1, int num = 0, int part = 0, - bool owner = false, MElement* orig = NULL) - : MLine(v0, v1, num, part), _owner(owner), _orig(orig), _intpt(0) {} + bool owner = false, MElement *orig = NULL) + : MLine(v0, v1, num, part), _owner(owner), _orig(orig), _intpt(0) + { + } MLineChild(const std::vector<MVertex *> &v, int num = 0, int part = 0, bool owner = false, MElement *orig = NULL) - : MLine(v, num, part) - , _owner(owner) - , _orig(orig) - , _intpt(0) + : MLine(v, num, part), _owner(owner), _orig(orig), _intpt(0) { } ~MLineChild() { - if(_owner) - delete _orig; + if(_owner) delete _orig; } virtual int getTypeForMSH() const { return MSH_LIN_C; } - virtual const nodalBasis* getFunctionSpace(int order=-1, bool serendip=false) const + virtual const nodalBasis *getFunctionSpace(int order = -1, + bool serendip = false) const { if(_orig) return _orig->getFunctionSpace(order, serendip); return 0; } - virtual const JacobianBasis* getJacobianFuncSpace(int order=-1) const + virtual const JacobianBasis *getJacobianFuncSpace(int order = -1) const { if(_orig) return _orig->getJacobianFuncSpace(order); return 0; } - virtual void getShapeFunctions(double u, double v, double w, double s[], int o) const + virtual void getShapeFunctions(double u, double v, double w, double s[], + int o) const { if(_orig) _orig->getShapeFunctions(u, v, w, s, o); } - virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int o) const + virtual void getGradShapeFunctions(double u, double v, double w, + double s[][3], int o) const { if(_orig) _orig->getGradShapeFunctions(u, v, w, s, o); } - virtual void getHessShapeFunctions(double u, double v, double w, double s[][3][3], int o) const + virtual void getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int o) const { if(_orig) _orig->getHessShapeFunctions(u, v, w, s, o); } @@ -381,71 +412,79 @@ class MLineChild : public MLine { virtual bool isInside(double u, double v, double w) const; virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); virtual MElement *getParent() const { return _orig; } - virtual void setParent(MElement *p, bool owner = false) { _orig = p; _owner = owner; } + virtual void setParent(MElement *p, bool owner = false) + { + _orig = p; + _owner = owner; + } virtual bool ownsParent() const { return _owner; } }; - // -------------------- Border classes class MTriangleBorder : public MTriangle { - protected: - MElement* _domains[2]; +protected: + MElement *_domains[2]; IntPt *_intpt; - public: - MTriangleBorder(MVertex *v0, MVertex *v1, MVertex *v2, int num = 0, int part = 0, - MElement* d1 = NULL, MElement* d2 = NULL) + +public: + MTriangleBorder(MVertex *v0, MVertex *v1, MVertex *v2, int num = 0, + int part = 0, MElement *d1 = NULL, MElement *d2 = NULL) : MTriangle(v0, v1, v2, num, part), _intpt(0) { - _domains[0] = d1; _domains[1] = d2; + _domains[0] = d1; + _domains[1] = d2; } MTriangleBorder(const std::vector<MVertex *> &v, int num = 0, int part = 0, MElement *d1 = NULL, MElement *d2 = NULL) - : MTriangle(v, num, part) - , _intpt(0) + : MTriangle(v, num, part), _intpt(0) { - _domains[0] = d1; _domains[1] = d2; + _domains[0] = d1; + _domains[1] = d2; } ~MTriangleBorder() {} - virtual MElement* getDomain(int i) const { return _domains[i]; } - virtual void setDomain (MElement *d, int i) { _domains[i] = d; } - virtual MElement *getParent() const { + virtual MElement *getDomain(int i) const { return _domains[i]; } + virtual void setDomain(MElement *d, int i) { _domains[i] = d; } + virtual MElement *getParent() const + { if(_domains[0]) return _domains[0]->getParent(); if(_domains[1]) return _domains[1]->getParent(); return NULL; } virtual int getTypeForMSH() const { return MSH_TRI_B; } virtual bool isInside(double u, double v, double w) const; - // the integration points of the MTriangleBorder are in the parent element space + // the integration points of the MTriangleBorder are in the parent element + // space virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); }; class MPolygonBorder : public MPolygon { - protected: - MElement* _domains[2]; +protected: + MElement *_domains[2]; IntPt *_intpt; - public: - MPolygonBorder(const std::vector<MTriangle *> &v, int num = 0, int part = 0, - bool own = false, MElement *p = NULL, MElement *d1 = NULL, - MElement *d2 = NULL) - : MPolygon(v, num, part, own, p) - , _intpt(0) - { - _domains[0] = d1; - _domains[1] = d2; + +public: + MPolygonBorder(const std::vector<MTriangle *> &v, int num = 0, int part = 0, + bool own = false, MElement *p = NULL, MElement *d1 = NULL, + MElement *d2 = NULL) + : MPolygon(v, num, part, own, p), _intpt(0) + { + _domains[0] = d1; + _domains[1] = d2; } MPolygonBorder(const std::vector<MVertex *> &v, int num = 0, int part = 0, bool own = false, MElement *p = NULL, MElement *d1 = NULL, MElement *d2 = NULL) - : MPolygon(v, num, part, own, p) - , _intpt(0) + : MPolygon(v, num, part, own, p), _intpt(0) { - _domains[0] = d1; _domains[1] = d2; + _domains[0] = d1; + _domains[1] = d2; } ~MPolygonBorder() {} - virtual MElement* getDomain(int i) const { return _domains[i]; } - virtual void setDomain (MElement *d, int i) { _domains[i] = d; } - virtual MElement *getParent() const { + virtual MElement *getDomain(int i) const { return _domains[i]; } + virtual void setDomain(MElement *d, int i) { _domains[i] = d; } + virtual MElement *getParent() const + { if(_domains[0]) return _domains[0]->getParent(); if(_domains[1]) return _domains[1]->getParent(); return NULL; @@ -454,27 +493,30 @@ class MPolygonBorder : public MPolygon { }; class MLineBorder : public MLine { - protected: - MElement* _domains[2]; +protected: + MElement *_domains[2]; IntPt *_intpt; - public: + +public: MLineBorder(MVertex *v0, MVertex *v1, int num = 0, int part = 0, - MElement* d1 = NULL, MElement* d2 = NULL) + MElement *d1 = NULL, MElement *d2 = NULL) : MLine(v0, v1, num, part), _intpt(0) { - _domains[0] = d1; _domains[1] = d2; + _domains[0] = d1; + _domains[1] = d2; } MLineBorder(const std::vector<MVertex *> &v, int num = 0, int part = 0, MElement *d1 = NULL, MElement *d2 = NULL) - : MLine(v, num, part) - , _intpt(0) + : MLine(v, num, part), _intpt(0) { - _domains[0] = d1; _domains[1] = d2; + _domains[0] = d1; + _domains[1] = d2; } ~MLineBorder() {} - virtual MElement* getDomain(int i) const { return _domains[i]; } - virtual void setDomain (MElement *d, int i) { _domains[i] = d; } - virtual MElement *getParent() const { + virtual MElement *getDomain(int i) const { return _domains[i]; } + virtual void setDomain(MElement *d, int i) { _domains[i] = d; } + virtual MElement *getParent() const + { if(_domains[0]) return _domains[0]->getParent(); if(_domains[1]) return _domains[1]->getParent(); return NULL; @@ -492,12 +534,12 @@ class MLineBorder : public MLine { // The physical and elementary numbers of the elements with ls > 0 are // the maximum physical and elementary numbers existing in their dimension + 1. // The physical and elementary numbers of the elements on the border (ls=0) are -// the levelset tag, unless an entity of the same dimension has already this number, -// knowing that the elements are cut in ascending dimension order (points, lines, -// surfaces and then volumes). +// the levelset tag, unless an entity of the same dimension has already this +// number, knowing that the elements are cut in ascending dimension order +// (points, lines, surfaces and then volumes). GModel *buildCutMesh(GModel *gm, gLevelset *ls, - std::map<int, std::vector<MElement*> > elements[10], - std::map<int, MVertex*> &vertexMap, + std::map<int, std::vector<MElement *> > elements[10], + std::map<int, MVertex *> &vertexMap, std::map<int, std::map<int, std::string> > physicals[4], bool cutElem); diff --git a/Geo/MElementOctree.cpp b/Geo/MElementOctree.cpp index 67ebe3472187e0eb4306d8b7a7ef1a0b49e36352..c8688212c6634225dcee165d7386368690be6350 100644 --- a/Geo/MElementOctree.cpp +++ b/Geo/MElementOctree.cpp @@ -61,13 +61,17 @@ void MElementBB(void *a, double *min, double *max) static void MElementCentroid(void *a, double *x) { - MElement *e = (MElement*)a; + MElement *e = (MElement *)a; MVertex *v = e->getVertex(0); int n = e->getNumVertices(); - x[0] = v->x(); x[1] = v->y(); x[2] = v->z(); + x[0] = v->x(); + x[1] = v->y(); + x[2] = v->z(); for(int i = 1; i < n; i++) { v = e->getVertex(i); - x[0] += v->x(); x[1] += v->y(); x[2] += v->z(); + x[0] += v->x(); + x[1] += v->y(); + x[2] += v->z(); } double oc = 1. / (double)n; x[0] *= oc; @@ -77,7 +81,7 @@ static void MElementCentroid(void *a, double *x) int MElementInEle(void *a, double *x) { - MElement *e = (MElement*)a; + MElement *e = (MElement *)a; double uvw[3]; e->xyz2uvw(x, uvw); return e->isInside(uvw[0], uvw[1], uvw[2]) ? 1 : 0; @@ -92,39 +96,38 @@ MElementOctree::MElementOctree(GModel *m) : _gm(m) bbmin -= bbeps; bbmax += bbeps; double min[3] = {bbmin.x(), bbmin.y(), bbmin.z()}; - double size[3] = {bbmax.x() - bbmin.x(), - bbmax.y() - bbmin.y(), + double size[3] = {bbmax.x() - bbmin.x(), bbmax.y() - bbmin.y(), bbmax.z() - bbmin.z()}; const int maxElePerBucket = 100; // memory vs. speed trade-off - _octree = Octree_Create(maxElePerBucket, min, size, - MElementBB, MElementCentroid, MElementInEle); - std::vector<GEntity*> entities; + _octree = Octree_Create(maxElePerBucket, min, size, MElementBB, + MElementCentroid, MElementInEle); + std::vector<GEntity *> entities; m->getEntities(entities); // do not add Gvertex non-associated to any GEdge - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ - if (entities[i]->dim() == 0){ - GVertex *gv = dynamic_cast<GVertex*>(entities[i]); - if (gv && gv->edges().size() > 0){ - Octree_Insert(entities[i]->getMeshElement(j), _octree); - } - } - else - Octree_Insert(entities[i]->getMeshElement(j), _octree); + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { + if(entities[i]->dim() == 0) { + GVertex *gv = dynamic_cast<GVertex *>(entities[i]); + if(gv && gv->edges().size() > 0) { + Octree_Insert(entities[i]->getMeshElement(j), _octree); + } + } + else + Octree_Insert(entities[i]->getMeshElement(j), _octree); } } - //exit(1); + // exit(1); Octree_Arrange(_octree); } -MElementOctree::MElementOctree(const std::vector<MElement*> &v) : _gm(0), _elems(v) +MElementOctree::MElementOctree(const std::vector<MElement *> &v) + : _gm(0), _elems(v) { SBoundingBox3d bb; - for (std::size_t i = 0; i < v.size(); i++){ - for(std::size_t j = 0; j < v[i]->getNumVertices(); j++){ - //if (!_gm) _gm = v[i]->getVertex(j)->onWhat()->model(); - bb += SPoint3(v[i]->getVertex(j)->x(), - v[i]->getVertex(j)->y(), + for(std::size_t i = 0; i < v.size(); i++) { + for(std::size_t j = 0; j < v[i]->getNumVertices(); j++) { + // if (!_gm) _gm = v[i]->getVertex(j)->onWhat()->model(); + bb += SPoint3(v[i]->getVertex(j)->x(), v[i]->getVertex(j)->y(), v[i]->getVertex(j)->z()); } } @@ -134,23 +137,16 @@ MElementOctree::MElementOctree(const std::vector<MElement*> &v) : _gm(0), _elems bbmin -= bbeps; bbmax += bbeps; double min[3] = {bbmin.x(), bbmin.y(), bbmin.z()}; - double size[3] = {bbmax.x() - bbmin.x(), - bbmax.y() - bbmin.y(), + double size[3] = {bbmax.x() - bbmin.x(), bbmax.y() - bbmin.y(), bbmax.z() - bbmin.z()}; const int maxElePerBucket = 100; // memory vs. speed trade-off - _octree = Octree_Create(maxElePerBucket, min, size, - MElementBB, MElementCentroid, MElementInEle); - for (unsigned int i = 0; i < v.size(); i++) - Octree_Insert(v[i], _octree); + _octree = Octree_Create(maxElePerBucket, min, size, MElementBB, + MElementCentroid, MElementInEle); + for(unsigned int i = 0; i < v.size(); i++) Octree_Insert(v[i], _octree); Octree_Arrange(_octree); } - -MElementOctree::~MElementOctree() -{ - Octree_Delete(_octree); -} - +MElementOctree::~MElementOctree() { Octree_Delete(_octree); } std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, int dim, bool strict) @@ -159,26 +155,26 @@ std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, double tolIncr = 10.; double P[3] = {x, y, z}; - std::vector<void*> v; - std::vector<MElement*> e; - Octree_SearchAll(P, _octree,&v); - for (std::vector<void*>::iterator it = v.begin(); it != v.end(); ++it) { - MElement *el = (MElement*) *it; - if (dim == -1 || el->getDim() == dim)e.push_back(el); + std::vector<void *> v; + std::vector<MElement *> e; + Octree_SearchAll(P, _octree, &v); + for(std::vector<void *>::iterator it = v.begin(); it != v.end(); ++it) { + MElement *el = (MElement *)*it; + if(dim == -1 || el->getDim() == dim) e.push_back(el); } - if (e.empty() && !strict && _gm) { + if(e.empty() && !strict && _gm) { double initialTol = MElement::getTolerance(); double tol = initialTol; - while (tol < maxTol){ + while(tol < maxTol) { tol *= tolIncr; MElement::setTolerance(tol); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; _gm->getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ - MElement* el = entities[i]->getMeshElement(j); - if (dim == -1 || el->getDim() == dim){ - if (MElementInEle(el, P)){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { + MElement *el = entities[i]->getMeshElement(j); + if(dim == -1 || el->getDim() == dim) { + if(MElementInEle(el, P)) { e.push_back(el); } } @@ -191,16 +187,16 @@ std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, } MElement::setTolerance(initialTol); } - else if (e.empty() && !strict && !_gm){ + else if(e.empty() && !strict && !_gm) { double initialTol = MElement::getTolerance(); double tol = initialTol; - while (tol < maxTol){ + while(tol < maxTol) { tol *= tolIncr; MElement::setTolerance(tol); - for(unsigned int i = 0; i < _elems.size(); i++){ - MElement* el = _elems[i]; - if (dim == -1 || el->getDim() == dim){ - if (MElementInEle(el, P)){ + for(unsigned int i = 0; i < _elems.size(); i++) { + MElement *el = _elems[i]; + if(dim == -1 || el->getDim() == dim) { + if(MElementInEle(el, P)) { e.push_back(el); } } @@ -211,40 +207,40 @@ std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, } } MElement::setTolerance(initialTol); - //Msg::Warning("Point %g %g %g not found",x,y,z); + // Msg::Warning("Point %g %g %g not found",x,y,z); } return e; } -MElement *MElementOctree::find(double x, double y, double z, int dim, bool strict) const +MElement *MElementOctree::find(double x, double y, double z, int dim, + bool strict) const { double P[3] = {x, y, z}; - MElement *e = (MElement*)Octree_Search(P, _octree); - if (e && (dim == -1 || e->getDim() == dim)) - return e; - std::vector<void*> l; - if (e && e->getDim() != dim) { + MElement *e = (MElement *)Octree_Search(P, _octree); + if(e && (dim == -1 || e->getDim() == dim)) return e; + std::vector<void *> l; + if(e && e->getDim() != dim) { Octree_SearchAll(P, _octree, &l); - for (std::vector<void*>::iterator it = l.begin(); it != l.end(); it++) { - MElement *el = (MElement*) *it; - if (el->getDim() == dim) { + for(std::vector<void *>::iterator it = l.begin(); it != l.end(); it++) { + MElement *el = (MElement *)*it; + if(el->getDim() == dim) { return el; } } } - if (!strict && _gm) { + if(!strict && _gm) { double initialTol = MElement::getTolerance(); double tol = initialTol; - while (tol < 1.){ + while(tol < 1.) { tol *= 10; MElement::setTolerance(tol); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; _gm->getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { e = entities[i]->getMeshElement(j); - if (dim == -1 || e->getDim() == dim){ - if (MElementInEle(e, P)) { + if(dim == -1 || e->getDim() == dim) { + if(MElementInEle(e, P)) { MElement::setTolerance(initialTol); return e; } @@ -253,18 +249,18 @@ MElement *MElementOctree::find(double x, double y, double z, int dim, bool stric } } MElement::setTolerance(initialTol); - //Msg::Warning("Point %g %g %g not found",x,y,z); + // Msg::Warning("Point %g %g %g not found",x,y,z); } - else if (!strict && !_gm){ + else if(!strict && !_gm) { double initialTol = MElement::getTolerance(); double tol = initialTol; - while (tol < 0.1){ + while(tol < 0.1) { tol *= 10.0; MElement::setTolerance(tol); - for(unsigned int i = 0; i < _elems.size(); i++){ + for(unsigned int i = 0; i < _elems.size(); i++) { e = _elems[i]; - if (dim == -1 || e->getDim() == dim){ - if (MElementInEle(e, P)){ + if(dim == -1 || e->getDim() == dim) { + if(MElementInEle(e, P)) { MElement::setTolerance(initialTol); return e; } @@ -272,7 +268,7 @@ MElement *MElementOctree::find(double x, double y, double z, int dim, bool stric } } MElement::setTolerance(initialTol); - //Msg::Warning("Point %g %g %g not found",x,y,z); + // Msg::Warning("Point %g %g %g not found",x,y,z); } return NULL; } diff --git a/Geo/MElementOctree.h b/Geo/MElementOctree.h index 0a2bd6229a4e8faeb4ee7124c40c4f54dc71f96e..4ac0e0f4ca83f4891f41d5e62703f5b1fb9874c5 100644 --- a/Geo/MElementOctree.h +++ b/Geo/MElementOctree.h @@ -12,17 +12,20 @@ class Octree; class GModel; class MElement; -class MElementOctree{ - private: +class MElementOctree { +private: Octree *_octree; GModel *_gm; - std::vector<MElement*> _elems; - public: + std::vector<MElement *> _elems; + +public: MElementOctree(GModel *); - MElementOctree(const std::vector<MElement*> &); + MElementOctree(const std::vector<MElement *> &); ~MElementOctree(); - MElement *find(double x, double y, double z, int dim = -1, bool strict = false) const; - Octree *getInternalOctree(){ return _octree; } - std::vector<MElement *> findAll(double x, double y, double z, int dim, bool strict = false); + MElement *find(double x, double y, double z, int dim = -1, + bool strict = false) const; + Octree *getInternalOctree() { return _octree; } + std::vector<MElement *> findAll(double x, double y, double z, int dim, + bool strict = false); }; #endif diff --git a/Geo/MFace.cpp b/Geo/MFace.cpp index c3132c3cd9e61679a101d3e46194012baaf32dfe..622cdb2d764cd2f3d7135ef41e2f8e6d3f210774 100644 --- a/Geo/MFace.cpp +++ b/Geo/MFace.cpp @@ -17,23 +17,28 @@ bool compare(const MVertex *const v0, const MVertex *const v1) return v0->getNum() < v1->getNum(); } -void sortVertices(const std::vector<MVertex*> &v, std::vector<char> &s) +void sortVertices(const std::vector<MVertex *> &v, std::vector<char> &s) { - if (v.size() == 3){ + if(v.size() == 3) { s.resize(3); - if (v[0]->getNum() < v[1]->getNum() && - v[0]->getNum() < v[2]->getNum() ){ - s[0] = 0; s[1] = 1; s[2] = 2; + if(v[0]->getNum() < v[1]->getNum() && v[0]->getNum() < v[2]->getNum()) { + s[0] = 0; + s[1] = 1; + s[2] = 2; } - else if (v[1]->getNum() < v[0]->getNum() && - v[1]->getNum() < v[2]->getNum() ){ - s[0] = 1; s[1] = 0; s[2] = 2; + else if(v[1]->getNum() < v[0]->getNum() && + v[1]->getNum() < v[2]->getNum()) { + s[0] = 1; + s[1] = 0; + s[2] = 2; } else { - s[0] = 2; s[1] = 0; s[2] = 1; + s[0] = 2; + s[1] = 0; + s[2] = 1; } - if (v[s[2]]->getNum() < v[s[1]]->getNum()){ + if(v[s[2]]->getNum() < v[s[1]]->getNum()) { char temp = s[1]; s[1] = s[2]; s[2] = temp; @@ -41,11 +46,12 @@ void sortVertices(const std::vector<MVertex*> &v, std::vector<char> &s) return; } - std::vector<MVertex*> sorted = v; + std::vector<MVertex *> sorted = v; std::sort(sorted.begin(), sorted.end(), compare); s.reserve(sorted.size()); for(unsigned int i = 0; i < sorted.size(); i++) - s.push_back(std::distance(v.begin(), std::find(v.begin(), v.end(), sorted[i]))); + s.push_back( + std::distance(v.begin(), std::find(v.begin(), v.end(), sorted[i]))); } MFace::MFace(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3) @@ -58,11 +64,10 @@ MFace::MFace(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3) sortVertices(_v, _si); } -MFace::MFace(const std::vector<MVertex*> &v) +MFace::MFace(const std::vector<MVertex *> &v) { _v.reserve(v.size()); - for(unsigned int i = 0; i < v.size(); i++) - _v.push_back(v[i]); + for(unsigned int i = 0; i < v.size(); i++) _v.push_back(v[i]); sortVertices(_v, _si); } @@ -70,7 +75,7 @@ double MFace::approximateArea() const { SPoint3 p0 = _v[0]->point(), p1 = _v[1]->point(), p2 = _v[2]->point(); double a = triangle_area(p0, p1, p2); - if (_v.size() == 3) return a; + if(_v.size() == 3) return a; a += triangle_area(p0, p2, _v[3]->point()); return a; } @@ -78,46 +83,45 @@ double MFace::approximateArea() const SVector3 MFace::normal() const { double n[3]; - normal3points(_v[0]->x(), _v[0]->y(), _v[0]->z(), - _v[1]->x(), _v[1]->y(), _v[1]->z(), - _v[2]->x(), _v[2]->y(), _v[2]->z(), n); + normal3points(_v[0]->x(), _v[0]->y(), _v[0]->z(), _v[1]->x(), _v[1]->y(), + _v[1]->z(), _v[2]->x(), _v[2]->y(), _v[2]->z(), n); return SVector3(n[0], n[1], n[2]); } -bool MFace::computeCorrespondence(const MFace &other, - int &rotation, +bool MFace::computeCorrespondence(const MFace &other, int &rotation, bool &swap) const { rotation = 0; swap = false; - if (*this == other) { - for (std::size_t i = 0; i < getNumVertices(); i++) { - if (_v[0] == other.getVertex(i)) { + if(*this == other) { + for(std::size_t i = 0; i < getNumVertices(); i++) { + if(_v[0] == other.getVertex(i)) { rotation = i; break; } } - if (_v[1] == other.getVertex((rotation + 1) % getNumVertices())) swap = false; - else swap = true; + if(_v[1] == other.getVertex((rotation + 1) % getNumVertices())) + swap = false; + else + swap = true; return true; } return false; } -MFaceN::MFaceN(int type, int order, const std::vector<MVertex*> &v) - : _type(type), _order(order) +MFaceN::MFaceN(int type, int order, const std::vector<MVertex *> &v) + : _type(type), _order(order) { _v.resize(v.size()); - for(unsigned int i = 0; i < v.size(); i++) - _v[i] = v[i]; + for(unsigned int i = 0; i < v.size(); i++) _v[i] = v[i]; } MEdgeN MFaceN::getHighOrderEdge(int num, int sign) const { int nCorner = getNumCorners(); - std::vector<MVertex*> vertices((unsigned int)_order + 1); - if (sign == 1) { + std::vector<MVertex *> vertices((unsigned int)_order + 1); + if(sign == 1) { vertices[0] = _v[num]; vertices[1] = _v[(num + 1) % nCorner]; } @@ -128,18 +132,18 @@ MEdgeN MFaceN::getHighOrderEdge(int num, int sign) const int start = nCorner + num * (_order - 1); int end = nCorner + (num + 1) * (_order - 1); int k = 1; - if (sign == 1) { - for (int i = start; i < end; ++i) vertices[++k] = _v[i]; + if(sign == 1) { + for(int i = start; i < end; ++i) vertices[++k] = _v[i]; } else { - for (int i = end-1; i >= start; --i) vertices[++k] = _v[i]; + for(int i = end - 1; i >= start; --i) vertices[++k] = _v[i]; } return MEdgeN(vertices); } MFace MFaceN::getFace() const { - if (_type == TYPE_TRI) + if(_type == TYPE_TRI) return MFace(_v[0], _v[1], _v[2]); else return MFace(_v[0], _v[1], _v[2], _v[3]); @@ -154,7 +158,7 @@ SPoint3 MFaceN::pnt(double u, double v) const fs->f(u, v, 0, f); double x = 0, y = 0, z = 0; - for (int j = 0; j < fs->getNumShapeFunctions(); j++) { + for(int j = 0; j < fs->getNumShapeFunctions(); j++) { x += f[j] * _v[j]->x(); y += f[j] * _v[j]->y(); z += f[j] * _v[j]->z(); @@ -164,7 +168,7 @@ SPoint3 MFaceN::pnt(double u, double v) const SVector3 MFaceN::tangent(double u, double v, int num) const { - if (num != 0 && num != 1) num = 0; + if(num != 0 && num != 1) num = 0; int tag = ElementType::getType(_type, _order); const nodalBasis *fs = BasisFactory::getNodalBasis(tag); @@ -173,7 +177,7 @@ SVector3 MFaceN::tangent(double u, double v, int num) const fs->df(u, v, 0, sf); double dx = 0, dy = 0, dz = 0; - for (int j = 0; j < fs->getNumShapeFunctions(); j++) { + for(int j = 0; j < fs->getNumShapeFunctions(); j++) { dx += sf[j][num] * _v[j]->x(); dy += sf[j][num] * _v[j]->y(); dz += sf[j][num] * _v[j]->z(); @@ -190,8 +194,8 @@ SVector3 MFaceN::normal(double u, double v) const fs->df(u, v, 0, sf); double dx[2] = {0, 0}, dy[2] = {0, 0}, dz[2] = {0, 0}; - for (int j = 0; j < fs->getNumShapeFunctions(); j++) { - for (int k = 0; k < 1; ++k) { + for(int j = 0; j < fs->getNumShapeFunctions(); j++) { + for(int k = 0; k < 1; ++k) { dx[k] += sf[j][k] * _v[j]->x(); dy[k] += sf[j][k] * _v[j]->y(); dz[k] += sf[j][k] * _v[j]->z(); @@ -204,8 +208,8 @@ SVector3 MFaceN::normal(double u, double v) const return crossprod(t0, t1).unit(); } -void MFaceN::frame(double u, double v, - SVector3 &t0, SVector3 &t1, SVector3 &n) const +void MFaceN::frame(double u, double v, SVector3 &t0, SVector3 &t1, + SVector3 &n) const { int tag = ElementType::getType(_type, _order); const nodalBasis *fs = BasisFactory::getNodalBasis(tag); @@ -214,8 +218,8 @@ void MFaceN::frame(double u, double v, fs->df(u, v, 0, sf); double dx[2] = {0, 0}, dy[2] = {0, 0}, dz[2] = {0, 0}; - for (int j = 0; j < fs->getNumShapeFunctions(); j++) { - for (int k = 0; k < 2; ++k) { + for(int j = 0; j < fs->getNumShapeFunctions(); j++) { + for(int k = 0; k < 2; ++k) { dx[k] += sf[j][k] * _v[j]->x(); dy[k] += sf[j][k] * _v[j]->y(); dz[k] += sf[j][k] * _v[j]->z(); @@ -224,11 +228,11 @@ void MFaceN::frame(double u, double v, t0 = SVector3(dx[0], dy[0], dz[0]).unit(); t1 = SVector3(dx[1], dy[1], dz[1]).unit(); - n = crossprod(t0, t1); + n = crossprod(t0, t1); } -void MFaceN::frame(double u, double v, SPoint3 &p, - SVector3 &t0, SVector3 &t1, SVector3 &n) const +void MFaceN::frame(double u, double v, SPoint3 &p, SVector3 &t0, SVector3 &t1, + SVector3 &n) const { int tag = ElementType::getType(_type, _order); const nodalBasis *fs = BasisFactory::getNodalBasis(tag); @@ -240,11 +244,11 @@ void MFaceN::frame(double u, double v, SPoint3 &p, double x = 0, y = 0, z = 0; double dx[2] = {0, 0}, dy[2] = {0, 0}, dz[2] = {0, 0}; - for (int j = 0; j < fs->getNumShapeFunctions(); j++) { + for(int j = 0; j < fs->getNumShapeFunctions(); j++) { x += f[j] * _v[j]->x(); y += f[j] * _v[j]->y(); z += f[j] * _v[j]->z(); - for (int k = 0; k < 2; ++k) { + for(int k = 0; k < 2; ++k) { dx[k] += sf[j][k] * _v[j]->x(); dy[k] += sf[j][k] * _v[j]->y(); dz[k] += sf[j][k] * _v[j]->z(); @@ -254,19 +258,19 @@ void MFaceN::frame(double u, double v, SPoint3 &p, p = SPoint3(x, y, z); t0 = SVector3(dx[0], dy[0], dz[0]).unit(); t1 = SVector3(dx[1], dy[1], dz[1]).unit(); - n = crossprod(t0, t1); + n = crossprod(t0, t1); } void MFaceN::repositionInnerVertices(const fullMatrix<double> *placement) const { int nCorner = getNumCorners(); int start = nCorner + (_order - 1) * nCorner; - for (int i = start; i < (int)_v.size(); ++i) { + for(int i = start; i < (int)_v.size(); ++i) { MVertex *v = _v[i]; v->x() = 0; v->y() = 0; v->z() = 0; - for (int j = 0; j < placement->size2(); ++j) { + for(int j = 0; j < placement->size2(); ++j) { const double coeff = (*placement)(i - start, j); v->x() += coeff * _v[j]->x(); v->y() += coeff * _v[j]->y(); diff --git a/Geo/MFaceHash.h b/Geo/MFaceHash.h index c4a9ab46d6c5c902e66a16b17eec14ea1453c42c..b18e606e1619a0cd4bbae6324fe435ffc084f192 100644 --- a/Geo/MFaceHash.h +++ b/Geo/MFaceHash.h @@ -14,7 +14,7 @@ struct Hash_Face : public std::unary_function<MFace, size_t> { { const MVertex *v[4]; f.getOrderedVertices(v); - return HashFNV1a<sizeof(MVertex*[4])>::eval(v); + return HashFNV1a<sizeof(MVertex * [4])>::eval(v); } }; diff --git a/Geo/MHexahedron.cpp b/Geo/MHexahedron.cpp index b17963997f32f2185207c3c9ed7c17626c672bcd..92bad84e6c54350791d6ffe6aee5833f4e189878 100644 --- a/Geo/MHexahedron.cpp +++ b/Geo/MHexahedron.cpp @@ -18,15 +18,19 @@ std::map<int, IndicesReversed> MHexahedronN::_order2indicesReversedHex; -void MHexahedron::getEdgeRep(bool curved, int num, double *x, double *y, double *z, - SVector3 *n) +void MHexahedron::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { // don't use MElement::_getEdgeRep: it's slow due to the creation of MFaces MVertex *v0 = _v[edges_hexa(num, 0)]; MVertex *v1 = _v[edges_hexa(num, 1)]; - x[0] = v0->x(); y[0] = v0->y(); z[0] = v0->z(); - x[1] = v1->x(); y[1] = v1->y(); z[1] = v1->z(); - if(CTX::instance()->mesh.lightLines > 1){ + x[0] = v0->x(); + y[0] = v0->y(); + z[0] = v0->z(); + x[1] = v1->x(); + y[1] = v1->y(); + z[1] = v1->z(); + if(CTX::instance()->mesh.lightLines > 1) { static const int vv[12] = {2, 2, 3, 3, 2, 0, 1, 0, 6, 5, 4, 4}; MVertex *v2 = _v[vv[num]]; SVector3 t1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); @@ -35,7 +39,7 @@ void MHexahedron::getEdgeRep(bool curved, int num, double *x, double *y, double normal.normalize(); n[0] = n[1] = normal; } - else{ + else { n[0] = n[1] = SVector3(0., 0., 1.); } } @@ -53,9 +57,12 @@ int MHexahedron::getVolumeSign() mat[2][1] = _v[3]->z() - _v[0]->z(); mat[2][2] = _v[4]->z() - _v[0]->z(); double d = det3x3(mat); - if(d < 0.) return -1; - else if(d > 0.) return 1; - else return 0; + if(d < 0.) + return -1; + else if(d > 0.) + return 1; + else + return 0; } void MHexahedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) @@ -69,26 +76,26 @@ double MHexahedron::angleShapeMeasure() #if defined(HAVE_MESH) return qmHexahedron::angles(this); #else - return 0.; + return 0.; #endif - } double MHexahedron::getInnerRadius() { - //Only for vertically aligned elements (not inclined) - double innerRadius=std::numeric_limits<double>::max(); - for (int i=0; i<getNumFaces(); i++){ + // Only for vertically aligned elements (not inclined) + double innerRadius = std::numeric_limits<double>::max(); + for(int i = 0; i < getNumFaces(); i++) { MQuadrangle quad(getFace(i).getVertex(0), getFace(i).getVertex(1), getFace(i).getVertex(2), getFace(i).getVertex(3)); - innerRadius=std::min(innerRadius,quad.getInnerRadius()); + innerRadius = std::min(innerRadius, quad.getInnerRadius()); } return innerRadius; } -bool MHexahedron::getFaceInfo(const MFace &face, int &ithFace, int &sign, int &rot) const +bool MHexahedron::getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const { - for (ithFace = 0; ithFace < 6; ithFace++){ - if (_getFaceInfo(getFace(ithFace), face, sign, rot)) return true; + for(ithFace = 0; ithFace < 6; ithFace++) { + if(_getFaceInfo(getFace(ithFace), face, sign, rot)) return true; } Msg::Error("Could not get face information for hexahedron %d", getNum()); return false; @@ -96,72 +103,77 @@ bool MHexahedron::getFaceInfo(const MFace &face, int &ithFace, int &sign, int &r int MHexahedron::numCommonNodesInDualGraph(const MElement *const other) const { - switch (other->getType()) - { - case TYPE_PNT: return 1; - case TYPE_LIN: return 2; - case TYPE_TRI: return 3; - default: return 4; + switch(other->getType()) { + case TYPE_PNT: return 1; + case TYPE_LIN: return 2; + case TYPE_TRI: return 3; + default: return 4; } } -static void _myGetEdgeRep(MHexahedron *hex, int num, double *x, double *y, double *z, - SVector3 *n, int numSubEdges) { - - //const int numSubEdges = CTX::instance()->mesh.numSubEdges; - static double pp[8][3] = { - {-1,-1,-1},{1,-1,-1},{1,1,-1},{-1,1,-1}, - {-1,-1,1},{1,-1,1},{1,1,1},{-1,1,1} }; - static int ed [12][2] = { - {0,1},{0,3},{0,4},{1,2},{1,5},{2,3}, - {2,6},{3,7},{4,5},{4,7},{5,6},{7,6} - }; +static void _myGetEdgeRep(MHexahedron *hex, int num, double *x, double *y, + double *z, SVector3 *n, int numSubEdges) +{ + // const int numSubEdges = CTX::instance()->mesh.numSubEdges; + static double pp[8][3] = {{-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}, + {-1, -1, 1}, {1, -1, 1}, {1, 1, 1}, {-1, 1, 1}}; + static int ed[12][2] = {{0, 1}, {0, 3}, {0, 4}, {1, 2}, {1, 5}, {2, 3}, + {2, 6}, {3, 7}, {4, 5}, {4, 7}, {5, 6}, {7, 6}}; int iEdge = num / numSubEdges; int iSubEdge = num % numSubEdges; - int iVertex1 = ed [iEdge][0]; - int iVertex2 = ed [iEdge][1]; - double t1 = (double) iSubEdge / (double) numSubEdges; - double u1 = pp[iVertex1][0] * (1.-t1) + pp[iVertex2][0] * t1; - double v1 = pp[iVertex1][1] * (1.-t1) + pp[iVertex2][1] * t1; - double w1 = pp[iVertex1][2] * (1.-t1) + pp[iVertex2][2] * t1; + int iVertex1 = ed[iEdge][0]; + int iVertex2 = ed[iEdge][1]; + double t1 = (double)iSubEdge / (double)numSubEdges; + double u1 = pp[iVertex1][0] * (1. - t1) + pp[iVertex2][0] * t1; + double v1 = pp[iVertex1][1] * (1. - t1) + pp[iVertex2][1] * t1; + double w1 = pp[iVertex1][2] * (1. - t1) + pp[iVertex2][2] * t1; - double t2 = (double) (iSubEdge+1) / (double) numSubEdges; - double u2 = pp[iVertex1][0] * (1.-t2) + pp[iVertex2][0] * t2; - double v2 = pp[iVertex1][1] * (1.-t2) + pp[iVertex2][1] * t2; - double w2 = pp[iVertex1][2] * (1.-t2) + pp[iVertex2][2] * t2; + double t2 = (double)(iSubEdge + 1) / (double)numSubEdges; + double u2 = pp[iVertex1][0] * (1. - t2) + pp[iVertex2][0] * t2; + double v2 = pp[iVertex1][1] * (1. - t2) + pp[iVertex2][1] * t2; + double w2 = pp[iVertex1][2] * (1. - t2) + pp[iVertex2][2] * t2; SPoint3 pnt1, pnt2; hex->pnt(u1, v1, w1, pnt1); hex->pnt(u2, v2, w2, pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); // not great, but better than nothing - //static const int f[6] = {0, 0, 0, 1, 2, 3}; - n[0] = n[1] = 1 ; + // static const int f[6] = {0, 0, 0, 1, 2, 3}; + n[0] = n[1] = 1; } -void MHexahedron20::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MHexahedron20::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MHexahedron::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MHexahedron::getEdgeRep(false, num, x, y, z, n); } -void MHexahedron27::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MHexahedron27::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MHexahedron::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MHexahedron::getEdgeRep(false, num, x, y, z, n); } -void MHexahedronN::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MHexahedronN::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MHexahedron::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MHexahedron::getEdgeRep(false, num, x, y, z, n); } int MHexahedron20::getNumEdgesRep(bool curved) @@ -180,22 +192,21 @@ int MHexahedronN::getNumEdgesRep(bool curved) } void _myGetFaceRep(MHexahedron *hex, int num, double *x, double *y, double *z, - SVector3 *n, int numSubEdges) + SVector3 *n, int numSubEdges) { - static double pp[8][3] = { - {-1,-1,-1},{1,-1,-1},{1,1,-1},{-1,1,-1}, - {-1,-1,1},{1,-1,1},{1,1,1},{-1,1,1} }; + static double pp[8][3] = {{-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}, + {-1, -1, 1}, {1, -1, 1}, {1, 1, 1}, {-1, 1, 1}}; - int iFace = num / (2*numSubEdges * numSubEdges); - int iSubFace = num % (2*numSubEdges * numSubEdges); + int iFace = num / (2 * numSubEdges * numSubEdges); + int iSubFace = num % (2 * numSubEdges * numSubEdges); - int iVertex1 = hex->faces_hexa(iFace,0); - int iVertex2 = hex->faces_hexa(iFace,1); - int iVertex3 = hex->faces_hexa(iFace,2); - int iVertex4 = hex->faces_hexa(iFace,3); + int iVertex1 = hex->faces_hexa(iFace, 0); + int iVertex2 = hex->faces_hexa(iFace, 1); + int iVertex3 = hex->faces_hexa(iFace, 2); + int iVertex4 = hex->faces_hexa(iFace, 3); SPoint3 pnt1, pnt2, pnt3; - // double J1[3][3], J2[3][3], J3[3][3]; + // double J1[3][3], J2[3][3], J3[3][3]; /* 0 @@ -209,133 +220,121 @@ void _myGetFaceRep(MHexahedron *hex, int num, double *x, double *y, double *z, // on each layer, we have (numSubEdges) * 2 triangles // ix and iy are the coordinates of the sub-quadrangle - int io = iSubFace%2; - int ix = (iSubFace/2)/numSubEdges; - int iy = (iSubFace/2)%numSubEdges; + int io = iSubFace % 2; + int ix = (iSubFace / 2) / numSubEdges; + int iy = (iSubFace / 2) % numSubEdges; const double d = 2. / numSubEdges; - double ox = -1. + d*ix; - double oy = -1. + d*iy; - - if (io == 0){ - double U1 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V1 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W1 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double ox = -1. + d * ix; + double oy = -1. + d * iy; + + if(io == 0) { + double U1 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V1 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W1 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; ox += d; - double U2 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V2 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W2 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double U2 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V2 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W2 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; oy += d; - double U3 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V3 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W3 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double U3 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V3 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W3 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; hex->pnt(U1, V1, W1, pnt1); hex->pnt(U2, V2, W2, pnt2); hex->pnt(U3, V3, W3, pnt3); } - else{ - double U1 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V1 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W1 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + else { + double U1 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V1 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W1 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; ox += d; oy += d; - double U2 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V2 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W2 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double U2 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V2 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W2 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; ox -= d; - double U3 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V3 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W3 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double U3 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V3 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W3 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; hex->pnt(U1, V1, W1, pnt1); hex->pnt(U2, V2, W2, pnt2); hex->pnt(U3, V3, W3, pnt3); } - x[0] = pnt1.x(); x[1] = pnt2.x(); x[2] = pnt3.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); y[2] = pnt3.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); z[2] = pnt3.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + x[2] = pnt3.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + y[2] = pnt3.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); + z[2] = pnt3.z(); SVector3 d1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); SVector3 d2(x[2] - x[0], y[2] - y[0], z[2] - z[0]); @@ -345,66 +344,65 @@ void _myGetFaceRep(MHexahedron *hex, int num, double *x, double *y, double *z, n[2] = n[0]; } -void MHexahedron::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MHexahedron::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { #if defined(HAVE_VISUDEV) static const int fquad[24][4] = { - {0, 3, 2, 1}, {3, 2, 1, 0}, {2, 1, 0, 3}, {1, 0, 3, 2}, - {0, 1, 5, 4}, {1, 5, 4, 0}, {5, 4, 0, 1}, {4, 0, 1, 5}, - {0, 4, 7, 3}, {4, 7, 3, 0}, {7, 3, 0, 4}, {3, 0, 4, 7}, - {1, 2, 6, 5}, {2, 6, 5, 1}, {6, 5, 1, 2}, {5, 1, 2, 6}, - {2, 3, 7, 6}, {3, 7, 6, 2}, {7, 6, 2, 3}, {6, 2, 3, 7}, - {4, 5, 6, 7}, {5, 6, 7, 4}, {6, 7, 4, 5}, {7, 4, 5, 6} - }; - if (CTX::instance()->heavyVisu) { - if (CTX::instance()->mesh.numSubEdges > 1) { + {0, 3, 2, 1}, {3, 2, 1, 0}, {2, 1, 0, 3}, {1, 0, 3, 2}, {0, 1, 5, 4}, + {1, 5, 4, 0}, {5, 4, 0, 1}, {4, 0, 1, 5}, {0, 4, 7, 3}, {4, 7, 3, 0}, + {7, 3, 0, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {2, 6, 5, 1}, {6, 5, 1, 2}, + {5, 1, 2, 6}, {2, 3, 7, 6}, {3, 7, 6, 2}, {7, 6, 2, 3}, {6, 2, 3, 7}, + {4, 5, 6, 7}, {5, 6, 7, 4}, {6, 7, 4, 5}, {7, 4, 5, 6}}; + if(CTX::instance()->heavyVisu) { + if(CTX::instance()->mesh.numSubEdges > 1) { _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); return; } _getFaceRepQuad(getVertex(fquad[num][0]), getVertex(fquad[num][1]), - getVertex(fquad[num][2]), getVertex(fquad[num][3]), - x, y, z, n); + getVertex(fquad[num][2]), getVertex(fquad[num][3]), x, y, z, + n); return; } #endif - static const int f[12][3] = { - {0, 3, 2}, {0, 2, 1}, - {0, 1, 5}, {0, 5, 4}, - {0, 4, 7}, {0, 7, 3}, - {1, 2, 6}, {1, 6, 5}, - {2, 3, 7}, {2, 7, 6}, - {4, 5, 6}, {4, 6, 7} - }; + static const int f[12][3] = {{0, 3, 2}, {0, 2, 1}, {0, 1, 5}, {0, 5, 4}, + {0, 4, 7}, {0, 7, 3}, {1, 2, 6}, {1, 6, 5}, + {2, 3, 7}, {2, 7, 6}, {4, 5, 6}, {4, 6, 7}}; _getFaceRep(_v[f[num][0]], _v[f[num][1]], _v[f[num][2]], x, y, z, n); } -void MHexahedron20::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MHexahedron20::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MHexahedron::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MHexahedron::getFaceRep(false, num, x, y, z, n); } -void MHexahedron27::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MHexahedron27::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MHexahedron::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MHexahedron::getFaceRep(false, num, x, y, z, n); } -void MHexahedronN::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MHexahedronN::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MHexahedron::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MHexahedron::getFaceRep(false, num, x, y, z, n); } int MHexahedron::getNumFacesRep(bool curved) { #if defined(HAVE_VISUDEV) - if (CTX::instance()->heavyVisu) { - if (CTX::instance()->mesh.numSubEdges == 1) return 24; + if(CTX::instance()->heavyVisu) { + if(CTX::instance()->mesh.numSubEdges == 1) return 24; return 12 * std::pow(CTX::instance()->mesh.numSubEdges, 2); } #endif @@ -414,19 +412,19 @@ int MHexahedron::getNumFacesRep(bool curved) int MHexahedron20::getNumFacesRep(bool curved) { return curved ? 12 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MHexahedron::getNumFacesRep(curved); + MHexahedron::getNumFacesRep(curved); } int MHexahedron27::getNumFacesRep(bool curved) { return curved ? 12 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MHexahedron::getNumFacesRep(curved); + MHexahedron::getNumFacesRep(curved); } int MHexahedronN::getNumFacesRep(bool curved) { return curved ? 12 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MHexahedron::getNumFacesRep(curved); + MHexahedron::getNumFacesRep(curved); } void _getIndicesReversedHex(int order, IndicesReversed &indices) @@ -434,12 +432,12 @@ void _getIndicesReversedHex(int order, IndicesReversed &indices) fullMatrix<double> ref = gmshGenerateMonomialsHexahedron(order); indices.resize(ref.size1()); - for (int i = 0; i < ref.size1(); ++i) { + for(int i = 0; i < ref.size1(); ++i) { const double u = ref(i, 0); const double v = ref(i, 1); const double w = ref(i, 2); - for (int j = 0; j < ref.size1(); ++j) { - if (u == ref(j, 1) && v == ref(j, 0) && w == ref(j, 2)) { + for(int j = 0; j < ref.size1(); ++j) { + if(u == ref(j, 1) && v == ref(j, 0) && w == ref(j, 2)) { indices[i] = j; break; } @@ -451,7 +449,7 @@ void MHexahedronN::reverse() { std::map<int, IndicesReversed>::iterator it; it = _order2indicesReversedHex.find(_order); - if (it == _order2indicesReversedHex.end()) { + if(it == _order2indicesReversedHex.end()) { IndicesReversed indices; _getIndicesReversedHex(_order, indices); _order2indicesReversedHex[_order] = indices; @@ -461,20 +459,20 @@ void MHexahedronN::reverse() IndicesReversed &indices = it->second; // copy vertices - std::vector<MVertex*> oldv(8 + _vs.size()); - std::copy(_v, _v+8, oldv.begin()); - std::copy(_vs.begin(), _vs.end(), oldv.begin()+8); + std::vector<MVertex *> oldv(8 + _vs.size()); + std::copy(_v, _v + 8, oldv.begin()); + std::copy(_vs.begin(), _vs.end(), oldv.begin() + 8); // reverse - for (int i = 0; i < 8; ++i) { + for(int i = 0; i < 8; ++i) { _v[i] = oldv[indices[i]]; } - for (unsigned int i = 0; i < _vs.size(); ++i) { - _vs[i] = oldv[indices[8+i]]; + for(unsigned int i = 0; i < _vs.size(); ++i) { + _vs[i] = oldv[indices[8 + i]]; } } -//void _getIndicesHighOrderFace(int order, int numFace, int sign, int rot, +// void _getIndicesHighOrderFace(int order, int numFace, int sign, int rot, // IndicesHighOrderFace &indices) //{ // fullMatrix<double> ref = gmshGenerateMonomialsHexahedron(order); diff --git a/Geo/MHexahedron.h b/Geo/MHexahedron.h index ce85d8548c84d6aebc548e677ad12dedbf67b0df..531022b63dd4644dff1a8368b03b8427d29d2aba 100644 --- a/Geo/MHexahedron.h +++ b/Geo/MHexahedron.h @@ -26,45 +26,52 @@ * */ class MHexahedron : public MElement { - protected: +protected: MVertex *_v[8]; - void _getEdgeVertices(const int num, std::vector<MVertex*> &v) const + void _getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[edges_hexa(num, 0)]; v[1] = _v[edges_hexa(num, 1)]; } - void _getFaceVertices(const int num, std::vector<MVertex*> &v) const + void _getFaceVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[faces_hexa(num, 0)]; v[1] = _v[faces_hexa(num, 1)]; v[2] = _v[faces_hexa(num, 2)]; v[3] = _v[faces_hexa(num, 3)]; } - public : + +public: MHexahedron(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, - MVertex *v5, MVertex *v6, MVertex *v7, int num=0, int part=0) + MVertex *v5, MVertex *v6, MVertex *v7, int num = 0, int part = 0) : MElement(num, part) { - _v[0] = v0; _v[1] = v1; _v[2] = v2; _v[3] = v3; - _v[4] = v4; _v[5] = v5; _v[6] = v6; _v[7] = v7; + _v[0] = v0; + _v[1] = v1; + _v[2] = v2; + _v[3] = v3; + _v[4] = v4; + _v[5] = v5; + _v[6] = v6; + _v[7] = v7; } - MHexahedron(const std::vector<MVertex*> &v, int num=0, int part=0) + MHexahedron(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { for(int i = 0; i < 8; i++) _v[i] = v[i]; } - ~MHexahedron(){} + ~MHexahedron() {} virtual int getDim() const { return 3; } virtual std::size_t getNumVertices() const { return 8; } - virtual MVertex *getVertex(int num){ return _v[num]; } + virtual MVertex *getVertex(int num) { return _v[num]; } virtual const MVertex *getVertex(int num) const { return _v[num]; } - virtual void setVertex(int num, MVertex *v){ _v[num] = v; } + virtual void setVertex(int num, MVertex *v) { _v[num] = v; } virtual MVertex *getVertexDIFF(int num) { static const int map[8] = {2, 3, 7, 6, 0, 1, 5, 4}; return getVertex(map[num]); } - virtual int getNumEdges()const{ return 12; } + virtual int getNumEdges() const { return 12; } virtual MEdge getEdge(int num) const { return MEdge(_v[edges_hexa(num, 0)], _v[edges_hexa(num, 1)]); @@ -73,27 +80,28 @@ class MHexahedron : public MElement { { return edges_hexa(numEdge, numVert); } - virtual int getNumEdgesRep(bool curved){ return 12; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual int getNumEdgesRep(bool curved) { return 12; } + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); _getEdgeVertices(num, v); } - virtual int getNumFaces(){ return 6; } + virtual int getNumFaces() { return 6; } virtual MFace getFace(int num) const { - return MFace(_v[faces_hexa(num, 0)], - _v[faces_hexa(num, 1)], - _v[faces_hexa(num, 2)], - _v[faces_hexa(num, 3)]); + return MFace(_v[faces_hexa(num, 0)], _v[faces_hexa(num, 1)], + _v[faces_hexa(num, 2)], _v[faces_hexa(num, 3)]); } virtual double getInnerRadius(); virtual double angleShapeMeasure(); - virtual bool getFaceInfo(const MFace & face, int &ithFace, int &sign, int &rot) const; + virtual bool getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const; virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(4); _getFaceVertices(num, v); @@ -107,32 +115,69 @@ class MHexahedron : public MElement { virtual const char *getStringForDIFF() const { return "ElmB8n3D"; } virtual const char *getStringForINP() const { return "C3D8"; } virtual const char *getStringForKEY() const { return "_SOLID"; } - virtual const char *getStringForTOCHNOG() const { return "-hex8"; } + virtual const char *getStringForTOCHNOG() const { return "-hex8"; } virtual void reverse() { MVertex *tmp; - tmp = _v[0]; _v[0] = _v[2]; _v[2] = tmp; - tmp = _v[4]; _v[4] = _v[6]; _v[6] = tmp; + tmp = _v[0]; + _v[0] = _v[2]; + _v[2] = tmp; + tmp = _v[4]; + _v[4] = _v[6]; + _v[6] = tmp; } virtual int getVolumeSign(); virtual void getNode(int num, double &u, double &v, double &w) const { switch(num) { - case 0 : u = -1.; v = -1.; w = -1.; break; - case 1 : u = 1.; v = -1.; w = -1.; break; - case 2 : u = 1.; v = 1.; w = -1.; break; - case 3 : u = -1.; v = 1.; w = -1.; break; - case 4 : u = -1.; v = -1.; w = 1.; break; - case 5 : u = 1.; v = -1.; w = 1.; break; - case 6 : u = 1.; v = 1.; w = 1.; break; - case 7 : u = -1.; v = 1.; w = 1.; break; - default: u = 0.; v = 0.; w = 0.; break; + case 0: + u = -1.; + v = -1.; + w = -1.; + break; + case 1: + u = 1.; + v = -1.; + w = -1.; + break; + case 2: + u = 1.; + v = 1.; + w = -1.; + break; + case 3: + u = -1.; + v = 1.; + w = -1.; + break; + case 4: + u = -1.; + v = -1.; + w = 1.; + break; + case 5: + u = 1.; + v = -1.; + w = 1.; + break; + case 6: + u = 1.; + v = 1.; + w = 1.; + break; + case 7: + u = -1.; + v = 1.; + w = 1.; + break; + default: + u = 0.; + v = 0.; + w = 0.; + break; } } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0., 0., 0.); - } + virtual SPoint3 barycenterUVW() const { return SPoint3(0., 0., 0.); } virtual bool isInside(double u, double v, double w) const { double tol = getTolerance(); @@ -144,46 +189,24 @@ class MHexahedron : public MElement { virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); static int edges_hexa(const int edge, const int vert) { - static const int e[12][2] = { - {0, 1}, - {0, 3}, - {0, 4}, - {1, 2}, - {1, 5}, - {2, 3}, - {2, 6}, - {3, 7}, - {4, 5}, - {4, 7}, - {5, 6}, - {6, 7} - }; + static const int e[12][2] = {{0, 1}, {0, 3}, {0, 4}, {1, 2}, + {1, 5}, {2, 3}, {2, 6}, {3, 7}, + {4, 5}, {4, 7}, {5, 6}, {6, 7}}; return e[edge][vert]; } static int faces_hexa(const int face, const int vert) { - static const int f[6][4] = { - {0, 3, 2, 1}, - {0, 1, 5, 4}, - {0, 4, 7, 3}, - {1, 2, 6, 5}, - {2, 3, 7, 6}, - {4, 5, 6, 7} - }; + static const int f[6][4] = {{0, 3, 2, 1}, {0, 1, 5, 4}, {0, 4, 7, 3}, + {1, 2, 6, 5}, {2, 3, 7, 6}, {4, 5, 6, 7}}; return f[face][vert]; } static int faces2edge_hexa(const int face, const int edge) { // return -iedge - 1 if edge is inverted // iedge + 1 otherwise - static const int e[6][4] = { - {2, -6, -4, -1}, - {1, 5, -9, -3}, - {3, 10, -8, -2}, - {4, 7, -11, -5}, - {6, 8, -12, -7}, - {9, 11, 12, -10} - }; + static const int e[6][4] = {{2, -6, -4, -1}, {1, 5, -9, -3}, + {3, 10, -8, -2}, {4, 7, -11, -5}, + {6, 8, -12, -7}, {9, 11, 12, -10}}; return e[face][edge]; } virtual int numCommonNodesInDualGraph(const MElement *const other) const; @@ -206,92 +229,110 @@ class MHexahedron : public MElement { * */ class MHexahedron20 : public MHexahedron { - protected: +protected: MVertex *_vs[12]; - public : + +public: MHexahedron20(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, MVertex *v5, MVertex *v6, MVertex *v7, MVertex *v8, MVertex *v9, - MVertex *v10, MVertex *v11, MVertex *v12, MVertex *v13, MVertex *v14, - MVertex *v15, MVertex *v16, MVertex *v17, MVertex *v18, MVertex *v19, - int num=0, int part=0) + MVertex *v10, MVertex *v11, MVertex *v12, MVertex *v13, + MVertex *v14, MVertex *v15, MVertex *v16, MVertex *v17, + MVertex *v18, MVertex *v19, int num = 0, int part = 0) : MHexahedron(v0, v1, v2, v3, v4, v5, v6, v7, num, part) { - _vs[0] = v8; _vs[1] = v9; _vs[2] = v10; _vs[3] = v11; _vs[4] = v12; - _vs[5] = v13; _vs[6] = v14; _vs[7] = v15; _vs[8] = v16; _vs[9] = v17; - _vs[10] = v18; _vs[11] = v19; + _vs[0] = v8; + _vs[1] = v9; + _vs[2] = v10; + _vs[3] = v11; + _vs[4] = v12; + _vs[5] = v13; + _vs[6] = v14; + _vs[7] = v15; + _vs[8] = v16; + _vs[9] = v17; + _vs[10] = v18; + _vs[11] = v19; for(int i = 0; i < 12; i++) _vs[i]->setPolynomialOrder(2); } - MHexahedron20(const std::vector<MVertex*> &v, int num=0, int part=0) + MHexahedron20(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MHexahedron(v, num, part) { for(int i = 0; i < 12; i++) _vs[i] = v[8 + i]; for(int i = 0; i < 12; i++) _vs[i]->setPolynomialOrder(2); } - ~MHexahedron20(){} + ~MHexahedron20() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 20; } - virtual MVertex *getVertex(int num){ return num < 8 ? _v[num] : _vs[num - 8]; } - virtual const MVertex *getVertex(int num) const { return num < 8 ? _v[num] : _vs[num - 8]; } - virtual void setVertex(int num, MVertex *v){ if(num < 8) _v[num] = v; else _vs[num - 8] = v; } + virtual MVertex *getVertex(int num) + { + return num < 8 ? _v[num] : _vs[num - 8]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 8 ? _v[num] : _vs[num - 8]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 8) + _v[num] = v; + else + _vs[num - 8] = v; + } virtual MVertex *getVertexUNV(int num) { - static const int map[20] = {0, 8, 1, 11, 2, 13, 3, 9, 10, 12, - 14, 15, 4, 16, 5, 18, 6, 19, 7, 17}; + static const int map[20] = {0, 8, 1, 11, 2, 13, 3, 9, 10, 12, + 14, 15, 4, 16, 5, 18, 6, 19, 7, 17}; return getVertex(map[num]); } virtual MVertex *getVertexBDF(int num) { - static const int map[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, - 9, 10, 12, 14, 15, 16, 18, 19, 17}; + static const int map[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, + 13, 9, 10, 12, 14, 15, 16, 18, 19, 17}; return getVertex(map[num]); } virtual MVertex *getVertexINP(int num) { - static const int map[20]={0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, - 9, 16, 18, 19, 17, 10, 12, 14, 15}; + static const int map[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, + 13, 9, 16, 18, 19, 17, 10, 12, 14, 15}; return getVertex(map[num]); } virtual MVertex *getVertexKEY(int num) { - static const int map[20]={0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, - 9, 16, 18, 19, 17, 10, 12, 14, 15}; + static const int map[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, + 13, 9, 16, 18, 19, 17, 10, 12, 14, 15}; return getVertex(map[num]); } virtual MVertex *getVertexDIFF(int num) { - static const int map[20] = {2, 3, 7, 6, 0, 1, 5, 4, 9, 18, 12, - 19, 14, 11, 15, 13, 8, 16, 17, 10}; + static const int map[20] = {2, 3, 7, 6, 0, 1, 5, 4, 9, 18, + 12, 19, 14, 11, 15, 13, 8, 16, 17, 10}; return getVertex(map[num]); } virtual MVertex *getVertexVTK(int num) { - static const int map[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, - 9, 16, 18, 19, 17, 10, 12, 14, 15}; + static const int map[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, + 13, 9, 16, 18, 19, 17, 10, 12, 14, 15}; return getVertex(map[num]); } virtual int getNumEdgeVertices() const { return 12; } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MHexahedron::_getEdgeVertices(num, v); v[2] = _vs[num]; } virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(8); MHexahedron::_getFaceVertices(num, v); - static const int f[6][4] = { - {1, 5, 3, 0}, - {0, 4, 8, 2}, - {2, 9, 7, 1}, - {3, 6, 10, 4}, - {5, 7, 11, 6}, - {8, 10, 11, 9} - }; + static const int f[6][4] = {{1, 5, 3, 0}, {0, 4, 8, 2}, {2, 9, 7, 1}, + {3, 6, 10, 4}, {5, 7, 11, 6}, {8, 10, 11, 9}}; v[4] = _vs[f[num][0]]; v[5] = _vs[f[num][1]]; v[6] = _vs[f[num][2]]; @@ -307,19 +348,29 @@ class MHexahedron20 : public MHexahedron { virtual void reverse() { MVertex *tmp; - tmp = _v[0]; _v[0] = _v[2]; _v[2] = tmp; - tmp = _v[4]; _v[4] = _v[6]; _v[6] = tmp; + tmp = _v[0]; + _v[0] = _v[2]; + _v[2] = tmp; + tmp = _v[4]; + _v[4] = _v[6]; + _v[6] = tmp; MVertex *old[12]; for(int i = 0; i < 12; i++) old[i] = _vs[i]; - _vs[0] = old[3]; _vs[3] = old[0]; - _vs[1] = old[5]; _vs[5] = old[1]; - _vs[2] = old[6]; _vs[6] = old[2]; - _vs[8] = old[10]; _vs[10] = old[8]; - _vs[9] = old[11]; _vs[11] = old[9]; + _vs[0] = old[3]; + _vs[3] = old[0]; + _vs[1] = old[5]; + _vs[5] = old[1]; + _vs[2] = old[6]; + _vs[6] = old[2]; + _vs[8] = old[10]; + _vs[10] = old[8]; + _vs[9] = old[11]; + _vs[11] = old[9]; } virtual void getNode(int num, double &u, double &v, double &w) const { - num < 8 ? MHexahedron::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); + num < 8 ? MHexahedron::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } }; @@ -340,89 +391,118 @@ class MHexahedron20 : public MHexahedron { * */ class MHexahedron27 : public MHexahedron { - protected: +protected: MVertex *_vs[19]; - public : + +public: MHexahedron27(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, MVertex *v5, MVertex *v6, MVertex *v7, MVertex *v8, MVertex *v9, - MVertex *v10, MVertex *v11, MVertex *v12, MVertex *v13, MVertex *v14, - MVertex *v15, MVertex *v16, MVertex *v17, MVertex *v18, MVertex *v19, - MVertex *v20, MVertex *v21, MVertex *v22, MVertex *v23, MVertex *v24, - MVertex *v25, MVertex *v26, int num=0, int part=0) + MVertex *v10, MVertex *v11, MVertex *v12, MVertex *v13, + MVertex *v14, MVertex *v15, MVertex *v16, MVertex *v17, + MVertex *v18, MVertex *v19, MVertex *v20, MVertex *v21, + MVertex *v22, MVertex *v23, MVertex *v24, MVertex *v25, + MVertex *v26, int num = 0, int part = 0) : MHexahedron(v0, v1, v2, v3, v4, v5, v6, v7, num, part) { - _vs[0] = v8; _vs[1] = v9; _vs[2] = v10; _vs[3] = v11; _vs[4] = v12; - _vs[5] = v13; _vs[6] = v14; _vs[7] = v15; _vs[8] = v16; _vs[9] = v17; - _vs[10] = v18; _vs[11] = v19; _vs[12] = v20; _vs[13] = v21; _vs[14] = v22; - _vs[15] = v23; _vs[16] = v24; _vs[17] = v25; _vs[18] = v26; + _vs[0] = v8; + _vs[1] = v9; + _vs[2] = v10; + _vs[3] = v11; + _vs[4] = v12; + _vs[5] = v13; + _vs[6] = v14; + _vs[7] = v15; + _vs[8] = v16; + _vs[9] = v17; + _vs[10] = v18; + _vs[11] = v19; + _vs[12] = v20; + _vs[13] = v21; + _vs[14] = v22; + _vs[15] = v23; + _vs[16] = v24; + _vs[17] = v25; + _vs[18] = v26; for(int i = 0; i < 19; i++) _vs[i]->setPolynomialOrder(2); } - MHexahedron27(const std::vector<MVertex*> &v, int num=0, int part=0) + MHexahedron27(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MHexahedron(v, num, part) { for(int i = 0; i < 19; i++) _vs[i] = v[8 + i]; for(int i = 0; i < 19; i++) _vs[i]->setPolynomialOrder(2); } - ~MHexahedron27(){} + ~MHexahedron27() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 27; } - virtual MVertex *getVertex(int num){ return num < 8 ? _v[num] : _vs[num - 8]; } - virtual const MVertex *getVertex(int num) const { return num < 8 ? _v[num] : _vs[num - 8]; } - virtual void setVertex(int num, MVertex *v){ if(num < 8) _v[num] = v; else _vs[num - 8] = v; } + virtual MVertex *getVertex(int num) + { + return num < 8 ? _v[num] : _vs[num - 8]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 8 ? _v[num] : _vs[num - 8]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 8) + _v[num] = v; + else + _vs[num - 8] = v; + } virtual MVertex *getVertexINP(int num) { - static const int map[27] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 9, 16, 18, 19, - 17, 10, 12, 14, 15, 26, 20, 25, 21, 23, 24, 22}; + static const int map[27] = {0, 1, 2, 3, 4, 5, 6, 7, 8, + 11, 13, 9, 16, 18, 19, 17, 10, 12, + 14, 15, 26, 20, 25, 21, 23, 24, 22}; return getVertex(map[num]); } virtual MVertex *getVertexKEY(int num) { - static const int map[27] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 9, 16, 18, 19, - 17, 10, 12, 14, 15, 26, 20, 25, 21, 23, 24, 22}; + static const int map[27] = {0, 1, 2, 3, 4, 5, 6, 7, 8, + 11, 13, 9, 16, 18, 19, 17, 10, 12, + 14, 15, 26, 20, 25, 21, 23, 24, 22}; return getVertex(map[num]); } virtual MVertex *getVertexDIFF(int num) { - static const int map[27] = {6, 8, 26, 24, 0, 2, 20, 18, 7, 15, 3, 17, 5, 25, - 23, 21, 1, 9, 11, 19, 16, 4, 12, 14, 22, 10, 13}; + static const int map[27] = {6, 8, 26, 24, 0, 2, 20, 18, 7, + 15, 3, 17, 5, 25, 23, 21, 1, 9, + 11, 19, 16, 4, 12, 14, 22, 10, 13}; return getVertex(map[num]); } virtual MVertex *getVertexVTK(int num) { - static const int map[27] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 9, 16, 18, 19, - 17, 10, 12, 14,15, 22, 23, 21, 24, 20, 25, 26}; + static const int map[27] = {0, 1, 2, 3, 4, 5, 6, 7, 8, + 11, 13, 9, 16, 18, 19, 17, 10, 12, + 14, 15, 22, 23, 21, 24, 20, 25, 26}; return getVertex(map[num]); } virtual int getNumEdgeVertices() const { return 12; } virtual int getNumFaceVertices() const { return 6; } virtual int getNumVolumeVertices() const { return 1; } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MHexahedron::_getEdgeVertices(num, v); v[2] = _vs[num]; } virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(9); MHexahedron::_getFaceVertices(num, v); - static const int f[6][4] = { - {1, 5, 3, 0}, - {0, 4, 8, 2}, - {2, 9, 7, 1}, - {3, 6, 10, 4}, - {5, 7, 11, 6}, - {8, 10, 11, 9} - }; + static const int f[6][4] = {{1, 5, 3, 0}, {0, 4, 8, 2}, {2, 9, 7, 1}, + {3, 6, 10, 4}, {5, 7, 11, 6}, {8, 10, 11, 9}}; v[4] = _vs[f[num][0]]; v[5] = _vs[f[num][1]]; v[6] = _vs[f[num][2]]; v[7] = _vs[f[num][3]]; - v[8] = _vs[12+num]; + v[8] = _vs[12 + num]; } virtual int getTypeForMSH() const { return MSH_HEX_27; } virtual int getTypeForVTK() const { return 29; } @@ -434,23 +514,35 @@ class MHexahedron27 : public MHexahedron { virtual void reverse() { MVertex *tmp; - tmp = _v[0]; _v[0] = _v[2]; _v[2] = tmp; - tmp = _v[4]; _v[4] = _v[6]; _v[6] = tmp; + tmp = _v[0]; + _v[0] = _v[2]; + _v[2] = tmp; + tmp = _v[4]; + _v[4] = _v[6]; + _v[6] = tmp; MVertex *old[19]; for(int i = 0; i < 19; i++) old[i] = _vs[i]; // edge vertices - _vs[0] = old[3]; _vs[3] = old[0]; - _vs[1] = old[5]; _vs[5] = old[1]; - _vs[2] = old[6]; _vs[6] = old[2]; - _vs[8] = old[10]; _vs[10] = old[8]; - _vs[9] = old[11]; _vs[11] = old[9]; + _vs[0] = old[3]; + _vs[3] = old[0]; + _vs[1] = old[5]; + _vs[5] = old[1]; + _vs[2] = old[6]; + _vs[6] = old[2]; + _vs[8] = old[10]; + _vs[10] = old[8]; + _vs[9] = old[11]; + _vs[11] = old[9]; // face vertices - _vs[13] = old[15]; _vs[15] = old[13]; - _vs[14] = old[16]; _vs[16] = old[14]; + _vs[13] = old[15]; + _vs[15] = old[13]; + _vs[14] = old[16]; + _vs[16] = old[14]; } virtual void getNode(int num, double &u, double &v, double &w) const { - num < 8 ? MHexahedron::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); + num < 8 ? MHexahedron::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } }; @@ -483,86 +575,108 @@ class MHexahedron27 : public MHexahedron { */ typedef std::vector<int> IndicesReversed; -//typedef std::vector<int> IndicesHighOrderFace; -//typedef std::pair<std::pair<int,int>, std::pair<int,int> > TupleHighOrderFace; +// typedef std::vector<int> IndicesHighOrderFace; +// typedef std::pair<std::pair<int,int>, std::pair<int,int> > +// TupleHighOrderFace; class MHexahedronN : public MHexahedron { static std::map<int, IndicesReversed> _order2indicesReversedHex; -// static std::map<TupleHighOrderFace, IndicesHighOrderFace> _tuple2indicesHighOrderFace; + // static std::map<TupleHighOrderFace, IndicesHighOrderFace> + // _tuple2indicesHighOrderFace; - protected: +protected: const char _order; - std::vector<MVertex*> _vs; - public : - MHexahedronN(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, - MVertex *v4, MVertex *v5, MVertex *v6, MVertex *v7, - const std::vector<MVertex*> &v, char order, int num=0, int part=0) - : MHexahedron(v0, v1, v2, v3, v4, v5, v6, v7, num, part), _order(order), _vs(v) - { - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); - } - MHexahedronN(const std::vector<MVertex*> &v, char order, int num=0, int part=0) - : MHexahedron(v[0], v[1], v[2], v[3],v[4], v[5], v[6], v[7], num, part), _order(order) + std::vector<MVertex *> _vs; + +public: + MHexahedronN(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, + MVertex *v5, MVertex *v6, MVertex *v7, + const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) + : MHexahedron(v0, v1, v2, v3, v4, v5, v6, v7, num, part), _order(order), + _vs(v) + { + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); + } + MHexahedronN(const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) + : MHexahedron(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], num, part), + _order(order) { for(unsigned int i = 8; i < v.size(); i++) _vs.push_back(v[i]); - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); } - ~MHexahedronN(){} + ~MHexahedronN() {} virtual int getPolynomialOrder() const { return (int)_order; } virtual std::size_t getNumVertices() const { return 8 + _vs.size(); } - virtual MVertex *getVertex(int num){ return num < 8 ? _v[num] : _vs[num - 8]; } - virtual const MVertex *getVertex(int num) const { return num < 8 ? _v[num] : _vs[num - 8]; } - virtual void setVertex(int num, MVertex *v){ if(num < 8) _v[num] = v; else _vs[num - 8] = v; } + virtual MVertex *getVertex(int num) + { + return num < 8 ? _v[num] : _vs[num - 8]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 8 ? _v[num] : _vs[num - 8]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 8) + _v[num] = v; + else + _vs[num - 8] = v; + } virtual int getNumEdgeVertices() const { return 12 * (_order - 1); } virtual int getNumFaceVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; else - return 6 * (_order - 1)*(_order - 1); + return 6 * (_order - 1) * (_order - 1); } virtual int getNumVolumeVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; else return (_order - 1) * (_order - 1) * (_order - 1); } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { - v.resize(_order+1); + v.resize(_order + 1); MHexahedron::_getEdgeVertices(num, v); - for (int i = 0; i < _order - 1; i++) v[2+i] = _vs[(_order-1)*num+i]; + for(int i = 0; i < _order - 1; i++) v[2 + i] = _vs[(_order - 1) * num + i]; } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { - if (getIsAssimilatedSerendipity()) { + if(getIsAssimilatedSerendipity()) { v.resize(4 * _order); } else { - v.resize((_order+1) * (_order+1)); + v.resize((_order + 1) * (_order + 1)); } MHexahedron::_getFaceVertices(num, v); int count = 3; - int n = _order-1; - for (int i = 0; i < 4; i++) { - if(faces2edge_hexa(num, i) > 0){ + int n = _order - 1; + for(int i = 0; i < 4; i++) { + if(faces2edge_hexa(num, i) > 0) { int edge_num = faces2edge_hexa(num, i) - 1; - for (int j = 0; j < n; j++) v[++count] = _vs[n*edge_num + j]; + for(int j = 0; j < n; j++) v[++count] = _vs[n * edge_num + j]; } - else{ + else { int edge_num = -faces2edge_hexa(num, i) - 1; - for (int j = n-1; j >= 0; j--) v[++count] = _vs[n*edge_num + j]; + for(int j = n - 1; j >= 0; j--) v[++count] = _vs[n * edge_num + j]; } } - if ((int)v.size() > count + 1) { - int start = 12 * n + num * n*n; - for (int i = 0; i < n*n; i++){ + if((int)v.size() > count + 1) { + int start = 12 * n + num * n * n; + for(int i = 0; i < n * n; i++) { v[++count] = _vs[start + i]; } } @@ -570,9 +684,9 @@ class MHexahedronN : public MHexahedron { virtual int getTypeForMSH() const { // (p+1)^3 - if(_order == 1 && _vs.size() + 8 == 8) return MSH_HEX_8; - if(_order == 2 && _vs.size() + 8 == 27) return MSH_HEX_27; - if(_order == 3 && _vs.size() + 8 == 64 ) return MSH_HEX_64; + if(_order == 1 && _vs.size() + 8 == 8) return MSH_HEX_8; + if(_order == 2 && _vs.size() + 8 == 27) return MSH_HEX_27; + if(_order == 3 && _vs.size() + 8 == 64) return MSH_HEX_64; if(_order == 4 && _vs.size() + 8 == 125) return MSH_HEX_125; if(_order == 5 && _vs.size() + 8 == 216) return MSH_HEX_216; if(_order == 6 && _vs.size() + 8 == 343) return MSH_HEX_343; @@ -580,24 +694,27 @@ class MHexahedronN : public MHexahedron { if(_order == 8 && _vs.size() + 8 == 729) return MSH_HEX_729; if(_order == 9 && _vs.size() + 8 == 1000) return MSH_HEX_1000; - if(_order == 2 && _vs.size() + 8 == 20) return MSH_HEX_20; - if(_order == 3 && _vs.size() + 8 == 32) return MSH_HEX_32; - if(_order == 4 && _vs.size() + 8 == 44) return MSH_HEX_44; - if(_order == 5 && _vs.size() + 8 == 56) return MSH_HEX_56; - if(_order == 6 && _vs.size() + 8 == 68) return MSH_HEX_68; - if(_order == 7 && _vs.size() + 8 == 80) return MSH_HEX_80; - if(_order == 8 && _vs.size() + 8 == 92) return MSH_HEX_92; + if(_order == 2 && _vs.size() + 8 == 20) return MSH_HEX_20; + if(_order == 3 && _vs.size() + 8 == 32) return MSH_HEX_32; + if(_order == 4 && _vs.size() + 8 == 44) return MSH_HEX_44; + if(_order == 5 && _vs.size() + 8 == 56) return MSH_HEX_56; + if(_order == 6 && _vs.size() + 8 == 68) return MSH_HEX_68; + if(_order == 7 && _vs.size() + 8 == 80) return MSH_HEX_80; + if(_order == 8 && _vs.size() + 8 == 92) return MSH_HEX_92; if(_order == 9 && _vs.size() + 8 == 104) return MSH_HEX_104; - Msg::Error("no tag matches a p%d hexahedron with %d vertices", _order, 8+_vs.size()); + Msg::Error("no tag matches a p%d hexahedron with %d vertices", _order, + 8 + _vs.size()); return 0; } virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); virtual void reverse(); virtual void getNode(int num, double &u, double &v, double &w) const { - num < 8 ? MHexahedron::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); + num < 8 ? MHexahedron::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } }; diff --git a/Geo/MLine.cpp b/Geo/MLine.cpp index 561b477ea7345fd329712e7cb9f010a3e08bcffb..95259d40ffc9c2489838553dc469375147725155 100644 --- a/Geo/MLine.cpp +++ b/Geo/MLine.cpp @@ -18,40 +18,35 @@ void MLine::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) *pts = getGQLPts(pOrder); } -double MLine::getInnerRadius() -{ - return _v[0]->distance(_v[1]) * .5; -} +double MLine::getInnerRadius() { return _v[0]->distance(_v[1]) * .5; } -double MLine::getLength() -{ - return _v[0]->distance(_v[1]); -} +double MLine::getLength() { return _v[0]->distance(_v[1]); } -double MLine::getVolume() -{ - return getLength(); -} +double MLine::getVolume() { return getLength(); } int MLine3::getNumEdgesRep(bool curved) { return curved ? CTX::instance()->mesh.numSubEdges : 1; } -void MLine3::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MLine3::getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - if (curved) { + if(curved) { int numSubEdges = CTX::instance()->mesh.numSubEdges; SPoint3 pnt1, pnt2; pnt(-1. + 2 * (double)num / numSubEdges, 0., 0., pnt1); pnt(-1. + 2 * (double)(num + 1) / numSubEdges, 0., 0, pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); n[0] = n[1] = MEdge(_v[0], _v[1]).normal(); } - else MLine::getEdgeRep(false, num, x, y, z, n); + else + MLine::getEdgeRep(false, num, x, y, z, n); } int MLineN::getNumEdgesRep(bool curved) @@ -59,22 +54,28 @@ int MLineN::getNumEdgesRep(bool curved) return curved ? CTX::instance()->mesh.numSubEdges : 1; } -void MLineN::getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) +void MLineN::getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - if (curved) { + if(curved) { int numSubEdges = CTX::instance()->mesh.numSubEdges; SPoint3 pnt1, pnt2; pnt(-1. + 2 * (double)num / numSubEdges, 0., 0., pnt1); pnt(-1. + 2 * (double)(num + 1) / numSubEdges, 0., 0, pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); n[0] = n[1] = MEdge(_v[0], _v[1]).normal(); } - else MLine::getEdgeRep(false, num, x, y, z, n); + else + MLine::getEdgeRep(false, num, x, y, z, n); } -void MLine::discretize(double tol, std::vector<SPoint3> &dpts, std::vector<double> &ts) +void MLine::discretize(double tol, std::vector<SPoint3> &dpts, + std::vector<double> &ts) { ts.clear(); ts.push_back(-1); @@ -84,33 +85,33 @@ void MLine::discretize(double tol, std::vector<SPoint3> &dpts, std::vector<doubl dpts.push_back(getVertex(1)->point()); } -void MLine3::discretize(double tol, std::vector<SPoint3> &dpts, std::vector<double> &ts) +void MLine3::discretize(double tol, std::vector<SPoint3> &dpts, + std::vector<double> &ts) { SPoint3 p0 = getVertex(0)->point(); SPoint3 p2 = getVertex(1)->point(); - SPoint3 p1 = getVertex(2)->point() * 2 - (p0 + p2) * 0.5; + SPoint3 p1 = getVertex(2)->point() * 2 - (p0 + p2) * 0.5; decasteljau(tol, p0, p1, p2, dpts, ts); - for (size_t i = 0; i < ts.size(); ++i) - ts[i] = -1 + 2 * ts[i]; + for(size_t i = 0; i < ts.size(); ++i) ts[i] = -1 + 2 * ts[i]; } -void MLineN::discretize(double tol, std::vector<SPoint3> &dpts, std::vector<double> &ts) +void MLineN::discretize(double tol, std::vector<SPoint3> &dpts, + std::vector<double> &ts) { int order = getPolynomialOrder(); - if (order == 3) { + if(order == 3) { SPoint3 p0 = getVertex(0)->point(); SPoint3 p3 = getVertex(1)->point(); - SPoint3 p1 = p0 * (-5./6) + p3 * (1./3) + getVertex(2)->point() * 3. - - getVertex(3)->point() * 1.5; - SPoint3 p2 = p0 * (1./3) + p3 * (-5./6) - getVertex(2)->point() * 1.5 + - getVertex(3)->point() * 3.; + SPoint3 p1 = p0 * (-5. / 6) + p3 * (1. / 3) + getVertex(2)->point() * 3. - + getVertex(3)->point() * 1.5; + SPoint3 p2 = p0 * (1. / 3) + p3 * (-5. / 6) - getVertex(2)->point() * 1.5 + + getVertex(3)->point() * 3.; decasteljau(tol, p0, p1, p2, p3, dpts, ts); - for (size_t i = 0; i < ts.size(); ++i) - ts[i] = -1 + 2 * ts[i]; + for(size_t i = 0; i < ts.size(); ++i) ts[i] = -1 + 2 * ts[i]; return; } - fullMatrix<double> lagNodes(order + 1, 3), bezNodes( order + 1, 3); - for (int i = 0; i < order + 1; ++i) { + fullMatrix<double> lagNodes(order + 1, 3), bezNodes(order + 1, 3); + for(int i = 0; i < order + 1; ++i) { MVertex *v = getVertex(i); lagNodes(i, 0) = v->x(); lagNodes(i, 1) = v->y(); @@ -125,12 +126,11 @@ void MLineN::discretize(double tol, std::vector<SPoint3> &dpts, std::vector<doub pts[order][0] = bezNodes(1, 0); pts[order][1] = bezNodes(1, 1); pts[order][2] = bezNodes(1, 2); - for (int i = 0; i < order - 1; ++i) { + for(int i = 0; i < order - 1; ++i) { pts[i + 1][0] = bezNodes(i + 2, 0); pts[i + 1][1] = bezNodes(i + 2, 1); pts[i + 1][2] = bezNodes(i + 2, 2); } decasteljau(tol, pts, dpts, ts); - for (size_t i = 0; i < ts.size(); ++i) - ts[i] = -1 + 2 * ts[i]; + for(size_t i = 0; i < ts.size(); ++i) ts[i] = -1 + 2 * ts[i]; } diff --git a/Geo/MLine.h b/Geo/MLine.h index 2e76c27eb16a77984c0d3e02640f6bdd6a2a2f60..d58510685e97e91c2a525a6e4ce2925af69758a9 100644 --- a/Geo/MLine.h +++ b/Geo/MLine.h @@ -16,65 +16,73 @@ * */ class MLine : public MElement { - protected: +protected: MVertex *_v[2]; - void _getEdgeVertices(std::vector<MVertex*> &v) const + void _getEdgeVertices(std::vector<MVertex *> &v) const { v[0] = _v[0]; v[1] = _v[1]; } - public : - MLine(MVertex *v0, MVertex *v1, int num=0, int part=0) + +public: + MLine(MVertex *v0, MVertex *v1, int num = 0, int part = 0) : MElement(num, part) { - _v[0] = v0; _v[1] = v1; + _v[0] = v0; + _v[1] = v1; } - MLine(const std::vector<MVertex*> &v, int num=0, int part=0) + MLine(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { for(int i = 0; i < 2; i++) _v[i] = v[i]; } - ~MLine(){} + ~MLine() {} virtual int getDim() const { return 1; } virtual std::size_t getNumVertices() const { return 2; } - virtual MVertex *getVertex(int num){ return _v[num]; } - virtual const MVertex *getVertex(int num) const{ return _v[num]; } - virtual void setVertex(int num, MVertex *v){ _v[num] = v; } + virtual MVertex *getVertex(int num) { return _v[num]; } + virtual const MVertex *getVertex(int num) const { return _v[num]; } + virtual void setVertex(int num, MVertex *v) { _v[num] = v; } virtual double getInnerRadius(); // half-length of segment line virtual double getLength(); // length of segment line virtual double getVolume(); - virtual void getVertexInfo(const MVertex * vertex, int &ithVertex) const + virtual void getVertexInfo(const MVertex *vertex, int &ithVertex) const { ithVertex = _v[0] == vertex ? 0 : 1; } - virtual int getNumEdges()const{ return 1; } - virtual MEdge getEdge(int num) const{ return MEdge(_v[0], _v[1]); } - virtual int getNumEdgesRep(bool curved){ return 1; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual int getNumEdges() const { return 1; } + virtual MEdge getEdge(int num) const { return MEdge(_v[0], _v[1]); } + virtual int getNumEdgesRep(bool curved) { return 1; } + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { _getEdgeRep(_v[0], _v[1], x, y, z, n); } - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); _getEdgeVertices(v); } - virtual int getNumFaces(){ return 0; } + virtual int getNumFaces() { return 0; } virtual MFace getFace(int num) const { return MFace(); } - virtual int getNumFacesRep(bool curved){ return 0; } - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n){} + virtual int getNumFacesRep(bool curved) { return 0; } + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) + { + } virtual int getType() const { return TYPE_LIN; } virtual int getTypeForMSH() const { return MSH_LIN_2; } virtual int getTypeForUNV() const { return 21; } // linear beam virtual int getTypeForVTK() const { return 3; } virtual const char *getStringForPOS() const { return "SL"; } virtual const char *getStringForBDF() const { return "CBAR"; } - virtual const char *getStringForINP() const { return "T3D2"/*"C1D2"*/; } + virtual const char *getStringForINP() const { return "T3D2" /*"C1D2"*/; } virtual const char *getStringForKEY() const { return "_BEAM"; } virtual const char *getStringForTOCHNOG() const { return "-bar2"; } virtual void reverse() { - MVertex *tmp = _v[0]; _v[0] = _v[1]; _v[1] = tmp; + MVertex *tmp = _v[0]; + _v[0] = _v[1]; + _v[1] = tmp; } virtual bool isInside(double u, double v, double w) const { @@ -87,20 +95,19 @@ class MLine : public MElement { { v = w = 0.; switch(num) { - case 0 : u = -1.; break; - case 1 : u = 1.; break; - default: u = 0.; break; + case 0: u = -1.; break; + case 1: u = 1.; break; + default: u = 0.; break; } } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0, 0, 0); - } + virtual SPoint3 barycenterUVW() const { return SPoint3(0, 0, 0); } virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); - virtual void discretize(double tol, std::vector<SPoint3> &dpts, std::vector<double> &ts); + virtual void discretize(double tol, std::vector<SPoint3> &dpts, + std::vector<double> &ts); virtual int numCommonNodesInDualGraph(const MElement *const other) const { - return ((other->getType() == TYPE_LIN || other->getType() == TYPE_PNT) ? 1 : 2); + return ((other->getType() == TYPE_LIN || other->getType() == TYPE_PNT) ? 1 : + 2); } }; @@ -111,38 +118,52 @@ class MLine : public MElement { * */ class MLine3 : public MLine { - protected: +protected: MVertex *_vs[1]; - public : - MLine3(MVertex *v0, MVertex *v1, MVertex *v2, int num=0, int part=0) + +public: + MLine3(MVertex *v0, MVertex *v1, MVertex *v2, int num = 0, int part = 0) : MLine(v0, v1, num, part) { _vs[0] = v2; _vs[0]->setPolynomialOrder(2); } - MLine3(const std::vector<MVertex*> &v, int num=0, int part=0) + MLine3(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MLine(v, num, part) { _vs[0] = v[2]; _vs[0]->setPolynomialOrder(2); } - ~MLine3(){} + ~MLine3() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 3; } - virtual MVertex *getVertex(int num){ return num < 2 ? _v[num] : _vs[num - 2]; } - virtual const MVertex *getVertex(int num) const{ return num < 2 ? _v[num] : _vs[num - 2]; } - virtual void setVertex(int num, MVertex *v){ if(num < 2) _v[num] = v; else _vs[num - 2] = v; } + virtual MVertex *getVertex(int num) + { + return num < 2 ? _v[num] : _vs[num - 2]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 2 ? _v[num] : _vs[num - 2]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 2) + _v[num] = v; + else + _vs[num - 2] = v; + } virtual MVertex *getVertexUNV(int num) { static const int map[3] = {0, 2, 1}; return getVertex(map[num]); } - virtual MVertex *getVertexINP(int num){ return getVertexUNV(num); } - virtual MVertex *getVertexKEY(int num){ return getVertexUNV(num); } + virtual MVertex *getVertexINP(int num) { return getVertexUNV(num); } + virtual MVertex *getVertexKEY(int num) { return getVertexUNV(num); } virtual int getNumEdgeVertices() const { return 1; } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MLine::_getEdgeVertices(v); @@ -152,14 +173,15 @@ class MLine3 : public MLine { virtual int getTypeForUNV() const { return 24; } // parabolic beam virtual int getTypeForVTK() const { return 21; } virtual const char *getStringForPOS() const { return "SL2"; } - virtual const char *getStringForINP() const { return "T3D3"/*"C1D3"*/; } + virtual const char *getStringForINP() const { return "T3D3" /*"C1D3"*/; } virtual const char *getStringForKEY() const { return "_BEAM_ELBOW"; } virtual const char *getStringForTOCHNOG() const { return "-bar3"; } virtual void getNode(int num, double &u, double &v, double &w) const { num < 2 ? MLine::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); } - virtual void discretize(double tol, std::vector<SPoint3> &dpts, std::vector<double> &ts); + virtual void discretize(double tol, std::vector<SPoint3> &dpts, + std::vector<double> &ts); }; /* @@ -169,37 +191,51 @@ class MLine3 : public MLine { * */ class MLineN : public MLine { - protected: +protected: std::vector<MVertex *> _vs; - public : - MLineN(MVertex *v0, MVertex *v1, const std::vector<MVertex*> &vs, int num=0, int part=0) + +public: + MLineN(MVertex *v0, MVertex *v1, const std::vector<MVertex *> &vs, + int num = 0, int part = 0) : MLine(v0, v1, num, part), _vs(vs) { for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_vs.size() + 1); } - MLineN(const std::vector<MVertex*> &v, int num=0, int part=0) - : MLine(v[0] , v[1], num, part) + MLineN(const std::vector<MVertex *> &v, int num = 0, int part = 0) + : MLine(v[0], v[1], num, part) { - for(unsigned int i = 2; i < v.size(); i++) - _vs.push_back(v[i]); + for(unsigned int i = 2; i < v.size(); i++) _vs.push_back(v[i]); for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_vs.size() + 1); } - ~MLineN(){} + ~MLineN() {} virtual int getPolynomialOrder() const { return _vs.size() + 1; } virtual std::size_t getNumVertices() const { return _vs.size() + 2; } - virtual MVertex *getVertex(int num){ return num < 2 ? _v[num] : _vs[num - 2]; } - virtual const MVertex *getVertex(int num) const{ return num < 2 ? _v[num] : _vs[num - 2]; } - virtual void setVertex(int num, MVertex *v){ if(num < 2) _v[num] = v; else _vs[num - 2] = v; } + virtual MVertex *getVertex(int num) + { + return num < 2 ? _v[num] : _vs[num - 2]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 2 ? _v[num] : _vs[num - 2]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 2) + _v[num] = v; + else + _vs[num - 2] = v; + } virtual int getNumEdgeVertices() const { return _vs.size(); } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2 + _vs.size()); MLine::_getEdgeVertices(v); - for(unsigned int i = 0; i != _vs.size(); ++i) v[i+2] = _vs[i]; + for(unsigned int i = 0; i != _vs.size(); ++i) v[i + 2] = _vs[i]; } virtual int getTypeForMSH() const { @@ -213,13 +249,15 @@ class MLineN : public MLine { if(_vs.size() == 7) return MSH_LIN_9; if(_vs.size() == 8) return MSH_LIN_10; if(_vs.size() == 9) return MSH_LIN_11; - Msg::Error("no tag matches a line with %d vertices", 8+_vs.size()); + Msg::Error("no tag matches a line with %d vertices", 8 + _vs.size()); return 0; } virtual void reverse() { - MVertex *tmp = _v[0]; _v[0] = _v[1]; _v[1] = tmp; - std::vector<MVertex*> inv; + MVertex *tmp = _v[0]; + _v[0] = _v[1]; + _v[1] = tmp; + std::vector<MVertex *> inv; inv.insert(inv.begin(), _vs.rbegin(), _vs.rend()); _vs = inv; } @@ -227,11 +265,12 @@ class MLineN : public MLine { { num < 2 ? MLine::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); } - virtual void discretize(double tol, std::vector<SPoint3> &dpts, std::vector<double> &ts); + virtual void discretize(double tol, std::vector<SPoint3> &dpts, + std::vector<double> &ts); }; struct compareMLinePtr { - bool operator () (MLine *l1, MLine *l2) const + bool operator()(MLine *l1, MLine *l2) const { static Less_Edge le; return le(l1->getEdge(0), l2->getEdge(0)); diff --git a/Geo/MPoint.h b/Geo/MPoint.h index 8be73fedd5b1edfe2adb741186eb55e99fbacdd9..cb6af5689816301c2ebb3f254a008fca5d2506dd 100644 --- a/Geo/MPoint.h +++ b/Geo/MPoint.h @@ -14,33 +14,39 @@ * */ class MPoint : public MElement { - protected: +protected: MVertex *_v[1]; - public : - MPoint(MVertex *v0, int num=0, int part=0) - : MElement(num, part) + +public: + MPoint(MVertex *v0, int num = 0, int part = 0) : MElement(num, part) { _v[0] = v0; } - MPoint(const std::vector<MVertex*> &v, int num=0, int part=0) + MPoint(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { _v[0] = v[0]; } - ~MPoint(){} + ~MPoint() {} virtual int getDim() const { return 0; } virtual std::size_t getNumVertices() const { return 1; } - virtual MVertex *getVertex(int num){ return _v[0]; } + virtual MVertex *getVertex(int num) { return _v[0]; } virtual const MVertex *getVertex(int num) const { return _v[0]; } - virtual void setVertex(int num, MVertex *v){ _v[0] = v; } - virtual int getNumEdges()const{ return 0; } - virtual MEdge getEdge(int num) const{ return MEdge(); } - virtual int getNumEdgesRep(bool curved){ return 0; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n){} - virtual int getNumFaces(){ return 0; } + virtual void setVertex(int num, MVertex *v) { _v[0] = v; } + virtual int getNumEdges() const { return 0; } + virtual MEdge getEdge(int num) const { return MEdge(); } + virtual int getNumEdgesRep(bool curved) { return 0; } + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) + { + } + virtual int getNumFaces() { return 0; } virtual MFace getFace(int num) const { return MFace(); } - virtual int getNumFacesRep(bool curved){ return 0; } - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n){} + virtual int getNumFacesRep(bool curved) { return 0; } + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) + { + } virtual int getType() const { return TYPE_PNT; } virtual int getTypeForMSH() const { return MSH_PNT; } virtual int getTypeForVTK() const { return 1; } @@ -49,27 +55,25 @@ class MPoint : public MElement { { u = v = w = 0.; } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0., 0., 0.); - } - virtual void getShapeFunctions(double u, double v, double w, double s[], int o) const + virtual SPoint3 barycenterUVW() const { return SPoint3(0., 0., 0.); } + virtual void getShapeFunctions(double u, double v, double w, double s[], + int o) const { s[0] = 1.; } - virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int o) const + virtual void getGradShapeFunctions(double u, double v, double w, + double s[][3], int o) const { s[0][0] = s[0][1] = s[0][2] = 0.; } - virtual const JacobianBasis* getJacobianFuncSpace(int o) const + virtual const JacobianBasis *getJacobianFuncSpace(int o) const { return BasisFactory::getJacobianBasis(MSH_PNT); } virtual bool isInside(double u, double v, double w) const { double tol = getTolerance(); - if(fabs(u) > tol || fabs(v) > tol || fabs(w) > tol) - return false; + if(fabs(u) > tol || fabs(v) > tol || fabs(w) > tol) return false; return true; } virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts) diff --git a/Geo/MPrism.cpp b/Geo/MPrism.cpp index ed29dd8779915e3b6aac64239de8d041aec8eb5c..3f9b13081d6542c21016ee67ee9e6754e0663023 100644 --- a/Geo/MPrism.cpp +++ b/Geo/MPrism.cpp @@ -20,8 +20,12 @@ void MPrism::getEdgeRep(bool curved, int num, double *x, double *y, double *z, { MVertex *v0 = _v[edges_prism(num, 0)]; MVertex *v1 = _v[edges_prism(num, 1)]; - x[0] = v0->x(); y[0] = v0->y(); z[0] = v0->z(); - x[1] = v1->x(); y[1] = v1->y(); z[1] = v1->z(); + x[0] = v0->x(); + y[0] = v0->y(); + z[0] = v0->z(); + x[1] = v1->x(); + y[1] = v1->y(); + z[1] = v1->z(); // just one of the potential normals - did not bother computing the normal of // one of the faces - don't use MElement::_getEdgeRep as it uses MFace, which // is slow @@ -43,9 +47,12 @@ int MPrism::getVolumeSign() mat[2][1] = _v[2]->z() - _v[0]->z(); mat[2][2] = _v[3]->z() - _v[0]->z(); double d = det3x3(mat); - if(d < 0.) return -1; - else if(d > 0.) return 1; - else return 0; + if(d < 0.) + return -1; + else if(d > 0.) + return 1; + else + return 0; } void MPrism::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) @@ -57,21 +64,22 @@ void MPrism::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) double MPrism::getInnerRadius() { double dist[3], k = 0.; - int triEdges[3] = {0,1,3}; - for (int i = 0; i < 3; i++){ + int triEdges[3] = {0, 1, 3}; + for(int i = 0; i < 3; i++) { MEdge e = getEdge(triEdges[i]); dist[i] = e.getVertex(0)->distance(e.getVertex(1)); k += 0.5 * dist[i]; } double radTri = sqrt(k * (k - dist[0]) * (k - dist[1]) * (k - dist[2])) / k; - double radVert = 0.5*getVertex(0)->distance(getVertex(3)); - return std::min(radTri,radVert); + double radVert = 0.5 * getVertex(0)->distance(getVertex(3)); + return std::min(radTri, radVert); } -bool MPrism::getFaceInfo(const MFace &face, int &ithFace, int &sign, int &rot) const +bool MPrism::getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const { - for (ithFace = 0; ithFace < 5; ithFace++){ - if (_getFaceInfo(getFace(ithFace), face, sign, rot)) return true; + for(ithFace = 0; ithFace < 5; ithFace++) { + if(_getFaceInfo(getFace(ithFace), face, sign, rot)) return true; } Msg::Error("Could not get face information for prism %d", getNum()); return false; @@ -79,73 +87,78 @@ bool MPrism::getFaceInfo(const MFace &face, int &ithFace, int &sign, int &rot) c int MPrism::numCommonNodesInDualGraph(const MElement *const other) const { - switch (other->getType()) - { - case TYPE_PNT: return 1; - case TYPE_LIN: return 2; - case TYPE_QUA: return 4; - case TYPE_HEX: return 4; - default: return 3; + switch(other->getType()) { + case TYPE_PNT: return 1; + case TYPE_LIN: return 2; + case TYPE_QUA: return 4; + case TYPE_HEX: return 4; + default: return 3; } } static void _myGetEdgeRep(MPrism *pri, int num, double *x, double *y, double *z, SVector3 *n, int numSubEdges) { - //const int numSubEdges = CTX::instance()->mesh.numSubEdges; - static double pp[6][3] = { - {0,0,-1},{1,0,-1},{0,1,-1}, - {0,0,1},{1,0,1},{0,1,1} }; - static int ed [9][2] = { - {0,1},{0,2},{0,3},{1,2},{1,4},{2,5}, - {3,4},{3,5},{4,5} - }; + // const int numSubEdges = CTX::instance()->mesh.numSubEdges; + static double pp[6][3] = {{0, 0, -1}, {1, 0, -1}, {0, 1, -1}, + {0, 0, 1}, {1, 0, 1}, {0, 1, 1}}; + static int ed[9][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 4}, + {2, 5}, {3, 4}, {3, 5}, {4, 5}}; int iEdge = num / numSubEdges; int iSubEdge = num % numSubEdges; - int iVertex1 = ed [iEdge][0]; - int iVertex2 = ed [iEdge][1]; - double t1 = (double) iSubEdge / (double) numSubEdges; - double u1 = pp[iVertex1][0] * (1.-t1) + pp[iVertex2][0] * t1; - double v1 = pp[iVertex1][1] * (1.-t1) + pp[iVertex2][1] * t1; - double w1 = pp[iVertex1][2] * (1.-t1) + pp[iVertex2][2] * t1; + int iVertex1 = ed[iEdge][0]; + int iVertex2 = ed[iEdge][1]; + double t1 = (double)iSubEdge / (double)numSubEdges; + double u1 = pp[iVertex1][0] * (1. - t1) + pp[iVertex2][0] * t1; + double v1 = pp[iVertex1][1] * (1. - t1) + pp[iVertex2][1] * t1; + double w1 = pp[iVertex1][2] * (1. - t1) + pp[iVertex2][2] * t1; - double t2 = (double) (iSubEdge+1) / (double) numSubEdges; - double u2 = pp[iVertex1][0] * (1.-t2) + pp[iVertex2][0] * t2; - double v2 = pp[iVertex1][1] * (1.-t2) + pp[iVertex2][1] * t2; - double w2 = pp[iVertex1][2] * (1.-t2) + pp[iVertex2][2] * t2; + double t2 = (double)(iSubEdge + 1) / (double)numSubEdges; + double u2 = pp[iVertex1][0] * (1. - t2) + pp[iVertex2][0] * t2; + double v2 = pp[iVertex1][1] * (1. - t2) + pp[iVertex2][1] * t2; + double w2 = pp[iVertex1][2] * (1. - t2) + pp[iVertex2][2] * t2; SPoint3 pnt1, pnt2; pri->pnt(u1, v1, w1, pnt1); pri->pnt(u2, v2, w2, pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); // not great, but better than nothing - //static const int f[6] = {0, 0, 0, 1, 2, 3}; - n[0] = n[1] = 1 ; + // static const int f[6] = {0, 0, 0, 1, 2, 3}; + n[0] = n[1] = 1; } -void MPrism15::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPrism15::getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MPrism::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MPrism::getEdgeRep(false, num, x, y, z, n); } -void MPrism18::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPrism18::getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MPrism::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MPrism::getEdgeRep(false, num, x, y, z, n); } -void MPrismN::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPrismN::getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MPrism::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MPrism::getEdgeRep(false, num, x, y, z, n); } int MPrism15::getNumEdgesRep(bool curved) @@ -166,25 +179,24 @@ int MPrismN::getNumEdgesRep(bool curved) static void _myGetFaceRep(MPrism *pri, int num, double *x, double *y, double *z, SVector3 *n, int numSubEdges) { - static double pp[6][3] = { - {0,0,-1},{1,0,-1},{0,1,-1}, - {0,0,1},{1,0,1},{0,1,1} }; + static double pp[6][3] = {{0, 0, -1}, {1, 0, -1}, {0, 1, -1}, + {0, 0, 1}, {1, 0, 1}, {0, 1, 1}}; - int iFace = num / (numSubEdges * numSubEdges); + int iFace = num / (numSubEdges * numSubEdges); int iSubFace = num % (numSubEdges * numSubEdges); - if (iFace > 1) { - iFace = num / (2*numSubEdges * numSubEdges) + 1; - iSubFace = num % (2*numSubEdges * numSubEdges); + if(iFace > 1) { + iFace = num / (2 * numSubEdges * numSubEdges) + 1; + iSubFace = num % (2 * numSubEdges * numSubEdges); } - int iVertex1 = pri->faces_prism(iFace,0); - int iVertex2 = pri->faces_prism(iFace,1); - int iVertex3 = pri->faces_prism(iFace,2); - int iVertex4 = pri->faces_prism(iFace,3); + int iVertex1 = pri->faces_prism(iFace, 0); + int iVertex2 = pri->faces_prism(iFace, 1); + int iVertex3 = pri->faces_prism(iFace, 2); + int iVertex4 = pri->faces_prism(iFace, 3); SPoint3 pnt1, pnt2, pnt3; - // double J1[3][3], J2[3][3], J3[3][3]; + // double J1[3][3], J2[3][3], J3[3][3]; /* 0 @@ -198,139 +210,120 @@ static void _myGetFaceRep(MPrism *pri, int num, double *x, double *y, double *z, // on each layer, we have (numSubEdges) * 2 triangles // ix and iy are the coordinates of the sub-quadrangle - if (iFace > 1) { - int io = iSubFace%2; - int ix = (iSubFace/2)/numSubEdges; - int iy = (iSubFace/2)%numSubEdges; + if(iFace > 1) { + int io = iSubFace % 2; + int ix = (iSubFace / 2) / numSubEdges; + int iy = (iSubFace / 2) % numSubEdges; const double d = 2. / numSubEdges; - double ox = -1. + d*ix; - double oy = -1. + d*iy; - - if (io == 0){ - double U1 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V1 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W1 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double ox = -1. + d * ix; + double oy = -1. + d * iy; + + if(io == 0) { + double U1 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V1 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W1 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; ox += d; - double U2 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V2 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W2 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double U2 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V2 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W2 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; oy += d; - double U3 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V3 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W3 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double U3 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V3 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W3 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; pri->pnt(U1, V1, W1, pnt1); pri->pnt(U2, V2, W2, pnt2); pri->pnt(U3, V3, W3, pnt3); } - else{ - double U1 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V1 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W1 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + else { + double U1 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V1 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W1 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; ox += d; oy += d; - double U2 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V2 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W2 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double U2 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V2 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W2 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; ox -= d; - double U3 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V3 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W3 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; + double U3 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V3 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W3 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; pri->pnt(U1, V1, W1, pnt1); pri->pnt(U2, V2, W2, pnt2); pri->pnt(U3, V3, W3, pnt3); } - } else { int ix = 0, iy = 0; int nbt = 0; - for (int i = 0; i < numSubEdges; i++){ + for(int i = 0; i < numSubEdges; i++) { int nbl = (numSubEdges - i - 1) * 2 + 1; nbt += nbl; - if (nbt > iSubFace){ + if(nbt > iSubFace) { iy = i; ix = nbl - (nbt - iSubFace); break; @@ -340,39 +333,58 @@ static void _myGetFaceRep(MPrism *pri, int num, double *x, double *y, double *z, const double d = 1. / numSubEdges; double u1, v1, u2, v2, u3, v3; - if (ix % 2 == 0){ - u1 = ix / 2 * d; v1= iy*d; - u2 = (ix / 2 + 1) * d ; v2 = iy * d; - u3 = ix / 2 * d ; v3 = (iy+1) * d; + if(ix % 2 == 0) { + u1 = ix / 2 * d; + v1 = iy * d; + u2 = (ix / 2 + 1) * d; + v2 = iy * d; + u3 = ix / 2 * d; + v3 = (iy + 1) * d; } - else{ - u1 = (ix / 2 + 1) * d; v1= iy * d; - u2 = (ix / 2 + 1) * d; v2= (iy + 1) * d; - u3 = ix / 2 * d ; v3 = (iy + 1) * d; + else { + u1 = (ix / 2 + 1) * d; + v1 = iy * d; + u2 = (ix / 2 + 1) * d; + v2 = (iy + 1) * d; + u3 = ix / 2 * d; + v3 = (iy + 1) * d; } - double U1 = pp[iVertex1][0] * (1.-u1-v1) + pp[iVertex2][0] * u1 + pp[iVertex3][0] * v1; - double U2 = pp[iVertex1][0] * (1.-u2-v2) + pp[iVertex2][0] * u2 + pp[iVertex3][0] * v2; - double U3 = pp[iVertex1][0] * (1.-u3-v3) + pp[iVertex2][0] * u3 + pp[iVertex3][0] * v3; - - double V1 = pp[iVertex1][1] * (1.-u1-v1) + pp[iVertex2][1] * u1 + pp[iVertex3][1] * v1; - double V2 = pp[iVertex1][1] * (1.-u2-v2) + pp[iVertex2][1] * u2 + pp[iVertex3][1] * v2; - double V3 = pp[iVertex1][1] * (1.-u3-v3) + pp[iVertex2][1] * u3 + pp[iVertex3][1] * v3; - - double W1 = pp[iVertex1][2] * (1.-u1-v1) + pp[iVertex2][2] * u1 + pp[iVertex3][2] * v1; - double W2 = pp[iVertex1][2] * (1.-u2-v2) + pp[iVertex2][2] * u2 + pp[iVertex3][2] * v2; - double W3 = pp[iVertex1][2] * (1.-u3-v3) + pp[iVertex2][2] * u3 + pp[iVertex3][2] * v3; + double U1 = pp[iVertex1][0] * (1. - u1 - v1) + pp[iVertex2][0] * u1 + + pp[iVertex3][0] * v1; + double U2 = pp[iVertex1][0] * (1. - u2 - v2) + pp[iVertex2][0] * u2 + + pp[iVertex3][0] * v2; + double U3 = pp[iVertex1][0] * (1. - u3 - v3) + pp[iVertex2][0] * u3 + + pp[iVertex3][0] * v3; + + double V1 = pp[iVertex1][1] * (1. - u1 - v1) + pp[iVertex2][1] * u1 + + pp[iVertex3][1] * v1; + double V2 = pp[iVertex1][1] * (1. - u2 - v2) + pp[iVertex2][1] * u2 + + pp[iVertex3][1] * v2; + double V3 = pp[iVertex1][1] * (1. - u3 - v3) + pp[iVertex2][1] * u3 + + pp[iVertex3][1] * v3; + + double W1 = pp[iVertex1][2] * (1. - u1 - v1) + pp[iVertex2][2] * u1 + + pp[iVertex3][2] * v1; + double W2 = pp[iVertex1][2] * (1. - u2 - v2) + pp[iVertex2][2] * u2 + + pp[iVertex3][2] * v2; + double W3 = pp[iVertex1][2] * (1. - u3 - v3) + pp[iVertex2][2] * u3 + + pp[iVertex3][2] * v3; pri->pnt(U1, V1, W1, pnt1); pri->pnt(U2, V2, W2, pnt2); pri->pnt(U3, V3, W3, pnt3); } - - - x[0] = pnt1.x(); x[1] = pnt2.x(); x[2] = pnt3.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); y[2] = pnt3.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); z[2] = pnt3.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + x[2] = pnt3.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + y[2] = pnt3.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); + z[2] = pnt3.z(); SVector3 d1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); SVector3 d2(x[2] - x[0], y[2] - y[0], z[2] - z[0]); @@ -382,68 +394,68 @@ static void _myGetFaceRep(MPrism *pri, int num, double *x, double *y, double *z, n[2] = n[0]; } -void MPrism::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPrism::getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { #if defined(HAVE_VISUDEV) - static const int fquad[12][4] = { - {0, 1, 4, 3}, {1, 4, 3, 0}, {4, 3, 0, 1}, {3, 0, 1, 4}, - {1, 2, 5, 4}, {2, 5, 4, 1}, {5, 4, 1, 2}, {4, 1, 2, 5}, - {2, 0, 3, 5}, {0, 3, 5, 2}, {3, 5, 2, 0}, {5, 2, 0, 3} - }; - if (CTX::instance()->heavyVisu) { - if (CTX::instance()->mesh.numSubEdges > 1) { + static const int fquad[12][4] = {{0, 1, 4, 3}, {1, 4, 3, 0}, {4, 3, 0, 1}, + {3, 0, 1, 4}, {1, 2, 5, 4}, {2, 5, 4, 1}, + {5, 4, 1, 2}, {4, 1, 2, 5}, {2, 0, 3, 5}, + {0, 3, 5, 2}, {3, 5, 2, 0}, {5, 2, 0, 3}}; + if(CTX::instance()->heavyVisu) { + if(CTX::instance()->mesh.numSubEdges > 1) { _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); return; } - if (num > 1) { + if(num > 1) { int i = num - 2; _getFaceRepQuad(getVertex(fquad[i][0]), getVertex(fquad[i][1]), - getVertex(fquad[i][2]), getVertex(fquad[i][3]), - x, y, z, n); + getVertex(fquad[i][2]), getVertex(fquad[i][3]), x, y, z, + n); return; } } #endif - static const int f[8][3] = { - {0, 2, 1}, - {3, 4, 5}, - {0, 1, 4}, {0, 4, 3}, - {0, 3, 5}, {0, 5, 2}, - {1, 2, 5}, {1, 5, 4} - }; + static const int f[8][3] = {{0, 2, 1}, {3, 4, 5}, {0, 1, 4}, {0, 4, 3}, + {0, 3, 5}, {0, 5, 2}, {1, 2, 5}, {1, 5, 4}}; _getFaceRep(_v[f[num][0]], _v[f[num][1]], _v[f[num][2]], x, y, z, n); } -void MPrism15::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPrism15::getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MPrism::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MPrism::getFaceRep(false, num, x, y, z, n); } -void MPrism18::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPrism18::getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MPrism::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MPrism::getFaceRep(false, num, x, y, z, n); } -void MPrismN::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPrismN::getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MPrism::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MPrism::getFaceRep(false, num, x, y, z, n); } int MPrism::getNumFacesRep(bool curved) { #if defined(HAVE_VISUDEV) - if (CTX::instance()->heavyVisu) { - if (CTX::instance()->mesh.numSubEdges == 1) return 14; + if(CTX::instance()->heavyVisu) { + if(CTX::instance()->mesh.numSubEdges == 1) return 14; return 8 * std::pow(CTX::instance()->mesh.numSubEdges, 2); } - if (CTX::instance()->heavyVisu) return 14; + if(CTX::instance()->heavyVisu) return 14; #endif return 8; } @@ -451,78 +463,72 @@ int MPrism::getNumFacesRep(bool curved) int MPrism15::getNumFacesRep(bool curved) { return curved ? 8 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MPrism::getNumFacesRep(curved); + MPrism::getNumFacesRep(curved); } int MPrism18::getNumFacesRep(bool curved) { return curved ? 8 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MPrism::getNumFacesRep(curved); + MPrism::getNumFacesRep(curved); } int MPrismN::getNumFacesRep(bool curved) { return curved ? 8 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MPrism::getNumFacesRep(curved); + MPrism::getNumFacesRep(curved); } static void _addEdgeNodes(int num, bool reverse, int order, - const std::vector<MVertex*> &vs, - int &ind, std::vector<MVertex*> &v) + const std::vector<MVertex *> &vs, int &ind, + std::vector<MVertex *> &v) { - const int nNode = order-1, startNode = num*nNode, endNode = startNode+nNode-1; + const int nNode = order - 1, startNode = num * nNode, + endNode = startNode + nNode - 1; - if (reverse) - for (int i=endNode; i>=startNode; i--, ind++) v[ind] = vs[i]; + if(reverse) + for(int i = endNode; i >= startNode; i--, ind++) v[ind] = vs[i]; else - for (int i=startNode; i<=endNode; i++, ind++) v[ind] = vs[i]; + for(int i = startNode; i <= endNode; i++, ind++) v[ind] = vs[i]; } -static void _addFaceNodes(int num, int order, const std::vector<MVertex*> &vs, - int &ind, std::vector<MVertex*> &v) +static void _addFaceNodes(int num, int order, const std::vector<MVertex *> &vs, + int &ind, std::vector<MVertex *> &v) { - const int nNodeEd = order-1, nNodeTri = (order-2)*(order-1)/2; + const int nNodeEd = order - 1, nNodeTri = (order - 2) * (order - 1) / 2; int startNode, endNode; - if (num < 2) { - startNode = 9*nNodeEd+num*nNodeTri; - endNode = startNode+nNodeTri; + if(num < 2) { + startNode = 9 * nNodeEd + num * nNodeTri; + endNode = startNode + nNodeTri; } else { - const int nNodeQuad = (order-1)*(order-1); - startNode = 9*nNodeEd+2*nNodeTri+(num-2)*nNodeQuad; - endNode = startNode+nNodeQuad; + const int nNodeQuad = (order - 1) * (order - 1); + startNode = 9 * nNodeEd + 2 * nNodeTri + (num - 2) * nNodeQuad; + endNode = startNode + nNodeQuad; } - for (int i=startNode; i<endNode; i++, ind++) v[ind] = vs[i]; + for(int i = startNode; i < endNode; i++, ind++) v[ind] = vs[i]; } // To be tested -void MPrismN::getFaceVertices(const int num, std::vector<MVertex*> &v) const +void MPrismN::getFaceVertices(const int num, std::vector<MVertex *> &v) const { // FIXME serendipity case static const int edge[5][4] = { - {1, 3, 0, -1}, - {6, 8, 7, -1}, - {0, 4, 6, 2}, - {2, 7, 5, 1}, - {3, 5, 8, 4} - }; - static const bool reverse[5][4] = { - {false, true, true, false}, - {false, false, true, false}, - {false, false, true, true}, - {false, false, true, true}, - {false, false, true, true} - }; + {1, 3, 0, -1}, {6, 8, 7, -1}, {0, 4, 6, 2}, {2, 7, 5, 1}, {3, 5, 8, 4}}; + static const bool reverse[5][4] = {{false, true, true, false}, + {false, false, true, false}, + {false, false, true, true}, + {false, false, true, true}, + {false, false, true, true}}; int nNodeTotal, nEdge; - if (num < 2) { // Triangular face - nNodeTotal = (_order+1)*(_order+2)/2; + if(num < 2) { // Triangular face + nNodeTotal = (_order + 1) * (_order + 2) / 2; nEdge = 3; } - else { // Quad face - nNodeTotal = (_order+1)*(_order+1); + else { // Quad face + nNodeTotal = (_order + 1) * (_order + 1); nEdge = 4; } @@ -533,11 +539,11 @@ void MPrismN::getFaceVertices(const int num, std::vector<MVertex*> &v) const int ind = nEdge; // Add edge nodes - for (int iE=0; iE<nEdge; iE++) - _addEdgeNodes(edge[num][iE],reverse[num][iE],_order,_vs,ind,v); + for(int iE = 0; iE < nEdge; iE++) + _addEdgeNodes(edge[num][iE], reverse[num][iE], _order, _vs, ind, v); // Add face nodes - _addFaceNodes(num,_order,_vs,ind,v); + _addFaceNodes(num, _order, _vs, ind, v); } double MPrism::gammaShapeMeasure() @@ -554,12 +560,12 @@ void _getIndicesReversedPri(int order, IndicesReversed &indices) fullMatrix<double> ref = gmshGenerateMonomialsPrism(order); indices.resize(ref.size1()); - for (int i = 0; i < ref.size1(); ++i) { + for(int i = 0; i < ref.size1(); ++i) { const double u = ref(i, 0); const double v = ref(i, 1); const double w = ref(i, 2); - for (int j = 0; j < ref.size1(); ++j) { - if (u == ref(j, 1) && v == ref(j, 0) && w == ref(j, 2)) { + for(int j = 0; j < ref.size1(); ++j) { + if(u == ref(j, 1) && v == ref(j, 0) && w == ref(j, 2)) { indices[i] = j; break; } @@ -571,7 +577,7 @@ void MPrismN::reverse() { std::map<int, IndicesReversed>::iterator it; it = _order2indicesReversedPri.find(_order); - if (it == _order2indicesReversedPri.end()) { + if(it == _order2indicesReversedPri.end()) { IndicesReversed indices; _getIndicesReversedPri(_order, indices); _order2indicesReversedPri[_order] = indices; @@ -581,15 +587,15 @@ void MPrismN::reverse() IndicesReversed &indices = it->second; // copy vertices - std::vector<MVertex*> oldv(6 + _vs.size()); - std::copy(_v, _v+6, oldv.begin()); - std::copy(_vs.begin(), _vs.end(), oldv.begin()+6); + std::vector<MVertex *> oldv(6 + _vs.size()); + std::copy(_v, _v + 6, oldv.begin()); + std::copy(_vs.begin(), _vs.end(), oldv.begin() + 6); // reverse - for (int i = 0; i < 6; ++i) { + for(int i = 0; i < 6; ++i) { _v[i] = oldv[indices[i]]; } - for (unsigned int i = 0; i < _vs.size(); ++i) { - _vs[i] = oldv[indices[6+i]]; + for(unsigned int i = 0; i < _vs.size(); ++i) { + _vs[i] = oldv[indices[6 + i]]; } } diff --git a/Geo/MPrism.h b/Geo/MPrism.h index e6a35a9f6cc4e7ae88b4ddc7f0496dcab31d7ff0..574b1777a34ff2579c1df32c544a33bd124c6c90 100644 --- a/Geo/MPrism.h +++ b/Geo/MPrism.h @@ -32,41 +32,46 @@ * */ class MPrism : public MElement { - protected: +protected: MVertex *_v[6]; - void _getEdgeVertices(const int num, std::vector<MVertex*> &v) const + void _getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[edges_prism(num, 0)]; v[1] = _v[edges_prism(num, 1)]; } - void _getFaceVertices(const int num, std::vector<MVertex*> &v) const + void _getFaceVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[faces_prism(num, 0)]; v[1] = _v[faces_prism(num, 1)]; v[2] = _v[faces_prism(num, 2)]; if(num >= 2) v[3] = _v[faces_prism(num, 3)]; } - public : + +public: MPrism(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, - MVertex *v5, int num=0, int part=0) + MVertex *v5, int num = 0, int part = 0) : MElement(num, part) { - _v[0] = v0; _v[1] = v1; _v[2] = v2; _v[3] = v3; - _v[4] = v4; _v[5] = v5; + _v[0] = v0; + _v[1] = v1; + _v[2] = v2; + _v[3] = v3; + _v[4] = v4; + _v[5] = v5; } - MPrism(const std::vector<MVertex*> &v, int num=0, int part=0) + MPrism(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { for(int i = 0; i < 6; i++) _v[i] = v[i]; } - ~MPrism(){} + ~MPrism() {} virtual int getDim() const { return 3; } virtual std::size_t getNumVertices() const { return 6; } virtual double getInnerRadius(); - virtual MVertex *getVertex(int num){ return _v[num]; } - virtual const MVertex *getVertex(int num)const{ return _v[num]; } - virtual void setVertex(int num, MVertex *v){ _v[num] = v; } - virtual int getNumEdges()const{ return 9; } + virtual MVertex *getVertex(int num) { return _v[num]; } + virtual const MVertex *getVertex(int num) const { return _v[num]; } + virtual void setVertex(int num, MVertex *v) { _v[num] = v; } + virtual int getNumEdges() const { return 9; } virtual MEdge getEdge(int num) const { return MEdge(_v[edges_prism(num, 0)], _v[edges_prism(num, 1)]); @@ -75,30 +80,30 @@ class MPrism : public MElement { { return edges_prism(numEdge, numVert); } - virtual int getNumEdgesRep(bool curved){ return 9; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual int getNumEdgesRep(bool curved) { return 9; } + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); _getEdgeVertices(num, v); } - virtual int getNumFaces(){ return 5; } - virtual bool getFaceInfo(const MFace & face, int &ithFace, int &sign, int &rot) const; + virtual int getNumFaces() { return 5; } + virtual bool getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const; virtual MFace getFace(int num) const { if(num < 2) - return MFace(_v[faces_prism(num, 0)], - _v[faces_prism(num, 1)], + return MFace(_v[faces_prism(num, 0)], _v[faces_prism(num, 1)], _v[faces_prism(num, 2)]); else - return MFace(_v[faces_prism(num, 0)], - _v[faces_prism(num, 1)], - _v[faces_prism(num, 2)], - _v[faces_prism(num, 3)]); + return MFace(_v[faces_prism(num, 0)], _v[faces_prism(num, 1)], + _v[faces_prism(num, 2)], _v[faces_prism(num, 3)]); } virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize((num < 2) ? 3 : 4); _getFaceVertices(num, v); @@ -114,73 +119,86 @@ class MPrism : public MElement { virtual void reverse() { MVertex *tmp; - tmp = _v[0]; _v[0] = _v[1]; _v[1] = tmp; - tmp = _v[3]; _v[3] = _v[4]; _v[4] = tmp; + tmp = _v[0]; + _v[0] = _v[1]; + _v[1] = tmp; + tmp = _v[3]; + _v[3] = _v[4]; + _v[4] = tmp; } virtual double gammaShapeMeasure(); virtual int getVolumeSign(); virtual void getNode(int num, double &u, double &v, double &w) const { switch(num) { - case 0 : u = 0.; v = 0.; w = -1.; break; - case 1 : u = 1.; v = 0.; w = -1.; break; - case 2 : u = 0.; v = 1.; w = -1.; break; - case 3 : u = 0.; v = 0.; w = 1.; break; - case 4 : u = 1.; v = 0.; w = 1.; break; - case 5 : u = 0.; v = 1.; w = 1.; break; - default: u = 0.; v = 0.; w = 0.; break; + case 0: + u = 0.; + v = 0.; + w = -1.; + break; + case 1: + u = 1.; + v = 0.; + w = -1.; + break; + case 2: + u = 0.; + v = 1.; + w = -1.; + break; + case 3: + u = 0.; + v = 0.; + w = 1.; + break; + case 4: + u = 1.; + v = 0.; + w = 1.; + break; + case 5: + u = 0.; + v = 1.; + w = 1.; + break; + default: + u = 0.; + v = 0.; + w = 0.; + break; } } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(1/3., 1/3., 0.); - } + virtual SPoint3 barycenterUVW() const { return SPoint3(1 / 3., 1 / 3., 0.); } virtual bool isInside(double u, double v, double w) const { double tol = getTolerance(); - if(w > (1. + tol) || w < -(1. + tol) || u < (-tol) - || v < (-tol) || u > ((1. + tol) - v)) + if(w > (1. + tol) || w < -(1. + tol) || u < (-tol) || v < (-tol) || + u > ((1. + tol) - v)) return false; return true; } virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); static int edges_prism(const int edge, const int vert) { - static const int e[9][2] = { - {0, 1}, - {0, 2}, - {0, 3}, - {1, 2}, - {1, 4}, - {2, 5}, - {3, 4}, - {3, 5}, - {4, 5} - }; + static const int e[9][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 4}, + {2, 5}, {3, 4}, {3, 5}, {4, 5}}; return e[edge][vert]; } static int faces_prism(const int face, const int vert) { static const int f[5][4] = { - {0, 2, 1, -1}, - {3, 4, 5, -1}, - {0, 1, 4, 3}, - {0, 3, 5, 2}, - {1, 2, 5, 4} - }; + {0, 2, 1, -1}, {3, 4, 5, -1}, {0, 1, 4, 3}, {0, 3, 5, 2}, {1, 2, 5, 4}}; return f[face][vert]; } static int faces2edge_prism(const int face, const int edge) { // return -iedge - 1 if edge is inverted // iedge + 1 otherwise - static const int e[5][4] = { - {2, -4, -1, 0}, - {7, 9, -8, 0}, - {1, 5, -7, -3}, - {3, 8, -6, -2}, - {4, 6, -9, -5} - }; + static const int e[5][4] = {{2, -4, -1, 0}, + {7, 9, -8, 0}, + {1, 5, -7, -3}, + {3, 8, -6, -2}, + {4, 6, -9, -5}}; return e[face][edge]; } static int faceClosureEdge2edge(const int face, const int edge) @@ -188,13 +206,11 @@ class MPrism : public MElement { // Warning: numbering of element edge starts here at 1. // - 0 means no edge (triangular face) // - negative means going backward - static const int f[5][4] = { - {2, -4, -1, 0}, - {7, 9, -8, 0}, - {1, 5, -7, -3}, - {3, 8, -6, -2}, - {4, 6, -9, -5} - }; + static const int f[5][4] = {{2, -4, -1, 0}, + {7, 9, -8, 0}, + {1, 5, -7, -3}, + {3, 8, -6, -2}, + {4, 6, -9, -5}}; return f[face][edge]; } virtual int numCommonNodesInDualGraph(const MElement *const other) const; @@ -221,84 +237,116 @@ class MPrism : public MElement { * */ class MPrism15 : public MPrism { - protected: +protected: MVertex *_vs[9]; - public : + +public: MPrism15(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, MVertex *v5, MVertex *v6, MVertex *v7, MVertex *v8, MVertex *v9, MVertex *v10, MVertex *v11, MVertex *v12, MVertex *v13, MVertex *v14, - int num=0, int part=0) + int num = 0, int part = 0) : MPrism(v0, v1, v2, v3, v4, v5, num, part) { - _vs[0] = v6; _vs[1] = v7; _vs[2] = v8; _vs[3] = v9; _vs[4] = v10; - _vs[5] = v11; _vs[6] = v12; _vs[7] = v13; _vs[8] = v14; + _vs[0] = v6; + _vs[1] = v7; + _vs[2] = v8; + _vs[3] = v9; + _vs[4] = v10; + _vs[5] = v11; + _vs[6] = v12; + _vs[7] = v13; + _vs[8] = v14; for(int i = 0; i < 9; i++) _vs[i]->setPolynomialOrder(2); } - MPrism15(const std::vector<MVertex*> &v, int num=0, int part=0) + MPrism15(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MPrism(v, num, part) { for(int i = 0; i < 9; i++) _vs[i] = v[6 + i]; for(int i = 0; i < 9; i++) _vs[i]->setPolynomialOrder(2); } - ~MPrism15(){} + ~MPrism15() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 15; } - virtual MVertex *getVertex(int num){ return num < 6 ? _v[num] : _vs[num - 6]; } - virtual const MVertex *getVertex(int num) const { return num < 6 ? _v[num] : _vs[num - 6]; } - virtual void setVertex(int num, MVertex *v){ if(num < 6) _v[num] = v; else _vs[num - 6] = v; } + virtual MVertex *getVertex(int num) + { + return num < 6 ? _v[num] : _vs[num - 6]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 6 ? _v[num] : _vs[num - 6]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 6) + _v[num] = v; + else + _vs[num - 6] = v; + } virtual MVertex *getVertexUNV(int num) { - static const int map[15] = {0, 6, 1, 9, 2, 7, 8, 10, 11, 3, 12, 4, 14, 5, 13}; + static const int map[15] = {0, 6, 1, 9, 2, 7, 8, 10, + 11, 3, 12, 4, 14, 5, 13}; return getVertex(map[num]); } virtual MVertex *getVertexBDF(int num) { - static const int map[15] = {0, 1, 2, 3, 4, 5, 6, 9, 7, 8, 10, 11, 12, 14, 13}; + static const int map[15] = {0, 1, 2, 3, 4, 5, 6, 9, + 7, 8, 10, 11, 12, 14, 13}; return getVertex(map[num]); } - virtual MVertex *getVertexINP(int num){ return getVertexBDF(num); } - virtual MVertex *getVertexKEY(int num){ return getVertexBDF(num); } + virtual MVertex *getVertexINP(int num) { return getVertexBDF(num); } + virtual MVertex *getVertexKEY(int num) { return getVertexBDF(num); } virtual int getNumEdgeVertices() const { return 9; } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MPrism::_getEdgeVertices(num, v); v[2] = _vs[num]; } virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize((num < 2) ? 6 : 8); MPrism::_getFaceVertices(num, v); static const int f[5][4] = { - {1, 3, 0, -1}, - {6, 8, 7, -1}, - {0, 4, 6, 2}, - {2, 7, 5, 1}, - {3, 5, 8, 4} - }; + {1, 3, 0, -1}, {6, 8, 7, -1}, {0, 4, 6, 2}, {2, 7, 5, 1}, {3, 5, 8, 4}}; const int i = (num < 2) ? 3 : 4; - v[i ] = _vs[f[num][0]]; - v[i+1] = _vs[f[num][1]]; - v[i+2] = _vs[f[num][2]]; - if (num >= 2) v[7] = _vs[f[num][3]]; + v[i] = _vs[f[num][0]]; + v[i + 1] = _vs[f[num][1]]; + v[i + 2] = _vs[f[num][2]]; + if(num >= 2) v[7] = _vs[f[num][3]]; } virtual int getTypeForMSH() const { return MSH_PRI_15; } virtual int getTypeForUNV() const { return 113; } // solid parabolic wedge virtual const char *getStringForBDF() const { return "CPENTA"; } virtual const char *getStringForINP() const { return "C3D15"; } - virtual const char *getStringForKEY() const { return "_SOLID_P15"; } /* not implemented yet */ + virtual const char *getStringForKEY() const + { + return "_SOLID_P15"; + } /* not implemented yet */ virtual void reverse() { MVertex *tmp; - tmp = _v[0]; _v[0] = _v[1]; _v[1] = tmp; - tmp = _v[3]; _v[3] = _v[4]; _v[4] = tmp; - tmp = _vs[1]; _vs[1] = _vs[3]; _vs[3] = tmp; - tmp = _vs[2]; _vs[2] = _vs[4]; _vs[4] = tmp; - tmp = _vs[7]; _vs[7] = _vs[8]; _vs[8] = tmp; + tmp = _v[0]; + _v[0] = _v[1]; + _v[1] = tmp; + tmp = _v[3]; + _v[3] = _v[4]; + _v[4] = tmp; + tmp = _vs[1]; + _vs[1] = _vs[3]; + _vs[3] = tmp; + tmp = _vs[2]; + _vs[2] = _vs[4]; + _vs[4] = tmp; + tmp = _vs[7]; + _vs[7] = _vs[8]; + _vs[8] = tmp; } virtual void getNode(int num, double &u, double &v, double &w) const { @@ -327,62 +375,81 @@ class MPrism15 : public MPrism { * */ class MPrism18 : public MPrism { - protected: +protected: MVertex *_vs[12]; - public : + +public: MPrism18(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, MVertex *v5, MVertex *v6, MVertex *v7, MVertex *v8, MVertex *v9, MVertex *v10, MVertex *v11, MVertex *v12, MVertex *v13, MVertex *v14, - MVertex *v15, MVertex *v16, MVertex *v17, int num=0, int part=0) + MVertex *v15, MVertex *v16, MVertex *v17, int num = 0, int part = 0) : MPrism(v0, v1, v2, v3, v4, v5, num, part) { - _vs[0] = v6; _vs[1] = v7; _vs[2] = v8; _vs[3] = v9; _vs[4] = v10; - _vs[5] = v11; _vs[6] = v12; _vs[7] = v13; _vs[8] = v14; _vs[9] = v15; - _vs[10] = v16; _vs[11] = v17; + _vs[0] = v6; + _vs[1] = v7; + _vs[2] = v8; + _vs[3] = v9; + _vs[4] = v10; + _vs[5] = v11; + _vs[6] = v12; + _vs[7] = v13; + _vs[8] = v14; + _vs[9] = v15; + _vs[10] = v16; + _vs[11] = v17; for(int i = 0; i < 12; i++) _vs[i]->setPolynomialOrder(2); } - MPrism18(const std::vector<MVertex*> &v, int num=0, int part=0) + MPrism18(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MPrism(v, num, part) { for(int i = 0; i < 12; i++) _vs[i] = v[6 + i]; for(int i = 0; i < 12; i++) _vs[i]->setPolynomialOrder(2); } - ~MPrism18(){} + ~MPrism18() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 18; } - virtual MVertex *getVertex(int num){ return num < 6 ? _v[num] : _vs[num - 6]; } - virtual const MVertex *getVertex(int num) const{ return num < 6 ? _v[num] : _vs[num - 6]; } - virtual void setVertex(int num, MVertex *v){ if(num < 6) _v[num] = v; else _vs[num - 6] = v; } + virtual MVertex *getVertex(int num) + { + return num < 6 ? _v[num] : _vs[num - 6]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 6 ? _v[num] : _vs[num - 6]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 6) + _v[num] = v; + else + _vs[num - 6] = v; + } virtual int getNumEdgeVertices() const { return 9; } virtual int getNumFaceVertices() const { return 3; } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MPrism::_getEdgeVertices(num, v); v[2] = _vs[num]; } virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize((num < 2) ? 6 : 9); MPrism::_getFaceVertices(num, v); static const int f[5][4] = { - {1, 3, 0, -1}, - {6, 8, 7, -1}, - {0, 4, 6, 2}, - {2, 7, 5, 1}, - {3, 5, 8, 4} - }; + {1, 3, 0, -1}, {6, 8, 7, -1}, {0, 4, 6, 2}, {2, 7, 5, 1}, {3, 5, 8, 4}}; const int i = (num < 2) ? 3 : 4; - v[i ] = _vs[f[num][0]]; - v[i+1] = _vs[f[num][1]]; - v[i+2] = _vs[f[num][2]]; - if (num >= 2) { + v[i] = _vs[f[num][0]]; + v[i + 1] = _vs[f[num][1]]; + v[i + 2] = _vs[f[num][2]]; + if(num >= 2) { v[7] = _vs[f[num][3]]; - v[8] = _vs[7+num]; + v[8] = _vs[7 + num]; } } virtual int getTypeForMSH() const { return MSH_PRI_18; } @@ -390,14 +457,26 @@ class MPrism18 : public MPrism { virtual void reverse() { MVertex *tmp; - tmp = _v[0]; _v[0] = _v[1]; _v[1] = tmp; - tmp = _v[3]; _v[3] = _v[4]; _v[4] = tmp; + tmp = _v[0]; + _v[0] = _v[1]; + _v[1] = tmp; + tmp = _v[3]; + _v[3] = _v[4]; + _v[4] = tmp; // edge vertices - tmp = _vs[1]; _vs[1] = _vs[3]; _vs[3] = tmp; - tmp = _vs[2]; _vs[2] = _vs[4]; _vs[4] = tmp; - tmp = _vs[7]; _vs[7] = _vs[8]; _vs[8] = tmp; + tmp = _vs[1]; + _vs[1] = _vs[3]; + _vs[3] = tmp; + tmp = _vs[2]; + _vs[2] = _vs[4]; + _vs[4] = tmp; + tmp = _vs[7]; + _vs[7] = _vs[8]; + _vs[8] = tmp; // quad face vertices - tmp = _vs[10]; _vs[10] = _vs[11]; _vs[11] = tmp; + tmp = _vs[10]; + _vs[10] = _vs[11]; + _vs[11] = tmp; } virtual void getNode(int num, double &u, double &v, double &w) const { @@ -414,99 +493,122 @@ typedef std::vector<int> IndicesReversed; class MPrismN : public MPrism { static std::map<int, IndicesReversed> _order2indicesReversedPri; - protected: +protected: std::vector<MVertex *> _vs; const char _order; - public : + +public: MPrismN(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, - MVertex *v5, const std::vector<MVertex*> &v, char order, int num=0, int part=0) + MVertex *v5, const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) : MPrism(v0, v1, v2, v3, v4, v5, num, part), _vs(v), _order(order) { - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); } - MPrismN(const std::vector<MVertex*> &v, char order, int num=0, int part=0) + MPrismN(const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) : MPrism(v, num, part), _order(order) { - for (unsigned int i = 6; i < v.size(); i++) _vs.push_back(v[i]); - for (unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(2); + for(unsigned int i = 6; i < v.size(); i++) _vs.push_back(v[i]); + for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(2); } - ~MPrismN(){} + ~MPrismN() {} virtual int getPolynomialOrder() const { return _order; } - virtual std::size_t getNumVertices() const { return 6+_vs.size(); } - virtual MVertex *getVertex(int num){ return num < 6 ? _v[num] : _vs[num-6]; } - virtual const MVertex *getVertex(int num) const{ return num < 6 ? _v[num] : _vs[num - 6]; } - virtual void setVertex(int num, MVertex *v){ if(num < 6) _v[num] = v; else _vs[num - 6] = v; } - virtual int getNumEdgeVertices() const { return 9*(_order-1); } + virtual std::size_t getNumVertices() const { return 6 + _vs.size(); } + virtual MVertex *getVertex(int num) + { + return num < 6 ? _v[num] : _vs[num - 6]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 6 ? _v[num] : _vs[num - 6]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 6) + _v[num] = v; + else + _vs[num - 6] = v; + } + virtual int getNumEdgeVertices() const { return 9 * (_order - 1); } virtual int getNumFaceVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; - else - {int n = _order-1; return (n-1 + 3*n) * n;} + else { + int n = _order - 1; + return (n - 1 + 3 * n) * n; + } } virtual int getNumVolumeVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; - else - {int n = _order-1; return n * ((n-1) * n / 2);} + else { + int n = _order - 1; + return n * ((n - 1) * n / 2); + } } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { - v.resize(_order+1); + v.resize(_order + 1); MPrism::_getEdgeVertices(num, v); - const int n = _order-1; - for (int i=0; i<n; i++) v[2+i] = _vs[num*n+i]; + const int n = _order - 1; + for(int i = 0; i < n; i++) v[2 + i] = _vs[num * n + i]; } virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const; - virtual int getTypeForMSH() const { - switch (_order) { - case 0: - return MSH_PRI_1; - case 1: - return MSH_PRI_6; + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const; + virtual int getTypeForMSH() const + { + switch(_order) { + case 0: return MSH_PRI_1; + case 1: return MSH_PRI_6; case 2: - if (_vs.size() == 12) return MSH_PRI_18; - if (_vs.size() == 9) return MSH_PRI_15; + if(_vs.size() == 12) return MSH_PRI_18; + if(_vs.size() == 9) return MSH_PRI_15; break; case 3: - if (_vs.size() == 34) return MSH_PRI_40; - if (_vs.size() == 18) return MSH_PRI_24; + if(_vs.size() == 34) return MSH_PRI_40; + if(_vs.size() == 18) return MSH_PRI_24; break; case 4: - if (_vs.size() == 69) return MSH_PRI_75; - if (_vs.size() == 27) return MSH_PRI_33; + if(_vs.size() == 69) return MSH_PRI_75; + if(_vs.size() == 27) return MSH_PRI_33; break; case 5: - if (_vs.size() == 120) return MSH_PRI_126; - if (_vs.size() == 36) return MSH_PRI_42; + if(_vs.size() == 120) return MSH_PRI_126; + if(_vs.size() == 36) return MSH_PRI_42; break; case 6: - if (_vs.size() == 190) return MSH_PRI_196; - if (_vs.size() == 45) return MSH_PRI_51; + if(_vs.size() == 190) return MSH_PRI_196; + if(_vs.size() == 45) return MSH_PRI_51; break; case 7: - if (_vs.size() == 282) return MSH_PRI_288; - if (_vs.size() == 54) return MSH_PRI_60; + if(_vs.size() == 282) return MSH_PRI_288; + if(_vs.size() == 54) return MSH_PRI_60; break; case 8: - if (_vs.size() == 399) return MSH_PRI_405; - if (_vs.size() == 63) return MSH_PRI_69; + if(_vs.size() == 399) return MSH_PRI_405; + if(_vs.size() == 63) return MSH_PRI_69; break; case 9: - if (_vs.size() == 544) return MSH_PRI_550; - if (_vs.size() == 72) return MSH_PRI_78; + if(_vs.size() == 544) return MSH_PRI_550; + if(_vs.size() == 72) return MSH_PRI_78; break; } - Msg::Error("No tag matches a p%d prism with %d vertices", _order, 6+_vs.size()); + Msg::Error("No tag matches a p%d prism with %d vertices", _order, + 6 + _vs.size()); return 0; } - virtual const char *getStringForPOS() const { - switch (_order) { + virtual const char *getStringForPOS() const + { + switch(_order) { case 0: return "SI0"; case 1: return "SI1"; case 2: return "SI2"; @@ -524,7 +626,9 @@ class MPrismN : public MPrism { virtual void getNode(int num, double &u, double &v, double &w) const { const fullMatrix<double> &p = getFunctionSpace()->points; - u = p(num,0); v = p(num,1); w = p(num,2); + u = p(num, 0); + v = p(num, 1); + w = p(num, 2); } }; diff --git a/Geo/MPyramid.cpp b/Geo/MPyramid.cpp index d674e8dba8fd28db67d5f765ebd46afa81c8c634..1cba8703138d06a0b27a89f28ced9f3a08f823dc 100644 --- a/Geo/MPyramid.cpp +++ b/Geo/MPyramid.cpp @@ -25,9 +25,12 @@ int MPyramid::getVolumeSign() mat[2][1] = _v[3]->z() - _v[0]->z(); mat[2][2] = _v[4]->z() - _v[0]->z(); double d = det3x3(mat); - if(d < 0.) return -1; - else if(d > 0.) return 1; - else return 0; + if(d < 0.) + return -1; + else if(d > 0.) + return 1; + else + return 0; } void MPyramid::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) @@ -36,10 +39,11 @@ void MPyramid::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) *pts = getGQPyrPts(pOrder); } -bool MPyramid::getFaceInfo(const MFace &face, int &ithFace, int &sign, int &rot) const +bool MPyramid::getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const { - for (ithFace = 0; ithFace < 5; ++ithFace) { - if (_getFaceInfo(getFace(ithFace), face, sign, rot)) return true; + for(ithFace = 0; ithFace < 5; ++ithFace) { + if(_getFaceInfo(getFace(ithFace), face, sign, rot)) return true; } Msg::Error("Could not get face information for pyramid %d", getNum()); return false; @@ -51,51 +55,58 @@ int MPyramidN::getNumEdgesRep(bool curved) { // FIXME: remove !getIsAssimilatedSerendipity() when serendip are implemented return (curved && !getIsAssimilatedSerendipity()) ? - 8 * CTX::instance()->mesh.numSubEdges : 8; + 8 * CTX::instance()->mesh.numSubEdges : + 8; } -void MPyramidN::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPyramidN::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { // FIXME: remove !getIsAssimilatedSerendipity() when serendip are implemented - if (curved && !getIsAssimilatedSerendipity()) { + if(curved && !getIsAssimilatedSerendipity()) { int numSubEdges = CTX::instance()->mesh.numSubEdges; - static double pp[5][3] = {{-1,-1,0},{1,-1,0},{1,1,0},{-1,1,0},{0,0,1}}; - static int ed [8][2] = {{0,1},{0,3},{0,4},{1,2},{1,4},{2,3},{2,4},{3,4}}; + static double pp[5][3] = { + {-1, -1, 0}, {1, -1, 0}, {1, 1, 0}, {-1, 1, 0}, {0, 0, 1}}; + static int ed[8][2] = {{0, 1}, {0, 3}, {0, 4}, {1, 2}, + {1, 4}, {2, 3}, {2, 4}, {3, 4}}; int iEdge = num / numSubEdges; int iSubEdge = num % numSubEdges; - int iVertex1 = ed [iEdge][0]; - int iVertex2 = ed [iEdge][1]; - double t1 = (double) iSubEdge / (double) numSubEdges; - double u1 = pp[iVertex1][0] * (1.-t1) + pp[iVertex2][0] * t1; - double v1 = pp[iVertex1][1] * (1.-t1) + pp[iVertex2][1] * t1; - double w1 = pp[iVertex1][2] * (1.-t1) + pp[iVertex2][2] * t1; + int iVertex1 = ed[iEdge][0]; + int iVertex2 = ed[iEdge][1]; + double t1 = (double)iSubEdge / (double)numSubEdges; + double u1 = pp[iVertex1][0] * (1. - t1) + pp[iVertex2][0] * t1; + double v1 = pp[iVertex1][1] * (1. - t1) + pp[iVertex2][1] * t1; + double w1 = pp[iVertex1][2] * (1. - t1) + pp[iVertex2][2] * t1; - double t2 = (double) (iSubEdge+1) / (double) numSubEdges; - double u2 = pp[iVertex1][0] * (1.-t2) + pp[iVertex2][0] * t2; - double v2 = pp[iVertex1][1] * (1.-t2) + pp[iVertex2][1] * t2; - double w2 = pp[iVertex1][2] * (1.-t2) + pp[iVertex2][2] * t2; + double t2 = (double)(iSubEdge + 1) / (double)numSubEdges; + double u2 = pp[iVertex1][0] * (1. - t2) + pp[iVertex2][0] * t2; + double v2 = pp[iVertex1][1] * (1. - t2) + pp[iVertex2][1] * t2; + double w2 = pp[iVertex1][2] * (1. - t2) + pp[iVertex2][2] * t2; SPoint3 pnt1, pnt2; - pnt(u1,v1,w1,pnt1); - pnt(u2,v2,w2,pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + pnt(u1, v1, w1, pnt1); + pnt(u2, v2, w2, pnt2); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); // not great, but better than nothing static const int f[8] = {0, 1, 0, 2, 2, 3, 2, 3}; n[0] = n[1] = getFace(f[iEdge]).normal(); } - else MPyramid::getEdgeRep(false, num, x, y, z, n); + else + MPyramid::getEdgeRep(false, num, x, y, z, n); } int MPyramid::getNumFacesRep(bool curved) { #if defined(HAVE_VISUDEV) - if (CTX::instance()->heavyVisu) { - if (CTX::instance()->mesh.numSubEdges == 1) return 8; + if(CTX::instance()->heavyVisu) { + if(CTX::instance()->mesh.numSubEdges == 1) return 8; return 6 * std::pow(CTX::instance()->mesh.numSubEdges, 2); } #endif @@ -106,35 +117,31 @@ int MPyramidN::getNumFacesRep(bool curved) { // FIXME: remove !getIsAssimilatedSerendipity() when serendip are implemented return (curved && !getIsAssimilatedSerendipity()) ? - 6 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MPyramid::getNumFacesRep(curved); + 6 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : + MPyramid::getNumFacesRep(curved); } -static void _myGetFaceRep(MPyramid *pyr, int num, double *x, double *y, double *z, - SVector3 *n, int numSubEdges) +static void _myGetFaceRep(MPyramid *pyr, int num, double *x, double *y, + double *z, SVector3 *n, int numSubEdges) { static double pp[5][3] = { - {-1,-1,0}, - {1,-1,0}, - {1,1,0}, - {-1,1,0}, - {0,0,1} - }; - int iFace = num / (numSubEdges * numSubEdges); + {-1, -1, 0}, {1, -1, 0}, {1, 1, 0}, {-1, 1, 0}, {0, 0, 1}}; + int iFace = num / (numSubEdges * numSubEdges); int iSubFace = num % (numSubEdges * numSubEdges); - if (iFace > 3) { + if(iFace > 3) { iFace = 4; - iSubFace = num % (2*numSubEdges * numSubEdges); + iSubFace = num % (2 * numSubEdges * numSubEdges); } int iVertex1, iVertex2, iVertex3, iVertex4; - if (iFace < 4) { - iVertex1 = pyr->faces_pyramid(iFace,0); - iVertex2 = pyr->faces_pyramid(iFace,1); - iVertex3 = pyr->faces_pyramid(iFace,2); - } else { + if(iFace < 4) { + iVertex1 = pyr->faces_pyramid(iFace, 0); + iVertex2 = pyr->faces_pyramid(iFace, 1); + iVertex3 = pyr->faces_pyramid(iFace, 2); + } + else { iVertex1 = 0; iVertex2 = 1; iVertex3 = 2; @@ -143,14 +150,13 @@ static void _myGetFaceRep(MPyramid *pyr, int num, double *x, double *y, double * SPoint3 pnt1, pnt2, pnt3; - if (iFace < 4) { - + if(iFace < 4) { int ix = 0, iy = 0; int nbt = 0; - for (int i = 0; i < numSubEdges; i++){ + for(int i = 0; i < numSubEdges; i++) { int nbl = (numSubEdges - i - 1) * 2 + 1; nbt += nbl; - if (nbt > iSubFace){ + if(nbt > iSubFace) { iy = i; ix = nbl - (nbt - iSubFace); break; @@ -160,35 +166,49 @@ static void _myGetFaceRep(MPyramid *pyr, int num, double *x, double *y, double * const double d = 1. / numSubEdges; double u1, v1, u2, v2, u3, v3; - if (ix % 2 == 0){ - u1 = ix / 2 * d; v1= iy*d; - u2 = (ix / 2 + 1) * d ; v2 = iy * d; - u3 = ix / 2 * d ; v3 = (iy+1) * d; + if(ix % 2 == 0) { + u1 = ix / 2 * d; + v1 = iy * d; + u2 = (ix / 2 + 1) * d; + v2 = iy * d; + u3 = ix / 2 * d; + v3 = (iy + 1) * d; } - else{ - u1 = (ix / 2 + 1) * d; v1= iy * d; - u2 = (ix / 2 + 1) * d; v2= (iy + 1) * d; - u3 = ix / 2 * d ; v3 = (iy + 1) * d; + else { + u1 = (ix / 2 + 1) * d; + v1 = iy * d; + u2 = (ix / 2 + 1) * d; + v2 = (iy + 1) * d; + u3 = ix / 2 * d; + v3 = (iy + 1) * d; } - double U1 = pp[iVertex1][0] * (1.-u1-v1) + pp[iVertex2][0] * u1 + pp[iVertex3][0] * v1; - double U2 = pp[iVertex1][0] * (1.-u2-v2) + pp[iVertex2][0] * u2 + pp[iVertex3][0] * v2; - double U3 = pp[iVertex1][0] * (1.-u3-v3) + pp[iVertex2][0] * u3 + pp[iVertex3][0] * v3; - - double V1 = pp[iVertex1][1] * (1.-u1-v1) + pp[iVertex2][1] * u1 + pp[iVertex3][1] * v1; - double V2 = pp[iVertex1][1] * (1.-u2-v2) + pp[iVertex2][1] * u2 + pp[iVertex3][1] * v2; - double V3 = pp[iVertex1][1] * (1.-u3-v3) + pp[iVertex2][1] * u3 + pp[iVertex3][1] * v3; - - double W1 = pp[iVertex1][2] * (1.-u1-v1) + pp[iVertex2][2] * u1 + pp[iVertex3][2] * v1; - double W2 = pp[iVertex1][2] * (1.-u2-v2) + pp[iVertex2][2] * u2 + pp[iVertex3][2] * v2; - double W3 = pp[iVertex1][2] * (1.-u3-v3) + pp[iVertex2][2] * u3 + pp[iVertex3][2] * v3; + double U1 = pp[iVertex1][0] * (1. - u1 - v1) + pp[iVertex2][0] * u1 + + pp[iVertex3][0] * v1; + double U2 = pp[iVertex1][0] * (1. - u2 - v2) + pp[iVertex2][0] * u2 + + pp[iVertex3][0] * v2; + double U3 = pp[iVertex1][0] * (1. - u3 - v3) + pp[iVertex2][0] * u3 + + pp[iVertex3][0] * v3; + + double V1 = pp[iVertex1][1] * (1. - u1 - v1) + pp[iVertex2][1] * u1 + + pp[iVertex3][1] * v1; + double V2 = pp[iVertex1][1] * (1. - u2 - v2) + pp[iVertex2][1] * u2 + + pp[iVertex3][1] * v2; + double V3 = pp[iVertex1][1] * (1. - u3 - v3) + pp[iVertex2][1] * u3 + + pp[iVertex3][1] * v3; + + double W1 = pp[iVertex1][2] * (1. - u1 - v1) + pp[iVertex2][2] * u1 + + pp[iVertex3][2] * v1; + double W2 = pp[iVertex1][2] * (1. - u2 - v2) + pp[iVertex2][2] * u2 + + pp[iVertex3][2] * v2; + double W3 = pp[iVertex1][2] * (1. - u3 - v3) + pp[iVertex2][2] * u3 + + pp[iVertex3][2] * v3; pyr->pnt(U1, V1, W1, pnt1); pyr->pnt(U2, V2, W2, pnt2); pyr->pnt(U3, V3, W3, pnt3); } else { - /* 0 0 1 @@ -201,134 +221,122 @@ static void _myGetFaceRep(MPyramid *pyr, int num, double *x, double *y, double * // on each layer, we have (numSubEdges) * 2 triangles // ix and iy are the coordinates of the sub-quadrangle - int io = iSubFace%2; - int ix = (iSubFace/2)/numSubEdges; - int iy = (iSubFace/2)%numSubEdges; + int io = iSubFace % 2; + int ix = (iSubFace / 2) / numSubEdges; + int iy = (iSubFace / 2) % numSubEdges; const double d = 2. / numSubEdges; - double ox = -1. + d*ix; - double oy = -1. + d*iy; - - if (io == 0){ - double U1 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V1 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W1 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; - - ox += d; - - double U2 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V2 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W2 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; - - oy += d; - - double U3 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V3 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W3 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; - - pyr->pnt(U1,V1,W1, pnt1); - pyr->pnt(U2,V2,W2, pnt2); - pyr->pnt(U3,V3,W3, pnt3); + double ox = -1. + d * ix; + double oy = -1. + d * iy; + + if(io == 0) { + double U1 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V1 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W1 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; + + ox += d; + + double U2 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V2 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W2 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; + + oy += d; + + double U3 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V3 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W3 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; + + pyr->pnt(U1, V1, W1, pnt1); + pyr->pnt(U2, V2, W2, pnt2); + pyr->pnt(U3, V3, W3, pnt3); } - else{ - double U1 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V1 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W1 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; - - ox += d; - oy += d; - - double U2 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V2 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W2 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; - - ox -= d; - - double U3 = - pp[iVertex1][0] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][0] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][0] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][0] * (1.-ox)*(1+oy)*.25; - double V3 = - pp[iVertex1][1] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][1] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][1] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][1] * (1.-ox)*(1+oy)*.25; - double W3 = - pp[iVertex1][2] * (1.-ox)*(1-oy)*.25 + - pp[iVertex2][2] * (1.+ox)*(1-oy)*.25 + - pp[iVertex3][2] * (1.+ox)*(1+oy)*.25 + - pp[iVertex4][2] * (1.-ox)*(1+oy)*.25; - - pyr->pnt(U1,V1,W1, pnt1); - pyr->pnt(U2,V2,W2, pnt2); - pyr->pnt(U3,V3,W3, pnt3); + else { + double U1 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V1 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W1 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; + + ox += d; + oy += d; + + double U2 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V2 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W2 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; + + ox -= d; + + double U3 = pp[iVertex1][0] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][0] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][0] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][0] * (1. - ox) * (1 + oy) * .25; + double V3 = pp[iVertex1][1] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][1] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][1] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][1] * (1. - ox) * (1 + oy) * .25; + double W3 = pp[iVertex1][2] * (1. - ox) * (1 - oy) * .25 + + pp[iVertex2][2] * (1. + ox) * (1 - oy) * .25 + + pp[iVertex3][2] * (1. + ox) * (1 + oy) * .25 + + pp[iVertex4][2] * (1. - ox) * (1 + oy) * .25; + + pyr->pnt(U1, V1, W1, pnt1); + pyr->pnt(U2, V2, W2, pnt2); + pyr->pnt(U3, V3, W3, pnt3); } } - x[0] = pnt1.x(); x[1] = pnt2.x(); x[2] = pnt3.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); y[2] = pnt3.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); z[2] = pnt3.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + x[2] = pnt3.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + y[2] = pnt3.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); + z[2] = pnt3.z(); SVector3 d1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); SVector3 d2(x[2] - x[0], y[2] - y[0], z[2] - z[0]); @@ -338,56 +346,51 @@ static void _myGetFaceRep(MPyramid *pyr, int num, double *x, double *y, double * n[2] = n[0]; } -void MPyramid::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPyramid::getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { #if defined(HAVE_VISUDEV) static const int fquad[4][4] = { - {0, 3, 2, 1}, {3, 2, 1, 0}, {2, 1, 0, 3}, {1, 0, 3, 2} - }; - if (CTX::instance()->heavyVisu) { - if (CTX::instance()->mesh.numSubEdges > 1) { + {0, 3, 2, 1}, {3, 2, 1, 0}, {2, 1, 0, 3}, {1, 0, 3, 2}}; + if(CTX::instance()->heavyVisu) { + if(CTX::instance()->mesh.numSubEdges > 1) { _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); return; } - if (num > 3) { + if(num > 3) { int i = num - 4; _getFaceRepQuad(getVertex(fquad[i][0]), getVertex(fquad[i][1]), - getVertex(fquad[i][2]), getVertex(fquad[i][3]), - x, y, z, n); + getVertex(fquad[i][2]), getVertex(fquad[i][3]), x, y, z, + n); return; } } #endif - static const int f[6][3] = { - {0, 1, 4}, - {3, 0, 4}, - {1, 2, 4}, - {2, 3, 4}, - {0, 3, 2}, {0, 2, 1} - }; + static const int f[6][3] = {{0, 1, 4}, {3, 0, 4}, {1, 2, 4}, + {2, 3, 4}, {0, 3, 2}, {0, 2, 1}}; _getFaceRep(getVertex(f[num][0]), getVertex(f[num][1]), getVertex(f[num][2]), x, y, z, n); } int MPyramid::numCommonNodesInDualGraph(const MElement *const other) const { - switch (other->getType()) { - case TYPE_PNT: return 1; - case TYPE_LIN: return 2; - case TYPE_QUA: return 4; - case TYPE_HEX: return 4; - default: return 3; + switch(other->getType()) { + case TYPE_PNT: return 1; + case TYPE_LIN: return 2; + case TYPE_QUA: return 4; + case TYPE_HEX: return 4; + default: return 3; } } -void MPyramidN::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MPyramidN::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { // FIXME: remove !getIsAssimilatedSerendipity() when serendip are implemented - if (curved && !getIsAssimilatedSerendipity()) + if(curved && !getIsAssimilatedSerendipity()) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MPyramid::getFaceRep(false, num, x, y, z, n); + else + MPyramid::getFaceRep(false, num, x, y, z, n); } void _getIndicesReversedPyr(int order, IndicesReversed &indices) @@ -395,12 +398,12 @@ void _getIndicesReversedPyr(int order, IndicesReversed &indices) fullMatrix<double> ref = gmshGenerateMonomialsPyramid(order); indices.resize(ref.size1()); - for (int i = 0; i < ref.size1(); ++i) { + for(int i = 0; i < ref.size1(); ++i) { const double u = ref(i, 0); const double v = ref(i, 1); const double w = ref(i, 2); - for (int j = 0; j < ref.size1(); ++j) { - if (u == ref(j, 1) && v == ref(j, 0) && w == ref(j, 2)) { + for(int j = 0; j < ref.size1(); ++j) { + if(u == ref(j, 1) && v == ref(j, 0) && w == ref(j, 2)) { indices[i] = j; break; } @@ -412,7 +415,7 @@ void MPyramidN::reverse() { std::map<int, IndicesReversed>::iterator it; it = _order2indicesReversedPyr.find(_order); - if (it == _order2indicesReversedPyr.end()) { + if(it == _order2indicesReversedPyr.end()) { IndicesReversed indices; _getIndicesReversedPyr(_order, indices); _order2indicesReversedPyr[_order] = indices; @@ -422,37 +425,40 @@ void MPyramidN::reverse() IndicesReversed &indices = it->second; // copy vertices - std::vector<MVertex*> oldv(5 + _vs.size()); - std::copy(_v, _v+5, oldv.begin()); - std::copy(_vs.begin(), _vs.end(), oldv.begin()+5); + std::vector<MVertex *> oldv(5 + _vs.size()); + std::copy(_v, _v + 5, oldv.begin()); + std::copy(_vs.begin(), _vs.end(), oldv.begin() + 5); // reverse - for (int i = 0; i < 5; ++i) { + for(int i = 0; i < 5; ++i) { _v[i] = oldv[indices[i]]; } - for (unsigned int i = 0; i < _vs.size(); ++i) { - _vs[i] = oldv[indices[5+i]]; + for(unsigned int i = 0; i < _vs.size(); ++i) { + _vs[i] = oldv[indices[5 + i]]; } } -void MPyramidN::_addHOEdgePoints(int num,std::vector<MVertex*>& v,bool fwd) const +void MPyramidN::_addHOEdgePoints(int num, std::vector<MVertex *> &v, + bool fwd) const { - int minVtx = num * (_order-1); - int maxVtx = (num+1) * (_order-1) - 1; + int minVtx = num * (_order - 1); + int maxVtx = (num + 1) * (_order - 1) - 1; - if (fwd) for (int i=minVtx;i<=maxVtx;i++) v.push_back(_vs[i]); - else for (int i=maxVtx;i>=minVtx;i--) v.push_back(_vs[i]); + if(fwd) + for(int i = minVtx; i <= maxVtx; i++) v.push_back(_vs[i]); + else + for(int i = maxVtx; i >= minVtx; i--) v.push_back(_vs[i]); } -void MPyramidN::getFaceVertices(const int num, std::vector<MVertex*> &v) const +void MPyramidN::getFaceVertices(const int num, std::vector<MVertex *> &v) const { bool complete = !getIsAssimilatedSerendipity(); - int nbQ = (_order-1)*(_order-1); - int nbT = (_order-1)*(_order-2)/2; + int nbQ = (_order - 1) * (_order - 1); + int nbT = (_order - 1) * (_order - 2) / 2; - int nb = ((num==4) ? 4:3) * _order; - if (complete) nb += (num==4) ? nbQ:nbT; + int nb = ((num == 4) ? 4 : 3) * _order; + if(complete) nb += (num == 4) ? nbQ : nbT; v.reserve(nb); @@ -468,48 +474,48 @@ void MPyramidN::getFaceVertices(const int num, std::vector<MVertex*> &v) const v.push_back(_v[1]); } - switch (num) { + switch(num) { case 0: // 0 1 4 - { - _addHOEdgePoints(0,v); - _addHOEdgePoints(4,v); - _addHOEdgePoints(2,v,false); - break; - } + { + _addHOEdgePoints(0, v); + _addHOEdgePoints(4, v); + _addHOEdgePoints(2, v, false); + break; + } case 1: // 3 0 4 - { - _addHOEdgePoints(1,v,false); - _addHOEdgePoints(2,v); - _addHOEdgePoints(7,v,false); - break; - } + { + _addHOEdgePoints(1, v, false); + _addHOEdgePoints(2, v); + _addHOEdgePoints(7, v, false); + break; + } case 2: // 1 2 4 - { - _addHOEdgePoints(3,v); - _addHOEdgePoints(6,v); - _addHOEdgePoints(4,v,false); - break; - } + { + _addHOEdgePoints(3, v); + _addHOEdgePoints(6, v); + _addHOEdgePoints(4, v, false); + break; + } case 3: // 2 3 4 - { - _addHOEdgePoints(3,v); - _addHOEdgePoints(6,v); - _addHOEdgePoints(4,v,false); - break; - } + { + _addHOEdgePoints(3, v); + _addHOEdgePoints(6, v); + _addHOEdgePoints(4, v, false); + break; + } case 4: // 0 3 2 1 - { - _addHOEdgePoints(1,v); - _addHOEdgePoints(5,v,false); - _addHOEdgePoints(3,v,false); - _addHOEdgePoints(1,v,false); - break; - } + { + _addHOEdgePoints(1, v); + _addHOEdgePoints(5, v, false); + _addHOEdgePoints(3, v, false); + _addHOEdgePoints(1, v, false); + break; + } } - if (complete) { - int start = 8*(_order-1) + num*nbT; + if(complete) { + int start = 8 * (_order - 1) + num * nbT; int nbPoints = (num == 4) ? nbQ : nbT; - for (int i=start;i<start+nbPoints;i++) v.push_back(_vs[i]); + for(int i = start; i < start + nbPoints; i++) v.push_back(_vs[i]); } } diff --git a/Geo/MPyramid.h b/Geo/MPyramid.h index 8c58eb734526c590df196bd6faaf6293b66ec6f4..d955550c1af02e2af9928c363dc134e4121205f5 100644 --- a/Geo/MPyramid.h +++ b/Geo/MPyramid.h @@ -30,14 +30,14 @@ * */ class MPyramid : public MElement { - protected: +protected: MVertex *_v[5]; - void _getEdgeVertices(const int num, std::vector<MVertex*> &v) const + void _getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[edges_pyramid(num, 0)]; v[1] = _v[edges_pyramid(num, 1)]; } - void _getFaceVertices(const int num, std::vector<MVertex*> &v) const + void _getFaceVertices(const int num, std::vector<MVertex *> &v) const { if(num < 4) { v[0] = _v[faces_pyramid(num, 0)]; @@ -51,25 +51,30 @@ class MPyramid : public MElement { v[3] = _v[1]; } } - public : + +public: MPyramid(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, - int num=0, int part=0) + int num = 0, int part = 0) : MElement(num, part) { - _v[0] = v0; _v[1] = v1; _v[2] = v2; _v[3] = v3; _v[4] = v4; + _v[0] = v0; + _v[1] = v1; + _v[2] = v2; + _v[3] = v3; + _v[4] = v4; } - MPyramid(const std::vector<MVertex*> &v, int num=0, int part=0) + MPyramid(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { for(int i = 0; i < 5; i++) _v[i] = v[i]; } - ~MPyramid(){} + ~MPyramid() {} virtual int getDim() const { return 3; } virtual std::size_t getNumVertices() const { return 5; } - virtual MVertex *getVertex(int num){ return _v[num]; } - virtual const MVertex *getVertex(int num) const{ return _v[num]; } - virtual void setVertex(int num, MVertex *v){ _v[num] = v; } - virtual int getNumEdges()const{ return 8; } + virtual MVertex *getVertex(int num) { return _v[num]; } + virtual const MVertex *getVertex(int num) const { return _v[num]; } + virtual void setVertex(int num, MVertex *v) { _v[num] = v; } + virtual int getNumEdges() const { return 8; } virtual MEdge getEdge(int num) const { return MEdge(_v[edges_pyramid(num, 0)], _v[edges_pyramid(num, 1)]); @@ -78,7 +83,7 @@ class MPyramid : public MElement { { return edges_pyramid(numEdge, numVert); } - virtual int getNumEdgesRep(bool curved){ return 8; } + virtual int getNumEdgesRep(bool curved) { return 8; } virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) { @@ -86,17 +91,16 @@ class MPyramid : public MElement { MEdge e(getEdge(num)); _getEdgeRep(e.getVertex(0), e.getVertex(1), x, y, z, n, f[num]); } - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); _getEdgeVertices(num, v); } - virtual int getNumFaces(){ return 5; } + virtual int getNumFaces() { return 5; } virtual MFace getFace(int num) const { if(num < 4) - return MFace(_v[faces_pyramid(num, 0)], - _v[faces_pyramid(num, 1)], + return MFace(_v[faces_pyramid(num, 0)], _v[faces_pyramid(num, 1)], _v[faces_pyramid(num, 2)]); else return MFace(_v[0], _v[3], _v[2], _v[1]); @@ -104,12 +108,13 @@ class MPyramid : public MElement { virtual int getNumFacesRep(bool curved); virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize((num < 4) ? 3 : 4); _getFaceVertices(num, v); } - virtual bool getFaceInfo(const MFace & face, int &ithFace, int &sign, int &rot) const; + virtual bool getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const; virtual int getType() const { return TYPE_PYR; } virtual int getTypeForMSH() const { return MSH_PYR_5; } virtual int getTypeForVTK() const { return 14; } @@ -117,24 +122,47 @@ class MPyramid : public MElement { virtual const char *getStringForBDF() const { return "CPYRAM"; } virtual void reverse() { - MVertex *tmp = _v[0]; _v[0] = _v[2]; _v[2] = tmp; + MVertex *tmp = _v[0]; + _v[0] = _v[2]; + _v[2] = tmp; } virtual int getVolumeSign(); virtual void getNode(int num, double &u, double &v, double &w) const { switch(num) { - case 0 : u = -1.; v = -1.; w = 0.; break; - case 1 : u = 1.; v = -1.; w = 0.; break; - case 2 : u = 1.; v = 1.; w = 0.; break; - case 3 : u = -1.; v = 1.; w = 0.; break; - case 4 : u = 0.; v = 0.; w = 1.; break; - default: u = 0.; v = 0.; w = 0.; break; + case 0: + u = -1.; + v = -1.; + w = 0.; + break; + case 1: + u = 1.; + v = -1.; + w = 0.; + break; + case 2: + u = 1.; + v = 1.; + w = 0.; + break; + case 3: + u = -1.; + v = 1.; + w = 0.; + break; + case 4: + u = 0.; + v = 0.; + w = 1.; + break; + default: + u = 0.; + v = 0.; + w = 0.; + break; } } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0., 0., .2); - } + virtual SPoint3 barycenterUVW() const { return SPoint3(0., 0., .2); } virtual bool isInside(double u, double v, double w) const { double tol = getTolerance(); @@ -146,40 +174,25 @@ class MPyramid : public MElement { void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); static int edges_pyramid(const int edge, const int vert) { - static const int e[8][2] = { - {0, 1}, - {0, 3}, - {0, 4}, - {1, 2}, - {1, 4}, - {2, 3}, - {2, 4}, - {3, 4} - }; + static const int e[8][2] = {{0, 1}, {0, 3}, {0, 4}, {1, 2}, + {1, 4}, {2, 3}, {2, 4}, {3, 4}}; return e[edge][vert]; } static int faces_pyramid(const int face, const int vert) { static const int f[5][4] = { - {0, 1, 4, -1}, - {3, 0, 4, -1}, - {1, 2, 4, -1}, - {2, 3, 4, -1}, - {0, 3, 2, 1} - }; + {0, 1, 4, -1}, {3, 0, 4, -1}, {1, 2, 4, -1}, {2, 3, 4, -1}, {0, 3, 2, 1}}; return f[face][vert]; } static int faces2edge_pyramid(const int face, const int edge) { // return -iedge - 1 if edge is inverted // iedge + 1 otherwise - static const int e[5][4] = { - {1, 5, -3, 0}, - {-2, 3, -8, 0}, - {4, 7, -5, 0}, - {6, 8, -7, 0}, - {2, -6, -4, -1} - }; + static const int e[5][4] = {{1, 5, -3, 0}, + {-2, 3, -8, 0}, + {4, 7, -5, 0}, + {6, 8, -7, 0}, + {2, -6, -4, -1}}; return e[face][edge]; } virtual int numCommonNodesInDualGraph(const MElement *const other) const; @@ -232,65 +245,83 @@ typedef std::vector<int> IndicesReversed; class MPyramidN : public MPyramid { static std::map<int, IndicesReversed> _order2indicesReversedPyr; - protected: - std::vector<MVertex*> _vs; +protected: + std::vector<MVertex *> _vs; const char _order; - void _addHOEdgePoints(int num,std::vector<MVertex*>& v,bool fw=true) const; + void _addHOEdgePoints(int num, std::vector<MVertex *> &v, + bool fw = true) const; - public: - MPyramidN(MVertex* v0, MVertex* v1, MVertex* v2, MVertex* v3, MVertex* v4, - const std::vector<MVertex*> &v, char order, int num=0, int part=0) +public: + MPyramidN(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, + const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) : MPyramid(v0, v1, v2, v3, v4, num, part), _vs(v), _order(order) { - for (unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); getFunctionSpace(order); } - MPyramidN(const std::vector<MVertex*> &v, char order, int num=0, int part=0) + MPyramidN(const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) : MPyramid(v[0], v[1], v[2], v[3], v[4], num, part), _order(order) { - for (unsigned int i = 5; i < v.size(); i++ ) _vs.push_back(v[i]); - for (unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 5; i < v.size(); i++) _vs.push_back(v[i]); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); getFunctionSpace(order); } ~MPyramidN(); virtual int getPolynomialOrder() const { return _order; } virtual std::size_t getNumVertices() const { return 5 + _vs.size(); } - virtual MVertex *getVertex(int num){ return num < 5 ? _v[num] : _vs[num - 5]; } - virtual const MVertex *getVertex(int num) const { return num < 5 ? _v[num] : _vs[num - 5]; } - virtual void setVertex(int num, MVertex *v){ if(num < 5) _v[num] = v; else _vs[num - 5] = v; } + virtual MVertex *getVertex(int num) + { + return num < 5 ? _v[num] : _vs[num - 5]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 5 ? _v[num] : _vs[num - 5]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 5) + _v[num] = v; + else + _vs[num - 5] = v; + } virtual int getNumEdgeVertices() const { return 8 * (_order - 1); } virtual int getNumFaceVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; else - return (_order-1)*(_order-1) + 4 * ((_order - 1) * (_order - 2)) / 2; + return (_order - 1) * (_order - 1) + + 4 * ((_order - 1) * (_order - 2)) / 2; } - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { - v.resize(_order+1); + v.resize(_order + 1); MPyramid::_getEdgeVertices(num, v); int j = 2; const int ie = (num + 1) * (_order - 1); - for(int i = num * (_order -1); i != ie; ++i) v[j++] = _vs[i]; + for(int i = num * (_order - 1); i != ie; ++i) v[j++] = _vs[i]; } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const; + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const; virtual int getNumVolumeVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; else - return (_order-2) * ((_order-2)+1) * (2*(_order-2)+1) / 6; + return (_order - 2) * ((_order - 2) + 1) * (2 * (_order - 2) + 1) / 6; } virtual int getTypeForMSH() const { - if(_order == 1 && _vs.size() + 5 == 5) return MSH_PYR_5; - if(_order == 2 && _vs.size() + 5 == 14) return MSH_PYR_14; - if(_order == 3 && _vs.size() + 5 == 30) return MSH_PYR_30; - if(_order == 4 && _vs.size() + 5 == 55) return MSH_PYR_55; - if(_order == 5 && _vs.size() + 5 == 91) return MSH_PYR_91; + if(_order == 1 && _vs.size() + 5 == 5) return MSH_PYR_5; + if(_order == 2 && _vs.size() + 5 == 14) return MSH_PYR_14; + if(_order == 3 && _vs.size() + 5 == 30) return MSH_PYR_30; + if(_order == 4 && _vs.size() + 5 == 55) return MSH_PYR_55; + if(_order == 5 && _vs.size() + 5 == 91) return MSH_PYR_91; if(_order == 6 && _vs.size() + 5 == 140) return MSH_PYR_140; if(_order == 7 && _vs.size() + 5 == 204) return MSH_PYR_204; if(_order == 8 && _vs.size() + 5 == 285) return MSH_PYR_285; @@ -304,7 +335,8 @@ class MPyramidN : public MPyramid { if(_order == 7 && _vs.size() + 5 == 53) return MSH_PYR_53; if(_order == 8 && _vs.size() + 5 == 61) return MSH_PYR_61; if(_order == 9 && _vs.size() + 5 == 69) return MSH_PYR_69; - Msg::Error("no tag matches a p%d pyramid with %d vertices", _order, 5+_vs.size()); + Msg::Error("no tag matches a p%d pyramid with %d vertices", _order, + 5 + _vs.size()); return 0; } virtual void reverse(); diff --git a/Geo/MQuadrangle.cpp b/Geo/MQuadrangle.cpp index 17103314c6e61eed7f823a8230efcbe51cb9c2ff..b8d402075e622357a65528d34a06f30982442d72 100644 --- a/Geo/MQuadrangle.cpp +++ b/Geo/MQuadrangle.cpp @@ -17,15 +17,19 @@ #include <cstring> -void MQuadrangle::getEdgeRep(bool curved, int num, double *x, double *y, double *z, - SVector3 *n) +void MQuadrangle::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { // don't use MElement::_getEdgeRep: it's slow due to the creation of MFace MVertex *v0 = _v[edges_quad(num, 0)]; MVertex *v1 = _v[edges_quad(num, 1)]; - x[0] = v0->x(); y[0] = v0->y(); z[0] = v0->z(); - x[1] = v1->x(); y[1] = v1->y(); z[1] = v1->z(); - if(CTX::instance()->mesh.lightLines){ + x[0] = v0->x(); + y[0] = v0->y(); + z[0] = v0->z(); + x[1] = v1->x(); + y[1] = v1->y(); + z[1] = v1->z(); + if(CTX::instance()->mesh.lightLines) { static const int vv[4] = {2, 3, 0, 1}; MVertex *v2 = _v[vv[num]]; SVector3 t1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); @@ -34,7 +38,7 @@ void MQuadrangle::getEdgeRep(bool curved, int num, double *x, double *y, double normal.normalize(); n[0] = n[1] = normal; } - else{ + else { n[0] = n[1] = SVector3(0., 0., 1.); } } @@ -56,8 +60,7 @@ int MQuadrangle9::getNumEdgesRep(bool curved) double MQuadrangle::getVolume() { - if(getNumVertices() > 4) - return MElement::getVolume(); + if(getNumVertices() > 4) return MElement::getVolume(); double a = _v[0]->distance(_v[1]); double b = _v[1]->distance(_v[2]); double c = _v[2]->distance(_v[3]); @@ -65,80 +68,88 @@ double MQuadrangle::getVolume() double m = _v[0]->distance(_v[2]); double n = _v[1]->distance(_v[3]); double mn = 2. * m * n; - double abcd = a*a - b*b + c*c - d*d; - return sqrt( mn*mn - abcd*abcd ) / 4.; + double abcd = a * a - b * b + c * c - d * d; + return sqrt(mn * mn - abcd * abcd) / 4.; } int MQuadrangle::numCommonNodesInDualGraph(const MElement *const other) const { - switch (other->getType()) - { - case TYPE_PNT: return 1; - case TYPE_LIN: return 2; - case TYPE_TRI: return 2; - case TYPE_QUA: return 2; - default: return 4; + switch(other->getType()) { + case TYPE_PNT: return 1; + case TYPE_LIN: return 2; + case TYPE_TRI: return 2; + case TYPE_QUA: return 2; + default: return 4; } } -static void _myGetEdgeRep(MQuadrangle *q, int num, double *x, double *y, double *z, - SVector3 *n, int numSubEdges) +static void _myGetEdgeRep(MQuadrangle *q, int num, double *x, double *y, + double *z, SVector3 *n, int numSubEdges) { n[0] = n[1] = q->getFace(0).normal(); - int ie = num/numSubEdges; - int isub = num%numSubEdges; - double xi1 = -1. + (2.*isub)/numSubEdges; - double xi2 = -1. + (2.*(isub+1))/numSubEdges; + int ie = num / numSubEdges; + int isub = num % numSubEdges; + double xi1 = -1. + (2. * isub) / numSubEdges; + double xi2 = -1. + (2. * (isub + 1)) / numSubEdges; SPoint3 pnt1, pnt2; - switch(ie){ - case 0: - q->pnt( xi1, -1., 0., pnt1); - q->pnt( xi2, -1., 0., pnt2); - break; - case 1: - q->pnt( 1., xi1, 0., pnt1); - q->pnt( 1., xi2, 0., pnt2); - break; - case 2: - q->pnt( xi1, 1., 0., pnt1); - q->pnt( xi2, 1., 0., pnt2); - break; - case 3: - q->pnt(-1., xi1, 0., pnt1); - q->pnt(-1., xi2, 0., pnt2); - break; + switch(ie) { + case 0: + q->pnt(xi1, -1., 0., pnt1); + q->pnt(xi2, -1., 0., pnt2); + break; + case 1: + q->pnt(1., xi1, 0., pnt1); + q->pnt(1., xi2, 0., pnt2); + break; + case 2: + q->pnt(xi1, 1., 0., pnt1); + q->pnt(xi2, 1., 0., pnt2); + break; + case 3: + q->pnt(-1., xi1, 0., pnt1); + q->pnt(-1., xi2, 0., pnt2); + break; } - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); } -void MQuadrangleN::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MQuadrangleN::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MQuadrangle::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MQuadrangle::getEdgeRep(false, num, x, y, z, n); } -void MQuadrangle8::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MQuadrangle8::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MQuadrangle::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MQuadrangle::getEdgeRep(false, num, x, y, z, n); } -void MQuadrangle9::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MQuadrangle9::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MQuadrangle::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MQuadrangle::getEdgeRep(false, num, x, y, z, n); } -bool MQuadrangle::getFaceInfo(const MFace & face, int &ithFace, int &sign, +bool MQuadrangle::getFaceInfo(const MFace &face, int &ithFace, int &sign, int &rot) const { ithFace = 0; - if (_getFaceInfo(MFace(_v[0], _v[1], _v[2], _v[3]), face, sign, rot)) + if(_getFaceInfo(MFace(_v[0], _v[1], _v[2], _v[3]), face, sign, rot)) return true; Msg::Error("Could not get face information for quadrangle %d", getNum()); return false; @@ -147,8 +158,8 @@ bool MQuadrangle::getFaceInfo(const MFace & face, int &ithFace, int &sign, int MQuadrangle::getNumFacesRep(bool curved) { #if defined(HAVE_VISUDEV) - if (CTX::instance()->heavyVisu) { - if (CTX::instance()->mesh.numSubEdges == 1) return 4; + if(CTX::instance()->heavyVisu) { + if(CTX::instance()->mesh.numSubEdges == 1) return 4; return 2 * std::pow(CTX::instance()->mesh.numSubEdges, 2); } #endif @@ -158,42 +169,43 @@ int MQuadrangle::getNumFacesRep(bool curved) int MQuadrangleN::getNumFacesRep(bool curved) { return curved ? 2 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MQuadrangle::getNumFacesRep(curved); + MQuadrangle::getNumFacesRep(curved); } int MQuadrangle8::getNumFacesRep(bool curved) { return curved ? 2 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MQuadrangle::getNumFacesRep(curved); + MQuadrangle::getNumFacesRep(curved); } int MQuadrangle9::getNumFacesRep(bool curved) { return curved ? 2 * std::pow(CTX::instance()->mesh.numSubEdges, 2) : - MQuadrangle::getNumFacesRep(curved); + MQuadrangle::getNumFacesRep(curved); } -static void _myGetFaceRep(MQuadrangle *t, int num, double *x, double *y, double *z, - SVector3 *n, int numSubEdges) +static void _myGetFaceRep(MQuadrangle *t, int num, double *x, double *y, + double *z, SVector3 *n, int numSubEdges) { - int io = num%2; - int ix = (num/2)/numSubEdges; - int iy = (num/2)%numSubEdges; + int io = num % 2; + int ix = (num / 2) / numSubEdges; + int iy = (num / 2) % numSubEdges; const double d = 2. / numSubEdges; - const double ox = -1. + d*ix; - const double oy = -1. + d*iy; + const double ox = -1. + d * ix; + const double oy = -1. + d * iy; SPoint3 pnt1, pnt2, pnt3; double J1[3][3], J2[3][3], J3[3][3]; - if (io == 0){ + if(io == 0) { t->pnt(ox, oy, 0, pnt1); t->pnt(ox + d, oy, 0, pnt2); t->pnt(ox + d, oy + d, 0, pnt3); t->getJacobian(ox, oy, 0, J1); t->getJacobian(ox + d, oy, 0, J2); t->getJacobian(ox + d, oy + d, 0, J3); - } else{ + } + else { t->pnt(ox, oy, 0, pnt1); t->pnt(ox + d, oy + d, 0, pnt2); t->pnt(ox, oy + d, 0, pnt3); @@ -220,54 +232,63 @@ static void _myGetFaceRep(MQuadrangle *t, int num, double *x, double *y, double n[2].normalize(); } - x[0] = pnt1.x(); x[1] = pnt2.x(); x[2] = pnt3.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); y[2] = pnt3.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); z[2] = pnt3.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + x[2] = pnt3.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + y[2] = pnt3.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); + z[2] = pnt3.z(); } -void MQuadrangle::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MQuadrangle::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { #if defined(HAVE_VISUDEV) static const int fquad[4][4] = { - {0, 1, 2, 3}, {1, 2, 3, 0}, {2, 3, 0, 1}, {3, 0, 1, 2} - }; - if (CTX::instance()->heavyVisu) { - if (CTX::instance()->mesh.numSubEdges > 1) { + {0, 1, 2, 3}, {1, 2, 3, 0}, {2, 3, 0, 1}, {3, 0, 1, 2}}; + if(CTX::instance()->heavyVisu) { + if(CTX::instance()->mesh.numSubEdges > 1) { _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); return; } _getFaceRepQuad(getVertex(fquad[num][0]), getVertex(fquad[num][1]), - getVertex(fquad[num][2]), getVertex(fquad[num][3]), - x, y, z, n); + getVertex(fquad[num][2]), getVertex(fquad[num][3]), x, y, z, + n); return; } #endif - static const int f[2][3] = { - {0, 1, 2}, {0, 2, 3} - }; + static const int f[2][3] = {{0, 1, 2}, {0, 2, 3}}; _getFaceRep(_v[f[num][0]], _v[f[num][1]], _v[f[num][2]], x, y, z, n); } -void MQuadrangleN::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MQuadrangleN::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MQuadrangle::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MQuadrangle::getFaceRep(false, num, x, y, z, n); } -void MQuadrangle8::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MQuadrangle8::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MQuadrangle::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MQuadrangle::getFaceRep(false, num, x, y, z, n); } -void MQuadrangle9::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MQuadrangle9::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MQuadrangle::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MQuadrangle::getFaceRep(false, num, x, y, z, n); } void MQuadrangle::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) @@ -276,7 +297,7 @@ void MQuadrangle::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) *pts = getGQQPts(pOrder); } -double MQuadrangle::etaShapeMeasure() +double MQuadrangle::etaShapeMeasure() { #if defined(HAVE_MESH) return qmQuadrangle::eta(this); @@ -285,7 +306,8 @@ double MQuadrangle::etaShapeMeasure() #endif } -double MQuadrangle::gammaShapeMeasure(){ +double MQuadrangle::gammaShapeMeasure() +{ #if defined(HAVE_MESH) return qmQuadrangle::gamma(this); #else @@ -325,9 +347,9 @@ double MQuadrangle::getInnerRadius() double zm = (z[0] + z[1] + z[2] + z[3]) / 4; // using svd decomposition - fullMatrix<double> U(4,3), V(3,3); + fullMatrix<double> U(4, 3), V(3, 3); fullVector<double> sigma(3); - for (int i = 0; i < 4; i++) { + for(int i = 0; i < 4; i++) { U(i, 0) = x[i] - xm; U(i, 1) = y[i] - ym; U(i, 2) = z[i] - zm; @@ -351,16 +373,19 @@ double MQuadrangle::getInnerRadius() double d = -(xm * a + ym * b + zm * c); - double norm = sqrt(a*a+b*b+c*c); + double norm = sqrt(a * a + b * b + c * c); // projection of the 4 original points on the mean_plane double xp[4], yp[4], zp[4]; - for (int i = 0; i < 4; i++) { - xp[i] = ((b*b+c*c)*x[i]-a*b*y[i]-a*c*z[i]-d*a)/norm; - yp[i] = (-a*b*x[i]+(a*a+c*c)*y[i]-b*c*z[i]-d*b)/norm; - zp[i] = (-a*c*x[i]-b*c*y[i]+(a*a+b*b)*z[i]-d*c)/norm; + for(int i = 0; i < 4; i++) { + xp[i] = + ((b * b + c * c) * x[i] - a * b * y[i] - a * c * z[i] - d * a) / norm; + yp[i] = + (-a * b * x[i] + (a * a + c * c) * y[i] - b * c * z[i] - d * b) / norm; + zp[i] = + (-a * c * x[i] - b * c * y[i] + (a * a + b * b) * z[i] - d * c) / norm; } // go from XYZ-plane to XY-plane @@ -374,9 +399,9 @@ double MQuadrangle::getInnerRadius() // compute for each of the 4 possibilities the incircle radius, // keeping the minimum double R = 1.e22; - for (int j = 0; j < 4; j++){ + for(int j = 0; j < 4; j++) { r[j] = computeInnerRadiusForQuad(xn, yn, j); - if(r[j] < R){ + if(r[j] < R) { R = r[j]; } } @@ -387,11 +412,18 @@ double MQuadrangle::getInnerRadius() // but same value for a square // Mid-point of each edge of the quadrangle - SPoint3 A(_v[0]->x()+_v[1]->x(),_v[0]->y()+_v[1]->y(),_v[0]->z()+_v[1]->z()); - SPoint3 B(_v[1]->x()+_v[2]->x(),_v[1]->y()+_v[2]->y(),_v[1]->z()+_v[2]->z()); - SPoint3 C(_v[2]->x()+_v[3]->x(),_v[2]->y()+_v[3]->y(),_v[2]->z()+_v[3]->z()); - SPoint3 D(_v[3]->x()+_v[0]->x(),_v[3]->y()+_v[0]->y(),_v[3]->z()+_v[0]->z()); - A*=0.5; B*=0.5; C*=0.5; D*=0.5; + SPoint3 A(_v[0]->x() + _v[1]->x(), _v[0]->y() + _v[1]->y(), + _v[0]->z() + _v[1]->z()); + SPoint3 B(_v[1]->x() + _v[2]->x(), _v[1]->y() + _v[2]->y(), + _v[1]->z() + _v[2]->z()); + SPoint3 C(_v[2]->x() + _v[3]->x(), _v[2]->y() + _v[3]->y(), + _v[2]->z() + _v[3]->z()); + SPoint3 D(_v[3]->x() + _v[0]->x(), _v[3]->y() + _v[0]->y(), + _v[3]->z() + _v[0]->z()); + A *= 0.5; + B *= 0.5; + C *= 0.5; + D *= 0.5; // compute the length of the side double a = A.distance(B); @@ -400,28 +432,31 @@ double MQuadrangle::getInnerRadius() double d = D.distance(A); // perimeter - double s = a+b+c+d; - double halfs = 0.5*s; + double s = a + b + c + d; + double halfs = 0.5 * s; - return 0.25*sqrt( (a*c+b*d)*(a*d+b*c)*(a*b+c*d)/ - ((halfs-a)*(halfs-b)*(halfs-c)*(halfs-d)) - ); + return 0.25 * sqrt((a * c + b * d) * (a * d + b * c) * (a * b + c * d) / + ((halfs - a) * (halfs - b) * (halfs - c) * (halfs - d))); #endif // HAVE_LAPACK } void MQuadrangleN::reverse() { MVertex *tmp; - tmp = _v[1]; _v[1] = _v[3]; _v[3] = tmp; + tmp = _v[1]; + _v[1] = _v[3]; + _v[3] = tmp; - int npts = _order-1, base = 0; - std::vector<MVertex*>::iterator begin = _vs.begin() + base; + int npts = _order - 1, base = 0; + std::vector<MVertex *>::iterator begin = _vs.begin() + base; - while (npts > 0) { + while(npts > 0) { std::reverse(begin, begin + 4 * npts); base += 4 * npts; - if (npts > 1) { - tmp = _vs[base+1]; _vs[base+1] = _vs[base+3]; _vs[base+3] = tmp; + if(npts > 1) { + tmp = _vs[base + 1]; + _vs[base + 1] = _vs[base + 3]; + _vs[base + 3] = tmp; } npts -= 2; begin = _vs.begin() + base + 4; @@ -430,77 +465,92 @@ void MQuadrangleN::reverse() void MQuadrangle::reorient(int rot, bool swap) { - MVertex* tmp[4]; - if (swap) for (int i=0;i<4;i++) tmp[i] = _v[(4-i+rot)%4]; - else for (int i=0;i<4;i++) tmp[i] = _v[(4+i-rot)%4]; - std::memcpy(_v,tmp,4*sizeof(MVertex*)); + MVertex *tmp[4]; + if(swap) + for(int i = 0; i < 4; i++) tmp[i] = _v[(4 - i + rot) % 4]; + else + for(int i = 0; i < 4; i++) tmp[i] = _v[(4 + i - rot) % 4]; + std::memcpy(_v, tmp, 4 * sizeof(MVertex *)); } void MQuadrangle8::reorient(int rot, bool swap) { - if (rot == 0 && !swap) return; + if(rot == 0 && !swap) return; - MQuadrangle::reorient(rot,swap); - MVertex* tmp[4]; - if (swap) for (int i=0;i<4;i++) tmp[i] = _vs[(7-i+rot)%4]; - else for (int i=0;i<4;i++) tmp[i] = _vs[(4+i-rot)%4]; - std::memcpy(_vs,tmp,4*sizeof(MVertex*)); + MQuadrangle::reorient(rot, swap); + MVertex *tmp[4]; + if(swap) + for(int i = 0; i < 4; i++) tmp[i] = _vs[(7 - i + rot) % 4]; + else + for(int i = 0; i < 4; i++) tmp[i] = _vs[(4 + i - rot) % 4]; + std::memcpy(_vs, tmp, 4 * sizeof(MVertex *)); } void MQuadrangle9::reorient(int rot, bool swap) { - if (rot == 0 && !swap) return; + if(rot == 0 && !swap) return; - MQuadrangle::reorient(rot,swap); - MVertex* tmp[4]; - if (swap) for (int i=0;i<4;i++) tmp[i] = _vs[(7-i+rot)%4]; // edge swapped - else for (int i=0;i<4;i++) tmp[i] = _vs[(4+i-rot)%4]; - std::memcpy(_vs,tmp,4*sizeof(MVertex*)); + MQuadrangle::reorient(rot, swap); + MVertex *tmp[4]; + if(swap) + for(int i = 0; i < 4; i++) tmp[i] = _vs[(7 - i + rot) % 4]; // edge swapped + else + for(int i = 0; i < 4; i++) tmp[i] = _vs[(4 + i - rot) % 4]; + std::memcpy(_vs, tmp, 4 * sizeof(MVertex *)); } -std::map<TupleReorientation, IndicesReoriented> MQuadrangleN::_tuple2indicesReoriented; +std::map<TupleReorientation, IndicesReoriented> + MQuadrangleN::_tuple2indicesReoriented; -namespace -{ +namespace { void _getIndicesReorientedQuad(int order, int rot, bool swap, IndicesReoriented &indices) { fullMatrix<double> ref = gmshGenerateMonomialsQuadrangle(order); - ref.add(- order / 2.); + ref.add(-order / 2.); indices.resize(ref.size1()); - for (int i = 0; i < ref.size1(); ++i) { + for(int i = 0; i < ref.size1(); ++i) { double u = ref(i, 0); double v = ref(i, 1); double tmp = u; - if (swap) { + if(swap) { tmp = u; u = v; v = tmp; } - switch (rot) { - case 1: u = v; v = -tmp; break; - case 2: u = -u; v = -v; break; - case 3: u = -v; v = tmp; break; + switch(rot) { + case 1: + u = v; + v = -tmp; + break; + case 2: + u = -u; + v = -v; + break; + case 3: + u = -v; + v = tmp; + break; } - for (int j = 0; j < ref.size1(); ++j) { - if (u == ref(j, 0) && v == ref(j, 1)) { + for(int j = 0; j < ref.size1(); ++j) { + if(u == ref(j, 0) && v == ref(j, 1)) { indices[i] = j; break; } } } } -} +} // namespace void MQuadrangleN::reorient(int rot, bool swap) { - if (rot == 0 && !swap) return; + if(rot == 0 && !swap) return; TupleReorientation mytuple(getTypeForMSH(), std::make_pair(rot, swap)); std::map<TupleReorientation, IndicesReoriented>::iterator it; it = _tuple2indicesReoriented.find(mytuple); - if (it == _tuple2indicesReoriented.end()) { + if(it == _tuple2indicesReoriented.end()) { IndicesReoriented indices; _getIndicesReorientedQuad(_order, rot, swap, indices); _tuple2indicesReoriented[mytuple] = indices; @@ -510,26 +560,28 @@ void MQuadrangleN::reorient(int rot, bool swap) IndicesReoriented &indices = it->second; // copy vertices - std::vector<MVertex*> oldv(4 + _vs.size()); - std::copy(_v, _v+4, oldv.begin()); - std::copy(_vs.begin(), _vs.end(), oldv.begin()+4); + std::vector<MVertex *> oldv(4 + _vs.size()); + std::copy(_v, _v + 4, oldv.begin()); + std::copy(_vs.begin(), _vs.end(), oldv.begin() + 4); // reorient - for (int i = 0; i < 4; ++i) { + for(int i = 0; i < 4; ++i) { _v[i] = oldv[indices[i]]; } - for (unsigned int i = 0; i < _vs.size(); ++i) { - _vs[i] = oldv[indices[4+i]]; + for(unsigned int i = 0; i < _vs.size(); ++i) { + _vs[i] = oldv[indices[4 + i]]; } } MFaceN MQuadrangle::getHighOrderFace(int num, int sign, int rot) { const bool swap = sign == -1; - std::vector<MVertex*> vertices(getNumVertices()); + std::vector<MVertex *> vertices(getNumVertices()); - if (swap) for (int i=0;i<4;i++) vertices[i] = _v[(4-i+rot)%4]; - else for (int i=0;i<4;i++) vertices[i] = _v[(4+i-rot)%4]; + if(swap) + for(int i = 0; i < 4; i++) vertices[i] = _v[(4 - i + rot) % 4]; + else + for(int i = 0; i < 4; i++) vertices[i] = _v[(4 + i - rot) % 4]; return MFaceN(TYPE_QUA, 1, vertices); } @@ -537,18 +589,18 @@ MFaceN MQuadrangle::getHighOrderFace(int num, int sign, int rot) MFaceN MQuadrangle8::getHighOrderFace(int num, int sign, int rot) { const bool swap = sign == -1; - std::vector<MVertex*> vertices(getNumVertices()); + std::vector<MVertex *> vertices(getNumVertices()); - if (swap) { - for (int i=0;i<4;i++) { - vertices[i] = _v[(4-i+rot)%4]; - vertices[4+i] = _vs[(7-i+rot)%4]; + if(swap) { + for(int i = 0; i < 4; i++) { + vertices[i] = _v[(4 - i + rot) % 4]; + vertices[4 + i] = _vs[(7 - i + rot) % 4]; } } else { - for (int i=0;i<4;i++) { - vertices[i] = _v[(4+i-rot)%4]; - vertices[4+i] = _vs[(4+i-rot)%4]; + for(int i = 0; i < 4; i++) { + vertices[i] = _v[(4 + i - rot) % 4]; + vertices[4 + i] = _vs[(4 + i - rot) % 4]; } } return MFaceN(TYPE_QUA, 2, vertices); @@ -557,18 +609,18 @@ MFaceN MQuadrangle8::getHighOrderFace(int num, int sign, int rot) MFaceN MQuadrangle9::getHighOrderFace(int num, int sign, int rot) { const bool swap = sign == -1; - std::vector<MVertex*> vertices(getNumVertices()); + std::vector<MVertex *> vertices(getNumVertices()); - if (swap) { - for (int i=0;i<4;i++) { - vertices[i] = _v[(4-i+rot)%4]; - vertices[4+i] = _vs[(7-i+rot)%4]; + if(swap) { + for(int i = 0; i < 4; i++) { + vertices[i] = _v[(4 - i + rot) % 4]; + vertices[4 + i] = _vs[(7 - i + rot) % 4]; } } else { - for (int i=0;i<4;i++) { - vertices[i] = _v[(4+i-rot)%4]; - vertices[4+i] = _vs[(4+i-rot)%4]; + for(int i = 0; i < 4; i++) { + vertices[i] = _v[(4 + i - rot) % 4]; + vertices[4 + i] = _vs[(4 + i - rot) % 4]; } } vertices[8] = _vs[4]; @@ -581,7 +633,7 @@ MFaceN MQuadrangleN::getHighOrderFace(int num, int sign, int rot) TupleReorientation mytuple(TYPE_QUA, std::make_pair(rot, swap)); std::map<TupleReorientation, IndicesReoriented>::iterator it; it = _tuple2indicesReoriented.find(mytuple); - if (it == _tuple2indicesReoriented.end()) { + if(it == _tuple2indicesReoriented.end()) { IndicesReoriented indices; _getIndicesReorientedQuad(_order, rot, swap, indices); _tuple2indicesReoriented[mytuple] = indices; @@ -590,8 +642,8 @@ MFaceN MQuadrangleN::getHighOrderFace(int num, int sign, int rot) IndicesReoriented &indices = it->second; - std::vector<MVertex*> vertices(getNumVertices()); - for (std::size_t i = 0; i < getNumVertices(); ++i) { + std::vector<MVertex *> vertices(getNumVertices()); + for(std::size_t i = 0; i < getNumVertices(); ++i) { vertices[i] = getVertex(indices[i]); } return MFaceN(TYPE_QUA, _order, vertices); diff --git a/Geo/MQuadrangle.h b/Geo/MQuadrangle.h index 305265f4c86cb5061285ecb7390a8e3aeef072ec..6686f40b4f7e0affbdf66edce04e990e350a0dcb 100644 --- a/Geo/MQuadrangle.h +++ b/Geo/MQuadrangle.h @@ -24,14 +24,14 @@ * */ class MQuadrangle : public MElement { - protected: +protected: MVertex *_v[4]; - void _getEdgeVertices(const int num, std::vector<MVertex*> &v) const + void _getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[edges_quad(num, 0)]; v[1] = _v[edges_quad(num, 1)]; } - void _getFaceVertices(std::vector<MVertex*> &v) const + void _getFaceVertices(std::vector<MVertex *> &v) const { v[0] = _v[0]; v[1] = _v[1]; @@ -39,31 +39,36 @@ class MQuadrangle : public MElement { v[3] = _v[3]; } void projectInMeanPlane(double *xn, double *yn); - public : - MQuadrangle(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, int num=0, int part=0) + +public: + MQuadrangle(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, int num = 0, + int part = 0) : MElement(num, part) { - _v[0] = v0; _v[1] = v1; _v[2] = v2; _v[3] = v3; + _v[0] = v0; + _v[1] = v1; + _v[2] = v2; + _v[3] = v3; } - MQuadrangle(const std::vector<MVertex*> &v, int num=0, int part=0) + MQuadrangle(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { for(int i = 0; i < 4; i++) _v[i] = v[i]; } - ~MQuadrangle(){} + ~MQuadrangle() {} virtual double etaShapeMeasure(); virtual double gammaShapeMeasure(); virtual int getDim() const { return 2; } virtual std::size_t getNumVertices() const { return 4; } - virtual MVertex *getVertex(int num){ return _v[num]; } - virtual const MVertex *getVertex(int num) const{ return _v[num]; } - virtual void setVertex(int num, MVertex *v){ _v[num] = v; } + virtual MVertex *getVertex(int num) { return _v[num]; } + virtual const MVertex *getVertex(int num) const { return _v[num]; } + virtual void setVertex(int num, MVertex *v) { _v[num] = v; } virtual MVertex *getVertexDIFF(int num) { static const int map[4] = {0, 1, 3, 2}; return getVertex(map[num]); } - virtual int getNumEdges()const{ return 4; } + virtual int getNumEdges() const { return 4; } virtual MEdge getEdge(int num) const { return MEdge(_v[edges_quad(num, 0)], _v[edges_quad(num, 1)]); @@ -72,53 +77,76 @@ class MQuadrangle : public MElement { { return edges_quad(numEdge, numVert); } - virtual int getNumEdgesRep(bool curved){ return 4; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual int getNumEdgesRep(bool curved) { return 4; } + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); _getEdgeVertices(num, v); } - virtual int getNumFaces(){ return 1; } - virtual MFace getFace(int num) const { return MFace(_v[0], _v[1], _v[2], _v[3]); } + virtual int getNumFaces() { return 1; } + virtual MFace getFace(int num) const + { + return MFace(_v[0], _v[1], _v[2], _v[3]); + } virtual MFaceN getHighOrderFace(int num, int sign, int rot); - virtual bool getFaceInfo(const MFace & face, int &ithFace, int &sign, int &rot) const; + virtual bool getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const; virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(4); _getFaceVertices(v); } virtual int getType() const { return TYPE_QUA; } virtual int getTypeForMSH() const { return MSH_QUA_4; } - virtual int getTypeForUNV() const { return 94; } // thin shell linear quadrilateral + virtual int getTypeForUNV() const + { + return 94; + } // thin shell linear quadrilateral virtual int getTypeForVTK() const { return 9; } virtual const char *getStringForPOS() const { return "SQ"; } virtual const char *getStringForBDF() const { return "CQUAD4"; } virtual const char *getStringForDIFF() const { return "ElmB4n2D"; } - virtual const char *getStringForINP() const { return "CPS4"/*"C2D4"*/; } + virtual const char *getStringForINP() const { return "CPS4" /*"C2D4"*/; } virtual const char *getStringForKEY() const { return "_SHELL"; } virtual const char *getStringForTOCHNOG() const { return "-quad4"; } virtual void getNode(int num, double &u, double &v, double &w) const { w = 0.; switch(num) { - case 0 : u = -1.; v = -1.; break; - case 1 : u = 1.; v = -1.; break; - case 2 : u = 1.; v = 1.; break; - case 3 : u = -1.; v = 1.; break; - default: u = 0.; v = 0.; break; + case 0: + u = -1.; + v = -1.; + break; + case 1: + u = 1.; + v = -1.; + break; + case 2: + u = 1.; + v = 1.; + break; + case 3: + u = -1.; + v = 1.; + break; + default: + u = 0.; + v = 0.; + break; } } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0., 0., 0.); - } + virtual SPoint3 barycenterUVW() const { return SPoint3(0., 0., 0.); } virtual double getVolume(); virtual void reverse() { - MVertex *tmp = _v[1]; _v[1] = _v[3]; _v[3] = tmp; + MVertex *tmp = _v[1]; + _v[1] = _v[3]; + _v[3] = tmp; } // reorient the quadrangle to conform with other face // orientation computed with MFace based on this face with respect to other @@ -143,12 +171,7 @@ class MQuadrangle : public MElement { virtual double getOuterRadius(); static int edges_quad(const int edge, const int vert) { - static const int e[4][2] = { - {0, 1}, - {1, 2}, - {2, 3}, - {3, 0} - }; + static const int e[4][2] = {{0, 1}, {1, 2}, {2, 3}, {3, 0}}; return e[edge][vert]; } virtual int numCommonNodesInDualGraph(const MElement *const other) const; @@ -167,28 +190,44 @@ class MQuadrangle : public MElement { * */ class MQuadrangle8 : public MQuadrangle { - protected: +protected: MVertex *_vs[4]; - public : + +public: MQuadrangle8(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, - MVertex *v5, MVertex *v6, MVertex *v7, int num=0, int part=0) + MVertex *v5, MVertex *v6, MVertex *v7, int num = 0, int part = 0) : MQuadrangle(v0, v1, v2, v3, num, part) { - _vs[0] = v4; _vs[1] = v5; _vs[2] = v6; _vs[3] = v7; + _vs[0] = v4; + _vs[1] = v5; + _vs[2] = v6; + _vs[3] = v7; for(int i = 0; i < 4; i++) _vs[i]->setPolynomialOrder(2); } - MQuadrangle8(const std::vector<MVertex*> &v, int num=0, int part=0) + MQuadrangle8(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MQuadrangle(v, num, part) { for(int i = 0; i < 4; i++) _vs[i] = v[4 + i]; for(int i = 0; i < 4; i++) _vs[i]->setPolynomialOrder(2); } - ~MQuadrangle8(){} + ~MQuadrangle8() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 8; } - virtual MVertex *getVertex(int num){ return num < 4 ? _v[num] : _vs[num - 4]; } - virtual const MVertex *getVertex(int num) const { return num < 4 ? _v[num] : _vs[num - 4]; } - virtual void setVertex(int num, MVertex *v){ if(num < 4) _v[num] = v; else _vs[num - 4] = v; } + virtual MVertex *getVertex(int num) + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 4) + _v[num] = v; + else + _vs[num - 4] = v; + } virtual MVertex *getVertexUNV(int num) { static const int map[8] = {0, 4, 1, 5, 2, 6, 3, 7}; @@ -201,8 +240,9 @@ class MQuadrangle8 : public MQuadrangle { } virtual int getNumEdgeVertices() const { return 4; } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MQuadrangle::_getEdgeVertices(num, v); @@ -210,8 +250,9 @@ class MQuadrangle8 : public MQuadrangle { } virtual MFaceN getHighOrderFace(int num, int sign, int rot); virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(8); MQuadrangle::_getFaceVertices(v); @@ -221,18 +262,27 @@ class MQuadrangle8 : public MQuadrangle { v[7] = _vs[3]; } virtual int getTypeForMSH() const { return MSH_QUA_8; } - virtual int getTypeForUNV() const { return 95; } // shell parabolic quadrilateral + virtual int getTypeForUNV() const + { + return 95; + } // shell parabolic quadrilateral virtual int getTypeForVTK() const { return 23; } virtual const char *getStringForBDF() const { return "CQUAD8"; } virtual const char *getStringForDIFF() const { return "ElmB8n2D"; } - virtual const char *getStringForINP() const { return "CPS8"/*"C2D8"*/; } + virtual const char *getStringForINP() const { return "CPS8" /*"C2D8"*/; } virtual const char *getStringForKEY() const { return "_SHELL"; } virtual void reverse() { MVertex *tmp; - tmp = _v[1]; _v[1] = _v[3]; _v[3] = tmp; - tmp = _vs[0]; _vs[0] = _vs[3]; _vs[3] = tmp; - tmp = _vs[1]; _vs[1] = _vs[2]; _vs[2] = tmp; + tmp = _v[1]; + _v[1] = _v[3]; + _v[3] = tmp; + tmp = _vs[0]; + _vs[0] = _vs[3]; + _vs[3] = tmp; + tmp = _vs[1]; + _vs[1] = _vs[2]; + _vs[2] = tmp; } // reorient the quadrangle to conform with other face @@ -242,12 +292,10 @@ class MQuadrangle8 : public MQuadrangle { virtual void getNode(int num, double &u, double &v, double &w) const { - num < 4 ? MQuadrangle::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); - } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0., 0., 0.); + num < 4 ? MQuadrangle::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } + virtual SPoint3 barycenterUVW() const { return SPoint3(0., 0., 0.); } }; /* @@ -263,28 +311,46 @@ class MQuadrangle8 : public MQuadrangle { * */ class MQuadrangle9 : public MQuadrangle { - protected: +protected: MVertex *_vs[5]; - public : + +public: MQuadrangle9(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, - MVertex *v5, MVertex *v6, MVertex *v7, MVertex *v8, int num=0, int part=0) + MVertex *v5, MVertex *v6, MVertex *v7, MVertex *v8, int num = 0, + int part = 0) : MQuadrangle(v0, v1, v2, v3, num, part) { - _vs[0] = v4; _vs[1] = v5; _vs[2] = v6; _vs[3] = v7; _vs[4] = v8; + _vs[0] = v4; + _vs[1] = v5; + _vs[2] = v6; + _vs[3] = v7; + _vs[4] = v8; for(int i = 0; i < 5; i++) _vs[i]->setPolynomialOrder(2); } - MQuadrangle9(const std::vector<MVertex*> &v, int num=0, int part=0) + MQuadrangle9(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MQuadrangle(v, num, part) { for(int i = 0; i < 5; i++) _vs[i] = v[4 + i]; for(int i = 0; i < 5; i++) _vs[i]->setPolynomialOrder(2); } - ~MQuadrangle9(){} + ~MQuadrangle9() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 9; } - virtual MVertex *getVertex(int num){ return num < 4 ? _v[num] : _vs[num - 4]; } - virtual const MVertex *getVertex(int num) const { return num < 4 ? _v[num] : _vs[num - 4]; } - virtual void setVertex(int num, MVertex *v){ if(num < 4) _v[num] = v; else _vs[num - 4] = v; } + virtual MVertex *getVertex(int num) + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 4) + _v[num] = v; + else + _vs[num - 4] = v; + } virtual MVertex *getVertexDIFF(int num) { static const int map[9] = {0, 2, 8, 6, 1, 5, 7, 3, 4}; @@ -293,8 +359,9 @@ class MQuadrangle9 : public MQuadrangle { virtual int getNumEdgeVertices() const { return 4; } virtual int getNumFaceVertices() const { return 1; } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MQuadrangle::_getEdgeVertices(num, v); @@ -302,8 +369,9 @@ class MQuadrangle9 : public MQuadrangle { } virtual MFaceN getHighOrderFace(int num, int sign, int rot); virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(9); MQuadrangle::_getFaceVertices(v); @@ -322,9 +390,15 @@ class MQuadrangle9 : public MQuadrangle { virtual void reverse() { MVertex *tmp; - tmp = _v[1]; _v[1] = _v[3]; _v[3] = tmp; - tmp = _vs[0]; _vs[0] = _vs[3]; _vs[3] = tmp; - tmp = _vs[1]; _vs[1] = _vs[2]; _vs[2] = tmp; + tmp = _v[1]; + _v[1] = _v[3]; + _v[3] = tmp; + tmp = _vs[0]; + _vs[0] = _vs[3]; + _vs[3] = tmp; + tmp = _vs[1]; + _vs[1] = _vs[2]; + _vs[2] = tmp; } // reorient the quadrangle to conform with other face @@ -334,16 +408,14 @@ class MQuadrangle9 : public MQuadrangle { virtual void getNode(int num, double &u, double &v, double &w) const { - num < 4 ? MQuadrangle::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); - } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0., 0., 0.); + num < 4 ? MQuadrangle::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } + virtual SPoint3 barycenterUVW() const { return SPoint3(0., 0., 0.); } }; typedef std::vector<int> IndicesReoriented; -typedef std::pair<int, std::pair<int,int> > TupleReorientation; +typedef std::pair<int, std::pair<int, int> > TupleReorientation; /* * MQuadrangle @@ -362,51 +434,65 @@ typedef std::pair<int, std::pair<int,int> > TupleReorientation; * */ class MQuadrangleN : public MQuadrangle { - static std::map<TupleReorientation, IndicesReoriented> _tuple2indicesReoriented; - protected: + static std::map<TupleReorientation, IndicesReoriented> + _tuple2indicesReoriented; + +protected: std::vector<MVertex *> _vs; const char _order; - public: + +public: MQuadrangleN(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, - const std::vector<MVertex*> &v, char order, int num=0, int part=0) + const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) : MQuadrangle(v0, v1, v2, v3, num, part), _vs(v), _order(order) { - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); } - MQuadrangleN(const std::vector<MVertex*> &v, char order, int num=0, int part=0) + MQuadrangleN(const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) : MQuadrangle(v[0], v[1], v[2], v[3], num, part), _order(order) { for(unsigned int i = 4; i < v.size(); i++) _vs.push_back(v[i]); - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); } - ~MQuadrangleN(){} + ~MQuadrangleN() {} virtual int getPolynomialOrder() const { return _order; } - virtual std::size_t getNumVertices() const {return 4 + _vs.size(); } - virtual MVertex *getVertex(int num){ return num < 4 ? _v[num] : _vs[num - 4]; } - virtual const MVertex *getVertex(int num) const{ return num < 4 ? _v[num] : _vs[num - 4]; } + virtual std::size_t getNumVertices() const { return 4 + _vs.size(); } + virtual MVertex *getVertex(int num) + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 4 ? _v[num] : _vs[num - 4]; + } virtual int getNumFaceVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; else - return (_order - 1) * (_order - 1); + return (_order - 1) * (_order - 1); } virtual int getNumEdgeVertices() const { return 4 * (_order - 1); } virtual int getNumEdgesRep(bool curved); virtual int getNumFacesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(_order + 1); MQuadrangle::_getEdgeVertices(num, v); int j = 2; const int ie = (num + 1) * (_order - 1); - for(int i = num * (_order-1); i != ie; ++i) - v[j++] = _vs[i]; + for(int i = num * (_order - 1); i != ie; ++i) v[j++] = _vs[i]; } virtual MFaceN getHighOrderFace(int num, int sign, int rot); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(4 + _vs.size()); MQuadrangle::_getFaceVertices(v); @@ -418,33 +504,34 @@ class MQuadrangleN : public MQuadrangle { } virtual int getTypeForMSH() const { - if(_order== 1 && _vs.size() + 4 == 4) return MSH_QUA_4; - if(_order== 2 && _vs.size() + 4 == 9) return MSH_QUA_9; - if(_order== 3 && _vs.size() + 4 == 16) return MSH_QUA_16; - if(_order== 4 && _vs.size() + 4 == 25) return MSH_QUA_25; - if(_order== 5 && _vs.size() + 4 == 36) return MSH_QUA_36; - if(_order== 6 && _vs.size() + 4 == 49) return MSH_QUA_49; - if(_order== 7 && _vs.size() + 4 == 64) return MSH_QUA_64; - if(_order== 8 && _vs.size() + 4 == 81) return MSH_QUA_81; - if(_order== 9 && _vs.size() + 4 == 100) return MSH_QUA_100; - if(_order==10 && _vs.size() + 4 == 121) return MSH_QUA_121; + if(_order == 1 && _vs.size() + 4 == 4) return MSH_QUA_4; + if(_order == 2 && _vs.size() + 4 == 9) return MSH_QUA_9; + if(_order == 3 && _vs.size() + 4 == 16) return MSH_QUA_16; + if(_order == 4 && _vs.size() + 4 == 25) return MSH_QUA_25; + if(_order == 5 && _vs.size() + 4 == 36) return MSH_QUA_36; + if(_order == 6 && _vs.size() + 4 == 49) return MSH_QUA_49; + if(_order == 7 && _vs.size() + 4 == 64) return MSH_QUA_64; + if(_order == 8 && _vs.size() + 4 == 81) return MSH_QUA_81; + if(_order == 9 && _vs.size() + 4 == 100) return MSH_QUA_100; + if(_order == 10 && _vs.size() + 4 == 121) return MSH_QUA_121; - if(_order== 2 && _vs.size() + 4 == 8) return MSH_QUA_8; - if(_order== 3 && _vs.size() + 4 == 12) return MSH_QUA_12; - if(_order== 4 && _vs.size() + 4 == 16) return MSH_QUA_16I; - if(_order== 5 && _vs.size() + 4 == 20) return MSH_QUA_20; - if(_order== 6 && _vs.size() + 4 == 24) return MSH_QUA_24; - if(_order== 7 && _vs.size() + 4 == 28) return MSH_QUA_28; - if(_order== 8 && _vs.size() + 4 == 32) return MSH_QUA_32; - if(_order== 9 && _vs.size() + 4 == 36) return MSH_QUA_36I; - if(_order==10 && _vs.size() + 4 == 40) return MSH_QUA_40; - Msg::Error("no tag matches a p%d quadrangle with %d vertices", _order, 4+_vs.size()); + if(_order == 2 && _vs.size() + 4 == 8) return MSH_QUA_8; + if(_order == 3 && _vs.size() + 4 == 12) return MSH_QUA_12; + if(_order == 4 && _vs.size() + 4 == 16) return MSH_QUA_16I; + if(_order == 5 && _vs.size() + 4 == 20) return MSH_QUA_20; + if(_order == 6 && _vs.size() + 4 == 24) return MSH_QUA_24; + if(_order == 7 && _vs.size() + 4 == 28) return MSH_QUA_28; + if(_order == 8 && _vs.size() + 4 == 32) return MSH_QUA_32; + if(_order == 9 && _vs.size() + 4 == 36) return MSH_QUA_36I; + if(_order == 10 && _vs.size() + 4 == 40) return MSH_QUA_40; + Msg::Error("no tag matches a p%d quadrangle with %d vertices", _order, + 4 + _vs.size()); return 0; } virtual int getTypeForVTK() const { - if(_order== 2 && _vs.size() + 4 == 9) return 28; - if(_order== 2 && _vs.size() + 4 == 8) return 23; + if(_order == 2 && _vs.size() + 4 == 9) return 28; + if(_order == 2 && _vs.size() + 4 == 8) return 23; return MQuadrangle::getTypeForVTK(); } virtual void reverse(); @@ -456,42 +543,37 @@ class MQuadrangleN : public MQuadrangle { virtual void getNode(int num, double &u, double &v, double &w) const { - num < 4 ? MQuadrangle::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); - } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0., 0., 0.); + num < 4 ? MQuadrangle::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } + virtual SPoint3 barycenterUVW() const { return SPoint3(0., 0., 0.); } }; -template <class T> -void inline sort2(T &a, T &b) +template <class T> void inline sort2(T &a, T &b) { - if(b < a){ + if(b < a) { T t = b; b = a; a = t; } } -template <class T> -void sort4(T *t[4]) +template <class T> void sort4(T *t[4]) { - sort2<T*>(t[0], t[1]); - sort2<T*>(t[2], t[3]); - sort2<T*>(t[0], t[2]); - sort2<T*>(t[1], t[3]); - sort2<T*>(t[1], t[2]); + sort2<T *>(t[0], t[1]); + sort2<T *>(t[2], t[3]); + sort2<T *>(t[0], t[2]); + sort2<T *>(t[1], t[3]); + sort2<T *>(t[1], t[2]); } -struct compareMQuadrangleLexicographic -{ - bool operator () (MQuadrangle *t1, MQuadrangle *t2) const +struct compareMQuadrangleLexicographic { + bool operator()(MQuadrangle *t1, MQuadrangle *t2) const { - MVertex *_v1[] = {t1->getVertex(0), t1->getVertex(1), - t1->getVertex(2), t1->getVertex(3)}; - MVertex *_v2[] = {t2->getVertex(0), t2->getVertex(1), - t2->getVertex(2), t2->getVertex(3)}; + MVertex *_v1[] = {t1->getVertex(0), t1->getVertex(1), t1->getVertex(2), + t1->getVertex(3)}; + MVertex *_v2[] = {t2->getVertex(0), t2->getVertex(1), t2->getVertex(2), + t2->getVertex(3)}; sort4(_v1); sort4(_v2); if(_v1[0] < _v2[0]) return true; diff --git a/Geo/MSubElement.cpp b/Geo/MSubElement.cpp index e5d87b061bc19b4d6dc99b9a5f7a12d736a89b81..9a13fbef3dbbbd8da16cdcabae269ab1d77ca4f4 100644 --- a/Geo/MSubElement.cpp +++ b/Geo/MSubElement.cpp @@ -14,63 +14,74 @@ MSubTetrahedron::~MSubTetrahedron() { - if(_pts) delete [] _pts; + if(_pts) delete[] _pts; if(_base) delete _base; } void MSubTetrahedron::updateParent(GModel *gm) { - _orig=gm->getMeshElementByTag(_orig_N); + _orig = gm->getMeshElementByTag(_orig_N); } -const nodalBasis* MSubTetrahedron::getFunctionSpace(int order, bool serendip) const +const nodalBasis *MSubTetrahedron::getFunctionSpace(int order, + bool serendip) const { if(_orig) return _orig->getFunctionSpace(order, serendip); return 0; } -const JacobianBasis* MSubTetrahedron::getJacobianFuncSpace(int order) const +const JacobianBasis *MSubTetrahedron::getJacobianFuncSpace(int order) const { if(_orig) return _orig->getJacobianFuncSpace(order); return 0; } -void MSubTetrahedron::getShapeFunctions(double u, double v, double w, double s[], int order) const +void MSubTetrahedron::getShapeFunctions(double u, double v, double w, + double s[], int order) const { if(_orig) _orig->getShapeFunctions(u, v, w, s, order); } -void MSubTetrahedron::getGradShapeFunctions(double u, double v, double w, double s[][3], int order) const +void MSubTetrahedron::getGradShapeFunctions(double u, double v, double w, + double s[][3], int order) const { if(_orig) _orig->getGradShapeFunctions(u, v, w, s, order); } -void MSubTetrahedron::getHessShapeFunctions(double u, double v, double w, double s[][3][3], int order) const +void MSubTetrahedron::getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int order) const { if(_orig) _orig->getHessShapeFunctions(u, v, w, s, order); } -void MSubTetrahedron::getThirdDerivativeShapeFunctions(double u, double v, double w, double s[][3][3][3], int order) const +void MSubTetrahedron::getThirdDerivativeShapeFunctions(double u, double v, + double w, + double s[][3][3][3], + int order) const { if(_orig) _orig->getThirdDerivativeShapeFunctions(u, v, w, s, order); } -double MSubTetrahedron::getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const +double MSubTetrahedron::getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(gsf, jac); return 0; } -double MSubTetrahedron::getJacobian(const std::vector<SVector3> &gsf, double jac[3][3]) const +double MSubTetrahedron::getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(gsf, jac); return 0; } -double MSubTetrahedron::getJacobian(double u, double v, double w, double jac[3][3]) const +double MSubTetrahedron::getJacobian(double u, double v, double w, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(u, v, w, jac); return 0; } -double MSubTetrahedron::getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const +double MSubTetrahedron::getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const { if(_orig) return _orig->getPrimaryJacobian(u, v, w, jac); return 0; @@ -88,13 +99,13 @@ int MSubTetrahedron::getNumPrimaryShapeFunctions() const return 0; } -const MVertex* MSubTetrahedron::getShapeFunctionNode(int i) const +const MVertex *MSubTetrahedron::getShapeFunctionNode(int i) const { if(_orig) return _orig->getShapeFunctionNode(i); return 0; } -MVertex* MSubTetrahedron::getShapeFunctionNode(int i) +MVertex *MSubTetrahedron::getShapeFunctionNode(int i) { if(_orig) return _orig->getShapeFunctionNode(i); return 0; @@ -102,10 +113,12 @@ MVertex* MSubTetrahedron::getShapeFunctionNode(int i) void MSubTetrahedron::xyz2uvw(double xyz[3], double uvw[3]) const { - if(_orig) _orig->xyz2uvw(xyz,uvw); + if(_orig) _orig->xyz2uvw(xyz, uvw); } -void MSubTetrahedron::movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const +void MSubTetrahedron::movePointFromParentSpaceToElementSpace(double &u, + double &v, + double &w) const { if(!_orig) return; SPoint3 p; @@ -113,10 +126,14 @@ void MSubTetrahedron::movePointFromParentSpaceToElementSpace(double &u, double & double xyz[3] = {p.x(), p.y(), p.z()}; double uvwE[3]; getBaseElement()->xyz2uvw(xyz, uvwE); - u = uvwE[0]; v = uvwE[1]; w = uvwE[2]; + u = uvwE[0]; + v = uvwE[1]; + w = uvwE[2]; } -void MSubTetrahedron::movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const +void MSubTetrahedron::movePointFromElementSpaceToParentSpace(double &u, + double &v, + double &w) const { if(!_orig) return; SPoint3 p; @@ -124,15 +141,16 @@ void MSubTetrahedron::movePointFromElementSpaceToParentSpace(double &u, double & double xyz[3] = {p.x(), p.y(), p.z()}; double uvwP[3]; _orig->xyz2uvw(xyz, uvwP); - u = uvwP[0]; v = uvwP[1]; w = uvwP[2]; + u = uvwP[0]; + v = uvwP[1]; + w = uvwP[2]; } bool MSubTetrahedron::isInside(double u, double v, double w) const { if(!_orig) return false; - if (_orig->getDim()!=getDim()) - {// projection on the base Element + if(_orig->getDim() != getDim()) { // projection on the base Element SPoint3 p; _orig->pnt(u, v, w, p); double xyz[3] = {p.x(), p.y(), p.z()}; @@ -141,35 +159,31 @@ bool MSubTetrahedron::isInside(double u, double v, double w) const SPoint3 pE; getBaseElement()->pnt(uvwE[0], uvwE[1], uvwE[2], pE); double tol = _isInsideTolerance; - if (fabs(p.x()-pE.x())>tol) return false; - if (fabs(p.y()-pE.y())>tol) return false; - if (fabs(p.z()-pE.z())>tol) return false; + if(fabs(p.x() - pE.x()) > tol) return false; + if(fabs(p.y() - pE.y()) > tol) return false; + if(fabs(p.z() - pE.z()) > tol) return false; } movePointFromParentSpaceToElementSpace(u, v, w); - if(getBaseElement()->isInside(u, v, w)) - return true; + if(getBaseElement()->isInside(u, v, w)) return true; return false; } void MSubTetrahedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { - if(_pts) - { - if(pOrder==_pOrder) - { + if(_pts) { + if(pOrder == _pOrder) { *npts = _npts; *pts = _pts; return; } else - delete [] _pts; + delete[] _pts; } _pOrder = pOrder; - if(!_orig) - { + if(!_orig) { getBaseElement()->getIntegrationPoints(pOrder, &_npts, &_pts); *npts = _npts; *pts = _pts; @@ -183,12 +197,12 @@ void MSubTetrahedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) IntPt *ptsb; getBaseElement()->getIntegrationPoints(pOrder, &_npts, &ptsb); - // (ii) get the coordinates of these points in the parametric space of parent element - double u,v,w; + // (ii) get the coordinates of these points in the parametric space of parent + // element + double u, v, w; double jac[3][3]; double baseJac, origJac; - for(int i=0; i<_npts; ++i) - { + for(int i = 0; i < _npts; ++i) { u = ptsb[i].pt[0]; v = ptsb[i].pt[1]; w = ptsb[i].pt[2]; @@ -200,50 +214,49 @@ void MSubTetrahedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) _pts[i].pt[0] = u; _pts[i].pt[1] = v; _pts[i].pt[2] = w; - _pts[i].weight = ptsb[i].weight * baseJac/origJac; + _pts[i].weight = ptsb[i].weight * baseJac / origJac; } *npts = _npts; *pts = _pts; } - // MSubTriangle MSubTriangle::~MSubTriangle() { - if(_pts) delete [] _pts; + if(_pts) delete[] _pts; if(_base) delete _base; } void MSubTriangle::updateParent(GModel *gm) { - _orig=gm->getMeshElementByTag(_orig_N); + _orig = gm->getMeshElementByTag(_orig_N); } - -const nodalBasis* MSubTriangle::getFunctionSpace(int order, bool serendip) const +const nodalBasis *MSubTriangle::getFunctionSpace(int order, bool serendip) const { if(_orig) return _orig->getFunctionSpace(order, serendip); return 0; } -const JacobianBasis* MSubTriangle::getJacobianFuncSpace(int order) const +const JacobianBasis *MSubTriangle::getJacobianFuncSpace(int order) const { if(_orig) return _orig->getJacobianFuncSpace(order); return 0; } -void MSubTriangle::getShapeFunctions(double u, double v, double w, double s[], int order) const +void MSubTriangle::getShapeFunctions(double u, double v, double w, double s[], + int order) const { if(_orig) _orig->getShapeFunctions(u, v, w, s, order); } -void MSubTriangle::getGradShapeFunctions(double u, double v, double w, double s[][3], int order) const +void MSubTriangle::getGradShapeFunctions(double u, double v, double w, + double s[][3], int order) const { - if(!_orig) - return; + if(!_orig) return; - if (_orig->getDim()==getDim()) + if(_orig->getDim() == getDim()) return _orig->getGradShapeFunctions(u, v, w, s, order); int nsf = getNumShapeFunctions(); @@ -262,60 +275,74 @@ void MSubTriangle::getGradShapeFunctions(double u, double v, double w, double s[ SVector3 tang[2]; tang[0] = edge[0].tangent(); tang[1] = edge[1].tangent(); - SVector3 vect = crossprod(tang[0],tang[1]); - tang[1] = crossprod(vect,tang[0]); + SVector3 vect = crossprod(tang[0], tang[1]); + tang[1] = crossprod(vect, tang[0]); double gradxyz[3]; double projgradxyz[3]; - for (int i=0; i<nsf; ++i) - { - // (i) get the cartesian coordinates of the gradient - gradxyz[0] = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; - gradxyz[1] = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + invjac[1][2] * gradsuvw[i][2]; - gradxyz[2] = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * gradsuvw[i][2]; + for(int i = 0; i < nsf; ++i) { + // (i) get the cartesian coordinates of the gradient + gradxyz[0] = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + + invjac[0][2] * gradsuvw[i][2]; + gradxyz[1] = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + + invjac[1][2] * gradsuvw[i][2]; + gradxyz[2] = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + + invjac[2][2] * gradsuvw[i][2]; // (ii) projection of the gradient on edges in the cartesian space SVector3 grad(&gradxyz[0]); double prodscal[2]; - prodscal[0] = dot(tang[0],grad); - prodscal[1] = dot(tang[1],grad); - projgradxyz[0] = prodscal[0]*tang[0].x() + prodscal[1]*tang[1].x(); - projgradxyz[1] = prodscal[0]*tang[0].y() + prodscal[1]*tang[1].y(); - projgradxyz[2] = prodscal[0]*tang[0].z() + prodscal[1]*tang[1].z(); - - // (iii) get the parametric coordinates of the projection in the parametric space of the parent element - s[i][0] = jac[0][0] * projgradxyz[0] + jac[0][1] * projgradxyz[1] + jac[0][2] * projgradxyz[2]; - s[i][1] = jac[1][0] * projgradxyz[0] + jac[1][1] * projgradxyz[1] + jac[1][2] * projgradxyz[2]; - s[i][2] = jac[2][0] * projgradxyz[0] + jac[2][1] * projgradxyz[1] + jac[2][2] * projgradxyz[2]; + prodscal[0] = dot(tang[0], grad); + prodscal[1] = dot(tang[1], grad); + projgradxyz[0] = prodscal[0] * tang[0].x() + prodscal[1] * tang[1].x(); + projgradxyz[1] = prodscal[0] * tang[0].y() + prodscal[1] * tang[1].y(); + projgradxyz[2] = prodscal[0] * tang[0].z() + prodscal[1] * tang[1].z(); + + // (iii) get the parametric coordinates of the projection in the parametric + // space of the parent element + s[i][0] = jac[0][0] * projgradxyz[0] + jac[0][1] * projgradxyz[1] + + jac[0][2] * projgradxyz[2]; + s[i][1] = jac[1][0] * projgradxyz[0] + jac[1][1] * projgradxyz[1] + + jac[1][2] * projgradxyz[2]; + s[i][2] = jac[2][0] * projgradxyz[0] + jac[2][1] * projgradxyz[1] + + jac[2][2] * projgradxyz[2]; } } -void MSubTriangle::getHessShapeFunctions(double u, double v, double w, double s[][3][3], int order) const +void MSubTriangle::getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int order) const { if(_orig) _orig->getHessShapeFunctions(u, v, w, s, order); } -void MSubTriangle::getThirdDerivativeShapeFunctions(double u, double v, double w, double s[][3][3][3], int order) const +void MSubTriangle::getThirdDerivativeShapeFunctions(double u, double v, + double w, + double s[][3][3][3], + int order) const { if(_orig) _orig->getThirdDerivativeShapeFunctions(u, v, w, s, order); } -double MSubTriangle::getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const +double MSubTriangle::getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(gsf, jac); return 0; } -double MSubTriangle::getJacobian(const std::vector<SVector3> &gsf, double jac[3][3]) const +double MSubTriangle::getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(gsf, jac); return 0; } -double MSubTriangle::getJacobian(double u, double v, double w, double jac[3][3]) const +double MSubTriangle::getJacobian(double u, double v, double w, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(u, v, w, jac); return 0; } -double MSubTriangle::getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const +double MSubTriangle::getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const { if(_orig) return _orig->getPrimaryJacobian(u, v, w, jac); return 0; @@ -333,13 +360,13 @@ int MSubTriangle::getNumPrimaryShapeFunctions() const return 0; } -const MVertex* MSubTriangle::getShapeFunctionNode(int i) const +const MVertex *MSubTriangle::getShapeFunctionNode(int i) const { if(_orig) return _orig->getShapeFunctionNode(i); return 0; } -MVertex* MSubTriangle::getShapeFunctionNode(int i) +MVertex *MSubTriangle::getShapeFunctionNode(int i) { if(_orig) return _orig->getShapeFunctionNode(i); return 0; @@ -347,10 +374,11 @@ MVertex* MSubTriangle::getShapeFunctionNode(int i) void MSubTriangle::xyz2uvw(double xyz[3], double uvw[3]) const { - if(_orig) _orig->xyz2uvw(xyz,uvw); + if(_orig) _orig->xyz2uvw(xyz, uvw); } -void MSubTriangle::movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const +void MSubTriangle::movePointFromParentSpaceToElementSpace(double &u, double &v, + double &w) const { if(!_orig) return; SPoint3 p; @@ -358,10 +386,13 @@ void MSubTriangle::movePointFromParentSpaceToElementSpace(double &u, double &v, double xyz[3] = {p.x(), p.y(), p.z()}; double uvwE[3]; getBaseElement()->xyz2uvw(xyz, uvwE); - u = uvwE[0]; v = uvwE[1]; w = uvwE[2]; + u = uvwE[0]; + v = uvwE[1]; + w = uvwE[2]; } -void MSubTriangle::movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const +void MSubTriangle::movePointFromElementSpaceToParentSpace(double &u, double &v, + double &w) const { if(!_orig) return; SPoint3 p; @@ -369,15 +400,16 @@ void MSubTriangle::movePointFromElementSpaceToParentSpace(double &u, double &v, double xyz[3] = {p.x(), p.y(), p.z()}; double uvwP[3]; _orig->xyz2uvw(xyz, uvwP); - u = uvwP[0]; v = uvwP[1]; w = uvwP[2]; + u = uvwP[0]; + v = uvwP[1]; + w = uvwP[2]; } bool MSubTriangle::isInside(double u, double v, double w) const { if(!_orig) return false; - if (_orig->getDim()!=getDim()) - {// projection on the base Element + if(_orig->getDim() != getDim()) { // projection on the base Element SPoint3 p; _orig->pnt(u, v, w, p); double xyz[3] = {p.x(), p.y(), p.z()}; @@ -386,35 +418,31 @@ bool MSubTriangle::isInside(double u, double v, double w) const SPoint3 pE; getBaseElement()->pnt(uvwE[0], uvwE[1], uvwE[2], pE); double tol = _isInsideTolerance; - if (fabs(p.x()-pE.x())>tol) return false; - if (fabs(p.y()-pE.y())>tol) return false; - if (fabs(p.z()-pE.z())>tol) return false; + if(fabs(p.x() - pE.x()) > tol) return false; + if(fabs(p.y() - pE.y()) > tol) return false; + if(fabs(p.z() - pE.z()) > tol) return false; } movePointFromParentSpaceToElementSpace(u, v, w); - if(getBaseElement()->isInside(u, v, w)) - return true; + if(getBaseElement()->isInside(u, v, w)) return true; return false; } void MSubTriangle::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { - if(_pts) - { - if(pOrder==_pOrder) - { + if(_pts) { + if(pOrder == _pOrder) { *npts = _npts; *pts = _pts; return; } else - delete [] _pts; + delete[] _pts; } _pOrder = pOrder; - if(!_orig) - { + if(!_orig) { getBaseElement()->getIntegrationPoints(pOrder, &_npts, &_pts); *npts = _npts; *pts = _pts; @@ -427,12 +455,12 @@ void MSubTriangle::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) IntPt *ptsb; getBaseElement()->getIntegrationPoints(pOrder, &_npts, &ptsb); - // (ii) get the coordinates of these points in the parametric space of parent element - double u,v,w; + // (ii) get the coordinates of these points in the parametric space of parent + // element + double u, v, w; double jac[3][3]; double baseJac, origJac; - for(int i=0; i<_npts; ++i) - { + for(int i = 0; i < _npts; ++i) { u = ptsb[i].pt[0]; v = ptsb[i].pt[1]; w = ptsb[i].pt[2]; @@ -444,49 +472,49 @@ void MSubTriangle::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) _pts[i].pt[0] = u; _pts[i].pt[1] = v; _pts[i].pt[2] = w; - _pts[i].weight = ptsb[i].weight * baseJac/origJac; + _pts[i].weight = ptsb[i].weight * baseJac / origJac; } *npts = _npts; *pts = _pts; } - // MSubLine MSubLine::~MSubLine() { - if(_pts) delete [] _pts; + if(_pts) delete[] _pts; if(_base) delete _base; } void MSubLine::updateParent(GModel *gm) { - _orig=gm->getMeshElementByTag(_orig_N); + _orig = gm->getMeshElementByTag(_orig_N); } -const nodalBasis* MSubLine::getFunctionSpace(int order, bool serendip) const +const nodalBasis *MSubLine::getFunctionSpace(int order, bool serendip) const { if(_orig) return _orig->getFunctionSpace(order, serendip); return 0; } -const JacobianBasis* MSubLine::getJacobianFuncSpace(int order) const +const JacobianBasis *MSubLine::getJacobianFuncSpace(int order) const { if(_orig) return _orig->getJacobianFuncSpace(order); return 0; } -void MSubLine::getShapeFunctions(double u, double v, double w, double s[], int order) const +void MSubLine::getShapeFunctions(double u, double v, double w, double s[], + int order) const { if(_orig) _orig->getShapeFunctions(u, v, w, s, order); } -void MSubLine::getGradShapeFunctions(double u, double v, double w, double s[][3], int order) const +void MSubLine::getGradShapeFunctions(double u, double v, double w, + double s[][3], int order) const { - if(!_orig) - return; + if(!_orig) return; - if (_orig->getDim()==getDim()) + if(_orig->getDim() == getDim()) return _orig->getGradShapeFunctions(u, v, w, s, order); int nsf = _orig->getNumShapeFunctions(); @@ -502,53 +530,66 @@ void MSubLine::getGradShapeFunctions(double u, double v, double w, double s[][3] double gradxyz[3]; double projgradxyz[3]; - for (int i=0; i<nsf; ++i) - { + for(int i = 0; i < nsf; ++i) { // (i) get the cartesian coordinates of the gradient - gradxyz[0] = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; - gradxyz[1] = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + invjac[1][2] * gradsuvw[i][2]; - gradxyz[2] = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * gradsuvw[i][2]; + gradxyz[0] = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + + invjac[0][2] * gradsuvw[i][2]; + gradxyz[1] = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + + invjac[1][2] * gradsuvw[i][2]; + gradxyz[2] = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + + invjac[2][2] * gradsuvw[i][2]; // (ii) projection of the gradient on edges in the cartesian space SVector3 grad(&gradxyz[0]); - double prodscal = dot(tang,grad); + double prodscal = dot(tang, grad); projgradxyz[0] = prodscal * tang.x(); projgradxyz[1] = prodscal * tang.y(); projgradxyz[2] = prodscal * tang.z(); - // (iii) get the parametric coordinates of the projection in the parametric space of the parent element - s[i][0] = jac[0][0] * projgradxyz[0] + jac[0][1] * projgradxyz[1] + jac[0][2] * projgradxyz[2]; - s[i][1] = jac[1][0] * projgradxyz[0] + jac[1][1] * projgradxyz[1] + jac[1][2] * projgradxyz[2]; - s[i][2] = jac[2][0] * projgradxyz[0] + jac[2][1] * projgradxyz[1] + jac[2][2] * projgradxyz[2]; + // (iii) get the parametric coordinates of the projection in the parametric + // space of the parent element + s[i][0] = jac[0][0] * projgradxyz[0] + jac[0][1] * projgradxyz[1] + + jac[0][2] * projgradxyz[2]; + s[i][1] = jac[1][0] * projgradxyz[0] + jac[1][1] * projgradxyz[1] + + jac[1][2] * projgradxyz[2]; + s[i][2] = jac[2][0] * projgradxyz[0] + jac[2][1] * projgradxyz[1] + + jac[2][2] * projgradxyz[2]; } } -void MSubLine::getHessShapeFunctions(double u, double v, double w, double s[][3][3], int order) const +void MSubLine::getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int order) const { if(_orig) _orig->getHessShapeFunctions(u, v, w, s, order); } -void MSubLine::getThirdDerivativeShapeFunctions(double u, double v, double w, double s[][3][3][3], int order) const +void MSubLine::getThirdDerivativeShapeFunctions(double u, double v, double w, + double s[][3][3][3], + int order) const { if(_orig) _orig->getThirdDerivativeShapeFunctions(u, v, w, s, order); } -double MSubLine::getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const +double MSubLine::getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(gsf, jac); return 0; } -double MSubLine::getJacobian(const std::vector<SVector3> &gsf, double jac[3][3]) const +double MSubLine::getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(gsf, jac); return 0; } -double MSubLine::getJacobian(double u, double v, double w, double jac[3][3]) const +double MSubLine::getJacobian(double u, double v, double w, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(u, v, w, jac); return 0; } -double MSubLine::getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const +double MSubLine::getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const { if(_orig) return _orig->getPrimaryJacobian(u, v, w, jac); return 0; @@ -566,13 +607,13 @@ int MSubLine::getNumPrimaryShapeFunctions() const return 0; } -const MVertex* MSubLine::getShapeFunctionNode(int i) const +const MVertex *MSubLine::getShapeFunctionNode(int i) const { if(_orig) return _orig->getShapeFunctionNode(i); return 0; } -MVertex* MSubLine::getShapeFunctionNode(int i) +MVertex *MSubLine::getShapeFunctionNode(int i) { if(_orig) return _orig->getShapeFunctionNode(i); return 0; @@ -580,10 +621,11 @@ MVertex* MSubLine::getShapeFunctionNode(int i) void MSubLine::xyz2uvw(double xyz[3], double uvw[3]) const { - if(_orig) _orig->xyz2uvw(xyz,uvw); + if(_orig) _orig->xyz2uvw(xyz, uvw); } -void MSubLine::movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const +void MSubLine::movePointFromParentSpaceToElementSpace(double &u, double &v, + double &w) const { if(!_orig) return; SPoint3 p; @@ -591,10 +633,13 @@ void MSubLine::movePointFromParentSpaceToElementSpace(double &u, double &v, doub double xyz[3] = {p.x(), p.y(), p.z()}; double uvwE[3]; getBaseElement()->xyz2uvw(xyz, uvwE); - u = uvwE[0]; v = uvwE[1]; w = uvwE[2]; + u = uvwE[0]; + v = uvwE[1]; + w = uvwE[2]; } -void MSubLine::movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const +void MSubLine::movePointFromElementSpaceToParentSpace(double &u, double &v, + double &w) const { if(!_orig) return; SPoint3 p; @@ -602,15 +647,16 @@ void MSubLine::movePointFromElementSpaceToParentSpace(double &u, double &v, doub double xyz[3] = {p.x(), p.y(), p.z()}; double uvwP[3]; _orig->xyz2uvw(xyz, uvwP); - u = uvwP[0]; v = uvwP[1]; w = uvwP[2]; + u = uvwP[0]; + v = uvwP[1]; + w = uvwP[2]; } bool MSubLine::isInside(double u, double v, double w) const { if(!_orig) return false; - if (_orig->getDim()!=getDim()) - {// projection on the base Element + if(_orig->getDim() != getDim()) { // projection on the base Element SPoint3 p; _orig->pnt(u, v, w, p); double xyz[3] = {p.x(), p.y(), p.z()}; @@ -619,35 +665,31 @@ bool MSubLine::isInside(double u, double v, double w) const SPoint3 pE; getBaseElement()->pnt(uvwE[0], uvwE[1], uvwE[2], pE); double tol = _isInsideTolerance; - if (fabs(p.x()-pE.x())>tol) return false; - if (fabs(p.y()-pE.y())>tol) return false; - if (fabs(p.z()-pE.z())>tol) return false; + if(fabs(p.x() - pE.x()) > tol) return false; + if(fabs(p.y() - pE.y()) > tol) return false; + if(fabs(p.z() - pE.z()) > tol) return false; } movePointFromParentSpaceToElementSpace(u, v, w); - if(getBaseElement()->isInside(u, v, w)) - return true; + if(getBaseElement()->isInside(u, v, w)) return true; return false; } void MSubLine::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { - if(_pts) - { - if(pOrder==_pOrder) - { + if(_pts) { + if(pOrder == _pOrder) { *npts = _npts; *pts = _pts; return; } else - delete [] _pts; + delete[] _pts; } _pOrder = pOrder; - if(!_orig) - { + if(!_orig) { getBaseElement()->getIntegrationPoints(pOrder, &_npts, &_pts); *npts = _npts; *pts = _pts; @@ -661,12 +703,12 @@ void MSubLine::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) IntPt *ptsb; getBaseElement()->getIntegrationPoints(pOrder, &_npts, &ptsb); - // (ii) get the coordinates of these points in the parametric space of parent element - double u,v,w; + // (ii) get the coordinates of these points in the parametric space of parent + // element + double u, v, w; double jac[3][3]; double baseJac, origJac; - for(int i=0; i<_npts; ++i) - { + for(int i = 0; i < _npts; ++i) { u = ptsb[i].pt[0]; v = ptsb[i].pt[1]; w = ptsb[i].pt[2]; @@ -678,74 +720,82 @@ void MSubLine::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) _pts[i].pt[0] = u; _pts[i].pt[1] = v; _pts[i].pt[2] = w; - _pts[i].weight = ptsb[i].weight * baseJac/origJac; + _pts[i].weight = ptsb[i].weight * baseJac / origJac; } *npts = _npts; *pts = _pts; } - // MSubPoint MSubPoint::~MSubPoint() { - if(_pts) delete [] _pts; + if(_pts) delete[] _pts; if(_base) delete _base; } void MSubPoint::updateParent(GModel *gm) { - _orig=gm->getMeshElementByTag(_orig_N); + _orig = gm->getMeshElementByTag(_orig_N); } -const nodalBasis* MSubPoint::getFunctionSpace(int order, bool serendip) const +const nodalBasis *MSubPoint::getFunctionSpace(int order, bool serendip) const { if(_orig) return _orig->getFunctionSpace(order, serendip); return 0; } -const JacobianBasis* MSubPoint::getJacobianFuncSpace(int order) const +const JacobianBasis *MSubPoint::getJacobianFuncSpace(int order) const { if(_orig) return _orig->getJacobianFuncSpace(order); return 0; } -void MSubPoint::getShapeFunctions(double u, double v, double w, double s[], int order) const +void MSubPoint::getShapeFunctions(double u, double v, double w, double s[], + int order) const { if(_orig) _orig->getShapeFunctions(u, v, w, s, order); } -void MSubPoint::getGradShapeFunctions(double u, double v, double w, double s[][3], int order) const +void MSubPoint::getGradShapeFunctions(double u, double v, double w, + double s[][3], int order) const { if(_orig) _orig->getGradShapeFunctions(u, v, w, s, order); } -void MSubPoint::getHessShapeFunctions(double u, double v, double w, double s[][3][3], int order) const +void MSubPoint::getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int order) const { if(_orig) _orig->getHessShapeFunctions(u, v, w, s, order); } -void MSubPoint::getThirdDerivativeShapeFunctions(double u, double v, double w, double s[][3][3][3], int order) const +void MSubPoint::getThirdDerivativeShapeFunctions(double u, double v, double w, + double s[][3][3][3], + int order) const { if(_orig) _orig->getThirdDerivativeShapeFunctions(u, v, w, s, order); } -double MSubPoint::getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const +double MSubPoint::getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(gsf, jac); return 0; } -double MSubPoint::getJacobian(const std::vector<SVector3> &gsf, double jac[3][3]) const +double MSubPoint::getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(gsf, jac); return 0; } -double MSubPoint::getJacobian(double u, double v, double w, double jac[3][3]) const +double MSubPoint::getJacobian(double u, double v, double w, + double jac[3][3]) const { if(_orig) return _orig->getJacobian(u, v, w, jac); return 0; } -double MSubPoint::getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const +double MSubPoint::getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const { if(_orig) return _orig->getPrimaryJacobian(u, v, w, jac); return 0; @@ -763,13 +813,13 @@ int MSubPoint::getNumPrimaryShapeFunctions() const return 0; } -const MVertex* MSubPoint::getShapeFunctionNode(int i) const +const MVertex *MSubPoint::getShapeFunctionNode(int i) const { if(_orig) return _orig->getShapeFunctionNode(i); return 0; } -MVertex* MSubPoint::getShapeFunctionNode(int i) +MVertex *MSubPoint::getShapeFunctionNode(int i) { if(_orig) return _orig->getShapeFunctionNode(i); return 0; @@ -777,10 +827,11 @@ MVertex* MSubPoint::getShapeFunctionNode(int i) void MSubPoint::xyz2uvw(double xyz[3], double uvw[3]) const { - if(_orig) _orig->xyz2uvw(xyz,uvw); + if(_orig) _orig->xyz2uvw(xyz, uvw); } -void MSubPoint::movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const +void MSubPoint::movePointFromParentSpaceToElementSpace(double &u, double &v, + double &w) const { if(!_orig) return; SPoint3 p; @@ -788,10 +839,13 @@ void MSubPoint::movePointFromParentSpaceToElementSpace(double &u, double &v, dou double xyz[3] = {p.x(), p.y(), p.z()}; double uvwE[3]; getBaseElement()->xyz2uvw(xyz, uvwE); - u = uvwE[0]; v = uvwE[1]; w = uvwE[2]; + u = uvwE[0]; + v = uvwE[1]; + w = uvwE[2]; } -void MSubPoint::movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const +void MSubPoint::movePointFromElementSpaceToParentSpace(double &u, double &v, + double &w) const { if(!_orig) return; SPoint3 p; @@ -799,15 +853,16 @@ void MSubPoint::movePointFromElementSpaceToParentSpace(double &u, double &v, dou double xyz[3] = {p.x(), p.y(), p.z()}; double uvwP[3]; _orig->xyz2uvw(xyz, uvwP); - u = uvwP[0]; v = uvwP[1]; w = uvwP[2]; + u = uvwP[0]; + v = uvwP[1]; + w = uvwP[2]; } bool MSubPoint::isInside(double u, double v, double w) const { if(!_orig) return false; - if (_orig->getDim()!=getDim()) - {// projection on the base Element + if(_orig->getDim() != getDim()) { // projection on the base Element SPoint3 p; _orig->pnt(u, v, w, p); double xyz[3] = {p.x(), p.y(), p.z()}; @@ -816,22 +871,20 @@ bool MSubPoint::isInside(double u, double v, double w) const SPoint3 pE; getBaseElement()->pnt(uvwE[0], uvwE[1], uvwE[2], pE); double tol = _isInsideTolerance; - if (fabs(p.x()-pE.x())>tol) return false; - if (fabs(p.y()-pE.y())>tol) return false; - if (fabs(p.z()-pE.z())>tol) return false; + if(fabs(p.x() - pE.x()) > tol) return false; + if(fabs(p.y() - pE.y()) > tol) return false; + if(fabs(p.z() - pE.z()) > tol) return false; } movePointFromParentSpaceToElementSpace(u, v, w); - if(getBaseElement()->isInside(u, v, w)) - return true; + if(getBaseElement()->isInside(u, v, w)) return true; return false; } void MSubPoint::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) { // invariable regardless of the order - if(!_pts) - { + if(!_pts) { if(!_orig) return; _pts = new IntPt[1]; @@ -845,7 +898,7 @@ void MSubPoint::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) _pts[0].pt[0] = v_uvw[0]; _pts[0].pt[1] = v_uvw[1]; _pts[0].pt[2] = v_uvw[2]; - _pts[0].weight = 1./origJac; + _pts[0].weight = 1. / origJac; } *npts = 1; *pts = _pts; diff --git a/Geo/MSubElement.h b/Geo/MSubElement.h index 570c2a26f04256daf831fed45073439ea189e45f..2c583d99dee8207825a17203dc856870cbe10941 100644 --- a/Geo/MSubElement.h +++ b/Geo/MSubElement.h @@ -17,19 +17,18 @@ #include "MPoint.h" // A sub tetrahedron, contained in another element -class MSubTetrahedron : public MTetrahedron -{ +class MSubTetrahedron : public MTetrahedron { friend class MElementFactory; friend class GModel; - protected: + +protected: bool _owner; - union - { - MElement* _orig; // pointer to parent - int _orig_N ; // element number of parent (only used while reading file...) + union { + MElement *_orig; // pointer to parent + int _orig_N; // element number of parent (only used while reading file...) }; - std::vector<MElement*> _parents; // not used in msh 3 file format - mutable MElement* _base; + std::vector<MElement *> _parents; // not used in msh 3 file format + mutable MElement *_base; int _pOrder; int _npts; @@ -37,84 +36,109 @@ class MSubTetrahedron : public MTetrahedron MSubTetrahedron(const std::vector<MVertex *> &v, int num, int part, bool owner, int orig) - : MTetrahedron(v, num, part) - , _owner(owner) - , _orig_N(orig) - , _base(0) - , _pOrder(-1) - , _npts(0) - , _pts(0) + : MTetrahedron(v, num, part), _owner(owner), _orig_N(orig), _base(0), + _pOrder(-1), _npts(0), _pts(0) { } - virtual void updateParent(GModel *gm); // NEVER ever use this ! (except for reading msh files !) + virtual void updateParent( + GModel *gm); // NEVER ever use this ! (except for reading msh files !) - public: - MSubTetrahedron(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, int num=0, int part=0, - bool owner=false, MElement* orig=NULL) - : MTetrahedron(v0, v1, v2, v3, num, part), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), _pts(0) {} +public: + MSubTetrahedron(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, + int num = 0, int part = 0, bool owner = false, + MElement *orig = NULL) + : MTetrahedron(v0, v1, v2, v3, num, part), _owner(owner), _orig(orig), + _base(0), _pOrder(-1), _npts(0), _pts(0) + { + } MSubTetrahedron(const std::vector<MVertex *> &v, int num = 0, int part = 0, bool owner = false, MElement *orig = NULL) - : MTetrahedron(v, num, part) - , _owner(owner) - , _orig(orig) - , _base(0) - , _pOrder(-1) - , _npts(0) - , _pts(0) + : MTetrahedron(v, num, part), _owner(owner), _orig(orig), _base(0), + _pOrder(-1), _npts(0), _pts(0) + { + } + MSubTetrahedron(const MTetrahedron &tet, bool owner = false, + MElement *orig = NULL) + : MTetrahedron(tet), _owner(owner), _orig(orig), _base(0), _pOrder(-1), + _npts(0), _pts(0) { } - MSubTetrahedron(const MTetrahedron &tet, bool owner=false, MElement* orig=NULL) - : MTetrahedron(tet), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), _pts(0) {} ~MSubTetrahedron(); virtual int getTypeForMSH() const { return MSH_TET_SUB; } - virtual const nodalBasis* getFunctionSpace(int order=-1, bool serendip=false) const; - virtual const JacobianBasis* getJacobianFuncSpace(int order=-1) const; + virtual const nodalBasis *getFunctionSpace(int order = -1, + bool serendip = false) const; + virtual const JacobianBasis *getJacobianFuncSpace(int order = -1) const; // the parametric coordinates are the coordinates in the local parent element - virtual void getShapeFunctions(double u, double v, double w, double s[], int order=-1) const; - virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int order=-1) const; - virtual void getHessShapeFunctions(double u, double v, double w, double s[][3][3], int order=-1) const; - virtual void getThirdDerivativeShapeFunctions(double u, double v, double w, double s[][3][3][3], int order=-1) const; - virtual double getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const; - virtual double getJacobian(const std::vector<SVector3> &gsf, double jac[3][3])const; - virtual double getJacobian(double u, double v, double w, double jac[3][3]) const; - virtual double getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const; + virtual void getShapeFunctions(double u, double v, double w, double s[], + int order = -1) const; + virtual void getGradShapeFunctions(double u, double v, double w, + double s[][3], int order = -1) const; + virtual void getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int order = -1) const; + virtual void getThirdDerivativeShapeFunctions(double u, double v, double w, + double s[][3][3][3], + int order = -1) const; + virtual double getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const; + virtual double getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const; + virtual double getJacobian(double u, double v, double w, + double jac[3][3]) const; + virtual double getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const; virtual int getNumShapeFunctions() const; virtual int getNumPrimaryShapeFunctions() const; - virtual const MVertex* getShapeFunctionNode(int i) const; - virtual MVertex* getShapeFunctionNode(int i); + virtual const MVertex *getShapeFunctionNode(int i) const; + virtual MVertex *getShapeFunctionNode(int i); virtual void xyz2uvw(double xyz[3], double uvw[3]) const; - virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const; - virtual void movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const; + virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, + double &w) const; + virtual void movePointFromElementSpaceToParentSpace(double &u, double &v, + double &w) const; virtual bool isInside(double u, double v, double w) const; virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); virtual MElement *getParent() const { return _orig; } - virtual void setParent(MElement *p, bool owner = false) { _orig = p; _owner = owner; } + virtual void setParent(MElement *p, bool owner = false) + { + _orig = p; + _owner = owner; + } virtual bool ownsParent() const { return _owner; } - virtual std::vector<MElement*> getMultiParents() const { return _parents; } - virtual void setMultiParent(std::vector<MElement*> &parents, bool owner = false) + virtual std::vector<MElement *> getMultiParents() const { return _parents; } + virtual void setMultiParent(std::vector<MElement *> &parents, + bool owner = false) { - _parents = parents; _orig = _parents[0]; _owner = owner; + _parents = parents; + _orig = _parents[0]; + _owner = owner; + } + virtual const MElement *getBaseElement() const + { + if(!_base) _base = new MTetrahedron(*this); + return _base; + } + virtual MElement *getBaseElement() + { + if(!_base) _base = new MTetrahedron(*this); + return _base; } - virtual const MElement *getBaseElement() const {if(!_base) _base=new MTetrahedron(*this); return _base;} - virtual MElement *getBaseElement() {if(!_base) _base=new MTetrahedron(*this); return _base;} }; // A sub triangle, contained in another element -class MSubTriangle : public MTriangle -{ +class MSubTriangle : public MTriangle { friend class MElementFactory; friend class GModel; - protected: + +protected: bool _owner; - union - { - MElement* _orig; // pointer to parent - int _orig_N ; // element number of parent (only used while reading file...) + union { + MElement *_orig; // pointer to parent + int _orig_N; // element number of parent (only used while reading file...) }; - std::vector<MElement*> _parents; // not used in msh 3 file format - mutable MElement* _base; + std::vector<MElement *> _parents; // not used in msh 3 file format + mutable MElement *_base; int _pOrder; int _npts; @@ -122,83 +146,106 @@ class MSubTriangle : public MTriangle MSubTriangle(const std::vector<MVertex *> &v, int num, int part, bool owner, int orig) - : MTriangle(v, num, part) - , _owner(owner) - , _orig_N(orig) - , _base(0) - , _pOrder(-1) - , _npts(0) - , _pts(0) - { - } - virtual void updateParent(GModel *gm); // NEVER ever use this ! (except for reading msh files !) - public: - MSubTriangle(MVertex *v0, MVertex *v1, MVertex *v2, int num=0, int part=0, - bool owner=false, MElement* orig=NULL) - : MTriangle(v0, v1, v2, num, part), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), _pts(0) {} + : MTriangle(v, num, part), _owner(owner), _orig_N(orig), _base(0), + _pOrder(-1), _npts(0), _pts(0) + { + } + virtual void updateParent( + GModel *gm); // NEVER ever use this ! (except for reading msh files !) +public: + MSubTriangle(MVertex *v0, MVertex *v1, MVertex *v2, int num = 0, int part = 0, + bool owner = false, MElement *orig = NULL) + : MTriangle(v0, v1, v2, num, part), _owner(owner), _orig(orig), _base(0), + _pOrder(-1), _npts(0), _pts(0) + { + } MSubTriangle(const std::vector<MVertex *> &v, int num = 0, int part = 0, bool owner = false, MElement *orig = NULL) - : MTriangle(v, num, part) - , _owner(owner) - , _orig(orig) - , _base(0) - , _pOrder(-1) - , _npts(0) - , _pts(0) + : MTriangle(v, num, part), _owner(owner), _orig(orig), _base(0), + _pOrder(-1), _npts(0), _pts(0) + { + } + MSubTriangle(const MTriangle &tri, bool owner = false, MElement *orig = NULL) + : MTriangle(tri), _owner(owner), _orig(orig), _base(0), _pOrder(-1), + _npts(0), _pts(0) { } - MSubTriangle(const MTriangle &tri, bool owner=false, MElement* orig=NULL) - : MTriangle(tri), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), _pts(0) {} ~MSubTriangle(); virtual int getTypeForMSH() const { return MSH_TRI_SUB; } - virtual const nodalBasis* getFunctionSpace(int order=-1, bool serendip=false) const; - virtual const JacobianBasis* getJacobianFuncSpace(int order=-1) const; + virtual const nodalBasis *getFunctionSpace(int order = -1, + bool serendip = false) const; + virtual const JacobianBasis *getJacobianFuncSpace(int order = -1) const; // the parametric coordinates are the coordinates in the local parent element - virtual void getShapeFunctions(double u, double v, double w, double s[], int order=-1) const; - virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int order=-1) const; - virtual void getHessShapeFunctions(double u, double v, double w, double s[][3][3], int order=-1) const; - virtual void getThirdDerivativeShapeFunctions(double u, double v, double w, double s[][3][3][3], int order=-1) const; - virtual double getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const; - virtual double getJacobian(const std::vector<SVector3> &gsf, double jac[3][3])const; - virtual double getJacobian(double u, double v, double w, double jac[3][3])const; - virtual double getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const; + virtual void getShapeFunctions(double u, double v, double w, double s[], + int order = -1) const; + virtual void getGradShapeFunctions(double u, double v, double w, + double s[][3], int order = -1) const; + virtual void getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int order = -1) const; + virtual void getThirdDerivativeShapeFunctions(double u, double v, double w, + double s[][3][3][3], + int order = -1) const; + virtual double getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const; + virtual double getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const; + virtual double getJacobian(double u, double v, double w, + double jac[3][3]) const; + virtual double getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const; virtual int getNumShapeFunctions() const; virtual int getNumPrimaryShapeFunctions() const; - virtual const MVertex* getShapeFunctionNode(int i) const; - virtual MVertex* getShapeFunctionNode(int i); + virtual const MVertex *getShapeFunctionNode(int i) const; + virtual MVertex *getShapeFunctionNode(int i); virtual void xyz2uvw(double xyz[3], double uvw[3]) const; - virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const; - virtual void movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const; + virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, + double &w) const; + virtual void movePointFromElementSpaceToParentSpace(double &u, double &v, + double &w) const; virtual bool isInside(double u, double v, double w) const; virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); virtual MElement *getParent() const { return _orig; } - virtual void setParent(MElement *p, bool owner = false) { _orig = p; _owner = owner; } + virtual void setParent(MElement *p, bool owner = false) + { + _orig = p; + _owner = owner; + } virtual bool ownsParent() const { return _owner; } - virtual std::vector<MElement*> getMultiParents() const { return _parents; } - virtual void setMultiParent(std::vector<MElement*> &parents, bool owner = false) + virtual std::vector<MElement *> getMultiParents() const { return _parents; } + virtual void setMultiParent(std::vector<MElement *> &parents, + bool owner = false) + { + _parents = parents; + _orig = _parents[0]; + _owner = owner; + } + virtual const MElement *getBaseElement() const { - _parents = parents; _orig = _parents[0]; _owner = owner; + if(!_base) _base = new MTriangle(*this); + return _base; + } + virtual MElement *getBaseElement() + { + if(!_base) _base = new MTriangle(*this); + return _base; } - virtual const MElement *getBaseElement() const {if(!_base) _base=new MTriangle(*this); return _base;} - virtual MElement *getBaseElement() {if(!_base) _base=new MTriangle(*this); return _base;} }; // A sub line, contained in another element -class MSubLine : public MLine -{ +class MSubLine : public MLine { friend class MElementFactory; friend class GModel; - protected: + +protected: bool _owner; - union - { - MElement* _orig; // pointer to parent - int _orig_N ; // element number of parent (only used while reading file...) + union { + MElement *_orig; // pointer to parent + int _orig_N; // element number of parent (only used while reading file...) }; - std::vector<MElement*> _parents; // not used in msh 3 file format - mutable MElement* _base; + std::vector<MElement *> _parents; // not used in msh 3 file format + mutable MElement *_base; int _pOrder; int _npts; @@ -206,83 +253,106 @@ class MSubLine : public MLine MSubLine(const std::vector<MVertex *> &v, int num, int part, bool owner, int orig) - : MLine(v, num, part) - , _owner(owner) - , _orig_N(orig) - , _base(0) - , _pOrder(-1) - , _npts(0) - , _pts(0) - { - } - virtual void updateParent(GModel *gm); // NEVER ever use this ! (except for reading msh files !) - public: - MSubLine(MVertex *v0, MVertex *v1, int num=0, int part=0, - bool owner=false, MElement* orig=NULL) - : MLine(v0, v1, num, part), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), _pts(0) {} + : MLine(v, num, part), _owner(owner), _orig_N(orig), _base(0), _pOrder(-1), + _npts(0), _pts(0) + { + } + virtual void updateParent( + GModel *gm); // NEVER ever use this ! (except for reading msh files !) +public: + MSubLine(MVertex *v0, MVertex *v1, int num = 0, int part = 0, + bool owner = false, MElement *orig = NULL) + : MLine(v0, v1, num, part), _owner(owner), _orig(orig), _base(0), + _pOrder(-1), _npts(0), _pts(0) + { + } MSubLine(const std::vector<MVertex *> &v, int num = 0, int part = 0, bool owner = false, MElement *orig = NULL) - : MLine(v, num, part) - , _owner(owner) - , _orig(orig) - , _base(0) - , _pOrder(-1) - , _npts(0) - , _pts(0) + : MLine(v, num, part), _owner(owner), _orig(orig), _base(0), _pOrder(-1), + _npts(0), _pts(0) + { + } + MSubLine(const MLine &lin, bool owner = false, MElement *orig = NULL) + : MLine(lin), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), + _pts(0) { } - MSubLine(const MLine &lin, bool owner=false, MElement* orig=NULL) - : MLine(lin), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), _pts(0) {} ~MSubLine(); virtual int getTypeForMSH() const { return MSH_LIN_SUB; } - virtual const nodalBasis* getFunctionSpace(int order=-1, bool serendip=false) const; - virtual const JacobianBasis* getJacobianFuncSpace(int order=-1) const; + virtual const nodalBasis *getFunctionSpace(int order = -1, + bool serendip = false) const; + virtual const JacobianBasis *getJacobianFuncSpace(int order = -1) const; // the parametric coordinates are the coordinates in the local parent element - virtual void getShapeFunctions(double u, double v, double w, double s[], int order=-1) const; - virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int order=-1) const; - virtual void getHessShapeFunctions(double u, double v, double w, double s[][3][3], int order=-1) const; - virtual void getThirdDerivativeShapeFunctions(double u, double v, double w, double s[][3][3][3], int order=-1) const; - virtual double getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const; - virtual double getJacobian(const std::vector<SVector3> &gsf, double jac[3][3])const; - virtual double getJacobian(double u, double v, double w, double jac[3][3]) const; - virtual double getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const; + virtual void getShapeFunctions(double u, double v, double w, double s[], + int order = -1) const; + virtual void getGradShapeFunctions(double u, double v, double w, + double s[][3], int order = -1) const; + virtual void getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int order = -1) const; + virtual void getThirdDerivativeShapeFunctions(double u, double v, double w, + double s[][3][3][3], + int order = -1) const; + virtual double getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const; + virtual double getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const; + virtual double getJacobian(double u, double v, double w, + double jac[3][3]) const; + virtual double getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const; virtual int getNumShapeFunctions() const; virtual int getNumPrimaryShapeFunctions() const; - virtual const MVertex* getShapeFunctionNode(int i) const; - virtual MVertex* getShapeFunctionNode(int i); + virtual const MVertex *getShapeFunctionNode(int i) const; + virtual MVertex *getShapeFunctionNode(int i); virtual void xyz2uvw(double xyz[3], double uvw[3]) const; - virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const; - virtual void movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const; + virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, + double &w) const; + virtual void movePointFromElementSpaceToParentSpace(double &u, double &v, + double &w) const; virtual bool isInside(double u, double v, double w) const; virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); virtual MElement *getParent() const { return _orig; } - virtual void setParent(MElement *p, bool owner = false) { _orig = p; _owner = owner; } + virtual void setParent(MElement *p, bool owner = false) + { + _orig = p; + _owner = owner; + } virtual bool ownsParent() const { return _owner; } - virtual std::vector<MElement*> getMultiParents() const { return _parents; } - virtual void setMultiParent(std::vector<MElement*> &parents, bool owner = false) + virtual std::vector<MElement *> getMultiParents() const { return _parents; } + virtual void setMultiParent(std::vector<MElement *> &parents, + bool owner = false) + { + _parents = parents; + _orig = _parents[0]; + _owner = owner; + } + virtual const MElement *getBaseElement() const { - _parents = parents; _orig = _parents[0]; _owner = owner; + if(!_base) _base = new MLine(*this); + return _base; + } + virtual MElement *getBaseElement() + { + if(!_base) _base = new MLine(*this); + return _base; } - virtual const MElement *getBaseElement() const {if(!_base) _base=new MLine(*this); return _base;} - virtual MElement *getBaseElement() {if(!_base) _base=new MLine(*this); return _base;} }; // A sub point, contained in another element -class MSubPoint : public MPoint -{ +class MSubPoint : public MPoint { friend class MElementFactory; friend class GModel; - protected: + +protected: bool _owner; - union - { - MElement* _orig; // pointer to parent - int _orig_N ; // element number of parent (only used while reading file...) + union { + MElement *_orig; // pointer to parent + int _orig_N; // element number of parent (only used while reading file...) }; - std::vector<MElement*> _parents; // not used in msh 3 file format - mutable MElement* _base; + std::vector<MElement *> _parents; // not used in msh 3 file format + mutable MElement *_base; int _pOrder; int _npts; @@ -290,68 +360,91 @@ class MSubPoint : public MPoint MSubPoint(const std::vector<MVertex *> &v, int num, int part, bool owner, int orig) - : MPoint(v, num, part) - , _owner(owner) - , _orig_N(orig) - , _base(0) - , _pOrder(-1) - , _npts(0) - , _pts(0) - { - } - virtual void updateParent(GModel *gm); // NEVER ever use this ! (except for reading msh files !) - public: - MSubPoint(MVertex *v0, int num=0, int part=0, - bool owner=false, MElement* orig=NULL) - : MPoint(v0, num, part), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), _pts(0) {} + : MPoint(v, num, part), _owner(owner), _orig_N(orig), _base(0), _pOrder(-1), + _npts(0), _pts(0) + { + } + virtual void updateParent( + GModel *gm); // NEVER ever use this ! (except for reading msh files !) +public: + MSubPoint(MVertex *v0, int num = 0, int part = 0, bool owner = false, + MElement *orig = NULL) + : MPoint(v0, num, part), _owner(owner), _orig(orig), _base(0), _pOrder(-1), + _npts(0), _pts(0) + { + } MSubPoint(const std::vector<MVertex *> &v, int num = 0, int part = 0, bool owner = false, MElement *orig = NULL) - : MPoint(v, num, part) - , _owner(owner) - , _orig(orig) - , _base(0) - , _pOrder(-1) - , _npts(0) - , _pts(0) + : MPoint(v, num, part), _owner(owner), _orig(orig), _base(0), _pOrder(-1), + _npts(0), _pts(0) + { + } + MSubPoint(const MPoint &pt, bool owner = false, MElement *orig = NULL) + : MPoint(pt), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), + _pts(0) { } - MSubPoint(const MPoint &pt, bool owner=false, MElement* orig=NULL) - : MPoint(pt), _owner(owner), _orig(orig), _base(0), _pOrder(-1), _npts(0), _pts(0) {} ~MSubPoint(); virtual int getTypeForMSH() const { return MSH_PNT_SUB; } - virtual const nodalBasis* getFunctionSpace(int order=-1, bool serendip=false) const; - virtual const JacobianBasis* getJacobianFuncSpace(int order=-1) const; + virtual const nodalBasis *getFunctionSpace(int order = -1, + bool serendip = false) const; + virtual const JacobianBasis *getJacobianFuncSpace(int order = -1) const; // the parametric coordinates are the coordinates in the local parent element - virtual void getShapeFunctions(double u, double v, double w, double s[], int order=-1) const; - virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int order=-1) const; - virtual void getHessShapeFunctions(double u, double v, double w, double s[][3][3], int order=-1) const; - virtual void getThirdDerivativeShapeFunctions(double u, double v, double w, double s[][3][3][3], int order=-1) const; - virtual double getJacobian(const fullMatrix<double> &gsf, double jac[3][3]) const; - virtual double getJacobian(const std::vector<SVector3> &gsf, double jac[3][3])const; - virtual double getJacobian(double u, double v, double w, double jac[3][3]) const; - virtual double getPrimaryJacobian(double u, double v, double w, double jac[3][3]) const; + virtual void getShapeFunctions(double u, double v, double w, double s[], + int order = -1) const; + virtual void getGradShapeFunctions(double u, double v, double w, + double s[][3], int order = -1) const; + virtual void getHessShapeFunctions(double u, double v, double w, + double s[][3][3], int order = -1) const; + virtual void getThirdDerivativeShapeFunctions(double u, double v, double w, + double s[][3][3][3], + int order = -1) const; + virtual double getJacobian(const fullMatrix<double> &gsf, + double jac[3][3]) const; + virtual double getJacobian(const std::vector<SVector3> &gsf, + double jac[3][3]) const; + virtual double getJacobian(double u, double v, double w, + double jac[3][3]) const; + virtual double getPrimaryJacobian(double u, double v, double w, + double jac[3][3]) const; virtual int getNumShapeFunctions() const; virtual int getNumPrimaryShapeFunctions() const; - virtual const MVertex* getShapeFunctionNode(int i) const; - virtual MVertex* getShapeFunctionNode(int i); + virtual const MVertex *getShapeFunctionNode(int i) const; + virtual MVertex *getShapeFunctionNode(int i); virtual void xyz2uvw(double xyz[3], double uvw[3]) const; - virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, double &w) const; - virtual void movePointFromElementSpaceToParentSpace(double &u, double &v, double &w) const; + virtual void movePointFromParentSpaceToElementSpace(double &u, double &v, + double &w) const; + virtual void movePointFromElementSpaceToParentSpace(double &u, double &v, + double &w) const; virtual bool isInside(double u, double v, double w) const; virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts); virtual MElement *getParent() const { return _orig; } - virtual void setParent(MElement *p, bool owner = false) { _orig = p; _owner = owner; } + virtual void setParent(MElement *p, bool owner = false) + { + _orig = p; + _owner = owner; + } virtual bool ownsParent() const { return _owner; } - virtual std::vector<MElement*> getMultiParents() const { return _parents; } - virtual void setMultiParent(std::vector<MElement*> &parents, bool owner = false) + virtual std::vector<MElement *> getMultiParents() const { return _parents; } + virtual void setMultiParent(std::vector<MElement *> &parents, + bool owner = false) + { + _parents = parents; + _orig = _parents[0]; + _owner = owner; + } + virtual const MElement *getBaseElement() const { - _parents = parents; _orig = _parents[0]; _owner = owner; + if(!_base) _base = new MPoint(*this); + return _base; + } + virtual MElement *getBaseElement() + { + if(!_base) _base = new MPoint(*this); + return _base; } - virtual const MElement *getBaseElement() const {if(!_base) _base=new MPoint(*this); return _base;} - virtual MElement *getBaseElement() {if(!_base) _base=new MPoint(*this); return _base;} }; #endif - diff --git a/Geo/MTetrahedron.cpp b/Geo/MTetrahedron.cpp index ec9f1c81d91339e438ec395c4f3dd33c5c9683e6..fe43edca57fe7cf5a402bc03f67f8b3a50ba4b00 100644 --- a/Geo/MTetrahedron.cpp +++ b/Geo/MTetrahedron.cpp @@ -16,19 +16,23 @@ #include "meshGRegionDelaunayInsertion.h" #endif -#define SQU(a) ((a)*(a)) +#define SQU(a) ((a) * (a)) std::map<int, IndicesReversed> MTetrahedronN::_order2indicesReversedTet; -void MTetrahedron::getEdgeRep(bool curved, int num, double *x, double *y, double *z, - SVector3 *n) +void MTetrahedron::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { // don't use MElement::_getEdgeRep: it's slow due to the creation of MFaces MVertex *v0 = _v[edges_tetra(num, 0)]; MVertex *v1 = _v[edges_tetra(num, 1)]; - x[0] = v0->x(); y[0] = v0->y(); z[0] = v0->z(); - x[1] = v1->x(); y[1] = v1->y(); z[1] = v1->z(); - if(CTX::instance()->mesh.lightLines > 1){ + x[0] = v0->x(); + y[0] = v0->y(); + z[0] = v0->z(); + x[1] = v1->x(); + y[1] = v1->y(); + z[1] = v1->z(); + if(CTX::instance()->mesh.lightLines > 1) { static const int vv[6] = {2, 0, 1, 1, 0, 2}; MVertex *v2 = _v[vv[num]]; SVector3 t1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); @@ -37,7 +41,7 @@ void MTetrahedron::getEdgeRep(bool curved, int num, double *x, double *y, double normal.normalize(); n[0] = n[1] = normal; } - else{ + else { n[0] = n[1] = SVector3(0., 0., 1.); } } @@ -73,16 +77,16 @@ double MTetrahedron::getInnerRadius() // radius of inscribed sphere = 3 * Volume / sum(Area_i) double dist[3], face_area = 0.; double vol = getVolume(); - for(int i = 0; i < 4; i++){ + for(int i = 0; i < 4; i++) { MFace f = getFace(i); - for (int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { MEdge e = f.getEdge(j); dist[j] = e.getVertex(0)->distance(e.getVertex(1)); } - face_area += 0.25 * sqrt((dist[0] + dist[1] + dist[2]) * - (-dist[0] + dist[1] + dist[2]) * - (dist[0] - dist[1] + dist[2]) * - (dist[0] + dist[1] - dist[2])); + face_area += + 0.25 * + sqrt((dist[0] + dist[1] + dist[2]) * (-dist[0] + dist[1] + dist[2]) * + (dist[0] - dist[1] + dist[2]) * (dist[0] + dist[1] - dist[2])); } return 3 * vol / face_area; } @@ -126,12 +130,11 @@ void MTetrahedron::xyz2uvw(double xyz[3], double uvw[3]) const int MTetrahedron::numCommonNodesInDualGraph(const MElement *const other) const { - switch (other->getType()) - { - case TYPE_PNT: return 1; - case TYPE_LIN: return 2; - case TYPE_QUA: return 4; - default: return 3; + switch(other->getType()) { + case TYPE_PNT: return 1; + case TYPE_LIN: return 2; + case TYPE_QUA: return 4; + default: return 3; } } @@ -145,50 +148,57 @@ int MTetrahedronN::getNumEdgesRep(bool curved) return curved ? 6 * CTX::instance()->mesh.numSubEdges : 6; } -static void _myGetEdgeRep(MTetrahedron *tet, int num, double *x, double *y, double *z, - SVector3 *n, int numSubEdges) +static void _myGetEdgeRep(MTetrahedron *tet, int num, double *x, double *y, + double *z, SVector3 *n, int numSubEdges) { - static double pp[4][3] = {{0,0,0},{1,0,0},{0,1,0},{0,0,1}}; - static int ed [6][2] = {{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}}; + static double pp[4][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; + static int ed[6][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}}; int iEdge = num / numSubEdges; int iSubEdge = num % numSubEdges; - int iVertex1 = ed [iEdge][0]; - int iVertex2 = ed [iEdge][1]; - double t1 = (double) iSubEdge / (double) numSubEdges; - double u1 = pp[iVertex1][0] * (1.-t1) + pp[iVertex2][0] * t1; - double v1 = pp[iVertex1][1] * (1.-t1) + pp[iVertex2][1] * t1; - double w1 = pp[iVertex1][2] * (1.-t1) + pp[iVertex2][2] * t1; + int iVertex1 = ed[iEdge][0]; + int iVertex2 = ed[iEdge][1]; + double t1 = (double)iSubEdge / (double)numSubEdges; + double u1 = pp[iVertex1][0] * (1. - t1) + pp[iVertex2][0] * t1; + double v1 = pp[iVertex1][1] * (1. - t1) + pp[iVertex2][1] * t1; + double w1 = pp[iVertex1][2] * (1. - t1) + pp[iVertex2][2] * t1; - double t2 = (double) (iSubEdge+1) / (double) numSubEdges; - double u2 = pp[iVertex1][0] * (1.-t2) + pp[iVertex2][0] * t2; - double v2 = pp[iVertex1][1] * (1.-t2) + pp[iVertex2][1] * t2; - double w2 = pp[iVertex1][2] * (1.-t2) + pp[iVertex2][2] * t2; + double t2 = (double)(iSubEdge + 1) / (double)numSubEdges; + double u2 = pp[iVertex1][0] * (1. - t2) + pp[iVertex2][0] * t2; + double v2 = pp[iVertex1][1] * (1. - t2) + pp[iVertex2][1] * t2; + double w2 = pp[iVertex1][2] * (1. - t2) + pp[iVertex2][2] * t2; SPoint3 pnt1, pnt2; - tet->pnt(u1,v1,w1,pnt1); - tet->pnt(u2,v2,w2,pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + tet->pnt(u1, v1, w1, pnt1); + tet->pnt(u2, v2, w2, pnt2); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); // not great, but better than nothing static const int f[6] = {0, 0, 0, 1, 2, 3}; n[0] = n[1] = tet->getFace(f[iEdge]).normal(); } -void MTetrahedron10::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MTetrahedron10::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MTetrahedron::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MTetrahedron::getEdgeRep(false, num, x, y, z, n); } -void MTetrahedronN::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MTetrahedronN::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MTetrahedron::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MTetrahedron::getEdgeRep(false, num, x, y, z, n); } int MTetrahedronN::getNumFacesRep(bool curved) @@ -201,12 +211,12 @@ int MTetrahedron10::getNumFacesRep(bool curved) return curved ? 4 * SQU(CTX::instance()->mesh.numSubEdges) : 4; } -static void _myGetFaceRep(MTetrahedron *tet, int num, double *x, double *y, double *z, - SVector3 *n , int numSubEdges) +static void _myGetFaceRep(MTetrahedron *tet, int num, double *x, double *y, + double *z, SVector3 *n, int numSubEdges) { - static double pp[4][3] = {{0,0,0},{1,0,0},{0,1,0},{0,0,1}}; - static int fak [4][3] = {{0,2,1},{0,1,3},{0,3,2},{1,2,3}}; - int iFace = num / (numSubEdges * numSubEdges); + static double pp[4][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; + static int fak[4][3] = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2}, {1, 2, 3}}; + int iFace = num / (numSubEdges * numSubEdges); int iSubFace = num % (numSubEdges * numSubEdges); int iVertex1 = fak[iFace][0]; @@ -227,10 +237,10 @@ static void _myGetFaceRep(MTetrahedron *tet, int num, double *x, double *y, doub // on the ith layer, we have (numSubEdges-1-i) * 2 + 1 triangles int ix = 0, iy = 0; int nbt = 0; - for (int i = 0; i < numSubEdges; i++){ + for(int i = 0; i < numSubEdges; i++) { int nbl = (numSubEdges - i - 1) * 2 + 1; nbt += nbl; - if (nbt > iSubFace){ + if(nbt > iSubFace) { iy = i; ix = nbl - (nbt - iSubFace); break; @@ -241,36 +251,57 @@ static void _myGetFaceRep(MTetrahedron *tet, int num, double *x, double *y, doub SPoint3 pnt1, pnt2, pnt3; double u1, v1, u2, v2, u3, v3; - if (ix % 2 == 0){ - u1 = ix / 2 * d; v1= iy*d; - u2 = (ix / 2 + 1) * d ; v2 = iy * d; - u3 = ix / 2 * d ; v3 = (iy+1) * d; + if(ix % 2 == 0) { + u1 = ix / 2 * d; + v1 = iy * d; + u2 = (ix / 2 + 1) * d; + v2 = iy * d; + u3 = ix / 2 * d; + v3 = (iy + 1) * d; } - else{ - u1 = (ix / 2 + 1) * d; v1= iy * d; - u2 = (ix / 2 + 1) * d; v2= (iy + 1) * d; - u3 = ix / 2 * d ; v3 = (iy + 1) * d; + else { + u1 = (ix / 2 + 1) * d; + v1 = iy * d; + u2 = (ix / 2 + 1) * d; + v2 = (iy + 1) * d; + u3 = ix / 2 * d; + v3 = (iy + 1) * d; } - double U1 = pp[iVertex1][0] * (1.-u1-v1) + pp[iVertex2][0] * u1 + pp[iVertex3][0] * v1; - double U2 = pp[iVertex1][0] * (1.-u2-v2) + pp[iVertex2][0] * u2 + pp[iVertex3][0] * v2; - double U3 = pp[iVertex1][0] * (1.-u3-v3) + pp[iVertex2][0] * u3 + pp[iVertex3][0] * v3; - - double V1 = pp[iVertex1][1] * (1.-u1-v1) + pp[iVertex2][1] * u1 + pp[iVertex3][1] * v1; - double V2 = pp[iVertex1][1] * (1.-u2-v2) + pp[iVertex2][1] * u2 + pp[iVertex3][1] * v2; - double V3 = pp[iVertex1][1] * (1.-u3-v3) + pp[iVertex2][1] * u3 + pp[iVertex3][1] * v3; - - double W1 = pp[iVertex1][2] * (1.-u1-v1) + pp[iVertex2][2] * u1 + pp[iVertex3][2] * v1; - double W2 = pp[iVertex1][2] * (1.-u2-v2) + pp[iVertex2][2] * u2 + pp[iVertex3][2] * v2; - double W3 = pp[iVertex1][2] * (1.-u3-v3) + pp[iVertex2][2] * u3 + pp[iVertex3][2] * v3; + double U1 = pp[iVertex1][0] * (1. - u1 - v1) + pp[iVertex2][0] * u1 + + pp[iVertex3][0] * v1; + double U2 = pp[iVertex1][0] * (1. - u2 - v2) + pp[iVertex2][0] * u2 + + pp[iVertex3][0] * v2; + double U3 = pp[iVertex1][0] * (1. - u3 - v3) + pp[iVertex2][0] * u3 + + pp[iVertex3][0] * v3; + + double V1 = pp[iVertex1][1] * (1. - u1 - v1) + pp[iVertex2][1] * u1 + + pp[iVertex3][1] * v1; + double V2 = pp[iVertex1][1] * (1. - u2 - v2) + pp[iVertex2][1] * u2 + + pp[iVertex3][1] * v2; + double V3 = pp[iVertex1][1] * (1. - u3 - v3) + pp[iVertex2][1] * u3 + + pp[iVertex3][1] * v3; + + double W1 = pp[iVertex1][2] * (1. - u1 - v1) + pp[iVertex2][2] * u1 + + pp[iVertex3][2] * v1; + double W2 = pp[iVertex1][2] * (1. - u2 - v2) + pp[iVertex2][2] * u2 + + pp[iVertex3][2] * v2; + double W3 = pp[iVertex1][2] * (1. - u3 - v3) + pp[iVertex2][2] * u3 + + pp[iVertex3][2] * v3; tet->pnt(U1, V1, W1, pnt1); tet->pnt(U2, V2, W2, pnt2); tet->pnt(U3, V3, W3, pnt3); - x[0] = pnt1.x(); x[1] = pnt2.x(); x[2] = pnt3.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); y[2] = pnt3.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); z[2] = pnt3.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + x[2] = pnt3.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + y[2] = pnt3.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); + z[2] = pnt3.z(); SVector3 d1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); SVector3 d2(x[2] - x[0], y[2] - y[0], z[2] - z[0]); @@ -280,18 +311,22 @@ static void _myGetFaceRep(MTetrahedron *tet, int num, double *x, double *y, doub n[2] = n[0]; } -void MTetrahedronN::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MTetrahedronN::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MTetrahedron::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MTetrahedron::getFaceRep(false, num, x, y, z, n); } -void MTetrahedron10::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MTetrahedron10::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MTetrahedron::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MTetrahedron::getFaceRep(false, num, x, y, z, n); } void MTetrahedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) @@ -300,10 +335,11 @@ void MTetrahedron::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) *pts = getGQTetPts(pOrder); } -bool MTetrahedron::getFaceInfo(const MFace &face, int &ithFace, int &sign, int &rot) const +bool MTetrahedron::getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const { - for (ithFace = 0; ithFace < 4; ithFace++){ - if (_getFaceInfo(getFace(ithFace), face, sign, rot)) return true; + for(ithFace = 0; ithFace < 4; ithFace++) { + if(_getFaceInfo(getFace(ithFace), face, sign, rot)) return true; } Msg::Error("Could not get face information for tetrahedron %d", getNum()); return false; @@ -314,12 +350,12 @@ void _getIndicesReversedTet(int order, IndicesReversed &indices) fullMatrix<double> ref = gmshGenerateMonomialsTetrahedron(order); indices.resize(ref.size1()); - for (int i = 0; i < ref.size1(); ++i) { + for(int i = 0; i < ref.size1(); ++i) { const double u = ref(i, 0); const double v = ref(i, 1); const double w = ref(i, 2); - for (int j = 0; j < ref.size1(); ++j) { - if (u == ref(j, 1) && v == ref(j, 0) && w == ref(j, 2)) { + for(int j = 0; j < ref.size1(); ++j) { + if(u == ref(j, 1) && v == ref(j, 0) && w == ref(j, 2)) { indices[i] = j; break; } @@ -331,7 +367,7 @@ void MTetrahedronN::reverse() { std::map<int, IndicesReversed>::iterator it; it = _order2indicesReversedTet.find(_order); - if (it == _order2indicesReversedTet.end()) { + if(it == _order2indicesReversedTet.end()) { IndicesReversed indices; _getIndicesReversedTet(_order, indices); _order2indicesReversedTet[_order] = indices; @@ -341,15 +377,15 @@ void MTetrahedronN::reverse() IndicesReversed &indices = it->second; // copy vertices - std::vector<MVertex*> oldv(4 + _vs.size()); - std::copy(_v, _v+4, oldv.begin()); - std::copy(_vs.begin(), _vs.end(), oldv.begin()+4); + std::vector<MVertex *> oldv(4 + _vs.size()); + std::copy(_v, _v + 4, oldv.begin()); + std::copy(_vs.begin(), _vs.end(), oldv.begin() + 4); // reverse - for (int i = 0; i < 4; ++i) { + for(int i = 0; i < 4; ++i) { _v[i] = oldv[indices[i]]; } - for (unsigned int i = 0; i < _vs.size(); ++i) { - _vs[i] = oldv[indices[4+i]]; + for(unsigned int i = 0; i < _vs.size(); ++i) { + _vs[i] = oldv[indices[4 + i]]; } } diff --git a/Geo/MTetrahedron.h b/Geo/MTetrahedron.h index 699d18649bf9df09a0e59125fe10d4a53a0a1c58..7ba52dd99af7bcfb2197f009486d375af8821a4e 100644 --- a/Geo/MTetrahedron.h +++ b/Geo/MTetrahedron.h @@ -32,37 +32,42 @@ * */ class MTetrahedron : public MElement { - protected: +protected: MVertex *_v[4]; - void _getEdgeVertices(const int num, std::vector<MVertex*> &v) const + void _getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[edges_tetra(num, 0)]; v[1] = _v[edges_tetra(num, 1)]; } - void _getFaceVertices(const int num, std::vector<MVertex*> &v) const + void _getFaceVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[faces_tetra(num, 0)]; v[1] = _v[faces_tetra(num, 1)]; v[2] = _v[faces_tetra(num, 2)]; } - public : - MTetrahedron(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, int num=0, int part=0) + +public: + MTetrahedron(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, int num = 0, + int part = 0) : MElement(num, part) { - _v[0] = v0; _v[1] = v1; _v[2] = v2; _v[3] = v3; + _v[0] = v0; + _v[1] = v1; + _v[2] = v2; + _v[3] = v3; } - MTetrahedron(const std::vector<MVertex*> &v, int num=0, int part=0) + MTetrahedron(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { for(int i = 0; i < 4; i++) _v[i] = v[i]; } - ~MTetrahedron(){} + ~MTetrahedron() {} virtual int getDim() const { return 3; } virtual std::size_t getNumVertices() const { return 4; } - virtual MVertex *getVertex(int num){ return _v[num]; } + virtual MVertex *getVertex(int num) { return _v[num]; } virtual const MVertex *getVertex(int num) const { return _v[num]; } - virtual void setVertex(int num, MVertex *v){ _v[num] = v; } - virtual int getNumEdges()const{ return 6; } + virtual void setVertex(int num, MVertex *v) { _v[num] = v; } + virtual int getNumEdges() const { return 6; } virtual MEdge getEdge(int num) const { return MEdge(_v[edges_tetra(num, 0)], _v[edges_tetra(num, 1)]); @@ -71,28 +76,30 @@ class MTetrahedron : public MElement { { return edges_tetra(numEdge, numVert); } - virtual int getNumEdgesRep(bool curved){ return 6; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual int getNumEdgesRep(bool curved) { return 6; } + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); _getEdgeVertices(num, v); } - virtual int getNumFaces(){ return 4; } + virtual int getNumFaces() { return 4; } virtual MFace getFace(int num) const { - return MFace(_v[faces_tetra(num, 0)], - _v[faces_tetra(num, 1)], + return MFace(_v[faces_tetra(num, 0)], _v[faces_tetra(num, 1)], _v[faces_tetra(num, 2)]); } - virtual bool getFaceInfo(const MFace & face, int &ithFace, int &sign, int &rot) const; - virtual int getNumFacesRep(bool curved){ return 4; } - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual bool getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const; + virtual int getNumFacesRep(bool curved) { return 4; } + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - _getFaceRep(_v[faces_tetra(num, 0)], _v[faces_tetra(num, 1)], _v[faces_tetra(num, 2)], - x, y, z, n); + _getFaceRep(_v[faces_tetra(num, 0)], _v[faces_tetra(num, 1)], + _v[faces_tetra(num, 2)], x, y, z, n); } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); _getFaceVertices(num, v); @@ -109,7 +116,9 @@ class MTetrahedron : public MElement { virtual const char *getStringForTOCHNOG() const { return "-tet4"; } virtual void reverse() { - MVertex *tmp = _v[0]; _v[0] = _v[1]; _v[1] = tmp; + MVertex *tmp = _v[0]; + _v[0] = _v[1]; + _v[1] = tmp; } void getMat(double mat[3][3]) const { @@ -124,7 +133,7 @@ class MTetrahedron : public MElement { mat[2][2] = _v[3]->z() - _v[0]->z(); } virtual double getVolume(); - virtual int getVolumeSign(){ return (getVolume() >= 0) ? 1 : -1; } + virtual int getVolumeSign() { return (getVolume() >= 0) ? 1 : -1; } virtual double gammaShapeMeasure(); virtual double getInnerRadius(); virtual double getCircumRadius(); @@ -133,17 +142,34 @@ class MTetrahedron : public MElement { virtual void getNode(int num, double &u, double &v, double &w) const { switch(num) { - case 0 : u = 0.; v = 0.; w = 0.; break; - case 1 : u = 1.; v = 0.; w = 0.; break; - case 2 : u = 0.; v = 1.; w = 0.; break; - case 3 : u = 0.; v = 0.; w = 1.; break; - default: u = 0.; v = 0.; w = 0.; break; + case 0: + u = 0.; + v = 0.; + w = 0.; + break; + case 1: + u = 1.; + v = 0.; + w = 0.; + break; + case 2: + u = 0.; + v = 1.; + w = 0.; + break; + case 3: + u = 0.; + v = 0.; + w = 1.; + break; + default: + u = 0.; + v = 0.; + w = 0.; + break; } } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(.25, .25, .25); - } + virtual SPoint3 barycenterUVW() const { return SPoint3(.25, .25, .25); } virtual bool isInside(double u, double v, double w) const { double tol = getTolerance(); @@ -155,24 +181,12 @@ class MTetrahedron : public MElement { virtual SPoint3 circumcenter(); static int edges_tetra(const int edge, const int vert) { - static const int e[6][2] = { - {0, 1}, - {1, 2}, - {2, 0}, - {3, 0}, - {3, 2}, - {3, 1} - }; + static const int e[6][2] = {{0, 1}, {1, 2}, {2, 0}, {3, 0}, {3, 2}, {3, 1}}; return e[edge][vert]; } static int faces_tetra(const int face, const int vert) { - static const int f[4][3] = { - {0, 2, 1}, - {0, 1, 3}, - {0, 3, 2}, - {3, 1, 2} - }; + static const int f[4][3] = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2}, {3, 1, 2}}; return f[face][vert]; } static int faces2edge_tetra(const int face, const int edge) @@ -180,11 +194,7 @@ class MTetrahedron : public MElement { // return -iedge - 1 if edge is inverted // iedge + 1 otherwise static const int e[4][3] = { - {-3, -2, -1}, - { 1, -6, 4}, - {-4, 5, 3}, - { 6, 2, -5} - }; + {-3, -2, -1}, {1, -6, 4}, {-4, 5, 3}, {6, 2, -5}}; return e[face][edge]; } virtual int numCommonNodesInDualGraph(const MElement *const other) const; @@ -208,29 +218,47 @@ class MTetrahedron : public MElement { * */ class MTetrahedron10 : public MTetrahedron { - protected: +protected: MVertex *_vs[6]; - public : - MTetrahedron10(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, - MVertex *v5, MVertex *v6, MVertex *v7, MVertex *v8, MVertex *v9, - int num=0, int part=0) + +public: + MTetrahedron10(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, + MVertex *v4, MVertex *v5, MVertex *v6, MVertex *v7, + MVertex *v8, MVertex *v9, int num = 0, int part = 0) : MTetrahedron(v0, v1, v2, v3, num, part) { - _vs[0] = v4; _vs[1] = v5; _vs[2] = v6; _vs[3] = v7; _vs[4] = v8; _vs[5] = v9; + _vs[0] = v4; + _vs[1] = v5; + _vs[2] = v6; + _vs[3] = v7; + _vs[4] = v8; + _vs[5] = v9; for(int i = 0; i < 6; i++) _vs[i]->setPolynomialOrder(2); } - MTetrahedron10(const std::vector<MVertex*> &v, int num=0, int part=0) + MTetrahedron10(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MTetrahedron(v, num, part) { for(int i = 0; i < 6; i++) _vs[i] = v[4 + i]; for(int i = 0; i < 6; i++) _vs[i]->setPolynomialOrder(2); } - ~MTetrahedron10(){} + ~MTetrahedron10() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 10; } - virtual MVertex *getVertex(int num){ return num < 4 ? _v[num] : _vs[num - 4]; } - virtual const MVertex *getVertex(int num) const { return num < 4 ? _v[num] : _vs[num - 4]; } - virtual void setVertex(int num, MVertex *v){ if(num < 4) _v[num] = v; else _vs[num - 4] = v; } + virtual MVertex *getVertex(int num) + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 4) + _v[num] = v; + else + _vs[num - 4] = v; + } virtual MVertex *getVertexUNV(int num) { static const int map[10] = {0, 4, 1, 5, 2, 6, 7, 9, 8, 3}; @@ -246,36 +274,36 @@ class MTetrahedron10 : public MTetrahedron { static const int map[10] = {0, 1, 2, 3, 4, 5, 6, 7, 9, 8}; return getVertex(map[num]); } - virtual MVertex *getVertexDIFF(int num){ return getVertexBDF(num); } - virtual MVertex *getVertexINP(int num){ return getVertexBDF(num); } - virtual MVertex *getVertexKEY(int num){ return getVertexBDF(num); } + virtual MVertex *getVertexDIFF(int num) { return getVertexBDF(num); } + virtual MVertex *getVertexINP(int num) { return getVertexBDF(num); } + virtual MVertex *getVertexKEY(int num) { return getVertexBDF(num); } virtual int getNumEdgeVertices() const { return 6; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); virtual int getNumEdgesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); virtual int getNumFacesRep(bool curved); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MTetrahedron::_getEdgeVertices(num, v); v[2] = _vs[num]; } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(6); MTetrahedron::_getFaceVertices(num, v); - static const int f[4][3] = { - {2, 1, 0}, - {0, 5, 3}, - {3, 4, 2}, - {5, 1, 4} - }; + static const int f[4][3] = {{2, 1, 0}, {0, 5, 3}, {3, 4, 2}, {5, 1, 4}}; v[3] = _vs[f[num][0]]; v[4] = _vs[f[num][1]]; v[5] = _vs[f[num][2]]; } virtual int getTypeForMSH() const { return MSH_TET_10; } - virtual int getTypeForUNV() const { return 118; } // solid parabolic tetrahedron + virtual int getTypeForUNV() const + { + return 118; + } // solid parabolic tetrahedron virtual int getTypeForVTK() const { return 24; } virtual const char *getStringForPOS() const { return "SS2"; } virtual const char *getStringForBDF() const { return "CTETRA"; } @@ -286,17 +314,24 @@ class MTetrahedron10 : public MTetrahedron { virtual void reverse() { MVertex *tmp; - tmp = _v[0] ; _v[0] = _v[1]; _v[1] = tmp; - tmp = _vs[1]; _vs[1] = _vs[2]; _vs[2] = tmp; - tmp = _vs[5]; _vs[5] = _vs[3]; _vs[3] = tmp; + tmp = _v[0]; + _v[0] = _v[1]; + _v[1] = tmp; + tmp = _vs[1]; + _vs[1] = _vs[2]; + _vs[2] = tmp; + tmp = _vs[5]; + _vs[5] = _vs[3]; + _vs[3] = tmp; } virtual void getNode(int num, double &u, double &v, double &w) const { - num < 4 ? MTetrahedron::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); + num < 4 ? MTetrahedron::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } void xyz2uvw(double xyz[3], double uvw[3]) const { - return MElement::xyz2uvw(xyz,uvw); + return MElement::xyz2uvw(xyz, uvw); } }; @@ -322,78 +357,95 @@ typedef std::vector<int> IndicesReversed; class MTetrahedronN : public MTetrahedron { static std::map<int, IndicesReversed> _order2indicesReversedTet; - protected: +protected: std::vector<MVertex *> _vs; const char _order; - public: + +public: MTetrahedronN(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, - const std::vector<MVertex*> &v, char order, int num=0, int part=0) - : MTetrahedron(v0, v1, v2, v3, num, part) , _vs (v), _order(order) + const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) + : MTetrahedron(v0, v1, v2, v3, num, part), _vs(v), _order(order) { - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); } - MTetrahedronN(const std::vector<MVertex*> &v, char order, int num=0, int part=0) - : MTetrahedron(v[0], v[1], v[2], v[3], num, part) , _order(order) + MTetrahedronN(const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) + : MTetrahedron(v[0], v[1], v[2], v[3], num, part), _order(order) { for(unsigned int i = 4; i < v.size(); i++) _vs.push_back(v[i]); - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); } - ~MTetrahedronN(){} + ~MTetrahedronN() {} virtual int getPolynomialOrder() const { return _order; } virtual std::size_t getNumVertices() const { return 4 + _vs.size(); } - virtual MVertex *getVertex(int num){ return num < 4 ? _v[num] : _vs[num - 4]; } - virtual const MVertex *getVertex(int num) const{ return num < 4 ? _v[num] : _vs[num - 4]; } - virtual void setVertex(int num, MVertex *v){ if(num < 4) _v[num] = v; else _vs[num - 4] = v; } + virtual MVertex *getVertex(int num) + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 4 ? _v[num] : _vs[num - 4]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 4) + _v[num] = v; + else + _vs[num - 4] = v; + } virtual int getNumEdgeVertices() const { return 6 * (_order - 1); } virtual int getNumFaceVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; else - return 4 * ((_order - 1) * (_order - 2)) / 2; + return 4 * ((_order - 1) * (_order - 2)) / 2; } - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(_order + 1); MTetrahedron::_getEdgeVertices(num, v); int j = 2; - const int ie = (num + 1) * (_order -1); - for(int i = num * (_order -1); i != ie; ++i) v[j++] = _vs[i]; + const int ie = (num + 1) * (_order - 1); + for(int i = num * (_order - 1); i != ie; ++i) v[j++] = _vs[i]; } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { - if (getIsAssimilatedSerendipity()) { + if(getIsAssimilatedSerendipity()) { v.resize(3 * _order); } else { - v.resize((_order+1) * (_order+2) / 2); + v.resize((_order + 1) * (_order + 2) / 2); } MTetrahedron::_getFaceVertices(num, v); int count = 2; int n = _order - 1; - for (int i = 0; i < 3; i++) { - if(faces2edge_tetra(num, i) > 0){ + for(int i = 0; i < 3; i++) { + if(faces2edge_tetra(num, i) > 0) { int edge_num = faces2edge_tetra(num, i) - 1; - for (int j = 0; j < n; j++) v[++count] = _vs[n*edge_num + j]; + for(int j = 0; j < n; j++) v[++count] = _vs[n * edge_num + j]; } - else{ + else { int edge_num = -faces2edge_tetra(num, i) - 1; - for (int j = n-1; j >= 0; j--) v[++count] = _vs[n*edge_num + j]; + for(int j = n - 1; j >= 0; j--) v[++count] = _vs[n * edge_num + j]; } } - if ((int)v.size() > count + 1) { - int start = 6 * n + num * (n-1)*n/2; - for (int i = 0; i < (n-1)*n/2; i++){ + if((int)v.size() > count + 1) { + int start = 6 * n + num * (n - 1) * n / 2; + for(int i = 0; i < (n - 1) * n / 2; i++) { v[++count] = _vs[start + i]; } } } virtual int getNumVolumeVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; else return ((_order - 1) * (_order - 2) * (_order - 3)) / 6; @@ -401,7 +453,7 @@ class MTetrahedronN : public MTetrahedron { virtual int getTypeForMSH() const { // (p+1)*(p+2)*(p+3)/6 - if(_order == 1 && _vs.size() + 4 == 4) return MSH_TET_4; + if(_order == 1 && _vs.size() + 4 == 4) return MSH_TET_4; if(_order == 2 && _vs.size() + 4 == 10) return MSH_TET_10; if(_order == 3 && _vs.size() + 4 == 20) return MSH_TET_20; if(_order == 4 && _vs.size() + 4 == 35) return MSH_TET_35; @@ -420,21 +472,25 @@ class MTetrahedronN : public MTetrahedron { if(_order == 8 && _vs.size() + 4 == 46) return MSH_TET_46; if(_order == 9 && _vs.size() + 4 == 52) return MSH_TET_52; if(_order == 10 && _vs.size() + 4 == 58) return MSH_TET_58; - Msg::Error("no tag matches a p%d tetrahedron with %d vertices", _order, 4+_vs.size()); + Msg::Error("no tag matches a p%d tetrahedron with %d vertices", _order, + 4 + _vs.size()); return 0; } virtual void reverse(); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); virtual int getNumEdgesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); virtual int getNumFacesRep(bool curved); virtual void getNode(int num, double &u, double &v, double &w) const { - num < 4 ? MTetrahedron::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); + num < 4 ? MTetrahedron::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } void xyz2uvw(double xyz[3], double uvw[3]) const { - return MElement::xyz2uvw(xyz,uvw); + return MElement::xyz2uvw(xyz, uvw); } }; diff --git a/Geo/MTriangle.cpp b/Geo/MTriangle.cpp index a8feb1feddd11d587240f22aeeab9e441f666c69..2220fe0804cf7277d10976a7dfe69b4e9155b696 100644 --- a/Geo/MTriangle.cpp +++ b/Geo/MTriangle.cpp @@ -18,17 +18,21 @@ #include <cmath> #include <cstring> -void MTriangle::getEdgeRep(bool curved, int num, double *x, double *y, double *z, - SVector3 *n) +void MTriangle::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { // don't use MElement::_getEdgeRep: it's slow due to the creation of MFace // could speed this up by computing and storing the normal only if num==0; we // always call getEdgeRep in sequence MVertex *v0 = _v[edges_tri(num, 0)]; MVertex *v1 = _v[edges_tri(num, 1)]; - x[0] = v0->x(); y[0] = v0->y(); z[0] = v0->z(); - x[1] = v1->x(); y[1] = v1->y(); z[1] = v1->z(); - if(CTX::instance()->mesh.lightLines){ + x[0] = v0->x(); + y[0] = v0->y(); + z[0] = v0->z(); + x[1] = v1->x(); + y[1] = v1->y(); + z[1] = v1->z(); + if(CTX::instance()->mesh.lightLines) { static const int vv[3] = {2, 0, 1}; MVertex *v2 = _v[vv[num]]; SVector3 t1(x[1] - x[0], y[1] - y[0], z[1] - z[0]); @@ -37,7 +41,7 @@ void MTriangle::getEdgeRep(bool curved, int num, double *x, double *y, double *z normal.normalize(); n[0] = n[1] = normal; } - else{ + else { n[0] = n[1] = SVector3(0., 0., 1.); } } @@ -54,8 +58,7 @@ SPoint3 MTriangle::circumcenter() double MTriangle::getVolume() { - if(getNumVertices() > 3) - return MElement::getVolume(); + if(getNumVertices() > 3) return MElement::getVolume(); SPoint3 p0(_v[0]->x(), _v[0]->y(), _v[0]->z()); SPoint3 p1(_v[1]->x(), _v[1]->y(), _v[1]->z()); SPoint3 p2(_v[2]->x(), _v[2]->y(), _v[2]->z()); @@ -67,26 +70,28 @@ double MTriangle::getInnerRadius() { // radius of inscribed circle = 2 * Area / sum(Line_i) double dist[3], k = 0.; - for (int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { MEdge e = getEdge(i); dist[i] = e.getVertex(0)->distance(e.getVertex(1)); k += 0.5 * dist[i]; } - double const area = std::sqrt(k*(k-dist[0])*(k-dist[1])*(k-dist[2])); - return area/k; + double const area = + std::sqrt(k * (k - dist[0]) * (k - dist[1]) * (k - dist[2])); + return area / k; } double MTriangle::getOuterRadius() { // radius of circle circumscribing a triangle double dist[3], k = 0.0; - for (int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { MEdge e = getEdge(i); dist[i] = e.getVertex(0)->distance(e.getVertex(1)); k += 0.5 * dist[i]; } - double const area = std::sqrt(k*(k-dist[0])*(k-dist[1])*(k-dist[2])); - return dist[0]*dist[1]*dist[2]/(4*area); + double const area = + std::sqrt(k * (k - dist[0]) * (k - dist[1]) * (k - dist[2])); + return dist[0] * dist[1] * dist[2] / (4 * area); } double MTriangle::angleShapeMeasure() @@ -107,7 +112,6 @@ double MTriangle::etaShapeMeasure() #endif } - double MTriangle::gammaShapeMeasure() { #if defined(HAVE_MESH) @@ -135,22 +139,24 @@ void MTriangle::xyz2uvw(double xyz[3], double uvw[3]) const const double O[3] = {_v[0]->x(), _v[0]->y(), _v[0]->z()}; const double d[3] = {xyz[0] - O[0], xyz[1] - O[1], xyz[2] - O[2]}; - const double d1[3] = {_v[1]->x() - O[0], _v[1]->y() - O[1], _v[1]->z() - O[2]}; - const double d2[3] = {_v[2]->x() - O[0], _v[2]->y() - O[1], _v[2]->z() - O[2]}; + const double d1[3] = {_v[1]->x() - O[0], _v[1]->y() - O[1], + _v[1]->z() - O[2]}; + const double d2[3] = {_v[2]->x() - O[0], _v[2]->y() - O[1], + _v[2]->z() - O[2]}; const double Jxy = d1[0] * d2[1] - d1[1] * d2[0]; const double Jxz = d1[0] * d2[2] - d1[2] * d2[0]; const double Jyz = d1[1] * d2[2] - d1[2] * d2[1]; - if ((std::abs(Jxy) > std::abs(Jxz)) && (std::abs(Jxy) > std::abs(Jyz))){ + if((std::abs(Jxy) > std::abs(Jxz)) && (std::abs(Jxy) > std::abs(Jyz))) { uvw[0] = (d[0] * d2[1] - d[1] * d2[0]) / Jxy; uvw[1] = (d[1] * d1[0] - d[0] * d1[1]) / Jxy; } - else if (std::abs(Jxz) > std::abs(Jyz)){ + else if(std::abs(Jxz) > std::abs(Jyz)) { uvw[0] = (d[0] * d2[2] - d[2] * d2[0]) / Jxz; uvw[1] = (d[2] * d1[0] - d[0] * d1[2]) / Jxz; } - else{ + else { uvw[0] = (d[1] * d2[2] - d[2] * d2[1]) / Jyz; uvw[1] = (d[2] * d1[1] - d[1] * d1[2]) / Jyz; } @@ -159,79 +165,93 @@ void MTriangle::xyz2uvw(double xyz[3], double uvw[3]) const int MTriangle::numCommonNodesInDualGraph(const MElement *const other) const { - switch (other->getType()) - { - case TYPE_PNT: return 1; - case TYPE_LIN: return 2; - case TYPE_TRI: return 2; - case TYPE_QUA: return 2; - default: return 3; + switch(other->getType()) { + case TYPE_PNT: return 1; + case TYPE_LIN: return 2; + case TYPE_TRI: return 2; + case TYPE_QUA: return 2; + default: return 3; } } -int MTriangleN::getNumEdgesRep(bool curved) { +int MTriangleN::getNumEdgesRep(bool curved) +{ return curved ? 3 * CTX::instance()->mesh.numSubEdges : 3; } -int MTriangle6::getNumEdgesRep(bool curved) { +int MTriangle6::getNumEdgesRep(bool curved) +{ return curved ? 3 * CTX::instance()->mesh.numSubEdges : 3; } -static void _myGetEdgeRep(MTriangle *t, int num, double *x, double *y, double *z, - SVector3 *n, int numSubEdges) +static void _myGetEdgeRep(MTriangle *t, int num, double *x, double *y, + double *z, SVector3 *n, int numSubEdges) { n[0] = n[1] = t->getFace(0).normal(); - if (num < numSubEdges){ + if(num < numSubEdges) { SPoint3 pnt1, pnt2; - t->pnt((double)num / numSubEdges, 0., 0.,pnt1); + t->pnt((double)num / numSubEdges, 0., 0., pnt1); t->pnt((double)(num + 1) / numSubEdges, 0., 0, pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); return; } - if (num < 2 * numSubEdges){ + if(num < 2 * numSubEdges) { SPoint3 pnt1, pnt2; num -= numSubEdges; t->pnt(1. - (double)num / numSubEdges, (double)num / numSubEdges, 0, pnt1); - t->pnt(1. - (double)(num + 1) / numSubEdges, (double)(num + 1) / numSubEdges, 0, pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); - return ; + t->pnt(1. - (double)(num + 1) / numSubEdges, + (double)(num + 1) / numSubEdges, 0, pnt2); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); + return; } { SPoint3 pnt1, pnt2; num -= 2 * numSubEdges; - t->pnt(0, (double)num / numSubEdges, 0,pnt1); - t->pnt(0, (double)(num + 1) / numSubEdges, 0,pnt2); - x[0] = pnt1.x(); x[1] = pnt2.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); + t->pnt(0, (double)num / numSubEdges, 0, pnt1); + t->pnt(0, (double)(num + 1) / numSubEdges, 0, pnt2); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); } } -void MTriangleN::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MTriangleN::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MTriangle::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MTriangle::getEdgeRep(false, num, x, y, z, n); } -void MTriangle6::getEdgeRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MTriangle6::getEdgeRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MTriangle::getEdgeRep(false, num, x, y, z, n); + if(curved) + _myGetEdgeRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MTriangle::getEdgeRep(false, num, x, y, z, n); } -bool MTriangle::getFaceInfo(const MFace & face, int &ithFace, int &sign, +bool MTriangle::getFaceInfo(const MFace &face, int &ithFace, int &sign, int &rot) const { ithFace = 0; - if (_getFaceInfo(MFace(_v[0], _v[1], _v[2]), face, sign, rot)) - return true; + if(_getFaceInfo(MFace(_v[0], _v[1], _v[2]), face, sign, rot)) return true; Msg::Error("Could not get face information for triangle %d", getNum()); return false; } @@ -245,18 +265,18 @@ int MTriangleN::getNumFacesRep(bool curved) return curved ? std::pow(CTX::instance()->mesh.numSubEdges, 2) : 1; } -static void _myGetFaceRep(MTriangle *t, int num, double *x, double *y, double *z, - SVector3 *n, int numSubEdges) +static void _myGetFaceRep(MTriangle *t, int num, double *x, double *y, + double *z, SVector3 *n, int numSubEdges) { // on the first layer, we have (numSubEdges-1) * 2 + 1 triangles // on the second layer, we have (numSubEdges-2) * 2 + 1 triangles // on the ith layer, we have (numSubEdges-1-i) * 2 + 1 triangles int ix = 0, iy = 0; int nbt = 0; - for (int i = 0; i < numSubEdges; i++){ + for(int i = 0; i < numSubEdges; i++) { int nbl = (numSubEdges - i - 1) * 2 + 1; nbt += nbl; - if (nbt > num){ + if(nbt > num) { iy = i; ix = nbl - (nbt - num); break; @@ -267,7 +287,7 @@ static void _myGetFaceRep(MTriangle *t, int num, double *x, double *y, double *z SPoint3 pnt1, pnt2, pnt3; double J1[3][3], J2[3][3], J3[3][3]; - if (ix % 2 == 0){ + if(ix % 2 == 0) { t->pnt(ix / 2 * d, iy * d, 0, pnt1); t->pnt((ix / 2 + 1) * d, iy * d, 0, pnt2); t->pnt(ix / 2 * d, (iy + 1) * d, 0, pnt3); @@ -275,7 +295,7 @@ static void _myGetFaceRep(MTriangle *t, int num, double *x, double *y, double *z t->getJacobian((ix / 2 + 1) * d, iy * d, 0, J2); t->getJacobian(ix / 2 * d, (iy + 1) * d, 0, J3); } - else{ + else { t->pnt((ix / 2 + 1) * d, iy * d, 0, pnt1); t->pnt((ix / 2 + 1) * d, (iy + 1) * d, 0, pnt2); t->pnt(ix / 2 * d, (iy + 1) * d, 0, pnt3); @@ -302,23 +322,33 @@ static void _myGetFaceRep(MTriangle *t, int num, double *x, double *y, double *z n[2].normalize(); } - x[0] = pnt1.x(); x[1] = pnt2.x(); x[2] = pnt3.x(); - y[0] = pnt1.y(); y[1] = pnt2.y(); y[2] = pnt3.y(); - z[0] = pnt1.z(); z[1] = pnt2.z(); z[2] = pnt3.z(); + x[0] = pnt1.x(); + x[1] = pnt2.x(); + x[2] = pnt3.x(); + y[0] = pnt1.y(); + y[1] = pnt2.y(); + y[2] = pnt3.y(); + z[0] = pnt1.z(); + z[1] = pnt2.z(); + z[2] = pnt3.z(); } -void MTriangleN::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MTriangleN::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MTriangle::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MTriangle::getFaceRep(false, num, x, y, z, n); } -void MTriangle6::getFaceRep(bool curved, int num, - double *x, double *y, double *z, SVector3 *n) +void MTriangle6::getFaceRep(bool curved, int num, double *x, double *y, + double *z, SVector3 *n) { - if (curved) _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); - else MTriangle::getFaceRep(false, num, x, y, z, n); + if(curved) + _myGetFaceRep(this, num, x, y, z, n, CTX::instance()->mesh.numSubEdges); + else + MTriangle::getFaceRep(false, num, x, y, z, n); } void MTriangle::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) @@ -330,84 +360,100 @@ void MTriangle::getIntegrationPoints(int pOrder, int *npts, IntPt **pts) void MTriangleN::reverse() { MVertex *tmp; - tmp = _v[1]; _v[1] = _v[2]; _v[2] = tmp; + tmp = _v[1]; + _v[1] = _v[2]; + _v[2] = tmp; - int npts = _order-1, base = 0; - std::vector<MVertex*>::iterator begin = _vs.begin() + base; + int npts = _order - 1, base = 0; + std::vector<MVertex *>::iterator begin = _vs.begin() + base; - while (npts > 0) { + while(npts > 0) { std::reverse(begin, begin + 3 * npts); base += 3 * npts; - if (npts > 2) { - tmp = _vs[base+1]; _vs[base+1] = _vs[base+2]; _vs[base+2] = tmp; + if(npts > 2) { + tmp = _vs[base + 1]; + _vs[base + 1] = _vs[base + 2]; + _vs[base + 2] = tmp; } npts -= 3; begin = _vs.begin() + base + 3; } } -void MTriangle::reorient(int rot,bool swap) +void MTriangle::reorient(int rot, bool swap) { - if (rot == 0 && !swap) return; - - MVertex* tmp[3]; - std::memcpy(tmp,_v,3*sizeof(MVertex*)); - if (swap) for (int i=0;i<3;i++) _v[i] = tmp[(3-i+rot)%3]; - else for (int i=0;i<3;i++) _v[i] = tmp[(3+i-rot)%3]; + if(rot == 0 && !swap) return; + + MVertex *tmp[3]; + std::memcpy(tmp, _v, 3 * sizeof(MVertex *)); + if(swap) + for(int i = 0; i < 3; i++) _v[i] = tmp[(3 - i + rot) % 3]; + else + for(int i = 0; i < 3; i++) _v[i] = tmp[(3 + i - rot) % 3]; } void MTriangle6::reorient(int rot, bool swap) { - if (rot == 0 && !swap) return; - - MTriangle::reorient(rot,swap); - MVertex* tmp[3]; - std::memcpy(tmp,_vs,3*sizeof(MVertex*)); - if (swap) for (int i=0;i<3;i++) _vs[i] = tmp[(5+rot-i)%3]; - else for (int i=0;i<3;i++) _vs[i] = tmp[(3-rot+i)%3]; + if(rot == 0 && !swap) return; + + MTriangle::reorient(rot, swap); + MVertex *tmp[3]; + std::memcpy(tmp, _vs, 3 * sizeof(MVertex *)); + if(swap) + for(int i = 0; i < 3; i++) _vs[i] = tmp[(5 + rot - i) % 3]; + else + for(int i = 0; i < 3; i++) _vs[i] = tmp[(3 - rot + i) % 3]; } -std::map<TupleReorientation, IndicesReoriented> MTriangleN::_tuple2indicesReoriented; +std::map<TupleReorientation, IndicesReoriented> + MTriangleN::_tuple2indicesReoriented; -namespace -{ +namespace { void _getIndicesReorientedTri(int order, int rot, bool swap, IndicesReoriented &indices) { fullMatrix<double> ref = gmshGenerateMonomialsTriangle(order); indices.resize(ref.size1()); - for (int i = 0; i < ref.size1(); ++i) { + for(int i = 0; i < ref.size1(); ++i) { double u = ref(i, 0); double v = ref(i, 1); double tmp; - if (swap) { + if(swap) { tmp = u; u = v; v = tmp; } - switch (rot) { - case 1: tmp = u; u = order - u - v; v = tmp; break; - case 2: tmp = v; v = order - u - v; u = tmp; break; + switch(rot) { + case 1: + tmp = u; + u = order - u - v; + v = tmp; + break; + case 2: + tmp = v; + v = order - u - v; + u = tmp; + break; } - for (int j = 0; j < ref.size1(); ++j) { - if (u == ref(j, 0) && v == ref(j, 1)) { + for(int j = 0; j < ref.size1(); ++j) { + if(u == ref(j, 0) && v == ref(j, 1)) { indices[i] = j; break; } } } } -} +} // namespace void MTriangleN::reorient(int rot, bool swap) { - if (rot == 0 && !swap) return; + if(rot == 0 && !swap) return; TupleReorientation mytuple(getTypeForMSH(), std::make_pair(rot, swap)); std::map<TupleReorientation, IndicesReoriented>::iterator it; it = _tuple2indicesReoriented.find(mytuple); - if (it == _tuple2indicesReoriented.end()) { + if(it == _tuple2indicesReoriented.end()) { IndicesReoriented indices; _getIndicesReorientedTri(_order, rot, swap, indices); _tuple2indicesReoriented[mytuple] = indices; @@ -417,26 +463,28 @@ void MTriangleN::reorient(int rot, bool swap) IndicesReoriented &indices = it->second; // copy vertices - std::vector<MVertex*> oldv(3 + _vs.size()); - std::copy(_v, _v+3, oldv.begin()); - std::copy(_vs.begin(), _vs.end(), oldv.begin()+3); + std::vector<MVertex *> oldv(3 + _vs.size()); + std::copy(_v, _v + 3, oldv.begin()); + std::copy(_vs.begin(), _vs.end(), oldv.begin() + 3); // reorient - for (int i = 0; i < 3; ++i) { + for(int i = 0; i < 3; ++i) { _v[i] = oldv[indices[i]]; } - for (unsigned int i = 0; i < _vs.size(); ++i) { - _vs[i] = oldv[indices[3+i]]; + for(unsigned int i = 0; i < _vs.size(); ++i) { + _vs[i] = oldv[indices[3 + i]]; } } MFaceN MTriangle::getHighOrderFace(int num, int sign, int rot) { const bool swap = sign == -1; - std::vector<MVertex*> vertices(getNumVertices()); + std::vector<MVertex *> vertices(getNumVertices()); - if (swap) for (int i=0;i<3;i++) vertices[i] = _v[(3-i+rot)%3]; - else for (int i=0;i<3;i++) vertices[i] = _v[(3+i-rot)%3]; + if(swap) + for(int i = 0; i < 3; i++) vertices[i] = _v[(3 - i + rot) % 3]; + else + for(int i = 0; i < 3; i++) vertices[i] = _v[(3 + i - rot) % 3]; return MFaceN(TYPE_TRI, 1, vertices); } @@ -444,18 +492,18 @@ MFaceN MTriangle::getHighOrderFace(int num, int sign, int rot) MFaceN MTriangle6::getHighOrderFace(int num, int sign, int rot) { const bool swap = sign == -1; - std::vector<MVertex*> vertices(getNumVertices()); + std::vector<MVertex *> vertices(getNumVertices()); - if (swap) { - for (int i=0;i<3;i++) { - vertices[i] = _v[(3-i+rot)%3]; - vertices[3+i] = _vs[(5-i+rot)%3]; + if(swap) { + for(int i = 0; i < 3; i++) { + vertices[i] = _v[(3 - i + rot) % 3]; + vertices[3 + i] = _vs[(5 - i + rot) % 3]; } } else { - for (int i=0;i<3;i++) { - vertices[i] = _v[(3+i-rot)%3]; - vertices[3+i] = _vs[(3+i-rot)%3]; + for(int i = 0; i < 3; i++) { + vertices[i] = _v[(3 + i - rot) % 3]; + vertices[3 + i] = _vs[(3 + i - rot) % 3]; } } return MFaceN(TYPE_TRI, 2, vertices); @@ -468,7 +516,7 @@ MFaceN MTriangleN::getHighOrderFace(int num, int sign, int rot) TupleReorientation mytuple(TYPE_TRI, std::make_pair(rot, swap)); std::map<TupleReorientation, IndicesReoriented>::iterator it; it = _tuple2indicesReoriented.find(mytuple); - if (it == _tuple2indicesReoriented.end()) { + if(it == _tuple2indicesReoriented.end()) { IndicesReoriented indices; _getIndicesReorientedTri(_order, rot, swap, indices); _tuple2indicesReoriented[mytuple] = indices; @@ -477,8 +525,8 @@ MFaceN MTriangleN::getHighOrderFace(int num, int sign, int rot) IndicesReoriented &indices = it->second; - std::vector<MVertex*> vertices(getNumVertices()); - for (std::size_t i = 0; i < getNumVertices(); ++i) { + std::vector<MVertex *> vertices(getNumVertices()); + for(std::size_t i = 0; i < getNumVertices(); ++i) { vertices[i] = getVertex(indices[i]); } return MFaceN(TYPE_TRI, _order, vertices); diff --git a/Geo/MTriangle.h b/Geo/MTriangle.h index 071496d01a8260b6e575f2d366215f67bb266741..729022225499929cab51695864df97c39462266c 100644 --- a/Geo/MTriangle.h +++ b/Geo/MTriangle.h @@ -24,31 +24,34 @@ * */ class MTriangle : public MElement { - protected: +protected: MVertex *_v[3]; - void _getEdgeVertices(const int num, std::vector<MVertex*> &v) const + void _getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[edges_tri(num, 0)]; v[1] = _v[edges_tri(num, 1)]; } - void _getFaceVertices(std::vector<MVertex*> &v) const + void _getFaceVertices(std::vector<MVertex *> &v) const { v[0] = _v[0]; v[1] = _v[1]; v[2] = _v[2]; } - public : - MTriangle(MVertex *v0, MVertex *v1, MVertex *v2, int num=0, int part=0) + +public: + MTriangle(MVertex *v0, MVertex *v1, MVertex *v2, int num = 0, int part = 0) : MElement(num, part) { - _v[0] = v0; _v[1] = v1; _v[2] = v2; + _v[0] = v0; + _v[1] = v1; + _v[2] = v2; } - MTriangle(const std::vector<MVertex*> &v, int num=0, int part=0) + MTriangle(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { for(int i = 0; i < 3; i++) _v[i] = v[i]; } - ~MTriangle(){} + ~MTriangle() {} virtual int getDim() const { return 2; } virtual double etaShapeMeasure(); virtual double gammaShapeMeasure(); @@ -56,9 +59,9 @@ class MTriangle : public MElement { virtual double getOuterRadius(); virtual double angleShapeMeasure(); virtual std::size_t getNumVertices() const { return 3; } - virtual MVertex *getVertex(int num){ return _v[num]; } + virtual MVertex *getVertex(int num) { return _v[num]; } virtual const MVertex *getVertex(int num) const { return _v[num]; } - virtual void setVertex(int num, MVertex *v){ _v[num] = v; } + virtual void setVertex(int num, MVertex *v) { _v[num] = v; } virtual void xyz2uvw(double xyz[3], double uvw[3]) const; virtual MVertex *getOtherVertex(MVertex *v1, MVertex *v2) { @@ -67,7 +70,7 @@ class MTriangle : public MElement { if(_v[2] != v1 && _v[2] != v2) return _v[2]; return 0; } - virtual int getNumEdges()const{ return 3; } + virtual int getNumEdges() const { return 3; } virtual MEdge getEdge(int num) const { return MEdge(_v[edges_tri(num, 0)], _v[edges_tri(num, 1)]); @@ -76,26 +79,26 @@ class MTriangle : public MElement { { return edges_tri(numEdge, numVert); } - virtual int getNumEdgesRep(bool curved){ return 3; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual int getNumEdgesRep(bool curved) { return 3; } + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); _getEdgeVertices(num, v); } - virtual int getNumFaces(){ return 1; } - virtual MFace getFace(int num) const - { - return MFace(_v[0], _v[1], _v[2]); - } - virtual bool getFaceInfo(const MFace & face, int &ithFace, int &sign, int &rot) const; + virtual int getNumFaces() { return 1; } + virtual MFace getFace(int num) const { return MFace(_v[0], _v[1], _v[2]); } + virtual bool getFaceInfo(const MFace &face, int &ithFace, int &sign, + int &rot) const; virtual MFaceN getHighOrderFace(int num, int sign, int rot); - virtual int getNumFacesRep(bool curved){ return 1; } - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual int getNumFacesRep(bool curved) { return 1; } + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { _getFaceRep(_v[0], _v[1], _v[2], x, y, z, n); } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); _getFaceVertices(v); @@ -107,12 +110,17 @@ class MTriangle : public MElement { virtual const char *getStringForPOS() const { return "ST"; } virtual const char *getStringForBDF() const { return "CTRIA3"; } virtual const char *getStringForDIFF() const { return "ElmT3n2D"; } - virtual const char *getStringForINP() const { return "CPS3"/*"STRI3"*//*"C2D3"*/; } + virtual const char *getStringForINP() const + { + return "CPS3" /*"STRI3"*/ /*"C2D3"*/; + } virtual const char *getStringForKEY() const { return "_SHELL"; } virtual const char *getStringForTOCHNOG() const { return "-tria3"; } virtual void reverse() { - MVertex *tmp = _v[1]; _v[1] = _v[2]; _v[2] = tmp; + MVertex *tmp = _v[1]; + _v[1] = _v[2]; + _v[2] = tmp; } // reorient the triangle to conform with other face @@ -124,16 +132,25 @@ class MTriangle : public MElement { { w = 0.; switch(num) { - case 0 : u = 0.; v = 0.; break; - case 1 : u = 1.; v = 0.; break; - case 2 : u = 0.; v = 1.; break; - default: u = 0.; v = 0.; break; + case 0: + u = 0.; + v = 0.; + break; + case 1: + u = 1.; + v = 0.; + break; + case 2: + u = 0.; + v = 1.; + break; + default: + u = 0.; + v = 0.; + break; } } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(1/3., 1/3., 0.); - } + virtual SPoint3 barycenterUVW() const { return SPoint3(1 / 3., 1 / 3., 0.); } virtual bool isInside(double u, double v, double w) const { double tol = getTolerance(); @@ -146,11 +163,7 @@ class MTriangle : public MElement { virtual double getVolume(); static int edges_tri(const int edge, const int vert) { - static const int e[3][2] = { - {0, 1}, - {1, 2}, - {2, 0} - }; + static const int e[3][2] = {{0, 1}, {1, 2}, {2, 0}}; return e[edge][vert]; } virtual int numCommonNodesInDualGraph(const MElement *const other) const; @@ -169,38 +182,57 @@ class MTriangle : public MElement { * */ class MTriangle6 : public MTriangle { - protected: +protected: MVertex *_vs[3]; - public : + +public: MTriangle6(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, MVertex *v4, - MVertex *v5, int num=0, int part=0) + MVertex *v5, int num = 0, int part = 0) : MTriangle(v0, v1, v2, num, part) { - _vs[0] = v3; _vs[1] = v4; _vs[2] = v5; + _vs[0] = v3; + _vs[1] = v4; + _vs[2] = v5; for(int i = 0; i < 3; i++) _vs[i]->setPolynomialOrder(2); } - MTriangle6(const std::vector<MVertex*> &v, int num=0, int part=0) + MTriangle6(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MTriangle(v, num, part) { for(int i = 0; i < 3; i++) _vs[i] = v[3 + i]; for(int i = 0; i < 3; i++) _vs[i]->setPolynomialOrder(2); } - ~MTriangle6(){} + ~MTriangle6() {} virtual int getPolynomialOrder() const { return 2; } virtual std::size_t getNumVertices() const { return 6; } - virtual MVertex *getVertex(int num){ return num < 3 ? _v[num] : _vs[num - 3]; } - virtual const MVertex *getVertex(int num) const { return num < 3 ? _v[num] : _vs[num - 3]; } - virtual void setVertex(int num, MVertex *v){ if(num < 3) _v[num] = v; else _vs[num - 3] = v; } + virtual MVertex *getVertex(int num) + { + return num < 3 ? _v[num] : _vs[num - 3]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 3 ? _v[num] : _vs[num - 3]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 3) + _v[num] = v; + else + _vs[num - 3] = v; + } virtual MVertex *getVertexUNV(int num) { static const int map[6] = {0, 3, 1, 4, 2, 5}; return getVertex(map[num]); } - virtual void xyz2uvw(double xyz[3], double uvw[3]) const{ MElement::xyz2uvw(xyz, uvw); } + virtual void xyz2uvw(double xyz[3], double uvw[3]) const + { + MElement::xyz2uvw(xyz, uvw); + } virtual int getNumEdgeVertices() const { return 3; } virtual int getNumEdgesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3); MTriangle::_getEdgeVertices(num, v); @@ -208,8 +240,9 @@ class MTriangle6 : public MTriangle { } virtual MFaceN getHighOrderFace(int num, int sign, int rot); virtual int getNumFacesRep(bool curved); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(6); MTriangle::_getFaceVertices(v); @@ -218,23 +251,34 @@ class MTriangle6 : public MTriangle { v[5] = _vs[2]; } virtual int getTypeForMSH() const { return MSH_TRI_6; } - virtual int getTypeForUNV() const { return 92; } // thin shell parabolic triangle + virtual int getTypeForUNV() const + { + return 92; + } // thin shell parabolic triangle virtual int getTypeForVTK() const { return 22; } virtual const char *getStringForPOS() const { return "ST2"; } virtual const char *getStringForBDF() const { return "CTRIA6"; } virtual const char *getStringForDIFF() const { return "ElmT6n2D"; } - virtual const char *getStringForINP() const { return "CPS6"/*"STRI65"*//*"C2D6"*/; } + virtual const char *getStringForINP() const + { + return "CPS6" /*"STRI65"*/ /*"C2D6"*/; + } virtual const char *getStringForKEY() const { return "_SHELL"; } virtual const char *getStringForTOCHNOG() const { return "-tria6"; } virtual void reverse() { MVertex *tmp; - tmp = _v[1]; _v[1] = _v[2]; _v[2] = tmp; - tmp = _vs[0]; _vs[0] = _vs[2]; _vs[2] = tmp; + tmp = _v[1]; + _v[1] = _v[2]; + _v[2] = tmp; + tmp = _vs[0]; + _vs[0] = _vs[2]; + _vs[2] = tmp; } virtual void getNode(int num, double &u, double &v, double &w) const { - num < 3 ? MTriangle::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); + num < 3 ? MTriangle::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } // reorient the triangle to conform with other face // orientation computed with MFace based on this face with respect to other @@ -243,7 +287,7 @@ class MTriangle6 : public MTriangle { }; typedef std::vector<int> IndicesReoriented; -typedef std::pair<int, std::pair<int,int> > TupleReorientation; +typedef std::pair<int, std::pair<int, int> > TupleReorientation; /* * MTriangleN FIXME: check the plot @@ -262,52 +306,76 @@ typedef std::pair<int, std::pair<int,int> > TupleReorientation; * */ class MTriangleN : public MTriangle { - static std::map<TupleReorientation, IndicesReoriented> _tuple2indicesReoriented; - protected: + static std::map<TupleReorientation, IndicesReoriented> + _tuple2indicesReoriented; + +protected: std::vector<MVertex *> _vs; const char _order; - public: + +public: MTriangleN(MVertex *v0, MVertex *v1, MVertex *v2, - const std::vector<MVertex*> &v, char order, int num=0, int part=0) + const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) : MTriangle(v0, v1, v2, num, part), _vs(v), _order(order) { - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); } - MTriangleN(const std::vector<MVertex*> &v, char order, int num=0, int part=0) + MTriangleN(const std::vector<MVertex *> &v, char order, int num = 0, + int part = 0) : MTriangle(v[0], v[1], v[2], num, part), _order(order) { for(unsigned int i = 3; i < v.size(); i++) _vs.push_back(v[i]); - for(unsigned int i = 0; i < _vs.size(); i++) _vs[i]->setPolynomialOrder(_order); + for(unsigned int i = 0; i < _vs.size(); i++) + _vs[i]->setPolynomialOrder(_order); } - ~MTriangleN(){} + ~MTriangleN() {} virtual int getPolynomialOrder() const { return _order; } virtual std::size_t getNumVertices() const { return 3 + _vs.size(); } - virtual MVertex *getVertex(int num){ return num < 3 ? _v[num] : _vs[num - 3]; } - virtual const MVertex *getVertex(int num) const { return num < 3 ? _v[num] : _vs[num - 3]; } - virtual void setVertex(int num, MVertex *v){ if(num < 3) _v[num] = v; else _vs[num - 3] = v; } + virtual MVertex *getVertex(int num) + { + return num < 3 ? _v[num] : _vs[num - 3]; + } + virtual const MVertex *getVertex(int num) const + { + return num < 3 ? _v[num] : _vs[num - 3]; + } + virtual void setVertex(int num, MVertex *v) + { + if(num < 3) + _v[num] = v; + else + _vs[num - 3] = v; + } virtual int getNumFaceVertices() const { - if (getIsAssimilatedSerendipity()) + if(getIsAssimilatedSerendipity()) return 0; else - return (_order - 1) * (_order - 2) / 2; + return (_order - 1) * (_order - 2) / 2; + } + virtual void xyz2uvw(double xyz[3], double uvw[3]) const + { + MElement::xyz2uvw(xyz, uvw); } - virtual void xyz2uvw(double xyz[3], double uvw[3]) const { MElement::xyz2uvw(xyz, uvw); } virtual int getNumEdgeVertices() const { return 3 * (_order - 1); } virtual int getNumEdgesRep(bool curved); virtual int getNumFacesRep(bool curved); - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(_order + 1); MTriangle::_getEdgeVertices(num, v); int j = 2; const int ie = (num + 1) * (_order - 1); - for(int i = num * (_order-1); i != ie; ++i) v[j++] = _vs[i]; + for(int i = num * (_order - 1); i != ie; ++i) v[j++] = _vs[i]; } virtual MFaceN getHighOrderFace(int num, int sign, int rot); - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n); - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n); + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize(3 + _vs.size()); MTriangle::_getFaceVertices(v); @@ -324,7 +392,7 @@ class MTriangleN : public MTriangle { if(_order == 7 && _vs.size() == 33) return MSH_TRI_36; if(_order == 8 && _vs.size() == 42) return MSH_TRI_45; if(_order == 9 && _vs.size() == 52) return MSH_TRI_55; - if(_order ==10 && _vs.size() == 63) return MSH_TRI_66; + if(_order == 10 && _vs.size() == 63) return MSH_TRI_66; if(_order == 3 && _vs.size() == 6) return MSH_TRI_9; if(_order == 4 && _vs.size() == 9) return MSH_TRI_12; @@ -333,8 +401,9 @@ class MTriangleN : public MTriangle { if(_order == 7 && _vs.size() == 18) return MSH_TRI_21I; if(_order == 8 && _vs.size() == 21) return MSH_TRI_24; if(_order == 9 && _vs.size() == 24) return MSH_TRI_27; - if(_order ==10 && _vs.size() == 27) return MSH_TRI_30; - Msg::Error("no tag matches a p%d triangle with %d vertices", _order, 3+_vs.size()); + if(_order == 10 && _vs.size() == 27) return MSH_TRI_30; + Msg::Error("no tag matches a p%d triangle with %d vertices", _order, + 3 + _vs.size()); return 0; } virtual int getTypeForVTK() const @@ -344,7 +413,8 @@ class MTriangleN : public MTriangle { virtual void reverse(); virtual void getNode(int num, double &u, double &v, double &w) const { - num < 3 ? MTriangle::getNode(num, u, v, w) : MElement::getNode(num, u, v, w); + num < 3 ? MTriangle::getNode(num, u, v, w) : + MElement::getNode(num, u, v, w); } // reorient the triangle to conform with other face // orientation computed with MFace based on this face with respect to other @@ -352,33 +422,33 @@ class MTriangleN : public MTriangle { virtual void reorient(int rotation, bool swap); }; -template <class T> -void sort3(T t[3]) +template <class T> void sort3(T t[3]) { T temp; - if(t[0] > t[1]){ + if(t[0] > t[1]) { temp = t[1]; t[1] = t[0]; t[0] = temp; } - if(t[1] > t[2]){ + if(t[1] > t[2]) { temp = t[2]; t[2] = t[1]; t[1] = temp; } - if(t[0] > t[1]){ + if(t[0] > t[1]) { temp = t[1]; t[1] = t[0]; t[0] = temp; } } -struct compareMTriangleLexicographic -{ - bool operator () (MTriangle *t1, MTriangle *t2) const +struct compareMTriangleLexicographic { + bool operator()(MTriangle *t1, MTriangle *t2) const { - int _v1[3] = {t1->getVertex(0)->getNum(), t1->getVertex(1)->getNum(), t1->getVertex(2)->getNum()}; - int _v2[3] = {t2->getVertex(0)->getNum(), t2->getVertex(1)->getNum(), t2->getVertex(2)->getNum()}; + int _v1[3] = {t1->getVertex(0)->getNum(), t1->getVertex(1)->getNum(), + t1->getVertex(2)->getNum()}; + int _v2[3] = {t2->getVertex(0)->getNum(), t2->getVertex(1)->getNum(), + t2->getVertex(2)->getNum()}; sort3(_v1); sort3(_v2); if(_v1[0] < _v2[0]) return true; diff --git a/Geo/MTrihedron.cpp b/Geo/MTrihedron.cpp index d08ca230427818a940a5b8018ae19312d91a7812..e1364a7bdaf5d4c6b45cfcf0459d08f2edf19591 100644 --- a/Geo/MTrihedron.cpp +++ b/Geo/MTrihedron.cpp @@ -3,12 +3,12 @@ int MTrihedron::numCommonNodesInDualGraph(const MElement *const other) const { - switch (other->getType()) { - case TYPE_PNT: return 1; - case TYPE_LIN: return 2; - case TYPE_QUA: return 4; - case TYPE_HEX: return 4; - case TYPE_TRIH: return 2; - default: return 3; + switch(other->getType()) { + case TYPE_PNT: return 1; + case TYPE_LIN: return 2; + case TYPE_QUA: return 4; + case TYPE_HEX: return 4; + case TYPE_TRIH: return 2; + default: return 3; } } diff --git a/Geo/MTrihedron.h b/Geo/MTrihedron.h index 936699a2ecc4dda582810d534406c116a22cd2ce..421c71aa31ee3120317533464a279e7ac3a8b490 100644 --- a/Geo/MTrihedron.h +++ b/Geo/MTrihedron.h @@ -24,14 +24,14 @@ */ class MTrihedron : public MElement { - protected: +protected: MVertex *_v[4]; - void _getEdgeVertices(const int num, std::vector<MVertex*> &v) const + void _getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v[0] = _v[edges_trihedron(num, 0)]; v[1] = _v[edges_trihedron(num, 1)]; } - void _getFaceVertices(const int num, std::vector<MVertex*> &v) const + void _getFaceVertices(const int num, std::vector<MVertex *> &v) const { if(num > 0) { v[0] = _v[faces_trihedron(num, 0)]; @@ -46,60 +46,63 @@ class MTrihedron : public MElement { } } - public: - MTrihedron(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, int num=0, int part=0) +public: + MTrihedron(MVertex *v0, MVertex *v1, MVertex *v2, MVertex *v3, int num = 0, + int part = 0) : MElement(num, part) { - _v[0] = v0; _v[1] = v1; _v[2] = v2; _v[3] = v3; + _v[0] = v0; + _v[1] = v1; + _v[2] = v2; + _v[3] = v3; } - MTrihedron(const std::vector<MVertex*> &v, int num=0, int part=0) + MTrihedron(const std::vector<MVertex *> &v, int num = 0, int part = 0) : MElement(num, part) { for(int i = 0; i < 4; i++) _v[i] = v[i]; } - ~MTrihedron(){} - virtual int getDim() const { return 3; } //Can have a volume... + ~MTrihedron() {} + virtual int getDim() const { return 3; } // Can have a volume... virtual std::size_t getNumVertices() const { return 4; } - virtual MVertex *getVertex(int num){ return _v[num]; } + virtual MVertex *getVertex(int num) { return _v[num]; } virtual const MVertex *getVertex(int num) const { return _v[num]; } - virtual void setVertex(int num, MVertex *v){ _v[num] = v; } - virtual int getNumEdges()const{ return 5; } + virtual void setVertex(int num, MVertex *v) { _v[num] = v; } + virtual int getNumEdges() const { return 5; } virtual MEdge getEdge(int num) const { return MEdge(_v[edges_trihedron(num, 0)], _v[edges_trihedron(num, 1)]); } - virtual int getNumEdgesRep(bool curved){ return 5; } - virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual int getNumEdgesRep(bool curved) { return 5; } + virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { MEdge e(getEdge(num)); _getEdgeRep(e.getVertex(0), e.getVertex(1), x, y, z, n, 0); } - virtual void getEdgeVertices(const int num, std::vector<MVertex*> &v) const + virtual void getEdgeVertices(const int num, std::vector<MVertex *> &v) const { v.resize(2); _getEdgeVertices(num, v); } - virtual int getNumFaces(){ return 3; } + virtual int getNumFaces() { return 3; } virtual MFace getFace(int num) const { if(num > 0) - return MFace(_v[faces_trihedron(num, 0)], - _v[faces_trihedron(num, 1)], + return MFace(_v[faces_trihedron(num, 0)], _v[faces_trihedron(num, 1)], _v[faces_trihedron(num, 2)]); else return MFace(_v[0], _v[1], _v[2], _v[3]); } - virtual int getNumFacesRep(bool curved){ return 2; } - virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n) + virtual int getNumFacesRep(bool curved) { return 2; } + virtual void getFaceRep(bool curved, int num, double *x, double *y, double *z, + SVector3 *n) { - static const int f[2][3] = { - {0, 1, 3}, {1, 2, 3} - }; - _getFaceRep(getVertex(f[num][0]), getVertex(f[num][1]), getVertex(f[num][2]), - x, y, z, n); + static const int f[2][3] = {{0, 1, 3}, {1, 2, 3}}; + _getFaceRep(getVertex(f[num][0]), getVertex(f[num][1]), + getVertex(f[num][2]), x, y, z, n); } - virtual void getFaceVertices(const int num, std::vector<MVertex*> &v) const + virtual void getFaceVertices(const int num, std::vector<MVertex *> &v) const { v.resize((num == 0) ? 4 : 3); _getFaceVertices(num, v); @@ -109,26 +112,40 @@ class MTrihedron : public MElement { virtual void reverse() { - MVertex *tmp = _v[1]; _v[1] = _v[3]; _v[3] = tmp; + MVertex *tmp = _v[1]; + _v[1] = _v[3]; + _v[3] = tmp; } - virtual int getVolumeSign(){return 0;}; - virtual double getVolume(){return 0;}; - virtual bool setVolumePositive(){return false;}; + virtual int getVolumeSign() { return 0; }; + virtual double getVolume() { return 0; }; + virtual bool setVolumePositive() { return false; }; virtual void getNode(int num, double &u, double &v, double &w) const { w = 0; switch(num) { - case 0 : u = -1.; v = -1.; break; - case 1 : u = 1.; v = -1.; break; - case 2 : u = 1.; v = 1.; break; - case 3 : u = -1.; v = 1.; break; - default: u = 0.; v = 0.; break; + case 0: + u = -1.; + v = -1.; + break; + case 1: + u = 1.; + v = -1.; + break; + case 2: + u = 1.; + v = 1.; + break; + case 3: + u = -1.; + v = 1.; + break; + default: + u = 0.; + v = 0.; + break; } } - virtual SPoint3 barycenterUVW() const - { - return SPoint3(0., 0., 0.); - } + virtual SPoint3 barycenterUVW() const { return SPoint3(0., 0., 0.); } virtual bool isInside(double u, double v, double w) const { double tol = getTolerance(); @@ -140,11 +157,7 @@ class MTrihedron : public MElement { static int edges_trihedron(const int edge, const int vert) { static const int e[5][2] = { - {0, 1}, - {1, 2}, - {2, 3}, - {3, 0}, - {1, 3}, + {0, 1}, {1, 2}, {2, 3}, {3, 0}, {1, 3}, }; return e[edge][vert]; } @@ -158,7 +171,9 @@ class MTrihedron : public MElement { return f[face][vert]; } - // Return the number of nodes that this element must have with the other in order to put an edge between them in the dual graph used during the partitioning. + // Return the number of nodes that this element must have with the other in + // order to put an edge between them in the dual graph used during the + // partitioning. virtual int numCommonNodesInDualGraph(const MElement *const other) const; }; diff --git a/Geo/MVertex.cpp b/Geo/MVertex.cpp index 7bb59b80beb7abd937315812a3b01c6204caaf9c..bde5c5a296fe458eb3c770cf9e2d11c39007cf9f 100644 --- a/Geo/MVertex.cpp +++ b/Geo/MVertex.cpp @@ -24,12 +24,7 @@ double angle3Vertices(const MVertex *p1, const MVertex *p2, const MVertex *p3) } MVertex::MVertex(double x, double y, double z, GEntity *ge, int num) - : _visible(1) - , _order(1) - , _x(x) - , _y(y) - , _z(z) - , _ge(ge) + : _visible(1), _order(1), _x(x), _y(y), _z(z), _ge(ge) { #if defined(_OPENMP) #pragma omp critical diff --git a/Geo/MVertex.h b/Geo/MVertex.h index 282e49b3982429d012d6d61db1daf5dce28c2308..7553dac33464377df253d92ecc48702c8666465b 100644 --- a/Geo/MVertex.h +++ b/Geo/MVertex.h @@ -132,10 +132,7 @@ public: MEdgeVertex(double x, double y, double z, GEntity *ge, double u, int num = 0, double lc = -1.0) - : MVertex(x, y, z, ge, num) - , _u(u) - , _lc(lc) - , bl_data(0) + : MVertex(x, y, z, ge, num), _u(u), _lc(lc), bl_data(0) { } virtual ~MEdgeVertex() @@ -164,10 +161,7 @@ public: MFaceVertex(double x, double y, double z, GEntity *ge, double u, double v, int num = 0) - : MVertex(x, y, z, ge, num) - , _u(u) - , _v(v) - , bl_data(0) + : MVertex(x, y, z, ge, num), _u(u), _v(v), bl_data(0) { } virtual ~MFaceVertex() diff --git a/Geo/MVertexBoundaryLayerData.cpp b/Geo/MVertexBoundaryLayerData.cpp index 296fc31ff115cbacd8d8850eb33027982f8c10a2..61df7509d0fb80d225a00f722651a8d99480691d 100644 --- a/Geo/MVertexBoundaryLayerData.cpp +++ b/Geo/MVertexBoundaryLayerData.cpp @@ -5,9 +5,9 @@ #include "MVertexBoundaryLayerData.h" -std::vector<MVertex*>* MVertexBoundaryLayerData::getChildren(int i) +std::vector<MVertex *> *MVertexBoundaryLayerData::getChildren(int i) { - if (i < (int)this->children.size() && i >= 0) { + if(i < (int)this->children.size() && i >= 0) { return &(children[i]); } else { @@ -17,7 +17,7 @@ std::vector<MVertex*>* MVertexBoundaryLayerData::getChildren(int i) int MVertexBoundaryLayerData::getNumChildren(int i) { - if (i < (int)this->children.size() && i >= 0) { + if(i < (int)this->children.size() && i >= 0) { return (int)this->children[i].size(); } else { diff --git a/Geo/MVertexBoundaryLayerData.h b/Geo/MVertexBoundaryLayerData.h index f81d604beefd2a49f59694056e84c3ffccfd7ac1..e427821bf5f6886177b0be376791ffa2deeb8302 100644 --- a/Geo/MVertexBoundaryLayerData.h +++ b/Geo/MVertexBoundaryLayerData.h @@ -16,14 +16,14 @@ class MVertex; // direction, in order. class MVertexBoundaryLayerData { - private: - std::vector<std::vector<MVertex*> > children; +private: + std::vector<std::vector<MVertex *> > children; - public: +public: MVertexBoundaryLayerData(){}; ~MVertexBoundaryLayerData(){}; - std::vector<MVertex*>* getChildren(int i); + std::vector<MVertex *> *getChildren(int i); int getNumChildren(int i); int getNumChildrenFamilies(); diff --git a/Geo/MVertexRTree.h b/Geo/MVertexRTree.h index 8fed0bdb697812bd97f44e667bead26522f44a4d..679917f2b3d345a78d27cc253e4e4520c5069757 100644 --- a/Geo/MVertexRTree.h +++ b/Geo/MVertexRTree.h @@ -13,20 +13,21 @@ // Stores MVertex pointers in an R-Tree so we can query unique vertices by their // coordinates, up to a prescribed tolerance. -class MVertexRTree{ - private: - RTree<MVertex*, double, 3, double> *_rtree; +class MVertexRTree { +private: + RTree<MVertex *, double, 3, double> *_rtree; double _tol; static bool rtree_callback(MVertex *v, void *ctx) { - MVertex **out = static_cast<MVertex**>(ctx); + MVertex **out = static_cast<MVertex **>(ctx); *out = v; return false; // we're done searching } - public: + +public: MVertexRTree(double tolerance = 1.e-8) { - _rtree = new RTree<MVertex*, double, 3, double>(); + _rtree = new RTree<MVertex *, double, 3, double>(); _tol = tolerance; } ~MVertexRTree() @@ -34,32 +35,32 @@ class MVertexRTree{ _rtree->RemoveAll(); delete _rtree; } - MVertex *insert(MVertex *v, bool warnIfExists=false, - std::set<MVertex*> *duplicates=0) + MVertex *insert(MVertex *v, bool warnIfExists = false, + std::set<MVertex *> *duplicates = 0) { MVertex *out; double _min[3] = {v->x() - _tol, v->y() - _tol, v->z() - _tol}; double _max[3] = {v->x() + _tol, v->y() + _tol, v->z() + _tol}; - if(!_rtree->Search(_min, _max, rtree_callback, &out)){ + if(!_rtree->Search(_min, _max, rtree_callback, &out)) { _rtree->Insert(_min, _max, v); return 0; } - else{ - if(duplicates){ + else { + if(duplicates) { duplicates->insert(out); duplicates->insert(v); } - if(warnIfExists){ + if(warnIfExists) { Msg::Warning("Vertex %d (%.16g, %.16g, %.16g) already exists in the " "mesh with tolerance %g: Vertex %d (%.16g, %.16g, %.16g)", - v->getNum(), v->x(), v->y(), v->z(), _tol, - out->getNum(), out->x(), out->y(), out->z()); + v->getNum(), v->x(), v->y(), v->z(), _tol, out->getNum(), + out->x(), out->y(), out->z()); } return out; } } - int insert(std::vector<MVertex*> &v, bool warnIfExists=false, - std::set<MVertex*> *duplicates=0) + int insert(std::vector<MVertex *> &v, bool warnIfExists = false, + std::set<MVertex *> *duplicates = 0) { int num = 0; for(unsigned int i = 0; i < v.size(); i++) @@ -71,14 +72,10 @@ class MVertexRTree{ MVertex *out; double _min[3] = {x - _tol, y - _tol, z - _tol}; double _max[3] = {x + _tol, y + _tol, z + _tol}; - if(_rtree->Search(_min, _max, rtree_callback, &out)) - return out; + if(_rtree->Search(_min, _max, rtree_callback, &out)) return out; return 0; } - unsigned int size() - { - return _rtree->Count(); - } + unsigned int size() { return _rtree->Count(); } }; #endif diff --git a/Geo/MZone.cpp b/Geo/MZone.cpp index 2f87ba15820b693608832d353e9e6d29e3352084..03e45b3dd6bd891c04170fb3bd03e5ad5a0de25c 100644 --- a/Geo/MZone.cpp +++ b/Geo/MZone.cpp @@ -16,9 +16,7 @@ * Forward declarations *============================================================================*/ -template <unsigned DIM> -struct ParseEntity; - +template <unsigned DIM> struct ParseEntity; /******************************************************************************* * @@ -26,7 +24,6 @@ struct ParseEntity; * ******************************************************************************/ - /*============================================================================== * * Routine: add_elements_in_entities @@ -53,19 +50,16 @@ struct ParseEntity; template <unsigned DIM> template <typename EntIter> -void MZone<DIM>::add_elements_in_entities -(EntIter begin, EntIter end, const int partition) +void MZone<DIM>::add_elements_in_entities(EntIter begin, EntIter end, + const int partition) { - // Find the neighbours of each vertex, edge, and face for(EntIter itEnt = begin; itEnt != end; ++itEnt) { ParseEntity<DIM>::eval(*itEnt, boFaceMap, elemVec, vertMap, zoneElemConn, partition); } - } - /*============================================================================== * * Routine: add_elements_in_entity @@ -94,17 +88,13 @@ void MZone<DIM>::add_elements_in_entities template <unsigned DIM> template <typename EntPtr> -void MZone<DIM>::add_elements_in_entity -(EntPtr entity, const int partition) +void MZone<DIM>::add_elements_in_entity(EntPtr entity, const int partition) { - // Find the neighbours of each vertex, edge, and face ParseEntity<DIM>::eval(entity, boFaceMap, elemVec, vertMap, zoneElemConn, partition); - } - /*============================================================================== * * Routine: zoneData @@ -119,26 +109,24 @@ void MZone<DIM>::add_elements_in_entity * *============================================================================*/ -template <unsigned DIM> -int MZone<DIM>::zoneData() +template <unsigned DIM> int MZone<DIM>::zoneData() { - if(elemVec.size() == 0) return 1; // Resize output arrays zoneVertVec.resize(vertMap.size()); -//--Label boundary vertices and start building output vector of vertices. -//--Also record boundary faces that contain a boundary vertex. + //--Label boundary vertices and start building output vector of vertices. + //--Also record boundary faces that contain a boundary vertex. - std::vector<MVertex*> faceVertices; + std::vector<MVertex *> faceVertices; unsigned cVert = 0; for(typename BoFaceMap::iterator fMapIt = boFaceMap.begin(); fMapIt != boFaceMap.end(); ++fMapIt) { // Get all the vertices on the face - DimTr<DIM>::getAllFaceVertices - (elemVec[fMapIt->second.parentElementIndex].element, - fMapIt->second.parentFace, faceVertices); + DimTr<DIM>::getAllFaceVertices( + elemVec[fMapIt->second.parentElementIndex].element, + fMapIt->second.parentFace, faceVertices); const int nVert = faceVertices.size(); for(int iVert = 0; iVert != nVert; ++iVert) { int &index = vertMap[faceVertices[iVert]]; @@ -157,32 +145,32 @@ int MZone<DIM>::zoneData() } numBoVert = cVert; -//--Label interior vertices and complete output vector of vertices + //--Label interior vertices and complete output vector of vertices const VertexMap::iterator vMapEnd = vertMap.end(); - for(VertexMap::iterator vMapIt = vertMap.begin(); - vMapIt != vMapEnd; ++vMapIt) { - if(vMapIt->second == 0) { // Vertex in zone interior + for(VertexMap::iterator vMapIt = vertMap.begin(); vMapIt != vMapEnd; + ++vMapIt) { + if(vMapIt->second == 0) { // Vertex in zone interior zoneVertVec[cVert] = vMapIt->first; vMapIt->second = ++cVert; } } -//--Initialize the connectivity array for the various types of elements. Note -//--that 'iElemType' is MSH_TYPE-1. + //--Initialize the connectivity array for the various types of elements. Note + //--that 'iElemType' is MSH_TYPE-1. for(int iElemType = 0; iElemType != MSH_NUM_TYPE; ++iElemType) { if(zoneElemConn[iElemType].numElem > 0) { - zoneElemConn[iElemType].connectivity.resize - (zoneElemConn[iElemType].numElem*MElement::getInfoMSH(iElemType+1)); + zoneElemConn[iElemType].connectivity.resize( + zoneElemConn[iElemType].numElem * MElement::getInfoMSH(iElemType + 1)); // Members numBoElem, and iConn should be set to zero via the constructor // or a clear } } -//--The elements are added to the connectivity in two loops. The first loop -//--looks for boundary elements. The second loop adds the remaining interior -//--elements. + //--The elements are added to the connectivity in two loops. The first loop + //--looks for boundary elements. The second loop adds the remaining interior + //--elements. unsigned cElem = 1; const ElementVec::const_iterator eVecEnd = elemVec.end(); @@ -202,16 +190,17 @@ int MZone<DIM>::zoneData() // Load connectivity for this element type const int nVert = eVecIt->element->getNumVertices(); for(int iVert = 0; iVert != nVert; ++iVert) { - zoneElemConn[iElemType].add_to_connectivity - (vertMap[eVecIt->element->getVertex(iVert)]); + zoneElemConn[iElemType].add_to_connectivity( + vertMap[eVecIt->element->getVertex(iVert)]); } break; } } } -//--Now loop through all elements again and do same thing for all elements with -//--index set to 0 + //--Now loop through all elements again and do same thing for all elements + //with + //--index set to 0 for(ElementVec::iterator eVecIt = elemVec.begin(); eVecIt != eVecEnd; ++eVecIt) { @@ -223,27 +212,25 @@ int MZone<DIM>::zoneData() // Load connectivity for this element type const int nVert = eVecIt->element->getNumVertices(); for(int iVert = 0; iVert != nVert; ++iVert) { - zoneElemConn[iElemType].add_to_connectivity - (vertMap[eVecIt->element->getVertex(iVert)]); + zoneElemConn[iElemType].add_to_connectivity( + vertMap[eVecIt->element->getVertex(iVert)]); } } } -//**If we are going to write the boundary element faces, we need to update -//**.parentElementIndex from "index in elemVec" to "elemVec[iParent].index. -//**This is the index of the parent element local to the zone. + //**If we are going to write the boundary element faces, we need to update + //**.parentElementIndex from "index in elemVec" to "elemVec[iParent].index. + //**This is the index of the parent element local to the zone. -//--Clean-up for containers that are no longer required. Only 'boVertMap' is -//--still required but 'boFaceMap' is also retained because it contains the -//--faces referenced by 'boVertMap'. + //--Clean-up for containers that are no longer required. Only 'boVertMap' is + //--still required but 'boFaceMap' is also retained because it contains the + //--faces referenced by 'boVertMap'. elemVec.clear(); vertMap.clear(); return 0; - } - /******************************************************************************* * * Struct ParseEntity @@ -255,21 +242,20 @@ int MZone<DIM>::zoneData() * ******************************************************************************/ -template <unsigned DIM> -struct ParseEntity -{ - typedef typename DimTr<DIM>::FaceT FaceT; // The type/dimension of face +template <unsigned DIM> struct ParseEntity { + typedef typename DimTr<DIM>::FaceT FaceT; // The type/dimension of face typedef typename LFaceTr<FaceT>::BoFaceMap BoFaceMap; // The corresponding map - static void eval(const GEntity *const entity, - BoFaceMap &boFaceMap, - ElementVec &elemVec, - VertexMap &vertMap, - ElementConnectivity *zoneElemConn, - const int partition) + static void eval(const GEntity *const entity, BoFaceMap &boFaceMap, + ElementVec &elemVec, VertexMap &vertMap, + ElementConnectivity *zoneElemConn, const int partition) { unsigned numElem[6]; - numElem[0] = 0; numElem[1] = 0; numElem[2] = 0; numElem[3] = 0; numElem[4] = 0; + numElem[0] = 0; + numElem[1] = 0; + numElem[2] = 0; + numElem[3] = 0; + numElem[4] = 0; numElem[5] = 0; entity->getNumMeshElements(numElem); // Loop over all types of elements @@ -287,16 +273,15 @@ struct ParseEntity // Unique list of vertices const int nVert = element[iElem]->getNumVertices(); for(int iVert = 0; iVert != nVert; ++iVert) - vertMap[element[iElem]->getVertex(iVert)] = 0; // Unlabelled + vertMap[element[iElem]->getVertex(iVert)] = 0; // Unlabelled // Maintain list of (base element) faces with only one bounding // element. const int nFace = DimTr<DIM>::getNumFace(element[iElem]); for(int iFace = 0; iFace != nFace; ++iFace) { FaceT face = DimTr<DIM>::getFace(element[iElem], iFace); std::pair<typename BoFaceMap::iterator, bool> insBoFaceMap = - boFaceMap.insert(std::pair<FaceT, FaceData> - (face, FaceData(element[iElem], iFace, - eVecIndex))); + boFaceMap.insert(std::pair<FaceT, FaceData>( + face, FaceData(element[iElem], iFace, eVecIndex))); if(!insBoFaceMap.second) { // The face already exists and is therefore bounded on both sides // by elements. Not a boundary face so delete. @@ -309,7 +294,6 @@ struct ParseEntity } }; - /******************************************************************************* * * Explicit instantiations of class MZone @@ -325,25 +309,23 @@ template class MZone<3>; //--container of entities // Vector container -template void MZone<2>::add_elements_in_entities -<std::vector<GEntity*>::const_iterator> -(std::vector<GEntity*>::const_iterator begin, - std::vector<GEntity*>::const_iterator end, const int partition); +template void +MZone<2>::add_elements_in_entities<std::vector<GEntity *>::const_iterator>( + std::vector<GEntity *>::const_iterator begin, + std::vector<GEntity *>::const_iterator end, const int partition); -template void MZone<3>::add_elements_in_entities -<std::vector<GEntity*>::const_iterator> -(std::vector<GEntity*>::const_iterator begin, - std::vector<GEntity*>::const_iterator end, const int partition); +template void +MZone<3>::add_elements_in_entities<std::vector<GEntity *>::const_iterator>( + std::vector<GEntity *>::const_iterator begin, + std::vector<GEntity *>::const_iterator end, const int partition); //--Explicit instantiations of the routines for adding elements from a single //--entity -template void MZone<2>::add_elements_in_entity -<GFace*> -(GFace* entity, const int partition); +template void MZone<2>::add_elements_in_entity<GFace *>(GFace *entity, + const int partition); -template void MZone<3>::add_elements_in_entity -<GRegion*> -(GRegion* entity, const int partition); +template void MZone<3>::add_elements_in_entity<GRegion *>(GRegion *entity, + const int partition); #endif diff --git a/Geo/MZone.h b/Geo/MZone.h index 5328dc8ecbb2b8eae1e15c4424d563e72f617db7..b69c41c84d3c912bc1a2595d30789a55c929408b 100644 --- a/Geo/MZone.h +++ b/Geo/MZone.h @@ -30,14 +30,11 @@ #include "HashMap.h" #endif - /*============================================================================== * Forward declarations *============================================================================*/ -template <unsigned DIM> -class MZoneBoundary; - +template <unsigned DIM> class MZoneBoundary; /*============================================================================== * Required types @@ -45,26 +42,22 @@ class MZoneBoundary; //--Record of unique elements -struct ElemData -{ +struct ElemData { MElement *element; int index; - ElemData(MElement *const _element) - : element(_element), index(0) - { } + ElemData(MElement *const _element) : element(_element), index(0) {} }; typedef std::vector<ElemData> ElementVec; //--Record of unique vertices -typedef std::map<MVertex*, int, std::less<MVertex*> > VertexMap; +typedef std::map<MVertex *, int, std::less<MVertex *> > VertexMap; //--Data for each face. Ultimately, only faces on the boundary of the zone are //--stored. Value type for 'BoFaceMap'. -struct FaceData -{ +struct FaceData { MElement *parentElement; int parentFace; int parentElementIndex; @@ -72,16 +65,15 @@ struct FaceData FaceData(MElement *const _parentElement, const int _parentFace, const int _parentElementIndex) : parentElement(_parentElement), parentFace(_parentFace), - parentElementIndex(_parentElementIndex), faceIndex(0) - { } + parentElementIndex(_parentElementIndex), faceIndex(0) + { + } }; //--Provides information and boundary faces connected to a vertex. Value type //--for 'BoVertexMap' -template <typename BFMapIt> -struct ZoneVertexData -{ +template <typename BFMapIt> struct ZoneVertexData { CCon::FaceVector<BFMapIt> faces; // Vector optimized for storing faces int index; }; @@ -90,21 +82,15 @@ struct ZoneVertexData * User I/O *--------------------------------------------------------------------*/ -struct ElementConnectivity -{ +struct ElementConnectivity { std::vector<int> connectivity; int numElem; int numBoElem; int iConn; // Constructor - ElementConnectivity() - : numElem(0), numBoElem(0), iConn(0) - { } + ElementConnectivity() : numElem(0), numBoElem(0), iConn(0) {} // Member functions - void add_to_connectivity(const int i) - { - connectivity[iConn++] = i; - } + void add_to_connectivity(const int i) { connectivity[iConn++] = i; } void clear() { connectivity.clear(); @@ -120,24 +106,20 @@ typedef std::vector<ElementConnectivity> ElementConnectivityVec; //--Output type for vertices in the zone -typedef std::vector<MVertex*> VertexVec; - +typedef std::vector<MVertex *> VertexVec; /*============================================================================== * Traits classes - that return information about a type *============================================================================*/ template <typename FaceT> struct LFaceTr; -template <> struct LFaceTr<MEdge> -{ +template <> struct LFaceTr<MEdge> { typedef std::map<MEdge, FaceData, Less_Edge> BoFaceMap; }; -template <> struct LFaceTr<MFace> -{ +template <> struct LFaceTr<MFace> { typedef std::map<MFace, FaceData, Less_Face> BoFaceMap; }; - /******************************************************************************* * * class: MZone @@ -160,64 +142,54 @@ template <> struct LFaceTr<MFace> * ******************************************************************************/ -template <unsigned DIM> -class MZone -{ - +template <unsigned DIM> class MZone { + /*============================================================================== + * Internal types + *============================================================================*/ -/*============================================================================== - * Internal types - *============================================================================*/ - - public: +public: typedef typename DimTr<DIM>::FaceT FaceT; typedef typename LFaceTr<FaceT>::BoFaceMap BoFaceMap; - typedef typename std::map<const MVertex*, - ZoneVertexData<typename BoFaceMap::const_iterator>, - std::less<const MVertex*> > BoVertexMap; - + typedef typename std::map<const MVertex *, + ZoneVertexData<typename BoFaceMap::const_iterator>, + std::less<const MVertex *> > + BoVertexMap; -/*============================================================================== - * Member functions - *============================================================================*/ + /*============================================================================== + * Member functions + *============================================================================*/ - public: +public: + //--Default constructor. -//--Default constructor. - - MZone() - : numBoVert(0) - { - elemVec.reserve(8192); - } + MZone() : numBoVert(0) { elemVec.reserve(8192); } -/*--------------------------------------------------------------------* - * Elements added from entities. - * Note: It is much easier to keep these in the .cpp file but that - * requries explicit instantiations for each Ent and EntIter. - * Currently, instantiations only exist for containers of type: - * vector - * More can be added as required at the end of MZone.cpp - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * Elements added from entities. + * Note: It is much easier to keep these in the .cpp file but that + * requries explicit instantiations for each Ent and EntIter. + * Currently, instantiations only exist for containers of type: + * vector + * More can be added as required at the end of MZone.cpp + *--------------------------------------------------------------------*/ -//--Add all elements in a container of entities. The specific type of entity -//--is not known and must be specified as parameter 'Ent'. + //--Add all elements in a container of entities. The specific type of entity + //--is not known and must be specified as parameter 'Ent'. template <typename EntIter> void add_elements_in_entities(EntIter begin, EntIter end, const int partition = -1); -//--Add elements in a single entity. + //--Add elements in a single entity. template <typename EntPtr> void add_elements_in_entity(EntPtr entity, const int partition = -1); - -/*--------------------------------------------------------------------* - * Reset the database - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * Reset the database + *--------------------------------------------------------------------*/ - void clear() + void clear() { elemVec.clear(); vertMap.clear(); @@ -230,17 +202,17 @@ class MZone numBoVert = 0; } -/*--------------------------------------------------------------------* - * Process/query the zone - only after all elements have been added! - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * Process/query the zone - only after all elements have been added! + *--------------------------------------------------------------------*/ -//--Compute the zone data + //--Compute the zone data int zoneData(); -//--Total number of elements + //--Total number of elements - int totalElements() const + int totalElements() const { int numElem = 0; for(int iElemType = 0; iElemType != MSH_NUM_TYPE; ++iElemType) @@ -248,7 +220,7 @@ class MZone return numElem; } -//--Number of element types + //--Number of element types int numElementTypes() const { @@ -257,8 +229,8 @@ class MZone if(zoneElemConn[iElemType].numElem > 0) ++numElemType; return numElemType; } - -//--Memory management + + //--Memory management static void preInit() { @@ -269,35 +241,31 @@ class MZone CCon::FaceVector<typename BoFaceMap::const_iterator>::release_memory(); } -/*============================================================================== - * Member data - *============================================================================*/ - - private: - -//--Data members + /*============================================================================== + * Member data + *============================================================================*/ - ElementVec elemVec; // Set of unique elements - VertexMap vertMap; // Set of unique vertices and associated - // numbers in the zone - BoFaceMap boFaceMap; // Map of boundary faces - BoVertexMap boVertMap; // Map of boundary vertices +private: + //--Data members - public: + ElementVec elemVec; // Set of unique elements + VertexMap vertMap; // Set of unique vertices and associated + // numbers in the zone + BoFaceMap boFaceMap; // Map of boundary faces + BoVertexMap boVertMap; // Map of boundary vertices +public: // I/O VertexVec zoneVertVec; ElementConnectivity zoneElemConn[MSH_NUM_TYPE]; - // Connectivity for each type of element + // Connectivity for each type of element int numBoVert; - -/*============================================================================== - * Friends - *============================================================================*/ + /*============================================================================== + * Friends + *============================================================================*/ friend class MZoneBoundary<DIM>; - }; #endif diff --git a/Geo/MZoneBoundary.cpp b/Geo/MZoneBoundary.cpp index de5ccbd5bcd9d5787bc7663f0c8924f5cf963545..aaef6b69d8f7d4a07ae9be9c0690afaf39b614ba 100644 --- a/Geo/MZoneBoundary.cpp +++ b/Geo/MZoneBoundary.cpp @@ -9,7 +9,7 @@ #if defined(HAVE_LIBCGNS) -#define DEBUG_FaceT 0 // NBN: toggle reporting of face insertions +#define DEBUG_FaceT 0 // NBN: toggle reporting of face insertions #include <iostream> // DBG #include <limits> // ? @@ -19,11 +19,7 @@ //--Types at local scope -enum { - NormalSourceGeometry = 1, - NormalSourceElement = 2 -}; - +enum { NormalSourceGeometry = 1, NormalSourceElement = 2 }; /******************************************************************************* * @@ -38,15 +34,11 @@ enum { * ******************************************************************************/ -class BCPatchIndex -{ - struct PatchData - { +class BCPatchIndex { + struct PatchData { int index; std::vector<int> eTagVec; - PatchData(int eTag1) - : index(eTag1), eTagVec(1, eTag1) - { } + PatchData(int eTag1) : index(eTag1), eTagVec(1, eTag1) {} }; typedef std::list<PatchData> PatchDataList; @@ -72,11 +64,8 @@ class BCPatchIndex return insPatch.first; } - public: - - BCPatchIndex() - : sharedPatch(false) - { } +public: + BCPatchIndex() : sharedPatch(false) {} // Add an entity tag void add(const int eTag) { _add(eTag); } @@ -106,20 +95,19 @@ class BCPatchIndex // Once all entity tags have been added, generate patch indices void generatePatchIndices() { -// if(sharedPatch) { // Don't renumber if not shared to preserve entity -// // numbers. Mostly useful for debugging. - int c = 0; - for(PatchDataListIt pDIt = patchData.begin(); pDIt != patchData.end(); - ++pDIt) pDIt->index = c++; -// } + // if(sharedPatch) { // Don't renumber if not shared to preserve entity + // // numbers. Mostly useful for debugging. + int c = 0; + for(PatchDataListIt pDIt = patchData.begin(); pDIt != patchData.end(); + ++pDIt) + pDIt->index = c++; + // } } // Get the patch index for an entity (generate patch indices first) int getIndex(const int eTag) { return patch[eTag]->index; } - }; - /******************************************************************************* * * Routine updateBoVec @@ -171,13 +159,12 @@ class BCPatchIndex ******************************************************************************/ template <unsigned DIM, typename FaceT> -void updateBoVec -(const int normalSource, const MVertex *const vertex, const int zoneIndex, - const int vertIndex, - const CCon::FaceVector<typename MZoneBoundary<DIM>::template - GlobalVertexData<FaceT>::FaceDataB> &faces, ZoneBoVec &zoneBoVec, - BCPatchIndex &patch, bool &warnNormFromElem); - +void updateBoVec(const int normalSource, const MVertex *const vertex, + const int zoneIndex, const int vertIndex, + const CCon::FaceVector<typename MZoneBoundary< + DIM>::template GlobalVertexData<FaceT>::FaceDataB> &faces, + ZoneBoVec &zoneBoVec, BCPatchIndex &patch, + bool &warnNormFromElem); /******************************************************************************* * @@ -187,7 +174,6 @@ void updateBoVec //--"Contained" routines - /*============================================================================== * * Routine edge_normal @@ -213,28 +199,29 @@ void updateBoVec * *============================================================================*/ -int edge_normal -(const MVertex *const vertex, const int zoneIndex, const GEdge *const gEdge, - const CCon::FaceVector<MZoneBoundary<2>::GlobalVertexData<MEdge>::FaceDataB> - &faces, SVector3 &boNormal, const int onlyFace = -1) +int edge_normal( + const MVertex *const vertex, const int zoneIndex, const GEdge *const gEdge, + const CCon::FaceVector<MZoneBoundary<2>::GlobalVertexData<MEdge>::FaceDataB> + &faces, + SVector3 &boNormal, const int onlyFace = -1) { - - double par=0.0; + double par = 0.0; // Note: const_cast used to match MVertex.cpp interface - if(!reparamMeshVertexOnEdge(const_cast<MVertex*>(vertex), gEdge, par)) return 1; + if(!reparamMeshVertexOnEdge(const_cast<MVertex *>(vertex), gEdge, par)) + return 1; const SVector3 tangent(gEdge->firstDer(par)); - // Tangent to the boundary face - SPoint3 interior(0., 0., 0.); // An interior point - SVector3 meshPlaneNormal(0.); // This normal is perpendicular to the - // plane of the mesh + // Tangent to the boundary face + SPoint3 interior(0., 0., 0.); // An interior point + SVector3 meshPlaneNormal(0.); // This normal is perpendicular to the + // plane of the mesh // The interior point and mesh plane normal are computed from all elements in // the zone. int cFace = 0; int iFace = 0; int nFace = faces.size(); - if ( onlyFace >= 0 ) { + if(onlyFace >= 0) { iFace = onlyFace; nFace = onlyFace + 1; } @@ -255,13 +242,10 @@ int edge_normal boNormal.normalize(); // Direction vector from vertex to interior (inwards). The normal should // point in the same direction. - if(dot(boNormal, SVector3(vertex->point(), interior)) < 0.) - boNormal.negate(); + if(dot(boNormal, SVector3(vertex->point(), interior)) < 0.) boNormal.negate(); return 0; - } - /*============================================================================== * * Routine updateBoVec<2, MEdge> @@ -269,13 +253,13 @@ int edge_normal *============================================================================*/ template <> -void updateBoVec<2, MEdge> -(const int normalSource, const MVertex *const vertex, const int zoneIndex, - const int vertIndex, - const CCon::FaceVector<MZoneBoundary<2>::GlobalVertexData<MEdge>::FaceDataB> - &faces, ZoneBoVec &zoneBoVec, BCPatchIndex &patch, bool &warnNormFromElem) +void updateBoVec<2, MEdge>( + const int normalSource, const MVertex *const vertex, const int zoneIndex, + const int vertIndex, + const CCon::FaceVector<MZoneBoundary<2>::GlobalVertexData<MEdge>::FaceDataB> + &faces, + ZoneBoVec &zoneBoVec, BCPatchIndex &patch, bool &warnNormFromElem) { - GEntity *ent; if(normalSource == NormalSourceElement) goto getNormalFromElements; ent = vertex->onWhat(); @@ -287,25 +271,25 @@ void updateBoVec<2, MEdge> switch(ent->dim()) { case 0: -/*--------------------------------------------------------------------* - * In this case, there are possibly two GEdges from this zone - * connected to the vertex. If the angle between the two edges is - * significant, the BC patch will be split and this vertex will be - * written in both patches with different normals. If the angle is - * small, or only one GEdge belongs to this zone, then the vertex will - * only be written to one patch. - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * In this case, there are possibly two GEdges from this zone + * connected to the vertex. If the angle between the two edges is + * significant, the BC patch will be split and this vertex will be + * written in both patches with different normals. If the angle is + * small, or only one GEdge belongs to this zone, then the vertex will + * only be written to one patch. + *--------------------------------------------------------------------*/ { // Get the edge entities that are connected to the vertex - std::vector<GEdge*> gEdgeList = ent->edges(); + std::vector<GEdge *> gEdgeList = ent->edges(); // Find edge entities that are connected to elements in the zone - std::vector<std::pair<GEdge*, int> > useGEdge; + std::vector<std::pair<GEdge *, int> > useGEdge; const int nFace = faces.size(); for(int iFace = 0; iFace != nFace; ++iFace) { if(zoneIndex == faces[iFace].zoneIndex) { - MEdge mEdge = faces[iFace].parentElement->getEdge - (faces[iFace].parentFace); + MEdge mEdge = + faces[iFace].parentElement->getEdge(faces[iFace].parentFace); // Get the other vertex on the mesh edge. MVertex *vertex2 = mEdge.getMinVertex(); if(vertex2 == vertex) vertex2 = mEdge.getMaxVertex(); @@ -314,85 +298,75 @@ void updateBoVec<2, MEdge> // edge entities that will be used to determine the normal GEntity *const ent2 = vertex2->onWhat(); if(ent2->dim() == 1) { - useGEdge.push_back(std::pair<GEdge*, int> - (static_cast<GEdge*>(ent2), iFace)); + useGEdge.push_back( + std::pair<GEdge *, int>(static_cast<GEdge *>(ent2), iFace)); } } } -//--'useGEdge' now contains the edge entities that will be used to determine -//--the normals + //--'useGEdge' now contains the edge entities that will be used to + //determine + //--the normals switch(useGEdge.size()) { - case 0: -// goto getNormalFromElements; + // goto getNormalFromElements; // We probably don't want BC data if none of the faces attatched to // this vertex and in this zone are on the boundary. break; - case 1: - { - const GEdge *const gEdge = - static_cast<const GEdge*>(useGEdge[0].first); - SVector3 boNormal; - if(edge_normal(vertex, zoneIndex, gEdge, faces, boNormal)) - goto getNormalFromElements; - zoneBoVec.push_back(VertexBoundary(zoneIndex, gEdge->tag(), - boNormal, - const_cast<MVertex*>(vertex), - vertIndex)); - patch.add(gEdge->tag()); + case 1: { + const GEdge *const gEdge = + static_cast<const GEdge *>(useGEdge[0].first); + SVector3 boNormal; + if(edge_normal(vertex, zoneIndex, gEdge, faces, boNormal)) + goto getNormalFromElements; + zoneBoVec.push_back(VertexBoundary(zoneIndex, gEdge->tag(), boNormal, + const_cast<MVertex *>(vertex), + vertIndex)); + patch.add(gEdge->tag()); + } break; + + case 2: { + // Get the first normal + const GEdge *const gEdge1 = + static_cast<const GEdge *>(useGEdge[0].first); + SVector3 boNormal1; + if(edge_normal(vertex, zoneIndex, gEdge1, faces, boNormal1, + useGEdge[0].second)) + goto getNormalFromElements; + + // Get the second normal + const GEdge *const gEdge2 = + static_cast<const GEdge *>(useGEdge[1].first); + SVector3 boNormal2; + if(edge_normal(vertex, zoneIndex, gEdge2, faces, boNormal2, + useGEdge[1].second)) + goto getNormalFromElements; + + if(dot(boNormal1, boNormal2) < 0.98) { + //--Write 2 separate patches + + zoneBoVec.push_back( + VertexBoundary(zoneIndex, gEdge1->tag(), boNormal1, + const_cast<MVertex *>(vertex), vertIndex)); + patch.add(gEdge1->tag()); + zoneBoVec.push_back( + VertexBoundary(zoneIndex, gEdge2->tag(), boNormal2, + const_cast<MVertex *>(vertex), vertIndex)); + patch.add(gEdge2->tag()); } - break; - - case 2: - { - // Get the first normal - const GEdge *const gEdge1 = - static_cast<const GEdge*>(useGEdge[0].first); - SVector3 boNormal1; - if(edge_normal(vertex, zoneIndex, gEdge1, faces, boNormal1, - useGEdge[0].second)) - goto getNormalFromElements; - - // Get the second normal - const GEdge *const gEdge2 = - static_cast<const GEdge*>(useGEdge[1].first); - SVector3 boNormal2; - if(edge_normal(vertex, zoneIndex, gEdge2, faces, boNormal2, - useGEdge[1].second)) - goto getNormalFromElements; - - if(dot(boNormal1, boNormal2) < 0.98) { - -//--Write 2 separate patches - - zoneBoVec.push_back(VertexBoundary(zoneIndex, gEdge1->tag(), - boNormal1, - const_cast<MVertex*>(vertex), - vertIndex)); - patch.add(gEdge1->tag()); - zoneBoVec.push_back(VertexBoundary(zoneIndex, gEdge2->tag(), - boNormal2, - const_cast<MVertex*>(vertex), - vertIndex)); - patch.add(gEdge2->tag()); - } - else { - -//--Write one patch - - boNormal1 += boNormal2; - boNormal1 *= 0.5; - zoneBoVec.push_back(VertexBoundary(zoneIndex, gEdge1->tag(), - boNormal1, - const_cast<MVertex*>(vertex), - vertIndex)); - patch.addPair(gEdge1->tag(), gEdge2->tag()); - } + else { + //--Write one patch + + boNormal1 += boNormal2; + boNormal1 *= 0.5; + zoneBoVec.push_back( + VertexBoundary(zoneIndex, gEdge1->tag(), boNormal1, + const_cast<MVertex *>(vertex), vertIndex)); + patch.addPair(gEdge1->tag(), gEdge2->tag()); } - break; + } break; default: Msg::Error("Internal error based on 2-D boundary assumptions (file " @@ -404,34 +378,33 @@ void updateBoVec<2, MEdge> break; case 1: -/*--------------------------------------------------------------------* - * The vertex exists on an edge and belongs to only 1 BC patch. - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * The vertex exists on an edge and belongs to only 1 BC patch. + *--------------------------------------------------------------------*/ { SVector3 boNormal; - if(edge_normal(vertex, zoneIndex, static_cast<const GEdge*>(ent), faces, - boNormal)) + if(edge_normal(vertex, zoneIndex, static_cast<const GEdge *>(ent), + faces, boNormal)) goto getNormalFromElements; zoneBoVec.push_back(VertexBoundary(zoneIndex, ent->tag(), boNormal, - const_cast<MVertex*>(vertex), + const_cast<MVertex *>(vertex), vertIndex)); patch.add(ent->tag()); } break; - default: - goto getNormalFromElements; + default: goto getNormalFromElements; } } return; - getNormalFromElements: ; +getNormalFromElements:; -/*--------------------------------------------------------------------* - * Geometry information cannot be used - generate normals from the - * elements - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * Geometry information cannot be used - generate normals from the + * elements + *--------------------------------------------------------------------*/ { if(warnNormFromElem && normalSource == 1) { @@ -441,13 +414,13 @@ void updateBoVec<2, MEdge> } // The mesh plane normal is computed from all elements attached to the // vertex - SVector3 meshPlaneNormal(0.); // This normal is perpendicular to the - // plane of the mesh + SVector3 meshPlaneNormal(0.); // This normal is perpendicular to the + // plane of the mesh const int nFace = faces.size(); for(int iFace = 0; iFace != nFace; ++iFace) { if(faces[iFace].zoneIndex == zoneIndex) { - // Make sure all the planes go in the same direction - //**Required? + // Make sure all the planes go in the same direction + //**Required? SVector3 mpnt = faces[iFace].parentElement->getFace(0).normal(); if(dot(mpnt, meshPlaneNormal) < 0.) mpnt.negate(); meshPlaneNormal += mpnt; @@ -460,8 +433,10 @@ void updateBoVec<2, MEdge> SVector3 boNormal(0.); for(int iFace = 0; iFace != nFace; ++iFace) { if(faces[iFace].zoneIndex == zoneIndex) { - const SVector3 tangent = faces[iFace].parentElement->getEdge - (faces[iFace].parentFace).tangent(); + const SVector3 tangent = + faces[iFace] + .parentElement->getEdge(faces[iFace].parentFace) + .tangent(); // Normal to the boundary (unknown direction) SVector3 bnt = crossprod(tangent, meshPlaneNormal); // Inwards normal @@ -472,14 +447,12 @@ void updateBoVec<2, MEdge> } } boNormal.normalize(); - zoneBoVec.push_back(VertexBoundary(zoneIndex, 0, boNormal, - const_cast<MVertex*>(vertex), - vertIndex)); + zoneBoVec.push_back(VertexBoundary( + zoneIndex, 0, boNormal, const_cast<MVertex *>(vertex), vertIndex)); patch.add(0); } } - /******************************************************************************* * * Routine updateBoVec - SPECIALIZED for 3D @@ -499,13 +472,13 @@ void updateBoVec<2, MEdge> ******************************************************************************/ template <> -void updateBoVec<3, MFace> -(const int normalSource, const MVertex *const vertex, const int zoneIndex, - const int vertIndex, - const CCon::FaceVector<MZoneBoundary<3>::GlobalVertexData<MFace>::FaceDataB> - &faces, ZoneBoVec &zoneBoVec, BCPatchIndex &patch, bool &warnNormFromElem) +void updateBoVec<3, MFace>( + const int normalSource, const MVertex *const vertex, const int zoneIndex, + const int vertIndex, + const CCon::FaceVector<MZoneBoundary<3>::GlobalVertexData<MFace>::FaceDataB> + &faces, + ZoneBoVec &zoneBoVec, BCPatchIndex &patch, bool &warnNormFromElem) { - GEntity *ent; if(normalSource == NormalSourceElement) goto getNormalFromElements; ent = vertex->onWhat(); @@ -518,60 +491,57 @@ void updateBoVec<3, MFace> case 0: case 1: -/*--------------------------------------------------------------------* - * In this case, there are possibly multiple GFaces from this zone - * connected to the vertex. One patch for each GFace will be written. - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * In this case, there are possibly multiple GFaces from this zone + * connected to the vertex. One patch for each GFace will be written. + *--------------------------------------------------------------------*/ { + //--Get a list of face entities connected to 'ent' -//--Get a list of face entities connected to 'ent' - - std::list<GFace*> gFaceList; + std::list<GFace *> gFaceList; switch(ent->dim()) { - case 0: - { - std::vector<GEdge*> gEdgeList = ent->edges(); - std::list<GFace*> gFaceList; - for(std::vector<GEdge*>::const_iterator gEIt = gEdgeList.begin(); - gEIt != gEdgeList.end(); ++gEIt) { - std::vector<GFace*> alist = (*gEIt)->faces(); - gFaceList.insert(gFaceList.end(), alist.begin(), alist.end()); - } - // Remove duplicates - gFaceList.sort(); - gFaceList.unique(); + case 0: { + std::vector<GEdge *> gEdgeList = ent->edges(); + std::list<GFace *> gFaceList; + for(std::vector<GEdge *>::const_iterator gEIt = gEdgeList.begin(); + gEIt != gEdgeList.end(); ++gEIt) { + std::vector<GFace *> alist = (*gEIt)->faces(); + gFaceList.insert(gFaceList.end(), alist.begin(), alist.end()); } - break; - case 1: - { - std::vector<GFace*> fac = ent->faces(); - gFaceList.insert(gFaceList.end(), fac.begin(), fac.end()); - } - break; + // Remove duplicates + gFaceList.sort(); + gFaceList.unique(); + } break; + case 1: { + std::vector<GFace *> fac = ent->faces(); + gFaceList.insert(gFaceList.end(), fac.begin(), fac.end()); + } break; } -//--Get a list of face entities connected to the 'vertex' that are also in the -//--zone + //--Get a list of face entities connected to the 'vertex' that are also + //in the + //--zone - std::list<const GFace*> useGFace; - std::vector<GEdge*> gEdgeList; + std::list<const GFace *> useGFace; + std::vector<GEdge *> gEdgeList; const int nFace = faces.size(); for(int iFace = 0; iFace != nFace; ++iFace) { if(zoneIndex == faces[iFace].zoneIndex) { bool matchedFace = false; - MFace mFace = faces[iFace].parentElement->getFace - (faces[iFace].parentFace); + MFace mFace = + faces[iFace].parentElement->getFace(faces[iFace].parentFace); const int nVOnF = mFace.getNumVertices(); - int vertexOnF; // The index of 'vertex' in the face + int vertexOnF; // The index of 'vertex' in the face for(int iVOnF = 0; iVOnF != nVOnF; ++iVOnF) { const MVertex *const vertex2 = mFace.getVertex(iVOnF); - if(vertex == vertex2) vertexOnF = iVOnF; + if(vertex == vertex2) + vertexOnF = iVOnF; else { const GEntity *const ent2 = vertex2->onWhat(); if(ent2->dim() == 2) { matchedFace = true; - useGFace.push_back(static_cast<const GFace*>(ent2)); + useGFace.push_back(static_cast<const GFace *>(ent2)); break; } } @@ -606,13 +576,13 @@ void updateBoVec<3, MFace> const GEntity *const ent3 = vertex3->onWhat(); if(ent2->dim() == 1 && ent3->dim() == 1) { // Which GFace is bounded by edges ent2 and ent3? - for(std::list<GFace*>::const_iterator gFIt = gFaceList.begin(); + for(std::list<GFace *>::const_iterator gFIt = gFaceList.begin(); gFIt != gFaceList.end(); ++gFIt) { gEdgeList = (*gFIt)->edges(); - if((std::find(gEdgeList.begin(), gEdgeList.end(), ent2) - != gEdgeList.end()) && - (std::find(gEdgeList.begin(), gEdgeList.end(), ent3) - != gEdgeList.end())) { + if((std::find(gEdgeList.begin(), gEdgeList.end(), ent2) != + gEdgeList.end()) && + (std::find(gEdgeList.begin(), gEdgeList.end(), ent3) != + gEdgeList.end())) { // Edges ent2 and ent3 bound this face useGFace.push_back(*gFIt); break; @@ -621,36 +591,39 @@ void updateBoVec<3, MFace> } else if(ent->dim() == 1 && (ent2->dim() + ent3->dim() == 1)) { const GEntity *entCmp; - if(ent2->dim() == 1) entCmp = ent2; - else entCmp = ent3; + if(ent2->dim() == 1) + entCmp = ent2; + else + entCmp = ent3; // Which GFace is bounded by entCmp - for(std::list<GFace*>::const_iterator gFIt = gFaceList.begin(); + for(std::list<GFace *>::const_iterator gFIt = gFaceList.begin(); gFIt != gFaceList.end(); ++gFIt) { gEdgeList = (*gFIt)->edges(); - if(std::find(gEdgeList.begin(), gEdgeList.end(), entCmp) - != gEdgeList.end()) { + if(std::find(gEdgeList.begin(), gEdgeList.end(), entCmp) != + gEdgeList.end()) { // Edge entCmp and the original edge bound this face useGFace.push_back(*gFIt); break; } } } - } // Stupid triangles - } // End if face in zone - } // End loop over faces + } // Stupid triangles + } // End if face in zone + } // End loop over faces // Duplicates are a possibility, remove useGFace.sort(); useGFace.unique(); -//--'useGFace' now contains the face entities that connect to vertex. A BC -//--patch will be written for each of them. + //--'useGFace' now contains the face entities that connect to vertex. A + //BC + //--patch will be written for each of them. - for(std::list<const GFace*>::const_iterator gFIt = useGFace.begin(); + for(std::list<const GFace *>::const_iterator gFIt = useGFace.begin(); gFIt != useGFace.end(); ++gFIt) { - SPoint2 par; - if(!reparamMeshVertexOnFace(const_cast<MVertex*>(vertex), *gFIt, par)) - goto getNormalFromElements; // :P After all that! + if(!reparamMeshVertexOnFace(const_cast<MVertex *>(vertex), *gFIt, + par)) + goto getNormalFromElements; // :P After all that! SVector3 boNormal = (*gFIt)->normal(par); SPoint3 interior(0., 0., 0.); @@ -666,29 +639,28 @@ void updateBoVec<3, MFace> if(dot(boNormal, SVector3(vertex->point(), interior)) < 0.) boNormal.negate(); - zoneBoVec.push_back(VertexBoundary(zoneIndex, (*gFIt)->tag(), - boNormal, - const_cast<MVertex*>(vertex), - vertIndex)); + zoneBoVec.push_back( + VertexBoundary(zoneIndex, (*gFIt)->tag(), boNormal, + const_cast<MVertex *>(vertex), vertIndex)); patch.add((*gFIt)->tag()); } } break; case 2: -/*--------------------------------------------------------------------* - * The vertex exists on a face and belongs to only 1 BC patch. - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * The vertex exists on a face and belongs to only 1 BC patch. + *--------------------------------------------------------------------*/ { - const GFace *const gFace = static_cast<const GFace*>(ent); + const GFace *const gFace = static_cast<const GFace *>(ent); SPoint2 par; - if(!reparamMeshVertexOnFace(const_cast<MVertex*>(vertex), gFace, par)) + if(!reparamMeshVertexOnFace(const_cast<MVertex *>(vertex), gFace, par)) goto getNormalFromElements; - SVector3 boNormal = static_cast<const GFace*>(ent)->normal(par); + SVector3 boNormal = static_cast<const GFace *>(ent)->normal(par); SPoint3 interior(0., 0., 0.); - int cFace = 0; + int cFace = 0; const int nFace = faces.size(); for(int iFace = 0; iFace != nFace; ++iFace) { if(faces[iFace].zoneIndex == zoneIndex) { @@ -701,23 +673,22 @@ void updateBoVec<3, MFace> boNormal.negate(); zoneBoVec.push_back(VertexBoundary(zoneIndex, gFace->tag(), boNormal, - const_cast<MVertex*>(vertex), + const_cast<MVertex *>(vertex), vertIndex)); patch.add(gFace->tag()); } break; - default: - goto getNormalFromElements; + default: goto getNormalFromElements; } } return; - getNormalFromElements: ; +getNormalFromElements:; -/*--------------------------------------------------------------------* - * Geometry information cannot be used - generate normals from the - * elements - *--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------* + * Geometry information cannot be used - generate normals from the + * elements + *--------------------------------------------------------------------*/ { if(warnNormFromElem && normalSource == 1) { @@ -734,8 +705,8 @@ void updateBoVec<3, MFace> for(int iFace = 0; iFace != nFace; ++iFace) { if(faces[iFace].zoneIndex == zoneIndex) { // Normal to the boundary (unknown direction) - SVector3 bnt = faces[iFace].parentElement->getFace - (faces[iFace].parentFace).normal(); + SVector3 bnt = + faces[iFace].parentElement->getFace(faces[iFace].parentFace).normal(); // Inwards normal const SVector3 inwards(vertex->point(), faces[iFace].parentElement->barycenter()); @@ -744,22 +715,18 @@ void updateBoVec<3, MFace> } } boNormal.normalize(); - zoneBoVec.push_back(VertexBoundary(zoneIndex, 0, boNormal, - const_cast<MVertex*>(vertex), - vertIndex)); + zoneBoVec.push_back(VertexBoundary( + zoneIndex, 0, boNormal, const_cast<MVertex *>(vertex), vertIndex)); patch.add(0); } - } - /******************************************************************************* * * Routines from class MZoneBoundary * ******************************************************************************/ - /*============================================================================== * * Routine: interiorBoundaryVertices @@ -784,49 +751,48 @@ void updateBoVec<3, MFace> *============================================================================*/ template <unsigned DIM> -int MZoneBoundary<DIM>::interiorBoundaryVertices -(const int newZoneIndex, const MZone<DIM> &mZone, ZoneConnMap &zoneConnMap) +int MZoneBoundary<DIM>::interiorBoundaryVertices(const int newZoneIndex, + const MZone<DIM> &mZone, + ZoneConnMap &zoneConnMap) { - if(mZone.boVertMap.size() == 0) return 1; zoneConnMap.clear(); // Loop over all the boundary vertices in 'mZone' for(typename MZone<DIM>::BoVertexMap::const_iterator vMapIt = - mZone.boVertMap.begin(); vMapIt != mZone.boVertMap.end(); ++vMapIt) { - -//--Find or insert this vertex into the global map - -// bool debug = false; -// if(vMapIt->first->x() == 1. && vMapIt->first->y() == 0.) { -// std::cout << "Working with vertex(1, 0): " << vMapIt->first -// << " for zone " << newZoneIndex << std::endl; -// debug = true; -// } + mZone.boVertMap.begin(); + vMapIt != mZone.boVertMap.end(); ++vMapIt) { + //--Find or insert this vertex into the global map + + // bool debug = false; + // if(vMapIt->first->x() == 1. && vMapIt->first->y() == 0.) { + // std::cout << "Working with vertex(1, 0): " << vMapIt->first + // << " for zone " << newZoneIndex << std::endl; + // debug = true; + // } std::pair<typename GlobalBoVertexMap::iterator, bool> insGblBoVertMap = - globalBoVertMap.insert(std::pair<const MVertex*, GlobalVertexData<FaceT> > - (vMapIt->first, GlobalVertexData<FaceT>())); + globalBoVertMap.insert( + std::pair<const MVertex *, GlobalVertexData<FaceT> >( + vMapIt->first, GlobalVertexData<FaceT>())); GlobalVertexData<FaceT> &globalVertData = insGblBoVertMap.first->second; - // Ref. to the global boundary vertex - // data + // Ref. to the global boundary vertex + // data const ZoneVertexData<typename MZone<DIM>::BoFaceMap::const_iterator> - &zoneVertData = vMapIt->second; // Ref. to boundary vertex data for a - // zone + &zoneVertData = vMapIt->second; // Ref. to boundary vertex data for a + // zone if(insGblBoVertMap.second) { - -//--A new vertex was inserted + //--A new vertex was inserted // Copy faces const int nFace = zoneVertData.faces.size(); for(int iFace = 0; iFace != nFace; ++iFace) { - -#if (0) +#if(0) // NBN: changing the member object for a pointer means // we need to do the following in two steps (see below) - globalVertData.faces.push_back - (typename GlobalVertexData<FaceT>::FaceDataB - (newZoneIndex, zoneVertData.faces[iFace])); + globalVertData.faces.push_back( + typename GlobalVertexData<FaceT>::FaceDataB( + newZoneIndex, zoneVertData.faces[iFace])); #else // Using FaceAllocator<T> with face2Pool, the std constructors @@ -842,88 +808,86 @@ int MZoneBoundary<DIM>::interiorBoundaryVertices // See adjusted version of MZoneBoundary::clear(); // Step 1: append new FaceDataB<> object - typename GlobalVertexData<FaceT>::FaceDataB& tFDB = - globalVertData.faces.push_back - (typename GlobalVertexData<FaceT>::FaceDataB - (newZoneIndex, zoneVertData.faces[iFace]) ); + typename GlobalVertexData<FaceT>::FaceDataB &tFDB = + globalVertData.faces.push_back( + typename GlobalVertexData<FaceT>::FaceDataB( + newZoneIndex, zoneVertData.faces[iFace])); // Step 2: construct its internal face object tFDB.face = new FaceT(zoneVertData.faces[iFace]->first); - #if (DEBUG_FaceT) - if (! tFDB.face) { - Msg::Info("MZoneBoundary<DIM>::interiorBoundaryVertices, failed to alloc face object"); - } else { +#if(DEBUG_FaceT) + if(!tFDB.face) { + Msg::Info("MZoneBoundary<DIM>::interiorBoundaryVertices, failed to " + "alloc face object"); + } + else { int nv = tFDB.face->getNumVertices(); - Msg::Info("interiorBoundaryVertices: allocated FaceT object %5d with %d verts", ++iCount, nv); + Msg::Info("interiorBoundaryVertices: allocated FaceT object %5d with " + "%d verts", + ++iCount, nv); } - #endif - +#endif #endif } // Copy information about the vertex in the zone - globalVertData.zoneData.push_back - (typename GlobalVertexData<FaceT>::ZoneData - (zoneVertData.index, newZoneIndex)); + globalVertData.zoneData.push_back( + typename GlobalVertexData<FaceT>::ZoneData(zoneVertData.index, + newZoneIndex)); } else { - -//--This vertex already exists and zone connectivity must be determined + //--This vertex already exists and zone connectivity must be determined // Add to the zone connectivity const int nPrevZone = globalVertData.zoneData.size(); for(int iPrevZone = 0; iPrevZone != nPrevZone; ++iPrevZone) { - ZoneConnectivity &zoneConn = - zoneConnMap[ZonePair(globalVertData.zoneData[iPrevZone].zoneIndex, - newZoneIndex)]; - zoneConn.vertexPairVec.push_back - (ZoneConnectivity::VertexPair - // const_cast okay, no changes to keys in 'globalBoVertMap' - (const_cast<MVertex*>(insGblBoVertMap.first->first), - globalVertData.zoneData[iPrevZone].zoneIndex, - newZoneIndex, - globalVertData.zoneData[iPrevZone].vertexIndex, - zoneVertData.index)); + ZoneConnectivity &zoneConn = zoneConnMap[ZonePair( + globalVertData.zoneData[iPrevZone].zoneIndex, newZoneIndex)]; + zoneConn.vertexPairVec.push_back( + ZoneConnectivity::VertexPair + // const_cast okay, no changes to keys in 'globalBoVertMap' + (const_cast<MVertex *>(insGblBoVertMap.first->first), + globalVertData.zoneData[iPrevZone].zoneIndex, newZoneIndex, + globalVertData.zoneData[iPrevZone].vertexIndex, zoneVertData.index)); } // Update the list of faces attached to this vertex unsigned nGFace = globalVertData.faces.size(); - // This is the number of faces searched - // from 'globalVertData'. It will only - // decrease if the size() is less. - // Since a FaceVector swaps the last - // element into the erased index, this - // implies that if new faces are added, - // then old ones deleted, some of the - // faces from zoneVertData may also be - // searched. This is okay since they - // are all unique. + // This is the number of faces searched + // from 'globalVertData'. It will only + // decrease if the size() is less. + // Since a FaceVector swaps the last + // element into the erased index, this + // implies that if new faces are added, + // then old ones deleted, some of the + // faces from zoneVertData may also be + // searched. This is okay since they + // are all unique. const typename MZone<DIM>::BoFaceMap::const_iterator *zFace = &zoneVertData.faces[0]; for(int nZFace = zoneVertData.faces.size(); nZFace--;) { bool foundMatch = false; - for(unsigned int iGFace = 0; iGFace != nGFace; ++iGFace) - { + for(unsigned int iGFace = 0; iGFace != nGFace; ++iGFace) { // NBN: face is now a pointer, so need to de-reference - //if((*zFace)->first == globalVertData.faces[iGFace].face ) - if(globalVertData.faces[iGFace].face){ - if((*zFace)->first == *(globalVertData.faces[iGFace].face)) { - foundMatch = true; - // Faces match - delete from 'globalVertData'. - globalVertData.faces.erase(iGFace); - // Erasing from the FaceVector swaps the last element into this - // index. We only decrease nGFace if the size is less. - nGFace = std::min(globalVertData.faces.size(), nGFace); - break; - } + // if((*zFace)->first == globalVertData.faces[iGFace].face ) + if(globalVertData.faces[iGFace].face) { + if((*zFace)->first == *(globalVertData.faces[iGFace].face)) { + foundMatch = true; + // Faces match - delete from 'globalVertData'. + globalVertData.faces.erase(iGFace); + // Erasing from the FaceVector swaps the last element into this + // index. We only decrease nGFace if the size is less. + nGFace = std::min(globalVertData.faces.size(), nGFace); + break; } + } } if(!foundMatch) { // New face - add to 'globalVertData' - globalVertData.faces.push_back - (typename GlobalVertexData<FaceT>::FaceDataB(newZoneIndex, *zFace)); + globalVertData.faces.push_back( + typename GlobalVertexData<FaceT>::FaceDataB(newZoneIndex, *zFace)); } ++zFace; } @@ -935,18 +899,16 @@ int MZoneBoundary<DIM>::interiorBoundaryVertices } else { // Update the list of zones attached to this vertex - globalVertData.zoneData.push_back - (typename GlobalVertexData<FaceT>::ZoneData - (zoneVertData.index, newZoneIndex)); + globalVertData.zoneData.push_back( + typename GlobalVertexData<FaceT>::ZoneData(zoneVertData.index, + newZoneIndex)); } } - } // End loop over boundary vertices + } // End loop over boundary vertices return 0; - } - /*============================================================================== * * Routine: exteriorBoundaryVertices @@ -979,32 +941,32 @@ int MZoneBoundary<DIM>::interiorBoundaryVertices ******************************************************************************/ template <unsigned DIM> -int MZoneBoundary<DIM>::exteriorBoundaryVertices -(const int normalSource, ZoneBoVec &zoneBoVec) +int MZoneBoundary<DIM>::exteriorBoundaryVertices(const int normalSource, + ZoneBoVec &zoneBoVec) { - if(globalBoVertMap.size() == 0) return 1; zoneBoVec.clear(); - zoneBoVec.reserve(3*globalBoVertMap.size()/2); + zoneBoVec.reserve(3 * globalBoVertMap.size() / 2); - BCPatchIndex patch; // Provides a BC patch index for each - // entity - bool warnNormFromElem = true; // A warning that normals were - // determined from elements. This - // warning is only give once (after - // which the flag is set to false) + BCPatchIndex patch; // Provides a BC patch index for each + // entity + bool warnNormFromElem = true; // A warning that normals were + // determined from elements. This + // warning is only give once (after + // which the flag is set to false) const typename GlobalBoVertexMap::const_iterator vMapEnd = globalBoVertMap.end(); for(typename GlobalBoVertexMap::const_iterator vMapIt = - globalBoVertMap.begin(); vMapIt != vMapEnd; ++vMapIt) { + globalBoVertMap.begin(); + vMapIt != vMapEnd; ++vMapIt) { const int nZone = vMapIt->second.zoneData.size(); for(int iZone = 0; iZone != nZone; ++iZone) { const typename GlobalVertexData<FaceT>::ZoneData &zoneData = vMapIt->second.zoneData[iZone]; // Ref. to data stored for this zone -//--Try to find an outwards normal for this vertex + //--Try to find an outwards normal for this vertex if(normalSource) { updateBoVec<DIM, FaceT>(normalSource, vMapIt->first, zoneData.zoneIndex, @@ -1014,7 +976,7 @@ int MZoneBoundary<DIM>::exteriorBoundaryVertices else { // Keys to 'globalBoVertMap' will not change so const_cast is okay. zoneBoVec.push_back(VertexBoundary(zoneData.zoneIndex, 0, SVector3(0.), - const_cast<MVertex*>(vMapIt->first), + const_cast<MVertex *>(vMapIt->first), zoneData.vertexIndex)); } } @@ -1034,10 +996,8 @@ int MZoneBoundary<DIM>::exteriorBoundaryVertices } return 0; - } - /******************************************************************************* * * Specialization of constructor @@ -1048,30 +1008,25 @@ int MZoneBoundary<DIM>::exteriorBoundaryVertices * ******************************************************************************/ -template<> -template<> +template <> +template <> MZoneBoundary<2>::GlobalVertexData<MEdge>::FaceDataB::FaceDataB() - : - //face(0, 0), // NBN: replaced this MEdge object - face(NULL), // NBN: with a pointer to MEdge - parentElement(0), // NBN: also, init members - parentFace(0), - faceIndex(0), - zoneIndex(0) -{ } - -template<> -template<> -MZoneBoundary<3>::GlobalVertexData<MFace>::FaceDataB::FaceDataB() - : - //face(0, 0, 0), // NBN: replaced this MFace object - face(NULL), // NBN: with a pointer to MFace - parentElement(0), // NBN: also, init members - parentFace(0), - faceIndex(0), - zoneIndex(0) -{ } + : // face(0, 0), // NBN: replaced this MEdge object + face(NULL), // NBN: with a pointer to MEdge + parentElement(0), // NBN: also, init members + parentFace(0), faceIndex(0), zoneIndex(0) +{ +} +template <> +template <> +MZoneBoundary<3>::GlobalVertexData<MFace>::FaceDataB::FaceDataB() + : // face(0, 0, 0), // NBN: replaced this MFace object + face(NULL), // NBN: with a pointer to MFace + parentElement(0), // NBN: also, init members + parentFace(0), faceIndex(0), zoneIndex(0) +{ +} /******************************************************************************* * diff --git a/Geo/MZoneBoundary.h b/Geo/MZoneBoundary.h index ce8c5162094bef7821f8a4d1a76b3c5e3b96cdb5..31a97f84fbc5b0426afca823bce2f89b58013bde 100644 --- a/Geo/MZoneBoundary.h +++ b/Geo/MZoneBoundary.h @@ -17,7 +17,6 @@ #include "MZone.h" - /*============================================================================== * Required types *============================================================================*/ @@ -28,11 +27,10 @@ //--Interface between two zones for connectivity -struct ZonePair -{ +struct ZonePair { int zone1; int zone2; - ZonePair(const int _zone1, const int _zone2) + ZonePair(const int _zone1, const int _zone2) { if(_zone1 < _zone2) { zone1 = _zone1; @@ -47,13 +45,11 @@ struct ZonePair inline bool operator==(const ZonePair &zpA, const ZonePair &zpB) { - return (zpA.zone1 == zpB.zone1 && zpA.zone2 == zpB.zone2); + return (zpA.zone1 == zpB.zone1 && zpA.zone2 == zpB.zone2); } // Less than for std::map -struct Less_ZonePair - : public std::binary_function<ZonePair, ZonePair, bool> -{ +struct Less_ZonePair : public std::binary_function<ZonePair, ZonePair, bool> { bool operator()(const ZonePair &zpA, const ZonePair &zpB) const { if(zpA.zone1 < zpB.zone1) return true; @@ -65,24 +61,20 @@ struct Less_ZonePair //--Definition of the zone connectivity (a vector of vertex pairs for 2 zones). -struct ZoneConnectivity -{ +struct ZoneConnectivity { // Internal structures - struct VertexPair // Pairs of vertices. Ordered based on - // zone indices. + struct VertexPair // Pairs of vertices. Ordered based on + // zone indices. { MVertex *vertex; int vertexIndex1; int vertexIndex2; // Constructors - VertexPair() - : vertex(0), vertexIndex1(0), vertexIndex2(0) - { } - VertexPair(MVertex *const _vertex, - const int zone1, const int zone2, + VertexPair() : vertex(0), vertexIndex1(0), vertexIndex2(0) {} + VertexPair(MVertex *const _vertex, const int zone1, const int zone2, const int _vertexIndex1, const int _vertexIndex2) - : vertex(_vertex), - vertexIndex1(_vertexIndex1), vertexIndex2(_vertexIndex2) + : vertex(_vertex), vertexIndex1(_vertexIndex1), + vertexIndex2(_vertexIndex2) { if(zone2 < zone1) { vertexIndex1 = _vertexIndex2; @@ -95,24 +87,21 @@ struct ZoneConnectivity // Constructor ZoneConnectivity() { - vertexPairVec.reserve(32); // Avoid small reallocations by push_back() + vertexPairVec.reserve(32); // Avoid small reallocations by push_back() } }; -struct ZoneConnectivityByElem -{ +struct ZoneConnectivityByElem { // Internal structures - struct ElementPair // Pairs of elements. Ordered based on - // zone indices + struct ElementPair // Pairs of elements. Ordered based on + // zone indices { int elemIndex1; int elemIndex2; // Constructors - ElementPair() - : elemIndex1(0), elemIndex2(0) - { } - ElementPair(const int zone1, const int zone2, - const int _elemIndex1, const int _elemIndex2) + ElementPair() : elemIndex1(0), elemIndex2(0) {} + ElementPair(const int zone1, const int zone2, const int _elemIndex1, + const int _elemIndex2) : elemIndex1(_elemIndex1), elemIndex2(_elemIndex2) { if(zone2 < zone1) { @@ -126,7 +115,7 @@ struct ZoneConnectivityByElem // Constructor ZoneConnectivityByElem() { - elemPairVec.reserve(32); // Avoid small reallocations by push_back() + elemPairVec.reserve(32); // Avoid small reallocations by push_back() } }; @@ -138,23 +127,21 @@ typedef std::map<ZonePair, ZoneConnectivity, Less_ZonePair> ZoneConnMap; * Boundaries at the domain extent *--------------------------------------------------------------------*/ -struct VertexBoundary -{ +struct VertexBoundary { int zoneIndex; int bcPatchIndex; SVector3 normal; MVertex *vertex; int vertexIndex; // Constructors - VertexBoundary() - : vertex(0), vertexIndex(0) - { } + VertexBoundary() : vertex(0), vertexIndex(0) {} VertexBoundary(const int _zoneIndex, const int _bcPatchIndex, const SVector3 &_normal, MVertex *const _vertex, const int _vertexIndex) : zoneIndex(_zoneIndex), bcPatchIndex(_bcPatchIndex), normal(_normal), vertex(_vertex), vertexIndex(_vertexIndex) - { } + { + } }; typedef std::vector<VertexBoundary> ZoneBoVec; @@ -162,39 +149,34 @@ typedef std::vector<VertexBoundary> ZoneBoVec; //--Function object for sorting the ZoneBoVec vector by zone and then BC patch //--index -struct ZoneBoVecSort -{ +struct ZoneBoVecSort { bool operator()(const int i0, const int i1) { if(zoneBoVec[i0].zoneIndex == zoneBoVec[i1].zoneIndex) return zoneBoVec[i0].bcPatchIndex < zoneBoVec[i1].bcPatchIndex; return zoneBoVec[i0].zoneIndex < zoneBoVec[i1].zoneIndex; } - ZoneBoVecSort(const ZoneBoVec &_zoneBoVec) - : zoneBoVec(_zoneBoVec) - { } - private: + ZoneBoVecSort(const ZoneBoVec &_zoneBoVec) : zoneBoVec(_zoneBoVec) {} + +private: const ZoneBoVec &zoneBoVec; }; -struct ElementBoundary -{ +struct ElementBoundary { int zoneIndex; int bcPatchIndex; SVector3 normal; int elemIndex; // Constructors - ElementBoundary() - : elemIndex(0) - { } + ElementBoundary() : elemIndex(0) {} ElementBoundary(const int _zoneIndex, const int _bcPatchIndex, const SVector3 &_normal, const int _elemIndex) : zoneIndex(_zoneIndex), bcPatchIndex(_bcPatchIndex), normal(_normal), elemIndex(_elemIndex) - { } + { + } }; - /******************************************************************************* * * class: MZoneBoundary @@ -218,41 +200,32 @@ struct ElementBoundary * ******************************************************************************/ -template <unsigned DIM> -class MZoneBoundary -{ - - -/*============================================================================== - * Internal types - *============================================================================*/ - -//--Type of face (MEdge or MFace) +template <unsigned DIM> class MZoneBoundary { + /*============================================================================== + * Internal types + *============================================================================*/ - private: + //--Type of face (MEdge or MFace) +private: typedef typename DimTr<DIM>::FaceT FaceT; -//--Data stored for connectivity of vertices - - public: + //--Data stored for connectivity of vertices - template<typename FaceT> - struct GlobalVertexData - { - struct FaceDataB - { - // NBN: cannot use a FaceT object in FaceVector. +public: + template <typename FaceT> struct GlobalVertexData { + struct FaceDataB { + // NBN: cannot use a FaceT object in FaceVector. // class FaceT has embedded std::vector objects; // custom allocator for FaceVector<T> does not call ctors, // but std:: dtors will try to delete _v, _si - // - // Simple fix: use a pointer to FaceT, then build the - // FaceT object once the FaceDataB structure has been + // + // Simple fix: use a pointer to FaceT, then build the + // FaceT object once the FaceDataB structure has been // safely added to the container (push_back) - //FaceT face; // NBN: FaceT contains std:: containers - FaceT* face; // NBN: use FaceT* (then init in two steps) + // FaceT face; // NBN: FaceT contains std:: containers + FaceT *face; // NBN: use FaceT* (then init in two steps) MElement *parentElement; int parentFace; @@ -260,75 +233,74 @@ class MZoneBoundary int zoneIndex; FaceDataB(const int _zoneIndex, const typename MZone<DIM>::BoFaceMap::const_iterator bFMapIt) - : - //face(bFMapIt->first), - face(NULL), // NBN: need to load this after insertion into container - parentElement(bFMapIt->second.parentElement), - parentFace(bFMapIt->second.parentFace), - faceIndex(bFMapIt->second.faceIndex), zoneIndex(_zoneIndex) - { } -// private: // Default constructor should be private ... but currently - // fails on some compilers (earlier versions of g++?) + : // face(bFMapIt->first), + face(NULL), // NBN: need to load this after insertion into container + parentElement(bFMapIt->second.parentElement), + parentFace(bFMapIt->second.parentFace), + faceIndex(bFMapIt->second.faceIndex), zoneIndex(_zoneIndex) + { + } + // private: // Default constructor should be private ... but + // currently + // fails on some compilers (earlier versions of g++?) // The default constructor is required by 'set_offsets()' in // class 'FaceAllocator'. This is invoked by preInit() below. FaceDataB(); friend class CCon::FaceAllocator<FaceDataB>; }; - struct ZoneData - { + struct ZoneData { int vertexIndex; int zoneIndex; ZoneData(const int _vertexIndex, const int _zoneIndex) : vertexIndex(_vertexIndex), zoneIndex(_zoneIndex) - { } -// private: // Default constructor should be private ... but currently - // fails on some compilers (earlier versions of g++?) + { + } + // private: // Default constructor should be private ... but + // currently + // fails on some compilers (earlier versions of g++?) // The default constructor is required by 'set_offsets()' in // class 'FaceAllocator'. This is invoked by preInit() below. - ZoneData() - : vertexIndex(0), zoneIndex(0) // NBN: init members - { } + ZoneData() : vertexIndex(0), zoneIndex(0) // NBN: init members + { + } friend class CCon::FaceAllocator<ZoneData>; }; CCon::FaceVector<FaceDataB> faces; CCon::FaceVector<ZoneData> zoneData; - // A 'FaceVector' is not strictly - // optimized for the vertices but should - // still work quite well. + // A 'FaceVector' is not strictly + // optimized for the vertices but should + // still work quite well. // Constructor - GlobalVertexData() { } + GlobalVertexData() {} }; - private: - - typedef std::map<const MVertex*, GlobalVertexData<FaceT>, - std::less<const MVertex*> > GlobalBoVertexMap; - - -/*============================================================================== - * Member functions - *============================================================================*/ +private: + typedef std::map<const MVertex *, GlobalVertexData<FaceT>, + std::less<const MVertex *> > + GlobalBoVertexMap; - public: + /*============================================================================== + * Member functions + *============================================================================*/ -//--Reset the database +public: + //--Reset the database void clear() { // NBN: using FaceT* so need to dealloc: int icount = 0; typename GlobalBoVertexMap::iterator itEnd = globalBoVertMap.end(); - for (typename GlobalBoVertexMap::iterator itBoV = globalBoVertMap.begin(); - itBoV != itEnd; ++itBoV) - { + for(typename GlobalBoVertexMap::iterator itBoV = globalBoVertMap.begin(); + itBoV != itEnd; ++itBoV) { // ... clear the faces - GlobalVertexData<FaceT>& ref = itBoV->second; + GlobalVertexData<FaceT> &ref = itBoV->second; size_t nf = ref.faces.size(); - for (unsigned int i=0; i<nf; ++i) { - ++ icount; - FaceT* p = ref.faces[i].face; - if (p) { - delete (p); + for(unsigned int i = 0; i < nf; ++i) { + ++icount; + FaceT *p = ref.faces[i].face; + if(p) { + delete(p); p = NULL; } } @@ -339,45 +311,43 @@ class MZoneBoundary globalBoVertMap.clear(); } -//--Add a zone to the global map of boundary vertices and return connectivity -//--between zones. + //--Add a zone to the global map of boundary vertices and return connectivity + //--between zones. int interiorBoundaryVertices(const int newZoneIndex, const MZone<DIM> &mZone, ZoneConnMap &zoneConnMap); - -//--Return exterior boundary vertices (unconnected vertices at the extent of the -//--domain + + //--Return exterior boundary vertices (unconnected vertices at the extent of + //the + //--domain int exteriorBoundaryVertices(const int normalSource, ZoneBoVec &zoneBoVec); -//--Memory management + //--Memory management static void preInit() { - CCon::FaceVector<typename GlobalVertexData<FaceT>::FaceDataB> - ::init_memory(); + CCon::FaceVector< + typename GlobalVertexData<FaceT>::FaceDataB>::init_memory(); CCon::FaceVector<typename GlobalVertexData<FaceT>::ZoneData>::init_memory(); } static void postDestroy() { - CCon::FaceVector<typename GlobalVertexData<FaceT>::FaceDataB> - ::release_memory(); - CCon::FaceVector<typename GlobalVertexData<FaceT>::ZoneData> - ::release_memory(); + CCon::FaceVector< + typename GlobalVertexData<FaceT>::FaceDataB>::release_memory(); + CCon::FaceVector< + typename GlobalVertexData<FaceT>::ZoneData>::release_memory(); } - -/*============================================================================== - * Member data - *============================================================================*/ + /*============================================================================== + * Member data + *============================================================================*/ private: + //--Data members -//--Data members - - GlobalBoVertexMap globalBoVertMap; // Map of unconnected boundary vertices - // for the entire domain - + GlobalBoVertexMap globalBoVertMap; // Map of unconnected boundary vertices + // for the entire domain }; #endif diff --git a/Geo/OCCEdge.cpp b/Geo/OCCEdge.cpp index a451333f1ea0e1a83a899878323bc194aacfcca6..0b37e88dbc4792d780c653ce095f53fbca540eec 100644 --- a/Geo/OCCEdge.cpp +++ b/Geo/OCCEdge.cpp @@ -37,21 +37,18 @@ #include <BOPTools_AlgoTools.hxx> OCCEdge::OCCEdge(GModel *m, TopoDS_Edge edge, int num, GVertex *v1, GVertex *v2) - : GEdge(m, num, v1, v2) - , c(edge) - , trimmed(0) + : GEdge(m, num, v1, v2), c(edge), trimmed(0) { // force orientation of internal/external edges: otherwise reverse will not // produce the expected result - if (c.Orientation() == TopAbs_INTERNAL || c.Orientation() == TopAbs_EXTERNAL){ + if(c.Orientation() == TopAbs_INTERNAL || c.Orientation() == TopAbs_EXTERNAL) { c = TopoDS::Edge(c.Oriented(TopAbs_FORWARD)); } curve = BRep_Tool::Curve(c, s0, s1); // build the reverse curve c_rev = c; c_rev.Reverse(); - if(model()->getOCCInternals()) - model()->getOCCInternals()->bind(c, num); + if(model()->getOCCInternals()) model()->getOCCInternals()->bind(c, num); } OCCEdge::~OCCEdge() @@ -63,10 +60,9 @@ OCCEdge::~OCCEdge() SBoundingBox3d OCCEdge::bounds(bool fast) const { Bnd_Box b; - try{ + try { BRepBndLib::Add(c, b); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return SBoundingBox3d(); } @@ -76,16 +72,13 @@ SBoundingBox3d OCCEdge::bounds(bool fast) const return bbox; } -Range<double> OCCEdge::parBounds(int i) const -{ - return Range<double>(s0, s1); -} +Range<double> OCCEdge::parBounds(int i) const { return Range<double>(s0, s1); } void OCCEdge::setTrimmed(OCCFace *f) { - if (!trimmed){ + if(!trimmed) { trimmed = f; - const TopoDS_Face *s = (TopoDS_Face*) trimmed->getNativePtr(); + const TopoDS_Face *s = (TopoDS_Face *)trimmed->getNativePtr(); curve2d = BRep_Tool::CurveOnSurface(c, *s, s0, s1); if(curve2d.IsNull()) trimmed = 0; } @@ -93,26 +86,26 @@ void OCCEdge::setTrimmed(OCCFace *f) SPoint2 OCCEdge::reparamOnFace(const GFace *face, double epar, int dir) const { - if (face->getNativeType() != GEntity::OpenCascadeModel){ + if(face->getNativeType() != GEntity::OpenCascadeModel) { const GPoint pt = point(epar); SPoint3 sp(pt.x(), pt.y(), pt.z()); return face->parFromPoint(sp); } - else{ - const TopoDS_Face *s = (TopoDS_Face*) face->getNativePtr(); + else { + const TopoDS_Face *s = (TopoDS_Face *)face->getNativePtr(); double t0, t1; Handle(Geom2d_Curve) c2d; - if(dir == 1){ + if(dir == 1) { c2d = BRep_Tool::CurveOnSurface(c, *s, t0, t1); } - else{ + else { c2d = BRep_Tool::CurveOnSurface(c_rev, *s, t0, t1); } - if(c2d.IsNull()){ - Msg::Error("Reparam on face failed: curve %d is not on surface %d", - tag(), face->tag()); + if(c2d.IsNull()) { + Msg::Error("Reparam on face failed: curve %d is not on surface %d", tag(), + face->tag()); const GPoint pt = point(epar); SPoint3 sp(pt.x(), pt.y(), pt.z()); return face->parFromPoint(sp); @@ -123,47 +116,50 @@ SPoint2 OCCEdge::reparamOnFace(const GFace *face, double epar, int dir) const pnt.Coord(u, v); // sometimes OCC miserably fails ... - if (CTX::instance()->geom.reparamOnFaceRobust){ + if(CTX::instance()->geom.reparamOnFaceRobust) { GPoint p1 = point(epar); GPoint p2 = face->point(u, v); - double dx = p1.x()-p2.x(); - double dy = p1.y()-p2.y(); - double dz = p1.z()-p2.z(); - if(sqrt(dx * dx + dy * dy + dz * dz) > CTX::instance()->geom.tolerance){ - Msg::Debug("Reparam on face was inaccurate for curve %d on surface %d at point %g", - tag(), face->tag(), epar); - Msg::Debug("On the face %d local (%g %g) global (%g %g %g)", - face->tag(), u, v, p2.x(), p2.y(), p2.z()); - Msg::Debug("On the edge %d local (%g) global (%g %g %g)", - tag(), epar, p1.x(), p1.y(), p1.z()); - double guess [2] = {u,v}; - GPoint pp = face->closestPoint(SPoint3(p1.x(),p1.y(),p1.z()), guess); - u = pp.u(); - v = pp.v(); - - GPoint p2 = face->point(u, v); - dx = p1.x()-p2.x(); - dy = p1.y()-p2.y(); - dz = p1.z()-p2.z(); - if(sqrt(dx * dx + dy * dy + dz * dz) > CTX::instance()->geom.tolerance){ - Msg::Error("Closest Point was inaccurate for curve %d on surface %d at point %g", - tag(), face->tag(), epar); - Msg::Error("On the face %d local (%g %g) global (%g %g %g)", - face->tag(), u, v, p2.x(), p2.y(), p2.z()); - Msg::Error("On the edge %d local (%g) global (%g %g %g)", - tag(), epar, p1.x(), p1.y(), p1.z()); - } - else Msg::Info("OK"); + double dx = p1.x() - p2.x(); + double dy = p1.y() - p2.y(); + double dz = p1.z() - p2.z(); + if(sqrt(dx * dx + dy * dy + dz * dz) > CTX::instance()->geom.tolerance) { + Msg::Debug("Reparam on face was inaccurate for curve %d on surface %d " + "at point %g", + tag(), face->tag(), epar); + Msg::Debug("On the face %d local (%g %g) global (%g %g %g)", + face->tag(), u, v, p2.x(), p2.y(), p2.z()); + Msg::Debug("On the edge %d local (%g) global (%g %g %g)", tag(), epar, + p1.x(), p1.y(), p1.z()); + double guess[2] = {u, v}; + GPoint pp = face->closestPoint(SPoint3(p1.x(), p1.y(), p1.z()), guess); + u = pp.u(); + v = pp.v(); + + GPoint p2 = face->point(u, v); + dx = p1.x() - p2.x(); + dy = p1.y() - p2.y(); + dz = p1.z() - p2.z(); + if(sqrt(dx * dx + dy * dy + dz * dz) > + CTX::instance()->geom.tolerance) { + Msg::Error("Closest Point was inaccurate for curve %d on surface %d " + "at point %g", + tag(), face->tag(), epar); + Msg::Error("On the face %d local (%g %g) global (%g %g %g)", + face->tag(), u, v, p2.x(), p2.y(), p2.z()); + Msg::Error("On the edge %d local (%g) global (%g %g %g)", tag(), epar, + p1.x(), p1.y(), p1.z()); + } + else + Msg::Info("OK"); } } return SPoint2(u, v); } - } GPoint OCCEdge::closestPoint(const SPoint3 &qp, double ¶m) const { - if(curve.IsNull()){ + if(curve.IsNull()) { Msg::Error("OCC curve is null in closestPoint"); return GPoint(0, 0); } @@ -171,14 +167,14 @@ GPoint OCCEdge::closestPoint(const SPoint3 &qp, double ¶m) const gp_Pnt pnt(qp.x(), qp.y(), qp.z()); GeomAPI_ProjectPointOnCurve proj(pnt, curve, s0, s1); - if(!proj.NbPoints()){ + if(!proj.NbPoints()) { Msg::Error("OCC ProjectPointOnCurve failed"); return GPoint(0, 0); } param = proj.LowerDistanceParameter(); - if(param < s0 || param > s1){ + if(param < s0 || param > s1) { Msg::Error("Point projection is out of edge bounds"); return GPoint(0, 0); } @@ -192,24 +188,25 @@ bool OCCEdge::isSeam(const GFace *face) const { if(face->geomType() == GEntity::CompoundSurface) return false; if(face->getNativeType() != GEntity::OpenCascadeModel) return false; - const TopoDS_Face *s = (TopoDS_Face*) face->getNativePtr(); + const TopoDS_Face *s = (TopoDS_Face *)face->getNativePtr(); bool ret = BRep_Tool::IsClosed(c, *s); return ret; } GPoint OCCEdge::point(double par) const { - if(trimmed){ + if(trimmed) { double u, v; curve2d->Value(par).Coord(u, v); return trimmed->point(u, v); } - else if(!curve.IsNull()){ + else if(!curve.IsNull()) { gp_Pnt pnt = curve->Value(par); - return GPoint(pnt.X(), pnt.Y(), pnt.Z(),this,par); + return GPoint(pnt.X(), pnt.Y(), pnt.Z(), this, par); } - else{ - Msg::Warning("OCC Curve %d is neither a 3D curve not a trimmed curve", tag()); + else { + Msg::Warning("OCC Curve %d is neither a 3D curve not a trimmed curve", + tag()); return GPoint(0, 0, 0); } } @@ -225,49 +222,49 @@ SVector3 OCCEdge::firstDer(double par) const GEntity::GeomType OCCEdge::geomType() const { - if(curve.IsNull()){ - if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Circle)) + if(curve.IsNull()) { + if(curve2d->DynamicType() == STANDARD_TYPE(Geom_Circle)) return Circle; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Line)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_Line)) return Line; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) return Ellipse; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Parabola)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_Parabola)) return Parabola; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Hyperbola)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_Hyperbola)) return Hyperbola; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) return TrimmedCurve; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve)) return OffsetCurve; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) return BSpline; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_BezierCurve)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_BezierCurve)) return Bezier; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Conic)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_Conic)) return Conic; return Unknown; } - else{ - if (curve->DynamicType() == STANDARD_TYPE(Geom_Circle)) + else { + if(curve->DynamicType() == STANDARD_TYPE(Geom_Circle)) return Circle; - else if (curve->DynamicType() == STANDARD_TYPE(Geom_Line)) + else if(curve->DynamicType() == STANDARD_TYPE(Geom_Line)) return Line; - else if (curve->DynamicType() == STANDARD_TYPE(Geom_Parabola)) + else if(curve->DynamicType() == STANDARD_TYPE(Geom_Parabola)) return Parabola; - else if (curve->DynamicType() == STANDARD_TYPE(Geom_Hyperbola)) + else if(curve->DynamicType() == STANDARD_TYPE(Geom_Hyperbola)) return Hyperbola; - else if (curve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) + else if(curve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) return TrimmedCurve; - else if (curve->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve)) + else if(curve->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve)) return OffsetCurve; - else if (curve->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) + else if(curve->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) return Ellipse; - else if (curve->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) + else if(curve->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) return BSpline; - else if (curve->DynamicType() == STANDARD_TYPE(Geom_BezierCurve)) + else if(curve->DynamicType() == STANDARD_TYPE(Geom_BezierCurve)) return Bezier; - else if (curve2d->DynamicType() == STANDARD_TYPE(Geom_Conic)) + else if(curve2d->DynamicType() == STANDARD_TYPE(Geom_Conic)) return Conic; return Unknown; } @@ -287,7 +284,7 @@ int OCCEdge::minimumMeshSegments() const // if the edge is closed, ensure that at least 3 points are generated in the // 1D mesh (4 segments, one of which is degenerated) - if (getBeginVertex() == getEndVertex()) np = std::max(4, np); + if(getBeginVertex() == getEndVertex()) np = std::max(4, np); return std::max(np, meshAttributes.minimumMeshSegments); } @@ -305,7 +302,7 @@ double OCCEdge::curvature(double par) const const double eps = 1.e-15; Standard_Real Crv; - if (curve.IsNull()){ + if(curve.IsNull()) { Geom2dLProp_CLProps2d aCLProps(curve2d, 2, eps); aCLProps.SetParameter(par); if(!aCLProps.IsTangentDefined()) @@ -313,7 +310,7 @@ double OCCEdge::curvature(double par) const else Crv = aCLProps.Curvature(); } - else{ + else { BRepAdaptor_Curve brepc(c); BRepLProp_CLProps prop(brepc, 2, eps); prop.SetParameter(par); @@ -328,21 +325,21 @@ double OCCEdge::curvature(double par) const void OCCEdge::writeGEO(FILE *fp) { - if(geomType() == Circle){ + if(geomType() == Circle) { gp_Pnt center; - if(curve.IsNull()){ + if(curve.IsNull()) { center = Handle(Geom_Circle)::DownCast(curve2d)->Location(); } - else{ + else { center = Handle(Geom_Circle)::DownCast(curve)->Location(); } // GEO supports only circle arcs < Pi - if(s1 - s0 < M_PI){ + if(s1 - s0 < M_PI) { fprintf(fp, "p%d = newp;\n", tag()); - fprintf(fp, "Point(p%d + 1) = {%.16g, %.16g, %.16g};\n", - tag(), center.X(), center.Y(), center.Z()); - fprintf(fp, "Circle(%d) = {%d, p%d + 1, %d};\n", - tag(), getBeginVertex()->tag(), tag(), getEndVertex()->tag()); + fprintf(fp, "Point(p%d + 1) = {%.16g, %.16g, %.16g};\n", tag(), + center.X(), center.Y(), center.Z()); + fprintf(fp, "Circle(%d) = {%d, p%d + 1, %d};\n", tag(), + getBeginVertex()->tag(), tag(), getEndVertex()->tag()); } else GEdge::writeGEO(fp); diff --git a/Geo/OCCEdge.h b/Geo/OCCEdge.h index ae8f98ffeb3a4c33c5a78bbe63a2279d974cebf7..deb7df1da208669bee892a5fb0bfe47af43d94a4 100644 --- a/Geo/OCCEdge.h +++ b/Geo/OCCEdge.h @@ -21,7 +21,7 @@ class OCCFace; #include <BRep_Tool.hxx> class OCCEdge : public GEdge { - protected: +protected: TopoDS_Edge _replacement; TopoDS_Edge c; TopoDS_Edge c_rev; @@ -29,7 +29,8 @@ class OCCEdge : public GEdge { Handle(Geom_Curve) curve; mutable Handle(Geom2d_Curve) curve2d; mutable GFace *trimmed; - public: + +public: OCCEdge(GModel *model, TopoDS_Edge _e, int num, GVertex *v1, GVertex *v2); virtual ~OCCEdge(); virtual SBoundingBox3d bounds(bool fast = false) const; @@ -38,13 +39,13 @@ class OCCEdge : public GEdge { virtual bool degenerate(int) const { return BRep_Tool::Degenerated(c); } virtual GPoint point(double p) const; virtual SVector3 firstDer(double par) const; - virtual double curvature (double par) const; + virtual double curvature(double par) const; virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const; virtual GPoint closestPoint(const SPoint3 &queryPoint, double ¶m) const; ModelType getNativeType() const { return OpenCascadeModel; } - void * getNativePtr() const { return (void*)&c; } - virtual int minimumMeshSegments () const; - virtual int minimumDrawSegments () const; + void *getNativePtr() const { return (void *)&c; } + virtual int minimumMeshSegments() const; + virtual int minimumDrawSegments() const; bool is3D() const { return !curve.IsNull(); } void setTrimmed(OCCFace *); bool isSeam(const GFace *) const; diff --git a/Geo/OCCFace.cpp b/Geo/OCCFace.cpp index a10dd2b6ebb972656264185676edc11f54270d89..afbf418dd0f16d08c484d464bbd45c492e7a1c56 100644 --- a/Geo/OCCFace.cpp +++ b/Geo/OCCFace.cpp @@ -43,20 +43,17 @@ #include <BRepTools.hxx> OCCFace::OCCFace(GModel *m, TopoDS_Face _s, int num) - : GFace(m, num) - , s(_s) - , _radius(-1) + : GFace(m, num), s(_s), _radius(-1) { setup(); - if(model()->getOCCInternals()) - model()->getOCCInternals()->bind(s, num); + if(model()->getOCCInternals()) model()->getOCCInternals()->bind(s, num); // if(tag() == 10) writeBREP("s10.brep"); } OCCFace::~OCCFace() { - if(model()->getOCCInternals() && !model()->isBeingDestroyed()){ + if(model()->getOCCInternals() && !model()->isBeingDestroyed()) { model()->getOCCInternals()->unbind(s, tag()); // potentially slow } } @@ -67,32 +64,33 @@ void OCCFace::setup() l_edges.clear(); l_dirs.clear(); TopExp_Explorer exp2, exp3; - for(exp2.Init(s.Oriented(TopAbs_FORWARD), TopAbs_WIRE); exp2.More(); exp2.Next()){ + for(exp2.Init(s.Oriented(TopAbs_FORWARD), TopAbs_WIRE); exp2.More(); + exp2.Next()) { TopoDS_Wire wire = TopoDS::Wire(exp2.Current()); Msg::Debug("OCC Face %d - New Wire", tag()); - std::vector<GEdge*> l_wire; - for(exp3.Init(wire, TopAbs_EDGE); exp3.More(); exp3.Next()){ + std::vector<GEdge *> l_wire; + for(exp3.Init(wire, TopAbs_EDGE); exp3.More(); exp3.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp3.Current()); GEdge *e = 0; if(model()->getOCCInternals()) e = model()->getOCCInternals()->getEdgeForOCCShape(model(), edge); - if(!e){ - Msg::Error("Unknown edge in face %d", tag()); + if(!e) { + Msg::Error("Unknown edge in face %d", tag()); } - else if(edge.Orientation() == TopAbs_INTERNAL){ + else if(edge.Orientation() == TopAbs_INTERNAL) { Msg::Debug("Adding embedded edge %d in face %d", e->tag(), tag()); embedded_edges.push_back(e); - OCCEdge *occe = (OCCEdge*)e; + OCCEdge *occe = (OCCEdge *)e; occe->setTrimmed(this); } - else{ + else { l_wire.push_back(e); Msg::Debug("Edge %d (%d --> %d) ori %d", e->tag(), e->getBeginVertex()->tag(), e->getEndVertex()->tag(), edge.Orientation()); e->addFace(this); - if(!e->is3D()){ - OCCEdge *occe = (OCCEdge*)e; + if(!e->is3D()) { + OCCEdge *occe = (OCCEdge *)e; occe->setTrimmed(this); } } @@ -100,16 +98,16 @@ void OCCFace::setup() GEdgeLoop el(l_wire); // printf("l_wire of size %d %d\n",l_wire.size(),el.count()); - for(GEdgeLoop::citer it = el.begin(); it != el.end(); ++it){ + for(GEdgeLoop::citer it = el.begin(); it != el.end(); ++it) { l_edges.push_back(it->ge); l_dirs.push_back(it->_sign); - if (el.count() == 2){ + if(el.count() == 2) { it->ge->meshAttributes.minimumMeshSegments = - std::max(it->ge->meshAttributes.minimumMeshSegments,2); + std::max(it->ge->meshAttributes.minimumMeshSegments, 2); } - if (el.count() == 1){ + if(el.count() == 1) { it->ge->meshAttributes.minimumMeshSegments = - std::max(it->ge->meshAttributes.minimumMeshSegments,3); + std::max(it->ge->meshAttributes.minimumMeshSegments, 3); } } edgeLoops.push_back(el); @@ -118,12 +116,12 @@ void OCCFace::setup() BRepAdaptor_Surface surface(s); _periodic[0] = surface.IsUPeriodic(); _periodic[1] = surface.IsVPeriodic(); - if (_periodic[0]) _period[0]=surface.UPeriod(); - if (_periodic[1]) _period[1]=surface.VPeriod(); + if(_periodic[0]) _period[0] = surface.UPeriod(); + if(_periodic[1]) _period[1] = surface.VPeriod(); ShapeAnalysis::GetFaceUVBounds(s, umin, umax, vmin, vmax); - Msg::Debug("OCC Face %d with %d parameter bounds (%g,%g)(%g,%g)", - tag(), l_edges.size(), umin, umax, vmin, vmax); + Msg::Debug("OCC Face %d with %d parameter bounds (%g,%g)(%g,%g)", tag(), + l_edges.size(), umin, umax, vmin, vmax); // we do that for the projections to converge on the borders of the surface const double du = umax - umin; const double dv = vmax - vmin; @@ -134,36 +132,35 @@ void OCCFace::setup() occface = BRep_Tool::Surface(s); for(exp2.Init(s.Oriented(TopAbs_FORWARD), TopAbs_VERTEX, TopAbs_EDGE); - exp2.More(); exp2.Next()){ + exp2.More(); exp2.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp2.Current()); GVertex *v = 0; if(model()->getOCCInternals()) v = model()->getOCCInternals()->getVertexForOCCShape(model(), vertex); - if(!v){ + if(!v) { Msg::Error("Unknown vertex in face %d", tag()); } - else if(vertex.Orientation() == TopAbs_INTERNAL){ + else if(vertex.Orientation() == TopAbs_INTERNAL) { Msg::Debug("Adding embedded vertex %d in face %d", v->tag(), tag()); embedded_vertices.push_back(v); } } - if (geomType()==GEntity::Sphere){ + if(geomType() == GEntity::Sphere) { BRepAdaptor_Surface surface(s); gp_Sphere sphere = surface.Sphere(); _radius = sphere.Radius(); gp_Pnt loc = sphere.Location(); - _center = SPoint3(loc.X(),loc.Y(),loc.Z()); + _center = SPoint3(loc.X(), loc.Y(), loc.Z()); } } SBoundingBox3d OCCFace::bounds(bool fast) const { Bnd_Box b; - try{ + try { BRepBndLib::Add(s, b); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return SBoundingBox3d(); } @@ -178,8 +175,7 @@ Range<double> OCCFace::parBounds(int i) const double umin2, umax2, vmin2, vmax2; ShapeAnalysis::GetFaceUVBounds(s, umin2, umax2, vmin2, vmax2); - if(i == 0) - return Range<double>(umin2, umax2); + if(i == 0) return Range<double>(umin2, umax2); return Range<double>(vmin2, vmax2); } @@ -194,21 +190,21 @@ SVector3 OCCFace::normal(const SPoint2 ¶m) const SVector3 t2(dv.X(), dv.Y(), dv.Z()); SVector3 n(crossprod(t1, t2)); n.normalize(); - if (s.Orientation() == TopAbs_REVERSED) return n * (-1.); + if(s.Orientation() == TopAbs_REVERSED) return n * (-1.); return n; } -Pair<SVector3,SVector3> OCCFace::firstDer(const SPoint2 ¶m) const +Pair<SVector3, SVector3> OCCFace::firstDer(const SPoint2 ¶m) const { gp_Pnt pnt; gp_Vec du, dv; occface->D1(param.x(), param.y(), pnt, du, dv); - return Pair<SVector3,SVector3>(SVector3(du.X(), du.Y(), du.Z()), - SVector3(dv.X(), dv.Y(), dv.Z())); + return Pair<SVector3, SVector3>(SVector3(du.X(), du.Y(), du.Z()), + SVector3(dv.X(), dv.Y(), dv.Z())); } -void OCCFace::secondDer(const SPoint2 ¶m, - SVector3 &dudu, SVector3 &dvdv, SVector3 &dudv) const +void OCCFace::secondDer(const SPoint2 ¶m, SVector3 &dudu, SVector3 &dvdv, + SVector3 &dudv) const { gp_Pnt pnt; gp_Vec du, dv, duu, dvv, duv; @@ -234,44 +230,44 @@ GPoint OCCFace::point(double par1, double par2) const double du = umax2 - umin2; double dv = vmax2 - vmin2; - if (par1 > (umax2+.1*du) || par1 < (umin2-.1*du) || - par2 > (vmax2+.1*dv) || par2 < (vmin2-.1*dv)){ - GPoint p(0,0,0, this, pp); + if(par1 > (umax2 + .1 * du) || par1 < (umin2 - .1 * du) || + par2 > (vmax2 + .1 * dv) || par2 < (vmin2 - .1 * dv)) { + GPoint p(0, 0, 0, this, pp); p.setNoSuccess(); return p; } - try{ + try { gp_Pnt val; val = occface->Value(par1, par2); return GPoint(val.X(), val.Y(), val.Z(), this, pp); - } - catch(Standard_OutOfRange){ - GPoint p(0,0,0, this, pp); + } catch(Standard_OutOfRange) { + GPoint p(0, 0, 0, this, pp); p.setNoSuccess(); return p; } #endif } -GPoint OCCFace::closestPoint(const SPoint3 &qp, const double initialGuess[2]) const +GPoint OCCFace::closestPoint(const SPoint3 &qp, + const double initialGuess[2]) const { gp_Pnt pnt(qp.x(), qp.y(), qp.z()); GeomAPI_ProjectPointOnSurf proj(pnt, occface, umin, umax, vmin, vmax); - if(!proj.NbPoints()){ + if(!proj.NbPoints()) { Msg::Warning("OCC Project Point on Surface FAIL"); GPoint gp(0, 0); gp.setNoSuccess(); return gp; } - double pp[2] = {initialGuess[0],initialGuess[1]}; + double pp[2] = {initialGuess[0], initialGuess[1]}; proj.LowerDistanceParameters(pp[0], pp[1]); // Msg::Info("projection lower distance parameters %g %g",pp[0],pp[1]); - if((pp[0] < umin || umax < pp[0]) || (pp[1]<vmin || vmax<pp[1])){ + if((pp[0] < umin || umax < pp[0]) || (pp[1] < vmin || vmax < pp[1])) { Msg::Warning("Point projection is out of face bounds"); GPoint gp(0, 0); gp.setNoSuccess(); @@ -286,7 +282,7 @@ SPoint2 OCCFace::parFromPoint(const SPoint3 &qp, bool onSurface) const { gp_Pnt pnt(qp.x(), qp.y(), qp.z()); GeomAPI_ProjectPointOnSurf proj(pnt, occface, umin, umax, vmin, vmax); - if(!proj.NbPoints()){ + if(!proj.NbPoints()) { Msg::Error("OCC Project Point on Surface FAIL"); return GFace::parFromPoint(qp); } @@ -297,21 +293,21 @@ SPoint2 OCCFace::parFromPoint(const SPoint3 &qp, bool onSurface) const GEntity::GeomType OCCFace::geomType() const { - if (occface->DynamicType() == STANDARD_TYPE(Geom_Plane)) + if(occface->DynamicType() == STANDARD_TYPE(Geom_Plane)) return Plane; - else if (occface->DynamicType() == STANDARD_TYPE(Geom_ToroidalSurface)) + else if(occface->DynamicType() == STANDARD_TYPE(Geom_ToroidalSurface)) return Torus; - else if (occface->DynamicType() == STANDARD_TYPE(Geom_BezierSurface)) + else if(occface->DynamicType() == STANDARD_TYPE(Geom_BezierSurface)) return BezierSurface; - else if (occface->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) + else if(occface->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) return Cylinder; - else if (occface->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface)) + else if(occface->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface)) return Cone; - else if (occface->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution)) + else if(occface->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution)) return SurfaceOfRevolution; - else if (occface->DynamicType() == STANDARD_TYPE(Geom_SphericalSurface)) + else if(occface->DynamicType() == STANDARD_TYPE(Geom_SphericalSurface)) return Sphere; - else if (occface->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) + else if(occface->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) return BSplineSurface; return Unknown; } @@ -321,19 +317,17 @@ double OCCFace::curvatureMax(const SPoint2 ¶m) const const double eps = 1.e-12; BRepAdaptor_Surface sf(s, Standard_True); BRepLProp_SLProps prop(sf, 2, eps); - prop.SetParameters (param.x(), param.y()); + prop.SetParameters(param.x(), param.y()); - if(!prop.IsCurvatureDefined()){ + if(!prop.IsCurvatureDefined()) { return eps; } return std::max(fabs(prop.MinCurvature()), fabs(prop.MaxCurvature())); } -double OCCFace::curvatures(const SPoint2 ¶m, - SVector3 &dirMax, - SVector3 &dirMin, - double &curvMax, +double OCCFace::curvatures(const SPoint2 ¶m, SVector3 &dirMax, + SVector3 &dirMin, double &curvMax, double &curvMin) const { const double eps = 1.e-12; @@ -341,7 +335,7 @@ double OCCFace::curvatures(const SPoint2 ¶m, BRepLProp_SLProps prop(sf, 2, eps); prop.SetParameters(param.x(), param.y()); - if (!prop.IsCurvatureDefined()){ + if(!prop.IsCurvatureDefined()) { return -1.; } @@ -364,7 +358,7 @@ double OCCFace::curvatures(const SPoint2 ¶m, bool OCCFace::containsPoint(const SPoint3 &pt) const { - if(geomType() == Plane){ + if(geomType() == Plane) { gp_Pln pl = Handle(Geom_Plane)::DownCast(occface)->Pln(); double n[3], c; pl.Coefficients(n[0], n[1], n[2], c); @@ -373,19 +367,20 @@ bool OCCFace::containsPoint(const SPoint3 &pt) const double v[3] = {pt.x(), pt.y(), pt.z()}; std::vector<int>::const_iterator ito = l_dirs.begin(); - for(std::vector<GEdge*>::const_iterator it = l_edges.begin(); it != l_edges.end(); it++){ + for(std::vector<GEdge *>::const_iterator it = l_edges.begin(); + it != l_edges.end(); it++) { GEdge *c = *it; int ori = 1; - if(ito != l_dirs.end()){ + if(ito != l_dirs.end()) { ori = *ito; ++ito; } int N = 10; Range<double> range = c->parBounds(0); - for(int j = 0; j < N ; j++) { + for(int j = 0; j < N; j++) { double u1 = (double)j / (double)N; double u2 = (double)(j + 1) / (double)N; - if(ori < 0){ + if(ori < 0) { u1 = 1. - u1; u2 = 1. - u2; } @@ -410,8 +405,8 @@ bool OCCFace::buildSTLTriangulation(bool force) stl_vertices_uv.clear(); stl_vertices_xyz.clear(); stl_triangles.clear(); - if(!model()->getOCCInternals()->makeFaceSTL(s, stl_vertices_uv, stl_vertices_xyz, - stl_normals, stl_triangles)){ + if(!model()->getOCCInternals()->makeFaceSTL( + s, stl_vertices_uv, stl_vertices_xyz, stl_normals, stl_triangles)) { Msg::Info("OpenCASCADE triangulation of surface %d failed", tag()); // add a dummy triangle so that we won't try again stl_vertices_uv.push_back(SPoint2(0., 0.)); @@ -426,13 +421,12 @@ bool OCCFace::buildSTLTriangulation(bool force) bool OCCFace::isSphere(double &radius, SPoint3 ¢er) const { - switch(geomType()){ + switch(geomType()) { case GEntity::Sphere: radius = _radius; center = _center; return true; - default: - return false; + default: return false; } } diff --git a/Geo/OCCFace.h b/Geo/OCCFace.h index d28692b3486083e456b396dc501505d186b3fcc2..bc2ca259cb88d1f1cccb37cafc751497e8c33eba 100644 --- a/Geo/OCCFace.h +++ b/Geo/OCCFace.h @@ -16,43 +16,47 @@ #include <TopoDS_Face.hxx> class OCCFace : public GFace { - protected: +protected: TopoDS_Face s; Handle(Geom_Surface) occface; double umin, umax, vmin, vmax; bool _periodic[2]; double _period[2]; - bool buildSTLTriangulation(bool force=false); + bool buildSTLTriangulation(bool force = false); void setup(); double _radius; SPoint3 _center; - public: + +public: OCCFace(GModel *m, TopoDS_Face s, int num); virtual ~OCCFace(); virtual SBoundingBox3d bounds(bool fast = false) const; Range<double> parBounds(int i) const; virtual GPoint point(double par1, double par2) const; - virtual GPoint closestPoint(const SPoint3 & queryPoint, + virtual GPoint closestPoint(const SPoint3 &queryPoint, const double initialGuess[2]) const; virtual bool containsPoint(const SPoint3 &pt) const; virtual SVector3 normal(const SPoint2 ¶m) const; - virtual Pair<SVector3,SVector3> firstDer(const SPoint2 ¶m) const; - virtual void secondDer(const SPoint2 &, SVector3 &, SVector3 &, SVector3 &) const; + virtual Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m) const; + virtual void secondDer(const SPoint2 &, SVector3 &, SVector3 &, + SVector3 &) const; virtual GEntity::GeomType geomType() const; ModelType getNativeType() const { return OpenCascadeModel; } - void *getNativePtr() const { return (void*)&s; } - virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const; + void *getNativePtr() const { return (void *)&s; } + virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface = true) const; virtual double curvatureMax(const SPoint2 ¶m) const; - virtual double curvatures(const SPoint2 ¶m, SVector3 &dirMax, SVector3 &dirMin, - double &curvMax, double &curvMin) const; + virtual double curvatures(const SPoint2 ¶m, SVector3 &dirMax, + SVector3 &dirMin, double &curvMax, + double &curvMin) const; // tells if it's a sphere, and if it is, returns parameters - virtual bool isSphere (double &radius, SPoint3 ¢er) const; + virtual bool isSphere(double &radius, SPoint3 ¢er) const; virtual bool periodic(int dim) const { return _periodic[dim]; } virtual double period(int dim) const { return _period[dim]; } - // true if the parameter value is interior to the face (taking into account boundaries) - virtual bool containsParam(const SPoint2 &pt) ; + // true if the parameter value is interior to the face (taking into account + // boundaries) + virtual bool containsParam(const SPoint2 &pt); // save itself in BREP format (for debug e.g.) - void writeBREP (const char *filename); + void writeBREP(const char *filename); }; #endif diff --git a/Geo/OCCMeshAttributes.h b/Geo/OCCMeshAttributes.h index aa11812d886388a4f3234692f89a04484d74a8a9..babb0ee5b1c4832e5dfc988111064e9ba3452827 100644 --- a/Geo/OCCMeshAttributes.h +++ b/Geo/OCCMeshAttributes.h @@ -20,126 +20,111 @@ #include <BRepTools.hxx> class OCCMeshAttributes { - private: +private: int _dim; TopoDS_Shape _shape; double _meshSize; ExtrudeParams *_extrude; int _sourceDim; TopoDS_Shape _sourceShape; - public: - OCCMeshAttributes() - : _dim(-1), _meshSize(MAX_LC), _extrude(0), _sourceDim(-1) {} + +public: + OCCMeshAttributes() : _dim(-1), _meshSize(MAX_LC), _extrude(0), _sourceDim(-1) + { + } OCCMeshAttributes(int dim, TopoDS_Shape shape) - : _dim(dim) - , _shape(shape) - , _meshSize(MAX_LC) - , _extrude(0) - , _sourceDim(-1) + : _dim(dim), _shape(shape), _meshSize(MAX_LC), _extrude(0), _sourceDim(-1) { } OCCMeshAttributes(int dim, TopoDS_Shape shape, double size) - : _dim(dim) - , _shape(shape) - , _meshSize(size) - , _extrude(0) - , _sourceDim(-1) + : _dim(dim), _shape(shape), _meshSize(size), _extrude(0), _sourceDim(-1) { } OCCMeshAttributes(int dim, TopoDS_Shape shape, ExtrudeParams *e, int sourceDim, TopoDS_Shape sourceShape) - : _dim(dim) - , _shape(shape) - , _meshSize(MAX_LC) - , _extrude(e) - , _sourceDim(sourceDim) - , _sourceShape(sourceShape) + : _dim(dim), _shape(shape), _meshSize(MAX_LC), _extrude(e), + _sourceDim(sourceDim), _sourceShape(sourceShape) { } - ~OCCMeshAttributes(){} - int getDim(){ return _dim; } - TopoDS_Shape getShape(){ return _shape; } - double getMeshSize(){ return _meshSize; } - ExtrudeParams *getExtrudeParams(){ return _extrude; } - int getSourceDim(){ return _sourceDim; } - TopoDS_Shape getSourceShape(){ return _sourceShape; } + ~OCCMeshAttributes() {} + int getDim() { return _dim; } + TopoDS_Shape getShape() { return _shape; } + double getMeshSize() { return _meshSize; } + ExtrudeParams *getExtrudeParams() { return _extrude; } + int getSourceDim() { return _sourceDim; } + TopoDS_Shape getSourceShape() { return _sourceShape; } }; // mesh attributes are stored according to the center of their associated shape // bounding box; this allows to efficiently search for potential matches, even // if the actual underlying shape has been changed (e.g. through boolean // fragments) -class OCCMeshAttributesRTree{ - private: - RTree<OCCMeshAttributes*, double, 3, double> *_rtree[4]; - std::vector<OCCMeshAttributes*> _all; +class OCCMeshAttributesRTree { +private: + RTree<OCCMeshAttributes *, double, 3, double> *_rtree[4]; + std::vector<OCCMeshAttributes *> _all; double _tol; static bool rtree_callback(OCCMeshAttributes *v, void *ctx) { - std::vector<OCCMeshAttributes*> *out = - static_cast<std::vector<OCCMeshAttributes*>*>(ctx); + std::vector<OCCMeshAttributes *> *out = + static_cast<std::vector<OCCMeshAttributes *> *>(ctx); out->push_back(v); return true; } - public: + +public: OCCMeshAttributesRTree(double tolerance = 1.e-8) { for(int dim = 0; dim < 4; dim++) - _rtree[dim] = new RTree<OCCMeshAttributes*, double, 3, double>(); + _rtree[dim] = new RTree<OCCMeshAttributes *, double, 3, double>(); _tol = tolerance; } ~OCCMeshAttributesRTree() { clear(); - for(int dim = 0; dim < 4; dim++) - delete _rtree[dim]; + for(int dim = 0; dim < 4; dim++) delete _rtree[dim]; } void clear() { - for(int dim = 0; dim < 4; dim++) - _rtree[dim]->RemoveAll(); - for(unsigned int i = 0; i < _all.size(); i++) - delete _all[i]; + for(int dim = 0; dim < 4; dim++) _rtree[dim]->RemoveAll(); + for(unsigned int i = 0; i < _all.size(); i++) delete _all[i]; _all.clear(); } - void print(const std::string &fileName="") + void print(const std::string &fileName = "") { FILE *fp = stdout; - if(fileName.size()){ + if(fileName.size()) { fp = Fopen(fileName.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Could not open file '%s'", fileName.c_str()); return; } } fprintf(fp, "View(\"rtree mesh sizes\"){\n"); - for(unsigned int i = 0; i < _all.size(); i++){ - if(_all[i]->getDim() != 0) - continue; - if(_all[i]->getMeshSize() == MAX_LC) - continue; + for(unsigned int i = 0; i < _all.size(); i++) { + if(_all[i]->getDim() != 0) continue; + if(_all[i]->getMeshSize() == MAX_LC) continue; gp_Pnt pnt = BRep_Tool::Pnt(TopoDS::Vertex(_all[i]->getShape())); fprintf(fp, "SP(%g,%g,%g){%g};\n", pnt.X(), pnt.Y(), pnt.Z(), _all[i]->getMeshSize()); } fprintf(fp, "};\n"); - if(fileName.size()) - fclose(fp); + if(fileName.size()) fclose(fp); } void insert(OCCMeshAttributes *v) { _all.push_back(v); if(v->getDim() < 0 || v->getDim() > 3) return; Bnd_Box box; - try{ + try { BRepBndLib::Add(v->getShape(), box); - if(box.IsVoid()){ - Msg::Debug("Inserting (null or degenerate) shape with void bounding box"); - //BRepTools::Dump(v->getShape(), std::cout); + if(box.IsVoid()) { + Msg::Debug( + "Inserting (null or degenerate) shape with void bounding box"); + // BRepTools::Dump(v->getShape(), std::cout); return; } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return; } @@ -159,14 +144,14 @@ class OCCMeshAttributesRTree{ attr.clear(); if(dim < 0 || dim > 3) return; Bnd_Box box; - try{ + try { BRepBndLib::Add(shape, box); - if(box.IsVoid()){ - Msg::Debug("Searching for (null or degenerate) shape with void bounding box"); + if(box.IsVoid()) { + Msg::Debug( + "Searching for (null or degenerate) shape with void bounding box"); return; } - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return; } @@ -177,20 +162,18 @@ class OCCMeshAttributesRTree{ double z = 0.5 * (zmin + zmax); double bmin[3] = {x - _tol, y - _tol, z - _tol}; double bmax[3] = {x + _tol, y + _tol, z + _tol}; - std::vector<OCCMeshAttributes*> tmp; + std::vector<OCCMeshAttributes *> tmp; _rtree[dim]->Search(bmin, bmax, rtree_callback, &tmp); Msg::Debug("OCCRTree found %d matches at (%g,%g,%g) in tree of size %d", (int)tmp.size(), x, y, z, (int)_all.size()); - if(tmp.empty()){ // no match + if(tmp.empty()) { // no match return; } - if(!excludeSame){ - for(unsigned int i = 0; i < tmp.size(); i++){ - if(requireMeshSize && tmp[i]->getMeshSize() == MAX_LC) - continue; - if(requireExtrudeParams && !tmp[i]->getExtrudeParams()) - continue; - if(shape.IsSame(tmp[i]->getShape())){ // exact match: same shape + if(!excludeSame) { + for(unsigned int i = 0; i < tmp.size(); i++) { + if(requireMeshSize && tmp[i]->getMeshSize() == MAX_LC) continue; + if(requireExtrudeParams && !tmp[i]->getExtrudeParams()) continue; + if(shape.IsSame(tmp[i]->getShape())) { // exact match: same shape attr.push_back(tmp[i]); Msg::Debug("OCCRTree exact match"); return; @@ -198,14 +181,12 @@ class OCCMeshAttributesRTree{ } } // potential matches based on bounding box - for(unsigned int i = 0; i < tmp.size(); i++){ - if(requireMeshSize && tmp[i]->getMeshSize() == MAX_LC) - continue; - if(requireExtrudeParams && !tmp[i]->getExtrudeParams()) - continue; + for(unsigned int i = 0; i < tmp.size(); i++) { + if(requireMeshSize && tmp[i]->getMeshSize() == MAX_LC) continue; + if(requireExtrudeParams && !tmp[i]->getExtrudeParams()) continue; Bnd_Box box2; BRepBndLib::Add(tmp[i]->getShape(), box2); - if(box.Distance(box2) < _tol){ + if(box.Distance(box2) < _tol) { attr.push_back(tmp[i]); } } @@ -214,21 +195,20 @@ class OCCMeshAttributesRTree{ } double getMeshSize(int dim, TopoDS_Shape shape) { - std::vector<OCCMeshAttributes*> attr; + std::vector<OCCMeshAttributes *> attr; find(dim, shape, attr, true, false, false); - for(unsigned int i = 0; i < attr.size(); i++){ - if(attr[i]->getMeshSize() < MAX_LC) - return attr[i]->getMeshSize(); + for(unsigned int i = 0; i < attr.size(); i++) { + if(attr[i]->getMeshSize() < MAX_LC) return attr[i]->getMeshSize(); } return MAX_LC; } - ExtrudeParams *getExtrudeParams(int dim, TopoDS_Shape shape, - int &sourceDim, TopoDS_Shape &sourceShape) + ExtrudeParams *getExtrudeParams(int dim, TopoDS_Shape shape, int &sourceDim, + TopoDS_Shape &sourceShape) { - std::vector<OCCMeshAttributes*> attr; + std::vector<OCCMeshAttributes *> attr; find(dim, shape, attr, false, true, false); - for(unsigned int i = 0; i < attr.size(); i++){ - if(attr[i]->getExtrudeParams()){ + for(unsigned int i = 0; i < attr.size(); i++) { + if(attr[i]->getExtrudeParams()) { sourceDim = attr[i]->getSourceDim(); sourceShape = attr[i]->getSourceShape(); return attr[i]->getExtrudeParams(); @@ -236,11 +216,12 @@ class OCCMeshAttributesRTree{ } return 0; } - void getSimilarShapes(int dim, TopoDS_Shape shape, std::vector<TopoDS_Shape> &other) + void getSimilarShapes(int dim, TopoDS_Shape shape, + std::vector<TopoDS_Shape> &other) { - std::vector<OCCMeshAttributes*> attr; + std::vector<OCCMeshAttributes *> attr; find(dim, shape, attr, false, false, true); - for(unsigned int i = 0; i < attr.size(); i++){ + for(unsigned int i = 0; i < attr.size(); i++) { TopoDS_Shape s = attr[i]->getShape(); if(!s.IsNull()) other.push_back(s); } diff --git a/Geo/OCCRegion.cpp b/Geo/OCCRegion.cpp index c2b6a02e8c8e8f57c00cd6323a4817317e0b4e79..cfb44234859dc54ef0131db597e9e89b3c76f854 100644 --- a/Geo/OCCRegion.cpp +++ b/Geo/OCCRegion.cpp @@ -23,12 +23,10 @@ #include <BRepTools.hxx> OCCRegion::OCCRegion(GModel *m, TopoDS_Solid _s, int num) - : GRegion(m, num) - , s(_s) + : GRegion(m, num), s(_s) { setup(); - if(model()->getOCCInternals()) - model()->getOCCInternals()->bind(s, num); + if(model()->getOCCInternals()) model()->getOCCInternals()->bind(s, num); // if(tag() == 1) writeBREP("v1.brep"); } @@ -43,53 +41,53 @@ void OCCRegion::setup() { l_faces.clear(); TopExp_Explorer exp2, exp3; - for(exp2.Init(s, TopAbs_SHELL); exp2.More(); exp2.Next()){ + for(exp2.Init(s, TopAbs_SHELL); exp2.More(); exp2.Next()) { const TopoDS_Shape &shell = exp2.Current(); - Msg::Debug("OCC Region %d - New Shell",tag()); - for(exp3.Init(shell, TopAbs_FACE); exp3.More(); exp3.Next()){ + Msg::Debug("OCC Region %d - New Shell", tag()); + for(exp3.Init(shell, TopAbs_FACE); exp3.More(); exp3.Next()) { TopoDS_Face face = TopoDS::Face(exp3.Current()); GFace *f = 0; if(model()->getOCCInternals()) f = model()->getOCCInternals()->getFaceForOCCShape(model(), face); - if(!f){ + if(!f) { Msg::Error("Unknown face in region %d", tag()); } - else if (face.Orientation() == TopAbs_INTERNAL){ + else if(face.Orientation() == TopAbs_INTERNAL) { Msg::Debug("Adding embedded face %d in region %d", f->tag(), tag()); embedded_faces.push_back(f); } - else{ + else { l_faces.push_back(f); f->addRegion(this); } } } - for (exp3.Init(s, TopAbs_EDGE, TopAbs_FACE); exp3.More(); exp3.Next()){ + for(exp3.Init(s, TopAbs_EDGE, TopAbs_FACE); exp3.More(); exp3.Next()) { TopoDS_Edge edge = TopoDS::Edge(exp3.Current()); GEdge *e = 0; if(model()->getOCCInternals()) e = model()->getOCCInternals()->getEdgeForOCCShape(model(), edge); - if(!e){ + if(!e) { Msg::Error("Unknown edge in region %d", tag()); } - else if (edge.Orientation() == TopAbs_INTERNAL){ + else if(edge.Orientation() == TopAbs_INTERNAL) { Msg::Debug("Adding embedded edge %d in region %d", e->tag(), tag()); embedded_edges.push_back(e); - //OCCEdge *occe = (OCCEdge*)e; - //occe->setTrimmed(this); + // OCCEdge *occe = (OCCEdge*)e; + // occe->setTrimmed(this); } } - for (exp3.Init(s, TopAbs_VERTEX, TopAbs_FACE); exp3.More(); exp3.Next()){ + for(exp3.Init(s, TopAbs_VERTEX, TopAbs_FACE); exp3.More(); exp3.Next()) { TopoDS_Vertex vertex = TopoDS::Vertex(exp3.Current()); GVertex *v = 0; if(model()->getOCCInternals()) v = model()->getOCCInternals()->getVertexForOCCShape(model(), vertex); - if (!v){ + if(!v) { Msg::Error("Unknown vertex in region %d", tag()); } - else if (vertex.Orientation() == TopAbs_INTERNAL){ + else if(vertex.Orientation() == TopAbs_INTERNAL) { Msg::Debug("Adding embedded vertex %d in region %d", v->tag(), tag()); embedded_vertices.push_back(v); } @@ -101,10 +99,9 @@ void OCCRegion::setup() SBoundingBox3d OCCRegion::bounds(bool fast) const { Bnd_Box b; - try{ + try { BRepBndLib::Add(s, b); - } - catch(Standard_Failure &err){ + } catch(Standard_Failure &err) { Msg::Error("OpenCASCADE exception %s", err.GetMessageString()); return SBoundingBox3d(); } @@ -114,10 +111,7 @@ SBoundingBox3d OCCRegion::bounds(bool fast) const return bbox; } -GEntity::GeomType OCCRegion::geomType() const -{ - return Volume; -} +GEntity::GeomType OCCRegion::geomType() const { return Volume; } void OCCRegion::writeBREP(const char *filename) { diff --git a/Geo/OCCRegion.h b/Geo/OCCRegion.h index 99e3bd8a4f3e4b26b5c75bada03cc7987604f267..a68a346ecfbbad1c9ec6dfa8ae815b7fbe2aac2a 100644 --- a/Geo/OCCRegion.h +++ b/Geo/OCCRegion.h @@ -14,16 +14,17 @@ #include <TopoDS_Solid.hxx> class OCCRegion : public GRegion { - protected: +protected: TopoDS_Solid s; void setup(); - public: + +public: OCCRegion(GModel *m, TopoDS_Solid s, int num); virtual ~OCCRegion(); virtual SBoundingBox3d bounds(bool fast = false) const; virtual GeomType geomType() const; ModelType getNativeType() const { return OpenCascadeModel; } - void * getNativePtr() const { return (void*)&s; } + void *getNativePtr() const { return (void *)&s; } TopoDS_Solid getTopoDS_Shape() { return s; } void writeBREP(const char *filename); }; diff --git a/Geo/OCCVertex.cpp b/Geo/OCCVertex.cpp index 47dcca0823999422bbab29dc20173a54be80ee41..c1eb92d58bdc2d7bd5ca2f8280909db37b1bd6a5 100644 --- a/Geo/OCCVertex.cpp +++ b/Geo/OCCVertex.cpp @@ -17,16 +17,14 @@ #include <gp_Pnt.hxx> OCCVertex::OCCVertex(GModel *m, int num, TopoDS_Vertex v, double lc) - : GVertex(m, num, lc) - , _v(v) + : GVertex(m, num, lc), _v(v) { max_curvature = -1; gp_Pnt pnt = BRep_Tool::Pnt(_v); _x = pnt.X(); _y = pnt.Y(); _z = pnt.Z(); - if(model()->getOCCInternals()) - model()->getOCCInternals()->bind(_v, num); + if(model()->getOCCInternals()) model()->getOCCInternals()->bind(_v, num); } OCCVertex::~OCCVertex() @@ -40,7 +38,7 @@ void OCCVertex::setPosition(GPoint &p) _x = p.x(); _y = p.y(); _z = p.z(); - if(mesh_vertices.size()){ + if(mesh_vertices.size()) { mesh_vertices[0]->x() = p.x(); mesh_vertices[0]->y() = p.y(); mesh_vertices[0]->z() = p.z(); @@ -53,7 +51,7 @@ double max_surf_curvature(const GVertex *gv, double x, double y, double z, std::vector<GFace *> faces = _myGEdge->faces(); std::vector<GFace *>::iterator it = faces.begin(); double curv = 1.e-22; - while(it != faces.end()){ + while(it != faces.end()) { SPoint2 par = gv->reparamOnFace((*it), 1); double cc = (*it)->curvatureDiv(par); if(cc > 0) curv = std::max(curv, cc); @@ -64,11 +62,11 @@ double max_surf_curvature(const GVertex *gv, double x, double y, double z, double OCCVertex::max_curvature_of_surfaces() const { - if(max_curvature < 0){ - for(std::vector<GEdge*>::const_iterator it = l_edges.begin(); - it != l_edges.end(); ++it){ - max_curvature = std::max(max_surf_curvature(this, x(), y(), z(), *it), - max_curvature); + if(max_curvature < 0) { + for(std::vector<GEdge *>::const_iterator it = l_edges.begin(); + it != l_edges.end(); ++it) { + max_curvature = + std::max(max_surf_curvature(this, x(), y(), z(), *it), max_curvature); } // printf("max curvature (%d) = %12.5E lc = %12.5E\n",tag(), // max_curvature, prescribedMeshSizeAtVertex()); @@ -78,15 +76,16 @@ double OCCVertex::max_curvature_of_surfaces() const SPoint2 OCCVertex::reparamOnFace(const GFace *gf, int dir) const { - std::vector<GEdge*>::const_iterator it = l_edges.begin(); - while(it != l_edges.end()){ - std::vector<GEdge*> const& l = gf->edges(); - if(std::find(l.begin(), l.end(), *it) != l.end()){ - if((*it)->isSeam(gf)){ - const TopoDS_Face *s = (TopoDS_Face*)gf->getNativePtr(); - const TopoDS_Edge *c = (TopoDS_Edge*)(*it)->getNativePtr(); - double s1,s0; - Handle(Geom2d_Curve) curve2d = BRep_Tool::CurveOnSurface(*c, *s, s0, s1); + std::vector<GEdge *>::const_iterator it = l_edges.begin(); + while(it != l_edges.end()) { + std::vector<GEdge *> const &l = gf->edges(); + if(std::find(l.begin(), l.end(), *it) != l.end()) { + if((*it)->isSeam(gf)) { + const TopoDS_Face *s = (TopoDS_Face *)gf->getNativePtr(); + const TopoDS_Edge *c = (TopoDS_Edge *)(*it)->getNativePtr(); + double s1, s0; + Handle(Geom2d_Curve) curve2d = + BRep_Tool::CurveOnSurface(*c, *s, s0, s1); if((*it)->getBeginVertex() == this) return (*it)->reparamOnFace(gf, s0, dir); else if((*it)->getEndVertex() == this) @@ -96,24 +95,25 @@ SPoint2 OCCVertex::reparamOnFace(const GFace *gf, int dir) const ++it; } it = l_edges.begin(); - while(it != l_edges.end()){ - std::vector<GEdge*> const& l = gf->edges(); - if(std::find(l.begin(), l.end(), *it) != l.end()){ - if (gf->getNativeType() == GEntity::OpenCascadeModel){ - const TopoDS_Face *s = (TopoDS_Face*)gf->getNativePtr(); - const TopoDS_Edge *c = (TopoDS_Edge*)(*it)->getNativePtr(); - double s1,s0; - Handle(Geom2d_Curve) curve2d = BRep_Tool::CurveOnSurface(*c, *s, s0, s1); - if((*it)->getBeginVertex() == this) - return (*it)->reparamOnFace(gf, s0, dir); - else if((*it)->getEndVertex() == this) - return (*it)->reparamOnFace(gf, s1, dir); + while(it != l_edges.end()) { + std::vector<GEdge *> const &l = gf->edges(); + if(std::find(l.begin(), l.end(), *it) != l.end()) { + if(gf->getNativeType() == GEntity::OpenCascadeModel) { + const TopoDS_Face *s = (TopoDS_Face *)gf->getNativePtr(); + const TopoDS_Edge *c = (TopoDS_Edge *)(*it)->getNativePtr(); + double s1, s0; + Handle(Geom2d_Curve) curve2d = + BRep_Tool::CurveOnSurface(*c, *s, s0, s1); + if((*it)->getBeginVertex() == this) + return (*it)->reparamOnFace(gf, s0, dir); + else if((*it)->getEndVertex() == this) + return (*it)->reparamOnFace(gf, s1, dir); } - //if not OCCFace (OK for planar faces) - else{ - const GPoint pt = point(); - SPoint3 sp(pt.x(), pt.y(), pt.z()); - gf->parFromPoint(sp); + // if not OCCFace (OK for planar faces) + else { + const GPoint pt = point(); + SPoint3 sp(pt.x(), pt.y(), pt.z()); + gf->parFromPoint(sp); } } ++it; diff --git a/Geo/OCCVertex.h b/Geo/OCCVertex.h index ea07d0f561b78c2ba8d2374a321fca36bea47318..bad584f4c721570f3a64704cfd1887d9eb4abc9d 100644 --- a/Geo/OCCVertex.h +++ b/Geo/OCCVertex.h @@ -15,13 +15,14 @@ #include <TopoDS_Vertex.hxx> class OCCVertex : public GVertex { - protected: +protected: TopoDS_Vertex _v; double _x, _y, _z; mutable double max_curvature; double max_curvature_of_surfaces() const; - public: - OCCVertex(GModel *m, int num, TopoDS_Vertex v, double lc=MAX_LC); + +public: + OCCVertex(GModel *m, int num, TopoDS_Vertex v, double lc = MAX_LC); virtual ~OCCVertex(); virtual GPoint point() const { return GPoint(x(), y(), z()); } virtual double x() const { return _x; } @@ -29,7 +30,7 @@ class OCCVertex : public GVertex { virtual double z() const { return _z; } virtual void setPosition(GPoint &p); ModelType getNativeType() const { return OpenCascadeModel; } - void *getNativePtr() const { return (void*)&_v; } + void *getNativePtr() const { return (void *)&_v; } virtual SPoint2 reparamOnFace(const GFace *gf, int) const; TopoDS_Vertex getShape() { return _v; } }; diff --git a/Geo/Pair.h b/Geo/Pair.h index a625c8d3ce26a9fb70d9f32af9f35acf45d150eb..6e291a693fe4c6e6662b1a5af9ca3803450ff1d1 100644 --- a/Geo/Pair.h +++ b/Geo/Pair.h @@ -7,18 +7,18 @@ #define _PAIR_H_ // A pair of values, the types of which can be different -template <class L, class R> -class Pair{ - private: +template <class L, class R> class Pair { +private: L Left; R Right; - public: + +public: Pair() {} - Pair(const L& left, const R& right) : Left(left), Right(right) {} + Pair(const L &left, const R &right) : Left(left), Right(right) {} L left() const { return Left; } - void left(const L& left) { Left = left; } + void left(const L &left) { Left = left; } R right() const { return Right; } - void right(const R& right) { Right = right; } + void right(const R &right) { Right = right; } L first() const { return Left; } R second() const { return Right; } }; diff --git a/Geo/Range.h b/Geo/Range.h index b2a7db99b92e8f92fc1d169b6173e5ea04e9f772..56dcfb6a378429e6a22dddf9fcc7c96af9d2e68f 100644 --- a/Geo/Range.h +++ b/Geo/Range.h @@ -7,33 +7,36 @@ #define _RANGE_H_ // represents a range of values of the template type -template <class T> -class Range { - private: +template <class T> class Range { +private: T Low; T High; - public: + +public: Range() {} - Range(const T& low, const T& high) : Low(low), High(high) {} + Range(const T &low, const T &high) : Low(low), High(high) {} T low() const { return Low; } - void low(const T& low) { Low = low; } + void low(const T &low) { Low = low; } T high() const { return High; } - void high(const T& high) { High = high; } - int contains(const T& value) const; - int contains(const Range<T> & range) const; - int operator == (const Range<T> &range) const; + void high(const T &high) { High = high; } + int contains(const T &value) const; + int contains(const Range<T> &range) const; + int operator==(const Range<T> &range) const; }; -template<class T> -int Range<T>::contains(const T& value) const -{ return ( (value >= Low) && (value <= High) ); } +template <class T> int Range<T>::contains(const T &value) const +{ + return ((value >= Low) && (value <= High)); +} -template<class T> -int Range<T>::contains(const Range<T>& range) const -{ return ( (range.low() >= Low) && (range.high() <= High) ); } +template <class T> int Range<T>::contains(const Range<T> &range) const +{ + return ((range.low() >= Low) && (range.high() <= High)); +} -template<class T> -int Range<T>::operator == (const Range<T>& range) const -{ return ( (range.low() == Low) && (range.high() == High) ); } +template <class T> int Range<T>::operator==(const Range<T> &range) const +{ + return ((range.low() == Low) && (range.high() == High)); +} #endif diff --git a/Geo/SBoundingBox3d.h b/Geo/SBoundingBox3d.h index 710e6207351216f0e20a500429100db718e8047c..269a8d989850456d70c64f20bc30684aa8bc3624 100644 --- a/Geo/SBoundingBox3d.h +++ b/Geo/SBoundingBox3d.h @@ -19,16 +19,20 @@ // A bounding box class - add points and it grows to be the bounding // box of the point set class SBoundingBox3d { - private: +private: SPoint3 MinPt, MaxPt; - public: + +public: SBoundingBox3d() - : MinPt(DBL_MAX,DBL_MAX,DBL_MAX), MaxPt(-DBL_MAX,-DBL_MAX,-DBL_MAX) {} - SBoundingBox3d(const SPoint3 &pt) - : MinPt(pt), MaxPt(pt) {} - SBoundingBox3d(double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax) - : MinPt(xmin, ymin, zmin), MaxPt(xmax, ymax, zmax) {} + : MinPt(DBL_MAX, DBL_MAX, DBL_MAX), MaxPt(-DBL_MAX, -DBL_MAX, -DBL_MAX) + { + } + SBoundingBox3d(const SPoint3 &pt) : MinPt(pt), MaxPt(pt) {} + SBoundingBox3d(double xmin, double ymin, double zmin, double xmax, + double ymax, double zmax) + : MinPt(xmin, ymin, zmin), MaxPt(xmax, ymax, zmax) + { + } bool empty() { if(MinPt.x() == DBL_MAX || MinPt.y() == DBL_MAX || MinPt.z() == DBL_MAX || @@ -38,27 +42,21 @@ class SBoundingBox3d { } void reset() { - MinPt = SPoint3(DBL_MAX,DBL_MAX,DBL_MAX); - MaxPt = SPoint3(-DBL_MAX,-DBL_MAX,-DBL_MAX); + MinPt = SPoint3(DBL_MAX, DBL_MAX, DBL_MAX); + MaxPt = SPoint3(-DBL_MAX, -DBL_MAX, -DBL_MAX); } void operator+=(const SPoint3 &pt) { // note: it is possible for pt[i] to be both > MaxPt[i] and < MinPt[i] // the first point always will be both - if(pt[0] < MinPt[0]) - MinPt[0] = pt[0]; - if (pt[0] > MaxPt[0]) - MaxPt[0] = pt[0]; + if(pt[0] < MinPt[0]) MinPt[0] = pt[0]; + if(pt[0] > MaxPt[0]) MaxPt[0] = pt[0]; - if(pt[1] < MinPt[1]) - MinPt[1] = pt[1]; - if (pt[1] > MaxPt[1]) - MaxPt[1] = pt[1]; + if(pt[1] < MinPt[1]) MinPt[1] = pt[1]; + if(pt[1] > MaxPt[1]) MaxPt[1] = pt[1]; - if(pt[2] < MinPt[2]) - MinPt[2] = pt[2]; - if (pt[2] > MaxPt[2]) - MaxPt[2] = pt[2]; + if(pt[2] < MinPt[2]) MinPt[2] = pt[2]; + if(pt[2] > MaxPt[2]) MaxPt[2] = pt[2]; } void operator+=(const SBoundingBox3d &box) { @@ -80,8 +78,12 @@ class SBoundingBox3d { SPoint3 center = (MinPt + MaxPt) * .5; MaxPt -= center; MinPt -= center; - MaxPt[0] *= sx; MaxPt[1] *= sy; MaxPt[2] *= sz; - MinPt[0] *= sx; MinPt[1] *= sy; MinPt[2] *= sz; + MaxPt[0] *= sx; + MaxPt[1] *= sy; + MaxPt[2] *= sz; + MinPt[0] *= sx; + MinPt[1] *= sy; + MinPt[2] *= sz; MaxPt += center; MinPt += center; } @@ -100,32 +102,24 @@ class SBoundingBox3d { } bool contains(const SBoundingBox3d &bound) { - if(bound.MinPt.x() >= MinPt.x() && - bound.MinPt.y() >= MinPt.y() && - bound.MinPt.z() >= MinPt.z() && - bound.MaxPt.x() <= MaxPt.x() && - bound.MaxPt.y() <= MaxPt.y() && - bound.MaxPt.z() <= MaxPt.z()) return true; + if(bound.MinPt.x() >= MinPt.x() && bound.MinPt.y() >= MinPt.y() && + bound.MinPt.z() >= MinPt.z() && bound.MaxPt.x() <= MaxPt.x() && + bound.MaxPt.y() <= MaxPt.y() && bound.MaxPt.z() <= MaxPt.z()) + return true; return false; } bool contains(const SPoint3 &p) { - if(p.x() >= MinPt.x() && - p.y() >= MinPt.y() && - p.z() >= MinPt.z() && - p.x() <= MaxPt.x() && - p.y() <= MaxPt.y() && - p.z() <= MaxPt.z()) return true; + if(p.x() >= MinPt.x() && p.y() >= MinPt.y() && p.z() >= MinPt.z() && + p.x() <= MaxPt.x() && p.y() <= MaxPt.y() && p.z() <= MaxPt.z()) + return true; return false; } bool contains(double x, double y, double z) { - if(x >= MinPt.x() && - y >= MinPt.y() && - z >= MinPt.z() && - x <= MaxPt.x() && - y <= MaxPt.y() && - z <= MaxPt.z()) return true; + if(x >= MinPt.x() && y >= MinPt.y() && z >= MinPt.z() && x <= MaxPt.x() && + y <= MaxPt.y() && z <= MaxPt.z()) + return true; return false; } }; diff --git a/Geo/SOrientedBoundingBox.cpp b/Geo/SOrientedBoundingBox.cpp index 30234cfc1a95a6fbbaa2bc0f1f4f2dca6ee14ec9..ae91ab7f81817bca39dcbfcef074bcd81dcfece4 100644 --- a/Geo/SOrientedBoundingBox.cpp +++ b/Geo/SOrientedBoundingBox.cpp @@ -23,15 +23,15 @@ double SOrientedBoundingRectangle::area() { double b = size->at(0); double B = size->at(1); - return (b*B); + return (b * B); } SOrientedBoundingRectangle::SOrientedBoundingRectangle() { - center = new std::vector<double>(2,0); - size = new std::vector<double>(2,0); - axisX = new std::vector<double>(2,0); - axisY = new std::vector<double>(2,0); + center = new std::vector<double>(2, 0); + size = new std::vector<double>(2, 0); + axisX = new std::vector<double>(2, 0); + axisY = new std::vector<double>(2, 0); } SOrientedBoundingRectangle::~SOrientedBoundingRectangle() @@ -48,37 +48,37 @@ void SOrientedBoundingBox::fillp() double dy = 0.5 * size[1]; double dz = 0.5 * size[2]; - p1x = center[0] - (axisX[0]*dx) - (axisY[0]*dy) - (axisZ[0]*dz); - p1y = center[1] - (axisX[1]*dx) - (axisY[1]*dy) - (axisZ[1]*dz); - p1z = center[2] - (axisX[2]*dx) - (axisY[2]*dy) - (axisZ[2]*dz); + p1x = center[0] - (axisX[0] * dx) - (axisY[0] * dy) - (axisZ[0] * dz); + p1y = center[1] - (axisX[1] * dx) - (axisY[1] * dy) - (axisZ[1] * dz); + p1z = center[2] - (axisX[2] * dx) - (axisY[2] * dy) - (axisZ[2] * dz); - p2x = center[0] + (axisX[0]*dx) - (axisY[0]*dy) - (axisZ[0]*dz); - p2y = center[1] + (axisX[1]*dx) - (axisY[1]*dy) - (axisZ[1]*dz); - p2z = center[2] + (axisX[2]*dx) - (axisY[2]*dy) - (axisZ[2]*dz); + p2x = center[0] + (axisX[0] * dx) - (axisY[0] * dy) - (axisZ[0] * dz); + p2y = center[1] + (axisX[1] * dx) - (axisY[1] * dy) - (axisZ[1] * dz); + p2z = center[2] + (axisX[2] * dx) - (axisY[2] * dy) - (axisZ[2] * dz); - p3x = center[0] - (axisX[0]*dx) + (axisY[0]*dy) - (axisZ[0]*dz); - p3y = center[1] - (axisX[1]*dx) + (axisY[1]*dy) - (axisZ[1]*dz); - p3z = center[2] - (axisX[2]*dx) + (axisY[2]*dy) - (axisZ[2]*dz); + p3x = center[0] - (axisX[0] * dx) + (axisY[0] * dy) - (axisZ[0] * dz); + p3y = center[1] - (axisX[1] * dx) + (axisY[1] * dy) - (axisZ[1] * dz); + p3z = center[2] - (axisX[2] * dx) + (axisY[2] * dy) - (axisZ[2] * dz); - p4x = center[0] + (axisX[0]*dx) + (axisY[0]*dy) - (axisZ[0]*dz); - p4y = center[1] + (axisX[1]*dx) + (axisY[1]*dy) - (axisZ[1]*dz); - p4z = center[2] + (axisX[2]*dx) + (axisY[2]*dy) - (axisZ[2]*dz); + p4x = center[0] + (axisX[0] * dx) + (axisY[0] * dy) - (axisZ[0] * dz); + p4y = center[1] + (axisX[1] * dx) + (axisY[1] * dy) - (axisZ[1] * dz); + p4z = center[2] + (axisX[2] * dx) + (axisY[2] * dy) - (axisZ[2] * dz); - p5x = center[0] - (axisX[0]*dx) - (axisY[0]*dy) + (axisZ[0]*dz); - p5y = center[1] - (axisX[1]*dx) - (axisY[1]*dy) + (axisZ[1]*dz); - p5z = center[2] - (axisX[2]*dx) - (axisY[2]*dy) + (axisZ[2]*dz); + p5x = center[0] - (axisX[0] * dx) - (axisY[0] * dy) + (axisZ[0] * dz); + p5y = center[1] - (axisX[1] * dx) - (axisY[1] * dy) + (axisZ[1] * dz); + p5z = center[2] - (axisX[2] * dx) - (axisY[2] * dy) + (axisZ[2] * dz); - p6x = center[0] + (axisX[0]*dx) - (axisY[0]*dy) + (axisZ[0]*dz); - p6y = center[1] + (axisX[1]*dx) - (axisY[1]*dy) + (axisZ[1]*dz); - p6z = center[2] + (axisX[2]*dx) - (axisY[2]*dy) + (axisZ[2]*dz); + p6x = center[0] + (axisX[0] * dx) - (axisY[0] * dy) + (axisZ[0] * dz); + p6y = center[1] + (axisX[1] * dx) - (axisY[1] * dy) + (axisZ[1] * dz); + p6z = center[2] + (axisX[2] * dx) - (axisY[2] * dy) + (axisZ[2] * dz); - p7x = center[0] - (axisX[0]*dx) + (axisY[0]*dy) + (axisZ[0]*dz); - p7y = center[1] - (axisX[1]*dx) + (axisY[1]*dy) + (axisZ[1]*dz); - p7z = center[2] - (axisX[2]*dx) + (axisY[2]*dy) + (axisZ[2]*dz); + p7x = center[0] - (axisX[0] * dx) + (axisY[0] * dy) + (axisZ[0] * dz); + p7y = center[1] - (axisX[1] * dx) + (axisY[1] * dy) + (axisZ[1] * dz); + p7z = center[2] - (axisX[2] * dx) + (axisY[2] * dy) + (axisZ[2] * dz); - p8x = center[0] + (axisX[0]*dx) + (axisY[0]*dy) + (axisZ[0]*dz); - p8y = center[1] + (axisX[1]*dx) + (axisY[1]*dy) + (axisZ[1]*dz); - p8z = center[2] + (axisX[2]*dx) + (axisY[2]*dy) + (axisZ[2]*dz); + p8x = center[0] + (axisX[0] * dx) + (axisY[0] * dy) + (axisZ[0] * dz); + p8y = center[1] + (axisX[1] * dx) + (axisY[1] * dy) + (axisZ[1] * dz); + p8z = center[2] + (axisX[2] * dx) + (axisY[2] * dy) + (axisZ[2] * dz); } SOrientedBoundingBox::SOrientedBoundingBox() @@ -91,10 +91,8 @@ SOrientedBoundingBox::SOrientedBoundingBox() fillp(); } -SOrientedBoundingBox::SOrientedBoundingBox(SVector3 ¢er_, - double sizeX, - double sizeY, - double sizeZ, +SOrientedBoundingBox::SOrientedBoundingBox(SVector3 ¢er_, double sizeX, + double sizeY, double sizeZ, const SVector3 &axisX_, const SVector3 &axisY_, const SVector3 &axisZ_) @@ -110,7 +108,7 @@ SOrientedBoundingBox::SOrientedBoundingBox(SVector3 ¢er_, fillp(); } -SOrientedBoundingBox::SOrientedBoundingBox(SOrientedBoundingBox* other) +SOrientedBoundingBox::SOrientedBoundingBox(SOrientedBoundingBox *other) { size = other->getSize(); axisX = other->getAxis(0); @@ -133,7 +131,7 @@ double SOrientedBoundingBox::getMinSize() SVector3 SOrientedBoundingBox::getAxis(int axis) { SVector3 ret; - switch (axis) { + switch(axis) { case 0: ret = axisX; break; case 1: ret = axisY; break; case 2: ret = axisZ; break; @@ -141,50 +139,50 @@ SVector3 SOrientedBoundingBox::getAxis(int axis) return ret; } -bool SOrientedBoundingBox::intersects(SOrientedBoundingBox& obb) +bool SOrientedBoundingBox::intersects(SOrientedBoundingBox &obb) { SVector3 collide_axes[15]; - for (int i = 0; i < 3; i ++) { + for(int i = 0; i < 3; i++) { collide_axes[i] = getAxis(i); - collide_axes[i+3] = obb.getAxis(i); + collide_axes[i + 3] = obb.getAxis(i); } SVector3 sizes[2]; sizes[0] = getSize(); sizes[1] = obb.getSize(); - for(unsigned int i=0 ; i<3 ; i++) { - for(unsigned int j=3 ; j<6 ; j++) { - collide_axes[3*i+j+3] = crossprod(collide_axes[i],collide_axes[j]); + for(unsigned int i = 0; i < 3; i++) { + for(unsigned int j = 3; j < 6; j++) { + collide_axes[3 * i + j + 3] = crossprod(collide_axes[i], collide_axes[j]); } } SVector3 T = obb.getCenter() - getCenter(); - for(unsigned int i=0 ; i<15 ; i++) { + for(unsigned int i = 0; i < 15; i++) { double val = 0.0; - for(unsigned int j=0 ; j<6 ; j++) { - val += 0.5*(sizes[j<3?0:1])(j % 3) * fabs(dot(collide_axes[j],collide_axes[i])); + for(unsigned int j = 0; j < 6; j++) { + val += 0.5 * (sizes[j < 3 ? 0 : 1])(j % 3) * + fabs(dot(collide_axes[j], collide_axes[i])); } - if (fabs(dot(collide_axes[i],T )) > val) - return false; + if(fabs(dot(collide_axes[i], T)) > val) return false; } return true; } - -SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& vertices) +SOrientedBoundingBox * +SOrientedBoundingBox::buildOBB(std::vector<SPoint3> &vertices) { #if defined(HAVE_MESH) int num_vertices = vertices.size(); // First organize the data - + std::set<SPoint3> unique; - unique.insert(vertices.begin(),vertices.end()); - + unique.insert(vertices.begin(), vertices.end()); + num_vertices = unique.size(); - fullMatrix<double> data(3,num_vertices); + fullMatrix<double> data(3, num_vertices); fullVector<double> mean(3); fullVector<double> vmins(3); @@ -195,122 +193,129 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& verti vmaxs.setAll(-DBL_MAX); size_t idx = 0; - for (std::set<SPoint3>::iterator uIter=unique.begin();uIter!=unique.end();++uIter) { - - const SPoint3& pp = *uIter; - for (int d=0;d<3;d++) { - data(d,idx) = pp[d]; - vmins(d) = std::min(vmins(d),pp[d]); - vmaxs(d) = std::max(vmaxs(d),pp[d]); + for(std::set<SPoint3>::iterator uIter = unique.begin(); uIter != unique.end(); + ++uIter) { + const SPoint3 &pp = *uIter; + for(int d = 0; d < 3; d++) { + data(d, idx) = pp[d]; + vmins(d) = std::min(vmins(d), pp[d]); + vmaxs(d) = std::max(vmaxs(d), pp[d]); mean(d) += pp[d]; } idx++; } - for (int i=0;i<3;i++) mean(i) /= num_vertices; - + for(int i = 0; i < 3; i++) mean(i) /= num_vertices; + // Get the deviation from the mean - fullMatrix<double> B(3,num_vertices); - for (int i = 0; i < 3; i++) { - for (int j = 0; j < num_vertices; j++) { - B(i,j) = data(i,j) - mean(i); + fullMatrix<double> B(3, num_vertices); + for(int i = 0; i < 3; i++) { + for(int j = 0; j < num_vertices; j++) { + B(i, j) = data(i, j) - mean(i); } } // Compute the covariance matrix - fullMatrix<double> covariance(3,3); + fullMatrix<double> covariance(3, 3); B.mult(B.transpose(), covariance); - covariance.scale(1./(num_vertices-1)); + covariance.scale(1. / (num_vertices - 1)); /* Msg::Debug("Covariance matrix"); Msg::Debug("%f %f %f", covariance(0,0),covariance(0,1),covariance(0,2) ); Msg::Debug("%f %f %f", covariance(1,0),covariance(1,1),covariance(1,2) ); Msg::Debug("%f %f %f", covariance(2,0),covariance(2,1),covariance(2,2) ); */ - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - if (fabs(covariance(i,j))< 10e-16) - covariance(i,j) = 0; + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + if(fabs(covariance(i, j)) < 10e-16) covariance(i, j) = 0; } } - fullMatrix<double> left_eigv(3,3); - fullMatrix<double> right_eigv(3,3); + fullMatrix<double> left_eigv(3, 3); + fullMatrix<double> right_eigv(3, 3); fullVector<double> real_eig(3); fullVector<double> img_eig(3); - covariance.eig(real_eig, img_eig, left_eigv, right_eigv,true); + covariance.eig(real_eig, img_eig, left_eigv, right_eigv, true); // Now, project the data in the new basis. - fullMatrix<double> projected(3,num_vertices); - left_eigv.transpose().mult(data,projected); + fullMatrix<double> projected(3, num_vertices); + left_eigv.transpose().mult(data, projected); // Get the size of the box in the new direction fullVector<double> mins(3); fullVector<double> maxs(3); - for (int i = 0; i < 3; i++) { + for(int i = 0; i < 3; i++) { mins(i) = DBL_MAX; maxs(i) = -DBL_MAX; - for (int j = 0; j < num_vertices; j++) { - maxs(i) =std::max(maxs(i),projected(i,j)); - mins(i) = std::min(mins(i),projected(i,j)); + for(int j = 0; j < num_vertices; j++) { + maxs(i) = std::max(maxs(i), projected(i, j)); + mins(i) = std::min(mins(i), projected(i, j)); } } - //double means[3]; + // double means[3]; double sizes[3]; // Note: the size is computed in the box's coordinates! - for(int i = 0 ; i < 3 ; i++) { + for(int i = 0; i < 3; i++) { sizes[i] = maxs(i) - mins(i); - //means[i] = (maxs(i) - mins(i)) / 2.; + // means[i] = (maxs(i) - mins(i)) / 2.; } - if (sizes[0] == 0 && sizes[1] == 0) { + if(sizes[0] == 0 && sizes[1] == 0) { // Entity is a straight line... SVector3 center; SVector3 Axis1; SVector3 Axis2; SVector3 Axis3; - Axis1[0] = left_eigv(0,0); Axis1[1] = left_eigv(1,0); Axis1[2] = left_eigv(2,0); - Axis2[0] = left_eigv(0,1); Axis2[1] = left_eigv(1,1); Axis2[2] = left_eigv(2,1); - Axis3[0] = left_eigv(0,2); Axis3[1] = left_eigv(1,2); Axis3[2] = left_eigv(2,2); - - center[0] = (vmaxs(0)+vmins(0))/2.0; - center[1] = (vmaxs(1)+vmins(1))/2.0; - center[2] = (vmaxs(2)+vmins(2))/2.0; - - return(new SOrientedBoundingBox(center, sizes[0], sizes[1], sizes[2], - Axis1, Axis2, Axis3)); + Axis1[0] = left_eigv(0, 0); + Axis1[1] = left_eigv(1, 0); + Axis1[2] = left_eigv(2, 0); + Axis2[0] = left_eigv(0, 1); + Axis2[1] = left_eigv(1, 1); + Axis2[2] = left_eigv(2, 1); + Axis3[0] = left_eigv(0, 2); + Axis3[1] = left_eigv(1, 2); + Axis3[2] = left_eigv(2, 2); + + center[0] = (vmaxs(0) + vmins(0)) / 2.0; + center[1] = (vmaxs(1) + vmins(1)) / 2.0; + center[2] = (vmaxs(2) + vmins(2)) / 2.0; + + return (new SOrientedBoundingBox(center, sizes[0], sizes[1], sizes[2], + Axis1, Axis2, Axis3)); } // We take the smallest component, then project the data on the plane defined // by the other twos int smallest_comp = 0; - if (sizes[0] <= sizes[1] && sizes[0] <= sizes[2]) + if(sizes[0] <= sizes[1] && sizes[0] <= sizes[2]) smallest_comp = 0; - else if (sizes[1] <= sizes[0] && sizes[1] <= sizes[2]) + else if(sizes[1] <= sizes[0] && sizes[1] <= sizes[2]) smallest_comp = 1; - else if (sizes[2] <= sizes[0] && sizes[2] <= sizes[1]) + else if(sizes[2] <= sizes[0] && sizes[2] <= sizes[1]) smallest_comp = 2; // The projection has been done circa line 161. // We just ignore the coordinate corresponding to smallest_comp. - std::vector<SPoint2*> points; - for (int i = 0; i < num_vertices; i++) { - SPoint2* p = new SPoint2(projected(smallest_comp==0?1:0,i), - projected(smallest_comp==2?1:2,i)); + std::vector<SPoint2 *> points; + for(int i = 0; i < num_vertices; i++) { + SPoint2 *p = new SPoint2(projected(smallest_comp == 0 ? 1 : 0, i), + projected(smallest_comp == 2 ? 1 : 2, i)); bool keep = true; - for (std::vector<SPoint2*>::iterator point = points.begin(); - point != points.end();point++) { - if ( fabs((*p)[0] -(**point)[0]) < 10e-10 && fabs((*p)[1] -(**point)[1]) < 10e-10 ) { + for(std::vector<SPoint2 *>::iterator point = points.begin(); + point != points.end(); point++) { + if(fabs((*p)[0] - (**point)[0]) < 10e-10 && + fabs((*p)[1] - (**point)[1]) < 10e-10) { keep = false; break; } } - if (keep) { + if(keep) { points.push_back(p); - } else { + } + else { delete p; } } @@ -319,23 +324,24 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& verti DocRecord record(points.size()); record.numPoints = points.size(); srand((unsigned)time(0)); - for (unsigned int i = 0; i < points.size(); i++) { - record.points[i].where.h = points[i]->x()+ - (10e-6)*sizes[smallest_comp==0?1:0]*(-0.5+((double)rand())/RAND_MAX); - record.points[i].where.v = points[i]->y()+ - (10e-6)*sizes[smallest_comp==2?1:0]*(-0.5+((double)rand())/RAND_MAX); + for(unsigned int i = 0; i < points.size(); i++) { + record.points[i].where.h = + points[i]->x() + (10e-6) * sizes[smallest_comp == 0 ? 1 : 0] * + (-0.5 + ((double)rand()) / RAND_MAX); + record.points[i].where.v = + points[i]->y() + (10e-6) * sizes[smallest_comp == 2 ? 1 : 0] * + (-0.5 + ((double)rand()) / RAND_MAX); record.points[i].adjacent = NULL; } - try{ + try { record.MakeMeshWithPoints(); - } - catch(const char *err){ + } catch(const char *err) { Msg::Error("%s", err); } std::vector<Segment> convex_hull; - for (int i = 0; i < record.numTriangles; i++) { + for(int i = 0; i < record.numTriangles; i++) { Segment segs[3]; segs[0].from = record.triangles[i].a; segs[0].to = record.triangles[i].b; @@ -344,28 +350,28 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& verti segs[2].from = record.triangles[i].c; segs[2].to = record.triangles[i].a; - for (int j = 0; j < 3; j++) { + for(int j = 0; j < 3; j++) { bool okay = true; - for (std::vector<Segment>::iterator seg = convex_hull.begin(); - seg != convex_hull.end(); seg++) { - if ( ((*seg).from == segs[j].from && (*seg).from == segs[j].to) - // FIXME: - // || ((*seg).from == segs[j].to && (*seg).from == segs[j].from) - ) { + for(std::vector<Segment>::iterator seg = convex_hull.begin(); + seg != convex_hull.end(); seg++) { + if(((*seg).from == segs[j].from && (*seg).from == segs[j].to) + // FIXME: + // || ((*seg).from == segs[j].to && (*seg).from == segs[j].from) + ) { convex_hull.erase(seg); okay = false; break; } } - if (okay) { + if(okay) { convex_hull.push_back(segs[j]); } } } // Now, examinate all the directions given by the edges of the convex hull - // to find the one that lets us build the least-area bounding rectangle for then - // points. + // to find the one that lets us build the least-area bounding rectangle for + // then points. fullVector<double> axis(2); axis(0) = 1; axis(1) = 0; @@ -378,76 +384,79 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& verti least_rectangle.size->at(0) = -1; least_rectangle.size->at(1) = 1; - for (std::vector<Segment>::iterator seg = convex_hull.begin(); - seg != convex_hull.end(); seg++) { - + for(std::vector<Segment>::iterator seg = convex_hull.begin(); + seg != convex_hull.end(); seg++) { fullVector<double> segment(2); - //segment(0) = record.points[(*seg).from].where.h - record.points[(*seg).to].where.h; - //segment(1) = record.points[(*seg).from].where.v - record.points[(*seg).to].where.v; + // segment(0) = record.points[(*seg).from].where.h - + // record.points[(*seg).to].where.h; segment(1) = + // record.points[(*seg).from].where.v - record.points[(*seg).to].where.v; segment(0) = points[(*seg).from]->x() - points[(*seg).to]->x(); segment(1) = points[(*seg).from]->y() - points[(*seg).to]->y(); - segment.scale(1.0/segment.norm()); + segment.scale(1.0 / segment.norm()); - double cosine = axis(0)*segment(0) + segment(1)*axis(1); - double sine = axis(1)*segment(0) - segment(1)*axis(0); - //double sine = axis(0)*segment(1) - segment(0)*axis(1); + double cosine = axis(0) * segment(0) + segment(1) * axis(1); + double sine = axis(1) * segment(0) - segment(1) * axis(0); + // double sine = axis(0)*segment(1) - segment(0)*axis(1); - fullMatrix<double> rotation(2,2); + fullMatrix<double> rotation(2, 2); - rotation(0,0) = cosine; rotation(0,1) = sine; - rotation(1,0) = -sine; rotation(1,1) = cosine; + rotation(0, 0) = cosine; + rotation(0, 1) = sine; + rotation(1, 0) = -sine; + rotation(1, 1) = cosine; double max_x = -DBL_MAX; double min_x = DBL_MAX; double max_y = -DBL_MAX; double min_y = DBL_MAX; - for (int i = 0; i < record.numPoints; i++) { + for(int i = 0; i < record.numPoints; i++) { fullVector<double> pnt(2); - //pnt(0) = record.points[i].where.h; - //pnt(1) = record.points[i].where.v; + // pnt(0) = record.points[i].where.h; + // pnt(1) = record.points[i].where.v; pnt(0) = points[i]->x(); pnt(1) = points[i]->y(); fullVector<double> rot_pnt(2); - rotation.mult(pnt,rot_pnt); - if (rot_pnt(0) < min_x) min_x = rot_pnt(0); - if (rot_pnt(0) > max_x) max_x = rot_pnt(0); - if (rot_pnt(1) < min_y) min_y = rot_pnt(1); - if (rot_pnt(1) > max_y) max_y = rot_pnt(1); + rotation.mult(pnt, rot_pnt); + if(rot_pnt(0) < min_x) min_x = rot_pnt(0); + if(rot_pnt(0) > max_x) max_x = rot_pnt(0); + if(rot_pnt(1) < min_y) min_y = rot_pnt(1); + if(rot_pnt(1) > max_y) max_y = rot_pnt(1); } -/**/ + /**/ fullVector<double> center_rot(2); fullVector<double> center_before_rot(2); - center_before_rot(0) = (max_x+min_x)/2.0; - center_before_rot(1) = (max_y+min_y)/2.0; - fullMatrix<double> rotation_inv(2,2); + center_before_rot(0) = (max_x + min_x) / 2.0; + center_before_rot(1) = (max_y + min_y) / 2.0; + fullMatrix<double> rotation_inv(2, 2); - rotation_inv(0,0) = cosine; rotation_inv(0,1) = -sine; - rotation_inv(1,0) = sine; rotation_inv(1,1) = cosine; + rotation_inv(0, 0) = cosine; + rotation_inv(0, 1) = -sine; + rotation_inv(1, 0) = sine; + rotation_inv(1, 1) = cosine; - rotation_inv.mult(center_before_rot,center_rot); + rotation_inv.mult(center_before_rot, center_rot); fullVector<double> axis_rot1(2); fullVector<double> axis_rot2(2); - rotation_inv.mult(axis,axis_rot1); - rotation_inv.mult(axis2,axis_rot2); -//*/ - - if ((least_rectangle.area() == -1) || - (max_x-min_x)*(max_y-min_y) < least_rectangle.area()) { + rotation_inv.mult(axis, axis_rot1); + rotation_inv.mult(axis2, axis_rot2); + //*/ - least_rectangle.size->at(0) = max_x-min_x; - least_rectangle.size->at(1) = max_y-min_y; - least_rectangle.center->at(0) = (max_x+min_x)/2.0; - least_rectangle.center->at(1) = (max_y+min_y)/2.0; + if((least_rectangle.area() == -1) || + (max_x - min_x) * (max_y - min_y) < least_rectangle.area()) { + least_rectangle.size->at(0) = max_x - min_x; + least_rectangle.size->at(1) = max_y - min_y; + least_rectangle.center->at(0) = (max_x + min_x) / 2.0; + least_rectangle.center->at(1) = (max_y + min_y) / 2.0; least_rectangle.center->at(0) = center_rot(0); least_rectangle.center->at(1) = center_rot(1); least_rectangle.axisX->at(0) = axis_rot1(0); least_rectangle.axisX->at(1) = axis_rot1(1); -// least_rectangle.axisX->at(0) = segment(0); -// least_rectangle.axisX->at(1) = segment(1); + // least_rectangle.axisX->at(0) = segment(0); + // least_rectangle.axisX->at(1) = segment(1); least_rectangle.axisY->at(0) = axis_rot2(0); least_rectangle.axisY->at(1) = axis_rot2(1); } @@ -455,12 +464,12 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& verti double min_pca = DBL_MAX; double max_pca = -DBL_MAX; - for (int i = 0; i < num_vertices; i++) { - min_pca = std::min(min_pca,projected(smallest_comp,i)); - max_pca = std::max(max_pca,projected(smallest_comp,i)); + for(int i = 0; i < num_vertices; i++) { + min_pca = std::min(min_pca, projected(smallest_comp, i)); + max_pca = std::max(max_pca, projected(smallest_comp, i)); } - double center_pca = (max_pca+min_pca)/2.0; - double size_pca = (max_pca-min_pca); + double center_pca = (max_pca + min_pca) / 2.0; + double size_pca = (max_pca - min_pca); double raw_data[3][5]; raw_data[0][0] = size_pca; @@ -471,44 +480,53 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& verti raw_data[1][1] = least_rectangle.center->at(0); raw_data[2][1] = least_rectangle.center->at(1); - for (int i = 0; i < 3; i++) { - raw_data[0][2+i] = left_eigv(i,smallest_comp); - raw_data[1][2+i] = least_rectangle.axisX->at(0)*left_eigv(i,smallest_comp==0?1:0) + - least_rectangle.axisX->at(1)*left_eigv(i,smallest_comp==2?1:2); - raw_data[2][2+i] = least_rectangle.axisY->at(0)*left_eigv(i,smallest_comp==0?1:0) + - least_rectangle.axisY->at(1)*left_eigv(i,smallest_comp==2?1:2); + for(int i = 0; i < 3; i++) { + raw_data[0][2 + i] = left_eigv(i, smallest_comp); + raw_data[1][2 + i] = + least_rectangle.axisX->at(0) * left_eigv(i, smallest_comp == 0 ? 1 : 0) + + least_rectangle.axisX->at(1) * left_eigv(i, smallest_comp == 2 ? 1 : 2); + raw_data[2][2 + i] = + least_rectangle.axisY->at(0) * left_eigv(i, smallest_comp == 0 ? 1 : 0) + + least_rectangle.axisY->at(1) * left_eigv(i, smallest_comp == 2 ? 1 : 2); } - // Msg::Info("Test 1 : %f %f",least_rectangle.center->at(0),least_rectangle.center->at(1)); - // Msg::Info("Test 2 : %f %f",least_rectangle.axisY->at(0),least_rectangle.axisY->at(1)); + // Msg::Info("Test 1 : %f + // %f",least_rectangle.center->at(0),least_rectangle.center->at(1)); + // Msg::Info("Test 2 : %f + // %f",least_rectangle.axisY->at(0),least_rectangle.axisY->at(1)); int tri[3]; - if (size_pca > least_rectangle.size->at(0)) { // P > R0 - if (size_pca > least_rectangle.size->at(1)) { // P > R1 + if(size_pca > least_rectangle.size->at(0)) { // P > R0 + if(size_pca > least_rectangle.size->at(1)) { // P > R1 tri[0] = 0; - if (least_rectangle.size->at(0) > least_rectangle.size->at(1)) { // R0 > R1 + if(least_rectangle.size->at(0) > least_rectangle.size->at(1)) { // R0 > R1 tri[1] = 1; tri[2] = 2; - } else { // R1 > R0 + } + else { // R1 > R0 tri[1] = 2; tri[2] = 1; } - } else { // P < R1 + } + else { // P < R1 tri[0] = 2; tri[1] = 0; tri[2] = 1; } - } else { // P < R0 - if (size_pca < least_rectangle.size->at(1)) { // P < R1 + } + else { // P < R0 + if(size_pca < least_rectangle.size->at(1)) { // P < R1 tri[2] = 0; - if (least_rectangle.size->at(0) > least_rectangle.size->at(1)) { + if(least_rectangle.size->at(0) > least_rectangle.size->at(1)) { tri[0] = 1; tri[1] = 2; - } else { + } + else { tri[0] = 2; tri[1] = 1; } - } else { + } + else { tri[0] = 1; tri[1] = 0; tri[2] = 2; @@ -521,25 +539,25 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& verti SVector3 Axis2; SVector3 Axis3; - for (int i = 0; i < 3; i++) { + for(int i = 0; i < 3; i++) { size[i] = raw_data[tri[i]][0]; center[i] = raw_data[tri[i]][1]; - Axis1[i] = raw_data[tri[0]][2+i]; - Axis2[i] = raw_data[tri[1]][2+i]; - Axis3[i] = raw_data[tri[2]][2+i]; + Axis1[i] = raw_data[tri[0]][2 + i]; + Axis2[i] = raw_data[tri[1]][2 + i]; + Axis3[i] = raw_data[tri[2]][2 + i]; } SVector3 aux1; SVector3 aux2; SVector3 aux3; - for (int i = 0; i < 3; i++) { - aux1(i) = left_eigv(i,smallest_comp); - aux2(i) = left_eigv(i,smallest_comp==0?1:0); - aux3(i) = left_eigv(i,smallest_comp==2?1:2); + for(int i = 0; i < 3; i++) { + aux1(i) = left_eigv(i, smallest_comp); + aux2(i) = left_eigv(i, smallest_comp == 0 ? 1 : 0); + aux3(i) = left_eigv(i, smallest_comp == 2 ? 1 : 2); } - center = aux1*center_pca + aux2*least_rectangle.center->at(0) + - aux3*least_rectangle.center->at(1); - //center[1] = -center[1]; + center = aux1 * center_pca + aux2 * least_rectangle.center->at(0) + + aux3 * least_rectangle.center->at(1); + // center[1] = -center[1]; /* Msg::Info("Box center : %f %f %f",center[0],center[1],center[2]); @@ -551,33 +569,33 @@ SOrientedBoundingBox* SOrientedBoundingBox::buildOBB(std::vector<SPoint3>& verti Msg::Info("Volume : %f", size[0]*size[1]*size[2]); */ - return (new SOrientedBoundingBox(center, - size[0], size[1], size[2], Axis1, Axis2, Axis3)); + return (new SOrientedBoundingBox(center, size[0], size[1], size[2], Axis1, + Axis2, Axis3)); #else Msg::Error("SOrientedBoundingBox requires mesh module"); return 0; #endif } -double SOrientedBoundingBox::compare(SOrientedBoundingBox& obb1, - SOrientedBoundingBox& obb2) +double SOrientedBoundingBox::compare(SOrientedBoundingBox &obb1, + SOrientedBoundingBox &obb2) { // "center term" double center_term = norm(obb1.getCenter() - obb2.getCenter()); // "size term" double size_term = 0.0; - for (int i = 0; i < 3; i++) { - if ((obb1.getSize())(i) + (obb2.getSize())(i) != 0) { + for(int i = 0; i < 3; i++) { + if((obb1.getSize())(i) + (obb2.getSize())(i) != 0) { size_term += fabs((obb1.getSize())(i) - (obb2.getSize())(i)) / - ((obb1.getSize())(i) + (obb2.getSize())(i)); + ((obb1.getSize())(i) + (obb2.getSize())(i)); } } // "orientation term" double orientation_term = 0.0; - for (int i = 0; i < 3; i++) { - orientation_term += 1 - fabs(dot(obb1.getAxis(i),obb2.getAxis(i))); + for(int i = 0; i < 3; i++) { + orientation_term += 1 - fabs(dot(obb1.getAxis(i), obb2.getAxis(i))); } return (center_term + size_term + orientation_term); diff --git a/Geo/SOrientedBoundingBox.h b/Geo/SOrientedBoundingBox.h index d5c950b53a5e264806ecb1f11940b37f1cc06497..bf273f432c2b174ba5a7f91c1aa45c313663f7b6 100644 --- a/Geo/SOrientedBoundingBox.h +++ b/Geo/SOrientedBoundingBox.h @@ -17,7 +17,7 @@ #include "Pair.h" class SOrientedBoundingRectangle { - public: +public: std::vector<double> *center; std::vector<double> *size; std::vector<double> *axisX; @@ -28,7 +28,7 @@ class SOrientedBoundingRectangle { }; class SOrientedBoundingBox { - private: +private: SVector3 center; SVector3 size; SVector3 axisX; @@ -36,7 +36,7 @@ class SOrientedBoundingBox { SVector3 axisZ; void fillp(); - public: +public: double p1x, p1y, p1z; double p2x, p2y, p2z; double p3x, p3y, p3z; @@ -51,26 +51,26 @@ class SOrientedBoundingBox { // axis system of the box. The axis form the local coordinates // system of the box. All these data are given in the local // coordinates system of the object. - SOrientedBoundingBox(SVector3& center, double sizeX, double sizeY, + SOrientedBoundingBox(SVector3 ¢er, double sizeX, double sizeY, double sizeZ, const SVector3 &axisX, const SVector3 &axisY, const SVector3 &axisZ); - SOrientedBoundingBox(SOrientedBoundingBox* other); - ~SOrientedBoundingBox(){} + SOrientedBoundingBox(SOrientedBoundingBox *other); + ~SOrientedBoundingBox() {} - SVector3 getCenter(){ return center; } - const SVector3 &getCenter() const{ return center; } - double getCenterX(){ return center[0]; } - double getCenterY(){ return center[1]; } - double getCenterZ(){ return center[2]; } - SVector3 getSize(){ return size; } + SVector3 getCenter() { return center; } + const SVector3 &getCenter() const { return center; } + double getCenterX() { return center[0]; } + double getCenterY() { return center[1]; } + double getCenterZ() { return center[2]; } + SVector3 getSize() { return size; } double getMaxSize(); double getMinSize(); // valid values for axis are 0 (X-axis), 1 (Y-axis) or 2 (Z-axis) SVector3 getAxis(int axis); - static SOrientedBoundingBox* buildOBB(std::vector<SPoint3>& vertices); + static SOrientedBoundingBox *buildOBB(std::vector<SPoint3> &vertices); bool intersects(SOrientedBoundingBox &obb); diff --git a/Geo/SPoint2.h b/Geo/SPoint2.h index c989bdf8da32e9d878a5cc4193c850c1126f8e2c..b79215fe94d3f4ce4d84d8ecc4690e2890acff2f 100644 --- a/Geo/SPoint2.h +++ b/Geo/SPoint2.h @@ -10,12 +10,25 @@ // A point in 2-space class SPoint2 { - protected: +protected: double P[2]; - public: - SPoint2(double x=0.0, double y=0.0) { P[0] = x; P[1] = y; } - SPoint2(double *p) { P[0] = p[0]; P[1] = p[1]; } - SPoint2(const SPoint2 &pt) { P[0] = pt.P[0]; P[1] = pt.P[1]; } + +public: + SPoint2(double x = 0.0, double y = 0.0) + { + P[0] = x; + P[1] = y; + } + SPoint2(double *p) + { + P[0] = p[0]; + P[1] = p[1]; + } + SPoint2(const SPoint2 &pt) + { + P[0] = pt.P[0]; + P[1] = pt.P[1]; + } virtual ~SPoint2() {} void setPosition(double xx, double yy); void getPosition(double *xx, double *yy) const; @@ -24,14 +37,14 @@ class SPoint2 { inline double y(void) const; double &operator[](int); double operator[](int) const; - double distance(const SPoint2 &p)const; + double distance(const SPoint2 &p) const; SPoint2 &operator=(const SPoint2 &p); void operator+=(const SPoint2 &p); void operator-=(const SPoint2 &p); void operator*=(double mult); - SPoint2 operator*(double mult)const; + SPoint2 operator*(double mult) const; operator double *() { return P; } - bool operator < (const SPoint2 &other) const + bool operator<(const SPoint2 &other) const { if(other.P[0] < P[0]) return true; if(other.P[0] > P[0]) return false; @@ -40,49 +53,73 @@ class SPoint2 { } }; -inline SPoint2 operator + (const SPoint2 &a, const SPoint2 &b) -{ return SPoint2(a.x()+b.x(),a.y()+b.y()); } +inline SPoint2 operator+(const SPoint2 &a, const SPoint2 &b) +{ + return SPoint2(a.x() + b.x(), a.y() + b.y()); +} -inline SPoint2 operator - (const SPoint2 &a, const SPoint2 &b) -{ return SPoint2(a.x()-b.x(),a.y()-b.y()); } +inline SPoint2 operator-(const SPoint2 &a, const SPoint2 &b) +{ + return SPoint2(a.x() - b.x(), a.y() - b.y()); +} inline void SPoint2::setPosition(double xx, double yy) -{ P[0] = xx; P[1] = yy; } +{ + P[0] = xx; + P[1] = yy; +} inline void SPoint2::getPosition(double *xx, double *yy) const -{ *xx = P[0]; *yy = P[1]; } +{ + *xx = P[0]; + *yy = P[1]; +} inline void SPoint2::position(double *p) const -{ p[0] = P[0]; p[1] = P[1]; } +{ + p[0] = P[0]; + p[1] = P[1]; +} -inline double SPoint2::x(void) const -{ return P[0]; } +inline double SPoint2::x(void) const { return P[0]; } -inline double SPoint2::y(void) const -{ return P[1]; } +inline double SPoint2::y(void) const { return P[1]; } -inline SPoint2 & SPoint2::operator=(const SPoint2 &p) -{ P[0] = p.P[0]; P[1]=p.P[1]; return *this; } +inline SPoint2 &SPoint2::operator=(const SPoint2 &p) +{ + P[0] = p.P[0]; + P[1] = p.P[1]; + return *this; +} -inline double &SPoint2::operator[](int i) -{ return P[i]; } +inline double &SPoint2::operator[](int i) { return P[i]; } -inline double SPoint2::operator[](int i) const -{ return P[i]; } +inline double SPoint2::operator[](int i) const { return P[i]; } inline void SPoint2::operator+=(const SPoint2 &p) -{ P[0] += p.P[0]; P[1] += p.P[1];} +{ + P[0] += p.P[0]; + P[1] += p.P[1]; +} inline void SPoint2::operator-=(const SPoint2 &p) -{ P[0] -= p.P[0]; P[1] -= p.P[1];} +{ + P[0] -= p.P[0]; + P[1] -= p.P[1]; +} inline void SPoint2::operator*=(double mult) -{ P[0] *= mult; P[1] *= mult; } +{ + P[0] *= mult; + P[1] *= mult; +} -inline SPoint2 SPoint2::operator*(double mult)const -{ return SPoint2(P[0]*mult, P[1]*mult); } +inline SPoint2 SPoint2::operator*(double mult) const +{ + return SPoint2(P[0] * mult, P[1] * mult); +} -inline double SPoint2::distance(const SPoint2 &p)const +inline double SPoint2::distance(const SPoint2 &p) const { double x = P[0] - p.P[0], y = P[1] - p.P[1]; return std::sqrt(x * x + y * y); diff --git a/Geo/SPoint3.h b/Geo/SPoint3.h index f31f4cb1ec5055a2f4fed5a372b79378feb726cd..62cd981da56a4047d073c209e5ea48cb25ebc2d2 100644 --- a/Geo/SPoint3.h +++ b/Geo/SPoint3.h @@ -9,20 +9,41 @@ #include <cmath> // A point in 3-space class SPoint3 { - protected: +protected: double P[3]; - public: + +public: SPoint3() { P[0] = P[1] = P[2] = 0.; } - SPoint3(double x, double y, double z) { P[0] = x; P[1] = y; P[2] = z; } - SPoint3(const double *p) { P[0] = p[0]; P[1] = p[1]; P[2] = p[2]; } - SPoint3(const SPoint3 &pt) { P[0] = pt.P[0]; P[1] = pt.P[1]; P[2] = pt.P[2]; } + SPoint3(double x, double y, double z) + { + P[0] = x; + P[1] = y; + P[2] = z; + } + SPoint3(const double *p) + { + P[0] = p[0]; + P[1] = p[1]; + P[2] = p[2]; + } + SPoint3(const SPoint3 &pt) + { + P[0] = pt.P[0]; + P[1] = pt.P[1]; + P[2] = pt.P[2]; + } virtual ~SPoint3() {} void setPosition(double xx, double yy, double zz); - void setPosition(const SPoint3 &pt,const SPoint3 &dir,const double dist_) + void setPosition(const SPoint3 &pt, const SPoint3 &dir, const double dist_) { - P[0]=pt.P[0]; P[1]=pt.P[1]; P[2]=pt.P[2]; - SPoint3 a(dir); a*=dist_; - P[0]+=a[0]; P[1]+=a[1]; P[2]+=a[2]; + P[0] = pt.P[0]; + P[1] = pt.P[1]; + P[2] = pt.P[2]; + SPoint3 a(dir); + a *= dist_; + P[0] += a[0]; + P[1] += a[1]; + P[2] += a[2]; } void getPosition(double *xx, double *yy, double *zz) const; void position(double *) const; @@ -38,70 +59,104 @@ class SPoint3 { void operator/=(double mult); SPoint3 operator*(double mult); operator double *() { return P; } - double distance(const SPoint3 &p)const; + double distance(const SPoint3 &p) const; // lexicographic - bool operator < (const SPoint3 &p) const + bool operator<(const SPoint3 &p) const { - if (P[0] < p.P[0]) return true; - if (P[0] > p.P[0]) return false; - if (P[1] < p.P[1]) return true; - if (P[1] > p.P[1]) return false; - if (P[2] < p.P[2]) return true; + if(P[0] < p.P[0]) return true; + if(P[0] > p.P[0]) return false; + if(P[1] < p.P[1]) return true; + if(P[1] > p.P[1]) return false; + if(P[2] < p.P[2]) return true; return false; } - const double* data() const{return P;} - double* data() {return P;} + const double *data() const { return P; } + double *data() { return P; } }; -inline SPoint3 operator + (const SPoint3 &a, const SPoint3 &b) -{ return SPoint3(a.x() + b.x(), a.y() + b.y(), a.z() + b.z()); } +inline SPoint3 operator+(const SPoint3 &a, const SPoint3 &b) +{ + return SPoint3(a.x() + b.x(), a.y() + b.y(), a.z() + b.z()); +} -inline SPoint3 operator - (const SPoint3 &a, const SPoint3 &b) -{ return SPoint3(a.x() - b.x(), a.y() - b.y(), a.z() - b.z()); } +inline SPoint3 operator-(const SPoint3 &a, const SPoint3 &b) +{ + return SPoint3(a.x() - b.x(), a.y() - b.y(), a.z() - b.z()); +} inline void SPoint3::setPosition(double xx, double yy, double zz) -{ P[0] = xx; P[1] = yy; P[2] = zz; } +{ + P[0] = xx; + P[1] = yy; + P[2] = zz; +} inline void SPoint3::getPosition(double *xx, double *yy, double *zz) const -{ *xx = P[0]; *yy = P[1]; *zz = P[2]; } +{ + *xx = P[0]; + *yy = P[1]; + *zz = P[2]; +} inline void SPoint3::position(double *p) const -{ p[0] = P[0]; p[1] = P[1]; p[2] = P[2]; } +{ + p[0] = P[0]; + p[1] = P[1]; + p[2] = P[2]; +} -inline double SPoint3::x(void) const -{ return P[0]; } +inline double SPoint3::x(void) const { return P[0]; } -inline double SPoint3::y(void) const -{ return P[1]; } +inline double SPoint3::y(void) const { return P[1]; } -inline double SPoint3::z(void) const -{ return P[2]; } +inline double SPoint3::z(void) const { return P[2]; } -inline SPoint3 & SPoint3::operator=(const SPoint3 &p) -{ P[0] = p.P[0]; P[1] = p.P[1]; P[2] = p.P[2]; return *this; } +inline SPoint3 &SPoint3::operator=(const SPoint3 &p) +{ + P[0] = p.P[0]; + P[1] = p.P[1]; + P[2] = p.P[2]; + return *this; +} inline void SPoint3::operator+=(const SPoint3 &p) -{ P[0] += p.P[0]; P[1] += p.P[1]; P[2] += p.P[2]; } +{ + P[0] += p.P[0]; + P[1] += p.P[1]; + P[2] += p.P[2]; +} inline void SPoint3::operator-=(const SPoint3 &p) -{ P[0] -= p.P[0]; P[1] -= p.P[1]; P[2] -= p.P[2]; } +{ + P[0] -= p.P[0]; + P[1] -= p.P[1]; + P[2] -= p.P[2]; +} inline void SPoint3::operator*=(double mult) -{ P[0] *= mult; P[1] *= mult; P[2] *= mult; } +{ + P[0] *= mult; + P[1] *= mult; + P[2] *= mult; +} inline void SPoint3::operator/=(double div) -{ P[0] /= div; P[1] /= div; P[2] /= div; } +{ + P[0] /= div; + P[1] /= div; + P[2] /= div; +} inline SPoint3 SPoint3::operator*(double mult) -{ return SPoint3(P[0] * mult, P[1] * mult, P[2] * mult); } +{ + return SPoint3(P[0] * mult, P[1] * mult, P[2] * mult); +} -inline double &SPoint3::operator[](int i) -{ return P[i]; } +inline double &SPoint3::operator[](int i) { return P[i]; } -inline double SPoint3::operator[](int i) const -{ return P[i]; } +inline double SPoint3::operator[](int i) const { return P[i]; } -inline double SPoint3::distance(const SPoint3 &p)const +inline double SPoint3::distance(const SPoint3 &p) const { double x = P[0] - p.P[0], y = P[1] - p.P[1], z = P[2] - p.P[2]; return std::sqrt(x * x + y * y + z * z); diff --git a/Geo/STensor3.cpp b/Geo/STensor3.cpp index c30aa0716d8292e1b7cd0cbdb831ead073c21abe..0a538a92df4d1395b917a8f2fc2722e03bd5cc82 100644 --- a/Geo/STensor3.cpp +++ b/Geo/STensor3.cpp @@ -8,183 +8,184 @@ // compute the largest inscribed ellipsoid -void SMetric3::print (const char *s) const +void SMetric3::print(const char *s) const { printf(" metric %s : %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E \n", s, - (*this)(0,0), (*this)(1,1), (*this)(2,2), - (*this)(0,1), (*this)(0,2), (*this)(1,2)); + (*this)(0, 0), (*this)(1, 1), (*this)(2, 2), (*this)(0, 1), + (*this)(0, 2), (*this)(1, 2)); } -void STensor3::print (const char *s) const +void STensor3::print(const char *s) const { - printf(" tensor %s : \n" - " %12.5E %12.5E %12.5E \n %12.5E %12.5E %12.5E \n %12.5E %12.5E %12.5E \n", s, - (*this)(0,0), (*this)(0,1), (*this)(0,2), - (*this)(1,0), (*this)(1,1), (*this)(1,2), - (*this)(2,0), (*this)(2,1), (*this)(2,2)); + printf( + " tensor %s : \n" + " %12.5E %12.5E %12.5E \n %12.5E %12.5E %12.5E \n %12.5E %12.5E %12.5E \n", + s, (*this)(0, 0), (*this)(0, 1), (*this)(0, 2), (*this)(1, 0), + (*this)(1, 1), (*this)(1, 2), (*this)(2, 0), (*this)(2, 1), (*this)(2, 2)); } -SMetric3 intersection (const SMetric3 &m1, const SMetric3 &m2) +SMetric3 intersection(const SMetric3 &m1, const SMetric3 &m2) { SMetric3 im1 = m1.invert(); - fullMatrix<double> V(3,3); + fullMatrix<double> V(3, 3); fullVector<double> S(3); im1 *= m2; - im1.eig(V,S,true); - SVector3 v0(V(0,0),V(1,0),V(2,0)); - SVector3 v1(V(0,1),V(1,1),V(2,1)); - SVector3 v2(V(0,2),V(1,2),V(2,2)); - double l0 = std::max(dot(v0,m1,v0),dot(v0,m2,v0)); - double l1 = std::max(dot(v1,m1,v1),dot(v1,m2,v1)); - double l2 = std::max(dot(v2,m1,v2),dot(v2,m2,v2)); + im1.eig(V, S, true); + SVector3 v0(V(0, 0), V(1, 0), V(2, 0)); + SVector3 v1(V(0, 1), V(1, 1), V(2, 1)); + SVector3 v2(V(0, 2), V(1, 2), V(2, 2)); + double l0 = std::max(dot(v0, m1, v0), dot(v0, m2, v0)); + double l1 = std::max(dot(v1, m1, v1), dot(v1, m2, v1)); + double l2 = std::max(dot(v2, m1, v2), dot(v2, m2, v2)); // Correction from the PhD thesis of Frederic Alauzet p.16 // If m2 = alpha*m1, then take the largest metric - static const double eps = 1.e-2; // Tolerance to detect triple eigenvalue - // (i.e. proportional metrics) + static const double eps = 1.e-2; // Tolerance to detect triple eigenvalue + // (i.e. proportional metrics) const double max_eig = std::max(S(0), std::max(S(1), S(2))); const double min_eig = std::min(S(0), std::min(S(1), S(2))); - const double range_eig = fabs((max_eig-min_eig)/max_eig); - if (range_eig < eps) return (max_eig >= 1.) ? m2 : m1; + const double range_eig = fabs((max_eig - min_eig) / max_eig); + if(range_eig < eps) return (max_eig >= 1.) ? m2 : m1; - SMetric3 iv(l0,l1,l2,v0,v1,v2); + SMetric3 iv(l0, l1, l2, v0, v1, v2); return iv; } -SMetric3 intersection_alauzet (const SMetric3 &m1, const SMetric3 &m2) +SMetric3 intersection_alauzet(const SMetric3 &m1, const SMetric3 &m2) { SMetric3 im1 = m1.invert(); - fullMatrix<double> V(3,3); + fullMatrix<double> V(3, 3); fullVector<double> S(3); im1 *= m2; - im1.eig(V,S,true); - SVector3 v0(V(0,0),V(1,0),V(2,0)); - SVector3 v1(V(0,1),V(1,1),V(2,1)); - SVector3 v2(V(0,2),V(1,2),V(2,2)); + im1.eig(V, S, true); + SVector3 v0(V(0, 0), V(1, 0), V(2, 0)); + SVector3 v1(V(0, 1), V(1, 1), V(2, 1)); + SVector3 v2(V(0, 2), V(1, 2), V(2, 2)); // is this required?? v0.normalize(); v1.normalize(); v2.normalize(); - double l0 = std::max(dot(v0,m1,v0),dot(v0,m2,v0)); - double l1 = std::max(dot(v1,m1,v1),dot(v1,m2,v1)); - double l2 = std::max(dot(v2,m1,v2),dot(v2,m2,v2)); - SMetric3 iv(l0,l1,l2,v0,v1,v2); + double l0 = std::max(dot(v0, m1, v0), dot(v0, m2, v0)); + double l1 = std::max(dot(v1, m1, v1), dot(v1, m2, v1)); + double l2 = std::max(dot(v2, m1, v2), dot(v2, m2, v2)); + SMetric3 iv(l0, l1, l2, v0, v1, v2); return iv; } // preserve orientation of m1 !!! -SMetric3 intersection_conserveM1 (const SMetric3 &m1, const SMetric3 &m2) +SMetric3 intersection_conserveM1(const SMetric3 &m1, const SMetric3 &m2) { // we should do // return intersection (m1,m2); - fullMatrix<double> V(3,3); + fullMatrix<double> V(3, 3); fullVector<double> S(3); - m1.eig(V,S,true); - SVector3 v0(V(0,0),V(1,0),V(2,0)); - SVector3 v1(V(0,1),V(1,1),V(2,1)); - SVector3 v2(V(0,2),V(1,2),V(2,2)); - double l0 = std::max(dot(v0,m1,v0),dot(v0,m2,v0)); - double l1 = std::max(dot(v1,m1,v1),dot(v1,m2,v1)); - double l2 = std::max(dot(v2,m1,v2),dot(v2,m2,v2)); - SMetric3 iv(l0,l1,l2,v0,v1,v2); + m1.eig(V, S, true); + SVector3 v0(V(0, 0), V(1, 0), V(2, 0)); + SVector3 v1(V(0, 1), V(1, 1), V(2, 1)); + SVector3 v2(V(0, 2), V(1, 2), V(2, 2)); + double l0 = std::max(dot(v0, m1, v0), dot(v0, m2, v0)); + double l1 = std::max(dot(v1, m1, v1), dot(v1, m2, v1)); + double l2 = std::max(dot(v2, m1, v2), dot(v2, m2, v2)); + SMetric3 iv(l0, l1, l2, v0, v1, v2); return iv; } namespace { -double anisoRatio2D (double v0x, double v0y, double v0z, - double v1x, double v1y, double v1z, - double v2x, double v2y, double v2z, - double s0, double s1, double s2) { - - static const double eps = 1.e-8; - - double ratio; - if (v0x*v0x+v0y*v0y+(v0z-1.)*(v0z-1.) < eps) // If 1st eigenvect corresponds to z dir. ... - ratio = std::min(fabs(s1/s2),fabs(s2/s1)); // ... consider ratio of 2nd and 3rd eigenval. - else if (v1x*v1x+v1y*v1y+(v1z-1.)*(v1z-1.) < eps) // If 2nd eigenvect corresponds to z dir. ... - ratio = std::min(fabs(s0/s2),fabs(s2/s0)); // ... consider ratio of 1st and 3rd eigenval. - else if (v2x*v2x+v2y*v2y+(v2z-1.)*(v2z-1.) < eps) // If 3rd eigenvect corresponds to z dir. ... - ratio = std::min(fabs(s0/s1),fabs(s1/s0)); // ... consider ratio of 1st and 2nd eigenval. - else { - printf("Error in anisoRatio2D: z direction not found!\n"); - ratio = 0.; + double anisoRatio2D(double v0x, double v0y, double v0z, double v1x, + double v1y, double v1z, double v2x, double v2y, + double v2z, double s0, double s1, double s2) + { + static const double eps = 1.e-8; + + double ratio; + if(v0x * v0x + v0y * v0y + (v0z - 1.) * (v0z - 1.) < + eps) // If 1st eigenvect corresponds to z dir. ... + ratio = + std::min(fabs(s1 / s2), + fabs(s2 / s1)); // ... consider ratio of 2nd and 3rd eigenval. + else if(v1x * v1x + v1y * v1y + (v1z - 1.) * (v1z - 1.) < + eps) // If 2nd eigenvect corresponds to z dir. ... + ratio = + std::min(fabs(s0 / s2), + fabs(s2 / s0)); // ... consider ratio of 1st and 3rd eigenval. + else if(v2x * v2x + v2y * v2y + (v2z - 1.) * (v2z - 1.) < + eps) // If 3rd eigenvect corresponds to z dir. ... + ratio = + std::min(fabs(s0 / s1), + fabs(s1 / s0)); // ... consider ratio of 1st and 2nd eigenval. + else { + printf("Error in anisoRatio2D: z direction not found!\n"); + ratio = 0.; + } + + return ratio; } - return ratio; - -} - -} +} // namespace // preserve orientation of the most anisotropic metric !!! -SMetric3 intersection_conserve_mostaniso (const SMetric3 &m1, const SMetric3 &m2) +SMetric3 intersection_conserve_mostaniso(const SMetric3 &m1, const SMetric3 &m2) { - fullMatrix<double> V1(3,3); + fullMatrix<double> V1(3, 3); fullVector<double> S1(3); - m1.eig(V1,S1,true); - double ratio1 = fabs(S1(0)/S1(2)); // Minimum ratio because we take sorted eigenvalues - fullMatrix<double> V2(3,3); + m1.eig(V1, S1, true); + double ratio1 = + fabs(S1(0) / S1(2)); // Minimum ratio because we take sorted eigenvalues + fullMatrix<double> V2(3, 3); fullVector<double> S2(3); - m2.eig(V2,S2,true); - double ratio2 = fabs(S2(0)/S2(2)); // Minimum ratio because we take sorted eigenvalues + m2.eig(V2, S2, true); + double ratio2 = + fabs(S2(0) / S2(2)); // Minimum ratio because we take sorted eigenvalues - if (ratio1 < ratio2) + if(ratio1 < ratio2) return intersection_conserveM1(m1, m2); else return intersection_conserveM1(m2, m1); } // preserve orientation of the most anisotropic metric in 2D!!! -SMetric3 intersection_conserve_mostaniso_2d (const SMetric3 &m1, const SMetric3 &m2) +SMetric3 intersection_conserve_mostaniso_2d(const SMetric3 &m1, + const SMetric3 &m2) { - - fullMatrix<double> V1(3,3); + fullMatrix<double> V1(3, 3); fullVector<double> S1(3); - m1.eig(V1,S1,false); - double ratio1 = anisoRatio2D(V1(0,0),V1(1,0),V1(2,0), - V1(0,1),V1(1,1),V1(2,1), - V1(0,2),V1(1,2),V1(2,2), - S1(0),S1(1),S1(2)); + m1.eig(V1, S1, false); + double ratio1 = + anisoRatio2D(V1(0, 0), V1(1, 0), V1(2, 0), V1(0, 1), V1(1, 1), V1(2, 1), + V1(0, 2), V1(1, 2), V1(2, 2), S1(0), S1(1), S1(2)); - fullMatrix<double> V2(3,3); + fullMatrix<double> V2(3, 3); fullVector<double> S2(3); - m2.eig(V2,S2,false); - double ratio2 = anisoRatio2D(V2(0,0),V2(1,0),V2(2,0), - V2(0,1),V2(1,1),V2(2,1), - V2(0,2),V2(1,2),V2(2,2), - S2(0),S2(1),S2(2)); + m2.eig(V2, S2, false); + double ratio2 = + anisoRatio2D(V2(0, 0), V2(1, 0), V2(2, 0), V2(0, 1), V2(1, 1), V2(2, 1), + V2(0, 2), V2(1, 2), V2(2, 2), S2(0), S2(1), S2(2)); - if (ratio1 < ratio2) + if(ratio1 < ratio2) return intersection_conserveM1(m1, m2); else return intersection_conserveM1(m2, m1); - } // (1-t) * m1 + t * m2 -SMetric3 interpolation (const SMetric3 &m1, - const SMetric3 &m2, - const double t) +SMetric3 interpolation(const SMetric3 &m1, const SMetric3 &m2, const double t) { SMetric3 im1 = m1.invert(); SMetric3 im2 = m2.invert(); - im1 *= (1.-t); + im1 *= (1. - t); im2 *= t; im1 += im2; return im1.invert(); } -SMetric3 interpolation (const SMetric3 &m1, - const SMetric3 &m2, - const SMetric3 &m3, - const double u, - const double v) +SMetric3 interpolation(const SMetric3 &m1, const SMetric3 &m2, + const SMetric3 &m3, const double u, const double v) { SMetric3 im1 = m1.invert(); SMetric3 im2 = m2.invert(); SMetric3 im3 = m3.invert(); - im1 *= (1.-u-v); + im1 *= (1. - u - v); im2 *= u; im3 *= v; im1 += im2; @@ -192,19 +193,15 @@ SMetric3 interpolation (const SMetric3 &m1, return im1.invert(); } -SMetric3 interpolation (const SMetric3 &m1, - const SMetric3 &m2, - const SMetric3 &m3, - const SMetric3 &m4, - const double u, - const double v, - const double w) +SMetric3 interpolation(const SMetric3 &m1, const SMetric3 &m2, + const SMetric3 &m3, const SMetric3 &m4, const double u, + const double v, const double w) { SMetric3 im1 = m1.invert(); SMetric3 im2 = m2.invert(); SMetric3 im3 = m3.invert(); SMetric3 im4 = m4.invert(); - im1 *= (1.-u-v-w); + im1 *= (1. - u - v - w); im2 *= u; im3 *= v; im4 *= w; diff --git a/Geo/STensor3.h b/Geo/STensor3.h index eae49bd5a830521a5847dd90ad14cd3d4635fd12..11f2c94109b338a76b3dd2a182f14e2f5adc7602 100644 --- a/Geo/STensor3.h +++ b/Geo/STensor3.h @@ -12,33 +12,33 @@ // concrete class for symmetric positive definite 3x3 matrix class SMetric3 { - protected: +protected: // lower diagonal storage // 00 10 11 20 21 22 double _val[6]; - public: + +public: inline int getIndex(int i, int j) const { - static int _index[3][3] = {{0,1,3},{1,2,4},{3,4,5}}; + static int _index[3][3] = {{0, 1, 3}, {1, 2, 4}, {3, 4, 5}}; return _index[i][j]; } void getMat(fullMatrix<double> &mat) const { - for (int i = 0; i < 3; i++){ - for (int j = 0; j < 3; j++){ - mat(i,j) = _val[getIndex(i, j)]; + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + mat(i, j) = _val[getIndex(i, j)]; } } } - void setMat(const fullMatrix<double> & mat) + void setMat(const fullMatrix<double> &mat) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - _val[getIndex(i, j)] = mat(i, j); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) _val[getIndex(i, j)] = mat(i, j); } - SMetric3(const SMetric3& m) + SMetric3(const SMetric3 &m) { - for (int i = 0; i < 6; i++) _val[i] = m._val[i]; + for(int i = 0; i < 6; i++) _val[i] = m._val[i]; } // default constructor, identity SMetric3(const double v = 1.0) @@ -47,51 +47,47 @@ class SMetric3 { _val[1] = _val[3] = _val[4] = 0.0; } SMetric3(const double l1, // l1 = h1^-2 - const double l2, - const double l3, - const SVector3 &t1, - const SVector3 &t2, - const SVector3 &t3) + const double l2, const double l3, const SVector3 &t1, + const SVector3 &t2, const SVector3 &t3) { // M = e^t * diag * e // where the elements of diag are l_i = h_i^-2 // and the rows of e are the UNIT and ORTHOGONAL directions - fullMatrix<double> e(3,3); - e(0,0) = t1(0); e(0,1) = t1(1); e(0,2) = t1(2); - e(1,0) = t2(0); e(1,1) = t2(1); e(1,2) = t2(2); - e(2,0) = t3(0); e(2,1) = t3(1); e(2,2) = t3(2); + fullMatrix<double> e(3, 3); + e(0, 0) = t1(0); + e(0, 1) = t1(1); + e(0, 2) = t1(2); + e(1, 0) = t2(0); + e(1, 1) = t2(1); + e(1, 2) = t2(2); + e(2, 0) = t3(0); + e(2, 1) = t3(1); + e(2, 2) = t3(2); e.transposeInPlace(); - fullMatrix<double> tmp(3,3); - tmp(0,0) = l1 * e(0,0); - tmp(0,1) = l2 * e(0,1); - tmp(0,2) = l3 * e(0,2); - tmp(1,0) = l1 * e(1,0); - tmp(1,1) = l2 * e(1,1); - tmp(1,2) = l3 * e(1,2); - tmp(2,0) = l1 * e(2,0); - tmp(2,1) = l2 * e(2,1); - tmp(2,2) = l3 * e(2,2); + fullMatrix<double> tmp(3, 3); + tmp(0, 0) = l1 * e(0, 0); + tmp(0, 1) = l2 * e(0, 1); + tmp(0, 2) = l3 * e(0, 2); + tmp(1, 0) = l1 * e(1, 0); + tmp(1, 1) = l2 * e(1, 1); + tmp(1, 2) = l3 * e(1, 2); + tmp(2, 0) = l1 * e(2, 0); + tmp(2, 1) = l2 * e(2, 1); + tmp(2, 2) = l3 * e(2, 2); e.transposeInPlace(); - _val[0] = tmp(0,0) * e(0,0) + tmp(0,1) * e(1,0) + tmp(0,2) * e(2,0); - _val[1] = tmp(1,0) * e(0,0) + tmp(1,1) * e(1,0) + tmp(1,2) * e(2,0); - _val[2] = tmp(1,0) * e(0,1) + tmp(1,1) * e(1,1) + tmp(1,2) * e(2,1); - _val[3] = tmp(2,0) * e(0,0) + tmp(2,1) * e(1,0) + tmp(2,2) * e(2,0); - _val[4] = tmp(2,0) * e(0,1) + tmp(2,1) * e(1,1) + tmp(2,2) * e(2,1); - _val[5] = tmp(2,0) * e(0,2) + tmp(2,1) * e(1,2) + tmp(2,2) * e(2,2); - - } - inline double &operator()(int i, int j) - { - return _val[getIndex(i, j)]; - } - inline double operator()(int i, int j) const - { - return _val[getIndex(i, j)]; - } + _val[0] = tmp(0, 0) * e(0, 0) + tmp(0, 1) * e(1, 0) + tmp(0, 2) * e(2, 0); + _val[1] = tmp(1, 0) * e(0, 0) + tmp(1, 1) * e(1, 0) + tmp(1, 2) * e(2, 0); + _val[2] = tmp(1, 0) * e(0, 1) + tmp(1, 1) * e(1, 1) + tmp(1, 2) * e(2, 1); + _val[3] = tmp(2, 0) * e(0, 0) + tmp(2, 1) * e(1, 0) + tmp(2, 2) * e(2, 0); + _val[4] = tmp(2, 0) * e(0, 1) + tmp(2, 1) * e(1, 1) + tmp(2, 2) * e(2, 1); + _val[5] = tmp(2, 0) * e(0, 2) + tmp(2, 1) * e(1, 2) + tmp(2, 2) * e(2, 2); + } + inline double &operator()(int i, int j) { return _val[getIndex(i, j)]; } + inline double operator()(int i, int j) const { return _val[getIndex(i, j)]; } SMetric3 invert() const { fullMatrix<double> m(3, 3); @@ -103,28 +99,28 @@ class SMetric3 { } double determinant() const { - fullMatrix<double> m(3,3); + fullMatrix<double> m(3, 3); getMat(m); double det = m.determinant(); return det; } - SMetric3 operator + (const SMetric3 &other) const + SMetric3 operator+(const SMetric3 &other) const { SMetric3 res(*this); - for (int i = 0; i < 6; i++) res._val[i] += other._val[i]; + for(int i = 0; i < 6; i++) res._val[i] += other._val[i]; return res; } - SMetric3& operator += (const SMetric3 &other) + SMetric3 &operator+=(const SMetric3 &other) { - for (int i = 0; i < 6; i++) _val[i] += other._val[i]; + for(int i = 0; i < 6; i++) _val[i] += other._val[i]; return *this; } - SMetric3& operator *= (const double &other) + SMetric3 &operator*=(const double &other) { - for (int i = 0; i < 6; i++) _val[i] *= other; + for(int i = 0; i < 6; i++) _val[i] *= other; return *this; } - SMetric3& operator *= (const SMetric3 &other) + SMetric3 &operator*=(const SMetric3 &other) { fullMatrix<double> m1(3, 3), m2(3, 3), m3(3, 3); getMat(m1); @@ -135,16 +131,17 @@ class SMetric3 { } SMetric3 transform(fullMatrix<double> &V) { - fullMatrix<double> m(3,3); + fullMatrix<double> m(3, 3); getMat(m); - fullMatrix<double> result(3,3),temp(3,3); - V.transpose().mult(m,temp); - temp.mult(V,result); - SMetric3 a; a.setMat(result); + fullMatrix<double> result(3, 3), temp(3, 3); + V.transpose().mult(m, temp); + temp.mult(V, result); + SMetric3 a; + a.setMat(result); return a; } // s: true if eigenvalues are sorted (from min to max of the REAL part) - void eig(fullMatrix<double> &V, fullVector<double> &S, bool s=false) const + void eig(fullMatrix<double> &V, fullVector<double> &S, bool s = false) const { fullMatrix<double> me(3, 3), right(3, 3); fullVector<double> im(3); @@ -157,88 +154,77 @@ class SMetric3 { // scalar product with respect to the metric inline double dot(const SVector3 &a, const SMetric3 &m, const SVector3 &b) { - return - b.x() * ( m(0,0) * a.x() + m(1,0) * a.y() + m(2,0) * a.z() ) + - b.y() * ( m(0,1) * a.x() + m(1,1) * a.y() + m(2,1) * a.z() ) + - b.z() * ( m(0,2) * a.x() + m(1,2) * a.y() + m(2,2) * a.z() ) ; + return b.x() * (m(0, 0) * a.x() + m(1, 0) * a.y() + m(2, 0) * a.z()) + + b.y() * (m(0, 1) * a.x() + m(1, 1) * a.y() + m(2, 1) * a.z()) + + b.z() * (m(0, 2) * a.x() + m(1, 2) * a.y() + m(2, 2) * a.z()); } // preserve orientation of m1 -SMetric3 intersection_conserveM1 (const SMetric3 &m1, - const SMetric3 &m2); +SMetric3 intersection_conserveM1(const SMetric3 &m1, const SMetric3 &m2); // preserve orientation of the most anisotropic metric -SMetric3 intersection_conserve_mostaniso (const SMetric3 &m1, const SMetric3 &m2); -SMetric3 intersection_conserve_mostaniso_2d (const SMetric3 &m1, const SMetric3 &m2); +SMetric3 intersection_conserve_mostaniso(const SMetric3 &m1, + const SMetric3 &m2); +SMetric3 intersection_conserve_mostaniso_2d(const SMetric3 &m1, + const SMetric3 &m2); // compute the largest inscribed ellipsoid... -SMetric3 intersection (const SMetric3 &m1, - const SMetric3 &m2); -SMetric3 intersection_alauzet (const SMetric3 &m1, - const SMetric3 &m2); -SMetric3 interpolation (const SMetric3 &m1, - const SMetric3 &m2, - const double t); -SMetric3 interpolation (const SMetric3 &m1, - const SMetric3 &m2, - const SMetric3 &m3, - const double u, - const double v); -SMetric3 interpolation (const SMetric3 &m1, - const SMetric3 &m2, - const SMetric3 &m3, - const SMetric3 &m4, - const double u, - const double v, - const double w); +SMetric3 intersection(const SMetric3 &m1, const SMetric3 &m2); +SMetric3 intersection_alauzet(const SMetric3 &m1, const SMetric3 &m2); +SMetric3 interpolation(const SMetric3 &m1, const SMetric3 &m2, const double t); +SMetric3 interpolation(const SMetric3 &m1, const SMetric3 &m2, + const SMetric3 &m3, const double u, const double v); +SMetric3 interpolation(const SMetric3 &m1, const SMetric3 &m2, + const SMetric3 &m3, const SMetric3 &m4, const double u, + const double v, const double w); // concrete class for general 3x3 matrix class STensor3 { - protected: +protected: // 00 01 02 10 11 12 20 21 22 double _val[9]; - public: + +public: inline int getIndex(int i, int j) const { - static int _index[3][3] = {{0,1,2},{3,4,5},{6,7,8}}; + static int _index[3][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}; return _index[i][j]; } - inline void set_m11(double x){ _val[0] = x; } - inline void set_m21(double x){ _val[3] = x; } - inline void set_m31(double x){ _val[6] = x; } - inline void set_m12(double x){ _val[1] = x; } - inline void set_m22(double x){ _val[4] = x; } - inline void set_m32(double x){ _val[7] = x; } - inline void set_m13(double x){ _val[2] = x; } - inline void set_m23(double x){ _val[5] = x; } - inline void set_m33(double x){ _val[8] = x; } - inline double get_m11(){ return _val[0]; } - inline double get_m21(){ return _val[3]; } - inline double get_m31(){ return _val[6]; } - inline double get_m12(){ return _val[1]; } - inline double get_m22(){ return _val[4]; } - inline double get_m32(){ return _val[7]; } - inline double get_m13(){ return _val[2]; } - inline double get_m23(){ return _val[5]; } - inline double get_m33(){ return _val[8]; } - inline const double* data() const {return _val;} - inline double* data() {return _val;} + inline void set_m11(double x) { _val[0] = x; } + inline void set_m21(double x) { _val[3] = x; } + inline void set_m31(double x) { _val[6] = x; } + inline void set_m12(double x) { _val[1] = x; } + inline void set_m22(double x) { _val[4] = x; } + inline void set_m32(double x) { _val[7] = x; } + inline void set_m13(double x) { _val[2] = x; } + inline void set_m23(double x) { _val[5] = x; } + inline void set_m33(double x) { _val[8] = x; } + inline double get_m11() { return _val[0]; } + inline double get_m21() { return _val[3]; } + inline double get_m31() { return _val[6]; } + inline double get_m12() { return _val[1]; } + inline double get_m22() { return _val[4]; } + inline double get_m32() { return _val[7]; } + inline double get_m13() { return _val[2]; } + inline double get_m23() { return _val[5]; } + inline double get_m33() { return _val[8]; } + inline const double *data() const { return _val; } + inline double *data() { return _val; } void getMat(fullMatrix<double> &mat) const { - for (int i = 0; i < 3; i++){ - for (int j = 0; j < 3; j++){ - mat(i,j) = _val[getIndex(i, j)]; + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + mat(i, j) = _val[getIndex(i, j)]; } } } - void setMat (const fullMatrix<double> & mat) + void setMat(const fullMatrix<double> &mat) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - _val[getIndex(i, j)] = mat(i, j); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) _val[getIndex(i, j)] = mat(i, j); } - STensor3(const STensor3& other) + STensor3(const STensor3 &other) { - for (int i = 0; i < 9; i++) _val[i] = other._val[i]; + for(int i = 0; i < 9; i++) _val[i] = other._val[i]; } // default constructor, null tensor STensor3(const double v = 0.0) @@ -247,153 +233,154 @@ class STensor3 { _val[1] = _val[2] = _val[3] = 0.0; _val[5] = _val[6] = _val[7] = 0.0; } - inline double &operator()(int i, int j) - { - return _val[getIndex(i, j)]; - } - inline double operator()(int i, int j) const - { - return _val[getIndex(i, j)]; - } - inline double operator[](int i) const - { - return _val[i]; - } - inline double &operator[](int i) - { - return _val[i]; - } + inline double &operator()(int i, int j) { return _val[getIndex(i, j)]; } + inline double operator()(int i, int j) const { return _val[getIndex(i, j)]; } + inline double operator[](int i) const { return _val[i]; } + inline double &operator[](int i) { return _val[i]; } STensor3 invert() const { double det = (*this).determinant(); - double udet =0.; + double udet = 0.; STensor3 ithis; - if(det == 0.) + if(det == 0.) Msg::Error("det=0 in STensor inversion"); else - udet = 1./det; - ithis(0,0) = ((*this)(1,1) * (*this)(2,2) - (*this)(1,2) * (*this)(2,1))* udet; - ithis(1,0) = -((*this)(1,0) * (*this)(2,2) - (*this)(1,2) * (*this)(2,0))* udet; - ithis(2,0) = ((*this)(1,0) * (*this)(2,1) - (*this)(1,1) * (*this)(2,0))* udet; - ithis(0,1) = -((*this)(0,1) * (*this)(2,2) - (*this)(0,2) * (*this)(2,1))* udet; - ithis(1,1) = ((*this)(0,0) * (*this)(2,2) - (*this)(0,2) * (*this)(2,0))* udet; - ithis(2,1) = -((*this)(0,0) * (*this)(2,1) - (*this)(0,1) * (*this)(2,0))* udet; - ithis(0,2) = ((*this)(0,1) * (*this)(1,2) - (*this)(0,2) * (*this)(1,1))* udet; - ithis(1,2) = -((*this)(0,0) * (*this)(1,2) - (*this)(0,2) * (*this)(1,0))* udet; - ithis(2,2) = ((*this)(0,0) * (*this)(1,1) - (*this)(0,1) * (*this)(1,0))* udet; + udet = 1. / det; + ithis(0, 0) = + ((*this)(1, 1) * (*this)(2, 2) - (*this)(1, 2) * (*this)(2, 1)) * udet; + ithis(1, 0) = + -((*this)(1, 0) * (*this)(2, 2) - (*this)(1, 2) * (*this)(2, 0)) * udet; + ithis(2, 0) = + ((*this)(1, 0) * (*this)(2, 1) - (*this)(1, 1) * (*this)(2, 0)) * udet; + ithis(0, 1) = + -((*this)(0, 1) * (*this)(2, 2) - (*this)(0, 2) * (*this)(2, 1)) * udet; + ithis(1, 1) = + ((*this)(0, 0) * (*this)(2, 2) - (*this)(0, 2) * (*this)(2, 0)) * udet; + ithis(2, 1) = + -((*this)(0, 0) * (*this)(2, 1) - (*this)(0, 1) * (*this)(2, 0)) * udet; + ithis(0, 2) = + ((*this)(0, 1) * (*this)(1, 2) - (*this)(0, 2) * (*this)(1, 1)) * udet; + ithis(1, 2) = + -((*this)(0, 0) * (*this)(1, 2) - (*this)(0, 2) * (*this)(1, 0)) * udet; + ithis(2, 2) = + ((*this)(0, 0) * (*this)(1, 1) - (*this)(0, 1) * (*this)(1, 0)) * udet; return ithis; } - STensor3 transpose () const + STensor3 transpose() const { STensor3 ithis; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - ithis(i,j) = (*this)(j,i); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) ithis(i, j) = (*this)(j, i); return ithis; } - STensor3& operator = (const STensor3 &other){ - for (int i = 0; i < 9; i++) _val[i] = other._val[i]; + STensor3 &operator=(const STensor3 &other) + { + for(int i = 0; i < 9; i++) _val[i] = other._val[i]; return *this; } - STensor3 operator + (const STensor3 &other) const + STensor3 operator+(const STensor3 &other) const { STensor3 res(*this); - for (int i = 0; i < 9; i++) res._val[i] += other._val[i]; + for(int i = 0; i < 9; i++) res._val[i] += other._val[i]; return res; } - STensor3& operator += (const STensor3 &other) + STensor3 &operator+=(const STensor3 &other) { - for (int i = 0; i < 9; i++) _val[i] += other._val[i]; + for(int i = 0; i < 9; i++) _val[i] += other._val[i]; return *this; } - STensor3& operator *= (const double &other) + STensor3 &operator*=(const double &other) { - for (int i = 0; i < 9; i++) _val[i] *= other; + for(int i = 0; i < 9; i++) _val[i] *= other; return *this; } - STensor3& operator *= (const STensor3 &other) - { - double a00=0.,a01=0.,a02=0.,a10=0.,a11=0.,a12=0.,a20=0.,a21=0.,a22=0.; - for(int i=0;i<3;i++) - { - a00+=(*this)(0,i)*other(i,0); - a01+=(*this)(0,i)*other(i,1); - a02+=(*this)(0,i)*other(i,2); - a10+=(*this)(1,i)*other(i,0); - a11+=(*this)(1,i)*other(i,1); - a12+=(*this)(1,i)*other(i,2); - a20+=(*this)(2,i)*other(i,0); - a21+=(*this)(2,i)*other(i,1); - a22+=(*this)(2,i)*other(i,2); + STensor3 &operator*=(const STensor3 &other) + { + double a00 = 0., a01 = 0., a02 = 0., a10 = 0., a11 = 0., a12 = 0., a20 = 0., + a21 = 0., a22 = 0.; + for(int i = 0; i < 3; i++) { + a00 += (*this)(0, i) * other(i, 0); + a01 += (*this)(0, i) * other(i, 1); + a02 += (*this)(0, i) * other(i, 2); + a10 += (*this)(1, i) * other(i, 0); + a11 += (*this)(1, i) * other(i, 1); + a12 += (*this)(1, i) * other(i, 2); + a20 += (*this)(2, i) * other(i, 0); + a21 += (*this)(2, i) * other(i, 1); + a22 += (*this)(2, i) * other(i, 2); } - (*this)(0,0)=a00; - (*this)(0,1)=a01; - (*this)(0,2)=a02; - (*this)(1,0)=a10; - (*this)(1,1)=a11; - (*this)(1,2)=a12; - (*this)(2,0)=a20; - (*this)(2,1)=a21; - (*this)(2,2)=a22; + (*this)(0, 0) = a00; + (*this)(0, 1) = a01; + (*this)(0, 2) = a02; + (*this)(1, 0) = a10; + (*this)(1, 1) = a11; + (*this)(1, 2) = a12; + (*this)(2, 0) = a20; + (*this)(2, 1) = a21; + (*this)(2, 2) = a22; return *this; } - void operator-= (const STensor3 &other) + void operator-=(const STensor3 &other) { - for(int i=0;i<9;i++) _val[i]-=other._val[i]; + for(int i = 0; i < 9; i++) _val[i] -= other._val[i]; } - void daxpy(const STensor3 &other, const double alpha=1.) + void daxpy(const STensor3 &other, const double alpha = 1.) { - if(alpha==1.) - for(int i=0;i<9;i++) _val[i]+=other._val[i]; + if(alpha == 1.) + for(int i = 0; i < 9; i++) _val[i] += other._val[i]; else - for(int i=0;i<9;i++) _val[i]+=alpha*other._val[i]; - } - double trace() const - { - return ((_val[0]+_val[4]+_val[8])); + for(int i = 0; i < 9; i++) _val[i] += alpha * other._val[i]; } + double trace() const { return ((_val[0] + _val[4] + _val[8])); } double dotprod() const { - double prod=0; - for(int i=0;i<9;i++) prod+=_val[i]*_val[i]; + double prod = 0; + for(int i = 0; i < 9; i++) prod += _val[i] * _val[i]; return prod; } - double determinant() const{ - double det= ((*this)(0,0) * ((*this)(1,1) * (*this)(2,2) - (*this)(1,2) * (*this)(2,1)) - - (*this)(0,1) * ((*this)(1,0) * (*this)(2,2) - (*this)(1,2) * (*this)(2,0)) + - (*this)(0,2) * ((*this)(1,0) * (*this)(2,1) - (*this)(1,1) * (*this)(2,0))); + double determinant() const + { + double det = + ((*this)(0, 0) * + ((*this)(1, 1) * (*this)(2, 2) - (*this)(1, 2) * (*this)(2, 1)) - + (*this)(0, 1) * + ((*this)(1, 0) * (*this)(2, 2) - (*this)(1, 2) * (*this)(2, 0)) + + (*this)(0, 2) * + ((*this)(1, 0) * (*this)(2, 1) - (*this)(1, 1) * (*this)(2, 0))); return det; }; void print(const char *) const; - double norm0() const{ + double norm0() const + { double val = 0; - for (int i=0; i<9; i++) - if (fabs(_val[i])>val) - val = fabs(_val[i]); + for(int i = 0; i < 9; i++) + if(fabs(_val[i]) > val) val = fabs(_val[i]); return val; }; - double norm2()const{ + double norm2() const + { double sqr = 0; - for (int i=0; i<3; i++){ - for (int j =0; j<3; j++){ - sqr += this->operator()(i,j)*this->operator()(i,j); + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + sqr += this->operator()(i, j) * this->operator()(i, j); } } return sqrt(sqr); } - STensor3 dev() const{ - double p= trace()/3.; + STensor3 dev() const + { + double p = trace() / 3.; STensor3 de(*this); - de(0,0) -= p; - de(1,1) -= p; - de(2,2) -= p; + de(0, 0) -= p; + de(1, 1) -= p; + de(2, 2) -= p; return de; } - void eig(fullMatrix<double> &V, fullVector<double> &S, bool s=false) const + void eig(fullMatrix<double> &V, fullVector<double> &S, bool s = false) const { fullMatrix<double> me(3, 3), left(3, 3); fullVector<double> im(3); @@ -405,38 +392,34 @@ class STensor3 { // tensor product inline void tensprod(const SVector3 &a, const SVector3 &b, STensor3 &c) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - c(i,j)=a(i)*b(j); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) c(i, j) = a(i) * b(j); } - inline double dot(const STensor3 &a, const STensor3 &b) { - double prod=0; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - prod+=a(i,j)*b(i,j); + double prod = 0; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) prod += a(i, j) * b(i, j); return prod; } -inline SVector3 operator* (const STensor3& t, const SVector3& v){ - SVector3 temp(0.,0.,0.); - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - temp[i]+= t(i,j)*v[j]; +inline SVector3 operator*(const STensor3 &t, const SVector3 &v) +{ + SVector3 temp(0., 0., 0.); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) temp[i] += t(i, j) * v[j]; return temp; } -inline SVector3 operator* (const SVector3& v, const STensor3& t){ - SVector3 temp(0.,0.,0.); - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - temp[j]+= v[i]*t(i,j); +inline SVector3 operator*(const SVector3 &v, const STensor3 &t) +{ + SVector3 temp(0., 0., 0.); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) temp[j] += v[i] * t(i, j); return temp; } - inline STensor3 operator*(const STensor3 &t, double m) { STensor3 val(t); @@ -444,7 +427,7 @@ inline STensor3 operator*(const STensor3 &t, double m) return val; } -inline STensor3 operator*(double m,const STensor3 &t) +inline STensor3 operator*(double m, const STensor3 &t) { STensor3 val(t); val *= m; diff --git a/Geo/SVector3.h b/Geo/SVector3.h index f02f26bd0589cd58dcd7a928f6eef9d80d71dde2..bc343668c9268e888e9b60000f1dbca376d83c73 100644 --- a/Geo/SVector3.h +++ b/Geo/SVector3.h @@ -13,10 +13,11 @@ // concrete class for vector of size 3 class SVector3 { - protected: +protected: SPoint3 P; - public: - SVector3():P() {} + +public: + SVector3() : P() {} // Construct from 2 SPoints, vector from p1 to p2 SVector3(const SPoint3 &p1, const SPoint3 &p2) : P(p2 - p1) {} // Construct from a single SPoint, vector from origin to p1 @@ -24,54 +25,82 @@ class SVector3 { SVector3(double x, double y, double z) : P(x, y, z) {} SVector3(double v) : P(v, v, v) {} SVector3(const double *array) : P(array) {} - SVector3(const SVector3& v) : P(v.P) {} + SVector3(const SVector3 &v) : P(v.P) {} double x(void) const { return P.x(); } double y(void) const { return P.y(); } double z(void) const { return P.z(); } double norm() const { return std::sqrt(this->normSq()); } - double normSq() const{ return P[0] * P[0] + P[1] * P[1] + P[2] * P[2]; } + double normSq() const { return P[0] * P[0] + P[1] * P[1] + P[2] * P[2]; } // Beware that " w = v.normalize() " produces the vector // w = (v.norm(), v.norm(), v.norm()), which is NOT a unit vector! // Use " w = v.unit() " to affect to "w" the unit vector parallel to "v". double normalize() { - double n = norm(); if(n){ P[0] /= n; P[1] /= n; P[2] /= n; } + double n = norm(); + if(n) { + P[0] /= n; + P[1] /= n; + P[2] /= n; + } return n; } - SVector3 unit() const{ SVector3 y(*this); y.normalize(); return y; } - void negate() { P[0] = -P[0]; P[1] = -P[1]; P[2] = -P[2]; } + SVector3 unit() const + { + SVector3 y(*this); + y.normalize(); + return y; + } + void negate() + { + P[0] = -P[0]; + P[1] = -P[1]; + P[2] = -P[2]; + } // why both [] and (), why not - double &operator[](int i){ return P[i]; } + double &operator[](int i) { return P[i]; } double operator[](int i) const { return P[i]; } - double &operator()(int i){ return P[i]; } + double &operator()(int i) { return P[i]; } double operator()(int i) const { return P[i]; } - SVector3 & operator += (const SVector3 &a) + SVector3 &operator+=(const SVector3 &a) { - P[0] += a[0]; P[1] += a[1]; P[2] += a[2]; + P[0] += a[0]; + P[1] += a[1]; + P[2] += a[2]; return *this; } - SVector3 & operator -= (const SVector3 &a) + SVector3 &operator-=(const SVector3 &a) { - P[0] -= a[0]; P[1] -= a[1]; P[2] -= a[2]; + P[0] -= a[0]; + P[1] -= a[1]; + P[2] -= a[2]; return *this; } - SVector3 & operator *= (const SVector3 &a) + SVector3 &operator*=(const SVector3 &a) { - P[0] *= a[0]; P[1] *= a[1]; P[2] *= a[2]; + P[0] *= a[0]; + P[1] *= a[1]; + P[2] *= a[2]; return *this; } - SVector3 & operator *= (const double v) + SVector3 &operator*=(const double v) { - P[0] *= v; P[1] *= v; P[2] *= v; + P[0] *= v; + P[1] *= v; + P[2] *= v; return *this; } - SVector3 & operator = (const SVector3& a) { - P[0] = a[0]; P[1] = a[1]; P[2] = a[2]; + SVector3 &operator=(const SVector3 &a) + { + P[0] = a[0]; + P[1] = a[1]; + P[2] = a[2]; return *this; } - SVector3 & operator = (double v) + SVector3 &operator=(double v) { - P[0] = v; P[1] = v; P[2] = v; + P[0] = v; + P[1] = v; + P[2] = v; return *this; } operator double *() { return P; } @@ -81,14 +110,14 @@ class SVector3 { } // Needed to allow the initialization of a SPoint3 from a SPoint3, a distance // and a direction - SPoint3 point() const{ return P; } - int getMaxValue(double& val) const + SPoint3 point() const { return P; } + int getMaxValue(double &val) const { - if ((P[0] >=P[1]) && (P[0]>=P[2])){ + if((P[0] >= P[1]) && (P[0] >= P[2])) { val = P[0]; return 0; } - else if ((P[1] >=P[0]) && (P[1]>=P[2])){ + else if((P[1] >= P[0]) && (P[1] >= P[2])) { val = P[1]; return 1; } @@ -97,148 +126,167 @@ class SVector3 { return 2; } } - const double* data() const {return P.data();} - double* data() {return P.data();} - void axpy(const double a, const SVector3& y){ - for (int i=0; i<3; i++){ - P[i] += (a*y[i]); + const double *data() const { return P.data(); } + double *data() { return P.data(); } + void axpy(const double a, const SVector3 &y) + { + for(int i = 0; i < 3; i++) { + P[i] += (a * y[i]); } } }; inline double dot(const SVector3 &a, const SVector3 &b) -{ return a.x() * b.x() + a.y() * b.y() + a.z() * b.z(); } +{ + return a.x() * b.x() + a.y() * b.y() + a.z() * b.z(); +} -inline double norm(const SVector3 &v) -{ return sqrt(dot(v, v)); } +inline double norm(const SVector3 &v) { return sqrt(dot(v, v)); } -inline double normSq(const SVector3 &v) -{ return dot(v, v); } +inline double normSq(const SVector3 &v) { return dot(v, v); } inline SVector3 crossprod(const SVector3 &a, const SVector3 &b) -{ return SVector3(a.y() * b.z() - b.y() * a.z(), +{ + return SVector3(a.y() * b.z() - b.y() * a.z(), -(a.x() * b.z() - b.x() * a.z()), - a.x() * b.y() - b.x() * a.y()); } + a.x() * b.y() - b.x() * a.y()); +} -inline double angle (const SVector3 &a, const SVector3 &b) +inline double angle(const SVector3 &a, const SVector3 &b) { - double cosTheta = dot(a,b); - double sinTheta = norm(crossprod(a,b)); - return atan2 (sinTheta,cosTheta); + double cosTheta = dot(a, b); + double sinTheta = norm(crossprod(a, b)); + return atan2(sinTheta, cosTheta); } inline double signedAngle(const SVector3 &a, const SVector3 &b, const SVector3 &n) { - double cosTheta = dot(a,b); - double sinTheta = dot(crossprod(a,b), n); - return atan2 (sinTheta,cosTheta); + double cosTheta = dot(a, b); + double sinTheta = dot(crossprod(a, b), n); + return atan2(sinTheta, cosTheta); } - -inline SVector3 operator*(double m,const SVector3 &v) -{ return SVector3(v[0] * m, v[1] * m, v[2] * m); } +inline SVector3 operator*(double m, const SVector3 &v) +{ + return SVector3(v[0] * m, v[1] * m, v[2] * m); +} inline SVector3 operator*(const SVector3 &v, double m) -{ return SVector3(v[0] * m, v[1] * m, v[2] * m); } +{ + return SVector3(v[0] * m, v[1] * m, v[2] * m); +} inline SVector3 operator*(const SVector3 &v1, const SVector3 &v2) -{ return SVector3(v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]); } +{ + return SVector3(v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]); +} -inline SVector3 operator+(const SVector3 &a,const SVector3 &b) -{ return SVector3(a[0] + b[0], a[1] + b[1], a[2] + b[2]); } +inline SVector3 operator+(const SVector3 &a, const SVector3 &b) +{ + return SVector3(a[0] + b[0], a[1] + b[1], a[2] + b[2]); +} -inline SPoint3 operator+(const SPoint3 &a,const SVector3 &b) -{ return SPoint3(a[0] + b[0], a[1] + b[1], a[2] + b[2]); } +inline SPoint3 operator+(const SPoint3 &a, const SVector3 &b) +{ + return SPoint3(a[0] + b[0], a[1] + b[1], a[2] + b[2]); +} -inline SVector3 operator-(const SVector3 &a,const SVector3 &b) -{ return SVector3(a[0] - b[0], a[1] - b[1], a[2] - b[2]); } +inline SVector3 operator-(const SVector3 &a, const SVector3 &b) +{ + return SVector3(a[0] - b[0], a[1] - b[1], a[2] - b[2]); +} -inline SPoint3 operator-(const SPoint3 &a,const SVector3 &b) -{ return SPoint3(a[0] - b[0], a[1] - b[1], a[2] - b[2]); } +inline SPoint3 operator-(const SPoint3 &a, const SVector3 &b) +{ + return SPoint3(a[0] - b[0], a[1] - b[1], a[2] - b[2]); +} inline SVector3 operator-(const SVector3 &a) -{ return SVector3(-a[0], -a[1], -a[2]); } - +{ + return SVector3(-a[0], -a[1], -a[2]); +} inline void buildOrthoBasis_naive(SVector3 &dir, SVector3 &dir1, SVector3 &dir2) { dir.normalize(); - if (dir[1]!=0.0 && dir[2]!=0.0){ - dir1 = SVector3(1.0, 0.0, -dir[0]/dir[2]); - dir2 = SVector3 (dir[0]/dir[2], -(dir[0]*dir[0]+dir[2]*dir[2])/(dir[1]*dir[2]), 1.0); - } - else if (dir[0]!=0.0 && dir[2]!=0.0){ - dir1 = SVector3(-dir[1]/dir[0], 1.0, 0.0); - dir2 = SVector3(1.0, dir[1]/dir[0], -(dir[1]*dir[1]+dir[0]*dir[0])/(dir[0]*dir[2])); - } - else if (dir[0]!=0.0 && dir[1]!=0.0){ - dir1 = SVector3(0.0, -dir[2]/dir[1], 1.0); - dir2 = SVector3(-(dir[1]*dir[1]+dir[2]*dir[2])/(dir[0]*dir[1]), 1.0, dir[2]/dir[1]); - } - else if (dir[0]==0.0 && dir[1]==0.0){ - dir1 = SVector3(0.0, 1.0, 0.0); - dir2 = SVector3(1.0, 0.0, 0.0); - } - else if (dir[1]==0.0 && dir[2]==0.0){ - dir1 = SVector3(0.0, 1.0, 0.0); - dir2 = SVector3(0.0, 0.0, 1.0); - } - else if (dir[0]==0.0 && dir[2]==0.0){ - dir1 = SVector3(1.0, 0.0, 0.0); - dir2 = SVector3(0.0, 0.0, 1.0); - } - else{ - Msg::Error("Problem with computing orthoBasis"); - } - // printf("XYZ =%g %g %g r=%g dir0 = %g %g %g dir1 = %g %g %g dir2 =%g %g %g\n", - // x,y,z,d, dir[0], dir[1], dir[2], dir1[0], dir1[1], dir1[2], dir2[0], dir2[1], dir2[2] ); - // printf("0x1 =%g 1x2=%g 2x1=%g \n", dot(dir, dir1), dot(dir1,dir2), dot(dir2,dir)); - dir1.normalize(); - dir2.normalize(); + if(dir[1] != 0.0 && dir[2] != 0.0) { + dir1 = SVector3(1.0, 0.0, -dir[0] / dir[2]); + dir2 = + SVector3(dir[0] / dir[2], + -(dir[0] * dir[0] + dir[2] * dir[2]) / (dir[1] * dir[2]), 1.0); + } + else if(dir[0] != 0.0 && dir[2] != 0.0) { + dir1 = SVector3(-dir[1] / dir[0], 1.0, 0.0); + dir2 = SVector3(1.0, dir[1] / dir[0], + -(dir[1] * dir[1] + dir[0] * dir[0]) / (dir[0] * dir[2])); + } + else if(dir[0] != 0.0 && dir[1] != 0.0) { + dir1 = SVector3(0.0, -dir[2] / dir[1], 1.0); + dir2 = SVector3(-(dir[1] * dir[1] + dir[2] * dir[2]) / (dir[0] * dir[1]), + 1.0, dir[2] / dir[1]); + } + else if(dir[0] == 0.0 && dir[1] == 0.0) { + dir1 = SVector3(0.0, 1.0, 0.0); + dir2 = SVector3(1.0, 0.0, 0.0); + } + else if(dir[1] == 0.0 && dir[2] == 0.0) { + dir1 = SVector3(0.0, 1.0, 0.0); + dir2 = SVector3(0.0, 0.0, 1.0); + } + else if(dir[0] == 0.0 && dir[2] == 0.0) { + dir1 = SVector3(1.0, 0.0, 0.0); + dir2 = SVector3(0.0, 0.0, 1.0); + } + else { + Msg::Error("Problem with computing orthoBasis"); + } + // printf("XYZ =%g %g %g r=%g dir0 = %g %g %g dir1 = %g %g %g dir2 =%g %g + // %g\n", x,y,z,d, dir[0], dir[1], dir[2], dir1[0], dir1[1], dir1[2], + // dir2[0], dir2[1], dir2[2] ); printf("0x1 =%g 1x2=%g 2x1=%g \n", dot(dir, + // dir1), dot(dir1,dir2), dot(dir2,dir)); + dir1.normalize(); + dir2.normalize(); } -//given a normal, build tangent and binormal -inline void buildOrthoBasis(SVector3 &normal, SVector3 &tangent, SVector3 &binormal) +// given a normal, build tangent and binormal +inline void buildOrthoBasis(SVector3 &normal, SVector3 &tangent, + SVector3 &binormal) { - //pick any Unit-Vector that's not parallel to normal: + // pick any Unit-Vector that's not parallel to normal: normal.normalize(); - if (fabs(normal[0]) > fabs(normal[1]) ) + if(fabs(normal[0]) > fabs(normal[1])) tangent = SVector3(0.0, 1.0, 0.0); else tangent = SVector3(1.0, 0.0, 0.0); - //build a binormal from tangent and normal: + // build a binormal from tangent and normal: binormal = crossprod(tangent, normal); double t1 = binormal.normalize(); - //and correct the tangent from the binormal and the normal. + // and correct the tangent from the binormal and the normal. tangent = crossprod(normal, binormal); double t2 = tangent.normalize(); - if (t1 == 0.0 || t2 == 0.0) - buildOrthoBasis_naive(normal, tangent, binormal); - + if(t1 == 0.0 || t2 == 0.0) buildOrthoBasis_naive(normal, tangent, binormal); } -//given a normal and guess tangent, build binormal -inline void buildOrthoBasis2(SVector3 &normal, SVector3 &tangent, SVector3 &binormal) +// given a normal and guess tangent, build binormal +inline void buildOrthoBasis2(SVector3 &normal, SVector3 &tangent, + SVector3 &binormal) { - normal.normalize(); tangent.normalize(); - //build a binormal from tangent and normal: + // build a binormal from tangent and normal: binormal = crossprod(tangent, normal); double t1 = binormal.normalize(); - //and correct the tangent from the binormal and the normal. + // and correct the tangent from the binormal and the normal. tangent = crossprod(normal, binormal); double t2 = tangent.normalize(); - if (t1 == 0.0 || t2 == 0.0) - buildOrthoBasis_naive(normal, tangent, binormal); - + if(t1 == 0.0 || t2 == 0.0) buildOrthoBasis_naive(normal, tangent, binormal); } #endif diff --git a/Geo/affineTransformation.cpp b/Geo/affineTransformation.cpp index fcbe5d1ca5fb6151e6619d1b4edc4db0eb99e538..6b22405640af6fc5855cfc05a7a157b0ba9855b1 100644 --- a/Geo/affineTransformation.cpp +++ b/Geo/affineTransformation.cpp @@ -9,42 +9,38 @@ #include "fullMatrix.h" - template <class FLOAT> -bool computeAffineTransformationTemplate(const FLOAT* rc, - const FLOAT* ra, +bool computeAffineTransformationTemplate(const FLOAT *rc, const FLOAT *ra, const FLOAT *tr, - std::vector<double>& tfo) { - + std::vector<double> &tfo) +{ tfo.clear(); tfo.reserve(16); - fullMatrix<double> compoundRotation(3,3); - for (int i=0;i<3;i++) compoundRotation(i,i) = 1; - - for (int i=0;i<3;i++) { - - if (ra[i] != 0) { + fullMatrix<double> compoundRotation(3, 3); + for(int i = 0; i < 3; i++) compoundRotation(i, i) = 1; + for(int i = 0; i < 3; i++) { + if(ra[i] != 0) { fullMatrix<double> tmp(compoundRotation); - fullMatrix<double> rotation(3,3); - rotation(i,i) = 1; + fullMatrix<double> rotation(3, 3); + rotation(i, i) = 1; - int ii = (i+1)%3; - int jj = (i+2)%3; + int ii = (i + 1) % 3; + int jj = (i + 2) % 3; double ca = cos(ra[i]); double sa = sin(ra[i]); // rotation with alpha - rotation(ii,ii) = ca; - rotation(ii,jj) = sa; - rotation(jj,ii) = -sa; - rotation(jj,jj) = ca; + rotation(ii, ii) = ca; + rotation(ii, jj) = sa; + rotation(jj, ii) = -sa; + rotation(jj, jj) = ca; - compoundRotation.gemm(rotation,tmp,1,0); + compoundRotation.gemm(rotation, tmp, 1, 0); } } @@ -53,55 +49,55 @@ bool computeAffineTransformationTemplate(const FLOAT* rc, fullVector<double> disp(3); fullVector<double> center(3); - for (int i=0;i<3;i++) center(i) = rc[i]; - compoundRotation.mult(center,disp); + for(int i = 0; i < 3; i++) center(i) = rc[i]; + compoundRotation.mult(center, disp); // add specified translation - for (int i=0;i<3;i++) disp(i) = - tr[i]; + for(int i = 0; i < 3; i++) disp(i) = -tr[i]; // copy to tfo tfo.clear(); - for (int i=0;i<3;i++) { - for (int j=0;j<3;j++) tfo.push_back(compoundRotation(i,j)); + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) tfo.push_back(compoundRotation(i, j)); tfo.push_back(disp(i)); } - for (int i=0;i<3;i++) tfo.push_back(0); + for(int i = 0; i < 3; i++) tfo.push_back(0); tfo.push_back(1); return true; } -bool computeAffineTransformation(const float* rc, - const float* ra, - const float *tr, - std::vector<double>& tfo) { - return computeAffineTransformationTemplate(rc,ra,tr,tfo); +bool computeAffineTransformation(const float *rc, const float *ra, + const float *tr, std::vector<double> &tfo) +{ + return computeAffineTransformationTemplate(rc, ra, tr, tfo); } -bool computeAffineTransformation(const double* rc, - const double* ra, - const double *tr, - std::vector<double>& tfo) { - return computeAffineTransformationTemplate(rc,ra,tr,tfo); +bool computeAffineTransformation(const double *rc, const double *ra, + const double *tr, std::vector<double> &tfo) +{ + return computeAffineTransformationTemplate(rc, ra, tr, tfo); } -bool invertAffineTransformation(const std::vector<double>& tfo, - std::vector<double>& newTfo) { - - fullMatrix<double> inv(4,4); - for (int i=0;i<4;i++) for (int j=0;j<4;j++) inv(i,j) = tfo[i*4+j]; +bool invertAffineTransformation(const std::vector<double> &tfo, + std::vector<double> &newTfo) +{ + fullMatrix<double> inv(4, 4); + for(int i = 0; i < 4; i++) + for(int j = 0; j < 4; j++) inv(i, j) = tfo[i * 4 + j]; inv.invertInPlace(); newTfo.clear(); - for (int i=0;i<4;i++) for (int j=0;j<4;j++) newTfo.push_back(inv(i,j)); + for(int i = 0; i < 4; i++) + for(int j = 0; j < 4; j++) newTfo.push_back(inv(i, j)); return true; } - -bool setUnitAffineTransformation(std::vector<double>& tfo) { - tfo.resize(16,0); - for (int i=0;i<16;i+=5) tfo[i] = 1; +bool setUnitAffineTransformation(std::vector<double> &tfo) +{ + tfo.resize(16, 0); + for(int i = 0; i < 16; i += 5) tfo[i] = 1; return true; } diff --git a/Geo/affineTransformation.h b/Geo/affineTransformation.h index 81a70dfeeca2a7c41600037f2ceb5bb7cb57e747..e6a0af8ff68b98f2015453d82ce0707112b4ffd6 100644 --- a/Geo/affineTransformation.h +++ b/Geo/affineTransformation.h @@ -10,27 +10,26 @@ // compute affine transformation from rotation/translation -bool computeAffineTransformation(const double* rc, // rotation center - const double* ra, // rotation angle - const double* tr, // translation - std::vector<double>& tfo // transformation - ); +bool computeAffineTransformation(const double *rc, // rotation center + const double *ra, // rotation angle + const double *tr, // translation + std::vector<double> &tfo // transformation +); // compute affine transfomration from rotation/translation -bool computeAffineTransformation(const float* rc, // rotation center - const float* ra, // rotation angle - const float* tr, // translation - std::vector<double>& tfo // transformation - ); +bool computeAffineTransformation(const float *rc, // rotation center + const float *ra, // rotation angle + const float *tr, // translation + std::vector<double> &tfo // transformation +); // invert affine transformation -bool invertAffineTransformation(const std::vector<double>& tfo, - std::vector<double>& newTfo); +bool invertAffineTransformation(const std::vector<double> &tfo, + std::vector<double> &newTfo); -// initialize transformation with unitary one - -bool setUnitAffineTransformation(std::vector<double>& tfo); +// initialize transformation with unitary one +bool setUnitAffineTransformation(std::vector<double> &tfo); #endif diff --git a/Geo/boundaryLayersData.cpp b/Geo/boundaryLayersData.cpp index 0465f05d531f3f88c25780d6dc47275f0c70af3f..23f83d97ea7bf1a4603a1a37dcb1a6d8b38f410d 100644 --- a/Geo/boundaryLayersData.cpp +++ b/Geo/boundaryLayersData.cpp @@ -14,10 +14,10 @@ #if !defined(HAVE_MESH) || !defined(HAVE_ANN) -BoundaryLayerField* getBLField(GModel *gm){ return 0; } -bool buildAdditionalPoints2D(GFace *gf ){ return false; } -bool buildAdditionalPoints3D(GRegion *gr){ return false; } -edgeColumn BoundaryLayerColumns::getColumns(MVertex *v1, MVertex *v2 , int side) +BoundaryLayerField *getBLField(GModel *gm) { return 0; } +bool buildAdditionalPoints2D(GFace *gf) { return false; } +bool buildAdditionalPoints3D(GRegion *gr) { return false; } +edgeColumn BoundaryLayerColumns::getColumns(MVertex *v1, MVertex *v2, int side) { return edgeColumn(BoundaryLayerData(), BoundaryLayerData()); } @@ -41,104 +41,113 @@ edgeColumn BoundaryLayerColumns::getColumns(MVertex *v1, MVertex *v2 , int side) SVector3 interiorNormal(const SPoint2 &p1, const SPoint2 &p2, const SPoint2 &p3) { - SVector3 ez(0,0,1); - SVector3 d(p1.x()-p2.x(),p1.y()-p2.y(),0); - SVector3 h(p3.x()-0.5*(p2.x()+p1.x()),p3.y()-0.5*(p2.y()+p1.y()),0); + SVector3 ez(0, 0, 1); + SVector3 d(p1.x() - p2.x(), p1.y() - p2.y(), 0); + SVector3 h(p3.x() - 0.5 * (p2.x() + p1.x()), p3.y() - 0.5 * (p2.y() + p1.y()), + 0); SVector3 n = crossprod(d, ez); n.normalize(); - if(dot(n,h) > 0) return n; - return n*(-1.); + if(dot(n, h) > 0) return n; + return n * (-1.); } -edgeColumn BoundaryLayerColumns::getColumns(MVertex *v1, MVertex *v2 , int side) +edgeColumn BoundaryLayerColumns::getColumns(MVertex *v1, MVertex *v2, int side) { Equal_Edge aaa; MEdge e(v1, v2); - std::map<MVertex*,BoundaryLayerFan>::const_iterator it1 = _fans.find(v1); - std::map<MVertex*,BoundaryLayerFan>::const_iterator it2 = _fans.find(v2); - int N1 = getNbColumns(v1) ; - int N2 = getNbColumns(v2) ; + std::map<MVertex *, BoundaryLayerFan>::const_iterator it1 = _fans.find(v1); + std::map<MVertex *, BoundaryLayerFan>::const_iterator it2 = _fans.find(v2); + int N1 = getNbColumns(v1); + int N2 = getNbColumns(v2); int nbSides = _normals.count(e); // if(nbSides != 1)printf("I'm here %d sides\n",nbSides); // Standard case, only two extruded columns from the two vertices - if(N1 == 1 && N2 == 1) return edgeColumn(getColumn(v1,0),getColumn(v2,0)); + if(N1 == 1 && N2 == 1) return edgeColumn(getColumn(v1, 0), getColumn(v2, 0)); // one fan on - if(nbSides == 1){ - if(it1 != _fans.end() && it2 == _fans.end() ){ - if(aaa(it1->second._e1,e)) - return edgeColumn(getColumn(v1,0),getColumn(v2,0)); + if(nbSides == 1) { + if(it1 != _fans.end() && it2 == _fans.end()) { + if(aaa(it1->second._e1, e)) + return edgeColumn(getColumn(v1, 0), getColumn(v2, 0)); else - return edgeColumn(getColumn(v1,N1-1),getColumn(v2,0)); + return edgeColumn(getColumn(v1, N1 - 1), getColumn(v2, 0)); } - if(it2 != _fans.end() && it1 == _fans.end() ){ - if(aaa(it2->second._e1,e)) - return edgeColumn(getColumn(v1,0),getColumn(v2,0)); + if(it2 != _fans.end() && it1 == _fans.end()) { + if(aaa(it2->second._e1, e)) + return edgeColumn(getColumn(v1, 0), getColumn(v2, 0)); else - return edgeColumn(getColumn(v1,0),getColumn(v2,N2-1)); + return edgeColumn(getColumn(v1, 0), getColumn(v2, N2 - 1)); } - if(it2 != _fans.end() && it1 != _fans.end() ){ + if(it2 != _fans.end() && it1 != _fans.end()) { int c1, c2; - if(aaa(it1->second._e1,e)) - c1 = 0; + if(aaa(it1->second._e1, e)) + c1 = 0; else - c1 = N1-1; - if(aaa(it2->second._e1,e)) - c2 = 0; + c1 = N1 - 1; + if(aaa(it2->second._e1, e)) + c2 = 0; else - c2 = N2-1; - return edgeColumn(getColumn(v1,c1),getColumn(v2,c2)); + c2 = N2 - 1; + return edgeColumn(getColumn(v1, c1), getColumn(v2, c2)); } // fan on the right - if(N1 == 1 || N2 == 2){ - const BoundaryLayerData & c10 = getColumn(v1,0); - const BoundaryLayerData & c20 = getColumn(v2,0); - const BoundaryLayerData & c21 = getColumn(v2,1); - if(dot(c10._n,c20._n) > dot(c10._n,c21._n) ) return edgeColumn(c10,c20); - else return edgeColumn(c10,c21); + if(N1 == 1 || N2 == 2) { + const BoundaryLayerData &c10 = getColumn(v1, 0); + const BoundaryLayerData &c20 = getColumn(v2, 0); + const BoundaryLayerData &c21 = getColumn(v2, 1); + if(dot(c10._n, c20._n) > dot(c10._n, c21._n)) + return edgeColumn(c10, c20); + else + return edgeColumn(c10, c21); } // fan on the left - if(N1 == 2 || N2 == 1){ - const BoundaryLayerData & c10 = getColumn(v1,0); - const BoundaryLayerData & c11 = getColumn(v1,1); - const BoundaryLayerData & c20 = getColumn(v2,0); - if(dot(c10._n,c20._n) > dot(c11._n,c20._n) ) return edgeColumn(c10,c20); - else return edgeColumn(c11,c20); + if(N1 == 2 || N2 == 1) { + const BoundaryLayerData &c10 = getColumn(v1, 0); + const BoundaryLayerData &c11 = getColumn(v1, 1); + const BoundaryLayerData &c20 = getColumn(v2, 0); + if(dot(c10._n, c20._n) > dot(c11._n, c20._n)) + return edgeColumn(c10, c20); + else + return edgeColumn(c11, c20); } // Msg::Error("Impossible Boundary Layer Configuration : " // "one side and no fans %d %d", N1, N2); // FIXME WRONG - return N1 ? edgeColumn(getColumn(v1,0),getColumn(v1,0)) : - edgeColumn(getColumn(v2,0),getColumn(v2,0)); + return N1 ? edgeColumn(getColumn(v1, 0), getColumn(v1, 0)) : + edgeColumn(getColumn(v2, 0), getColumn(v2, 0)); } - else if(nbSides == 2){ - int i1=0,i2=1,j1=0,j2=1; - if(it1 != _fans.end()){ - i1 = aaa(it1->second._e1,e) ? 0 : N1-1; - i2 = !aaa(it1->second._e1,e) ? 0 : N1-1; + else if(nbSides == 2) { + int i1 = 0, i2 = 1, j1 = 0, j2 = 1; + if(it1 != _fans.end()) { + i1 = aaa(it1->second._e1, e) ? 0 : N1 - 1; + i2 = !aaa(it1->second._e1, e) ? 0 : N1 - 1; } - if(it2 != _fans.end()){ - j1 = aaa(it2->second._e1,e) ? 0 : N2-1; - j2 = !aaa(it2->second._e1,e) ? 0 : N2-1; + if(it2 != _fans.end()) { + j1 = aaa(it2->second._e1, e) ? 0 : N2 - 1; + j2 = !aaa(it2->second._e1, e) ? 0 : N2 - 1; } - const BoundaryLayerData & c10 = getColumn(v1,i1); - const BoundaryLayerData & c11 = getColumn(v1,i2); - const BoundaryLayerData & c20 = getColumn(v2,j1); - const BoundaryLayerData & c21 = getColumn(v2,j2); - - if(side == 0){ - if(dot(c10._n,c20._n) > dot(c10._n,c21._n) ) return edgeColumn(c10,c20); - else return edgeColumn(c10,c21); + const BoundaryLayerData &c10 = getColumn(v1, i1); + const BoundaryLayerData &c11 = getColumn(v1, i2); + const BoundaryLayerData &c20 = getColumn(v2, j1); + const BoundaryLayerData &c21 = getColumn(v2, j2); + + if(side == 0) { + if(dot(c10._n, c20._n) > dot(c10._n, c21._n)) + return edgeColumn(c10, c20); + else + return edgeColumn(c10, c21); } - if(side == 1){ - if(dot(c11._n,c20._n) > dot(c11._n,c21._n) ) return edgeColumn(c11,c20); - else return edgeColumn(c11,c21); + if(side == 1) { + if(dot(c11._n, c20._n) > dot(c11._n, c21._n)) + return edgeColumn(c11, c20); + else + return edgeColumn(c11, c21); } } - Msg::Error("Not yet Done in BoundaryLayerData nbSides = %d, ",nbSides ); + Msg::Error("Not yet Done in BoundaryLayerData nbSides = %d, ", nbSides); static BoundaryLayerData error; static edgeColumn error2(error, error); return error2; @@ -148,47 +157,53 @@ static void treat2Connections(GFace *gf, MVertex *_myVert, MEdge &e1, MEdge &e2, BoundaryLayerColumns *_columns, std::vector<SVector3> &_dirs, bool fan) { - std::vector<SVector3> N1,N2; - for(std::multimap<MEdge,SVector3,Less_Edge>::iterator itm = - _columns->_normals.lower_bound(e1); - itm != _columns->_normals.upper_bound(e1); ++itm) N1.push_back(itm->second); - for(std::multimap<MEdge,SVector3,Less_Edge>::iterator itm = - _columns->_normals.lower_bound(e2); - itm != _columns->_normals.upper_bound(e2); ++itm) N2.push_back(itm->second); - if(N1.size() == N2.size()){ - for(unsigned int SIDE = 0; SIDE < N1.size() ; SIDE++){ - if(!fan){ - SVector3 x = N1[SIDE]*1.01+N2[SIDE]; + std::vector<SVector3> N1, N2; + for(std::multimap<MEdge, SVector3, Less_Edge>::iterator itm = + _columns->_normals.lower_bound(e1); + itm != _columns->_normals.upper_bound(e1); ++itm) + N1.push_back(itm->second); + for(std::multimap<MEdge, SVector3, Less_Edge>::iterator itm = + _columns->_normals.lower_bound(e2); + itm != _columns->_normals.upper_bound(e2); ++itm) + N2.push_back(itm->second); + if(N1.size() == N2.size()) { + for(unsigned int SIDE = 0; SIDE < N1.size(); SIDE++) { + if(!fan) { + SVector3 x = N1[SIDE] * 1.01 + N2[SIDE]; x.normalize(); _dirs.push_back(x); } - else if(fan){ + else if(fan) { // if the angle is greater than PI, than reverse the sense - double alpha1 = atan2(N1[SIDE].y(),N1[SIDE].x()); - double alpha2 = atan2(N2[SIDE].y(),N2[SIDE].x()); - double AMAX = std::max(alpha1,alpha2); - double AMIN = std::min(alpha1,alpha2); + double alpha1 = atan2(N1[SIDE].y(), N1[SIDE].x()); + double alpha2 = atan2(N2[SIDE].y(), N2[SIDE].x()); + double AMAX = std::max(alpha1, alpha2); + double AMIN = std::min(alpha1, alpha2); MEdge ee[2]; - if(alpha1 > alpha2){ - ee[0] = e2;ee[1] = e1; + if(alpha1 > alpha2) { + ee[0] = e2; + ee[1] = e1; } else { - ee[0] = e1;ee[1] = e2; + ee[0] = e1; + ee[1] = e2; } - if(AMAX - AMIN >= M_PI){ + if(AMAX - AMIN >= M_PI) { double temp = AMAX; - AMAX = AMIN + 2*M_PI; + AMAX = AMIN + 2 * M_PI; AMIN = temp; MEdge eee0 = ee[0]; - ee[0] = ee[1];ee[1] = eee0; + ee[0] = ee[1]; + ee[1] = eee0; } double frac = fabs(AMAX - AMIN) / M_PI; - int n = (int)(frac * CTX::instance()->mesh.boundaryLayerFanPoints + 0.5); - int fanSize = fan ? n : 0 ; - _columns->addFan(_myVert,ee[0],ee[1],true); - for(int i = -1; i <= fanSize; i++){ - double t =(double)(i + 1)/(fanSize + 1); - double alpha = t * AMAX + (1.-t) * AMIN; + int n = + (int)(frac * CTX::instance()->mesh.boundaryLayerFanPoints + 0.5); + int fanSize = fan ? n : 0; + _columns->addFan(_myVert, ee[0], ee[1], true); + for(int i = -1; i <= fanSize; i++) { + double t = (double)(i + 1) / (fanSize + 1); + double alpha = t * AMAX + (1. - t) * AMIN; SVector3 x(cos(alpha), sin(alpha), 0); x.normalize(); _dirs.push_back(x); @@ -204,33 +219,35 @@ static void treat2Connections(GFace *gf, MVertex *_myVert, MEdge &e1, MEdge &e2, } } -static void treat3Connections(GFace *gf, MVertex *_myVert, MEdge &e1, - MEdge &e2, MEdge &e3, - BoundaryLayerColumns *_columns, +static void treat3Connections(GFace *gf, MVertex *_myVert, MEdge &e1, MEdge &e2, + MEdge &e3, BoundaryLayerColumns *_columns, std::vector<SVector3> &_dirs) { - std::vector<SVector3> N1,N2,N3; - for(std::multimap<MEdge,SVector3,Less_Edge>::iterator itm = - _columns->_normals.lower_bound(e1); - itm != _columns->_normals.upper_bound(e1); ++itm) N1.push_back(itm->second); - for(std::multimap<MEdge,SVector3,Less_Edge>::iterator itm = - _columns->_normals.lower_bound(e2); - itm != _columns->_normals.upper_bound(e2); ++itm) N2.push_back(itm->second); - for(std::multimap<MEdge,SVector3,Less_Edge>::iterator itm = - _columns->_normals.lower_bound(e3); - itm != _columns->_normals.upper_bound(e3); ++itm) N3.push_back(itm->second); - - SVector3 x1,x2; - if(N1.size() == 2){ + std::vector<SVector3> N1, N2, N3; + for(std::multimap<MEdge, SVector3, Less_Edge>::iterator itm = + _columns->_normals.lower_bound(e1); + itm != _columns->_normals.upper_bound(e1); ++itm) + N1.push_back(itm->second); + for(std::multimap<MEdge, SVector3, Less_Edge>::iterator itm = + _columns->_normals.lower_bound(e2); + itm != _columns->_normals.upper_bound(e2); ++itm) + N2.push_back(itm->second); + for(std::multimap<MEdge, SVector3, Less_Edge>::iterator itm = + _columns->_normals.lower_bound(e3); + itm != _columns->_normals.upper_bound(e3); ++itm) + N3.push_back(itm->second); + + SVector3 x1, x2; + if(N1.size() == 2) { } - else if(N2.size() == 2){ + else if(N2.size() == 2) { std::vector<SVector3> temp = N1; N1.clear(); N1 = N2; N2.clear(); N2 = temp; } - else if(N3.size() == 2){ + else if(N3.size() == 2) { std::vector<SVector3> temp = N1; N1.clear(); N1 = N3; @@ -240,13 +257,13 @@ static void treat3Connections(GFace *gf, MVertex *_myVert, MEdge &e1, else { Msg::Error("Impossible boundary layer configuration"); } - if(dot(N1[0],N2[0]) > dot(N1[0],N3[0])){ - x1 = N1[0]*1.01+N2[0]; - x2 = N1[1]*1.01+N3[0]; + if(dot(N1[0], N2[0]) > dot(N1[0], N3[0])) { + x1 = N1[0] * 1.01 + N2[0]; + x2 = N1[1] * 1.01 + N3[0]; } else { - x1 = N1[1]*1.01+N2[0]; - x2 = N1[0]*1.01+N3[0]; + x1 = N1[1] * 1.01 + N2[0]; + x2 = N1[0] * 1.01 + N3[0]; } x1.normalize(); _dirs.push_back(x1); @@ -256,7 +273,7 @@ static void treat3Connections(GFace *gf, MVertex *_myVert, MEdge &e1, static bool isEdgeOfFaceBL(GFace *gf, GEdge *ge, BoundaryLayerField *blf) { - if(blf->isEdgeBL(ge->tag()))return true; + if(blf->isEdgeBL(ge->tag())) return true; /* std::list<GFace*> faces = ge->faces(); for(std::list<GFace*>::iterator it = faces.begin(); @@ -271,29 +288,28 @@ static bool isEdgeOfFaceBL(GFace *gf, GEdge *ge, BoundaryLayerField *blf) return false; } -static void getEdgesData(GFace *gf, - BoundaryLayerField *blf, +static void getEdgesData(GFace *gf, BoundaryLayerField *blf, BoundaryLayerColumns *_columns, - std::set<MVertex*> &_vertices, - std::set<MEdge,Less_Edge> &allEdges, - std::multimap<MVertex*,MVertex*> &tangents) + std::set<MVertex *> &_vertices, + std::set<MEdge, Less_Edge> &allEdges, + std::multimap<MVertex *, MVertex *> &tangents) { // get all model edges - std::vector<GEdge*> edges = gf->edges(); - std::vector<GEdge*> const& embedded_edges = gf->embeddedEdges(); - edges.insert(edges.begin(), embedded_edges.begin(),embedded_edges.end()); + std::vector<GEdge *> edges = gf->edges(); + std::vector<GEdge *> const &embedded_edges = gf->embeddedEdges(); + edges.insert(edges.begin(), embedded_edges.begin(), embedded_edges.end()); // iterate on model edges - std::vector<GEdge*>::iterator ite = edges.begin(); - while(ite != edges.end()){ + std::vector<GEdge *>::iterator ite = edges.begin(); + while(ite != edges.end()) { // check if this edge generates a boundary layer - if(isEdgeOfFaceBL(gf,*ite,blf)){ - for(unsigned int i = 0; i < (*ite)->lines.size(); i++){ + if(isEdgeOfFaceBL(gf, *ite, blf)) { + for(unsigned int i = 0; i < (*ite)->lines.size(); i++) { MVertex *v1 = (*ite)->lines[i]->getVertex(0); MVertex *v2 = (*ite)->lines[i]->getVertex(1); - allEdges.insert(MEdge(v1,v2)); - _columns->_non_manifold_edges.insert(std::make_pair(v1,v2)); - _columns->_non_manifold_edges.insert(std::make_pair(v2,v1)); + allEdges.insert(MEdge(v1, v2)); + _columns->_non_manifold_edges.insert(std::make_pair(v1, v2)); + _columns->_non_manifold_edges.insert(std::make_pair(v2, v1)); _vertices.insert(v1); _vertices.insert(v2); } @@ -310,86 +326,83 @@ static void getEdgesData(GFace *gf, } } -static void getNormals(GFace *gf, - BoundaryLayerField *blf, +static void getNormals(GFace *gf, BoundaryLayerField *blf, BoundaryLayerColumns *_columns, - std::set<MEdge,Less_Edge> &allEdges) + std::set<MEdge, Less_Edge> &allEdges) { // assume that the initial mesh has been created i.e. that there exist // triangles inside the domain. Triangles are used to define exterior normals - for(unsigned int i = 0; i < gf->triangles.size(); i++){ - SPoint2 p0,p1,p2; + for(unsigned int i = 0; i < gf->triangles.size(); i++) { + SPoint2 p0, p1, p2; MVertex *v0 = gf->triangles[i]->getVertex(0); MVertex *v1 = gf->triangles[i]->getVertex(1); MVertex *v2 = gf->triangles[i]->getVertex(2); reparamMeshEdgeOnFace(v0, v1, gf, p0, p1); reparamMeshEdgeOnFace(v0, v2, gf, p0, p2); - MEdge me01(v0,v1); - if(allEdges.find(me01) != allEdges.end()){ - SVector3 v01 = interiorNormal(p0,p1,p2); - _columns->_normals.insert(std::make_pair(me01,v01)); + MEdge me01(v0, v1); + if(allEdges.find(me01) != allEdges.end()) { + SVector3 v01 = interiorNormal(p0, p1, p2); + _columns->_normals.insert(std::make_pair(me01, v01)); } - MEdge me02(v0,v2); - if(allEdges.find(me02) != allEdges.end()){ - SVector3 v02 = interiorNormal(p0,p2,p1); - _columns->_normals.insert(std::make_pair(me02,v02)); + MEdge me02(v0, v2); + if(allEdges.find(me02) != allEdges.end()) { + SVector3 v02 = interiorNormal(p0, p2, p1); + _columns->_normals.insert(std::make_pair(me02, v02)); } - MEdge me21(v2,v1); - if(allEdges.find(me21) != allEdges.end()){ - SVector3 v21 = interiorNormal(p2,p1,p0); - _columns->_normals.insert(std::make_pair(me21,v21)); + MEdge me21(v2, v1); + if(allEdges.find(me21) != allEdges.end()) { + SVector3 v21 = interiorNormal(p2, p1, p0); + _columns->_normals.insert(std::make_pair(me21, v21)); } } } -static void addColumnAtTheEndOfTheBL(GEdge *ge, - GVertex *gv, - BoundaryLayerColumns* _columns, +static void addColumnAtTheEndOfTheBL(GEdge *ge, GVertex *gv, + BoundaryLayerColumns *_columns, BoundaryLayerField *blf) { - if(!blf->isEdgeBL(ge->tag())){ + if(!blf->isEdgeBL(ge->tag())) { GVertex *g0 = ge->getBeginVertex(); GVertex *g1 = ge->getEndVertex(); - MVertex * v0 = g0->mesh_vertices[0]; - MVertex * v1 = g1->mesh_vertices[0]; - std::vector<MVertex*> invert; - for(unsigned int i = 0; i < ge->mesh_vertices.size() ; i++) + MVertex *v0 = g0->mesh_vertices[0]; + MVertex *v1 = g1->mesh_vertices[0]; + std::vector<MVertex *> invert; + for(unsigned int i = 0; i < ge->mesh_vertices.size(); i++) invert.push_back(ge->mesh_vertices[ge->mesh_vertices.size() - i - 1]); - SVector3 t(v1->x()-v0->x(), v1->y()-v0->y(),v1->z()-v0->z()); + SVector3 t(v1->x() - v0->x(), v1->y() - v0->y(), v1->z() - v0->z()); t.normalize(); if(g0 == gv) _columns->addColumn(t, v0, ge->mesh_vertices); else if(g1 == gv) - _columns->addColumn(t*-1.0, v1,invert); + _columns->addColumn(t * -1.0, v1, invert); } } void getLocalInfoAtNode(MVertex *v, BoundaryLayerField *blf, double &hwall) { hwall = blf->hwall_n; - if(v->onWhat()->dim() == 0){ - hwall= blf->hwall(v->onWhat()->tag()); + if(v->onWhat()->dim() == 0) { + hwall = blf->hwall(v->onWhat()->tag()); } - else if(v->onWhat()->dim() == 1){ - GEdge *ge = (GEdge*)v->onWhat(); + else if(v->onWhat()->dim() == 1) { + GEdge *ge = (GEdge *)v->onWhat(); Range<double> bounds = ge->parBounds(0); double t_begin = bounds.low(); double t_end = bounds.high(); double t; - v->getParameter(0,t); + v->getParameter(0, t); double hwall_beg = blf->hwall(ge->getBeginVertex()->tag()); double hwall_end = blf->hwall(ge->getEndVertex()->tag()); - double x = (t-t_begin)/(t_end-t_begin); + double x = (t - t_begin) / (t_end - t_begin); double hwallLin = hwall_beg + x * (hwall_end - hwall_beg); double hwall_mid = std::min(hwall_beg, hwall_end); - double hwallQuad = hwall_beg * (1-x)*(1-x) + - hwall_mid * 2*x*(1-x) + - hwall_end * x*x; + double hwallQuad = hwall_beg * (1 - x) * (1 - x) + + hwall_mid * 2 * x * (1 - x) + hwall_end * x * x; // we prefer a quadratic growing: - hwall = 0*hwallLin + 1*hwallQuad; + hwall = 0 * hwallLin + 1 * hwallQuad; } } @@ -400,105 +413,110 @@ bool buildAdditionalPoints2D(GFace *gf) FieldManager *fields = gf->model()->getFields(); int nBL = fields->getNumBoundaryLayerFields(); - if (nBL == 0) return false; + if(nBL == 0) return false; // Note: boundary layers must be separate (must not touch each other) bool addedAdditionalPoints = false; - for (int i = 0; i < nBL; ++i) { + for(int i = 0; i < nBL; ++i) { // GET THE FIELD THAT DEFINES THE DISTANCE FUNCTION Field *bl_field = fields->get(fields->getBoundaryLayerField(i)); - if (bl_field == NULL) continue; - BoundaryLayerField *blf = dynamic_cast<BoundaryLayerField*>(bl_field); + if(bl_field == NULL) continue; + BoundaryLayerField *blf = dynamic_cast<BoundaryLayerField *>(bl_field); blf->setupFor2d(gf->tag()); - std::set<MVertex*> _vertices; - std::set<MEdge,Less_Edge> allEdges; - std::multimap<MVertex*,MVertex*> tangents; + std::set<MVertex *> _vertices; + std::set<MEdge, Less_Edge> allEdges; + std::multimap<MVertex *, MVertex *> tangents; - getEdgesData( gf, blf, _columns, _vertices , allEdges , tangents ); + getEdgesData(gf, blf, _columns, _vertices, allEdges, tangents); if(!_vertices.size()) continue; getNormals(gf, blf, _columns, allEdges); // for all boundry points - for(std::set<MVertex*>::iterator it = _vertices.begin(); it != _vertices.end() ; ++it){ - + for(std::set<MVertex *>::iterator it = _vertices.begin(); + it != _vertices.end(); ++it) { bool endOfTheBL = false; SVector3 dirEndOfBL; - std::vector<MVertex*> columnEndOfBL; + std::vector<MVertex *> columnEndOfBL; - std::vector<MVertex*> _connections; + std::vector<MVertex *> _connections; std::vector<SVector3> _dirs; // get all vertices that are connected to that // vertex among all boundary layer vertices ! - bool fan = (*it)->onWhat()->dim() == 0 && blf->isFanNode((*it)->onWhat()->tag()); + bool fan = + (*it)->onWhat()->dim() == 0 && blf->isFanNode((*it)->onWhat()->tag()); - for(std::multimap<MVertex*,MVertex*>::iterator itm = - _columns->_non_manifold_edges.lower_bound(*it); + for(std::multimap<MVertex *, MVertex *>::iterator itm = + _columns->_non_manifold_edges.lower_bound(*it); itm != _columns->_non_manifold_edges.upper_bound(*it); ++itm) _connections.push_back(itm->second); // A trailing edge topology : 3 edges incident to a vertex - if(_connections.size() == 3){ - MEdge e1(*it,_connections[0]); - MEdge e2(*it,_connections[1]); - MEdge e3(*it,_connections[2]); - treat3Connections(gf, *it,e1,e2,e3, _columns, _dirs); + if(_connections.size() == 3) { + MEdge e1(*it, _connections[0]); + MEdge e2(*it, _connections[1]); + MEdge e3(*it, _connections[2]); + treat3Connections(gf, *it, e1, e2, e3, _columns, _dirs); } - // STANDARD CASE, one vertex connected to two neighboring vertices - else if(_connections.size() == 2){ - MEdge e1(*it,_connections[0]); - MEdge e2(*it,_connections[1]); - treat2Connections(gf, *it,e1,e2, _columns, _dirs, fan); + // STANDARD CASE, one vertex connected to two neighboring vertices + else if(_connections.size() == 2) { + MEdge e1(*it, _connections[0]); + MEdge e2(*it, _connections[1]); + treat2Connections(gf, *it, e1, e2, _columns, _dirs, fan); } - else if(_connections.size() == 1){ - MEdge e1(*it,_connections[0]); + else if(_connections.size() == 1) { + MEdge e1(*it, _connections[0]); std::vector<SVector3> N1; - std::multimap<MEdge,SVector3,Less_Edge>::iterator itm; - for(itm = _columns->_normals.lower_bound(e1); + std::multimap<MEdge, SVector3, Less_Edge>::iterator itm; + for(itm = _columns->_normals.lower_bound(e1); itm != _columns->_normals.upper_bound(e1); ++itm) N1.push_back(itm->second); - // one point has only one side and one normal : it has to be at the end of the BL - // then, we have the tangent to the connecting edge + // one point has only one side and one normal : it has to be at the end + // of the BL then, we have the tangent to the connecting edge // *it _connections[0] // --------- + ----------- // NO BL BL - if(N1.size() == 1){ - std::vector<MVertex*> Ts; - for(std::multimap<MVertex*,MVertex*>::iterator itm = - tangents.lower_bound(*it); - itm != tangents.upper_bound(*it); ++itm) Ts.push_back(itm->second); + if(N1.size() == 1) { + std::vector<MVertex *> Ts; + for(std::multimap<MVertex *, MVertex *>::iterator itm = + tangents.lower_bound(*it); + itm != tangents.upper_bound(*it); ++itm) + Ts.push_back(itm->second); // end of the BL --> let's add a column that correspond to the // model edge that lies after the end of teh BL - if(Ts.size() == 1){ + if(Ts.size() == 1) { // printf("HERE WE ARE IN FACE %d %d\n",gf->tag(),Ts.size()); - // printf("Classif dim %d %d\n",(*it)->onWhat()->dim(),Ts[0]->onWhat()->dim()); - GEdge *ge = dynamic_cast<GEdge*>(Ts[0]->onWhat()); - GVertex *gv = dynamic_cast<GVertex*>((*it)->onWhat()); - if(ge && gv){ - addColumnAtTheEndOfTheBL(ge,gv,_columns,blf); + // printf("Classif dim %d + // %d\n",(*it)->onWhat()->dim(),Ts[0]->onWhat()->dim()); + GEdge *ge = dynamic_cast<GEdge *>(Ts[0]->onWhat()); + GVertex *gv = dynamic_cast<GVertex *>((*it)->onWhat()); + if(ge && gv) { + addColumnAtTheEndOfTheBL(ge, gv, _columns, blf); } } else { - Msg::Error("Impossible BL Configuration -- One Edge -- Tscp.size() = %d",Ts.size()); + Msg::Error( + "Impossible BL Configuration -- One Edge -- Tscp.size() = %d", + Ts.size()); } } - else if(N1.size() == 2){ - SPoint2 p0,p1; + else if(N1.size() == 2) { + SPoint2 p0, p1; reparamMeshEdgeOnFace(_connections[0], *it, gf, p0, p1); - double alpha1 = atan2(N1[0].y(),N1[0].x()); - double alpha2 = atan2(N1[1].y(),N1[1].x()); - double alpha3 = atan2(p1.y()-p0.y(),p1.x()-p0.x()); - double AMAX = std::max(alpha1,alpha2); - double AMIN = std::min(alpha1,alpha2); - if(alpha3 > AMAX){ + double alpha1 = atan2(N1[0].y(), N1[0].x()); + double alpha2 = atan2(N1[1].y(), N1[1].x()); + double alpha3 = atan2(p1.y() - p0.y(), p1.x() - p0.x()); + double AMAX = std::max(alpha1, alpha2); + double AMIN = std::min(alpha1, alpha2); + if(alpha3 > AMAX) { double temp = AMAX; - AMAX = AMIN + 2*M_PI; + AMAX = AMIN + 2 * M_PI; AMIN = temp; } if(alpha3 < AMIN) { @@ -507,12 +525,13 @@ bool buildAdditionalPoints2D(GFace *gf) AMAX = temp; } double frac = fabs(AMAX - AMIN) / M_PI; - int n = (int)(frac * CTX::instance()->mesh.boundaryLayerFanPoints + 0.5); - int fanSize = fan ? n : 0 ; - if(fan) _columns->addFan(*it,e1,e1,true); - for(int i = -1; i <= fanSize; i++){ - double t = (double)(i + 1)/ (fanSize + 1); - double alpha = t * AMAX + (1.-t) * AMIN; + int n = + (int)(frac * CTX::instance()->mesh.boundaryLayerFanPoints + 0.5); + int fanSize = fan ? n : 0; + if(fan) _columns->addFan(*it, e1, e1, true); + for(int i = -1; i <= fanSize; i++) { + double t = (double)(i + 1) / (fanSize + 1); + double alpha = t * AMAX + (1. - t) * AMIN; SVector3 x(cos(alpha), sin(alpha), 0); x.normalize(); _dirs.push_back(x); @@ -523,7 +542,7 @@ bool buildAdditionalPoints2D(GFace *gf) // if(_dirs.size() > 1)printf("%d directions\n",_dirs.size()); // now create the BL points - for(unsigned int DIR=0;DIR<_dirs.size();DIR++){ + for(unsigned int DIR = 0; DIR < _dirs.size(); DIR++) { SVector3 n = _dirs[DIR]; // < ------------------------------- > // @@ -532,32 +551,34 @@ bool buildAdditionalPoints2D(GFace *gf) // < ------------------------------- > // /* if (endOfTheBL){ - printf("%g %g %d %d %g\n", (*it)->x(), (*it)->y(), DIR, (int)_dirs.size(), - dot(n, dirEndOfBL)); + printf("%g %g %d %d %g\n", (*it)->x(), (*it)->y(), DIR, + (int)_dirs.size(), dot(n, dirEndOfBL)); } */ - if(endOfTheBL && dot(n,dirEndOfBL) > .99){ + if(endOfTheBL && dot(n, dirEndOfBL) > .99) { // printf( "coucou c'est moi\n"); } else { MVertex *first = *it; double hwall; getLocalInfoAtNode(first, blf, hwall); - std::vector<MVertex*> _column; - SPoint2 par = gf->parFromPoint(SPoint3(first->x(),first->y(),first->z())); + std::vector<MVertex *> _column; + SPoint2 par = + gf->parFromPoint(SPoint3(first->x(), first->y(), first->z())); double L = hwall; - while(1){ + while(1) { // printf("L = %g\n",L); if(L > blf->thickness) break; SPoint2 pnew(par.x() + L * n.x(), par.y() + L * n.y()); GPoint pp = gf->point(pnew); - MFaceVertex *_current = new MFaceVertex(pp.x(),pp.y(),pp.z(),gf,pnew.x(),pnew.y()); + MFaceVertex *_current = + new MFaceVertex(pp.x(), pp.y(), pp.z(), gf, pnew.x(), pnew.y()); _current->bl_data = new MVertexBoundaryLayerData; _column.push_back(_current); - int ith = _column.size() ; - L+= hwall * pow(blf->ratio, ith); + int ith = _column.size(); + L += hwall * pow(blf->ratio, ith); } - _columns->addColumn(n,*it, _column /*,_metrics*/); + _columns->addColumn(n, *it, _column /*,_metrics*/); } } } diff --git a/Geo/boundaryLayersData.h b/Geo/boundaryLayersData.h index 3a490ba94167d5013e19f7275465058dc9c09d2b..cb42104d99f9e1cdd318d9e228c54a4124e3f1e3 100644 --- a/Geo/boundaryLayersData.h +++ b/Geo/boundaryLayersData.h @@ -23,11 +23,10 @@ const int USEFANS__ = 1; struct BoundaryLayerData { SVector3 _n; - std::vector<MVertex*> _column; - BoundaryLayerData(){} + std::vector<MVertex *> _column; + BoundaryLayerData() {} BoundaryLayerData(const SVector3 &dir, const std::vector<MVertex *> &column) - : _n(dir) - , _column(column) + : _n(dir), _column(column) { } }; @@ -35,31 +34,35 @@ struct BoundaryLayerData { struct BoundaryLayerFan { MEdge _e1, _e2; bool sense; - BoundaryLayerFan(MEdge e1, MEdge e2 , bool s = true) - : _e1(e1),_e2(e2) , sense (s){} + BoundaryLayerFan(MEdge e1, MEdge e2, bool s = true) + : _e1(e1), _e2(e2), sense(s) + { + } }; struct edgeColumn { const BoundaryLayerData &_c1, &_c2; edgeColumn(const BoundaryLayerData &c1, const BoundaryLayerData &c2) - : _c1(c1), _c2(c2){} + : _c1(c1), _c2(c2) + { + } }; -class BoundaryLayerColumns -{ - std::map<MVertex*, BoundaryLayerFan> _fans; - public: +class BoundaryLayerColumns { + std::map<MVertex *, BoundaryLayerFan> _fans; + +public: // Element columns - std::map<MElement*,MElement*> _toFirst; - std::map<MElement*,std::vector<MElement*> > _elemColumns; - std::map<MFace, GFace*, Less_Face> _inverse_classification; - std::multimap<MVertex*, BoundaryLayerData> _data; - size_t size () const {return _data.size();} - typedef std::multimap<MVertex*,BoundaryLayerData>::iterator iter; - typedef std::map<MVertex*, BoundaryLayerFan>::iterator iterf; - std::multimap<MVertex*, MVertex*> _non_manifold_edges; + std::map<MElement *, MElement *> _toFirst; + std::map<MElement *, std::vector<MElement *> > _elemColumns; + std::map<MFace, GFace *, Less_Face> _inverse_classification; + std::multimap<MVertex *, BoundaryLayerData> _data; + size_t size() const { return _data.size(); } + typedef std::multimap<MVertex *, BoundaryLayerData>::iterator iter; + typedef std::map<MVertex *, BoundaryLayerFan>::iterator iterf; + std::multimap<MVertex *, MVertex *> _non_manifold_edges; std::multimap<MEdge, SVector3, Less_Edge> _normals; - void clearData () + void clearData() { _toFirst.clear(); _elemColumns.clear(); @@ -70,7 +73,7 @@ class BoundaryLayerColumns _elemColumns.clear(); _fans.clear(); } - void clearElementData () + void clearElementData() { _toFirst.clear(); _elemColumns.clear(); @@ -79,11 +82,11 @@ class BoundaryLayerColumns iter end() { return _data.end(); } iterf beginf() { return _fans.begin(); } iterf endf() { return _fans.end(); } - BoundaryLayerColumns (){} + BoundaryLayerColumns() {} inline void addColumn(const SVector3 &dir, MVertex *v, const std::vector<MVertex *> &_column) { - _data.insert (std::make_pair(v, BoundaryLayerData(dir, _column))); + _data.insert(std::make_pair(v, BoundaryLayerData(dir, _column))); } inline void addFan(MVertex *v, MEdge e1, MEdge e2, bool s) { @@ -91,45 +94,46 @@ class BoundaryLayerColumns } inline const BoundaryLayerFan *getFan(MVertex *v) const { - std::map<MVertex*,BoundaryLayerFan>::const_iterator it = _fans.find(v); - if (it != _fans.end()){ - return &it->second; - } - return 0; + std::map<MVertex *, BoundaryLayerFan>::const_iterator it = _fans.find(v); + if(it != _fans.end()) { + return &it->second; + } + return 0; } inline const BoundaryLayerData &getColumn(MVertex *v, MEdge e) const { - std::map<MVertex*,BoundaryLayerFan>::const_iterator it = _fans.find(v); - int N = getNbColumns(v) ; - if (N == 1) return getColumn(v, 0); + std::map<MVertex *, BoundaryLayerFan>::const_iterator it = _fans.find(v); + int N = getNbColumns(v); + if(N == 1) return getColumn(v, 0); Equal_Edge aaa; - if (it != _fans.end()){ - if (aaa(it->second._e1, e)) - return getColumn(v, 0); + if(it != _fans.end()) { + if(aaa(it->second._e1, e)) + return getColumn(v, 0); else - return getColumn(v, N-1); + return getColumn(v, N - 1); } Msg::Error("Cannot handle embedded lines in boundary layers"); static BoundaryLayerData error; return error; } - edgeColumn getColumns(MVertex *v1, MVertex *v2 , int side); + edgeColumn getColumns(MVertex *v1, MVertex *v2, int side); inline int getNbColumns(MVertex *v) const { return _data.count(v); } inline const BoundaryLayerData &getColumn(MVertex *v, int iColumn) const { int count = 0; - for(std::multimap<MVertex*, BoundaryLayerData>::const_iterator itm = - _data.lower_bound(v); itm != _data.upper_bound(v); ++itm){ - if (count++ == iColumn) return itm->second; + for(std::multimap<MVertex *, BoundaryLayerData>::const_iterator itm = + _data.lower_bound(v); + itm != _data.upper_bound(v); ++itm) { + if(count++ == iColumn) return itm->second; } static BoundaryLayerData error; return error; } }; -BoundaryLayerField* getBLField(GModel *gm); -bool buildAdditionalPoints2D(GFace *gf ) ; -bool buildAdditionalPoints3D(GRegion *gr) ; +BoundaryLayerField *getBLField(GModel *gm); +bool buildAdditionalPoints2D(GFace *gf); +bool buildAdditionalPoints3D(GRegion *gr); void buildMeshMetric(GFace *gf, double *uv, SMetric3 &m, double metric[3]); #endif diff --git a/Geo/closestPoint.cpp b/Geo/closestPoint.cpp index a27d6d35fffc6b4a56c913c020049c731cc41dd8..869ae02dccf84e8f842723425ef28ad4c659d6ac 100644 --- a/Geo/closestPoint.cpp +++ b/Geo/closestPoint.cpp @@ -10,18 +10,18 @@ #include <vector> #if defined(HAVE_ANN) -static void oversample (std::vector<SPoint3> &s, double tol) +static void oversample(std::vector<SPoint3> &s, double tol) { std::vector<SPoint3> t; - for (unsigned int i = 1; i < s.size(); i++){ - SPoint3 p0 = s[i-1]; + for(unsigned int i = 1; i < s.size(); i++) { + SPoint3 p0 = s[i - 1]; SPoint3 p1 = s[i]; double d = p0.distance(p1); - int N = (int) (d / tol); + int N = (int)(d / tol); t.push_back(p0); - for (int j = 1; j < N; j++){ - const double xi = (double) j/ N; - t.push_back(p0 + (p1-p0)*xi); + for(int j = 1; j < N; j++) { + const double xi = (double)j / N; + t.push_back(p0 + (p1 - p0) * xi); } t.push_back(p1); } @@ -29,25 +29,25 @@ static void oversample (std::vector<SPoint3> &s, double tol) } #endif -closestPointFinder::closestPointFinder(GEntity *ge, double e) : _tolerance (e) +closestPointFinder::closestPointFinder(GEntity *ge, double e) : _tolerance(e) { #if defined(HAVE_ANN) std::vector<SPoint3> pts; - if (ge->dim() == 1){ + if(ge->dim() == 1) { GEdge *edge = ge->cast2Edge(); - if (edge){ + if(edge) { std::vector<double> ts; - edge->discretize(_tolerance, pts,ts); + edge->discretize(_tolerance, pts, ts); oversample(pts, _tolerance); } - else{ + else { Msg::Error("Can get edge in closestPointFinder"); } } index = new ANNidx[1]; dist = new ANNdist[1]; zeronodes = annAllocPts(pts.size(), 3); - for (unsigned int k = 0; k < pts.size(); k++){ + for(unsigned int k = 0; k < pts.size(); k++) { zeronodes[k][0] = pts[k].x(); zeronodes[k][1] = pts[k].y(); zeronodes[k][2] = pts[k].z(); @@ -58,24 +58,23 @@ closestPointFinder::closestPointFinder(GEntity *ge, double e) : _tolerance (e) #endif } -closestPointFinder::~closestPointFinder () +closestPointFinder::~closestPointFinder() { #if defined(HAVE_ANN) if(kdtree) delete kdtree; if(zeronodes) annDeallocPts(zeronodes); - delete[]index; - delete[]dist; + delete[] index; + delete[] dist; #endif } -SPoint3 closestPointFinder::operator() (const SPoint3 &p) +SPoint3 closestPointFinder::operator()(const SPoint3 &p) { #if defined(HAVE_ANN) - double xyz[3] = {p.x(),p.y(),p.z()}; + double xyz[3] = {p.x(), p.y(), p.z()}; kdtree->annkSearch(xyz, 1, index, dist); - return SPoint3(zeronodes[index[0]][0], - zeronodes[index[0]][1], - zeronodes[index[0]][2]); + return SPoint3(zeronodes[index[0]][0], zeronodes[index[0]][1], + zeronodes[index[0]][2]); #else return p; #endif diff --git a/Geo/closestPoint.h b/Geo/closestPoint.h index 70b32b45e552afefa80785a817e3eda4f1d7e857..7e8a8b85d5fb59b22cf4f0f197d67ecfe8bd6598 100644 --- a/Geo/closestPoint.h +++ b/Geo/closestPoint.h @@ -15,8 +15,7 @@ #include "SPoint3.h" class GEntity; -class closestPointFinder -{ +class closestPointFinder { #if defined(HAVE_ANN) ANNkd_tree *kdtree; ANNpointArray zeronodes; @@ -24,11 +23,12 @@ class closestPointFinder ANNdistArray dist; #endif double _tolerance; - public : - closestPointFinder (GEntity*, double); - ~closestPointFinder (); - SPoint3 operator () (const SPoint3 & p); - inline double tol() const {return _tolerance;} + +public: + closestPointFinder(GEntity *, double); + ~closestPointFinder(); + SPoint3 operator()(const SPoint3 &p); + inline double tol() const { return _tolerance; } }; #endif diff --git a/Geo/closestVertex.cpp b/Geo/closestVertex.cpp index aca32f516673fc9fd9b0642c8455488e70744e9b..da248ff4d526bfe2593b300384f0c40ca76246d2 100644 --- a/Geo/closestVertex.cpp +++ b/Geo/closestVertex.cpp @@ -9,57 +9,55 @@ #include "GFace.h" #include <vector> -closestVertexFinder :: closestVertexFinder (GEntity *ge,bool closure): - nbVtcs(0) { - +closestVertexFinder ::closestVertexFinder(GEntity *ge, bool closure) : nbVtcs(0) +{ #if defined(HAVE_ANN) - - - std::set<MVertex*> vtcs; - ge->addVerticesInSet(vtcs,closure); - + + std::set<MVertex *> vtcs; + ge->addVerticesInSet(vtcs, closure); + nbVtcs = vtcs.size(); - vertex = new MVertex*[nbVtcs]; + vertex = new MVertex *[nbVtcs]; index = new ANNidx[1]; dist = new ANNdist[1]; - - vCoord = annAllocPts(nbVtcs, 3); - + + vCoord = annAllocPts(nbVtcs, 3); + int k = 0; - std::set<MVertex*>::iterator vIter=vtcs.begin(); - for (;vIter!=vtcs.end();++vIter,++k) { - MVertex* mv = *vIter; + std::set<MVertex *>::iterator vIter = vtcs.begin(); + for(; vIter != vtcs.end(); ++vIter, ++k) { + MVertex *mv = *vIter; vCoord[k][0] = mv->x(); vCoord[k][1] = mv->y(); vCoord[k][2] = mv->z(); vertex[k] = mv; } - kdtree = new ANNkd_tree(vCoord,nbVtcs, 3); + kdtree = new ANNkd_tree(vCoord, nbVtcs, 3); #else Msg::Fatal("Gmsh should be compiled using ANN"); #endif } -closestVertexFinder :: ~closestVertexFinder () +closestVertexFinder ::~closestVertexFinder() { #if defined(HAVE_ANN) - if (nbVtcs) { + if(nbVtcs) { delete kdtree; annDeallocPts(vCoord); delete[] vertex; - delete[]index; - delete[]dist; + delete[] index; + delete[] dist; } #endif } -MVertex* closestVertexFinder ::operator() (const SPoint3& p) +MVertex *closestVertexFinder ::operator()(const SPoint3 &p) { #if defined(HAVE_ANN) - if (nbVtcs == 0) return NULL; + if(nbVtcs == 0) return NULL; - double xyz[3] = {p.x(),p.y(),p.z()}; + double xyz[3] = {p.x(), p.y(), p.z()}; kdtree->annkSearch(xyz, 1, index, dist); return vertex[index[0]]; #else @@ -67,26 +65,25 @@ MVertex* closestVertexFinder ::operator() (const SPoint3& p) #endif } - -MVertex* closestVertexFinder ::operator() (const SPoint3& p, - const std::vector<double>& tfo) +MVertex *closestVertexFinder ::operator()(const SPoint3 &p, + const std::vector<double> &tfo) { #if defined(HAVE_ANN) - if (nbVtcs == 0) return NULL; + if(nbVtcs == 0) return NULL; - double ori[4] = {p.x(),p.y(),p.z(),1}; - double xyz[4] = {0,0,0,0}; - if (tfo.size() == 16) { - int idx=0; - for (int i=0;i<4;i++) for (int j=0;j<4;j++) xyz[i] += tfo[idx++] * ori[j]; + double ori[4] = {p.x(), p.y(), p.z(), 1}; + double xyz[4] = {0, 0, 0, 0}; + if(tfo.size() == 16) { + int idx = 0; + for(int i = 0; i < 4; i++) + for(int j = 0; j < 4; j++) xyz[i] += tfo[idx++] * ori[j]; } - else std::memcpy(xyz,ori,3*sizeof(double)); + else + std::memcpy(xyz, ori, 3 * sizeof(double)); kdtree->annkSearch(xyz, 1, index, dist); return vertex[index[0]]; #else return NULL; #endif } - - diff --git a/Geo/closestVertex.h b/Geo/closestVertex.h index df2a80d4dc4bc020d987532f25633191477d2c36..1ba8e7a460e4bd73d7fa985f6910cdca3ab7db7a 100644 --- a/Geo/closestVertex.h +++ b/Geo/closestVertex.h @@ -23,29 +23,27 @@ class MVertex; // object for locating closest mesh (principal) vertex on the entity, // in/excluding the closure -class closestVertexFinder -{ +class closestVertexFinder { #if defined(HAVE_ANN) ANNkd_tree *kdtree; ANNpointArray vCoord; ANNidxArray index; ANNdistArray dist; - MVertex** vertex; + MVertex **vertex; #endif unsigned int nbVtcs; -public : - closestVertexFinder (GEntity* ge,bool includeClosure); - ~closestVertexFinder (); +public: + closestVertexFinder(GEntity *ge, bool includeClosure); + ~closestVertexFinder(); // find closest vertex for given point - MVertex* operator() (const SPoint3& p); + MVertex *operator()(const SPoint3 &p); // find closest vertex for transformation of given point - MVertex* operator() (const SPoint3& p,const std::vector<double>& tfo); - - unsigned int getNbVtcs() const {return nbVtcs;} + MVertex *operator()(const SPoint3 &p, const std::vector<double> &tfo); + unsigned int getNbVtcs() const { return nbVtcs; } }; #endif diff --git a/Geo/discreteDiskFace.h b/Geo/discreteDiskFace.h index 274877fe220656f7ad014b696301d96e137d5d62..95753423c27a4e1b261ed654961cd15ecc79b353 100644 --- a/Geo/discreteDiskFace.h +++ b/Geo/discreteDiskFace.h @@ -26,29 +26,25 @@ #include "linearSystemCSR.h" #include "dofManager.h" - -inline int nodeLocalNum(MElement* e, MVertex* v) +inline int nodeLocalNum(MElement *e, MVertex *v) { - for(int i=0; i<e->getNumVertices(); i++) - if (v == e->getVertex(i)) - return i; + for(int i = 0; i < e->getNumVertices(); i++) + if(v == e->getVertex(i)) return i; return -1; } -inline int edgeLocalNum(MElement* e, MEdge ed) +inline int edgeLocalNum(MElement *e, MEdge ed) { - for(int i=0; i<e->getNumEdges(); i++) - if (ed == e->getEdge(i)) - return i; + for(int i = 0; i < e->getNumEdges(); i++) + if(ed == e->getEdge(i)) return i; return -1; } -inline MEdge maxEdge(MElement* e) +inline MEdge maxEdge(MElement *e) { MEdge maxEd = e->getEdge(0); - for(int i=0; i<e->getNumEdges(); i++) - if (maxEd.length() < e->getEdge(i).length()) - maxEd = e->getEdge(i); + for(int i = 0; i < e->getNumEdges(); i++) + if(maxEd.length() < e->getEdge(i).length()) maxEd = e->getEdge(i); return maxEd; } @@ -56,129 +52,135 @@ class ANNkd_tree; class Octree; class GRbf; -// compute dummy attributes of any conformal (linear~straighted-sided) triangulation +// compute dummy attributes of any conformal (linear~straighted-sided) +// triangulation class triangulation { - - public: - +public: // attributes int idNum, iter; // number of identification, for hashing purposes - std::vector<MElement*> tri;// trianglse - GFace* gf; + std::vector<MElement *> tri; // trianglse + GFace *gf; double maxD; bool seamPoint; - std::set<MVertex*> vert;// nodes + std::set<MVertex *> vert; // nodes // edge to 1 or 2 triangle(s), their num into the vector of MElement* - std::map<MEdge,std::vector<int>,Less_Edge> ed2tri; - std::map<double,std::vector<MVertex*> > bord; //border(s) #todo |-> std::vector - std::set<MEdge,Less_Edge> borderEdg; // border edges #todo |-> std::vector + std::map<MEdge, std::vector<int>, Less_Edge> ed2tri; + std::map<double, std::vector<MVertex *> > + bord; // border(s) #todo |-> std::vector + std::set<MEdge, Less_Edge> borderEdg; // border edges #todo |-> std::vector - std::list<GEdge*> my_GEdges; - std::set<int> fillingHoles; // obsolete ? /!\ used within discreteDiskFace class + std::list<GEdge *> my_GEdges; + std::set<int> + fillingHoles; // obsolete ? /!\ used within discreteDiskFace class //---- methods - double geodesicDistance ();// prototype here + double geodesicDistance(); // prototype here double aspectRatio() { double L = bord.rbegin()->first; - if (L == 0.0)return 1.e22; // #mark shoudn't we throw instead ? - if (maxD < 0) maxD = geodesicDistance(); + if(L == 0.0) return 1.e22; // #mark shoudn't we throw instead ? + if(maxD < 0) maxD = geodesicDistance(); return maxD / L; } int genus() // dummy formula for Chi { - return ( ed2tri.size() - vert.size() - tri.size() + 2 - bord.size() )/2; + return (ed2tri.size() - vert.size() - tri.size() + 2 - bord.size()) / 2; } void assignVert() { - for(unsigned int i = 0; i < tri.size(); ++i){ - MElement* t = tri[i]; + for(unsigned int i = 0; i < tri.size(); ++i) { + MElement *t = tri[i]; SPoint3 P[3]; - for(int j = 0; j < t->getNumVertices() ; j++){ - MVertex* tv = t->getVertex(j); - if(j<3) - P[j].setPosition(tv->x(),tv->y(),tv->z()); - std::set<MVertex*>::iterator it = vert.find(tv); - if (it == vert.end()) vert.insert (tv); + for(int j = 0; j < t->getNumVertices(); j++) { + MVertex *tv = t->getVertex(j); + if(j < 3) P[j].setPosition(tv->x(), tv->y(), tv->z()); + std::set<MVertex *>::iterator it = vert.find(tv); + if(it == vert.end()) vert.insert(tv); } } } void assignEd2tri() { - for(unsigned int i = 0; i < tri.size(); ++i){ + for(unsigned int i = 0; i < tri.size(); ++i) { MElement *t = tri[i]; - for(int j = 0; j < 3 ; j++){ - MEdge ed = t->getEdge(j); - ed2tri[ed].push_back(i); + for(int j = 0; j < 3; j++) { + MEdge ed = t->getEdge(j); + ed2tri[ed].push_back(i); } } } void assignBord() { - for(unsigned int i = 0; i < tri.size(); ++i){ + for(unsigned int i = 0; i < tri.size(); ++i) { MElement *t = tri[i]; - for(int j = 0; j < t->getNumEdges() ; j++){ - MEdge ed = t->getEdge(j); - std::set<MEdge,Less_Edge>::iterator it = borderEdg.find(ed); - if (it == borderEdg.end()) borderEdg.insert(ed); - else borderEdg.erase(it); + for(int j = 0; j < t->getNumEdges(); j++) { + MEdge ed = t->getEdge(j); + std::set<MEdge, Less_Edge>::iterator it = borderEdg.find(ed); + if(it == borderEdg.end()) + borderEdg.insert(ed); + else + borderEdg.erase(it); } } - std::map<MVertex*,std::vector<MVertex*> > firstNode2Edge; - for (std::set<MEdge>::iterator ie = borderEdg.begin(); ie != borderEdg.end() ; ++ie) { + std::map<MVertex *, std::vector<MVertex *> > firstNode2Edge; + for(std::set<MEdge>::iterator ie = borderEdg.begin(); ie != borderEdg.end(); + ++ie) { MEdge ed = *ie; const std::vector<int> &nT = ed2tri[ed]; - MElement* t = tri[nT[0]]; + MElement *t = tri[nT[0]]; - std::vector<MVertex*> vecver; - t->getEdgeVertices(edgeLocalNum(t,ed),vecver); + std::vector<MVertex *> vecver; + t->getEdgeVertices(edgeLocalNum(t, ed), vecver); MVertex *first = vecver[0]; MVertex *last = vecver[1]; vecver.erase(vecver.begin()); vecver.erase(vecver.begin()); - std::map<MVertex*,std::vector<MVertex*> >::iterator im = firstNode2Edge.find(first); - if (im != firstNode2Edge.end()){ + std::map<MVertex *, std::vector<MVertex *> >::iterator im = + firstNode2Edge.find(first); + if(im != firstNode2Edge.end()) { Msg::Info("Assumed seam point for discreteFace %d", gf->tag()); - seamPoint = true; - break; + seamPoint = true; + break; } firstNode2Edge[first] = vecver; firstNode2Edge[first].push_back(last); } - while (!firstNode2Edge.empty()&&!seamPoint) { - std::vector<MVertex*> loop; + while(!firstNode2Edge.empty() && !seamPoint) { + std::vector<MVertex *> loop; double length = 0.; - std::map<MVertex*,std::vector<MVertex*> >::iterator in = firstNode2Edge.begin(); - MVertex* previous = in->first; + std::map<MVertex *, std::vector<MVertex *> >::iterator in = + firstNode2Edge.begin(); + MVertex *previous = in->first; while(in != firstNode2Edge.end()) { // it didn't find it - const std::vector<MVertex*> &myV = in->second; - for(unsigned int i=0; i<myV.size(); i++){ - loop.push_back(previous); - MVertex* current = myV[i]; - length += sqrt( (current->x()-previous->x()) * (current->x()-previous->x()) + - (current->y()-previous->y()) * (current->y()-previous->y()) + - (current->z()-previous->z()) * (current->z()-previous->z()) ); - - previous = current; - } - firstNode2Edge.erase(in); - in = firstNode2Edge.find(previous); - }// end while in - bord.insert(std::make_pair(length,loop)); + const std::vector<MVertex *> &myV = in->second; + for(unsigned int i = 0; i < myV.size(); i++) { + loop.push_back(previous); + MVertex *current = myV[i]; + length += sqrt( + (current->x() - previous->x()) * (current->x() - previous->x()) + + (current->y() - previous->y()) * (current->y() - previous->y()) + + (current->z() - previous->z()) * (current->z() - previous->z())); + + previous = current; + } + firstNode2Edge.erase(in); + in = firstNode2Edge.find(previous); + } // end while in + bord.insert(std::make_pair(length, loop)); // it shouldn't be possible to have twice the same length ? actually, it // is possible, but quite seldom #fixme ----> multimap ? } // end while firstNode2Edge - }// end method + } // end method void assign() { @@ -189,24 +191,29 @@ class triangulation { maxD = -1.e22; } - void print (char *name, int elementary) const { - FILE *f = fopen (name,"w"); - fprintf(f,"View \"\"{\n"); - for (unsigned int i=0;i<tri.size();i++){ - tri[i]->writePOS(f,true,false,false,false,false,false, 1.0, elementary); + void print(char *name, int elementary) const + { + FILE *f = fopen(name, "w"); + fprintf(f, "View \"\"{\n"); + for(unsigned int i = 0; i < tri.size(); i++) { + tri[i]->writePOS(f, true, false, false, false, false, false, 1.0, + elementary); } - fprintf(f,"};\n"); + fprintf(f, "};\n"); fclose(f); } triangulation() : gf(0) {} - triangulation(int id, const std::vector<MElement*> &input, GFace* gface) - : idNum(id), tri(input), gf(gface){ assign(); } + triangulation(int id, const std::vector<MElement *> &input, GFace *gface) + : idNum(id), tri(input), gf(gface) + { + assign(); + } }; // triangles in the physical space xyz, with their parametric coordinates -class discreteDiskFaceTriangle { - public: +class discreteDiskFaceTriangle { +public: std::vector<SPoint3> p; // vertices in (u;v) GFace *gf; // GFace tag MElement *tri; // mesh triangle in (x;y;z) @@ -215,57 +222,58 @@ class discreteDiskFaceTriangle { class discreteDiskFace : public GFace { GFace *_parent; - void buildOct(std::vector<GFace*> *CAD = NULL) const; + void buildOct(std::vector<GFace *> *CAD = NULL) const; bool parametrize() const; bool checkOrientationUV(); void optimize(); - public: - discreteDiskFace(GFace *parent, triangulation* diskTriangulation, - int p=1, std::vector<GFace*> *CAD = NULL); +public: + discreteDiskFace(GFace *parent, triangulation *diskTriangulation, int p = 1, + std::vector<GFace *> *CAD = NULL); virtual ~discreteDiskFace(); - void getTriangleUV(const double u,const double v,discreteDiskFaceTriangle **mt, - double &_u, double &_v) const; + void getTriangleUV(const double u, const double v, + discreteDiskFaceTriangle **mt, double &_u, + double &_v) const; using GFace::point; GPoint point(double par1, double par2) const; SPoint2 parFromVertex(MVertex *v) const; - SVector3 normal(const SPoint2&) const; - double curvatureMax(const SPoint2&) const; + SVector3 normal(const SPoint2 &) const; + double curvatureMax(const SPoint2 &) const; virtual Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m) const; - virtual void secondDer(const SPoint2 ¶m, - SVector3 *dudu, SVector3 *dvdv, SVector3 *dudv) const; + virtual void secondDer(const SPoint2 ¶m, SVector3 *dudu, SVector3 *dvdv, + SVector3 *dudv) const; GEntity::GeomType geomType() const { return DiscreteDiskSurface; } GPoint intersectionWithCircle(const SVector3 &n1, const SVector3 &n2, - const SVector3 &p, const double &d, - double uv[2]) const; + const SVector3 &p, const double &d, + double uv[2]) const; GPoint intersectionWithCircle2(const SVector3 &n1, const SVector3 &n2, - const SVector3 &p, const double &d, - double uv[2]) const; - void printAtlasMesh () ; - void printParamMesh () ; - void putOnView(int iFace, int iMap, bool,bool); - - std::vector<MElement*> discrete_triangles; - protected: + const SVector3 &p, const double &d, + double uv[2]) const; + void printAtlasMesh(); + void printParamMesh(); + void putOnView(int iFace, int iMap, bool, bool); + + std::vector<MElement *> discrete_triangles; + +protected: // a copy of the mesh that should not be destroyed - triangulation* initialTriangulation; - triangulation* geoTriangulation;// parametrized triangulation - std::vector<MVertex*> discrete_vertices; + triangulation *initialTriangulation; + triangulation *geoTriangulation; // parametrized triangulation + std::vector<MVertex *> discrete_vertices; int _order; - int _n;// number of dof's for a triangle + int _n; // number of dof's for a triangle double _totLength; - std::map<double,std::vector<MVertex*> > _loops; - std::vector<MVertex*> _U0; // dirichlet's bc's - mutable std::set<MVertex*> allNodes; - mutable std::map<MVertex*, SPoint3> coordinates; - mutable std::map<SPoint3,SPoint3 > _coordPoints; + std::map<double, std::vector<MVertex *> > _loops; + std::vector<MVertex *> _U0; // dirichlet's bc's + mutable std::set<MVertex *> allNodes; + mutable std::map<MVertex *, SPoint3> coordinates; + mutable std::map<SPoint3, SPoint3> _coordPoints; mutable v2t_cont adjv; - mutable std::map<MVertex*, Pair<SVector3,SVector3> > firstDerivatives; + mutable std::map<MVertex *, Pair<SVector3, SVector3> > firstDerivatives; mutable discreteDiskFaceTriangle *_ddft; mutable Octree *oct; mutable std::vector<double> _coords; - }; #endif diff --git a/Geo/discreteEdge.cpp b/Geo/discreteEdge.cpp index db596b6f400e008f3f623c300a572f8db92c1c7f..2b255fe48607496e49ec4d724c3bfb37c029d228 100644 --- a/Geo/discreteEdge.cpp +++ b/Geo/discreteEdge.cpp @@ -25,8 +25,7 @@ discreteEdge::discreteEdge(GModel *model, int num, GVertex *_v0, GVertex *_v1) CreateReversedCurve(c); } -discreteEdge::discreteEdge(GModel *model, int num) -: GEdge(model, num) +discreteEdge::discreteEdge(GModel *model, int num) : GEdge(model, num) { Curve *c = CreateCurve(num, MSH_SEGM_DISCRETE, 0, 0, 0, -1, -1, 0., 1.); Tree_Add(model->getGEOInternals()->Curves, &c); @@ -35,8 +34,10 @@ discreteEdge::discreteEdge(GModel *model, int num) discreteEdge::~discreteEdge() { - for (unsigned int i=0 ; i<discrete_lines.size(); i++)delete discrete_lines[i]; - for (unsigned int i=0 ; i<discrete_vertices.size(); i++)delete discrete_vertices[i]; + for(unsigned int i = 0; i < discrete_lines.size(); i++) + delete discrete_lines[i]; + for(unsigned int i = 0; i < discrete_vertices.size(); i++) + delete discrete_vertices[i]; discrete_lines.clear(); discrete_vertices.clear(); } @@ -45,53 +46,56 @@ void discreteEdge::orderMLines() { size_t ss = lines.size(); std::vector<MEdge> ed; - std::vector<std::vector<MVertex*> >vs; - for (unsigned int i = 0; i < lines.size(); i++) { - ed.push_back(MEdge(lines[i]->getVertex(0),lines[i]->getVertex(1))); + std::vector<std::vector<MVertex *> > vs; + for(unsigned int i = 0; i < lines.size(); i++) { + ed.push_back(MEdge(lines[i]->getVertex(0), lines[i]->getVertex(1))); delete lines[i]; } lines.clear(); - if (!SortEdgeConsecutive (ed,vs)) - Msg::Warning ("Discrete edge segments cannot be ordered"); + if(!SortEdgeConsecutive(ed, vs)) + Msg::Warning("Discrete edge segments cannot be ordered"); - if (vs.size() != 1) - Msg::Warning ("Discrete Edge %d is mutiply connected",tag()); + if(vs.size() != 1) + Msg::Warning("Discrete Edge %d is mutiply connected", tag()); unsigned int START = 0; - for ( ; START < vs[0].size(); START++) if (vs[0][START]->onWhat()->dim() == 0) break; + for(; START < vs[0].size(); START++) + if(vs[0][START]->onWhat()->dim() == 0) break; - if (START == vs[0].size()) - Msg::Warning ("Discrete Edge %d topology is wrong",tag()); + if(START == vs[0].size()) + Msg::Warning("Discrete Edge %d topology is wrong", tag()); unsigned int i = START; - while (lines.size() != ss){ - if (vs[0][i% vs[0].size()] != vs[0][(i+1)% vs[0].size()]) - lines.push_back(new MLine(vs[0][i% vs[0].size()],vs[0][(i+1)% vs[0].size()])); + while(lines.size() != ss) { + if(vs[0][i % vs[0].size()] != vs[0][(i + 1) % vs[0].size()]) + lines.push_back( + new MLine(vs[0][i % vs[0].size()], vs[0][(i + 1) % vs[0].size()])); i++; } mesh_vertices.clear(); - for (unsigned int i = 0; i < lines.size()-1; ++i){ + for(unsigned int i = 0; i < lines.size() - 1; ++i) { MVertex *v11 = lines[i]->getVertex(1); mesh_vertices.push_back(v11); } - GVertex *g0 = static_cast<GVertex*>(lines[0]->getVertex(0)->onWhat()); - if (!g0)Msg::Error ("Compound Edge with non consecutive lines"); - GVertex *g1 = static_cast<GVertex*>(lines[lines.size()-1]->getVertex(1)->onWhat()); - if (!g1)Msg::Error ("Compound Edge with non consecutive lines"); - setBeginVertex (g0); - setEndVertex (g1); + GVertex *g0 = static_cast<GVertex *>(lines[0]->getVertex(0)->onWhat()); + if(!g0) Msg::Error("Compound Edge with non consecutive lines"); + GVertex *g1 = + static_cast<GVertex *>(lines[lines.size() - 1]->getVertex(1)->onWhat()); + if(!g1) Msg::Error("Compound Edge with non consecutive lines"); + setBeginVertex(g0); + setEndVertex(g1); } bool discreteEdge::getLocalParameter(const double &t, int &iLine, double &tLoc) const { - for (iLine = 0; iLine < (int)discrete_lines.size(); iLine++){ + for(iLine = 0; iLine < (int)discrete_lines.size(); iLine++) { double tmin = _pars[iLine]; - double tmax = _pars[iLine+1]; - if (t >= tmin && t <= tmax){ - tLoc = (t-tmin)/(tmax-tmin); + double tmax = _pars[iLine + 1]; + if(t >= tmin && t <= tmax) { + tLoc = (t - tmin) / (tmax - tmin); return true; } } @@ -110,16 +114,15 @@ GPoint discreteEdge::point(double par) const MVertex *vE = discrete_lines[iEdge]->getVertex(1); if(!vB || !vE) return GPoint(); - //linear Lagrange mesh - x = vB->x() + tLoc * (vE->x()- vB->x()); - y = vB->y() + tLoc * (vE->y()- vB->y()); - z = vB->z() + tLoc * (vE->z()- vB->z()); - return GPoint(x,y,z,this,par); + // linear Lagrange mesh + x = vB->x() + tLoc * (vE->x() - vB->x()); + y = vB->y() + tLoc * (vE->y() - vB->y()); + z = vB->z() + tLoc * (vE->z() - vB->z()); + return GPoint(x, y, z, this, par); } SVector3 discreteEdge::firstDer(double par) const { - double tLoc; int iEdge; @@ -130,11 +133,10 @@ SVector3 discreteEdge::firstDer(double par) const if(!vB || !vE) return SVector3(); - double dx, dy, dz; - dx = (vE->x() - vB->x());// / dt; - dy = (vE->y() - vB->y());// / dt; - dz = (vE->z() - vB->z());// / dt; + dx = (vE->x() - vB->x()); // / dt; + dy = (vE->y() - vB->y()); // / dt; + dz = (vE->z() - vB->z()); // / dt; SVector3 der(dx, dy, dz); return der; @@ -153,40 +155,38 @@ Range<double> discreteEdge::parBounds(int i) const void discreteEdge::createGeometry() { - if (discrete_lines.empty()){ - + if(discrete_lines.empty()) { orderMLines(); bool reverse = lines[0]->getVertex(0) == getEndVertex()->mesh_vertices[0]; - std::map<MVertex*,MVertex*> old2new; + std::map<MVertex *, MVertex *> old2new; - for (unsigned int i = 0; i < lines.size(); i++){ - for (unsigned int j = 0; j < 2; j++){ - MVertex *v = lines[i]->getVertex(j); - if (old2new.find(v) == old2new.end()){ - MVertex *vnew = new MVertex(v->x(), v->y(),v->z(), this); - old2new[v] = vnew; - } + for(unsigned int i = 0; i < lines.size(); i++) { + for(unsigned int j = 0; j < 2; j++) { + MVertex *v = lines[i]->getVertex(j); + if(old2new.find(v) == old2new.end()) { + MVertex *vnew = new MVertex(v->x(), v->y(), v->z(), this); + old2new[v] = vnew; + } } } - std::vector<MLine*> _temp; + std::vector<MLine *> _temp; discrete_lines.resize(lines.size()); - for (unsigned int i = 0; i < lines.size(); i++){ + for(unsigned int i = 0; i < lines.size(); i++) { MVertex *v0 = lines[i]->getVertex(0); MVertex *v1 = lines[i]->getVertex(1); MVertex *v00 = old2new[v0]; MVertex *v01 = old2new[v1]; - if (reverse) - discrete_lines[lines.size() - i - 1] = new MLine(v01,v00); + if(reverse) + discrete_lines[lines.size() - i - 1] = new MLine(v01, v00); else - discrete_lines[i] = new MLine(v00,v01); - + discrete_lines[i] = new MLine(v00, v01); } // compute parameters and recompute the vertices _pars.push_back(0.0); - for (unsigned int i = 1; i < discrete_lines.size(); i++){ + for(unsigned int i = 1; i < discrete_lines.size(); i++) { _pars.push_back((double)i); MVertex *newv = discrete_lines[i]->getVertex(0); discrete_vertices.push_back(newv); @@ -200,7 +200,7 @@ void discreteEdge::createGeometry() void discreteEdge::mesh(bool verbose) { #if defined(HAVE_MESH) - if (discrete_lines.empty()) return; + if(discrete_lines.empty()) return; meshGEdge mesher; mesher(this); #endif @@ -208,7 +208,7 @@ void discreteEdge::mesh(bool verbose) void discreteEdge::writeGEO(FILE *fp) { - if (getBeginVertex() && getEndVertex()) + if(getBeginVertex() && getEndVertex()) fprintf(fp, "Discrete Line(%d) = {%d,%d};\n", tag(), getBeginVertex()->tag(), getEndVertex()->tag()); } diff --git a/Geo/discreteEdge.h b/Geo/discreteEdge.h index 48edd5fae1e00e196cb981a93a97a0aa78779679..581576203da531e32517ce8a91d5b1683472a1dc 100644 --- a/Geo/discreteEdge.h +++ b/Geo/discreteEdge.h @@ -11,13 +11,14 @@ #include "discreteVertex.h" class discreteEdge : public GEdge { - protected: +protected: std::vector<double> _pars; - std::vector<MVertex*> discrete_vertices; - std::vector<MLine*> discrete_lines; + std::vector<MVertex *> discrete_vertices; + std::vector<MLine *> discrete_lines; void orderMLines(); bool getLocalParameter(const double &t, int &iEdge, double &tLoc) const; - public: + +public: discreteEdge(GModel *model, int num, GVertex *_v0, GVertex *_v1); discreteEdge(GModel *model, int num); virtual ~discreteEdge(); @@ -25,12 +26,12 @@ class discreteEdge : public GEdge { virtual GPoint point(double p) const; virtual SVector3 firstDer(double par) const; virtual double curvature(double par) const; - virtual bool haveParametrization(){ return !_pars.empty(); } + virtual bool haveParametrization() { return !_pars.empty(); } virtual Range<double> parBounds(int) const; void createGeometry(); - virtual void mesh(bool verbose) ; + virtual void mesh(bool verbose); void writeGEO(FILE *fp); - int minimumDrawSegments() const {return 2*_pars.size();} + int minimumDrawSegments() const { return 2 * _pars.size(); } }; #endif diff --git a/Geo/discreteFace.cpp b/Geo/discreteFace.cpp index f6c6d2fc32c833b24c7039af0b33f2a1952484c1..8a1661ed279274362065a8116ba493e2c45e81d6 100644 --- a/Geo/discreteFace.cpp +++ b/Geo/discreteFace.cpp @@ -15,8 +15,7 @@ #include "MElementOctree.h" #include "Octree.h" -discreteFace::discreteFace(GModel *model, int num) - : GFace(model, num) +discreteFace::discreteFace(GModel *model, int num) : GFace(model, num) { Surface *s = CreateSurface(num, MSH_SURF_DISCRETE); Tree_Add(model->getGEOInternals()->Surfaces, &s); @@ -25,14 +24,14 @@ discreteFace::discreteFace(GModel *model, int num) void discreteFace::setBoundEdges(const std::vector<int> &tagEdges) { - for (unsigned int i = 0; i != tagEdges.size(); i++){ + for(unsigned int i = 0; i != tagEdges.size(); i++) { GEdge *ge = model()->getEdgeByTag(tagEdges[i]); - if(ge){ + if(ge) { l_edges.push_back(ge); l_dirs.push_back(1); ge->addFace(this); } - else{ + else { Msg::Error("Unknown model edge %d", tagEdges[i]); } } @@ -41,48 +40,46 @@ void discreteFace::setBoundEdges(const std::vector<int> &tagEdges) void discreteFace::setBoundEdges(const std::vector<int> &tagEdges, const std::vector<int> &signEdges) { - if(signEdges.size() != tagEdges.size()){ + if(signEdges.size() != tagEdges.size()) { Msg::Error("Wrong number of edge signs in setBoundEdges"); setBoundEdges(tagEdges); } - for (std::vector<int>::size_type i = 0; i != tagEdges.size(); i++){ + for(std::vector<int>::size_type i = 0; i != tagEdges.size(); i++) { GEdge *ge = model()->getEdgeByTag(tagEdges[i]); - if(ge){ + if(ge) { l_edges.push_back(ge); l_dirs.push_back(signEdges[i]); ge->addFace(this); } - else{ + else { Msg::Error("Unknown model edge %d", tagEdges[i]); } } } - -// split old GEdge's + // split old GEdge's #ifdef HAVE_HXT -static void splitDiscreteEdge(GEdge *de , MVertex *v, GVertex *gv, int &TAG) +static void splitDiscreteEdge(GEdge *de, MVertex *v, GVertex *gv, int &TAG) { GVertex *gv0 = de->getBeginVertex(); GVertex *gv1 = de->getEndVertex(); - if (v != gv->mesh_vertices[0])Msg::Error ("Error in splitDiscreteEdge"); + if(v != gv->mesh_vertices[0]) Msg::Error("Error in splitDiscreteEdge"); - discreteEdge *de_new[2] ={ - new discreteEdge (de->model(),++TAG,gv0,gv), - new discreteEdge (de->model(),++TAG,gv,gv1) - }; + discreteEdge *de_new[2] = {new discreteEdge(de->model(), ++TAG, gv0, gv), + new discreteEdge(de->model(), ++TAG, gv, gv1)}; int current = 0; de_new[current]->lines.push_back(de->lines[0]); - for (size_t i=0 ; i<de->mesh_vertices.size(); i++){ - if (de->mesh_vertices[i] == v)current++; + for(size_t i = 0; i < de->mesh_vertices.size(); i++) { + if(de->mesh_vertices[i] == v) + current++; else { de_new[current]->mesh_vertices.push_back(de->mesh_vertices[i]); de->mesh_vertices[i]->setEntity(de_new[current]); } - de_new[current]->lines.push_back(de->lines[i+1]); + de_new[current]->lines.push_back(de->lines[i + 1]); } de->lines.clear(); de->mesh_vertices.clear(); @@ -94,26 +91,31 @@ static void splitDiscreteEdge(GEdge *de , MVertex *v, GVertex *gv, int &TAG) void discreteFace::writeGEO(FILE *fp) { - fprintf(fp, "Discrete Face(%d) = {",tag()); + fprintf(fp, "Discrete Face(%d) = {", tag()); int count = 0; - for (std::vector<GEdge*>::const_iterator it = l_edges.begin(); - it != l_edges.end() ;++it){ - if (count == 0) fprintf(fp, "%d", (*it)->tag()); - else fprintf(fp, ",%d", (*it)->tag()); - count ++; + for(std::vector<GEdge *>::const_iterator it = l_edges.begin(); + it != l_edges.end(); ++it) { + if(count == 0) + fprintf(fp, "%d", (*it)->tag()); + else + fprintf(fp, ",%d", (*it)->tag()); + count++; } fprintf(fp, "};\n"); } -int discreteFace::trianglePosition(double par1, double par2, double &u, double &v) const +int discreteFace::trianglePosition(double par1, double par2, double &u, + double &v) const { #ifdef HAVE_HXT - double xy[3]={par1,par2,0}; + double xy[3] = {par1, par2, 0}; double uv[3]; - const MElement *e = _parametrizations[_current_parametrization].oct->find(par1,par2,0.0); - if (!e)return -1; - e->xyz2uvw(xy,uv); - int position = (int)((MTriangle*)e - &_parametrizations[_current_parametrization].t2d[0]); + const MElement *e = + _parametrizations[_current_parametrization].oct->find(par1, par2, 0.0); + if(!e) return -1; + e->xyz2uvw(xy, uv); + int position = + (int)((MTriangle *)e - &_parametrizations[_current_parametrization].t2d[0]); u = uv[0]; v = uv[1]; return position; @@ -125,79 +127,81 @@ int discreteFace::trianglePosition(double par1, double par2, double &u, double & GPoint discreteFace::point(double par1, double par2) const { #ifdef HAVE_HXT - double xy[3]={par1,par2,0}; + double xy[3] = {par1, par2, 0}; double uv[3]; - const MElement *e = _parametrizations[_current_parametrization].oct->find(par1,par2,0.0); - if (!e){ - GPoint gp = GPoint(1.e21,1.e21,1.e21,this,xy); + const MElement *e = + _parametrizations[_current_parametrization].oct->find(par1, par2, 0.0); + if(!e) { + GPoint gp = GPoint(1.e21, 1.e21, 1.e21, this, xy); gp.setNoSuccess(); return gp; } - e->xyz2uvw(xy,uv); - int position = (int)((MTriangle*)e - &_parametrizations[_current_parametrization].t2d[0]); - const MTriangle &t3d = _parametrizations[_current_parametrization].t3d[position]; - - double X=0,Y=0,Z=0; - double eval[3] = {1.-uv[0]-uv[1],uv[0],uv[1]}; - - for(int io=0; io<3; io++){ - X += t3d.getVertex(io)->x()*eval[io]; - Y += t3d.getVertex(io)->y()*eval[io]; - Z += t3d.getVertex(io)->z()*eval[io]; + e->xyz2uvw(xy, uv); + int position = + (int)((MTriangle *)e - &_parametrizations[_current_parametrization].t2d[0]); + const MTriangle &t3d = + _parametrizations[_current_parametrization].t3d[position]; + + double X = 0, Y = 0, Z = 0; + double eval[3] = {1. - uv[0] - uv[1], uv[0], uv[1]}; + + for(int io = 0; io < 3; io++) { + X += t3d.getVertex(io)->x() * eval[io]; + Y += t3d.getVertex(io)->y() * eval[io]; + Z += t3d.getVertex(io)->z() * eval[io]; } - return GPoint(X,Y,Z,this,xy); + return GPoint(X, Y, Z, this, xy); #else Msg::Error("Cannot evaluate point on discrete face without HXT"); return GPoint(); #endif } -class dfWrapper{ - public: +class dfWrapper { +public: SPoint3 _p; double _distance; SPoint3 _closestPoint; - MTriangle *_t3d,*_t2d; - dfWrapper(const SPoint3 &p) - : _p(p) , _distance (1.e22) , _t3d(NULL), _t2d(NULL){} + MTriangle *_t3d, *_t2d; + dfWrapper(const SPoint3 &p) : _p(p), _distance(1.e22), _t3d(NULL), _t2d(NULL) + { + } }; #ifdef HAVE_HXT static SVector3 _NORMAL_(const MTriangle &t3d) { - - SVector3 v31 (t3d.getVertex(2)->x() - t3d.getVertex(0)->x(), - t3d.getVertex(2)->y() - t3d.getVertex(0)->y(), - t3d.getVertex(2)->z() - t3d.getVertex(0)->z()); - SVector3 v21 (t3d.getVertex(1)->x() - t3d.getVertex(0)->x(), - t3d.getVertex(1)->y() - t3d.getVertex(0)->y(), - t3d.getVertex(1)->z() - t3d.getVertex(0)->z()); - SVector3 n = crossprod(v31,v21); + SVector3 v31(t3d.getVertex(2)->x() - t3d.getVertex(0)->x(), + t3d.getVertex(2)->y() - t3d.getVertex(0)->y(), + t3d.getVertex(2)->z() - t3d.getVertex(0)->z()); + SVector3 v21(t3d.getVertex(1)->x() - t3d.getVertex(0)->x(), + t3d.getVertex(1)->y() - t3d.getVertex(0)->y(), + t3d.getVertex(1)->z() - t3d.getVertex(0)->z()); + SVector3 n = crossprod(v31, v21); n.normalize(); return n; } #endif -bool discreteFace_rtree_callback(std::pair<MTriangle*,MTriangle*> *t,void* w) +bool discreteFace_rtree_callback(std::pair<MTriangle *, MTriangle *> *t, + void *w) { - dfWrapper* wrapper = static_cast<dfWrapper*>(w); + dfWrapper *wrapper = static_cast<dfWrapper *>(w); SPoint3 closePt; double d; // printf("distance %p %p\n", t->first, t->second); - signedDistancePointTriangle(SPoint3 (t->first->getVertex(0)->x(), - t->first->getVertex(0)->y(), - t->first->getVertex(0)->z()), - SPoint3 (t->first->getVertex(1)->x(), - t->first->getVertex(1)->y(), - t->first->getVertex(1)->z()), - SPoint3 (t->first->getVertex(2)->x(), - t->first->getVertex(2)->y(), - t->first->getVertex(2)->z()), - wrapper->_p, d, closePt); + signedDistancePointTriangle( + SPoint3(t->first->getVertex(0)->x(), t->first->getVertex(0)->y(), + t->first->getVertex(0)->z()), + SPoint3(t->first->getVertex(1)->x(), t->first->getVertex(1)->y(), + t->first->getVertex(1)->z()), + SPoint3(t->first->getVertex(2)->x(), t->first->getVertex(2)->y(), + t->first->getVertex(2)->z()), + wrapper->_p, d, closePt); // printf("%g\n",d); - if (fabs(d) < wrapper->_distance){ + if(fabs(d) < wrapper->_distance) { wrapper->_distance = fabs(d); wrapper->_closestPoint = closePt; wrapper->_t3d = t->first; @@ -211,47 +215,46 @@ GPoint discreteFace::closestPoint(const SPoint3 &queryPoint, double maxDistance, SVector3 *normal) const { #ifdef HAVE_HXT - dfWrapper wrapper (queryPoint); + dfWrapper wrapper(queryPoint); do { wrapper._distance = 1.e22; - double MIN[3] = {queryPoint.x() - maxDistance, - queryPoint.y() - maxDistance, + double MIN[3] = {queryPoint.x() - maxDistance, queryPoint.y() - maxDistance, queryPoint.z() - maxDistance}; - double MAX[3] = {queryPoint.x() + maxDistance, - queryPoint.y() + maxDistance, + double MAX[3] = {queryPoint.x() + maxDistance, queryPoint.y() + maxDistance, queryPoint.z() + maxDistance}; - _parametrizations[_current_parametrization].rtree3d.Search - (MIN, MAX,discreteFace_rtree_callback,&wrapper); + _parametrizations[_current_parametrization].rtree3d.Search( + MIN, MAX, discreteFace_rtree_callback, &wrapper); maxDistance *= 2.0; - }while (!wrapper._t3d); - - if (normal){ - SVector3 t1 (wrapper._t3d->getVertex(1)->x() - wrapper._t3d->getVertex(0)->x(), - wrapper._t3d->getVertex(1)->y() - wrapper._t3d->getVertex(0)->y(), - wrapper._t3d->getVertex(1)->z() - wrapper._t3d->getVertex(0)->z()); - SVector3 t2 (wrapper._t3d->getVertex(2)->x() - wrapper._t3d->getVertex(0)->x(), - wrapper._t3d->getVertex(2)->y() - wrapper._t3d->getVertex(0)->y(), - wrapper._t3d->getVertex(2)->z() - wrapper._t3d->getVertex(0)->z()); - *normal = crossprod(t1,t2); + } while(!wrapper._t3d); + + if(normal) { + SVector3 t1( + wrapper._t3d->getVertex(1)->x() - wrapper._t3d->getVertex(0)->x(), + wrapper._t3d->getVertex(1)->y() - wrapper._t3d->getVertex(0)->y(), + wrapper._t3d->getVertex(1)->z() - wrapper._t3d->getVertex(0)->z()); + SVector3 t2( + wrapper._t3d->getVertex(2)->x() - wrapper._t3d->getVertex(0)->x(), + wrapper._t3d->getVertex(2)->y() - wrapper._t3d->getVertex(0)->y(), + wrapper._t3d->getVertex(2)->z() - wrapper._t3d->getVertex(0)->z()); + *normal = crossprod(t1, t2); normal->normalize(); } - double xyz[3]={wrapper._closestPoint.x(), - wrapper._closestPoint.y(), - wrapper._closestPoint.z()}; + double xyz[3] = {wrapper._closestPoint.x(), wrapper._closestPoint.y(), + wrapper._closestPoint.z()}; double uvw[3]; - wrapper._t3d->xyz2uvw (xyz,uvw); + wrapper._t3d->xyz2uvw(xyz, uvw); const MVertex *v0 = wrapper._t2d->getVertex(0); const MVertex *v1 = wrapper._t2d->getVertex(1); const MVertex *v2 = wrapper._t2d->getVertex(2); - double U = 1-uvw[0]-uvw[1]; + double U = 1 - uvw[0] - uvw[1]; double V = uvw[0]; double W = uvw[1]; - SPoint2 pp(U*v0->x()+V*v1->x()+W*v2->x(), - U*v0->y()+V*v1->y()+W*v2->y()); - return GPoint (xyz[0],xyz[1],xyz[2],this,pp); + SPoint2 pp(U * v0->x() + V * v1->x() + W * v2->x(), + U * v0->y() + V * v1->y() + W * v2->y()); + return GPoint(xyz[0], xyz[1], xyz[2], this, pp); #else - return GPoint (); + return GPoint(); #endif } @@ -259,7 +262,7 @@ GPoint discreteFace::closestPoint(const SPoint3 &queryPoint, const double initialGuess[2]) const { #ifdef HAVE_HXT - return closestPoint(queryPoint, 0.0001); + return closestPoint(queryPoint, 0.0001); #else Msg::Error("Cannot evaluate closest point on discrete face without HXT"); return GPoint(); @@ -269,8 +272,8 @@ GPoint discreteFace::closestPoint(const SPoint3 &queryPoint, SPoint2 discreteFace::parFromPoint(const SPoint3 &p, bool onSurface) const { #ifdef HAVE_HXT - GPoint gp = closestPoint(p, 0.0001); - return SPoint2 (gp.u(), gp.v()); + GPoint gp = closestPoint(p, 0.0001); + return SPoint2(gp.u(), gp.v()); #else Msg::Error("Cannot evaluate par from point on discrete face without HXT"); return SPoint2(); @@ -280,28 +283,29 @@ SPoint2 discreteFace::parFromPoint(const SPoint3 &p, bool onSurface) const SVector3 discreteFace::normal(const SPoint2 ¶m) const { #ifdef HAVE_HXT - MElement *e = _parametrizations[_current_parametrization].oct->find - (param.x(), param.y(), 0.0); - if (!e){ - Msg::Warning("discreteFace::normal << triangle not found %g %g",param[0],param[1]); - return SVector3(0,0,0); + MElement *e = _parametrizations[_current_parametrization].oct->find( + param.x(), param.y(), 0.0); + if(!e) { + Msg::Warning("discreteFace::normal << triangle not found %g %g", param[0], + param[1]); + return SVector3(0, 0, 0); } - int position = (int)((MTriangle*)e - &_parametrizations[_current_parametrization].t2d[0]); - const MTriangle &t3d = _parametrizations[_current_parametrization].t3d[position]; - return _NORMAL_ (t3d); + int position = + (int)((MTriangle *)e - &_parametrizations[_current_parametrization].t2d[0]); + const MTriangle &t3d = + _parametrizations[_current_parametrization].t3d[position]; + return _NORMAL_(t3d); #else Msg::Error("Cannot evaluate normal on discrete face without HXT"); return SVector3(); #endif } -double discreteFace::curvatureMax(const SPoint2 ¶m) const -{ - return false; -} +double discreteFace::curvatureMax(const SPoint2 ¶m) const { return false; } -double discreteFace::curvatures(const SPoint2 ¶m, SVector3 &dirMax, SVector3 &dirMin, - double &curvMax, double &curvMin) const +double discreteFace::curvatures(const SPoint2 ¶m, SVector3 &dirMax, + SVector3 &dirMin, double &curvMax, + double &curvMin) const { return false; } @@ -309,57 +313,59 @@ double discreteFace::curvatures(const SPoint2 ¶m, SVector3 &dirMax, SVector3 Pair<SVector3, SVector3> discreteFace::firstDer(const SPoint2 ¶m) const { #ifdef HAVE_HXT - MElement *e = _parametrizations[_current_parametrization].oct->find - (param.x(), param.y(), 0.0); - if (!e){ - Msg::Warning("discreteFace::firstDer << triangle not found %g %g", - param[0], param[1]); - return Pair<SVector3, SVector3>(SVector3(1,0,0), SVector3(0,1,0)); + MElement *e = _parametrizations[_current_parametrization].oct->find( + param.x(), param.y(), 0.0); + if(!e) { + Msg::Warning("discreteFace::firstDer << triangle not found %g %g", param[0], + param[1]); + return Pair<SVector3, SVector3>(SVector3(1, 0, 0), SVector3(0, 1, 0)); } - int position = (int)((MTriangle*)e - &_parametrizations[_current_parametrization].t2d[0]); + int position = + (int)((MTriangle *)e - &_parametrizations[_current_parametrization].t2d[0]); - const MTriangle &t3d = _parametrizations[_current_parametrization].t3d[position]; + const MTriangle &t3d = + _parametrizations[_current_parametrization].t3d[position]; const MVertex *v1 = t3d.getVertex(0); const MVertex *v2 = t3d.getVertex(1); const MVertex *v3 = t3d.getVertex(2); - double M3D[3][2] = { {v2->x()-v1->x(),v3->x()-v1->x()}, - {v2->y()-v1->y(),v3->y()-v1->y()}, - {v2->z()-v1->z(),v3->z()-v1->z()}}; + double M3D[3][2] = {{v2->x() - v1->x(), v3->x() - v1->x()}, + {v2->y() - v1->y(), v3->y() - v1->y()}, + {v2->z() - v1->z(), v3->z() - v1->z()}}; v1 = e->getVertex(0); v2 = e->getVertex(1); v3 = e->getVertex(2); - double M2D[2][2] = { { (v3->y()- v1->y()), -(v3->x()- v1->x())}, - {-(v2->y()- v1->y()), (v2->x()- v1->x())}}; + double M2D[2][2] = {{(v3->y() - v1->y()), -(v3->x() - v1->x())}, + {-(v2->y() - v1->y()), (v2->x() - v1->x())}}; - double det = 1./(M2D[0][0]*M2D[1][1]-M2D[1][0]*M2D[0][1]); + double det = 1. / (M2D[0][0] * M2D[1][1] - M2D[1][0] * M2D[0][1]); // printf("det = %12.5E\n",det); double dxdu[3][2]; - for (int i = 0; i < 3; i++){ - for (int j = 0; j < 2; j++){ + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 2; j++) { dxdu[i][j] = 0.; - for (int k = 0; k < 2; k++){ - dxdu[i][j] += det*M3D[i][k]*M2D[k][j]; + for(int k = 0; k < 2; k++) { + dxdu[i][j] += det * M3D[i][k] * M2D[k][j]; } } } return Pair<SVector3, SVector3>(SVector3(dxdu[0][0], dxdu[1][0], dxdu[2][0]), - SVector3(dxdu[0][1], dxdu[1][1], dxdu[2][1])); + SVector3(dxdu[0][1], dxdu[1][1], dxdu[2][1])); #endif SVector3 v; Msg::Error("firstDer failed"); - return Pair<SVector3, SVector3>(v,v); + return Pair<SVector3, SVector3>(v, v); } -void discreteFace::secondDer(const SPoint2 ¶m, - SVector3 &dudu, SVector3 &dvdv, SVector3 &dudv) const +void discreteFace::secondDer(const SPoint2 ¶m, SVector3 &dudu, + SVector3 &dvdv, SVector3 &dudv) const { return; } @@ -368,9 +374,10 @@ void discreteFace::createGeometry() { checkAndFixOrientation(); #ifdef HAVE_HXT - HXTStatus s = reparametrize_through_hxt (); - if (s != HXT_STATUS_OK) { - Msg::Error("Impossible to create the geometry of discrete surface %d",tag()); + HXTStatus s = reparametrize_through_hxt(); + if(s != HXT_STATUS_OK) { + Msg::Error("Impossible to create the geometry of discrete surface %d", + tag()); return; } #endif @@ -379,86 +386,85 @@ void discreteFace::createGeometry() void discreteFace::checkAndFixOrientation() { // first of all, all the triangles have to be oriented in the same way - std::map<MEdge,std::vector<MElement*>,Less_Edge> ed2tri; // edge to 1 or 2 triangle(s) + std::map<MEdge, std::vector<MElement *>, Less_Edge> + ed2tri; // edge to 1 or 2 triangle(s) - for(unsigned int i = 0; i < triangles.size(); ++i){ + for(unsigned int i = 0; i < triangles.size(); ++i) { MElement *e = triangles[i]; - for(int j = 0; j < e->getNumEdges() ; j++){ + for(int j = 0; j < e->getNumEdges(); j++) { MEdge ed = e->getEdge(j); ed2tri[ed].push_back(e); } } // element to its neighbors - std::map<MElement*,std::vector<MElement*> > neighbors; - for (unsigned int i=0; i<triangles.size(); ++i){ - MElement* e = triangles[i]; - for(int j = 0; j < e->getNumEdges(); j++){ + std::map<MElement *, std::vector<MElement *> > neighbors; + for(unsigned int i = 0; i < triangles.size(); ++i) { + MElement *e = triangles[i]; + for(int j = 0; j < e->getNumEdges(); j++) { // #improveme: efficiency could be improved by setting neighbors mutually - std::vector<MElement*> my_mt = ed2tri[e->getEdge(j)]; - if (my_mt.size() > 1){// my_mt.size() = {1;2} - MElement* neighTri = my_mt[0] == e ? my_mt[1] : my_mt[0]; - neighbors[e].push_back(neighTri); + std::vector<MElement *> my_mt = ed2tri[e->getEdge(j)]; + if(my_mt.size() > 1) { // my_mt.size() = {1;2} + MElement *neighTri = my_mt[0] == e ? my_mt[1] : my_mt[0]; + neighbors[e].push_back(neighTri); } } } // element for reference orientation - std::queue<MElement*> checkList; + std::queue<MElement *> checkList; // corresponding neighbor element to be checked for its orientation - std::queue< std::vector<MElement*> > checkLists; + std::queue<std::vector<MElement *> > checkLists; // todo list - std::queue<MElement*> my_todo; + std::queue<MElement *> my_todo; // help to complete todo list - std::map<MElement*,bool> check_todo; + std::map<MElement *, bool> check_todo; my_todo.push(triangles[0]); - check_todo[triangles[0]]=true; - while(!my_todo.empty()){ - - MElement* myMT = my_todo.front(); + check_todo[triangles[0]] = true; + while(!my_todo.empty()) { + MElement *myMT = my_todo.front(); my_todo.pop(); - std::vector<MElement*> myV = neighbors[myMT]; - std::vector<MElement*> myInsertion; + std::vector<MElement *> myV = neighbors[myMT]; + std::vector<MElement *> myInsertion; checkList.push(myMT); - for(unsigned int i=0; i<myV.size(); ++i){ - if (check_todo.find(myV[i]) == check_todo.end()){ - myInsertion.push_back(myV[i]); - check_todo[myV[i]] = true; - my_todo.push(myV[i]); + for(unsigned int i = 0; i < myV.size(); ++i) { + if(check_todo.find(myV[i]) == check_todo.end()) { + myInsertion.push_back(myV[i]); + check_todo[myV[i]] = true; + my_todo.push(myV[i]); } } checkLists.push(myInsertion); - }// end while + } // end while - while(!checkList.empty() && !checkLists.empty()){ - MElement* current = checkList.front(); + while(!checkList.empty() && !checkLists.empty()) { + MElement *current = checkList.front(); checkList.pop(); - std::vector<MElement*> neigs = checkLists.front(); + std::vector<MElement *> neigs = checkLists.front(); checkLists.pop(); - for (unsigned int i=0; i<neigs.size(); i++){ + for(unsigned int i = 0; i < neigs.size(); i++) { bool myCond = false; - for (unsigned int k=0; k<3; k++){ - for (unsigned int j=0; j<3; j++){ - if (current->getVertex(k) == neigs[i]->getVertex(j)){ - myCond = true; - if (!(current->getVertex(k!=2 ?k+1 : 0 ) == - neigs[i]->getVertex(j!=0 ? j-1 : 2) || - current->getVertex(k!=0 ?k-1 : 2 ) == - neigs[i]->getVertex(j!=2 ? j+1 : 0))){ - neigs[i]->reverse(); - //Msg::Info("discreteFace: triangle %d has been reoriented.", + for(unsigned int k = 0; k < 3; k++) { + for(unsigned int j = 0; j < 3; j++) { + if(current->getVertex(k) == neigs[i]->getVertex(j)) { + myCond = true; + if(!(current->getVertex(k != 2 ? k + 1 : 0) == + neigs[i]->getVertex(j != 0 ? j - 1 : 2) || + current->getVertex(k != 0 ? k - 1 : 2) == + neigs[i]->getVertex(j != 2 ? j + 1 : 0))) { + neigs[i]->reverse(); + // Msg::Info("discreteFace: triangle %d has been reoriented.", // neigs[i]->getNum()); - } - break; - } - } - if (myCond) - break; + } + break; + } + } + if(myCond) break; } } } @@ -469,18 +475,19 @@ void discreteFace::mesh(bool verbose) #ifdef HAVE_HXT if(_parametrizations.empty()) return; - std::vector<MTriangle*> _t; - std::vector<MVertex*> _v; - std::vector<GEdge*> const tmp = l_edges; + std::vector<MTriangle *> _t; + std::vector<MVertex *> _v; + std::vector<GEdge *> const tmp = l_edges; int _tagtemp = tag(); - for (size_t i = 0; i < _parametrizations.size () ; i++){ + for(size_t i = 0; i < _parametrizations.size(); i++) { setTag(i); l_edges.clear(); l_edges.insert(l_edges.begin(), _parametrizations[i].bnd.begin(), - _parametrizations[i].bnd.end()); + _parametrizations[i].bnd.end()); embedded_edges.clear(); - embedded_edges.insert(embedded_edges.begin(),_parametrizations[i].emb.begin(), - _parametrizations[i].emb.end()); + embedded_edges.insert(embedded_edges.begin(), + _parametrizations[i].emb.begin(), + _parametrizations[i].emb.end()); _current_parametrization = i; triangles.clear(); mesh_vertices.clear(); @@ -492,7 +499,7 @@ void discreteFace::mesh(bool verbose) triangles = _t; mesh_vertices = _v; l_edges = tmp; - embedded_edges.clear() ; + embedded_edges.clear(); meshStatistics.status = GFace::DONE; #else Msg::Error("Cannot mesh a discrete face without HXT"); @@ -500,42 +507,44 @@ void discreteFace::mesh(bool verbose) } #ifdef HAVE_HXT -HXTStatus gmsh2hxt(GFace *gf, HXTMesh **pm, - std::map<MVertex*,int> &v2c, - std::vector<MVertex*> &c2v) +HXTStatus gmsh2hxt(GFace *gf, HXTMesh **pm, std::map<MVertex *, int> &v2c, + std::vector<MVertex *> &c2v) { HXTContext *context; hxtContextCreate(&context); HXTMesh *m; HXT_CHECK(hxtMeshCreate(context, &m)); - std::set<MVertex*> all; - for (size_t i = 0; i<gf->triangles.size(); i++){ - all.insert (gf->triangles[i]->getVertex(0)); - all.insert (gf->triangles[i]->getVertex(1)); - all.insert (gf->triangles[i]->getVertex(2)); + std::set<MVertex *> all; + for(size_t i = 0; i < gf->triangles.size(); i++) { + all.insert(gf->triangles[i]->getVertex(0)); + all.insert(gf->triangles[i]->getVertex(1)); + all.insert(gf->triangles[i]->getVertex(2)); } m->vertices.num = m->vertices.size = all.size(); - HXT_CHECK(hxtAlignedMalloc(&m->vertices.coord, 4*m->vertices.num*sizeof( double )) ); + HXT_CHECK( + hxtAlignedMalloc(&m->vertices.coord, 4 * m->vertices.num * sizeof(double))); size_t count = 0; c2v.resize(all.size()); - for (std::set<MVertex*>::iterator it = all.begin(); it != all.end(); it++){ - m->vertices.coord[4*count+0] = (*it)->x(); - m->vertices.coord[4*count+1] = (*it)->y(); - m->vertices.coord[4*count+2] = (*it)->z(); - m->vertices.coord[4*count+3] = 0.0; + for(std::set<MVertex *>::iterator it = all.begin(); it != all.end(); it++) { + m->vertices.coord[4 * count + 0] = (*it)->x(); + m->vertices.coord[4 * count + 1] = (*it)->y(); + m->vertices.coord[4 * count + 2] = (*it)->z(); + m->vertices.coord[4 * count + 3] = 0.0; v2c[*it] = count; c2v[count++] = *it; } all.clear(); m->triangles.num = m->triangles.size = gf->triangles.size(); - HXT_CHECK( hxtAlignedMalloc(&m->triangles.node, (m->triangles.num)*3*sizeof(uint32_t)) ); - HXT_CHECK( hxtAlignedMalloc(&m->triangles.colors, (m->triangles.num)*sizeof(uint16_t)) ); - for (size_t i = 0; i<gf->triangles.size(); i++){ - m->triangles.node[3*i+0] = v2c[gf->triangles[i]->getVertex(0)]; - m->triangles.node[3*i+1] = v2c[gf->triangles[i]->getVertex(1)]; - m->triangles.node[3*i+2] = v2c[gf->triangles[i]->getVertex(2)]; + HXT_CHECK(hxtAlignedMalloc(&m->triangles.node, + (m->triangles.num) * 3 * sizeof(uint32_t))); + HXT_CHECK(hxtAlignedMalloc(&m->triangles.colors, + (m->triangles.num) * sizeof(uint16_t))); + for(size_t i = 0; i < gf->triangles.size(); i++) { + m->triangles.node[3 * i + 0] = v2c[gf->triangles[i]->getVertex(0)]; + m->triangles.node[3 * i + 1] = v2c[gf->triangles[i]->getVertex(1)]; + m->triangles.node[3 * i + 2] = v2c[gf->triangles[i]->getVertex(2)]; m->triangles.colors[i] = gf->tag(); } @@ -655,20 +664,23 @@ static void splitInternalEdges(std::vector<MEdge> &e, int ITH, } #endif -GPoint discreteFace::intersectionWithCircle(const SVector3 &n1, const SVector3 &n2, - const SVector3 &p, const double &R, - double uv[2]) +GPoint discreteFace::intersectionWithCircle(const SVector3 &n1, + const SVector3 &n2, + const SVector3 &p, const double &R, + double uv[2]) { #ifdef HAVE_HXT - MTriangle *t2d = (MTriangle*)_parametrizations[_current_parametrization].oct->find - (uv[0], uv[1], 0.0); + MTriangle *t2d = + (MTriangle *)_parametrizations[_current_parametrization].oct->find( + uv[0], uv[1], 0.0); MTriangle *t3d = NULL; - if (t2d) { - int position = (int)(t2d - &_parametrizations[_current_parametrization].t2d[0]); + if(t2d) { + int position = + (int)(t2d - &_parametrizations[_current_parametrization].t2d[0]); t3d = &_parametrizations[_current_parametrization].t3d[position]; } - SVector3 n = crossprod(n1,n2); + SVector3 n = crossprod(n1, n2); n.normalize(); // printf("UV %g %g ",uv[0],uv[1]); @@ -677,91 +689,94 @@ GPoint discreteFace::intersectionWithCircle(const SVector3 &n1, const SVector3 & int N = _parametrizations[_current_parametrization].t3d.size(); int start = 0; - if (t2d)start = -1; - for (int i=start;i<N;i++){ - if (i >= 0){ + if(t2d) start = -1; + for(int i = start; i < N; i++) { + if(i >= 0) { t2d = &_parametrizations[_current_parametrization].t2d[i]; t3d = &_parametrizations[_current_parametrization].t3d[i]; } - SVector3 v0(t3d->getVertex(0)->x(),t3d->getVertex(0)->y(),t3d->getVertex(0)->z()); - SVector3 v1(t3d->getVertex(1)->x(),t3d->getVertex(1)->y(),t3d->getVertex(1)->z()); - SVector3 v2(t3d->getVertex(2)->x(),t3d->getVertex(2)->y(),t3d->getVertex(2)->z()); - SVector3 v0_2d(t2d->getVertex(0)->x(),t2d->getVertex(0)->y(),t2d->getVertex(0)->z()); - SVector3 v1_2d(t2d->getVertex(1)->x(),t2d->getVertex(1)->y(),t2d->getVertex(1)->z()); - SVector3 v2_2d(t2d->getVertex(2)->x(),t2d->getVertex(2)->y(),t2d->getVertex(2)->z()); - SVector3 t1 = v1 - v0; - SVector3 t2 = v2 - v0; - SVector3 t = crossprod(t1,t2); + SVector3 v0(t3d->getVertex(0)->x(), t3d->getVertex(0)->y(), + t3d->getVertex(0)->z()); + SVector3 v1(t3d->getVertex(1)->x(), t3d->getVertex(1)->y(), + t3d->getVertex(1)->z()); + SVector3 v2(t3d->getVertex(2)->x(), t3d->getVertex(2)->y(), + t3d->getVertex(2)->z()); + SVector3 v0_2d(t2d->getVertex(0)->x(), t2d->getVertex(0)->y(), + t2d->getVertex(0)->z()); + SVector3 v1_2d(t2d->getVertex(1)->x(), t2d->getVertex(1)->y(), + t2d->getVertex(1)->z()); + SVector3 v2_2d(t2d->getVertex(2)->x(), t2d->getVertex(2)->y(), + t2d->getVertex(2)->z()); + SVector3 t1 = v1 - v0; + SVector3 t2 = v2 - v0; + SVector3 t = crossprod(t1, t2); t.normalize(); - SVector3 d = crossprod(n,t); - if (d.norm() < 1.e-12) continue; + SVector3 d = crossprod(n, t); + if(d.norm() < 1.e-12) continue; d.normalize(); - double rhs[2] = {dot(n,p), dot(v0,t)}; + double rhs[2] = {dot(n, p), dot(v0, t)}; double r[2]; double m[2][2]; - SVector3 x0(0,0,0); + SVector3 x0(0, 0, 0); m[0][0] = n.y(); m[0][1] = n.z(); m[1][0] = t.y(); m[1][1] = t.z(); - if (fabs(det2x2(m)) > 1.e-12){ - sys2x2(m,rhs,r); - x0 = SVector3(0,r[0],r[1]); + if(fabs(det2x2(m)) > 1.e-12) { + sys2x2(m, rhs, r); + x0 = SVector3(0, r[0], r[1]); } else { m[0][0] = n.x(); m[0][1] = n.z(); m[1][0] = t.x(); m[1][1] = t.z(); - if (fabs(det2x2(m)) > 1.e-12){ - sys2x2(m,rhs,r); - x0 = SVector3(r[0],0,r[1]); + if(fabs(det2x2(m)) > 1.e-12) { + sys2x2(m, rhs, r); + x0 = SVector3(r[0], 0, r[1]); } else { - m[0][0] = n.x(); - m[0][1] = n.y(); - m[1][0] = t.x(); - m[1][1] = t.y(); - if (sys2x2(m,rhs,r)) { - x0 = SVector3(r[0],r[1],0); - } - else{ - // printf("mauvaise pioche\n"); - continue; - } + m[0][0] = n.x(); + m[0][1] = n.y(); + m[1][0] = t.x(); + m[1][1] = t.y(); + if(sys2x2(m, rhs, r)) { + x0 = SVector3(r[0], r[1], 0); + } + else { + // printf("mauvaise pioche\n"); + continue; + } } } const double a = 1.0; - const double b = -2*dot(d,p-x0); - const double c = dot(p-x0,p-x0) - R*R; - const double delta = b*b-4*a*c; - if (delta >= 0){ - double sign = (dot(n2,d) > 0)? 1.0:-1.0; - const double ta = (-b + sign*sqrt(delta)) / (2.*a); - const double tb = (-b - sign*sqrt(delta)) / (2.*a); + const double b = -2 * dot(d, p - x0); + const double c = dot(p - x0, p - x0) - R * R; + const double delta = b * b - 4 * a * c; + if(delta >= 0) { + double sign = (dot(n2, d) > 0) ? 1.0 : -1.0; + const double ta = (-b + sign * sqrt(delta)) / (2. * a); + const double tb = (-b - sign * sqrt(delta)) / (2. * a); SVector3 s[2] = {x0 + d * ta, x0 + d * tb}; - for (int IT=0;IT<2;IT++){ - double mat[2][2], b[2],uv[2]; - mat[0][0] = dot(t1,t1); - mat[1][1] = dot(t2,t2); - mat[0][1] = mat[1][0] = dot(t1,t2); - b[0] = dot(s[IT]-v0,t1) ; - b[1] = dot(s[IT]-v0,t2) ; - sys2x2(mat,b,uv); - // check now if the point is inside the triangle - if (uv[0] >= -1.e-6 && uv[1] >= -1.e-6 && - 1.-uv[0]-uv[1] >= -1.e-6 ) { - SVector3 pp = - v0_2d * ( 1.-uv[0]-uv[1] ) + - v1_2d * uv[0] + - v2_2d * uv[1] ; - uv[0] = pp.x(); - uv[1] = pp.y(); - // printf("%d\n",i); - // printf("--> UV %g %g\n",pp[0],pp[1]); - return GPoint(s[IT].x(),s[IT].y(),s[IT].z(),this,uv); - } + for(int IT = 0; IT < 2; IT++) { + double mat[2][2], b[2], uv[2]; + mat[0][0] = dot(t1, t1); + mat[1][1] = dot(t2, t2); + mat[0][1] = mat[1][0] = dot(t1, t2); + b[0] = dot(s[IT] - v0, t1); + b[1] = dot(s[IT] - v0, t2); + sys2x2(mat, b, uv); + // check now if the point is inside the triangle + if(uv[0] >= -1.e-6 && uv[1] >= -1.e-6 && 1. - uv[0] - uv[1] >= -1.e-6) { + SVector3 pp = + v0_2d * (1. - uv[0] - uv[1]) + v1_2d * uv[0] + v2_2d * uv[1]; + uv[0] = pp.x(); + uv[1] = pp.y(); + // printf("%d\n",i); + // printf("--> UV %g %g\n",pp[0],pp[1]); + return GPoint(s[IT].x(), s[IT].y(), s[IT].z(), this, uv); + } } } } @@ -774,52 +789,50 @@ GPoint discreteFace::intersectionWithCircle(const SVector3 &n1, const SVector3 & #ifdef HAVE_HXT -static void existingEdges (GFace *gf, std::map<MEdge, GEdge*, Less_Edge> &edges) +static void existingEdges(GFace *gf, std::map<MEdge, GEdge *, Less_Edge> &edges) { - std::vector<GEdge*> const& e = gf->edges(); - for (std::vector<GEdge*>::const_iterator it = e.begin(); it != e.end(); ++it){ - for (unsigned int i = 0;i<(*it)->lines.size(); i++){ + std::vector<GEdge *> const &e = gf->edges(); + for(std::vector<GEdge *>::const_iterator it = e.begin(); it != e.end(); + ++it) { + for(unsigned int i = 0; i < (*it)->lines.size(); i++) { MLine *ml = (*it)->lines[i]; - edges.insert (std::make_pair(MEdge(ml->getVertex(0),ml->getVertex(1)),*it)); + edges.insert( + std::make_pair(MEdge(ml->getVertex(0), ml->getVertex(1)), *it)); } } } -bool discreteFace::compute_topology_of_partition(int nbColors, - int *colors, - int *nNodes, - int *nodes, - double *uv, - double angle_threshold, - std::vector<MVertex*> &c2v, - std::vector<std::vector<MEdge> > &boundaries, - std::vector<std::vector<MEdge> > &internals) +bool discreteFace::compute_topology_of_partition( + int nbColors, int *colors, int *nNodes, int *nodes, double *uv, + double angle_threshold, std::vector<MVertex *> &c2v, + std::vector<std::vector<MEdge> > &boundaries, + std::vector<std::vector<MEdge> > &internals) { GModel *gm = model(); - int TAG = gm->getMaxElementNumber()+1; + int TAG = gm->getMaxElementNumber() + 1; // Assign parameters for each vertex of each partition std::vector<int> cpt(_parametrizations.size()); - std::vector<MTriangle*> &ts = triangles; + std::vector<MTriangle *> &ts = triangles; // make a copy of the geometry and of the parametrization (could be smaller) - std::map<std::pair<MVertex*,int>,SPoint2> params; - for (size_t i=0;i<_parametrizations.size();i++){ + std::map<std::pair<MVertex *, int>, SPoint2> params; + for(size_t i = 0; i < _parametrizations.size(); i++) { cpt[colors[i]] = 0; - for (int j=nNodes[i];j<nNodes[i+1]; j++){ + for(int j = nNodes[i]; j < nNodes[i + 1]; j++) { MVertex *vert = c2v[nodes[j]]; - double U = uv[2*j+0]; - double V = uv[2*j+1]; - std::pair<MVertex*,int> pp = std::make_pair(vert,i); - params[pp] = SPoint2(U,V); + double U = uv[2 * j + 0]; + double V = uv[2 * j + 1]; + std::pair<MVertex *, int> pp = std::make_pair(vert, i); + params[pp] = SPoint2(U, V); } } // count how much triangles per partition - for (size_t i = 0 ; i<ts.size(); i++){ - cpt[colors[i]] ++; + for(size_t i = 0; i < ts.size(); i++) { + cpt[colors[i]]++; } - for (size_t i=0;i<_parametrizations.size();i++){ + for(size_t i = 0; i < _parametrizations.size(); i++) { _parametrizations[colors[i]].t3d.reserve(cpt[colors[i]]); _parametrizations[colors[i]].t2d.reserve(cpt[colors[i]]); } @@ -827,13 +840,13 @@ bool discreteFace::compute_topology_of_partition(int nbColors, #undef debug #ifdef debug // save the atlas in pos files for checking - debugging - FILE *f = fopen("atlasP.pos","w"); - fprintf(f,"View \"\"{\n"); - FILE *f2 = fopen("atlasR.pos","w"); - fprintf(f2,"View \"\"{\n"); + FILE *f = fopen("atlasP.pos", "w"); + fprintf(f, "View \"\"{\n"); + FILE *f2 = fopen("atlasR.pos", "w"); + fprintf(f2, "View \"\"{\n"); #endif // created copies of triangles, both in 2D and in 3D - for (size_t i = 0 ; i < ts.size(); i++){ + for(size_t i = 0; i < ts.size(); i++) { MTriangle *t = ts[i]; int c = colors[i]; MVertex *v0 = new MVertex(t->getVertex(0)->x(), t->getVertex(0)->y(), @@ -853,63 +866,63 @@ bool discreteFace::compute_topology_of_partition(int nbColors, _parametrizations[c].t3d.push_back(t3d); _parametrizations[c].t2d.push_back(t2d); #ifdef debug - fprintf(f,"ST(%g,%g,%g,%g,%g,%g,%g,%g,%g){%d,%d,%d};\n", - vv0->x()+2.2*c,vv0->y(),vv0->z(), - vv1->x()+2.2*c,vv1->y(),vv1->z(), - vv2->x()+2.2*c,vv2->y(),vv2->z(),c,c,c); - fprintf(f2,"ST(%g,%g,%g,%g,%g,%g,%g,%g,%g){%d,%d,%d};\n", - v0->x(),v0->y(),v0->z(), - v1->x(),v1->y(),v1->z(), - v2->x(),v2->y(),v2->z(),c,c,c); + fprintf(f, "ST(%g,%g,%g,%g,%g,%g,%g,%g,%g){%d,%d,%d};\n", + vv0->x() + 2.2 * c, vv0->y(), vv0->z(), vv1->x() + 2.2 * c, + vv1->y(), vv1->z(), vv2->x() + 2.2 * c, vv2->y(), vv2->z(), c, c, + c); + fprintf(f2, "ST(%g,%g,%g,%g,%g,%g,%g,%g,%g){%d,%d,%d};\n", v0->x(), v0->y(), + v0->z(), v1->x(), v1->y(), v1->z(), v2->x(), v2->y(), v2->z(), c, c, + c); #endif } #ifdef debug - fprintf(f,"};\n"); + fprintf(f, "};\n"); fclose(f); - fprintf(f2,"};\n"); + fprintf(f2, "};\n"); fclose(f2); #endif // compute 1D topology // edges between two colors - std::map<MEdge, std::pair<int,int>, Less_Edge> l; + std::map<MEdge, std::pair<int, int>, Less_Edge> l; // temporary map, useful for computing dihedral angles ... - std::map<MEdge, MTriangle*, Less_Edge> lt; - for (size_t i = 0 ; i<ts.size(); i++){ + std::map<MEdge, MTriangle *, Less_Edge> lt; + for(size_t i = 0; i < ts.size(); i++) { MTriangle *t = ts[i]; int c = colors[i]; - for (int j=0;j<3;j++){ + for(int j = 0; j < 3; j++) { MEdge e = t->getEdge(j); - std::map<MEdge, std::pair<int,int> , Less_Edge>::iterator it = l.find(e); - if (it == l.end()){ - std::pair<int,int> p = std::make_pair(c,(int)-1); - l[e] = p; - lt[e] = t; + std::map<MEdge, std::pair<int, int>, Less_Edge>::iterator it = l.find(e); + if(it == l.end()) { + std::pair<int, int> p = std::make_pair(c, (int)-1); + l[e] = p; + lt[e] = t; } else { - if (it->second.first == c){ - l.erase(it); - std::map<MEdge, MTriangle* , Less_Edge>::iterator it2 = lt.find(e); - MTriangle *t0 = it2->second; - SVector3 v1 (t0->getVertex(2)->x()-t0->getVertex(0)->x(), - t0->getVertex(2)->y()-t0->getVertex(0)->y(), - t0->getVertex(2)->z()-t0->getVertex(0)->z()); - SVector3 v2 (t0->getVertex(1)->x()-t0->getVertex(0)->x(), - t0->getVertex(1)->y()-t0->getVertex(0)->y(), - t0->getVertex(1)->z()-t0->getVertex(0)->z()); - SVector3 n0 = crossprod(v1,v2); - SVector3 v3 (t->getVertex(2)->x()-t->getVertex(0)->x(), - t->getVertex(2)->y()-t->getVertex(0)->y(), - t->getVertex(2)->z()-t->getVertex(0)->z()); - SVector3 v4 (t->getVertex(1)->x()-t->getVertex(0)->x(), - t->getVertex(1)->y()-t->getVertex(0)->y(), - t->getVertex(1)->z()-t->getVertex(0)->z()); - SVector3 n1 = crossprod(v3,v4); - if (angle (n0,n1) > angle_threshold)internals[c].push_back(e); - lt.erase(it2); - } - else it->second.second=c; + if(it->second.first == c) { + l.erase(it); + std::map<MEdge, MTriangle *, Less_Edge>::iterator it2 = lt.find(e); + MTriangle *t0 = it2->second; + SVector3 v1(t0->getVertex(2)->x() - t0->getVertex(0)->x(), + t0->getVertex(2)->y() - t0->getVertex(0)->y(), + t0->getVertex(2)->z() - t0->getVertex(0)->z()); + SVector3 v2(t0->getVertex(1)->x() - t0->getVertex(0)->x(), + t0->getVertex(1)->y() - t0->getVertex(0)->y(), + t0->getVertex(1)->z() - t0->getVertex(0)->z()); + SVector3 n0 = crossprod(v1, v2); + SVector3 v3(t->getVertex(2)->x() - t->getVertex(0)->x(), + t->getVertex(2)->y() - t->getVertex(0)->y(), + t->getVertex(2)->z() - t->getVertex(0)->z()); + SVector3 v4(t->getVertex(1)->x() - t->getVertex(0)->x(), + t->getVertex(1)->y() - t->getVertex(0)->y(), + t->getVertex(1)->z() - t->getVertex(0)->z()); + SVector3 n1 = crossprod(v3, v4); + if(angle(n0, n1) > angle_threshold) internals[c].push_back(e); + lt.erase(it2); + } + else + it->second.second = c; } } } @@ -917,65 +930,72 @@ bool discreteFace::compute_topology_of_partition(int nbColors, // compute model edges that are internal to a partition or on its boundary // the form of an internal edge is a vector of MEdge - std::map<std::pair<int,int> , std::vector<MEdge> > edges; + std::map<std::pair<int, int>, std::vector<MEdge> > edges; { - std::map<MEdge, std::pair<int,int> , Less_Edge>::iterator it = l.begin(); - for (; it != l.end(); ++it){ - std::pair<int,int> x = it->second; - std::pair<int,int> y = std::make_pair(std::min(x.first,x.second), - std::max(x.first,x.second)); - std::map<std::pair<int,int> , std::vector<MEdge> >:: iterator itf = edges.find(y); - if (itf == edges.end()){ - std::vector<MEdge> v; v.push_back(it->first); - edges [y] = v; + std::map<MEdge, std::pair<int, int>, Less_Edge>::iterator it = l.begin(); + for(; it != l.end(); ++it) { + std::pair<int, int> x = it->second; + std::pair<int, int> y = std::make_pair(std::min(x.first, x.second), + std::max(x.first, x.second)); + std::map<std::pair<int, int>, std::vector<MEdge> >::iterator itf = + edges.find(y); + if(itf == edges.end()) { + std::vector<MEdge> v; + v.push_back(it->first); + edges[y] = v; } else { - itf->second.push_back(it->first); + itf->second.push_back(it->first); } } } // each color has MEdges as boundaries { - std::map<std::pair<int,int> , std::vector<MEdge> >::iterator it = edges.begin(); - for (; it != edges.end() ; ++it) { - if (it->first.first != -1) + std::map<std::pair<int, int>, std::vector<MEdge> >::iterator it = + edges.begin(); + for(; it != edges.end(); ++it) { + if(it->first.first != -1) boundaries[it->first.first].insert(boundaries[it->first.first].begin(), - it->second.begin(),it->second.end()); - if (it->first.second != -1) - boundaries[it->first.second].insert(boundaries[it->first.second].begin(), - it->second.begin(),it->second.end()); + it->second.begin(), + it->second.end()); + if(it->first.second != -1) + boundaries[it->first.second].insert( + boundaries[it->first.second].begin(), it->second.begin(), + it->second.end()); } } - // split external edges i.e. edges that were already there but that are split by - // partitions + // split external edges i.e. edges that were already there but that are split + // by partitions { - std::map<std::pair<int,int> , std::vector<MEdge> >::iterator it = edges.begin(); - for (; it != edges.end() ; ++it) { - std::vector< std::vector<MVertex *> >vs; + std::map<std::pair<int, int>, std::vector<MEdge> >::iterator it = + edges.begin(); + for(; it != edges.end(); ++it) { + std::vector<std::vector<MVertex *> > vs; // this is the tricky beast !!! SortEdgeConsecutive(it->second, vs); - for (size_t k = 0; k< vs.size(); k++){ - std::vector<MVertex*> &v = vs[k]; - MVertex *vs[2] = {v[0],v[v.size()-1]}; - for (int i = 0; i < 2; i++){ - if(vs[i]->onWhat()->dim() == 1 && it->first.second != -1 && it->first.first != -1) { - // vs[i]->onWhat()->mesh_vertices.erase + for(size_t k = 0; k < vs.size(); k++) { + std::vector<MVertex *> &v = vs[k]; + MVertex *vs[2] = {v[0], v[v.size() - 1]}; + for(int i = 0; i < 2; i++) { + if(vs[i]->onWhat()->dim() == 1 && it->first.second != -1 && + it->first.first != -1) { + // vs[i]->onWhat()->mesh_vertices.erase // (std::remove(vs[i]->onWhat()->mesh_vertices.begin(), - // vs[i]->onWhat()->mesh_vertices.end(), vs[i]), - // vs[i]->onWhat()->mesh_vertices.end()); - discreteEdge *de = static_cast<discreteEdge*> (vs[i]->onWhat()); - if(!de) Msg::Error("Can only split discrete edges at that point"); - discreteVertex* gstart = new discreteVertex(gm, ++TAG + 1); - gm->add(gstart); - vs[i]->setEntity(gstart); - gstart->mesh_vertices.push_back(vs[i]); - splitDiscreteEdge(de,vs[i],gstart,TAG); - // printf("%d %d\n",it->first.first,it->first.second); - Msg::Info("Splitting Existing discrete Edge %d", de->tag()); - } - } + // vs[i]->onWhat()->mesh_vertices.end(), vs[i]), + // vs[i]->onWhat()->mesh_vertices.end()); + discreteEdge *de = static_cast<discreteEdge *>(vs[i]->onWhat()); + if(!de) Msg::Error("Can only split discrete edges at that point"); + discreteVertex *gstart = new discreteVertex(gm, ++TAG + 1); + gm->add(gstart); + vs[i]->setEntity(gstart); + gstart->mesh_vertices.push_back(vs[i]); + splitDiscreteEdge(de, vs[i], gstart, TAG); + // printf("%d %d\n",it->first.first,it->first.second); + Msg::Info("Splitting Existing discrete Edge %d", de->tag()); + } + } } } } @@ -983,46 +1003,50 @@ bool discreteFace::compute_topology_of_partition(int nbColors, // at that point, end vertices of partition lines are either classified on // GVertex or on GFace { - std::map<std::pair<int,int> , std::vector<MEdge> >::iterator it = edges.begin(); - for (; it != edges.end() ; ++it) { - std::vector< std::vector<MVertex *> >vs; + std::map<std::pair<int, int>, std::vector<MEdge> >::iterator it = + edges.begin(); + for(; it != edges.end(); ++it) { + std::vector<std::vector<MVertex *> > vs; SortEdgeConsecutive(it->second, vs); - for (size_t k = 0; k< vs.size(); k++){ - std::vector<MVertex*> &v = vs[k]; - MVertex *ends[2] = {v[0],v[v.size()-1]}; - if( ends[0]->onWhat() == this || ends[1]->onWhat() == this) { - for (int i=0;i<2;i++){ - if (ends[i]->onWhat()==this){ - discreteVertex* gstart = new discreteVertex (gm, ++TAG); - v_internals.push_back(gstart); - gm->add(gstart); - ends[i]->setEntity(gstart); - gstart->mesh_vertices.push_back(ends[i]); - } - } - } - if (it->first.first != -1){ - discreteEdge *de = new discreteEdge - (gm, ++TAG, (GVertex*)ends[0]->onWhat(), (GVertex*)ends[1]->onWhat()); - e_internals.push_back(de); - Msg::Info("Creation of one internal discrete edge %d (%d %d) to discrete " - "face %d", de->tag(), ends[0]->onWhat()->tag(), - ends[1]->onWhat()->tag(), tag()); - gm->add(de); - for (size_t i = 1; i < v.size() -1; i++){ - v[i]->setEntity(de); - de->mesh_vertices.push_back(v[i]); - } - for(size_t i = 1; i < v.size(); i++) - de->lines.push_back(new MLine(v[i-1],v[i])); - } + for(size_t k = 0; k < vs.size(); k++) { + std::vector<MVertex *> &v = vs[k]; + MVertex *ends[2] = {v[0], v[v.size() - 1]}; + if(ends[0]->onWhat() == this || ends[1]->onWhat() == this) { + for(int i = 0; i < 2; i++) { + if(ends[i]->onWhat() == this) { + discreteVertex *gstart = new discreteVertex(gm, ++TAG); + v_internals.push_back(gstart); + gm->add(gstart); + ends[i]->setEntity(gstart); + gstart->mesh_vertices.push_back(ends[i]); + } + } + } + if(it->first.first != -1) { + discreteEdge *de = + new discreteEdge(gm, ++TAG, (GVertex *)ends[0]->onWhat(), + (GVertex *)ends[1]->onWhat()); + e_internals.push_back(de); + Msg::Info( + "Creation of one internal discrete edge %d (%d %d) to discrete " + "face %d", + de->tag(), ends[0]->onWhat()->tag(), ends[1]->onWhat()->tag(), + tag()); + gm->add(de); + for(size_t i = 1; i < v.size() - 1; i++) { + v[i]->setEntity(de); + de->mesh_vertices.push_back(v[i]); + } + for(size_t i = 1; i < v.size(); i++) + de->lines.push_back(new MLine(v[i - 1], v[i])); + } } } } - // EMBEDDED STUFF + // EMBEDDED STUFF #if 0 for (size_t i = 0; i < _parametrizations.size(); i++){ std::vector<std::vector<MVertex*> >eds; @@ -1103,89 +1127,101 @@ HXTStatus discreteFace::reparametrize_through_hxt() HXT_CHECK(hxtInitializeLinearSystems(&n, NULL)); HXTMesh *m; - std::map<MVertex*,int> v2c; - std::vector<MVertex*> c2v; - gmsh2hxt(this, &m, v2c,c2v); + std::map<MVertex *, int> v2c; + std::vector<MVertex *> c2v; + gmsh2hxt(this, &m, v2c, c2v); HXTParametrization *parametrization; int *colors, *nNodes, *nodes, nc; double *uv; HXT_CHECK(hxtParametrizationCreate(m, 0, ¶metrization)); - HXT_CHECK(hxtParametrizationCompute(parametrization, &colors, &nNodes, - &nodes, &uv, &nc,&m)); - //HXT_CHECK(hxtParametrizationWrite(parametrization, "hop")); + HXT_CHECK(hxtParametrizationCompute(parametrization, &colors, &nNodes, &nodes, + &uv, &nc, &m)); + // HXT_CHECK(hxtParametrizationWrite(parametrization, "hop")); // compute curvatures - HXTEdges* edges; - double *crossField,*nodalCurvatures; - HXT_CHECK(hxtEdgesCreate(m,&edges)); - HXT_CHECK(hxtCurvatureRusinkiewicz(m, &nodalCurvatures, &crossField, edges, false)); + HXTEdges *edges; + double *crossField, *nodalCurvatures; + HXT_CHECK(hxtEdgesCreate(m, &edges)); + HXT_CHECK( + hxtCurvatureRusinkiewicz(m, &nodalCurvatures, &crossField, edges, false)); HXT_CHECK(hxtEdgesDelete(&edges)); _parametrizations.resize(nc); std::vector<std::vector<MEdge> > boundaries(nc); std::vector<std::vector<MEdge> > internals(nc); if(!compute_topology_of_partition(nc, colors, nNodes, nodes, uv, - 0.7*M_PI/2, c2v, boundaries, internals)) + 0.7 * M_PI / 2, c2v, boundaries, internals)) Msg::Warning("Impossible to compute the topology of the %d partitions", nc); - Msg::Info("Face %d split int %d parts",tag(), _parametrizations.size()); + Msg::Info("Face %d split int %d parts", tag(), _parametrizations.size()); // Msg::Info("Face %d has %d internal edges", tag(), internals[0].size()); - std::map<MEdge, GEdge*, Less_Edge> cad_edges; + std::map<MEdge, GEdge *, Less_Edge> cad_edges; existingEdges(this, cad_edges); - for(size_t i = 0; i < _parametrizations.size(); i++){ + for(size_t i = 0; i < _parametrizations.size(); i++) { Less_Edge le; - std::sort(boundaries[i].begin(),boundaries[i].end(),le); - std::set<discreteEdge*> des; - for(GModel::eiter it = model()->firstEdge(); it != model()->lastEdge(); it++){ - for(size_t k = 0; k < (*it)->lines.size(); k++){ - MEdge e((*it)->lines[k]->getVertex(0), (*it)->lines[k]->getVertex(1)); - if(std::binary_search(boundaries[i].begin(), boundaries[i].end(), e, le)){ - discreteEdge *de = static_cast<discreteEdge*>(*it); - if(!de) Msg::Error("Reparametrization only works for discrete geometries"); - if(des.find(de) == des.end()){ - if(de->_compound.size()){ - if(de->compound_edge)des.insert((discreteEdge*)de->compound_edge); - } - else{ - des.insert(de); - } - } - } + std::sort(boundaries[i].begin(), boundaries[i].end(), le); + std::set<discreteEdge *> des; + for(GModel::eiter it = model()->firstEdge(); it != model()->lastEdge(); + it++) { + for(size_t k = 0; k < (*it)->lines.size(); k++) { + MEdge e((*it)->lines[k]->getVertex(0), (*it)->lines[k]->getVertex(1)); + if(std::binary_search(boundaries[i].begin(), boundaries[i].end(), e, + le)) { + discreteEdge *de = static_cast<discreteEdge *>(*it); + if(!de) + Msg::Error("Reparametrization only works for discrete geometries"); + if(des.find(de) == des.end()) { + if(de->_compound.size()) { + if(de->compound_edge) + des.insert((discreteEdge *)de->compound_edge); + } + else { + des.insert(de); + } + } + } } } _parametrizations[i].bnd.insert(_parametrizations[i].bnd.begin(), des.begin(), des.end()); } - for(size_t i = 0; i < _parametrizations.size(); i++){ - std::vector<MElement*>temp; - for(size_t j = 0; j < _parametrizations[i].t2d.size(); j++){ + for(size_t i = 0; i < _parametrizations.size(); i++) { + std::vector<MElement *> temp; + for(size_t j = 0; j < _parametrizations[i].t2d.size(); j++) { temp.push_back(&_parametrizations[i].t2d[j]); double MIN[3] = {_parametrizations[i].t3d[j].getVertex(0)->x(), - _parametrizations[i].t3d[j].getVertex(0)->y(), - _parametrizations[i].t3d[j].getVertex(0)->z()}; + _parametrizations[i].t3d[j].getVertex(0)->y(), + _parametrizations[i].t3d[j].getVertex(0)->z()}; double MAX[3] = {_parametrizations[i].t3d[j].getVertex(0)->x(), - _parametrizations[i].t3d[j].getVertex(0)->y(), - _parametrizations[i].t3d[j].getVertex(0)->z()}; - for(int k = 1; k < 3; k++){ - MAX[0] = std::max(MAX[0], _parametrizations[i].t3d[j].getVertex(k)->x()); - MIN[0] = std::min(MIN[0], _parametrizations[i].t3d[j].getVertex(k)->x()); - MAX[1] = std::max(MAX[1], _parametrizations[i].t3d[j].getVertex(k)->y()); - MIN[1] = std::min(MIN[1], _parametrizations[i].t3d[j].getVertex(k)->y()); - MAX[2] = std::max(MAX[2], _parametrizations[i].t3d[j].getVertex(k)->z()); - MIN[2] = std::min(MIN[2], _parametrizations[i].t3d[j].getVertex(k)->z()); + _parametrizations[i].t3d[j].getVertex(0)->y(), + _parametrizations[i].t3d[j].getVertex(0)->z()}; + for(int k = 1; k < 3; k++) { + MAX[0] = + std::max(MAX[0], _parametrizations[i].t3d[j].getVertex(k)->x()); + MIN[0] = + std::min(MIN[0], _parametrizations[i].t3d[j].getVertex(k)->x()); + MAX[1] = + std::max(MAX[1], _parametrizations[i].t3d[j].getVertex(k)->y()); + MIN[1] = + std::min(MIN[1], _parametrizations[i].t3d[j].getVertex(k)->y()); + MAX[2] = + std::max(MAX[2], _parametrizations[i].t3d[j].getVertex(k)->z()); + MIN[2] = + std::min(MIN[2], _parametrizations[i].t3d[j].getVertex(k)->z()); } - std::pair<MTriangle*,MTriangle*> *tt = new std::pair<MTriangle*,MTriangle*> - (&_parametrizations[i].t3d[j], &_parametrizations[i].t2d[j]); + std::pair<MTriangle *, MTriangle *> *tt = + new std::pair<MTriangle *, MTriangle *>(&_parametrizations[i].t3d[j], + &_parametrizations[i].t2d[j]); _parametrizations[i].rtree3d.Insert(MIN, MAX, tt); } _parametrizations[i].oct = new MElementOctree(temp); } - for (size_t i = 0; i < _parametrizations.size(); i++){ - for (size_t j = 0; j < _parametrizations[i].emb.size(); j++){ + for(size_t i = 0; i < _parametrizations.size(); i++) { + for(size_t j = 0; j < _parametrizations[i].emb.size(); j++) { model()->add(_parametrizations[i].emb[j]); } } @@ -1195,7 +1231,7 @@ HXTStatus discreteFace::reparametrize_through_hxt() return HXT_STATUS_OK; } -hxt_reparam_surf::~hxt_reparam_surf () +hxt_reparam_surf::~hxt_reparam_surf() { if(oct) delete oct; } diff --git a/Geo/discreteFace.h b/Geo/discreteFace.h index 99fb41dfabb9bf0a730c71425d95bcc9823044ac..473b02b575e6b029d74e4c8de2d6f3831002d28c 100644 --- a/Geo/discreteFace.h +++ b/Geo/discreteFace.h @@ -28,13 +28,13 @@ extern "C" { class hxt_reparam_surf { public: MElementOctree *oct; - mutable RTree< std::pair<MTriangle*,MTriangle*> *,double,3> rtree3d; - std::vector<MVertex> v2d; - std::vector<MVertex> v3d; + mutable RTree<std::pair<MTriangle *, MTriangle *> *, double, 3> rtree3d; + std::vector<MVertex> v2d; + std::vector<MVertex> v3d; std::vector<MTriangle> t2d; std::vector<MTriangle> t3d; - std::vector<discreteEdge*> bnd; - std::vector<discreteEdge*> emb; + std::vector<discreteEdge *> bnd; + std::vector<discreteEdge *> emb; hxt_reparam_surf() : oct(NULL) {} ~hxt_reparam_surf(); }; @@ -44,43 +44,41 @@ class triangulation; #endif class discreteFace : public GFace { - private: +private: void checkAndFixOrientation(); #ifdef HAVE_HXT int _current_parametrization; - std::vector< hxt_reparam_surf > _parametrizations; - std::vector<discreteEdge*> e_internals; - std::vector<discreteVertex*> v_internals; + std::vector<hxt_reparam_surf> _parametrizations; + std::vector<discreteEdge *> e_internals; + std::vector<discreteVertex *> v_internals; HXTStatus reparametrize_through_hxt(); - bool compute_topology_of_partition(int nbColors, - int *colors, - int *nNodes, - int *nodes, - double *uv, - double angle_threshold, - std::vector<MVertex*> &c2v, - std::vector<std::vector<MEdge> > &boundaries, - std::vector<std::vector<MEdge> > &internals); + bool + compute_topology_of_partition(int nbColors, int *colors, int *nNodes, + int *nodes, double *uv, double angle_threshold, + std::vector<MVertex *> &c2v, + std::vector<std::vector<MEdge> > &boundaries, + std::vector<std::vector<MEdge> > &internals); #endif - public: +public: discreteFace(GModel *model, int num); virtual ~discreteFace() {} using GFace::point; GPoint point(double par1, double par2) const; - SPoint2 parFromPoint(const SPoint3 &p, bool onSurface=true) const; + SPoint2 parFromPoint(const SPoint3 &p, bool onSurface = true) const; GPoint closestPoint(const SPoint3 &queryPoint, double maxDistance, SVector3 *normal = NULL) const; - GPoint closestPoint(const SPoint3 &queryPoint, const double initialGuess[2]) const; + GPoint closestPoint(const SPoint3 &queryPoint, + const double initialGuess[2]) const; SVector3 normal(const SPoint2 ¶m) const; double curvatureMax(const SPoint2 ¶m) const; double curvatures(const SPoint2 ¶m, SVector3 &dirMax, SVector3 &dirMin, double &curvMax, double &curvMin) const; GEntity::GeomType geomType() const { return DiscreteSurface; } virtual Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m) const; - virtual void secondDer(const SPoint2 ¶m, - SVector3 &dudu, SVector3 &dvdv, SVector3 &dudv) const; + virtual void secondDer(const SPoint2 ¶m, SVector3 &dudu, SVector3 &dvdv, + SVector3 &dudv) const; void writeGEO(FILE *fp); void createGeometry(); virtual void mesh(bool verbose); @@ -89,8 +87,8 @@ class discreteFace : public GFace { const std::vector<int> &signEdges); int trianglePosition(double par1, double par2, double &u, double &v) const; GPoint intersectionWithCircle(const SVector3 &n1, const SVector3 &n2, - const SVector3 &p, const double &R, - double uv[2]) ; + const SVector3 &p, const double &R, + double uv[2]); }; #endif diff --git a/Geo/discreteRegion.cpp b/Geo/discreteRegion.cpp index 3fae80b8f1566a6500dfafcb669408f78072cc5c..4a3dfabfc4eb3e49b2ceaad1dfdfda2609ca00d9 100644 --- a/Geo/discreteRegion.cpp +++ b/Geo/discreteRegion.cpp @@ -23,13 +23,14 @@ discreteRegion::discreteRegion(GModel *model, int num) : GRegion(model, num) void discreteRegion::setBoundFaces(const std::set<int> &tagFaces) { - for (std::set<int>::const_iterator it = tagFaces.begin() ; it != tagFaces.end();++it){ + for(std::set<int>::const_iterator it = tagFaces.begin(); it != tagFaces.end(); + ++it) { GFace *face = model()->getFaceByTag(*it); - if(face){ + if(face) { l_faces.push_back(face); face->addRegion(this); } - else{ + else { Msg::Error("Unknown model face %d", *it); } } @@ -38,48 +39,52 @@ void discreteRegion::setBoundFaces(const std::set<int> &tagFaces) void discreteRegion::setBoundFaces(const std::vector<int> &tagFaces, const std::vector<int> &signFaces) { - if(tagFaces.size() != signFaces.size()){ + if(tagFaces.size() != signFaces.size()) { Msg::Error("Wrong number of face signs in setBoundFaces"); std::set<int> tags; tags.insert(tagFaces.begin(), tagFaces.end()); setBoundFaces(tags); } - for (unsigned int i = 0; i != tagFaces.size(); i++){ + for(unsigned int i = 0; i != tagFaces.size(); i++) { GFace *face = model()->getFaceByTag(tagFaces[i]); - if(face){ + if(face) { l_faces.push_back(face); face->addRegion(this); l_dirs.push_back(signFaces[i]); } - else{ + else { Msg::Error("Unknown model face %d", tagFaces[i]); } } } -void discreteRegion::findFaces(std::map<MFace, std::vector<int>, Less_Face> &map_faces) +void discreteRegion::findFaces( + std::map<MFace, std::vector<int>, Less_Face> &map_faces) { std::set<MFace, Less_Face> bound_faces; - for (unsigned int elem = 0; elem < getNumMeshElements() ; elem++) { + for(unsigned int elem = 0; elem < getNumMeshElements(); elem++) { MElement *e = getMeshElement(elem); - for (int iFace = 0; iFace < e->getNumFaces(); iFace++) { - MFace tmp_face = e->getFace(iFace); - std::set<MFace, Less_Face >::iterator itset = bound_faces.find(tmp_face); - if (itset == bound_faces.end()) bound_faces.insert(tmp_face); - else bound_faces.erase(itset); + for(int iFace = 0; iFace < e->getNumFaces(); iFace++) { + MFace tmp_face = e->getFace(iFace); + std::set<MFace, Less_Face>::iterator itset = bound_faces.find(tmp_face); + if(itset == bound_faces.end()) + bound_faces.insert(tmp_face); + else + bound_faces.erase(itset); } } // for the boundary faces, associate the tag of the discrete face - for (std::set<MFace, Less_Face>::iterator itv = bound_faces.begin(); - itv != bound_faces.end(); ++itv){ - std::map<MFace, std::vector<int>, Less_Face >::iterator itmap = map_faces.find(*itv); - if (itmap == map_faces.end()){ + for(std::set<MFace, Less_Face>::iterator itv = bound_faces.begin(); + itv != bound_faces.end(); ++itv) { + std::map<MFace, std::vector<int>, Less_Face>::iterator itmap = + map_faces.find(*itv); + if(itmap == map_faces.end()) { std::vector<int> tagRegions; tagRegions.push_back(tag()); map_faces.insert(std::make_pair(*itv, tagRegions)); } - else{ + else { std::vector<int> tagRegions = itmap->second; tagRegions.push_back(tag()); itmap->second = tagRegions; @@ -92,25 +97,29 @@ void discreteRegion::remesh() #if defined(HAVE_MESH) bool classify = false; - if(CTX::instance()->mesh.oldRefinement){ + if(CTX::instance()->mesh.oldRefinement) { insertVerticesInRegion(this, 2000000000, classify); } - else{ + else { insertVerticesInRegion(this, 0, classify); - void edgeBasedRefinement(const int numThreads, const int nptsatonce, GRegion *gr); + void edgeBasedRefinement(const int numThreads, const int nptsatonce, + GRegion *gr); edgeBasedRefinement(1, 1, this); } // not functional yet: need boundaries for(int i = 0; i < std::max(CTX::instance()->mesh.optimize, - CTX::instance()->mesh.optimizeNetgen); i++){ - if(CTX::instance()->mesh.optimize >= i){ + CTX::instance()->mesh.optimizeNetgen); + i++) { + if(CTX::instance()->mesh.optimize >= i) { printf("optimizing!\n"); - optimizeMeshGRegionGmsh opt; opt(this, true); + optimizeMeshGRegionGmsh opt; + opt(this, true); } - if(CTX::instance()->mesh.optimizeNetgen >= i){ + if(CTX::instance()->mesh.optimizeNetgen >= i) { printf("optimizing netgen!\n"); - optimizeMeshGRegionNetgen opt; opt(this, true); + optimizeMeshGRegionNetgen opt; + opt(this, true); } } diff --git a/Geo/discreteRegion.h b/Geo/discreteRegion.h index 24d1c6a0418aa7fa9732778c8ce37ee0fab490a5..84d504f9df331bfdbcc33c58aa265ea47258c337 100644 --- a/Geo/discreteRegion.h +++ b/Geo/discreteRegion.h @@ -11,7 +11,7 @@ #include "MFace.h" class discreteRegion : public GRegion { - public: +public: discreteRegion(GModel *model, int num); virtual ~discreteRegion() {} virtual GeomType geomType() const { return DiscreteVolume; } diff --git a/Geo/discreteVertex.h b/Geo/discreteVertex.h index 3446b139aebb8b386873ab6190a6d0bd6350d64d..a64b10b2d1960f76f92ced2eda97531c2a17ca8d 100644 --- a/Geo/discreteVertex.h +++ b/Geo/discreteVertex.h @@ -11,20 +11,20 @@ #include "MVertex.h" class discreteVertex : public GVertex { - public: - discreteVertex(GModel *m, int num) : GVertex(m, num){} - virtual ~discreteVertex(){} +public: + discreteVertex(GModel *m, int num) : GVertex(m, num) {} + virtual ~discreteVertex() {} virtual GPoint point() const { return GPoint(x(), y(), z(), this); } - virtual double x() const - { + virtual double x() const + { return mesh_vertices.size() ? mesh_vertices[0]->x() : 0.; } virtual double y() const - { + { return mesh_vertices.size() ? mesh_vertices[0]->y() : 0.; } virtual double z() const - { + { return mesh_vertices.size() ? mesh_vertices[0]->z() : 0.; } }; diff --git a/Geo/findLinks.cpp b/Geo/findLinks.cpp index e57384e81adaec8a6a044f72dbef6f304e3a825f..e7dd4a9c29a1b83e9700e18d0f1cfadc105ea4cd 100644 --- a/Geo/findLinks.cpp +++ b/Geo/findLinks.cpp @@ -10,26 +10,25 @@ #include "TreeUtils.h" #include "ListUtils.h" -typedef struct{ +typedef struct { int n, a; -}nxa; +} nxa; -typedef struct{ +typedef struct { int n; List_T *l; -}lnk; +} lnk; - -static void freeLink(void * link) +static void freeLink(void *link) { - List_Delete(((lnk*) link)->l); + List_Delete(((lnk *)link)->l); Free(link); } static int complink(const void *a, const void *b) { - lnk *q = (lnk*)a; - lnk *w = (lnk*)b; + lnk *q = (lnk *)a; + lnk *w = (lnk *)b; return q->n - w->n; } @@ -41,7 +40,7 @@ static void recurFindLinkedEdges(int ed, List_T *edges, Tree_T *points, Tree_T *links) { GEdge *ge = GModel::current()->getEdgeByTag(ed); - if(!ge){ + if(!ge) { Msg::Error("Unknown curve %d", ed); return; } @@ -63,7 +62,7 @@ static void recurFindLinkedEdges(int ed, List_T *edges, Tree_T *points, nxa na; List_Read(lk.l, i, &na); if(na.a != ed) { - if(List_ISearchSeq(edges, &na.a, fcmp_absint) < 0){ + if(List_ISearchSeq(edges, &na.a, fcmp_absint) < 0) { List_Add(edges, &na.a); recurFindLinkedEdges(na.a, edges, points, links); } @@ -77,8 +76,9 @@ static int createEdgeLinks(Tree_T *links) { GModel *m = GModel::current(); for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++) { - GEdge *ge = *it;; - if(!ge->getBeginVertex() || !ge->getEndVertex()){ + GEdge *ge = *it; + ; + if(!ge->getBeginVertex() || !ge->getEndVertex()) { Msg::Error("Cannot link curves with no begin or end points"); return 0; } @@ -88,10 +88,10 @@ static int createEdgeLinks(Tree_T *links) int ip[2]; ip[0] = ge->getBeginVertex()->tag(); ip[1] = ge->getEndVertex()->tag(); - for(int k = 0; k < 2; k++){ + for(int k = 0; k < 2; k++) { lnk li, *pli; li.n = ip[k]; - if((pli = (lnk*)Tree_PQuery(links, &li))) { + if((pli = (lnk *)Tree_PQuery(links, &li))) { List_Add(pli->l, &na); } else { @@ -116,35 +116,35 @@ static void orientAndSortEdges(List_T *edges, Tree_T *links) List_Add(edges, &num); GEdge *ge0 = GModel::current()->getEdgeByTag(abs(num)); - if(!ge0){ + if(!ge0) { Msg::Error("Unknown curve %d", abs(num)); List_Delete(temp); return; } int sign = 1; - while(List_Nbr(edges) < List_Nbr(temp)){ + while(List_Nbr(edges) < List_Nbr(temp)) { lnk lk; if(sign > 0) lk.n = ge0->getEndVertex()->tag(); else lk.n = ge0->getBeginVertex()->tag(); Tree_Query(links, &lk); - for(int j = 0; j < List_Nbr(lk.l); j++){ + for(int j = 0; j < List_Nbr(lk.l); j++) { nxa na; List_Read(lk.l, j, &na); - if(ge0->tag() != na.a && List_Search(temp, &na.a, fcmp_absint)){ + if(ge0->tag() != na.a && List_Search(temp, &na.a, fcmp_absint)) { GEdge *ge1 = GModel::current()->getEdgeByTag(abs(na.a)); - if(!ge1){ + if(!ge1) { Msg::Error("Unknown curve %d", abs(na.a)); List_Delete(temp); return; } - if(lk.n == ge1->getBeginVertex()->tag()){ + if(lk.n == ge1->getBeginVertex()->tag()) { sign = 1; num = na.a; } - else{ + else { sign = -1; num = -na.a; } @@ -163,18 +163,18 @@ int allEdgesLinked(int ed, List_T *edges) Tree_T *links = Tree_Create(sizeof(lnk), complink); Tree_T *points = Tree_Create(sizeof(int), fcmp_int); - if(!createEdgeLinks(links)){ + if(!createEdgeLinks(links)) { Tree_Delete(links, freeLink); Tree_Delete(points); return 0; } // initialize point tree with all hanging points - for(int i = 0; i < List_Nbr(edges); i++){ + for(int i = 0; i < List_Nbr(edges); i++) { int num; List_Read(edges, i, &num); GEdge *ge = GModel::current()->getEdgeByTag(abs(num)); - if(!ge){ + if(!ge) { Msg::Error("Unknown curve %d", abs(num)); Tree_Delete(links, freeLink); Tree_Delete(points); @@ -183,7 +183,7 @@ int allEdgesLinked(int ed, List_T *edges) int ip[2]; ip[0] = ge->getBeginVertex()->tag(); ip[1] = ge->getEndVertex()->tag(); - for(int k = 0; k < 2; k++){ + for(int k = 0; k < 2; k++) { if(!Tree_Search(points, &ip[k])) Tree_Add(points, &ip[k]); else @@ -191,14 +191,14 @@ int allEdgesLinked(int ed, List_T *edges) } } - if(List_ISearchSeq(edges, &ed, fcmp_absint) < 0){ + if(List_ISearchSeq(edges, &ed, fcmp_absint) < 0) { List_Add(edges, &ed); recurFindLinkedEdges(ed, edges, points, links); } int found = 0; - if(!Tree_Nbr(points)){ + if(!Tree_Nbr(points)) { found = 1; // at this point we can orient all the edges in a line loop in a // consistent manner (left- or right-oriented, depending on the @@ -220,13 +220,14 @@ static void recurFindLinkedFaces(int fac, List_T *faces, Tree_T *edges, Tree_T *links) { GFace *gf = GModel::current()->getFaceByTag(abs(fac)); - if(!gf){ + if(!gf) { Msg::Error("Unknown surface %d", abs(fac)); return; } - std::vector<GEdge*> const& l = gf->edges(); - for(std::vector<GEdge*>::const_iterator it = l.begin(); it != l.end(); it++) { + std::vector<GEdge *> const &l = gf->edges(); + for(std::vector<GEdge *>::const_iterator it = l.begin(); it != l.end(); + it++) { GEdge *ge = *it; lnk lk; lk.n = std::abs(ge->tag()); @@ -240,7 +241,7 @@ static void recurFindLinkedFaces(int fac, List_T *faces, Tree_T *edges, nxa na; List_Read(lk.l, i, &na); if(na.a != fac) { - if(List_ISearchSeq(faces, &na.a, fcmp_absint) < 0){ + if(List_ISearchSeq(faces, &na.a, fcmp_absint) < 0) { List_Add(faces, &na.a); recurFindLinkedFaces(na.a, faces, edges, links); } @@ -255,15 +256,16 @@ static void createFaceLinks(Tree_T *links) GModel *m = GModel::current(); for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++) { GFace *gf = *it; - if(gf->tag() > 0){ + if(gf->tag() > 0) { nxa na; na.a = gf->tag(); - std::vector<GEdge*> const& l = gf->edges(); - for(std::vector<GEdge*>::const_iterator ite = l.begin(); ite != l.end(); ite++) { + std::vector<GEdge *> const &l = gf->edges(); + for(std::vector<GEdge *>::const_iterator ite = l.begin(); ite != l.end(); + ite++) { GEdge *ge = *ite; lnk li, *pli; li.n = std::abs(ge->tag()); - if((pli = (lnk*)Tree_PQuery(links, &li))) { + if((pli = (lnk *)Tree_PQuery(links, &li))) { List_Add(pli->l, &na); } else { @@ -284,18 +286,19 @@ int allFacesLinked(int fac, List_T *faces) createFaceLinks(links); // initialize edge tree with all boundary edges - for(int i = 0; i < List_Nbr(faces); i++){ + for(int i = 0; i < List_Nbr(faces); i++) { int num; List_Read(faces, i, &num); GFace *gf = GModel::current()->getFaceByTag(abs(num)); - if(!gf){ + if(!gf) { Msg::Error("Unknown surface %d", abs(num)); Tree_Delete(links, freeLink); Tree_Delete(edges); return 0; } - std::vector<GEdge*> const& l = gf->edges(); - for(std::vector<GEdge*>::const_iterator it = l.begin(); it != l.end(); it++) { + std::vector<GEdge *> const &l = gf->edges(); + for(std::vector<GEdge *>::const_iterator it = l.begin(); it != l.end(); + it++) { GEdge *ge = *it; int ic = std::abs(ge->tag()); if(!Tree_Search(edges, &ic)) @@ -305,7 +308,7 @@ int allFacesLinked(int fac, List_T *faces) } } - if(List_ISearchSeq(faces, &fac, fcmp_absint) < 0){ + if(List_ISearchSeq(faces, &fac, fcmp_absint) < 0) { List_Add(faces, &fac); // Warning: this is correct only if the surfaces are defined with // correct orientations, i.e., if the hole boundaries are oriented @@ -316,7 +319,7 @@ int allFacesLinked(int fac, List_T *faces) int found = 0; - if(!Tree_Nbr(edges)){ + if(!Tree_Nbr(edges)) { found = 1; // we could orient the faces here, but it's not really // necessary... diff --git a/Geo/fourierEdge.cpp b/Geo/fourierEdge.cpp index b10ab635ff65de9e9474fe76f61db8b7c0127906..e3938476f04eb28a22d45428b2038ec53a63db4c 100644 --- a/Geo/fourierEdge.cpp +++ b/Geo/fourierEdge.cpp @@ -9,29 +9,29 @@ #if defined(HAVE_FOURIER_MODEL) -fourierEdge::fourierEdge(GModel *model, FM::TopoEdge* edge_, int tag, - GVertex *v0, GVertex *v1) - : GEdge(model, tag, v0, v1), edge(edge_) +fourierEdge::fourierEdge(GModel *model, FM::TopoEdge *edge_, int tag, + GVertex *v0, GVertex *v1) + : GEdge(model, tag, v0, v1), edge(edge_) { } Range<double> fourierEdge::parBounds(int i) const -{ - return(Range<double>(0.,1.)); +{ + return (Range<double>(0., 1.)); } -GPoint fourierEdge::point(double p) const +GPoint fourierEdge::point(double p) const { double x, y, z; - edge->F(p,x,y,z); - return GPoint(x,y,z); + edge->F(p, x, y, z); + return GPoint(x, y, z); } SVector3 fourierEdge::firstDer(double par) const { - double x,y,z; - edge->Dfdt(par,x,y,z); - return SVector3(x,y,z); + double x, y, z; + edge->Dfdt(par, x, y, z); + return SVector3(x, y, z); } int fourierEdge::minimumMeshSegments() const diff --git a/Geo/fourierEdge.h b/Geo/fourierEdge.h index 3ff5e699bd10a4aef604545c664871fa354cf45a..1952bbe8a7bfd3da9cb1e48d59b0617e7a6e3da3 100644 --- a/Geo/fourierEdge.h +++ b/Geo/fourierEdge.h @@ -17,18 +17,20 @@ #include "FM_TopoFace.h" class fourierEdge : public GEdge { - protected: +protected: FM::TopoEdge *edge; int edgeNum; - public: - fourierEdge(GModel *model, FM::TopoEdge *edge_, int tag, GVertex *v0, GVertex *v1); + +public: + fourierEdge(GModel *model, FM::TopoEdge *edge_, int tag, GVertex *v0, + GVertex *v1); virtual ~fourierEdge() {} virtual Range<double> parBounds(int i) const; virtual GeomType geomType() const { return ParametricCurve; } virtual GPoint point(double p) const; virtual SVector3 firstDer(double par) const; - virtual int minimumMeshSegments () const; - virtual int minimumDrawSegments () const; + virtual int minimumMeshSegments() const; + virtual int minimumDrawSegments() const; ModelType getNativeType() const { return FourierModel; } }; diff --git a/Geo/fourierFace.cpp b/Geo/fourierFace.cpp index d7702df21ad58f5e6e42eab88a94ad3b08e4ed30..d5348325489ec27569b32f3266b49e16cad1b988 100644 --- a/Geo/fourierFace.cpp +++ b/Geo/fourierFace.cpp @@ -12,11 +12,11 @@ #if defined(HAVE_FOURIER_MODEL) fourierFace::fourierFace(GModel *m, FM::TopoFace *face_, int tag, - std::list<GEdge*> l_edges_) - : GFace(m,tag), face(face_) + std::list<GEdge *> l_edges_) + : GFace(m, tag), face(face_) { - for (std::list<GEdge*>::iterator it = l_edges_.begin(); - it != l_edges_.end(); it++) { + for(std::list<GEdge *>::iterator it = l_edges_.begin(); it != l_edges_.end(); + it++) { l_edges.push_back((*it)); l_dirs.push_back(1); } @@ -25,22 +25,24 @@ fourierFace::fourierFace(GModel *m, FM::TopoFace *face_, int tag, Range<double> fourierFace::parBounds(int i) const { - return Range<double>(0.,1.); + return Range<double>(0., 1.); } GPoint fourierFace::point(double par1, double par2) const { - double pp[2] = {par1,par2}; - double x,y,z; - face->F(par1,par2,x,y,z); + double pp[2] = {par1, par2}; + double x, y, z; + face->F(par1, par2, x, y, z); return GPoint(x, y, z, this, pp); } SPoint2 fourierFace::parFromPoint(const SPoint3 &p, bool onSurface) const { double u, v, x, y, z; - x = p.x(); y = p.y(); z = p.z(); - face->Inverse(x,y,z,u,v); + x = p.x(); + y = p.y(); + z = p.z(); + face->Inverse(x, y, z, u, v); return SPoint2(u, v); } @@ -55,14 +57,14 @@ bool fourierFace::containsParam(const SPoint2 &pt) const SVector3 fourierFace::normal(const SPoint2 ¶m) const { - double x,y,z; - face->GetUnitNormal(param[0],param[1],x,y,z); + double x, y, z; + face->GetUnitNormal(param[0], param[1], x, y, z); return SVector3(x, y, z); } GEntity::GeomType fourierFace::geomType() const { - return GEntity::ParametricSurface; + return GEntity::ParametricSurface; } Pair<SVector3, SVector3> fourierFace::firstDer(const SPoint2 ¶m) const @@ -71,10 +73,11 @@ Pair<SVector3, SVector3> fourierFace::firstDer(const SPoint2 ¶m) const return Pair<SVector3, SVector3>(); } -void fourierFace::secondDer(const SPoint2 ¶m, - SVector3 &dudu, SVector3 &dvdv, SVector3 &dudv) const +void fourierFace::secondDer(const SPoint2 ¶m, SVector3 &dudu, + SVector3 &dvdv, SVector3 &dudv) const { - Msg::Error("Computation of the second derivatives not implemented for fourier face"); + Msg::Error( + "Computation of the second derivatives not implemented for fourier face"); } #endif diff --git a/Geo/fourierFace.h b/Geo/fourierFace.h index e1014cc3f2f3287b6c26e82f66660b747d96af94..bddf3dfaec53ad1bd255ca8d5149d7ff56e4e999 100644 --- a/Geo/fourierFace.h +++ b/Geo/fourierFace.h @@ -17,19 +17,22 @@ #include "FM_TopoFace.h" class fourierFace : public GFace { - protected: +protected: FM::TopoFace *face; - public: - fourierFace(GModel *m, FM::TopoFace *face_, int tag, std::list<GEdge*> l_edges_); + +public: + fourierFace(GModel *m, FM::TopoFace *face_, int tag, + std::list<GEdge *> l_edges_); virtual ~fourierFace() {} Range<double> parBounds(int i) const; virtual GPoint point(double par1, double par2) const; - virtual SPoint2 parFromPoint(const SPoint3 &p, bool onSurface=true) const; + virtual SPoint2 parFromPoint(const SPoint3 &p, bool onSurface = true) const; virtual bool containsParam(const SPoint2 &pt) const; virtual SVector3 normal(const SPoint2 ¶m) const; virtual GEntity::GeomType geomType() const; - virtual Pair<SVector3,SVector3> firstDer(const SPoint2 ¶m) const; - virtual void secondDer(const SPoint2 &, SVector3 &, SVector3 &, SVector3 &) const; + virtual Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m) const; + virtual void secondDer(const SPoint2 &, SVector3 &, SVector3 &, + SVector3 &) const; ModelType getNativeType() const { return FourierModel; } void *getNativePtr() const { return face; } }; diff --git a/Geo/fourierProjectionFace.cpp b/Geo/fourierProjectionFace.cpp index 0f0953d09e763e1bb2f83256666aedf83b7eb279..ab9900c60d95b70488f1723d4e253bbcbf1c128a 100644 --- a/Geo/fourierProjectionFace.cpp +++ b/Geo/fourierProjectionFace.cpp @@ -10,8 +10,9 @@ #if defined(HAVE_FOURIER_MODEL) -fourierProjectionFace::fourierProjectionFace(GModel *m, int num, FM::ProjectionSurface* ps) - : GFace(m,num), ps_(ps) +fourierProjectionFace::fourierProjectionFace(GModel *m, int num, + FM::ProjectionSurface *ps) + : GFace(m, num), ps_(ps) { buildSTLTriangulation(); } @@ -25,30 +26,32 @@ GPoint fourierProjectionFace::point(double par1, double par2) const return GPoint(p[0], p[1], p[2]); } -SPoint2 fourierProjectionFace::parFromPoint(const SPoint3 &p, bool onSurface) const -{ - double u,v; +SPoint2 fourierProjectionFace::parFromPoint(const SPoint3 &p, + bool onSurface) const +{ + double u, v; ps_->Inverse(p[0], p[1], p[2], u, v); return SPoint2(u, v); } -Pair<SVector3,SVector3> fourierProjectionFace::firstDer(const SPoint2 ¶m) const +Pair<SVector3, SVector3> +fourierProjectionFace::firstDer(const SPoint2 ¶m) const { SVector3 du; SVector3 dv; ps_->Dfdu(param.x(), param.y(), du[0], du[1], du[2]); ps_->Dfdv(param.x(), param.y(), dv[0], dv[1], dv[2]); - return Pair<SVector3,SVector3>(du, dv); -} + return Pair<SVector3, SVector3>(du, dv); +} -void fourierProjectionFace::secondDer(const SPoint2 ¶m, - SVector3 *dudu, SVector3 *dvdv, SVector3 *dudv) const +void fourierProjectionFace::secondDer(const SPoint2 ¶m, SVector3 *dudu, + SVector3 *dvdv, SVector3 *dudv) const { Msg::Error("Computation of the second derivatives not implemented"); } SVector3 fourierProjectionFace::normal(const SPoint2 ¶m) const -{ +{ double x, y, z; ps_->GetUnitNormal(param.x(), param.y(), x, y, z); return SVector3(x, y, z); diff --git a/Geo/fourierProjectionFace.h b/Geo/fourierProjectionFace.h index 28203cf44ac33ab0101106a3f81a6bd3e747703c..7229e8859596c84db2a6813a30fb7a0fb02cc46d 100644 --- a/Geo/fourierProjectionFace.h +++ b/Geo/fourierProjectionFace.h @@ -15,20 +15,21 @@ #include "FM_ProjectionSurface.h" class fourierProjectionFace : public GFace { - protected: +protected: FM::ProjectionSurface *ps_; - public: - fourierProjectionFace(GModel *m, int num, FM::ProjectionSurface* ps); + +public: + fourierProjectionFace(GModel *m, int num, FM::ProjectionSurface *ps); ~fourierProjectionFace(); Range<double> parBounds(int i) const; - GPoint point(double par1, double par2) const; - SVector3 normal(const SPoint2 ¶m) const; - Pair<SVector3,SVector3> firstDer(const SPoint2 ¶m) const; - void secondDer(const SPoint2 &, SVector3 *, SVector3 *, SVector3 *) const; - SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const; + GPoint point(double par1, double par2) const; + SVector3 normal(const SPoint2 ¶m) const; + Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m) const; + void secondDer(const SPoint2 &, SVector3 *, SVector3 *, SVector3 *) const; + SPoint2 parFromPoint(const SPoint3 &, bool onSurface = true) const; virtual GEntity::GeomType geomType() const { return GEntity::ProjectionFace; } ModelType getNativeType() const { return UnknownModel; } - void *getNativePtr() const { return ps_; } + void *getNativePtr() const { return ps_; } }; #endif diff --git a/Geo/fourierVertex.h b/Geo/fourierVertex.h index 810a8c759c1d0558b0c52b99fdd94d4ef3f66bef..43d13fe887fe1e066090cddcdf26c148ef859edf 100644 --- a/Geo/fourierVertex.h +++ b/Geo/fourierVertex.h @@ -16,12 +16,15 @@ #include "FM_TopoVertex.h" class fourierVertex : public GVertex { - protected: +protected: FM::TopoVertex *v; - public: - fourierVertex(GModel *m, int num, FM::TopoVertex* _v) : GVertex(m, num), v(_v){} + +public: + fourierVertex(GModel *m, int num, FM::TopoVertex *_v) : GVertex(m, num), v(_v) + { + } virtual ~fourierVertex() {} - virtual GPoint point() const { return GPoint(x(),y(),z()); } + virtual GPoint point() const { return GPoint(x(), y(), z()); } virtual double x() const { return v->GetX(); } virtual double y() const { return v->GetY(); } virtual double z() const { return v->GetZ(); } diff --git a/Geo/ghostEdge.h b/Geo/ghostEdge.h index d2c778a125fbb23a75e6b46c79da20770822a5c1..7165728346a2e4b82c6a3d8df7a336dbfa8431f9 100644 --- a/Geo/ghostEdge.h +++ b/Geo/ghostEdge.h @@ -13,47 +13,58 @@ #include "MLine.h" class ghostEdge : public discreteEdge { - private: +private: unsigned int _partitions; - std::map<MElement*, unsigned int> _ghostCells; + std::map<MElement *, unsigned int> _ghostCells; bool _saveMesh; bool _haveMesh; - public: + +public: ghostEdge(GModel *model, const int num, const unsigned int partitions) - : discreteEdge(model, num, NULL, NULL), _partitions(partitions), - _ghostCells(), _saveMesh(false), _haveMesh(false) {} + : discreteEdge(model, num, NULL, NULL), _partitions(partitions), + _ghostCells(), _saveMesh(false), _haveMesh(false) + { + } virtual ~ghostEdge() { - if(!_haveMesh){ + if(!_haveMesh) { lines.clear(); mesh_vertices.clear(); } } virtual GeomType geomType() const { return GhostCurve; } - virtual void setPartition(const unsigned int partitions) { _partitions = partitions; } + virtual void setPartition(const unsigned int partitions) + { + _partitions = partitions; + } virtual unsigned int getPartition() const { return _partitions; } bool saveMesh() const { return _saveMesh; } void saveMesh(bool saveMesh) { _saveMesh = saveMesh; } bool haveMesh() const { return _haveMesh; } void haveMesh(bool haveMesh) { _haveMesh = haveMesh; } - virtual std::map<MElement*, unsigned int> &getGhostCells() { return _ghostCells; } - + virtual std::map<MElement *, unsigned int> &getGhostCells() + { + return _ghostCells; + } + void addLine(MLine *l, unsigned int onWhichPartition) { GEdge::addLine(l); - _ghostCells.insert(std::pair<MElement*, unsigned int>(l,onWhichPartition)); - model()->addGhostCells(l,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(l, onWhichPartition)); + model()->addGhostCells(l, onWhichPartition); } void addElement(int type, MElement *e, unsigned int onWhichPartition) { GEdge::addElement(type, e); - _ghostCells.insert(std::pair<MElement*, unsigned int>(e,onWhichPartition)); - model()->addGhostCells(e,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(e, onWhichPartition)); + model()->addGhostCells(e, onWhichPartition); } - + // To make the hidden function visible in ghostEdge - using discreteEdge::addLine; using discreteEdge::addElement; + using discreteEdge::addLine; }; #endif diff --git a/Geo/ghostFace.h b/Geo/ghostFace.h index e858f51c25af56f23a9095335b613252528cc1cf..a29e45bc25c1abedb92dd93b81ce5119d10c2d1a 100644 --- a/Geo/ghostFace.h +++ b/Geo/ghostFace.h @@ -15,18 +15,21 @@ #include "MElementCut.h" class ghostFace : public discreteFace { - private: +private: unsigned int _partitions; - std::map<MElement*, unsigned int> _ghostCells; + std::map<MElement *, unsigned int> _ghostCells; bool _saveMesh; bool _haveMesh; - public: + +public: ghostFace(GModel *model, const int num, const unsigned int partitions) - : discreteFace(model, num), _partitions(partitions), _ghostCells(), - _saveMesh(false), _haveMesh(false) {} + : discreteFace(model, num), _partitions(partitions), _ghostCells(), + _saveMesh(false), _haveMesh(false) + { + } virtual ~ghostFace() { - if(!_haveMesh){ + if(!_haveMesh) { triangles.clear(); quadrangles.clear(); polygons.clear(); @@ -34,43 +37,53 @@ class ghostFace : public discreteFace { } } virtual GeomType geomType() const { return GhostSurface; } - virtual void setPartition(const unsigned int partitions) { _partitions = partitions; } + virtual void setPartition(const unsigned int partitions) + { + _partitions = partitions; + } virtual unsigned int getPartition() const { return _partitions; } bool saveMesh() const { return _saveMesh; } void saveMesh(bool saveMesh) { _saveMesh = saveMesh; } bool haveMesh() const { return _haveMesh; } void haveMesh(bool haveMesh) { _haveMesh = haveMesh; } - virtual std::map<MElement*, unsigned int> &getGhostCells() { return _ghostCells; } + virtual std::map<MElement *, unsigned int> &getGhostCells() + { + return _ghostCells; + } virtual void addTriangle(MTriangle *t, unsigned int onWhichPartition) { GFace::addTriangle(t); - _ghostCells.insert(std::pair<MElement*, unsigned int>(t,onWhichPartition)); - model()->addGhostCells(t,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(t, onWhichPartition)); + model()->addGhostCells(t, onWhichPartition); } virtual void addQuadrangle(MQuadrangle *q, unsigned int onWhichPartition) { GFace::addQuadrangle(q); - _ghostCells.insert(std::pair<MElement*, unsigned int>(q,onWhichPartition)); - model()->addGhostCells(q,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(q, onWhichPartition)); + model()->addGhostCells(q, onWhichPartition); } virtual void addPolygon(MPolygon *p, unsigned int onWhichPartition) { GFace::addPolygon(p); - _ghostCells.insert(std::pair<MElement*, unsigned int>(p,onWhichPartition)); - model()->addGhostCells(p,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(p, onWhichPartition)); + model()->addGhostCells(p, onWhichPartition); } virtual void addElement(int type, MElement *e, unsigned int onWhichPartition) { GFace::addElement(type, e); - _ghostCells.insert(std::pair<MElement*, unsigned int>(e,onWhichPartition)); - model()->addGhostCells(e,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(e, onWhichPartition)); + model()->addGhostCells(e, onWhichPartition); } - + // To make the hidden function visible in ghostFace - using discreteFace::addTriangle; - using discreteFace::addQuadrangle; using discreteFace::addElement; + using discreteFace::addQuadrangle; + using discreteFace::addTriangle; }; #endif diff --git a/Geo/ghostRegion.h b/Geo/ghostRegion.h index 73dd91ba39488927683ae7711b9a1d14bacf95b5..cef5ab92aad50fa5b7359719e1201e2701339b47 100644 --- a/Geo/ghostRegion.h +++ b/Geo/ghostRegion.h @@ -16,18 +16,21 @@ #include "MElementCut.h" class ghostRegion : public discreteRegion { - private: +private: unsigned int _partitions; - std::map<MElement*, unsigned int> _ghostCells; + std::map<MElement *, unsigned int> _ghostCells; bool _saveMesh; bool _haveMesh; - public: + +public: ghostRegion(GModel *model, const int num, const unsigned int partitions) - : discreteRegion(model, num), _partitions(partitions), _ghostCells(), - _saveMesh(false), _haveMesh(false) {} + : discreteRegion(model, num), _partitions(partitions), _ghostCells(), + _saveMesh(false), _haveMesh(false) + { + } virtual ~ghostRegion() { - if(!_haveMesh){ + if(!_haveMesh) { tetrahedra.clear(); hexahedra.clear(); prisms.clear(); @@ -38,65 +41,78 @@ class ghostRegion : public discreteRegion { } } virtual GeomType geomType() const { return GhostVolume; } - virtual void setPartition(const unsigned int partitions) { _partitions = partitions; } + virtual void setPartition(const unsigned int partitions) + { + _partitions = partitions; + } virtual unsigned int getPartition() const { return _partitions; } bool saveMesh() const { return _saveMesh; } void saveMesh(bool saveMesh) { _saveMesh = saveMesh; } bool haveMesh() const { return _haveMesh; } void haveMesh(bool haveMesh) { _haveMesh = haveMesh; } - virtual std::map<MElement*, unsigned int> &getGhostCells() { return _ghostCells; } - + virtual std::map<MElement *, unsigned int> &getGhostCells() + { + return _ghostCells; + } + void addTetrahedron(MTetrahedron *t, unsigned int onWhichPartition) { GRegion::addTetrahedron(t); - _ghostCells.insert(std::pair<MElement*, unsigned int>(t,onWhichPartition)); - model()->addGhostCells(t,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(t, onWhichPartition)); + model()->addGhostCells(t, onWhichPartition); } void addHexahedron(MHexahedron *h, unsigned int onWhichPartition) { GRegion::addHexahedron(h); - _ghostCells.insert(std::pair<MElement*, unsigned int>(h,onWhichPartition)); - model()->addGhostCells(h,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(h, onWhichPartition)); + model()->addGhostCells(h, onWhichPartition); } void addPrism(MPrism *p, unsigned int onWhichPartition) { GRegion::addPrism(p); - _ghostCells.insert(std::pair<MElement*, unsigned int>(p,onWhichPartition)); - model()->addGhostCells(p,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(p, onWhichPartition)); + model()->addGhostCells(p, onWhichPartition); } void addPyramid(MPyramid *p, unsigned int onWhichPartition) { GRegion::addPyramid(p); - _ghostCells.insert(std::pair<MElement*, unsigned int>(p,onWhichPartition)); - model()->addGhostCells(p,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(p, onWhichPartition)); + model()->addGhostCells(p, onWhichPartition); } void addPolyhedron(MPolyhedron *p, unsigned int onWhichPartition) { GRegion::addPolyhedron(p); - _ghostCells.insert(std::pair<MElement*, unsigned int>(p,onWhichPartition)); - model()->addGhostCells(p,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(p, onWhichPartition)); + model()->addGhostCells(p, onWhichPartition); } void addTrihedron(MTrihedron *t, unsigned int onWhichPartition) { GRegion::addTrihedron(t); - _ghostCells.insert(std::pair<MElement*, unsigned int>(t,onWhichPartition)); - model()->addGhostCells(t,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(t, onWhichPartition)); + model()->addGhostCells(t, onWhichPartition); } void addElement(int type, MElement *e, unsigned int onWhichPartition) { GRegion::addElement(type, e); - _ghostCells.insert(std::pair<MElement*, unsigned int>(e,onWhichPartition)); - model()->addGhostCells(e,onWhichPartition); + _ghostCells.insert( + std::pair<MElement *, unsigned int>(e, onWhichPartition)); + model()->addGhostCells(e, onWhichPartition); } - + // To make the hidden function visible in ghostRegion - using discreteRegion::addTetrahedron; + using discreteRegion::addElement; using discreteRegion::addHexahedron; + using discreteRegion::addPolyhedron; using discreteRegion::addPrism; using discreteRegion::addPyramid; - using discreteRegion::addPolyhedron; + using discreteRegion::addTetrahedron; using discreteRegion::addTrihedron; - using discreteRegion::addElement; }; #endif diff --git a/Geo/gmshEdge.cpp b/Geo/gmshEdge.cpp index 6f447fa41e292b1b9f1994050a72d639c74557f2..319894972ef6a92d732bf8b1ce89c74d5a471bf9 100644 --- a/Geo/gmshEdge.cpp +++ b/Geo/gmshEdge.cpp @@ -22,16 +22,16 @@ gmshEdge::gmshEdge(GModel *m, Curve *edge, GVertex *v1, GVertex *v2) void gmshEdge::resetNativePtr(Curve *edge, GVertex *_v1, GVertex *_v2) { c = edge; - v0 = _v1; v1 = _v2; + v0 = _v1; + v1 = _v2; if(v0) v0->addEdge(this); if(v1 && v1 != v0) v1->addEdge(this); } bool gmshEdge::degenerate(int dim) const { - if (c->beg == c->end && - c->Typ == MSH_SEGM_LINE && - List_Nbr(c->Control_Points) == 0){ + if(c->beg == c->end && c->Typ == MSH_SEGM_LINE && + List_Nbr(c->Control_Points) == 0) { Msg::Info("Model Edge %d is degenerate", tag()); return true; } @@ -50,7 +50,7 @@ void gmshEdge::resetMeshAttributes() Range<double> gmshEdge::parBounds(int i) const { - return Range<double>(c->ubeg, c->uend); + return Range<double>(c->ubeg, c->uend); } GPoint gmshEdge::point(double par) const @@ -73,10 +73,10 @@ SVector3 gmshEdge::secondDer(double par) const GEntity::GeomType gmshEdge::geomType() const { - switch (c->Typ){ - case MSH_SEGM_LINE : return Line; - case MSH_SEGM_CIRC : - case MSH_SEGM_CIRC_INV : return Circle; + switch(c->Typ) { + case MSH_SEGM_LINE: return Line; + case MSH_SEGM_CIRC: + case MSH_SEGM_CIRC_INV: return Circle; case MSH_SEGM_ELLI: case MSH_SEGM_ELLI_INV: return Ellipse; case MSH_SEGM_BSPLN: @@ -85,40 +85,41 @@ GEntity::GeomType gmshEdge::geomType() const case MSH_SEGM_SPLN: return Nurb; case MSH_SEGM_BND_LAYER: return BoundaryLayerCurve; case MSH_SEGM_DISCRETE: return DiscreteCurve; - default : return Unknown; + default: return Unknown; } } std::string gmshEdge::getAdditionalInfoString(bool multline) { - if(List_Nbr(c->Control_Points) > 0){ + if(List_Nbr(c->Control_Points) > 0) { std::ostringstream sstream; sstream << "Control points: "; - for(int i = 0; i < List_Nbr(c->Control_Points); i++){ + for(int i = 0; i < List_Nbr(c->Control_Points); i++) { if(i) sstream << ", "; Vertex *v; List_Read(c->Control_Points, i, &v); sstream << v->Num; } - if(meshAttributes.method == MESH_TRANSFINITE || - meshAttributes.extrude || meshAttributes.reverseMesh){ - if(multline) sstream << "\n"; - else sstream << " "; + if(meshAttributes.method == MESH_TRANSFINITE || meshAttributes.extrude || + meshAttributes.reverseMesh) { + if(multline) + sstream << "\n"; + else + sstream << " "; sstream << "Mesh attributes:"; - if(meshAttributes.method == MESH_TRANSFINITE){ + if(meshAttributes.method == MESH_TRANSFINITE) { sstream << " transfinite (" << meshAttributes.nbPointsTransfinite; int type = meshAttributes.typeTransfinite; if(std::abs(type) == 1) - sstream << ", progression " << gmsh_sign(type) * meshAttributes.coeffTransfinite; + sstream << ", progression " + << gmsh_sign(type) * meshAttributes.coeffTransfinite; else if(std::abs(type) == 2) sstream << ", bump " << meshAttributes.coeffTransfinite; sstream << ")"; } - if(meshAttributes.extrude) - sstream << " extruded"; - if(meshAttributes.reverseMesh) - sstream << " reversed"; + if(meshAttributes.extrude) sstream << " extruded"; + if(meshAttributes.reverseMesh) sstream << " reversed"; } return sstream.str(); } @@ -126,25 +127,26 @@ std::string gmshEdge::getAdditionalInfoString(bool multline) return GEdge::getAdditionalInfoString(); } -int gmshEdge::minimumMeshSegments () const +int gmshEdge::minimumMeshSegments() const { int np; - if(geomType() == Line){ + if(geomType() == Line) { np = GEdge::minimumMeshSegments(); // FIXME FOR QUADS - if(List_Nbr(c->Control_Points) > 2){ + if(List_Nbr(c->Control_Points) > 2) { np = 3 * (List_Nbr(c->Control_Points)) + 1; } } else if(geomType() == Circle || geomType() == Ellipse) np = (int)(0.99 + fabs(c->Circle.t1 - c->Circle.t2) * - ((double)CTX::instance()->mesh.minCircPoints - 1.0) / (2 * M_PI)); + ((double)CTX::instance()->mesh.minCircPoints - 1.0) / + (2 * M_PI)); else np = CTX::instance()->mesh.minCurvPoints - 1; return std::max(np, meshAttributes.minimumMeshSegments); } -int gmshEdge::minimumDrawSegments () const +int gmshEdge::minimumDrawSegments() const { int n = List_Nbr(c->Control_Points) - 1; if(!n) n = GEdge::minimumDrawSegments(); @@ -155,212 +157,200 @@ int gmshEdge::minimumDrawSegments () const return CTX::instance()->geom.numSubEdges * n; } -SPoint2 gmshEdge::reparamOnFace(const GFace *face, double epar,int dir) const +SPoint2 gmshEdge::reparamOnFace(const GFace *face, double epar, int dir) const { - Surface *s = (Surface*) face->getNativePtr(); + Surface *s = (Surface *)face->getNativePtr(); bool periodic = (c->end == c->beg); - if(s->geometry){ - switch (c->Typ) { - case MSH_SEGM_LINE: - { - Vertex *v[3]; - List_Read(c->Control_Points, 0, &v[1]); - List_Read(c->Control_Points, 1, &v[2]); - SPoint2 p = v[1]->pntOnGeometry + - (v[2]->pntOnGeometry - v[1]->pntOnGeometry) * epar; - return p; - } + if(s->geometry) { + switch(c->Typ) { + case MSH_SEGM_LINE: { + Vertex *v[3]; + List_Read(c->Control_Points, 0, &v[1]); + List_Read(c->Control_Points, 1, &v[2]); + SPoint2 p = v[1]->pntOnGeometry + + (v[2]->pntOnGeometry - v[1]->pntOnGeometry) * epar; + return p; + } case MSH_SEGM_BSPLN: - case MSH_SEGM_BEZIER: - { - int NbControlPoints = List_Nbr(c->Control_Points); - int NbCurves = NbControlPoints + (periodic ? -1 : 1); - int iCurve = (int)floor(epar * (double)NbCurves); - if(iCurve >= NbCurves) - iCurve = NbCurves - 1; - else if (iCurve < 0) // ? does it happen ? - iCurve = 0; - double t1 = (double)(iCurve) / (double)(NbCurves); - double t2 = (double)(iCurve+1) / (double)(NbCurves); - double t = (epar - t1) / (t2 - t1); - Vertex *v[4]; - for(int j = 0; j < 4; j ++ ){ - int k = iCurve - (periodic ? 1 : 2) + j; - if(k < 0) - k = periodic ? k + NbControlPoints - 1 : 0; - if(k >= NbControlPoints) - k = periodic ? k - NbControlPoints + 1: NbControlPoints - 1; - List_Read(c->Control_Points, k, &v[j]); - } - return InterpolateCubicSpline(v, t, c->mat, t1, t2, c->geometry,0); + case MSH_SEGM_BEZIER: { + int NbControlPoints = List_Nbr(c->Control_Points); + int NbCurves = NbControlPoints + (periodic ? -1 : 1); + int iCurve = (int)floor(epar * (double)NbCurves); + if(iCurve >= NbCurves) + iCurve = NbCurves - 1; + else if(iCurve < 0) // ? does it happen ? + iCurve = 0; + double t1 = (double)(iCurve) / (double)(NbCurves); + double t2 = (double)(iCurve + 1) / (double)(NbCurves); + double t = (epar - t1) / (t2 - t1); + Vertex *v[4]; + for(int j = 0; j < 4; j++) { + int k = iCurve - (periodic ? 1 : 2) + j; + if(k < 0) k = periodic ? k + NbControlPoints - 1 : 0; + if(k >= NbControlPoints) + k = periodic ? k - NbControlPoints + 1 : NbControlPoints - 1; + List_Read(c->Control_Points, k, &v[j]); } - case MSH_SEGM_SPLN : - { - Vertex temp1, temp2; - int N = List_Nbr(c->Control_Points); - int i = (int)((double)(N - 1) * epar); - if(i < 0) - i = 0; - if(i >= N - 1) - i = N - 2; - double t1 = (double)(i) / (double)(N - 1); - double t2 = (double)(i + 1) / (double)(N - 1); - double t = (epar - t1) / (t2 - t1); - Vertex *v[4]; - List_Read(c->Control_Points, i, &v[1]); - List_Read(c->Control_Points, i + 1, &v[2]); - if(!i) { - if(c->beg == c->end){ - List_Read(c->Control_Points,N-2,&v[0]); - } - else{ - v[0] = &temp1; - v[0]->pntOnGeometry = v[1]->pntOnGeometry * 2. - v[2]->pntOnGeometry; - } + return InterpolateCubicSpline(v, t, c->mat, t1, t2, c->geometry, 0); + } + case MSH_SEGM_SPLN: { + Vertex temp1, temp2; + int N = List_Nbr(c->Control_Points); + int i = (int)((double)(N - 1) * epar); + if(i < 0) i = 0; + if(i >= N - 1) i = N - 2; + double t1 = (double)(i) / (double)(N - 1); + double t2 = (double)(i + 1) / (double)(N - 1); + double t = (epar - t1) / (t2 - t1); + Vertex *v[4]; + List_Read(c->Control_Points, i, &v[1]); + List_Read(c->Control_Points, i + 1, &v[2]); + if(!i) { + if(c->beg == c->end) { + List_Read(c->Control_Points, N - 2, &v[0]); } - else{ - List_Read(c->Control_Points, i - 1, &v[0]); + else { + v[0] = &temp1; + v[0]->pntOnGeometry = v[1]->pntOnGeometry * 2. - v[2]->pntOnGeometry; } - if(i == N - 2) { - if(c->beg == c->end){ - List_Read(c->Control_Points,1,&v[3]); - } - else{ - v[3] = &temp2; - v[3]->pntOnGeometry = v[2]->pntOnGeometry * 2. - v[1]->pntOnGeometry; - } + } + else { + List_Read(c->Control_Points, i - 1, &v[0]); + } + if(i == N - 2) { + if(c->beg == c->end) { + List_Read(c->Control_Points, 1, &v[3]); } - else{ - List_Read(c->Control_Points, i + 2, &v[3]); + else { + v[3] = &temp2; + v[3]->pntOnGeometry = v[2]->pntOnGeometry * 2. - v[1]->pntOnGeometry; } - return InterpolateCubicSpline(v, t, c->mat, t1, t2, c->geometry,0); } - default: - Msg::Error("Unknown edge type in reparamOnFace"); - return SPoint2(); + else { + List_Read(c->Control_Points, i + 2, &v[3]); + } + return InterpolateCubicSpline(v, t, c->mat, t1, t2, c->geometry, 0); + } + default: Msg::Error("Unknown edge type in reparamOnFace"); return SPoint2(); } } - - if(s->Typ == MSH_SURF_REGL){ + if(s->Typ == MSH_SURF_REGL) { Curve *C[4]; - for(int i = 0; i < 4; i++) - List_Read(s->Generatrices, i, &C[i]); + for(int i = 0; i < 4; i++) List_Read(s->Generatrices, i, &C[i]); double U, V; - if (C[0]->Num == c->Num) { - U = (epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg) ; + if(C[0]->Num == c->Num) { + U = (epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg); V = 0; } - else if (C[0]->Num == -c->Num) { - U = (C[0]->uend - epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg) ; + else if(C[0]->Num == -c->Num) { + U = (C[0]->uend - epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg); V = 0; } - else if (C[1]->Num == c->Num) { - V = (epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg) ; + else if(C[1]->Num == c->Num) { + V = (epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg); U = 1; } - else if (C[1]->Num == -c->Num) { - V = (C[1]->uend - epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg) ; + else if(C[1]->Num == -c->Num) { + V = (C[1]->uend - epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg); U = 1; } - else if (C[2]->Num == c->Num) { - U = 1 - (epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg) ; + else if(C[2]->Num == c->Num) { + U = 1 - (epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg); V = 1; } - else if (C[2]->Num == -c->Num) { - U = 1 - ( C[2]->uend -epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg) ; + else if(C[2]->Num == -c->Num) { + U = 1 - (C[2]->uend - epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg); V = 1; } - else if (C[3]->Num == c->Num) { - V = 1-(epar - C[3]->ubeg) / (C[3]->uend - C[3]->ubeg) ; + else if(C[3]->Num == c->Num) { + V = 1 - (epar - C[3]->ubeg) / (C[3]->uend - C[3]->ubeg); U = 0; } - else if (C[3]->Num == -c->Num) { - V = 1-(C[3]->uend - epar - C[3]->ubeg) / (C[3]->uend - C[3]->ubeg) ; + else if(C[3]->Num == -c->Num) { + V = 1 - (C[3]->uend - epar - C[3]->ubeg) / (C[3]->uend - C[3]->ubeg); U = 0; } - else{ + else { Msg::Info("Reparameterizing edge %d on face %d", c->Num, s->Num); return GEdge::reparamOnFace(face, epar, dir); } return SPoint2(U, V); } - else if (s->Typ == MSH_SURF_TRIC){ + else if(s->Typ == MSH_SURF_TRIC) { Curve *C[3]; - for(int i = 0; i < 3; i++) - List_Read(s->Generatrices, i, &C[i]); + for(int i = 0; i < 3; i++) List_Read(s->Generatrices, i, &C[i]); double U, V; - if(CTX::instance()->geom.oldRuledSurface){ - if (C[0]->Num == c->Num) { - U = (epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg) ; + if(CTX::instance()->geom.oldRuledSurface) { + if(C[0]->Num == c->Num) { + U = (epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg); V = 0; } - else if (C[0]->Num == -c->Num) { - U = (C[0]->uend - epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg) ; + else if(C[0]->Num == -c->Num) { + U = (C[0]->uend - epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg); V = 0; } - else if (C[1]->Num == c->Num) { - V = (epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg) ; + else if(C[1]->Num == c->Num) { + V = (epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg); U = 1; } - else if (C[1]->Num == -c->Num) { - V = (C[1]->uend - epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg) ; + else if(C[1]->Num == -c->Num) { + V = (C[1]->uend - epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg); U = 1; } - else if (C[2]->Num == c->Num) { - U = 1-(epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg) ; + else if(C[2]->Num == c->Num) { + U = 1 - (epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg); V = 1; } - else if (C[2]->Num == -c->Num) { - U = 1-(C[2]->uend - epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg) ; + else if(C[2]->Num == -c->Num) { + U = 1 - (C[2]->uend - epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg); V = 1; } - else{ + else { Msg::Info("Reparameterizing edge %d on face %d", c->Num, s->Num); return GEdge::reparamOnFace(face, epar, dir); } - } - else{ + else { // FIXME: workaround for exact extrusions bool hack = false; if(CTX::instance()->geom.exactExtrusion && s->Extrude && s->Extrude->geo.Mode == EXTRUDED_ENTITY && s->Typ != MSH_SURF_PLAN) hack = true; - if (C[0]->Num == c->Num) { - U = (epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg) ; + if(C[0]->Num == c->Num) { + U = (epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg); V = 0; } - else if (C[0]->Num == -c->Num) { - U = (C[0]->uend - epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg) ; + else if(C[0]->Num == -c->Num) { + U = (C[0]->uend - epar - C[0]->ubeg) / (C[0]->uend - C[0]->ubeg); V = 0; } - else if (C[1]->Num == c->Num) { - V = (epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg) ; + else if(C[1]->Num == c->Num) { + V = (epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg); U = 1; } - else if (C[1]->Num == -c->Num) { - V = (C[1]->uend - epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg) ; + else if(C[1]->Num == -c->Num) { + V = (C[1]->uend - epar - C[1]->ubeg) / (C[1]->uend - C[1]->ubeg); U = 1; } - else if (C[2]->Num == c->Num) { - U = 1-(epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg) ; + else if(C[2]->Num == c->Num) { + U = 1 - (epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg); V = hack ? 1 : U; } - else if (C[2]->Num == -c->Num) { - U = 1-(C[2]->uend - epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg) ; + else if(C[2]->Num == -c->Num) { + U = 1 - (C[2]->uend - epar - C[2]->ubeg) / (C[2]->uend - C[2]->ubeg); V = hack ? 1 : U; } - else{ + else { Msg::Info("Reparameterizing edge %d on face %d", c->Num, s->Num); return GEdge::reparamOnFace(face, epar, dir); } } return SPoint2(U, V); } - else{ + else { return GEdge::reparamOnFace(face, epar, dir); } } @@ -368,18 +358,12 @@ SPoint2 gmshEdge::reparamOnFace(const GFace *face, double epar,int dir) const void gmshEdge::writeGEO(FILE *fp) { if(!c || c->Num < 0 || c->Typ == MSH_SEGM_DISCRETE) return; - switch (c->Typ) { - case MSH_SEGM_LINE: - fprintf(fp, "Line(%d) = ", c->Num); - break; + switch(c->Typ) { + case MSH_SEGM_LINE: fprintf(fp, "Line(%d) = ", c->Num); break; case MSH_SEGM_CIRC: - case MSH_SEGM_CIRC_INV: - fprintf(fp, "Circle(%d) = ", c->Num); - break; + case MSH_SEGM_CIRC_INV: fprintf(fp, "Circle(%d) = ", c->Num); break; case MSH_SEGM_ELLI: - case MSH_SEGM_ELLI_INV: - fprintf(fp, "Ellipse(%d) = ", c->Num); - break; + case MSH_SEGM_ELLI_INV: fprintf(fp, "Ellipse(%d) = ", c->Num); break; case MSH_SEGM_NURBS: fprintf(fp, "Nurbs(%d) = {", c->Num); for(int i = 0; i < List_Nbr(c->Control_Points); i++) { @@ -389,8 +373,7 @@ void gmshEdge::writeGEO(FILE *fp) fprintf(fp, "%d", v->Num); else fprintf(fp, ", %d", v->Num); - if(i % 8 == 7 && i != List_Nbr(c->Control_Points) - 1) - fprintf(fp, "\n"); + if(i % 8 == 7 && i != List_Nbr(c->Control_Points) - 1) fprintf(fp, "\n"); } fprintf(fp, "}\n"); fprintf(fp, " Knots {"); @@ -405,18 +388,10 @@ void gmshEdge::writeGEO(FILE *fp) fprintf(fp, "}\n"); fprintf(fp, " Order %d;\n", c->degre); return; - case MSH_SEGM_SPLN: - fprintf(fp, "Spline(%d) = ", c->Num); - break; - case MSH_SEGM_BSPLN: - fprintf(fp, "BSpline(%d) = ", c->Num); - break; - case MSH_SEGM_BEZIER: - fprintf(fp, "Bezier(%d) = ", c->Num); - break; - default: - Msg::Error("Unknown curve type %d", c->Typ); - return; + case MSH_SEGM_SPLN: fprintf(fp, "Spline(%d) = ", c->Num); break; + case MSH_SEGM_BSPLN: fprintf(fp, "BSpline(%d) = ", c->Num); break; + case MSH_SEGM_BEZIER: fprintf(fp, "Bezier(%d) = ", c->Num); break; + default: Msg::Error("Unknown curve type %d", c->Typ); return; } for(int i = 0; i < List_Nbr(c->Control_Points); i++) { Vertex *v; @@ -425,16 +400,15 @@ void gmshEdge::writeGEO(FILE *fp) fprintf(fp, ", %d", v->Num); else fprintf(fp, "{%d", v->Num); - if(i % 8 == 7) - fprintf(fp, "\n"); + if(i % 8 == 7) fprintf(fp, "\n"); } fprintf(fp, "};\n"); - if(meshAttributes.method == MESH_TRANSFINITE){ + if(meshAttributes.method == MESH_TRANSFINITE) { fprintf(fp, "Transfinite Line {%d} = %d", tag() * (meshAttributes.typeTransfinite > 0 ? 1 : -1), meshAttributes.nbPointsTransfinite); - if(meshAttributes.typeTransfinite){ + if(meshAttributes.typeTransfinite) { if(std::abs(meshAttributes.typeTransfinite) == 1) fprintf(fp, "Using Progression "); else if(std::abs(meshAttributes.typeTransfinite) == 2) @@ -444,130 +418,118 @@ void gmshEdge::writeGEO(FILE *fp) fprintf(fp, ";\n"); } - if(meshAttributes.reverseMesh) - fprintf(fp, "Reverse Line {%d};\n", tag()); + if(meshAttributes.reverseMesh) fprintf(fp, "Reverse Line {%d};\n", tag()); } static inline SPoint3 curveGetPoint(Curve *c, int i) { Vertex *v; - List_Read(c->Control_Points, i , &v); + List_Read(c->Control_Points, i, &v); return SPoint3(v->Pos.X, v->Pos.Y, v->Pos.Z); } -void gmshEdge::discretize(double tol, std::vector<SPoint3> &pts, std::vector<double> &ts) +void gmshEdge::discretize(double tol, std::vector<SPoint3> &pts, + std::vector<double> &ts) { switch(c->Typ) { - case MSH_SEGM_LINE : - { - int NPt = List_Nbr(c->Control_Points); - pts.resize(NPt); - ts.resize(NPt); - for (int i = 0; i < NPt; ++i) { - pts[i]= curveGetPoint(c, i); - ts[i] = i / (double) (NPt - 1); - } - return; + case MSH_SEGM_LINE: { + int NPt = List_Nbr(c->Control_Points); + pts.resize(NPt); + ts.resize(NPt); + for(int i = 0; i < NPt; ++i) { + pts[i] = curveGetPoint(c, i); + ts[i] = i / (double)(NPt - 1); + } + return; + } + case MSH_SEGM_BEZIER: { + int NbCurves = (List_Nbr(c->Control_Points) - 1) / 3; + for(int iCurve = 0; iCurve < NbCurves; ++iCurve) { + double t1 = (iCurve) / (double)(NbCurves); + double t2 = (iCurve + 1) / (double)(NbCurves); + SPoint3 pt[4]; + for(int i = 0; i < 4; i++) { + pt[i] = curveGetPoint(c, iCurve * 3 + i); } - case MSH_SEGM_BEZIER : - { - int NbCurves = (List_Nbr(c->Control_Points) - 1) / 3; - for (int iCurve = 0; iCurve < NbCurves; ++iCurve) { - double t1 = (iCurve) / (double)(NbCurves); - double t2 = (iCurve+1) / (double)(NbCurves); - SPoint3 pt[4]; - for(int i = 0; i < 4; i++) { - pt[i] = curveGetPoint(c, iCurve * 3 + i); - } - std::vector<double> lts; - std::vector<SPoint3> lpts; - decasteljau(tol, pt[0], pt[1], pt[2], pt[3], lpts, lts); - for (size_t i = (iCurve == 0 ? 0 : 1); i < lpts.size(); ++i) { - pts.push_back(lpts[i]); - ts.push_back(t1 + lts[i] * (t2 - t1)); - } - } - break; + std::vector<double> lts; + std::vector<SPoint3> lpts; + decasteljau(tol, pt[0], pt[1], pt[2], pt[3], lpts, lts); + for(size_t i = (iCurve == 0 ? 0 : 1); i < lpts.size(); ++i) { + pts.push_back(lpts[i]); + ts.push_back(t1 + lts[i] * (t2 - t1)); } - case MSH_SEGM_BSPLN: - { - bool periodic = (c->end == c->beg); - int NbControlPoints = List_Nbr(c->Control_Points); - int NbCurves = NbControlPoints + (periodic ? -1 : 1); - SPoint3 pt[4]; - for (int iCurve = 0; iCurve < NbCurves; ++iCurve) { - double t1 = (iCurve) / (double)(NbCurves); - double t2 = (iCurve+1) / (double)(NbCurves); - for(int i = 0; i < 4; i++) { - int k; - if (periodic) { - k = (iCurve - 1 + i) % (NbControlPoints - 1); - if (k < 0) - k += NbControlPoints - 1; - } - else { - k = std::max(0, std::min(iCurve - 2 + i, NbControlPoints -1)); - } - pt[i] = curveGetPoint(c, k); - } - SPoint3 bpt[4] = { - (pt[0] + pt[1] * 4 + pt[2]) * (1./6.), - (pt[1] * 2 + pt[2]) * (1./3.), - (pt[1] + pt[2] * 2) * (1./3.), - (pt[1] + pt[2] * 4 + pt[3]) * (1./6.) - }; - std::vector<double> lts; - std::vector<SPoint3> lpts; - decasteljau(tol, bpt[0], bpt[1], bpt[2], bpt[3], lpts, lts); - for (size_t i = (iCurve == 0 ? 0 : 1); i < lpts.size(); ++i) { - pts.push_back(lpts[i]); - ts.push_back(t1 + lts[i] * (t2 - t1)); - } + } + break; + } + case MSH_SEGM_BSPLN: { + bool periodic = (c->end == c->beg); + int NbControlPoints = List_Nbr(c->Control_Points); + int NbCurves = NbControlPoints + (periodic ? -1 : 1); + SPoint3 pt[4]; + for(int iCurve = 0; iCurve < NbCurves; ++iCurve) { + double t1 = (iCurve) / (double)(NbCurves); + double t2 = (iCurve + 1) / (double)(NbCurves); + for(int i = 0; i < 4; i++) { + int k; + if(periodic) { + k = (iCurve - 1 + i) % (NbControlPoints - 1); + if(k < 0) k += NbControlPoints - 1; } - break; - } - case MSH_SEGM_SPLN: - { - int NbCurves = List_Nbr(c->Control_Points) - 1; - SPoint3 pt[4]; - for (int iCurve = 0; iCurve < NbCurves; ++iCurve) { - double t1 = (iCurve) / (double)(NbCurves); - double t2 = (iCurve+1) / (double)(NbCurves); - pt[1] = curveGetPoint(c, iCurve); - pt[2] = curveGetPoint(c, iCurve + 1); - if(iCurve == 0) { - if(c->beg == c->end) - pt[0] = curveGetPoint(c, NbCurves - 1); - else - pt[0] = SPoint3(pt[1] * 2 - pt[2]); - } - else - pt[0] = curveGetPoint(c, iCurve - 1); - if(iCurve == NbCurves - 1) { - if(c->beg == c->end) - pt[3] = curveGetPoint(c, 1); - else - pt[3] = SPoint3(2 * pt[2] - pt[1]); - } - else - pt[3] = curveGetPoint(c, iCurve + 2); - SPoint3 bpt[4] = { - pt[1], - (pt[1] * 6 + pt[2] - pt[0]) * (1./6.), - (pt[2] * 6 - pt[3] + pt[1]) * (1./6.), - pt[2] - }; - std::vector<double> lts; - std::vector<SPoint3> lpts; - decasteljau(tol, bpt[0], bpt[1], bpt[2], bpt[3], lpts, lts); - for (size_t i = (iCurve == 0 ? 0 : 1); i < lpts.size(); ++i) { - pts.push_back(lpts[i]); - ts.push_back(t1 + lts[i] * (t2 - t1)); - } + else { + k = std::max(0, std::min(iCurve - 2 + i, NbControlPoints - 1)); } - break; + pt[i] = curveGetPoint(c, k); + } + SPoint3 bpt[4] = {(pt[0] + pt[1] * 4 + pt[2]) * (1. / 6.), + (pt[1] * 2 + pt[2]) * (1. / 3.), + (pt[1] + pt[2] * 2) * (1. / 3.), + (pt[1] + pt[2] * 4 + pt[3]) * (1. / 6.)}; + std::vector<double> lts; + std::vector<SPoint3> lpts; + decasteljau(tol, bpt[0], bpt[1], bpt[2], bpt[3], lpts, lts); + for(size_t i = (iCurve == 0 ? 0 : 1); i < lpts.size(); ++i) { + pts.push_back(lpts[i]); + ts.push_back(t1 + lts[i] * (t2 - t1)); } - default : - GEdge::discretize(tol, pts, ts); + } + break; + } + case MSH_SEGM_SPLN: { + int NbCurves = List_Nbr(c->Control_Points) - 1; + SPoint3 pt[4]; + for(int iCurve = 0; iCurve < NbCurves; ++iCurve) { + double t1 = (iCurve) / (double)(NbCurves); + double t2 = (iCurve + 1) / (double)(NbCurves); + pt[1] = curveGetPoint(c, iCurve); + pt[2] = curveGetPoint(c, iCurve + 1); + if(iCurve == 0) { + if(c->beg == c->end) + pt[0] = curveGetPoint(c, NbCurves - 1); + else + pt[0] = SPoint3(pt[1] * 2 - pt[2]); + } + else + pt[0] = curveGetPoint(c, iCurve - 1); + if(iCurve == NbCurves - 1) { + if(c->beg == c->end) + pt[3] = curveGetPoint(c, 1); + else + pt[3] = SPoint3(2 * pt[2] - pt[1]); + } + else + pt[3] = curveGetPoint(c, iCurve + 2); + SPoint3 bpt[4] = {pt[1], (pt[1] * 6 + pt[2] - pt[0]) * (1. / 6.), + (pt[2] * 6 - pt[3] + pt[1]) * (1. / 6.), pt[2]}; + std::vector<double> lts; + std::vector<SPoint3> lpts; + decasteljau(tol, bpt[0], bpt[1], bpt[2], bpt[3], lpts, lts); + for(size_t i = (iCurve == 0 ? 0 : 1); i < lpts.size(); ++i) { + pts.push_back(lpts[i]); + ts.push_back(t1 + lts[i] * (t2 - t1)); + } + } + break; + } + default: GEdge::discretize(tol, pts, ts); } } diff --git a/Geo/gmshEdge.h b/Geo/gmshEdge.h index e37ceb34adb6589e6f09361e12ccf3be7a074ff8..d9c29bb674656f528716cd72e042de87cd2cc4c0 100644 --- a/Geo/gmshEdge.h +++ b/Geo/gmshEdge.h @@ -11,10 +11,10 @@ class Curve; class gmshEdge : public GEdge { - protected: +protected: Curve *c; - public: +public: gmshEdge(GModel *model, Curve *edge, GVertex *v1, GVertex *v2); virtual ~gmshEdge() {} virtual Range<double> parBounds(int i) const; @@ -30,7 +30,8 @@ class gmshEdge : public GEdge { virtual void resetMeshAttributes(); virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const; virtual void writeGEO(FILE *fp); - void discretize(double tol, std::vector<SPoint3> &dpts, std::vector<double> &ts); + void discretize(double tol, std::vector<SPoint3> &dpts, + std::vector<double> &ts); virtual bool degenerate(int dim) const; void resetNativePtr(Curve *edge, GVertex *v1, GVertex *v2); }; diff --git a/Geo/gmshEdgeDiscretize.cpp b/Geo/gmshEdgeDiscretize.cpp index 0b3c8825c21ded95735b80fda12a579781df1459..3753cc1d668c8a25932d030d8049b545015675c1 100644 --- a/Geo/gmshEdgeDiscretize.cpp +++ b/Geo/gmshEdgeDiscretize.cpp @@ -15,6 +15,7 @@ class discreteList { std::vector<std::pair<SPoint3, double> > _pts; std::vector<int> _next; + public: int insertPoint(int pos, const SPoint3 &pt, double t) { @@ -29,15 +30,12 @@ public: spts.reserve(_pts.size()); ts.clear(); ts.reserve(_pts.size()); - for (int p = _next[0]; p != -1; p = _next[p + 1]) { + for(int p = _next[0]; p != -1; p = _next[p + 1]) { spts.push_back(_pts[p].first); ts.push_back(_pts[p].second); } } - discreteList() - { - _next.push_back(-1); - } + discreteList() { _next.push_back(-1); } }; static void decasteljau(double tol, discreteList &discrete, int pos, @@ -73,8 +71,7 @@ static int discretizeBezier(double tol, discreteList &discrete, int pos, const SPoint3 pt[4], double t0, double t3, bool insertFirstPoint) { - if (insertFirstPoint) - pos = discrete.insertPoint(pos, pt[0], t0); + if(insertFirstPoint) pos = discrete.insertPoint(pos, pt[0], t0); int newp = discrete.insertPoint(pos, pt[3], t3); decasteljau(tol, discrete, pos, pt[0], pt[1], pt[2], pt[3], t0, t3); return newp; @@ -84,12 +81,10 @@ static int discretizeBSpline(double tol, discreteList &discrete, int pos, const SPoint3 pt[4], double t0, double t3, bool insertFirstPoint) { - SPoint3 bpt[4] = { - SPoint3((pt[0] + 4 * pt[1] + pt[2]) * (1./6.)), - SPoint3((2 * pt[1] + pt[2]) * (1./3.)), - SPoint3((pt[1] + 2 * pt[2]) * (1./3.)), - SPoint3((pt[1] + 4 * pt[2] + pt[3]) * (1./6.)) - }; + SPoint3 bpt[4] = {SPoint3((pt[0] + 4 * pt[1] + pt[2]) * (1. / 6.)), + SPoint3((2 * pt[1] + pt[2]) * (1. / 3.)), + SPoint3((pt[1] + 2 * pt[2]) * (1. / 3.)), + SPoint3((pt[1] + 4 * pt[2] + pt[3]) * (1. / 6.))}; return discretizeBezier(tol, discrete, pos, bpt, t0, t3, insertFirstPoint); } @@ -97,19 +92,15 @@ static int discretizeCatmullRom(double tol, discreteList &discrete, int pos, const SPoint3 pt[4], double t0, double t3, bool insertFirstPoint) { - SPoint3 bpt[4] = { - pt[1], - SPoint3(( 6 * pt[1] + pt[2] - pt[0]) * (1./6.)), - SPoint3(( 6 * pt[2] - pt[3] + pt[1]) * (1./6.)), - pt[2] - }; + SPoint3 bpt[4] = {pt[1], SPoint3((6 * pt[1] + pt[2] - pt[0]) * (1. / 6.)), + SPoint3((6 * pt[2] - pt[3] + pt[1]) * (1. / 6.)), pt[2]}; return discretizeBezier(tol, discrete, pos, bpt, t0, t3, insertFirstPoint); } static inline SPoint3 curveGetPoint(Curve *c, int i) { Vertex *v; - List_Read(c->Control_Points, i , &v); + List_Read(c->Control_Points, i, &v); return SPoint3(v->Pos.X, v->Pos.Y, v->Pos.Z); } @@ -118,96 +109,91 @@ static void discretizeCurve(Curve *c, double tol, std::vector<SPoint3> &pts, { discreteList discrete; switch(c->Typ) { - case MSH_SEGM_LINE : - { - int NPt = List_Nbr(c->Control_Points); - pts.resize(NPt); - ts.resize(NPt); - for (int i = 0; i < NPt; ++i) { - pts[i]= curveGetPoint(c, i); - ts[i] = i / (double) (NPt - 1); - } - return; + case MSH_SEGM_LINE: { + int NPt = List_Nbr(c->Control_Points); + pts.resize(NPt); + ts.resize(NPt); + for(int i = 0; i < NPt; ++i) { + pts[i] = curveGetPoint(c, i); + ts[i] = i / (double)(NPt - 1); } - case MSH_SEGM_BEZIER : - { - int back = -1; - int NbCurves = (List_Nbr(c->Control_Points) - 1) / 3; - for (int iCurve = 0; iCurve < NbCurves; ++iCurve) { - double t1 = (iCurve) / (double)(NbCurves); - double t2 = (iCurve+1) / (double)(NbCurves); - SPoint3 pt[4]; - for(int i = 0; i < 4; i++) { - pt[i] = curveGetPoint(c, iCurve * 3 + i); - } - back = discretizeBezier(tol, discrete, back, pt, t1, t2, iCurve == 0); + return; + } + case MSH_SEGM_BEZIER: { + int back = -1; + int NbCurves = (List_Nbr(c->Control_Points) - 1) / 3; + for(int iCurve = 0; iCurve < NbCurves; ++iCurve) { + double t1 = (iCurve) / (double)(NbCurves); + double t2 = (iCurve + 1) / (double)(NbCurves); + SPoint3 pt[4]; + for(int i = 0; i < 4; i++) { + pt[i] = curveGetPoint(c, iCurve * 3 + i); } - break; + back = discretizeBezier(tol, discrete, back, pt, t1, t2, iCurve == 0); } - case MSH_SEGM_BSPLN: - { - int back = -1; - bool periodic = (c->end == c->beg); - int NbControlPoints = List_Nbr(c->Control_Points); - int NbCurves = NbControlPoints + (periodic ? -1 : 1); - SPoint3 pt[4]; - for (int iCurve = 0; iCurve < NbCurves; ++iCurve) { - double t1 = (iCurve) / (double)(NbCurves); - double t2 = (iCurve+1) / (double)(NbCurves); - for(int i = 0; i < 4; i++) { - int k; - if (periodic) { - k = (iCurve - 1 + i) % (NbControlPoints - 1); - if (k < 0) - k += NbControlPoints - 1; - } - else { - k = std::max(0, std::min(iCurve - 2 + i, NbControlPoints -1)); - } - pt[i] = curveGetPoint(c, k); + break; + } + case MSH_SEGM_BSPLN: { + int back = -1; + bool periodic = (c->end == c->beg); + int NbControlPoints = List_Nbr(c->Control_Points); + int NbCurves = NbControlPoints + (periodic ? -1 : 1); + SPoint3 pt[4]; + for(int iCurve = 0; iCurve < NbCurves; ++iCurve) { + double t1 = (iCurve) / (double)(NbCurves); + double t2 = (iCurve + 1) / (double)(NbCurves); + for(int i = 0; i < 4; i++) { + int k; + if(periodic) { + k = (iCurve - 1 + i) % (NbControlPoints - 1); + if(k < 0) k += NbControlPoints - 1; + } + else { + k = std::max(0, std::min(iCurve - 2 + i, NbControlPoints - 1)); } - back = discretizeBSpline(tol, discrete, back, pt, t1, t2, iCurve == 0); + pt[i] = curveGetPoint(c, k); } - break; + back = discretizeBSpline(tol, discrete, back, pt, t1, t2, iCurve == 0); } - case MSH_SEGM_SPLN: - { - int NbCurves = List_Nbr(c->Control_Points) - 1; - SPoint3 pt[4]; - int back = -1; - for (int iCurve = 0; iCurve < NbCurves; ++iCurve) { - double t1 = (iCurve) / (double)(NbCurves); - double t2 = (iCurve+1) / (double)(NbCurves); - pt[1] = curveGetPoint(c, iCurve); - pt[2] = curveGetPoint(c, iCurve + 1); - if(iCurve == 0) { - if(c->beg == c->end) - pt[0] = curveGetPoint(c, NbCurves - 1); - else - pt[0] = SPoint3(pt[1] * 2 - pt[2]); - } + break; + } + case MSH_SEGM_SPLN: { + int NbCurves = List_Nbr(c->Control_Points) - 1; + SPoint3 pt[4]; + int back = -1; + for(int iCurve = 0; iCurve < NbCurves; ++iCurve) { + double t1 = (iCurve) / (double)(NbCurves); + double t2 = (iCurve + 1) / (double)(NbCurves); + pt[1] = curveGetPoint(c, iCurve); + pt[2] = curveGetPoint(c, iCurve + 1); + if(iCurve == 0) { + if(c->beg == c->end) + pt[0] = curveGetPoint(c, NbCurves - 1); else - pt[0] = curveGetPoint(c, iCurve - 1); - if(iCurve == NbCurves - 1) { - if(c->beg == c->end) - pt[3] = curveGetPoint(c, 1); - else - pt[3] = SPoint3(2 * pt[2] - pt[1]); - } + pt[0] = SPoint3(pt[1] * 2 - pt[2]); + } + else + pt[0] = curveGetPoint(c, iCurve - 1); + if(iCurve == NbCurves - 1) { + if(c->beg == c->end) + pt[3] = curveGetPoint(c, 1); else - pt[3] = curveGetPoint(c, iCurve + 2); - back = discretizeCatmullRom(tol, discrete, back, pt, t1, t2, iCurve == 0); + pt[3] = SPoint3(2 * pt[2] - pt[1]); } - break; + else + pt[3] = curveGetPoint(c, iCurve + 2); + back = discretizeCatmullRom(tol, discrete, back, pt, t1, t2, iCurve == 0); } - default : + break; + } + default: Msg::Error("discretizeCurve not implemented for curve type %d", c->Typ); } discrete.sort(pts, ts); } -void gmshEdge::discretize(double tol, std::vector<SPoint3> - &dpts, std::vector<double> &ts) +void gmshEdge::discretize(double tol, std::vector<SPoint3> &dpts, + std::vector<double> &ts) { discretizeCurve(c, tol, dpts, ts); } diff --git a/Geo/gmshFace.cpp b/Geo/gmshFace.cpp index d872083da1896bf5811d3835b9b268ff062e3cef..4e13a61fe8eac13d60876903ee91f062e15c2ef8 100644 --- a/Geo/gmshFace.cpp +++ b/Geo/gmshFace.cpp @@ -20,8 +20,7 @@ #include "Field.h" #endif -gmshFace::gmshFace(GModel *m, Surface *face) - : GFace(m, face->Num) +gmshFace::gmshFace(GModel *m, Surface *face) : GFace(m, face->Num) { resetNativePtr(face); resetMeshAttributes(); @@ -30,14 +29,15 @@ gmshFace::gmshFace(GModel *m, Surface *face) // a face is degenerate if bool gmshFace::degenerate(int dim) const { - std::vector<GEdge*> const& eds = edges(); + std::vector<GEdge *> const &eds = edges(); int numNonDegenerate = 0; - std::set<GEdge*> t; - for(std::vector<GEdge*>::const_iterator it = eds.begin(); it != eds.end(); ++it){ + std::set<GEdge *> t; + for(std::vector<GEdge *>::const_iterator it = eds.begin(); it != eds.end(); + ++it) { GEdge *e = *it; GVertex *start = e->getBeginVertex(); - GVertex *next = e->getEndVertex(); - if (start != next && t.find(e) == t.end()){ + GVertex *next = e->getEndVertex(); + if(start != next && t.find(e) == t.end()) { numNonDegenerate++; } t.insert(e); @@ -53,24 +53,24 @@ void gmshFace::resetNativePtr(Surface *face) l_dirs.clear(); edgeLoops.clear(); - std::vector<GEdge*> eds; + std::vector<GEdge *> eds; std::vector<int> nums; - for(int i = 0; i < List_Nbr(s->Generatrices); i++){ + for(int i = 0; i < List_Nbr(s->Generatrices); i++) { Curve *c; List_Read(s->Generatrices, i, &c); GEdge *e = model()->getEdgeByTag(abs(c->Num)); - if(e){ + if(e) { eds.push_back(e); nums.push_back(c->Num); } else Msg::Error("Unknown curve %d", c->Num); } - for(int i = 0; i < List_Nbr(s->GeneratricesByTag); i++){ + for(int i = 0; i < List_Nbr(s->GeneratricesByTag); i++) { int j; List_Read(s->GeneratricesByTag, i, &j); GEdge *e = model()->getEdgeByTag(abs(j)); - if(e){ + if(e) { eds.push_back(e); nums.push_back(j); } @@ -78,18 +78,18 @@ void gmshFace::resetNativePtr(Surface *face) Msg::Error("Unknown curve %d", j); } - std::vector<GEdge*> l_wire; + std::vector<GEdge *> l_wire; l_wire.reserve(eds.size()); GVertex *first = 0; - for(unsigned int i = 0; i < eds.size(); i++){ + for(unsigned int i = 0; i < eds.size(); i++) { GEdge *e = eds[i]; int num = nums[i]; GVertex *start = (num > 0) ? e->getBeginVertex() : e->getEndVertex(); - GVertex *next = (num > 0) ? e->getEndVertex() : e->getBeginVertex(); - if (!first) first = start; + GVertex *next = (num > 0) ? e->getEndVertex() : e->getBeginVertex(); + if(!first) first = start; l_wire.push_back(e); - if (next == first){ + if(next == first) { edgeLoops.push_back(GEdgeLoop(l_wire)); l_wire.clear(); first = 0; @@ -97,7 +97,7 @@ void gmshFace::resetNativePtr(Surface *face) l_edges.push_back(e); e->addFace(this); l_dirs.push_back((num > 0) ? 1 : -1); - if (List_Nbr(s->Generatrices) == 2){ + if(List_Nbr(s->Generatrices) == 2) { e->meshAttributes.minimumMeshSegments = std::max(e->meshAttributes.minimumMeshSegments, 2); } @@ -114,9 +114,9 @@ double gmshFace::getMetricEigenvalue(const SPoint2 &pt) return s->geometry->getMetricEigenvalue(pt); } -void gmshFace::setModelEdges(std::list<GEdge*> &ed) +void gmshFace::setModelEdges(std::list<GEdge *> &ed) { - for (std::list<GEdge*>::iterator it = ed.begin(); it != ed.end() ; ++it){ + for(std::list<GEdge *>::iterator it = ed.begin(); it != ed.end(); ++it) { l_edges.push_back(*it); (*it)->addFace(this); l_dirs.push_back(1); @@ -129,11 +129,11 @@ void gmshFace::resetMeshAttributes() meshAttributes.recombineAngle = s->RecombineAngle; meshAttributes.method = s->Method; meshAttributes.extrude = s->Extrude; - if(meshAttributes.method == MESH_TRANSFINITE){ + if(meshAttributes.method == MESH_TRANSFINITE) { meshAttributes.transfiniteArrangement = s->Recombine_Dir; meshAttributes.transfiniteSmoothing = s->TransfiniteSmoothing; meshAttributes.corners.clear(); - for(int i = 0; i < List_Nbr(s->TrsfPoints); i++){ + for(int i = 0; i < List_Nbr(s->TrsfPoints); i++) { Vertex *corn; List_Read(s->TrsfPoints, i, &corn); GVertex *gv = model()->getVertexByTag(corn->Num); @@ -146,21 +146,18 @@ void gmshFace::resetMeshAttributes() meshAttributes.reverseMesh = s->ReverseMesh; } -Range<double> gmshFace::parBounds(int i) const -{ - return Range<double>(0, 1); -} +Range<double> gmshFace::parBounds(int i) const { return Range<double>(0, 1); } SVector3 gmshFace::normal(const SPoint2 ¶m) const { - if(s->Typ != MSH_SURF_PLAN){ + if(s->Typ != MSH_SURF_PLAN) { Vertex vu = InterpolateSurface(s, param[0], param[1], 1, 1); Vertex vv = InterpolateSurface(s, param[0], param[1], 1, 2); Vertex n = vu % vv; n.norme(); return SVector3(n.Pos.X, n.Pos.Y, n.Pos.Z); } - else{ + else { // We cannot use InterpolateSurface() for plane surfaces since it // relies on the mean plane, which does not respect the // orientation @@ -173,7 +170,7 @@ SVector3 gmshFace::normal(const SPoint2 ¶m) const GPoint pt = point(param.x(), param.y()); double v[3] = {pt.x(), pt.y(), pt.z()}; int NP = 10, tries = 0; - while(1){ + while(1) { tries++; double angle = 0.; for(int i = 0; i < List_Nbr(s->Generatrices); i++) { @@ -190,11 +187,12 @@ SVector3 gmshFace::normal(const SPoint2 ¶m) const angle += angle_plan(v, v1, v2, n); } } - if(fabs(angle) < 0.5){ // we're outside + if(fabs(angle) < 0.5) { // we're outside NP *= 2; - Msg::Debug("Could not compute normal of surface %d - retrying with %d points", - tag(), NP); - if(tries > 10){ + Msg::Debug( + "Could not compute normal of surface %d - retrying with %d points", + tag(), NP); + if(tries > 10) { Msg::Warning("Could not orient normal of surface %d", tag()); return SVector3(n[0], n[1], n[2]); } @@ -209,13 +207,13 @@ SVector3 gmshFace::normal(const SPoint2 ¶m) const Pair<SVector3, SVector3> gmshFace::firstDer(const SPoint2 ¶m) const { - if(s->Typ == MSH_SURF_PLAN && !s->geometry){ + if(s->Typ == MSH_SURF_PLAN && !s->geometry) { double x, y, z, VX[3], VY[3]; getMeanPlaneData(VX, VY, x, y, z); return Pair<SVector3, SVector3>(SVector3(VX[0], VX[1], VX[2]), SVector3(VY[0], VY[1], VY[2])); } - else{ + else { Vertex vu = InterpolateSurface(s, param[0], param[1], 1, 1); Vertex vv = InterpolateSurface(s, param[0], param[1], 1, 2); return Pair<SVector3, SVector3>(SVector3(vu.Pos.X, vu.Pos.Y, vu.Pos.Z), @@ -223,46 +221,47 @@ Pair<SVector3, SVector3> gmshFace::firstDer(const SPoint2 ¶m) const } } -void gmshFace::secondDer(const SPoint2 ¶m, - SVector3 &dudu, SVector3 &dvdv, SVector3 &dudv) const +void gmshFace::secondDer(const SPoint2 ¶m, SVector3 &dudu, SVector3 &dvdv, + SVector3 &dudv) const { - if(s->Typ == MSH_SURF_PLAN && !s->geometry){ + if(s->Typ == MSH_SURF_PLAN && !s->geometry) { dudu = SVector3(0., 0., 0.); dvdv = SVector3(0., 0., 0.); dudv = SVector3(0., 0., 0.); } - else{ + else { Vertex vuu = InterpolateSurface(s, param[0], param[1], 2, 1); Vertex vvv = InterpolateSurface(s, param[0], param[1], 2, 2); Vertex vuv = InterpolateSurface(s, param[0], param[1], 2, 3); - dudu = SVector3(vuu.Pos.X,vuu.Pos.Y,vuu.Pos.Z); - dvdv = SVector3(vvv.Pos.X,vvv.Pos.Y,vvv.Pos.Z); - dudv = SVector3(vuv.Pos.X,vuv.Pos.Y,vuv.Pos.Z); + dudu = SVector3(vuu.Pos.X, vuu.Pos.Y, vuu.Pos.Z); + dvdv = SVector3(vvv.Pos.X, vvv.Pos.Y, vvv.Pos.Z); + dudv = SVector3(vuv.Pos.X, vuv.Pos.Y, vuv.Pos.Z); } } GPoint gmshFace::point(double par1, double par2) const { double pp[2] = {par1, par2}; - if(s->Typ == MSH_SURF_PLAN && !s->geometry){ + if(s->Typ == MSH_SURF_PLAN && !s->geometry) { double x, y, z, VX[3], VY[3]; getMeanPlaneData(VX, VY, x, y, z); return GPoint(x + VX[0] * par1 + VY[0] * par2, y + VX[1] * par1 + VY[1] * par2, z + VX[2] * par1 + VY[2] * par2, this, pp); } - else{ + else { Vertex v = InterpolateSurface(s, par1, par2, 0, 0); return GPoint(v.Pos.X, v.Pos.Y, v.Pos.Z, this, pp); } } -GPoint gmshFace::closestPoint(const SPoint3 & qp, const double initialGuess[2]) const +GPoint gmshFace::closestPoint(const SPoint3 &qp, + const double initialGuess[2]) const { #if defined(HAVE_BFGS) return GFace::closestPoint(qp, initialGuess); #endif - if (s->Typ == MSH_SURF_PLAN && !s->geometry){ + if(s->Typ == MSH_SURF_PLAN && !s->geometry) { double XP = qp.x(); double YP = qp.y(); double ZP = qp.z(); @@ -272,16 +271,16 @@ GPoint gmshFace::closestPoint(const SPoint3 & qp, const double initialGuess[2]) double MN[2][2]; double B[3] = {XP - x, YP - y, ZP - z}; double BN[2], UV[2]; - for (int i = 0; i < 2; i++){ + for(int i = 0; i < 2; i++) { BN[i] = 0; - for (int k = 0; k < 3; k++){ + for(int k = 0; k < 3; k++) { BN[i] += B[k] * M[k][i]; } } - for (int i = 0; i < 2; i++){ - for (int j = 0; j < 2; j++){ + for(int i = 0; i < 2; i++) { + for(int j = 0; j < 2; j++) { MN[i][j] = 0; - for (int k = 0; k < 3; k++){ + for(int k = 0; k < 3; k++) { MN[i][j] += M[k][i] * M[k][j]; } } @@ -296,14 +295,13 @@ GPoint gmshFace::closestPoint(const SPoint3 & qp, const double initialGuess[2]) v.Pos.Z = qp.z(); double u[2] = {initialGuess[0], initialGuess[1]}; bool result = ProjectPointOnSurface(s, v, u); - if (!result) - return GPoint(-1.e22, -1.e22, -1.e22, 0, u); + if(!result) return GPoint(-1.e22, -1.e22, -1.e22, 0, u); return GPoint(v.Pos.X, v.Pos.Y, v.Pos.Z, this, u); } SPoint2 gmshFace::parFromPoint(const SPoint3 &qp, bool onSurface) const { - if(s->Typ == MSH_SURF_PLAN){ + if(s->Typ == MSH_SURF_PLAN) { double x, y, z, VX[3], VY[3]; getMeanPlaneData(VX, VY, x, y, z); double const vec[3] = {qp.x() - x, qp.y() - y, qp.z() - z}; @@ -311,34 +309,30 @@ SPoint2 gmshFace::parFromPoint(const SPoint3 &qp, bool onSurface) const double const v = prosca(vec, VY); return SPoint2(u, v); } - else{ + else { return GFace::parFromPoint(qp, onSurface); } } GEntity::GeomType gmshFace::geomType() const { - switch(s->Typ){ + switch(s->Typ) { case MSH_SURF_PLAN: if(s->geometry) return ParametricSurface; else return Plane; case MSH_SURF_REGL: - case MSH_SURF_TRIC: - return RuledSurface; - case MSH_SURF_DISCRETE: - return DiscreteSurface; - case MSH_SURF_BND_LAYER: - return BoundaryLayerSurface; - default: - return Unknown; + case MSH_SURF_TRIC: return RuledSurface; + case MSH_SURF_DISCRETE: return DiscreteSurface; + case MSH_SURF_BND_LAYER: return BoundaryLayerSurface; + default: return Unknown; } } bool gmshFace::containsPoint(const SPoint3 &pt) const { - if(s->Typ == MSH_SURF_PLAN){ + if(s->Typ == MSH_SURF_PLAN) { // OK to use the normal from the mean plane here: we compensate // for the (possibly wrong) orientation at the end double n[3] = {meanPlane.a, meanPlane.b, meanPlane.c}; @@ -378,28 +372,29 @@ bool gmshFace::buildSTLTriangulation(bool force) stl_triangles.clear(); #if defined(HAVE_MESH) - if (!triangles.size()){ + if(!triangles.size()) { // FIXME: mesh only this surface... model()->mesh(2); } #endif - std::map<MVertex*,int> _v; + std::map<MVertex *, int> _v; int COUNT = 0; - for (unsigned int j = 0; j < triangles.size(); j++){ - for (int i = 0; i < 3; i++){ + for(unsigned int j = 0; j < triangles.size(); j++) { + for(int i = 0; i < 3; i++) { MVertex *v = triangles[j]->getVertex(i); - std::map<MVertex*,int>::iterator it = _v.find(v); - if (it == _v.end()){ + std::map<MVertex *, int>::iterator it = _v.find(v); + if(it == _v.end()) { _v[v] = COUNT; stl_triangles.push_back(COUNT); COUNT++; } - else stl_triangles.push_back(it->second); + else + stl_triangles.push_back(it->second); } } - std::map<MVertex*,int>::iterator itv = _v.begin(); - for ( ; itv != _v.end() ; ++itv){ + std::map<MVertex *, int>::iterator itv = _v.begin(); + for(; itv != _v.end(); ++itv) { MVertex *v = itv->first; stl_vertices_xyz.push_back(SPoint3(v->x(), v->y(), v->z())); SPoint2 param; diff --git a/Geo/gmshFace.h b/Geo/gmshFace.h index 3f44a27e738f46b8a123126ef11313f7c49f8b3c..68ce7642e1fd6146ed9c959f9ff03107ef3eadde 100644 --- a/Geo/gmshFace.h +++ b/Geo/gmshFace.h @@ -11,14 +11,15 @@ class Surface; class gmshFace : public GFace { - protected: +protected: Surface *s; bool buildSTLTriangulation(bool force); - public: + +public: gmshFace(GModel *m, Surface *face); - virtual ~gmshFace(){} + virtual ~gmshFace() {} Range<double> parBounds(int i) const; - void setModelEdges(std::list<GEdge*> &); + void setModelEdges(std::list<GEdge *> &); using GFace::point; virtual GPoint point(double par1, double par2) const; virtual GPoint closestPoint(const SPoint3 &queryPoint, @@ -26,12 +27,13 @@ class gmshFace : public GFace { virtual bool containsPoint(const SPoint3 &pt) const; virtual double getMetricEigenvalue(const SPoint2 &); virtual SVector3 normal(const SPoint2 ¶m) const; - virtual Pair<SVector3,SVector3> firstDer(const SPoint2 ¶m) const; - virtual void secondDer(const SPoint2 &, SVector3 &, SVector3 &, SVector3 &) const; + virtual Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m) const; + virtual void secondDer(const SPoint2 &, SVector3 &, SVector3 &, + SVector3 &) const; virtual GEntity::GeomType geomType() const; ModelType getNativeType() const { return GmshModel; } void *getNativePtr() const { return s; } - virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true) const; + virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface = true) const; virtual void resetMeshAttributes(); void resetNativePtr(Surface *_s); bool degenerate(int dim) const; diff --git a/Geo/gmshLevelset.cpp b/Geo/gmshLevelset.cpp index feb1d544254977c3e7a639261bccba69eb549dfe..93c5ee09ec1ec1265e91c66ad0a9800f52350ed8 100644 --- a/Geo/gmshLevelset.cpp +++ b/Geo/gmshLevelset.cpp @@ -22,10 +22,11 @@ #include "ANN/ANN.h" #endif -std::set<gLevelset*, gLevelsetLessThan> gLevelset::all_; +std::set<gLevelset *, gLevelsetLessThan> gLevelset::all_; int gLevelset::maxTag_ = 0; -bool gLevelsetLessThan::operator()(const gLevelset *l1, const gLevelset *l2) const +bool gLevelsetLessThan::operator()(const gLevelset *l1, + const gLevelset *l2) const { return l1->getTag() < l2->getTag(); } @@ -33,15 +34,12 @@ bool gLevelsetLessThan::operator()(const gLevelset *l1, const gLevelset *l2) con gLevelset *gLevelset::find(int tag) { gLevelset l(tag); - std::set<gLevelset*, gLevelsetLessThan>::iterator it = all_.find(&l); + std::set<gLevelset *, gLevelsetLessThan>::iterator it = all_.find(&l); if(it == all_.end()) return 0; return *it; } -void gLevelset::add(gLevelset *l) -{ - all_.insert(l); -} +void gLevelset::add(gLevelset *l) { all_.insert(l); } void insertActiveCells(double x, double y, double z, double rmax, cartesianBox<double> &box) @@ -81,7 +79,7 @@ int removeBadChildCells(cartesianBox<double> *parent) int K = parent->getNzeta(); for(int i = 0; i < I; i++) for(int j = 0; j < J; j++) - for(int k = 0; k < K; k++){ + for(int k = 0; k < K; k++) { // remove children if they do not entirely fill parent, or if // there is no parent on the boundary int idx[8] = {child->getCellIndex(2 * i, 2 * j, 2 * k), @@ -93,19 +91,25 @@ int removeBadChildCells(cartesianBox<double> *parent) child->getCellIndex(2 * i + 1, 2 * j + 1, 2 * k), child->getCellIndex(2 * i + 1, 2 * j + 1, 2 * k + 1)}; bool exist[8], atLeastOne = false, butNotAll = false; - for(int ii = 0; ii < 8; ii++){ + for(int ii = 0; ii < 8; ii++) { exist[ii] = child->activeCellExists(idx[ii]); if(exist[ii]) atLeastOne = true; if(!exist[ii]) butNotAll = true; } if(atLeastOne && (butNotAll || - (i != 0 && !parent->activeCellExists(parent->getCellIndex(i - 1, j, k))) || - (i != I - 1 && !parent->activeCellExists(parent->getCellIndex(i + 1, j, k))) || - (j != 0 && !parent->activeCellExists(parent->getCellIndex(i, j - 1, k))) || - (j != J - 1 && !parent->activeCellExists(parent->getCellIndex(i, j + 1, k))) || - (k != 0 && !parent->activeCellExists(parent->getCellIndex(i, j, k - 1))) || - (k != K - 1 && !parent->activeCellExists(parent->getCellIndex(i, j, k + 1))))) + (i != 0 && + !parent->activeCellExists(parent->getCellIndex(i - 1, j, k))) || + (i != I - 1 && + !parent->activeCellExists(parent->getCellIndex(i + 1, j, k))) || + (j != 0 && + !parent->activeCellExists(parent->getCellIndex(i, j - 1, k))) || + (j != J - 1 && + !parent->activeCellExists(parent->getCellIndex(i, j + 1, k))) || + (k != 0 && + !parent->activeCellExists(parent->getCellIndex(i, j, k - 1))) || + (k != K - 1 && + !parent->activeCellExists(parent->getCellIndex(i, j, k + 1))))) for(int ii = 0; ii < 8; ii++) child->eraseActiveCell(idx[ii]); } return removeBadChildCells(child); @@ -116,13 +120,15 @@ void removeParentCellsWithChildren(cartesianBox<double> *box) if(!box->getChildBox()) return; for(int i = 0; i < box->getNxi(); i++) for(int j = 0; j < box->getNeta(); j++) - for(int k = 0; k < box->getNzeta(); k++){ - if(box->activeCellExists(box->getCellIndex(i, j, k))){ + for(int k = 0; k < box->getNzeta(); k++) { + if(box->activeCellExists(box->getCellIndex(i, j, k))) { cartesianBox<double> *parent = box, *child; int ii = i, jj = j, kk = k; - while((child = parent->getChildBox())){ - ii *= 2; jj *= 2; kk *= 2; - if(child->activeCellExists(child->getCellIndex(ii, jj, kk))){ + while((child = parent->getChildBox())) { + ii *= 2; + jj *= 2; + kk *= 2; + if(child->activeCellExists(child->getCellIndex(ii, jj, kk))) { box->eraseActiveCell(box->getCellIndex(i, j, k)); break; } @@ -138,40 +144,42 @@ void computeLevelset(GModel *gm, cartesianBox<double> &box) std::vector<SPoint3> nodes; std::vector<int> indices; for(cartesianBox<double>::valIter it = box.nodalValuesBegin(); - it != box.nodalValuesEnd(); ++it){ + it != box.nodalValuesEnd(); ++it) { nodes.push_back(box.getNodeCoordinates(it->first)); indices.push_back(it->first); } - //Msg::Info(" %d nodes in the grid at level %d", (int)nodes.size(), box.getLevel()); + // Msg::Info(" %d nodes in the grid at level %d", (int)nodes.size(), + // box.getLevel()); std::vector<double> dist, localdist; std::vector<SPoint3> dummy; - for(GModel::fiter fit = gm->firstFace(); fit != gm->lastFace(); fit++){ - if((*fit)->geomType() == GEntity::DiscreteSurface){ - for(unsigned int k = 0; k < (*fit)->getNumMeshElements(); k++){ + for(GModel::fiter fit = gm->firstFace(); fit != gm->lastFace(); fit++) { + if((*fit)->geomType() == GEntity::DiscreteSurface) { + for(unsigned int k = 0; k < (*fit)->getNumMeshElements(); k++) { std::vector<double> iDistances; std::vector<SPoint3> iClosePts; std::vector<double> iDistancesE; MElement *e = (*fit)->getMeshElement(k); - if(e->getType() == TYPE_TRI){ + if(e->getType() == TYPE_TRI) { MVertex *v1 = e->getVertex(0); MVertex *v2 = e->getVertex(1); MVertex *v3 = e->getVertex(2); - SPoint3 p1(v1->x(),v1->y(),v1->z()); - SPoint3 p2(v2->x(),v2->y(),v2->z()); - SPoint3 p3(v3->x(),v3->y(),v3->z()); - //sign plus if in the direction of the normal + SPoint3 p1(v1->x(), v1->y(), v1->z()); + SPoint3 p2(v2->x(), v2->y(), v2->z()); + SPoint3 p3(v3->x(), v3->y(), v3->z()); + // sign plus if in the direction of the normal signedDistancesPointsTriangle(localdist, dummy, nodes, p2, p1, p3); } if(dist.empty()) dist = localdist; - else{ - for(unsigned int j = 0; j < localdist.size(); j++){ - dist[j] = (fabs(dist[j]) < fabs(localdist[j])) ? dist[j] : localdist[j]; + else { + for(unsigned int j = 0; j < localdist.size(); j++) { + dist[j] = + (fabs(dist[j]) < fabs(localdist[j])) ? dist[j] : localdist[j]; } } } } - else{ + else { // we should use the STL here Msg::Info("Levelset computation on CAD surface not implemented"); } @@ -183,12 +191,11 @@ void computeLevelset(GModel *gm, cartesianBox<double> &box) if(box.getChildBox()) computeLevelset(gm, *box.getChildBox()); } -inline double det3(double d11, double d12, double d13, - double d21, double d22, double d23, - double d31, double d32, double d33) +inline double det3(double d11, double d12, double d13, double d21, double d22, + double d23, double d31, double d32, double d33) { return d11 * (d22 * d33 - d23 * d32) - d21 * (d12 * d33 - d13 * d32) + - d31 * (d12 * d23 - d13 * d22); + d31 * (d12 * d23 - d13 * d22); } inline void norm(const double *vec, double *norm) @@ -199,7 +206,8 @@ inline void norm(const double *vec, double *norm) norm[2] = vec[2] / n; } -inline void cross(const double *pt0, const double *pt1, const double *pt2, double *cross) +inline void cross(const double *pt0, const double *pt1, const double *pt2, + double *cross) { double v1[3] = {pt1[0] - pt0[0], pt1[1] - pt0[1], pt1[2] - pt0[2]}; double v2[3] = {pt2[0] - pt0[0], pt2[1] - pt0[1], pt2[2] - pt0[2]}; @@ -211,31 +219,38 @@ inline void cross(const double *pt0, const double *pt1, const double *pt2, doubl inline bool isPlanar(const double *pt1, const double *pt2, const double *pt3, const double *pt4) { - double c1[3]; cross(pt1, pt2, pt3, c1); - double c2[3]; cross(pt1, pt2, pt4, c2); - double n1[3]; norm(c1, n1); - double n2[3]; norm(c2, n2); + double c1[3]; + cross(pt1, pt2, pt3, c1); + double c2[3]; + cross(pt1, pt2, pt4, c2); + double n1[3]; + norm(c1, n1); + double n2[3]; + norm(c2, n2); return (n1[0] == n2[0] && n1[1] == n2[1] && n1[2] == n2[2]); } inline double evalRadialFnDer(int p, int index, double dx, double dy, double dz, double ep) { - double r2 = dx*dx+dy*dy+dz*dz; //r^2 + double r2 = dx * dx + dy * dy + dz * dz; // r^2 switch(index) { - case 0 : // GA + case 0: // GA switch(p) { - case 0: return exp(-ep*ep*r2); - case 1: return -2*ep*ep*dx*exp(-ep*ep*r2); // _x - case 2: return -2*ep*ep*dy*exp(-ep*ep*r2); // _y - case 3: return -2*ep*ep*dz*exp(-ep*ep*r2); // _z + case 0: return exp(-ep * ep * r2); + case 1: + return -2 * ep * ep * dx * exp(-ep * ep * r2); // _x + case 2: + return -2 * ep * ep * dy * exp(-ep * ep * r2); // _y + case 3: + return -2 * ep * ep * dz * exp(-ep * ep * r2); // _z } - case 1 : //MQ + case 1: // MQ switch(p) { - case 0: return sqrt(1+ep*ep*r2); - case 1: return ep*ep*dx/sqrt(1+ep*ep*r2); - case 2: return ep*ep*dy/sqrt(1+ep*ep*r2); - case 3: return ep*ep*dz/sqrt(1+ep*ep*r2); + case 0: return sqrt(1 + ep * ep * r2); + case 1: return ep * ep * dx / sqrt(1 + ep * ep * r2); + case 2: return ep * ep * dy / sqrt(1 + ep * ep * r2); + case 3: return ep * ep * dz / sqrt(1 + ep * ep * r2); } } return 0.; @@ -243,33 +258,32 @@ inline double evalRadialFnDer(int p, int index, double dx, double dy, double dz, inline void printNodes(fullMatrix<double> &myNodes, fullMatrix<double> &surf) { - FILE * xyz = Fopen("myNodes.pos","w"); - if(xyz){ - fprintf(xyz,"View \"\"{\n"); - for(int itv = 1; itv != myNodes.size1(); ++itv){ - fprintf(xyz,"SP(%g,%g,%g){%g};\n", myNodes(itv,0), myNodes(itv,1), - myNodes(itv,2), surf(itv,0)); + FILE *xyz = Fopen("myNodes.pos", "w"); + if(xyz) { + fprintf(xyz, "View \"\"{\n"); + for(int itv = 1; itv != myNodes.size1(); ++itv) { + fprintf(xyz, "SP(%g,%g,%g){%g};\n", myNodes(itv, 0), myNodes(itv, 1), + myNodes(itv, 2), surf(itv, 0)); } - fprintf(xyz,"};\n"); + fprintf(xyz, "};\n"); fclose(xyz); } } -// extrude a list of the primitive levelsets with a "Level-order traversal sequence" +// extrude a list of the primitive levelsets with a "Level-order traversal +// sequence" void gLevelset::getPrimitives(std::vector<gLevelset *> &gLsPrimitives) { std::queue<gLevelset *> Q; Q.push(this); - while(!Q.empty()){ + while(!Q.empty()) { gLevelset *p = Q.front(); std::vector<gLevelset *> pp; pp = p->getChildren(); - if(pp.empty()) - gLsPrimitives.push_back(p); + if(pp.empty()) gLsPrimitives.push_back(p); Q.pop(); - if(!pp.empty()){ - for(int i = 0; i < (int)pp.size(); i++) - Q.push(pp[i]); + if(!pp.empty()) { + for(int i = 0; i < (int)pp.size(); i++) Q.push(pp[i]); } } } @@ -281,7 +295,7 @@ void gLevelset::getPrimitivesPO(std::vector<gLevelset *> &gLsPrimitives) std::stack<gLevelset *> S; std::stack<gLevelset *> Sc; // levelset checked S.push(this); - while(!S.empty()){ + while(!S.empty()) { gLevelset *p = S.top(); std::vector<gLevelset *> pp; pp = p->getChildren(); @@ -311,7 +325,7 @@ void gLevelset::getRPN(std::vector<gLevelset *> &gLsRPN) std::stack<gLevelset *> S; std::stack<gLevelset *> Sc; // levelset checked S.push(this); - while(!S.empty()){ + while(!S.empty()) { gLevelset *p = S.top(); std::vector<gLevelset *> pp; pp = p->getChildren(); @@ -336,48 +350,46 @@ void gLevelset::getRPN(std::vector<gLevelset *> &gLsRPN) } } -gLevelset::gLevelset(const gLevelset &lv) -{ - tag_ = lv.tag_; -} +gLevelset::gLevelset(const gLevelset &lv) { tag_ = lv.tag_; } -gLevelsetSphere::gLevelsetSphere(const double &x, const double &y, const double &z, - const double &R, int tag) +gLevelsetSphere::gLevelsetSphere(const double &x, const double &y, + const double &z, const double &R, int tag) : gLevelsetPrimitive(tag), xc(x), yc(y), zc(z), r(R) { _hasDerivatives = true; } -void gLevelsetSphere::gradient(double x, double y, double z, - double & dfdx, double & dfdy, double & dfdz) const +void gLevelsetSphere::gradient(double x, double y, double z, double &dfdx, + double &dfdy, double &dfdz) const { - const double xx = x-xc, yy = y-yc, zz = z-zc, dist = sqrt(xx*xx+yy*yy+zz*zz); + const double xx = x - xc, yy = y - yc, zz = z - zc, + dist = sqrt(xx * xx + yy * yy + zz * zz); - dfdx = xx/dist; - dfdy = yy/dist; - dfdz = zz/dist; + dfdx = xx / dist; + dfdy = yy / dist; + dfdz = zz / dist; } -void gLevelsetSphere::hessian(double x, double y, double z, - double & dfdxx, double & dfdxy, double & dfdxz, - double & dfdyx, double & dfdyy, double & dfdyz, - double & dfdzx, double & dfdzy, double & dfdzz) const +void gLevelsetSphere::hessian(double x, double y, double z, double &dfdxx, + double &dfdxy, double &dfdxz, double &dfdyx, + double &dfdyy, double &dfdyz, double &dfdzx, + double &dfdzy, double &dfdzz) const { - const double xx = x-xc, yy = y-yc, zz = z-zc; - const double distSq = xx*xx+yy*yy, fact = 1./(distSq*sqrt(distSq)); + const double xx = x - xc, yy = y - yc, zz = z - zc; + const double distSq = xx * xx + yy * yy, fact = 1. / (distSq * sqrt(distSq)); - dfdxx = (zz*zz+yy*yy)*fact; - dfdxy = -xx*yy*fact; - dfdxz = -xx*zz*fact; + dfdxx = (zz * zz + yy * yy) * fact; + dfdxy = -xx * yy * fact; + dfdxz = -xx * zz * fact; dfdyx = dfdxy; - dfdyy = (xx*xx+zz*zz)*fact; - dfdyz = -yy*zz*fact; + dfdyy = (xx * xx + zz * zz) * fact; + dfdyz = -yy * zz * fact; dfdzx = dfdxz; dfdzy = dfdyz; - dfdzz = (xx*xx+yy*yy)*fact; + dfdzz = (xx * xx + yy * yy) * fact; } -gLevelsetPlane::gLevelsetPlane(const std::vector<double> &pt, +gLevelsetPlane::gLevelsetPlane(const std::vector<double> &pt, const std::vector<double> &norm, int tag) : gLevelsetPrimitive(tag) { @@ -387,7 +399,7 @@ gLevelsetPlane::gLevelsetPlane(const std::vector<double> &pt, d = -a * pt[0] - b * pt[1] - c * pt[2]; } -gLevelsetPlane::gLevelsetPlane(const double * pt, const double *norm, int tag) +gLevelsetPlane::gLevelsetPlane(const double *pt, const double *norm, int tag) : gLevelsetPrimitive(tag) { a = norm[0]; @@ -396,14 +408,15 @@ gLevelsetPlane::gLevelsetPlane(const double * pt, const double *norm, int tag) d = -a * pt[0] - b * pt[1] - c * pt[2]; } -gLevelsetPlane::gLevelsetPlane(const double * pt1, const double *pt2, +gLevelsetPlane::gLevelsetPlane(const double *pt1, const double *pt2, const double *pt3, int tag) : gLevelsetPrimitive(tag) { a = det3(1., pt1[1], pt1[2], 1., pt2[1], pt2[2], 1., pt3[1], pt3[2]); b = det3(pt1[0], 1., pt1[2], pt2[0], 1., pt2[2], pt3[0], 1., pt3[2]); c = det3(pt1[0], pt1[1], 1., pt2[0], pt2[1], 1., pt3[0], pt3[1], 1.); - d = -det3(pt1[0], pt1[1], pt1[2], pt2[0], pt2[1], pt2[2], pt3[0], pt3[1], pt3[2]); + d = -det3(pt1[0], pt1[1], pt1[2], pt2[0], pt2[1], pt2[2], pt3[0], pt3[1], + pt3[2]); } gLevelsetPlane::gLevelsetPlane(const gLevelsetPlane &lv) @@ -416,37 +429,36 @@ gLevelsetPlane::gLevelsetPlane(const gLevelsetPlane &lv) } // level set defined by points (RBF interpolation) -fullMatrix<double> gLevelsetPoints::generateRbfMat(int p, int index, - const fullMatrix<double> &nodes1, - const fullMatrix<double> &nodes2) const +fullMatrix<double> +gLevelsetPoints::generateRbfMat(int p, int index, + const fullMatrix<double> &nodes1, + const fullMatrix<double> &nodes2) const { int m = nodes2.size1(); int n = nodes1.size1(); - fullMatrix<double> rbfMat(m,n); + fullMatrix<double> rbfMat(m, n); - double eps =0.5/delta; + double eps = 0.5 / delta; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { - double dx = nodes2(i,0)-nodes1(j,0); - double dy = nodes2(i,1)-nodes1(j,1); - double dz = nodes2(i,2)-nodes1(j,2); - rbfMat(i,j) = evalRadialFnDer(p, index, dx,dy,dz,eps); + double dx = nodes2(i, 0) - nodes1(j, 0); + double dy = nodes2(i, 1) - nodes1(j, 1); + double dz = nodes2(i, 2) - nodes1(j, 2); + rbfMat(i, j) = evalRadialFnDer(p, index, dx, dy, dz, eps); } } return rbfMat; } -void gLevelsetPoints::RbfOp(int p, int index, - const fullMatrix<double> &cntrs, +void gLevelsetPoints::RbfOp(int p, int index, const fullMatrix<double> &cntrs, const fullMatrix<double> &nodes, - fullMatrix<double> &D, - bool isLocal) const + fullMatrix<double> &D, bool isLocal) const { - fullMatrix<double> rbfMatB = generateRbfMat(p,index, cntrs,nodes); + fullMatrix<double> rbfMatB = generateRbfMat(p, index, cntrs, nodes); fullMatrix<double> rbfInvA; - if(isLocal){ - rbfInvA = generateRbfMat(0,index, cntrs,cntrs); + if(isLocal) { + rbfInvA = generateRbfMat(0, index, cntrs, cntrs); rbfInvA.invertInPlace(); } else { @@ -461,12 +473,13 @@ void gLevelsetPoints::evalRbfDer(int p, int index, const fullMatrix<double> &cntrs, const fullMatrix<double> &nodes, const fullMatrix<double> &fValues, - fullMatrix<double> &fApprox, bool isLocal) const + fullMatrix<double> &fApprox, + bool isLocal) const { - fApprox.resize(nodes.size1(),fValues.size2()); + fApprox.resize(nodes.size1(), fValues.size2()); fullMatrix<double> D; - RbfOp(p,index, cntrs,nodes,D,isLocal); - fApprox.gemm(D,fValues, 1.0, 0.0); + RbfOp(p, index, cntrs, nodes, D, isLocal); + fApprox.gemm(D, fValues, 1.0, 0.0); } void gLevelsetPoints::setup_level_set(const fullMatrix<double> &cntrs, @@ -474,62 +487,67 @@ void gLevelsetPoints::setup_level_set(const fullMatrix<double> &cntrs, fullMatrix<double> &level_set_funvals) { int numNodes = cntrs.size1(); - int nTot = 3*numNodes; + int nTot = 3 * numNodes; double normFactor; - level_set_nodes.resize(nTot,3); - level_set_funvals.resize(nTot,1); - fullMatrix<double> ONES(numNodes+1,1),sx(numNodes,1),sy(numNodes,1); - fullMatrix<double> sz(numNodes,1),norms(numNodes,3), cntrsPlus(numNodes+1,3); + level_set_nodes.resize(nTot, 3); + level_set_funvals.resize(nTot, 1); + fullMatrix<double> ONES(numNodes + 1, 1), sx(numNodes, 1), sy(numNodes, 1); + fullMatrix<double> sz(numNodes, 1), norms(numNodes, 3), + cntrsPlus(numNodes + 1, 3); // Computes the normal vectors to the surface at each node double dist_min = 1.e6; double dist_max = 1.e-6; - for(int i = 0; i < numNodes; ++i){ - ONES(i,0)=1.0; - cntrsPlus(i,0) = cntrs(i,0); - cntrsPlus(i,1) = cntrs(i,1); - cntrsPlus(i,2) = cntrs(i,2); - for(int j = i+1; j < numNodes; j++){ - double dist = sqrt((cntrs(i,0)-cntrs(j,0))*(cntrs(i,0)-cntrs(j,0))+ - (cntrs(i,1)-cntrs(j,1))*(cntrs(i,1)-cntrs(j,1))+ - (cntrs(i,2)-cntrs(j,2))*(cntrs(i,2)-cntrs(j,2))); - if(dist<dist_min) dist_min = dist; - if(dist>dist_max) dist_max = dist; + for(int i = 0; i < numNodes; ++i) { + ONES(i, 0) = 1.0; + cntrsPlus(i, 0) = cntrs(i, 0); + cntrsPlus(i, 1) = cntrs(i, 1); + cntrsPlus(i, 2) = cntrs(i, 2); + for(int j = i + 1; j < numNodes; j++) { + double dist = + sqrt((cntrs(i, 0) - cntrs(j, 0)) * (cntrs(i, 0) - cntrs(j, 0)) + + (cntrs(i, 1) - cntrs(j, 1)) * (cntrs(i, 1) - cntrs(j, 1)) + + (cntrs(i, 2) - cntrs(j, 2)) * (cntrs(i, 2) - cntrs(j, 2))); + if(dist < dist_min) dist_min = dist; + if(dist > dist_max) dist_max = dist; } } - ONES(numNodes,0) = -1.0; - cntrsPlus(numNodes,0) = cntrs(0,0)+dist_max; - cntrsPlus(numNodes,1) = cntrs(0,1)+dist_max; - cntrsPlus(numNodes,2) = cntrs(0,2)+dist_max; - - delta = 0.23*dist_min; - evalRbfDer(1, 1, cntrsPlus,cntrs,ONES,sx, true); - evalRbfDer(2, 1, cntrsPlus,cntrs,ONES,sy, true); - evalRbfDer(3, 1, cntrsPlus,cntrs,ONES,sz, true); - for(int i = 0; i < numNodes; ++i){ - normFactor = sqrt(sx(i,0)*sx(i,0)+sy(i,0)*sy(i,0)+sz(i,0)*sz(i,0)); - sx(i,0) = sx(i,0)/normFactor; - sy(i,0) = sy(i,0)/normFactor; - sz(i,0) = sz(i,0)/normFactor; - norms(i,0) = sx(i,0);norms(i,1) = sy(i,0);norms(i,2) = sz(i,0); + ONES(numNodes, 0) = -1.0; + cntrsPlus(numNodes, 0) = cntrs(0, 0) + dist_max; + cntrsPlus(numNodes, 1) = cntrs(0, 1) + dist_max; + cntrsPlus(numNodes, 2) = cntrs(0, 2) + dist_max; + + delta = 0.23 * dist_min; + evalRbfDer(1, 1, cntrsPlus, cntrs, ONES, sx, true); + evalRbfDer(2, 1, cntrsPlus, cntrs, ONES, sy, true); + evalRbfDer(3, 1, cntrsPlus, cntrs, ONES, sz, true); + for(int i = 0; i < numNodes; ++i) { + normFactor = + sqrt(sx(i, 0) * sx(i, 0) + sy(i, 0) * sy(i, 0) + sz(i, 0) * sz(i, 0)); + sx(i, 0) = sx(i, 0) / normFactor; + sy(i, 0) = sy(i, 0) / normFactor; + sz(i, 0) = sz(i, 0) / normFactor; + norms(i, 0) = sx(i, 0); + norms(i, 1) = sy(i, 0); + norms(i, 2) = sz(i, 0); } - for(int i = 0; i < numNodes; ++i){ - for(int j = 0; j < 3; ++j){ - level_set_nodes(i,j) = cntrs(i,j); - level_set_nodes(i+numNodes,j) = cntrs(i,j)-delta*norms(i,j); - level_set_nodes(i+2*numNodes,j) = cntrs(i,j)+delta*norms(i,j); + for(int i = 0; i < numNodes; ++i) { + for(int j = 0; j < 3; ++j) { + level_set_nodes(i, j) = cntrs(i, j); + level_set_nodes(i + numNodes, j) = cntrs(i, j) - delta * norms(i, j); + level_set_nodes(i + 2 * numNodes, j) = cntrs(i, j) + delta * norms(i, j); } - level_set_funvals(i,0) = 0.0; - level_set_funvals(i+numNodes,0) = -1; - level_set_funvals(i+2*numNodes,0) = 1; + level_set_funvals(i, 0) = 0.0; + level_set_funvals(i + numNodes, 0) = -1; + level_set_funvals(i + 2 * numNodes, 0) = 1; } } gLevelsetPoints::gLevelsetPoints(fullMatrix<double> ¢ers, int tag) : gLevelsetPrimitive(tag) { - int nbNodes = 3*centers.size1(); + int nbNodes = 3 * centers.size1(); setup_level_set(centers, points, surf); printNodes(points, surf); @@ -537,7 +555,7 @@ gLevelsetPoints::gLevelsetPoints(fullMatrix<double> ¢ers, int tag) // build invA matrix for 3*n points int indexRBF = 1; matAInv.resize(nbNodes, nbNodes); - matAInv = generateRbfMat(0, indexRBF, points,points); + matAInv = generateRbfMat(0, indexRBF, points, points); matAInv.invertInPlace(); } @@ -552,8 +570,8 @@ double gLevelsetPoints::operator()(double x, double y, double z) const if(mapP.empty()) Msg::Info("Levelset Points : call computeLS() before calling operator()\n"); - SPoint3 sp(x,y,z); - std::map<SPoint3,double>::const_iterator it = mapP.find(sp); + SPoint3 sp(x, y, z); + std::map<SPoint3, double>::const_iterator it = mapP.find(sp); if(it != mapP.end()) return it->second; printf("Levelset Points : Point not found\n"); return 0; @@ -566,17 +584,17 @@ double gLevelsetPoints::operator()(double x, double y, double z) const // return surf_eval(0,0); } -void gLevelsetPoints::computeLS(std::vector<MVertex*> &vert) +void gLevelsetPoints::computeLS(std::vector<MVertex *> &vert) { fullMatrix<double> xyz_eval(vert.size(), 3), surf_eval(vert.size(), 1); - for(unsigned int i = 0; i < vert.size(); i++){ - xyz_eval(i,0) = vert[i]->x(); - xyz_eval(i,1) = vert[i]->y(); - xyz_eval(i,2) = vert[i]->z(); + for(unsigned int i = 0; i < vert.size(); i++) { + xyz_eval(i, 0) = vert[i]->x(); + xyz_eval(i, 1) = vert[i]->y(); + xyz_eval(i, 2) = vert[i]->z(); } evalRbfDer(0, 1, points, xyz_eval, surf, surf_eval); - for(unsigned int i = 0; i < vert.size(); i++){ - mapP[SPoint3(vert[i]->x(), vert[i]->y(),vert[i]->z())] = surf_eval(i,0); + for(unsigned int i = 0; i < vert.size(); i++) { + mapP[SPoint3(vert[i]->x(), vert[i]->y(), vert[i]->z())] = surf_eval(i, 0); } } @@ -594,19 +612,18 @@ void gLevelsetPoints::computeLS(std::vector<MVertex*> &vert) gLevelsetQuadric::gLevelsetQuadric(const gLevelsetQuadric &lv) : gLevelsetPrimitive(lv) { - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { B[i] = lv.B[i]; - for(int j = 0; j < 3; j++) - A[i][j] = lv.A[i][j]; + for(int j = 0; j < 3; j++) A[i][j] = lv.A[i][j]; } C = lv.C; } void gLevelsetQuadric::Ax(const double x[3], double res[3], double fact) { - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { res[i] = 0.; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { res[i] += A[i][j] * x[j] * fact; } } @@ -614,9 +631,9 @@ void gLevelsetQuadric::Ax(const double x[3], double res[3], double fact) void gLevelsetQuadric::xAx(const double x[3], double &res, double fact) { - res= fact * (A[0][0] * x[0] * x[0] + A[1][1] * x[1] * x[1] + - A[2][2] * x[2] * x[2] + A[1][0] * x[1] * x[0] * 2. + - A[2][0] * x[2] * x[0] * 2. + A[1][2] * x[1] * x[2] * 2.); + res = fact * (A[0][0] * x[0] * x[0] + A[1][1] * x[1] * x[1] + + A[2][2] * x[2] * x[2] + A[1][0] * x[1] * x[0] * 2. + + A[2][0] * x[2] * x[0] * 2. + A[1][2] * x[1] * x[2] * 2.); } void gLevelsetQuadric::translate(const double transl[3]) @@ -636,11 +653,11 @@ void gLevelsetQuadric::rotate(const double rotate[3][3]) { double a11 = 0., a12 = 0., a13 = 0., a22 = 0., a23 = 0., a33 = 0.; double b1 = 0., b2 = 0., b3 = 0.; - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { b1 += B[i] * rotate[i][0]; b2 += B[i] * rotate[i][1]; b3 += B[i] * rotate[i][2]; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { a11 += rotate[i][0] * A[i][j] * rotate[j][0]; a12 += rotate[i][0] * A[i][j] * rotate[j][1]; a13 += rotate[i][0] * A[i][j] * rotate[j][2]; @@ -661,14 +678,16 @@ void gLevelsetQuadric::rotate(const double rotate[3][3]) } // computes the rotation matrix of the rotation of the vector (0,0,1) to dir -void gLevelsetQuadric::computeRotationMatrix(const double dir[3], double t[3][3]) +void gLevelsetQuadric::computeRotationMatrix(const double dir[3], + double t[3][3]) { double norm = sqrt(dir[0] * dir[0] + dir[1] * dir[1]); double n[3] = {1., 0., 0.}; double ct = 1., st = 0.; if(norm != 0.) { double theta = atan(norm / dir[2]); - n[0] = dir[1] / norm; n[1] = -dir[0] / norm; + n[0] = dir[1] / norm; + n[1] = -dir[0] / norm; ct = cos(theta); st = sin(theta); } @@ -688,11 +707,11 @@ void gLevelsetQuadric::computeRotationMatrix(const double dir1[3], double t[3][3]) { double norm = sqrt((dir1[1] * dir2[2] - dir1[2] * dir2[1]) * - (dir1[1] * dir2[2] - dir1[2] * dir2[1]) - + (dir1[2] * dir2[0] - dir1[0] * dir2[2]) * - (dir1[2] * dir2[0] - dir1[0] * dir2[2]) - + (dir1[0] * dir2[1] - dir1[1] * dir2[0]) * - (dir1[0] * dir2[1] - dir1[1] * dir2[0])); + (dir1[1] * dir2[2] - dir1[2] * dir2[1]) + + (dir1[2] * dir2[0] - dir1[0] * dir2[2]) * + (dir1[2] * dir2[0] - dir1[0] * dir2[2]) + + (dir1[0] * dir2[1] - dir1[1] * dir2[0]) * + (dir1[0] * dir2[1] - dir1[1] * dir2[0])); double n[3] = {1., 0., 0.}; double ct = 1., st = 0.; if(norm != 0.) { @@ -716,7 +735,7 @@ void gLevelsetQuadric::computeRotationMatrix(const double dir1[3], void gLevelsetQuadric::init() { - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { B[i] = 0.; for(int j = 0; j < 3; j++) A[i][j] = 0.; } @@ -725,47 +744,47 @@ void gLevelsetQuadric::init() double gLevelsetQuadric::operator()(double x, double y, double z) const { - return(A[0][0] * x * x + 2. * A[0][1] * x * y + 2. * A[0][2] * x * z + - A[1][1] * y * y + 2. * A[1][2] * y * z + A[2][2] * z * z + - B[0] * x + B[1] * y + B[2] * z + C); + return (A[0][0] * x * x + 2. * A[0][1] * x * y + 2. * A[0][2] * x * z + + A[1][1] * y * y + 2. * A[1][2] * y * z + A[2][2] * z * z + B[0] * x + + B[1] * y + B[2] * z + C); } gLevelsetShamrock::gLevelsetShamrock(double _xmid, double _ymid, double _zmid, double _a, double _b, int _c, int tag) - : gLevelsetPrimitive(tag), xmid(_xmid), - a(_a), b(_b), c(_c) + : gLevelsetPrimitive(tag), xmid(_xmid), a(_a), b(_b), c(_c) { // creating the iso-zero double angle = 0.; double r; - while(angle<=2.*M_PI){ - r = a+b*sin(c*angle); - iso_x.push_back(r*sin(angle)+xmid); - iso_y.push_back(r*cos(angle)+xmid); - angle += 2.*M_PI/1000.; + while(angle <= 2. * M_PI) { + r = a + b * sin(c * angle); + iso_x.push_back(r * sin(angle) + xmid); + iso_y.push_back(r * cos(angle) + xmid); + angle += 2. * M_PI / 1000.; } } double gLevelsetShamrock::operator()(double x, double y, double z) const { // computing distance to pre-defined (sampled) iso-zero - double dx,dy,xi,yi,d; - dx = x-iso_x[0]; - dy = y-iso_y[0]; - double distance = sqrt(dx*dx+dy*dy); + double dx, dy, xi, yi, d; + dx = x - iso_x[0]; + dy = y - iso_y[0]; + double distance = sqrt(dx * dx + dy * dy); std::vector<double>::const_iterator itx = iso_x.begin(); std::vector<double>::const_iterator itxen = iso_x.end(); std::vector<double>::const_iterator ity = iso_y.begin(); std::vector<double>::const_iterator itminx = iso_x.begin(); std::vector<double>::const_iterator itminy = iso_y.begin(); - itx++;ity++; - for(;itx!=itxen;itx++,ity++){ + itx++; + ity++; + for(; itx != itxen; itx++, ity++) { xi = *itx; yi = *ity; - dx = x-xi; - dy = y-yi; - d = sqrt(dx*dx+dy*dy); - if(distance>d){ + dx = x - xi; + dy = y - yi; + d = sqrt(dx * dx + dy * dy); + if(distance > d) { distance = d; itminx = itx; itminy = ity; @@ -773,25 +792,26 @@ double gLevelsetShamrock::operator()(double x, double y, double z) const } // still need to find the LS sign... using vectorial prod with tangent vector // if not, the LS gradient is discontinuous on iso-zero... oups ! - SVector3 t,p; + SVector3 t, p; p(0) = (*itminx) - x; p(1) = (*itminy) - y; - if(itminx==(itxen-1)){ + if(itminx == (itxen - 1)) { t(0) = iso_x[0] - (*itminx); t(1) = iso_y[0] - (*itminy); } - else{ - t(0) = (*(itminx+1)) - (*itminx); - t(1) = (*(itminy+1)) - (*itminy); + else { + t(0) = (*(itminx + 1)) - (*itminx); + t(1) = (*(itminy + 1)) - (*itminy); } - double vectprod = (p(0)*t(1) - p(1)*t(0)); + double vectprod = (p(0) * t(1) - p(1) * t(0)); double sign = (vectprod < 0.) ? -1. : 1.; return sign * distance; } -gLevelsetPopcorn::gLevelsetPopcorn(double _xc, double _yc, double _zc, double _r0, - double _A, double _sigma, int tag) +gLevelsetPopcorn::gLevelsetPopcorn(double _xc, double _yc, double _zc, + double _r0, double _A, double _sigma, + int tag) : gLevelsetPrimitive(tag) { A = _A; @@ -805,23 +825,34 @@ gLevelsetPopcorn::gLevelsetPopcorn(double _xc, double _yc, double _zc, double _r double gLevelsetPopcorn::operator()(double x, double y, double z) const { double s2 = sigma * sigma; - double r = sqrt((x-xc)*(x-xc)+(y-yc)*(y-yc)+(z-zc)*(z-zc)); - //printf("z=%g zc=%g r=%g \n", z, zc, r); - double val = r - r0; - for(int k = 0; k< 5; k++){ - double xk = r0/sqrt(5.0)*(2.*cos(2*k*M_PI/5.0)); - double yk = r0/sqrt(5.0)*(2.*sin(2*k*M_PI/5.0)); - double zk = r0/sqrt(5.0); - val -= A*exp(-((x-xc-xk)*(x-xc-xk)+(y-yc-yk)*(y-yc-yk)+(z-zc-zk)*(z-zc-zk))/s2); + double r = + sqrt((x - xc) * (x - xc) + (y - yc) * (y - yc) + (z - zc) * (z - zc)); + // printf("z=%g zc=%g r=%g \n", z, zc, r); + double val = r - r0; + for(int k = 0; k < 5; k++) { + double xk = r0 / sqrt(5.0) * (2. * cos(2 * k * M_PI / 5.0)); + double yk = r0 / sqrt(5.0) * (2. * sin(2 * k * M_PI / 5.0)); + double zk = r0 / sqrt(5.0); + val -= + A * exp(-((x - xc - xk) * (x - xc - xk) + (y - yc - yk) * (y - yc - yk) + + (z - zc - zk) * (z - zc - zk)) / + s2); } - for(int k = 5; k< 10; k++){ - double xk = r0/sqrt(5.0)*(2.*cos((2.*(k-5.)-1.)*M_PI/5.0)); - double yk = r0/sqrt(5.0)*(2.*sin((2.*(k-5.)-1.)*M_PI/5.0)); - double zk = -r0/sqrt(5.0); - val -= A*exp(-((x-xc-xk)*(x-xc-xk)+(y-yc-yk)*(y-yc-yk)+(z-zc-zk)*(z-zc-zk))/s2); + for(int k = 5; k < 10; k++) { + double xk = r0 / sqrt(5.0) * (2. * cos((2. * (k - 5.) - 1.) * M_PI / 5.0)); + double yk = r0 / sqrt(5.0) * (2. * sin((2. * (k - 5.) - 1.) * M_PI / 5.0)); + double zk = -r0 / sqrt(5.0); + val -= + A * exp(-((x - xc - xk) * (x - xc - xk) + (y - yc - yk) * (y - yc - yk) + + (z - zc - zk) * (z - zc - zk)) / + s2); } - val -= A*exp(-((x-xc)*(x-xc)+(y-yc)*(y-yc)+(z-zc-r0)*(z-zc-r0))/s2); - val -= A*exp(-((x-xc)*(x-xc)+(y-yc)*(y-yc)+(z-zc+r0)*(z-zc+r0))/s2); + val -= A * exp(-((x - xc) * (x - xc) + (y - yc) * (y - yc) + + (z - zc - r0) * (z - zc - r0)) / + s2); + val -= A * exp(-((x - xc) * (x - xc) + (y - yc) * (y - yc) + + (z - zc + r0) * (z - zc + r0)) / + s2); return val; } @@ -868,30 +899,30 @@ double gLevelsetMathEvalAll::operator()(double x, double y, double z) const return 1.; } -void gLevelsetMathEvalAll::gradient(double x, double y, double z, - double & dfdx, double & dfdy, double & dfdz) const +void gLevelsetMathEvalAll::gradient(double x, double y, double z, double &dfdx, + double &dfdy, double &dfdz) const { std::vector<double> values(3), res(13); values[0] = x; values[1] = y; values[2] = z; - if(_expr->eval(values, res)){ + if(_expr->eval(values, res)) { dfdx = res[1]; dfdy = res[2]; dfdz = res[3]; } } -void gLevelsetMathEvalAll::hessian(double x, double y, double z, - double & dfdxx, double & dfdxy, double & dfdxz, - double & dfdyx, double & dfdyy, double & dfdyz, - double & dfdzx, double & dfdzy, double & dfdzz) const +void gLevelsetMathEvalAll::hessian(double x, double y, double z, double &dfdxx, + double &dfdxy, double &dfdxz, double &dfdyx, + double &dfdyy, double &dfdyz, double &dfdzx, + double &dfdzy, double &dfdzz) const { std::vector<double> values(3), res(13); values[0] = x; values[1] = y; values[2] = z; - if(_expr->eval(values, res)){ + if(_expr->eval(values, res)) { dfdxx = res[4]; dfdxy = res[5]; dfdxz = res[6]; @@ -907,28 +938,28 @@ void gLevelsetMathEvalAll::hessian(double x, double y, double z, #if defined(HAVE_ANN) gLevelsetDistMesh::gLevelsetDistMesh(GModel *gm, const std::string &physical, int nbClose, int tag) - : gLevelsetPrimitive(tag) - , _nbClose(nbClose) + : gLevelsetPrimitive(tag), _nbClose(nbClose) { - std::map<int, std::vector<GEntity*> > groups [4]; + std::map<int, std::vector<GEntity *> > groups[4]; gm->getPhysicalGroups(groups); - for(GModel::piter it = gm->firstPhysicalName(); - it != gm->lastPhysicalName() ; ++it){ - if(it->second == physical){ + for(GModel::piter it = gm->firstPhysicalName(); it != gm->lastPhysicalName(); + ++it) { + if(it->second == physical) { _entities = groups[it->first.first][it->first.second]; } } - if(_entities.size() == 0){ - Msg::Error("distanceToMesh: the physical name '%s' does not exist in the GModel", - physical.c_str()); + if(_entities.size() == 0) { + Msg::Error( + "distanceToMesh: the physical name '%s' does not exist in the GModel", + physical.c_str()); } - //setup + // setup std::set<MVertex *> _all; - for(unsigned int i = 0; i < _entities.size(); i++){ + for(unsigned int i = 0; i < _entities.size(); i++) { for(unsigned int k = 0; k < _entities[i]->getNumMeshElements(); k++) { MElement *e = _entities[i]->getMeshElement(k); - for(std::size_t j = 0; j< e->getNumVertices();j++){ + for(std::size_t j = 0; j < e->getNumVertices(); j++) { MVertex *v = _entities[i]->getMeshElement(k)->getVertex(j); _all.insert(v); _v2e.insert(std::make_pair(v, e)); @@ -937,15 +968,16 @@ gLevelsetDistMesh::gLevelsetDistMesh(GModel *gm, const std::string &physical, } ANNpointArray nodes; nodes = annAllocPts(_all.size(), 3); - std::set<MVertex*>::iterator itp = _all.begin(); + std::set<MVertex *>::iterator itp = _all.begin(); int ind = 0; - while(itp != _all.end()){ - MVertex* pt = *itp; + while(itp != _all.end()) { + MVertex *pt = *itp; nodes[ind][0] = pt->x(); nodes[ind][1] = pt->y(); nodes[ind][2] = pt->z(); _vertices.push_back(pt); - itp++; ind++; + itp++; + ind++; } _kdtree = new ANNkd_tree(nodes, _all.size(), 3); } @@ -965,49 +997,54 @@ double gLevelsetDistMesh::operator()(double x, double y, double z) const std::vector<ANNdist> dist(_nbClose); double point[3] = {x, y, z}; SPoint3 pt(x, y, z); - _kdtree->annkSearch(point, _nbClose, &index[0], &dist[0]); // squared distances - std::set<MElement*> elements; + _kdtree->annkSearch(point, _nbClose, &index[0], + &dist[0]); // squared distances + std::set<MElement *> elements; int dimE = 1; - for(int i = 0; i < _nbClose; i++){ + for(int i = 0; i < _nbClose; i++) { int iVertex = index[i]; MVertex *v = _vertices[iVertex]; - for(std::multimap<MVertex*,MElement*>::const_iterator itm = - _v2e.lower_bound(v); itm != _v2e.upper_bound(v); ++itm){ + for(std::multimap<MVertex *, MElement *>::const_iterator itm = + _v2e.lower_bound(v); + itm != _v2e.upper_bound(v); ++itm) { elements.insert(itm->second); dimE = itm->second->getDim(); } } double minDistance = 1.e22; SPoint3 closestPoint; - std::vector<MElement*> closestElements; - for(std::set<MElement*>::iterator it = elements.begin(); - it != elements.end(); ++it){ + std::vector<MElement *> closestElements; + for(std::set<MElement *>::iterator it = elements.begin(); + it != elements.end(); ++it) { double distance = 0.; MVertex *v1 = (*it)->getVertex(0); MVertex *v2 = (*it)->getVertex(1); SPoint3 p1(v1->x(), v1->y(), v1->z()); SPoint3 p2(v2->x(), v2->y(), v2->z()); SPoint3 closePt; - if(dimE == 1){ + if(dimE == 1) { signedDistancePointLine(p1, p2, pt, distance, closePt); // !! > 0 } - else if(dimE == 2){ + else if(dimE == 2) { MVertex *v3 = (*it)->getVertex(2); SPoint3 p3(v3->x(), v3->y(), v3->z()); - if(p1 == p2 || p1 == p3 || p2 == p3) distance = 1.e22; - else signedDistancePointTriangle(p1, p2, p3, pt, distance, closePt); + if(p1 == p2 || p1 == p3 || p2 == p3) + distance = 1.e22; + else + signedDistancePointTriangle(p1, p2, p3, pt, distance, closePt); } - else{ - Msg::Error("Cannot compute a distance to an entity of dimension %d\n", dimE); + else { + Msg::Error("Cannot compute a distance to an entity of dimension %d\n", + dimE); } - if(dimE == 1 && fabs(distance) < fabs(minDistance)){ + if(dimE == 1 && fabs(distance) < fabs(minDistance)) { minDistance = distance; } - else if(dimE == 2){ - if(fabs(distance) - fabs(minDistance) < 1.e-9){ + else if(dimE == 2) { + if(fabs(distance) - fabs(minDistance) < 1.e-9) { closestElements.push_back(*it); } - else if(fabs(distance) < fabs(minDistance)){ + else if(fabs(distance) < fabs(minDistance)) { closestPoint = closePt; minDistance = distance; closestElements.clear(); @@ -1015,30 +1052,40 @@ double gLevelsetDistMesh::operator()(double x, double y, double z) const } } } - if(closestElements.size() > 1){ + if(closestElements.size() > 1) { SVector3 vd(closestPoint, pt); SVector3 meanNorm(0., 0., 0.); // angle weighted mean normal - if(closestElements.size() == 2){ // closestPoint on edge - meanNorm = closestElements[0]->getFace(0).normal() + closestElements[1]->getFace(0).normal(); + if(closestElements.size() == 2) { // closestPoint on edge + meanNorm = closestElements[0]->getFace(0).normal() + + closestElements[1]->getFace(0).normal(); } - else{ // closestPoint on vertex - for(unsigned int i = 0; i < closestElements.size(); i++){ + else { // closestPoint on vertex + for(unsigned int i = 0; i < closestElements.size(); i++) { double alpha = 0.; - SPoint3 p1; bool found = false; - for(int j = 0; j < closestElements[i]->getNumEdges(); j++){ + SPoint3 p1; + bool found = false; + for(int j = 0; j < closestElements[i]->getNumEdges(); j++) { SPoint3 ep0 = closestElements[i]->getEdge(j).getVertex(0)->point(); SPoint3 ep1 = closestElements[i]->getEdge(j).getVertex(1)->point(); - if(closestPoint == ep0){ - if(!found) {p1 = ep1; found = true;} + if(closestPoint == ep0) { + if(!found) { + p1 = ep1; + found = true; + } else { - alpha = angle (SVector3(closestPoint, p1), SVector3(closestPoint, ep1)); + alpha = + angle(SVector3(closestPoint, p1), SVector3(closestPoint, ep1)); break; } } - if(closestPoint == ep1){ - if(!found) {p1 = ep0; found = true;} + if(closestPoint == ep1) { + if(!found) { + p1 = ep0; + found = true; + } else { - alpha = angle (SVector3(closestPoint, p1), SVector3(closestPoint, ep0)); + alpha = + angle(SVector3(closestPoint, p1), SVector3(closestPoint, ep0)); break; } } @@ -1055,15 +1102,15 @@ double gLevelsetDistMesh::operator()(double x, double y, double z) const } #endif -#if defined (HAVE_POST) +#if defined(HAVE_POST) gLevelsetPostView::gLevelsetPostView(int index, int tag) : gLevelsetPrimitive(tag), _viewIndex(index) { - if(_viewIndex >= 0 && _viewIndex < (int)PView::list.size()){ + if(_viewIndex >= 0 && _viewIndex < (int)PView::list.size()) { PView *view = PView::list[_viewIndex]; _octree = new OctreePost(view); } - else{ + else { Msg::Error("Unknown View[%d] in PostView levelset", _viewIndex); _octree = 0; } @@ -1084,15 +1131,17 @@ gLevelsetGenCylinder::gLevelsetGenCylinder(const double *pt, const double *dir, { A[0][0] = 1.; A[1][1] = 1.; - C = - R * R; + C = -R * R; double rot[3][3]; computeRotationMatrix(dir, rot); rotate(rot); translate(pt); } -gLevelsetGenCylinder::gLevelsetGenCylinder(const gLevelsetGenCylinder& lv) - : gLevelsetQuadric(lv){} +gLevelsetGenCylinder::gLevelsetGenCylinder(const gLevelsetGenCylinder &lv) + : gLevelsetQuadric(lv) +{ +} gLevelsetEllipsoid::gLevelsetEllipsoid(const double *pt, const double *dir, const double &a, const double &b, @@ -1109,8 +1158,10 @@ gLevelsetEllipsoid::gLevelsetEllipsoid(const double *pt, const double *dir, translate(pt); } -gLevelsetEllipsoid::gLevelsetEllipsoid(const gLevelsetEllipsoid& lv) - : gLevelsetQuadric(lv){} +gLevelsetEllipsoid::gLevelsetEllipsoid(const gLevelsetEllipsoid &lv) + : gLevelsetQuadric(lv) +{ +} gLevelsetCone::gLevelsetCone(const double *pt, const double *dir, const double &angle, int tag) @@ -1125,13 +1176,11 @@ gLevelsetCone::gLevelsetCone(const double *pt, const double *dir, translate(pt); } -gLevelsetCone::gLevelsetCone(const gLevelsetCone& lv) - : gLevelsetQuadric(lv){} +gLevelsetCone::gLevelsetCone(const gLevelsetCone &lv) : gLevelsetQuadric(lv) {} -gLevelsetGeneralQuadric::gLevelsetGeneralQuadric(const double *pt, const double *dir, - const double &x2, const double &y2, - const double &z2, const double &z, - const double &c, int tag) +gLevelsetGeneralQuadric::gLevelsetGeneralQuadric( + const double *pt, const double *dir, const double &x2, const double &y2, + const double &z2, const double &z, const double &c, int tag) : gLevelsetQuadric(tag) { A[0][0] = x2; @@ -1145,22 +1194,25 @@ gLevelsetGeneralQuadric::gLevelsetGeneralQuadric(const double *pt, const double translate(pt); } -gLevelsetGeneralQuadric::gLevelsetGeneralQuadric(const gLevelsetGeneralQuadric& lv) - : gLevelsetQuadric(lv){} +gLevelsetGeneralQuadric::gLevelsetGeneralQuadric( + const gLevelsetGeneralQuadric &lv) + : gLevelsetQuadric(lv) +{ +} gLevelsetTools::gLevelsetTools(const gLevelsetTools &lv) : gLevelset(lv) { - std::vector<gLevelset *> _children=lv.getChildren(); + std::vector<gLevelset *> _children = lv.getChildren(); unsigned siz = _children.size(); children.resize(siz); - for(unsigned i = 0; i < siz; ++i) - children[i] = _children[i]->clone(); + for(unsigned i = 0; i < siz; ++i) children[i] = _children[i]->clone(); } -gLevelsetYarn::gLevelsetYarn(int dim, int phys, double minA, double majA, int type, int tag) +gLevelsetYarn::gLevelsetYarn(int dim, int phys, double minA, double majA, + int type, int tag) : gLevelsetPrimitive(tag) //, minorAxis(minA), majorAxis(majA), typeLs(type) { - std::map<int, std::vector<GEntity*> > groups; + std::map<int, std::vector<GEntity *> > groups; GModel::current()->getPhysicalGroups(dim, groups); entities = groups[phys]; if(!entities.size()) @@ -1170,18 +1222,18 @@ gLevelsetYarn::gLevelsetYarn(int dim, int phys, double minA, double majA, int ty double gLevelsetYarn::operator()(double x, double y, double z) const { double dist = 0.0; - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { GEntity *g = entities[i]; - for(unsigned int j = 0; j < g->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < g->getNumMeshElements(); j++) { MElement *e = g->getMeshElement(j); MVertex *v1 = e->getVertex(0); MVertex *v2 = e->getVertex(1); SPoint3 p1(v1->x(), v1->y(), v1->z()); SPoint3 p2(v2->x(), v2->y(), v2->z()); /*if(e->getType() == TYPE_LIN){ - signedDistancesPointsEllipseLine(iDistances, iDistancesE, iIsInYarn, iClosePts, - pts, p1, p2, majorAxis, minorAxis, - majorAxis, minorAxis, typeLs); + signedDistancesPointsEllipseLine(iDistances, iDistancesE, iIsInYarn, + iClosePts, pts, p1, p2, majorAxis, minorAxis, majorAxis, minorAxis, + typeLs); } else if(e->getType() == TYPE_TRI){ MVertex *v3 = e->getVertex(2); @@ -1199,17 +1251,21 @@ gLevelsetImproved::gLevelsetImproved(const gLevelsetImproved &lv) Ls = lv.Ls->clone(); } -gLevelsetBox::gLevelsetBox(const double *pt, const double *dir1, const double *dir2, - const double *dir3, const double &a, const double &b, - const double &c, int tag) +gLevelsetBox::gLevelsetBox(const double *pt, const double *dir1, + const double *dir2, const double *dir3, + const double &a, const double &b, const double &c, + int tag) : gLevelsetImproved() { double dir1m[3] = {-dir1[0], -dir1[1], -dir1[2]}; double dir2m[3] = {-dir2[0], -dir2[1], -dir2[2]}; double dir3m[3] = {-dir3[0], -dir3[1], -dir3[2]}; - double n1[3]; norm(dir1, n1); - double n2[3]; norm(dir2, n2); - double n3[3]; norm(dir3, n3); + double n1[3]; + norm(dir1, n1); + double n2[3]; + norm(dir2, n2); + double n3[3]; + norm(dir3, n3); double pt2[3] = {pt[0] + a * n1[0] + b * n2[0] + c * n3[0], pt[1] + a * n1[1] + b * n2[1] + c * n3[1], pt[2] + a * n1[2] + b * n2[2] + c * n3[2]}; @@ -1223,18 +1279,20 @@ gLevelsetBox::gLevelsetBox(const double *pt, const double *dir1, const double *d Ls = new gLevelsetIntersection(p); } -gLevelsetBox::gLevelsetBox(const double *pt1, const double *pt2, const double *pt3, - const double *pt4, const double *pt5, const double *pt6, +gLevelsetBox::gLevelsetBox(const double *pt1, const double *pt2, + const double *pt3, const double *pt4, + const double *pt5, const double *pt6, const double *pt7, const double *pt8, int tag) : gLevelsetImproved() { if(!isPlanar(pt1, pt2, pt3, pt4) || !isPlanar(pt5, pt6, pt7, pt8) || !isPlanar(pt1, pt2, pt5, pt6) || !isPlanar(pt3, pt4, pt7, pt8) || !isPlanar(pt1, pt4, pt5, pt8) || !isPlanar(pt2, pt3, pt6, pt7)) - printf("WARNING : faces of the box are not planar! %d, %d, %d, %d, %d, %d\n", - isPlanar(pt1, pt2, pt3, pt4), isPlanar(pt5, pt6, pt7, pt8), - isPlanar(pt1, pt2, pt5, pt6), isPlanar(pt3, pt4, pt7, pt8), - isPlanar(pt1, pt4, pt5, pt8), isPlanar(pt2, pt3, pt6, pt7)); + printf( + "WARNING : faces of the box are not planar! %d, %d, %d, %d, %d, %d\n", + isPlanar(pt1, pt2, pt3, pt4), isPlanar(pt5, pt6, pt7, pt8), + isPlanar(pt1, pt2, pt5, pt6), isPlanar(pt3, pt4, pt7, pt8), + isPlanar(pt1, pt4, pt5, pt8), isPlanar(pt2, pt3, pt6, pt7)); std::vector<gLevelset *> p; p.push_back(new gLevelsetPlane(pt5, pt6, pt8, tag++)); p.push_back(new gLevelsetPlane(pt1, pt4, pt2, tag++)); @@ -1245,18 +1303,18 @@ gLevelsetBox::gLevelsetBox(const double *pt1, const double *pt2, const double *p Ls = new gLevelsetIntersection(p); } -gLevelsetBox::gLevelsetBox(const gLevelsetBox &lv) - : gLevelsetImproved(lv){} +gLevelsetBox::gLevelsetBox(const gLevelsetBox &lv) : gLevelsetImproved(lv) {} gLevelsetCylinder::gLevelsetCylinder(const std::vector<double> &pt, const std::vector<double> &dir, const double &R, const double &H, int tag) : gLevelsetImproved() { - double pt1[3]={pt[0], pt[1], pt[2]}; + double pt1[3] = {pt[0], pt[1], pt[2]}; double dir1[3] = {dir[0], dir[1], dir[2]}; double dir2[3] = {-dir1[0], -dir1[1], -dir1[2]}; - double n[3]; norm(dir1, n); + double n[3]; + norm(dir1, n); double pt2[3] = {pt1[0] + H * n[0], pt1[1] + H * n[1], pt1[2] + H * n[2]}; std::vector<gLevelset *> p; p.push_back(new gLevelsetGenCylinder(pt1, dir1, R, tag++)); @@ -1270,7 +1328,8 @@ gLevelsetCylinder::gLevelsetCylinder(const double *pt, const double *dir, : gLevelsetImproved() { double dir2[3] = {-dir[0], -dir[1], -dir[2]}; - double n[3]; norm(dir, n); + double n[3]; + norm(dir, n); double pt2[3] = {pt[0] + H * n[0], pt[1] + H * n[1], pt[2] + H * n[2]}; std::vector<gLevelset *> p; p.push_back(new gLevelsetGenCylinder(pt, dir, R, tag++)); @@ -1279,13 +1338,14 @@ gLevelsetCylinder::gLevelsetCylinder(const double *pt, const double *dir, Ls = new gLevelsetIntersection(p); } -gLevelsetCylinder::gLevelsetCylinder(const double * pt, const double *dir, +gLevelsetCylinder::gLevelsetCylinder(const double *pt, const double *dir, const double &R, const double &r, const double &H, int tag) : gLevelsetImproved() { double dir2[3] = {-dir[0], -dir[1], -dir[2]}; - double n[3]; norm(dir, n); + double n[3]; + norm(dir, n); double pt2[3] = {pt[0] + H * n[0], pt[1] + H * n[1], pt[2] + H * n[2]}; std::vector<gLevelset *> p1; p1.push_back(new gLevelsetGenCylinder(pt, dir, R, tag++)); @@ -1298,7 +1358,9 @@ gLevelsetCylinder::gLevelsetCylinder(const double * pt, const double *dir, } gLevelsetCylinder::gLevelsetCylinder(const gLevelsetCylinder &lv) - : gLevelsetImproved(lv){} + : gLevelsetImproved(lv) +{ +} gLevelsetConrod::gLevelsetConrod(const double *pt, const double *dir1, const double *dir2, const double &H1, @@ -1309,40 +1371,53 @@ gLevelsetConrod::gLevelsetConrod(const double *pt, const double *dir1, const double &E, int tag) : gLevelsetImproved() { - double n1[3]; norm(dir1, n1); - double n2[3]; norm(dir2, n2); + double n1[3]; + norm(dir1, n1); + double n2[3]; + norm(dir2, n2); double pt1[3] = {pt[0] - n2[0] * H1 / 2., pt[1] - n2[1] * H1 / 2., pt[2] - n2[2] * H1 / 2.}; double pt2[3] = {pt[0] + n1[0] * E - n2[0] * H2 / 2., pt[1] + n1[1] * E - n2[1] * H2 / 2., pt[2] + n1[2] * E - n2[2] * H2 / 2.}; - double dir3[3]; cross(pt1, pt2, pt, dir3); - double n3[3]; norm(dir3, n3); + double dir3[3]; + cross(pt1, pt2, pt, dir3); + double n3[3]; + norm(dir3, n3); double pt31[3] = {pt[0] - n2[0] * H3 / 2. + n3[0] * L1 / 2., pt[1] - n2[1] * H3 / 2. + n3[1] * L1 / 2., pt[2] - n2[2] * H3 / 2. + n3[2] * L1 / 2.}; - double pt32[3] = {pt31[0] - n3[0] * L1, pt31[1] - n3[1] * L1, pt31[2] - n3[2] * L1}; - double pt33[3] = {pt32[0] + n2[0] * H3, pt32[1] + n2[1] * H3, pt32[2] + n2[2] * H3}; - double pt34[3] = {pt33[0] + n3[0] * L1, pt33[1] + n3[1] * L1, pt33[2] + n3[2] * L1}; + double pt32[3] = {pt31[0] - n3[0] * L1, pt31[1] - n3[1] * L1, + pt31[2] - n3[2] * L1}; + double pt33[3] = {pt32[0] + n2[0] * H3, pt32[1] + n2[1] * H3, + pt32[2] + n2[2] * H3}; + double pt34[3] = {pt33[0] + n3[0] * L1, pt33[1] + n3[1] * L1, + pt33[2] + n3[2] * L1}; double pt35[3] = {pt[0] + n1[0] * E - n2[0] * H3 / 2. + n3[0] * L2 / 2., pt[1] + n1[1] * E - n2[1] * H3 / 2. + n3[1] * L2 / 2., pt[2] + n1[2] * E - n2[2] * H3 / 2. + n3[2] * L2 / 2.}; - double pt36[3] = {pt35[0] - n3[0] * L2, pt35[1] - n3[1] * L2, pt35[2] - n3[2] * L2}; - double pt37[3] = {pt36[0] + n2[0] * H3, pt36[1] + n2[1] * H3, pt36[2] + n2[2] * H3}; - double pt38[3] = {pt37[0] + n3[0] * L2, pt37[1] + n3[1] * L2, pt37[2] + n3[2] * L2}; + double pt36[3] = {pt35[0] - n3[0] * L2, pt35[1] - n3[1] * L2, + pt35[2] - n3[2] * L2}; + double pt37[3] = {pt36[0] + n2[0] * H3, pt36[1] + n2[1] * H3, + pt36[2] + n2[2] * H3}; + double pt38[3] = {pt37[0] + n3[0] * L2, pt37[1] + n3[1] * L2, + pt37[2] + n3[2] * L2}; std::vector<gLevelset *> p1; - p1.push_back(new gLevelsetBox(pt31, pt32, pt33, pt34, pt35, pt36, pt37, pt38, tag)); - p1.push_back(new gLevelsetCylinder(pt1, dir2, R1, H1, tag+6)); - p1.push_back(new gLevelsetCylinder(pt2, dir2, R2, H2, tag+9)); + p1.push_back( + new gLevelsetBox(pt31, pt32, pt33, pt34, pt35, pt36, pt37, pt38, tag)); + p1.push_back(new gLevelsetCylinder(pt1, dir2, R1, H1, tag + 6)); + p1.push_back(new gLevelsetCylinder(pt2, dir2, R2, H2, tag + 9)); std::vector<gLevelset *> p2; p2.push_back(new gLevelsetUnion(p1)); - p2.push_back(new gLevelsetGenCylinder(pt1, dir2, r1, tag+12)); - p2.push_back(new gLevelsetGenCylinder(pt2, dir2, r2, tag+13)); + p2.push_back(new gLevelsetGenCylinder(pt1, dir2, r1, tag + 12)); + p2.push_back(new gLevelsetGenCylinder(pt2, dir2, r2, tag + 13)); Ls = new gLevelsetCut(p2); } gLevelsetConrod::gLevelsetConrod(const gLevelsetConrod &lv) - : gLevelsetImproved(lv){} + : gLevelsetImproved(lv) +{ +} // Level-set for NACA0012 airfoil, last coeff. modified for zero-thickness // trailing edge cf. http://en.wikipedia.org/wiki/NACA_airfoil @@ -1353,49 +1428,57 @@ gLevelsetNACA00::gLevelsetNACA00(double x0, double y0, double c, double t) } void gLevelsetNACA00::getClosestBndPoint(double x, double y, double z, - double &xb, double &yb, double &curvRad, - bool &in) const + double &xb, double &yb, + double &curvRad, bool &in) const { static const int maxIter = 100; static const double tol = 1.e-10; - const double tolr = tol/_c; // Tolerance (scaled bu chord) - in = false; // Whether the point is inside the airfoil + const double tolr = tol / _c; // Tolerance (scaled bu chord) + in = false; // Whether the point is inside the airfoil // Point translated according to airfoil origin and symmetry - const double xt = x-_x0, yt = fabs(y-_y0); + const double xt = x - _x0, yt = fabs(y - _y0); - if(xt-_c > 1.21125*_t*yt) { + if(xt - _c > 1.21125 * _t * yt) { // Behind line normal to airfoil at trailing edge, closest boundary point is // trailing edge... - xb = _x0+_c; + xb = _x0 + _c; yb = _y0; curvRad = 0.; } else { // ...otherwise Newton-Raphson to find closest boundary point - const double fact = 5.*_t*_c; - double xtb = std::max(xt,tolr), ytb; + const double fact = 5. * _t * _c; + double xtb = std::max(xt, tolr), ytb; double dyb, ddyb; - for(int it=0; it<maxIter; it++) { - const double xbr = xtb/_c, sxbr = sqrt(xbr), xbr32 = xbr*sxbr, - xbr2 = xbr*xbr, xbr3 = xbr2*xbr, xbr4 = xbr2*xbr2; - ytb = fact*(0.2969*sxbr-0.1260*xbr-0.3516*xbr2+0.2843*xbr3-0.1036*xbr4); - dyb = fact*(0.14845/sxbr-0.4144*xbr3+0.8529*xbr2-0.7032*xbr-0.126)/_c; - ddyb = fact*(-0.074225/xbr32-1.2432*xbr2+1.7058*xbr-0.7032)/(_c*_c); - const double xx = xt-xtb, yy = yt-ytb; + for(int it = 0; it < maxIter; it++) { + const double xbr = xtb / _c, sxbr = sqrt(xbr), xbr32 = xbr * sxbr, + xbr2 = xbr * xbr, xbr3 = xbr2 * xbr, xbr4 = xbr2 * xbr2; + ytb = fact * (0.2969 * sxbr - 0.1260 * xbr - 0.3516 * xbr2 + + 0.2843 * xbr3 - 0.1036 * xbr4); + dyb = fact * + (0.14845 / sxbr - 0.4144 * xbr3 + 0.8529 * xbr2 - 0.7032 * xbr - + 0.126) / + _c; + ddyb = fact * + (-0.074225 / xbr32 - 1.2432 * xbr2 + 1.7058 * xbr - 0.7032) / + (_c * _c); + const double xx = xt - xtb, yy = yt - ytb; in = (xt > 0) && (yy < 0); - const double dDistSq = -2.*(xx+dyb*yy); - const double ddDistSq = 2.*(1.-ddyb*yy+dyb*dyb); - const double mIncr = dDistSq/ddDistSq; - if(fabs(mIncr) < tolr) break; - else xtb -= mIncr; + const double dDistSq = -2. * (xx + dyb * yy); + const double ddDistSq = 2. * (1. - ddyb * yy + dyb * dyb); + const double mIncr = dDistSq / ddDistSq; + if(fabs(mIncr) < tolr) + break; + else + xtb -= mIncr; if(xtb < tolr) xtb = tolr; - if (xtb > _c-tolr) xtb = _c-tolr; + if(xtb > _c - tolr) xtb = _c - tolr; } - xb = _x0+xtb; - yb = (y >= _y0) ? _y0+ytb : _y0-ytb; - const double norm = sqrt(1.+dyb*dyb); - curvRad = norm*norm*norm/fabs(ddyb); + xb = _x0 + xtb; + yb = (y >= _y0) ? _y0 + ytb : _y0 - ytb; + const double norm = sqrt(1. + dyb * dyb); + curvRad = norm * norm * norm / fabs(ddyb); } } @@ -1405,45 +1488,46 @@ double gLevelsetNACA00::operator()(double x, double y, double z) const bool in; getClosestBndPoint(x, y, z, xb, yb, curvRadb, in); - const double xx = x-xb, yy = y-yb, distSq = xx*xx+yy*yy; + const double xx = x - xb, yy = y - yb, distSq = xx * xx + yy * yy; return in ? -sqrt(distSq) : sqrt(distSq); } -void gLevelsetNACA00::gradient(double x, double y, double z, - double & dfdx, double & dfdy, double & dfdz) const +void gLevelsetNACA00::gradient(double x, double y, double z, double &dfdx, + double &dfdy, double &dfdz) const { double xb, yb, curvRadb; bool in; getClosestBndPoint(x, y, z, xb, yb, curvRadb, in); - const double xx = x-xb, yy = y-yb, distSq = xx*xx+yy*yy; + const double xx = x - xb, yy = y - yb, distSq = xx * xx + yy * yy; const double dist = in ? -sqrt(distSq) : sqrt(distSq); - dfdx = xx/dist; - dfdy = yy/dist; + dfdx = xx / dist; + dfdy = yy / dist; dfdz = 0.; } -void gLevelsetNACA00::hessian(double x, double y, double z, - double & dfdxx, double & dfdxy, double & dfdxz, - double & dfdyx, double & dfdyy, double & dfdyz, - double & dfdzx, double & dfdzy, double & dfdzz) const +void gLevelsetNACA00::hessian(double x, double y, double z, double &dfdxx, + double &dfdxy, double &dfdxz, double &dfdyx, + double &dfdyy, double &dfdyz, double &dfdzx, + double &dfdzy, double &dfdzz) const { double xb, yb, curvRadb; bool in; getClosestBndPoint(x, y, z, xb, yb, curvRadb, in); - const double xx = x-xb, yy = y-yb, distSq = xx*xx+yy*yy; + const double xx = x - xb, yy = y - yb, distSq = xx * xx + yy * yy; const double dist = in ? -sqrt(distSq) : sqrt(distSq); - const double curvRad = curvRadb+dist, fact = 1./(curvRad*curvRad*curvRad); + const double curvRad = curvRadb + dist, + fact = 1. / (curvRad * curvRad * curvRad); - dfdxx = yy*yy*fact; - dfdxy = -xx*yy*fact; + dfdxx = yy * yy * fact; + dfdxy = -xx * yy * fact; dfdxz = 0.; dfdyx = dfdxy; - dfdyy = xx*xx*fact; + dfdyy = xx * xx * fact; dfdyz = 0.; dfdzx = 0.; dfdzy = 0.; diff --git a/Geo/gmshLevelset.h b/Geo/gmshLevelset.h index b9c7d8ce0516750bd58c315dd48dbfc442ac6a5e..6246728361efae4f0fad0b31cd3be8f89399dfb9 100644 --- a/Geo/gmshLevelset.h +++ b/Geo/gmshLevelset.h @@ -32,36 +32,35 @@ class ANNkd_tree; #endif // PRIMITIVE LEVELSET -#define UNKNOWN 0 -#define SPHERE 1 -#define PLANE 2 -#define GENCYLINDER 3 -#define ELLIPS 4 -#define CONE 5 -#define QUADRIC 6 -#define BOX 7 -#define CYLINDER 8 -#define CONROD 9 -#define LSMESH 10 -#define LSPOINTS 11 // don't define 'POINTS' as it's reserved by win32 +#define UNKNOWN 0 +#define SPHERE 1 +#define PLANE 2 +#define GENCYLINDER 3 +#define ELLIPS 4 +#define CONE 5 +#define QUADRIC 6 +#define BOX 7 +#define CYLINDER 8 +#define CONROD 9 +#define LSMESH 10 +#define LSPOINTS 11 // don't define 'POINTS' as it's reserved by win32 // TOOLS -#define CUT 12 -#define UNION 13 -#define INTER 14 -#define CRACK 15 -#define DISK 16 +#define CUT 12 +#define UNION 13 +#define INTER 14 +#define CRACK 15 +#define DISK 16 class gLevelset; class gLevelsetLessThan { - public: +public: bool operator()(const gLevelset *l1, const gLevelset *l2) const; }; -class gLevelset : public simpleFunction<double> -{ - protected: +class gLevelset : public simpleFunction<double> { +protected: // negative values of the levelset are inside the domain. static const short insideDomain = -1; // unique levelset id, must be greater than 0 @@ -69,19 +68,22 @@ class gLevelset : public simpleFunction<double> // max tag in all levelsets static int maxTag_; // all levelsets - static std::set<gLevelset*, gLevelsetLessThan> all_; + static std::set<gLevelset *, gLevelsetLessThan> all_; + public: gLevelset(int tag = 0) { - if(tag <= 0) tag_ = gLevelset::maxTag_++; - else tag_ = tag; + if(tag <= 0) + tag_ = gLevelset::maxTag_++; + else + tag_ = tag; } gLevelset(const gLevelset &); - virtual ~gLevelset(){} + virtual ~gLevelset() {} static gLevelset *find(int tag); static void add(gLevelset *l); virtual gLevelset *clone() const { return 0; } - virtual double operator() (double x, double y, double z) const { return 0.; } + virtual double operator()(double x, double y, double z) const { return 0.; } bool isInsideDomain(const double &x, const double &y, const double &z) const { return this->operator()(x, y, z) * insideDomain > 0.; @@ -94,11 +96,11 @@ public: { return this->operator()(x, y, z) == 0.; } - virtual std::vector<gLevelset*> getChildren() const + virtual std::vector<gLevelset *> getChildren() const { - return std::vector<gLevelset*>(); + return std::vector<gLevelset *>(); } - virtual double choose (double d1, double d2) const { return 0.; } + virtual double choose(double d1, double d2) const { return 0.; } virtual int type() const { return 0; } virtual bool isPrimitive() const { return false; } void setTag(int t) { tag_ = t; } @@ -115,20 +117,20 @@ public: { printf("LS : "); switch(type()) { - case SPHERE : printf("SPHERE"); break; - case PLANE : printf("PLANE"); break; - case GENCYLINDER : printf("GENCYLINDER"); break; - case ELLIPS : printf("ELLIPS"); break; - case CONE : printf("CONE"); break; - case QUADRIC : printf("QUADRIC"); break; - case BOX : printf("BOX"); break; - case CYLINDER : printf("CYLINDER"); break; - case CONROD : printf("CONROD"); break; - case CUT : printf("CUT"); break; - case UNION : printf("UNION"); break; - case INTER : printf("INTER"); break; - case LSMESH: printf("LSMESH"); break; - case LSPOINTS: printf("LSPOINTS"); break; + case SPHERE: printf("SPHERE"); break; + case PLANE: printf("PLANE"); break; + case GENCYLINDER: printf("GENCYLINDER"); break; + case ELLIPS: printf("ELLIPS"); break; + case CONE: printf("CONE"); break; + case QUADRIC: printf("QUADRIC"); break; + case BOX: printf("BOX"); break; + case CYLINDER: printf("CYLINDER"); break; + case CONROD: printf("CONROD"); break; + case CUT: printf("CUT"); break; + case UNION: printf("UNION"); break; + case INTER: printf("INTER"); break; + case LSMESH: printf("LSMESH"); break; + case LSPOINTS: printf("LSPOINTS"); break; } printf(" Tag=%d\n", getTag()); } @@ -136,17 +138,19 @@ public: // PRIMITIVES -class gLevelsetPrimitive : public gLevelset -{ - public: +class gLevelsetPrimitive : public gLevelset { +public: gLevelsetPrimitive() : gLevelset() {} gLevelsetPrimitive(const gLevelsetPrimitive &lv) : gLevelset(lv) {} - gLevelsetPrimitive(int tag) : gLevelset(tag) { } + gLevelsetPrimitive(int tag) : gLevelset(tag) {} virtual double operator()(double x, double y, double z) const = 0; - std::vector<gLevelset *> getChildren() const { - std::vector<gLevelset *> p; return p; + std::vector<gLevelset *> getChildren() const + { + std::vector<gLevelset *> p; + return p; } - double choose(double d1, double d2) const { + double choose(double d1, double d2) const + { Msg::Error("Cannot use function \"choose\" with a primitive!\n"); return d1; } @@ -154,39 +158,41 @@ class gLevelsetPrimitive : public gLevelset virtual bool isPrimitive() const { return true; } }; -class gLevelsetSphere : public gLevelsetPrimitive -{ - protected: +class gLevelsetSphere : public gLevelsetPrimitive { +protected: double xc, yc, zc, r; - public: + +public: gLevelsetSphere(const double &x, const double &y, const double &z, const double &R, int tag = 0); virtual double operator()(double x, double y, double z) const { if(r >= 0.) return sqrt((xc - x) * (xc - x) + (yc - y) * (yc - y) + - (zc - z) * (zc - z)) - r; - return (- r - sqrt((xc - x) * (xc - x) + (yc - y) * (yc - y) + - (zc - z) * (zc - z))); - } - void gradient(double x, double y, double z, - double &dfdx, double &dfdy, double &dfdz) const; - void hessian(double x, double y, double z, - double &dfdxx, double &dfdxy, double &dfdxz, - double &dfdyx, double &dfdyy, double &dfdyz, + (zc - z) * (zc - z)) - + r; + return (-r - sqrt((xc - x) * (xc - x) + (yc - y) * (yc - y) + + (zc - z) * (zc - z))); + } + void gradient(double x, double y, double z, double &dfdx, double &dfdy, + double &dfdz) const; + void hessian(double x, double y, double z, double &dfdxx, double &dfdxy, + double &dfdxz, double &dfdyx, double &dfdyy, double &dfdyz, double &dfdzx, double &dfdzy, double &dfdzz) const; int type() const { return SPHERE; } }; -class gLevelsetPlane : public gLevelsetPrimitive -{ - protected: +class gLevelsetPlane : public gLevelsetPrimitive { +protected: double a, b, c, d; - public: + +public: // define the plane _a*x+_b*y+_c*z+_d, with outward normal (a,b,c) gLevelsetPlane(const double _a, const double _b, const double _c, const double _d, int tag = 0) - : gLevelsetPrimitive(tag), a(_a), b(_b), c(_c), d(_d) {} + : gLevelsetPrimitive(tag), a(_a), b(_b), c(_c), d(_d) + { + } // define the plane passing through the point pt and with outward normal norm gLevelsetPlane(const std::vector<double> &pt, const std::vector<double> &norm, int tag = 0); @@ -197,7 +203,7 @@ class gLevelsetPlane : public gLevelsetPrimitive int tag = 0); // copy constructor gLevelsetPlane(const gLevelsetPlane &lv); - virtual gLevelset * clone() const { return new gLevelsetPlane(*this); } + virtual gLevelset *clone() const { return new gLevelsetPlane(*this); } // return negative value inward and positive value outward virtual double operator()(double x, double y, double z) const { @@ -206,9 +212,8 @@ class gLevelsetPlane : public gLevelsetPrimitive int type() const { return PLANE; } }; -class gLevelsetPoints : public gLevelsetPrimitive -{ - protected: +class gLevelsetPoints : public gLevelsetPrimitive { +protected: fullMatrix<double> points; fullMatrix<double> surf; fullMatrix<double> matAInv; @@ -217,13 +222,10 @@ class gLevelsetPoints : public gLevelsetPrimitive fullMatrix<double> generateRbfMat(int p, int index, const fullMatrix<double> &nodes1, const fullMatrix<double> &nodes2) const; - void RbfOp(int p, int index, - const fullMatrix<double> &cntrs, - const fullMatrix<double> &nodes, - fullMatrix<double> &D, + void RbfOp(int p, int index, const fullMatrix<double> &cntrs, + const fullMatrix<double> &nodes, fullMatrix<double> &D, bool isLocal = false) const; - void evalRbfDer(int p, int index, - const fullMatrix<double> &cntrs, + void evalRbfDer(int p, int index, const fullMatrix<double> &cntrs, const fullMatrix<double> &nodes, const fullMatrix<double> &fValues, fullMatrix<double> &fApprox, bool isLocal = false) const; @@ -231,21 +233,20 @@ class gLevelsetPoints : public gLevelsetPrimitive fullMatrix<double> &level_set_nodes, fullMatrix<double> &level_set_funvals); - public: +public: // define the data points gLevelsetPoints(fullMatrix<double> &_centers, int tag = 0); // copy constructor gLevelsetPoints(const gLevelsetPoints &lv); - virtual gLevelset * clone() const { return new gLevelsetPoints(*this); } + virtual gLevelset *clone() const { return new gLevelsetPoints(*this); } // return negative value inward and positive value outward virtual double operator()(double x, double y, double z) const; - void computeLS(std::vector<MVertex*> &vert); + void computeLS(std::vector<MVertex *> &vert); int type() const { return LSPOINTS; } }; -class gLevelsetQuadric : public gLevelsetPrimitive -{ - protected: +class gLevelsetQuadric : public gLevelsetPrimitive { +protected: double A[3][3], B[3], C; void translate(const double transl[3]); void rotate(const double rotate[3][3]); @@ -255,7 +256,8 @@ class gLevelsetQuadric : public gLevelsetPrimitive void Ax(const double x[3], double res[3], double fact = 1.0); void xAx(const double x[3], double &res, double fact = 1.0); void init(); - public: + +public: gLevelsetQuadric(int tag = 0) : gLevelsetPrimitive(tag) { init(); } gLevelsetQuadric(const gLevelsetQuadric &); virtual ~gLevelsetQuadric() {} @@ -263,53 +265,53 @@ class gLevelsetQuadric : public gLevelsetPrimitive virtual int type() const = 0; }; -class gLevelsetGenCylinder : public gLevelsetQuadric -{ - public: +class gLevelsetGenCylinder : public gLevelsetQuadric { +public: gLevelsetGenCylinder(const double *pt, const double *dir, const double &R, int tag = 0); gLevelsetGenCylinder(const gLevelsetGenCylinder &); - virtual gLevelset * clone() const { return new gLevelsetGenCylinder(*this); } + virtual gLevelset *clone() const { return new gLevelsetGenCylinder(*this); } int type() const { return GENCYLINDER; } }; -class gLevelsetEllipsoid : public gLevelsetQuadric -{ - public: +class gLevelsetEllipsoid : public gLevelsetQuadric { +public: gLevelsetEllipsoid(const double *pt, const double *dir, const double &a, const double &b, const double &c, int tag = 0); gLevelsetEllipsoid(const gLevelsetEllipsoid &); - virtual gLevelset * clone() const { return new gLevelsetEllipsoid(*this); } + virtual gLevelset *clone() const { return new gLevelsetEllipsoid(*this); } int type() const { return ELLIPS; } }; -class gLevelsetCone : public gLevelsetQuadric -{ - public: - gLevelsetCone(const double *pt, const double *dir, const double &angle, int tag = 0); +class gLevelsetCone : public gLevelsetQuadric { +public: + gLevelsetCone(const double *pt, const double *dir, const double &angle, + int tag = 0); gLevelsetCone(const gLevelsetCone &); - virtual gLevelset * clone() const { return new gLevelsetCone(*this); } + virtual gLevelset *clone() const { return new gLevelsetCone(*this); } int type() const { return CONE; } }; -class gLevelsetGeneralQuadric : public gLevelsetQuadric -{ - public: - gLevelsetGeneralQuadric(const double *pt, const double *dir, - const double &x2, const double &y2, const double &z2, - const double &z, const double &c, int tag = 0); +class gLevelsetGeneralQuadric : public gLevelsetQuadric { +public: + gLevelsetGeneralQuadric(const double *pt, const double *dir, const double &x2, + const double &y2, const double &z2, const double &z, + const double &c, int tag = 0); gLevelsetGeneralQuadric(const gLevelsetGeneralQuadric &); - virtual gLevelset * clone() const { return new gLevelsetGeneralQuadric(*this); } + virtual gLevelset *clone() const + { + return new gLevelsetGeneralQuadric(*this); + } int type() const { return QUADRIC; } }; -class gLevelsetPopcorn: public gLevelsetPrimitive -{ +class gLevelsetPopcorn : public gLevelsetPrimitive { double A; double sigma; double r0; double xc, yc, zc; - public: + +public: gLevelsetPopcorn(double xc, double yc, double zc, double r0, double A, double sigma, int tag = 0); ~gLevelsetPopcorn() {} @@ -321,12 +323,12 @@ class gLevelsetPopcorn: public gLevelsetPrimitive // the "shamrock-like" iso-zero from Dobrzynski and Frey, "Anisotropic delaunay // mesh adaptation for unsteady simulations", 17th International Meshing // Rountable (2008)(177–194) -class gLevelsetShamrock: public gLevelsetPrimitive -{ +class gLevelsetShamrock : public gLevelsetPrimitive { double xmid, a, b; int c; std::vector<double> iso_x, iso_y; - public: + +public: gLevelsetShamrock(double xmid, double ymid, double zmid, double a, double b, int c = 3, int tag = 0); ~gLevelsetShamrock() {} @@ -334,41 +336,42 @@ class gLevelsetShamrock: public gLevelsetPrimitive int type() const { return UNKNOWN; } }; -class gLevelsetMathEval: public gLevelsetPrimitive -{ +class gLevelsetMathEval : public gLevelsetPrimitive { mathEvaluator *_expr; - public: - gLevelsetMathEval(const std::string &f, int tag = 0); - ~gLevelsetMathEval() - { - if(_expr) delete _expr; } + +public: + gLevelsetMathEval(const std::string &f, int tag = 0); + ~gLevelsetMathEval() + { + if(_expr) delete _expr; + } double operator()(double x, double y, double z) const; int type() const { return UNKNOWN; } }; -class gLevelsetMathEvalAll: public gLevelsetPrimitive -{ +class gLevelsetMathEvalAll : public gLevelsetPrimitive { mathEvaluator *_expr; - public: + +public: gLevelsetMathEvalAll(std::vector<std::string> f, int tag = 0); - ~gLevelsetMathEvalAll() { if(_expr) delete _expr; } + ~gLevelsetMathEvalAll() + { + if(_expr) delete _expr; + } double operator()(double x, double y, double z) const; - void gradient(double x, double y, double z, - double &dfdx, double &dfdy, double &dfdz) const; - void hessian(double x, double y, double z, - double &dfdxx, double &dfdxy, double &dfdxz, - double &dfdyx, double &dfdyy, double &dfdyz, + void gradient(double x, double y, double z, double &dfdx, double &dfdy, + double &dfdz) const; + void hessian(double x, double y, double z, double &dfdxx, double &dfdxy, + double &dfdxz, double &dfdyx, double &dfdyy, double &dfdyz, double &dfdzx, double &dfdzy, double &dfdzz) const; int type() const { return UNKNOWN; } }; -class gLevelsetSimpleFunction: public gLevelsetPrimitive -{ +class gLevelsetSimpleFunction : public gLevelsetPrimitive { simpleFunction<double> *_f; - public: - gLevelsetSimpleFunction(simpleFunction<double> *f, int tag = 0) { - _f = f; - } + +public: + gLevelsetSimpleFunction(simpleFunction<double> *f, int tag = 0) { _f = f; } ~gLevelsetSimpleFunction() {} double operator()(double x, double y, double z) const { @@ -378,62 +381,66 @@ class gLevelsetSimpleFunction: public gLevelsetPrimitive }; #if defined(HAVE_ANN) -class gLevelsetDistMesh: public gLevelsetPrimitive -{ +class gLevelsetDistMesh : public gLevelsetPrimitive { const int _nbClose; - std::vector<GEntity*> _entities; - std::vector<MVertex*> _vertices; - std::multimap<MVertex*, MElement*> _v2e; + std::vector<GEntity *> _entities; + std::vector<MVertex *> _vertices; + std::multimap<MVertex *, MElement *> _v2e; ANNkd_tree *_kdtree; - public : - gLevelsetDistMesh(GModel *gm, const std::string &physical, int nbClose = 5, - int tag = 0); - double operator()(double x, double y, double z) const; - ~gLevelsetDistMesh(); - int type() const { return LSMESH; } + +public: + gLevelsetDistMesh(GModel *gm, const std::string &physical, int nbClose = 5, + int tag = 0); + double operator()(double x, double y, double z) const; + ~gLevelsetDistMesh(); + int type() const { return LSMESH; } }; #endif #if defined(HAVE_POST) -class gLevelsetPostView : public gLevelsetPrimitive -{ +class gLevelsetPostView : public gLevelsetPrimitive { int _viewIndex; OctreePost *_octree; - public: + +public: gLevelsetPostView(int index, int tag = 0); - ~gLevelsetPostView() { if(_octree) delete _octree; } + ~gLevelsetPostView() + { + if(_octree) delete _octree; + } double operator()(double x, double y, double z) const; int type() const { return UNKNOWN; } }; #endif -class gLevelsetNACA00 : public gLevelsetPrimitive -{ +class gLevelsetNACA00 : public gLevelsetPrimitive { double _x0, _y0, _c, _t; - public: + +public: gLevelsetNACA00(double x0, double y0, double c, double t); ~gLevelsetNACA00() {} double operator()(double x, double y, double z) const; - void gradient(double x, double y, double z, - double &dfdx, double &dfdy, double &dfdz) const; - void hessian(double x, double y, double z, - double &dfdxx, double &dfdxy, double &dfdxz, - double &dfdyx, double &dfdyy, double &dfdyz, + void gradient(double x, double y, double z, double &dfdx, double &dfdy, + double &dfdz) const; + void hessian(double x, double y, double z, double &dfdxx, double &dfdxy, + double &dfdxz, double &dfdyx, double &dfdyy, double &dfdyz, double &dfdzx, double &dfdzy, double &dfdzz) const; int type() const { return UNKNOWN; } - private: + +private: void getClosestBndPoint(const double x, const double y, const double z, double &xb, double &yb, double &curvRad, bool &in) const; }; -class gLevelsetYarn : public gLevelsetPrimitive -{ - //double minorAxis, majorAxis; - //int typeLs; - std::vector<GEntity*> entities; - public: - gLevelsetYarn(int dim, int phys, double minA, double majA, int type, int tag = 0); +class gLevelsetYarn : public gLevelsetPrimitive { + // double minorAxis, majorAxis; + // int typeLs; + std::vector<GEntity *> entities; + +public: + gLevelsetYarn(int dim, int phys, double minA, double majA, int type, + int tag = 0); ~gLevelsetYarn() {} double operator()(double x, double y, double z) const; int type() const { return UNKNOWN; } @@ -441,30 +448,30 @@ class gLevelsetYarn : public gLevelsetPrimitive // TOOLS -class gLevelsetTools : public gLevelset -{ +class gLevelsetTools : public gLevelset { protected: std::vector<gLevelset *> children; - bool _delChildren;//flag to delete only if called from gmsh Parser - public: + bool _delChildren; // flag to delete only if called from gmsh Parser +public: gLevelsetTools(int tag = 0) : gLevelset(tag) {} - gLevelsetTools(const std::vector<gLevelset *> &p, bool delC = false, int tag = 0) + gLevelsetTools(const std::vector<gLevelset *> &p, bool delC = false, + int tag = 0) : gLevelset(tag) { - children = p; _delChildren = delC; + children = p; + _delChildren = delC; } gLevelsetTools(const gLevelsetTools &); virtual ~gLevelsetTools() { - if(_delChildren){ - for(int i = 0; i < (int)children.size(); i++) - delete children[i]; + if(_delChildren) { + for(int i = 0; i < (int)children.size(); i++) delete children[i]; } } double operator()(double x, double y, double z) const { double d = (*children[0])(x, y, z); - for(int i = 1; i < (int)children.size(); i++){ + for(int i = 1; i < (int)children.size(); i++) { double dt = (*children[i])(x, y, z); d = choose(d, dt); } @@ -494,11 +501,11 @@ protected: } }; -class gLevelsetReverse : public gLevelset -{ - protected: +class gLevelsetReverse : public gLevelset { +protected: gLevelset *ls; - public: + +public: gLevelsetReverse(gLevelset *p, int tag = 0) : gLevelset(tag), ls(p) {} double operator()(double x, double y, double z) const { @@ -506,43 +513,42 @@ class gLevelsetReverse : public gLevelset } std::vector<gLevelset *> getChildren() const { return ls->getChildren(); } virtual bool isPrimitive() const { return ls->isPrimitive(); } - virtual double choose(double d1, double d2) const { return -ls->choose(d1, d2); } + virtual double choose(double d1, double d2) const + { + return -ls->choose(d1, d2); + } virtual int type() const { return ls->type(); } int getTag() const { return ls->getTag(); } }; // This levelset takes the first levelset in the list as the object and the // others as tools that cut it -class gLevelsetCut : public gLevelsetTools -{ - public: - gLevelsetCut(const std::vector<gLevelset *> &p, bool delC = false, - int tag = 0) - : gLevelsetTools(p, delC, tag) - { - } - double choose(double d1, double d2) const - { - return (d1 > -d2) ? d1 : -d2; // greater of d1 and -d2 +class gLevelsetCut : public gLevelsetTools { +public: + gLevelsetCut(const std::vector<gLevelset *> &p, bool delC = false, + int tag = 0) + : gLevelsetTools(p, delC, tag) + { + } + double choose(double d1, double d2) const + { + return (d1 > -d2) ? d1 : -d2; // greater of d1 and -d2 } gLevelsetCut(const gLevelsetCut &lv) : gLevelsetTools(lv) {} - virtual gLevelset * clone() const { return new gLevelsetCut(*this); } + virtual gLevelset *clone() const { return new gLevelsetCut(*this); } int type2() const { return CUT; } }; // This levelset takes the minimum -class gLevelsetUnion : public gLevelsetTools -{ - public: - gLevelsetUnion(const std::vector<gLevelset *> &p, bool delC = false, - int tag = 0) - : gLevelsetTools(p, delC, tag) - { - } - gLevelsetUnion(const gLevelsetUnion &lv) - : gLevelsetTools(lv) - {} - virtual gLevelset * clone() const{ return new gLevelsetUnion(*this); } +class gLevelsetUnion : public gLevelsetTools { +public: + gLevelsetUnion(const std::vector<gLevelset *> &p, bool delC = false, + int tag = 0) + : gLevelsetTools(p, delC, tag) + { + } + gLevelsetUnion(const gLevelsetUnion &lv) : gLevelsetTools(lv) {} + virtual gLevelset *clone() const { return new gLevelsetUnion(*this); } double choose(double d1, double d2) const { @@ -552,34 +558,30 @@ class gLevelsetUnion : public gLevelsetTools }; // This levelset takes the maximum -class gLevelsetIntersection : public gLevelsetTools -{ - public: - gLevelsetIntersection(const std::vector<gLevelset *> &p, bool delC = false, - int tag = 0) - : gLevelsetTools(p, delC, tag) - { - } - gLevelsetIntersection(const gLevelsetIntersection &lv) - : gLevelsetTools(lv) - {} +class gLevelsetIntersection : public gLevelsetTools { +public: + gLevelsetIntersection(const std::vector<gLevelset *> &p, bool delC = false, + int tag = 0) + : gLevelsetTools(p, delC, tag) + { + } + gLevelsetIntersection(const gLevelsetIntersection &lv) : gLevelsetTools(lv) {} virtual gLevelset *clone() const { return new gLevelsetIntersection(*this); } - double choose(double d1, double d2) const { + double choose(double d1, double d2) const + { return (d1 > d2) ? d1 : d2; // greater of d1 and d2 } int type2() const { return INTER; } }; // Crack defined by a normal and a tangent levelset -class gLevelsetCrack : public gLevelsetTools -{ - public: +class gLevelsetCrack : public gLevelsetTools { +public: gLevelsetCrack(std::vector<gLevelset *> p, bool delC = false, int tag = 0) : gLevelsetTools(tag) { - if(p.size() != 2) - printf("Error : gLevelsetCrack needs 2 levelsets\n"); + if(p.size() != 2) printf("Error : gLevelsetCrack needs 2 levelsets\n"); children.push_back(p[0]); children.push_back(new gLevelsetReverse(p[0])); if(p[1]) children.push_back(p[1]); @@ -592,26 +594,27 @@ class gLevelsetCrack : public gLevelsetTools int type2() const { return CRACK; } }; - // IMPROVED LEVELSET -class gLevelsetImproved : public gLevelset -{ - protected: +class gLevelsetImproved : public gLevelset { +protected: gLevelset *Ls; - public: - gLevelsetImproved(int tag = 0) : gLevelset(tag) { } + +public: + gLevelsetImproved(int tag = 0) : gLevelset(tag) {} gLevelsetImproved(const gLevelsetImproved &lv); - double operator()(double x, double y, double z) const { return (*Ls)(x, y, z); } + double operator()(double x, double y, double z) const + { + return (*Ls)(x, y, z); + } std::vector<gLevelset *> getChildren() const { return Ls->getChildren(); } double choose(double d1, double d2) const { return Ls->choose(d1, d2); } virtual int type() const = 0; virtual bool isPrimitive() const { return Ls->isPrimitive(); } }; -class gLevelsetBox : public gLevelsetImproved -{ - public: +class gLevelsetBox : public gLevelsetImproved { +public: // create a box with parallel faces : // pt is a corner of the box, // dir1 is the direction of the first edge starting from pt, @@ -641,13 +644,12 @@ class gLevelsetBox : public gLevelsetImproved const double *pt4, const double *pt5, const double *pt6, const double *pt7, const double *pt8, int tag = 0); gLevelsetBox(const gLevelsetBox &); - virtual gLevelset * clone() const { return new gLevelsetBox(*this); } + virtual gLevelset *clone() const { return new gLevelsetBox(*this); } int type() const { return BOX; } }; -class gLevelsetCylinder : public gLevelsetImproved -{ - public: +class gLevelsetCylinder : public gLevelsetImproved { +public: // create a cylinder : pt is the point in the middle of the cylinder base, // dir is the direction of the cylinder axis, // R is the outer radius of the cylinder, @@ -672,13 +674,12 @@ class gLevelsetCylinder : public gLevelsetImproved gLevelsetCylinder(const double *pt, const double *dir, const double &R, const double &r, const double &H, int tag = 0); gLevelsetCylinder(const gLevelsetCylinder &); - virtual gLevelset * clone() const { return new gLevelsetCylinder(*this); } + virtual gLevelset *clone() const { return new gLevelsetCylinder(*this); } int type() const { return CYLINDER; } }; -class gLevelsetConrod : public gLevelsetImproved -{ - public: +class gLevelsetConrod : public gLevelsetImproved { +public: // create a connecting rod : // pt is the point in the middle of the first bore, // dir1 is the direction of the rod, @@ -713,7 +714,7 @@ class gLevelsetConrod : public gLevelsetImproved const double &r2, const double &L1, const double &L2, const double &E, int tag = 0); gLevelsetConrod(const gLevelsetConrod &); - virtual gLevelset * clone() const { return new gLevelsetConrod(*this); } + virtual gLevelset *clone() const { return new gLevelsetConrod(*this); } int type() const { return CONROD; } }; diff --git a/Geo/gmshRegion.cpp b/Geo/gmshRegion.cpp index d1fe8d00a5383d93e4dfcc0c0f8fef8ccb8e0dc1..9195b1cf96bb2b1fef5eac2bff7bb12d9710edfa 100644 --- a/Geo/gmshRegion.cpp +++ b/Geo/gmshRegion.cpp @@ -9,8 +9,7 @@ #include "Geo.h" #include "GmshMessage.h" -gmshRegion::gmshRegion(GModel *m, ::Volume *volume) - : GRegion(m, volume->Num) +gmshRegion::gmshRegion(GModel *m, ::Volume *volume) : GRegion(m, volume->Num) { resetNativePtr(volume); resetMeshAttributes(); @@ -21,13 +20,13 @@ void gmshRegion::resetNativePtr(::Volume *volume) v = volume; l_faces.clear(); l_dirs.clear(); - for(int i = 0; i < List_Nbr(v->Surfaces); i++){ + for(int i = 0; i < List_Nbr(v->Surfaces); i++) { Surface *s; List_Read(v->Surfaces, i, &s); int ori; List_Read(v->SurfacesOrientations, i, &ori); GFace *f = model()->getFaceByTag(abs(s->Num)); - if(f){ + if(f) { l_faces.push_back(f); l_dirs.push_back(ori); f->addRegion(this); @@ -35,11 +34,11 @@ void gmshRegion::resetNativePtr(::Volume *volume) else Msg::Error("Unknown surface %d", s->Num); } - for(int i = 0; i < List_Nbr(v->SurfacesByTag); i++){ + for(int i = 0; i < List_Nbr(v->SurfacesByTag); i++) { int is; List_Read(v->SurfacesByTag, i, &is); GFace *f = model()->getFaceByTag(abs(is)); - if(f){ + if(f) { l_faces.push_back(f); l_dirs.push_back(gmsh_sign(is)); f->addRegion(this); @@ -55,9 +54,9 @@ void gmshRegion::resetMeshAttributes() meshAttributes.method = v->Method; meshAttributes.QuadTri = v->QuadTri; meshAttributes.extrude = v->Extrude; - if(meshAttributes.method == MESH_TRANSFINITE){ + if(meshAttributes.method == MESH_TRANSFINITE) { meshAttributes.corners.clear(); - for(int i = 0; i < List_Nbr(v->TrsfPoints); i++){ + for(int i = 0; i < List_Nbr(v->TrsfPoints); i++) { Vertex *corn; List_Read(v->TrsfPoints, i, &corn); GVertex *gv = model()->getVertexByTag(corn->Num); @@ -71,8 +70,8 @@ void gmshRegion::resetMeshAttributes() GEntity::GeomType gmshRegion::geomType() const { - switch (v->Typ){ - case MSH_VOLUME_DISCRETE : return DiscreteVolume; - default : return Volume; + switch(v->Typ) { + case MSH_VOLUME_DISCRETE: return DiscreteVolume; + default: return Volume; } } diff --git a/Geo/gmshRegion.h b/Geo/gmshRegion.h index 35b1125f17bad695185c19933f84fe021b76efae..50eee760934c225a1df006e7ea1dce0664f2d3c6 100644 --- a/Geo/gmshRegion.h +++ b/Geo/gmshRegion.h @@ -11,9 +11,10 @@ class Volume; class gmshRegion : public GRegion { - protected: +protected: ::Volume *v; - public: + +public: gmshRegion(GModel *m, ::Volume *_v); virtual ~gmshRegion() {} virtual GeomType geomType() const; diff --git a/Geo/gmshSurface.cpp b/Geo/gmshSurface.cpp index 1f3c66d7af04d895acc22b9d750220a6bd0e2cfb..7bbe84da69dae08b6ac61e3be33fdbe6a354a4ee 100644 --- a/Geo/gmshSurface.cpp +++ b/Geo/gmshSurface.cpp @@ -8,11 +8,12 @@ #include "gmshSurface.h" #include "mathEvaluator.h" -std::map<int,gmshSurface*> gmshSurface::allGmshSurfaces; +std::map<int, gmshSurface *> gmshSurface::allGmshSurfaces; SPoint2 gmshSurface::parFromPoint(double x, double y, double z) { - Msg::Error("Parametric coordinate computation not implemented for this type of surface"); + Msg::Error("Parametric coordinate computation not implemented for this type " + "of surface"); return SPoint2(); } @@ -34,12 +35,13 @@ double gmshSurface::getMetricEigenvalue(const SPoint2 &) return 0; } -gmshSurface *gmshSphere::NewSphere(int iSphere, double x, double y, double z, double r) +gmshSurface *gmshSphere::NewSphere(int iSphere, double x, double y, double z, + double r) { gmshSphere *sph = new gmshSphere(x, y, z, r); - if(allGmshSurfaces.find(iSphere) != allGmshSurfaces.end()){ - Msg::Error("gmshSurface %d already exists",iSphere); + if(allGmshSurfaces.find(iSphere) != allGmshSurfaces.end()) { + Msg::Error("gmshSurface %d already exists", iSphere); } allGmshSurfaces[iSphere] = sph; @@ -48,9 +50,9 @@ gmshSurface *gmshSphere::NewSphere(int iSphere, double x, double y, double z, do gmshSurface *gmshSurface::getSurface(int iSurface) { - std::map<int, gmshSurface*>::iterator it = allGmshSurfaces.find(iSurface); - if(it == allGmshSurfaces.end()){ - Msg::Error("gmshSurface %d does not exist",iSurface); + std::map<int, gmshSurface *>::iterator it = allGmshSurfaces.find(iSurface); + if(it == allGmshSurfaces.end()) { + Msg::Error("gmshSurface %d does not exist", iSurface); return 0; } return it->second; @@ -58,19 +60,19 @@ gmshSurface *gmshSurface::getSurface(int iSurface) SPoint3 gmshSphere::point(double par1, double par2) const { - par2 += M_PI*.5; + par2 += M_PI * .5; const double x = xc + r * sin(par2) * cos(par1); const double y = yc + r * sin(par2) * sin(par1); const double z = zc - r * cos(par2); return SPoint3(x, y, z); } -gmshSurface *gmshPolarSphere::NewPolarSphere(int iSphere, double x, double y, double z, - double r) +gmshSurface *gmshPolarSphere::NewPolarSphere(int iSphere, double x, double y, + double z, double r) { gmshPolarSphere *sph = new gmshPolarSphere(x, y, z, r); - if(allGmshSurfaces.find(iSphere) != allGmshSurfaces.end()){ + if(allGmshSurfaces.find(iSphere) != allGmshSurfaces.end()) { Msg::Error("gmshSurface %d already exists", iSphere); } @@ -78,17 +80,19 @@ gmshSurface *gmshPolarSphere::NewPolarSphere(int iSphere, double x, double y, do return sph; } -gmshPolarSphere::gmshPolarSphere(double x, double y, double z, double _r) : r(_r), o(x,y,z) +gmshPolarSphere::gmshPolarSphere(double x, double y, double z, double _r) + : r(_r), o(x, y, z) { } SPoint3 gmshPolarSphere::point(double u, double v) const { - //stereographic projection from the south pole, origin of the axis - //at the center of the sphere - //u=-x/(r+z) v=-y/(r+z) - double rp2 = u*u+v*v; - SPoint3 p(-2*r*u/(1+rp2),-2*r*v/(1+rp2),r*(1-rp2)/(1+rp2)); + // stereographic projection from the south pole, origin of the axis + // at the center of the sphere + // u=-x/(r+z) v=-y/(r+z) + double rp2 = u * u + v * v; + SPoint3 p(-2 * r * u / (1 + rp2), -2 * r * v / (1 + rp2), + r * (1 - rp2) / (1 + rp2)); p += o; return p; } @@ -98,8 +102,8 @@ gmshSurface *gmshParametricSurface::NewParametricSurface(int iSurf, char *valX, { gmshParametricSurface *sph = new gmshParametricSurface(valX, valY, valZ); - if(allGmshSurfaces.find(iSurf) != allGmshSurfaces.end()){ - Msg::Error("gmshSurface %d already exists",iSurf); + if(allGmshSurfaces.find(iSurf) != allGmshSurfaces.end()) { + Msg::Error("gmshSurface %d already exists", iSurf); } allGmshSurfaces[iSurf] = sph; return sph; @@ -114,7 +118,7 @@ gmshParametricSurface::gmshParametricSurface(char *valX, char *valY, char *valZ) variables[0] = "u"; variables[1] = "v"; _f = new mathEvaluator(expressions, variables); - if(expressions.empty()){ + if(expressions.empty()) { delete _f; _f = 0; } @@ -127,7 +131,7 @@ gmshParametricSurface::~gmshParametricSurface() SPoint3 gmshParametricSurface::point(double par1, double par2) const { - if(_f){ + if(_f) { std::vector<double> values(2), res(3); values[0] = par1; values[1] = par2; diff --git a/Geo/gmshSurface.h b/Geo/gmshSurface.h index fc1cc0213e7b498b071e9798bbc5055a7dcd7e3e..39424923cc8eb383be7996f34a7ba36b53c23d9e 100644 --- a/Geo/gmshSurface.h +++ b/Geo/gmshSurface.h @@ -16,24 +16,23 @@ #include "SBoundingBox3d.h" #include "Numeric.h" -class gmshSurface -{ - protected: - static std::map<int, gmshSurface*> allGmshSurfaces; - public: - //there are points define in this surface parameterization +class gmshSurface { +protected: + static std::map<int, gmshSurface *> allGmshSurfaces; + +public: + // there are points define in this surface parameterization bool vertex_defined_on_surface; - virtual ~gmshSurface(){} - static void reset() + virtual ~gmshSurface() {} + static void reset() { - std::map<int, gmshSurface*>::iterator it = allGmshSurfaces.begin(); - for (; it != allGmshSurfaces.end(); ++it){ - if(!it->second->vertex_defined_on_surface) - delete it->second; + std::map<int, gmshSurface *>::iterator it = allGmshSurfaces.begin(); + for(; it != allGmshSurfaces.end(); ++it) { + if(!it->second->vertex_defined_on_surface) delete it->second; } allGmshSurfaces.clear(); }; - static gmshSurface* getSurface(int tag); + static gmshSurface *getSurface(int tag); virtual Range<double> parBounds(int i) const = 0; /// Underlying geometric representation of this entity. enum gmshSurfaceType { @@ -53,31 +52,38 @@ class gmshSurface // Return the normal to the face at the given parameter location. virtual SVector3 normal(const SPoint2 ¶m) const; // Return the first derivate of the face at the parameter location. - virtual Pair<SVector3,SVector3> firstDer(const SPoint2 ¶m); + virtual Pair<SVector3, SVector3> firstDer(const SPoint2 ¶m); virtual double getMetricEigenvalue(const SPoint2 &); }; -class gmshSphere : public gmshSurface -{ - private: +class gmshSphere : public gmshSurface { +private: double xc, yc, zc, r; - gmshSphere(double _x, double _y, double _z, double _r) : xc(_x), yc(_y), zc(_z), r(_r){} - public: - static gmshSurface *NewSphere(int _iSphere, double _x, double _y, double _z, double _r); - virtual Range<double> parBounds(int i) const - { - if(i == 0) + gmshSphere(double _x, double _y, double _z, double _r) + : xc(_x), yc(_y), zc(_z), r(_r) + { + } + +public: + static gmshSurface *NewSphere(int _iSphere, double _x, double _y, double _z, + double _r); + virtual Range<double> parBounds(int i) const + { + if(i == 0) return Range<double>(0., 2 * M_PI); else return Range<double>(0., M_PI); } - virtual gmshSurface::gmshSurfaceType geomType() const { return gmshSurface::Sphere; } + virtual gmshSurface::gmshSurfaceType geomType() const + { + return gmshSurface::Sphere; + } using gmshSurface::point; virtual SPoint3 point(double par1, double par2) const; virtual SVector3 normal(const SPoint2 ¶m) const { - SPoint3 p1 = gmshSurface::point(param); - SPoint3 p2(xc, yc, zc); + SPoint3 p1 = gmshSurface::point(param); + SPoint3 p2(xc, yc, zc); SVector3 n(p1, p2); n.normalize(); return n; @@ -85,52 +91,56 @@ class gmshSphere : public gmshSurface }; #include "stdio.h" -class gmshPolarSphere : public gmshSurface -{ - private: +class gmshPolarSphere : public gmshSurface { +private: double r; SPoint3 o; gmshPolarSphere(double x, double y, double z, double _r); - public: - static gmshSurface *NewPolarSphere(int _iSphere, double _x, double _y, double _z, double _r); - virtual Range<double> parBounds(int i) const - { + +public: + static gmshSurface *NewPolarSphere(int _iSphere, double _x, double _y, + double _z, double _r); + virtual Range<double> parBounds(int i) const + { if(i == 0) return Range<double>(-M_PI, M_PI); else return Range<double>(-M_PI, M_PI); } - virtual gmshSurface::gmshSurfaceType geomType() const { return gmshSurface::PolarSphere; } + virtual gmshSurface::gmshSurfaceType geomType() const + { + return gmshSurface::PolarSphere; + } using gmshSurface::point; virtual SPoint3 point(double par1, double par2) const; virtual SVector3 normal(const SPoint2 ¶m) const { - SPoint3 p1 = gmshSurface::point(param); + SPoint3 p1 = gmshSurface::point(param); SVector3 n(p1, o); n.normalize(); return n; } - virtual double getMetricEigenvalue ( const SPoint2 &p) + virtual double getMetricEigenvalue(const SPoint2 &p) { - double l = (4*r*r)/(4*r*r+p.x()*p.x()+p.y()*p.y()); - return l*l; + double l = (4 * r * r) / (4 * r * r + p.x() * p.x() + p.y() * p.y()); + return l * l; } }; class mathEvaluator; -class gmshParametricSurface : public gmshSurface -{ - private: +class gmshParametricSurface : public gmshSurface { +private: mathEvaluator *_f; - gmshParametricSurface(char*, char*, char*); + gmshParametricSurface(char *, char *, char *); ~gmshParametricSurface(); - public: - static gmshSurface *NewParametricSurface(int iSurf, char*, char*, char*); + +public: + static gmshSurface *NewParametricSurface(int iSurf, char *, char *, char *); virtual Range<double> parBounds(int i) const; - virtual gmshSurface::gmshSurfaceType geomType() const - { - return gmshSurface::ParametricSurface; + virtual gmshSurface::gmshSurfaceType geomType() const + { + return gmshSurface::ParametricSurface; } using gmshSurface::point; virtual SPoint3 point(double par1, double par2) const; diff --git a/Geo/gmshVertex.cpp b/Geo/gmshVertex.cpp index 8700bf4eeb0c7135ddbb5527ff3df243732c1f3c..f6f6174e19b4af668cedd91522711bde7d4bc2c2 100644 --- a/Geo/gmshVertex.cpp +++ b/Geo/gmshVertex.cpp @@ -18,42 +18,27 @@ gmshVertex::gmshVertex(GModel *m, Vertex *_v) resetMeshAttributes(); } -void gmshVertex::resetNativePtr(Vertex *_v) -{ - v = _v; -} +void gmshVertex::resetNativePtr(Vertex *_v) { v = _v; } -void gmshVertex::resetMeshAttributes() -{ - meshSize = v->lc; -} +void gmshVertex::resetMeshAttributes() { meshSize = v->lc; } GPoint gmshVertex::point() const { return GPoint(v->Pos.X, v->Pos.Y, v->Pos.Z, this); } -double gmshVertex::x() const -{ - return v->Pos.X; -} +double gmshVertex::x() const { return v->Pos.X; } -double gmshVertex::y() const -{ - return v->Pos.Y; -} +double gmshVertex::y() const { return v->Pos.Y; } -double gmshVertex::z() const -{ - return v->Pos.Z; -} +double gmshVertex::z() const { return v->Pos.Z; } void gmshVertex::setPosition(GPoint &p) { v->Pos.X = p.x(); v->Pos.Y = p.y(); v->Pos.Z = p.z(); - if(mesh_vertices.size()){ + if(mesh_vertices.size()) { mesh_vertices[0]->x() = p.x(); mesh_vertices[0]->y() = p.y(); mesh_vertices[0]->z() = p.z(); @@ -76,97 +61,94 @@ void gmshVertex::setPrescribedMeshSizeAtVertex(double l) SPoint2 gmshVertex::reparamOnFace(const GFace *face, int dir) const { - Surface *s = (Surface*)face->getNativePtr(); + Surface *s = (Surface *)face->getNativePtr(); - if(s->geometry){ + if(s->geometry) { // It is not always right if it is periodic. - if(l_edges.size() == 1 && - (*l_edges.begin())->getBeginVertex() == - (*l_edges.begin())->getEndVertex()){ + if(l_edges.size() == 1 && (*l_edges.begin())->getBeginVertex() == + (*l_edges.begin())->getEndVertex()) { Range<double> bb = (*l_edges.begin())->parBounds(0); return (*l_edges.begin())->reparamOnFace(face, bb.low(), dir); } return v->pntOnGeometry; } - if(s->Typ == MSH_SURF_REGL){ + if(s->Typ == MSH_SURF_REGL) { Curve *C[4]; - for(int i = 0; i < 4; i++) - List_Read(s->Generatrices, i, &C[i]); + for(int i = 0; i < 4; i++) List_Read(s->Generatrices, i, &C[i]); double U, V; - if ((C[0]->beg == v && C[3]->beg == v) || - (C[0]->end == v && C[3]->beg == v) || - (C[0]->beg == v && C[3]->end == v) || - (C[0]->end == v && C[3]->end == v)){ + if((C[0]->beg == v && C[3]->beg == v) || + (C[0]->end == v && C[3]->beg == v) || + (C[0]->beg == v && C[3]->end == v) || + (C[0]->end == v && C[3]->end == v)) { U = V = 0; } - else if ((C[0]->beg == v && C[1]->beg == v) || - (C[0]->end == v && C[1]->beg == v) || - (C[0]->beg == v && C[1]->end == v) || - (C[0]->end == v && C[1]->end == v)){ + else if((C[0]->beg == v && C[1]->beg == v) || + (C[0]->end == v && C[1]->beg == v) || + (C[0]->beg == v && C[1]->end == v) || + (C[0]->end == v && C[1]->end == v)) { U = 1; V = 0; } - else if ((C[2]->beg == v && C[1]->beg == v) || - (C[2]->end == v && C[1]->beg == v) || - (C[2]->beg == v && C[1]->end == v) || - (C[2]->end == v && C[1]->end == v)){ + else if((C[2]->beg == v && C[1]->beg == v) || + (C[2]->end == v && C[1]->beg == v) || + (C[2]->beg == v && C[1]->end == v) || + (C[2]->end == v && C[1]->end == v)) { U = 1; V = 1; } - else if ((C[2]->beg == v && C[3]->beg == v) || - (C[2]->end == v && C[3]->beg == v) || - (C[2]->beg == v && C[3]->end == v) || - (C[2]->end == v && C[3]->end == v)){ + else if((C[2]->beg == v && C[3]->beg == v) || + (C[2]->end == v && C[3]->beg == v) || + (C[2]->beg == v && C[3]->end == v) || + (C[2]->end == v && C[3]->end == v)) { U = 0; V = 1; } - else{ + else { Msg::Info("Reparameterizing point %d on face %d", v->Num, s->Num); return GVertex::reparamOnFace(face, dir); } return SPoint2(U, V); } - else if(s->Typ == MSH_SURF_TRIC){ + else if(s->Typ == MSH_SURF_TRIC) { Curve *C[3]; - for(int i = 0; i < 3; i++) - List_Read(s->Generatrices, i, &C[i]); + for(int i = 0; i < 3; i++) List_Read(s->Generatrices, i, &C[i]); double U, V; - if ((C[0]->beg == v && C[2]->beg == v) || - (C[0]->end == v && C[2]->beg == v) || - (C[0]->beg == v && C[2]->end == v) || - (C[0]->end == v && C[2]->end == v)){ + if((C[0]->beg == v && C[2]->beg == v) || + (C[0]->end == v && C[2]->beg == v) || + (C[0]->beg == v && C[2]->end == v) || + (C[0]->end == v && C[2]->end == v)) { U = V = 0; } - else if ((C[0]->beg == v && C[1]->beg == v) || - (C[0]->end == v && C[1]->beg == v) || - (C[0]->beg == v && C[1]->end == v) || - (C[0]->end == v && C[1]->end == v)){ + else if((C[0]->beg == v && C[1]->beg == v) || + (C[0]->end == v && C[1]->beg == v) || + (C[0]->beg == v && C[1]->end == v) || + (C[0]->end == v && C[1]->end == v)) { U = 1; V = 0; } - else if ((C[2]->beg == v && C[1]->beg == v) || - (C[2]->end == v && C[1]->beg == v) || - (C[2]->beg == v && C[1]->end == v) || - (C[2]->end == v && C[1]->end == v)){ + else if((C[2]->beg == v && C[1]->beg == v) || + (C[2]->end == v && C[1]->beg == v) || + (C[2]->beg == v && C[1]->end == v) || + (C[2]->end == v && C[1]->end == v)) { U = 1; V = 1; } - else{ + else { Msg::Info("Reparameterizing point %d on face %d", v->Num, s->Num); return GVertex::reparamOnFace(face, dir); } return SPoint2(U, V); } - else{ + else { return GVertex::reparamOnFace(face, dir); } } void gmshVertex::writeGEO(FILE *fp, const std::string &meshSizeParameter) { - fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %.16g};\n", - v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc); + fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %.16g};\n", v->Num, v->Pos.X, + v->Pos.Y, v->Pos.Z, v->lc); } diff --git a/Geo/gmshVertex.h b/Geo/gmshVertex.h index 68a5d1ef32b839b07ee362458bcda79814d7e359..5fbb60a030143ee21d9499b0e11f5982a40cd04f 100644 --- a/Geo/gmshVertex.h +++ b/Geo/gmshVertex.h @@ -11,10 +11,10 @@ class Vertex; class gmshVertex : public GVertex { - protected: +protected: Vertex *v; - public: +public: gmshVertex(GModel *m, Vertex *_v); virtual ~gmshVertex() {} virtual void resetMeshAttributes(); @@ -28,7 +28,7 @@ class gmshVertex : public GVertex { void *getNativePtr() const { return v; } virtual void setPrescribedMeshSizeAtVertex(double l); virtual SPoint2 reparamOnFace(const GFace *gf, int) const; - virtual void writeGEO(FILE *fp, const std::string &meshSizeParameter=""); + virtual void writeGEO(FILE *fp, const std::string &meshSizeParameter = ""); void resetNativePtr(Vertex *_v); }; diff --git a/Geo/intersectCurveSurface.cpp b/Geo/intersectCurveSurface.cpp index 10c484795e77d4c55a73e7e1809a5cc51ee29f9f..1184d3ec2cd81f9852b3e074bb3e65ce1ee09eab 100644 --- a/Geo/intersectCurveSurface.cpp +++ b/Geo/intersectCurveSurface.cpp @@ -6,17 +6,18 @@ #include "intersectCurveSurface.h" #include "Numeric.h" -static bool _kaboom(fullVector<double> &uvt, - fullVector<double> &res, void *_data); +static bool _kaboom(fullVector<double> &uvt, fullVector<double> &res, + void *_data); -struct intersectCurveSurfaceData -{ +struct intersectCurveSurfaceData { const curveFunctor &c; const surfaceFunctor &s; const double epsilon; - intersectCurveSurfaceData(const curveFunctor & _c, - const surfaceFunctor & _s, - const double &eps) : c(_c),s(_s),epsilon(eps){} + intersectCurveSurfaceData(const curveFunctor &_c, const surfaceFunctor &_s, + const double &eps) + : c(_c), s(_s), epsilon(eps) + { + } bool apply(double newPoint[3]) { try { @@ -25,21 +26,19 @@ struct intersectCurveSurfaceData uvt(1) = newPoint[1]; uvt(2) = newPoint[2]; fullVector<double> res(3); - _kaboom(uvt,res,this); + _kaboom(uvt, res, this); // printf("start with %12.5E\n",res.norm()); - if (res.norm() < epsilon)return true; + if(res.norm() < epsilon) return true; - - if(newton_fd(_kaboom, uvt, this)){ - // printf("--- CONVERGED -----------\n"); - newPoint[0] = uvt(0); - newPoint[1] = uvt(1); - newPoint[2] = uvt(2); - // printf("newton done\n"); - return true; + if(newton_fd(_kaboom, uvt, this)) { + // printf("--- CONVERGED -----------\n"); + newPoint[0] = uvt(0); + newPoint[1] = uvt(1); + newPoint[2] = uvt(2); + // printf("newton done\n"); + return true; } - } - catch (...){ + } catch(...) { // printf("intersect curve surface failed !\n"); } // printf("newton failed\n"); @@ -47,10 +46,10 @@ struct intersectCurveSurfaceData } }; -static bool _kaboom(fullVector<double> &uvt, - fullVector<double> &res, void *_data) +static bool _kaboom(fullVector<double> &uvt, fullVector<double> &res, + void *_data) { - intersectCurveSurfaceData *data = (intersectCurveSurfaceData*)_data; + intersectCurveSurfaceData *data = (intersectCurveSurfaceData *)_data; SPoint3 s = data->s(uvt(0), uvt(1)); SPoint3 c = data->c(uvt(2)); res(0) = s.x() - c.x(); @@ -59,7 +58,7 @@ static bool _kaboom(fullVector<double> &uvt, return true; } -int intersectCurveSurface(curveFunctor &c, surfaceFunctor & s, double uvt[3], +int intersectCurveSurface(curveFunctor &c, surfaceFunctor &s, double uvt[3], double epsilon) { intersectCurveSurfaceData data(c, s, epsilon); diff --git a/Geo/intersectCurveSurface.h b/Geo/intersectCurveSurface.h index 4b36bd65f10b962fb3ecce6b9992509f012780ca..cc3be01c6aca5b208ad7399feb45ab29084cfb7e 100644 --- a/Geo/intersectCurveSurface.h +++ b/Geo/intersectCurveSurface.h @@ -14,73 +14,77 @@ #include "GFace.h" #include "GEdge.h" -class surfaceFunctor -{ -public : - virtual ~surfaceFunctor(){} - virtual SPoint3 operator () (double u, double v) const = 0; +class surfaceFunctor { +public: + virtual ~surfaceFunctor() {} + virtual SPoint3 operator()(double u, double v) const = 0; }; -class curveFunctor -{ -public : - virtual ~curveFunctor(){} - virtual SPoint3 operator () (double t) const = 0; +class curveFunctor { +public: + virtual ~curveFunctor() {} + virtual SPoint3 operator()(double t) const = 0; }; -class surfaceFunctorGFace : public surfaceFunctor -{ +class surfaceFunctorGFace : public surfaceFunctor { const GFace *gf; -public : + +public: surfaceFunctorGFace(const GFace *_gf) : gf(_gf) {} - virtual SPoint3 operator () (double u, double v) const { - GPoint gp = gf->point(u,v); - if (! gp.succeeded())throw gf; - return SPoint3(gp.x(),gp.y(),gp.z()); + virtual SPoint3 operator()(double u, double v) const + { + GPoint gp = gf->point(u, v); + if(!gp.succeeded()) throw gf; + return SPoint3(gp.x(), gp.y(), gp.z()); } }; -class curveFunctorGEdge : public curveFunctor -{ +class curveFunctorGEdge : public curveFunctor { const GEdge *ge; -public : + +public: curveFunctorGEdge(const GEdge *_ge) : ge(_ge) {} - virtual SPoint3 operator () (double t) const { - GPoint gp = ge->point(t); - return SPoint3(gp.x(),gp.y(),gp.z()); + virtual SPoint3 operator()(double t) const + { + GPoint gp = ge->point(t); + return SPoint3(gp.x(), gp.y(), gp.z()); } }; -class curveFunctorCircle : public curveFunctor -{ - SVector3 n1,n2; +class curveFunctorCircle : public curveFunctor { + SVector3 n1, n2; SVector3 middle; double d; -public : - curveFunctorCircle(const SVector3 & _n1, const SVector3 & _n2, - const SVector3 & _middle, const double & _d) : - n1(_n1), n2(_n2), middle(_middle), d(_d){} - virtual SPoint3 operator () (double t) const + +public: + curveFunctorCircle(const SVector3 &_n1, const SVector3 &_n2, + const SVector3 &_middle, const double &_d) + : n1(_n1), n2(_n2), middle(_middle), d(_d) { - SVector3 dir = (n1*cos(t)+n2*sin(t))*d; - return SPoint3(middle.x() + dir.x(), - middle.y() + dir.y(), - middle.z() + dir.z()); + } + virtual SPoint3 operator()(double t) const + { + SVector3 dir = (n1 * cos(t) + n2 * sin(t)) * d; + return SPoint3(middle.x() + dir.x(), middle.y() + dir.y(), + middle.z() + dir.z()); } }; -class surfaceFunctorPlane : public surfaceFunctor -{ +class surfaceFunctorPlane : public surfaceFunctor { const SPoint3 p; - const SVector3 v1,v2; -public : - surfaceFunctorPlane(const SPoint3 &_p, const SVector3 &_v1, const SVector3 &_v2) - : p(_p),v1(_v1),v2(_v2) {} - virtual SPoint3 operator () (double u, double v) const + const SVector3 v1, v2; + +public: + surfaceFunctorPlane(const SPoint3 &_p, const SVector3 &_v1, + const SVector3 &_v2) + : p(_p), v1(_v1), v2(_v2) + { + } + virtual SPoint3 operator()(double u, double v) const { - return SPoint3 (p.x() + u * v1.x() + v * v2.x(), - p.y() + u * v1.y() + v * v2.y(), - p.z() + u * v1.z() + v * v2.z()) ; + return SPoint3(p.x() + u * v1.x() + v * v2.x(), + p.y() + u * v1.y() + v * v2.y(), + p.z() + u * v1.z() + v * v2.z()); } }; @@ -88,7 +92,7 @@ public : // the initial guess should be a good guess // returns 1 --> OK // returns 0 --> NOT CONVERGED -int intersectCurveSurface(curveFunctor &c, surfaceFunctor & s, double uvt[3], +int intersectCurveSurface(curveFunctor &c, surfaceFunctor &s, double uvt[3], double epsilon); #endif diff --git a/Geo/partitionEdge.h b/Geo/partitionEdge.h index 188991b4c1eadd6d2b7d2f13732880839b901fd5..10b4ac34251bbbb9cf772091bf1593595b601dbf 100644 --- a/Geo/partitionEdge.h +++ b/Geo/partitionEdge.h @@ -13,22 +13,28 @@ class partitionEdge : public discreteEdge { private: std::vector<unsigned int> _partitions; GEntity *_parentEntity; + public: partitionEdge(GModel *model, int num, GVertex *_v0, GVertex *_v1, const std::vector<unsigned int> &partitions) : discreteEdge(model, num, _v0, _v1), _partitions(partitions), - _parentEntity(NULL) {} - partitionEdge(GModel *model, int num, const std::vector<unsigned int> &partitions) - : discreteEdge(model, num), _partitions(partitions), _parentEntity(NULL) {} + _parentEntity(NULL) + { + } + partitionEdge(GModel *model, int num, + const std::vector<unsigned int> &partitions) + : discreteEdge(model, num), _partitions(partitions), _parentEntity(NULL) + { + } virtual ~partitionEdge() {} virtual GeomType geomType() const { return PartitionCurve; } - virtual void setParentEntity(GEntity* e) { _parentEntity = e; } - virtual GEntity* getParentEntity() { return _parentEntity; } + virtual void setParentEntity(GEntity *e) { _parentEntity = e; } + virtual GEntity *getParentEntity() { return _parentEntity; } virtual void setPartitions(std::vector<unsigned int> &partitions) { _partitions = partitions; } - virtual const std::vector<unsigned int>& getPartitions() const + virtual const std::vector<unsigned int> &getPartitions() const { return _partitions; } @@ -39,15 +45,15 @@ public: virtual unsigned int numPartitions() const { return _partitions.size(); } }; -struct Less_partitionEdge : - public std::binary_function<partitionEdge*, partitionEdge*, bool> { - bool operator()(const partitionEdge* e1, const partitionEdge* e2) const +struct Less_partitionEdge + : public std::binary_function<partitionEdge *, partitionEdge *, bool> { + bool operator()(const partitionEdge *e1, const partitionEdge *e2) const { - if (e1->numPartitions() < e2->numPartitions()) return true; - if (e1->numPartitions() > e2->numPartitions()) return false; - for (unsigned int i = 0; i < e1->numPartitions(); i++){ - if (e1->getPartition(i) < e2->getPartition(i)) return true; - if (e1->getPartition(i) > e2->getPartition(i)) return false; + if(e1->numPartitions() < e2->numPartitions()) return true; + if(e1->numPartitions() > e2->numPartitions()) return false; + for(unsigned int i = 0; i < e1->numPartitions(); i++) { + if(e1->getPartition(i) < e2->getPartition(i)) return true; + if(e1->getPartition(i) > e2->getPartition(i)) return false; } return false; } diff --git a/Geo/partitionFace.h b/Geo/partitionFace.h index 3befab1b9ac41557841bac94d5260cc433f27384..5b6a9744a38790b2016b2b83d5ff42180693f301 100644 --- a/Geo/partitionFace.h +++ b/Geo/partitionFace.h @@ -13,20 +13,26 @@ class partitionFace : public discreteFace { private: std::vector<unsigned int> _partitions; GEntity *_parentEntity; + public: - partitionFace(GModel *model, int num, const std::vector<unsigned int> &partitions) - : discreteFace(model, num), _partitions(partitions), _parentEntity(NULL) {} + partitionFace(GModel *model, int num, + const std::vector<unsigned int> &partitions) + : discreteFace(model, num), _partitions(partitions), _parentEntity(NULL) + { + } partitionFace(GModel *model, int num) - : discreteFace(model, num), _partitions(), _parentEntity(NULL) {} + : discreteFace(model, num), _partitions(), _parentEntity(NULL) + { + } virtual ~partitionFace() {} virtual GeomType geomType() const { return PartitionSurface; } - virtual void setParentEntity(GEntity* f) { _parentEntity = f; } - virtual GEntity* getParentEntity() { return _parentEntity; } + virtual void setParentEntity(GEntity *f) { _parentEntity = f; } + virtual GEntity *getParentEntity() { return _parentEntity; } virtual void setPartitions(std::vector<unsigned int> &partitions) { _partitions = partitions; } - virtual const std::vector<unsigned int>& getPartitions() const + virtual const std::vector<unsigned int> &getPartitions() const { return _partitions; } @@ -37,15 +43,15 @@ public: virtual unsigned int numPartitions() const { return _partitions.size(); } }; -struct Less_partitionFace : - public std::binary_function<partitionFace*, partitionFace*, bool> { - bool operator()(const partitionFace* e1, const partitionFace* e2) const +struct Less_partitionFace + : public std::binary_function<partitionFace *, partitionFace *, bool> { + bool operator()(const partitionFace *e1, const partitionFace *e2) const { - if (e1->numPartitions() < e2->numPartitions()) return true; - if (e1->numPartitions() > e2->numPartitions()) return false; - for (unsigned int i = 0; i < e1->numPartitions(); i++){ - if (e1->getPartition(i) < e2->getPartition(i)) return true; - if (e1->getPartition(i) > e2->getPartition(i)) return false; + if(e1->numPartitions() < e2->numPartitions()) return true; + if(e1->numPartitions() > e2->numPartitions()) return false; + for(unsigned int i = 0; i < e1->numPartitions(); i++) { + if(e1->getPartition(i) < e2->getPartition(i)) return true; + if(e1->getPartition(i) > e2->getPartition(i)) return false; } return false; } diff --git a/Geo/partitionRegion.h b/Geo/partitionRegion.h index 16803bf4e85c21895a3cea21aa8149ac669a1e40..72e20258535bedbf544ab95b8789f70f1c74e875 100644 --- a/Geo/partitionRegion.h +++ b/Geo/partitionRegion.h @@ -13,20 +13,26 @@ class partitionRegion : public discreteRegion { private: std::vector<unsigned int> _partitions; GEntity *_parentEntity; + public: - partitionRegion(GModel *model, int num, const std::vector<unsigned int> &partitions) : - discreteRegion(model, num), _partitions(partitions), _parentEntity(NULL) {} + partitionRegion(GModel *model, int num, + const std::vector<unsigned int> &partitions) + : discreteRegion(model, num), _partitions(partitions), _parentEntity(NULL) + { + } partitionRegion(GModel *model, int num) - : discreteRegion(model, num), _partitions(), _parentEntity(NULL) {} + : discreteRegion(model, num), _partitions(), _parentEntity(NULL) + { + } virtual ~partitionRegion() {} virtual GeomType geomType() const { return PartitionVolume; } - virtual void setParentEntity(GEntity* r) { _parentEntity = r; } - virtual GEntity* getParentEntity() { return _parentEntity; } + virtual void setParentEntity(GEntity *r) { _parentEntity = r; } + virtual GEntity *getParentEntity() { return _parentEntity; } virtual void setPartitions(std::vector<unsigned int> &partitions) { _partitions = partitions; } - virtual const std::vector<unsigned int>& getPartitions() const + virtual const std::vector<unsigned int> &getPartitions() const { return _partitions; } @@ -37,15 +43,15 @@ public: virtual unsigned int numPartitions() const { return _partitions.size(); } }; -struct Less_partitionRegion : - public std::binary_function<partitionRegion*, partitionRegion*, bool> { - bool operator()(const partitionRegion* e1, const partitionRegion* e2) const +struct Less_partitionRegion + : public std::binary_function<partitionRegion *, partitionRegion *, bool> { + bool operator()(const partitionRegion *e1, const partitionRegion *e2) const { - if (e1->numPartitions() < e2->numPartitions()) return true; - if (e1->numPartitions() > e2->numPartitions()) return false; - for (unsigned int i = 0; i < e1->numPartitions(); i++){ - if (e1->getPartition(i) < e2->getPartition(i)) return true; - if (e1->getPartition(i) > e2->getPartition(i)) return false; + if(e1->numPartitions() < e2->numPartitions()) return true; + if(e1->numPartitions() > e2->numPartitions()) return false; + for(unsigned int i = 0; i < e1->numPartitions(); i++) { + if(e1->getPartition(i) < e2->getPartition(i)) return true; + if(e1->getPartition(i) > e2->getPartition(i)) return false; } return false; } diff --git a/Geo/partitionVertex.h b/Geo/partitionVertex.h index d0ec0bc5c3922129e3a71cbad6b21685e21c114e..67beca624c0fdb35215a5d55ca4d592ae7cff971 100644 --- a/Geo/partitionVertex.h +++ b/Geo/partitionVertex.h @@ -9,24 +9,30 @@ #include "GModel.h" #include "discreteVertex.h" -class partitionVertex : public discreteVertex{ +class partitionVertex : public discreteVertex { private: std::vector<unsigned int> _partitions; GEntity *_parentEntity; + public: - partitionVertex(GModel *model, int num, const std::vector<unsigned int> &partitions) - : discreteVertex(model, num), _partitions(partitions), _parentEntity(NULL) {} + partitionVertex(GModel *model, int num, + const std::vector<unsigned int> &partitions) + : discreteVertex(model, num), _partitions(partitions), _parentEntity(NULL) + { + } partitionVertex(GModel *model, int num) - : discreteVertex(model, num), _partitions(), _parentEntity(NULL) {} + : discreteVertex(model, num), _partitions(), _parentEntity(NULL) + { + } virtual ~partitionVertex() {} virtual GeomType geomType() const { return PartitionVertex; } - virtual void setParentEntity(GEntity* v) { _parentEntity = v; } - virtual GEntity* getParentEntity() { return _parentEntity; } + virtual void setParentEntity(GEntity *v) { _parentEntity = v; } + virtual GEntity *getParentEntity() { return _parentEntity; } virtual void setPartitions(std::vector<unsigned int> &partitions) { _partitions = partitions; } - virtual const std::vector<unsigned int>& getPartitions() const + virtual const std::vector<unsigned int> &getPartitions() const { return _partitions; } @@ -37,15 +43,15 @@ public: virtual unsigned int numPartitions() const { return _partitions.size(); } }; -struct Less_partitionVertex : - public std::binary_function<partitionVertex*, partitionVertex*, bool> { - bool operator()(const partitionVertex* e1, const partitionVertex* e2) const +struct Less_partitionVertex + : public std::binary_function<partitionVertex *, partitionVertex *, bool> { + bool operator()(const partitionVertex *e1, const partitionVertex *e2) const { - if (e1->numPartitions() < e2->numPartitions()) return true; - if (e1->numPartitions() > e2->numPartitions()) return false; - for (unsigned int i = 0; i < e1->numPartitions(); i++){ - if (e1->getPartition(i) < e2->getPartition(i)) return true; - if (e1->getPartition(i) > e2->getPartition(i)) return false; + if(e1->numPartitions() < e2->numPartitions()) return true; + if(e1->numPartitions() > e2->numPartitions()) return false; + for(unsigned int i = 0; i < e1->numPartitions(); i++) { + if(e1->getPartition(i) < e2->getPartition(i)) return true; + if(e1->getPartition(i) > e2->getPartition(i)) return false; } return false; } diff --git a/Graphics/Camera.cpp b/Graphics/Camera.cpp index d0ec4bbff5d2ba9c2a0b7bdb41cb43cbedaa4f0d..759de86325ea21239cec862bbae20ad6ff2aee97 100644 --- a/Graphics/Camera.cpp +++ b/Graphics/Camera.cpp @@ -18,31 +18,35 @@ #include "Context.h" #include "drawContext.h" -Camera::Camera() : on(false), stereoEnable(false), Lc(1.), glFnear(0.0001), glFfar(10000) {} +Camera::Camera() + : on(false), stereoEnable(false), Lc(1.), glFnear(0.0001), glFfar(10000) +{ +} Camera::~Camera() {} void Camera::init() { - if(CTX::instance()->fileread ) { on = true; } + if(CTX::instance()->fileread) { + on = true; + } eye_sep_ratio = CTX::instance()->eye_sep_ratio; aperture = CTX::instance()->camera_aperture; focallength = CTX::instance()->focallength_ratio * 100.; alongZ(); this->lookAtCg(); eyesep = distance * eye_sep_ratio / 100.; - ref_distance=distance; - glFnear=.0001*distance; - glFfar=10000*distance; + ref_distance = distance; + glFnear = .0001 * distance; + glFfar = 10000 * distance; this->update(); - } void Camera::alongX() { front.set(-1., 0., 0.); up.set(0., 0., 1); - position = target-distance * front; + position = target - distance * front; this->update(); } @@ -50,7 +54,7 @@ void Camera::alongY() { front.set(0., -1., 0.); up.set(1., 0., 0); - position = target-distance * front; + position = target - distance * front; this->update(); } @@ -58,19 +62,29 @@ void Camera::alongZ() { front.set(0., 0., -1.); up.set(0., 1., 0); - position = target-distance * front; + position = target - distance * front; this->update(); } void Camera::upX() { - if( up.x > 0.){ - if (up.x !=1.) { up.set(1.,0.,0.); } - else { up.set(-1.,0.,0.); right=-right; } + if(up.x > 0.) { + if(up.x != 1.) { + up.set(1., 0., 0.); + } + else { + up.set(-1., 0., 0.); + right = -right; + } } else { - if (up.x !=-1.) {up.set(-1.,0.,0.); } - else { up.set(1.,0.,0.); right=-right; } + if(up.x != -1.) { + up.set(-1., 0., 0.); + } + else { + up.set(1., 0., 0.); + right = -right; + } } front.x = up.y * right.z - up.z * right.y; front.y = up.z * right.x - up.x * right.z; @@ -81,13 +95,23 @@ void Camera::upX() void Camera::upY() { - if( up.y > 0.){ - if (up.y !=1.) { up.set(0.,1.,0.); } - else { up.set(0.,-1.,0.); right=-right; } + if(up.y > 0.) { + if(up.y != 1.) { + up.set(0., 1., 0.); + } + else { + up.set(0., -1., 0.); + right = -right; + } } else { - if (up.y !=-1.) {up.set(0.,-1.,0.); } - else { up.set(0.,1.,0.); right=-right; } + if(up.y != -1.) { + up.set(0., -1., 0.); + } + else { + up.set(0., 1., 0.); + right = -right; + } } front.x = up.y * right.z - up.z * right.y; front.y = up.z * right.x - up.x * right.z; @@ -96,16 +120,25 @@ void Camera::upY() this->update(); } - void Camera::upZ() { - if( up.z > 0.){ - if (up.z !=1.) { up.set(0.,0.,1.); } - else { up.set(0.,0.,-1.); right=-right; } + if(up.z > 0.) { + if(up.z != 1.) { + up.set(0., 0., 1.); + } + else { + up.set(0., 0., -1.); + right = -right; + } } else { - if (up.z !=-1.) {up.set(0.,0.,-1.); } - else { up.set(0.,0.,1.); right=-right; } + if(up.z != -1.) { + up.set(0., 0., -1.); + } + else { + up.set(0., 0., 1.); + right = -right; + } } front.x = up.y * right.z - up.z * right.y; front.y = up.z * right.x - up.x * right.z; @@ -114,11 +147,17 @@ void Camera::upZ() this->update(); } +void Camera::tiltHeadLeft() +{ + up = -1. * right; + update(); +} - -void Camera::tiltHeadLeft() { up = -1. * right; update(); } - -void Camera::tiltHeadRight() { up = right; update(); } +void Camera::tiltHeadRight() +{ + up = right; + update(); +} void Camera::lookAtCg() { @@ -137,7 +176,7 @@ void Camera::lookAtCg() eyesep = focallength * eye_sep_ratio / 100.; } -void Camera::giveViewportDimension(const int& W,const int& H) +void Camera::giveViewportDimension(const int &W, const int &H) { screenwidth = W; screenheight = H; @@ -174,61 +213,68 @@ void Camera::update() void Camera::affiche() { - std::cout<<" ------------ GENERAL PARAMETERS ------------" <<std::endl ; - std::cout<<" CTX aperture "<< CTX::instance()->camera_aperture <<std::endl ; - std::cout<<" CTX eyesep ratio "<< CTX::instance()->eye_sep_ratio <<std::endl ; - std::cout<<" CTX focallength ratio "<< CTX::instance()->focallength_ratio <<std::endl ; - std::cout<<" ------------ CAMERA PARAMETERS ------------" <<std::endl ; - std::cout<<" position "<< position.x<<","<<position.y<<","<<position.z <<std::endl ; - std::cout<<" front "<< front.x<<","<<front.y<<","<<front.z <<std::endl; - std::cout<<" up "<< up.x<<","<<up.y<<","<<up.z <<std::endl; - std::cout<<" right "<< right.x<<","<<right.y<<","<<right.z <<std::endl; - std::cout<<" target "<< target.x<<","<<target.y<<","<<target.z <<std::endl; - std::cout<<" focallength_ratio "<<focallength_ratio <<std::endl; - std::cout<<" focallength "<<focallength <<std::endl; - std::cout<<" aperture "<<aperture <<std::endl; - std::cout<<" eyesep_ratio "<<eye_sep_ratio <<std::endl; - std::cout<<" eyesep "<<eyesep <<std::endl; - std::cout<<" screenwidth "<<screenwidth <<std::endl; - std::cout<<" screenheight "<<screenheight <<std::endl; - std::cout<<" distance "<<distance <<std::endl; - std::cout<<" ref_distance "<<ref_distance <<std::endl; - std::cout<<" button_left_down "<<button_left_down <<std::endl; - std::cout<<" button_middle_down "<< button_middle_down <<std::endl; - std::cout<<" button_right_down "<< button_right_down <<std::endl; - std::cout<<" stereoEnable "<< stereoEnable <<std::endl; - std::cout<<" Lc "<< Lc<<std::endl; - std::cout<<" eye_sep_ratio "<<eye_sep_ratio <<std::endl; - std::cout<<" closeness "<< closeness<<std::endl; - std::cout<<" glFnear "<< glFnear <<std::endl; - std::cout<<" glFfar "<< glFfar <<std::endl; - std::cout<<" radians "<<radians <<std::endl; - std::cout<<" wd2 "<<wd2 <<std::endl; -} - -void Camera::moveRight(double& theta) + std::cout << " ------------ GENERAL PARAMETERS ------------" << std::endl; + std::cout << " CTX aperture " << CTX::instance()->camera_aperture + << std::endl; + std::cout << " CTX eyesep ratio " << CTX::instance()->eye_sep_ratio + << std::endl; + std::cout << " CTX focallength ratio " << CTX::instance()->focallength_ratio + << std::endl; + std::cout << " ------------ CAMERA PARAMETERS ------------" << std::endl; + std::cout << " position " << position.x << "," << position.y << "," + << position.z << std::endl; + std::cout << " front " << front.x << "," << front.y << "," << front.z + << std::endl; + std::cout << " up " << up.x << "," << up.y << "," << up.z << std::endl; + std::cout << " right " << right.x << "," << right.y << "," << right.z + << std::endl; + std::cout << " target " << target.x << "," << target.y << "," << target.z + << std::endl; + std::cout << " focallength_ratio " << focallength_ratio << std::endl; + std::cout << " focallength " << focallength << std::endl; + std::cout << " aperture " << aperture << std::endl; + std::cout << " eyesep_ratio " << eye_sep_ratio << std::endl; + std::cout << " eyesep " << eyesep << std::endl; + std::cout << " screenwidth " << screenwidth << std::endl; + std::cout << " screenheight " << screenheight << std::endl; + std::cout << " distance " << distance << std::endl; + std::cout << " ref_distance " << ref_distance << std::endl; + std::cout << " button_left_down " << button_left_down << std::endl; + std::cout << " button_middle_down " << button_middle_down << std::endl; + std::cout << " button_right_down " << button_right_down << std::endl; + std::cout << " stereoEnable " << stereoEnable << std::endl; + std::cout << " Lc " << Lc << std::endl; + std::cout << " eye_sep_ratio " << eye_sep_ratio << std::endl; + std::cout << " closeness " << closeness << std::endl; + std::cout << " glFnear " << glFnear << std::endl; + std::cout << " glFfar " << glFfar << std::endl; + std::cout << " radians " << radians << std::endl; + std::cout << " wd2 " << wd2 << std::endl; +} + +void Camera::moveRight(double &theta) { this->update(); - position = position-distance * tan(theta) * right; + position = position - distance * tan(theta) * right; target = position + distance * front; this->update(); } -void Camera::moveUp(double& theta) +void Camera::moveUp(double &theta) { this->update(); - position = position+distance * tan(theta) * up; - target = position+distance * front; + position = position + distance * tan(theta) * up; + target = position + distance * front; this->update(); } -void Camera::zoom(double& factor) +void Camera::zoom(double &factor) { distance = fabs(1. / factor * ref_distance); position = target - distance * front; } -void Camera::rotate(double* q) +void Camera::rotate(double *q) { this->update(); // rotation projection in global coordinates @@ -245,33 +291,33 @@ void Camera::rotate(double* q) normalize(front); normalize(up); normalize(right); - //actualize camera position + // actualize camera position position = target - distance * front; this->update(); } -void Camera::move_and_look(double _movfront,double _movright,double _movup, - double _thetafront,double _thetaright,double _thetaup, - double _azimut,double _elevation) +void Camera::move_and_look(double _movfront, double _movright, double _movup, + double _thetafront, double _thetaright, + double _thetaup, double _azimut, double _elevation) { - position= position + _movfront*front + _movright*right + _movup*up; + position = position + _movfront * front + _movright * right + _movup * up; Quaternion omega_up; - omega_up.x = sin( _thetaup ) * up.x ; - omega_up.y = sin( _thetaup ) * up.y ; - omega_up.z = sin( _thetaup ) * up.z ; - omega_up.w = cos( _thetaup ); + omega_up.x = sin(_thetaup) * up.x; + omega_up.y = sin(_thetaup) * up.y; + omega_up.z = sin(_thetaup) * up.z; + omega_up.w = cos(_thetaup); normalize(omega_up); Quaternion omega_right; - omega_right.x = sin( _thetaright ) * right.x ; - omega_right.y = sin( _thetaright ) * right.y ; - omega_right.z = sin( _thetaright ) * right.z ; - omega_right.w = cos( _thetaright ); + omega_right.x = sin(_thetaright) * right.x; + omega_right.y = sin(_thetaright) * right.y; + omega_right.z = sin(_thetaright) * right.z; + omega_right.w = cos(_thetaright); normalize(omega_right); Quaternion omega_front; - omega_front.x = sin( _thetafront ) * front.x ; - omega_front.y = sin( _thetafront ) * front.y ; - omega_front.z = sin( _thetafront ) * front.z ; - omega_front.w = cos( _thetafront ); + omega_front.x = sin(_thetafront) * front.x; + omega_front.y = sin(_thetafront) * front.y; + omega_front.z = sin(_thetafront) * front.z; + omega_front.w = cos(_thetafront); normalize(omega_front); Quaternion omega; omega = omega_up * omega_right * omega_front; @@ -285,85 +331,85 @@ void Camera::move_and_look(double _movfront,double _movright,double _movup, normalize(right); this->update(); // in azimuthal coordinates - XYZ look,newlook; - _elevation = std::min(_elevation,1.57); - _elevation = std::max(_elevation,-1.57); - look=cos(_azimut)*front-sin(_azimut)*right; - newlook=cos(_elevation)*look+sin(_elevation)*up; + XYZ look, newlook; + _elevation = std::min(_elevation, 1.57); + _elevation = std::max(_elevation, -1.57); + look = cos(_azimut) * front - sin(_azimut) * right; + newlook = cos(_elevation) * look + sin(_elevation) * up; target = position + distance * newlook; } - - - - - - - - - - - - //////////////////////////////////////////////////////////////// // QUATERNION and XYZ functions //////////////////////////////////////////////////////////////// double length(Quaternion &q) { - return sqrt(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w); + return sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); } -double length(XYZ &p) -{ - return sqrt(p.x * p.x + p.y * p.y + p.z * p.z); -} +double length(XYZ &p) { return sqrt(p.x * p.x + p.y * p.y + p.z * p.z); } void normalize_axe(Quaternion &q) { double sina = sin(acos(q.w)); double l; - if (sina != 0.){ - l = ( q.x*q.x + q.y*q.y + q.z*q.z ) / (sina*sina); - l =sqrt(l) ; + if(sina != 0.) { + l = (q.x * q.x + q.y * q.y + q.z * q.z) / (sina * sina); + l = sqrt(l); } - else{ + else { l = 0.; } - if(l != 0. ){ - q.x /= l; q.y /= l; q.z /= l; - } + if(l != 0.) { + q.x /= l; + q.y /= l; + q.z /= l; + } } void normalize(Quaternion &q) { double L = length(q); - q.x /= L; q.y /= L; q.z /= L; q.w /= L; - + q.x /= L; + q.y /= L; + q.z /= L; + q.w /= L; } void normalize(XYZ &p) { double L = length(p); - p.x /= L; p.y /= L; p.z /= L; + p.x /= L; + p.y /= L; + p.z /= L; } -XYZ::XYZ (const Quaternion &R) : x(R.x), y(R.y), z(R.z){} +XYZ::XYZ(const Quaternion &R) : x(R.x), y(R.y), z(R.z) {} -XYZ::XYZ(double _x,double _y,double _z) : x(_x),y(_y),z(_z){} +XYZ::XYZ(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {} - -void XYZ::set(const double& _x, const double& _y, const double& _z){ x = _x; y =_y; z = _z; } +void XYZ::set(const double &_x, const double &_y, const double &_z) +{ + x = _x; + y = _y; + z = _z; +} void rotate(const Quaternion &omega, XYZ axe) { XYZ new_axe; - Quaternion qaxe,new_qaxe; - qaxe.x = axe.x; qaxe.y = axe.y; qaxe.z = axe.z; qaxe.w = 0.; + Quaternion qaxe, new_qaxe; + qaxe.x = axe.x; + qaxe.y = axe.y; + qaxe.z = axe.z; + qaxe.w = 0.; new_qaxe = mult(mult(omega, qaxe), conjugate(omega)); - axe.x = new_qaxe.x; axe.y = new_qaxe.y; axe.z = new_qaxe.z; + axe.x = new_qaxe.x; + axe.y = new_qaxe.y; + axe.z = new_qaxe.z; } -XYZ operator* (const double &a, const XYZ &T) +XYZ operator*(const double &a, const XYZ &T) { XYZ res(T); res.x *= a; @@ -372,7 +418,7 @@ XYZ operator* (const double &a, const XYZ &T) return res; } -XYZ operator+ (const XYZ &L, const XYZ &R) +XYZ operator+(const XYZ &L, const XYZ &R) { XYZ res(L); res.x += R.x; @@ -380,7 +426,7 @@ XYZ operator+ (const XYZ &L, const XYZ &R) res.z += R.z; return res; } -XYZ operator- (const XYZ &L, const XYZ &R) +XYZ operator-(const XYZ &L, const XYZ &R) { XYZ res(L); res.x -= R.x; @@ -388,7 +434,7 @@ XYZ operator- (const XYZ &L, const XYZ &R) res.z -= R.z; return res; } -XYZ operator- (const XYZ &R) +XYZ operator-(const XYZ &R) { XYZ res; res.x = -R.x; @@ -399,17 +445,18 @@ XYZ operator- (const XYZ &R) Quaternion::Quaternion(const XYZ &R) : x(R.x), y(R.y), z(R.z), w(0.) {} -Quaternion::Quaternion(const XYZ &R, const double &A) { - x=R.x*sin(A); - y=R.y*sin(A); - z=R.z*sin(A); - w=cos(A); +Quaternion::Quaternion(const XYZ &R, const double &A) +{ + x = R.x * sin(A); + y = R.y * sin(A); + z = R.z * sin(A); + w = cos(A); } -Quaternion::Quaternion(): x(0.), y(0.),z(0.),w(1.) {} +Quaternion::Quaternion() : x(0.), y(0.), z(0.), w(1.) {} Quaternion::~Quaternion() {} -Quaternion mult(const Quaternion& A, const Quaternion& B) +Quaternion mult(const Quaternion &A, const Quaternion &B) { Quaternion C; C.x = A.w * B.x + A.x * B.w + A.y * B.z - A.z * B.y; @@ -419,13 +466,15 @@ Quaternion mult(const Quaternion& A, const Quaternion& B) return C; } -Quaternion operator *(const Quaternion& A, const Quaternion& B) +Quaternion operator*(const Quaternion &A, const Quaternion &B) { return mult(A, B); } Quaternion conjugate(Quaternion quat) { - quat.x = -quat.x; quat.y = -quat.y; quat.z = -quat.z; + quat.x = -quat.x; + quat.y = -quat.y; + quat.z = -quat.z; return quat; } diff --git a/Graphics/Camera.h b/Graphics/Camera.h index 87d2635b894aabd6f0bbeda8f78e637cabf0e3f8..64a8c5433f995876faedb02d816065e14bc8b13a 100644 --- a/Graphics/Camera.h +++ b/Graphics/Camera.h @@ -14,23 +14,23 @@ class XYZ { public: XYZ() : x(0.), y(0.), z(0.){}; ~XYZ(){}; - XYZ(double _x,double _y,double _z); + XYZ(double _x, double _y, double _z); double x, y, z; - void set(const double & _x, const double & _y ,const double & _z); - XYZ (const Quaternion &R); + void set(const double &_x, const double &_y, const double &_z); + XYZ(const Quaternion &R); }; double length(XYZ &p); void normalize(XYZ &p); void rotate(const Quaternion &omega, XYZ axe); -XYZ operator* (const double &a,const XYZ &T); -XYZ operator+ (const XYZ &L,const XYZ &R); -XYZ operator- (const XYZ &L,const XYZ &R); -XYZ operator- (const XYZ &R); +XYZ operator*(const double &a, const XYZ &T); +XYZ operator+(const XYZ &L, const XYZ &R); +XYZ operator-(const XYZ &L, const XYZ &R); +XYZ operator-(const XYZ &R); -class Quaternion{ +class Quaternion { public: - double x,y,z,w; + double x, y, z, w; Quaternion(); Quaternion(const XYZ &R); Quaternion(const XYZ &R, const double &A); @@ -40,41 +40,41 @@ public: double length(Quaternion &quat); void normalize(Quaternion &quat); Quaternion conjugate(Quaternion quat); -Quaternion mult(const Quaternion& A,const Quaternion& B); -Quaternion operator *(const Quaternion &A, const Quaternion &B); +Quaternion mult(const Quaternion &A, const Quaternion &B); +Quaternion operator*(const Quaternion &A, const Quaternion &B); class Camera { - public: +public: Camera(); ~Camera(); bool on; - XYZ position; /* camera position */ - XYZ front; /* View direction vector */ - XYZ up; /* View up direction */ - XYZ right; /* View right direction */ - XYZ target; /* center of rotation and screen */ - double focallength; /* Focal Length along vd */ + XYZ position; /* camera position */ + XYZ front; /* View direction vector */ + XYZ up; /* View up direction */ + XYZ right; /* View right direction */ + XYZ target; /* center of rotation and screen */ + double focallength; /* Focal Length along vd */ double focallength_ratio; - double aperture; /* Camera aperture */ - double eyesep; /* Eye separation */ - int screenwidth,screenheight; + double aperture; /* Camera aperture */ + double eyesep; /* Eye separation */ + int screenwidth, screenheight; double screenratio, distance, ref_distance; bool button_left_down, button_middle_down, button_right_down; bool stereoEnable; double Lc, eye_sep_ratio, closeness, ndfl, glFnear, glFfar, radians, wd2; - double glFleft,glFright,glFtop,glFbottom; - void giveViewportDimension(const int& W,const int& H); + double glFleft, glFright, glFtop, glFbottom; + void giveViewportDimension(const int &W, const int &H); void lookAtCg(); void init(); - void rotate(double* q); + void rotate(double *q); // - void move_and_look(double _movfront,double _movright,double _movup, - double _rotfront,double _rotright,double _rotup, - double _azimut,double _elevation); + void move_and_look(double _movfront, double _movright, double _movup, + double _rotfront, double _rotright, double _rotup, + double _azimut, double _elevation); // - void moveRight(double& theta); - void moveUp(double& theta); - void zoom(double& factor); + void moveRight(double &theta); + void moveUp(double &theta); + void zoom(double &factor); void update(); void affiche(); void alongX(); @@ -88,14 +88,14 @@ class Camera { }; class mouseAndKeyboard { - public: +public: bool button_left_down; bool button_middle_down; bool button_right_down; int key; int mode; - mouseAndKeyboard() {}; - ~mouseAndKeyboard() {}; + mouseAndKeyboard(){}; + ~mouseAndKeyboard(){}; }; #endif diff --git a/Graphics/PixelBuffer.h b/Graphics/PixelBuffer.h index 32fdf71aecbea2724fc7d88a07729dc77bdba863..ade7479563f04fc88be0a4ee328ff97576cb93b7 100644 --- a/Graphics/PixelBuffer.h +++ b/Graphics/PixelBuffer.h @@ -29,34 +29,35 @@ #include <GL/osmesa.h> #endif -class PixelBuffer{ - private: +class PixelBuffer { +private: int _width, _height, _numComp, _dataSize; GLenum _format, _type; unsigned char *_pixels; - public: + +public: PixelBuffer(int width, int height, GLenum format, GLenum type) : _width(width), _height(height), _format(format), _type(type) { - if(format == GL_RGB){ + if(format == GL_RGB) { _numComp = 3; } - else if(format == GL_RGBA){ + else if(format == GL_RGBA) { _numComp = 4; } - else{ + else { Msg::Error("Unknown pixel format: assuming RGB"); _format = GL_RGB; _numComp = 3; } - - if(type == GL_UNSIGNED_BYTE){ + + if(type == GL_UNSIGNED_BYTE) { _dataSize = sizeof(unsigned char); } - else if(type == GL_FLOAT){ + else if(type == GL_FLOAT) { _dataSize = sizeof(float); } - else{ + else { Msg::Error("Unknown pixel storage type: assuming unsigned byte"); _type = GL_UNSIGNED_BYTE; _dataSize = sizeof(unsigned char); @@ -65,64 +66,65 @@ class PixelBuffer{ _pixels = new unsigned char[n]; for(int i = 0; i < n; i++) _pixels[i] = 0; } - ~PixelBuffer() - { - delete [] _pixels; - } - int getWidth(){ return _width; } - int getHeight(){ return _height; } - int getNumComp(){ return _numComp; } - int getDataSize(){ return _dataSize; } - GLenum getFormat(){ return _format; } - GLenum getType(){ return _type; } - void *getPixels(){ return (void*)_pixels; } + ~PixelBuffer() { delete[] _pixels; } + int getWidth() { return _width; } + int getHeight() { return _height; } + int getNumComp() { return _numComp; } + int getDataSize() { return _dataSize; } + GLenum getFormat() { return _format; } + GLenum getType() { return _type; } + void *getPixels() { return (void *)_pixels; } void copyPixels(int x, int y, PixelBuffer *buffer) { - if(x + buffer->getWidth() > _width || y + buffer->getHeight() > _height){ + if(x + buffer->getWidth() > _width || y + buffer->getHeight() > _height) { Msg::Error("Destination pixel buffer too small for holding copy"); return; } if(buffer->getNumComp() != _numComp || buffer->getDataSize() != _dataSize || - buffer->getFormat() != _format || buffer->getType() != _type){ + buffer->getFormat() != _format || buffer->getType() != _type) { Msg::Error("Pixel buffer type mismatch: impossible to copy"); return; } for(int i = 0; i < buffer->getWidth(); i++) for(int j = 0; j < buffer->getHeight(); j++) memcpy(_pixels + ((j + y) * _width + (i + x)) * _dataSize * _numComp, - (unsigned char*)buffer->getPixels() + (j * buffer->getWidth() + i) * - _dataSize * _numComp, _dataSize * _numComp); + (unsigned char *)buffer->getPixels() + + (j * buffer->getWidth() + i) * _dataSize * _numComp, + _dataSize * _numComp); } void fill(int offscreen) { - if(!offscreen){ + if(!offscreen) { // workaround double buffering issues by redrawing twice drawContext::global()->drawCurrentOpenglWindow(true); drawContext::global()->drawCurrentOpenglWindow(true); glFinish(); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glReadPixels(0, 0, _width, _height, _format, _type, (void*)_pixels); + glReadPixels(0, 0, _width, _height, _format, _type, (void *)_pixels); } - else{ + else { #if defined(HAVE_OSMESA) - if(_format != GL_RGB && _type != GL_UNSIGNED_BYTE){ - Msg::Error("Offscreen rendering only implemented for GL_RGB/GL_UNSIGNED_BYTE"); + if(_format != GL_RGB && _type != GL_UNSIGNED_BYTE) { + Msg::Error( + "Offscreen rendering only implemented for GL_RGB/GL_UNSIGNED_BYTE"); return; } OSMesaContext ctx = OSMesaCreateContextExt(OSMESA_RGB, 16, 0, 0, NULL); - if(!ctx){ + if(!ctx) { Msg::Error("OSMesaCreateContext failed"); return; } - if(!OSMesaMakeCurrent(ctx, (void*)_pixels, GL_UNSIGNED_BYTE, _width, _height)){ + if(!OSMesaMakeCurrent(ctx, (void *)_pixels, GL_UNSIGNED_BYTE, _width, + _height)) { Msg::Error("OSMesaMakeCurrent failed"); } drawContext::global()->drawCurrentOpenglWindow(false); glFinish(); OSMesaDestroyContext(ctx); #else - Msg::Warning("Gmsh must be compiled with OSMesa to support offscreen rendering"); + Msg::Warning( + "Gmsh must be compiled with OSMesa to support offscreen rendering"); #endif } } diff --git a/Graphics/ReadImg.cpp b/Graphics/ReadImg.cpp index 27f55f1685669c14b130606614aefe969facaa27..d102ade3e0458581b040cbcd9e246cb95f4aba7b 100644 --- a/Graphics/ReadImg.cpp +++ b/Graphics/ReadImg.cpp @@ -19,17 +19,17 @@ // from an image, we create a post-procession view -static PViewDataList *Img2Data(Fl_RGB_Image &img_init, int quads=1, - int resizex=0, int resizey=0) +static PViewDataList *Img2Data(Fl_RGB_Image &img_init, int quads = 1, + int resizex = 0, int resizey = 0) { img_init.desaturate(); // convert to grayscale // resize if necessary Fl_RGB_Image *img; if(!resizex || !resizey) - img = (Fl_RGB_Image*)img_init.copy(); + img = (Fl_RGB_Image *)img_init.copy(); else - img = (Fl_RGB_Image*)img_init.copy(resizex, resizey); + img = (Fl_RGB_Image *)img_init.copy(resizex, resizey); const unsigned char *data = img->array; int height = img->h(); @@ -52,31 +52,55 @@ static PViewDataList *Img2Data(Fl_RGB_Image &img_init, int quads=1, for(int j = 0; j < width - 1; j++) { double x = j; double x1 = j + 1; - double val1 = (double)a[j * dim]/255.; - double val2 = (double)a1[j * dim]/255.; - double val3 = (double)a1[(j + 1) * dim]/255.; - double val4 = (double)a[(j + 1) * dim]/255.; - if(quads){ // generate quads - d->SQ.push_back(x); d->SQ.push_back(x); - d->SQ.push_back(x1); d->SQ.push_back(x1); - d->SQ.push_back(y); d->SQ.push_back(y1); - d->SQ.push_back(y1); d->SQ.push_back(y); - d->SQ.push_back(z); d->SQ.push_back(z); - d->SQ.push_back(z); d->SQ.push_back(z); - d->SQ.push_back(val1); d->SQ.push_back(val2); - d->SQ.push_back(val3); d->SQ.push_back(val4); + double val1 = (double)a[j * dim] / 255.; + double val2 = (double)a1[j * dim] / 255.; + double val3 = (double)a1[(j + 1) * dim] / 255.; + double val4 = (double)a[(j + 1) * dim] / 255.; + if(quads) { // generate quads + d->SQ.push_back(x); + d->SQ.push_back(x); + d->SQ.push_back(x1); + d->SQ.push_back(x1); + d->SQ.push_back(y); + d->SQ.push_back(y1); + d->SQ.push_back(y1); + d->SQ.push_back(y); + d->SQ.push_back(z); + d->SQ.push_back(z); + d->SQ.push_back(z); + d->SQ.push_back(z); + d->SQ.push_back(val1); + d->SQ.push_back(val2); + d->SQ.push_back(val3); + d->SQ.push_back(val4); d->NbSQ++; } - else{ // generate triangles - d->ST.push_back(x); d->ST.push_back(x); d->ST.push_back(x1); - d->ST.push_back(y); d->ST.push_back(y1); d->ST.push_back(y1); - d->ST.push_back(z); d->ST.push_back(z); d->ST.push_back(z); - d->ST.push_back(val1); d->ST.push_back(val2); d->ST.push_back(val3); + else { // generate triangles + d->ST.push_back(x); + d->ST.push_back(x); + d->ST.push_back(x1); + d->ST.push_back(y); + d->ST.push_back(y1); + d->ST.push_back(y1); + d->ST.push_back(z); + d->ST.push_back(z); + d->ST.push_back(z); + d->ST.push_back(val1); + d->ST.push_back(val2); + d->ST.push_back(val3); d->NbST++; - d->ST.push_back(x); d->ST.push_back(x1); d->ST.push_back(x1); - d->ST.push_back(y); d->ST.push_back(y1); d->ST.push_back(y); - d->ST.push_back(z); d->ST.push_back(z); d->ST.push_back(z); - d->ST.push_back(val1); d->ST.push_back(val3); d->ST.push_back(val4); + d->ST.push_back(x); + d->ST.push_back(x1); + d->ST.push_back(x1); + d->ST.push_back(y); + d->ST.push_back(y1); + d->ST.push_back(y); + d->ST.push_back(z); + d->ST.push_back(z); + d->ST.push_back(z); + d->ST.push_back(val1); + d->ST.push_back(val3); + d->ST.push_back(val4); d->NbST++; } } @@ -92,9 +116,8 @@ static int EndPos(const char *name, PViewData *d) strcpy(name_pos, name); strcat(name_pos, ".pos"); int i; - for(i = strlen(name) - 1; i >= 0; i--){ - if(name[i] == '/' || name[i] == '\\') - break; + for(i = strlen(name) - 1; i >= 0; i--) { + if(name[i] == '/' || name[i] == '\\') break; } if(i <= 0) strcpy(title, name); @@ -102,11 +125,11 @@ static int EndPos(const char *name, PViewData *d) strcpy(title, &name[i + 1]); d->setName(title); d->setFileName(name_pos); - if(d->finalize()){ + if(d->finalize()) { new PView(d); return 1; } - else{ + else { delete d; return 0; } @@ -138,9 +161,9 @@ int read_bmp(const std::string &fileName) #else -int read_pnm(std::string fileName){ return 0; } -int read_jpeg(std::string fileName){ return 0; } -int read_png(std::string fileName){ return 0; } -int read_bmp(std::string fileName){ return 0; } +int read_pnm(std::string fileName) { return 0; } +int read_jpeg(std::string fileName) { return 0; } +int read_png(std::string fileName) { return 0; } +int read_bmp(std::string fileName) { return 0; } #endif diff --git a/Graphics/drawAxes.cpp b/Graphics/drawAxes.cpp index 031c59d957c5cb1494e502ca4cd800c74651ed28..711a3380f56c3a6511f8df00ce52de0578ba938e 100644 --- a/Graphics/drawAxes.cpp +++ b/Graphics/drawAxes.cpp @@ -14,7 +14,7 @@ #include "Numeric.h" #include "gl2ps.h" -#define SQU(a) ((a)*(a)) +#define SQU(a) ((a) * (a)) static int drawTics(drawContext *ctx, int comp, double n, std::string &format, std::string &label, double p1[3], double p2[3], @@ -32,7 +32,8 @@ static int drawTics(drawContext *ctx, int comp, double n, std::string &format, double w2 = w * 1.25; // distance to labels // draw label at the end of the axis - ctx->drawString(label, p2[0] + t[0] * w2, p2[1] + t[1] * w2, p2[2] + t[2] * w2); + ctx->drawString(label, p2[0] + t[0] * w2, p2[1] + t[1] * w2, + p2[2] + t[2] * w2); // return number of tics in special cases if(n < 2.) return 0; @@ -40,8 +41,8 @@ static int drawTics(drawContext *ctx, int comp, double n, std::string &format, // select perp direction automatically if it is not provided double lp = norme(perp); - if(!lp){ - switch(comp){ + if(!lp) { + switch(comp) { case 0: perp[1] = -1.; break; case 1: perp[0] = -1.; break; case 2: perp[0] = 1.; break; @@ -60,7 +61,7 @@ static int drawTics(drawContext *ctx, int comp, double n, std::string &format, double winl = sqrt(SQU(win2[0] - win1[0]) + SQU(win2[1] - win1[1])); double strl = drawContext::global()->getStringWidth(tmp); if((n - 1) * strl > winl) n = (int)(winl / strl) + 1; - if(n <= 1){ + if(n <= 1) { if(comp < 0) // ruler n = 2; else @@ -71,11 +72,12 @@ static int drawTics(drawContext *ctx, int comp, double n, std::string &format, double step = l / (double)(n - 1); double value_step = value_l / (double)(n - 1); - for(int i = 0; i < n; i++){ + for(int i = 0; i < n; i++) { double d = i * step; double p[3] = {p1[0] + t[0] * d, p1[1] + t[1] * d, p1[2] + t[2] * d}; double q[3] = {p[0] + perp[0] * w, p[1] + perp[1] * w, p[2] + perp[2] * w}; - double r[3] = {p[0] + perp[0] * w2, p[1] + perp[1] * w2, p[2] + perp[2] * w2}; + double r[3] = {p[0] + perp[0] * w2, p[1] + perp[1] * w2, + p[2] + perp[2] * w2}; double value_d = i * value_step; double value_p[3] = {value_p1[0] + value_t[0] * value_d, @@ -110,7 +112,8 @@ static int drawTics(drawContext *ctx, int comp, double n, std::string &format, return n; } -static void drawGridStipple(int n1, int n2, double p1[3], double p2[3], double p3[3]) +static void drawGridStipple(int n1, int n2, double p1[3], double p2[3], + double p3[3]) { double t1[3] = {p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]}; double t2[3] = {p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]}; @@ -122,22 +125,16 @@ static void drawGridStipple(int n1, int n2, double p1[3], double p2[3], double p gl2psEnable(GL2PS_LINE_STIPPLE); glBegin(GL_LINES); - for(int i = 1; i < n1 - 1; i++){ + for(int i = 1; i < n1 - 1; i++) { double d = (double)i / (double)(n1 - 1) * l1; - glVertex3d(p1[0] + t1[0] * d, - p1[1] + t1[1] * d, - p1[2] + t1[2] * d); - glVertex3d(p1[0] + t1[0] * d + t2[0] * l2, - p1[1] + t1[1] * d + t2[1] * l2, + glVertex3d(p1[0] + t1[0] * d, p1[1] + t1[1] * d, p1[2] + t1[2] * d); + glVertex3d(p1[0] + t1[0] * d + t2[0] * l2, p1[1] + t1[1] * d + t2[1] * l2, p1[2] + t1[2] * d + t2[2] * l2); } - for(int i = 1; i < n2 - 1; i++){ - double d = (double)i/(double)(n2 - 1) * l2; - glVertex3d(p1[0] + t2[0] * d, - p1[1] + t2[1] * d, - p1[2] + t2[2] * d); - glVertex3d(p1[0] + t2[0] * d + t1[0] * l1, - p1[1] + t2[1] * d + t1[1] * l1, + for(int i = 1; i < n2 - 1; i++) { + double d = (double)i / (double)(n2 - 1) * l2; + glVertex3d(p1[0] + t2[0] * d, p1[1] + t2[1] * d, p1[2] + t2[2] * d); + glVertex3d(p1[0] + t2[0] * d + t1[0] * l1, p1[1] + t2[1] * d + t1[1] * l1, p1[2] + t2[2] * d + t1[2] * l1); } @@ -146,21 +143,21 @@ static void drawGridStipple(int n1, int n2, double p1[3], double p2[3], double p gl2psDisable(GL2PS_LINE_STIPPLE); } -void drawContext::drawAxis(double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax, - int ntics, int mikado) +void drawContext::drawAxis(double xmin, double ymin, double zmin, double xmax, + double ymax, double zmax, int ntics, int mikado) { - if(mikado){ + if(mikado) { ntics = (ntics - 1) * mikado; if(ntics < 1) ntics = 1; - double dd[3] = {(xmax - xmin) / ntics, - (ymax - ymin) / ntics, + double dd[3] = {(xmax - xmin) / ntics, (ymax - ymin) / ntics, (zmax - zmin) / ntics}; double axe_color[4]; glGetDoublev(GL_CURRENT_COLOR, axe_color); - for(int i = 1; i <= ntics; i++){ - if(i % 2) glColor4dv(axe_color); - else glColor3f(1, 1, 1); + for(int i = 1; i <= ntics; i++) { + if(i % 2) + glColor4dv(axe_color); + else + glColor3f(1, 1, 1); double cx[2] = {xmin + (i - 1) * dd[0], xmin + i * dd[0]}; double cy[2] = {ymin + (i - 1) * dd[1], ymin + i * dd[1]}; double cz[2] = {zmin + (i - 1) * dd[2], zmin + i * dd[2]}; @@ -168,7 +165,7 @@ void drawContext::drawAxis(double xmin, double ymin, double zmin, } glColor4dv(axe_color); } - else{ + else { glBegin(GL_LINES); glVertex3d(xmin, ymin, zmin); glVertex3d(xmax, ymax, zmax); @@ -187,8 +184,7 @@ void drawContext::drawAxes(int mode, double tics[3], std::string format[3], // 4: open grid // 5: ruler - if((mode < 1) || (bb[0] == bb[1] && bb[2] == bb[3] && bb[4] == bb[5])) - return; + if((mode < 1) || (bb[0] == bb[1] && bb[2] == bb[3] && bb[4] == bb[5])) return; double xmin = bb[0], xmax = bb[1]; double ymin = bb[2], ymax = bb[3]; @@ -202,16 +198,20 @@ void drawContext::drawAxes(int mode, double tics[3], std::string format[3], double pixelfact = pixel_equiv_x / s[0]; - if(mode == 5){ // draw ruler from xyz_min to xyz_max + if(mode == 5) { // draw ruler from xyz_min to xyz_max double end[3] = {xmax, ymax, zmax}; double dir[3] = {xmax - xmin, ymax - ymin, zmax - zmin}; double perp[3]; if((fabs(dir[0]) >= fabs(dir[1]) && fabs(dir[0]) >= fabs(dir[2])) || - (fabs(dir[1]) >= fabs(dir[0]) && fabs(dir[1]) >= fabs(dir[2]))){ - perp[0] = dir[1]; perp[1] = -dir[0]; perp[2] = 0.; + (fabs(dir[1]) >= fabs(dir[0]) && fabs(dir[1]) >= fabs(dir[2]))) { + perp[0] = dir[1]; + perp[1] = -dir[0]; + perp[2] = 0.; } - else{ - perp[0] = 0.; perp[1] = dir[2]; perp[2] = -dir[1]; + else { + perp[0] = 0.; + perp[1] = dir[2]; + perp[2] = -dir[1]; } double value_end[3] = {value_xmax, value_ymax, value_zmax}; drawTics(this, -1, tics[0], format[0], label[0], orig, end, perp, mikado, @@ -229,19 +229,25 @@ void drawContext::drawAxes(int mode, double tics[3], std::string format[3], double dym[3] = {(xmin != xmax) ? -1. : 0., 0., (zmin != zmax) ? -1. : 0.}; double dzm[3] = {(xmin != xmax) ? -1. : 0., (ymin != ymax) ? -1. : 0., 0.}; - int nx = (xmin != xmax) ? drawTics(this, 0, tics[0], format[0], label[0], orig, xx, dxm, - mikado, pixelfact, value_orig, value_xx) : 0; - int ny = (ymin != ymax) ? drawTics(this, 1, tics[1], format[1], label[1], orig, yy, dym, - mikado, pixelfact, value_orig, value_yy) : 0; - int nz = (zmin != zmax) ? drawTics(this, 2, tics[2], format[2], label[2], orig, zz, dzm, - mikado, pixelfact, value_orig, value_zz) : 0; + int nx = (xmin != xmax) ? + drawTics(this, 0, tics[0], format[0], label[0], orig, xx, dxm, + mikado, pixelfact, value_orig, value_xx) : + 0; + int ny = (ymin != ymax) ? + drawTics(this, 1, tics[1], format[1], label[1], orig, yy, dym, + mikado, pixelfact, value_orig, value_yy) : + 0; + int nz = (zmin != zmax) ? + drawTics(this, 2, tics[2], format[2], label[2], orig, zz, dzm, + mikado, pixelfact, value_orig, value_zz) : + 0; drawAxis(xmin, ymin, zmin, xmax, ymin, zmin, nx, mikado); drawAxis(xmin, ymin, zmin, xmin, ymax, zmin, ny, mikado); drawAxis(xmin, ymin, zmin, xmin, ymin, zmax, nz, mikado); // open box - if(mode > 1){ + if(mode > 1) { drawAxis(xmin, ymax, zmin, xmax, ymax, zmin, nx, mikado); drawAxis(xmax, ymin, zmin, xmax, ymax, zmin, ny, mikado); drawAxis(xmax, ymin, zmin, xmax, ymin, zmax, nz, mikado); @@ -251,19 +257,19 @@ void drawContext::drawAxes(int mode, double tics[3], std::string format[3], } // closed box - if(mode == 2 || mode == 3){ + if(mode == 2 || mode == 3) { drawAxis(xmin, ymax, zmax, xmax, ymax, zmax, nx, mikado); drawAxis(xmax, ymin, zmax, xmax, ymax, zmax, ny, mikado); drawAxis(xmax, ymax, zmin, xmax, ymax, zmax, nz, mikado); } - if(mode > 2){ + if(mode > 2) { drawGridStipple(nx, ny, orig, xx, yy); drawGridStipple(ny, nz, orig, yy, zz); drawGridStipple(nx, nz, orig, xx, zz); } - if(mode == 3){ + if(mode == 3) { double orig2[3] = {xmax, ymax, zmax}; double xy[3] = {xmax, ymax, zmin}; double yz[3] = {xmin, ymax, zmax}; @@ -278,9 +284,8 @@ void drawContext::drawAxes(int mode, double tics[3], std::string format[3], std::string label[3], SBoundingBox3d &bb, int mikado, SBoundingBox3d &value_bb) { - double bbox[6] = {bb.min().x(), bb.max().x(), - bb.min().y(), bb.max().y(), - bb.min().z(), bb.max().z()}; + double bbox[6] = {bb.min().x(), bb.max().x(), bb.min().y(), + bb.max().y(), bb.min().z(), bb.max().z()}; double value_bbox[6] = {value_bb.min().x(), value_bb.max().x(), value_bb.min().y(), value_bb.max().y(), value_bb.min().z(), value_bb.max().z()}; @@ -290,62 +295,68 @@ void drawContext::drawAxes(int mode, double tics[3], std::string format[3], void drawContext::drawAxes() { bool geometryExists = false; - for(unsigned int i = 0; i < GModel::list.size(); i++){ - if(!GModel::list[i]->empty()){ + for(unsigned int i = 0; i < GModel::list.size(); i++) { + if(!GModel::list[i]->empty()) { geometryExists = true; break; } } - if(geometryExists && (CTX::instance()->drawBBox || !CTX::instance()->mesh.draw)) { - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + if(geometryExists && + (CTX::instance()->drawBBox || !CTX::instance()->mesh.draw)) { + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); glLineWidth((float)CTX::instance()->lineWidth); gl2psLineWidth((float)(CTX::instance()->lineWidth * CTX::instance()->print.epsLineWidthFactor)); - drawBox(CTX::instance()->min[0], CTX::instance()->min[1], CTX::instance()->min[2], - CTX::instance()->max[0], CTX::instance()->max[1], CTX::instance()->max[2]); - glColor3d(1.,0.,0.); + drawBox(CTX::instance()->min[0], CTX::instance()->min[1], + CTX::instance()->min[2], CTX::instance()->max[0], + CTX::instance()->max[1], CTX::instance()->max[2]); + glColor3d(1., 0., 0.); for(int j = 0; j < 6; j++) - if(CTX::instance()->geom.clip & (1 << j) || CTX::instance()->mesh.clip & (1 << j)) - drawPlaneInBoundingBox - (CTX::instance()->min[0], CTX::instance()->min[1], CTX::instance()->min[2], - CTX::instance()->max[0], CTX::instance()->max[1], CTX::instance()->max[2], - CTX::instance()->clipPlane[j][0], CTX::instance()->clipPlane[j][1], - CTX::instance()->clipPlane[j][2], CTX::instance()->clipPlane[j][3]); + if(CTX::instance()->geom.clip & (1 << j) || + CTX::instance()->mesh.clip & (1 << j)) + drawPlaneInBoundingBox( + CTX::instance()->min[0], CTX::instance()->min[1], + CTX::instance()->min[2], CTX::instance()->max[0], + CTX::instance()->max[1], CTX::instance()->max[2], + CTX::instance()->clipPlane[j][0], CTX::instance()->clipPlane[j][1], + CTX::instance()->clipPlane[j][2], CTX::instance()->clipPlane[j][3]); } - if(CTX::instance()->axes){ - glColor4ubv((GLubyte *) & CTX::instance()->color.axes); + if(CTX::instance()->axes) { + glColor4ubv((GLubyte *)&CTX::instance()->color.axes); glLineWidth((float)CTX::instance()->lineWidth); gl2psLineWidth((float)(CTX::instance()->lineWidth * CTX::instance()->print.epsLineWidthFactor)); - if(!CTX::instance()->axesAutoPosition){ + if(!CTX::instance()->axesAutoPosition) { drawAxes(CTX::instance()->axes, CTX::instance()->axesTics, CTX::instance()->axesFormat, CTX::instance()->axesLabel, CTX::instance()->axesPosition, CTX::instance()->axesMikado, CTX::instance()->axesForceValue ? CTX::instance()->axesValue : - CTX::instance()->axesPosition); + CTX::instance()->axesPosition); } - else{ - double bb[6] = - {CTX::instance()->min[0], CTX::instance()->max[0], CTX::instance()->min[1], - CTX::instance()->max[1], CTX::instance()->min[2], CTX::instance()->max[2]}; + else { + double bb[6] = {CTX::instance()->min[0], CTX::instance()->max[0], + CTX::instance()->min[1], CTX::instance()->max[1], + CTX::instance()->min[2], CTX::instance()->max[2]}; drawAxes(CTX::instance()->axes, CTX::instance()->axesTics, - CTX::instance()->axesFormat, CTX::instance()->axesLabel, - bb, CTX::instance()->axesMikado, CTX::instance()->axesForceValue ? - CTX::instance()->axesValue : bb); + CTX::instance()->axesFormat, CTX::instance()->axesLabel, bb, + CTX::instance()->axesMikado, + CTX::instance()->axesForceValue ? CTX::instance()->axesValue : + bb); } } - if(CTX::instance()->drawRotationCenter){ - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + if(CTX::instance()->drawRotationCenter) { + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); if(CTX::instance()->rotationCenterCg) drawSphere(CTX::instance()->pointSize, CTX::instance()->cg[0], CTX::instance()->cg[1], CTX::instance()->cg[2], CTX::instance()->geom.light); else drawSphere(CTX::instance()->pointSize, CTX::instance()->rotationCenter[0], - CTX::instance()->rotationCenter[1], CTX::instance()->rotationCenter[2], + CTX::instance()->rotationCenter[1], + CTX::instance()->rotationCenter[2], CTX::instance()->geom.light); } } @@ -359,14 +370,14 @@ void drawContext::drawSmallAxes() double cy = CTX::instance()->smallAxesPos[1]; fix2dCoordinates(&cx, &cy); - double xx, xy, yx, yy , zx, zy; + double xx, xy, yx, yy, zx, zy; - if (CTX::instance()->camera) { + if(CTX::instance()->camera) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - gluLookAt(camera.position.x,camera.position.y,camera.position.z, - camera.target.x,camera.target.y,camera.target.z, - camera.up.x,camera.up.y,camera.up.z); + gluLookAt(camera.position.x, camera.position.y, camera.position.z, + camera.target.x, camera.target.y, camera.target.z, camera.up.x, + camera.up.y, camera.up.z); glPushMatrix(); glPopMatrix(); float fvViewMatrix[16]; @@ -382,7 +393,7 @@ void drawContext::drawSmallAxes() /// } - else{ + else { xx = l * rot[0]; xy = l * rot[1]; yx = l * rot[4]; @@ -392,8 +403,8 @@ void drawContext::drawSmallAxes() } glLineWidth((float)CTX::instance()->lineWidth); gl2psLineWidth((float)(CTX::instance()->lineWidth * - CTX::instance()->print.epsLineWidthFactor)); - glColor4ubv((GLubyte *) & CTX::instance()->color.smallAxes); + CTX::instance()->print.epsLineWidthFactor)); + glColor4ubv((GLubyte *)&CTX::instance()->color.smallAxes); glBegin(GL_LINES); glVertex2d(cx, cy); diff --git a/Graphics/drawContext.cpp b/Graphics/drawContext.cpp index 8118933b9f23af16c903c020773d26bf021e68e3..e0d6bfe13ef0f22390a1938ccccb8a3e151b8862 100644 --- a/Graphics/drawContext.cpp +++ b/Graphics/drawContext.cpp @@ -33,7 +33,7 @@ #endif drawContextGlobal *drawContext::_global = 0; -void (*drawContext::drawGeomTransient)(void*) = 0; +void (*drawContext::drawGeomTransient)(void *) = 0; void drawContext::setDrawGeomTransientFunction(void (*fct)(void *)) { @@ -46,12 +46,12 @@ drawContext::drawContext(openglWindow *window, drawTransform *transform) : _transform(transform), _openglWindow(window) { // initialize from temp values in global context - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { r[i] = CTX::instance()->tmpRotation[i]; t[i] = CTX::instance()->tmpTranslation[i]; s[i] = CTX::instance()->tmpScale[i]; } - for(int i = 0; i < 4; i++){ + for(int i = 0; i < 4; i++) { quaternion[i] = CTX::instance()->tmpQuaternion[i]; } viewport[0] = viewport[1] = 0; @@ -68,15 +68,12 @@ drawContext::drawContext(openglWindow *window, drawTransform *transform) _displayLists = 0; } -drawContext::~drawContext() -{ - invalidateQuadricsAndDisplayLists(); -} +drawContext::~drawContext() { invalidateQuadricsAndDisplayLists(); } bool drawContext::isHighResolution() { - // this must be dynamic: the high resolution can change when a window is moved - // across displays +// this must be dynamic: the high resolution can change when a window is moved +// across displays #if defined(HAVE_FLTK) if(_openglWindow) return _openglWindow->pixel_w() > _openglWindow->w(); #endif @@ -91,28 +88,33 @@ drawContextGlobal *drawContext::global() void drawContext::invalidateQuadricsAndDisplayLists() { - if(_quadric){ gluDeleteQuadric(_quadric); _quadric = 0; } - if(_displayLists){ glDeleteLists(_displayLists, 3); _displayLists = 0; } + if(_quadric) { + gluDeleteQuadric(_quadric); + _quadric = 0; + } + if(_displayLists) { + glDeleteLists(_displayLists, 3); + _displayLists = 0; + } } void drawContext::createQuadricsAndDisplayLists() { if(!_quadric) _quadric = gluNewQuadric(); - if(!_quadric){ + if(!_quadric) { Msg::Error("Could not create quadric"); return; } if(!_displayLists) _displayLists = glGenLists(3); - if(!_displayLists){ + if(!_displayLists) { Msg::Error("Could not generate display lists"); return; } // display list 0 (sphere) glNewList(_displayLists + 0, GL_COMPILE); - gluSphere(_quadric, 1., - CTX::instance()->quadricSubdivisions, + gluSphere(_quadric, 1., CTX::instance()->quadricSubdivisions, CTX::instance()->quadricSubdivisions); glEndList(); @@ -134,7 +136,7 @@ void drawContext::createQuadricsAndDisplayLists() CTX::instance()->quadricSubdivisions, 1); glTranslated(0., 0., -CTX::instance()->arrowRelStemLength); if(CTX::instance()->arrowRelStemRadius > 0 && - CTX::instance()->arrowRelStemLength > 0){ + CTX::instance()->arrowRelStemLength > 0) { gluCylinder(_quadric, CTX::instance()->arrowRelStemRadius, CTX::instance()->arrowRelStemRadius, CTX::instance()->arrowRelStemLength, @@ -168,10 +170,22 @@ void drawContext::buildRotationMatrix() double F = sin(z); double AD = A * D; double BD = B * D; - rot[0] = C*E; rot[1] = BD*E+A*F; rot[2] =-AD*E+B*F; rot[3] = 0.; - rot[4] =-C*F; rot[5] =-BD*F+A*E; rot[6] = AD*F+B*E; rot[7] = 0.; - rot[8] = D; rot[9] =-B*C; rot[10] = A*C; rot[11] = 0.; - rot[12] = 0.; rot[13] = 0.; rot[14] = 0.; rot[15] = 1.; + rot[0] = C * E; + rot[1] = BD * E + A * F; + rot[2] = -AD * E + B * F; + rot[3] = 0.; + rot[4] = -C * F; + rot[5] = -BD * F + A * E; + rot[6] = AD * F + B * E; + rot[7] = 0.; + rot[8] = D; + rot[9] = -B * C; + rot[10] = A * C; + rot[11] = 0.; + rot[12] = 0.; + rot[13] = 0.; + rot[14] = 0.; + rot[15] = 1.; setQuaternionFromEulerAngles(); } } @@ -181,7 +195,7 @@ void drawContext::addQuaternion(double p1x, double p1y, double p2x, double p2y) double quat[4]; trackball(quat, p1x, p1y, p2x, p2y); add_quats(quat, quaternion, quaternion); - if (CTX::instance()->camera) camera.rotate(quat); + if(CTX::instance()->camera) camera.rotate(quat); } void drawContext::addQuaternionFromAxisAndAngle(double axis[3], double angle) @@ -205,9 +219,9 @@ void drawContext::setQuaternionFromEulerAngles() double x = r[0] * M_PI / 180.; double y = r[1] * M_PI / 180.; double z = r[2] * M_PI / 180.; - double xx[3] = {1.,0.,0.}; - double yy[3] = {0.,1.,0.}; - double zz[3] = {0.,0.,1.}; + double xx[3] = {1., 0., 0.}; + double yy[3] = {0., 1., 0.}; + double zz[3] = {0., 0., 1.}; double q1[4], q2[4], q3[4], tmp[4]; axis_to_quat(xx, -x, q1); axis_to_quat(yy, -y, q2); @@ -219,17 +233,17 @@ void drawContext::setQuaternionFromEulerAngles() void drawContext::setEulerAnglesFromRotationMatrix() { r[1] = asin(rot[8]); // Calculate Y-axis angle - double C = cos(r[1]); + double C = cos(r[1]); r[1] *= 180. / M_PI; - if(fabs(C) > 0.005){ // Gimball lock? - double tmpx = rot[10] / C; // No, so get X-axis angle + if(fabs(C) > 0.005) { // Gimball lock? + double tmpx = rot[10] / C; // No, so get X-axis angle double tmpy = -rot[9] / C; r[0] = atan2(tmpy, tmpx) * 180. / M_PI; - tmpx = rot[0] / C; // Get Z-axis angle + tmpx = rot[0] / C; // Get Z-axis angle tmpy = -rot[4] / C; r[2] = atan2(tmpy, tmpx) * 180. / M_PI; } - else{ // Gimball lock has occurred + else { // Gimball lock has occurred r[0] = 0.; // Set X-axis angle to zero double tmpx = rot[5]; // And calculate Z-axis angle double tmpy = rot[1]; @@ -248,10 +262,10 @@ static int needPolygonOffset() (CTX::instance()->mesh.surfacesEdges || CTX::instance()->geom.curves || CTX::instance()->geom.surfaces)) return 1; - if(m->getMeshStatus() == 3 && - (CTX::instance()->mesh.surfacesEdges || CTX::instance()->mesh.volumesEdges)) + if(m->getMeshStatus() == 3 && (CTX::instance()->mesh.surfacesEdges || + CTX::instance()->mesh.volumesEdges)) return 1; - for(unsigned int i = 0; i < PView::list.size(); i++){ + for(unsigned int i = 0; i < PView::list.size(); i++) { PViewOptions *opt = PView::list[i]->getOptions(); if(opt->visible && opt->showElement) return 1; } @@ -276,13 +290,14 @@ void drawContext::draw3d() // given implementation. glPolygonOffset((float)CTX::instance()->polygonOffsetFactor, (float)CTX::instance()->polygonOffsetUnits); - if(CTX::instance()->polygonOffsetFactor || CTX::instance()->polygonOffsetUnits) - CTX::instance()->polygonOffset = CTX::instance()->polygonOffsetAlways ? 1 : - needPolygonOffset(); + if(CTX::instance()->polygonOffsetFactor || + CTX::instance()->polygonOffsetUnits) + CTX::instance()->polygonOffset = + CTX::instance()->polygonOffsetAlways ? 1 : needPolygonOffset(); else CTX::instance()->polygonOffset = 0; - // speedup drawing of textured fonts on cocoa mac version + // speedup drawing of textured fonts on cocoa mac version #if defined(HAVE_FLTK) && defined(__APPLE__) int numStrings = GModel::current()->getNumVertices(); if(CTX::instance()->mesh.pointsNum) @@ -291,8 +306,7 @@ void drawContext::draw3d() CTX::instance()->mesh.volumesNum) numStrings = std::max(numStrings, GModel::current()->getNumMeshElements()); numStrings *= 2; - if(gl_texture_pile_height() < numStrings) - gl_texture_pile_height(numStrings); + if(gl_texture_pile_height() < numStrings) gl_texture_pile_height(numStrings); #endif glDepthFunc(GL_LESS); @@ -306,71 +320,70 @@ void drawContext::draw3d() drawBackgroundImage(true); drawMesh(); drawPost(); - //drawAxes(); + // drawAxes(); drawGraph2d(true); } void drawContext::draw2d() { glDisable(GL_DEPTH_TEST); - for(int i = 0; i < 6; i++) - glDisable((GLenum)(GL_CLIP_PLANE0 + i)); + for(int i = 0; i < 6; i++) glDisable((GLenum)(GL_CLIP_PLANE0 + i)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho((double)viewport[0], (double)viewport[2], - (double)viewport[1], (double)viewport[3], - -100., 100.); // in pixels, so we can draw some 3D glyphs + glOrtho((double)viewport[0], (double)viewport[2], (double)viewport[1], + (double)viewport[3], -100., + 100.); // in pixels, so we can draw some 3D glyphs // hack to make the 2D primitives appear "in front" in GL2PS - glTranslated(0., 0., CTX::instance()->clipFactor > 1. ? - 1. / CTX::instance()->clipFactor : CTX::instance()->clipFactor); + glTranslated(0., 0., + CTX::instance()->clipFactor > 1. ? + 1. / CTX::instance()->clipFactor : + CTX::instance()->clipFactor); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); drawGraph2d(false); drawText2d(); - if(CTX::instance()->post.draw && !CTX::instance()->stereo) - drawScales(); - if(CTX::instance()->smallAxes) - drawSmallAxes(); + if(CTX::instance()->post.draw && !CTX::instance()->stereo) drawScales(); + if(CTX::instance()->smallAxes) drawSmallAxes(); } void drawContext::drawBackgroundGradient() { - if(CTX::instance()->bgGradient == 1){ // vertical + if(CTX::instance()->bgGradient == 1) { // vertical glBegin(GL_QUADS); - glColor4ubv((GLubyte *) & CTX::instance()->color.bg); + glColor4ubv((GLubyte *)&CTX::instance()->color.bg); glVertex2i(viewport[0], viewport[1]); glVertex2i(viewport[2], viewport[1]); - glColor4ubv((GLubyte *) & CTX::instance()->color.bgGrad); + glColor4ubv((GLubyte *)&CTX::instance()->color.bgGrad); glVertex2i(viewport[2], viewport[3]); glVertex2i(viewport[0], viewport[3]); glEnd(); } - else if(CTX::instance()->bgGradient == 2){ // horizontal + else if(CTX::instance()->bgGradient == 2) { // horizontal glBegin(GL_QUADS); - glColor4ubv((GLubyte *) & CTX::instance()->color.bg); + glColor4ubv((GLubyte *)&CTX::instance()->color.bg); glVertex2i(viewport[2], viewport[1]); glVertex2i(viewport[2], viewport[3]); - glColor4ubv((GLubyte *) & CTX::instance()->color.bgGrad); + glColor4ubv((GLubyte *)&CTX::instance()->color.bgGrad); glVertex2i(viewport[0], viewport[3]); glVertex2i(viewport[0], viewport[1]); glEnd(); } - else if(CTX::instance()->bgGradient == 3){ // radial + else if(CTX::instance()->bgGradient == 3) { // radial double cx = 0.5 * (viewport[0] + viewport[2]); double cy = 0.5 * (viewport[1] + viewport[3]); - double r = 0.5 * std::max(viewport[2] - viewport[0], - viewport[3] - viewport[1]); + double r = + 0.5 * std::max(viewport[2] - viewport[0], viewport[3] - viewport[1]); glBegin(GL_TRIANGLE_FAN); - glColor4ubv((GLubyte *) & CTX::instance()->color.bgGrad); + glColor4ubv((GLubyte *)&CTX::instance()->color.bgGrad); glVertex2d(cx, cy); - glColor4ubv((GLubyte *) & CTX::instance()->color.bg); + glColor4ubv((GLubyte *)&CTX::instance()->color.bg); glVertex2d(cx + r, cy); int ntheta = 36; - for(int i = 1; i < ntheta + 1; i ++){ + for(int i = 1; i < ntheta + 1; i++) { double theta = i * 2 * M_PI / (double)ntheta; glVertex2d(cx + r * cos(theta), cy + r * sin(theta)); } @@ -388,16 +401,16 @@ bool drawContext::generateTextureForImage(const std::string &name, int page, GLuint &imageTexture, GLuint &imageW, GLuint &imageH) { - if(StatFile(name)){ + if(StatFile(name)) { Msg::Warning("Could not open file `%s'", name.c_str()); return false; } std::string ext = SplitFileName(name)[2]; - if(ext == ".pdf" || ext == ".PDF"){ + if(ext == ".pdf" || ext == ".PDF") { #if defined(HAVE_POPPLER) - if(!imageTexture){ - if(!gmshPopplerWrapper::instance()->loadFromFile(name)){ + if(!imageTexture) { + if(!gmshPopplerWrapper::instance()->loadFromFile(name)) { Msg::Error("Could not load PDF file '%s'", name.c_str()); return false; } @@ -411,27 +424,27 @@ bool drawContext::generateTextureForImage(const std::string &name, int page, return false; #endif } - else{ + else { #if defined(HAVE_FLTK) - if(!imageTexture){ + if(!imageTexture) { Fl_RGB_Image *img = 0; if(ext == ".jpg" || ext == ".JPG" || ext == ".jpeg" || ext == ".JPEG") img = new Fl_JPEG_Image(name.c_str()); else if(ext == ".png" || ext == ".PNG") img = new Fl_PNG_Image(name.c_str()); - if(!img){ + if(!img) { Msg::Error("Could not load background image '%s'", name.c_str()); return false; } - Fl_RGB_Image *img2 = (Fl_RGB_Image*)img->copy(2048, 2048); + Fl_RGB_Image *img2 = (Fl_RGB_Image *)img->copy(2048, 2048); glPixelStorei(GL_UNPACK_ROW_LENGTH, img2->w()); glGenTextures(1, &imageTexture); glBindTexture(GL_TEXTURE_2D, imageTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img2->w(), img2->h(), 0, - (img2->d() == 4) ? GL_RGBA : GL_RGB, - GL_UNSIGNED_BYTE, img2->array); + (img2->d() == 4) ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, + img2->array); imageW = img->w(); imageH = img->h(); delete img; @@ -449,7 +462,8 @@ void drawContext::drawBackgroundImage(bool threeD) { if(CTX::instance()->bgImageFileName.empty() || (CTX::instance()->bgImage3d && !threeD) || - (!CTX::instance()->bgImage3d && threeD)) return; + (!CTX::instance()->bgImage3d && threeD)) + return; std::string name = FixRelativePath(GModel::current()->getFileName(), CTX::instance()->bgImageFileName); @@ -460,39 +474,39 @@ void drawContext::drawBackgroundImage(bool threeD) double h = CTX::instance()->bgImageSize[1]; if(!generateTextureForImage(name, CTX::instance()->bgImagePage, - _bgImageTexture, _bgImageW, _bgImageH)){ + _bgImageTexture, _bgImageW, _bgImageH)) { CTX::instance()->bgImageFileName.clear(); return; } if(!_bgImageTexture) return; - if(w < 0 && h < 0){ + if(w < 0 && h < 0) { w = viewport[2] - viewport[0]; h = viewport[3] - viewport[1]; } - else if(w < 0 && h == 0){ + else if(w < 0 && h == 0) { w = viewport[2] - viewport[0]; h = w * _bgImageH / _bgImageW; } - else if(w < 0){ + else if(w < 0) { w = viewport[2] - viewport[0]; } - else if(w == 0 && h < 0){ + else if(w == 0 && h < 0) { h = viewport[3] - viewport[1]; w = h * _bgImageW / _bgImageH; } - else if(h < 0){ + else if(h < 0) { h = viewport[3] - viewport[1]; } - else if(w == 0 && h == 0){ + else if(w == 0 && h == 0) { w = _bgImageW; h = _bgImageH; } - else if(h == 0){ + else if(h == 0) { h = w * _bgImageH / _bgImageW; } - else if(w == 0){ + else if(w == 0) { w = h * _bgImageW / _bgImageH; } @@ -504,22 +518,30 @@ void drawContext::drawBackgroundImage(bool threeD) glBindTexture(GL_TEXTURE_2D, _bgImageTexture); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin(GL_QUADS); - if(threeD){ - glTexCoord2f(1.0f, 1.0f); glVertex2d(x+w, y); - glTexCoord2f(1.0f, 0.0f); glVertex2d(x+w, y+h); - glTexCoord2f(0.0f, 0.0f); glVertex2d(x, y+h); - glTexCoord2f(0.0f, 1.0f); glVertex2d(x, y); + if(threeD) { + glTexCoord2f(1.0f, 1.0f); + glVertex2d(x + w, y); + glTexCoord2f(1.0f, 0.0f); + glVertex2d(x + w, y + h); + glTexCoord2f(0.0f, 0.0f); + glVertex2d(x, y + h); + glTexCoord2f(0.0f, 1.0f); + glVertex2d(x, y); } - else{ + else { int c = fix2dCoordinates(&x, &y); // y=0 now means top if(c & 1) x -= w / 2.; if(c & 2) y += h / 2.; if(x < viewport[0]) x = viewport[0]; if(y < viewport[1]) y = viewport[1]; - glTexCoord2f(1.0f, 1.0f); glVertex2d(x+w, y-h); - glTexCoord2f(1.0f, 0.0f); glVertex2d(x+w, y); - glTexCoord2f(0.0f, 0.0f); glVertex2d(x, y); - glTexCoord2f(0.0f, 1.0f); glVertex2d(x, y-h); + glTexCoord2f(1.0f, 1.0f); + glVertex2d(x + w, y - h); + glTexCoord2f(1.0f, 0.0f); + glVertex2d(x + w, y); + glTexCoord2f(0.0f, 0.0f); + glVertex2d(x, y); + glTexCoord2f(0.0f, 1.0f); + glVertex2d(x, y - h); } glEnd(); glDisable(GL_TEXTURE_2D); @@ -529,25 +551,24 @@ void drawContext::drawBackgroundImage(bool threeD) void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick) { double Va = - (double) (viewport[3] - viewport[1]) / - (double) (viewport[2] - viewport[0]); + (double)(viewport[3] - viewport[1]) / (double)(viewport[2] - viewport[0]); double Wa = (CTX::instance()->max[1] - CTX::instance()->min[1]) / - (CTX::instance()->max[0] - CTX::instance()->min[0]); + (CTX::instance()->max[0] - CTX::instance()->min[0]); // compute the viewport in World coordinates (with margins) if(Va > Wa) { vxmin = CTX::instance()->min[0]; vxmax = CTX::instance()->max[0]; vymin = 0.5 * (CTX::instance()->min[1] + CTX::instance()->max[1] - - Va * (CTX::instance()->max[0] - CTX::instance()->min[0])); + Va * (CTX::instance()->max[0] - CTX::instance()->min[0])); vymax = 0.5 * (CTX::instance()->min[1] + CTX::instance()->max[1] + - Va * (CTX::instance()->max[0] - CTX::instance()->min[0])); + Va * (CTX::instance()->max[0] - CTX::instance()->min[0])); } else { vxmin = 0.5 * (CTX::instance()->min[0] + CTX::instance()->max[0] - - (CTX::instance()->max[1] - CTX::instance()->min[1]) / Va); + (CTX::instance()->max[1] - CTX::instance()->min[1]) / Va); vxmax = 0.5 * (CTX::instance()->min[0] + CTX::instance()->max[0] + - (CTX::instance()->max[1] - CTX::instance()->min[1]) / Va); + (CTX::instance()->max[1] - CTX::instance()->min[1]) / Va); vymin = CTX::instance()->min[1]; vymax = CTX::instance()->max[1]; } @@ -576,11 +597,11 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick) // set up the near and far clipping planes so that the box is large enough to // manipulate the model and zoom, but not too big (otherwise the z-buffer // resolution e.g. with Mesa can become insufficient) - double zmax = std::max(fabs(CTX::instance()->min[2]), - fabs(CTX::instance()->max[2])); + double zmax = + std::max(fabs(CTX::instance()->min[2]), fabs(CTX::instance()->max[2])); if(zmax < CTX::instance()->lc) zmax = CTX::instance()->lc; - if (CTX::instance()->camera) { // if we use the camera mode + if(CTX::instance()->camera) { // if we use the camera mode glDisable(GL_DEPTH_TEST); glPushMatrix(); glLoadIdentity(); @@ -591,17 +612,17 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick) double dy = 1.5 * tan(camera.radians) * w; double dz = -w * 1.25; glBegin(GL_QUADS); - glColor4ubv((GLubyte *) & CTX::instance()->color.bg); + glColor4ubv((GLubyte *)&CTX::instance()->color.bg); glVertex3i((int)-dx, (int)-dy, (int)dz); - glVertex3i((int) dx, (int)-dy, (int)dz); - glColor4ubv((GLubyte *) & CTX::instance()->color.bgGrad); - glVertex3i((int) dx, (int)dy, (int)dz); + glVertex3i((int)dx, (int)-dy, (int)dz); + glColor4ubv((GLubyte *)&CTX::instance()->color.bgGrad); + glVertex3i((int)dx, (int)dy, (int)dz); glVertex3i((int)-dx, (int)dy, (int)dz); glEnd(); glPopMatrix(); glEnable(GL_DEPTH_TEST); } - else if(!CTX::instance()->camera){ // if not in camera mode + else if(!CTX::instance()->camera) { // if not in camera mode double clip_near, clip_far; if(CTX::instance()->ortho) { @@ -619,21 +640,21 @@ void drawContext::initProjection(int xpick, int ypick, int wpick, int hpick) // restrict picking to a rectangular region around xpick,ypick if(render_mode == GMSH_SELECT) gluPickMatrix((GLdouble)xpick, (GLdouble)(viewport[3] - ypick), - (GLdouble)wpick, (GLdouble)hpick, (GLint *)viewport); + (GLdouble)wpick, (GLdouble)hpick, (GLint *)viewport); // draw background if not in selection mode if(render_mode != GMSH_SELECT && - (CTX::instance()->bgGradient || CTX::instance()->bgImageFileName.size()) && - (!CTX::instance()->printing || CTX::instance()->print.background)){ + (CTX::instance()->bgGradient || + CTX::instance()->bgImageFileName.size()) && + (!CTX::instance()->printing || CTX::instance()->print.background)) { glDisable(GL_DEPTH_TEST); glPushMatrix(); glLoadIdentity(); // the z values and the translation are only needed for GL2PS, which does // not understand "no depth test" (hence we must make sure that we draw // the background behind the rest of the scene) - glOrtho((double)viewport[0], (double)viewport[2], - (double)viewport[1], (double)viewport[3], - clip_near, clip_far); + glOrtho((double)viewport[0], (double)viewport[2], (double)viewport[1], + (double)viewport[3], clip_near, clip_far); glTranslated(0., 0., -0.99 * clip_far); drawBackgroundGradient(); // hack for GL2PS (to make sure that the image is in front of the @@ -684,36 +705,45 @@ void drawContext::initRenderModel() (GLfloat)CTX::instance()->lightPosition[i][3]}; glLightfv((GLenum)(GL_LIGHT0 + i), GL_POSITION, position); - GLfloat r = (GLfloat)(CTX::instance()->unpackRed - (CTX::instance()->color.ambientLight[i]) / 255.); - GLfloat g = (GLfloat)(CTX::instance()->unpackGreen - (CTX::instance()->color.ambientLight[i]) / 255.); - GLfloat b = (GLfloat)(CTX::instance()->unpackBlue - (CTX::instance()->color.ambientLight[i]) / 255.); + GLfloat r = (GLfloat)( + CTX::instance()->unpackRed(CTX::instance()->color.ambientLight[i]) / + 255.); + GLfloat g = (GLfloat)( + CTX::instance()->unpackGreen(CTX::instance()->color.ambientLight[i]) / + 255.); + GLfloat b = (GLfloat)( + CTX::instance()->unpackBlue(CTX::instance()->color.ambientLight[i]) / + 255.); GLfloat ambient[4] = {r, g, b, 1.0F}; glLightfv((GLenum)(GL_LIGHT0 + i), GL_AMBIENT, ambient); - r = (GLfloat)(CTX::instance()->unpackRed - (CTX::instance()->color.diffuseLight[i]) / 255.); - g = (GLfloat)(CTX::instance()->unpackGreen - (CTX::instance()->color.diffuseLight[i]) / 255.); - b = (GLfloat)(CTX::instance()->unpackBlue - (CTX::instance()->color.diffuseLight[i]) / 255.); + r = (GLfloat)( + CTX::instance()->unpackRed(CTX::instance()->color.diffuseLight[i]) / + 255.); + g = (GLfloat)( + CTX::instance()->unpackGreen(CTX::instance()->color.diffuseLight[i]) / + 255.); + b = (GLfloat)( + CTX::instance()->unpackBlue(CTX::instance()->color.diffuseLight[i]) / + 255.); GLfloat diffuse[4] = {r, g, b, 1.0F}; glLightfv((GLenum)(GL_LIGHT0 + i), GL_DIFFUSE, diffuse); - r = (GLfloat)(CTX::instance()->unpackRed - (CTX::instance()->color.specularLight[i]) / 255.); - g = (GLfloat)(CTX::instance()->unpackGreen - (CTX::instance()->color.specularLight[i]) / 255.); - b = (GLfloat)(CTX::instance()->unpackBlue - (CTX::instance()->color.specularLight[i]) / 255.); + r = (GLfloat)( + CTX::instance()->unpackRed(CTX::instance()->color.specularLight[i]) / + 255.); + g = (GLfloat)( + CTX::instance()->unpackGreen(CTX::instance()->color.specularLight[i]) / + 255.); + b = (GLfloat)( + CTX::instance()->unpackBlue(CTX::instance()->color.specularLight[i]) / + 255.); GLfloat specular[4] = {r, g, b, 1.0F}; glLightfv((GLenum)(GL_LIGHT0 + i), GL_SPECULAR, specular); glEnable((GLenum)(GL_LIGHT0 + i)); } - else{ + else { glDisable((GLenum)(GL_LIGHT0 + i)); } } @@ -755,12 +785,10 @@ void drawContext::initPosition(bool saveMatrices) // NB: Those operations are applied to the model in the view coordinates // (in opposite order) glScaled(s[0], s[1], s[2]); - glTranslated(t[0]-CTX::instance()->cg[0], - t[1]-CTX::instance()->cg[1], - t[2]-CTX::instance()->cg[2]); + glTranslated(t[0] - CTX::instance()->cg[0], t[1] - CTX::instance()->cg[1], + t[2] - CTX::instance()->cg[2]); if(CTX::instance()->rotationCenterCg) - glTranslated(CTX::instance()->cg[0], - CTX::instance()->cg[1], + glTranslated(CTX::instance()->cg[0], CTX::instance()->cg[1], CTX::instance()->cg[2]); else glTranslated(CTX::instance()->rotationCenter[0], @@ -771,8 +799,7 @@ void drawContext::initPosition(bool saveMatrices) glMultMatrixd(rot); if(CTX::instance()->rotationCenterCg) - glTranslated(-CTX::instance()->cg[0], - -CTX::instance()->cg[1], + glTranslated(-CTX::instance()->cg[0], -CTX::instance()->cg[1], -CTX::instance()->cg[2]); else glTranslated(-CTX::instance()->rotationCenter[0], @@ -782,7 +809,7 @@ void drawContext::initPosition(bool saveMatrices) // store the projection and modelview matrices at this precise moment (so that // we can use them at any later time, even if the context has changed, i.e., // even if we are out of draw()) - if (saveMatrices) { + if(saveMatrices) { glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); } @@ -796,7 +823,7 @@ void drawContext::initPosition(bool saveMatrices) // cursor position void drawContext::unproject(double winx, double winy, double p[3], double d[3]) { - if(isHighResolution()){ + if(isHighResolution()) { winx *= 2; // true pixels winy *= 2; } @@ -835,7 +862,8 @@ void drawContext::viewport2World(double vp[3], double xyz[3]) glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); - gluUnProject(vp[0], vp[1], vp[2], model, proj, viewport, &xyz[0], &xyz[1], &xyz[2]); + gluUnProject(vp[0], vp[1], vp[2], model, proj, viewport, &xyz[0], &xyz[1], + &xyz[2]); } void drawContext::world2Viewport(double xyz[3], double vp[3]) @@ -845,18 +873,21 @@ void drawContext::world2Viewport(double xyz[3], double vp[3]) glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); - gluProject(xyz[0], xyz[1], xyz[2], model, proj, viewport, &vp[0], &vp[1], &vp[2]); + gluProject(xyz[0], xyz[1], xyz[2], model, proj, viewport, &vp[0], &vp[1], + &vp[2]); } -class hit{ - public: +class hit { +public: GLuint type, ient, depth, type2, ient2; - hit(GLuint t, GLuint i, GLuint d, GLuint t2=0, GLuint i2=0) - : type(t), ient(i), depth(d), type2(t2), ient2(i2) {} + hit(GLuint t, GLuint i, GLuint d, GLuint t2 = 0, GLuint i2 = 0) + : type(t), ient(i), depth(d), type2(t2), ient2(i2) + { + } }; -class hitDepthLessThan{ - public: +class hitDepthLessThan { +public: bool operator()(const hit &h1, const hit &h2) const { return h1.depth < h2.depth; @@ -867,7 +898,7 @@ class hitDepthLessThan{ // are not always stored: returning 0 is not an error) static MElement *getElement(GEntity *e, int va_type, int index) { - switch(va_type){ + switch(va_type) { case 2: if(e->va_lines && index < e->va_lines->getNumElementPointers()) return *e->va_lines->getElementPointerArray(index); @@ -880,15 +911,14 @@ static MElement *getElement(GEntity *e, int va_type, int index) return 0; } -bool drawContext::select(int type, bool multiple, bool mesh, bool post, - int x, int y, int w, int h, - std::vector<GVertex*> &vertices, - std::vector<GEdge*> &edges, - std::vector<GFace*> &faces, - std::vector<GRegion*> ®ions, - std::vector<MElement*> &elements, +bool drawContext::select(int type, bool multiple, bool mesh, bool post, int x, + int y, int w, int h, std::vector<GVertex *> &vertices, + std::vector<GEdge *> &edges, + std::vector<GFace *> &faces, + std::vector<GRegion *> ®ions, + std::vector<MElement *> &elements, std::vector<SPoint2> &points, - std::vector<PView*> &views) + std::vector<PView *> &views) { vertices.clear(); edges.clear(); @@ -901,10 +931,12 @@ bool drawContext::select(int type, bool multiple, bool mesh, bool post, // in our case the selection buffer size is equal to between 5 and 7 times the // maximum number of possible hits GModel *m = GModel::current(); - int eles = (mesh && CTX::instance()->pickElements) ? 4 * m->getNumMeshElements() : 0; + int eles = + (mesh && CTX::instance()->pickElements) ? 4 * m->getNumMeshElements() : 0; int nviews = PView::list.size() * 100; int size = 7 * (m->getNumVertices() + m->getNumEdges() + m->getNumFaces() + - m->getNumRegions() + eles) + nviews; + m->getNumRegions() + eles) + + nviews; if(!size) return false; // the model is empty, don't bother! // allocate selection buffer @@ -929,11 +961,11 @@ bool drawContext::select(int type, bool multiple, bool mesh, bool post, // 2d stuff glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), - (GLdouble)w, (GLdouble)h, (GLint *)viewport); - glOrtho((double)viewport[0], (double)viewport[2], - (double)viewport[1], (double)viewport[3], - -100., 100.); // in pixels, so we can draw some 3D glyphs + gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), (GLdouble)w, + (GLdouble)h, (GLint *)viewport); + glOrtho((double)viewport[0], (double)viewport[2], (double)viewport[1], + (double)viewport[3], -100., + 100.); // in pixels, so we can draw some 3D glyphs glMatrixMode(GL_MODELVIEW); glLoadIdentity(); drawGraph2d(false); @@ -944,12 +976,12 @@ bool drawContext::select(int type, bool multiple, bool mesh, bool post, GLint numhits = glRenderMode(GL_RENDER); render_mode = drawContext::GMSH_RENDER; - if(!numhits){ // no hits - delete [] selectionBuffer; + if(!numhits) { // no hits + delete[] selectionBuffer; return false; } - else if(numhits < 0){ // overflow - delete [] selectionBuffer; + else if(numhits < 0) { // overflow + delete[] selectionBuffer; Msg::Warning("Too many entities selected"); return false; } @@ -970,14 +1002,16 @@ bool drawContext::select(int type, bool multiple, bool mesh, bool post, GLuint names = *ptr++; GLuint mindepth = *ptr++; GLuint maxdepth = *ptr++; - if(names == 2){ - GLuint depth = maxdepth + 0 * mindepth; // could do something with mindepth + if(names == 2) { + GLuint depth = + maxdepth + 0 * mindepth; // could do something with mindepth GLuint type = *ptr++; GLuint ient = *ptr++; hits.push_back(hit(type, ient, depth)); } - else if(names == 4){ - GLuint depth = maxdepth + 0 * mindepth; // could do something with mindepth + else if(names == 4) { + GLuint depth = + maxdepth + 0 * mindepth; // could do something with mindepth GLuint type = *ptr++; GLuint ient = *ptr++; GLuint type2 = *ptr++; @@ -986,9 +1020,9 @@ bool drawContext::select(int type, bool multiple, bool mesh, bool post, } } - delete [] selectionBuffer; + delete[] selectionBuffer; - if(!hits.size()){ // no entities + if(!hits.size()) { // no entities return false; } @@ -1003,85 +1037,72 @@ bool drawContext::select(int type, bool multiple, bool mesh, bool post, typmin = std::min(typmin, hits[i].type); for(unsigned int i = 0; i < hits.size(); i++) { - if((type == ENT_ALL) || - (type == ENT_NONE && hits[i].type == typmin) || + if((type == ENT_ALL) || (type == ENT_NONE && hits[i].type == typmin) || (type == ENT_POINT && hits[i].type == 0) || (type == ENT_CURVE && hits[i].type == 1) || (type == ENT_SURFACE && hits[i].type == 2) || - (type == ENT_VOLUME && hits[i].type == 3)){ - switch (hits[i].type) { - case 0: - { - GVertex *v = m->getVertexByTag(hits[i].ient); - if(!v){ - Msg::Error("Problem in point selection processing"); - return false; - } - vertices.push_back(v); - if(!multiple) return true; + (type == ENT_VOLUME && hits[i].type == 3)) { + switch(hits[i].type) { + case 0: { + GVertex *v = m->getVertexByTag(hits[i].ient); + if(!v) { + Msg::Error("Problem in point selection processing"); + return false; + } + vertices.push_back(v); + if(!multiple) return true; + } break; + case 1: { + GEdge *e = m->getEdgeByTag(hits[i].ient); + if(!e) { + Msg::Error("Problem in line selection processing"); + return false; } - break; - case 1: - { - GEdge *e = m->getEdgeByTag(hits[i].ient); - if(!e){ - Msg::Error("Problem in line selection processing"); - return false; - } - if(hits[i].type2){ - MElement *ele = getElement(e, hits[i].type2, hits[i].ient2); - if(ele) elements.push_back(ele); - } - edges.push_back(e); - if(!multiple) return true; + if(hits[i].type2) { + MElement *ele = getElement(e, hits[i].type2, hits[i].ient2); + if(ele) elements.push_back(ele); } - break; - case 2: - { - GFace *f = m->getFaceByTag(hits[i].ient); - if(!f){ - Msg::Error("Problem in surface selection processing"); - return false; - } - if(hits[i].type2){ - MElement *ele = getElement(f, hits[i].type2, hits[i].ient2); - if(ele) elements.push_back(ele); - } - faces.push_back(f); - if(!multiple) return true; + edges.push_back(e); + if(!multiple) return true; + } break; + case 2: { + GFace *f = m->getFaceByTag(hits[i].ient); + if(!f) { + Msg::Error("Problem in surface selection processing"); + return false; } - break; - case 3: - { - GRegion *r = m->getRegionByTag(hits[i].ient); - if(!r){ - Msg::Error("Problem in volume selection processing"); - return false; - } - if(hits[i].type2){ - MElement *ele = getElement(r, hits[i].type2, hits[i].ient2); - if(ele) elements.push_back(ele); - } - regions.push_back(r); - if(!multiple) return true; + if(hits[i].type2) { + MElement *ele = getElement(f, hits[i].type2, hits[i].ient2); + if(ele) elements.push_back(ele); } - break; - case 4: - { - int tag = hits[i].ient; - SPoint2 p = getGraph2dDataPointForTag(tag); - points.push_back(p); - if(!multiple) return true; + faces.push_back(f); + if(!multiple) return true; + } break; + case 3: { + GRegion *r = m->getRegionByTag(hits[i].ient); + if(!r) { + Msg::Error("Problem in volume selection processing"); + return false; } - break; - case 5: - { - int tag = hits[i].ient; - if(tag >= 0 && tag < (int)PView::list.size()) - views.push_back(PView::list[tag]); - if(!multiple) return true; + if(hits[i].type2) { + MElement *ele = getElement(r, hits[i].type2, hits[i].ient2); + if(ele) elements.push_back(ele); } - break; + regions.push_back(r); + if(!multiple) return true; + } break; + case 4: { + int tag = hits[i].ient; + SPoint2 p = getGraph2dDataPointForTag(tag); + points.push_back(p); + if(!multiple) return true; + } break; + case 5: { + int tag = hits[i].ient; + if(tag >= 0 && tag < (int)PView::list.size()) + views.push_back(PView::list[tag]); + if(!multiple) return true; + } break; } } } @@ -1097,14 +1118,15 @@ void drawContext::recenterForRotationCenterChange(SPoint3 newRotationCenter) // Recompute model translation so that the view is not changed SPoint3 &p = newRotationCenter; double vp[3]; - gluProject(p.x(), p.y(), p.z(), model, proj, viewport, &vp[0], &vp[1], &vp[2]); + gluProject(p.x(), p.y(), p.z(), model, proj, viewport, &vp[0], &vp[1], + &vp[2]); double wnr[3]; // look at mousePosition::recenter() const double &width = viewport[2]; const double &height = viewport[3]; - wnr[0] = (vxmin + vp[0] / width * (vxmax - vxmin)) / s[0] - - t[0] + t_init[0] / s[0]; - wnr[1] = (vymin + vp[1] / height * (vymax - vymin)) / s[1] - - t[1] + t_init[1] / s[1]; + wnr[0] = + (vxmin + vp[0] / width * (vxmax - vxmin)) / s[0] - t[0] + t_init[0] / s[0]; + wnr[1] = + (vymin + vp[1] / height * (vymax - vymin)) / s[1] - t[1] + t_init[1] / s[1]; t[0] += wnr[0] + CTX::instance()->cg[0] - p.x(); t[1] += wnr[1] + CTX::instance()->cg[1] - p.y(); } diff --git a/Graphics/drawContext.h b/Graphics/drawContext.h index ebbde1504401a7ae28cccfdab5f328a1c90abe8c..01abfe24c114663333af5ca46e577c4b0735ce10 100644 --- a/Graphics/drawContext.h +++ b/Graphics/drawContext.h @@ -44,40 +44,40 @@ class PView; class openglWindow; class drawTransform { - public: - drawTransform(){} - virtual ~drawTransform(){} - virtual void transform(double &x, double &y, double &z){} - virtual void transformOneForm(double &x, double &y, double &z){} - virtual void transformTwoForm(double &x, double &y, double &z){} - virtual void setMatrix(double mat[3][3], double tra[3]){} +public: + drawTransform() {} + virtual ~drawTransform() {} + virtual void transform(double &x, double &y, double &z) {} + virtual void transformOneForm(double &x, double &y, double &z) {} + virtual void transformTwoForm(double &x, double &y, double &z) {} + virtual void setMatrix(double mat[3][3], double tra[3]) {} }; class drawTransformScaled : public drawTransform { - private: +private: double _mat[3][3]; double _tra[3]; - public: - drawTransformScaled(double mat[3][3], double tra[3]=0) - : drawTransform() +public: + drawTransformScaled(double mat[3][3], double tra[3] = 0) : drawTransform() { setMatrix(mat, tra); } - virtual void setMatrix(double mat[3][3], double tra[3]=0) + virtual void setMatrix(double mat[3][3], double tra[3] = 0) { - for(int i = 0; i < 3; i++){ - for(int j = 0; j < 3; j++) - _mat[i][j] = mat[i][j]; - if(tra) _tra[i] = tra[i]; - else _tra[i] = 0.; + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) _mat[i][j] = mat[i][j]; + if(tra) + _tra[i] = tra[i]; + else + _tra[i] = 0.; } } virtual void transform(double &x, double &y, double &z) { double xyz[3] = {x, y, z}; x = y = z = 0.; - for(int k = 0; k < 3; k++){ + for(int k = 0; k < 3; k++) { x += _mat[0][k] * xyz[k]; y += _mat[1][k] * xyz[k]; z += _mat[2][k] * xyz[k]; @@ -91,39 +91,42 @@ class drawTransformScaled : public drawTransform { // global drawing functions, which need to be redefined for each widget toolkit // (FLTK, Qt, etc.) class drawContextGlobal { - public: - drawContextGlobal(){} - virtual ~drawContextGlobal(){} - virtual void draw(){} - virtual void drawCurrentOpenglWindow(bool make_current){} - virtual int getFontIndex(const char *fontname){ return 0; } - virtual int getFontEnum(int index){ return 0; } - virtual const char *getFontName(int index){ return "Helvetica"; } - virtual int getFontAlign(const char *alignstr){ return 0; } - virtual int getFontSize(){ return 12; } - virtual void setFont(int fontid, int fontsize){} - virtual double getStringWidth(const char *str){ return 1.; } - virtual int getStringHeight(){ return 12; } - virtual int getStringDescent(){ return 3; } - virtual void drawString(const char *str){} - virtual void resetFontTextures(){} - virtual void flushString(){} - virtual std::string getName(){ return "None"; } +public: + drawContextGlobal() {} + virtual ~drawContextGlobal() {} + virtual void draw() {} + virtual void drawCurrentOpenglWindow(bool make_current) {} + virtual int getFontIndex(const char *fontname) { return 0; } + virtual int getFontEnum(int index) { return 0; } + virtual const char *getFontName(int index) { return "Helvetica"; } + virtual int getFontAlign(const char *alignstr) { return 0; } + virtual int getFontSize() { return 12; } + virtual void setFont(int fontid, int fontsize) {} + virtual double getStringWidth(const char *str) { return 1.; } + virtual int getStringHeight() { return 12; } + virtual int getStringDescent() { return 3; } + virtual void drawString(const char *str) {} + virtual void resetFontTextures() {} + virtual void flushString() {} + virtual std::string getName() { return "None"; } }; class drawContext { - private: +private: static drawContextGlobal *_global; drawTransform *_transform; GLUquadricObj *_quadric; GLuint _displayLists; - std::set<GModel*> _hiddenModels; - std::set<PView*> _hiddenViews; + std::set<GModel *> _hiddenModels; + std::set<PView *> _hiddenViews; GLuint _bgImageTexture, _bgImageW, _bgImageH; openglWindow *_openglWindow; - struct imgtex{ GLuint tex, w, h; }; + struct imgtex { + GLuint tex, w, h; + }; std::map<std::string, imgtex> _imageTextures; - public: + +public: Camera camera; double r[3]; // current Euler angles (in degrees!) double t[3], s[3]; // current translation and scale @@ -133,34 +136,35 @@ class drawContext { double t_init[3]; // initial translation before applying modelview transform double vxmin, vxmax, vymin, vymax; // current viewport in real coordinates double pixel_equiv_x, pixel_equiv_y; // approx equiv model length of a pixel - double model[16], proj[16]; // the modelview and projection matrix as they were - // at the time of the last InitPosition() call - enum RenderMode {GMSH_RENDER=1, GMSH_SELECT=2, GMSH_FEEDBACK=3}; + double model[16], + proj[16]; // the modelview and projection matrix as they were + // at the time of the last InitPosition() call + enum RenderMode { GMSH_RENDER = 1, GMSH_SELECT = 2, GMSH_FEEDBACK = 3 }; int render_mode; // current rendering mode - public: - drawContext(openglWindow *window=0, drawTransform *transform=0); +public: + drawContext(openglWindow *window = 0, drawTransform *transform = 0); ~drawContext(); bool isHighResolution(); void copyViewAttributes(drawContext *other) { camera = other->camera; - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { r[i] = other->r[i]; t[i] = other->t[i]; s[i] = other->s[i]; t_init[i] = other->t_init[i]; } - for(int i = 0; i < 4; i++){ + for(int i = 0; i < 4; i++) { quaternion[i] = other->quaternion[i]; } - for(int i = 0; i < 16; i++){ + for(int i = 0; i < 16; i++) { rot[i] = other->rot[i]; } } - static void setGlobal(drawContextGlobal *global){ _global = global; } + static void setGlobal(drawContextGlobal *global) { _global = global; } static drawContextGlobal *global(); - void setTransform(drawTransform *transform){ _transform = transform; } - drawTransform *getTransform(){ return _transform; } + void setTransform(drawTransform *transform) { _transform = transform; } + drawTransform *getTransform() { return _transform; } void transform(double &x, double &y, double &z) { if(_transform) _transform->transform(x, y, z); @@ -173,21 +177,31 @@ class drawContext { { if(_transform) _transform->transformTwoForm(x, y, z); } - void hide(GModel *m){ _hiddenModels.insert(m); } - void hide(PView *v){ _hiddenViews.insert(v); } + void hide(GModel *m) { _hiddenModels.insert(m); } + void hide(PView *v) { _hiddenViews.insert(v); } void show(GModel *m) { - std::set<GModel*>::iterator it = _hiddenModels.find(m); + std::set<GModel *>::iterator it = _hiddenModels.find(m); if(it != _hiddenModels.end()) _hiddenModels.erase(it); } void show(PView *v) { - std::set<PView*>::iterator it = _hiddenViews.find(v); + std::set<PView *>::iterator it = _hiddenViews.find(v); if(it != _hiddenViews.end()) _hiddenViews.erase(it); } - void showAll(){ _hiddenModels.clear(); _hiddenViews.clear(); } - bool isVisible(GModel *m){ return (_hiddenModels.find(m) == _hiddenModels.end()); } - bool isVisible(PView *v){ return (_hiddenViews.find(v) == _hiddenViews.end()); } + void showAll() + { + _hiddenModels.clear(); + _hiddenViews.clear(); + } + bool isVisible(GModel *m) + { + return (_hiddenModels.find(m) == _hiddenModels.end()); + } + bool isVisible(PView *v) + { + return (_hiddenViews.find(v) == _hiddenViews.end()); + } void createQuadricsAndDisplayLists(); void invalidateQuadricsAndDisplayLists(); bool generateTextureForImage(const std::string &name, int page, @@ -200,17 +214,19 @@ class drawContext { void addQuaternionFromAxisAndAngle(double axis[3], double angle); void setQuaternionFromEulerAngles(); void setEulerAnglesFromRotationMatrix(); - void initProjection(int xpick=0, int ypick=0, int wpick=0, int hpick=0); + void initProjection(int xpick = 0, int ypick = 0, int wpick = 0, + int hpick = 0); void initRenderModel(); void initPosition(bool saveMatrices); void unproject(double winx, double winy, double p[3], double d[3]); void viewport2World(double vp[3], double xyz[3]); void world2Viewport(double xyz[3], double vp[3]); - bool select(int type, bool multiple, bool mesh, bool post, int x, int y, int w, int h, - std::vector<GVertex*> &vertices, std::vector<GEdge*> &edges, - std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, - std::vector<MElement*> &elements, std::vector<SPoint2> &points, - std::vector<PView*> &views); + bool select(int type, bool multiple, bool mesh, bool post, int x, int y, + int w, int h, std::vector<GVertex *> &vertices, + std::vector<GEdge *> &edges, std::vector<GFace *> &faces, + std::vector<GRegion *> ®ions, + std::vector<MElement *> &elements, std::vector<SPoint2> &points, + std::vector<PView *> &views); void recenterForRotationCenterChange(SPoint3 newRotationCenter); int fix2dCoordinates(double *x, double *y); void draw3d(); @@ -222,11 +238,11 @@ class drawContext { void drawBackgroundImage(bool moving); void drawText2d(); void drawGraph2d(bool inModelCoordinates); - void drawAxis(double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax, - int nticks, int mikado); + void drawAxis(double xmin, double ymin, double zmin, double xmax, double ymax, + double zmax, int nticks, int mikado); void drawAxes(int mode, double tics[3], std::string format[3], - std::string label[3], double bb[6], int mikado, double value_bb[6]); + std::string label[3], double bb[6], int mikado, + double value_bb[6]); void drawAxes(int mode, double tics[3], std::string format[3], std::string label[3], SBoundingBox3d &bb, int mikado, SBoundingBox3d &value_bb); @@ -235,58 +251,57 @@ class drawContext { void drawTrackball(); void drawScales(); void drawString(const std::string &s, double x, double y, double z, - const std::string &font_name, int font_enum, - int font_size, int align, int line_num = 0); + const std::string &font_name, int font_enum, int font_size, + int align, int line_num = 0); void drawString(const std::string &s, double x, double y, double z, int line_num = 0); void drawStringCenter(const std::string &s, double x, double y, double z, int line_num = 0); void drawStringRight(const std::string &s, double x, double y, double z, int line_num = 0); - void drawString(const std::string &s, double x, double y, double z, double style, - int line_num = 0); - void drawImage(const std::string &s, double x, double y, double z, int align = 0); - void drawSphere(double R, double x, double y, double z, int n1, int n2, int light); - void drawCube(double x, double y, double z, double val[9], - int light); + void drawString(const std::string &s, double x, double y, double z, + double style, int line_num = 0); + void drawImage(const std::string &s, double x, double y, double z, + int align = 0); + void drawSphere(double R, double x, double y, double z, int n1, int n2, + int light); + void drawCube(double x, double y, double z, double val[9], int light); void drawEllipsoid(double x, double y, double z, float v0[3], float v1[3], - float v2[3], int light); - void drawEllipse(double x, double y, double z, float v0[3], float v1[3], int light); + float v2[3], int light); + void drawEllipse(double x, double y, double z, float v0[3], float v1[3], + int light); void drawSphere(double size, double x, double y, double z, int light); void drawCylinder(double width, double *x, double *y, double *z, int light); void drawTaperedCylinder(double width, double val1, double val2, - double ValMin, double ValMax, - double *x, double *y, double *z, int light); - void drawArrow3d(double x, double y, double z, double dx, double dy, double dz, - double length, int light); - void drawVector(int Type, int Fill, double x, double y, double z, - double dx, double dy, double dz, int light); - void drawBox(double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax, - bool labels=true); + double ValMin, double ValMax, double *x, double *y, + double *z, int light); + void drawArrow3d(double x, double y, double z, double dx, double dy, + double dz, double length, int light); + void drawVector(int Type, int Fill, double x, double y, double z, double dx, + double dy, double dz, int light); + void drawBox(double xmin, double ymin, double zmin, double xmax, double ymax, + double zmax, bool labels = true); void drawPlaneInBoundingBox(double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax, - double a, double b, double c, double d, - int shade=0); + double xmax, double ymax, double zmax, double a, + double b, double c, double d, int shade = 0); // dynamic pointer to a transient geometry drawing function static void setDrawGeomTransientFunction(void (*fct)(void *)); - static void (*drawGeomTransient)(void*); + static void (*drawGeomTransient)(void *); }; class mousePosition { - public: +public: double win[3]; // window coordinates double wnr[3]; // world coordinates BEFORE rotation double s[3]; // scaling state when the event was recorded double t[3]; // translation state when the event was recorded mousePosition() { - for(int i = 0; i < 3; i++) - win[i] = wnr[i] = s[i] = t[i] = 0.; + for(int i = 0; i < 3; i++) win[i] = wnr[i] = s[i] = t[i] = 0.; } mousePosition(const mousePosition &instance) { - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { win[i] = instance.win[i]; wnr[i] = instance.wnr[i]; s[i] = instance.s[i]; @@ -295,7 +310,7 @@ class mousePosition { } void set(drawContext *ctx, int x, int y) { - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { s[i] = ctx->s[i]; t[i] = ctx->t[i]; } @@ -303,12 +318,14 @@ class mousePosition { win[1] = (double)y; win[2] = 0.; - wnr[0] = - (ctx->vxmin + win[0] / (double)ctx->viewport[2] * (ctx->vxmax - ctx->vxmin)) - / ctx->s[0] - ctx->t[0] + ctx->t_init[0] / ctx->s[0]; - wnr[1] = - (ctx->vymax - win[1] / (double)ctx->viewport[3] * (ctx->vymax - ctx->vymin)) - / ctx->s[1] - ctx->t[1] + ctx->t_init[1] / ctx->s[1]; + wnr[0] = (ctx->vxmin + + win[0] / (double)ctx->viewport[2] * (ctx->vxmax - ctx->vxmin)) / + ctx->s[0] - + ctx->t[0] + ctx->t_init[0] / ctx->s[0]; + wnr[1] = (ctx->vymax - + win[1] / (double)ctx->viewport[3] * (ctx->vymax - ctx->vymin)) / + ctx->s[1] - + ctx->t[1] + ctx->t_init[1] / ctx->s[1]; wnr[2] = 0.; } void recenter(drawContext *ctx) diff --git a/Graphics/drawGeom.cpp b/Graphics/drawGeom.cpp index d6fbd66c1a4abb7dbdb6caa1d7bea524553035d1..fb1e31c685b13000cf4846886690991710dee74c 100644 --- a/Graphics/drawGeom.cpp +++ b/Graphics/drawGeom.cpp @@ -13,27 +13,28 @@ #include "GmshMessage.h" #include "StringUtils.h" -static void drawEntityLabel(drawContext *ctx, GEntity *e, - double x, double y, double z, double offset) +static void drawEntityLabel(drawContext *ctx, GEntity *e, double x, double y, + double z, double offset) { double xx = x + offset / ctx->s[0]; double yy = y + offset / ctx->s[1]; double zz = z + offset / ctx->s[2]; - if(CTX::instance()->geom.labelType == 0){ - std::vector<std::string> info = SplitString(e->getInfoString(false, true), '\n'); + if(CTX::instance()->geom.labelType == 0) { + std::vector<std::string> info = + SplitString(e->getInfoString(false, true), '\n'); for(int line = 0; line < (int)info.size(); line++) ctx->drawString(info[line].c_str(), xx, yy, zz, line); return; } char str[1024]; - if(CTX::instance()->geom.labelType == 1){ + if(CTX::instance()->geom.labelType == 1) { sprintf(str, "%d", e->tag()); } - else{ + else { strcpy(str, ""); - for(unsigned int i = 0; i < e->physicals.size(); i++){ + for(unsigned int i = 0; i < e->physicals.size(); i++) { char tmp[32]; if(i) strcat(str, ", "); sprintf(tmp, "%d", e->physicals[i]); @@ -44,11 +45,12 @@ static void drawEntityLabel(drawContext *ctx, GEntity *e, } class drawGVertex { - private : +private: drawContext *_ctx; - public : - drawGVertex(drawContext *ctx) : _ctx(ctx){} - void operator () (GVertex *v) + +public: + drawGVertex(drawContext *ctx) : _ctx(ctx) {} + void operator()(GVertex *v) { if(!v->getVisibility()) return; if(v->geomType() == GEntity::BoundaryLayerPoint) return; @@ -64,7 +66,7 @@ class drawGVertex { double ps = CTX::instance()->geom.pointSize; double sps = CTX::instance()->geom.selectedPointSize; - if(_ctx->isHighResolution()){ + if(_ctx->isHighResolution()) { ps *= CTX::instance()->highResolutionPointSizeFactor; sps *= CTX::instance()->highResolutionPointSizeFactor; } @@ -73,21 +75,21 @@ class drawGVertex { glPointSize((float)sps); gl2psPointSize((float)(CTX::instance()->geom.selectedPointSize * CTX::instance()->print.epsPointSizeFactor)); - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.selection); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.selection); } else { glPointSize((float)ps); gl2psPointSize((float)(CTX::instance()->geom.pointSize * CTX::instance()->print.epsPointSizeFactor)); - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.point); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.point); } - if(CTX::instance()->geom.highlightOrphans){ - std::vector<GEdge*> const& edges = v->edges(); + if(CTX::instance()->geom.highlightOrphans) { + std::vector<GEdge *> const &edges = v->edges(); if(edges.size() == 0) - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.highlight[0]); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.highlight[0]); else if(edges.size() == 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.highlight[1]); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.highlight[1]); } double x = v->x(), y = v->y(), z = v->z(); @@ -108,10 +110,10 @@ class drawGVertex { } if(CTX::instance()->geom.pointsNum || v->getSelection() > 1) { - double offset = (0.5 * ps + - 0.1 * CTX::instance()->glFontSize) * _ctx->pixel_equiv_x; + double offset = + (0.5 * ps + 0.1 * CTX::instance()->glFontSize) * _ctx->pixel_equiv_x; if(v->getSelection() > 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); drawEntityLabel(_ctx, v, x, y, z, offset); } @@ -123,11 +125,12 @@ class drawGVertex { }; class drawGEdge { - private : +private: drawContext *_ctx; - public : - drawGEdge(drawContext *ctx) : _ctx(ctx){} - void operator () (GEdge *e) + +public: + drawGEdge(drawContext *ctx) : _ctx(ctx) {} + void operator()(GEdge *e) { if(!e->getVisibility()) return; if(e->geomType() == GEntity::DiscreteCurve) return; @@ -147,21 +150,21 @@ class drawGEdge { glLineWidth((float)CTX::instance()->geom.selectedCurveWidth); gl2psLineWidth((float)(CTX::instance()->geom.selectedCurveWidth * CTX::instance()->print.epsLineWidthFactor)); - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.selection); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.selection); } else { glLineWidth((float)CTX::instance()->geom.curveWidth); gl2psLineWidth((float)(CTX::instance()->geom.curveWidth * CTX::instance()->print.epsLineWidthFactor)); - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.curve); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.curve); } - if(CTX::instance()->geom.highlightOrphans){ - std::vector<GFace*> faces = e->faces(); + if(CTX::instance()->geom.highlightOrphans) { + std::vector<GFace *> faces = e->faces(); if(faces.empty()) - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.highlight[0]); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.highlight[0]); else if(faces.size() == 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.highlight[1]); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.highlight[1]); } Range<double> t_bounds = e->parBounds(0); @@ -174,16 +177,18 @@ class drawGEdge { for(int i = 0; i < N - 1; i++) { double t1 = t_min + (double)i / (double)(N - 1) * (t_max - t_min); GPoint p1 = e->point(t1); - double t2 = t_min + (double)(i + 1) / (double)(N - 1) * (t_max - t_min); + double t2 = + t_min + (double)(i + 1) / (double)(N - 1) * (t_max - t_min); GPoint p2 = e->point(t2); double x[2] = {p1.x(), p2.x()}; double y[2] = {p1.y(), p2.y()}; double z[2] = {p1.z(), p2.z()}; _ctx->transform(x[0], y[0], z[0]); _ctx->transform(x[1], y[1], z[1]); - _ctx->drawCylinder(e->getSelection() ? CTX::instance()->geom.selectedCurveWidth : - CTX::instance()->geom.curveWidth, x, y, z, - CTX::instance()->geom.light); + _ctx->drawCylinder(e->getSelection() ? + CTX::instance()->geom.selectedCurveWidth : + CTX::instance()->geom.curveWidth, + x, y, z, CTX::instance()->geom.light); } } else { @@ -202,11 +207,12 @@ class drawGEdge { if(CTX::instance()->geom.curvesNum || e->getSelection() > 1) { GPoint p = e->point(t_min + 0.5 * (t_max - t_min)); double offset = (0.5 * CTX::instance()->geom.curveWidth + - 0.1 * CTX::instance()->glFontSize) * _ctx->pixel_equiv_x; + 0.1 * CTX::instance()->glFontSize) * + _ctx->pixel_equiv_x; double x = p.x(), y = p.y(), z = p.z(); _ctx->transform(x, y, z); if(e->getSelection() > 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); drawEntityLabel(_ctx, e, x, y, z, offset); } @@ -216,13 +222,14 @@ class drawGEdge { SVector3 der = e->firstDer(t); der.normalize(); for(int i = 0; i < 3; i++) - der[i] *= CTX::instance()->geom.tangents * _ctx->pixel_equiv_x / _ctx->s[i]; - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.tangents); + der[i] *= + CTX::instance()->geom.tangents * _ctx->pixel_equiv_x / _ctx->s[i]; + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.tangents); double x = p.x(), y = p.y(), z = p.z(); _ctx->transform(x, y, z); _ctx->transformOneForm(der[0], der[1], der[2]); - _ctx->drawVector(CTX::instance()->vectorType, 0, x, y, z, der[0], der[1], der[2], - CTX::instance()->geom.light); + _ctx->drawVector(CTX::instance()->vectorType, 0, x, y, z, der[0], der[1], + der[2], CTX::instance()->geom.light); } if(select) { @@ -233,40 +240,39 @@ class drawGEdge { }; class drawGFace { - private: +private: drawContext *_ctx; - void _drawVertexArray(VertexArray *va, bool useNormalArray, int forceColor=0, - unsigned int color=0) + void _drawVertexArray(VertexArray *va, bool useNormalArray, + int forceColor = 0, unsigned int color = 0) { if(!va || !va->getNumVertices()) return; glVertexPointer(3, GL_FLOAT, 0, va->getVertexArray()); glEnableClientState(GL_VERTEX_ARRAY); - if(useNormalArray){ + if(useNormalArray) { glEnable(GL_LIGHTING); glNormalPointer(NORMAL_GLTYPE, 0, va->getNormalArray()); glEnableClientState(GL_NORMAL_ARRAY); } - else{ + else { glDisableClientState(GL_NORMAL_ARRAY); } - if(forceColor){ + if(forceColor) { glDisableClientState(GL_COLOR_ARRAY); - glColor4ubv((GLubyte *) & color); + glColor4ubv((GLubyte *)&color); } - else{ + else { glColorPointer(4, GL_UNSIGNED_BYTE, 0, va->getColorArray()); glEnableClientState(GL_COLOR_ARRAY); } - if(CTX::instance()->polygonOffset) - glEnable(GL_POLYGON_OFFSET_FILL); - if(CTX::instance()->geom.surfaceType > 1){ + if(CTX::instance()->polygonOffset) glEnable(GL_POLYGON_OFFSET_FILL); + if(CTX::instance()->geom.surfaceType > 1) { if(CTX::instance()->geom.lightTwoSide) glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); else glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } - else{ + else { glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } @@ -278,9 +284,10 @@ class drawGFace { glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); } - public : + +public: drawGFace(drawContext *ctx) : _ctx(ctx) {} - void operator () (GFace *f) + void operator()(GFace *f) { if(!f->getVisibility()) return; if(f->geomType() == GEntity::DiscreteSurface) return; @@ -298,13 +305,13 @@ class drawGFace { glLineWidth((float)(CTX::instance()->geom.selectedCurveWidth / 2.)); gl2psLineWidth((float)(CTX::instance()->geom.selectedCurveWidth / 2. * CTX::instance()->print.epsLineWidthFactor)); - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.selection); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.selection); } else { glLineWidth((float)(CTX::instance()->geom.curveWidth / 2.)); gl2psLineWidth((float)(CTX::instance()->geom.curveWidth / 2. * CTX::instance()->print.epsLineWidthFactor)); - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.surface); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.surface); } if(CTX::instance()->geom.lightTwoSide) @@ -320,26 +327,25 @@ class drawGFace { CTX::instance()->geom.surfacesNum || CTX::instance()->geom.normals) f->buildRepresentationCross(); - if(CTX::instance()->geom.surfaces || f->getSelection() > 1){ - if(CTX::instance()->geom.surfaceType > 0 && f->va_geom_triangles){ + if(CTX::instance()->geom.surfaces || f->getSelection() > 1) { + if(CTX::instance()->geom.surfaceType > 0 && f->va_geom_triangles) { bool selected = false; - if (f->getSelection()) - selected = true; - _drawVertexArray - (f->va_geom_triangles, CTX::instance()->geom.light, - (f->geomType() == GEntity::ProjectionFace) ? true : selected, - (f->geomType() == GEntity::ProjectionFace) ? - CTX::instance()->color.geom.projection : - CTX::instance()->color.geom.selection); + if(f->getSelection()) selected = true; + _drawVertexArray(f->va_geom_triangles, CTX::instance()->geom.light, + (f->geomType() == GEntity::ProjectionFace) ? true : + selected, + (f->geomType() == GEntity::ProjectionFace) ? + CTX::instance()->color.geom.projection : + CTX::instance()->color.geom.selection); } - else{ + else { glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x0F0F); gl2psEnable(GL2PS_LINE_STIPPLE); - for(int dim = 0; dim < 2; dim++){ - for(unsigned int i = 0; i < f->cross[dim].size(); i++){ + for(int dim = 0; dim < 2; dim++) { + for(unsigned int i = 0; i < f->cross[dim].size(); i++) { glBegin(GL_LINE_STRIP); - for(unsigned int j = 0; j < f->cross[dim][i].size(); j++){ + for(unsigned int j = 0; j < f->cross[dim][i].size(); j++) { double x = f->cross[dim][i][j].x(); double y = f->cross[dim][i][j].y(); double z = f->cross[dim][i][j].z(); @@ -354,7 +360,7 @@ class drawGFace { } } - if(f->cross[0].size() && f->cross[0][0].size() >= 2){ + if(f->cross[0].size() && f->cross[0][0].size() >= 2) { int idx = f->cross[0][0].size() / 2; if(CTX::instance()->geom.surfacesNum || f->getSelection() > 1) { double offset = 0.1 * CTX::instance()->glFontSize * _ctx->pixel_equiv_x; @@ -363,24 +369,24 @@ class drawGFace { double z = f->cross[0][0][idx].z(); _ctx->transform(x, y, z); if(f->getSelection() > 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); drawEntityLabel(_ctx, f, x, y, z, offset); } if(CTX::instance()->geom.normals) { - SPoint3 p(f->cross[0][0][idx].x(), - f->cross[0][0][idx].y(), + SPoint3 p(f->cross[0][0][idx].x(), f->cross[0][0][idx].y(), f->cross[0][0][idx].z()); SPoint2 uv = f->parFromPoint(p); SVector3 n = f->normal(uv); for(int i = 0; i < 3; i++) - n[i] *= CTX::instance()->geom.normals * _ctx->pixel_equiv_x / _ctx->s[i]; - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.normals); + n[i] *= + CTX::instance()->geom.normals * _ctx->pixel_equiv_x / _ctx->s[i]; + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.normals); double x = p.x(), y = p.y(), z = p.z(); _ctx->transform(x, y, z); _ctx->transformTwoForm(n[0], n[1], n[2]); - _ctx->drawVector(CTX::instance()->vectorType, 0, x, y, z, n[0], n[1], n[2], - CTX::instance()->geom.light); + _ctx->drawVector(CTX::instance()->vectorType, 0, x, y, z, n[0], n[1], + n[2], CTX::instance()->geom.light); } } @@ -392,11 +398,12 @@ class drawGFace { }; class drawGRegion { - private : +private: drawContext *_ctx; - public : - drawGRegion(drawContext *ctx) : _ctx(ctx){} - void operator () (GRegion *r) + +public: + drawGRegion(drawContext *ctx) : _ctx(ctx) {} + void operator()(GRegion *r) { if(!r->getVisibility()) return; @@ -413,15 +420,15 @@ class drawGRegion { glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); if(r->getSelection()) - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.selection); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.selection); else - glColor4ubv((GLubyte *) & CTX::instance()->color.geom.volume); + glColor4ubv((GLubyte *)&CTX::instance()->color.geom.volume); const double size = 8.; double x = 0., y = 0., z = 0.; if(CTX::instance()->geom.volumes || CTX::instance()->geom.volumesNum || - r->getSelection() > 1){ + r->getSelection() > 1) { SPoint3 p = r->bounds(true).center(); // fast approx if mesh-based x = p.x(); y = p.y(); @@ -432,11 +439,11 @@ class drawGRegion { if(CTX::instance()->geom.volumes || r->getSelection() > 1) _ctx->drawSphere(size, x, y, z, CTX::instance()->geom.light); - if(CTX::instance()->geom.volumesNum || r->getSelection() > 1){ - double offset = (1. * size + 0.1 * CTX::instance()->glFontSize) * - _ctx->pixel_equiv_x; + if(CTX::instance()->geom.volumesNum || r->getSelection() > 1) { + double offset = + (1. * size + 0.1 * CTX::instance()->glFontSize) * _ctx->pixel_equiv_x; if(r->getSelection() > 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); drawEntityLabel(_ctx, r, x, y, z, offset); } @@ -460,9 +467,9 @@ void drawContext::drawGeom() else glDisable((GLenum)(GL_CLIP_PLANE0 + i)); - for(unsigned int i = 0; i < GModel::list.size(); i++){ + for(unsigned int i = 0; i < GModel::list.size(); i++) { GModel *m = GModel::list[i]; - if(m->getVisibility() && isVisible(m)){ + if(m->getVisibility() && isVisible(m)) { std::for_each(m->firstVertex(), m->lastVertex(), drawGVertex(this)); std::for_each(m->firstEdge(), m->lastEdge(), drawGEdge(this)); std::for_each(m->firstFace(), m->lastFace(), drawGFace(this)); @@ -470,6 +477,5 @@ void drawContext::drawGeom() } } - for(int i = 0; i < 6; i++) - glDisable((GLenum)(GL_CLIP_PLANE0 + i)); + for(int i = 0; i < 6; i++) glDisable((GLenum)(GL_CLIP_PLANE0 + i)); } diff --git a/Graphics/drawGlyph.cpp b/Graphics/drawGlyph.cpp index a48e68bfce07b47f037f54aad0b4bdbc19a8f7d3..293dceed8aeb7c815b0653772fac9aac9e35a66a 100644 --- a/Graphics/drawGlyph.cpp +++ b/Graphics/drawGlyph.cpp @@ -20,7 +20,7 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, if(s.empty()) return; if(CTX::instance()->printing && !CTX::instance()->print.text) return; - if(s.size() > 8 && s.substr(0, 7) == "file://"){ + if(s.size() > 8 && s.substr(0, 7) == "file://") { drawImage(s.substr(7), x, y, z, align); return; } @@ -30,7 +30,7 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); if(valid == GL_FALSE) return; // the primitive is culled - if(align > 0 || line_num){ + if(align > 0 || line_num) { GLdouble pos[4]; glGetDoublev(GL_CURRENT_RASTER_POSITION, pos); double x[3], w[3] = {pos[0], pos[1], pos[2]}; @@ -39,22 +39,42 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, double height = drawContext::global()->getStringHeight(); // width and height must here be computed in true pixel coordinates, because // viewport2world uses the actual, pixel-sized (not FLTK-sized) viewport - if(isHighResolution()){ + if(isHighResolution()) { width *= 2; height *= 2; } // alignment for TeX is handled directly by gl2ps if(!CTX::instance()->printing || - CTX::instance()->print.fileFormat != FORMAT_TEX){ - switch(align){ - case 1: w[0] -= width/2.; break; // bottom center - case 2: w[0] -= width; break; // bottom right - case 3: w[1] -= height; break; // top left - case 4: w[0] -= width/2.; w[1] -= height; break; // top center - case 5: w[0] -= width; w[1] -= height; break; // top right - case 6: w[1] -= height/2.; break; // center left - case 7: w[0] -= width/2.; w[1] -= height/2.; break; // center center - case 8: w[0] -= width; w[1] -= height/2.; break; // center right + CTX::instance()->print.fileFormat != FORMAT_TEX) { + switch(align) { + case 1: + w[0] -= width / 2.; + break; // bottom center + case 2: + w[0] -= width; + break; // bottom right + case 3: + w[1] -= height; + break; // top left + case 4: + w[0] -= width / 2.; + w[1] -= height; + break; // top center + case 5: + w[0] -= width; + w[1] -= height; + break; // top right + case 6: + w[1] -= height / 2.; + break; // center left + case 7: + w[0] -= width / 2.; + w[1] -= height / 2.; + break; // center center + case 8: + w[0] -= width; + w[1] -= height / 2.; + break; // center right default: break; } } @@ -64,25 +84,43 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, glRasterPos3d(x[0], x[1], x[2]); } - if(!CTX::instance()->printing){ + if(!CTX::instance()->printing) { drawContext::global()->setFont(font_enum, font_size); drawContext::global()->drawString(s.c_str()); } - else{ - if(CTX::instance()->print.fileFormat == FORMAT_TEX){ - std::string tmp = SanitizeTeXString - (s.c_str(), CTX::instance()->print.texAsEquation); + else { + if(CTX::instance()->print.fileFormat == FORMAT_TEX) { + std::string tmp = + SanitizeTeXString(s.c_str(), CTX::instance()->print.texAsEquation); int opt; - switch(align){ - case 1: opt = GL2PS_TEXT_B; break; // bottom center - case 2: opt = GL2PS_TEXT_BR; break; // bottom right - case 3: opt = GL2PS_TEXT_TL; break; // top left - case 4: opt = GL2PS_TEXT_T; break; // top center - case 5: opt = GL2PS_TEXT_TR; break; // top right - case 6: opt = GL2PS_TEXT_CL; break; // center left - case 7: opt = GL2PS_TEXT_C; break; // center center - case 8: opt = GL2PS_TEXT_CR; break; // center right - default: opt = GL2PS_TEXT_BL; break; // bottom left + switch(align) { + case 1: + opt = GL2PS_TEXT_B; + break; // bottom center + case 2: + opt = GL2PS_TEXT_BR; + break; // bottom right + case 3: + opt = GL2PS_TEXT_TL; + break; // top left + case 4: + opt = GL2PS_TEXT_T; + break; // top center + case 5: + opt = GL2PS_TEXT_TR; + break; // top right + case 6: + opt = GL2PS_TEXT_CL; + break; // center left + case 7: + opt = GL2PS_TEXT_C; + break; // center center + case 8: + opt = GL2PS_TEXT_CR; + break; // center right + default: + opt = GL2PS_TEXT_BL; + break; // bottom left } gl2psTextOpt(tmp.c_str(), font_name.c_str(), font_size, opt, 0.); } @@ -91,10 +129,10 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, CTX::instance()->print.fileFormat == FORMAT_EPS || CTX::instance()->print.fileFormat == FORMAT_PDF || CTX::instance()->print.fileFormat == FORMAT_SVG || - CTX::instance()->print.fileFormat == FORMAT_TIKZ)){ + CTX::instance()->print.fileFormat == FORMAT_TIKZ)) { gl2psText(s.c_str(), font_name.c_str(), font_size); } - else{ + else { drawContext::global()->setFont(font_enum, font_size); drawContext::global()->drawString(s.c_str()); } @@ -108,15 +146,15 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, CTX::instance()->glFontSize, 0, line_num); } -void drawContext::drawStringCenter(const std::string &s, double x, double y, double z, - int line_num) +void drawContext::drawStringCenter(const std::string &s, double x, double y, + double z, int line_num) { drawString(s, x, y, z, CTX::instance()->glFont, CTX::instance()->glFontEnum, CTX::instance()->glFontSize, 1, line_num); } -void drawContext::drawStringRight(const std::string &s, double x, double y, double z, - int line_num) +void drawContext::drawStringRight(const std::string &s, double x, double y, + double z, int line_num) { drawString(s, x, y, z, CTX::instance()->glFont, CTX::instance()->glFontEnum, CTX::instance()->glFontSize, 2, line_num); @@ -127,13 +165,13 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, { unsigned int bits = (unsigned int)style; - if(!bits){ // use defaults + if(!bits) { // use defaults drawString(s, x, y, z, line_num); } - else{ + else { int size = (bits & 0xff); - int font = (bits>>8 & 0xff); - int align = (bits>>16 & 0xff); + int font = (bits >> 8 & 0xff); + int align = (bits >> 16 & 0xff); int font_enum = drawContext::global()->getFontEnum(font); std::string font_name = drawContext::global()->getFontName(font); if(!size) size = CTX::instance()->glFontSize; @@ -141,8 +179,8 @@ void drawContext::drawString(const std::string &s, double x, double y, double z, } } -void drawContext::drawImage(const std::string &name, double x, double y, double z, - int align) +void drawContext::drawImage(const std::string &name, double x, double y, + double z, int align) { // format can be "@wxh" or "@wxh,wx,wy,wz,hx,hy,hz", where w and h are the // width and height (in model coordinates for T3 or in pixels for T2) of the @@ -150,17 +188,17 @@ void drawContext::drawImage(const std::string &name, double x, double y, double // hx,hy,hz is the direction of the left edge of the image. size_t p = name.find_last_of('@'); std::string file = name, format; - if(p != std::string::npos){ + if(p != std::string::npos) { format = name.substr(p + 1); file = name.substr(0, p); } double w = 0., h = 0., wx = 1., wy = 0., wz = 0., hx = 0., hy = 1., hz = 0.; bool billboard = false; - if(format.size()){ + if(format.size()) { bool ok; if(format.find(',') != std::string::npos) - ok = (sscanf(format.c_str(), "%lfx%lf,%lf,%lf,%lf,%lf,%lf,%lf", - &w, &h, &wx, &wy, &wz, &hx, &hy, &hz) == 8); + ok = (sscanf(format.c_str(), "%lfx%lf,%lf,%lf,%lf,%lf,%lf,%lf", &w, &h, + &wx, &wy, &wz, &hx, &hy, &hz) == 8); else ok = (sscanf(format.c_str(), "%lfx%lf", &w, &h) == 2); if(!ok) @@ -170,36 +208,36 @@ void drawContext::drawImage(const std::string &name, double x, double y, double } imgtex *img; - if(!_imageTextures.count(file)){ + if(!_imageTextures.count(file)) { img = &_imageTextures[file]; file = FixRelativePath(GModel::current()->getFileName(), file); - if(!generateTextureForImage(file, 1, img->tex, img->w, img->h)){ + if(!generateTextureForImage(file, 1, img->tex, img->w, img->h)) { Msg::Error("Problem generating image texture"); return; } } - else{ + else { img = &_imageTextures[file]; } - if(!img->tex){ + if(!img->tex) { Msg::Error("No texture for image"); return; } - if(w == 0 && h == 0){ + if(w == 0 && h == 0) { w = img->w; h = img->h; } - else if(h == 0){ + else if(h == 0) { h = w * img->h / img->w; } - else if(w == 0){ + else if(w == 0) { w = h * img->w / img->h; } GLboolean valid = GL_TRUE; GLint matrixMode = 0; - if(billboard){ + if(billboard) { glRasterPos3d(x, y, z); GLfloat pos[4]; glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); @@ -213,21 +251,43 @@ void drawContext::drawImage(const std::string &name, double x, double y, double double fact = isHighResolution() ? 2. : 1.; glOrtho((double)viewport[0], (double)viewport[2] * fact, (double)viewport[1], (double)viewport[3] * fact, -1, 1); - x = pos[0]; y = pos[1]; z = 0; + x = pos[0]; + y = pos[1]; + z = 0; w *= fact * s[0] / pixel_equiv_x; h *= fact * s[1] / pixel_equiv_y; glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid); } - if(valid == GL_TRUE){ - switch(align){ - case 1: x -= w/2.; break; // bottom center - case 2: x -= w; break; // bottom right - case 3: y -= h; break; // top left - case 4: x -= w/2.; y -= h; break; // top center - case 5: x -= w; y -= h; break; // top right - case 6: y -= h/2.; break; // center left - case 7: x -= w/2.; y -= h/2.; break; // center center - case 8: x -= w; y -= h/2.; break; // center right + if(valid == GL_TRUE) { + switch(align) { + case 1: + x -= w / 2.; + break; // bottom center + case 2: + x -= w; + break; // bottom right + case 3: + y -= h; + break; // top left + case 4: + x -= w / 2.; + y -= h; + break; // top center + case 5: + x -= w; + y -= h; + break; // top right + case 6: + y -= h / 2.; + break; // center left + case 7: + x -= w / 2.; + y -= h / 2.; + break; // center center + case 8: + x -= w; + y -= h / 2.; + break; // center right default: break; } glEnable(GL_BLEND); @@ -236,15 +296,19 @@ void drawContext::drawImage(const std::string &name, double x, double y, double glBindTexture(GL_TEXTURE_2D, img->tex); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin(GL_QUADS); - glTexCoord2f(1.0f, 1.0f); glVertex3d(x+wx*w, y+wy*w, z+wz*w); - glTexCoord2f(1.0f, 0.0f); glVertex3d(x+wx*w+hx*h, y+wy*w+hy*h, z+wz*w+hz*h); - glTexCoord2f(0.0f, 0.0f); glVertex3d(x+hx*h, y+hy*h, z+hz*h); - glTexCoord2f(0.0f, 1.0f); glVertex3d(x, y, z); + glTexCoord2f(1.0f, 1.0f); + glVertex3d(x + wx * w, y + wy * w, z + wz * w); + glTexCoord2f(1.0f, 0.0f); + glVertex3d(x + wx * w + hx * h, y + wy * w + hy * h, z + wz * w + hz * h); + glTexCoord2f(0.0f, 0.0f); + glVertex3d(x + hx * h, y + hy * h, z + hz * h); + glTexCoord2f(0.0f, 1.0f); + glVertex3d(x, y, z); glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); } - if(billboard){ + if(billboard) { glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -253,77 +317,81 @@ void drawContext::drawImage(const std::string &name, double x, double y, double } void drawContext::drawCube(double x, double y, double z, double val[9], - int light) + int light) { - double d0[3] = {val[0],val[1],val[2]}; - double d1[3] = {val[3],val[4],val[5]}; - double d2[3] = {val[6],val[7],val[8]}; - - double x0[3] = {x + d1[0] + d1[0] + d2[0] , x + d0[1] + d1[1] + d2[1] , z + d0[2] + d1[2] + d2[2] }; - double x1[3] = {x - d1[0] + d1[0] + d2[0] , x - d0[1] + d1[1] + d2[1] , z - d0[2] + d1[2] + d2[2] }; - double x2[3] = {x - d1[0] - d1[0] + d2[0] , x - d0[1] - d1[1] + d2[1] , z - d0[2] - d1[2] + d2[2] }; - double x3[3] = {x + d1[0] - d1[0] + d2[0] , x + d0[1] - d1[1] + d2[1] , z + d0[2] - d1[2] + d2[2] }; - - double x4[3] = {x + d1[0] + d1[0] - d2[0] , x + d0[1] + d1[1] - d2[1] , z + d0[2] + d1[2] - d2[2] }; - double x5[3] = {x - d1[0] + d1[0] - d2[0] , x - d0[1] + d1[1] - d2[1] , z - d0[2] + d1[2] - d2[2] }; - double x6[3] = {x - d1[0] - d1[0] - d2[0] , x - d0[1] - d1[1] - d2[1] , z - d0[2] - d1[2] - d2[2] }; - double x7[3] = {x + d1[0] - d1[0] - d2[0] , x + d0[1] - d1[1] - d2[1] , z + d0[2] - d1[2] - d2[2] }; + double d0[3] = {val[0], val[1], val[2]}; + double d1[3] = {val[3], val[4], val[5]}; + double d2[3] = {val[6], val[7], val[8]}; + + double x0[3] = {x + d1[0] + d1[0] + d2[0], x + d0[1] + d1[1] + d2[1], + z + d0[2] + d1[2] + d2[2]}; + double x1[3] = {x - d1[0] + d1[0] + d2[0], x - d0[1] + d1[1] + d2[1], + z - d0[2] + d1[2] + d2[2]}; + double x2[3] = {x - d1[0] - d1[0] + d2[0], x - d0[1] - d1[1] + d2[1], + z - d0[2] - d1[2] + d2[2]}; + double x3[3] = {x + d1[0] - d1[0] + d2[0], x + d0[1] - d1[1] + d2[1], + z + d0[2] - d1[2] + d2[2]}; + + double x4[3] = {x + d1[0] + d1[0] - d2[0], x + d0[1] + d1[1] - d2[1], + z + d0[2] + d1[2] - d2[2]}; + double x5[3] = {x - d1[0] + d1[0] - d2[0], x - d0[1] + d1[1] - d2[1], + z - d0[2] + d1[2] - d2[2]}; + double x6[3] = {x - d1[0] - d1[0] - d2[0], x - d0[1] - d1[1] - d2[1], + z - d0[2] - d1[2] - d2[2]}; + double x7[3] = {x + d1[0] - d1[0] - d2[0], x + d0[1] - d1[1] - d2[1], + z + d0[2] - d1[2] - d2[2]}; if(light) glEnable(GL_LIGHTING); glPushMatrix(); glBegin(GL_POLYGON); - glColor3f( x0[0], x0[1], x0[2]); - glColor3f( x1[0], x1[1], x1[2]); - glColor3f( x2[0], x2[1], x2[2]); - glColor3f( x3[0], x3[1], x3[2]); + glColor3f(x0[0], x0[1], x0[2]); + glColor3f(x1[0], x1[1], x1[2]); + glColor3f(x2[0], x2[1], x2[2]); + glColor3f(x3[0], x3[1], x3[2]); glEnd(); glBegin(GL_POLYGON); - glColor3f( x4[0], x4[1], x4[2]); - glColor3f( x7[0], x7[1], x7[2]); - glColor3f( x6[0], x6[1], x6[2]); - glColor3f( x5[0], x5[1], x5[2]); + glColor3f(x4[0], x4[1], x4[2]); + glColor3f(x7[0], x7[1], x7[2]); + glColor3f(x6[0], x6[1], x6[2]); + glColor3f(x5[0], x5[1], x5[2]); glEnd(); glBegin(GL_POLYGON); - glColor3f( x0[0], x0[1], x0[2]); - glColor3f( x3[0], x3[1], x3[2]); - glColor3f( x7[0], x7[1], x7[2]); - glColor3f( x4[0], x4[1], x4[2]); + glColor3f(x0[0], x0[1], x0[2]); + glColor3f(x3[0], x3[1], x3[2]); + glColor3f(x7[0], x7[1], x7[2]); + glColor3f(x4[0], x4[1], x4[2]); glEnd(); - glBegin(GL_POLYGON); - glColor3f( x1[0], x1[1], x1[2]); - glColor3f( x5[0], x5[1], x5[2]); - glColor3f( x6[0], x6[1], x6[2]); - glColor3f( x2[0], x2[1], x2[2]); + glColor3f(x1[0], x1[1], x1[2]); + glColor3f(x5[0], x5[1], x5[2]); + glColor3f(x6[0], x6[1], x6[2]); + glColor3f(x2[0], x2[1], x2[2]); glEnd(); - glBegin(GL_POLYGON); - glColor3f( x0[0], x0[1], x0[2]); - glColor3f( x4[0], x4[1], x4[2]); - glColor3f( x5[0], x5[1], x5[2]); - glColor3f( x1[0], x1[1], x1[2]); + glColor3f(x0[0], x0[1], x0[2]); + glColor3f(x4[0], x4[1], x4[2]); + glColor3f(x5[0], x5[1], x5[2]); + glColor3f(x1[0], x1[1], x1[2]); glEnd(); - glBegin(GL_POLYGON); - glColor3f( x3[0], x3[1], x3[2]); - glColor3f( x2[0], x2[1], x2[2]); - glColor3f( x6[0], x6[1], x6[2]); - glColor3f( x7[0], x7[1], x7[2]); + glColor3f(x3[0], x3[1], x3[2]); + glColor3f(x2[0], x2[1], x2[2]); + glColor3f(x6[0], x6[1], x6[2]); + glColor3f(x7[0], x7[1], x7[2]); glEnd(); glPopMatrix(); glDisable(GL_LIGHTING); } - -void drawContext::drawSphere(double R, double x, double y, double z, - int n1, int n2, int light) +void drawContext::drawSphere(double R, double x, double y, double z, int n1, + int n2, int light) { if(light) glEnable(GL_LIGHTING); glPushMatrix(); @@ -333,41 +401,49 @@ void drawContext::drawSphere(double R, double x, double y, double z, glDisable(GL_LIGHTING); } -void drawContext::drawEllipse(double x, double y, double z, float v0[3], float v1[3], - int light) +void drawContext::drawEllipse(double x, double y, double z, float v0[3], + float v1[3], int light) { if(light) glEnable(GL_LIGHTING); glPushMatrix(); - GLfloat m[16] = { - v0[0], v0[1], v0[2], .0f, - v1[0], v1[1], v1[2], .0f, - v0[1]*v1[2]-v0[2]*v1[1], v0[2]*v1[0]-v0[0]*v1[2], v0[0]*v1[1]-v0[1]*v1[0], .0f, - (GLfloat)x, (GLfloat)y, (GLfloat)z, 1.f - }; + GLfloat m[16] = {v0[0], + v0[1], + v0[2], + .0f, + v1[0], + v1[1], + v1[2], + .0f, + v0[1] * v1[2] - v0[2] * v1[1], + v0[2] * v1[0] - v0[0] * v1[2], + v0[0] * v1[1] - v0[1] * v1[0], + .0f, + (GLfloat)x, + (GLfloat)y, + (GLfloat)z, + 1.f}; glMultMatrixf(m); glCallList(_displayLists + 2); glPopMatrix(); glDisable(GL_LIGHTING); } -void drawContext::drawEllipsoid(double x, double y, double z, float v0[3], float v1[3], - float v2[3], int light) +void drawContext::drawEllipsoid(double x, double y, double z, float v0[3], + float v1[3], float v2[3], int light) { if(light) glEnable(GL_LIGHTING); glPushMatrix(); - GLfloat m[16] = { - v0[0], v0[1], v0[2], .0f, - v1[0], v1[1], v1[2], .0f, - v2[0], v2[1], v2[2], .0f, - (GLfloat)x, (GLfloat)y, (GLfloat)z, 1.f - }; + GLfloat m[16] = {v0[0], v0[1], v0[2], .0f, v1[0], v1[1], + v1[2], .0f, v2[0], v2[1], v2[2], .0f, + (GLfloat)x, (GLfloat)y, (GLfloat)z, 1.f}; glMultMatrixf(m); glCallList(_displayLists + 0); glPopMatrix(); glDisable(GL_LIGHTING); } -void drawContext::drawSphere(double size, double x, double y, double z, int light) +void drawContext::drawSphere(double size, double x, double y, double z, + int light) { double ss = size * pixel_equiv_x / s[0]; // size is in pixels if(light) glEnable(GL_LIGHTING); @@ -380,8 +456,8 @@ void drawContext::drawSphere(double size, double x, double y, double z, int ligh } void drawContext::drawTaperedCylinder(double width, double val1, double val2, - double ValMin, double ValMax, - double *x, double *y, double *z, int light) + double ValMin, double ValMax, double *x, + double *y, double *z, int light) { if(light) glEnable(GL_LIGHTING); @@ -397,7 +473,7 @@ void drawContext::drawTaperedCylinder(double width, double val1, double val2, double axis[3], phi; prodve(zdir, vdir, axis); double const cosphi = prosca(zdir, vdir); - if(!norme(axis)){ + if(!norme(axis)) { axis[0] = 0.; axis[1] = 1.; axis[2] = 0.; @@ -407,13 +483,15 @@ void drawContext::drawTaperedCylinder(double width, double val1, double val2, glPushMatrix(); glTranslated(x[0], y[0], z[0]); glRotated(phi, axis[0], axis[1], axis[2]); - gluCylinder(_quadric, radius1, radius2, length, CTX::instance()->quadricSubdivisions, 1); + gluCylinder(_quadric, radius1, radius2, length, + CTX::instance()->quadricSubdivisions, 1); glPopMatrix(); glDisable(GL_LIGHTING); } -void drawContext::drawCylinder(double width, double *x, double *y, double *z, int light) +void drawContext::drawCylinder(double width, double *x, double *y, double *z, + int light) { if(light) glEnable(GL_LIGHTING); @@ -427,7 +505,7 @@ void drawContext::drawCylinder(double width, double *x, double *y, double *z, in double axis[3], phi; prodve(zdir, vdir, axis); double const cosphi = prosca(zdir, vdir); - if(!norme(axis)){ + if(!norme(axis)) { axis[0] = 0.; axis[1] = 1.; axis[2] = 0.; @@ -437,16 +515,16 @@ void drawContext::drawCylinder(double width, double *x, double *y, double *z, in glPushMatrix(); glTranslated(x[0], y[0], z[0]); glRotated(phi, axis[0], axis[1], axis[2]); - gluCylinder(_quadric, radius, radius, length, CTX::instance()->quadricSubdivisions, 1); + gluCylinder(_quadric, radius, radius, length, + CTX::instance()->quadricSubdivisions, 1); glPopMatrix(); glDisable(GL_LIGHTING); } -static void drawSimpleVector(int arrow, int fill, - double x, double y, double z, - double dx, double dy, double dz, - double d, int light) +static void drawSimpleVector(int arrow, int fill, double x, double y, double z, + double dx, double dy, double dz, double d, + int light) { double n[3], t[3], u[3]; @@ -482,7 +560,7 @@ static void drawSimpleVector(int arrow, int fill, double b = CTX::instance()->arrowRelHeadRadius * d; - if(arrow){ + if(arrow) { double f1 = CTX::instance()->arrowRelStemLength; double f2 = (1 - 2. * CTX::instance()->arrowRelStemRadius) * f1; // hack :-) @@ -537,47 +615,47 @@ static void drawSimpleVector(int arrow, int fill, glEnd(); } } - else{ // simple pyramid - if(fill){ - double top[3] = { x+dx, y+dy, z+dz }; - double tp[3] = { x+b*t[0], y+b*t[1], z+b*t[2] }; - double tm[3] = { x-b*t[0], y-b*t[1], z-b*t[2] }; - double up[3] = { x+b*u[0], y+b*u[1], z+b*u[2] }; - double um[3] = { x-b*u[0], y-b*u[1], z-b*u[2] }; + else { // simple pyramid + if(fill) { + double top[3] = {x + dx, y + dy, z + dz}; + double tp[3] = {x + b * t[0], y + b * t[1], z + b * t[2]}; + double tm[3] = {x - b * t[0], y - b * t[1], z - b * t[2]}; + double up[3] = {x + b * u[0], y + b * u[1], z + b * u[2]}; + double um[3] = {x - b * u[0], y - b * u[1], z - b * u[2]}; double nn[3]; if(light && fill) glEnable(GL_LIGHTING); glBegin(GL_TRIANGLES); - if(light){ - normal3points(tm[0], tm[1], tm[2], um[0], um[1], um[2], - top[0], top[1], top[2], nn); + if(light) { + normal3points(tm[0], tm[1], tm[2], um[0], um[1], um[2], top[0], top[1], + top[2], nn); glNormal3dv(nn); } glVertex3d(tm[0], tm[1], tm[2]); glVertex3d(um[0], um[1], um[2]); glVertex3d(top[0], top[1], top[2]); - if(light){ - normal3points(um[0], um[1], um[2], tp[0], tp[1], tp[2], - top[0], top[1], top[2], nn); + if(light) { + normal3points(um[0], um[1], um[2], tp[0], tp[1], tp[2], top[0], top[1], + top[2], nn); glNormal3dv(nn); } glVertex3d(um[0], um[1], um[2]); glVertex3d(tp[0], tp[1], tp[2]); glVertex3d(top[0], top[1], top[2]); - if(light){ - normal3points(tp[0], tp[1], tp[2], up[0], up[1], up[2], - top[0], top[1], top[2], nn); + if(light) { + normal3points(tp[0], tp[1], tp[2], up[0], up[1], up[2], top[0], top[1], + top[2], nn); glNormal3dv(nn); } glVertex3d(tp[0], tp[1], tp[2]); glVertex3d(up[0], up[1], up[2]); glVertex3d(top[0], top[1], top[2]); - if(light){ - normal3points(up[0], up[1], up[2], tm[0], tm[1], tm[2], - top[0], top[1], top[2], nn); + if(light) { + normal3points(up[0], up[1], up[2], tm[0], tm[1], tm[2], top[0], top[1], + top[2], nn); glNormal3dv(nn); } glVertex3d(up[0], up[1], up[2]); @@ -586,42 +664,40 @@ static void drawSimpleVector(int arrow, int fill, glEnd(); glDisable(GL_LIGHTING); } - else{ + else { glBegin(GL_LINE_LOOP); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); glEnd(); glBegin(GL_LINES); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + dx, y + dy, z + dz); - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + dx, y + dy, z + dz); - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + dx, y + dy, z + dz); - glVertex3d (x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); + glVertex3d(x + dx, y + dy, z + dz); glEnd(); } } - } -void drawContext::drawArrow3d(double x, double y, double z, - double dx, double dy, double dz, - double length, int light) +void drawContext::drawArrow3d(double x, double y, double z, double dx, + double dy, double dz, double length, int light) { double zdir[3] = {0., 0., 1.}; double vdir[3] = {dx / length, dy / length, dz / length}; double axis[3]; prodve(zdir, vdir, axis); double const cosphi = prosca(zdir, vdir); - if(!norme(axis)){ + if(!norme(axis)) { axis[0] = 0.; axis[1] = 1.; axis[2] = 0.; @@ -645,7 +721,7 @@ void drawContext::drawVector(int Type, int Fill, double x, double y, double z, if(length == 0.0) return; - switch(Type){ + switch(Type) { case 1: glBegin(GL_LINES); glVertex3d(x, y, z); @@ -653,7 +729,7 @@ void drawContext::drawVector(int Type, int Fill, double x, double y, double z, glEnd(); break; case 6: - if(CTX::instance()->arrowRelHeadRadius){ + if(CTX::instance()->arrowRelHeadRadius) { glBegin(GL_POINTS); glVertex3d(x + dx, y + dy, z + dz); glEnd(); @@ -661,56 +737,47 @@ void drawContext::drawVector(int Type, int Fill, double x, double y, double z, glBegin(GL_LINES); glVertex3d(x + dx, y + dy, z + dz); // color gradient - glColor4ubv((GLubyte *) & CTX::instance()->color.bg); + glColor4ubv((GLubyte *)&CTX::instance()->color.bg); glVertex3d(x, y, z); glEnd(); break; - case 2: - drawSimpleVector(1, Fill, x, y, z, dx, dy, dz, length, light); - break; - case 3: - drawSimpleVector(0, Fill, x, y, z, dx, dy, dz, length, light); - break; + case 2: drawSimpleVector(1, Fill, x, y, z, dx, dy, dz, length, light); break; + case 3: drawSimpleVector(0, Fill, x, y, z, dx, dy, dz, length, light); break; case 4: - default: - drawArrow3d(x, y, z, dx, dy, dz, length, light); - break; + default: drawArrow3d(x, y, z, dx, dy, dz, length, light); break; } } -class point{ - public: +class point { +public: double x, y, z; bool valid; point() : x(0.), y(0.), z(0.), valid(false) {} point(double xi, double yi, double zi) : x(xi), y(yi), z(zi), valid(true) {} }; -class plane{ - private: +class plane { +private: double _a, _b, _c, _d; - public: + +public: plane(double a, double b, double c, double d) : _a(a), _b(b), _c(c), _d(d) {} - double val(point &p) - { - return _a * p.x + _b * p.y + _c * p.z + _d; - }; + double val(point &p) { return _a * p.x + _b * p.y + _c * p.z + _d; }; point intersect(point &p1, point &p2) { double v1 = val(p1), v2 = val(p2); - if(fabs(v1) < 1.e-12){ + if(fabs(v1) < 1.e-12) { if(fabs(v2) < 1.e-12) return point(); else return point(p1.x, p1.y, p1.z); } - else if(fabs(v2) < 1.e-12){ + else if(fabs(v2) < 1.e-12) { return point(p2.x, p2.y, p2.z); } - else if(v1 * v2 < 0.){ - double coef = - v1 / (v2 - v1); - return point(coef * (p2.x - p1.x) + p1.x, - coef * (p2.y - p1.y) + p1.y, + else if(v1 * v2 < 0.) { + double coef = -v1 / (v2 - v1); + return point(coef * (p2.x - p1.x) + p1.x, coef * (p2.y - p1.y) + p1.y, coef * (p2.z - p1.z) + p1.z); } else @@ -718,9 +785,8 @@ class plane{ } }; -void drawContext::drawBox(double xmin, double ymin, double zmin, - double xmax, double ymax, double zmax, - bool labels) +void drawContext::drawBox(double xmin, double ymin, double zmin, double xmax, + double ymax, double zmax, bool labels) { glBegin(GL_LINE_LOOP); glVertex3d(xmin, ymin, zmin); @@ -744,16 +810,14 @@ void drawContext::drawBox(double xmin, double ymin, double zmin, glVertex3d(xmin, ymax, zmin); glVertex3d(xmin, ymax, zmax); glEnd(); - if(labels){ + if(labels) { char label[256]; double offset = 0.3 * CTX::instance()->glFontSize * pixel_equiv_x; sprintf(label, "(%g,%g,%g)", xmin, ymin, zmin); - drawString(label, xmin + offset / s[0], - ymin + offset / s[1], + drawString(label, xmin + offset / s[0], ymin + offset / s[1], zmin + offset / s[2]); sprintf(label, "(%g,%g,%g)", xmax, ymax, zmax); - drawString(label, xmax + offset / s[0], - ymax + offset / s[1], + drawString(label, xmax + offset / s[0], ymax + offset / s[1], zmax + offset / s[2]); } } @@ -783,16 +847,10 @@ void drawContext::drawPlaneInBoundingBox(double xmin, double ymin, double zmin, edge[10] = pl.intersect(p6, p7); edge[11] = pl.intersect(p7, p8); - int face[6][4] = { - {0, 2, 4, 8}, - {0, 1, 3, 5}, - {1, 2, 7, 9}, - {3, 4, 6, 10}, - {5, 6, 7, 11}, - {8, 9, 10, 11} - }; + int face[6][4] = {{0, 2, 4, 8}, {0, 1, 3, 5}, {1, 2, 7, 9}, + {3, 4, 6, 10}, {5, 6, 7, 11}, {8, 9, 10, 11}}; - double n[3] = {a,b,c}, ll = 50; + double n[3] = {a, b, c}, ll = 50; norme(n); if(CTX::instance()->arrowRelStemRadius) ll = CTX::instance()->lineWidth / CTX::instance()->arrowRelStemRadius; @@ -804,23 +862,22 @@ void drawContext::drawPlaneInBoundingBox(double xmin, double ymin, double zmin, int n_shade = 0; point p_shade[24]; - for(int i = 0; i < 6; i++){ + for(int i = 0; i < 6; i++) { int nb = 0; point p[4]; - for(int j = 0; j < 4; j++){ - if(edge[face[i][j]].valid == true) - p[nb++] = edge[face[i][j]]; + for(int j = 0; j < 4; j++) { + if(edge[face[i][j]].valid == true) p[nb++] = edge[face[i][j]]; } - if(nb > 1){ - for(int j = 1; j < nb; j++){ - double xx[2] = {p[j].x, p[j-1].x}; - double yy[2] = {p[j].y, p[j-1].y}; - double zz[2] = {p[j].z, p[j-1].z}; + if(nb > 1) { + for(int j = 1; j < nb; j++) { + double xx[2] = {p[j].x, p[j - 1].x}; + double yy[2] = {p[j].y, p[j - 1].y}; + double zz[2] = {p[j].z, p[j - 1].z}; drawCylinder(CTX::instance()->lineWidth, xx, yy, zz, 1); } - for(int j = 0; j < nb; j++){ + for(int j = 0; j < nb; j++) { drawArrow3d(p[j].x, p[j].y, p[j].z, n[0], n[1], n[2], length, 1); - if(shade){ + if(shade) { p_shade[n_shade].x = p[j].x; p_shade[n_shade].y = p[j].y; p_shade[n_shade].z = p[j].z; @@ -830,7 +887,7 @@ void drawContext::drawPlaneInBoundingBox(double xmin, double ymin, double zmin, } } - if(shade){ + if(shade) { // disable two-side lighting beacuse polygon can overlap itself GLboolean twoside; glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &twoside); @@ -838,7 +895,7 @@ void drawContext::drawPlaneInBoundingBox(double xmin, double ymin, double zmin, glEnable(GL_LIGHTING); glBegin(GL_POLYGON); glNormal3d(n[0], n[1], n[2]); - for(int j = 0; j < n_shade; j++){ + for(int j = 0; j < n_shade; j++) { glVertex3d(p_shade[j].x, p_shade[j].y, p_shade[j].z); } glEnd(); diff --git a/Graphics/drawGraph2d.cpp b/Graphics/drawGraph2d.cpp index b7291353f5568a7d9d61f41e2bb4d91027ac9215..48ceafe410ce031c6f8b30d4196eec1cae10176e 100644 --- a/Graphics/drawGraph2d.cpp +++ b/Graphics/drawGraph2d.cpp @@ -14,7 +14,8 @@ int drawContext::fix2dCoordinates(double *x, double *y) { - int ret = (*x > 99999 && *y > 99999) ? 3 : (*y > 99999) ? 2 : (*x > 99999) ? 1 : 0; + int ret = + (*x > 99999 && *y > 99999) ? 3 : (*y > 99999) ? 2 : (*x > 99999) ? 1 : 0; if(*x < 0) // measure from right border *x = viewport[2] + *x; @@ -32,23 +33,23 @@ int drawContext::fix2dCoordinates(double *x, double *y) void drawContext::drawText2d() { - for(unsigned int i = 0; i < PView::list.size(); i++){ + for(unsigned int i = 0; i < PView::list.size(); i++) { PViewData *data = PView::list[i]->getData(); PViewOptions *opt = PView::list[i]->getOptions(); - if(opt->visible && opt->drawStrings && isVisible(PView::list[i])){ - if(render_mode == drawContext::GMSH_SELECT){ + if(opt->visible && opt->drawStrings && isVisible(PView::list[i])) { + if(render_mode == drawContext::GMSH_SELECT) { glPushName(5); glPushName(PView::list[i]->getIndex()); } - glColor4ubv((GLubyte *) & opt->color.text2d); - for(int j = 0; j < data->getNumStrings2D(); j++){ + glColor4ubv((GLubyte *)&opt->color.text2d); + for(int j = 0; j < data->getNumStrings2D(); j++) { double x, y, style; std::string str; data->getString2D(j, opt->timeStep, str, x, y, style); fix2dCoordinates(&x, &y); drawString(str, x, y, 0., style); } - if(render_mode == drawContext::GMSH_SELECT){ + if(render_mode == drawContext::GMSH_SELECT) { glPopName(); glPopName(); } @@ -67,14 +68,14 @@ static bool getGraphData(PView *p, std::vector<double> &x, double &xmin, int numy = 0; if(opt->type == PViewOptions::Plot2D || - opt->type == PViewOptions::Plot2DSpace){ + opt->type == PViewOptions::Plot2DSpace) { numy = 1; } - else if(opt->type == PViewOptions::Plot2DTime){ + else if(opt->type == PViewOptions::Plot2DTime) { numy = 0; - for(int ent = 0; ent < data->getNumEntities(0); ent++){ + for(int ent = 0; ent < data->getNumEntities(0); ent++) { if(data->skipEntity(0, ent)) continue; - for(int ele = 0; ele < data->getNumElements(0, ent); ele++){ + for(int ele = 0; ele < data->getNumElements(0, ent); ele++) { if(data->skipElement(0, ent, ele, true)) continue; if(opt->skipElement(data->getType(0, ent, ele))) continue; if(data->getDimension(0, ent, ele) >= 2) continue; @@ -90,7 +91,7 @@ static bool getGraphData(PView *p, std::vector<double> &x, double &xmin, opt->type == PViewOptions::Plot2DSpace); int which2d = 0; - if(opt->type == PViewOptions::Plot2D){ + if(opt->type == PViewOptions::Plot2D) { SBoundingBox3d bbox = p->getData()->getBoundingBox(); SPoint3 min = bbox.min(); SPoint3 max = bbox.max(); @@ -105,57 +106,54 @@ static bool getGraphData(PView *p, std::vector<double> &x, double &xmin, SPoint3 p0(0., 0., 0.); numy = 0; - for(int ent = 0; ent < data->getNumEntities(0); ent++){ + for(int ent = 0; ent < data->getNumEntities(0); ent++) { if(data->skipEntity(0, ent)) continue; - for(int ele = 0; ele < data->getNumElements(0, ent); ele++){ + for(int ele = 0; ele < data->getNumElements(0, ent); ele++) { if(data->skipElement(0, ent, ele, true)) continue; if(opt->skipElement(data->getType(0, ent, ele))) continue; if(data->getDimension(0, ent, ele) >= 2) continue; int numNodes = data->getNumNodes(0, ent, ele); // reorder the nodes for high order line elements std::vector<int> reorder(numNodes); - if(numNodes < 3){ - for(int j = 0; j < numNodes; j++) - reorder[j] = j; + if(numNodes < 3) { + for(int j = 0; j < numNodes; j++) reorder[j] = j; } - else{ + else { reorder[0] = 0; reorder[numNodes - 1] = 1; - for(int j = 1; j < numNodes - 1; j++) - reorder[j] = 1 + j; + for(int j = 1; j < numNodes - 1; j++) reorder[j] = 1 + j; } - for(int ts = space ? opt->timeStep : 0; ts < opt->timeStep + 1; ts++){ + for(int ts = space ? opt->timeStep : 0; ts < opt->timeStep + 1; ts++) { if(!data->hasTimeStep(ts)) continue; int numComp = data->getNumComponents(ts, ent, ele); - for(int j = 0; j < numNodes; j++){ + for(int j = 0; j < numNodes; j++) { double val[9], xyz[3]; data->getNode(ts, ent, ele, reorder[j], xyz[0], xyz[1], xyz[2]); for(int k = 0; k < numComp; k++) data->getValue(ts, ent, ele, reorder[j], k, val[k]); double vy = ComputeScalarRep(numComp, val); - if(opt->type == PViewOptions::Plot2D){ + if(opt->type == PViewOptions::Plot2D) { x.push_back(xyz[which2d]); y[0].push_back(vy); } - else if(opt->type == PViewOptions::Plot2DSpace){ + else if(opt->type == PViewOptions::Plot2DSpace) { // compute curvilinear coordinate - if(x.empty()){ + if(x.empty()) { p0 = SPoint3(xyz[0], xyz[1], xyz[2]); x.push_back(ComputeScalarRep(3, xyz)); } - else{ + else { SPoint3 p1(xyz[0], xyz[1], xyz[2]); x.push_back(x.back() + p0.distance(p1)); p0 = p1; } y[0].push_back(vy); } - else{ + else { if(!numy) x.push_back(data->getTime(ts)); y[numy].push_back(vy); } - } } numy++; @@ -164,41 +162,39 @@ static bool getGraphData(PView *p, std::vector<double> &x, double &xmin, if(x.empty()) return false; - if(opt->abscissaRangeType == PViewOptions::Custom){ + if(opt->abscissaRangeType == PViewOptions::Custom) { std::vector<double> x2; std::vector<std::vector<double> > y2(y.size()); - for(unsigned int i = 0; i < x.size(); i++){ - if(x[i] >= opt->customAbscissaMin && x[i] <= opt->customAbscissaMax){ + for(unsigned int i = 0; i < x.size(); i++) { + if(x[i] >= opt->customAbscissaMin && x[i] <= opt->customAbscissaMax) { x2.push_back(x[i]); - for(unsigned int j = 0; j < y2.size(); j++) - y2[j].push_back(y[j][i]); + for(unsigned int j = 0; j < y2.size(); j++) y2[j].push_back(y[j][i]); } } x = x2; y = y2; } - if(space){ + if(space) { xmin = xmax = x[0]; - for(unsigned int i = 1; i < x.size(); i++){ + for(unsigned int i = 1; i < x.size(); i++) { xmin = std::min(xmin, x[i]); xmax = std::max(xmax, x[i]); } } - else{ + else { xmin = data->getTime(0); xmax = data->getTime(data->getNumTimeSteps() - 1); } if(opt->scaleType == PViewOptions::Logarithmic) for(unsigned int i = 0; i < y.size(); i++) - for(unsigned int j = 0; j < y[i].size(); j++) - y[i][j] = log10(y[i][j]); + for(unsigned int j = 0; j < y[i].size(); j++) y[i][j] = log10(y[i][j]); ymin = VAL_INF; ymax = -VAL_INF; - for(unsigned int i = 0; i < y.size(); i++){ - for(unsigned int j = 0; j < y[i].size(); j++){ + for(unsigned int i = 0; i < y.size(); i++) { + for(unsigned int j = 0; j < y[i].size(); j++) { ymin = std::min(ymin, y[i][j]); ymax = std::max(ymax, y[i][j]); } @@ -220,12 +216,12 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, if(width <= 0 || height <= 0) return; - if(!overlay && !inModelCoordinates){ + if(!overlay && !inModelCoordinates) { int alpha = CTX::instance()->unpackAlpha(opt->color.background2d); - if(alpha != 0){ + if(alpha != 0) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - glColor4ubv((GLubyte *) & opt->color.background2d); + glColor4ubv((GLubyte *)&opt->color.background2d); glBegin(GL_QUADS); glVertex2d(xleft, ytop); glVertex2d(xleft + width, ytop); @@ -238,11 +234,12 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, // total font height double font_h = drawContext::global()->getStringHeight() ? - drawContext::global()->getStringHeight() : 1; + drawContext::global()->getStringHeight() : + 1; // height above ref. point double font_a = font_h - drawContext::global()->getStringDescent(); - if(inModelCoordinates){ + if(inModelCoordinates) { double ss = ctx->pixel_equiv_x / ctx->s[0]; font_h *= ss; font_a *= ss; @@ -260,15 +257,15 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, gl2psLineWidth((float)(CTX::instance()->lineWidth * CTX::instance()->print.epsLineWidthFactor)); - glColor4ubv((GLubyte *) & opt->color.axes); + glColor4ubv((GLubyte *)&opt->color.axes); // bare axes - if(!overlay){ + if(!overlay) { glBegin(GL_LINE_STRIP); glVertex2d(xleft, ytop); glVertex2d(xleft, ytop - height); glVertex2d(xleft + width, ytop - height); - if(opt->axes > 1){ + if(opt->axes > 1) { glVertex2d(xleft + width, ytop); glVertex2d(xleft, ytop); } @@ -278,21 +275,20 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, // y label std::string label = data->getName(); if(opt->type == PViewOptions::Plot2D || - opt->type == PViewOptions::Plot2DSpace){ + opt->type == PViewOptions::Plot2DSpace) { int nt = data->getNumTimeSteps(); - if((opt->showTime == 1 && nt > 1) || opt->showTime == 2){ + if((opt->showTime == 1 && nt > 1) || opt->showTime == 2) { char tmp[256]; sprintf(tmp, opt->format.c_str(), data->getTime(opt->timeStep)); label += std::string(" (") + tmp + ")"; } - else if((opt->showTime == 3 && nt > 1) || opt->showTime == 4){ + else if((opt->showTime == 3 && nt > 1) || opt->showTime == 4) { char tmp[256]; sprintf(tmp, "%d", opt->timeStep); label += std::string(" (") + tmp + ")"; } } - if(opt->scaleType == PViewOptions::Logarithmic) - label = "Log10 " + label; + if(opt->scaleType == PViewOptions::Logarithmic) label = "Log10 " + label; ctx->drawString(label, xleft + (overlay ? width : 0), ytop + font_h + tic, 0, CTX::instance()->glFontTitle, CTX::instance()->glFontEnumTitle, @@ -300,29 +296,29 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, // x label label = opt->axesLabel[0]; - ctx->drawString(label, xleft + width / 2, - ytop - height - 2 * font_h - 2 * tic - overlay * (font_h + tic), 0, - CTX::instance()->glFontTitle, - CTX::instance()->glFontEnumTitle, - CTX::instance()->glFontSizeTitle, 1); + ctx->drawString( + label, xleft + width / 2, + ytop - height - 2 * font_h - 2 * tic - overlay * (font_h + tic), 0, + CTX::instance()->glFontTitle, CTX::instance()->glFontEnumTitle, + CTX::instance()->glFontSizeTitle, 1); // y tics and horizontal grid - if(opt->nbIso > 0){ + if(opt->nbIso > 0) { int nb = opt->nbIso; if(opt->showScale && (opt->nbIso * font_h > height)) nb = (int)floor(height / font_h); double dy = height / (double)nb; double dv = (opt->tmpMax - opt->tmpMin) / (double)nb; - for(int i = 0; i < nb + 1; i++){ + for(int i = 0; i < nb + 1; i++) { glBegin(GL_LINES); glVertex2d(xleft, ytop - i * dy); glVertex2d(xleft + tic, ytop - i * dy); - if(opt->axes > 1){ + if(opt->axes > 1) { glVertex2d(xleft + width - tic, ytop - i * dy); glVertex2d(xleft + width, ytop - i * dy); } glEnd(); - if(opt->axes > 2 && i != 0 && i != nb){ + if(opt->axes > 2 && i != 0 && i != nb) { glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x1111); gl2psEnable(GL2PS_LINE_STIPPLE); @@ -336,22 +332,24 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, gl2psLineWidth((float)(CTX::instance()->lineWidth * CTX::instance()->print.epsLineWidthFactor)); } - if(opt->showScale){ + if(opt->showScale) { char tmp[256]; - sprintf(tmp, opt->format.c_str(), (i == nb) ? opt->tmpMin : - (opt->tmpMax - i * dv)); - if(!overlay){ - ctx->drawStringRight(tmp, xleft - 2 * tic, ytop - i * dy - font_a / 3., 0.); + sprintf(tmp, opt->format.c_str(), + (i == nb) ? opt->tmpMin : (opt->tmpMax - i * dv)); + if(!overlay) { + ctx->drawStringRight(tmp, xleft - 2 * tic, + ytop - i * dy - font_a / 3., 0.); } - else{ - ctx->drawString(tmp, xleft + width + 2 * tic, ytop - i * dy - font_a / 3., 0.); + else { + ctx->drawString(tmp, xleft + width + 2 * tic, + ytop - i * dy - font_a / 3., 0.); } } } } // x tics and vertical grid - if(opt->axesTics[0] > 0){ + if(opt->axesTics[0] > 0) { int nb = opt->axesTics[0]; char tmp[256]; sprintf(tmp, opt->axesFormat[0].c_str(), -M_PI * 1.e4); @@ -363,16 +361,16 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, double dx = width / (double)(nb - 1); double ybot = ytop - height; - for(int i = 0; i < nb; i++){ + for(int i = 0; i < nb; i++) { glBegin(GL_LINES); glVertex2d(xleft + i * dx, ybot); glVertex2d(xleft + i * dx, ybot + tic); - if(opt->axes > 1){ + if(opt->axes > 1) { glVertex2d(xleft + i * dx, ytop); glVertex2d(xleft + i * dx, ytop - tic); } glEnd(); - if(opt->axes > 2 && i != 0 && i != nb - 1){ + if(opt->axes > 2 && i != 0 && i != nb - 1) { glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x1111); gl2psEnable(GL2PS_LINE_STIPPLE); @@ -386,7 +384,7 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, gl2psLineWidth((float)(CTX::instance()->lineWidth * CTX::instance()->print.epsLineWidthFactor)); } - if(opt->showScale){ + if(opt->showScale) { char tmp[256]; if(nb == 1) sprintf(tmp, opt->axesFormat[0].c_str(), xmin); @@ -394,11 +392,11 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, sprintf(tmp, opt->axesFormat[0].c_str(), xmin + i * (xmax - xmin) / (double)(nb - 1)); ctx->drawStringCenter(tmp, xleft + i * dx, - ybot - font_h - tic - overlay * (font_h + tic), 0.); + ybot - font_h - tic - overlay * (font_h + tic), + 0.); } } } - } static std::map<SPoint2, unsigned int> tags; @@ -414,22 +412,20 @@ static unsigned int getTagForGraph2dDataPoint(const SPoint2 &p) return t; } -SPoint2 getGraph2dDataPointForTag(unsigned int tag) -{ - return tags_rev[tag]; -} +SPoint2 getGraph2dDataPointForTag(unsigned int tag) { return tags_rev[tag]; } static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop, double width, double height, double x, double y, double xmin, double xmax, double ymin, double ymax, - bool numeric, bool singlePoint, bool inModelCoordinates) + bool numeric, bool singlePoint, + bool inModelCoordinates) { PViewOptions *opt = p->getOptions(); double px = xleft; if(xmin != xmax) px += (x - xmin) / (xmax - xmin) * width; - if(opt->saturateValues){ + if(opt->saturateValues) { if(y > ymax) y = ymax; else if(y < ymin) @@ -440,23 +436,23 @@ static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop, double py = ybot; if(ymax != ymin) py += (y - ymin) / (ymax - ymin) * height; - if(y >= ymin && y <= ymax){ + if(y >= ymin && y <= ymax) { unsigned int col = opt->getColor(y, ymin, ymax, true); - glColor4ubv((GLubyte *) &col); + glColor4ubv((GLubyte *)&col); - if(singlePoint && ctx->render_mode == drawContext::GMSH_SELECT){ + if(singlePoint && ctx->render_mode == drawContext::GMSH_SELECT) { glPushName(4); glPushName(getTagForGraph2dDataPoint(SPoint2(x, y))); } - if(numeric){ + if(numeric) { double offset = 3; if(inModelCoordinates) offset *= ctx->pixel_equiv_x / ctx->s[0]; char label[256]; sprintf(label, opt->format.c_str(), y); ctx->drawString(label, px + offset, py + offset, 0.); } - else if(singlePoint && (opt->pointType == 1 || opt->pointType == 3)){ + else if(singlePoint && (opt->pointType == 1 || opt->pointType == 3)) { double ps = CTX::instance()->pointSize; if(ctx->isHighResolution()) ps *= CTX::instance()->highResolutionPointSizeFactor; @@ -465,23 +461,22 @@ static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop, else ctx->drawSphere(ps, px, py, 0, 10, 10, opt->light); } - else{ + else { if(singlePoint) glBegin(GL_POINTS); glVertex2d(px, py); if(singlePoint) glEnd(); } - if(singlePoint && ctx->render_mode == drawContext::GMSH_SELECT){ + if(singlePoint && ctx->render_mode == drawContext::GMSH_SELECT) { glPopName(); glPopName(); } - } } -static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double ytop, - double width, double height, std::vector<double> &x, - double xmin, double xmax, +static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, + double ytop, double width, double height, + std::vector<double> &x, double xmin, double xmax, std::vector<std::vector<double> > &y, bool inModelCoordinates) { @@ -494,26 +489,28 @@ static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double yto ps *= CTX::instance()->highResolutionPointSizeFactor; glPointSize((float)ps); - gl2psPointSize((float)(opt->pointSize * CTX::instance()->print.epsPointSizeFactor)); + gl2psPointSize( + (float)(opt->pointSize * CTX::instance()->print.epsPointSizeFactor)); glLineWidth((float)opt->lineWidth); - gl2psLineWidth((float)(opt->lineWidth * CTX::instance()->print.epsLineWidthFactor)); + gl2psLineWidth( + (float)(opt->lineWidth * CTX::instance()->print.epsLineWidthFactor)); if(opt->intervalsType == PViewOptions::Discrete || - opt->intervalsType == PViewOptions::Continuous){ - for(unsigned int i = 0; i < y.size(); i++){ - if(opt->useStipple){ + opt->intervalsType == PViewOptions::Continuous) { + for(unsigned int i = 0; i < y.size(); i++) { + if(opt->useStipple) { glEnable(GL_LINE_STIPPLE); glLineStipple(opt->stipple[i % 10][0], opt->stipple[i % 10][1]); gl2psEnable(GL2PS_LINE_STIPPLE); } glBegin(GL_LINE_STRIP); for(unsigned int j = 0; j < x.size(); j++) - addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], - xmin, xmax, opt->tmpMin, opt->tmpMax, false, false, + addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin, + xmax, opt->tmpMin, opt->tmpMax, false, false, inModelCoordinates); glEnd(); - if(opt->useStipple){ + if(opt->useStipple) { glDisable(GL_LINE_STIPPLE); gl2psDisable(GL2PS_LINE_STIPPLE); } @@ -522,26 +519,26 @@ static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double yto if(opt->intervalsType == PViewOptions::Iso || opt->intervalsType == PViewOptions::Discrete || - opt->intervalsType == PViewOptions::Numeric){ + opt->intervalsType == PViewOptions::Numeric) { for(unsigned int i = 0; i < y.size(); i++) for(unsigned int j = 0; j < x.size(); j++) - addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], - xmin, xmax, opt->tmpMin, opt->tmpMax, false, true, + addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin, + xmax, opt->tmpMin, opt->tmpMax, false, true, inModelCoordinates); } - if(opt->intervalsType == PViewOptions::Numeric){ + if(opt->intervalsType == PViewOptions::Numeric) { for(unsigned int i = 0; i < y.size(); i++) for(unsigned int j = 0; j < x.size(); j++) - addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], - xmin, xmax, opt->tmpMin, opt->tmpMax, true, true, + addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], xmin, + xmax, opt->tmpMin, opt->tmpMax, true, true, inModelCoordinates); } } static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop, - double width, double height, double tic, int overlay=0, - bool inModelCoordinates=false) + double width, double height, double tic, int overlay = 0, + bool inModelCoordinates = false) { std::vector<double> x; std::vector<std::vector<double> > y; @@ -550,15 +547,15 @@ static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop, PViewData *data = p->getData(); PViewOptions *opt = p->getOptions(); - if(opt->rangeType == PViewOptions::Custom){ + if(opt->rangeType == PViewOptions::Custom) { opt->tmpMin = opt->customMin; opt->tmpMax = opt->customMax; } - else if(opt->rangeType == PViewOptions::PerTimeStep){ + else if(opt->rangeType == PViewOptions::PerTimeStep) { opt->tmpMin = data->getMin(opt->timeStep); opt->tmpMax = data->getMax(opt->timeStep); } - else if(opt->abscissaRangeType == PViewOptions::Custom){ + else if(opt->abscissaRangeType == PViewOptions::Custom) { // FIXME: should also compute min/max for reduced abscissa range over all // steps opt->tmpMin = ymin; @@ -569,7 +566,7 @@ static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop, opt->tmpMax = data->getMax(); } - if(opt->scaleType == PViewOptions::Logarithmic){ + if(opt->scaleType == PViewOptions::Logarithmic) { opt->tmpMin = log10(opt->tmpMin); opt->tmpMax = log10(opt->tmpMax); } @@ -582,8 +579,8 @@ static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop, void drawContext::drawGraph2d(bool inModelCoordinates) { - std::vector<PView*> graphs; - for(unsigned int i = 0; i < PView::list.size(); i++){ + std::vector<PView *> graphs; + for(unsigned int i = 0; i < PView::list.size(); i++) { PViewData *data = PView::list[i]->getData(); PViewOptions *opt = PView::list[i]->getOptions(); if(!data->getDirty() && opt->visible && opt->type != PViewOptions::Plot3D && @@ -598,14 +595,14 @@ void drawContext::drawGraph2d(bool inModelCoordinates) double mx = 25, my = 5; // x- and y-margin double xsep = 0., ysep = drawContext::global()->getStringHeight() + tic; char label[1024]; - for(unsigned int i = 0; i < graphs.size(); i++){ + for(unsigned int i = 0; i < graphs.size(); i++) { PViewOptions *opt = graphs[i]->getOptions(); sprintf(label, opt->format.c_str(), -M_PI * 1.e4); xsep = std::max(xsep, drawContext::global()->getStringWidth(label)); } xsep += tic; - if(inModelCoordinates){ + if(inModelCoordinates) { double ss = pixel_equiv_x / s[0]; tic *= ss; mx *= ss; @@ -633,32 +630,31 @@ void drawContext::drawGraph2d(bool inModelCoordinates) int overlay[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double winw = viewport[2] - viewport[0]; double winh = viewport[3] - viewport[1]; - for(unsigned int i = 0; i < graphs.size(); i++){ + for(unsigned int i = 0; i < graphs.size(); i++) { double x = viewport[0] + mx + xsep; double y = viewport[1] + my + 3 * ysep; PView *p = graphs[i]; PViewOptions *opt = graphs[i]->getOptions(); - if(opt->autoPosition == 0 && !inModelCoordinates){ // manual + if(opt->autoPosition == 0 && !inModelCoordinates) { // manual double x = opt->position[0], y = opt->position[1]; int center = fix2dCoordinates(&x, &y); - drawGraph(this, p, - x - (center & 1 ? opt->size[0] / 2. : 0), - y + (center & 2 ? opt->size[1] / 2. : 0), - opt->size[0], opt->size[1], tic); + drawGraph(this, p, x - (center & 1 ? opt->size[0] / 2. : 0), + y + (center & 2 ? opt->size[1] / 2. : 0), opt->size[0], + opt->size[1], tic); } - else if(opt->autoPosition == 1 && !inModelCoordinates){ // automatic - if(graphs.size() == 1){ + else if(opt->autoPosition == 1 && !inModelCoordinates) { // automatic + if(graphs.size() == 1) { double w = winw - 2 * mx - 2 * xsep; double h = winh - 2 * my - 7 * ysep; drawGraph(this, p, x, viewport[3] - y, w, h, tic); } - else if(graphs.size() == 2){ + else if(graphs.size() == 2) { double w = winw - 2 * mx - 2 * xsep; double h = (winh - 3 * my - 12 * ysep) / 2.; if(i == 1) y += (h + my + 5 * ysep); drawGraph(this, p, x, viewport[3] - y, w, h, tic); } - else{ + else { double w = (winw - 3 * mx - 4 * xsep) / 2.; double h = (winh - 3 * my - 12 * ysep) / 2.; if(i == 1 || i == 3) x += (w + mx + 2 * xsep); @@ -666,7 +662,8 @@ void drawContext::drawGraph2d(bool inModelCoordinates) drawGraph(this, p, x, viewport[3] - y, w, h, tic); } } - else if(opt->autoPosition >= 2 && opt->autoPosition <= 11 && !inModelCoordinates){ + else if(opt->autoPosition >= 2 && opt->autoPosition <= 11 && + !inModelCoordinates) { // top left (2), top right (3), bottom left (4), bottom right (5), top // half (6), bottom half (7), left half (8), right half (9), full (10), // top third (11) @@ -689,7 +686,8 @@ void drawContext::drawGraph2d(bool inModelCoordinates) if(opt->axes) overlay[opt->autoPosition] += (opt->axesLabel[0].size() ? 2 : 1); } - else if(opt->autoPosition == 12 && inModelCoordinates){ // in model coordinates + else if(opt->autoPosition == 12 && + inModelCoordinates) { // in model coordinates drawGraph(this, p, opt->position[0], opt->position[1] + opt->size[1], opt->size[0], opt->size[1], tic, 0, true); } diff --git a/Graphics/drawMesh.cpp b/Graphics/drawMesh.cpp index 6c8a1960f9594acc365e394e9a0fa11c478a6c90..e6be5a957bac7d3adc2b0fa7bea08b3fb6f40d59 100644 --- a/Graphics/drawMesh.cpp +++ b/Graphics/drawMesh.cpp @@ -34,18 +34,18 @@ extern unsigned int getColorByEntity(GEntity *e); extern bool isElementVisible(MElement *ele); -template<class T> +template <class T> static void drawElementLabels(drawContext *ctx, GEntity *e, - std::vector<T*> &elements, int forceColor=0, - unsigned int color=0) + std::vector<T *> &elements, int forceColor = 0, + unsigned int color = 0) { unsigned col = forceColor ? color : getColorByEntity(e); - glColor4ubv((GLubyte *) & col); + glColor4ubv((GLubyte *)&col); int labelStep = CTX::instance()->mesh.labelSampling; if(labelStep <= 0) labelStep = 1; - for(unsigned int i = 0; i < elements.size(); i++){ + for(unsigned int i = 0; i < elements.size(); i++) { MElement *ele = elements[i]; if(!isElementVisible(ele)) continue; if(i % labelStep == 0) { @@ -55,7 +55,7 @@ static void drawElementLabels(drawContext *ctx, GEntity *e, sprintf(str, "(%g,%g,%g)", pc.x(), pc.y(), pc.z()); else if(CTX::instance()->mesh.labelType == 3) sprintf(str, "%d", ele->getPartition()); - else if(CTX::instance()->mesh.labelType == 2){ + else if(CTX::instance()->mesh.labelType == 2) { int np = e->physicals.size(); int p = np ? e->physicals[np - 1] : 0; sprintf(str, "%d", p); @@ -69,11 +69,11 @@ static void drawElementLabels(drawContext *ctx, GEntity *e, } } -template<class T> -static void drawNormals(drawContext *ctx, std::vector<T*> &elements) +template <class T> +static void drawNormals(drawContext *ctx, std::vector<T *> &elements) { - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.normals); - for(unsigned int i = 0; i < elements.size(); i++){ + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.normals); + for(unsigned int i = 0; i < elements.size(); i++) { MElement *ele = elements[i]; if(!isElementVisible(ele)) continue; SVector3 n = ele->getFace(0).normal(); @@ -85,11 +85,11 @@ static void drawNormals(drawContext *ctx, std::vector<T*> &elements) } } -template<class T> -static void drawTangents(drawContext *ctx, std::vector<T*> &elements) +template <class T> +static void drawTangents(drawContext *ctx, std::vector<T *> &elements) { - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.tangents); - for(unsigned int i = 0; i < elements.size(); i++){ + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.tangents); + for(unsigned int i = 0; i < elements.size(); i++) { MElement *ele = elements[i]; if(!isElementVisible(ele)) continue; SVector3 t = ele->getEdge(0).tangent(); @@ -102,7 +102,7 @@ static void drawTangents(drawContext *ctx, std::vector<T*> &elements) } static void drawVertexLabel(drawContext *ctx, GEntity *e, MVertex *v, - int partition=-1) + int partition = -1) { if(!v->getVisibility()) return; @@ -111,7 +111,7 @@ static void drawVertexLabel(drawContext *ctx, GEntity *e, MVertex *v, char str[256]; if(CTX::instance()->mesh.labelType == 4) sprintf(str, "(%.16g,%.16g,%.16g)", v->x(), v->y(), v->z()); - else if(CTX::instance()->mesh.labelType == 3){ + else if(CTX::instance()->mesh.labelType == 3) { if(partition < 0) sprintf(str, "NA"); else @@ -126,20 +126,20 @@ static void drawVertexLabel(drawContext *ctx, GEntity *e, MVertex *v, if(CTX::instance()->mesh.colorCarousel == 0 || CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces){ // by element type + CTX::instance()->mesh.surfacesFaces) { // by element type if(v->getPolynomialOrder() > 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.nodeSup); + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.nodeSup); else - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.node); + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.node); } - else{ + else { unsigned int col = getColorByEntity(e); - glColor4ubv((GLubyte *) & col); + glColor4ubv((GLubyte *)&col); } double offset = (0.5 * CTX::instance()->mesh.pointSize + - 0.1 * CTX::instance()->glFontSize) * ctx->pixel_equiv_x; - ctx->drawString(str, v->x() + offset / ctx->s[0], - v->y() + offset / ctx->s[1], + 0.1 * CTX::instance()->glFontSize) * + ctx->pixel_equiv_x; + ctx->drawString(str, v->x() + offset / ctx->s[0], v->y() + offset / ctx->s[1], v->z() + offset / ctx->s[2]); } @@ -147,41 +147,41 @@ static void drawVerticesPerEntity(drawContext *ctx, GEntity *e) { if(CTX::instance()->mesh.points) { if(CTX::instance()->mesh.pointType) { - for(unsigned int i = 0; i < e->mesh_vertices.size(); i++){ + for(unsigned int i = 0; i < e->mesh_vertices.size(); i++) { MVertex *v = e->mesh_vertices[i]; if(!v->getVisibility()) continue; if(CTX::instance()->mesh.colorCarousel == 0 || CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces){ // by element type + CTX::instance()->mesh.surfacesFaces) { // by element type if(v->getPolynomialOrder() > 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.nodeSup); + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.nodeSup); else - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.node); + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.node); } - else{ + else { unsigned int col = getColorByEntity(e); - glColor4ubv((GLubyte *) & col); + glColor4ubv((GLubyte *)&col); } ctx->drawSphere(CTX::instance()->mesh.pointSize, v->x(), v->y(), v->z(), CTX::instance()->mesh.light); } } - else{ + else { glBegin(GL_POINTS); - for(unsigned int i = 0; i < e->mesh_vertices.size(); i++){ + for(unsigned int i = 0; i < e->mesh_vertices.size(); i++) { MVertex *v = e->mesh_vertices[i]; if(!v->getVisibility()) continue; if(CTX::instance()->mesh.colorCarousel == 0 || CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces){ // by element type + CTX::instance()->mesh.surfacesFaces) { // by element type if(v->getPolynomialOrder() > 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.nodeSup); + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.nodeSup); else - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.node); + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.node); } - else{ + else { unsigned int col = getColorByEntity(e); - glColor4ubv((GLubyte *) & col); + glColor4ubv((GLubyte *)&col); } glVertex3d(v->x(), v->y(), v->z()); } @@ -196,34 +196,34 @@ static void drawVerticesPerEntity(drawContext *ctx, GEntity *e) } } -template<class T> +template <class T> static void drawVerticesPerElement(drawContext *ctx, GEntity *e, - std::vector<T*> &elements) + std::vector<T *> &elements) { - for(unsigned int i = 0; i < elements.size(); i++){ + for(unsigned int i = 0; i < elements.size(); i++) { MElement *ele = elements[i]; - for(std::size_t j = 0; j < ele->getNumVertices(); j++){ + for(std::size_t j = 0; j < ele->getNumVertices(); j++) { MVertex *v = ele->getVertex(j); // FIXME isElementVisible() can be slow: we should also use a // vertex array for drawing vertices... - if(isElementVisible(ele) && v->getVisibility()){ + if(isElementVisible(ele) && v->getVisibility()) { if(CTX::instance()->mesh.points) { if(CTX::instance()->mesh.colorCarousel == 0 || CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces){ // by element type + CTX::instance()->mesh.surfacesFaces) { // by element type if(v->getPolynomialOrder() > 1) - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.nodeSup); + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.nodeSup); else - glColor4ubv((GLubyte *) & CTX::instance()->color.mesh.node); + glColor4ubv((GLubyte *)&CTX::instance()->color.mesh.node); } - else{ + else { unsigned int col = getColorByEntity(e); - glColor4ubv((GLubyte *) & col); + glColor4ubv((GLubyte *)&col); } if(CTX::instance()->mesh.pointType) - ctx->drawSphere(CTX::instance()->mesh.pointSize, v->x(), v->y(), v->z(), - CTX::instance()->mesh.light); - else{ + ctx->drawSphere(CTX::instance()->mesh.pointSize, v->x(), v->y(), + v->z(), CTX::instance()->mesh.light); + else { glBegin(GL_POINTS); glVertex3d(v->x(), v->y(), v->z()); glEnd(); @@ -236,35 +236,35 @@ static void drawVerticesPerElement(drawContext *ctx, GEntity *e, } } -template<class T> -static void drawBarycentricDual(std::vector<T*> &elements) +template <class T> static void drawBarycentricDual(std::vector<T *> &elements) { - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x0F0F); gl2psEnable(GL2PS_LINE_STIPPLE); glBegin(GL_LINES); - for(unsigned int i = 0; i < elements.size(); i++){ + for(unsigned int i = 0; i < elements.size(); i++) { MElement *ele = elements[i]; if(!isElementVisible(ele)) continue; SPoint3 pc = ele->barycenter(); - if(ele->getDim() == 2){ - for(int j = 0; j < ele->getNumEdges(); j++){ + if(ele->getDim() == 2) { + for(int j = 0; j < ele->getNumEdges(); j++) { MEdge e = ele->getEdge(j); SPoint3 p = e.barycenter(); glVertex3d(pc.x(), pc.y(), pc.z()); glVertex3d(p.x(), p.y(), p.z()); } } - else if(ele->getDim() == 3){ - for(int j = 0; j < ele->getNumFaces(); j++){ + else if(ele->getDim() == 3) { + for(int j = 0; j < ele->getNumFaces(); j++) { MFace f = ele->getFace(j); SPoint3 p = f.barycenter(); glVertex3d(pc.x(), pc.y(), pc.z()); glVertex3d(p.x(), p.y(), p.z()); - for(std::size_t k = 0; k < f.getNumVertices(); k++){ + for(std::size_t k = 0; k < f.getNumVertices(); k++) { MEdge e(f.getVertex(k), (k == f.getNumVertices() - 1) ? - f.getVertex(0) : f.getVertex(k + 1)); + f.getVertex(0) : + f.getVertex(k + 1)); SPoint3 pe = e.barycenter(); glVertex3d(p.x(), p.y(), p.z()); glVertex3d(pe.x(), pe.y(), pe.z()); @@ -277,20 +277,19 @@ static void drawBarycentricDual(std::vector<T*> &elements) gl2psDisable(GL2PS_LINE_STIPPLE); } -template<class T> -static void drawVoronoiDual(std::vector<T*> &elements) +template <class T> static void drawVoronoiDual(std::vector<T *> &elements) { - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x0F0F); gl2psEnable(GL2PS_LINE_STIPPLE); glBegin(GL_LINES); - for(unsigned int i = 0; i < elements.size(); i++){ + for(unsigned int i = 0; i < elements.size(); i++) { T *ele = elements[i]; if(!isElementVisible(ele)) continue; SPoint3 pc = ele->circumcenter(); - if(ele->getDim() == 2){ - for(int j = 0; j < ele->getNumEdges(); j++){ + if(ele->getDim() == 2) { + for(int j = 0; j < ele->getNumEdges(); j++) { MEdge e = ele->getEdge(j); SVector3 p2p1(e.getVertex(1)->x() - e.getVertex(0)->x(), e.getVertex(1)->y() - e.getVertex(0)->y(), @@ -298,23 +297,25 @@ static void drawVoronoiDual(std::vector<T*> &elements) SVector3 pcp1(pc.x() - e.getVertex(0)->x(), pc.y() - e.getVertex(0)->y(), pc.z() - e.getVertex(0)->z()); - double alpha = dot(pcp1,p2p1) / dot(p2p1,p2p1); - SPoint3 p((1 - alpha)*e.getVertex(0)->x() + alpha * e.getVertex(1)->x(), - (1 - alpha)*e.getVertex(0)->y() + alpha * e.getVertex(1)->y(), - (1 - alpha)*e.getVertex(0)->z() + alpha * e.getVertex(1)->z()); + double alpha = dot(pcp1, p2p1) / dot(p2p1, p2p1); + SPoint3 p( + (1 - alpha) * e.getVertex(0)->x() + alpha * e.getVertex(1)->x(), + (1 - alpha) * e.getVertex(0)->y() + alpha * e.getVertex(1)->y(), + (1 - alpha) * e.getVertex(0)->z() + alpha * e.getVertex(1)->z()); glVertex3d(pc.x(), pc.y(), pc.z()); glVertex3d(p.x(), p.y(), p.z()); } } - else if(ele->getDim() == 3){ - for(int j = 0; j < ele->getNumFaces(); j++){ + else if(ele->getDim() == 3) { + for(int j = 0; j < ele->getNumFaces(); j++) { MFace f = ele->getFace(j); SPoint3 p = f.barycenter(); glVertex3d(pc.x(), pc.y(), pc.z()); glVertex3d(p.x(), p.y(), p.z()); - for(std::size_t k = 0; k < f.getNumVertices(); k++){ + for(std::size_t k = 0; k < f.getNumVertices(); k++) { MEdge e(f.getVertex(k), (k == f.getNumVertices() - 1) ? - f.getVertex(0) : f.getVertex(k + 1)); + f.getVertex(0) : + f.getVertex(k + 1)); SPoint3 pe = e.barycenter(); glVertex3d(p.x(), p.y(), p.z()); glVertex3d(pe.x(), pe.y(), pe.z()); @@ -329,18 +330,21 @@ static void drawVoronoiDual(std::vector<T*> &elements) // Routine for drawing the vertex arrays -static void drawArrays(drawContext *ctx, GEntity *e, VertexArray *va, GLint type, - bool useNormalArray, int forceColor=0, unsigned int color=0) +static void drawArrays(drawContext *ctx, GEntity *e, VertexArray *va, + GLint type, bool useNormalArray, int forceColor = 0, + unsigned int color = 0) { if(!va || !va->getNumVertices()) return; // If we want to be enable picking of individual elements we need to // draw each one separately - bool select = (ctx->render_mode == drawContext::GMSH_SELECT && - CTX::instance()->pickElements && e->model() == GModel::current()); + bool select = + (ctx->render_mode == drawContext::GMSH_SELECT && + CTX::instance()->pickElements && e->model() == GModel::current()); if(select) { - if(va->getNumElementPointers() == va->getNumVertices()){ - for(int i = 0; i < va->getNumVertices(); i += va->getNumVerticesPerElement()){ + if(va->getNumElementPointers() == va->getNumVertices()) { + for(int i = 0; i < va->getNumVertices(); + i += va->getNumVerticesPerElement()) { glPushName(va->getNumVerticesPerElement()); glPushName(i); glBegin(type); @@ -357,7 +361,7 @@ static void drawArrays(drawContext *ctx, GEntity *e, VertexArray *va, GLint type glVertexPointer(3, GL_FLOAT, 0, va->getVertexArray()); glEnableClientState(GL_VERTEX_ARRAY); - if(useNormalArray){ + if(useNormalArray) { glEnable(GL_LIGHTING); glNormalPointer(NORMAL_GLTYPE, 0, va->getNormalArray()); glEnableClientState(GL_NORMAL_ARRAY); @@ -365,20 +369,20 @@ static void drawArrays(drawContext *ctx, GEntity *e, VertexArray *va, GLint type else glDisableClientState(GL_NORMAL_ARRAY); - if(forceColor){ + if(forceColor) { glDisableClientState(GL_COLOR_ARRAY); - glColor4ubv((GLubyte *) & color); + glColor4ubv((GLubyte *)&color); } else if(CTX::instance()->pickElements || (!e->getSelection() && (CTX::instance()->mesh.colorCarousel == 0 || - CTX::instance()->mesh.colorCarousel == 3))){ + CTX::instance()->mesh.colorCarousel == 3))) { glColorPointer(4, GL_UNSIGNED_BYTE, 0, va->getColorArray()); glEnableClientState(GL_COLOR_ARRAY); } - else{ + else { glDisableClientState(GL_COLOR_ARRAY); color = getColorByEntity(e); - glColor4ubv((GLubyte *) & color); + glColor4ubv((GLubyte *)&color); } if(va->getNumVerticesPerElement() > 2 && CTX::instance()->polygonOffset) @@ -397,11 +401,12 @@ static void drawArrays(drawContext *ctx, GEntity *e, VertexArray *va, GLint type // GVertex drawing routines class drawMeshGVertex { - private: +private: drawContext *_ctx; - public: - drawMeshGVertex(drawContext *ctx) : _ctx(ctx){} - void operator () (GVertex *v) + +public: + drawMeshGVertex(drawContext *ctx) : _ctx(ctx) {} + void operator()(GVertex *v) { if(!v->getVisibility()) return; @@ -427,11 +432,12 @@ class drawMeshGVertex { // GEdge drawing routines class drawMeshGEdge { - private: +private: drawContext *_ctx; - public: - drawMeshGEdge(drawContext *ctx) : _ctx(ctx){} - void operator () (GEdge *e) + +public: + drawMeshGEdge(drawContext *ctx) : _ctx(ctx) {} + void operator()(GEdge *e) { if(!e->getVisibility()) { return; @@ -449,18 +455,16 @@ class drawMeshGEdge { if(CTX::instance()->mesh.lines) drawArrays(_ctx, e, e->va_lines, GL_LINES, false); - if(CTX::instance()->mesh.linesNum) - drawElementLabels(_ctx, e, e->lines); + if(CTX::instance()->mesh.linesNum) drawElementLabels(_ctx, e, e->lines); - if(CTX::instance()->mesh.points || CTX::instance()->mesh.pointsNum){ + if(CTX::instance()->mesh.points || CTX::instance()->mesh.pointsNum) { if(e->getAllElementsVisible()) drawVerticesPerEntity(_ctx, e); else drawVerticesPerElement(_ctx, e, e->lines); } - if(CTX::instance()->mesh.tangents) - drawTangents(_ctx, e->lines); + if(CTX::instance()->mesh.tangents) drawTangents(_ctx, e->lines); if(select) { glPopName(); @@ -472,11 +476,12 @@ class drawMeshGEdge { // GFace drawing routines class drawMeshGFace { - private: +private: drawContext *_ctx; - public: - drawMeshGFace(drawContext *ctx) : _ctx(ctx){} - void operator () (GFace *f) + +public: + drawMeshGFace(drawContext *ctx) : _ctx(ctx) {} + void operator()(GFace *f) { if(!f->getVisibility()) { return; @@ -493,28 +498,33 @@ class drawMeshGFace { drawArrays(_ctx, f, f->va_lines, GL_LINES, CTX::instance()->mesh.light && CTX::instance()->mesh.lightLines, - CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); + CTX::instance()->mesh.surfacesFaces, + CTX::instance()->color.mesh.line); if(CTX::instance()->mesh.lightTwoSide) glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - drawArrays(_ctx, f, f->va_triangles, GL_TRIANGLES, CTX::instance()->mesh.light); + drawArrays(_ctx, f, f->va_triangles, GL_TRIANGLES, + CTX::instance()->mesh.light); if(CTX::instance()->mesh.surfacesNum) { if(CTX::instance()->mesh.triangles) - drawElementLabels(_ctx, f, f->triangles, CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, f, f->triangles, + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); if(CTX::instance()->mesh.quadrangles) - drawElementLabels(_ctx, f, f->quadrangles, CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, f, f->quadrangles, + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); - drawElementLabels(_ctx, f, f->polygons, CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, f, f->polygons, + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); } - if(CTX::instance()->mesh.points || CTX::instance()->mesh.pointsNum){ + if(CTX::instance()->mesh.points || CTX::instance()->mesh.pointsNum) { if(f->getAllElementsVisible()) drawVerticesPerEntity(_ctx, f); - else{ + else { if(CTX::instance()->mesh.triangles) drawVerticesPerElement(_ctx, f, f->triangles); if(CTX::instance()->mesh.quadrangles) @@ -548,11 +558,12 @@ class drawMeshGFace { // GRegion drawing routines class drawMeshGRegion { - private: +private: drawContext *_ctx; - public: - drawMeshGRegion(drawContext *ctx) : _ctx(ctx){} - void operator () (GRegion *r) + +public: + drawMeshGRegion(drawContext *ctx) : _ctx(ctx) {} + void operator()(GRegion *r) { if(!r->getVisibility()) return; @@ -565,50 +576,63 @@ class drawMeshGRegion { glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - drawArrays(_ctx, r, r->va_lines, GL_LINES, CTX::instance()->mesh.light && - (CTX::instance()->mesh.lightLines > 1), CTX::instance()->mesh.volumesFaces, - CTX::instance()->color.mesh.line); + drawArrays( + _ctx, r, r->va_lines, GL_LINES, + CTX::instance()->mesh.light && (CTX::instance()->mesh.lightLines > 1), + CTX::instance()->mesh.volumesFaces, CTX::instance()->color.mesh.line); if(CTX::instance()->mesh.lightTwoSide) glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - drawArrays(_ctx, r, r->va_triangles, GL_TRIANGLES, CTX::instance()->mesh.light); + drawArrays(_ctx, r, r->va_triangles, GL_TRIANGLES, + CTX::instance()->mesh.light); if(CTX::instance()->mesh.volumesNum) { if(CTX::instance()->mesh.tetrahedra) - drawElementLabels(_ctx, r, r->tetrahedra, CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, r, r->tetrahedra, + CTX::instance()->mesh.volumesFaces || + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); if(CTX::instance()->mesh.hexahedra) - drawElementLabels(_ctx, r, r->hexahedra, CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, r, r->hexahedra, + CTX::instance()->mesh.volumesFaces || + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); if(CTX::instance()->mesh.prisms) - drawElementLabels(_ctx, r, r->prisms, CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, r, r->prisms, + CTX::instance()->mesh.volumesFaces || + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); if(CTX::instance()->mesh.pyramids) - drawElementLabels(_ctx, r, r->pyramids, CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, r, r->pyramids, + CTX::instance()->mesh.volumesFaces || + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); if(CTX::instance()->mesh.trihedra) - drawElementLabels(_ctx, r, r->trihedra, CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, r, r->trihedra, + CTX::instance()->mesh.volumesFaces || + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); - drawElementLabels(_ctx, r, r->polyhedra, CTX::instance()->mesh.volumesFaces || - CTX::instance()->mesh.surfacesFaces, + drawElementLabels(_ctx, r, r->polyhedra, + CTX::instance()->mesh.volumesFaces || + CTX::instance()->mesh.surfacesFaces, CTX::instance()->color.mesh.line); } - if(CTX::instance()->mesh.points || CTX::instance()->mesh.pointsNum){ + if(CTX::instance()->mesh.points || CTX::instance()->mesh.pointsNum) { if(r->getAllElementsVisible()) drawVerticesPerEntity(_ctx, r); - else{ - if(CTX::instance()->mesh.tetrahedra) drawVerticesPerElement(_ctx, r, r->tetrahedra); - if(CTX::instance()->mesh.hexahedra) drawVerticesPerElement(_ctx, r, r->hexahedra); - if(CTX::instance()->mesh.prisms) drawVerticesPerElement(_ctx, r, r->prisms); - if(CTX::instance()->mesh.pyramids) drawVerticesPerElement(_ctx, r, r->pyramids); - if(CTX::instance()->mesh.trihedra) drawVerticesPerElement(_ctx, r, r->trihedra); + else { + if(CTX::instance()->mesh.tetrahedra) + drawVerticesPerElement(_ctx, r, r->tetrahedra); + if(CTX::instance()->mesh.hexahedra) + drawVerticesPerElement(_ctx, r, r->hexahedra); + if(CTX::instance()->mesh.prisms) + drawVerticesPerElement(_ctx, r, r->prisms); + if(CTX::instance()->mesh.pyramids) + drawVerticesPerElement(_ctx, r, r->pyramids); + if(CTX::instance()->mesh.trihedra) + drawVerticesPerElement(_ctx, r, r->trihedra); drawVerticesPerElement(_ctx, r, r->polyhedra); } } @@ -660,7 +684,7 @@ void drawContext::drawMesh() // make sure to flag any model-dependent post-processing view as // changed if the underlying mesh has, before resetting the changed // flag - if(CTX::instance()->mesh.changed){ + if(CTX::instance()->mesh.changed) { for(unsigned int i = 0; i < GModel::list.size(); i++) for(unsigned int j = 0; j < PView::list.size(); j++) if(PView::list[j]->getData()->hasModel(GModel::list[i])) @@ -675,7 +699,7 @@ void drawContext::drawMesh() gl2psLineWidth((float)(CTX::instance()->mesh.lineWidth * CTX::instance()->print.epsLineWidthFactor)); - if(!CTX::instance()->clipWholeElements){ + if(!CTX::instance()->clipWholeElements) { for(int i = 0; i < 6; i++) if(CTX::instance()->mesh.clip & (1 << i)) glEnable((GLenum)(GL_CLIP_PLANE0 + i)); @@ -683,7 +707,7 @@ void drawContext::drawMesh() glDisable((GLenum)(GL_CLIP_PLANE0 + i)); } - for(unsigned int i = 0; i < GModel::list.size(); i++){ + for(unsigned int i = 0; i < GModel::list.size(); i++) { GModel *m = GModel::list[i]; bool changed = m->fillVertexArrays(); if(changed) Msg::Debug("mesh vertex arrays have changed"); @@ -691,13 +715,13 @@ void drawContext::drawMesh() // FIXME: resetting texture pile fixes bug with recent MacOS versions if(changed) gl_texture_pile_height(gl_texture_pile_height()); #endif - if(m->getVisibility() && isVisible(m)){ + if(m->getVisibility() && isVisible(m)) { int status = m->getMeshStatus(); if(status >= 0) std::for_each(m->firstVertex(), m->lastVertex(), drawMeshGVertex(this)); if(status >= 1) std::for_each(m->firstEdge(), m->lastEdge(), drawMeshGEdge(this)); - if(status >= 2){ + if(status >= 2) { beginFakeTransparency(); std::for_each(m->firstFace(), m->lastFace(), drawMeshGFace(this)); endFakeTransparency(); @@ -709,6 +733,5 @@ void drawContext::drawMesh() CTX::instance()->mesh.changed = 0; - for(int i = 0; i < 6; i++) - glDisable((GLenum)(GL_CLIP_PLANE0 + i)); + for(int i = 0; i < 6; i++) glDisable((GLenum)(GL_CLIP_PLANE0 + i)); } diff --git a/Graphics/drawPost.cpp b/Graphics/drawPost.cpp index 93ebd08b632729636cb6c7abc9c343459f27471e..5b8299d67d0e45755f5f9dadb8f48ce55073a365 100644 --- a/Graphics/drawPost.cpp +++ b/Graphics/drawPost.cpp @@ -33,12 +33,12 @@ static void drawArrays(drawContext *ctx, PView *p, VertexArray *va, GLint type, if(CTX::instance()->polygonOffset || opt->showElement) glEnable(GL_POLYGON_OFFSET_FILL); - if(type == GL_POINTS && opt->pointType > 0){ - for(int i = 0; i < va->getNumVertices(); i++){ + if(type == GL_POINTS && opt->pointType > 0) { + for(int i = 0; i < va->getNumVertices(); i++) { float *p = va->getVertexArray(3 * i); glColor4ubv((GLubyte *)va->getColorArray(4 * i)); double f = 1.; - if(opt->pointType > 1){ + if(opt->pointType > 1) { #if defined(HAVE_VISUDEV) f = *va->getNormalArray(3 * i); #else @@ -46,11 +46,12 @@ static void drawArrays(drawContext *ctx, PView *p, VertexArray *va, GLint type, f = char2float(*n); #endif } - if(opt->pointType == 2){ + if(opt->pointType == 2) { int s = (int)(opt->pointSize * f); - if(s){ + if(s) { glPointSize((float)s); - gl2psPointSize((float)(s * CTX::instance()->print.epsPointSizeFactor)); + gl2psPointSize( + (float)(s * CTX::instance()->print.epsPointSizeFactor)); glBegin(GL_POINTS); glVertex3d(p[0], p[1], p[2]); glEnd(); @@ -60,13 +61,14 @@ static void drawArrays(drawContext *ctx, PView *p, VertexArray *va, GLint type, ctx->drawSphere(opt->pointSize * f, p[0], p[1], p[2], opt->light); } } - else if(type == GL_LINES && opt->lineType > 0){ - for(int i = 0; i < va->getNumVertices(); i += 2){ + else if(type == GL_LINES && opt->lineType > 0) { + for(int i = 0; i < va->getNumVertices(); i += 2) { float *p0 = va->getVertexArray(3 * i); float *p1 = va->getVertexArray(3 * (i + 1)); - double x[2] = {p0[0], p1[0]}, y[2] = {p0[1], p1[1]}, z[2] = {p0[2], p1[2]}; + double x[2] = {p0[0], p1[0]}, y[2] = {p0[1], p1[1]}, + z[2] = {p0[2], p1[2]}; glColor4ubv((GLubyte *)va->getColorArray(4 * i)); - if (opt->lineType == 2){ + if(opt->lineType == 2) { #if defined(HAVE_VISUDEV) double v0 = *va->getNormalArray(3 * i); double v1 = *va->getNormalArray(3 * (i + 1)); @@ -75,14 +77,15 @@ static void drawArrays(drawContext *ctx, PView *p, VertexArray *va, GLint type, char *n1 = va->getNormalArray(3 * (i + 1)); double v0 = char2float(*n0), v1 = char2float(*n1); #endif - ctx->drawTaperedCylinder(opt->lineWidth, v0, v1, 0., 1., x, y, z, opt->light); + ctx->drawTaperedCylinder(opt->lineWidth, v0, v1, 0., 1., x, y, z, + opt->light); } - else if (opt->lineType == 1) + else if(opt->lineType == 1) ctx->drawCylinder(opt->lineWidth, x, y, z, opt->light); else { // 2D (for now) MNT diagrams for frames - float l = sqrt ((p0[0] - p1[0]) * (p0[0] - p1[0]) + - (p0[1] - p1[1]) * (p0[1] - p1[1]) + - (p0[2] - p1[2]) * (p0[2] - p1[2]) ); + float l = sqrt((p0[0] - p1[0]) * (p0[0] - p1[0]) + + (p0[1] - p1[1]) * (p0[1] - p1[1]) + + (p0[2] - p1[2]) * (p0[2] - p1[2])); #if defined(HAVE_VISUDEV) double v0 = *va->getNormalArray(3 * i); double v1 = *va->getNormalArray(3 * (i + 1)); @@ -91,18 +94,19 @@ static void drawArrays(drawContext *ctx, PView *p, VertexArray *va, GLint type, char *n1 = va->getNormalArray(3 * (i + 1)); double v0 = char2float(*n0), v1 = char2float(*n1); #endif - float dir [3] = {(p1[0] - p0[0]) / l , (p1[1] - p0[1]) / l , (p1[2] - p0[2]) / l}; + float dir[3] = {(p1[0] - p0[0]) / l, (p1[1] - p0[1]) / l, + (p1[2] - p0[2]) / l}; printf("%g %g %g %g %g %g\n", v0, v1, p0[0], p0[1], p1[0], p1[1]); - ctx->drawVector(1, 0, - p0[0] - dir[1] * v0 , p0[1] + dir[0] * v0 , 0.0, - p1[0] - dir[1] * v1 , p1[1] + dir[0] * v1 , 0.0,opt->light); + ctx->drawVector(1, 0, p0[0] - dir[1] * v0, p0[1] + dir[0] * v0, 0.0, + p1[0] - dir[1] * v1, p1[1] + dir[0] * v1, 0.0, + opt->light); } } } - else{ + else { glVertexPointer(3, GL_FLOAT, 0, va->getVertexArray()); glEnableClientState(GL_VERTEX_ARRAY); - if(useNormalArray){ + if(useNormalArray) { glEnable(GL_LIGHTING); glNormalPointer(NORMAL_GLTYPE, 0, va->getNormalArray()); glEnableClientState(GL_NORMAL_ARRAY); @@ -131,18 +135,19 @@ static void drawEllipseArray(drawContext *ctx, PView *p, VertexArray *va) float *s = va->getVertexArray(3 * i); float vv[3][3]; double lmax = opt->tmpMax; - double scale = (opt->arrowSizeMax - opt->arrowSizeMin) *ctx->pixel_equiv_x / ctx->s[0]/2; - double lmin = opt->arrowSizeMin * ctx->pixel_equiv_x / ctx->s[0]/2; - for (int j = 0; j < 3; j++) { + double scale = (opt->arrowSizeMax - opt->arrowSizeMin) * + ctx->pixel_equiv_x / ctx->s[0] / 2; + double lmin = opt->arrowSizeMin * ctx->pixel_equiv_x / ctx->s[0] / 2; + for(int j = 0; j < 3; j++) { float *v = va->getVertexArray(3 * (i + j + 1)); - double l = sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); - double l2 = std::min(1., l/lmax); - for (int k = 0; k < 3; k++) { - vv[j][k] = v[k]/l*(scale*l2 + lmin); + double l = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + double l2 = std::min(1., l / lmax); + for(int k = 0; k < 3; k++) { + vv[j][k] = v[k] / l * (scale * l2 + lmin); } } glColor4ubv((GLubyte *)va->getColorArray(4 * i)); - if (opt->tensorType == PViewOptions::Ellipsoid) + if(opt->tensorType == PViewOptions::Ellipsoid) ctx->drawEllipsoid(s[0], s[1], s[2], vv[0], vv[1], vv[2], opt->light); else ctx->drawEllipse(s[0], s[1], s[2], vv[0], vv[1], opt->light); @@ -155,20 +160,20 @@ static void drawVectorArray(drawContext *ctx, PView *p, VertexArray *va) PViewOptions *opt = p->getOptions(); - for(int i = 0; i < va->getNumVertices(); i += 2){ + for(int i = 0; i < va->getNumVertices(); i += 2) { float *s = va->getVertexArray(3 * i); float *v = va->getVertexArray(3 * (i + 1)); glColor4ubv((GLubyte *)va->getColorArray(4 * i)); double vv[3] = {v[0], v[1], v[2]}; double l = sqrt(vv[0] * vv[0] + vv[1] * vv[1] + vv[2] * vv[2]); double lmax = opt->tmpMax; - if((l || opt->vectorType == 6) && lmax){ + if((l || opt->vectorType == 6) && lmax) { double scale = (opt->arrowSizeMax - opt->arrowSizeMin) / lmax; // log scaling - if(opt->scaleType == PViewOptions::Logarithmic && - opt->tmpMin > 0 && opt->tmpMax > opt->tmpMin && l != opt->tmpMin){ + if(opt->scaleType == PViewOptions::Logarithmic && opt->tmpMin > 0 && + opt->tmpMax > opt->tmpMin && l != opt->tmpMin) { scale = (opt->arrowSizeMax - opt->arrowSizeMin) / l * - log10(l / opt->tmpMin) / log10(opt->tmpMax / opt->tmpMin); + log10(l / opt->tmpMin) / log10(opt->tmpMax / opt->tmpMin); } if(opt->arrowSizeMin && l) scale += opt->arrowSizeMin / l; double px = scale * v[0]; @@ -176,18 +181,24 @@ static void drawVectorArray(drawContext *ctx, PView *p, VertexArray *va) double pz = scale * v[2]; // only draw vectors larger than 1 pixel on screen, except when // drawing "comet" glyphs - if(opt->vectorType == 6 || fabs(px) > 1. || fabs(py) > 1. || fabs(pz) > 1.){ + if(opt->vectorType == 6 || fabs(px) > 1. || fabs(py) > 1. || + fabs(pz) > 1.) { double d = ctx->pixel_equiv_x / ctx->s[0]; double dx = px * d, dy = py * d, dz = pz * d; double x = s[0], y = s[1], z = s[2]; - if(opt->centerGlyphs == 2){ - x -= dx; y -= dy; z -= dz; + if(opt->centerGlyphs == 2) { + x -= dx; + y -= dy; + z -= dz; } - else if(opt->centerGlyphs == 1){ - x -= 0.5 * dx; y -= 0.5 * dy; z -= 0.5 * dz; + else if(opt->centerGlyphs == 1) { + x -= 0.5 * dx; + y -= 0.5 * dy; + z -= 0.5 * dz; } - ctx->drawVector(opt->vectorType, opt->intervalsType != PViewOptions::Iso, - x, y, z, dx, dy, dz, opt->light); + ctx->drawVector(opt->vectorType, + opt->intervalsType != PViewOptions::Iso, x, y, z, dx, + dy, dz, opt->light); } } } @@ -199,7 +210,7 @@ static std::string stringValue(int numComp, double d[9], double norm, char label[100]; if(numComp == 1) sprintf(label, format, d[0]); - else if(numComp == 3){ + else if(numComp == 3) { char str[3][32]; sprintf(str[0], format, d[0]); sprintf(str[1], format, d[1]); @@ -211,26 +222,26 @@ static std::string stringValue(int numComp, double d[9], double norm, return std::string(label); } -static void drawNumberGlyphs(drawContext *ctx, PView *p, int numNodes, int numComp, - double **xyz, double **val) +static void drawNumberGlyphs(drawContext *ctx, PView *p, int numNodes, + int numComp, double **xyz, double **val) { PViewOptions *opt = p->getOptions(); double d[9] = {0., 0., 0., 0., 0., 0., 0., 0., 0.}; double vmin = opt->tmpMin, vmax = opt->tmpMax; - if(opt->glyphLocation == PViewOptions::COG){ + if(opt->glyphLocation == PViewOptions::COG) { SPoint3 pc(0., 0., 0.); - for(int i = 0; i < numNodes; i++){ + for(int i = 0; i < numNodes; i++) { pc += SPoint3(xyz[i][0], xyz[i][1], xyz[i][2]); for(int j = 0; j < numComp; j++) d[j] += val[i][j]; } pc /= (double)numNodes; for(int j = 0; j < numComp; j++) d[j] /= (double)numNodes; double v = ComputeScalarRep(numComp, d); - if(v >= vmin && v <= vmax){ + if(v >= vmin && v <= vmax) { unsigned int col = opt->getColor(v, vmin, vmax, false, opt->nbIso); - glColor4ubv((GLubyte *) & col); + glColor4ubv((GLubyte *)&col); if(opt->centerGlyphs == 2) ctx->drawStringRight(stringValue(numComp, d, v, opt->format.c_str()), pc.x(), pc.y(), pc.z()); @@ -238,22 +249,24 @@ static void drawNumberGlyphs(drawContext *ctx, PView *p, int numNodes, int numCo ctx->drawStringCenter(stringValue(numComp, d, v, opt->format.c_str()), pc.x(), pc.y(), pc.z()); else - ctx->drawString(stringValue(numComp, d, v, opt->format.c_str()), - pc.x(), pc.y(), pc.z()); + ctx->drawString(stringValue(numComp, d, v, opt->format.c_str()), pc.x(), + pc.y(), pc.z()); } } - else if(opt->glyphLocation == PViewOptions::Vertex){ - for(int i = 0; i < numNodes; i++){ + else if(opt->glyphLocation == PViewOptions::Vertex) { + for(int i = 0; i < numNodes; i++) { double v = ComputeScalarRep(numComp, val[i]); - if(v >= vmin && v <= vmax){ + if(v >= vmin && v <= vmax) { unsigned int col = opt->getColor(v, vmin, vmax, false, opt->nbIso); - glColor4ubv((GLubyte *) & col); + glColor4ubv((GLubyte *)&col); if(opt->centerGlyphs == 2) - ctx->drawStringRight(stringValue(numComp, val[i], v, opt->format.c_str()), - xyz[i][0], xyz[i][1], xyz[i][2]); + ctx->drawStringRight( + stringValue(numComp, val[i], v, opt->format.c_str()), xyz[i][0], + xyz[i][1], xyz[i][2]); else if(opt->centerGlyphs == 1) - ctx->drawStringCenter(stringValue(numComp, val[i], v, opt->format.c_str()), - xyz[i][0], xyz[i][1], xyz[i][2]); + ctx->drawStringCenter( + stringValue(numComp, val[i], v, opt->format.c_str()), xyz[i][0], + xyz[i][1], xyz[i][2]); else ctx->drawString(stringValue(numComp, val[i], v, opt->format.c_str()), xyz[i][0], xyz[i][1], xyz[i][2]); @@ -272,16 +285,18 @@ static void drawNormalVectorGlyphs(drawContext *ctx, PView *p, int numNodes, pc += SPoint3(xyz[i][0], xyz[i][1], xyz[i][2]); pc /= (double)numNodes; - SVector3 t1(xyz[1][0] - xyz[0][0], xyz[1][1] - xyz[0][1], xyz[1][2] - xyz[0][2]); - SVector3 t2(xyz[2][0] - xyz[0][0], xyz[2][1] - xyz[0][1], xyz[2][2] - xyz[0][2]); + SVector3 t1(xyz[1][0] - xyz[0][0], xyz[1][1] - xyz[0][1], + xyz[1][2] - xyz[0][2]); + SVector3 t2(xyz[2][0] - xyz[0][0], xyz[2][1] - xyz[0][1], + xyz[2][2] - xyz[0][2]); SVector3 n = crossprod(t1, t2); n.normalize(); for(int i = 0; i < 3; i++) n[i] *= opt->normals * ctx->pixel_equiv_x / ctx->s[i]; - glColor4ubv((GLubyte *) & opt->color.normals); - ctx->drawVector(CTX::instance()->vectorType, 0, pc[0], pc[1], pc[2], n[0], n[1], n[2], - opt->light); + glColor4ubv((GLubyte *)&opt->color.normals); + ctx->drawVector(CTX::instance()->vectorType, 0, pc[0], pc[1], pc[2], n[0], + n[1], n[2], opt->light); } static void drawTangentVectorGlyphs(drawContext *ctx, PView *p, int numNodes, @@ -296,9 +311,9 @@ static void drawTangentVectorGlyphs(drawContext *ctx, PView *p, int numNodes, t.normalize(); for(int i = 0; i < 3; i++) t[i] *= opt->tangents * ctx->pixel_equiv_x / ctx->s[i]; - glColor4ubv((GLubyte *) & opt->color.tangents); - ctx->drawVector(CTX::instance()->vectorType, 0, pc[0], pc[1], pc[2], t[0], t[1], t[2], - opt->light); + glColor4ubv((GLubyte *)&opt->color.tangents); + ctx->drawVector(CTX::instance()->vectorType, 0, pc[0], pc[1], pc[2], t[0], + t[1], t[2], opt->light); } static void drawGlyphs(drawContext *ctx, PView *p) @@ -309,14 +324,15 @@ static void drawGlyphs(drawContext *ctx, PView *p) PViewData *data = p->getData(true); PViewOptions *opt = p->getOptions(); - if(!opt->normals && !opt->tangents && opt->intervalsType != PViewOptions::Numeric) + if(!opt->normals && !opt->tangents && + opt->intervalsType != PViewOptions::Numeric) return; Msg::Debug("drawing extra glyphs (this is slow...)"); // speedup drawing of textured fonts on cocoa mac version #if defined(HAVE_FLTK) && defined(__APPLE__) - if(opt->intervalsType == PViewOptions::Numeric){ + if(opt->intervalsType == PViewOptions::Numeric) { int numStrings = 0; for(int ent = 0; ent < data->getNumEntities(opt->timeStep); ent++) numStrings += data->getNumElements(opt->timeStep, ent); @@ -325,53 +341,57 @@ static void drawGlyphs(drawContext *ctx, PView *p) } #endif - //double xyz[PVIEW_NMAX][3], val[PVIEW_NMAX][9]; + // double xyz[PVIEW_NMAX][3], val[PVIEW_NMAX][9]; int NMAX = PVIEW_NMAX; - double **xyz = new double*[NMAX]; - double **val = new double*[NMAX]; - for(int i = 0; i < NMAX; i++){ + double **xyz = new double *[NMAX]; + double **val = new double *[NMAX]; + for(int i = 0; i < NMAX; i++) { xyz[i] = new double[3]; val[i] = new double[9]; } - for(int ent = 0; ent < data->getNumEntities(opt->timeStep); ent++){ + for(int ent = 0; ent < data->getNumEntities(opt->timeStep); ent++) { if(data->skipEntity(opt->timeStep, ent)) continue; - for(int i = 0; i < data->getNumElements(opt->timeStep, ent); i++){ - if(data->skipElement(opt->timeStep, ent, i, true, opt->sampling)) continue; + for(int i = 0; i < data->getNumElements(opt->timeStep, ent); i++) { + if(data->skipElement(opt->timeStep, ent, i, true, opt->sampling)) + continue; int type = data->getType(opt->timeStep, ent, i); if(opt->skipElement(type)) continue; int dim = data->getDimension(opt->timeStep, ent, i); int numComp = data->getNumComponents(opt->timeStep, ent, i); int numNodes = data->getNumNodes(opt->timeStep, ent, i); - if(numNodes > NMAX){ - if(type == TYPE_POLYG || type == TYPE_POLYH){ - for(int j = 0; j < NMAX; j++){ - delete [] xyz[i]; - delete [] val[i]; + if(numNodes > NMAX) { + if(type == TYPE_POLYG || type == TYPE_POLYH) { + for(int j = 0; j < NMAX; j++) { + delete[] xyz[i]; + delete[] val[i]; } - delete [] xyz; - delete [] val; + delete[] xyz; + delete[] val; NMAX = numNodes; - xyz = new double*[NMAX]; - val = new double*[NMAX]; - for(int j = 0; j < NMAX; j++){ + xyz = new double *[NMAX]; + val = new double *[NMAX]; + for(int j = 0; j < NMAX; j++) { xyz[j] = new double[3]; val[j] = new double[9]; } } - else{ - if(numNodesError != numNodes){ + else { + if(numNodesError != numNodes) { numNodesError = numNodes; - Msg::Warning("Fields with %d nodes per element cannot be displayed: " - "either force the field type or select 'Adapt visualization " - "grid' if the field is high-order", numNodes); + Msg::Warning( + "Fields with %d nodes per element cannot be displayed: " + "either force the field type or select 'Adapt visualization " + "grid' if the field is high-order", + numNodes); } continue; } } - for(int j = 0; j < numNodes; j++){ - data->getNode(opt->timeStep, ent, i, j, xyz[j][0], xyz[j][1], xyz[j][2]); - if(opt->forceNumComponents){ - for(int k = 0; k < opt->forceNumComponents; k++){ + for(int j = 0; j < numNodes; j++) { + data->getNode(opt->timeStep, ent, i, j, xyz[j][0], xyz[j][1], + xyz[j][2]); + if(opt->forceNumComponents) { + for(int k = 0; k < opt->forceNumComponents; k++) { int comp = opt->componentMap[k]; if(comp >= 0 && comp < numComp) data->getValue(opt->timeStep, ent, i, j, comp, val[j][k]); @@ -394,19 +414,19 @@ static void drawGlyphs(drawContext *ctx, PView *p) drawTangentVectorGlyphs(ctx, p, numNodes, xyz, val); } } - for(int j = 0; j < NMAX; j++){ - delete [] xyz[j]; - delete [] val[j]; + for(int j = 0; j < NMAX; j++) { + delete[] xyz[j]; + delete[] val[j]; } - delete [] xyz; - delete [] val; + delete[] xyz; + delete[] val; } static bool eyeChanged(drawContext *ctx, PView *p) { double zeye = 100 * CTX::instance()->lc; SPoint3 tmp(ctx->rot[2] * zeye, ctx->rot[6] * zeye, ctx->rot[10] * zeye); - if(tmp.distance(p->getEye()) > 1.e-3){ + if(tmp.distance(p->getEye()) > 1.e-3) { p->setEye(tmp); return true; } @@ -414,11 +434,12 @@ static bool eyeChanged(drawContext *ctx, PView *p) } class drawPView { - private: +private: drawContext *_ctx; - public: + +public: drawPView(drawContext *ctx) : _ctx(ctx) {} - void operator () (PView *p) + void operator()(PView *p) { // use adaptive data if available PViewData *data = p->getData(true); @@ -426,35 +447,37 @@ class drawPView { if(data->getDirty() || !data->getNumTimeSteps()) return; if(!opt->visible || opt->type != PViewOptions::Plot3D) return; - if(!_ctx->isVisible(p)) return; + if(!_ctx->isVisible(p)) return; - if(_ctx->render_mode == drawContext::GMSH_SELECT){ + if(_ctx->render_mode == drawContext::GMSH_SELECT) { glPushName(5); glPushName(p->getIndex()); } glPointSize((float)opt->pointSize); - gl2psPointSize((float)(opt->pointSize * - CTX::instance()->print.epsPointSizeFactor)); + gl2psPointSize( + (float)(opt->pointSize * CTX::instance()->print.epsPointSizeFactor)); glLineWidth((float)opt->lineWidth); - gl2psLineWidth((float)(opt->lineWidth * - CTX::instance()->print.epsLineWidthFactor)); + gl2psLineWidth( + (float)(opt->lineWidth * CTX::instance()->print.epsLineWidthFactor)); - if(opt->axes && opt->type == PViewOptions::Plot3D){ - glColor4ubv((GLubyte *) & opt->color.axes); + if(opt->axes && opt->type == PViewOptions::Plot3D) { + glColor4ubv((GLubyte *)&opt->color.axes); glLineWidth((float)CTX::instance()->lineWidth); gl2psLineWidth((float)(CTX::instance()->lineWidth * CTX::instance()->print.epsLineWidthFactor)); if(!opt->axesAutoPosition) - _ctx->drawAxes(opt->axes, opt->axesTics, opt->axesFormat, opt->axesLabel, - opt->axesPosition, opt->axesMikado, opt->axesPosition); + _ctx->drawAxes(opt->axes, opt->axesTics, opt->axesFormat, + opt->axesLabel, opt->axesPosition, opt->axesMikado, + opt->axesPosition); else if(!opt->tmpBBox.empty()) - _ctx->drawAxes(opt->axes, opt->axesTics, opt->axesFormat, opt->axesLabel, - opt->tmpBBox, opt->axesMikado, opt->tmpBBox); + _ctx->drawAxes(opt->axes, opt->axesTics, opt->axesFormat, + opt->axesLabel, opt->tmpBBox, opt->axesMikado, + opt->tmpBBox); } - if(!CTX::instance()->clipWholeElements){ + if(!CTX::instance()->clipWholeElements) { for(int i = 0; i < 6; i++) if(opt->clip & (1 << i)) glEnable((GLenum)(GL_CLIP_PLANE0 + i)); @@ -462,8 +485,8 @@ class drawPView { glDisable((GLenum)(GL_CLIP_PLANE0 + i)); } - if(CTX::instance()->alpha && ColorTable_IsAlpha(&opt->colorTable)){ - if(opt->fakeTransparency){ + if(CTX::instance()->alpha && ColorTable_IsAlpha(&opt->colorTable)) { + if(opt->fakeTransparency) { // simple additive blending "a la xpost": glBlendFunc(GL_SRC_ALPHA, GL_ONE); // glBlendEquation(GL_FUNC_ADD); // maximum intensity projection "a la volsuite": @@ -471,28 +494,29 @@ class drawPView { glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); } - else{ + else { // real translucent blending (requires back-to-front traversal) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glBlendEquation(GL_FUNC_ADD); glEnable(GL_BLEND); if(p->va_triangles && p->va_triangles->getNumVertices() && - eyeChanged(_ctx, p)){ + eyeChanged(_ctx, p)) { Msg::Debug("Sorting View[%d] for transparency", p->getIndex()); - p->va_triangles->sort(p->getEye().x(), p->getEye().y(), p->getEye().z()); + p->va_triangles->sort(p->getEye().x(), p->getEye().y(), + p->getEye().z()); } } } - if(opt->rangeType == PViewOptions::Custom){ - opt->tmpMin = opt->customMin; - opt->tmpMax = opt->customMax; + if(opt->rangeType == PViewOptions::Custom) { + opt->tmpMin = opt->customMin; + opt->tmpMax = opt->customMax; } - else if(opt->rangeType == PViewOptions::PerTimeStep){ + else if(opt->rangeType == PViewOptions::PerTimeStep) { opt->tmpMin = data->getMin(opt->timeStep); opt->tmpMax = data->getMax(opt->timeStep); } - else{ + else { // FIXME: this is not perfect for multi-step adaptive views, as // we don't have the correct min/max info for the other steps opt->tmpMin = data->getMin(); @@ -505,8 +529,7 @@ class drawPView { drawArrays(_ctx, p, p->va_points, GL_POINTS, false); drawArrays(_ctx, p, p->va_lines, GL_LINES, opt->light && opt->lightLines); - if(opt->lightTwoSide) - glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + if(opt->lightTwoSide) glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); drawArrays(_ctx, p, p->va_triangles, GL_TRIANGLES, opt->light); @@ -520,9 +543,9 @@ class drawPView { drawGlyphs(_ctx, p); // draw the 3D strings - if(opt->drawStrings){ - glColor4ubv((GLubyte *) & opt->color.text3d); - for(int i = 0; i < data->getNumStrings3D(); i++){ + if(opt->drawStrings) { + glColor4ubv((GLubyte *)&opt->color.text3d); + for(int i = 0; i < data->getNumStrings3D(); i++) { double x, y, z, style; std::string str; data->getString3D(i, opt->timeStep, str, x, y, z, style); @@ -530,28 +553,27 @@ class drawPView { } } - if(CTX::instance()->alpha){ + if(CTX::instance()->alpha) { glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } - for(int i = 0; i < 6; i++) - glDisable((GLenum)(GL_CLIP_PLANE0 + i)); + for(int i = 0; i < 6; i++) glDisable((GLenum)(GL_CLIP_PLANE0 + i)); - if(_ctx->render_mode == drawContext::GMSH_SELECT){ + if(_ctx->render_mode == drawContext::GMSH_SELECT) { glPopName(); glPopName(); } - } }; class drawPViewBoundingBox { - private: +private: drawContext *_ctx; - public: + +public: drawPViewBoundingBox(drawContext *ctx) : _ctx(ctx) {} - void operator () (PView *p) + void operator()(PView *p) { PViewData *data = p->getData(); PViewOptions *opt = p->getOptions(); @@ -561,22 +583,21 @@ class drawPViewBoundingBox { SBoundingBox3d bb = data->getBoundingBox(opt->timeStep); if(bb.empty()) return; - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); glLineWidth((float)CTX::instance()->lineWidth); gl2psLineWidth((float)(CTX::instance()->lineWidth * CTX::instance()->print.epsLineWidthFactor)); - _ctx->drawBox(bb.min().x(), bb.min().y(), bb.min().z(), - bb.max().x(), bb.max().y(), bb.max().z()); + _ctx->drawBox(bb.min().x(), bb.min().y(), bb.min().z(), bb.max().x(), + bb.max().y(), bb.max().z()); glColor3d(1., 0., 0.); for(int i = 0; i < 6; i++) if(opt->clip & (1 << i)) - _ctx->drawPlaneInBoundingBox(bb.min().x(), bb.min().y(), bb.min().z(), - bb.max().x(), bb.max().y(), bb.max().z(), - CTX::instance()->clipPlane[i][0], - CTX::instance()->clipPlane[i][1], - CTX::instance()->clipPlane[i][2], - CTX::instance()->clipPlane[i][3]); + _ctx->drawPlaneInBoundingBox( + bb.min().x(), bb.min().y(), bb.min().z(), bb.max().x(), bb.max().y(), + bb.max().z(), CTX::instance()->clipPlane[i][0], + CTX::instance()->clipPlane[i][1], CTX::instance()->clipPlane[i][2], + CTX::instance()->clipPlane[i][3]); } }; @@ -588,11 +609,12 @@ void drawContext::drawPost() if(PView::list.empty()) return; if(CTX::instance()->drawBBox || !CTX::instance()->post.draw) - std::for_each(PView::list.begin(), PView::list.end(), drawPViewBoundingBox(this)); + std::for_each(PView::list.begin(), PView::list.end(), + drawPViewBoundingBox(this)); if(!CTX::instance()->post.draw) return; - for(unsigned int i = 0; i < PView::list.size(); i++){ + for(unsigned int i = 0; i < PView::list.size(); i++) { bool changed = PView::list[i]->fillVertexArrays(); if(changed) Msg::Debug("post-pro vertex arrays have changed"); #if defined(HAVE_FLTK) && defined(__APPLE__) diff --git a/Graphics/drawScales.cpp b/Graphics/drawScales.cpp index eef5c7c6e73d4586ac7a8a8af693578ad1cfbc9f..a8d263baee783bfd9d0522706d5cefa3ef7522e0 100644 --- a/Graphics/drawScales.cpp +++ b/Graphics/drawScales.cpp @@ -20,17 +20,17 @@ static void drawScaleBar(PView *p, double xmin, double ymin, double width, for(int i = 0; i < opt->nbIso; i++) { if(opt->intervalsType == PViewOptions::Discrete || - opt->intervalsType == PViewOptions::Numeric){ + opt->intervalsType == PViewOptions::Numeric) { unsigned int col = opt->getColor(i, opt->nbIso); - glColor4ubv((GLubyte *) &col); + glColor4ubv((GLubyte *)&col); glBegin(GL_QUADS); - if(horizontal){ + if(horizontal) { glVertex2d(xmin + i * box, ymin); glVertex2d(xmin + (i + 1) * box, ymin); glVertex2d(xmin + (i + 1) * box, ymin + height); glVertex2d(xmin + i * box, ymin + height); } - else{ + else { glVertex2d(xmin, ymin + i * box); glVertex2d(xmin + width, ymin + i * box); glVertex2d(xmin + width, ymin + (i + 1) * box); @@ -38,42 +38,42 @@ static void drawScaleBar(PView *p, double xmin, double ymin, double width, } glEnd(); } - else if(opt->intervalsType == PViewOptions::Continuous){ + else if(opt->intervalsType == PViewOptions::Continuous) { glBegin(GL_QUADS); double dv = (opt->tmpMax - opt->tmpMin) / (opt->nbIso ? opt->nbIso : 1); double v1 = opt->tmpMin + i * dv; unsigned int col1 = opt->getColor(v1, opt->tmpMin, opt->tmpMax, true); - glColor4ubv((GLubyte *) &col1); - if(horizontal){ + glColor4ubv((GLubyte *)&col1); + if(horizontal) { glVertex2d(xmin + i * box, ymin + height); glVertex2d(xmin + i * box, ymin); } - else{ + else { glVertex2d(xmin, ymin + i * box); glVertex2d(xmin + width, ymin + i * box); } double v2 = opt->tmpMin + (i + 1) * dv; unsigned int col2 = opt->getColor(v2, opt->tmpMin, opt->tmpMax, true); - glColor4ubv((GLubyte *) &col2); - if(horizontal){ + glColor4ubv((GLubyte *)&col2); + if(horizontal) { glVertex2d(xmin + (i + 1) * box, ymin); glVertex2d(xmin + (i + 1) * box, ymin + height); } - else{ + else { glVertex2d(xmin + width, ymin + (i + 1) * box); glVertex2d(xmin, ymin + (i + 1) * box); } glEnd(); } - else{ + else { unsigned int col = opt->getColor(i, opt->nbIso); - glColor4ubv((GLubyte *) &col); + glColor4ubv((GLubyte *)&col); glBegin(GL_LINES); - if(horizontal){ + if(horizontal) { glVertex2d(xmin + box / 2. + i * box, ymin); glVertex2d(xmin + box / 2. + i * box, ymin + height); } - else{ + else { glVertex2d(xmin, ymin + box / 2. + i * box); glVertex2d(xmin + width, ymin + box / 2. + i * box); } @@ -82,8 +82,9 @@ static void drawScaleBar(PView *p, double xmin, double ymin, double width, } } -static void drawScaleValues(drawContext *ctx, PView *p, double xmin, double ymin, - double width, double height, double tic, int horizontal) +static void drawScaleValues(drawContext *ctx, PView *p, double xmin, + double ymin, double width, double height, + double tic, int horizontal) { PViewOptions *opt = p->getOptions(); @@ -92,7 +93,8 @@ static void drawScaleValues(drawContext *ctx, PView *p, double xmin, double ymin drawContext::global()->setFont(CTX::instance()->glFontEnum, CTX::instance()->glFontSize); double font_h = drawContext::global()->getStringHeight(); // total font height - double font_a = drawContext::global()->getStringHeight() - + double font_a = + drawContext::global()->getStringHeight() - drawContext::global()->getStringDescent(); // height above ref pt char label[1024]; @@ -102,50 +104,56 @@ static void drawScaleValues(drawContext *ctx, PView *p, double xmin, double ymin int nbv = opt->nbIso; double f = (opt->intervalsType == PViewOptions::Discrete || opt->intervalsType == PViewOptions::Numeric || - opt->intervalsType == PViewOptions::Continuous) ? 2 : 2.5; + opt->intervalsType == PViewOptions::Continuous) ? + 2 : + 2.5; - if(horizontal && width < nbv * maxw){ - if(width < f * maxw) nbv = 1; - else nbv = 2; + if(horizontal && width < nbv * maxw) { + if(width < f * maxw) + nbv = 1; + else + nbv = 2; } - else if(!horizontal && height < nbv * font_h){ - if(height < f * font_h) nbv = 1; - else nbv = 2; + else if(!horizontal && height < nbv * font_h) { + if(height < f * font_h) + nbv = 1; + else + nbv = 2; } double box = (horizontal ? width : height) / opt->nbIso; double vbox = (horizontal ? width : height) / nbv; - glColor4ubv((GLubyte *) & CTX::instance()->color.text); + glColor4ubv((GLubyte *)&CTX::instance()->color.text); if(opt->intervalsType == PViewOptions::Discrete || opt->intervalsType == PViewOptions::Numeric || - opt->intervalsType == PViewOptions::Continuous){ + opt->intervalsType == PViewOptions::Continuous) { for(int i = 0; i < nbv + 1; i++) { double v = opt->getScaleValue(i, nbv + 1, opt->tmpMin, opt->tmpMax); sprintf(label, opt->format.c_str(), v); - if(horizontal){ + if(horizontal) { ctx->drawStringCenter(label, xmin + i * vbox, ymin + height + tic, 0.); } - else{ + else { ctx->drawString(label, xmin + width + tic, ymin + i * vbox - font_a / 3., 0.); } } } - else{ - if(opt->nbIso > 2 && (nbv == 1 || nbv == 2)){ + else { + if(opt->nbIso > 2 && (nbv == 1 || nbv == 2)) { vbox = (vbox * nbv - box) / nbv; nbv++; } for(int i = 0; i < nbv; i++) { double v = opt->getScaleValue(i, nbv, opt->tmpMin, opt->tmpMax); sprintf(label, opt->format.c_str(), v); - if(horizontal){ + if(horizontal) { ctx->drawStringCenter(label, xmin + box / 2. + i * vbox, ymin + height + tic, 0.); } - else{ + else { ctx->drawString(label, xmin + width + tic, ymin + box / 2. + i * vbox - font_a / 3., 0.); } @@ -154,13 +162,15 @@ static void drawScaleValues(drawContext *ctx, PView *p, double xmin, double ymin } static void drawScaleLabel(drawContext *ctx, PView *p, double xmin, double ymin, - double width, double height, double tic, int horizontal) + double width, double height, double tic, + int horizontal) { PViewOptions *opt = p->getOptions(); PViewData *data; // requested by Laurent: but is this really what we should be doing? - if(opt->externalViewIndex >= 0 && opt->externalViewIndex < (int)PView::list.size()) + if(opt->externalViewIndex >= 0 && + opt->externalViewIndex < (int)PView::list.size()) data = PView::list[opt->externalViewIndex]->getData(); else data = p->getData(); @@ -177,12 +187,15 @@ static void drawScaleLabel(drawContext *ctx, PView *p, double xmin, double ymin, char time[256]; sprintf(time, opt->format.c_str(), data->getTime(opt->timeStep)); int choice = opt->showTime; - if(choice == 3){ // automatic - if(n == 1) choice = 0; // nothing - else if(n == 2) choice = 2; // harmonic - else choice = 5; // multi-step data + if(choice == 3) { // automatic + if(n == 1) + choice = 0; // nothing + else if(n == 2) + choice = 2; // harmonic + else + choice = 5; // multi-step data } - switch(choice){ + switch(choice) { case 1: // time series sprintf(label, "%s - time %s", data->getName().c_str(), time); break; @@ -191,9 +204,8 @@ static void drawScaleLabel(drawContext *ctx, PView *p, double xmin, double ymin, sprintf(label, "%s - %s part", data->getName().c_str(), ((opt->timeStep - n0) % 2) ? "imaginary" : "real"); else - sprintf(label, "%s - harmonic %s (%s part)", - data->getName().c_str(), time, - ((opt->timeStep - n0) % 2) ? "imaginary" : "real"); + sprintf(label, "%s - harmonic %s (%s part)", data->getName().c_str(), + time, ((opt->timeStep - n0) % 2) ? "imaginary" : "real"); break; case 3: // automatic // never here @@ -206,29 +218,25 @@ static void drawScaleLabel(drawContext *ctx, PView *p, double xmin, double ymin, opt->timeStep, data->getNumTimeSteps() - 1); break; case 6: // real eigenvalues - sprintf(label, "%s - eigenvalue %s", data->getName().c_str(), - time); + sprintf(label, "%s - eigenvalue %s", data->getName().c_str(), time); break; case 7: // complex eigenvalues sprintf(label, "%s - eigenvalue %s (%s part)", data->getName().c_str(), time, ((opt->timeStep - n0) % 2) ? "imaginary" : "real"); break; - default: - sprintf(label, "%s", data->getName().c_str()); - break; + default: sprintf(label, "%s", data->getName().c_str()); break; } - if(horizontal){ - ctx->drawString(label, xmin + width / 2., ymin + height + tic + 1.4 * font_h, 0., - CTX::instance()->glFontTitle, - CTX::instance()->glFontEnumTitle, - CTX::instance()->glFontSizeTitle, 1); + if(horizontal) { + ctx->drawString( + label, xmin + width / 2., ymin + height + tic + 1.4 * font_h, 0., + CTX::instance()->glFontTitle, CTX::instance()->glFontEnumTitle, + CTX::instance()->glFontSizeTitle, 1); } - else{ - ctx->drawString(label, xmin, ymin - 2 * font_h, 0., - CTX::instance()->glFontTitle, - CTX::instance()->glFontEnumTitle, - CTX::instance()->glFontSizeTitle, 0); + else { + ctx->drawString( + label, xmin, ymin - 2 * font_h, 0., CTX::instance()->glFontTitle, + CTX::instance()->glFontEnumTitle, CTX::instance()->glFontSizeTitle, 0); } } @@ -239,19 +247,19 @@ static void drawScale(drawContext *ctx, PView *p, double xmin, double ymin, PViewData *data = p->getData(true); PViewOptions *opt = p->getOptions(); - if(opt->externalViewIndex >= 0){ + if(opt->externalViewIndex >= 0) { opt->tmpMin = opt->externalMin; opt->tmpMax = opt->externalMax; } - else if(opt->rangeType == PViewOptions::Custom){ + else if(opt->rangeType == PViewOptions::Custom) { opt->tmpMin = opt->customMin; opt->tmpMax = opt->customMax; } - else if(opt->rangeType == PViewOptions::PerTimeStep){ + else if(opt->rangeType == PViewOptions::PerTimeStep) { opt->tmpMin = data->getMin(opt->timeStep); opt->tmpMax = data->getMax(opt->timeStep); } - else{ + else { opt->tmpMin = data->getMin(); opt->tmpMax = data->getMax(); } @@ -263,8 +271,8 @@ static void drawScale(drawContext *ctx, PView *p, double xmin, double ymin, void drawContext::drawScales() { - std::vector<PView*> scales; - for(unsigned int i = 0; i < PView::list.size(); i++){ + std::vector<PView *> scales; + for(unsigned int i = 0; i < PView::list.size(); i++) { PViewData *data = PView::list[i]->getData(); PViewOptions *opt = PView::list[i]->getOptions(); if(!data->getDirty() && opt->visible && opt->showScale && @@ -298,50 +306,53 @@ void drawContext::drawScales() int c = fix2dCoordinates(&x, &y); if(c & 1) x -= w / 2.; if(c & 2) y += h / 2.; - drawScale(this, p, x, y, w, h, tic, CTX::instance()->post.horizontalScales); + drawScale(this, p, x, y, w, h, tic, + CTX::instance()->post.horizontalScales); } - else if(CTX::instance()->post.horizontalScales){ + else if(CTX::instance()->post.horizontalScales) { double ysep = 20.; double xc = (viewport[2] - viewport[0]) / 2.; - if(scales.size() == 1){ + if(scales.size() == 1) { double w = (viewport[2] - viewport[0]) / 2., h = bar_size; double x = xc - w / 2., y = viewport[1] + ysep; drawScale(this, p, x, y, w, h, tic, 1); } - else{ + else { double xsep = maxw / 4. + (viewport[2] - viewport[0]) / 10.; double w = (viewport[2] - viewport[0] - 4 * xsep) / 2.; if(w < 20.) w = 20.; double h = bar_size; double x = xc - (i % 2 ? -xsep / 1.5 : w + xsep / 1.5); - double y = viewport[1] + ysep + + double y = + viewport[1] + ysep + (i / 2) * (bar_size + tic + 2 * drawContext::global()->getStringHeight() + ysep); drawScale(this, p, x, y, w, h, tic, 1); } } - else{ + else { double xsep = 20.; double dy = 2. * drawContext::global()->getStringHeight(); - if(scales.size() == 1){ + if(scales.size() == 1) { double ysep = (viewport[3] - viewport[1]) / 6.; double w = bar_size, h = viewport[3] - viewport[1] - 2 * ysep - dy; double x = viewport[0] + xsep, y = viewport[1] + ysep + dy; drawScale(this, p, x, y, w, h, tic, 0); } - else{ + else { double ysep = (viewport[3] - viewport[1]) / 15.; double w = bar_size; double h = (viewport[3] - viewport[1] - 3 * ysep - 2.5 * dy) / 2.; double x = viewport[0] + xsep + width_total + (i / 2) * xsep; - double y = viewport[1] + ysep + dy + (1 - i % 2) * (h + 1.5 * dy + ysep); + double y = + viewport[1] + ysep + dy + (1 - i % 2) * (h + 1.5 * dy + ysep); drawScale(this, p, x, y, w, h, tic, 0); } // compute width width_prev = width; sprintf(label, opt->format.c_str(), -M_PI * 1.e-4); width = bar_size + tic + drawContext::global()->getStringWidth(label); - if(opt->showTime){ + if(opt->showTime) { char tmp[256]; sprintf(tmp, opt->format.c_str(), data->getTime(opt->timeStep)); sprintf(label, "%s (%s)", data->getName().c_str(), tmp); @@ -349,7 +360,8 @@ void drawContext::drawScales() else sprintf(label, "%s", data->getName().c_str()); width = std::max(width, drawContext::global()->getStringWidth(label)); - if(i % 2) width_total += std::max(bar_size + width, bar_size + width_prev); + if(i % 2) + width_total += std::max(bar_size + width, bar_size + width_prev); } } } diff --git a/Graphics/gl2gif.cpp b/Graphics/gl2gif.cpp index 1a39d89702f81b2f3372a5fa0261c3d04f4919df..bc8cc4d4df294f4bee7b199bdb87c00363ba31dd 100644 --- a/Graphics/gl2gif.cpp +++ b/Graphics/gl2gif.cpp @@ -51,7 +51,7 @@ /* PPM colormap routines */ #define HASH_SIZE 20023 -#define ppm_hashpixel(p) ( ( (int) (p) & 0x7fffffff ) % HASH_SIZE ) +#define ppm_hashpixel(p) (((int)(p)&0x7fffffff) % HASH_SIZE) static int static_red[MAX_GIFCOLORS]; static int static_green[MAX_GIFCOLORS]; @@ -66,10 +66,9 @@ static colorhash_table ppm_alloccolorhash() colorhash_table cht; int i; - cht = (colorhash_table) Malloc(HASH_SIZE * sizeof(colorhist_list)); + cht = (colorhash_table)Malloc(HASH_SIZE * sizeof(colorhist_list)); - for(i = 0; i < HASH_SIZE; ++i) - cht[i] = (colorhist_list) 0; + for(i = 0; i < HASH_SIZE; ++i) cht[i] = (colorhist_list)0; return cht; } @@ -80,16 +79,17 @@ static void ppm_freecolorhash(colorhash_table cht) colorhist_list chl, chlnext; for(i = 0; i < HASH_SIZE; ++i) - for(chl = cht[i]; chl != (colorhist_list) 0; chl = chlnext) { + for(chl = cht[i]; chl != (colorhist_list)0; chl = chlnext) { chlnext = chl->next; Free((char *)chl); } Free((char *)cht); } -static colorhash_table ppm_computecolorhash(pixel ** const pixels, +static colorhash_table ppm_computecolorhash(pixel **const pixels, const int cols, const int rows, - const int maxcolors, int *const colorsP) + const int maxcolors, + int *const colorsP) { colorhash_table cht; const pixel *pP; @@ -103,17 +103,16 @@ static colorhash_table ppm_computecolorhash(pixel ** const pixels, for(row = 0; row < rows; ++row) for(col = 0, pP = pixels[row]; col < cols; ++col, ++pP) { hash = ppm_hashpixel(*pP); - for(chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next) - if(PPM_EQUAL(chl->ch.color, *pP)) - break; - if(chl != (colorhist_list) 0) + for(chl = cht[hash]; chl != (colorhist_list)0; chl = chl->next) + if(PPM_EQUAL(chl->ch.color, *pP)) break; + if(chl != (colorhist_list)0) ++(chl->ch.value); else { if(++(*colorsP) > maxcolors) { ppm_freecolorhash(cht); - return (colorhash_table) 0; + return (colorhash_table)0; } - chl = (colorhist_list) Malloc(sizeof(struct colorhist_list_item)); + chl = (colorhist_list)Malloc(sizeof(struct colorhist_list_item)); chl->ch.color = *pP; chl->ch.value = 1; chl->next = cht[hash]; @@ -124,13 +123,13 @@ static colorhash_table ppm_computecolorhash(pixel ** const pixels, return cht; } -static int ppm_addtocolorhash(colorhash_table cht, const pixel * const colorP, +static int ppm_addtocolorhash(colorhash_table cht, const pixel *const colorP, const int value) { int hash; colorhist_list chl; - chl = (colorhist_list) Malloc(sizeof(struct colorhist_list_item)); + chl = (colorhist_list)Malloc(sizeof(struct colorhist_list_item)); hash = ppm_hashpixel(*colorP); chl->ch.color = *colorP; chl->ch.value = value; @@ -147,11 +146,11 @@ static colorhist_vector ppm_colorhashtocolorhist(const colorhash_table cht, int i, j; /* Now collate the hash table into a simple colorhist array. */ - chv = (colorhist_vector) Malloc(maxcolors * sizeof(struct colorhist_item)); + chv = (colorhist_vector)Malloc(maxcolors * sizeof(struct colorhist_item)); /* Loop through the hash table. */ j = 0; for(i = 0; i < HASH_SIZE; ++i) - for(chl = cht[i]; chl != (colorhist_list) 0; chl = chl->next) { + for(chl = cht[i]; chl != (colorhist_list)0; chl = chl->next) { /* Add the new entry. */ chv[j] = chl->ch; ++j; @@ -169,16 +168,16 @@ static colorhash_table ppm_colorhisttocolorhash(const colorhist_vector chv, pixel color; colorhist_list chl; - cht = ppm_alloccolorhash(); /* Initializes to NULLs */ + cht = ppm_alloccolorhash(); /* Initializes to NULLs */ for(i = 0; i < colors; ++i) { color = chv[i].color; hash = ppm_hashpixel(color); - for(chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next) + for(chl = cht[hash]; chl != (colorhist_list)0; chl = chl->next) if(PPM_EQUAL(chl->ch.color, color)) Msg::Error("GIF: same color found twice - %d %d %d", PPM_GETR(color), - PPM_GETG(color), PPM_GETB(color)); - chl = (colorhist_list) Malloc(sizeof(struct colorhist_list_item)); + PPM_GETG(color), PPM_GETB(color)); + chl = (colorhist_list)Malloc(sizeof(struct colorhist_list_item)); chl->ch.color = color; chl->ch.value = i; chl->next = cht[hash]; @@ -188,39 +187,34 @@ static colorhash_table ppm_colorhisttocolorhash(const colorhist_vector chv, return cht; } -static colorhist_vector ppm_computecolorhist(pixel ** const pixels, +static colorhist_vector ppm_computecolorhist(pixel **const pixels, const int cols, const int rows, - const int maxcolors, int *const colorsP) + const int maxcolors, + int *const colorsP) { colorhash_table cht; colorhist_vector chv; cht = ppm_computecolorhash(pixels, cols, rows, maxcolors, colorsP); - if(cht == (colorhash_table) 0) - return (colorhist_vector) 0; + if(cht == (colorhash_table)0) return (colorhist_vector)0; chv = ppm_colorhashtocolorhist(cht, maxcolors); ppm_freecolorhash(cht); return chv; } - -static int ppm_lookupcolor(const colorhash_table cht, const pixel * const colorP) +static int ppm_lookupcolor(const colorhash_table cht, const pixel *const colorP) { int hash; colorhist_list chl; hash = ppm_hashpixel(*colorP); - for(chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next) - if(PPM_EQUAL(chl->ch.color, *colorP)) - return chl->ch.value; + for(chl = cht[hash]; chl != (colorhist_list)0; chl = chl->next) + if(PPM_EQUAL(chl->ch.color, *colorP)) return chl->ch.value; return -1; } -static void ppm_freecolorhist(colorhist_vector chv) -{ - Free((char *)chv); -} +static void ppm_freecolorhist(colorhist_vector chv) { Free((char *)chv); } static int colorstobpp(int colors) { @@ -250,11 +244,7 @@ static int colorstobpp(int colors) return bpp; } - -static int sqr(int x) -{ - return x * x; -} +static int sqr(int x) { return x * x; } static int closestcolor(pixel color) { @@ -266,9 +256,8 @@ static int closestcolor(pixel color) dmin = 1000000; for(i = 0; i < static_nbcolors; i++) { - d = - sqr(r - static_red[i]) + sqr(g - static_green[i]) + sqr(b - - static_blue[i]); + d = sqr(r - static_red[i]) + sqr(g - static_green[i]) + + sqr(b - static_blue[i]); if(d < dmin) { dmin = d; imin = i; @@ -278,7 +267,6 @@ static int closestcolor(pixel color) return imin; } - static int GetPixel(int x, int y) { int color; @@ -291,7 +279,6 @@ static int GetPixel(int x, int y) return color; } - /* PPM quantization */ /* #define LARGE_NORM */ @@ -302,8 +289,7 @@ static int GetPixel(int x, int y) #define REP_AVERAGE_PIXELS typedef struct box *box_vector; -struct box -{ +struct box { int ind; int colors; int sum; @@ -311,25 +297,25 @@ struct box static int redcompare(const void *ch1, const void *ch2) { - return (int)PPM_GETR(((colorhist_vector) ch1)->color) - - (int)PPM_GETR(((colorhist_vector) ch2)->color); + return (int)PPM_GETR(((colorhist_vector)ch1)->color) - + (int)PPM_GETR(((colorhist_vector)ch2)->color); } static int greencompare(const void *ch1, const void *ch2) { - return (int)PPM_GETG(((colorhist_vector) ch1)->color) - - (int)PPM_GETG(((colorhist_vector) ch2)->color); + return (int)PPM_GETG(((colorhist_vector)ch1)->color) - + (int)PPM_GETG(((colorhist_vector)ch2)->color); } static int bluecompare(const void *ch1, const void *ch2) { - return (int)PPM_GETB(((colorhist_vector) ch1)->color) - - (int)PPM_GETB(((colorhist_vector) ch2)->color); + return (int)PPM_GETB(((colorhist_vector)ch1)->color) - + (int)PPM_GETB(((colorhist_vector)ch2)->color); } static int sumcompare(const void *b1, const void *b2) { - return (((box_vector) b2)->sum - ((box_vector) b1)->sum); + return (((box_vector)b2)->sum - ((box_vector)b1)->sum); } /* @@ -338,21 +324,20 @@ static int sumcompare(const void *b1, const void *b2) * Display", SIGGRAPH '82 Proceedings, page 297. */ -static colorhist_vector mediancut(colorhist_vector chv, int colors, - int sum, pixval maxval, int newcolors) +static colorhist_vector mediancut(colorhist_vector chv, int colors, int sum, + pixval maxval, int newcolors) { colorhist_vector colormap; box_vector bv; int bi, i; int boxes; - bv = (box_vector) malloc(sizeof(struct box) * newcolors); + bv = (box_vector)malloc(sizeof(struct box) * newcolors); colormap = - (colorhist_vector) malloc(sizeof(struct colorhist_item) * newcolors); - if(bv == (box_vector) 0 || colormap == (colorhist_vector) 0) + (colorhist_vector)malloc(sizeof(struct colorhist_item) * newcolors); + if(bv == (box_vector)0 || colormap == (colorhist_vector)0) Msg::Error("GIF: out of memory"); - for(i = 0; i < newcolors; ++i) - PPM_ASSIGN(colormap[i].color, 0, 0, 0); + for(i = 0; i < newcolors; ++i) PPM_ASSIGN(colormap[i].color, 0, 0, 0); /* * Set up the initial box. @@ -375,10 +360,8 @@ static colorhist_vector mediancut(colorhist_vector chv, int colors, * Find the first splittable box. */ for(bi = 0; bi < boxes; ++bi) - if(bv[bi].colors >= 2) - break; - if(bi == boxes) - break; /* ran out of colors! */ + if(bv[bi].colors >= 2) break; + if(bi == boxes) break; /* ran out of colors! */ indx = bv[bi].ind; clrs = bv[bi].colors; sm = bv[bi].sum; @@ -392,30 +375,24 @@ static colorhist_vector mediancut(colorhist_vector chv, int colors, minb = maxb = PPM_GETB(chv[indx].color); for(i = 1; i < clrs; ++i) { v = PPM_GETR(chv[indx + i].color); - if(v < minr) - minr = v; - if(v > maxr) - maxr = v; + if(v < minr) minr = v; + if(v > maxr) maxr = v; v = PPM_GETG(chv[indx + i].color); - if(v < ming) - ming = v; - if(v > maxg) - maxg = v; + if(v < ming) ming = v; + if(v > maxg) maxg = v; v = PPM_GETB(chv[indx + i].color); - if(v < minb) - minb = v; - if(v > maxb) - maxb = v; + if(v < minb) minb = v; + if(v > maxb) maxb = v; } - /* - * Find the largest dimension, and sort by that component. I have - * included two methods for determining the "largest" dimension; - * first by simply comparing the range in RGB space, and second - * by transforming into luminosities before the comparison. You - * can switch which method is used by switching the commenting on - * the LARGE_ defines at the beginning of this source file. - */ + /* + * Find the largest dimension, and sort by that component. I have + * included two methods for determining the "largest" dimension; + * first by simply comparing the range in RGB space, and second + * by transforming into luminosities before the comparison. You + * can switch which method is used by switching the commenting on + * the LARGE_ defines at the beginning of this source file. + */ #ifdef LARGE_NORM if(maxr - minr >= maxg - ming && maxr - minr >= maxb - minb) qsort((char *)&(chv[indx]), clrs, sizeof(struct colorhist_item), @@ -457,8 +434,7 @@ static colorhist_vector mediancut(colorhist_vector chv, int colors, lowersum = chv[indx].value; halfsum = sm / 2; for(i = 1; i < clrs - 1; ++i) { - if(lowersum >= halfsum) - break; + if(lowersum >= halfsum) break; lowersum += chv[indx + i].value; } @@ -485,7 +461,6 @@ static colorhist_vector mediancut(colorhist_vector chv, int colors, * the beginning of this source file. */ for(bi = 0; bi < boxes; ++bi) { - #ifdef REP_CENTER_BOX int indx = bv[bi].ind; int clrs = bv[bi].colors; @@ -537,14 +512,11 @@ static colorhist_vector mediancut(colorhist_vector chv, int colors, sum += chv[indx + i].value; } r = r / sum; - if(r > (long)maxval) - r = maxval; /* avoid math errors */ + if(r > (long)maxval) r = maxval; /* avoid math errors */ g = g / sum; - if(g > (long)maxval) - g = maxval; + if(g > (long)maxval) g = maxval; b = b / sum; - if(b > (long)maxval) - b = maxval; + if(b > (long)maxval) b = maxval; PPM_ASSIGN(colormap[bi].color, r, g, b); #endif } @@ -556,16 +528,15 @@ static colorhist_vector mediancut(colorhist_vector chv, int colors, return colormap; } + /* GIF compression routines */ -/* GIF compression routines */ - -#define BITS 12 -#define HSIZE 5003 /* 80% occupancy */ -#define TRUE 1 -#define FALSE 0 +#define BITS 12 +#define HSIZE 5003 /* 80% occupancy */ +#define TRUE 1 +#define FALSE 0 typedef unsigned char char_type; -typedef int (*ifunptr) (int, int); +typedef int (*ifunptr)(int, int); static int g_init_bits; static FILE *g_outfile; @@ -579,20 +550,20 @@ static int Interlace; #define ARGVAL() (*++(*argv) || (--argc && *++argv)) -static int n_bits; /* number of bits/code */ -static int maxbits = BITS; /* user settable max # bits/code */ -static code_int maxcode; /* maximum code, given n_bits */ -static code_int maxmaxcode = (code_int) 1 << BITS; - /* should NEVER generate this code */ +static int n_bits; /* number of bits/code */ +static int maxbits = BITS; /* user settable max # bits/code */ +static code_int maxcode; /* maximum code, given n_bits */ +static code_int maxmaxcode = (code_int)1 << BITS; +/* should NEVER generate this code */ -#define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1) +#define MAXCODE(n_bits) (((code_int)1 << (n_bits)) - 1) static count_int htab[HSIZE]; static unsigned short codetab[HSIZE]; -#define HashTabOf(i) htab[i] -#define CodeTabOf(i) codetab[i] +#define HashTabOf(i) htab[i] +#define CodeTabOf(i) codetab[i] -static code_int hsize = HSIZE; /* for dynamic table sizing */ +static code_int hsize = HSIZE; /* for dynamic table sizing */ /* * To save much memory, we overlay the table used by compress() with those @@ -603,11 +574,11 @@ static code_int hsize = HSIZE; /* for dynamic table sizing */ * possible stack (stack used to be 8000 characters). */ -#define tab_prefixof(i) CodeTabOf(i) -#define tab_suffixof(i) ((char_type*)(htab))[i] -#define de_stack ((char_type*)&tab_suffixof((code_int)1<<BITS)) +#define tab_prefixof(i) CodeTabOf(i) +#define tab_suffixof(i) ((char_type *)(htab))[i] +#define de_stack ((char_type *)&tab_suffixof((code_int)1 << BITS)) -static code_int free_ent = 0; /* first unused entry */ +static code_int free_ent = 0; /* first unused entry */ /* * block compression parameters -- after all codes are used up, @@ -615,8 +586,8 @@ static code_int free_ent = 0; /* first unused entry */ */ static int clear_flg = 0; -static long int in_count = 1; /* length of input */ -static long int out_count = 0; /* # of codes output (for debugging) */ +static long int in_count = 1; /* length of input */ +static long int out_count = 0; /* # of codes output (for debugging) */ static int ClearCode; static int EOFCode; @@ -628,17 +599,13 @@ static int a_count; /* * Set up the 'byte output' routine */ -static void char_init() -{ - a_count = 0; -} +static void char_init() { a_count = 0; } /* * Define the storage for the packet accumulator */ static char accum[256]; - /* * Flush the packet to disk, and reset the accumulator */ @@ -658,8 +625,7 @@ static void flush_char() static void char_out(int c) { accum[a_count++] = c; - if(a_count >= 254) - flush_char(); + if(a_count >= 254) flush_char(); } /* @@ -684,8 +650,7 @@ static void BumpPixel() if(!Interlace) ++cury; else { - switch (Pass) { - + switch(Pass) { case 0: cury += 8; if(cury >= Height) { @@ -710,15 +675,12 @@ static void BumpPixel() } break; - case 3: - cury += 2; - break; + case 3: cury += 2; break; } } } } - /* * Return the next pixel from the image */ @@ -726,19 +688,17 @@ static int GIFNextPixel(ifunptr getpixel) { int r; - if(CountDown == 0) - return EOF; + if(CountDown == 0) return EOF; --CountDown; - r = (*getpixel) (curx, cury); + r = (*getpixel)(curx, cury); BumpPixel(); return r; } - /* * Output the given code. * Inputs: @@ -757,11 +717,9 @@ static int GIFNextPixel(ifunptr getpixel) static unsigned long cur_accum = 0; static int cur_bits = 0; -static unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, - 0x001F, 0x003F, 0x007F, 0x00FF, - 0x01FF, 0x03FF, 0x07FF, 0x0FFF, - 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF -}; +static unsigned long masks[] = {0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, + 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, + 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF}; static void output(code_int code) { @@ -785,7 +743,6 @@ static void output(code_int code) * then increase it, if possible. */ if(free_ent > maxcode || clear_flg) { - if(clear_flg) { maxcode = MAXCODE(n_bits = g_init_bits); clear_flg = 0; @@ -813,12 +770,10 @@ static void output(code_int code) fflush(g_outfile); - if(ferror(g_outfile)) - Msg::Error("GIF: Error writing output file"); + if(ferror(g_outfile)) Msg::Error("GIF: Error writing output file"); } } - /* * compress * @@ -836,14 +791,14 @@ static void output(code_int code) */ static void cl_hash(count_int hsize) -{ /* reset code table */ +{ /* reset code table */ count_int *htab_p = htab + hsize; long i; long m1 = -1; i = hsize - 16; - do { /* might use Sys V memset(3) here */ + do { /* might use Sys V memset(3) here */ *(htab_p - 16) = m1; *(htab_p - 15) = m1; *(htab_p - 14) = m1; @@ -863,28 +818,26 @@ static void cl_hash(count_int hsize) htab_p -= 16; } while((i -= 16) >= 0); - for(i += 16; i > 0; --i) - *--htab_p = m1; + for(i += 16; i > 0; --i) *--htab_p = m1; } - /* * Clear out the hash table */ static void cl_block() -{ /* table clear for block compress */ +{ /* table clear for block compress */ - cl_hash((count_int) hsize); + cl_hash((count_int)hsize); free_ent = ClearCode + 2; clear_flg = 1; - output((code_int) ClearCode); + output((code_int)ClearCode); } -static void compress(int init_bits, FILE * outfile, ifunptr ReadValue) +static void compress(int init_bits, FILE *outfile, ifunptr ReadValue) { long fcode; - code_int i /* = 0 */ ; + code_int i /* = 0 */; int c; code_int ent; code_int disp; @@ -915,47 +868,42 @@ static void compress(int init_bits, FILE * outfile, ifunptr ReadValue) ent = GIFNextPixel(ReadValue); hshift = 0; - for(fcode = (long)hsize; fcode < 65536L; fcode *= 2L) - ++hshift; - hshift = 8 - hshift; /* set hash code range bound */ + for(fcode = (long)hsize; fcode < 65536L; fcode *= 2L) ++hshift; + hshift = 8 - hshift; /* set hash code range bound */ hsize_reg = hsize; - cl_hash((count_int) hsize_reg); /* clear hash table */ + cl_hash((count_int)hsize_reg); /* clear hash table */ - output((code_int) ClearCode); + output((code_int)ClearCode); while((c = GIFNextPixel(ReadValue)) != EOF) { - ++in_count; fcode = (long)(((long)c << maxbits) + ent); - i = (((code_int) c << hshift) ^ ent); /* xor hashing */ + i = (((code_int)c << hshift) ^ ent); /* xor hashing */ if(HashTabOf(i) == fcode) { ent = CodeTabOf(i); continue; } - else if((long)HashTabOf(i) < 0) /* empty slot */ + else if((long)HashTabOf(i) < 0) /* empty slot */ goto nomatch; - disp = hsize_reg - i; /* secondary hash (after G. Knott) */ - if(i == 0) - disp = 1; + disp = hsize_reg - i; /* secondary hash (after G. Knott) */ + if(i == 0) disp = 1; probe: - if((i -= disp) < 0) - i += hsize_reg; + if((i -= disp) < 0) i += hsize_reg; if(HashTabOf(i) == fcode) { ent = CodeTabOf(i); continue; } - if((long)HashTabOf(i) > 0) - goto probe; + if((long)HashTabOf(i) > 0) goto probe; nomatch: - output((code_int) ent); + output((code_int)ent); ++out_count; ent = c; if(free_ent < maxmaxcode) { - CodeTabOf(i) = free_ent++; /* code -> hashtable */ + CodeTabOf(i) = free_ent++; /* code -> hashtable */ HashTabOf(i) = fcode; } else @@ -964,27 +912,23 @@ static void compress(int init_bits, FILE * outfile, ifunptr ReadValue) /* * Put out the final code. */ - output((code_int) ent); + output((code_int)ent); ++out_count; - output((code_int) EOFCode); + output((code_int)EOFCode); } - /* * Write out a word to the GIF file */ -static void Putword(int w, FILE * fp) +static void Putword(int w, FILE *fp) { fputc(w & 0xff, fp); fputc((w / 256) & 0xff, fp); } - -static void GIFEncode(FILE * fp, - int GWidth, int GHeight, - int GInterlace, int Background, int Transparent, - int BitsPerPixel, int Red[], int Green[], int Blue[], - ifunptr GetPixel) +static void GIFEncode(FILE *fp, int GWidth, int GHeight, int GInterlace, + int Background, int Transparent, int BitsPerPixel, + int Red[], int Green[], int Blue[], ifunptr GetPixel) { int B; int RWidth, RHeight; @@ -1012,7 +956,7 @@ static void GIFEncode(FILE * fp, /* * Calculate number of bits we are expecting */ - CountDown = (long)Width *(long)Height; + CountDown = (long)Width * (long)Height; /* * Indicate which pass we are on (if interlace) @@ -1046,7 +990,7 @@ static void GIFEncode(FILE * fp, /* * Indicate that there is a global colour map */ - B = 0x80; /* Yes, there is a color map */ + B = 0x80; /* Yes, there is a color map */ /* * OR in the resolution @@ -1137,20 +1081,16 @@ static void GIFEncode(FILE * fp, * Write the GIF file terminator */ fputc(';', fp); - } + /* gl2gif public routine */ -/* gl2gif public routine */ +#define FS_SCALE 1024 +#define MAXCOL2 32767 -#define FS_SCALE 1024 -#define MAXCOL2 32767 - -void create_gif(FILE * outfile, PixelBuffer *buffer, - int dither, int sort, int interlace, - int transparency) +void create_gif(FILE *outfile, PixelBuffer *buffer, int dither, int sort, + int interlace, int transparency) { - int i, j, k, transparent, rows, cols; pixel transcolor; colorhist_vector chv, colormap; @@ -1169,33 +1109,30 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, int height = buffer->getHeight(); int numcomp = buffer->getNumComp(); - if(numcomp != 3){ + if(numcomp != 3) { Msg::Error("GIF only implemented for GL_RGB"); return; } - static_pixels = (pixel **) Malloc(height * sizeof(pixel *)); + static_pixels = (pixel **)Malloc(height * sizeof(pixel *)); for(i = 0; i < height; i++) - static_pixels[i] = (pixel *) Malloc(3 * width * sizeof(pixel)); + static_pixels[i] = (pixel *)Malloc(3 * width * sizeof(pixel)); - unsigned char *pixels = (unsigned char*)buffer->getPixels(); + unsigned char *pixels = (unsigned char *)buffer->getPixels(); for(i = 0; i < height; i++) for(j = 0; j < width; j++) - PPM_ASSIGN(static_pixels[height - 1 - i][j], - pixels[i * width * 3 + j * 3], - pixels[i * width * 3 + j * 3 + 1], - pixels[i * width * 3 + j * 3 + 2]); + PPM_ASSIGN( + static_pixels[height - 1 - i][j], pixels[i * width * 3 + j * 3], + pixels[i * width * 3 + j * 3 + 1], pixels[i * width * 3 + j * 3 + 2]); /* Try to compute color histogram */ chv = ppm_computecolorhist(static_pixels, width, height, MAX_GIFCOLORS, &static_nbcolors); - /* Fuck, there are more than 256 colors in the picture: we need to quantize */ - if(chv == (colorhist_vector) 0) { - + if(chv == (colorhist_vector)0) { Msg::Debug("GIF: too many colors in image"); rows = height; @@ -1205,13 +1142,12 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, Msg::Debug("GIF: making histogram..."); chv = ppm_computecolorhist(static_pixels, width, height, MAXCOL2, &static_nbcolors); - if(chv != (colorhist_vector) 0) - break; + if(chv != (colorhist_vector)0) break; Msg::Debug("GIF: still too many colors!"); newmaxval = maxval / 2; - Msg::Debug( - "GIF: scaling colors from maxval=%d to maxval=%d to improve clustering...", - maxval, newmaxval); + Msg::Debug("GIF: scaling colors from maxval=%d to maxval=%d to improve " + "clustering...", + maxval, newmaxval); for(row = 0; row < rows; ++row) for(col = 0, pP = static_pixels[row]; col < cols; ++col, ++pP) PPM_DEPTH(*pP, *pP, maxval, newmaxval); @@ -1219,8 +1155,7 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, } Msg::Debug("GIF: %d colors found", static_nbcolors); Msg::Debug("GIF: choosing %d colors...", newcolors); - colormap = - mediancut(chv, static_nbcolors, rows * cols, maxval, newcolors); + colormap = mediancut(chv, static_nbcolors, rows * cols, maxval, newcolors); cht = ppm_alloccolorhash(); @@ -1249,7 +1184,6 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, fs_direction = 1; } for(row = 0; row < rows; ++row) { - if(dither) for(col = 0; col < cols + 2; ++col) nextrerr[col] = nextgerr[col] = nextberr[col] = 0; @@ -1266,7 +1200,6 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, } do { - if(dither) { /* Use Floyd-Steinberg errors to adjust actual color. */ sr = PPM_GETR(*pP) + thisrerr[col + 1] / FS_SCALE; @@ -1300,9 +1233,8 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, r2 = PPM_GETR(colormap[i].color); g2 = PPM_GETG(colormap[i].color); b2 = PPM_GETB(colormap[i].color); - newdist = - (r1 - r2) * (r1 - r2) + - (g1 - g2) * (g1 - g2) + (b1 - b2) * (b1 - b2); + newdist = (r1 - r2) * (r1 - r2) + (g1 - g2) * (g1 - g2) + + (b1 - b2) * (b1 - b2); if(newdist < dist) { ind = i; dist = newdist; @@ -1364,8 +1296,7 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, --col; --pP; } - } - while(col != limitcol); + } while(col != limitcol); if(dither) { temperr = thisrerr; @@ -1379,11 +1310,9 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, nextberr = temperr; fs_direction = !fs_direction; } - } - if(cht) - ppm_freecolorhash(cht); + if(cht) ppm_freecolorhash(cht); if(dither) { Free(thisrerr); Free(nextrerr); @@ -1394,7 +1323,6 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, } chv = ppm_computecolorhist(static_pixels, width, height, MAX_GIFCOLORS, &static_nbcolors); - } /* We now have a colormap of maximum 256 colors */ @@ -1406,16 +1334,15 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, } /* Sort the colormap */ - for(i = 0; i < static_nbcolors; i++) - static_permi[i] = i; + for(i = 0; i < static_nbcolors; i++) static_permi[i] = i; if(sort) { Msg::Debug("GIF: sorting colormap"); for(i = 0; i < static_nbcolors; i++) for(j = i + 1; j < static_nbcolors; j++) - if(((static_red[i] * MAX_GIFCOLORS) + - static_green[i]) * MAX_GIFCOLORS + static_blue[i] > - ((static_red[j] * MAX_GIFCOLORS) + - static_green[j]) * MAX_GIFCOLORS + static_blue[j]) { + if(((static_red[i] * MAX_GIFCOLORS) + static_green[i]) * MAX_GIFCOLORS + + static_blue[i] > + ((static_red[j] * MAX_GIFCOLORS) + static_green[j]) * MAX_GIFCOLORS + + static_blue[j]) { k = static_permi[i]; static_permi[i] = static_permi[j]; static_permi[j] = k; @@ -1430,8 +1357,7 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, static_blue[j] = k; } } - for(i = 0; i < static_nbcolors; i++) - static_perm[static_permi[i]] = i; + for(i = 0; i < static_nbcolors; i++) static_perm[static_permi[i]] = i; BitsPerPixel = colorstobpp(static_nbcolors); @@ -1439,7 +1365,8 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, static_cht = ppm_colorhisttocolorhash(chv, static_nbcolors); ppm_freecolorhist(chv); - /* figure out the transparent colour index, assuming the background is white */ + /* figure out the transparent colour index, assuming the background is white + */ if(transparency) { PPM_ASSIGN(transcolor, 255, 255, 255); transparent = ppm_lookupcolor(static_cht, &transcolor); @@ -1455,8 +1382,6 @@ void create_gif(FILE * outfile, PixelBuffer *buffer, GIFEncode(outfile, width, height, interlace, 0, transparent, BitsPerPixel, static_red, static_green, static_blue, GetPixel); - for(i = 0; i < height; i++) - Free(static_pixels[i]); + for(i = 0; i < height; i++) Free(static_pixels[i]); Free(static_pixels); - } diff --git a/Graphics/gl2gif.h b/Graphics/gl2gif.h index c7f51fe90aff90adaed1f2879007a25b59a36c9c..d5dfc031058ad9f2197164f6a3f69315c434546a 100644 --- a/Graphics/gl2gif.h +++ b/Graphics/gl2gif.h @@ -9,42 +9,43 @@ #include <stdio.h> #include "PixelBuffer.h" -#define MAX_GIFCOLORS 256 +#define MAX_GIFCOLORS 256 /* New types */ -typedef unsigned int pixval; -typedef unsigned long pixel; -typedef int code_int; -typedef long int count_int; +typedef unsigned int pixval; +typedef unsigned long pixel; +typedef int code_int; +typedef long int count_int; /* PPM handling */ -#define PPM_GETR(p) (((p) & 0x3ff00000) >> 20) -#define PPM_GETG(p) (((p) & 0xffc00) >> 10) -#define PPM_GETB(p) ((p) & 0x3ff) -#define PPM_EQUAL(p,q) ((p) == (q)) +#define PPM_GETR(p) (((p)&0x3ff00000) >> 20) +#define PPM_GETG(p) (((p)&0xffc00) >> 10) +#define PPM_GETB(p) ((p)&0x3ff) +#define PPM_EQUAL(p, q) ((p) == (q)) -#define PPM_ASSIGN(p,red,grn,blu) \ - (p) = ((pixel) (red) << 20) | ((pixel) (grn) << 10) | (pixel) (blu) +#define PPM_ASSIGN(p, red, grn, blu) \ + (p) = ((pixel)(red) << 20) | ((pixel)(grn) << 10) | (pixel)(blu) -#define PPM_LUMIN(p) ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) ) +#define PPM_LUMIN(p) \ + (0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p)) -#define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \ - PPM_ASSIGN( (newp), \ - ( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \ - ( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \ - ( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) ) +#define PPM_DEPTH(newp, p, oldmaxval, newmaxval) \ + PPM_ASSIGN((newp), \ + ((int)PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2) / (oldmaxval), \ + ((int)PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2) / (oldmaxval), \ + ((int)PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2) / (oldmaxval)) /* Color histogram stuff */ -typedef struct colorhist_item* colorhist_vector; +typedef struct colorhist_item *colorhist_vector; struct colorhist_item { pixel color; int value; }; -typedef struct colorhist_list_item* colorhist_list; +typedef struct colorhist_list_item *colorhist_list; struct colorhist_list_item { struct colorhist_item ch; colorhist_list next; @@ -52,13 +53,11 @@ struct colorhist_list_item { /* Color hash table stuff */ -typedef colorhist_list* colorhash_table; +typedef colorhist_list *colorhash_table; /* Public function */ -void create_gif(FILE *outfile, PixelBuffer *buffer, - int dither, int sort, int interlace, - int transparency); - +void create_gif(FILE *outfile, PixelBuffer *buffer, int dither, int sort, + int interlace, int transparency); #endif diff --git a/Graphics/gl2jpeg.cpp b/Graphics/gl2jpeg.cpp index b2273f6c4a787c25a75f621330c273f34f2fc126..6d31fa1c757d0d871ed7068bb3c8e90e48086339 100644 --- a/Graphics/gl2jpeg.cpp +++ b/Graphics/gl2jpeg.cpp @@ -16,8 +16,7 @@ void create_jpeg(FILE *outfile, PixelBuffer *buffer, int quality, int smoothing) #else -extern "C" -{ +extern "C" { #include <jpeglib.h> #include <jerror.h> } @@ -26,14 +25,14 @@ static void my_output_message(j_common_ptr cinfo) { char buffer[JMSG_LENGTH_MAX]; - (*cinfo->err->format_message) (cinfo, buffer); + (*cinfo->err->format_message)(cinfo, buffer); Msg::Debug("%s", buffer); } void create_jpeg(FILE *outfile, PixelBuffer *buffer, int quality, int smoothing) { - if(buffer->getFormat() != GL_RGB || buffer->getType() != GL_UNSIGNED_BYTE){ + if(buffer->getFormat() != GL_RGB || buffer->getType() != GL_UNSIGNED_BYTE) { Msg::Error("JPEG only implemented for GL_RGB and GL_UNSIGNED_BYTE"); return; } @@ -55,8 +54,8 @@ void create_jpeg(FILE *outfile, PixelBuffer *buffer, int quality, int smoothing) cinfo.smoothing_factor = smoothing; jpeg_start_compress(&cinfo, TRUE); - unsigned char *pixels = (unsigned char*)buffer->getPixels(); - JSAMPROW row_pointer[1]; + unsigned char *pixels = (unsigned char *)buffer->getPixels(); + JSAMPROW row_pointer[1]; int row_stride = cinfo.image_width * cinfo.input_components; int i = cinfo.image_height - 1; while(i >= 0) { diff --git a/Graphics/gl2jpeg.h b/Graphics/gl2jpeg.h index 1df458e5957ed4469259068884a78e96e4b70008..39bc83d59bfe0a34ac1e8a6797b6baf93f431cdb 100644 --- a/Graphics/gl2jpeg.h +++ b/Graphics/gl2jpeg.h @@ -9,6 +9,7 @@ #include <stdio.h> #include "PixelBuffer.h" -void create_jpeg(FILE *outfile, PixelBuffer *buffer, int quality, int smoothing); +void create_jpeg(FILE *outfile, PixelBuffer *buffer, int quality, + int smoothing); #endif diff --git a/Graphics/gl2pgf.cpp b/Graphics/gl2pgf.cpp index 0e9ed833ad13c7b326ccfbe6cd9187e8227d50c9..b83d9d50f583069e912fefb5df0ae6b2fd361432 100644 --- a/Graphics/gl2pgf.cpp +++ b/Graphics/gl2pgf.cpp @@ -21,49 +21,52 @@ static int assembleColmapStr(const int num, const int intType, int &samples, std::string &ret) { - GmshColorTable * ct = GetColorTable(num); // i + GmshColorTable *ct = GetColorTable(num); // i ret.assign("\\pgfplotsset{\ncolormap={gmshcolormap}{%% note: " "Only needed once if colorbars do not change\n"); - samples = (int) opt_view_nb_iso(num, GMSH_GET, 0); + samples = (int)opt_view_nb_iso(num, GMSH_GET, 0); double step = 0.; - switch (intType){ - case 2: samples=64; break; // continuous is approximated by 64 samples - case 3: break; // filled (sampled colorbar) - case 1: break; // iso lines - case 4: // numericals - default: - return 1; - } - step = (double) (1.*ct->size)/(samples-1.); + switch(intType) { + case 2: + samples = 64; + break; // continuous is approximated by 64 samples + case 3: + break; // filled (sampled colorbar) + case 1: + break; // iso lines + case 4: // numericals + default: return 1; + } + step = (double)(1. * ct->size) / (samples - 1.); int r, g, b, a; unsigned int idx; char tmp[265]; - for (unsigned int j=0; j < (unsigned int) samples-1; j++ /*j+=4*/) { - idx = (unsigned int)j*step; - //printf("j=%d, idx=%d step=%f\n", j, idx, step); + for(unsigned int j = 0; j < (unsigned int)samples - 1; j++ /*j+=4*/) { + idx = (unsigned int)j * step; + // printf("j=%d, idx=%d step=%f\n", j, idx, step); r = CTX::instance()->unpackRed(ct->table[idx]); g = CTX::instance()->unpackGreen(ct->table[idx]); b = CTX::instance()->unpackBlue(ct->table[idx]); a = CTX::instance()->unpackAlpha(ct->table[idx]); - if (a != 255) + if(a != 255) Msg::Warning("PGF export does not handle transparent colormaps"); - sprintf(tmp, "rgb255=(%d,%d,%d) ",r,g,b); + sprintf(tmp, "rgb255=(%d,%d,%d) ", r, g, b); ret.append(tmp); - if (intType != 2) // sampled + if(intType != 2) // sampled // reinsert, because then the end color is interpreted correctly // for shader=flat mean ret.append(tmp); } - //endpoint - r = CTX::instance()->unpackRed(ct->table[ct->size-1]); - g = CTX::instance()->unpackGreen(ct->table[ct->size-1]); - b = CTX::instance()->unpackBlue(ct->table[ct->size-1]); - sprintf(tmp, "rgb255=(%d,%d,%d) ",r,g,b); + // endpoint + r = CTX::instance()->unpackRed(ct->table[ct->size - 1]); + g = CTX::instance()->unpackGreen(ct->table[ct->size - 1]); + b = CTX::instance()->unpackBlue(ct->table[ct->size - 1]); + sprintf(tmp, "rgb255=(%d,%d,%d) ", r, g, b); ret.append(tmp); - if (intType != 2) // sampled + if(intType != 2) // sampled // reinsert, because then the end color is interpreted correctly // for shader=flat mean ret.append(tmp); @@ -73,83 +76,86 @@ static int assembleColmapStr(const int num, const int intType, int &samples, return 0; } -static int assembleColbarStr(const int num, const int intType, const int samples, - std::string &ret) +static int assembleColbarStr(const int num, const int intType, + const int samples, std::string &ret) { double cbmin, cbmax; cbmin = opt_view_min(num, GMSH_GET, 0); cbmax = opt_view_max(num, GMSH_GET, 0); - int rangeType = (int) opt_view_range_type(num, GMSH_GET,0); + int rangeType = (int)opt_view_range_type(num, GMSH_GET, 0); char tmp[265]; - switch (rangeType) { - case 2: - { - cbmin = opt_view_custom_min(num, GMSH_GET, 0); - cbmax = opt_view_custom_max(num, GMSH_GET, 0); - break; - } - case 1: // default - case 3: // per time step FIXME - default: break; + switch(rangeType) { + case 2: { + cbmin = opt_view_custom_min(num, GMSH_GET, 0); + cbmax = opt_view_custom_max(num, GMSH_GET, 0); + break; + } + case 1: // default + case 3: // per time step FIXME + default: break; } ret.assign("\tcolorbar style={\n\t\t%%width=0.5cm, " "%% adjust width of colorbar\n" "\t\t%%height=6cm,%% adjust height of colorbar,\n"); - if (intType != 2) { // sampled - sprintf(tmp, "\t\tsamples=%d,\n", samples+1); + if(intType != 2) { // sampled + sprintf(tmp, "\t\tsamples=%d,\n", samples + 1); ret.append(tmp); } - int scaleType = (int) opt_view_scale_type(num, GMSH_GET, 0); - int horizontal = (int) opt_print_pgf_horiz_bar(0, GMSH_GET, 0); - //1 linear - //2 log - //3 double log ??? - if (scaleType == 2) { // log - // see http://tex.stackexchange.com/questions/23750/log-color-bar-meta-data-in-pgfplot - if (horizontal) + int scaleType = (int)opt_view_scale_type(num, GMSH_GET, 0); + int horizontal = (int)opt_print_pgf_horiz_bar(0, GMSH_GET, 0); + // 1 linear + // 2 log + // 3 double log ??? + if(scaleType == 2) { // log + // see + // http://tex.stackexchange.com/questions/23750/log-color-bar-meta-data-in-pgfplot + if(horizontal) sprintf(tmp, "\t\txticklabel={$10^{\\pgfmathparse{\\tick}" - "\\pgfmathprintnumber\\pgfmathresult}$},\n"); + "\\pgfmathprintnumber\\pgfmathresult}$},\n"); else sprintf(tmp, "\t\tyticklabel={$10^{\\pgfmathparse{\\tick}" - "\\pgfmathprintnumber\\pgfmathresult}$},\n"); + "\\pgfmathprintnumber\\pgfmathresult}$},\n"); ret.append(tmp); } ret.append("\t}]\n\t %% a dummy plot for the colorbar (invisible):\n"); - if (scaleType == 2) {// log - cbmin = log10 (cbmin); - cbmax = log10 (cbmax); - } - sprintf(tmp, "\t \\addplot[point meta min=%f," - "point meta max=%f, update limits=false, draw=none, colorbar source]\n\t" - "coordinates{(1,1)};\n", cbmin, cbmax); + if(scaleType == 2) { // log + cbmin = log10(cbmin); + cbmax = log10(cbmax); + } + sprintf( + tmp, + "\t \\addplot[point meta min=%f," + "point meta max=%f, update limits=false, draw=none, colorbar source]\n\t" + "coordinates{(1,1)};\n", + cbmin, cbmax); ret.append(tmp); return 0; } static int assemblePostAxis(const int num, const int intType, std::string &ret) { - int horizontal = (int) opt_print_pgf_horiz_bar(0, GMSH_GET, 0); + int horizontal = (int)opt_print_pgf_horiz_bar(0, GMSH_GET, 0); std::string post_var; char tmp[265]; post_var = PView::list[num]->getData()->getName(); - if (!post_var.empty()) { - sprintf(tmp,"\ttitle={%s},\n", post_var.c_str() ); + if(!post_var.empty()) { + sprintf(tmp, "\ttitle={%s},\n", post_var.c_str()); ret.assign(tmp); } ret.append("\tcolorbar,\n\tcolormap name=gmshcolormap,\n"); - if (horizontal) { + if(horizontal) { ret.append("\tcolorbar horizontal,\n"); } else { ret.append("\tcolorbar right, %% or left...\n"); } - if (intType == 3){ // sampled + if(intType == 3) { // sampled ret.append("\tcolorbar sampled,\n"); } - else if (intType == 1){ + else if(intType == 1) { ret.append("\tcolorbar sampled line,\n"); } return 0; @@ -159,7 +165,7 @@ static int getMinMaxOfAxis(const int num, double result[8][3]) { double xmin, xmax, ymin, ymax, zmin, zmax; // axes ranges - if (!(int) opt_general_axes_auto_position(0, GMSH_GET,0)) { + if(!(int)opt_general_axes_auto_position(0, GMSH_GET, 0)) { // needs to get manual axes set xmin = opt_general_axes_xmin(0, GMSH_GET, 0); xmax = opt_general_axes_xmax(0, GMSH_GET, 0); @@ -167,11 +173,11 @@ static int getMinMaxOfAxis(const int num, double result[8][3]) ymax = opt_general_axes_ymax(0, GMSH_GET, 0); zmin = opt_general_axes_zmin(0, GMSH_GET, 0); zmax = opt_general_axes_zmax(0, GMSH_GET, 0); - fprintf(stderr,"General axes non auto, using\n"); - fprintf(stderr,"x=(%f,%f), y=(%f,%f), z=(%f,%f)\n", - xmin, xmax, ymin, ymax, zmin, zmax); + fprintf(stderr, "General axes non auto, using\n"); + fprintf(stderr, "x=(%f,%f), y=(%f,%f), z=(%f,%f)\n", xmin, xmax, ymin, ymax, + zmin, zmax); } - else if (num >= 0 && !(int) opt_view_axes_auto_position(num, GMSH_GET,0) ) { + else if(num >= 0 && !(int)opt_view_axes_auto_position(num, GMSH_GET, 0)) { // needs to get manual axes set xmin = opt_view_axes_xmin(num, GMSH_GET, 0); xmax = opt_view_axes_xmax(num, GMSH_GET, 0); @@ -179,20 +185,20 @@ static int getMinMaxOfAxis(const int num, double result[8][3]) ymax = opt_view_axes_ymax(num, GMSH_GET, 0); zmin = opt_view_axes_zmin(num, GMSH_GET, 0); zmax = opt_view_axes_zmax(num, GMSH_GET, 0); - fprintf(stderr,"View axes non auto, using:\n"); - fprintf(stderr,"x=(%f,%f), y=(%f,%f), z=(%f,%f)\n", - xmin, xmax, ymin, ymax, zmin, zmax); + fprintf(stderr, "View axes non auto, using:\n"); + fprintf(stderr, "x=(%f,%f), y=(%f,%f), z=(%f,%f)\n", xmin, xmax, ymin, ymax, + zmin, zmax); } - else {// default + else { // default xmin = CTX::instance()->min[0]; xmax = CTX::instance()->max[0]; ymin = CTX::instance()->min[1]; ymax = CTX::instance()->max[1]; zmin = CTX::instance()->min[2]; zmax = CTX::instance()->max[2]; - fprintf(stderr,"Axes auto, using:\n"); - fprintf(stderr,"x=(%f,%f), y=(%f,%f), z=(%f,%f)\n", - xmin, xmax, ymin, ymax, zmin, zmax); + fprintf(stderr, "Axes auto, using:\n"); + fprintf(stderr, "x=(%f,%f), y=(%f,%f), z=(%f,%f)\n", xmin, xmax, ymin, ymax, + zmin, zmax); } result[0][0] = result[1][0] = result[2][0] = result[3][0] = xmin; result[4][0] = result[5][0] = result[6][0] = result[7][0] = xmax; @@ -219,146 +225,154 @@ static int assemble2d(const int num, const int exportAxis, std::string &axisstr, std::string &plotstr, double *eulerAngles) { double axPts[8][3]; - double factor=1.; + double factor = 1.; double xmin, xmax, ymin, ymax; axisstr.append("\taxis equal image, %% use png aspect ratio\n"); - if (exportAxis) { + if(exportAxis) { getMinMaxOfAxis(num, axPts); std::string xlab, ylab, zlab; xlab = CTX::instance()->axesLabel[0]; ylab = CTX::instance()->axesLabel[1]; zlab = CTX::instance()->axesLabel[2]; - if (xlab.empty()) - xlab = "x"; - if (ylab.empty()) - ylab = "y"; - if (zlab.empty()) - zlab = "z"; - - fprintf(stderr,"Euler two dim: 0:%f, 1:%f, 2:%f\n", - eulerAngles[0], eulerAngles[1], eulerAngles[2]); - int r0 = (int) (eulerAngles[0]+0.5); - int r1 = (int) (eulerAngles[1]+0.5); - int r2 = (int) (eulerAngles[2]+0.5); - if (r0 % 90 != 0 || r1 % 90 != 0 || r2 % 90 !=0) { - fprintf(stderr,"Euler two dim: 0:%d, 1:%d, 2:%d\n", r0, r1, r2); + if(xlab.empty()) xlab = "x"; + if(ylab.empty()) ylab = "y"; + if(zlab.empty()) zlab = "z"; + + fprintf(stderr, "Euler two dim: 0:%f, 1:%f, 2:%f\n", eulerAngles[0], + eulerAngles[1], eulerAngles[2]); + int r0 = (int)(eulerAngles[0] + 0.5); + int r1 = (int)(eulerAngles[1] + 0.5); + int r2 = (int)(eulerAngles[2] + 0.5); + if(r0 % 90 != 0 || r1 % 90 != 0 || r2 % 90 != 0) { + fprintf(stderr, "Euler two dim: 0:%d, 1:%d, 2:%d\n", r0, r1, r2); Msg::Error("Please select a plane view (X, Y, Z)"); return 1; } - if (r0 % 180 == 0 && r1 % 360 == 0 && r2 % 180 == 0) { + if(r0 % 180 == 0 && r1 % 360 == 0 && r2 % 180 == 0) { // xy - xmin=axPts[0][0]; xmax=axPts[4][0]; ymin=axPts[0][1]; ymax=axPts[2][1]; - if (r2 == 180) - axisstr.append("\tx dir=reverse,\n"); - if ((r2 == 180 && abs(r0) < 1) || (r0 == 180 && abs(r2) < 1)) + xmin = axPts[0][0]; + xmax = axPts[4][0]; + ymin = axPts[0][1]; + ymax = axPts[2][1]; + if(r2 == 180) axisstr.append("\tx dir=reverse,\n"); + if((r2 == 180 && abs(r0) < 1) || (r0 == 180 && abs(r2) < 1)) axisstr.append("\ty dir=reverse,\n"); axisstr.append("\txlabel={" + xlab + "},\n"); axisstr.append("\tylabel={" + ylab + "},\n"); } - else if (r0 % 180 == 0 && r1 % 360 ==0 && (r2 == 90 || r2 == 270)) { + else if(r0 % 180 == 0 && r1 % 360 == 0 && (r2 == 90 || r2 == 270)) { // yx - xmin=axPts[0][1]; xmax=axPts[2][1]; ymin=axPts[0][0]; ymax=axPts[4][0]; - if (r2 == 90) - axisstr.append("\tx dir=reverse,\n"); - if (r2 == 270 || (r2 == 90 && r0 == 180)) + xmin = axPts[0][1]; + xmax = axPts[2][1]; + ymin = axPts[0][0]; + ymax = axPts[4][0]; + if(r2 == 90) axisstr.append("\tx dir=reverse,\n"); + if(r2 == 270 || (r2 == 90 && r0 == 180)) axisstr.append("\ty dir=reverse,\n"); axisstr.append("\txlabel={" + ylab + "},\n"); axisstr.append("\tylabel={" + xlab + "},\n"); } - else if ((r0 == 90 || r0 == 270) && r1 % 360 == 0 && - (r2 == 90 || r2 == 270)) { - xmin=axPts[0][1]; xmax=axPts[2][1]; ymin=axPts[0][2]; ymax=axPts[1][2]; - if(r2 == 90) - axisstr.append("\tx dir=reverse,\n"); - if(r0 == 90) - axisstr.append("\ty dir=reverse,\n"); + else if((r0 == 90 || r0 == 270) && r1 % 360 == 0 && + (r2 == 90 || r2 == 270)) { + xmin = axPts[0][1]; + xmax = axPts[2][1]; + ymin = axPts[0][2]; + ymax = axPts[1][2]; + if(r2 == 90) axisstr.append("\tx dir=reverse,\n"); + if(r0 == 90) axisstr.append("\ty dir=reverse,\n"); // yz axisstr.append("\txlabel={" + ylab + "},\n"); axisstr.append("\tylabel={" + zlab + "},\n"); } - else if (r0 % 360 == 0 && (r1 == 90 || r1 == 270) && r2 % 180 == 0) { + else if(r0 % 360 == 0 && (r1 == 90 || r1 == 270) && r2 % 180 == 0) { // zy - xmin=axPts[0][2]; xmax=axPts[1][2]; ymin=axPts[0][1]; ymax=axPts[2][1]; - if (r1 == 270) - axisstr.append("\tx dir=reverse,\n"); - if (r2 == 180) - axisstr.append("\ty dir=reverse,\n"); + xmin = axPts[0][2]; + xmax = axPts[1][2]; + ymin = axPts[0][1]; + ymax = axPts[2][1]; + if(r1 == 270) axisstr.append("\tx dir=reverse,\n"); + if(r2 == 180) axisstr.append("\ty dir=reverse,\n"); axisstr.append("\txlabel={" + zlab + "},\n"); axisstr.append("\tylabel={" + ylab + "},\n"); } - else if ((r0 == 90 || r0 == 270) && r1 % 360 == 0 && r2 % 180 == 0) { + else if((r0 == 90 || r0 == 270) && r1 % 360 == 0 && r2 % 180 == 0) { // xz - xmin=axPts[0][0]; xmax=axPts[4][0]; ymin=axPts[0][2]; ymax=axPts[1][2]; - if (r2 == 180) // x dir=reverse + xmin = axPts[0][0]; + xmax = axPts[4][0]; + ymin = axPts[0][2]; + ymax = axPts[1][2]; + if(r2 == 180) // x dir=reverse axisstr.append("\tx dir=reverse,\n"); - if (r0 == 90) - axisstr.append("\ty dir=reverse,\n"); + if(r0 == 90) axisstr.append("\ty dir=reverse,\n"); axisstr.append("\txlabel={" + xlab + "},\n"); axisstr.append("\tylabel={" + zlab + "},\n"); } - else if (r0 % 360 == 0 && (r1 == 90 || r1 == 270) && - (r2 == 90 || r2 == 270)) { - if (r1 == 270) - axisstr.append("\tx dir=reverse,\n"); - if (r2 == 270) - axisstr.append("\ty dir=reverse,\n"); + else if(r0 % 360 == 0 && (r1 == 90 || r1 == 270) && + (r2 == 90 || r2 == 270)) { + if(r1 == 270) axisstr.append("\tx dir=reverse,\n"); + if(r2 == 270) axisstr.append("\ty dir=reverse,\n"); // zx - xmin=axPts[0][2]; xmax=axPts[1][2]; ymin=axPts[0][0]; ymax=axPts[4][0]; + xmin = axPts[0][2]; + xmax = axPts[1][2]; + ymin = axPts[0][0]; + ymax = axPts[4][0]; axisstr.append("\txlabel={" + zlab + "},\n"); axisstr.append("\tylabel={" + xlab + "},\n"); } else { Msg::Error("Cannot infer orientation from Euler angles..."); // this should not happen - //error=true; + // error=true; return 2; } - if (fabs(xmax - xmin) < 1e-8 || - fabs(ymax - ymin) < 1e-8) { - Msg::Error("I inferred x (%f) or y (%f) dimension to be zero. Cannot produce.", - fabs(xmax - xmin), fabs(ymax - ymin)); + if(fabs(xmax - xmin) < 1e-8 || fabs(ymax - ymin) < 1e-8) { + Msg::Error( + "I inferred x (%f) or y (%f) dimension to be zero. Cannot produce.", + fabs(xmax - xmin), fabs(ymax - ymin)); return 3; } - double diagonal[3] = {xmax-xmin, ymax-ymin, 0}; + double diagonal[3] = {xmax - xmin, ymax - ymin, 0}; double minlen = norm3(diagonal); std::string suffix; if(minlen < 1e-5) { - factor=1e6; + factor = 1e6; suffix.assign(" / $\\mu$m"); } else if(minlen < 0.01) { - factor=1e3; + factor = 1e3; suffix.assign(" / mm"); } else if(minlen > 1e6) { - factor=1e-6; + factor = 1e-6; suffix.assign(" / Mm"); } else if(minlen > 1000) { - factor=1e-3; + factor = 1e-3; suffix.assign(" / Km"); } - if (factor != 1) { + if(factor != 1) { char tmp[265]; - sprintf(tmp, "The pgf output has been rescaled in order to please " + sprintf(tmp, + "The pgf output has been rescaled in order to please " "the TeX number precision/range. Rescaling your results by " - "a factor %g", factor); + "a factor %g", + factor); Msg::Warning(tmp); // sprintf(tmp, "$\\times 10^{%d}$},",(int)(log10(factor)+0.5)); // std::string repl = tmp; // replace two labels std::size_t foundy = axisstr.rfind("},"); - if (foundy!=std::string::npos) - axisstr.insert(foundy,suffix); + if(foundy != std::string::npos) + axisstr.insert(foundy, suffix); else return 4; std::size_t foundx = axisstr.rfind("},", foundy); - if (foundx!=std::string::npos) - axisstr.insert(foundx,suffix); + if(foundx != std::string::npos) + axisstr.insert(foundx, suffix); else return 4; } @@ -369,12 +383,12 @@ static int assemble2d(const int num, const int exportAxis, std::string &axisstr, } else { // no axis - xmin=0, xmax=1, ymin=0, ymax=1; + xmin = 0, xmax = 1, ymin = 0, ymax = 1; axisstr.append("\thide axis,\n"); } char tmp[265]; - sprintf(tmp,"\t \\addplot graphics[xmin=%f, xmax=%f, ymin=%f, ymax=%f]\n", - xmin*factor, xmax*factor, ymin*factor, ymax*factor); + sprintf(tmp, "\t \\addplot graphics[xmin=%f, xmax=%f, ymin=%f, ymax=%f]\n", + xmin * factor, xmax * factor, ymin * factor, ymax * factor); plotstr.assign(tmp); @@ -385,7 +399,7 @@ static int assemble3d(const int num, const int exportAxis, std::string &axisstr, std::string &plotstr, double *eulerAngles, int *viewport, double *proj, double *model, int ypix, int xpix) { - if (exportAxis) { + if(exportAxis) { axisstr.append("\tenlargelimits=false, %% tight axis, use xmin=<val>, "); axisstr.append("xmax=<val> for custom bounding box\n"); axisstr.append("\tgrid=both,\n\tminor tick num=1,\n"); @@ -393,24 +407,21 @@ static int assemble3d(const int num, const int exportAxis, std::string &axisstr, xlab = CTX::instance()->axesLabel[0]; ylab = CTX::instance()->axesLabel[1]; zlab = CTX::instance()->axesLabel[2]; - if (xlab.empty()) - xlab = "x"; - if (ylab.empty()) - ylab = "y"; - if (zlab.empty()) - zlab = "z"; - axisstr.append("\txlabel={" + xlab + "}, %%\n\tylabel={" + - ylab + "},\n\tzlabel={" + zlab + "},\n"); + if(xlab.empty()) xlab = "x"; + if(ylab.empty()) ylab = "y"; + if(zlab.empty()) zlab = "z"; + axisstr.append("\txlabel={" + xlab + "}, %%\n\tylabel={" + ylab + + "},\n\tzlabel={" + zlab + "},\n"); axisstr.append("\tzlabel style={rotate=-90},\n"); // bug? } else { - if(opt_general_orthographic(0, GMSH_GET, 0) == 0 ) { + if(opt_general_orthographic(0, GMSH_GET, 0) == 0) { Msg::Warning("Axes are not orthogonal, but because you do not want " "any axes, I'll continue with a 2d picture."); return assemble2d(num, 0, axisstr, plotstr, eulerAngles); } - if (CTX::instance()->camera) { + if(CTX::instance()->camera) { Msg::Warning("Camera output not supported, but since you do not want " "any axes, I'll continue with a 2d picture."); return assemble2d(num, 0, axisstr, plotstr, eulerAngles); @@ -427,96 +438,98 @@ static int assemble3d(const int num, const int exportAxis, std::string &axisstr, double axPts[8][3]; getMinMaxOfAxis(num, axPts); - double factor=1.; + double factor = 1.; // requires the pixel coordinates of the axis ends (actually any four // points with all different x/y/z <pixX, pixY> would suffice) double axViewPt[8][3]; std::vector<int> acceptableAnchors; std::vector<int> masked; - bool reorder = false; + bool reorder = false; double minlen = 0.; std::string suffix; - for (unsigned int j=0; j < 8; j++) { + for(unsigned int j = 0; j < 8; j++) { // project the 8 axis end points to pixel coordinates, // accept if they are in the screen range. - gluProject(axPts[j][0], axPts[j][1], axPts[j][2], model, proj, - viewport, &axViewPt[j][0], &axViewPt[j][1], &axViewPt[j][2]); + gluProject(axPts[j][0], axPts[j][1], axPts[j][2], model, proj, viewport, + &axViewPt[j][0], &axViewPt[j][1], &axViewPt[j][2]); // printf("x=%f, y=%f, z=%f\n", axPts[j][0], axPts[j][1], axPts[j][2]); // printf("xprn=%f, yprn=%f, zprn=%f\n", // axViewPt[j][0], axViewPt[j][1], axViewPt[j][2]); - if ((int)(axViewPt[j][0]+0.5) <= xpix && - (int)(axViewPt[j][1]+0.5) <= ypix) { + if((int)(axViewPt[j][0] + 0.5) <= xpix && + (int)(axViewPt[j][1] + 0.5) <= ypix) { acceptableAnchors.push_back(j); } else masked.push_back(j); - if (j>0) { + if(j > 0) { // respecting TeXs range limts (1e-4 relative precision) minlen = norm3(axPts[j]); - //fprintf(stderr,"j=%d, vec length %f:\n", j, minlen); + // fprintf(stderr,"j=%d, vec length %f:\n", j, minlen); if(minlen < 1e-5) { - factor=1e6; + factor = 1e6; suffix.assign("/$\\mu$m"); } else if(minlen < 0.01) { - factor=1e3; + factor = 1e3; suffix.assign("/mm"); } else if(minlen > 1e6) { - factor=1e-6; + factor = 1e-6; suffix.assign("/Mm"); } else if(minlen > 1000) { - factor=1e-3; + factor = 1e-3; suffix.assign("/Km"); } } - if (j == 1 && acceptableAnchors.size() == 2) { + if(j == 1 && acceptableAnchors.size() == 2) { // precaution: if the first two coordinates are accepted, a // division by zero can occur in pgfplots // furthermore, four points with equal x=xmin leads to // singular system in pgfplots - reorder=true; + reorder = true; acceptableAnchors.pop_back(); } } - if (reorder) acceptableAnchors.push_back(1); + if(reorder) acceptableAnchors.push_back(1); - if (acceptableAnchors.size() < 4) { + if(acceptableAnchors.size() < 4) { Msg::Error("Unable to calculate anchors for pgf output. " "Make sure the entire scene is visible or adjust " "the axes min/max values to fit inside your screen."); return 2; } - if (factor != 1) { + if(factor != 1) { char tmp[265]; - sprintf(tmp, "The pgf output has been rescaled in order to please " + sprintf(tmp, + "The pgf output has been rescaled in order to please " "the TeX number precision/range. Rescaling your results by " - "a factor %g", factor); + "a factor %g", + factor); Msg::Warning(tmp); // replace three labels - if (exportAxis) { + if(exportAxis) { // xlabel={x<>}, %% // ylabel={y<>}, // zlabel={z<>}, // zlabel style={rotate=-90}, std::size_t foundrot = axisstr.rfind("},"); - std::size_t foundz = axisstr.rfind("},", foundrot-1); - if (foundz!=std::string::npos) - axisstr.insert(foundz,suffix); + std::size_t foundz = axisstr.rfind("},", foundrot - 1); + if(foundz != std::string::npos) + axisstr.insert(foundz, suffix); else return 4; - std::size_t foundy = axisstr.rfind("},",foundz); - if (foundy!=std::string::npos) - axisstr.insert(foundy,suffix); + std::size_t foundy = axisstr.rfind("},", foundz); + if(foundy != std::string::npos) + axisstr.insert(foundy, suffix); else return 4; std::size_t foundx = axisstr.rfind("},", foundy); - if (foundx!=std::string::npos) - axisstr.insert(foundx,suffix); + if(foundx != std::string::npos) + axisstr.insert(foundx, suffix); else return 4; } @@ -526,24 +539,24 @@ static int assemble3d(const int num, const int exportAxis, std::string &axisstr, plotstr.assign("\t \\addplot3[surf] graphics[debug=false,%%=visual,\n"); plotstr.append("\t points={%%\n"); - unsigned int j=0; - for (std::vector<int>::iterator it = acceptableAnchors.begin(); - it != acceptableAnchors.end(); ++it, j++) { - sprintf(tmp,"\t (%f,%f,%f)", factor*axPts[*it][0], - factor*axPts[*it][1], factor*axPts[*it][2]); + unsigned int j = 0; + for(std::vector<int>::iterator it = acceptableAnchors.begin(); + it != acceptableAnchors.end(); ++it, j++) { + sprintf(tmp, "\t (%f,%f,%f)", factor * axPts[*it][0], + factor * axPts[*it][1], factor * axPts[*it][2]); plotstr.append(tmp); - if (j > 3) { + if(j > 3) { plotstr.append("%%"); } // ypix-y syntax for easier debugging w/ e.g. gimp pixel - sprintf(tmp," => (%d, %d-%d)\n", (int)(axViewPt[*it][0]+0.5), - ypix,ypix-(int)(axViewPt[*it][1]+0.5)); + sprintf(tmp, " => (%d, %d-%d)\n", (int)(axViewPt[*it][0] + 0.5), ypix, + ypix - (int)(axViewPt[*it][1] + 0.5)); plotstr.append(tmp); } - for (std::vector<int>::iterator it = masked.begin(); - it != masked.end(); ++it) { - sprintf(tmp,"\t (%f,%f,%f)", factor*axPts[*it][0], - factor*axPts[*it][1], factor*axPts[*it][2]); + for(std::vector<int>::iterator it = masked.begin(); it != masked.end(); + ++it) { + sprintf(tmp, "\t (%f,%f,%f)", factor * axPts[*it][0], + factor * axPts[*it][1], factor * axPts[*it][2]); plotstr.append(tmp); plotstr.append(" %% out of pixel range, discarded\n"); } @@ -551,9 +564,9 @@ static int assemble3d(const int num, const int exportAxis, std::string &axisstr, return 0; } -int print_pgf(const std::string &name, const int num, const int cnt, - PixelBuffer *buffer, double *eulerAngles, - int *viewport, double *proj, double *model) +int print_pgf(const std::string &name, const int num, const int cnt, + PixelBuffer *buffer, double *eulerAngles, int *viewport, + double *proj, double *model) { int ypix = buffer->getHeight(); int xpix = buffer->getWidth(); @@ -564,7 +577,7 @@ int print_pgf(const std::string &name, const int num, const int cnt, std::string pgffilen = path + base + ".pgf"; std::string texfilen = path + base + ".tex"; FILE *fp = Fopen(pngfilen.c_str(), "wb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", pngfilen.c_str()); return 1; } @@ -574,7 +587,7 @@ int print_pgf(const std::string &name, const int num, const int cnt, // write pgf int twoDim = (int)opt_print_pgf_two_dim(0, GMSH_GET, 0); int exportAxis = (int)opt_print_pgf_export_axis(0, GMSH_GET, 0); - if (cnt > 1) + if(cnt > 1) Msg::Warning("PGF colorbar output works only with a single visible " "scale. Consider disabling all but one. I can only create a " "single colorbar. Colorbar will be suppressed"); @@ -582,8 +595,8 @@ int print_pgf(const std::string &name, const int num, const int cnt, int samples; std::string colmap_s, colbar_s, post_axis_s; // color map - if (cnt == 1) { // one post processing view scale visible - int intType = (int) opt_view_intervals_type(num, GMSH_GET, 0); + if(cnt == 1) { // one post processing view scale visible + int intType = (int)opt_view_intervals_type(num, GMSH_GET, 0); if(assembleColmapStr(num, intType, samples, colmap_s) != 0) { Msg::Error("Unable to assemble colormap for PGF output"); return 1; @@ -604,23 +617,23 @@ int print_pgf(const std::string &name, const int num, const int cnt, std::string axis_s, plot_s; axis_s.assign("\\begin{tikzpicture}\n\\begin{axis}[\n\twidth=.5\\linewidth," "%% set figure width here\n"); - if (twoDim) { - if (assemble2d(num, exportAxis, axis_s, plot_s, eulerAngles) != 0) { + if(twoDim) { + if(assemble2d(num, exportAxis, axis_s, plot_s, eulerAngles) != 0) { return 1; } } else { // 3d - if (assemble3d(num, exportAxis, axis_s, plot_s, eulerAngles, - viewport, proj, model, ypix, xpix) != 0) { + if(assemble3d(num, exportAxis, axis_s, plot_s, eulerAngles, viewport, proj, + model, ypix, xpix) != 0) { return 1; } } char tmp[265]; - sprintf(tmp,"\t {%s.png};\n", base.c_str()); + sprintf(tmp, "\t {%s.png};\n", base.c_str()); plot_s.append(tmp); fp = Fopen(pgffilen.c_str(), "wb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", pgffilen.c_str()); return 1; } @@ -632,54 +645,59 @@ int print_pgf(const std::string &name, const int num, const int cnt, fprintf(fp, "\\end{axis}\n\\end{tikzpicture}%%\n"); fclose(fp); - if (twoDim) { + if(twoDim) { // try to trim the png... char tmp[2048]; - if (system(NULL)) { + if(system(NULL)) { std::string pngname = name; - pngname.replace(pngname.end()-3, pngname.end(), "png"); + pngname.replace(pngname.end() - 3, pngname.end(), "png"); sprintf(tmp, "convert -trim %s %s", pngname.c_str(), pngname.c_str()); Msg::Info("Running:"); Msg::Info(tmp); int ret = system(tmp); Msg::Info("Conversion returned value %d", ret); - if (ret == 0) // success + if(ret == 0) // success Msg::Info("Automatic trim successful."); else { Msg::Warning("Cannot automatically trim output png."); - sprintf(tmp, "One should now manually crop the margins, using e.g." + sprintf(tmp, + "One should now manually crop the margins, using e.g." "gimp or `convert -trim %s %s` to get rid of any remaining" - "margins.", pngfilen.c_str(), pngfilen.c_str()); + "margins.", + pngfilen.c_str(), pngfilen.c_str()); Msg::Warning(tmp); } } else { Msg::Warning("Cannot automatically trim output png."); - sprintf(tmp, "One should now manually crop the margins, using e.g." + sprintf(tmp, + "One should now manually crop the margins, using e.g." "gimp or `convert -trim %s %s` to get rid of any remaining" - "margins.", pngfilen.c_str(), pngfilen.c_str()); + "margins.", + pngfilen.c_str(), pngfilen.c_str()); Msg::Warning(tmp); } } // try to add transparency, do not(!) crop otherwise the transformation // matrix is wrong!!!! - if (!twoDim) { + if(!twoDim) { char tmp[2048]; - if (system(NULL)) { + if(system(NULL)) { std::string pngname = name; - pngname.replace(pngname.end()-3, pngname.end(), "png"); - sprintf(tmp, "convert -transparent white %s %s", - pngname.c_str(), pngname.c_str()); + pngname.replace(pngname.end() - 3, pngname.end(), "png"); + sprintf(tmp, "convert -transparent white %s %s", pngname.c_str(), + pngname.c_str()); Msg::Info("Running:"); Msg::Info(tmp); int ret = system(tmp); Msg::Info("Conversion returned value %d", ret); - if (ret == 0) // success + if(ret == 0) // success Msg::Info("Automatic transparent white background successful."); else { Msg::Warning("Cannot automatically add transparency to png."); - sprintf(tmp, "One should now manually add a transparent layer in " + sprintf(tmp, + "One should now manually add a transparent layer in " "order to not obstruct the axis. e.g. using gimp or " "convert -transparent white %s %s`.", pngfilen.c_str(), pngfilen.c_str()); @@ -688,7 +706,8 @@ int print_pgf(const std::string &name, const int num, const int cnt, } else { // exit (EXIT_FAILURE); Msg::Warning("Cannot automatically add transparency to output png."); - sprintf(tmp, "One should now manually add a transparent layer in " + sprintf(tmp, + "One should now manually add a transparent layer in " "order to not obstruct the axis. e.g. using gimp or " "`convert -transparent white %s %s`.", pngfilen.c_str(), pngfilen.c_str()); @@ -698,17 +717,17 @@ int print_pgf(const std::string &name, const int num, const int cnt, // try to write a helper tex file just in case it does not exist fp = Fopen(texfilen.c_str(), "r"); - if(fp){ + if(fp) { fclose(fp); Msg::Info("File '%s' exists, please add '\\input{%s}' by yourself.", texfilen.c_str(), pgffilen.c_str()); } else { fp = Fopen(texfilen.c_str(), "w"); - fprintf(fp,"\\documentclass{article}\n\\usepackage{pgfplots}\n" - "\\pgfplotsset{compat=1.8}\n\\begin{document}\n"); - fprintf(fp,"\n\\input{%s}\n", pgffilen.c_str()); - fprintf(fp,"\n\\end{document}\n"); + fprintf(fp, "\\documentclass{article}\n\\usepackage{pgfplots}\n" + "\\pgfplotsset{compat=1.8}\n\\begin{document}\n"); + fprintf(fp, "\n\\input{%s}\n", pgffilen.c_str()); + fprintf(fp, "\n\\end{document}\n"); fclose(fp); } return 0; diff --git a/Graphics/gl2pgf.h b/Graphics/gl2pgf.h index 62c17c126e34335fe6d29e3b98bc3e90a13bdf89..c7cf5085075d40b2ef24ea0f3eb3912c7c09d3ea 100644 --- a/Graphics/gl2pgf.h +++ b/Graphics/gl2pgf.h @@ -9,8 +9,8 @@ #include <string> #include "PixelBuffer.h" -int print_pgf(const std::string &name, const int num, const int cnt, - PixelBuffer *buffer, double *eulerAngles, - int *viewport, double *proj, double *model); +int print_pgf(const std::string &name, const int num, const int cnt, + PixelBuffer *buffer, double *eulerAngles, int *viewport, + double *proj, double *model); #endif diff --git a/Graphics/gl2png.cpp b/Graphics/gl2png.cpp index 4f25c57a10ee1b25d00b22f5cc22dc0c9ebd6114..42435a55542b20c30edb1a321ba79803f41da605 100644 --- a/Graphics/gl2png.cpp +++ b/Graphics/gl2png.cpp @@ -18,24 +18,25 @@ void create_png(FILE *file, PixelBuffer *buffer, int quality) #include <png.h> #ifndef png_jmpbuf -# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) #endif void create_png(FILE *file, PixelBuffer *buffer, int quality) { if((buffer->getFormat() != GL_RGB && buffer->getFormat() != GL_RGBA) || - buffer->getType() != GL_UNSIGNED_BYTE){ + buffer->getType() != GL_UNSIGNED_BYTE) { Msg::Error("PNG only implemented for GL_RGB/GL_RGBA and GL_UNSIGNED_BYTE"); return; } - png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - + png_structp png_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if(png_ptr == NULL) { Msg::Error("Could not create PNG write struct"); return; } - + png_infop info_ptr = png_create_info_struct(png_ptr); if(info_ptr == NULL) { @@ -43,30 +44,31 @@ void create_png(FILE *file, PixelBuffer *buffer, int quality) Msg::Error("Could not create PNG info struct"); return; } - + if(setjmp(png_jmpbuf(png_ptr))) { png_destroy_write_struct(&png_ptr, &info_ptr); Msg::Error("Could not setjmp in PNG"); return; } - + png_init_io(png_ptr, file); - + int height = buffer->getHeight(); int width = buffer->getWidth(); int numcomp = buffer->getNumComp(); - //png_set_compression_level(png_ptr, 5); - png_set_IHDR(png_ptr, info_ptr, width, height, 8, + // png_set_compression_level(png_ptr, 5); + png_set_IHDR(png_ptr, info_ptr, width, height, 8, (numcomp == 3) ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGBA, - PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, + PNG_FILTER_TYPE_BASE); time_t now; time(&now); - png_text text_ptr[10]; - text_ptr[0].key = (char*)"Creator"; - text_ptr[0].text = (char*)"Gmsh"; + png_text text_ptr[10]; + text_ptr[0].key = (char *)"Creator"; + text_ptr[0].text = (char *)"Gmsh"; text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[1].key = (char*)"Date"; + text_ptr[1].key = (char *)"Date"; text_ptr[1].text = ctime(&now); text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; png_set_text(png_ptr, info_ptr, text_ptr, 2); diff --git a/Graphics/gl2ppm.cpp b/Graphics/gl2ppm.cpp index fe61987934a257d61c20014c9121ab4e588a1732..1e125ba02c9f7f5532e3726701f6f175e15b6ccf 100644 --- a/Graphics/gl2ppm.cpp +++ b/Graphics/gl2ppm.cpp @@ -7,14 +7,14 @@ void create_ppm(FILE *outfile, PixelBuffer *buffer) { - if(buffer->getFormat() != GL_RGB || buffer->getType() != GL_UNSIGNED_BYTE){ + if(buffer->getFormat() != GL_RGB || buffer->getType() != GL_UNSIGNED_BYTE) { Msg::Error("PPM only implemented for GL_RGB and GL_UNSIGNED_BYTE"); return; } int width = buffer->getWidth(); int height = buffer->getHeight(); - unsigned char *pixels = (unsigned char*)buffer->getPixels(); + unsigned char *pixels = (unsigned char *)buffer->getPixels(); fprintf(outfile, "P6\n"); fprintf(outfile, "%d %d\n", width, height); diff --git a/Graphics/gl2ps.cpp b/Graphics/gl2ps.cpp index 3016ed529b7391f6e3f2699ce59014ca64f6b696..73df174efbce56117c533ea4e1832c30447ef458 100644 --- a/Graphics/gl2ps.cpp +++ b/Graphics/gl2ps.cpp @@ -59,52 +59,52 @@ /* Magic numbers (assuming that the order of magnitude of window coordinates is 10^3) */ -#define GL2PS_EPSILON 5.0e-3F -#define GL2PS_ZSCALE 1000.0F -#define GL2PS_ZOFFSET 5.0e-2F +#define GL2PS_EPSILON 5.0e-3F +#define GL2PS_ZSCALE 1000.0F +#define GL2PS_ZOFFSET 5.0e-2F #define GL2PS_ZOFFSET_LARGE 20.0F -#define GL2PS_ZERO(arg) (fabs(arg) < 1.e-20) +#define GL2PS_ZERO(arg) (fabs(arg) < 1.e-20) /* BSP tree primitive comparison */ -#define GL2PS_COINCIDENT 1 +#define GL2PS_COINCIDENT 1 #define GL2PS_IN_FRONT_OF 2 -#define GL2PS_IN_BACK_OF 3 -#define GL2PS_SPANNING 4 +#define GL2PS_IN_BACK_OF 3 +#define GL2PS_SPANNING 4 /* 2D BSP tree primitive comparison */ #define GL2PS_POINT_COINCIDENT 0 -#define GL2PS_POINT_INFRONT 1 -#define GL2PS_POINT_BACK 2 +#define GL2PS_POINT_INFRONT 1 +#define GL2PS_POINT_BACK 2 /* Internal feedback buffer pass-through tokens */ -#define GL2PS_BEGIN_OFFSET_TOKEN 1 -#define GL2PS_END_OFFSET_TOKEN 2 +#define GL2PS_BEGIN_OFFSET_TOKEN 1 +#define GL2PS_END_OFFSET_TOKEN 2 #define GL2PS_BEGIN_BOUNDARY_TOKEN 3 -#define GL2PS_END_BOUNDARY_TOKEN 4 -#define GL2PS_BEGIN_STIPPLE_TOKEN 5 -#define GL2PS_END_STIPPLE_TOKEN 6 -#define GL2PS_POINT_SIZE_TOKEN 7 -#define GL2PS_LINE_CAP_TOKEN 8 -#define GL2PS_LINE_JOIN_TOKEN 9 -#define GL2PS_LINE_WIDTH_TOKEN 10 -#define GL2PS_BEGIN_BLEND_TOKEN 11 -#define GL2PS_END_BLEND_TOKEN 12 -#define GL2PS_SRC_BLEND_TOKEN 13 -#define GL2PS_DST_BLEND_TOKEN 14 -#define GL2PS_IMAGEMAP_TOKEN 15 -#define GL2PS_DRAW_PIXELS_TOKEN 16 -#define GL2PS_TEXT_TOKEN 17 +#define GL2PS_END_BOUNDARY_TOKEN 4 +#define GL2PS_BEGIN_STIPPLE_TOKEN 5 +#define GL2PS_END_STIPPLE_TOKEN 6 +#define GL2PS_POINT_SIZE_TOKEN 7 +#define GL2PS_LINE_CAP_TOKEN 8 +#define GL2PS_LINE_JOIN_TOKEN 9 +#define GL2PS_LINE_WIDTH_TOKEN 10 +#define GL2PS_BEGIN_BLEND_TOKEN 11 +#define GL2PS_END_BLEND_TOKEN 12 +#define GL2PS_SRC_BLEND_TOKEN 13 +#define GL2PS_DST_BLEND_TOKEN 14 +#define GL2PS_IMAGEMAP_TOKEN 15 +#define GL2PS_DRAW_PIXELS_TOKEN 16 +#define GL2PS_TEXT_TOKEN 17 typedef enum { - T_UNDEFINED = -1, - T_CONST_COLOR = 1, - T_VAR_COLOR = 1<<1, - T_ALPHA_1 = 1<<2, - T_ALPHA_LESS_1 = 1<<3, - T_VAR_ALPHA = 1<<4 + T_UNDEFINED = -1, + T_CONST_COLOR = 1, + T_VAR_COLOR = 1 << 1, + T_ALPHA_1 = 1 << 2, + T_ALPHA_LESS_1 = 1 << 3, + T_VAR_ALPHA = 1 << 4 } GL2PS_TRIANGLE_PROPERTY; typedef GLfloat GL2PSplane[4]; @@ -182,8 +182,8 @@ typedef struct { #endif } GL2PScompress; -typedef struct{ - GL2PSlist* ptrlist; +typedef struct { + GL2PSlist *ptrlist; int gsno, fontno, imno, shno, maskshno, trgroupno; int gsobjno, fontobjno, imobjno, shobjno, maskshobjno, trgroupobjno; } GL2PSpdfgroup; @@ -232,12 +232,12 @@ typedef struct { } GL2PScontext; typedef struct { - void (*printHeader)(void); - void (*printFooter)(void); - void (*beginViewport)(GLint viewport[4]); + void (*printHeader)(void); + void (*printFooter)(void); + void (*beginViewport)(GLint viewport[4]); GLint (*endViewport)(void); - void (*printPrimitive)(void *data); - void (*printFinalPrimitive)(void); + void (*printPrimitive)(void *data); + void (*printFinalPrimitive)(void); const char *file_extension; const char *description; } GL2PSbackend; @@ -261,11 +261,11 @@ static void gl2psMsg(GLint level, const char *fmt, ...) { va_list args; - if(!(gl2ps->options & GL2PS_SILENT)){ - switch(level){ - case GL2PS_INFO : fprintf(stderr, "GL2PS info: "); break; - case GL2PS_WARNING : fprintf(stderr, "GL2PS warning: "); break; - case GL2PS_ERROR : fprintf(stderr, "GL2PS error: "); break; + if(!(gl2ps->options & GL2PS_SILENT)) { + switch(level) { + case GL2PS_INFO: fprintf(stderr, "GL2PS info: "); break; + case GL2PS_WARNING: fprintf(stderr, "GL2PS warning: "); break; + case GL2PS_ERROR: fprintf(stderr, "GL2PS error: "); break; } va_start(args, fmt); vfprintf(stderr, fmt, args); @@ -281,7 +281,7 @@ static void *gl2psMalloc(size_t size) if(!size) return NULL; ptr = malloc(size); - if(!ptr){ + if(!ptr) { gl2psMsg(GL2PS_ERROR, "Couldn't allocate requested memory"); return NULL; } @@ -293,7 +293,7 @@ static void *gl2psRealloc(void *ptr, size_t size) void *orig = ptr; if(!size) return NULL; ptr = realloc(orig, size); - if(!ptr){ + if(!ptr) { gl2psMsg(GL2PS_ERROR, "Couldn't reallocate requested memory"); free(orig); return NULL; @@ -311,19 +311,19 @@ static int gl2psWriteBigEndian(unsigned long data, int bytes) { int i; int size = sizeof(unsigned long); - for(i = 1; i <= bytes; ++i){ + for(i = 1; i <= bytes; ++i) { fputc(0xff & (data >> (size - i) * 8), gl2ps->stream); } return bytes; } -/* zlib compression helper routines */ + /* zlib compression helper routines */ #if defined(GL2PS_HAVE_ZLIB) static void gl2psSetupCompress(void) { - gl2ps->compress = (GL2PScompress*)gl2psMalloc(sizeof(GL2PScompress)); + gl2ps->compress = (GL2PScompress *)gl2psMalloc(sizeof(GL2PScompress)); gl2ps->compress->src = NULL; gl2ps->compress->start = NULL; gl2ps->compress->dest = NULL; @@ -333,8 +333,7 @@ static void gl2psSetupCompress(void) static void gl2psFreeCompress(void) { - if(!gl2ps->compress) - return; + if(!gl2ps->compress) return; gl2psFree(gl2ps->compress->start); gl2psFree(gl2ps->compress->dest); gl2ps->compress->src = NULL; @@ -348,33 +347,30 @@ static int gl2psAllocCompress(unsigned int srcsize) { gl2psFreeCompress(); - if(!gl2ps->compress || !srcsize) - return GL2PS_ERROR; + if(!gl2ps->compress || !srcsize) return GL2PS_ERROR; gl2ps->compress->srcLen = srcsize; gl2ps->compress->destLen = (int)ceil(1.001 * gl2ps->compress->srcLen + 12); - gl2ps->compress->src = (Bytef*)gl2psMalloc(gl2ps->compress->srcLen); + gl2ps->compress->src = (Bytef *)gl2psMalloc(gl2ps->compress->srcLen); gl2ps->compress->start = gl2ps->compress->src; - gl2ps->compress->dest = (Bytef*)gl2psMalloc(gl2ps->compress->destLen); + gl2ps->compress->dest = (Bytef *)gl2psMalloc(gl2ps->compress->destLen); return GL2PS_SUCCESS; } static void *gl2psReallocCompress(unsigned int srcsize) { - if(!gl2ps->compress || !srcsize) - return NULL; + if(!gl2ps->compress || !srcsize) return NULL; - if(srcsize < gl2ps->compress->srcLen) - return gl2ps->compress->start; + if(srcsize < gl2ps->compress->srcLen) return gl2ps->compress->start; gl2ps->compress->srcLen = srcsize; gl2ps->compress->destLen = (int)ceil(1.001 * gl2ps->compress->srcLen + 12); - gl2ps->compress->src = (Bytef*)gl2psRealloc(gl2ps->compress->src, - gl2ps->compress->srcLen); + gl2ps->compress->src = + (Bytef *)gl2psRealloc(gl2ps->compress->src, gl2ps->compress->srcLen); gl2ps->compress->start = gl2ps->compress->src; - gl2ps->compress->dest = (Bytef*)gl2psRealloc(gl2ps->compress->dest, - gl2ps->compress->destLen); + gl2ps->compress->dest = + (Bytef *)gl2psRealloc(gl2ps->compress->dest, gl2ps->compress->destLen); return gl2ps->compress->start; } @@ -383,8 +379,8 @@ static int gl2psWriteBigEndianCompress(unsigned long data, int bytes) { int i; int size = sizeof(unsigned long); - for(i = 1; i <= bytes; ++i){ - *gl2ps->compress->src = (Bytef)(0xff & (data >> (size-i) * 8)); + for(i = 1; i <= bytes; ++i) { + *gl2ps->compress->src = (Bytef)(0xff & (data >> (size - i) * 8)); ++gl2ps->compress->src; } return bytes; @@ -400,7 +396,7 @@ static int gl2psDeflate(void) #endif -static int gl2psPrintf(const char* fmt, ...) +static int gl2psPrintf(const char *fmt, ...) { int ret; va_list args; @@ -415,7 +411,7 @@ static int gl2psPrintf(const char* fmt, ...) keep trying larger sizes until it does. */ int bufsize = sizeof(buf); #endif - if(gl2ps->options & GL2PS_COMPRESS){ + if(gl2ps->options & GL2PS_COMPRESS) { va_start(args, fmt); #if defined(GL2PS_HAVE_NO_VSNPRINTF) ret = vsprintf(buf, fmt, args); @@ -424,7 +420,7 @@ static int gl2psPrintf(const char* fmt, ...) #endif va_end(args); #if !defined(GL2PS_HAVE_NO_VSNPRINTF) - while(ret >= (bufsize - 1) || ret < 0){ + while(ret >= (bufsize - 1) || ret < 0) { /* Too big. Allocate a new buffer. */ bufsize *= 2; if(freebuf == GL_TRUE) gl2psFree(bufptr); @@ -436,12 +432,12 @@ static int gl2psPrintf(const char* fmt, ...) } #endif oldsize = gl2ps->compress->srcLen; - gl2ps->compress->start = (Bytef*)gl2psReallocCompress(oldsize + ret); + gl2ps->compress->start = (Bytef *)gl2psReallocCompress(oldsize + ret); memcpy(gl2ps->compress->start + oldsize, bufptr, ret); if(freebuf == GL_TRUE) gl2psFree(bufptr); ret = 0; } - else{ + else { #endif va_start(args, fmt); ret = vfprintf(gl2ps->stream, fmt, args); @@ -458,11 +454,11 @@ static void gl2psPrintGzipHeader(void) char tmp[10] = {'\x1f', '\x8b', /* magic numbers: 0x1f, 0x8b */ 8, /* compression method: Z_DEFLATED */ 0, /* flags */ - 0, 0, 0, 0, /* time */ + 0, 0, 0, 0, /* time */ 2, /* extra flags: max compression */ '\x03'}; /* OS code: 0x03 (Unix) */ - if(gl2ps->options & GL2PS_COMPRESS){ + if(gl2ps->options & GL2PS_COMPRESS) { gl2psSetupCompress(); /* add the gzip file header */ fwrite(tmp, 10, 1, gl2ps->stream); @@ -477,27 +473,27 @@ static void gl2psPrintGzipFooter(void) uLong crc, len; char tmp[8]; - if(gl2ps->options & GL2PS_COMPRESS){ - if(Z_OK != gl2psDeflate()){ + if(gl2ps->options & GL2PS_COMPRESS) { + if(Z_OK != gl2psDeflate()) { gl2psMsg(GL2PS_ERROR, "Zlib deflate error"); } - else{ + else { /* determine the length of the header in the zlib stream */ n = 2; /* CMF+FLG */ - if(gl2ps->compress->dest[1] & (1<<5)){ + if(gl2ps->compress->dest[1] & (1 << 5)) { n += 4; /* DICTID */ } /* write the data, without the zlib header and footer */ - fwrite(gl2ps->compress->dest+n, gl2ps->compress->destLen-(n+4), - 1, gl2ps->stream); + fwrite(gl2ps->compress->dest + n, gl2ps->compress->destLen - (n + 4), 1, + gl2ps->stream); /* add the gzip file footer */ crc = crc32(0L, gl2ps->compress->start, gl2ps->compress->srcLen); - for(n = 0; n < 4; ++n){ + for(n = 0; n < 4; ++n) { tmp[n] = (char)(crc & 0xff); crc >>= 8; } len = gl2ps->compress->srcLen; - for(n = 4; n < 8; ++n){ + for(n = 4; n < 8; ++n) { tmp[n] = (char)(len & 0xff); len >>= 8; } @@ -514,20 +510,19 @@ static void gl2psPrintGzipFooter(void) static void gl2psListRealloc(GL2PSlist *list, GLint n) { - if(!list){ + if(!list) { gl2psMsg(GL2PS_ERROR, "Cannot reallocate NULL list"); return; } if(n <= 0) return; - if(!list->array){ + if(!list->array) { list->nmax = n; - list->array = (char*)gl2psMalloc(list->nmax * list->size); + list->array = (char *)gl2psMalloc(list->nmax * list->size); } - else{ - if(n > list->nmax){ + else { + if(n > list->nmax) { list->nmax = ((n - 1) / list->incr + 1) * list->incr; - list->array = (char*)gl2psRealloc(list->array, - list->nmax * list->size); + list->array = (char *)gl2psRealloc(list->array, list->nmax * list->size); } } } @@ -538,7 +533,7 @@ static GL2PSlist *gl2psListCreate(GLint n, GLint incr, GLint size) if(n < 0) n = 0; if(incr <= 0) incr = 1; - list = (GL2PSlist*)gl2psMalloc(sizeof(GL2PSlist)); + list = (GL2PSlist *)gl2psMalloc(sizeof(GL2PSlist)); list->nmax = 0; list->incr = incr; list->size = size; @@ -563,7 +558,7 @@ static void gl2psListDelete(GL2PSlist *list) static void gl2psListAdd(GL2PSlist *list, void *data) { - if(!list){ + if(!list) { gl2psMsg(GL2PS_ERROR, "Cannot add into unallocated list"); return; } @@ -574,18 +569,17 @@ static void gl2psListAdd(GL2PSlist *list, void *data) static int gl2psListNbr(GL2PSlist *list) { - if(!list) - return 0; + if(!list) return 0; return list->n; } static void *gl2psListPointer(GL2PSlist *list, GLint idx) { - if(!list){ + if(!list) { gl2psMsg(GL2PS_ERROR, "Cannot point into unallocated list"); return NULL; } - if((idx < 0) || (idx >= list->n)){ + if((idx < 0) || (idx >= list->n)) { gl2psMsg(GL2PS_ERROR, "Wrong list index in gl2psListPointer"); return NULL; } @@ -595,8 +589,7 @@ static void *gl2psListPointer(GL2PSlist *list, GLint idx) static void gl2psListSort(GL2PSlist *list, int (*fcmp)(const void *a, const void *b)) { - if(!list) - return; + if(!list) return; qsort(list->array, list->n, list->size, fcmp); } @@ -604,7 +597,7 @@ static void gl2psListAction(GL2PSlist *list, void (*action)(void *data)) { GLint i; - for(i = 0; i < gl2psListNbr(list); i++){ + for(i = 0; i < gl2psListNbr(list); i++) { (*action)(gl2psListPointer(list, i)); } } @@ -613,8 +606,8 @@ static void gl2psListActionInverse(GL2PSlist *list, void (*action)(void *data)) { GLint i; - for(i = gl2psListNbr(list); i > 0; i--){ - (*action)(gl2psListPointer(list, i-1)); + for(i = gl2psListNbr(list); i > 0; i--) { + (*action)(gl2psListPointer(list, i - 1)); } } @@ -627,15 +620,17 @@ static void gl2psListRead(GL2PSlist *list, int index, void *data) memcpy(data, &list->array[index * list->size], list->size); } -static void gl2psEncodeBase64Block(unsigned char in[3], unsigned char out[4], int len) +static void gl2psEncodeBase64Block(unsigned char in[3], unsigned char out[4], + int len) { static const char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - out[0] = cb64[ in[0] >> 2 ]; - out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ]; - out[2] = (len > 1) ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '='; - out[3] = (len > 2) ? cb64[ in[2] & 0x3f ] : '='; + out[0] = cb64[in[0] >> 2]; + out[1] = cb64[((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4)]; + out[2] = + (len > 1) ? cb64[((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)] : '='; + out[3] = (len > 2) ? cb64[in[2] & 0x3f] : '='; } static void gl2psListEncodeBase64(GL2PSlist *list) @@ -644,7 +639,7 @@ static void gl2psListEncodeBase64(GL2PSlist *list) int i, n, index, len; n = list->n * list->size; - buffer = (unsigned char*)gl2psMalloc(n * sizeof(unsigned char)); + buffer = (unsigned char *)gl2psMalloc(n * sizeof(unsigned char)); memcpy(buffer, list->array, n * sizeof(unsigned char)); gl2psListReset(list); @@ -652,19 +647,18 @@ static void gl2psListEncodeBase64(GL2PSlist *list) while(index < n) { len = 0; for(i = 0; i < 3; i++) { - if(index < n){ + if(index < n) { in[i] = buffer[index]; len++; } - else{ + else { in[i] = 0; } index++; } if(len) { gl2psEncodeBase64Block(in, out, len); - for(i = 0; i < 4; i++) - gl2psListAdd(list, &out[i]); + for(i = 0; i < 4; i++) gl2psListAdd(list, &out[i]); } } gl2psFree(buffer); @@ -676,8 +670,7 @@ static void gl2psListEncodeBase64(GL2PSlist *list) static GLboolean gl2psSameColor(GL2PSrgba rgba1, GL2PSrgba rgba2) { - if(!GL2PS_ZERO(rgba1[0] - rgba2[0]) || - !GL2PS_ZERO(rgba1[1] - rgba2[1]) || + if(!GL2PS_ZERO(rgba1[0] - rgba2[0]) || !GL2PS_ZERO(rgba1[1] - rgba2[1]) || !GL2PS_ZERO(rgba1[2] - rgba2[2])) return GL_FALSE; return GL_TRUE; @@ -687,8 +680,8 @@ static GLboolean gl2psVertsSameColor(const GL2PSprimitive *prim) { int i; - for(i = 1; i < prim->numverts; i++){ - if(!gl2psSameColor(prim->verts[0].rgba, prim->verts[i].rgba)){ + for(i = 1; i < prim->numverts; i++) { + if(!gl2psSameColor(prim->verts[0].rgba, prim->verts[i].rgba)) { return GL_FALSE; } } @@ -702,7 +695,7 @@ static GLboolean gl2psSameColorThreshold(int n, GL2PSrgba rgba[], if(n < 2) return GL_TRUE; - for(i = 1; i < n; i++){ + for(i = 1; i < n; i++) { if(fabs(rgba[0][0] - rgba[i][0]) > threshold[0] || fabs(rgba[0][1] - rgba[i][1]) > threshold[1] || fabs(rgba[0][2] - rgba[i][2]) > threshold[2]) @@ -715,33 +708,31 @@ static GLboolean gl2psSameColorThreshold(int n, GL2PSrgba rgba[], static void gl2psSetLastColor(GL2PSrgba rgba) { int i; - for(i = 0; i < 3; ++i){ + for(i = 0; i < 3; ++i) { gl2ps->lastrgba[i] = rgba[i]; } } -static GLfloat gl2psGetRGB(GL2PSimage *im, GLuint x, GLuint y, - GLfloat *red, GLfloat *green, GLfloat *blue) +static GLfloat gl2psGetRGB(GL2PSimage *im, GLuint x, GLuint y, GLfloat *red, + GLfloat *green, GLfloat *blue) { - GLsizei width = im->width; GLsizei height = im->height; GLfloat *pixels = im->pixels; GLfloat *pimag; /* OpenGL image is from down to up, PS image is up to down */ - switch(im->format){ - case GL_RGBA: - pimag = pixels + 4 * (width * (height - 1 - y) + x); - break; + switch(im->format) { + case GL_RGBA: pimag = pixels + 4 * (width * (height - 1 - y) + x); break; case GL_RGB: - default: - pimag = pixels + 3 * (width * (height - 1 - y) + x); - break; + default: pimag = pixels + 3 * (width * (height - 1 - y) + x); break; } - *red = *pimag; pimag++; - *green = *pimag; pimag++; - *blue = *pimag; pimag++; + *red = *pimag; + pimag++; + *green = *pimag; + pimag++; + *blue = *pimag; + pimag++; return (im->format == GL_RGBA) ? *pimag : 1.0F; } @@ -751,7 +742,7 @@ static GLfloat gl2psGetRGB(GL2PSimage *im, GLuint x, GLuint y, static GL2PSimage *gl2psCopyPixmap(GL2PSimage *im) { int size; - GL2PSimage *image = (GL2PSimage*)gl2psMalloc(sizeof(GL2PSimage)); + GL2PSimage *image = (GL2PSimage *)gl2psMalloc(sizeof(GL2PSimage)); image->width = im->width; image->height = im->height; @@ -760,17 +751,15 @@ static GL2PSimage *gl2psCopyPixmap(GL2PSimage *im) image->zoom_x = im->zoom_x; image->zoom_y = im->zoom_y; - switch(image->format){ + switch(image->format) { case GL_RGBA: size = image->height * image->width * 4 * sizeof(GLfloat); break; case GL_RGB: - default: - size = image->height * image->width * 3 * sizeof(GLfloat); - break; + default: size = image->height * image->width * 3 * sizeof(GLfloat); break; } - image->pixels = (GLfloat*)gl2psMalloc(size); + image->pixels = (GLfloat *)gl2psMalloc(size); memcpy(image->pixels, im->pixels, size); return image; @@ -778,8 +767,7 @@ static GL2PSimage *gl2psCopyPixmap(GL2PSimage *im) static void gl2psFreePixmap(GL2PSimage *im) { - if(!im) - return; + if(!im) return; gl2psFree(im->pixels); gl2psFree(im); } @@ -787,20 +775,20 @@ static void gl2psFreePixmap(GL2PSimage *im) #if defined(GL2PS_HAVE_LIBPNG) #if !defined(png_jmpbuf) -# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) #endif -static void gl2psUserWritePNG(png_structp png_ptr, png_bytep data, png_size_t length) +static void gl2psUserWritePNG(png_structp png_ptr, png_bytep data, + png_size_t length) { unsigned int i; - GL2PSlist *png = (GL2PSlist*)png_get_io_ptr(png_ptr); - for(i = 0; i < length; i++) - gl2psListAdd(png, &data[i]); + GL2PSlist *png = (GL2PSlist *)png_get_io_ptr(png_ptr); + for(i = 0; i < length; i++) gl2psListAdd(png, &data[i]); } static void gl2psUserFlushPNG(png_structp png_ptr) { - (void) png_ptr; /* not used */ + (void)png_ptr; /* not used */ } static void gl2psConvertPixmapToPNG(GL2PSimage *pixmap, GL2PSlist *png) @@ -811,10 +799,11 @@ static void gl2psConvertPixmapToPNG(GL2PSimage *pixmap, GL2PSlist *png) GLfloat dr, dg, db; int row, col; - if(!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) + if(!(png_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) return; - if(!(info_ptr = png_create_info_struct(png_ptr))){ + if(!(info_ptr = png_create_info_struct(png_ptr))) { png_destroy_write_struct(&png_ptr, NULL); return; } @@ -827,17 +816,18 @@ static void gl2psConvertPixmapToPNG(GL2PSimage *pixmap, GL2PSlist *png) png_set_write_fn(png_ptr, (void *)png, gl2psUserWritePNG, gl2psUserFlushPNG); png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION); png_set_IHDR(png_ptr, info_ptr, pixmap->width, pixmap->height, 8, - PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, - PNG_FILTER_TYPE_BASE); + PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); png_write_info(png_ptr, info_ptr); - row_data = (unsigned char*)gl2psMalloc(3 * pixmap->width * sizeof(unsigned char)); - for(row = 0; row < pixmap->height; row++){ - for(col = 0; col < pixmap->width; col++){ + row_data = + (unsigned char *)gl2psMalloc(3 * pixmap->width * sizeof(unsigned char)); + for(row = 0; row < pixmap->height; row++) { + for(col = 0; col < pixmap->width; col++) { gl2psGetRGB(pixmap, col, row, &dr, &dg, &db); - row_data[3*col] = (unsigned char)(255. * dr); - row_data[3*col+1] = (unsigned char)(255. * dg); - row_data[3*col+2] = (unsigned char)(255. * db); + row_data[3 * col] = (unsigned char)(255. * dr); + row_data[3 * col + 1] = (unsigned char)(255. * dg); + row_data[3 * col + 2] = (unsigned char)(255. * db); } png_write_row(png_ptr, (png_bytep)row_data); } @@ -863,7 +853,7 @@ static GLint gl2psAddText(GLint type, const char *str, const char *fontname, if(gl2ps->options & GL2PS_NO_TEXT) return GL2PS_SUCCESS; - if (gl2ps->forcerasterpos) { + if(gl2ps->forcerasterpos) { pos[0] = gl2ps->rasterpos.xyz[0]; pos[1] = gl2ps->rasterpos.xyz[1]; pos[2] = gl2ps->rasterpos.xyz[2]; @@ -875,11 +865,11 @@ static GLint gl2psAddText(GLint type, const char *str, const char *fontname, glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); } - prim = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); prim->type = (GLshort)type; prim->boundary = 0; prim->numverts = 1; - prim->verts = (GL2PSvertex*)gl2psMalloc(sizeof(GL2PSvertex)); + prim->verts = (GL2PSvertex *)gl2psMalloc(sizeof(GL2PSvertex)); prim->verts[0].xyz[0] = pos[0]; prim->verts[0].xyz[1] = pos[1]; prim->verts[0].xyz[2] = pos[2]; @@ -893,11 +883,11 @@ static GLint gl2psAddText(GLint type, const char *str, const char *fontname, prim->linecap = 0; prim->linejoin = 0; - if (color) { + if(color) { memcpy(prim->verts[0].rgba, color, 4 * sizeof(float)); } else { - if (gl2ps->forcerasterpos) { + if(gl2ps->forcerasterpos) { prim->verts[0].rgba[0] = gl2ps->rasterpos.rgba[0]; prim->verts[0].rgba[1] = gl2ps->rasterpos.rgba[1]; prim->verts[0].rgba[2] = gl2ps->rasterpos.rgba[2]; @@ -907,10 +897,11 @@ static GLint gl2psAddText(GLint type, const char *str, const char *fontname, glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba); } } - prim->data.text = (GL2PSstring*)gl2psMalloc(sizeof(GL2PSstring)); - prim->data.text->str = (char*)gl2psMalloc((strlen(str)+1)*sizeof(char)); + prim->data.text = (GL2PSstring *)gl2psMalloc(sizeof(GL2PSstring)); + prim->data.text->str = (char *)gl2psMalloc((strlen(str) + 1) * sizeof(char)); strcpy(prim->data.text->str, str); - prim->data.text->fontname = (char*)gl2psMalloc((strlen(fontname)+1)*sizeof(char)); + prim->data.text->fontname = + (char *)gl2psMalloc((strlen(fontname) + 1) * sizeof(char)); strcpy(prim->data.text->fontname, fontname); prim->data.text->fontsize = fontsize; prim->data.text->alignment = alignment; @@ -919,7 +910,7 @@ static GLint gl2psAddText(GLint type, const char *str, const char *fontname, gl2ps->forcerasterpos = GL_FALSE; /* If no OpenGL context, just add directly to primitives */ - if (gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) { + if(gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) { gl2psListAdd(gl2ps->primitives, &prim); } else { @@ -932,10 +923,11 @@ static GLint gl2psAddText(GLint type, const char *str, const char *fontname, static GL2PSstring *gl2psCopyText(GL2PSstring *t) { - GL2PSstring *text = (GL2PSstring*)gl2psMalloc(sizeof(GL2PSstring)); - text->str = (char*)gl2psMalloc((strlen(t->str)+1)*sizeof(char)); + GL2PSstring *text = (GL2PSstring *)gl2psMalloc(sizeof(GL2PSstring)); + text->str = (char *)gl2psMalloc((strlen(t->str) + 1) * sizeof(char)); strcpy(text->str, t->str); - text->fontname = (char*)gl2psMalloc((strlen(t->fontname)+1)*sizeof(char)); + text->fontname = + (char *)gl2psMalloc((strlen(t->fontname) + 1) * sizeof(char)); strcpy(text->fontname, t->fontname); text->fontsize = t->fontsize; text->alignment = t->alignment; @@ -946,8 +938,7 @@ static GL2PSstring *gl2psCopyText(GL2PSstring *t) static void gl2psFreeText(GL2PSstring *text) { - if(!text) - return; + if(!text) return; gl2psFree(text->str); gl2psFree(text->fontname); gl2psFree(text); @@ -960,8 +951,8 @@ static GLboolean gl2psSupportedBlendMode(GLenum sfactor, GLenum dfactor) /* returns TRUE if gl2ps supports the argument combination: only two blending modes have been implemented so far */ - if( (sfactor == GL_SRC_ALPHA && dfactor == GL_ONE_MINUS_SRC_ALPHA) || - (sfactor == GL_ONE && dfactor == GL_ZERO) ) + if((sfactor == GL_SRC_ALPHA && dfactor == GL_ONE_MINUS_SRC_ALPHA) || + (sfactor == GL_ONE && dfactor == GL_ZERO)) return GL_TRUE; return GL_FALSE; } @@ -973,20 +964,16 @@ static void gl2psAdaptVertexForBlending(GL2PSvertex *v) alpha value is changed to 1.0 if source blending GL_ONE is active. This might be extended in the future */ - if(!v || !gl2ps) - return; + if(!v || !gl2ps) return; - if(gl2ps->options & GL2PS_NO_BLENDING || !gl2ps->blending){ + if(gl2ps->options & GL2PS_NO_BLENDING || !gl2ps->blending) { v->rgba[3] = 1.0F; return; } - switch(gl2ps->blendfunc[0]){ - case GL_ONE: - v->rgba[3] = 1.0F; - break; - default: - break; + switch(gl2ps->blendfunc[0]) { + case GL_ONE: v->rgba[3] = 1.0F; break; + default: break; } } @@ -1012,10 +999,10 @@ static void gl2psAssignTriangleProperties(GL2PStriangle *t) */ if(!GL2PS_ZERO(t->vertex[0].rgba[3] - t->vertex[1].rgba[3]) || - !GL2PS_ZERO(t->vertex[1].rgba[3] - t->vertex[2].rgba[3])){ + !GL2PS_ZERO(t->vertex[1].rgba[3] - t->vertex[2].rgba[3])) { t->prop |= T_VAR_ALPHA; } - else{ + else { if(t->vertex[0].rgba[3] < 1) t->prop |= T_ALPHA_LESS_1; else @@ -1029,16 +1016,14 @@ static void gl2psFillTriangleFromPrimitive(GL2PStriangle *t, GL2PSprimitive *p, t->vertex[0] = p->verts[0]; t->vertex[1] = p->verts[1]; t->vertex[2] = p->verts[2]; - if(GL_TRUE == assignprops) - gl2psAssignTriangleProperties(t); + if(GL_TRUE == assignprops) gl2psAssignTriangleProperties(t); } static void gl2psInitTriangle(GL2PStriangle *t) { int i; - GL2PSvertex vertex = { {-1.0F, -1.0F, -1.0F}, {-1.0F, -1.0F, -1.0F, -1.0F} }; - for(i = 0; i < 3; i++) - t->vertex[i] = vertex; + GL2PSvertex vertex = {{-1.0F, -1.0F, -1.0F}, {-1.0F, -1.0F, -1.0F, -1.0F}}; + for(i = 0; i < 3; i++) t->vertex[i] = vertex; t->prop = T_UNDEFINED; } @@ -1054,12 +1039,12 @@ static GL2PSprimitive *gl2psCopyPrimitive(GL2PSprimitive *p) { GL2PSprimitive *prim; - if(!p){ + if(!p) { gl2psMsg(GL2PS_ERROR, "Trying to copy an empty primitive"); return NULL; } - prim = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); prim->type = p->type; prim->numverts = p->numverts; @@ -1073,19 +1058,14 @@ static GL2PSprimitive *gl2psCopyPrimitive(GL2PSprimitive *p) prim->width = p->width; prim->linecap = p->linecap; prim->linejoin = p->linejoin; - prim->verts = (GL2PSvertex*)gl2psMalloc(p->numverts*sizeof(GL2PSvertex)); + prim->verts = (GL2PSvertex *)gl2psMalloc(p->numverts * sizeof(GL2PSvertex)); memcpy(prim->verts, p->verts, p->numverts * sizeof(GL2PSvertex)); - switch(prim->type){ - case GL2PS_PIXMAP : - prim->data.image = gl2psCopyPixmap(p->data.image); - break; - case GL2PS_TEXT : - case GL2PS_SPECIAL : - prim->data.text = gl2psCopyText(p->data.text); - break; - default: - break; + switch(prim->type) { + case GL2PS_PIXMAP: prim->data.image = gl2psCopyPixmap(p->data.image); break; + case GL2PS_TEXT: + case GL2PS_SPECIAL: prim->data.text = gl2psCopyText(p->data.text); break; + default: break; } return prim; @@ -1093,8 +1073,7 @@ static GL2PSprimitive *gl2psCopyPrimitive(GL2PSprimitive *p) static GLboolean gl2psSamePosition(GL2PSxyz p1, GL2PSxyz p2) { - if(!GL2PS_ZERO(p1[0] - p2[0]) || - !GL2PS_ZERO(p1[1] - p2[1]) || + if(!GL2PS_ZERO(p1[0] - p2[0]) || !GL2PS_ZERO(p1[1] - p2[1]) || !GL2PS_ZERO(p1[2] - p2[2])) return GL_FALSE; return GL_TRUE; @@ -1108,27 +1087,25 @@ static GLboolean gl2psSamePosition(GL2PSxyz p1, GL2PSxyz p2) static GLfloat gl2psComparePointPlane(GL2PSxyz point, GL2PSplane plane) { - return (plane[0] * point[0] + - plane[1] * point[1] + - plane[2] * point[2] + + return (plane[0] * point[0] + plane[1] * point[1] + plane[2] * point[2] + plane[3]); } static GLfloat gl2psPsca(GLfloat *a, GLfloat *b) { - return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]); + return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]); } static void gl2psPvec(GLfloat *a, GLfloat *b, GLfloat *c) { - c[0] = a[1]*b[2] - a[2]*b[1]; - c[1] = a[2]*b[0] - a[0]*b[2]; - c[2] = a[0]*b[1] - a[1]*b[0]; + c[0] = a[1] * b[2] - a[2] * b[1]; + c[1] = a[2] * b[0] - a[0] * b[2]; + c[2] = a[0] * b[1] - a[1] * b[0]; } static GLfloat gl2psNorm(GLfloat *a) { - return (GLfloat)sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); + return (GLfloat)sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); } static void gl2psGetNormal(GLfloat *a, GLfloat *b, GLfloat *c) @@ -1136,12 +1113,12 @@ static void gl2psGetNormal(GLfloat *a, GLfloat *b, GLfloat *c) GLfloat norm; gl2psPvec(a, b, c); - if(!GL2PS_ZERO(norm = gl2psNorm(c))){ + if(!GL2PS_ZERO(norm = gl2psNorm(c))) { c[0] = c[0] / norm; c[1] = c[1] / norm; c[2] = c[2] / norm; } - else{ + else { /* The plane is still wrong despite our tests in gl2psGetPlane. Let's return a dummy value for now (this is a hack: we should do more intelligent tests in GetPlane) */ @@ -1154,9 +1131,9 @@ static void gl2psGetPlane(GL2PSprimitive *prim, GL2PSplane plane) { GL2PSxyz v = {0.0F, 0.0F, 0.0F}, w = {0.0F, 0.0F, 0.0F}; - switch(prim->type){ - case GL2PS_TRIANGLE : - case GL2PS_QUADRANGLE : + switch(prim->type) { + case GL2PS_TRIANGLE: + case GL2PS_QUADRANGLE: v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0]; v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1]; v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2]; @@ -1164,49 +1141,50 @@ static void gl2psGetPlane(GL2PSprimitive *prim, GL2PSplane plane) w[1] = prim->verts[2].xyz[1] - prim->verts[0].xyz[1]; w[2] = prim->verts[2].xyz[2] - prim->verts[0].xyz[2]; if((GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])) || - (GL2PS_ZERO(w[0]) && GL2PS_ZERO(w[1]) && GL2PS_ZERO(w[2]))){ + (GL2PS_ZERO(w[0]) && GL2PS_ZERO(w[1]) && GL2PS_ZERO(w[2]))) { plane[0] = plane[1] = 0.0F; plane[2] = 1.0F; plane[3] = -prim->verts[0].xyz[2]; } - else{ + else { gl2psGetNormal(v, w, plane); - plane[3] = - - plane[0] * prim->verts[0].xyz[0] - - plane[1] * prim->verts[0].xyz[1] - - plane[2] * prim->verts[0].xyz[2]; + plane[3] = -plane[0] * prim->verts[0].xyz[0] - + plane[1] * prim->verts[0].xyz[1] - + plane[2] * prim->verts[0].xyz[2]; } break; - case GL2PS_LINE : + case GL2PS_LINE: v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0]; v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1]; v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2]; - if(GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])){ + if(GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])) { plane[0] = plane[1] = 0.0F; plane[2] = 1.0F; plane[3] = -prim->verts[0].xyz[2]; } - else{ - if(GL2PS_ZERO(v[0])) w[0] = 1.0F; - else if(GL2PS_ZERO(v[1])) w[1] = 1.0F; - else w[2] = 1.0F; + else { + if(GL2PS_ZERO(v[0])) + w[0] = 1.0F; + else if(GL2PS_ZERO(v[1])) + w[1] = 1.0F; + else + w[2] = 1.0F; gl2psGetNormal(v, w, plane); - plane[3] = - - plane[0] * prim->verts[0].xyz[0] - - plane[1] * prim->verts[0].xyz[1] - - plane[2] * prim->verts[0].xyz[2]; + plane[3] = -plane[0] * prim->verts[0].xyz[0] - + plane[1] * prim->verts[0].xyz[1] - + plane[2] * prim->verts[0].xyz[2]; } break; - case GL2PS_POINT : - case GL2PS_PIXMAP : - case GL2PS_TEXT : - case GL2PS_SPECIAL : + case GL2PS_POINT: + case GL2PS_PIXMAP: + case GL2PS_TEXT: + case GL2PS_SPECIAL: case GL2PS_IMAGEMAP: plane[0] = plane[1] = 0.0F; plane[2] = 1.0F; plane[3] = -prim->verts[0].xyz[2]; break; - default : + default: gl2psMsg(GL2PS_ERROR, "Unknown primitive type in BSP tree"); plane[0] = plane[1] = plane[3] = 0.0F; plane[2] = 1.0F; @@ -1245,20 +1223,20 @@ static void gl2psCreateSplitPrimitive(GL2PSprimitive *parent, GL2PSplane plane, { GLshort i; - if(parent->type == GL2PS_IMAGEMAP){ + if(parent->type == GL2PS_IMAGEMAP) { child->type = GL2PS_IMAGEMAP; child->data.image = parent->data.image; } - else{ - if(numverts > 4){ + else { + if(numverts > 4) { gl2psMsg(GL2PS_WARNING, "%d vertices in polygon", numverts); numverts = 4; } - switch(numverts){ - case 1 : child->type = GL2PS_POINT; break; - case 2 : child->type = GL2PS_LINE; break; - case 3 : child->type = GL2PS_TRIANGLE; break; - case 4 : child->type = GL2PS_QUADRANGLE; break; + switch(numverts) { + case 1: child->type = GL2PS_POINT; break; + case 2: child->type = GL2PS_LINE; break; + case 3: child->type = GL2PS_TRIANGLE; break; + case 4: child->type = GL2PS_QUADRANGLE; break; default: child->type = GL2PS_NO_TYPE; break; } } @@ -1274,15 +1252,15 @@ static void gl2psCreateSplitPrimitive(GL2PSprimitive *parent, GL2PSplane plane, child->linecap = parent->linecap; child->linejoin = parent->linejoin; child->numverts = numverts; - child->verts = (GL2PSvertex*)gl2psMalloc(numverts * sizeof(GL2PSvertex)); + child->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex)); - for(i = 0; i < numverts; i++){ - if(index1[i] < 0){ + for(i = 0; i < numverts; i++) { + if(index1[i] < 0) { child->verts[i] = parent->verts[index0[i]]; } - else{ - gl2psCutEdge(&parent->verts[index0[i]], &parent->verts[index1[i]], - plane, &child->verts[i]); + else { + gl2psCutEdge(&parent->verts[index0[i]], &parent->verts[index1[i]], plane, + &child->verts[i]); } } } @@ -1292,9 +1270,9 @@ static void gl2psAddIndex(GLshort *index0, GLshort *index1, GLshort *nb, { GLint k; - for(k = 0; k < *nb; k++){ - if((index0[k] == i && index1[k] == j) || - (index1[k] == i && index0[k] == j)) return; + for(k = 0; k < *nb; k++) { + if((index0[k] == i && index1[k] == j) || (index1[k] == i && index0[k] == j)) + return; } index0[*nb] = i; index1[*nb] = j; @@ -1312,25 +1290,29 @@ static GLint gl2psTestSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane) GLshort i, j; GLfloat d[5]; - for(i = 0; i < prim->numverts; i++){ + for(i = 0; i < prim->numverts; i++) { d[i] = gl2psComparePointPlane(prim->verts[i].xyz, plane); } - if(prim->numverts < 2){ + if(prim->numverts < 2) { return 0; } - else{ - for(i = 0; i < prim->numverts; i++){ + else { + for(i = 0; i < prim->numverts; i++) { j = gl2psGetIndex(i, prim->numverts); - if(d[j] > GL2PS_EPSILON){ - if(type == GL2PS_COINCIDENT) type = GL2PS_IN_BACK_OF; - else if(type != GL2PS_IN_BACK_OF) return 1; - if(d[i] < -GL2PS_EPSILON) return 1; + if(d[j] > GL2PS_EPSILON) { + if(type == GL2PS_COINCIDENT) + type = GL2PS_IN_BACK_OF; + else if(type != GL2PS_IN_BACK_OF) + return 1; + if(d[i] < -GL2PS_EPSILON) return 1; } - else if(d[j] < -GL2PS_EPSILON){ - if(type == GL2PS_COINCIDENT) type = GL2PS_IN_FRONT_OF; - else if(type != GL2PS_IN_FRONT_OF) return 1; - if(d[i] > GL2PS_EPSILON) return 1; + else if(d[j] < -GL2PS_EPSILON) { + if(type == GL2PS_COINCIDENT) + type = GL2PS_IN_FRONT_OF; + else if(type != GL2PS_IN_FRONT_OF) + return 1; + if(d[i] > GL2PS_EPSILON) return 1; } } } @@ -1346,40 +1328,47 @@ static GLint gl2psSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane, type = GL2PS_COINCIDENT; - for(i = 0; i < prim->numverts; i++){ + for(i = 0; i < prim->numverts; i++) { d[i] = gl2psComparePointPlane(prim->verts[i].xyz, plane); } - switch(prim->type){ - case GL2PS_POINT : - if(d[0] > GL2PS_EPSILON) type = GL2PS_IN_BACK_OF; - else if(d[0] < -GL2PS_EPSILON) type = GL2PS_IN_FRONT_OF; - else type = GL2PS_COINCIDENT; + switch(prim->type) { + case GL2PS_POINT: + if(d[0] > GL2PS_EPSILON) + type = GL2PS_IN_BACK_OF; + else if(d[0] < -GL2PS_EPSILON) + type = GL2PS_IN_FRONT_OF; + else + type = GL2PS_COINCIDENT; break; - default : - for(i = 0; i < prim->numverts; i++){ + default: + for(i = 0; i < prim->numverts; i++) { j = gl2psGetIndex(i, prim->numverts); - if(d[j] > GL2PS_EPSILON){ - if(type == GL2PS_COINCIDENT) type = GL2PS_IN_BACK_OF; - else if(type != GL2PS_IN_BACK_OF) type = GL2PS_SPANNING; - if(d[i] < -GL2PS_EPSILON){ + if(d[j] > GL2PS_EPSILON) { + if(type == GL2PS_COINCIDENT) + type = GL2PS_IN_BACK_OF; + else if(type != GL2PS_IN_BACK_OF) + type = GL2PS_SPANNING; + if(d[i] < -GL2PS_EPSILON) { gl2psAddIndex(in0, in1, &in, i, j); gl2psAddIndex(out0, out1, &out, i, j); type = GL2PS_SPANNING; } gl2psAddIndex(out0, out1, &out, j, -1); } - else if(d[j] < -GL2PS_EPSILON){ - if(type == GL2PS_COINCIDENT) type = GL2PS_IN_FRONT_OF; - else if(type != GL2PS_IN_FRONT_OF) type = GL2PS_SPANNING; - if(d[i] > GL2PS_EPSILON){ + else if(d[j] < -GL2PS_EPSILON) { + if(type == GL2PS_COINCIDENT) + type = GL2PS_IN_FRONT_OF; + else if(type != GL2PS_IN_FRONT_OF) + type = GL2PS_SPANNING; + if(d[i] > GL2PS_EPSILON) { gl2psAddIndex(in0, in1, &in, i, j); gl2psAddIndex(out0, out1, &out, i, j); type = GL2PS_SPANNING; } gl2psAddIndex(in0, in1, &in, j, -1); } - else{ + else { gl2psAddIndex(in0, in1, &in, j, -1); gl2psAddIndex(out0, out1, &out, j, -1); } @@ -1387,9 +1376,9 @@ static GLint gl2psSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane, break; } - if(type == GL2PS_SPANNING){ - *back = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); - *front = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + if(type == GL2PS_SPANNING) { + *back = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); + *front = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); gl2psCreateSplitPrimitive(prim, plane, *back, out, out0, out1); gl2psCreateSplitPrimitive(prim, plane, *front, in, in0, in1); } @@ -1397,11 +1386,11 @@ static GLint gl2psSplitPrimitive(GL2PSprimitive *prim, GL2PSplane plane, return type; } -static void gl2psDivideQuad(GL2PSprimitive *quad, - GL2PSprimitive **t1, GL2PSprimitive **t2) +static void gl2psDivideQuad(GL2PSprimitive *quad, GL2PSprimitive **t1, + GL2PSprimitive **t2) { - *t1 = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); - *t2 = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + *t1 = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); + *t2 = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); (*t1)->type = (*t2)->type = GL2PS_TRIANGLE; (*t1)->numverts = (*t2)->numverts = 3; (*t1)->culled = (*t2)->culled = quad->culled; @@ -1413,16 +1402,18 @@ static void gl2psDivideQuad(GL2PSprimitive *quad, (*t1)->width = (*t2)->width = quad->width; (*t1)->linecap = (*t2)->linecap = quad->linecap; (*t1)->linejoin = (*t2)->linejoin = quad->linejoin; - (*t1)->verts = (GL2PSvertex*)gl2psMalloc(3 * sizeof(GL2PSvertex)); - (*t2)->verts = (GL2PSvertex*)gl2psMalloc(3 * sizeof(GL2PSvertex)); + (*t1)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex)); + (*t2)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex)); (*t1)->verts[0] = quad->verts[0]; (*t1)->verts[1] = quad->verts[1]; (*t1)->verts[2] = quad->verts[2]; - (*t1)->boundary = ((quad->boundary & 1) ? 1 : 0) | ((quad->boundary & 2) ? 2 : 0); + (*t1)->boundary = + ((quad->boundary & 1) ? 1 : 0) | ((quad->boundary & 2) ? 2 : 0); (*t2)->verts[0] = quad->verts[0]; (*t2)->verts[1] = quad->verts[2]; (*t2)->verts[2] = quad->verts[3]; - (*t2)->boundary = ((quad->boundary & 4) ? 2 : 0) | ((quad->boundary & 8) ? 4 : 0); + (*t2)->boundary = + ((quad->boundary & 4) ? 2 : 0) | ((quad->boundary & 8) ? 4 : 0); } static int gl2psCompareDepth(const void *a, const void *b) @@ -1431,27 +1422,27 @@ static int gl2psCompareDepth(const void *a, const void *b) GLfloat dq = 0.0F, dw = 0.0F, diff; int i; - q = *(const GL2PSprimitive* const*)a; - w = *(const GL2PSprimitive* const*)b; + q = *(const GL2PSprimitive *const *)a; + w = *(const GL2PSprimitive *const *)b; - for(i = 0; i < q->numverts; i++){ + for(i = 0; i < q->numverts; i++) { dq += q->verts[i].xyz[2]; } dq /= (GLfloat)q->numverts; - for(i = 0; i < w->numverts; i++){ + for(i = 0; i < w->numverts; i++) { dw += w->verts[i].xyz[2]; } dw /= (GLfloat)w->numverts; diff = dq - dw; - if(diff > 0.){ + if(diff > 0.) { return -1; } - else if(diff < 0.){ + else if(diff < 0.) { return 1; } - else{ + else { return 0; } } @@ -1460,8 +1451,8 @@ static int gl2psTrianglesFirst(const void *a, const void *b) { const GL2PSprimitive *q, *w; - q = *(const GL2PSprimitive* const*)a; - w = *(const GL2PSprimitive* const*)b; + q = *(const GL2PSprimitive *const *)a; + w = *(const GL2PSprimitive *const *)b; return (q->type < w->type ? 1 : -1); } @@ -1472,40 +1463,41 @@ static GLint gl2psFindRoot(GL2PSlist *primitives, GL2PSprimitive **root) GL2PSplane plane; GLint maxp; - if(!gl2psListNbr(primitives)){ + if(!gl2psListNbr(primitives)) { gl2psMsg(GL2PS_ERROR, "Cannot fint root in empty primitive list"); return 0; } - *root = *(GL2PSprimitive**)gl2psListPointer(primitives, 0); + *root = *(GL2PSprimitive **)gl2psListPointer(primitives, 0); - if(gl2ps->options & GL2PS_BEST_ROOT){ + if(gl2ps->options & GL2PS_BEST_ROOT) { maxp = gl2psListNbr(primitives); - if(maxp > gl2ps->maxbestroot){ + if(maxp > gl2ps->maxbestroot) { maxp = gl2ps->maxbestroot; } - for(i = 0; i < maxp; i++){ - prim1 = *(GL2PSprimitive**)gl2psListPointer(primitives, i); + for(i = 0; i < maxp; i++) { + prim1 = *(GL2PSprimitive **)gl2psListPointer(primitives, i); gl2psGetPlane(prim1, plane); count = 0; - for(j = 0; j < gl2psListNbr(primitives); j++){ - if(j != i){ - prim2 = *(GL2PSprimitive**)gl2psListPointer(primitives, j); + for(j = 0; j < gl2psListNbr(primitives); j++) { + if(j != i) { + prim2 = *(GL2PSprimitive **)gl2psListPointer(primitives, j); count += gl2psTestSplitPrimitive(prim2, plane); } if(count > best) break; } - if(count < best){ + if(count < best) { best = count; idx = i; *root = prim1; if(!count) return idx; } } - /* if(index) gl2psMsg(GL2PS_INFO, "GL2PS_BEST_ROOT was worth it: %d", index); */ + /* if(index) gl2psMsg(GL2PS_INFO, "GL2PS_BEST_ROOT was worth it: %d", + * index); */ return idx; } - else{ + else { return 0; } } @@ -1513,7 +1505,7 @@ static GLint gl2psFindRoot(GL2PSlist *primitives, GL2PSprimitive **root) static void gl2psFreeImagemap(GL2PSimagemap *list) { GL2PSimagemap *next; - while(list != NULL){ + while(list != NULL) { next = list->next; gl2psFree(list->image->pixels); gl2psFree(list->image); @@ -1526,12 +1518,12 @@ static void gl2psFreePrimitive(void *data) { GL2PSprimitive *q; - q = *(GL2PSprimitive**)data; + q = *(GL2PSprimitive **)data; gl2psFree(q->verts); - if(q->type == GL2PS_TEXT || q->type == GL2PS_SPECIAL){ + if(q->type == GL2PS_TEXT || q->type == GL2PS_SPECIAL) { gl2psFreeText(q->data.text); } - else if(q->type == GL2PS_PIXMAP){ + else if(q->type == GL2PS_PIXMAP) { gl2psFreePixmap(q->data.image); } gl2psFree(q); @@ -1541,23 +1533,22 @@ static void gl2psAddPrimitiveInList(GL2PSprimitive *prim, GL2PSlist *list) { GL2PSprimitive *t1, *t2; - if(prim->type != GL2PS_QUADRANGLE){ + if(prim->type != GL2PS_QUADRANGLE) { gl2psListAdd(list, &prim); } - else{ + else { gl2psDivideQuad(prim, &t1, &t2); gl2psListAdd(list, &t1); gl2psListAdd(list, &t2); gl2psFreePrimitive(&prim); } - } static void gl2psFreeBspTree(GL2PSbsptree **tree) { - if(*tree){ + if(*tree) { if((*tree)->back) gl2psFreeBspTree(&(*tree)->back); - if((*tree)->primitives){ + if((*tree)->primitives) { gl2psListAction((*tree)->primitives, gl2psFreePrimitive); gl2psListDelete((*tree)->primitives); } @@ -1569,14 +1560,18 @@ static void gl2psFreeBspTree(GL2PSbsptree **tree) static GLboolean gl2psGreater(GLfloat f1, GLfloat f2) { - if(f1 > f2) return GL_TRUE; - else return GL_FALSE; + if(f1 > f2) + return GL_TRUE; + else + return GL_FALSE; } static GLboolean gl2psLess(GLfloat f1, GLfloat f2) { - if(f1 < f2) return GL_TRUE; - else return GL_FALSE; + if(f1 < f2) + return GL_TRUE; + else + return GL_FALSE; } static void gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives) @@ -1587,27 +1582,23 @@ static void gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives) tree->front = NULL; tree->back = NULL; - tree->primitives = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + tree->primitives = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); idx = gl2psFindRoot(primitives, &prim); gl2psGetPlane(prim, tree->plane); gl2psAddPrimitiveInList(prim, tree->primitives); - frontlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); - backlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + frontlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); + backlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); - for(i = 0; i < gl2psListNbr(primitives); i++){ - if(i != idx){ - prim = *(GL2PSprimitive**)gl2psListPointer(primitives,i); - switch(gl2psSplitPrimitive(prim, tree->plane, &frontprim, &backprim)){ + for(i = 0; i < gl2psListNbr(primitives); i++) { + if(i != idx) { + prim = *(GL2PSprimitive **)gl2psListPointer(primitives, i); + switch(gl2psSplitPrimitive(prim, tree->plane, &frontprim, &backprim)) { case GL2PS_COINCIDENT: gl2psAddPrimitiveInList(prim, tree->primitives); break; - case GL2PS_IN_BACK_OF: - gl2psAddPrimitiveInList(prim, backlist); - break; - case GL2PS_IN_FRONT_OF: - gl2psAddPrimitiveInList(prim, frontlist); - break; + case GL2PS_IN_BACK_OF: gl2psAddPrimitiveInList(prim, backlist); break; + case GL2PS_IN_FRONT_OF: gl2psAddPrimitiveInList(prim, frontlist); break; case GL2PS_SPANNING: gl2psAddPrimitiveInList(backprim, backlist); gl2psAddPrimitiveInList(frontprim, frontlist); @@ -1617,32 +1608,33 @@ static void gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives) } } - if(gl2psListNbr(tree->primitives)){ + if(gl2psListNbr(tree->primitives)) { gl2psListSort(tree->primitives, gl2psTrianglesFirst); } - if(gl2psListNbr(frontlist)){ + if(gl2psListNbr(frontlist)) { gl2psListSort(frontlist, gl2psTrianglesFirst); - tree->front = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree)); + tree->front = (GL2PSbsptree *)gl2psMalloc(sizeof(GL2PSbsptree)); gl2psBuildBspTree(tree->front, frontlist); } - else{ + else { gl2psListDelete(frontlist); } - if(gl2psListNbr(backlist)){ + if(gl2psListNbr(backlist)) { gl2psListSort(backlist, gl2psTrianglesFirst); - tree->back = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree)); + tree->back = (GL2PSbsptree *)gl2psMalloc(sizeof(GL2PSbsptree)); gl2psBuildBspTree(tree->back, backlist); } - else{ + else { gl2psListDelete(backlist); } gl2psListDelete(primitives); } -static void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon, +static void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, + GLfloat epsilon, GLboolean (*compare)(GLfloat f1, GLfloat f2), void (*action)(void *data), int inverse) { @@ -1652,27 +1644,27 @@ static void gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsil result = gl2psComparePointPlane(eye, tree->plane); - if(GL_TRUE == compare(result, epsilon)){ + if(GL_TRUE == compare(result, epsilon)) { gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action, inverse); - if(inverse){ + if(inverse) { gl2psListActionInverse(tree->primitives, action); } - else{ + else { gl2psListAction(tree->primitives, action); } gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action, inverse); } - else if(GL_TRUE == compare(-epsilon, result)){ + else if(GL_TRUE == compare(-epsilon, result)) { gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action, inverse); - if(inverse){ + if(inverse) { gl2psListActionInverse(tree->primitives, action); } - else{ + else { gl2psListAction(tree->primitives, action); } gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action, inverse); } - else{ + else { gl2psTraverseBspTree(tree->front, eye, epsilon, compare, action, inverse); gl2psTraverseBspTree(tree->back, eye, epsilon, compare, action, inverse); } @@ -1685,19 +1677,18 @@ static void gl2psRescaleAndOffset(void) GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ; int i, j; - if(!gl2psListNbr(gl2ps->primitives)) - return; + if(!gl2psListNbr(gl2ps->primitives)) return; /* get z-buffer range */ - prim = *(GL2PSprimitive**)gl2psListPointer(gl2ps->primitives, 0); + prim = *(GL2PSprimitive **)gl2psListPointer(gl2ps->primitives, 0); minZ = maxZ = prim->verts[0].xyz[2]; - for(i = 1; i < prim->numverts; i++){ + for(i = 1; i < prim->numverts; i++) { if(prim->verts[i].xyz[2] < minZ) minZ = prim->verts[i].xyz[2]; if(prim->verts[i].xyz[2] > maxZ) maxZ = prim->verts[i].xyz[2]; } - for(i = 1; i < gl2psListNbr(gl2ps->primitives); i++){ - prim = *(GL2PSprimitive**)gl2psListPointer(gl2ps->primitives, i); - for(j = 0; j < prim->numverts; j++){ + for(i = 1; i < gl2psListNbr(gl2ps->primitives); i++) { + prim = *(GL2PSprimitive **)gl2psListPointer(gl2ps->primitives, i); + for(j = 0; j < prim->numverts; j++) { if(prim->verts[j].xyz[2] < minZ) minZ = prim->verts[j].xyz[2]; if(prim->verts[j].xyz[2] > maxZ) maxZ = prim->verts[j].xyz[2]; } @@ -1711,44 +1702,43 @@ static void gl2psRescaleAndOffset(void) if(scaleZ > 100000.F) scaleZ = 100000.F; /* apply offsets */ - for(i = 0; i < gl2psListNbr(gl2ps->primitives); i++){ - prim = *(GL2PSprimitive**)gl2psListPointer(gl2ps->primitives, i); - for(j = 0; j < prim->numverts; j++){ + for(i = 0; i < gl2psListNbr(gl2ps->primitives); i++) { + prim = *(GL2PSprimitive **)gl2psListPointer(gl2ps->primitives, i); + for(j = 0; j < prim->numverts; j++) { prim->verts[j].xyz[2] = (prim->verts[j].xyz[2] - minZ) * scaleZ; } if((gl2ps->options & GL2PS_SIMPLE_LINE_OFFSET) && - (prim->type == GL2PS_LINE)){ - if(gl2ps->sort == GL2PS_SIMPLE_SORT){ + (prim->type == GL2PS_LINE)) { + if(gl2ps->sort == GL2PS_SIMPLE_SORT) { prim->verts[0].xyz[2] -= GL2PS_ZOFFSET_LARGE; prim->verts[1].xyz[2] -= GL2PS_ZOFFSET_LARGE; } - else{ + else { prim->verts[0].xyz[2] -= GL2PS_ZOFFSET; prim->verts[1].xyz[2] -= GL2PS_ZOFFSET; } } - else if(prim->offset && (prim->type == GL2PS_TRIANGLE)){ + else if(prim->offset && (prim->type == GL2PS_TRIANGLE)) { factor = prim->ofactor; units = prim->ounits; - area = - (prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) * - (prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) - - (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) * - (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]); - if(!GL2PS_ZERO(area)){ - dZdX = - ((prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) * - (prim->verts[1].xyz[2] - prim->verts[0].xyz[2]) - - (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]) * - (prim->verts[2].xyz[2] - prim->verts[1].xyz[2])) / area; - dZdY = - ((prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) * - (prim->verts[2].xyz[2] - prim->verts[1].xyz[2]) - - (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) * - (prim->verts[1].xyz[2] - prim->verts[0].xyz[2])) / area; + area = (prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) * + (prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) - + (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) * + (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]); + if(!GL2PS_ZERO(area)) { + dZdX = ((prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) * + (prim->verts[1].xyz[2] - prim->verts[0].xyz[2]) - + (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]) * + (prim->verts[2].xyz[2] - prim->verts[1].xyz[2])) / + area; + dZdY = ((prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) * + (prim->verts[2].xyz[2] - prim->verts[1].xyz[2]) - + (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) * + (prim->verts[1].xyz[2] - prim->verts[0].xyz[2])) / + area; maxdZ = (GLfloat)sqrt(dZdX * dZdX + dZdY * dZdY); } - else{ + else { maxdZ = 0.0F; } dZ = factor * maxdZ + units; @@ -1771,15 +1761,15 @@ static GLint gl2psGetPlaneFromPoints(GL2PSxyz a, GL2PSxyz b, GL2PSplane plane) plane[0] = b[1] - a[1]; plane[1] = a[0] - b[0]; - n = (GLfloat)sqrt(plane[0]*plane[0] + plane[1]*plane[1]); + n = (GLfloat)sqrt(plane[0] * plane[0] + plane[1] * plane[1]); plane[2] = 0.0F; - if(!GL2PS_ZERO(n)){ + if(!GL2PS_ZERO(n)) { plane[0] /= n; plane[1] /= n; - plane[3] = -plane[0]*a[0]-plane[1]*a[1]; + plane[3] = -plane[0] * a[0] - plane[1] * a[1]; return 1; } - else{ + else { plane[0] = -1.0F; plane[1] = 0.0F; plane[3] = a[0]; @@ -1789,8 +1779,8 @@ static GLint gl2psGetPlaneFromPoints(GL2PSxyz a, GL2PSxyz b, GL2PSplane plane) static void gl2psFreeBspImageTree(GL2PSbsptree2d **tree) { - if(*tree){ - if((*tree)->back) gl2psFreeBspImageTree(&(*tree)->back); + if(*tree) { + if((*tree)->back) gl2psFreeBspImageTree(&(*tree)->back); if((*tree)->front) gl2psFreeBspImageTree(&(*tree)->front); gl2psFree(*tree); *tree = NULL; @@ -1802,9 +1792,12 @@ static GLint gl2psCheckPoint(GL2PSxyz point, GL2PSplane plane) GLfloat pt_dis; pt_dis = gl2psComparePointPlane(point, plane); - if(pt_dis > GL2PS_EPSILON) return GL2PS_POINT_INFRONT; - else if(pt_dis < -GL2PS_EPSILON) return GL2PS_POINT_BACK; - else return GL2PS_POINT_COINCIDENT; + if(pt_dis > GL2PS_EPSILON) + return GL2PS_POINT_INFRONT; + else if(pt_dis < -GL2PS_EPSILON) + return GL2PS_POINT_BACK; + else + return GL2PS_POINT_COINCIDENT; } static void gl2psAddPlanesInBspTreeImage(GL2PSprimitive *prim, @@ -1815,97 +1808,90 @@ static void gl2psAddPlanesInBspTreeImage(GL2PSprimitive *prim, GLint offset = 0; GL2PSbsptree2d *head = NULL, *cur = NULL; - if((*tree == NULL) && (prim->numverts > 2)){ + if((*tree == NULL) && (prim->numverts > 2)) { /* don't cull if transparent for(i = 0; i < prim->numverts - 1; i++) if(prim->verts[i].rgba[3] < 1.0F) return; */ - head = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); - for(i = 0; i < prim->numverts-1; i++){ - if(!gl2psGetPlaneFromPoints(prim->verts[i].xyz, - prim->verts[i+1].xyz, - head->plane)){ - if(prim->numverts-i > 3){ + head = (GL2PSbsptree2d *)gl2psMalloc(sizeof(GL2PSbsptree2d)); + for(i = 0; i < prim->numverts - 1; i++) { + if(!gl2psGetPlaneFromPoints(prim->verts[i].xyz, prim->verts[i + 1].xyz, + head->plane)) { + if(prim->numverts - i > 3) { offset++; } - else{ + else { gl2psFree(head); return; } } - else{ + else { break; } } head->back = NULL; head->front = NULL; - for(i = 2+offset; i < prim->numverts; i++){ + for(i = 2 + offset; i < prim->numverts; i++) { ret = gl2psCheckPoint(prim->verts[i].xyz, head->plane); if(ret != GL2PS_POINT_COINCIDENT) break; } - switch(ret){ - case GL2PS_POINT_INFRONT : + switch(ret) { + case GL2PS_POINT_INFRONT: cur = head; - for(i = 1+offset; i < prim->numverts-1; i++){ - if(cur->front == NULL){ - cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + for(i = 1 + offset; i < prim->numverts - 1; i++) { + if(cur->front == NULL) { + cur->front = (GL2PSbsptree2d *)gl2psMalloc(sizeof(GL2PSbsptree2d)); } - if(gl2psGetPlaneFromPoints(prim->verts[i].xyz, - prim->verts[i+1].xyz, - cur->front->plane)){ + if(gl2psGetPlaneFromPoints(prim->verts[i].xyz, prim->verts[i + 1].xyz, + cur->front->plane)) { cur = cur->front; cur->front = NULL; cur->back = NULL; } } - if(cur->front == NULL){ - cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + if(cur->front == NULL) { + cur->front = (GL2PSbsptree2d *)gl2psMalloc(sizeof(GL2PSbsptree2d)); } - if(gl2psGetPlaneFromPoints(prim->verts[i].xyz, - prim->verts[offset].xyz, - cur->front->plane)){ + if(gl2psGetPlaneFromPoints(prim->verts[i].xyz, prim->verts[offset].xyz, + cur->front->plane)) { cur->front->front = NULL; cur->front->back = NULL; } - else{ + else { gl2psFree(cur->front); cur->front = NULL; } break; - case GL2PS_POINT_BACK : - for(i = 0; i < 4; i++){ + case GL2PS_POINT_BACK: + for(i = 0; i < 4; i++) { head->plane[i] = -head->plane[i]; } cur = head; - for(i = 1+offset; i < prim->numverts-1; i++){ - if(cur->front == NULL){ - cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + for(i = 1 + offset; i < prim->numverts - 1; i++) { + if(cur->front == NULL) { + cur->front = (GL2PSbsptree2d *)gl2psMalloc(sizeof(GL2PSbsptree2d)); } - if(gl2psGetPlaneFromPoints(prim->verts[i+1].xyz, - prim->verts[i].xyz, - cur->front->plane)){ + if(gl2psGetPlaneFromPoints(prim->verts[i + 1].xyz, prim->verts[i].xyz, + cur->front->plane)) { cur = cur->front; cur->front = NULL; cur->back = NULL; } } - if(cur->front == NULL){ - cur->front = (GL2PSbsptree2d*)gl2psMalloc(sizeof(GL2PSbsptree2d)); + if(cur->front == NULL) { + cur->front = (GL2PSbsptree2d *)gl2psMalloc(sizeof(GL2PSbsptree2d)); } - if(gl2psGetPlaneFromPoints(prim->verts[offset].xyz, - prim->verts[i].xyz, - cur->front->plane)){ + if(gl2psGetPlaneFromPoints(prim->verts[offset].xyz, prim->verts[i].xyz, + cur->front->plane)) { cur->front->front = NULL; cur->front->back = NULL; } - else{ + else { gl2psFree(cur->front); cur->front = NULL; } break; - default: - gl2psFree(head); - return; + default: gl2psFree(head); return; } (*tree) = head; } @@ -1917,13 +1903,16 @@ static GLint gl2psCheckPrimitive(GL2PSprimitive *prim, GL2PSplane plane) GLint pos; pos = gl2psCheckPoint(prim->verts[0].xyz, plane); - for(i = 1; i < prim->numverts; i++){ + for(i = 1; i < prim->numverts; i++) { pos |= gl2psCheckPoint(prim->verts[i].xyz, plane); if(pos == (GL2PS_POINT_INFRONT | GL2PS_POINT_BACK)) return GL2PS_SPANNING; } - if(pos & GL2PS_POINT_INFRONT) return GL2PS_IN_FRONT_OF; - else if(pos & GL2PS_POINT_BACK) return GL2PS_IN_BACK_OF; - else return GL2PS_COINCIDENT; + if(pos & GL2PS_POINT_INFRONT) + return GL2PS_IN_FRONT_OF; + else if(pos & GL2PS_POINT_BACK) + return GL2PS_IN_BACK_OF; + else + return GL2PS_COINCIDENT; } static GL2PSprimitive *gl2psCreateSplitPrimitive2D(GL2PSprimitive *parent, @@ -1931,19 +1920,21 @@ static GL2PSprimitive *gl2psCreateSplitPrimitive2D(GL2PSprimitive *parent, GL2PSvertex *vertx) { GLint i; - GL2PSprimitive *child = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + GL2PSprimitive *child = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); - if(parent->type == GL2PS_IMAGEMAP){ + if(parent->type == GL2PS_IMAGEMAP) { child->type = GL2PS_IMAGEMAP; child->data.image = parent->data.image; } else { - switch(numverts){ - case 1 : child->type = GL2PS_POINT; break; - case 2 : child->type = GL2PS_LINE; break; - case 3 : child->type = GL2PS_TRIANGLE; break; - case 4 : child->type = GL2PS_QUADRANGLE; break; - default: child->type = GL2PS_NO_TYPE; break; /* FIXME */ + switch(numverts) { + case 1: child->type = GL2PS_POINT; break; + case 2: child->type = GL2PS_LINE; break; + case 3: child->type = GL2PS_TRIANGLE; break; + case 4: child->type = GL2PS_QUADRANGLE; break; + default: + child->type = GL2PS_NO_TYPE; + break; /* FIXME */ } } child->boundary = 0; /* FIXME: not done! */ @@ -1957,17 +1948,15 @@ static GL2PSprimitive *gl2psCreateSplitPrimitive2D(GL2PSprimitive *parent, child->linecap = parent->linecap; child->linejoin = parent->linejoin; child->numverts = numverts; - child->verts = (GL2PSvertex*)gl2psMalloc(numverts * sizeof(GL2PSvertex)); - for(i = 0; i < numverts; i++){ + child->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex)); + for(i = 0; i < numverts; i++) { child->verts[i] = vertx[i]; } return child; } -static void gl2psSplitPrimitive2D(GL2PSprimitive *prim, - GL2PSplane plane, - GL2PSprimitive **front, - GL2PSprimitive **back) +static void gl2psSplitPrimitive2D(GL2PSprimitive *prim, GL2PSplane plane, + GL2PSprimitive **front, GL2PSprimitive **back) { /* cur will hold the position of the current vertex prev will hold the position of the previous vertex @@ -1982,60 +1971,60 @@ static void gl2psSplitPrimitive2D(GL2PSprimitive *prim, /* number of vertices in front and back list */ GLshort front_count = 0, back_count = 0; - for(i = 0; i <= prim->numverts; i++){ + for(i = 0; i <= prim->numverts; i++) { v1 = i; - if(v1 == prim->numverts){ + if(v1 == prim->numverts) { if(prim->numverts < 3) break; v1 = 0; v2 = prim->numverts - 1; cur = prev0; } - else if(flag){ + else if(flag) { cur = gl2psCheckPoint(prim->verts[v1].xyz, plane); - if(i == 0){ + if(i == 0) { prev0 = cur; } } if(((prev == -1) || (prev == cur) || (prev == 0) || (cur == 0)) && - (i < prim->numverts)){ - if(cur == GL2PS_POINT_INFRONT){ + (i < prim->numverts)) { + if(cur == GL2PS_POINT_INFRONT) { front_count++; - front_list = (GL2PSvertex*)gl2psRealloc(front_list, - sizeof(GL2PSvertex)*front_count); - front_list[front_count-1] = prim->verts[v1]; + front_list = (GL2PSvertex *)gl2psRealloc( + front_list, sizeof(GL2PSvertex) * front_count); + front_list[front_count - 1] = prim->verts[v1]; } - else if(cur == GL2PS_POINT_BACK){ + else if(cur == GL2PS_POINT_BACK) { back_count++; - back_list = (GL2PSvertex*)gl2psRealloc(back_list, - sizeof(GL2PSvertex)*back_count); - back_list[back_count-1] = prim->verts[v1]; + back_list = (GL2PSvertex *)gl2psRealloc(back_list, sizeof(GL2PSvertex) * + back_count); + back_list[back_count - 1] = prim->verts[v1]; } - else{ + else { front_count++; - front_list = (GL2PSvertex*)gl2psRealloc(front_list, - sizeof(GL2PSvertex)*front_count); - front_list[front_count-1] = prim->verts[v1]; + front_list = (GL2PSvertex *)gl2psRealloc( + front_list, sizeof(GL2PSvertex) * front_count); + front_list[front_count - 1] = prim->verts[v1]; back_count++; - back_list = (GL2PSvertex*)gl2psRealloc(back_list, - sizeof(GL2PSvertex)*back_count); - back_list[back_count-1] = prim->verts[v1]; + back_list = (GL2PSvertex *)gl2psRealloc(back_list, sizeof(GL2PSvertex) * + back_count); + back_list[back_count - 1] = prim->verts[v1]; } flag = 1; } - else if((prev != cur) && (cur != 0) && (prev != 0)){ - if(v1 != 0){ - v2 = v1-1; + else if((prev != cur) && (cur != 0) && (prev != 0)) { + if(v1 != 0) { + v2 = v1 - 1; i--; } front_count++; - front_list = (GL2PSvertex*)gl2psRealloc(front_list, - sizeof(GL2PSvertex)*front_count); - gl2psCutEdge(&prim->verts[v2], &prim->verts[v1], - plane, &front_list[front_count-1]); + front_list = (GL2PSvertex *)gl2psRealloc(front_list, sizeof(GL2PSvertex) * + front_count); + gl2psCutEdge(&prim->verts[v2], &prim->verts[v1], plane, + &front_list[front_count - 1]); back_count++; - back_list = (GL2PSvertex*)gl2psRealloc(back_list, - sizeof(GL2PSvertex)*back_count); - back_list[back_count-1] = front_list[front_count-1]; + back_list = (GL2PSvertex *)gl2psRealloc(back_list, + sizeof(GL2PSvertex) * back_count); + back_list[back_count - 1] = front_list[front_count - 1]; flag = 0; } prev = cur; @@ -2054,29 +2043,30 @@ static GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree) /* FIXME: until we consider the actual extent of text strings and pixmaps, never cull them. Otherwise the whole string/pixmap gets culled as soon as the reference point is hidden */ - if(prim->type == GL2PS_PIXMAP || - prim->type == GL2PS_TEXT || - prim->type == GL2PS_SPECIAL){ + if(prim->type == GL2PS_PIXMAP || prim->type == GL2PS_TEXT || + prim->type == GL2PS_SPECIAL) { return 1; } - if(*tree == NULL){ - if((prim->type != GL2PS_IMAGEMAP) && (GL_FALSE == gl2ps->zerosurfacearea)){ + if(*tree == NULL) { + if((prim->type != GL2PS_IMAGEMAP) && (GL_FALSE == gl2ps->zerosurfacearea)) { gl2psAddPlanesInBspTreeImage(gl2ps->primitivetoadd, tree); } return 1; } - else{ - switch(gl2psCheckPrimitive(prim, (*tree)->plane)){ + else { + switch(gl2psCheckPrimitive(prim, (*tree)->plane)) { case GL2PS_IN_BACK_OF: return gl2psAddInBspImageTree(prim, &(*tree)->back); case GL2PS_IN_FRONT_OF: - if((*tree)->front != NULL) return gl2psAddInBspImageTree(prim, &(*tree)->front); - else return 0; + if((*tree)->front != NULL) + return gl2psAddInBspImageTree(prim, &(*tree)->front); + else + return 0; case GL2PS_SPANNING: gl2psSplitPrimitive2D(prim, (*tree)->plane, &frontprim, &backprim); ret = gl2psAddInBspImageTree(backprim, &(*tree)->back); - if((*tree)->front != NULL){ - if(gl2psAddInBspImageTree(frontprim, &(*tree)->front)){ + if((*tree)->front != NULL) { + if(gl2psAddInBspImageTree(frontprim, &(*tree)->front)) { ret = 1; } } @@ -2086,20 +2076,22 @@ static GLint gl2psAddInBspImageTree(GL2PSprimitive *prim, GL2PSbsptree2d **tree) gl2psFree(backprim); return ret; case GL2PS_COINCIDENT: - if((*tree)->back != NULL){ + if((*tree)->back != NULL) { gl2ps->zerosurfacearea = GL_TRUE; ret = gl2psAddInBspImageTree(prim, &(*tree)->back); gl2ps->zerosurfacearea = GL_FALSE; if(ret) return ret; } - if((*tree)->front != NULL){ + if((*tree)->front != NULL) { gl2ps->zerosurfacearea = GL_TRUE; ret = gl2psAddInBspImageTree(prim, &(*tree)->front); gl2ps->zerosurfacearea = GL_FALSE; if(ret) return ret; } - if(prim->type == GL2PS_LINE) return 1; - else return 0; + if(prim->type == GL2PS_LINE) + return 1; + else + return 0; } } return 0; @@ -2109,13 +2101,14 @@ static void gl2psAddInImageTree(void *data) { GL2PSprimitive *prim = *(GL2PSprimitive **)data; gl2ps->primitivetoadd = prim; - if(prim->type == GL2PS_IMAGEMAP && prim->data.image->format == GL2PS_IMAGEMAP_VISIBLE){ + if(prim->type == GL2PS_IMAGEMAP && + prim->data.image->format == GL2PS_IMAGEMAP_VISIBLE) { prim->culled = 1; } - else if(!gl2psAddInBspImageTree(prim, &gl2ps->imagetree)){ + else if(!gl2psAddInBspImageTree(prim, &gl2ps->imagetree)) { prim->culled = 1; } - else if(prim->type == GL2PS_IMAGEMAP){ + else if(prim->type == GL2PS_IMAGEMAP) { prim->data.image->format = GL2PS_IMAGEMAP_VISIBLE; } } @@ -2129,16 +2122,16 @@ static void gl2psAddBoundaryInList(GL2PSprimitive *prim, GL2PSlist *list) GL2PSxyz c; c[0] = c[1] = c[2] = 0.0F; - for(i = 0; i < prim->numverts; i++){ + for(i = 0; i < prim->numverts; i++) { c[0] += prim->verts[i].xyz[0]; c[1] += prim->verts[i].xyz[1]; } c[0] /= prim->numverts; c[1] /= prim->numverts; - for(i = 0; i < prim->numverts; i++){ - if(prim->boundary & (GLint)pow(2., i)){ - b = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + for(i = 0; i < prim->numverts; i++) { + if(prim->boundary & (GLint)pow(2., i)) { + b = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); b->type = GL2PS_LINE; b->offset = prim->offset; b->ofactor = prim->ofactor; @@ -2151,7 +2144,7 @@ static void gl2psAddBoundaryInList(GL2PSprimitive *prim, GL2PSlist *list) b->linejoin = prim->linejoin; b->boundary = 0; b->numverts = 2; - b->verts = (GL2PSvertex*)gl2psMalloc(2 * sizeof(GL2PSvertex)); + b->verts = (GL2PSvertex *)gl2psMalloc(2 * sizeof(GL2PSvertex)); #if 0 /* FIXME: need to work on boundary offset... */ v[0] = c[0] - prim->verts[i].xyz[0]; @@ -2191,7 +2184,6 @@ static void gl2psAddBoundaryInList(GL2PSprimitive *prim, GL2PSlist *list) gl2psListAdd(list, &b); } } - } static void gl2psBuildPolygonBoundary(GL2PSbsptree *tree) @@ -2201,8 +2193,8 @@ static void gl2psBuildPolygonBoundary(GL2PSbsptree *tree) if(!tree) return; gl2psBuildPolygonBoundary(tree->back); - for(i = 0; i < gl2psListNbr(tree->primitives); i++){ - prim = *(GL2PSprimitive**)gl2psListPointer(tree->primitives, i); + for(i = 0; i < gl2psListNbr(tree->primitives); i++) { + prim = *(GL2PSprimitive **)gl2psListPointer(tree->primitives, i); if(prim->boundary) gl2psAddBoundaryInList(prim, tree->primitives); } gl2psBuildPolygonBoundary(tree->front); @@ -2219,14 +2211,14 @@ GL2PSDLL_API void gl2psAddPolyPrimitive(GLshort type, GLshort numverts, GLfloat ofactor, GLfloat ounits, GLushort pattern, GLint factor, GLfloat width, GLint linecap, - GLint linejoin,char boundary) + GLint linejoin, char boundary) { GL2PSprimitive *prim; - prim = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); prim->type = type; prim->numverts = numverts; - prim->verts = (GL2PSvertex*)gl2psMalloc(numverts * sizeof(GL2PSvertex)); + prim->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex)); memcpy(prim->verts, verts, numverts * sizeof(GL2PSvertex)); prim->boundary = boundary; prim->offset = (char)offset; @@ -2253,7 +2245,7 @@ static GLint gl2psGetVertex(GL2PSvertex *v, GLfloat *p) v->xyz[1] = p[1]; v->xyz[2] = p[2]; - if(gl2ps->colormode == GL_COLOR_INDEX && gl2ps->colorsize > 0){ + if(gl2ps->colormode == GL_COLOR_INDEX && gl2ps->colorsize > 0) { i = (GLint)(p[3] + 0.5); v->rgba[0] = gl2ps->colormap[i][0]; v->rgba[1] = gl2ps->colormap[i][1]; @@ -2261,7 +2253,7 @@ static GLint gl2psGetVertex(GL2PSvertex *v, GLfloat *p) v->rgba[3] = gl2ps->colormap[i][3]; return 4; } - else{ + else { v->rgba[0] = p[3]; v->rgba[1] = p[4]; v->rgba[2] = p[5]; @@ -2286,75 +2278,77 @@ static void gl2psParseFeedbackBuffer(GLint used) current = gl2ps->feedback; boundary = gl2ps->boundary = GL_FALSE; - while(used > 0){ - + while(used > 0) { if(GL_TRUE == boundary) gl2ps->boundary = GL_TRUE; - switch((GLint)*current){ - case GL_POINT_TOKEN : - current ++; - used --; + switch((GLint)*current) { + case GL_POINT_TOKEN: + current++; + used--; i = gl2psGetVertex(&vertices[0], current); current += i; - used -= i; - gl2psAddPolyPrimitive(GL2PS_POINT, 1, vertices, 0, 0.0, 0.0, - pattern, factor, psize, lcap, ljoin, 0); + used -= i; + gl2psAddPolyPrimitive(GL2PS_POINT, 1, vertices, 0, 0.0, 0.0, pattern, + factor, psize, lcap, ljoin, 0); break; - case GL_LINE_TOKEN : - case GL_LINE_RESET_TOKEN : - current ++; - used --; + case GL_LINE_TOKEN: + case GL_LINE_RESET_TOKEN: + current++; + used--; i = gl2psGetVertex(&vertices[0], current); current += i; - used -= i; + used -= i; i = gl2psGetVertex(&vertices[1], current); current += i; - used -= i; - gl2psAddPolyPrimitive(GL2PS_LINE, 2, vertices, 0, 0.0, 0.0, - pattern, factor, lwidth, lcap, ljoin, 0); + used -= i; + gl2psAddPolyPrimitive(GL2PS_LINE, 2, vertices, 0, 0.0, 0.0, pattern, + factor, lwidth, lcap, ljoin, 0); break; - case GL_POLYGON_TOKEN : + case GL_POLYGON_TOKEN: count = (GLint)current[1]; current += 2; used -= 2; v = vtot = 0; - while(count > 0 && used > 0){ + while(count > 0 && used > 0) { i = gl2psGetVertex(&vertices[v], current); gl2psAdaptVertexForBlending(&vertices[v]); current += i; - used -= i; - count --; + used -= i; + count--; vtot++; - if(v == 2){ - if(GL_TRUE == boundary){ - if(!count && vtot == 2) flag = 1|2|4; - else if(!count) flag = 2|4; - else if(vtot == 2) flag = 1|2; - else flag = 2; + if(v == 2) { + if(GL_TRUE == boundary) { + if(!count && vtot == 2) + flag = 1 | 2 | 4; + else if(!count) + flag = 2 | 4; + else if(vtot == 2) + flag = 1 | 2; + else + flag = 2; } else flag = 0; gl2psAddPolyPrimitive(GL2PS_TRIANGLE, 3, vertices, offset, ofactor, - ounits, pattern, factor, 1, lcap, ljoin, - flag); + ounits, pattern, factor, 1, lcap, ljoin, flag); vertices[1] = vertices[2]; } else - v ++; + v++; } break; - case GL_BITMAP_TOKEN : - case GL_DRAW_PIXEL_TOKEN : - case GL_COPY_PIXEL_TOKEN : - current ++; - used --; + case GL_BITMAP_TOKEN: + case GL_DRAW_PIXEL_TOKEN: + case GL_COPY_PIXEL_TOKEN: + current++; + used--; i = gl2psGetVertex(&vertices[0], current); current += i; - used -= i; + used -= i; break; - case GL_PASS_THROUGH_TOKEN : - switch((GLint)current[1]){ - case GL2PS_BEGIN_OFFSET_TOKEN : + case GL_PASS_THROUGH_TOKEN: + switch((GLint)current[1]) { + case GL2PS_BEGIN_OFFSET_TOKEN: offset = 1; current += 2; used -= 2; @@ -2363,17 +2357,20 @@ static void gl2psParseFeedbackBuffer(GLint used) used -= 2; ounits = current[1]; break; - case GL2PS_END_OFFSET_TOKEN : + case GL2PS_END_OFFSET_TOKEN: offset = 0; ofactor = 0.0; ounits = 0.0; break; - case GL2PS_BEGIN_BOUNDARY_TOKEN : boundary = GL_TRUE; break; - case GL2PS_END_BOUNDARY_TOKEN : boundary = GL_FALSE; break; - case GL2PS_END_STIPPLE_TOKEN : pattern = 0; factor = 0; break; - case GL2PS_BEGIN_BLEND_TOKEN : gl2ps->blending = GL_TRUE; break; - case GL2PS_END_BLEND_TOKEN : gl2ps->blending = GL_FALSE; break; - case GL2PS_BEGIN_STIPPLE_TOKEN : + case GL2PS_BEGIN_BOUNDARY_TOKEN: boundary = GL_TRUE; break; + case GL2PS_END_BOUNDARY_TOKEN: boundary = GL_FALSE; break; + case GL2PS_END_STIPPLE_TOKEN: + pattern = 0; + factor = 0; + break; + case GL2PS_BEGIN_BLEND_TOKEN: gl2ps->blending = GL_TRUE; break; + case GL2PS_END_BLEND_TOKEN: gl2ps->blending = GL_FALSE; break; + case GL2PS_BEGIN_STIPPLE_TOKEN: current += 2; used -= 2; pattern = (GLushort)current[1]; @@ -2381,37 +2378,37 @@ static void gl2psParseFeedbackBuffer(GLint used) used -= 2; factor = (GLint)current[1]; break; - case GL2PS_SRC_BLEND_TOKEN : + case GL2PS_SRC_BLEND_TOKEN: current += 2; used -= 2; gl2ps->blendfunc[0] = (GLint)current[1]; break; - case GL2PS_DST_BLEND_TOKEN : + case GL2PS_DST_BLEND_TOKEN: current += 2; used -= 2; gl2ps->blendfunc[1] = (GLint)current[1]; break; - case GL2PS_POINT_SIZE_TOKEN : + case GL2PS_POINT_SIZE_TOKEN: current += 2; used -= 2; psize = current[1]; break; - case GL2PS_LINE_CAP_TOKEN : + case GL2PS_LINE_CAP_TOKEN: current += 2; used -= 2; lcap = current[1]; break; - case GL2PS_LINE_JOIN_TOKEN : + case GL2PS_LINE_JOIN_TOKEN: current += 2; used -= 2; ljoin = current[1]; break; - case GL2PS_LINE_WIDTH_TOKEN : + case GL2PS_LINE_WIDTH_TOKEN: current += 2; used -= 2; lwidth = current[1]; break; - case GL2PS_IMAGEMAP_TOKEN : + case GL2PS_IMAGEMAP_TOKEN: prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); prim->type = GL2PS_IMAGEMAP; prim->boundary = 0; @@ -2425,8 +2422,8 @@ static void gl2psParseFeedbackBuffer(GLint used) prim->factor = 0; prim->width = 1; - node = (GL2PSimagemap*)gl2psMalloc(sizeof(GL2PSimagemap)); - node->image = (GL2PSimage*)gl2psMalloc(sizeof(GL2PSimage)); + node = (GL2PSimagemap *)gl2psMalloc(sizeof(GL2PSimagemap)); + node->image = (GL2PSimage *)gl2psMalloc(sizeof(GL2PSimage)); node->image->type = 0; node->image->format = 0; node->image->zoom_x = 1.0F; @@ -2440,17 +2437,22 @@ static void gl2psParseFeedbackBuffer(GLint used) gl2ps->imagemap_tail = node; prim->data.image = node->image; - current += 2; used -= 2; + current += 2; + used -= 2; i = gl2psGetVertex(&prim->verts[0], ¤t[1]); - current += i; used -= i; + current += i; + used -= i; node->image->width = (GLint)current[2]; - current += 2; used -= 2; + current += 2; + used -= 2; node->image->height = (GLint)current[2]; - prim->verts[0].xyz[0] = prim->verts[0].xyz[0] - (int)(node->image->width / 2) + 0.5F; - prim->verts[0].xyz[1] = prim->verts[0].xyz[1] - (int)(node->image->height / 2) + 0.5F; - for(i = 1; i < 4; i++){ - for(v = 0; v < 3; v++){ + prim->verts[0].xyz[0] = + prim->verts[0].xyz[0] - (int)(node->image->width / 2) + 0.5F; + prim->verts[0].xyz[1] = + prim->verts[0].xyz[1] - (int)(node->image->height / 2) + 0.5F; + for(i = 1; i < 4; i++) { + for(v = 0; v < 3; v++) { prim->verts[i].xyz[v] = prim->verts[0].xyz[v]; prim->verts[i].rgba[v] = prim->verts[0].rgba[v]; } @@ -2463,24 +2465,28 @@ static void gl2psParseFeedbackBuffer(GLint used) sizeoffloat = sizeof(GLfloat); v = 2 * sizeoffloat; - vtot = node->image->height + node->image->height * - ((node->image->width - 1) / 8); - node->image->pixels = (GLfloat*)gl2psMalloc(v + vtot); + vtot = node->image->height + + node->image->height * ((node->image->width - 1) / 8); + node->image->pixels = (GLfloat *)gl2psMalloc(v + vtot); node->image->pixels[0] = prim->verts[0].xyz[0]; node->image->pixels[1] = prim->verts[0].xyz[1]; - for(i = 0; i < vtot; i += sizeoffloat){ - current += 2; used -= 2; + for(i = 0; i < vtot; i += sizeoffloat) { + current += 2; + used -= 2; if((vtot - i) >= 4) - memcpy(&(((char*)(node->image->pixels))[i + v]), &(current[2]), sizeoffloat); + memcpy(&(((char *)(node->image->pixels))[i + v]), &(current[2]), + sizeoffloat); else - memcpy(&(((char*)(node->image->pixels))[i + v]), &(current[2]), vtot - i); + memcpy(&(((char *)(node->image->pixels))[i + v]), &(current[2]), + vtot - i); } - current++; used--; + current++; + used--; gl2psListAdd(gl2ps->primitives, &prim); break; - case GL2PS_DRAW_PIXELS_TOKEN : - case GL2PS_TEXT_TOKEN : + case GL2PS_DRAW_PIXELS_TOKEN: + case GL2PS_TEXT_TOKEN: if(auxindex < gl2psListNbr(gl2ps->auxprimitives)) gl2psListAdd(gl2ps->primitives, gl2psListPointer(gl2ps->auxprimitives, auxindex++)); @@ -2491,10 +2497,10 @@ static void gl2psParseFeedbackBuffer(GLint used) current += 2; used -= 2; break; - default : + default: gl2psMsg(GL2PS_WARNING, "Unknown token in buffer"); - current ++; - used --; + current++; + used--; break; } } @@ -2535,14 +2541,14 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) gl2psPrintf("%.2f %.2f translate\n", x, y); gl2psPrintf("%.2f %.2f scale\n", width * im->zoom_x, height * im->zoom_y); - if(greyscale){ /* greyscale */ + if(greyscale) { /* greyscale */ gl2psPrintf("/picstr %d string def\n", width); gl2psPrintf("%d %d %d\n", width, height, 8); gl2psPrintf("[ %d 0 0 -%d 0 %d ]\n", width, height, height); gl2psPrintf("{ currentfile picstr readhexstring pop }\n"); gl2psPrintf("image\n"); - for(row = 0; row < height; row++){ - for(col = 0; col < width; col++){ + for(row = 0; row < height; row++) { + for(col = 0; col < width; col++) { gl2psGetRGB(im, col, row, &dr, &dg, &db); fgrey = (0.30F * dr + 0.59F * dg + 0.11F * db); grey = (unsigned char)(255. * fgrey); @@ -2553,8 +2559,9 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) nbhex = width * height * 2; gl2psPrintf("%%%% nbhex digit :%d\n", nbhex); } - else if(nbit == 2){ /* color, 2 bits for r and g and b; rgbs following each other */ - nrgb = width * 3; + else if(nbit == + 2) { /* color, 2 bits for r and g and b; rgbs following each other */ + nrgb = width * 3; nbits = nrgb * nbit; nbyte = nbits / 8; if((nbyte * 8) != nbits) nbyte++; @@ -2564,11 +2571,11 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) gl2psPrintf("{ currentfile rgbstr readhexstring pop }\n"); gl2psPrintf("false 3\n"); gl2psPrintf("colorimage\n"); - for(row = 0; row < height; row++){ + for(row = 0; row < height; row++) { icase = 1; col = 0; b = 0; - for(ibyte = 0; ibyte < nbyte; ibyte++){ + for(ibyte = 0; ibyte < nbyte; ibyte++) { if(icase == 1) { if(col < width) { gl2psGetRGB(im, col, row, &dr, &dg, &db); @@ -2581,8 +2588,8 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) green = (unsigned char)(3. * dg); blue = (unsigned char)(3. * db); b = red; - b = (b<<2) + green; - b = (b<<2) + blue; + b = (b << 2) + green; + b = (b << 2) + blue; if(col < width) { gl2psGetRGB(im, col, row, &dr, &dg, &db); } @@ -2593,14 +2600,14 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) red = (unsigned char)(3. * dr); green = (unsigned char)(3. * dg); blue = (unsigned char)(3. * db); - b = (b<<2) + red; + b = (b << 2) + red; gl2psWriteByte(b); b = 0; icase++; } else if(icase == 2) { b = green; - b = (b<<2) + blue; + b = (b << 2) + blue; if(col < width) { gl2psGetRGB(im, col, row, &dr, &dg, &db); } @@ -2611,8 +2618,8 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) red = (unsigned char)(3. * dr); green = (unsigned char)(3. * dg); blue = (unsigned char)(3. * db); - b = (b<<2) + red; - b = (b<<2) + green; + b = (b << 2) + red; + b = (b << 2) + green; gl2psWriteByte(b); b = 0; icase++; @@ -2629,9 +2636,9 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) red = (unsigned char)(3. * dr); green = (unsigned char)(3. * dg); blue = (unsigned char)(3. * db); - b = (b<<2) + red; - b = (b<<2) + green; - b = (b<<2) + blue; + b = (b << 2) + red; + b = (b << 2) + green; + b = (b << 2) + blue; gl2psWriteByte(b); b = 0; icase = 1; @@ -2640,8 +2647,9 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) gl2psPrintf("\n"); } } - else if(nbit == 4){ /* color, 4 bits for r and g and b; rgbs following each other */ - nrgb = width * 3; + else if(nbit == + 4) { /* color, 4 bits for r and g and b; rgbs following each other */ + nrgb = width * 3; nbits = nrgb * nbit; nbyte = nbits / 8; if((nbyte * 8) != nbits) nbyte++; @@ -2651,10 +2659,10 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) gl2psPrintf("{ currentfile rgbstr readhexstring pop }\n"); gl2psPrintf("false 3\n"); gl2psPrintf("colorimage\n"); - for(row = 0; row < height; row++){ + for(row = 0; row < height; row++) { col = 0; icase = 1; - for(ibyte = 0; ibyte < nbyte; ibyte++){ + for(ibyte = 0; ibyte < nbyte; ibyte++) { if(icase == 1) { if(col < width) { gl2psGetRGB(im, col, row, &dr, &dg, &db); @@ -2691,7 +2699,7 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) gl2psPrintf("\n"); } } - else{ /* 8 bit for r and g and b */ + else { /* 8 bit for r and g and b */ nbyte = width * 3; gl2psPrintf("/rgbstr %d string def\n", nbyte); gl2psPrintf("%d %d %d\n", width, height, 8); @@ -2699,8 +2707,8 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) gl2psPrintf("{ currentfile rgbstr readhexstring pop }\n"); gl2psPrintf("false 3\n"); gl2psPrintf("colorimage\n"); - for(row = 0; row < height; row++){ - for(col = 0; col < width; col++){ + for(row = 0; row < height; row++) { + for(col = 0; col < width; col++) { gl2psGetRGB(im, col, row, &dr, &dg, &db); red = (unsigned char)(255. * dr); gl2psWriteByte(red); @@ -2716,9 +2724,10 @@ static void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GL2PSimage *im) gl2psPrintf("grestore\n"); } -static void gl2psPrintPostScriptImagemap(GLfloat x, GLfloat y, - GLsizei width, GLsizei height, - const unsigned char *imagemap){ +static void gl2psPrintPostScriptImagemap(GLfloat x, GLfloat y, GLsizei width, + GLsizei height, + const unsigned char *imagemap) +{ int i, size; if((width <= 0) || (height <= 0)) return; @@ -2727,9 +2736,9 @@ static void gl2psPrintPostScriptImagemap(GLfloat x, GLfloat y, gl2psPrintf("gsave\n"); gl2psPrintf("%.2f %.2f translate\n", x, y); - gl2psPrintf("%d %d scale\n%d %d\ntrue\n", width, height,width, height); + gl2psPrintf("%d %d scale\n%d %d\ntrue\n", width, height, width, height); gl2psPrintf("[ %d 0 0 -%d 0 %d ] {<", width, height); - for(i = 0; i < size; i++){ + for(i = 0; i < size; i++) { gl2psWriteByte(*imagemap); imagemap++; } @@ -2747,10 +2756,10 @@ static void gl2psPrintPostScriptHeader(void) time(&now); - if(gl2ps->format == GL2PS_PS){ + if(gl2ps->format == GL2PS_PS) { gl2psPrintf("%%!PS-Adobe-3.0\n"); } - else{ + else { gl2psPrintf("%%!PS-Adobe-3.0 EPSF-3.0\n"); } @@ -2765,26 +2774,26 @@ static void gl2psPrintPostScriptHeader(void) GL2PS_PATCH_VERSION, GL2PS_EXTRA_VERSION, GL2PS_COPYRIGHT, gl2ps->producer, ctime(&now)); - if(gl2ps->format == GL2PS_PS){ + if(gl2ps->format == GL2PS_PS) { gl2psPrintf("%%%%Orientation: %s\n" "%%%%DocumentMedia: Default %d %d 0 () ()\n", (gl2ps->options & GL2PS_LANDSCAPE) ? "Landscape" : "Portrait", (gl2ps->options & GL2PS_LANDSCAPE) ? (int)gl2ps->viewport[3] : - (int)gl2ps->viewport[2], + (int)gl2ps->viewport[2], (gl2ps->options & GL2PS_LANDSCAPE) ? (int)gl2ps->viewport[2] : - (int)gl2ps->viewport[3]); + (int)gl2ps->viewport[3]); } gl2psPrintf("%%%%BoundingBox: %d %d %d %d\n" "%%%%EndComments\n", (gl2ps->options & GL2PS_LANDSCAPE) ? (int)gl2ps->viewport[1] : - (int)gl2ps->viewport[0], + (int)gl2ps->viewport[0], (gl2ps->options & GL2PS_LANDSCAPE) ? (int)gl2ps->viewport[0] : - (int)gl2ps->viewport[1], + (int)gl2ps->viewport[1], (gl2ps->options & GL2PS_LANDSCAPE) ? (int)gl2ps->viewport[3] : - (int)gl2ps->viewport[2], + (int)gl2ps->viewport[2], (gl2ps->options & GL2PS_LANDSCAPE) ? (int)gl2ps->viewport[2] : - (int)gl2ps->viewport[3]); + (int)gl2ps->viewport[3]); /* RGB color: r g b C (replace C by G in output to change from rgb to gray) Grayscale: r g b G @@ -2810,7 +2819,8 @@ static void gl2psPrintPostScriptHeader(void) gl2psPrintf("/BD { bind def } bind def\n" "/C { setrgbcolor } BD\n" - "/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add setgray } BD\n" + "/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 " + "add setgray } BD\n" "/W { setlinewidth } BD\n" "/LC { setlinecap } BD\n" "/LJ { setlinejoin } BD\n"); @@ -2829,16 +2839,22 @@ static void gl2psPrintPostScriptHeader(void) /* rotated text routines: same nameanem with R appended */ - gl2psPrintf("/FCT { FC translate 0 0 } BD\n" - "/SR { gsave FCT moveto rotate show grestore } BD\n" - "/SBCR{ gsave FCT moveto rotate SW -2 div 0 rmoveto show grestore } BD\n" - "/SBRR{ gsave FCT moveto rotate SW neg 0 rmoveto show grestore } BD\n" - "/SCLR{ gsave FCT moveto rotate 0 SH -2 div rmoveto show grestore} BD\n"); - gl2psPrintf("/SCCR{ gsave FCT moveto rotate SW -2 div SH -2 div rmoveto show grestore} BD\n" - "/SCRR{ gsave FCT moveto rotate SW neg SH -2 div rmoveto show grestore} BD\n" - "/STLR{ gsave FCT moveto rotate 0 SH neg rmoveto show grestore } BD\n" - "/STCR{ gsave FCT moveto rotate SW -2 div SH neg rmoveto show grestore } BD\n" - "/STRR{ gsave FCT moveto rotate SW neg SH neg rmoveto show grestore } BD\n"); + gl2psPrintf( + "/FCT { FC translate 0 0 } BD\n" + "/SR { gsave FCT moveto rotate show grestore } BD\n" + "/SBCR{ gsave FCT moveto rotate SW -2 div 0 rmoveto show grestore } BD\n" + "/SBRR{ gsave FCT moveto rotate SW neg 0 rmoveto show grestore } BD\n" + "/SCLR{ gsave FCT moveto rotate 0 SH -2 div rmoveto show grestore} BD\n"); + gl2psPrintf( + "/SCCR{ gsave FCT moveto rotate SW -2 div SH -2 div rmoveto show grestore} " + "BD\n" + "/SCRR{ gsave FCT moveto rotate SW neg SH -2 div rmoveto show grestore} " + "BD\n" + "/STLR{ gsave FCT moveto rotate 0 SH neg rmoveto show grestore } BD\n" + "/STCR{ gsave FCT moveto rotate SW -2 div SH neg rmoveto show grestore } " + "BD\n" + "/STRR{ gsave FCT moveto rotate SW neg SH neg rmoveto show grestore } " + "BD\n"); gl2psPrintf("/P { newpath 0.0 360.0 arc closepath fill } BD\n" "/LS { newpath moveto } BD\n" @@ -2849,23 +2865,31 @@ static void gl2psPrintPostScriptHeader(void) /* Smooth-shaded triangle with PostScript level 3 shfill operator: x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 STshfill */ - gl2psPrintf("/STshfill {\n" - " /b1 exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n" - " /b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n" - " /b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n" - " gsave << /ShadingType 4 /ColorSpace [/DeviceRGB]\n" - " /DataSource [ 0 x1 y1 r1 g1 b1 0 x2 y2 r2 g2 b2 0 x3 y3 r3 g3 b3 ] >>\n" - " shfill grestore } BD\n"); + gl2psPrintf( + "/STshfill {\n" + " /b1 exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n" + " /b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n" + " /b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n" + " gsave << /ShadingType 4 /ColorSpace [/DeviceRGB]\n" + " /DataSource [ 0 x1 y1 r1 g1 b1 0 x2 y2 r2 g2 b2 0 x3 y3 r3 g3 b3 ] " + ">>\n" + " shfill grestore } BD\n"); /* Flat-shaded triangle with middle color: x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 Tm */ gl2psPrintf(/* stack : x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 */ - "/Tm { 3 -1 roll 8 -1 roll 13 -1 roll add add 3 div\n" /* r = (r1+r2+r3)/3 */ + "/Tm { 3 -1 roll 8 -1 roll 13 -1 roll add add 3 div\n" /* r = + (r1+r2+r3)/3 + */ /* stack : x3 y3 g3 b3 x2 y2 g2 b2 x1 y1 g1 b1 r */ - " 3 -1 roll 7 -1 roll 11 -1 roll add add 3 div\n" /* g = (g1+g2+g3)/3 */ + " 3 -1 roll 7 -1 roll 11 -1 roll add add 3 div\n" /* g = + (g1+g2+g3)/3 + */ /* stack : x3 y3 b3 x2 y2 b2 x1 y1 b1 r g b */ - " 3 -1 roll 6 -1 roll 9 -1 roll add add 3 div" /* b = (b1+b2+b3)/3 */ + " 3 -1 roll 6 -1 roll 9 -1 roll add add 3 div" /* b = + (b1+b2+b3)/3 + */ /* stack : x3 y3 x2 y2 x1 y1 r g b */ " C T } BD\n"); @@ -2900,7 +2924,8 @@ static void gl2psPrintPostScriptHeader(void) " 4 index 10 index add 0.5 mul\n" /* b12 = (b1+b2)/2 */ " 5 copy 5 copy 40 5 roll 25 5 roll 15 5 roll 25 5 roll\n"); - /* stack = (V3) (V13) (V23) (V13) (V12) (V23) (V13) (V1) (V12) (V23) (V12) (V2) */ + /* stack = (V3) (V13) (V23) (V13) (V12) (V23) (V13) (V1) (V12) (V23) (V12) + * (V2) */ gl2psPrintf(" STnoshfill STnoshfill STnoshfill STnoshfill } BD\n"); @@ -2908,35 +2933,40 @@ static void gl2psPrintPostScriptHeader(void) between corner colors does not exceed the thresholds: x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 STnoshfill */ - gl2psPrintf("/STnoshfill {\n" - " 2 index 8 index sub abs rThreshold gt\n" /* |r1-r2|>rth */ - " { STsplit }\n" - " { 1 index 7 index sub abs gThreshold gt\n" /* |g1-g2|>gth */ - " { STsplit }\n" - " { dup 6 index sub abs bThreshold gt\n" /* |b1-b2|>bth */ - " { STsplit }\n" - " { 2 index 13 index sub abs rThreshold gt\n" /* |r1-r3|>rht */ - " { STsplit }\n" - " { 1 index 12 index sub abs gThreshold gt\n" /* |g1-g3|>gth */ - " { STsplit }\n" - " { dup 11 index sub abs bThreshold gt\n" /* |b1-b3|>bth */ - " { STsplit }\n" - " { 7 index 13 index sub abs rThreshold gt\n"); /* |r2-r3|>rht */ - gl2psPrintf(" { STsplit }\n" - " { 6 index 12 index sub abs gThreshold gt\n" /* |g2-g3|>gth */ - " { STsplit }\n" - " { 5 index 11 index sub abs bThreshold gt\n" /* |b2-b3|>bth */ - " { STsplit }\n" - " { Tm }\n" /* all colors sufficiently similar */ - " ifelse }\n" - " ifelse }\n" - " ifelse }\n" - " ifelse }\n" - " ifelse }\n" - " ifelse }\n" - " ifelse }\n" - " ifelse }\n" - " ifelse } BD\n"); + gl2psPrintf( + "/STnoshfill {\n" + " 2 index 8 index sub abs rThreshold gt\n" /* |r1-r2|>rth */ + " { STsplit }\n" + " { 1 index 7 index sub abs gThreshold gt\n" /* |g1-g2|>gth */ + " { STsplit }\n" + " { dup 6 index sub abs bThreshold gt\n" /* |b1-b2|>bth */ + " { STsplit }\n" + " { 2 index 13 index sub abs rThreshold gt\n" /* |r1-r3|>rht */ + " { STsplit }\n" + " { 1 index 12 index sub abs gThreshold gt\n" /* |g1-g3|>gth */ + " { STsplit }\n" + " { dup 11 index sub abs bThreshold gt\n" /* |b1-b3|>bth */ + " { STsplit }\n" + " { 7 index 13 index sub abs rThreshold gt\n"); /* |r2-r3|>rht + */ + gl2psPrintf( + " { STsplit }\n" + " { 6 index 12 index sub abs gThreshold gt\n" /* |g2-g3|>gth + */ + " { STsplit }\n" + " { 5 index 11 index sub abs bThreshold gt\n" /* |b2-b3|>bth + */ + " { STsplit }\n" + " { Tm }\n" /* all colors sufficiently similar */ + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse }\n" + " ifelse } BD\n"); gl2psPrintf("tryPS3shading\n" "{ /shfill where\n" @@ -2955,9 +2985,8 @@ static void gl2psPrintPostScriptHeader(void) "%%%%Page: 1 1\n" "%%%%BeginPageSetup\n"); - if(gl2ps->options & GL2PS_LANDSCAPE){ - gl2psPrintf("%d 0 translate 90 rotate\n", - (int)gl2ps->viewport[3]); + if(gl2ps->options & GL2PS_LANDSCAPE) { + gl2psPrintf("%d 0 translate 90 rotate\n", (int)gl2ps->viewport[3]); } gl2psPrintf("%%%%EndPageSetup\n" @@ -2965,20 +2994,21 @@ static void gl2psPrintPostScriptHeader(void) "gsave\n" "1.0 1.0 scale\n"); - if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ + if(gl2ps->options & GL2PS_DRAW_BACKGROUND) { gl2psPrintf("%g %g %g C\n" "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n" "closepath fill\n", gl2ps->bgcolor[0], gl2ps->bgcolor[1], gl2ps->bgcolor[2], - (int)gl2ps->viewport[0], (int)gl2ps->viewport[1], (int)gl2ps->viewport[2], - (int)gl2ps->viewport[1], (int)gl2ps->viewport[2], (int)gl2ps->viewport[3], + (int)gl2ps->viewport[0], (int)gl2ps->viewport[1], + (int)gl2ps->viewport[2], (int)gl2ps->viewport[1], + (int)gl2ps->viewport[2], (int)gl2ps->viewport[3], (int)gl2ps->viewport[0], (int)gl2ps->viewport[3]); } } static void gl2psPrintPostScriptColor(GL2PSrgba rgba) { - if(!gl2psSameColor(gl2ps->lastrgba, rgba)){ + if(!gl2psSameColor(gl2ps->lastrgba, rgba)) { gl2psSetLastColor(rgba); gl2psPrintf("%g %g %g C\n", rgba[0], rgba[1], rgba[2]); } @@ -2992,17 +3022,16 @@ static void gl2psResetPostScriptColor(void) static void gl2psEndPostScriptLine(void) { int i; - if(gl2ps->lastvertex.rgba[0] >= 0.){ - gl2psPrintf("%g %g LE\n", gl2ps->lastvertex.xyz[0], gl2ps->lastvertex.xyz[1]); - for(i = 0; i < 3; i++) - gl2ps->lastvertex.xyz[i] = -1.; - for(i = 0; i < 4; i++) - gl2ps->lastvertex.rgba[i] = -1.; + if(gl2ps->lastvertex.rgba[0] >= 0.) { + gl2psPrintf("%g %g LE\n", gl2ps->lastvertex.xyz[0], + gl2ps->lastvertex.xyz[1]); + for(i = 0; i < 3; i++) gl2ps->lastvertex.xyz[i] = -1.; + for(i = 0; i < 4; i++) gl2ps->lastvertex.rgba[i] = -1.; } } -static void gl2psParseStipplePattern(GLushort pattern, GLint factor, - int *nb, int array[10]) +static void gl2psParseStipplePattern(GLushort pattern, GLint factor, int *nb, + int array[10]) { int i, n; int on[8] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -3010,16 +3039,25 @@ static void gl2psParseStipplePattern(GLushort pattern, GLint factor, char tmp[16]; /* extract the 16 bits from the OpenGL stipple pattern */ - for(n = 15; n >= 0; n--){ + for(n = 15; n >= 0; n--) { tmp[n] = (char)(pattern & 0x01); pattern >>= 1; } /* compute the on/off pixel sequence */ n = 0; - for(i = 0; i < 8; i++){ - while(n < 16 && !tmp[n]){ off[i]++; n++; } - while(n < 16 && tmp[n]){ on[i]++; n++; } - if(n >= 15){ i++; break; } + for(i = 0; i < 8; i++) { + while(n < 16 && !tmp[n]) { + off[i]++; + n++; + } + while(n < 16 && tmp[n]) { + on[i]++; + n++; + } + if(n >= 15) { + i++; + break; + } } /* store the on/off array from right to left, starting with off @@ -3028,31 +3066,31 @@ static void gl2psParseStipplePattern(GLushort pattern, GLint factor, couples (our longest possible array is thus [on4 off4 on3 off3 on2 off2 on1 off1 on0 off0]) */ *nb = 0; - for(n = i - 1; n >= 0; n--){ + for(n = i - 1; n >= 0; n--) { array[(*nb)++] = factor * on[n]; array[(*nb)++] = factor * off[n]; if(*nb == 10) break; } } -static int gl2psPrintPostScriptDash(GLushort pattern, GLint factor, const char *str) +static int gl2psPrintPostScriptDash(GLushort pattern, GLint factor, + const char *str) { int len = 0, i, n, array[10]; - if(pattern == gl2ps->lastpattern && factor == gl2ps->lastfactor) - return 0; + if(pattern == gl2ps->lastpattern && factor == gl2ps->lastfactor) return 0; gl2ps->lastpattern = pattern; gl2ps->lastfactor = factor; - if(!pattern || !factor){ + if(!pattern || !factor) { /* solid line */ len += gl2psPrintf("[] 0 %s\n", str); } - else{ + else { gl2psParseStipplePattern(pattern, factor, &n, array); len += gl2psPrintf("["); - for(i = 0; i < n; i++){ + for(i = 0; i < n; i++) { if(i) len += gl2psPrintf(" "); len += gl2psPrintf("%d", array[i]); } @@ -3067,7 +3105,7 @@ static void gl2psPrintPostScriptPrimitive(void *data) int newline; GL2PSprimitive *prim; - prim = *(GL2PSprimitive**)data; + prim = *(GL2PSprimitive **)data; if((gl2ps->options & GL2PS_OCCLUSION_CULL) && prim->culled) return; @@ -3078,20 +3116,20 @@ static void gl2psPrintPostScriptPrimitive(void *data) finish the current line (if any): */ if(prim->type != GL2PS_LINE) gl2psEndPostScriptLine(); - switch(prim->type){ - case GL2PS_POINT : + switch(prim->type) { + case GL2PS_POINT: gl2psPrintPostScriptColor(prim->verts[0].rgba); - gl2psPrintf("%g %g %g P\n", - prim->verts[0].xyz[0], prim->verts[0].xyz[1], 0.5 * prim->width); + gl2psPrintf("%g %g %g P\n", prim->verts[0].xyz[0], prim->verts[0].xyz[1], + 0.5 * prim->width); break; - case GL2PS_LINE : + case GL2PS_LINE: if(!gl2psSamePosition(gl2ps->lastvertex.xyz, prim->verts[0].xyz) || !gl2psSameColor(gl2ps->lastrgba, prim->verts[0].rgba) || gl2ps->lastlinewidth != prim->width || gl2ps->lastlinecap != prim->linecap || gl2ps->lastlinejoin != prim->linejoin || gl2ps->lastpattern != prim->pattern || - gl2ps->lastfactor != prim->factor){ + gl2ps->lastfactor != prim->factor) { /* End the current line if the new segment does not start where the last one ended, or if the color, the width or the stippling have changed (multi-stroking lines with changing @@ -3101,18 +3139,18 @@ static void gl2psPrintPostScriptPrimitive(void *data) gl2psEndPostScriptLine(); newline = 1; } - else{ + else { newline = 0; } - if(gl2ps->lastlinewidth != prim->width){ + if(gl2ps->lastlinewidth != prim->width) { gl2ps->lastlinewidth = prim->width; gl2psPrintf("%g W\n", gl2ps->lastlinewidth); } - if(gl2ps->lastlinecap != prim->linecap){ + if(gl2ps->lastlinecap != prim->linecap) { gl2ps->lastlinecap = prim->linecap; gl2psPrintf("%d LC\n", gl2ps->lastlinecap); } - if(gl2ps->lastlinejoin != prim->linejoin){ + if(gl2ps->lastlinejoin != prim->linejoin) { gl2ps->lastlinejoin = prim->linejoin; gl2psPrintf("%d LJ\n", gl2ps->lastlinejoin); } @@ -3122,53 +3160,49 @@ static void gl2psPrintPostScriptPrimitive(void *data) newline ? "LS" : "L"); gl2ps->lastvertex = prim->verts[1]; break; - case GL2PS_TRIANGLE : - if(!gl2psVertsSameColor(prim)){ + case GL2PS_TRIANGLE: + if(!gl2psVertsSameColor(prim)) { gl2psResetPostScriptColor(); - gl2psPrintf("%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n", - prim->verts[2].xyz[0], prim->verts[2].xyz[1], - prim->verts[2].rgba[0], prim->verts[2].rgba[1], - prim->verts[2].rgba[2], prim->verts[1].xyz[0], - prim->verts[1].xyz[1], prim->verts[1].rgba[0], - prim->verts[1].rgba[1], prim->verts[1].rgba[2], - prim->verts[0].xyz[0], prim->verts[0].xyz[1], - prim->verts[0].rgba[0], prim->verts[0].rgba[1], - prim->verts[0].rgba[2]); + gl2psPrintf( + "%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n", + prim->verts[2].xyz[0], prim->verts[2].xyz[1], prim->verts[2].rgba[0], + prim->verts[2].rgba[1], prim->verts[2].rgba[2], prim->verts[1].xyz[0], + prim->verts[1].xyz[1], prim->verts[1].rgba[0], prim->verts[1].rgba[1], + prim->verts[1].rgba[2], prim->verts[0].xyz[0], prim->verts[0].xyz[1], + prim->verts[0].rgba[0], prim->verts[0].rgba[1], prim->verts[0].rgba[2]); } - else{ + else { gl2psPrintPostScriptColor(prim->verts[0].rgba); - gl2psPrintf("%g %g %g %g %g %g T\n", - prim->verts[2].xyz[0], prim->verts[2].xyz[1], - prim->verts[1].xyz[0], prim->verts[1].xyz[1], - prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + gl2psPrintf("%g %g %g %g %g %g T\n", prim->verts[2].xyz[0], + prim->verts[2].xyz[1], prim->verts[1].xyz[0], + prim->verts[1].xyz[1], prim->verts[0].xyz[0], + prim->verts[0].xyz[1]); } break; - case GL2PS_QUADRANGLE : + case GL2PS_QUADRANGLE: gl2psMsg(GL2PS_WARNING, "There should not be any quad left to print"); break; - case GL2PS_PIXMAP : + case GL2PS_PIXMAP: gl2psPrintPostScriptPixmap(prim->verts[0].xyz[0], prim->verts[0].xyz[1], prim->data.image); break; - case GL2PS_IMAGEMAP : - if(prim->data.image->type != GL2PS_IMAGEMAP_WRITTEN){ + case GL2PS_IMAGEMAP: + if(prim->data.image->type != GL2PS_IMAGEMAP_WRITTEN) { gl2psPrintPostScriptColor(prim->verts[0].rgba); - gl2psPrintPostScriptImagemap(prim->data.image->pixels[0], - prim->data.image->pixels[1], - prim->data.image->width, prim->data.image->height, - (const unsigned char*)(&(prim->data.image->pixels[2]))); + gl2psPrintPostScriptImagemap( + prim->data.image->pixels[0], prim->data.image->pixels[1], + prim->data.image->width, prim->data.image->height, + (const unsigned char *)(&(prim->data.image->pixels[2]))); prim->data.image->type = GL2PS_IMAGEMAP_WRITTEN; } break; - case GL2PS_TEXT : + case GL2PS_TEXT: gl2psPrintPostScriptColor(prim->verts[0].rgba); gl2psPrintf("(%s) ", prim->data.text->str); - if(prim->data.text->angle) - gl2psPrintf("%g ", prim->data.text->angle); - gl2psPrintf("%g %g %d /%s ", - prim->verts[0].xyz[0], prim->verts[0].xyz[1], + if(prim->data.text->angle) gl2psPrintf("%g ", prim->data.text->angle); + gl2psPrintf("%g %g %d /%s ", prim->verts[0].xyz[0], prim->verts[0].xyz[1], prim->data.text->fontsize, prim->data.text->fontname); - switch(prim->data.text->alignment){ + switch(prim->data.text->alignment) { case GL2PS_TEXT_C: gl2psPrintf(prim->data.text->angle ? "SCCR\n" : "SCC\n"); break; @@ -3194,20 +3228,17 @@ static void gl2psPrintPostScriptPrimitive(void *data) gl2psPrintf(prim->data.text->angle ? "STRR\n" : "STR\n"); break; case GL2PS_TEXT_BL: - default: - gl2psPrintf(prim->data.text->angle ? "SR\n" : "S\n"); - break; + default: gl2psPrintf(prim->data.text->angle ? "SR\n" : "S\n"); break; } break; - case GL2PS_SPECIAL : + case GL2PS_SPECIAL: /* alignment contains the format for which the special output text is intended */ if(prim->data.text->alignment == GL2PS_PS || prim->data.text->alignment == GL2PS_EPS) gl2psPrintf("%s\n", prim->data.text->str); break; - default : - break; + default: break; } } @@ -3232,7 +3263,7 @@ static void gl2psPrintPostScriptBeginViewport(GLint viewport[4]) glRenderMode(GL_FEEDBACK); - if(gl2ps->header){ + if(gl2ps->header) { gl2psPrintPostScriptHeader(); gl2ps->header = GL_FALSE; } @@ -3243,11 +3274,11 @@ static void gl2psPrintPostScriptBeginViewport(GLint viewport[4]) gl2psPrintf("gsave\n" "1.0 1.0 scale\n"); - if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ - if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){ + if(gl2ps->options & GL2PS_DRAW_BACKGROUND) { + if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0) { glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba); } - else{ + else { glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx); rgba[0] = gl2ps->colormap[idx][0]; rgba[1] = gl2ps->colormap[idx][1]; @@ -3257,14 +3288,13 @@ static void gl2psPrintPostScriptBeginViewport(GLint viewport[4]) gl2psPrintf("%g %g %g C\n" "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n" "closepath fill\n", - rgba[0], rgba[1], rgba[2], - x, y, x+w, y, x+w, y+h, x, y+h); + rgba[0], rgba[1], rgba[2], x, y, x + w, y, x + w, y + h, x, + y + h); } gl2psPrintf("newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n" "closepath clip\n", - x, y, x+w, y, x+w, y+h, x, y+h); - + x, y, x + w, y, x + w, y + h, x, y + h); } static GLint gl2psPrintPostScriptEndViewport(void) @@ -3284,27 +3314,23 @@ static void gl2psPrintPostScriptFinalPrimitive(void) /* definition of the PostScript and Encapsulated PostScript backends */ -static GL2PSbackend gl2psPS = { - gl2psPrintPostScriptHeader, - gl2psPrintPostScriptFooter, - gl2psPrintPostScriptBeginViewport, - gl2psPrintPostScriptEndViewport, - gl2psPrintPostScriptPrimitive, - gl2psPrintPostScriptFinalPrimitive, - "ps", - "Postscript" -}; - -static GL2PSbackend gl2psEPS = { - gl2psPrintPostScriptHeader, - gl2psPrintPostScriptFooter, - gl2psPrintPostScriptBeginViewport, - gl2psPrintPostScriptEndViewport, - gl2psPrintPostScriptPrimitive, - gl2psPrintPostScriptFinalPrimitive, - "eps", - "Encapsulated Postscript" -}; +static GL2PSbackend gl2psPS = {gl2psPrintPostScriptHeader, + gl2psPrintPostScriptFooter, + gl2psPrintPostScriptBeginViewport, + gl2psPrintPostScriptEndViewport, + gl2psPrintPostScriptPrimitive, + gl2psPrintPostScriptFinalPrimitive, + "ps", + "Postscript"}; + +static GL2PSbackend gl2psEPS = {gl2psPrintPostScriptHeader, + gl2psPrintPostScriptFooter, + gl2psPrintPostScriptBeginViewport, + gl2psPrintPostScriptEndViewport, + gl2psPrintPostScriptPrimitive, + gl2psPrintPostScriptFinalPrimitive, + "eps", + "Encapsulated Postscript"}; /********************************************************************* * @@ -3318,9 +3344,9 @@ static void gl2psPrintTeXHeader(void) time_t now; int i; - if(gl2ps->filename && strlen(gl2ps->filename) < 256){ - for(i = (int)strlen(gl2ps->filename) - 1; i >= 0; i--){ - if(gl2ps->filename[i] == '.'){ + if(gl2ps->filename && strlen(gl2ps->filename) < 256) { + for(i = (int)strlen(gl2ps->filename) - 1; i >= 0; i--) { + if(gl2ps->filename[i] == '.') { strncpy(name, gl2ps->filename, i); name[i] = '\0'; break; @@ -3328,7 +3354,7 @@ static void gl2psPrintTeXHeader(void) } if(i <= 0) strcpy(name, gl2ps->filename); } - else{ + else { strcpy(name, "untitled"); } @@ -3357,62 +3383,42 @@ static void gl2psPrintTeXPrimitive(void *data) { GL2PSprimitive *prim; - prim = *(GL2PSprimitive**)data; + prim = *(GL2PSprimitive **)data; - switch(prim->type){ - case GL2PS_TEXT : + switch(prim->type) { + case GL2PS_TEXT: fprintf(gl2ps->stream, "\\fontsize{%d}{0}\n\\selectfont", prim->data.text->fontsize); - fprintf(gl2ps->stream, "\\put(%g,%g)", - prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + fprintf(gl2ps->stream, "\\put(%g,%g)", prim->verts[0].xyz[0], + prim->verts[0].xyz[1]); if(prim->data.text->angle) fprintf(gl2ps->stream, "{\\rotatebox{%g}", prim->data.text->angle); fprintf(gl2ps->stream, "{\\makebox(0,0)"); - switch(prim->data.text->alignment){ - case GL2PS_TEXT_C: - fprintf(gl2ps->stream, "{"); - break; - case GL2PS_TEXT_CL: - fprintf(gl2ps->stream, "[l]{"); - break; - case GL2PS_TEXT_CR: - fprintf(gl2ps->stream, "[r]{"); - break; - case GL2PS_TEXT_B: - fprintf(gl2ps->stream, "[b]{"); - break; - case GL2PS_TEXT_BR: - fprintf(gl2ps->stream, "[br]{"); - break; - case GL2PS_TEXT_T: - fprintf(gl2ps->stream, "[t]{"); - break; - case GL2PS_TEXT_TL: - fprintf(gl2ps->stream, "[tl]{"); - break; - case GL2PS_TEXT_TR: - fprintf(gl2ps->stream, "[tr]{"); - break; + switch(prim->data.text->alignment) { + case GL2PS_TEXT_C: fprintf(gl2ps->stream, "{"); break; + case GL2PS_TEXT_CL: fprintf(gl2ps->stream, "[l]{"); break; + case GL2PS_TEXT_CR: fprintf(gl2ps->stream, "[r]{"); break; + case GL2PS_TEXT_B: fprintf(gl2ps->stream, "[b]{"); break; + case GL2PS_TEXT_BR: fprintf(gl2ps->stream, "[br]{"); break; + case GL2PS_TEXT_T: fprintf(gl2ps->stream, "[t]{"); break; + case GL2PS_TEXT_TL: fprintf(gl2ps->stream, "[tl]{"); break; + case GL2PS_TEXT_TR: fprintf(gl2ps->stream, "[tr]{"); break; case GL2PS_TEXT_BL: - default: - fprintf(gl2ps->stream, "[bl]{"); - break; + default: fprintf(gl2ps->stream, "[bl]{"); break; } fprintf(gl2ps->stream, "\\textcolor[rgb]{%g,%g,%g}{{%s}}", - prim->verts[0].rgba[0], prim->verts[0].rgba[1], prim->verts[0].rgba[2], - prim->data.text->str); - if(prim->data.text->angle) - fprintf(gl2ps->stream, "}"); + prim->verts[0].rgba[0], prim->verts[0].rgba[1], + prim->verts[0].rgba[2], prim->data.text->str); + if(prim->data.text->angle) fprintf(gl2ps->stream, "}"); fprintf(gl2ps->stream, "}}\n"); break; - case GL2PS_SPECIAL : + case GL2PS_SPECIAL: /* alignment contains the format for which the special output text is intended */ - if (prim->data.text->alignment == GL2PS_TEX) + if(prim->data.text->alignment == GL2PS_TEX) fprintf(gl2ps->stream, "%s\n", prim->data.text->str); break; - default : - break; + default: break; } } @@ -3424,38 +3430,31 @@ static void gl2psPrintTeXFooter(void) static void gl2psPrintTeXBeginViewport(GLint viewport[4]) { - (void) viewport; /* not used */ + (void)viewport; /* not used */ glRenderMode(GL_FEEDBACK); gl2psResetLineProperties(); - if(gl2ps->header){ + if(gl2ps->header) { gl2psPrintTeXHeader(); gl2ps->header = GL_FALSE; } } -static GLint gl2psPrintTeXEndViewport(void) -{ - return gl2psPrintPrimitives(); -} +static GLint gl2psPrintTeXEndViewport(void) { return gl2psPrintPrimitives(); } -static void gl2psPrintTeXFinalPrimitive(void) -{ -} +static void gl2psPrintTeXFinalPrimitive(void) {} /* definition of the LaTeX backend */ -static GL2PSbackend gl2psTEX = { - gl2psPrintTeXHeader, - gl2psPrintTeXFooter, - gl2psPrintTeXBeginViewport, - gl2psPrintTeXEndViewport, - gl2psPrintTeXPrimitive, - gl2psPrintTeXFinalPrimitive, - "tex", - "LaTeX text" -}; +static GL2PSbackend gl2psTEX = {gl2psPrintTeXHeader, + gl2psPrintTeXFooter, + gl2psPrintTeXBeginViewport, + gl2psPrintTeXEndViewport, + gl2psPrintTeXPrimitive, + gl2psPrintTeXFinalPrimitive, + "tex", + "LaTeX text"}; /********************************************************************* * @@ -3466,7 +3465,7 @@ static GL2PSbackend gl2psTEX = { static int gl2psPrintPDFCompressorType(void) { #if defined(GL2PS_HAVE_ZLIB) - if(gl2ps->options & GL2PS_COMPRESS){ + if(gl2ps->options & GL2PS_COMPRESS) { return fprintf(gl2ps->stream, "/Filter [/FlateDecode]\n"); } #endif @@ -3478,7 +3477,7 @@ static int gl2psPrintPDFStrokeColor(GL2PSrgba rgba) int i, offs = 0; gl2psSetLastColor(rgba); - for(i = 0; i < 3; ++i){ + for(i = 0; i < 3; ++i) { if(GL2PS_ZERO(rgba[i])) offs += gl2psPrintf("%.0f ", 0.); else if(rgba[i] < 1e-4 || rgba[i] > 1e6) /* avoid %e formatting */ @@ -3494,7 +3493,7 @@ static int gl2psPrintPDFFillColor(GL2PSrgba rgba) { int i, offs = 0; - for(i = 0; i < 3; ++i){ + for(i = 0; i < 3; ++i) { if(GL2PS_ZERO(rgba[i])) offs += gl2psPrintf("%.0f ", 0.); else if(rgba[i] < 1e-4 || rgba[i] > 1e6) /* avoid %e formatting */ @@ -3536,26 +3535,25 @@ static void gl2psPutPDFText(GL2PSstring *text, int cnt, GLfloat x, GLfloat y) { GLfloat rad, crad, srad; - if(text->angle == 0.0F){ - gl2ps->streamlength += gl2psPrintf - ("BT\n" - "/F%d %d Tf\n" - "%f %f Td\n" - "(%s) Tj\n" - "ET\n", - cnt, text->fontsize, x, y, text->str); + if(text->angle == 0.0F) { + gl2ps->streamlength += gl2psPrintf("BT\n" + "/F%d %d Tf\n" + "%f %f Td\n" + "(%s) Tj\n" + "ET\n", + cnt, text->fontsize, x, y, text->str); } - else{ + else { rad = (GLfloat)(3.141593F * text->angle / 180.0F); srad = (GLfloat)sin(rad); crad = (GLfloat)cos(rad); - gl2ps->streamlength += gl2psPrintf - ("BT\n" - "/F%d %d Tf\n" - "%f %f %f %f %f %f Tm\n" - "(%s) Tj\n" - "ET\n", - cnt, text->fontsize, crad, srad, -srad, crad, x, y, text->str); + gl2ps->streamlength += gl2psPrintf("BT\n" + "/F%d %d Tf\n" + "%f %f %f %f %f %f Tm\n" + "(%s) Tj\n" + "ET\n", + cnt, text->fontsize, crad, srad, -srad, + crad, x, y, text->str); } } @@ -3567,13 +3565,13 @@ static void gl2psPutPDFSpecial(int prim, int sec, GL2PSstring *text) static void gl2psPutPDFImage(GL2PSimage *image, int cnt, GLfloat x, GLfloat y) { - gl2ps->streamlength += gl2psPrintf - ("q\n" - "%d 0 0 %d %f %f cm\n" - "/Im%d Do\n" - "Q\n", - (int)(image->zoom_x * image->width), (int)(image->zoom_y * image->height), - x, y, cnt); + gl2ps->streamlength += + gl2psPrintf("q\n" + "%d 0 0 %d %f %f cm\n" + "/Im%d Do\n" + "Q\n", + (int)(image->zoom_x * image->width), + (int)(image->zoom_y * image->height), x, y, cnt); } static void gl2psPDFstacksInit(void) @@ -3589,13 +3587,12 @@ static void gl2psPDFstacksInit(void) static void gl2psPDFgroupObjectInit(GL2PSpdfgroup *gro) { - if(!gro) - return; + if(!gro) return; gro->ptrlist = NULL; - gro->fontno = gro->gsno = gro->imno = gro->maskshno = gro->shno - = gro->trgroupno = gro->fontobjno = gro->imobjno = gro->shobjno - = gro->maskshobjno = gro->gsobjno = gro->trgroupobjno = -1; + gro->fontno = gro->gsno = gro->imno = gro->maskshno = gro->shno = + gro->trgroupno = gro->fontobjno = gro->imobjno = gro->shobjno = + gro->maskshobjno = gro->gsobjno = gro->trgroupobjno = -1; } /* Build up group objects and assign name and object numbers */ @@ -3615,25 +3612,24 @@ static void gl2psPDFgroupListInit(void) GL2PStriangle lastt, tmpt; int lastTriangleWasNotSimpleWithSameColor = 0; - if(!gl2ps->pdfprimlist) - return; + if(!gl2ps->pdfprimlist) return; gl2ps->pdfgrouplist = gl2psListCreate(500, 500, sizeof(GL2PSpdfgroup)); gl2psInitTriangle(&lastt); - for(i = 0; i < gl2psListNbr(gl2ps->pdfprimlist); ++i){ - p = *(GL2PSprimitive**)gl2psListPointer(gl2ps->pdfprimlist, i); - switch(p->type){ + for(i = 0; i < gl2psListNbr(gl2ps->pdfprimlist); ++i) { + p = *(GL2PSprimitive **)gl2psListPointer(gl2ps->pdfprimlist, i); + switch(p->type) { case GL2PS_PIXMAP: gl2psPDFgroupObjectInit(&gro); - gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); gro.imno = gl2ps->im_stack++; gl2psListAdd(gro.ptrlist, &p); gl2psListAdd(gl2ps->pdfgrouplist, &gro); break; case GL2PS_TEXT: gl2psPDFgroupObjectInit(&gro); - gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); gro.fontno = gl2ps->font_stack++; gl2psListAdd(gro.ptrlist, &p); gl2psListAdd(gl2ps->pdfgrouplist, &gro); @@ -3642,13 +3638,13 @@ static void gl2psPDFgroupListInit(void) if(lasttype != p->type || lastwidth != p->width || lastlinecap != p->linecap || lastlinejoin != p->linejoin || lastpattern != p->pattern || lastfactor != p->factor || - !gl2psSameColor(p->verts[0].rgba, lastrgba)){ + !gl2psSameColor(p->verts[0].rgba, lastrgba)) { gl2psPDFgroupObjectInit(&gro); - gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); gl2psListAdd(gro.ptrlist, &p); gl2psListAdd(gl2ps->pdfgrouplist, &gro); } - else{ + else { gl2psListAdd(gro.ptrlist, &p); } lastpattern = p->pattern; @@ -3662,13 +3658,13 @@ static void gl2psPDFgroupListInit(void) break; case GL2PS_POINT: if(lasttype != p->type || lastwidth != p->width || - !gl2psSameColor(p->verts[0].rgba, lastrgba)){ + !gl2psSameColor(p->verts[0].rgba, lastrgba)) { gl2psPDFgroupObjectInit(&gro); - gro.ptrlist = gl2psListCreate(1,2,sizeof(GL2PSprimitive*)); + gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); gl2psListAdd(gro.ptrlist, &p); gl2psListAdd(gl2ps->pdfgrouplist, &gro); } - else{ + else { gl2psListAdd(gro.ptrlist, &p); } lastwidth = p->width; @@ -3682,13 +3678,13 @@ static void gl2psPDFgroupListInit(void) !(tmpt.prop & T_CONST_COLOR && tmpt.prop & T_ALPHA_1) || !gl2psSameColor(tmpt.vertex[0].rgba, lastt.vertex[0].rgba); if(lasttype == p->type && tmpt.prop == lastt.prop && - lastTriangleWasNotSimpleWithSameColor){ + lastTriangleWasNotSimpleWithSameColor) { /* TODO Check here for last alpha */ gl2psListAdd(gro.ptrlist, &p); } - else{ + else { gl2psPDFgroupObjectInit(&gro); - gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); gl2psListAdd(gro.ptrlist, &p); gl2psListAdd(gl2ps->pdfgrouplist, &gro); } @@ -3696,12 +3692,11 @@ static void gl2psPDFgroupListInit(void) break; case GL2PS_SPECIAL: gl2psPDFgroupObjectInit(&gro); - gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive*)); + gro.ptrlist = gl2psListCreate(1, 2, sizeof(GL2PSprimitive *)); gl2psListAdd(gro.ptrlist, &p); gl2psListAdd(gl2ps->pdfgrouplist, &gro); break; - default: - break; + default: break; } lasttype = p->type; } @@ -3712,24 +3707,21 @@ static void gl2psSortOutTrianglePDFgroup(GL2PSpdfgroup *gro) GL2PStriangle t; GL2PSprimitive *prim = NULL; - if(!gro) - return; + if(!gro) return; - if(!gl2psListNbr(gro->ptrlist)) - return; + if(!gl2psListNbr(gro->ptrlist)) return; - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, 0); + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, 0); - if(prim->type != GL2PS_TRIANGLE) - return; + if(prim->type != GL2PS_TRIANGLE) return; gl2psFillTriangleFromPrimitive(&t, prim, GL_TRUE); - if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_LESS_1){ + if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_LESS_1) { gro->gsno = gl2ps->extgs_stack++; - gro->gsobjno = gl2ps->objects_stack ++; + gro->gsobjno = gl2ps->objects_stack++; } - else if(t.prop & T_CONST_COLOR && t.prop & T_VAR_ALPHA){ + else if(t.prop & T_CONST_COLOR && t.prop & T_VAR_ALPHA) { gro->gsno = gl2ps->extgs_stack++; gro->gsobjno = gl2ps->objects_stack++; gro->trgroupno = gl2ps->trgroupobjects_stack++; @@ -3737,17 +3729,17 @@ static void gl2psSortOutTrianglePDFgroup(GL2PSpdfgroup *gro) gro->maskshno = gl2ps->mshader_stack++; gro->maskshobjno = gl2ps->objects_stack++; } - else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_1){ + else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_1) { gro->shno = gl2ps->shader_stack++; gro->shobjno = gl2ps->objects_stack++; } - else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_LESS_1){ + else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_LESS_1) { gro->gsno = gl2ps->extgs_stack++; gro->gsobjno = gl2ps->objects_stack++; gro->shno = gl2ps->shader_stack++; gro->shobjno = gl2ps->objects_stack++; } - else if(t.prop & T_VAR_COLOR && t.prop & T_VAR_ALPHA){ + else if(t.prop & T_VAR_COLOR && t.prop & T_VAR_ALPHA) { gro->gsno = gl2ps->extgs_stack++; gro->gsobjno = gl2ps->objects_stack++; gro->shno = gl2ps->shader_stack++; @@ -3768,31 +3760,28 @@ static void gl2psPDFgroupListWriteMainStream(void) GL2PSpdfgroup *gro; GL2PStriangle t; - if(!gl2ps->pdfgrouplist) - return; + if(!gl2ps->pdfgrouplist) return; count = gl2psListNbr(gl2ps->pdfgrouplist); - for(i = 0; i < count; ++i){ - gro = (GL2PSpdfgroup*)gl2psListPointer(gl2ps->pdfgrouplist, i); + for(i = 0; i < count; ++i) { + gro = (GL2PSpdfgroup *)gl2psListPointer(gl2ps->pdfgrouplist, i); lastel = gl2psListNbr(gro->ptrlist) - 1; - if(lastel < 0) - continue; + if(lastel < 0) continue; - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, 0); + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, 0); - switch(prim->type){ + switch(prim->type) { case GL2PS_POINT: gl2ps->streamlength += gl2psPrintf("1 J\n"); gl2ps->streamlength += gl2psPrintPDFLineWidth(prim->width); gl2ps->streamlength += gl2psPrintPDFStrokeColor(prim->verts[0].rgba); - for(j = 0; j <= lastel; ++j){ - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); - gl2ps->streamlength += - gl2psPrintf("%f %f m %f %f l\n", - prim->verts[0].xyz[0], prim->verts[0].xyz[1], - prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + for(j = 0; j <= lastel; ++j) { + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); + gl2ps->streamlength += gl2psPrintf( + "%f %f m %f %f l\n", prim->verts[0].xyz[0], prim->verts[0].xyz[1], + prim->verts[0].xyz[0], prim->verts[0].xyz[1]); } gl2ps->streamlength += gl2psPrintf("S\n"); gl2ps->streamlength += gl2psPrintf("0 J\n"); @@ -3805,38 +3794,34 @@ static void gl2psPDFgroupListWriteMainStream(void) gl2ps->streamlength += gl2psPrintPDFLineCap(prim->linecap); gl2ps->streamlength += gl2psPrintPDFLineJoin(prim->linejoin); gl2ps->streamlength += gl2psPrintPDFStrokeColor(prim->verts[0].rgba); - gl2ps->streamlength += gl2psPrintPostScriptDash(prim->pattern, prim->factor, "d"); + gl2ps->streamlength += + gl2psPrintPostScriptDash(prim->pattern, prim->factor, "d"); /* start new path */ gl2ps->streamlength += - gl2psPrintf("%f %f m\n", - prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + gl2psPrintf("%f %f m\n", prim->verts[0].xyz[0], prim->verts[0].xyz[1]); - for(j = 1; j <= lastel; ++j){ + for(j = 1; j <= lastel; ++j) { prev = prim; - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); - if(!gl2psSamePosition(prim->verts[0].xyz, prev->verts[1].xyz)){ + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); + if(!gl2psSamePosition(prim->verts[0].xyz, prev->verts[1].xyz)) { /* the starting point of the new segment does not match the end point of the previous line, so we end the current path and start a new one */ - gl2ps->streamlength += - gl2psPrintf("%f %f l\n", - prev->verts[1].xyz[0], prev->verts[1].xyz[1]); - gl2ps->streamlength += - gl2psPrintf("%f %f m\n", - prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + gl2ps->streamlength += gl2psPrintf("%f %f l\n", prev->verts[1].xyz[0], + prev->verts[1].xyz[1]); + gl2ps->streamlength += gl2psPrintf("%f %f m\n", prim->verts[0].xyz[0], + prim->verts[0].xyz[1]); } - else{ + else { /* the two segements are connected, so we just append to the current path */ - gl2ps->streamlength += - gl2psPrintf("%f %f l\n", - prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + gl2ps->streamlength += gl2psPrintf("%f %f l\n", prim->verts[0].xyz[0], + prim->verts[0].xyz[1]); } } /* end last path */ gl2ps->streamlength += - gl2psPrintf("%f %f l\n", - prim->verts[1].xyz[0], prim->verts[1].xyz[1]); + gl2psPrintf("%f %f l\n", prim->verts[1].xyz[0], prim->verts[1].xyz[1]); gl2ps->streamlength += gl2psPrintf("S\n"); break; case GL2PS_TRIANGLE: @@ -3844,74 +3829,71 @@ static void gl2psPDFgroupListWriteMainStream(void) gl2psSortOutTrianglePDFgroup(gro); /* No alpha and const color: Simple PDF draw orders */ - if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_1){ + if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_1) { gl2ps->streamlength += gl2psPrintPDFFillColor(t.vertex[0].rgba); - for(j = 0; j <= lastel; ++j){ - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); + for(j = 0; j <= lastel; ++j) { + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); gl2psFillTriangleFromPrimitive(&t, prim, GL_FALSE); - gl2ps->streamlength - += gl2psPrintf("%f %f m\n" - "%f %f l\n" - "%f %f l\n" - "h f\n", - t.vertex[0].xyz[0], t.vertex[0].xyz[1], - t.vertex[1].xyz[0], t.vertex[1].xyz[1], - t.vertex[2].xyz[0], t.vertex[2].xyz[1]); + gl2ps->streamlength += gl2psPrintf( + "%f %f m\n" + "%f %f l\n" + "%f %f l\n" + "h f\n", + t.vertex[0].xyz[0], t.vertex[0].xyz[1], t.vertex[1].xyz[0], + t.vertex[1].xyz[1], t.vertex[2].xyz[0], t.vertex[2].xyz[1]); } } /* Const alpha < 1 and const color: Simple PDF draw orders and an extra extended Graphics State for the alpha const */ - else if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_LESS_1){ + else if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_LESS_1) { gl2ps->streamlength += gl2psPrintf("q\n" "/GS%d gs\n", gro->gsno); gl2ps->streamlength += gl2psPrintPDFFillColor(prim->verts[0].rgba); - for(j = 0; j <= lastel; ++j){ - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); + for(j = 0; j <= lastel; ++j) { + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); gl2psFillTriangleFromPrimitive(&t, prim, GL_FALSE); - gl2ps->streamlength - += gl2psPrintf("%f %f m\n" - "%f %f l\n" - "%f %f l\n" - "h f\n", - t.vertex[0].xyz[0], t.vertex[0].xyz[1], - t.vertex[1].xyz[0], t.vertex[1].xyz[1], - t.vertex[2].xyz[0], t.vertex[2].xyz[1]); + gl2ps->streamlength += gl2psPrintf( + "%f %f m\n" + "%f %f l\n" + "%f %f l\n" + "h f\n", + t.vertex[0].xyz[0], t.vertex[0].xyz[1], t.vertex[1].xyz[0], + t.vertex[1].xyz[1], t.vertex[2].xyz[0], t.vertex[2].xyz[1]); } gl2ps->streamlength += gl2psPrintf("Q\n"); } /* Variable alpha and const color: Simple PDF draw orders and an extra extended Graphics State + Xobject + Shader object for the alpha mask */ - else if(t.prop & T_CONST_COLOR && t.prop & T_VAR_ALPHA){ + else if(t.prop & T_CONST_COLOR && t.prop & T_VAR_ALPHA) { gl2ps->streamlength += gl2psPrintf("q\n" "/GS%d gs\n" "/TrG%d Do\n", gro->gsno, gro->trgroupno); gl2ps->streamlength += gl2psPrintPDFFillColor(prim->verts[0].rgba); - for(j = 0; j <= lastel; ++j){ - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); + for(j = 0; j <= lastel; ++j) { + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); gl2psFillTriangleFromPrimitive(&t, prim, GL_FALSE); - gl2ps->streamlength - += gl2psPrintf("%f %f m\n" - "%f %f l\n" - "%f %f l\n" - "h f\n", - t.vertex[0].xyz[0], t.vertex[0].xyz[1], - t.vertex[1].xyz[0], t.vertex[1].xyz[1], - t.vertex[2].xyz[0], t.vertex[2].xyz[1]); + gl2ps->streamlength += gl2psPrintf( + "%f %f m\n" + "%f %f l\n" + "%f %f l\n" + "h f\n", + t.vertex[0].xyz[0], t.vertex[0].xyz[1], t.vertex[1].xyz[0], + t.vertex[1].xyz[1], t.vertex[2].xyz[0], t.vertex[2].xyz[1]); } gl2ps->streamlength += gl2psPrintf("Q\n"); } /* Variable color and no alpha: Shader Object for the colored triangle(s) */ - else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_1){ + else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_1) { gl2ps->streamlength += gl2psPrintf("/Sh%d sh\n", gro->shno); } /* Variable color and const alpha < 1: Shader Object for the colored triangle(s) and an extra extended Graphics State for the alpha const */ - else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_LESS_1){ + else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_LESS_1) { gl2ps->streamlength += gl2psPrintf("q\n" "/GS%d gs\n" "/Sh%d sh\n" @@ -3921,25 +3903,26 @@ static void gl2psPDFgroupListWriteMainStream(void) /* Variable alpha and color: Shader Object for the colored triangle(s) and an extra extended Graphics State + Xobject + Shader object for the alpha mask */ - else if(t.prop & T_VAR_COLOR && t.prop & T_VAR_ALPHA){ - gl2ps->streamlength += gl2psPrintf("q\n" - "/GS%d gs\n" - "/TrG%d Do\n" - "/Sh%d sh\n" - "Q\n", - gro->gsno, gro->trgroupno, gro->shno); + else if(t.prop & T_VAR_COLOR && t.prop & T_VAR_ALPHA) { + gl2ps->streamlength += + gl2psPrintf("q\n" + "/GS%d gs\n" + "/TrG%d Do\n" + "/Sh%d sh\n" + "Q\n", + gro->gsno, gro->trgroupno, gro->shno); } break; case GL2PS_PIXMAP: - for(j = 0; j <= lastel; ++j){ - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); + for(j = 0; j <= lastel; ++j) { + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); gl2psPutPDFImage(prim->data.image, gro->imno, prim->verts[0].xyz[0], prim->verts[0].xyz[1]); } break; case GL2PS_TEXT: - for(j = 0; j <= lastel; ++j){ - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); + for(j = 0; j <= lastel; ++j) { + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); gl2ps->streamlength += gl2psPrintPDFFillColor(prim->verts[0].rgba); gl2psPutPDFText(prim->data.text, gro->fontno, prim->verts[0].xyz[0], prim->verts[0].xyz[1]); @@ -3947,15 +3930,13 @@ static void gl2psPDFgroupListWriteMainStream(void) break; case GL2PS_SPECIAL: lastel = gl2psListNbr(gro->ptrlist) - 1; - if(lastel < 0) - continue; + if(lastel < 0) continue; - for(j = 0; j <= lastel; ++j){ - prim = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); + for(j = 0; j <= lastel; ++j) { + prim = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); gl2psPutPDFSpecial(i, j, prim->data.text); } - default: - break; + default: break; } } } @@ -3968,12 +3949,11 @@ static int gl2psPDFgroupListWriteGStateResources(void) int offs = 0; int i; - offs += fprintf(gl2ps->stream, - "/ExtGState\n" - "<<\n" - "/GSa 7 0 R\n"); - for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i){ - gro = (GL2PSpdfgroup*)gl2psListPointer(gl2ps->pdfgrouplist, i); + offs += fprintf(gl2ps->stream, "/ExtGState\n" + "<<\n" + "/GSa 7 0 R\n"); + for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i) { + gro = (GL2PSpdfgroup *)gl2psListPointer(gl2ps->pdfgrouplist, i); if(gro->gsno >= 0) offs += fprintf(gl2ps->stream, "/GS%d %d 0 R\n", gro->gsno, gro->gsobjno); } @@ -3989,17 +3969,17 @@ static int gl2psPDFgroupListWriteShaderResources(void) int offs = 0; int i; - offs += fprintf(gl2ps->stream, - "/Shading\n" - "<<\n"); - for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i){ - gro = (GL2PSpdfgroup*)gl2psListPointer(gl2ps->pdfgrouplist, i); + offs += fprintf(gl2ps->stream, "/Shading\n" + "<<\n"); + for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i) { + gro = (GL2PSpdfgroup *)gl2psListPointer(gl2ps->pdfgrouplist, i); if(gro->shno >= 0) offs += fprintf(gl2ps->stream, "/Sh%d %d 0 R\n", gro->shno, gro->shobjno); if(gro->maskshno >= 0) - offs += fprintf(gl2ps->stream, "/TrSh%d %d 0 R\n", gro->maskshno, gro->maskshobjno); + offs += fprintf(gl2ps->stream, "/TrSh%d %d 0 R\n", gro->maskshno, + gro->maskshobjno); } - offs += fprintf(gl2ps->stream,">>\n"); + offs += fprintf(gl2ps->stream, ">>\n"); return offs; } @@ -4011,30 +3991,29 @@ static int gl2psPDFgroupListWriteXObjectResources(void) GL2PSpdfgroup *gro; int offs = 0; - offs += fprintf(gl2ps->stream, - "/XObject\n" - "<<\n"); - - for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i){ - gro = (GL2PSpdfgroup*)gl2psListPointer(gl2ps->pdfgrouplist, i); - if(!gl2psListNbr(gro->ptrlist)) - continue; - p = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, 0); - switch(p->type){ + offs += fprintf(gl2ps->stream, "/XObject\n" + "<<\n"); + + for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i) { + gro = (GL2PSpdfgroup *)gl2psListPointer(gl2ps->pdfgrouplist, i); + if(!gl2psListNbr(gro->ptrlist)) continue; + p = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, 0); + switch(p->type) { case GL2PS_PIXMAP: gro->imobjno = gl2ps->objects_stack++; - if(GL_RGBA == p->data.image->format) /* reserve one object for image mask */ + if(GL_RGBA == + p->data.image->format) /* reserve one object for image mask */ gl2ps->objects_stack++; offs += fprintf(gl2ps->stream, "/Im%d %d 0 R\n", gro->imno, gro->imobjno); case GL2PS_TRIANGLE: - if(gro->trgroupno >=0) - offs += fprintf(gl2ps->stream, "/TrG%d %d 0 R\n", gro->trgroupno, gro->trgroupobjno); - break; - default: + if(gro->trgroupno >= 0) + offs += fprintf(gl2ps->stream, "/TrG%d %d 0 R\n", gro->trgroupno, + gro->trgroupobjno); break; + default: break; } } - offs += fprintf(gl2ps->stream,">>\n"); + offs += fprintf(gl2ps->stream, ">>\n"); return offs; } @@ -4048,12 +4027,12 @@ static int gl2psPDFgroupListWriteFontResources(void) offs += fprintf(gl2ps->stream, "/Font\n<<\n"); - for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i){ - gro = (GL2PSpdfgroup*)gl2psListPointer(gl2ps->pdfgrouplist, i); - if(gro->fontno < 0) - continue; + for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i) { + gro = (GL2PSpdfgroup *)gl2psListPointer(gl2ps->pdfgrouplist, i); + if(gro->fontno < 0) continue; gro->fontobjno = gl2ps->objects_stack++; - offs += fprintf(gl2ps->stream, "/F%d %d 0 R\n", gro->fontno, gro->fontobjno); + offs += + fprintf(gl2ps->stream, "/F%d %d 0 R\n", gro->fontno, gro->fontobjno); } offs += fprintf(gl2ps->stream, ">>\n"); @@ -4065,11 +4044,10 @@ static void gl2psPDFgroupListDelete(void) int i; GL2PSpdfgroup *gro = NULL; - if(!gl2ps->pdfgrouplist) - return; + if(!gl2ps->pdfgrouplist) return; - for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i){ - gro = (GL2PSpdfgroup*)gl2psListPointer(gl2ps->pdfgrouplist,i); + for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i) { + gro = (GL2PSpdfgroup *)gl2psListPointer(gl2ps->pdfgrouplist, i); gl2psListDelete(gro->ptrlist); } @@ -4098,23 +4076,19 @@ static int gl2psPrintPDFInfo(void) GL2PS_PATCH_VERSION, GL2PS_EXTRA_VERSION, GL2PS_COPYRIGHT, gl2ps->producer); - if(!newtime){ - offs += fprintf(gl2ps->stream, - ">>\n" - "endobj\n"); + if(!newtime) { + offs += fprintf(gl2ps->stream, ">>\n" + "endobj\n"); return offs; } - offs += fprintf(gl2ps->stream, - "/CreationDate (D:%d%02d%02d%02d%02d%02d)\n" - ">>\n" - "endobj\n", - newtime->tm_year+1900, - newtime->tm_mon+1, - newtime->tm_mday, - newtime->tm_hour, - newtime->tm_min, - newtime->tm_sec); + offs += + fprintf(gl2ps->stream, + "/CreationDate (D:%d%02d%02d%02d%02d%02d)\n" + ">>\n" + "endobj\n", + newtime->tm_year + 1900, newtime->tm_mon + 1, newtime->tm_mday, + newtime->tm_hour, newtime->tm_min, newtime->tm_sec); return offs; } @@ -4122,25 +4096,23 @@ static int gl2psPrintPDFInfo(void) static int gl2psPrintPDFCatalog(void) { - return fprintf(gl2ps->stream, - "2 0 obj\n" - "<<\n" - "/Type /Catalog\n" - "/Pages 3 0 R\n" - ">>\n" - "endobj\n"); + return fprintf(gl2ps->stream, "2 0 obj\n" + "<<\n" + "/Type /Catalog\n" + "/Pages 3 0 R\n" + ">>\n" + "endobj\n"); } static int gl2psPrintPDFPages(void) { - return fprintf(gl2ps->stream, - "3 0 obj\n" - "<<\n" - "/Type /Pages\n" - "/Kids [6 0 R]\n" - "/Count 1\n" - ">>\n" - "endobj\n"); + return fprintf(gl2ps->stream, "3 0 obj\n" + "<<\n" + "/Type /Pages\n" + "/Kids [6 0 R]\n" + "/Count 1\n" + ">>\n" + "endobj\n"); } /* Open stream for data - graphical objects, fonts etc. PDF object 4 */ @@ -4149,14 +4121,12 @@ static int gl2psOpenPDFDataStream(void) { int offs = 0; - offs += fprintf(gl2ps->stream, - "4 0 obj\n" - "<<\n" - "/Length 5 0 R\n" ); + offs += fprintf(gl2ps->stream, "4 0 obj\n" + "<<\n" + "/Length 5 0 R\n"); offs += gl2psPrintPDFCompressorType(); - offs += fprintf(gl2ps->stream, - ">>\n" - "stream\n"); + offs += fprintf(gl2ps->stream, ">>\n" + "stream\n"); return offs; } @@ -4168,11 +4138,11 @@ static int gl2psOpenPDFDataStreamWritePreface(void) offs = gl2psPrintf("/GSa gs\n"); - if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ + if(gl2ps->options & GL2PS_DRAW_BACKGROUND) { offs += gl2psPrintPDFFillColor(gl2ps->bgcolor); - offs += gl2psPrintf("%d %d %d %d re\n", - (int)gl2ps->viewport[0], (int)gl2ps->viewport[1], - (int)gl2ps->viewport[2], (int)gl2ps->viewport[3]); + offs += gl2psPrintf("%d %d %d %d re\n", (int)gl2ps->viewport[0], + (int)gl2ps->viewport[1], (int)gl2ps->viewport[2], + (int)gl2ps->viewport[3]); offs += gl2psPrintf("f\n"); } return offs; @@ -4183,13 +4153,13 @@ static int gl2psOpenPDFDataStreamWritePreface(void) static void gl2psPrintPDFHeader(void) { int offs = 0; - gl2ps->pdfprimlist = gl2psListCreate(500, 500, sizeof(GL2PSprimitive*)); + gl2ps->pdfprimlist = gl2psListCreate(500, 500, sizeof(GL2PSprimitive *)); gl2psPDFstacksInit(); - gl2ps->xreflist = (int*)gl2psMalloc(sizeof(int) * gl2ps->objects_stack); + gl2ps->xreflist = (int *)gl2psMalloc(sizeof(int) * gl2ps->objects_stack); #if defined(GL2PS_HAVE_ZLIB) - if(gl2ps->options & GL2PS_COMPRESS){ + if(gl2ps->options & GL2PS_COMPRESS) { gl2psSetupCompress(); } #endif @@ -4215,10 +4185,9 @@ static void gl2psPrintPDFHeader(void) static void gl2psPrintPDFPrimitive(void *data) { - GL2PSprimitive *prim = *(GL2PSprimitive**)data; + GL2PSprimitive *prim = *(GL2PSprimitive **)data; - if((gl2ps->options & GL2PS_OCCLUSION_CULL) && prim->culled) - return; + if((gl2ps->options & GL2PS_OCCLUSION_CULL) && prim->culled) return; prim = gl2psCopyPrimitive(prim); /* deep copy */ gl2psListAdd(gl2ps->pdfprimlist, &prim); @@ -4231,7 +4200,7 @@ static int gl2psClosePDFDataStream(void) int offs = 0; #if defined(GL2PS_HAVE_ZLIB) - if(gl2ps->options & GL2PS_COMPRESS){ + if(gl2ps->options & GL2PS_COMPRESS) { if(Z_OK != gl2psDeflate()) gl2psMsg(GL2PS_ERROR, "Zlib deflate error"); else @@ -4243,9 +4212,8 @@ static int gl2psClosePDFDataStream(void) } #endif - offs += fprintf(gl2ps->stream, - "endstream\n" - "endobj\n"); + offs += fprintf(gl2ps->stream, "endstream\n" + "endobj\n"); return offs; } @@ -4256,7 +4224,8 @@ static int gl2psPrintPDFDataStreamLength(int val) return fprintf(gl2ps->stream, "5 0 obj\n" "%d\n" - "endobj\n", val); + "endobj\n", + val); } /* Put the info created before in PDF objects */ @@ -4307,10 +4276,9 @@ static int gl2psPDFgroupListWriteVariableResources(void) offs += gl2psPDFgroupListWriteFontResources(); /* End resources and page */ - offs += fprintf(gl2ps->stream, - ">>\n" - ">>\n" - "endobj\n"); + offs += fprintf(gl2ps->stream, ">>\n" + ">>\n" + "endobj\n"); return offs; } @@ -4318,28 +4286,26 @@ static int gl2psPDFgroupListWriteVariableResources(void) static int gl2psPrintPDFGSObject(void) { - return fprintf(gl2ps->stream, - "7 0 obj\n" - "<<\n" - "/Type /ExtGState\n" - "/SA false\n" - "/SM 0.02\n" - "/OP false\n" - "/op false\n" - "/OPM 0\n" - "/BG2 /Default\n" - "/UCR2 /Default\n" - "/TR2 /Default\n" - ">>\n" - "endobj\n"); + return fprintf(gl2ps->stream, "7 0 obj\n" + "<<\n" + "/Type /ExtGState\n" + "/SA false\n" + "/SM 0.02\n" + "/OP false\n" + "/op false\n" + "/OPM 0\n" + "/BG2 /Default\n" + "/UCR2 /Default\n" + "/TR2 /Default\n" + ">>\n" + "endobj\n"); } /* Put vertex' edge flag (8bit) and coordinates (32bit) in shader stream */ -static int gl2psPrintPDFShaderStreamDataCoord(GL2PSvertex *vertex, - int (*action)(unsigned long data, int size), - GLfloat dx, GLfloat dy, - GLfloat xmin, GLfloat ymin) +static int gl2psPrintPDFShaderStreamDataCoord( + GL2PSvertex *vertex, int (*action)(unsigned long data, int size), GLfloat dx, + GLfloat dy, GLfloat xmin, GLfloat ymin) { int offs = 0; unsigned long imap; @@ -4355,11 +4321,11 @@ static int gl2psPrintPDFShaderStreamDataCoord(GL2PSvertex *vertex, /* The Shader stream in PDF requires to be in a 'big-endian' order */ - if(GL2PS_ZERO(dx * dy)){ + if(GL2PS_ZERO(dx * dy)) { offs += (*action)(0, 4); offs += (*action)(0, 4); } - else{ + else { diff = (vertex->xyz[0] - xmin) / dx; if(diff > 1) diff = 1.0F; @@ -4383,7 +4349,8 @@ static int gl2psPrintPDFShaderStreamDataCoord(GL2PSvertex *vertex, /* Put vertex' rgb value (8bit for every component) in shader stream */ static int gl2psPrintPDFShaderStreamDataRGB(GL2PSvertex *vertex, - int (*action)(unsigned long data, int size)) + int (*action)(unsigned long data, + int size)) { int offs = 0; unsigned long imap; @@ -4406,9 +4373,8 @@ static int gl2psPrintPDFShaderStreamDataRGB(GL2PSvertex *vertex, /* Put vertex' alpha (8/16bit) in shader stream */ -static int gl2psPrintPDFShaderStreamDataAlpha(GL2PSvertex *vertex, - int (*action)(unsigned long data, int size), - int sigbyte) +static int gl2psPrintPDFShaderStreamDataAlpha( + GL2PSvertex *vertex, int (*action)(unsigned long data, int size), int sigbyte) { int offs = 0; unsigned long imap; @@ -4417,8 +4383,7 @@ static int gl2psPrintPDFShaderStreamDataAlpha(GL2PSvertex *vertex, /* FIXME: temp bux fix for 64 bit archs: */ if(sizeof(unsigned long) == 8) dmax = dmax - 2048.; - if(sigbyte != 8 && sigbyte != 16) - sigbyte = 8; + if(sigbyte != 8 && sigbyte != 16) sigbyte = 8; sigbyte /= 8; @@ -4431,26 +4396,23 @@ static int gl2psPrintPDFShaderStreamDataAlpha(GL2PSvertex *vertex, /* Put a triangles raw data in shader stream */ -static int gl2psPrintPDFShaderStreamData(GL2PStriangle *triangle, - GLfloat dx, GLfloat dy, - GLfloat xmin, GLfloat ymin, - int (*action)(unsigned long data, int size), - int gray) +static int gl2psPrintPDFShaderStreamData( + GL2PStriangle *triangle, GLfloat dx, GLfloat dy, GLfloat xmin, GLfloat ymin, + int (*action)(unsigned long data, int size), int gray) { int i, offs = 0; GL2PSvertex v; - if(gray && gray != 8 && gray != 16) - gray = 8; + if(gray && gray != 8 && gray != 16) gray = 8; - for(i = 0; i < 3; ++i){ - offs += gl2psPrintPDFShaderStreamDataCoord(&triangle->vertex[i], action, - dx, dy, xmin, ymin); - if(gray){ + for(i = 0; i < 3; ++i) { + offs += gl2psPrintPDFShaderStreamDataCoord(&triangle->vertex[i], action, dx, + dy, xmin, ymin); + if(gray) { v = triangle->vertex[i]; offs += gl2psPrintPDFShaderStreamDataAlpha(&v, action, gray); } - else{ + else { offs += gl2psPrintPDFShaderStreamDataRGB(&triangle->vertex[i], action); } } @@ -4458,9 +4420,8 @@ static int gl2psPrintPDFShaderStreamData(GL2PStriangle *triangle, return offs; } -static void gl2psPDFRectHull(GLfloat *xmin, GLfloat *xmax, - GLfloat *ymin, GLfloat *ymax, - GL2PStriangle *triangles, int cnt) +static void gl2psPDFRectHull(GLfloat *xmin, GLfloat *xmax, GLfloat *ymin, + GLfloat *ymax, GL2PStriangle *triangles, int cnt) { int i, j; @@ -4469,8 +4430,8 @@ static void gl2psPDFRectHull(GLfloat *xmin, GLfloat *xmax, *ymin = triangles[0].vertex[0].xyz[1]; *ymax = triangles[0].vertex[0].xyz[1]; - for(i = 0; i < cnt; ++i){ - for(j = 0; j < 3; ++j){ + for(i = 0; i < cnt; ++i) { + for(j = 0; j < 3; ++j) { if(*xmin > triangles[i].vertex[j].xyz[0]) *xmin = triangles[i].vertex[j].xyz[0]; if(*xmax < triangles[i].vertex[j].xyz[0]) @@ -4488,25 +4449,19 @@ static void gl2psPDFRectHull(GLfloat *xmin, GLfloat *xmax, gray == 8 8bit-grayscale (for alpha masks) gray == 16 16bit-grayscale (for alpha masks) */ -static int gl2psPrintPDFShader(int obj, GL2PStriangle *triangles, - int size, int gray) +static int gl2psPrintPDFShader(int obj, GL2PStriangle *triangles, int size, + int gray) { int i, offs = 0, vertexbytes, done = 0; GLfloat xmin, xmax, ymin, ymax; - switch(gray){ - case 0: - vertexbytes = 1+4+4+1+1+1; - break; - case 8: - vertexbytes = 1+4+4+1; - break; - case 16: - vertexbytes = 1+4+4+2; - break; + switch(gray) { + case 0: vertexbytes = 1 + 4 + 4 + 1 + 1 + 1; break; + case 8: vertexbytes = 1 + 4 + 4 + 1; break; + case 16: vertexbytes = 1 + 4 + 4 + 2; break; default: gray = 8; - vertexbytes = 1+4+4+1; + vertexbytes = 1 + 4 + 4 + 1; break; } @@ -4521,22 +4476,20 @@ static int gl2psPrintPDFShader(int obj, GL2PStriangle *triangles, "/BitsPerComponent %d " "/BitsPerFlag 8 " "/Decode [%f %f %f %f 0 1 %s] ", - obj, - (gray) ? "/DeviceGray" : "/DeviceRGB", - (gray) ? gray : 8, - xmin, xmax, ymin, ymax, - (gray) ? "" : "0 1 0 1"); + obj, (gray) ? "/DeviceGray" : "/DeviceRGB", (gray) ? gray : 8, + xmin, xmax, ymin, ymax, (gray) ? "" : "0 1 0 1"); #if defined(GL2PS_HAVE_ZLIB) - if(gl2ps->options & GL2PS_COMPRESS){ + if(gl2ps->options & GL2PS_COMPRESS) { gl2psAllocCompress(vertexbytes * size * 3); for(i = 0; i < size; ++i) - gl2psPrintPDFShaderStreamData(&triangles[i], - xmax-xmin, ymax-ymin, xmin, ymin, - gl2psWriteBigEndianCompress, gray); + gl2psPrintPDFShaderStreamData(&triangles[i], xmax - xmin, ymax - ymin, + xmin, ymin, gl2psWriteBigEndianCompress, + gray); - if(Z_OK == gl2psDeflate() && 23 + gl2ps->compress->destLen < gl2ps->compress->srcLen){ + if(Z_OK == gl2psDeflate() && + 23 + gl2ps->compress->destLen < gl2ps->compress->srcLen) { offs += gl2psPrintPDFCompressorType(); offs += fprintf(gl2ps->stream, "/Length %d " @@ -4544,15 +4497,15 @@ static int gl2psPrintPDFShader(int obj, GL2PStriangle *triangles, "stream\n", (int)gl2ps->compress->destLen); offs += gl2ps->compress->destLen * fwrite(gl2ps->compress->dest, - gl2ps->compress->destLen, - 1, gl2ps->stream); + gl2ps->compress->destLen, 1, + gl2ps->stream); done = 1; } gl2psFreeCompress(); } #endif - if(!done){ + if(!done) { /* no compression, or too long after compression, or compress error -> write non-compressed entry */ offs += fprintf(gl2ps->stream, @@ -4561,14 +4514,13 @@ static int gl2psPrintPDFShader(int obj, GL2PStriangle *triangles, "stream\n", vertexbytes * 3 * size); for(i = 0; i < size; ++i) - offs += gl2psPrintPDFShaderStreamData(&triangles[i], - xmax-xmin, ymax-ymin, xmin, ymin, - gl2psWriteBigEndian, gray); + offs += + gl2psPrintPDFShaderStreamData(&triangles[i], xmax - xmin, ymax - ymin, + xmin, ymin, gl2psWriteBigEndian, gray); } - offs += fprintf(gl2ps->stream, - "\nendstream\n" - "endobj\n"); + offs += fprintf(gl2ps->stream, "\nendstream\n" + "endobj\n"); return offs; } @@ -4587,25 +4539,21 @@ static int gl2psPrintPDFShaderMask(int obj, int childobj) "/BBox [ %d %d %d %d ]\n" "/Group \n<<\n/S /Transparency /CS /DeviceRGB\n" ">>\n", - obj, - (int)gl2ps->viewport[0], (int)gl2ps->viewport[1], + obj, (int)gl2ps->viewport[0], (int)gl2ps->viewport[1], (int)gl2ps->viewport[2], (int)gl2ps->viewport[3]); - len = (childobj>0) - ? (int)strlen("/TrSh sh\n") + (int)log10((double)childobj)+1 - : (int)strlen("/TrSh0 sh\n"); + len = (childobj > 0) ? + (int)strlen("/TrSh sh\n") + (int)log10((double)childobj) + 1 : + (int)strlen("/TrSh0 sh\n"); offs += fprintf(gl2ps->stream, "/Length %d\n" ">>\n" "stream\n", len); - offs += fprintf(gl2ps->stream, - "/TrSh%d sh\n", - childobj); - offs += fprintf(gl2ps->stream, - "endstream\n" - "endobj\n"); + offs += fprintf(gl2ps->stream, "/TrSh%d sh\n", childobj); + offs += fprintf(gl2ps->stream, "endstream\n" + "endobj\n"); return offs; } @@ -4623,13 +4571,10 @@ static int gl2psPrintPDFShaderExtGS(int obj, int childobj) "<<\n", obj); - offs += fprintf(gl2ps->stream, - "/SMask << /S /Alpha /G %d 0 R >> ", - childobj); + offs += fprintf(gl2ps->stream, "/SMask << /S /Alpha /G %d 0 R >> ", childobj); - offs += fprintf(gl2ps->stream, - ">>\n" - "endobj\n"); + offs += fprintf(gl2ps->stream, ">>\n" + "endobj\n"); return offs; } @@ -4651,30 +4596,27 @@ static int gl2psPrintPDFShaderSimpleExtGS(int obj, GLfloat alpha) /* Similar groups of functions for pixmaps and text */ -static int gl2psPrintPDFPixmapStreamData(GL2PSimage *im, - int (*action)(unsigned long data, int size), - int gray) +static int gl2psPrintPDFPixmapStreamData( + GL2PSimage *im, int (*action)(unsigned long data, int size), int gray) { int x, y, shift; GLfloat r, g, b, a; - if(im->format != GL_RGBA && gray) - return 0; + if(im->format != GL_RGBA && gray) return 0; - if(gray && gray != 8 && gray != 16) - gray = 8; + if(gray && gray != 8 && gray != 16) gray = 8; gray /= 8; shift = (sizeof(unsigned long) - 1) * 8; - for(y = 0; y < im->height; ++y){ - for(x = 0; x < im->width; ++x){ + for(y = 0; y < im->height; ++y) { + for(x = 0; x < im->width; ++x) { a = gl2psGetRGB(im, x, y, &r, &g, &b); - if(im->format == GL_RGBA && gray){ + if(im->format == GL_RGBA && gray) { (*action)((unsigned long)(a * 255) << shift, gray); } - else{ + else { (*action)((unsigned long)(r * 255) << shift, 1); (*action)((unsigned long)(g * 255) << shift, 1); (*action)((unsigned long)(b * 255) << shift, 1); @@ -4682,7 +4624,7 @@ static int gl2psPrintPDFPixmapStreamData(GL2PSimage *im, } } - switch(gray){ + switch(gray) { case 0: return 3 * im->width * im->height; case 1: return im->width * im->height; case 2: return 2 * im->width * im->height; @@ -4694,11 +4636,9 @@ static int gl2psPrintPDFPixmap(int obj, int childobj, GL2PSimage *im, int gray) { int offs = 0, done = 0, sigbytes = 3; - if(gray && gray !=8 && gray != 16) - gray = 8; + if(gray && gray != 8 && gray != 16) gray = 8; - if(gray) - sigbytes = gray / 8; + if(gray) sigbytes = gray / 8; offs += fprintf(gl2ps->stream, "%d 0 obj\n" @@ -4709,37 +4649,36 @@ static int gl2psPrintPDFPixmap(int obj, int childobj, GL2PSimage *im, int gray) "/Height %d\n" "/ColorSpace %s \n" "/BitsPerComponent 8\n", - obj, - (int)im->width, (int)im->height, - (gray) ? "/DeviceGray" : "/DeviceRGB" ); - if(GL_RGBA == im->format && gray == 0){ - offs += fprintf(gl2ps->stream, - "/SMask %d 0 R\n", - childobj); + obj, (int)im->width, (int)im->height, + (gray) ? "/DeviceGray" : "/DeviceRGB"); + if(GL_RGBA == im->format && gray == 0) { + offs += fprintf(gl2ps->stream, "/SMask %d 0 R\n", childobj); } #if defined(GL2PS_HAVE_ZLIB) - if(gl2ps->options & GL2PS_COMPRESS){ + if(gl2ps->options & GL2PS_COMPRESS) { gl2psAllocCompress((int)(im->width * im->height * sigbytes)); gl2psPrintPDFPixmapStreamData(im, gl2psWriteBigEndianCompress, gray); - if(Z_OK == gl2psDeflate() && 23 + gl2ps->compress->destLen < gl2ps->compress->srcLen){ + if(Z_OK == gl2psDeflate() && + 23 + gl2ps->compress->destLen < gl2ps->compress->srcLen) { offs += gl2psPrintPDFCompressorType(); offs += fprintf(gl2ps->stream, "/Length %d " ">>\n" "stream\n", (int)gl2ps->compress->destLen); - offs += gl2ps->compress->destLen * fwrite(gl2ps->compress->dest, gl2ps->compress->destLen, - 1, gl2ps->stream); + offs += gl2ps->compress->destLen * fwrite(gl2ps->compress->dest, + gl2ps->compress->destLen, 1, + gl2ps->stream); done = 1; } gl2psFreeCompress(); } #endif - if(!done){ + if(!done) { /* no compression, or too long after compression, or compress error -> write non-compressed entry */ offs += fprintf(gl2ps->stream, @@ -4750,9 +4689,8 @@ static int gl2psPrintPDFPixmap(int obj, int childobj, GL2PSimage *im, int gray) offs += gl2psPrintPDFPixmapStreamData(im, gl2psWriteBigEndian, gray); } - offs += fprintf(gl2ps->stream, - "\nendstream\n" - "endobj\n"); + offs += fprintf(gl2ps->stream, "\nendstream\n" + "endobj\n"); return offs; } @@ -4779,42 +4717,39 @@ static int gl2psPrintPDFText(int obj, GL2PSstring *s, int fontnumber) static int gl2psPDFgroupListWriteObjects(int entryoffs) { - int i,j; + int i, j; GL2PSprimitive *p = NULL; GL2PSpdfgroup *gro; int offs = entryoffs; GL2PStriangle *triangles; int size = 0; - if(!gl2ps->pdfgrouplist) - return offs; + if(!gl2ps->pdfgrouplist) return offs; - for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i){ - gro = (GL2PSpdfgroup*)gl2psListPointer(gl2ps->pdfgrouplist, i); - if(!gl2psListNbr(gro->ptrlist)) - continue; - p = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, 0); - switch(p->type){ - case GL2PS_POINT: - break; - case GL2PS_LINE: - break; + for(i = 0; i < gl2psListNbr(gl2ps->pdfgrouplist); ++i) { + gro = (GL2PSpdfgroup *)gl2psListPointer(gl2ps->pdfgrouplist, i); + if(!gl2psListNbr(gro->ptrlist)) continue; + p = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, 0); + switch(p->type) { + case GL2PS_POINT: break; + case GL2PS_LINE: break; case GL2PS_TRIANGLE: size = gl2psListNbr(gro->ptrlist); - triangles = (GL2PStriangle*)gl2psMalloc(sizeof(GL2PStriangle) * size); - for(j = 0; j < size; ++j){ - p = *(GL2PSprimitive**)gl2psListPointer(gro->ptrlist, j); + triangles = (GL2PStriangle *)gl2psMalloc(sizeof(GL2PStriangle) * size); + for(j = 0; j < size; ++j) { + p = *(GL2PSprimitive **)gl2psListPointer(gro->ptrlist, j); gl2psFillTriangleFromPrimitive(&triangles[j], p, GL_TRUE); } - if(triangles[0].prop & T_VAR_COLOR){ + if(triangles[0].prop & T_VAR_COLOR) { gl2ps->xreflist[gro->shobjno] = offs; offs += gl2psPrintPDFShader(gro->shobjno, triangles, size, 0); } - if(triangles[0].prop & T_ALPHA_LESS_1){ + if(triangles[0].prop & T_ALPHA_LESS_1) { gl2ps->xreflist[gro->gsobjno] = offs; - offs += gl2psPrintPDFShaderSimpleExtGS(gro->gsobjno, triangles[0].vertex[0].rgba[3]); + offs += gl2psPrintPDFShaderSimpleExtGS(gro->gsobjno, + triangles[0].vertex[0].rgba[3]); } - if(triangles[0].prop & T_VAR_ALPHA){ + if(triangles[0].prop & T_VAR_ALPHA) { gl2ps->xreflist[gro->gsobjno] = offs; offs += gl2psPrintPDFShaderExtGS(gro->gsobjno, gro->trgroupobjno); gl2ps->xreflist[gro->trgroupobjno] = offs; @@ -4826,24 +4761,24 @@ static int gl2psPDFgroupListWriteObjects(int entryoffs) break; case GL2PS_PIXMAP: gl2ps->xreflist[gro->imobjno] = offs; - offs += gl2psPrintPDFPixmap(gro->imobjno, gro->imobjno+1, p->data.image, 0); - if(p->data.image->format == GL_RGBA){ - gl2ps->xreflist[gro->imobjno+1] = offs; - offs += gl2psPrintPDFPixmap(gro->imobjno+1, -1, p->data.image, 8); + offs += + gl2psPrintPDFPixmap(gro->imobjno, gro->imobjno + 1, p->data.image, 0); + if(p->data.image->format == GL_RGBA) { + gl2ps->xreflist[gro->imobjno + 1] = offs; + offs += gl2psPrintPDFPixmap(gro->imobjno + 1, -1, p->data.image, 8); } break; case GL2PS_TEXT: gl2ps->xreflist[gro->fontobjno] = offs; - offs += gl2psPrintPDFText(gro->fontobjno,p->data.text,gro->fontno); + offs += gl2psPrintPDFText(gro->fontobjno, p->data.text, gro->fontno); break; - case GL2PS_SPECIAL : + case GL2PS_SPECIAL: /* alignment contains the format for which the special output text is intended */ if(p->data.text->alignment == GL2PS_PDF) offs += fprintf(gl2ps->stream, "%s\n", p->data.text->str); break; - default: - break; + default: break; } } return offs; @@ -4870,8 +4805,8 @@ static void gl2psPrintPDFFooter(void) offs += gl2psPrintPDFOpenPage(); offs += gl2psPDFgroupListWriteVariableResources(); - gl2ps->xreflist = (int*)gl2psRealloc(gl2ps->xreflist, - sizeof(int) * (gl2ps->objects_stack + 1)); + gl2ps->xreflist = (int *)gl2psRealloc( + gl2ps->xreflist, sizeof(int) * (gl2ps->objects_stack + 1)); gl2ps->xreflist[7] = offs; offs += gl2psPrintPDFGSObject(); @@ -4885,7 +4820,8 @@ static void gl2psPrintPDFFooter(void) fprintf(gl2ps->stream, "xref\n" "0 %d\n" - "%010d 65535 f \n", gl2ps->objects_stack, 0); + "%010d 65535 f \n", + gl2ps->objects_stack, 0); for(i = 1; i < gl2ps->objects_stack; ++i) fprintf(gl2ps->stream, "%010d 00000 n \n", gl2ps->xreflist[i]); @@ -4908,7 +4844,7 @@ static void gl2psPrintPDFFooter(void) gl2psPDFgroupListDelete(); #if defined(GL2PS_HAVE_ZLIB) - if(gl2ps->options & GL2PS_COMPRESS){ + if(gl2ps->options & GL2PS_COMPRESS) { gl2psFreeCompress(); gl2psFree(gl2ps->compress); gl2ps->compress = NULL; @@ -4929,18 +4865,18 @@ static void gl2psPrintPDFBeginViewport(GLint viewport[4]) gl2psResetLineProperties(); - if(gl2ps->header){ + if(gl2ps->header) { gl2psPrintPDFHeader(); gl2ps->header = GL_FALSE; } offs += gl2psPrintf("q\n"); - if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ - if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){ + if(gl2ps->options & GL2PS_DRAW_BACKGROUND) { + if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0) { glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba); } - else{ + else { glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx); rgba[0] = gl2ps->colormap[idx][0]; rgba[1] = gl2ps->colormap[idx][1]; @@ -4953,7 +4889,7 @@ static void gl2psPrintPDFBeginViewport(GLint viewport[4]) "f\n", x, y, w, h); } - else{ + else { offs += gl2psPrintf("%d %d %d %d re\n" "W\n" "n\n", @@ -4972,22 +4908,18 @@ static GLint gl2psPrintPDFEndViewport(void) return res; } -static void gl2psPrintPDFFinalPrimitive(void) -{ -} +static void gl2psPrintPDFFinalPrimitive(void) {} /* definition of the PDF backend */ -static GL2PSbackend gl2psPDF = { - gl2psPrintPDFHeader, - gl2psPrintPDFFooter, - gl2psPrintPDFBeginViewport, - gl2psPrintPDFEndViewport, - gl2psPrintPDFPrimitive, - gl2psPrintPDFFinalPrimitive, - "pdf", - "Portable Document Format" -}; +static GL2PSbackend gl2psPDF = {gl2psPrintPDFHeader, + gl2psPrintPDFFooter, + gl2psPrintPDFBeginViewport, + gl2psPrintPDFEndViewport, + gl2psPrintPDFPrimitive, + gl2psPrintPDFFinalPrimitive, + "pdf", + "Portable Document Format"}; /********************************************************************* * @@ -4995,17 +4927,16 @@ static GL2PSbackend gl2psPDF = { * *********************************************************************/ -static void gl2psSVGGetCoordsAndColors(int n, GL2PSvertex *verts, - GL2PSxyz *xyz, GL2PSrgba *rgba) +static void gl2psSVGGetCoordsAndColors(int n, GL2PSvertex *verts, GL2PSxyz *xyz, + GL2PSrgba *rgba) { int i, j; - for(i = 0; i < n; i++){ + for(i = 0; i < n; i++) { xyz[i][0] = verts[i].xyz[0]; xyz[i][1] = gl2ps->viewport[3] - verts[i].xyz[1]; xyz[i][2] = 0.0F; - for(j = 0; j < 4; j++) - rgba[i][j] = verts[i].rgba[j]; + for(j = 0; j < 4; j++) rgba[i][j] = verts[i].rgba[j]; } } @@ -5028,13 +4959,13 @@ static void gl2psPrintSVGHeader(void) time(&now); - if (gl2ps->options & GL2PS_LANDSCAPE){ + if(gl2ps->options & GL2PS_LANDSCAPE) { x = (int)gl2ps->viewport[1]; y = (int)gl2ps->viewport[0]; width = (int)gl2ps->viewport[3]; height = (int)gl2ps->viewport[2]; } - else{ + else { x = (int)gl2ps->viewport[0]; y = (int)gl2ps->viewport[1]; width = (int)gl2ps->viewport[2]; @@ -5055,15 +4986,16 @@ static void gl2psPrintSVGHeader(void) "For: %s\n" "CreationDate: %s", GL2PS_MAJOR_VERSION, GL2PS_MINOR_VERSION, GL2PS_PATCH_VERSION, - GL2PS_EXTRA_VERSION, GL2PS_COPYRIGHT, gl2ps->producer, ctime(&now)); + GL2PS_EXTRA_VERSION, GL2PS_COPYRIGHT, gl2ps->producer, + ctime(&now)); gl2psPrintf("</desc>\n"); gl2psPrintf("<defs>\n"); gl2psPrintf("</defs>\n"); - if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ + if(gl2ps->options & GL2PS_DRAW_BACKGROUND) { gl2psSVGGetColorString(gl2ps->bgcolor, col); - gl2psPrintf("<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", col, - (int)gl2ps->viewport[0], (int)gl2ps->viewport[1], + gl2psPrintf("<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", + col, (int)gl2ps->viewport[0], (int)gl2ps->viewport[1], (int)gl2ps->viewport[2], (int)gl2ps->viewport[1], (int)gl2ps->viewport[2], (int)gl2ps->viewport[3], (int)gl2ps->viewport[0], (int)gl2ps->viewport[3]); @@ -5084,7 +5016,7 @@ static void gl2psPrintSVGSmoothTriangle(GL2PSxyz xyz[3], GL2PSrgba rgba[3]) without explicitly pre-defining gradients, so for now we just do recursive subdivision */ - if(gl2psSameColorThreshold(3, rgba, gl2ps->threshold)){ + if(gl2psSameColorThreshold(3, rgba, gl2ps->threshold)) { gl2psSVGGetColorString(rgba[0], col); gl2psPrintf("<polygon fill=\"%s\" ", col); if(rgba[0][3] < 1.0F) gl2psPrintf("fill-opacity=\"%g\" ", rgba[0][3]); @@ -5092,47 +5024,47 @@ static void gl2psPrintSVGSmoothTriangle(GL2PSxyz xyz[3], GL2PSrgba rgba[3]) gl2psPrintf("points=\"%g,%g %g,%g %g,%g\"/>\n", xyz[0][0], xyz[0][1], xyz[1][0], xyz[1][1], xyz[2][0], xyz[2][1]); } - else{ + else { /* subdivide into 4 subtriangles */ - for(i = 0; i < 3; i++){ + for(i = 0; i < 3; i++) { xyz2[0][i] = xyz[0][i]; xyz2[1][i] = 0.5F * (xyz[0][i] + xyz[1][i]); xyz2[2][i] = 0.5F * (xyz[0][i] + xyz[2][i]); } - for(i = 0; i < 4; i++){ + for(i = 0; i < 4; i++) { rgba2[0][i] = rgba[0][i]; rgba2[1][i] = 0.5F * (rgba[0][i] + rgba[1][i]); rgba2[2][i] = 0.5F * (rgba[0][i] + rgba[2][i]); } gl2psPrintSVGSmoothTriangle(xyz2, rgba2); - for(i = 0; i < 3; i++){ + for(i = 0; i < 3; i++) { xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[1][i]); xyz2[1][i] = xyz[1][i]; xyz2[2][i] = 0.5F * (xyz[1][i] + xyz[2][i]); } - for(i = 0; i < 4; i++){ + for(i = 0; i < 4; i++) { rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[1][i]); rgba2[1][i] = rgba[1][i]; rgba2[2][i] = 0.5F * (rgba[1][i] + rgba[2][i]); } gl2psPrintSVGSmoothTriangle(xyz2, rgba2); - for(i = 0; i < 3; i++){ + for(i = 0; i < 3; i++) { xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[2][i]); xyz2[1][i] = xyz[2][i]; xyz2[2][i] = 0.5F * (xyz[1][i] + xyz[2][i]); } - for(i = 0; i < 4; i++){ + for(i = 0; i < 4; i++) { rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[2][i]); rgba2[1][i] = rgba[2][i]; rgba2[2][i] = 0.5F * (rgba[1][i] + rgba[2][i]); } gl2psPrintSVGSmoothTriangle(xyz2, rgba2); - for(i = 0; i < 3; i++){ + for(i = 0; i < 3; i++) { xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[1][i]); xyz2[1][i] = 0.5F * (xyz[1][i] + xyz[2][i]); xyz2[2][i] = 0.5F * (xyz[0][i] + xyz[2][i]); } - for(i = 0; i < 4; i++){ + for(i = 0; i < 4; i++) { rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[1][i]); rgba2[1][i] = 0.5F * (rgba[1][i] + rgba[2][i]); rgba2[2][i] = 0.5F * (rgba[0][i] + rgba[2][i]); @@ -5149,7 +5081,7 @@ static void gl2psPrintSVGDash(GLushort pattern, GLint factor) gl2psParseStipplePattern(pattern, factor, &n, array); gl2psPrintf("stroke-dasharray=\""); - for(i = 0; i < n; i++){ + for(i = 0; i < n; i++) { if(i) gl2psPrintf(","); gl2psPrintf("%d", array[i]); } @@ -5159,13 +5091,11 @@ static void gl2psPrintSVGDash(GLushort pattern, GLint factor) static void gl2psEndSVGLine(void) { int i; - if(gl2ps->lastvertex.rgba[0] >= 0.){ + if(gl2ps->lastvertex.rgba[0] >= 0.) { gl2psPrintf("%g,%g\"/>\n", gl2ps->lastvertex.xyz[0], gl2ps->viewport[3] - gl2ps->lastvertex.xyz[1]); - for(i = 0; i < 3; i++) - gl2ps->lastvertex.xyz[i] = -1.; - for(i = 0; i < 4; i++) - gl2ps->lastvertex.rgba[i] = -1.; + for(i = 0; i < 3; i++) gl2ps->lastvertex.xyz[i] = -1.; + for(i = 0; i < 4; i++) gl2ps->lastvertex.rgba[i] = -1.; } } @@ -5190,21 +5120,23 @@ static void gl2psPrintSVGPixmap(GLfloat x, GLfloat y, GL2PSimage *pixmap) /* Use "transform" attribute to scale and translate the image from the coordinates origin (0,0) */ y -= pixmap->zoom_y * (GLfloat)pixmap->height; - gl2psPrintf("<image x=\"%g\" y=\"%g\" width=\"%d\" height=\"%d\"\n", - 0., 0., pixmap->width, pixmap->height); - gl2psPrintf("transform=\"matrix(%g,0,0,%g,%g,%g)\"\n", - pixmap->zoom_x, pixmap->zoom_y, x, y); + gl2psPrintf("<image x=\"%g\" y=\"%g\" width=\"%d\" height=\"%d\"\n", 0., 0., + pixmap->width, pixmap->height); + gl2psPrintf("transform=\"matrix(%g,0,0,%g,%g,%g)\"\n", pixmap->zoom_x, + pixmap->zoom_y, x, y); gl2psPrintf("xlink:href=\"data:image/png;base64,"); - for(i = 0; i < gl2psListNbr(png); i++){ + for(i = 0; i < gl2psListNbr(png); i++) { gl2psListRead(png, i, &c); gl2psPrintf("%c", c); } gl2psPrintf("\"/>\n"); gl2psListDelete(png); #else - (void) x; (void) y; (void) pixmap; /* not used */ + (void)x; + (void)y; + (void)pixmap; /* not used */ gl2psMsg(GL2PS_WARNING, "GL2PS must be compiled with PNG support in " - "order to embed images in SVG streams"); + "order to embed images in SVG streams"); #endif } @@ -5217,7 +5149,7 @@ static void gl2psPrintSVGPrimitive(void *data) char lcap[7], ljoin[7]; int newline; - prim = *(GL2PSprimitive**)data; + prim = *(GL2PSprimitive **)data; if((gl2ps->options & GL2PS_OCCLUSION_CULL) && prim->culled) return; @@ -5228,22 +5160,22 @@ static void gl2psPrintSVGPrimitive(void *data) gl2psSVGGetCoordsAndColors(prim->numverts, prim->verts, xyz, rgba); - switch(prim->type){ - case GL2PS_POINT : + switch(prim->type) { + case GL2PS_POINT: gl2psSVGGetColorString(rgba[0], col); gl2psPrintf("<circle fill=\"%s\" ", col); if(rgba[0][3] < 1.0F) gl2psPrintf("fill-opacity=\"%g\" ", rgba[0][3]); - gl2psPrintf("cx=\"%g\" cy=\"%g\" r=\"%g\"/>\n", - xyz[0][0], xyz[0][1], 0.5 * prim->width); + gl2psPrintf("cx=\"%g\" cy=\"%g\" r=\"%g\"/>\n", xyz[0][0], xyz[0][1], + 0.5 * prim->width); break; - case GL2PS_LINE : + case GL2PS_LINE: if(!gl2psSamePosition(gl2ps->lastvertex.xyz, prim->verts[0].xyz) || !gl2psSameColor(gl2ps->lastrgba, prim->verts[0].rgba) || gl2ps->lastlinewidth != prim->width || gl2ps->lastlinecap != prim->linecap || gl2ps->lastlinejoin != prim->linejoin || gl2ps->lastpattern != prim->pattern || - gl2ps->lastfactor != prim->factor){ + gl2ps->lastfactor != prim->factor) { /* End the current line if the new segment does not start where the last one ended, or if the color, the width or the stippling have changed (we will need to use multi-point @@ -5251,7 +5183,7 @@ static void gl2psPrintSVGPrimitive(void *data) gl2psEndSVGLine(); newline = 1; } - else{ + else { newline = 0; } gl2ps->lastvertex = prim->verts[1]; @@ -5261,59 +5193,44 @@ static void gl2psPrintSVGPrimitive(void *data) gl2ps->lastlinejoin = prim->linejoin; gl2ps->lastpattern = prim->pattern; gl2ps->lastfactor = prim->factor; - if(newline){ + if(newline) { gl2psSVGGetColorString(rgba[0], col); gl2psPrintf("<polyline fill=\"none\" stroke=\"%s\" stroke-width=\"%g\" ", col, prim->width); - switch (prim->linecap){ - case GL2PS_LINE_CAP_BUTT: - sprintf (lcap, "%s", "butt"); - break; - case GL2PS_LINE_CAP_ROUND: - sprintf (lcap, "%s", "round"); - break; - case GL2PS_LINE_CAP_SQUARE: - sprintf (lcap, "%s", "square"); - break; + switch(prim->linecap) { + case GL2PS_LINE_CAP_BUTT: sprintf(lcap, "%s", "butt"); break; + case GL2PS_LINE_CAP_ROUND: sprintf(lcap, "%s", "round"); break; + case GL2PS_LINE_CAP_SQUARE: sprintf(lcap, "%s", "square"); break; } - switch (prim->linejoin){ - case GL2PS_LINE_JOIN_MITER: - sprintf (ljoin, "%s", "miter"); - break; - case GL2PS_LINE_JOIN_ROUND: - sprintf (ljoin, "%s", "round"); - break; - case GL2PS_LINE_JOIN_BEVEL: - sprintf (ljoin, "%s", "bevel"); - break; + switch(prim->linejoin) { + case GL2PS_LINE_JOIN_MITER: sprintf(ljoin, "%s", "miter"); break; + case GL2PS_LINE_JOIN_ROUND: sprintf(ljoin, "%s", "round"); break; + case GL2PS_LINE_JOIN_BEVEL: sprintf(ljoin, "%s", "bevel"); break; } - gl2psPrintf("stroke-linecap=\"%s\" stroke-linejoin=\"%s\" ", - lcap, ljoin); + gl2psPrintf("stroke-linecap=\"%s\" stroke-linejoin=\"%s\" ", lcap, ljoin); if(rgba[0][3] < 1.0F) gl2psPrintf("stroke-opacity=\"%g\" ", rgba[0][3]); gl2psPrintSVGDash(prim->pattern, prim->factor); gl2psPrintf("points=\"%g,%g ", xyz[0][0], xyz[0][1]); } - else{ + else { gl2psPrintf("%g,%g ", xyz[0][0], xyz[0][1]); } break; - case GL2PS_TRIANGLE : - gl2psPrintSVGSmoothTriangle(xyz, rgba); - break; - case GL2PS_QUADRANGLE : + case GL2PS_TRIANGLE: gl2psPrintSVGSmoothTriangle(xyz, rgba); break; + case GL2PS_QUADRANGLE: gl2psMsg(GL2PS_WARNING, "There should not be any quad left to print"); break; - case GL2PS_PIXMAP : + case GL2PS_PIXMAP: gl2psPrintSVGPixmap(xyz[0][0], xyz[0][1], prim->data.image); break; - case GL2PS_TEXT : + case GL2PS_TEXT: gl2psSVGGetColorString(prim->verts[0].rgba, col); - gl2psPrintf("<text fill=\"%s\" x=\"%g\" y=\"%g\" font-size=\"%d\" ", - col, xyz[0][0], xyz[0][1], prim->data.text->fontsize); + gl2psPrintf("<text fill=\"%s\" x=\"%g\" y=\"%g\" font-size=\"%d\" ", col, + xyz[0][0], xyz[0][1], prim->data.text->fontsize); if(prim->data.text->angle) - gl2psPrintf("transform=\"rotate(%g, %g, %g)\" ", - -prim->data.text->angle, xyz[0][0], xyz[0][1]); - switch(prim->data.text->alignment){ + gl2psPrintf("transform=\"rotate(%g, %g, %g)\" ", -prim->data.text->angle, + xyz[0][0], xyz[0][1]); + switch(prim->data.text->alignment) { case GL2PS_TEXT_C: gl2psPrintf("text-anchor=\"middle\" dy=\"%d\" ", prim->data.text->fontsize / 2); @@ -5326,12 +5243,8 @@ static void gl2psPrintSVGPrimitive(void *data) gl2psPrintf("text-anchor=\"end\" dy=\"%d\" ", prim->data.text->fontsize / 2); break; - case GL2PS_TEXT_B: - gl2psPrintf("text-anchor=\"middle\" dy=\"0\" "); - break; - case GL2PS_TEXT_BR: - gl2psPrintf("text-anchor=\"end\" dy=\"0\" "); - break; + case GL2PS_TEXT_B: gl2psPrintf("text-anchor=\"middle\" dy=\"0\" "); break; + case GL2PS_TEXT_BR: gl2psPrintf("text-anchor=\"end\" dy=\"0\" "); break; case GL2PS_TEXT_T: gl2psPrintf("text-anchor=\"middle\" dy=\"%d\" ", prim->data.text->fontsize); @@ -5341,8 +5254,7 @@ static void gl2psPrintSVGPrimitive(void *data) prim->data.text->fontsize); break; case GL2PS_TEXT_TR: - gl2psPrintf("text-anchor=\"end\" dy=\"%d\" ", - prim->data.text->fontsize); + gl2psPrintf("text-anchor=\"end\" dy=\"%d\" ", prim->data.text->fontsize); break; case GL2PS_TEXT_BL: default: /* same as GL2PS_TEXT_BL */ @@ -5356,31 +5268,33 @@ static void gl2psPrintSVGPrimitive(void *data) else if(!strcmp(prim->data.text->fontname, "Times-Italic")) gl2psPrintf("font-family=\"Times\" font-style=\"italic\">"); else if(!strcmp(prim->data.text->fontname, "Times-BoldItalic")) - gl2psPrintf("font-family=\"Times\" font-style=\"italic\" font-weight=\"bold\">"); + gl2psPrintf( + "font-family=\"Times\" font-style=\"italic\" font-weight=\"bold\">"); else if(!strcmp(prim->data.text->fontname, "Helvetica-Bold")) gl2psPrintf("font-family=\"Helvetica\" font-weight=\"bold\">"); else if(!strcmp(prim->data.text->fontname, "Helvetica-Oblique")) gl2psPrintf("font-family=\"Helvetica\" font-style=\"oblique\">"); else if(!strcmp(prim->data.text->fontname, "Helvetica-BoldOblique")) - gl2psPrintf("font-family=\"Helvetica\" font-style=\"oblique\" font-weight=\"bold\">"); + gl2psPrintf("font-family=\"Helvetica\" font-style=\"oblique\" " + "font-weight=\"bold\">"); else if(!strcmp(prim->data.text->fontname, "Courier-Bold")) gl2psPrintf("font-family=\"Courier\" font-weight=\"bold\">"); else if(!strcmp(prim->data.text->fontname, "Courier-Oblique")) gl2psPrintf("font-family=\"Courier\" font-style=\"oblique\">"); else if(!strcmp(prim->data.text->fontname, "Courier-BoldOblique")) - gl2psPrintf("font-family=\"Courier\" font-style=\"oblique\" font-weight=\"bold\">"); + gl2psPrintf( + "font-family=\"Courier\" font-style=\"oblique\" font-weight=\"bold\">"); else gl2psPrintf("font-family=\"%s\">", prim->data.text->fontname); gl2psPrintf("%s</text>\n", prim->data.text->str); break; - case GL2PS_SPECIAL : + case GL2PS_SPECIAL: /* alignment contains the format for which the special output text is intended */ if(prim->data.text->alignment == GL2PS_SVG) gl2psPrintf("%s\n", prim->data.text->str); break; - default : - break; + default: break; } } @@ -5403,16 +5317,16 @@ static void gl2psPrintSVGBeginViewport(GLint viewport[4]) gl2psResetLineProperties(); - if(gl2ps->header){ + if(gl2ps->header) { gl2psPrintSVGHeader(); gl2ps->header = GL_FALSE; } - if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ - if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){ + if(gl2ps->options & GL2PS_DRAW_BACKGROUND) { + if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0) { glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba); } - else{ + else { glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx); rgba[0] = gl2ps->colormap[idx][0]; rgba[1] = gl2ps->colormap[idx][1]; @@ -5421,19 +5335,15 @@ static void gl2psPrintSVGBeginViewport(GLint viewport[4]) } gl2psSVGGetColorString(rgba, col); gl2psPrintf("<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\" ", col, - x, gl2ps->viewport[3] - y, - x + w, gl2ps->viewport[3] - y, - x + w, gl2ps->viewport[3] - (y + h), - x, gl2ps->viewport[3] - (y + h)); + x, gl2ps->viewport[3] - y, x + w, gl2ps->viewport[3] - y, x + w, + gl2ps->viewport[3] - (y + h), x, gl2ps->viewport[3] - (y + h)); gl2psPrintf("shape-rendering=\"crispEdges\"/>\n"); } gl2psPrintf("<clipPath id=\"cp%d%d%d%d\">\n", x, y, w, h); - gl2psPrintf(" <polygon points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", - x, gl2ps->viewport[3] - y, - x + w, gl2ps->viewport[3] - y, - x + w, gl2ps->viewport[3] - (y + h), - x, gl2ps->viewport[3] - (y + h)); + gl2psPrintf(" <polygon points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", x, + gl2ps->viewport[3] - y, x + w, gl2ps->viewport[3] - y, x + w, + gl2ps->viewport[3] - (y + h), x, gl2ps->viewport[3] - (y + h)); gl2psPrintf("</clipPath>\n"); gl2psPrintf("<g clip-path=\"url(#cp%d%d%d%d)\">\n", x, y, w, h); } @@ -5455,16 +5365,14 @@ static void gl2psPrintSVGFinalPrimitive(void) /* definition of the SVG backend */ -static GL2PSbackend gl2psSVG = { - gl2psPrintSVGHeader, - gl2psPrintSVGFooter, - gl2psPrintSVGBeginViewport, - gl2psPrintSVGEndViewport, - gl2psPrintSVGPrimitive, - gl2psPrintSVGFinalPrimitive, - "svg", - "Scalable Vector Graphics" -}; +static GL2PSbackend gl2psSVG = {gl2psPrintSVGHeader, + gl2psPrintSVGFooter, + gl2psPrintSVGBeginViewport, + gl2psPrintSVGEndViewport, + gl2psPrintSVGPrimitive, + gl2psPrintSVGFinalPrimitive, + "svg", + "Scalable Vector Graphics"}; /********************************************************************* * @@ -5474,9 +5382,10 @@ static GL2PSbackend gl2psSVG = { static void gl2psPrintPGFColor(GL2PSrgba rgba) { - if(!gl2psSameColor(gl2ps->lastrgba, rgba)){ + if(!gl2psSameColor(gl2ps->lastrgba, rgba)) { gl2psSetLastColor(rgba); - fprintf(gl2ps->stream, "\\color[rgb]{%f,%f,%f}\n", rgba[0], rgba[1], rgba[2]); + fprintf(gl2ps->stream, "\\color[rgb]{%f,%f,%f}\n", rgba[0], rgba[1], + rgba[2]); } } @@ -5496,7 +5405,7 @@ static void gl2psPrintPGFHeader(void) gl2ps->producer, ctime(&now)); fprintf(gl2ps->stream, "\\begin{pgfpicture}\n"); - if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ + if(gl2ps->options & GL2PS_DRAW_BACKGROUND) { gl2psPrintPGFColor(gl2ps->bgcolor); fprintf(gl2ps->stream, "\\pgfpathrectanglecorners{" @@ -5511,17 +5420,16 @@ static void gl2psPrintPGFDash(GLushort pattern, GLint factor) { int i, n, array[10]; - if(pattern == gl2ps->lastpattern && factor == gl2ps->lastfactor) - return; + if(pattern == gl2ps->lastpattern && factor == gl2ps->lastfactor) return; gl2ps->lastpattern = pattern; gl2ps->lastfactor = factor; - if(!pattern || !factor){ + if(!pattern || !factor) { /* solid line */ fprintf(gl2ps->stream, "\\pgfsetdash{}{0pt}\n"); } - else{ + else { gl2psParseStipplePattern(pattern, factor, &n, array); fprintf(gl2ps->stream, "\\pgfsetdash{"); for(i = 0; i < n; i++) fprintf(gl2ps->stream, "{%dpt}", array[i]); @@ -5531,17 +5439,17 @@ static void gl2psPrintPGFDash(GLushort pattern, GLint factor) static const char *gl2psPGFTextAlignment(int align) { - switch(align){ - case GL2PS_TEXT_C : return "center"; - case GL2PS_TEXT_CL : return "west"; - case GL2PS_TEXT_CR : return "east"; - case GL2PS_TEXT_B : return "south"; - case GL2PS_TEXT_BR : return "south east"; - case GL2PS_TEXT_T : return "north"; - case GL2PS_TEXT_TL : return "north west"; - case GL2PS_TEXT_TR : return "north east"; - case GL2PS_TEXT_BL : - default : return "south west"; + switch(align) { + case GL2PS_TEXT_C: return "center"; + case GL2PS_TEXT_CL: return "west"; + case GL2PS_TEXT_CR: return "east"; + case GL2PS_TEXT_B: return "south"; + case GL2PS_TEXT_BR: return "south east"; + case GL2PS_TEXT_T: return "north"; + case GL2PS_TEXT_TL: return "north west"; + case GL2PS_TEXT_TR: return "north east"; + case GL2PS_TEXT_BL: + default: return "south west"; } } @@ -5549,28 +5457,28 @@ static void gl2psPrintPGFPrimitive(void *data) { GL2PSprimitive *prim; - prim = *(GL2PSprimitive**)data; + prim = *(GL2PSprimitive **)data; - switch(prim->type){ - case GL2PS_POINT : + switch(prim->type) { + case GL2PS_POINT: /* Points in openGL are rectangular */ gl2psPrintPGFColor(prim->verts[0].rgba); fprintf(gl2ps->stream, "\\pgfpathrectangle{\\pgfpoint{%fpt}{%fpt}}" "{\\pgfpoint{%fpt}{%fpt}}\n\\pgfusepath{fill}\n", - prim->verts[0].xyz[0]-0.5*prim->width, - prim->verts[0].xyz[1]-0.5*prim->width, - prim->width,prim->width); + prim->verts[0].xyz[0] - 0.5 * prim->width, + prim->verts[0].xyz[1] - 0.5 * prim->width, prim->width, + prim->width); break; - case GL2PS_LINE : + case GL2PS_LINE: gl2psPrintPGFColor(prim->verts[0].rgba); - if(gl2ps->lastlinewidth != prim->width){ + if(gl2ps->lastlinewidth != prim->width) { gl2ps->lastlinewidth = prim->width; fprintf(gl2ps->stream, "\\pgfsetlinewidth{%fpt}\n", gl2ps->lastlinewidth); } - if(gl2ps->lastlinecap != prim->linecap){ + if(gl2ps->lastlinecap != prim->linecap) { gl2ps->lastlinecap = prim->linecap; - switch (prim->linecap){ + switch(prim->linecap) { case GL2PS_LINE_CAP_BUTT: fprintf(gl2ps->stream, "\\pgfset%s\n", "buttcap"); break; @@ -5582,9 +5490,9 @@ static void gl2psPrintPGFPrimitive(void *data) break; } } - if(gl2ps->lastlinejoin != prim->linejoin){ + if(gl2ps->lastlinejoin != prim->linejoin) { gl2ps->lastlinejoin = prim->linejoin; - switch (prim->linejoin){ + switch(prim->linejoin) { case GL2PS_LINE_JOIN_MITER: fprintf(gl2ps->stream, "\\pgfset%s\n", "miterjoin"); break; @@ -5601,17 +5509,17 @@ static void gl2psPrintPGFPrimitive(void *data) "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n" "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n" "\\pgfusepath{stroke}\n", - prim->verts[1].xyz[0], prim->verts[1].xyz[1], - prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + prim->verts[1].xyz[0], prim->verts[1].xyz[1], prim->verts[0].xyz[0], + prim->verts[0].xyz[1]); break; - case GL2PS_TRIANGLE : - if(gl2ps->lastlinewidth != 0){ + case GL2PS_TRIANGLE: + if(gl2ps->lastlinewidth != 0) { gl2ps->lastlinewidth = 0; fprintf(gl2ps->stream, "\\pgfsetlinewidth{0.01pt}\n"); } - if(gl2ps->lastlinecap != prim->linecap){ + if(gl2ps->lastlinecap != prim->linecap) { gl2ps->lastlinecap = prim->linecap; - switch (prim->linecap){ + switch(prim->linecap) { case GL2PS_LINE_CAP_BUTT: fprintf(gl2ps->stream, "\\pgfset%s\n", "buttcap"); break; @@ -5623,9 +5531,9 @@ static void gl2psPrintPGFPrimitive(void *data) break; } } - if(gl2ps->lastlinejoin != prim->linejoin){ + if(gl2ps->lastlinejoin != prim->linejoin) { gl2ps->lastlinejoin = prim->linejoin; - switch (prim->linejoin){ + switch(prim->linejoin) { case GL2PS_LINE_JOIN_MITER: fprintf(gl2ps->stream, "\\pgfset%s\n", "miterjoin"); break; @@ -5644,18 +5552,20 @@ static void gl2psPrintPGFPrimitive(void *data) "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n" "\\pgfpathclose\n" "\\pgfusepath{fill,stroke}\n", - prim->verts[2].xyz[0], prim->verts[2].xyz[1], - prim->verts[1].xyz[0], prim->verts[1].xyz[1], - prim->verts[0].xyz[0], prim->verts[0].xyz[1]); + prim->verts[2].xyz[0], prim->verts[2].xyz[1], prim->verts[1].xyz[0], + prim->verts[1].xyz[1], prim->verts[0].xyz[0], + prim->verts[0].xyz[1]); break; - case GL2PS_TEXT : + case GL2PS_TEXT: fprintf(gl2ps->stream, "{\n\\pgftransformshift{\\pgfpoint{%fpt}{%fpt}}\n", prim->verts[0].xyz[0], prim->verts[0].xyz[1]); if(prim->data.text->angle) - fprintf(gl2ps->stream, "\\pgftransformrotate{%f}{", prim->data.text->angle); + fprintf(gl2ps->stream, "\\pgftransformrotate{%f}{", + prim->data.text->angle); - fprintf(gl2ps->stream, "\\pgfnode{rectangle}{%s}{\\fontsize{%d}{0}\\selectfont", + fprintf(gl2ps->stream, + "\\pgfnode{rectangle}{%s}{\\fontsize{%d}{0}\\selectfont", gl2psPGFTextAlignment(prim->data.text->alignment), prim->data.text->fontsize); @@ -5665,19 +5575,17 @@ static void gl2psPrintPGFPrimitive(void *data) fprintf(gl2ps->stream, "}{}{\\pgfusepath{discard}}}"); - if(prim->data.text->angle) - fprintf(gl2ps->stream, "}"); + if(prim->data.text->angle) fprintf(gl2ps->stream, "}"); fprintf(gl2ps->stream, "\n"); break; - case GL2PS_SPECIAL : + case GL2PS_SPECIAL: /* alignment contains the format for which the special output text is intended */ - if (prim->data.text->alignment == GL2PS_PGF) + if(prim->data.text->alignment == GL2PS_PGF) fprintf(gl2ps->stream, "%s\n", prim->data.text->str); break; - default : - break; + default: break; } } @@ -5696,17 +5604,17 @@ static void gl2psPrintPGFBeginViewport(GLint viewport[4]) gl2psResetLineProperties(); - if(gl2ps->header){ + if(gl2ps->header) { gl2psPrintPGFHeader(); gl2ps->header = GL_FALSE; } fprintf(gl2ps->stream, "\\begin{pgfscope}\n"); - if(gl2ps->options & GL2PS_DRAW_BACKGROUND){ - if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0){ + if(gl2ps->options & GL2PS_DRAW_BACKGROUND) { + if(gl2ps->colormode == GL_RGBA || gl2ps->colorsize == 0) { glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba); } - else{ + else { glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx); rgba[0] = gl2ps->colormap[idx][0]; rgba[1] = gl2ps->colormap[idx][1]; @@ -5736,22 +5644,18 @@ static GLint gl2psPrintPGFEndViewport(void) return res; } -static void gl2psPrintPGFFinalPrimitive(void) -{ -} +static void gl2psPrintPGFFinalPrimitive(void) {} /* definition of the PGF backend */ -static GL2PSbackend gl2psPGF = { - gl2psPrintPGFHeader, - gl2psPrintPGFFooter, - gl2psPrintPGFBeginViewport, - gl2psPrintPGFEndViewport, - gl2psPrintPGFPrimitive, - gl2psPrintPGFFinalPrimitive, - "tex", - "PGF Latex Graphics" -}; +static GL2PSbackend gl2psPGF = {gl2psPrintPGFHeader, + gl2psPrintPGFFooter, + gl2psPrintPGFBeginViewport, + gl2psPrintPGFEndViewport, + gl2psPrintPGFPrimitive, + gl2psPrintPGFFinalPrimitive, + "tex", + "PGF Latex Graphics"}; /********************************************************************* * @@ -5763,12 +5667,12 @@ static GL2PSbackend gl2psPGF = { #defines in gl2ps.h */ static GL2PSbackend *gl2psbackends[] = { - &gl2psPS, /* 0 */ + &gl2psPS, /* 0 */ &gl2psEPS, /* 1 */ &gl2psTEX, /* 2 */ &gl2psPDF, /* 3 */ &gl2psSVG, /* 4 */ - &gl2psPGF /* 5 */ + &gl2psPGF /* 5 */ }; static void gl2psComputeTightBoundingBox(void *data) @@ -5776,9 +5680,9 @@ static void gl2psComputeTightBoundingBox(void *data) GL2PSprimitive *prim; int i; - prim = *(GL2PSprimitive**)data; + prim = *(GL2PSprimitive **)data; - for(i = 0; i < prim->numverts; i++){ + for(i = 0; i < prim->numverts; i++) { if(prim->verts[i].xyz[0] < gl2ps->viewport[0]) gl2ps->viewport[0] = (GLint)prim->verts[i].xyz[0]; if(prim->verts[i].xyz[0] > gl2ps->viewport[2]) @@ -5796,23 +5700,22 @@ static GLint gl2psPrintPrimitives(void) GL2PSxyz eye = {0.0F, 0.0F, 100.0F * GL2PS_ZSCALE}; GLint used = 0; - if ((gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) == GL2PS_NONE) { + if((gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) == GL2PS_NONE) { used = glRenderMode(GL_RENDER); } - if(used < 0){ + if(used < 0) { gl2psMsg(GL2PS_INFO, "OpenGL feedback buffer overflow"); return GL2PS_OVERFLOW; } - if(used > 0) - gl2psParseFeedbackBuffer(used); + if(used > 0) gl2psParseFeedbackBuffer(used); gl2psRescaleAndOffset(); - if(gl2ps->header){ + if(gl2ps->header) { if(gl2psListNbr(gl2ps->primitives) && - (gl2ps->options & GL2PS_TIGHT_BOUNDING_BOX)){ + (gl2ps->options & GL2PS_TIGHT_BOUNDING_BOX)) { gl2ps->viewport[0] = gl2ps->viewport[1] = 100000; gl2ps->viewport[2] = gl2ps->viewport[3] = -100000; gl2psListAction(gl2ps->primitives, gl2psComputeTightBoundingBox); @@ -5821,34 +5724,36 @@ static GLint gl2psPrintPrimitives(void) gl2ps->header = GL_FALSE; } - if(!gl2psListNbr(gl2ps->primitives)){ + if(!gl2psListNbr(gl2ps->primitives)) { /* empty feedback buffer and/or nothing else to print */ return GL2PS_NO_FEEDBACK; } - switch(gl2ps->sort){ - case GL2PS_NO_SORT : - gl2psListAction(gl2ps->primitives, gl2psbackends[gl2ps->format]->printPrimitive); + switch(gl2ps->sort) { + case GL2PS_NO_SORT: + gl2psListAction(gl2ps->primitives, + gl2psbackends[gl2ps->format]->printPrimitive); gl2psListAction(gl2ps->primitives, gl2psFreePrimitive); /* reset the primitive list, waiting for the next viewport */ gl2psListReset(gl2ps->primitives); break; - case GL2PS_SIMPLE_SORT : + case GL2PS_SIMPLE_SORT: gl2psListSort(gl2ps->primitives, gl2psCompareDepth); - if(gl2ps->options & GL2PS_OCCLUSION_CULL){ + if(gl2ps->options & GL2PS_OCCLUSION_CULL) { gl2psListActionInverse(gl2ps->primitives, gl2psAddInImageTree); gl2psFreeBspImageTree(&gl2ps->imagetree); } - gl2psListAction(gl2ps->primitives, gl2psbackends[gl2ps->format]->printPrimitive); + gl2psListAction(gl2ps->primitives, + gl2psbackends[gl2ps->format]->printPrimitive); gl2psListAction(gl2ps->primitives, gl2psFreePrimitive); /* reset the primitive list, waiting for the next viewport */ gl2psListReset(gl2ps->primitives); break; - case GL2PS_BSP_SORT : - root = (GL2PSbsptree*)gl2psMalloc(sizeof(GL2PSbsptree)); + case GL2PS_BSP_SORT: + root = (GL2PSbsptree *)gl2psMalloc(sizeof(GL2PSbsptree)); gl2psBuildBspTree(root, gl2ps->primitives); if(GL_TRUE == gl2ps->boundary) gl2psBuildPolygonBoundary(root); - if(gl2ps->options & GL2PS_OCCLUSION_CULL){ + if(gl2ps->options & GL2PS_OCCLUSION_CULL) { gl2psTraverseBspTree(root, eye, -GL2PS_EPSILON, gl2psLess, gl2psAddInImageTree, 1); gl2psFreeBspImageTree(&gl2ps->imagetree); @@ -5858,7 +5763,7 @@ static GLint gl2psPrintPrimitives(void) gl2psFreeBspTree(&root); /* reallocate the primitive list (it's been deleted by gl2psBuildBspTree) in case there is another viewport */ - gl2ps->primitives = gl2psListCreate(500, 500, sizeof(GL2PSprimitive*)); + gl2ps->primitives = gl2psListCreate(500, 500, sizeof(GL2PSprimitive *)); break; } gl2psbackends[gl2ps->format]->printFinalPrimitive(); @@ -5868,23 +5773,23 @@ static GLint gl2psPrintPrimitives(void) static GLboolean gl2psCheckOptions(GLint options, GLint colormode) { - if (options & GL2PS_NO_OPENGL_CONTEXT) { - if (options & GL2PS_DRAW_BACKGROUND) { + if(options & GL2PS_NO_OPENGL_CONTEXT) { + if(options & GL2PS_DRAW_BACKGROUND) { gl2psMsg(GL2PS_ERROR, "Options GL2PS_NO_OPENGL_CONTEXT and " "GL2PS_DRAW_BACKGROUND are incompatible."); return GL_FALSE; } - if (options & GL2PS_USE_CURRENT_VIEWPORT) { + if(options & GL2PS_USE_CURRENT_VIEWPORT) { gl2psMsg(GL2PS_ERROR, "Options GL2PS_NO_OPENGL_CONTEXT and " "GL2PS_USE_CURRENT_VIEWPORT are incompatible."); return GL_FALSE; } - if ((options & GL2PS_NO_BLENDING) == GL2PS_NONE) { + if((options & GL2PS_NO_BLENDING) == GL2PS_NONE) { gl2psMsg(GL2PS_ERROR, "Option GL2PS_NO_OPENGL_CONTEXT requires " "option GL2PS_NO_BLENDING."); return GL_FALSE; } - if (colormode != GL_RGBA) { + if(colormode != GL_RGBA) { gl2psMsg(GL2PS_ERROR, "Option GL2PS_NO_OPENGL_CONTEXT requires colormode " "to be GL_RGBA."); return GL_FALSE; @@ -5904,27 +5809,29 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, GLint viewport[4], GLint format, GLint sort, GLint options, GLint colormode, GLint colorsize, GL2PSrgba *colormap, - GLint nr, GLint ng, GLint nb, GLint buffersize, - FILE *stream, const char *filename) + GLint nr, GLint ng, GLint nb, + GLint buffersize, FILE *stream, + const char *filename) { GLint idx; int i; - if(gl2ps){ + if(gl2ps) { gl2psMsg(GL2PS_ERROR, "gl2psBeginPage called in wrong program state"); return GL2PS_ERROR; } - gl2ps = (GL2PScontext*)gl2psMalloc(sizeof(GL2PScontext)); + gl2ps = (GL2PScontext *)gl2psMalloc(sizeof(GL2PScontext)); /* Validate options */ - if (gl2psCheckOptions(options, colormode) == GL_FALSE) { + if(gl2psCheckOptions(options, colormode) == GL_FALSE) { gl2psFree(gl2ps); gl2ps = NULL; return GL2PS_ERROR; } - if(format >= 0 && format < (GLint)(sizeof(gl2psbackends) / sizeof(gl2psbackends[0]))){ + if(format >= 0 && + format < (GLint)(sizeof(gl2psbackends) / sizeof(gl2psbackends[0]))) { gl2ps->format = format; } else { @@ -5934,23 +5841,21 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, return GL2PS_ERROR; } - switch(sort){ - case GL2PS_NO_SORT : - case GL2PS_SIMPLE_SORT : - case GL2PS_BSP_SORT : - gl2ps->sort = sort; - break; - default : + switch(sort) { + case GL2PS_NO_SORT: + case GL2PS_SIMPLE_SORT: + case GL2PS_BSP_SORT: gl2ps->sort = sort; break; + default: gl2psMsg(GL2PS_ERROR, "Unknown sorting algorithm: %d", sort); gl2psFree(gl2ps); gl2ps = NULL; return GL2PS_ERROR; } - if(stream){ + if(stream) { gl2ps->stream = stream; } - else{ + else { gl2psMsg(GL2PS_ERROR, "Bad file pointer"); gl2psFree(gl2ps); gl2ps = NULL; @@ -5965,19 +5870,20 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, gl2ps->imagemap_head = NULL; gl2ps->imagemap_tail = NULL; - if(gl2ps->options & GL2PS_USE_CURRENT_VIEWPORT){ + if(gl2ps->options & GL2PS_USE_CURRENT_VIEWPORT) { glGetIntegerv(GL_VIEWPORT, gl2ps->viewport); } - else{ - for(i = 0; i < 4; i++){ + else { + for(i = 0; i < 4; i++) { gl2ps->viewport[i] = viewport[i]; } } - if(!gl2ps->viewport[2] || !gl2ps->viewport[3]){ - gl2psMsg(GL2PS_ERROR, "Incorrect viewport (x=%d, y=%d, width=%d, height=%d)", - gl2ps->viewport[0], gl2ps->viewport[1], - gl2ps->viewport[2], gl2ps->viewport[3]); + if(!gl2ps->viewport[2] || !gl2ps->viewport[3]) { + gl2psMsg(GL2PS_ERROR, + "Incorrect viewport (x=%d, y=%d, width=%d, height=%d)", + gl2ps->viewport[0], gl2ps->viewport[1], gl2ps->viewport[2], + gl2ps->viewport[3]); gl2psFree(gl2ps); gl2ps = NULL; return GL2PS_ERROR; @@ -5988,10 +5894,10 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, gl2ps->threshold[2] = nb ? 1.0F / (GLfloat)nb : 0.100F; gl2ps->colormode = colormode; gl2ps->buffersize = buffersize > 0 ? buffersize : 2048 * 2048; - for(i = 0; i < 3; i++){ + for(i = 0; i < 3; i++) { gl2ps->lastvertex.xyz[i] = -1.0F; } - for(i = 0; i < 4; i++){ + for(i = 0; i < 4; i++) { gl2ps->lastvertex.rgba[i] = -1.0F; gl2ps->lastrgba[i] = -1.0F; } @@ -6009,9 +5915,9 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, /* get default blending mode from current OpenGL state (enabled by default for SVG) */ - if ((gl2ps->options & GL2PS_NO_BLENDING) == GL2PS_NONE) { - gl2ps->blending = (gl2ps->format == GL2PS_SVG) ? GL_TRUE - : glIsEnabled(GL_BLEND); + if((gl2ps->options & GL2PS_NO_BLENDING) == GL2PS_NONE) { + gl2ps->blending = + (gl2ps->format == GL2PS_SVG) ? GL_TRUE : glIsEnabled(GL_BLEND); glGetIntegerv(GL_BLEND_SRC, &gl2ps->blendfunc[0]); glGetIntegerv(GL_BLEND_DST, &gl2ps->blendfunc[1]); } @@ -6019,22 +5925,23 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, gl2ps->blending = GL_FALSE; } - if(gl2ps->colormode == GL_RGBA){ + if(gl2ps->colormode == GL_RGBA) { gl2ps->colorsize = 0; gl2ps->colormap = NULL; - if ((gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) == GL2PS_NONE) { + if((gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) == GL2PS_NONE) { glGetFloatv(GL_COLOR_CLEAR_VALUE, gl2ps->bgcolor); } } - else if(gl2ps->colormode == GL_COLOR_INDEX){ - if(!colorsize || !colormap){ + else if(gl2ps->colormode == GL_COLOR_INDEX) { + if(!colorsize || !colormap) { gl2psMsg(GL2PS_ERROR, "Missing colormap for GL_COLOR_INDEX rendering"); gl2psFree(gl2ps); gl2ps = NULL; return GL2PS_ERROR; } gl2ps->colorsize = colorsize; - gl2ps->colormap = (GL2PSrgba*)gl2psMalloc(gl2ps->colorsize * sizeof(GL2PSrgba)); + gl2ps->colormap = + (GL2PSrgba *)gl2psMalloc(gl2ps->colorsize * sizeof(GL2PSrgba)); memcpy(gl2ps->colormap, colormap, gl2ps->colorsize * sizeof(GL2PSrgba)); glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx); gl2ps->bgcolor[0] = gl2ps->colormap[idx][0]; @@ -6042,45 +5949,48 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, gl2ps->bgcolor[2] = gl2ps->colormap[idx][2]; gl2ps->bgcolor[3] = 1.0F; } - else{ + else { gl2psMsg(GL2PS_ERROR, "Unknown color mode in gl2psBeginPage"); gl2psFree(gl2ps); gl2ps = NULL; return GL2PS_ERROR; } - if(!title){ - gl2ps->title = (char*)gl2psMalloc(sizeof(char)); + if(!title) { + gl2ps->title = (char *)gl2psMalloc(sizeof(char)); gl2ps->title[0] = '\0'; } - else{ - gl2ps->title = (char*)gl2psMalloc((strlen(title)+1)*sizeof(char)); + else { + gl2ps->title = (char *)gl2psMalloc((strlen(title) + 1) * sizeof(char)); strcpy(gl2ps->title, title); } - if(!producer){ - gl2ps->producer = (char*)gl2psMalloc(sizeof(char)); + if(!producer) { + gl2ps->producer = (char *)gl2psMalloc(sizeof(char)); gl2ps->producer[0] = '\0'; } - else{ - gl2ps->producer = (char*)gl2psMalloc((strlen(producer)+1)*sizeof(char)); + else { + gl2ps->producer = + (char *)gl2psMalloc((strlen(producer) + 1) * sizeof(char)); strcpy(gl2ps->producer, producer); } - if(!filename){ - gl2ps->filename = (char*)gl2psMalloc(sizeof(char)); + if(!filename) { + gl2ps->filename = (char *)gl2psMalloc(sizeof(char)); gl2ps->filename[0] = '\0'; } - else{ - gl2ps->filename = (char*)gl2psMalloc((strlen(filename)+1)*sizeof(char)); + else { + gl2ps->filename = + (char *)gl2psMalloc((strlen(filename) + 1) * sizeof(char)); strcpy(gl2ps->filename, filename); } - gl2ps->primitives = gl2psListCreate(500, 500, sizeof(GL2PSprimitive*)); - gl2ps->auxprimitives = gl2psListCreate(100, 100, sizeof(GL2PSprimitive*)); + gl2ps->primitives = gl2psListCreate(500, 500, sizeof(GL2PSprimitive *)); + gl2ps->auxprimitives = gl2psListCreate(100, 100, sizeof(GL2PSprimitive *)); - if ((gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) == GL2PS_NONE) { - gl2ps->feedback = (GLfloat*)gl2psMalloc(gl2ps->buffersize * sizeof(GLfloat)); + if((gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) == GL2PS_NONE) { + gl2ps->feedback = + (GLfloat *)gl2psMalloc(gl2ps->buffersize * sizeof(GLfloat)); glFeedbackBuffer(gl2ps->buffersize, GL_3D_COLOR, gl2ps->feedback); glRenderMode(GL_FEEDBACK); } @@ -6100,8 +6010,7 @@ GL2PSDLL_API GLint gl2psEndPage(void) res = gl2psPrintPrimitives(); - if(res != GL2PS_OVERFLOW) - (gl2psbackends[gl2ps->format]->printFooter)(); + if(res != GL2PS_OVERFLOW) (gl2psbackends[gl2ps->format]->printFooter)(); fflush(gl2ps->stream); @@ -6143,20 +6052,23 @@ GL2PSDLL_API GLint gl2psEndViewport(void) } GL2PSDLL_API GLint gl2psTextOptColor(const char *str, const char *fontname, - GLshort fontsize, GLint alignment, GLfloat angle, - GL2PSrgba color) + GLshort fontsize, GLint alignment, + GLfloat angle, GL2PSrgba color) { return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, alignment, angle, color); } GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname, - GLshort fontsize, GLint alignment, GLfloat angle) + GLshort fontsize, GLint alignment, + GLfloat angle) { - return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, alignment, angle, NULL); + return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, alignment, angle, + NULL); } -GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GLshort fontsize) +GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, + GLshort fontsize) { return gl2psAddText(GL2PS_TEXT, str, fontname, fontsize, GL2PS_TEXT_BL, 0.0F, NULL); @@ -6167,14 +6079,14 @@ GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str) return gl2psAddText(GL2PS_SPECIAL, str, "", 0, format, 0.0F, NULL); } -GL2PSDLL_API GLint gl2psSpecialColor(GLint format, const char *str, GL2PSrgba rgba) +GL2PSDLL_API GLint gl2psSpecialColor(GLint format, const char *str, + GL2PSrgba rgba) { return gl2psAddText(GL2PS_SPECIAL, str, "", 0, format, 0.0F, rgba); } -GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, - GLint xorig, GLint yorig, - GLenum format, GLenum type, +GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GLint xorig, + GLint yorig, GLenum format, GLenum type, const void *pixels) { int size, i; @@ -6189,13 +6101,13 @@ GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, if(gl2ps->options & GL2PS_NO_PIXMAP) return GL2PS_SUCCESS; - if((format != GL_RGB && format != GL_RGBA) || type != GL_FLOAT){ + if((format != GL_RGB && format != GL_RGBA) || type != GL_FLOAT) { gl2psMsg(GL2PS_ERROR, "gl2psDrawPixels only implemented for " - "GL_RGB/GL_RGBA, GL_FLOAT pixels"); + "GL_RGB/GL_RGBA, GL_FLOAT pixels"); return GL2PS_ERROR; } - if (gl2ps->forcerasterpos) { + if(gl2ps->forcerasterpos) { pos[0] = gl2ps->rasterpos.xyz[0]; pos[1] = gl2ps->rasterpos.xyz[1]; pos[2] = gl2ps->rasterpos.xyz[2]; @@ -6212,11 +6124,11 @@ GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, glGetFloatv(GL_ZOOM_Y, &zoom_y); } - prim = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); + prim = (GL2PSprimitive *)gl2psMalloc(sizeof(GL2PSprimitive)); prim->type = GL2PS_PIXMAP; prim->boundary = 0; prim->numverts = 1; - prim->verts = (GL2PSvertex*)gl2psMalloc(sizeof(GL2PSvertex)); + prim->verts = (GL2PSvertex *)gl2psMalloc(sizeof(GL2PSvertex)); prim->verts[0].xyz[0] = pos[0] + xorig; prim->verts[0].xyz[1] = pos[1] + yorig; prim->verts[0].xyz[2] = pos[2]; @@ -6227,7 +6139,7 @@ GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, prim->pattern = 0; prim->factor = 0; prim->width = 1; - if (gl2ps->forcerasterpos) { + if(gl2ps->forcerasterpos) { prim->verts[0].rgba[0] = gl2ps->rasterpos.rgba[0]; prim->verts[0].rgba[1] = gl2ps->rasterpos.rgba[1]; prim->verts[0].rgba[2] = gl2ps->rasterpos.rgba[2]; @@ -6236,7 +6148,7 @@ GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, else { glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba); } - prim->data.image = (GL2PSimage*)gl2psMalloc(sizeof(GL2PSimage)); + prim->data.image = (GL2PSimage *)gl2psMalloc(sizeof(GL2PSimage)); prim->data.image->width = width; prim->data.image->height = height; prim->data.image->zoom_x = zoom_x; @@ -6246,36 +6158,35 @@ GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, gl2ps->forcerasterpos = GL_FALSE; - switch(format){ + switch(format) { case GL_RGBA: - if(gl2ps->options & GL2PS_NO_BLENDING || !gl2ps->blending){ + if(gl2ps->options & GL2PS_NO_BLENDING || !gl2ps->blending) { /* special case: blending turned off */ prim->data.image->format = GL_RGB; size = height * width * 3; - prim->data.image->pixels = (GLfloat*)gl2psMalloc(size * sizeof(GLfloat)); - piv = (const GLfloat*)pixels; - for(i = 0; i < size; ++i, ++piv){ + prim->data.image->pixels = (GLfloat *)gl2psMalloc(size * sizeof(GLfloat)); + piv = (const GLfloat *)pixels; + for(i = 0; i < size; ++i, ++piv) { prim->data.image->pixels[i] = *piv; - if(!((i + 1) % 3)) - ++piv; + if(!((i + 1) % 3)) ++piv; } } - else{ + else { size = height * width * 4; - prim->data.image->pixels = (GLfloat*)gl2psMalloc(size * sizeof(GLfloat)); + prim->data.image->pixels = (GLfloat *)gl2psMalloc(size * sizeof(GLfloat)); memcpy(prim->data.image->pixels, pixels, size * sizeof(GLfloat)); } break; case GL_RGB: default: size = height * width * 3; - prim->data.image->pixels = (GLfloat*)gl2psMalloc(size * sizeof(GLfloat)); + prim->data.image->pixels = (GLfloat *)gl2psMalloc(size * sizeof(GLfloat)); memcpy(prim->data.image->pixels, pixels, size * sizeof(GLfloat)); break; } /* If no OpenGL context, just add directly to primitives */ - if ((gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) == GL2PS_NONE) { + if((gl2ps->options & GL2PS_NO_OPENGL_CONTEXT) == GL2PS_NONE) { gl2psListAdd(gl2ps->auxprimitives, &prim); glPassThrough(GL2PS_DRAW_PIXELS_TOKEN); } @@ -6288,7 +6199,8 @@ GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GL2PSDLL_API GLint gl2psDrawImageMap(GLsizei width, GLsizei height, const GLfloat position[3], - const unsigned char *imagemap){ + const unsigned char *imagemap) +{ int size, i; int sizeoffloat = sizeof(GLfloat); @@ -6299,12 +6211,12 @@ GL2PSDLL_API GLint gl2psDrawImageMap(GLsizei width, GLsizei height, size = height + height * ((width - 1) / 8); glPassThrough(GL2PS_IMAGEMAP_TOKEN); glBegin(GL_POINTS); - glVertex3f(position[0], position[1],position[2]); + glVertex3f(position[0], position[1], position[2]); glEnd(); glPassThrough((GLfloat)width); glPassThrough((GLfloat)height); - for(i = 0; i < size; i += sizeoffloat){ - const float *value = (const float*)imagemap; + for(i = 0; i < size; i += sizeoffloat) { + const float *value = (const float *)imagemap; glPassThrough(*value); imagemap += sizeoffloat; } @@ -6318,28 +6230,24 @@ GL2PSDLL_API GLint gl2psEnable(GLint mode) if(!gl2ps) return GL2PS_UNINITIALIZED; - switch(mode){ - case GL2PS_POLYGON_OFFSET_FILL : + switch(mode) { + case GL2PS_POLYGON_OFFSET_FILL: glPassThrough(GL2PS_BEGIN_OFFSET_TOKEN); glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &tmp2); glPassThrough(tmp2); glGetFloatv(GL_POLYGON_OFFSET_UNITS, &tmp2); glPassThrough(tmp2); break; - case GL2PS_POLYGON_BOUNDARY : - glPassThrough(GL2PS_BEGIN_BOUNDARY_TOKEN); - break; - case GL2PS_LINE_STIPPLE : + case GL2PS_POLYGON_BOUNDARY: glPassThrough(GL2PS_BEGIN_BOUNDARY_TOKEN); break; + case GL2PS_LINE_STIPPLE: glPassThrough(GL2PS_BEGIN_STIPPLE_TOKEN); glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &tmp); glPassThrough((GLfloat)tmp); glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &tmp); glPassThrough((GLfloat)tmp); break; - case GL2PS_BLEND : - glPassThrough(GL2PS_BEGIN_BLEND_TOKEN); - break; - default : + case GL2PS_BLEND: glPassThrough(GL2PS_BEGIN_BLEND_TOKEN); break; + default: gl2psMsg(GL2PS_WARNING, "Unknown mode in gl2psEnable: %d", mode); return GL2PS_WARNING; } @@ -6351,20 +6259,12 @@ GL2PSDLL_API GLint gl2psDisable(GLint mode) { if(!gl2ps) return GL2PS_UNINITIALIZED; - switch(mode){ - case GL2PS_POLYGON_OFFSET_FILL : - glPassThrough(GL2PS_END_OFFSET_TOKEN); - break; - case GL2PS_POLYGON_BOUNDARY : - glPassThrough(GL2PS_END_BOUNDARY_TOKEN); - break; - case GL2PS_LINE_STIPPLE : - glPassThrough(GL2PS_END_STIPPLE_TOKEN); - break; - case GL2PS_BLEND : - glPassThrough(GL2PS_END_BLEND_TOKEN); - break; - default : + switch(mode) { + case GL2PS_POLYGON_OFFSET_FILL: glPassThrough(GL2PS_END_OFFSET_TOKEN); break; + case GL2PS_POLYGON_BOUNDARY: glPassThrough(GL2PS_END_BOUNDARY_TOKEN); break; + case GL2PS_LINE_STIPPLE: glPassThrough(GL2PS_END_STIPPLE_TOKEN); break; + case GL2PS_BLEND: glPassThrough(GL2PS_END_BLEND_TOKEN); break; + default: gl2psMsg(GL2PS_WARNING, "Unknown mode in gl2psDisable: %d", mode); return GL2PS_WARNING; } @@ -6454,7 +6354,8 @@ GL2PSDLL_API GLint gl2psGetOptions(GLint *options) GL2PSDLL_API const char *gl2psGetFileExtension(GLint format) { - if(format >= 0 && format < (GLint)(sizeof(gl2psbackends) / sizeof(gl2psbackends[0]))) + if(format >= 0 && + format < (GLint)(sizeof(gl2psbackends) / sizeof(gl2psbackends[0]))) return gl2psbackends[format]->file_extension; else return "Unknown format"; @@ -6462,20 +6363,17 @@ GL2PSDLL_API const char *gl2psGetFileExtension(GLint format) GL2PSDLL_API const char *gl2psGetFormatDescription(GLint format) { - if(format >= 0 && format < (GLint)(sizeof(gl2psbackends) / sizeof(gl2psbackends[0]))) + if(format >= 0 && + format < (GLint)(sizeof(gl2psbackends) / sizeof(gl2psbackends[0]))) return gl2psbackends[format]->description; else return "Unknown format"; } -GL2PSDLL_API GLint gl2psGetFileFormat() -{ - return gl2ps->format; -} +GL2PSDLL_API GLint gl2psGetFileFormat() { return gl2ps->format; } GL2PSDLL_API GLint gl2psForceRasterPos(GL2PSvertex *vert) { - if(!gl2ps) { return GL2PS_UNINITIALIZED; } diff --git a/Graphics/gl2ps.h b/Graphics/gl2ps.h index 513608a739ad0f59724acd5d408417cc637487c1..8bca0e76a357a39ab214b9c10e1aa023b675a405 100644 --- a/Graphics/gl2ps.h +++ b/Graphics/gl2ps.h @@ -43,43 +43,43 @@ /* Define GL2PSDLL at compile time to build a Windows DLL */ #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) -# if defined(_MSC_VER) -# pragma warning(disable:4115) -# pragma warning(disable:4127) -# pragma warning(disable:4996) -# endif -# include <windows.h> -# if defined(GL2PSDLL) -# if defined(GL2PSDLL_EXPORTS) -# define GL2PSDLL_API __declspec(dllexport) -# else -# define GL2PSDLL_API __declspec(dllimport) -# endif -# else -# define GL2PSDLL_API -# endif +#if defined(_MSC_VER) +#pragma warning(disable : 4115) +#pragma warning(disable : 4127) +#pragma warning(disable : 4996) +#endif +#include <windows.h> +#if defined(GL2PSDLL) +#if defined(GL2PSDLL_EXPORTS) +#define GL2PSDLL_API __declspec(dllexport) +#else +#define GL2PSDLL_API __declspec(dllimport) +#endif #else -# define GL2PSDLL_API +#define GL2PSDLL_API +#endif +#else +#define GL2PSDLL_API #endif #if defined(__APPLE__) || defined(HAVE_OPENGL_GL_H) -# include <OpenGL/gl.h> +#include <OpenGL/gl.h> #else -# include <GL/gl.h> +#include <GL/gl.h> #endif /* Support for compressed PostScript/PDF/SVG and for embedded PNG images in SVG */ #if defined(HAVE_ZLIB) || defined(HAVE_LIBZ) -# define GL2PS_HAVE_ZLIB -# if defined(HAVE_LIBPNG) || defined(HAVE_PNG) -# define GL2PS_HAVE_LIBPNG -# endif +#define GL2PS_HAVE_ZLIB +#if defined(HAVE_LIBPNG) || defined(HAVE_PNG) +#define GL2PS_HAVE_LIBPNG +#endif #endif #if defined(HAVE_NO_VSNPRINTF) -# define GL2PS_HAVE_NO_VSNPRINTF +#define GL2PS_HAVE_NO_VSNPRINTF #endif /* Version number */ @@ -89,15 +89,15 @@ #define GL2PS_PATCH_VERSION 0 #define GL2PS_EXTRA_VERSION "" -#define GL2PS_VERSION (GL2PS_MAJOR_VERSION + \ - 0.01 * GL2PS_MINOR_VERSION + \ - 0.0001 * GL2PS_PATCH_VERSION) +#define GL2PS_VERSION \ + (GL2PS_MAJOR_VERSION + 0.01 * GL2PS_MINOR_VERSION + \ + 0.0001 * GL2PS_PATCH_VERSION) #define GL2PS_COPYRIGHT "(C) 1999-2017 C. Geuzaine" /* Output file formats (the values and the ordering are important!) */ -#define GL2PS_PS 0 +#define GL2PS_PS 0 #define GL2PS_EPS 1 #define GL2PS_TEX 2 #define GL2PS_PDF 3 @@ -106,55 +106,54 @@ /* Sorting algorithms */ -#define GL2PS_NO_SORT 1 +#define GL2PS_NO_SORT 1 #define GL2PS_SIMPLE_SORT 2 -#define GL2PS_BSP_SORT 3 +#define GL2PS_BSP_SORT 3 /* Message levels and error codes */ -#define GL2PS_SUCCESS 0 -#define GL2PS_INFO 1 -#define GL2PS_WARNING 2 -#define GL2PS_ERROR 3 -#define GL2PS_NO_FEEDBACK 4 -#define GL2PS_OVERFLOW 5 +#define GL2PS_SUCCESS 0 +#define GL2PS_INFO 1 +#define GL2PS_WARNING 2 +#define GL2PS_ERROR 3 +#define GL2PS_NO_FEEDBACK 4 +#define GL2PS_OVERFLOW 5 #define GL2PS_UNINITIALIZED 6 /* Options for gl2psBeginPage */ -#define GL2PS_NONE 0 -#define GL2PS_DRAW_BACKGROUND (1<<0) -#define GL2PS_SIMPLE_LINE_OFFSET (1<<1) -#define GL2PS_SILENT (1<<2) -#define GL2PS_BEST_ROOT (1<<3) -#define GL2PS_OCCLUSION_CULL (1<<4) -#define GL2PS_NO_TEXT (1<<5) -#define GL2PS_LANDSCAPE (1<<6) -#define GL2PS_NO_PS3_SHADING (1<<7) -#define GL2PS_NO_PIXMAP (1<<8) -#define GL2PS_USE_CURRENT_VIEWPORT (1<<9) -#define GL2PS_COMPRESS (1<<10) -#define GL2PS_NO_BLENDING (1<<11) -#define GL2PS_TIGHT_BOUNDING_BOX (1<<12) -#define GL2PS_NO_OPENGL_CONTEXT (1<<13) +#define GL2PS_NONE 0 +#define GL2PS_DRAW_BACKGROUND (1 << 0) +#define GL2PS_SIMPLE_LINE_OFFSET (1 << 1) +#define GL2PS_SILENT (1 << 2) +#define GL2PS_BEST_ROOT (1 << 3) +#define GL2PS_OCCLUSION_CULL (1 << 4) +#define GL2PS_NO_TEXT (1 << 5) +#define GL2PS_LANDSCAPE (1 << 6) +#define GL2PS_NO_PS3_SHADING (1 << 7) +#define GL2PS_NO_PIXMAP (1 << 8) +#define GL2PS_USE_CURRENT_VIEWPORT (1 << 9) +#define GL2PS_COMPRESS (1 << 10) +#define GL2PS_NO_BLENDING (1 << 11) +#define GL2PS_TIGHT_BOUNDING_BOX (1 << 12) +#define GL2PS_NO_OPENGL_CONTEXT (1 << 13) /* Arguments for gl2psEnable/gl2psDisable */ #define GL2PS_POLYGON_OFFSET_FILL 1 -#define GL2PS_POLYGON_BOUNDARY 2 -#define GL2PS_LINE_STIPPLE 3 -#define GL2PS_BLEND 4 - +#define GL2PS_POLYGON_BOUNDARY 2 +#define GL2PS_LINE_STIPPLE 3 +#define GL2PS_BLEND 4 /* Arguments for gl2psLineCap/Join */ -#define GL2PS_LINE_CAP_BUTT 0 -#define GL2PS_LINE_CAP_ROUND 1 -#define GL2PS_LINE_CAP_SQUARE 2 +#define GL2PS_LINE_CAP_BUTT 0 +#define GL2PS_LINE_CAP_ROUND 1 +#define GL2PS_LINE_CAP_SQUARE 2 -#define GL2PS_LINE_JOIN_MITER 0 -#define GL2PS_LINE_JOIN_ROUND 1 -#define GL2PS_LINE_JOIN_BEVEL 2 +#define GL2PS_LINE_JOIN_MITER 0 +#define GL2PS_LINE_JOIN_ROUND 1 +#define GL2PS_LINE_JOIN_BEVEL 2 /* Text alignment (o=raster position; default mode is BL): +---+ +---+ +---+ +---+ +---+ +---+ +-o-+ o---+ +---o @@ -162,13 +161,13 @@ +---+ +---+ +---+ +-o-+ o---+ +---o +---+ +---+ +---+ C CL CR B BL BR T TL TR */ -#define GL2PS_TEXT_C 1 +#define GL2PS_TEXT_C 1 #define GL2PS_TEXT_CL 2 #define GL2PS_TEXT_CR 3 -#define GL2PS_TEXT_B 4 +#define GL2PS_TEXT_B 4 #define GL2PS_TEXT_BL 5 #define GL2PS_TEXT_BR 6 -#define GL2PS_TEXT_T 7 +#define GL2PS_TEXT_T 7 #define GL2PS_TEXT_TL 8 #define GL2PS_TEXT_TR 9 @@ -181,17 +180,17 @@ typedef struct { } GL2PSvertex; /* Primitive types */ -#define GL2PS_NO_TYPE -1 -#define GL2PS_TEXT 1 -#define GL2PS_POINT 2 -#define GL2PS_LINE 3 -#define GL2PS_QUADRANGLE 4 -#define GL2PS_TRIANGLE 5 -#define GL2PS_PIXMAP 6 -#define GL2PS_IMAGEMAP 7 +#define GL2PS_NO_TYPE -1 +#define GL2PS_TEXT 1 +#define GL2PS_POINT 2 +#define GL2PS_LINE 3 +#define GL2PS_QUADRANGLE 4 +#define GL2PS_TRIANGLE 5 +#define GL2PS_PIXMAP 6 +#define GL2PS_IMAGEMAP 7 #define GL2PS_IMAGEMAP_WRITTEN 8 #define GL2PS_IMAGEMAP_VISIBLE 9 -#define GL2PS_SPECIAL 10 +#define GL2PS_SPECIAL 10 #if defined(__cplusplus) extern "C" { @@ -201,8 +200,9 @@ GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer, GLint viewport[4], GLint format, GLint sort, GLint options, GLint colormode, GLint colorsize, GL2PSrgba *colormap, - GLint nr, GLint ng, GLint nb, GLint buffersize, - FILE *stream, const char *filename); + GLint nr, GLint ng, GLint nb, + GLint buffersize, FILE *stream, + const char *filename); GL2PSDLL_API GLint gl2psEndPage(void); GL2PSDLL_API GLint gl2psSetOptions(GLint options); GL2PSDLL_API GLint gl2psGetOptions(GLint *options); @@ -213,13 +213,14 @@ GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname, GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname, GLshort fontsize, GLint align, GLfloat angle); GL2PSDLL_API GLint gl2psTextOptColor(const char *str, const char *fontname, - GLshort fontsize, GLint align, GLfloat angle, - GL2PSrgba color); + GLshort fontsize, GLint align, + GLfloat angle, GL2PSrgba color); GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str); -GL2PSDLL_API GLint gl2psSpecialColor(GLint format, const char *str, GL2PSrgba rgba); -GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, - GLint xorig, GLint yorig, - GLenum format, GLenum type, const void *pixels); +GL2PSDLL_API GLint gl2psSpecialColor(GLint format, const char *str, + GL2PSrgba rgba); +GL2PSDLL_API GLint gl2psDrawPixels(GLsizei width, GLsizei height, GLint xorig, + GLint yorig, GLenum format, GLenum type, + const void *pixels); GL2PSDLL_API GLint gl2psEnable(GLint mode); GL2PSDLL_API GLint gl2psDisable(GLint mode); GL2PSDLL_API GLint gl2psPointSize(GLfloat value); diff --git a/Graphics/gl2yuv.cpp b/Graphics/gl2yuv.cpp index 35ce206abaead088f40da1900681c89c819f7cba..9cf1bb1e073dde4e46c541790bdbd0bc957e43f1 100644 --- a/Graphics/gl2yuv.cpp +++ b/Graphics/gl2yuv.cpp @@ -32,9 +32,9 @@ #include "MallocUtils.h" #include "gl2yuv.h" -void create_yuv(FILE * outfile, PixelBuffer *buffer) +void create_yuv(FILE *outfile, PixelBuffer *buffer) { - if(buffer->getFormat() != GL_RGB || buffer->getType() != GL_UNSIGNED_BYTE){ + if(buffer->getFormat() != GL_RGB || buffer->getType() != GL_UNSIGNED_BYTE) { Msg::Error("YUV only implemented for GL_RGB and GL_UNSIGNED_BYTE"); return; } @@ -108,51 +108,42 @@ void create_yuv(FILE * outfile, PixelBuffer *buffer) dcr = orig_cr[y / 2]; dcb = orig_cb[y / 2]; - for(x = 0; x < width; x += 2, dy0 += 2, dy1 += 2, dcr++, - dcb++, src0 += 6, src1 += 6) { - *dy0 = (unsigned char)(mult299[*src0] + - mult587[src0[1]] + mult114[src0[2]]); - - *dy1 = (unsigned char)(mult299[*src1] + - mult587[src1[1]] + mult114[src1[2]]); - - dy0[1] = (unsigned char)(mult299[src0[3]] + - mult587[src0[4]] + mult114[src0[5]]); - - dy1[1] = (unsigned char)(mult299[src1[3]] + - mult587[src1[4]] + mult114[src1[5]]); - - *dcb = (unsigned char)((mult16874[*src0] + - mult33126[src0[1]] + - mult5[src0[2]] + - mult16874[*src1] + - mult33126[src1[1]] + - mult5[src1[2]] + - mult16874[src0[3]] + - mult33126[src0[4]] + - mult5[src0[5]] + - mult16874[src1[3]] + - mult33126[src1[4]] + - mult5[src1[5]]) / cdivisor) + 128; - - *dcr = (unsigned char)((mult5[*src0] + - mult41869[src0[1]] + - mult08131[src0[2]] + - mult5[*src1] + - mult41869[src1[1]] + - mult08131[src1[2]] + - mult5[src0[3]] + - mult41869[src0[4]] + - mult08131[src0[5]] + - mult5[src1[3]] + - mult41869[src1[4]] + - mult08131[src1[5]]) / cdivisor) + 128; + for(x = 0; x < width; + x += 2, dy0 += 2, dy1 += 2, dcr++, dcb++, src0 += 6, src1 += 6) { + *dy0 = + (unsigned char)(mult299[*src0] + mult587[src0[1]] + mult114[src0[2]]); + + *dy1 = + (unsigned char)(mult299[*src1] + mult587[src1[1]] + mult114[src1[2]]); + + dy0[1] = + (unsigned char)(mult299[src0[3]] + mult587[src0[4]] + mult114[src0[5]]); + + dy1[1] = + (unsigned char)(mult299[src1[3]] + mult587[src1[4]] + mult114[src1[5]]); + + *dcb = (unsigned char)((mult16874[*src0] + mult33126[src0[1]] + + mult5[src0[2]] + mult16874[*src1] + + mult33126[src1[1]] + mult5[src1[2]] + + mult16874[src0[3]] + mult33126[src0[4]] + + mult5[src0[5]] + mult16874[src1[3]] + + mult33126[src1[4]] + mult5[src1[5]]) / + cdivisor) + + 128; + + *dcr = (unsigned char)((mult5[*src0] + mult41869[src0[1]] + + mult08131[src0[2]] + mult5[*src1] + + mult41869[src1[1]] + mult08131[src1[2]] + + mult5[src0[3]] + mult41869[src0[4]] + + mult08131[src0[5]] + mult5[src1[3]] + + mult41869[src1[4]] + mult08131[src1[5]]) / + cdivisor) + + 128; } } // Y - for(y = height - 1; y >= 0; y--) - fwrite(orig_y[y], 1, width, outfile); + for(y = height - 1; y >= 0; y--) fwrite(orig_y[y], 1, width, outfile); // U for(y = height / 2 - 1; y >= 0; y--) @@ -162,16 +153,12 @@ void create_yuv(FILE * outfile, PixelBuffer *buffer) for(y = height / 2 - 1; y >= 0; y--) fwrite(orig_cr[y], 1, width / 2, outfile); - for(y = 0; y < height; y++) - Free(orig_y[y]); + for(y = 0; y < height; y++) Free(orig_y[y]); Free(orig_y); - for(y = 0; y < height / 2; y++) - Free(orig_cr[y]); + for(y = 0; y < height / 2; y++) Free(orig_cr[y]); Free(orig_cr); - for(y = 0; y < height / 2; y++) - Free(orig_cb[y]); + for(y = 0; y < height / 2; y++) Free(orig_cb[y]); Free(orig_cb); - } diff --git a/Numeric/BasisFactory.cpp b/Numeric/BasisFactory.cpp index fe834d968622acd712ba3e788a7ec68cfa36d434..5d709aa75c02b3738a39af2071d20d77d584b032 100644 --- a/Numeric/BasisFactory.cpp +++ b/Numeric/BasisFactory.cpp @@ -14,171 +14,167 @@ #include <map> #include <cstddef> -std::map<int, nodalBasis*> BasisFactory::fs; -std::map<int, CondNumBasis*> BasisFactory::cs; -std::map<FuncSpaceData, JacobianBasis*> BasisFactory::js; -std::map<FuncSpaceData, bezierBasis*> BasisFactory::bs; -std::map<FuncSpaceData, GradientBasis*> BasisFactory::gs; +std::map<int, nodalBasis *> BasisFactory::fs; +std::map<int, CondNumBasis *> BasisFactory::cs; +std::map<FuncSpaceData, JacobianBasis *> BasisFactory::js; +std::map<FuncSpaceData, bezierBasis *> BasisFactory::bs; +std::map<FuncSpaceData, GradientBasis *> BasisFactory::gs; -const nodalBasis* BasisFactory::getNodalBasis(int tag) +const nodalBasis *BasisFactory::getNodalBasis(int tag) { // If the Basis has already been built, return it. - std::map<int, nodalBasis*>::const_iterator it = fs.find(tag); - if (it != fs.end()) { + std::map<int, nodalBasis *>::const_iterator it = fs.find(tag); + if(it != fs.end()) { return it->second; } // Get the parent type to see which kind of basis // we want to create - nodalBasis* F = NULL; - if (tag == MSH_TRI_MINI) + nodalBasis *F = NULL; + if(tag == MSH_TRI_MINI) F = new miniBasisTri(); - else if (tag == MSH_TET_MINI) + else if(tag == MSH_TET_MINI) F = new miniBasisTet(); else { int parentType = ElementType::getParentType(tag); switch(parentType) { - case(TYPE_PNT): - case(TYPE_LIN): - case(TYPE_TRI): - case(TYPE_QUA): - case(TYPE_PRI): - case(TYPE_TET): - case(TYPE_HEX): - F = new polynomialBasis(tag); - break; - case(TYPE_PYR): - F = new pyramidalBasis(tag); - break; - default: - Msg::Error("Unknown type of element %d (in BasisFactory)", tag); - return NULL; + case(TYPE_PNT): + case(TYPE_LIN): + case(TYPE_TRI): + case(TYPE_QUA): + case(TYPE_PRI): + case(TYPE_TET): + case(TYPE_HEX): F = new polynomialBasis(tag); break; + case(TYPE_PYR): F = new pyramidalBasis(tag); break; + default: + Msg::Error("Unknown type of element %d (in BasisFactory)", tag); + return NULL; } } - std::pair<std::map<int, nodalBasis*>::const_iterator, bool> inserted; + std::pair<std::map<int, nodalBasis *>::const_iterator, bool> inserted; #if defined(_OPENMP) - #pragma omp critical +#pragma omp critical #endif - { - inserted = fs.insert(std::make_pair(tag, F)); + { + inserted = fs.insert(std::make_pair(tag, F)); - if (!inserted.second) - delete F; - } + if(!inserted.second) delete F; + } return inserted.first->second; } -const JacobianBasis* BasisFactory::getJacobianBasis(FuncSpaceData fsd) +const JacobianBasis *BasisFactory::getJacobianBasis(FuncSpaceData fsd) { FuncSpaceData data = fsd.getForNonSerendipitySpace(); - std::map<FuncSpaceData, JacobianBasis*>::const_iterator it = js.find(data); - if (it != js.end()) return it->second; + std::map<FuncSpaceData, JacobianBasis *>::const_iterator it = js.find(data); + if(it != js.end()) return it->second; - JacobianBasis* J = new JacobianBasis(data); + JacobianBasis *J = new JacobianBasis(data); js.insert(std::make_pair(data, J)); return J; } -const JacobianBasis* BasisFactory::getJacobianBasis(int tag, int order) +const JacobianBasis *BasisFactory::getJacobianBasis(int tag, int order) { const int type = ElementType::getParentType(tag); - if (type != TYPE_PYR) + if(type != TYPE_PYR) return getJacobianBasis(FuncSpaceData(true, tag, order)); else - return getJacobianBasis(FuncSpaceData(true, tag, false, order+1, order)); + return getJacobianBasis(FuncSpaceData(true, tag, false, order + 1, order)); } -const JacobianBasis* BasisFactory::getJacobianBasis(int tag) +const JacobianBasis *BasisFactory::getJacobianBasis(int tag) { const int jacOrder = JacobianBasis::jacobianOrder(tag); const int type = ElementType::getParentType(tag); - if (type != TYPE_PYR) + if(type != TYPE_PYR) return getJacobianBasis(FuncSpaceData(true, tag, jacOrder)); else - return getJacobianBasis(FuncSpaceData(true, tag, false, jacOrder+2, jacOrder)); + return getJacobianBasis( + FuncSpaceData(true, tag, false, jacOrder + 2, jacOrder)); } -const CondNumBasis* BasisFactory::getCondNumBasis(int tag, int cnOrder) +const CondNumBasis *BasisFactory::getCondNumBasis(int tag, int cnOrder) { - std::map<int, CondNumBasis*>::const_iterator it = cs.find(tag); - if (it != cs.end()) return it->second; + std::map<int, CondNumBasis *>::const_iterator it = cs.find(tag); + if(it != cs.end()) return it->second; - CondNumBasis* M = new CondNumBasis(tag, cnOrder); + CondNumBasis *M = new CondNumBasis(tag, cnOrder); cs.insert(std::make_pair(tag, M)); return M; } -const GradientBasis* BasisFactory::getGradientBasis(FuncSpaceData data) +const GradientBasis *BasisFactory::getGradientBasis(FuncSpaceData data) { - std::map<FuncSpaceData, GradientBasis*>::const_iterator it = gs.find(data); - if (it != gs.end()) return it->second; + std::map<FuncSpaceData, GradientBasis *>::const_iterator it = gs.find(data); + if(it != gs.end()) return it->second; - GradientBasis* G = new GradientBasis(data); + GradientBasis *G = new GradientBasis(data); gs.insert(std::make_pair(data, G)); return G; } -const GradientBasis* BasisFactory::getGradientBasis(int tag, int order) +const GradientBasis *BasisFactory::getGradientBasis(int tag, int order) { return getGradientBasis(FuncSpaceData(true, tag, order)); } -const GradientBasis* BasisFactory::getGradientBasis(int tag) +const GradientBasis *BasisFactory::getGradientBasis(int tag) { return getGradientBasis(FuncSpaceData(tag)); } -const bezierBasis* BasisFactory::getBezierBasis(FuncSpaceData fsd) +const bezierBasis *BasisFactory::getBezierBasis(FuncSpaceData fsd) { FuncSpaceData data = fsd.getForPrimaryElement(); - std::map<FuncSpaceData, bezierBasis*>::const_iterator it = bs.find(data); - if (it != bs.end()) return it->second; + std::map<FuncSpaceData, bezierBasis *>::const_iterator it = bs.find(data); + if(it != bs.end()) return it->second; - bezierBasis* B = new bezierBasis(data); + bezierBasis *B = new bezierBasis(data); bs.insert(std::make_pair(data, B)); return B; } -const bezierBasis* BasisFactory::getBezierBasis(int parentTag, int order) +const bezierBasis *BasisFactory::getBezierBasis(int parentTag, int order) { int primaryTag = ElementType::getType(parentTag, 1); return getBezierBasis(FuncSpaceData(true, primaryTag, order)); } -const bezierBasis* BasisFactory::getBezierBasis(int tag) +const bezierBasis *BasisFactory::getBezierBasis(int tag) { return getBezierBasis(FuncSpaceData(tag)); } void BasisFactory::clearAll() { - std::map<int, nodalBasis*>::iterator itF = fs.begin(); - while (itF != fs.end()) { + std::map<int, nodalBasis *>::iterator itF = fs.begin(); + while(itF != fs.end()) { delete itF->second; itF++; } fs.clear(); - std::map<FuncSpaceData, JacobianBasis*>::iterator itJ = js.begin(); - while (itJ != js.end()) { + std::map<FuncSpaceData, JacobianBasis *>::iterator itJ = js.begin(); + while(itJ != js.end()) { delete itJ->second; itJ++; } js.clear(); - std::map<FuncSpaceData, GradientBasis*>::iterator itG = gs.begin(); - while (itG != gs.end()) { + std::map<FuncSpaceData, GradientBasis *>::iterator itG = gs.begin(); + while(itG != gs.end()) { delete itG->second; itG++; } gs.clear(); - std::map<FuncSpaceData, bezierBasis*>::iterator itB = bs.begin(); - while (itB != bs.end()) { + std::map<FuncSpaceData, bezierBasis *>::iterator itB = bs.begin(); + while(itB != bs.end()) { delete itB->second; itB++; } diff --git a/Numeric/BasisFactory.h b/Numeric/BasisFactory.h index 0472c4d409d43211257c2acba2e7e30655b7543d..c9f05b7a606cc9b3a8a10955b8be576098130677 100644 --- a/Numeric/BasisFactory.h +++ b/Numeric/BasisFactory.h @@ -14,40 +14,39 @@ class CondNumBasis; class JacobianBasis; class FuncSpaceData; -class BasisFactory -{ - private: - static std::map<int, nodalBasis*> fs; - static std::map<int, CondNumBasis*> cs; - static std::map<FuncSpaceData, JacobianBasis*> js; - static std::map<FuncSpaceData, bezierBasis*> bs; - static std::map<FuncSpaceData, GradientBasis*> gs; - - public: +class BasisFactory { +private: + static std::map<int, nodalBasis *> fs; + static std::map<int, CondNumBasis *> cs; + static std::map<FuncSpaceData, JacobianBasis *> js; + static std::map<FuncSpaceData, bezierBasis *> bs; + static std::map<FuncSpaceData, GradientBasis *> gs; + +public: // Caution: the returned pointer can be NULL // Nodal - static const nodalBasis* getNodalBasis(int tag); + static const nodalBasis *getNodalBasis(int tag); // Jacobian // Warning: bases returned by BasisFactory::getJacobianBasis(int tag) are the // only safe bases for using Bezier on the jacobian determinant! - static const JacobianBasis* getJacobianBasis(FuncSpaceData); - static const JacobianBasis* getJacobianBasis(int tag, int order); - static const JacobianBasis* getJacobianBasis(int tag); + static const JacobianBasis *getJacobianBasis(FuncSpaceData); + static const JacobianBasis *getJacobianBasis(int tag, int order); + static const JacobianBasis *getJacobianBasis(int tag); // Condition number - static const CondNumBasis* getCondNumBasis(int tag, int cnOrder = -1); + static const CondNumBasis *getCondNumBasis(int tag, int cnOrder = -1); // Gradients - static const GradientBasis* getGradientBasis(FuncSpaceData); - static const GradientBasis* getGradientBasis(int tag, int order); - static const GradientBasis* getGradientBasis(int tag); + static const GradientBasis *getGradientBasis(FuncSpaceData); + static const GradientBasis *getGradientBasis(int tag, int order); + static const GradientBasis *getGradientBasis(int tag); // Bezier - static const bezierBasis* getBezierBasis(FuncSpaceData); - static const bezierBasis* getBezierBasis(int parentTag, int order); - static const bezierBasis* getBezierBasis(int tag); + static const bezierBasis *getBezierBasis(FuncSpaceData); + static const bezierBasis *getBezierBasis(int parentTag, int order); + static const bezierBasis *getBezierBasis(int tag); static void clearAll(); }; diff --git a/Numeric/BergotBasis.cpp b/Numeric/BergotBasis.cpp index 7ebacf3fe9633b1a3000af7baab6e934430423f6..49da237188009dec3928f16678120447988a08e1 100644 --- a/Numeric/BergotBasis.cpp +++ b/Numeric/BergotBasis.cpp @@ -8,155 +8,152 @@ #include "MElement.h" #include "orthogonalBasis.h" - - -BergotBasis::BergotBasis(int p,bool incpl): order(p),incomplete(incpl) +BergotBasis::BergotBasis(int p, bool incpl) : order(p), incomplete(incpl) { - - if (incomplete && order > 2) { - Msg::Error("Incomplete pyramids of order %i not yet implemented",order); + if(incomplete && order > 2) { + Msg::Error("Incomplete pyramids of order %i not yet implemented", order); } } -BergotBasis::~BergotBasis() -{ -} - - -bool BergotBasis::validIJ(int i,int j) const { +BergotBasis::~BergotBasis() {} - if (!incomplete) return (i<=order) && (j<=order); - if (i+j <= order) return true; - if (i+j == order+1) return i==1 || j==1; +bool BergotBasis::validIJ(int i, int j) const +{ + if(!incomplete) return (i <= order) && (j <= order); + if(i + j <= order) return true; + if(i + j == order + 1) return i == 1 || j == 1; return false; } // Values of Bergot basis functions for coordinates (u,v,w) in the unit pyramid: // f = L_i(uhat)*L_j(vhat)*(1-w)^max(i,j)*P_k^{2*max(i,j)+2,0}(what) // with i,j = 0...order and k = 0...order-max(i,j) -// and (uhat,vhat,what) = (u/(1-w),v/(1-w),2*w-1) reduced coordinates in the unit cube [-1,1]^3 -void BergotBasis::f(double u, double v, double w, double* val) const +// and (uhat,vhat,what) = (u/(1-w),v/(1-w),2*w-1) reduced coordinates in the +// unit cube [-1,1]^3 +void BergotBasis::f(double u, double v, double w, double *val) const { // Compute Legendre polynomials at uhat - double uhat = (w == 1.) ? 0. : u/(1.-w); - std::vector<double> uFcts(order+1); - LegendrePolynomials::f(order, uhat,&(uFcts[0])); + double uhat = (w == 1.) ? 0. : u / (1. - w); + std::vector<double> uFcts(order + 1); + LegendrePolynomials::f(order, uhat, &(uFcts[0])); // Compute Legendre polynomials at vhat - double vhat = (w == 1.) ? 0. : v/(1.-w); - std::vector<double> vFcts(order+1); - LegendrePolynomials::f(order, vhat,&(vFcts[0])); + double vhat = (w == 1.) ? 0. : v / (1. - w); + std::vector<double> vFcts(order + 1); + LegendrePolynomials::f(order, vhat, &(vFcts[0])); // Compute Jacobi polynomials at what - double what = 2.*w - 1.; - std::vector<std::vector<double> > wFcts(order+1), wGrads(order+1); - for (int mIJ=0; mIJ<=order; mIJ++) { - int kMax = order-mIJ; + double what = 2. * w - 1.; + std::vector<std::vector<double> > wFcts(order + 1), wGrads(order + 1); + for(int mIJ = 0; mIJ <= order; mIJ++) { + int kMax = order - mIJ; std::vector<double> &wf = wFcts[mIJ]; - wf.resize(kMax+1); - JacobiPolynomials::f(kMax, 2.*mIJ+2., 0., what, &(wf[0])); + wf.resize(kMax + 1); + JacobiPolynomials::f(kMax, 2. * mIJ + 2., 0., what, &(wf[0])); } // Recombine to find shape function values int index = 0; - for (int i=0;i<=order;i++) { - for (int j=0;j<=order;j++) { - if (validIJ(i,j)) { - int mIJ = std::max(i,j); - double fact = pow(1.-w, mIJ); + for(int i = 0; i <= order; i++) { + for(int j = 0; j <= order; j++) { + if(validIJ(i, j)) { + int mIJ = std::max(i, j); + double fact = pow(1. - w, mIJ); std::vector<double> &wf = wFcts[mIJ]; - for (int k=0; k<=order-mIJ; k++,index++) val[index] = uFcts[i] * vFcts[j] * wf[k] * fact; + for(int k = 0; k <= order - mIJ; k++, index++) + val[index] = uFcts[i] * vFcts[j] * wf[k] * fact; } } } } - - -// Derivatives of Bergot basis functions for coordinates (u,v,w) in the unit pyramid: -// dfdu = L'_i(uhat)*L_j(vhat)*(1-w)^(max(i,j)-1)*P_k^{2*max(i,j)+2,0}(what) -// dfdv = L_i(uhat)*L'_j(vhat)*(1-w)^(max(i,j)-1)*P_k^{2*max(i,j)+2,0}(what) -// dfdw = (1-w)^(max(i,j)-2)*P_k^{2*max(i,j)+2,0}(what)*(u*L'_i(uhat)*L_j(vhat)+v*L_i(uhat)*L'_j(vhat)) -// + u*v*(1-w)^(max(i,j)-1)*(2*(1-w)*P'_k^{2*max(i,j)+2,0}(what)-max(i,j)*P_k^{2*max(i,j)+2,0}(what)) +// Derivatives of Bergot basis functions for coordinates (u,v,w) in the unit +// pyramid: dfdu = +// L'_i(uhat)*L_j(vhat)*(1-w)^(max(i,j)-1)*P_k^{2*max(i,j)+2,0}(what) dfdv = +// L_i(uhat)*L'_j(vhat)*(1-w)^(max(i,j)-1)*P_k^{2*max(i,j)+2,0}(what) dfdw = +// (1-w)^(max(i,j)-2)*P_k^{2*max(i,j)+2,0}(what)*(u*L'_i(uhat)*L_j(vhat)+v*L_i(uhat)*L'_j(vhat)) +// + +// u*v*(1-w)^(max(i,j)-1)*(2*(1-w)*P'_k^{2*max(i,j)+2,0}(what)-max(i,j)*P_k^{2*max(i,j)+2,0}(what)) // with i,j = 0...order and k = 0...order-max(i,j) -// and (uhat,vhat,what) = (u/(1-w),v/(1-w),2*w-1) reduced coordinates in the unit cube [-1,1]^3 +// and (uhat,vhat,what) = (u/(1-w),v/(1-w),2*w-1) reduced coordinates in the +// unit cube [-1,1]^3 void BergotBasis::df(double u, double v, double w, double grads[][3]) const { - // Compute Legendre polynomials and derivatives at uhat - double uhat = (w == 1.) ? 0. : u/(1.-w); - std::vector<double> uFcts(order+1), uGrads(order+1); - LegendrePolynomials::f(order, uhat,&(uFcts[0])); - LegendrePolynomials::df(order, uhat,&(uGrads[0])); + double uhat = (w == 1.) ? 0. : u / (1. - w); + std::vector<double> uFcts(order + 1), uGrads(order + 1); + LegendrePolynomials::f(order, uhat, &(uFcts[0])); + LegendrePolynomials::df(order, uhat, &(uGrads[0])); // Compute Legendre polynomials and derivatives at vhat - double vhat = (w == 1.) ? 0. : v/(1.-w); - std::vector<double> vFcts(order+1), vGrads(order+1); - LegendrePolynomials::f(order, vhat,&(vFcts[0])); - LegendrePolynomials::df(order, vhat,&(vGrads[0])); + double vhat = (w == 1.) ? 0. : v / (1. - w); + std::vector<double> vFcts(order + 1), vGrads(order + 1); + LegendrePolynomials::f(order, vhat, &(vFcts[0])); + LegendrePolynomials::df(order, vhat, &(vGrads[0])); // Compute Jacobi polynomials and derivatives at what - double what = 2.*w - 1.; - std::vector<std::vector<double> > wFcts(order+1), wGrads(order+1); - for (int mIJ=0; mIJ<=order; mIJ++) { - int kMax = order-mIJ; + double what = 2. * w - 1.; + std::vector<std::vector<double> > wFcts(order + 1), wGrads(order + 1); + for(int mIJ = 0; mIJ <= order; mIJ++) { + int kMax = order - mIJ; std::vector<double> &wf = wFcts[mIJ], &wg = wGrads[mIJ]; - wf.resize(kMax+1); - wg.resize(kMax+1); - JacobiPolynomials::f(kMax, 2.*mIJ+2., 0., what, &(wf[0])); - JacobiPolynomials::df(kMax, 2.*mIJ+2., 0., what, &(wg[0])); + wf.resize(kMax + 1); + wg.resize(kMax + 1); + JacobiPolynomials::f(kMax, 2. * mIJ + 2., 0., what, &(wf[0])); + JacobiPolynomials::df(kMax, 2. * mIJ + 2., 0., what, &(wg[0])); } // Recombine to find the shape function gradients int index = 0; - for (int i=0;i<=order;i++) { - for (int j=0;j<=order;j++) { - if (validIJ(i,j)) { - int mIJ = std::max(i,j); + for(int i = 0; i <= order; i++) { + for(int j = 0; j <= order; j++) { + if(validIJ(i, j)) { + int mIJ = std::max(i, j); std::vector<double> &wf = wFcts[mIJ], &wg = wGrads[mIJ]; - if (mIJ == 0) { // Indeterminate form for mIJ = 0 - for (int k=0; k<=order-mIJ; k++,index++) { + if(mIJ == 0) { // Indeterminate form for mIJ = 0 + for(int k = 0; k <= order - mIJ; k++, index++) { grads[index][0] = 0.; grads[index][1] = 0.; - grads[index][2] = 2.*wg[k]; + grads[index][2] = 2. * wg[k]; } } - else if (mIJ == 1) { // Indeterminate form for mIJ = 1 - if (i == 0) { - for (int k=0; k<=order-mIJ; k++,index++) { + else if(mIJ == 1) { // Indeterminate form for mIJ = 1 + if(i == 0) { + for(int k = 0; k <= order - mIJ; k++, index++) { grads[index][0] = 0.; grads[index][1] = wf[k]; - grads[index][2] = 2.*v*wg[k]; + grads[index][2] = 2. * v * wg[k]; } } - else if (j == 0) { - for (int k=0; k<=order-mIJ; k++,index++) { + else if(j == 0) { + for(int k = 0; k <= order - mIJ; k++, index++) { grads[index][0] = wf[k]; grads[index][1] = 0.; - grads[index][2] = 2.*u*wg[k]; + grads[index][2] = 2. * u * wg[k]; } } else { - for (int k=0; k<=order-mIJ; k++,index++) { - grads[index][0] = vhat*wf[k]; - grads[index][1] = uhat*wf[k]; - grads[index][2] = uhat*vhat*wf[k]+2.*uhat*v*wg[k]; + for(int k = 0; k <= order - mIJ; k++, index++) { + grads[index][0] = vhat * wf[k]; + grads[index][1] = uhat * wf[k]; + grads[index][2] = uhat * vhat * wf[k] + 2. * uhat * v * wg[k]; } } } - else { // General formula - double oMW = 1.-w; - double powM2 = pow(oMW, mIJ-2); - double powM1 = powM2*oMW; - for (int k=0; k<=order-mIJ; k++,index++) { - grads[index][0] = uGrads[i] * vFcts[j] * wf[k] * powM1; - grads[index][1] = uFcts[i] * vGrads[j] * wf[k] * powM1; - grads[index][2] = wf[k]*powM2*(u*uGrads[i]*vFcts[j]+v*uFcts[i]*vGrads[j]) - + uFcts[i]*vFcts[j]*powM1*(2.*oMW*wg[k]-mIJ*wf[k]); + else { // General formula + double oMW = 1. - w; + double powM2 = pow(oMW, mIJ - 2); + double powM1 = powM2 * oMW; + for(int k = 0; k <= order - mIJ; k++, index++) { + grads[index][0] = uGrads[i] * vFcts[j] * wf[k] * powM1; + grads[index][1] = uFcts[i] * vGrads[j] * wf[k] * powM1; + grads[index][2] = + wf[k] * powM2 * + (u * uGrads[i] * vFcts[j] + v * uFcts[i] * vGrads[j]) + + uFcts[i] * vFcts[j] * powM1 * (2. * oMW * wg[k] - mIJ * wf[k]); } } } } - } + } } - diff --git a/Numeric/BergotBasis.h b/Numeric/BergotBasis.h index 32fb39e009f671b9b08c85d162f98a246058712e..94bfe49667b6c0c01c1134ac54b7e7a9cda2533d 100644 --- a/Numeric/BergotBasis.h +++ b/Numeric/BergotBasis.h @@ -9,33 +9,33 @@ #include "nodalBasis.h" #include "polynomialBasis.h" - // Basis functios for pyramidal elements: cf. M. Bergot, G. Cohen, M. Durufle, // HIGHER-ORDER FINITE ELEMENTS FOR HYBRID MESHES USING NEW NODAL PYRAMIDAL // ELEMENTS, J. Sci. Comput. 42, 3 (2010) 345-381", DOI: // 10.1007/s10915-009-9334-9 class BergotBasis { - public: - - BergotBasis(int p,bool incpl=false); +public: + BergotBasis(int p, bool incpl = false); virtual ~BergotBasis(); - int size() const { const int n = order+1; return n*(n+1)*(2*n+1)/6; } - + int size() const + { + const int n = order + 1; + return n * (n + 1) * (2 * n + 1) / 6; + } void f(double u, double v, double w, double *val) const; void df(double u, double v, double w, double grads[][3]) const; - void initialize() {}; + void initialize(){}; - bool validIJ(int i,int j) const; + bool validIJ(int i, int j) const; - private: - - int order; //!< maximal order of surrounding functional spaces (on triangle / quad) +private: + int order; //!< maximal order of surrounding functional spaces (on triangle / + //!< quad) bool incomplete; //!< serendipity interpolation - }; #endif diff --git a/Numeric/CondNumBasis.cpp b/Numeric/CondNumBasis.cpp index 4526e4f9e5c1ddb1f4e27e7b00353b97c27c302e..fefc2c28e603d28c670d12b81cb4efb7084de6af 100644 --- a/Numeric/CondNumBasis.cpp +++ b/Numeric/CondNumBasis.cpp @@ -15,307 +15,336 @@ #include "BasisFactory.h" #include "Numeric.h" - namespace { + // Compute the determinant of a 3x3 matrix + inline double calcDet3x3(double M11, double M12, double M13, double M21, + double M22, double M23, double M31, double M32, + double M33) + { + return M11 * (M22 * M33 - M23 * M32) - M12 * (M21 * M33 - M23 * M31) + + M13 * (M21 * M32 - M22 * M31); + } -// Compute the determinant of a 3x3 matrix -inline double calcDet3x3(double M11, double M12, double M13, - double M21, double M22, double M23, - double M31, double M32, double M33) -{ - return M11 * (M22*M33 - M23*M32) - - M12 * (M21*M33 - M23*M31) - + M13 * (M21*M32 - M22*M31); -} - - -// Compute the squared Frobenius norm of the inverse of a matrix -template<bool sign> -inline double calcInvCondNum2D(double dxdX, double dxdY, - double dydX, double dydY, - double dzdX, double dzdY, - double nx, double ny, double nz) -{ - const double dxdXSq = dxdX*dxdX, dydXSq = dydX*dydX, dzdXSq = dzdX*dzdX; - const double dxdYSq = dxdY*dxdY, dydYSq = dydY*dydY, dzdYSq = dzdY*dzdY; - const double Dx = dxdXSq - dxdYSq, Dy = dydXSq - dydYSq; - const double Cx = dxdX * dxdY, Cy = dydX * dydY; - const double S1 = dzdYSq * dzdYSq; - const double S2 = (dzdXSq - Dy - Dx) * dzdYSq; - const double S3 = (Cy + Cx) * dzdX * dzdY; - const double S4 = dzdXSq * dzdXSq; - const double S5 = (Dy + Dx) * dzdXSq; - const double S6 = Cx * Cy; - const double S7 = dydXSq * dydXSq; - const double S8 = Dy*dydXSq; - const double S9 = dxdXSq * dxdXSq; - const double S10 = Dx*dxdXSq; - const double S11 = Dy*Dy; - const double S12 = Dx*Dy; - const double S13 = Dx*Dx; - const double S = 2.*(S2+S5+S12)+ 4.*(S7-S8+S9-S10) + 8.*(S3+S6) + S1+S4+S11+S13; - const double N = dxdXSq + dxdYSq + dydXSq + dydYSq + dzdXSq + dzdYSq; - const double sqrtS = (S > 0.0) ? sqrt(S) : 0.0; //// Plaxis modification - const double sigma1Sq = 0.5 * (N + sqrtS), sigma2Sq = 0.5 * (N - sqrtS); - const double iCN = 2. * sqrt(sigma1Sq*sigma2Sq) / (sigma1Sq+sigma2Sq); - if (sign) { - const double lnx = dydX*dzdY - dzdX*dydY, lny = dzdX*dxdY - dxdX*dzdY, // Local normal from mapping gradients - lnz = dxdX*dydY - dydX*dxdY; - const double dp = lnx*nx + lny*ny + lnz*nz; // Dot product to determine element validity - return (dp >= 0.) ? iCN : -iCN; + // Compute the squared Frobenius norm of the inverse of a matrix + template <bool sign> + inline double calcInvCondNum2D(double dxdX, double dxdY, double dydX, + double dydY, double dzdX, double dzdY, + double nx, double ny, double nz) + { + const double dxdXSq = dxdX * dxdX, dydXSq = dydX * dydX, + dzdXSq = dzdX * dzdX; + const double dxdYSq = dxdY * dxdY, dydYSq = dydY * dydY, + dzdYSq = dzdY * dzdY; + const double Dx = dxdXSq - dxdYSq, Dy = dydXSq - dydYSq; + const double Cx = dxdX * dxdY, Cy = dydX * dydY; + const double S1 = dzdYSq * dzdYSq; + const double S2 = (dzdXSq - Dy - Dx) * dzdYSq; + const double S3 = (Cy + Cx) * dzdX * dzdY; + const double S4 = dzdXSq * dzdXSq; + const double S5 = (Dy + Dx) * dzdXSq; + const double S6 = Cx * Cy; + const double S7 = dydXSq * dydXSq; + const double S8 = Dy * dydXSq; + const double S9 = dxdXSq * dxdXSq; + const double S10 = Dx * dxdXSq; + const double S11 = Dy * Dy; + const double S12 = Dx * Dy; + const double S13 = Dx * Dx; + const double S = 2. * (S2 + S5 + S12) + 4. * (S7 - S8 + S9 - S10) + + 8. * (S3 + S6) + S1 + S4 + S11 + S13; + const double N = dxdXSq + dxdYSq + dydXSq + dydYSq + dzdXSq + dzdYSq; + const double sqrtS = (S > 0.0) ? sqrt(S) : 0.0; //// Plaxis modification + const double sigma1Sq = 0.5 * (N + sqrtS), sigma2Sq = 0.5 * (N - sqrtS); + const double iCN = 2. * sqrt(sigma1Sq * sigma2Sq) / (sigma1Sq + sigma2Sq); + if(sign) { + const double lnx = dydX * dzdY - dzdX * dydY, + lny = dzdX * dxdY - + dxdX * dzdY, // Local normal from mapping gradients + lnz = dxdX * dydY - dydX * dxdY; + const double dp = lnx * nx + lny * ny + + lnz * nz; // Dot product to determine element validity + return (dp >= 0.) ? iCN : -iCN; + } + else + return iCN; + // return std::min(sqrt(sigma1Sq), sqrt(sigma2Sq)) / + // std::max(sqrt(sigma1Sq), sqrt(sigma2Sq)); } - else - return iCN; -// return std::min(sqrt(sigma1Sq), sqrt(sigma2Sq)) / std::max(sqrt(sigma1Sq), sqrt(sigma2Sq)); -} + // Compute the squared Frobenius norm of the inverse of a matrix + template <bool sign> + inline double calcInvCondNum3D(double J11, double J12, double J13, double J21, + double J22, double J23, double J31, double J32, + double J33) + { + const double D = calcDet3x3(J11, J12, J13, J21, J22, J23, J31, J32, J33); + if(D == 0.) return 0.; + const double I11 = J22 * J33 - J23 * J32, I12 = J13 * J32 - J12 * J33, + I13 = J12 * J23 - J13 * J22, I21 = J23 * J31 - J21 * J33, + I22 = J11 * J33 - J13 * J31, I23 = J13 * J21 - J11 * J23, + I31 = J21 * J32 - J22 * J31, I32 = J12 * J31 - J11 * J32, + I33 = J11 * J22 - J12 * J21; + const double nSqJ = J11 * J11 + J12 * J12 + J13 * J13 + J21 * J21 + + J22 * J22 + J23 * J23 + J31 * J31 + J32 * J32 + + J33 * J33; + const double nSqDInvJ = I11 * I11 + I12 * I12 + I13 * I13 + I21 * I21 + + I22 * I22 + I23 * I23 + I31 * I31 + I32 * I32 + + I33 * I33; + if(sign) + return 3. * D / sqrt(nSqJ * nSqDInvJ); + else + return 3. * std::fabs(D) / sqrt(nSqJ * nSqDInvJ); + } -// Compute the squared Frobenius norm of the inverse of a matrix -template<bool sign> -inline double calcInvCondNum3D(double J11, double J12, double J13, - double J21, double J22, double J23, - double J31, double J32, double J33) -{ - const double D = calcDet3x3(J11, J12, J13, J21, J22, J23, J31, J32, J33); - if (D == 0.) return 0.; - const double I11 = J22*J33-J23*J32, I12 = J13*J32-J12*J33, I13 = J12*J23-J13*J22, - I21 = J23*J31-J21*J33, I22 = J11*J33-J13*J31, I23 = J13*J21-J11*J23, - I31 = J21*J32-J22*J31, I32 = J12*J31-J11*J32, I33 = J11*J22-J12*J21; - const double nSqJ = J11*J11 + J12*J12 + J13*J13 - + J21*J21 + J22*J22 + J23*J23 - + J31*J31 + J32*J32 + J33*J33; - const double nSqDInvJ = I11*I11 + I12*I12 + I13*I13 - + I21*I21 + I22*I22 + I23*I23 - + I31*I31 + I32*I32 + I33*I33; - if (sign) - return 3.*D/sqrt(nSqJ*nSqDInvJ); - else - return 3.*std::fabs(D)/sqrt(nSqJ*nSqDInvJ); -} + // Compute condition number and its gradients + // w.r.t. node positions, at one location in a 2D element + template <bool sign> + inline void calcGradInvCondNum2D(double dxdX, double dxdY, double dydX, + double dydY, double dzdX, double dzdY, + double nx, double ny, double nz, int i, + int numMapNodes, + const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, + fullMatrix<double> &IDI) + { + const double EpsDegen = 1.e-6; + + bool posJac = true; + if(sign) { + const double lnx = dydX * dzdY - dzdX * dydY, + lny = dzdX * dxdY - + dxdX * dzdY, // Local normal from mapping gradients + lnz = dxdX * dydY - dydX * dxdY; + const double dp = lnx * nx + lny * ny + + lnz * nz; // Dot product to determine element validity + posJac = (dp >= 0.); + } + const double dxdXSq = dxdX * dxdX, dydXSq = dydX * dydX, + dzdXSq = dzdX * dzdX; + const double dxdYSq = dxdY * dxdY, dydYSq = dydY * dydY, + dzdYSq = dzdY * dzdY; + const double Dx = dxdXSq - dxdYSq, Dy = dydXSq - dydYSq; + const double Cx = dxdX * dxdY, Cy = dydX * dydY; + const double S1 = dzdYSq * dzdYSq; + const double S2 = (dzdXSq - Dy - Dx) * dzdYSq; + const double S3 = (Cy + Cx) * dzdX * dzdY; + const double S4 = dzdXSq * dzdXSq; + const double S5 = (Dy + Dx) * dzdXSq; + const double S6 = Cx * Cy; + const double S7 = dydXSq * dydXSq; + const double S8 = Dy * dydXSq; + const double S9 = dxdXSq * dxdXSq; + const double S10 = Dx * dxdXSq; + const double S11 = Dy * Dy; + const double S12 = Dx * Dy; + const double S13 = Dx * Dx; + const double S = 2. * (S2 + S5 + S12) + 4. * (S7 - S8 + S9 - S10) + + 8. * (S3 + S6) + S1 + S4 + S11 + S13; + if(S == 0.) { // S == 0. -> Ideal element + for(int j = 0; j < 3 * numMapNodes; j++) IDI(i, j) = 0.; + IDI(i, 3 * numMapNodes) = posJac ? 1. : -1.; + return; + } + const double N = dxdXSq + dxdYSq + dydXSq + dydYSq + dzdXSq + dzdYSq; + const double sqrtS = sqrt(S), invSqrtS = 1. / sqrtS; + const double sigma1Sq = 0.5 * (N + sqrtS), sigma2Sq = 0.5 * (N - sqrtS); + const bool degen = + (sigma2Sq < EpsDegen * sigma1Sq); // Check for degenerate element + const double sum = sigma1Sq + sigma2Sq, invSum = 1. / sum; + const double prod = sigma1Sq * sigma2Sq; + const double sqrtProd = sqrt(prod); + const double halfICN = sqrtProd * invSum; + IDI(i, 3 * numMapNodes) = posJac ? 2. * halfICN : -2. * halfICN; + + if(degen) { // Degenerate element: special formula for gradients + const double nnXx = dzdX * ny - dydX * nz, nnXy = dxdX * nz - dzdX * nx, + nnXz = dydX * nx - dxdX * ny; + const double nnYx = dzdY * ny - dydY * nz, nnYy = dxdY * nz - dzdY * nx, + nnYz = dydY * nx - dxdY * ny; + const double fact = 2. / N; + for(int j = 0; j < numMapNodes; j++) { + const double &dPhidX = gSMatX(i, j); + const double &dPhidY = gSMatY(i, j); + IDI(i, j) = fact * (dPhidY * nnXx - dPhidX * nnYx); + IDI(i, j + numMapNodes) = fact * (dPhidY * nnXy - dPhidX * nnYy); + IDI(i, j + 2 * numMapNodes) = fact * (dPhidY * nnXz - dPhidX * nnYz); + } + return; + } -// Compute condition number and its gradients -// w.r.t. node positions, at one location in a 2D element -template<bool sign> -inline void calcGradInvCondNum2D(double dxdX, double dxdY, - double dydX, double dydY, - double dzdX, double dzdY, - double nx, double ny, double nz, - int i, int numMapNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - fullMatrix<double> &IDI) -{ - const double EpsDegen = 1.e-6; - - bool posJac = true; - if (sign) { - const double lnx = dydX*dzdY - dzdX*dydY, lny = dzdX*dxdY - dxdX*dzdY, // Local normal from mapping gradients - lnz = dxdX*dydY - dydX*dxdY; - const double dp = lnx*nx + lny*ny + lnz*nz; // Dot product to determine element validity - posJac = (dp >= 0.); - } + const double invSqrtProd = 1. / sqrtProd; - const double dxdXSq = dxdX*dxdX, dydXSq = dydX*dydX, dzdXSq = dzdX*dzdX; - const double dxdYSq = dxdY*dxdY, dydYSq = dydY*dydY, dzdYSq = dzdY*dzdY; - const double Dx = dxdXSq - dxdYSq, Dy = dydXSq - dydYSq; - const double Cx = dxdX * dxdY, Cy = dydX * dydY; - const double S1 = dzdYSq * dzdYSq; - const double S2 = (dzdXSq - Dy - Dx) * dzdYSq; - const double S3 = (Cy + Cx) * dzdX * dzdY; - const double S4 = dzdXSq * dzdXSq; - const double S5 = (Dy + Dx) * dzdXSq; - const double S6 = Cx * Cy; - const double S7 = dydXSq * dydXSq; - const double S8 = Dy*dydXSq; - const double S9 = dxdXSq * dxdXSq; - const double S10 = Dx*dxdXSq; - const double S11 = Dy*Dy; - const double S12 = Dx*Dy; - const double S13 = Dx*Dx; - const double S = 2.*(S2+S5+S12)+ 4.*(S7-S8+S9-S10) + 8.*(S3+S6) + S1+S4+S11+S13; - if (S == 0.) { // S == 0. -> Ideal element - for (int j = 0; j<3*numMapNodes; j++) IDI(i, j) = 0.; - IDI(i, 3*numMapNodes) = posJac ? 1. : -1.; - return; - } - const double N = dxdXSq + dxdYSq + dydXSq + dydYSq + dzdXSq + dzdYSq; - const double sqrtS = sqrt(S), invSqrtS = 1./sqrtS; - const double sigma1Sq = 0.5 * (N + sqrtS), sigma2Sq = 0.5 * (N - sqrtS); - const bool degen = (sigma2Sq < EpsDegen*sigma1Sq); // Check for degenerate element - const double sum = sigma1Sq + sigma2Sq, invSum = 1. / sum; - const double prod = sigma1Sq * sigma2Sq; - const double sqrtProd = sqrt(prod); - const double halfICN = sqrtProd * invSum; - IDI(i, 3*numMapNodes) = posJac ? 2. * halfICN : -2. * halfICN; - - if (degen) { // Degenerate element: special formula for gradients - const double nnXx = dzdX*ny - dydX*nz, nnXy = dxdX*nz - dzdX*nx, - nnXz = dydX*nx - dxdX*ny; - const double nnYx = dzdY*ny - dydY*nz, nnYy = dxdY*nz - dzdY*nx, - nnYz = dydY*nx - dxdY*ny; - const double fact = 2./N; - for (int j = 0; j < numMapNodes; j++) { + for(int j = 0; j < numMapNodes; j++) { const double &dPhidX = gSMatX(i, j); const double &dPhidY = gSMatY(i, j); - IDI(i, j) = fact * (dPhidY*nnXx - dPhidX*nnYx); - IDI(i, j+numMapNodes) = fact * (dPhidY*nnXy - dPhidX*nnYy); - IDI(i, j+2*numMapNodes) = fact * (dPhidY*nnXz - dPhidX*nnYz); - } - return; - } - const double invSqrtProd = 1. / sqrtProd; - - for (int j = 0; j < numMapNodes; j++) { - const double &dPhidX = gSMatX(i, j); - const double &dPhidY = gSMatY(i, j); - - const double ddxdXSqdxj = 2.*dPhidX*dxdX, ddxdYSqdxj = 2.*dPhidY*dxdY; - const double dDxdxj = ddxdXSqdxj - ddxdYSqdxj; - const double dCxdxj = dPhidX*dxdY + dxdX*dPhidY; - const double dS2dxj = -dDxdxj * dzdYSq; - const double dS3dxj = dCxdxj * dzdX * dzdY; - const double dS5dxj = dDxdxj * dzdXSq; - const double dS6dxj = dCxdxj * Cy; - const double dS9dxj = 2. * ddxdXSqdxj * dxdXSq; - const double dS10dxj = dDxdxj*dxdXSq + Dx*ddxdXSqdxj; - const double dS12dxj = dDxdxj * Dy; - const double dS13dxj = 2. * dDxdxj* Dx; - const double dSdxj = 2.*(dS2dxj+dS5dxj+dS12dxj)+ 4.*(dS9dxj-dS10dxj) - + 8.*(dS3dxj+dS6dxj) + dS13dxj; - const double dNdxj = ddxdXSqdxj + ddxdYSqdxj; - const double dsqrtSdxj = 0.5*dSdxj*invSqrtS; - const double dsigma1Sqdxj = 0.5 * (dNdxj + dsqrtSdxj), - dsigma2Sqdxj = 0.5 * (dNdxj - dsqrtSdxj); - const double dSumdxj = dsigma1Sqdxj + dsigma2Sqdxj; - const double dProddxj = dsigma1Sqdxj*sigma2Sq + sigma1Sq*dsigma2Sqdxj; - const double diCNdxj = (dProddxj*sum - 2.*prod*dSumdxj)*invSum*invSum*invSqrtProd; - IDI(i, j) = posJac ? diCNdxj : -diCNdxj; - - const double ddydXSqdyj = 2.*dPhidX*dydX, ddydYSqdyj = 2.*dPhidY*dydY; - const double dDydyj = ddydXSqdyj - ddydYSqdyj; - const double dCydyj = dPhidX*dydY + dydX*dPhidY; - const double dS2dyj = -dDydyj * dzdYSq; - const double dS3dyj = dCydyj * dzdX * dzdY; - const double dS5dyj = dDydyj * dzdXSq; - const double dS6dyj = Cx * dCydyj; - const double dS7dyj = 2. * ddydXSqdyj * dydXSq; - const double dS8dyj = dDydyj*dydXSq + Dy*ddydXSqdyj; - const double dS11dyj = 2. * dDydyj * Dy; - const double dS12dyj = Dx* dDydyj; - const double dSdyj = 2.*(dS2dyj+dS5dyj+dS12dyj)+ 4.*(dS7dyj-dS8dyj) - + 8.*(dS3dyj+dS6dyj) + dS11dyj; - const double dNdyj = ddydXSqdyj + ddydYSqdyj; - const double dsqrtSdyj = 0.5*dSdyj*invSqrtS; - const double dsigma1Sqdyj = 0.5 * (dNdyj + dsqrtSdyj), - dsigma2Sqdyj = 0.5 * (dNdyj - dsqrtSdyj); - const double dSumdyj = dsigma1Sqdyj + dsigma2Sqdyj; - const double dProddyj = dsigma1Sqdyj*sigma2Sq + sigma1Sq*dsigma2Sqdyj; - const double diCNdyj = (dProddyj*sum - 2.*prod*dSumdyj)*invSum*invSum*invSqrtProd; - IDI(i, j+numMapNodes) = posJac ? diCNdyj : -diCNdyj; - - const double ddzdXSqdzj = 2.*dPhidX*dzdX, ddzdYSqdzj = 2.*dPhidY*dzdY; - const double dS1dzj = 2. * ddzdYSqdzj * dzdYSq; - const double dS2dzj = (dzdXSq - Dy - Dx) * ddzdYSqdzj; - const double dS3dzj = (Cy + Cx) * - (ddzdXSqdzj*dzdY + dzdX*ddzdYSqdzj); - const double dS4dzj = 2. * ddzdXSqdzj * dzdXSq; - const double dS5dzj = (Dy + Dx) * ddzdXSqdzj; - const double dSdzj = 2.*(dS2dzj+dS5dzj) + 8.*dS3dzj + dS1dzj+dS4dzj; - const double dNdzj = ddzdXSqdzj + ddzdYSqdzj; - const double dsqrtSdzj = 0.5*dSdzj*invSqrtS; - const double dsigma1Sqdzj = 0.5 * (dNdzj + dsqrtSdzj), - dsigma2Sqdzj = 0.5 * (dNdzj - dsqrtSdzj); - const double dSumdzj = dsigma1Sqdzj + dsigma2Sqdzj; - const double dProddzj = dsigma1Sqdzj*sigma2Sq + sigma1Sq*dsigma2Sqdzj; - const double diCNdzj = (dProddzj*sum - 2.*prod*dSumdzj)*invSum*invSum*invSqrtProd; - IDI(i, j+2*numMapNodes) = posJac ? diCNdzj : -diCNdzj; + const double ddxdXSqdxj = 2. * dPhidX * dxdX, + ddxdYSqdxj = 2. * dPhidY * dxdY; + const double dDxdxj = ddxdXSqdxj - ddxdYSqdxj; + const double dCxdxj = dPhidX * dxdY + dxdX * dPhidY; + const double dS2dxj = -dDxdxj * dzdYSq; + const double dS3dxj = dCxdxj * dzdX * dzdY; + const double dS5dxj = dDxdxj * dzdXSq; + const double dS6dxj = dCxdxj * Cy; + const double dS9dxj = 2. * ddxdXSqdxj * dxdXSq; + const double dS10dxj = dDxdxj * dxdXSq + Dx * ddxdXSqdxj; + const double dS12dxj = dDxdxj * Dy; + const double dS13dxj = 2. * dDxdxj * Dx; + const double dSdxj = 2. * (dS2dxj + dS5dxj + dS12dxj) + + 4. * (dS9dxj - dS10dxj) + 8. * (dS3dxj + dS6dxj) + + dS13dxj; + const double dNdxj = ddxdXSqdxj + ddxdYSqdxj; + const double dsqrtSdxj = 0.5 * dSdxj * invSqrtS; + const double dsigma1Sqdxj = 0.5 * (dNdxj + dsqrtSdxj), + dsigma2Sqdxj = 0.5 * (dNdxj - dsqrtSdxj); + const double dSumdxj = dsigma1Sqdxj + dsigma2Sqdxj; + const double dProddxj = dsigma1Sqdxj * sigma2Sq + sigma1Sq * dsigma2Sqdxj; + const double diCNdxj = + (dProddxj * sum - 2. * prod * dSumdxj) * invSum * invSum * invSqrtProd; + IDI(i, j) = posJac ? diCNdxj : -diCNdxj; + + const double ddydXSqdyj = 2. * dPhidX * dydX, + ddydYSqdyj = 2. * dPhidY * dydY; + const double dDydyj = ddydXSqdyj - ddydYSqdyj; + const double dCydyj = dPhidX * dydY + dydX * dPhidY; + const double dS2dyj = -dDydyj * dzdYSq; + const double dS3dyj = dCydyj * dzdX * dzdY; + const double dS5dyj = dDydyj * dzdXSq; + const double dS6dyj = Cx * dCydyj; + const double dS7dyj = 2. * ddydXSqdyj * dydXSq; + const double dS8dyj = dDydyj * dydXSq + Dy * ddydXSqdyj; + const double dS11dyj = 2. * dDydyj * Dy; + const double dS12dyj = Dx * dDydyj; + const double dSdyj = 2. * (dS2dyj + dS5dyj + dS12dyj) + + 4. * (dS7dyj - dS8dyj) + 8. * (dS3dyj + dS6dyj) + + dS11dyj; + const double dNdyj = ddydXSqdyj + ddydYSqdyj; + const double dsqrtSdyj = 0.5 * dSdyj * invSqrtS; + const double dsigma1Sqdyj = 0.5 * (dNdyj + dsqrtSdyj), + dsigma2Sqdyj = 0.5 * (dNdyj - dsqrtSdyj); + const double dSumdyj = dsigma1Sqdyj + dsigma2Sqdyj; + const double dProddyj = dsigma1Sqdyj * sigma2Sq + sigma1Sq * dsigma2Sqdyj; + const double diCNdyj = + (dProddyj * sum - 2. * prod * dSumdyj) * invSum * invSum * invSqrtProd; + IDI(i, j + numMapNodes) = posJac ? diCNdyj : -diCNdyj; + + const double ddzdXSqdzj = 2. * dPhidX * dzdX, + ddzdYSqdzj = 2. * dPhidY * dzdY; + const double dS1dzj = 2. * ddzdYSqdzj * dzdYSq; + const double dS2dzj = (dzdXSq - Dy - Dx) * ddzdYSqdzj; + const double dS3dzj = (Cy + Cx) * (ddzdXSqdzj * dzdY + dzdX * ddzdYSqdzj); + const double dS4dzj = 2. * ddzdXSqdzj * dzdXSq; + const double dS5dzj = (Dy + Dx) * ddzdXSqdzj; + const double dSdzj = + 2. * (dS2dzj + dS5dzj) + 8. * dS3dzj + dS1dzj + dS4dzj; + const double dNdzj = ddzdXSqdzj + ddzdYSqdzj; + const double dsqrtSdzj = 0.5 * dSdzj * invSqrtS; + const double dsigma1Sqdzj = 0.5 * (dNdzj + dsqrtSdzj), + dsigma2Sqdzj = 0.5 * (dNdzj - dsqrtSdzj); + const double dSumdzj = dsigma1Sqdzj + dsigma2Sqdzj; + const double dProddzj = dsigma1Sqdzj * sigma2Sq + sigma1Sq * dsigma2Sqdzj; + const double diCNdzj = + (dProddzj * sum - 2. * prod * dSumdzj) * invSum * invSum * invSqrtProd; + IDI(i, j + 2 * numMapNodes) = posJac ? diCNdzj : -diCNdzj; + } } -} - -// Compute condition number and its gradients -// w.r.t. node positions, at one location in a 3D element -template<bool sign> -inline void calcGradInvCondNum3D(double dxdX, double dxdY, double dxdZ, - double dydX, double dydY, double dydZ, - double dzdX, double dzdY, double dzdZ, - int i, int numMapNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - fullMatrix<double> &IDI) -{ - const double normJSq = dxdX*dxdX + dxdY*dxdY + dxdZ*dxdZ - + dydX*dydX + dydY*dydY + dydZ*dydZ - + dzdX*dzdX + dzdY*dzdY + dzdZ*dzdZ; - const double I11 = dydY*dzdZ - dydZ*dzdY, I12 = dxdZ*dzdY - dxdY*dzdZ, - I13 = dxdY*dydZ - dxdZ*dydY, I21 = dydZ*dzdX - dydX*dzdZ, - I22 = dxdX*dzdZ - dxdZ*dzdX, I23 = dxdZ*dydX - dxdX*dydZ, - I31 = dydX*dzdY - dydY*dzdX, I32 = dxdY*dzdX - dxdX*dzdY, - I33 = dxdX*dydY - dxdY*dydX; - const double normISq = I11*I11 + I12*I12 + I13*I13 - + I21*I21 + I22*I22 + I23*I23 - + I31*I31 + I32*I32 + I33*I33; - const double invProd = 1./(normJSq*normISq), invSqrtProd = sqrt(invProd); - const double D = calcDet3x3(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ); - const bool reverse = (!sign && (D < 0.)); - const double sICN = 3.*D*invSqrtProd; - IDI(i, 3*numMapNodes) = reverse ? -sICN : sICN; - - for (int j = 0; j < numMapNodes; j++) { - const double &dPhidX = gSMatX(i, j); - const double &dPhidY = gSMatY(i, j); - const double &dPhidZ = gSMatZ(i, j); - - const double dNormJSqdxj = 2.*(dPhidX*dxdX + dPhidY*dxdY + dPhidZ*dxdZ); - const double dNormISqdxj = 2.*((dPhidZ*dzdY - dPhidY*dzdZ)*I12 + (dPhidY*dydZ - dPhidZ*dydY)*I13 - + (dPhidX*dzdZ - dPhidZ*dzdX)*I22 + (dPhidZ*dydX - dPhidX*dydZ)*I23 - + (dPhidY*dzdX - dPhidX*dzdY)*I32 + (dPhidX*dydY - dPhidY*dydX)*I33); - const double dProddxj = dNormJSqdxj*normISq + dNormISqdxj*normJSq; - const double dDdxj = dPhidX * dydY * dzdZ + dzdX * dPhidY * dydZ + - dydX * dzdY * dPhidZ - dzdX * dydY * dPhidZ - - dPhidX * dzdY * dydZ - dydX * dPhidY * dzdZ; - const double dsICNdxj = 3. * (dDdxj*invSqrtProd - 0.5*D*dProddxj*invProd*invSqrtProd); - IDI(i, j) = reverse ? -dsICNdxj : dsICNdxj; - - const double dNormJSqdyj = 2.*(dPhidX*dydX + dPhidY*dydY + dPhidZ*dydZ); - const double dNormISqdyj = 2.*((dPhidY*dzdZ - dPhidZ*dzdY)*I11 + (dxdY*dPhidZ - dxdZ*dPhidY)*I13 - + (dPhidZ*dzdX - dPhidX*dzdZ)*I21 + (dxdZ*dPhidX - dxdX*dPhidZ)*I23 - + (dPhidX*dzdY - dPhidY*dzdX)*I31 + (dxdX*dPhidY - dxdY*dPhidX)*I33); - const double dProddyj = dNormJSqdyj*normISq + dNormISqdyj*normJSq; - const double dDdyj = dxdX * dPhidY * dzdZ + dzdX * dxdY * dPhidZ + - dPhidX * dzdY * dxdZ - dzdX * dPhidY * dxdZ - - dxdX * dzdY * dPhidZ - dPhidX * dxdY * dzdZ; - const double dsICNdyj = 3. * (dDdyj*invSqrtProd - 0.5*D*dProddyj*invProd*invSqrtProd); - IDI(i, j+numMapNodes) = reverse ? -dsICNdyj : dsICNdyj; - - const double dNormJSqdzj = 2.*(dPhidX*dzdX + dPhidY*dzdY + dPhidZ*dzdZ); - const double dNormISqdzj = 2.*((dydY*dPhidZ - dydZ*dPhidY)*I11 + (dxdZ*dPhidY - dxdY*dPhidZ)*I12 - + (dydZ*dPhidX - dydX*dPhidZ)*I21 + (dxdX*dPhidZ - dxdZ*dPhidX)*I22 - + (dydX*dPhidY - dydY*dPhidX)*I31 + (dxdY*dPhidX - dxdX*dPhidY)*I32); - const double dProddzj = dNormJSqdzj*normISq + dNormISqdzj*normJSq; - const double dDdzj = dxdX * dydY * dPhidZ + dPhidX * dxdY * dydZ + - dydX * dPhidY * dxdZ - dPhidX * dydY * dxdZ - - dxdX * dPhidY * dydZ - dydX * dxdY * dPhidZ; - const double dsICNdzj = 3. * (dDdzj*invSqrtProd - 0.5*D*dProddzj*invProd*invSqrtProd); - IDI(i, j+2*numMapNodes) = reverse ? -dsICNdzj : dsICNdzj; + // Compute condition number and its gradients + // w.r.t. node positions, at one location in a 3D element + template <bool sign> + inline void calcGradInvCondNum3D( + double dxdX, double dxdY, double dxdZ, double dydX, double dydY, + double dydZ, double dzdX, double dzdY, double dzdZ, int i, int numMapNodes, + const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, + const fullMatrix<double> &gSMatZ, fullMatrix<double> &IDI) + { + const double normJSq = dxdX * dxdX + dxdY * dxdY + dxdZ * dxdZ + + dydX * dydX + dydY * dydY + dydZ * dydZ + + dzdX * dzdX + dzdY * dzdY + dzdZ * dzdZ; + const double I11 = dydY * dzdZ - dydZ * dzdY, + I12 = dxdZ * dzdY - dxdY * dzdZ, + I13 = dxdY * dydZ - dxdZ * dydY, + I21 = dydZ * dzdX - dydX * dzdZ, + I22 = dxdX * dzdZ - dxdZ * dzdX, + I23 = dxdZ * dydX - dxdX * dydZ, + I31 = dydX * dzdY - dydY * dzdX, + I32 = dxdY * dzdX - dxdX * dzdY, + I33 = dxdX * dydY - dxdY * dydX; + const double normISq = I11 * I11 + I12 * I12 + I13 * I13 + I21 * I21 + + I22 * I22 + I23 * I23 + I31 * I31 + I32 * I32 + + I33 * I33; + const double invProd = 1. / (normJSq * normISq), + invSqrtProd = sqrt(invProd); + const double D = + calcDet3x3(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ); + const bool reverse = (!sign && (D < 0.)); + const double sICN = 3. * D * invSqrtProd; + IDI(i, 3 * numMapNodes) = reverse ? -sICN : sICN; + + for(int j = 0; j < numMapNodes; j++) { + const double &dPhidX = gSMatX(i, j); + const double &dPhidY = gSMatY(i, j); + const double &dPhidZ = gSMatZ(i, j); + + const double dNormJSqdxj = + 2. * (dPhidX * dxdX + dPhidY * dxdY + dPhidZ * dxdZ); + const double dNormISqdxj = 2. * ((dPhidZ * dzdY - dPhidY * dzdZ) * I12 + + (dPhidY * dydZ - dPhidZ * dydY) * I13 + + (dPhidX * dzdZ - dPhidZ * dzdX) * I22 + + (dPhidZ * dydX - dPhidX * dydZ) * I23 + + (dPhidY * dzdX - dPhidX * dzdY) * I32 + + (dPhidX * dydY - dPhidY * dydX) * I33); + const double dProddxj = dNormJSqdxj * normISq + dNormISqdxj * normJSq; + const double dDdxj = dPhidX * dydY * dzdZ + dzdX * dPhidY * dydZ + + dydX * dzdY * dPhidZ - dzdX * dydY * dPhidZ - + dPhidX * dzdY * dydZ - dydX * dPhidY * dzdZ; + const double dsICNdxj = + 3. * (dDdxj * invSqrtProd - 0.5 * D * dProddxj * invProd * invSqrtProd); + IDI(i, j) = reverse ? -dsICNdxj : dsICNdxj; + + const double dNormJSqdyj = + 2. * (dPhidX * dydX + dPhidY * dydY + dPhidZ * dydZ); + const double dNormISqdyj = 2. * ((dPhidY * dzdZ - dPhidZ * dzdY) * I11 + + (dxdY * dPhidZ - dxdZ * dPhidY) * I13 + + (dPhidZ * dzdX - dPhidX * dzdZ) * I21 + + (dxdZ * dPhidX - dxdX * dPhidZ) * I23 + + (dPhidX * dzdY - dPhidY * dzdX) * I31 + + (dxdX * dPhidY - dxdY * dPhidX) * I33); + const double dProddyj = dNormJSqdyj * normISq + dNormISqdyj * normJSq; + const double dDdyj = dxdX * dPhidY * dzdZ + dzdX * dxdY * dPhidZ + + dPhidX * dzdY * dxdZ - dzdX * dPhidY * dxdZ - + dxdX * dzdY * dPhidZ - dPhidX * dxdY * dzdZ; + const double dsICNdyj = + 3. * (dDdyj * invSqrtProd - 0.5 * D * dProddyj * invProd * invSqrtProd); + IDI(i, j + numMapNodes) = reverse ? -dsICNdyj : dsICNdyj; + + const double dNormJSqdzj = + 2. * (dPhidX * dzdX + dPhidY * dzdY + dPhidZ * dzdZ); + const double dNormISqdzj = 2. * ((dydY * dPhidZ - dydZ * dPhidY) * I11 + + (dxdZ * dPhidY - dxdY * dPhidZ) * I12 + + (dydZ * dPhidX - dydX * dPhidZ) * I21 + + (dxdX * dPhidZ - dxdZ * dPhidX) * I22 + + (dydX * dPhidY - dydY * dPhidX) * I31 + + (dxdY * dPhidX - dxdX * dPhidY) * I32); + const double dProddzj = dNormJSqdzj * normISq + dNormISqdzj * normJSq; + const double dDdzj = dxdX * dydY * dPhidZ + dPhidX * dxdY * dydZ + + dydX * dPhidY * dxdZ - dPhidX * dydY * dxdZ - + dxdX * dPhidY * dydZ - dydX * dxdY * dPhidZ; + const double dsICNdzj = + 3. * (dDdzj * invSqrtProd - 0.5 * D * dProddzj * invProd * invSqrtProd); + IDI(i, j + 2 * numMapNodes) = reverse ? -dsICNdzj : dsICNdzj; + } } -} - - -} +} // namespace -CondNumBasis::CondNumBasis(int tag, int cnOrder) : - _tag(tag), _dim(ElementType::getDimension(tag)), +CondNumBasis::CondNumBasis(int tag, int cnOrder) + : _tag(tag), _dim(ElementType::getDimension(tag)), _condNumOrder(cnOrder >= 0 ? cnOrder : condNumOrder(tag)) { - if (ElementType::getParentType(tag) == TYPE_TRIH){ + if(ElementType::getParentType(tag) == TYPE_TRIH) { _nCondNumNodes = 1; _nMapNodes = 4; _nPrimMapNodes = 4; @@ -323,11 +352,12 @@ CondNumBasis::CondNumBasis(int tag, int cnOrder) : } const bool serendip = false; - FuncSpaceData data = (ElementType::getParentType(tag) == TYPE_PYR) ? - FuncSpaceData(true, tag, true, 1, _condNumOrder-1, &serendip) : + FuncSpaceData data = + (ElementType::getParentType(tag) == TYPE_PYR) ? + FuncSpaceData(true, tag, true, 1, _condNumOrder - 1, &serendip) : FuncSpaceData(true, tag, _condNumOrder, &serendip); - fullMatrix<double> lagPoints; // Sampling points + fullMatrix<double> lagPoints; // Sampling points gmshGeneratePoints(data, lagPoints); _nCondNumNodes = lagPoints.size1(); _nMapNodes = BasisFactory::getNodalBasis(tag)->getNumShapeFunctions(); @@ -344,8 +374,8 @@ CondNumBasis::CondNumBasis(int tag, int cnOrder) : double xBar = 0., yBar = 0., zBar = 0.; double barycenter[3] = {0., 0., 0.}; - for (int i = 0; i < _nPrimMapNodes; i++) { - for (int j = 0; j < primMapBasis->points.size2(); ++j) { + for(int i = 0; i < _nPrimMapNodes; i++) { + for(int j = 0; j < primMapBasis->points.size2(); ++j) { barycenter[j] += primMapBasis->points(i, j); } } @@ -353,14 +383,14 @@ CondNumBasis::CondNumBasis(int tag, int cnOrder) : barycenter[1] /= _nPrimMapNodes; barycenter[2] /= _nPrimMapNodes; - double (*barDPsi)[3] = new double[_nPrimMapNodes][3]; + double(*barDPsi)[3] = new double[_nPrimMapNodes][3]; primMapBasis->df(xBar, yBar, zBar, barDPsi); // TODO: Make primGradShape from ideal element primGradShapeBarycenterX.resize(_nPrimMapNodes); primGradShapeBarycenterY.resize(_nPrimMapNodes); primGradShapeBarycenterZ.resize(_nPrimMapNodes); - for (int j=0; j<_nPrimMapNodes; j++) { + for(int j = 0; j < _nPrimMapNodes; j++) { primGradShapeBarycenterX(j) = barDPsi[j][0]; primGradShapeBarycenterY(j) = barDPsi[j][1]; primGradShapeBarycenterZ(j) = barDPsi[j][2]; @@ -369,7 +399,6 @@ CondNumBasis::CondNumBasis(int tag, int cnOrder) : delete[] barDPsi; } - int CondNumBasis::condNumOrder(int tag) { const int parentType = ElementType::getParentType(tag); @@ -377,86 +406,88 @@ int CondNumBasis::condNumOrder(int tag) return condNumOrder(parentType, order); } - int CondNumBasis::condNumOrder(int parentType, int order) { - switch (parentType) { - case TYPE_PNT : return 0; - case TYPE_LIN : return order - 1; - case TYPE_TRI : return (order == 1) ? 0 : order; - case TYPE_QUA : return order; - case TYPE_TET : return (order == 1) ? 0 : order; - case TYPE_PRI : return order; - case TYPE_HEX : return order; - case TYPE_PYR : return order; - case TYPE_TRIH : return 0; - default : - Msg::Error("Unknown element type %d, return order 0", parentType); - return 0; + switch(parentType) { + case TYPE_PNT: return 0; + case TYPE_LIN: return order - 1; + case TYPE_TRI: return (order == 1) ? 0 : order; + case TYPE_QUA: return order; + case TYPE_TET: return (order == 1) ? 0 : order; + case TYPE_PRI: return order; + case TYPE_HEX: return order; + case TYPE_PYR: return order; + case TYPE_TRIH: return 0; + default: + Msg::Error("Unknown element type %d, return order 0", parentType); + return 0; } } - -// Calculate the inverse condition number in Frobenius norm for one element, with normal vectors to straight -// element for regularization. Evaluation points depend on the given matrices for shape function gradients. -template<bool sign> -inline void CondNumBasis::getInvCondNumGeneral(int nCondNumNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &normals, - fullVector<double> &condNum) const +// Calculate the inverse condition number in Frobenius norm for one element, +// with normal vectors to straight element for regularization. Evaluation points +// depend on the given matrices for shape function gradients. +template <bool sign> +inline void CondNumBasis::getInvCondNumGeneral( + int nCondNumNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, + fullVector<double> &condNum) const { - switch (_dim) { + switch(_dim) { + case 0: { + for(int i = 0; i < nCondNumNodes; i++) condNum(i) = 1.; + break; + } - case 0 : { - for (int i = 0; i < nCondNumNodes; i++) condNum(i) = 1.; - break; - } + case 1: { + Msg::Warning("Inverse condition number not implemented in 1D"); + condNum.setAll(0.); + break; + } - case 1 : { - Msg::Warning("Inverse condition number not implemented in 1D"); - condNum.setAll(0.); - break; + case 2: { + fullMatrix<double> dxyzdX(nCondNumNodes, 3), dxyzdY(nCondNumNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + gSMatY.mult(nodesXYZ, dxyzdY); + for(int i = 0; i < nCondNumNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = dxyzdY(i, 0), &dydY = dxyzdY(i, 1), + &dzdY = dxyzdY(i, 2); + const double &nx = normals(0, 0), &ny = normals(0, 1), + &nz = normals(0, 2); + condNum(i) = + calcInvCondNum2D<sign>(dxdX, dxdY, dydX, dydY, dzdX, dzdY, nx, ny, nz); } + break; + } - case 2 : { - fullMatrix<double> dxyzdX(nCondNumNodes,3), dxyzdY(nCondNumNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - gSMatY.mult(nodesXYZ, dxyzdY); - for (int i = 0; i < nCondNumNodes; i++) { - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = dxyzdY(i,0), &dydY = dxyzdY(i,1), &dzdY = dxyzdY(i,2); - const double &nx = normals(0,0), &ny = normals(0,1), &nz = normals(0,2); - condNum(i) = calcInvCondNum2D<sign>(dxdX, dxdY, dydX, dydY, dzdX, dzdY, nx, ny, nz); - } + case 3: { + if(ElementType::getParentType(_tag) == TYPE_TRIH) { + for(int i = 0; i < nCondNumNodes; i++) condNum(i) = 1.; break; } - - case 3 : { - if (ElementType::getParentType(_tag) == TYPE_TRIH){ - for (int i = 0; i < nCondNumNodes; i++) condNum(i) = 1.; - break; - } - fullMatrix<double> dxyzdX(nCondNumNodes, 3), dxyzdY(nCondNumNodes, 3), dxyzdZ(nCondNumNodes, 3); - gSMatX.mult(nodesXYZ, dxyzdX); - gSMatY.mult(nodesXYZ, dxyzdY); - gSMatZ.mult(nodesXYZ, dxyzdZ); - for (int i = 0; i < nCondNumNodes; i++) { - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = dxyzdY(i,0), &dydY = dxyzdY(i,1), &dzdY = dxyzdY(i,2); - const double &dxdZ = dxyzdZ(i,0), &dydZ = dxyzdZ(i,1), &dzdZ = dxyzdZ(i,2); - condNum(i) = calcInvCondNum3D<sign>(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ); - } - break; + fullMatrix<double> dxyzdX(nCondNumNodes, 3), dxyzdY(nCondNumNodes, 3), + dxyzdZ(nCondNumNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + gSMatY.mult(nodesXYZ, dxyzdY); + gSMatZ.mult(nodesXYZ, dxyzdZ); + for(int i = 0; i < nCondNumNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = dxyzdY(i, 0), &dydY = dxyzdY(i, 1), + &dzdY = dxyzdY(i, 2); + const double &dxdZ = dxyzdZ(i, 0), &dydZ = dxyzdZ(i, 1), + &dzdZ = dxyzdZ(i, 2); + condNum(i) = calcInvCondNum3D<sign>(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, + dzdX, dzdY, dzdZ); } + break; + } } } - void CondNumBasis::getInvCondNumGeneral(int nCondNumNodes, const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, @@ -465,124 +496,117 @@ void CondNumBasis::getInvCondNumGeneral(int nCondNumNodes, fullVector<double> &invCond) const { fullMatrix<double> dumNormals; - getInvCondNumGeneral<false>(nCondNumNodes, gSMatX, gSMatY, gSMatZ, - nodesXYZ, dumNormals, invCond); + getInvCondNumGeneral<false>(nCondNumNodes, gSMatX, gSMatY, gSMatZ, nodesXYZ, + dumNormals, invCond); } - -void CondNumBasis::getSignedInvCondNumGeneral(int nCondNumNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &normals, - fullVector<double> &invCond) const +void CondNumBasis::getSignedInvCondNumGeneral( + int nCondNumNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, + fullVector<double> &invCond) const { - getInvCondNumGeneral<true>(nCondNumNodes, gSMatX, gSMatY, gSMatZ, - nodesXYZ, normals, invCond); + getInvCondNumGeneral<true>(nCondNumNodes, gSMatX, gSMatY, gSMatZ, nodesXYZ, + normals, invCond); } - -// Calculate the inverse condition number in Frobenius norm and its gradients w.r.t. node position, -// with normal vectors to straight element for regularization. Evaluation points depend on the -// given matrices for shape function gradients. -template<bool sign> -inline void CondNumBasis::getInvCondNumAndGradientsGeneral(int nCondNumNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &normals, - fullMatrix<double> &IDI) const +// Calculate the inverse condition number in Frobenius norm and its gradients +// w.r.t. node position, with normal vectors to straight element for +// regularization. Evaluation points depend on the given matrices for shape +// function gradients. +template <bool sign> +inline void CondNumBasis::getInvCondNumAndGradientsGeneral( + int nCondNumNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, + fullMatrix<double> &IDI) const { - fullMatrix<double> JDJ(nCondNumNodes, 3*_nMapNodes+1); - - switch (_dim) { - - case 0 : { - for (int i = 0; i < nCondNumNodes; i++) { - for (int j = 0; j < _nMapNodes; j++) { - IDI(i,j) = 0.; - IDI(i,j+1*_nMapNodes) = 0.; - IDI(i,j+2*_nMapNodes) = 0.; - } - IDI(i,3*_nMapNodes) = 1.; + fullMatrix<double> JDJ(nCondNumNodes, 3 * _nMapNodes + 1); + + switch(_dim) { + case 0: { + for(int i = 0; i < nCondNumNodes; i++) { + for(int j = 0; j < _nMapNodes; j++) { + IDI(i, j) = 0.; + IDI(i, j + 1 * _nMapNodes) = 0.; + IDI(i, j + 2 * _nMapNodes) = 0.; } - break; + IDI(i, 3 * _nMapNodes) = 1.; } + break; + } - case 1 : { - Msg::Warning("Inverse condition number not implemented in 1D"); - IDI.setAll(0.); - break; - } + case 1: { + Msg::Warning("Inverse condition number not implemented in 1D"); + IDI.setAll(0.); + break; + } - case 2 : { - fullMatrix<double> dxyzdX(nCondNumNodes,3), dxyzdY(nCondNumNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - gSMatY.mult(nodesXYZ, dxyzdY); - for (int i = 0; i < nCondNumNodes; i++) { - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = dxyzdY(i,0), &dydY = dxyzdY(i,1), &dzdY = dxyzdY(i,2); - const double &nx = normals(0,0), &ny = normals(0,1), &nz = normals(0,2); - calcGradInvCondNum2D<sign>(dxdX, dxdY, dydX, dydY, dzdX, dzdY, - nx, ny, nz, i, _nMapNodes, gSMatX, gSMatY, IDI); - } - break; + case 2: { + fullMatrix<double> dxyzdX(nCondNumNodes, 3), dxyzdY(nCondNumNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + gSMatY.mult(nodesXYZ, dxyzdY); + for(int i = 0; i < nCondNumNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = dxyzdY(i, 0), &dydY = dxyzdY(i, 1), + &dzdY = dxyzdY(i, 2); + const double &nx = normals(0, 0), &ny = normals(0, 1), + &nz = normals(0, 2); + calcGradInvCondNum2D<sign>(dxdX, dxdY, dydX, dydY, dzdX, dzdY, nx, ny, nz, + i, _nMapNodes, gSMatX, gSMatY, IDI); } + break; + } - case 3 : { - if (ElementType::getParentType(_tag) == TYPE_TRIH){ - for (int i = 0; i < nCondNumNodes; i++) { - for (int j = 0; j < _nMapNodes; j++) { - IDI(i,j) = 0.; - IDI(i,j+1*_nMapNodes) = 0.; - IDI(i,j+2*_nMapNodes) = 0.; - } - IDI(i,3*_nMapNodes) = 1.; + case 3: { + if(ElementType::getParentType(_tag) == TYPE_TRIH) { + for(int i = 0; i < nCondNumNodes; i++) { + for(int j = 0; j < _nMapNodes; j++) { + IDI(i, j) = 0.; + IDI(i, j + 1 * _nMapNodes) = 0.; + IDI(i, j + 2 * _nMapNodes) = 0.; } - break; - } - fullMatrix<double> dxyzdX(nCondNumNodes,3), dxyzdY(nCondNumNodes,3), dxyzdZ(nCondNumNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - gSMatY.mult(nodesXYZ, dxyzdY); - gSMatZ.mult(nodesXYZ, dxyzdZ); - for (int i = 0; i < nCondNumNodes; i++) { - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = dxyzdY(i,0), &dydY = dxyzdY(i,1), &dzdY = dxyzdY(i,2); - const double &dxdZ = dxyzdZ(i,0), &dydZ = dxyzdZ(i,1), &dzdZ = dxyzdZ(i,2); - calcGradInvCondNum3D<sign>(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ, - i, _nMapNodes, - gSMatX, gSMatY, gSMatZ, IDI); + IDI(i, 3 * _nMapNodes) = 1.; } break; } + fullMatrix<double> dxyzdX(nCondNumNodes, 3), dxyzdY(nCondNumNodes, 3), + dxyzdZ(nCondNumNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + gSMatY.mult(nodesXYZ, dxyzdY); + gSMatZ.mult(nodesXYZ, dxyzdZ); + for(int i = 0; i < nCondNumNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = dxyzdY(i, 0), &dydY = dxyzdY(i, 1), + &dzdY = dxyzdY(i, 2); + const double &dxdZ = dxyzdZ(i, 0), &dydZ = dxyzdZ(i, 1), + &dzdZ = dxyzdZ(i, 2); + calcGradInvCondNum3D<sign>(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, + dzdZ, i, _nMapNodes, gSMatX, gSMatY, gSMatZ, + IDI); + } + break; + } } } - -void CondNumBasis::getInvCondNumAndGradientsGeneral(int nCondNumNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - fullMatrix<double> &IDI) const +void CondNumBasis::getInvCondNumAndGradientsGeneral( + int nCondNumNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesXYZ, fullMatrix<double> &IDI) const { fullMatrix<double> dumNormals; getInvCondNumAndGradientsGeneral<false>(nCondNumNodes, gSMatX, gSMatY, gSMatZ, nodesXYZ, dumNormals, IDI); } - -void CondNumBasis::getSignedInvCondNumAndGradientsGeneral(int nCondNumNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &normals, - fullMatrix<double> &IDI) const +void CondNumBasis::getSignedInvCondNumAndGradientsGeneral( + int nCondNumNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, + fullMatrix<double> &IDI) const { getInvCondNumAndGradientsGeneral<true>(nCondNumNodes, gSMatX, gSMatY, gSMatZ, nodesXYZ, normals, IDI); diff --git a/Numeric/CondNumBasis.h b/Numeric/CondNumBasis.h index 7b4c30bc2d19494cffec838dd59f1708c13b51cd..8ee20fb47706ce82d6987187f70dd3544309c2bc 100644 --- a/Numeric/CondNumBasis.h +++ b/Numeric/CondNumBasis.h @@ -12,18 +12,18 @@ #include "JacobianBasis.h" class CondNumBasis { - private: +private: const GradientBasis *_gradBasis; const int _tag, _dim, _condNumOrder; fullVector<double> primGradShapeBarycenterX, primGradShapeBarycenterY, - primGradShapeBarycenterZ; + primGradShapeBarycenterZ; int _nCondNumNodes; int _nMapNodes, _nPrimMapNodes; - public : +public: CondNumBasis(int tag, int cnOrder = -1); // Get methods @@ -38,52 +38,49 @@ class CondNumBasis { // Condition number evaluation methods inline void getInvCondNum(const fullMatrix<double> &nodesXYZ, - fullVector<double> &invCond) const { - getInvCondNumGeneral(_nCondNumNodes, - _gradBasis->gradShapeIdealMatX, + fullVector<double> &invCond) const + { + getInvCondNumGeneral(_nCondNumNodes, _gradBasis->gradShapeIdealMatX, _gradBasis->gradShapeIdealMatY, - _gradBasis->gradShapeIdealMatZ, - nodesXYZ, invCond); + _gradBasis->gradShapeIdealMatZ, nodesXYZ, invCond); } inline void getSignedInvCondNum(const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, - fullVector<double> &invCond) const { - getSignedInvCondNumGeneral(_nCondNumNodes, - _gradBasis->gradShapeIdealMatX, + fullVector<double> &invCond) const + { + getSignedInvCondNumGeneral(_nCondNumNodes, _gradBasis->gradShapeIdealMatX, _gradBasis->gradShapeIdealMatY, - _gradBasis->gradShapeIdealMatZ, - nodesXYZ, normals, invCond); + _gradBasis->gradShapeIdealMatZ, nodesXYZ, + normals, invCond); } inline void getInvCondNumAndGradients(const fullMatrix<double> &nodesXYZ, - fullMatrix<double> &IDI) const { - getInvCondNumAndGradientsGeneral(_nCondNumNodes, - _gradBasis->gradShapeIdealMatX, - _gradBasis->gradShapeIdealMatY, - _gradBasis->gradShapeIdealMatZ, - nodesXYZ, IDI); + fullMatrix<double> &IDI) const + { + getInvCondNumAndGradientsGeneral( + _nCondNumNodes, _gradBasis->gradShapeIdealMatX, + _gradBasis->gradShapeIdealMatY, _gradBasis->gradShapeIdealMatZ, nodesXYZ, + IDI); } - inline void getSignedInvCondNumAndGradients(const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &normals, - fullMatrix<double> &IDI) const { - getSignedInvCondNumAndGradientsGeneral(_nCondNumNodes, - _gradBasis->gradShapeIdealMatX, - _gradBasis->gradShapeIdealMatY, - _gradBasis->gradShapeIdealMatZ, - nodesXYZ, normals, IDI); + inline void + getSignedInvCondNumAndGradients(const fullMatrix<double> &nodesXYZ, + const fullMatrix<double> &normals, + fullMatrix<double> &IDI) const + { + getSignedInvCondNumAndGradientsGeneral( + _nCondNumNodes, _gradBasis->gradShapeIdealMatX, + _gradBasis->gradShapeIdealMatY, _gradBasis->gradShapeIdealMatZ, nodesXYZ, + normals, IDI); } - - private : - template<bool sign> - void getInvCondNumGeneral(int nCondNumNodes, - const fullMatrix<double> &gSMatX, +private: + template <bool sign> + void getInvCondNumGeneral(int nCondNumNodes, const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, fullVector<double> &invCond) const; - void getInvCondNumGeneral(int nCondNumNodes, - const fullMatrix<double> &gSMatX, + void getInvCondNumGeneral(int nCondNumNodes, const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, const fullMatrix<double> &nodesXYZ, @@ -96,7 +93,7 @@ class CondNumBasis { const fullMatrix<double> &normals, fullVector<double> &invCond) const; - template<bool sign> + template <bool sign> void getInvCondNumAndGradientsGeneral(int nCondNumNodes, const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, @@ -104,21 +101,16 @@ class CondNumBasis { const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, fullMatrix<double> &IDI) const; - void getInvCondNumAndGradientsGeneral(int nCondNumNodes, // No normal given -> unsigned measure - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - fullMatrix<double> &IDI) const; - void getSignedInvCondNumAndGradientsGeneral(int nCondNumNodes, // Normals given -> signed measure - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &normals, - fullMatrix<double> &IDI) const; - - + void getInvCondNumAndGradientsGeneral( + int nCondNumNodes, // No normal given -> unsigned measure + const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, + const fullMatrix<double> &gSMatZ, const fullMatrix<double> &nodesXYZ, + fullMatrix<double> &IDI) const; + void getSignedInvCondNumAndGradientsGeneral( + int nCondNumNodes, // Normals given -> signed measure + const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, + const fullMatrix<double> &gSMatZ, const fullMatrix<double> &nodesXYZ, + const fullMatrix<double> &normals, fullMatrix<double> &IDI) const; }; #endif diff --git a/Numeric/ConjugateGradients.cpp b/Numeric/ConjugateGradients.cpp index e27a846b7edce2ead7703909d16252dfe2ec4676..bf76d18119823de4d8275347b3a8f4edfa4ed2d6 100644 --- a/Numeric/ConjugateGradients.cpp +++ b/Numeric/ConjugateGradients.cpp @@ -12,29 +12,30 @@ f(x+a*d) = f(x) + f'(x) ( */ -static double _norm (std::vector<double> &x){ +static double _norm(std::vector<double> &x) +{ double n = 0.0; - for (unsigned int i=0;i<x.size();i++)n += x[i]*x[i]; + for(unsigned int i = 0; i < x.size(); i++) n += x[i] * x[i]; return sqrt(n); } -static void scale (std::vector<double> &x, double s){ - for (unsigned int i=0;i<x.size();i++)x[i]*=s; +static void scale(std::vector<double> &x, double s) +{ + for(unsigned int i = 0; i < x.size(); i++) x[i] *= s; } -static void gmshLineSearch(void (*func)(std::vector<double> &x, - double &Obj, - bool needGrad, - std::vector<double> &gradObj, void *), // the function - void* data, // eventual data - std::vector<double> &x, // variables - std::vector<double> &p, // search direction - std::vector<double> &g, // gradient - double &f, - double stpmax, - int &check) +static void gmshLineSearch(void (*func)(std::vector<double> &x, double &Obj, + bool needGrad, + std::vector<double> &gradObj, + void *), // the function + void *data, // eventual data + std::vector<double> &x, // variables + std::vector<double> &p, // search direction + std::vector<double> &g, // gradient + double &f, double stpmax, int &check) { int i; - double alam, alam2 = 1., alamin, f2 = 0., fold2 = 0., rhs1, rhs2, temp, tmplam = 0.; + double alam, alam2 = 1., alamin, f2 = 0., fold2 = 0., rhs1, rhs2, temp, + tmplam = 0.; const double ALF = 1.e-4; const double TOLX = 1.0e-9; @@ -43,57 +44,67 @@ static void gmshLineSearch(void (*func)(std::vector<double> &x, double fold; (*func)(xold, fold, false, grad, data); - check=0; + check = 0; int n = x.size(); double norm = _norm(p); - if (norm > stpmax) scale(p,stpmax / norm); - double slope=0.0; - for (i = 0; i < n; i++) slope += g[i]*p[i]; - double test=0.0; - for (i = 0; i < n; i++) { + if(norm > stpmax) scale(p, stpmax / norm); + double slope = 0.0; + for(i = 0; i < n; i++) slope += g[i] * p[i]; + double test = 0.0; + for(i = 0; i < n; i++) { temp = fabs(p[i]) / std::max(fabs(xold[i]), 1.0); - if (temp > test) test = temp; + if(temp > test) test = temp; } alamin = TOLX / test; alam = 1.; while(1) { - for (i = 0; i < n; i++) x[i] = xold[i] + alam*p[i]; + for(i = 0; i < n; i++) x[i] = xold[i] + alam * p[i]; (*func)(x, f, false, grad, data); - if (f > 1.e280) alam*=.5; - else break; + if(f > 1.e280) + alam *= .5; + else + break; } while(1) { - for (i = 0; i < n; i++) x[i] = xold[i] + alam*p[i]; + for(i = 0; i < n; i++) x[i] = xold[i] + alam * p[i]; (*func)(x, f, false, grad, data); - // printf("alam = %12.5E alamin = %12.5E f = %12.5E fold = %12.5E slope %12.5E stuff %12.5E\n",alam,alamin,f,fold, slope, ALF * alam * slope); + // printf("alam = %12.5E alamin = %12.5E f = %12.5E fold = %12.5E slope + // %12.5E stuff %12.5E\n",alam,alamin,f,fold, slope, ALF * alam * + // slope); // f = (*func)(x, data); - if (alam < alamin) { - for (i = 0; i <n; i++) x[i] = xold[i]; + if(alam < alamin) { + for(i = 0; i < n; i++) x[i] = xold[i]; check = 1; return; } - else if (f <= fold + ALF * alam * slope) return; + else if(f <= fold + ALF * alam * slope) + return; else { - if (alam == 1.0) + if(alam == 1.0) tmplam = -slope / (2.0 * (f - fold - slope)); else { rhs1 = f - fold - alam * slope; rhs2 = f2 - fold2 - alam2 * slope; - const double a = (rhs1/(alam*alam)-rhs2/(alam2*alam2))/(alam-alam2); - const double b = (-alam2*rhs1/(alam*alam)+alam*rhs2/(alam2*alam2))/(alam-alam2); - if (a == 0.0) tmplam = -slope / (2.0 * b); + const double a = + (rhs1 / (alam * alam) - rhs2 / (alam2 * alam2)) / (alam - alam2); + const double b = + (-alam2 * rhs1 / (alam * alam) + alam * rhs2 / (alam2 * alam2)) / + (alam - alam2); + if(a == 0.0) + tmplam = -slope / (2.0 * b); else { - const double disc = b*b-3.0*a*slope; - if (disc < 0.0) Msg::Error("Roundoff problem in gmshLineSearch."); - else tmplam = (-b+sqrt(disc))/(3.0*a); + const double disc = b * b - 3.0 * a * slope; + if(disc < 0.0) + Msg::Error("Roundoff problem in gmshLineSearch."); + else + tmplam = (-b + sqrt(disc)) / (3.0 * a); } - if (tmplam > 0.5 * alam) - tmplam = 0.5 * alam; + if(tmplam > 0.5 * alam) tmplam = 0.5 * alam; } } alam2 = alam; @@ -103,14 +114,14 @@ static void gmshLineSearch(void (*func)(std::vector<double> &x, } } -// Simple Gradient Descent Minimization (use finite differences to compute the gradient) +// Simple Gradient Descent Minimization (use finite differences to compute the +// gradient) -double GradientDescent(void (*func)(std::vector<double> &x, - double &Obj, - bool needGrad, - std::vector<double> &gradObj, void *), // its gradient - std::vector<double> &x, // The variables - void *data) // User data +double GradientDescent(void (*func)(std::vector<double> &x, double &Obj, + bool needGrad, std::vector<double> &gradObj, + void *), // its gradient + std::vector<double> &x, // The variables + void *data) // User data { const int MAXIT = 3; const int N = x.size(); @@ -119,19 +130,19 @@ double GradientDescent(void (*func)(std::vector<double> &x, std::vector<double> dir(N); double f; -// printf("entering gradient descent (%d unknowns)...\n",N); + // printf("entering gradient descent (%d unknowns)...\n",N); - for (int iter = 0; iter < MAXIT; iter++){ + for(int iter = 0; iter < MAXIT; iter++) { // compute gradient of func - double stpmax=100000; + double stpmax = 100000; func(x, f, true, grad, data); // printf("computing f ... %22.15E\n",f); - for (int i=0;i<N;i++)dir[i] = -grad[i]; + for(int i = 0; i < N; i++) dir[i] = -grad[i]; int check; gmshLineSearch(func, data, x, dir, grad, f, stpmax, check); // printf("line search is done, f reduces to %22.15E\n",f); // printf("Line search done x = (%g %g) f = %g\n",x(0),x(1),f); - if (check == 1) break; + if(check == 1) break; } return f; } diff --git a/Numeric/ConjugateGradients.h b/Numeric/ConjugateGradients.h index e22929a8881cfe380ca06d034a2c7fa2df5d9c48..2e2aa414b7b9bf0f8af1b6c56389142f63e7589e 100644 --- a/Numeric/ConjugateGradients.h +++ b/Numeric/ConjugateGradients.h @@ -3,16 +3,15 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to the public mailing list <gmsh@onelab.info>. -#ifndef _CONJUGATEGRADIENTS -#define _CONJUGATEGRADIENTS +#ifndef _CONJUGATEGRADIENTS +#define _CONJUGATEGRADIENTS #include <vector> -double GradientDescent(void (*func)(std::vector<double> &x, - double &Obj, - bool needGrad, - std::vector<double> &gradObj, void *), - std::vector<double> &x, - void *data); // User data +double GradientDescent(void (*func)(std::vector<double> &x, double &Obj, + bool needGrad, std::vector<double> &gradObj, + void *), + std::vector<double> &x, + void *data); // User data #endif diff --git a/Numeric/ElementType.cpp b/Numeric/ElementType.cpp index ee2d7c11792069d0d66a4852eb0064a524a285f6..88801c54c3d6b3e565c6a4815e1467c294e84c0d 100644 --- a/Numeric/ElementType.cpp +++ b/Numeric/ElementType.cpp @@ -10,232 +10,285 @@ int ElementType::getParentType(int mshtype) { switch(mshtype) { - case(MSH_PNT): - return TYPE_PNT; - case(MSH_LIN_2): case(MSH_LIN_3): - case(MSH_LIN_4): case(MSH_LIN_5): - case(MSH_LIN_6): case(MSH_LIN_7): - case(MSH_LIN_8): case(MSH_LIN_9): - case(MSH_LIN_10): case(MSH_LIN_11): - case(MSH_LIN_B): case(MSH_LIN_C): - case(MSH_LIN_1): - return TYPE_LIN; - case(MSH_TRI_3): case(MSH_TRI_6): - case(MSH_TRI_9): case(MSH_TRI_10): - case(MSH_TRI_12): case(MSH_TRI_15): - case(MSH_TRI_15I): case(MSH_TRI_21): - case(MSH_TRI_28): case(MSH_TRI_36): - case(MSH_TRI_45): case(MSH_TRI_55): - case(MSH_TRI_66): case(MSH_TRI_18): - case(MSH_TRI_21I): case(MSH_TRI_24): - case(MSH_TRI_27): case(MSH_TRI_30): - case(MSH_TRI_B): case(MSH_TRI_1): - return TYPE_TRI; - case(MSH_QUA_4): case(MSH_QUA_9): - case(MSH_QUA_8): case(MSH_QUA_16): - case(MSH_QUA_25): case(MSH_QUA_36): - case(MSH_QUA_12): case(MSH_QUA_16I): - case(MSH_QUA_20): case(MSH_QUA_49): - case(MSH_QUA_64): case(MSH_QUA_81): - case(MSH_QUA_100): case(MSH_QUA_121): - case(MSH_QUA_24): case(MSH_QUA_28): - case(MSH_QUA_32): case(MSH_QUA_36I): - case(MSH_QUA_40): case(MSH_QUA_1): - return TYPE_QUA; - case(MSH_TET_4): case(MSH_TET_10): - case(MSH_TET_20): case(MSH_TET_35): - case(MSH_TET_56): case(MSH_TET_22): - case(MSH_TET_28): case(MSH_TET_84): - case(MSH_TET_120): case(MSH_TET_165): - case(MSH_TET_220): case(MSH_TET_286): - case(MSH_TET_34): case(MSH_TET_40): - case(MSH_TET_46): case(MSH_TET_52): - case(MSH_TET_58): case(MSH_TET_1): - case(MSH_TET_16): - return TYPE_TET; - case(MSH_PYR_5): case(MSH_PYR_14): - case(MSH_PYR_13): case(MSH_PYR_30): - case(MSH_PYR_55): case(MSH_PYR_91): - case(MSH_PYR_140): case(MSH_PYR_204): - case(MSH_PYR_285): case(MSH_PYR_385): - case(MSH_PYR_21): case(MSH_PYR_29): - case(MSH_PYR_37): case(MSH_PYR_45): - case(MSH_PYR_53): case(MSH_PYR_61): - case(MSH_PYR_69): case(MSH_PYR_1): - return TYPE_PYR; - case(MSH_PRI_6): case(MSH_PRI_18): - case(MSH_PRI_15): case(MSH_PRI_1): - case(MSH_PRI_40): case(MSH_PRI_75): - case(MSH_PRI_126): case(MSH_PRI_196): - case(MSH_PRI_288): case(MSH_PRI_405): - case(MSH_PRI_550): case(MSH_PRI_24): - case(MSH_PRI_33): case(MSH_PRI_42): - case(MSH_PRI_51): case(MSH_PRI_60): - case(MSH_PRI_69): case(MSH_PRI_78): - return TYPE_PRI; - case(MSH_HEX_8): case(MSH_HEX_27): - case(MSH_HEX_20): case(MSH_HEX_1): - case(MSH_HEX_64): case(MSH_HEX_125): - case(MSH_HEX_216): case(MSH_HEX_343): - case(MSH_HEX_512): case(MSH_HEX_729): - case(MSH_HEX_1000): case(MSH_HEX_32): - case(MSH_HEX_44): case(MSH_HEX_56): - case(MSH_HEX_68): case(MSH_HEX_80): - case(MSH_HEX_92): case(MSH_HEX_104): - return TYPE_HEX; - case(MSH_POLYG_): case(MSH_POLYG_B): - return TYPE_POLYG; - case(MSH_POLYH_): - return TYPE_POLYH; - case(MSH_PNT_SUB): case(MSH_LIN_SUB): - case(MSH_TRI_SUB): case(MSH_TET_SUB): - return TYPE_XFEM; - case(MSH_TRI_MINI): - case(MSH_TET_MINI): - return TYPE_MINI; - case(MSH_TRIH_4): - return TYPE_TRIH; - - default: - Msg::Error("Unknown element MSH type %i for parent type, returning -1.", mshtype); - return -1; + case(MSH_PNT): return TYPE_PNT; + case(MSH_LIN_2): + case(MSH_LIN_3): + case(MSH_LIN_4): + case(MSH_LIN_5): + case(MSH_LIN_6): + case(MSH_LIN_7): + case(MSH_LIN_8): + case(MSH_LIN_9): + case(MSH_LIN_10): + case(MSH_LIN_11): + case(MSH_LIN_B): + case(MSH_LIN_C): + case(MSH_LIN_1): return TYPE_LIN; + case(MSH_TRI_3): + case(MSH_TRI_6): + case(MSH_TRI_9): + case(MSH_TRI_10): + case(MSH_TRI_12): + case(MSH_TRI_15): + case(MSH_TRI_15I): + case(MSH_TRI_21): + case(MSH_TRI_28): + case(MSH_TRI_36): + case(MSH_TRI_45): + case(MSH_TRI_55): + case(MSH_TRI_66): + case(MSH_TRI_18): + case(MSH_TRI_21I): + case(MSH_TRI_24): + case(MSH_TRI_27): + case(MSH_TRI_30): + case(MSH_TRI_B): + case(MSH_TRI_1): return TYPE_TRI; + case(MSH_QUA_4): + case(MSH_QUA_9): + case(MSH_QUA_8): + case(MSH_QUA_16): + case(MSH_QUA_25): + case(MSH_QUA_36): + case(MSH_QUA_12): + case(MSH_QUA_16I): + case(MSH_QUA_20): + case(MSH_QUA_49): + case(MSH_QUA_64): + case(MSH_QUA_81): + case(MSH_QUA_100): + case(MSH_QUA_121): + case(MSH_QUA_24): + case(MSH_QUA_28): + case(MSH_QUA_32): + case(MSH_QUA_36I): + case(MSH_QUA_40): + case(MSH_QUA_1): return TYPE_QUA; + case(MSH_TET_4): + case(MSH_TET_10): + case(MSH_TET_20): + case(MSH_TET_35): + case(MSH_TET_56): + case(MSH_TET_22): + case(MSH_TET_28): + case(MSH_TET_84): + case(MSH_TET_120): + case(MSH_TET_165): + case(MSH_TET_220): + case(MSH_TET_286): + case(MSH_TET_34): + case(MSH_TET_40): + case(MSH_TET_46): + case(MSH_TET_52): + case(MSH_TET_58): + case(MSH_TET_1): + case(MSH_TET_16): return TYPE_TET; + case(MSH_PYR_5): + case(MSH_PYR_14): + case(MSH_PYR_13): + case(MSH_PYR_30): + case(MSH_PYR_55): + case(MSH_PYR_91): + case(MSH_PYR_140): + case(MSH_PYR_204): + case(MSH_PYR_285): + case(MSH_PYR_385): + case(MSH_PYR_21): + case(MSH_PYR_29): + case(MSH_PYR_37): + case(MSH_PYR_45): + case(MSH_PYR_53): + case(MSH_PYR_61): + case(MSH_PYR_69): + case(MSH_PYR_1): return TYPE_PYR; + case(MSH_PRI_6): + case(MSH_PRI_18): + case(MSH_PRI_15): + case(MSH_PRI_1): + case(MSH_PRI_40): + case(MSH_PRI_75): + case(MSH_PRI_126): + case(MSH_PRI_196): + case(MSH_PRI_288): + case(MSH_PRI_405): + case(MSH_PRI_550): + case(MSH_PRI_24): + case(MSH_PRI_33): + case(MSH_PRI_42): + case(MSH_PRI_51): + case(MSH_PRI_60): + case(MSH_PRI_69): + case(MSH_PRI_78): return TYPE_PRI; + case(MSH_HEX_8): + case(MSH_HEX_27): + case(MSH_HEX_20): + case(MSH_HEX_1): + case(MSH_HEX_64): + case(MSH_HEX_125): + case(MSH_HEX_216): + case(MSH_HEX_343): + case(MSH_HEX_512): + case(MSH_HEX_729): + case(MSH_HEX_1000): + case(MSH_HEX_32): + case(MSH_HEX_44): + case(MSH_HEX_56): + case(MSH_HEX_68): + case(MSH_HEX_80): + case(MSH_HEX_92): + case(MSH_HEX_104): return TYPE_HEX; + case(MSH_POLYG_): + case(MSH_POLYG_B): return TYPE_POLYG; + case(MSH_POLYH_): return TYPE_POLYH; + case(MSH_PNT_SUB): + case(MSH_LIN_SUB): + case(MSH_TRI_SUB): + case(MSH_TET_SUB): return TYPE_XFEM; + case(MSH_TRI_MINI): + case(MSH_TET_MINI): return TYPE_MINI; + case(MSH_TRIH_4): return TYPE_TRIH; + + default: + Msg::Error("Unknown element MSH type %i for parent type, returning -1.", + mshtype); + return -1; } } int ElementType::getOrder(int mshtype) { - switch (mshtype) { - case MSH_PNT : return 0; - case MSH_LIN_1 : return 0; - case MSH_LIN_2 : return 1; - case MSH_LIN_3 : return 2; - case MSH_LIN_4 : return 3; - case MSH_LIN_5 : return 4; - case MSH_LIN_6 : return 5; - case MSH_LIN_7 : return 6; - case MSH_LIN_8 : return 7; - case MSH_LIN_9 : return 8; - case MSH_LIN_10 : return 9; - case MSH_LIN_11 : return 10; - case MSH_TRI_1 : return 0; - case MSH_TRI_3 : return 1; - case MSH_TRI_6 : return 2; - case MSH_TRI_10 : return 3; - case MSH_TRI_15 : return 4; - case MSH_TRI_21 : return 5; - case MSH_TRI_28 : return 6; - case MSH_TRI_36 : return 7; - case MSH_TRI_45 : return 8; - case MSH_TRI_55 : return 9; - case MSH_TRI_66 : return 10; - case MSH_TRI_9 : return 3; - case MSH_TRI_12 : return 4; - case MSH_TRI_15I : return 5; - case MSH_TRI_18 : return 6; - case MSH_TRI_21I : return 7; - case MSH_TRI_24 : return 8; - case MSH_TRI_27 : return 9; - case MSH_TRI_30 : return 10; - case MSH_TRI_MINI : return 1; - case MSH_POLYG_ : return 1; - case MSH_POLYG_B : return 1; - case MSH_TET_1 : return 0; - case MSH_TET_4 : return 1; - case MSH_TET_10 : return 2; - case MSH_TET_20 : return 3; - case MSH_TET_35 : return 4; - case MSH_TET_56 : return 5; - case MSH_TET_84 : return 6; - case MSH_TET_120 : return 7; - case MSH_TET_165 : return 8; - case MSH_TET_220 : return 9; - case MSH_TET_286 : return 10; - case MSH_TET_16 : return 3; - case MSH_TET_22 : return 4; - case MSH_TET_28 : return 5; - case MSH_TET_34 : return 6; - case MSH_TET_40 : return 7; - case MSH_TET_46 : return 8; - case MSH_TET_52 : return 9; - case MSH_TET_58 : return 10; - case MSH_TET_MINI : return 1; - case MSH_QUA_1 : return 0; - case MSH_QUA_4 : return 1; - case MSH_QUA_9 : return 2; - case MSH_QUA_16 : return 3; - case MSH_QUA_25 : return 4; - case MSH_QUA_36 : return 5; - case MSH_QUA_49 : return 6; - case MSH_QUA_64 : return 7; - case MSH_QUA_81 : return 8; - case MSH_QUA_100 : return 9; - case MSH_QUA_121 : return 10; - case MSH_QUA_8 : return 2; - case MSH_QUA_12 : return 3; - case MSH_QUA_16I : return 4; - case MSH_QUA_20 : return 5; - case MSH_QUA_24 : return 6; - case MSH_QUA_28 : return 7; - case MSH_QUA_32 : return 8; - case MSH_QUA_36I : return 9; - case MSH_QUA_40 : return 10; - case MSH_PRI_1 : return 0; - case MSH_PRI_6 : return 1; - case MSH_PRI_18 : return 2; - case MSH_PRI_40 : return 3; - case MSH_PRI_75 : return 4; - case MSH_PRI_126 : return 5; - case MSH_PRI_196 : return 6; - case MSH_PRI_288 : return 7; - case MSH_PRI_405 : return 8; - case MSH_PRI_550 : return 9; - case MSH_PRI_15 : return 2; - case MSH_PRI_24 : return 3; - case MSH_PRI_33 : return 4; - case MSH_PRI_42 : return 5; - case MSH_PRI_51 : return 6; - case MSH_PRI_60 : return 7; - case MSH_PRI_69 : return 8; - case MSH_PRI_78 : return 9; - case MSH_HEX_1 : return 0; - case MSH_HEX_8 : return 1; - case MSH_HEX_27 : return 2; - case MSH_HEX_64 : return 3; - case MSH_HEX_125 : return 4; - case MSH_HEX_216 : return 5; - case MSH_HEX_343 : return 6; - case MSH_HEX_512 : return 7; - case MSH_HEX_729 : return 8; + switch(mshtype) { + case MSH_PNT: return 0; + case MSH_LIN_1: return 0; + case MSH_LIN_2: return 1; + case MSH_LIN_3: return 2; + case MSH_LIN_4: return 3; + case MSH_LIN_5: return 4; + case MSH_LIN_6: return 5; + case MSH_LIN_7: return 6; + case MSH_LIN_8: return 7; + case MSH_LIN_9: return 8; + case MSH_LIN_10: return 9; + case MSH_LIN_11: return 10; + case MSH_TRI_1: return 0; + case MSH_TRI_3: return 1; + case MSH_TRI_6: return 2; + case MSH_TRI_10: return 3; + case MSH_TRI_15: return 4; + case MSH_TRI_21: return 5; + case MSH_TRI_28: return 6; + case MSH_TRI_36: return 7; + case MSH_TRI_45: return 8; + case MSH_TRI_55: return 9; + case MSH_TRI_66: return 10; + case MSH_TRI_9: return 3; + case MSH_TRI_12: return 4; + case MSH_TRI_15I: return 5; + case MSH_TRI_18: return 6; + case MSH_TRI_21I: return 7; + case MSH_TRI_24: return 8; + case MSH_TRI_27: return 9; + case MSH_TRI_30: return 10; + case MSH_TRI_MINI: return 1; + case MSH_POLYG_: return 1; + case MSH_POLYG_B: return 1; + case MSH_TET_1: return 0; + case MSH_TET_4: return 1; + case MSH_TET_10: return 2; + case MSH_TET_20: return 3; + case MSH_TET_35: return 4; + case MSH_TET_56: return 5; + case MSH_TET_84: return 6; + case MSH_TET_120: return 7; + case MSH_TET_165: return 8; + case MSH_TET_220: return 9; + case MSH_TET_286: return 10; + case MSH_TET_16: return 3; + case MSH_TET_22: return 4; + case MSH_TET_28: return 5; + case MSH_TET_34: return 6; + case MSH_TET_40: return 7; + case MSH_TET_46: return 8; + case MSH_TET_52: return 9; + case MSH_TET_58: return 10; + case MSH_TET_MINI: return 1; + case MSH_QUA_1: return 0; + case MSH_QUA_4: return 1; + case MSH_QUA_9: return 2; + case MSH_QUA_16: return 3; + case MSH_QUA_25: return 4; + case MSH_QUA_36: return 5; + case MSH_QUA_49: return 6; + case MSH_QUA_64: return 7; + case MSH_QUA_81: return 8; + case MSH_QUA_100: return 9; + case MSH_QUA_121: return 10; + case MSH_QUA_8: return 2; + case MSH_QUA_12: return 3; + case MSH_QUA_16I: return 4; + case MSH_QUA_20: return 5; + case MSH_QUA_24: return 6; + case MSH_QUA_28: return 7; + case MSH_QUA_32: return 8; + case MSH_QUA_36I: return 9; + case MSH_QUA_40: return 10; + case MSH_PRI_1: return 0; + case MSH_PRI_6: return 1; + case MSH_PRI_18: return 2; + case MSH_PRI_40: return 3; + case MSH_PRI_75: return 4; + case MSH_PRI_126: return 5; + case MSH_PRI_196: return 6; + case MSH_PRI_288: return 7; + case MSH_PRI_405: return 8; + case MSH_PRI_550: return 9; + case MSH_PRI_15: return 2; + case MSH_PRI_24: return 3; + case MSH_PRI_33: return 4; + case MSH_PRI_42: return 5; + case MSH_PRI_51: return 6; + case MSH_PRI_60: return 7; + case MSH_PRI_69: return 8; + case MSH_PRI_78: return 9; + case MSH_HEX_1: return 0; + case MSH_HEX_8: return 1; + case MSH_HEX_27: return 2; + case MSH_HEX_64: return 3; + case MSH_HEX_125: return 4; + case MSH_HEX_216: return 5; + case MSH_HEX_343: return 6; + case MSH_HEX_512: return 7; + case MSH_HEX_729: return 8; case MSH_HEX_1000: return 9; - case MSH_HEX_20 : return 2; - case MSH_HEX_32 : return 3; - case MSH_HEX_44 : return 4; - case MSH_HEX_56 : return 5; - case MSH_HEX_68 : return 6; - case MSH_HEX_80 : return 7; - case MSH_HEX_92 : return 8; - case MSH_HEX_104 : return 9; - case MSH_PYR_1 : return 0; - case MSH_PYR_5 : return 1; - case MSH_PYR_14 : return 2; - case MSH_PYR_30 : return 3; - case MSH_PYR_55 : return 4; - case MSH_PYR_91 : return 5; - case MSH_PYR_140 : return 6; - case MSH_PYR_204 : return 7; - case MSH_PYR_285 : return 8; - case MSH_PYR_385 : return 9; - case MSH_PYR_13 : return 2; - case MSH_PYR_21 : return 3; - case MSH_PYR_29 : return 4; - case MSH_PYR_37 : return 5; - case MSH_PYR_45 : return 6; - case MSH_PYR_53 : return 7; - case MSH_PYR_61 : return 8; - case MSH_PYR_69 : return 9; - case MSH_TRIH_4 : return 1; - case MSH_POLYH_ : return 1; - default : + case MSH_HEX_20: return 2; + case MSH_HEX_32: return 3; + case MSH_HEX_44: return 4; + case MSH_HEX_56: return 5; + case MSH_HEX_68: return 6; + case MSH_HEX_80: return 7; + case MSH_HEX_92: return 8; + case MSH_HEX_104: return 9; + case MSH_PYR_1: return 0; + case MSH_PYR_5: return 1; + case MSH_PYR_14: return 2; + case MSH_PYR_30: return 3; + case MSH_PYR_55: return 4; + case MSH_PYR_91: return 5; + case MSH_PYR_140: return 6; + case MSH_PYR_204: return 7; + case MSH_PYR_285: return 8; + case MSH_PYR_385: return 9; + case MSH_PYR_13: return 2; + case MSH_PYR_21: return 3; + case MSH_PYR_29: return 4; + case MSH_PYR_37: return 5; + case MSH_PYR_45: return 6; + case MSH_PYR_53: return 7; + case MSH_PYR_61: return 8; + case MSH_PYR_69: return 9; + case MSH_TRIH_4: return 1; + case MSH_POLYH_: return 1; + default: Msg::Warning("Unknown element MSH type %d, assuming order 1.", mshtype); return 1; } @@ -244,234 +297,299 @@ int ElementType::getOrder(int mshtype) int ElementType::getDimension(int mshtype) { switch(mshtype) { - case(MSH_PNT): case(MSH_PNT_SUB): - return 0; - - case(MSH_LIN_2): case(MSH_LIN_3): - case(MSH_LIN_4): case(MSH_LIN_5): - case(MSH_LIN_6): case(MSH_LIN_7): - case(MSH_LIN_8): case(MSH_LIN_9): - case(MSH_LIN_10): case(MSH_LIN_11): - case(MSH_LIN_B): case(MSH_LIN_C): - case(MSH_LIN_1): case(MSH_LIN_SUB): - return 1; - - case(MSH_TRI_3): case(MSH_TRI_6): - case(MSH_TRI_9): case(MSH_TRI_10): - case(MSH_TRI_12): case(MSH_TRI_15): - case(MSH_TRI_15I): case(MSH_TRI_21): - case(MSH_TRI_28): case(MSH_TRI_36): - case(MSH_TRI_45): case(MSH_TRI_55): - case(MSH_TRI_66): case(MSH_TRI_18): - case(MSH_TRI_21I): case(MSH_TRI_24): - case(MSH_TRI_27): case(MSH_TRI_30): - case(MSH_TRI_B): case(MSH_TRI_1): - case(MSH_TRI_SUB): case(MSH_TRI_MINI): - - case(MSH_QUA_4): case(MSH_QUA_9): - case(MSH_QUA_8): case(MSH_QUA_16): - case(MSH_QUA_25): case(MSH_QUA_36): - case(MSH_QUA_12): case(MSH_QUA_16I): - case(MSH_QUA_20): case(MSH_QUA_49): - case(MSH_QUA_64): case(MSH_QUA_81): - case(MSH_QUA_100): case(MSH_QUA_121): - case(MSH_QUA_24): case(MSH_QUA_28): - case(MSH_QUA_32): case(MSH_QUA_36I): - case(MSH_QUA_40): case(MSH_QUA_1): - - case(MSH_POLYG_): case(MSH_POLYG_B): - return 2; - - case(MSH_TET_4): case(MSH_TET_10): - case(MSH_TET_20): case(MSH_TET_35): - case(MSH_TET_56): case(MSH_TET_22): - case(MSH_TET_28): case(MSH_TET_84): - case(MSH_TET_120): case(MSH_TET_165): - case(MSH_TET_220): case(MSH_TET_286): - case(MSH_TET_34): case(MSH_TET_40): - case(MSH_TET_46): case(MSH_TET_52): - case(MSH_TET_58): case(MSH_TET_1): - case(MSH_TET_16): case(MSH_TET_SUB): - case(MSH_TET_MINI): - - case(MSH_PYR_5): case(MSH_PYR_14): - case(MSH_PYR_13): case(MSH_PYR_30): - case(MSH_PYR_55): case(MSH_PYR_91): - case(MSH_PYR_140): case(MSH_PYR_204): - case(MSH_PYR_285): case(MSH_PYR_385): - case(MSH_PYR_21): case(MSH_PYR_29): - case(MSH_PYR_37): case(MSH_PYR_45): - case(MSH_PYR_53): case(MSH_PYR_61): - case(MSH_PYR_69): case(MSH_PYR_1): - - case(MSH_PRI_6): case(MSH_PRI_18): - case(MSH_PRI_15): case(MSH_PRI_1): - case(MSH_PRI_40): case(MSH_PRI_75): - case(MSH_PRI_126): case(MSH_PRI_196): - case(MSH_PRI_288): case(MSH_PRI_405): - case(MSH_PRI_550): case(MSH_PRI_24): - case(MSH_PRI_33): case(MSH_PRI_42): - case(MSH_PRI_51): case(MSH_PRI_60): - case(MSH_PRI_69): case(MSH_PRI_78): - - case(MSH_HEX_8): case(MSH_HEX_27): - case(MSH_HEX_20): case(MSH_HEX_1): - case(MSH_HEX_64): case(MSH_HEX_125): - case(MSH_HEX_216): case(MSH_HEX_343): - case(MSH_HEX_512): case(MSH_HEX_729): - case(MSH_HEX_1000): case(MSH_HEX_32): - case(MSH_HEX_44): case(MSH_HEX_56): - case(MSH_HEX_68): case(MSH_HEX_80): - case(MSH_HEX_92): case(MSH_HEX_104): - - case(MSH_TRIH_4): - - case(MSH_POLYH_): - return 3; - - default: - Msg::Error("Unknown element MSH type %i for dimension, returning -1.", mshtype); - return -1; + case(MSH_PNT): + case(MSH_PNT_SUB): return 0; + + case(MSH_LIN_2): + case(MSH_LIN_3): + case(MSH_LIN_4): + case(MSH_LIN_5): + case(MSH_LIN_6): + case(MSH_LIN_7): + case(MSH_LIN_8): + case(MSH_LIN_9): + case(MSH_LIN_10): + case(MSH_LIN_11): + case(MSH_LIN_B): + case(MSH_LIN_C): + case(MSH_LIN_1): + case(MSH_LIN_SUB): return 1; + + case(MSH_TRI_3): + case(MSH_TRI_6): + case(MSH_TRI_9): + case(MSH_TRI_10): + case(MSH_TRI_12): + case(MSH_TRI_15): + case(MSH_TRI_15I): + case(MSH_TRI_21): + case(MSH_TRI_28): + case(MSH_TRI_36): + case(MSH_TRI_45): + case(MSH_TRI_55): + case(MSH_TRI_66): + case(MSH_TRI_18): + case(MSH_TRI_21I): + case(MSH_TRI_24): + case(MSH_TRI_27): + case(MSH_TRI_30): + case(MSH_TRI_B): + case(MSH_TRI_1): + case(MSH_TRI_SUB): + case(MSH_TRI_MINI): + + case(MSH_QUA_4): + case(MSH_QUA_9): + case(MSH_QUA_8): + case(MSH_QUA_16): + case(MSH_QUA_25): + case(MSH_QUA_36): + case(MSH_QUA_12): + case(MSH_QUA_16I): + case(MSH_QUA_20): + case(MSH_QUA_49): + case(MSH_QUA_64): + case(MSH_QUA_81): + case(MSH_QUA_100): + case(MSH_QUA_121): + case(MSH_QUA_24): + case(MSH_QUA_28): + case(MSH_QUA_32): + case(MSH_QUA_36I): + case(MSH_QUA_40): + case(MSH_QUA_1): + + case(MSH_POLYG_): + case(MSH_POLYG_B): return 2; + + case(MSH_TET_4): + case(MSH_TET_10): + case(MSH_TET_20): + case(MSH_TET_35): + case(MSH_TET_56): + case(MSH_TET_22): + case(MSH_TET_28): + case(MSH_TET_84): + case(MSH_TET_120): + case(MSH_TET_165): + case(MSH_TET_220): + case(MSH_TET_286): + case(MSH_TET_34): + case(MSH_TET_40): + case(MSH_TET_46): + case(MSH_TET_52): + case(MSH_TET_58): + case(MSH_TET_1): + case(MSH_TET_16): + case(MSH_TET_SUB): + case(MSH_TET_MINI): + + case(MSH_PYR_5): + case(MSH_PYR_14): + case(MSH_PYR_13): + case(MSH_PYR_30): + case(MSH_PYR_55): + case(MSH_PYR_91): + case(MSH_PYR_140): + case(MSH_PYR_204): + case(MSH_PYR_285): + case(MSH_PYR_385): + case(MSH_PYR_21): + case(MSH_PYR_29): + case(MSH_PYR_37): + case(MSH_PYR_45): + case(MSH_PYR_53): + case(MSH_PYR_61): + case(MSH_PYR_69): + case(MSH_PYR_1): + + case(MSH_PRI_6): + case(MSH_PRI_18): + case(MSH_PRI_15): + case(MSH_PRI_1): + case(MSH_PRI_40): + case(MSH_PRI_75): + case(MSH_PRI_126): + case(MSH_PRI_196): + case(MSH_PRI_288): + case(MSH_PRI_405): + case(MSH_PRI_550): + case(MSH_PRI_24): + case(MSH_PRI_33): + case(MSH_PRI_42): + case(MSH_PRI_51): + case(MSH_PRI_60): + case(MSH_PRI_69): + case(MSH_PRI_78): + + case(MSH_HEX_8): + case(MSH_HEX_27): + case(MSH_HEX_20): + case(MSH_HEX_1): + case(MSH_HEX_64): + case(MSH_HEX_125): + case(MSH_HEX_216): + case(MSH_HEX_343): + case(MSH_HEX_512): + case(MSH_HEX_729): + case(MSH_HEX_1000): + case(MSH_HEX_32): + case(MSH_HEX_44): + case(MSH_HEX_56): + case(MSH_HEX_68): + case(MSH_HEX_80): + case(MSH_HEX_92): + case(MSH_HEX_104): + + case(MSH_TRIH_4): + + case(MSH_POLYH_): return 3; + + default: + Msg::Error("Unknown element MSH type %i for dimension, returning -1.", + mshtype); + return -1; } } // Give the number of node corresponding to a msh type. int ElementType::getNumVertices(int mshtype) { - switch (mshtype) { - case MSH_PNT : return 1; - case MSH_LIN_1 : return 1; - case MSH_LIN_2 : return 2; - case MSH_LIN_3 : return 3; - case MSH_LIN_4 : return 4; - case MSH_LIN_5 : return 5; - case MSH_LIN_6 : return 6; - case MSH_LIN_7 : return 7; - case MSH_LIN_8 : return 8; - case MSH_LIN_9 : return 9; - case MSH_LIN_10 : return 10; - case MSH_LIN_11 : return 11; - case MSH_TRI_1 : return 1; - case MSH_TRI_3 : return 3; - case MSH_TRI_6 : return 6; - case MSH_TRI_10 : return 10; - case MSH_TRI_15 : return 15; - case MSH_TRI_21 : return 21; - case MSH_TRI_28 : return 28; - case MSH_TRI_36 : return 36; - case MSH_TRI_45 : return 45; - case MSH_TRI_55 : return 55; - case MSH_TRI_66 : return 66; - case MSH_TRI_9 : return 9; - case MSH_TRI_12 : return 12; - case MSH_TRI_15I : return 15; - case MSH_TRI_18 : return 18; - case MSH_TRI_21I : return 21; - case MSH_TRI_24 : return 24; - case MSH_TRI_27 : return 27; - case MSH_TRI_30 : return 30; - //case MSH_TRI_MINI : return 0; - //case MSH_POLYG_ : return 0; - //case MSH_POLYG_B : return 0; - case MSH_TET_1 : return 1; - case MSH_TET_4 : return 4; - case MSH_TET_10 : return 10; - case MSH_TET_20 : return 20; - case MSH_TET_35 : return 35; - case MSH_TET_56 : return 56; - case MSH_TET_84 : return 84; - case MSH_TET_120 : return 120; - case MSH_TET_165 : return 165; - case MSH_TET_220 : return 220; - case MSH_TET_286 : return 286; - case MSH_TET_16 : return 16; - case MSH_TET_22 : return 22; - case MSH_TET_28 : return 28; - case MSH_TET_34 : return 34; - case MSH_TET_40 : return 40; - case MSH_TET_46 : return 46; - case MSH_TET_52 : return 52; - case MSH_TET_58 : return 58; - //case MSH_TET_MINI : return 0; - case MSH_QUA_1 : return 1; - case MSH_QUA_4 : return 4; - case MSH_QUA_9 : return 9; - case MSH_QUA_16 : return 16; - case MSH_QUA_25 : return 25; - case MSH_QUA_36 : return 36; - case MSH_QUA_49 : return 49; - case MSH_QUA_64 : return 64; - case MSH_QUA_81 : return 81; - case MSH_QUA_100 : return 100; - case MSH_QUA_121 : return 121; - case MSH_QUA_8 : return 8; - case MSH_QUA_12 : return 12; - case MSH_QUA_16I : return 16; - case MSH_QUA_20 : return 20; - case MSH_QUA_24 : return 24; - case MSH_QUA_28 : return 28; - case MSH_QUA_32 : return 32; - case MSH_QUA_36I : return 36; - case MSH_QUA_40 : return 40; - case MSH_PRI_1 : return 1; - case MSH_PRI_6 : return 6; - case MSH_PRI_18 : return 18; - case MSH_PRI_40 : return 40; - case MSH_PRI_75 : return 75; - case MSH_PRI_126 : return 126; - case MSH_PRI_196 : return 196; - case MSH_PRI_288 : return 288; - case MSH_PRI_405 : return 405; - case MSH_PRI_550 : return 550; - case MSH_PRI_15 : return 15; - case MSH_PRI_24 : return 24; - case MSH_PRI_33 : return 33; - case MSH_PRI_42 : return 42; - case MSH_PRI_51 : return 51; - case MSH_PRI_60 : return 60; - case MSH_PRI_69 : return 69; - case MSH_PRI_78 : return 78; - case MSH_HEX_1 : return 1; - case MSH_HEX_8 : return 8; - case MSH_HEX_27 : return 27; - case MSH_HEX_64 : return 64; - case MSH_HEX_125 : return 125; - case MSH_HEX_216 : return 216; - case MSH_HEX_343 : return 343; - case MSH_HEX_512 : return 512; - case MSH_HEX_729 : return 729; - case MSH_HEX_1000: return 1000; - case MSH_HEX_20 : return 20; - case MSH_HEX_32 : return 32; - case MSH_HEX_44 : return 44; - case MSH_HEX_56 : return 56; - case MSH_HEX_68 : return 68; - case MSH_HEX_80 : return 80; - case MSH_HEX_92 : return 92; - case MSH_HEX_104 : return 104; - case MSH_PYR_1 : return 1; - case MSH_PYR_5 : return 5; - case MSH_PYR_14 : return 14; - case MSH_PYR_30 : return 30; - case MSH_PYR_55 : return 55; - case MSH_PYR_91 : return 91; - case MSH_PYR_140 : return 140; - case MSH_PYR_204 : return 204; - case MSH_PYR_285 : return 285; - case MSH_PYR_385 : return 385; - case MSH_PYR_13 : return 13; - case MSH_PYR_21 : return 21; - case MSH_PYR_29 : return 29; - case MSH_PYR_37 : return 37; - case MSH_PYR_45 : return 45; - case MSH_PYR_53 : return 53; - case MSH_PYR_61 : return 61; - case MSH_PYR_69 : return 69; - case MSH_TRIH_4 : return 4; - //case MSH_POLYH_ : return 0; - default : - Msg::Warning("Unknown element MSH type %d", mshtype); - return 0; + switch(mshtype) { + case MSH_PNT: return 1; + case MSH_LIN_1: return 1; + case MSH_LIN_2: return 2; + case MSH_LIN_3: return 3; + case MSH_LIN_4: return 4; + case MSH_LIN_5: return 5; + case MSH_LIN_6: return 6; + case MSH_LIN_7: return 7; + case MSH_LIN_8: return 8; + case MSH_LIN_9: return 9; + case MSH_LIN_10: return 10; + case MSH_LIN_11: return 11; + case MSH_TRI_1: return 1; + case MSH_TRI_3: return 3; + case MSH_TRI_6: return 6; + case MSH_TRI_10: return 10; + case MSH_TRI_15: return 15; + case MSH_TRI_21: return 21; + case MSH_TRI_28: return 28; + case MSH_TRI_36: return 36; + case MSH_TRI_45: return 45; + case MSH_TRI_55: return 55; + case MSH_TRI_66: return 66; + case MSH_TRI_9: return 9; + case MSH_TRI_12: return 12; + case MSH_TRI_15I: return 15; + case MSH_TRI_18: return 18; + case MSH_TRI_21I: return 21; + case MSH_TRI_24: return 24; + case MSH_TRI_27: return 27; + case MSH_TRI_30: + return 30; + // case MSH_TRI_MINI : return 0; + // case MSH_POLYG_ : return 0; + // case MSH_POLYG_B : return 0; + case MSH_TET_1: return 1; + case MSH_TET_4: return 4; + case MSH_TET_10: return 10; + case MSH_TET_20: return 20; + case MSH_TET_35: return 35; + case MSH_TET_56: return 56; + case MSH_TET_84: return 84; + case MSH_TET_120: return 120; + case MSH_TET_165: return 165; + case MSH_TET_220: return 220; + case MSH_TET_286: return 286; + case MSH_TET_16: return 16; + case MSH_TET_22: return 22; + case MSH_TET_28: return 28; + case MSH_TET_34: return 34; + case MSH_TET_40: return 40; + case MSH_TET_46: return 46; + case MSH_TET_52: return 52; + case MSH_TET_58: + return 58; + // case MSH_TET_MINI : return 0; + case MSH_QUA_1: return 1; + case MSH_QUA_4: return 4; + case MSH_QUA_9: return 9; + case MSH_QUA_16: return 16; + case MSH_QUA_25: return 25; + case MSH_QUA_36: return 36; + case MSH_QUA_49: return 49; + case MSH_QUA_64: return 64; + case MSH_QUA_81: return 81; + case MSH_QUA_100: return 100; + case MSH_QUA_121: return 121; + case MSH_QUA_8: return 8; + case MSH_QUA_12: return 12; + case MSH_QUA_16I: return 16; + case MSH_QUA_20: return 20; + case MSH_QUA_24: return 24; + case MSH_QUA_28: return 28; + case MSH_QUA_32: return 32; + case MSH_QUA_36I: return 36; + case MSH_QUA_40: return 40; + case MSH_PRI_1: return 1; + case MSH_PRI_6: return 6; + case MSH_PRI_18: return 18; + case MSH_PRI_40: return 40; + case MSH_PRI_75: return 75; + case MSH_PRI_126: return 126; + case MSH_PRI_196: return 196; + case MSH_PRI_288: return 288; + case MSH_PRI_405: return 405; + case MSH_PRI_550: return 550; + case MSH_PRI_15: return 15; + case MSH_PRI_24: return 24; + case MSH_PRI_33: return 33; + case MSH_PRI_42: return 42; + case MSH_PRI_51: return 51; + case MSH_PRI_60: return 60; + case MSH_PRI_69: return 69; + case MSH_PRI_78: return 78; + case MSH_HEX_1: return 1; + case MSH_HEX_8: return 8; + case MSH_HEX_27: return 27; + case MSH_HEX_64: return 64; + case MSH_HEX_125: return 125; + case MSH_HEX_216: return 216; + case MSH_HEX_343: return 343; + case MSH_HEX_512: return 512; + case MSH_HEX_729: return 729; + case MSH_HEX_1000: return 1000; + case MSH_HEX_20: return 20; + case MSH_HEX_32: return 32; + case MSH_HEX_44: return 44; + case MSH_HEX_56: return 56; + case MSH_HEX_68: return 68; + case MSH_HEX_80: return 80; + case MSH_HEX_92: return 92; + case MSH_HEX_104: return 104; + case MSH_PYR_1: return 1; + case MSH_PYR_5: return 5; + case MSH_PYR_14: return 14; + case MSH_PYR_30: return 30; + case MSH_PYR_55: return 55; + case MSH_PYR_91: return 91; + case MSH_PYR_140: return 140; + case MSH_PYR_204: return 204; + case MSH_PYR_285: return 285; + case MSH_PYR_385: return 385; + case MSH_PYR_13: return 13; + case MSH_PYR_21: return 21; + case MSH_PYR_29: return 29; + case MSH_PYR_37: return 37; + case MSH_PYR_45: return 45; + case MSH_PYR_53: return 53; + case MSH_PYR_61: return 61; + case MSH_PYR_69: return 69; + case MSH_TRIH_4: + return 4; + // case MSH_POLYH_ : return 0; + default: Msg::Warning("Unknown element MSH type %d", mshtype); return 0; } return 0; @@ -482,213 +600,272 @@ int ElementType::getNumVertices(int mshtype) // 1 is for element that is either Serendipity or not ! int ElementType::getSerendipity(int mshtype) { - switch (mshtype) { - case MSH_PNT : case MSH_LIN_1 : - case MSH_LIN_2 : case MSH_LIN_3 : - case MSH_LIN_4 : case MSH_LIN_5 : - case MSH_LIN_6 : case MSH_LIN_7 : - case MSH_LIN_8 : case MSH_LIN_9 : - case MSH_LIN_10 : case MSH_LIN_11 : - - case MSH_TRI_1 : case MSH_TRI_3 : - case MSH_TRI_6 : - - case MSH_QUA_1 : case MSH_QUA_4 : - - case MSH_TET_1 : case MSH_TET_4 : - case MSH_TET_10 : - - case MSH_PRI_1 : case MSH_PRI_6 : - - case MSH_HEX_1 : case MSH_HEX_8 : - - case MSH_PYR_1 : case MSH_PYR_5 : - - case MSH_POLYG_ : case MSH_POLYG_B : - case MSH_POLYH_ : + switch(mshtype) { + case MSH_PNT: + case MSH_LIN_1: + case MSH_LIN_2: + case MSH_LIN_3: + case MSH_LIN_4: + case MSH_LIN_5: + case MSH_LIN_6: + case MSH_LIN_7: + case MSH_LIN_8: + case MSH_LIN_9: + case MSH_LIN_10: + case MSH_LIN_11: + + case MSH_TRI_1: + case MSH_TRI_3: + case MSH_TRI_6: + + case MSH_QUA_1: + case MSH_QUA_4: + + case MSH_TET_1: + case MSH_TET_4: + case MSH_TET_10: + + case MSH_PRI_1: + case MSH_PRI_6: + + case MSH_HEX_1: + case MSH_HEX_8: + + case MSH_PYR_1: + case MSH_PYR_5: + + case MSH_POLYG_: + case MSH_POLYG_B: + case MSH_POLYH_: return 1; // Serendipity or not - - case MSH_TRI_10 : case MSH_TRI_15 : - case MSH_TRI_21 : case MSH_TRI_28 : - case MSH_TRI_36 : case MSH_TRI_45 : - case MSH_TRI_55 : case MSH_TRI_66 : - - case MSH_QUA_9 : case MSH_QUA_16 : - case MSH_QUA_25 : case MSH_QUA_36 : - case MSH_QUA_49 : case MSH_QUA_64 : - case MSH_QUA_81 : case MSH_QUA_100 : - case MSH_QUA_121 : - - case MSH_TET_20 : case MSH_TET_35 : - case MSH_TET_56 : case MSH_TET_84 : - case MSH_TET_120 : case MSH_TET_165 : - case MSH_TET_220 : case MSH_TET_286 : - - case MSH_PRI_18 : case MSH_PRI_40 : - case MSH_PRI_75 : case MSH_PRI_126 : - case MSH_PRI_196 : case MSH_PRI_288 : - case MSH_PRI_405 : case MSH_PRI_550 : - - case MSH_HEX_27 : case MSH_HEX_64 : - case MSH_HEX_125 : case MSH_HEX_216 : - case MSH_HEX_343 : case MSH_HEX_512 : - case MSH_HEX_729 : case MSH_HEX_1000: - - case MSH_PYR_14 : case MSH_PYR_30 : - case MSH_PYR_55 : case MSH_PYR_91 : - case MSH_PYR_140 : case MSH_PYR_204 : - case MSH_PYR_285 : case MSH_PYR_385 : - - case MSH_TRIH_4 : + case MSH_TRI_10: + case MSH_TRI_15: + case MSH_TRI_21: + case MSH_TRI_28: + case MSH_TRI_36: + case MSH_TRI_45: + case MSH_TRI_55: + case MSH_TRI_66: + + case MSH_QUA_9: + case MSH_QUA_16: + case MSH_QUA_25: + case MSH_QUA_36: + case MSH_QUA_49: + case MSH_QUA_64: + case MSH_QUA_81: + case MSH_QUA_100: + case MSH_QUA_121: + + case MSH_TET_20: + case MSH_TET_35: + case MSH_TET_56: + case MSH_TET_84: + case MSH_TET_120: + case MSH_TET_165: + case MSH_TET_220: + case MSH_TET_286: + + case MSH_PRI_18: + case MSH_PRI_40: + case MSH_PRI_75: + case MSH_PRI_126: + case MSH_PRI_196: + case MSH_PRI_288: + case MSH_PRI_405: + case MSH_PRI_550: + + case MSH_HEX_27: + case MSH_HEX_64: + case MSH_HEX_125: + case MSH_HEX_216: + case MSH_HEX_343: + case MSH_HEX_512: + case MSH_HEX_729: + case MSH_HEX_1000: + + case MSH_PYR_14: + case MSH_PYR_30: + case MSH_PYR_55: + case MSH_PYR_91: + case MSH_PYR_140: + case MSH_PYR_204: + case MSH_PYR_285: + case MSH_PYR_385: + + case MSH_TRIH_4: return 0; // Not Serendipity - - case MSH_TRI_9 : case MSH_TRI_12 : - case MSH_TRI_15I : case MSH_TRI_18 : - case MSH_TRI_21I : case MSH_TRI_24 : - case MSH_TRI_27 : case MSH_TRI_30 : - - case MSH_QUA_8 : case MSH_QUA_12 : - case MSH_QUA_16I : case MSH_QUA_20 : - case MSH_QUA_24 : case MSH_QUA_28 : - case MSH_QUA_32 : case MSH_QUA_36I : - case MSH_QUA_40 : - - case MSH_TET_22 : case MSH_TET_28 : - case MSH_TET_34 : case MSH_TET_40 : - case MSH_TET_46 : case MSH_TET_52 : - case MSH_TET_58 : case MSH_TET_16 : - - case MSH_PRI_15 : case MSH_PRI_24 : - case MSH_PRI_33 : case MSH_PRI_42 : - case MSH_PRI_51 : case MSH_PRI_60 : - case MSH_PRI_69 : case MSH_PRI_78 : - - case MSH_HEX_20 : case MSH_HEX_32 : - case MSH_HEX_44 : case MSH_HEX_56 : - case MSH_HEX_68 : case MSH_HEX_80 : - case MSH_HEX_92 : case MSH_HEX_104 : - - case MSH_PYR_13 : case MSH_PYR_21 : - case MSH_PYR_29 : case MSH_PYR_37 : - case MSH_PYR_45 : case MSH_PYR_53 : - case MSH_PYR_61 : case MSH_PYR_69 : + case MSH_TRI_9: + case MSH_TRI_12: + case MSH_TRI_15I: + case MSH_TRI_18: + case MSH_TRI_21I: + case MSH_TRI_24: + case MSH_TRI_27: + case MSH_TRI_30: + + case MSH_QUA_8: + case MSH_QUA_12: + case MSH_QUA_16I: + case MSH_QUA_20: + case MSH_QUA_24: + case MSH_QUA_28: + case MSH_QUA_32: + case MSH_QUA_36I: + case MSH_QUA_40: + + case MSH_TET_22: + case MSH_TET_28: + case MSH_TET_34: + case MSH_TET_40: + case MSH_TET_46: + case MSH_TET_52: + case MSH_TET_58: + case MSH_TET_16: + + case MSH_PRI_15: + case MSH_PRI_24: + case MSH_PRI_33: + case MSH_PRI_42: + case MSH_PRI_51: + case MSH_PRI_60: + case MSH_PRI_69: + case MSH_PRI_78: + + case MSH_HEX_20: + case MSH_HEX_32: + case MSH_HEX_44: + case MSH_HEX_56: + case MSH_HEX_68: + case MSH_HEX_80: + case MSH_HEX_92: + case MSH_HEX_104: + + case MSH_PYR_13: + case MSH_PYR_21: + case MSH_PYR_29: + case MSH_PYR_37: + case MSH_PYR_45: + case MSH_PYR_53: + case MSH_PYR_61: + case MSH_PYR_69: return 2; // Only Serendipity - default : - Msg::Warning("Unknown element MSH type %d, assuming not serendipity.", mshtype); + default: + Msg::Warning("Unknown element MSH type %d, assuming not serendipity.", + mshtype); return 0; } } int ElementType::getType(int parentType, int order, bool serendip) { - switch (parentType) { - case TYPE_PNT : - return MSH_PNT; - case TYPE_LIN : + switch(parentType) { + case TYPE_PNT: return MSH_PNT; + case TYPE_LIN: switch(order) { - case 0 : return MSH_LIN_1; - case 1 : return MSH_LIN_2; - case 2 : return MSH_LIN_3; - case 3 : return MSH_LIN_4; - case 4 : return MSH_LIN_5; - case 5 : return MSH_LIN_6; - case 6 : return MSH_LIN_7; - case 7 : return MSH_LIN_8; - case 8 : return MSH_LIN_9; - case 9 : return MSH_LIN_10; + case 0: return MSH_LIN_1; + case 1: return MSH_LIN_2; + case 2: return MSH_LIN_3; + case 3: return MSH_LIN_4; + case 4: return MSH_LIN_5; + case 5: return MSH_LIN_6; + case 6: return MSH_LIN_7; + case 7: return MSH_LIN_8; + case 8: return MSH_LIN_9; + case 9: return MSH_LIN_10; case 10: return MSH_LIN_11; - default : Msg::Error("Line order %i unknown", order); return 0; + default: Msg::Error("Line order %i unknown", order); return 0; } break; - case TYPE_TRI : + case TYPE_TRI: switch(order) { - case 0 : return MSH_TRI_1; - case 1 : return MSH_TRI_3; - case 2 : return MSH_TRI_6; - case 3 : return serendip ? MSH_TRI_9 : MSH_TRI_10; - case 4 : return serendip ? MSH_TRI_12 : MSH_TRI_15; - case 5 : return serendip ? MSH_TRI_15I: MSH_TRI_21; - case 6 : return serendip ? MSH_TRI_18 : MSH_TRI_28; - case 7 : return serendip ? MSH_TRI_21I: MSH_TRI_36; - case 8 : return serendip ? MSH_TRI_24 : MSH_TRI_45; - case 9 : return serendip ? MSH_TRI_27 : MSH_TRI_55; + case 0: return MSH_TRI_1; + case 1: return MSH_TRI_3; + case 2: return MSH_TRI_6; + case 3: return serendip ? MSH_TRI_9 : MSH_TRI_10; + case 4: return serendip ? MSH_TRI_12 : MSH_TRI_15; + case 5: return serendip ? MSH_TRI_15I : MSH_TRI_21; + case 6: return serendip ? MSH_TRI_18 : MSH_TRI_28; + case 7: return serendip ? MSH_TRI_21I : MSH_TRI_36; + case 8: return serendip ? MSH_TRI_24 : MSH_TRI_45; + case 9: return serendip ? MSH_TRI_27 : MSH_TRI_55; case 10: return serendip ? MSH_TRI_30 : MSH_TRI_66; - default : Msg::Error("Triangle order %i unknown", order); return 0; + default: Msg::Error("Triangle order %i unknown", order); return 0; } break; - case TYPE_QUA : + case TYPE_QUA: switch(order) { - case 0 : return MSH_QUA_1; - case 1 : return MSH_QUA_4; - case 2 : return serendip ? MSH_QUA_8 : MSH_QUA_9; - case 3 : return serendip ? MSH_QUA_12 : MSH_QUA_16; - case 4 : return serendip ? MSH_QUA_16I: MSH_QUA_25; - case 5 : return serendip ? MSH_QUA_20 : MSH_QUA_36; - case 6 : return serendip ? MSH_QUA_24 : MSH_QUA_49; - case 7 : return serendip ? MSH_QUA_28 : MSH_QUA_64; - case 8 : return serendip ? MSH_QUA_32 : MSH_QUA_81; - case 9 : return serendip ? MSH_QUA_36I: MSH_QUA_100; + case 0: return MSH_QUA_1; + case 1: return MSH_QUA_4; + case 2: return serendip ? MSH_QUA_8 : MSH_QUA_9; + case 3: return serendip ? MSH_QUA_12 : MSH_QUA_16; + case 4: return serendip ? MSH_QUA_16I : MSH_QUA_25; + case 5: return serendip ? MSH_QUA_20 : MSH_QUA_36; + case 6: return serendip ? MSH_QUA_24 : MSH_QUA_49; + case 7: return serendip ? MSH_QUA_28 : MSH_QUA_64; + case 8: return serendip ? MSH_QUA_32 : MSH_QUA_81; + case 9: return serendip ? MSH_QUA_36I : MSH_QUA_100; case 10: return serendip ? MSH_QUA_40 : MSH_QUA_121; - default : Msg::Error("Quad order %i unknown", order); return 0; + default: Msg::Error("Quad order %i unknown", order); return 0; } break; - case TYPE_TET : + case TYPE_TET: switch(order) { - case 0 : return MSH_TET_1; - case 1 : return MSH_TET_4; - case 2 : return MSH_TET_10; - case 3 : return serendip ? MSH_TET_16 : MSH_TET_20; - case 4 : return serendip ? MSH_TET_22 : MSH_TET_35; - case 5 : return serendip ? MSH_TET_28 : MSH_TET_56; - case 6 : return serendip ? MSH_TET_34 : MSH_TET_84; - case 7 : return serendip ? MSH_TET_40: MSH_TET_120; - case 8 : return serendip ? MSH_TET_46: MSH_TET_165; - case 9 : return serendip ? MSH_TET_52: MSH_TET_220; - case 10: return serendip ? MSH_TET_58: MSH_TET_286; - default : Msg::Error("Tetrahedron order %i unknown", order); return 0; + case 0: return MSH_TET_1; + case 1: return MSH_TET_4; + case 2: return MSH_TET_10; + case 3: return serendip ? MSH_TET_16 : MSH_TET_20; + case 4: return serendip ? MSH_TET_22 : MSH_TET_35; + case 5: return serendip ? MSH_TET_28 : MSH_TET_56; + case 6: return serendip ? MSH_TET_34 : MSH_TET_84; + case 7: return serendip ? MSH_TET_40 : MSH_TET_120; + case 8: return serendip ? MSH_TET_46 : MSH_TET_165; + case 9: return serendip ? MSH_TET_52 : MSH_TET_220; + case 10: return serendip ? MSH_TET_58 : MSH_TET_286; + default: Msg::Error("Tetrahedron order %i unknown", order); return 0; } break; - case TYPE_HEX : + case TYPE_HEX: switch(order) { - case 0 : return MSH_HEX_1; - case 1 : return MSH_HEX_8; - case 2 : return serendip ? MSH_HEX_20 : MSH_HEX_27; - case 3 : return serendip ? MSH_HEX_32 : MSH_HEX_64; - case 4 : return serendip ? MSH_HEX_44 : MSH_HEX_125; - case 5 : return serendip ? MSH_HEX_56: MSH_HEX_216; - case 6 : return serendip ? MSH_HEX_68: MSH_HEX_343; - case 7 : return serendip ? MSH_HEX_80: MSH_HEX_512; - case 8 : return serendip ? MSH_HEX_92: MSH_HEX_729; - case 9 : return serendip ? MSH_HEX_104: MSH_HEX_1000; - default : Msg::Error("hexahedron order %i unknown", order); return 0; + case 0: return MSH_HEX_1; + case 1: return MSH_HEX_8; + case 2: return serendip ? MSH_HEX_20 : MSH_HEX_27; + case 3: return serendip ? MSH_HEX_32 : MSH_HEX_64; + case 4: return serendip ? MSH_HEX_44 : MSH_HEX_125; + case 5: return serendip ? MSH_HEX_56 : MSH_HEX_216; + case 6: return serendip ? MSH_HEX_68 : MSH_HEX_343; + case 7: return serendip ? MSH_HEX_80 : MSH_HEX_512; + case 8: return serendip ? MSH_HEX_92 : MSH_HEX_729; + case 9: return serendip ? MSH_HEX_104 : MSH_HEX_1000; + default: Msg::Error("hexahedron order %i unknown", order); return 0; } break; - case TYPE_PRI : + case TYPE_PRI: switch(order) { - case 0 : return MSH_PRI_1; - case 1 : return MSH_PRI_6; - case 2 : return serendip ? MSH_PRI_15 : MSH_PRI_18; - case 3 : return serendip ? MSH_PRI_24 : MSH_PRI_40; - case 4 : return serendip ? MSH_PRI_33 : MSH_PRI_75; - case 5 : return serendip ? MSH_PRI_42 : MSH_PRI_126; - case 6 : return serendip ? MSH_PRI_51 : MSH_PRI_196; - case 7 : return serendip ? MSH_PRI_60 : MSH_PRI_288; - case 8 : return serendip ? MSH_PRI_69 : MSH_PRI_405; - case 9 : return serendip ? MSH_PRI_78 : MSH_PRI_550; - default : Msg::Error("Prism order %i unknown", order); return 0; + case 0: return MSH_PRI_1; + case 1: return MSH_PRI_6; + case 2: return serendip ? MSH_PRI_15 : MSH_PRI_18; + case 3: return serendip ? MSH_PRI_24 : MSH_PRI_40; + case 4: return serendip ? MSH_PRI_33 : MSH_PRI_75; + case 5: return serendip ? MSH_PRI_42 : MSH_PRI_126; + case 6: return serendip ? MSH_PRI_51 : MSH_PRI_196; + case 7: return serendip ? MSH_PRI_60 : MSH_PRI_288; + case 8: return serendip ? MSH_PRI_69 : MSH_PRI_405; + case 9: return serendip ? MSH_PRI_78 : MSH_PRI_550; + default: Msg::Error("Prism order %i unknown", order); return 0; } break; - case TYPE_PYR : + case TYPE_PYR: switch(order) { - case 0 : return MSH_PYR_1; - case 1 : return MSH_PYR_5; - case 2 : return serendip ? MSH_PYR_13 : MSH_PYR_14; + case 0: return MSH_PYR_1; + case 1: return MSH_PYR_5; + case 2: return serendip ? MSH_PYR_13 : MSH_PYR_14; case 3: return serendip ? MSH_PYR_21 : MSH_PYR_30; case 4: return serendip ? MSH_PYR_29 : MSH_PYR_55; case 5: return serendip ? MSH_PYR_37 : MSH_PYR_91; @@ -696,13 +873,13 @@ int ElementType::getType(int parentType, int order, bool serendip) case 7: return serendip ? MSH_PYR_53 : MSH_PYR_204; case 8: return serendip ? MSH_PYR_61 : MSH_PYR_285; case 9: return serendip ? MSH_PYR_69 : MSH_PYR_385; - default : Msg::Error("Pyramid order %i unknown", order); return 0; + default: Msg::Error("Pyramid order %i unknown", order); return 0; } break; - case TYPE_TRIH : - return MSH_TRIH_4; - default : - Msg::Warning("Unknown element parent type %i, returning 0", parentType); return 0; + case TYPE_TRIH: return MSH_TRIH_4; + default: + Msg::Warning("Unknown element parent type %i, returning 0", parentType); + return 0; } } @@ -711,49 +888,22 @@ int ElementType::getPrimaryType(int mshtype) return getType(getParentType(mshtype), 1); } -std::string ElementType::nameOfParentType(int parentType) { - - switch (parentType) { - - case TYPE_PNT: - return std::string("point"); - break; - case TYPE_LIN: - return std::string("line"); - break; - case TYPE_TRI: - return std::string("triangle"); - break; - case TYPE_QUA: - return std::string("quadrangle"); - break; - case TYPE_TET: - return std::string("tetrahedron"); - break; - case TYPE_PYR: - return std::string("pyramid"); - break; - case TYPE_PRI: - return std::string("prism"); - break; - case TYPE_HEX: - return std::string("hexahedron"); - break; - case TYPE_POLYG: - return std::string("polygon"); - break; - case TYPE_POLYH: - return std::string("polyhedron"); - break; - case TYPE_XFEM: - return std::string("xfem"); - break; - case TYPE_MINI: - return std::string("mini"); - break; - case TYPE_TRIH: - return std::string("trihedron"); - break; +std::string ElementType::nameOfParentType(int parentType) +{ + switch(parentType) { + case TYPE_PNT: return std::string("point"); break; + case TYPE_LIN: return std::string("line"); break; + case TYPE_TRI: return std::string("triangle"); break; + case TYPE_QUA: return std::string("quadrangle"); break; + case TYPE_TET: return std::string("tetrahedron"); break; + case TYPE_PYR: return std::string("pyramid"); break; + case TYPE_PRI: return std::string("prism"); break; + case TYPE_HEX: return std::string("hexahedron"); break; + case TYPE_POLYG: return std::string("polygon"); break; + case TYPE_POLYH: return std::string("polyhedron"); break; + case TYPE_XFEM: return std::string("xfem"); break; + case TYPE_MINI: return std::string("mini"); break; + case TYPE_TRIH: return std::string("trihedron"); break; } return std::string("undefined"); diff --git a/Numeric/ElementType.h b/Numeric/ElementType.h index 0476c44d5e61a0d6ef4a8a6abf30590d4b6db355..2fa8a7cde7b4c8fef39757dc6fe544c266641f0d 100644 --- a/Numeric/ElementType.h +++ b/Numeric/ElementType.h @@ -8,8 +8,7 @@ #include <string> -namespace ElementType -{ +namespace ElementType { // Give parent type, order & dimension corresponding to any element MSH type. int getParentType(int type); int getOrder(int type); @@ -29,6 +28,6 @@ namespace ElementType // Give first order element tag int getPrimaryType(int type); std::string nameOfParentType(int type); -} +} // namespace ElementType #endif diff --git a/Numeric/FuncSpaceData.cpp b/Numeric/FuncSpaceData.cpp index 934ff4a7115659457cf9b2b3244ff99a33601622..5a4d668cf3c1e019c43b4e98531ab5a221ae17e6 100644 --- a/Numeric/FuncSpaceData.cpp +++ b/Numeric/FuncSpaceData.cpp @@ -6,83 +6,91 @@ #include "FuncSpaceData.h" #include "MElement.h" -FuncSpaceData::FuncSpaceData(const FuncSpaceData &fsd, - int order, - const bool *serendip) : - _tag(fsd._tag), _spaceOrder(order), - _serendipity(serendip ? *serendip : fsd._serendipity), - _nij(0), _nk(_spaceOrder), _pyramidalSpace(fsd._pyramidalSpace) -{} +FuncSpaceData::FuncSpaceData(const FuncSpaceData &fsd, int order, + const bool *serendip) + : _tag(fsd._tag), _spaceOrder(order), + _serendipity(serendip ? *serendip : fsd._serendipity), _nij(0), + _nk(_spaceOrder), _pyramidalSpace(fsd._pyramidalSpace) +{ +} -FuncSpaceData::FuncSpaceData(const FuncSpaceData &fsd, - int nij, int nk, - const bool *serendip) : - _tag(fsd._tag), _spaceOrder(fsd._pyramidalSpace ? nij+nk : std::max(nij, nk)), - _serendipity(serendip ? *serendip : fsd._serendipity), - _nij(nij), _nk(nk), _pyramidalSpace(fsd._pyramidalSpace) -{} +FuncSpaceData::FuncSpaceData(const FuncSpaceData &fsd, int nij, int nk, + const bool *serendip) + : _tag(fsd._tag), + _spaceOrder(fsd._pyramidalSpace ? nij + nk : std::max(nij, nk)), + _serendipity(serendip ? *serendip : fsd._serendipity), _nij(nij), _nk(nk), + _pyramidalSpace(fsd._pyramidalSpace) +{ +} -FuncSpaceData::FuncSpaceData(const MElement *el, const bool *serendip) : - _tag(el->getTypeForMSH()), _spaceOrder(el->getPolynomialOrder()), - _serendipity(serendip ? *serendip : el->getIsOnlySerendipity()), - _nij(0), _nk(_spaceOrder), _pyramidalSpace(el->getType() == TYPE_PYR) -{} +FuncSpaceData::FuncSpaceData(const MElement *el, const bool *serendip) + : _tag(el->getTypeForMSH()), _spaceOrder(el->getPolynomialOrder()), + _serendipity(serendip ? *serendip : el->getIsOnlySerendipity()), _nij(0), + _nk(_spaceOrder), _pyramidalSpace(el->getType() == TYPE_PYR) +{ +} -FuncSpaceData::FuncSpaceData(const MElement *el, int order, const bool *serendip) : - _tag(el->getTypeForMSH()), _spaceOrder(order), - _serendipity(serendip ? *serendip : el->getIsOnlySerendipity()), - _nij(0), _nk(_spaceOrder), _pyramidalSpace(el->getType() == TYPE_PYR) -{} +FuncSpaceData::FuncSpaceData(const MElement *el, int order, + const bool *serendip) + : _tag(el->getTypeForMSH()), _spaceOrder(order), + _serendipity(serendip ? *serendip : el->getIsOnlySerendipity()), _nij(0), + _nk(_spaceOrder), _pyramidalSpace(el->getType() == TYPE_PYR) +{ +} FuncSpaceData::FuncSpaceData(const MElement *el, bool pyr, int nij, int nk, - const bool *serendip) : - _tag(el->getTypeForMSH()), _spaceOrder(pyr ? nij+nk : std::max(nij, nk)), - _serendipity(serendip ? *serendip : el->getIsOnlySerendipity()), - _nij(nij), _nk(nk), _pyramidalSpace(pyr) + const bool *serendip) + : _tag(el->getTypeForMSH()), _spaceOrder(pyr ? nij + nk : std::max(nij, nk)), + _serendipity(serendip ? *serendip : el->getIsOnlySerendipity()), _nij(nij), + _nk(nk), _pyramidalSpace(pyr) { - if (el->getType() != TYPE_PYR) + if(el->getType() != TYPE_PYR) Msg::Error("Creation of pyramidal space data for a non-pyramid element !"); } -FuncSpaceData::FuncSpaceData(int tag, const bool *serendip) : - _tag(tag), _spaceOrder(ElementType::getOrder(tag)), - _serendipity(serendip ? *serendip : ElementType::getSerendipity(_tag) > 1), - _nij(0), _nk(_spaceOrder), - _pyramidalSpace(ElementType::getParentType(tag) == TYPE_PYR) -{} +FuncSpaceData::FuncSpaceData(int tag, const bool *serendip) + : _tag(tag), _spaceOrder(ElementType::getOrder(tag)), + _serendipity(serendip ? *serendip : ElementType::getSerendipity(_tag) > 1), + _nij(0), _nk(_spaceOrder), + _pyramidalSpace(ElementType::getParentType(tag) == TYPE_PYR) +{ +} FuncSpaceData::FuncSpaceData(bool isTag, int tagOrType, int order, - const bool *serendip, bool elemIsSerendip) : - _tag(isTag ? tagOrType : ElementType::getType(tagOrType, order, elemIsSerendip)), - _spaceOrder(order), - _serendipity(serendip ? *serendip : ElementType::getSerendipity(_tag) > 1), - _nij(0), _nk(_spaceOrder), - _pyramidalSpace(isTag ? - ElementType::getParentType(tagOrType) == TYPE_PYR : - tagOrType == TYPE_PYR) -{} + const bool *serendip, bool elemIsSerendip) + : _tag(isTag ? tagOrType : + ElementType::getType(tagOrType, order, elemIsSerendip)), + _spaceOrder(order), + _serendipity(serendip ? *serendip : ElementType::getSerendipity(_tag) > 1), + _nij(0), _nk(_spaceOrder), + _pyramidalSpace(isTag ? ElementType::getParentType(tagOrType) == TYPE_PYR : + tagOrType == TYPE_PYR) +{ +} FuncSpaceData::FuncSpaceData(bool isTag, int tagOrType, bool pyr, int nij, - int nk, const bool *serendip, bool elemIsSerendip) : - _tag(isTag ? tagOrType : - ElementType::getType(tagOrType, pyr ? nij+nk : std::max(nij, nk), elemIsSerendip)), - _spaceOrder(pyr ? nij+nk : std::max(nij, nk)), - _serendipity(serendip ? *serendip : ElementType::getSerendipity(_tag) > 1), - _nij(nij), _nk(nk), _pyramidalSpace(pyr) + int nk, const bool *serendip, bool elemIsSerendip) + : _tag(isTag ? + tagOrType : + ElementType::getType(tagOrType, pyr ? nij + nk : std::max(nij, nk), + elemIsSerendip)), + _spaceOrder(pyr ? nij + nk : std::max(nij, nk)), + _serendipity(serendip ? *serendip : ElementType::getSerendipity(_tag) > 1), + _nij(nij), _nk(nk), _pyramidalSpace(pyr) { - if (ElementType::getParentType(_tag) != TYPE_PYR) + if(ElementType::getParentType(_tag) != TYPE_PYR) Msg::Error("Creation of pyramidal space data for a non-pyramid element!"); } void FuncSpaceData::getOrderForBezier(int order[3], int exponentZ) const { - if (_pyramidalSpace && exponentZ < 0) { + if(_pyramidalSpace && exponentZ < 0) { Msg::Error("getOrderForBezier needs third exponent for pyramidal space!"); order[0] = order[1] = order[2] = -1; return; } - if (elementType() == TYPE_PYR) { - if (_pyramidalSpace) { + if(elementType() == TYPE_PYR) { + if(_pyramidalSpace) { order[0] = order[1] = _nij + exponentZ; order[2] = _nk; } @@ -100,21 +108,22 @@ FuncSpaceData FuncSpaceData::getForPrimaryElement() const int type = elementType(); int primTag = ElementType::getType(type, 1, elementIsOnlySerendipity()); - if (primTag == _tag) return *this; + if(primTag == _tag) return *this; - if (type == TYPE_PYR) - return FuncSpaceData(true, primTag, _pyramidalSpace, _nij, _nk, &_serendipity); + if(type == TYPE_PYR) + return FuncSpaceData(true, primTag, _pyramidalSpace, _nij, _nk, + &_serendipity); else return FuncSpaceData(true, primTag, _spaceOrder, &_serendipity); } FuncSpaceData FuncSpaceData::getForNonSerendipitySpace() const { - if (!_serendipity) return *this; + if(!_serendipity) return *this; int type = elementType(); bool serendip = false; - if (type == TYPE_PYR) + if(type == TYPE_PYR) return FuncSpaceData(true, _tag, _pyramidalSpace, _nij, _nk, &serendip); else return FuncSpaceData(true, _tag, _spaceOrder, &serendip); diff --git a/Numeric/FuncSpaceData.h b/Numeric/FuncSpaceData.h index 6573b965677129318e8ae3afa588979774319350..75e753831fb3ad400f9bd0a2630d3567c3809797 100644 --- a/Numeric/FuncSpaceData.h +++ b/Numeric/FuncSpaceData.h @@ -12,18 +12,19 @@ #include <cstddef> class MElement; -class FuncSpaceData -{ +class FuncSpaceData { // Store data that allows to easily know how to construct gradient, jacobian, // bezier and metric bases. private: int _tag, _spaceOrder; bool _serendipity; - // '_tag' determine the type and the order of the element and if it is serendipity. + // '_tag' determine the type and the order of the element and if it is + // serendipity. // // For non-pyramidal elements, the space is the space of the same type element - // at order '_spaceOrder'. It is a serendipity space if '_serendipity' is true. + // at order '_spaceOrder'. It is a serendipity space if '_serendipity' is + // true. // // Pyramids int _nij, _nk; @@ -31,30 +32,30 @@ private: // For pyramids, '_spaceOrder' is not used. // There are two possible spaces in function of '_pyramidalSpace'. // if '_pyramidalSpace' == true, - // the space is {X^i Y^j Z^k | i,j <= k+'_nij', k <= '_nk'}, (pyramid-like space) + // the space is {X^i Y^j Z^k | i,j <= k+'_nij', k <= '_nk'}, (pyramid-like + // space) // otherwise, // the space is {X^i Y^j Z^k | i,j <= '_nij', k <= '_nk'}, (hex-like space) // where X = xi/(1-zeta), Y = eta/(1-zeta) and Z = (1-zeta). public: - FuncSpaceData() : _tag(-1), _spaceOrder(-1), _serendipity(false), _nij(-1), _nk(-1), - _pyramidalSpace(false) {} + _pyramidalSpace(false) + { + } // Constructors for the function space of a different order - FuncSpaceData(const FuncSpaceData &fsd, - int order, + FuncSpaceData(const FuncSpaceData &fsd, int order, const bool *serendip = NULL); - FuncSpaceData(const FuncSpaceData &fsd, - int nij, int nk, + FuncSpaceData(const FuncSpaceData &fsd, int nij, int nk, const bool *serendip = NULL); // Constructors using MElement* FuncSpaceData(const MElement *el, const bool *serendip = NULL); FuncSpaceData(const MElement *el, int order, const bool *serendip = NULL); FuncSpaceData(const MElement *el, bool pyr, int nij, int nk, - const bool *serendip = NULL); + const bool *serendip = NULL); // Constructor using element tag FuncSpaceData(int tag, const bool *serendip = NULL); @@ -77,10 +78,13 @@ public: int elementType() const { return ElementType::getParentType(_tag); } int elementOrder() const { return ElementType::getOrder(_tag); } int dimension() const { return ElementType::getDimension(_tag); } - int spaceOrder() const { return _spaceOrder;} + int spaceOrder() const { return _spaceOrder; } int nij() const { return _nij; } int nk() const { return _nk; } - bool elementIsOnlySerendipity() const { return ElementType::getSerendipity(_tag) > 1; } + bool elementIsOnlySerendipity() const + { + return ElementType::getSerendipity(_tag) > 1; + } bool spaceIsSerendipity() const { return _serendipity; } bool isPyramidalSpace() const { return _pyramidalSpace; } @@ -91,29 +95,32 @@ public: FuncSpaceData getForNonSerendipitySpace() const; // - inline bool operator<(const FuncSpaceData &other) const { - if (_tag == other._tag) { - if (_spaceOrder == other._spaceOrder) { - if (_nij == other._nij) { - if (_nk == other._nk) { + inline bool operator<(const FuncSpaceData &other) const + { + if(_tag == other._tag) { + if(_spaceOrder == other._spaceOrder) { + if(_nij == other._nij) { + if(_nk == other._nk) { return _pyramidalSpace == true ? false : other._pyramidalSpace; } - else return _nk < other._nk; + else + return _nk < other._nk; } - else return _nij < other._nij; + else + return _nij < other._nij; } - else return _spaceOrder < other._spaceOrder; + else + return _spaceOrder < other._spaceOrder; } - else return _tag < other._tag; + else + return _tag < other._tag; } - inline bool operator==(const FuncSpaceData &other) const { + inline bool operator==(const FuncSpaceData &other) const + { return _tag == other._tag && _spaceOrder == other._spaceOrder && _nij == other._nij && _nk == other._nk && _pyramidalSpace == other._pyramidalSpace; } }; - - - #endif diff --git a/Numeric/GaussIntegration.cpp b/Numeric/GaussIntegration.cpp index 26878e154b4633338ca360342c431ea86f753ff4..4ba53e1e6e41ead3700c5aa62d4f021c0c19c529 100644 --- a/Numeric/GaussIntegration.cpp +++ b/Numeric/GaussIntegration.cpp @@ -9,9 +9,9 @@ static void pts2fullMatrix(int npts, IntPt *pts, fullMatrix<double> &pMatrix, fullVector<double> &wMatrix) { - pMatrix.resize(npts,3); - wMatrix.resize(npts,1); - for (int i = 0; i < npts; i++) { + pMatrix.resize(npts, 3); + wMatrix.resize(npts, 1); + for(int i = 0; i < npts; i++) { pMatrix(i, 0) = pts[i].pt[0]; pMatrix(i, 1) = pts[i].pt[1]; pMatrix(i, 2) = pts[i].pt[2]; @@ -22,61 +22,75 @@ static void pts2fullMatrix(int npts, IntPt *pts, fullMatrix<double> &pMatrix, void gaussIntegration::getTriangle(int order, fullMatrix<double> &pts, fullVector<double> &weights) { - pts2fullMatrix(getNGQTPts(order),getGQTPts(order),pts,weights); + pts2fullMatrix(getNGQTPts(order), getGQTPts(order), pts, weights); } void gaussIntegration::getLine(int order, fullMatrix<double> &pts, fullVector<double> &weights) { - pts2fullMatrix(getNGQLPts(order),getGQLPts(order),pts,weights); + pts2fullMatrix(getNGQLPts(order), getGQLPts(order), pts, weights); } void gaussIntegration::getQuad(int order, fullMatrix<double> &pts, fullVector<double> &weights) { - pts2fullMatrix(getNGQQPts(order),getGQQPts(order),pts,weights); + pts2fullMatrix(getNGQQPts(order), getGQQPts(order), pts, weights); } void gaussIntegration::getTetrahedron(int order, fullMatrix<double> &pts, fullVector<double> &weights) { - pts2fullMatrix(getNGQTetPts(order),getGQTetPts(order),pts,weights); + pts2fullMatrix(getNGQTetPts(order), getGQTetPts(order), pts, weights); } void gaussIntegration::getHexahedron(int order, fullMatrix<double> &pts, fullVector<double> &weights) { - pts2fullMatrix(getNGQHPts(order),getGQHPts(order),pts,weights); + pts2fullMatrix(getNGQHPts(order), getGQHPts(order), pts, weights); } void gaussIntegration::getPrism(int order, fullMatrix<double> &pts, fullVector<double> &weights) { - pts2fullMatrix(getNGQPriPts(order),getGQPriPts(order),pts,weights); + pts2fullMatrix(getNGQPriPts(order), getGQPriPts(order), pts, weights); } void gaussIntegration::getPyramid(int order, fullMatrix<double> &pts, - fullVector<double> &weights) + fullVector<double> &weights) { - pts2fullMatrix(getNGQPyrPts(order),getGQPyrPts(order),pts,weights); + pts2fullMatrix(getNGQPyrPts(order), getGQPyrPts(order), pts, weights); } void gaussIntegration::get(int elementType, int order, fullMatrix<double> &pts, fullVector<double> &weights) { - switch (elementType) { - case TYPE_TRI : pts2fullMatrix(getNGQTPts(order), getGQTPts(order), pts, weights); break; - case TYPE_LIN : pts2fullMatrix(getNGQLPts(order), getGQLPts(order), pts, weights); break; - case TYPE_QUA : pts2fullMatrix(getNGQQPts(order), getGQQPts(order), pts, weights); break; - case TYPE_TET : pts2fullMatrix(getNGQTetPts(order), getGQTetPts(order), pts, weights); break; - case TYPE_HEX : pts2fullMatrix(getNGQHPts(order), getGQHPts(order), pts, weights); break; - case TYPE_PRI : pts2fullMatrix(getNGQPriPts(order), getGQPriPts(order), pts, weights); break; - case TYPE_PYR : pts2fullMatrix(getNGQPyrPts(order), getGQPyrPts(order), pts, weights); break; - case TYPE_PNT : - weights.resize(1,1); + switch(elementType) { + case TYPE_TRI: + pts2fullMatrix(getNGQTPts(order), getGQTPts(order), pts, weights); + break; + case TYPE_LIN: + pts2fullMatrix(getNGQLPts(order), getGQLPts(order), pts, weights); + break; + case TYPE_QUA: + pts2fullMatrix(getNGQQPts(order), getGQQPts(order), pts, weights); + break; + case TYPE_TET: + pts2fullMatrix(getNGQTetPts(order), getGQTetPts(order), pts, weights); + break; + case TYPE_HEX: + pts2fullMatrix(getNGQHPts(order), getGQHPts(order), pts, weights); + break; + case TYPE_PRI: + pts2fullMatrix(getNGQPriPts(order), getGQPriPts(order), pts, weights); + break; + case TYPE_PYR: + pts2fullMatrix(getNGQPyrPts(order), getGQPyrPts(order), pts, weights); + break; + case TYPE_PNT: + weights.resize(1, 1); weights(0) = 1.; - pts.resize(1,3); + pts.resize(1, 3); break; - default : Msg::Error("No integration rules defined for type %i", elementType); + default: Msg::Error("No integration rules defined for type %i", elementType); } } diff --git a/Numeric/GaussIntegration.h b/Numeric/GaussIntegration.h index ea120c40910ef2cea5e8b2a172818207b6d82664..42786852ee08e767e207c58c9b69dedef107a5f2 100644 --- a/Numeric/GaussIntegration.h +++ b/Numeric/GaussIntegration.h @@ -8,19 +8,19 @@ #include "fullMatrix.h" -struct IntPt{ +struct IntPt { double pt[3]; double weight; }; int GaussLegendreTri(int n1, int n2, IntPt *pts); -int GaussLegendreTet(int n1, int n2, int n3, IntPt *pts); +int GaussLegendreTet(int n1, int n2, int n3, IntPt *pts); -int getNGQLPts (int order); -IntPt *getGQLPts (int order); +int getNGQLPts(int order); +IntPt *getGQLPts(int order); int getNGQTPts(int order); -IntPt *getGQTPts (int order); +IntPt *getGQTPts(int order); int getNGQQPts(int order); IntPt *getGQQPts(int order); @@ -38,7 +38,7 @@ int getNGQHPts(int order); IntPt *getGQHPts(int order); class gaussIntegration { - public: +public: static void get(int elementType, int order, fullMatrix<double> &pts, fullVector<double> &weights); static void getTriangle(int order, fullMatrix<double> &pts, @@ -49,12 +49,12 @@ class gaussIntegration { fullVector<double> &weights); static void getTetrahedron(int order, fullMatrix<double> &pts, fullVector<double> &weights); - static void getHexahedron(int order, fullMatrix<double> &pts, + static void getHexahedron(int order, fullMatrix<double> &pts, fullVector<double> &weights); static void getPrism(int order, fullMatrix<double> &pts, fullVector<double> &weights); static void getPyramid(int order, fullMatrix<double> &pts, - fullVector<double> &weights); + fullVector<double> &weights); }; #endif diff --git a/Numeric/GaussJacobi1D.cpp b/Numeric/GaussJacobi1D.cpp index 59e967ff7a3e7fb88fcd21890f0f06c00f773861..5f5a1d73c3b04c049b9237141c44c80d46d89bb6 100644 --- a/Numeric/GaussJacobi1D.cpp +++ b/Numeric/GaussJacobi1D.cpp @@ -86,1487 +86,4095 @@ int main(int argc, char **argv) #include <stdlib.h> #include <stdio.h> #include "GmshMessage.h" -static double _gaussJacobiPt_1[5][5][1] = { - { // a = 0 - { 0.000000000000000e+00}, - { 3.333333333333333e-01}, - { 5.000000000000000e-01}, - { 6.000000000000000e-01}, - { 6.666666666666666e-01} - }, - { // a = 1 - {-3.333333333333333e-01}, - { 0.000000000000000e+00}, - { 2.000000000000000e-01}, - { 3.333333333333333e-01}, - { 4.285714285714285e-01} - }, - { // a = 2 - {-5.000000000000000e-01}, - {-2.000000000000000e-01}, - { 0.000000000000000e+00}, - { 1.428571428571428e-01}, - { 2.500000000000000e-01} - }, - { // a = 3 - {-6.000000000000000e-01}, - {-3.333333333333333e-01}, - {-1.428571428571428e-01}, - { 0.000000000000000e+00}, - { 1.111111111111111e-01} - }, - { // a = 4 - {-6.666666666666666e-01}, - {-4.285714285714285e-01}, - {-2.500000000000000e-01}, - {-1.111111111111111e-01}, - { 0.000000000000000e+00} - } -}; +static double _gaussJacobiPt_1[5][5][1] = {{// a = 0 + {0.000000000000000e+00}, + {3.333333333333333e-01}, + {5.000000000000000e-01}, + {6.000000000000000e-01}, + {6.666666666666666e-01}}, + {// a = 1 + {-3.333333333333333e-01}, + {0.000000000000000e+00}, + {2.000000000000000e-01}, + {3.333333333333333e-01}, + {4.285714285714285e-01}}, + {// a = 2 + {-5.000000000000000e-01}, + {-2.000000000000000e-01}, + {0.000000000000000e+00}, + {1.428571428571428e-01}, + {2.500000000000000e-01}}, + {// a = 3 + {-6.000000000000000e-01}, + {-3.333333333333333e-01}, + {-1.428571428571428e-01}, + {0.000000000000000e+00}, + {1.111111111111111e-01}}, + {// a = 4 + {-6.666666666666666e-01}, + {-4.285714285714285e-01}, + {-2.500000000000000e-01}, + {-1.111111111111111e-01}, + {0.000000000000000e+00}}}; static double _gaussJacobiPt_2[5][5][2] = { - { // a = 0 - {-5.773502691896257e-01, 5.773502691896257e-01}, - {-2.898979485566356e-01, 6.898979485566357e-01}, - {-8.830368802245062e-02, 7.549703546891172e-01}, - { 5.971587178976978e-02, 7.974269853530873e-01}, - { 1.726731646460114e-01, 8.273268353539885e-01} - }, - { // a = 1 - {-6.898979485566357e-01, 2.898979485566356e-01}, - {-4.472135954999579e-01, 4.472135954999579e-01}, - {-2.612038749637415e-01, 5.469181606780271e-01}, - {-1.159625273557000e-01, 6.159625273556999e-01}, - {-2.775557561562891e-17, 6.666666666666667e-01} - }, - { // a = 2 - {-7.549703546891172e-01, 8.830368802245062e-02}, - {-5.469181606780271e-01, 2.612038749637415e-01}, - {-3.779644730092272e-01, 3.779644730092272e-01}, - {-2.402530733520422e-01, 4.624752955742643e-01}, - {-1.265986323710904e-01, 5.265986323710904e-01} - }, - { // a = 3 - {-7.974269853530873e-01, -5.971587178976978e-02}, - {-6.159625273556999e-01, 1.159625273557000e-01}, - {-4.624752955742643e-01, 2.402530733520422e-01}, - {-3.333333333333333e-01, 3.333333333333333e-01}, - {-2.240092377397959e-01, 4.058274195579776e-01} - }, - { // a = 4 - {-8.273268353539885e-01, -1.726731646460114e-01}, - {-6.666666666666667e-01, 2.775557561562891e-17}, - {-5.265986323710904e-01, 1.265986323710904e-01}, - {-4.058274195579776e-01, 2.240092377397959e-01}, - {-3.015113445777636e-01, 3.015113445777636e-01} - } -}; + {// a = 0 + {-5.773502691896257e-01, 5.773502691896257e-01}, + {-2.898979485566356e-01, 6.898979485566357e-01}, + {-8.830368802245062e-02, 7.549703546891172e-01}, + {5.971587178976978e-02, 7.974269853530873e-01}, + {1.726731646460114e-01, 8.273268353539885e-01}}, + {// a = 1 + {-6.898979485566357e-01, 2.898979485566356e-01}, + {-4.472135954999579e-01, 4.472135954999579e-01}, + {-2.612038749637415e-01, 5.469181606780271e-01}, + {-1.159625273557000e-01, 6.159625273556999e-01}, + {-2.775557561562891e-17, 6.666666666666667e-01}}, + {// a = 2 + {-7.549703546891172e-01, 8.830368802245062e-02}, + {-5.469181606780271e-01, 2.612038749637415e-01}, + {-3.779644730092272e-01, 3.779644730092272e-01}, + {-2.402530733520422e-01, 4.624752955742643e-01}, + {-1.265986323710904e-01, 5.265986323710904e-01}}, + {// a = 3 + {-7.974269853530873e-01, -5.971587178976978e-02}, + {-6.159625273556999e-01, 1.159625273557000e-01}, + {-4.624752955742643e-01, 2.402530733520422e-01}, + {-3.333333333333333e-01, 3.333333333333333e-01}, + {-2.240092377397959e-01, 4.058274195579776e-01}}, + {// a = 4 + {-8.273268353539885e-01, -1.726731646460114e-01}, + {-6.666666666666667e-01, 2.775557561562891e-17}, + {-5.265986323710904e-01, 1.265986323710904e-01}, + {-4.058274195579776e-01, 2.240092377397959e-01}, + {-3.015113445777636e-01, 3.015113445777636e-01}}}; static double _gaussJacobiPt_3[5][5][3] = { - { // a = 0 - {-7.745966692414833e-01, 1.205632815803881e-16, 7.745966692414832e-01}, - {-5.753189235216941e-01, 1.810662711185308e-01, 8.228240809745919e-01}, - {-4.100044197769969e-01, 3.059924679232963e-01, 8.540119518537008e-01}, - {-2.734707395669761e-01, 3.976225383272270e-01, 8.758482012397490e-01}, - {-1.597738813262838e-01, 4.677787104157496e-01, 8.919951709105340e-01} - }, - { // a = 1 - {-8.228240809745919e-01, -1.810662711185308e-01, 5.753189235216941e-01}, - {-6.546536707079771e-01, -9.844555726168380e-17, 6.546536707079772e-01}, - {-5.077876295583149e-01, 1.323008207773232e-01, 7.088201421143250e-01}, - {-3.816683386353370e-01, 2.334502967228511e-01, 7.482180419124858e-01}, - {-2.733778240471743e-01, 3.133731347413368e-01, 7.781865074876556e-01} - }, - { // a = 2 - {-8.540119518537008e-01, -3.059924679232963e-01, 4.100044197769969e-01}, - {-7.088201421143250e-01, -1.323008207773232e-01, 5.077876295583149e-01}, - {-5.773502691896258e-01, 5.724587470723463e-17, 5.773502691896257e-01}, - {-4.611587037808975e-01, 1.043853303832390e-01, 6.295006461249313e-01}, - {-3.590327974759225e-01, 1.889305092895958e-01, 6.701022881863266e-01} - }, - { // a = 3 - {-8.758482012397490e-01, -3.976225383272270e-01, 2.734707395669761e-01}, - {-7.482180419124858e-01, -2.334502967228511e-01, 3.816683386353370e-01}, - {-6.295006461249313e-01, -1.043853303832390e-01, 4.611587037808975e-01}, - {-5.222329678670936e-01, -7.155734338404329e-18, 5.222329678670936e-01}, - {-4.261936288339650e-01, 8.625035138615555e-02, 5.707125082170403e-01} - }, - { // a = 4 - {-8.919951709105340e-01, -4.677787104157496e-01, 1.597738813262838e-01}, - {-7.781865074876556e-01, -3.133731347413368e-01, 2.733778240471743e-01}, - {-6.701022881863266e-01, -1.889305092895958e-01, 3.590327974759225e-01}, - {-5.707125082170403e-01, -8.625035138615555e-02, 4.261936288339650e-01}, - {-4.803844614152614e-01, -9.757819552369540e-18, 4.803844614152614e-01} - } -}; + {// a = 0 + {-7.745966692414833e-01, 1.205632815803881e-16, 7.745966692414832e-01}, + {-5.753189235216941e-01, 1.810662711185308e-01, 8.228240809745919e-01}, + {-4.100044197769969e-01, 3.059924679232963e-01, 8.540119518537008e-01}, + {-2.734707395669761e-01, 3.976225383272270e-01, 8.758482012397490e-01}, + {-1.597738813262838e-01, 4.677787104157496e-01, 8.919951709105340e-01}}, + {// a = 1 + {-8.228240809745919e-01, -1.810662711185308e-01, 5.753189235216941e-01}, + {-6.546536707079771e-01, -9.844555726168380e-17, 6.546536707079772e-01}, + {-5.077876295583149e-01, 1.323008207773232e-01, 7.088201421143250e-01}, + {-3.816683386353370e-01, 2.334502967228511e-01, 7.482180419124858e-01}, + {-2.733778240471743e-01, 3.133731347413368e-01, 7.781865074876556e-01}}, + {// a = 2 + {-8.540119518537008e-01, -3.059924679232963e-01, 4.100044197769969e-01}, + {-7.088201421143250e-01, -1.323008207773232e-01, 5.077876295583149e-01}, + {-5.773502691896258e-01, 5.724587470723463e-17, 5.773502691896257e-01}, + {-4.611587037808975e-01, 1.043853303832390e-01, 6.295006461249313e-01}, + {-3.590327974759225e-01, 1.889305092895958e-01, 6.701022881863266e-01}}, + {// a = 3 + {-8.758482012397490e-01, -3.976225383272270e-01, 2.734707395669761e-01}, + {-7.482180419124858e-01, -2.334502967228511e-01, 3.816683386353370e-01}, + {-6.295006461249313e-01, -1.043853303832390e-01, 4.611587037808975e-01}, + {-5.222329678670936e-01, -7.155734338404329e-18, 5.222329678670936e-01}, + {-4.261936288339650e-01, 8.625035138615555e-02, 5.707125082170403e-01}}, + {// a = 4 + {-8.919951709105340e-01, -4.677787104157496e-01, 1.597738813262838e-01}, + {-7.781865074876556e-01, -3.133731347413368e-01, 2.733778240471743e-01}, + {-6.701022881863266e-01, -1.889305092895958e-01, 3.590327974759225e-01}, + {-5.707125082170403e-01, -8.625035138615555e-02, 4.261936288339650e-01}, + {-4.803844614152614e-01, -9.757819552369540e-18, 4.803844614152614e-01}}}; static double _gaussJacobiPt_4[5][5][4] = { - { // a = 0 - {-8.611363115940525e-01, -3.399810435848561e-01, 3.399810435848563e-01, 8.611363115940522e-01}, - {-7.204802713124385e-01, -1.671808647378336e-01, 4.463139727237523e-01, 8.857916077709644e-01}, - {-5.917028357935457e-01, -3.409459020873494e-02, 5.227985248962753e-01, 9.029989011060053e-01}, - {-4.770444223382206e-01, 7.169289217650020e-02, 5.805664599385740e-01, 9.156941611322373e-01}, - {-3.757290143059655e-01, 1.578313191246453e-01, 6.257830332324487e-01, 9.254479952822050e-01} - }, - { // a = 1 - {-8.857916077709644e-01, -4.463139727237523e-01, 1.671808647378336e-01, 7.204802713124385e-01}, - {-7.650553239294647e-01, -2.852315164806452e-01, 2.852315164806453e-01, 7.650553239294645e-01}, - {-6.507788566919654e-01, -1.563704318081081e-01, 3.734893787362535e-01, 7.972962734001834e-01}, - {-5.462841953788393e-01, -5.089520957245923e-02, 4.421244835661375e-01, 8.217215880518276e-01}, - {-4.519097560851453e-01, 3.702073588896999e-02, 4.970906821069787e-01, 8.408752611661195e-01} - }, - { // a = 2 - {-9.029989011060053e-01, -5.227985248962753e-01, 3.409459020873494e-02, 5.917028357935457e-01}, - {-7.972962734001834e-01, -3.734893787362535e-01, 1.563704318081081e-01, 6.507788566919654e-01}, - {-6.947465906068658e-01, -2.505628070857315e-01, 2.505628070857316e-01, 6.947465906068658e-01}, - {-5.990347085082480e-01, -1.476110519995259e-01, 3.255437708118887e-01, 7.287942973881928e-01}, - {-5.110896002353021e-01, -6.017330591592821e-02, 3.867299771317085e-01, 7.559615004480931e-01} - }, - { // a = 3 - {-9.156941611322373e-01, -5.805664599385740e-01, -7.169289217650020e-02, 4.770444223382206e-01}, - {-8.217215880518276e-01, -4.421244835661375e-01, 5.089520957245923e-02, 5.462841953788393e-01}, - {-7.287942973881928e-01, -3.255437708118887e-01, 1.476110519995259e-01, 5.990347085082480e-01}, - {-6.406425159697439e-01, -2.260876561655187e-01, 2.260876561655185e-01, 6.406425159697442e-01}, - {-5.585054900997352e-01, -1.403071030756702e-01, 2.911390755462105e-01, 6.743401842958617e-01} - }, - { // a = 4 - {-9.254479952822050e-01, -6.257830332324487e-01, -1.578313191246453e-01, 3.757290143059655e-01}, - {-8.408752611661195e-01, -4.970906821069787e-01, -3.702073588896999e-02, 4.519097560851453e-01}, - {-7.559615004480931e-01, -3.867299771317085e-01, 6.017330591592821e-02, 5.110896002353021e-01}, - {-6.743401842958617e-01, -2.911390755462105e-01, 1.403071030756702e-01, 5.585054900997352e-01}, - {-5.974051457014303e-01, -2.076224744324486e-01, 2.076224744324486e-01, 5.974051457014302e-01} - } -}; + {// a = 0 + {-8.611363115940525e-01, -3.399810435848561e-01, 3.399810435848563e-01, + 8.611363115940522e-01}, + {-7.204802713124385e-01, -1.671808647378336e-01, 4.463139727237523e-01, + 8.857916077709644e-01}, + {-5.917028357935457e-01, -3.409459020873494e-02, 5.227985248962753e-01, + 9.029989011060053e-01}, + {-4.770444223382206e-01, 7.169289217650020e-02, 5.805664599385740e-01, + 9.156941611322373e-01}, + {-3.757290143059655e-01, 1.578313191246453e-01, 6.257830332324487e-01, + 9.254479952822050e-01}}, + {// a = 1 + {-8.857916077709644e-01, -4.463139727237523e-01, 1.671808647378336e-01, + 7.204802713124385e-01}, + {-7.650553239294647e-01, -2.852315164806452e-01, 2.852315164806453e-01, + 7.650553239294645e-01}, + {-6.507788566919654e-01, -1.563704318081081e-01, 3.734893787362535e-01, + 7.972962734001834e-01}, + {-5.462841953788393e-01, -5.089520957245923e-02, 4.421244835661375e-01, + 8.217215880518276e-01}, + {-4.519097560851453e-01, 3.702073588896999e-02, 4.970906821069787e-01, + 8.408752611661195e-01}}, + {// a = 2 + {-9.029989011060053e-01, -5.227985248962753e-01, 3.409459020873494e-02, + 5.917028357935457e-01}, + {-7.972962734001834e-01, -3.734893787362535e-01, 1.563704318081081e-01, + 6.507788566919654e-01}, + {-6.947465906068658e-01, -2.505628070857315e-01, 2.505628070857316e-01, + 6.947465906068658e-01}, + {-5.990347085082480e-01, -1.476110519995259e-01, 3.255437708118887e-01, + 7.287942973881928e-01}, + {-5.110896002353021e-01, -6.017330591592821e-02, 3.867299771317085e-01, + 7.559615004480931e-01}}, + {// a = 3 + {-9.156941611322373e-01, -5.805664599385740e-01, -7.169289217650020e-02, + 4.770444223382206e-01}, + {-8.217215880518276e-01, -4.421244835661375e-01, 5.089520957245923e-02, + 5.462841953788393e-01}, + {-7.287942973881928e-01, -3.255437708118887e-01, 1.476110519995259e-01, + 5.990347085082480e-01}, + {-6.406425159697439e-01, -2.260876561655187e-01, 2.260876561655185e-01, + 6.406425159697442e-01}, + {-5.585054900997352e-01, -1.403071030756702e-01, 2.911390755462105e-01, + 6.743401842958617e-01}}, + {// a = 4 + {-9.254479952822050e-01, -6.257830332324487e-01, -1.578313191246453e-01, + 3.757290143059655e-01}, + {-8.408752611661195e-01, -4.970906821069787e-01, -3.702073588896999e-02, + 4.519097560851453e-01}, + {-7.559615004480931e-01, -3.867299771317085e-01, 6.017330591592821e-02, + 5.110896002353021e-01}, + {-6.743401842958617e-01, -2.911390755462105e-01, 1.403071030756702e-01, + 5.585054900997352e-01}, + {-5.974051457014303e-01, -2.076224744324486e-01, 2.076224744324486e-01, + 5.974051457014302e-01}}}; static double _gaussJacobiPt_5[5][5][5] = { - { // a = 0 - {-9.061798459386639e-01, -5.384693101056829e-01, -2.296712866029664e-17, 5.384693101056830e-01, 9.061798459386639e-01}, - {-8.029298284023467e-01, -3.909285467072722e-01, 1.240503795052278e-01, 6.039731642527837e-01, 9.203802858970622e-01}, - {-7.021084258940329e-01, -2.686669452617738e-01, 2.202272258689614e-01, 6.530393584566088e-01, 9.308421201635702e-01}, - {-6.075759852065801e-01, -1.657995763555987e-01, 2.971400084741230e-01, 6.912102999476756e-01, 9.388714069865340e-01}, - {-5.204159103950381e-01, -7.813265093696906e-02, 3.601184654820193e-01, 7.217726873528852e-01, 9.452288370685311e-01} - }, - { // a = 1 - {-9.203802858970622e-01, -6.039731642527837e-01, -1.240503795052278e-01, 3.909285467072722e-01, 8.029298284023467e-01}, - {-8.302238962785672e-01, -4.688487934707142e-01, 5.063780056112226e-17, 4.688487934707142e-01, 8.302238962785672e-01}, - {-7.401236485798885e-01, -3.538526341284552e-01, 9.890279315083066e-02, 5.288423044511161e-01, 8.508465697217814e-01}, - {-6.539998151013593e-01, -2.549967597332658e-01, 1.797678318882373e-01, 5.765287751266746e-01, 8.669856821054276e-01}, - {-5.732884185071708e-01, -1.692400163826446e-01, 2.471879027735052e-01, 6.153765309147026e-01, 8.799640012016079e-01} - }, - { // a = 2 - {-9.308421201635702e-01, -6.530393584566088e-01, -2.202272258689614e-01, 2.686669452617738e-01, 7.021084258940329e-01}, - {-8.508465697217814e-01, -5.288423044511161e-01, -9.890279315083066e-02, 3.538526341284552e-01, 7.401236485798885e-01}, - {-7.694553243317872e-01, -4.209148050238113e-01, 1.220627971223391e-16, 4.209148050238114e-01, 7.694553243317872e-01}, - {-6.904577501267610e-01, -3.265199313490006e-01, 8.233784955203487e-02, 4.751788706128313e-01, 7.927942946442286e-01}, - {-6.154421152496427e-01, -2.434337651431532e-01, 1.520219788537995e-01, 5.200367263054764e-01, 8.118171752335199e-01} - }, - { // a = 3 - {-9.388714069865340e-01, -6.912102999476756e-01, -2.971400084741230e-01, 1.657995763555987e-01, 6.075759852065801e-01}, - {-8.669856821054276e-01, -5.765287751266746e-01, -1.797678318882373e-01, 2.549967597332658e-01, 6.539998151013593e-01}, - {-7.927942946442286e-01, -4.751788706128313e-01, -8.233784955203487e-02, 3.265199313490006e-01, 6.904577501267610e-01}, - {-7.198842953848503e-01, -3.852703828805474e-01, 6.265476865476206e-17, 3.852703828805473e-01, 7.198842953848507e-01}, - {-6.498906441312227e-01, -3.051663960317241e-01, 7.057137877891513e-02, 4.344497877305027e-01, 7.441535207123526e-01} - }, - { // a = 4 - {-9.452288370685311e-01, -7.217726873528852e-01, -3.601184654820193e-01, 7.813265093696906e-02, 5.204159103950381e-01}, - {-8.799640012016079e-01, -6.153765309147026e-01, -2.471879027735052e-01, 1.692400163826446e-01, 5.732884185071708e-01}, - {-8.118171752335199e-01, -5.200367263054764e-01, -1.520219788537995e-01, 2.434337651431532e-01, 6.154421152496427e-01}, - {-7.441535207123526e-01, -4.344497877305027e-01, -7.057137877891513e-02, 3.051663960317241e-01, 6.498906441312227e-01}, - {-6.785983445458468e-01, -3.574067443365933e-01, 1.135699304818221e-16, 3.574067443365931e-01, 6.785983445458470e-01} - } -}; + {// a = 0 + {-9.061798459386639e-01, -5.384693101056829e-01, -2.296712866029664e-17, + 5.384693101056830e-01, 9.061798459386639e-01}, + {-8.029298284023467e-01, -3.909285467072722e-01, 1.240503795052278e-01, + 6.039731642527837e-01, 9.203802858970622e-01}, + {-7.021084258940329e-01, -2.686669452617738e-01, 2.202272258689614e-01, + 6.530393584566088e-01, 9.308421201635702e-01}, + {-6.075759852065801e-01, -1.657995763555987e-01, 2.971400084741230e-01, + 6.912102999476756e-01, 9.388714069865340e-01}, + {-5.204159103950381e-01, -7.813265093696906e-02, 3.601184654820193e-01, + 7.217726873528852e-01, 9.452288370685311e-01}}, + {// a = 1 + {-9.203802858970622e-01, -6.039731642527837e-01, -1.240503795052278e-01, + 3.909285467072722e-01, 8.029298284023467e-01}, + {-8.302238962785672e-01, -4.688487934707142e-01, 5.063780056112226e-17, + 4.688487934707142e-01, 8.302238962785672e-01}, + {-7.401236485798885e-01, -3.538526341284552e-01, 9.890279315083066e-02, + 5.288423044511161e-01, 8.508465697217814e-01}, + {-6.539998151013593e-01, -2.549967597332658e-01, 1.797678318882373e-01, + 5.765287751266746e-01, 8.669856821054276e-01}, + {-5.732884185071708e-01, -1.692400163826446e-01, 2.471879027735052e-01, + 6.153765309147026e-01, 8.799640012016079e-01}}, + {// a = 2 + {-9.308421201635702e-01, -6.530393584566088e-01, -2.202272258689614e-01, + 2.686669452617738e-01, 7.021084258940329e-01}, + {-8.508465697217814e-01, -5.288423044511161e-01, -9.890279315083066e-02, + 3.538526341284552e-01, 7.401236485798885e-01}, + {-7.694553243317872e-01, -4.209148050238113e-01, 1.220627971223391e-16, + 4.209148050238114e-01, 7.694553243317872e-01}, + {-6.904577501267610e-01, -3.265199313490006e-01, 8.233784955203487e-02, + 4.751788706128313e-01, 7.927942946442286e-01}, + {-6.154421152496427e-01, -2.434337651431532e-01, 1.520219788537995e-01, + 5.200367263054764e-01, 8.118171752335199e-01}}, + {// a = 3 + {-9.388714069865340e-01, -6.912102999476756e-01, -2.971400084741230e-01, + 1.657995763555987e-01, 6.075759852065801e-01}, + {-8.669856821054276e-01, -5.765287751266746e-01, -1.797678318882373e-01, + 2.549967597332658e-01, 6.539998151013593e-01}, + {-7.927942946442286e-01, -4.751788706128313e-01, -8.233784955203487e-02, + 3.265199313490006e-01, 6.904577501267610e-01}, + {-7.198842953848503e-01, -3.852703828805474e-01, 6.265476865476206e-17, + 3.852703828805473e-01, 7.198842953848507e-01}, + {-6.498906441312227e-01, -3.051663960317241e-01, 7.057137877891513e-02, + 4.344497877305027e-01, 7.441535207123526e-01}}, + {// a = 4 + {-9.452288370685311e-01, -7.217726873528852e-01, -3.601184654820193e-01, + 7.813265093696906e-02, 5.204159103950381e-01}, + {-8.799640012016079e-01, -6.153765309147026e-01, -2.471879027735052e-01, + 1.692400163826446e-01, 5.732884185071708e-01}, + {-8.118171752335199e-01, -5.200367263054764e-01, -1.520219788537995e-01, + 2.434337651431532e-01, 6.154421152496427e-01}, + {-7.441535207123526e-01, -4.344497877305027e-01, -7.057137877891513e-02, + 3.051663960317241e-01, 6.498906441312227e-01}, + {-6.785983445458468e-01, -3.574067443365933e-01, 1.135699304818221e-16, + 3.574067443365931e-01, 6.785983445458470e-01}}}; static double _gaussJacobiPt_6[5][5][6] = { - { // a = 0 - {-9.324695142031519e-01, -6.612093864662646e-01, -2.386191860831971e-01, 2.386191860831968e-01, 6.612093864662646e-01, 9.324695142031523e-01}, - {-8.538913426394820e-01, -5.384677240601088e-01, -1.173430375431004e-01, 3.260306194376912e-01, 7.038428006630316e-01, 9.413671456804302e-01}, - {-7.736112323551240e-01, -4.313622546234276e-01, -1.807282632950416e-02, 3.951261639542176e-01, 7.368721166840299e-01, 9.481908898126653e-01}, - {-6.954536764313222e-01, -3.373990859248842e-01, 6.482313345808229e-02, 4.512055566591650e-01, 7.632333688745154e-01, 9.535907033644436e-01}, - {-6.210608321550133e-01, -2.544976879714631e-01, 1.351447457091878e-01, 4.976729950111234e-01, 7.847703168931964e-01, 9.579704625129687e-01} - }, - { // a = 1 - {-9.413671456804302e-01, -7.038428006630316e-01, -3.260306194376912e-01, 1.173430375431004e-01, 5.384677240601088e-01, 8.538913426394820e-01}, - {-8.717401485096062e-01, -5.917001814331421e-01, -2.092992179024789e-01, 2.092992179024784e-01, 5.917001814331418e-01, 8.717401485096067e-01}, - {-7.993818545492362e-01, -4.919057913388810e-01, -1.117339353995897e-01, 2.835397724481963e-01, 6.337933270557147e-01, 8.856884817837958e-01}, - {-7.279042649828523e-01, -4.029169178070013e-01, -2.885478667483911e-02, 3.448376945011423e-01, 6.679457984322057e-01, 8.968924765313449e-01}, - {-6.590086789824122e-01, -3.233115599281374e-01, 4.246736788877636e-02, 3.963569738302052e-01, 6.962280608304199e-01, 9.060913657729128e-01} - }, - { // a = 2 - {-9.481908898126653e-01, -7.368721166840299e-01, -3.951261639542176e-01, 1.807282632950416e-02, 4.313622546234276e-01, 7.736112323551240e-01}, - {-8.856884817837958e-01, -6.337933270557147e-01, -2.835397724481963e-01, 1.117339353995897e-01, 4.919057913388810e-01, 7.993818545492362e-01}, - {-8.198459954634868e-01, -5.406046373873585e-01, -1.886774224907859e-01, 1.886774224907859e-01, 5.406046373873586e-01, 8.198459954634867e-01}, - {-7.540309604648933e-01, -4.563858095825369e-01, -1.069422717353892e-01, 2.531275817031343e-01, 5.806736588601311e-01, 8.364989776901421e-01}, - {-6.899306434299896e-01, -3.801739750840734e-01, -3.575072875934796e-02, 3.079564307616816e-01, 6.142457880527944e-01, 8.503197951256017e-01} - }, - { // a = 3 - {-9.535907033644436e-01, -7.632333688745154e-01, -4.512055566591650e-01, -6.482313345808229e-02, 3.373990859248842e-01, 6.954536764313222e-01}, - {-8.968924765313449e-01, -6.679457984322057e-01, -3.448376945011423e-01, 2.885478667483911e-02, 4.029169178070013e-01, 7.279042649828523e-01}, - {-8.364989776901421e-01, -5.806736588601311e-01, -2.531275817031343e-01, 1.069422717353892e-01, 4.563858095825369e-01, 7.540309604648933e-01}, - {-7.755355259865796e-01, -5.009134932118855e-01, -1.731567539181084e-01, 1.731567539181084e-01, 5.009134932118857e-01, 7.755355259865793e-01}, - {-7.156393366264865e-01, -4.280278563380202e-01, -1.027801644267999e-01, 2.300782005729258e-01, 5.386042094609106e-01, 7.935544210416807e-01} - }, - { // a = 4 - {-9.579704625129687e-01, -7.847703168931964e-01, -4.976729950111234e-01, -1.351447457091878e-01, 2.544976879714631e-01, 6.210608321550133e-01}, - {-9.060913657729128e-01, -6.962280608304199e-01, -3.963569738302052e-01, -4.246736788877636e-02, 3.233115599281374e-01, 6.590086789824122e-01}, - {-8.503197951256017e-01, -6.142457880527944e-01, -3.079564307616816e-01, 3.575072875934796e-02, 3.801739750840734e-01, 6.899306434299896e-01}, - {-7.935544210416807e-01, -5.386042094609106e-01, -2.300782005729258e-01, 1.027801644267999e-01, 4.280278563380202e-01, 7.156393366264865e-01}, - {-7.373657361102366e-01, -4.688999449180306e-01, -1.609294785830220e-01, 1.609294785830219e-01, 4.688999449180306e-01, 7.373657361102364e-01} - } -}; + {// a = 0 + {-9.324695142031519e-01, -6.612093864662646e-01, -2.386191860831971e-01, + 2.386191860831968e-01, 6.612093864662646e-01, 9.324695142031523e-01}, + {-8.538913426394820e-01, -5.384677240601088e-01, -1.173430375431004e-01, + 3.260306194376912e-01, 7.038428006630316e-01, 9.413671456804302e-01}, + {-7.736112323551240e-01, -4.313622546234276e-01, -1.807282632950416e-02, + 3.951261639542176e-01, 7.368721166840299e-01, 9.481908898126653e-01}, + {-6.954536764313222e-01, -3.373990859248842e-01, 6.482313345808229e-02, + 4.512055566591650e-01, 7.632333688745154e-01, 9.535907033644436e-01}, + {-6.210608321550133e-01, -2.544976879714631e-01, 1.351447457091878e-01, + 4.976729950111234e-01, 7.847703168931964e-01, 9.579704625129687e-01}}, + {// a = 1 + {-9.413671456804302e-01, -7.038428006630316e-01, -3.260306194376912e-01, + 1.173430375431004e-01, 5.384677240601088e-01, 8.538913426394820e-01}, + {-8.717401485096062e-01, -5.917001814331421e-01, -2.092992179024789e-01, + 2.092992179024784e-01, 5.917001814331418e-01, 8.717401485096067e-01}, + {-7.993818545492362e-01, -4.919057913388810e-01, -1.117339353995897e-01, + 2.835397724481963e-01, 6.337933270557147e-01, 8.856884817837958e-01}, + {-7.279042649828523e-01, -4.029169178070013e-01, -2.885478667483911e-02, + 3.448376945011423e-01, 6.679457984322057e-01, 8.968924765313449e-01}, + {-6.590086789824122e-01, -3.233115599281374e-01, 4.246736788877636e-02, + 3.963569738302052e-01, 6.962280608304199e-01, 9.060913657729128e-01}}, + {// a = 2 + {-9.481908898126653e-01, -7.368721166840299e-01, -3.951261639542176e-01, + 1.807282632950416e-02, 4.313622546234276e-01, 7.736112323551240e-01}, + {-8.856884817837958e-01, -6.337933270557147e-01, -2.835397724481963e-01, + 1.117339353995897e-01, 4.919057913388810e-01, 7.993818545492362e-01}, + {-8.198459954634868e-01, -5.406046373873585e-01, -1.886774224907859e-01, + 1.886774224907859e-01, 5.406046373873586e-01, 8.198459954634867e-01}, + {-7.540309604648933e-01, -4.563858095825369e-01, -1.069422717353892e-01, + 2.531275817031343e-01, 5.806736588601311e-01, 8.364989776901421e-01}, + {-6.899306434299896e-01, -3.801739750840734e-01, -3.575072875934796e-02, + 3.079564307616816e-01, 6.142457880527944e-01, 8.503197951256017e-01}}, + {// a = 3 + {-9.535907033644436e-01, -7.632333688745154e-01, -4.512055566591650e-01, + -6.482313345808229e-02, 3.373990859248842e-01, 6.954536764313222e-01}, + {-8.968924765313449e-01, -6.679457984322057e-01, -3.448376945011423e-01, + 2.885478667483911e-02, 4.029169178070013e-01, 7.279042649828523e-01}, + {-8.364989776901421e-01, -5.806736588601311e-01, -2.531275817031343e-01, + 1.069422717353892e-01, 4.563858095825369e-01, 7.540309604648933e-01}, + {-7.755355259865796e-01, -5.009134932118855e-01, -1.731567539181084e-01, + 1.731567539181084e-01, 5.009134932118857e-01, 7.755355259865793e-01}, + {-7.156393366264865e-01, -4.280278563380202e-01, -1.027801644267999e-01, + 2.300782005729258e-01, 5.386042094609106e-01, 7.935544210416807e-01}}, + {// a = 4 + {-9.579704625129687e-01, -7.847703168931964e-01, -4.976729950111234e-01, + -1.351447457091878e-01, 2.544976879714631e-01, 6.210608321550133e-01}, + {-9.060913657729128e-01, -6.962280608304199e-01, -3.963569738302052e-01, + -4.246736788877636e-02, 3.233115599281374e-01, 6.590086789824122e-01}, + {-8.503197951256017e-01, -6.142457880527944e-01, -3.079564307616816e-01, + 3.575072875934796e-02, 3.801739750840734e-01, 6.899306434299896e-01}, + {-7.935544210416807e-01, -5.386042094609106e-01, -2.300782005729258e-01, + 1.027801644267999e-01, 4.280278563380202e-01, 7.156393366264865e-01}, + {-7.373657361102366e-01, -4.688999449180306e-01, -1.609294785830220e-01, + 1.609294785830219e-01, 4.688999449180306e-01, 7.373657361102364e-01}}}; static double _gaussJacobiPt_7[5][5][7] = { - { // a = 0 - {-9.491079123427586e-01, -7.415311855993943e-01, -4.058451513773970e-01, 1.193908377356533e-16, 4.058451513773974e-01, 7.415311855993942e-01, 9.491079123427585e-01}, - {-8.874748789261557e-01, -6.395186165262153e-01, -2.947505657736608e-01, 9.430725266111044e-02, 4.684203544308211e-01, 7.706418936781918e-01, 9.550412271225752e-01}, - {-8.223663331260054e-01, -5.470344931828751e-01, -2.000430265579859e-01, 1.719957108058808e-01, 5.188917479038850e-01, 7.938219417039016e-01, 9.597344524531991e-01}, - {-7.571457423351552e-01, -4.632731193770239e-01, -1.182670787543269e-01, 2.372080568631812e-01, 5.605071039321651e-01, 8.127250682903714e-01, 9.635398290278467e-01}, - {-6.935171222617036e-01, -3.873469549165231e-01, -4.691981399801844e-02, 2.927786050394288e-01, 5.954333796292736e-01, 8.284398011290520e-01, 9.666876609340463e-01} - }, - { // a = 1 - {-9.550412271225752e-01, -7.706418936781918e-01, -4.684203544308211e-01, -9.430725266111044e-02, 2.947505657736608e-01, 6.395186165262153e-01, 8.874748789261557e-01}, - {-8.997579954114601e-01, -6.771862795107377e-01, -3.631174638261781e-01, -3.020666787869917e-17, 3.631174638261780e-01, 6.771862795107376e-01, 8.997579954114603e-01}, - {-8.405901445935972e-01, -5.911813487913296e-01, -2.718937884336990e-01, 7.898300551160212e-02, 4.191737999226332e-01, 7.076570510566212e-01, 9.096161312101220e-01}, - {-7.806436006674152e-01, -5.122885621840089e-01, -1.920542687645395e-01, 1.462023496817571e-01, 4.660272611591706e-01, 7.328300530177787e-01, 9.177045455350352e-01}, - {-7.215735195976674e-01, -4.399832807349889e-01, -1.215869111005672e-01, 2.041569362298995e-01, 5.058029972816601e-01, 7.539854765822848e-01, 9.244614592341160e-01} - }, - { // a = 2 - {-9.597344524531991e-01, -7.938219417039016e-01, -5.188917479038850e-01, -1.719957108058808e-01, 2.000430265579859e-01, 5.470344931828751e-01, 8.223663331260054e-01}, - {-9.096161312101220e-01, -7.076570510566212e-01, -4.191737999226332e-01, -7.898300551160212e-02, 2.718937884336990e-01, 5.911813487913296e-01, 8.405901445935972e-01}, - {-8.554020262848745e-01, -6.273781397626187e-01, -3.316295536027899e-01, 1.696236582304631e-16, 3.316295536027896e-01, 6.273781397626187e-01, 8.554020262848745e-01}, - {-7.999546795922177e-01, -5.529486988055030e-01, -2.541331370777906e-01, 6.801075022236561e-02, 3.821440122181823e-01, 6.576200959973667e-01, 8.676827096691756e-01}, - {-7.448575365180665e-01, -4.840945559720232e-01, -1.850563195192408e-01, 1.272401577969688e-01, 4.254565070960148e-01, 6.832791838943486e-01, 8.780325632219984e-01} - }, - { // a = 3 - {-9.635398290278467e-01, -8.127250682903714e-01, -5.605071039321651e-01, -2.372080568631812e-01, 1.182670787543269e-01, 4.632731193770239e-01, 7.571457423351552e-01}, - {-9.177045455350352e-01, -7.328300530177787e-01, -4.660272611591706e-01, -1.462023496817571e-01, 1.920542687645395e-01, 5.122885621840089e-01, 7.806436006674152e-01}, - {-8.676827096691756e-01, -6.576200959973667e-01, -3.821440122181823e-01, -6.801075022236561e-02, 2.541331370777906e-01, 5.529486988055030e-01, 7.999546795922177e-01}, - {-8.161152234442209e-01, -5.872564900763582e-01, -3.071626846160234e-01, 9.092219072621500e-17, 3.071626846160234e-01, 5.872564900763583e-01, 8.161152234442204e-01}, - {-7.645054103328334e-01, -5.216402272912483e-01, -2.397563306151332e-01, 5.974952126508076e-02, 3.530300783204262e-01, 6.166124827563498e-01, 8.298432192306912e-01} - }, - { // a = 4 - {-9.666876609340463e-01, -8.284398011290520e-01, -5.954333796292736e-01, -2.927786050394288e-01, 4.691981399801844e-02, 3.873469549165231e-01, 6.935171222617036e-01}, - {-9.244614592341160e-01, -7.539854765822848e-01, -5.058029972816601e-01, -2.041569362298995e-01, 1.215869111005672e-01, 4.399832807349889e-01, 7.215735195976674e-01}, - {-8.780325632219984e-01, -6.832791838943486e-01, -4.254565070960148e-01, -1.272401577969688e-01, 1.850563195192408e-01, 4.840945559720232e-01, 7.448575365180665e-01}, - {-8.298432192306912e-01, -6.166124827563498e-01, -3.530300783204262e-01, -5.974952126508076e-02, 2.397563306151332e-01, 5.216402272912483e-01, 7.645054103328334e-01}, - {-7.813155385456068e-01, -5.540100741142812e-01, -2.874349787466332e-01, -1.330996207987286e-16, 2.874349787466332e-01, 5.540100741142814e-01, 7.813155385456063e-01} - } -}; + {// a = 0 + {-9.491079123427586e-01, -7.415311855993943e-01, -4.058451513773970e-01, + 1.193908377356533e-16, 4.058451513773974e-01, 7.415311855993942e-01, + 9.491079123427585e-01}, + {-8.874748789261557e-01, -6.395186165262153e-01, -2.947505657736608e-01, + 9.430725266111044e-02, 4.684203544308211e-01, 7.706418936781918e-01, + 9.550412271225752e-01}, + {-8.223663331260054e-01, -5.470344931828751e-01, -2.000430265579859e-01, + 1.719957108058808e-01, 5.188917479038850e-01, 7.938219417039016e-01, + 9.597344524531991e-01}, + {-7.571457423351552e-01, -4.632731193770239e-01, -1.182670787543269e-01, + 2.372080568631812e-01, 5.605071039321651e-01, 8.127250682903714e-01, + 9.635398290278467e-01}, + {-6.935171222617036e-01, -3.873469549165231e-01, -4.691981399801844e-02, + 2.927786050394288e-01, 5.954333796292736e-01, 8.284398011290520e-01, + 9.666876609340463e-01}}, + {// a = 1 + {-9.550412271225752e-01, -7.706418936781918e-01, -4.684203544308211e-01, + -9.430725266111044e-02, 2.947505657736608e-01, 6.395186165262153e-01, + 8.874748789261557e-01}, + {-8.997579954114601e-01, -6.771862795107377e-01, -3.631174638261781e-01, + -3.020666787869917e-17, 3.631174638261780e-01, 6.771862795107376e-01, + 8.997579954114603e-01}, + {-8.405901445935972e-01, -5.911813487913296e-01, -2.718937884336990e-01, + 7.898300551160212e-02, 4.191737999226332e-01, 7.076570510566212e-01, + 9.096161312101220e-01}, + {-7.806436006674152e-01, -5.122885621840089e-01, -1.920542687645395e-01, + 1.462023496817571e-01, 4.660272611591706e-01, 7.328300530177787e-01, + 9.177045455350352e-01}, + {-7.215735195976674e-01, -4.399832807349889e-01, -1.215869111005672e-01, + 2.041569362298995e-01, 5.058029972816601e-01, 7.539854765822848e-01, + 9.244614592341160e-01}}, + {// a = 2 + {-9.597344524531991e-01, -7.938219417039016e-01, -5.188917479038850e-01, + -1.719957108058808e-01, 2.000430265579859e-01, 5.470344931828751e-01, + 8.223663331260054e-01}, + {-9.096161312101220e-01, -7.076570510566212e-01, -4.191737999226332e-01, + -7.898300551160212e-02, 2.718937884336990e-01, 5.911813487913296e-01, + 8.405901445935972e-01}, + {-8.554020262848745e-01, -6.273781397626187e-01, -3.316295536027899e-01, + 1.696236582304631e-16, 3.316295536027896e-01, 6.273781397626187e-01, + 8.554020262848745e-01}, + {-7.999546795922177e-01, -5.529486988055030e-01, -2.541331370777906e-01, + 6.801075022236561e-02, 3.821440122181823e-01, 6.576200959973667e-01, + 8.676827096691756e-01}, + {-7.448575365180665e-01, -4.840945559720232e-01, -1.850563195192408e-01, + 1.272401577969688e-01, 4.254565070960148e-01, 6.832791838943486e-01, + 8.780325632219984e-01}}, + {// a = 3 + {-9.635398290278467e-01, -8.127250682903714e-01, -5.605071039321651e-01, + -2.372080568631812e-01, 1.182670787543269e-01, 4.632731193770239e-01, + 7.571457423351552e-01}, + {-9.177045455350352e-01, -7.328300530177787e-01, -4.660272611591706e-01, + -1.462023496817571e-01, 1.920542687645395e-01, 5.122885621840089e-01, + 7.806436006674152e-01}, + {-8.676827096691756e-01, -6.576200959973667e-01, -3.821440122181823e-01, + -6.801075022236561e-02, 2.541331370777906e-01, 5.529486988055030e-01, + 7.999546795922177e-01}, + {-8.161152234442209e-01, -5.872564900763582e-01, -3.071626846160234e-01, + 9.092219072621500e-17, 3.071626846160234e-01, 5.872564900763583e-01, + 8.161152234442204e-01}, + {-7.645054103328334e-01, -5.216402272912483e-01, -2.397563306151332e-01, + 5.974952126508076e-02, 3.530300783204262e-01, 6.166124827563498e-01, + 8.298432192306912e-01}}, + {// a = 4 + {-9.666876609340463e-01, -8.284398011290520e-01, -5.954333796292736e-01, + -2.927786050394288e-01, 4.691981399801844e-02, 3.873469549165231e-01, + 6.935171222617036e-01}, + {-9.244614592341160e-01, -7.539854765822848e-01, -5.058029972816601e-01, + -2.041569362298995e-01, 1.215869111005672e-01, 4.399832807349889e-01, + 7.215735195976674e-01}, + {-8.780325632219984e-01, -6.832791838943486e-01, -4.254565070960148e-01, + -1.272401577969688e-01, 1.850563195192408e-01, 4.840945559720232e-01, + 7.448575365180665e-01}, + {-8.298432192306912e-01, -6.166124827563498e-01, -3.530300783204262e-01, + -5.974952126508076e-02, 2.397563306151332e-01, 5.216402272912483e-01, + 7.645054103328334e-01}, + {-7.813155385456068e-01, -5.540100741142812e-01, -2.874349787466332e-01, + -1.330996207987286e-16, 2.874349787466332e-01, 5.540100741142814e-01, + 7.813155385456063e-01}}}; static double _gaussJacobiPt_8[5][5][8] = { - { // a = 0 - {-9.602898564975361e-01, -7.966664774136268e-01, -5.255324099163290e-01, -1.834346424956498e-01, 1.834346424956497e-01, 5.255324099163293e-01, 7.966664774136266e-01, 9.602898564975361e-01}, - {-9.107320894200608e-01, -7.112674859157088e-01, -4.263504857111389e-01, -9.037336960685306e-02, 2.561356708334552e-01, 5.713830412087384e-01, 8.173527842004120e-01, 9.644401697052731e-01}, - {-8.570179299198136e-01, -6.315434071665675e-01, -3.391045436487230e-01, -1.119415636897813e-02, 3.166960170455960e-01, 6.090496630225205e-01, 8.341987650286973e-01, 9.678044808961578e-01}, - {-8.019964845798543e-01, -5.575129853004078e-01, -2.617521999756697e-01, 5.709086240380931e-02, 3.679864968632376e-01, 6.405678993571100e-01, 8.481874257978048e-01, 9.705868801708124e-01}, - {-7.472540512432631e-01, -4.889418958435321e-01, -1.927174022123253e-01, 1.166333515795879e-01, 4.120190857656781e-01, 6.673430840774790e-01, 8.599914321053584e-01, 9.729263957710169e-01} - }, - { // a = 1 - {-9.644401697052731e-01, -8.173527842004120e-01, -5.713830412087384e-01, -2.561356708334552e-01, 9.037336960685306e-02, 4.263504857111389e-01, 7.112674859157088e-01, 9.107320894200608e-01}, - {-9.195339081664592e-01, -7.387738651055049e-01, -4.779249498104446e-01, -1.652789576663870e-01, 1.652789576663869e-01, 4.779249498104450e-01, 7.387738651055050e-01, 9.195339081664591e-01}, - {-8.703573241268080e-01, -6.645470948363091e-01, -3.946644000536821e-01, -8.695007955319405e-02, 2.285115660779311e-01, 5.208520499369652e-01, 7.614560676074159e-01, 9.267518465266287e-01}, - {-8.195233921518306e-01, -5.949138061049166e-01, -3.200375269392208e-01, -1.863585738859826e-02, 2.826720570759457e-01, 5.571701327304996e-01, 7.804894180746164e-01, 9.327789747035043e-01}, - {-7.685354791349837e-01, -5.298348546428772e-01, -2.528017363011083e-01, 4.151229262559467e-02, 3.296204876806622e-01, 5.883145946940839e-01, 7.966938216380223e-01, 9.378880162977485e-01} - }, - { // a = 2 - {-9.678044808961578e-01, -8.341987650286973e-01, -6.090496630225205e-01, -3.166960170455960e-01, 1.119415636897813e-02, 3.391045436487230e-01, 6.315434071665675e-01, 8.570179299198136e-01}, - {-9.267518465266287e-01, -7.614560676074159e-01, -5.208520499369652e-01, -2.285115660779311e-01, 8.695007955319405e-02, 3.946644000536821e-01, 6.645470948363091e-01, 8.703573241268080e-01}, - {-8.814085756174123e-01, -6.920606182568352e-01, -4.414329761085157e-01, -1.516316642932666e-01, 1.516316642932666e-01, 4.414329761085160e-01, 6.920606182568353e-01, 8.814085756174119e-01}, - {-8.341761817227134e-01, -6.263929253413220e-01, -3.695845236865031e-01, -8.393148155168002e-02, 2.075757323546850e-01, 4.813831786277564e-01, 7.153622848580607e-01, 8.907162974140972e-01}, - {-7.864720177123645e-01, -5.645463876430995e-01, -3.043211015125024e-01, -2.382031564025630e-02, 2.564819459809511e-01, 5.159276939944784e-01, 7.353585492129080e-01, 8.986643605926121e-01} - }, - { // a = 3 - {-9.705868801708124e-01, -8.481874257978048e-01, -6.405678993571100e-01, -3.679864968632376e-01, -5.709086240380931e-02, 2.617521999756697e-01, 5.575129853004078e-01, 8.019964845798543e-01}, - {-9.327789747035043e-01, -7.804894180746164e-01, -5.571701327304996e-01, -2.826720570759457e-01, 1.863585738859826e-02, 3.200375269392208e-01, 5.949138061049166e-01, 8.195233921518306e-01}, - {-8.907162974140972e-01, -7.153622848580607e-01, -4.813831786277564e-01, -2.075757323546850e-01, 8.393148155168002e-02, 3.695845236865031e-01, 6.263929253413220e-01, 8.341761817227134e-01}, - {-8.466129750532434e-01, -6.532727259934625e-01, -4.122676659703658e-01, -1.408897472254330e-01, 1.408897472254329e-01, 4.122676659703658e-01, 6.532727259934625e-01, 8.466129750532435e-01}, - {-8.018025475096356e-01, -5.944045793960987e-01, -3.490378929922565e-01, -8.124065226338430e-02, 1.910552607065690e-01, 4.494483070822128e-01, 6.765041657375356e-01, 8.573040255915798e-01} - }, - { // a = 4 - {-9.729263957710169e-01, -8.599914321053584e-01, -6.673430840774790e-01, -4.120190857656781e-01, -1.166333515795879e-01, 1.927174022123253e-01, 4.889418958435321e-01, 7.472540512432631e-01}, - {-9.378880162977485e-01, -7.966938216380223e-01, -5.883145946940839e-01, -3.296204876806622e-01, -4.151229262559467e-02, 2.528017363011083e-01, 5.298348546428772e-01, 7.685354791349837e-01}, - {-8.986643605926121e-01, -7.353585492129080e-01, -5.159276939944784e-01, -2.564819459809511e-01, 2.382031564025630e-02, 3.043211015125024e-01, 5.645463876430995e-01, 7.864720177123645e-01}, - {-8.573040255915798e-01, -6.765041657375356e-01, -4.494483070822128e-01, -1.910552607065690e-01, 8.124065226338430e-02, 3.490378929922565e-01, 5.944045793960987e-01, 8.018025475096356e-01}, - {-8.150613531510142e-01, -6.203761367241419e-01, -3.882476639637909e-01, -1.321495189448358e-01, 1.321495189448357e-01, 3.882476639637909e-01, 6.203761367241423e-01, 8.150613531510140e-01} - } -}; + {// a = 0 + {-9.602898564975361e-01, -7.966664774136268e-01, -5.255324099163290e-01, + -1.834346424956498e-01, 1.834346424956497e-01, 5.255324099163293e-01, + 7.966664774136266e-01, 9.602898564975361e-01}, + {-9.107320894200608e-01, -7.112674859157088e-01, -4.263504857111389e-01, + -9.037336960685306e-02, 2.561356708334552e-01, 5.713830412087384e-01, + 8.173527842004120e-01, 9.644401697052731e-01}, + {-8.570179299198136e-01, -6.315434071665675e-01, -3.391045436487230e-01, + -1.119415636897813e-02, 3.166960170455960e-01, 6.090496630225205e-01, + 8.341987650286973e-01, 9.678044808961578e-01}, + {-8.019964845798543e-01, -5.575129853004078e-01, -2.617521999756697e-01, + 5.709086240380931e-02, 3.679864968632376e-01, 6.405678993571100e-01, + 8.481874257978048e-01, 9.705868801708124e-01}, + {-7.472540512432631e-01, -4.889418958435321e-01, -1.927174022123253e-01, + 1.166333515795879e-01, 4.120190857656781e-01, 6.673430840774790e-01, + 8.599914321053584e-01, 9.729263957710169e-01}}, + {// a = 1 + {-9.644401697052731e-01, -8.173527842004120e-01, -5.713830412087384e-01, + -2.561356708334552e-01, 9.037336960685306e-02, 4.263504857111389e-01, + 7.112674859157088e-01, 9.107320894200608e-01}, + {-9.195339081664592e-01, -7.387738651055049e-01, -4.779249498104446e-01, + -1.652789576663870e-01, 1.652789576663869e-01, 4.779249498104450e-01, + 7.387738651055050e-01, 9.195339081664591e-01}, + {-8.703573241268080e-01, -6.645470948363091e-01, -3.946644000536821e-01, + -8.695007955319405e-02, 2.285115660779311e-01, 5.208520499369652e-01, + 7.614560676074159e-01, 9.267518465266287e-01}, + {-8.195233921518306e-01, -5.949138061049166e-01, -3.200375269392208e-01, + -1.863585738859826e-02, 2.826720570759457e-01, 5.571701327304996e-01, + 7.804894180746164e-01, 9.327789747035043e-01}, + {-7.685354791349837e-01, -5.298348546428772e-01, -2.528017363011083e-01, + 4.151229262559467e-02, 3.296204876806622e-01, 5.883145946940839e-01, + 7.966938216380223e-01, 9.378880162977485e-01}}, + {// a = 2 + {-9.678044808961578e-01, -8.341987650286973e-01, -6.090496630225205e-01, + -3.166960170455960e-01, 1.119415636897813e-02, 3.391045436487230e-01, + 6.315434071665675e-01, 8.570179299198136e-01}, + {-9.267518465266287e-01, -7.614560676074159e-01, -5.208520499369652e-01, + -2.285115660779311e-01, 8.695007955319405e-02, 3.946644000536821e-01, + 6.645470948363091e-01, 8.703573241268080e-01}, + {-8.814085756174123e-01, -6.920606182568352e-01, -4.414329761085157e-01, + -1.516316642932666e-01, 1.516316642932666e-01, 4.414329761085160e-01, + 6.920606182568353e-01, 8.814085756174119e-01}, + {-8.341761817227134e-01, -6.263929253413220e-01, -3.695845236865031e-01, + -8.393148155168002e-02, 2.075757323546850e-01, 4.813831786277564e-01, + 7.153622848580607e-01, 8.907162974140972e-01}, + {-7.864720177123645e-01, -5.645463876430995e-01, -3.043211015125024e-01, + -2.382031564025630e-02, 2.564819459809511e-01, 5.159276939944784e-01, + 7.353585492129080e-01, 8.986643605926121e-01}}, + {// a = 3 + {-9.705868801708124e-01, -8.481874257978048e-01, -6.405678993571100e-01, + -3.679864968632376e-01, -5.709086240380931e-02, 2.617521999756697e-01, + 5.575129853004078e-01, 8.019964845798543e-01}, + {-9.327789747035043e-01, -7.804894180746164e-01, -5.571701327304996e-01, + -2.826720570759457e-01, 1.863585738859826e-02, 3.200375269392208e-01, + 5.949138061049166e-01, 8.195233921518306e-01}, + {-8.907162974140972e-01, -7.153622848580607e-01, -4.813831786277564e-01, + -2.075757323546850e-01, 8.393148155168002e-02, 3.695845236865031e-01, + 6.263929253413220e-01, 8.341761817227134e-01}, + {-8.466129750532434e-01, -6.532727259934625e-01, -4.122676659703658e-01, + -1.408897472254330e-01, 1.408897472254329e-01, 4.122676659703658e-01, + 6.532727259934625e-01, 8.466129750532435e-01}, + {-8.018025475096356e-01, -5.944045793960987e-01, -3.490378929922565e-01, + -8.124065226338430e-02, 1.910552607065690e-01, 4.494483070822128e-01, + 6.765041657375356e-01, 8.573040255915798e-01}}, + {// a = 4 + {-9.729263957710169e-01, -8.599914321053584e-01, -6.673430840774790e-01, + -4.120190857656781e-01, -1.166333515795879e-01, 1.927174022123253e-01, + 4.889418958435321e-01, 7.472540512432631e-01}, + {-9.378880162977485e-01, -7.966938216380223e-01, -5.883145946940839e-01, + -3.296204876806622e-01, -4.151229262559467e-02, 2.528017363011083e-01, + 5.298348546428772e-01, 7.685354791349837e-01}, + {-8.986643605926121e-01, -7.353585492129080e-01, -5.159276939944784e-01, + -2.564819459809511e-01, 2.382031564025630e-02, 3.043211015125024e-01, + 5.645463876430995e-01, 7.864720177123645e-01}, + {-8.573040255915798e-01, -6.765041657375356e-01, -4.494483070822128e-01, + -1.910552607065690e-01, 8.124065226338430e-02, 3.490378929922565e-01, + 5.944045793960987e-01, 8.018025475096356e-01}, + {-8.150613531510142e-01, -6.203761367241419e-01, -3.882476639637909e-01, + -1.321495189448358e-01, 1.321495189448357e-01, 3.882476639637909e-01, + 6.203761367241423e-01, 8.150613531510140e-01}}}; static double _gaussJacobiPt_9[5][5][9] = { - { // a = 0 - {-9.681602395076263e-01, -8.360311073266357e-01, -6.133714327005902e-01, -3.242534234038092e-01, 1.326953380915175e-16, 3.242534234038091e-01, 6.133714327005909e-01, 8.360311073266358e-01, 9.681602395076259e-01}, - {-9.274843742335809e-01, -7.638420424200024e-01, -5.256460303700794e-01, -2.362344693905879e-01, 7.605919783797824e-02, 3.806648401447243e-01, 6.477666876740095e-01, 8.512252205816079e-01, 9.711751807022464e-01}, - {-8.824917284265482e-01, -6.948736840264746e-01, -4.465371434806706e-01, -1.593881127023262e-01, 1.410927092243745e-01, 4.282178233215592e-01, 6.764809664718510e-01, 8.638309408124645e-01, 9.736682288057708e-01}, - {-8.355699007465744e-01, -6.295336343600942e-01, -3.748857803554502e-01, -9.163895512654086e-02, 1.974060716007357e-01, 4.688847536930802e-01, 7.008274627772243e-01, 8.744601050923133e-01, 9.757641631395919e-01}, - {-7.881340969377992e-01, -5.679366071879309e-01, -3.097390830018205e-01, -3.142696039742536e-02, 2.466818663525159e-01, 5.040823074972006e-01, 7.217401049086223e-01, 8.835451997712869e-01, 9.775509053589865e-01} - }, - { // a = 1 - {-9.711751807022464e-01, -8.512252205816079e-01, -6.477666876740095e-01, -3.806648401447243e-01, -7.605919783797824e-02, 2.362344693905879e-01, 5.256460303700794e-01, 7.638420424200024e-01, 9.274843742335809e-01}, - {-9.340014304080591e-01, -7.844834736631441e-01, -5.652353269962053e-01, -2.957581355869396e-01, 1.657705705033761e-16, 2.957581355869396e-01, 5.652353269962049e-01, 7.844834736631443e-01, 9.340014304080594e-01}, - {-8.925384000020725e-01, -7.201109148685505e-01, -4.900440596696391e-01, -2.208314223042547e-01, 6.574716964719765e-02, 3.464843764286125e-01, 5.986396729615450e-01, 8.017835761840958e-01, 9.394414301944946e-01}, - {-8.489741483615989e-01, -6.586135324720294e-01, -4.213302803386361e-01, -1.541595263825746e-01, 1.232164245971234e-01, 3.902723508949431e-01, 6.272215113080293e-01, 8.164975743684556e-01, 9.440514445681056e-01}, - {-8.046361404063783e-01, -6.002072581691080e-01, -3.583609511932042e-01, -9.442184263442212e-02, 1.739175857079093e-01, 4.284797926931285e-01, 6.519657612574546e-01, 8.291678634722249e-01, 9.480082327506564e-01} - }, - { // a = 2 - {-9.736682288057708e-01, -8.638309408124645e-01, -6.764809664718510e-01, -4.282178233215592e-01, -1.410927092243745e-01, 1.593881127023262e-01, 4.465371434806706e-01, 6.948736840264746e-01, 8.824917284265482e-01}, - {-9.394414301944946e-01, -8.017835761840958e-01, -5.986396729615450e-01, -3.464843764286125e-01, -6.574716964719765e-02, 2.208314223042547e-01, 4.900440596696391e-01, 7.201109148685505e-01, 8.925384000020725e-01}, - {-9.009956399852163e-01, -7.414536200077351e-01, -5.270976864620975e-01, -2.736916683369723e-01, 1.906164022956036e-16, 2.736916683369724e-01, 5.270976864620979e-01, 7.414536200077346e-01, 9.009956399852161e-01}, - {-8.603434933842060e-01, -6.834031465006075e-01, -4.612126320788709e-01, -2.083953491716633e-01, 5.794283012626211e-02, 3.196976196385388e-01, 5.590578592345261e-01, 7.597463643479582e-01, 9.082142956141493e-01}, - {-8.187289806673660e-01, -6.279144513982540e-01, -4.004199861805029e-01, -1.494726032171039e-01, 1.094320494310559e-01, 3.601297218463011e-01, 5.869214550374694e-01, 7.756040809473087e-01, 9.144487142010916e-01} - }, - { // a = 3 - {-9.757641631395919e-01, -8.744601050923133e-01, -7.008274627772243e-01, -4.688847536930802e-01, -1.974060716007357e-01, 9.163895512654086e-02, 3.748857803554502e-01, 6.295336343600942e-01, 8.355699007465744e-01}, - {-9.440514445681056e-01, -8.164975743684556e-01, -6.272215113080293e-01, -3.902723508949431e-01, -1.232164245971234e-01, 1.541595263825746e-01, 4.213302803386361e-01, 6.586135324720294e-01, 8.489741483615989e-01}, - {-9.082142956141493e-01, -7.597463643479582e-01, -5.590578592345261e-01, -3.196976196385388e-01, -5.794283012626211e-02, 2.083953491716633e-01, 4.612126320788709e-01, 6.834031465006075e-01, 8.603434933842060e-01}, - {-8.701112990998542e-01, -7.047978089781992e-01, -4.958599884031408e-01, -2.559426475667511e-01, -3.812130663754214e-17, 2.559426475667511e-01, 4.958599884031407e-01, 7.047978089781995e-01, 8.701112990998543e-01}, - {-8.309087961009430e-01, -6.519770894105430e-01, -4.371938639535175e-01, -1.980481288632627e-01, 5.182013173722937e-02, 2.979980392716625e-01, 5.262570717976479e-01, 7.234572361307320e-01, 8.785953993909942e-01} - }, - { // a = 4 - {-9.775509053589865e-01, -8.835451997712869e-01, -7.217401049086223e-01, -5.040823074972006e-01, -2.466818663525159e-01, 3.142696039742536e-02, 3.097390830018205e-01, 5.679366071879309e-01, 7.881340969377992e-01}, - {-9.480082327506564e-01, -8.291678634722249e-01, -6.519657612574546e-01, -4.284797926931285e-01, -1.739175857079093e-01, 9.442184263442212e-02, 3.583609511932042e-01, 6.002072581691080e-01, 8.046361404063783e-01}, - {-9.144487142010916e-01, -7.756040809473087e-01, -5.869214550374694e-01, -3.601297218463011e-01, -1.094320494310559e-01, 1.494726032171039e-01, 4.004199861805029e-01, 6.279144513982540e-01, 8.187289806673660e-01}, - {-8.785953993909942e-01, -7.234572361307320e-01, -5.262570717976479e-01, -2.979980392716625e-01, -5.182013173722937e-02, 1.980481288632627e-01, 4.371938639535175e-01, 6.519770894105430e-01, 8.309087961009430e-01}, - {-8.415432338524422e-01, -6.730793583747041e-01, -4.696405716393736e-01, -2.412610543732914e-01, -1.755982678689780e-17, 2.412610543732915e-01, 4.696405716393739e-01, 6.730793583747037e-01, 8.415432338524426e-01} - } -}; + {// a = 0 + {-9.681602395076263e-01, -8.360311073266357e-01, -6.133714327005902e-01, + -3.242534234038092e-01, 1.326953380915175e-16, 3.242534234038091e-01, + 6.133714327005909e-01, 8.360311073266358e-01, 9.681602395076259e-01}, + {-9.274843742335809e-01, -7.638420424200024e-01, -5.256460303700794e-01, + -2.362344693905879e-01, 7.605919783797824e-02, 3.806648401447243e-01, + 6.477666876740095e-01, 8.512252205816079e-01, 9.711751807022464e-01}, + {-8.824917284265482e-01, -6.948736840264746e-01, -4.465371434806706e-01, + -1.593881127023262e-01, 1.410927092243745e-01, 4.282178233215592e-01, + 6.764809664718510e-01, 8.638309408124645e-01, 9.736682288057708e-01}, + {-8.355699007465744e-01, -6.295336343600942e-01, -3.748857803554502e-01, + -9.163895512654086e-02, 1.974060716007357e-01, 4.688847536930802e-01, + 7.008274627772243e-01, 8.744601050923133e-01, 9.757641631395919e-01}, + {-7.881340969377992e-01, -5.679366071879309e-01, -3.097390830018205e-01, + -3.142696039742536e-02, 2.466818663525159e-01, 5.040823074972006e-01, + 7.217401049086223e-01, 8.835451997712869e-01, 9.775509053589865e-01}}, + {// a = 1 + {-9.711751807022464e-01, -8.512252205816079e-01, -6.477666876740095e-01, + -3.806648401447243e-01, -7.605919783797824e-02, 2.362344693905879e-01, + 5.256460303700794e-01, 7.638420424200024e-01, 9.274843742335809e-01}, + {-9.340014304080591e-01, -7.844834736631441e-01, -5.652353269962053e-01, + -2.957581355869396e-01, 1.657705705033761e-16, 2.957581355869396e-01, + 5.652353269962049e-01, 7.844834736631443e-01, 9.340014304080594e-01}, + {-8.925384000020725e-01, -7.201109148685505e-01, -4.900440596696391e-01, + -2.208314223042547e-01, 6.574716964719765e-02, 3.464843764286125e-01, + 5.986396729615450e-01, 8.017835761840958e-01, 9.394414301944946e-01}, + {-8.489741483615989e-01, -6.586135324720294e-01, -4.213302803386361e-01, + -1.541595263825746e-01, 1.232164245971234e-01, 3.902723508949431e-01, + 6.272215113080293e-01, 8.164975743684556e-01, 9.440514445681056e-01}, + {-8.046361404063783e-01, -6.002072581691080e-01, -3.583609511932042e-01, + -9.442184263442212e-02, 1.739175857079093e-01, 4.284797926931285e-01, + 6.519657612574546e-01, 8.291678634722249e-01, 9.480082327506564e-01}}, + {// a = 2 + {-9.736682288057708e-01, -8.638309408124645e-01, -6.764809664718510e-01, + -4.282178233215592e-01, -1.410927092243745e-01, 1.593881127023262e-01, + 4.465371434806706e-01, 6.948736840264746e-01, 8.824917284265482e-01}, + {-9.394414301944946e-01, -8.017835761840958e-01, -5.986396729615450e-01, + -3.464843764286125e-01, -6.574716964719765e-02, 2.208314223042547e-01, + 4.900440596696391e-01, 7.201109148685505e-01, 8.925384000020725e-01}, + {-9.009956399852163e-01, -7.414536200077351e-01, -5.270976864620975e-01, + -2.736916683369723e-01, 1.906164022956036e-16, 2.736916683369724e-01, + 5.270976864620979e-01, 7.414536200077346e-01, 9.009956399852161e-01}, + {-8.603434933842060e-01, -6.834031465006075e-01, -4.612126320788709e-01, + -2.083953491716633e-01, 5.794283012626211e-02, 3.196976196385388e-01, + 5.590578592345261e-01, 7.597463643479582e-01, 9.082142956141493e-01}, + {-8.187289806673660e-01, -6.279144513982540e-01, -4.004199861805029e-01, + -1.494726032171039e-01, 1.094320494310559e-01, 3.601297218463011e-01, + 5.869214550374694e-01, 7.756040809473087e-01, 9.144487142010916e-01}}, + {// a = 3 + {-9.757641631395919e-01, -8.744601050923133e-01, -7.008274627772243e-01, + -4.688847536930802e-01, -1.974060716007357e-01, 9.163895512654086e-02, + 3.748857803554502e-01, 6.295336343600942e-01, 8.355699007465744e-01}, + {-9.440514445681056e-01, -8.164975743684556e-01, -6.272215113080293e-01, + -3.902723508949431e-01, -1.232164245971234e-01, 1.541595263825746e-01, + 4.213302803386361e-01, 6.586135324720294e-01, 8.489741483615989e-01}, + {-9.082142956141493e-01, -7.597463643479582e-01, -5.590578592345261e-01, + -3.196976196385388e-01, -5.794283012626211e-02, 2.083953491716633e-01, + 4.612126320788709e-01, 6.834031465006075e-01, 8.603434933842060e-01}, + {-8.701112990998542e-01, -7.047978089781992e-01, -4.958599884031408e-01, + -2.559426475667511e-01, -3.812130663754214e-17, 2.559426475667511e-01, + 4.958599884031407e-01, 7.047978089781995e-01, 8.701112990998543e-01}, + {-8.309087961009430e-01, -6.519770894105430e-01, -4.371938639535175e-01, + -1.980481288632627e-01, 5.182013173722937e-02, 2.979980392716625e-01, + 5.262570717976479e-01, 7.234572361307320e-01, 8.785953993909942e-01}}, + {// a = 4 + {-9.775509053589865e-01, -8.835451997712869e-01, -7.217401049086223e-01, + -5.040823074972006e-01, -2.466818663525159e-01, 3.142696039742536e-02, + 3.097390830018205e-01, 5.679366071879309e-01, 7.881340969377992e-01}, + {-9.480082327506564e-01, -8.291678634722249e-01, -6.519657612574546e-01, + -4.284797926931285e-01, -1.739175857079093e-01, 9.442184263442212e-02, + 3.583609511932042e-01, 6.002072581691080e-01, 8.046361404063783e-01}, + {-9.144487142010916e-01, -7.756040809473087e-01, -5.869214550374694e-01, + -3.601297218463011e-01, -1.094320494310559e-01, 1.494726032171039e-01, + 4.004199861805029e-01, 6.279144513982540e-01, 8.187289806673660e-01}, + {-8.785953993909942e-01, -7.234572361307320e-01, -5.262570717976479e-01, + -2.979980392716625e-01, -5.182013173722937e-02, 1.980481288632627e-01, + 4.371938639535175e-01, 6.519770894105430e-01, 8.309087961009430e-01}, + {-8.415432338524422e-01, -6.730793583747041e-01, -4.696405716393736e-01, + -2.412610543732914e-01, -1.755982678689780e-17, 2.412610543732915e-01, + 4.696405716393739e-01, 6.730793583747037e-01, 8.415432338524426e-01}}}; static double _gaussJacobiPt_10[5][5][10] = { - { // a = 0 - {-9.739065285171717e-01, -8.650633666889843e-01, -6.794095682990244e-01, -4.333953941292470e-01, -1.488743389816313e-01, 1.488743389816313e-01, 4.333953941292470e-01, 6.794095682990243e-01, 8.650633666889843e-01, 9.739065285171715e-01}, - {-9.399419356770270e-01, -8.034219755802933e-01, -6.019578420737978e-01, -3.518889233533303e-01, -7.347753143132112e-02, 2.107203062284260e-01, 4.776806479830875e-01, 7.057771007138595e-01, 8.765358562457040e-01, 9.761647731351693e-01}, - {-9.017485852810456e-01, -7.434201491488169e-01, -5.306953590962158e-01, -2.792189773094194e-01, -7.614252829747811e-03, 2.639842991013244e-01, 5.154376077349526e-01, 7.280995318995418e-01, 8.862036989326839e-01, 9.780630950876519e-01}, - {-8.613271088850980e-01, -6.856332660312396e-01, -4.650086703114362e-01, -2.139744802399369e-01, 5.048251851516934e-02, 3.103826659850264e-01, 5.480331483513736e-01, 7.472488397741176e-01, 8.944629538061557e-01, 9.796812251228244e-01}, - {-8.199178362351495e-01, -6.303550954878622e-01, -4.043537027125084e-01, -1.550546219842314e-01, 1.021468439538920e-01, 3.511897906371766e-01, 5.764716294274184e-01, 7.638613323722466e-01, 9.016013710454236e-01, 9.810769556502610e-01} - }, - { // a = 1 - {-9.761647731351693e-01, -8.765358562457040e-01, -7.057771007138595e-01, -4.776806479830875e-01, -2.107203062284260e-01, 7.347753143132112e-02, 3.518889233533303e-01, 6.019578420737978e-01, 8.034219755802933e-01, 9.399419356770270e-01}, - {-9.448992722228821e-01, -8.192793216440065e-01, -6.328761530318606e-01, -3.995309409653489e-01, -1.365529328549276e-01, 1.365529328549271e-01, 3.995309409653491e-01, 6.328761530318606e-01, 8.192793216440070e-01, 9.448992722228819e-01}, - {-9.094983608302611e-01, -7.631088440019468e-01, -5.652332575100812e-01, -3.292354970041083e-01, -7.117334827324186e-02, 1.913747164426928e-01, 4.405195498504024e-01, 6.592831498785090e-01, 8.327552288678481e-01, 9.490992712758392e-01}, - {-8.717988602357006e-01, -7.086348926458873e-01, -5.024174899448293e-01, -2.656314293511225e-01, -1.304427122046542e-02, 2.395117022503627e-01, 4.761841196319480e-01, 6.821096827661082e-01, 8.443513542364890e-01, 9.527034178464308e-01}, - {-8.329595255944936e-01, -6.561998977483142e-01, -4.440277436855557e-01, -2.077966706765967e-01, 3.901170739715901e-02, 2.821452398625555e-01, 5.075151520208082e-01, 7.020443972389159e-01, 8.544370670976112e-01, 9.558302740879103e-01} - }, - { // a = 2 - {-9.780630950876519e-01, -8.862036989326839e-01, -7.280995318995418e-01, -5.154376077349526e-01, -2.639842991013244e-01, 7.614252829747811e-03, 2.792189773094194e-01, 5.306953590962158e-01, 7.434201491488169e-01, 9.017485852810456e-01}, - {-9.490992712758392e-01, -8.327552288678481e-01, -6.592831498785090e-01, -4.405195498504024e-01, -1.913747164426928e-01, 7.117334827324186e-02, 3.292354970041083e-01, 5.652332575100812e-01, 7.631088440019468e-01, 9.094983608302611e-01}, - {-9.161107762068036e-01, -7.799669939442457e-01, -5.949632458480204e-01, -3.726118186991069e-01, -1.268599300863403e-01, 1.268599300863403e-01, 3.726118186991069e-01, 5.949632458480203e-01, 7.799669939442458e-01, 9.161107762068036e-01}, - {-8.807912109437932e-01, -7.284632806046210e-01, -5.348443890505100e-01, -3.107491243455487e-01, -6.909824387191019e-02, 1.761014975938553e-01, 4.106184090051115e-01, 6.208379342182873e-01, 7.945685564256927e-01, 9.218198515734364e-01}, - {-8.442242737922968e-01, -6.786158236511477e-01, -4.786347594797316e-01, -2.541552139983547e-01, -1.704941403243429e-02, 2.199859984581642e-01, 4.442133105112832e-01, 6.435704988651870e-01, 8.073410928638888e-01, 9.267993534862115e-01} - }, - { // a = 3 - {-9.796812251228244e-01, -8.944629538061557e-01, -7.472488397741176e-01, -5.480331483513736e-01, -3.103826659850264e-01, -5.048251851516934e-02, 2.139744802399369e-01, 4.650086703114362e-01, 6.856332660312396e-01, 8.613271088850980e-01}, - {-9.527034178464308e-01, -8.443513542364890e-01, -6.821096827661082e-01, -4.761841196319480e-01, -2.395117022503627e-01, 1.304427122046542e-02, 2.656314293511225e-01, 5.024174899448293e-01, 7.086348926458873e-01, 8.717988602357006e-01}, - {-9.218198515734364e-01, -7.945685564256927e-01, -6.208379342182873e-01, -4.106184090051115e-01, -1.761014975938553e-01, 6.909824387191019e-02, 3.107491243455487e-01, 5.348443890505100e-01, 7.284632806046210e-01, 8.807912109437932e-01}, - {-8.885985593332147e-01, -7.457393868160163e-01, -5.632398897449369e-01, -3.505293497675201e-01, -1.189763373695647e-01, 1.189763373695645e-01, 3.505293497675201e-01, 5.632398897449366e-01, 7.457393868160164e-01, 8.885985593332155e-01}, - {-8.540547736606900e-01, -6.982518869219184e-01, -5.091080491652173e-01, -2.952602241318521e-01, -6.721510331152565e-02, 1.636772801427245e-01, 3.858878375165101e-01, 5.883230379225718e-01, 7.609305533813385e-01, 8.954416985984290e-01} - }, - { // a = 4 - {-9.810769556502610e-01, -9.016013710454236e-01, -7.638613323722466e-01, -5.764716294274184e-01, -3.511897906371766e-01, -1.021468439538920e-01, 1.550546219842314e-01, 4.043537027125084e-01, 6.303550954878622e-01, 8.199178362351495e-01}, - {-9.558302740879103e-01, -8.544370670976112e-01, -7.020443972389159e-01, -5.075151520208082e-01, -2.821452398625555e-01, -3.901170739715901e-02, 2.077966706765967e-01, 4.440277436855557e-01, 6.561998977483142e-01, 8.329595255944936e-01}, - {-9.267993534862115e-01, -8.073410928638888e-01, -6.435704988651870e-01, -4.442133105112832e-01, -2.199859984581642e-01, 1.704941403243429e-02, 2.541552139983547e-01, 4.786347594797316e-01, 6.786158236511477e-01, 8.442242737922968e-01}, - {-8.954416985984290e-01, -7.609305533813385e-01, -5.883230379225718e-01, -3.858878375165101e-01, -1.636772801427245e-01, 6.721510331152565e-02, 2.952602241318521e-01, 5.091080491652173e-01, 6.982518869219184e-01, 8.540547736606900e-01}, - {-8.627103339975803e-01, -7.156009978402934e-01, -5.361601043856260e-01, -3.319805614805308e-01, -1.124011006827486e-01, 1.124011006827486e-01, 3.319805614805308e-01, 5.361601043856263e-01, 7.156009978402929e-01, 8.627103339975802e-01} - } -}; + {// a = 0 + {-9.739065285171717e-01, -8.650633666889843e-01, -6.794095682990244e-01, + -4.333953941292470e-01, -1.488743389816313e-01, 1.488743389816313e-01, + 4.333953941292470e-01, 6.794095682990243e-01, 8.650633666889843e-01, + 9.739065285171715e-01}, + {-9.399419356770270e-01, -8.034219755802933e-01, -6.019578420737978e-01, + -3.518889233533303e-01, -7.347753143132112e-02, 2.107203062284260e-01, + 4.776806479830875e-01, 7.057771007138595e-01, 8.765358562457040e-01, + 9.761647731351693e-01}, + {-9.017485852810456e-01, -7.434201491488169e-01, -5.306953590962158e-01, + -2.792189773094194e-01, -7.614252829747811e-03, 2.639842991013244e-01, + 5.154376077349526e-01, 7.280995318995418e-01, 8.862036989326839e-01, + 9.780630950876519e-01}, + {-8.613271088850980e-01, -6.856332660312396e-01, -4.650086703114362e-01, + -2.139744802399369e-01, 5.048251851516934e-02, 3.103826659850264e-01, + 5.480331483513736e-01, 7.472488397741176e-01, 8.944629538061557e-01, + 9.796812251228244e-01}, + {-8.199178362351495e-01, -6.303550954878622e-01, -4.043537027125084e-01, + -1.550546219842314e-01, 1.021468439538920e-01, 3.511897906371766e-01, + 5.764716294274184e-01, 7.638613323722466e-01, 9.016013710454236e-01, + 9.810769556502610e-01}}, + {// a = 1 + {-9.761647731351693e-01, -8.765358562457040e-01, -7.057771007138595e-01, + -4.776806479830875e-01, -2.107203062284260e-01, 7.347753143132112e-02, + 3.518889233533303e-01, 6.019578420737978e-01, 8.034219755802933e-01, + 9.399419356770270e-01}, + {-9.448992722228821e-01, -8.192793216440065e-01, -6.328761530318606e-01, + -3.995309409653489e-01, -1.365529328549276e-01, 1.365529328549271e-01, + 3.995309409653491e-01, 6.328761530318606e-01, 8.192793216440070e-01, + 9.448992722228819e-01}, + {-9.094983608302611e-01, -7.631088440019468e-01, -5.652332575100812e-01, + -3.292354970041083e-01, -7.117334827324186e-02, 1.913747164426928e-01, + 4.405195498504024e-01, 6.592831498785090e-01, 8.327552288678481e-01, + 9.490992712758392e-01}, + {-8.717988602357006e-01, -7.086348926458873e-01, -5.024174899448293e-01, + -2.656314293511225e-01, -1.304427122046542e-02, 2.395117022503627e-01, + 4.761841196319480e-01, 6.821096827661082e-01, 8.443513542364890e-01, + 9.527034178464308e-01}, + {-8.329595255944936e-01, -6.561998977483142e-01, -4.440277436855557e-01, + -2.077966706765967e-01, 3.901170739715901e-02, 2.821452398625555e-01, + 5.075151520208082e-01, 7.020443972389159e-01, 8.544370670976112e-01, + 9.558302740879103e-01}}, + {// a = 2 + {-9.780630950876519e-01, -8.862036989326839e-01, -7.280995318995418e-01, + -5.154376077349526e-01, -2.639842991013244e-01, 7.614252829747811e-03, + 2.792189773094194e-01, 5.306953590962158e-01, 7.434201491488169e-01, + 9.017485852810456e-01}, + {-9.490992712758392e-01, -8.327552288678481e-01, -6.592831498785090e-01, + -4.405195498504024e-01, -1.913747164426928e-01, 7.117334827324186e-02, + 3.292354970041083e-01, 5.652332575100812e-01, 7.631088440019468e-01, + 9.094983608302611e-01}, + {-9.161107762068036e-01, -7.799669939442457e-01, -5.949632458480204e-01, + -3.726118186991069e-01, -1.268599300863403e-01, 1.268599300863403e-01, + 3.726118186991069e-01, 5.949632458480203e-01, 7.799669939442458e-01, + 9.161107762068036e-01}, + {-8.807912109437932e-01, -7.284632806046210e-01, -5.348443890505100e-01, + -3.107491243455487e-01, -6.909824387191019e-02, 1.761014975938553e-01, + 4.106184090051115e-01, 6.208379342182873e-01, 7.945685564256927e-01, + 9.218198515734364e-01}, + {-8.442242737922968e-01, -6.786158236511477e-01, -4.786347594797316e-01, + -2.541552139983547e-01, -1.704941403243429e-02, 2.199859984581642e-01, + 4.442133105112832e-01, 6.435704988651870e-01, 8.073410928638888e-01, + 9.267993534862115e-01}}, + {// a = 3 + {-9.796812251228244e-01, -8.944629538061557e-01, -7.472488397741176e-01, + -5.480331483513736e-01, -3.103826659850264e-01, -5.048251851516934e-02, + 2.139744802399369e-01, 4.650086703114362e-01, 6.856332660312396e-01, + 8.613271088850980e-01}, + {-9.527034178464308e-01, -8.443513542364890e-01, -6.821096827661082e-01, + -4.761841196319480e-01, -2.395117022503627e-01, 1.304427122046542e-02, + 2.656314293511225e-01, 5.024174899448293e-01, 7.086348926458873e-01, + 8.717988602357006e-01}, + {-9.218198515734364e-01, -7.945685564256927e-01, -6.208379342182873e-01, + -4.106184090051115e-01, -1.761014975938553e-01, 6.909824387191019e-02, + 3.107491243455487e-01, 5.348443890505100e-01, 7.284632806046210e-01, + 8.807912109437932e-01}, + {-8.885985593332147e-01, -7.457393868160163e-01, -5.632398897449369e-01, + -3.505293497675201e-01, -1.189763373695647e-01, 1.189763373695645e-01, + 3.505293497675201e-01, 5.632398897449366e-01, 7.457393868160164e-01, + 8.885985593332155e-01}, + {-8.540547736606900e-01, -6.982518869219184e-01, -5.091080491652173e-01, + -2.952602241318521e-01, -6.721510331152565e-02, 1.636772801427245e-01, + 3.858878375165101e-01, 5.883230379225718e-01, 7.609305533813385e-01, + 8.954416985984290e-01}}, + {// a = 4 + {-9.810769556502610e-01, -9.016013710454236e-01, -7.638613323722466e-01, + -5.764716294274184e-01, -3.511897906371766e-01, -1.021468439538920e-01, + 1.550546219842314e-01, 4.043537027125084e-01, 6.303550954878622e-01, + 8.199178362351495e-01}, + {-9.558302740879103e-01, -8.544370670976112e-01, -7.020443972389159e-01, + -5.075151520208082e-01, -2.821452398625555e-01, -3.901170739715901e-02, + 2.077966706765967e-01, 4.440277436855557e-01, 6.561998977483142e-01, + 8.329595255944936e-01}, + {-9.267993534862115e-01, -8.073410928638888e-01, -6.435704988651870e-01, + -4.442133105112832e-01, -2.199859984581642e-01, 1.704941403243429e-02, + 2.541552139983547e-01, 4.786347594797316e-01, 6.786158236511477e-01, + 8.442242737922968e-01}, + {-8.954416985984290e-01, -7.609305533813385e-01, -5.883230379225718e-01, + -3.858878375165101e-01, -1.636772801427245e-01, 6.721510331152565e-02, + 2.952602241318521e-01, 5.091080491652173e-01, 6.982518869219184e-01, + 8.540547736606900e-01}, + {-8.627103339975803e-01, -7.156009978402934e-01, -5.361601043856260e-01, + -3.319805614805308e-01, -1.124011006827486e-01, 1.124011006827486e-01, + 3.319805614805308e-01, 5.361601043856263e-01, 7.156009978402929e-01, + 8.627103339975802e-01}}}; static double _gaussJacobiPt_11[5][5][11] = { - { // a = 0 - {-9.782286581460572e-01, -8.870625997680954e-01, -7.301520055740494e-01, -5.190961292068116e-01, -2.695431559523448e-01, 8.990116993431148e-17, 2.695431559523452e-01, 5.190961292068121e-01, 7.301520055740492e-01, 8.870625997680951e-01, 9.782286581460565e-01}, - {-9.494527592049596e-01, -8.339167731051895e-01, -6.616497992456370e-01, -4.444065697819357e-01, -1.969945595342782e-01, 6.372477382083178e-02, 3.199836841706696e-01, 5.543187859123245e-01, 7.507615497111143e-01, 8.959290977456387e-01, 9.799634390766393e-01}, - {-9.166502875732961e-01, -7.813821987087842e-01, -5.975687171818291e-01, -3.766484797259134e-01, -1.324796783091365e-01, 1.196032002822751e-01, 3.637640961875316e-01, 5.846633168058799e-01, 7.684227467412095e-01, 9.035006158114272e-01, 9.814420523373022e-01}, - {-8.815050981582672e-01, -7.300895420693674e-01, -5.376306582815262e-01, -3.148786315648594e-01, -7.467746164964285e-02, 1.690488271761821e-01, 4.021513598077393e-01, 6.110911177561568e-01, 7.837304284250708e-01, 9.100423014430291e-01, 9.827173571154848e-01}, - {-8.450970699006651e-01, -6.804166869434627e-01, -4.815566464700486e-01, -2.583360920470064e-01, -2.256130427059169e-02, 2.131411465156455e-01, 4.361026703374636e-01, 6.343232294876886e-01, 7.971284747718846e-01, 9.157513698038646e-01, 9.838286010229199e-01} - }, - { // a = 1 - {-9.799634390766393e-01, -8.959290977456387e-01, -7.507615497111143e-01, -5.543187859123245e-01, -3.199836841706696e-01, -6.372477382083178e-02, 1.969945595342782e-01, 4.444065697819357e-01, 6.616497992456370e-01, 8.339167731051895e-01, 9.494527592049596e-01}, - {-9.533098466421640e-01, -8.463475646518723e-01, -6.861884690817576e-01, -4.829098210913363e-01, -2.492869301062400e-01, -1.108639036007883e-16, 2.492869301062400e-01, 4.829098210913361e-01, 6.861884690817573e-01, 8.463475646518727e-01, 9.533098466421642e-01}, - {-9.227507501505473e-01, -7.970153602414491e-01, -6.253560933791470e-01, -4.176466650618614e-01, -1.859372436416418e-01, 5.631285370564750e-02, 2.950276358082067e-01, 5.163349586454838e-01, 7.073732767467203e-01, 8.570382107575023e-01, 9.566191768110855e-01}, - {-8.898367245100568e-01, -7.485662540163880e-01, -5.680981744017178e-01, -3.577590638131492e-01, -1.287946644776952e-01, 1.064841567596346e-01, 3.354075673360336e-01, 5.456411031715711e-01, 7.258542657054387e-01, 8.663317891939751e-01, 9.594898452062001e-01}, - {-8.555756571796961e-01, -7.013974542586021e-01, -5.142279489925600e-01, -3.026160560151034e-01, -7.696225083294500e-02, 1.514958061896425e-01, 3.713372609314780e-01, 5.715561659012299e-01, 7.421222103097419e-01, 8.744863989765731e-01, 9.620037471924632e-01} - }, - { // a = 2 - {-9.814420523373022e-01, -9.035006158114272e-01, -7.684227467412095e-01, -5.846633168058799e-01, -3.637640961875316e-01, -1.196032002822751e-01, 1.324796783091365e-01, 3.766484797259134e-01, 5.975687171818291e-01, 7.813821987087842e-01, 9.166502875732961e-01}, - {-9.566191768110855e-01, -8.570382107575023e-01, -7.073732767467203e-01, -5.163349586454838e-01, -2.950276358082067e-01, -5.631285370564750e-02, 1.859372436416418e-01, 4.176466650618614e-01, 6.253560933791470e-01, 7.970153602414491e-01, 9.227507501505473e-01}, - {-9.280164504291800e-01, -8.105462166425115e-01, -6.495055391494071e-01, -4.534807213176902e-01, -2.330195022455460e-01, -8.622673226532133e-17, 2.330195022455463e-01, 4.534807213176898e-01, 6.495055391494077e-01, 8.105462166425111e-01, 9.280164504291800e-01}, - {-8.970679126941687e-01, -7.646511545017334e-01, -5.947359989878861e-01, -3.954678201717901e-01, -1.767513641082236e-01, 5.047694502127038e-02, 2.748372403061862e-01, 4.850881398161955e-01, 6.706962723986961e-01, 8.223748504646330e-01, 9.326082098642275e-01}, - {-8.647161717639213e-01, -7.197589131798050e-01, -5.429481353816696e-01, -3.417707669419396e-01, -1.254372559510012e-01, 9.600953090830763e-02, 3.122485942369511e-01, 5.131878133741616e-01, 6.894463729644811e-01, 8.328052835847137e-01, 9.366479338640069e-01} - }, - { // a = 3 - {-9.827173571154848e-01, -9.100423014430291e-01, -7.837304284250708e-01, -6.110911177561568e-01, -4.021513598077393e-01, -1.690488271761821e-01, 7.467746164964285e-02, 3.148786315648594e-01, 5.376306582815262e-01, 7.300895420693674e-01, 8.815050981582672e-01}, - {-9.594898452062001e-01, -8.663317891939751e-01, -7.258542657054387e-01, -5.456411031715711e-01, -3.354075673360336e-01, -1.064841567596346e-01, 1.287946644776952e-01, 3.577590638131492e-01, 5.680981744017178e-01, 7.485662540163880e-01, 8.898367245100568e-01}, - {-9.326082098642275e-01, -8.223748504646330e-01, -6.706962723986961e-01, -4.850881398161955e-01, -2.748372403061862e-01, -5.047694502127038e-02, 1.767513641082236e-01, 3.954678201717901e-01, 5.947359989878861e-01, 7.646511545017334e-01, 8.970679126941687e-01}, - {-9.034041403870294e-01, -7.787845784779767e-01, -6.182345728494725e-01, -4.289096757953184e-01, -2.195793237904602e-01, 1.880251561444324e-16, 2.195793237904604e-01, 4.289096757953185e-01, 6.182345728494730e-01, 7.787845784779760e-01, 9.034041403870291e-01}, - {-8.727612048660429e-01, -7.359684858680122e-01, -5.684065507932738e-01, -3.766663677964620e-01, -1.689427615236661e-01, 4.575611394302053e-02, 2.580828632077494e-01, 4.587847623799057e-01, 6.391253205952770e-01, 7.913041329664285e-01, 9.090025225826618e-01} - }, - { // a = 4 - {-9.838286010229199e-01, -9.157513698038646e-01, -7.971284747718846e-01, -6.343232294876886e-01, -4.361026703374636e-01, -2.131411465156455e-01, 2.256130427059169e-02, 2.583360920470064e-01, 4.815566464700486e-01, 6.804166869434627e-01, 8.450970699006651e-01}, - {-9.620037471924632e-01, -8.744863989765731e-01, -7.421222103097419e-01, -5.715561659012299e-01, -3.713372609314780e-01, -1.514958061896425e-01, 7.696225083294500e-02, 3.026160560151034e-01, 5.142279489925600e-01, 7.013974542586021e-01, 8.555756571796961e-01}, - {-9.366479338640069e-01, -8.328052835847137e-01, -6.894463729644811e-01, -5.131878133741616e-01, -3.122485942369511e-01, -9.600953090830763e-02, 1.254372559510012e-01, 3.417707669419396e-01, 5.429481353816696e-01, 7.197589131798050e-01, 8.647161717639213e-01}, - {-9.090025225826618e-01, -7.913041329664285e-01, -6.391253205952770e-01, -4.587847623799057e-01, -2.580828632077494e-01, -4.575611394302053e-02, 1.689427615236661e-01, 3.766663677964620e-01, 5.684065507932738e-01, 7.359684858680122e-01, 8.727612048660429e-01}, - {-8.798977019228941e-01, -7.503874112500294e-01, -5.911380520239878e-01, -4.079784824393289e-01, -2.082302875232295e-01, 5.390152688331639e-17, 2.082302875232296e-01, 4.079784824393290e-01, 5.911380520239875e-01, 7.503874112500289e-01, 8.798977019228944e-01} - } -}; + {// a = 0 + {-9.782286581460572e-01, -8.870625997680954e-01, -7.301520055740494e-01, + -5.190961292068116e-01, -2.695431559523448e-01, 8.990116993431148e-17, + 2.695431559523452e-01, 5.190961292068121e-01, 7.301520055740492e-01, + 8.870625997680951e-01, 9.782286581460565e-01}, + {-9.494527592049596e-01, -8.339167731051895e-01, -6.616497992456370e-01, + -4.444065697819357e-01, -1.969945595342782e-01, 6.372477382083178e-02, + 3.199836841706696e-01, 5.543187859123245e-01, 7.507615497111143e-01, + 8.959290977456387e-01, 9.799634390766393e-01}, + {-9.166502875732961e-01, -7.813821987087842e-01, -5.975687171818291e-01, + -3.766484797259134e-01, -1.324796783091365e-01, 1.196032002822751e-01, + 3.637640961875316e-01, 5.846633168058799e-01, 7.684227467412095e-01, + 9.035006158114272e-01, 9.814420523373022e-01}, + {-8.815050981582672e-01, -7.300895420693674e-01, -5.376306582815262e-01, + -3.148786315648594e-01, -7.467746164964285e-02, 1.690488271761821e-01, + 4.021513598077393e-01, 6.110911177561568e-01, 7.837304284250708e-01, + 9.100423014430291e-01, 9.827173571154848e-01}, + {-8.450970699006651e-01, -6.804166869434627e-01, -4.815566464700486e-01, + -2.583360920470064e-01, -2.256130427059169e-02, 2.131411465156455e-01, + 4.361026703374636e-01, 6.343232294876886e-01, 7.971284747718846e-01, + 9.157513698038646e-01, 9.838286010229199e-01}}, + {// a = 1 + {-9.799634390766393e-01, -8.959290977456387e-01, -7.507615497111143e-01, + -5.543187859123245e-01, -3.199836841706696e-01, -6.372477382083178e-02, + 1.969945595342782e-01, 4.444065697819357e-01, 6.616497992456370e-01, + 8.339167731051895e-01, 9.494527592049596e-01}, + {-9.533098466421640e-01, -8.463475646518723e-01, -6.861884690817576e-01, + -4.829098210913363e-01, -2.492869301062400e-01, -1.108639036007883e-16, + 2.492869301062400e-01, 4.829098210913361e-01, 6.861884690817573e-01, + 8.463475646518727e-01, 9.533098466421642e-01}, + {-9.227507501505473e-01, -7.970153602414491e-01, -6.253560933791470e-01, + -4.176466650618614e-01, -1.859372436416418e-01, 5.631285370564750e-02, + 2.950276358082067e-01, 5.163349586454838e-01, 7.073732767467203e-01, + 8.570382107575023e-01, 9.566191768110855e-01}, + {-8.898367245100568e-01, -7.485662540163880e-01, -5.680981744017178e-01, + -3.577590638131492e-01, -1.287946644776952e-01, 1.064841567596346e-01, + 3.354075673360336e-01, 5.456411031715711e-01, 7.258542657054387e-01, + 8.663317891939751e-01, 9.594898452062001e-01}, + {-8.555756571796961e-01, -7.013974542586021e-01, -5.142279489925600e-01, + -3.026160560151034e-01, -7.696225083294500e-02, 1.514958061896425e-01, + 3.713372609314780e-01, 5.715561659012299e-01, 7.421222103097419e-01, + 8.744863989765731e-01, 9.620037471924632e-01}}, + {// a = 2 + {-9.814420523373022e-01, -9.035006158114272e-01, -7.684227467412095e-01, + -5.846633168058799e-01, -3.637640961875316e-01, -1.196032002822751e-01, + 1.324796783091365e-01, 3.766484797259134e-01, 5.975687171818291e-01, + 7.813821987087842e-01, 9.166502875732961e-01}, + {-9.566191768110855e-01, -8.570382107575023e-01, -7.073732767467203e-01, + -5.163349586454838e-01, -2.950276358082067e-01, -5.631285370564750e-02, + 1.859372436416418e-01, 4.176466650618614e-01, 6.253560933791470e-01, + 7.970153602414491e-01, 9.227507501505473e-01}, + {-9.280164504291800e-01, -8.105462166425115e-01, -6.495055391494071e-01, + -4.534807213176902e-01, -2.330195022455460e-01, -8.622673226532133e-17, + 2.330195022455463e-01, 4.534807213176898e-01, 6.495055391494077e-01, + 8.105462166425111e-01, 9.280164504291800e-01}, + {-8.970679126941687e-01, -7.646511545017334e-01, -5.947359989878861e-01, + -3.954678201717901e-01, -1.767513641082236e-01, 5.047694502127038e-02, + 2.748372403061862e-01, 4.850881398161955e-01, 6.706962723986961e-01, + 8.223748504646330e-01, 9.326082098642275e-01}, + {-8.647161717639213e-01, -7.197589131798050e-01, -5.429481353816696e-01, + -3.417707669419396e-01, -1.254372559510012e-01, 9.600953090830763e-02, + 3.122485942369511e-01, 5.131878133741616e-01, 6.894463729644811e-01, + 8.328052835847137e-01, 9.366479338640069e-01}}, + {// a = 3 + {-9.827173571154848e-01, -9.100423014430291e-01, -7.837304284250708e-01, + -6.110911177561568e-01, -4.021513598077393e-01, -1.690488271761821e-01, + 7.467746164964285e-02, 3.148786315648594e-01, 5.376306582815262e-01, + 7.300895420693674e-01, 8.815050981582672e-01}, + {-9.594898452062001e-01, -8.663317891939751e-01, -7.258542657054387e-01, + -5.456411031715711e-01, -3.354075673360336e-01, -1.064841567596346e-01, + 1.287946644776952e-01, 3.577590638131492e-01, 5.680981744017178e-01, + 7.485662540163880e-01, 8.898367245100568e-01}, + {-9.326082098642275e-01, -8.223748504646330e-01, -6.706962723986961e-01, + -4.850881398161955e-01, -2.748372403061862e-01, -5.047694502127038e-02, + 1.767513641082236e-01, 3.954678201717901e-01, 5.947359989878861e-01, + 7.646511545017334e-01, 8.970679126941687e-01}, + {-9.034041403870294e-01, -7.787845784779767e-01, -6.182345728494725e-01, + -4.289096757953184e-01, -2.195793237904602e-01, 1.880251561444324e-16, + 2.195793237904604e-01, 4.289096757953185e-01, 6.182345728494730e-01, + 7.787845784779760e-01, 9.034041403870291e-01}, + {-8.727612048660429e-01, -7.359684858680122e-01, -5.684065507932738e-01, + -3.766663677964620e-01, -1.689427615236661e-01, 4.575611394302053e-02, + 2.580828632077494e-01, 4.587847623799057e-01, 6.391253205952770e-01, + 7.913041329664285e-01, 9.090025225826618e-01}}, + {// a = 4 + {-9.838286010229199e-01, -9.157513698038646e-01, -7.971284747718846e-01, + -6.343232294876886e-01, -4.361026703374636e-01, -2.131411465156455e-01, + 2.256130427059169e-02, 2.583360920470064e-01, 4.815566464700486e-01, + 6.804166869434627e-01, 8.450970699006651e-01}, + {-9.620037471924632e-01, -8.744863989765731e-01, -7.421222103097419e-01, + -5.715561659012299e-01, -3.713372609314780e-01, -1.514958061896425e-01, + 7.696225083294500e-02, 3.026160560151034e-01, 5.142279489925600e-01, + 7.013974542586021e-01, 8.555756571796961e-01}, + {-9.366479338640069e-01, -8.328052835847137e-01, -6.894463729644811e-01, + -5.131878133741616e-01, -3.122485942369511e-01, -9.600953090830763e-02, + 1.254372559510012e-01, 3.417707669419396e-01, 5.429481353816696e-01, + 7.197589131798050e-01, 8.647161717639213e-01}, + {-9.090025225826618e-01, -7.913041329664285e-01, -6.391253205952770e-01, + -4.587847623799057e-01, -2.580828632077494e-01, -4.575611394302053e-02, + 1.689427615236661e-01, 3.766663677964620e-01, 5.684065507932738e-01, + 7.359684858680122e-01, 8.727612048660429e-01}, + {-8.798977019228941e-01, -7.503874112500294e-01, -5.911380520239878e-01, + -4.079784824393289e-01, -2.082302875232295e-01, 5.390152688331639e-17, + 2.082302875232296e-01, 4.079784824393290e-01, 5.911380520239875e-01, + 7.503874112500289e-01, 8.798977019228944e-01}}}; static double _gaussJacobiPt_12[5][5][12] = { - { // a = 0 - {-9.815606342467196e-01, -9.041172563704754e-01, -7.699026741943048e-01, -5.873179542866176e-01, -3.678314989981800e-01, -1.252334085114694e-01, 1.252334085114691e-01, 3.678314989981800e-01, 5.873179542866177e-01, 7.699026741943049e-01, 9.041172563704749e-01, 9.815606342467198e-01}, - {-9.568758736682992e-01, -8.578842025288225e-01, -7.091050875298717e-01, -5.191977790504539e-01, -2.992013005545100e-01, -6.190169862563523e-02, 1.789098375970846e-01, 4.092382314748395e-01, 6.156978909402920e-01, 7.862910182330464e-01, 9.111070736891850e-01, 9.829218900231450e-01}, - {-9.284130705853431e-01, -8.115901470890873e-01, -6.514370284295737e-01, -4.564929059061454e-01, -2.372477269169123e-01, -5.514720898064603e-03, 2.262159800046200e-01, 4.454530844013695e-01, 6.403784218951537e-01, 8.004847489147718e-01, 9.171443790914112e-01, 9.840959085947233e-01}, - {-8.975985245538983e-01, -7.658644530411951e-01, -5.968254805124207e-01, -3.985851767850569e-01, -1.809975303605268e-01, 4.505689466379486e-02, 2.682559251563394e-01, 4.774140753925782e-01, 6.620471364134675e-01, 8.128997139816979e-01, 9.224119060591074e-01, 9.851188469194457e-01}, - {-8.653713567789760e-01, -7.211162307744255e-01, -5.451620543220070e-01, -3.449596695560612e-01, -1.296751980287479e-01, 9.069665054560958e-02, 3.058839569922088e-01, 5.058415548115412e-01, 6.812292401370837e-01, 8.238523505345596e-01, 9.270483578727584e-01, 9.860181128521710e-01} - }, - { // a = 1 - {-9.829218900231450e-01, -9.111070736891850e-01, -7.862910182330464e-01, -6.156978909402920e-01, -4.092382314748395e-01, -1.789098375970846e-01, 6.190169862563523e-02, 2.992013005545100e-01, 5.191977790504539e-01, 7.091050875298717e-01, 8.578842025288225e-01, 9.568758736682992e-01}, - {-9.599350452672614e-01, -8.678010538303474e-01, -7.288685990913262e-01, -5.506394029286470e-01, -3.427240133427128e-01, -1.163318688837038e-01, 1.163318688837040e-01, 3.427240133427129e-01, 5.506394029286469e-01, 7.288685990913261e-01, 8.678010538303473e-01, 9.599350452672608e-01}, - {-9.332995079627837e-01, -8.241972989426256e-01, -6.740760996874169e-01, -4.903756525854291e-01, -2.822893850278608e-01, -6.024581279546619e-02, 1.646232114144044e-01, 3.810428592335757e-01, 5.781613306985280e-01, 7.460940443267943e-01, 8.764183644350997e-01, 9.625883913376251e-01}, - {-9.043331546184969e-01, -7.809126253419221e-01, -6.219083835463991e-01, -4.344082673160836e-01, -2.270991419035120e-01, -9.646622564773525e-03, 2.077935066056401e-01, 4.150599242580991e-01, 6.024641833517987e-01, 7.612448577054650e-01, 8.839768468276173e-01, 9.649117336854240e-01}, - {-8.739130405699720e-01, -7.383592484595911e-01, -5.723160028857331e-01, -3.823156444185185e-01, -1.764804636187008e-01, 3.626016647351250e-02, 2.466384345791495e-01, 4.454751347453242e-01, 6.240886140472163e-01, 7.746772510739069e-01, 8.906610149309094e-01, 9.669630944473241e-01} - }, - { // a = 2 - {-9.840959085947233e-01, -9.171443790914112e-01, -8.004847489147718e-01, -6.403784218951537e-01, -4.454530844013695e-01, -2.262159800046200e-01, 5.514720898064603e-03, 2.372477269169123e-01, 4.564929059061454e-01, 6.514370284295737e-01, 8.115901470890873e-01, 9.284130705853431e-01}, - {-9.625883913376251e-01, -8.764183644350997e-01, -7.460940443267943e-01, -5.781613306985280e-01, -3.810428592335757e-01, -1.646232114144044e-01, 6.024581279546619e-02, 2.822893850278608e-01, 4.903756525854291e-01, 6.740760996874169e-01, 8.241972989426256e-01, 9.332995079627837e-01}, - {-9.375597349081080e-01, -8.352126561026334e-01, -6.939208718647533e-01, -5.202087732305216e-01, -3.221818845733797e-01, -1.090939783245157e-01, 1.090939783245159e-01, 3.221818845733799e-01, 5.202087732305219e-01, 6.939208718647533e-01, 8.352126561026330e-01, 9.375597349081080e-01}, - {-9.102327624610815e-01, -7.941268989273503e-01, -6.440098121005434e-01, -4.661176002087244e-01, -2.681497149953622e-01, -5.873195293835499e-02, 1.529949068722340e-01, 3.577839774894385e-01, 5.466901395218944e-01, 7.114641560912678e-01, 8.449215035762696e-01, 9.413071615285881e-01}, - {-8.814285988340554e-01, -7.535707100992809e-01, -5.963560239063559e-01, -4.155417840165797e-01, -2.183604632007295e-01, -1.282219763078040e-02, 1.926867198241465e-01, 3.897680125529990e-01, 5.703631554143442e-01, 7.270881350352043e-01, 8.535444412555850e-01, 9.446293136055027e-01} - }, - { // a = 3 - {-9.851188469194457e-01, -9.224119060591074e-01, -8.128997139816979e-01, -6.620471364134675e-01, -4.774140753925782e-01, -2.682559251563394e-01, -4.505689466379486e-02, 1.809975303605268e-01, 3.985851767850569e-01, 5.968254805124207e-01, 7.658644530411951e-01, 8.975985245538983e-01}, - {-9.649117336854240e-01, -8.839768468276173e-01, -7.612448577054650e-01, -6.024641833517987e-01, -4.150599242580991e-01, -2.077935066056401e-01, 9.646622564773525e-03, 2.270991419035120e-01, 4.344082673160836e-01, 6.219083835463991e-01, 7.809126253419221e-01, 9.043331546184969e-01}, - {-9.413071615285881e-01, -8.449215035762696e-01, -7.114641560912678e-01, -5.466901395218944e-01, -3.577839774894385e-01, -1.529949068722340e-01, 5.873195293835499e-02, 2.681497149953622e-01, 4.661176002087244e-01, 6.440098121005434e-01, 7.941268989273503e-01, 9.102327624610815e-01}, - {-9.154441928381977e-01, -8.058259018763845e-01, -6.636387128706127e-01, -4.943982121529223e-01, -3.049616623290851e-01, -1.030585549013792e-01, 1.030585549013790e-01, 3.049616623290852e-01, 4.943982121529225e-01, 6.636387128706129e-01, 8.058259018763847e-01, 9.154441928381978e-01}, - {-8.880935320208031e-01, -7.670933934819978e-01, -6.177975944271482e-01, -4.453039951958354e-01, -2.560808727544255e-01, -5.734006950825194e-02, 1.433097819098507e-01, 3.381761358407890e-01, 5.197877891222927e-01, 6.811929286730756e-01, 8.162579526423345e-01, 9.200816433936687e-01} - }, - { // a = 4 - {-9.860181128521710e-01, -9.270483578727584e-01, -8.238523505345596e-01, -6.812292401370837e-01, -5.058415548115412e-01, -3.058839569922088e-01, -9.069665054560958e-02, 1.296751980287479e-01, 3.449596695560612e-01, 5.451620543220070e-01, 7.211162307744255e-01, 8.653713567789760e-01}, - {-9.669630944473241e-01, -8.906610149309094e-01, -7.746772510739069e-01, -6.240886140472163e-01, -4.454751347453242e-01, -2.466384345791495e-01, -3.626016647351250e-02, 1.764804636187008e-01, 3.823156444185185e-01, 5.723160028857331e-01, 7.383592484595911e-01, 8.739130405699720e-01}, - {-9.446293136055027e-01, -8.535444412555850e-01, -7.270881350352043e-01, -5.703631554143442e-01, -3.897680125529990e-01, -1.926867198241465e-01, 1.282219763078040e-02, 2.183604632007295e-01, 4.155417840165797e-01, 5.963560239063559e-01, 7.535707100992809e-01, 8.814285988340554e-01}, - {-9.200816433936687e-01, -8.162579526423345e-01, -6.811929286730756e-01, -5.197877891222927e-01, -3.381761358407890e-01, -1.433097819098507e-01, 5.734006950825194e-02, 2.560808727544255e-01, 4.453039951958354e-01, 6.177975944271482e-01, 7.670933934819978e-01, 8.880935320208031e-01}, - {-8.940452670188849e-01, -7.791963246910317e-01, -6.370465362841737e-01, -4.721286777836322e-01, -2.902502314930908e-01, -9.792564278297608e-02, 9.792564278297598e-02, 2.902502314930907e-01, 4.721286777836323e-01, 6.370465362841733e-01, 7.791963246910319e-01, 8.940452670188848e-01} - } -}; + {// a = 0 + {-9.815606342467196e-01, -9.041172563704754e-01, -7.699026741943048e-01, + -5.873179542866176e-01, -3.678314989981800e-01, -1.252334085114694e-01, + 1.252334085114691e-01, 3.678314989981800e-01, 5.873179542866177e-01, + 7.699026741943049e-01, 9.041172563704749e-01, 9.815606342467198e-01}, + {-9.568758736682992e-01, -8.578842025288225e-01, -7.091050875298717e-01, + -5.191977790504539e-01, -2.992013005545100e-01, -6.190169862563523e-02, + 1.789098375970846e-01, 4.092382314748395e-01, 6.156978909402920e-01, + 7.862910182330464e-01, 9.111070736891850e-01, 9.829218900231450e-01}, + {-9.284130705853431e-01, -8.115901470890873e-01, -6.514370284295737e-01, + -4.564929059061454e-01, -2.372477269169123e-01, -5.514720898064603e-03, + 2.262159800046200e-01, 4.454530844013695e-01, 6.403784218951537e-01, + 8.004847489147718e-01, 9.171443790914112e-01, 9.840959085947233e-01}, + {-8.975985245538983e-01, -7.658644530411951e-01, -5.968254805124207e-01, + -3.985851767850569e-01, -1.809975303605268e-01, 4.505689466379486e-02, + 2.682559251563394e-01, 4.774140753925782e-01, 6.620471364134675e-01, + 8.128997139816979e-01, 9.224119060591074e-01, 9.851188469194457e-01}, + {-8.653713567789760e-01, -7.211162307744255e-01, -5.451620543220070e-01, + -3.449596695560612e-01, -1.296751980287479e-01, 9.069665054560958e-02, + 3.058839569922088e-01, 5.058415548115412e-01, 6.812292401370837e-01, + 8.238523505345596e-01, 9.270483578727584e-01, 9.860181128521710e-01}}, + {// a = 1 + {-9.829218900231450e-01, -9.111070736891850e-01, -7.862910182330464e-01, + -6.156978909402920e-01, -4.092382314748395e-01, -1.789098375970846e-01, + 6.190169862563523e-02, 2.992013005545100e-01, 5.191977790504539e-01, + 7.091050875298717e-01, 8.578842025288225e-01, 9.568758736682992e-01}, + {-9.599350452672614e-01, -8.678010538303474e-01, -7.288685990913262e-01, + -5.506394029286470e-01, -3.427240133427128e-01, -1.163318688837038e-01, + 1.163318688837040e-01, 3.427240133427129e-01, 5.506394029286469e-01, + 7.288685990913261e-01, 8.678010538303473e-01, 9.599350452672608e-01}, + {-9.332995079627837e-01, -8.241972989426256e-01, -6.740760996874169e-01, + -4.903756525854291e-01, -2.822893850278608e-01, -6.024581279546619e-02, + 1.646232114144044e-01, 3.810428592335757e-01, 5.781613306985280e-01, + 7.460940443267943e-01, 8.764183644350997e-01, 9.625883913376251e-01}, + {-9.043331546184969e-01, -7.809126253419221e-01, -6.219083835463991e-01, + -4.344082673160836e-01, -2.270991419035120e-01, -9.646622564773525e-03, + 2.077935066056401e-01, 4.150599242580991e-01, 6.024641833517987e-01, + 7.612448577054650e-01, 8.839768468276173e-01, 9.649117336854240e-01}, + {-8.739130405699720e-01, -7.383592484595911e-01, -5.723160028857331e-01, + -3.823156444185185e-01, -1.764804636187008e-01, 3.626016647351250e-02, + 2.466384345791495e-01, 4.454751347453242e-01, 6.240886140472163e-01, + 7.746772510739069e-01, 8.906610149309094e-01, 9.669630944473241e-01}}, + {// a = 2 + {-9.840959085947233e-01, -9.171443790914112e-01, -8.004847489147718e-01, + -6.403784218951537e-01, -4.454530844013695e-01, -2.262159800046200e-01, + 5.514720898064603e-03, 2.372477269169123e-01, 4.564929059061454e-01, + 6.514370284295737e-01, 8.115901470890873e-01, 9.284130705853431e-01}, + {-9.625883913376251e-01, -8.764183644350997e-01, -7.460940443267943e-01, + -5.781613306985280e-01, -3.810428592335757e-01, -1.646232114144044e-01, + 6.024581279546619e-02, 2.822893850278608e-01, 4.903756525854291e-01, + 6.740760996874169e-01, 8.241972989426256e-01, 9.332995079627837e-01}, + {-9.375597349081080e-01, -8.352126561026334e-01, -6.939208718647533e-01, + -5.202087732305216e-01, -3.221818845733797e-01, -1.090939783245157e-01, + 1.090939783245159e-01, 3.221818845733799e-01, 5.202087732305219e-01, + 6.939208718647533e-01, 8.352126561026330e-01, 9.375597349081080e-01}, + {-9.102327624610815e-01, -7.941268989273503e-01, -6.440098121005434e-01, + -4.661176002087244e-01, -2.681497149953622e-01, -5.873195293835499e-02, + 1.529949068722340e-01, 3.577839774894385e-01, 5.466901395218944e-01, + 7.114641560912678e-01, 8.449215035762696e-01, 9.413071615285881e-01}, + {-8.814285988340554e-01, -7.535707100992809e-01, -5.963560239063559e-01, + -4.155417840165797e-01, -2.183604632007295e-01, -1.282219763078040e-02, + 1.926867198241465e-01, 3.897680125529990e-01, 5.703631554143442e-01, + 7.270881350352043e-01, 8.535444412555850e-01, 9.446293136055027e-01}}, + {// a = 3 + {-9.851188469194457e-01, -9.224119060591074e-01, -8.128997139816979e-01, + -6.620471364134675e-01, -4.774140753925782e-01, -2.682559251563394e-01, + -4.505689466379486e-02, 1.809975303605268e-01, 3.985851767850569e-01, + 5.968254805124207e-01, 7.658644530411951e-01, 8.975985245538983e-01}, + {-9.649117336854240e-01, -8.839768468276173e-01, -7.612448577054650e-01, + -6.024641833517987e-01, -4.150599242580991e-01, -2.077935066056401e-01, + 9.646622564773525e-03, 2.270991419035120e-01, 4.344082673160836e-01, + 6.219083835463991e-01, 7.809126253419221e-01, 9.043331546184969e-01}, + {-9.413071615285881e-01, -8.449215035762696e-01, -7.114641560912678e-01, + -5.466901395218944e-01, -3.577839774894385e-01, -1.529949068722340e-01, + 5.873195293835499e-02, 2.681497149953622e-01, 4.661176002087244e-01, + 6.440098121005434e-01, 7.941268989273503e-01, 9.102327624610815e-01}, + {-9.154441928381977e-01, -8.058259018763845e-01, -6.636387128706127e-01, + -4.943982121529223e-01, -3.049616623290851e-01, -1.030585549013792e-01, + 1.030585549013790e-01, 3.049616623290852e-01, 4.943982121529225e-01, + 6.636387128706129e-01, 8.058259018763847e-01, 9.154441928381978e-01}, + {-8.880935320208031e-01, -7.670933934819978e-01, -6.177975944271482e-01, + -4.453039951958354e-01, -2.560808727544255e-01, -5.734006950825194e-02, + 1.433097819098507e-01, 3.381761358407890e-01, 5.197877891222927e-01, + 6.811929286730756e-01, 8.162579526423345e-01, 9.200816433936687e-01}}, + {// a = 4 + {-9.860181128521710e-01, -9.270483578727584e-01, -8.238523505345596e-01, + -6.812292401370837e-01, -5.058415548115412e-01, -3.058839569922088e-01, + -9.069665054560958e-02, 1.296751980287479e-01, 3.449596695560612e-01, + 5.451620543220070e-01, 7.211162307744255e-01, 8.653713567789760e-01}, + {-9.669630944473241e-01, -8.906610149309094e-01, -7.746772510739069e-01, + -6.240886140472163e-01, -4.454751347453242e-01, -2.466384345791495e-01, + -3.626016647351250e-02, 1.764804636187008e-01, 3.823156444185185e-01, + 5.723160028857331e-01, 7.383592484595911e-01, 8.739130405699720e-01}, + {-9.446293136055027e-01, -8.535444412555850e-01, -7.270881350352043e-01, + -5.703631554143442e-01, -3.897680125529990e-01, -1.926867198241465e-01, + 1.282219763078040e-02, 2.183604632007295e-01, 4.155417840165797e-01, + 5.963560239063559e-01, 7.535707100992809e-01, 8.814285988340554e-01}, + {-9.200816433936687e-01, -8.162579526423345e-01, -6.811929286730756e-01, + -5.197877891222927e-01, -3.381761358407890e-01, -1.433097819098507e-01, + 5.734006950825194e-02, 2.560808727544255e-01, 4.453039951958354e-01, + 6.177975944271482e-01, 7.670933934819978e-01, 8.880935320208031e-01}, + {-8.940452670188849e-01, -7.791963246910317e-01, -6.370465362841737e-01, + -4.721286777836322e-01, -2.902502314930908e-01, -9.792564278297608e-02, + 9.792564278297598e-02, 2.902502314930907e-01, 4.721286777836323e-01, + 6.370465362841733e-01, 7.791963246910319e-01, 8.940452670188848e-01}}}; static double _gaussJacobiPt_13[5][5][13] = { - { // a = 0 - {-9.841830547185881e-01, -9.175983992229780e-01, -8.015780907333101e-01, -6.423493394403400e-01, -4.484927510364468e-01, -2.304583159551350e-01, -1.825585923415764e-17, 2.304583159551348e-01, 4.484927510364468e-01, 6.423493394403403e-01, 8.015780907333100e-01, 9.175983992229779e-01, 9.841830547185880e-01}, - {-9.627792699780243e-01, -8.770489182014617e-01, -7.473896426133787e-01, -5.803140565468751e-01, -3.842020034392034e-01, -1.688879280426809e-01, 5.483122799176440e-02, 2.757372054355224e-01, 4.827529185884745e-01, 6.654979772168846e-01, 8.148095506019946e-01, 9.232037225206431e-01, 9.852706979478216e-01}, - {-9.378577884571782e-01, -8.359992910744131e-01, -6.953820878944645e-01, -5.224995326165541e-01, -3.254186271207771e-01, -1.133492452589102e-01, 1.037947221885803e-01, 3.158609747078495e-01, 5.129342008257433e-01, 6.858000516069814e-01, 8.263764396848292e-01, 9.280932745996597e-01, 9.862183373800824e-01}, - {-9.106353256416408e-01, -7.950501880808041e-01, -6.456064598075977e-01, -4.685123736589696e-01, -2.714330101999745e-01, -6.295573766798158e-02, 1.478192177054831e-01, 3.516856060316347e-01, 5.397366495788333e-01, 7.037556485667396e-01, 8.365759709534939e-01, 9.323962103257980e-01, 9.870513781018821e-01}, - {-8.819299912717916e-01, -7.546128207084335e-01, -5.980631053849997e-01, -4.180138386608684e-01, -2.216670569070099e-01, -1.699926205218229e-02, 1.876383043526464e-01, 3.838820988418686e-01, 5.637060045203091e-01, 7.197530330541561e-01, 8.456382235310491e-01, 9.362123163978009e-01, 9.877894276207884e-01} - }, - { // a = 1 - {-9.852706979478216e-01, -9.232037225206431e-01, -8.148095506019946e-01, -6.654979772168846e-01, -4.827529185884745e-01, -2.757372054355224e-01, -5.483122799176440e-02, 1.688879280426809e-01, 3.842020034392034e-01, 5.803140565468751e-01, 7.473896426133787e-01, 8.770489182014617e-01, 9.627792699780243e-01}, - {-9.652459265038384e-01, -8.850820442229769e-01, -7.635196899518156e-01, -6.062532054698457e-01, -4.206380547136724e-01, -2.153539553637941e-01, -1.158883731072409e-16, 2.153539553637944e-01, 4.206380547136724e-01, 6.062532054698455e-01, 7.635196899518154e-01, 8.850820442229765e-01, 9.652459265038388e-01}, - {-9.418312621637074e-01, -8.463065055546860e-01, -7.140417072439607e-01, -5.507411438219464e-01, -3.635261963879374e-01, -1.605740533846422e-01, 4.924732876650102e-02, 2.567686837832749e-01, 4.529207661918739e-01, 6.291308945030947e-01, 7.776975152952331e-01, 8.921259396516220e-01, 9.674056024342457e-01}, - {-9.161548669307376e-01, -8.074581835226583e-01, -6.664670058592463e-01, -4.986511763145122e-01, -3.108112704919443e-01, -1.106133190663083e-01, 9.375695179582762e-02, 2.939377397626047e-01, 4.817363810899637e-01, 6.494658682590815e-01, 7.902598912526678e-01, 8.983533522410839e-01, 9.693123044508440e-01}, - {-8.889818875272764e-01, -7.689426467374832e-01, -6.208330748596507e-01, -4.497111437325291e-01, -2.619946702262355e-01, -6.483965382272970e-02, 1.342032992982673e-01, 3.274983541528479e-01, 5.076246936830698e-01, 6.676644755102082e-01, 8.014698135747076e-01, 9.038988956134982e-01, 9.710080612023384e-01} - }, - { // a = 2 - {-9.862183373800824e-01, -9.280932745996597e-01, -8.263764396848292e-01, -6.858000516069814e-01, -5.129342008257433e-01, -3.158609747078495e-01, -1.037947221885803e-01, 1.133492452589102e-01, 3.254186271207771e-01, 5.224995326165541e-01, 6.953820878944645e-01, 8.359992910744131e-01, 9.378577884571782e-01}, - {-9.674056024342457e-01, -8.921259396516220e-01, -7.776975152952331e-01, -6.291308945030947e-01, -4.529207661918739e-01, -2.567686837832749e-01, -4.924732876650102e-02, 1.605740533846422e-01, 3.635261963879374e-01, 5.507411438219464e-01, 7.140417072439607e-01, 8.463065055546860e-01, 9.418312621637074e-01}, - {-9.453259519042577e-01, -8.553876327107929e-01, -7.305245163043851e-01, -5.757768514612055e-01, -3.974652678425383e-01, -2.028850022403152e-01, 1.862729696854636e-16, 2.028850022403152e-01, 3.974652678425381e-01, 5.757768514612053e-01, 7.305245163043851e-01, 8.553876327107927e-01, 9.453259519042574e-01}, - {-9.210296137771264e-01, -8.184382169675549e-01, -6.849778326927073e-01, -5.254931513420590e-01, -3.460474803730903e-01, -1.535140263506328e-01, 4.471826297434506e-02, 2.410367231256098e-01, 4.279004525950136e-01, 5.981317381870436e-01, 7.451940552878702e-01, 8.634502697656881e-01, 9.484236582772773e-01}, - {-8.952341031014633e-01, -7.816747334968547e-01, -6.411227209112407e-01, -4.780615105195047e-01, -2.982357362646483e-01, -1.080903642726692e-01, 8.552681931385767e-02, 2.756308606370586e-01, 4.553586993533330e-01, 6.182203855088778e-01, 7.583364539007535e-01, 8.706574334491421e-01, 9.511885164033581e-01} - }, - { // a = 3 - {-9.870513781018821e-01, -9.323962103257980e-01, -8.365759709534939e-01, -7.037556485667396e-01, -5.397366495788333e-01, -3.516856060316347e-01, -1.478192177054831e-01, 6.295573766798158e-02, 2.714330101999745e-01, 4.685123736589696e-01, 6.456064598075977e-01, 7.950501880808041e-01, 9.106353256416408e-01}, - {-9.693123044508440e-01, -8.983533522410839e-01, -7.902598912526678e-01, -6.494658682590815e-01, -4.817363810899637e-01, -2.939377397626047e-01, -9.375695179582762e-02, 1.106133190663083e-01, 3.108112704919443e-01, 4.986511763145122e-01, 6.664670058592463e-01, 8.074581835226583e-01, 9.161548669307376e-01}, - {-9.484236582772773e-01, -8.634502697656881e-01, -7.451940552878702e-01, -5.981317381870436e-01, -4.279004525950136e-01, -2.410367231256098e-01, -4.471826297434506e-02, 1.535140263506328e-01, 3.460474803730903e-01, 5.254931513420590e-01, 6.849778326927073e-01, 8.184382169675549e-01, 9.210296137771264e-01}, - {-9.253667145266221e-01, -8.282251089102080e-01, -7.015195418872225e-01, -5.495612784412456e-01, -3.777802389330993e-01, -1.923628590319902e-01, 1.421753408307642e-16, 1.923628590319905e-01, 3.777802389330995e-01, 5.495612784412456e-01, 7.015195418872221e-01, 8.282251089102080e-01, 9.253667145266217e-01}, - {-9.008160699206721e-01, -7.930646544109481e-01, -6.593223567858463e-01, -5.035800839674237e-01, -3.310006752666606e-01, -1.474091888902083e-01, 4.096661645938558e-02, 2.277258470854101e-01, 4.065194629697887e-01, 5.712714108286815e-01, 7.163938040499569e-01, 8.370045341964304e-01, 9.292507475914998e-01} - }, - { // a = 4 - {-9.877894276207884e-01, -9.362123163978009e-01, -8.456382235310491e-01, -7.197530330541561e-01, -5.637060045203091e-01, -3.838820988418686e-01, -1.876383043526464e-01, 1.699926205218229e-02, 2.216670569070099e-01, 4.180138386608684e-01, 5.980631053849997e-01, 7.546128207084335e-01, 8.819299912717916e-01}, - {-9.710080612023384e-01, -9.038988956134982e-01, -8.014698135747076e-01, -6.676644755102082e-01, -5.076246936830698e-01, -3.274983541528479e-01, -1.342032992982673e-01, 6.483965382272970e-02, 2.619946702262355e-01, 4.497111437325291e-01, 6.208330748596507e-01, 7.689426467374832e-01, 8.889818875272764e-01}, - {-9.511885164033581e-01, -8.706574334491421e-01, -7.583364539007535e-01, -6.182203855088778e-01, -4.553586993533330e-01, -2.756308606370586e-01, -8.552681931385767e-02, 1.080903642726692e-01, 2.982357362646483e-01, 4.780615105195047e-01, 6.411227209112407e-01, 7.816747334968547e-01, 8.952341031014633e-01}, - {-9.292507475914998e-01, -8.370045341964304e-01, -7.163938040499569e-01, -5.712714108286815e-01, -4.065194629697887e-01, -2.277258470854101e-01, -4.096661645938558e-02, 1.474091888902083e-01, 3.310006752666606e-01, 5.035800839674237e-01, 6.593223567858463e-01, 7.930646544109481e-01, 9.008160699206721e-01}, - {-9.058305855710760e-01, -8.033157644669905e-01, -6.757433171702266e-01, -5.266790973840587e-01, -3.607799904378995e-01, -1.833275555317881e-01, -5.624830782443055e-17, 1.833275555317884e-01, 3.607799904378998e-01, 5.266790973840583e-01, 6.757433171702257e-01, 8.033157644669903e-01, 9.058305855710764e-01} - } -}; + {// a = 0 + {-9.841830547185881e-01, -9.175983992229780e-01, -8.015780907333101e-01, + -6.423493394403400e-01, -4.484927510364468e-01, -2.304583159551350e-01, + -1.825585923415764e-17, 2.304583159551348e-01, 4.484927510364468e-01, + 6.423493394403403e-01, 8.015780907333100e-01, 9.175983992229779e-01, + 9.841830547185880e-01}, + {-9.627792699780243e-01, -8.770489182014617e-01, -7.473896426133787e-01, + -5.803140565468751e-01, -3.842020034392034e-01, -1.688879280426809e-01, + 5.483122799176440e-02, 2.757372054355224e-01, 4.827529185884745e-01, + 6.654979772168846e-01, 8.148095506019946e-01, 9.232037225206431e-01, + 9.852706979478216e-01}, + {-9.378577884571782e-01, -8.359992910744131e-01, -6.953820878944645e-01, + -5.224995326165541e-01, -3.254186271207771e-01, -1.133492452589102e-01, + 1.037947221885803e-01, 3.158609747078495e-01, 5.129342008257433e-01, + 6.858000516069814e-01, 8.263764396848292e-01, 9.280932745996597e-01, + 9.862183373800824e-01}, + {-9.106353256416408e-01, -7.950501880808041e-01, -6.456064598075977e-01, + -4.685123736589696e-01, -2.714330101999745e-01, -6.295573766798158e-02, + 1.478192177054831e-01, 3.516856060316347e-01, 5.397366495788333e-01, + 7.037556485667396e-01, 8.365759709534939e-01, 9.323962103257980e-01, + 9.870513781018821e-01}, + {-8.819299912717916e-01, -7.546128207084335e-01, -5.980631053849997e-01, + -4.180138386608684e-01, -2.216670569070099e-01, -1.699926205218229e-02, + 1.876383043526464e-01, 3.838820988418686e-01, 5.637060045203091e-01, + 7.197530330541561e-01, 8.456382235310491e-01, 9.362123163978009e-01, + 9.877894276207884e-01}}, + {// a = 1 + {-9.852706979478216e-01, -9.232037225206431e-01, -8.148095506019946e-01, + -6.654979772168846e-01, -4.827529185884745e-01, -2.757372054355224e-01, + -5.483122799176440e-02, 1.688879280426809e-01, 3.842020034392034e-01, + 5.803140565468751e-01, 7.473896426133787e-01, 8.770489182014617e-01, + 9.627792699780243e-01}, + {-9.652459265038384e-01, -8.850820442229769e-01, -7.635196899518156e-01, + -6.062532054698457e-01, -4.206380547136724e-01, -2.153539553637941e-01, + -1.158883731072409e-16, 2.153539553637944e-01, 4.206380547136724e-01, + 6.062532054698455e-01, 7.635196899518154e-01, 8.850820442229765e-01, + 9.652459265038388e-01}, + {-9.418312621637074e-01, -8.463065055546860e-01, -7.140417072439607e-01, + -5.507411438219464e-01, -3.635261963879374e-01, -1.605740533846422e-01, + 4.924732876650102e-02, 2.567686837832749e-01, 4.529207661918739e-01, + 6.291308945030947e-01, 7.776975152952331e-01, 8.921259396516220e-01, + 9.674056024342457e-01}, + {-9.161548669307376e-01, -8.074581835226583e-01, -6.664670058592463e-01, + -4.986511763145122e-01, -3.108112704919443e-01, -1.106133190663083e-01, + 9.375695179582762e-02, 2.939377397626047e-01, 4.817363810899637e-01, + 6.494658682590815e-01, 7.902598912526678e-01, 8.983533522410839e-01, + 9.693123044508440e-01}, + {-8.889818875272764e-01, -7.689426467374832e-01, -6.208330748596507e-01, + -4.497111437325291e-01, -2.619946702262355e-01, -6.483965382272970e-02, + 1.342032992982673e-01, 3.274983541528479e-01, 5.076246936830698e-01, + 6.676644755102082e-01, 8.014698135747076e-01, 9.038988956134982e-01, + 9.710080612023384e-01}}, + {// a = 2 + {-9.862183373800824e-01, -9.280932745996597e-01, -8.263764396848292e-01, + -6.858000516069814e-01, -5.129342008257433e-01, -3.158609747078495e-01, + -1.037947221885803e-01, 1.133492452589102e-01, 3.254186271207771e-01, + 5.224995326165541e-01, 6.953820878944645e-01, 8.359992910744131e-01, + 9.378577884571782e-01}, + {-9.674056024342457e-01, -8.921259396516220e-01, -7.776975152952331e-01, + -6.291308945030947e-01, -4.529207661918739e-01, -2.567686837832749e-01, + -4.924732876650102e-02, 1.605740533846422e-01, 3.635261963879374e-01, + 5.507411438219464e-01, 7.140417072439607e-01, 8.463065055546860e-01, + 9.418312621637074e-01}, + {-9.453259519042577e-01, -8.553876327107929e-01, -7.305245163043851e-01, + -5.757768514612055e-01, -3.974652678425383e-01, -2.028850022403152e-01, + 1.862729696854636e-16, 2.028850022403152e-01, 3.974652678425381e-01, + 5.757768514612053e-01, 7.305245163043851e-01, 8.553876327107927e-01, + 9.453259519042574e-01}, + {-9.210296137771264e-01, -8.184382169675549e-01, -6.849778326927073e-01, + -5.254931513420590e-01, -3.460474803730903e-01, -1.535140263506328e-01, + 4.471826297434506e-02, 2.410367231256098e-01, 4.279004525950136e-01, + 5.981317381870436e-01, 7.451940552878702e-01, 8.634502697656881e-01, + 9.484236582772773e-01}, + {-8.952341031014633e-01, -7.816747334968547e-01, -6.411227209112407e-01, + -4.780615105195047e-01, -2.982357362646483e-01, -1.080903642726692e-01, + 8.552681931385767e-02, 2.756308606370586e-01, 4.553586993533330e-01, + 6.182203855088778e-01, 7.583364539007535e-01, 8.706574334491421e-01, + 9.511885164033581e-01}}, + {// a = 3 + {-9.870513781018821e-01, -9.323962103257980e-01, -8.365759709534939e-01, + -7.037556485667396e-01, -5.397366495788333e-01, -3.516856060316347e-01, + -1.478192177054831e-01, 6.295573766798158e-02, 2.714330101999745e-01, + 4.685123736589696e-01, 6.456064598075977e-01, 7.950501880808041e-01, + 9.106353256416408e-01}, + {-9.693123044508440e-01, -8.983533522410839e-01, -7.902598912526678e-01, + -6.494658682590815e-01, -4.817363810899637e-01, -2.939377397626047e-01, + -9.375695179582762e-02, 1.106133190663083e-01, 3.108112704919443e-01, + 4.986511763145122e-01, 6.664670058592463e-01, 8.074581835226583e-01, + 9.161548669307376e-01}, + {-9.484236582772773e-01, -8.634502697656881e-01, -7.451940552878702e-01, + -5.981317381870436e-01, -4.279004525950136e-01, -2.410367231256098e-01, + -4.471826297434506e-02, 1.535140263506328e-01, 3.460474803730903e-01, + 5.254931513420590e-01, 6.849778326927073e-01, 8.184382169675549e-01, + 9.210296137771264e-01}, + {-9.253667145266221e-01, -8.282251089102080e-01, -7.015195418872225e-01, + -5.495612784412456e-01, -3.777802389330993e-01, -1.923628590319902e-01, + 1.421753408307642e-16, 1.923628590319905e-01, 3.777802389330995e-01, + 5.495612784412456e-01, 7.015195418872221e-01, 8.282251089102080e-01, + 9.253667145266217e-01}, + {-9.008160699206721e-01, -7.930646544109481e-01, -6.593223567858463e-01, + -5.035800839674237e-01, -3.310006752666606e-01, -1.474091888902083e-01, + 4.096661645938558e-02, 2.277258470854101e-01, 4.065194629697887e-01, + 5.712714108286815e-01, 7.163938040499569e-01, 8.370045341964304e-01, + 9.292507475914998e-01}}, + {// a = 4 + {-9.877894276207884e-01, -9.362123163978009e-01, -8.456382235310491e-01, + -7.197530330541561e-01, -5.637060045203091e-01, -3.838820988418686e-01, + -1.876383043526464e-01, 1.699926205218229e-02, 2.216670569070099e-01, + 4.180138386608684e-01, 5.980631053849997e-01, 7.546128207084335e-01, + 8.819299912717916e-01}, + {-9.710080612023384e-01, -9.038988956134982e-01, -8.014698135747076e-01, + -6.676644755102082e-01, -5.076246936830698e-01, -3.274983541528479e-01, + -1.342032992982673e-01, 6.483965382272970e-02, 2.619946702262355e-01, + 4.497111437325291e-01, 6.208330748596507e-01, 7.689426467374832e-01, + 8.889818875272764e-01}, + {-9.511885164033581e-01, -8.706574334491421e-01, -7.583364539007535e-01, + -6.182203855088778e-01, -4.553586993533330e-01, -2.756308606370586e-01, + -8.552681931385767e-02, 1.080903642726692e-01, 2.982357362646483e-01, + 4.780615105195047e-01, 6.411227209112407e-01, 7.816747334968547e-01, + 8.952341031014633e-01}, + {-9.292507475914998e-01, -8.370045341964304e-01, -7.163938040499569e-01, + -5.712714108286815e-01, -4.065194629697887e-01, -2.277258470854101e-01, + -4.096661645938558e-02, 1.474091888902083e-01, 3.310006752666606e-01, + 5.035800839674237e-01, 6.593223567858463e-01, 7.930646544109481e-01, + 9.008160699206721e-01}, + {-9.058305855710760e-01, -8.033157644669905e-01, -6.757433171702266e-01, + -5.266790973840587e-01, -3.607799904378995e-01, -1.833275555317881e-01, + -5.624830782443055e-17, 1.833275555317884e-01, 3.607799904378998e-01, + 5.266790973840583e-01, 6.757433171702257e-01, 8.033157644669903e-01, + 9.058305855710764e-01}}}; static double _gaussJacobiPt_14[5][5][14] = { - { // a = 0 - {-9.862838086968119e-01, -9.284348836635733e-01, -8.272013150697648e-01, -6.872929048116856e-01, -5.152486363581542e-01, -3.191123689278900e-01, -1.080549487073435e-01, 1.080549487073435e-01, 3.191123689278900e-01, 5.152486363581542e-01, 6.872929048116850e-01, 8.272013150697648e-01, 9.284348836635735e-01, 9.862838086968122e-01}, - {-9.675504681972001e-01, -8.926054001205508e-01, -7.786856176390310e-01, -6.307794788869493e-01, -4.553529057785293e-01, -2.600733767408079e-01, -5.347572267974627e-02, 1.554106853848594e-01, 3.574565120221275e-01, 5.438314587014840e-01, 7.063902646375723e-01, 8.380290006360896e-01, 9.329971909359740e-01, 9.871664784143631e-01}, - {-9.455542414823662e-01, -8.559914774935045e-01, -7.316498014631939e-01, -5.775484768691215e-01, -3.999818343398130e-01, -2.062147934551938e-01, -4.178279499956644e-03, 1.978572426056912e-01, 3.916209437166875e-01, 5.691804858622089e-01, 7.232669480810515e-01, 8.475727550502922e-01, 9.370114803626848e-01, 9.879423822578670e-01}, - {-9.213405323982298e-01, -8.191530812718913e-01, -6.862182421056147e-01, -5.273616882897626e-01, -3.486229419300244e-01, -1.568482829897273e-01, 4.060221440065589e-02, 2.361454791491090e-01, 4.222695774228935e-01, 5.918235067181938e-01, 7.382925716753266e-01, 8.560492581055449e-01, 9.405710797542279e-01, 9.886297914367171e-01}, - {-8.956243128031848e-01, -7.824879388346706e-01, -6.424595258511370e-01, -4.800058744226682e-01, -3.008503036738516e-01, -1.114139007278459e-01, 8.148084907040697e-02, 2.708746515343146e-01, 4.499293275199216e-01, 6.121776361861849e-01, 7.517583176886480e-01, 8.636288139522612e-01, 9.437492282057267e-01, 9.892430321558936e-01} - }, - { // a = 1 - {-9.871664784143631e-01, -9.329971909359740e-01, -8.380290006360896e-01, -7.063902646375723e-01, -5.438314587014840e-01, -3.574565120221275e-01, -1.554106853848594e-01, 5.347572267974627e-02, 2.600733767408079e-01, 4.553529057785293e-01, 6.307794788869493e-01, 7.786856176390310e-01, 8.926054001205508e-01, 9.675504681972001e-01}, - {-9.695680462702181e-01, -8.992005330934723e-01, -7.920082918618153e-01, -6.523887028824931e-01, -4.860594218871375e-01, -2.998304689007633e-01, -1.013262735219493e-01, 1.013262735219494e-01, 2.998304689007631e-01, 4.860594218871379e-01, 6.523887028824933e-01, 7.920082918618150e-01, 8.992005330934723e-01, 9.695680462702181e-01}, - {-9.488282127349588e-01, -8.645214689380346e-01, -7.471933239124674e-01, -6.012857583849247e-01, -4.323922573304602e-01, -2.469989436350616e-01, -5.222861229576757e-02, 1.444346476503013e-01, 3.354335885984767e-01, 5.134284108882744e-01, 6.715788624029718e-01, 8.038069681730003e-01, 9.050298305711774e-01, 9.713491721732797e-01}, - {-9.259196266960135e-01, -8.294978563227613e-01, -7.037315434527489e-01, -5.529003696348437e-01, -3.823945623908705e-01, -1.983555397813217e-01, -7.425888570215776e-03, 1.834981744510787e-01, 3.675185843502905e-01, 5.379857442116746e-01, 6.887392688167489e-01, 8.143306946055725e-01, 9.102197714126011e-01, 9.729331490008095e-01}, - {-9.015122251643732e-01, -7.945173126562066e-01, -6.617143688762277e-01, -5.070666283409846e-01, -3.357011963889833e-01, -1.534030104128147e-01, 3.364266638379835e-02, 2.190778018779264e-01, 3.965941037313985e-01, 5.601503105969163e-01, 7.041790253866186e-01, 8.237767275748286e-01, 9.148703595248108e-01, 9.743510194905652e-01} - }, - { // a = 2 - {-9.879423822578670e-01, -9.370114803626848e-01, -8.475727550502922e-01, -7.232669480810515e-01, -5.691804858622089e-01, -3.916209437166875e-01, -1.978572426056912e-01, 4.178279499956644e-03, 2.062147934551938e-01, 3.999818343398130e-01, 5.775484768691215e-01, 7.316498014631939e-01, 8.559914774935045e-01, 9.455542414823662e-01}, - {-9.713491721732797e-01, -9.050298305711774e-01, -8.038069681730003e-01, -6.715788624029718e-01, -5.134284108882744e-01, -3.354335885984767e-01, -1.444346476503013e-01, 5.222861229576757e-02, 2.469989436350616e-01, 4.323922573304602e-01, 6.012857583849247e-01, 7.471933239124674e-01, 8.645214689380346e-01, 9.488282127349588e-01}, - {-9.517299551512826e-01, -8.720925079976581e-01, -7.610187556794574e-01, -6.224601813697707e-01, -4.614117410818559e-01, -2.836899503115700e-01, -9.571632215598336e-02, 9.571632215598339e-02, 2.836899503115702e-01, 4.614117410818562e-01, 6.224601813697704e-01, 7.610187556794574e-01, 8.720925079976578e-01, 9.517299551512816e-01}, - {-9.299930693574174e-01, -8.387151945704939e-01, -7.193714788656792e-01, -5.757752998715386e-01, -4.127589541066776e-01, -2.358538267037598e-01, -5.107555113027149e-02, 1.352879146599514e-01, 3.168928900212988e-01, 4.875571404387233e-01, 6.414713137074618e-01, 7.733984560034671e-01, 8.788584305988894e-01, 9.543196534184706e-01}, - {-9.067679404933646e-01, -8.052741220001853e-01, -6.789732449993078e-01, -5.313965758720792e-01, -3.671559798643468e-01, -1.914824466486846e-01, -1.000079958841649e-02, 1.714671012158039e-01, 3.470952113819603e-01, 5.112430718865147e-01, 6.586386330283140e-01, 7.845496440369255e-01, 8.849417008614823e-01, 9.566451588200905e-01} - }, - { // a = 3 - {-9.886297914367171e-01, -9.405710797542279e-01, -8.560492581055449e-01, -7.382925716753266e-01, -5.918235067181938e-01, -4.222695774228935e-01, -2.361454791491090e-01, -4.060221440065589e-02, 1.568482829897273e-01, 3.486229419300244e-01, 5.273616882897626e-01, 6.862182421056147e-01, 8.191530812718913e-01, 9.213405323982298e-01}, - {-9.729331490008095e-01, -9.102197714126011e-01, -8.143306946055725e-01, -6.887392688167489e-01, -5.379857442116746e-01, -3.675185843502905e-01, -1.834981744510787e-01, 7.425888570215776e-03, 1.983555397813217e-01, 3.823945623908705e-01, 5.529003696348437e-01, 7.037315434527489e-01, 8.294978563227613e-01, 9.259196266960135e-01}, - {-9.543196534184706e-01, -8.788584305988894e-01, -7.733984560034671e-01, -6.414713137074618e-01, -4.875571404387233e-01, -3.168928900212988e-01, -1.352879146599514e-01, 5.107555113027149e-02, 2.358538267037598e-01, 4.127589541066776e-01, 5.757752998715386e-01, 7.193714788656792e-01, 8.387151945704939e-01, 9.299930693574174e-01}, - {-9.336404975104380e-01, -8.469810432842003e-01, -7.334265985449164e-01, -5.963895043330733e-01, -4.402194426468624e-01, -2.699166024363143e-01, -9.094583560853807e-02, 9.094583560853824e-02, 2.699166024363141e-01, 4.402194426468622e-01, 5.963895043330731e-01, 7.334265985449161e-01, 8.469810432842000e-01, 9.336404975104384e-01}, - {-9.114885667667870e-01, -8.149518299963644e-01, -6.945353123697448e-01, -5.533973172747298e-01, -3.957016938581564e-01, -2.261943417931378e-01, -5.000477651748858e-02, 1.275250408431297e-01, 3.010087548760103e-01, 4.651823505033575e-01, 6.150672654932331e-01, 7.461284802953800e-01, 8.544363353075707e-01, 9.369256112577277e-01} - }, - { // a = 4 - {-9.892430321558936e-01, -9.437492282057267e-01, -8.636288139522612e-01, -7.517583176886480e-01, -6.121776361861849e-01, -4.499293275199216e-01, -2.708746515343146e-01, -8.148084907040697e-02, 1.114139007278459e-01, 3.008503036738516e-01, 4.800058744226682e-01, 6.424595258511370e-01, 7.824879388346706e-01, 8.956243128031848e-01}, - {-9.743510194905652e-01, -9.148703595248108e-01, -8.237767275748286e-01, -7.041790253866186e-01, -5.601503105969163e-01, -3.965941037313985e-01, -2.190778018779264e-01, -3.364266638379835e-02, 1.534030104128147e-01, 3.357011963889833e-01, 5.070666283409846e-01, 6.617143688762277e-01, 7.945173126562066e-01, 9.015122251643732e-01}, - {-9.566451588200905e-01, -8.849417008614823e-01, -7.845496440369255e-01, -6.586386330283140e-01, -5.112430718865147e-01, -3.470952113819603e-01, -1.714671012158039e-01, 1.000079958841649e-02, 1.914824466486846e-01, 3.671559798643468e-01, 5.313965758720792e-01, 6.789732449993078e-01, 8.052741220001853e-01, 9.067679404933646e-01}, - {-9.369256112577277e-01, -8.544363353075707e-01, -7.461284802953800e-01, -6.150672654932331e-01, -4.651823505033575e-01, -3.010087548760103e-01, -1.275250408431297e-01, 5.000477651748858e-02, 2.261943417931378e-01, 3.957016938581564e-01, 5.533973172747298e-01, 6.945353123697448e-01, 8.149518299963644e-01, 9.114885667667870e-01}, - {-9.157522075247713e-01, -8.237062724568985e-01, -7.086420304384200e-01, -5.733938373825735e-01, -4.217337559554012e-01, -2.579806669485394e-01, -8.682433786103685e-02, 8.682433786103677e-02, 2.579806669485393e-01, 4.217337559554015e-01, 5.733938373825737e-01, 7.086420304384200e-01, 8.237062724568984e-01, 9.157522075247710e-01} - } -}; + {// a = 0 + {-9.862838086968119e-01, -9.284348836635733e-01, -8.272013150697648e-01, + -6.872929048116856e-01, -5.152486363581542e-01, -3.191123689278900e-01, + -1.080549487073435e-01, 1.080549487073435e-01, 3.191123689278900e-01, + 5.152486363581542e-01, 6.872929048116850e-01, 8.272013150697648e-01, + 9.284348836635735e-01, 9.862838086968122e-01}, + {-9.675504681972001e-01, -8.926054001205508e-01, -7.786856176390310e-01, + -6.307794788869493e-01, -4.553529057785293e-01, -2.600733767408079e-01, + -5.347572267974627e-02, 1.554106853848594e-01, 3.574565120221275e-01, + 5.438314587014840e-01, 7.063902646375723e-01, 8.380290006360896e-01, + 9.329971909359740e-01, 9.871664784143631e-01}, + {-9.455542414823662e-01, -8.559914774935045e-01, -7.316498014631939e-01, + -5.775484768691215e-01, -3.999818343398130e-01, -2.062147934551938e-01, + -4.178279499956644e-03, 1.978572426056912e-01, 3.916209437166875e-01, + 5.691804858622089e-01, 7.232669480810515e-01, 8.475727550502922e-01, + 9.370114803626848e-01, 9.879423822578670e-01}, + {-9.213405323982298e-01, -8.191530812718913e-01, -6.862182421056147e-01, + -5.273616882897626e-01, -3.486229419300244e-01, -1.568482829897273e-01, + 4.060221440065589e-02, 2.361454791491090e-01, 4.222695774228935e-01, + 5.918235067181938e-01, 7.382925716753266e-01, 8.560492581055449e-01, + 9.405710797542279e-01, 9.886297914367171e-01}, + {-8.956243128031848e-01, -7.824879388346706e-01, -6.424595258511370e-01, + -4.800058744226682e-01, -3.008503036738516e-01, -1.114139007278459e-01, + 8.148084907040697e-02, 2.708746515343146e-01, 4.499293275199216e-01, + 6.121776361861849e-01, 7.517583176886480e-01, 8.636288139522612e-01, + 9.437492282057267e-01, 9.892430321558936e-01}}, + {// a = 1 + {-9.871664784143631e-01, -9.329971909359740e-01, -8.380290006360896e-01, + -7.063902646375723e-01, -5.438314587014840e-01, -3.574565120221275e-01, + -1.554106853848594e-01, 5.347572267974627e-02, 2.600733767408079e-01, + 4.553529057785293e-01, 6.307794788869493e-01, 7.786856176390310e-01, + 8.926054001205508e-01, 9.675504681972001e-01}, + {-9.695680462702181e-01, -8.992005330934723e-01, -7.920082918618153e-01, + -6.523887028824931e-01, -4.860594218871375e-01, -2.998304689007633e-01, + -1.013262735219493e-01, 1.013262735219494e-01, 2.998304689007631e-01, + 4.860594218871379e-01, 6.523887028824933e-01, 7.920082918618150e-01, + 8.992005330934723e-01, 9.695680462702181e-01}, + {-9.488282127349588e-01, -8.645214689380346e-01, -7.471933239124674e-01, + -6.012857583849247e-01, -4.323922573304602e-01, -2.469989436350616e-01, + -5.222861229576757e-02, 1.444346476503013e-01, 3.354335885984767e-01, + 5.134284108882744e-01, 6.715788624029718e-01, 8.038069681730003e-01, + 9.050298305711774e-01, 9.713491721732797e-01}, + {-9.259196266960135e-01, -8.294978563227613e-01, -7.037315434527489e-01, + -5.529003696348437e-01, -3.823945623908705e-01, -1.983555397813217e-01, + -7.425888570215776e-03, 1.834981744510787e-01, 3.675185843502905e-01, + 5.379857442116746e-01, 6.887392688167489e-01, 8.143306946055725e-01, + 9.102197714126011e-01, 9.729331490008095e-01}, + {-9.015122251643732e-01, -7.945173126562066e-01, -6.617143688762277e-01, + -5.070666283409846e-01, -3.357011963889833e-01, -1.534030104128147e-01, + 3.364266638379835e-02, 2.190778018779264e-01, 3.965941037313985e-01, + 5.601503105969163e-01, 7.041790253866186e-01, 8.237767275748286e-01, + 9.148703595248108e-01, 9.743510194905652e-01}}, + {// a = 2 + {-9.879423822578670e-01, -9.370114803626848e-01, -8.475727550502922e-01, + -7.232669480810515e-01, -5.691804858622089e-01, -3.916209437166875e-01, + -1.978572426056912e-01, 4.178279499956644e-03, 2.062147934551938e-01, + 3.999818343398130e-01, 5.775484768691215e-01, 7.316498014631939e-01, + 8.559914774935045e-01, 9.455542414823662e-01}, + {-9.713491721732797e-01, -9.050298305711774e-01, -8.038069681730003e-01, + -6.715788624029718e-01, -5.134284108882744e-01, -3.354335885984767e-01, + -1.444346476503013e-01, 5.222861229576757e-02, 2.469989436350616e-01, + 4.323922573304602e-01, 6.012857583849247e-01, 7.471933239124674e-01, + 8.645214689380346e-01, 9.488282127349588e-01}, + {-9.517299551512826e-01, -8.720925079976581e-01, -7.610187556794574e-01, + -6.224601813697707e-01, -4.614117410818559e-01, -2.836899503115700e-01, + -9.571632215598336e-02, 9.571632215598339e-02, 2.836899503115702e-01, + 4.614117410818562e-01, 6.224601813697704e-01, 7.610187556794574e-01, + 8.720925079976578e-01, 9.517299551512816e-01}, + {-9.299930693574174e-01, -8.387151945704939e-01, -7.193714788656792e-01, + -5.757752998715386e-01, -4.127589541066776e-01, -2.358538267037598e-01, + -5.107555113027149e-02, 1.352879146599514e-01, 3.168928900212988e-01, + 4.875571404387233e-01, 6.414713137074618e-01, 7.733984560034671e-01, + 8.788584305988894e-01, 9.543196534184706e-01}, + {-9.067679404933646e-01, -8.052741220001853e-01, -6.789732449993078e-01, + -5.313965758720792e-01, -3.671559798643468e-01, -1.914824466486846e-01, + -1.000079958841649e-02, 1.714671012158039e-01, 3.470952113819603e-01, + 5.112430718865147e-01, 6.586386330283140e-01, 7.845496440369255e-01, + 8.849417008614823e-01, 9.566451588200905e-01}}, + {// a = 3 + {-9.886297914367171e-01, -9.405710797542279e-01, -8.560492581055449e-01, + -7.382925716753266e-01, -5.918235067181938e-01, -4.222695774228935e-01, + -2.361454791491090e-01, -4.060221440065589e-02, 1.568482829897273e-01, + 3.486229419300244e-01, 5.273616882897626e-01, 6.862182421056147e-01, + 8.191530812718913e-01, 9.213405323982298e-01}, + {-9.729331490008095e-01, -9.102197714126011e-01, -8.143306946055725e-01, + -6.887392688167489e-01, -5.379857442116746e-01, -3.675185843502905e-01, + -1.834981744510787e-01, 7.425888570215776e-03, 1.983555397813217e-01, + 3.823945623908705e-01, 5.529003696348437e-01, 7.037315434527489e-01, + 8.294978563227613e-01, 9.259196266960135e-01}, + {-9.543196534184706e-01, -8.788584305988894e-01, -7.733984560034671e-01, + -6.414713137074618e-01, -4.875571404387233e-01, -3.168928900212988e-01, + -1.352879146599514e-01, 5.107555113027149e-02, 2.358538267037598e-01, + 4.127589541066776e-01, 5.757752998715386e-01, 7.193714788656792e-01, + 8.387151945704939e-01, 9.299930693574174e-01}, + {-9.336404975104380e-01, -8.469810432842003e-01, -7.334265985449164e-01, + -5.963895043330733e-01, -4.402194426468624e-01, -2.699166024363143e-01, + -9.094583560853807e-02, 9.094583560853824e-02, 2.699166024363141e-01, + 4.402194426468622e-01, 5.963895043330731e-01, 7.334265985449161e-01, + 8.469810432842000e-01, 9.336404975104384e-01}, + {-9.114885667667870e-01, -8.149518299963644e-01, -6.945353123697448e-01, + -5.533973172747298e-01, -3.957016938581564e-01, -2.261943417931378e-01, + -5.000477651748858e-02, 1.275250408431297e-01, 3.010087548760103e-01, + 4.651823505033575e-01, 6.150672654932331e-01, 7.461284802953800e-01, + 8.544363353075707e-01, 9.369256112577277e-01}}, + {// a = 4 + {-9.892430321558936e-01, -9.437492282057267e-01, -8.636288139522612e-01, + -7.517583176886480e-01, -6.121776361861849e-01, -4.499293275199216e-01, + -2.708746515343146e-01, -8.148084907040697e-02, 1.114139007278459e-01, + 3.008503036738516e-01, 4.800058744226682e-01, 6.424595258511370e-01, + 7.824879388346706e-01, 8.956243128031848e-01}, + {-9.743510194905652e-01, -9.148703595248108e-01, -8.237767275748286e-01, + -7.041790253866186e-01, -5.601503105969163e-01, -3.965941037313985e-01, + -2.190778018779264e-01, -3.364266638379835e-02, 1.534030104128147e-01, + 3.357011963889833e-01, 5.070666283409846e-01, 6.617143688762277e-01, + 7.945173126562066e-01, 9.015122251643732e-01}, + {-9.566451588200905e-01, -8.849417008614823e-01, -7.845496440369255e-01, + -6.586386330283140e-01, -5.112430718865147e-01, -3.470952113819603e-01, + -1.714671012158039e-01, 1.000079958841649e-02, 1.914824466486846e-01, + 3.671559798643468e-01, 5.313965758720792e-01, 6.789732449993078e-01, + 8.052741220001853e-01, 9.067679404933646e-01}, + {-9.369256112577277e-01, -8.544363353075707e-01, -7.461284802953800e-01, + -6.150672654932331e-01, -4.651823505033575e-01, -3.010087548760103e-01, + -1.275250408431297e-01, 5.000477651748858e-02, 2.261943417931378e-01, + 3.957016938581564e-01, 5.533973172747298e-01, 6.945353123697448e-01, + 8.149518299963644e-01, 9.114885667667870e-01}, + {-9.157522075247713e-01, -8.237062724568985e-01, -7.086420304384200e-01, + -5.733938373825735e-01, -4.217337559554012e-01, -2.579806669485394e-01, + -8.682433786103685e-02, 8.682433786103677e-02, 2.579806669485393e-01, + 4.217337559554015e-01, 5.733938373825737e-01, 7.086420304384200e-01, + 8.237062724568984e-01, 9.157522075247710e-01}}}; static double _gaussJacobiPt_15[5][5][15] = { - { // a = 0 - {-9.879925180204854e-01, -9.372733924007058e-01, -8.482065834104272e-01, -7.244177313601701e-01, -5.709721726085393e-01, -3.941513470775634e-01, -2.011940939974345e-01, -8.775352290365505e-18, 2.011940939974347e-01, 3.941513470775633e-01, 5.709721726085393e-01, 7.244177313601702e-01, 8.482065834104268e-01, 9.372733924007057e-01, 9.879925180204855e-01}, - {-9.714610905263487e-01, -9.054008198116664e-01, -8.045734013587562e-01, -6.728619212112202e-01, -5.153294780626855e-01, -3.380303900599199e-01, -1.477783218133716e-01, 4.811538307353035e-02, 2.421226227060440e-01, 4.267878274849456e-01, 5.950144898997918e-01, 7.403379488928178e-01, 8.571740937696825e-01, 9.410354027041151e-01, 9.887186220549768e-01}, - {-9.519077486700472e-01, -8.725636434710378e-01, -7.618990574306275e-01, -6.238509545500194e-01, -4.633959461050459e-01, -2.863292035375701e-01, -9.904871118710282e-02, 9.167752849104549e-02, 2.789566128258846e-01, 4.560200681410275e-01, 6.164685874446926e-01, 7.545034275690048e-01, 8.651362683220029e-01, 9.443708761634801e-01, 9.893618959943125e-01}, - {-9.302370030518765e-01, -8.392771956636823e-01, -7.203493790211057e-01, -5.772536773256602e-01, -4.148055995879016e-01, -2.385173322680288e-01, -5.438366372937470e-02, 1.313291689648413e-01, 3.122992582302949e-01, 4.823652765933844e-01, 6.357367475568939e-01, 7.671915120184530e-01, 8.722539177842026e-01, 9.473485817737878e-01, 9.899357513621353e-01}, - {-9.070761581549767e-01, -8.059178909088814e-01, -6.800346165868267e-01, -5.329459599609458e-01, -3.692485872705891e-01, -1.941562655040178e-01, -1.327533184434133e-02, 1.675914220447396e-01, 3.426368994804752e-01, 5.062386877385864e-01, 6.531408708912725e-01, 7.786235676115519e-01, 8.786551557289582e-01, 9.500232370953487e-01, 9.904508519925874e-01} - }, - { // a = 1 - {-9.887186220549768e-01, -9.410354027041151e-01, -8.571740937696825e-01, -7.403379488928178e-01, -5.950144898997918e-01, -4.267878274849456e-01, -2.421226227060440e-01, -4.811538307353035e-02, 1.477783218133716e-01, 3.380303900599199e-01, 5.153294780626855e-01, 6.728619212112202e-01, 8.045734013587562e-01, 9.054008198116664e-01, 9.714610905263487e-01}, - {-9.731321766314176e-01, -9.108799959155736e-01, -8.156962512217703e-01, -6.910289806276844e-01, -5.413853993301014e-01, -3.721744335654771e-01, -1.895119735183171e-01, -1.062702462397255e-16, 1.895119735183174e-01, 3.721744335654765e-01, 5.413853993301015e-01, 6.910289806276848e-01, 8.156962512217705e-01, 9.108799959155733e-01, 9.731321766314182e-01}, - {-9.546368989897532e-01, -8.796998267938857e-01, -7.749725606727137e-01, -6.439623806560700e-01, -4.911186416765717e-01, -3.216424211165446e-01, -1.413034773917096e-01, 4.375769163449201e-02, 2.272394230515447e-01, 4.028936578980453e-01, 5.647387725977340e-01, 7.072632657024025e-01, 8.256133057273756e-01, 9.157573308768492e-01, 9.746182143542607e-01}, - {-9.340771185735171e-01, -8.479879583912526e-01, -7.351810111688980e-01, -5.990463806247165e-01, -4.439054441337806e-01, -2.747259553942212e-01, -9.693751531355099e-02, 8.374954028591096e-02, 2.615299181081761e-01, 4.306908476223183e-01, 5.857960839438230e-01, 7.218607883366844e-01, 8.345117004808159e-01, 9.201270930490951e-01, 9.759483529495837e-01}, - {-9.120418435252217e-01, -8.161086826141644e-01, -6.964452749078387e-01, -5.561903872314952e-01, -3.994821387837031e-01, -2.310372004666394e-01, -5.595368849274608e-02, 1.204587645778244e-01, 2.928456554515722e-01, 4.559724985456258e-01, 6.048848773904851e-01, 7.350594536294244e-01, 8.425415407228948e-01, 9.240647910019436e-01, 9.771459204163240e-01} - }, - { // a = 2 - {-9.893618959943125e-01, -9.443708761634801e-01, -8.651362683220029e-01, -7.545034275690048e-01, -6.164685874446926e-01, -4.560200681410275e-01, -2.789566128258846e-01, -9.167752849104549e-02, 9.904871118710282e-02, 2.863292035375701e-01, 4.633959461050459e-01, 6.238509545500194e-01, 7.618990574306275e-01, 8.725636434710378e-01, 9.519077486700472e-01}, - {-9.746182143542607e-01, -9.157573308768492e-01, -8.256133057273756e-01, -7.072632657024025e-01, -5.647387725977340e-01, -4.028936578980453e-01, -2.272394230515447e-01, -4.375769163449201e-02, 1.413034773917096e-01, 3.216424211165446e-01, 4.911186416765717e-01, 6.439623806560700e-01, 7.749725606727137e-01, 8.796998267938857e-01, 9.546368989897532e-01}, - {-9.570723569250649e-01, -8.860756470171520e-01, -7.866736157817856e-01, -6.620052748493139e-01, -5.160661648573681e-01, -3.535432174725606e-01, -1.796585048481437e-01, -4.609842526636674e-16, 1.796585048481435e-01, 3.535432174725607e-01, 5.160661648573680e-01, 6.620052748493132e-01, 7.866736157817855e-01, 8.860756470171529e-01, 9.570723569250653e-01}, - {-9.375152153081482e-01, -8.557973197264757e-01, -7.485028549147995e-01, -6.186689672872857e-01, -4.701894279164579e-01, -3.075580988701691e-01, -1.357088578802053e-01, 4.014057436815714e-02, 2.146493274139599e-01, 3.825165807978498e-01, 5.386431713491237e-01, 6.782871379922397e-01, 7.972092103695705e-01, 8.918069782350803e-01, 9.592591899489894e-01}, - {-9.165012968427499e-01, -8.252741537357187e-01, -7.112340906696808e-01, -5.771908195301713e-01, -4.268836655920332e-01, -2.645942743101839e-01, -9.497246357770434e-02, 7.711178614625226e-02, 2.467134954931324e-01, 4.089570916809139e-01, 5.591777863472297e-01, 6.930566578591542e-01, 8.067464015278942e-01, 8.969871994293460e-01, 9.612336791076534e-01} - }, - { // a = 3 - {-9.899357513621353e-01, -9.473485817737878e-01, -8.722539177842026e-01, -7.671915120184530e-01, -6.357367475568939e-01, -4.823652765933844e-01, -3.122992582302949e-01, -1.313291689648413e-01, 5.438366372937470e-02, 2.385173322680288e-01, 4.148055995879016e-01, 5.772536773256602e-01, 7.203493790211057e-01, 8.392771956636823e-01, 9.302370030518765e-01}, - {-9.759483529495837e-01, -9.201270930490951e-01, -8.345117004808159e-01, -7.218607883366844e-01, -5.857960839438230e-01, -4.306908476223183e-01, -2.615299181081761e-01, -8.374954028591096e-02, 9.693751531355099e-02, 2.747259553942212e-01, 4.439054441337806e-01, 5.990463806247165e-01, 7.351810111688980e-01, 8.479879583912526e-01, 9.340771185735171e-01}, - {-9.592591899489894e-01, -8.918069782350803e-01, -7.972092103695705e-01, -6.782871379922397e-01, -5.386431713491237e-01, -3.825165807978498e-01, -2.146493274139599e-01, -4.014057436815714e-02, 1.357088578802053e-01, 3.075580988701691e-01, 4.701894279164579e-01, 6.186689672872857e-01, 7.485028549147995e-01, 8.557973197264757e-01, 9.375152153081482e-01}, - {-9.406114633231666e-01, -8.628391076256091e-01, -7.605365042686635e-01, -6.364350506390479e-01, -4.940562478763855e-01, -3.374791447825760e-01, -1.712006196860757e-01, 5.320929732608815e-18, 1.712006196860760e-01, 3.374791447825756e-01, 4.940562478763855e-01, 6.364350506390479e-01, 7.605365042686636e-01, 8.628391076256089e-01, 9.406114633231664e-01}, - {-9.205285031164320e-01, -8.335627913756348e-01, -7.246330284619493e-01, -5.962629586010140e-01, -4.518431265230561e-01, -2.952724832473960e-01, -1.308035671394406e-01, 3.708709078110611e-02, 2.038260180478653e-01, 3.648698701790187e-01, 5.158310383530933e-01, 6.525997025097098e-01, 7.714618119693399e-01, 8.692217675427797e-01, 9.434145644874151e-01} - }, - { // a = 4 - {-9.904508519925874e-01, -9.500232370953487e-01, -8.786551557289582e-01, -7.786235676115519e-01, -6.531408708912725e-01, -5.062386877385864e-01, -3.426368994804752e-01, -1.675914220447396e-01, 1.327533184434133e-02, 1.941562655040178e-01, 3.692485872705891e-01, 5.329459599609458e-01, 6.800346165868267e-01, 8.059178909088814e-01, 9.070761581549767e-01}, - {-9.771459204163240e-01, -9.240647910019436e-01, -8.425415407228948e-01, -7.350594536294244e-01, -6.048848773904851e-01, -4.559724985456258e-01, -2.928456554515722e-01, -1.204587645778244e-01, 5.595368849274608e-02, 2.310372004666394e-01, 3.994821387837031e-01, 5.561903872314952e-01, 6.964452749078387e-01, 8.161086826141644e-01, 9.120418435252217e-01}, - {-9.612336791076534e-01, -8.969871994293460e-01, -8.067464015278942e-01, -6.930566578591542e-01, -5.591777863472297e-01, -4.089570916809139e-01, -2.467134954931324e-01, -7.711178614625226e-02, 9.497246357770434e-02, 2.645942743101839e-01, 4.268836655920332e-01, 5.771908195301713e-01, 7.112340906696808e-01, 8.252741537357187e-01, 9.165012968427499e-01}, - {-9.434145644874151e-01, -8.692217675427797e-01, -7.714618119693399e-01, -6.525997025097098e-01, -5.158310383530933e-01, -3.648698701790187e-01, -2.038260180478653e-01, -3.708709078110611e-02, 1.308035671394406e-01, 2.952724832473960e-01, 4.518431265230561e-01, 5.962629586010140e-01, 7.246330284619493e-01, 8.335627913756348e-01, 9.205285031164320e-01}, - {-9.241836441156038e-01, -8.410955304608326e-01, -7.368313252269588e-01, -6.136649010261924e-01, -4.746801705494179e-01, -3.234377875279980e-01, -1.638366843073226e-01, 6.866986139640594e-17, 1.638366843073226e-01, 3.234377875279979e-01, 4.746801705494182e-01, 6.136649010261921e-01, 7.368313252269589e-01, 8.410955304608326e-01, 9.241836441156041e-01} - } -}; + {// a = 0 + {-9.879925180204854e-01, -9.372733924007058e-01, -8.482065834104272e-01, + -7.244177313601701e-01, -5.709721726085393e-01, -3.941513470775634e-01, + -2.011940939974345e-01, -8.775352290365505e-18, 2.011940939974347e-01, + 3.941513470775633e-01, 5.709721726085393e-01, 7.244177313601702e-01, + 8.482065834104268e-01, 9.372733924007057e-01, 9.879925180204855e-01}, + {-9.714610905263487e-01, -9.054008198116664e-01, -8.045734013587562e-01, + -6.728619212112202e-01, -5.153294780626855e-01, -3.380303900599199e-01, + -1.477783218133716e-01, 4.811538307353035e-02, 2.421226227060440e-01, + 4.267878274849456e-01, 5.950144898997918e-01, 7.403379488928178e-01, + 8.571740937696825e-01, 9.410354027041151e-01, 9.887186220549768e-01}, + {-9.519077486700472e-01, -8.725636434710378e-01, -7.618990574306275e-01, + -6.238509545500194e-01, -4.633959461050459e-01, -2.863292035375701e-01, + -9.904871118710282e-02, 9.167752849104549e-02, 2.789566128258846e-01, + 4.560200681410275e-01, 6.164685874446926e-01, 7.545034275690048e-01, + 8.651362683220029e-01, 9.443708761634801e-01, 9.893618959943125e-01}, + {-9.302370030518765e-01, -8.392771956636823e-01, -7.203493790211057e-01, + -5.772536773256602e-01, -4.148055995879016e-01, -2.385173322680288e-01, + -5.438366372937470e-02, 1.313291689648413e-01, 3.122992582302949e-01, + 4.823652765933844e-01, 6.357367475568939e-01, 7.671915120184530e-01, + 8.722539177842026e-01, 9.473485817737878e-01, 9.899357513621353e-01}, + {-9.070761581549767e-01, -8.059178909088814e-01, -6.800346165868267e-01, + -5.329459599609458e-01, -3.692485872705891e-01, -1.941562655040178e-01, + -1.327533184434133e-02, 1.675914220447396e-01, 3.426368994804752e-01, + 5.062386877385864e-01, 6.531408708912725e-01, 7.786235676115519e-01, + 8.786551557289582e-01, 9.500232370953487e-01, 9.904508519925874e-01}}, + {// a = 1 + {-9.887186220549768e-01, -9.410354027041151e-01, -8.571740937696825e-01, + -7.403379488928178e-01, -5.950144898997918e-01, -4.267878274849456e-01, + -2.421226227060440e-01, -4.811538307353035e-02, 1.477783218133716e-01, + 3.380303900599199e-01, 5.153294780626855e-01, 6.728619212112202e-01, + 8.045734013587562e-01, 9.054008198116664e-01, 9.714610905263487e-01}, + {-9.731321766314176e-01, -9.108799959155736e-01, -8.156962512217703e-01, + -6.910289806276844e-01, -5.413853993301014e-01, -3.721744335654771e-01, + -1.895119735183171e-01, -1.062702462397255e-16, 1.895119735183174e-01, + 3.721744335654765e-01, 5.413853993301015e-01, 6.910289806276848e-01, + 8.156962512217705e-01, 9.108799959155733e-01, 9.731321766314182e-01}, + {-9.546368989897532e-01, -8.796998267938857e-01, -7.749725606727137e-01, + -6.439623806560700e-01, -4.911186416765717e-01, -3.216424211165446e-01, + -1.413034773917096e-01, 4.375769163449201e-02, 2.272394230515447e-01, + 4.028936578980453e-01, 5.647387725977340e-01, 7.072632657024025e-01, + 8.256133057273756e-01, 9.157573308768492e-01, 9.746182143542607e-01}, + {-9.340771185735171e-01, -8.479879583912526e-01, -7.351810111688980e-01, + -5.990463806247165e-01, -4.439054441337806e-01, -2.747259553942212e-01, + -9.693751531355099e-02, 8.374954028591096e-02, 2.615299181081761e-01, + 4.306908476223183e-01, 5.857960839438230e-01, 7.218607883366844e-01, + 8.345117004808159e-01, 9.201270930490951e-01, 9.759483529495837e-01}, + {-9.120418435252217e-01, -8.161086826141644e-01, -6.964452749078387e-01, + -5.561903872314952e-01, -3.994821387837031e-01, -2.310372004666394e-01, + -5.595368849274608e-02, 1.204587645778244e-01, 2.928456554515722e-01, + 4.559724985456258e-01, 6.048848773904851e-01, 7.350594536294244e-01, + 8.425415407228948e-01, 9.240647910019436e-01, 9.771459204163240e-01}}, + {// a = 2 + {-9.893618959943125e-01, -9.443708761634801e-01, -8.651362683220029e-01, + -7.545034275690048e-01, -6.164685874446926e-01, -4.560200681410275e-01, + -2.789566128258846e-01, -9.167752849104549e-02, 9.904871118710282e-02, + 2.863292035375701e-01, 4.633959461050459e-01, 6.238509545500194e-01, + 7.618990574306275e-01, 8.725636434710378e-01, 9.519077486700472e-01}, + {-9.746182143542607e-01, -9.157573308768492e-01, -8.256133057273756e-01, + -7.072632657024025e-01, -5.647387725977340e-01, -4.028936578980453e-01, + -2.272394230515447e-01, -4.375769163449201e-02, 1.413034773917096e-01, + 3.216424211165446e-01, 4.911186416765717e-01, 6.439623806560700e-01, + 7.749725606727137e-01, 8.796998267938857e-01, 9.546368989897532e-01}, + {-9.570723569250649e-01, -8.860756470171520e-01, -7.866736157817856e-01, + -6.620052748493139e-01, -5.160661648573681e-01, -3.535432174725606e-01, + -1.796585048481437e-01, -4.609842526636674e-16, 1.796585048481435e-01, + 3.535432174725607e-01, 5.160661648573680e-01, 6.620052748493132e-01, + 7.866736157817855e-01, 8.860756470171529e-01, 9.570723569250653e-01}, + {-9.375152153081482e-01, -8.557973197264757e-01, -7.485028549147995e-01, + -6.186689672872857e-01, -4.701894279164579e-01, -3.075580988701691e-01, + -1.357088578802053e-01, 4.014057436815714e-02, 2.146493274139599e-01, + 3.825165807978498e-01, 5.386431713491237e-01, 6.782871379922397e-01, + 7.972092103695705e-01, 8.918069782350803e-01, 9.592591899489894e-01}, + {-9.165012968427499e-01, -8.252741537357187e-01, -7.112340906696808e-01, + -5.771908195301713e-01, -4.268836655920332e-01, -2.645942743101839e-01, + -9.497246357770434e-02, 7.711178614625226e-02, 2.467134954931324e-01, + 4.089570916809139e-01, 5.591777863472297e-01, 6.930566578591542e-01, + 8.067464015278942e-01, 8.969871994293460e-01, 9.612336791076534e-01}}, + {// a = 3 + {-9.899357513621353e-01, -9.473485817737878e-01, -8.722539177842026e-01, + -7.671915120184530e-01, -6.357367475568939e-01, -4.823652765933844e-01, + -3.122992582302949e-01, -1.313291689648413e-01, 5.438366372937470e-02, + 2.385173322680288e-01, 4.148055995879016e-01, 5.772536773256602e-01, + 7.203493790211057e-01, 8.392771956636823e-01, 9.302370030518765e-01}, + {-9.759483529495837e-01, -9.201270930490951e-01, -8.345117004808159e-01, + -7.218607883366844e-01, -5.857960839438230e-01, -4.306908476223183e-01, + -2.615299181081761e-01, -8.374954028591096e-02, 9.693751531355099e-02, + 2.747259553942212e-01, 4.439054441337806e-01, 5.990463806247165e-01, + 7.351810111688980e-01, 8.479879583912526e-01, 9.340771185735171e-01}, + {-9.592591899489894e-01, -8.918069782350803e-01, -7.972092103695705e-01, + -6.782871379922397e-01, -5.386431713491237e-01, -3.825165807978498e-01, + -2.146493274139599e-01, -4.014057436815714e-02, 1.357088578802053e-01, + 3.075580988701691e-01, 4.701894279164579e-01, 6.186689672872857e-01, + 7.485028549147995e-01, 8.557973197264757e-01, 9.375152153081482e-01}, + {-9.406114633231666e-01, -8.628391076256091e-01, -7.605365042686635e-01, + -6.364350506390479e-01, -4.940562478763855e-01, -3.374791447825760e-01, + -1.712006196860757e-01, 5.320929732608815e-18, 1.712006196860760e-01, + 3.374791447825756e-01, 4.940562478763855e-01, 6.364350506390479e-01, + 7.605365042686636e-01, 8.628391076256089e-01, 9.406114633231664e-01}, + {-9.205285031164320e-01, -8.335627913756348e-01, -7.246330284619493e-01, + -5.962629586010140e-01, -4.518431265230561e-01, -2.952724832473960e-01, + -1.308035671394406e-01, 3.708709078110611e-02, 2.038260180478653e-01, + 3.648698701790187e-01, 5.158310383530933e-01, 6.525997025097098e-01, + 7.714618119693399e-01, 8.692217675427797e-01, 9.434145644874151e-01}}, + {// a = 4 + {-9.904508519925874e-01, -9.500232370953487e-01, -8.786551557289582e-01, + -7.786235676115519e-01, -6.531408708912725e-01, -5.062386877385864e-01, + -3.426368994804752e-01, -1.675914220447396e-01, 1.327533184434133e-02, + 1.941562655040178e-01, 3.692485872705891e-01, 5.329459599609458e-01, + 6.800346165868267e-01, 8.059178909088814e-01, 9.070761581549767e-01}, + {-9.771459204163240e-01, -9.240647910019436e-01, -8.425415407228948e-01, + -7.350594536294244e-01, -6.048848773904851e-01, -4.559724985456258e-01, + -2.928456554515722e-01, -1.204587645778244e-01, 5.595368849274608e-02, + 2.310372004666394e-01, 3.994821387837031e-01, 5.561903872314952e-01, + 6.964452749078387e-01, 8.161086826141644e-01, 9.120418435252217e-01}, + {-9.612336791076534e-01, -8.969871994293460e-01, -8.067464015278942e-01, + -6.930566578591542e-01, -5.591777863472297e-01, -4.089570916809139e-01, + -2.467134954931324e-01, -7.711178614625226e-02, 9.497246357770434e-02, + 2.645942743101839e-01, 4.268836655920332e-01, 5.771908195301713e-01, + 7.112340906696808e-01, 8.252741537357187e-01, 9.165012968427499e-01}, + {-9.434145644874151e-01, -8.692217675427797e-01, -7.714618119693399e-01, + -6.525997025097098e-01, -5.158310383530933e-01, -3.648698701790187e-01, + -2.038260180478653e-01, -3.708709078110611e-02, 1.308035671394406e-01, + 2.952724832473960e-01, 4.518431265230561e-01, 5.962629586010140e-01, + 7.246330284619493e-01, 8.335627913756348e-01, 9.205285031164320e-01}, + {-9.241836441156038e-01, -8.410955304608326e-01, -7.368313252269588e-01, + -6.136649010261924e-01, -4.746801705494179e-01, -3.234377875279980e-01, + -1.638366843073226e-01, 6.866986139640594e-17, 1.638366843073226e-01, + 3.234377875279979e-01, 4.746801705494182e-01, 6.136649010261921e-01, + 7.368313252269589e-01, 8.410955304608326e-01, 9.241836441156041e-01}}}; static double _gaussJacobiPt_16[5][5][16] = { - { // a = 0 - {-9.894009349916498e-01, -9.445750230732327e-01, -8.656312023878318e-01, -7.554044083550032e-01, -6.178762444026438e-01, -4.580167776572273e-01, -2.816035507792587e-01, -9.501250983763743e-02, 9.501250983763739e-02, 2.816035507792591e-01, 4.580167776572278e-01, 6.178762444026438e-01, 7.554044083550032e-01, 8.656312023878316e-01, 9.445750230732322e-01, 9.894009349916498e-01}, - {-9.747060412520832e-01, -9.160488353809505e-01, -8.262167530742823e-01, -7.082762955504214e-01, -5.662451079297364e-01, -4.049602758500824e-01, -2.299143037529789e-01, -4.706823205033688e-02, 1.373513128087494e-01, 3.170641449043537e-01, 4.859503843096581e-01, 6.382588806842324e-01, 7.688031248403683e-01, 8.731381088323267e-01, 9.477129726372123e-01, 9.900054006724562e-01}, - {-9.572128749973940e-01, -8.864485714244914e-01, -7.873719490976079e-01, -6.631117660529239e-01, -5.176505158982829e-01, -3.556598348291217e-01, -1.823447706330063e-01, -3.275112306375042e-03, 1.757940717662811e-01, 3.491075799517409e-01, 5.110951365109774e-01, 6.565504810339957e-01, 7.807987814824587e-01, 8.798471245667236e-01, 9.505140647611299e-01, 9.905446257541308e-01}, - {-9.377092719183144e-01, -8.562451750037930e-01, -7.492839650298050e-01, -6.198533769301103e-01, -4.718351192889191e-01, -3.097091416491135e-01, -1.383940640462959e-01, 3.690849614668840e-02, 2.108740894722364e-01, 3.782180657649011e-01, 5.338565354412820e-01, 6.730610490487624e-01, 7.916024265417829e-01, 8.858795299221087e-01, 9.530298592323596e-01, 9.910286337248018e-01}, - {-9.167479775042821e-01, -8.257903604647133e-01, -7.120872458188394e-01, -5.784400647678622e-01, -4.285771241777813e-01, -2.667674616449476e-01, -9.764721963226911e-02, 7.392791326390238e-02, 2.430274096054646e-01, 4.047898233844638e-01, 5.545636130543964e-01, 6.880414611442671e-01, 8.013845042207106e-01, 8.913331227981797e-01, 9.553018899056175e-01, 9.914654944114704e-01} - }, - { // a = 1 - {-9.900054006724562e-01, -9.477129726372123e-01, -8.731381088323267e-01, -7.688031248403683e-01, -6.382588806842324e-01, -4.859503843096581e-01, -3.170641449043537e-01, -1.373513128087494e-01, 4.706823205033688e-02, 2.299143037529789e-01, 4.049602758500824e-01, 5.662451079297364e-01, 7.082762955504214e-01, 8.262167530742823e-01, 9.160488353809505e-01, 9.747060412520832e-01}, - {-9.761055574121982e-01, -9.206491853475337e-01, -8.355935352180905e-01, -7.236793292832425e-01, -5.885048343186619e-01, -4.344150369121241e-01, -2.663626528782810e-01, -8.974909348465208e-02, 8.974909348465229e-02, 2.663626528782810e-01, 4.344150369121239e-01, 5.885048343186617e-01, 7.236793292832425e-01, 8.355935352180902e-01, 9.206491853475338e-01, 9.761055574121985e-01}, - {-9.595114682455033e-01, -8.924769893388035e-01, -7.984651844798845e-01, -6.802799728644459e-01, -5.415016596022540e-01, -3.863435570617144e-01, -2.195186934229180e-01, -4.609531222738535e-02, 1.286575395980946e-01, 2.994302662032589e-01, 4.610341154503937e-01, 6.085588543979088e-01, 7.375219388154022e-01, 8.440045809240291e-01, 9.247702002457903e-01, 9.773581987508880e-01}, - {-9.409608366407752e-01, -8.636460712122042e-01, -7.619455202124780e-01, -6.385746462731227e-01, -4.970344264511430e-01, -3.413801895594403e-01, -1.760827651118862e-01, -5.893982585463109e-03, 1.642920271882932e-01, 3.295804243787531e-01, 4.852168301957202e-01, 6.267242648147607e-01, 7.500319955706670e-01, 8.515925628534156e-01, 9.284832715262351e-01, 9.784859504075568e-01}, - {-9.209737734118978e-01, -8.344954070119577e-01, -7.261762199358890e-01, -5.985259449824257e-01, -4.549163129786197e-01, -2.992246909546222e-01, -1.356801738983313e-01, 3.126520422397432e-02, 1.970626556302207e-01, 3.571926768572186e-01, 5.072892310515162e-01, 6.432592858831594e-01, 7.613946691623876e-01, 8.584732305760546e-01, 9.318462517780637e-01, 9.795066153084454e-01} - }, - { // a = 2 - {-9.905446257541308e-01, -9.505140647611299e-01, -8.798471245667236e-01, -7.807987814824587e-01, -6.565504810339957e-01, -5.110951365109774e-01, -3.491075799517409e-01, -1.757940717662811e-01, 3.275112306375042e-03, 1.823447706330063e-01, 3.556598348291217e-01, 5.176505158982829e-01, 6.631117660529239e-01, 7.873719490976079e-01, 8.864485714244914e-01, 9.572128749973940e-01}, - {-9.773581987508880e-01, -9.247702002457903e-01, -8.440045809240291e-01, -7.375219388154022e-01, -6.085588543979088e-01, -4.610341154503937e-01, -2.994302662032589e-01, -1.286575395980946e-01, 4.609531222738535e-02, 2.195186934229180e-01, 3.863435570617144e-01, 5.415016596022540e-01, 6.802799728644459e-01, 7.984651844798845e-01, 8.924769893388035e-01, 9.595114682455033e-01}, - {-9.615752688648729e-01, -8.978950350642905e-01, -8.084499084464360e-01, -6.957632079030802e-01, -5.630665755046921e-01, -4.141742040127355e-01, -2.533681074573462e-01, -8.527369670920626e-02, 8.527369670920577e-02, 2.533681074573459e-01, 4.141742040127351e-01, 5.630665755046921e-01, 6.957632079030803e-01, 8.084499084464359e-01, 8.978950350642909e-01, 9.615752688648739e-01}, - {-9.438888240199840e-01, -8.703180459982073e-01, -7.733780575517809e-01, -6.555135690475470e-01, -5.198939197866800e-01, -3.702027782115193e-01, -2.105166025818927e-01, -4.518785730822867e-02, 1.212756205471697e-01, 2.843343709525846e-01, 4.395415393726846e-01, 5.826644873682109e-01, 7.098007121044375e-01, 8.174855142419918e-01, 9.027912835169776e-01, 9.634385588342155e-01}, - {-9.247895108353522e-01, -8.423656112568880e-01, -7.389353075463891e-01, -6.167546547591967e-01, -4.788834203333949e-01, -3.288545112075327e-01, -1.705367278255938e-01, -8.021803085205316e-03, 1.544860902785040e-01, 3.127811143606774e-01, 4.627656149166524e-01, 6.005568188437546e-01, 7.225879867803563e-01, 8.257020348063675e-01, 9.072379035241481e-01, 9.651292464969872e-01} - }, - { // a = 3 - {-9.910286337248018e-01, -9.530298592323596e-01, -8.858795299221087e-01, -7.916024265417829e-01, -6.730610490487624e-01, -5.338565354412820e-01, -3.782180657649011e-01, -2.108740894722364e-01, -3.690849614668840e-02, 1.383940640462959e-01, 3.097091416491135e-01, 4.718351192889191e-01, 6.198533769301103e-01, 7.492839650298050e-01, 8.562451750037930e-01, 9.377092719183144e-01}, - {-9.784859504075568e-01, -9.284832715262351e-01, -8.515925628534156e-01, -7.500319955706670e-01, -6.267242648147607e-01, -4.852168301957202e-01, -3.295804243787531e-01, -1.642920271882932e-01, 5.893982585463109e-03, 1.760827651118862e-01, 3.413801895594403e-01, 4.970344264511430e-01, 6.385746462731227e-01, 7.619455202124780e-01, 8.636460712122042e-01, 9.409608366407752e-01}, - {-9.634385588342155e-01, -9.027912835169776e-01, -8.174855142419918e-01, -7.098007121044375e-01, -5.826644873682109e-01, -4.395415393726846e-01, -2.843343709525846e-01, -1.212756205471697e-01, 4.518785730822867e-02, 2.105166025818927e-01, 3.702027782115193e-01, 5.198939197866800e-01, 6.555135690475470e-01, 7.733780575517809e-01, 8.703180459982073e-01, 9.438888240199840e-01}, - {-9.465393703611532e-01, -8.763642873336548e-01, -7.837538028121771e-01, -6.709165393977796e-01, -5.407313772935233e-01, -3.965549962084527e-01, -2.421148815938047e-01, -8.140743165627992e-02, 8.140743165627992e-02, 2.421148815938046e-01, 3.965549962084526e-01, 5.407313772935235e-01, 6.709165393977797e-01, 7.837538028121770e-01, 8.763642873336551e-01, 9.465393703611527e-01}, - {-9.282523434212562e-01, -8.495163902626972e-01, -7.505463464780788e-01, -6.333764810492698e-01, -5.007922253354110e-01, -3.560220833420524e-01, -2.026145434279687e-01, -4.433851788871399e-02, 1.149138254938367e-01, 2.712248220317488e-01, 4.207489017311875e-01, 5.598083768784687e-01, 6.849859355910252e-01, 7.932139708221823e-01, 8.818692907531401e-01, 9.489502181602690e-01} - }, - { // a = 4 - {-9.914654944114704e-01, -9.553018899056175e-01, -8.913331227981797e-01, -8.013845042207106e-01, -6.880414611442671e-01, -5.545636130543964e-01, -4.047898233844638e-01, -2.430274096054646e-01, -7.392791326390238e-02, 9.764721963226911e-02, 2.667674616449476e-01, 4.285771241777813e-01, 5.784400647678622e-01, 7.120872458188394e-01, 8.257903604647133e-01, 9.167479775042821e-01}, - {-9.795066153084454e-01, -9.318462517780637e-01, -8.584732305760546e-01, -7.613946691623876e-01, -6.432592858831594e-01, -5.072892310515162e-01, -3.571926768572186e-01, -1.970626556302207e-01, -3.126520422397432e-02, 1.356801738983313e-01, 2.992246909546222e-01, 4.549163129786197e-01, 5.985259449824257e-01, 7.261762199358890e-01, 8.344954070119577e-01, 9.209737734118978e-01}, - {-9.651292464969872e-01, -9.072379035241481e-01, -8.257020348063675e-01, -7.225879867803563e-01, -6.005568188437546e-01, -4.627656149166524e-01, -3.127811143606774e-01, -1.544860902785040e-01, 8.021803085205316e-03, 1.705367278255938e-01, 3.288545112075327e-01, 4.788834203333949e-01, 6.167546547591967e-01, 7.389353075463891e-01, 8.423656112568880e-01, 9.247895108353522e-01}, - {-9.489502181602690e-01, -8.818692907531401e-01, -7.932139708221823e-01, -6.849859355910252e-01, -5.598083768784687e-01, -4.207489017311875e-01, -2.712248220317488e-01, -1.149138254938367e-01, 4.433851788871399e-02, 2.026145434279687e-01, 3.560220833420524e-01, 5.007922253354110e-01, 6.333764810492698e-01, 7.505463464780788e-01, 8.495163902626972e-01, 9.282523434212562e-01}, - {-9.314092374214358e-01, -8.560426877689151e-01, -7.611591267205700e-01, -6.485979623693823e-01, -5.209022245954822e-01, -3.810302000144717e-01, -2.322444337687661e-01, -7.802355528024467e-02, 7.802355528024484e-02, 2.322444337687661e-01, 3.810302000144720e-01, 5.209022245954824e-01, 6.485979623693826e-01, 7.611591267205696e-01, 8.560426877689152e-01, 9.314092374214352e-01} - } -}; + {// a = 0 + {-9.894009349916498e-01, -9.445750230732327e-01, -8.656312023878318e-01, + -7.554044083550032e-01, -6.178762444026438e-01, -4.580167776572273e-01, + -2.816035507792587e-01, -9.501250983763743e-02, 9.501250983763739e-02, + 2.816035507792591e-01, 4.580167776572278e-01, 6.178762444026438e-01, + 7.554044083550032e-01, 8.656312023878316e-01, 9.445750230732322e-01, + 9.894009349916498e-01}, + {-9.747060412520832e-01, -9.160488353809505e-01, -8.262167530742823e-01, + -7.082762955504214e-01, -5.662451079297364e-01, -4.049602758500824e-01, + -2.299143037529789e-01, -4.706823205033688e-02, 1.373513128087494e-01, + 3.170641449043537e-01, 4.859503843096581e-01, 6.382588806842324e-01, + 7.688031248403683e-01, 8.731381088323267e-01, 9.477129726372123e-01, + 9.900054006724562e-01}, + {-9.572128749973940e-01, -8.864485714244914e-01, -7.873719490976079e-01, + -6.631117660529239e-01, -5.176505158982829e-01, -3.556598348291217e-01, + -1.823447706330063e-01, -3.275112306375042e-03, 1.757940717662811e-01, + 3.491075799517409e-01, 5.110951365109774e-01, 6.565504810339957e-01, + 7.807987814824587e-01, 8.798471245667236e-01, 9.505140647611299e-01, + 9.905446257541308e-01}, + {-9.377092719183144e-01, -8.562451750037930e-01, -7.492839650298050e-01, + -6.198533769301103e-01, -4.718351192889191e-01, -3.097091416491135e-01, + -1.383940640462959e-01, 3.690849614668840e-02, 2.108740894722364e-01, + 3.782180657649011e-01, 5.338565354412820e-01, 6.730610490487624e-01, + 7.916024265417829e-01, 8.858795299221087e-01, 9.530298592323596e-01, + 9.910286337248018e-01}, + {-9.167479775042821e-01, -8.257903604647133e-01, -7.120872458188394e-01, + -5.784400647678622e-01, -4.285771241777813e-01, -2.667674616449476e-01, + -9.764721963226911e-02, 7.392791326390238e-02, 2.430274096054646e-01, + 4.047898233844638e-01, 5.545636130543964e-01, 6.880414611442671e-01, + 8.013845042207106e-01, 8.913331227981797e-01, 9.553018899056175e-01, + 9.914654944114704e-01}}, + {// a = 1 + {-9.900054006724562e-01, -9.477129726372123e-01, -8.731381088323267e-01, + -7.688031248403683e-01, -6.382588806842324e-01, -4.859503843096581e-01, + -3.170641449043537e-01, -1.373513128087494e-01, 4.706823205033688e-02, + 2.299143037529789e-01, 4.049602758500824e-01, 5.662451079297364e-01, + 7.082762955504214e-01, 8.262167530742823e-01, 9.160488353809505e-01, + 9.747060412520832e-01}, + {-9.761055574121982e-01, -9.206491853475337e-01, -8.355935352180905e-01, + -7.236793292832425e-01, -5.885048343186619e-01, -4.344150369121241e-01, + -2.663626528782810e-01, -8.974909348465208e-02, 8.974909348465229e-02, + 2.663626528782810e-01, 4.344150369121239e-01, 5.885048343186617e-01, + 7.236793292832425e-01, 8.355935352180902e-01, 9.206491853475338e-01, + 9.761055574121985e-01}, + {-9.595114682455033e-01, -8.924769893388035e-01, -7.984651844798845e-01, + -6.802799728644459e-01, -5.415016596022540e-01, -3.863435570617144e-01, + -2.195186934229180e-01, -4.609531222738535e-02, 1.286575395980946e-01, + 2.994302662032589e-01, 4.610341154503937e-01, 6.085588543979088e-01, + 7.375219388154022e-01, 8.440045809240291e-01, 9.247702002457903e-01, + 9.773581987508880e-01}, + {-9.409608366407752e-01, -8.636460712122042e-01, -7.619455202124780e-01, + -6.385746462731227e-01, -4.970344264511430e-01, -3.413801895594403e-01, + -1.760827651118862e-01, -5.893982585463109e-03, 1.642920271882932e-01, + 3.295804243787531e-01, 4.852168301957202e-01, 6.267242648147607e-01, + 7.500319955706670e-01, 8.515925628534156e-01, 9.284832715262351e-01, + 9.784859504075568e-01}, + {-9.209737734118978e-01, -8.344954070119577e-01, -7.261762199358890e-01, + -5.985259449824257e-01, -4.549163129786197e-01, -2.992246909546222e-01, + -1.356801738983313e-01, 3.126520422397432e-02, 1.970626556302207e-01, + 3.571926768572186e-01, 5.072892310515162e-01, 6.432592858831594e-01, + 7.613946691623876e-01, 8.584732305760546e-01, 9.318462517780637e-01, + 9.795066153084454e-01}}, + {// a = 2 + {-9.905446257541308e-01, -9.505140647611299e-01, -8.798471245667236e-01, + -7.807987814824587e-01, -6.565504810339957e-01, -5.110951365109774e-01, + -3.491075799517409e-01, -1.757940717662811e-01, 3.275112306375042e-03, + 1.823447706330063e-01, 3.556598348291217e-01, 5.176505158982829e-01, + 6.631117660529239e-01, 7.873719490976079e-01, 8.864485714244914e-01, + 9.572128749973940e-01}, + {-9.773581987508880e-01, -9.247702002457903e-01, -8.440045809240291e-01, + -7.375219388154022e-01, -6.085588543979088e-01, -4.610341154503937e-01, + -2.994302662032589e-01, -1.286575395980946e-01, 4.609531222738535e-02, + 2.195186934229180e-01, 3.863435570617144e-01, 5.415016596022540e-01, + 6.802799728644459e-01, 7.984651844798845e-01, 8.924769893388035e-01, + 9.595114682455033e-01}, + {-9.615752688648729e-01, -8.978950350642905e-01, -8.084499084464360e-01, + -6.957632079030802e-01, -5.630665755046921e-01, -4.141742040127355e-01, + -2.533681074573462e-01, -8.527369670920626e-02, 8.527369670920577e-02, + 2.533681074573459e-01, 4.141742040127351e-01, 5.630665755046921e-01, + 6.957632079030803e-01, 8.084499084464359e-01, 8.978950350642909e-01, + 9.615752688648739e-01}, + {-9.438888240199840e-01, -8.703180459982073e-01, -7.733780575517809e-01, + -6.555135690475470e-01, -5.198939197866800e-01, -3.702027782115193e-01, + -2.105166025818927e-01, -4.518785730822867e-02, 1.212756205471697e-01, + 2.843343709525846e-01, 4.395415393726846e-01, 5.826644873682109e-01, + 7.098007121044375e-01, 8.174855142419918e-01, 9.027912835169776e-01, + 9.634385588342155e-01}, + {-9.247895108353522e-01, -8.423656112568880e-01, -7.389353075463891e-01, + -6.167546547591967e-01, -4.788834203333949e-01, -3.288545112075327e-01, + -1.705367278255938e-01, -8.021803085205316e-03, 1.544860902785040e-01, + 3.127811143606774e-01, 4.627656149166524e-01, 6.005568188437546e-01, + 7.225879867803563e-01, 8.257020348063675e-01, 9.072379035241481e-01, + 9.651292464969872e-01}}, + {// a = 3 + {-9.910286337248018e-01, -9.530298592323596e-01, -8.858795299221087e-01, + -7.916024265417829e-01, -6.730610490487624e-01, -5.338565354412820e-01, + -3.782180657649011e-01, -2.108740894722364e-01, -3.690849614668840e-02, + 1.383940640462959e-01, 3.097091416491135e-01, 4.718351192889191e-01, + 6.198533769301103e-01, 7.492839650298050e-01, 8.562451750037930e-01, + 9.377092719183144e-01}, + {-9.784859504075568e-01, -9.284832715262351e-01, -8.515925628534156e-01, + -7.500319955706670e-01, -6.267242648147607e-01, -4.852168301957202e-01, + -3.295804243787531e-01, -1.642920271882932e-01, 5.893982585463109e-03, + 1.760827651118862e-01, 3.413801895594403e-01, 4.970344264511430e-01, + 6.385746462731227e-01, 7.619455202124780e-01, 8.636460712122042e-01, + 9.409608366407752e-01}, + {-9.634385588342155e-01, -9.027912835169776e-01, -8.174855142419918e-01, + -7.098007121044375e-01, -5.826644873682109e-01, -4.395415393726846e-01, + -2.843343709525846e-01, -1.212756205471697e-01, 4.518785730822867e-02, + 2.105166025818927e-01, 3.702027782115193e-01, 5.198939197866800e-01, + 6.555135690475470e-01, 7.733780575517809e-01, 8.703180459982073e-01, + 9.438888240199840e-01}, + {-9.465393703611532e-01, -8.763642873336548e-01, -7.837538028121771e-01, + -6.709165393977796e-01, -5.407313772935233e-01, -3.965549962084527e-01, + -2.421148815938047e-01, -8.140743165627992e-02, 8.140743165627992e-02, + 2.421148815938046e-01, 3.965549962084526e-01, 5.407313772935235e-01, + 6.709165393977797e-01, 7.837538028121770e-01, 8.763642873336551e-01, + 9.465393703611527e-01}, + {-9.282523434212562e-01, -8.495163902626972e-01, -7.505463464780788e-01, + -6.333764810492698e-01, -5.007922253354110e-01, -3.560220833420524e-01, + -2.026145434279687e-01, -4.433851788871399e-02, 1.149138254938367e-01, + 2.712248220317488e-01, 4.207489017311875e-01, 5.598083768784687e-01, + 6.849859355910252e-01, 7.932139708221823e-01, 8.818692907531401e-01, + 9.489502181602690e-01}}, + {// a = 4 + {-9.914654944114704e-01, -9.553018899056175e-01, -8.913331227981797e-01, + -8.013845042207106e-01, -6.880414611442671e-01, -5.545636130543964e-01, + -4.047898233844638e-01, -2.430274096054646e-01, -7.392791326390238e-02, + 9.764721963226911e-02, 2.667674616449476e-01, 4.285771241777813e-01, + 5.784400647678622e-01, 7.120872458188394e-01, 8.257903604647133e-01, + 9.167479775042821e-01}, + {-9.795066153084454e-01, -9.318462517780637e-01, -8.584732305760546e-01, + -7.613946691623876e-01, -6.432592858831594e-01, -5.072892310515162e-01, + -3.571926768572186e-01, -1.970626556302207e-01, -3.126520422397432e-02, + 1.356801738983313e-01, 2.992246909546222e-01, 4.549163129786197e-01, + 5.985259449824257e-01, 7.261762199358890e-01, 8.344954070119577e-01, + 9.209737734118978e-01}, + {-9.651292464969872e-01, -9.072379035241481e-01, -8.257020348063675e-01, + -7.225879867803563e-01, -6.005568188437546e-01, -4.627656149166524e-01, + -3.127811143606774e-01, -1.544860902785040e-01, 8.021803085205316e-03, + 1.705367278255938e-01, 3.288545112075327e-01, 4.788834203333949e-01, + 6.167546547591967e-01, 7.389353075463891e-01, 8.423656112568880e-01, + 9.247895108353522e-01}, + {-9.489502181602690e-01, -8.818692907531401e-01, -7.932139708221823e-01, + -6.849859355910252e-01, -5.598083768784687e-01, -4.207489017311875e-01, + -2.712248220317488e-01, -1.149138254938367e-01, 4.433851788871399e-02, + 2.026145434279687e-01, 3.560220833420524e-01, 5.007922253354110e-01, + 6.333764810492698e-01, 7.505463464780788e-01, 8.495163902626972e-01, + 9.282523434212562e-01}, + {-9.314092374214358e-01, -8.560426877689151e-01, -7.611591267205700e-01, + -6.485979623693823e-01, -5.209022245954822e-01, -3.810302000144717e-01, + -2.322444337687661e-01, -7.802355528024467e-02, 7.802355528024484e-02, + 2.322444337687661e-01, 3.810302000144720e-01, 5.209022245954824e-01, + 6.485979623693826e-01, 7.611591267205696e-01, 8.560426877689152e-01, + 9.314092374214352e-01}}}; static double _gaussJacobiPt_17[5][5][17] = { - { // a = 0 - {-9.905754753144175e-01, -9.506755217687679e-01, -8.802391537269858e-01, -7.815140038968016e-01, -6.576711592166909e-01, -5.126905370864770e-01, -3.512317634538761e-01, -1.784841814958475e-01, 2.891240832020117e-16, 1.784841814958480e-01, 3.512317634538758e-01, 5.126905370864769e-01, 6.576711592166909e-01, 7.815140038968014e-01, 8.802391537269861e-01, 9.506755217687678e-01, 9.905754753144176e-01}, - {-9.774280812644873e-01, -9.250023956466999e-01, -8.444860691845969e-01, -7.383321191348272e-01, -6.097671570499329e-01, -4.626979054681029e-01, -3.015931169067645e-01, -1.313479337732691e-01, 4.286480629384036e-02, 2.157517305558086e-01, 3.820597644956084e-01, 5.367357484456553e-01, 6.750799931437268e-01, 7.928891341296058e-01, 8.865840624618436e-01, 9.533198117524516e-01, 9.910840128644255e-01}, - {-9.616877876948248e-01, -8.981940331930888e-01, -8.090108466286575e-01, -6.966541714199016e-01, -5.643462061624421e-01, -4.158900027701711e-01, -2.555550770936288e-01, -8.795335618095160e-02, 8.209389329396230e-02, 2.496949167183642e-01, 4.100282674039528e-01, 5.584815496156972e-01, 6.907841434682287e-01, 8.031301263389173e-01, 8.922879703456302e-01, 9.556945893763397e-01, 9.915404690270184e-01}, - {-9.440451254615260e-01, -8.706792905502057e-01, -7.740093571093564e-01, -6.564732388028863e-01, -5.212314653521029e-01, -3.719574707953516e-01, -2.127163966347863e-01, -4.784864049312098e-02, 1.181504282279267e-01, 2.807538473356057e-01, 4.355268889593358e-01, 5.782482020488821e-01, 7.050250660668096e-01, 8.123996757237790e-01, 8.974436826849810e-01, 9.578391162452090e-01, 9.919524562851854e-01}, - {-9.249892783053915e-01, -8.427843144252944e-01, -7.396287586026777e-01, -6.177726863246541e-01, -4.802677558932255e-01, -3.306375157462263e-01, -1.727405267608647e-01, -1.065770795451046e-02, 1.514178501087743e-01, 3.092913409538758e-01, 4.588757464889782e-01, 5.962981277200242e-01, 7.180001816621536e-01, 8.208305814129484e-01, 9.021268559589816e-01, 9.597853716854473e-01, 9.923261722321879e-01} - }, - { // a = 1 - {-9.910840128644255e-01, -9.533198117524516e-01, -8.865840624618436e-01, -7.928891341296058e-01, -6.750799931437268e-01, -5.367357484456553e-01, -3.820597644956084e-01, -2.157517305558086e-01, -4.286480629384036e-02, 1.313479337732691e-01, 3.015931169067645e-01, 4.626979054681029e-01, 6.097671570499329e-01, 7.383321191348272e-01, 8.444860691845969e-01, 9.250023956466999e-01, 9.774280812644873e-01}, - {-9.786117662220799e-01, -9.289015281525864e-01, -8.524605777966460e-01, -7.514942025526127e-01, -6.289081372652203e-01, -4.882292856807139e-01, -3.335048478244987e-01, -1.691860234092818e-01, -1.665046143760084e-16, 1.691860234092817e-01, 3.335048478244990e-01, 4.882292856807132e-01, 6.289081372652205e-01, 7.514942025526128e-01, 8.524605777966462e-01, 9.289015281525863e-01, 9.786117662220806e-01}, - {-9.636416865082660e-01, -9.033313870695993e-01, -8.184996794834295e-01, -7.114134481279344e-01, -5.849841648087440e-01, -4.426574597624207e-01, -2.883144119743151e-01, -1.261645224344254e-01, 3.936948234963909e-02, 2.037724323515019e-01, 3.625599355735324e-01, 5.114007245456810e-01, 6.462348034849609e-01, 7.633841646531336e-01, 8.596529930005170e-01, 9.324142828193726e-01, 9.796774008502553e-01}, - {-9.468222497938702e-01, -8.770185326029446e-01, -7.848982279745622e-01, -6.726583574659784e-01, -5.431626894326741e-01, -3.997503128986412e-01, -2.461292332798860e-01, -8.627505968926927e-02, 7.567375096313100e-02, 2.355237922490816e-01, 3.891356348643729e-01, 5.325311889144551e-01, 6.619968051286731e-01, 7.741794671498309e-01, 8.661735399229268e-01, 9.355955080676056e-01, 9.806418179830122e-01}, - {-9.286147395489064e-01, -8.502765366317450e-01, -7.518065551615287e-01, -6.352288720488580e-01, -5.033149654427417e-01, -3.592771942669792e-01, -2.066463540871556e-01, -4.917265901033056e-02, 1.092708637575098e-01, 2.647854992377059e-01, 4.135436549332882e-01, 5.518835134075636e-01, 6.763994067228070e-01, 7.840257663815949e-01, 8.721125674704689e-01, 9.384901185215214e-01, 9.815187934580930e-01} - }, - { // a = 2 - {-9.915404690270184e-01, -9.556945893763397e-01, -8.922879703456302e-01, -8.031301263389173e-01, -6.907841434682287e-01, -5.584815496156972e-01, -4.100282674039528e-01, -2.496949167183642e-01, -8.209389329396230e-02, 8.795335618095160e-02, 2.555550770936288e-01, 4.158900027701711e-01, 5.643462061624421e-01, 6.966541714199016e-01, 8.090108466286575e-01, 8.981940331930888e-01, 9.616877876948248e-01}, - {-9.796774008502553e-01, -9.324142828193726e-01, -8.596529930005170e-01, -7.633841646531336e-01, -6.462348034849609e-01, -5.114007245456810e-01, -3.625599355735324e-01, -2.037724323515019e-01, -3.936948234963909e-02, 1.261645224344254e-01, 2.883144119743151e-01, 4.426574597624207e-01, 5.849841648087440e-01, 7.114134481279344e-01, 8.184996794834295e-01, 9.033313870695993e-01, 9.636416865082660e-01}, - {-9.654056566363756e-01, -9.079732908611975e-01, -8.270840670608106e-01, -7.247881935933748e-01, -6.037259844098118e-01, -4.670299895594999e-01, -3.182393733097758e-01, -1.612071437949028e-01, 1.150186551453999e-16, 1.612071437949027e-01, 3.182393733097758e-01, 4.670299895594998e-01, 6.037259844098116e-01, 7.247881935933748e-01, 8.270840670608109e-01, 9.079732908611978e-01, 9.654056566363753e-01}, - {-9.493360375532447e-01, -8.827622111968597e-01, -7.947773237268659e-01, -6.873681609495105e-01, -5.631384234390187e-01, -4.251330011379990e-01, -2.767440389967885e-01, -1.216223878338291e-01, 3.641400098237035e-02, 1.934747798438161e-01, 3.456933308446512e-01, 4.893221814341125e-01, 6.208254882814699e-01, 7.369664831223374e-01, 8.348882494392900e-01, 9.121883604997983e-01, 9.670061462837062e-01}, - {-9.319045732496574e-01, -8.570824487650820e-01, -7.628845637619294e-01, -6.511372729771566e-01, -5.243655614869540e-01, -3.855067963818991e-01, -2.378005881335030e-01, -8.470135365007662e-02, 7.020671612619145e-02, 2.232953532172637e-01, 3.709780547084832e-01, 5.097945900205915e-01, 6.364924385626791e-01, 7.481034669599836e-01, 8.420145731709701e-01, 9.160330611344176e-01, 9.684649045056777e-01} - }, - { // a = 3 - {-9.919524562851854e-01, -9.578391162452090e-01, -8.974436826849810e-01, -8.123996757237790e-01, -7.050250660668096e-01, -5.782482020488821e-01, -4.355268889593358e-01, -2.807538473356057e-01, -1.181504282279267e-01, 4.784864049312098e-02, 2.127163966347863e-01, 3.719574707953516e-01, 5.212314653521029e-01, 6.564732388028863e-01, 7.740093571093564e-01, 8.706792905502057e-01, 9.440451254615260e-01}, - {-9.806418179830122e-01, -9.355955080676056e-01, -8.661735399229268e-01, -7.741794671498309e-01, -6.619968051286731e-01, -5.325311889144551e-01, -3.891356348643729e-01, -2.355237922490816e-01, -7.567375096313100e-02, 8.627505968926927e-02, 2.461292332798860e-01, 3.997503128986412e-01, 5.431626894326741e-01, 6.726583574659784e-01, 7.848982279745622e-01, 8.770185326029446e-01, 9.468222497938702e-01}, - {-9.670061462837062e-01, -9.121883604997983e-01, -8.348882494392900e-01, -7.369664831223374e-01, -6.208254882814699e-01, -4.893221814341125e-01, -3.456933308446512e-01, -1.934747798438161e-01, -3.641400098237035e-02, 1.216223878338291e-01, 2.767440389967885e-01, 4.251330011379990e-01, 5.631384234390187e-01, 6.873681609495105e-01, 7.947773237268659e-01, 8.827622111968597e-01, 9.493360375532447e-01}, - {-9.516223373047707e-01, -8.879908826152110e-01, -8.037819975688445e-01, -7.007980407964133e-01, -5.814136612436279e-01, -4.484136433201561e-01, -3.049095404575777e-01, -1.542619339178430e-01, -1.418789690956185e-16, 1.542619339178432e-01, 3.049095404575780e-01, 4.484136433201565e-01, 5.814136612436285e-01, 7.007980407964132e-01, 8.037819975688439e-01, 8.879908826152105e-01, 9.516223373047705e-01}, - {-9.349034872157332e-01, -8.632928073826790e-01, -7.730067925955711e-01, -6.656979776524788e-01, -5.436734702399830e-01, -4.096265485206677e-01, -2.665370690765072e-01, -1.175939058162494e-01, 3.388019332106498e-02, 1.845044982654642e-01, 3.309166897023827e-01, 4.698486159552260e-01, 5.982001155246841e-01, 7.131099311825061e-01, 8.120242635794045e-01, 8.927711382360564e-01, 9.537107590745444e-01} - }, - { // a = 4 - {-9.923261722321879e-01, -9.597853716854473e-01, -9.021268559589816e-01, -8.208305814129484e-01, -7.180001816621536e-01, -5.962981277200242e-01, -4.588757464889782e-01, -3.092913409538758e-01, -1.514178501087743e-01, 1.065770795451046e-02, 1.727405267608647e-01, 3.306375157462263e-01, 4.802677558932255e-01, 6.177726863246541e-01, 7.396287586026777e-01, 8.427843144252944e-01, 9.249892783053915e-01}, - {-9.815187934580930e-01, -9.384901185215214e-01, -8.721125674704689e-01, -7.840257663815949e-01, -6.763994067228070e-01, -5.518835134075636e-01, -4.135436549332882e-01, -2.647854992377059e-01, -1.092708637575098e-01, 4.917265901033056e-02, 2.066463540871556e-01, 3.592771942669792e-01, 5.033149654427417e-01, 6.352288720488580e-01, 7.518065551615287e-01, 8.502765366317450e-01, 9.286147395489064e-01}, - {-9.684649045056777e-01, -9.160330611344176e-01, -8.420145731709701e-01, -7.481034669599836e-01, -6.364924385626791e-01, -5.097945900205915e-01, -3.709780547084832e-01, -2.232953532172637e-01, -7.020671612619145e-02, 8.470135365007662e-02, 2.378005881335030e-01, 3.855067963818991e-01, 5.243655614869540e-01, 6.511372729771566e-01, 7.628845637619294e-01, 8.570824487650820e-01, 9.319045732496574e-01}, - {-9.537107590745444e-01, -8.927711382360564e-01, -8.120242635794045e-01, -7.131099311825061e-01, -5.982001155246841e-01, -4.698486159552260e-01, -3.309166897023827e-01, -1.845044982654642e-01, -3.388019332106498e-02, 1.175939058162494e-01, 2.665370690765072e-01, 4.096265485206677e-01, 5.436734702399830e-01, 6.656979776524788e-01, 7.730067925955711e-01, 8.632928073826790e-01, 9.349034872157332e-01}, - {-9.376485606026945e-01, -8.689829496453235e-01, -7.822929230769724e-01, -6.790775203475938e-01, -5.614504190051148e-01, -4.318873330057092e-01, -2.931355035976249e-01, -1.481445906475424e-01, 2.150030887489372e-16, 1.481445906475425e-01, 2.931355035976240e-01, 4.318873330057091e-01, 5.614504190051155e-01, 6.790775203475938e-01, 7.822929230769724e-01, 8.689829496453246e-01, 9.376485606026940e-01} - } -}; + {// a = 0 + {-9.905754753144175e-01, -9.506755217687679e-01, -8.802391537269858e-01, + -7.815140038968016e-01, -6.576711592166909e-01, -5.126905370864770e-01, + -3.512317634538761e-01, -1.784841814958475e-01, 2.891240832020117e-16, + 1.784841814958480e-01, 3.512317634538758e-01, 5.126905370864769e-01, + 6.576711592166909e-01, 7.815140038968014e-01, 8.802391537269861e-01, + 9.506755217687678e-01, 9.905754753144176e-01}, + {-9.774280812644873e-01, -9.250023956466999e-01, -8.444860691845969e-01, + -7.383321191348272e-01, -6.097671570499329e-01, -4.626979054681029e-01, + -3.015931169067645e-01, -1.313479337732691e-01, 4.286480629384036e-02, + 2.157517305558086e-01, 3.820597644956084e-01, 5.367357484456553e-01, + 6.750799931437268e-01, 7.928891341296058e-01, 8.865840624618436e-01, + 9.533198117524516e-01, 9.910840128644255e-01}, + {-9.616877876948248e-01, -8.981940331930888e-01, -8.090108466286575e-01, + -6.966541714199016e-01, -5.643462061624421e-01, -4.158900027701711e-01, + -2.555550770936288e-01, -8.795335618095160e-02, 8.209389329396230e-02, + 2.496949167183642e-01, 4.100282674039528e-01, 5.584815496156972e-01, + 6.907841434682287e-01, 8.031301263389173e-01, 8.922879703456302e-01, + 9.556945893763397e-01, 9.915404690270184e-01}, + {-9.440451254615260e-01, -8.706792905502057e-01, -7.740093571093564e-01, + -6.564732388028863e-01, -5.212314653521029e-01, -3.719574707953516e-01, + -2.127163966347863e-01, -4.784864049312098e-02, 1.181504282279267e-01, + 2.807538473356057e-01, 4.355268889593358e-01, 5.782482020488821e-01, + 7.050250660668096e-01, 8.123996757237790e-01, 8.974436826849810e-01, + 9.578391162452090e-01, 9.919524562851854e-01}, + {-9.249892783053915e-01, -8.427843144252944e-01, -7.396287586026777e-01, + -6.177726863246541e-01, -4.802677558932255e-01, -3.306375157462263e-01, + -1.727405267608647e-01, -1.065770795451046e-02, 1.514178501087743e-01, + 3.092913409538758e-01, 4.588757464889782e-01, 5.962981277200242e-01, + 7.180001816621536e-01, 8.208305814129484e-01, 9.021268559589816e-01, + 9.597853716854473e-01, 9.923261722321879e-01}}, + {// a = 1 + {-9.910840128644255e-01, -9.533198117524516e-01, -8.865840624618436e-01, + -7.928891341296058e-01, -6.750799931437268e-01, -5.367357484456553e-01, + -3.820597644956084e-01, -2.157517305558086e-01, -4.286480629384036e-02, + 1.313479337732691e-01, 3.015931169067645e-01, 4.626979054681029e-01, + 6.097671570499329e-01, 7.383321191348272e-01, 8.444860691845969e-01, + 9.250023956466999e-01, 9.774280812644873e-01}, + {-9.786117662220799e-01, -9.289015281525864e-01, -8.524605777966460e-01, + -7.514942025526127e-01, -6.289081372652203e-01, -4.882292856807139e-01, + -3.335048478244987e-01, -1.691860234092818e-01, -1.665046143760084e-16, + 1.691860234092817e-01, 3.335048478244990e-01, 4.882292856807132e-01, + 6.289081372652205e-01, 7.514942025526128e-01, 8.524605777966462e-01, + 9.289015281525863e-01, 9.786117662220806e-01}, + {-9.636416865082660e-01, -9.033313870695993e-01, -8.184996794834295e-01, + -7.114134481279344e-01, -5.849841648087440e-01, -4.426574597624207e-01, + -2.883144119743151e-01, -1.261645224344254e-01, 3.936948234963909e-02, + 2.037724323515019e-01, 3.625599355735324e-01, 5.114007245456810e-01, + 6.462348034849609e-01, 7.633841646531336e-01, 8.596529930005170e-01, + 9.324142828193726e-01, 9.796774008502553e-01}, + {-9.468222497938702e-01, -8.770185326029446e-01, -7.848982279745622e-01, + -6.726583574659784e-01, -5.431626894326741e-01, -3.997503128986412e-01, + -2.461292332798860e-01, -8.627505968926927e-02, 7.567375096313100e-02, + 2.355237922490816e-01, 3.891356348643729e-01, 5.325311889144551e-01, + 6.619968051286731e-01, 7.741794671498309e-01, 8.661735399229268e-01, + 9.355955080676056e-01, 9.806418179830122e-01}, + {-9.286147395489064e-01, -8.502765366317450e-01, -7.518065551615287e-01, + -6.352288720488580e-01, -5.033149654427417e-01, -3.592771942669792e-01, + -2.066463540871556e-01, -4.917265901033056e-02, 1.092708637575098e-01, + 2.647854992377059e-01, 4.135436549332882e-01, 5.518835134075636e-01, + 6.763994067228070e-01, 7.840257663815949e-01, 8.721125674704689e-01, + 9.384901185215214e-01, 9.815187934580930e-01}}, + {// a = 2 + {-9.915404690270184e-01, -9.556945893763397e-01, -8.922879703456302e-01, + -8.031301263389173e-01, -6.907841434682287e-01, -5.584815496156972e-01, + -4.100282674039528e-01, -2.496949167183642e-01, -8.209389329396230e-02, + 8.795335618095160e-02, 2.555550770936288e-01, 4.158900027701711e-01, + 5.643462061624421e-01, 6.966541714199016e-01, 8.090108466286575e-01, + 8.981940331930888e-01, 9.616877876948248e-01}, + {-9.796774008502553e-01, -9.324142828193726e-01, -8.596529930005170e-01, + -7.633841646531336e-01, -6.462348034849609e-01, -5.114007245456810e-01, + -3.625599355735324e-01, -2.037724323515019e-01, -3.936948234963909e-02, + 1.261645224344254e-01, 2.883144119743151e-01, 4.426574597624207e-01, + 5.849841648087440e-01, 7.114134481279344e-01, 8.184996794834295e-01, + 9.033313870695993e-01, 9.636416865082660e-01}, + {-9.654056566363756e-01, -9.079732908611975e-01, -8.270840670608106e-01, + -7.247881935933748e-01, -6.037259844098118e-01, -4.670299895594999e-01, + -3.182393733097758e-01, -1.612071437949028e-01, 1.150186551453999e-16, + 1.612071437949027e-01, 3.182393733097758e-01, 4.670299895594998e-01, + 6.037259844098116e-01, 7.247881935933748e-01, 8.270840670608109e-01, + 9.079732908611978e-01, 9.654056566363753e-01}, + {-9.493360375532447e-01, -8.827622111968597e-01, -7.947773237268659e-01, + -6.873681609495105e-01, -5.631384234390187e-01, -4.251330011379990e-01, + -2.767440389967885e-01, -1.216223878338291e-01, 3.641400098237035e-02, + 1.934747798438161e-01, 3.456933308446512e-01, 4.893221814341125e-01, + 6.208254882814699e-01, 7.369664831223374e-01, 8.348882494392900e-01, + 9.121883604997983e-01, 9.670061462837062e-01}, + {-9.319045732496574e-01, -8.570824487650820e-01, -7.628845637619294e-01, + -6.511372729771566e-01, -5.243655614869540e-01, -3.855067963818991e-01, + -2.378005881335030e-01, -8.470135365007662e-02, 7.020671612619145e-02, + 2.232953532172637e-01, 3.709780547084832e-01, 5.097945900205915e-01, + 6.364924385626791e-01, 7.481034669599836e-01, 8.420145731709701e-01, + 9.160330611344176e-01, 9.684649045056777e-01}}, + {// a = 3 + {-9.919524562851854e-01, -9.578391162452090e-01, -8.974436826849810e-01, + -8.123996757237790e-01, -7.050250660668096e-01, -5.782482020488821e-01, + -4.355268889593358e-01, -2.807538473356057e-01, -1.181504282279267e-01, + 4.784864049312098e-02, 2.127163966347863e-01, 3.719574707953516e-01, + 5.212314653521029e-01, 6.564732388028863e-01, 7.740093571093564e-01, + 8.706792905502057e-01, 9.440451254615260e-01}, + {-9.806418179830122e-01, -9.355955080676056e-01, -8.661735399229268e-01, + -7.741794671498309e-01, -6.619968051286731e-01, -5.325311889144551e-01, + -3.891356348643729e-01, -2.355237922490816e-01, -7.567375096313100e-02, + 8.627505968926927e-02, 2.461292332798860e-01, 3.997503128986412e-01, + 5.431626894326741e-01, 6.726583574659784e-01, 7.848982279745622e-01, + 8.770185326029446e-01, 9.468222497938702e-01}, + {-9.670061462837062e-01, -9.121883604997983e-01, -8.348882494392900e-01, + -7.369664831223374e-01, -6.208254882814699e-01, -4.893221814341125e-01, + -3.456933308446512e-01, -1.934747798438161e-01, -3.641400098237035e-02, + 1.216223878338291e-01, 2.767440389967885e-01, 4.251330011379990e-01, + 5.631384234390187e-01, 6.873681609495105e-01, 7.947773237268659e-01, + 8.827622111968597e-01, 9.493360375532447e-01}, + {-9.516223373047707e-01, -8.879908826152110e-01, -8.037819975688445e-01, + -7.007980407964133e-01, -5.814136612436279e-01, -4.484136433201561e-01, + -3.049095404575777e-01, -1.542619339178430e-01, -1.418789690956185e-16, + 1.542619339178432e-01, 3.049095404575780e-01, 4.484136433201565e-01, + 5.814136612436285e-01, 7.007980407964132e-01, 8.037819975688439e-01, + 8.879908826152105e-01, 9.516223373047705e-01}, + {-9.349034872157332e-01, -8.632928073826790e-01, -7.730067925955711e-01, + -6.656979776524788e-01, -5.436734702399830e-01, -4.096265485206677e-01, + -2.665370690765072e-01, -1.175939058162494e-01, 3.388019332106498e-02, + 1.845044982654642e-01, 3.309166897023827e-01, 4.698486159552260e-01, + 5.982001155246841e-01, 7.131099311825061e-01, 8.120242635794045e-01, + 8.927711382360564e-01, 9.537107590745444e-01}}, + {// a = 4 + {-9.923261722321879e-01, -9.597853716854473e-01, -9.021268559589816e-01, + -8.208305814129484e-01, -7.180001816621536e-01, -5.962981277200242e-01, + -4.588757464889782e-01, -3.092913409538758e-01, -1.514178501087743e-01, + 1.065770795451046e-02, 1.727405267608647e-01, 3.306375157462263e-01, + 4.802677558932255e-01, 6.177726863246541e-01, 7.396287586026777e-01, + 8.427843144252944e-01, 9.249892783053915e-01}, + {-9.815187934580930e-01, -9.384901185215214e-01, -8.721125674704689e-01, + -7.840257663815949e-01, -6.763994067228070e-01, -5.518835134075636e-01, + -4.135436549332882e-01, -2.647854992377059e-01, -1.092708637575098e-01, + 4.917265901033056e-02, 2.066463540871556e-01, 3.592771942669792e-01, + 5.033149654427417e-01, 6.352288720488580e-01, 7.518065551615287e-01, + 8.502765366317450e-01, 9.286147395489064e-01}, + {-9.684649045056777e-01, -9.160330611344176e-01, -8.420145731709701e-01, + -7.481034669599836e-01, -6.364924385626791e-01, -5.097945900205915e-01, + -3.709780547084832e-01, -2.232953532172637e-01, -7.020671612619145e-02, + 8.470135365007662e-02, 2.378005881335030e-01, 3.855067963818991e-01, + 5.243655614869540e-01, 6.511372729771566e-01, 7.628845637619294e-01, + 8.570824487650820e-01, 9.319045732496574e-01}, + {-9.537107590745444e-01, -8.927711382360564e-01, -8.120242635794045e-01, + -7.131099311825061e-01, -5.982001155246841e-01, -4.698486159552260e-01, + -3.309166897023827e-01, -1.845044982654642e-01, -3.388019332106498e-02, + 1.175939058162494e-01, 2.665370690765072e-01, 4.096265485206677e-01, + 5.436734702399830e-01, 6.656979776524788e-01, 7.730067925955711e-01, + 8.632928073826790e-01, 9.349034872157332e-01}, + {-9.376485606026945e-01, -8.689829496453235e-01, -7.822929230769724e-01, + -6.790775203475938e-01, -5.614504190051148e-01, -4.318873330057092e-01, + -2.931355035976249e-01, -1.481445906475424e-01, 2.150030887489372e-16, + 1.481445906475425e-01, 2.931355035976240e-01, 4.318873330057091e-01, + 5.614504190051155e-01, 6.790775203475938e-01, 7.822929230769724e-01, + 8.689829496453246e-01, 9.376485606026940e-01}}}; static double _gaussJacobiPt_18[5][5][18] = { - { // a = 0 - {-9.915651684209310e-01, -9.558239495713977e-01, -8.926024664975554e-01, -8.037049589725231e-01, -6.916870430603531e-01, -5.597708310739477e-01, -4.117511614628424e-01, -2.518862256915055e-01, -8.477501304173533e-02, 8.477501304173478e-02, 2.518862256915057e-01, 4.117511614628427e-01, 5.597708310739473e-01, 6.916870430603532e-01, 8.037049589725230e-01, 8.926024664975557e-01, 9.558239495713977e-01, 9.915651684209309e-01}, - {-9.797336964051945e-01, -9.326015038912652e-01, -8.600417793993865e-01, -7.640396507241585e-01, -6.472148595497391e-01, -5.127543868123012e-01, -3.643260782273030e-01, -2.059787211196644e-01, -4.203164174155230e-02, 1.230431015517241e-01, 2.847427000467310e-01, 4.386564198796566e-01, 5.805859208223142e-01, 7.066597926447641e-01, 8.134392081429099e-01, 8.980119168242189e-01, 9.580727032124667e-01, 9.919970412322650e-01}, - {-9.654968151885738e-01, -9.082157910346329e-01, -8.275397282215858e-01, -7.255134414001100e-01, -6.047702996728351e-01, -4.684346162700265e-01, -3.200362544506315e-01, -1.634181053418361e-01, -2.636205500547094e-03, 1.581454482593639e-01, 3.147628043959833e-01, 4.631596344267958e-01, 5.994926081527394e-01, 7.202308583296615e-01, 8.222474817670050e-01, 9.029007093915506e-01, 9.601032979053139e-01, 9.923868355049964e-01}, - {-9.494633358614275e-01, -8.830567874178292e-01, -7.952929854218481e-01, -6.881537322533672e-01, -5.642361984904343e-01, -4.265776402741575e-01, -2.785617030491334e-01, -1.238300984934756e-01, 3.380876425338892e-02, 1.904742330566806e-01, 3.423092737126247e-01, 4.855755959179479e-01, 6.167457880276481e-01, 7.325902337993169e-01, 8.302567088965966e-01, 9.073408014613273e-01, 9.619460504511647e-01, 9.927404163003614e-01}, - {-9.320680711544124e-01, -8.574256011734057e-01, -7.634539032404926e-01, -6.519749553303759e-01, -5.255076915542232e-01, -3.869824423142821e-01, -2.396310621188066e-01, -8.689970601284235e-02, 6.763599254962109e-02, 2.203564015650038e-01, 3.676835040083336e-01, 5.061651544605044e-01, 6.325562096613778e-01, 7.438947259655249e-01, 8.375714999820000e-01, 9.113914351713388e-01, 9.636259026153904e-01, 9.930626069197461e-01} - }, - { // a = 1 - {-9.919970412322650e-01, -9.580727032124667e-01, -8.980119168242189e-01, -8.134392081429099e-01, -7.066597926447641e-01, -5.805859208223142e-01, -4.386564198796566e-01, -2.847427000467310e-01, -1.230431015517241e-01, 4.203164174155230e-02, 2.059787211196644e-01, 3.643260782273030e-01, 5.127543868123012e-01, 6.472148595497391e-01, 7.640396507241585e-01, 8.600417793993865e-01, 9.326015038912652e-01, 9.797336964051945e-01}, - {-9.807437048939144e-01, -9.359344988126653e-01, -8.668779780899500e-01, -7.753682609520556e-01, -6.637764022903112e-01, -5.349928640318862e-01, -3.923531837139092e-01, -2.395517059229865e-01, -8.054593723882174e-02, 8.054593723882221e-02, 2.395517059229864e-01, 3.923531837139091e-01, 5.349928640318862e-01, 6.637764022903111e-01, 7.753682609520564e-01, 8.668779780899500e-01, 9.359344988126651e-01, 9.807437048939139e-01}, - {-9.671715346739649e-01, -9.126285555530927e-01, -8.357160065906806e-01, -7.382852879071825e-01, -6.227268653309460e-01, -4.918834487495606e-01, -3.489757413144571e-01, -1.975220899813244e-01, -4.125151717547191e-02, 1.159882277809087e-01, 2.703254675735441e-01, 4.179599547137846e-01, 5.552564548060258e-01, 6.788342531396245e-01, 7.856503691197853e-01, 8.730743731339660e-01, 9.389526537953393e-01, 9.816577547521641e-01}, - {-9.518538220458710e-01, -8.885268701941211e-01, -8.047210165392289e-01, -7.022300516974338e-01, -5.834173407157311e-01, -4.510544517248982e-01, -3.082382010388641e-01, -1.583133053787015e-01, -4.792371471985597e-03, 1.487270800496405e-01, 2.986472259694831e-01, 4.414544106880812e-01, 5.738015737454587e-01, 6.925867323817538e-01, 7.950256814092369e-01, 8.787171589479275e-01, 9.416986583232526e-01, 9.824889092920019e-01}, - {-9.352014348342639e-01, -8.639185558803630e-01, -7.740458928102649e-01, -6.672284715254208e-01, -5.457629155697068e-01, -4.123302795456282e-01, -2.698969250762572e-01, -1.216373353085339e-01, 2.914064845107950e-02, 1.790713055670388e-01, 3.248069526250779e-01, 4.630930918907747e-01, 5.908413054531469e-01, 7.051983471363626e-01, 8.036099153174605e-01, 8.838776492971402e-01, 9.442078032684286e-01, 9.832479622756365e-01} - }, - { // a = 2 - {-9.923868355049964e-01, -9.601032979053139e-01, -9.029007093915506e-01, -8.222474817670050e-01, -7.202308583296615e-01, -5.994926081527394e-01, -4.631596344267958e-01, -3.147628043959833e-01, -1.581454482593639e-01, 2.636205500547094e-03, 1.634181053418361e-01, 3.200362544506315e-01, 4.684346162700265e-01, 6.047702996728351e-01, 7.255134414001100e-01, 8.275397282215858e-01, 9.082157910346329e-01, 9.654968151885738e-01}, - {-9.816577547521641e-01, -9.389526537953393e-01, -8.730743731339660e-01, -7.856503691197853e-01, -6.788342531396245e-01, -5.552564548060258e-01, -4.179599547137846e-01, -2.703254675735441e-01, -1.159882277809087e-01, 4.125151717547191e-02, 1.975220899813244e-01, 3.489757413144571e-01, 4.918834487495606e-01, 6.227268653309460e-01, 7.382852879071825e-01, 8.357160065906806e-01, 9.126285555530927e-01, 9.671715346739649e-01}, - {-9.686909783865258e-01, -9.166350766447443e-01, -8.431474467170091e-01, -7.499101295243042e-01, -6.391003286370385e-01, -5.133127283086356e-01, -3.754946217673181e-01, -2.288758312146870e-01, -7.689268019371842e-02, 7.689268019371846e-02, 2.288758312146867e-01, 3.754946217673183e-01, 5.133127283086359e-01, 6.391003286370388e-01, 7.499101295243040e-01, 8.431474467170090e-01, 9.166350766447436e-01, 9.686909783865253e-01}, - {-9.540278442594630e-01, -8.935057475607323e-01, -8.133122649255592e-01, -7.150761166059388e-01, -6.009546177650399e-01, -4.734843749889841e-01, -3.355074618108145e-01, -1.901033901605648e-01, -4.051877786408334e-02, 1.099057957723520e-01, 2.578107011395917e-01, 3.998924667022931e-01, 5.329776953162680e-01, 6.540941092273742e-01, 7.605372739175675e-01, 8.499319751911004e-01, 9.202891565580816e-01, 9.700758123604537e-01}, - {-9.380574875508457e-01, -8.698423210174842e-01, -7.837211574147637e-01, -6.811833582361538e-01, -5.643289492029844e-01, -4.356176947021973e-01, -2.977792142157404e-01, -1.537443802667707e-01, -6.579175083963535e-03, 1.405821755931029e-01, 2.846047134068398e-01, 4.224199379905137e-01, 5.510914442276028e-01, 6.678777255585759e-01, 7.702909596414218e-01, 8.561509802194558e-01, 9.236354714303612e-01, 9.713431867658865e-01} - }, - { // a = 3 - {-9.927404163003614e-01, -9.619460504511647e-01, -9.073408014613273e-01, -8.302567088965966e-01, -7.325902337993169e-01, -6.167457880276481e-01, -4.855755959179479e-01, -3.423092737126247e-01, -1.904742330566806e-01, -3.380876425338892e-02, 1.238300984934756e-01, 2.785617030491334e-01, 4.265776402741575e-01, 5.642361984904343e-01, 6.881537322533672e-01, 7.952929854218481e-01, 8.830567874178292e-01, 9.494633358614275e-01}, - {-9.824889092920019e-01, -9.416986583232526e-01, -8.787171589479275e-01, -7.950256814092369e-01, -6.925867323817538e-01, -5.738015737454587e-01, -4.414544106880812e-01, -2.986472259694831e-01, -1.487270800496405e-01, 4.792371471985597e-03, 1.583133053787015e-01, 3.082382010388641e-01, 4.510544517248982e-01, 5.834173407157311e-01, 7.022300516974338e-01, 8.047210165392289e-01, 8.885268701941211e-01, 9.518538220458710e-01}, - {-9.700758123604537e-01, -9.202891565580816e-01, -8.499319751911004e-01, -7.605372739175675e-01, -6.540941092273742e-01, -5.329776953162680e-01, -3.998924667022931e-01, -2.578107011395917e-01, -1.099057957723520e-01, 4.051877786408334e-02, 1.901033901605648e-01, 3.355074618108145e-01, 4.734843749889841e-01, 6.009546177650399e-01, 7.150761166059388e-01, 8.133122649255592e-01, 8.935057475607323e-01, 9.540278442594630e-01}, - {-9.560135943888842e-01, -8.980570243572540e-01, -8.211742079281799e-01, -7.268482562554985e-01, -6.170540638861418e-01, -4.941195380654311e-01, -3.606595744420355e-01, -2.195159750236575e-01, -7.369538959516307e-02, 7.369538959516310e-02, 2.195159750236572e-01, 3.606595744420353e-01, 4.941195380654312e-01, 6.170540638861415e-01, 7.268482562554986e-01, 8.211742079281799e-01, 8.980570243572534e-01, 9.560135943888849e-01}, - {-9.406716018299898e-01, -8.752690235990669e-01, -7.925948396415901e-01, -6.940008697968770e-01, -5.814125292148909e-01, -4.570923251529789e-01, -3.235579576772019e-01, -1.835210867072505e-01, -3.982859819235517e-02, 1.045968327724419e-01, 2.468169713048031e-01, 3.839382955954997e-01, 5.131713325873237e-01, 6.318881063328614e-01, 7.376771018524569e-01, 8.283965454283431e-01, 9.022337344110721e-01, 9.578345626901899e-01} - }, - { // a = 4 - {-9.930626069197461e-01, -9.636259026153904e-01, -9.113914351713388e-01, -8.375714999820000e-01, -7.438947259655249e-01, -6.325562096613778e-01, -5.061651544605044e-01, -3.676835040083336e-01, -2.203564015650038e-01, -6.763599254962109e-02, 8.689970601284235e-02, 2.396310621188066e-01, 3.869824423142821e-01, 5.255076915542232e-01, 6.519749553303759e-01, 7.634539032404926e-01, 8.574256011734057e-01, 9.320680711544124e-01}, - {-9.832479622756365e-01, -9.442078032684286e-01, -8.838776492971402e-01, -8.036099153174605e-01, -7.051983471363626e-01, -5.908413054531469e-01, -4.630930918907747e-01, -3.248069526250779e-01, -1.790713055670388e-01, -2.914064845107950e-02, 1.216373353085339e-01, 2.698969250762572e-01, 4.123302795456282e-01, 5.457629155697068e-01, 6.672284715254208e-01, 7.740458928102649e-01, 8.639185558803630e-01, 9.352014348342639e-01}, - {-9.713431867658865e-01, -9.236354714303612e-01, -8.561509802194558e-01, -7.702909596414218e-01, -6.678777255585759e-01, -5.510914442276028e-01, -4.224199379905137e-01, -2.846047134068398e-01, -1.405821755931029e-01, 6.579175083963535e-03, 1.537443802667707e-01, 2.977792142157404e-01, 4.356176947021973e-01, 5.643289492029844e-01, 6.811833582361538e-01, 7.837211574147637e-01, 8.698423210174842e-01, 9.380574875508457e-01}, - {-9.578345626901899e-01, -9.022337344110721e-01, -8.283965454283431e-01, -7.376771018524569e-01, -6.318881063328614e-01, -5.131713325873237e-01, -3.839382955954997e-01, -2.468169713048031e-01, -1.045968327724419e-01, 3.982859819235517e-02, 1.835210867072505e-01, 3.235579576772019e-01, 4.570923251529789e-01, 5.814125292148909e-01, 6.940008697968770e-01, 7.925948396415901e-01, 8.752690235990669e-01, 9.406716018299898e-01}, - {-9.430733616755570e-01, -8.802590331203356e-01, -8.007634086732659e-01, -7.058162784628557e-01, -5.971873476945267e-01, -4.769626082578843e-01, -3.474693703678786e-01, -2.112213791304131e-01, -7.086646675516287e-02, 7.086646675516269e-02, 2.112213791304132e-01, 3.474693703678784e-01, 4.769626082578839e-01, 5.971873476945273e-01, 7.058162784628557e-01, 8.007634086732658e-01, 8.802590331203353e-01, 9.430733616755580e-01} - } -}; + {// a = 0 + {-9.915651684209310e-01, -9.558239495713977e-01, -8.926024664975554e-01, + -8.037049589725231e-01, -6.916870430603531e-01, -5.597708310739477e-01, + -4.117511614628424e-01, -2.518862256915055e-01, -8.477501304173533e-02, + 8.477501304173478e-02, 2.518862256915057e-01, 4.117511614628427e-01, + 5.597708310739473e-01, 6.916870430603532e-01, 8.037049589725230e-01, + 8.926024664975557e-01, 9.558239495713977e-01, 9.915651684209309e-01}, + {-9.797336964051945e-01, -9.326015038912652e-01, -8.600417793993865e-01, + -7.640396507241585e-01, -6.472148595497391e-01, -5.127543868123012e-01, + -3.643260782273030e-01, -2.059787211196644e-01, -4.203164174155230e-02, + 1.230431015517241e-01, 2.847427000467310e-01, 4.386564198796566e-01, + 5.805859208223142e-01, 7.066597926447641e-01, 8.134392081429099e-01, + 8.980119168242189e-01, 9.580727032124667e-01, 9.919970412322650e-01}, + {-9.654968151885738e-01, -9.082157910346329e-01, -8.275397282215858e-01, + -7.255134414001100e-01, -6.047702996728351e-01, -4.684346162700265e-01, + -3.200362544506315e-01, -1.634181053418361e-01, -2.636205500547094e-03, + 1.581454482593639e-01, 3.147628043959833e-01, 4.631596344267958e-01, + 5.994926081527394e-01, 7.202308583296615e-01, 8.222474817670050e-01, + 9.029007093915506e-01, 9.601032979053139e-01, 9.923868355049964e-01}, + {-9.494633358614275e-01, -8.830567874178292e-01, -7.952929854218481e-01, + -6.881537322533672e-01, -5.642361984904343e-01, -4.265776402741575e-01, + -2.785617030491334e-01, -1.238300984934756e-01, 3.380876425338892e-02, + 1.904742330566806e-01, 3.423092737126247e-01, 4.855755959179479e-01, + 6.167457880276481e-01, 7.325902337993169e-01, 8.302567088965966e-01, + 9.073408014613273e-01, 9.619460504511647e-01, 9.927404163003614e-01}, + {-9.320680711544124e-01, -8.574256011734057e-01, -7.634539032404926e-01, + -6.519749553303759e-01, -5.255076915542232e-01, -3.869824423142821e-01, + -2.396310621188066e-01, -8.689970601284235e-02, 6.763599254962109e-02, + 2.203564015650038e-01, 3.676835040083336e-01, 5.061651544605044e-01, + 6.325562096613778e-01, 7.438947259655249e-01, 8.375714999820000e-01, + 9.113914351713388e-01, 9.636259026153904e-01, 9.930626069197461e-01}}, + {// a = 1 + {-9.919970412322650e-01, -9.580727032124667e-01, -8.980119168242189e-01, + -8.134392081429099e-01, -7.066597926447641e-01, -5.805859208223142e-01, + -4.386564198796566e-01, -2.847427000467310e-01, -1.230431015517241e-01, + 4.203164174155230e-02, 2.059787211196644e-01, 3.643260782273030e-01, + 5.127543868123012e-01, 6.472148595497391e-01, 7.640396507241585e-01, + 8.600417793993865e-01, 9.326015038912652e-01, 9.797336964051945e-01}, + {-9.807437048939144e-01, -9.359344988126653e-01, -8.668779780899500e-01, + -7.753682609520556e-01, -6.637764022903112e-01, -5.349928640318862e-01, + -3.923531837139092e-01, -2.395517059229865e-01, -8.054593723882174e-02, + 8.054593723882221e-02, 2.395517059229864e-01, 3.923531837139091e-01, + 5.349928640318862e-01, 6.637764022903111e-01, 7.753682609520564e-01, + 8.668779780899500e-01, 9.359344988126651e-01, 9.807437048939139e-01}, + {-9.671715346739649e-01, -9.126285555530927e-01, -8.357160065906806e-01, + -7.382852879071825e-01, -6.227268653309460e-01, -4.918834487495606e-01, + -3.489757413144571e-01, -1.975220899813244e-01, -4.125151717547191e-02, + 1.159882277809087e-01, 2.703254675735441e-01, 4.179599547137846e-01, + 5.552564548060258e-01, 6.788342531396245e-01, 7.856503691197853e-01, + 8.730743731339660e-01, 9.389526537953393e-01, 9.816577547521641e-01}, + {-9.518538220458710e-01, -8.885268701941211e-01, -8.047210165392289e-01, + -7.022300516974338e-01, -5.834173407157311e-01, -4.510544517248982e-01, + -3.082382010388641e-01, -1.583133053787015e-01, -4.792371471985597e-03, + 1.487270800496405e-01, 2.986472259694831e-01, 4.414544106880812e-01, + 5.738015737454587e-01, 6.925867323817538e-01, 7.950256814092369e-01, + 8.787171589479275e-01, 9.416986583232526e-01, 9.824889092920019e-01}, + {-9.352014348342639e-01, -8.639185558803630e-01, -7.740458928102649e-01, + -6.672284715254208e-01, -5.457629155697068e-01, -4.123302795456282e-01, + -2.698969250762572e-01, -1.216373353085339e-01, 2.914064845107950e-02, + 1.790713055670388e-01, 3.248069526250779e-01, 4.630930918907747e-01, + 5.908413054531469e-01, 7.051983471363626e-01, 8.036099153174605e-01, + 8.838776492971402e-01, 9.442078032684286e-01, 9.832479622756365e-01}}, + {// a = 2 + {-9.923868355049964e-01, -9.601032979053139e-01, -9.029007093915506e-01, + -8.222474817670050e-01, -7.202308583296615e-01, -5.994926081527394e-01, + -4.631596344267958e-01, -3.147628043959833e-01, -1.581454482593639e-01, + 2.636205500547094e-03, 1.634181053418361e-01, 3.200362544506315e-01, + 4.684346162700265e-01, 6.047702996728351e-01, 7.255134414001100e-01, + 8.275397282215858e-01, 9.082157910346329e-01, 9.654968151885738e-01}, + {-9.816577547521641e-01, -9.389526537953393e-01, -8.730743731339660e-01, + -7.856503691197853e-01, -6.788342531396245e-01, -5.552564548060258e-01, + -4.179599547137846e-01, -2.703254675735441e-01, -1.159882277809087e-01, + 4.125151717547191e-02, 1.975220899813244e-01, 3.489757413144571e-01, + 4.918834487495606e-01, 6.227268653309460e-01, 7.382852879071825e-01, + 8.357160065906806e-01, 9.126285555530927e-01, 9.671715346739649e-01}, + {-9.686909783865258e-01, -9.166350766447443e-01, -8.431474467170091e-01, + -7.499101295243042e-01, -6.391003286370385e-01, -5.133127283086356e-01, + -3.754946217673181e-01, -2.288758312146870e-01, -7.689268019371842e-02, + 7.689268019371846e-02, 2.288758312146867e-01, 3.754946217673183e-01, + 5.133127283086359e-01, 6.391003286370388e-01, 7.499101295243040e-01, + 8.431474467170090e-01, 9.166350766447436e-01, 9.686909783865253e-01}, + {-9.540278442594630e-01, -8.935057475607323e-01, -8.133122649255592e-01, + -7.150761166059388e-01, -6.009546177650399e-01, -4.734843749889841e-01, + -3.355074618108145e-01, -1.901033901605648e-01, -4.051877786408334e-02, + 1.099057957723520e-01, 2.578107011395917e-01, 3.998924667022931e-01, + 5.329776953162680e-01, 6.540941092273742e-01, 7.605372739175675e-01, + 8.499319751911004e-01, 9.202891565580816e-01, 9.700758123604537e-01}, + {-9.380574875508457e-01, -8.698423210174842e-01, -7.837211574147637e-01, + -6.811833582361538e-01, -5.643289492029844e-01, -4.356176947021973e-01, + -2.977792142157404e-01, -1.537443802667707e-01, -6.579175083963535e-03, + 1.405821755931029e-01, 2.846047134068398e-01, 4.224199379905137e-01, + 5.510914442276028e-01, 6.678777255585759e-01, 7.702909596414218e-01, + 8.561509802194558e-01, 9.236354714303612e-01, 9.713431867658865e-01}}, + {// a = 3 + {-9.927404163003614e-01, -9.619460504511647e-01, -9.073408014613273e-01, + -8.302567088965966e-01, -7.325902337993169e-01, -6.167457880276481e-01, + -4.855755959179479e-01, -3.423092737126247e-01, -1.904742330566806e-01, + -3.380876425338892e-02, 1.238300984934756e-01, 2.785617030491334e-01, + 4.265776402741575e-01, 5.642361984904343e-01, 6.881537322533672e-01, + 7.952929854218481e-01, 8.830567874178292e-01, 9.494633358614275e-01}, + {-9.824889092920019e-01, -9.416986583232526e-01, -8.787171589479275e-01, + -7.950256814092369e-01, -6.925867323817538e-01, -5.738015737454587e-01, + -4.414544106880812e-01, -2.986472259694831e-01, -1.487270800496405e-01, + 4.792371471985597e-03, 1.583133053787015e-01, 3.082382010388641e-01, + 4.510544517248982e-01, 5.834173407157311e-01, 7.022300516974338e-01, + 8.047210165392289e-01, 8.885268701941211e-01, 9.518538220458710e-01}, + {-9.700758123604537e-01, -9.202891565580816e-01, -8.499319751911004e-01, + -7.605372739175675e-01, -6.540941092273742e-01, -5.329776953162680e-01, + -3.998924667022931e-01, -2.578107011395917e-01, -1.099057957723520e-01, + 4.051877786408334e-02, 1.901033901605648e-01, 3.355074618108145e-01, + 4.734843749889841e-01, 6.009546177650399e-01, 7.150761166059388e-01, + 8.133122649255592e-01, 8.935057475607323e-01, 9.540278442594630e-01}, + {-9.560135943888842e-01, -8.980570243572540e-01, -8.211742079281799e-01, + -7.268482562554985e-01, -6.170540638861418e-01, -4.941195380654311e-01, + -3.606595744420355e-01, -2.195159750236575e-01, -7.369538959516307e-02, + 7.369538959516310e-02, 2.195159750236572e-01, 3.606595744420353e-01, + 4.941195380654312e-01, 6.170540638861415e-01, 7.268482562554986e-01, + 8.211742079281799e-01, 8.980570243572534e-01, 9.560135943888849e-01}, + {-9.406716018299898e-01, -8.752690235990669e-01, -7.925948396415901e-01, + -6.940008697968770e-01, -5.814125292148909e-01, -4.570923251529789e-01, + -3.235579576772019e-01, -1.835210867072505e-01, -3.982859819235517e-02, + 1.045968327724419e-01, 2.468169713048031e-01, 3.839382955954997e-01, + 5.131713325873237e-01, 6.318881063328614e-01, 7.376771018524569e-01, + 8.283965454283431e-01, 9.022337344110721e-01, 9.578345626901899e-01}}, + {// a = 4 + {-9.930626069197461e-01, -9.636259026153904e-01, -9.113914351713388e-01, + -8.375714999820000e-01, -7.438947259655249e-01, -6.325562096613778e-01, + -5.061651544605044e-01, -3.676835040083336e-01, -2.203564015650038e-01, + -6.763599254962109e-02, 8.689970601284235e-02, 2.396310621188066e-01, + 3.869824423142821e-01, 5.255076915542232e-01, 6.519749553303759e-01, + 7.634539032404926e-01, 8.574256011734057e-01, 9.320680711544124e-01}, + {-9.832479622756365e-01, -9.442078032684286e-01, -8.838776492971402e-01, + -8.036099153174605e-01, -7.051983471363626e-01, -5.908413054531469e-01, + -4.630930918907747e-01, -3.248069526250779e-01, -1.790713055670388e-01, + -2.914064845107950e-02, 1.216373353085339e-01, 2.698969250762572e-01, + 4.123302795456282e-01, 5.457629155697068e-01, 6.672284715254208e-01, + 7.740458928102649e-01, 8.639185558803630e-01, 9.352014348342639e-01}, + {-9.713431867658865e-01, -9.236354714303612e-01, -8.561509802194558e-01, + -7.702909596414218e-01, -6.678777255585759e-01, -5.510914442276028e-01, + -4.224199379905137e-01, -2.846047134068398e-01, -1.405821755931029e-01, + 6.579175083963535e-03, 1.537443802667707e-01, 2.977792142157404e-01, + 4.356176947021973e-01, 5.643289492029844e-01, 6.811833582361538e-01, + 7.837211574147637e-01, 8.698423210174842e-01, 9.380574875508457e-01}, + {-9.578345626901899e-01, -9.022337344110721e-01, -8.283965454283431e-01, + -7.376771018524569e-01, -6.318881063328614e-01, -5.131713325873237e-01, + -3.839382955954997e-01, -2.468169713048031e-01, -1.045968327724419e-01, + 3.982859819235517e-02, 1.835210867072505e-01, 3.235579576772019e-01, + 4.570923251529789e-01, 5.814125292148909e-01, 6.940008697968770e-01, + 7.925948396415901e-01, 8.752690235990669e-01, 9.406716018299898e-01}, + {-9.430733616755570e-01, -8.802590331203356e-01, -8.007634086732659e-01, + -7.058162784628557e-01, -5.971873476945267e-01, -4.769626082578843e-01, + -3.474693703678786e-01, -2.112213791304131e-01, -7.086646675516287e-02, + 7.086646675516269e-02, 2.112213791304132e-01, 3.474693703678784e-01, + 4.769626082578839e-01, 5.971873476945273e-01, 7.058162784628557e-01, + 8.007634086732658e-01, 8.802590331203353e-01, 9.430733616755580e-01}}}; static double _gaussJacobiPt_19[5][5][19] = { - { // a = 0 - {-9.924068438435840e-01, -9.602081521348295e-01, -9.031559036148181e-01, -8.227146565371428e-01, -7.209661773352293e-01, -6.005453046616812e-01, -4.645707413759610e-01, -3.165640999636298e-01, -1.603586456402251e-01, -4.532915871182588e-17, 1.603586456402255e-01, 3.165640999636301e-01, 4.645707413759610e-01, 6.005453046616810e-01, 7.209661773352293e-01, 8.227146565371430e-01, 9.031559036148178e-01, 9.602081521348298e-01, 9.924068438435842e-01}, - {-9.817036105419110e-01, -9.391052741604416e-01, -8.733916961487305e-01, -7.861862699636901e-01, -6.796372314174222e-01, -5.563684459535231e-01, -4.194153033078046e-01, -2.721500897585415e-01, -1.181989852980638e-01, 3.864721284289620e-02, 1.945264276698457e-01, 3.456003984723762e-01, 4.881491930357941e-01, 6.186628101904733e-01, 7.339276228838024e-01, 8.311055544315803e-01, 9.078041339031377e-01, 9.621363259368234e-01, 9.927767143628865e-01}, - {-9.687656131034041e-01, -9.168338048468146e-01, -8.435213634582798e-01, -7.505063259676529e-01, -6.399607141264746e-01, -5.144730383465962e-01, -3.769835818281900e-01, -2.307144896090938e-01, -7.909392558417634e-02, 7.432440289595950e-02, 2.259445944613356e-01, 3.722128651635634e-01, 5.097008618096635e-01, 6.351860326618163e-01, 7.457271802768796e-01, 8.387334472666771e-01, 9.120252098183146e-01, 9.638860433241988e-01, 9.931122191922750e-01}, - {-9.541325657289441e-01, -8.937483372930265e-01, -8.137375397998309e-01, -7.157251890846623e-01, -6.018636940213240e-01, -4.746838938427767e-01, -3.370214029861148e-01, -1.919487394244451e-01, -4.270515565537299e-02, 1.073763332826841e-01, 2.549436795335277e-01, 3.967008181520774e-01, 5.294813697335221e-01, 6.503194177091137e-01, 7.565157996610259e-01, 8.456984585556585e-01, 9.158755965848563e-01, 9.654810111292242e-01, 9.934179359338322e-01}, - {-9.381925880961598e-01, -8.701262070446421e-01, -7.841928905697005e-01, -6.818787573429902e-01, -5.652792604234657e-01, -4.368488096626384e-01, -2.993110852898324e-01, -1.555905873293583e-01, -8.746639675228289e-03, 1.380933246873833e-01, 2.818011169668809e-01, 4.193148161952170e-01, 5.477042199321511e-01, 6.642334092163530e-01, 7.664191373856486e-01, 8.520838358367295e-01, 9.194022002927418e-01, 9.669409108013977e-01, 9.936976636433223e-01} - }, - { // a = 1 - {-9.927767143628865e-01, -9.621363259368234e-01, -9.078041339031377e-01, -8.311055544315803e-01, -7.339276228838024e-01, -6.186628101904733e-01, -4.881491930357941e-01, -3.456003984723762e-01, -1.945264276698457e-01, -3.864721284289620e-02, 1.181989852980638e-01, 2.721500897585415e-01, 4.194153033078046e-01, 5.563684459535231e-01, 6.796372314174222e-01, 7.861862699636901e-01, 8.733916961487305e-01, 9.391052741604416e-01, 9.817036105419110e-01}, - {-9.825722966045483e-01, -9.419762969597455e-01, -8.792947553235908e-01, -7.960019260777124e-01, -6.940510260622235e-01, -5.758319602618305e-01, -4.441157832790019e-01, -3.019898565087649e-01, -1.527855158021848e-01, 2.289005659682439e-16, 1.527855158021857e-01, 3.019898565087648e-01, 4.441157832790021e-01, 5.758319602618305e-01, 6.940510260622232e-01, 7.960019260777121e-01, 8.792947553235905e-01, 9.419762969597457e-01, 9.825722966045478e-01}, - {-9.702118352226099e-01, -9.206515031851537e-01, -8.506141897553071e-01, -7.616259702846082e-01, -6.556669138762707e-01, -5.351015124839219e-01, -4.026220096978030e-01, -2.611873147766147e-01, -1.139566025748227e-01, 3.578137274376932e-02, 1.846817927510595e-01, 3.294185154274714e-01, 4.667583859081779e-01, 5.936334619153820e-01, 7.072095391454226e-01, 8.049494340124221e-01, 8.846695584095992e-01, 9.445882416976967e-01, 9.833621839924535e-01}, - {-9.562048482655054e-01, -8.985002947097739e-01, -8.219518315937427e-01, -7.280361591823064e-01, -6.187196373985259e-01, -4.963201229057058e-01, -3.634412390034732e-01, -2.229125664979379e-01, -7.772787461820081e-02, 6.901926865596085e-02, 2.142016919024650e-01, 3.547253981975705e-01, 4.875955742268418e-01, 6.099804531094561e-01, 7.192716801502376e-01, 8.131398893527734e-01, 8.895842597576115e-01, 9.469747283673363e-01, 9.840835352168241e-01}, - {-9.409188193395728e-01, -8.757887952146138e-01, -7.934591851841005e-01, -6.952762130983182e-01, -5.831573214072102e-01, -4.593556577126222e-01, -3.263785236182557e-01, -1.869264081809693e-01, -4.383451773857224e-02, 9.998638036435302e-02, 2.416098761657177e-01, 3.781538232699593e-01, 5.068391888221000e-01, 6.250467245882182e-01, 7.303703378559132e-01, 8.206660817270313e-01, 8.940957291165776e-01, 9.491637909883229e-01, 9.847449039448798e-01} - }, - { // a = 2 - {-9.931122191922750e-01, -9.638860433241988e-01, -9.120252098183146e-01, -8.387334472666771e-01, -7.457271802768796e-01, -6.351860326618163e-01, -5.097008618096635e-01, -3.722128651635634e-01, -2.259445944613356e-01, -7.432440289595950e-02, 7.909392558417634e-02, 2.307144896090938e-01, 3.769835818281900e-01, 5.144730383465962e-01, 6.399607141264746e-01, 7.505063259676529e-01, 8.435213634582798e-01, 9.168338048468146e-01, 9.687656131034041e-01}, - {-9.833621839924535e-01, -9.445882416976967e-01, -8.846695584095992e-01, -8.049494340124221e-01, -7.072095391454226e-01, -5.936334619153820e-01, -4.667583859081779e-01, -3.294185154274714e-01, -1.846817927510595e-01, -3.578137274376932e-02, 1.139566025748227e-01, 2.611873147766147e-01, 4.026220096978030e-01, 5.351015124839219e-01, 6.556669138762707e-01, 7.616259702846082e-01, 8.506141897553071e-01, 9.206515031851537e-01, 9.702118352226099e-01}, - {-9.715298869015092e-01, -9.241330296344175e-01, -8.570883531701216e-01, -7.717880819083639e-01, -6.700428106461579e-01, -5.540187095782213e-01, -4.261876765017645e-01, -2.892737483770999e-01, -1.461947517314944e-01, 6.526506903617471e-17, 1.461947517314943e-01, 2.892737483771002e-01, 4.261876765017646e-01, 5.540187095782215e-01, 6.700428106461577e-01, 7.717880819083637e-01, 8.570883531701212e-01, 9.241330296344171e-01, 9.715298869015094e-01}, - {-9.580975732361291e-01, -9.028436165169708e-01, -8.294671774016156e-01, -7.393140219060632e-01, -6.341856925553612e-01, -5.162108026174503e-01, -3.877860952555865e-01, -2.515235262396889e-01, -1.101956939692327e-01, 3.332116272227584e-02, 1.761059725051167e-01, 3.152524302106142e-01, 4.479282475419564e-01, 5.714328923847800e-01, 6.832526907653459e-01, 7.811122875376469e-01, 8.630218377970922e-01, 9.273210396417414e-01, 9.727361037078076e-01}, - {-9.434139449248803e-01, -8.809754982163734e-01, -8.019556994543423e-01, -7.075770854962449e-01, -5.995989154410151e-01, -4.800948915950720e-01, -3.513786579154723e-01, -2.159492745201093e-01, -7.643923222398297e-02, 6.443816513809246e-02, 2.039422522098615e-01, 3.393586755707776e-01, 4.680524180005532e-01, 5.875192275027991e-01, 6.954345189343037e-01, 7.896989201972935e-01, 8.684799845070860e-01, 9.302512460396403e-01, 9.738441553234483e-01} - }, - { // a = 3 - {-9.934179359338322e-01, -9.654810111292242e-01, -9.158755965848563e-01, -8.456984585556585e-01, -7.565157996610259e-01, -6.503194177091137e-01, -5.294813697335221e-01, -3.967008181520774e-01, -2.549436795335277e-01, -1.073763332826841e-01, 4.270515565537299e-02, 1.919487394244451e-01, 3.370214029861148e-01, 4.746838938427767e-01, 6.018636940213240e-01, 7.157251890846623e-01, 8.137375397998309e-01, 8.937483372930265e-01, 9.541325657289441e-01}, - {-9.840835352168241e-01, -9.469747283673363e-01, -8.895842597576115e-01, -8.131398893527734e-01, -7.192716801502376e-01, -6.099804531094561e-01, -4.875955742268418e-01, -3.547253981975705e-01, -2.142016919024650e-01, -6.901926865596085e-02, 7.772787461820081e-02, 2.229125664979379e-01, 3.634412390034732e-01, 4.963201229057058e-01, 6.187196373985259e-01, 7.280361591823064e-01, 8.219518315937427e-01, 8.985002947097739e-01, 9.562048482655054e-01}, - {-9.727361037078076e-01, -9.273210396417414e-01, -8.630218377970922e-01, -7.811122875376469e-01, -6.832526907653459e-01, -5.714328923847800e-01, -4.479282475419564e-01, -3.152524302106142e-01, -1.761059725051167e-01, -3.332116272227584e-02, 1.101956939692327e-01, 2.515235262396889e-01, 3.877860952555865e-01, 5.162108026174503e-01, 6.341856925553612e-01, 7.393140219060632e-01, 8.294671774016156e-01, 9.028436165169708e-01, 9.580975732361291e-01}, - {-9.598331551372716e-01, -9.068290470846583e-01, -8.363697393818060e-01, -7.496849118004351e-01, -6.484294844485208e-01, -5.345632402111724e-01, -4.102977278024534e-01, -2.780492595141671e-01, -1.403905321985083e-01, 1.712118613001251e-16, 1.403905321985082e-01, 2.780492595141668e-01, 4.102977278024532e-01, 5.345632402111721e-01, 6.484294844485208e-01, 7.496849118004354e-01, 8.363697393818065e-01, 9.068290470846581e-01, 9.598331551372720e-01}, - {-9.457062435701694e-01, -8.857442001833971e-01, -8.097753194824441e-01, -7.189123398745034e-01, -6.147733966267394e-01, -4.992715873240594e-01, -3.745466083255027e-01, -2.429157943553277e-01, -1.068277382208775e-01, 3.118465840212984e-02, 1.685520081441182e-01, 3.027166648820372e-01, 4.311806441713941e-01, 5.515524780026212e-01, 6.615923289492358e-01, 7.592550290653267e-01, 8.427319868191872e-01, 9.104992318340046e-01, 9.614304199151867e-01} - }, - { // a = 4 - {-9.936976636433223e-01, -9.669409108013977e-01, -9.194022002927418e-01, -8.520838358367295e-01, -7.664191373856486e-01, -6.642334092163530e-01, -5.477042199321511e-01, -4.193148161952170e-01, -2.818011169668809e-01, -1.380933246873833e-01, 8.746639675228289e-03, 1.555905873293583e-01, 2.993110852898324e-01, 4.368488096626384e-01, 5.652792604234657e-01, 6.818787573429902e-01, 7.841928905697005e-01, 8.701262070446421e-01, 9.381925880961598e-01}, - {-9.847449039448798e-01, -9.491637909883229e-01, -8.940957291165776e-01, -8.206660817270313e-01, -7.303703378559132e-01, -6.250467245882182e-01, -5.068391888221000e-01, -3.781538232699593e-01, -2.416098761657177e-01, -9.998638036435302e-02, 4.383451773857224e-02, 1.869264081809693e-01, 3.263785236182557e-01, 4.593556577126222e-01, 5.831573214072102e-01, 6.952762130983182e-01, 7.934591851841005e-01, 8.757887952146138e-01, 9.409188193395728e-01}, - {-9.738441553234483e-01, -9.302512460396403e-01, -8.684799845070860e-01, -7.896989201972935e-01, -6.954345189343037e-01, -5.875192275027991e-01, -4.680524180005532e-01, -3.393586755707776e-01, -2.039422522098615e-01, -6.443816513809246e-02, 7.643923222398297e-02, 2.159492745201093e-01, 3.513786579154723e-01, 4.800948915950720e-01, 5.995989154410151e-01, 7.075770854962449e-01, 8.019556994543423e-01, 8.809754982163734e-01, 9.434139449248803e-01}, - {-9.614304199151867e-01, -9.104992318340046e-01, -8.427319868191872e-01, -7.592550290653267e-01, -6.615923289492358e-01, -5.515524780026212e-01, -4.311806441713941e-01, -3.027166648820372e-01, -1.685520081441182e-01, -3.118465840212984e-02, 1.068277382208775e-01, 2.429157943553277e-01, 3.745466083255027e-01, 4.992715873240594e-01, 6.147733966267394e-01, 7.189123398745034e-01, 8.097753194824441e-01, 8.857442001833971e-01, 9.457062435701694e-01}, - {-9.478195484252341e-01, -8.901437173510250e-01, -8.169964473303695e-01, -7.293926385108993e-01, -6.288240517036139e-01, -5.170595252735890e-01, -3.960819796175919e-01, -2.680442820640357e-01, -1.352277250309032e-01, 6.200982416265827e-17, 1.352277250309034e-01, 2.680442820640360e-01, 3.960819796175923e-01, 5.170595252735887e-01, 6.288240517036128e-01, 7.293926385108987e-01, 8.169964473303695e-01, 8.901437173510254e-01, 9.478195484252345e-01} - } -}; + {// a = 0 + {-9.924068438435840e-01, -9.602081521348295e-01, -9.031559036148181e-01, + -8.227146565371428e-01, -7.209661773352293e-01, -6.005453046616812e-01, + -4.645707413759610e-01, -3.165640999636298e-01, -1.603586456402251e-01, + -4.532915871182588e-17, 1.603586456402255e-01, 3.165640999636301e-01, + 4.645707413759610e-01, 6.005453046616810e-01, 7.209661773352293e-01, + 8.227146565371430e-01, 9.031559036148178e-01, 9.602081521348298e-01, + 9.924068438435842e-01}, + {-9.817036105419110e-01, -9.391052741604416e-01, -8.733916961487305e-01, + -7.861862699636901e-01, -6.796372314174222e-01, -5.563684459535231e-01, + -4.194153033078046e-01, -2.721500897585415e-01, -1.181989852980638e-01, + 3.864721284289620e-02, 1.945264276698457e-01, 3.456003984723762e-01, + 4.881491930357941e-01, 6.186628101904733e-01, 7.339276228838024e-01, + 8.311055544315803e-01, 9.078041339031377e-01, 9.621363259368234e-01, + 9.927767143628865e-01}, + {-9.687656131034041e-01, -9.168338048468146e-01, -8.435213634582798e-01, + -7.505063259676529e-01, -6.399607141264746e-01, -5.144730383465962e-01, + -3.769835818281900e-01, -2.307144896090938e-01, -7.909392558417634e-02, + 7.432440289595950e-02, 2.259445944613356e-01, 3.722128651635634e-01, + 5.097008618096635e-01, 6.351860326618163e-01, 7.457271802768796e-01, + 8.387334472666771e-01, 9.120252098183146e-01, 9.638860433241988e-01, + 9.931122191922750e-01}, + {-9.541325657289441e-01, -8.937483372930265e-01, -8.137375397998309e-01, + -7.157251890846623e-01, -6.018636940213240e-01, -4.746838938427767e-01, + -3.370214029861148e-01, -1.919487394244451e-01, -4.270515565537299e-02, + 1.073763332826841e-01, 2.549436795335277e-01, 3.967008181520774e-01, + 5.294813697335221e-01, 6.503194177091137e-01, 7.565157996610259e-01, + 8.456984585556585e-01, 9.158755965848563e-01, 9.654810111292242e-01, + 9.934179359338322e-01}, + {-9.381925880961598e-01, -8.701262070446421e-01, -7.841928905697005e-01, + -6.818787573429902e-01, -5.652792604234657e-01, -4.368488096626384e-01, + -2.993110852898324e-01, -1.555905873293583e-01, -8.746639675228289e-03, + 1.380933246873833e-01, 2.818011169668809e-01, 4.193148161952170e-01, + 5.477042199321511e-01, 6.642334092163530e-01, 7.664191373856486e-01, + 8.520838358367295e-01, 9.194022002927418e-01, 9.669409108013977e-01, + 9.936976636433223e-01}}, + {// a = 1 + {-9.927767143628865e-01, -9.621363259368234e-01, -9.078041339031377e-01, + -8.311055544315803e-01, -7.339276228838024e-01, -6.186628101904733e-01, + -4.881491930357941e-01, -3.456003984723762e-01, -1.945264276698457e-01, + -3.864721284289620e-02, 1.181989852980638e-01, 2.721500897585415e-01, + 4.194153033078046e-01, 5.563684459535231e-01, 6.796372314174222e-01, + 7.861862699636901e-01, 8.733916961487305e-01, 9.391052741604416e-01, + 9.817036105419110e-01}, + {-9.825722966045483e-01, -9.419762969597455e-01, -8.792947553235908e-01, + -7.960019260777124e-01, -6.940510260622235e-01, -5.758319602618305e-01, + -4.441157832790019e-01, -3.019898565087649e-01, -1.527855158021848e-01, + 2.289005659682439e-16, 1.527855158021857e-01, 3.019898565087648e-01, + 4.441157832790021e-01, 5.758319602618305e-01, 6.940510260622232e-01, + 7.960019260777121e-01, 8.792947553235905e-01, 9.419762969597457e-01, + 9.825722966045478e-01}, + {-9.702118352226099e-01, -9.206515031851537e-01, -8.506141897553071e-01, + -7.616259702846082e-01, -6.556669138762707e-01, -5.351015124839219e-01, + -4.026220096978030e-01, -2.611873147766147e-01, -1.139566025748227e-01, + 3.578137274376932e-02, 1.846817927510595e-01, 3.294185154274714e-01, + 4.667583859081779e-01, 5.936334619153820e-01, 7.072095391454226e-01, + 8.049494340124221e-01, 8.846695584095992e-01, 9.445882416976967e-01, + 9.833621839924535e-01}, + {-9.562048482655054e-01, -8.985002947097739e-01, -8.219518315937427e-01, + -7.280361591823064e-01, -6.187196373985259e-01, -4.963201229057058e-01, + -3.634412390034732e-01, -2.229125664979379e-01, -7.772787461820081e-02, + 6.901926865596085e-02, 2.142016919024650e-01, 3.547253981975705e-01, + 4.875955742268418e-01, 6.099804531094561e-01, 7.192716801502376e-01, + 8.131398893527734e-01, 8.895842597576115e-01, 9.469747283673363e-01, + 9.840835352168241e-01}, + {-9.409188193395728e-01, -8.757887952146138e-01, -7.934591851841005e-01, + -6.952762130983182e-01, -5.831573214072102e-01, -4.593556577126222e-01, + -3.263785236182557e-01, -1.869264081809693e-01, -4.383451773857224e-02, + 9.998638036435302e-02, 2.416098761657177e-01, 3.781538232699593e-01, + 5.068391888221000e-01, 6.250467245882182e-01, 7.303703378559132e-01, + 8.206660817270313e-01, 8.940957291165776e-01, 9.491637909883229e-01, + 9.847449039448798e-01}}, + {// a = 2 + {-9.931122191922750e-01, -9.638860433241988e-01, -9.120252098183146e-01, + -8.387334472666771e-01, -7.457271802768796e-01, -6.351860326618163e-01, + -5.097008618096635e-01, -3.722128651635634e-01, -2.259445944613356e-01, + -7.432440289595950e-02, 7.909392558417634e-02, 2.307144896090938e-01, + 3.769835818281900e-01, 5.144730383465962e-01, 6.399607141264746e-01, + 7.505063259676529e-01, 8.435213634582798e-01, 9.168338048468146e-01, + 9.687656131034041e-01}, + {-9.833621839924535e-01, -9.445882416976967e-01, -8.846695584095992e-01, + -8.049494340124221e-01, -7.072095391454226e-01, -5.936334619153820e-01, + -4.667583859081779e-01, -3.294185154274714e-01, -1.846817927510595e-01, + -3.578137274376932e-02, 1.139566025748227e-01, 2.611873147766147e-01, + 4.026220096978030e-01, 5.351015124839219e-01, 6.556669138762707e-01, + 7.616259702846082e-01, 8.506141897553071e-01, 9.206515031851537e-01, + 9.702118352226099e-01}, + {-9.715298869015092e-01, -9.241330296344175e-01, -8.570883531701216e-01, + -7.717880819083639e-01, -6.700428106461579e-01, -5.540187095782213e-01, + -4.261876765017645e-01, -2.892737483770999e-01, -1.461947517314944e-01, + 6.526506903617471e-17, 1.461947517314943e-01, 2.892737483771002e-01, + 4.261876765017646e-01, 5.540187095782215e-01, 6.700428106461577e-01, + 7.717880819083637e-01, 8.570883531701212e-01, 9.241330296344171e-01, + 9.715298869015094e-01}, + {-9.580975732361291e-01, -9.028436165169708e-01, -8.294671774016156e-01, + -7.393140219060632e-01, -6.341856925553612e-01, -5.162108026174503e-01, + -3.877860952555865e-01, -2.515235262396889e-01, -1.101956939692327e-01, + 3.332116272227584e-02, 1.761059725051167e-01, 3.152524302106142e-01, + 4.479282475419564e-01, 5.714328923847800e-01, 6.832526907653459e-01, + 7.811122875376469e-01, 8.630218377970922e-01, 9.273210396417414e-01, + 9.727361037078076e-01}, + {-9.434139449248803e-01, -8.809754982163734e-01, -8.019556994543423e-01, + -7.075770854962449e-01, -5.995989154410151e-01, -4.800948915950720e-01, + -3.513786579154723e-01, -2.159492745201093e-01, -7.643923222398297e-02, + 6.443816513809246e-02, 2.039422522098615e-01, 3.393586755707776e-01, + 4.680524180005532e-01, 5.875192275027991e-01, 6.954345189343037e-01, + 7.896989201972935e-01, 8.684799845070860e-01, 9.302512460396403e-01, + 9.738441553234483e-01}}, + {// a = 3 + {-9.934179359338322e-01, -9.654810111292242e-01, -9.158755965848563e-01, + -8.456984585556585e-01, -7.565157996610259e-01, -6.503194177091137e-01, + -5.294813697335221e-01, -3.967008181520774e-01, -2.549436795335277e-01, + -1.073763332826841e-01, 4.270515565537299e-02, 1.919487394244451e-01, + 3.370214029861148e-01, 4.746838938427767e-01, 6.018636940213240e-01, + 7.157251890846623e-01, 8.137375397998309e-01, 8.937483372930265e-01, + 9.541325657289441e-01}, + {-9.840835352168241e-01, -9.469747283673363e-01, -8.895842597576115e-01, + -8.131398893527734e-01, -7.192716801502376e-01, -6.099804531094561e-01, + -4.875955742268418e-01, -3.547253981975705e-01, -2.142016919024650e-01, + -6.901926865596085e-02, 7.772787461820081e-02, 2.229125664979379e-01, + 3.634412390034732e-01, 4.963201229057058e-01, 6.187196373985259e-01, + 7.280361591823064e-01, 8.219518315937427e-01, 8.985002947097739e-01, + 9.562048482655054e-01}, + {-9.727361037078076e-01, -9.273210396417414e-01, -8.630218377970922e-01, + -7.811122875376469e-01, -6.832526907653459e-01, -5.714328923847800e-01, + -4.479282475419564e-01, -3.152524302106142e-01, -1.761059725051167e-01, + -3.332116272227584e-02, 1.101956939692327e-01, 2.515235262396889e-01, + 3.877860952555865e-01, 5.162108026174503e-01, 6.341856925553612e-01, + 7.393140219060632e-01, 8.294671774016156e-01, 9.028436165169708e-01, + 9.580975732361291e-01}, + {-9.598331551372716e-01, -9.068290470846583e-01, -8.363697393818060e-01, + -7.496849118004351e-01, -6.484294844485208e-01, -5.345632402111724e-01, + -4.102977278024534e-01, -2.780492595141671e-01, -1.403905321985083e-01, + 1.712118613001251e-16, 1.403905321985082e-01, 2.780492595141668e-01, + 4.102977278024532e-01, 5.345632402111721e-01, 6.484294844485208e-01, + 7.496849118004354e-01, 8.363697393818065e-01, 9.068290470846581e-01, + 9.598331551372720e-01}, + {-9.457062435701694e-01, -8.857442001833971e-01, -8.097753194824441e-01, + -7.189123398745034e-01, -6.147733966267394e-01, -4.992715873240594e-01, + -3.745466083255027e-01, -2.429157943553277e-01, -1.068277382208775e-01, + 3.118465840212984e-02, 1.685520081441182e-01, 3.027166648820372e-01, + 4.311806441713941e-01, 5.515524780026212e-01, 6.615923289492358e-01, + 7.592550290653267e-01, 8.427319868191872e-01, 9.104992318340046e-01, + 9.614304199151867e-01}}, + {// a = 4 + {-9.936976636433223e-01, -9.669409108013977e-01, -9.194022002927418e-01, + -8.520838358367295e-01, -7.664191373856486e-01, -6.642334092163530e-01, + -5.477042199321511e-01, -4.193148161952170e-01, -2.818011169668809e-01, + -1.380933246873833e-01, 8.746639675228289e-03, 1.555905873293583e-01, + 2.993110852898324e-01, 4.368488096626384e-01, 5.652792604234657e-01, + 6.818787573429902e-01, 7.841928905697005e-01, 8.701262070446421e-01, + 9.381925880961598e-01}, + {-9.847449039448798e-01, -9.491637909883229e-01, -8.940957291165776e-01, + -8.206660817270313e-01, -7.303703378559132e-01, -6.250467245882182e-01, + -5.068391888221000e-01, -3.781538232699593e-01, -2.416098761657177e-01, + -9.998638036435302e-02, 4.383451773857224e-02, 1.869264081809693e-01, + 3.263785236182557e-01, 4.593556577126222e-01, 5.831573214072102e-01, + 6.952762130983182e-01, 7.934591851841005e-01, 8.757887952146138e-01, + 9.409188193395728e-01}, + {-9.738441553234483e-01, -9.302512460396403e-01, -8.684799845070860e-01, + -7.896989201972935e-01, -6.954345189343037e-01, -5.875192275027991e-01, + -4.680524180005532e-01, -3.393586755707776e-01, -2.039422522098615e-01, + -6.443816513809246e-02, 7.643923222398297e-02, 2.159492745201093e-01, + 3.513786579154723e-01, 4.800948915950720e-01, 5.995989154410151e-01, + 7.075770854962449e-01, 8.019556994543423e-01, 8.809754982163734e-01, + 9.434139449248803e-01}, + {-9.614304199151867e-01, -9.104992318340046e-01, -8.427319868191872e-01, + -7.592550290653267e-01, -6.615923289492358e-01, -5.515524780026212e-01, + -4.311806441713941e-01, -3.027166648820372e-01, -1.685520081441182e-01, + -3.118465840212984e-02, 1.068277382208775e-01, 2.429157943553277e-01, + 3.745466083255027e-01, 4.992715873240594e-01, 6.147733966267394e-01, + 7.189123398745034e-01, 8.097753194824441e-01, 8.857442001833971e-01, + 9.457062435701694e-01}, + {-9.478195484252341e-01, -8.901437173510250e-01, -8.169964473303695e-01, + -7.293926385108993e-01, -6.288240517036139e-01, -5.170595252735890e-01, + -3.960819796175919e-01, -2.680442820640357e-01, -1.352277250309032e-01, + 6.200982416265827e-17, 1.352277250309034e-01, 2.680442820640360e-01, + 3.960819796175923e-01, 5.170595252735887e-01, 6.288240517036128e-01, + 7.293926385108987e-01, 8.169964473303695e-01, 8.901437173510254e-01, + 9.478195484252345e-01}}}; static double _gaussJacobiPt_20[5][5][20] = { - { // a = 0 - {-9.931285991850952e-01, -9.639719272779143e-01, -9.122344282513257e-01, -8.391169718222189e-01, -7.463319064601509e-01, -6.360536807265149e-01, -5.108670019508269e-01, -3.737060887154198e-01, -2.277858511416452e-01, -7.652652113349705e-02, 7.652652113349773e-02, 2.277858511416454e-01, 3.737060887154196e-01, 5.108670019508272e-01, 6.360536807265154e-01, 7.463319064601509e-01, 8.391169718222189e-01, 9.122344282513255e-01, 9.639719272779136e-01, 9.931285991850951e-01}, - {-9.833999115858654e-01, -9.447138932948739e-01, -8.849310847263726e-01, -8.053917435869075e-01, -7.078735060717811e-01, -5.945550166731893e-01, -4.679677164713189e-01, -3.309393978110274e-01, -1.865310669670130e-01, -3.796857740714772e-02, 1.114294260739779e-01, 2.583256388312061e-01, 3.994386463281002e-01, 5.316162273728158e-01, 6.519057747289156e-01, 7.576202653526481e-01, 8.463983258207562e-01, 9.162571377644696e-01, 9.656375637094887e-01, 9.934477866618997e-01}, - {-9.715915776812837e-01, -9.242974243009963e-01, -8.573980298375014e-01, -7.722826058290941e-01, -6.707578292631232e-01, -5.549851840709735e-01, -4.274312220305754e-01, -2.908140915547353e-01, -1.480453163656539e-01, -2.167630965696736e-03, 1.437099181334871e-01, 2.864782597950937e-01, 4.230945756374549e-01, 5.506471612313897e-01, 6.664174930379810e-01, 7.679381846890263e-01, 8.530456164294296e-01, 9.199261990761861e-01, 9.671558237320242e-01, 9.937386325185127e-01}, - {-9.581845086238181e-01, -9.030451899112609e-01, -8.298209923457061e-01, -7.398548937355769e-01, -6.349447042574379e-01, -5.172146281327684e-01, -3.890564457287243e-01, -2.530767071271488e-01, -1.120422771293650e-01, 3.117654567263744e-02, 1.736647095100555e-01, 3.125218745772579e-01, 4.449215213686147e-01, 5.681685289058432e-01, 6.797540659287594e-01, 7.774066892722269e-01, 8.591386303112140e-01, 9.232864082692881e-01, 9.685454587723635e-01, 9.940047516128481e-01}, - {-9.435265556341332e-01, -8.812123690364497e-01, -8.023498337699549e-01, -7.081590575458313e-01, -6.003958035470570e-01, -4.811296541505814e-01, -3.526696582764543e-01, -2.175099154401632e-01, -7.827769544334341e-02, 6.231907170262852e-02, 2.015451357980186e-01, 3.366914836259650e-01, 4.651282390350354e-01, 5.843559500013151e-01, 6.920543004188958e-01, 7.861273205203085e-01, 8.647442419716747e-01, 9.263752833783981e-01, 9.698221655249791e-01, 9.942491690485675e-01} - }, - { // a = 1 - {-9.934477866618997e-01, -9.656375637094887e-01, -9.162571377644696e-01, -8.463983258207562e-01, -7.576202653526481e-01, -6.519057747289156e-01, -5.316162273728158e-01, -3.994386463281002e-01, -2.583256388312061e-01, -1.114294260739779e-01, 3.796857740714772e-02, 1.865310669670130e-01, 3.309393978110274e-01, 4.679677164713189e-01, 5.945550166731893e-01, 7.078735060717811e-01, 8.053917435869075e-01, 8.849310847263726e-01, 9.447138932948739e-01, 9.833999115858654e-01}, - {-9.841524384576462e-01, -9.472042839992285e-01, -8.900622901909047e-01, -8.139489276119214e-01, -7.204872399612022e-01, -6.116694382842588e-01, -4.898148751899025e-01, -3.575207101389196e-01, -2.176065851592846e-01, -7.305454001089838e-02, 7.305454001089846e-02, 2.176065851592850e-01, 3.575207101389195e-01, 4.898148751899022e-01, 6.116694382842589e-01, 7.204872399612018e-01, 8.139489276119213e-01, 8.900622901909043e-01, 9.472042839992284e-01, 9.841524384576464e-01}, - {-9.728490003223152e-01, -9.276220046420424e-01, -8.635890950328927e-01, -7.820188121879189e-01, -6.845646193893430e-01, -5.732081715663796e-01, -4.502154691435611e-01, -3.180898688918408e-01, -1.795208475273123e-01, -3.732914672814721e-02, 1.055906943388334e-01, 2.463292847437273e-01, 3.820216188437758e-01, 5.099054037185025e-01, 6.273772907633637e-01, 7.320458642347447e-01, 8.217802966869686e-01, 8.947536334874647e-01, 9.494795693351372e-01, 9.848396583490030e-01}, - {-9.599925533680100e-01, -9.071988008260675e-01, -8.370191490220766e-01, -7.506784236818881e-01, -6.498250129881387e-01, -5.364109703528316e-01, -4.126391323267534e-01, -2.809163094878119e-01, -1.438051101890145e-01, -3.973532273301354e-03, 1.358572040742253e-01, 2.729657381390465e-01, 4.046835976024960e-01, 5.284471699380933e-01, 6.418476163755474e-01, 7.426777597540268e-01, 8.289750254961494e-01, 8.990595560693609e-01, 9.515665127550957e-01, 9.854697234027601e-01}, - {-9.459130880025061e-01, -8.861795017091665e-01, -8.105000946410110e-01, -7.199833913967633e-01, -6.162413969143141e-01, -5.011799661761364e-01, -3.769307051321039e-01, -2.458022032072700e-01, -1.102338401037254e-01, 2.725096715742614e-02, 1.640923749944930e-01, 2.977421015068777e-01, 4.257110585991223e-01, 5.456158100705951e-01, 6.552230219023855e-01, 7.524910898128965e-01, 8.356081663539943e-01, 9.030258401954091e-01, 9.534876075209534e-01, 9.860494825021773e-01} - }, - { // a = 2 - {-9.937386325185127e-01, -9.671558237320242e-01, -9.199261990761861e-01, -8.530456164294296e-01, -7.679381846890263e-01, -6.664174930379810e-01, -5.506471612313897e-01, -4.230945756374549e-01, -2.864782597950937e-01, -1.437099181334871e-01, 2.167630965696736e-03, 1.480453163656539e-01, 2.908140915547353e-01, 4.274312220305754e-01, 5.549851840709735e-01, 6.707578292631232e-01, 7.722826058290941e-01, 8.573980298375014e-01, 9.242974243009963e-01, 9.715915776812837e-01}, - {-9.848396583490030e-01, -9.494795693351372e-01, -8.947536334874647e-01, -8.217802966869686e-01, -7.320458642347447e-01, -6.273772907633637e-01, -5.099054037185025e-01, -3.820216188437758e-01, -2.463292847437273e-01, -1.055906943388334e-01, 3.732914672814721e-02, 1.795208475273123e-01, 3.180898688918408e-01, 4.502154691435611e-01, 5.732081715663796e-01, 6.845646193893430e-01, 7.820188121879189e-01, 8.635890950328927e-01, 9.276220046420424e-01, 9.728490003223152e-01}, - {-9.739996980631568e-01, -9.306660538330068e-01, -8.692622359998137e-01, -7.909499184461404e-01, -6.972465925942919e-01, -5.899739481326430e-01, -4.712190610894856e-01, -3.432929478249571e-01, -2.086853191283322e-01, -7.001601826403463e-02, 7.001601826403488e-02, 2.086853191283322e-01, 3.432929478249571e-01, 4.712190610894858e-01, 5.899739481326426e-01, 6.972465925942918e-01, 7.909499184461403e-01, 8.692622359998134e-01, 9.306660538330068e-01, 9.739996980631566e-01}, - {-9.616504155940135e-01, -9.110097715946518e-01, -8.436291898796430e-01, -7.606286634638074e-01, -6.635235706432816e-01, -5.541123216395500e-01, -4.344285990374992e-01, -3.066997074854389e-01, -1.733038086619201e-01, -3.672511147229498e-02, 1.004926347760595e-01, 2.357936429264362e-01, 3.666577666363077e-01, 4.906474988000649e-01, 6.054534387450493e-01, 7.089374200734915e-01, 7.991726003810313e-01, 8.744801478869817e-01, 9.334637336715732e-01, 9.750567200195495e-01}, - {-9.481055003979928e-01, -8.907457878377200e-01, -8.179995202368456e-01, -7.308761083974978e-01, -6.308592355980930e-01, -5.197081762147855e-01, -3.993951562253618e-01, -2.720614769940173e-01, -1.399762483482133e-01, -5.494638151929874e-03, 1.289847373845600e-01, 2.610629129517353e-01, 3.883835497638911e-01, 5.086750923626424e-01, 6.197913974299832e-01, 7.197501567964062e-01, 8.067685347217822e-01, 8.792957531093589e-01, 9.360438621263841e-01, 9.760310691470183e-01} - }, - { // a = 3 - {-9.940047516128481e-01, -9.685454587723635e-01, -9.232864082692881e-01, -8.591386303112140e-01, -7.774066892722269e-01, -6.797540659287594e-01, -5.681685289058432e-01, -4.449215213686147e-01, -3.125218745772579e-01, -1.736647095100555e-01, -3.117654567263744e-02, 1.120422771293650e-01, 2.530767071271488e-01, 3.890564457287243e-01, 5.172146281327684e-01, 6.349447042574379e-01, 7.398548937355769e-01, 8.298209923457061e-01, 9.030451899112609e-01, 9.581845086238181e-01}, - {-9.854697234027601e-01, -9.515665127550957e-01, -8.990595560693609e-01, -8.289750254961494e-01, -7.426777597540268e-01, -6.418476163755474e-01, -5.284471699380933e-01, -4.046835976024960e-01, -2.729657381390465e-01, -1.358572040742253e-01, 3.973532273301354e-03, 1.438051101890145e-01, 2.809163094878119e-01, 4.126391323267534e-01, 5.364109703528316e-01, 6.498250129881387e-01, 7.506784236818881e-01, 8.370191490220766e-01, 9.071988008260675e-01, 9.599925533680100e-01}, - {-9.750567200195495e-01, -9.334637336715732e-01, -8.744801478869817e-01, -7.991726003810313e-01, -7.089374200734915e-01, -6.054534387450493e-01, -4.906474988000649e-01, -3.666577666363077e-01, -2.357936429264362e-01, -1.004926347760595e-01, 3.672511147229498e-02, 1.733038086619201e-01, 3.066997074854389e-01, 4.344285990374992e-01, 5.541123216395500e-01, 6.635235706432816e-01, 7.606286634638074e-01, 8.436291898796430e-01, 9.110097715946518e-01, 9.616504155940135e-01}, - {-9.631760954318513e-01, -9.145189742513045e-01, -8.497208044210458e-01, -7.698081976860754e-01, -6.761776737233162e-01, -5.704900044992628e-01, -4.546268952239742e-01, -3.306537887548358e-01, -2.007817797384749e-01, -6.732766017970912e-02, 6.732766017970879e-02, 2.007817797384753e-01, 3.306537887548358e-01, 4.546268952239739e-01, 5.704900044992632e-01, 6.761776737233161e-01, 7.698081976860757e-01, 8.497208044210460e-01, 9.145189742513045e-01, 9.631760954318507e-01}, - {-9.501266164899248e-01, -8.949581014155217e-01, -8.249236667203856e-01, -7.409443589443760e-01, -6.443888980269158e-01, -5.368848635844138e-01, -4.202608433938532e-01, -2.965068087081985e-01, -1.677371279190688e-01, -3.615317339296357e-02, 9.599491703313548e-02, 2.264470491500666e-01, 3.529720469273613e-01, 4.734060161816378e-01, 5.856896291267025e-01, 6.879038579984679e-01, 7.783040026070599e-01, 8.553530256947313e-01, 9.177610066872539e-01, 9.645848220828218e-01} - }, - { // a = 4 - {-9.942491690485675e-01, -9.698221655249791e-01, -9.263752833783981e-01, -8.647442419716747e-01, -7.861273205203085e-01, -6.920543004188958e-01, -5.843559500013151e-01, -4.651282390350354e-01, -3.366914836259650e-01, -2.015451357980186e-01, -6.231907170262852e-02, 7.827769544334341e-02, 2.175099154401632e-01, 3.526696582764543e-01, 4.811296541505814e-01, 6.003958035470570e-01, 7.081590575458313e-01, 8.023498337699549e-01, 8.812123690364497e-01, 9.435265556341332e-01}, - {-9.860494825021773e-01, -9.534876075209534e-01, -9.030258401954091e-01, -8.356081663539943e-01, -7.524910898128965e-01, -6.552230219023855e-01, -5.456158100705951e-01, -4.257110585991223e-01, -2.977421015068777e-01, -1.640923749944930e-01, -2.725096715742614e-02, 1.102338401037254e-01, 2.458022032072700e-01, 3.769307051321039e-01, 5.011799661761364e-01, 6.162413969143141e-01, 7.199833913967633e-01, 8.105000946410110e-01, 8.861795017091665e-01, 9.459130880025061e-01}, - {-9.760310691470183e-01, -9.360438621263841e-01, -8.792957531093589e-01, -8.067685347217822e-01, -7.197501567964062e-01, -6.197913974299832e-01, -5.086750923626424e-01, -3.883835497638911e-01, -2.610629129517353e-01, -1.289847373845600e-01, 5.494638151929874e-03, 1.399762483482133e-01, 2.720614769940173e-01, 3.993951562253618e-01, 5.197081762147855e-01, 6.308592355980930e-01, 7.308761083974978e-01, 8.179995202368456e-01, 8.907457878377200e-01, 9.481055003979928e-01}, - {-9.645848220828218e-01, -9.177610066872539e-01, -8.553530256947313e-01, -7.783040026070599e-01, -6.879038579984679e-01, -5.856896291267025e-01, -4.734060161816378e-01, -3.529720469273613e-01, -2.264470491500666e-01, -9.599491703313548e-02, 3.615317339296357e-02, 1.677371279190688e-01, 2.965068087081985e-01, 4.202608433938532e-01, 5.368848635844138e-01, 6.443888980269158e-01, 7.409443589443760e-01, 8.249236667203856e-01, 8.949581014155217e-01, 9.501266164899248e-01}, - {-9.519958077802642e-01, -8.988562490531128e-01, -8.313367459311208e-01, -7.502792899007257e-01, -6.569492492298097e-01, -5.528554873154808e-01, -4.396967278749787e-01, -3.193256384373270e-01, -1.937155739696671e-01, -6.492698686090238e-02, 6.492698686090227e-02, 1.937155739696671e-01, 3.193256384373275e-01, 4.396967278749784e-01, 5.528554873154808e-01, 6.569492492298099e-01, 7.502792899007257e-01, 8.313367459311209e-01, 8.988562490531121e-01, 9.519958077802642e-01} - } -}; + {// a = 0 + {-9.931285991850952e-01, -9.639719272779143e-01, -9.122344282513257e-01, + -8.391169718222189e-01, -7.463319064601509e-01, -6.360536807265149e-01, + -5.108670019508269e-01, -3.737060887154198e-01, -2.277858511416452e-01, + -7.652652113349705e-02, 7.652652113349773e-02, 2.277858511416454e-01, + 3.737060887154196e-01, 5.108670019508272e-01, 6.360536807265154e-01, + 7.463319064601509e-01, 8.391169718222189e-01, 9.122344282513255e-01, + 9.639719272779136e-01, 9.931285991850951e-01}, + {-9.833999115858654e-01, -9.447138932948739e-01, -8.849310847263726e-01, + -8.053917435869075e-01, -7.078735060717811e-01, -5.945550166731893e-01, + -4.679677164713189e-01, -3.309393978110274e-01, -1.865310669670130e-01, + -3.796857740714772e-02, 1.114294260739779e-01, 2.583256388312061e-01, + 3.994386463281002e-01, 5.316162273728158e-01, 6.519057747289156e-01, + 7.576202653526481e-01, 8.463983258207562e-01, 9.162571377644696e-01, + 9.656375637094887e-01, 9.934477866618997e-01}, + {-9.715915776812837e-01, -9.242974243009963e-01, -8.573980298375014e-01, + -7.722826058290941e-01, -6.707578292631232e-01, -5.549851840709735e-01, + -4.274312220305754e-01, -2.908140915547353e-01, -1.480453163656539e-01, + -2.167630965696736e-03, 1.437099181334871e-01, 2.864782597950937e-01, + 4.230945756374549e-01, 5.506471612313897e-01, 6.664174930379810e-01, + 7.679381846890263e-01, 8.530456164294296e-01, 9.199261990761861e-01, + 9.671558237320242e-01, 9.937386325185127e-01}, + {-9.581845086238181e-01, -9.030451899112609e-01, -8.298209923457061e-01, + -7.398548937355769e-01, -6.349447042574379e-01, -5.172146281327684e-01, + -3.890564457287243e-01, -2.530767071271488e-01, -1.120422771293650e-01, + 3.117654567263744e-02, 1.736647095100555e-01, 3.125218745772579e-01, + 4.449215213686147e-01, 5.681685289058432e-01, 6.797540659287594e-01, + 7.774066892722269e-01, 8.591386303112140e-01, 9.232864082692881e-01, + 9.685454587723635e-01, 9.940047516128481e-01}, + {-9.435265556341332e-01, -8.812123690364497e-01, -8.023498337699549e-01, + -7.081590575458313e-01, -6.003958035470570e-01, -4.811296541505814e-01, + -3.526696582764543e-01, -2.175099154401632e-01, -7.827769544334341e-02, + 6.231907170262852e-02, 2.015451357980186e-01, 3.366914836259650e-01, + 4.651282390350354e-01, 5.843559500013151e-01, 6.920543004188958e-01, + 7.861273205203085e-01, 8.647442419716747e-01, 9.263752833783981e-01, + 9.698221655249791e-01, 9.942491690485675e-01}}, + {// a = 1 + {-9.934477866618997e-01, -9.656375637094887e-01, -9.162571377644696e-01, + -8.463983258207562e-01, -7.576202653526481e-01, -6.519057747289156e-01, + -5.316162273728158e-01, -3.994386463281002e-01, -2.583256388312061e-01, + -1.114294260739779e-01, 3.796857740714772e-02, 1.865310669670130e-01, + 3.309393978110274e-01, 4.679677164713189e-01, 5.945550166731893e-01, + 7.078735060717811e-01, 8.053917435869075e-01, 8.849310847263726e-01, + 9.447138932948739e-01, 9.833999115858654e-01}, + {-9.841524384576462e-01, -9.472042839992285e-01, -8.900622901909047e-01, + -8.139489276119214e-01, -7.204872399612022e-01, -6.116694382842588e-01, + -4.898148751899025e-01, -3.575207101389196e-01, -2.176065851592846e-01, + -7.305454001089838e-02, 7.305454001089846e-02, 2.176065851592850e-01, + 3.575207101389195e-01, 4.898148751899022e-01, 6.116694382842589e-01, + 7.204872399612018e-01, 8.139489276119213e-01, 8.900622901909043e-01, + 9.472042839992284e-01, 9.841524384576464e-01}, + {-9.728490003223152e-01, -9.276220046420424e-01, -8.635890950328927e-01, + -7.820188121879189e-01, -6.845646193893430e-01, -5.732081715663796e-01, + -4.502154691435611e-01, -3.180898688918408e-01, -1.795208475273123e-01, + -3.732914672814721e-02, 1.055906943388334e-01, 2.463292847437273e-01, + 3.820216188437758e-01, 5.099054037185025e-01, 6.273772907633637e-01, + 7.320458642347447e-01, 8.217802966869686e-01, 8.947536334874647e-01, + 9.494795693351372e-01, 9.848396583490030e-01}, + {-9.599925533680100e-01, -9.071988008260675e-01, -8.370191490220766e-01, + -7.506784236818881e-01, -6.498250129881387e-01, -5.364109703528316e-01, + -4.126391323267534e-01, -2.809163094878119e-01, -1.438051101890145e-01, + -3.973532273301354e-03, 1.358572040742253e-01, 2.729657381390465e-01, + 4.046835976024960e-01, 5.284471699380933e-01, 6.418476163755474e-01, + 7.426777597540268e-01, 8.289750254961494e-01, 8.990595560693609e-01, + 9.515665127550957e-01, 9.854697234027601e-01}, + {-9.459130880025061e-01, -8.861795017091665e-01, -8.105000946410110e-01, + -7.199833913967633e-01, -6.162413969143141e-01, -5.011799661761364e-01, + -3.769307051321039e-01, -2.458022032072700e-01, -1.102338401037254e-01, + 2.725096715742614e-02, 1.640923749944930e-01, 2.977421015068777e-01, + 4.257110585991223e-01, 5.456158100705951e-01, 6.552230219023855e-01, + 7.524910898128965e-01, 8.356081663539943e-01, 9.030258401954091e-01, + 9.534876075209534e-01, 9.860494825021773e-01}}, + {// a = 2 + {-9.937386325185127e-01, -9.671558237320242e-01, -9.199261990761861e-01, + -8.530456164294296e-01, -7.679381846890263e-01, -6.664174930379810e-01, + -5.506471612313897e-01, -4.230945756374549e-01, -2.864782597950937e-01, + -1.437099181334871e-01, 2.167630965696736e-03, 1.480453163656539e-01, + 2.908140915547353e-01, 4.274312220305754e-01, 5.549851840709735e-01, + 6.707578292631232e-01, 7.722826058290941e-01, 8.573980298375014e-01, + 9.242974243009963e-01, 9.715915776812837e-01}, + {-9.848396583490030e-01, -9.494795693351372e-01, -8.947536334874647e-01, + -8.217802966869686e-01, -7.320458642347447e-01, -6.273772907633637e-01, + -5.099054037185025e-01, -3.820216188437758e-01, -2.463292847437273e-01, + -1.055906943388334e-01, 3.732914672814721e-02, 1.795208475273123e-01, + 3.180898688918408e-01, 4.502154691435611e-01, 5.732081715663796e-01, + 6.845646193893430e-01, 7.820188121879189e-01, 8.635890950328927e-01, + 9.276220046420424e-01, 9.728490003223152e-01}, + {-9.739996980631568e-01, -9.306660538330068e-01, -8.692622359998137e-01, + -7.909499184461404e-01, -6.972465925942919e-01, -5.899739481326430e-01, + -4.712190610894856e-01, -3.432929478249571e-01, -2.086853191283322e-01, + -7.001601826403463e-02, 7.001601826403488e-02, 2.086853191283322e-01, + 3.432929478249571e-01, 4.712190610894858e-01, 5.899739481326426e-01, + 6.972465925942918e-01, 7.909499184461403e-01, 8.692622359998134e-01, + 9.306660538330068e-01, 9.739996980631566e-01}, + {-9.616504155940135e-01, -9.110097715946518e-01, -8.436291898796430e-01, + -7.606286634638074e-01, -6.635235706432816e-01, -5.541123216395500e-01, + -4.344285990374992e-01, -3.066997074854389e-01, -1.733038086619201e-01, + -3.672511147229498e-02, 1.004926347760595e-01, 2.357936429264362e-01, + 3.666577666363077e-01, 4.906474988000649e-01, 6.054534387450493e-01, + 7.089374200734915e-01, 7.991726003810313e-01, 8.744801478869817e-01, + 9.334637336715732e-01, 9.750567200195495e-01}, + {-9.481055003979928e-01, -8.907457878377200e-01, -8.179995202368456e-01, + -7.308761083974978e-01, -6.308592355980930e-01, -5.197081762147855e-01, + -3.993951562253618e-01, -2.720614769940173e-01, -1.399762483482133e-01, + -5.494638151929874e-03, 1.289847373845600e-01, 2.610629129517353e-01, + 3.883835497638911e-01, 5.086750923626424e-01, 6.197913974299832e-01, + 7.197501567964062e-01, 8.067685347217822e-01, 8.792957531093589e-01, + 9.360438621263841e-01, 9.760310691470183e-01}}, + {// a = 3 + {-9.940047516128481e-01, -9.685454587723635e-01, -9.232864082692881e-01, + -8.591386303112140e-01, -7.774066892722269e-01, -6.797540659287594e-01, + -5.681685289058432e-01, -4.449215213686147e-01, -3.125218745772579e-01, + -1.736647095100555e-01, -3.117654567263744e-02, 1.120422771293650e-01, + 2.530767071271488e-01, 3.890564457287243e-01, 5.172146281327684e-01, + 6.349447042574379e-01, 7.398548937355769e-01, 8.298209923457061e-01, + 9.030451899112609e-01, 9.581845086238181e-01}, + {-9.854697234027601e-01, -9.515665127550957e-01, -8.990595560693609e-01, + -8.289750254961494e-01, -7.426777597540268e-01, -6.418476163755474e-01, + -5.284471699380933e-01, -4.046835976024960e-01, -2.729657381390465e-01, + -1.358572040742253e-01, 3.973532273301354e-03, 1.438051101890145e-01, + 2.809163094878119e-01, 4.126391323267534e-01, 5.364109703528316e-01, + 6.498250129881387e-01, 7.506784236818881e-01, 8.370191490220766e-01, + 9.071988008260675e-01, 9.599925533680100e-01}, + {-9.750567200195495e-01, -9.334637336715732e-01, -8.744801478869817e-01, + -7.991726003810313e-01, -7.089374200734915e-01, -6.054534387450493e-01, + -4.906474988000649e-01, -3.666577666363077e-01, -2.357936429264362e-01, + -1.004926347760595e-01, 3.672511147229498e-02, 1.733038086619201e-01, + 3.066997074854389e-01, 4.344285990374992e-01, 5.541123216395500e-01, + 6.635235706432816e-01, 7.606286634638074e-01, 8.436291898796430e-01, + 9.110097715946518e-01, 9.616504155940135e-01}, + {-9.631760954318513e-01, -9.145189742513045e-01, -8.497208044210458e-01, + -7.698081976860754e-01, -6.761776737233162e-01, -5.704900044992628e-01, + -4.546268952239742e-01, -3.306537887548358e-01, -2.007817797384749e-01, + -6.732766017970912e-02, 6.732766017970879e-02, 2.007817797384753e-01, + 3.306537887548358e-01, 4.546268952239739e-01, 5.704900044992632e-01, + 6.761776737233161e-01, 7.698081976860757e-01, 8.497208044210460e-01, + 9.145189742513045e-01, 9.631760954318507e-01}, + {-9.501266164899248e-01, -8.949581014155217e-01, -8.249236667203856e-01, + -7.409443589443760e-01, -6.443888980269158e-01, -5.368848635844138e-01, + -4.202608433938532e-01, -2.965068087081985e-01, -1.677371279190688e-01, + -3.615317339296357e-02, 9.599491703313548e-02, 2.264470491500666e-01, + 3.529720469273613e-01, 4.734060161816378e-01, 5.856896291267025e-01, + 6.879038579984679e-01, 7.783040026070599e-01, 8.553530256947313e-01, + 9.177610066872539e-01, 9.645848220828218e-01}}, + {// a = 4 + {-9.942491690485675e-01, -9.698221655249791e-01, -9.263752833783981e-01, + -8.647442419716747e-01, -7.861273205203085e-01, -6.920543004188958e-01, + -5.843559500013151e-01, -4.651282390350354e-01, -3.366914836259650e-01, + -2.015451357980186e-01, -6.231907170262852e-02, 7.827769544334341e-02, + 2.175099154401632e-01, 3.526696582764543e-01, 4.811296541505814e-01, + 6.003958035470570e-01, 7.081590575458313e-01, 8.023498337699549e-01, + 8.812123690364497e-01, 9.435265556341332e-01}, + {-9.860494825021773e-01, -9.534876075209534e-01, -9.030258401954091e-01, + -8.356081663539943e-01, -7.524910898128965e-01, -6.552230219023855e-01, + -5.456158100705951e-01, -4.257110585991223e-01, -2.977421015068777e-01, + -1.640923749944930e-01, -2.725096715742614e-02, 1.102338401037254e-01, + 2.458022032072700e-01, 3.769307051321039e-01, 5.011799661761364e-01, + 6.162413969143141e-01, 7.199833913967633e-01, 8.105000946410110e-01, + 8.861795017091665e-01, 9.459130880025061e-01}, + {-9.760310691470183e-01, -9.360438621263841e-01, -8.792957531093589e-01, + -8.067685347217822e-01, -7.197501567964062e-01, -6.197913974299832e-01, + -5.086750923626424e-01, -3.883835497638911e-01, -2.610629129517353e-01, + -1.289847373845600e-01, 5.494638151929874e-03, 1.399762483482133e-01, + 2.720614769940173e-01, 3.993951562253618e-01, 5.197081762147855e-01, + 6.308592355980930e-01, 7.308761083974978e-01, 8.179995202368456e-01, + 8.907457878377200e-01, 9.481055003979928e-01}, + {-9.645848220828218e-01, -9.177610066872539e-01, -8.553530256947313e-01, + -7.783040026070599e-01, -6.879038579984679e-01, -5.856896291267025e-01, + -4.734060161816378e-01, -3.529720469273613e-01, -2.264470491500666e-01, + -9.599491703313548e-02, 3.615317339296357e-02, 1.677371279190688e-01, + 2.965068087081985e-01, 4.202608433938532e-01, 5.368848635844138e-01, + 6.443888980269158e-01, 7.409443589443760e-01, 8.249236667203856e-01, + 8.949581014155217e-01, 9.501266164899248e-01}, + {-9.519958077802642e-01, -8.988562490531128e-01, -8.313367459311208e-01, + -7.502792899007257e-01, -6.569492492298097e-01, -5.528554873154808e-01, + -4.396967278749787e-01, -3.193256384373270e-01, -1.937155739696671e-01, + -6.492698686090238e-02, 6.492698686090227e-02, 1.937155739696671e-01, + 3.193256384373275e-01, 4.396967278749784e-01, 5.528554873154808e-01, + 6.569492492298099e-01, 7.502792899007257e-01, 8.313367459311209e-01, + 8.988562490531121e-01, 9.519958077802642e-01}}}; -static double _gaussJacobiWt_1[5][5][1] = { - { // a = 0 - { 2.000000000000000e+00}, - { 2.000000000000000e+00}, - { 2.666666666666667e+00}, - { 3.999999999999999e+00}, - { 6.400000000000002e+00} - }, - { // a = 1 - { 2.000000000000000e+00}, - { 1.333333333333333e+00}, - { 1.333333333333333e+00}, - { 1.600000000000000e+00}, - { 2.133333333333333e+00} - }, - { // a = 2 - { 2.666666666666667e+00}, - { 1.333333333333333e+00}, - { 1.066666666666667e+00}, - { 1.066666666666667e+00}, - { 1.219047619047619e+00} - }, - { // a = 3 - { 3.999999999999999e+00}, - { 1.600000000000000e+00}, - { 1.066666666666667e+00}, - { 9.142857142857136e-01}, - { 9.142857142857136e-01} - }, - { // a = 4 - { 6.400000000000002e+00}, - { 2.133333333333333e+00}, - { 1.219047619047619e+00}, - { 9.142857142857136e-01}, - { 8.126984126984133e-01} - } -}; +static double _gaussJacobiWt_1[5][5][1] = {{// a = 0 + {2.000000000000000e+00}, + {2.000000000000000e+00}, + {2.666666666666667e+00}, + {3.999999999999999e+00}, + {6.400000000000002e+00}}, + {// a = 1 + {2.000000000000000e+00}, + {1.333333333333333e+00}, + {1.333333333333333e+00}, + {1.600000000000000e+00}, + {2.133333333333333e+00}}, + {// a = 2 + {2.666666666666667e+00}, + {1.333333333333333e+00}, + {1.066666666666667e+00}, + {1.066666666666667e+00}, + {1.219047619047619e+00}}, + {// a = 3 + {3.999999999999999e+00}, + {1.600000000000000e+00}, + {1.066666666666667e+00}, + {9.142857142857136e-01}, + {9.142857142857136e-01}}, + {// a = 4 + {6.400000000000002e+00}, + {2.133333333333333e+00}, + {1.219047619047619e+00}, + {9.142857142857136e-01}, + {8.126984126984133e-01}}}; static double _gaussJacobiWt_2[5][5][2] = { - { // a = 0 - { 9.999999999999998e-01, 9.999999999999998e-01}, - { 7.278344730240912e-01, 1.272165526975909e+00}, - { 8.062870566386036e-01, 1.860379610028064e+00}, - { 1.070483996910220e+00, 2.929516003089780e+00}, - { 1.570639752904591e+00, 4.829360247095410e+00} - }, - { // a = 1 - { 1.272165526975909e+00, 7.278344730240912e-01}, - { 6.666666666666665e-01, 6.666666666666665e-01}, - { 5.723857625084603e-01, 7.609475708248731e-01}, - { 6.178319863829406e-01, 9.821680136170595e-01}, - { 7.619047619047621e-01, 1.371428571428571e+00} - }, - { // a = 2 - { 1.860379610028064e+00, 8.062870566386036e-01}, - { 7.609475708248731e-01, 5.723857625084603e-01}, - { 5.333333333333332e-01, 5.333333333333332e-01}, - { 4.851462451783867e-01, 5.815204214882800e-01}, - { 5.162099145606410e-01, 7.028377044869784e-01} - }, - { // a = 3 - { 2.929516003089780e+00, 1.070483996910220e+00}, - { 9.821680136170595e-01, 6.178319863829406e-01}, - { 5.815204214882800e-01, 4.851462451783867e-01}, - { 4.571428571428567e-01, 4.571428571428567e-01}, - { 4.278171291840188e-01, 4.864685851016950e-01} - }, - { // a = 4 - { 4.829360247095410e+00, 1.570639752904591e+00}, - { 1.371428571428571e+00, 7.619047619047621e-01}, - { 7.028377044869784e-01, 5.162099145606410e-01}, - { 4.864685851016950e-01, 4.278171291840188e-01}, - { 4.063492063492065e-01, 4.063492063492065e-01} - } -}; + {// a = 0 + {9.999999999999998e-01, 9.999999999999998e-01}, + {7.278344730240912e-01, 1.272165526975909e+00}, + {8.062870566386036e-01, 1.860379610028064e+00}, + {1.070483996910220e+00, 2.929516003089780e+00}, + {1.570639752904591e+00, 4.829360247095410e+00}}, + {// a = 1 + {1.272165526975909e+00, 7.278344730240912e-01}, + {6.666666666666665e-01, 6.666666666666665e-01}, + {5.723857625084603e-01, 7.609475708248731e-01}, + {6.178319863829406e-01, 9.821680136170595e-01}, + {7.619047619047621e-01, 1.371428571428571e+00}}, + {// a = 2 + {1.860379610028064e+00, 8.062870566386036e-01}, + {7.609475708248731e-01, 5.723857625084603e-01}, + {5.333333333333332e-01, 5.333333333333332e-01}, + {4.851462451783867e-01, 5.815204214882800e-01}, + {5.162099145606410e-01, 7.028377044869784e-01}}, + {// a = 3 + {2.929516003089780e+00, 1.070483996910220e+00}, + {9.821680136170595e-01, 6.178319863829406e-01}, + {5.815204214882800e-01, 4.851462451783867e-01}, + {4.571428571428567e-01, 4.571428571428567e-01}, + {4.278171291840188e-01, 4.864685851016950e-01}}, + {// a = 4 + {4.829360247095410e+00, 1.570639752904591e+00}, + {1.371428571428571e+00, 7.619047619047621e-01}, + {7.028377044869784e-01, 5.162099145606410e-01}, + {4.864685851016950e-01, 4.278171291840188e-01}, + {4.063492063492065e-01, 4.063492063492065e-01}}}; static double _gaussJacobiWt_3[5][5][3] = { - { // a = 0 - { 5.555555555555554e-01, 8.888888888888888e-01, 5.555555555555551e-01}, - { 2.793079196058165e-01, 9.169644254383441e-01, 8.037276549558382e-01}, - { 2.396056240686457e-01, 1.169970154078928e+00, 1.257090888519093e+00}, - { 2.636649485227477e-01, 1.673598360908908e+00, 2.062736690568345e+00}, - { 3.350093498638904e-01, 2.568853550597510e+00, 3.496137099538602e+00} - }, - { // a = 1 - { 8.037276549558382e-01, 9.169644254383441e-01, 2.793079196058165e-01}, - { 3.111111111111109e-01, 7.111111111111114e-01, 3.111111111111109e-01}, - { 2.149692150245489e-01, 7.231217117171123e-01, 3.952424065916725e-01}, - { 1.969322326330964e-01, 8.572885350869465e-01, 5.457792322799566e-01}, - { 2.135584815618425e-01, 1.121471649365120e+00, 7.983032024063695e-01} - }, - { // a = 2 - { 1.257090888519093e+00, 1.169970154078928e+00, 2.396056240686457e-01}, - { 3.952424065916725e-01, 7.231217117171123e-01, 2.149692150245489e-01}, - { 2.285714285714288e-01, 6.095238095238090e-01, 2.285714285714287e-01}, - { 1.793761350221325e-01, 6.159564099114720e-01, 2.713341217330624e-01}, - { 1.697182757645627e-01, 7.013330305371294e-01, 3.479963127459271e-01} - }, - { // a = 3 - { 2.062736690568345e+00, 1.673598360908908e+00, 2.636649485227477e-01}, - { 5.457792322799566e-01, 8.572885350869465e-01, 1.969322326330964e-01}, - { 2.713341217330624e-01, 6.159564099114720e-01, 1.793761350221325e-01}, - { 1.862433862433863e-01, 5.417989417989422e-01, 1.862433862433863e-01}, - { 1.563116811307890e-01, 5.457163448164892e-01, 2.122576883384357e-01} - }, - { // a = 4 - { 3.496137099538602e+00, 2.568853550597510e+00, 3.350093498638904e-01}, - { 7.983032024063695e-01, 1.121471649365120e+00, 2.135584815618425e-01}, - { 3.479963127459271e-01, 7.013330305371294e-01, 1.697182757645627e-01}, - { 2.122576883384357e-01, 5.457163448164892e-01, 1.563116811307890e-01}, - { 1.600769600769601e-01, 4.925444925444932e-01, 1.600769600769602e-01} - } -}; + {// a = 0 + {5.555555555555554e-01, 8.888888888888888e-01, 5.555555555555551e-01}, + {2.793079196058165e-01, 9.169644254383441e-01, 8.037276549558382e-01}, + {2.396056240686457e-01, 1.169970154078928e+00, 1.257090888519093e+00}, + {2.636649485227477e-01, 1.673598360908908e+00, 2.062736690568345e+00}, + {3.350093498638904e-01, 2.568853550597510e+00, 3.496137099538602e+00}}, + {// a = 1 + {8.037276549558382e-01, 9.169644254383441e-01, 2.793079196058165e-01}, + {3.111111111111109e-01, 7.111111111111114e-01, 3.111111111111109e-01}, + {2.149692150245489e-01, 7.231217117171123e-01, 3.952424065916725e-01}, + {1.969322326330964e-01, 8.572885350869465e-01, 5.457792322799566e-01}, + {2.135584815618425e-01, 1.121471649365120e+00, 7.983032024063695e-01}}, + {// a = 2 + {1.257090888519093e+00, 1.169970154078928e+00, 2.396056240686457e-01}, + {3.952424065916725e-01, 7.231217117171123e-01, 2.149692150245489e-01}, + {2.285714285714288e-01, 6.095238095238090e-01, 2.285714285714287e-01}, + {1.793761350221325e-01, 6.159564099114720e-01, 2.713341217330624e-01}, + {1.697182757645627e-01, 7.013330305371294e-01, 3.479963127459271e-01}}, + {// a = 3 + {2.062736690568345e+00, 1.673598360908908e+00, 2.636649485227477e-01}, + {5.457792322799566e-01, 8.572885350869465e-01, 1.969322326330964e-01}, + {2.713341217330624e-01, 6.159564099114720e-01, 1.793761350221325e-01}, + {1.862433862433863e-01, 5.417989417989422e-01, 1.862433862433863e-01}, + {1.563116811307890e-01, 5.457163448164892e-01, 2.122576883384357e-01}}, + {// a = 4 + {3.496137099538602e+00, 2.568853550597510e+00, 3.350093498638904e-01}, + {7.983032024063695e-01, 1.121471649365120e+00, 2.135584815618425e-01}, + {3.479963127459271e-01, 7.013330305371294e-01, 1.697182757645627e-01}, + {2.122576883384357e-01, 5.457163448164892e-01, 1.563116811307890e-01}, + {1.600769600769601e-01, 4.925444925444932e-01, 1.600769600769602e-01}}}; static double _gaussJacobiWt_4[5][5][4] = { - { // a = 0 - { 3.478548451374539e-01, 6.521451548625463e-01, 6.521451548625460e-01, 3.478548451374541e-01}, - { 1.247238838000323e-01, 5.193901904329290e-01, 8.138582720410841e-01, 5.420276537259530e-01}, - { 8.281792599934459e-02, 5.490710973833848e-01, 1.147670318393714e+00, 8.871073248902248e-01}, - { 7.453387296111182e-02, 6.806675862842664e-01, 1.744069903018255e+00, 1.500728637736366e+00}, - { 8.052325269261341e-02, 9.334202291982018e-01, 2.786166786040798e+00, 2.599889732068390e+00} - }, - { // a = 1 - { 5.420276537259530e-01, 8.138582720410841e-01, 5.193901904329290e-01, 1.247238838000323e-01}, - { 1.569499125956940e-01, 5.097167540709726e-01, 5.097167540709733e-01, 1.569499125956941e-01}, - { 8.666291257402473e-02, 4.412333545929730e-01, 5.901533609926285e-01, 2.152837051737071e-01}, - { 6.638113568870473e-02, 4.612300776638222e-01, 7.590529887421843e-01, 3.133357979052909e-01}, - { 6.218189651967275e-02, 5.452982185335850e-01, 1.049649305865381e+00, 4.762039124146956e-01} - }, - { // a = 2 - { 8.871073248902248e-01, 1.147670318393714e+00, 5.490710973833848e-01, 8.281792599934459e-02}, - { 2.152837051737071e-01, 5.901533609926285e-01, 4.412333545929730e-01, 8.666291257402473e-02}, - { 1.017094468982020e-01, 4.316238864351311e-01, 4.316238864351309e-01, 1.017094468982023e-01}, - { 6.780964183677224e-02, 3.895640495203256e-01, 4.799597086802413e-01, 1.293332666293279e-01}, - { 5.607674171114099e-02, 4.044763521362413e-01, 5.840016959463765e-01, 1.744928292538610e-01} - }, - { // a = 3 - { 1.500728637736366e+00, 1.744069903018255e+00, 6.806675862842664e-01, 7.453387296111182e-02}, - { 3.133357979052909e-01, 7.590529887421843e-01, 4.612300776638222e-01, 6.638113568870473e-02}, - { 1.293332666293279e-01, 4.799597086802413e-01, 3.895640495203256e-01, 6.780964183677224e-02}, - { 7.633163504650844e-02, 3.808112220963483e-01, 3.808112220963482e-01, 7.633163504650840e-02}, - { 5.650779719733934e-02, 3.522705749121590e-01, 4.131267636004213e-01, 9.238057857579422e-02} - }, - { // a = 4 - { 2.599889732068390e+00, 2.786166786040798e+00, 9.334202291982018e-01, 8.052325269261341e-02}, - { 4.762039124146956e-01, 1.049649305865381e+00, 5.452982185335850e-01, 6.218189651967275e-02}, - { 1.744928292538610e-01, 5.840016959463765e-01, 4.044763521362413e-01, 5.607674171114099e-02}, - { 9.238057857579422e-02, 4.131267636004213e-01, 3.522705749121590e-01, 5.650779719733934e-02}, - { 6.190306686727069e-02, 3.444461394819360e-01, 3.444461394819356e-01, 6.190306686727064e-02} - } -}; + {// a = 0 + {3.478548451374539e-01, 6.521451548625463e-01, 6.521451548625460e-01, + 3.478548451374541e-01}, + {1.247238838000323e-01, 5.193901904329290e-01, 8.138582720410841e-01, + 5.420276537259530e-01}, + {8.281792599934459e-02, 5.490710973833848e-01, 1.147670318393714e+00, + 8.871073248902248e-01}, + {7.453387296111182e-02, 6.806675862842664e-01, 1.744069903018255e+00, + 1.500728637736366e+00}, + {8.052325269261341e-02, 9.334202291982018e-01, 2.786166786040798e+00, + 2.599889732068390e+00}}, + {// a = 1 + {5.420276537259530e-01, 8.138582720410841e-01, 5.193901904329290e-01, + 1.247238838000323e-01}, + {1.569499125956940e-01, 5.097167540709726e-01, 5.097167540709733e-01, + 1.569499125956941e-01}, + {8.666291257402473e-02, 4.412333545929730e-01, 5.901533609926285e-01, + 2.152837051737071e-01}, + {6.638113568870473e-02, 4.612300776638222e-01, 7.590529887421843e-01, + 3.133357979052909e-01}, + {6.218189651967275e-02, 5.452982185335850e-01, 1.049649305865381e+00, + 4.762039124146956e-01}}, + {// a = 2 + {8.871073248902248e-01, 1.147670318393714e+00, 5.490710973833848e-01, + 8.281792599934459e-02}, + {2.152837051737071e-01, 5.901533609926285e-01, 4.412333545929730e-01, + 8.666291257402473e-02}, + {1.017094468982020e-01, 4.316238864351311e-01, 4.316238864351309e-01, + 1.017094468982023e-01}, + {6.780964183677224e-02, 3.895640495203256e-01, 4.799597086802413e-01, + 1.293332666293279e-01}, + {5.607674171114099e-02, 4.044763521362413e-01, 5.840016959463765e-01, + 1.744928292538610e-01}}, + {// a = 3 + {1.500728637736366e+00, 1.744069903018255e+00, 6.806675862842664e-01, + 7.453387296111182e-02}, + {3.133357979052909e-01, 7.590529887421843e-01, 4.612300776638222e-01, + 6.638113568870473e-02}, + {1.293332666293279e-01, 4.799597086802413e-01, 3.895640495203256e-01, + 6.780964183677224e-02}, + {7.633163504650844e-02, 3.808112220963483e-01, 3.808112220963482e-01, + 7.633163504650840e-02}, + {5.650779719733934e-02, 3.522705749121590e-01, 4.131267636004213e-01, + 9.238057857579422e-02}}, + {// a = 4 + {2.599889732068390e+00, 2.786166786040798e+00, 9.334202291982018e-01, + 8.052325269261341e-02}, + {4.762039124146956e-01, 1.049649305865381e+00, 5.452982185335850e-01, + 6.218189651967275e-02}, + {1.744928292538610e-01, 5.840016959463765e-01, 4.044763521362413e-01, + 5.607674171114099e-02}, + {9.238057857579422e-02, 4.131267636004213e-01, 3.522705749121590e-01, + 5.650779719733934e-02}, + {6.190306686727069e-02, 3.444461394819360e-01, 3.444461394819356e-01, + 6.190306686727064e-02}}}; static double _gaussJacobiWt_5[5][5][5] = { - { // a = 0 - { 2.369268850561887e-01, 4.786286704993663e-01, 5.688888888888893e-01, 4.786286704993676e-01, 2.369268850561885e-01}, - { 6.299165808676893e-02, 2.956354802904664e-01, 5.855479483386790e-01, 6.686985523774791e-01, 3.871263609066063e-01}, - { 3.291060162479219e-02, 2.564448057836955e-01, 7.136012897727206e-01, 1.009591695199294e+00, 6.541182742861671e-01}, - { 2.433102994064120e-02, 2.713171978123492e-01, 9.671192512595976e-01, 1.605064071439325e+00, 1.132168449548085e+00}, - { 2.230326649360302e-02, 3.267373352151112e-01, 1.408783024172256e+00, 2.646806819262076e+00, 1.995369554856960e+00} - }, - { // a = 1 - { 3.871263609066063e-01, 6.686985523774791e-01, 5.855479483386790e-01, 2.956354802904664e-01, 6.299165808676893e-02}, - { 8.601768212280758e-02, 3.368394607343355e-01, 4.876190476190479e-01, 3.368394607343353e-01, 8.601768212280750e-02}, - { 3.831930848119028e-02, 2.452059739900081e-01, 4.967399704812981e-01, 4.282880432585657e-01, 1.247800371222710e-01}, - { 2.456646444319764e-02, 2.225592686751806e-01, 5.765700495773455e-01, 5.871497496181131e-01, 1.891544676861635e-01}, - { 1.980513588884996e-02, 2.339699037681826e-01, 7.329078641092172e-01, 8.501544609361894e-01, 2.964959686308937e-01} - }, - { // a = 2 - { 6.541182742861671e-01, 1.009591695199294e+00, 7.136012897727206e-01, 2.564448057836955e-01, 3.291060162479219e-02}, - { 1.247800371222710e-01, 4.282880432585657e-01, 4.967399704812981e-01, 2.452059739900081e-01, 3.831930848119028e-02}, - { 4.843727109064629e-02, 2.681764855231103e-01, 4.334391534391542e-01, 2.681764855231104e-01, 4.843727109064622e-02}, - { 2.741017806633719e-02, 2.129178606036481e-01, 4.390843794439510e-01, 3.222065654722181e-01, 6.504768308051222e-02}, - { 1.972253761462016e-02, 1.984881119078501e-01, 4.944191223907425e-01, 4.149098629289183e-01, 9.150798420548717e-02} - }, - { // a = 3 - { 1.132168449548085e+00, 1.605064071439325e+00, 9.671192512595976e-01, 2.713171978123492e-01, 2.433102994064120e-02}, - { 1.891544676861635e-01, 5.871497496181131e-01, 5.765700495773455e-01, 2.225592686751806e-01, 2.456646444319764e-02}, - { 6.504768308051222e-02, 3.222065654722181e-01, 4.390843794439510e-01, 2.129178606036481e-01, 2.741017806633719e-02}, - { 3.294330378740572e-02, 2.271817563376542e-01, 3.940355940355940e-01, 2.271817563376544e-01, 3.294330378740577e-02}, - { 2.140403046183203e-02, 1.901585833153595e-01, 3.978207020574319e-01, 2.629653755603543e-01, 4.193702289073592e-02} - }, - { // a = 4 - { 1.995369554856960e+00, 2.646806819262076e+00, 1.408783024172256e+00, 3.267373352151112e-01, 2.230326649360302e-02}, - { 2.964959686308937e-01, 8.501544609361894e-01, 7.329078641092172e-01, 2.339699037681826e-01, 1.980513588884996e-02}, - { 9.150798420548717e-02, 4.149098629289183e-01, 4.944191223907425e-01, 1.984881119078501e-01, 1.972253761462016e-02}, - { 4.193702289073592e-02, 2.629653755603543e-01, 3.978207020574319e-01, 1.901585833153595e-01, 2.140403046183203e-02}, - { 2.483803845828180e-02, 1.996485860283427e-01, 3.637251637251640e-01, 1.996485860283425e-01, 2.483803845828179e-02} - } -}; + {// a = 0 + {2.369268850561887e-01, 4.786286704993663e-01, 5.688888888888893e-01, + 4.786286704993676e-01, 2.369268850561885e-01}, + {6.299165808676893e-02, 2.956354802904664e-01, 5.855479483386790e-01, + 6.686985523774791e-01, 3.871263609066063e-01}, + {3.291060162479219e-02, 2.564448057836955e-01, 7.136012897727206e-01, + 1.009591695199294e+00, 6.541182742861671e-01}, + {2.433102994064120e-02, 2.713171978123492e-01, 9.671192512595976e-01, + 1.605064071439325e+00, 1.132168449548085e+00}, + {2.230326649360302e-02, 3.267373352151112e-01, 1.408783024172256e+00, + 2.646806819262076e+00, 1.995369554856960e+00}}, + {// a = 1 + {3.871263609066063e-01, 6.686985523774791e-01, 5.855479483386790e-01, + 2.956354802904664e-01, 6.299165808676893e-02}, + {8.601768212280758e-02, 3.368394607343355e-01, 4.876190476190479e-01, + 3.368394607343353e-01, 8.601768212280750e-02}, + {3.831930848119028e-02, 2.452059739900081e-01, 4.967399704812981e-01, + 4.282880432585657e-01, 1.247800371222710e-01}, + {2.456646444319764e-02, 2.225592686751806e-01, 5.765700495773455e-01, + 5.871497496181131e-01, 1.891544676861635e-01}, + {1.980513588884996e-02, 2.339699037681826e-01, 7.329078641092172e-01, + 8.501544609361894e-01, 2.964959686308937e-01}}, + {// a = 2 + {6.541182742861671e-01, 1.009591695199294e+00, 7.136012897727206e-01, + 2.564448057836955e-01, 3.291060162479219e-02}, + {1.247800371222710e-01, 4.282880432585657e-01, 4.967399704812981e-01, + 2.452059739900081e-01, 3.831930848119028e-02}, + {4.843727109064629e-02, 2.681764855231103e-01, 4.334391534391542e-01, + 2.681764855231104e-01, 4.843727109064622e-02}, + {2.741017806633719e-02, 2.129178606036481e-01, 4.390843794439510e-01, + 3.222065654722181e-01, 6.504768308051222e-02}, + {1.972253761462016e-02, 1.984881119078501e-01, 4.944191223907425e-01, + 4.149098629289183e-01, 9.150798420548717e-02}}, + {// a = 3 + {1.132168449548085e+00, 1.605064071439325e+00, 9.671192512595976e-01, + 2.713171978123492e-01, 2.433102994064120e-02}, + {1.891544676861635e-01, 5.871497496181131e-01, 5.765700495773455e-01, + 2.225592686751806e-01, 2.456646444319764e-02}, + {6.504768308051222e-02, 3.222065654722181e-01, 4.390843794439510e-01, + 2.129178606036481e-01, 2.741017806633719e-02}, + {3.294330378740572e-02, 2.271817563376542e-01, 3.940355940355940e-01, + 2.271817563376544e-01, 3.294330378740577e-02}, + {2.140403046183203e-02, 1.901585833153595e-01, 3.978207020574319e-01, + 2.629653755603543e-01, 4.193702289073592e-02}}, + {// a = 4 + {1.995369554856960e+00, 2.646806819262076e+00, 1.408783024172256e+00, + 3.267373352151112e-01, 2.230326649360302e-02}, + {2.964959686308937e-01, 8.501544609361894e-01, 7.329078641092172e-01, + 2.339699037681826e-01, 1.980513588884996e-02}, + {9.150798420548717e-02, 4.149098629289183e-01, 4.944191223907425e-01, + 1.984881119078501e-01, 1.972253761462016e-02}, + {4.193702289073592e-02, 2.629653755603543e-01, 3.978207020574319e-01, + 1.901585833153595e-01, 2.140403046183203e-02}, + {2.483803845828180e-02, 1.996485860283427e-01, 3.637251637251640e-01, + 1.996485860283425e-01, 2.483803845828179e-02}}}; static double _gaussJacobiWt_6[5][5][6] = { - { // a = 0 - { 1.713244923791702e-01, 3.607615730481386e-01, 4.679139345726911e-01, 4.679139345726911e-01, 3.607615730481376e-01, 1.713244923791706e-01}, - { 3.495320725443805e-02, 1.758206622020359e-01, 3.946446035626222e-01, 5.631702151527973e-01, 5.421699889260740e-01, 2.892413229020351e-01}, - { 1.464860645495436e-02, 1.257623774795602e-01, 4.103165690369300e-01, 7.566174939883293e-01, 8.590119978942456e-01, 5.003096218126468e-01}, - { 8.987373976578002e-03, 1.133650549076629e-01, 4.884190756130669e-01, 1.095092508282256e+00, 1.412815859853395e+00, 8.813201273670372e-01}, - { 7.021247827874482e-03, 1.192571020536328e-01, 6.386004701784105e-01, 1.671678537383974e+00, 2.388772810023287e+00, 1.574669832532825e+00} - }, - { // a = 1 - { 2.892413229020351e-01, 5.421699889260740e-01, 5.631702151527973e-01, 3.946446035626222e-01, 1.758206622020359e-01, 3.495320725443805e-02}, - { 5.058357701608170e-02, 2.216925320225180e-01, 3.943905576280664e-01, 3.943905576280665e-01, 2.216925320225174e-01, 5.058357701608157e-02}, - { 1.843529878587512e-02, 1.358529778168891e-01, 3.489876099449661e-01, 4.515030795218800e-01, 3.020152876737603e-01, 7.653907958996159e-02}, - { 9.961013589566662e-03, 1.066909507493963e-01, 3.604023838564919e-01, 5.679937419135328e-01, 4.351533970782932e-01, 1.197985128127204e-01}, - { 6.928693007278721e-03, 9.913784846400839e-02, 4.151288701788876e-01, 7.654986227904429e-01, 6.540853399480817e-01, 1.925539589446358e-01} - }, - { // a = 2 - { 5.003096218126468e-01, 8.590119978942456e-01, 7.566174939883293e-01, 4.103165690369300e-01, 1.257623774795602e-01, 1.464860645495436e-02}, - { 7.653907958996159e-02, 3.020152876737603e-01, 4.515030795218800e-01, 3.489876099449661e-01, 1.358529778168891e-01, 1.843529878587512e-02}, - { 2.467268662655667e-02, 1.616918610467478e-01, 3.469687856600291e-01, 3.469687856600285e-01, 1.616918610467480e-01, 2.467268662655670e-02}, - { 1.190918435049791e-02, 1.124106922355262e-01, 3.159318481963147e-01, 3.851301217260023e-01, 2.066707140383849e-01, 3.461410611994043e-02}, - { 7.465506062062473e-03, 9.349129673941403e-02, 3.248487564768479e-01, 4.638613909718463e-01, 2.789755555810522e-01, 5.040511321639656e-02} - }, - { // a = 3 - { 8.813201273670372e-01, 1.412815859853395e+00, 1.095092508282256e+00, 4.884190756130669e-01, 1.133650549076629e-01, 8.987373976578002e-03}, - { 1.197985128127204e-01, 4.351533970782932e-01, 5.679937419135328e-01, 3.604023838564919e-01, 1.066909507493963e-01, 9.961013589566662e-03}, - { 3.461410611994043e-02, 2.066707140383849e-01, 3.851301217260023e-01, 3.159318481963147e-01, 1.124106922355262e-01, 1.190918435049791e-02}, - { 1.509646565423384e-02, 1.288175931617939e-01, 3.132287983268299e-01, 3.132287983268291e-01, 1.288175931617941e-01, 1.509646565423381e-02}, - { 8.612784576503985e-03, 9.692537560473276e-02, 2.906135774136844e-01, 3.405664410139636e-01, 1.575185821600764e-01, 2.004895351675277e-02} - }, - { // a = 4 - { 1.574669832532825e+00, 2.388772810023287e+00, 1.671678537383974e+00, 6.386004701784105e-01, 1.192571020536328e-01, 7.021247827874482e-03}, - { 1.925539589446358e-01, 6.540853399480817e-01, 7.654986227904429e-01, 4.151288701788876e-01, 9.913784846400839e-02, 6.928693007278721e-03}, - { 5.040511321639656e-02, 2.789755555810522e-01, 4.638613909718463e-01, 3.248487564768479e-01, 9.349129673941403e-02, 7.465506062062473e-03}, - { 2.004895351675277e-02, 1.575185821600764e-01, 3.405664410139636e-01, 2.906135774136844e-01, 9.692537560473276e-02, 8.612784576503985e-03}, - { 1.049480686269434e-02, 1.081759676054256e-01, 2.876784318810869e-01, 2.876784318810872e-01, 1.081759676054254e-01, 1.049480686269431e-02} - } -}; + {// a = 0 + {1.713244923791702e-01, 3.607615730481386e-01, 4.679139345726911e-01, + 4.679139345726911e-01, 3.607615730481376e-01, 1.713244923791706e-01}, + {3.495320725443805e-02, 1.758206622020359e-01, 3.946446035626222e-01, + 5.631702151527973e-01, 5.421699889260740e-01, 2.892413229020351e-01}, + {1.464860645495436e-02, 1.257623774795602e-01, 4.103165690369300e-01, + 7.566174939883293e-01, 8.590119978942456e-01, 5.003096218126468e-01}, + {8.987373976578002e-03, 1.133650549076629e-01, 4.884190756130669e-01, + 1.095092508282256e+00, 1.412815859853395e+00, 8.813201273670372e-01}, + {7.021247827874482e-03, 1.192571020536328e-01, 6.386004701784105e-01, + 1.671678537383974e+00, 2.388772810023287e+00, 1.574669832532825e+00}}, + {// a = 1 + {2.892413229020351e-01, 5.421699889260740e-01, 5.631702151527973e-01, + 3.946446035626222e-01, 1.758206622020359e-01, 3.495320725443805e-02}, + {5.058357701608170e-02, 2.216925320225180e-01, 3.943905576280664e-01, + 3.943905576280665e-01, 2.216925320225174e-01, 5.058357701608157e-02}, + {1.843529878587512e-02, 1.358529778168891e-01, 3.489876099449661e-01, + 4.515030795218800e-01, 3.020152876737603e-01, 7.653907958996159e-02}, + {9.961013589566662e-03, 1.066909507493963e-01, 3.604023838564919e-01, + 5.679937419135328e-01, 4.351533970782932e-01, 1.197985128127204e-01}, + {6.928693007278721e-03, 9.913784846400839e-02, 4.151288701788876e-01, + 7.654986227904429e-01, 6.540853399480817e-01, 1.925539589446358e-01}}, + {// a = 2 + {5.003096218126468e-01, 8.590119978942456e-01, 7.566174939883293e-01, + 4.103165690369300e-01, 1.257623774795602e-01, 1.464860645495436e-02}, + {7.653907958996159e-02, 3.020152876737603e-01, 4.515030795218800e-01, + 3.489876099449661e-01, 1.358529778168891e-01, 1.843529878587512e-02}, + {2.467268662655667e-02, 1.616918610467478e-01, 3.469687856600291e-01, + 3.469687856600285e-01, 1.616918610467480e-01, 2.467268662655670e-02}, + {1.190918435049791e-02, 1.124106922355262e-01, 3.159318481963147e-01, + 3.851301217260023e-01, 2.066707140383849e-01, 3.461410611994043e-02}, + {7.465506062062473e-03, 9.349129673941403e-02, 3.248487564768479e-01, + 4.638613909718463e-01, 2.789755555810522e-01, 5.040511321639656e-02}}, + {// a = 3 + {8.813201273670372e-01, 1.412815859853395e+00, 1.095092508282256e+00, + 4.884190756130669e-01, 1.133650549076629e-01, 8.987373976578002e-03}, + {1.197985128127204e-01, 4.351533970782932e-01, 5.679937419135328e-01, + 3.604023838564919e-01, 1.066909507493963e-01, 9.961013589566662e-03}, + {3.461410611994043e-02, 2.066707140383849e-01, 3.851301217260023e-01, + 3.159318481963147e-01, 1.124106922355262e-01, 1.190918435049791e-02}, + {1.509646565423384e-02, 1.288175931617939e-01, 3.132287983268299e-01, + 3.132287983268291e-01, 1.288175931617941e-01, 1.509646565423381e-02}, + {8.612784576503985e-03, 9.692537560473276e-02, 2.906135774136844e-01, + 3.405664410139636e-01, 1.575185821600764e-01, 2.004895351675277e-02}}, + {// a = 4 + {1.574669832532825e+00, 2.388772810023287e+00, 1.671678537383974e+00, + 6.386004701784105e-01, 1.192571020536328e-01, 7.021247827874482e-03}, + {1.925539589446358e-01, 6.540853399480817e-01, 7.654986227904429e-01, + 4.151288701788876e-01, 9.913784846400839e-02, 6.928693007278721e-03}, + {5.040511321639656e-02, 2.789755555810522e-01, 4.638613909718463e-01, + 3.248487564768479e-01, 9.349129673941403e-02, 7.465506062062473e-03}, + {2.004895351675277e-02, 1.575185821600764e-01, 3.405664410139636e-01, + 2.906135774136844e-01, 9.692537560473276e-02, 8.612784576503985e-03}, + {1.049480686269434e-02, 1.081759676054256e-01, 2.876784318810869e-01, + 2.876784318810872e-01, 1.081759676054254e-01, 1.049480686269431e-02}}}; static double _gaussJacobiWt_7[5][5][7] = { - { // a = 0 - { 1.294849661688698e-01, 2.797053914892769e-01, 3.818300505051181e-01, 4.179591836734698e-01, 3.818300505051184e-01, 2.797053914892769e-01, 1.294849661688693e-01}, - { 2.085744881122954e-02, 1.096334268874941e-01, 2.655387858619662e-01, 4.285002627834957e-01, 5.095635891983534e-01, 4.420370327634995e-01, 2.238694536939636e-01}, - { 7.141504269513715e-03, 6.530340505843775e-02, 2.353776903162285e-01, 5.051710296711309e-01, 7.338704262383613e-01, 7.255905969014901e-01, 3.942120142115044e-01}, - { 3.678466030780718e-03, 5.036154251066968e-02, 2.449946740199021e-01, 6.559226976607052e-01, 1.116001569715522e+00, 1.224904981815210e+00, 7.041360682472115e-01}, - { 2.466358609245232e-03, 4.630428125875304e-02, 2.856629636061731e-01, 9.135309681033585e-01, 1.767195973241718e+00, 2.112699069906774e+00, 1.272140385273975e+00} - }, - { // a = 1 - { 2.238694536939636e-01, 4.420370327634995e-01, 5.095635891983534e-01, 4.285002627834957e-01, 2.655387858619662e-01, 1.096334268874941e-01, 2.085744881122954e-02}, - { 3.151620015049874e-02, 1.486404045834101e-01, 3.007504247445494e-01, 3.715192743764176e-01, 3.007504247445494e-01, 1.486404045834105e-01, 3.151620015049873e-02}, - { 9.532643339678785e-03, 7.715728171811140e-02, 2.305847060006972e-01, 3.781277874504896e-01, 3.752913023507270e-01, 2.133648594462040e-01, 4.927475302742602e-02}, - { 4.379899959590618e-03, 5.253609983883843e-02, 2.107827034784674e-01, 4.308341311075597e-01, 5.025896761789808e-01, 3.197482880841080e-01, 7.912920135245609e-02}, - { 2.642311378657445e-03, 4.312011267525697e-02, 2.185688182208882e-01, 5.335551901841303e-01, 7.100879649121659e-01, 4.955201006997029e-01, 1.298388352625310e-01} - }, - { // a = 2 - { 3.942120142115044e-01, 7.255905969014901e-01, 7.338704262383613e-01, 5.051710296711309e-01, 2.353776903162285e-01, 6.530340505843775e-02, 7.141504269513715e-03}, - { 4.927475302742602e-02, 2.133648594462040e-01, 3.752913023507270e-01, 3.781277874504896e-01, 2.305847060006972e-01, 7.715728171811140e-02, 9.532643339678785e-03}, - { 1.334549735945821e-02, 9.805327628228531e-02, 2.530621622477638e-01, 3.377447948876519e-01, 2.530621622477643e-01, 9.805327628228526e-02, 1.334549735945821e-02}, - { 5.533765135448010e-03, 5.972976517243198e-02, 2.059687370691036e-01, 3.422207058046752e-01, 3.020722731851695e-01, 1.317412132665570e-01, 1.940020703328168e-02}, - { 3.034276182623651e-03, 4.425535951665623e-02, 1.921252934435704e-01, 3.810336414431639e-01, 3.845887142013036e-01, 1.849354686244639e-01, 2.907486563583823e-02} - }, - { // a = 3 - { 7.041360682472115e-01, 1.224904981815210e+00, 1.116001569715522e+00, 6.559226976607052e-01, 2.449946740199021e-01, 5.036154251066968e-02, 3.678466030780718e-03}, - { 7.912920135245609e-02, 3.197482880841080e-01, 5.025896761789808e-01, 4.308341311075597e-01, 2.107827034784674e-01, 5.253609983883843e-02, 4.379899959590618e-03}, - { 1.940020703328168e-02, 1.317412132665570e-01, 3.020722731851695e-01, 3.422207058046752e-01, 2.059687370691036e-01, 5.972976517243198e-02, 5.533765135448010e-03}, - { 7.329141196234674e-03, 7.256869444637780e-02, 2.213628084751741e-01, 3.117644260501397e-01, 2.213628084751741e-01, 7.256869444637799e-02, 7.329141196234693e-03}, - { 3.683138566713657e-03, 4.898574137818602e-02, 1.875104432454986e-01, 3.149663131830458e-01, 2.561146864945805e-01, 9.293860268022443e-02, 1.008678873746496e-02} - }, - { // a = 4 - { 1.272140385273975e+00, 2.112699069906774e+00, 1.767195973241718e+00, 9.135309681033585e-01, 2.856629636061731e-01, 4.630428125875304e-02, 2.466358609245232e-03}, - { 1.298388352625310e-01, 4.955201006997029e-01, 7.100879649121659e-01, 5.335551901841303e-01, 2.185688182208882e-01, 4.312011267525697e-02, 2.642311378657445e-03}, - { 2.907486563583823e-02, 1.849354686244639e-01, 3.845887142013036e-01, 3.810336414431639e-01, 1.921252934435704e-01, 4.425535951665623e-02, 3.034276182623651e-03}, - { 1.008678873746496e-02, 9.293860268022443e-02, 2.561146864945805e-01, 3.149663131830458e-01, 1.875104432454986e-01, 4.898574137818602e-02, 3.683138566713657e-03}, - { 4.678245726339981e-03, 5.759754869493600e-02, 1.985833464378651e-01, 2.909801309801314e-01, 1.985833464378650e-01, 5.759754869493602e-02, 4.678245726340002e-03} - } -}; + {// a = 0 + {1.294849661688698e-01, 2.797053914892769e-01, 3.818300505051181e-01, + 4.179591836734698e-01, 3.818300505051184e-01, 2.797053914892769e-01, + 1.294849661688693e-01}, + {2.085744881122954e-02, 1.096334268874941e-01, 2.655387858619662e-01, + 4.285002627834957e-01, 5.095635891983534e-01, 4.420370327634995e-01, + 2.238694536939636e-01}, + {7.141504269513715e-03, 6.530340505843775e-02, 2.353776903162285e-01, + 5.051710296711309e-01, 7.338704262383613e-01, 7.255905969014901e-01, + 3.942120142115044e-01}, + {3.678466030780718e-03, 5.036154251066968e-02, 2.449946740199021e-01, + 6.559226976607052e-01, 1.116001569715522e+00, 1.224904981815210e+00, + 7.041360682472115e-01}, + {2.466358609245232e-03, 4.630428125875304e-02, 2.856629636061731e-01, + 9.135309681033585e-01, 1.767195973241718e+00, 2.112699069906774e+00, + 1.272140385273975e+00}}, + {// a = 1 + {2.238694536939636e-01, 4.420370327634995e-01, 5.095635891983534e-01, + 4.285002627834957e-01, 2.655387858619662e-01, 1.096334268874941e-01, + 2.085744881122954e-02}, + {3.151620015049874e-02, 1.486404045834101e-01, 3.007504247445494e-01, + 3.715192743764176e-01, 3.007504247445494e-01, 1.486404045834105e-01, + 3.151620015049873e-02}, + {9.532643339678785e-03, 7.715728171811140e-02, 2.305847060006972e-01, + 3.781277874504896e-01, 3.752913023507270e-01, 2.133648594462040e-01, + 4.927475302742602e-02}, + {4.379899959590618e-03, 5.253609983883843e-02, 2.107827034784674e-01, + 4.308341311075597e-01, 5.025896761789808e-01, 3.197482880841080e-01, + 7.912920135245609e-02}, + {2.642311378657445e-03, 4.312011267525697e-02, 2.185688182208882e-01, + 5.335551901841303e-01, 7.100879649121659e-01, 4.955201006997029e-01, + 1.298388352625310e-01}}, + {// a = 2 + {3.942120142115044e-01, 7.255905969014901e-01, 7.338704262383613e-01, + 5.051710296711309e-01, 2.353776903162285e-01, 6.530340505843775e-02, + 7.141504269513715e-03}, + {4.927475302742602e-02, 2.133648594462040e-01, 3.752913023507270e-01, + 3.781277874504896e-01, 2.305847060006972e-01, 7.715728171811140e-02, + 9.532643339678785e-03}, + {1.334549735945821e-02, 9.805327628228531e-02, 2.530621622477638e-01, + 3.377447948876519e-01, 2.530621622477643e-01, 9.805327628228526e-02, + 1.334549735945821e-02}, + {5.533765135448010e-03, 5.972976517243198e-02, 2.059687370691036e-01, + 3.422207058046752e-01, 3.020722731851695e-01, 1.317412132665570e-01, + 1.940020703328168e-02}, + {3.034276182623651e-03, 4.425535951665623e-02, 1.921252934435704e-01, + 3.810336414431639e-01, 3.845887142013036e-01, 1.849354686244639e-01, + 2.907486563583823e-02}}, + {// a = 3 + {7.041360682472115e-01, 1.224904981815210e+00, 1.116001569715522e+00, + 6.559226976607052e-01, 2.449946740199021e-01, 5.036154251066968e-02, + 3.678466030780718e-03}, + {7.912920135245609e-02, 3.197482880841080e-01, 5.025896761789808e-01, + 4.308341311075597e-01, 2.107827034784674e-01, 5.253609983883843e-02, + 4.379899959590618e-03}, + {1.940020703328168e-02, 1.317412132665570e-01, 3.020722731851695e-01, + 3.422207058046752e-01, 2.059687370691036e-01, 5.972976517243198e-02, + 5.533765135448010e-03}, + {7.329141196234674e-03, 7.256869444637780e-02, 2.213628084751741e-01, + 3.117644260501397e-01, 2.213628084751741e-01, 7.256869444637799e-02, + 7.329141196234693e-03}, + {3.683138566713657e-03, 4.898574137818602e-02, 1.875104432454986e-01, + 3.149663131830458e-01, 2.561146864945805e-01, 9.293860268022443e-02, + 1.008678873746496e-02}}, + {// a = 4 + {1.272140385273975e+00, 2.112699069906774e+00, 1.767195973241718e+00, + 9.135309681033585e-01, 2.856629636061731e-01, 4.630428125875304e-02, + 2.466358609245232e-03}, + {1.298388352625310e-01, 4.955201006997029e-01, 7.100879649121659e-01, + 5.335551901841303e-01, 2.185688182208882e-01, 4.312011267525697e-02, + 2.642311378657445e-03}, + {2.907486563583823e-02, 1.849354686244639e-01, 3.845887142013036e-01, + 3.810336414431639e-01, 1.921252934435704e-01, 4.425535951665623e-02, + 3.034276182623651e-03}, + {1.008678873746496e-02, 9.293860268022443e-02, 2.561146864945805e-01, + 3.149663131830458e-01, 1.875104432454986e-01, 4.898574137818602e-02, + 3.683138566713657e-03}, + {4.678245726339981e-03, 5.759754869493600e-02, 1.985833464378651e-01, + 2.909801309801314e-01, 1.985833464378650e-01, 5.759754869493602e-02, + 4.678245726340002e-03}}}; static double _gaussJacobiWt_8[5][5][8] = { - { // a = 0 - { 1.012285362903761e-01, 2.223810344533746e-01, 3.137066458778874e-01, 3.626837833783613e-01, 3.626837833783629e-01, 3.137066458778879e-01, 2.223810344533742e-01, 1.012285362903756e-01}, - { 1.318076576899512e-02, 7.137161062394448e-02, 1.817572780187955e-01, 3.167983979692773e-01, 4.241894377437207e-01, 4.500231978835504e-01, 3.644760945454947e-01, 1.782032174462240e-01}, - { 3.748142272277550e-03, 3.579617370411527e-02, 1.379749102418798e-01, 3.265154111083508e-01, 5.475774673732261e-01, 6.822781533755100e-01, 6.145447461377790e-01, 3.182316624535267e-01}, - { 1.639361248317194e-03, 2.377094533317060e-02, 1.256811814607175e-01, 3.781052906942359e-01, 7.592700769857601e-01, 1.077789430280474e+00, 1.058912565145634e+00, 5.748311488516893e-01}, - { 9.506953721303734e-04, 1.916640120390382e-02, 1.304935723309592e-01, 4.771178704140306e-01, 1.111038421145520e+00, 1.757123113317146e+00, 1.856018088575039e+00, 1.048091837641275e+00} - }, - { // a = 1 - { 1.782032174462240e-01, 3.644760945454947e-01, 4.500231978835504e-01, 4.241894377437207e-01, 3.167983979692773e-01, 1.817572780187955e-01, 7.137161062394448e-02, 1.318076576899512e-02}, - { 2.059009564912193e-02, 1.021477023603583e-01, 2.253365549698582e-01, 3.185923136873289e-01, 3.185923136873280e-01, 2.253365549698585e-01, 1.021477023603587e-01, 2.059009564912189e-02}, - { 5.238552377780736e-03, 4.528118112126706e-02, 1.500406762783725e-01, 2.870401661205415e-01, 3.597380415060730e-01, 3.002369137811520e-01, 1.527157338016535e-01, 3.304206834649234e-02}, - { 2.065739340562864e-03, 2.685329227552708e-02, 1.213601585989501e-01, 2.944871735464791e-01, 4.423861616913500e-01, 4.224558133538641e-01, 2.362061416285682e-01, 5.418551956469873e-02}, - { 1.087611730783180e-03, 1.950920488347055e-02, 1.130503382722116e-01, 3.329077231648351e-01, 5.806711112295920e-01, 6.202631214886722e-01, 3.753897779892454e-01, 9.045444457452227e-02} - }, - { // a = 2 - { 3.182316624535267e-01, 6.145447461377790e-01, 6.822781533755100e-01, 5.475774673732261e-01, 3.265154111083508e-01, 1.379749102418798e-01, 3.579617370411527e-02, 3.748142272277550e-03}, - { 3.304206834649234e-02, 1.527157338016535e-01, 3.002369137811520e-01, 3.597380415060730e-01, 2.870401661205415e-01, 1.500406762783725e-01, 4.528118112126706e-02, 5.238552377780736e-03}, - { 7.604803485383861e-03, 6.061158316018715e-02, 1.777998015448418e-01, 2.873171451429209e-01, 2.873171451429211e-01, 1.777998015448412e-01, 6.061158316018710e-02, 7.604803485383872e-03}, - { 2.729955919133130e-03, 3.245563265976652e-02, 1.291970707835632e-01, 2.642124004061389e-01, 3.168304818118640e-01, 2.250337703756065e-01, 8.482314252379990e-02, 1.138421218679475e-02}, - { 1.316071835548569e-03, 2.144888716307647e-02, 1.090504123249688e-01, 2.702184288613528e-01, 3.764958077560768e-01, 2.999974929296935e-01, 1.230408981710883e-01, 1.747962000581336e-02} - }, - { // a = 3 - { 5.748311488516893e-01, 1.058912565145634e+00, 1.077789430280474e+00, 7.592700769857601e-01, 3.781052906942359e-01, 1.256811814607175e-01, 2.377094533317060e-02, 1.639361248317194e-03}, - { 5.418551956469873e-02, 2.362061416285682e-01, 4.224558133538641e-01, 4.423861616913500e-01, 2.944871735464791e-01, 1.213601585989501e-01, 2.685329227552708e-02, 2.065739340562864e-03}, - { 1.138421218679475e-02, 8.482314252379990e-02, 2.250337703756065e-01, 3.168304818118640e-01, 2.642124004061389e-01, 1.291970707835632e-01, 3.245563265976652e-02, 2.729955919133130e-03}, - { 3.750222228158977e-03, 4.138608360546010e-02, 1.483214149682089e-01, 2.636851363410289e-01, 2.636851363410289e-01, 1.483214149682089e-01, 4.138608360546023e-02, 3.750222228158972e-03}, - { 1.667252698843120e-03, 2.507758136623631e-02, 1.143814533710352e-01, 2.459996537221724e-01, 2.859103573133612e-01, 1.808092061439313e-01, 5.512024438244439e-02, 5.319965287689448e-03} - }, - { // a = 4 - { 1.048091837641275e+00, 1.856018088575039e+00, 1.757123113317146e+00, 1.111038421145520e+00, 4.771178704140306e-01, 1.304935723309592e-01, 1.916640120390382e-02, 9.506953721303734e-04}, - { 9.045444457452227e-02, 3.753897779892454e-01, 6.202631214886722e-01, 5.806711112295920e-01, 3.329077231648351e-01, 1.130503382722116e-01, 1.950920488347055e-02, 1.087611730783180e-03}, - { 1.747962000581336e-02, 1.230408981710883e-01, 2.999974929296935e-01, 3.764958077560768e-01, 2.702184288613528e-01, 1.090504123249688e-01, 2.144888716307647e-02, 1.316071835548569e-03}, - { 5.319965287689448e-03, 5.512024438244439e-02, 1.808092061439313e-01, 2.859103573133612e-01, 2.459996537221724e-01, 1.143814533710352e-01, 2.507758136623631e-02, 1.667252698843120e-03}, - { 2.194344706426763e-03, 3.083030321571734e-02, 1.282931004441076e-01, 2.450314579829549e-01, 2.450314579829549e-01, 1.282931004441075e-01, 3.083030321571735e-02, 2.194344706426775e-03} - } -}; + {// a = 0 + {1.012285362903761e-01, 2.223810344533746e-01, 3.137066458778874e-01, + 3.626837833783613e-01, 3.626837833783629e-01, 3.137066458778879e-01, + 2.223810344533742e-01, 1.012285362903756e-01}, + {1.318076576899512e-02, 7.137161062394448e-02, 1.817572780187955e-01, + 3.167983979692773e-01, 4.241894377437207e-01, 4.500231978835504e-01, + 3.644760945454947e-01, 1.782032174462240e-01}, + {3.748142272277550e-03, 3.579617370411527e-02, 1.379749102418798e-01, + 3.265154111083508e-01, 5.475774673732261e-01, 6.822781533755100e-01, + 6.145447461377790e-01, 3.182316624535267e-01}, + {1.639361248317194e-03, 2.377094533317060e-02, 1.256811814607175e-01, + 3.781052906942359e-01, 7.592700769857601e-01, 1.077789430280474e+00, + 1.058912565145634e+00, 5.748311488516893e-01}, + {9.506953721303734e-04, 1.916640120390382e-02, 1.304935723309592e-01, + 4.771178704140306e-01, 1.111038421145520e+00, 1.757123113317146e+00, + 1.856018088575039e+00, 1.048091837641275e+00}}, + {// a = 1 + {1.782032174462240e-01, 3.644760945454947e-01, 4.500231978835504e-01, + 4.241894377437207e-01, 3.167983979692773e-01, 1.817572780187955e-01, + 7.137161062394448e-02, 1.318076576899512e-02}, + {2.059009564912193e-02, 1.021477023603583e-01, 2.253365549698582e-01, + 3.185923136873289e-01, 3.185923136873280e-01, 2.253365549698585e-01, + 1.021477023603587e-01, 2.059009564912189e-02}, + {5.238552377780736e-03, 4.528118112126706e-02, 1.500406762783725e-01, + 2.870401661205415e-01, 3.597380415060730e-01, 3.002369137811520e-01, + 1.527157338016535e-01, 3.304206834649234e-02}, + {2.065739340562864e-03, 2.685329227552708e-02, 1.213601585989501e-01, + 2.944871735464791e-01, 4.423861616913500e-01, 4.224558133538641e-01, + 2.362061416285682e-01, 5.418551956469873e-02}, + {1.087611730783180e-03, 1.950920488347055e-02, 1.130503382722116e-01, + 3.329077231648351e-01, 5.806711112295920e-01, 6.202631214886722e-01, + 3.753897779892454e-01, 9.045444457452227e-02}}, + {// a = 2 + {3.182316624535267e-01, 6.145447461377790e-01, 6.822781533755100e-01, + 5.475774673732261e-01, 3.265154111083508e-01, 1.379749102418798e-01, + 3.579617370411527e-02, 3.748142272277550e-03}, + {3.304206834649234e-02, 1.527157338016535e-01, 3.002369137811520e-01, + 3.597380415060730e-01, 2.870401661205415e-01, 1.500406762783725e-01, + 4.528118112126706e-02, 5.238552377780736e-03}, + {7.604803485383861e-03, 6.061158316018715e-02, 1.777998015448418e-01, + 2.873171451429209e-01, 2.873171451429211e-01, 1.777998015448412e-01, + 6.061158316018710e-02, 7.604803485383872e-03}, + {2.729955919133130e-03, 3.245563265976652e-02, 1.291970707835632e-01, + 2.642124004061389e-01, 3.168304818118640e-01, 2.250337703756065e-01, + 8.482314252379990e-02, 1.138421218679475e-02}, + {1.316071835548569e-03, 2.144888716307647e-02, 1.090504123249688e-01, + 2.702184288613528e-01, 3.764958077560768e-01, 2.999974929296935e-01, + 1.230408981710883e-01, 1.747962000581336e-02}}, + {// a = 3 + {5.748311488516893e-01, 1.058912565145634e+00, 1.077789430280474e+00, + 7.592700769857601e-01, 3.781052906942359e-01, 1.256811814607175e-01, + 2.377094533317060e-02, 1.639361248317194e-03}, + {5.418551956469873e-02, 2.362061416285682e-01, 4.224558133538641e-01, + 4.423861616913500e-01, 2.944871735464791e-01, 1.213601585989501e-01, + 2.685329227552708e-02, 2.065739340562864e-03}, + {1.138421218679475e-02, 8.482314252379990e-02, 2.250337703756065e-01, + 3.168304818118640e-01, 2.642124004061389e-01, 1.291970707835632e-01, + 3.245563265976652e-02, 2.729955919133130e-03}, + {3.750222228158977e-03, 4.138608360546010e-02, 1.483214149682089e-01, + 2.636851363410289e-01, 2.636851363410289e-01, 1.483214149682089e-01, + 4.138608360546023e-02, 3.750222228158972e-03}, + {1.667252698843120e-03, 2.507758136623631e-02, 1.143814533710352e-01, + 2.459996537221724e-01, 2.859103573133612e-01, 1.808092061439313e-01, + 5.512024438244439e-02, 5.319965287689448e-03}}, + {// a = 4 + {1.048091837641275e+00, 1.856018088575039e+00, 1.757123113317146e+00, + 1.111038421145520e+00, 4.771178704140306e-01, 1.304935723309592e-01, + 1.916640120390382e-02, 9.506953721303734e-04}, + {9.045444457452227e-02, 3.753897779892454e-01, 6.202631214886722e-01, + 5.806711112295920e-01, 3.329077231648351e-01, 1.130503382722116e-01, + 1.950920488347055e-02, 1.087611730783180e-03}, + {1.747962000581336e-02, 1.230408981710883e-01, 2.999974929296935e-01, + 3.764958077560768e-01, 2.702184288613528e-01, 1.090504123249688e-01, + 2.144888716307647e-02, 1.316071835548569e-03}, + {5.319965287689448e-03, 5.512024438244439e-02, 1.808092061439313e-01, + 2.859103573133612e-01, 2.459996537221724e-01, 1.143814533710352e-01, + 2.507758136623631e-02, 1.667252698843120e-03}, + {2.194344706426763e-03, 3.083030321571734e-02, 1.282931004441076e-01, + 2.450314579829549e-01, 2.450314579829549e-01, 1.282931004441075e-01, + 3.083030321571735e-02, 2.194344706426775e-03}}}; static double _gaussJacobiWt_9[5][5][9] = { - { // a = 0 - { 8.127438836157411e-02, 1.806481606948576e-01, 2.606106964029355e-01, 3.123470770400029e-01, 3.302393550012604e-01, 3.123470770400026e-01, 2.606106964029358e-01, 1.806481606948577e-01, 8.127438836157462e-02}, - { 8.723388343092522e-03, 4.824001713914176e-02, 1.272192859642164e-01, 2.336047811806602e-01, 3.374332873796808e-01, 4.012352367734722e-01, 3.941349686893823e-01, 3.042970204372327e-01, 1.451120140931190e-01}, - { 2.090098772155721e-03, 2.059518916486971e-02, 8.324893263481772e-02, 2.107462472203986e-01, 3.883250229160511e-01, 5.542751655184366e-01, 6.213885532844445e-01, 5.239162962671715e-01, 2.620811608883183e-01}, - { 7.845319977778029e-04, 1.186239691255504e-02, 6.658886187786846e-02, 2.174021008992404e-01, 4.877532225754264e-01, 8.086861710341628e-01, 1.011430820366790e+00, 9.176978056758962e-01, 4.777940886602817e-01}, - { 3.965682418173630e-04, 8.426634988953123e-03, 6.164203230608564e-02, 2.478976287781169e-01, 6.548686598515728e-01, 1.230854190469301e+00, 1.688161800534614e+00, 1.629871337573286e+00, 8.778811472562599e-01} - }, - { // a = 1 - { 1.451120140931190e-01, 3.042970204372327e-01, 3.941349686893823e-01, 4.012352367734722e-01, 3.374332873796808e-01, 2.336047811806602e-01, 1.272192859642164e-01, 4.824001713914176e-02, 8.723388343092522e-03}, - { 1.399105612442674e-02, 7.198285617566078e-02, 1.687989736144606e-01, 2.617849830242733e-01, 3.002175954556906e-01, 2.617849830242739e-01, 1.687989736144598e-01, 7.198285617566107e-02, 1.399105612442681e-02}, - { 3.030817632182705e-03, 2.748374753453522e-02, 9.805812910221282e-02, 2.087932895712605e-01, 3.051311007659898e-01, 3.200280655639854e-01, 2.367140611838098e-01, 1.111609349017288e-01, 2.293318707762953e-02}, - { 1.034922348157220e-03, 1.427547148407746e-02, 7.032863437209930e-02, 1.925454294714609e-01, 3.424554571282205e-01, 4.180731001947779e-01, 3.465889255613732e-01, 1.764296268206113e-01, 3.826843261922368e-02}, - { 4.786263988780120e-04, 9.212258249834964e-03, 5.887792199407641e-02, 1.981190855706645e-01, 4.148750183845514e-01, 5.753500819840168e-01, 5.252549930815448e-01, 2.863458082051972e-01, 6.481953946456900e-02} - }, - { // a = 2 - { 2.620811608883183e-01, 5.239162962671715e-01, 6.213885532844445e-01, 5.542751655184366e-01, 3.883250229160511e-01, 2.107462472203986e-01, 8.324893263481772e-02, 2.059518916486971e-02, 2.090098772155721e-03}, - { 2.293318707762953e-02, 1.111609349017288e-01, 2.367140611838098e-01, 3.200280655639854e-01, 3.051311007659898e-01, 2.087932895712605e-01, 9.805812910221282e-02, 2.748374753453522e-02, 3.030817632182705e-03}, - { 4.532848780190382e-03, 3.836522894944150e-02, 1.235014142449354e-01, 2.283718742253705e-01, 2.771239342667918e-01, 2.283718742253703e-01, 1.235014142449353e-01, 3.836522894944139e-02, 4.532848780190396e-03}, - { 1.419556432490855e-03, 1.813834092782009e-02, 8.021608746285096e-02, 1.901798804976253e-01, 2.806631498803743e-01, 2.695875591080467e-01, 1.639747057251420e-01, 5.553300732494925e-02, 6.954379307367488e-03}, - { 6.050195730337762e-04, 1.072010839565942e-02, 6.125688594656706e-02, 1.781164561605714e-01, 3.093861808649055e-01, 3.380708352029016e-01, 2.271764603321054e-01, 8.281530039514041e-02, 1.090037217673476e-02} - }, - { // a = 3 - { 4.777940886602817e-01, 9.176978056758962e-01, 1.011430820366790e+00, 8.086861710341628e-01, 4.877532225754264e-01, 2.174021008992404e-01, 6.658886187786846e-02, 1.186239691255504e-02, 7.845319977778029e-04}, - { 3.826843261922368e-02, 1.764296268206113e-01, 3.465889255613732e-01, 4.180731001947779e-01, 3.424554571282205e-01, 1.925454294714609e-01, 7.032863437209930e-02, 1.427547148407746e-02, 1.034922348157220e-03}, - { 6.954379307367488e-03, 5.553300732494925e-02, 1.639747057251420e-01, 2.695875591080467e-01, 2.806631498803743e-01, 1.901798804976253e-01, 8.021608746285096e-02, 1.813834092782009e-02, 1.419556432490855e-03}, - { 2.011157144719757e-03, 2.408461451798091e-02, 9.725756139115974e-02, 2.044650214311605e-01, 2.586490053156716e-01, 2.044650214311607e-01, 9.725756139115969e-02, 2.408461451798086e-02, 2.011157144719762e-03}, - { 7.948083143692002e-04, 1.312668794657135e-02, 6.824097450514767e-02, 1.755898455477392e-01, 2.613016730817572e-01, 2.352175534981812e-01, 1.239193872628280e-01, 3.316676971481035e-02, 2.928014414309612e-03} - }, - { // a = 4 - { 8.778811472562599e-01, 1.629871337573286e+00, 1.688161800534614e+00, 1.230854190469301e+00, 6.548686598515728e-01, 2.478976287781169e-01, 6.164203230608564e-02, 8.426634988953123e-03, 3.965682418173630e-04}, - { 6.481953946456900e-02, 2.863458082051972e-01, 5.252549930815448e-01, 5.753500819840168e-01, 4.148750183845514e-01, 1.981190855706645e-01, 5.887792199407641e-02, 9.212258249834964e-03, 4.786263988780120e-04}, - { 1.090037217673476e-02, 8.281530039514041e-02, 2.271764603321054e-01, 3.380708352029016e-01, 3.093861808649055e-01, 1.781164561605714e-01, 6.125688594656706e-02, 1.072010839565942e-02, 6.050195730337762e-04}, - { 2.928014414309612e-03, 3.316676971481035e-02, 1.239193872628280e-01, 2.352175534981812e-01, 2.613016730817572e-01, 1.755898455477392e-01, 6.824097450514767e-02, 1.312668794657135e-02, 7.948083143692002e-04}, - { 1.078664987774300e-03, 1.676843637593469e-02, 8.038851350441679e-02, 1.863964125090003e-01, 2.434343579441625e-01, 1.863964125090002e-01, 8.038851350441661e-02, 1.676843637593475e-02, 1.078664987774288e-03} - } -}; + {// a = 0 + {8.127438836157411e-02, 1.806481606948576e-01, 2.606106964029355e-01, + 3.123470770400029e-01, 3.302393550012604e-01, 3.123470770400026e-01, + 2.606106964029358e-01, 1.806481606948577e-01, 8.127438836157462e-02}, + {8.723388343092522e-03, 4.824001713914176e-02, 1.272192859642164e-01, + 2.336047811806602e-01, 3.374332873796808e-01, 4.012352367734722e-01, + 3.941349686893823e-01, 3.042970204372327e-01, 1.451120140931190e-01}, + {2.090098772155721e-03, 2.059518916486971e-02, 8.324893263481772e-02, + 2.107462472203986e-01, 3.883250229160511e-01, 5.542751655184366e-01, + 6.213885532844445e-01, 5.239162962671715e-01, 2.620811608883183e-01}, + {7.845319977778029e-04, 1.186239691255504e-02, 6.658886187786846e-02, + 2.174021008992404e-01, 4.877532225754264e-01, 8.086861710341628e-01, + 1.011430820366790e+00, 9.176978056758962e-01, 4.777940886602817e-01}, + {3.965682418173630e-04, 8.426634988953123e-03, 6.164203230608564e-02, + 2.478976287781169e-01, 6.548686598515728e-01, 1.230854190469301e+00, + 1.688161800534614e+00, 1.629871337573286e+00, 8.778811472562599e-01}}, + {// a = 1 + {1.451120140931190e-01, 3.042970204372327e-01, 3.941349686893823e-01, + 4.012352367734722e-01, 3.374332873796808e-01, 2.336047811806602e-01, + 1.272192859642164e-01, 4.824001713914176e-02, 8.723388343092522e-03}, + {1.399105612442674e-02, 7.198285617566078e-02, 1.687989736144606e-01, + 2.617849830242733e-01, 3.002175954556906e-01, 2.617849830242739e-01, + 1.687989736144598e-01, 7.198285617566107e-02, 1.399105612442681e-02}, + {3.030817632182705e-03, 2.748374753453522e-02, 9.805812910221282e-02, + 2.087932895712605e-01, 3.051311007659898e-01, 3.200280655639854e-01, + 2.367140611838098e-01, 1.111609349017288e-01, 2.293318707762953e-02}, + {1.034922348157220e-03, 1.427547148407746e-02, 7.032863437209930e-02, + 1.925454294714609e-01, 3.424554571282205e-01, 4.180731001947779e-01, + 3.465889255613732e-01, 1.764296268206113e-01, 3.826843261922368e-02}, + {4.786263988780120e-04, 9.212258249834964e-03, 5.887792199407641e-02, + 1.981190855706645e-01, 4.148750183845514e-01, 5.753500819840168e-01, + 5.252549930815448e-01, 2.863458082051972e-01, 6.481953946456900e-02}}, + {// a = 2 + {2.620811608883183e-01, 5.239162962671715e-01, 6.213885532844445e-01, + 5.542751655184366e-01, 3.883250229160511e-01, 2.107462472203986e-01, + 8.324893263481772e-02, 2.059518916486971e-02, 2.090098772155721e-03}, + {2.293318707762953e-02, 1.111609349017288e-01, 2.367140611838098e-01, + 3.200280655639854e-01, 3.051311007659898e-01, 2.087932895712605e-01, + 9.805812910221282e-02, 2.748374753453522e-02, 3.030817632182705e-03}, + {4.532848780190382e-03, 3.836522894944150e-02, 1.235014142449354e-01, + 2.283718742253705e-01, 2.771239342667918e-01, 2.283718742253703e-01, + 1.235014142449353e-01, 3.836522894944139e-02, 4.532848780190396e-03}, + {1.419556432490855e-03, 1.813834092782009e-02, 8.021608746285096e-02, + 1.901798804976253e-01, 2.806631498803743e-01, 2.695875591080467e-01, + 1.639747057251420e-01, 5.553300732494925e-02, 6.954379307367488e-03}, + {6.050195730337762e-04, 1.072010839565942e-02, 6.125688594656706e-02, + 1.781164561605714e-01, 3.093861808649055e-01, 3.380708352029016e-01, + 2.271764603321054e-01, 8.281530039514041e-02, 1.090037217673476e-02}}, + {// a = 3 + {4.777940886602817e-01, 9.176978056758962e-01, 1.011430820366790e+00, + 8.086861710341628e-01, 4.877532225754264e-01, 2.174021008992404e-01, + 6.658886187786846e-02, 1.186239691255504e-02, 7.845319977778029e-04}, + {3.826843261922368e-02, 1.764296268206113e-01, 3.465889255613732e-01, + 4.180731001947779e-01, 3.424554571282205e-01, 1.925454294714609e-01, + 7.032863437209930e-02, 1.427547148407746e-02, 1.034922348157220e-03}, + {6.954379307367488e-03, 5.553300732494925e-02, 1.639747057251420e-01, + 2.695875591080467e-01, 2.806631498803743e-01, 1.901798804976253e-01, + 8.021608746285096e-02, 1.813834092782009e-02, 1.419556432490855e-03}, + {2.011157144719757e-03, 2.408461451798091e-02, 9.725756139115974e-02, + 2.044650214311605e-01, 2.586490053156716e-01, 2.044650214311607e-01, + 9.725756139115969e-02, 2.408461451798086e-02, 2.011157144719762e-03}, + {7.948083143692002e-04, 1.312668794657135e-02, 6.824097450514767e-02, + 1.755898455477392e-01, 2.613016730817572e-01, 2.352175534981812e-01, + 1.239193872628280e-01, 3.316676971481035e-02, 2.928014414309612e-03}}, + {// a = 4 + {8.778811472562599e-01, 1.629871337573286e+00, 1.688161800534614e+00, + 1.230854190469301e+00, 6.548686598515728e-01, 2.478976287781169e-01, + 6.164203230608564e-02, 8.426634988953123e-03, 3.965682418173630e-04}, + {6.481953946456900e-02, 2.863458082051972e-01, 5.252549930815448e-01, + 5.753500819840168e-01, 4.148750183845514e-01, 1.981190855706645e-01, + 5.887792199407641e-02, 9.212258249834964e-03, 4.786263988780120e-04}, + {1.090037217673476e-02, 8.281530039514041e-02, 2.271764603321054e-01, + 3.380708352029016e-01, 3.093861808649055e-01, 1.781164561605714e-01, + 6.125688594656706e-02, 1.072010839565942e-02, 6.050195730337762e-04}, + {2.928014414309612e-03, 3.316676971481035e-02, 1.239193872628280e-01, + 2.352175534981812e-01, 2.613016730817572e-01, 1.755898455477392e-01, + 6.824097450514767e-02, 1.312668794657135e-02, 7.948083143692002e-04}, + {1.078664987774300e-03, 1.676843637593469e-02, 8.038851350441679e-02, + 1.863964125090003e-01, 2.434343579441625e-01, 1.863964125090002e-01, + 8.038851350441661e-02, 1.676843637593475e-02, 1.078664987774288e-03}}}; static double _gaussJacobiWt_10[5][5][10] = { - { // a = 0 - { 6.667134430868796e-02, 1.494513491505811e-01, 2.190863625159821e-01, 2.692667193099963e-01, 2.955242247147531e-01, 2.955242247147530e-01, 2.692667193099950e-01, 2.190863625159810e-01, 1.494513491505806e-01, 6.667134430868778e-02}, - { 5.996562409625547e-03, 3.367727913193280e-02, 9.109836581305251e-02, 1.736076256286021e-01, 2.642123022534021e-01, 3.382284387633099e-01, 3.707875747108959e-01, 3.448452011567033e-01, 2.571486180363293e-01, 1.203980320961483e-01}, - { 1.225920293577290e-03, 1.236418555789262e-02, 5.175911254846813e-02, 1.375806003724243e-01, 2.708365201345128e-01, 4.230703101357128e-01, 5.396177550515026e-01, 5.605560616693339e-01, 4.501834912224668e-01, 2.194727096807776e-01}, - { 3.987380445189374e-04, 6.222149508714171e-03, 3.652163224889284e-02, 1.266064472484918e-01, 3.074176848778439e-01, 5.662005832870052e-01, 8.196507122185764e-01, 9.345810965658908e-01, 7.991845596077661e-01, 4.032163963923006e-01}, - { 1.769883681770343e-04, 3.914215649037393e-03, 3.022337095838256e-02, 1.304380877942701e-01, 3.774434228870330e-01, 7.988833608734847e-01, 1.287936562606778e+00, 1.590225340423518e+00, 1.435055060650287e+00, 7.457035897890363e-01} - }, - { // a = 1 - { 1.203980320961483e-01, 2.571486180363293e-01, 3.448452011567033e-01, 3.707875747108959e-01, 3.382284387633099e-01, 2.642123022534021e-01, 1.736076256286021e-01, 9.109836581305251e-02, 3.367727913193280e-02, 5.996562409625547e-03}, - { 9.825404805768089e-03, 5.193914377420801e-02, 1.273919483477327e-01, 2.111657418760754e-01, 2.663444278628828e-01, 2.663444278628820e-01, 2.111657418760756e-01, 1.273919483477328e-01, 5.193914377420816e-02, 9.825404805768235e-03}, - { 1.832057042737568e-03, 1.722313873549234e-02, 6.492067351505550e-02, 1.494378024738416e-01, 2.433228507440566e-01, 2.970266172545428e-01, 2.747429441803760e-01, 1.860911217803869e-01, 8.234582767628330e-02, 1.639029993056046e-02}, - { 5.462394333370451e-04, 7.882014015731303e-03, 4.142722670706492e-02, 1.239436761798637e-01, 2.485884205662773e-01, 3.580177743107589e-01, 3.768424674561625e-01, 2.814735121059265e-01, 1.335242156496223e-01, 2.775445357525714e-02}, - { 2.233142705313782e-04, 4.536712221208265e-03, 3.122730629731009e-02, 1.160081068088709e-01, 2.770339268510800e-01, 4.588756720797210e-01, 5.392437346710152e-01, 4.379961709280589e-01, 2.205892704417909e-01, 4.759911876374553e-02} - }, - { // a = 2 - { 2.194727096807776e-01, 4.501834912224668e-01, 5.605560616693339e-01, 5.396177550515026e-01, 4.230703101357128e-01, 2.708365201345128e-01, 1.375806003724243e-01, 5.175911254846813e-02, 1.236418555789262e-02, 1.225920293577290e-03}, - { 1.639029993056046e-02, 8.234582767628330e-02, 1.860911217803869e-01, 2.747429441803760e-01, 2.970266172545428e-01, 2.433228507440566e-01, 1.494378024738416e-01, 6.492067351505550e-02, 1.722313873549234e-02, 1.832057042737568e-03}, - { 2.808941213367817e-03, 2.488609750147603e-02, 8.590158815236659e-02, 1.754113673268373e-01, 2.443253391392856e-01, 2.443253391392861e-01, 1.754113673268374e-01, 8.590158815236641e-02, 2.488609750147600e-02, 2.808941213367841e-03}, - { 7.730524588664571e-04, 1.043934319224347e-02, 4.999771360892913e-02, 1.322845011659509e-01, 2.266422530788494e-01, 2.674654289496634e-01, 2.189397652323106e-01, 1.186681094634199e-01, 3.705619872334139e-02, 4.400300793092868e-03}, - { 2.929041347145321e-04, 5.536370347918375e-03, 3.458592594755515e-02, 1.133460102777502e-01, 2.309929948180737e-01, 3.136606795061906e-01, 2.871907378094203e-01, 1.698401658098329e-01, 5.658135757422238e-02, 7.020472821941071e-03} - }, - { // a = 3 - { 4.032163963923006e-01, 7.991845596077661e-01, 9.345810965658908e-01, 8.196507122185764e-01, 5.662005832870052e-01, 3.074176848778439e-01, 1.266064472484918e-01, 3.652163224889284e-02, 6.222149508714171e-03, 3.987380445189374e-04}, - { 2.775445357525714e-02, 1.335242156496223e-01, 2.814735121059265e-01, 3.768424674561625e-01, 3.580177743107589e-01, 2.485884205662773e-01, 1.239436761798637e-01, 4.142722670706492e-02, 7.882014015731303e-03, 5.462394333370451e-04}, - { 4.400300793092868e-03, 3.705619872334139e-02, 1.186681094634199e-01, 2.189397652323106e-01, 2.674654289496634e-01, 2.266422530788494e-01, 1.322845011659509e-01, 4.999771360892913e-02, 1.043934319224347e-02, 7.730524588664571e-04}, - { 1.124433170553250e-03, 1.434465433125631e-02, 6.345603076730036e-02, 1.512552800345786e-01, 2.269624588391684e-01, 2.269624588391684e-01, 1.512552800345791e-01, 6.345603076730053e-02, 1.434465433125623e-02, 1.124433170553240e-03}, - { 3.969709655448310e-04, 7.051772659876825e-03, 4.054135817725277e-02, 1.194221947109241e-01, 2.129306406750290e-01, 2.450507596235002e-01, 1.829292062176269e-01, 8.395914704503786e-02, 2.032943574788931e-02, 1.674228463030883e-03} - }, - { // a = 4 - { 7.457035897890363e-01, 1.435055060650287e+00, 1.590225340423518e+00, 1.287936562606778e+00, 7.988833608734847e-01, 3.774434228870330e-01, 1.304380877942701e-01, 3.022337095838256e-02, 3.914215649037393e-03, 1.769883681770343e-04}, - { 4.759911876374553e-02, 2.205892704417909e-01, 4.379961709280589e-01, 5.392437346710152e-01, 4.588756720797210e-01, 2.770339268510800e-01, 1.160081068088709e-01, 3.122730629731009e-02, 4.536712221208265e-03, 2.233142705313782e-04}, - { 7.020472821941071e-03, 5.658135757422238e-02, 1.698401658098329e-01, 2.871907378094203e-01, 3.136606795061906e-01, 2.309929948180737e-01, 1.133460102777502e-01, 3.458592594755515e-02, 5.536370347918375e-03, 2.929041347145321e-04}, - { 1.674228463030883e-03, 2.032943574788931e-02, 8.395914704503786e-02, 1.829292062176269e-01, 2.450507596235002e-01, 2.129306406750290e-01, 1.194221947109241e-01, 4.054135817725277e-02, 7.051772659876825e-03, 3.969709655448310e-04}, - { 5.533092611488388e-04, 9.312078732135522e-03, 4.981615856567945e-02, 1.338440861946089e-01, 2.128235735956336e-01, 2.128235735956340e-01, 1.338440861946093e-01, 4.981615856567939e-02, 9.312078732135546e-03, 5.533092611488373e-04} - } -}; + {// a = 0 + {6.667134430868796e-02, 1.494513491505811e-01, 2.190863625159821e-01, + 2.692667193099963e-01, 2.955242247147531e-01, 2.955242247147530e-01, + 2.692667193099950e-01, 2.190863625159810e-01, 1.494513491505806e-01, + 6.667134430868778e-02}, + {5.996562409625547e-03, 3.367727913193280e-02, 9.109836581305251e-02, + 1.736076256286021e-01, 2.642123022534021e-01, 3.382284387633099e-01, + 3.707875747108959e-01, 3.448452011567033e-01, 2.571486180363293e-01, + 1.203980320961483e-01}, + {1.225920293577290e-03, 1.236418555789262e-02, 5.175911254846813e-02, + 1.375806003724243e-01, 2.708365201345128e-01, 4.230703101357128e-01, + 5.396177550515026e-01, 5.605560616693339e-01, 4.501834912224668e-01, + 2.194727096807776e-01}, + {3.987380445189374e-04, 6.222149508714171e-03, 3.652163224889284e-02, + 1.266064472484918e-01, 3.074176848778439e-01, 5.662005832870052e-01, + 8.196507122185764e-01, 9.345810965658908e-01, 7.991845596077661e-01, + 4.032163963923006e-01}, + {1.769883681770343e-04, 3.914215649037393e-03, 3.022337095838256e-02, + 1.304380877942701e-01, 3.774434228870330e-01, 7.988833608734847e-01, + 1.287936562606778e+00, 1.590225340423518e+00, 1.435055060650287e+00, + 7.457035897890363e-01}}, + {// a = 1 + {1.203980320961483e-01, 2.571486180363293e-01, 3.448452011567033e-01, + 3.707875747108959e-01, 3.382284387633099e-01, 2.642123022534021e-01, + 1.736076256286021e-01, 9.109836581305251e-02, 3.367727913193280e-02, + 5.996562409625547e-03}, + {9.825404805768089e-03, 5.193914377420801e-02, 1.273919483477327e-01, + 2.111657418760754e-01, 2.663444278628828e-01, 2.663444278628820e-01, + 2.111657418760756e-01, 1.273919483477328e-01, 5.193914377420816e-02, + 9.825404805768235e-03}, + {1.832057042737568e-03, 1.722313873549234e-02, 6.492067351505550e-02, + 1.494378024738416e-01, 2.433228507440566e-01, 2.970266172545428e-01, + 2.747429441803760e-01, 1.860911217803869e-01, 8.234582767628330e-02, + 1.639029993056046e-02}, + {5.462394333370451e-04, 7.882014015731303e-03, 4.142722670706492e-02, + 1.239436761798637e-01, 2.485884205662773e-01, 3.580177743107589e-01, + 3.768424674561625e-01, 2.814735121059265e-01, 1.335242156496223e-01, + 2.775445357525714e-02}, + {2.233142705313782e-04, 4.536712221208265e-03, 3.122730629731009e-02, + 1.160081068088709e-01, 2.770339268510800e-01, 4.588756720797210e-01, + 5.392437346710152e-01, 4.379961709280589e-01, 2.205892704417909e-01, + 4.759911876374553e-02}}, + {// a = 2 + {2.194727096807776e-01, 4.501834912224668e-01, 5.605560616693339e-01, + 5.396177550515026e-01, 4.230703101357128e-01, 2.708365201345128e-01, + 1.375806003724243e-01, 5.175911254846813e-02, 1.236418555789262e-02, + 1.225920293577290e-03}, + {1.639029993056046e-02, 8.234582767628330e-02, 1.860911217803869e-01, + 2.747429441803760e-01, 2.970266172545428e-01, 2.433228507440566e-01, + 1.494378024738416e-01, 6.492067351505550e-02, 1.722313873549234e-02, + 1.832057042737568e-03}, + {2.808941213367817e-03, 2.488609750147603e-02, 8.590158815236659e-02, + 1.754113673268373e-01, 2.443253391392856e-01, 2.443253391392861e-01, + 1.754113673268374e-01, 8.590158815236641e-02, 2.488609750147600e-02, + 2.808941213367841e-03}, + {7.730524588664571e-04, 1.043934319224347e-02, 4.999771360892913e-02, + 1.322845011659509e-01, 2.266422530788494e-01, 2.674654289496634e-01, + 2.189397652323106e-01, 1.186681094634199e-01, 3.705619872334139e-02, + 4.400300793092868e-03}, + {2.929041347145321e-04, 5.536370347918375e-03, 3.458592594755515e-02, + 1.133460102777502e-01, 2.309929948180737e-01, 3.136606795061906e-01, + 2.871907378094203e-01, 1.698401658098329e-01, 5.658135757422238e-02, + 7.020472821941071e-03}}, + {// a = 3 + {4.032163963923006e-01, 7.991845596077661e-01, 9.345810965658908e-01, + 8.196507122185764e-01, 5.662005832870052e-01, 3.074176848778439e-01, + 1.266064472484918e-01, 3.652163224889284e-02, 6.222149508714171e-03, + 3.987380445189374e-04}, + {2.775445357525714e-02, 1.335242156496223e-01, 2.814735121059265e-01, + 3.768424674561625e-01, 3.580177743107589e-01, 2.485884205662773e-01, + 1.239436761798637e-01, 4.142722670706492e-02, 7.882014015731303e-03, + 5.462394333370451e-04}, + {4.400300793092868e-03, 3.705619872334139e-02, 1.186681094634199e-01, + 2.189397652323106e-01, 2.674654289496634e-01, 2.266422530788494e-01, + 1.322845011659509e-01, 4.999771360892913e-02, 1.043934319224347e-02, + 7.730524588664571e-04}, + {1.124433170553250e-03, 1.434465433125631e-02, 6.345603076730036e-02, + 1.512552800345786e-01, 2.269624588391684e-01, 2.269624588391684e-01, + 1.512552800345791e-01, 6.345603076730053e-02, 1.434465433125623e-02, + 1.124433170553240e-03}, + {3.969709655448310e-04, 7.051772659876825e-03, 4.054135817725277e-02, + 1.194221947109241e-01, 2.129306406750290e-01, 2.450507596235002e-01, + 1.829292062176269e-01, 8.395914704503786e-02, 2.032943574788931e-02, + 1.674228463030883e-03}}, + {// a = 4 + {7.457035897890363e-01, 1.435055060650287e+00, 1.590225340423518e+00, + 1.287936562606778e+00, 7.988833608734847e-01, 3.774434228870330e-01, + 1.304380877942701e-01, 3.022337095838256e-02, 3.914215649037393e-03, + 1.769883681770343e-04}, + {4.759911876374553e-02, 2.205892704417909e-01, 4.379961709280589e-01, + 5.392437346710152e-01, 4.588756720797210e-01, 2.770339268510800e-01, + 1.160081068088709e-01, 3.122730629731009e-02, 4.536712221208265e-03, + 2.233142705313782e-04}, + {7.020472821941071e-03, 5.658135757422238e-02, 1.698401658098329e-01, + 2.871907378094203e-01, 3.136606795061906e-01, 2.309929948180737e-01, + 1.133460102777502e-01, 3.458592594755515e-02, 5.536370347918375e-03, + 2.929041347145321e-04}, + {1.674228463030883e-03, 2.032943574788931e-02, 8.395914704503786e-02, + 1.829292062176269e-01, 2.450507596235002e-01, 2.129306406750290e-01, + 1.194221947109241e-01, 4.054135817725277e-02, 7.051772659876825e-03, + 3.969709655448310e-04}, + {5.533092611488388e-04, 9.312078732135522e-03, 4.981615856567945e-02, + 1.338440861946089e-01, 2.128235735956336e-01, 2.128235735956340e-01, + 1.338440861946093e-01, 4.981615856567939e-02, 9.312078732135546e-03, + 5.533092611488373e-04}}}; static double _gaussJacobiWt_11[5][5][11] = { - { // a = 0 - { 5.566856711617359e-02, 1.255803694649046e-01, 1.862902109277350e-01, 2.331937645919905e-01, 2.628045445102469e-01, 2.729250867779014e-01, 2.628045445102468e-01, 2.331937645919903e-01, 1.862902109277345e-01, 1.255803694649044e-01, 5.566856711617318e-02}, - { 4.254669172978147e-03, 2.417568384191924e-02, 6.665449380672291e-02, 1.305661868553332e-01, 2.063654426891905e-01, 2.781275006327323e-01, 3.275164119522538e-01, 3.386376915360718e-01, 3.024801922287482e-01, 2.197523645314864e-01, 1.014693627525651e-01}, - { 7.504038880782284e-04, 7.704164604345901e-03, 3.312003410575227e-02, 9.131672734478077e-02, 1.887173083104552e-01, 3.143217423874861e-01, 4.370577785683599e-01, 5.134684747980476e-01, 5.038363440029392e-01, 3.899668882453152e-01, 1.864068004111078e-01}, - { 2.133502587477222e-04, 3.411276856284806e-03, 2.071970073321518e-02, 7.516721727852196e-02, 1.935791520138537e-01, 3.846472609341519e-01, 6.152504691304241e-01, 8.056538714959643e-01, 8.566217628420132e-01, 7.000185078915774e-01, 3.447174305652413e-01}, - { 8.373308015001190e-05, 1.910381097398653e-03, 1.538057913605891e-02, 7.006400214752159e-02, 2.171198836550185e-01, 5.012202707328959e-01, 9.038653956468931e-01, 1.299520565991693e+00, 1.481068587210711e+00, 1.268666943139948e+00, 6.410996581617191e-01} - }, - { // a = 1 - { 1.014693627525651e-01, 2.197523645314864e-01, 3.024801922287482e-01, 3.386376915360718e-01, 3.275164119522538e-01, 2.781275006327323e-01, 2.063654426891905e-01, 1.305661868553332e-01, 6.665449380672291e-02, 2.417568384191924e-02, 4.254669172978147e-03}, - { 7.095539995635450e-03, 3.829380565181230e-02, 9.717589117367044e-02, 1.692843256838664e-01, 2.288516794949587e-01, 2.519308493334464e-01, 2.288516794949586e-01, 1.692843256838672e-01, 9.717589117367048e-02, 3.829380565181205e-02, 7.095539995635458e-03}, - { 1.149899262705060e-03, 1.111523459854731e-02, 4.369574953640146e-02, 1.066649642595343e-01, 1.880714727028224e-01, 2.557004122008758e-01, 2.746085708964524e-01, 2.315271861986933e-01, 1.467419246783587e-01, 6.204547371934391e-02, 1.201244527959806e-02}, - { 3.016629546290895e-04, 4.508258947434251e-03, 2.490755722153995e-02, 7.971906620710731e-02, 1.748287416827368e-01, 2.834908718635391e-01, 3.506808225567526e-01, 3.305087708885728e-01, 2.280226846392065e-01, 1.024342121217006e-01, 2.059735091678128e-02}, - { 1.096783521306954e-04, 2.324551515253453e-03, 1.694941861111087e-02, 6.792551436237800e-02, 1.789973972638532e-01, 3.371979991598771e-01, 4.708939598294999e-01, 4.886006136701065e-01, 3.628202611779144e-01, 1.718078254086433e-01, 3.570611398256825e-02} - }, - { // a = 2 - { 1.864068004111078e-01, 3.899668882453152e-01, 5.038363440029392e-01, 5.134684747980476e-01, 4.370577785683599e-01, 3.143217423874861e-01, 1.887173083104552e-01, 9.131672734478077e-02, 3.312003410575227e-02, 7.704164604345901e-03, 7.504038880782284e-04}, - { 1.201244527959806e-02, 6.204547371934391e-02, 1.467419246783587e-01, 2.315271861986933e-01, 2.746085708964524e-01, 2.557004122008758e-01, 1.880714727028224e-01, 1.066649642595343e-01, 4.369574953640146e-02, 1.111523459854731e-02, 1.149899262705060e-03}, - { 1.800505712143062e-03, 1.652979749395006e-02, 6.021451394938584e-02, 1.325938441003085e-01, 2.046269423886040e-01, 2.351354593778834e-01, 2.046269423886035e-01, 1.325938441003083e-01, 6.021451394938595e-02, 1.652979749395013e-02, 1.800505712143067e-03}, - { 4.384344964523082e-04, 6.183266472687995e-03, 3.150640500283894e-02, 9.066995484349000e-02, 1.737233827592598e-01, 2.379749388872305e-01, 2.387560489479536e-01, 1.733323982904236e-01, 8.599874690757750e-02, 2.521164399849497e-02, 2.871446060256749e-03}, - { 1.484733835020589e-04, 2.953427403304018e-03, 1.978315420318005e-02, 7.109997502153002e-02, 1.634634630424583e-01, 2.600835280107577e-01, 2.948607419574116e-01, 2.361731707811737e-01, 1.265434095391612e-01, 3.928594784442110e-02, 4.652327860721107e-03} - }, - { // a = 3 - { 3.447174305652413e-01, 7.000185078915774e-01, 8.566217628420132e-01, 8.056538714959643e-01, 6.152504691304241e-01, 3.846472609341519e-01, 1.935791520138537e-01, 7.516721727852196e-02, 2.071970073321518e-02, 3.411276856284806e-03, 2.133502587477222e-04}, - { 2.059735091678128e-02, 1.024342121217006e-01, 2.280226846392065e-01, 3.305087708885728e-01, 3.506808225567526e-01, 2.834908718635391e-01, 1.748287416827368e-01, 7.971906620710731e-02, 2.490755722153995e-02, 4.508258947434251e-03, 3.016629546290895e-04}, - { 2.871446060256749e-03, 2.521164399849497e-02, 8.599874690757750e-02, 1.733323982904236e-01, 2.387560489479536e-01, 2.379749388872305e-01, 1.737233827592598e-01, 9.066995484349000e-02, 3.150640500283894e-02, 6.183266472687995e-03, 4.384344964523082e-04}, - { 6.523613474704498e-04, 8.748910971782960e-03, 4.156660510678858e-02, 1.091649348532573e-01, 1.863580639798480e-01, 2.213039617674194e-01, 1.863580639798469e-01, 1.091649348532574e-01, 4.156660510678864e-02, 8.748910971782996e-03, 6.523613474704435e-04}, - { 2.067362223280178e-04, 3.891630830430294e-03, 2.421953842084509e-02, 7.924262835390317e-02, 1.621005459870287e-01, 2.235084160660967e-01, 2.128254368400618e-01, 1.377782067838998e-01, 5.681049195022907e-02, 1.271152895582430e-02, 9.905538750657984e-04} - }, - { // a = 4 - { 6.410996581617191e-01, 1.268666943139948e+00, 1.481068587210711e+00, 1.299520565991693e+00, 9.038653956468931e-01, 5.012202707328959e-01, 2.171198836550185e-01, 7.006400214752159e-02, 1.538057913605891e-02, 1.910381097398653e-03, 8.373308015001190e-05}, - { 3.570611398256825e-02, 1.718078254086433e-01, 3.628202611779144e-01, 4.886006136701065e-01, 4.708939598294999e-01, 3.371979991598771e-01, 1.789973972638532e-01, 6.792551436237800e-02, 1.694941861111087e-02, 2.324551515253453e-03, 1.096783521306954e-04}, - { 4.652327860721107e-03, 3.928594784442110e-02, 1.265434095391612e-01, 2.361731707811737e-01, 2.948607419574116e-01, 2.600835280107577e-01, 1.634634630424583e-01, 7.109997502153002e-02, 1.978315420318005e-02, 2.953427403304018e-03, 1.484733835020589e-04}, - { 9.905538750657984e-04, 1.271152895582430e-02, 5.681049195022907e-02, 1.377782067838998e-01, 2.128254368400618e-01, 2.235084160660967e-01, 1.621005459870287e-01, 7.924262835390317e-02, 2.421953842084509e-02, 3.891630830430294e-03, 2.067362223280178e-04}, - { 2.949699603442579e-04, 5.289865663661539e-03, 3.086829305071137e-02, 9.305474127317909e-02, 1.720131439851640e-01, 2.096563848322926e-01, 1.720131439851645e-01, 9.305474127317945e-02, 3.086829305071124e-02, 5.289865663661513e-03, 2.949699603442520e-04} - } -}; + {// a = 0 + {5.566856711617359e-02, 1.255803694649046e-01, 1.862902109277350e-01, + 2.331937645919905e-01, 2.628045445102469e-01, 2.729250867779014e-01, + 2.628045445102468e-01, 2.331937645919903e-01, 1.862902109277345e-01, + 1.255803694649044e-01, 5.566856711617318e-02}, + {4.254669172978147e-03, 2.417568384191924e-02, 6.665449380672291e-02, + 1.305661868553332e-01, 2.063654426891905e-01, 2.781275006327323e-01, + 3.275164119522538e-01, 3.386376915360718e-01, 3.024801922287482e-01, + 2.197523645314864e-01, 1.014693627525651e-01}, + {7.504038880782284e-04, 7.704164604345901e-03, 3.312003410575227e-02, + 9.131672734478077e-02, 1.887173083104552e-01, 3.143217423874861e-01, + 4.370577785683599e-01, 5.134684747980476e-01, 5.038363440029392e-01, + 3.899668882453152e-01, 1.864068004111078e-01}, + {2.133502587477222e-04, 3.411276856284806e-03, 2.071970073321518e-02, + 7.516721727852196e-02, 1.935791520138537e-01, 3.846472609341519e-01, + 6.152504691304241e-01, 8.056538714959643e-01, 8.566217628420132e-01, + 7.000185078915774e-01, 3.447174305652413e-01}, + {8.373308015001190e-05, 1.910381097398653e-03, 1.538057913605891e-02, + 7.006400214752159e-02, 2.171198836550185e-01, 5.012202707328959e-01, + 9.038653956468931e-01, 1.299520565991693e+00, 1.481068587210711e+00, + 1.268666943139948e+00, 6.410996581617191e-01}}, + {// a = 1 + {1.014693627525651e-01, 2.197523645314864e-01, 3.024801922287482e-01, + 3.386376915360718e-01, 3.275164119522538e-01, 2.781275006327323e-01, + 2.063654426891905e-01, 1.305661868553332e-01, 6.665449380672291e-02, + 2.417568384191924e-02, 4.254669172978147e-03}, + {7.095539995635450e-03, 3.829380565181230e-02, 9.717589117367044e-02, + 1.692843256838664e-01, 2.288516794949587e-01, 2.519308493334464e-01, + 2.288516794949586e-01, 1.692843256838672e-01, 9.717589117367048e-02, + 3.829380565181205e-02, 7.095539995635458e-03}, + {1.149899262705060e-03, 1.111523459854731e-02, 4.369574953640146e-02, + 1.066649642595343e-01, 1.880714727028224e-01, 2.557004122008758e-01, + 2.746085708964524e-01, 2.315271861986933e-01, 1.467419246783587e-01, + 6.204547371934391e-02, 1.201244527959806e-02}, + {3.016629546290895e-04, 4.508258947434251e-03, 2.490755722153995e-02, + 7.971906620710731e-02, 1.748287416827368e-01, 2.834908718635391e-01, + 3.506808225567526e-01, 3.305087708885728e-01, 2.280226846392065e-01, + 1.024342121217006e-01, 2.059735091678128e-02}, + {1.096783521306954e-04, 2.324551515253453e-03, 1.694941861111087e-02, + 6.792551436237800e-02, 1.789973972638532e-01, 3.371979991598771e-01, + 4.708939598294999e-01, 4.886006136701065e-01, 3.628202611779144e-01, + 1.718078254086433e-01, 3.570611398256825e-02}}, + {// a = 2 + {1.864068004111078e-01, 3.899668882453152e-01, 5.038363440029392e-01, + 5.134684747980476e-01, 4.370577785683599e-01, 3.143217423874861e-01, + 1.887173083104552e-01, 9.131672734478077e-02, 3.312003410575227e-02, + 7.704164604345901e-03, 7.504038880782284e-04}, + {1.201244527959806e-02, 6.204547371934391e-02, 1.467419246783587e-01, + 2.315271861986933e-01, 2.746085708964524e-01, 2.557004122008758e-01, + 1.880714727028224e-01, 1.066649642595343e-01, 4.369574953640146e-02, + 1.111523459854731e-02, 1.149899262705060e-03}, + {1.800505712143062e-03, 1.652979749395006e-02, 6.021451394938584e-02, + 1.325938441003085e-01, 2.046269423886040e-01, 2.351354593778834e-01, + 2.046269423886035e-01, 1.325938441003083e-01, 6.021451394938595e-02, + 1.652979749395013e-02, 1.800505712143067e-03}, + {4.384344964523082e-04, 6.183266472687995e-03, 3.150640500283894e-02, + 9.066995484349000e-02, 1.737233827592598e-01, 2.379749388872305e-01, + 2.387560489479536e-01, 1.733323982904236e-01, 8.599874690757750e-02, + 2.521164399849497e-02, 2.871446060256749e-03}, + {1.484733835020589e-04, 2.953427403304018e-03, 1.978315420318005e-02, + 7.109997502153002e-02, 1.634634630424583e-01, 2.600835280107577e-01, + 2.948607419574116e-01, 2.361731707811737e-01, 1.265434095391612e-01, + 3.928594784442110e-02, 4.652327860721107e-03}}, + {// a = 3 + {3.447174305652413e-01, 7.000185078915774e-01, 8.566217628420132e-01, + 8.056538714959643e-01, 6.152504691304241e-01, 3.846472609341519e-01, + 1.935791520138537e-01, 7.516721727852196e-02, 2.071970073321518e-02, + 3.411276856284806e-03, 2.133502587477222e-04}, + {2.059735091678128e-02, 1.024342121217006e-01, 2.280226846392065e-01, + 3.305087708885728e-01, 3.506808225567526e-01, 2.834908718635391e-01, + 1.748287416827368e-01, 7.971906620710731e-02, 2.490755722153995e-02, + 4.508258947434251e-03, 3.016629546290895e-04}, + {2.871446060256749e-03, 2.521164399849497e-02, 8.599874690757750e-02, + 1.733323982904236e-01, 2.387560489479536e-01, 2.379749388872305e-01, + 1.737233827592598e-01, 9.066995484349000e-02, 3.150640500283894e-02, + 6.183266472687995e-03, 4.384344964523082e-04}, + {6.523613474704498e-04, 8.748910971782960e-03, 4.156660510678858e-02, + 1.091649348532573e-01, 1.863580639798480e-01, 2.213039617674194e-01, + 1.863580639798469e-01, 1.091649348532574e-01, 4.156660510678864e-02, + 8.748910971782996e-03, 6.523613474704435e-04}, + {2.067362223280178e-04, 3.891630830430294e-03, 2.421953842084509e-02, + 7.924262835390317e-02, 1.621005459870287e-01, 2.235084160660967e-01, + 2.128254368400618e-01, 1.377782067838998e-01, 5.681049195022907e-02, + 1.271152895582430e-02, 9.905538750657984e-04}}, + {// a = 4 + {6.410996581617191e-01, 1.268666943139948e+00, 1.481068587210711e+00, + 1.299520565991693e+00, 9.038653956468931e-01, 5.012202707328959e-01, + 2.171198836550185e-01, 7.006400214752159e-02, 1.538057913605891e-02, + 1.910381097398653e-03, 8.373308015001190e-05}, + {3.570611398256825e-02, 1.718078254086433e-01, 3.628202611779144e-01, + 4.886006136701065e-01, 4.708939598294999e-01, 3.371979991598771e-01, + 1.789973972638532e-01, 6.792551436237800e-02, 1.694941861111087e-02, + 2.324551515253453e-03, 1.096783521306954e-04}, + {4.652327860721107e-03, 3.928594784442110e-02, 1.265434095391612e-01, + 2.361731707811737e-01, 2.948607419574116e-01, 2.600835280107577e-01, + 1.634634630424583e-01, 7.109997502153002e-02, 1.978315420318005e-02, + 2.953427403304018e-03, 1.484733835020589e-04}, + {9.905538750657984e-04, 1.271152895582430e-02, 5.681049195022907e-02, + 1.377782067838998e-01, 2.128254368400618e-01, 2.235084160660967e-01, + 1.621005459870287e-01, 7.924262835390317e-02, 2.421953842084509e-02, + 3.891630830430294e-03, 2.067362223280178e-04}, + {2.949699603442579e-04, 5.289865663661539e-03, 3.086829305071137e-02, + 9.305474127317909e-02, 1.720131439851640e-01, 2.096563848322926e-01, + 1.720131439851645e-01, 9.305474127317945e-02, 3.086829305071124e-02, + 5.289865663661513e-03, 2.949699603442520e-04}}}; static double _gaussJacobiWt_12[5][5][12] = { - { // a = 0 - { 4.717533638651165e-02, 1.069393259953177e-01, 1.600783285433471e-01, 2.031674267230658e-01, 2.334925365383551e-01, 2.491470458134026e-01, 2.491470458134035e-01, 2.334925365383542e-01, 2.031674267230665e-01, 1.600783285433462e-01, 1.069393259953178e-01, 4.717533638651158e-02}, - { 3.100728883752147e-03, 1.777923118267409e-02, 4.974403666568916e-02, 9.950712163706166e-02, 1.618066148276543e-01, 2.264553748546699e-01, 2.804373599905204e-01, 3.107852672621240e-01, 3.075864107201645e-01, 2.664270025066927e-01, 1.897114079215105e-01, 8.665944354748625e-02}, - { 4.764028784664954e-04, 4.959627188356132e-03, 2.176673715283072e-02, 6.173093619109135e-02, 1.323787491568754e-01, 2.312644147098197e-01, 3.421181085615115e-01, 4.365915293138515e-01, 4.820048599008365e-01, 4.526734779957938e-01, 3.404529229392461e-01, 1.602489006779884e-01}, - { 1.193330081565083e-04, 1.945006560838395e-03, 1.213502956040336e-02, 4.560803582593135e-02, 1.228862623362184e-01, 2.585409591884750e-01, 4.447159771712300e-01, 6.403133491695374e-01, 7.766469990726416e-01, 7.822051788980672e-01, 6.168690025573704e-01, 2.980148666511306e-01}, - { 4.167550989594096e-05, 9.746484451651032e-04, 8.110511582616609e-03, 3.854481130511551e-02, 1.259585671789702e-01, 3.106195879667678e-01, 6.083968301148478e-01, 9.725643700996832e-01, 1.280325087870005e+00, 1.370700913695420e+00, 1.126816800360463e+00, 5.569461958710573e-01} - }, - { // a = 1 - { 8.665944354748625e-02, 1.897114079215105e-01, 2.664270025066927e-01, 3.075864107201645e-01, 3.107852672621240e-01, 2.804373599905204e-01, 2.264553748546699e-01, 1.618066148276543e-01, 9.950712163706166e-02, 4.974403666568916e-02, 1.777923118267409e-02, 3.100728883752147e-03}, - { 5.248378306690829e-03, 2.878773224796075e-02, 7.501033346761930e-02, 1.357541298844588e-01, 1.933877382614317e-01, 2.284783544985051e-01, 2.284783544985060e-01, 1.933877382614313e-01, 1.357541298844587e-01, 7.501033346761908e-02, 2.878773224796063e-02, 5.248378306690834e-03}, - { 7.456481160415842e-04, 7.367522276476792e-03, 2.993159664982637e-02, 7.646513872066901e-02, 1.432531534925865e-01, 2.109979259488977e-01, 2.521139155965506e-01, 2.461565322299591e-01, 1.933856185056310e-01, 1.164183433759065e-01, 4.750023002042897e-02, 8.997708400360172e-03}, - { 1.733201954603828e-04, 2.663375924142158e-03, 1.530538769641553e-02, 5.163296826317448e-02, 1.212728758681529e-01, 2.149277465007842e-01, 2.987288283147951e-01, 3.296424030105624e-01, 2.853791830959428e-01, 1.850479228618409e-01, 7.963049002866893e-02, 1.559549824006065e-02}, - { 5.636000883929227e-05, 1.235639203329192e-03, 9.431187007408585e-03, 4.011459085676399e-02, 1.140748319888013e-01, 2.368318931636009e-01, 3.750272556032356e-01, 4.602252951282348e-01, 4.336459582840581e-01, 3.000874153659292e-01, 1.353132928880176e-01, 2.728961383511349e-02} - }, - { // a = 2 - { 1.602489006779884e-01, 3.404529229392461e-01, 4.526734779957938e-01, 4.820048599008365e-01, 4.365915293138515e-01, 3.421181085615115e-01, 2.312644147098197e-01, 1.323787491568754e-01, 6.173093619109135e-02, 2.176673715283072e-02, 4.959627188356132e-03, 4.764028784664954e-04}, - { 8.997708400360172e-03, 4.750023002042897e-02, 1.164183433759065e-01, 1.933856185056310e-01, 2.461565322299591e-01, 2.521139155965506e-01, 2.109979259488977e-01, 1.432531534925865e-01, 7.646513872066901e-02, 2.993159664982637e-02, 7.367522276476792e-03, 7.456481160415842e-04}, - { 1.188743462219393e-03, 1.122649323736320e-02, 4.267068321985847e-02, 9.965956754203634e-02, 1.663963219714445e-01, 2.121915239004110e-01, 2.121915239004118e-01, 1.663963219714444e-01, 9.965956754203625e-02, 4.267068321985902e-02, 1.122649323736324e-02, 1.188743462219383e-03}, - { 2.577369625023287e-04, 3.763263514317599e-03, 2.014208651189309e-02, 6.192061938238031e-02, 1.293473345939407e-01, 1.982851263604149e-01, 2.306926096950135e-01, 2.047209310033421e-01, 1.354431301030032e-01, 6.268919235475058e-02, 1.747921950928045e-02, 1.925416675828279e-03}, - { 7.840742034268568e-05, 1.625091831063023e-03, 1.150901408639995e-02, 4.448959898667763e-02, 1.123347127135556e-01, 2.015952487575734e-01, 2.672983975138279e-01, 2.641333767278580e-01, 1.906288199813589e-01, 9.447154448063547e-02, 2.772150868146296e-02, 3.161897866864669e-03} - }, - { // a = 3 - { 2.980148666511306e-01, 6.168690025573704e-01, 7.822051788980672e-01, 7.766469990726416e-01, 6.403133491695374e-01, 4.447159771712300e-01, 2.585409591884750e-01, 1.228862623362184e-01, 4.560803582593135e-02, 1.213502956040336e-02, 1.945006560838395e-03, 1.193330081565083e-04}, - { 1.559549824006065e-02, 7.963049002866893e-02, 1.850479228618409e-01, 2.853791830959428e-01, 3.296424030105624e-01, 2.987288283147951e-01, 2.149277465007842e-01, 1.212728758681529e-01, 5.163296826317448e-02, 1.530538769641553e-02, 2.663375924142158e-03, 1.733201954603828e-04}, - { 1.925416675828279e-03, 1.747921950928045e-02, 6.268919235475058e-02, 1.354431301030032e-01, 2.047209310033421e-01, 2.306926096950135e-01, 1.982851263604149e-01, 1.293473345939407e-01, 6.192061938238031e-02, 2.014208651189309e-02, 3.763263514317599e-03, 2.577369625023287e-04}, - { 3.911486181435101e-04, 5.461105384452814e-03, 2.746919446371457e-02, 7.788624927503261e-02, 1.469991263025606e-01, 1.989360330989531e-01, 1.989360330989529e-01, 1.469991263025605e-01, 7.788624927503256e-02, 2.746919446371462e-02, 5.461105384452812e-03, 3.911486181435191e-04}, - { 1.117846511781470e-04, 2.205326630343932e-03, 1.462738139401716e-02, 5.202304164220765e-02, 1.184941629093040e-01, 1.875938598228309e-01, 2.138206304777831e-01, 1.761070201336626e-01, 1.019753091517070e-01, 3.861402950916015e-02, 8.108924612841111e-03, 6.042433506779847e-04} - }, - { // a = 4 - { 5.569461958710573e-01, 1.126816800360463e+00, 1.370700913695420e+00, 1.280325087870005e+00, 9.725643700996832e-01, 6.083968301148478e-01, 3.106195879667678e-01, 1.259585671789702e-01, 3.854481130511551e-02, 8.110511582616609e-03, 9.746484451651032e-04, 4.167550989594096e-05}, - { 2.728961383511349e-02, 1.353132928880176e-01, 3.000874153659292e-01, 4.336459582840581e-01, 4.602252951282348e-01, 3.750272556032356e-01, 2.368318931636009e-01, 1.140748319888013e-01, 4.011459085676399e-02, 9.431187007408585e-03, 1.235639203329192e-03, 5.636000883929227e-05}, - { 3.161897866864669e-03, 2.772150868146296e-02, 9.447154448063547e-02, 1.906288199813589e-01, 2.641333767278580e-01, 2.672983975138279e-01, 2.015952487575734e-01, 1.123347127135556e-01, 4.448959898667763e-02, 1.150901408639995e-02, 1.625091831063023e-03, 7.840742034268568e-05}, - { 6.042433506779847e-04, 8.108924612841111e-03, 3.861402950916015e-02, 1.019753091517070e-01, 1.761070201336626e-01, 2.138206304777831e-01, 1.875938598228309e-01, 1.184941629093040e-01, 5.202304164220765e-02, 1.462738139401716e-02, 2.205326630343932e-03, 1.117846511781470e-04}, - { 1.628181143406894e-04, 3.074794517936475e-03, 1.924705568647300e-02, 6.361096326827916e-02, 1.323750332742049e-01, 1.878785414879722e-01, 1.878785414879728e-01, 1.323750332742052e-01, 6.361096326827892e-02, 1.924705568647300e-02, 3.074794517936469e-03, 1.628181143406876e-04} - } -}; + {// a = 0 + {4.717533638651165e-02, 1.069393259953177e-01, 1.600783285433471e-01, + 2.031674267230658e-01, 2.334925365383551e-01, 2.491470458134026e-01, + 2.491470458134035e-01, 2.334925365383542e-01, 2.031674267230665e-01, + 1.600783285433462e-01, 1.069393259953178e-01, 4.717533638651158e-02}, + {3.100728883752147e-03, 1.777923118267409e-02, 4.974403666568916e-02, + 9.950712163706166e-02, 1.618066148276543e-01, 2.264553748546699e-01, + 2.804373599905204e-01, 3.107852672621240e-01, 3.075864107201645e-01, + 2.664270025066927e-01, 1.897114079215105e-01, 8.665944354748625e-02}, + {4.764028784664954e-04, 4.959627188356132e-03, 2.176673715283072e-02, + 6.173093619109135e-02, 1.323787491568754e-01, 2.312644147098197e-01, + 3.421181085615115e-01, 4.365915293138515e-01, 4.820048599008365e-01, + 4.526734779957938e-01, 3.404529229392461e-01, 1.602489006779884e-01}, + {1.193330081565083e-04, 1.945006560838395e-03, 1.213502956040336e-02, + 4.560803582593135e-02, 1.228862623362184e-01, 2.585409591884750e-01, + 4.447159771712300e-01, 6.403133491695374e-01, 7.766469990726416e-01, + 7.822051788980672e-01, 6.168690025573704e-01, 2.980148666511306e-01}, + {4.167550989594096e-05, 9.746484451651032e-04, 8.110511582616609e-03, + 3.854481130511551e-02, 1.259585671789702e-01, 3.106195879667678e-01, + 6.083968301148478e-01, 9.725643700996832e-01, 1.280325087870005e+00, + 1.370700913695420e+00, 1.126816800360463e+00, 5.569461958710573e-01}}, + {// a = 1 + {8.665944354748625e-02, 1.897114079215105e-01, 2.664270025066927e-01, + 3.075864107201645e-01, 3.107852672621240e-01, 2.804373599905204e-01, + 2.264553748546699e-01, 1.618066148276543e-01, 9.950712163706166e-02, + 4.974403666568916e-02, 1.777923118267409e-02, 3.100728883752147e-03}, + {5.248378306690829e-03, 2.878773224796075e-02, 7.501033346761930e-02, + 1.357541298844588e-01, 1.933877382614317e-01, 2.284783544985051e-01, + 2.284783544985060e-01, 1.933877382614313e-01, 1.357541298844587e-01, + 7.501033346761908e-02, 2.878773224796063e-02, 5.248378306690834e-03}, + {7.456481160415842e-04, 7.367522276476792e-03, 2.993159664982637e-02, + 7.646513872066901e-02, 1.432531534925865e-01, 2.109979259488977e-01, + 2.521139155965506e-01, 2.461565322299591e-01, 1.933856185056310e-01, + 1.164183433759065e-01, 4.750023002042897e-02, 8.997708400360172e-03}, + {1.733201954603828e-04, 2.663375924142158e-03, 1.530538769641553e-02, + 5.163296826317448e-02, 1.212728758681529e-01, 2.149277465007842e-01, + 2.987288283147951e-01, 3.296424030105624e-01, 2.853791830959428e-01, + 1.850479228618409e-01, 7.963049002866893e-02, 1.559549824006065e-02}, + {5.636000883929227e-05, 1.235639203329192e-03, 9.431187007408585e-03, + 4.011459085676399e-02, 1.140748319888013e-01, 2.368318931636009e-01, + 3.750272556032356e-01, 4.602252951282348e-01, 4.336459582840581e-01, + 3.000874153659292e-01, 1.353132928880176e-01, 2.728961383511349e-02}}, + {// a = 2 + {1.602489006779884e-01, 3.404529229392461e-01, 4.526734779957938e-01, + 4.820048599008365e-01, 4.365915293138515e-01, 3.421181085615115e-01, + 2.312644147098197e-01, 1.323787491568754e-01, 6.173093619109135e-02, + 2.176673715283072e-02, 4.959627188356132e-03, 4.764028784664954e-04}, + {8.997708400360172e-03, 4.750023002042897e-02, 1.164183433759065e-01, + 1.933856185056310e-01, 2.461565322299591e-01, 2.521139155965506e-01, + 2.109979259488977e-01, 1.432531534925865e-01, 7.646513872066901e-02, + 2.993159664982637e-02, 7.367522276476792e-03, 7.456481160415842e-04}, + {1.188743462219393e-03, 1.122649323736320e-02, 4.267068321985847e-02, + 9.965956754203634e-02, 1.663963219714445e-01, 2.121915239004110e-01, + 2.121915239004118e-01, 1.663963219714444e-01, 9.965956754203625e-02, + 4.267068321985902e-02, 1.122649323736324e-02, 1.188743462219383e-03}, + {2.577369625023287e-04, 3.763263514317599e-03, 2.014208651189309e-02, + 6.192061938238031e-02, 1.293473345939407e-01, 1.982851263604149e-01, + 2.306926096950135e-01, 2.047209310033421e-01, 1.354431301030032e-01, + 6.268919235475058e-02, 1.747921950928045e-02, 1.925416675828279e-03}, + {7.840742034268568e-05, 1.625091831063023e-03, 1.150901408639995e-02, + 4.448959898667763e-02, 1.123347127135556e-01, 2.015952487575734e-01, + 2.672983975138279e-01, 2.641333767278580e-01, 1.906288199813589e-01, + 9.447154448063547e-02, 2.772150868146296e-02, 3.161897866864669e-03}}, + {// a = 3 + {2.980148666511306e-01, 6.168690025573704e-01, 7.822051788980672e-01, + 7.766469990726416e-01, 6.403133491695374e-01, 4.447159771712300e-01, + 2.585409591884750e-01, 1.228862623362184e-01, 4.560803582593135e-02, + 1.213502956040336e-02, 1.945006560838395e-03, 1.193330081565083e-04}, + {1.559549824006065e-02, 7.963049002866893e-02, 1.850479228618409e-01, + 2.853791830959428e-01, 3.296424030105624e-01, 2.987288283147951e-01, + 2.149277465007842e-01, 1.212728758681529e-01, 5.163296826317448e-02, + 1.530538769641553e-02, 2.663375924142158e-03, 1.733201954603828e-04}, + {1.925416675828279e-03, 1.747921950928045e-02, 6.268919235475058e-02, + 1.354431301030032e-01, 2.047209310033421e-01, 2.306926096950135e-01, + 1.982851263604149e-01, 1.293473345939407e-01, 6.192061938238031e-02, + 2.014208651189309e-02, 3.763263514317599e-03, 2.577369625023287e-04}, + {3.911486181435101e-04, 5.461105384452814e-03, 2.746919446371457e-02, + 7.788624927503261e-02, 1.469991263025606e-01, 1.989360330989531e-01, + 1.989360330989529e-01, 1.469991263025605e-01, 7.788624927503256e-02, + 2.746919446371462e-02, 5.461105384452812e-03, 3.911486181435191e-04}, + {1.117846511781470e-04, 2.205326630343932e-03, 1.462738139401716e-02, + 5.202304164220765e-02, 1.184941629093040e-01, 1.875938598228309e-01, + 2.138206304777831e-01, 1.761070201336626e-01, 1.019753091517070e-01, + 3.861402950916015e-02, 8.108924612841111e-03, 6.042433506779847e-04}}, + {// a = 4 + {5.569461958710573e-01, 1.126816800360463e+00, 1.370700913695420e+00, + 1.280325087870005e+00, 9.725643700996832e-01, 6.083968301148478e-01, + 3.106195879667678e-01, 1.259585671789702e-01, 3.854481130511551e-02, + 8.110511582616609e-03, 9.746484451651032e-04, 4.167550989594096e-05}, + {2.728961383511349e-02, 1.353132928880176e-01, 3.000874153659292e-01, + 4.336459582840581e-01, 4.602252951282348e-01, 3.750272556032356e-01, + 2.368318931636009e-01, 1.140748319888013e-01, 4.011459085676399e-02, + 9.431187007408585e-03, 1.235639203329192e-03, 5.636000883929227e-05}, + {3.161897866864669e-03, 2.772150868146296e-02, 9.447154448063547e-02, + 1.906288199813589e-01, 2.641333767278580e-01, 2.672983975138279e-01, + 2.015952487575734e-01, 1.123347127135556e-01, 4.448959898667763e-02, + 1.150901408639995e-02, 1.625091831063023e-03, 7.840742034268568e-05}, + {6.042433506779847e-04, 8.108924612841111e-03, 3.861402950916015e-02, + 1.019753091517070e-01, 1.761070201336626e-01, 2.138206304777831e-01, + 1.875938598228309e-01, 1.184941629093040e-01, 5.202304164220765e-02, + 1.462738139401716e-02, 2.205326630343932e-03, 1.117846511781470e-04}, + {1.628181143406894e-04, 3.074794517936475e-03, 1.924705568647300e-02, + 6.361096326827916e-02, 1.323750332742049e-01, 1.878785414879722e-01, + 1.878785414879728e-01, 1.323750332742052e-01, 6.361096326827892e-02, + 1.924705568647300e-02, 3.074794517936469e-03, 1.628181143406876e-04}}}; static double _gaussJacobiWt_13[5][5][13] = { - { // a = 0 - { 4.048400476531575e-02, 9.212149983772837e-02, 1.388735102197882e-01, 1.781459807619455e-01, 2.078160475368879e-01, 2.262831802628978e-01, 2.325515532308743e-01, 2.262831802628966e-01, 2.078160475368891e-01, 1.781459807619461e-01, 1.388735102197881e-01, 9.212149983772847e-02, 4.048400476531563e-02}, - { 2.312226819744752e-03, 1.335343700309510e-02, 3.779569791837089e-02, 7.685582865887940e-02, 1.277471486488124e-01, 1.839831227042100e-01, 2.364819252563691e-01, 2.752621179502622e-01, 2.913987860632732e-01, 2.788538731285788e-01, 2.358157518265868e-01, 1.652811576793572e-01, 7.485892634246154e-02}, - { 3.121359461131697e-04, 3.285767134327090e-03, 1.465912911391509e-02, 4.250855471066116e-02, 9.382607674481498e-02, 1.700399737180531e-01, 2.635236134274632e-01, 3.569968060449198e-01, 4.267201728469727e-01, 4.488922970466200e-01, 4.072786457015594e-01, 2.994136653507510e-01, 1.392098288804964e-01}, - { 6.937390186694232e-05, 1.148285284471928e-03, 7.319582997219005e-03, 2.829353227289212e-02, 7.899581366652146e-02, 1.737411980856215e-01, 3.158212716990506e-01, 4.874953331555133e-01, 6.473175933518743e-01, 7.394215458673388e-01, 7.133884534469215e-01, 5.468339215681184e-01, 2.601540947025925e-01}, - { 2.168601794925228e-05, 5.174028875011276e-04, 4.421556577357340e-03, 2.173743508511354e-02, 7.408929962728636e-02, 1.923993910880153e-01, 4.015101204430444e-01, 6.943966563830739e-01, 1.010970989863907e+00, 1.241523395706928e+00, 1.264462345661009e+00, 1.005683466539794e+00, 4.882662541190213e-01} - }, - { // a = 1 - { 7.485892634246154e-02, 1.652811576793572e-01, 2.358157518265868e-01, 2.788538731285788e-01, 2.913987860632732e-01, 2.752621179502622e-01, 2.364819252563691e-01, 1.839831227042100e-01, 1.277471486488124e-01, 7.685582865887940e-02, 3.779569791837089e-02, 1.335343700309510e-02, 2.312226819744752e-03}, - { 3.963459182191560e-03, 2.202259816054245e-02, 5.859867372784859e-02, 1.092820307207265e-01, 1.621330288912999e-01, 2.021428178096500e-01, 2.170481163488148e-01, 2.021428178096503e-01, 1.621330288913002e-01, 1.092820307207269e-01, 5.859867372784814e-02, 2.202259816054258e-02, 3.963459182191537e-03}, - { 4.974697396217912e-04, 5.002681014390005e-03, 2.086493921623218e-02, 5.525688426182686e-02, 1.085484975066134e-01, 1.700194948735662e-01, 2.200217680401301e-01, 2.386791532071573e-01, 2.165954959761593e-01, 1.610154481635283e-01, 9.305911626472203e-02, 3.690349010142586e-02, 6.868894967957435e-03}, - { 1.031100740970801e-04, 1.620522373394041e-03, 9.611568848164579e-03, 3.381296713438840e-02, 8.382448867815685e-02, 1.591371702342223e-01, 2.415053788486821e-01, 2.987711704546474e-01, 3.017760050589875e-01, 2.443408860166679e-01, 1.507931911828451e-01, 6.268541649393325e-02, 1.201812460181474e-02}, - { 3.014616932438513e-05, 6.793549303198244e-04, 5.380402912272425e-03, 2.400342141421549e-02, 7.250399049992343e-02, 1.623672833574305e-01, 2.828789150684345e-01, 3.924556097743016e-01, 4.354347544679585e-01, 3.800960790498376e-01, 2.485665142539380e-01, 1.077332484690910e-01, 2.120361296628662e-02} - }, - { // a = 2 - { 1.392098288804964e-01, 2.994136653507510e-01, 4.072786457015594e-01, 4.488922970466200e-01, 4.267201728469727e-01, 3.569968060449198e-01, 2.635236134274632e-01, 1.700399737180531e-01, 9.382607674481498e-02, 4.250855471066116e-02, 1.465912911391509e-02, 3.285767134327090e-03, 3.121359461131697e-04}, - { 6.868894967957435e-03, 3.690349010142586e-02, 9.305911626472203e-02, 1.610154481635283e-01, 2.165954959761593e-01, 2.386791532071573e-01, 2.200217680401301e-01, 1.700194948735662e-01, 1.085484975066134e-01, 5.525688426182686e-02, 2.086493921623218e-02, 5.002681014390005e-03, 4.974697396217912e-04}, - { 8.055421013939556e-04, 7.783410603515764e-03, 3.061136703734236e-02, 7.492798978976632e-02, 1.330992358210581e-01, 1.839654979337558e-01, 2.042805800930028e-01, 1.839654979337549e-01, 1.330992358210576e-01, 7.492798978976679e-02, 3.061136703734238e-02, 7.783410603515736e-03, 8.055421013939598e-04}, - { 1.564122466970863e-04, 2.349147984501424e-03, 1.308305096663412e-02, 4.240412564469897e-02, 9.484987207187981e-02, 1.587022870850947e-01, 2.065979808917429e-01, 2.123067112458968e-01, 1.712314102542858e-01, 1.052512386966261e-01, 4.607540000443199e-02, 1.233648660199831e-02, 1.322542972178784e-03}, - { 4.295001061479064e-05, 9.205812398147590e-04, 6.821344197017788e-03, 2.796255040489091e-02, 7.607183809904966e-02, 1.499986056368707e-01, 2.241370184428464e-01, 2.584752687983442e-01, 2.293349277361163e-01, 1.523281087819183e-01, 7.088709168777810e-02, 1.986948913071626e-02, 2.197844881642222e-03} - }, - { // a = 3 - { 2.601540947025925e-01, 5.468339215681184e-01, 7.133884534469215e-01, 7.394215458673388e-01, 6.473175933518743e-01, 4.874953331555133e-01, 3.158212716990506e-01, 1.737411980856215e-01, 7.899581366652146e-02, 2.829353227289212e-02, 7.319582997219005e-03, 1.148285284471928e-03, 6.937390186694232e-05}, - { 1.201812460181474e-02, 6.268541649393325e-02, 1.507931911828451e-01, 2.443408860166679e-01, 3.017760050589875e-01, 2.987711704546474e-01, 2.415053788486821e-01, 1.591371702342223e-01, 8.382448867815685e-02, 3.381296713438840e-02, 9.611568848164579e-03, 1.620522373394041e-03, 1.031100740970801e-04}, - { 1.322542972178784e-03, 1.233648660199831e-02, 4.607540000443199e-02, 1.052512386966261e-01, 1.712314102542858e-01, 2.123067112458968e-01, 2.065979808917429e-01, 1.587022870850947e-01, 9.484987207187981e-02, 4.240412564469897e-02, 1.308305096663412e-02, 2.349147984501424e-03, 1.564122466970863e-04}, - { 2.415281909787100e-04, 3.484873369011269e-03, 1.836046147696099e-02, 5.537471349643075e-02, 1.132067473271513e-01, 1.697100479751122e-01, 1.935289706144242e-01, 1.697100479751119e-01, 1.132067473271510e-01, 5.537471349643071e-02, 1.836046147696111e-02, 3.484873369011242e-03, 2.415281909787145e-04}, - { 6.252059281441082e-05, 1.281884255660952e-03, 8.956207670262731e-03, 3.407904169227087e-02, 8.459163548636887e-02, 1.493001878472489e-01, 1.953783065712911e-01, 1.923582394121643e-01, 1.413269982499625e-01, 7.484582724561369e-02, 2.645164081457572e-02, 5.274380504982012e-03, 3.788439424974829e-04} - }, - { // a = 4 - { 4.882662541190213e-01, 1.005683466539794e+00, 1.264462345661009e+00, 1.241523395706928e+00, 1.010970989863907e+00, 6.943966563830739e-01, 4.015101204430444e-01, 1.923993910880153e-01, 7.408929962728636e-02, 2.173743508511354e-02, 4.421556577357340e-03, 5.174028875011276e-04, 2.168601794925228e-05}, - { 2.120361296628662e-02, 1.077332484690910e-01, 2.485665142539380e-01, 3.800960790498376e-01, 4.354347544679585e-01, 3.924556097743016e-01, 2.828789150684345e-01, 1.623672833574305e-01, 7.250399049992343e-02, 2.400342141421549e-02, 5.380402912272425e-03, 6.793549303198244e-04, 3.014616932438513e-05}, - { 2.197844881642222e-03, 1.986948913071626e-02, 7.088709168777810e-02, 1.523281087819183e-01, 2.293349277361163e-01, 2.584752687983442e-01, 2.241370184428464e-01, 1.499986056368707e-01, 7.607183809904966e-02, 2.796255040489091e-02, 6.821344197017788e-03, 9.205812398147590e-04, 4.295001061479064e-05}, - { 3.788439424974829e-04, 5.274380504982012e-03, 2.645164081457572e-02, 7.484582724561369e-02, 1.413269982499625e-01, 1.923582394121643e-01, 1.953783065712911e-01, 1.493001878472489e-01, 8.459163548636887e-02, 3.407904169227087e-02, 8.956207670262731e-03, 1.281884255660952e-03, 6.252059281441082e-05}, - { 9.274747547932102e-05, 1.827839107867632e-03, 1.211960626309079e-02, 4.316636605369080e-02, 9.880604143765884e-02, 1.581799533378842e-01, 1.843133053470706e-01, 1.581799533378844e-01, 9.880604143765898e-02, 4.316636605369080e-02, 1.211960626309077e-02, 1.827839107867644e-03, 9.274747547932266e-05} - } -}; + {// a = 0 + {4.048400476531575e-02, 9.212149983772837e-02, 1.388735102197882e-01, + 1.781459807619455e-01, 2.078160475368879e-01, 2.262831802628978e-01, + 2.325515532308743e-01, 2.262831802628966e-01, 2.078160475368891e-01, + 1.781459807619461e-01, 1.388735102197881e-01, 9.212149983772847e-02, + 4.048400476531563e-02}, + {2.312226819744752e-03, 1.335343700309510e-02, 3.779569791837089e-02, + 7.685582865887940e-02, 1.277471486488124e-01, 1.839831227042100e-01, + 2.364819252563691e-01, 2.752621179502622e-01, 2.913987860632732e-01, + 2.788538731285788e-01, 2.358157518265868e-01, 1.652811576793572e-01, + 7.485892634246154e-02}, + {3.121359461131697e-04, 3.285767134327090e-03, 1.465912911391509e-02, + 4.250855471066116e-02, 9.382607674481498e-02, 1.700399737180531e-01, + 2.635236134274632e-01, 3.569968060449198e-01, 4.267201728469727e-01, + 4.488922970466200e-01, 4.072786457015594e-01, 2.994136653507510e-01, + 1.392098288804964e-01}, + {6.937390186694232e-05, 1.148285284471928e-03, 7.319582997219005e-03, + 2.829353227289212e-02, 7.899581366652146e-02, 1.737411980856215e-01, + 3.158212716990506e-01, 4.874953331555133e-01, 6.473175933518743e-01, + 7.394215458673388e-01, 7.133884534469215e-01, 5.468339215681184e-01, + 2.601540947025925e-01}, + {2.168601794925228e-05, 5.174028875011276e-04, 4.421556577357340e-03, + 2.173743508511354e-02, 7.408929962728636e-02, 1.923993910880153e-01, + 4.015101204430444e-01, 6.943966563830739e-01, 1.010970989863907e+00, + 1.241523395706928e+00, 1.264462345661009e+00, 1.005683466539794e+00, + 4.882662541190213e-01}}, + {// a = 1 + {7.485892634246154e-02, 1.652811576793572e-01, 2.358157518265868e-01, + 2.788538731285788e-01, 2.913987860632732e-01, 2.752621179502622e-01, + 2.364819252563691e-01, 1.839831227042100e-01, 1.277471486488124e-01, + 7.685582865887940e-02, 3.779569791837089e-02, 1.335343700309510e-02, + 2.312226819744752e-03}, + {3.963459182191560e-03, 2.202259816054245e-02, 5.859867372784859e-02, + 1.092820307207265e-01, 1.621330288912999e-01, 2.021428178096500e-01, + 2.170481163488148e-01, 2.021428178096503e-01, 1.621330288913002e-01, + 1.092820307207269e-01, 5.859867372784814e-02, 2.202259816054258e-02, + 3.963459182191537e-03}, + {4.974697396217912e-04, 5.002681014390005e-03, 2.086493921623218e-02, + 5.525688426182686e-02, 1.085484975066134e-01, 1.700194948735662e-01, + 2.200217680401301e-01, 2.386791532071573e-01, 2.165954959761593e-01, + 1.610154481635283e-01, 9.305911626472203e-02, 3.690349010142586e-02, + 6.868894967957435e-03}, + {1.031100740970801e-04, 1.620522373394041e-03, 9.611568848164579e-03, + 3.381296713438840e-02, 8.382448867815685e-02, 1.591371702342223e-01, + 2.415053788486821e-01, 2.987711704546474e-01, 3.017760050589875e-01, + 2.443408860166679e-01, 1.507931911828451e-01, 6.268541649393325e-02, + 1.201812460181474e-02}, + {3.014616932438513e-05, 6.793549303198244e-04, 5.380402912272425e-03, + 2.400342141421549e-02, 7.250399049992343e-02, 1.623672833574305e-01, + 2.828789150684345e-01, 3.924556097743016e-01, 4.354347544679585e-01, + 3.800960790498376e-01, 2.485665142539380e-01, 1.077332484690910e-01, + 2.120361296628662e-02}}, + {// a = 2 + {1.392098288804964e-01, 2.994136653507510e-01, 4.072786457015594e-01, + 4.488922970466200e-01, 4.267201728469727e-01, 3.569968060449198e-01, + 2.635236134274632e-01, 1.700399737180531e-01, 9.382607674481498e-02, + 4.250855471066116e-02, 1.465912911391509e-02, 3.285767134327090e-03, + 3.121359461131697e-04}, + {6.868894967957435e-03, 3.690349010142586e-02, 9.305911626472203e-02, + 1.610154481635283e-01, 2.165954959761593e-01, 2.386791532071573e-01, + 2.200217680401301e-01, 1.700194948735662e-01, 1.085484975066134e-01, + 5.525688426182686e-02, 2.086493921623218e-02, 5.002681014390005e-03, + 4.974697396217912e-04}, + {8.055421013939556e-04, 7.783410603515764e-03, 3.061136703734236e-02, + 7.492798978976632e-02, 1.330992358210581e-01, 1.839654979337558e-01, + 2.042805800930028e-01, 1.839654979337549e-01, 1.330992358210576e-01, + 7.492798978976679e-02, 3.061136703734238e-02, 7.783410603515736e-03, + 8.055421013939598e-04}, + {1.564122466970863e-04, 2.349147984501424e-03, 1.308305096663412e-02, + 4.240412564469897e-02, 9.484987207187981e-02, 1.587022870850947e-01, + 2.065979808917429e-01, 2.123067112458968e-01, 1.712314102542858e-01, + 1.052512386966261e-01, 4.607540000443199e-02, 1.233648660199831e-02, + 1.322542972178784e-03}, + {4.295001061479064e-05, 9.205812398147590e-04, 6.821344197017788e-03, + 2.796255040489091e-02, 7.607183809904966e-02, 1.499986056368707e-01, + 2.241370184428464e-01, 2.584752687983442e-01, 2.293349277361163e-01, + 1.523281087819183e-01, 7.088709168777810e-02, 1.986948913071626e-02, + 2.197844881642222e-03}}, + {// a = 3 + {2.601540947025925e-01, 5.468339215681184e-01, 7.133884534469215e-01, + 7.394215458673388e-01, 6.473175933518743e-01, 4.874953331555133e-01, + 3.158212716990506e-01, 1.737411980856215e-01, 7.899581366652146e-02, + 2.829353227289212e-02, 7.319582997219005e-03, 1.148285284471928e-03, + 6.937390186694232e-05}, + {1.201812460181474e-02, 6.268541649393325e-02, 1.507931911828451e-01, + 2.443408860166679e-01, 3.017760050589875e-01, 2.987711704546474e-01, + 2.415053788486821e-01, 1.591371702342223e-01, 8.382448867815685e-02, + 3.381296713438840e-02, 9.611568848164579e-03, 1.620522373394041e-03, + 1.031100740970801e-04}, + {1.322542972178784e-03, 1.233648660199831e-02, 4.607540000443199e-02, + 1.052512386966261e-01, 1.712314102542858e-01, 2.123067112458968e-01, + 2.065979808917429e-01, 1.587022870850947e-01, 9.484987207187981e-02, + 4.240412564469897e-02, 1.308305096663412e-02, 2.349147984501424e-03, + 1.564122466970863e-04}, + {2.415281909787100e-04, 3.484873369011269e-03, 1.836046147696099e-02, + 5.537471349643075e-02, 1.132067473271513e-01, 1.697100479751122e-01, + 1.935289706144242e-01, 1.697100479751119e-01, 1.132067473271510e-01, + 5.537471349643071e-02, 1.836046147696111e-02, 3.484873369011242e-03, + 2.415281909787145e-04}, + {6.252059281441082e-05, 1.281884255660952e-03, 8.956207670262731e-03, + 3.407904169227087e-02, 8.459163548636887e-02, 1.493001878472489e-01, + 1.953783065712911e-01, 1.923582394121643e-01, 1.413269982499625e-01, + 7.484582724561369e-02, 2.645164081457572e-02, 5.274380504982012e-03, + 3.788439424974829e-04}}, + {// a = 4 + {4.882662541190213e-01, 1.005683466539794e+00, 1.264462345661009e+00, + 1.241523395706928e+00, 1.010970989863907e+00, 6.943966563830739e-01, + 4.015101204430444e-01, 1.923993910880153e-01, 7.408929962728636e-02, + 2.173743508511354e-02, 4.421556577357340e-03, 5.174028875011276e-04, + 2.168601794925228e-05}, + {2.120361296628662e-02, 1.077332484690910e-01, 2.485665142539380e-01, + 3.800960790498376e-01, 4.354347544679585e-01, 3.924556097743016e-01, + 2.828789150684345e-01, 1.623672833574305e-01, 7.250399049992343e-02, + 2.400342141421549e-02, 5.380402912272425e-03, 6.793549303198244e-04, + 3.014616932438513e-05}, + {2.197844881642222e-03, 1.986948913071626e-02, 7.088709168777810e-02, + 1.523281087819183e-01, 2.293349277361163e-01, 2.584752687983442e-01, + 2.241370184428464e-01, 1.499986056368707e-01, 7.607183809904966e-02, + 2.796255040489091e-02, 6.821344197017788e-03, 9.205812398147590e-04, + 4.295001061479064e-05}, + {3.788439424974829e-04, 5.274380504982012e-03, 2.645164081457572e-02, + 7.484582724561369e-02, 1.413269982499625e-01, 1.923582394121643e-01, + 1.953783065712911e-01, 1.493001878472489e-01, 8.459163548636887e-02, + 3.407904169227087e-02, 8.956207670262731e-03, 1.281884255660952e-03, + 6.252059281441082e-05}, + {9.274747547932102e-05, 1.827839107867632e-03, 1.211960626309079e-02, + 4.316636605369080e-02, 9.880604143765884e-02, 1.581799533378842e-01, + 1.843133053470706e-01, 1.581799533378844e-01, 9.880604143765898e-02, + 4.316636605369080e-02, 1.211960626309077e-02, 1.827839107867644e-03, + 9.274747547932266e-05}}}; static double _gaussJacobiWt_14[5][5][14] = { - { // a = 0 - { 3.511946033175177e-02, 8.015808715976037e-02, 1.215185706879029e-01, 1.572031671581935e-01, 1.855383974779378e-01, 2.051984637212956e-01, 2.152638534631587e-01, 2.152638534631577e-01, 2.051984637212954e-01, 1.855383974779379e-01, 1.572031671581937e-01, 1.215185706879025e-01, 8.015808715976024e-02, 3.511946033175173e-02}, - { 1.758854834988620e-03, 1.021640527075066e-02, 2.918593653285032e-02, 6.012921497571456e-02, 1.016938616285951e-01, 1.497723858359430e-01, 1.980778180928126e-01, 2.391422360901269e-01, 2.655694025043416e-01, 2.713266384167318e-01, 2.528521022973164e-01, 2.097838140076677e-01, 1.451843122217735e-01, 6.530701729038797e-02}, - { 2.102092933512020e-04, 2.232794727575034e-03, 1.009427116125995e-02, 2.979900540226315e-02, 6.730381389709168e-02, 1.255546582805833e-01, 2.017294682947131e-01, 2.859120823401174e-01, 3.620274580356865e-01, 4.111193923157733e-01, 4.162069232856134e-01, 3.673181769173702e-01, 2.651167637596821e-01, 1.220416489555879e-01}, - { 4.172050424740590e-05, 6.992940782808716e-04, 4.535933794294162e-03, 1.793630081767578e-02, 5.153000016154856e-02, 1.174031767230196e-01, 2.228449471866996e-01, 3.627915647760550e-01, 5.149516227368192e-01, 6.414563472313936e-01, 6.984046665688880e-01, 6.508470638921978e-01, 4.875112074531002e-01, 2.290461540757796e-01}, - { 1.173639058512370e-05, 2.846438887262163e-04, 2.485900952118036e-03, 1.256281166489784e-02, 4.430069886476670e-02, 1.199026280873384e-01, 2.630633931261068e-01, 4.834847111771459e-01, 7.587927790172442e-01, 1.025672181668925e+00, 1.191094759828622e+00, 1.164961742792316e+00, 9.018798069579228e-01, 4.315022055832897e-01} - }, - { // a = 1 - { 6.530701729038797e-02, 1.451843122217735e-01, 2.097838140076677e-01, 2.528521022973164e-01, 2.713266384167318e-01, 2.655694025043416e-01, 2.391422360901269e-01, 1.980778180928126e-01, 1.497723858359430e-01, 1.016938616285951e-01, 6.012921497571456e-02, 2.918593653285032e-02, 1.021640527075066e-02, 1.758854834988620e-03}, - { 3.047858953593590e-03, 1.711338650097897e-02, 4.631282209740326e-02, 8.847140045241639e-02, 1.355587811983995e-01, 1.762776180037205e-01, 1.998847994601545e-01, 1.998847994601549e-01, 1.762776180037204e-01, 1.355587811983991e-01, 8.847140045241658e-02, 4.631282209740335e-02, 1.711338650097906e-02, 3.047858953593541e-03}, - { 3.403087202360611e-04, 3.471711700989961e-03, 1.479157271769134e-02, 4.032641683989160e-02, 8.227667090507361e-02, 1.352669120293372e-01, 1.861827100865889e-01, 2.186012826669045e-01, 2.200726823124868e-01, 1.885218718051658e-01, 1.340953938539698e-01, 7.499376231263508e-02, 2.905988249720480e-02, 5.332154885158092e-03}, - { 6.326269590322779e-05, 1.012767430464015e-03, 6.163825551175200e-03, 2.243366363111491e-02, 5.808025257876499e-02, 1.164450220527087e-01, 1.892321595216501e-01, 2.552838807732780e-01, 2.884332111068226e-01, 2.715893798478555e-01, 2.083823653344777e-01, 1.235445432558051e-01, 4.992893560070189e-02, 9.406730619278396e-03}, - { 1.671115988738263e-05, 3.852214816032570e-04, 3.144749464370408e-03, 1.458586244466036e-02, 4.625785213424146e-02, 1.100417700576028e-01, 2.066164379880107e-01, 3.147928014648291e-01, 3.937137487359457e-01, 4.030686596785491e-01, 3.307677342029942e-01, 2.065581792297196e-01, 8.666585276148885e-02, 1.671775252943195e-02} - }, - { // a = 2 - { 1.220416489555879e-01, 2.651167637596821e-01, 3.673181769173702e-01, 4.162069232856134e-01, 4.111193923157733e-01, 3.620274580356865e-01, 2.859120823401174e-01, 2.017294682947131e-01, 1.255546582805833e-01, 6.730381389709168e-02, 2.979900540226315e-02, 1.009427116125995e-02, 2.232794727575034e-03, 2.102092933512020e-04}, - { 5.332154885158092e-03, 2.905988249720480e-02, 7.499376231263508e-02, 1.340953938539698e-01, 1.885218718051658e-01, 2.200726823124868e-01, 2.186012826669045e-01, 1.861827100865889e-01, 1.352669120293372e-01, 8.227667090507361e-02, 4.032641683989160e-02, 1.479157271769134e-02, 3.471711700989961e-03, 3.403087202360611e-04}, - { 5.586064709005593e-04, 5.499532798090235e-03, 2.224031959950351e-02, 5.654832171301194e-02, 1.055748101407930e-01, 1.555387412347390e-01, 1.873730013762955e-01, 1.873730013762958e-01, 1.555387412347388e-01, 1.055748101407924e-01, 5.654832171301170e-02, 2.224031959950363e-02, 5.499532798090282e-03, 5.586064709005656e-04}, - { 9.765465540376725e-05, 1.501166549005689e-03, 8.637420163295084e-03, 2.922785972294529e-02, 6.908814810661304e-02, 1.239465762335072e-01, 1.761757163790470e-01, 2.024489568015474e-01, 1.887763460334439e-01, 1.410830888081298e-01, 8.171734482851201e-02, 3.418487199480662e-02, 8.853374574732106e-03, 9.281418156773890e-04}, - { 2.431288690188338e-05, 5.358029984208312e-04, 4.120999400580611e-03, 1.772433215611306e-02, 5.122531495852684e-02, 1.089154125117942e-01, 1.787849820162886e-01, 2.320748308491345e-01, 2.397668405212407e-01, 1.951394580846807e-01, 1.211678827619336e-01, 5.355397527023554e-02, 1.445467930873957e-02, 1.558795323029924e-03} - }, - { // a = 3 - { 2.290461540757796e-01, 4.875112074531002e-01, 6.508470638921978e-01, 6.984046665688880e-01, 6.414563472313936e-01, 5.149516227368192e-01, 3.627915647760550e-01, 2.228449471866996e-01, 1.174031767230196e-01, 5.153000016154856e-02, 1.793630081767578e-02, 4.535933794294162e-03, 6.992940782808716e-04, 4.172050424740590e-05}, - { 9.406730619278396e-03, 4.992893560070189e-02, 1.235445432558051e-01, 2.083823653344777e-01, 2.715893798478555e-01, 2.884332111068226e-01, 2.552838807732780e-01, 1.892321595216501e-01, 1.164450220527087e-01, 5.808025257876499e-02, 2.243366363111491e-02, 6.163825551175200e-03, 1.012767430464015e-03, 6.326269590322779e-05}, - { 9.281418156773890e-04, 8.853374574732106e-03, 3.418487199480662e-02, 8.171734482851201e-02, 1.410830888081298e-01, 1.887763460334439e-01, 2.024489568015474e-01, 1.761757163790470e-01, 1.239465762335072e-01, 6.908814810661304e-02, 2.922785972294529e-02, 8.637420163295084e-03, 1.501166549005689e-03, 9.765465540376725e-05}, - { 1.531264199821700e-04, 2.270365489800732e-03, 1.242758279499570e-02, 3.942481542267345e-02, 8.599763370516886e-02, 1.399301754013571e-01, 1.769391579088787e-01, 1.769391579088797e-01, 1.399301754013570e-01, 8.599763370516889e-02, 3.942481542267379e-02, 1.242758279499558e-02, 2.270365489800726e-03, 1.531264199821710e-04}, - { 3.605040848512942e-05, 7.632313931747922e-04, 5.567043435815090e-03, 2.239273767352773e-02, 5.961631094357124e-02, 1.148344200669121e-01, 1.676068890453595e-01, 1.893484779985816e-01, 1.660298118878007e-01, 1.112668769094685e-01, 5.479020397259165e-02, 1.829532943164775e-02, 3.494862251538960e-03, 2.434688672395410e-04} - }, - { // a = 4 - { 4.315022055832897e-01, 9.018798069579228e-01, 1.164961742792316e+00, 1.191094759828622e+00, 1.025672181668925e+00, 7.587927790172442e-01, 4.834847111771459e-01, 2.630633931261068e-01, 1.199026280873384e-01, 4.430069886476670e-02, 1.256281166489784e-02, 2.485900952118036e-03, 2.846438887262163e-04, 1.173639058512370e-05}, - { 1.671775252943195e-02, 8.666585276148885e-02, 2.065581792297196e-01, 3.307677342029942e-01, 4.030686596785491e-01, 3.937137487359457e-01, 3.147928014648291e-01, 2.066164379880107e-01, 1.100417700576028e-01, 4.625785213424146e-02, 1.458586244466036e-02, 3.144749464370408e-03, 3.852214816032570e-04, 1.671115988738263e-05}, - { 1.558795323029924e-03, 1.445467930873957e-02, 5.355397527023554e-02, 1.211678827619336e-01, 1.951394580846807e-01, 2.397668405212407e-01, 2.320748308491345e-01, 1.787849820162886e-01, 1.089154125117942e-01, 5.122531495852684e-02, 1.772433215611306e-02, 4.120999400580611e-03, 5.358029984208312e-04, 2.431288690188338e-05}, - { 2.434688672395410e-04, 3.494862251538960e-03, 1.829532943164775e-02, 5.479020397259165e-02, 1.112668769094685e-01, 1.660298118878007e-01, 1.893484779985816e-01, 1.676068890453595e-01, 1.148344200669121e-01, 5.961631094357124e-02, 2.239273767352773e-02, 5.567043435815090e-03, 7.632313931747922e-04, 3.605040848512942e-05}, - { 5.436270385637171e-05, 1.110219627694651e-03, 7.722246645059216e-03, 2.925690394797785e-02, 7.239536173538437e-02, 1.277429033427264e-01, 1.680672083465083e-01, 1.680672083465078e-01, 1.277429033427264e-01, 7.239536173538448e-02, 2.925690394797775e-02, 7.722246645059281e-03, 1.110219627694634e-03, 5.436270385637183e-05} - } -}; + {// a = 0 + {3.511946033175177e-02, 8.015808715976037e-02, 1.215185706879029e-01, + 1.572031671581935e-01, 1.855383974779378e-01, 2.051984637212956e-01, + 2.152638534631587e-01, 2.152638534631577e-01, 2.051984637212954e-01, + 1.855383974779379e-01, 1.572031671581937e-01, 1.215185706879025e-01, + 8.015808715976024e-02, 3.511946033175173e-02}, + {1.758854834988620e-03, 1.021640527075066e-02, 2.918593653285032e-02, + 6.012921497571456e-02, 1.016938616285951e-01, 1.497723858359430e-01, + 1.980778180928126e-01, 2.391422360901269e-01, 2.655694025043416e-01, + 2.713266384167318e-01, 2.528521022973164e-01, 2.097838140076677e-01, + 1.451843122217735e-01, 6.530701729038797e-02}, + {2.102092933512020e-04, 2.232794727575034e-03, 1.009427116125995e-02, + 2.979900540226315e-02, 6.730381389709168e-02, 1.255546582805833e-01, + 2.017294682947131e-01, 2.859120823401174e-01, 3.620274580356865e-01, + 4.111193923157733e-01, 4.162069232856134e-01, 3.673181769173702e-01, + 2.651167637596821e-01, 1.220416489555879e-01}, + {4.172050424740590e-05, 6.992940782808716e-04, 4.535933794294162e-03, + 1.793630081767578e-02, 5.153000016154856e-02, 1.174031767230196e-01, + 2.228449471866996e-01, 3.627915647760550e-01, 5.149516227368192e-01, + 6.414563472313936e-01, 6.984046665688880e-01, 6.508470638921978e-01, + 4.875112074531002e-01, 2.290461540757796e-01}, + {1.173639058512370e-05, 2.846438887262163e-04, 2.485900952118036e-03, + 1.256281166489784e-02, 4.430069886476670e-02, 1.199026280873384e-01, + 2.630633931261068e-01, 4.834847111771459e-01, 7.587927790172442e-01, + 1.025672181668925e+00, 1.191094759828622e+00, 1.164961742792316e+00, + 9.018798069579228e-01, 4.315022055832897e-01}}, + {// a = 1 + {6.530701729038797e-02, 1.451843122217735e-01, 2.097838140076677e-01, + 2.528521022973164e-01, 2.713266384167318e-01, 2.655694025043416e-01, + 2.391422360901269e-01, 1.980778180928126e-01, 1.497723858359430e-01, + 1.016938616285951e-01, 6.012921497571456e-02, 2.918593653285032e-02, + 1.021640527075066e-02, 1.758854834988620e-03}, + {3.047858953593590e-03, 1.711338650097897e-02, 4.631282209740326e-02, + 8.847140045241639e-02, 1.355587811983995e-01, 1.762776180037205e-01, + 1.998847994601545e-01, 1.998847994601549e-01, 1.762776180037204e-01, + 1.355587811983991e-01, 8.847140045241658e-02, 4.631282209740335e-02, + 1.711338650097906e-02, 3.047858953593541e-03}, + {3.403087202360611e-04, 3.471711700989961e-03, 1.479157271769134e-02, + 4.032641683989160e-02, 8.227667090507361e-02, 1.352669120293372e-01, + 1.861827100865889e-01, 2.186012826669045e-01, 2.200726823124868e-01, + 1.885218718051658e-01, 1.340953938539698e-01, 7.499376231263508e-02, + 2.905988249720480e-02, 5.332154885158092e-03}, + {6.326269590322779e-05, 1.012767430464015e-03, 6.163825551175200e-03, + 2.243366363111491e-02, 5.808025257876499e-02, 1.164450220527087e-01, + 1.892321595216501e-01, 2.552838807732780e-01, 2.884332111068226e-01, + 2.715893798478555e-01, 2.083823653344777e-01, 1.235445432558051e-01, + 4.992893560070189e-02, 9.406730619278396e-03}, + {1.671115988738263e-05, 3.852214816032570e-04, 3.144749464370408e-03, + 1.458586244466036e-02, 4.625785213424146e-02, 1.100417700576028e-01, + 2.066164379880107e-01, 3.147928014648291e-01, 3.937137487359457e-01, + 4.030686596785491e-01, 3.307677342029942e-01, 2.065581792297196e-01, + 8.666585276148885e-02, 1.671775252943195e-02}}, + {// a = 2 + {1.220416489555879e-01, 2.651167637596821e-01, 3.673181769173702e-01, + 4.162069232856134e-01, 4.111193923157733e-01, 3.620274580356865e-01, + 2.859120823401174e-01, 2.017294682947131e-01, 1.255546582805833e-01, + 6.730381389709168e-02, 2.979900540226315e-02, 1.009427116125995e-02, + 2.232794727575034e-03, 2.102092933512020e-04}, + {5.332154885158092e-03, 2.905988249720480e-02, 7.499376231263508e-02, + 1.340953938539698e-01, 1.885218718051658e-01, 2.200726823124868e-01, + 2.186012826669045e-01, 1.861827100865889e-01, 1.352669120293372e-01, + 8.227667090507361e-02, 4.032641683989160e-02, 1.479157271769134e-02, + 3.471711700989961e-03, 3.403087202360611e-04}, + {5.586064709005593e-04, 5.499532798090235e-03, 2.224031959950351e-02, + 5.654832171301194e-02, 1.055748101407930e-01, 1.555387412347390e-01, + 1.873730013762955e-01, 1.873730013762958e-01, 1.555387412347388e-01, + 1.055748101407924e-01, 5.654832171301170e-02, 2.224031959950363e-02, + 5.499532798090282e-03, 5.586064709005656e-04}, + {9.765465540376725e-05, 1.501166549005689e-03, 8.637420163295084e-03, + 2.922785972294529e-02, 6.908814810661304e-02, 1.239465762335072e-01, + 1.761757163790470e-01, 2.024489568015474e-01, 1.887763460334439e-01, + 1.410830888081298e-01, 8.171734482851201e-02, 3.418487199480662e-02, + 8.853374574732106e-03, 9.281418156773890e-04}, + {2.431288690188338e-05, 5.358029984208312e-04, 4.120999400580611e-03, + 1.772433215611306e-02, 5.122531495852684e-02, 1.089154125117942e-01, + 1.787849820162886e-01, 2.320748308491345e-01, 2.397668405212407e-01, + 1.951394580846807e-01, 1.211678827619336e-01, 5.355397527023554e-02, + 1.445467930873957e-02, 1.558795323029924e-03}}, + {// a = 3 + {2.290461540757796e-01, 4.875112074531002e-01, 6.508470638921978e-01, + 6.984046665688880e-01, 6.414563472313936e-01, 5.149516227368192e-01, + 3.627915647760550e-01, 2.228449471866996e-01, 1.174031767230196e-01, + 5.153000016154856e-02, 1.793630081767578e-02, 4.535933794294162e-03, + 6.992940782808716e-04, 4.172050424740590e-05}, + {9.406730619278396e-03, 4.992893560070189e-02, 1.235445432558051e-01, + 2.083823653344777e-01, 2.715893798478555e-01, 2.884332111068226e-01, + 2.552838807732780e-01, 1.892321595216501e-01, 1.164450220527087e-01, + 5.808025257876499e-02, 2.243366363111491e-02, 6.163825551175200e-03, + 1.012767430464015e-03, 6.326269590322779e-05}, + {9.281418156773890e-04, 8.853374574732106e-03, 3.418487199480662e-02, + 8.171734482851201e-02, 1.410830888081298e-01, 1.887763460334439e-01, + 2.024489568015474e-01, 1.761757163790470e-01, 1.239465762335072e-01, + 6.908814810661304e-02, 2.922785972294529e-02, 8.637420163295084e-03, + 1.501166549005689e-03, 9.765465540376725e-05}, + {1.531264199821700e-04, 2.270365489800732e-03, 1.242758279499570e-02, + 3.942481542267345e-02, 8.599763370516886e-02, 1.399301754013571e-01, + 1.769391579088787e-01, 1.769391579088797e-01, 1.399301754013570e-01, + 8.599763370516889e-02, 3.942481542267379e-02, 1.242758279499558e-02, + 2.270365489800726e-03, 1.531264199821710e-04}, + {3.605040848512942e-05, 7.632313931747922e-04, 5.567043435815090e-03, + 2.239273767352773e-02, 5.961631094357124e-02, 1.148344200669121e-01, + 1.676068890453595e-01, 1.893484779985816e-01, 1.660298118878007e-01, + 1.112668769094685e-01, 5.479020397259165e-02, 1.829532943164775e-02, + 3.494862251538960e-03, 2.434688672395410e-04}}, + {// a = 4 + {4.315022055832897e-01, 9.018798069579228e-01, 1.164961742792316e+00, + 1.191094759828622e+00, 1.025672181668925e+00, 7.587927790172442e-01, + 4.834847111771459e-01, 2.630633931261068e-01, 1.199026280873384e-01, + 4.430069886476670e-02, 1.256281166489784e-02, 2.485900952118036e-03, + 2.846438887262163e-04, 1.173639058512370e-05}, + {1.671775252943195e-02, 8.666585276148885e-02, 2.065581792297196e-01, + 3.307677342029942e-01, 4.030686596785491e-01, 3.937137487359457e-01, + 3.147928014648291e-01, 2.066164379880107e-01, 1.100417700576028e-01, + 4.625785213424146e-02, 1.458586244466036e-02, 3.144749464370408e-03, + 3.852214816032570e-04, 1.671115988738263e-05}, + {1.558795323029924e-03, 1.445467930873957e-02, 5.355397527023554e-02, + 1.211678827619336e-01, 1.951394580846807e-01, 2.397668405212407e-01, + 2.320748308491345e-01, 1.787849820162886e-01, 1.089154125117942e-01, + 5.122531495852684e-02, 1.772433215611306e-02, 4.120999400580611e-03, + 5.358029984208312e-04, 2.431288690188338e-05}, + {2.434688672395410e-04, 3.494862251538960e-03, 1.829532943164775e-02, + 5.479020397259165e-02, 1.112668769094685e-01, 1.660298118878007e-01, + 1.893484779985816e-01, 1.676068890453595e-01, 1.148344200669121e-01, + 5.961631094357124e-02, 2.239273767352773e-02, 5.567043435815090e-03, + 7.632313931747922e-04, 3.605040848512942e-05}, + {5.436270385637171e-05, 1.110219627694651e-03, 7.722246645059216e-03, + 2.925690394797785e-02, 7.239536173538437e-02, 1.277429033427264e-01, + 1.680672083465083e-01, 1.680672083465078e-01, 1.277429033427264e-01, + 7.239536173538448e-02, 2.925690394797775e-02, 7.722246645059281e-03, + 1.110219627694634e-03, 5.436270385637183e-05}}}; static double _gaussJacobiWt_15[5][5][15] = { - { // a = 0 - { 3.075324199611757e-02, 7.036604748810713e-02, 1.071592204671720e-01, 1.395706779261547e-01, 1.662692058169941e-01, 1.861610000155624e-01, 1.984314853271120e-01, 2.025782419255613e-01, 1.984314853271113e-01, 1.861610000155633e-01, 1.662692058169939e-01, 1.395706779261541e-01, 1.071592204671720e-01, 7.036604748810849e-02, 3.075324199611724e-02}, - { 1.361369536551531e-03, 7.944938772580104e-03, 2.286888957888458e-02, 4.761676142039013e-02, 8.166523709047938e-02, 1.224390783458742e-01, 1.656029407376909e-01, 2.056494492475466e-01, 2.366967682388525e-01, 2.533758206460455e-01, 2.516724265943871e-01, 2.295953020277652e-01, 1.875665597762403e-01, 1.284761794998632e-01, 5.746827848685050e-02}, - { 1.450302845560770e-04, 1.551898104511576e-03, 7.092589081872773e-03, 2.124530388619431e-02, 4.888840088164845e-02, 9.334865987821336e-02, 1.543473326821964e-01, 2.266124253939308e-01, 2.997910063368096e-01, 3.599324465649280e-01, 3.923301431552733e-01, 3.850564613482390e-01, 3.322504612128357e-01, 2.362212060543858e-01, 1.078533018010732e-01}, - { 2.585340731604618e-05, 4.378607855880670e-04, 2.881246161389350e-03, 1.160763344018081e-02, 3.413515901499558e-02, 8.002648876667806e-02, 1.572570008624858e-01, 2.669941215119746e-01, 3.989282001105054e-01, 5.297859784496826e-01, 6.268514151355382e-01, 6.563833721915975e-01, 5.945480330054383e-01, 4.369558233071931e-01, 2.031818138494339e-01}, - { 6.577338630276249e-06, 1.617066548368291e-04, 1.437883338565402e-03, 7.433658353540824e-03, 2.695601717582732e-02, 7.546056362045914e-02, 1.723819441472571e-01, 3.325139160240520e-01, 5.532046948703171e-01, 8.034274289207013e-01, 1.022649648177834e+00, 1.134525842127504e+00, 1.073247356970688e+00, 8.125339613230375e-01, 3.840588009567493e-01} - }, - { // a = 1 - { 5.746827848685050e-02, 1.284761794998632e-01, 1.875665597762403e-01, 2.295953020277652e-01, 2.516724265943871e-01, 2.533758206460455e-01, 2.366967682388525e-01, 2.056494492475466e-01, 1.656029407376909e-01, 1.224390783458742e-01, 8.166523709047938e-02, 4.761676142039013e-02, 2.286888957888458e-02, 7.944938772580104e-03, 1.361369536551531e-03}, - { 2.381481280370131e-03, 1.348727800770647e-02, 3.700876967991389e-02, 7.209569246318243e-02, 1.133832831987529e-01, 1.524867201520407e-01, 1.804925045079649e-01, 1.906618747534698e-01, 1.804925045079654e-01, 1.524867201520411e-01, 1.133832831987531e-01, 7.209569246318165e-02, 3.700876967991393e-02, 1.348727800770642e-02, 2.381481280370122e-03}, - { 2.380200274799758e-04, 2.457162376870999e-03, 1.065426402280023e-02, 2.974543346782881e-02, 6.258586116251916e-02, 1.069828834870801e-01, 1.546300069238103e-01, 1.930634339116912e-01, 2.101876288400313e-01, 1.994430325754368e-01, 1.631096937049873e-01, 1.119321794891277e-01, 6.093558148320583e-02, 2.316717283056530e-02, 4.200979029897066e-03}, - { 3.989594298513038e-05, 6.485419257040981e-04, 4.032210580019437e-03, 1.509172541568208e-02, 4.048174155984200e-02, 8.482337899782486e-02, 1.455790387958571e-01, 2.101625149179988e-01, 2.585749167505400e-01, 2.717641484363737e-01, 2.417730354393612e-01, 1.775271423023882e-01, 1.018320141434618e-01, 4.020416618244093e-02, 7.465528609521850e-03}, - { 9.564800569512470e-06, 2.246902673979137e-04, 1.881010905989381e-03, 9.009424597422900e-03, 2.973883046602749e-02, 7.430647278784271e-02, 1.481537120735755e-01, 2.429913106097891e-01, 3.331096745621285e-01, 3.833708678793872e-01, 3.676337515813533e-01, 2.867694424478702e-01, 1.723802709343906e-01, 7.039997426456655e-02, 1.335433515502442e-02} - }, - { // a = 2 - { 1.078533018010732e-01, 2.362212060543858e-01, 3.322504612128357e-01, 3.850564613482390e-01, 3.923301431552733e-01, 3.599324465649280e-01, 2.997910063368096e-01, 2.266124253939308e-01, 1.543473326821964e-01, 9.334865987821336e-02, 4.888840088164845e-02, 2.124530388619431e-02, 7.092589081872773e-03, 1.551898104511576e-03, 1.450302845560770e-04}, - { 4.200979029897066e-03, 2.316717283056530e-02, 6.093558148320583e-02, 1.119321794891277e-01, 1.631096937049873e-01, 1.994430325754368e-01, 2.101876288400313e-01, 1.930634339116912e-01, 1.546300069238103e-01, 1.069828834870801e-01, 6.258586116251916e-02, 2.974543346782881e-02, 1.065426402280023e-02, 2.457162376870999e-03, 2.380200274799758e-04}, - { 3.954143471301420e-04, 3.953934556033900e-03, 1.636277008696444e-02, 4.292661168253369e-02, 8.346688866640495e-02, 1.294773718313208e-01, 1.664368225428811e-01, 1.806270392401284e-01, 1.664368225428809e-01, 1.294773718313211e-01, 8.346688866640509e-02, 4.292661168253403e-02, 1.636277008696448e-02, 3.953934556033856e-03, 3.954143471301450e-04}, - { 6.254119566947010e-05, 9.802192572269726e-04, 5.794837658762271e-03, 2.031983282938327e-02, 5.025691543102584e-02, 9.541526248281391e-02, 1.455101306538528e-01, 1.825492550181576e-01, 1.901778202656092e-01, 1.640494903571746e-01, 1.152440650674971e-01, 6.357424247420110e-02, 2.561505601453008e-02, 6.453002679244033e-03, 6.639952815188880e-04}, - { 1.417643908543084e-05, 3.197754911068428e-04, 2.537171515594708e-03, 1.135605645149475e-02, 3.449686520396603e-02, 7.799847056736668e-02, 1.380901162628800e-01, 1.968003942591436e-01, 2.285497484981823e-01, 2.161163747057937e-01, 1.639222449468583e-01, 9.628397038686043e-02, 4.077303017837298e-02, 1.066347790600116e-02, 1.125746234911803e-03} - }, - { // a = 3 - { 2.031818138494339e-01, 4.369558233071931e-01, 5.945480330054383e-01, 6.563833721915975e-01, 6.268514151355382e-01, 5.297859784496826e-01, 3.989282001105054e-01, 2.669941215119746e-01, 1.572570008624858e-01, 8.002648876667806e-02, 3.413515901499558e-02, 1.160763344018081e-02, 2.881246161389350e-03, 4.378607855880670e-04, 2.585340731604618e-05}, - { 7.465528609521850e-03, 4.020416618244093e-02, 1.018320141434618e-01, 1.775271423023882e-01, 2.417730354393612e-01, 2.717641484363737e-01, 2.585749167505400e-01, 2.101625149179988e-01, 1.455790387958571e-01, 8.482337899782486e-02, 4.048174155984200e-02, 1.509172541568208e-02, 4.032210580019437e-03, 6.485419257040981e-04, 3.989594298513038e-05}, - { 6.639952815188880e-04, 6.453002679244033e-03, 2.561505601453008e-02, 6.357424247420110e-02, 1.152440650674971e-01, 1.640494903571746e-01, 1.901778202656092e-01, 1.825492550181576e-01, 1.455101306538528e-01, 9.541526248281391e-02, 5.025691543102584e-02, 2.031983282938327e-02, 5.794837658762271e-03, 9.802192572269726e-04, 6.254119566947010e-05}, - { 9.941503643760824e-05, 1.508014690540833e-03, 8.522080665722536e-03, 2.819376328954274e-02, 6.487375121104519e-02, 1.128561049466510e-01, 1.550768514742840e-01, 1.720257516572654e-01, 1.550768514742839e-01, 1.128561049466507e-01, 6.487375121104572e-02, 2.819376328954276e-02, 8.522080665722524e-03, 1.508014690540854e-03, 9.941503643760746e-05}, - { 2.136948535903032e-05, 4.647808599472939e-04, 3.514606934469031e-03, 1.480659425046614e-02, 4.177052276856309e-02, 8.643147469595718e-02, 1.377808822227968e-01, 1.735940203750788e-01, 1.745073063296745e-01, 1.393357798854470e-01, 8.660128569035903e-02, 4.015238063907264e-02, 1.278810166895641e-02, 2.356603322559922e-03, 1.600051570066408e-04} - }, - { // a = 4 - { 3.840588009567493e-01, 8.125339613230375e-01, 1.073247356970688e+00, 1.134525842127504e+00, 1.022649648177834e+00, 8.034274289207013e-01, 5.532046948703171e-01, 3.325139160240520e-01, 1.723819441472571e-01, 7.546056362045914e-02, 2.695601717582732e-02, 7.433658353540824e-03, 1.437883338565402e-03, 1.617066548368291e-04, 6.577338630276249e-06}, - { 1.335433515502442e-02, 7.039997426456655e-02, 1.723802709343906e-01, 2.867694424478702e-01, 3.676337515813533e-01, 3.833708678793872e-01, 3.331096745621285e-01, 2.429913106097891e-01, 1.481537120735755e-01, 7.430647278784271e-02, 2.973883046602749e-02, 9.009424597422900e-03, 1.881010905989381e-03, 2.246902673979137e-04, 9.564800569512470e-06}, - { 1.125746234911803e-03, 1.066347790600116e-02, 4.077303017837298e-02, 9.628397038686043e-02, 1.639222449468583e-01, 2.161163747057937e-01, 2.285497484981823e-01, 1.968003942591436e-01, 1.380901162628800e-01, 7.799847056736668e-02, 3.449686520396603e-02, 1.135605645149475e-02, 2.537171515594708e-03, 3.197754911068428e-04, 1.417643908543084e-05}, - { 1.600051570066408e-04, 2.356603322559922e-03, 1.278810166895641e-02, 4.015238063907264e-02, 8.660128569035903e-02, 1.393357798854470e-01, 1.745073063296745e-01, 1.735940203750788e-01, 1.377808822227968e-01, 8.643147469595718e-02, 4.177052276856309e-02, 1.480659425046614e-02, 3.514606934469031e-03, 4.647808599472939e-04, 2.136948535903032e-05}, - { 3.270206634932764e-05, 6.882489120970992e-04, 4.983774075775140e-03, 1.988294796912480e-02, 5.248831687315733e-02, 1.003300875956463e-01, 1.456699432818424e-01, 1.645463711504280e-01, 1.456699432818425e-01, 1.003300875956463e-01, 5.248831687315735e-02, 1.988294796912477e-02, 4.983774075775164e-03, 6.882489120970967e-04, 3.270206634932829e-05} - } -}; + {// a = 0 + {3.075324199611757e-02, 7.036604748810713e-02, 1.071592204671720e-01, + 1.395706779261547e-01, 1.662692058169941e-01, 1.861610000155624e-01, + 1.984314853271120e-01, 2.025782419255613e-01, 1.984314853271113e-01, + 1.861610000155633e-01, 1.662692058169939e-01, 1.395706779261541e-01, + 1.071592204671720e-01, 7.036604748810849e-02, 3.075324199611724e-02}, + {1.361369536551531e-03, 7.944938772580104e-03, 2.286888957888458e-02, + 4.761676142039013e-02, 8.166523709047938e-02, 1.224390783458742e-01, + 1.656029407376909e-01, 2.056494492475466e-01, 2.366967682388525e-01, + 2.533758206460455e-01, 2.516724265943871e-01, 2.295953020277652e-01, + 1.875665597762403e-01, 1.284761794998632e-01, 5.746827848685050e-02}, + {1.450302845560770e-04, 1.551898104511576e-03, 7.092589081872773e-03, + 2.124530388619431e-02, 4.888840088164845e-02, 9.334865987821336e-02, + 1.543473326821964e-01, 2.266124253939308e-01, 2.997910063368096e-01, + 3.599324465649280e-01, 3.923301431552733e-01, 3.850564613482390e-01, + 3.322504612128357e-01, 2.362212060543858e-01, 1.078533018010732e-01}, + {2.585340731604618e-05, 4.378607855880670e-04, 2.881246161389350e-03, + 1.160763344018081e-02, 3.413515901499558e-02, 8.002648876667806e-02, + 1.572570008624858e-01, 2.669941215119746e-01, 3.989282001105054e-01, + 5.297859784496826e-01, 6.268514151355382e-01, 6.563833721915975e-01, + 5.945480330054383e-01, 4.369558233071931e-01, 2.031818138494339e-01}, + {6.577338630276249e-06, 1.617066548368291e-04, 1.437883338565402e-03, + 7.433658353540824e-03, 2.695601717582732e-02, 7.546056362045914e-02, + 1.723819441472571e-01, 3.325139160240520e-01, 5.532046948703171e-01, + 8.034274289207013e-01, 1.022649648177834e+00, 1.134525842127504e+00, + 1.073247356970688e+00, 8.125339613230375e-01, 3.840588009567493e-01}}, + {// a = 1 + {5.746827848685050e-02, 1.284761794998632e-01, 1.875665597762403e-01, + 2.295953020277652e-01, 2.516724265943871e-01, 2.533758206460455e-01, + 2.366967682388525e-01, 2.056494492475466e-01, 1.656029407376909e-01, + 1.224390783458742e-01, 8.166523709047938e-02, 4.761676142039013e-02, + 2.286888957888458e-02, 7.944938772580104e-03, 1.361369536551531e-03}, + {2.381481280370131e-03, 1.348727800770647e-02, 3.700876967991389e-02, + 7.209569246318243e-02, 1.133832831987529e-01, 1.524867201520407e-01, + 1.804925045079649e-01, 1.906618747534698e-01, 1.804925045079654e-01, + 1.524867201520411e-01, 1.133832831987531e-01, 7.209569246318165e-02, + 3.700876967991393e-02, 1.348727800770642e-02, 2.381481280370122e-03}, + {2.380200274799758e-04, 2.457162376870999e-03, 1.065426402280023e-02, + 2.974543346782881e-02, 6.258586116251916e-02, 1.069828834870801e-01, + 1.546300069238103e-01, 1.930634339116912e-01, 2.101876288400313e-01, + 1.994430325754368e-01, 1.631096937049873e-01, 1.119321794891277e-01, + 6.093558148320583e-02, 2.316717283056530e-02, 4.200979029897066e-03}, + {3.989594298513038e-05, 6.485419257040981e-04, 4.032210580019437e-03, + 1.509172541568208e-02, 4.048174155984200e-02, 8.482337899782486e-02, + 1.455790387958571e-01, 2.101625149179988e-01, 2.585749167505400e-01, + 2.717641484363737e-01, 2.417730354393612e-01, 1.775271423023882e-01, + 1.018320141434618e-01, 4.020416618244093e-02, 7.465528609521850e-03}, + {9.564800569512470e-06, 2.246902673979137e-04, 1.881010905989381e-03, + 9.009424597422900e-03, 2.973883046602749e-02, 7.430647278784271e-02, + 1.481537120735755e-01, 2.429913106097891e-01, 3.331096745621285e-01, + 3.833708678793872e-01, 3.676337515813533e-01, 2.867694424478702e-01, + 1.723802709343906e-01, 7.039997426456655e-02, 1.335433515502442e-02}}, + {// a = 2 + {1.078533018010732e-01, 2.362212060543858e-01, 3.322504612128357e-01, + 3.850564613482390e-01, 3.923301431552733e-01, 3.599324465649280e-01, + 2.997910063368096e-01, 2.266124253939308e-01, 1.543473326821964e-01, + 9.334865987821336e-02, 4.888840088164845e-02, 2.124530388619431e-02, + 7.092589081872773e-03, 1.551898104511576e-03, 1.450302845560770e-04}, + {4.200979029897066e-03, 2.316717283056530e-02, 6.093558148320583e-02, + 1.119321794891277e-01, 1.631096937049873e-01, 1.994430325754368e-01, + 2.101876288400313e-01, 1.930634339116912e-01, 1.546300069238103e-01, + 1.069828834870801e-01, 6.258586116251916e-02, 2.974543346782881e-02, + 1.065426402280023e-02, 2.457162376870999e-03, 2.380200274799758e-04}, + {3.954143471301420e-04, 3.953934556033900e-03, 1.636277008696444e-02, + 4.292661168253369e-02, 8.346688866640495e-02, 1.294773718313208e-01, + 1.664368225428811e-01, 1.806270392401284e-01, 1.664368225428809e-01, + 1.294773718313211e-01, 8.346688866640509e-02, 4.292661168253403e-02, + 1.636277008696448e-02, 3.953934556033856e-03, 3.954143471301450e-04}, + {6.254119566947010e-05, 9.802192572269726e-04, 5.794837658762271e-03, + 2.031983282938327e-02, 5.025691543102584e-02, 9.541526248281391e-02, + 1.455101306538528e-01, 1.825492550181576e-01, 1.901778202656092e-01, + 1.640494903571746e-01, 1.152440650674971e-01, 6.357424247420110e-02, + 2.561505601453008e-02, 6.453002679244033e-03, 6.639952815188880e-04}, + {1.417643908543084e-05, 3.197754911068428e-04, 2.537171515594708e-03, + 1.135605645149475e-02, 3.449686520396603e-02, 7.799847056736668e-02, + 1.380901162628800e-01, 1.968003942591436e-01, 2.285497484981823e-01, + 2.161163747057937e-01, 1.639222449468583e-01, 9.628397038686043e-02, + 4.077303017837298e-02, 1.066347790600116e-02, 1.125746234911803e-03}}, + {// a = 3 + {2.031818138494339e-01, 4.369558233071931e-01, 5.945480330054383e-01, + 6.563833721915975e-01, 6.268514151355382e-01, 5.297859784496826e-01, + 3.989282001105054e-01, 2.669941215119746e-01, 1.572570008624858e-01, + 8.002648876667806e-02, 3.413515901499558e-02, 1.160763344018081e-02, + 2.881246161389350e-03, 4.378607855880670e-04, 2.585340731604618e-05}, + {7.465528609521850e-03, 4.020416618244093e-02, 1.018320141434618e-01, + 1.775271423023882e-01, 2.417730354393612e-01, 2.717641484363737e-01, + 2.585749167505400e-01, 2.101625149179988e-01, 1.455790387958571e-01, + 8.482337899782486e-02, 4.048174155984200e-02, 1.509172541568208e-02, + 4.032210580019437e-03, 6.485419257040981e-04, 3.989594298513038e-05}, + {6.639952815188880e-04, 6.453002679244033e-03, 2.561505601453008e-02, + 6.357424247420110e-02, 1.152440650674971e-01, 1.640494903571746e-01, + 1.901778202656092e-01, 1.825492550181576e-01, 1.455101306538528e-01, + 9.541526248281391e-02, 5.025691543102584e-02, 2.031983282938327e-02, + 5.794837658762271e-03, 9.802192572269726e-04, 6.254119566947010e-05}, + {9.941503643760824e-05, 1.508014690540833e-03, 8.522080665722536e-03, + 2.819376328954274e-02, 6.487375121104519e-02, 1.128561049466510e-01, + 1.550768514742840e-01, 1.720257516572654e-01, 1.550768514742839e-01, + 1.128561049466507e-01, 6.487375121104572e-02, 2.819376328954276e-02, + 8.522080665722524e-03, 1.508014690540854e-03, 9.941503643760746e-05}, + {2.136948535903032e-05, 4.647808599472939e-04, 3.514606934469031e-03, + 1.480659425046614e-02, 4.177052276856309e-02, 8.643147469595718e-02, + 1.377808822227968e-01, 1.735940203750788e-01, 1.745073063296745e-01, + 1.393357798854470e-01, 8.660128569035903e-02, 4.015238063907264e-02, + 1.278810166895641e-02, 2.356603322559922e-03, 1.600051570066408e-04}}, + {// a = 4 + {3.840588009567493e-01, 8.125339613230375e-01, 1.073247356970688e+00, + 1.134525842127504e+00, 1.022649648177834e+00, 8.034274289207013e-01, + 5.532046948703171e-01, 3.325139160240520e-01, 1.723819441472571e-01, + 7.546056362045914e-02, 2.695601717582732e-02, 7.433658353540824e-03, + 1.437883338565402e-03, 1.617066548368291e-04, 6.577338630276249e-06}, + {1.335433515502442e-02, 7.039997426456655e-02, 1.723802709343906e-01, + 2.867694424478702e-01, 3.676337515813533e-01, 3.833708678793872e-01, + 3.331096745621285e-01, 2.429913106097891e-01, 1.481537120735755e-01, + 7.430647278784271e-02, 2.973883046602749e-02, 9.009424597422900e-03, + 1.881010905989381e-03, 2.246902673979137e-04, 9.564800569512470e-06}, + {1.125746234911803e-03, 1.066347790600116e-02, 4.077303017837298e-02, + 9.628397038686043e-02, 1.639222449468583e-01, 2.161163747057937e-01, + 2.285497484981823e-01, 1.968003942591436e-01, 1.380901162628800e-01, + 7.799847056736668e-02, 3.449686520396603e-02, 1.135605645149475e-02, + 2.537171515594708e-03, 3.197754911068428e-04, 1.417643908543084e-05}, + {1.600051570066408e-04, 2.356603322559922e-03, 1.278810166895641e-02, + 4.015238063907264e-02, 8.660128569035903e-02, 1.393357798854470e-01, + 1.745073063296745e-01, 1.735940203750788e-01, 1.377808822227968e-01, + 8.643147469595718e-02, 4.177052276856309e-02, 1.480659425046614e-02, + 3.514606934469031e-03, 4.647808599472939e-04, 2.136948535903032e-05}, + {3.270206634932764e-05, 6.882489120970992e-04, 4.983774075775140e-03, + 1.988294796912480e-02, 5.248831687315733e-02, 1.003300875956463e-01, + 1.456699432818424e-01, 1.645463711504280e-01, 1.456699432818425e-01, + 1.003300875956463e-01, 5.248831687315735e-02, 1.988294796912477e-02, + 4.983774075775164e-03, 6.882489120970967e-04, 3.270206634932829e-05}}}; static double _gaussJacobiWt_16[5][5][16] = { - { // a = 0 - { 2.715245941175462e-02, 6.225352393864694e-02, 9.515851168249319e-02, 1.246289712555337e-01, 1.495959888165765e-01, 1.691565193950026e-01, 1.826034150449236e-01, 1.894506104550689e-01, 1.894506104550686e-01, 1.826034150449236e-01, 1.691565193950040e-01, 1.495959888165770e-01, 1.246289712555335e-01, 9.515851168249274e-02, 6.225352393864816e-02, 2.715245941175361e-02}, - { 1.069974660222133e-03, 6.268753894383217e-03, 1.815692954455441e-02, 3.813667153866382e-02, 6.615833742254290e-02, 1.006369324258804e-01, 1.385912663171433e-01, 1.759895287569755e-01, 2.082565513752259e-01, 2.308755184370723e-01, 2.400034195524547e-01, 2.330169608394235e-01, 2.089143776158375e-01, 1.685177246297131e-01, 1.144498103605734e-01, 5.095724262933609e-02}, - { 1.022272845575511e-04, 1.100624831804441e-03, 5.075679996550666e-03, 1.538825540853410e-02, 3.595879081183868e-02, 6.998036396489642e-02, 1.184302132620137e-01, 1.788574851962384e-01, 2.448963033427010e-01, 3.067843756094874e-01, 3.529012614071950e-01, 3.720499151789028e-01, 3.559725877803447e-01, 3.014865974553465e-01, 2.116867401387175e-01, 9.599524499753551e-02}, - { 1.645403553813077e-05, 2.810984663741514e-04, 1.871994950950287e-03, 7.659488973341010e-03, 2.296383918512497e-02, 5.511761553637654e-02, 1.114173308007192e-01, 1.956846689333942e-01, 3.045244503288194e-01, 4.249223695602613e-01, 5.347144569888445e-01, 6.066021950419013e-01, 6.150504887913217e-01, 5.441179287945612e-01, 3.936061072588884e-01, 1.814495123535865e-01}, - { 3.802981432515828e-06, 9.457232099215046e-05, 8.537009641983972e-04, 4.498144983852153e-03, 1.669461174469204e-02, 4.805700432818851e-02, 1.134822881869975e-01, 2.276658705643878e-01, 3.968513160501413e-01, 6.095544357011915e-01, 8.311227287328088e-01, 1.006869361724458e+00, 1.075483424598769e+00, 9.894996614284247e-01, 7.352608922220575e-01, 3.440081834674061e-01} - }, - { // a = 1 - { 5.095724262933609e-02, 1.144498103605734e-01, 1.685177246297131e-01, 2.089143776158375e-01, 2.330169608394235e-01, 2.400034195524547e-01, 2.308755184370723e-01, 2.082565513752259e-01, 1.759895287569755e-01, 1.385912663171433e-01, 1.006369324258804e-01, 6.615833742254290e-02, 3.813667153866382e-02, 1.815692954455441e-02, 6.268753894383217e-03, 1.069974660222133e-03}, - { 1.887330784493700e-03, 1.076546289492211e-02, 2.988147148121786e-02, 5.916001477056534e-02, 9.505028234858227e-02, 1.313788705924051e-01, 1.609693251940497e-01, 1.775739086004304e-01, 1.775739086004309e-01, 1.609693251940501e-01, 1.313788705924048e-01, 9.505028234858223e-02, 5.916001477056535e-02, 2.988147148121778e-02, 1.076546289492213e-02, 1.887330784493685e-03}, - { 1.698025124495790e-04, 1.770386723581758e-03, 7.789441259570089e-03, 2.218028006185762e-02, 4.786842078109829e-02, 8.447556533337106e-02, 1.270241564481966e-01, 1.665548894839569e-01, 1.927394176374404e-01, 1.975899514951430e-01, 1.787303523995938e-01, 1.407322447077076e-01, 9.376092262241206e-02, 4.991514620138311e-02, 1.867859293367477e-02, 3.353762731897149e-03}, - { 2.578714087921435e-05, 4.246117309935728e-04, 2.687511917009500e-03, 1.029598800135757e-02, 2.844079742817500e-02, 6.179496814205326e-02, 1.108719264575604e-01, 1.689921177620562e-01, 2.223098386929797e-01, 2.540697217750311e-01, 2.517792026852257e-01, 2.137832852465952e-01, 1.513596728003014e-01, 8.446415338494762e-02, 3.270152672822537e-02, 5.998890106611426e-03}, - { 5.634459894440214e-06, 1.344854147383470e-04, 1.149919705915970e-03, 5.657890726706088e-03, 1.930803511321534e-02, 5.024082428497778e-02, 1.052107231881148e-01, 1.831235224275267e-01, 2.699105354464341e-01, 3.398410737565294e-01, 3.654229722448049e-01, 3.320025624737325e-01, 2.482721380479175e-01, 1.445495991083272e-01, 5.770987347642392e-02, 1.079354345807437e-02} - }, - { // a = 2 - { 9.599524499753551e-02, 2.116867401387175e-01, 3.014865974553465e-01, 3.559725877803447e-01, 3.720499151789028e-01, 3.529012614071950e-01, 3.067843756094874e-01, 2.448963033427010e-01, 1.788574851962384e-01, 1.184302132620137e-01, 6.998036396489642e-02, 3.595879081183868e-02, 1.538825540853410e-02, 5.075679996550666e-03, 1.100624831804441e-03, 1.022272845575511e-04}, - { 3.353762731897149e-03, 1.867859293367477e-02, 4.991514620138311e-02, 9.376092262241206e-02, 1.407322447077076e-01, 1.787303523995938e-01, 1.975899514951430e-01, 1.927394176374404e-01, 1.665548894839569e-01, 1.270241564481966e-01, 8.447556533337106e-02, 4.786842078109829e-02, 2.218028006185762e-02, 7.789441259570089e-03, 1.770386723581758e-03, 1.698025124495790e-04}, - { 2.851028111045836e-04, 2.888362384608862e-03, 1.218595250377919e-02, 3.281371177446366e-02, 6.598717556901483e-02, 1.067925061960959e-01, 1.447084879899489e-01, 1.676720341043171e-01, 1.676720341043172e-01, 1.447084879899489e-01, 1.067925061960961e-01, 6.598717556901471e-02, 3.281371177446393e-02, 1.218595250377930e-02, 2.888362384608850e-03, 2.851028111045832e-04}, - { 4.098202241034733e-05, 6.529039222891601e-04, 3.948680945863501e-03, 1.426493992620472e-02, 3.663551493758229e-02, 7.288010714004602e-02, 1.177127346665102e-01, 1.584742824795390e-01, 1.801679222247757e-01, 1.734582938872888e-01, 1.404128090993128e-01, 9.372756792904854e-02, 4.964938663070913e-02, 1.938572758402635e-02, 4.771501563692155e-03, 4.833117073677417e-04}, - { 8.490486434111524e-06, 1.953281523148330e-04, 1.590969767457516e-03, 7.363343945797644e-03, 2.331781850974260e-02, 5.547609273183583e-02, 1.044924524334554e-01, 1.605871958716448e-01, 2.045897636195508e-01, 2.171469008161425e-01, 1.909546298420537e-01, 1.366218004277177e-01, 7.661011465812488e-02, 3.129618082710216e-02, 7.970138959092005e-03, 8.263979991533265e-04} - }, - { // a = 3 - { 1.814495123535865e-01, 3.936061072588884e-01, 5.441179287945612e-01, 6.150504887913217e-01, 6.066021950419013e-01, 5.347144569888445e-01, 4.249223695602613e-01, 3.045244503288194e-01, 1.956846689333942e-01, 1.114173308007192e-01, 5.511761553637654e-02, 2.296383918512497e-02, 7.659488973341010e-03, 1.871994950950287e-03, 2.810984663741514e-04, 1.645403553813077e-05}, - { 5.998890106611426e-03, 3.270152672822537e-02, 8.446415338494762e-02, 1.513596728003014e-01, 2.137832852465952e-01, 2.517792026852257e-01, 2.540697217750311e-01, 2.223098386929797e-01, 1.689921177620562e-01, 1.108719264575604e-01, 6.179496814205326e-02, 2.844079742817500e-02, 1.029598800135757e-02, 2.687511917009500e-03, 4.246117309935728e-04, 2.578714087921435e-05}, - { 4.833117073677417e-04, 4.771501563692155e-03, 1.938572758402635e-02, 4.964938663070913e-02, 9.372756792904854e-02, 1.404128090993128e-01, 1.734582938872888e-01, 1.801679222247757e-01, 1.584742824795390e-01, 1.177127346665102e-01, 7.288010714004602e-02, 3.663551493758229e-02, 1.426493992620472e-02, 3.948680945863501e-03, 6.529039222891601e-04, 4.098202241034733e-05}, - { 6.594607515502350e-05, 1.019829862953540e-03, 5.920407682087497e-03, 2.028924040958996e-02, 4.881461620470607e-02, 8.975304278241378e-02, 1.320257098490893e-01, 1.592540642768620e-01, 1.592540642768618e-01, 1.320257098490895e-01, 8.975304278241346e-02, 4.881461620470619e-02, 2.028924040959005e-02, 5.920407682087568e-03, 1.019829862953536e-03, 6.594607515502718e-05}, - { 1.298916413480863e-05, 2.890544685478188e-04, 2.253540326638734e-03, 9.871415749385264e-03, 2.923262925357270e-02, 6.419650366769132e-02, 1.100325101279169e-01, 1.514531497430954e-01, 1.697322409592206e-01, 1.552077026664362e-01, 1.147351464277535e-01, 6.698174288785233e-02, 2.952774094946983e-02, 9.036667378732568e-03, 1.615371522285304e-03, 1.073089929796298e-04} - }, - { // a = 4 - { 3.440081834674061e-01, 7.352608922220575e-01, 9.894996614284247e-01, 1.075483424598769e+00, 1.006869361724458e+00, 8.311227287328088e-01, 6.095544357011915e-01, 3.968513160501413e-01, 2.276658705643878e-01, 1.134822881869975e-01, 4.805700432818851e-02, 1.669461174469204e-02, 4.498144983852153e-03, 8.537009641983972e-04, 9.457232099215046e-05, 3.802981432515828e-06}, - { 1.079354345807437e-02, 5.770987347642392e-02, 1.445495991083272e-01, 2.482721380479175e-01, 3.320025624737325e-01, 3.654229722448049e-01, 3.398410737565294e-01, 2.699105354464341e-01, 1.831235224275267e-01, 1.052107231881148e-01, 5.024082428497778e-02, 1.930803511321534e-02, 5.657890726706088e-03, 1.149919705915970e-03, 1.344854147383470e-04, 5.634459894440214e-06}, - { 8.263979991533265e-04, 7.970138959092005e-03, 3.129618082710216e-02, 7.661011465812488e-02, 1.366218004277177e-01, 1.909546298420537e-01, 2.171469008161425e-01, 2.045897636195508e-01, 1.605871958716448e-01, 1.044924524334554e-01, 5.547609273183583e-02, 2.331781850974260e-02, 7.363343945797644e-03, 1.590969767457516e-03, 1.953281523148330e-04, 8.490486434111524e-06}, - { 1.073089929796298e-04, 1.615371522285304e-03, 9.036667378732568e-03, 2.952774094946983e-02, 6.698174288785233e-02, 1.147351464277535e-01, 1.552077026664362e-01, 1.697322409592206e-01, 1.514531497430954e-01, 1.100325101279169e-01, 6.419650366769132e-02, 2.923262925357270e-02, 9.871415749385264e-03, 2.253540326638734e-03, 2.890544685478188e-04, 1.298916413480863e-05}, - { 2.014342068771001e-05, 4.349468538409732e-04, 3.259085486437477e-03, 1.358290074012528e-02, 3.786126061350023e-02, 7.736410216205108e-02, 1.218426931452863e-01, 1.519840739272774e-01, 1.519840739272777e-01, 1.218426931452862e-01, 7.736410216205106e-02, 3.786126061350014e-02, 1.358290074012529e-02, 3.259085486437511e-03, 4.349468538409689e-04, 2.014342068770944e-05} - } -}; + {// a = 0 + {2.715245941175462e-02, 6.225352393864694e-02, 9.515851168249319e-02, + 1.246289712555337e-01, 1.495959888165765e-01, 1.691565193950026e-01, + 1.826034150449236e-01, 1.894506104550689e-01, 1.894506104550686e-01, + 1.826034150449236e-01, 1.691565193950040e-01, 1.495959888165770e-01, + 1.246289712555335e-01, 9.515851168249274e-02, 6.225352393864816e-02, + 2.715245941175361e-02}, + {1.069974660222133e-03, 6.268753894383217e-03, 1.815692954455441e-02, + 3.813667153866382e-02, 6.615833742254290e-02, 1.006369324258804e-01, + 1.385912663171433e-01, 1.759895287569755e-01, 2.082565513752259e-01, + 2.308755184370723e-01, 2.400034195524547e-01, 2.330169608394235e-01, + 2.089143776158375e-01, 1.685177246297131e-01, 1.144498103605734e-01, + 5.095724262933609e-02}, + {1.022272845575511e-04, 1.100624831804441e-03, 5.075679996550666e-03, + 1.538825540853410e-02, 3.595879081183868e-02, 6.998036396489642e-02, + 1.184302132620137e-01, 1.788574851962384e-01, 2.448963033427010e-01, + 3.067843756094874e-01, 3.529012614071950e-01, 3.720499151789028e-01, + 3.559725877803447e-01, 3.014865974553465e-01, 2.116867401387175e-01, + 9.599524499753551e-02}, + {1.645403553813077e-05, 2.810984663741514e-04, 1.871994950950287e-03, + 7.659488973341010e-03, 2.296383918512497e-02, 5.511761553637654e-02, + 1.114173308007192e-01, 1.956846689333942e-01, 3.045244503288194e-01, + 4.249223695602613e-01, 5.347144569888445e-01, 6.066021950419013e-01, + 6.150504887913217e-01, 5.441179287945612e-01, 3.936061072588884e-01, + 1.814495123535865e-01}, + {3.802981432515828e-06, 9.457232099215046e-05, 8.537009641983972e-04, + 4.498144983852153e-03, 1.669461174469204e-02, 4.805700432818851e-02, + 1.134822881869975e-01, 2.276658705643878e-01, 3.968513160501413e-01, + 6.095544357011915e-01, 8.311227287328088e-01, 1.006869361724458e+00, + 1.075483424598769e+00, 9.894996614284247e-01, 7.352608922220575e-01, + 3.440081834674061e-01}}, + {// a = 1 + {5.095724262933609e-02, 1.144498103605734e-01, 1.685177246297131e-01, + 2.089143776158375e-01, 2.330169608394235e-01, 2.400034195524547e-01, + 2.308755184370723e-01, 2.082565513752259e-01, 1.759895287569755e-01, + 1.385912663171433e-01, 1.006369324258804e-01, 6.615833742254290e-02, + 3.813667153866382e-02, 1.815692954455441e-02, 6.268753894383217e-03, + 1.069974660222133e-03}, + {1.887330784493700e-03, 1.076546289492211e-02, 2.988147148121786e-02, + 5.916001477056534e-02, 9.505028234858227e-02, 1.313788705924051e-01, + 1.609693251940497e-01, 1.775739086004304e-01, 1.775739086004309e-01, + 1.609693251940501e-01, 1.313788705924048e-01, 9.505028234858223e-02, + 5.916001477056535e-02, 2.988147148121778e-02, 1.076546289492213e-02, + 1.887330784493685e-03}, + {1.698025124495790e-04, 1.770386723581758e-03, 7.789441259570089e-03, + 2.218028006185762e-02, 4.786842078109829e-02, 8.447556533337106e-02, + 1.270241564481966e-01, 1.665548894839569e-01, 1.927394176374404e-01, + 1.975899514951430e-01, 1.787303523995938e-01, 1.407322447077076e-01, + 9.376092262241206e-02, 4.991514620138311e-02, 1.867859293367477e-02, + 3.353762731897149e-03}, + {2.578714087921435e-05, 4.246117309935728e-04, 2.687511917009500e-03, + 1.029598800135757e-02, 2.844079742817500e-02, 6.179496814205326e-02, + 1.108719264575604e-01, 1.689921177620562e-01, 2.223098386929797e-01, + 2.540697217750311e-01, 2.517792026852257e-01, 2.137832852465952e-01, + 1.513596728003014e-01, 8.446415338494762e-02, 3.270152672822537e-02, + 5.998890106611426e-03}, + {5.634459894440214e-06, 1.344854147383470e-04, 1.149919705915970e-03, + 5.657890726706088e-03, 1.930803511321534e-02, 5.024082428497778e-02, + 1.052107231881148e-01, 1.831235224275267e-01, 2.699105354464341e-01, + 3.398410737565294e-01, 3.654229722448049e-01, 3.320025624737325e-01, + 2.482721380479175e-01, 1.445495991083272e-01, 5.770987347642392e-02, + 1.079354345807437e-02}}, + {// a = 2 + {9.599524499753551e-02, 2.116867401387175e-01, 3.014865974553465e-01, + 3.559725877803447e-01, 3.720499151789028e-01, 3.529012614071950e-01, + 3.067843756094874e-01, 2.448963033427010e-01, 1.788574851962384e-01, + 1.184302132620137e-01, 6.998036396489642e-02, 3.595879081183868e-02, + 1.538825540853410e-02, 5.075679996550666e-03, 1.100624831804441e-03, + 1.022272845575511e-04}, + {3.353762731897149e-03, 1.867859293367477e-02, 4.991514620138311e-02, + 9.376092262241206e-02, 1.407322447077076e-01, 1.787303523995938e-01, + 1.975899514951430e-01, 1.927394176374404e-01, 1.665548894839569e-01, + 1.270241564481966e-01, 8.447556533337106e-02, 4.786842078109829e-02, + 2.218028006185762e-02, 7.789441259570089e-03, 1.770386723581758e-03, + 1.698025124495790e-04}, + {2.851028111045836e-04, 2.888362384608862e-03, 1.218595250377919e-02, + 3.281371177446366e-02, 6.598717556901483e-02, 1.067925061960959e-01, + 1.447084879899489e-01, 1.676720341043171e-01, 1.676720341043172e-01, + 1.447084879899489e-01, 1.067925061960961e-01, 6.598717556901471e-02, + 3.281371177446393e-02, 1.218595250377930e-02, 2.888362384608850e-03, + 2.851028111045832e-04}, + {4.098202241034733e-05, 6.529039222891601e-04, 3.948680945863501e-03, + 1.426493992620472e-02, 3.663551493758229e-02, 7.288010714004602e-02, + 1.177127346665102e-01, 1.584742824795390e-01, 1.801679222247757e-01, + 1.734582938872888e-01, 1.404128090993128e-01, 9.372756792904854e-02, + 4.964938663070913e-02, 1.938572758402635e-02, 4.771501563692155e-03, + 4.833117073677417e-04}, + {8.490486434111524e-06, 1.953281523148330e-04, 1.590969767457516e-03, + 7.363343945797644e-03, 2.331781850974260e-02, 5.547609273183583e-02, + 1.044924524334554e-01, 1.605871958716448e-01, 2.045897636195508e-01, + 2.171469008161425e-01, 1.909546298420537e-01, 1.366218004277177e-01, + 7.661011465812488e-02, 3.129618082710216e-02, 7.970138959092005e-03, + 8.263979991533265e-04}}, + {// a = 3 + {1.814495123535865e-01, 3.936061072588884e-01, 5.441179287945612e-01, + 6.150504887913217e-01, 6.066021950419013e-01, 5.347144569888445e-01, + 4.249223695602613e-01, 3.045244503288194e-01, 1.956846689333942e-01, + 1.114173308007192e-01, 5.511761553637654e-02, 2.296383918512497e-02, + 7.659488973341010e-03, 1.871994950950287e-03, 2.810984663741514e-04, + 1.645403553813077e-05}, + {5.998890106611426e-03, 3.270152672822537e-02, 8.446415338494762e-02, + 1.513596728003014e-01, 2.137832852465952e-01, 2.517792026852257e-01, + 2.540697217750311e-01, 2.223098386929797e-01, 1.689921177620562e-01, + 1.108719264575604e-01, 6.179496814205326e-02, 2.844079742817500e-02, + 1.029598800135757e-02, 2.687511917009500e-03, 4.246117309935728e-04, + 2.578714087921435e-05}, + {4.833117073677417e-04, 4.771501563692155e-03, 1.938572758402635e-02, + 4.964938663070913e-02, 9.372756792904854e-02, 1.404128090993128e-01, + 1.734582938872888e-01, 1.801679222247757e-01, 1.584742824795390e-01, + 1.177127346665102e-01, 7.288010714004602e-02, 3.663551493758229e-02, + 1.426493992620472e-02, 3.948680945863501e-03, 6.529039222891601e-04, + 4.098202241034733e-05}, + {6.594607515502350e-05, 1.019829862953540e-03, 5.920407682087497e-03, + 2.028924040958996e-02, 4.881461620470607e-02, 8.975304278241378e-02, + 1.320257098490893e-01, 1.592540642768620e-01, 1.592540642768618e-01, + 1.320257098490895e-01, 8.975304278241346e-02, 4.881461620470619e-02, + 2.028924040959005e-02, 5.920407682087568e-03, 1.019829862953536e-03, + 6.594607515502718e-05}, + {1.298916413480863e-05, 2.890544685478188e-04, 2.253540326638734e-03, + 9.871415749385264e-03, 2.923262925357270e-02, 6.419650366769132e-02, + 1.100325101279169e-01, 1.514531497430954e-01, 1.697322409592206e-01, + 1.552077026664362e-01, 1.147351464277535e-01, 6.698174288785233e-02, + 2.952774094946983e-02, 9.036667378732568e-03, 1.615371522285304e-03, + 1.073089929796298e-04}}, + {// a = 4 + {3.440081834674061e-01, 7.352608922220575e-01, 9.894996614284247e-01, + 1.075483424598769e+00, 1.006869361724458e+00, 8.311227287328088e-01, + 6.095544357011915e-01, 3.968513160501413e-01, 2.276658705643878e-01, + 1.134822881869975e-01, 4.805700432818851e-02, 1.669461174469204e-02, + 4.498144983852153e-03, 8.537009641983972e-04, 9.457232099215046e-05, + 3.802981432515828e-06}, + {1.079354345807437e-02, 5.770987347642392e-02, 1.445495991083272e-01, + 2.482721380479175e-01, 3.320025624737325e-01, 3.654229722448049e-01, + 3.398410737565294e-01, 2.699105354464341e-01, 1.831235224275267e-01, + 1.052107231881148e-01, 5.024082428497778e-02, 1.930803511321534e-02, + 5.657890726706088e-03, 1.149919705915970e-03, 1.344854147383470e-04, + 5.634459894440214e-06}, + {8.263979991533265e-04, 7.970138959092005e-03, 3.129618082710216e-02, + 7.661011465812488e-02, 1.366218004277177e-01, 1.909546298420537e-01, + 2.171469008161425e-01, 2.045897636195508e-01, 1.605871958716448e-01, + 1.044924524334554e-01, 5.547609273183583e-02, 2.331781850974260e-02, + 7.363343945797644e-03, 1.590969767457516e-03, 1.953281523148330e-04, + 8.490486434111524e-06}, + {1.073089929796298e-04, 1.615371522285304e-03, 9.036667378732568e-03, + 2.952774094946983e-02, 6.698174288785233e-02, 1.147351464277535e-01, + 1.552077026664362e-01, 1.697322409592206e-01, 1.514531497430954e-01, + 1.100325101279169e-01, 6.419650366769132e-02, 2.923262925357270e-02, + 9.871415749385264e-03, 2.253540326638734e-03, 2.890544685478188e-04, + 1.298916413480863e-05}, + {2.014342068771001e-05, 4.349468538409732e-04, 3.259085486437477e-03, + 1.358290074012528e-02, 3.786126061350023e-02, 7.736410216205108e-02, + 1.218426931452863e-01, 1.519840739272774e-01, 1.519840739272777e-01, + 1.218426931452862e-01, 7.736410216205106e-02, 3.786126061350014e-02, + 1.358290074012529e-02, 3.259085486437511e-03, 4.349468538409689e-04, + 2.014342068770944e-05}}}; static double _gaussJacobiWt_17[5][5][17] = { - { // a = 0 - { 2.414830286854748e-02, 5.545952937398731e-02, 8.503614831717922e-02, 1.118838471934042e-01, 1.351363684685254e-01, 1.540457610768101e-01, 1.680041021564505e-01, 1.765627053669921e-01, 1.794464703562071e-01, 1.765627053669920e-01, 1.680041021564513e-01, 1.540457610768113e-01, 1.351363684685263e-01, 1.118838471934041e-01, 8.503614831717887e-02, 5.545952937398716e-02, 2.414830286854753e-02}, - { 8.524651568277072e-04, 5.010733757564868e-03, 1.458892193368564e-02, 3.086568885922368e-02, 5.405478980920327e-02, 8.321311204118144e-02, 1.162980963508203e-01, 1.503693019484489e-01, 1.819111615965693e-01, 2.072389677171849e-01, 2.229396716942430e-01, 2.262944455298862e-01, 2.156317266701110e-01, 1.905674774984742e-01, 1.521029153029695e-01, 1.025697116808203e-01, 4.549081245278783e-02}, - { 7.344643360100710e-05, 7.948522026838238e-04, 3.693392470216972e-03, 1.131107007164897e-02, 2.677213833455836e-02, 5.293135808289402e-02, 9.130913790909347e-02, 1.411103146484007e-01, 1.986340488958086e-01, 2.573085608990289e-01, 3.084419355768195e-01, 3.426032314234782e-01, 3.513809501807375e-01, 3.291518067765479e-01, 2.744631183653730e-01, 1.907020961496262e-01, 8.598520824614991e-02}, - { 1.072518386566368e-05, 1.845748136500827e-04, 1.241661747105944e-03, 5.147047016717799e-03, 1.568299803301124e-02, 3.838770877189669e-02, 7.943907234514626e-02, 1.434568646827850e-01, 2.307394793749237e-01, 3.349054339255650e-01, 4.420417170175802e-01, 5.321478233319703e-01, 5.829612491775451e-01, 5.753857970850771e-01, 4.990411553052296e-01, 3.562103001236256e-01, 1.630163920643000e-01}, - { 2.261469412614750e-06, 5.678553100877205e-05, 5.191816769372674e-04, 2.779782677670493e-03, 1.052067600587753e-02, 3.100088336557466e-02, 7.525531120080720e-02, 1.559524871316514e-01, 2.823982527589936e-01, 4.537122510063411e-01, 6.528527480865959e-01, 8.449175462761370e-01, 9.822496334619499e-01, 1.016352742424321e+00, 9.134366220512035e-01, 6.680980456421279e-01, 3.098947892333867e-01} - }, - { // a = 1 - { 4.549081245278783e-02, 1.025697116808203e-01, 1.521029153029695e-01, 1.905674774984742e-01, 2.156317266701110e-01, 2.262944455298862e-01, 2.229396716942430e-01, 2.072389677171849e-01, 1.819111615965693e-01, 1.503693019484489e-01, 1.162980963508203e-01, 8.321311204118144e-02, 5.405478980920327e-02, 3.086568885922368e-02, 1.458892193368564e-02, 5.010733757564868e-03, 8.524651568277072e-04}, - { 1.514739815459632e-03, 8.692316294131076e-03, 2.436068639363824e-02, 4.888597833155504e-02, 7.995220547465692e-02, 1.130368323567139e-01, 1.424624885130020e-01, 1.627604598450957e-01, 1.700019192848272e-01, 1.627604598450952e-01, 1.424624885130013e-01, 1.130368323567144e-01, 7.995220547465695e-02, 4.888597833155554e-02, 2.436068639363805e-02, 8.692316294131038e-03, 1.514739815459635e-03}, - { 1.233044634533328e-04, 1.296392811140574e-03, 5.774603058213583e-03, 1.671747559098046e-02, 3.685209548354167e-02, 6.677766301568872e-02, 1.037320040118806e-01, 1.415359966428405e-01, 1.719799936538742e-01, 1.872988928665976e-01, 1.828637284314485e-01, 1.590316882031948e-01, 1.213448824926961e-01, 7.887150802970438e-02, 4.120817316457946e-02, 1.521563810625176e-02, 2.709293307248373e-03}, - { 1.704155122351367e-05, 2.836791789418342e-04, 1.822811755104407e-03, 7.121780894954346e-03, 2.016315103614819e-02, 4.515440228850054e-02, 8.404393997951824e-02, 1.339140400477353e-01, 1.859094690043127e-01, 2.269615005870788e-01, 2.442284372718092e-01, 2.305539788374319e-01, 1.882978790989171e-01, 1.293042909913915e-01, 7.050121921816414e-02, 2.684787285389501e-02, 4.874505404873660e-03}, - { 3.406740694092426e-06, 8.242230799538509e-05, 7.175170540563040e-04, 3.611592575391886e-03, 1.267515200344258e-02, 3.412027839486566e-02, 7.442351009396078e-02, 1.360137453605255e-01, 2.125809450270678e-01, 2.874097484686258e-01, 3.374891186887510e-01, 3.430062341880836e-01, 2.978727394079814e-01, 2.149730401934955e-01, 1.218267835691143e-01, 4.771039224384056e-02, 8.816707015440529e-03} - }, - { // a = 2 - { 8.598520824614991e-02, 1.907020961496262e-01, 2.744631183653730e-01, 3.291518067765479e-01, 3.513809501807375e-01, 3.426032314234782e-01, 3.084419355768195e-01, 2.573085608990289e-01, 1.986340488958086e-01, 1.411103146484007e-01, 9.130913790909347e-02, 5.293135808289402e-02, 2.677213833455836e-02, 1.131107007164897e-02, 3.693392470216972e-03, 7.948522026838238e-04, 7.344643360100710e-05}, - { 2.709293307248373e-03, 1.521563810625176e-02, 4.120817316457946e-02, 7.887150802970438e-02, 1.213448824926961e-01, 1.590316882031948e-01, 1.828637284314485e-01, 1.872988928665976e-01, 1.719799936538742e-01, 1.415359966428405e-01, 1.037320040118806e-01, 6.677766301568872e-02, 3.685209548354167e-02, 1.671747559098046e-02, 5.774603058213583e-03, 1.296392811140574e-03, 1.233044634533328e-04}, - { 2.090067034827627e-04, 2.141017957655637e-03, 9.181538456807289e-03, 2.527288528222823e-02, 5.227733398127146e-02, 8.764340394578723e-02, 1.240430597999046e-01, 1.516117923086600e-01, 1.619065897950735e-01, 1.516117923086597e-01, 1.240430597999047e-01, 8.764340394578669e-02, 5.227733398127170e-02, 2.527288528222810e-02, 9.181538456807341e-03, 2.141017957655655e-03, 2.090067034827575e-04}, - { 2.741746351398126e-05, 4.429186278435173e-04, 2.730964161249059e-03, 1.011754357138828e-02, 2.682070082647672e-02, 5.547954007175986e-02, 9.397537178712370e-02, 1.340471353459491e-01, 1.635243116845976e-01, 1.717052876554434e-01, 1.549622335479171e-01, 1.190030993702081e-01, 7.611527386932622e-02, 3.896656778366746e-02, 1.481557358615418e-02, 3.575387040721511e-03, 3.573402733269803e-04}, - { 5.210369255787608e-06, 1.219003512982789e-04, 1.015320713912196e-03, 4.834464715692282e-03, 1.585656557912542e-02, 3.937085511771213e-02, 7.807825098547579e-02, 1.276739708535340e-01, 1.753314519941376e-01, 2.039595721371063e-01, 2.010239069684333e-01, 1.664126212401902e-01, 1.133687094883810e-01, 6.112793638187385e-02, 2.422102922342991e-02, 6.030144692356797e-03, 6.157082357045311e-04} - }, - { // a = 3 - { 1.630163920643000e-01, 3.562103001236256e-01, 4.990411553052296e-01, 5.753857970850771e-01, 5.829612491775451e-01, 5.321478233319703e-01, 4.420417170175802e-01, 3.349054339255650e-01, 2.307394793749237e-01, 1.434568646827850e-01, 7.943907234514626e-02, 3.838770877189669e-02, 1.568299803301124e-02, 5.147047016717799e-03, 1.241661747105944e-03, 1.845748136500827e-04, 1.072518386566368e-05}, - { 4.874505404873660e-03, 2.684787285389501e-02, 7.050121921816414e-02, 1.293042909913915e-01, 1.882978790989171e-01, 2.305539788374319e-01, 2.442284372718092e-01, 2.269615005870788e-01, 1.859094690043127e-01, 1.339140400477353e-01, 8.404393997951824e-02, 4.515440228850054e-02, 2.016315103614819e-02, 7.121780894954346e-03, 1.822811755104407e-03, 2.836791789418342e-04, 1.704155122351367e-05}, - { 3.573402733269803e-04, 3.575387040721511e-03, 1.481557358615418e-02, 3.896656778366746e-02, 7.611527386932622e-02, 1.190030993702081e-01, 1.549622335479171e-01, 1.717052876554434e-01, 1.635243116845976e-01, 1.340471353459491e-01, 9.397537178712370e-02, 5.547954007175986e-02, 2.682070082647672e-02, 1.011754357138828e-02, 2.730964161249059e-03, 4.429186278435173e-04, 2.741746351398126e-05}, - { 4.460712615943976e-05, 7.013003636904480e-04, 4.165617804861459e-03, 1.470898188971299e-02, 3.674689770287290e-02, 7.077651083566822e-02, 1.101810000987092e-01, 1.423843548974512e-01, 1.548671728474618e-01, 1.423843548974516e-01, 1.101810000987091e-01, 7.077651083566813e-02, 3.674689770287288e-02, 1.470898188971304e-02, 4.165617804861450e-03, 7.013003636904514e-04, 4.460712615944224e-05}, - { 8.078156583640950e-06, 1.833288272322261e-04, 1.467044310162418e-03, 6.643131051799167e-03, 2.049793389243312e-02, 4.732591740229600e-02, 8.617597512125302e-02, 1.275969889954371e-01, 1.562112018380642e-01, 1.591517437915593e-01, 1.345868931717605e-01, 9.329342759618311e-02, 5.166702485870460e-02, 2.182338989518186e-02, 6.455906596396846e-03, 1.124418294497242e-03, 7.331048617018153e-05} - }, - { // a = 4 - { 3.098947892333867e-01, 6.680980456421279e-01, 9.134366220512035e-01, 1.016352742424321e+00, 9.822496334619499e-01, 8.449175462761370e-01, 6.528527480865959e-01, 4.537122510063411e-01, 2.823982527589936e-01, 1.559524871316514e-01, 7.525531120080720e-02, 3.100088336557466e-02, 1.052067600587753e-02, 2.779782677670493e-03, 5.191816769372674e-04, 5.678553100877205e-05, 2.261469412614750e-06}, - { 8.816707015440529e-03, 4.771039224384056e-02, 1.218267835691143e-01, 2.149730401934955e-01, 2.978727394079814e-01, 3.430062341880836e-01, 3.374891186887510e-01, 2.874097484686258e-01, 2.125809450270678e-01, 1.360137453605255e-01, 7.442351009396078e-02, 3.412027839486566e-02, 1.267515200344258e-02, 3.611592575391886e-03, 7.175170540563040e-04, 8.242230799538509e-05, 3.406740694092426e-06}, - { 6.157082357045311e-04, 6.030144692356797e-03, 2.422102922342991e-02, 6.112793638187385e-02, 1.133687094883810e-01, 1.664126212401902e-01, 2.010239069684333e-01, 2.039595721371063e-01, 1.753314519941376e-01, 1.276739708535340e-01, 7.807825098547579e-02, 3.937085511771213e-02, 1.585656557912542e-02, 4.834464715692282e-03, 1.015320713912196e-03, 1.219003512982789e-04, 5.210369255787608e-06}, - { 7.331048617018153e-05, 1.124418294497242e-03, 6.455906596396846e-03, 2.182338989518186e-02, 5.166702485870460e-02, 9.329342759618311e-02, 1.345868931717605e-01, 1.591517437915593e-01, 1.562112018380642e-01, 1.275969889954371e-01, 8.617597512125302e-02, 4.732591740229600e-02, 2.049793389243312e-02, 6.643131051799167e-03, 1.467044310162418e-03, 1.833288272322261e-04, 8.078156583640950e-06}, - { 1.267943688429357e-05, 2.798792988735616e-04, 2.159507823450682e-03, 9.342274356001830e-03, 2.727243969963370e-02, 5.895618575762269e-02, 9.939377920866957e-02, 1.345962178012885e-01, 1.486724859335633e-01, 1.345962178012887e-01, 9.939377920866907e-02, 5.895618575762289e-02, 2.727243969963356e-02, 9.342274356001870e-03, 2.159507823450709e-03, 2.798792988735582e-04, 1.267943688429400e-05} - } -}; + {// a = 0 + {2.414830286854748e-02, 5.545952937398731e-02, 8.503614831717922e-02, + 1.118838471934042e-01, 1.351363684685254e-01, 1.540457610768101e-01, + 1.680041021564505e-01, 1.765627053669921e-01, 1.794464703562071e-01, + 1.765627053669920e-01, 1.680041021564513e-01, 1.540457610768113e-01, + 1.351363684685263e-01, 1.118838471934041e-01, 8.503614831717887e-02, + 5.545952937398716e-02, 2.414830286854753e-02}, + {8.524651568277072e-04, 5.010733757564868e-03, 1.458892193368564e-02, + 3.086568885922368e-02, 5.405478980920327e-02, 8.321311204118144e-02, + 1.162980963508203e-01, 1.503693019484489e-01, 1.819111615965693e-01, + 2.072389677171849e-01, 2.229396716942430e-01, 2.262944455298862e-01, + 2.156317266701110e-01, 1.905674774984742e-01, 1.521029153029695e-01, + 1.025697116808203e-01, 4.549081245278783e-02}, + {7.344643360100710e-05, 7.948522026838238e-04, 3.693392470216972e-03, + 1.131107007164897e-02, 2.677213833455836e-02, 5.293135808289402e-02, + 9.130913790909347e-02, 1.411103146484007e-01, 1.986340488958086e-01, + 2.573085608990289e-01, 3.084419355768195e-01, 3.426032314234782e-01, + 3.513809501807375e-01, 3.291518067765479e-01, 2.744631183653730e-01, + 1.907020961496262e-01, 8.598520824614991e-02}, + {1.072518386566368e-05, 1.845748136500827e-04, 1.241661747105944e-03, + 5.147047016717799e-03, 1.568299803301124e-02, 3.838770877189669e-02, + 7.943907234514626e-02, 1.434568646827850e-01, 2.307394793749237e-01, + 3.349054339255650e-01, 4.420417170175802e-01, 5.321478233319703e-01, + 5.829612491775451e-01, 5.753857970850771e-01, 4.990411553052296e-01, + 3.562103001236256e-01, 1.630163920643000e-01}, + {2.261469412614750e-06, 5.678553100877205e-05, 5.191816769372674e-04, + 2.779782677670493e-03, 1.052067600587753e-02, 3.100088336557466e-02, + 7.525531120080720e-02, 1.559524871316514e-01, 2.823982527589936e-01, + 4.537122510063411e-01, 6.528527480865959e-01, 8.449175462761370e-01, + 9.822496334619499e-01, 1.016352742424321e+00, 9.134366220512035e-01, + 6.680980456421279e-01, 3.098947892333867e-01}}, + {// a = 1 + {4.549081245278783e-02, 1.025697116808203e-01, 1.521029153029695e-01, + 1.905674774984742e-01, 2.156317266701110e-01, 2.262944455298862e-01, + 2.229396716942430e-01, 2.072389677171849e-01, 1.819111615965693e-01, + 1.503693019484489e-01, 1.162980963508203e-01, 8.321311204118144e-02, + 5.405478980920327e-02, 3.086568885922368e-02, 1.458892193368564e-02, + 5.010733757564868e-03, 8.524651568277072e-04}, + {1.514739815459632e-03, 8.692316294131076e-03, 2.436068639363824e-02, + 4.888597833155504e-02, 7.995220547465692e-02, 1.130368323567139e-01, + 1.424624885130020e-01, 1.627604598450957e-01, 1.700019192848272e-01, + 1.627604598450952e-01, 1.424624885130013e-01, 1.130368323567144e-01, + 7.995220547465695e-02, 4.888597833155554e-02, 2.436068639363805e-02, + 8.692316294131038e-03, 1.514739815459635e-03}, + {1.233044634533328e-04, 1.296392811140574e-03, 5.774603058213583e-03, + 1.671747559098046e-02, 3.685209548354167e-02, 6.677766301568872e-02, + 1.037320040118806e-01, 1.415359966428405e-01, 1.719799936538742e-01, + 1.872988928665976e-01, 1.828637284314485e-01, 1.590316882031948e-01, + 1.213448824926961e-01, 7.887150802970438e-02, 4.120817316457946e-02, + 1.521563810625176e-02, 2.709293307248373e-03}, + {1.704155122351367e-05, 2.836791789418342e-04, 1.822811755104407e-03, + 7.121780894954346e-03, 2.016315103614819e-02, 4.515440228850054e-02, + 8.404393997951824e-02, 1.339140400477353e-01, 1.859094690043127e-01, + 2.269615005870788e-01, 2.442284372718092e-01, 2.305539788374319e-01, + 1.882978790989171e-01, 1.293042909913915e-01, 7.050121921816414e-02, + 2.684787285389501e-02, 4.874505404873660e-03}, + {3.406740694092426e-06, 8.242230799538509e-05, 7.175170540563040e-04, + 3.611592575391886e-03, 1.267515200344258e-02, 3.412027839486566e-02, + 7.442351009396078e-02, 1.360137453605255e-01, 2.125809450270678e-01, + 2.874097484686258e-01, 3.374891186887510e-01, 3.430062341880836e-01, + 2.978727394079814e-01, 2.149730401934955e-01, 1.218267835691143e-01, + 4.771039224384056e-02, 8.816707015440529e-03}}, + {// a = 2 + {8.598520824614991e-02, 1.907020961496262e-01, 2.744631183653730e-01, + 3.291518067765479e-01, 3.513809501807375e-01, 3.426032314234782e-01, + 3.084419355768195e-01, 2.573085608990289e-01, 1.986340488958086e-01, + 1.411103146484007e-01, 9.130913790909347e-02, 5.293135808289402e-02, + 2.677213833455836e-02, 1.131107007164897e-02, 3.693392470216972e-03, + 7.948522026838238e-04, 7.344643360100710e-05}, + {2.709293307248373e-03, 1.521563810625176e-02, 4.120817316457946e-02, + 7.887150802970438e-02, 1.213448824926961e-01, 1.590316882031948e-01, + 1.828637284314485e-01, 1.872988928665976e-01, 1.719799936538742e-01, + 1.415359966428405e-01, 1.037320040118806e-01, 6.677766301568872e-02, + 3.685209548354167e-02, 1.671747559098046e-02, 5.774603058213583e-03, + 1.296392811140574e-03, 1.233044634533328e-04}, + {2.090067034827627e-04, 2.141017957655637e-03, 9.181538456807289e-03, + 2.527288528222823e-02, 5.227733398127146e-02, 8.764340394578723e-02, + 1.240430597999046e-01, 1.516117923086600e-01, 1.619065897950735e-01, + 1.516117923086597e-01, 1.240430597999047e-01, 8.764340394578669e-02, + 5.227733398127170e-02, 2.527288528222810e-02, 9.181538456807341e-03, + 2.141017957655655e-03, 2.090067034827575e-04}, + {2.741746351398126e-05, 4.429186278435173e-04, 2.730964161249059e-03, + 1.011754357138828e-02, 2.682070082647672e-02, 5.547954007175986e-02, + 9.397537178712370e-02, 1.340471353459491e-01, 1.635243116845976e-01, + 1.717052876554434e-01, 1.549622335479171e-01, 1.190030993702081e-01, + 7.611527386932622e-02, 3.896656778366746e-02, 1.481557358615418e-02, + 3.575387040721511e-03, 3.573402733269803e-04}, + {5.210369255787608e-06, 1.219003512982789e-04, 1.015320713912196e-03, + 4.834464715692282e-03, 1.585656557912542e-02, 3.937085511771213e-02, + 7.807825098547579e-02, 1.276739708535340e-01, 1.753314519941376e-01, + 2.039595721371063e-01, 2.010239069684333e-01, 1.664126212401902e-01, + 1.133687094883810e-01, 6.112793638187385e-02, 2.422102922342991e-02, + 6.030144692356797e-03, 6.157082357045311e-04}}, + {// a = 3 + {1.630163920643000e-01, 3.562103001236256e-01, 4.990411553052296e-01, + 5.753857970850771e-01, 5.829612491775451e-01, 5.321478233319703e-01, + 4.420417170175802e-01, 3.349054339255650e-01, 2.307394793749237e-01, + 1.434568646827850e-01, 7.943907234514626e-02, 3.838770877189669e-02, + 1.568299803301124e-02, 5.147047016717799e-03, 1.241661747105944e-03, + 1.845748136500827e-04, 1.072518386566368e-05}, + {4.874505404873660e-03, 2.684787285389501e-02, 7.050121921816414e-02, + 1.293042909913915e-01, 1.882978790989171e-01, 2.305539788374319e-01, + 2.442284372718092e-01, 2.269615005870788e-01, 1.859094690043127e-01, + 1.339140400477353e-01, 8.404393997951824e-02, 4.515440228850054e-02, + 2.016315103614819e-02, 7.121780894954346e-03, 1.822811755104407e-03, + 2.836791789418342e-04, 1.704155122351367e-05}, + {3.573402733269803e-04, 3.575387040721511e-03, 1.481557358615418e-02, + 3.896656778366746e-02, 7.611527386932622e-02, 1.190030993702081e-01, + 1.549622335479171e-01, 1.717052876554434e-01, 1.635243116845976e-01, + 1.340471353459491e-01, 9.397537178712370e-02, 5.547954007175986e-02, + 2.682070082647672e-02, 1.011754357138828e-02, 2.730964161249059e-03, + 4.429186278435173e-04, 2.741746351398126e-05}, + {4.460712615943976e-05, 7.013003636904480e-04, 4.165617804861459e-03, + 1.470898188971299e-02, 3.674689770287290e-02, 7.077651083566822e-02, + 1.101810000987092e-01, 1.423843548974512e-01, 1.548671728474618e-01, + 1.423843548974516e-01, 1.101810000987091e-01, 7.077651083566813e-02, + 3.674689770287288e-02, 1.470898188971304e-02, 4.165617804861450e-03, + 7.013003636904514e-04, 4.460712615944224e-05}, + {8.078156583640950e-06, 1.833288272322261e-04, 1.467044310162418e-03, + 6.643131051799167e-03, 2.049793389243312e-02, 4.732591740229600e-02, + 8.617597512125302e-02, 1.275969889954371e-01, 1.562112018380642e-01, + 1.591517437915593e-01, 1.345868931717605e-01, 9.329342759618311e-02, + 5.166702485870460e-02, 2.182338989518186e-02, 6.455906596396846e-03, + 1.124418294497242e-03, 7.331048617018153e-05}}, + {// a = 4 + {3.098947892333867e-01, 6.680980456421279e-01, 9.134366220512035e-01, + 1.016352742424321e+00, 9.822496334619499e-01, 8.449175462761370e-01, + 6.528527480865959e-01, 4.537122510063411e-01, 2.823982527589936e-01, + 1.559524871316514e-01, 7.525531120080720e-02, 3.100088336557466e-02, + 1.052067600587753e-02, 2.779782677670493e-03, 5.191816769372674e-04, + 5.678553100877205e-05, 2.261469412614750e-06}, + {8.816707015440529e-03, 4.771039224384056e-02, 1.218267835691143e-01, + 2.149730401934955e-01, 2.978727394079814e-01, 3.430062341880836e-01, + 3.374891186887510e-01, 2.874097484686258e-01, 2.125809450270678e-01, + 1.360137453605255e-01, 7.442351009396078e-02, 3.412027839486566e-02, + 1.267515200344258e-02, 3.611592575391886e-03, 7.175170540563040e-04, + 8.242230799538509e-05, 3.406740694092426e-06}, + {6.157082357045311e-04, 6.030144692356797e-03, 2.422102922342991e-02, + 6.112793638187385e-02, 1.133687094883810e-01, 1.664126212401902e-01, + 2.010239069684333e-01, 2.039595721371063e-01, 1.753314519941376e-01, + 1.276739708535340e-01, 7.807825098547579e-02, 3.937085511771213e-02, + 1.585656557912542e-02, 4.834464715692282e-03, 1.015320713912196e-03, + 1.219003512982789e-04, 5.210369255787608e-06}, + {7.331048617018153e-05, 1.124418294497242e-03, 6.455906596396846e-03, + 2.182338989518186e-02, 5.166702485870460e-02, 9.329342759618311e-02, + 1.345868931717605e-01, 1.591517437915593e-01, 1.562112018380642e-01, + 1.275969889954371e-01, 8.617597512125302e-02, 4.732591740229600e-02, + 2.049793389243312e-02, 6.643131051799167e-03, 1.467044310162418e-03, + 1.833288272322261e-04, 8.078156583640950e-06}, + {1.267943688429357e-05, 2.798792988735616e-04, 2.159507823450682e-03, + 9.342274356001830e-03, 2.727243969963370e-02, 5.895618575762269e-02, + 9.939377920866957e-02, 1.345962178012885e-01, 1.486724859335633e-01, + 1.345962178012887e-01, 9.939377920866907e-02, 5.895618575762289e-02, + 2.727243969963356e-02, 9.342274356001870e-03, 2.159507823450709e-03, + 2.798792988735582e-04, 1.267943688429400e-05}}}; static double _gaussJacobiWt_18[5][5][18] = { - { // a = 0 - { 2.161601352648338e-02, 4.971454889496964e-02, 7.642573025488929e-02, 1.009420441062867e-01, 1.225552067114792e-01, 1.406429146706503e-01, 1.546846751262655e-01, 1.642764837458326e-01, 1.691423829631442e-01, 1.691423829631429e-01, 1.642764837458318e-01, 1.546846751262635e-01, 1.406429146706503e-01, 1.225552067114790e-01, 1.009420441062875e-01, 7.642573025488945e-02, 4.971454889496991e-02, 2.161601352648325e-02}, - { 6.874763363928110e-04, 4.052100717204171e-03, 1.184977225773143e-02, 2.522415552952214e-02, 4.452748038963721e-02, 6.923320192359710e-02, 9.795036000516714e-02, 1.285392245105141e-01, 1.583166491544315e-01, 1.843296039609656e-01, 2.036677154254966e-01, 2.137811512112557e-01, 2.127693385273428e-01, 1.996089076708109e-01, 1.742956282985715e-01, 1.378844756876899e-01, 9.242540065350746e-02, 4.085735774016225e-02}, - { 5.368068899634072e-05, 5.834960693129630e-04, 2.728729629501225e-03, 8.428402271657531e-03, 2.016577310749002e-02, 4.040199030683767e-02, 7.081822580075989e-02, 1.115511812291829e-01, 1.606291335709576e-01, 2.137873949516817e-01, 2.647678096165807e-01, 3.061023573787931e-01, 3.302693264796611e-01, 3.310174583001593e-01, 3.046010740275800e-01, 2.506712613738371e-01, 1.726301814335524e-01, 7.745919043012615e-02}, - { 7.143047059659526e-06, 1.236979709554158e-04, 8.393136884857152e-04, 3.517909509275885e-03, 1.086686545597887e-02, 2.704274554020083e-02, 5.707351931836106e-02, 1.054852772016667e-01, 1.743524688503781e-01, 2.613202738971239e-01, 3.583325568195404e-01, 4.517347241902343e-01, 5.240892056307999e-01, 5.575257368344728e-01, 5.379123179479284e-01, 4.587644597424037e-01, 3.237630567646403e-01, 1.472487275904956e-01}, - { 1.379358472387834e-06, 3.492387820617333e-05, 3.228012635247697e-04, 1.752110766240564e-03, 6.742331822435822e-03, 2.026452402149521e-02, 5.035088171345147e-02, 1.072160159013254e-01, 2.003842848789916e-01, 3.340468517487669e-01, 5.019827083103603e-01, 6.842242944023629e-01, 8.476698268134801e-01, 9.517835944351031e-01, 9.586361961925012e-01, 8.445483311981076e-01, 6.094355014419863e-01, 2.806034418531839e-01} - }, - { // a = 1 - { 4.085735774016225e-02, 9.242540065350746e-02, 1.378844756876899e-01, 1.742956282985715e-01, 1.996089076708109e-01, 2.127693385273428e-01, 2.137811512112557e-01, 2.036677154254966e-01, 1.843296039609656e-01, 1.583166491544315e-01, 1.285392245105141e-01, 9.795036000516714e-02, 6.923320192359710e-02, 4.452748038963721e-02, 2.522415552952214e-02, 1.184977225773143e-02, 4.052100717204171e-03, 6.874763363928110e-04}, - { 1.229581431698275e-03, 7.092065296428100e-03, 2.003881330086018e-02, 4.067462415626539e-02, 6.752484909660991e-02, 9.728891750906635e-02, 1.255226249941509e-01, 1.475947503551022e-01, 1.597004405264855e-01, 1.597004405264850e-01, 1.475947503551025e-01, 1.255226249941507e-01, 9.728891750906601e-02, 6.752484909660994e-02, 4.067462415626495e-02, 2.003881330086045e-02, 7.092065296428068e-03, 1.229581431698274e-03}, - { 9.098286157647830e-05, 9.634158803041655e-04, 4.336571948371077e-03, 1.273178786082411e-02, 2.857311891219792e-02, 5.293885672594971e-02, 8.449607730213654e-02, 1.191430571755908e-01, 1.506517750458153e-01, 1.722265315616270e-01, 1.785183671601017e-01, 1.674086598707683e-01, 1.408972238575466e-01, 1.047064397051893e-01, 6.665186226668300e-02, 3.427417304093411e-02, 1.251227914602443e-02, 2.212153011692748e-03}, - { 1.149031268213569e-05, 1.930610326975742e-04, 1.256618860512075e-03, 4.992380393516446e-03, 1.443254955791392e-02, 3.315555479379857e-02, 6.363713184991962e-02, 1.052032887042713e-01, 1.526454441285636e-01, 1.965453123513496e-01, 2.257067133425438e-01, 2.310515549876802e-01, 2.094284018553430e-01, 1.655309207275169e-01, 1.107644344873579e-01, 5.921155001315227e-02, 2.223252506518649e-02, 4.001067535993429e-03}, - { 2.109107632985097e-06, 5.162402390756201e-05, 4.563660585216808e-04, 2.342147375753609e-03, 8.418211512379521e-03, 2.332135443300519e-02, 5.264149614509298e-02, 1.001989938821832e-01, 1.643582058048056e-01, 2.354279904820576e-01, 2.964699894263590e-01, 3.284848883825424e-01, 3.184156232276903e-01, 2.661510106586024e-01, 1.863612242329334e-01, 1.032043344779669e-01, 3.975632546812279e-02, 7.271438633774174e-03} - }, - { // a = 2 - { 7.745919043012615e-02, 1.726301814335524e-01, 2.506712613738371e-01, 3.046010740275800e-01, 3.310174583001593e-01, 3.302693264796611e-01, 3.061023573787931e-01, 2.647678096165807e-01, 2.137873949516817e-01, 1.606291335709576e-01, 1.115511812291829e-01, 7.081822580075989e-02, 4.040199030683767e-02, 2.016577310749002e-02, 8.428402271657531e-03, 2.728729629501225e-03, 5.834960693129630e-04, 5.368068899634072e-05}, - { 2.212153011692748e-03, 1.251227914602443e-02, 3.427417304093411e-02, 6.665186226668300e-02, 1.047064397051893e-01, 1.408972238575466e-01, 1.674086598707683e-01, 1.785183671601017e-01, 1.722265315616270e-01, 1.506517750458153e-01, 1.191430571755908e-01, 8.449607730213654e-02, 5.293885672594971e-02, 2.857311891219792e-02, 1.273178786082411e-02, 4.336571948371077e-03, 9.634158803041655e-04, 9.098286157647830e-05}, - { 1.555411177967525e-04, 1.608493070349398e-03, 6.994604383611504e-03, 1.961654758676466e-02, 4.155892803186271e-02, 7.177662245875577e-02, 1.053530580641081e-01, 1.345948346801263e-01, 1.516747039399580e-01, 1.516747039399586e-01, 1.345948346801259e-01, 1.053530580641087e-01, 7.177662245875543e-02, 4.155892803186259e-02, 1.961654758676483e-02, 6.994604383611529e-03, 1.608493070349451e-03, 1.555411177967647e-04}, - { 1.869155856882047e-05, 3.055807690569521e-04, 1.915583989637664e-03, 7.251025645696982e-03, 1.974665671556773e-02, 4.221746248438694e-02, 7.442585616039420e-02, 1.113920199185810e-01, 1.439907618691804e-01, 1.621874923914561e-01, 1.595306664007640e-01, 1.364361306942730e-01, 1.002424802875679e-01, 6.184176158360809e-02, 3.075363614936213e-02, 1.143059196857848e-02, 2.712286246365422e-03, 2.679818336219699e-04}, - { 3.269223337105815e-06, 7.760122479817879e-05, 6.588681960960293e-04, 3.214414493445375e-03, 1.086335577339085e-02, 2.796797242286062e-02, 5.792477037326835e-02, 9.975438564992598e-02, 1.457384085664732e-01, 1.826410146562621e-01, 1.970994660526998e-01, 1.826111949895710e-01, 1.436673775925216e-01, 9.388752927841161e-02, 4.895950685402934e-02, 1.889904031163007e-02, 4.614476050999984e-03, 4.649673378976005e-04} - }, - { // a = 3 - { 1.472487275904956e-01, 3.237630567646403e-01, 4.587644597424037e-01, 5.379123179479284e-01, 5.575257368344728e-01, 5.240892056307999e-01, 4.517347241902343e-01, 3.583325568195404e-01, 2.613202738971239e-01, 1.743524688503781e-01, 1.054852772016667e-01, 5.707351931836106e-02, 2.704274554020083e-02, 1.086686545597887e-02, 3.517909509275885e-03, 8.393136884857152e-04, 1.236979709554158e-04, 7.143047059659526e-06}, - { 4.001067535993429e-03, 2.223252506518649e-02, 5.921155001315227e-02, 1.107644344873579e-01, 1.655309207275169e-01, 2.094284018553430e-01, 2.310515549876802e-01, 2.257067133425438e-01, 1.965453123513496e-01, 1.526454441285636e-01, 1.052032887042713e-01, 6.363713184991962e-02, 3.315555479379857e-02, 1.443254955791392e-02, 4.992380393516446e-03, 1.256618860512075e-03, 1.930610326975742e-04, 1.149031268213569e-05}, - { 2.679818336219699e-04, 2.712286246365422e-03, 1.143059196857848e-02, 3.075363614936213e-02, 6.184176158360809e-02, 1.002424802875679e-01, 1.364361306942730e-01, 1.595306664007640e-01, 1.621874923914561e-01, 1.439907618691804e-01, 1.113920199185810e-01, 7.442585616039420e-02, 4.221746248438694e-02, 1.974665671556773e-02, 7.251025645696982e-03, 1.915583989637664e-03, 3.055807690569521e-04, 1.869155856882047e-05}, - { 3.071494273034652e-05, 4.897953879208422e-04, 2.967141212515172e-03, 1.074889875869436e-02, 2.772988023715186e-02, 5.555498276083879e-02, 9.071239675106800e-02, 1.241647024269679e-01, 1.447443446649699e-01, 1.447443446649698e-01, 1.241647024269679e-01, 9.071239675106800e-02, 5.555498276083873e-02, 2.772988023715190e-02, 1.074889875869443e-02, 2.967141212515153e-03, 4.897953879208445e-04, 3.071494273034725e-05}, - { 5.130302491305114e-06, 1.184181551834821e-04, 9.691435945273369e-04, 4.515401925262028e-03, 1.443102107494373e-02, 3.476818380495148e-02, 6.662943462436244e-02, 1.048715433584174e-01, 1.381327265381891e-01, 1.536959594348183e-01, 1.447084631974914e-01, 1.146159805453939e-01, 7.524706156544342e-02, 3.984473529379105e-02, 1.622557930340822e-02, 4.662006566972243e-03, 7.939877179254163e-04, 5.093728214026404e-05} - }, - { // a = 4 - { 2.806034418531839e-01, 6.094355014419863e-01, 8.445483311981076e-01, 9.586361961925012e-01, 9.517835944351031e-01, 8.476698268134801e-01, 6.842242944023629e-01, 5.019827083103603e-01, 3.340468517487669e-01, 2.003842848789916e-01, 1.072160159013254e-01, 5.035088171345147e-02, 2.026452402149521e-02, 6.742331822435822e-03, 1.752110766240564e-03, 3.228012635247697e-04, 3.492387820617333e-05, 1.379358472387834e-06}, - { 7.271438633774174e-03, 3.975632546812279e-02, 1.032043344779669e-01, 1.863612242329334e-01, 2.661510106586024e-01, 3.184156232276903e-01, 3.284848883825424e-01, 2.964699894263590e-01, 2.354279904820576e-01, 1.643582058048056e-01, 1.001989938821832e-01, 5.264149614509298e-02, 2.332135443300519e-02, 8.418211512379521e-03, 2.342147375753609e-03, 4.563660585216808e-04, 5.162402390756201e-05, 2.109107632985097e-06}, - { 4.649673378976005e-04, 4.614476050999984e-03, 1.889904031163007e-02, 4.895950685402934e-02, 9.388752927841161e-02, 1.436673775925216e-01, 1.826111949895710e-01, 1.970994660526998e-01, 1.826410146562621e-01, 1.457384085664732e-01, 9.975438564992598e-02, 5.792477037326835e-02, 2.796797242286062e-02, 1.086335577339085e-02, 3.214414493445375e-03, 6.588681960960293e-04, 7.760122479817879e-05, 3.269223337105815e-06}, - { 5.093728214026404e-05, 7.939877179254163e-04, 4.662006566972243e-03, 1.622557930340822e-02, 3.984473529379105e-02, 7.524706156544342e-02, 1.146159805453939e-01, 1.447084631974914e-01, 1.536959594348183e-01, 1.381327265381891e-01, 1.048715433584174e-01, 6.662943462436244e-02, 3.476818380495148e-02, 1.443102107494373e-02, 4.515401925262028e-03, 9.691435945273369e-04, 1.184181551834821e-04, 5.130302491305114e-06}, - { 8.141436240381040e-06, 1.831710948151471e-04, 1.449550604695897e-03, 6.475639422004388e-03, 1.966820356071560e-02, 4.461036393740649e-02, 7.967416056529358e-02, 1.155983644015973e-01, 1.386816113264379e-01, 1.386816113264371e-01, 1.155983644015979e-01, 7.967416056529328e-02, 4.461036393740658e-02, 1.966820356071560e-02, 6.475639422004406e-03, 1.449550604695908e-03, 1.831710948151466e-04, 8.141436240380612e-06} - } -}; + {// a = 0 + {2.161601352648338e-02, 4.971454889496964e-02, 7.642573025488929e-02, + 1.009420441062867e-01, 1.225552067114792e-01, 1.406429146706503e-01, + 1.546846751262655e-01, 1.642764837458326e-01, 1.691423829631442e-01, + 1.691423829631429e-01, 1.642764837458318e-01, 1.546846751262635e-01, + 1.406429146706503e-01, 1.225552067114790e-01, 1.009420441062875e-01, + 7.642573025488945e-02, 4.971454889496991e-02, 2.161601352648325e-02}, + {6.874763363928110e-04, 4.052100717204171e-03, 1.184977225773143e-02, + 2.522415552952214e-02, 4.452748038963721e-02, 6.923320192359710e-02, + 9.795036000516714e-02, 1.285392245105141e-01, 1.583166491544315e-01, + 1.843296039609656e-01, 2.036677154254966e-01, 2.137811512112557e-01, + 2.127693385273428e-01, 1.996089076708109e-01, 1.742956282985715e-01, + 1.378844756876899e-01, 9.242540065350746e-02, 4.085735774016225e-02}, + {5.368068899634072e-05, 5.834960693129630e-04, 2.728729629501225e-03, + 8.428402271657531e-03, 2.016577310749002e-02, 4.040199030683767e-02, + 7.081822580075989e-02, 1.115511812291829e-01, 1.606291335709576e-01, + 2.137873949516817e-01, 2.647678096165807e-01, 3.061023573787931e-01, + 3.302693264796611e-01, 3.310174583001593e-01, 3.046010740275800e-01, + 2.506712613738371e-01, 1.726301814335524e-01, 7.745919043012615e-02}, + {7.143047059659526e-06, 1.236979709554158e-04, 8.393136884857152e-04, + 3.517909509275885e-03, 1.086686545597887e-02, 2.704274554020083e-02, + 5.707351931836106e-02, 1.054852772016667e-01, 1.743524688503781e-01, + 2.613202738971239e-01, 3.583325568195404e-01, 4.517347241902343e-01, + 5.240892056307999e-01, 5.575257368344728e-01, 5.379123179479284e-01, + 4.587644597424037e-01, 3.237630567646403e-01, 1.472487275904956e-01}, + {1.379358472387834e-06, 3.492387820617333e-05, 3.228012635247697e-04, + 1.752110766240564e-03, 6.742331822435822e-03, 2.026452402149521e-02, + 5.035088171345147e-02, 1.072160159013254e-01, 2.003842848789916e-01, + 3.340468517487669e-01, 5.019827083103603e-01, 6.842242944023629e-01, + 8.476698268134801e-01, 9.517835944351031e-01, 9.586361961925012e-01, + 8.445483311981076e-01, 6.094355014419863e-01, 2.806034418531839e-01}}, + {// a = 1 + {4.085735774016225e-02, 9.242540065350746e-02, 1.378844756876899e-01, + 1.742956282985715e-01, 1.996089076708109e-01, 2.127693385273428e-01, + 2.137811512112557e-01, 2.036677154254966e-01, 1.843296039609656e-01, + 1.583166491544315e-01, 1.285392245105141e-01, 9.795036000516714e-02, + 6.923320192359710e-02, 4.452748038963721e-02, 2.522415552952214e-02, + 1.184977225773143e-02, 4.052100717204171e-03, 6.874763363928110e-04}, + {1.229581431698275e-03, 7.092065296428100e-03, 2.003881330086018e-02, + 4.067462415626539e-02, 6.752484909660991e-02, 9.728891750906635e-02, + 1.255226249941509e-01, 1.475947503551022e-01, 1.597004405264855e-01, + 1.597004405264850e-01, 1.475947503551025e-01, 1.255226249941507e-01, + 9.728891750906601e-02, 6.752484909660994e-02, 4.067462415626495e-02, + 2.003881330086045e-02, 7.092065296428068e-03, 1.229581431698274e-03}, + {9.098286157647830e-05, 9.634158803041655e-04, 4.336571948371077e-03, + 1.273178786082411e-02, 2.857311891219792e-02, 5.293885672594971e-02, + 8.449607730213654e-02, 1.191430571755908e-01, 1.506517750458153e-01, + 1.722265315616270e-01, 1.785183671601017e-01, 1.674086598707683e-01, + 1.408972238575466e-01, 1.047064397051893e-01, 6.665186226668300e-02, + 3.427417304093411e-02, 1.251227914602443e-02, 2.212153011692748e-03}, + {1.149031268213569e-05, 1.930610326975742e-04, 1.256618860512075e-03, + 4.992380393516446e-03, 1.443254955791392e-02, 3.315555479379857e-02, + 6.363713184991962e-02, 1.052032887042713e-01, 1.526454441285636e-01, + 1.965453123513496e-01, 2.257067133425438e-01, 2.310515549876802e-01, + 2.094284018553430e-01, 1.655309207275169e-01, 1.107644344873579e-01, + 5.921155001315227e-02, 2.223252506518649e-02, 4.001067535993429e-03}, + {2.109107632985097e-06, 5.162402390756201e-05, 4.563660585216808e-04, + 2.342147375753609e-03, 8.418211512379521e-03, 2.332135443300519e-02, + 5.264149614509298e-02, 1.001989938821832e-01, 1.643582058048056e-01, + 2.354279904820576e-01, 2.964699894263590e-01, 3.284848883825424e-01, + 3.184156232276903e-01, 2.661510106586024e-01, 1.863612242329334e-01, + 1.032043344779669e-01, 3.975632546812279e-02, 7.271438633774174e-03}}, + {// a = 2 + {7.745919043012615e-02, 1.726301814335524e-01, 2.506712613738371e-01, + 3.046010740275800e-01, 3.310174583001593e-01, 3.302693264796611e-01, + 3.061023573787931e-01, 2.647678096165807e-01, 2.137873949516817e-01, + 1.606291335709576e-01, 1.115511812291829e-01, 7.081822580075989e-02, + 4.040199030683767e-02, 2.016577310749002e-02, 8.428402271657531e-03, + 2.728729629501225e-03, 5.834960693129630e-04, 5.368068899634072e-05}, + {2.212153011692748e-03, 1.251227914602443e-02, 3.427417304093411e-02, + 6.665186226668300e-02, 1.047064397051893e-01, 1.408972238575466e-01, + 1.674086598707683e-01, 1.785183671601017e-01, 1.722265315616270e-01, + 1.506517750458153e-01, 1.191430571755908e-01, 8.449607730213654e-02, + 5.293885672594971e-02, 2.857311891219792e-02, 1.273178786082411e-02, + 4.336571948371077e-03, 9.634158803041655e-04, 9.098286157647830e-05}, + {1.555411177967525e-04, 1.608493070349398e-03, 6.994604383611504e-03, + 1.961654758676466e-02, 4.155892803186271e-02, 7.177662245875577e-02, + 1.053530580641081e-01, 1.345948346801263e-01, 1.516747039399580e-01, + 1.516747039399586e-01, 1.345948346801259e-01, 1.053530580641087e-01, + 7.177662245875543e-02, 4.155892803186259e-02, 1.961654758676483e-02, + 6.994604383611529e-03, 1.608493070349451e-03, 1.555411177967647e-04}, + {1.869155856882047e-05, 3.055807690569521e-04, 1.915583989637664e-03, + 7.251025645696982e-03, 1.974665671556773e-02, 4.221746248438694e-02, + 7.442585616039420e-02, 1.113920199185810e-01, 1.439907618691804e-01, + 1.621874923914561e-01, 1.595306664007640e-01, 1.364361306942730e-01, + 1.002424802875679e-01, 6.184176158360809e-02, 3.075363614936213e-02, + 1.143059196857848e-02, 2.712286246365422e-03, 2.679818336219699e-04}, + {3.269223337105815e-06, 7.760122479817879e-05, 6.588681960960293e-04, + 3.214414493445375e-03, 1.086335577339085e-02, 2.796797242286062e-02, + 5.792477037326835e-02, 9.975438564992598e-02, 1.457384085664732e-01, + 1.826410146562621e-01, 1.970994660526998e-01, 1.826111949895710e-01, + 1.436673775925216e-01, 9.388752927841161e-02, 4.895950685402934e-02, + 1.889904031163007e-02, 4.614476050999984e-03, 4.649673378976005e-04}}, + {// a = 3 + {1.472487275904956e-01, 3.237630567646403e-01, 4.587644597424037e-01, + 5.379123179479284e-01, 5.575257368344728e-01, 5.240892056307999e-01, + 4.517347241902343e-01, 3.583325568195404e-01, 2.613202738971239e-01, + 1.743524688503781e-01, 1.054852772016667e-01, 5.707351931836106e-02, + 2.704274554020083e-02, 1.086686545597887e-02, 3.517909509275885e-03, + 8.393136884857152e-04, 1.236979709554158e-04, 7.143047059659526e-06}, + {4.001067535993429e-03, 2.223252506518649e-02, 5.921155001315227e-02, + 1.107644344873579e-01, 1.655309207275169e-01, 2.094284018553430e-01, + 2.310515549876802e-01, 2.257067133425438e-01, 1.965453123513496e-01, + 1.526454441285636e-01, 1.052032887042713e-01, 6.363713184991962e-02, + 3.315555479379857e-02, 1.443254955791392e-02, 4.992380393516446e-03, + 1.256618860512075e-03, 1.930610326975742e-04, 1.149031268213569e-05}, + {2.679818336219699e-04, 2.712286246365422e-03, 1.143059196857848e-02, + 3.075363614936213e-02, 6.184176158360809e-02, 1.002424802875679e-01, + 1.364361306942730e-01, 1.595306664007640e-01, 1.621874923914561e-01, + 1.439907618691804e-01, 1.113920199185810e-01, 7.442585616039420e-02, + 4.221746248438694e-02, 1.974665671556773e-02, 7.251025645696982e-03, + 1.915583989637664e-03, 3.055807690569521e-04, 1.869155856882047e-05}, + {3.071494273034652e-05, 4.897953879208422e-04, 2.967141212515172e-03, + 1.074889875869436e-02, 2.772988023715186e-02, 5.555498276083879e-02, + 9.071239675106800e-02, 1.241647024269679e-01, 1.447443446649699e-01, + 1.447443446649698e-01, 1.241647024269679e-01, 9.071239675106800e-02, + 5.555498276083873e-02, 2.772988023715190e-02, 1.074889875869443e-02, + 2.967141212515153e-03, 4.897953879208445e-04, 3.071494273034725e-05}, + {5.130302491305114e-06, 1.184181551834821e-04, 9.691435945273369e-04, + 4.515401925262028e-03, 1.443102107494373e-02, 3.476818380495148e-02, + 6.662943462436244e-02, 1.048715433584174e-01, 1.381327265381891e-01, + 1.536959594348183e-01, 1.447084631974914e-01, 1.146159805453939e-01, + 7.524706156544342e-02, 3.984473529379105e-02, 1.622557930340822e-02, + 4.662006566972243e-03, 7.939877179254163e-04, 5.093728214026404e-05}}, + {// a = 4 + {2.806034418531839e-01, 6.094355014419863e-01, 8.445483311981076e-01, + 9.586361961925012e-01, 9.517835944351031e-01, 8.476698268134801e-01, + 6.842242944023629e-01, 5.019827083103603e-01, 3.340468517487669e-01, + 2.003842848789916e-01, 1.072160159013254e-01, 5.035088171345147e-02, + 2.026452402149521e-02, 6.742331822435822e-03, 1.752110766240564e-03, + 3.228012635247697e-04, 3.492387820617333e-05, 1.379358472387834e-06}, + {7.271438633774174e-03, 3.975632546812279e-02, 1.032043344779669e-01, + 1.863612242329334e-01, 2.661510106586024e-01, 3.184156232276903e-01, + 3.284848883825424e-01, 2.964699894263590e-01, 2.354279904820576e-01, + 1.643582058048056e-01, 1.001989938821832e-01, 5.264149614509298e-02, + 2.332135443300519e-02, 8.418211512379521e-03, 2.342147375753609e-03, + 4.563660585216808e-04, 5.162402390756201e-05, 2.109107632985097e-06}, + {4.649673378976005e-04, 4.614476050999984e-03, 1.889904031163007e-02, + 4.895950685402934e-02, 9.388752927841161e-02, 1.436673775925216e-01, + 1.826111949895710e-01, 1.970994660526998e-01, 1.826410146562621e-01, + 1.457384085664732e-01, 9.975438564992598e-02, 5.792477037326835e-02, + 2.796797242286062e-02, 1.086335577339085e-02, 3.214414493445375e-03, + 6.588681960960293e-04, 7.760122479817879e-05, 3.269223337105815e-06}, + {5.093728214026404e-05, 7.939877179254163e-04, 4.662006566972243e-03, + 1.622557930340822e-02, 3.984473529379105e-02, 7.524706156544342e-02, + 1.146159805453939e-01, 1.447084631974914e-01, 1.536959594348183e-01, + 1.381327265381891e-01, 1.048715433584174e-01, 6.662943462436244e-02, + 3.476818380495148e-02, 1.443102107494373e-02, 4.515401925262028e-03, + 9.691435945273369e-04, 1.184181551834821e-04, 5.130302491305114e-06}, + {8.141436240381040e-06, 1.831710948151471e-04, 1.449550604695897e-03, + 6.475639422004388e-03, 1.966820356071560e-02, 4.461036393740649e-02, + 7.967416056529358e-02, 1.155983644015973e-01, 1.386816113264379e-01, + 1.386816113264371e-01, 1.155983644015979e-01, 7.967416056529328e-02, + 4.461036393740658e-02, 1.966820356071560e-02, 6.475639422004406e-03, + 1.449550604695908e-03, 1.831710948151466e-04, 8.141436240380612e-06}}}; static double _gaussJacobiWt_19[5][5][19] = { - { // a = 0 - { 1.946178822972679e-02, 4.481422676569998e-02, 6.904454273764080e-02, 9.149002162244989e-02, 1.115666455473345e-01, 1.287539625393360e-01, 1.426067021736069e-01, 1.527660420658599e-01, 1.589688433939547e-01, 1.610544498487829e-01, 1.589688433939543e-01, 1.527660420658588e-01, 1.426067021736070e-01, 1.287539625393369e-01, 1.115666455473330e-01, 9.149002162245089e-02, 6.904454273764137e-02, 4.481422676569920e-02, 1.946178822972615e-02}, - { 5.605103767134955e-04, 3.311523043695969e-03, 9.720366848173149e-03, 2.079912531311367e-02, 3.696436771726646e-02, 5.795938844843888e-02, 8.284669025103120e-02, 1.100722325773918e-01, 1.375958318076299e-01, 1.630754834873472e-01, 1.840879428645532e-01, 1.983641858748268e-01, 2.040167465068774e-01, 1.997365529616778e-01, 1.849397126743136e-01, 1.598494801959666e-01, 1.255051011429315e-01, 8.369860700791859e-02, 3.689615090013360e-02}, - { 3.984561865575305e-05, 4.347411450560393e-04, 2.044246871127711e-03, 6.360354603588442e-03, 1.535830778153859e-02, 3.111827850042484e-02, 5.528648862345732e-02, 8.849152503229592e-02, 1.298545225759704e-01, 1.767245051985921e-01, 2.247328634888243e-01, 2.682005445648802e-01, 3.008600041627805e-01, 3.167859857190464e-01, 3.113790897780943e-01, 2.822249375958077e-01, 2.296651982296304e-01, 1.569668507218607e-01, 7.013837645503440e-02}, - { 4.850900010806030e-06, 8.445609644738916e-05, 5.772901537617500e-04, 2.442703009312268e-03, 7.634373255300905e-03, 1.926809079186000e-02, 4.134933417543026e-02, 7.793303492969085e-02, 1.317865475900290e-01, 2.028527195722385e-01, 2.869781892238947e-01, 3.754076925412700e-01, 4.554122600049595e-01, 5.121377461676451e-01, 5.314043607306927e-01, 5.028652272171822e-01, 4.227498364192864e-01, 2.954537193248141e-01, 1.336575678961767e-01}, - { 8.609342341304727e-07, 2.195418015541902e-05, 2.048345089081777e-04, 1.124941845934449e-03, 4.391025905286927e-03, 1.342274300690410e-02, 3.401889768337303e-02, 7.412588019454035e-02, 1.422769443598799e-01, 2.445935573098928e-01, 3.809318142807546e-01, 5.414453253908550e-01, 7.051636855722944e-01, 8.418828934590468e-01, 9.177058730817034e-01, 9.032372560675493e-01, 7.822309986938917e-01, 5.579521398605582e-01, 2.552683736642419e-01} - }, - { // a = 1 - { 3.689615090013360e-02, 8.369860700791859e-02, 1.255051011429315e-01, 1.598494801959666e-01, 1.849397126743136e-01, 1.997365529616778e-01, 2.040167465068774e-01, 1.983641858748268e-01, 1.840879428645532e-01, 1.630754834873472e-01, 1.375958318076299e-01, 1.100722325773918e-01, 8.284669025103120e-02, 5.795938844843888e-02, 3.696436771726646e-02, 2.079912531311367e-02, 9.720366848173149e-03, 3.311523043695969e-03, 5.605103767134955e-04}, - { 1.008385312706966e-03, 5.841722290372158e-03, 1.662150932996668e-02, 3.406810256913539e-02, 5.728024975687648e-02, 8.385841043825301e-02, 1.103463166152258e-01, 1.329003715750341e-01, 1.480490036130086e-01, 1.533851903321753e-01, 1.480490036130075e-01, 1.329003715750345e-01, 1.103463166152252e-01, 8.385841043825290e-02, 5.728024975687628e-02, 3.406810256913543e-02, 1.662150932996680e-02, 5.841722290372092e-03, 1.008385312706957e-03}, - { 6.811355527608095e-05, 7.256847086317543e-04, 3.295949977701830e-03, 9.793481062327353e-03, 2.231699982913302e-02, 4.213487754444793e-02, 6.880889694350813e-02, 9.973189523592281e-02, 1.303406870631796e-01, 1.550416782880165e-01, 1.686291604730529e-01, 1.677772931837769e-01, 1.521211910662728e-01, 1.245411430075938e-01, 9.050115647374285e-02, 5.659385384743003e-02, 2.870867865279573e-02, 1.037880759954857e-02, 1.823784820975372e-03}, - { 7.890029264832080e-06, 1.336371906453365e-04, 8.795281626705755e-04, 3.544724777971203e-03, 1.043213257085324e-02, 2.449159290065994e-02, 4.824786095713658e-02, 8.227192747526953e-02, 1.238465975721789e-01, 1.666064240400921e-01, 2.016599152004384e-01, 2.200916949750041e-01, 2.160520342090567e-01, 1.892108191920295e-01, 1.454364820381162e-01, 9.518622519644325e-02, 5.002844810375543e-02, 1.855766005372870e-02, 3.314405354687945e-03}, - { 1.334218092243121e-06, 3.298705701827740e-05, 2.955047853687727e-04, 1.542148806636644e-03, 5.657369326440370e-03, 1.606234902208807e-02, 3.732754593228763e-02, 7.353175485492856e-02, 1.255914199301243e-01, 1.886975631725893e-01, 2.515279400573580e-01, 2.984983991244974e-01, 3.149282373208025e-01, 2.932415394641560e-01, 2.372371552516054e-01, 1.618627408070737e-01, 8.787493382556881e-02, 3.337272048401561e-02, 6.049689892682875e-03} - }, - { // a = 2 - { 7.013837645503440e-02, 1.569668507218607e-01, 2.296651982296304e-01, 2.822249375958077e-01, 3.113790897780943e-01, 3.167859857190464e-01, 3.008600041627805e-01, 2.682005445648802e-01, 2.247328634888243e-01, 1.767245051985921e-01, 1.298545225759704e-01, 8.849152503229592e-02, 5.528648862345732e-02, 3.111827850042484e-02, 1.535830778153859e-02, 6.360354603588442e-03, 2.044246871127711e-03, 4.347411450560393e-04, 3.984561865575305e-05}, - { 1.823784820975372e-03, 1.037880759954857e-02, 2.870867865279573e-02, 5.659385384743003e-02, 9.050115647374285e-02, 1.245411430075938e-01, 1.521211910662728e-01, 1.677772931837769e-01, 1.686291604730529e-01, 1.550416782880165e-01, 1.303406870631796e-01, 9.973189523592281e-02, 6.880889694350813e-02, 4.213487754444793e-02, 2.231699982913302e-02, 9.793481062327353e-03, 3.295949977701830e-03, 7.256847086317543e-04, 6.811355527608095e-05}, - { 1.173448388110257e-04, 1.223444566638098e-03, 5.384347319761795e-03, 1.534480330909799e-02, 3.318049432584984e-02, 5.877516556322710e-02, 8.896868783349395e-02, 1.179664493379611e-01, 1.390144617318000e-01, 1.467162690133844e-01, 1.390144617317998e-01, 1.179664493379615e-01, 8.896868783349424e-02, 5.877516556322719e-02, 3.318049432585000e-02, 1.534480330909794e-02, 5.384347319761749e-03, 1.223444566638114e-03, 1.173448388110220e-04}, - { 1.296374690332938e-05, 2.141377622987574e-04, 1.361656309718859e-03, 5.250543995687603e-03, 1.463299593637842e-02, 3.217901779481117e-02, 5.868590141665852e-02, 9.146679112075290e-02, 1.240901788987191e-01, 1.480952280899640e-01, 1.561968086406756e-01, 1.454856696779677e-01, 1.189118019818240e-01, 8.414703822663099e-02, 5.033564678419491e-02, 2.441608503811752e-02, 8.899487024796105e-03, 2.081125384831356e-03, 2.035888357357768e-04}, - { 2.093360509041031e-06, 5.031761095882681e-05, 4.343704191148428e-04, 2.164095980749780e-03, 7.504498911413320e-03, 1.992920065532674e-02, 4.282940652330748e-02, 7.705933482169039e-02, 1.185716060673332e-01, 1.580365585437519e-01, 1.836117844872129e-01, 1.860740774055974e-01, 1.636132101405143e-01, 1.232597302543858e-01, 7.773274682926593e-02, 3.938604033343654e-02, 1.486434065063976e-02, 3.568715316312661e-03, 3.554907360980722e-04} - }, - { // a = 3 - { 1.336575678961767e-01, 2.954537193248141e-01, 4.227498364192864e-01, 5.028652272171822e-01, 5.314043607306927e-01, 5.121377461676451e-01, 4.554122600049595e-01, 3.754076925412700e-01, 2.869781892238947e-01, 2.028527195722385e-01, 1.317865475900290e-01, 7.793303492969085e-02, 4.134933417543026e-02, 1.926809079186000e-02, 7.634373255300905e-03, 2.442703009312268e-03, 5.772901537617500e-04, 8.445609644738916e-05, 4.850900010806030e-06}, - { 3.314405354687945e-03, 1.855766005372870e-02, 5.002844810375543e-02, 9.518622519644325e-02, 1.454364820381162e-01, 1.892108191920295e-01, 2.160520342090567e-01, 2.200916949750041e-01, 2.016599152004384e-01, 1.666064240400921e-01, 1.238465975721789e-01, 8.227192747526953e-02, 4.824786095713658e-02, 2.449159290065994e-02, 1.043213257085324e-02, 3.544724777971203e-03, 8.795281626705755e-04, 1.336371906453365e-04, 7.890029264832080e-06}, - { 2.035888357357768e-04, 2.081125384831356e-03, 8.899487024796105e-03, 2.441608503811752e-02, 5.033564678419491e-02, 8.414703822663099e-02, 1.189118019818240e-01, 1.454856696779677e-01, 1.561968086406756e-01, 1.480952280899640e-01, 1.240901788987191e-01, 9.146679112075290e-02, 5.868590141665852e-02, 3.217901779481117e-02, 1.463299593637842e-02, 5.250543995687603e-03, 1.361656309718859e-03, 2.141377622987574e-04, 1.296374690332938e-05}, - { 2.149655149432985e-05, 3.470406137227695e-04, 2.138467175357608e-03, 7.920083289565880e-03, 2.100439685600973e-02, 4.352450780386551e-02, 7.401554617101007e-02, 1.063558591688529e-01, 1.313916503865534e-01, 1.408476182528491e-01, 1.313916503865534e-01, 1.063558591688531e-01, 7.401554617101044e-02, 4.352450780386571e-02, 2.100439685600972e-02, 7.920083289565876e-03, 2.138467175357619e-03, 3.470406137227704e-04, 2.149655149433083e-05}, - { 3.321450074956702e-06, 7.780370502869147e-05, 6.492883283212298e-04, 3.100695450147653e-03, 1.021464267133030e-02, 2.552629379880667e-02, 5.109991482279012e-02, 8.470337520014772e-02, 1.186345344062564e-01, 1.420108030482593e-01, 1.459617739757232e-01, 1.286146280844985e-01, 9.636825757527101e-02, 6.039827807990202e-02, 3.077351632643268e-02, 1.214252394050649e-02, 3.401896897666733e-03, 5.682215167242046e-04, 3.594500782696828e-05} - }, - { // a = 4 - { 2.552683736642419e-01, 5.579521398605582e-01, 7.822309986938917e-01, 9.032372560675493e-01, 9.177058730817034e-01, 8.418828934590468e-01, 7.051636855722944e-01, 5.414453253908550e-01, 3.809318142807546e-01, 2.445935573098928e-01, 1.422769443598799e-01, 7.412588019454035e-02, 3.401889768337303e-02, 1.342274300690410e-02, 4.391025905286927e-03, 1.124941845934449e-03, 2.048345089081777e-04, 2.195418015541902e-05, 8.609342341304727e-07}, - { 6.049689892682875e-03, 3.337272048401561e-02, 8.787493382556881e-02, 1.618627408070737e-01, 2.372371552516054e-01, 2.932415394641560e-01, 3.149282373208025e-01, 2.984983991244974e-01, 2.515279400573580e-01, 1.886975631725893e-01, 1.255914199301243e-01, 7.353175485492856e-02, 3.732754593228763e-02, 1.606234902208807e-02, 5.657369326440370e-03, 1.542148806636644e-03, 2.955047853687727e-04, 3.298705701827740e-05, 1.334218092243121e-06}, - { 3.554907360980722e-04, 3.568715316312661e-03, 1.486434065063976e-02, 3.938604033343654e-02, 7.773274682926593e-02, 1.232597302543858e-01, 1.636132101405143e-01, 1.860740774055974e-01, 1.836117844872129e-01, 1.580365585437519e-01, 1.185716060673332e-01, 7.705933482169039e-02, 4.282940652330748e-02, 1.992920065532674e-02, 7.504498911413320e-03, 2.164095980749780e-03, 4.343704191148428e-04, 5.031761095882681e-05, 2.093360509041031e-06}, - { 3.594500782696828e-05, 5.682215167242046e-04, 3.401896897666733e-03, 1.214252394050649e-02, 3.077351632643268e-02, 6.039827807990202e-02, 9.636825757527101e-02, 1.286146280844985e-01, 1.459617739757232e-01, 1.420108030482593e-01, 1.186345344062564e-01, 8.470337520014772e-02, 5.109991482279012e-02, 2.552629379880667e-02, 1.021464267133030e-02, 3.100695450147653e-03, 6.492883283212298e-04, 7.780370502869147e-05, 3.321450074956702e-06}, - { 5.324137185742938e-06, 1.217946961597439e-04, 9.853009259019165e-04, 4.526097064741301e-03, 1.422614507855207e-02, 3.362941349642161e-02, 6.310203771805291e-02, 9.708176030106656e-02, 1.248558130316049e-01, 1.356310397990403e-01, 1.248558130316052e-01, 9.708176030106599e-02, 6.310203771805288e-02, 3.362941349642171e-02, 1.422614507855212e-02, 4.526097064741306e-03, 9.853009259019106e-04, 1.217946961597426e-04, 5.324137185743394e-06} - } -}; + {// a = 0 + {1.946178822972679e-02, 4.481422676569998e-02, 6.904454273764080e-02, + 9.149002162244989e-02, 1.115666455473345e-01, 1.287539625393360e-01, + 1.426067021736069e-01, 1.527660420658599e-01, 1.589688433939547e-01, + 1.610544498487829e-01, 1.589688433939543e-01, 1.527660420658588e-01, + 1.426067021736070e-01, 1.287539625393369e-01, 1.115666455473330e-01, + 9.149002162245089e-02, 6.904454273764137e-02, 4.481422676569920e-02, + 1.946178822972615e-02}, + {5.605103767134955e-04, 3.311523043695969e-03, 9.720366848173149e-03, + 2.079912531311367e-02, 3.696436771726646e-02, 5.795938844843888e-02, + 8.284669025103120e-02, 1.100722325773918e-01, 1.375958318076299e-01, + 1.630754834873472e-01, 1.840879428645532e-01, 1.983641858748268e-01, + 2.040167465068774e-01, 1.997365529616778e-01, 1.849397126743136e-01, + 1.598494801959666e-01, 1.255051011429315e-01, 8.369860700791859e-02, + 3.689615090013360e-02}, + {3.984561865575305e-05, 4.347411450560393e-04, 2.044246871127711e-03, + 6.360354603588442e-03, 1.535830778153859e-02, 3.111827850042484e-02, + 5.528648862345732e-02, 8.849152503229592e-02, 1.298545225759704e-01, + 1.767245051985921e-01, 2.247328634888243e-01, 2.682005445648802e-01, + 3.008600041627805e-01, 3.167859857190464e-01, 3.113790897780943e-01, + 2.822249375958077e-01, 2.296651982296304e-01, 1.569668507218607e-01, + 7.013837645503440e-02}, + {4.850900010806030e-06, 8.445609644738916e-05, 5.772901537617500e-04, + 2.442703009312268e-03, 7.634373255300905e-03, 1.926809079186000e-02, + 4.134933417543026e-02, 7.793303492969085e-02, 1.317865475900290e-01, + 2.028527195722385e-01, 2.869781892238947e-01, 3.754076925412700e-01, + 4.554122600049595e-01, 5.121377461676451e-01, 5.314043607306927e-01, + 5.028652272171822e-01, 4.227498364192864e-01, 2.954537193248141e-01, + 1.336575678961767e-01}, + {8.609342341304727e-07, 2.195418015541902e-05, 2.048345089081777e-04, + 1.124941845934449e-03, 4.391025905286927e-03, 1.342274300690410e-02, + 3.401889768337303e-02, 7.412588019454035e-02, 1.422769443598799e-01, + 2.445935573098928e-01, 3.809318142807546e-01, 5.414453253908550e-01, + 7.051636855722944e-01, 8.418828934590468e-01, 9.177058730817034e-01, + 9.032372560675493e-01, 7.822309986938917e-01, 5.579521398605582e-01, + 2.552683736642419e-01}}, + {// a = 1 + {3.689615090013360e-02, 8.369860700791859e-02, 1.255051011429315e-01, + 1.598494801959666e-01, 1.849397126743136e-01, 1.997365529616778e-01, + 2.040167465068774e-01, 1.983641858748268e-01, 1.840879428645532e-01, + 1.630754834873472e-01, 1.375958318076299e-01, 1.100722325773918e-01, + 8.284669025103120e-02, 5.795938844843888e-02, 3.696436771726646e-02, + 2.079912531311367e-02, 9.720366848173149e-03, 3.311523043695969e-03, + 5.605103767134955e-04}, + {1.008385312706966e-03, 5.841722290372158e-03, 1.662150932996668e-02, + 3.406810256913539e-02, 5.728024975687648e-02, 8.385841043825301e-02, + 1.103463166152258e-01, 1.329003715750341e-01, 1.480490036130086e-01, + 1.533851903321753e-01, 1.480490036130075e-01, 1.329003715750345e-01, + 1.103463166152252e-01, 8.385841043825290e-02, 5.728024975687628e-02, + 3.406810256913543e-02, 1.662150932996680e-02, 5.841722290372092e-03, + 1.008385312706957e-03}, + {6.811355527608095e-05, 7.256847086317543e-04, 3.295949977701830e-03, + 9.793481062327353e-03, 2.231699982913302e-02, 4.213487754444793e-02, + 6.880889694350813e-02, 9.973189523592281e-02, 1.303406870631796e-01, + 1.550416782880165e-01, 1.686291604730529e-01, 1.677772931837769e-01, + 1.521211910662728e-01, 1.245411430075938e-01, 9.050115647374285e-02, + 5.659385384743003e-02, 2.870867865279573e-02, 1.037880759954857e-02, + 1.823784820975372e-03}, + {7.890029264832080e-06, 1.336371906453365e-04, 8.795281626705755e-04, + 3.544724777971203e-03, 1.043213257085324e-02, 2.449159290065994e-02, + 4.824786095713658e-02, 8.227192747526953e-02, 1.238465975721789e-01, + 1.666064240400921e-01, 2.016599152004384e-01, 2.200916949750041e-01, + 2.160520342090567e-01, 1.892108191920295e-01, 1.454364820381162e-01, + 9.518622519644325e-02, 5.002844810375543e-02, 1.855766005372870e-02, + 3.314405354687945e-03}, + {1.334218092243121e-06, 3.298705701827740e-05, 2.955047853687727e-04, + 1.542148806636644e-03, 5.657369326440370e-03, 1.606234902208807e-02, + 3.732754593228763e-02, 7.353175485492856e-02, 1.255914199301243e-01, + 1.886975631725893e-01, 2.515279400573580e-01, 2.984983991244974e-01, + 3.149282373208025e-01, 2.932415394641560e-01, 2.372371552516054e-01, + 1.618627408070737e-01, 8.787493382556881e-02, 3.337272048401561e-02, + 6.049689892682875e-03}}, + {// a = 2 + {7.013837645503440e-02, 1.569668507218607e-01, 2.296651982296304e-01, + 2.822249375958077e-01, 3.113790897780943e-01, 3.167859857190464e-01, + 3.008600041627805e-01, 2.682005445648802e-01, 2.247328634888243e-01, + 1.767245051985921e-01, 1.298545225759704e-01, 8.849152503229592e-02, + 5.528648862345732e-02, 3.111827850042484e-02, 1.535830778153859e-02, + 6.360354603588442e-03, 2.044246871127711e-03, 4.347411450560393e-04, + 3.984561865575305e-05}, + {1.823784820975372e-03, 1.037880759954857e-02, 2.870867865279573e-02, + 5.659385384743003e-02, 9.050115647374285e-02, 1.245411430075938e-01, + 1.521211910662728e-01, 1.677772931837769e-01, 1.686291604730529e-01, + 1.550416782880165e-01, 1.303406870631796e-01, 9.973189523592281e-02, + 6.880889694350813e-02, 4.213487754444793e-02, 2.231699982913302e-02, + 9.793481062327353e-03, 3.295949977701830e-03, 7.256847086317543e-04, + 6.811355527608095e-05}, + {1.173448388110257e-04, 1.223444566638098e-03, 5.384347319761795e-03, + 1.534480330909799e-02, 3.318049432584984e-02, 5.877516556322710e-02, + 8.896868783349395e-02, 1.179664493379611e-01, 1.390144617318000e-01, + 1.467162690133844e-01, 1.390144617317998e-01, 1.179664493379615e-01, + 8.896868783349424e-02, 5.877516556322719e-02, 3.318049432585000e-02, + 1.534480330909794e-02, 5.384347319761749e-03, 1.223444566638114e-03, + 1.173448388110220e-04}, + {1.296374690332938e-05, 2.141377622987574e-04, 1.361656309718859e-03, + 5.250543995687603e-03, 1.463299593637842e-02, 3.217901779481117e-02, + 5.868590141665852e-02, 9.146679112075290e-02, 1.240901788987191e-01, + 1.480952280899640e-01, 1.561968086406756e-01, 1.454856696779677e-01, + 1.189118019818240e-01, 8.414703822663099e-02, 5.033564678419491e-02, + 2.441608503811752e-02, 8.899487024796105e-03, 2.081125384831356e-03, + 2.035888357357768e-04}, + {2.093360509041031e-06, 5.031761095882681e-05, 4.343704191148428e-04, + 2.164095980749780e-03, 7.504498911413320e-03, 1.992920065532674e-02, + 4.282940652330748e-02, 7.705933482169039e-02, 1.185716060673332e-01, + 1.580365585437519e-01, 1.836117844872129e-01, 1.860740774055974e-01, + 1.636132101405143e-01, 1.232597302543858e-01, 7.773274682926593e-02, + 3.938604033343654e-02, 1.486434065063976e-02, 3.568715316312661e-03, + 3.554907360980722e-04}}, + {// a = 3 + {1.336575678961767e-01, 2.954537193248141e-01, 4.227498364192864e-01, + 5.028652272171822e-01, 5.314043607306927e-01, 5.121377461676451e-01, + 4.554122600049595e-01, 3.754076925412700e-01, 2.869781892238947e-01, + 2.028527195722385e-01, 1.317865475900290e-01, 7.793303492969085e-02, + 4.134933417543026e-02, 1.926809079186000e-02, 7.634373255300905e-03, + 2.442703009312268e-03, 5.772901537617500e-04, 8.445609644738916e-05, + 4.850900010806030e-06}, + {3.314405354687945e-03, 1.855766005372870e-02, 5.002844810375543e-02, + 9.518622519644325e-02, 1.454364820381162e-01, 1.892108191920295e-01, + 2.160520342090567e-01, 2.200916949750041e-01, 2.016599152004384e-01, + 1.666064240400921e-01, 1.238465975721789e-01, 8.227192747526953e-02, + 4.824786095713658e-02, 2.449159290065994e-02, 1.043213257085324e-02, + 3.544724777971203e-03, 8.795281626705755e-04, 1.336371906453365e-04, + 7.890029264832080e-06}, + {2.035888357357768e-04, 2.081125384831356e-03, 8.899487024796105e-03, + 2.441608503811752e-02, 5.033564678419491e-02, 8.414703822663099e-02, + 1.189118019818240e-01, 1.454856696779677e-01, 1.561968086406756e-01, + 1.480952280899640e-01, 1.240901788987191e-01, 9.146679112075290e-02, + 5.868590141665852e-02, 3.217901779481117e-02, 1.463299593637842e-02, + 5.250543995687603e-03, 1.361656309718859e-03, 2.141377622987574e-04, + 1.296374690332938e-05}, + {2.149655149432985e-05, 3.470406137227695e-04, 2.138467175357608e-03, + 7.920083289565880e-03, 2.100439685600973e-02, 4.352450780386551e-02, + 7.401554617101007e-02, 1.063558591688529e-01, 1.313916503865534e-01, + 1.408476182528491e-01, 1.313916503865534e-01, 1.063558591688531e-01, + 7.401554617101044e-02, 4.352450780386571e-02, 2.100439685600972e-02, + 7.920083289565876e-03, 2.138467175357619e-03, 3.470406137227704e-04, + 2.149655149433083e-05}, + {3.321450074956702e-06, 7.780370502869147e-05, 6.492883283212298e-04, + 3.100695450147653e-03, 1.021464267133030e-02, 2.552629379880667e-02, + 5.109991482279012e-02, 8.470337520014772e-02, 1.186345344062564e-01, + 1.420108030482593e-01, 1.459617739757232e-01, 1.286146280844985e-01, + 9.636825757527101e-02, 6.039827807990202e-02, 3.077351632643268e-02, + 1.214252394050649e-02, 3.401896897666733e-03, 5.682215167242046e-04, + 3.594500782696828e-05}}, + {// a = 4 + {2.552683736642419e-01, 5.579521398605582e-01, 7.822309986938917e-01, + 9.032372560675493e-01, 9.177058730817034e-01, 8.418828934590468e-01, + 7.051636855722944e-01, 5.414453253908550e-01, 3.809318142807546e-01, + 2.445935573098928e-01, 1.422769443598799e-01, 7.412588019454035e-02, + 3.401889768337303e-02, 1.342274300690410e-02, 4.391025905286927e-03, + 1.124941845934449e-03, 2.048345089081777e-04, 2.195418015541902e-05, + 8.609342341304727e-07}, + {6.049689892682875e-03, 3.337272048401561e-02, 8.787493382556881e-02, + 1.618627408070737e-01, 2.372371552516054e-01, 2.932415394641560e-01, + 3.149282373208025e-01, 2.984983991244974e-01, 2.515279400573580e-01, + 1.886975631725893e-01, 1.255914199301243e-01, 7.353175485492856e-02, + 3.732754593228763e-02, 1.606234902208807e-02, 5.657369326440370e-03, + 1.542148806636644e-03, 2.955047853687727e-04, 3.298705701827740e-05, + 1.334218092243121e-06}, + {3.554907360980722e-04, 3.568715316312661e-03, 1.486434065063976e-02, + 3.938604033343654e-02, 7.773274682926593e-02, 1.232597302543858e-01, + 1.636132101405143e-01, 1.860740774055974e-01, 1.836117844872129e-01, + 1.580365585437519e-01, 1.185716060673332e-01, 7.705933482169039e-02, + 4.282940652330748e-02, 1.992920065532674e-02, 7.504498911413320e-03, + 2.164095980749780e-03, 4.343704191148428e-04, 5.031761095882681e-05, + 2.093360509041031e-06}, + {3.594500782696828e-05, 5.682215167242046e-04, 3.401896897666733e-03, + 1.214252394050649e-02, 3.077351632643268e-02, 6.039827807990202e-02, + 9.636825757527101e-02, 1.286146280844985e-01, 1.459617739757232e-01, + 1.420108030482593e-01, 1.186345344062564e-01, 8.470337520014772e-02, + 5.109991482279012e-02, 2.552629379880667e-02, 1.021464267133030e-02, + 3.100695450147653e-03, 6.492883283212298e-04, 7.780370502869147e-05, + 3.321450074956702e-06}, + {5.324137185742938e-06, 1.217946961597439e-04, 9.853009259019165e-04, + 4.526097064741301e-03, 1.422614507855207e-02, 3.362941349642161e-02, + 6.310203771805291e-02, 9.708176030106656e-02, 1.248558130316049e-01, + 1.356310397990403e-01, 1.248558130316052e-01, 9.708176030106599e-02, + 6.310203771805288e-02, 3.362941349642171e-02, 1.422614507855212e-02, + 4.526097064741306e-03, 9.853009259019106e-04, 1.217946961597426e-04, + 5.324137185743394e-06}}}; static double _gaussJacobiWt_20[5][5][20] = { - { // a = 0 - { 1.761400713915242e-02, 4.060142980038731e-02, 6.267204833410815e-02, 8.327674157670452e-02, 1.019301198172405e-01, 1.181945319615191e-01, 1.316886384491763e-01, 1.420961093183825e-01, 1.491729864726036e-01, 1.527533871307256e-01, 1.527533871307259e-01, 1.491729864726023e-01, 1.420961093183812e-01, 1.316886384491764e-01, 1.181945319615192e-01, 1.019301198172412e-01, 8.327674157670538e-02, 6.267204833410936e-02, 4.060142980038590e-02, 1.761400713915169e-02}, - { 4.615276287027270e-04, 2.732249104343666e-03, 8.045830455856230e-03, 1.729287645076072e-02, 3.091067172020609e-02, 4.881618450672030e-02, 7.038826751682419e-02, 9.450118469419572e-02, 1.196069673705157e-01, 1.438596766154505e-01, 1.652708272666635e-01, 1.818823557654130e-01, 1.919418464397755e-01, 1.940644202394171e-01, 1.873667674502307e-01, 1.715611833519132e-01, 1.470009593465910e-01, 1.146729495165212e-01, 7.613987785480811e-02, 3.348337670509027e-02}, - { 2.999376794669490e-05, 3.283128166985746e-04, 1.551106476940114e-03, 4.856365634138007e-03, 1.181955553577188e-02, 2.417991336725892e-02, 4.345672644898421e-02, 7.050844862594696e-02, 1.051273540532928e-01, 1.457640273461495e-01, 1.894583233139678e-01, 2.320192379647163e-01, 2.684514516278038e-01, 2.935793637761428e-01, 3.027791230153783e-01, 2.927033324258168e-01, 2.618771545405842e-01, 2.110605154330050e-01, 1.433100186059095e-01, 6.380634189021206e-02}, - { 3.353157815245817e-06, 5.865150039219185e-05, 4.034690749605404e-04, 1.721235152696699e-03, 5.434032377411945e-03, 1.388178212294715e-02, 3.021900147777163e-02, 5.791305909034001e-02, 9.984562193439421e-02, 1.571689542619357e-01, 2.282016241857572e-01, 3.077139757869390e-01, 3.869187976499687e-01, 4.543425677646190e-01, 4.975364730140931e-01, 5.053500939332114e-01, 4.703018887241133e-01, 3.904992299906391e-01, 2.706253022010680e-01, 1.218608865989266e-01}, - { 5.487666144509803e-07, 1.408082045731623e-05, 1.324482317181066e-04, 7.348351356219093e-04, 2.903844678093574e-03, 9.007089025276100e-03, 2.321995573202859e-02, 5.160210830764782e-02, 1.013151319675854e-01, 1.787658575111919e-01, 2.868682492789557e-01, 4.221084777884259e-01, 5.724638958602063e-01, 7.172611206902804e-01, 8.296570542443914e-01, 8.816546739615281e-01, 8.506582511915869e-01, 7.258617735691842e-01, 5.125612778000509e-01, 2.332093254391667e-01} - }, - { // a = 1 - { 3.348337670509027e-02, 7.613987785480811e-02, 1.146729495165212e-01, 1.470009593465910e-01, 1.715611833519132e-01, 1.873667674502307e-01, 1.940644202394171e-01, 1.919418464397755e-01, 1.818823557654130e-01, 1.652708272666635e-01, 1.438596766154505e-01, 1.196069673705157e-01, 9.450118469419572e-02, 7.038826751682419e-02, 4.881618450672030e-02, 3.091067172020609e-02, 1.729287645076072e-02, 8.045830455856230e-03, 2.732249104343666e-03, 4.615276287027270e-04}, - { 8.347039028800767e-04, 4.853837985129194e-03, 1.389394537278705e-02, 2.871680139970984e-02, 4.881143733193006e-02, 7.244187855657948e-02, 9.693142868622774e-02, 1.191306500788975e-01, 1.359813551393849e-01, 1.450706282131411e-01, 1.450706282131418e-01, 1.359813551393853e-01, 1.191306500788962e-01, 9.693142868622770e-02, 7.244187855657933e-02, 4.881143733193033e-02, 2.871680139970995e-02, 1.389394537278698e-02, 4.853837985129205e-03, 8.347039028800518e-04}, - { 5.166952892188504e-05, 5.534155648984280e-04, 2.533111849839604e-03, 7.605135695448976e-03, 1.755930125382356e-02, 3.369212673625989e-02, 5.610557668795496e-02, 8.323880983967474e-02, 1.118469222205676e-01, 1.375099136203495e-01, 1.555850094352541e-01, 1.623606827860373e-01, 1.560831512615479e-01, 1.375379398711523e-01, 1.099817259095764e-01, 7.840239268122247e-02, 4.828401025360043e-02, 2.420748025005280e-02, 8.678070962343857e-03, 1.516886924807432e-03}, - { 5.508816805110130e-06, 9.395785146685461e-05, 6.243491188529550e-04, 2.547695718598530e-03, 7.614249225118673e-03, 1.821276452255625e-02, 3.668674985122761e-02, 6.422806943997313e-02, 9.973365570521556e-02, 1.391716330269610e-01, 1.759232352855731e-01, 2.022362018391584e-01, 2.114582928769587e-01, 2.003145395556726e-01, 1.703452071881208e-01, 1.278345091835762e-01, 8.208265565431398e-02, 4.251330311793730e-02, 1.560475718403892e-02, 2.768664837876082e-03}, - { 8.608565193967390e-07, 2.147068799231026e-05, 1.945685263756131e-04, 1.030224401391309e-03, 3.846832631931801e-03, 1.115544541050236e-02, 2.658027343122925e-02, 5.391728248057852e-02, 9.529842117037533e-02, 1.490373520401883e-01, 2.082485745245979e-01, 2.613605315772212e-01, 2.949905454247750e-01, 2.985079493675207e-01, 2.685308164679017e-01, 2.112205458232889e-01, 1.409153963594707e-01, 7.519614627891190e-02, 2.820646294534146e-02, 5.073632927221474e-03} - }, - { // a = 2 - { 6.380634189021206e-02, 1.433100186059095e-01, 2.110605154330050e-01, 2.618771545405842e-01, 2.927033324258168e-01, 3.027791230153783e-01, 2.935793637761428e-01, 2.684514516278038e-01, 2.320192379647163e-01, 1.894583233139678e-01, 1.457640273461495e-01, 1.051273540532928e-01, 7.050844862594696e-02, 4.345672644898421e-02, 2.417991336725892e-02, 1.181955553577188e-02, 4.856365634138007e-03, 1.551106476940114e-03, 3.283128166985746e-04, 2.999376794669490e-05}, - { 1.516886924807432e-03, 8.678070962343857e-03, 2.420748025005280e-02, 4.828401025360043e-02, 7.840239268122247e-02, 1.099817259095764e-01, 1.375379398711523e-01, 1.560831512615479e-01, 1.623606827860373e-01, 1.555850094352541e-01, 1.375099136203495e-01, 1.118469222205676e-01, 8.323880983967474e-02, 5.610557668795496e-02, 3.369212673625989e-02, 1.755930125382356e-02, 7.605135695448976e-03, 2.533111849839604e-03, 5.534155648984280e-04, 5.166952892188504e-05}, - { 8.963958416222125e-05, 9.412369504911721e-04, 4.185615578021692e-03, 1.209524875975838e-02, 2.661909394666631e-02, 4.818878307902000e-02, 7.489000421795822e-02, 1.024830210115733e-01, 1.254035709001833e-01, 1.384371193054993e-01, 1.384371193054984e-01, 1.254035709001829e-01, 1.024830210115731e-01, 7.489000421795759e-02, 4.818878307902041e-02, 2.661909394666614e-02, 1.209524875975835e-02, 4.185615578021638e-03, 9.412369504911824e-04, 8.963958416221792e-05}, - { 9.133832615751404e-06, 1.522361906087519e-04, 9.801218872845627e-04, 3.840500991388080e-03, 1.091925932887307e-02, 2.460232879228123e-02, 4.619153795651842e-02, 7.452202443118797e-02, 1.053180157386830e-01, 1.319249233685375e-01, 1.473969196516950e-01, 1.471402483256259e-01, 1.308785801698183e-01, 1.029222538345098e-01, 7.052518894561741e-02, 4.108130098921402e-02, 1.950262382709381e-02, 6.989146872193697e-03, 1.613808116970697e-03, 1.565134159496541e-04}, - { 1.365672609013792e-06, 3.318802446839218e-05, 2.906728319505188e-04, 1.474835082245556e-03, 5.229769717038873e-03, 1.426541485584200e-02, 3.164685708156192e-02, 5.910982645477970e-02, 9.503926627878106e-02, 1.333954952735661e-01, 1.647626611402603e-01, 1.796362585016358e-01, 1.725966082984333e-01, 1.451318036180439e-01, 1.053370296604169e-01, 6.441753335893181e-02, 3.183553435649934e-02, 1.178131560140924e-02, 2.787299050841663e-03, 2.748841883042782e-04} - }, - { // a = 3 - { 1.218608865989266e-01, 2.706253022010680e-01, 3.904992299906391e-01, 4.703018887241133e-01, 5.053500939332114e-01, 4.975364730140931e-01, 4.543425677646190e-01, 3.869187976499687e-01, 3.077139757869390e-01, 2.282016241857572e-01, 1.571689542619357e-01, 9.984562193439421e-02, 5.791305909034001e-02, 3.021900147777163e-02, 1.388178212294715e-02, 5.434032377411945e-03, 1.721235152696699e-03, 4.034690749605404e-04, 5.865150039219185e-05, 3.353157815245817e-06}, - { 2.768664837876082e-03, 1.560475718403892e-02, 4.251330311793730e-02, 8.208265565431398e-02, 1.278345091835762e-01, 1.703452071881208e-01, 2.003145395556726e-01, 2.114582928769587e-01, 2.022362018391584e-01, 1.759232352855731e-01, 1.391716330269610e-01, 9.973365570521556e-02, 6.422806943997313e-02, 3.668674985122761e-02, 1.821276452255625e-02, 7.614249225118673e-03, 2.547695718598530e-03, 6.243491188529550e-04, 9.395785146685461e-05, 5.508816805110130e-06}, - { 1.565134159496541e-04, 1.613808116970697e-03, 6.989146872193697e-03, 1.950262382709381e-02, 4.108130098921402e-02, 7.052518894561741e-02, 1.029222538345098e-01, 1.308785801698183e-01, 1.471402483256259e-01, 1.473969196516950e-01, 1.319249233685375e-01, 1.053180157386830e-01, 7.452202443118797e-02, 4.619153795651842e-02, 2.460232879228123e-02, 1.091925932887307e-02, 3.840500991388080e-03, 9.801218872845627e-04, 1.522361906087519e-04, 9.133832615751404e-06}, - { 1.527154101373512e-05, 2.492077839669210e-04, 1.558589765751209e-03, 5.884470157562622e-03, 1.598407267195838e-02, 3.410053092833960e-02, 6.005016361458117e-02, 8.994567818901381e-02, 1.167202913055262e-01, 1.326345811851433e-01, 1.326345811851431e-01, 1.167202913055252e-01, 8.994567818901364e-02, 6.005016361458185e-02, 3.410053092833917e-02, 1.598407267195846e-02, 5.884470157562566e-03, 1.558589765751212e-03, 2.492077839669240e-04, 1.527154101373508e-05}, - { 2.188798134953572e-06, 5.193696919466755e-05, 4.408704587341790e-04, 2.151144965499640e-03, 7.275652327322867e-03, 1.876646076608530e-02, 3.900661638805282e-02, 6.758896385657921e-02, 9.973580843301608e-02, 1.269630174622720e-01, 1.403628996744191e-01, 1.349491911479255e-01, 1.123982508662798e-01, 8.030758988092142e-02, 4.835953681070639e-02, 2.383149400707292e-02, 9.149112182261167e-03, 2.507478061206504e-03, 4.117713457583669e-04, 2.572988427133085e-05} - }, - { // a = 4 - { 2.332093254391667e-01, 5.125612778000509e-01, 7.258617735691842e-01, 8.506582511915869e-01, 8.816546739615281e-01, 8.296570542443914e-01, 7.172611206902804e-01, 5.724638958602063e-01, 4.221084777884259e-01, 2.868682492789557e-01, 1.787658575111919e-01, 1.013151319675854e-01, 5.160210830764782e-02, 2.321995573202859e-02, 9.007089025276100e-03, 2.903844678093574e-03, 7.348351356219093e-04, 1.324482317181066e-04, 1.408082045731623e-05, 5.487666144509803e-07}, - { 5.073632927221474e-03, 2.820646294534146e-02, 7.519614627891190e-02, 1.409153963594707e-01, 2.112205458232889e-01, 2.685308164679017e-01, 2.985079493675207e-01, 2.949905454247750e-01, 2.613605315772212e-01, 2.082485745245979e-01, 1.490373520401883e-01, 9.529842117037533e-02, 5.391728248057852e-02, 2.658027343122925e-02, 1.115544541050236e-02, 3.846832631931801e-03, 1.030224401391309e-03, 1.945685263756131e-04, 2.147068799231026e-05, 8.608565193967390e-07}, - { 2.748841883042782e-04, 2.787299050841663e-03, 1.178131560140924e-02, 3.183553435649934e-02, 6.441753335893181e-02, 1.053370296604169e-01, 1.451318036180439e-01, 1.725966082984333e-01, 1.796362585016358e-01, 1.647626611402603e-01, 1.333954952735661e-01, 9.503926627878106e-02, 5.910982645477970e-02, 3.164685708156192e-02, 1.426541485584200e-02, 5.229769717038873e-03, 1.474835082245556e-03, 2.906728319505188e-04, 3.318802446839218e-05, 1.365672609013792e-06}, - { 2.572988427133085e-05, 4.117713457583669e-04, 2.507478061206504e-03, 9.149112182261167e-03, 2.383149400707292e-02, 4.835953681070639e-02, 8.030758988092142e-02, 1.123982508662798e-01, 1.349491911479255e-01, 1.403628996744191e-01, 1.269630174622720e-01, 9.973580843301608e-02, 6.758896385657921e-02, 3.900661638805282e-02, 1.876646076608530e-02, 7.275652327322867e-03, 2.151144965499640e-03, 4.408704587341790e-04, 5.193696919466755e-05, 2.188798134953572e-06}, - { 3.541057356964325e-06, 8.219557979508511e-05, 6.778974578105168e-04, 3.190765480046624e-03, 1.033284641747933e-02, 2.531842456855826e-02, 4.957668331918856e-02, 8.020967907936748e-02, 1.094538766469818e-01, 1.275032967426225e-01, 1.275032967426227e-01, 1.094538766469818e-01, 8.020967907936748e-02, 4.957668331918842e-02, 2.531842456855835e-02, 1.033284641747933e-02, 3.190765480046644e-03, 6.778974578105047e-04, 8.219557979508573e-05, 3.541057356964604e-06} - } -}; + {// a = 0 + {1.761400713915242e-02, 4.060142980038731e-02, 6.267204833410815e-02, + 8.327674157670452e-02, 1.019301198172405e-01, 1.181945319615191e-01, + 1.316886384491763e-01, 1.420961093183825e-01, 1.491729864726036e-01, + 1.527533871307256e-01, 1.527533871307259e-01, 1.491729864726023e-01, + 1.420961093183812e-01, 1.316886384491764e-01, 1.181945319615192e-01, + 1.019301198172412e-01, 8.327674157670538e-02, 6.267204833410936e-02, + 4.060142980038590e-02, 1.761400713915169e-02}, + {4.615276287027270e-04, 2.732249104343666e-03, 8.045830455856230e-03, + 1.729287645076072e-02, 3.091067172020609e-02, 4.881618450672030e-02, + 7.038826751682419e-02, 9.450118469419572e-02, 1.196069673705157e-01, + 1.438596766154505e-01, 1.652708272666635e-01, 1.818823557654130e-01, + 1.919418464397755e-01, 1.940644202394171e-01, 1.873667674502307e-01, + 1.715611833519132e-01, 1.470009593465910e-01, 1.146729495165212e-01, + 7.613987785480811e-02, 3.348337670509027e-02}, + {2.999376794669490e-05, 3.283128166985746e-04, 1.551106476940114e-03, + 4.856365634138007e-03, 1.181955553577188e-02, 2.417991336725892e-02, + 4.345672644898421e-02, 7.050844862594696e-02, 1.051273540532928e-01, + 1.457640273461495e-01, 1.894583233139678e-01, 2.320192379647163e-01, + 2.684514516278038e-01, 2.935793637761428e-01, 3.027791230153783e-01, + 2.927033324258168e-01, 2.618771545405842e-01, 2.110605154330050e-01, + 1.433100186059095e-01, 6.380634189021206e-02}, + {3.353157815245817e-06, 5.865150039219185e-05, 4.034690749605404e-04, + 1.721235152696699e-03, 5.434032377411945e-03, 1.388178212294715e-02, + 3.021900147777163e-02, 5.791305909034001e-02, 9.984562193439421e-02, + 1.571689542619357e-01, 2.282016241857572e-01, 3.077139757869390e-01, + 3.869187976499687e-01, 4.543425677646190e-01, 4.975364730140931e-01, + 5.053500939332114e-01, 4.703018887241133e-01, 3.904992299906391e-01, + 2.706253022010680e-01, 1.218608865989266e-01}, + {5.487666144509803e-07, 1.408082045731623e-05, 1.324482317181066e-04, + 7.348351356219093e-04, 2.903844678093574e-03, 9.007089025276100e-03, + 2.321995573202859e-02, 5.160210830764782e-02, 1.013151319675854e-01, + 1.787658575111919e-01, 2.868682492789557e-01, 4.221084777884259e-01, + 5.724638958602063e-01, 7.172611206902804e-01, 8.296570542443914e-01, + 8.816546739615281e-01, 8.506582511915869e-01, 7.258617735691842e-01, + 5.125612778000509e-01, 2.332093254391667e-01}}, + {// a = 1 + {3.348337670509027e-02, 7.613987785480811e-02, 1.146729495165212e-01, + 1.470009593465910e-01, 1.715611833519132e-01, 1.873667674502307e-01, + 1.940644202394171e-01, 1.919418464397755e-01, 1.818823557654130e-01, + 1.652708272666635e-01, 1.438596766154505e-01, 1.196069673705157e-01, + 9.450118469419572e-02, 7.038826751682419e-02, 4.881618450672030e-02, + 3.091067172020609e-02, 1.729287645076072e-02, 8.045830455856230e-03, + 2.732249104343666e-03, 4.615276287027270e-04}, + {8.347039028800767e-04, 4.853837985129194e-03, 1.389394537278705e-02, + 2.871680139970984e-02, 4.881143733193006e-02, 7.244187855657948e-02, + 9.693142868622774e-02, 1.191306500788975e-01, 1.359813551393849e-01, + 1.450706282131411e-01, 1.450706282131418e-01, 1.359813551393853e-01, + 1.191306500788962e-01, 9.693142868622770e-02, 7.244187855657933e-02, + 4.881143733193033e-02, 2.871680139970995e-02, 1.389394537278698e-02, + 4.853837985129205e-03, 8.347039028800518e-04}, + {5.166952892188504e-05, 5.534155648984280e-04, 2.533111849839604e-03, + 7.605135695448976e-03, 1.755930125382356e-02, 3.369212673625989e-02, + 5.610557668795496e-02, 8.323880983967474e-02, 1.118469222205676e-01, + 1.375099136203495e-01, 1.555850094352541e-01, 1.623606827860373e-01, + 1.560831512615479e-01, 1.375379398711523e-01, 1.099817259095764e-01, + 7.840239268122247e-02, 4.828401025360043e-02, 2.420748025005280e-02, + 8.678070962343857e-03, 1.516886924807432e-03}, + {5.508816805110130e-06, 9.395785146685461e-05, 6.243491188529550e-04, + 2.547695718598530e-03, 7.614249225118673e-03, 1.821276452255625e-02, + 3.668674985122761e-02, 6.422806943997313e-02, 9.973365570521556e-02, + 1.391716330269610e-01, 1.759232352855731e-01, 2.022362018391584e-01, + 2.114582928769587e-01, 2.003145395556726e-01, 1.703452071881208e-01, + 1.278345091835762e-01, 8.208265565431398e-02, 4.251330311793730e-02, + 1.560475718403892e-02, 2.768664837876082e-03}, + {8.608565193967390e-07, 2.147068799231026e-05, 1.945685263756131e-04, + 1.030224401391309e-03, 3.846832631931801e-03, 1.115544541050236e-02, + 2.658027343122925e-02, 5.391728248057852e-02, 9.529842117037533e-02, + 1.490373520401883e-01, 2.082485745245979e-01, 2.613605315772212e-01, + 2.949905454247750e-01, 2.985079493675207e-01, 2.685308164679017e-01, + 2.112205458232889e-01, 1.409153963594707e-01, 7.519614627891190e-02, + 2.820646294534146e-02, 5.073632927221474e-03}}, + {// a = 2 + {6.380634189021206e-02, 1.433100186059095e-01, 2.110605154330050e-01, + 2.618771545405842e-01, 2.927033324258168e-01, 3.027791230153783e-01, + 2.935793637761428e-01, 2.684514516278038e-01, 2.320192379647163e-01, + 1.894583233139678e-01, 1.457640273461495e-01, 1.051273540532928e-01, + 7.050844862594696e-02, 4.345672644898421e-02, 2.417991336725892e-02, + 1.181955553577188e-02, 4.856365634138007e-03, 1.551106476940114e-03, + 3.283128166985746e-04, 2.999376794669490e-05}, + {1.516886924807432e-03, 8.678070962343857e-03, 2.420748025005280e-02, + 4.828401025360043e-02, 7.840239268122247e-02, 1.099817259095764e-01, + 1.375379398711523e-01, 1.560831512615479e-01, 1.623606827860373e-01, + 1.555850094352541e-01, 1.375099136203495e-01, 1.118469222205676e-01, + 8.323880983967474e-02, 5.610557668795496e-02, 3.369212673625989e-02, + 1.755930125382356e-02, 7.605135695448976e-03, 2.533111849839604e-03, + 5.534155648984280e-04, 5.166952892188504e-05}, + {8.963958416222125e-05, 9.412369504911721e-04, 4.185615578021692e-03, + 1.209524875975838e-02, 2.661909394666631e-02, 4.818878307902000e-02, + 7.489000421795822e-02, 1.024830210115733e-01, 1.254035709001833e-01, + 1.384371193054993e-01, 1.384371193054984e-01, 1.254035709001829e-01, + 1.024830210115731e-01, 7.489000421795759e-02, 4.818878307902041e-02, + 2.661909394666614e-02, 1.209524875975835e-02, 4.185615578021638e-03, + 9.412369504911824e-04, 8.963958416221792e-05}, + {9.133832615751404e-06, 1.522361906087519e-04, 9.801218872845627e-04, + 3.840500991388080e-03, 1.091925932887307e-02, 2.460232879228123e-02, + 4.619153795651842e-02, 7.452202443118797e-02, 1.053180157386830e-01, + 1.319249233685375e-01, 1.473969196516950e-01, 1.471402483256259e-01, + 1.308785801698183e-01, 1.029222538345098e-01, 7.052518894561741e-02, + 4.108130098921402e-02, 1.950262382709381e-02, 6.989146872193697e-03, + 1.613808116970697e-03, 1.565134159496541e-04}, + {1.365672609013792e-06, 3.318802446839218e-05, 2.906728319505188e-04, + 1.474835082245556e-03, 5.229769717038873e-03, 1.426541485584200e-02, + 3.164685708156192e-02, 5.910982645477970e-02, 9.503926627878106e-02, + 1.333954952735661e-01, 1.647626611402603e-01, 1.796362585016358e-01, + 1.725966082984333e-01, 1.451318036180439e-01, 1.053370296604169e-01, + 6.441753335893181e-02, 3.183553435649934e-02, 1.178131560140924e-02, + 2.787299050841663e-03, 2.748841883042782e-04}}, + {// a = 3 + {1.218608865989266e-01, 2.706253022010680e-01, 3.904992299906391e-01, + 4.703018887241133e-01, 5.053500939332114e-01, 4.975364730140931e-01, + 4.543425677646190e-01, 3.869187976499687e-01, 3.077139757869390e-01, + 2.282016241857572e-01, 1.571689542619357e-01, 9.984562193439421e-02, + 5.791305909034001e-02, 3.021900147777163e-02, 1.388178212294715e-02, + 5.434032377411945e-03, 1.721235152696699e-03, 4.034690749605404e-04, + 5.865150039219185e-05, 3.353157815245817e-06}, + {2.768664837876082e-03, 1.560475718403892e-02, 4.251330311793730e-02, + 8.208265565431398e-02, 1.278345091835762e-01, 1.703452071881208e-01, + 2.003145395556726e-01, 2.114582928769587e-01, 2.022362018391584e-01, + 1.759232352855731e-01, 1.391716330269610e-01, 9.973365570521556e-02, + 6.422806943997313e-02, 3.668674985122761e-02, 1.821276452255625e-02, + 7.614249225118673e-03, 2.547695718598530e-03, 6.243491188529550e-04, + 9.395785146685461e-05, 5.508816805110130e-06}, + {1.565134159496541e-04, 1.613808116970697e-03, 6.989146872193697e-03, + 1.950262382709381e-02, 4.108130098921402e-02, 7.052518894561741e-02, + 1.029222538345098e-01, 1.308785801698183e-01, 1.471402483256259e-01, + 1.473969196516950e-01, 1.319249233685375e-01, 1.053180157386830e-01, + 7.452202443118797e-02, 4.619153795651842e-02, 2.460232879228123e-02, + 1.091925932887307e-02, 3.840500991388080e-03, 9.801218872845627e-04, + 1.522361906087519e-04, 9.133832615751404e-06}, + {1.527154101373512e-05, 2.492077839669210e-04, 1.558589765751209e-03, + 5.884470157562622e-03, 1.598407267195838e-02, 3.410053092833960e-02, + 6.005016361458117e-02, 8.994567818901381e-02, 1.167202913055262e-01, + 1.326345811851433e-01, 1.326345811851431e-01, 1.167202913055252e-01, + 8.994567818901364e-02, 6.005016361458185e-02, 3.410053092833917e-02, + 1.598407267195846e-02, 5.884470157562566e-03, 1.558589765751212e-03, + 2.492077839669240e-04, 1.527154101373508e-05}, + {2.188798134953572e-06, 5.193696919466755e-05, 4.408704587341790e-04, + 2.151144965499640e-03, 7.275652327322867e-03, 1.876646076608530e-02, + 3.900661638805282e-02, 6.758896385657921e-02, 9.973580843301608e-02, + 1.269630174622720e-01, 1.403628996744191e-01, 1.349491911479255e-01, + 1.123982508662798e-01, 8.030758988092142e-02, 4.835953681070639e-02, + 2.383149400707292e-02, 9.149112182261167e-03, 2.507478061206504e-03, + 4.117713457583669e-04, 2.572988427133085e-05}}, + {// a = 4 + {2.332093254391667e-01, 5.125612778000509e-01, 7.258617735691842e-01, + 8.506582511915869e-01, 8.816546739615281e-01, 8.296570542443914e-01, + 7.172611206902804e-01, 5.724638958602063e-01, 4.221084777884259e-01, + 2.868682492789557e-01, 1.787658575111919e-01, 1.013151319675854e-01, + 5.160210830764782e-02, 2.321995573202859e-02, 9.007089025276100e-03, + 2.903844678093574e-03, 7.348351356219093e-04, 1.324482317181066e-04, + 1.408082045731623e-05, 5.487666144509803e-07}, + {5.073632927221474e-03, 2.820646294534146e-02, 7.519614627891190e-02, + 1.409153963594707e-01, 2.112205458232889e-01, 2.685308164679017e-01, + 2.985079493675207e-01, 2.949905454247750e-01, 2.613605315772212e-01, + 2.082485745245979e-01, 1.490373520401883e-01, 9.529842117037533e-02, + 5.391728248057852e-02, 2.658027343122925e-02, 1.115544541050236e-02, + 3.846832631931801e-03, 1.030224401391309e-03, 1.945685263756131e-04, + 2.147068799231026e-05, 8.608565193967390e-07}, + {2.748841883042782e-04, 2.787299050841663e-03, 1.178131560140924e-02, + 3.183553435649934e-02, 6.441753335893181e-02, 1.053370296604169e-01, + 1.451318036180439e-01, 1.725966082984333e-01, 1.796362585016358e-01, + 1.647626611402603e-01, 1.333954952735661e-01, 9.503926627878106e-02, + 5.910982645477970e-02, 3.164685708156192e-02, 1.426541485584200e-02, + 5.229769717038873e-03, 1.474835082245556e-03, 2.906728319505188e-04, + 3.318802446839218e-05, 1.365672609013792e-06}, + {2.572988427133085e-05, 4.117713457583669e-04, 2.507478061206504e-03, + 9.149112182261167e-03, 2.383149400707292e-02, 4.835953681070639e-02, + 8.030758988092142e-02, 1.123982508662798e-01, 1.349491911479255e-01, + 1.403628996744191e-01, 1.269630174622720e-01, 9.973580843301608e-02, + 6.758896385657921e-02, 3.900661638805282e-02, 1.876646076608530e-02, + 7.275652327322867e-03, 2.151144965499640e-03, 4.408704587341790e-04, + 5.193696919466755e-05, 2.188798134953572e-06}, + {3.541057356964325e-06, 8.219557979508511e-05, 6.778974578105168e-04, + 3.190765480046624e-03, 1.033284641747933e-02, 2.531842456855826e-02, + 4.957668331918856e-02, 8.020967907936748e-02, 1.094538766469818e-01, + 1.275032967426225e-01, 1.275032967426227e-01, 1.094538766469818e-01, + 8.020967907936748e-02, 4.957668331918842e-02, 2.531842456855835e-02, + 1.033284641747933e-02, 3.190765480046644e-03, 6.778974578105047e-04, + 8.219557979508573e-05, 3.541057356964604e-06}}}; void getGaussJacobiQuadrature(int a, int b, int n, double **pt, double **wt) { @@ -1574,88 +4182,87 @@ void getGaussJacobiQuadrature(int a, int b, int n, double **pt, double **wt) *wt = NULL; if(a < 0 || a > 4 || b < 0 || b > 4) Msg::Error("Gauss-Jacobi %i %i quadrature not available.", a, b); - switch (n) { - case 1 : - *pt = _gaussJacobiPt_1[a][b]; - *wt = _gaussJacobiWt_1[a][b]; - break; - case 2 : - *pt = _gaussJacobiPt_2[a][b]; - *wt = _gaussJacobiWt_2[a][b]; - break; - case 3 : - *pt = _gaussJacobiPt_3[a][b]; - *wt = _gaussJacobiWt_3[a][b]; - break; - case 4 : - *pt = _gaussJacobiPt_4[a][b]; - *wt = _gaussJacobiWt_4[a][b]; - break; - case 5 : - *pt = _gaussJacobiPt_5[a][b]; - *wt = _gaussJacobiWt_5[a][b]; - break; - case 6 : - *pt = _gaussJacobiPt_6[a][b]; - *wt = _gaussJacobiWt_6[a][b]; - break; - case 7 : - *pt = _gaussJacobiPt_7[a][b]; - *wt = _gaussJacobiWt_7[a][b]; - break; - case 8 : - *pt = _gaussJacobiPt_8[a][b]; - *wt = _gaussJacobiWt_8[a][b]; - break; - case 9 : - *pt = _gaussJacobiPt_9[a][b]; - *wt = _gaussJacobiWt_9[a][b]; - break; - case 10 : - *pt = _gaussJacobiPt_10[a][b]; - *wt = _gaussJacobiWt_10[a][b]; - break; - case 11 : - *pt = _gaussJacobiPt_11[a][b]; - *wt = _gaussJacobiWt_11[a][b]; - break; - case 12 : - *pt = _gaussJacobiPt_12[a][b]; - *wt = _gaussJacobiWt_12[a][b]; - break; - case 13 : - *pt = _gaussJacobiPt_13[a][b]; - *wt = _gaussJacobiWt_13[a][b]; - break; - case 14 : - *pt = _gaussJacobiPt_14[a][b]; - *wt = _gaussJacobiWt_14[a][b]; - break; - case 15 : - *pt = _gaussJacobiPt_15[a][b]; - *wt = _gaussJacobiWt_15[a][b]; - break; - case 16 : - *pt = _gaussJacobiPt_16[a][b]; - *wt = _gaussJacobiWt_16[a][b]; - break; - case 17 : - *pt = _gaussJacobiPt_17[a][b]; - *wt = _gaussJacobiWt_17[a][b]; - break; - case 18 : - *pt = _gaussJacobiPt_18[a][b]; - *wt = _gaussJacobiWt_18[a][b]; - break; - case 19 : - *pt = _gaussJacobiPt_19[a][b]; - *wt = _gaussJacobiWt_19[a][b]; - break; - case 20 : - *pt = _gaussJacobiPt_20[a][b]; - *wt = _gaussJacobiWt_20[a][b]; - break; - default : - Msg::Error("%i-points Gauss-Jacobi quadrature not available.", n); + switch(n) { + case 1: + *pt = _gaussJacobiPt_1[a][b]; + *wt = _gaussJacobiWt_1[a][b]; + break; + case 2: + *pt = _gaussJacobiPt_2[a][b]; + *wt = _gaussJacobiWt_2[a][b]; + break; + case 3: + *pt = _gaussJacobiPt_3[a][b]; + *wt = _gaussJacobiWt_3[a][b]; + break; + case 4: + *pt = _gaussJacobiPt_4[a][b]; + *wt = _gaussJacobiWt_4[a][b]; + break; + case 5: + *pt = _gaussJacobiPt_5[a][b]; + *wt = _gaussJacobiWt_5[a][b]; + break; + case 6: + *pt = _gaussJacobiPt_6[a][b]; + *wt = _gaussJacobiWt_6[a][b]; + break; + case 7: + *pt = _gaussJacobiPt_7[a][b]; + *wt = _gaussJacobiWt_7[a][b]; + break; + case 8: + *pt = _gaussJacobiPt_8[a][b]; + *wt = _gaussJacobiWt_8[a][b]; + break; + case 9: + *pt = _gaussJacobiPt_9[a][b]; + *wt = _gaussJacobiWt_9[a][b]; + break; + case 10: + *pt = _gaussJacobiPt_10[a][b]; + *wt = _gaussJacobiWt_10[a][b]; + break; + case 11: + *pt = _gaussJacobiPt_11[a][b]; + *wt = _gaussJacobiWt_11[a][b]; + break; + case 12: + *pt = _gaussJacobiPt_12[a][b]; + *wt = _gaussJacobiWt_12[a][b]; + break; + case 13: + *pt = _gaussJacobiPt_13[a][b]; + *wt = _gaussJacobiWt_13[a][b]; + break; + case 14: + *pt = _gaussJacobiPt_14[a][b]; + *wt = _gaussJacobiWt_14[a][b]; + break; + case 15: + *pt = _gaussJacobiPt_15[a][b]; + *wt = _gaussJacobiWt_15[a][b]; + break; + case 16: + *pt = _gaussJacobiPt_16[a][b]; + *wt = _gaussJacobiWt_16[a][b]; + break; + case 17: + *pt = _gaussJacobiPt_17[a][b]; + *wt = _gaussJacobiWt_17[a][b]; + break; + case 18: + *pt = _gaussJacobiPt_18[a][b]; + *wt = _gaussJacobiWt_18[a][b]; + break; + case 19: + *pt = _gaussJacobiPt_19[a][b]; + *wt = _gaussJacobiWt_19[a][b]; + break; + case 20: + *pt = _gaussJacobiPt_20[a][b]; + *wt = _gaussJacobiWt_20[a][b]; + break; + default: Msg::Error("%i-points Gauss-Jacobi quadrature not available.", n); } } diff --git a/Numeric/GaussLegendre1D.h b/Numeric/GaussLegendre1D.h index cc8feaa091898a03648d0e4f2f0624e7800052d0..8f180864737b0ef78025379481388954ec2408a2 100644 --- a/Numeric/GaussLegendre1D.h +++ b/Numeric/GaussLegendre1D.h @@ -4,143 +4,219 @@ // bugs and problems to the public mailing list <gmsh@onelab.info>. /* 1 point rule points */ -static double _GL_pt1[1]={ - 0.000000000000000e+00}; +static double _GL_pt1[1] = {0.000000000000000e+00}; /* 1 point rule weights */ -static double _GL_wt1[1]={ - 2.000000000000000e+00}; +static double _GL_wt1[1] = {2.000000000000000e+00}; /* 2 point rule points */ -static double _GL_pt2[2]={ - -5.773502691896257e-01, 5.773502691896257e-01}; +static double _GL_pt2[2] = {-5.773502691896257e-01, 5.773502691896257e-01}; /* 2 point rule weights */ -static double _GL_wt2[2]={ - 1.000000000000000e+00, 1.000000000000000e+00}; +static double _GL_wt2[2] = {1.000000000000000e+00, 1.000000000000000e+00}; /* 3 point rule points */ -static double _GL_pt3[3]={ - -7.745966692414834e-01, 0.000000000000000e+00, 7.745966692414834e-01}; +static double _GL_pt3[3] = {-7.745966692414834e-01, 0.000000000000000e+00, + 7.745966692414834e-01}; /* 3 point rule weights */ -static double _GL_wt3[3]={ - 5.555555555555552e-01, 8.888888888888888e-01, 5.555555555555552e-01}; +static double _GL_wt3[3] = {5.555555555555552e-01, 8.888888888888888e-01, + 5.555555555555552e-01}; /* 4 point rule points */ -static double _GL_pt4[4]={ - -8.611363115940526e-01,-3.399810435848563e-01, 3.399810435848563e-01, 8.611363115940526e-01}; +static double _GL_pt4[4] = {-8.611363115940526e-01, -3.399810435848563e-01, + 3.399810435848563e-01, 8.611363115940526e-01}; /* 4 point rule weights */ -static double _GL_wt4[4]={ - 3.478548451374537e-01, 6.521451548625464e-01, 6.521451548625464e-01, 3.478548451374537e-01}; +static double _GL_wt4[4] = {3.478548451374537e-01, 6.521451548625464e-01, + 6.521451548625464e-01, 3.478548451374537e-01}; /* 5 point rule points */ -static double _GL_pt5[5]={ - -9.061798459386640e-01,-5.384693101056831e-01, 0.000000000000000e+00, 5.384693101056831e-01, 9.061798459386640e-01}; +static double _GL_pt5[5] = {-9.061798459386640e-01, -5.384693101056831e-01, + 0.000000000000000e+00, 5.384693101056831e-01, + 9.061798459386640e-01}; /* 5 point rule weights */ -static double _GL_wt5[5]={ - 2.369268850561890e-01, 4.786286704993665e-01, 5.688888888888889e-01, 4.786286704993665e-01, 2.369268850561890e-01}; +static double _GL_wt5[5] = {2.369268850561890e-01, 4.786286704993665e-01, + 5.688888888888889e-01, 4.786286704993665e-01, + 2.369268850561890e-01}; /* 6 point rule points */ -static double _GL_pt6[6]={ - -9.324695142031521e-01,-6.612093864662646e-01,-2.386191860831969e-01, 2.386191860831969e-01, 6.612093864662646e-01, 9.324695142031521e-01}; +static double _GL_pt6[6] = {-9.324695142031521e-01, -6.612093864662646e-01, + -2.386191860831969e-01, 2.386191860831969e-01, + 6.612093864662646e-01, 9.324695142031521e-01}; /* 6 point rule weights */ -static double _GL_wt6[6]={ - 1.713244923791705e-01, 3.607615730481386e-01, 4.679139345726913e-01, 4.679139345726913e-01, 3.607615730481386e-01, 1.713244923791705e-01}; - /* 7 point rule points */ - static double _GL_pt7[7]={ - -9.491079123427585e-01,-7.415311855993945e-01,-4.058451513773972e-01, 0.000000000000000e+00, 4.058451513773972e-01, 7.415311855993945e-01, 9.491079123427585e-01}; - - /* 7 point rule weights */ - static double _GL_wt7[7]={ - 1.294849661688697e-01, 2.797053914892767e-01, 3.818300505051190e-01, 4.179591836734694e-01, 3.818300505051190e-01, 2.797053914892767e-01, 1.294849661688697e-01}; - - /* 8 point rule points */ - static double _GL_pt8[8]={ - -9.602898564975363e-01,-7.966664774136268e-01,-5.255324099163290e-01,-1.834346424956498e-01, 1.834346424956498e-01, 5.255324099163290e-01, 7.966664774136268e-01, 9.602898564975363e-01}; - - /* 8 point rule weights */ - static double _GL_wt8[8]={ - 1.012285362903768e-01, 2.223810344533745e-01, 3.137066458778874e-01, 3.626837833783620e-01, 3.626837833783620e-01, 3.137066458778874e-01, 2.223810344533745e-01, 1.012285362903768e-01}; - - /* 9 point rule points */ - static double _GL_pt9[9]={ - -9.681602395076261e-01,-8.360311073266359e-01,-6.133714327005905e-01,-3.242534234038089e-01, 0.000000000000000e+00, 3.242534234038089e-01, 6.133714327005905e-01, 8.360311073266359e-01, 9.681602395076261e-01}; - - /* 9 point rule weights */ - static double _GL_wt9[9]={ - 8.127438836157463e-02, 1.806481606948576e-01, 2.606106964029355e-01, 3.123470770400029e-01, 3.302393550012598e-01, 3.123470770400029e-01, 2.606106964029355e-01, 1.806481606948576e-01, 8.127438836157463e-02}; - - /* 10 point rule points */ - static double _GL_pt10[10]={ - -9.739065285171716e-01,-8.650633666889845e-01,-6.794095682990244e-01,-4.333953941292472e-01,-1.488743389816312e-01, 1.488743389816312e-01, 4.333953941292472e-01, 6.794095682990244e-01, 8.650633666889845e-01, 9.739065285171716e-01}; - - /* 10 point rule weights */ - static double _GL_wt10[10]={ - 6.667134430868774e-02, 1.494513491505805e-01, 2.190863625159822e-01, 2.692667193099962e-01, 2.955242247147529e-01, 2.955242247147529e-01, 2.692667193099962e-01, 2.190863625159822e-01, 1.494513491505805e-01, 6.667134430868774e-02}; - - /* 11 point rule points */ - static double _GL_pt11[11]={ - -9.782286581460570e-01,-8.870625997680953e-01,-7.301520055740494e-01,-5.190961292068118e-01,-2.695431559523450e-01, 0.000000000000000e+00, 2.695431559523450e-01, 5.190961292068118e-01, 7.301520055740494e-01, 8.870625997680953e-01, 9.782286581460570e-01}; - - /* 11 point rule weights */ - static double _GL_wt11[11]={ - 5.566856711617354e-02, 1.255803694649047e-01, 1.862902109277343e-01, 2.331937645919903e-01, 2.628045445102466e-01, 2.729250867779006e-01, 2.628045445102466e-01, 2.331937645919903e-01, 1.862902109277343e-01, 1.255803694649047e-01, 5.566856711617354e-02}; - - /* 12 point rule points */ - static double _GL_pt12[12]={ - -9.815606342467192e-01,-9.041172563704748e-01,-7.699026741943047e-01,-5.873179542866175e-01,-3.678314989981802e-01,-1.252334085114689e-01, 1.252334085114689e-01, 3.678314989981802e-01, 5.873179542866175e-01, 7.699026741943047e-01, 9.041172563704748e-01, 9.815606342467192e-01}; - - /* 12 point rule weights */ - static double _GL_wt12[12]={ - 4.717533638651183e-02, 1.069393259953182e-01, 1.600783285433463e-01, 2.031674267230658e-01, 2.334925365383548e-01, 2.491470458134029e-01, 2.491470458134029e-01, 2.334925365383548e-01, 2.031674267230658e-01, 1.600783285433463e-01, 1.069393259953182e-01, 4.717533638651183e-02}; - - /* 13 point rule points */ - static double _GL_pt13[13]={ - -9.841830547185881e-01,-9.175983992229780e-01,-8.015780907333099e-01,-6.423493394403402e-01,-4.484927510364468e-01,-2.304583159551348e-01, 1.232595164407831e-32, 2.304583159551348e-01, 4.484927510364468e-01, 6.423493394403402e-01, 8.015780907333099e-01, 9.175983992229780e-01, 9.841830547185881e-01}; - - /* 13 point rule weights */ - static double _GL_wt13[13]={ - 4.048400476531581e-02, 9.212149983772838e-02, 1.388735102197872e-01, 1.781459807619457e-01, 2.078160475368884e-01, 2.262831802628971e-01, 2.325515532308739e-01, 2.262831802628971e-01, 2.078160475368884e-01, 1.781459807619457e-01, 1.388735102197872e-01, 9.212149983772838e-02, 4.048400476531581e-02}; - - /* 14 point rule points */ - static double _GL_pt14[14]={ - -9.862838086968123e-01,-9.284348836635736e-01,-8.272013150697650e-01,-6.872929048116855e-01,-5.152486363581541e-01,-3.191123689278897e-01,-1.080549487073437e-01, 1.080549487073437e-01, 3.191123689278897e-01, 5.152486363581541e-01, 6.872929048116855e-01, 8.272013150697650e-01, 9.284348836635736e-01, 9.862838086968123e-01}; - - /* 14 point rule weights */ - static double _GL_wt14[14]={ - 3.511946033175199e-02, 8.015808715976037e-02, 1.215185706879031e-01, 1.572031671581936e-01, 1.855383974779378e-01, 2.051984637212955e-01, 2.152638534631578e-01, 2.152638534631578e-01, 2.051984637212955e-01, 1.855383974779378e-01, 1.572031671581936e-01, 1.215185706879031e-01, 8.015808715976037e-02, 3.511946033175199e-02}; - - /* 15 point rule points */ - static double _GL_pt15[15]={ - -9.879925180204854e-01,-9.372733924007060e-01,-8.482065834104272e-01,-7.244177313601701e-01,-5.709721726085388e-01,-3.941513470775634e-01,-2.011940939974345e-01, 1.232595164407831e-32, 2.011940939974345e-01, 3.941513470775634e-01, 5.709721726085388e-01, 7.244177313601701e-01, 8.482065834104272e-01, 9.372733924007060e-01, 9.879925180204854e-01}; - - /* 15 point rule weights */ - static double _GL_wt15[15]={ - 3.075324199611663e-02, 7.036604748810814e-02, 1.071592204671720e-01, 1.395706779261543e-01, 1.662692058169940e-01, 1.861610000155622e-01, 1.984314853271116e-01, 2.025782419255613e-01, 1.984314853271116e-01, 1.861610000155622e-01, 1.662692058169940e-01, 1.395706779261543e-01, 1.071592204671720e-01, 7.036604748810814e-02, 3.075324199611663e-02}; - - /* 16 point rule points */ - static double _GL_pt16[16]={ - -9.894009349916499e-01,-9.445750230732326e-01,-8.656312023878318e-01,-7.554044083550030e-01,-6.178762444026438e-01,-4.580167776572274e-01,-2.816035507792589e-01,-9.501250983763744e-02, 9.501250983763744e-02, 2.816035507792589e-01, 4.580167776572274e-01, 6.178762444026438e-01, 7.554044083550030e-01, 8.656312023878318e-01, 9.445750230732326e-01, 9.894009349916499e-01}; - - /* 16 point rule weights */ - static double _GL_wt16[16]={ - 2.715245941175406e-02, 6.225352393864778e-02, 9.515851168249290e-02, 1.246289712555339e-01, 1.495959888165768e-01, 1.691565193950026e-01, 1.826034150449236e-01, 1.894506104550685e-01, 1.894506104550685e-01, 1.826034150449236e-01, 1.691565193950026e-01, 1.495959888165768e-01, 1.246289712555339e-01, 9.515851168249290e-02, 6.225352393864778e-02, 2.715245941175406e-02}; - - /* 20 point rule points */ - static double _GL_pt20[20]={ - -9.931285991850949e-01, -9.639719272779138e-01, -9.122344282513259e-01, -8.391169718222188e-01, -7.463319064601508e-01, -6.360536807265150e-01, -5.108670019508271e-01, -3.737060887154196e-01, -2.277858511416451e-01, -7.652652113349733e-02, 7.652652113349733e-02, 2.277858511416451e-01, 3.737060887154196e-01, 5.108670019508271e-01, 6.360536807265150e-01, 7.463319064601508e-01, 8.391169718222188e-01, 9.122344282513259e-01, 9.639719272779138e-01, 9.931285991850949e-01}; - - /* 20 point rule weights */ - static double _GL_wt20[20]={ - 1.761400713915212e-02, 4.060142980038694e-02, 6.267204833410906e-02, 8.327674157670475e-02, 1.019301198172404e-01, 1.181945319615184e-01, 1.316886384491766e-01, 1.420961093183821e-01, 1.491729864726037e-01, 1.527533871307259e-01, 1.527533871307259e-01, 1.491729864726037e-01, 1.420961093183821e-01, 1.316886384491766e-01, 1.181945319615184e-01, 1.019301198172404e-01, 8.327674157670475e-02, 6.267204833410906e-02, 4.060142980038694e-02, 1.761400713915212e-02}; +static double _GL_wt6[6] = {1.713244923791705e-01, 3.607615730481386e-01, + 4.679139345726913e-01, 4.679139345726913e-01, + 3.607615730481386e-01, 1.713244923791705e-01}; +/* 7 point rule points */ +static double _GL_pt7[7] = {-9.491079123427585e-01, -7.415311855993945e-01, + -4.058451513773972e-01, 0.000000000000000e+00, + 4.058451513773972e-01, 7.415311855993945e-01, + 9.491079123427585e-01}; + +/* 7 point rule weights */ +static double _GL_wt7[7] = {1.294849661688697e-01, 2.797053914892767e-01, + 3.818300505051190e-01, 4.179591836734694e-01, + 3.818300505051190e-01, 2.797053914892767e-01, + 1.294849661688697e-01}; + +/* 8 point rule points */ +static double _GL_pt8[8] = {-9.602898564975363e-01, -7.966664774136268e-01, + -5.255324099163290e-01, -1.834346424956498e-01, + 1.834346424956498e-01, 5.255324099163290e-01, + 7.966664774136268e-01, 9.602898564975363e-01}; + +/* 8 point rule weights */ +static double _GL_wt8[8] = {1.012285362903768e-01, 2.223810344533745e-01, + 3.137066458778874e-01, 3.626837833783620e-01, + 3.626837833783620e-01, 3.137066458778874e-01, + 2.223810344533745e-01, 1.012285362903768e-01}; + +/* 9 point rule points */ +static double _GL_pt9[9] = { + -9.681602395076261e-01, -8.360311073266359e-01, -6.133714327005905e-01, + -3.242534234038089e-01, 0.000000000000000e+00, 3.242534234038089e-01, + 6.133714327005905e-01, 8.360311073266359e-01, 9.681602395076261e-01}; + +/* 9 point rule weights */ +static double _GL_wt9[9] = { + 8.127438836157463e-02, 1.806481606948576e-01, 2.606106964029355e-01, + 3.123470770400029e-01, 3.302393550012598e-01, 3.123470770400029e-01, + 2.606106964029355e-01, 1.806481606948576e-01, 8.127438836157463e-02}; + +/* 10 point rule points */ +static double _GL_pt10[10] = {-9.739065285171716e-01, -8.650633666889845e-01, + -6.794095682990244e-01, -4.333953941292472e-01, + -1.488743389816312e-01, 1.488743389816312e-01, + 4.333953941292472e-01, 6.794095682990244e-01, + 8.650633666889845e-01, 9.739065285171716e-01}; + +/* 10 point rule weights */ +static double _GL_wt10[10] = {6.667134430868774e-02, 1.494513491505805e-01, + 2.190863625159822e-01, 2.692667193099962e-01, + 2.955242247147529e-01, 2.955242247147529e-01, + 2.692667193099962e-01, 2.190863625159822e-01, + 1.494513491505805e-01, 6.667134430868774e-02}; + +/* 11 point rule points */ +static double _GL_pt11[11] = { + -9.782286581460570e-01, -8.870625997680953e-01, -7.301520055740494e-01, + -5.190961292068118e-01, -2.695431559523450e-01, 0.000000000000000e+00, + 2.695431559523450e-01, 5.190961292068118e-01, 7.301520055740494e-01, + 8.870625997680953e-01, 9.782286581460570e-01}; + +/* 11 point rule weights */ +static double _GL_wt11[11] = { + 5.566856711617354e-02, 1.255803694649047e-01, 1.862902109277343e-01, + 2.331937645919903e-01, 2.628045445102466e-01, 2.729250867779006e-01, + 2.628045445102466e-01, 2.331937645919903e-01, 1.862902109277343e-01, + 1.255803694649047e-01, 5.566856711617354e-02}; + +/* 12 point rule points */ +static double _GL_pt12[12] = { + -9.815606342467192e-01, -9.041172563704748e-01, -7.699026741943047e-01, + -5.873179542866175e-01, -3.678314989981802e-01, -1.252334085114689e-01, + 1.252334085114689e-01, 3.678314989981802e-01, 5.873179542866175e-01, + 7.699026741943047e-01, 9.041172563704748e-01, 9.815606342467192e-01}; + +/* 12 point rule weights */ +static double _GL_wt12[12] = { + 4.717533638651183e-02, 1.069393259953182e-01, 1.600783285433463e-01, + 2.031674267230658e-01, 2.334925365383548e-01, 2.491470458134029e-01, + 2.491470458134029e-01, 2.334925365383548e-01, 2.031674267230658e-01, + 1.600783285433463e-01, 1.069393259953182e-01, 4.717533638651183e-02}; + +/* 13 point rule points */ +static double _GL_pt13[13] = { + -9.841830547185881e-01, -9.175983992229780e-01, -8.015780907333099e-01, + -6.423493394403402e-01, -4.484927510364468e-01, -2.304583159551348e-01, + 1.232595164407831e-32, 2.304583159551348e-01, 4.484927510364468e-01, + 6.423493394403402e-01, 8.015780907333099e-01, 9.175983992229780e-01, + 9.841830547185881e-01}; + +/* 13 point rule weights */ +static double _GL_wt13[13] = { + 4.048400476531581e-02, 9.212149983772838e-02, 1.388735102197872e-01, + 1.781459807619457e-01, 2.078160475368884e-01, 2.262831802628971e-01, + 2.325515532308739e-01, 2.262831802628971e-01, 2.078160475368884e-01, + 1.781459807619457e-01, 1.388735102197872e-01, 9.212149983772838e-02, + 4.048400476531581e-02}; + +/* 14 point rule points */ +static double _GL_pt14[14] = { + -9.862838086968123e-01, -9.284348836635736e-01, -8.272013150697650e-01, + -6.872929048116855e-01, -5.152486363581541e-01, -3.191123689278897e-01, + -1.080549487073437e-01, 1.080549487073437e-01, 3.191123689278897e-01, + 5.152486363581541e-01, 6.872929048116855e-01, 8.272013150697650e-01, + 9.284348836635736e-01, 9.862838086968123e-01}; + +/* 14 point rule weights */ +static double _GL_wt14[14] = { + 3.511946033175199e-02, 8.015808715976037e-02, 1.215185706879031e-01, + 1.572031671581936e-01, 1.855383974779378e-01, 2.051984637212955e-01, + 2.152638534631578e-01, 2.152638534631578e-01, 2.051984637212955e-01, + 1.855383974779378e-01, 1.572031671581936e-01, 1.215185706879031e-01, + 8.015808715976037e-02, 3.511946033175199e-02}; + +/* 15 point rule points */ +static double _GL_pt15[15] = { + -9.879925180204854e-01, -9.372733924007060e-01, -8.482065834104272e-01, + -7.244177313601701e-01, -5.709721726085388e-01, -3.941513470775634e-01, + -2.011940939974345e-01, 1.232595164407831e-32, 2.011940939974345e-01, + 3.941513470775634e-01, 5.709721726085388e-01, 7.244177313601701e-01, + 8.482065834104272e-01, 9.372733924007060e-01, 9.879925180204854e-01}; + +/* 15 point rule weights */ +static double _GL_wt15[15] = { + 3.075324199611663e-02, 7.036604748810814e-02, 1.071592204671720e-01, + 1.395706779261543e-01, 1.662692058169940e-01, 1.861610000155622e-01, + 1.984314853271116e-01, 2.025782419255613e-01, 1.984314853271116e-01, + 1.861610000155622e-01, 1.662692058169940e-01, 1.395706779261543e-01, + 1.071592204671720e-01, 7.036604748810814e-02, 3.075324199611663e-02}; + +/* 16 point rule points */ +static double _GL_pt16[16] = { + -9.894009349916499e-01, -9.445750230732326e-01, -8.656312023878318e-01, + -7.554044083550030e-01, -6.178762444026438e-01, -4.580167776572274e-01, + -2.816035507792589e-01, -9.501250983763744e-02, 9.501250983763744e-02, + 2.816035507792589e-01, 4.580167776572274e-01, 6.178762444026438e-01, + 7.554044083550030e-01, 8.656312023878318e-01, 9.445750230732326e-01, + 9.894009349916499e-01}; + +/* 16 point rule weights */ +static double _GL_wt16[16] = { + 2.715245941175406e-02, 6.225352393864778e-02, 9.515851168249290e-02, + 1.246289712555339e-01, 1.495959888165768e-01, 1.691565193950026e-01, + 1.826034150449236e-01, 1.894506104550685e-01, 1.894506104550685e-01, + 1.826034150449236e-01, 1.691565193950026e-01, 1.495959888165768e-01, + 1.246289712555339e-01, 9.515851168249290e-02, 6.225352393864778e-02, + 2.715245941175406e-02}; + +/* 20 point rule points */ +static double _GL_pt20[20] = { + -9.931285991850949e-01, -9.639719272779138e-01, -9.122344282513259e-01, + -8.391169718222188e-01, -7.463319064601508e-01, -6.360536807265150e-01, + -5.108670019508271e-01, -3.737060887154196e-01, -2.277858511416451e-01, + -7.652652113349733e-02, 7.652652113349733e-02, 2.277858511416451e-01, + 3.737060887154196e-01, 5.108670019508271e-01, 6.360536807265150e-01, + 7.463319064601508e-01, 8.391169718222188e-01, 9.122344282513259e-01, + 9.639719272779138e-01, 9.931285991850949e-01}; + +/* 20 point rule weights */ +static double _GL_wt20[20] = { + 1.761400713915212e-02, 4.060142980038694e-02, 6.267204833410906e-02, + 8.327674157670475e-02, 1.019301198172404e-01, 1.181945319615184e-01, + 1.316886384491766e-01, 1.420961093183821e-01, 1.491729864726037e-01, + 1.527533871307259e-01, 1.527533871307259e-01, 1.491729864726037e-01, + 1.420961093183821e-01, 1.316886384491766e-01, 1.181945319615184e-01, + 1.019301198172404e-01, 8.327674157670475e-02, 6.267204833410906e-02, + 4.060142980038694e-02, 1.761400713915212e-02}; inline void gmshGaussLegendre1D(int nbQuadPoints, double **t, double **w) { - switch (nbQuadPoints){ + switch(nbQuadPoints) { case 1: *t = _GL_pt1; *w = _GL_wt1; @@ -209,10 +285,9 @@ inline void gmshGaussLegendre1D(int nbQuadPoints, double **t, double **w) *t = _GL_pt20; *w = _GL_wt20; break; - default : + default: *t = 0; *w = 0; break; } } - diff --git a/Numeric/GaussLegendreSimplex.cpp b/Numeric/GaussLegendreSimplex.cpp index 27aabff39edac95f6140cb3e02654efb47aa380b..b4f949ba669a9280b04a4d80a8aa562b21f103be 100644 --- a/Numeric/GaussLegendreSimplex.cpp +++ b/Numeric/GaussLegendreSimplex.cpp @@ -7,8 +7,8 @@ #include "GaussIntegration.h" #include "GaussLegendre1D.h" -static void brickToTet(double xi, double eta, double zeta, - double *r, double *s, double *t, double *J) +static void brickToTet(double xi, double eta, double zeta, double *r, double *s, + double *t, double *J) { double r1, rs1; *r = 0.5e0 * (1.0e0 + xi); @@ -25,49 +25,46 @@ void quadToTri(double xi, double eta, double *r, double *s, double *J) *r = 0.5e0 * (1.0e0 + xi); r1 = 1.0e0 - (*r); *s = 0.5e0 * (1.0e0 + eta) * r1; - *J = 0.25e0 * r1; + *J = 0.25e0 * r1; } -double quadToTriJac(double,double eta) -{ - return 0.125e0 * (1.0e0 - eta); -} +double quadToTriJac(double, double eta) { return 0.125e0 * (1.0e0 - eta); } -int GaussLegendreTet(int n1, int n2, int n3, IntPt *pts) +int GaussLegendreTet(int n1, int n2, int n3, IntPt *pts) { /* get degenerate n1Xn2Xn3 Gauss-Legendre scheme to integrate over a tet */ - int i,j,k,index=0; - double *pt1,*pt2,*pt3,*wt1,*wt2,*wt3,dJ; + int i, j, k, index = 0; + double *pt1, *pt2, *pt3, *wt1, *wt2, *wt3, dJ; - gmshGaussLegendre1D(n1,&pt1,&wt1); - gmshGaussLegendre1D(n2,&pt2,&wt2); - gmshGaussLegendre1D(n3,&pt3,&wt3); - for(i=0; i < n1; i++) { - for(j=0; j < n2; j++) { - for(k=0; k < n3; k++) { - brickToTet(pt1[i],pt2[j],pt3[k],&(pts[index].pt[0]), - &(pts[index].pt[1]),&(pts[index].pt[2]),&dJ); - pts[index++].weight = dJ*wt1[i]*wt2[j]*wt3[k]; + gmshGaussLegendre1D(n1, &pt1, &wt1); + gmshGaussLegendre1D(n2, &pt2, &wt2); + gmshGaussLegendre1D(n3, &pt3, &wt3); + for(i = 0; i < n1; i++) { + for(j = 0; j < n2; j++) { + for(k = 0; k < n3; k++) { + brickToTet(pt1[i], pt2[j], pt3[k], &(pts[index].pt[0]), + &(pts[index].pt[1]), &(pts[index].pt[2]), &dJ); + pts[index++].weight = dJ * wt1[i] * wt2[j] * wt3[k]; } } } return index; } -int GaussLegendreTri(int n1,int n2,IntPt *pts) +int GaussLegendreTri(int n1, int n2, IntPt *pts) { /* get degenerate n1Xn2 Gauss-Legendre scheme to integrate over a tri */ - int i,j,index=0; - double *pt1,*pt2,*wt1,*wt2,dJ; - //const double two = 2.0000000000000000; + int i, j, index = 0; + double *pt1, *pt2, *wt1, *wt2, dJ; + // const double two = 2.0000000000000000; - gmshGaussLegendre1D(n1,&pt1,&wt1); - gmshGaussLegendre1D(n2,&pt2,&wt2); - for(i=0; i < n1; i++) { - for(j=0; j < n2; j++) { - quadToTri(pt1[i],pt2[j],&(pts[index].pt[0]),&(pts[index].pt[1]),&dJ); + gmshGaussLegendre1D(n1, &pt1, &wt1); + gmshGaussLegendre1D(n2, &pt2, &wt2); + for(i = 0; i < n1; i++) { + for(j = 0; j < n2; j++) { + quadToTri(pt1[i], pt2[j], &(pts[index].pt[0]), &(pts[index].pt[1]), &dJ); pts[index].pt[2] = 0; - pts[index++].weight = dJ*wt1[i]*wt2[j]; + pts[index++].weight = dJ * wt1[i] * wt2[j]; } } return index; diff --git a/Numeric/GaussQuadratureHex.cpp b/Numeric/GaussQuadratureHex.cpp index 419ab8a7bb02ce63a3b3e70b3106f6de9279505a..6dd9d44bbc6593df0ef66b21f10e01f3b980d08d 100644 --- a/Numeric/GaussQuadratureHex.cpp +++ b/Numeric/GaussQuadratureHex.cpp @@ -6,63 +6,51 @@ #include "GaussIntegration.h" #include "GaussLegendre1D.h" -const double a1 = 0.40824826; -const double ma1 =-0.40824826; -const double a2 = 0.81649658; -const double ma2 =-0.81649658; -const double b1 = 0.70710678; -const double mb1 =-0.70710678; -const double c1 = 0.57735027; -const double mc1 =-0.57735027; -const double w1 = 1.3333333333; -const double xh6[6] = { a1, a1, ma1, ma1, ma2, a2}; -const double yh6[6] = { b1, mb1, b1, mb1, 0., 0.}; -const double zh6[6] = {mc1, mc1, c1, c1, mc1, c1}; -const double ph6[6] = { w1, w1, w1, w1, w1, w1}; +const double a1 = 0.40824826; +const double ma1 = -0.40824826; +const double a2 = 0.81649658; +const double ma2 = -0.81649658; +const double b1 = 0.70710678; +const double mb1 = -0.70710678; +const double c1 = 0.57735027; +const double mc1 = -0.57735027; +const double w1 = 1.3333333333; +const double xh6[6] = {a1, a1, ma1, ma1, ma2, a2}; +const double yh6[6] = {b1, mb1, b1, mb1, 0., 0.}; +const double zh6[6] = {mc1, mc1, c1, c1, mc1, c1}; +const double ph6[6] = {w1, w1, w1, w1, w1, w1}; -IntPt GQH1[1] = -{ - { {0.0,0.0,0.0},8.0 } -}; +IntPt GQH1[1] = {{{0.0, 0.0, 0.0}, 8.0}}; -IntPt GQH6[6] = -{ - { {xh6[0],yh6[0],zh6[0]},ph6[0] }, - { {xh6[1],yh6[1],zh6[1]},ph6[1] }, - { {xh6[2],yh6[2],zh6[2]},ph6[2] }, - { {xh6[3],yh6[3],zh6[3]},ph6[3] }, - { {xh6[4],yh6[4],zh6[4]},ph6[4] }, - { {xh6[5],yh6[5],zh6[5]},ph6[5] } -}; +IntPt GQH6[6] = { + {{xh6[0], yh6[0], zh6[0]}, ph6[0]}, {{xh6[1], yh6[1], zh6[1]}, ph6[1]}, + {{xh6[2], yh6[2], zh6[2]}, ph6[2]}, {{xh6[3], yh6[3], zh6[3]}, ph6[3]}, + {{xh6[4], yh6[4], zh6[4]}, ph6[4]}, {{xh6[5], yh6[5], zh6[5]}, ph6[5]}}; -const double xh8[8] = - {0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626, - 0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626}; -const double yh8[8] = - {0.577350269189626,0.577350269189626,-0.577350269189626,-0.577350269189626, - 0.577350269189626,0.577350269189626,-0.577350269189626,-0.577350269189626}; -const double zh8[8] = - {-0.577350269189626,-0.577350269189626,-0.577350269189626,-0.577350269189626, - 0.577350269189626,0.577350269189626,0.577350269189626,0.577350269189626}; -const double ph8[8] = {1.,1.,1.,1.,1.,1.,1.,1.}; +const double xh8[8] = { + 0.577350269189626, -0.577350269189626, 0.577350269189626, -0.577350269189626, + 0.577350269189626, -0.577350269189626, 0.577350269189626, -0.577350269189626}; +const double yh8[8] = { + 0.577350269189626, 0.577350269189626, -0.577350269189626, -0.577350269189626, + 0.577350269189626, 0.577350269189626, -0.577350269189626, -0.577350269189626}; +const double zh8[8] = {-0.577350269189626, -0.577350269189626, + -0.577350269189626, -0.577350269189626, + 0.577350269189626, 0.577350269189626, + 0.577350269189626, 0.577350269189626}; +const double ph8[8] = {1., 1., 1., 1., 1., 1., 1., 1.}; -IntPt GQH8[8] = -{ - { {xh8[0],yh8[0],zh8[0]},ph8[0] }, - { {xh8[1],yh8[1],zh8[1]},ph8[1] }, - { {xh8[2],yh8[2],zh8[2]},ph8[2] }, - { {xh8[3],yh8[3],zh8[3]},ph8[3] }, - { {xh8[4],yh8[4],zh8[4]},ph8[4] }, - { {xh8[5],yh8[5],zh8[5]},ph8[5] }, - { {xh8[6],yh8[6],zh8[6]},ph8[6] }, - { {xh8[7],yh8[7],zh8[7]},ph8[7] } -}; +IntPt GQH8[8] = { + {{xh8[0], yh8[0], zh8[0]}, ph8[0]}, {{xh8[1], yh8[1], zh8[1]}, ph8[1]}, + {{xh8[2], yh8[2], zh8[2]}, ph8[2]}, {{xh8[3], yh8[3], zh8[3]}, ph8[3]}, + {{xh8[4], yh8[4], zh8[4]}, ph8[4]}, {{xh8[5], yh8[5], zh8[5]}, ph8[5]}, + {{xh8[6], yh8[6], zh8[6]}, ph8[6]}, {{xh8[7], yh8[7], zh8[7]}, ph8[7]}}; IntPt *getGQHPts(int order); int getNGQHPts(int order); -IntPt * GQH[17] = {GQH1,GQH1,GQH6,GQH8,0,0,0,0,0,0,0,0,0,0,0,0,0}; -int GQHnPt[4] = {1,1,6,8}; +IntPt *GQH[17] = {GQH1, GQH1, GQH6, GQH8, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; +int GQHnPt[4] = {1, 1, 6, 8}; IntPt *getGQHPts(int order) { @@ -70,23 +58,23 @@ IntPt *getGQHPts(int order) if(order == 2) return GQH[3]; if(order == 3) return GQH[3]; int n = (order + 1) / (float)2 + 0.5; - int index = n-2 + 4; - if(index >= (int)(sizeof(GQH) / sizeof(IntPt*))){ + int index = n - 2 + 4; + if(index >= (int)(sizeof(GQH) / sizeof(IntPt *))) { Msg::Error("Increase size of GQH in gauss quadrature hex"); index = 0; } - if(!GQH[index]){ - double *pt,*wt; - gmshGaussLegendre1D(n,&pt,&wt); - GQH[index] = new IntPt[n*n*n]; + if(!GQH[index]) { + double *pt, *wt; + gmshGaussLegendre1D(n, &pt, &wt); + GQH[index] = new IntPt[n * n * n]; int l = 0; - for(int i=0; i < n; i++) { - for(int j=0; j < n; j++) { - for(int k=0; k < n; k++) { + for(int i = 0; i < n; i++) { + for(int j = 0; j < n; j++) { + for(int k = 0; k < n; k++) { GQH[index][l].pt[0] = pt[i]; GQH[index][l].pt[1] = pt[j]; GQH[index][l].pt[2] = pt[k]; - GQH[index][l++].weight = wt[i]*wt[j]*wt[k]; + GQH[index][l++].weight = wt[i] * wt[j] * wt[k]; } } } @@ -96,10 +84,9 @@ IntPt *getGQHPts(int order) int getNGQHPts(int order) { - if(order == 3)return 8; - if(order == 2)return 8; - if(order < 2) - return GQHnPt[order]; + if(order == 3) return 8; + if(order == 2) return 8; + if(order < 2) return GQHnPt[order]; int n = (order + 1) / (float)2 + 0.5; return n * n * n; } diff --git a/Numeric/GaussQuadratureLin.cpp b/Numeric/GaussQuadratureLin.cpp index e3cdaa4f8802cfc84377bed52d9c1bcb7f32ee91..c1ccd740c3f13ca4fe8e59d850ddea07188674d8 100644 --- a/Numeric/GaussQuadratureLin.cpp +++ b/Numeric/GaussQuadratureLin.cpp @@ -6,7 +6,7 @@ #include "GaussIntegration.h" #include "GaussLegendre1D.h" -IntPt * GQL[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +IntPt *GQL[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; IntPt *getGQLPts(int order) { @@ -14,15 +14,15 @@ IntPt *getGQLPts(int order) // (order + 1) / 2 *ROUNDED UP* int n = (order + 1) / (double)2 + 0.5; int index = n; - if(index >= (int)(sizeof(GQL) / sizeof(IntPt*))){ + if(index >= (int)(sizeof(GQL) / sizeof(IntPt *))) { Msg::Error("Increase size of GQL in gauss quadrature line"); index = 0; } if(!GQL[index]) { - double *pt,*wt; - gmshGaussLegendre1D(n,&pt,&wt); + double *pt, *wt; + gmshGaussLegendre1D(n, &pt, &wt); GQL[index] = new IntPt[n]; - for(int i=0; i < n; i++) { + for(int i = 0; i < n; i++) { GQL[index][i].pt[0] = pt[i]; GQL[index][i].pt[1] = 0.0; GQL[index][i].pt[2] = 0.0; @@ -32,7 +32,4 @@ IntPt *getGQLPts(int order) return GQL[index]; } -int getNGQLPts(int order) -{ - return (order + 1) / (double)2 + 0.5; -} +int getNGQLPts(int order) { return (order + 1) / (double)2 + 0.5; } diff --git a/Numeric/GaussQuadraturePri.cpp b/Numeric/GaussQuadraturePri.cpp index b6f8652ab0c3c9e29f46fefcb251681e299c017d..4f5c1b8220e0f5c7b8d9b2b7c20b00215448bf45 100644 --- a/Numeric/GaussQuadraturePri.cpp +++ b/Numeric/GaussQuadraturePri.cpp @@ -10,31 +10,32 @@ IntPt *getGQPriPts(int order); int getNGQPriPts(int order); -IntPt * GQP[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +IntPt *GQP[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; IntPt *getGQPriPts(int order) { - int nLin = (order+3)/2; + int nLin = (order + 3) / 2; int nTri = getNGQTPts(order); - int n = nLin*nTri; + int n = nLin * nTri; int index = order; - if (index >= (int)(sizeof(GQP) / sizeof(IntPt*))){ + if(index >= (int)(sizeof(GQP) / sizeof(IntPt *))) { Msg::Error("Increase size of GQP in gauss quadrature prism"); index = 0; } - if(!GQP[index]){ - double *linPt,*linWt; + if(!GQP[index]) { + double *linPt, *linWt; IntPt *triPts = getGQTPts(order); - gmshGaussLegendre1D(nLin,&linPt,&linWt); + gmshGaussLegendre1D(nLin, &linPt, &linWt); GQP[index] = new IntPt[n]; int l = 0; - for(int i=0; i < nTri; i++) { - for(int j=0; j < nLin; j++) { + for(int i = 0; i < nTri; i++) { + for(int j = 0; j < nLin; j++) { GQP[index][l].pt[0] = triPts[i].pt[0]; GQP[index][l].pt[1] = triPts[i].pt[1]; GQP[index][l].pt[2] = linPt[j]; - GQP[index][l++].weight = triPts[i].weight*linWt[j]; + GQP[index][l++].weight = triPts[i].weight * linWt[j]; } } } @@ -43,13 +44,13 @@ IntPt *getGQPriPts(int order) int getNGQPriPts(int order) { - int nLin = (order+3)/2; + int nLin = (order + 3) / 2; int nTri = getNGQTPts(order); return nLin * nTri; -// if(order == 3)return 8; -// if(order == 2)return 8; -// if(order < 2) -// return GQPnPt[order]; -// return ((order+3)/2)*((order+3)/2)*((order+3)/2); + // if(order == 3)return 8; + // if(order == 2)return 8; + // if(order < 2) + // return GQPnPt[order]; + // return ((order+3)/2)*((order+3)/2)*((order+3)/2); } diff --git a/Numeric/GaussQuadraturePyr.cpp b/Numeric/GaussQuadraturePyr.cpp index 4776d7dcaffe86bfa4520680ab0abf301d9bc374..54c7e3193fa29484fb83692178cd70798732d72e 100644 --- a/Numeric/GaussQuadraturePyr.cpp +++ b/Numeric/GaussQuadraturePyr.cpp @@ -11,26 +11,26 @@ IntPt *getGQPyrPts(int order); int getNGQPyrPts(int order); -IntPt * GQPyr[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +IntPt *GQPyr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; IntPt *getGQPyrPts(int order) { int index = order; - if(index >= (int)(sizeof(GQPyr) / sizeof(IntPt*))){ + if(index >= (int)(sizeof(GQPyr) / sizeof(IntPt *))) { Msg::Error("Increase size of GQPyr in gauss quadrature pyr"); index = 0; } if(!GQPyr[index]) { - - int nbPtUV = order/2 + 1; - int nbPtW = order/2 + 1; + int nbPtUV = order / 2 + 1; + int nbPtW = order / 2 + 1; int nbPtUV2 = nbPtUV * nbPtUV; - double *linPt,*linWt; - gmshGaussLegendre1D(nbPtUV,&linPt,&linWt); + double *linPt, *linWt; + gmshGaussLegendre1D(nbPtUV, &linPt, &linWt); double *GJ20Pt, *GJ20Wt; getGaussJacobiQuadrature(2, 0, nbPtW, &GJ20Pt, &GJ20Wt); @@ -38,15 +38,15 @@ IntPt *getGQPyrPts(int order) GQPyr[index] = new IntPt[getNGQPyrPts(order)]; int l = 0; - for (int i = 0; i < getNGQPyrPts(order); i++) { - - // compose an integration rule for (1-w)^2 f(u,v,w) on the standard hexahedron + for(int i = 0; i < getNGQPyrPts(order); i++) { + // compose an integration rule for (1-w)^2 f(u,v,w) on the standard + // hexahedron int iW = i / (nbPtUV2); - int iU = (i - iW*nbPtUV2)/nbPtUV; - int iV = (i - iW*nbPtUV2 - iU*nbPtUV); + int iU = (i - iW * nbPtUV2) / nbPtUV; + int iV = (i - iW * nbPtUV2 - iU * nbPtUV); - double wt = linWt[iU]*linWt[iV]*GJ20Wt[iW]; + double wt = linWt[iU] * linWt[iV] * GJ20Wt[iW]; double up = linPt[iU]; double vp = linPt[iV]; @@ -54,24 +54,21 @@ IntPt *getGQPyrPts(int order) // now incorporate the Duffy transformation from pyramid to hexahedron - GQPyr[index][l].pt[0] = 0.5*(1-wp)*up; - GQPyr[index][l].pt[1] = 0.5*(1-wp)*vp; - GQPyr[index][l].pt[2] = 0.5*(1+wp); + GQPyr[index][l].pt[0] = 0.5 * (1 - wp) * up; + GQPyr[index][l].pt[1] = 0.5 * (1 - wp) * vp; + GQPyr[index][l].pt[2] = 0.5 * (1 + wp); wt *= 0.125; - GQPyr[index][l++].weight = wt *4./3.; - + GQPyr[index][l++].weight = wt * 4. / 3.; } - } return GQPyr[index]; } - int getNGQPyrPts(int order) { - int nbPtUV = order/2 + 1; - int nbPtW = order/2 + 1; + int nbPtUV = order / 2 + 1; + int nbPtW = order / 2 + 1; - return nbPtUV*nbPtUV*nbPtW; + return nbPtUV * nbPtUV * nbPtW; } diff --git a/Numeric/GaussQuadratureQuad.cpp b/Numeric/GaussQuadratureQuad.cpp index 30cc437856a5ad30191fd9eb0048fd05e7ba21a4..ebe55d6c73a9ed2096f9d74b38230fcfcce64c71 100644 --- a/Numeric/GaussQuadratureQuad.cpp +++ b/Numeric/GaussQuadratureQuad.cpp @@ -6,106 +6,100 @@ #include "GaussIntegration.h" #include "GaussLegendre1D.h" -IntPt GQQ1[1] = { - { {0.0,0.0,0.0},4.0 } -}; +IntPt GQQ1[1] = {{{0.0, 0.0, 0.0}, 4.0}}; -const double xq3[3] = {0.816496580928,-0.408248290464,-0.408248290464}; -const double yq3[3] = {0.0,0.840896415255,-0.840896415255}; -const double pq3[3] = {1.3333333333333,1.3333333333333,1.3333333333333}; -IntPt GQQ3[3] = { - { {xq3[0],yq3[0],0},pq3[0] }, - { {xq3[1],yq3[1],0},pq3[1] }, - { {xq3[2],yq3[2],0},pq3[2] } -}; +const double xq3[3] = {0.816496580928, -0.408248290464, -0.408248290464}; +const double yq3[3] = {0.0, 0.840896415255, -0.840896415255}; +const double pq3[3] = {1.3333333333333, 1.3333333333333, 1.3333333333333}; +IntPt GQQ3[3] = {{{xq3[0], yq3[0], 0}, pq3[0]}, + {{xq3[1], yq3[1], 0}, pq3[1]}, + {{xq3[2], yq3[2], 0}, pq3[2]}}; -const double xq4[4] = {0.577350269189626,-0.577350269189626,0.577350269189626,-0.577350269189626}; -const double yq4[4] = {0.577350269189626,0.577350269189626,-0.577350269189626,-0.577350269189626}; -const double pq4[4] = {1.,1.,1.,1.}; +const double xq4[4] = {0.577350269189626, -0.577350269189626, 0.577350269189626, + -0.577350269189626}; +const double yq4[4] = {0.577350269189626, 0.577350269189626, -0.577350269189626, + -0.577350269189626}; +const double pq4[4] = {1., 1., 1., 1.}; IntPt GQQ4[4] = { - { {xq4[0],yq4[0],0},pq4[0] }, - { {xq4[1],yq4[1],0},pq4[1] }, - { {xq4[2],yq4[2],0},pq4[2] }, - { {xq4[3],yq4[3],0},pq4[3] }, + {{xq4[0], yq4[0], 0}, pq4[0]}, + {{xq4[1], yq4[1], 0}, pq4[1]}, + {{xq4[2], yq4[2], 0}, pq4[2]}, + {{xq4[3], yq4[3], 0}, pq4[3]}, }; -// WARNING: It seems that there is a problem with the values with 7 integration points ! Geuzaine (16/06/2016) - -const double pq7[7] = {1.142857142857,0.595238095238,0.595238095238, - 0.416666666666,0.416666666666,0.416666666666,0.416666666666}; -const double xq7[7] = {0.0,-0.683130051064,0.683130051064,0.890654421782, - -0.890654421782,0.374256642286,-0.374256642286}; -const double yq7[7] = {0.0,-0.683130051064,0.683130051064,-0.374256642286,0.374256642286, - -0.890654421782,0.890654421782,}; -IntPt GQQ7[7] = { - { {xq7[0],yq7[0],0},pq7[0] }, - { {xq7[1],yq7[1],0},pq7[1] }, - { {xq7[2],yq7[2],0},pq7[2] }, - { {xq7[3],yq7[3],0},pq7[3] }, - { {xq7[4],yq7[4],0},pq7[4] }, - { {xq7[5],yq7[5],0},pq7[5] }, - { {xq7[6],yq7[6],0},pq7[6] } +// WARNING: It seems that there is a problem with the values with 7 integration +// points ! Geuzaine (16/06/2016) + +const double pq7[7] = {1.142857142857, 0.595238095238, 0.595238095238, + 0.416666666666, 0.416666666666, 0.416666666666, + 0.416666666666}; +const double xq7[7] = {0.0, + -0.683130051064, + 0.683130051064, + 0.890654421782, + -0.890654421782, + 0.374256642286, + -0.374256642286}; +const double yq7[7] = { + 0.0, + -0.683130051064, + 0.683130051064, + -0.374256642286, + 0.374256642286, + -0.890654421782, + 0.890654421782, }; +IntPt GQQ7[7] = {{{xq7[0], yq7[0], 0}, pq7[0]}, {{xq7[1], yq7[1], 0}, pq7[1]}, + {{xq7[2], yq7[2], 0}, pq7[2]}, {{xq7[3], yq7[3], 0}, pq7[3]}, + {{xq7[4], yq7[4], 0}, pq7[4]}, {{xq7[5], yq7[5], 0}, pq7[5]}, + {{xq7[6], yq7[6], 0}, pq7[6]}}; const double a9 = 0.774596669241483; const double z = 0.0; const double xq9[9] = {-a9, z, a9, -a9, z, a9, -a9, z, a9}; const double yq9[9] = {-a9, -a9, -a9, z, z, z, a9, a9, a9}; -const double pb2 = 0.888888888888889*0.888888888888889; -const double pc2 = 0.555555555555556*0.555555555555556; -const double pbc = 0.555555555555556*0.888888888888889; -const double pq9[9] = {pc2, pbc, pc2, pbc, pb2, pbc, pc2, pbc , pc2}; - -IntPt GQQ9[9] = { - { {xq9[0],yq9[0],0},pq9[0] }, - { {xq9[1],yq9[1],0},pq9[1] }, - { {xq9[2],yq9[2],0},pq9[2] }, - { {xq9[3],yq9[3],0},pq9[3] }, - { {xq9[4],yq9[4],0},pq9[4] }, - { {xq9[5],yq9[5],0},pq9[5] }, - { {xq9[6],yq9[6],0},pq9[6] }, - { {xq9[7],yq9[7],0},pq9[7] }, - { {xq9[8],yq9[8],0},pq9[8] } -}; +const double pb2 = 0.888888888888889 * 0.888888888888889; +const double pc2 = 0.555555555555556 * 0.555555555555556; +const double pbc = 0.555555555555556 * 0.888888888888889; +const double pq9[9] = {pc2, pbc, pc2, pbc, pb2, pbc, pc2, pbc, pc2}; + +IntPt GQQ9[9] = {{{xq9[0], yq9[0], 0}, pq9[0]}, {{xq9[1], yq9[1], 0}, pq9[1]}, + {{xq9[2], yq9[2], 0}, pq9[2]}, {{xq9[3], yq9[3], 0}, pq9[3]}, + {{xq9[4], yq9[4], 0}, pq9[4]}, {{xq9[5], yq9[5], 0}, pq9[5]}, + {{xq9[6], yq9[6], 0}, pq9[6]}, {{xq9[7], yq9[7], 0}, pq9[7]}, + {{xq9[8], yq9[8], 0}, pq9[8]}}; const double a16 = 0.861136311594053; const double b16 = 0.339981043584856; const double xq16[16] = {-a16, -b16, b16, a16, -a16, -b16, b16, a16, - -a16, -b16, b16, a16, -a16, -b16, b16, a16}; + -a16, -b16, b16, a16, -a16, -b16, b16, a16}; const double yq16[16] = {-a16, -a16, -a16, -a16, -b16, -b16, -b16, -b16, - b16, b16, b16, b16, a16, a16, a16, a16}; + b16, b16, b16, b16, a16, a16, a16, a16}; const double pe2 = 0.347854845137454 * 0.347854845137454; const double pf2 = 0.652145154862546 * 0.652145154862546; const double pef = 0.347854845137454 * 0.652145154862546; -double pq16[16] = { pe2, pef, pef, pe2, pef, pf2, pf2, pef, - pef, pf2, pf2, pef, pe2, pef, pef, pe2}; +double pq16[16] = {pe2, pef, pef, pe2, pef, pf2, pf2, pef, + pef, pf2, pf2, pef, pe2, pef, pef, pe2}; IntPt GQQ16[16] = { - { {xq16[0],yq16[0],0},pq16[0] }, - { {xq16[1],yq16[1],0},pq16[1] }, - { {xq16[2],yq16[2],0},pq16[2] }, - { {xq16[3],yq16[3],0},pq16[3] }, - { {xq16[4],yq16[4],0},pq16[4] }, - { {xq16[5],yq16[5],0},pq16[5] }, - { {xq16[6],yq16[6],0},pq16[6] }, - { {xq16[7],yq16[7],0},pq16[7] }, - { {xq16[8],yq16[8],0},pq16[8] }, - { {xq16[9],yq16[9],0},pq16[9] }, - { {xq16[10],yq16[10],0},pq16[10] }, - { {xq16[11],yq16[11],0},pq16[11] }, - { {xq16[12],yq16[12],0},pq16[12] }, - { {xq16[13],yq16[13],0},pq16[13] }, - { {xq16[14],yq16[14],0},pq16[14] }, - { {xq16[15],yq16[15],0},pq16[15] } -}; + {{xq16[0], yq16[0], 0}, pq16[0]}, {{xq16[1], yq16[1], 0}, pq16[1]}, + {{xq16[2], yq16[2], 0}, pq16[2]}, {{xq16[3], yq16[3], 0}, pq16[3]}, + {{xq16[4], yq16[4], 0}, pq16[4]}, {{xq16[5], yq16[5], 0}, pq16[5]}, + {{xq16[6], yq16[6], 0}, pq16[6]}, {{xq16[7], yq16[7], 0}, pq16[7]}, + {{xq16[8], yq16[8], 0}, pq16[8]}, {{xq16[9], yq16[9], 0}, pq16[9]}, + {{xq16[10], yq16[10], 0}, pq16[10]}, {{xq16[11], yq16[11], 0}, pq16[11]}, + {{xq16[12], yq16[12], 0}, pq16[12]}, {{xq16[13], yq16[13], 0}, pq16[13]}, + {{xq16[14], yq16[14], 0}, pq16[14]}, {{xq16[15], yq16[15], 0}, pq16[15]}}; IntPt *getGQQPts(int order); int getNGQQPts(int order); -IntPt * GQQ[27] = {GQQ1,GQQ1,GQQ3,GQQ4,GQQ7,GQQ9,GQQ16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -int GQQnPt[7] = {1,1,3,4,7,9,16}; +IntPt *GQQ[27] = {GQQ1, GQQ1, GQQ3, GQQ4, GQQ7, GQQ9, GQQ16, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0}; +int GQQnPt[7] = {1, 1, 3, 4, 7, 9, 16}; IntPt *getGQQPts(int order) { @@ -113,22 +107,22 @@ IntPt *getGQQPts(int order) if(order == 2) return GQQ[3]; if(order == 3) return GQQ[3]; int n = (order + 1) / (float)2 + 0.5; - int index = n-2 + 7; - if(index >= (int)(sizeof(GQQ) / sizeof(IntPt*))){ + int index = n - 2 + 7; + if(index >= (int)(sizeof(GQQ) / sizeof(IntPt *))) { Msg::Error("Increase size of GQQ in gauss quadrature quad"); index = 0; } - if(!GQQ[index]){ - double *pt,*wt; - gmshGaussLegendre1D(n,&pt,&wt); - GQQ[index] = new IntPt[n*n]; + if(!GQQ[index]) { + double *pt, *wt; + gmshGaussLegendre1D(n, &pt, &wt); + GQQ[index] = new IntPt[n * n]; int k = 0; - for(int i=0; i < n; i++) { - for(int j=0; j < n; j++) { + for(int i = 0; i < n; i++) { + for(int j = 0; j < n; j++) { GQQ[index][k].pt[0] = pt[i]; GQQ[index][k].pt[1] = pt[j]; GQQ[index][k].pt[2] = 0.0; - GQQ[index][k++].weight = wt[i]*wt[j]; + GQQ[index][k++].weight = wt[i] * wt[j]; } } } @@ -139,8 +133,7 @@ int getNGQQPts(int order) { if(order == 3) return 4; if(order == 2) return 4; - if(order < 2) - return GQQnPt[order]; + if(order < 2) return GQQnPt[order]; int n = (order + 1) / (float)2 + 0.5; return n * n; } diff --git a/Numeric/GaussQuadratureTet.cpp b/Numeric/GaussQuadratureTet.cpp index b1fcc2ce5dbb2d6c091e49524029e35c782c36b2..f3e641be34b2ca3b141fb99366265457f7260b16 100644 --- a/Numeric/GaussQuadratureTet.cpp +++ b/Numeric/GaussQuadratureTet.cpp @@ -7,150 +7,99 @@ #include "GaussLegendre1D.h" /* constants for 4-point rule */ -#define a4 0.5854101966249685 -#define b4 0.138196601125015 +#define a4 0.5854101966249685 +#define b4 0.138196601125015 /* constants for 5-point rule */ -#define a5 0.500000000000000 -#define b5 0.166666666666667 +#define a5 0.500000000000000 +#define b5 0.166666666666667 /* constants for 16-point rule */ -#define a16 0.00839563235002047 -#define b16 0.0110903447722154 -#define c16 0.7716429020672371 -#define d16 0.0761190326442543 -#define e16 0.1197005277978019 -#define f16 0.0718316452676693 -#define g16 0.4042339134672644 +#define a16 0.00839563235002047 +#define b16 0.0110903447722154 +#define c16 0.7716429020672371 +#define d16 0.0761190326442543 +#define e16 0.1197005277978019 +#define f16 0.0718316452676693 +#define g16 0.4042339134672644 /* constants for 17-point rule */ -#define a17 0.0314030927894235 -#define b17 0.0111730972876738 -#define c17 0.00754759872721232 -#define p17 0.7316369079576180 -#define q17 0.0894543640141273 -#define e17 0.1325810999384657 -#define f17 0.0245400397290300 -#define g17 0.4214394310662522 +#define a17 0.0314030927894235 +#define b17 0.0111730972876738 +#define c17 0.00754759872721232 +#define p17 0.7316369079576180 +#define q17 0.0894543640141273 +#define e17 0.1325810999384657 +#define f17 0.0245400397290300 +#define g17 0.4214394310662522 /* constants for 29-point rule */ -#define a29 0.0150668817433579 -#define b29 0.00318663904649853 -#define c29 0.00726915640111095 -#define d29 0.00430194599366527 -#define p29 0.8277192480479295 -#define q29 0.0574269173173568 -#define e29 0.0513518841255634 -#define f29 0.4860510285706072 -#define g29 0.2312985436519147 -#define h29 0.2967538129690260 -#define i29 0.6081079894015281 -#define j29 0.0475690988147229 - -IntPt GQTet1[1] = { - {{.25, .25, .25}, 0.166666666666667} -}; - -IntPt GQTet2[4] = { - { {a4, b4, b4}, 0.0416666666666667}, - { {b4, a4, b4}, 0.0416666666666667}, - { {b4, b4, a4}, 0.0416666666666667}, - { {b4, b4, b4}, 0.0416666666666667} -}; - -IntPt GQTet3[5] = { - {{0.25, 0.25, 0.25}, -0.133333333333333}, - {{a5, b5, b5}, 0.075}, - {{b5, a5, b5}, 0.075}, - {{b5, b5, a5}, 0.075}, - {{b5, b5, b5}, 0.075} -}; +#define a29 0.0150668817433579 +#define b29 0.00318663904649853 +#define c29 0.00726915640111095 +#define d29 0.00430194599366527 +#define p29 0.8277192480479295 +#define q29 0.0574269173173568 +#define e29 0.0513518841255634 +#define f29 0.4860510285706072 +#define g29 0.2312985436519147 +#define h29 0.2967538129690260 +#define i29 0.6081079894015281 +#define j29 0.0475690988147229 + +IntPt GQTet1[1] = {{{.25, .25, .25}, 0.166666666666667}}; + +IntPt GQTet2[4] = {{{a4, b4, b4}, 0.0416666666666667}, + {{b4, a4, b4}, 0.0416666666666667}, + {{b4, b4, a4}, 0.0416666666666667}, + {{b4, b4, b4}, 0.0416666666666667}}; + +IntPt GQTet3[5] = {{{0.25, 0.25, 0.25}, -0.133333333333333}, + {{a5, b5, b5}, 0.075}, + {{b5, a5, b5}, 0.075}, + {{b5, b5, a5}, 0.075}, + {{b5, b5, b5}, 0.075}}; IntPt GQTet4[16] = { - {{c16, d16, d16}, a16}, - {{d16, c16, d16}, a16}, - {{d16, d16, c16}, a16}, - {{d16, d16, d16}, a16}, - {{e16, f16, g16}, b16}, - {{f16, e16, g16}, b16}, - {{e16, g16, g16}, b16}, - {{f16, g16, g16}, b16}, - {{g16, g16, e16}, b16}, - {{g16, g16, f16}, b16}, - {{g16, e16, f16}, b16}, - {{g16, f16, e16}, b16}, - {{e16, g16, f16}, b16}, - {{f16, g16, e16}, b16}, - {{g16, e16, g16}, b16}, - {{g16, f16, g16}, b16} -}; + {{c16, d16, d16}, a16}, {{d16, c16, d16}, a16}, {{d16, d16, c16}, a16}, + {{d16, d16, d16}, a16}, {{e16, f16, g16}, b16}, {{f16, e16, g16}, b16}, + {{e16, g16, g16}, b16}, {{f16, g16, g16}, b16}, {{g16, g16, e16}, b16}, + {{g16, g16, f16}, b16}, {{g16, e16, f16}, b16}, {{g16, f16, e16}, b16}, + {{e16, g16, f16}, b16}, {{f16, g16, e16}, b16}, {{g16, e16, g16}, b16}, + {{g16, f16, g16}, b16}}; IntPt GQTet5[17] = { - {{0.25, 0.25, 0.25}, a17}, - {{p17, q17, q17}, b17}, - {{q17, p17, q17}, b17}, - {{q17, q17, p17}, b17}, - {{q17, q17, q17}, b17}, - {{e17, f17, g17}, c17}, - {{f17, e17, g17}, c17}, - {{e17, g17, g17}, c17}, - {{f17, g17, g17}, c17}, - {{g17, g17, e17}, c17}, - {{g17, g17, f17}, c17}, - {{g17, e17, f17}, c17}, - {{g17, f17, e17}, c17}, - {{e17, g17, f17}, c17}, - {{f17, g17, e17}, c17}, - {{g17, e17, g17}, c17}, - {{g17, f17, g17}, c17} -}; + {{0.25, 0.25, 0.25}, a17}, {{p17, q17, q17}, b17}, {{q17, p17, q17}, b17}, + {{q17, q17, p17}, b17}, {{q17, q17, q17}, b17}, {{e17, f17, g17}, c17}, + {{f17, e17, g17}, c17}, {{e17, g17, g17}, c17}, {{f17, g17, g17}, c17}, + {{g17, g17, e17}, c17}, {{g17, g17, f17}, c17}, {{g17, e17, f17}, c17}, + {{g17, f17, e17}, c17}, {{e17, g17, f17}, c17}, {{f17, g17, e17}, c17}, + {{g17, e17, g17}, c17}, {{g17, f17, g17}, c17}}; IntPt GQTet6[29] = { - {{0.25, 0.25, 0.25}, a29}, - {{p29, q29, q29}, b29}, - {{q29, p29, q29}, b29}, - {{q29, q29, p29}, b29}, - {{q29, q29, q29}, b29}, - {{e29, f29, g29}, c29}, - {{f29, e29, g29}, c29}, - {{e29, g29, g29}, c29}, - {{f29, g29, g29}, c29}, - {{g29, g29, e29}, c29}, - {{g29, g29, f29}, c29}, - {{g29, e29, f29}, c29}, - {{g29, f29, e29}, c29}, - {{e29, g29, f29}, c29}, - {{f29, g29, e29}, c29}, - {{g29, e29, g29}, c29}, - {{g29, f29, g29}, c29}, - {{h29, i29, j29}, d29}, - {{i29, h29, j29}, d29}, - {{h29, j29, j29}, d29}, - {{i29, j29, j29}, d29}, - {{j29, j29, h29}, d29}, - {{j29, j29, i29}, d29}, - {{j29, h29, i29}, d29}, - {{j29, i29, h29}, d29}, - {{h29, j29, i29}, d29}, - {{i29, j29, h29}, d29}, - {{j29, h29, j29}, d29}, - {{j29, i29, j29}, d29} -}; - - -IntPt * GQTet[7] = {GQTet1,GQTet1,GQTet2,GQTet3,GQTet4,GQTet5,GQTet6}; -IntPt * GQTetDegen[17] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -int GQTetnPt[7] = {1,1,4,5,16,17,29}; + {{0.25, 0.25, 0.25}, a29}, {{p29, q29, q29}, b29}, {{q29, p29, q29}, b29}, + {{q29, q29, p29}, b29}, {{q29, q29, q29}, b29}, {{e29, f29, g29}, c29}, + {{f29, e29, g29}, c29}, {{e29, g29, g29}, c29}, {{f29, g29, g29}, c29}, + {{g29, g29, e29}, c29}, {{g29, g29, f29}, c29}, {{g29, e29, f29}, c29}, + {{g29, f29, e29}, c29}, {{e29, g29, f29}, c29}, {{f29, g29, e29}, c29}, + {{g29, e29, g29}, c29}, {{g29, f29, g29}, c29}, {{h29, i29, j29}, d29}, + {{i29, h29, j29}, d29}, {{h29, j29, j29}, d29}, {{i29, j29, j29}, d29}, + {{j29, j29, h29}, d29}, {{j29, j29, i29}, d29}, {{j29, h29, i29}, d29}, + {{j29, i29, h29}, d29}, {{h29, j29, i29}, d29}, {{i29, j29, h29}, d29}, + {{j29, h29, j29}, d29}, {{j29, i29, j29}, d29}}; + +IntPt *GQTet[7] = {GQTet1, GQTet1, GQTet2, GQTet3, GQTet4, GQTet5, GQTet6}; +IntPt *GQTetDegen[17] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +int GQTetnPt[7] = {1, 1, 4, 5, 16, 17, 29}; // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 1 on the tetrahedron */ /* 'Higher-order Finite Elements', P.Solin, K.Segeth and I. Dolezel */ -IntPt tetP1Solin[1] = { - {{0.25, 0.25, 0.25}, 0.166666666666667} -}; +IntPt tetP1Solin[1] = {{{0.25, 0.25, 0.25}, 0.166666666666667}}; -// 0 negative weights, 0 points outside of the tetrahedron, total sum of the weights is 1/6 +// 0 negative weights, 0 points outside of the tetrahedron, total sum of the +// weights is 1/6 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 2 on the tetrahedron */ @@ -160,10 +109,10 @@ IntPt tetP2Solin[4] = { {{0.138196601125, 0.138196601125, 0.138196601125}, 0.0416666666666667}, {{0.585410196625, 0.138196601125, 0.138196601125}, 0.0416666666666667}, {{0.138196601125, 0.585410196625, 0.138196601125}, 0.0416666666666667}, - {{0.138196601125, 0.138196601125, 0.585410196625}, 0.0416666666666667} -}; + {{0.138196601125, 0.138196601125, 0.585410196625}, 0.0416666666666667}}; -// 0 negative weights, 0 points outside of the tetrahedron, total sum of the weights is 1/6 +// 0 negative weights, 0 points outside of the tetrahedron, total sum of the +// weights is 1/6 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 3 on the tetrahedron */ @@ -174,10 +123,10 @@ IntPt tetP3Solin[5] = { {{0.166666666667, 0.166666666667, 0.166666666667}, +0.075000000000000}, {{0.166666666667, 0.166666666667, 0.500000000000}, +0.075000000000000}, {{0.166666666667, 0.500000000000, 0.166666666667}, +0.075000000000000}, - {{0.500000000000, 0.166666666667, 0.166666666667}, +0.075000000000000} -}; + {{0.500000000000, 0.166666666667, 0.166666666667}, +0.075000000000000}}; -// 1 negative weights, 0 points outside of the tetrahedron, total sum of the weights is 1/6 +// 1 negative weights, 0 points outside of the tetrahedron, total sum of the +// weights is 1/6 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 4 on the tetrahedron */ @@ -194,11 +143,10 @@ IntPt tetP4Solin[11] = { {{0.1005964238330, 0.3994035761670, 0.3994035761670}, +0.0248888888888}, {{0.3994035761670, 0.1005964238330, 0.1005964238330}, +0.0248888888888}, {{0.1005964238330, 0.3994035761670, 0.1005964238330}, +0.0248888888888}, - {{0.1005964238330, 0.1005964238330, 0.3994035761670}, +0.0248888888888} -}; - -// 1 negative weights, 0 points outside of the tetrahedron, total sum of the weights is 1/6 + {{0.1005964238330, 0.1005964238330, 0.3994035761670}, +0.0248888888888}}; +// 1 negative weights, 0 points outside of the tetrahedron, total sum of the +// weights is 1/6 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 5 on the tetrahedron */ @@ -218,11 +166,10 @@ IntPt tetP5Solin[14] = { {{0.0455037041256, 0.4544962958740, 0.4544962958740}, 0.00709100346285}, {{0.4544962958740, 0.0455037041256, 0.0455037041256}, 0.00709100346285}, {{0.0455037041256, 0.4544962958740, 0.0455037041256}, 0.00709100346285}, - {{0.0455037041256, 0.0455037041256, 0.4544962958740}, 0.00709100346285} -}; - -// 0 negative weights, 0 points outside of the tetrahedron, total sum of the weights is 1 + {{0.0455037041256, 0.0455037041256, 0.4544962958740}, 0.00709100346285}}; +// 0 negative weights, 0 points outside of the tetrahedron, total sum of the +// weights is 1 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 6 on the tetrahedron */ @@ -252,11 +199,10 @@ IntPt tetP6Solin[24] = { {{0.2696723314580, 0.6030056647920, 0.0636610018750}, 0.008035714285717}, {{0.6030056647920, 0.0636610018750, 0.2696723314580}, 0.008035714285717}, {{0.6030056647920, 0.0636610018750, 0.0636610018750}, 0.008035714285717}, - {{0.6030056647920, 0.2696723314580, 0.0636610018750}, 0.008035714285717} -}; - -// 0 negative weights, 0 points outside of the tetrahedron, total sum of the weights is 1 + {{0.6030056647920, 0.2696723314580, 0.0636610018750}, 0.008035714285717}}; +// 0 negative weights, 0 points outside of the tetrahedron, total sum of the +// weights is 1 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 7 on the tetrahedron */ @@ -293,11 +239,9 @@ IntPt tetP7Solin[31] = { {{0.20000000000000, 0.60000000000000, 0.10000000000000}, +0.027557319224000}, {{0.60000000000000, 0.10000000000000, 0.20000000000000}, +0.027557319224000}, {{0.60000000000000, 0.10000000000000, 0.10000000000000}, +0.027557319224000}, - {{0.60000000000000, 0.20000000000000, 0.10000000000000}, +0.027557319224000} -}; - -// 4 negative weights, 0 points outside of the tetrahedron + {{0.60000000000000, 0.20000000000000, 0.10000000000000}, +0.027557319224000}}; +// 4 negative weights, 0 points outside of the tetrahedron // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 8 on the tetrahedron */ @@ -346,74 +290,123 @@ IntPt tetP8Solin[43] = { {{0.1904860419350, 0.7362984589590, 0.0366077495532}, +0.002140519141167}, {{0.7362984589590, 0.0366077495532, 0.1904860419350}, +0.002140519141167}, {{0.7362984589590, 0.0366077495532, 0.0366077495532}, +0.002140519141167}, - {{0.7362984589590, 0.1904860419350, 0.0366077495532}, +0.002140519141167} -}; - -// 1 negative weights, 0 points outside of the tetrahedron + {{0.7362984589590, 0.1904860419350, 0.0366077495532}, +0.002140519141167}}; +// 1 negative weights, 0 points outside of the tetrahedron // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 9 on the tetrahedron */ /* 'Higher-order Finite Elements', P.Solin, K.Segeth and I. Dolezel */ IntPt tetP9Solin[53] = { - {{+0.25000000000000, +0.25000000000000, +0.25000000000000}, -0.137799038326167}, - {{+0.04835103854970, +0.04835103854970, +0.04835103854970}, +0.001865336569083}, - {{+0.04835103854970, +0.04835103854970, +0.85494688435100}, +0.001865336569083}, - {{+0.04835103854970, +0.85494688435100, +0.04835103854970}, +0.001865336569083}, - {{+0.85494688435100, +0.04835103854970, +0.04835103854970}, +0.001865336569083}, - {{+0.32457928011800, +0.32457928011800, +0.32457928011800}, +0.004309423969500}, - {{+0.32457928011800, +0.32457928011800, +0.02626215964640}, +0.004309423969500}, - {{+0.32457928011800, +0.02626215964640, +0.32457928011800}, +0.004309423969500}, - {{+0.02626215964640, +0.32457928011800, +0.32457928011800}, +0.004309423969500}, - {{+0.11461654022400, +0.11461654022400, +0.11461654022400}, -0.090184766481167}, - {{+0.11461654022400, +0.11461654022400, +0.65615037932800}, -0.090184766481167}, - {{+0.11461654022400, +0.65615037932800, +0.11461654022400}, -0.090184766481167}, - {{+0.65615037932800, +0.11461654022400, +0.11461654022400}, -0.090184766481167}, - {{+0.22548995191200, +0.22548995191200, +0.22548995191200}, +0.044672576202500}, - {{+0.22548995191200, +0.22548995191200, +0.32353014426500}, +0.044672576202500}, - {{+0.22548995191200, +0.32353014426500, +0.22548995191200}, +0.044672576202500}, - {{+0.32353014426500, +0.22548995191200, +0.22548995191200}, +0.044672576202500}, - {{+0.13162780924700, +0.13162780924700, +0.08366470161720}, +0.034700405884500}, - {{+0.13162780924700, +0.08366470161720, +0.13162780924700}, +0.034700405884500}, - {{+0.13162780924700, +0.13162780924700, +0.65307967988900}, +0.034700405884500}, - {{+0.13162780924700, +0.65307967988900, +0.13162780924700}, +0.034700405884500}, - {{+0.13162780924700, +0.08366470161720, +0.65307967988900}, +0.034700405884500}, - {{+0.13162780924700, +0.65307967988900, +0.08366470161720}, +0.034700405884500}, - {{+0.08366470161720, +0.13162780924700, +0.13162780924700}, +0.034700405884500}, - {{+0.08366470161720, +0.13162780924700, +0.65307967988900}, +0.034700405884500}, - {{+0.08366470161720, +0.65307967988900, +0.13162780924700}, +0.034700405884500}, - {{+0.65307967988900, +0.13162780924700, +0.08366470161720}, +0.034700405884500}, - {{+0.65307967988900, +0.13162780924700, +0.13162780924700}, +0.034700405884500}, - {{+0.65307967988900, +0.08366470161720, +0.13162780924700}, +0.034700405884500}, - {{+0.43395146141100, +0.43395146141100, +0.10776985954900}, +0.003352583902667}, - {{+0.43395146141100, +0.10776985954900, +0.43395146141100}, +0.003352583902667}, - {{+0.43395146141100, +0.43395146141100, +0.02432721762780}, +0.003352583902667}, - {{+0.43395146141100, +0.02432721762780, +0.43395146141100}, +0.003352583902667}, - {{+0.43395146141100, +0.10776985954900, +0.02432721762780}, +0.003352583902667}, - {{+0.43395146141100, +0.02432721762780, +0.10776985954900}, +0.003352583902667}, - {{+0.10776985954900, +0.43395146141100, +0.43395146141100}, +0.003352583902667}, - {{+0.10776985954900, +0.43395146141100, +0.02432721762780}, +0.003352583902667}, - {{+0.10776985954900, +0.02432721762780, +0.43395146141100}, +0.003352583902667}, - {{+0.02432721762780, +0.43395146141100, +0.10776985954900}, +0.003352583902667}, - {{+0.02432721762780, +0.43395146141100, +0.43395146141100}, +0.003352583902667}, - {{+0.02432721762780, +0.10776985954900, +0.43395146141100}, +0.003352583902667}, - {{-0.00137627731814, -0.00137627731814, +0.27655347263700}, +0.000431628875557}, - {{-0.00137627731814, +0.27655347263700, -0.00137627731814}, +0.000431628875557}, - {{-0.00137627731814, -0.00137627731814, +0.72619908199900}, +0.000431628875557}, - {{-0.00137627731814, +0.72619908199900, -0.00137627731814}, +0.000431628875557}, - {{-0.00137627731814, +0.27655347263700, +0.72619908199900}, +0.000431628875557}, - {{-0.00137627731814, +0.72619908199900, +0.27655347263700}, +0.000431628875557}, - {{+0.27655347263700, -0.00137627731814, -0.00137627731814}, +0.000431628875557}, - {{+0.27655347263700, -0.00137627731814, +0.72619908199900}, +0.000431628875557}, - {{+0.27655347263700, +0.72619908199900, -0.00137627731814}, +0.000431628875557}, - {{+0.72619908199900, -0.00137627731814, +0.27655347263700}, +0.000431628875557}, - {{+0.72619908199900, -0.00137627731814, -0.00137627731814}, +0.000431628875557}, - {{+0.72619908199900, +0.27655347263700, -0.00137627731814}, +0.000431628875557} -}; - -// 5 negative weights, 12 points outside of the tetrahedron - + {{+0.25000000000000, +0.25000000000000, +0.25000000000000}, + -0.137799038326167}, + {{+0.04835103854970, +0.04835103854970, +0.04835103854970}, + +0.001865336569083}, + {{+0.04835103854970, +0.04835103854970, +0.85494688435100}, + +0.001865336569083}, + {{+0.04835103854970, +0.85494688435100, +0.04835103854970}, + +0.001865336569083}, + {{+0.85494688435100, +0.04835103854970, +0.04835103854970}, + +0.001865336569083}, + {{+0.32457928011800, +0.32457928011800, +0.32457928011800}, + +0.004309423969500}, + {{+0.32457928011800, +0.32457928011800, +0.02626215964640}, + +0.004309423969500}, + {{+0.32457928011800, +0.02626215964640, +0.32457928011800}, + +0.004309423969500}, + {{+0.02626215964640, +0.32457928011800, +0.32457928011800}, + +0.004309423969500}, + {{+0.11461654022400, +0.11461654022400, +0.11461654022400}, + -0.090184766481167}, + {{+0.11461654022400, +0.11461654022400, +0.65615037932800}, + -0.090184766481167}, + {{+0.11461654022400, +0.65615037932800, +0.11461654022400}, + -0.090184766481167}, + {{+0.65615037932800, +0.11461654022400, +0.11461654022400}, + -0.090184766481167}, + {{+0.22548995191200, +0.22548995191200, +0.22548995191200}, + +0.044672576202500}, + {{+0.22548995191200, +0.22548995191200, +0.32353014426500}, + +0.044672576202500}, + {{+0.22548995191200, +0.32353014426500, +0.22548995191200}, + +0.044672576202500}, + {{+0.32353014426500, +0.22548995191200, +0.22548995191200}, + +0.044672576202500}, + {{+0.13162780924700, +0.13162780924700, +0.08366470161720}, + +0.034700405884500}, + {{+0.13162780924700, +0.08366470161720, +0.13162780924700}, + +0.034700405884500}, + {{+0.13162780924700, +0.13162780924700, +0.65307967988900}, + +0.034700405884500}, + {{+0.13162780924700, +0.65307967988900, +0.13162780924700}, + +0.034700405884500}, + {{+0.13162780924700, +0.08366470161720, +0.65307967988900}, + +0.034700405884500}, + {{+0.13162780924700, +0.65307967988900, +0.08366470161720}, + +0.034700405884500}, + {{+0.08366470161720, +0.13162780924700, +0.13162780924700}, + +0.034700405884500}, + {{+0.08366470161720, +0.13162780924700, +0.65307967988900}, + +0.034700405884500}, + {{+0.08366470161720, +0.65307967988900, +0.13162780924700}, + +0.034700405884500}, + {{+0.65307967988900, +0.13162780924700, +0.08366470161720}, + +0.034700405884500}, + {{+0.65307967988900, +0.13162780924700, +0.13162780924700}, + +0.034700405884500}, + {{+0.65307967988900, +0.08366470161720, +0.13162780924700}, + +0.034700405884500}, + {{+0.43395146141100, +0.43395146141100, +0.10776985954900}, + +0.003352583902667}, + {{+0.43395146141100, +0.10776985954900, +0.43395146141100}, + +0.003352583902667}, + {{+0.43395146141100, +0.43395146141100, +0.02432721762780}, + +0.003352583902667}, + {{+0.43395146141100, +0.02432721762780, +0.43395146141100}, + +0.003352583902667}, + {{+0.43395146141100, +0.10776985954900, +0.02432721762780}, + +0.003352583902667}, + {{+0.43395146141100, +0.02432721762780, +0.10776985954900}, + +0.003352583902667}, + {{+0.10776985954900, +0.43395146141100, +0.43395146141100}, + +0.003352583902667}, + {{+0.10776985954900, +0.43395146141100, +0.02432721762780}, + +0.003352583902667}, + {{+0.10776985954900, +0.02432721762780, +0.43395146141100}, + +0.003352583902667}, + {{+0.02432721762780, +0.43395146141100, +0.10776985954900}, + +0.003352583902667}, + {{+0.02432721762780, +0.43395146141100, +0.43395146141100}, + +0.003352583902667}, + {{+0.02432721762780, +0.10776985954900, +0.43395146141100}, + +0.003352583902667}, + {{-0.00137627731814, -0.00137627731814, +0.27655347263700}, + +0.000431628875557}, + {{-0.00137627731814, +0.27655347263700, -0.00137627731814}, + +0.000431628875557}, + {{-0.00137627731814, -0.00137627731814, +0.72619908199900}, + +0.000431628875557}, + {{-0.00137627731814, +0.72619908199900, -0.00137627731814}, + +0.000431628875557}, + {{-0.00137627731814, +0.27655347263700, +0.72619908199900}, + +0.000431628875557}, + {{-0.00137627731814, +0.72619908199900, +0.27655347263700}, + +0.000431628875557}, + {{+0.27655347263700, -0.00137627731814, -0.00137627731814}, + +0.000431628875557}, + {{+0.27655347263700, -0.00137627731814, +0.72619908199900}, + +0.000431628875557}, + {{+0.27655347263700, +0.72619908199900, -0.00137627731814}, + +0.000431628875557}, + {{+0.72619908199900, -0.00137627731814, +0.27655347263700}, + +0.000431628875557}, + {{+0.72619908199900, -0.00137627731814, -0.00137627731814}, + +0.000431628875557}, + {{+0.72619908199900, +0.27655347263700, -0.00137627731814}, + +0.000431628875557}}; + +// 5 negative weights, 12 points outside of the tetrahedron // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 11 on the tetrahedron */ @@ -545,11 +538,9 @@ IntPt tetP11Solin[126] = { {{0.1666666666670, 0.5000000000000, 0.1666666666670}, +0.004068080357150}, {{0.5000000000000, 0.1666666666670, 0.1666666666670}, +0.004068080357150}, {{0.1666666666670, 0.1666666666670, 0.1666666666670}, +0.004068080357150}, - {{0.2500000000000, 0.2500000000000, 0.2500000000000}, -9.4062316284e-05} -}; - -// 46 negative weights, 0 points outside of the tetrahedron + {{0.2500000000000, 0.2500000000000, 0.2500000000000}, -9.4062316284e-05}}; +// 46 negative weights, 0 points outside of the tetrahedron // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 13 on the tetrahedron */ @@ -765,11 +756,9 @@ IntPt tetP13Solin[210] = { {{0.1666666666670, 0.5000000000000, 0.1666666666670}, -0.000665685876623}, {{0.5000000000000, 0.1666666666670, 0.1666666666670}, -0.000665685876623}, {{0.1666666666670, 0.1666666666670, 0.1666666666670}, -0.000665685876623}, - {{0.2500000000000, 0.2500000000000, 0.2500000000000}, +6.270821086e-06} -}; - -// 80 negative weights, 0 points outside of the tetrahedron + {{0.2500000000000, 0.2500000000000, 0.2500000000000}, +6.270821086e-06}}; +// 80 negative weights, 0 points outside of the tetrahedron // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 15 on the tetrahedron */ @@ -1105,11 +1094,9 @@ IntPt tetP15Solin[330] = { {{0.1666666666670, 0.5000000000000, 0.1666666666670}, +8.3210734578e-05}, {{0.5000000000000, 0.1666666666670, 0.1666666666670}, +8.3210734578e-05}, {{0.1666666666670, 0.1666666666670, 0.1666666666670}, +8.3210734578e-05}, - {{0.2500000000000, 0.2500000000000, 0.2500000000000}, -3.25756939e-07} -}; - -// 130 negative weights, 0 points outside of the tetrahedron + {{0.2500000000000, 0.2500000000000, 0.2500000000000}, -3.25756939e-07}}; +// 130 negative weights, 0 points outside of the tetrahedron // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 17 on the tetrahedron */ @@ -1610,11 +1597,9 @@ IntPt tetP17Solin[495] = { {{0.1666666666670, 0.5000000000000, 0.1666666666670}, -8.22963309013e-06}, {{0.5000000000000, 0.1666666666670, 0.1666666666670}, -8.22963309013e-06}, {{0.1666666666670, 0.1666666666670, 0.1666666666670}, -8.22963309013e-06}, - {{0.2500000000000, 0.2500000000000, 0.2500000000000}, +1.3573205875e-08} -}; - -// 200 negative weights, 0 points outside of the tetrahedron + {{0.2500000000000, 0.2500000000000, 0.2500000000000}, +1.3573205875e-08}}; +// 200 negative weights, 0 points outside of the tetrahedron // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 19 on the tetrahedron */ @@ -2335,11 +2320,9 @@ IntPt tetP19Solin[715] = { {{0.1666666666670, 0.5000000000000, 0.1666666666670}, +6.6130980188e-07}, {{0.5000000000000, 0.1666666666670, 0.1666666666670}, +6.6130980188e-07}, {{0.1666666666670, 0.1666666666670, 0.1666666666670}, +6.6130980188e-07}, - {{0.2500000000000, 0.2500000000000, 0.2500000000000}, -4.6404125000e-10} -}; - -// 295 negative weights, 0 points outside of the tetrahedron + {{0.2500000000000, 0.2500000000000, 0.2500000000000}, -4.6404125000e-10}}; +// 295 negative weights, 0 points outside of the tetrahedron // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 21 on the tetrahedron */ @@ -3346,59 +3329,19 @@ IntPt tetP21Solin[1001] = { {{0.1666666666670, 0.5000000000000, 0.1666666666670}, -4.4087320125e-08}, {{0.5000000000000, 0.1666666666670, 0.1666666666670}, -4.4087320125e-08}, {{0.1666666666670, 0.1666666666670, 0.1666666666670}, -4.4087320125e-08}, - {{0.2500000000000, 0.2500000000000, 0.2500000000000}, +1.3258375e-11} -}; - -// 420 negative weights, 0 points outside of the tetrahedron - -IntPt * GQTetSolin[22] = { - tetP1Solin, - tetP1Solin, - tetP2Solin, - tetP3Solin, - tetP4Solin, - tetP5Solin, - tetP6Solin, - tetP7Solin, - tetP8Solin, - tetP9Solin, - tetP11Solin, - tetP11Solin, - tetP13Solin, - tetP13Solin, - tetP15Solin, - tetP15Solin, - tetP17Solin, - tetP17Solin, - tetP19Solin, - tetP19Solin, - tetP21Solin, - tetP21Solin -}; - -int GQTetnPtSolin[22] = { - 1, - 1, - 4, - 5, - 11, - 14, - 24, - 31, - 43, - 53, - 126, - 126, - 210, - 210, - 330, - 330, - 495, - 495, - 715, - 715, - 1001, - 1001}; + {{0.2500000000000, 0.2500000000000, 0.2500000000000}, +1.3258375e-11}}; + +// 420 negative weights, 0 points outside of the tetrahedron + +IntPt *GQTetSolin[22] = { + tetP1Solin, tetP1Solin, tetP2Solin, tetP3Solin, tetP4Solin, tetP5Solin, + tetP6Solin, tetP7Solin, tetP8Solin, tetP9Solin, tetP11Solin, tetP11Solin, + tetP13Solin, tetP13Solin, tetP15Solin, tetP15Solin, tetP17Solin, tetP17Solin, + tetP19Solin, tetP19Solin, tetP21Solin, tetP21Solin}; + +int GQTetnPtSolin[22] = {1, 1, 4, 5, 11, 14, 24, 31, + 43, 53, 126, 126, 210, 210, 330, 330, + 495, 495, 715, 715, 1001, 1001}; IntPt *getGQTetPts(int order); int getNGQTetPts(int order); @@ -3406,28 +3349,27 @@ int getNGQTetPts(int order); IntPt *getGQTetPts(int order) { // if(order < 7) - // return GQTet[order]; - - if (order < 22) return GQTetSolin[order]; - - int n = (order+4)/2; - int index = n-5; - if(!GQTetDegen[index]){ - int npts = n*n*n; + // return GQTet[order]; + + if(order < 22) return GQTetSolin[order]; + + int n = (order + 4) / 2; + int index = n - 5; + if(!GQTetDegen[index]) { + int npts = n * n * n; GQTetDegen[index] = new IntPt[npts]; - GaussLegendreTet(n,n,n,GQTetDegen[index]); + GaussLegendreTet(n, n, n, GQTetDegen[index]); } - return GQTetDegen[index]; + return GQTetDegen[index]; } int getNGQTetPts(int order) -{ +{ // if(order < 7) // return GQTetnPt[order]; - if (order < 22) return GQTetnPtSolin[order]; + if(order < 22) return GQTetnPtSolin[order]; - - int n = (order+4)/2; - return n*n*n; + int n = (order + 4) / 2; + return n * n * n; } diff --git a/Numeric/GaussQuadratureTri.cpp b/Numeric/GaussQuadratureTri.cpp index 7e1c3f4bc11ba6645bab7a798de6c4acfd28c8f1..2704f99cb0aa475c1bc6354f8cbb18f72343baf2 100644 --- a/Numeric/GaussQuadratureTri.cpp +++ b/Numeric/GaussQuadratureTri.cpp @@ -7,20 +7,17 @@ #include "GaussLegendre1D.h" IntPt GQT1[1] = { - {{0.333333333333333, 0.333333333333333, 0.}, 0.500000000000000} -}; + {{0.333333333333333, 0.333333333333333, 0.}, 0.500000000000000}}; IntPt GQT2[3] = { {{0.166666666666667, 0.166666666666667, 0.}, 0.166666666666667}, {{0.666666666666667, 0.166666666666667, 0.}, 0.166666666666667}, - {{0.166666666666667, 0.666666666666667, 0.}, 0.166666666666667} -}; + {{0.166666666666667, 0.666666666666667, 0.}, 0.166666666666667}}; IntPt GQT3[4] = { {{0.333333333333333, 0.333333333333333, 0.}, -0.281250000000000}, {{0.600000000000000, 0.200000000000000, 0.}, +0.260416666666667}, {{0.200000000000000, 0.600000000000000, 0.}, +0.260416666666667}, - {{0.200000000000000, 0.200000000000000, 0.}, +0.260416666666667} -}; + {{0.200000000000000, 0.200000000000000, 0.}, +0.260416666666667}}; IntPt GQT4[6] = { {{0.816847572980459, 0.091576213509771, 0.}, 0.054975871827661}, @@ -28,8 +25,7 @@ IntPt GQT4[6] = { {{0.091576213509771, 0.091576213509771, 0.}, 0.054975871827661}, {{0.108103018168070, 0.445948490915965, 0.}, 0.111690794839005}, {{0.445948490915965, 0.108103018168070, 0.}, 0.111690794839005}, - {{0.445948490915965, 0.445948490915965, 0.}, 0.111690794839005} -}; + {{0.445948490915965, 0.445948490915965, 0.}, 0.111690794839005}}; IntPt GQT5[7] = { {{0.333333333333333, 0.333333333333333, 0.}, 0.112500000000000}, @@ -38,8 +34,7 @@ IntPt GQT5[7] = { {{0.101286507323456, 0.101286507323456, 0.}, 0.062969590272414}, {{0.470142064105115, 0.059715871789770, 0.}, 0.066197076394253}, {{0.059715871789770, 0.470142064105115, 0.}, 0.066197076394253}, - {{0.470142064105115, 0.470142064105115, 0.}, 0.066197076394253} -}; + {{0.470142064105115, 0.470142064105115, 0.}, 0.066197076394253}}; IntPt GQT6[12] = { {{0.873821971016996, 0.063089014491502, 0.}, 0.025422453185104}, @@ -53,8 +48,7 @@ IntPt GQT6[12] = { {{0.636502499121399, 0.053145049844816, 0.}, 0.041425537809187}, {{0.310352451033785, 0.053145049844816, 0.}, 0.041425537809187}, {{0.053145049844816, 0.310352451033785, 0.}, 0.041425537809187}, - {{0.053145049844816, 0.636502499121399, 0.}, 0.041425537809187} -}; + {{0.053145049844816, 0.636502499121399, 0.}, 0.041425537809187}}; IntPt GQT7[13] = { {{0.333333333333333, 0.333333333333333, 0.}, -0.074785022233841}, @@ -89,23 +83,20 @@ IntPt GQT8[16] = { {{0.263112829634638, 0.008394777409958, 0.}, 0.013615157087217}, {{0.008394777409958, 0.263112829634638, 0.}, 0.013615157087217}, {{0.263112829634638, 0.728492392955404, 0.}, 0.013615157087217}, - {{0.728492392955404, 0.263112829634638, 0.}, 0.013615157087217} -}; - + {{0.728492392955404, 0.263112829634638, 0.}, 0.013615157087217}}; - -IntPt * GQT[9] = {GQT1,GQT1,GQT2,GQT3,GQT4,GQT5,GQT6,GQT7,GQT8}; -IntPt * GQTdegen[17] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -int GQTnPt[9] = {1,1,3,4,6,7,12,13,16}; +IntPt *GQT[9] = {GQT1, GQT1, GQT2, GQT3, GQT4, GQT5, GQT6, GQT7, GQT8}; +IntPt *GQTdegen[17] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +int GQTnPt[9] = {1, 1, 3, 4, 6, 7, 12, 13, 16}; // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 1 on the triangle */ /* 'Higher-order Finite Elements', P.Solin, K.Segeth and I. Dolezel */ IntPt triP1Solin[1] = { - {{0.333333333333333, 0.333333333333333, 0.}, 0.500000000000000} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.333333333333333, 0.333333333333333, 0.}, 0.500000000000000}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 2 on the triangle */ @@ -114,9 +105,9 @@ IntPt triP1Solin[1] = { IntPt triP2Solin[3] = { {{0.166666666666667, 0.166666666666667, 0.}, 0.166666666666667}, {{0.166666666666667, 0.666666666666667, 0.}, 0.166666666666667}, - {{0.666666666666667, 0.166666666666667, 0.}, 0.166666666666667} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.666666666666667, 0.166666666666667, 0.}, 0.166666666666667}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 3 on the triangle */ @@ -126,9 +117,9 @@ IntPt triP3Solin[4] = { {{0.333333333333333, 0.333333333333333, 0.}, -0.281250000000000}, {{0.200000000000000, 0.200000000000000, 0.}, 0.260416666666667}, {{0.200000000000000, 0.600000000000000, 0.}, 0.260416666666667}, - {{0.600000000000000, 0.200000000000000, 0.}, 0.260416666666667} -}; -// 1 negative weight, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.600000000000000, 0.200000000000000, 0.}, 0.260416666666667}}; +// 1 negative weight, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 4 on the triangle */ @@ -140,9 +131,9 @@ IntPt triP4Solin[6] = { {{0.108103018168070, 0.445948490915965, 0.}, 0.111690794839005}, {{0.091576213509771, 0.091576213509771, 0.}, 0.054975871827661}, {{0.091576213509771, 0.816847572980459, 0.}, 0.054975871827661}, - {{0.816847572980459, 0.091576213509771, 0.}, 0.054975871827661} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.816847572980459, 0.091576213509771, 0.}, 0.054975871827661}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 5 on the triangle */ @@ -155,9 +146,9 @@ IntPt triP5Solin[7] = { {{0.059715871789770, 0.470142064105115, 0.}, 0.066197076394253}, {{0.101286507323456, 0.101286507323456, 0.}, 0.062969590272414}, {{0.101286507323456, 0.797426985353087, 0.}, 0.062969590272414}, - {{0.797426985353087, 0.101286507323456, 0.}, 0.062969590272414} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.797426985353087, 0.101286507323456, 0.}, 0.062969590272414}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 6 on the triangle */ @@ -175,9 +166,9 @@ IntPt triP6Solin[12] = { {{0.053145049844816, 0.310352451033785, 0.}, 0.041425537809187}, {{0.310352451033785, 0.053145049844816, 0.}, 0.041425537809187}, {{0.636502499121399, 0.310352451033785, 0.}, 0.041425537809187}, - {{0.053145049844816, 0.636502499121399, 0.}, 0.041425537809187} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.053145049844816, 0.636502499121399, 0.}, 0.041425537809187}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 7 on the triangle */ @@ -196,9 +187,9 @@ IntPt triP7Solin[13] = { {{0.048690315425316, 0.312865496004874, 0.}, 0.038556880445128}, {{0.312865496004874, 0.048690315425316, 0.}, 0.038556880445128}, {{0.638444188569810, 0.312865496004874, 0.}, 0.038556880445128}, - {{0.048690315425316, 0.638444188569810, 0.}, 0.038556880445128} -}; -// 1 negative weight, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.048690315425316, 0.638444188569810, 0.}, 0.038556880445128}}; +// 1 negative weight, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 8 on the triangle */ @@ -220,9 +211,9 @@ IntPt triP8Solin[16] = { {{0.008394777409958, 0.263112829634638, 0.}, 0.013615157087217}, {{0.263112829634638, 0.008394777409958, 0.}, 0.013615157087217}, {{0.728492392955404, 0.263112829634638, 0.}, 0.013615157087217}, - {{0.008394777409958, 0.728492392955404, 0.}, 0.013615157087217} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.008394777409958, 0.728492392955404, 0.}, 0.013615157087217}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 9 on the triangle */ @@ -247,9 +238,9 @@ IntPt triP9Solin[19] = { {{0.0368384120547, 0.2219629891610, 0.}, 0.02164176968865}, {{0.2219629891610, 0.0368384120547, 0.}, 0.02164176968865}, {{0.7411985987840, 0.2219629891610, 0.}, 0.02164176968865}, - {{0.0368384120547, 0.7411985987840, 0.}, 0.02164176968865} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.0368384120547, 0.7411985987840, 0.}, 0.02164176968865}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 10 on the triangle */ @@ -280,9 +271,9 @@ IntPt triP10Solin[25] = { {{0.0095408154003, 0.0668032510122, 0.}, 0.00471083348185}, {{0.0668032510122, 0.0095408154003, 0.}, 0.00471083348185}, {{0.9236559335870, 0.0668032510122, 0.}, 0.00471083348185}, - {{0.0095408154003, 0.9236559335870, 0.}, 0.00471083348185} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.0095408154003, 0.9236559335870, 0.}, 0.00471083348185}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 11 on the triangle */ @@ -315,9 +306,9 @@ IntPt triP11Solin[27] = { {{+0.1714889803040, +0.0210220165362, 0.}, 0.01035382981955}, {{+0.0210220165362, +0.1714889803040, 0.}, 0.01035382981955}, {{+0.1714889803040, +0.8074890031600, 0.}, 0.01035382981955}, - {{+0.8074890031600, +0.0210220165362, 0.}, 0.01035382981955} -}; -// 0 negative weights, 3 points outside of the triangle, total sum of the weights is 0.5 + {{+0.8074890031600, +0.0210220165362, 0.}, 0.01035382981955}}; +// 0 negative weights, 3 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 12 on the triangle */ @@ -356,9 +347,9 @@ IntPt triP12Solin[33] = { {{0.0257340505483, 0.1162519159080, 0.}, 0.00865811555435}, {{0.1162519159080, 0.0257340505483, 0.}, 0.00865811555435}, {{0.8580140335440, 0.1162519159080, 0.}, 0.00865811555435}, - {{0.0257340505483, 0.8580140335440, 0.}, 0.00865811555435} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.0257340505483, 0.8580140335440, 0.}, 0.00865811555435}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 13 on the triangle */ @@ -401,9 +392,9 @@ IntPt triP13Solin[37] = { {{0.12635738549200, 0.02223307667410, 0.}, 0.007760893419500}, {{0.02223307667410, 0.12635738549200, 0.}, 0.007760893419500}, {{0.12635738549200, 0.85140953783400, 0.}, 0.007760893419500}, - {{0.85140953783400, 0.02223307667410, 0.}, 0.007760893419500} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.85140953783400, 0.02223307667410, 0.}, 0.007760893419500}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 14 on the triangle */ @@ -451,9 +442,9 @@ IntPt triP14Solin[42] = { {{0.11897449769700, 0.00126833093287, 0.}, 0.00250511441925}, {{0.00126833093287, 0.11897449769700, 0.}, 0.00250511441925}, {{0.11897449769700, 0.87975717137000, 0.}, 0.00250511441925}, - {{0.87975717137000, 0.00126833093287, 0.}, 0.00250511441925} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.87975717137000, 0.00126833093287, 0.}, 0.00250511441925}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 15 on the triangle */ @@ -507,9 +498,9 @@ IntPt triP15Solin[48] = { {{+0.1035756165760, +0.0124598093312, 0.}, 0.003836971315525}, {{+0.0124598093312, +0.1035756165760, 0.}, 0.003836971315525}, {{+0.1035756165760, +0.8839645740920, 0.}, 0.003836971315525}, - {{+0.8839645740920, +0.0124598093312, 0.}, 0.003836971315525} -}; -// 0 negative weights, 9 points outside of the triangle, total sum of the weights is 0.5 + {{+0.8839645740920, +0.0124598093312, 0.}, 0.003836971315525}}; +// 0 negative weights, 9 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 16 on the triangle */ @@ -567,9 +558,9 @@ IntPt triP16Solin[52] = { {{+0.08528361568270, +0.01431732023070, 0.}, 0.003425027273270}, {{+0.01431732023070, +0.08528361568270, 0.}, 0.003425027273270}, {{+0.08528361568270, +0.90039906408700, 0.}, 0.003425027273270}, - {{+0.90039906408700, +0.01431732023070, 0.}, 0.003425027273270} -}; -// 0 negative weights, 6 points outside of the triangle, total sum of the weights is 0.5 + {{+0.90039906408700, +0.01431732023070, 0.}, 0.003425027273270}}; +// 0 negative weights, 6 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 17 on the triangle */ @@ -636,9 +627,9 @@ IntPt triP17Solin[61] = { {{0.08071131367960, 0.01466318222480, 0.}, 0.003332816002085}, {{0.01466318222480, 0.08071131367960, 0.}, 0.003332816002085}, {{0.08071131367960, 0.90462550409600, 0.}, 0.003332816002085}, - {{0.90462550409600, 0.01466318222480, 0.}, 0.003332816002085} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.90462550409600, 0.01466318222480, 0.}, 0.003332816002085}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 18 on the triangle */ @@ -714,9 +705,9 @@ IntPt triP18Solin[70] = { {{+0.02087475528260, -0.03522201528790, 0.}, +2.3093830397e-05}, {{-0.03522201528790, +0.02087475528260, 0.}, +2.3093830397e-05}, {{+0.02087475528260, +1.01434726001000, 0.}, +2.3093830397e-05}, - {{+1.01434726001000, -0.03522201528790, 0.}, +2.3093830397e-05} -}; -// 3 negative weights, 6 points outside of the triangle, total sum of the weights is 0.5 + {{+1.01434726001000, -0.03522201528790, 0.}, +2.3093830397e-05}}; +// 3 negative weights, 6 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 19 on the triangle */ @@ -795,9 +786,9 @@ IntPt triP19Solin[73] = { {{0.06549462808290, 0.01016111929630, 0.}, 0.001899964427650}, {{0.01016111929630, 0.06549462808290, 0.}, 0.001899964427650}, {{0.06549462808290, 0.92434425262100, 0.}, 0.001899964427650}, - {{0.92434425262100, 0.01016111929630, 0.}, 0.001899964427650} -}; -// 0 negative weights, 0 points outside of the triangle, total sum of the weights is 0.5 + {{0.92434425262100, 0.01016111929630, 0.}, 0.001899964427650}}; +// 0 negative weights, 0 points outside of the triangle, total sum of the +// weights is 0.5 // ----------------------------------------------------------------------------- /*! Quadrature rule for an interpolation of order 20 on the triangle */ @@ -882,79 +873,41 @@ IntPt triP20Solin[79] = { {{+0.0596961091490, +0.0105477192941, 0.}, +0.001786954692975}, {{+0.0105477192941, +0.0596961091490, 0.}, +0.001786954692975}, {{+0.0596961091490, +0.9297561715570, 0.}, +0.001786954692975}, - {{+0.9297561715570, +0.0105477192941, 0.}, +0.001786954692975} -}; -// 3 negative weights, 9 points outside of the triangle, total sum of the weights is 0.5 - -IntPt * GQTSolin[21] = { - triP1Solin, - triP1Solin, - triP2Solin, - triP3Solin, - triP4Solin, - triP5Solin, - triP6Solin, - triP7Solin, - triP8Solin, - triP9Solin, - triP10Solin, - triP11Solin, - triP12Solin, - triP13Solin, - triP14Solin, - triP15Solin, - triP16Solin, - triP17Solin, - triP18Solin, - triP19Solin, - triP20Solin -}; + {{+0.9297561715570, +0.0105477192941, 0.}, +0.001786954692975}}; +// 3 negative weights, 9 points outside of the triangle, total sum of the +// weights is 0.5 + +IntPt *GQTSolin[21] = { + triP1Solin, triP1Solin, triP2Solin, triP3Solin, triP4Solin, triP5Solin, + triP6Solin, triP7Solin, triP8Solin, triP9Solin, triP10Solin, triP11Solin, + triP12Solin, triP13Solin, triP14Solin, triP15Solin, triP16Solin, triP17Solin, + triP18Solin, triP19Solin, triP20Solin}; -int GQTnPtSolin[21] = { - 1, - 1, - 3, - 4, - 6, - 7, - 12, - 13, - 16, - 19, - 25, - 27, - 33, - 37, - 42, - 48, - 52, - 61, - 70, - 73, - 79}; +int GQTnPtSolin[21] = {1, 1, 3, 4, 6, 7, 12, 13, 16, 19, 25, + 27, 33, 37, 42, 48, 52, 61, 70, 73, 79}; IntPt *getGQTPts(int order); int getNGQTPts(int order); IntPt *getGQTPts(int order) { - if (order < 21) return GQTSolin[order]; - int n = (order+3)/2; - int index = n-4; - if(index >= (int)(sizeof(GQTdegen) / sizeof(IntPt*))){ + if(order < 21) return GQTSolin[order]; + int n = (order + 3) / 2; + int index = n - 4; + if(index >= (int)(sizeof(GQTdegen) / sizeof(IntPt *))) { Msg::Error("Increase size of GQTdegen in gauss quadrature tri"); index = 0; } - if(!GQTdegen[index]){ - int npts = n*n; + if(!GQTdegen[index]) { + int npts = n * n; GQTdegen[index] = new IntPt[npts]; - GaussLegendreTri(n,n,GQTdegen[index]); + GaussLegendreTri(n, n, GQTdegen[index]); } return GQTdegen[index]; } int getNGQTPts(int order) { - if (order < 21) return GQTnPtSolin[order]; - return ((order+3)/2)*((order+3)/2); + if(order < 21) return GQTnPtSolin[order]; + return ((order + 3) / 2) * ((order + 3) / 2); } diff --git a/Numeric/HilbertCurve.cpp b/Numeric/HilbertCurve.cpp index 3532b44cf0a697bd8463cecd66e5edb014300876..59646de917110a708568f0bc79b29084303fe18a 100644 --- a/Numeric/HilbertCurve.cpp +++ b/Numeric/HilbertCurve.cpp @@ -6,55 +6,52 @@ #include "SBoundingBox3d.h" #include "MVertex.h" -struct HilbertSort -{ -// The code for generating table transgc -// from: http://graphics.stanford.edu/~seander/bithacks.html. +struct HilbertSort { + // The code for generating table transgc + // from: http://graphics.stanford.edu/~seander/bithacks.html. int transgc[8][3][8]; int tsb1mod3[8]; int maxDepth; int Limit; - SBoundingBox3d bbox ; + SBoundingBox3d bbox; void ComputeGrayCode(int n); - int Split(MVertex** vertices, - int arraysize,int GrayCode0,int GrayCode1, - double BoundingBoxXmin, double BoundingBoxXmax, - double BoundingBoxYmin, double BoundingBoxYmax, - double BoundingBoxZmin, double BoundingBoxZmax); - void Sort(MVertex** vertices, int arraysize, int e, int d, - double BoundingBoxXmin, double BoundingBoxXmax, + int Split(MVertex **vertices, int arraysize, int GrayCode0, int GrayCode1, + double BoundingBoxXmin, double BoundingBoxXmax, + double BoundingBoxYmin, double BoundingBoxYmax, + double BoundingBoxZmin, double BoundingBoxZmax); + void Sort(MVertex **vertices, int arraysize, int e, int d, + double BoundingBoxXmin, double BoundingBoxXmax, double BoundingBoxYmin, double BoundingBoxYmax, - double BoundingBoxZmin, double BoundingBoxZmax, int depth); - HilbertSort (int m = 0, int l=2) : maxDepth(m),Limit(l) + double BoundingBoxZmin, double BoundingBoxZmax, int depth); + HilbertSort(int m = 0, int l = 2) : maxDepth(m), Limit(l) { ComputeGrayCode(3); } - void MultiscaleSortHilbert(MVertex** vertices, int arraysize, - int threshold, double ratio, int *depth) + void MultiscaleSortHilbert(MVertex **vertices, int arraysize, int threshold, + double ratio, int *depth) { int middle; middle = 0; - if (arraysize >= threshold) { + if(arraysize >= threshold) { (*depth)++; middle = (int)(arraysize * ratio); MultiscaleSortHilbert(vertices, middle, threshold, ratio, depth); } - Sort (&(vertices[middle]),arraysize - middle,0,0, - bbox.min().x(),bbox.max().x(), - bbox.min().y(),bbox.max().y(), - bbox.min().z(),bbox.max().z(),0); + Sort(&(vertices[middle]), arraysize - middle, 0, 0, bbox.min().x(), + bbox.max().x(), bbox.min().y(), bbox.max().y(), bbox.min().z(), + bbox.max().z(), 0); } - void Apply (std::vector<MVertex*> &v) + void Apply(std::vector<MVertex *> &v) { - for (size_t i=0;i<v.size();i++){ + for(size_t i = 0; i < v.size(); i++) { MVertex *pv = v[i]; - bbox += SPoint3(pv->x(),pv->y(),pv->z()); + bbox += SPoint3(pv->x(), pv->y(), pv->z()); } bbox *= 1.01; - MVertex**pv = &v[0]; + MVertex **pv = &v[0]; int depth; - MultiscaleSortHilbert(pv, (int)v.size(), 10, 0.125,&depth); + MultiscaleSortHilbert(pv, (int)v.size(), 10, 0.125, &depth); } }; @@ -69,17 +66,17 @@ void HilbertSort::ComputeGrayCode(int n) mask = (n == 2) ? 3 : 7; // Generate the Gray code sequence. - for (i = 0; i < N; i++) { + for(i = 0; i < N; i++) { gc[i] = i ^ (i >> 1); } - for (e = 0; e < N; e++) { - for (d = 0; d < n; d++) { + for(e = 0; e < N; e++) { + for(d = 0; d < n; d++) { // Calculate the end point (f). - f = e ^ (1 << d); // Toggle the d-th bit of 'e'. + f = e ^ (1 << d); // Toggle the d-th bit of 'e'. // travel_bit = 2**p, the bit we want to travel. travel_bit = e ^ f; - for (i = 0; i < N; i++) { + for(i = 0; i < N; i++) { // // Rotate gc[i] left by (p + 1) % n bits. k = gc[i] * (travel_bit * 2); g = ((k | (k / N)) & mask); @@ -93,24 +90,23 @@ void HilbertSort::ComputeGrayCode(int n) // Count the consecutive '1' bits (trailing) on the right. tsb1mod3[0] = 0; - for (i = 1; i < N; i++) { + for(i = 1; i < N; i++) { v = ~i; // Count the 0s. v = (v ^ (v - 1)) >> 1; // Set v's trailing 0s to 1s and zero rest - for (c = 0; v; c++) { + for(c = 0; v; c++) { v >>= 1; } tsb1mod3[i] = c % n; } } - -int HilbertSort::Split(MVertex** vertices, - int arraysize,int GrayCode0,int GrayCode1, - double BoundingBoxXmin, double BoundingBoxXmax, - double BoundingBoxYmin, double BoundingBoxYmax, - double BoundingBoxZmin, double BoundingBoxZmax) +int HilbertSort::Split(MVertex **vertices, int arraysize, int GrayCode0, + int GrayCode1, double BoundingBoxXmin, + double BoundingBoxXmax, double BoundingBoxYmin, + double BoundingBoxYmax, double BoundingBoxZmin, + double BoundingBoxZmax) { - MVertex* swapvert; + MVertex *swapvert; int axis, d; double split; int i, j; @@ -120,18 +116,19 @@ int HilbertSort::Split(MVertex** vertices, axis = (GrayCode0 ^ GrayCode1) >> 1; // Calulate the split position along the axis. - if (axis == 0) { + if(axis == 0) { split = 0.5 * (BoundingBoxXmin + BoundingBoxXmax); - } else if (axis == 1) { + } + else if(axis == 1) { split = 0.5 * (BoundingBoxYmin + BoundingBoxYmax); - } else { // == 2 + } + else { // == 2 split = 0.5 * (BoundingBoxZmin + BoundingBoxZmax); } // Find the direction (+1 or -1) of the axis. If 'd' is +1, the direction // of the axis is to the positive of the axis, otherwise, it is -1. - d = ((GrayCode0 & (1<<axis)) == 0) ? 1 : -1; - + d = ((GrayCode0 & (1 << axis)) == 0) ? 1 : -1; // Partition the vertices into left- and right-arrays such that left points // have Hilbert indices lower than the right points. @@ -139,38 +136,39 @@ int HilbertSort::Split(MVertex** vertices, j = arraysize - 1; // Partition the vertices into left- and right-arrays. - if (d > 0) { + if(d > 0) { do { - for (; i < arraysize; i++) { - if (vertices[i]->point()[axis] >= split) break; + for(; i < arraysize; i++) { + if(vertices[i]->point()[axis] >= split) break; } - for (; j >= 0; j--) { - if (vertices[j]->point()[axis] < split) break; + for(; j >= 0; j--) { + if(vertices[j]->point()[axis] < split) break; } // Is the partition finished? - if (i == (j + 1)) break; + if(i == (j + 1)) break; // Swap i-th and j-th vertices. swapvert = vertices[i]; vertices[i] = vertices[j]; vertices[j] = swapvert; // Continue patitioning the array; - } while (true); - } else { + } while(true); + } + else { do { - for (; i < arraysize; i++) { - if (vertices[i]->point()[axis] <= split) break; + for(; i < arraysize; i++) { + if(vertices[i]->point()[axis] <= split) break; } - for (; j >= 0; j--) { - if (vertices[j]->point()[axis] > split) break; + for(; j >= 0; j--) { + if(vertices[j]->point()[axis] > split) break; } // Is the partition finished? - if (i == (j + 1)) break; + if(i == (j + 1)) break; // Swap i-th and j-th vertices. swapvert = vertices[i]; vertices[i] = vertices[j]; vertices[j] = swapvert; // Continue patitioning the array; - } while (true); + } while(true); } return i; @@ -178,10 +176,11 @@ int HilbertSort::Split(MVertex** vertices, // The sorting code is inspired by Tetgen 1.5 -void HilbertSort::Sort(MVertex** vertices, int arraysize, int e, int d, - double BoundingBoxXmin, double BoundingBoxXmax, +void HilbertSort::Sort(MVertex **vertices, int arraysize, int e, int d, + double BoundingBoxXmin, double BoundingBoxXmax, double BoundingBoxYmin, double BoundingBoxYmax, - double BoundingBoxZmin, double BoundingBoxZmax, int depth) + double BoundingBoxZmin, double BoundingBoxZmax, + int depth) { double x1, x2, y1, y2, z1, z2; int p[9], w, e_w, d_w, k, ei, di; @@ -191,85 +190,94 @@ void HilbertSort::Sort(MVertex** vertices, int arraysize, int e, int d, p[8] = arraysize; p[4] = Split(vertices, p[8], transgc[e][d][3], transgc[e][d][4], - BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, + BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax); p[2] = Split(vertices, p[4], transgc[e][d][1], transgc[e][d][2], - BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, + BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax); p[1] = Split(vertices, p[2], transgc[e][d][0], transgc[e][d][1], - BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, + BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax); - p[3] = Split(&(vertices[p[2]]), p[4] - p[2], - transgc[e][d][2], transgc[e][d][3], - BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, - BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax) + p[2]; - p[6] = Split(&(vertices[p[4]]), p[8] - p[4], - transgc[e][d][5], transgc[e][d][6], - BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, - BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax) + p[4]; - p[5] = Split(&(vertices[p[4]]), p[6] - p[4], - transgc[e][d][4], transgc[e][d][5], - BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, - BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax) + p[4]; - p[7] = Split(&(vertices[p[6]]), p[8] - p[6], - transgc[e][d][6], transgc[e][d][7], - BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, - BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax) + p[6]; + p[3] = + Split(&(vertices[p[2]]), p[4] - p[2], transgc[e][d][2], transgc[e][d][3], + BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax, + BoundingBoxZmin, BoundingBoxZmax) + + p[2]; + p[6] = + Split(&(vertices[p[4]]), p[8] - p[4], transgc[e][d][5], transgc[e][d][6], + BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax, + BoundingBoxZmin, BoundingBoxZmax) + + p[4]; + p[5] = + Split(&(vertices[p[4]]), p[6] - p[4], transgc[e][d][4], transgc[e][d][5], + BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax, + BoundingBoxZmin, BoundingBoxZmax) + + p[4]; + p[7] = + Split(&(vertices[p[6]]), p[8] - p[6], transgc[e][d][6], transgc[e][d][7], + BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax, + BoundingBoxZmin, BoundingBoxZmax) + + p[6]; - if (maxDepth > 0) { - if ((depth + 1) == maxDepth) { + if(maxDepth > 0) { + if((depth + 1) == maxDepth) { return; } } // Recursively sort the points in sub-boxes. - for (w = 0; w < 8; w++) { - if ((p[w+1] - p[w]) > Limit) { - if (w == 0) { + for(w = 0; w < 8; w++) { + if((p[w + 1] - p[w]) > Limit) { + if(w == 0) { e_w = 0; - } else { + } + else { k = 2 * ((w - 1) / 2); e_w = k ^ (k >> 1); } k = e_w; - e_w = ((k << (d+1)) & mask) | ((k >> (n-d-1)) & mask); + e_w = ((k << (d + 1)) & mask) | ((k >> (n - d - 1)) & mask); ei = e ^ e_w; - if (w == 0) { + if(w == 0) { d_w = 0; - } else { + } + else { d_w = ((w % 2) == 0) ? tsb1mod3[w - 1] : tsb1mod3[w]; } di = (d + d_w + 1) % n; - if (transgc[e][d][w] & 1) { + if(transgc[e][d][w] & 1) { x1 = 0.5 * (BoundingBoxXmin + BoundingBoxXmax); x2 = BoundingBoxXmax; - } else { + } + else { x1 = BoundingBoxXmin; x2 = 0.5 * (BoundingBoxXmin + BoundingBoxXmax); } - if (transgc[e][d][w] & 2) { // y-axis + if(transgc[e][d][w] & 2) { // y-axis y1 = 0.5 * (BoundingBoxYmin + BoundingBoxYmax); y2 = BoundingBoxYmax; - } else { + } + else { y1 = BoundingBoxYmin; y2 = 0.5 * (BoundingBoxYmin + BoundingBoxYmax); } - if (transgc[e][d][w] & 4) { // z-axis + if(transgc[e][d][w] & 4) { // z-axis z1 = 0.5 * (BoundingBoxZmin + BoundingBoxZmax); z2 = BoundingBoxZmax; - } else { + } + else { z1 = BoundingBoxZmin; z2 = 0.5 * (BoundingBoxZmin + BoundingBoxZmax); } - Sort(&(vertices[p[w]]), p[w+1] - p[w], ei, di, - x1, x2, y1, y2, z1, z2, depth+1); + Sort(&(vertices[p[w]]), p[w + 1] - p[w], ei, di, x1, x2, y1, y2, z1, z2, + depth + 1); } } } -void SortHilbert (std::vector<MVertex*>& v) +void SortHilbert(std::vector<MVertex *> &v) { HilbertSort h(1000); - //HilbertSort h; + // HilbertSort h; h.Apply(v); } diff --git a/Numeric/HilbertCurve.h b/Numeric/HilbertCurve.h index 14778c06571b407337e75243efb11d3bd8e36a30..d2af5f047f4e075ccb9cf44d15f8074437d3bcc6 100644 --- a/Numeric/HilbertCurve.h +++ b/Numeric/HilbertCurve.h @@ -6,6 +6,6 @@ #ifndef _HILBERT_CURVE_ #define _HILBERT_CURVE_ -void SortHilbert(std::vector<MVertex*>&); +void SortHilbert(std::vector<MVertex *> &); #endif diff --git a/Numeric/InnerVertexPlacement.cpp b/Numeric/InnerVertexPlacement.cpp index 149131800ae25ae2f419c486ba2fead2a5962b63..21654944d57015a27cafa0eefeec9c5b3cda6a67 100644 --- a/Numeric/InnerVertexPlacement.cpp +++ b/Numeric/InnerVertexPlacement.cpp @@ -5,69 +5,65 @@ #include "InnerVertexPlacement.h" #include "pointsGenerators.h" - namespace { typedef std::pair<std::pair<int, int>, int> mytuple; mytuple make_mytuple(int a, int b, int c) { - return std::make_pair(std::make_pair(a,b),c); + return std::make_pair(std::make_pair(a, b), c); } - - void double2int(const fullMatrix<double> &doubleMat, - fullMatrix<int> &intMat) { + + void double2int(const fullMatrix<double> &doubleMat, fullMatrix<int> &intMat) + { intMat.resize(doubleMat.size1(), doubleMat.size2(), false); - for (int i = 0; i < intMat.size1(); ++i) { - for (int j = 0; j < intMat.size2(); ++j) { + for(int i = 0; i < intMat.size1(); ++i) { + for(int j = 0; j < intMat.size2(); ++j) { intMat(i, j) = static_cast<int>(doubleMat(i, j) + .5); } } } - std::map<int, fullMatrix<double>*> storedMatrices[6]; -} - + std::map<int, fullMatrix<double> *> storedMatrices[6]; +} // namespace -fullMatrix<double>* getInnerVertexPlacement(int type, int order) +fullMatrix<double> *getInnerVertexPlacement(int type, int order) { - if (type < 3 || type > 8) - return NULL; - std::map<int, fullMatrix<double>*>::iterator it; - it = storedMatrices[type-3].find(order); - if (it != storedMatrices[type-3].end()) { + if(type < 3 || type > 8) return NULL; + std::map<int, fullMatrix<double> *>::iterator it; + it = storedMatrices[type - 3].find(order); + if(it != storedMatrices[type - 3].end()) { return it->second; } else { fullMatrix<double> *matrix = new fullMatrix<double>(); - switch (type) { - case TYPE_TRI: - *matrix = gmshGenerateInnerVertexPlacementTriangle(order); - break; - case TYPE_QUA: - *matrix = gmshGenerateInnerVertexPlacementQuadrangle(order); - break; - case TYPE_TET: - *matrix = gmshGenerateInnerVertexPlacementTetrahedron(order); - break; - case TYPE_PRI: - *matrix = gmshGenerateInnerVertexPlacementPrism(order); - break; - case TYPE_HEX: - *matrix = gmshGenerateInnerVertexPlacementHexahedron(order); - break; - case TYPE_PYR: - *matrix = gmshGenerateInnerVertexPlacementPyramid(order); - break; + switch(type) { + case TYPE_TRI: + *matrix = gmshGenerateInnerVertexPlacementTriangle(order); + break; + case TYPE_QUA: + *matrix = gmshGenerateInnerVertexPlacementQuadrangle(order); + break; + case TYPE_TET: + *matrix = gmshGenerateInnerVertexPlacementTetrahedron(order); + break; + case TYPE_PRI: + *matrix = gmshGenerateInnerVertexPlacementPrism(order); + break; + case TYPE_HEX: + *matrix = gmshGenerateInnerVertexPlacementHexahedron(order); + break; + case TYPE_PYR: + *matrix = gmshGenerateInnerVertexPlacementPyramid(order); + break; } - storedMatrices[type-3][order] = matrix; + storedMatrices[type - 3][order] = matrix; return matrix; } } - fullMatrix<double> gmshGenerateInnerVertexPlacementTriangle(int order) { - if (order < 3) return fullMatrix<double>(0, 0); + if(order < 3) return fullMatrix<double>(0, 0); const int szInc = 3 * order; const int szComp = (order + 1) * (order + 2) / 2; @@ -78,7 +74,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTriangle(int order) double2int(monomials, coordinates); std::map<std::pair<int, int>, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); coord2idx[std::make_pair(u, v)] = i; @@ -86,30 +82,30 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTriangle(int order) int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); - int q = n-u-v; + int q = n - u - v; double xi = (double)u / n; double eta = (double)v / n; double rho = (double)q / n; - M(i, coord2idx[std::make_pair(u+v, 0)]) += xi; - M(i, coord2idx[std::make_pair(u+q, v)]) += xi; - M(i, coord2idx[std::make_pair( 0, v+u)]) += eta; - M(i, coord2idx[std::make_pair( u, v+q)]) += eta; - M(i, coord2idx[std::make_pair( 0, v)]) += rho; - M(i, coord2idx[std::make_pair( u, 0)]) += rho; - M(i, coord2idx[std::make_pair( n, 0)]) -= xi; - M(i, coord2idx[std::make_pair( 0, n)]) -= eta; - M(i, coord2idx[std::make_pair( 0, 0)]) -= rho; + M(i, coord2idx[std::make_pair(u + v, 0)]) += xi; + M(i, coord2idx[std::make_pair(u + q, v)]) += xi; + M(i, coord2idx[std::make_pair(0, v + u)]) += eta; + M(i, coord2idx[std::make_pair(u, v + q)]) += eta; + M(i, coord2idx[std::make_pair(0, v)]) += rho; + M(i, coord2idx[std::make_pair(u, 0)]) += rho; + M(i, coord2idx[std::make_pair(n, 0)]) -= xi; + M(i, coord2idx[std::make_pair(0, n)]) -= eta; + M(i, coord2idx[std::make_pair(0, 0)]) -= rho; } return M; } fullMatrix<double> gmshGenerateInnerVertexPlacementQuadrangle(int order) { - if (order < 2) return fullMatrix<double>(0, 0); + if(order < 2) return fullMatrix<double>(0, 0); const int szInc = 4 * order; const int szComp = (order + 1) * (order + 1); @@ -120,7 +116,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementQuadrangle(int order) double2int(monomials, coordinates); std::map<std::pair<int, int>, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); coord2idx[std::make_pair(u, v)] = i; @@ -128,27 +124,27 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementQuadrangle(int order) int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); double xi = (double)u / n; double eta = (double)v / n; - M(i, coord2idx[std::make_pair(0, v)]) += 1-xi; + M(i, coord2idx[std::make_pair(0, v)]) += 1 - xi; M(i, coord2idx[std::make_pair(n, v)]) += xi; - M(i, coord2idx[std::make_pair(u, 0)]) += 1-eta; + M(i, coord2idx[std::make_pair(u, 0)]) += 1 - eta; M(i, coord2idx[std::make_pair(u, n)]) += eta; - M(i, coord2idx[std::make_pair(0, 0)]) -= (1-xi)*(1-eta); - M(i, coord2idx[std::make_pair(n, 0)]) -= xi*(1-eta); - M(i, coord2idx[std::make_pair(n, n)]) -= xi*eta; - M(i, coord2idx[std::make_pair(0, n)]) -= (1-xi)*eta; + M(i, coord2idx[std::make_pair(0, 0)]) -= (1 - xi) * (1 - eta); + M(i, coord2idx[std::make_pair(n, 0)]) -= xi * (1 - eta); + M(i, coord2idx[std::make_pair(n, n)]) -= xi * eta; + M(i, coord2idx[std::make_pair(0, n)]) -= (1 - xi) * eta; } return M; } fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedron(int order) { - if (order < 4) return fullMatrix<double>(0, 0); + if(order < 4) return fullMatrix<double>(0, 0); const int szInt = (order - 3) * (order - 2) * (order - 1) / 6; const int szComp = (order + 1) * (order + 2) * (order + 3) / 6; @@ -159,7 +155,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedron(int order) double2int(monomials, coordinates); std::map<mytuple, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); int w = coordinates(i, 2); @@ -168,38 +164,38 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedron(int order) int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); int w = coordinates(szInc + i, 2); - int q = n-u-v-w; + int q = n - u - v - w; double xi = (double)u / n; double eta = (double)v / n; double zeta = (double)w / n; double rho = (double)q / n; - M(i, coord2idx[make_mytuple(u+v, 0, w)]) += xi; - M(i, coord2idx[make_mytuple(u+w, v, 0)]) += xi; - M(i, coord2idx[make_mytuple(u+q, v, w)]) += xi; - M(i, coord2idx[make_mytuple(0, v+u, w)]) += eta; - M(i, coord2idx[make_mytuple(u, v+w, 0)]) += eta; - M(i, coord2idx[make_mytuple(u, v+q, w)]) += eta; - M(i, coord2idx[make_mytuple(0, v, w+u)]) += zeta; - M(i, coord2idx[make_mytuple(u, 0, w+v)]) += zeta; - M(i, coord2idx[make_mytuple(u, v, w+q)]) += zeta; + M(i, coord2idx[make_mytuple(u + v, 0, w)]) += xi; + M(i, coord2idx[make_mytuple(u + w, v, 0)]) += xi; + M(i, coord2idx[make_mytuple(u + q, v, w)]) += xi; + M(i, coord2idx[make_mytuple(0, v + u, w)]) += eta; + M(i, coord2idx[make_mytuple(u, v + w, 0)]) += eta; + M(i, coord2idx[make_mytuple(u, v + q, w)]) += eta; + M(i, coord2idx[make_mytuple(0, v, w + u)]) += zeta; + M(i, coord2idx[make_mytuple(u, 0, w + v)]) += zeta; + M(i, coord2idx[make_mytuple(u, v, w + q)]) += zeta; M(i, coord2idx[make_mytuple(0, v, w)]) += rho; M(i, coord2idx[make_mytuple(u, 0, w)]) += rho; M(i, coord2idx[make_mytuple(u, v, 0)]) += rho; - M(i, coord2idx[make_mytuple(n-q, 0, 0)]) -= xi; - M(i, coord2idx[make_mytuple(n-w, 0, w)]) -= xi; - M(i, coord2idx[make_mytuple(n-v, v, 0)]) -= xi; - M(i, coord2idx[make_mytuple(0, n-q, 0)]) -= eta; - M(i, coord2idx[make_mytuple(0, n-w, w)]) -= eta; - M(i, coord2idx[make_mytuple(u, n-u, 0)]) -= eta; - M(i, coord2idx[make_mytuple(0, 0, n-q)]) -= zeta; - M(i, coord2idx[make_mytuple(0, v, n-v)]) -= zeta; - M(i, coord2idx[make_mytuple(u, 0, n-u)]) -= zeta; + M(i, coord2idx[make_mytuple(n - q, 0, 0)]) -= xi; + M(i, coord2idx[make_mytuple(n - w, 0, w)]) -= xi; + M(i, coord2idx[make_mytuple(n - v, v, 0)]) -= xi; + M(i, coord2idx[make_mytuple(0, n - q, 0)]) -= eta; + M(i, coord2idx[make_mytuple(0, n - w, w)]) -= eta; + M(i, coord2idx[make_mytuple(u, n - u, 0)]) -= eta; + M(i, coord2idx[make_mytuple(0, 0, n - q)]) -= zeta; + M(i, coord2idx[make_mytuple(0, v, n - v)]) -= zeta; + M(i, coord2idx[make_mytuple(u, 0, n - u)]) -= zeta; M(i, coord2idx[make_mytuple(0, 0, w)]) -= rho; M(i, coord2idx[make_mytuple(0, v, 0)]) -= rho; M(i, coord2idx[make_mytuple(u, 0, 0)]) -= rho; @@ -214,7 +210,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedron(int order) fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedron(int order) { - if (order < 2) return fullMatrix<double>(0, 0); + if(order < 2) return fullMatrix<double>(0, 0); const int szInt = (order - 1) * (order - 1) * (order - 1); const int szComp = (order + 1) * (order + 1) * (order + 1); @@ -225,7 +221,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedron(int order) double2int(monomials, coordinates); std::map<mytuple, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); int w = coordinates(i, 2); @@ -234,7 +230,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedron(int order) int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); int w = coordinates(szInc + i, 2); @@ -242,33 +238,33 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedron(int order) double eta = (double)v / n; double zeta = (double)w / n; - M(i, coord2idx[make_mytuple(0, v, w)]) += 1-xi; + M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - xi; M(i, coord2idx[make_mytuple(n, v, w)]) += xi; - M(i, coord2idx[make_mytuple(u, 0, w)]) += 1-eta; + M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - eta; M(i, coord2idx[make_mytuple(u, n, w)]) += eta; - M(i, coord2idx[make_mytuple(u, v, 0)]) += 1-zeta; + M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - zeta; M(i, coord2idx[make_mytuple(u, v, n)]) += zeta; - M(i, coord2idx[make_mytuple(0, 0, w)]) -= (1-xi) * (1-eta); - M(i, coord2idx[make_mytuple(0, n, w)]) -= (1-xi) * eta; - M(i, coord2idx[make_mytuple(n, 0, w)]) -= xi * (1-eta); + M(i, coord2idx[make_mytuple(0, 0, w)]) -= (1 - xi) * (1 - eta); + M(i, coord2idx[make_mytuple(0, n, w)]) -= (1 - xi) * eta; + M(i, coord2idx[make_mytuple(n, 0, w)]) -= xi * (1 - eta); M(i, coord2idx[make_mytuple(n, n, w)]) -= xi * eta; - M(i, coord2idx[make_mytuple(u, 0, 0)]) -= (1-eta) * (1-zeta); - M(i, coord2idx[make_mytuple(u, 0, n)]) -= (1-eta) * zeta; - M(i, coord2idx[make_mytuple(u, n, 0)]) -= eta * (1-zeta); + M(i, coord2idx[make_mytuple(u, 0, 0)]) -= (1 - eta) * (1 - zeta); + M(i, coord2idx[make_mytuple(u, 0, n)]) -= (1 - eta) * zeta; + M(i, coord2idx[make_mytuple(u, n, 0)]) -= eta * (1 - zeta); M(i, coord2idx[make_mytuple(u, n, n)]) -= eta * zeta; - M(i, coord2idx[make_mytuple(0, v, 0)]) -= (1-zeta) * (1-xi); - M(i, coord2idx[make_mytuple(n, v, 0)]) -= (1-zeta) * xi; - M(i, coord2idx[make_mytuple(0, v, n)]) -= zeta * (1-xi); + M(i, coord2idx[make_mytuple(0, v, 0)]) -= (1 - zeta) * (1 - xi); + M(i, coord2idx[make_mytuple(n, v, 0)]) -= (1 - zeta) * xi; + M(i, coord2idx[make_mytuple(0, v, n)]) -= zeta * (1 - xi); M(i, coord2idx[make_mytuple(n, v, n)]) -= zeta * xi; - M(i, coord2idx[make_mytuple(0, 0, 0)]) += (1-xi) * (1-eta) * (1-zeta); - M(i, coord2idx[make_mytuple(0, 0, n)]) += (1-xi) * (1-eta) * zeta; - M(i, coord2idx[make_mytuple(0, n, 0)]) += (1-xi) * eta * (1-zeta); - M(i, coord2idx[make_mytuple(0, n, n)]) += (1-xi) * eta * zeta; - M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi * (1-eta) * (1-zeta); - M(i, coord2idx[make_mytuple(n, 0, n)]) += xi * (1-eta) * zeta; - M(i, coord2idx[make_mytuple(n, n, 0)]) += xi * eta * (1-zeta); + M(i, coord2idx[make_mytuple(0, 0, 0)]) += (1 - xi) * (1 - eta) * (1 - zeta); + M(i, coord2idx[make_mytuple(0, 0, n)]) += (1 - xi) * (1 - eta) * zeta; + M(i, coord2idx[make_mytuple(0, n, 0)]) += (1 - xi) * eta * (1 - zeta); + M(i, coord2idx[make_mytuple(0, n, n)]) += (1 - xi) * eta * zeta; + M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi * (1 - eta) * (1 - zeta); + M(i, coord2idx[make_mytuple(n, 0, n)]) += xi * (1 - eta) * zeta; + M(i, coord2idx[make_mytuple(n, n, 0)]) += xi * eta * (1 - zeta); M(i, coord2idx[make_mytuple(n, n, n)]) += xi * eta * zeta; } return M; @@ -276,7 +272,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedron(int order) fullMatrix<double> gmshGenerateInnerVertexPlacementPrism(int order) { - if (order < 3) return fullMatrix<double>(0, 0); + if(order < 3) return fullMatrix<double>(0, 0); const int szInt = (order - 1) * (order - 2) * (order - 1) / 2; const int szComp = (order + 1) * (order + 1) * (order + 2) / 2; @@ -287,7 +283,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementPrism(int order) double2int(monomials, coordinates); std::map<mytuple, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); int w = coordinates(i, 2); @@ -296,44 +292,44 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementPrism(int order) int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); int w = coordinates(szInc + i, 2); - int q = n-u-v; + int q = n - u - v; double xi = (double)u / n; double eta = (double)v / n; double zeta = (double)w / n; double rho = (double)q / n; - M(i, coord2idx[make_mytuple(u+v, 0, w)]) += xi; - M(i, coord2idx[make_mytuple(u+q, v, w)]) += xi; - M(i, coord2idx[make_mytuple(0, v+u, w)]) += eta; - M(i, coord2idx[make_mytuple(u, v+q, w)]) += eta; + M(i, coord2idx[make_mytuple(u + v, 0, w)]) += xi; + M(i, coord2idx[make_mytuple(u + q, v, w)]) += xi; + M(i, coord2idx[make_mytuple(0, v + u, w)]) += eta; + M(i, coord2idx[make_mytuple(u, v + q, w)]) += eta; M(i, coord2idx[make_mytuple(0, v, w)]) += rho; M(i, coord2idx[make_mytuple(u, 0, w)]) += rho; - M(i, coord2idx[make_mytuple(u, v, 0)]) += 1-zeta; + M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - zeta; M(i, coord2idx[make_mytuple(u, v, n)]) += zeta; M(i, coord2idx[make_mytuple(n, 0, w)]) -= xi; M(i, coord2idx[make_mytuple(0, n, w)]) -= eta; M(i, coord2idx[make_mytuple(0, 0, w)]) -= rho; - M(i, coord2idx[make_mytuple(u+v, 0, 0)]) -= xi * (1-zeta); - M(i, coord2idx[make_mytuple(u+q, v, 0)]) -= xi * (1-zeta); - M(i, coord2idx[make_mytuple(0, v+u, 0)]) -= eta * (1-zeta); - M(i, coord2idx[make_mytuple(u, v+q, 0)]) -= eta * (1-zeta); - M(i, coord2idx[make_mytuple(0, v, 0)]) -= rho * (1-zeta); - M(i, coord2idx[make_mytuple(u, 0, 0)]) -= rho * (1-zeta); - M(i, coord2idx[make_mytuple(u+v, 0, n)]) -= xi * zeta; - M(i, coord2idx[make_mytuple(u+q, v, n)]) -= xi * zeta; - M(i, coord2idx[make_mytuple(0, v+u, n)]) -= eta * zeta; - M(i, coord2idx[make_mytuple(u, v+q, n)]) -= eta * zeta; + M(i, coord2idx[make_mytuple(u + v, 0, 0)]) -= xi * (1 - zeta); + M(i, coord2idx[make_mytuple(u + q, v, 0)]) -= xi * (1 - zeta); + M(i, coord2idx[make_mytuple(0, v + u, 0)]) -= eta * (1 - zeta); + M(i, coord2idx[make_mytuple(u, v + q, 0)]) -= eta * (1 - zeta); + M(i, coord2idx[make_mytuple(0, v, 0)]) -= rho * (1 - zeta); + M(i, coord2idx[make_mytuple(u, 0, 0)]) -= rho * (1 - zeta); + M(i, coord2idx[make_mytuple(u + v, 0, n)]) -= xi * zeta; + M(i, coord2idx[make_mytuple(u + q, v, n)]) -= xi * zeta; + M(i, coord2idx[make_mytuple(0, v + u, n)]) -= eta * zeta; + M(i, coord2idx[make_mytuple(u, v + q, n)]) -= eta * zeta; M(i, coord2idx[make_mytuple(0, v, n)]) -= rho * zeta; M(i, coord2idx[make_mytuple(u, 0, n)]) -= rho * zeta; - M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi * (1-zeta); - M(i, coord2idx[make_mytuple(0, n, 0)]) += eta * (1-zeta); - M(i, coord2idx[make_mytuple(0, 0, 0)]) += rho * (1-zeta); + M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi * (1 - zeta); + M(i, coord2idx[make_mytuple(0, n, 0)]) += eta * (1 - zeta); + M(i, coord2idx[make_mytuple(0, 0, 0)]) += rho * (1 - zeta); M(i, coord2idx[make_mytuple(n, 0, n)]) += xi * zeta; M(i, coord2idx[make_mytuple(0, n, n)]) += eta * zeta; M(i, coord2idx[make_mytuple(0, 0, n)]) += rho * zeta; @@ -343,10 +339,11 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementPrism(int order) fullMatrix<double> gmshGenerateInnerVertexPlacementPyramid(int order) { - if (order < 3) return fullMatrix<double>(0, 0); + if(order < 3) return fullMatrix<double>(0, 0); - const int szInt = (order-2) * ((order-2)+1) * (2*(order-2)+1) / 6; - const int szComp = (order+1) * ((order+1)+1) * (2*(order+1)+1) / 6; + const int szInt = (order - 2) * ((order - 2) + 1) * (2 * (order - 2) + 1) / 6; + const int szComp = + (order + 1) * ((order + 1) + 1) * (2 * (order + 1) + 1) / 6; const int szInc = szComp - szInt; fullMatrix<double> monomials = gmshGenerateMonomialsPyramid(order, false); @@ -354,7 +351,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementPyramid(int order) double2int(monomials, coordinates); std::map<mytuple, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); int w = order - coordinates(i, 2); @@ -363,43 +360,43 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementPyramid(int order) int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); int w = order - coordinates(szInc + i, 2); - int q = n-u-w; - int r = n-v-w; + int q = n - u - w; + int r = n - v - w; double xi = (double)u / n; double eta = (double)v / n; double rho = (double)q / n; double tau = (double)r / n; - double xip = (double)u / (n-w); - double etap = (double)v / (n-w); + double xip = (double)u / (n - w); + double etap = (double)v / (n - w); // lateral faces - M(i, coord2idx[make_mytuple(0, v, w)]) += 1-xip; - M(i, coord2idx[make_mytuple(u, 0, w)]) += 1-etap; - M(i, coord2idx[make_mytuple(n-w, v, w)]) += xip; - M(i, coord2idx[make_mytuple(u, n-w, w)]) += etap; + M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - xip; + M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - etap; + M(i, coord2idx[make_mytuple(n - w, v, w)]) += xip; + M(i, coord2idx[make_mytuple(u, n - w, w)]) += etap; // basis face M(i, coord2idx[make_mytuple(u, v, 0)]) += rho * tau; - M(i, coord2idx[make_mytuple(u+w, v, 0)]) += xi * tau; - M(i, coord2idx[make_mytuple(u+w, v+w, 0)]) += xi * eta; - M(i, coord2idx[make_mytuple(u, v+w, 0)]) += rho * eta; + M(i, coord2idx[make_mytuple(u + w, v, 0)]) += xi * tau; + M(i, coord2idx[make_mytuple(u + w, v + w, 0)]) += xi * eta; + M(i, coord2idx[make_mytuple(u, v + w, 0)]) += rho * eta; // vertical edges - M(i, coord2idx[make_mytuple(0, 0, w)]) -= (1-xip) * (1-etap); - M(i, coord2idx[make_mytuple(n-w, 0, w)]) -= xip * (1-etap); - M(i, coord2idx[make_mytuple(n-w, n-w, w)]) -= xip * etap; - M(i, coord2idx[make_mytuple(0, n-w, w)]) -= (1-xip) * etap; + M(i, coord2idx[make_mytuple(0, 0, w)]) -= (1 - xip) * (1 - etap); + M(i, coord2idx[make_mytuple(n - w, 0, w)]) -= xip * (1 - etap); + M(i, coord2idx[make_mytuple(n - w, n - w, w)]) -= xip * etap; + M(i, coord2idx[make_mytuple(0, n - w, w)]) -= (1 - xip) * etap; // basis edges M(i, coord2idx[make_mytuple(0, v, 0)]) -= rho * tau; M(i, coord2idx[make_mytuple(u, 0, 0)]) -= rho * tau; - M(i, coord2idx[make_mytuple(u+w, 0, 0)]) -= xi * tau; + M(i, coord2idx[make_mytuple(u + w, 0, 0)]) -= xi * tau; M(i, coord2idx[make_mytuple(n, v, 0)]) -= xi * tau; - M(i, coord2idx[make_mytuple(n, v+w, 0)]) -= xi * eta; - M(i, coord2idx[make_mytuple(u+w, n, 0)]) -= xi * eta; + M(i, coord2idx[make_mytuple(n, v + w, 0)]) -= xi * eta; + M(i, coord2idx[make_mytuple(u + w, n, 0)]) -= xi * eta; M(i, coord2idx[make_mytuple(u, n, 0)]) -= rho * eta; - M(i, coord2idx[make_mytuple(0, v+w, 0)]) -= rho * eta; + M(i, coord2idx[make_mytuple(0, v + w, 0)]) -= rho * eta; // basis corners M(i, coord2idx[make_mytuple(0, 0, 0)]) += rho * tau; M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi * tau; @@ -409,11 +406,10 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementPyramid(int order) return M; } - fullMatrix<double> gmshGenerateInnerVertexPlacementTriangleLinear(int order, int dir) { - if (order < 3) return fullMatrix<double>(0, 0); + if(order < 3) return fullMatrix<double>(0, 0); const int szInc = 3 * order; const int szComp = (order + 1) * (order + 2) / 2; @@ -424,7 +420,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTriangleLinear(int order, double2int(monomials, coordinates); std::map<std::pair<int, int>, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); coord2idx[std::make_pair(u, v)] = i; @@ -432,28 +428,28 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTriangleLinear(int order, int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); double mu; - switch (dir) { - case 0: - mu = (double)u / (n-v); - M(i, coord2idx[std::make_pair( 0, v)]) += 1-mu; - M(i, coord2idx[std::make_pair(n-v, v)]) += mu; - break; - case 1: - mu = (double)v / (u+v); - M(i, coord2idx[std::make_pair(u+v, 0)]) += 1-mu; - M(i, coord2idx[std::make_pair( 0, u+v)]) += mu; - break; - default: - case 2: - mu = (double)v / (n-u); - M(i, coord2idx[std::make_pair(u, 0)]) += 1-mu; - M(i, coord2idx[std::make_pair(u, n-u)]) += mu; - break; + switch(dir) { + case 0: + mu = (double)u / (n - v); + M(i, coord2idx[std::make_pair(0, v)]) += 1 - mu; + M(i, coord2idx[std::make_pair(n - v, v)]) += mu; + break; + case 1: + mu = (double)v / (u + v); + M(i, coord2idx[std::make_pair(u + v, 0)]) += 1 - mu; + M(i, coord2idx[std::make_pair(0, u + v)]) += mu; + break; + default: + case 2: + mu = (double)v / (n - u); + M(i, coord2idx[std::make_pair(u, 0)]) += 1 - mu; + M(i, coord2idx[std::make_pair(u, n - u)]) += mu; + break; } } @@ -462,7 +458,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTriangleLinear(int order, fullMatrix<double> gmshGenerateInnerVertexPlacementQuadrangleLinear(int order) { - if (order < 2) return fullMatrix<double>(0, 0); + if(order < 2) return fullMatrix<double>(0, 0); const int szInc = 4 * order; const int szComp = (order + 1) * (order + 1); @@ -473,7 +469,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementQuadrangleLinear(int order) double2int(monomials, coordinates); std::map<std::pair<int, int>, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); coord2idx[std::make_pair(u, v)] = i; @@ -481,12 +477,12 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementQuadrangleLinear(int order) int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); double eta = (double)v / n; - M(i, coord2idx[std::make_pair(u, 0)]) += 1-eta; + M(i, coord2idx[std::make_pair(u, 0)]) += 1 - eta; M(i, coord2idx[std::make_pair(u, n)]) += eta; } return M; @@ -496,7 +492,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedronLinear(int order, int dir) { // 'dir' corresponds to the number of edge - if (order < 4) return fullMatrix<double>(0, 0); + if(order < 4) return fullMatrix<double>(0, 0); const int szInt = (order - 3) * (order - 2) * (order - 1) / 6; const int szComp = (order + 1) * (order + 2) * (order + 3) / 6; @@ -507,7 +503,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedronLinear(int order, double2int(monomials, coordinates); std::map<mytuple, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); int w = coordinates(i, 2); @@ -516,44 +512,44 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedronLinear(int order, int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); int w = coordinates(szInc + i, 2); double mu; - switch (dir) { - case 0: - mu = (double)u / (n-v-w); - M(i, coord2idx[make_mytuple( 0, v, w)]) += 1-mu; - M(i, coord2idx[make_mytuple(n-v-w, v, w)]) += mu; - break; - case 2: - mu = (double)v / (n-u-w); - M(i, coord2idx[make_mytuple(u, 0, w)]) += 1-mu; - M(i, coord2idx[make_mytuple(u, n-u-w, w)]) += mu; - break; - default: - case 3: - mu = (double)w / (n-u-v); - M(i, coord2idx[make_mytuple(u, v, 0)]) += 1-mu; - M(i, coord2idx[make_mytuple(u, v, n-u-v)]) += mu; - break; - case 1: - mu = (double)v / (u+v); - M(i, coord2idx[make_mytuple(u+v, 0, w)]) += 1-mu; - M(i, coord2idx[make_mytuple( 0, u+v, w)]) += mu; - break; - case 4: - mu = (double)w / (v+w); - M(i, coord2idx[make_mytuple(u, v+w, 0)]) += 1-mu; - M(i, coord2idx[make_mytuple(u, 0, v+w)]) += mu; - break; - case 5: - mu = (double)w / (u+w); - M(i, coord2idx[make_mytuple(u+w, v, 0)]) += 1-mu; - M(i, coord2idx[make_mytuple( 0, v, u+w)]) += mu; - break; + switch(dir) { + case 0: + mu = (double)u / (n - v - w); + M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - mu; + M(i, coord2idx[make_mytuple(n - v - w, v, w)]) += mu; + break; + case 2: + mu = (double)v / (n - u - w); + M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - mu; + M(i, coord2idx[make_mytuple(u, n - u - w, w)]) += mu; + break; + default: + case 3: + mu = (double)w / (n - u - v); + M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - mu; + M(i, coord2idx[make_mytuple(u, v, n - u - v)]) += mu; + break; + case 1: + mu = (double)v / (u + v); + M(i, coord2idx[make_mytuple(u + v, 0, w)]) += 1 - mu; + M(i, coord2idx[make_mytuple(0, u + v, w)]) += mu; + break; + case 4: + mu = (double)w / (v + w); + M(i, coord2idx[make_mytuple(u, v + w, 0)]) += 1 - mu; + M(i, coord2idx[make_mytuple(u, 0, v + w)]) += mu; + break; + case 5: + mu = (double)w / (u + w); + M(i, coord2idx[make_mytuple(u + w, v, 0)]) += 1 - mu; + M(i, coord2idx[make_mytuple(0, v, u + w)]) += mu; + break; } } return M; @@ -562,7 +558,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedronLinear(int order, fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedronLinear(int order, int dir) { - if (order < 2) return fullMatrix<double>(0, 0); + if(order < 2) return fullMatrix<double>(0, 0); const int szInt = (order - 1) * (order - 1) * (order - 1); const int szComp = (order + 1) * (order + 1) * (order + 1); @@ -573,7 +569,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedronLinear(int order, double2int(monomials, coordinates); std::map<mytuple, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); int w = coordinates(i, 2); @@ -582,37 +578,38 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedronLinear(int order, int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); int w = coordinates(szInc + i, 2); double eta; - switch (dir) { - case 0: - eta = (double)u / n; - M(i, coord2idx[make_mytuple(0, v, w)]) += 1-eta; - M(i, coord2idx[make_mytuple(n, v, w)]) += eta; - break; - case 1: - eta = (double)v / n; - M(i, coord2idx[make_mytuple(u, 0, w)]) += 1-eta; - M(i, coord2idx[make_mytuple(u, n, w)]) += eta; - break; - default: - case 2: - eta = (double)w / n; - M(i, coord2idx[make_mytuple(u, v, 0)]) += 1-eta; - M(i, coord2idx[make_mytuple(u, v, n)]) += eta; - break; + switch(dir) { + case 0: + eta = (double)u / n; + M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - eta; + M(i, coord2idx[make_mytuple(n, v, w)]) += eta; + break; + case 1: + eta = (double)v / n; + M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - eta; + M(i, coord2idx[make_mytuple(u, n, w)]) += eta; + break; + default: + case 2: + eta = (double)w / n; + M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - eta; + M(i, coord2idx[make_mytuple(u, v, n)]) += eta; + break; } } return M; } -fullMatrix<double> gmshGenerateInnerVertexPlacementPrismLinear(int order, int dir) +fullMatrix<double> gmshGenerateInnerVertexPlacementPrismLinear(int order, + int dir) { - if (order < 3) return fullMatrix<double>(0, 0); + if(order < 3) return fullMatrix<double>(0, 0); const int szInt = (order - 1) * (order - 2) * (order - 1) / 2; const int szComp = (order + 1) * (order + 1) * (order + 2) / 2; @@ -623,7 +620,7 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementPrismLinear(int order, int di double2int(monomials, coordinates); std::map<mytuple, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = coordinates(i, 0); int v = coordinates(i, 1); int w = coordinates(i, 2); @@ -632,34 +629,34 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementPrismLinear(int order, int di int &n = order; fullMatrix<double> M(szInt, szInc, true); - for (int i = 0; i < szInt; ++i) { + for(int i = 0; i < szInt; ++i) { int u = coordinates(szInc + i, 0); int v = coordinates(szInc + i, 1); int w = coordinates(szInc + i, 2); double eta, mu; - - switch (dir) { - case 0: - mu = (double)u / (n-v); - M(i, coord2idx[make_mytuple( 0, v, w)]) += 1-mu; - M(i, coord2idx[make_mytuple(n-v, v, w)]) += mu; - break; - case 1: - mu = (double)v / (u+v); - M(i, coord2idx[make_mytuple(u+v, 0, w)]) += 1-mu; - M(i, coord2idx[make_mytuple( 0, u+v, w)]) += mu; - break; - case 2: - mu = (double)v / (n-u); - M(i, coord2idx[make_mytuple(u, 0, w)]) += 1-mu; - M(i, coord2idx[make_mytuple(u, n-u, w)]) += mu; - break; - default: - case 3: - eta = (double)w / n; - M(i, coord2idx[make_mytuple(u, v, 0)]) += 1-eta; - M(i, coord2idx[make_mytuple(u, v, n)]) += eta; - break; + + switch(dir) { + case 0: + mu = (double)u / (n - v); + M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - mu; + M(i, coord2idx[make_mytuple(n - v, v, w)]) += mu; + break; + case 1: + mu = (double)v / (u + v); + M(i, coord2idx[make_mytuple(u + v, 0, w)]) += 1 - mu; + M(i, coord2idx[make_mytuple(0, u + v, w)]) += mu; + break; + case 2: + mu = (double)v / (n - u); + M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - mu; + M(i, coord2idx[make_mytuple(u, n - u, w)]) += mu; + break; + default: + case 3: + eta = (double)w / n; + M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - eta; + M(i, coord2idx[make_mytuple(u, v, n)]) += eta; + break; } } return M; diff --git a/Numeric/InnerVertexPlacement.h b/Numeric/InnerVertexPlacement.h index 8daf2e8b0af31a4433a3c9225292a712b14bfbeb..9c38435932ab408212f587e8c79dfcdc37e45d51 100644 --- a/Numeric/InnerVertexPlacement.h +++ b/Numeric/InnerVertexPlacement.h @@ -15,7 +15,7 @@ // TODO Amaury: Create sparseMatrix? -fullMatrix<double>* getInnerVertexPlacement(int type, int order); +fullMatrix<double> *getInnerVertexPlacement(int type, int order); fullMatrix<double> gmshGenerateInnerVertexPlacementTriangle(int order); fullMatrix<double> gmshGenerateInnerVertexPlacementQuadrangle(int order); @@ -24,10 +24,14 @@ fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedron(int order); fullMatrix<double> gmshGenerateInnerVertexPlacementPrism(int order); fullMatrix<double> gmshGenerateInnerVertexPlacementPyramid(int order); -fullMatrix<double> gmshGenerateInnerVertexPlacementTriangleLinear(int order, int dir); +fullMatrix<double> gmshGenerateInnerVertexPlacementTriangleLinear(int order, + int dir); fullMatrix<double> gmshGenerateInnerVertexPlacementQuadrangleLinear(int order); -fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedronLinear(int order, int dir); -fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedronLinear(int order, int dir); -fullMatrix<double> gmshGenerateInnerVertexPlacementPrismLinear(int order, int dir); - -#endif //GMSH_INTERIORVERTEXPLACEMENT_H +fullMatrix<double> gmshGenerateInnerVertexPlacementTetrahedronLinear(int order, + int dir); +fullMatrix<double> gmshGenerateInnerVertexPlacementHexahedronLinear(int order, + int dir); +fullMatrix<double> gmshGenerateInnerVertexPlacementPrismLinear(int order, + int dir); + +#endif // GMSH_INTERIORVERTEXPLACEMENT_H diff --git a/Numeric/Iso.cpp b/Numeric/Iso.cpp index f508a76a04090f21acd45a731a3a0311e556d919..56b5e65923d81ae60fad21b0f259af75d6d98813 100644 --- a/Numeric/Iso.cpp +++ b/Numeric/Iso.cpp @@ -5,17 +5,16 @@ #include "Numeric.h" -static void affect(double *xi, double *yi, double *zi, int i, - double *xp, double *yp, double *zp, int j) +static void affect(double *xi, double *yi, double *zi, int i, double *xp, + double *yp, double *zp, int j) { xi[i] = xp[j]; yi[i] = yp[j]; zi[i] = zp[j]; } -double InterpolateIso(double *X, double *Y, double *Z, - double *Val, double V, int I1, int I2, - double *XI, double *YI, double *ZI) +double InterpolateIso(double *X, double *Y, double *Z, double *Val, double V, + int I1, int I2, double *XI, double *YI, double *ZI) { if(Val[I1] == Val[I2]) { *XI = X[I1]; @@ -34,11 +33,10 @@ double InterpolateIso(double *X, double *Y, double *Z, // Compute an iso-point in a line -int IsoLine(double *X, double *Y, double *Z, double *Val, double V, - double *Xp, double *Yp, double *Zp) +int IsoLine(double *X, double *Y, double *Z, double *Val, double V, double *Xp, + double *Yp, double *Zp) { - if(Val[0] == Val[1]) - return 0; + if(Val[0] == Val[1]) return 0; if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) { InterpolateIso(X, Y, Z, Val, V, 0, 1, Xp, Yp, Zp); @@ -77,8 +75,7 @@ int IsoTriangle(double *X, double *Y, double *Z, double *Val, double V, int IsoSimplex(double *X, double *Y, double *Z, double *Val, double V, double *Xp, double *Yp, double *Zp, double n[3]) { - if(Val[0] == Val[1] && Val[0] == Val[2] && Val[0] == Val[3]) - return 0; + if(Val[0] == Val[1] && Val[0] == Val[2] && Val[0] == Val[3]) return 0; int nb = 0; if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) { @@ -116,8 +113,7 @@ int IsoSimplex(double *X, double *Y, double *Z, double *Val, double V, int ni = 1; for(int j = 1; j < nb; j++) { for(int i = 0; i < ni; i++) { - if(fabs(Xp[j] - xi[i]) < 1.e-12 && - fabs(Yp[j] - yi[i]) < 1.e-12 && + if(fabs(Xp[j] - xi[i]) < 1.e-12 && fabs(Yp[j] - yi[i]) < 1.e-12 && fabs(Zp[j] - zi[i]) < 1.e-12) { break; } @@ -127,13 +123,11 @@ int IsoSimplex(double *X, double *Y, double *Z, double *Val, double V, } } } - for(int i = 0; i < ni; i++) - affect(Xp, Yp, Zp, i, xi, yi, zi, i); + for(int i = 0; i < ni; i++) affect(Xp, Yp, Zp, i, xi, yi, zi, i); nb = ni; } - if(nb < 3 || nb > 4) - return 0; + if(nb < 3 || nb > 4) return 0; // 3 possible quads at this point: (0,2,5,3), (0,1,5,4) or // (1,2,4,3), so simply invert the 2 last vertices for having the @@ -183,8 +177,7 @@ int IsoSimplex(double *X, double *Y, double *Z, double *Val, double V, // Compute the line between the two iso-points V1 and V2 in a line -int CutLine(double *X, double *Y, double *Z, double *Val, - double V1, double V2, +int CutLine(double *X, double *Y, double *Z, double *Val, double V1, double V2, double *Xp2, double *Yp2, double *Zp2, double *Vp2) { int io[2]; @@ -237,9 +230,8 @@ int CutLine(double *X, double *Y, double *Z, double *Val, // Compute the polygon between the two iso-lines V1 and V2 in a // triangle -int CutTriangle(double *X, double *Y, double *Z, double *Val, - double V1, double V2, - double *Xp2, double *Yp2, double *Zp2, double *Vp2) +int CutTriangle(double *X, double *Y, double *Z, double *Val, double V1, + double V2, double *Xp2, double *Yp2, double *Zp2, double *Vp2) { // fill io so that it contains an indexing of the nodes such that // Val[io[i]] > Val[io[j]] if i > j @@ -346,7 +338,7 @@ int CutTriangle(double *X, double *Y, double *Z, double *Val, for(int i = 1; i < Np; i++) { if((Xp[i] != Xp2[Np2 - 1]) || (Yp[i] != Yp2[Np2 - 1]) || - (Zp[i] != Zp2[Np2 - 1])){ + (Zp[i] != Zp2[Np2 - 1])) { Vp2[Np2] = Vp[i]; Xp2[Np2] = Xp[i]; Yp2[Np2] = Yp[i]; @@ -370,14 +362,14 @@ int CutTriangle(double *X, double *Y, double *Z, double *Val, double outn[3]; prodve(out1, out2, outn); - if(prosca(inn, outn) < 0.0){ - for(int i = 0; i < Np2; i++){ + if(prosca(inn, outn) < 0.0) { + for(int i = 0; i < Np2; i++) { Vp[i] = Vp2[Np2 - i - 1]; Xp[i] = Xp2[Np2 - i - 1]; Yp[i] = Yp2[Np2 - i - 1]; Zp[i] = Zp2[Np2 - i - 1]; } - for(int i = 0; i < Np2; i++){ + for(int i = 0; i < Np2; i++) { Vp2[i] = Vp[i]; Xp2[i] = Xp[i]; Yp2[i] = Yp[i]; diff --git a/Numeric/Iso.h b/Numeric/Iso.h index 2aecb3b865524e0abac307a5bbc986394ee6c4bf..00a824279f7c823456edc045e04719d38990ad58 100644 --- a/Numeric/Iso.h +++ b/Numeric/Iso.h @@ -6,25 +6,22 @@ #ifndef _ISO_H_ #define _ISO_H_ -double InterpolateIso(double *X, double *Y, double *Z, - double *Val, double V, int I1, int I2, - double *XI, double *YI ,double *ZI); +double InterpolateIso(double *X, double *Y, double *Z, double *Val, double V, + int I1, int I2, double *XI, double *YI, double *ZI); -int IsoLine(double *X, double *Y, double *Z, double *Val, double V, - double *Xp, double *Yp, double *Zp); +int IsoLine(double *X, double *Y, double *Z, double *Val, double V, double *Xp, + double *Yp, double *Zp); -int IsoTriangle(double *X, double *Y, double *Z, double *Val, double V, +int IsoTriangle(double *X, double *Y, double *Z, double *Val, double V, double *Xp, double *Yp, double *Zp); int IsoSimplex(double *X, double *Y, double *Z, double *Val, double V, double *Xp, double *Yp, double *Zp, double n[3]); -int CutLine(double *x, double *y, double *z, double *v, - double min, double max, +int CutLine(double *x, double *y, double *z, double *v, double min, double max, double *xp, double *yp, double *zp, double *vp); -int CutTriangle(double *x, double *y, double *z, double *v, - double min, double max, - double *xp, double *yp, double *zp, double *vp); +int CutTriangle(double *x, double *y, double *z, double *v, double min, + double max, double *xp, double *yp, double *zp, double *vp); #endif diff --git a/Numeric/JacobianBasis.cpp b/Numeric/JacobianBasis.cpp index f0f3dcea2844b1da5209aeb8688966d2f6a1cb6c..e430f82525072aa0cfc4a274bd6be4453e788850 100644 --- a/Numeric/JacobianBasis.cpp +++ b/Numeric/JacobianBasis.cpp @@ -13,146 +13,127 @@ namespace { - template<class T> + template <class T> void calcMapFromIdealElement(int type, T &gSMatX, T &gSMatY, T &gSMatZ) { // 2D scaling - switch(type){ + switch(type) { case TYPE_QUA: case TYPE_HEX: - case TYPE_PYR: - { // Quad, hex, pyramid -> square with side of length 1 - gSMatX.scale(2.); - gSMatY.scale(2.); - break; - } - default: - { // Tri, tet, prism: equilateral tri with side of length 1 - static const double cTri[2] = {-1./std::sqrt(3.), 2./std::sqrt(3.)}; - gSMatY.scale(cTri[1]); - gSMatY.axpy(gSMatX, cTri[0]); - break; - } + case TYPE_PYR: { // Quad, hex, pyramid -> square with side of length 1 + gSMatX.scale(2.); + gSMatY.scale(2.); + break; + } + default: { // Tri, tet, prism: equilateral tri with side of length 1 + static const double cTri[2] = {-1. / std::sqrt(3.), 2. / std::sqrt(3.)}; + gSMatY.scale(cTri[1]); + gSMatY.axpy(gSMatX, cTri[0]); + break; + } } // 3D scaling - switch(type){ + switch(type) { case TYPE_HEX: - case TYPE_PRI: - { // Hex, prism -> side of length 1 in z - gSMatZ.scale(2.); - break; - } - case TYPE_PYR: - { // Pyramid -> height sqrt(2.)/2 - static const double cPyr = sqrt(2.); - gSMatZ.scale(cPyr); - break; - } - case TYPE_TET: - { // Tet: take into account (x, y) scaling to obtain regular tet - static const double cTet[3] = {-3./2/std::sqrt(6.), - -1./2/std::sqrt(2.), - std::sqrt(1.5)}; - gSMatZ.scale(cTet[2]); - gSMatZ.axpy(gSMatX, cTet[0]); - gSMatZ.axpy(gSMatY, cTet[1]); - break; - } + case TYPE_PRI: { // Hex, prism -> side of length 1 in z + gSMatZ.scale(2.); + break; + } + case TYPE_PYR: { // Pyramid -> height sqrt(2.)/2 + static const double cPyr = sqrt(2.); + gSMatZ.scale(cPyr); + break; + } + case TYPE_TET: { // Tet: take into account (x, y) scaling to obtain regular + // tet + static const double cTet[3] = {-3. / 2 / std::sqrt(6.), + -1. / 2 / std::sqrt(2.), std::sqrt(1.5)}; + gSMatZ.scale(cTet[2]); + gSMatZ.axpy(gSMatX, cTet[0]); + gSMatZ.axpy(gSMatY, cTet[1]); + break; + } } } // Compute the determinant of a 3x3 matrix - inline double calcDet3D(double M11, double M12, double M13, - double M21, double M22, double M23, - double M31, double M32, double M33) + inline double calcDet3D(double M11, double M12, double M13, double M21, + double M22, double M23, double M31, double M32, + double M33) { - return M11 * (M22*M33 - M23*M32) - - M12 * (M21*M33 - M23*M31) - + M13 * (M21*M32 - M22*M31); + return M11 * (M22 * M33 - M23 * M32) - M12 * (M21 * M33 - M23 * M31) + + M13 * (M21 * M32 - M22 * M31); } // Compute signed Jacobian and its gradients w.r.t. node positions, at one // location in a 1D element - inline void calcJDJ1D(double dxdX, double dxdY, double dxdZ, - double dydX, double dydY, double dydZ, - double dzdX, double dzdY, double dzdZ, - int i, int numMapNodes, + inline void calcJDJ1D(double dxdX, double dxdY, double dxdZ, double dydX, + double dydY, double dydZ, double dzdX, double dzdY, + double dzdZ, int i, int numMapNodes, const fullMatrix<double> &gSMatX, fullMatrix<double> &JDJ) { - for(int j = 0; j < numMapNodes; j++){ + for(int j = 0; j < numMapNodes; j++) { const double &dPhidX = gSMatX(i, j); JDJ(i, j) = dPhidX * dydY * dzdZ + dPhidX * dzdY * dydZ; - JDJ(i, j+numMapNodes) = dPhidX * dzdY * dxdZ - dPhidX * dxdY * dzdZ; - JDJ(i, j+2*numMapNodes) = dPhidX * dxdY * dydZ - dPhidX * dydY * dxdZ; + JDJ(i, j + numMapNodes) = dPhidX * dzdY * dxdZ - dPhidX * dxdY * dzdZ; + JDJ(i, j + 2 * numMapNodes) = dPhidX * dxdY * dydZ - dPhidX * dydY * dxdZ; } - JDJ(i, 3*numMapNodes) = calcDet3D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ); + JDJ(i, 3 * numMapNodes) = + calcDet3D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ); } // Compute signed Jacobian and its gradients w.r.t. node positions, at one // location in a 2D element - inline void calcJDJ2D(double dxdX, double dxdY, double dxdZ, - double dydX, double dydY, double dydZ, - double dzdX, double dzdY, double dzdZ, - int i, int numMapNodes, + inline void calcJDJ2D(double dxdX, double dxdY, double dxdZ, double dydX, + double dydY, double dydZ, double dzdX, double dzdY, + double dzdZ, int i, int numMapNodes, const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, fullMatrix<double> &JDJ) { - for(int j = 0; j < numMapNodes; j++){ + for(int j = 0; j < numMapNodes; j++) { const double &dPhidX = gSMatX(i, j); const double &dPhidY = gSMatY(i, j); - JDJ(i, j) = - dPhidX * dydY * dzdZ + dzdX * dPhidY * dydZ + - dPhidX * dzdY * dydZ - dydX * dPhidY * dzdZ; - JDJ(i, j+numMapNodes) = - dxdX * dPhidY * dzdZ + - dPhidX * dzdY * dxdZ - dzdX * dPhidY * dxdZ - - dPhidX * dxdY * dzdZ; - JDJ(i, j+2*numMapNodes) = - dPhidX * dxdY * dydZ + - dydX * dPhidY * dxdZ - dPhidX * dydY * dxdZ - - dxdX * dPhidY * dydZ; + JDJ(i, j) = dPhidX * dydY * dzdZ + dzdX * dPhidY * dydZ + + dPhidX * dzdY * dydZ - dydX * dPhidY * dzdZ; + JDJ(i, j + numMapNodes) = dxdX * dPhidY * dzdZ + dPhidX * dzdY * dxdZ - + dzdX * dPhidY * dxdZ - dPhidX * dxdY * dzdZ; + JDJ(i, j + 2 * numMapNodes) = dPhidX * dxdY * dydZ + + dydX * dPhidY * dxdZ - + dPhidX * dydY * dxdZ - dxdX * dPhidY * dydZ; } - JDJ(i, 3*numMapNodes) = calcDet3D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ); + JDJ(i, 3 * numMapNodes) = + calcDet3D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ); } // Compute signed Jacobian and its gradients w.r.t. node positions, at one // location in a 3D element - inline void calcJDJ3D(double dxdX, double dxdY, double dxdZ, - double dydX, double dydY, double dydZ, - double dzdX, double dzdY, double dzdZ, - int i, int numMapNodes, + inline void calcJDJ3D(double dxdX, double dxdY, double dxdZ, double dydX, + double dydY, double dydZ, double dzdX, double dzdY, + double dzdZ, int i, int numMapNodes, const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, fullMatrix<double> &JDJ) { - for(int j = 0; j < numMapNodes; j++){ + for(int j = 0; j < numMapNodes; j++) { const double &dPhidX = gSMatX(i, j); const double &dPhidY = gSMatY(i, j); const double &dPhidZ = gSMatZ(i, j); - JDJ(i, j) = - dPhidX * dydY * dzdZ + dzdX * dPhidY * dydZ + - dydX * dzdY * dPhidZ - dzdX * dydY * dPhidZ - - dPhidX * dzdY * dydZ - dydX * dPhidY * dzdZ; - JDJ(i, j+numMapNodes) = - dxdX * dPhidY * dzdZ + dzdX * dxdY * dPhidZ + - dPhidX * dzdY * dxdZ - dzdX * dPhidY * dxdZ - - dxdX * dzdY * dPhidZ - dPhidX * dxdY * dzdZ; - JDJ(i, j+2*numMapNodes) = - dxdX * dydY * dPhidZ + dPhidX * dxdY * dydZ + - dydX * dPhidY * dxdZ - dPhidX * dydY * dxdZ - - dxdX * dPhidY * dydZ - dydX * dxdY * dPhidZ; + JDJ(i, j) = dPhidX * dydY * dzdZ + dzdX * dPhidY * dydZ + + dydX * dzdY * dPhidZ - dzdX * dydY * dPhidZ - + dPhidX * dzdY * dydZ - dydX * dPhidY * dzdZ; + JDJ(i, j + numMapNodes) = dxdX * dPhidY * dzdZ + dzdX * dxdY * dPhidZ + + dPhidX * dzdY * dxdZ - dzdX * dPhidY * dxdZ - + dxdX * dzdY * dPhidZ - dPhidX * dxdY * dzdZ; + JDJ(i, j + 2 * numMapNodes) = + dxdX * dydY * dPhidZ + dPhidX * dxdY * dydZ + dydX * dPhidY * dxdZ - + dPhidX * dydY * dxdZ - dxdX * dPhidY * dydZ - dydX * dxdY * dPhidZ; } - JDJ(i, 3*numMapNodes) = calcDet3D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ); + JDJ(i, 3 * numMapNodes) = + calcDet3D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ); } } // namespace @@ -172,11 +153,11 @@ GradientBasis::GradientBasis(FuncSpaceData data) : _data(data) gradShapeMatX.resize(numSampPnts, numMapNodes); gradShapeMatY.resize(numSampPnts, numMapNodes); gradShapeMatZ.resize(numSampPnts, numMapNodes); - for (int i = 0; i < numSampPnts; i++) { - for (int j = 0; j < numMapNodes; j++) { - gradShapeMatX(i, j) = allDPsi(3*i+0, j); - gradShapeMatY(i, j) = allDPsi(3*i+1, j); - gradShapeMatZ(i, j) = allDPsi(3*i+2, j); + for(int i = 0; i < numSampPnts; i++) { + for(int j = 0; j < numMapNodes; j++) { + gradShapeMatX(i, j) = allDPsi(3 * i + 0, j); + gradShapeMatY(i, j) = allDPsi(3 * i + 1, j); + gradShapeMatZ(i, j) = allDPsi(3 * i + 2, j); } } @@ -187,7 +168,7 @@ GradientBasis::GradientBasis(FuncSpaceData data) : _data(data) gradShapeIdealMatY, gradShapeIdealMatZ); } -const bezierBasis* GradientBasis::getBezier() const +const bezierBasis *GradientBasis::getBezier() const { return BasisFactory::getBezierBasis(_data); } @@ -216,8 +197,8 @@ void GradientBasis::getAllGradientsFromNodes(const fullMatrix<double> &nodes, gradShapeMatZ.mult(nodes, prox); } -void GradientBasis::getAllIdealGradientsFromNodes(const fullMatrix<double> &nodes, - fullMatrix<double> &dxyzdXYZ) const +void GradientBasis::getAllIdealGradientsFromNodes( + const fullMatrix<double> &nodes, fullMatrix<double> &dxyzdXYZ) const { fullMatrix<double> prox; prox.setAsProxy(dxyzdXYZ, 0, 3); @@ -240,16 +221,14 @@ void GradientBasis::getIdealGradientsFromNodes(const fullMatrix<double> &nodes, if(dxyzdZ) gradShapeIdealMatZ.mult(nodes, *dxyzdZ); } -void GradientBasis::mapFromIdealElement(int type, - fullMatrix<double> &gSMatX, +void GradientBasis::mapFromIdealElement(int type, fullMatrix<double> &gSMatX, fullMatrix<double> &gSMatY, fullMatrix<double> &gSMatZ) { calcMapFromIdealElement(type, gSMatX, gSMatY, gSMatZ); } -void GradientBasis::mapFromIdealElement(int type, - fullVector<double> &gSVecX, +void GradientBasis::mapFromIdealElement(int type, fullVector<double> &gSVecX, fullVector<double> &gSVecY, fullVector<double> &gSVecZ) { @@ -258,18 +237,19 @@ void GradientBasis::mapFromIdealElement(int type, void GradientBasis::mapFromIdealElement(int type, double jac[3][3]) { - fullMatrix<double> dxyzdX(jac[0], 1, 3), dxyzdY(jac[1], 1, 3), dxyzdZ(jac[2], 1, 3); + fullMatrix<double> dxyzdX(jac[0], 1, 3), dxyzdY(jac[1], 1, 3), + dxyzdZ(jac[2], 1, 3); mapFromIdealElement(type, dxyzdX, dxyzdY, dxyzdZ); } void GradientBasis::lag2Bez(const fullMatrix<double> &lag, fullMatrix<double> &bez) const { - getBezier()->matrixLag2Bez.mult(lag,bez); + getBezier()->matrixLag2Bez.mult(lag, bez); } JacobianBasis::JacobianBasis(FuncSpaceData data) - : _data(data), _dim(data.dimension()) + : _data(data), _dim(data.dimension()) { const int parentType = data.elementType(); const int primJacobianOrder = jacobianOrder(parentType, 1); @@ -297,8 +277,8 @@ JacobianBasis::JacobianBasis(FuncSpaceData data) double xBar = 0., yBar = 0., zBar = 0.; double barycenter[3] = {0., 0., 0.}; - for(int i = 0; i < numPrimMapNodes; i++){ - for(int j = 0; j < primMapBasis->points.size2(); ++j){ + for(int i = 0; i < numPrimMapNodes; i++) { + for(int j = 0; j < primMapBasis->points.size2(); ++j) { barycenter[j] += primMapBasis->points(i, j); } } @@ -306,13 +286,13 @@ JacobianBasis::JacobianBasis(FuncSpaceData data) barycenter[1] /= numPrimMapNodes; barycenter[2] /= numPrimMapNodes; - double (*barDPsi)[3] = new double[numPrimMapNodes][3]; + double(*barDPsi)[3] = new double[numPrimMapNodes][3]; primMapBasis->df(xBar, yBar, zBar, barDPsi); primGradShapeBaryX.resize(numPrimMapNodes); primGradShapeBaryY.resize(numPrimMapNodes); primGradShapeBaryZ.resize(numPrimMapNodes); - for(int j = 0; j < numPrimMapNodes; j++){ + for(int j = 0; j < numPrimMapNodes; j++) { primGradShapeBaryX(j) = barDPsi[j][0]; primGradShapeBaryY(j) = barDPsi[j][1]; primGradShapeBaryZ(j) = barDPsi[j][2]; @@ -321,16 +301,17 @@ JacobianBasis::JacobianBasis(FuncSpaceData data) primIdealGradShapeBaryX = primGradShapeBaryX; primIdealGradShapeBaryY = primGradShapeBaryY; primIdealGradShapeBaryZ = primGradShapeBaryZ; - _gradBasis->mapFromIdealElement(primIdealGradShapeBaryX, primIdealGradShapeBaryY, - primIdealGradShapeBaryZ); + _gradBasis->mapFromIdealElement( + primIdealGradShapeBaryX, primIdealGradShapeBaryY, primIdealGradShapeBaryZ); delete[] barDPsi; - // Compute "fast" Jacobian evaluation matrices (at 1st order nodes + barycenter) + // Compute "fast" Jacobian evaluation matrices (at 1st order nodes + + // barycenter) numJacNodesFast = numPrimMapNodes + 1; fullMatrix<double> lagPointsFast(numJacNodesFast, 3); // Sampling points - lagPointsFast.copy(primMapBasis->points, 0, numPrimMapNodes, - 0, primMapBasis->points.size2(), 0, 0); // 1st order nodes + lagPointsFast.copy(primMapBasis->points, 0, numPrimMapNodes, 0, + primMapBasis->points.size2(), 0, 0); // 1st order nodes lagPointsFast(numPrimMapNodes, 0) = barycenter[0]; // Last point = barycenter lagPointsFast(numPrimMapNodes, 1) = barycenter[1]; lagPointsFast(numPrimMapNodes, 2) = barycenter[2]; @@ -343,16 +324,16 @@ JacobianBasis::JacobianBasis(FuncSpaceData data) gradShapeMatXFast.resize(numJacNodesFast, numMapNodes); gradShapeMatYFast.resize(numJacNodesFast, numMapNodes); gradShapeMatZFast.resize(numJacNodesFast, numMapNodes); - for (int i = 0; i < numJacNodesFast; i++) { - for (int j = 0; j < numMapNodes; j++) { - gradShapeMatXFast(i, j) = allDPsiFast(3*i+0, j); - gradShapeMatYFast(i, j) = allDPsiFast(3*i+1, j); - gradShapeMatZFast(i, j) = allDPsiFast(3*i+2, j); + for(int i = 0; i < numJacNodesFast; i++) { + for(int j = 0; j < numMapNodes; j++) { + gradShapeMatXFast(i, j) = allDPsiFast(3 * i + 0, j); + gradShapeMatYFast(i, j) = allDPsiFast(3 * i + 1, j); + gradShapeMatZFast(i, j) = allDPsiFast(3 * i + 2, j); } } } -const bezierBasis* JacobianBasis::getBezier() const +const bezierBasis *JacobianBasis::getBezier() const { return BasisFactory::getBezierBasis(_data); } @@ -363,7 +344,7 @@ double JacobianBasis::getPrimNormals1D(const fullMatrix<double> &nodesXYZ, fullMatrix<double> &result) const { fullVector<double> dxyzdXbar(3); - for(int j = 0; j < numPrimMapNodes; j++){ + for(int j = 0; j < numPrimMapNodes; j++) { dxyzdXbar(0) += primGradShapeBaryX(j) * nodesXYZ(j, 0); dxyzdXbar(1) += primGradShapeBaryX(j) * nodesXYZ(j, 1); dxyzdXbar(2) += primGradShapeBaryX(j) * nodesXYZ(j, 2); @@ -372,55 +353,67 @@ double JacobianBasis::getPrimNormals1D(const fullMatrix<double> &nodesXYZ, if((fabs(dxyzdXbar(0)) >= fabs(dxyzdXbar(1)) && fabs(dxyzdXbar(0)) >= fabs(dxyzdXbar(2))) || (fabs(dxyzdXbar(1)) >= fabs(dxyzdXbar(0)) && - fabs(dxyzdXbar(1)) >= fabs(dxyzdXbar(2)))){ - result(0,0) = dxyzdXbar(1); result(0,1) = -dxyzdXbar(0); result(0,2) = 0.; + fabs(dxyzdXbar(1)) >= fabs(dxyzdXbar(2)))) { + result(0, 0) = dxyzdXbar(1); + result(0, 1) = -dxyzdXbar(0); + result(0, 2) = 0.; } else { - result(0,0) = 0.; result(0,1) = dxyzdXbar(2); result(0,2) = -dxyzdXbar(1); + result(0, 0) = 0.; + result(0, 1) = dxyzdXbar(2); + result(0, 2) = -dxyzdXbar(1); } - const double norm0 = sqrt(result(0,0)*result(0,0)+ - result(0,1)*result(0,1)+ - result(0,2)*result(0,2)); - result(0,0) /= norm0; result(0,1) /= norm0; result(0,2) /= norm0; - - result(1,2) = dxyzdXbar(0) * result(0,1) - dxyzdXbar(1) * result(0,0); - result(1,1) = -dxyzdXbar(0) * result(0,2) + dxyzdXbar(2) * result(0,0); - result(1,0) = dxyzdXbar(1) * result(0,2) - dxyzdXbar(2) * result(0,1); - const double norm1 = sqrt(result(1,0)*result(1,0)+ - result(1,1)*result(1,1)+ - result(1,2)*result(1,2)); - result(1,0) /= norm1; result(1,1) /= norm1; result(1,2) /= norm1; - - return sqrt(dxyzdXbar(0)*dxyzdXbar(0)+ - dxyzdXbar(1)*dxyzdXbar(1)+ - dxyzdXbar(2)*dxyzdXbar(2)); + const double norm0 = + sqrt(result(0, 0) * result(0, 0) + result(0, 1) * result(0, 1) + + result(0, 2) * result(0, 2)); + result(0, 0) /= norm0; + result(0, 1) /= norm0; + result(0, 2) /= norm0; + + result(1, 2) = dxyzdXbar(0) * result(0, 1) - dxyzdXbar(1) * result(0, 0); + result(1, 1) = -dxyzdXbar(0) * result(0, 2) + dxyzdXbar(2) * result(0, 0); + result(1, 0) = dxyzdXbar(1) * result(0, 2) - dxyzdXbar(2) * result(0, 1); + const double norm1 = + sqrt(result(1, 0) * result(1, 0) + result(1, 1) * result(1, 1) + + result(1, 2) * result(1, 2)); + result(1, 0) /= norm1; + result(1, 1) /= norm1; + result(1, 2) /= norm1; + + return sqrt(dxyzdXbar(0) * dxyzdXbar(0) + dxyzdXbar(1) * dxyzdXbar(1) + + dxyzdXbar(2) * dxyzdXbar(2)); } // Computes (unit) normal to straight surface element at barycenter (with norm // as return value) double JacobianBasis::getPrimNormal2D(const fullMatrix<double> &nodesXYZ, - fullMatrix<double> &result, bool ideal) const + fullMatrix<double> &result, + bool ideal) const { - const fullVector<double> &gSX = ideal ? primIdealGradShapeBaryX : primGradShapeBaryX; - const fullVector<double> &gSY = ideal ? primIdealGradShapeBaryY : primGradShapeBaryY; + const fullVector<double> &gSX = + ideal ? primIdealGradShapeBaryX : primGradShapeBaryX; + const fullVector<double> &gSY = + ideal ? primIdealGradShapeBaryY : primGradShapeBaryY; fullMatrix<double> dxyzdX(1, 3), dxyzdY(1, 3); - for(int j=0; j<numPrimMapNodes; j++){ - dxyzdX(0, 0) += gSX(j)*nodesXYZ(j,0); - dxyzdX(0, 1) += gSX(j)*nodesXYZ(j,1); - dxyzdX(0, 2) += gSX(j)*nodesXYZ(j,2); - dxyzdY(0, 0) += gSY(j)*nodesXYZ(j,0); - dxyzdY(0, 1) += gSY(j)*nodesXYZ(j,1); - dxyzdY(0, 2) += gSY(j)*nodesXYZ(j,2); + for(int j = 0; j < numPrimMapNodes; j++) { + dxyzdX(0, 0) += gSX(j) * nodesXYZ(j, 0); + dxyzdX(0, 1) += gSX(j) * nodesXYZ(j, 1); + dxyzdX(0, 2) += gSX(j) * nodesXYZ(j, 2); + dxyzdY(0, 0) += gSY(j) * nodesXYZ(j, 0); + dxyzdY(0, 1) += gSY(j) * nodesXYZ(j, 1); + dxyzdY(0, 2) += gSY(j) * nodesXYZ(j, 2); } result(0, 2) = dxyzdX(0, 0) * dxyzdY(0, 1) - dxyzdX(0, 1) * dxyzdY(0, 0); result(0, 1) = -dxyzdX(0, 0) * dxyzdY(0, 2) + dxyzdX(0, 2) * dxyzdY(0, 0); result(0, 0) = dxyzdX(0, 1) * dxyzdY(0, 2) - dxyzdX(0, 2) * dxyzdY(0, 1); - double norm0 = sqrt(result(0, 0)*result(0, 0)+ - result(0, 1)*result(0, 1)+ - result(0, 2)*result(0, 2)); - const double invNorm0 = 1./norm0; - result(0, 0) *= invNorm0; result(0, 1) *= invNorm0; result(0, 2) *= invNorm0; + double norm0 = + sqrt(result(0, 0) * result(0, 0) + result(0, 1) * result(0, 1) + + result(0, 2) * result(0, 2)); + const double invNorm0 = 1. / norm0; + result(0, 0) *= invNorm0; + result(0, 1) *= invNorm0; + result(0, 2) *= invNorm0; return norm0; } @@ -429,20 +422,23 @@ double JacobianBasis::getPrimNormal2D(const fullMatrix<double> &nodesXYZ, double JacobianBasis::getPrimJac3D(const fullMatrix<double> &nodesXYZ, bool ideal) const { - const fullVector<double> &gSX = ideal ? primIdealGradShapeBaryX : primGradShapeBaryX; - const fullVector<double> &gSY = ideal ? primIdealGradShapeBaryY : primGradShapeBaryY; - const fullVector<double> &gSZ = ideal ? primIdealGradShapeBaryZ : primGradShapeBaryZ; + const fullVector<double> &gSX = + ideal ? primIdealGradShapeBaryX : primGradShapeBaryX; + const fullVector<double> &gSY = + ideal ? primIdealGradShapeBaryY : primGradShapeBaryY; + const fullVector<double> &gSZ = + ideal ? primIdealGradShapeBaryZ : primGradShapeBaryZ; fullMatrix<double> dxyzdX(1, 3), dxyzdY(1, 3), dxyzdZ(1, 3); - for(int j=0; j<numPrimMapNodes; j++){ - dxyzdX(0, 0) += gSX(j)*nodesXYZ(j,0); - dxyzdX(0, 1) += gSX(j)*nodesXYZ(j,1); - dxyzdX(0, 2) += gSX(j)*nodesXYZ(j,2); - dxyzdY(0, 0) += gSY(j)*nodesXYZ(j,0); - dxyzdY(0, 1) += gSY(j)*nodesXYZ(j,1); - dxyzdY(0, 2) += gSY(j)*nodesXYZ(j,2); - dxyzdZ(0, 0) += gSZ(j)*nodesXYZ(j,0); - dxyzdZ(0, 1) += gSZ(j)*nodesXYZ(j,1); - dxyzdZ(0, 2) += gSZ(j)*nodesXYZ(j,2); + for(int j = 0; j < numPrimMapNodes; j++) { + dxyzdX(0, 0) += gSX(j) * nodesXYZ(j, 0); + dxyzdX(0, 1) += gSX(j) * nodesXYZ(j, 1); + dxyzdX(0, 2) += gSX(j) * nodesXYZ(j, 2); + dxyzdY(0, 0) += gSY(j) * nodesXYZ(j, 0); + dxyzdY(0, 1) += gSY(j) * nodesXYZ(j, 1); + dxyzdY(0, 2) += gSY(j) * nodesXYZ(j, 2); + dxyzdZ(0, 0) += gSZ(j) * nodesXYZ(j, 0); + dxyzdZ(0, 1) += gSZ(j) * nodesXYZ(j, 1); + dxyzdZ(0, 2) += gSZ(j) * nodesXYZ(j, 2); } double dJ = fabs(calcDet3D(dxyzdX(0, 0), dxyzdY(0, 0), dxyzdZ(0, 0), dxyzdX(0, 1), dxyzdY(0, 1), dxyzdZ(0, 1), @@ -453,97 +449,95 @@ double JacobianBasis::getPrimJac3D(const fullMatrix<double> &nodesXYZ, // Calculate (signed, possibly scaled) Jacobian for one element, with normal // vectors to straight element for regularization. Evaluation points depend on // the given matrices for shape function gradients. -void JacobianBasis::getJacobianGeneral(int nJacNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - bool idealNorm, bool scaling, - fullVector<double> &jacobian, - const fullMatrix<double> *geomNormals) const +void JacobianBasis::getJacobianGeneral( + int nJacNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesXYZ, bool idealNorm, bool scaling, + fullVector<double> &jacobian, const fullMatrix<double> *geomNormals) const { - switch(_dim){ - case 0 : - { - for(int i = 0; i < nJacNodes; i++) jacobian(i) = 1.; - } - break; - case 1 : - { - fullMatrix<double> normals(2,3); - const double invScale = getPrimNormals1D(nodesXYZ,normals); - if(geomNormals) - normals.setAll(*geomNormals); - if(scaling){ - if(invScale == 0){ - for(int i = 0; i < nJacNodes; i++) jacobian(i) = 0; - return; - } - const double scale = 1./invScale; - // Faster to scale 1 normal than afterwards - normals(0,0) *= scale; normals(0,1) *= scale; normals(0,2) *= scale; - } - fullMatrix<double> dxyzdX(nJacNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - for(int i = 0; i < nJacNodes; i++){ - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = normals(0,0), &dydY = normals(0,1), &dzdY = normals(0,2); - const double &dxdZ = normals(1,0), &dydZ = normals(1,1), &dzdZ = normals(1,2); - jacobian(i) = calcDet3D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ); + switch(_dim) { + case 0: { + for(int i = 0; i < nJacNodes; i++) jacobian(i) = 1.; + } break; + case 1: { + fullMatrix<double> normals(2, 3); + const double invScale = getPrimNormals1D(nodesXYZ, normals); + if(geomNormals) normals.setAll(*geomNormals); + if(scaling) { + if(invScale == 0) { + for(int i = 0; i < nJacNodes; i++) jacobian(i) = 0; + return; } + const double scale = 1. / invScale; + // Faster to scale 1 normal than afterwards + normals(0, 0) *= scale; + normals(0, 1) *= scale; + normals(0, 2) *= scale; } - break; - case 2 : - { - fullMatrix<double> normal(1,3); - const double invScale = getPrimNormal2D(nodesXYZ, normal, idealNorm); - if(geomNormals) - normal.setAll(*geomNormals); - if(scaling){ - if(invScale == 0){ - for(int i = 0; i < nJacNodes; i++) jacobian(i) = 0; - return; - } - const double scale = 1./invScale; - // Faster to scale normal than afterwards - normal(0,0) *= scale; normal(0,1) *= scale; normal(0,2) *= scale; - } - fullMatrix<double> dxyzdX(nJacNodes,3), dxyzdY(nJacNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - gSMatY.mult(nodesXYZ, dxyzdY); - for(int i = 0; i < nJacNodes; i++){ - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = dxyzdY(i,0), &dydY = dxyzdY(i,1), &dzdY = dxyzdY(i,2); - const double &dxdZ = normal(0,0), &dydZ = normal(0,1), &dzdZ = normal(0,2); - jacobian(i) = calcDet3D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ); - } + fullMatrix<double> dxyzdX(nJacNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + for(int i = 0; i < nJacNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = normals(0, 0), &dydY = normals(0, 1), + &dzdY = normals(0, 2); + const double &dxdZ = normals(1, 0), &dydZ = normals(1, 1), + &dzdZ = normals(1, 2); + jacobian(i) = + calcDet3D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ); } - break; - case 3 : - { - fullMatrix<double> dum; - fullMatrix<double> dxyzdX(nJacNodes,3), dxyzdY(nJacNodes,3), dxyzdZ(nJacNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - gSMatY.mult(nodesXYZ, dxyzdY); - gSMatZ.mult(nodesXYZ, dxyzdZ); - for(int i = 0; i < nJacNodes; i++){ - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = dxyzdY(i,0), &dydY = dxyzdY(i,1), &dzdY = dxyzdY(i,2); - const double &dxdZ = dxyzdZ(i,0), &dydZ = dxyzdZ(i,1), &dzdZ = dxyzdZ(i,2); - jacobian(i) = calcDet3D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ); - } - if(scaling){ - const double scale = 1./getPrimJac3D(nodesXYZ); - jacobian.scale(scale); + } break; + case 2: { + fullMatrix<double> normal(1, 3); + const double invScale = getPrimNormal2D(nodesXYZ, normal, idealNorm); + if(geomNormals) normal.setAll(*geomNormals); + if(scaling) { + if(invScale == 0) { + for(int i = 0; i < nJacNodes; i++) jacobian(i) = 0; + return; } + const double scale = 1. / invScale; + // Faster to scale normal than afterwards + normal(0, 0) *= scale; + normal(0, 1) *= scale; + normal(0, 2) *= scale; + } + fullMatrix<double> dxyzdX(nJacNodes, 3), dxyzdY(nJacNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + gSMatY.mult(nodesXYZ, dxyzdY); + for(int i = 0; i < nJacNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = dxyzdY(i, 0), &dydY = dxyzdY(i, 1), + &dzdY = dxyzdY(i, 2); + const double &dxdZ = normal(0, 0), &dydZ = normal(0, 1), + &dzdZ = normal(0, 2); + jacobian(i) = + calcDet3D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ); + } + } break; + case 3: { + fullMatrix<double> dum; + fullMatrix<double> dxyzdX(nJacNodes, 3), dxyzdY(nJacNodes, 3), + dxyzdZ(nJacNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + gSMatY.mult(nodesXYZ, dxyzdY); + gSMatZ.mult(nodesXYZ, dxyzdZ); + for(int i = 0; i < nJacNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = dxyzdY(i, 0), &dydY = dxyzdY(i, 1), + &dzdY = dxyzdY(i, 2); + const double &dxdZ = dxyzdZ(i, 0), &dydZ = dxyzdZ(i, 1), + &dzdZ = dxyzdZ(i, 2); + jacobian(i) = + calcDet3D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ); + } + if(scaling) { + const double scale = 1. / getPrimJac3D(nodesXYZ); + jacobian.scale(scale); } - break; + } break; } } @@ -551,231 +545,223 @@ void JacobianBasis::getJacobianGeneral(int nJacNodes, // normal vectors to straight elements for regularization. Evaluation points // depend on the given matrices for shape function gradients. TODO: Optimize // and test 1D & 2D -void JacobianBasis::getJacobianGeneral(int nJacNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesX, - const fullMatrix<double> &nodesY, - const fullMatrix<double> &nodesZ, - bool idealNorm, bool scaling, - fullMatrix<double> &jacobian, - const fullMatrix<double> *geomNormals) const +void JacobianBasis::getJacobianGeneral( + int nJacNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesX, const fullMatrix<double> &nodesY, + const fullMatrix<double> &nodesZ, bool idealNorm, bool scaling, + fullMatrix<double> &jacobian, const fullMatrix<double> *geomNormals) const { - switch(_dim){ - case 0 : - { - const int numEl = nodesX.size2(); - for(int iEl = 0; iEl < numEl; iEl++) - for(int i = 0; i < nJacNodes; i++) jacobian(i, iEl) = 1.; - } - break; - case 1 : - { - const int numEl = nodesX.size2(); - fullMatrix<double> dxdX(nJacNodes,numEl); - fullMatrix<double> dydX(nJacNodes,numEl); - fullMatrix<double> dzdX(nJacNodes,numEl); - gSMatX.mult(nodesX, dxdX); gSMatX.mult(nodesY, dydX); gSMatX.mult(nodesZ, dzdX); - for(int iEl = 0; iEl < numEl; iEl++){ - fullMatrix<double> nodesXYZ(numPrimMapNodes,3); - for(int i = 0; i < numPrimMapNodes; i++){ - nodesXYZ(i,0) = nodesX(i,iEl); - nodesXYZ(i,1) = nodesY(i,iEl); - nodesXYZ(i,2) = nodesZ(i,iEl); - } - fullMatrix<double> normals(2,3); - const double invScale = getPrimNormals1D(nodesXYZ,normals); - if(geomNormals) - normals.setAll(*geomNormals); - if(scaling){ - if(invScale == 0){ - for(int i = 0; i < nJacNodes; i++) jacobian(i,iEl) = 0; - continue; - } - const double scale = 1./invScale; - // Faster to scale 1 normal than afterwards - normals(0,0) *= scale; normals(0,1) *= scale; normals(0,2) *= scale; + switch(_dim) { + case 0: { + const int numEl = nodesX.size2(); + for(int iEl = 0; iEl < numEl; iEl++) + for(int i = 0; i < nJacNodes; i++) jacobian(i, iEl) = 1.; + } break; + case 1: { + const int numEl = nodesX.size2(); + fullMatrix<double> dxdX(nJacNodes, numEl); + fullMatrix<double> dydX(nJacNodes, numEl); + fullMatrix<double> dzdX(nJacNodes, numEl); + gSMatX.mult(nodesX, dxdX); + gSMatX.mult(nodesY, dydX); + gSMatX.mult(nodesZ, dzdX); + for(int iEl = 0; iEl < numEl; iEl++) { + fullMatrix<double> nodesXYZ(numPrimMapNodes, 3); + for(int i = 0; i < numPrimMapNodes; i++) { + nodesXYZ(i, 0) = nodesX(i, iEl); + nodesXYZ(i, 1) = nodesY(i, iEl); + nodesXYZ(i, 2) = nodesZ(i, iEl); + } + fullMatrix<double> normals(2, 3); + const double invScale = getPrimNormals1D(nodesXYZ, normals); + if(geomNormals) normals.setAll(*geomNormals); + if(scaling) { + if(invScale == 0) { + for(int i = 0; i < nJacNodes; i++) jacobian(i, iEl) = 0; + continue; } - const double &dxdY = normals(0,0), &dydY = normals(0,1), &dzdY = normals(0,2); - const double &dxdZ = normals(1,0), &dydZ = normals(1,1), &dzdZ = normals(1,2); - for(int i = 0; i < nJacNodes; i++) - jacobian(i,iEl) = calcDet3D(dxdX(i,iEl), dxdY, dxdZ, - dydX(i,iEl), dydY, dydZ, - dzdX(i,iEl), dzdY, dzdZ); + const double scale = 1. / invScale; + // Faster to scale 1 normal than afterwards + normals(0, 0) *= scale; + normals(0, 1) *= scale; + normals(0, 2) *= scale; } + const double &dxdY = normals(0, 0), &dydY = normals(0, 1), + &dzdY = normals(0, 2); + const double &dxdZ = normals(1, 0), &dydZ = normals(1, 1), + &dzdZ = normals(1, 2); + for(int i = 0; i < nJacNodes; i++) + jacobian(i, iEl) = calcDet3D(dxdX(i, iEl), dxdY, dxdZ, dydX(i, iEl), + dydY, dydZ, dzdX(i, iEl), dzdY, dzdZ); } - break; - case 2 : - { - const int numEl = nodesX.size2(); - fullMatrix<double> dxdX(nJacNodes, numEl); - fullMatrix<double> dydX(nJacNodes, numEl); - fullMatrix<double> dzdX(nJacNodes, numEl); - fullMatrix<double> dxdY(nJacNodes, numEl); - fullMatrix<double> dydY(nJacNodes, numEl); - fullMatrix<double> dzdY(nJacNodes, numEl); - gSMatX.mult(nodesX, dxdX); gSMatX.mult(nodesY, dydX); gSMatX.mult(nodesZ, dzdX); - gSMatY.mult(nodesX, dxdY); gSMatY.mult(nodesY, dydY); gSMatY.mult(nodesZ, dzdY); - for(int iEl = 0; iEl < numEl; iEl++){ - fullMatrix<double> nodesXYZ(numPrimMapNodes,3); - for(int i = 0; i < numPrimMapNodes; i++){ - nodesXYZ(i,0) = nodesX(i,iEl); - nodesXYZ(i,1) = nodesY(i,iEl); - nodesXYZ(i,2) = nodesZ(i,iEl); - } - fullMatrix<double> normal(1,3); - const double invScale = getPrimNormal2D(nodesXYZ, normal, idealNorm); - if(geomNormals) - normal.setAll(*geomNormals); - if(scaling){ - if(invScale == 0){ - for(int i = 0; i < nJacNodes; i++) jacobian(i,iEl) = 0; - continue; - } - const double scale = 1./invScale; - // Faster to scale normal than afterwards - normal(0,0) *= scale; normal(0,1) *= scale; normal(0,2) *= scale; + } break; + case 2: { + const int numEl = nodesX.size2(); + fullMatrix<double> dxdX(nJacNodes, numEl); + fullMatrix<double> dydX(nJacNodes, numEl); + fullMatrix<double> dzdX(nJacNodes, numEl); + fullMatrix<double> dxdY(nJacNodes, numEl); + fullMatrix<double> dydY(nJacNodes, numEl); + fullMatrix<double> dzdY(nJacNodes, numEl); + gSMatX.mult(nodesX, dxdX); + gSMatX.mult(nodesY, dydX); + gSMatX.mult(nodesZ, dzdX); + gSMatY.mult(nodesX, dxdY); + gSMatY.mult(nodesY, dydY); + gSMatY.mult(nodesZ, dzdY); + for(int iEl = 0; iEl < numEl; iEl++) { + fullMatrix<double> nodesXYZ(numPrimMapNodes, 3); + for(int i = 0; i < numPrimMapNodes; i++) { + nodesXYZ(i, 0) = nodesX(i, iEl); + nodesXYZ(i, 1) = nodesY(i, iEl); + nodesXYZ(i, 2) = nodesZ(i, iEl); + } + fullMatrix<double> normal(1, 3); + const double invScale = getPrimNormal2D(nodesXYZ, normal, idealNorm); + if(geomNormals) normal.setAll(*geomNormals); + if(scaling) { + if(invScale == 0) { + for(int i = 0; i < nJacNodes; i++) jacobian(i, iEl) = 0; + continue; } - const double &dxdZ = normal(0,0), &dydZ = normal(0,1), &dzdZ = normal(0,2); - for(int i = 0; i < nJacNodes; i++) - jacobian(i,iEl) = calcDet3D(dxdX(i,iEl), dxdY(i,iEl), dxdZ, - dydX(i,iEl), dydY(i,iEl), dydZ, - dzdX(i,iEl), dzdY(i,iEl), dzdZ); + const double scale = 1. / invScale; + // Faster to scale normal than afterwards + normal(0, 0) *= scale; + normal(0, 1) *= scale; + normal(0, 2) *= scale; } + const double &dxdZ = normal(0, 0), &dydZ = normal(0, 1), + &dzdZ = normal(0, 2); + for(int i = 0; i < nJacNodes; i++) + jacobian(i, iEl) = + calcDet3D(dxdX(i, iEl), dxdY(i, iEl), dxdZ, dydX(i, iEl), + dydY(i, iEl), dydZ, dzdX(i, iEl), dzdY(i, iEl), dzdZ); } - break; - case 3 : - { - const int numEl = nodesX.size2(); - fullMatrix<double> dxdX(nJacNodes,numEl); - fullMatrix<double> dydX(nJacNodes,numEl); - fullMatrix<double> dzdX(nJacNodes,numEl); - fullMatrix<double> dxdY(nJacNodes,numEl); - fullMatrix<double> dydY(nJacNodes,numEl); - fullMatrix<double> dzdY(nJacNodes,numEl); - fullMatrix<double> dxdZ(nJacNodes,numEl); - fullMatrix<double> dydZ(nJacNodes,numEl); - fullMatrix<double> dzdZ(nJacNodes,numEl); - gSMatX.mult(nodesX, dxdX); gSMatX.mult(nodesY, dydX); gSMatX.mult(nodesZ, dzdX); - gSMatY.mult(nodesX, dxdY); gSMatY.mult(nodesY, dydY); gSMatY.mult(nodesZ, dzdY); - gSMatZ.mult(nodesX, dxdZ); gSMatZ.mult(nodesY, dydZ); gSMatZ.mult(nodesZ, dzdZ); - for(int iEl = 0; iEl < numEl; iEl++){ - for(int i = 0; i < nJacNodes; i++) - jacobian(i,iEl) = calcDet3D(dxdX(i,iEl), dxdY(i,iEl), dxdZ(i,iEl), - dydX(i,iEl), dydY(i,iEl), dydZ(i,iEl), - dzdX(i,iEl), dzdY(i,iEl), dzdZ(i,iEl)); - if(scaling){ - fullMatrix<double> nodesXYZ(numPrimMapNodes,3); - for(int i = 0; i < numPrimMapNodes; i++){ - nodesXYZ(i,0) = nodesX(i,iEl); - nodesXYZ(i,1) = nodesY(i,iEl); - nodesXYZ(i,2) = nodesZ(i,iEl); - } - const double scale = 1./getPrimJac3D(nodesXYZ); - for(int i = 0; i < nJacNodes; i++) jacobian(i,iEl) *= scale; + } break; + case 3: { + const int numEl = nodesX.size2(); + fullMatrix<double> dxdX(nJacNodes, numEl); + fullMatrix<double> dydX(nJacNodes, numEl); + fullMatrix<double> dzdX(nJacNodes, numEl); + fullMatrix<double> dxdY(nJacNodes, numEl); + fullMatrix<double> dydY(nJacNodes, numEl); + fullMatrix<double> dzdY(nJacNodes, numEl); + fullMatrix<double> dxdZ(nJacNodes, numEl); + fullMatrix<double> dydZ(nJacNodes, numEl); + fullMatrix<double> dzdZ(nJacNodes, numEl); + gSMatX.mult(nodesX, dxdX); + gSMatX.mult(nodesY, dydX); + gSMatX.mult(nodesZ, dzdX); + gSMatY.mult(nodesX, dxdY); + gSMatY.mult(nodesY, dydY); + gSMatY.mult(nodesZ, dzdY); + gSMatZ.mult(nodesX, dxdZ); + gSMatZ.mult(nodesY, dydZ); + gSMatZ.mult(nodesZ, dzdZ); + for(int iEl = 0; iEl < numEl; iEl++) { + for(int i = 0; i < nJacNodes; i++) + jacobian(i, iEl) = calcDet3D(dxdX(i, iEl), dxdY(i, iEl), dxdZ(i, iEl), + dydX(i, iEl), dydY(i, iEl), dydZ(i, iEl), + dzdX(i, iEl), dzdY(i, iEl), dzdZ(i, iEl)); + if(scaling) { + fullMatrix<double> nodesXYZ(numPrimMapNodes, 3); + for(int i = 0; i < numPrimMapNodes; i++) { + nodesXYZ(i, 0) = nodesX(i, iEl); + nodesXYZ(i, 1) = nodesY(i, iEl); + nodesXYZ(i, 2) = nodesZ(i, iEl); } + const double scale = 1. / getPrimJac3D(nodesXYZ); + for(int i = 0; i < nJacNodes; i++) jacobian(i, iEl) *= scale; } } - break; + } break; } } // Calculate (signed) Jacobian and its gradients for one element, with normal // vectors to straight element for regularization. Evaluation points depend on // the given matrices for shape function gradients. -void JacobianBasis::getSignedJacAndGradientsGeneral(int nJacNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &normals, - fullMatrix<double> &JDJ) const +void JacobianBasis::getSignedJacAndGradientsGeneral( + int nJacNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, + fullMatrix<double> &JDJ) const { - switch(_dim){ - case 0 : - { - for(int i = 0; i < nJacNodes; i++){ - for(int j = 0; j < numMapNodes; j++){ - JDJ(i, j) = 0.; - JDJ(i, j+1*numMapNodes) = 0.; - JDJ(i, j+2*numMapNodes) = 0.; - } - JDJ(i, 3*numMapNodes) = 1.; + switch(_dim) { + case 0: { + for(int i = 0; i < nJacNodes; i++) { + for(int j = 0; j < numMapNodes; j++) { + JDJ(i, j) = 0.; + JDJ(i, j + 1 * numMapNodes) = 0.; + JDJ(i, j + 2 * numMapNodes) = 0.; } + JDJ(i, 3 * numMapNodes) = 1.; } - break; - case 1 : - { - fullMatrix<double> dxyzdX(nJacNodes,3), dxyzdY(nJacNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - for(int i = 0; i < nJacNodes; i++){ - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = normals(0,0), &dydY = normals(0,1), &dzdY = normals(0,2); - const double &dxdZ = normals(1,0), &dydZ = normals(1,1), &dzdZ = normals(1,2); - calcJDJ1D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ, - i, numMapNodes, - gSMatX, JDJ); - } + } break; + case 1: { + fullMatrix<double> dxyzdX(nJacNodes, 3), dxyzdY(nJacNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + for(int i = 0; i < nJacNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = normals(0, 0), &dydY = normals(0, 1), + &dzdY = normals(0, 2); + const double &dxdZ = normals(1, 0), &dydZ = normals(1, 1), + &dzdZ = normals(1, 2); + calcJDJ1D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ, i, + numMapNodes, gSMatX, JDJ); } - break; - case 2 : - { - fullMatrix<double> dxyzdX(nJacNodes,3), dxyzdY(nJacNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - gSMatY.mult(nodesXYZ, dxyzdY); - for(int i = 0; i < nJacNodes; i++){ - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = dxyzdY(i,0), &dydY = dxyzdY(i,1), &dzdY = dxyzdY(i,2); - const double &dxdZ = normals(0,0), &dydZ = normals(0,1), &dzdZ = normals(0,2); - calcJDJ2D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ, - i, numMapNodes, - gSMatX, gSMatY, JDJ); - } + } break; + case 2: { + fullMatrix<double> dxyzdX(nJacNodes, 3), dxyzdY(nJacNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + gSMatY.mult(nodesXYZ, dxyzdY); + for(int i = 0; i < nJacNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = dxyzdY(i, 0), &dydY = dxyzdY(i, 1), + &dzdY = dxyzdY(i, 2); + const double &dxdZ = normals(0, 0), &dydZ = normals(0, 1), + &dzdZ = normals(0, 2); + calcJDJ2D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ, i, + numMapNodes, gSMatX, gSMatY, JDJ); } - break; - case 3 : - { - fullMatrix<double> dxyzdX(nJacNodes,3), dxyzdY(nJacNodes,3), dxyzdZ(nJacNodes,3); - gSMatX.mult(nodesXYZ, dxyzdX); - gSMatY.mult(nodesXYZ, dxyzdY); - gSMatZ.mult(nodesXYZ, dxyzdZ); - for(int i = 0; i < nJacNodes; i++){ - const double &dxdX = dxyzdX(i,0), &dydX = dxyzdX(i,1), &dzdX = dxyzdX(i,2); - const double &dxdY = dxyzdY(i,0), &dydY = dxyzdY(i,1), &dzdY = dxyzdY(i,2); - const double &dxdZ = dxyzdZ(i,0), &dydZ = dxyzdZ(i,1), &dzdZ = dxyzdZ(i,2); - calcJDJ3D(dxdX, dxdY, dxdZ, - dydX, dydY, dydZ, - dzdX, dzdY, dzdZ, - i, numMapNodes, - gSMatX, gSMatY, gSMatZ, JDJ); - } + } break; + case 3: { + fullMatrix<double> dxyzdX(nJacNodes, 3), dxyzdY(nJacNodes, 3), + dxyzdZ(nJacNodes, 3); + gSMatX.mult(nodesXYZ, dxyzdX); + gSMatY.mult(nodesXYZ, dxyzdY); + gSMatZ.mult(nodesXYZ, dxyzdZ); + for(int i = 0; i < nJacNodes; i++) { + const double &dxdX = dxyzdX(i, 0), &dydX = dxyzdX(i, 1), + &dzdX = dxyzdX(i, 2); + const double &dxdY = dxyzdY(i, 0), &dydY = dxyzdY(i, 1), + &dzdY = dxyzdY(i, 2); + const double &dxdZ = dxyzdZ(i, 0), &dydZ = dxyzdZ(i, 1), + &dzdZ = dxyzdZ(i, 2); + calcJDJ3D(dxdX, dxdY, dxdZ, dydX, dydY, dydZ, dzdX, dzdY, dzdZ, i, + numMapNodes, gSMatX, gSMatY, gSMatZ, JDJ); } - break; + } break; } } -void JacobianBasis::getSignedIdealJacAndGradientsGeneral(int nJacNodes, - const fullMatrix<double> &gSMatX, - const fullMatrix<double> &gSMatY, - const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &normals, - fullMatrix<double> &JDJ) const +void JacobianBasis::getSignedIdealJacAndGradientsGeneral( + int nJacNodes, const fullMatrix<double> &gSMatX, + const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, + const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, + fullMatrix<double> &JDJ) const { - getSignedJacAndGradientsGeneral(nJacNodes, gSMatX, gSMatY, gSMatZ, - nodesXYZ, normals, JDJ); + getSignedJacAndGradientsGeneral(nJacNodes, gSMatX, gSMatY, gSMatZ, nodesXYZ, + normals, JDJ); } - -void JacobianBasis::getMetricMinAndGradients(const fullMatrix<double> &nodesXYZ, - const fullMatrix<double> &nodesXYZStraight, - fullVector<double> &lambdaJ, - fullMatrix<double> &gradLambdaJ) const +void JacobianBasis::getMetricMinAndGradients( + const fullMatrix<double> &nodesXYZ, + const fullMatrix<double> &nodesXYZStraight, fullVector<double> &lambdaJ, + fullMatrix<double> &gradLambdaJ) const { // jacobian of the straight elements (only triangles for now) SPoint3 v0(nodesXYZ(0, 0), nodesXYZ(0, 1), nodesXYZ(0, 2)); @@ -784,14 +770,13 @@ void JacobianBasis::getMetricMinAndGradients(const fullMatrix<double> &nodesXYZ, SPoint3 *IXYZ[3] = {&v0, &v1, &v2}; double jaci[2][2] = { {IXYZ[1]->x() - IXYZ[0]->x(), IXYZ[2]->x() - IXYZ[0]->x()}, - {IXYZ[1]->y() - IXYZ[0]->y(), IXYZ[2]->y() - IXYZ[0]->y()} - }; + {IXYZ[1]->y() - IXYZ[0]->y(), IXYZ[2]->y() - IXYZ[0]->y()}}; double invJaci[2][2]; inv2x2(jaci, invJaci); - for(int l = 0; l < numJacNodes; l++){ + for(int l = 0; l < numJacNodes; l++) { double jac[2][2] = {{0., 0.}, {0., 0.}}; - for(int i = 0; i < numMapNodes; i++){ + for(int i = 0; i < numMapNodes; i++) { const double &dPhidX = _gradBasis->gradShapeMatX(l, i); const double &dPhidY = _gradBasis->gradShapeMatY(l, i); const double dpsidx = dPhidX * invJaci[0][0] + dPhidY * invJaci[1][0]; @@ -805,17 +790,21 @@ void JacobianBasis::getMetricMinAndGradients(const fullMatrix<double> &nodesXYZ, const double dydy = jac[1][0] * jac[1][0] + jac[1][1] * jac[1][1]; const double dxdy = jac[0][0] * jac[1][0] + jac[0][1] * jac[1][1]; const double sqr = sqrt((dxdx - dydy) * (dxdx - dydy) + 4 * dxdy * dxdy); - const double osqr = sqr > 1e-8 ? 1/sqr : 0; + const double osqr = sqr > 1e-8 ? 1 / sqr : 0; lambdaJ(l) = 0.5 * (dxdx + dydy - sqr); - const double axx = (1 - (dxdx - dydy) * osqr) * jac[0][0] - 2 * dxdy * osqr * jac[1][0]; - const double axy = (1 - (dxdx - dydy) * osqr) * jac[0][1] - 2 * dxdy * osqr * jac[1][1]; - const double ayx = -2 * dxdy * osqr * jac[0][0] + (1 - (dydy - dxdx) * osqr) * jac[1][0]; - const double ayy = -2 * dxdy * osqr * jac[0][1] + (1 - (dydy - dxdx) * osqr) * jac[1][1]; - const double axixi = axx * invJaci[0][0] + axy * invJaci[0][1]; + const double axx = + (1 - (dxdx - dydy) * osqr) * jac[0][0] - 2 * dxdy * osqr * jac[1][0]; + const double axy = + (1 - (dxdx - dydy) * osqr) * jac[0][1] - 2 * dxdy * osqr * jac[1][1]; + const double ayx = + -2 * dxdy * osqr * jac[0][0] + (1 - (dydy - dxdx) * osqr) * jac[1][0]; + const double ayy = + -2 * dxdy * osqr * jac[0][1] + (1 - (dydy - dxdx) * osqr) * jac[1][1]; + const double axixi = axx * invJaci[0][0] + axy * invJaci[0][1]; const double aetaeta = ayx * invJaci[1][0] + ayy * invJaci[1][1]; - const double aetaxi = ayx * invJaci[0][0] + ayy * invJaci[0][1]; - const double axieta = axx * invJaci[1][0] + axy * invJaci[1][1]; - for(int i = 0; i < numMapNodes; i++){ + const double aetaxi = ayx * invJaci[0][0] + ayy * invJaci[0][1]; + const double axieta = axx * invJaci[1][0] + axy * invJaci[1][1]; + for(int i = 0; i < numMapNodes; i++) { const double &dPhidX = _gradBasis->gradShapeMatX(l, i); const double &dPhidY = _gradBasis->gradShapeMatY(l, i); gradLambdaJ(l, i + 0 * numMapNodes) = axixi * dPhidX + axieta * dPhidY; @@ -863,18 +852,19 @@ int JacobianBasis::jacobianOrder(int tag) int JacobianBasis::jacobianOrder(int parentType, int order) { - switch(parentType){ - case TYPE_PNT : return 0; - case TYPE_LIN : return order - 1; - case TYPE_TRI : return 2*order - 2; - case TYPE_QUA : return 2*order - 1; - case TYPE_TET : return 3*order - 3; - case TYPE_PRI : return 3*order - 1; - case TYPE_HEX : return 3*order - 1; - case TYPE_PYR : return 3*order - 3; + switch(parentType) { + case TYPE_PNT: return 0; + case TYPE_LIN: return order - 1; + case TYPE_TRI: return 2 * order - 2; + case TYPE_QUA: return 2 * order - 1; + case TYPE_TET: return 3 * order - 3; + case TYPE_PRI: return 3 * order - 1; + case TYPE_HEX: return 3 * order - 1; + case TYPE_PYR: + return 3 * order - 3; // note : for the pyramid, the jacobian space is // different from the space of the mapping - default : + default: Msg::Error("Unknown element type %d, return order 0", parentType); return 0; } @@ -882,26 +872,20 @@ int JacobianBasis::jacobianOrder(int parentType, int order) FuncSpaceData JacobianBasis::jacobianMatrixSpace(int type, int order) { - if(type == TYPE_PYR){ + if(type == TYPE_PYR) { Msg::Error("jacobianMatrixSpace not yet implemented for pyramids"); return FuncSpaceData(false, type, false, 1, 0); } int jacOrder = -1; - switch(type){ - case TYPE_PNT : - jacOrder = 0; - break; - case TYPE_LIN : - case TYPE_TRI : - case TYPE_TET : - jacOrder = order - 1; - break; - case TYPE_QUA : - case TYPE_PRI : - case TYPE_HEX : - jacOrder = order; - break; - default : + switch(type) { + case TYPE_PNT: jacOrder = 0; break; + case TYPE_LIN: + case TYPE_TRI: + case TYPE_TET: jacOrder = order - 1; break; + case TYPE_QUA: + case TYPE_PRI: + case TYPE_HEX: jacOrder = order; break; + default: Msg::Error("Unknown element type %d, return order 0", type); return 0; } diff --git a/Numeric/JacobianBasis.h b/Numeric/JacobianBasis.h index 699d9952ad10190b3b170ba40d667d5c682e894e..ade1e42bf7f4fcaf1cf791ce9e7f8c93f1ef7e1d 100644 --- a/Numeric/JacobianBasis.h +++ b/Numeric/JacobianBasis.h @@ -12,18 +12,18 @@ class bezierBasis; class GradientBasis { - public: +public: fullMatrix<double> gradShapeMatX, gradShapeMatY, gradShapeMatZ; fullMatrix<double> gradShapeIdealMatX, gradShapeIdealMatY, gradShapeIdealMatZ; - private: +private: const FuncSpaceData _data; - public: +public: GradientBasis(FuncSpaceData); - int getNumSamplingPoints() const {return gradShapeMatX.size1();} - int getNumMapNodes() const {return gradShapeMatX.size2();} - const bezierBasis* getBezier() const; + int getNumSamplingPoints() const { return gradShapeMatX.size1(); } + int getNumMapNodes() const { return gradShapeMatX.size2(); } + const bezierBasis *getBezier() const; void getGradientsFromNodes(const fullMatrix<double> &nodes, fullMatrix<double> *dxyzdX, fullMatrix<double> *dxyzdY, @@ -40,22 +40,20 @@ class GradientBasis { fullMatrix<double> &dxyzdY, fullMatrix<double> &dxyzdZ) const { - GradientBasis::mapFromIdealElement(_data.elementType(), - dxyzdX, dxyzdY, dxyzdZ); + GradientBasis::mapFromIdealElement(_data.elementType(), dxyzdX, dxyzdY, + dxyzdZ); } void mapFromIdealElement(fullVector<double> &dxyzdX, fullVector<double> &dxyzdY, fullVector<double> &dxyzdZ) const { - GradientBasis::mapFromIdealElement(_data.elementType(), - dxyzdX, dxyzdY, dxyzdZ); + GradientBasis::mapFromIdealElement(_data.elementType(), dxyzdX, dxyzdY, + dxyzdZ); } - static void mapFromIdealElement(int type, - fullMatrix<double> &gSMatX, + static void mapFromIdealElement(int type, fullMatrix<double> &gSMatX, fullMatrix<double> &gSMatY, fullMatrix<double> &gSMatZ); - static void mapFromIdealElement(int type, - fullVector<double> &gSVecX, + static void mapFromIdealElement(int type, fullVector<double> &gSVecX, fullVector<double> &gSVecY, fullVector<double> &gSVecZ); static void mapFromIdealElement(int type, double jac[3][3]); @@ -63,7 +61,7 @@ class GradientBasis { }; class JacobianBasis { - private: +private: const GradientBasis *_gradBasis; const FuncSpaceData _data; const int _dim; @@ -77,36 +75,37 @@ class JacobianBasis { int numMapNodes, numPrimMapNodes; int numJacNodesFast; - public: +public: JacobianBasis(FuncSpaceData); // Get methods - inline int getJacOrder() const {return _data.spaceOrder();} - inline int getNumJacNodes() const {return numJacNodes;} - inline int getNumJacNodesFast() const {return numJacNodesFast;} - inline int getNumMapNodes() const {return numMapNodes;} - inline int getNumPrimJacNodes() const {return numPrimJacNodes;} - inline int getNumPrimMapNodes() const {return numPrimMapNodes;} - const bezierBasis* getBezier() const; + inline int getJacOrder() const { return _data.spaceOrder(); } + inline int getNumJacNodes() const { return numJacNodes; } + inline int getNumJacNodesFast() const { return numJacNodesFast; } + inline int getNumMapNodes() const { return numMapNodes; } + inline int getNumPrimJacNodes() const { return numPrimJacNodes; } + inline int getNumPrimMapNodes() const { return numPrimMapNodes; } + const bezierBasis *getBezier() const; // Jacobian evaluation methods double getPrimNormals1D(const fullMatrix<double> &nodesXYZ, fullMatrix<double> &result) const; double getPrimNormal2D(const fullMatrix<double> &nodesXYZ, - fullMatrix<double> &result, bool ideal=false) const; - double getPrimJac3D(const fullMatrix<double> &nodesXYZ, bool ideal=false) const; + fullMatrix<double> &result, bool ideal = false) const; + double getPrimJac3D(const fullMatrix<double> &nodesXYZ, + bool ideal = false) const; inline void getSignedJacAndGradients(const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, fullMatrix<double> &JDJ) const { - getSignedJacAndGradientsGeneral(numJacNodes, _gradBasis->gradShapeMatX, - _gradBasis->gradShapeMatY, - _gradBasis->gradShapeMatZ, - nodesXYZ, normals, JDJ); + getSignedJacAndGradientsGeneral( + numJacNodes, _gradBasis->gradShapeMatX, _gradBasis->gradShapeMatY, + _gradBasis->gradShapeMatZ, nodesXYZ, normals, JDJ); } inline void getSignedJacAndGradientsFast(const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &normals, - fullMatrix<double> &JDJ) const { + fullMatrix<double> &JDJ) const + { getSignedJacAndGradientsGeneral(numJacNodesFast, gradShapeMatXFast, gradShapeMatYFast, gradShapeMatZFast, nodesXYZ, normals, JDJ); @@ -117,8 +116,8 @@ class JacobianBasis { { getSignedJacAndGradientsGeneral(numJacNodes, _gradBasis->gradShapeIdealMatX, _gradBasis->gradShapeIdealMatY, - _gradBasis->gradShapeIdealMatZ, - nodesXYZ, normals, JDJ); + _gradBasis->gradShapeIdealMatZ, nodesXYZ, + normals, JDJ); } void getMetricMinAndGradients(const fullMatrix<double> &nodesXYZ, const fullMatrix<double> &nodesXYZStraight, @@ -129,8 +128,7 @@ class JacobianBasis { const fullMatrix<double> *normals = NULL) const { getJacobianGeneral(numJacNodes, _gradBasis->gradShapeMatX, - _gradBasis->gradShapeMatY, - _gradBasis->gradShapeMatZ, + _gradBasis->gradShapeMatY, _gradBasis->gradShapeMatZ, nodesXYZ, false, false, jacobian, normals); } inline void getSignedJacobian(const fullMatrix<double> &nodesX, @@ -140,36 +138,34 @@ class JacobianBasis { const fullMatrix<double> *normals = NULL) const { getJacobianGeneral(numJacNodes, _gradBasis->gradShapeMatX, - _gradBasis->gradShapeMatY, - _gradBasis->gradShapeMatZ, + _gradBasis->gradShapeMatY, _gradBasis->gradShapeMatZ, nodesX, nodesY, nodesZ, false, false, jacobian, normals); } - inline void getSignedIdealJacobian(const fullMatrix<double> &nodesXYZ, - fullVector<double> &jacobian, - const fullMatrix<double> *normals = NULL) const + inline void + getSignedIdealJacobian(const fullMatrix<double> &nodesXYZ, + fullVector<double> &jacobian, + const fullMatrix<double> *normals = NULL) const { getJacobianGeneral(numJacNodes, _gradBasis->gradShapeIdealMatX, _gradBasis->gradShapeIdealMatY, - _gradBasis->gradShapeIdealMatZ, - nodesXYZ, true, false, jacobian, normals); + _gradBasis->gradShapeIdealMatZ, nodesXYZ, true, false, + jacobian, normals); } - inline void getSignedIdealJacobian(const fullMatrix<double> &nodesX, - const fullMatrix<double> &nodesY, - const fullMatrix<double> &nodesZ, - fullMatrix<double> &jacobian, - const fullMatrix<double> *normals = NULL) const + inline void getSignedIdealJacobian( + const fullMatrix<double> &nodesX, const fullMatrix<double> &nodesY, + const fullMatrix<double> &nodesZ, fullMatrix<double> &jacobian, + const fullMatrix<double> *normals = NULL) const { getJacobianGeneral(numJacNodes, _gradBasis->gradShapeIdealMatX, _gradBasis->gradShapeIdealMatY, - _gradBasis->gradShapeIdealMatZ, - nodesX, nodesY, nodesZ, true, false, jacobian, normals); + _gradBasis->gradShapeIdealMatZ, nodesX, nodesY, nodesZ, + true, false, jacobian, normals); } inline void getScaledJacobian(const fullMatrix<double> &nodesXYZ, fullVector<double> &jacobian) const { getJacobianGeneral(numJacNodes, _gradBasis->gradShapeMatX, - _gradBasis->gradShapeMatY, - _gradBasis->gradShapeMatZ, + _gradBasis->gradShapeMatY, _gradBasis->gradShapeMatZ, nodesXYZ, false, true, jacobian, NULL); } inline void getScaledJacobian(const fullMatrix<double> &nodesX, @@ -178,25 +174,26 @@ class JacobianBasis { fullMatrix<double> &jacobian) const { getJacobianGeneral(numJacNodes, _gradBasis->gradShapeMatX, - _gradBasis->gradShapeMatY, - _gradBasis->gradShapeMatZ, + _gradBasis->gradShapeMatY, _gradBasis->gradShapeMatZ, nodesX, nodesY, nodesZ, false, true, jacobian, NULL); } - inline void getSignedJacobianFast(const fullMatrix<double> &nodesXYZ, - fullVector<double> &jacobian, - const fullMatrix<double> *normals = NULL) const + inline void + getSignedJacobianFast(const fullMatrix<double> &nodesXYZ, + fullVector<double> &jacobian, + const fullMatrix<double> *normals = NULL) const { - getJacobianGeneral(numJacNodesFast, gradShapeMatXFast, - gradShapeMatYFast, gradShapeMatZFast, - nodesXYZ, false, false, jacobian, normals); + getJacobianGeneral(numJacNodesFast, gradShapeMatXFast, gradShapeMatYFast, + gradShapeMatZFast, nodesXYZ, false, false, jacobian, + normals); } - inline void getScaledJacobianFast(const fullMatrix<double> &nodesXYZ, - fullVector<double> &jacobian, - const fullMatrix<double> *normals = NULL) const + inline void + getScaledJacobianFast(const fullMatrix<double> &nodesXYZ, + fullVector<double> &jacobian, + const fullMatrix<double> *normals = NULL) const { - getJacobianGeneral(numJacNodesFast, gradShapeMatXFast, - gradShapeMatYFast, gradShapeMatZFast, - nodesXYZ, false, true, jacobian, normals); + getJacobianGeneral(numJacNodesFast, gradShapeMatXFast, gradShapeMatYFast, + gradShapeMatZFast, nodesXYZ, false, true, jacobian, + normals); } void lag2Bez(const fullVector<double> &lag, fullVector<double> &bez) const; @@ -204,35 +201,31 @@ class JacobianBasis { inline void primJac2Jac(const fullVector<double> &primJac, fullVector<double> &jac) const { - matrixPrimJac2Jac.mult(primJac,jac); + matrixPrimJac2Jac.mult(primJac, jac); } // Research purpose (to be removed ?) void interpolate(const fullVector<double> &jacobian, - const fullMatrix<double> &uvw, - fullMatrix<double> &result, bool areBezier = false) const; + const fullMatrix<double> &uvw, fullMatrix<double> &result, + bool areBezier = false) const; static int jacobianOrder(int tag); static int jacobianOrder(int parentType, int order); static FuncSpaceData jacobianMatrixSpace(int type, int order); - private : - void getJacobianGeneral(int nJacNodes, - const fullMatrix<double> &gSMatX, +private: + void getJacobianGeneral(int nJacNodes, const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, - const fullMatrix<double> &nodesXYZ, - bool idealNorm, bool scaling, - fullVector<double> &jacobian, + const fullMatrix<double> &nodesXYZ, bool idealNorm, + bool scaling, fullVector<double> &jacobian, const fullMatrix<double> *normals) const; - void getJacobianGeneral(int nJacNodes, - const fullMatrix<double> &gSMatX, + void getJacobianGeneral(int nJacNodes, const fullMatrix<double> &gSMatX, const fullMatrix<double> &gSMatY, const fullMatrix<double> &gSMatZ, const fullMatrix<double> &nodesX, const fullMatrix<double> &nodesY, - const fullMatrix<double> &nodesZ, - bool idealNorm, bool scaling, - fullMatrix<double> &jacobian, + const fullMatrix<double> &nodesZ, bool idealNorm, + bool scaling, fullMatrix<double> &jacobian, const fullMatrix<double> *normals) const; void getSignedJacAndGradientsGeneral(int nJacNodes, const fullMatrix<double> &gSMatX, diff --git a/Numeric/Numeric.cpp b/Numeric/Numeric.cpp index 97dec338831ad07cd4e7efeaaa920c838a904b5f..67bc5b297c99f7d017a51f3638a6f4261d5cff52 100644 --- a/Numeric/Numeric.cpp +++ b/Numeric/Numeric.cpp @@ -10,8 +10,7 @@ double myatan2(double a, double b) { - if(a == 0.0 && b == 0) - return 0.0; + if(a == 0.0 && b == 0) return 0.0; return atan2(a, b); } @@ -38,15 +37,9 @@ double myacos(double a) double norm2(double a[3][3]) { double norm2sq = - std::pow(a[0][0], 2)+ - std::pow(a[0][1], 2)+ - std::pow(a[0][2], 2)+ - std::pow(a[1][0], 2)+ - std::pow(a[1][1], 2)+ - std::pow(a[1][2], 2)+ - std::pow(a[2][0], 2)+ - std::pow(a[2][1], 2)+ - std::pow(a[2][2], 2); + std::pow(a[0][0], 2) + std::pow(a[0][1], 2) + std::pow(a[0][2], 2) + + std::pow(a[1][0], 2) + std::pow(a[1][1], 2) + std::pow(a[1][2], 2) + + std::pow(a[2][0], 2) + std::pow(a[2][1], 2) + std::pow(a[2][2], 2); return std::sqrt(norm2sq); } @@ -59,21 +52,28 @@ void matvec(double mat[3][3], double vec[3], double res[3]) void matmat(double mat1[3][3], double mat2[3][3], double res[3][3]) { - res[0][0] = mat1[0][0]*mat2[0][0] + mat1[0][1]*mat2[1][0] + mat1[0][2]*mat2[2][0]; - res[0][1] = mat1[0][0]*mat2[0][1] + mat1[0][1]*mat2[1][1] + mat1[0][2]*mat2[2][1]; - res[0][2] = mat1[0][0]*mat2[0][2] + mat1[0][1]*mat2[1][2] + mat1[0][2]*mat2[2][2]; - res[1][0] = mat1[1][0]*mat2[0][0] + mat1[1][1]*mat2[1][0] + mat1[1][2]*mat2[2][0]; - res[1][1] = mat1[1][0]*mat2[0][1] + mat1[1][1]*mat2[1][1] + mat1[1][2]*mat2[2][1]; - res[1][2] = mat1[1][0]*mat2[0][2] + mat1[1][1]*mat2[1][2] + mat1[1][2]*mat2[2][2]; - res[2][0] = mat1[2][0]*mat2[0][0] + mat1[2][1]*mat2[1][0] + mat1[2][2]*mat2[2][0]; - res[2][1] = mat1[2][0]*mat2[0][1] + mat1[2][1]*mat2[1][1] + mat1[2][2]*mat2[2][1]; - res[2][2] = mat1[2][0]*mat2[0][2] + mat1[2][1]*mat2[1][2] + mat1[2][2]*mat2[2][2]; + res[0][0] = + mat1[0][0] * mat2[0][0] + mat1[0][1] * mat2[1][0] + mat1[0][2] * mat2[2][0]; + res[0][1] = + mat1[0][0] * mat2[0][1] + mat1[0][1] * mat2[1][1] + mat1[0][2] * mat2[2][1]; + res[0][2] = + mat1[0][0] * mat2[0][2] + mat1[0][1] * mat2[1][2] + mat1[0][2] * mat2[2][2]; + res[1][0] = + mat1[1][0] * mat2[0][0] + mat1[1][1] * mat2[1][0] + mat1[1][2] * mat2[2][0]; + res[1][1] = + mat1[1][0] * mat2[0][1] + mat1[1][1] * mat2[1][1] + mat1[1][2] * mat2[2][1]; + res[1][2] = + mat1[1][0] * mat2[0][2] + mat1[1][1] * mat2[1][2] + mat1[1][2] * mat2[2][2]; + res[2][0] = + mat1[2][0] * mat2[0][0] + mat1[2][1] * mat2[1][0] + mat1[2][2] * mat2[2][0]; + res[2][1] = + mat1[2][0] * mat2[0][1] + mat1[2][1] * mat2[1][1] + mat1[2][2] * mat2[2][1]; + res[2][2] = + mat1[2][0] * mat2[0][2] + mat1[2][1] * mat2[1][2] + mat1[2][2] * mat2[2][2]; } -void normal3points(double x0, double y0, double z0, - double x1, double y1, double z1, - double x2, double y2, double z2, - double n[3]) +void normal3points(double x0, double y0, double z0, double x1, double y1, + double z1, double x2, double y2, double z2, double n[3]) { double t1[3] = {x1 - x0, y1 - y0, z1 - z0}; double t2[3] = {x2 - x0, y2 - y0, z2 - z0}; @@ -81,9 +81,8 @@ void normal3points(double x0, double y0, double z0, norme(n); } -void normal2points(double x0, double y0, double z0, - double x1, double y1, double z1, - double n[3]) +void normal2points(double x0, double y0, double z0, double x1, double y1, + double z1, double n[3]) { // this computes one of the normals to the edge double t[3] = {x1 - x0, y1 - y0, z1 - z0}; @@ -130,16 +129,16 @@ double det3x3(double mat[3][3]) mat[0][2] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0])); } -double trace3x3(double mat[3][3]) -{ - return mat[0][0] + mat[1][1] + mat[2][2]; -} +double trace3x3(double mat[3][3]) { return mat[0][0] + mat[1][1] + mat[2][2]; } -double trace2 (double mat[3][3]) +double trace2(double mat[3][3]) { - double a00 = mat[0][0] * mat[0][0] + mat[1][0] * mat[0][1] + mat[2][0] * mat[0][2]; - double a11 = mat[1][0] * mat[0][1] + mat[1][1] * mat[1][1] + mat[1][2] * mat[2][1]; - double a22 = mat[2][0] * mat[0][2] + mat[2][1] * mat[1][2] + mat[2][2] * mat[2][2]; + double a00 = + mat[0][0] * mat[0][0] + mat[1][0] * mat[0][1] + mat[2][0] * mat[0][2]; + double a11 = + mat[1][0] * mat[0][1] + mat[1][1] * mat[1][1] + mat[1][2] * mat[2][1]; + double a22 = + mat[2][0] * mat[0][2] + mat[2][1] * mat[1][2] + mat[2][2] * mat[2][2]; return a00 + a11 + a22; } @@ -159,19 +158,18 @@ int sys3x3(double mat[3][3], double b[3], double res[3], double *det) ud = 1. / (*det); res[0] = b[0] * (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) - - mat[0][1] * (b[1] * mat[2][2] - mat[1][2] * b[2]) + - mat[0][2] * (b[1] * mat[2][1] - mat[1][1] * b[2]); + mat[0][1] * (b[1] * mat[2][2] - mat[1][2] * b[2]) + + mat[0][2] * (b[1] * mat[2][1] - mat[1][1] * b[2]); res[1] = mat[0][0] * (b[1] * mat[2][2] - mat[1][2] * b[2]) - - b[0] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) + - mat[0][2] * (mat[1][0] * b[2] - b[1] * mat[2][0]); + b[0] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) + + mat[0][2] * (mat[1][0] * b[2] - b[1] * mat[2][0]); res[2] = mat[0][0] * (mat[1][1] * b[2] - b[1] * mat[2][1]) - - mat[0][1] * (mat[1][0] * b[2] - b[1] * mat[2][0]) + - b[0] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]); + mat[0][1] * (mat[1][0] * b[2] - b[1] * mat[2][0]) + + b[0] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]); - for(i = 0; i < 3; i++) - res[i] *= ud; + for(i = 0; i < 3; i++) res[i] *= ud; return (1); } @@ -215,18 +213,17 @@ double det2x3(double mat[2][3]) double inv2x2(double mat[2][2], double inv[2][2]) { const double det = det2x2(mat); - if(det){ + if(det) { double ud = 1. / det; - inv[0][0] = mat[1][1] * ud; + inv[0][0] = mat[1][1] * ud; inv[1][0] = -mat[1][0] * ud; inv[0][1] = -mat[0][1] * ud; - inv[1][1] = mat[0][0] * ud; + inv[1][1] = mat[0][0] * ud; } - else{ + else { Msg::Error("Singular matrix 2x2"); for(int i = 0; i < 2; i++) - for(int j = 0; j < 2; j++) - inv[i][j] = 0.; + for(int j = 0; j < 2; j++) inv[i][j] = 0.; } return det; } @@ -234,23 +231,22 @@ double inv2x2(double mat[2][2], double inv[2][2]) double inv3x3(double mat[3][3], double inv[3][3]) { double det = det3x3(mat); - if(det){ + if(det) { double ud = 1. / det; - inv[0][0] = (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) * ud; + inv[0][0] = (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) * ud; inv[1][0] = -(mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) * ud; - inv[2][0] = (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]) * ud; + inv[2][0] = (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]) * ud; inv[0][1] = -(mat[0][1] * mat[2][2] - mat[0][2] * mat[2][1]) * ud; - inv[1][1] = (mat[0][0] * mat[2][2] - mat[0][2] * mat[2][0]) * ud; + inv[1][1] = (mat[0][0] * mat[2][2] - mat[0][2] * mat[2][0]) * ud; inv[2][1] = -(mat[0][0] * mat[2][1] - mat[0][1] * mat[2][0]) * ud; - inv[0][2] = (mat[0][1] * mat[1][2] - mat[0][2] * mat[1][1]) * ud; + inv[0][2] = (mat[0][1] * mat[1][2] - mat[0][2] * mat[1][1]) * ud; inv[1][2] = -(mat[0][0] * mat[1][2] - mat[0][2] * mat[1][0]) * ud; - inv[2][2] = (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) * ud; + inv[2][2] = (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) * ud; } - else{ + else { Msg::Error("Singular matrix 3x3"); for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - inv[i][j] = 0.; + for(int j = 0; j < 3; j++) inv[i][j] = 0.; } return det; } @@ -312,10 +308,9 @@ double triangle_area(double p0[3], double p1[3], double p2[3]) double triangle_area2d(double p0[2], double p1[2], double p2[2]) { const double c = - (p2[0] - p1[0])*(p0[1] - p1[1]) - - (p2[1] - p1[1])*(p0[0] - p1[0]); + (p2[0] - p1[0]) * (p0[1] - p1[1]) - (p2[1] - p1[1]) * (p0[0] - p1[0]); - return 0.5 * std::sqrt(c*c); + return 0.5 * std::sqrt(c * c); } void circumCenterXY(double *p1, double *p2, double *p3, double *res) @@ -333,7 +328,7 @@ void circumCenterXY(double *p1, double *p2, double *p3, double *res) if(d == 0.0) { // Msg::Warning("Colinear points in circum circle computation"); res[0] = res[1] = -99999.; - return ; + return; } a1 = x1 * x1 + y1 * y1; @@ -343,24 +338,29 @@ void circumCenterXY(double *p1, double *p2, double *p3, double *res) res[1] = (double)((a1 * (x2 - x3) + a2 * (x3 - x1) + a3 * (x1 - x2)) / d); } -void circumCenterXYZ(double *p1, double *p2, double *p3, double *res, double *uv) +void circumCenterXYZ(double *p1, double *p2, double *p3, double *res, + double *uv) { double v1[3] = {p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]}; double v2[3] = {p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]}; double vx[3] = {p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]}; double vy[3] = {p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]}; - double vz[3]; prodve(vx, vy, vz); prodve(vz, vx, vy); - norme(vx); norme(vy); norme(vz); + double vz[3]; + prodve(vx, vy, vz); + prodve(vz, vx, vy); + norme(vx); + norme(vy); + norme(vz); double p1P[2] = {0.0, 0.0}; double p2P[2] = {prosca(v1, vx), prosca(v1, vy)}; - double p3P[2] = { prosca(v2, vx), prosca(v2, vy)}; + double p3P[2] = {prosca(v2, vx), prosca(v2, vy)}; double resP[2]; - circumCenterXY(p1P, p2P, p3P,resP); + circumCenterXY(p1P, p2P, p3P, resP); - if(uv){ + if(uv) { double mat[2][2] = {{p2P[0] - p1P[0], p3P[0] - p1P[0]}, {p2P[1] - p1P[1], p3P[1] - p1P[1]}}; double rhs[2] = {resP[0] - p1P[0], resP[1] - p1P[1]}; @@ -380,9 +380,13 @@ void planarQuad_xyz2xy(double *x, double *y, double *z, double *xn, double *yn) double vx[3] = {x[1] - x[0], y[1] - y[0], z[1] - z[0]}; double vy[3] = {x[2] - x[0], y[2] - y[0], z[2] - z[0]}; - double vz[3]; prodve(vx, vy, vz); prodve(vz, vx, vy); + double vz[3]; + prodve(vx, vy, vz); + prodve(vz, vx, vy); - norme(vx); norme(vy); norme(vz); + norme(vx); + norme(vy); + norme(vz); double p1P[2] = {0.0, 0.0}; double p2P[2] = {prosca(v1, vx), prosca(v1, vy)}; @@ -402,46 +406,46 @@ void planarQuad_xyz2xy(double *x, double *y, double *z, double *xn, double *yn) double computeInnerRadiusForQuad(double *x, double *y, int i) { // parameters of the equations of the 3 edges - double a1 = y[(4+i)%4]-y[(5+i)%4]; - double a2 = y[(5+i)%4]-y[(6+i)%4]; - double a3 = y[(6+i)%4]-y[(7+i)%4]; + double a1 = y[(4 + i) % 4] - y[(5 + i) % 4]; + double a2 = y[(5 + i) % 4] - y[(6 + i) % 4]; + double a3 = y[(6 + i) % 4] - y[(7 + i) % 4]; - double b1 = x[(5+i)%4]-x[(4+i)%4]; - double b2 = x[(6+i)%4]-x[(5+i)%4]; - double b3 = x[(7+i)%4]-x[(6+i)%4]; + double b1 = x[(5 + i) % 4] - x[(4 + i) % 4]; + double b2 = x[(6 + i) % 4] - x[(5 + i) % 4]; + double b3 = x[(7 + i) % 4] - x[(6 + i) % 4]; - double c1 = y[(5+i)%4]*x[(4+i)%4]-y[(4+i)%4]*x[(5+i)%4]; - double c2 = y[(6+i)%4]*x[(5+i)%4]-y[(5+i)%4]*x[(6+i)%4]; - double c3 = y[(7+i)%4]*x[(6+i)%4]-y[(6+i)%4]*x[(7+i)%4]; + double c1 = y[(5 + i) % 4] * x[(4 + i) % 4] - y[(4 + i) % 4] * x[(5 + i) % 4]; + double c2 = y[(6 + i) % 4] * x[(5 + i) % 4] - y[(5 + i) % 4] * x[(6 + i) % 4]; + double c3 = y[(7 + i) % 4] * x[(6 + i) % 4] - y[(6 + i) % 4] * x[(7 + i) % 4]; // length of the 3 edges - double l1 = std::sqrt(a1*a1+b1*b1); - double l2 = std::sqrt(a2*a2+b2*b2); - double l3 = std::sqrt(a3*a3+b3*b3); + double l1 = std::sqrt(a1 * a1 + b1 * b1); + double l2 = std::sqrt(a2 * a2 + b2 * b2); + double l3 = std::sqrt(a3 * a3 + b3 * b3); // parameters of the 2 bisectors - double a12 = a1/l1-a2/l2; - double a23 = a2/l2-a3/l3; + double a12 = a1 / l1 - a2 / l2; + double a23 = a2 / l2 - a3 / l3; - double b12 = b1/l1-b2/l2; - double b23 = b2/l2-b3/l3; + double b12 = b1 / l1 - b2 / l2; + double b23 = b2 / l2 - b3 / l3; - double c12 = c1/l1-c2/l2; - double c23 = c2/l2-c3/l3; + double c12 = c1 / l1 - c2 / l2; + double c23 = c2 / l2 - c3 / l3; // compute the coordinates of the center of the incircle, // that is the point where the 2 bisectors meet - double x_s = (c12*b23-c23*b12)/(a23*b12-a12*b23); + double x_s = (c12 * b23 - c23 * b12) / (a23 * b12 - a12 * b23); double y_s = 0.; - if (b12 != 0) { - y_s = -a12/b12*x_s-c12/b12; + if(b12 != 0) { + y_s = -a12 / b12 * x_s - c12 / b12; } else { - y_s = -a23/b23*x_s-c23/b23; + y_s = -a23 / b23 * x_s - c23 / b23; } // finally get the radius of the circle - double r = (a1*x_s+b1*y_s+c1)/l1; + double r = (a1 * x_s + b1 * y_s + c1) / l1; return r; } @@ -450,17 +454,23 @@ char float2char(float f) { // float normalized in [-1, 1], char in [-127, 127] float c = f * 127.; - if(c > 127.) return 127; - else if(c < -127.) return -127; - else return (int)c; + if(c > 127.) + return 127; + else if(c < -127.) + return -127; + else + return (int)c; } float char2float(char c) { float f = c; - if(f > 127.) return 1.; - else if(f < -127) return -1.; - else return f / 127.; + if(f > 127.) + return 1.; + else if(f < -127) + return -1.; + else + return f / 127.; } void gradSimplex(double *x, double *y, double *z, double *v, double *grad) @@ -487,12 +497,11 @@ void gradSimplex(double *x, double *y, double *z, double *v, double *grad) double ComputeVonMises(double *V) { double tr = (V[0] + V[4] + V[8]) / 3.; - double v11 = V[0] - tr, v12 = V[1], v13 = V[2]; - double v21 = V[3], v22 = V[4] - tr, v23 = V[5]; - double v31 = V[6], v32 = V[7], v33 = V[8] - tr; - return sqrt(1.5 * (v11 * v11 + v12 * v12 + v13 * v13 + - v21 * v21 + v22 * v22 + v23 * v23 + - v31 * v31 + v32 * v32 + v33 * v33)); + double v11 = V[0] - tr, v12 = V[1], v13 = V[2]; + double v21 = V[3], v22 = V[4] - tr, v23 = V[5]; + double v31 = V[6], v32 = V[7], v33 = V[8] - tr; + return sqrt(1.5 * (v11 * v11 + v12 * v12 + v13 * v13 + v21 * v21 + v22 * v22 + + v23 * v23 + v31 * v31 + v32 * v32 + v33 * v33)); } double ComputeScalarRep(int numComp, double *val) @@ -508,14 +517,14 @@ double ComputeScalarRep(int numComp, double *val) void eigenvalue2x2(double mat[2][2], double v[2]) { - double a=1; - double b=-(mat[0][0]+mat[1][1]); - double c= (mat[0][0]*mat[1][1])-(mat[0][1]*mat[1][0]); + double a = 1; + double b = -(mat[0][0] + mat[1][1]); + double c = (mat[0][0] * mat[1][1]) - (mat[0][1] * mat[1][0]); - double det = b*b-4.*a*c; + double det = b * b - 4. * a * c; - v[0] = (-b+sqrt(det))/(2*a); - v[1] = (-b-sqrt(det))/(2*a); + v[0] = (-b + sqrt(det)) / (2 * a); + v[1] = (-b - sqrt(det)) / (2 * a); } void eigenvalue(double mat[3][3], double v[3]) @@ -528,9 +537,9 @@ void eigenvalue(double mat[3][3], double v[3]) double c[4]; c[3] = 1.0; - c[2] = - trace3x3(mat); + c[2] = -trace3x3(mat); c[1] = 0.5 * (c[2] * c[2] - trace2(mat)); - c[0] = - det3x3(mat); + c[0] = -det3x3(mat); // printf("%g %g %g\n", mat[0][0], mat[0][1], mat[0][2]); // printf("%g %g %g\n", mat[1][0], mat[1][1], mat[1][2]); @@ -549,7 +558,7 @@ void FindCubicRoots(const double coef[4], double real[3], double imag[3]) double c = coef[1]; double d = coef[0]; - if(!a || !d){ + if(!a || !d) { // Msg::Error("Degenerate cubic: use a second degree solver!"); return; } @@ -558,23 +567,23 @@ void FindCubicRoots(const double coef[4], double real[3], double imag[3]) c /= a; d /= a; - double q = (3.0*c - (b*b))/9.0; - double r = -(27.0*d) + b*(9.0*c - 2.0*(b*b)); + double q = (3.0 * c - (b * b)) / 9.0; + double r = -(27.0 * d) + b * (9.0 * c - 2.0 * (b * b)); r /= 54.0; - double discrim = q*q*q + r*r; + double discrim = q * q * q + r * r; imag[0] = 0.0; // The first root is always real. - double term1 = (b/3.0); + double term1 = (b / 3.0); - if (discrim > 0) { // one root is real, two are complex + if(discrim > 0) { // one root is real, two are complex double s = r + sqrt(discrim); - s = ((s < 0) ? -pow(-s, (1.0/3.0)) : pow(s, (1.0/3.0))); + s = ((s < 0) ? -pow(-s, (1.0 / 3.0)) : pow(s, (1.0 / 3.0))); double t = r - sqrt(discrim); - t = ((t < 0) ? -pow(-t, (1.0/3.0)) : pow(t, (1.0/3.0))); + t = ((t < 0) ? -pow(-t, (1.0 / 3.0)) : pow(t, (1.0 / 3.0))); real[0] = -term1 + s + t; - term1 += (s + t)/2.0; + term1 += (s + t) / 2.0; real[1] = real[2] = -term1; - term1 = sqrt(3.0)*(-t + s)/2; + term1 = sqrt(3.0) * (-t + s) / 2; imag[1] = term1; imag[2] = -term1; return; @@ -584,9 +593,9 @@ void FindCubicRoots(const double coef[4], double real[3], double imag[3]) imag[1] = imag[2] = 0.0; double r13; - if (discrim == 0){ // All roots real, at least two are equal. - r13 = ((r < 0) ? -pow(-r,(1.0/3.0)) : pow(r,(1.0/3.0))); - real[0] = -term1 + 2.0*r13; + if(discrim == 0) { // All roots real, at least two are equal. + r13 = ((r < 0) ? -pow(-r, (1.0 / 3.0)) : pow(r, (1.0 / 3.0))); + real[0] = -term1 + 2.0 * r13; real[1] = real[2] = -(r13 + term1); return; } @@ -594,12 +603,12 @@ void FindCubicRoots(const double coef[4], double real[3], double imag[3]) // Only option left is that all roots are real and unequal (to get // here, q < 0) q = -q; - double dum1 = q*q*q; - dum1 = acos(r/sqrt(dum1)); - r13 = 2.0*sqrt(q); - real[0] = -term1 + r13*cos(dum1/3.0); - real[1] = -term1 + r13*cos((dum1 + 2.0*M_PI)/3.0); - real[2] = -term1 + r13*cos((dum1 + 4.0*M_PI)/3.0); + double dum1 = q * q * q; + dum1 = acos(r / sqrt(dum1)); + r13 = 2.0 * sqrt(q); + real[0] = -term1 + r13 * cos(dum1 / 3.0); + real[1] = -term1 + r13 * cos((dum1 + 2.0 * M_PI) / 3.0); + real[2] = -term1 + r13 * cos((dum1 + 4.0 * M_PI) / 3.0); } void eigsort(double d[3]) @@ -607,13 +616,13 @@ void eigsort(double d[3]) int k, j, i; double p; - for (i=0; i<3; i++) { - p=d[k=i]; - for (j=i+1;j<3;j++) - if (d[j] >= p) p=d[k=j]; - if (k != i) { - d[k]=d[i]; - d[i]=p; + for(i = 0; i < 3; i++) { + p = d[k = i]; + for(j = i + 1; j < 3; j++) + if(d[j] >= p) p = d[k = j]; + if(k != i) { + d[k] = d[i]; + d[i] = p; } } } @@ -632,8 +641,8 @@ void invert_singular_matrix3x3(double MM[3][3], double II[3][3]) fullMatrix<double> M(3, 3), V(3, 3); fullVector<double> W(3); - for(i = 1; i <= n; i++){ - for(j = 1; j <= n; j++){ + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) { M(i - 1, j - 1) = MM[i - 1][j - 1]; } } @@ -665,43 +674,42 @@ bool newton_fd(bool (*func)(fullVector<double> &, fullVector<double> &, void *), fullMatrix<double> J(N, N); fullVector<double> f(N), feps(N), dx(N); - - for (int iter = 0; iter < MAXIT; iter++){ - if (x.norm() > 1.e6)return false; + for(int iter = 0; iter < MAXIT; iter++) { + if(x.norm() > 1.e6) return false; if(!func(x, f, data)) { return false; } bool isZero = false; - for (int k=0; k<N; k++) { - if (f(k) == 0. ) isZero = true; - else isZero = false; - if (isZero == false) break; + for(int k = 0; k < N; k++) { + if(f(k) == 0.) + isZero = true; + else + isZero = false; + if(isZero == false) break; } - if (isZero) break; + if(isZero) break; - for (int j = 0; j < N; j++){ + for(int j = 0; j < N; j++) { double h = EPS * fabs(x(j)); if(h == 0.) h = EPS; x(j) += h; if(!func(x, feps, data)) { - return false; + return false; } - for (int i = 0; i < N; i++){ + for(int i = 0; i < N; i++) { J(i, j) = (feps(i) - f(i)) / h; } x(j) -= h; } - if (N == 1) + if(N == 1) dx(0) = f(0) / J(0, 0); - else - if (!J.luSolve(f, dx)){ - return false; - } + else if(!J.luSolve(f, dx)) { + return false; + } - for (int i = 0; i < N; i++) - x(i) -= relax * dx(i); + for(int i = 0; i < N; i++) x(i) -= relax * dx(i); if(dx.norm() < tolx) { return true; @@ -710,7 +718,6 @@ bool newton_fd(bool (*func)(fullVector<double> &, fullVector<double> &, void *), return false; } - /* distance to triangle @@ -738,8 +745,9 @@ bool newton_fd(bool (*func)(fullVector<double> &, fullVector<double> &, void *), t = (p-p1)*(p2-p1)/||p2-p1||^2 */ -void signedDistancePointTriangle(const SPoint3 &p1,const SPoint3 &p2, const SPoint3 &p3, - const SPoint3 &p, double &d, SPoint3 &closePt) +void signedDistancePointTriangle(const SPoint3 &p1, const SPoint3 &p2, + const SPoint3 &p3, const SPoint3 &p, double &d, + SPoint3 &closePt) { SVector3 t1 = p2 - p1; SVector3 t2 = p3 - p1; @@ -762,9 +770,9 @@ void signedDistancePointTriangle(const SPoint3 &p1,const SPoint3 &p2, const SPoi v = (inv[1][0] * pp1.x() + inv[1][1] * pp1.y() + inv[1][2] * pp1.z()); d = (inv[2][0] * pp1.x() + inv[2][1] * pp1.y() + inv[2][2] * pp1.z()); double sign = (d > 0) ? 1. : -1.; - if (d == 0.) sign = 1.; - if (u >= 0. && v >= 0. && 1.-u-v >= 0.0){ //P(p) inside triangle - closePt = p1 + (p2-p1)*u + (p3-p1)*v; + if(d == 0.) sign = 1.; + if(u >= 0. && v >= 0. && 1. - u - v >= 0.0) { // P(p) inside triangle + closePt = p1 + (p2 - p1) * u + (p3 - p1) * v; } else { const double t12 = dot(pp1, t1) / n2t1; @@ -772,27 +780,29 @@ void signedDistancePointTriangle(const SPoint3 &p1,const SPoint3 &p2, const SPoi SVector3 pp2 = p - p2; const double t23 = dot(pp2, t3) / n2t3; d = 1.e10; - if (t12 >= 0 && t12 <= 1.){ + if(t12 >= 0 && t12 <= 1.) { d = sign * std::min(fabs(d), p.distance(p1 + (p2 - p1) * t12)); closePt = p1 + (p2 - p1) * t12; } - if (t13 >= 0 && t13 <= 1.){ - if (p.distance(p1 + (p3 - p1) * t13) < fabs(d)) closePt = p1 + (p3 - p1) * t13; + if(t13 >= 0 && t13 <= 1.) { + if(p.distance(p1 + (p3 - p1) * t13) < fabs(d)) + closePt = p1 + (p3 - p1) * t13; d = sign * std::min(fabs(d), p.distance(p1 + (p3 - p1) * t13)); } - if (t23 >= 0 && t23 <= 1.){ - if (p.distance(p2 + (p3 - p2) * t23) < fabs(d)) closePt = p2 + (p3 - p2) * t23; + if(t23 >= 0 && t23 <= 1.) { + if(p.distance(p2 + (p3 - p2) * t23) < fabs(d)) + closePt = p2 + (p3 - p2) * t23; d = sign * std::min(fabs(d), p.distance(p2 + (p3 - p2) * t23)); } - if (p.distance(p1) < fabs(d)){ + if(p.distance(p1) < fabs(d)) { closePt = p1; d = sign * std::min(fabs(d), p.distance(p1)); } - if (p.distance(p2) < fabs(d)){ + if(p.distance(p2) < fabs(d)) { closePt = p2; d = sign * std::min(fabs(d), p.distance(p2)); } - if (p.distance(p3) < fabs(d)){ + if(p.distance(p3) < fabs(d)) { closePt = p3; d = sign * std::min(fabs(d), p.distance(p3)); } @@ -802,8 +812,7 @@ void signedDistancePointTriangle(const SPoint3 &p1,const SPoint3 &p2, const SPoi void signedDistancesPointsTriangle(std::vector<double> &distances, std::vector<SPoint3> &closePts, const std::vector<SPoint3> &pts, - const SPoint3 &p1, - const SPoint3 &p2, + const SPoint3 &p1, const SPoint3 &p2, const SPoint3 &p3) { const unsigned pts_size = pts.size(); @@ -812,8 +821,7 @@ void signedDistancesPointsTriangle(std::vector<double> &distances, closePts.clear(); closePts.resize(pts_size); - for (unsigned int i = 0; i < pts_size; ++i) - distances[i] = 1.e22; + for(unsigned int i = 0; i < pts_size; ++i) distances[i] = 1.e22; SVector3 t1 = p2 - p1; SVector3 t2 = p3 - p1; @@ -830,21 +838,21 @@ void signedDistancesPointsTriangle(std::vector<double> &distances, double det = inv3x3(mat, inv); if(det == 0.0) return; - for (unsigned int i = 0; i < pts.size(); i++) { + for(unsigned int i = 0; i < pts.size(); i++) { double d; SPoint3 closePt; const SPoint3 &p = pts[i]; - //signedDistancePointTrianglePrecomputed(p1, p2, p3, p, d, closePt); + // signedDistancePointTrianglePrecomputed(p1, p2, p3, p, d, closePt); double u, v; SVector3 pp1 = p - p1; u = (inv[0][0] * pp1.x() + inv[0][1] * pp1.y() + inv[0][2] * pp1.z()); v = (inv[1][0] * pp1.x() + inv[1][1] * pp1.y() + inv[1][2] * pp1.z()); d = (inv[2][0] * pp1.x() + inv[2][1] * pp1.y() + inv[2][2] * pp1.z()); double sign = (d > 0) ? 1. : -1.; - if (d == 0.) sign = 1.; - if (u >= 0 && v >= 0 && 1.-u-v >= 0.0){ - closePt = SPoint3(0.,0.,0.);//TO DO + if(d == 0.) sign = 1.; + if(u >= 0 && v >= 0 && 1. - u - v >= 0.0) { + closePt = SPoint3(0., 0., 0.); // TO DO } else { const double t12 = dot(pp1, t1) / n2t1; @@ -853,47 +861,49 @@ void signedDistancesPointsTriangle(std::vector<double> &distances, const double t23 = dot(pp2, t3) / n2t3; d = 1.e10; SPoint3 closePt; - if (t12 >= 0 && t12 <= 1.){ - d = sign * std::min(fabs(d), p.distance(p1 + (p2 - p1) * t12)); - closePt = p1 + (p2 - p1) * t12; + if(t12 >= 0 && t12 <= 1.) { + d = sign * std::min(fabs(d), p.distance(p1 + (p2 - p1) * t12)); + closePt = p1 + (p2 - p1) * t12; } - if (t13 >= 0 && t13 <= 1.){ - if (p.distance(p1 + (p3 - p1) * t13) < fabs(d)) closePt = p1 + (p3 - p1) * t13; - d = sign * std::min(fabs(d), p.distance(p1 + (p3 - p1) * t13)); + if(t13 >= 0 && t13 <= 1.) { + if(p.distance(p1 + (p3 - p1) * t13) < fabs(d)) + closePt = p1 + (p3 - p1) * t13; + d = sign * std::min(fabs(d), p.distance(p1 + (p3 - p1) * t13)); } - if (t23 >= 0 && t23 <= 1.){ - if (p.distance(p2 + (p3 - p2) * t23) < fabs(d)) closePt = p2 + (p3 - p2) * t23; - d = sign * std::min(fabs(d), p.distance(p2 + (p3 - p2) * t23)); + if(t23 >= 0 && t23 <= 1.) { + if(p.distance(p2 + (p3 - p2) * t23) < fabs(d)) + closePt = p2 + (p3 - p2) * t23; + d = sign * std::min(fabs(d), p.distance(p2 + (p3 - p2) * t23)); } - if (p.distance(p1) < fabs(d)){ - closePt = p1; - d = sign * std::min(fabs(d), p.distance(p1)); + if(p.distance(p1) < fabs(d)) { + closePt = p1; + d = sign * std::min(fabs(d), p.distance(p1)); } - if (p.distance(p2) < fabs(d)){ - closePt = p2; - d = sign * std::min(fabs(d), p.distance(p2)); + if(p.distance(p2) < fabs(d)) { + closePt = p2; + d = sign * std::min(fabs(d), p.distance(p2)); } - if (p.distance(p3) < fabs(d)){ - closePt = p3; - d = sign * std::min(fabs(d), p.distance(p3)); + if(p.distance(p3) < fabs(d)) { + closePt = p3; + d = sign * std::min(fabs(d), p.distance(p3)); } } - //end signedDistance + // end signedDistance distances[i] = d; closePts[i] = closePt; } } -void signedDistancePointLine(const SPoint3 &p1, const SPoint3 &p2, const SPoint3 &p, - double &d, SPoint3 &closePt) +void signedDistancePointLine(const SPoint3 &p1, const SPoint3 &p2, + const SPoint3 &p, double &d, SPoint3 &closePt) { SVector3 v12 = p2 - p1; SVector3 v1p = p - p1; const double alpha = dot(v1p, v12) / dot(v12, v12); - if (alpha <= 0.) + if(alpha <= 0.) closePt = p1; - else if (alpha >= 1.) + else if(alpha >= 1.) closePt = p2; else closePt = p1 + (p2 - p1) * alpha; @@ -903,14 +913,13 @@ void signedDistancePointLine(const SPoint3 &p1, const SPoint3 &p2, const SPoint3 void signedDistancesPointsLine(std::vector<double> &distances, std::vector<SPoint3> &closePts, const std::vector<SPoint3> &pts, - const SPoint3 &p1, - const SPoint3 &p2) + const SPoint3 &p1, const SPoint3 &p2) { distances.clear(); distances.resize(pts.size()); closePts.clear(); closePts.resize(pts.size()); - for (unsigned int i = 0; i < pts.size(); i++) { + for(unsigned int i = 0; i < pts.size(); i++) { double d; SPoint3 closePt; const SPoint3 &p = pts[i]; @@ -920,13 +929,15 @@ void signedDistancesPointsLine(std::vector<double> &distances, } } -void changeReferential(const int direction,const SPoint3 &p,const SPoint3 &closePt, - const SPoint3 &p1, const SPoint3 &p2, double* xp, double* yp, - double* otherp, double* x, double* y, double* other) +void changeReferential(const int direction, const SPoint3 &p, + const SPoint3 &closePt, const SPoint3 &p1, + const SPoint3 &p2, double *xp, double *yp, + double *otherp, double *x, double *y, double *other) { - if(direction == 1){ + if(direction == 1) { const SPoint3 &d1 = SPoint3(1.0, 0.0, 0.0); - const SPoint3 &d = SPoint3(p2.x() - p1.x(), p2.y() - p1.y(), p2.z() - p1.z()); + const SPoint3 &d = + SPoint3(p2.x() - p1.x(), p2.y() - p1.y(), p2.z() - p1.z()); double norm = sqrt(d.x() * d.x() + d.y() * d.y() + d.z() * d.z()); const SPoint3 &dn = SPoint3(d.x() / norm, d.y() / norm, d.z() / norm); const SPoint3 &d3 = SPoint3(d1.y() * dn.z() - d1.z() * dn.y(), @@ -944,11 +955,13 @@ void changeReferential(const int direction,const SPoint3 &p,const SPoint3 &close *otherp = p.x() * d2n.x() + p.y() * d2n.y() + p.z() * d2n.z(); *x = closePt.x() * d1.x() + closePt.y() * d1.y() + closePt.z() * d1.z(); *y = closePt.x() * d3n.x() + closePt.y() * d3n.y() + closePt.z() * d3n.z(); - *other = closePt.x() * d2n.x() + closePt.y() * d2n.y() + closePt.z() * d2n.z(); + *other = + closePt.x() * d2n.x() + closePt.y() * d2n.y() + closePt.z() * d2n.z(); } - else{ + else { const SPoint3 &d2 = SPoint3(0.0, 1.0, 0.0); - const SPoint3 &d = SPoint3(p2.x() - p1.x(), p2.y() - p1.y(), p2.z() - p1.z()); + const SPoint3 &d = + SPoint3(p2.x() - p1.x(), p2.y() - p1.y(), p2.z() - p1.z()); double norm = sqrt(d.x() * d.x() + d.y() * d.y() + d.z() * d.z()); const SPoint3 &dn = SPoint3(d.x() / norm, d.y() / norm, d.z() / norm); const SPoint3 &d3 = SPoint3(dn.y() * d2.z() - dn.z() * d2.y(), @@ -966,7 +979,8 @@ void changeReferential(const int direction,const SPoint3 &p,const SPoint3 &close *otherp = p.x() * d1n.x() + p.y() * d1n.y() + p.z() * d1n.z(); *x = closePt.x() * d2.x() + closePt.y() * d2.y() + closePt.z() * d2.z(); *y = closePt.x() * d3n.x() + closePt.y() * d3n.y() + closePt.z() * d3n.z(); - *other = closePt.x() * d1n.x() + closePt.y() * d1n.y() + closePt.z() * d1n.z(); + *other = + closePt.x() * d1n.x() + closePt.y() * d1n.y() + closePt.z() * d1n.z(); } } @@ -976,21 +990,21 @@ int computeDistanceRatio(const double &y, const double &yp, const double &x, { double b; double a; - if (y == yp){ + if(y == yp) { b = -y; a = 0.0; } - else{ - if (x == xp){ + else { + if(x == xp) { b = -x; a = 0.0; } - else{ + else { b = (xp * y - x * yp) / (yp - y); - if (yp == 0.0){ - a=-(b+x)/y; + if(yp == 0.0) { + a = -(b + x) / y; } - else{ + else { a = -(b + xp) / yp; } } @@ -1000,85 +1014,85 @@ int computeDistanceRatio(const double &y, const double &yp, const double &x, double ce; double da = r1 * r1; double db = r2 * r2; - if (y == yp){ + if(y == yp) { ae = 1.0 / da; be = -(2 * x) / da; ce = (x * x / da) - 1.0; } - else{ - if (x == xp){ + else { + if(x == xp) { ae = 1.0 / db; be = -(2.0 * y) / db; ce = (y * y / db) - 1.0; } - else{ - if (fabs(a) < 0.00001){ + else { + if(fabs(a) < 0.00001) { ae = 1.0 / db; be = -(2.0 * y) / db; ce = (y * y / db) - 1.0; } - else{ + else { double a2 = a * a; ae = (1.0 / da) + (1.0 / (db * a2)); - be = (2.0 * y)/(db * a) + (2.0 * b) / (a2 * db) - ((2.0 * x) / da); - ce = (x * x) / da + (b * b) / (db * a2) + - (2.0 * b * y) / (a * db) + (y * y / db) - 1.0; + be = (2.0 * y) / (db * a) + (2.0 * b) / (a2 * db) - ((2.0 * x) / da); + ce = (x * x) / da + (b * b) / (db * a2) + (2.0 * b * y) / (a * db) + + (y * y / db) - 1.0; } } } double rho = be * be - 4 * ae * ce; double x1, x2, y1, y2, propdist; - if (rho < 0) { + if(rho < 0) { return 1; } - else{ + else { x1 = -(be + sqrt(rho)) / (2.0 * ae); x2 = (-be + sqrt(rho)) / (2.0 * ae); - if (y == yp){ + if(y == yp) { y1 = -b; y2 = -b; } - else{ - if (x == xp){ + else { + if(x == xp) { y1 = x1; y2 = x2; x1 = -b; x2 = -b; } - else{ - if (fabs(a) < 0.00001){ + else { + if(fabs(a) < 0.00001) { y1 = x1; y2 = x2; x1 = -b; x2 = -b; } - else{ + else { y1 = -(b + x1) / a; y2 = -(b + x2) / a; } } } - if (x1 == x2){ + if(x1 == x2) { propdist = (y1 - y) / (yp - y); - if(propdist < 0.0){ + if(propdist < 0.0) { propdist = (y2 - y) / (yp - y); } } - else{ - if (xp != x){ + else { + if(xp != x) { propdist = (x1 - x) / (xp - x); - if (propdist < 0.0){ + if(propdist < 0.0) { propdist = (x2 - x) / (xp - x); } } - else{ - if (yp != y){ + else { + if(yp != y) { propdist = (y1 - y) / (yp - y); - if(propdist < 0.0){ + if(propdist < 0.0) { propdist = (y2 - y) / (yp - y); } } - else{ + else { propdist = 0.01; } } @@ -1089,13 +1103,12 @@ int computeDistanceRatio(const double &y, const double &yp, const double &x, } void signedDistancesPointsEllipsePoint(std::vector<double> &distances, - std::vector<double> &distancesE, - std::vector<int> &isInYarn, - std::vector<SPoint3> &closePts, - const std::vector<SPoint3> &pts, - const SPoint3 &p1, - const SPoint3 &p2, - const double radius) + std::vector<double> &distancesE, + std::vector<int> &isInYarn, + std::vector<SPoint3> &closePts, + const std::vector<SPoint3> &pts, + const SPoint3 &p1, const SPoint3 &p2, + const double radius) { distances.clear(); distances.resize(pts.size()); @@ -1106,35 +1119,29 @@ void signedDistancesPointsEllipsePoint(std::vector<double> &distances, closePts.clear(); closePts.resize(pts.size()); double d; - for (unsigned int i = 0; i < pts.size();i++){ + for(unsigned int i = 0; i < pts.size(); i++) { SPoint3 closePt; const SPoint3 &p = pts[i]; signedDistancePointLine(p1, p2, p, d, closePt); closePts[i] = closePt; distances[i] = d; - if (d <= radius){ + if(d <= radius) { isInYarn[i] = 1; distancesE[i] = radius - d; } - else{ + else { isInYarn[i] = 0; distancesE[i] = d - radius; } } } -void signedDistancesPointsEllipseLine(std::vector<double>&distances, - std::vector<double> &distancesE, - std::vector<int>&isInYarn, - std::vector<SPoint3>&closePts, - const std::vector<SPoint3> &pts, - const SPoint3 &p1, - const SPoint3 &p2, - const double maxA, - const double minA, - const double maxB, - const double minB, - const int typeLevelSet) +void signedDistancesPointsEllipseLine( + std::vector<double> &distances, std::vector<double> &distancesE, + std::vector<int> &isInYarn, std::vector<SPoint3> &closePts, + const std::vector<SPoint3> &pts, const SPoint3 &p1, const SPoint3 &p2, + const double maxA, const double minA, const double maxB, const double minB, + const int typeLevelSet) { distances.clear(); distances.resize(pts.size()); @@ -1145,153 +1152,178 @@ void signedDistancesPointsEllipseLine(std::vector<double>&distances, closePts.clear(); closePts.resize(pts.size()); double d; - for (unsigned int i = 0; i < pts.size();i++){ + for(unsigned int i = 0; i < pts.size(); i++) { SPoint3 closePt; const SPoint3 &p = pts[i]; - signedDistancePointLine(p1,p2,p,d,closePt); + signedDistancePointLine(p1, p2, p, d, closePt); distances[i] = d; closePts[i] = closePt; - int direction=0; - if (!(p.x()==closePt.x() && p.y()==closePt.y() && p.z()==closePt.z())){ - double xp,yp,x,y,otherp,other,propdist; - if (typeLevelSet==2){ - if (p1.x()==p2.x()){ - direction=1; - if (fabs(closePt.x()-0.0)<0.00000001) isInYarn[i]=1; - if (fabs(closePt.x()-2.2)<0.00000001) isInYarn[i]=1; + int direction = 0; + if(!(p.x() == closePt.x() && p.y() == closePt.y() && + p.z() == closePt.z())) { + double xp, yp, x, y, otherp, other, propdist; + if(typeLevelSet == 2) { + if(p1.x() == p2.x()) { + direction = 1; + if(fabs(closePt.x() - 0.0) < 0.00000001) isInYarn[i] = 1; + if(fabs(closePt.x() - 2.2) < 0.00000001) isInYarn[i] = 1; } - else{ - if (p1.y()==p2.y()){ - direction=2; - if (fabs(closePt.y()-0.0)<0.00000001) isInYarn[i]=6; - if (fabs(closePt.y()-2.2)<0.00000001) isInYarn[i]=6; + else { + if(p1.y() == p2.y()) { + direction = 2; + if(fabs(closePt.y() - 0.0) < 0.00000001) isInYarn[i] = 6; + if(fabs(closePt.y() - 2.2) < 0.00000001) isInYarn[i] = 6; } - else{ - printf("Error %lf %lf\n",closePt.x(),closePt.y()); + else { + printf("Error %lf %lf\n", closePt.x(), closePt.y()); } } } - if (typeLevelSet==1){ - if (p1.x()==p2.x()){ - direction=1; - //if (fabs(closePt.x() - 0.0) < 0.00000001) isInYarn[i] = 1; - if (fabs(closePt.x() - 2.2) < 0.00000001) isInYarn[i] = 4; - //if (fabs(closePt.x() - 4.4) < 0.00000001) isInYarn[i] = 2; - //if (fabs(closePt.x() - 6.6) < 0.00000001) isInYarn[i] = 5; - //if (fabs(closePt.x() - 8.8) < 0.00000001) isInYarn[i] = 3; - //if (fabs(closePt.x() - 11.0) < 0.00000001) isInYarn[i] = 1; + if(typeLevelSet == 1) { + if(p1.x() == p2.x()) { + direction = 1; + // if (fabs(closePt.x() - 0.0) < 0.00000001) isInYarn[i] = 1; + if(fabs(closePt.x() - 2.2) < 0.00000001) isInYarn[i] = 4; + // if (fabs(closePt.x() - 4.4) < 0.00000001) isInYarn[i] = 2; + // if (fabs(closePt.x() - 6.6) < 0.00000001) isInYarn[i] = 5; + // if (fabs(closePt.x() - 8.8) < 0.00000001) isInYarn[i] = 3; + // if (fabs(closePt.x() - 11.0) < 0.00000001) isInYarn[i] = 1; } - else{ - if (p1.y() == p2.y()){ + else { + if(p1.y() == p2.y()) { direction = 2; - //if (fabs(closePt.y() - 0.0) < 0.00000001) isInYarn[i] = 6; - if (fabs(closePt.y() - 2.2) < 0.00000001) isInYarn[i] = 7; - //if (fabs(closePt.y() - 4.4) < 0.00000001) isInYarn[i] = 8; - //if (fabs(closePt.y() - 6.6) < 0.00000001) isInYarn[i] = 9; - //if (fabs(closePt.y() - 8.8) < 0.00000001) isInYarn[i] = 10; - //if (fabs(closePt.y() - 11.0) < 0.00000001) isInYarn[i] = 6; + // if (fabs(closePt.y() - 0.0) < 0.00000001) isInYarn[i] = 6; + if(fabs(closePt.y() - 2.2) < 0.00000001) isInYarn[i] = 7; + // if (fabs(closePt.y() - 4.4) < 0.00000001) isInYarn[i] = 8; + // if (fabs(closePt.y() - 6.6) < 0.00000001) isInYarn[i] = 9; + // if (fabs(closePt.y() - 8.8) < 0.00000001) isInYarn[i] = 10; + // if (fabs(closePt.y() - 11.0) < 0.00000001) isInYarn[i] = 6; } - else{ + else { printf("Error %lf %lf\n", closePt.x(), closePt.y()); } } } - if (typeLevelSet==4){ - if (p1.x()==p2.x()){ - direction=1; - if (fabs(closePt.x()-0.0)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=1; - if (fabs(closePt.x()-2.2)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=4; - if (fabs(closePt.x()-4.4)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=2; - if (fabs(closePt.x()-6.6)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=5; - if (fabs(closePt.x()-8.8)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=3; - if (fabs(closePt.x()-11.0)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=1; - if (fabs(closePt.x()-0.0)<0.00000001 && closePt.z()>0.35) isInYarn[i]=11; - if (fabs(closePt.x()-2.2)<0.00000001 && closePt.z()>0.35) isInYarn[i]=14; - if (fabs(closePt.x()-4.4)<0.00000001 && closePt.z()>0.35) isInYarn[i]=12; - if (fabs(closePt.x()-6.6)<0.00000001 && closePt.z()>0.35) isInYarn[i]=15; - if (fabs(closePt.x()-8.8)<0.00000001 && closePt.z()>0.35) isInYarn[i]=13; - if (fabs(closePt.x()-11.0)<0.00000001 && closePt.z()>0.35) isInYarn[i]=11; + if(typeLevelSet == 4) { + if(p1.x() == p2.x()) { + direction = 1; + if(fabs(closePt.x() - 0.0) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 1; + if(fabs(closePt.x() - 2.2) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 4; + if(fabs(closePt.x() - 4.4) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 2; + if(fabs(closePt.x() - 6.6) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 5; + if(fabs(closePt.x() - 8.8) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 3; + if(fabs(closePt.x() - 11.0) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 1; + if(fabs(closePt.x() - 0.0) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 11; + if(fabs(closePt.x() - 2.2) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 14; + if(fabs(closePt.x() - 4.4) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 12; + if(fabs(closePt.x() - 6.6) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 15; + if(fabs(closePt.x() - 8.8) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 13; + if(fabs(closePt.x() - 11.0) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 11; } - else{ - if (p1.y()==p2.y()){ - direction=2; - if (fabs(closePt.y()-0.0)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=6; - if (fabs(closePt.y()-2.2)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=7; - if (fabs(closePt.y()-4.4)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=8; - if (fabs(closePt.y()-6.6)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=9; - if (fabs(closePt.y()-8.8)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=10; - if (fabs(closePt.y()-11.0)<0.00000001 && closePt.z()<=0.35) isInYarn[i]=6; - if (fabs(closePt.y()-0.0)<0.00000001 && closePt.z()>0.35) isInYarn[i]=16; - if (fabs(closePt.y()-2.2)<0.00000001 && closePt.z()>0.35) isInYarn[i]=17; - if (fabs(closePt.y()-4.4)<0.00000001 && closePt.z()>0.35) isInYarn[i]=18; - if (fabs(closePt.y()-6.6)<0.00000001 && closePt.z()>0.35) isInYarn[i]=19; - if (fabs(closePt.y()-8.8)<0.00000001 && closePt.z()>0.35) isInYarn[i]=20; - if (fabs(closePt.y()-11.0)<0.00000001 && closePt.z()>0.35) isInYarn[i]=16; + else { + if(p1.y() == p2.y()) { + direction = 2; + if(fabs(closePt.y() - 0.0) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 6; + if(fabs(closePt.y() - 2.2) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 7; + if(fabs(closePt.y() - 4.4) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 8; + if(fabs(closePt.y() - 6.6) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 9; + if(fabs(closePt.y() - 8.8) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 10; + if(fabs(closePt.y() - 11.0) < 0.00000001 && closePt.z() <= 0.35) + isInYarn[i] = 6; + if(fabs(closePt.y() - 0.0) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 16; + if(fabs(closePt.y() - 2.2) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 17; + if(fabs(closePt.y() - 4.4) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 18; + if(fabs(closePt.y() - 6.6) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 19; + if(fabs(closePt.y() - 8.8) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 20; + if(fabs(closePt.y() - 11.0) < 0.00000001 && closePt.z() > 0.35) + isInYarn[i] = 16; } - else{ - printf("Error %lf %lf\n",closePt.x(),closePt.y()); + else { + printf("Error %lf %lf\n", closePt.x(), closePt.y()); } } } - if (typeLevelSet==3){ - direction=3; - isInYarn[i]=1; + if(typeLevelSet == 3) { + direction = 3; + isInYarn[i] = 1; } - if (typeLevelSet==5){ - if(p1.x()==p2.x()){ - direction=1; - if (fabs(closePt.x() - 0.0) < 0.00000001) isInYarn[i] = 1; - if (fabs(closePt.x() - 3.225) < 0.00000001) isInYarn[i] = 2; - if (fabs(closePt.x() - 6.45) < 0.00000001) isInYarn[i] = 3; - if (fabs(closePt.x() - 9.675) < 0.00000001) isInYarn[i] = 4; - if (fabs(closePt.x() - 12.9) < 0.00000001) isInYarn[i] = 1; + if(typeLevelSet == 5) { + if(p1.x() == p2.x()) { + direction = 1; + if(fabs(closePt.x() - 0.0) < 0.00000001) isInYarn[i] = 1; + if(fabs(closePt.x() - 3.225) < 0.00000001) isInYarn[i] = 2; + if(fabs(closePt.x() - 6.45) < 0.00000001) isInYarn[i] = 3; + if(fabs(closePt.x() - 9.675) < 0.00000001) isInYarn[i] = 4; + if(fabs(closePt.x() - 12.9) < 0.00000001) isInYarn[i] = 1; } - else{ - if (p1.y()==p2.y()){ - direction=2; - if (fabs(closePt.y() - 0.0) < 0.00000001) isInYarn[i] = 5; - if (fabs(closePt.y() - 1.665) < 0.00000001) isInYarn[i] = 6; - if (fabs(closePt.y() - 3.33) < 0.00000001) isInYarn[i] = 7; - if (fabs(closePt.y() - 4.995) < 0.00000001) isInYarn[i] = 8; - if (fabs(closePt.y() - 6.66) < 0.00000001) isInYarn[i] = 5; + else { + if(p1.y() == p2.y()) { + direction = 2; + if(fabs(closePt.y() - 0.0) < 0.00000001) isInYarn[i] = 5; + if(fabs(closePt.y() - 1.665) < 0.00000001) isInYarn[i] = 6; + if(fabs(closePt.y() - 3.33) < 0.00000001) isInYarn[i] = 7; + if(fabs(closePt.y() - 4.995) < 0.00000001) isInYarn[i] = 8; + if(fabs(closePt.y() - 6.66) < 0.00000001) isInYarn[i] = 5; } - else{ - printf("Error %lf %lf\n",closePt.x(),closePt.y()); + else { + printf("Error %lf %lf\n", closePt.x(), closePt.y()); } } } - changeReferential(direction, p, closePt, p1, p2, &xp, &yp, - &otherp, &x, &y, &other); + changeReferential(direction, p, closePt, p1, p2, &xp, &yp, &otherp, &x, + &y, &other); int result = 1; - if (fabs(other-otherp) > 0.01){ + if(fabs(other - otherp) > 0.01) { result = 1; } - else{ - if (direction==1){ + else { + if(direction == 1) { result = computeDistanceRatio(y, yp, x, xp, &propdist, maxA, minA); } - else{ - if (direction==2){ + else { + if(direction == 2) { result = computeDistanceRatio(y, yp, x, xp, &propdist, maxB, minB); } } } - if (result == 1){ + if(result == 1) { distancesE[i] = 1.e10; isInYarn[i] = 0; } - else{ - if (propdist < 1.0){ + else { + if(propdist < 1.0) { isInYarn[i] = 0; distancesE[i] = (1.0 / propdist) - 1.0; } - else{ + else { distancesE[i] = (1.0 - (1.0 / propdist)); } } } - else{ + else { isInYarn[i] = 0; distancesE[i] = 1000000.0; } @@ -1299,10 +1331,8 @@ void signedDistancesPointsEllipseLine(std::vector<double>&distances, } int intersection_segments(const SPoint2 &p1, const SPoint2 &p2, - const SPoint2 &q1, const SPoint2 &q2, - double x[2]) + const SPoint2 &q1, const SPoint2 &q2, double x[2]) { - double xp_max = std::max(p1.x(), p2.x()); double yp_max = std::max(p1.y(), p2.y()); double xq_max = std::max(q1.x(), q2.x()); @@ -1312,11 +1342,10 @@ int intersection_segments(const SPoint2 &p1, const SPoint2 &p2, double yp_min = std::min(p1.y(), p2.y()); double xq_min = std::min(q1.x(), q2.x()); double yq_min = std::min(q1.y(), q2.y()); - if (yq_min > yp_max || xq_min > xp_max || - yq_max < yp_min || xq_max < xp_min){ + if(yq_min > yp_max || xq_min > xp_max || yq_max < yp_min || xq_max < xp_min) { return 0; } - else{ + else { double A[2][2]; A[0][0] = p2.x() - p1.x(); A[0][1] = q1.x() - q2.x(); @@ -1324,19 +1353,17 @@ int intersection_segments(const SPoint2 &p1, const SPoint2 &p2, A[1][1] = q1.y() - q2.y(); double b[2] = {q1.x() - p1.x(), q1.y() - p1.y()}; sys2x2(A, b, x); - return (x[0] >= 0.0 && x[0] <= 1. && - x[1] >= 0.0 && x[1] <= 1.); + return (x[0] >= 0.0 && x[0] <= 1. && x[1] >= 0.0 && x[1] <= 1.); } } /// 3D VERSION int intersection_segments(const SPoint3 &p1, const SPoint3 &p2, - const SPoint3 &q1, const SPoint3 &q2, - double x[2]) + const SPoint3 &q1, const SPoint3 &q2, double x[2]) { - SVector3 v1(p2,p1),v2(q2,q1); + SVector3 v1(p2, p1), v2(q2, q1); double n1 = v1.norm(); double n2 = v2.norm(); - double EPS = 1.e-10*std::max(n1,n2); + double EPS = 1.e-10 * std::max(n1, n2); double A[2][2]; A[0][0] = p2.x() - p1.x(); A[0][1] = q1.x() - q2.x(); @@ -1359,25 +1386,23 @@ int intersection_segments(const SPoint3 &p1, const SPoint3 &p2, double detB = fabs(det2x2(B)); double detC = fabs(det2x2(C)); // printf("%12.5E %12.5E %12.5E\n",detA,detB,detC); - if (detA > detB && detA > detC) + if(detA > detB && detA > detC) sys2x2(A, a, x); - else if (detB > detA && detB > detC) + else if(detB > detA && detB > detC) sys2x2(B, b, x); else sys2x2(C, c, x); - if(x[0] >= 0.0 && x[0] <= 1. && - x[1] >= 0.0 && x[1] <= 1.) { - - SPoint3 x1 (p1.x()*(1.-x[0]) + p2.x()*x[0], - p1.y()*(1.-x[0]) + p2.y()*x[0], - p1.z()*(1.-x[0]) + p2.z()*x[0]); - SPoint3 x2 (q1.x()*(1.-x[0]) + q2.x()*x[0], - q1.y()*(1.-x[0]) + q2.y()*x[0], - q1.z()*(1.-x[0]) + q2.z()*x[0]); - - SVector3 d (x2,x1); + if(x[0] >= 0.0 && x[0] <= 1. && x[1] >= 0.0 && x[1] <= 1.) { + SPoint3 x1(p1.x() * (1. - x[0]) + p2.x() * x[0], + p1.y() * (1. - x[0]) + p2.y() * x[0], + p1.z() * (1. - x[0]) + p2.z() * x[0]); + SPoint3 x2(q1.x() * (1. - x[0]) + q2.x() * x[0], + q1.y() * (1. - x[0]) + q2.y() * x[0], + q1.z() * (1. - x[0]) + q2.z() * x[0]); + + SVector3 d(x2, x1); double nd = norm(d); - if (nd > EPS){ + if(nd > EPS) { x[0] = x[1] = 1.e22; return false; } @@ -1386,14 +1411,12 @@ int intersection_segments(const SPoint3 &p1, const SPoint3 &p2, return false; } -void fillMeanPlane(double res[4], double t1[3], double t2[3], mean_plane &meanPlane) +void fillMeanPlane(double res[4], double t1[3], double t2[3], + mean_plane &meanPlane) { - for(int i = 0; i < 3; i++) - meanPlane.plan[0][i] = t1[i]; - for(int i = 0; i < 3; i++) - meanPlane.plan[1][i] = t2[i]; - for(int i = 0; i < 3; i++) - meanPlane.plan[2][i] = res[i]; + for(int i = 0; i < 3; i++) meanPlane.plan[0][i] = t1[i]; + for(int i = 0; i < 3; i++) meanPlane.plan[1][i] = t2[i]; + for(int i = 0; i < 3; i++) meanPlane.plan[2][i] = res[i]; meanPlane.a = res[0]; meanPlane.b = res[1]; @@ -1402,19 +1425,20 @@ void fillMeanPlane(double res[4], double t1[3], double t2[3], mean_plane &meanPl meanPlane.x = meanPlane.y = meanPlane.z = 0.; if(fabs(meanPlane.a) >= fabs(meanPlane.b) && - fabs(meanPlane.a) >= fabs(meanPlane.c) ){ + fabs(meanPlane.a) >= fabs(meanPlane.c)) { meanPlane.x = meanPlane.d / meanPlane.a; } else if(fabs(meanPlane.b) >= fabs(meanPlane.a) && - fabs(meanPlane.b) >= fabs(meanPlane.c)){ + fabs(meanPlane.b) >= fabs(meanPlane.c)) { meanPlane.y = meanPlane.d / meanPlane.b; } - else{ + else { meanPlane.z = meanPlane.d / meanPlane.c; } } -void computeMeanPlaneSimple(const std::vector<SPoint3> &points, mean_plane &meanPlane) +void computeMeanPlaneSimple(const std::vector<SPoint3> &points, + mean_plane &meanPlane) { double xm = 0., ym = 0., zm = 0.; int ndata = points.size(); @@ -1472,54 +1496,60 @@ void computeMeanPlaneSimple(const std::vector<SPoint3> &points, mean_plane &mean fillMeanPlane(res, t1, t2, meanPlane); } -void projectPointToPlane(const SPoint3 &pt, SPoint3 &ptProj, const mean_plane &meanPlane) +void projectPointToPlane(const SPoint3 &pt, SPoint3 &ptProj, + const mean_plane &meanPlane) { - double u = pt.x(); - double v = pt.y(); - double w = pt.z(); + double u = pt.x(); + double v = pt.y(); + double w = pt.z(); double a = meanPlane.a; double b = meanPlane.b; double c = meanPlane.c; double d = meanPlane.d; - double t0 = -(a*u+b*v+c*w+d)/(a*a+b*b+c*c); + double t0 = -(a * u + b * v + c * w + d) / (a * a + b * b + c * c); - ptProj[0] = u + a*t0; - ptProj[1] = v + b*t0; - ptProj[2] = w + c*t0; + ptProj[0] = u + a * t0; + ptProj[1] = v + b * t0; + ptProj[2] = w + c * t0; } -void projectPointsToPlane(const std::vector<SPoint3> &pts, std::vector<SPoint3> &ptsProj, +void projectPointsToPlane(const std::vector<SPoint3> &pts, + std::vector<SPoint3> &ptsProj, const mean_plane &meanPlane) { ptsProj.resize(pts.size()); - for (unsigned int i= 0; i< pts.size(); i++){ - projectPointToPlane(pts[i],ptsProj[i], meanPlane); + for(unsigned int i = 0; i < pts.size(); i++) { + projectPointToPlane(pts[i], ptsProj[i], meanPlane); } } void transformPointsIntoOrthoBasis(const std::vector<SPoint3> &ptsProj, std::vector<SPoint3> &pointsUV, - const SPoint3 &ptCG, const mean_plane &meanPlane) + const SPoint3 &ptCG, + const mean_plane &meanPlane) { pointsUV.resize(ptsProj.size()); SVector3 normal(meanPlane.a, meanPlane.b, meanPlane.c); SVector3 tangent, binormal; buildOrthoBasis(normal, tangent, binormal); - for (unsigned int i= 0; i< ptsProj.size(); i++){ - SVector3 pp(ptsProj[i][0]-ptCG[0],ptsProj[i][1]-ptCG[1],ptsProj[i][2]-ptCG[2]) ; + for(unsigned int i = 0; i < ptsProj.size(); i++) { + SVector3 pp(ptsProj[i][0] - ptCG[0], ptsProj[i][1] - ptCG[1], + ptsProj[i][2] - ptCG[2]); pointsUV[i][0] = dot(pp, tangent); pointsUV[i][1] = dot(pp, binormal); pointsUV[i][2] = dot(pp, normal); } } -static bool catenary_fct(fullVector<double> &x, fullVector<double> &res, void *data) +static bool catenary_fct(fullVector<double> &x, fullVector<double> &res, + void *data) { - double *param = (double*)data; - double x0 = param[0], x1 = param[1], y0 = param[2], y1 = param[3], ys = param[4]; - res(0) = (ys-1/x(0)) + 1/x(0)*cosh(x(0)*(x0-x(1))) - y0; - res(1) = (ys-1/x(0)) + 1/x(0)*cosh(x(0)*(x1-x(1))) - y1; + double *param = (double *)data; + double x0 = param[0], x1 = param[1], y0 = param[2], y1 = param[3], + ys = param[4]; + res(0) = (ys - 1 / x(0)) + 1 / x(0) * cosh(x(0) * (x0 - x(1))) - y0; + res(1) = (ys - 1 / x(0)) + 1 / x(0) * cosh(x(0) * (x1 - x(1))) - y1; return true; } @@ -1540,22 +1570,22 @@ bool catenary(double x0, double x1, double y0, double y1, double ys, int N, double param[5] = {x0, x1, y0, y1, ys}; fullVector<double> x(2); bool success = false; - if(x0 != x1){ - x(0) = 1./(x1-x0); - x(1) = (x0+x1)/2.; - success = newton_fd(catenary_fct, x, param, 1., 1e-6*fabs(x1-x0)); + if(x0 != x1) { + x(0) = 1. / (x1 - x0); + x(1) = (x0 + x1) / 2.; + success = newton_fd(catenary_fct, x, param, 1., 1e-6 * fabs(x1 - x0)); } - if(success){ - double a = ys-1/x(0); - for(int i = 0; i < N; i++){ - double r = x0 + (i+1) * (x1-x0)/(N+1); - yp[i] = a+1/x(0)*cosh(x(0)*(r-x(1))); + if(success) { + double a = ys - 1 / x(0); + for(int i = 0; i < N; i++) { + double r = x0 + (i + 1) * (x1 - x0) / (N + 1); + yp[i] = a + 1 / x(0) * cosh(x(0) * (r - x(1))); } return true; } - else{ - for(int i = 0; i < N; i++){ - yp[i] = y0 + (i+1) * (y1-y0)/(N+1); + else { + for(int i = 0; i < N; i++) { + yp[i] = y0 + (i + 1) * (y1 - y0) / (N + 1); } return false; } diff --git a/Numeric/bezierBasis.cpp b/Numeric/bezierBasis.cpp index d5d012ae54b8a1ba400e752db0e6ac2f891ac522..15fd87d73ba1a2586d6c9c87d4046bf04d7b47f6 100644 --- a/Numeric/bezierBasis.cpp +++ b/Numeric/bezierBasis.cpp @@ -16,23 +16,23 @@ namespace { // Sub Control Points - std::vector< fullMatrix<double> > generateSubPointsLine(int order) + std::vector<fullMatrix<double> > generateSubPointsLine(int order) { - std::vector< fullMatrix<double> > subPoints(2); + std::vector<fullMatrix<double> > subPoints(2); subPoints[0] = gmshGenerateMonomialsLine(order); - subPoints[0].scale(.5/order); + subPoints[0].scale(.5 / order); subPoints[1].copy(subPoints[0]); subPoints[1].add(.5); return subPoints; } - std::vector< fullMatrix<double> > generateSubPointsTriangle(int order) + std::vector<fullMatrix<double> > generateSubPointsTriangle(int order) { - std::vector< fullMatrix<double> > subPoints(4); + std::vector<fullMatrix<double> > subPoints(4); fullMatrix<double> prox; subPoints[0] = gmshGenerateMonomialsTriangle(order); - subPoints[0].scale(.5/order); + subPoints[0].scale(.5 / order); subPoints[1].copy(subPoints[0]); prox.setAsProxy(subPoints[1], 0, 1); @@ -48,12 +48,12 @@ namespace { return subPoints; } - std::vector< fullMatrix<double> > generateSubPointsQuad(int order) + std::vector<fullMatrix<double> > generateSubPointsQuad(int order) { - std::vector< fullMatrix<double> > subPoints(4); + std::vector<fullMatrix<double> > subPoints(4); fullMatrix<double> prox; subPoints[0] = gmshGenerateMonomialsQuadrangle(order); - subPoints[0].scale(.5/order); + subPoints[0].scale(.5 / order); subPoints[1].copy(subPoints[0]); prox.setAsProxy(subPoints[1], 0, 1); @@ -69,13 +69,13 @@ namespace { return subPoints; } - std::vector< fullMatrix<double> > generateSubPointsTetrahedron(int order) + std::vector<fullMatrix<double> > generateSubPointsTetrahedron(int order) { - std::vector< fullMatrix<double> > subPoints(8); + std::vector<fullMatrix<double> > subPoints(8); fullMatrix<double> prox1; fullMatrix<double> prox2; subPoints[0] = gmshGenerateMonomialsTetrahedron(order); - subPoints[0].scale(.5/order); + subPoints[0].scale(.5 / order); subPoints[1].copy(subPoints[0]); prox1.setAsProxy(subPoints[1], 0, 1); @@ -137,13 +137,13 @@ namespace { return subPoints; } - std::vector< fullMatrix<double> > generateSubPointsPrism(int order) + std::vector<fullMatrix<double> > generateSubPointsPrism(int order) { - std::vector< fullMatrix<double> > subPoints(8); + std::vector<fullMatrix<double> > subPoints(8); fullMatrix<double> prox; subPoints[0] = gmshGenerateMonomialsPrism(order); - subPoints[0].scale(.5/order); + subPoints[0].scale(.5 / order); subPoints[1].copy(subPoints[0]); prox.setAsProxy(subPoints[1], 0, 1); @@ -177,13 +177,13 @@ namespace { return subPoints; } - std::vector< fullMatrix<double> > generateSubPointsHex(int order) + std::vector<fullMatrix<double> > generateSubPointsHex(int order) { - std::vector< fullMatrix<double> > subPoints(8); + std::vector<fullMatrix<double> > subPoints(8); fullMatrix<double> prox; subPoints[0] = gmshGenerateMonomialsHexahedron(order); - subPoints[0].scale(.5/order); + subPoints[0].scale(.5 / order); subPoints[1].copy(subPoints[0]); prox.setAsProxy(subPoints[1], 0, 1); @@ -216,14 +216,14 @@ namespace { return subPoints; } - std::vector< fullMatrix<double> > generateSubPointsPyr(int nij, int nk) + std::vector<fullMatrix<double> > generateSubPointsPyr(int nij, int nk) { - if(nk == 0){ - std::vector< fullMatrix<double> > subPoints(4); + if(nk == 0) { + std::vector<fullMatrix<double> > subPoints(4); fullMatrix<double> prox; subPoints[0] = gmshGenerateMonomialsPyramidGeneral(false, nij, nk); - subPoints[0].scale(.5/nij); + subPoints[0].scale(.5 / nij); subPoints[1].copy(subPoints[0]); prox.setAsProxy(subPoints[1], 0, 1); @@ -240,14 +240,14 @@ namespace { return subPoints; } else { - std::vector< fullMatrix<double> > subPoints(8); + std::vector<fullMatrix<double> > subPoints(8); fullMatrix<double> ref, prox; subPoints[0] = gmshGenerateMonomialsPyramidGeneral(false, nij, nk); prox.setAsProxy(subPoints[0], 2, 1); prox.scale(-1); prox.add(nk); - subPoints[0].scale(.5/std::max(nij,nk)); + subPoints[0].scale(.5 / std::max(nij, nk)); subPoints[1].copy(subPoints[0]); prox.setAsProxy(subPoints[1], 0, 1); @@ -277,7 +277,7 @@ namespace { prox.setAsProxy(subPoints[7], 2, 1); prox.add(.5); - for(int i = 0; i < 8; ++i){ + for(int i = 0; i < 8; ++i) { prox.setAsProxy(subPoints[i], 2, 1); prox.scale(-1); prox.add(1); @@ -290,30 +290,28 @@ namespace { // Matrices generation int nChoosek(int n, int k) { - if(n < k || k < 0){ + if(n < k || k < 0) { Msg::Error("Wrong argument for combination. (%d, %d)", n, k); return 1; } - if(k > n/2) k = n-k; - if(k == 1) - return n; - if(k == 0) - return 1; + if(k > n / 2) k = n - k; + if(k == 1) return n; + if(k == 0) return 1; int c = 1; for(int i = 1; i <= k; i++, n--) (c *= n) /= i; return c; } - fullMatrix<double> generateBez2LagMatrix - (const fullMatrix<double> &exponent, const fullMatrix<double> &point, - int order, int dimSimplex) + fullMatrix<double> generateBez2LagMatrix(const fullMatrix<double> &exponent, + const fullMatrix<double> &point, + int order, int dimSimplex) { - if(exponent.size1() != point.size1() || exponent.size2() != point.size2()){ + if(exponent.size1() != point.size1() || exponent.size2() != point.size2()) { Msg::Fatal("Wrong sizes for bez2lag matrix generation %d %d -- %d %d", - exponent.size1(),point.size1(), - exponent.size2(),point.size2()); + exponent.size1(), point.size1(), exponent.size2(), + point.size2()); return fullMatrix<double>(1, 1); } @@ -321,25 +319,25 @@ namespace { int dim = exponent.size2(); fullMatrix<double> bez2Lag(ndofs, ndofs); - for(int i = 0; i < ndofs; i++){ - for(int j = 0; j < ndofs; j++){ + for(int i = 0; i < ndofs; i++) { + for(int j = 0; j < ndofs; j++) { double dd = 1.; { double pointCompl = 1.; int exponentCompl = order; - for(int k = 0; k < dimSimplex; k++){ - dd *= nChoosek(exponentCompl, (int) exponent(i, k)) - * pow(point(j, k), exponent(i, k)); + for(int k = 0; k < dimSimplex; k++) { + dd *= nChoosek(exponentCompl, (int)exponent(i, k)) * + pow(point(j, k), exponent(i, k)); pointCompl -= point(j, k); - exponentCompl -= (int) exponent(i, k); + exponentCompl -= (int)exponent(i, k); } dd *= pow(pointCompl, exponentCompl); } for(int k = dimSimplex; k < dim; k++) - dd *= nChoosek(order, (int) exponent(i, k)) - * pow(point(j, k), exponent(i, k)) - * pow(1. - point(j, k), order - exponent(i, k)); + dd *= nChoosek(order, (int)exponent(i, k)) * + pow(point(j, k), exponent(i, k)) * + pow(1. - point(j, k), order - exponent(i, k)); bez2Lag(j, i) = dd; } @@ -347,15 +345,16 @@ namespace { return bez2Lag; } - fullMatrix<double> generateBez2LagMatrixPyramid - (const fullMatrix<double> &exponent, const fullMatrix<double> &point, - bool pyr, int nij, int nk) + fullMatrix<double> + generateBez2LagMatrixPyramid(const fullMatrix<double> &exponent, + const fullMatrix<double> &point, bool pyr, + int nij, int nk) { if(exponent.size1() != point.size1() || exponent.size2() != point.size2() || - exponent.size2() != 3){ - Msg::Fatal("Wrong sizes for pyramid's bez2lag matrix generation %d %d -- %d %d", - exponent.size1(), point.size1(), - exponent.size2(), point.size2()); + exponent.size2() != 3) { + Msg::Fatal( + "Wrong sizes for pyramid's bez2lag matrix generation %d %d -- %d %d", + exponent.size1(), point.size1(), exponent.size2(), point.size2()); return fullMatrix<double>(1, 1); } @@ -363,33 +362,33 @@ namespace { int n01 = nij; fullMatrix<double> bez2Lag(ndofs, ndofs); - for(int i = 0; i < ndofs; i++){ - for(int j = 0; j < ndofs; j++){ + for(int i = 0; i < ndofs; i++) { + for(int j = 0; j < ndofs; j++) { if(pyr) n01 = exponent(j, 2) + nij; bez2Lag(i, j) = - nChoosek(n01, exponent(j, 0)) - * nChoosek(n01, exponent(j, 1)) - * nChoosek(nk , exponent(j, 2)) - * pow_int(point(i, 0), exponent(j, 0)) - * pow_int(point(i, 1), exponent(j, 1)) - * pow_int(point(i, 2), exponent(j, 2)) - * pow_int(1. - point(i, 0), n01 - exponent(j, 0)) - * pow_int(1. - point(i, 1), n01 - exponent(j, 1)) - * pow_int(1. - point(i, 2), nk - exponent(j, 2)); + nChoosek(n01, exponent(j, 0)) * nChoosek(n01, exponent(j, 1)) * + nChoosek(nk, exponent(j, 2)) * pow_int(point(i, 0), exponent(j, 0)) * + pow_int(point(i, 1), exponent(j, 1)) * + pow_int(point(i, 2), exponent(j, 2)) * + pow_int(1. - point(i, 0), n01 - exponent(j, 0)) * + pow_int(1. - point(i, 1), n01 - exponent(j, 1)) * + pow_int(1. - point(i, 2), nk - exponent(j, 2)); } } return bez2Lag; } - fullMatrix<double> generateSubDivisor - (const fullMatrix<double> &exponents, - const std::vector< fullMatrix<double> > &subPoints, - const fullMatrix<double> &lag2Bez, int order, int dimSimplex) + fullMatrix<double> + generateSubDivisor(const fullMatrix<double> &exponents, + const std::vector<fullMatrix<double> > &subPoints, + const fullMatrix<double> &lag2Bez, int order, + int dimSimplex) { - if(exponents.size1() != lag2Bez.size1() || exponents.size1() != lag2Bez.size2()){ + if(exponents.size1() != lag2Bez.size1() || + exponents.size1() != lag2Bez.size2()) { Msg::Error("Wrong sizes for Bezier Divisor %d %d -- %d %d", - exponents.size1(), lag2Bez.size1(), - exponents.size1(), lag2Bez.size2()); + exponents.size1(), lag2Bez.size1(), exponents.size1(), + lag2Bez.size2()); return fullMatrix<double>(1, 1); } @@ -399,24 +398,26 @@ namespace { fullMatrix<double> intermediate2(nbPts, nbPts); fullMatrix<double> subDivisor(nbSubPts, nbPts); - for(unsigned int i = 0; i < subPoints.size(); i++){ + for(unsigned int i = 0; i < subPoints.size(); i++) { fullMatrix<double> intermediate1 = generateBez2LagMatrix(exponents, subPoints[i], order, dimSimplex); lag2Bez.mult(intermediate1, intermediate2); - subDivisor.copy(intermediate2, 0, nbPts, 0, nbPts, i*nbPts, 0); + subDivisor.copy(intermediate2, 0, nbPts, 0, nbPts, i * nbPts, 0); } return subDivisor; } - fullMatrix<double> generateSubDivisorPyramid - (const fullMatrix<double> &exponents, - const std::vector< fullMatrix<double> > &subPoints, - const fullMatrix<double> &lag2Bez, bool pyr, int nij, int nk) + fullMatrix<double> + generateSubDivisorPyramid(const fullMatrix<double> &exponents, + const std::vector<fullMatrix<double> > &subPoints, + const fullMatrix<double> &lag2Bez, bool pyr, + int nij, int nk) { - if(exponents.size1() != lag2Bez.size1() || exponents.size1() != lag2Bez.size2()){ + if(exponents.size1() != lag2Bez.size1() || + exponents.size1() != lag2Bez.size2()) { Msg::Error("Wrong sizes for Bezier Divisor %d %d -- %d %d", - exponents.size1(), lag2Bez.size1(), - exponents.size1(), lag2Bez.size2()); + exponents.size1(), lag2Bez.size1(), exponents.size1(), + lag2Bez.size2()); return fullMatrix<double>(1, 1); } @@ -426,12 +427,11 @@ namespace { fullMatrix<double> intermediate2(nbPts, nbPts); fullMatrix<double> subDivisor(nbSubPts, nbPts); - for(unsigned int i = 0; i < subPoints.size(); i++){ + for(unsigned int i = 0; i < subPoints.size(); i++) { fullMatrix<double> intermediate1 = - generateBez2LagMatrixPyramid(exponents, subPoints[i], - pyr, nij, nk); + generateBez2LagMatrixPyramid(exponents, subPoints[i], pyr, nij, nk); lag2Bez.mult(intermediate1, intermediate2); - subDivisor.copy(intermediate2, 0, nbPts, 0, nbPts, i*nbPts, 0); + subDivisor.copy(intermediate2, 0, nbPts, 0, nbPts, i * nbPts, 0); } return subDivisor; } @@ -439,14 +439,14 @@ namespace { void double2int(const fullMatrix<double> &matDouble, fullMatrix<int> &matInt) { matInt.resize(matDouble.size1(), matDouble.size2()); - for(int i = 0; i < matDouble.size1(); ++i){ - for(int j = 0; j < matDouble.size2(); ++j){ + for(int i = 0; i < matDouble.size1(); ++i) { + for(int j = 0; j < matDouble.size2(); ++j) { matInt(i, j) = static_cast<int>(matDouble(i, j) + .5); } } } -} +} // namespace bezierBasis::bezierBasis(FuncSpaceData data) : _data(data), _raiser(NULL) { @@ -456,10 +456,7 @@ bezierBasis::bezierBasis(FuncSpaceData data) : _data(data), _raiser(NULL) _construct(); } -bezierBasis::~bezierBasis() -{ - delete _raiser; -} +bezierBasis::~bezierBasis() { delete _raiser; } void bezierBasis::f(double u, double v, double w, double *sf) const { @@ -469,9 +466,9 @@ void bezierBasis::f(double u, double v, double w, double *sf) const // TODO Amaury: change (u,v,w) fs->f(u, v, w, p); - for(int i = 0; i < matrixBez2Lag.size1(); i++){ + for(int i = 0; i < matrixBez2Lag.size1(); i++) { sf[i] = 0.0; - for(int j = 0; j < matrixBez2Lag.size2(); j++){ + for(int j = 0; j < matrixBez2Lag.size2(); j++) { sf[i] += matrixBez2Lag(j, i) * p[j]; } } @@ -480,11 +477,11 @@ void bezierBasis::f(double u, double v, double w, double *sf) const void bezierBasis::generateBezierPoints(fullMatrix<double> &points) const { gmshGenerateMonomials(_data, points); - points.scale(1./_data.spaceOrder()); - if(_data.elementType() == TYPE_PYR && _data.nk() < _data.spaceOrder()){ + points.scale(1. / _data.spaceOrder()); + if(_data.elementType() == TYPE_PYR && _data.nk() < _data.spaceOrder()) { fullMatrix<double> prox; prox.setAsProxy(points, 2, 1); - prox.add(1-static_cast<double>(_data.nk())/_data.spaceOrder()); + prox.add(1 - static_cast<double>(_data.nk()) / _data.spaceOrder()); } } @@ -493,8 +490,7 @@ void bezierBasis::_FEpoints2BezPoints(fullMatrix<double> &points) const fullMatrix<double> tmp; switch(_data.elementType()) { case TYPE_TRI: - case TYPE_TET: - break; + case TYPE_TET: break; case TYPE_LIN: tmp.setAsProxy(points, 0, 1); @@ -520,7 +516,7 @@ void bezierBasis::_FEpoints2BezPoints(fullMatrix<double> &points) const break; case TYPE_PYR: - for(int i = 0; i < points.size1(); ++i){ + for(int i = 0; i < points.size1(); ++i) { points(i, 2) = 1. - points(i, 2); points(i, 0) = .5 * (1 + points(i, 0) / points(i, 2)); points(i, 1) = .5 * (1 + points(i, 1) / points(i, 2)); @@ -529,15 +525,15 @@ void bezierBasis::_FEpoints2BezPoints(fullMatrix<double> &points) const default: Msg::Error("_FEpoints2BezPoints not implemented for " - "type of element %d", _data.elementType()); + "type of element %d", + _data.elementType()); return; } } void bezierBasis::interpolate(const fullMatrix<double> &coeffs, const fullMatrix<double> &uvw, - fullMatrix<double> &result, - bool bezCoord) const + fullMatrix<double> &result, bool bezCoord) const { if(result.size1() != uvw.size1() || result.size2() != coeffs.size2()) result.resize(uvw.size1(), coeffs.size2()); @@ -549,28 +545,27 @@ void bezierBasis::interpolate(const fullMatrix<double> &coeffs, const int dim = _exponents.size2(); int order[3]; - for(int m = 0; m < uvw.size1(); ++m){ + for(int m = 0; m < uvw.size1(); ++m) { for(int n = 0; n < coeffs.size2(); ++n) result(m, n) = 0; - for(int i = 0; i < numCoeff; i++){ - _data.getOrderForBezier(order, _exponents(i, dim-1)); + for(int i = 0; i < numCoeff; i++) { + _data.getOrderForBezier(order, _exponents(i, dim - 1)); double dd = 1; double pointCompl = 1.; int exponentCompl = order[0]; - for(int k = 0; k < _dimSimplex; k++){ - dd *= nChoosek(exponentCompl, (int) _exponents(i, k)) - * pow(bezuvw(m, k), _exponents(i, k)); + for(int k = 0; k < _dimSimplex; k++) { + dd *= nChoosek(exponentCompl, (int)_exponents(i, k)) * + pow(bezuvw(m, k), _exponents(i, k)); pointCompl -= bezuvw(m, k); - exponentCompl -= (int) _exponents(i, k); + exponentCompl -= (int)_exponents(i, k); } dd *= pow_int(pointCompl, exponentCompl); - for(int k = _dimSimplex; k < dim; k++){ - dd *= nChoosek(order[k], (int) _exponents(i, k)) - * pow_int(bezuvw(m, k), _exponents(i, k)) - * pow_int(1. - bezuvw(m, k), order[k] - _exponents(i, k)); + for(int k = _dimSimplex; k < dim; k++) { + dd *= nChoosek(order[k], (int)_exponents(i, k)) * + pow_int(bezuvw(m, k), _exponents(i, k)) * + pow_int(1. - bezuvw(m, k), order[k] - _exponents(i, k)); } - for(int n = 0; n < coeffs.size2(); ++n) - result(m, n) += coeffs(i, n) * dd; + for(int n = 0; n < coeffs.size2(); ++n) result(m, n) += coeffs(i, n) * dd; } } } @@ -578,11 +573,11 @@ void bezierBasis::interpolate(const fullMatrix<double> &coeffs, void bezierBasis::lag2Bez(const fullMatrix<double> &lag, fullMatrix<double> &bez) const { - if(lag.size1() != matrixLag2Bez.size1()){ + if(lag.size1() != matrixLag2Bez.size1()) { Msg::Error("matrix not the right size in lag2Bez function %d vs %d", lag.size1(), matrixLag2Bez.size1()); } - if(bez.size1() != lag.size1() || bez.size2() != lag.size2()){ + if(bez.size1() != lag.size1() || bez.size2() != lag.size2()) { bez.resize(lag.size1(), lag.size2()); } matrixLag2Bez.mult(lag, bez); @@ -591,8 +586,8 @@ void bezierBasis::lag2Bez(const fullMatrix<double> &lag, void bezierBasis::subdivideBezCoeff(const fullMatrix<double> &coeff, fullMatrix<double> &subCoeff) const { - if(subCoeff.size1() != subDivisor.size1() - || subCoeff.size2() != coeff.size2() ){ + if(subCoeff.size1() != subDivisor.size1() || + subCoeff.size2() != coeff.size2()) { subCoeff.resize(subDivisor.size1(), coeff.size2()); } subDivisor.mult(coeff, subCoeff); @@ -601,7 +596,7 @@ void bezierBasis::subdivideBezCoeff(const fullMatrix<double> &coeff, void bezierBasis::subdivideBezCoeff(const fullVector<double> &coeff, fullVector<double> &subCoeff) const { - if(subCoeff.size() != subDivisor.size1()){ + if(subCoeff.size() != subDivisor.size1()) { subCoeff.resize(subDivisor.size1()); } subDivisor.mult(coeff, subCoeff); @@ -609,74 +604,76 @@ void bezierBasis::subdivideBezCoeff(const fullVector<double> &coeff, void bezierBasis::_construct() { - if(_data.elementType() == TYPE_PYR){ + if(_data.elementType() == TYPE_PYR) { Msg::Error("This bezierBasis constructor is not for pyramids!"); return; } - std::vector< fullMatrix<double> > subPoints; + std::vector<fullMatrix<double> > subPoints; int order = _data.spaceOrder(); - switch(_data.elementType()){ - case TYPE_PNT : + switch(_data.elementType()) { + case TYPE_PNT: _numLagCoeff = 1; _dimSimplex = 0; _exponents = gmshGenerateMonomialsLine(0); subPoints.push_back(gmshGeneratePointsLine(0)); break; - case TYPE_LIN : + case TYPE_LIN: _numLagCoeff = order ? 2 : 1; _dimSimplex = 0; _exponents = gmshGenerateMonomialsLine(order); subPoints = generateSubPointsLine(order); break; - case TYPE_TRI : + case TYPE_TRI: _numLagCoeff = order ? 3 : 1; _dimSimplex = 2; _exponents = gmshGenerateMonomialsTriangle(order); subPoints = generateSubPointsTriangle(order); break; - case TYPE_QUA : + case TYPE_QUA: _numLagCoeff = order ? 4 : 1; _dimSimplex = 0; _exponents = gmshGenerateMonomialsQuadrangle(order); subPoints = generateSubPointsQuad(order); break; - case TYPE_TET : + case TYPE_TET: _numLagCoeff = order ? 4 : 1; _dimSimplex = 3; _exponents = gmshGenerateMonomialsTetrahedron(order); subPoints = generateSubPointsTetrahedron(order); break; - case TYPE_PRI : + case TYPE_PRI: _numLagCoeff = order ? 6 : 1; _dimSimplex = 2; _exponents = gmshGenerateMonomialsPrism(order); subPoints = generateSubPointsPrism(order); break; - case TYPE_HEX : + case TYPE_HEX: _numLagCoeff = order ? 8 : 1; _dimSimplex = 0; _exponents = gmshGenerateMonomialsHexahedron(order); subPoints = generateSubPointsHex(order); break; - default : + default: Msg::Error("Unknown function space for parentType %d", _data.elementType()); return; } _numDivisions = static_cast<int>(subPoints.size()); fullMatrix<double> bezierPoints = _exponents; - if(order) bezierPoints.scale(1./order); + if(order) bezierPoints.scale(1. / order); - matrixBez2Lag = generateBez2LagMatrix(_exponents, bezierPoints, order, _dimSimplex); + matrixBez2Lag = + generateBez2LagMatrix(_exponents, bezierPoints, order, _dimSimplex); matrixBez2Lag.invert(matrixLag2Bez); - subDivisor = generateSubDivisor(_exponents, subPoints, matrixLag2Bez, order, _dimSimplex); + subDivisor = generateSubDivisor(_exponents, subPoints, matrixLag2Bez, order, + _dimSimplex); } void bezierBasis::_constructPyr() { - if(_data.elementType() != TYPE_PYR){ + if(_data.elementType() != TYPE_PYR) { Msg::Error("This bezierBasis constructor is for pyramids!"); } @@ -689,14 +686,14 @@ void bezierBasis::_constructPyr() fullMatrix<double> bezierPoints; generateBezierPoints(bezierPoints); - matrixBez2Lag = generateBez2LagMatrixPyramid(_exponents, bezierPoints, - pyr, nij, nk); + matrixBez2Lag = + generateBez2LagMatrixPyramid(_exponents, bezierPoints, pyr, nij, nk); matrixBez2Lag.invert(matrixLag2Bez); - if(pyr){ + if(pyr) { _numDivisions = 0; } else { - std::vector< fullMatrix<double> > subPoints; + std::vector<fullMatrix<double> > subPoints; subPoints = generateSubPointsPyr(nij, nk); _numDivisions = static_cast<int>(subPoints.size()); subDivisor = generateSubDivisorPyramid(_exponents, subPoints, matrixLag2Bez, @@ -704,15 +701,15 @@ void bezierBasis::_constructPyr() } } -bezierBasisRaiser* bezierBasis::getRaiser() const +bezierBasisRaiser *bezierBasis::getRaiser() const { - if(!_raiser){ - const_cast<bezierBasis*>(this)->_raiser = new bezierBasisRaiser(this); + if(!_raiser) { + const_cast<bezierBasis *>(this)->_raiser = new bezierBasisRaiser(this); } return _raiser; } -//const bezierBasis* bezierBasisRaiser::getRaisedBezierBasis(int raised) const +// const bezierBasis* bezierBasisRaiser::getRaisedBezierBasis(int raised) const //{ // if(raised != 2 && raised != 3){ // Msg::Error("Why would you want other than 2 or 3?"); @@ -730,7 +727,7 @@ bezierBasisRaiser* bezierBasis::getRaiser() const void bezierBasisRaiser::_fillRaiserData() { - if(_bfs->getType() == TYPE_PYR){ + if(_bfs->getType() == TYPE_PYR) { _fillRaiserDataPyr(); return; } @@ -753,40 +750,38 @@ void bezierBasisRaiser::_fillRaiserData() fullMatrix<int> exp2; { fullMatrix<double> expD2; - FuncSpaceData dataRaiser2(_bfs->_data, 2*order); + FuncSpaceData dataRaiser2(_bfs->_data, 2 * order); gmshGenerateMonomials(dataRaiser2, expD2); double2int(expD2, exp2); _raiser2.resize(exp2.size1()); } std::map<int, int> hashToInd2; - for(int i = 0; i < exp2.size1(); ++i){ + for(int i = 0; i < exp2.size1(); ++i) { int hash = 0; - for(int l = 0; l < dim; l++){ - hash += exp2(i, l) * pow_int(2*order+1, l); + for(int l = 0; l < dim; l++) { + hash += exp2(i, l) * pow_int(2 * order + 1, l); } hashToInd2[hash] = i; } - for(int i = 0; i < ncoeff; i++){ - for(int j = i; j < ncoeff; j++){ + for(int i = 0; i < ncoeff; i++) { + for(int j = i; j < ncoeff; j++) { double num = 1, den = 1; { int compl1 = order; int compl2 = order; - int compltot = 2*order; - for(int l = 0; l < dimSimplex; l++){ - num *= nChoosek(compl1, exp(i, l)) * - nChoosek(compl2, exp(j, l)); + int compltot = 2 * order; + for(int l = 0; l < dimSimplex; l++) { + num *= nChoosek(compl1, exp(i, l)) * nChoosek(compl2, exp(j, l)); den *= nChoosek(compltot, exp(i, l) + exp(j, l)); compl1 -= exp(i, l); compl2 -= exp(j, l); compltot -= exp(i, l) + exp(j, l); } - for(int l = dimSimplex; l < dim; l++){ - num *= nChoosek(order, exp(i, l)) * - nChoosek(order, exp(j, l)); - den *= nChoosek(2*order, exp(i, l) + exp(j, l)); + for(int l = dimSimplex; l < dim; l++) { + num *= nChoosek(order, exp(i, l)) * nChoosek(order, exp(j, l)); + den *= nChoosek(2 * order, exp(i, l) + exp(j, l)); } } @@ -794,10 +789,10 @@ void bezierBasisRaiser::_fillRaiserData() if(i < j) num *= 2; int hash = 0; - for(int l = 0; l < dim; l++){ - hash += (exp(i, l)+exp(j, l)) * pow_int(2*order+1, l); + for(int l = 0; l < dim; l++) { + hash += (exp(i, l) + exp(j, l)) * pow_int(2 * order + 1, l); } - _raiser2[hashToInd2[hash]].push_back(_Data(num/den, i, j)); + _raiser2[hashToInd2[hash]].push_back(_Data(num / den, i, j)); } } @@ -805,57 +800,58 @@ void bezierBasisRaiser::_fillRaiserData() fullMatrix<int> exp3; { fullMatrix<double> expD3; - FuncSpaceData dataRaiser3(_bfs->_data, 3*order); + FuncSpaceData dataRaiser3(_bfs->_data, 3 * order); gmshGenerateMonomials(dataRaiser3, expD3); double2int(expD3, exp3); _raiser3.resize(exp3.size1()); } std::map<int, int> hashToInd3; - for(int i = 0; i < exp3.size1(); ++i){ + for(int i = 0; i < exp3.size1(); ++i) { int hash = 0; - for(int l = 0; l < dim; l++){ - hash += exp3(i, l) * pow_int(3*order+1, l); + for(int l = 0; l < dim; l++) { + hash += exp3(i, l) * pow_int(3 * order + 1, l); } hashToInd3[hash] = i; } - for(int i = 0; i < ncoeff; i++){ - for(int j = i; j < ncoeff; j++){ - for(int k = j; k < ncoeff; ++k){ + for(int i = 0; i < ncoeff; i++) { + for(int j = i; j < ncoeff; j++) { + for(int k = j; k < ncoeff; ++k) { double num = 1, den = 1; { int compl1 = order; int compl2 = order; int compl3 = order; - int compltot = 3*order; - for(int l = 0; l < dimSimplex; l++){ - num *= nChoosek(compl1, exp(i, l)) * - nChoosek(compl2, exp(j, l)) * - nChoosek(compl3, exp(k, l)); + int compltot = 3 * order; + for(int l = 0; l < dimSimplex; l++) { + num *= nChoosek(compl1, exp(i, l)) * nChoosek(compl2, exp(j, l)) * + nChoosek(compl3, exp(k, l)); den *= nChoosek(compltot, exp(i, l) + exp(j, l) + exp(k, l)); compl1 -= exp(i, l); compl2 -= exp(j, l); compl3 -= exp(k, l); compltot -= exp(i, l) + exp(j, l) + exp(k, l); } - for(int l = dimSimplex; l < dim; l++){ - num *= nChoosek(order, exp(i, l)) * - nChoosek(order, exp(j, l)) * - nChoosek(order, exp(k, l)); - den *= nChoosek(3*order, exp(i, l) + exp(j, l) + exp(k, l)); + for(int l = dimSimplex; l < dim; l++) { + num *= nChoosek(order, exp(i, l)) * nChoosek(order, exp(j, l)) * + nChoosek(order, exp(k, l)); + den *= nChoosek(3 * order, exp(i, l) + exp(j, l) + exp(k, l)); } } // taking into account the multiplicity (Reminder: i <= j <= k) - if(i < j && j < k) num *= 6; - else if(i < j || j < k) num *= 3; + if(i < j && j < k) + num *= 6; + else if(i < j || j < k) + num *= 3; int hash = 0; - for(int l = 0; l < dim; l++){ - hash += (exp(i, l)+exp(j, l)+exp(k, l)) * pow_int(3*order+1, l); + for(int l = 0; l < dim; l++) { + hash += + (exp(i, l) + exp(j, l) + exp(k, l)) * pow_int(3 * order + 1, l); } - _raiser3[hashToInd3[hash]].push_back(_Data(num/den, i, j, k)); + _raiser3[hashToInd3[hash]].push_back(_Data(num / den, i, j, k)); } } } @@ -864,11 +860,11 @@ void bezierBasisRaiser::_fillRaiserData() void bezierBasisRaiser::_fillRaiserDataPyr() { FuncSpaceData fsdata = _bfs->getFuncSpaceData(); - if(fsdata.elementType() != TYPE_PYR){ + if(fsdata.elementType() != TYPE_PYR) { _fillRaiserData(); return; } - if(fsdata.isPyramidalSpace()){ + if(fsdata.isPyramidalSpace()) { Msg::Error("Bezier raiser not implemented for pyramidal space"); return; } @@ -890,38 +886,37 @@ void bezierBasisRaiser::_fillRaiserDataPyr() fullMatrix<int> exp2; { fullMatrix<double> expD2; - FuncSpaceData dataRaiser2(_bfs->_data, 2*order[0], 2*order[2]); + FuncSpaceData dataRaiser2(_bfs->_data, 2 * order[0], 2 * order[2]); gmshGenerateMonomials(dataRaiser2, expD2); double2int(expD2, exp2); _raiser2.resize(exp2.size1()); } std::map<int, int> hashToInd2; - for(int i = 0; i < exp2.size1(); ++i){ + for(int i = 0; i < exp2.size1(); ++i) { int hash = 0; - for(int l = 0; l < 3; l++){ - hash += exp2(i, l) * pow_int(2*orderHash+1, l); + for(int l = 0; l < 3; l++) { + hash += exp2(i, l) * pow_int(2 * orderHash + 1, l); } hashToInd2[hash] = i; } - for(int i = 0; i < ncoeff; i++){ - for(int j = i; j < ncoeff; j++){ + for(int i = 0; i < ncoeff; i++) { + for(int j = i; j < ncoeff; j++) { double num = 1, den = 1; - for(int l = 0; l < 3; l++){ - num *= nChoosek(order[l], exp(i, l)) - * nChoosek(order[l], exp(j, l)); - den *= nChoosek(2*order[l], exp(i, l) + exp(j, l)); + for(int l = 0; l < 3; l++) { + num *= nChoosek(order[l], exp(i, l)) * nChoosek(order[l], exp(j, l)); + den *= nChoosek(2 * order[l], exp(i, l) + exp(j, l)); } // taking into account the multiplicity (reminder: i <= j) if(i < j) num *= 2; int hash = 0; - for(int l = 0; l < 3; l++){ - hash += (exp(i, l)+exp(j, l)) * pow_int(2*orderHash+1, l); + for(int l = 0; l < 3; l++) { + hash += (exp(i, l) + exp(j, l)) * pow_int(2 * orderHash + 1, l); } - _raiser2[hashToInd2[hash]].push_back(_Data(num/den, i, j)); + _raiser2[hashToInd2[hash]].push_back(_Data(num / den, i, j)); } } @@ -929,41 +924,43 @@ void bezierBasisRaiser::_fillRaiserDataPyr() fullMatrix<int> exp3; { fullMatrix<double> expD3; - FuncSpaceData dataRaiser3(_bfs->_data, 3*order[0], 3*order[2]); + FuncSpaceData dataRaiser3(_bfs->_data, 3 * order[0], 3 * order[2]); gmshGenerateMonomials(dataRaiser3, expD3); double2int(expD3, exp3); _raiser3.resize(exp3.size1()); } std::map<int, int> hashToInd3; - for(int i = 0; i < exp3.size1(); ++i){ + for(int i = 0; i < exp3.size1(); ++i) { int hash = 0; - for(int l = 0; l < 3; l++){ - hash += exp3(i, l) * pow_int(3*orderHash+1, l); + for(int l = 0; l < 3; l++) { + hash += exp3(i, l) * pow_int(3 * orderHash + 1, l); } hashToInd3[hash] = i; } - for(int i = 0; i < ncoeff; i++){ - for(int j = i; j < ncoeff; j++){ - for(int k = j; k < ncoeff; ++k){ + for(int i = 0; i < ncoeff; i++) { + for(int j = i; j < ncoeff; j++) { + for(int k = j; k < ncoeff; ++k) { double num = 1, den = 1; - for(int l = 0; l < 3; l++){ - num *= nChoosek(order[l], exp(i, l)) - * nChoosek(order[l], exp(j, l)) - * nChoosek(order[l], exp(k, l)); - den *= nChoosek(3*order[l], exp(i, l) + exp(j, l) + exp(k, l)); + for(int l = 0; l < 3; l++) { + num *= nChoosek(order[l], exp(i, l)) * nChoosek(order[l], exp(j, l)) * + nChoosek(order[l], exp(k, l)); + den *= nChoosek(3 * order[l], exp(i, l) + exp(j, l) + exp(k, l)); } // taking into account the multiplicity (Reminder: i <= j <= k) - if(i < j && j < k) num *= 6; - else if(i < j || j < k) num *= 3; + if(i < j && j < k) + num *= 6; + else if(i < j || j < k) + num *= 3; int hash = 0; - for(int l = 0; l < 3; l++){ - hash += (exp(i, l)+exp(j, l)+exp(k, l)) * pow_int(3*orderHash+1, l); + for(int l = 0; l < 3; l++) { + hash += + (exp(i, l) + exp(j, l) + exp(k, l)) * pow_int(3 * orderHash + 1, l); } - _raiser3[hashToInd3[hash]].push_back(_Data(num/den, i, j, k)); + _raiser3[hashToInd3[hash]].push_back(_Data(num / den, i, j, k)); } } } @@ -975,20 +972,20 @@ void bezierBasisRaiser::computeCoeff(const fullVector<double> &coeffA, { coeffSquare.resize(_raiser2.size(), true); - if(&coeffA == &coeffB){ - for(unsigned int ind = 0; ind < _raiser2.size(); ++ind){ - for(unsigned int l = 0; l < _raiser2[ind].size(); ++l){ + if(&coeffA == &coeffB) { + for(unsigned int ind = 0; ind < _raiser2.size(); ++ind) { + for(unsigned int l = 0; l < _raiser2[ind].size(); ++l) { _Data &d = _raiser2[ind][l]; coeffSquare(ind) += d.val * coeffA(d.i) * coeffB(d.j); } } } else { - for(unsigned int ind = 0; ind < _raiser2.size(); ++ind){ - for(unsigned int l = 0; l < _raiser2[ind].size(); ++l){ + for(unsigned int ind = 0; ind < _raiser2.size(); ++ind) { + for(unsigned int l = 0; l < _raiser2[ind].size(); ++l) { _Data &d = _raiser2[ind][l]; - coeffSquare(ind) += d.val/2 * (coeffA(d.i) * coeffB(d.j) + - coeffA(d.j) * coeffB(d.i)); + coeffSquare(ind) += + d.val / 2 * (coeffA(d.i) * coeffB(d.j) + coeffA(d.j) * coeffB(d.i)); } } } @@ -1001,30 +998,32 @@ void bezierBasisRaiser::computeCoeff(const fullVector<double> &coeffA, { coeffCubic.resize(_raiser3.size(), true); - if(&coeffA == &coeffB && &coeffB == &coeffC){ - for(unsigned int ind = 0; ind < _raiser3.size(); ++ind){ - for(unsigned int l = 0; l < _raiser3[ind].size(); ++l){ + if(&coeffA == &coeffB && &coeffB == &coeffC) { + for(unsigned int ind = 0; ind < _raiser3.size(); ++ind) { + for(unsigned int l = 0; l < _raiser3[ind].size(); ++l) { _Data &d = _raiser3[ind][l]; coeffCubic(ind) += d.val * coeffA(d.i) * coeffB(d.j) * coeffC(d.k); } } } - else if(&coeffA != &coeffB && &coeffB != &coeffC){ - for(unsigned int ind = 0; ind < _raiser3.size(); ++ind){ - for(unsigned int l = 0; l < _raiser3[ind].size(); ++l){ + else if(&coeffA != &coeffB && &coeffB != &coeffC) { + for(unsigned int ind = 0; ind < _raiser3.size(); ++ind) { + for(unsigned int l = 0; l < _raiser3[ind].size(); ++l) { _Data &d = _raiser3[ind][l]; - coeffCubic(ind) += d.val/6 * (coeffA(d.i) * coeffB(d.j) * coeffC(d.k) + - coeffA(d.i) * coeffB(d.k) * coeffC(d.j) + - coeffA(d.j) * coeffB(d.i) * coeffC(d.k) + - coeffA(d.j) * coeffB(d.k) * coeffC(d.i) + - coeffA(d.k) * coeffB(d.i) * coeffC(d.j) + - coeffA(d.k) * coeffB(d.j) * coeffC(d.i)); + coeffCubic(ind) += d.val / 6 * + (coeffA(d.i) * coeffB(d.j) * coeffC(d.k) + + coeffA(d.i) * coeffB(d.k) * coeffC(d.j) + + coeffA(d.j) * coeffB(d.i) * coeffC(d.k) + + coeffA(d.j) * coeffB(d.k) * coeffC(d.i) + + coeffA(d.k) * coeffB(d.i) * coeffC(d.j) + + coeffA(d.k) * coeffB(d.j) * coeffC(d.i)); } } } else - Msg::Error("bezierBasisRaiser::computeCoeff not implemented for A == B != C " - "or A != B == C"); + Msg::Error( + "bezierBasisRaiser::computeCoeff not implemented for A == B != C " + "or A != B == C"); } void bezierBasisRaiser::computeCoeff(const fullMatrix<double> &coeffA, @@ -1033,26 +1032,26 @@ void bezierBasisRaiser::computeCoeff(const fullMatrix<double> &coeffA, { coeffSquare.resize(_raiser2.size(), coeffA.size2(), true); - if(&coeffA == &coeffB){ - for(unsigned int ind = 0; ind < _raiser2.size(); ++ind){ - for(unsigned int l = 0; l < _raiser2[ind].size(); ++l){ + if(&coeffA == &coeffB) { + for(unsigned int ind = 0; ind < _raiser2.size(); ++ind) { + for(unsigned int l = 0; l < _raiser2[ind].size(); ++l) { _Data &d = _raiser2[ind][l]; - for(int ind2 = 0; ind2 < coeffA.size2(); ++ind2){ - coeffSquare(ind, ind2) += d.val * coeffA(d.i, ind2) - * coeffB(d.j, ind2); + for(int ind2 = 0; ind2 < coeffA.size2(); ++ind2) { + coeffSquare(ind, ind2) += + d.val * coeffA(d.i, ind2) * coeffB(d.j, ind2); } } } } else { - for(unsigned int ind = 0; ind < _raiser2.size(); ++ind){ - for(unsigned int l = 0; l < _raiser2[ind].size(); ++l){ + for(unsigned int ind = 0; ind < _raiser2.size(); ++ind) { + for(unsigned int l = 0; l < _raiser2[ind].size(); ++l) { _Data &d = _raiser2[ind][l]; - double val = d.val/2; - for(int ind2 = 0; ind2 < coeffA.size2(); ++ind2){ - coeffSquare(ind, ind2) += val * - (coeffA(d.i, ind2) * coeffB(d.j, ind2) + - coeffA(d.j, ind2) * coeffB(d.i, ind2)); + double val = d.val / 2; + for(int ind2 = 0; ind2 < coeffA.size2(); ++ind2) { + coeffSquare(ind, ind2) += + val * (coeffA(d.i, ind2) * coeffB(d.j, ind2) + + coeffA(d.j, ind2) * coeffB(d.i, ind2)); } } } @@ -1066,33 +1065,33 @@ void bezierBasisRaiser::computeCoeff(const fullVector<double> &coeffA, { coeffCubic.resize(_raiser3.size(), coeffB.size2(), true); - if(&coeffB == &coeffC){ - for(unsigned int ind = 0; ind < _raiser3.size(); ++ind){ - for(unsigned int l = 0; l < _raiser3[ind].size(); ++l){ + if(&coeffB == &coeffC) { + for(unsigned int ind = 0; ind < _raiser3.size(); ++ind) { + for(unsigned int l = 0; l < _raiser3[ind].size(); ++l) { _Data &d = _raiser3[ind][l]; - double val = d.val/3; - for(int ind2 = 0; ind2 < coeffB.size2(); ++ind2){ - coeffCubic(ind, ind2) += val * - (coeffA(d.i) * coeffB(d.j, ind2) * coeffC(d.k, ind2) + - coeffA(d.j) * coeffB(d.i, ind2) * coeffC(d.k, ind2) + - coeffA(d.k) * coeffB(d.i, ind2) * coeffC(d.j, ind2)); + double val = d.val / 3; + for(int ind2 = 0; ind2 < coeffB.size2(); ++ind2) { + coeffCubic(ind, ind2) += + val * (coeffA(d.i) * coeffB(d.j, ind2) * coeffC(d.k, ind2) + + coeffA(d.j) * coeffB(d.i, ind2) * coeffC(d.k, ind2) + + coeffA(d.k) * coeffB(d.i, ind2) * coeffC(d.j, ind2)); } } } } else { - for(unsigned int ind = 0; ind < _raiser3.size(); ++ind){ - for(unsigned int l = 0; l < _raiser3[ind].size(); ++l){ + for(unsigned int ind = 0; ind < _raiser3.size(); ++ind) { + for(unsigned int l = 0; l < _raiser3[ind].size(); ++l) { _Data &d = _raiser3[ind][l]; - double val = d.val/6; - for(int ind2 = 0; ind2 < coeffB.size2(); ++ind2){ - coeffCubic(ind, ind2) += val * - (coeffA(d.i) * coeffB(d.j, ind2) * coeffC(d.k, ind2) + - coeffA(d.i) * coeffB(d.k, ind2) * coeffC(d.j, ind2) + - coeffA(d.j) * coeffB(d.i, ind2) * coeffC(d.k, ind2) + - coeffA(d.j) * coeffB(d.k, ind2) * coeffC(d.i, ind2) + - coeffA(d.k) * coeffB(d.i, ind2) * coeffC(d.j, ind2) + - coeffA(d.k) * coeffB(d.j, ind2) * coeffC(d.i, ind2)); + double val = d.val / 6; + for(int ind2 = 0; ind2 < coeffB.size2(); ++ind2) { + coeffCubic(ind, ind2) += + val * (coeffA(d.i) * coeffB(d.j, ind2) * coeffC(d.k, ind2) + + coeffA(d.i) * coeffB(d.k, ind2) * coeffC(d.j, ind2) + + coeffA(d.j) * coeffB(d.i, ind2) * coeffC(d.k, ind2) + + coeffA(d.j) * coeffB(d.k, ind2) * coeffC(d.i, ind2) + + coeffA(d.k) * coeffB(d.i, ind2) * coeffC(d.j, ind2) + + coeffA(d.k) * coeffB(d.j, ind2) * coeffC(d.i, ind2)); } } } diff --git a/Numeric/bezierBasis.h b/Numeric/bezierBasis.h index a7864381dd5897dc1ac2f7f6cdd7a739384235ed..0cc9b2127903f69cadf6cdce0ff8187d05eeef78 100644 --- a/Numeric/bezierBasis.h +++ b/Numeric/bezierBasis.h @@ -14,7 +14,7 @@ class MElement; class bezierBasisRaiser; class bezierBasis { - private : +private: // the 'numLagCoeff' first exponents are related to 'real' values int _numLagCoeff; int _numDivisions, _dimSimplex; @@ -24,7 +24,7 @@ class bezierBasis { friend class bezierBasisRaiser; fullMatrix<double> _exponents; - public : +public: fullMatrix<double> matrixLag2Bez; fullMatrix<double> matrixBez2Lag; fullMatrix<double> subDivisor; @@ -34,21 +34,21 @@ class bezierBasis { ~bezierBasis(); // get methods - inline int getDim() const {return _exponents.size2();} - inline int getType() const {return _data.elementType();} - inline int getOrder() const {return _data.spaceOrder();} - inline int getDimSimplex() const {return _dimSimplex;} - inline int getNumLagCoeff() const {return _numLagCoeff;} - inline int getNumDivision() const {return _numDivisions;} - inline int getNumSubNodes() const {return subDivisor.size1();} - inline FuncSpaceData getFuncSpaceData() const {return _data;} - bezierBasisRaiser* getRaiser() const; + inline int getDim() const { return _exponents.size2(); } + inline int getType() const { return _data.elementType(); } + inline int getOrder() const { return _data.spaceOrder(); } + inline int getDimSimplex() const { return _dimSimplex; } + inline int getNumLagCoeff() const { return _numLagCoeff; } + inline int getNumDivision() const { return _numDivisions; } + inline int getNumSubNodes() const { return subDivisor.size1(); } + inline FuncSpaceData getFuncSpaceData() const { return _data; } + bezierBasisRaiser *getRaiser() const; // Evaluate Bezier functions at the point (u, v, w) void f(double u, double v, double w, double *sf) const; // generate Bezier points - void generateBezierPoints(fullMatrix<double>&) const; + void generateBezierPoints(fullMatrix<double> &) const; // transform coeff Lagrange into Bezier coeff void lag2Bez(const fullMatrix<double> &lag, fullMatrix<double> &bez) const; @@ -63,43 +63,46 @@ class bezierBasis { // coeffs(numCoeff, n) and uvw(N, dim) // => result(N, n) void interpolate(const fullMatrix<double> &coeffs, - const fullMatrix<double> &uvw, - fullMatrix<double> &result, + const fullMatrix<double> &uvw, fullMatrix<double> &result, bool bezCoord = false) const; void interpolate(const fullVector<double> &coeffs, - const fullMatrix<double> &uvw, - fullVector<double> &result, - bool bezCoord = false) const { + const fullMatrix<double> &uvw, fullVector<double> &result, + bool bezCoord = false) const + { int size = uvw.size1(); result.resize(size); - fullMatrix<double> c(const_cast<double*>(coeffs.getDataPtr()), size, 1); - fullMatrix<double> r(const_cast<double*>(result.getDataPtr()), size, 1); + fullMatrix<double> c(const_cast<double *>(coeffs.getDataPtr()), size, 1); + fullMatrix<double> r(const_cast<double *>(result.getDataPtr()), size, 1); interpolate(c, uvw, r, bezCoord); } - private : +private: void _construct(); void _constructPyr(); - void _FEpoints2BezPoints(fullMatrix<double>&) const; + void _FEpoints2BezPoints(fullMatrix<double> &) const; }; class bezierBasisRaiser { // Let f, g, h be three function whose Bezier coefficients are given. // This class allows to compute the Bezier coefficients of f*g and f*g*h. - private : +private: class _Data { friend class bezierBasisRaiser; - private: + + private: int i, j, k; double val; - public: - _Data(double vv, int ii, int jj = -1, int kk = -1) : - i(ii), j(jj), k(kk), val(vv) {} + + public: + _Data(double vv, int ii, int jj = -1, int kk = -1) + : i(ii), j(jj), k(kk), val(vv) + { + } }; std::vector<std::vector<_Data> > _raiser2, _raiser3; const bezierBasis *_bfs; - public: +public: bezierBasisRaiser(const bezierBasis *bezier) : _bfs(bezier) { _fillRaiserData(); @@ -119,7 +122,8 @@ class bezierBasisRaiser { const fullMatrix<double> &coeffB, const fullMatrix<double> &coeffC, fullMatrix<double> &coeffCubic); - private: + +private: void _fillRaiserData(); void _fillRaiserDataPyr(); }; diff --git a/Numeric/cartesian.h b/Numeric/cartesian.h index e88e63f4d858e7687cbf9595371588b9d0b61de3..13d1ebefa236ba420cf1ba03d1a87bf410544a86 100644 --- a/Numeric/cartesian.h +++ b/Numeric/cartesian.h @@ -30,9 +30,8 @@ // referenced by a linear index (i + N * j) // // The (i,j) cell has nodes (i,j), (i+1,j), (i+1,j+1) and (i,j+1) -template <class scalar> -class cartesianBox { - private: +template <class scalar> class cartesianBox { +private: // number of subdivisions along the xi-, eta- and zeta-axis int _Nxi, _Neta, _Nzeta; // origin of the grid and spacing along xi, eta and zeta @@ -62,8 +61,8 @@ class cartesianBox { } void _printNodes(FILE *f) { - for (valIter it = _nodalValues.begin(); it != _nodalValues.end(); ++it){ - if(it->second.second > 0){ + for(valIter it = _nodalValues.begin(); it != _nodalValues.end(); ++it) { + if(it->second.second > 0) { SPoint3 p = getNodeCoordinates(it->first); fprintf(f, "%d %g %g %g\n", it->second.second, p.x(), p.y(), p.z()); } @@ -77,13 +76,13 @@ class cartesianBox { if(_childBox) n += _childBox->_getNumElements(simplex); return n; } - void _printElements(FILE *f, bool simplex, int startingNum=1) + void _printElements(FILE *f, bool simplex, int startingNum = 1) { int num = startingNum; - for(cellIter it = _activeCells.begin(); it != _activeCells.end(); ++it){ + for(cellIter it = _activeCells.begin(); it != _activeCells.end(); ++it) { int i, j, k; getCellIJK(*it, i, j, k); - if(!simplex){ + if(!simplex) { fprintf(f, "%d 5 3 1 1 1 %d %d %d %d %d %d %d %d\n", num++, std::abs(getNodeTag(getNodeIndex(i, j, k))), std::abs(getNodeTag(getNodeIndex(i + 1, j, k))), @@ -94,25 +93,25 @@ class cartesianBox { std::abs(getNodeTag(getNodeIndex(i + 1, j + 1, k + 1))), std::abs(getNodeTag(getNodeIndex(i, j + 1, k + 1)))); } - else{ + else { int idx[6][4] = { - {getNodeIndex(i, j + 1, k), getNodeIndex(i, j + 1, k + 1), + {getNodeIndex(i, j + 1, k), getNodeIndex(i, j + 1, k + 1), getNodeIndex(i + 1, j, k + 1), getNodeIndex(i + 1, j + 1, k + 1)}, - {getNodeIndex(i, j + 1, k), getNodeIndex(i + 1, j + 1, k + 1), + {getNodeIndex(i, j + 1, k), getNodeIndex(i + 1, j + 1, k + 1), getNodeIndex(i + 1, j, k + 1), getNodeIndex(i + 1, j + 1, k)}, - {getNodeIndex(i, j + 1, k), getNodeIndex(i, j, k + 1), + {getNodeIndex(i, j + 1, k), getNodeIndex(i, j, k + 1), getNodeIndex(i + 1, j, k + 1), getNodeIndex(i, j + 1, k + 1)}, - {getNodeIndex(i, j + 1, k), getNodeIndex(i + 1, j + 1, k), + {getNodeIndex(i, j + 1, k), getNodeIndex(i + 1, j + 1, k), getNodeIndex(i + 1, j, k + 1), getNodeIndex(i + 1, j, k)}, - {getNodeIndex(i, j + 1, k), getNodeIndex(i + 1, j, k), + {getNodeIndex(i, j + 1, k), getNodeIndex(i + 1, j, k), getNodeIndex(i + 1, j, k + 1), getNodeIndex(i, j, k)}, - {getNodeIndex(i, j + 1, k), getNodeIndex(i, j, k), - getNodeIndex(i + 1, j, k + 1), getNodeIndex(i, j, k + 1)} - }; - for(int ii = 0; ii < 6; ii++){ - fprintf(f, "%d 4 3 1 1 1 %d %d %d %d\n", num++, - std::abs(getNodeTag(idx[ii][0])), std::abs(getNodeTag(idx[ii][1])), - std::abs(getNodeTag(idx[ii][2])), std::abs(getNodeTag(idx[ii][3]))); + {getNodeIndex(i, j + 1, k), getNodeIndex(i, j, k), + getNodeIndex(i + 1, j, k + 1), getNodeIndex(i, j, k + 1)}}; + for(int ii = 0; ii < 6; ii++) { + fprintf( + f, "%d 4 3 1 1 1 %d %d %d %d\n", num++, + std::abs(getNodeTag(idx[ii][0])), std::abs(getNodeTag(idx[ii][1])), + std::abs(getNodeTag(idx[ii][2])), std::abs(getNodeTag(idx[ii][3]))); } } } @@ -120,66 +119,63 @@ class cartesianBox { } void _printValues(FILE *f) { - for(valIter it = _nodalValues.begin(); it != _nodalValues.end(); ++it){ + for(valIter it = _nodalValues.begin(); it != _nodalValues.end(); ++it) { if(it->second.second > 0) fprintf(f, "%d %g\n", it->second.second, it->second.first); } if(_childBox) _childBox->_printValues(f); } - public: - cartesianBox(double X0, double Y0, double Z0, - const SVector3 &dxi, const SVector3 &deta, const SVector3 &dzeta, - int Nxi, int Neta, int Nzeta, int level=1) - : _Nxi(Nxi), _Neta(Neta), _Nzeta(Nzeta), - _X0(X0), _Y0(Y0), _Z0(Z0), - _dxi(norm(dxi)), _deta(norm(deta)), _dzeta(norm(dzeta)), - _xiAxis(dxi), _etaAxis(deta), _zetaAxis(dzeta), - _level(level), _childBox(0) + +public: + cartesianBox(double X0, double Y0, double Z0, const SVector3 &dxi, + const SVector3 &deta, const SVector3 &dzeta, int Nxi, int Neta, + int Nzeta, int level = 1) + : _Nxi(Nxi), _Neta(Neta), _Nzeta(Nzeta), _X0(X0), _Y0(Y0), _Z0(Z0), + _dxi(norm(dxi)), _deta(norm(deta)), _dzeta(norm(dzeta)), _xiAxis(dxi), + _etaAxis(deta), _zetaAxis(dzeta), _level(level), _childBox(0) { _xiAxis.normalize(); _etaAxis.normalize(); _zetaAxis.normalize(); if(level > 1) - _childBox = new cartesianBox<scalar>(X0, Y0, Z0, dxi, deta, dzeta, - 2 * Nxi, 2 * Neta, 2 * Nzeta, - level - 1); + _childBox = new cartesianBox<scalar>( + X0, Y0, Z0, dxi, deta, dzeta, 2 * Nxi, 2 * Neta, 2 * Nzeta, level - 1); } - double getLC(){ return sqrt(_dxi * _dxi + _deta * _deta + _dzeta * _dzeta); } - int getNxi(){ return _Nxi; } - int getNeta(){ return _Neta; } - int getNzeta(){ return _Nzeta; } - cartesianBox<scalar> *getChildBox(){ return _childBox; } - int getLevel(){ return _level; } + double getLC() { return sqrt(_dxi * _dxi + _deta * _deta + _dzeta * _dzeta); } + int getNxi() { return _Nxi; } + int getNeta() { return _Neta; } + int getNzeta() { return _Nzeta; } + cartesianBox<scalar> *getChildBox() { return _childBox; } + int getLevel() { return _level; } typedef std::set<int>::const_iterator cellIter; - cellIter activeCellsBegin(){ return _activeCells.begin(); } - cellIter activeCellsEnd(){ return _activeCells.end(); } + cellIter activeCellsBegin() { return _activeCells.begin(); } + cellIter activeCellsEnd() { return _activeCells.end(); } typedef typename std::map<int, std::pair<scalar, int> >::iterator valIter; - valIter nodalValuesBegin(){ return _nodalValues.begin(); } - valIter nodalValuesEnd(){ return _nodalValues.end(); } - void setNodalValue(int i, scalar s){ _nodalValues[i].first = s; } + valIter nodalValuesBegin() { return _nodalValues.begin(); } + valIter nodalValuesEnd() { return _nodalValues.end(); } + void setNodalValue(int i, scalar s) { _nodalValues[i].first = s; } void getNodalValuesForCell(int t, std::vector<scalar> &values) { int i, j, k; getCellIJK(t, i, j, k); for(int I = 0; I < 2; I++) for(int J = 0; J < 2; J++) - for(int K = 0; K < 2; K++){ + for(int K = 0; K < 2; K++) { valIter it = _nodalValues.find(getNodeIndex(i + I, j + J, k + K)); if(it != _nodalValues.end()) values.push_back(it->second.first); - else{ - Msg::Error("Could not find value i,j,k=%d,%d,%d for cell %d", - i + I, j + J, k + K, t); + else { + Msg::Error("Could not find value i,j,k=%d,%d,%d for cell %d", i + I, + j + J, k + K, t); values.push_back(0.); } } } double getValueContainingPoint(double x, double y, double z) { + SVector3 DP(x - _X0, y - _Y0, z - _Z0); - SVector3 DP (x - _X0, y - _Y0, z - _Z0); - - int t = getCellContainingPoint(x, y,z); + int t = getCellContainingPoint(x, y, z); int i, j, k; getCellIJK(t, i, j, k); @@ -192,25 +188,33 @@ class cartesianBox { valIter it7 = _nodalValues.find(getNodeIndex(i + 1, j + 1, k + 1)); valIter it8 = _nodalValues.find(getNodeIndex(i, j + 1, k + 1)); - if(it1 == _nodalValues.end()) return _childBox->getValueContainingPoint(x,y,z); - if(it2 == _nodalValues.end()) return _childBox->getValueContainingPoint(x,y,z); - if(it3 == _nodalValues.end()) return _childBox->getValueContainingPoint(x,y,z); - if(it4 == _nodalValues.end()) return _childBox->getValueContainingPoint(x,y,z); - if(it5 == _nodalValues.end()) return _childBox->getValueContainingPoint(x,y,z); - if(it6 == _nodalValues.end()) return _childBox->getValueContainingPoint(x,y,z); - if(it7 == _nodalValues.end()) return _childBox->getValueContainingPoint(x,y,z); - if(it8 == _nodalValues.end()) return _childBox->getValueContainingPoint(x,y,z); + if(it1 == _nodalValues.end()) + return _childBox->getValueContainingPoint(x, y, z); + if(it2 == _nodalValues.end()) + return _childBox->getValueContainingPoint(x, y, z); + if(it3 == _nodalValues.end()) + return _childBox->getValueContainingPoint(x, y, z); + if(it4 == _nodalValues.end()) + return _childBox->getValueContainingPoint(x, y, z); + if(it5 == _nodalValues.end()) + return _childBox->getValueContainingPoint(x, y, z); + if(it6 == _nodalValues.end()) + return _childBox->getValueContainingPoint(x, y, z); + if(it7 == _nodalValues.end()) + return _childBox->getValueContainingPoint(x, y, z); + if(it8 == _nodalValues.end()) + return _childBox->getValueContainingPoint(x, y, z); double vals[8]; - vals[0] = it1->second.first; - vals[1] = it2->second.first; - vals[2] = it3->second.first; - vals[3] = it4->second.first; - vals[4] = it5->second.first; - vals[5] = it6->second.first; - vals[6] = it7->second.first; - vals[7] = it8->second.first; - //for (int i= 0; i< 8; i++) printf("vals %d = %g \n", i, vals[i]); + vals[0] = it1->second.first; + vals[1] = it2->second.first; + vals[2] = it3->second.first; + vals[3] = it4->second.first; + vals[4] = it5->second.first; + vals[5] = it6->second.first; + vals[6] = it7->second.first; + vals[7] = it8->second.first; + // for (int i= 0; i< 8; i++) printf("vals %d = %g \n", i, vals[i]); SPoint3 p1 = getNodeCoordinates(it1->first); SPoint3 p2 = getNodeCoordinates(it2->first); @@ -232,9 +236,9 @@ class cartesianBox { MHexahedron *newElem = new MHexahedron(v1, v2, v3, v4, v5, v6, v7, v8); double uvw[3]; - double xyz[3] = {x,y,z}; + double xyz[3] = {x, y, z}; newElem->xyz2uvw(xyz, uvw); - //printf("uvw =%g %g %g \n", uvw[0],uvw[1],uvw[2]); + // printf("uvw =%g %g %g \n", uvw[0],uvw[1],uvw[2]); double val = newElem->interpolate(vals, uvw[0], uvw[1], uvw[2]); delete newElem; @@ -253,16 +257,19 @@ class cartesianBox { { // P = P_0 + xi * _vdx + eta * _vdy + zeta *vdz // DP = P-P_0 * _vdx = xi - SVector3 DP (x - _X0, y - _Y0, z - _Z0); + SVector3 DP(x - _X0, y - _Y0, z - _Z0); double xi = dot(DP, _xiAxis); double eta = dot(DP, _etaAxis); double zeta = dot(DP, _zetaAxis); int i = xi / _dxi * _Nxi; int j = eta / _deta * _Neta; int k = zeta / _dzeta * _Nzeta; - if (i < 0) i = 0; if (i >= _Nxi) i = _Nxi - 1; - if (j < 0) j = 0; if (j >= _Neta) j = _Neta - 1; - if (k < 0) k = 0; if (k >= _Nzeta) k = _Nzeta - 1; + if(i < 0) i = 0; + if(i >= _Nxi) i = _Nxi - 1; + if(j < 0) j = 0; + if(j >= _Neta) j = _Neta - 1; + if(k < 0) k = 0; + if(k >= _Nzeta) k = _Nzeta - 1; return getCellIndex(i, j, k); } SPoint3 getNodeCoordinates(int t) const @@ -275,25 +282,27 @@ class cartesianBox { SVector3 D = xi * _xiAxis + eta * _etaAxis + zeta * _zetaAxis; return SPoint3(_X0 + D.x(), _Y0 + D.y(), _Z0 + D.z()); } - void insertActiveCell(int t){ _activeCells.insert(t); } - void eraseActiveCell(int t){ _activeCells.erase(t); } + void insertActiveCell(int t) { _activeCells.insert(t); } + void eraseActiveCell(int t) { _activeCells.erase(t); } bool activeCellExists(int t) { return (_activeCells.find(t) != _activeCells.end()); } int getCellIndex(int i, int j, int k) const { - return i + _Nxi * j + _Nxi *_Neta * k; + return i + _Nxi * j + _Nxi * _Neta * k; } int getNodeIndex(int i, int j, int k) const { - return i + (_Nxi+1) * j + (_Nxi+1) * (_Neta+1) * k; + return i + (_Nxi + 1) * j + (_Nxi + 1) * (_Neta + 1) * k; } int getNodeTag(int index) { valIter it = _nodalValues.find(index); - if(it != _nodalValues.end()) return it->second.second; - else return 0; + if(it != _nodalValues.end()) + return it->second.second; + else + return 0; } void getCellIJK(int index, int &i, int &j, int &k) const { @@ -309,27 +318,27 @@ class cartesianBox { } void createNodalValues() { - for(cellIter it = _activeCells.begin(); it != _activeCells.end(); ++it){ + for(cellIter it = _activeCells.begin(); it != _activeCells.end(); ++it) { const int &t = *it; int i, j, k; getCellIJK(t, i, j, k); - for (int I = 0; I < 2; I++) - for (int J = 0; J < 2; J++) - for (int K = 0; K < 2; K++) + for(int I = 0; I < 2; I++) + for(int J = 0; J < 2; J++) + for(int K = 0; K < 2; K++) _nodalValues[getNodeIndex(i + I, j + J, k + K)] = std::pair<scalar, int>(0., 0); } if(_childBox) _childBox->createNodalValues(); } - void renumberNodes(int startingNum=1, cartesianBox<scalar> *parent=0) + void renumberNodes(int startingNum = 1, cartesianBox<scalar> *parent = 0) { int num = startingNum; - for(valIter it = _nodalValues.begin(); it != _nodalValues.end(); it++){ + for(valIter it = _nodalValues.begin(); it != _nodalValues.end(); it++) { int i, j, k; getNodeIJK(it->first, i, j, k); if(!parent || i % 2 || j % 2 || k % 2) it->second.second = num++; - else{ + else { int tag = parent->getNodeTag(parent->getNodeIndex(i / 2, j / 2, k / 2)); if(!tag) // FIXME! not sure why this can happen, but it does (bug?) it->second.second = num++; @@ -339,11 +348,11 @@ class cartesianBox { } if(_childBox) _childBox->renumberNodes(num, this); } - void writeMSH(const std::string &fileName, bool simplex=false, - bool writeNodalValues=true) + void writeMSH(const std::string &fileName, bool simplex = false, + bool writeNodalValues = true) { FILE *f = fopen(fileName.c_str(), "w"); - if(!f){ + if(!f) { Msg::Error("Could not open file '%s'", fileName.c_str()); return; } @@ -354,11 +363,11 @@ class cartesianBox { fprintf(f, "$Nodes\n%d\n", numNodes); _printNodes(f); fprintf(f, "$EndNodes\n"); - fprintf(f,"$Elements\n%d\n", numElements); + fprintf(f, "$Elements\n%d\n", numElements); _printElements(f, simplex); - fprintf(f,"$EndElements\n"); - if(writeNodalValues){ - fprintf(f,"$NodeData\n1\n\"distance\"\n1\n0.0\n3\n0\n1\n%d\n", numNodes); + fprintf(f, "$EndElements\n"); + if(writeNodalValues) { + fprintf(f, "$NodeData\n1\n\"distance\"\n1\n0.0\n3\n0\n1\n%d\n", numNodes); _printValues(f); fprintf(f, "$EndNodeData\n"); } diff --git a/Numeric/decasteljau.cpp b/Numeric/decasteljau.cpp index e5b2337390f2344275f517aec74f819e287478ed..bb2123516a7cb194cf1e4308802e2c03916d84b9 100644 --- a/Numeric/decasteljau.cpp +++ b/Numeric/decasteljau.cpp @@ -27,19 +27,21 @@ static int sortedPointInsert(const SPoint3 &p, const double t, } static void sortedPointToVector(const std::vector<sortedPoint> &spts, - std::vector<SPoint3> &pts, std::vector<double> &ts) + std::vector<SPoint3> &pts, + std::vector<double> &ts) { pts.clear(); pts.reserve(spts.size()); ts.clear(); ts.reserve(spts.size()); - for (int p = 0; p != -1; p = spts[p].next) { + for(int p = 0; p != -1; p = spts[p].next) { pts.push_back(spts[p].p); ts.push_back(spts[p].t); } } -double sqDistPointSegment(const SPoint3 &p, const SPoint3 &s0, const SPoint3 &s1) +double sqDistPointSegment(const SPoint3 &p, const SPoint3 &s0, + const SPoint3 &s1) { SVector3 d(s1 - s0); SVector3 d0(p - s0); @@ -54,8 +56,7 @@ static void decasteljau(double tol, std::vector<sortedPoint> &discrete, int pos, const SPoint3 &p0, const SPoint3 &p1, const SPoint3 &p2, double t0, double t2) { - if(sqDistPointSegment(p1, p0, p2) < tol * tol) - return; + if(sqDistPointSegment(p1, p0, p2) < tol * tol) return; SPoint3 p01((p0 + p1) * 0.5); SPoint3 p12((p1 + p2) * 0.5); SPoint3 p012((p01 + p12) * 0.5); @@ -65,8 +66,9 @@ static void decasteljau(double tol, std::vector<sortedPoint> &discrete, int pos, decasteljau(tol, discrete, newpos, p012, p12, p2, t012, t2); } -void decasteljau(double tol, const SPoint3 &p0, const SPoint3 &p1, const SPoint3 &p2, - std::vector<SPoint3> &pts, std::vector<double> &ts) +void decasteljau(double tol, const SPoint3 &p0, const SPoint3 &p1, + const SPoint3 &p2, std::vector<SPoint3> &pts, + std::vector<double> &ts) { std::vector<sortedPoint> discrete; sortedPoint pnt1 = {p0, 0., 1}; @@ -77,11 +79,12 @@ void decasteljau(double tol, const SPoint3 &p0, const SPoint3 &p1, const SPoint3 sortedPointToVector(discrete, pts, ts); } -static void decasteljau(double tol, std::vector<sortedPoint> &discrete, - int pos, const SPoint3 &p0, const SPoint3 &p1, - const SPoint3 &p2, const SPoint3 &p3, double t0, double t3) +static void decasteljau(double tol, std::vector<sortedPoint> &discrete, int pos, + const SPoint3 &p0, const SPoint3 &p1, const SPoint3 &p2, + const SPoint3 &p3, double t0, double t3) { - if (std::max(sqDistPointSegment(p1, p0, p3), sqDistPointSegment(p2, p0, p3)) < tol * tol) + if(std::max(sqDistPointSegment(p1, p0, p3), sqDistPointSegment(p2, p0, p3)) < + tol * tol) return; SPoint3 p01((p0 + p1) * 0.5); SPoint3 p12((p1 + p2) * 0.5); @@ -95,8 +98,9 @@ static void decasteljau(double tol, std::vector<sortedPoint> &discrete, decasteljau(tol, discrete, newpos, p0123, p123, p23, p3, t0123, t3); } -void decasteljau(double tol, const SPoint3 &p0, const SPoint3 &p1, const SPoint3 &p2, - const SPoint3 &p3, std::vector<SPoint3> &pts, std::vector<double> &ts) +void decasteljau(double tol, const SPoint3 &p0, const SPoint3 &p1, + const SPoint3 &p2, const SPoint3 &p3, + std::vector<SPoint3> &pts, std::vector<double> &ts) { std::vector<sortedPoint> discrete; sortedPoint pnt1 = {p0, 0., 1}; @@ -112,16 +116,14 @@ static void decasteljau(double tol, std::vector<sortedPoint> &discrete, int pos, { int order = (int)pts.size() - 1; double dmax2 = 0; - for (int i = 1; i < order ; ++i) + for(int i = 1; i < order; ++i) dmax2 = std::max(dmax2, sqDistPointSegment(pts[i], pts[0], pts[order])); - if(dmax2 < tol * tol) - return; + if(dmax2 < tol * tol) return; std::vector<SPoint3> sub0(pts.size()); std::vector<SPoint3> sub1(pts); - for (int l = 0; l < order + 1; ++l) { + for(int l = 0; l < order + 1; ++l) { sub0[l] = sub1[0]; - for (int i = 0; i < order - l; ++i) - sub1[i] = (sub1[i] + sub1[i + 1]) * 0.5; + for(int i = 0; i < order - l; ++i) sub1[i] = (sub1[i] + sub1[i + 1]) * 0.5; } double tmid = 0.5 * (t0 + te); int newpos = sortedPointInsert(sub1[0], tmid, discrete, pos); diff --git a/Numeric/decasteljau.h b/Numeric/decasteljau.h index 4dfa70168813ecebba8fa8a99891394dd08383c9..195476dd5b0114c9f1e1d928f5ad23e36630997c 100644 --- a/Numeric/decasteljau.h +++ b/Numeric/decasteljau.h @@ -14,8 +14,8 @@ void decasteljau(double tol, const SPoint3 &p0, const SPoint3 &p1, const SPoint3 &p2, std::vector<SPoint3> &pts, std::vector<double> &ts); void decasteljau(double tol, const SPoint3 &p0, const SPoint3 &p1, - const SPoint3 &p2, const SPoint3 &p3, std::vector<SPoint3> &pts, - std::vector<double> &ts); + const SPoint3 &p2, const SPoint3 &p3, + std::vector<SPoint3> &pts, std::vector<double> &ts); void decasteljau(double tol, const std::vector<SPoint3> &controlPoints, std::vector<SPoint3> &pts, std::vector<double> &ts); diff --git a/Numeric/discreteFrechetDistance.cpp b/Numeric/discreteFrechetDistance.cpp index 21a5663e9b5f2f7b6f36530529c4697210e54ddb..487efcdc599dc7a4aa537c677df80d9e2fd2d753 100644 --- a/Numeric/discreteFrechetDistance.cpp +++ b/Numeric/discreteFrechetDistance.cpp @@ -7,50 +7,51 @@ #include "discreteFrechetDistance.h" #include "fullMatrix.h" -static double distance (const SPoint3 &p1, const SPoint3 &p2) +static double distance(const SPoint3 &p1, const SPoint3 &p2) { return p1.distance(p2); } -static double c(int i, int j, - fullMatrix<double> &CA, - const std::vector<SPoint3> &P, - const std::vector<SPoint3> &Q) +static double c(int i, int j, fullMatrix<double> &CA, + const std::vector<SPoint3> &P, const std::vector<SPoint3> &Q) { double CAij; - if (CA(i,j)>-1){ - CAij = CA(i,j); + if(CA(i, j) > -1) { + CAij = CA(i, j); } - else if (i==0 && j==0){ - CA(i,j) = distance(P[0],Q[0]); // update the CA permanent - CAij = CA(i,j); // set the current relevant value + else if(i == 0 && j == 0) { + CA(i, j) = distance(P[0], Q[0]); // update the CA permanent + CAij = CA(i, j); // set the current relevant value } - else if (i>0 && j==0){ - CA(i,j) = std::max(c(i-1,0,CA,P,Q), distance(P[i],Q[1]) ); - CAij = CA(i,j); + else if(i > 0 && j == 0) { + CA(i, j) = std::max(c(i - 1, 0, CA, P, Q), distance(P[i], Q[1])); + CAij = CA(i, j); } - else if (i==0 && j>0){ - CA(i,j) = std::max( c(0,j-1,CA,P,Q), distance(P[0],Q[j]) ); - CAij = CA(i,j); + else if(i == 0 && j > 0) { + CA(i, j) = std::max(c(0, j - 1, CA, P, Q), distance(P[0], Q[j])); + CAij = CA(i, j); } - else if (i>0 && j>0){ - double temp = std::min(std::min(c(i-1,j,CA,P,Q),c(i-1,j-1,CA,P,Q)),c(i,j-1,CA,P,Q)); - CA(i,j) = std::max(temp,distance(P[i],Q[j])); - CAij = CA(i,j); + else if(i > 0 && j > 0) { + double temp = + std::min(std::min(c(i - 1, j, CA, P, Q), c(i - 1, j - 1, CA, P, Q)), + c(i, j - 1, CA, P, Q)); + CA(i, j) = std::max(temp, distance(P[i], Q[j])); + CAij = CA(i, j); } - else{ - CA(i,j) = 1.e22; - CAij = CA(i,j); + else { + CA(i, j) = 1.e22; + CAij = CA(i, j); } return CAij; } -double discreteFrechetDistance (const std::vector<SPoint3> &P, - const std::vector<SPoint3> &Q){ +double discreteFrechetDistance(const std::vector<SPoint3> &P, + const std::vector<SPoint3> &Q) +{ const int sP = P.size(); const int sQ = Q.size(); - fullMatrix<double> CA (sP,sQ); + fullMatrix<double> CA(sP, sQ); CA.setAll(-1.0); - double cm = c(sP-1,sQ-1,CA,P,Q); + double cm = c(sP - 1, sQ - 1, CA, P, Q); return cm; } diff --git a/Numeric/discreteFrechetDistance.h b/Numeric/discreteFrechetDistance.h index 9f2e233b49e7d6d21c4dde89f65e80a0380e17c8..0c87f879717f806bc7396ecb68db3436634a5b54 100644 --- a/Numeric/discreteFrechetDistance.h +++ b/Numeric/discreteFrechetDistance.h @@ -9,7 +9,7 @@ #include <vector> #include "SPoint3.h" -double discreteFrechetDistance (const std::vector<SPoint3> &P, - const std::vector<SPoint3> &Q); +double discreteFrechetDistance(const std::vector<SPoint3> &P, + const std::vector<SPoint3> &Q); #endif diff --git a/Numeric/fullMatrix.cpp b/Numeric/fullMatrix.cpp index ecf855dc2f4b15aec4f78e06dee813b6b028d598..317c887cafd2c0d876cb3a8fb9f86b95d732c940 100644 --- a/Numeric/fullMatrix.cpp +++ b/Numeric/fullMatrix.cpp @@ -22,249 +22,257 @@ #if defined(HAVE_BLAS) extern "C" { - void F77NAME(daxpy)(int *n, double *alpha, double *x, int *incx, double *y, int *incy); - void F77NAME(zaxpy)(int *n, std::complex<double> *alpha, std::complex<double> *x, int *incx, std::complex<double> *y, int *incy); - void F77NAME(dcopy)(int *n, double *a, int *inca, double *b, int *incb); - void F77NAME(zcopy)(int *n, std::complex<double> *a, int *inca, std::complex<double> *b, int *incb); - void F77NAME(dgemm)(const char *transa, const char *transb, int *m, int *n, int *k, - double *alpha, double *a, int *lda, - double *b, int *ldb, double *beta, - double *c, int *ldc); - void F77NAME(zgemm)(const char *transa, const char *transb, int *m, int *n, int *k, - std::complex<double> *alpha, std::complex<double> *a, int *lda, - std::complex<double> *b, int *ldb, std::complex<double> *beta, - std::complex<double> *c, int *ldc); - void F77NAME(dgemv)(const char *trans, int *m, int *n, - double *alpha, double *a, int *lda, - double *x, int *incx, double *beta, - double *y, int *incy); - void F77NAME(zgemv)(const char *trans, int *m, int *n, - std::complex<double> *alpha, std::complex<double> *a, int *lda, - std::complex<double> *x, int *incx, std::complex<double> *beta, - std::complex<double> *y, int *incy); - void F77NAME(dscal)(int *n, double *alpha,double *x, int *incx); - void F77NAME(zscal)(int *n, std::complex<double> *alpha,std::complex<double> *x, int *incx); -} - -template<> -void fullVector<double>::axpy(const fullVector<double> &x,double alpha) +void F77NAME(daxpy)(int *n, double *alpha, double *x, int *incx, double *y, + int *incy); +void F77NAME(zaxpy)(int *n, std::complex<double> *alpha, + std::complex<double> *x, int *incx, std::complex<double> *y, + int *incy); +void F77NAME(dcopy)(int *n, double *a, int *inca, double *b, int *incb); +void F77NAME(zcopy)(int *n, std::complex<double> *a, int *inca, + std::complex<double> *b, int *incb); +void F77NAME(dgemm)(const char *transa, const char *transb, int *m, int *n, + int *k, double *alpha, double *a, int *lda, double *b, + int *ldb, double *beta, double *c, int *ldc); +void F77NAME(zgemm)(const char *transa, const char *transb, int *m, int *n, + int *k, std::complex<double> *alpha, + std::complex<double> *a, int *lda, std::complex<double> *b, + int *ldb, std::complex<double> *beta, + std::complex<double> *c, int *ldc); +void F77NAME(dgemv)(const char *trans, int *m, int *n, double *alpha, double *a, + int *lda, double *x, int *incx, double *beta, double *y, + int *incy); +void F77NAME(zgemv)(const char *trans, int *m, int *n, + std::complex<double> *alpha, std::complex<double> *a, + int *lda, std::complex<double> *x, int *incx, + std::complex<double> *beta, std::complex<double> *y, + int *incy); +void F77NAME(dscal)(int *n, double *alpha, double *x, int *incx); +void F77NAME(zscal)(int *n, std::complex<double> *alpha, + std::complex<double> *x, int *incx); +} + +template <> +void fullVector<double>::axpy(const fullVector<double> &x, double alpha) { int M = _r, INCX = 1, INCY = 1; - F77NAME(daxpy)(&M, &alpha, x._data,&INCX, _data, &INCY); + F77NAME(daxpy)(&M, &alpha, x._data, &INCX, _data, &INCY); } -template<> -void fullVector<std::complex<double> >::axpy(const fullVector<std::complex<double> > &x, - std::complex<double> alpha) +template <> +void fullVector<std::complex<double> >::axpy( + const fullVector<std::complex<double> > &x, std::complex<double> alpha) { int M = _r, INCX = 1, INCY = 1; - F77NAME(zaxpy)(&M, &alpha, x._data,&INCX, _data, &INCY); + F77NAME(zaxpy)(&M, &alpha, x._data, &INCX, _data, &INCY); } -template<> -void fullVector<double>::setAll(const fullVector<double> &m) +template <> void fullVector<double>::setAll(const fullVector<double> &m) { int stride = 1; F77NAME(dcopy)(&_r, m._data, &stride, _data, &stride); } -template<> -void fullVector<std::complex<double> >::setAll(const fullVector<std::complex<double> > &m) +template <> +void fullVector<std::complex<double> >::setAll( + const fullVector<std::complex<double> > &m) { int stride = 1; F77NAME(zcopy)(&_r, m._data, &stride, _data, &stride); } -template<> -void fullMatrix<int>::setAll(const fullMatrix<int> &m) +template <> void fullMatrix<int>::setAll(const fullMatrix<int> &m) { - if (_r != m._r || _c != m._c ) - Msg::Fatal("fullMatrix size does not match"); + if(_r != m._r || _c != m._c) Msg::Fatal("fullMatrix size does not match"); int N = _r * _c; - for (int i = 0; i < N; ++i) - _data[i] = m._data[i]; + for(int i = 0; i < N; ++i) _data[i] = m._data[i]; } -template<> -void fullMatrix<double>::setAll(const fullMatrix<double> &m) +template <> void fullMatrix<double>::setAll(const fullMatrix<double> &m) { - if (_r != m._r || _c != m._c ) - Msg::Fatal("fullMatrix size does not match"); + if(_r != m._r || _c != m._c) Msg::Fatal("fullMatrix size does not match"); int N = _r * _c; int stride = 1; F77NAME(dcopy)(&N, m._data, &stride, _data, &stride); } -template<> -void fullMatrix<std::complex<double> >::setAll(const fullMatrix<std::complex<double > > &m) +template <> +void fullMatrix<std::complex<double> >::setAll( + const fullMatrix<std::complex<double> > &m) { - if (_r != m._r || _c != m._c ) - Msg::Fatal("fullMatrix size does not match"); + if(_r != m._r || _c != m._c) Msg::Fatal("fullMatrix size does not match"); int N = _r * _c; int stride = 1; F77NAME(zcopy)(&N, m._data, &stride, _data, &stride); } -template<> -void fullMatrix<double>::scale(const double s) +template <> void fullMatrix<double>::scale(const double s) { int N = _r * _c; int stride = 1; double ss = s; - F77NAME(dscal)(&N, &ss,_data, &stride); + F77NAME(dscal)(&N, &ss, _data, &stride); } -template<> -void fullMatrix<std::complex<double> >::scale(const double s) +template <> void fullMatrix<std::complex<double> >::scale(const double s) { int N = _r * _c; int stride = 1; std::complex<double> ss(s, 0.); - F77NAME(zscal)(&N, &ss,_data, &stride); + F77NAME(zscal)(&N, &ss, _data, &stride); } -template<> -void fullMatrix<double>::mult(const fullMatrix<double> &b, fullMatrix<double> &c) const +template <> +void fullMatrix<double>::mult(const fullMatrix<double> &b, + fullMatrix<double> &c) const { int M = c.size1(), N = c.size2(), K = _c; int LDA = _r, LDB = b.size1(), LDC = c.size1(); double alpha = 1., beta = 0.; - F77NAME(dgemm)("N", "N", &M, &N, &K, &alpha, _data, &LDA, b._data, &LDB, - &beta, c._data, &LDC); + F77NAME(dgemm) + ("N", "N", &M, &N, &K, &alpha, _data, &LDA, b._data, &LDB, &beta, c._data, + &LDC); } -template<> -void fullMatrix<std::complex<double> >::mult(const fullMatrix<std::complex<double> > &b, - fullMatrix<std::complex<double> > &c) const +template <> +void fullMatrix<std::complex<double> >::mult( + const fullMatrix<std::complex<double> > &b, + fullMatrix<std::complex<double> > &c) const { int M = c.size1(), N = c.size2(), K = _c; int LDA = _r, LDB = b.size1(), LDC = c.size1(); std::complex<double> alpha = 1., beta = 0.; - F77NAME(zgemm)("N", "N", &M, &N, &K, &alpha, _data, &LDA, b._data, &LDB, - &beta, c._data, &LDC); + F77NAME(zgemm) + ("N", "N", &M, &N, &K, &alpha, _data, &LDA, b._data, &LDB, &beta, c._data, + &LDC); } -template<> -void fullMatrix<double>::gemm(const fullMatrix<double> &a, const fullMatrix<double> &b, - double alpha, double beta, bool transposeA, bool transposeB) +template <> +void fullMatrix<double>::gemm(const fullMatrix<double> &a, + const fullMatrix<double> &b, double alpha, + double beta, bool transposeA, bool transposeB) { int M = size1(), N = size2(), K = transposeA ? a.size1() : a.size2(); int LDA = a.size1(), LDB = b.size1(), LDC = size1(); - F77NAME(dgemm)(transposeA ? "T" : "N", transposeB ? "T" :"N", &M, &N, &K, &alpha, a._data, &LDA, b._data, &LDB, - &beta, _data, &LDC); + F77NAME(dgemm) + (transposeA ? "T" : "N", transposeB ? "T" : "N", &M, &N, &K, &alpha, a._data, + &LDA, b._data, &LDB, &beta, _data, &LDC); } -template<> -void fullMatrix<std::complex<double> >::gemm(const fullMatrix<std::complex<double> > &a, - const fullMatrix<std::complex<double> > &b, - std::complex<double> alpha, - std::complex<double> beta, - bool transposeA, - bool transposeB) +template <> +void fullMatrix<std::complex<double> >::gemm( + const fullMatrix<std::complex<double> > &a, + const fullMatrix<std::complex<double> > &b, std::complex<double> alpha, + std::complex<double> beta, bool transposeA, bool transposeB) { - int M = size1(), N = size2(), K = transposeA ? a.size1() : a.size2(); + int M = size1(), N = size2(), K = transposeA ? a.size1() : a.size2(); int LDA = a.size1(), LDB = b.size1(), LDC = size1(); - F77NAME(zgemm)(transposeA ? "T" : "N", transposeB ? "T" :"N", &M, &N, &K, &alpha, a._data, &LDA, b._data, &LDB, - &beta, _data, &LDC); + F77NAME(zgemm) + (transposeA ? "T" : "N", transposeB ? "T" : "N", &M, &N, &K, &alpha, a._data, + &LDA, b._data, &LDB, &beta, _data, &LDC); } -template<> -void fullMatrix<double>::axpy(const fullMatrix<double> &x,double alpha) +template <> +void fullMatrix<double>::axpy(const fullMatrix<double> &x, double alpha) { int M = _r * _c, INCX = 1, INCY = 1; - F77NAME(daxpy)(&M, &alpha, x._data,&INCX, _data, &INCY); + F77NAME(daxpy)(&M, &alpha, x._data, &INCX, _data, &INCY); } -template<> -void fullMatrix<double>::mult(const fullVector<double> &x, fullVector<double> &y) const +template <> +void fullMatrix<double>::mult(const fullVector<double> &x, + fullVector<double> &y) const { int M = _r, N = _c, LDA = _r, INCX = 1, INCY = 1; double alpha = 1., beta = 0.; - F77NAME(dgemv)("N", &M, &N, &alpha, _data, &LDA, x._data, &INCX, - &beta, y._data, &INCY); + F77NAME(dgemv) + ("N", &M, &N, &alpha, _data, &LDA, x._data, &INCX, &beta, y._data, &INCY); } -template<> -void fullMatrix<double>::multAddy(const fullVector<double> &x, fullVector<double> &y) const +template <> +void fullMatrix<double>::multAddy(const fullVector<double> &x, + fullVector<double> &y) const { int M = _r, N = _c, LDA = _r, INCX = 1, INCY = 1; double alpha = 1., beta = 1.; - F77NAME(dgemv)("N", &M, &N, &alpha, _data, &LDA, x._data, &INCX, - &beta, y._data, &INCY); + F77NAME(dgemv) + ("N", &M, &N, &alpha, _data, &LDA, x._data, &INCX, &beta, y._data, &INCY); } -template<> -void fullMatrix<std::complex<double> >::mult(const fullVector<std::complex<double> > &x, - fullVector<std::complex<double> > &y) const +template <> +void fullMatrix<std::complex<double> >::mult( + const fullVector<std::complex<double> > &x, + fullVector<std::complex<double> > &y) const { int M = _r, N = _c, LDA = _r, INCX = 1, INCY = 1; std::complex<double> alpha = 1., beta = 0.; - F77NAME(zgemv)("N", &M, &N, &alpha, _data, &LDA, x._data, &INCX, - &beta, y._data, &INCY); + F77NAME(zgemv) + ("N", &M, &N, &alpha, _data, &LDA, x._data, &INCX, &beta, y._data, &INCY); } -template<> -void fullMatrix<std::complex<double> >::multAddy(const fullVector<std::complex<double> > &x, - fullVector<std::complex<double> > &y) const +template <> +void fullMatrix<std::complex<double> >::multAddy( + const fullVector<std::complex<double> > &x, + fullVector<std::complex<double> > &y) const { int M = _r, N = _c, LDA = _r, INCX = 1, INCY = 1; std::complex<double> alpha = 1., beta = 1.; - F77NAME(zgemv)("N", &M, &N, &alpha, _data, &LDA, x._data, &INCX, - &beta, y._data, &INCY); + F77NAME(zgemv) + ("N", &M, &N, &alpha, _data, &LDA, x._data, &INCX, &beta, y._data, &INCY); } - -template<> -void fullMatrix<double>::multOnBlock(const fullMatrix<double> &b, const int ncol, const int fcol, const int alpha_, const int beta_, fullVector<double> &c) const +template <> +void fullMatrix<double>::multOnBlock(const fullMatrix<double> &b, + const int ncol, const int fcol, + const int alpha_, const int beta_, + fullVector<double> &c) const { - int M = 1, N = ncol, K = b.size1() ; + int M = 1, N = ncol, K = b.size1(); int LDA = _r, LDB = b.size1(), LDC = 1; double alpha = alpha_, beta = beta_; - F77NAME(dgemm)("N", "N", &M, &N, &K, &alpha, _data, &LDA, &(b._data[fcol*K]), &LDB, - &beta, &(c._data[fcol]), &LDC); + F77NAME(dgemm) + ("N", "N", &M, &N, &K, &alpha, _data, &LDA, &(b._data[fcol * K]), &LDB, &beta, + &(c._data[fcol]), &LDC); } -template<> -void fullMatrix<double>::multWithATranspose(const fullVector<double> &x, double alpha, double beta,fullVector<double> &y) const +template <> +void fullMatrix<double>::multWithATranspose(const fullVector<double> &x, + double alpha, double beta, + fullVector<double> &y) const { int M = _r, N = _c, LDA = _r, INCX = 1, INCY = 1; - F77NAME(dgemv)("T", &M, &N, &alpha, _data, &LDA, x._data, &INCX, - &beta, y._data, &INCY); - + F77NAME(dgemv) + ("T", &M, &N, &alpha, _data, &LDA, x._data, &INCX, &beta, y._data, &INCY); } - -template<> -void fullMatrix<int>::scale(const double s) +template <> void fullMatrix<int>::scale(const double s) { for(int i = 0; i < _r * _c; ++i) _data[i] *= s; } #endif - - #if defined(HAVE_LAPACK) extern "C" { - void F77NAME(dgesv)(int *N, int *nrhs, double *A, int *lda, int *ipiv, - double *b, int *ldb, int *info); - void F77NAME(dgetrf)(int *M, int *N, double *A, int *lda, int *ipiv, int *info); - void F77NAME(dgetrs)(char *trans, int *N, int *nrhs, double *A, int *lda, int *ipiv, - double *b, int *ldb, int *info); - void F77NAME(dgetri)(int *M, double *A, int *lda, int *ipiv, double *work, - int *lwork, int *info); - void F77NAME(dgesvd)(const char* jobu, const char *jobvt, int *M, int *N, - double *A, int *lda, double *S, double* U, int *ldu, - double *VT, int *ldvt, double *work, int *lwork, int *info); - void F77NAME(dgeev)(const char *jobvl, const char *jobvr, int *n, double *a, - int *lda, double *wr, double *wi, double *vl, int *ldvl, - double *vr, int *ldvr, double *work, int *lwork, int *info); +void F77NAME(dgesv)(int *N, int *nrhs, double *A, int *lda, int *ipiv, + double *b, int *ldb, int *info); +void F77NAME(dgetrf)(int *M, int *N, double *A, int *lda, int *ipiv, int *info); +void F77NAME(dgetrs)(char *trans, int *N, int *nrhs, double *A, int *lda, + int *ipiv, double *b, int *ldb, int *info); +void F77NAME(dgetri)(int *M, double *A, int *lda, int *ipiv, double *work, + int *lwork, int *info); +void F77NAME(dgesvd)(const char *jobu, const char *jobvt, int *M, int *N, + double *A, int *lda, double *S, double *U, int *ldu, + double *VT, int *ldvt, double *work, int *lwork, + int *info); +void F77NAME(dgeev)(const char *jobvl, const char *jobvr, int *n, double *a, + int *lda, double *wr, double *wi, double *vl, int *ldvl, + double *vr, int *ldvr, double *work, int *lwork, int *info); } static void swap(double *a, int inca, double *b, int incb, int n) { double tmp; - for (int i = 0; i < n; i++, a += inca, b += incb) { + for(int i = 0; i < n; i++, a += inca, b += incb) { tmp = (*a); (*a) = (*b); (*b) = tmp; @@ -276,18 +284,18 @@ static void eigSort(int n, double *wr, double *wi, double *VL, double *VR) // Sort the eigenvalues/vectors in ascending order according to // their real part. Warning: this will screw up the ordering if we // have complex eigenvalues. - for (int i = 0; i < n - 1; i++){ + for(int i = 0; i < n - 1; i++) { int k = i; double ek = wr[i]; // search for something to swap - for (int j = i + 1; j < n; j++){ + for(int j = i + 1; j < n; j++) { const double ej = wr[j]; - if(ej < ek){ + if(ej < ek) { k = j; ek = ej; } } - if (k != i){ + if(k != i) { swap(&wr[i], 1, &wr[k], 1, 1); swap(&wi[i], 1, &wi[k], 1, 1); swap(&VL[n * i], 1, &VL[n * k], 1, n); @@ -296,7 +304,7 @@ static void eigSort(int n, double *wr, double *wi, double *VL, double *VR) } } -template<> +template <> bool fullMatrix<double>::eig(fullVector<double> &DR, fullVector<double> &DI, fullMatrix<double> &VL, fullMatrix<double> &VR, bool sortRealPart) @@ -304,12 +312,14 @@ bool fullMatrix<double>::eig(fullVector<double> &DR, fullVector<double> &DI, int N = size1(), info; int lwork = 10 * N; double *work = new double[lwork]; - F77NAME(dgeev)("V", "V", &N, _data, &N, DR._data, DI._data, - VL._data, &N, VR._data, &N, work, &lwork, &info); - delete [] work; + F77NAME(dgeev) + ("V", "V", &N, _data, &N, DR._data, DI._data, VL._data, &N, VR._data, &N, + work, &lwork, &info); + delete[] work; if(info > 0) - Msg::Error("QR Algorithm failed to compute all the eigenvalues", info, info); + Msg::Error("QR Algorithm failed to compute all the eigenvalues", info, + info); else if(info < 0) Msg::Error("Wrong %d-th argument in eig", -info); else if(sortRealPart) @@ -318,20 +328,20 @@ bool fullMatrix<double>::eig(fullVector<double> &DR, fullVector<double> &DI, return true; } -template<> -bool fullMatrix<double>::luSolve(const fullVector<double> &rhs, fullVector<double> &result) +template <> +bool fullMatrix<double>::luSolve(const fullVector<double> &rhs, + fullVector<double> &result) { int N = size1(), nrhs = 1, lda = N, ldb = N, info; int *ipiv = new int[N]; for(int i = 0; i < N; i++) result(i) = rhs(i); F77NAME(dgesv)(&N, &nrhs, _data, &lda, ipiv, result._data, &ldb, &info); - delete [] ipiv; + delete[] ipiv; if(info == 0) return true; return false; } -template<> -bool fullMatrix<double>::luFactor(fullVector<int> &ipiv) +template <> bool fullMatrix<double>::luFactor(fullVector<int> &ipiv) { int M = size1(), N = size2(), lda = size1(), info; ipiv.resize(std::min(M, N)); @@ -340,38 +350,41 @@ bool fullMatrix<double>::luFactor(fullVector<int> &ipiv) return false; } -template<> -bool fullMatrix<double>::luSubstitute(const fullVector<double> &rhs, fullVector<int> &ipiv, fullVector<double> &result) +template <> +bool fullMatrix<double>::luSubstitute(const fullVector<double> &rhs, + fullVector<int> &ipiv, + fullVector<double> &result) { - int N = size1(), nrhs=1, lda = N, ldb = N, info; + int N = size1(), nrhs = 1, lda = N, ldb = N, info; char trans = 'N'; for(int i = 0; i < N; i++) result(i) = rhs(i); - F77NAME(dgetrs)(&trans, &N, &nrhs, _data, &lda, &ipiv(0), result._data, &ldb, &info); + F77NAME(dgetrs) + (&trans, &N, &nrhs, _data, &lda, &ipiv(0), result._data, &ldb, &info); if(info == 0) return true; return false; } -template<> -bool fullMatrix<double>::invert(fullMatrix<double> &result) const +template <> bool fullMatrix<double>::invert(fullMatrix<double> &result) const { int M = size1(), N = size2(), lda = size1(), info; int *ipiv = new int[std::min(M, N)]; - if (result.size2() != M || result.size1() != N) { - if (result._own_data || !result._data) - result.resize(M,N,false); + if(result.size2() != M || result.size1() != N) { + if(result._own_data || !result._data) + result.resize(M, N, false); else Msg::Fatal("FullMatrix: Bad dimension, I cannot write in proxy"); } result.setAll(*this); F77NAME(dgetrf)(&M, &N, result._data, &lda, ipiv, &info); - if(info == 0){ + if(info == 0) { int lwork = M * 4; double *work = new double[lwork]; F77NAME(dgetri)(&M, result._data, &lda, ipiv, work, &lwork, &info); - delete [] work; + delete[] work; } - delete [] ipiv; - if(info == 0) return true; + delete[] ipiv; + if(info == 0) + return true; else if(info > 0) Msg::Error("U(%d,%d)=0 in matrix inversion", info, info); else @@ -379,21 +392,20 @@ bool fullMatrix<double>::invert(fullMatrix<double> &result) const return false; } -template<> -bool fullMatrix<double>::invertInPlace() +template <> bool fullMatrix<double>::invertInPlace() { int N = size1(), nrhs = N, lda = N, ldb = N, info; int *ipiv = new int[N]; - double * invA = new double[N*N]; + double *invA = new double[N * N]; - for (int i = 0; i < N * N; i++) invA[i] = 0.; - for (int i = 0; i < N; i++) invA[i * N + i] = 1.; + for(int i = 0; i < N * N; i++) invA[i] = 0.; + for(int i = 0; i < N; i++) invA[i * N + i] = 1.; F77NAME(dgesv)(&N, &nrhs, _data, &lda, ipiv, invA, &ldb, &info); memcpy(_data, invA, N * N * sizeof(double)); - delete [] invA; - delete [] ipiv; + delete[] invA; + delete[] ipiv; if(info == 0) return true; if(info > 0) @@ -403,16 +415,15 @@ bool fullMatrix<double>::invertInPlace() return false; } -template<> -double fullMatrix<double>::determinant() const +template <> double fullMatrix<double>::determinant() const { fullMatrix<double> tmp(*this); int M = size1(), N = size2(), lda = size1(), info; int *ipiv = new int[std::min(M, N)]; F77NAME(dgetrf)(&M, &N, tmp._data, &lda, ipiv, &info); double det = 1.; - if(info == 0){ - for(int i = 0; i < size1(); i++){ + if(info == 0) { + for(int i = 0; i < size1(); i++) { det *= tmp(i, i); if(ipiv[i] != i + 1) det = -det; } @@ -421,19 +432,20 @@ double fullMatrix<double>::determinant() const det = 0.; else Msg::Error("Wrong %d-th argument in matrix factorization", -info); - delete [] ipiv; + delete[] ipiv; return det; } -template<> +template <> bool fullMatrix<double>::svd(fullMatrix<double> &V, fullVector<double> &S) { fullMatrix<double> VT(V.size2(), V.size1()); int M = size1(), N = size2(), LDA = size1(), LDVT = VT.size1(), info; int lwork = std::max(3 * std::min(M, N) + std::max(M, N), 5 * std::min(M, N)); fullVector<double> WORK(lwork); - F77NAME(dgesvd)("O", "A", &M, &N, _data, &LDA, S._data, _data, &LDA, - VT._data, &LDVT, WORK._data, &lwork, &info); + F77NAME(dgesvd) + ("O", "A", &M, &N, _data, &LDA, S._data, _data, &LDA, VT._data, &LDVT, + WORK._data, &lwork, &info); V = VT.transpose(); if(info == 0) return true; if(info > 0) @@ -448,150 +460,119 @@ bool fullMatrix<double>::svd(fullMatrix<double> &V, fullVector<double> &S) // Provide a default implementation of the matrix inversion // Bad algorithms but it allows to use // the polynomial basis without having lapack -template<> -double fullMatrix<double>::determinant() const{ - +template <> double fullMatrix<double>::determinant() const +{ if(_r == 2) - return (*this)(0,0) * (*this)(1,1) - (*this)(0,1) * (*this)(1,0); - else if (_r == 3) - { - double det = ((*this)(0,0)*(*this)(1,1)*(*this)(2,2) - + (*this)(0,1)*(*this)(1,2)*(*this)(2,0) - + (*this)(0,2)*(*this)(1,0)*(*this)(2,1)); - det -= (*this)(0,0)*(*this)(1,2)*(*this)(2,1); - det -= (*this)(0,1)*(*this)(1,0)*(*this)(2,2); - det -= (*this)(0,2)*(*this)(1,1)*(*this)(2,0); + return (*this)(0, 0) * (*this)(1, 1) - (*this)(0, 1) * (*this)(1, 0); + else if(_r == 3) { + double det = ((*this)(0, 0) * (*this)(1, 1) * (*this)(2, 2) + + (*this)(0, 1) * (*this)(1, 2) * (*this)(2, 0) + + (*this)(0, 2) * (*this)(1, 0) * (*this)(2, 1)); + det -= (*this)(0, 0) * (*this)(1, 2) * (*this)(2, 1); + det -= (*this)(0, 1) * (*this)(1, 0) * (*this)(2, 2); + det -= (*this)(0, 2) * (*this)(1, 1) * (*this)(2, 0); return det; } - else if (_r == 4) - { - std::vector<fullMatrix<double> > temp(4,fullMatrix<double>(3,3)); - for(int k = 0; k < 4; k++) - { - for(int i = 1; i < 4; i++) - { + else if(_r == 4) { + std::vector<fullMatrix<double> > temp(4, fullMatrix<double>(3, 3)); + for(int k = 0; k < 4; k++) { + for(int i = 1; i < 4; i++) { int j1 = 0; - for(int j = 0; j < 4; j++) - { - if(k != j) - temp[k](i-1,j1++) = (*this)(i,j); + for(int j = 0; j < 4; j++) { + if(k != j) temp[k](i - 1, j1++) = (*this)(i, j); } - } } - return ((*this)(0,0) * temp[0].determinant() - - (*this)(0,1) * temp[1].determinant() + - (*this)(0,2) * temp[2].determinant() - - (*this)(0,3) * temp[3].determinant()); - } - else if (_r == 5) - { - std::vector<fullMatrix<double> > temp(5,fullMatrix<double>(4,4)); - for(int k = 0; k < 5; k++) - { - for(int i = 1; i < 5; i++) - { + return ((*this)(0, 0) * temp[0].determinant() - + (*this)(0, 1) * temp[1].determinant() + + (*this)(0, 2) * temp[2].determinant() - + (*this)(0, 3) * temp[3].determinant()); + } + else if(_r == 5) { + std::vector<fullMatrix<double> > temp(5, fullMatrix<double>(4, 4)); + for(int k = 0; k < 5; k++) { + for(int i = 1; i < 5; i++) { int j1 = 0; - for(int j = 0; j < 5; j++) - { - if(k != j) - temp[k](i-1,j1++) = (*this)(i,j); + for(int j = 0; j < 5; j++) { + if(k != j) temp[k](i - 1, j1++) = (*this)(i, j); } } } - return ((*this)(0,0) * temp[0].determinant() - - (*this)(0,1) * temp[1].determinant() + - (*this)(0,2) * temp[2].determinant() - - (*this)(0,3) * temp[3].determinant() + - (*this)(0,4) * temp[4].determinant()); - } - else - { - std::vector<fullMatrix<double> > temp(_r,fullMatrix<double>(_r-1,_r-1)); - for(int k = 0; k < _r; k++) - { - for(int i = 1; i < _r; i++) - { + return ((*this)(0, 0) * temp[0].determinant() - + (*this)(0, 1) * temp[1].determinant() + + (*this)(0, 2) * temp[2].determinant() - + (*this)(0, 3) * temp[3].determinant() + + (*this)(0, 4) * temp[4].determinant()); + } + else { + std::vector<fullMatrix<double> > temp(_r, + fullMatrix<double>(_r - 1, _r - 1)); + for(int k = 0; k < _r; k++) { + for(int i = 1; i < _r; i++) { int j1 = 0; - for(int j = 0; j < _r; j++) - { - if(k != j) - temp[k](i-1,j1++) = (*this)(i,j); + for(int j = 0; j < _r; j++) { + if(k != j) temp[k](i - 1, j1++) = (*this)(i, j); } } } double det = 0; - for(int k = 0; k < _r; k+=2) - { - det += (*this)(0,k) * temp[k].determinant(); + for(int k = 0; k < _r; k += 2) { + det += (*this)(0, k) * temp[k].determinant(); } - for(int k = 1; k < _r; k+=2) - { - det -= (*this)(0,k) * temp[k].determinant(); + for(int k = 1; k < _r; k += 2) { + det -= (*this)(0, k) * temp[k].determinant(); } return det; - } - return (*this)(0,0); // 1x1 matrix + } + return (*this)(0, 0); // 1x1 matrix } -template<> -bool fullMatrix<double>::invert(fullMatrix<double> &result) const +template <> bool fullMatrix<double>::invert(fullMatrix<double> &result) const { if(_r != _c) return false; // Copy the matrix - result.resize(_r,_c); + result.resize(_r, _c); // to find out Determinant double det = this->determinant(); - if(det == 0) - return false; + if(det == 0) return false; // Matrix of cofactor put this in a function? - fullMatrix<double> cofactor(_r,_c); - if(_r == 2) - { - cofactor(0,0) = (*this)(1,1); - cofactor(0,1) = -(*this)(1,0); - cofactor(1,0) = -(*this)(0,1); - cofactor(1,1) = (*this)(0,0); + fullMatrix<double> cofactor(_r, _c); + if(_r == 2) { + cofactor(0, 0) = (*this)(1, 1); + cofactor(0, 1) = -(*this)(1, 0); + cofactor(1, 0) = -(*this)(0, 1); + cofactor(1, 1) = (*this)(0, 0); } - else if(_r >= 3) - { - std::vector<std::vector<fullMatrix<double> > > temp(_r,std::vector<fullMatrix<double> >(_r,fullMatrix<double>(_r-1,_r-1))); - for(int k1 = 0; k1 < _r; k1++) - { - for(int k2 = 0; k2 < _r; k2++) - { + else if(_r >= 3) { + std::vector<std::vector<fullMatrix<double> > > temp( + _r, + std::vector<fullMatrix<double> >(_r, fullMatrix<double>(_r - 1, _r - 1))); + for(int k1 = 0; k1 < _r; k1++) { + for(int k2 = 0; k2 < _r; k2++) { int i1 = 0; - for(int i = 0; i < _r; i++) - { + for(int i = 0; i < _r; i++) { int j1 = 0; - for(int j = 0; j < _r; j++) - { - if(k1 != i && k2 != j) - temp[k1][k2](i1,j1++) = (*this)(i,j); + for(int j = 0; j < _r; j++) { + if(k1 != i && k2 != j) temp[k1][k2](i1, j1++) = (*this)(i, j); } - if(k1 != i) - i1++; + if(k1 != i) i1++; } } } bool flagPositive; - for(int k1 = 0; k1 < _r; k1++) - { + for(int k1 = 0; k1 < _r; k1++) { flagPositive = (k1 % 2) == 0 ? true : false; - for(int k2 = 0; k2 < _r; k2++) - { - if(flagPositive) - { - cofactor(k1,k2) = temp[k1][k2].determinant(); + for(int k2 = 0; k2 < _r; k2++) { + if(flagPositive) { + cofactor(k1, k2) = temp[k1][k2].determinant(); flagPositive = false; } - else - { - cofactor(k1,k2) = -temp[k1][k2].determinant(); + else { + cofactor(k1, k2) = -temp[k1][k2].determinant(); flagPositive = true; } } @@ -600,11 +581,9 @@ bool fullMatrix<double>::invert(fullMatrix<double> &result) const // end cofactor // inv = transpose of cofactor / Determinant - for(int i = 0; i < _r; i++) - { - for(int j = 0; j < _c; j++) - { - result(j,i) = cofactor(i,j) / det; + for(int i = 0; i < _r; i++) { + for(int j = 0; j < _c; j++) { + result(j, i) = cofactor(i, j) / det; } } return true; @@ -612,40 +591,46 @@ bool fullMatrix<double>::invert(fullMatrix<double> &result) const #endif -template<> -void fullMatrix<double>::print(const std::string name, const std::string format) const +template <> +void fullMatrix<double>::print(const std::string name, + const std::string format) const { std::string rformat = (format == "") ? "%12.5E " : format; int ni = size1(); int nj = size2(); - printf("double %s [ %d ][ %d ]= { \n", name.c_str(),ni,nj); - for(int I = 0; I < ni; I++){ + printf("double %s [ %d ][ %d ]= { \n", name.c_str(), ni, nj); + for(int I = 0; I < ni; I++) { printf("{ "); - for(int J = 0; J < nj; J++){ + for(int J = 0; J < nj; J++) { printf(rformat.c_str(), (*this)(I, J)); - if (J!=nj-1)printf(","); + if(J != nj - 1) printf(","); } - if (I!=ni-1)printf("},\n"); - else printf("}\n"); + if(I != ni - 1) + printf("},\n"); + else + printf("}\n"); } printf("};\n"); } -template<> -void fullMatrix<int>::print(const std::string name, const std::string format) const +template <> +void fullMatrix<int>::print(const std::string name, + const std::string format) const { std::string rformat = (format == "") ? "%12d " : format; int ni = size1(); int nj = size2(); - printf("int %s [ %d ][ %d ]= { \n", name.c_str(),ni,nj); - for(int I = 0; I < ni; I++){ + printf("int %s [ %d ][ %d ]= { \n", name.c_str(), ni, nj); + for(int I = 0; I < ni; I++) { printf("{ "); - for(int J = 0; J < nj; J++){ + for(int J = 0; J < nj; J++) { printf(rformat.c_str(), (*this)(I, J)); - if (J!=nj-1)printf(","); + if(J != nj - 1) printf(","); } - if (I!=ni-1)printf("},\n"); - else printf("}\n"); + if(I != ni - 1) + printf("},\n"); + else + printf("}\n"); } printf("};\n"); } diff --git a/Numeric/fullMatrix.h b/Numeric/fullMatrix.h index e562b5bb34cbb69c989c7699bd48597d0efc0fd4..5d52a9eb00e7df39b81e25d1dbfc0d5a9df4018c 100644 --- a/Numeric/fullMatrix.h +++ b/Numeric/fullMatrix.h @@ -39,28 +39,26 @@ template <class scalar> class fullMatrix; */ // An abstract interface for vectors of scalar -template <class scalar> -class fullVector -{ - private: - int _r; // size of the vector - scalar *_data; // pointer on the first element +template <class scalar> class fullVector { +private: + int _r; // size of the vector + scalar *_data; // pointer on the first element bool _own_data; friend class fullMatrix<scalar>; - public: +public: // constructor and destructor /** Instantiates a zero size fullVector. */ - fullVector(void) : _r(0),_data(0),_own_data(1) {} + fullVector(void) : _r(0), _data(0), _own_data(1) {} /** @param r A positive integer. Instantiates a fullVector of size r filled with zeros. */ - fullVector(int r) : _r(r),_own_data(1) + fullVector(int r) : _r(r), _own_data(1) { _data = new scalar[_r]; setAll(scalar(0.)); @@ -85,7 +83,7 @@ class fullVector Instantiates a fullVector, which is a copy (and not a proxy) of other. */ - fullVector(const fullVector<scalar> &other) : _r(other._r),_own_data(1) + fullVector(const fullVector<scalar> &other) : _r(other._r), _own_data(1) { _data = new scalar[_r]; for(int i = 0; i < _r; ++i) _data[i] = other._data[i]; @@ -96,40 +94,40 @@ class fullVector */ ~fullVector() { - if(_own_data && _data) delete [] _data; + if(_own_data && _data) delete[] _data; } // get information (size, value) /** @return Returns the size of this fullVector */ - inline int size() const { return _r; } + inline int size() const { return _r; } /** @return Returns a const pointer to this fullVector data.@n This pointer will point to the following memory segment: [(*this)(0), (*this)(1), ..., (*this)(this->size() - 1)]. */ - inline const scalar * getDataPtr() const { return _data; } + inline const scalar *getDataPtr() const { return _data; } /** @return Returns a pointer to this fullVector data.@n This pointer will point to the following memory segment: [(*this)(0), (*this)(1), ..., (*this)(this->size() - 1)]. */ - inline scalar * getDataPtr() { return _data; } + inline scalar *getDataPtr() { return _data; } /** @param i A vector index between 0 and size() - 1. @returns Returns the ith scalar of this fullVector. */ - inline scalar operator () (int i) const { return _data[i]; } + inline scalar operator()(int i) const { return _data[i]; } /** @param i A vector index between 0 and size() - 1. @returns Returns a reference to the ith scalar of this fullVector. */ - inline scalar & operator () (int i) { return _data[i]; } + inline scalar &operator()(int i) { return _data[i]; } // copy /** @@ -138,11 +136,11 @@ class fullVector The right hand side fullVector will become a copy of other, and will loose its previous data. */ - fullVector<scalar>& operator= (const fullVector<scalar> &other) + fullVector<scalar> &operator=(const fullVector<scalar> &other) { - if (this != &other) { - if ((!resize(other.size(), false) && _r > 2*other.size())) { - if (_data) delete[] _data; + if(this != &other) { + if((!resize(other.size(), false) && _r > 2 * other.size())) { + if(_data) delete[] _data; _r = other.size(); _data = new scalar[_r]; } @@ -164,12 +162,12 @@ class fullVector The rth value of this fullVector is set to v. */ - inline void set(int r, scalar v){ - #ifdef _DEBUG - if (r >= _r || r < 0) - Msg::Fatal("invalid index to access fullVector : %i (size = %i)", - r, _r); - #endif + inline void set(int r, scalar v) + { +#ifdef _DEBUG + if(r >= _r || r < 0) + Msg::Fatal("invalid index to access fullVector : %i (size = %i)", r, _r); +#endif (*this)(r) = v; } @@ -199,18 +197,16 @@ class fullVector */ bool resize(int r, bool resetValue = true) { - if (_r < r || !_own_data) { - if (_own_data && _data) delete[] _data; + if(_r < r || !_own_data) { + if(_own_data && _data) delete[] _data; _r = r; _data = new scalar[_r]; _own_data = true; - if(resetValue) - setAll(scalar(0.)); + if(resetValue) setAll(scalar(0.)); return true; } _r = r; - if(resetValue) - setAll(scalar(0.)); + if(resetValue) setAll(scalar(0.)); return false; } @@ -226,7 +222,7 @@ class fullVector */ void setAsProxy(const fullVector<scalar> &original, int r_start, int r) { - if(_own_data && _data) delete [] _data; + if(_own_data && _data) delete[] _data; _own_data = false; _r = r; _data = original._data + r_start; @@ -243,7 +239,7 @@ class fullVector */ void setAsProxy(const fullMatrix<scalar> &original, int c) { - if(_own_data && _data) delete [] _data; + if(_own_data && _data) delete[] _data; _own_data = false; _r = original._r; _data = original._data + c * _r; @@ -258,7 +254,7 @@ class fullVector { if(s == scalar(0.)) for(int i = 0; i < _r; ++i) _data[i] = scalar(0.); - else if (s == -1.) + else if(s == -1.) for(int i = 0; i < _r; ++i) _data[i] = -_data[i]; else for(int i = 0; i < _r; ++i) _data[i] *= s; @@ -271,7 +267,7 @@ class fullVector */ inline void setAll(const scalar &m) { - for(int i = 0; i < _r; i++) set(i,m); + for(int i = 0; i < _r; i++) set(i, m); } /** @@ -299,7 +295,7 @@ class fullVector @return Returns the scalar product of this fullVector with the other. */ - inline scalar operator *(const fullVector<scalar> &other) + inline scalar operator*(const fullVector<scalar> &other) { scalar s = 0.; for(int i = 0; i < _r; ++i) s += _data[i] * other._data[i]; @@ -320,10 +316,10 @@ class fullVector x.size() must be greater or equal to @f$ N @f$. */ - void axpy(const fullVector<scalar> &x, scalar alpha=1.) + void axpy(const fullVector<scalar> &x, scalar alpha = 1.) #if !defined(HAVE_BLAS) { - for (int i = 0; i < _r; i++) _data[i] += alpha * x._data[i]; + for(int i = 0; i < _r; i++) _data[i] += alpha * x._data[i]; } #endif ; @@ -343,7 +339,7 @@ class fullVector */ void multTByT(const fullVector<scalar> &x) { - for (int i = 0; i < _r; i++) _data[i] *= x._data[i]; + for(int i = 0; i < _r; i++) _data[i] *= x._data[i]; } // printing and file treatment @@ -355,11 +351,11 @@ class fullVector This string starts by name. */ - void print(const char *name="") const + void print(const char *name = "") const { - printf("double %s[%d]=\n", name,size()); + printf("double %s[%d]=\n", name, size()); printf("{ "); - for(int I = 0; I < size(); I++){ + for(int I = 0; I < size(); I++) { printf("%12.5E ", (*this)(I)); } printf("};\n"); @@ -371,10 +367,7 @@ class fullVector Writes a binary representation of this fullVector into f. */ - void binarySave (FILE *f) const - { - fwrite (_data, sizeof(scalar), _r, f); - } + void binarySave(FILE *f) const { fwrite(_data, sizeof(scalar), _r, f); } /** @param f A pointer to a FILE stream containing a fullVector. @@ -384,44 +377,40 @@ class fullVector @see fullVector::binarySave */ - void binaryLoad (FILE *f) + void binaryLoad(FILE *f) { - if(fread (_data, sizeof(scalar), _r, f) != (size_t)_r) return; + if(fread(_data, sizeof(scalar), _r, f) != (size_t)_r) return; } - bool getOwnData() const {return _own_data;}; - void setOwnData(bool ownData) {_own_data = ownData;}; + bool getOwnData() const { return _own_data; }; + void setOwnData(bool ownData) { _own_data = ownData; }; }; // Specialisation of fullVector<scalar>::norm() const -template<> -inline double fullVector<double>::norm() const +template <> inline double fullVector<double>::norm() const { double n = 0.; for(int i = 0; i < _r; ++i) n += _data[i] * _data[i]; return sqrt(n); } -template<> +template <> inline std::complex<double> fullVector<std::complex<double> >::norm() const { double n = 0.; - for(int i = 0; i < _r; ++i) n += _data[i].real() * _data[i].real() + - _data[i].imag() * _data[i].imag(); + for(int i = 0; i < _r; ++i) + n += _data[i].real() * _data[i].real() + _data[i].imag() * _data[i].imag(); return std::complex<double>(sqrt(n), 0.); } - // An abstract interface for dense matrix of scalar -template <class scalar> -class fullMatrix -{ - private: +template <class scalar> class fullMatrix { +private: bool _own_data; // should data be freed on delete ? int _r, _c; // size of the matrix scalar *_data; // pointer on the first element friend class fullVector<scalar>; - public: +public: // constructor and destructor fullMatrix(scalar *original, int r, int c) { @@ -441,8 +430,7 @@ class fullMatrix { _data = new scalar[_r * _c]; _own_data = true; - if (init0) - setAll(scalar(0.)); + if(init0) setAll(scalar(0.)); } fullMatrix(int r, int c, scalar *data) : _r(r), _c(c), _data(data), _own_data(false) @@ -452,13 +440,13 @@ class fullMatrix fullMatrix(const fullMatrix<scalar> &other) : _r(other._r), _c(other._c) { _data = new scalar[_r * _c]; - _own_data=true; + _own_data = true; for(int i = 0; i < _r * _c; ++i) _data[i] = other._data[i]; } - fullMatrix() : _own_data(false),_r(0), _c(0), _data(0) {} + fullMatrix() : _own_data(false), _r(0), _c(0), _data(0) {} ~fullMatrix() { - if(_data && _own_data) delete [] _data; + if(_data && _own_data) delete[] _data; } // get information (size, value) @@ -466,66 +454,66 @@ class fullMatrix inline int size2() const { return _c; } inline scalar get(int r, int c) const { - #ifdef _DEBUG - if (r >= _r || r < 0 || c >= _c || c < 0) - Msg::Fatal("invalid index to access fullMatrix : %i %i (size = %i %i)", - r, c, _r, _c); - #endif +#ifdef _DEBUG + if(r >= _r || r < 0 || c >= _c || c < 0) + Msg::Fatal("invalid index to access fullMatrix : %i %i (size = %i %i)", r, + c, _r, _c); +#endif return (*this)(r, c); } - inline const scalar * getDataPtr() const { return _data; } - inline scalar * getDataPtr() { return _data; } + inline const scalar *getDataPtr() const { return _data; } + inline scalar *getDataPtr() { return _data; } // operations - inline void set(int r, int c, scalar v){ - #ifdef _DEBUG - if (r >= _r || r < 0 || c >= _c || c < 0) - Msg::Fatal("invalid index to access fullMatrix : %i %i (size = %i %i)", - r, c, _r, _c); - #endif + inline void set(int r, int c, scalar v) + { +#ifdef _DEBUG + if(r >= _r || r < 0 || c >= _c || c < 0) + Msg::Fatal("invalid index to access fullMatrix : %i %i (size = %i %i)", r, + c, _r, _c); +#endif (*this)(r, c) = v; } inline scalar norm() const { scalar n = 0.; for(int i = 0; i < _r; ++i) - for(int j = 0; j < _c; ++j) - n += (*this)(i, j) * (*this)(i, j); + for(int j = 0; j < _c; ++j) n += (*this)(i, j) * (*this)(i, j); return sqrt(n); } - bool resize(int r, int c, bool resetValue = true) // data will be owned (same as constructor) + bool + resize(int r, int c, + bool resetValue = true) // data will be owned (same as constructor) { - if ((r * c > _r * _c) || !_own_data) { - if (_own_data && _data) delete[] _data; + if((r * c > _r * _c) || !_own_data) { + if(_own_data && _data) delete[] _data; _r = r; _c = c; _data = new scalar[_r * _c]; _own_data = true; - if(resetValue) - setAll(scalar(0.)); + if(resetValue) setAll(scalar(0.)); return true; } _r = r; _c = c; - if(resetValue) - setAll(scalar(0.)); + if(resetValue) setAll(scalar(0.)); return false; // no reallocation } - void reshape(int nbRows, int nbColumns){ - if (nbRows == -1 && nbColumns != -1) - nbRows = _r * _c / nbColumns; - if (nbRows != -1 && nbColumns == -1) - nbColumns = _r * _c / nbRows; - if (nbRows*nbColumns != size1()*size2()) - Msg::Error("Invalid reshape, total number of entries must be equal (new %i x %i != old %i x %i)", nbRows, nbColumns, size1(), size2()); + void reshape(int nbRows, int nbColumns) + { + if(nbRows == -1 && nbColumns != -1) nbRows = _r * _c / nbColumns; + if(nbRows != -1 && nbColumns == -1) nbColumns = _r * _c / nbRows; + if(nbRows * nbColumns != size1() * size2()) + Msg::Error("Invalid reshape, total number of entries must be equal (new " + "%i x %i != old %i x %i)", + nbRows, nbColumns, size1(), size2()); _r = nbRows; _c = nbColumns; } void setAsProxy(const fullMatrix<scalar> &original) { - if(_data && _own_data) - delete [] _data; + if(_data && _own_data) delete[] _data; _c = original._c; _r = original._r; _own_data = false; @@ -533,8 +521,7 @@ class fullMatrix } void setAsProxy(const fullMatrix<scalar> &original, int c_start, int c) { - if(_data && _own_data) - delete [] _data; + if(_data && _own_data) delete[] _data; _c = c; _r = original._r; _own_data = false; @@ -542,40 +529,39 @@ class fullMatrix } void setAsProxy(scalar *data, int r, int c) { - if(_data && _own_data) - delete [] _data; + if(_data && _own_data) delete[] _data; _c = c; _r = r; _own_data = false; _data = data; } - fullMatrix<scalar> & operator = (const fullMatrix<scalar> &other) + fullMatrix<scalar> &operator=(const fullMatrix<scalar> &other) { copy(other); return *this; } - void operator += (const fullMatrix<scalar> &other) + void operator+=(const fullMatrix<scalar> &other) { - if(_r != other._r || _c!= other._c) + if(_r != other._r || _c != other._c) Msg::Error("sum matrices of different sizes\n"); for(int i = 0; i < _r * _c; ++i) _data[i] += other._data[i]; } - inline scalar operator () (int i, int j) const + inline scalar operator()(int i, int j) const { - #ifdef _DEBUG - if (i >= _r || i < 0 || j >= _c || j < 0) - Msg::Fatal("invalid index to access fullMatrix : %i %i (size = %i %i)", - i, j, _r, _c); - #endif +#ifdef _DEBUG + if(i >= _r || i < 0 || j >= _c || j < 0) + Msg::Fatal("invalid index to access fullMatrix : %i %i (size = %i %i)", i, + j, _r, _c); +#endif return _data[i + _r * j]; } - inline scalar & operator () (int i, int j) + inline scalar &operator()(int i, int j) { - #ifdef _DEBUG - if (i >= _r || i < 0 || j >= _c || j < 0) - Msg::Fatal("invalid index to access fullMatrix : %i %i (size = %i %i)", - i, j, _r, _c); - #endif +#ifdef _DEBUG + if(i >= _r || i < 0 || j >= _c || j < 0) + Msg::Fatal("invalid index to access fullMatrix : %i %i (size = %i %i)", i, + j, _r, _c); +#endif return _data[i + _r * j]; } void copy(const fullMatrix<scalar> &a, int i0, int ni, int j0, int nj, @@ -587,11 +573,11 @@ class fullMatrix } void copy(const fullMatrix<scalar> &a) { - if (_data && !_own_data) - Msg::Fatal("fullMatrix::copy operation is prohibited for proxies, use setAll instead"); - if (_r != a._r || _c != a._c) { - if(_data && _own_data) - delete [] _data; + if(_data && !_own_data) + Msg::Fatal("fullMatrix::copy operation is prohibited for proxies, use " + "setAll instead"); + if(_r != a._r || _c != a._c) { + if(_data && _own_data) delete[] _data; _r = a._r; _c = a._c; _data = new scalar[_r * _c]; @@ -610,24 +596,24 @@ class fullMatrix void mult(const fullMatrix<scalar> &b, fullMatrix<scalar> &c) const #if !defined(HAVE_BLAS) { - mult_naive(b,c); + mult_naive(b, c); } #endif ; void multTByT(const fullMatrix<scalar> &a) { - for (int i = 0; i < _r * _c; i++) _data[i] *= a._data[i]; + for(int i = 0; i < _r * _c; i++) _data[i] *= a._data[i]; } - void axpy(const fullMatrix<scalar> &x, scalar alpha=1.) + void axpy(const fullMatrix<scalar> &x, scalar alpha = 1.) #if !defined(HAVE_BLAS) { int n = _r * _c; - for (int i = 0; i < n; i++) _data[i] += alpha * x._data[i]; + for(int i = 0; i < n; i++) _data[i] += alpha * x._data[i]; } #endif ; void gemm_naive(const fullMatrix<scalar> &a, const fullMatrix<scalar> &b, - scalar alpha=1., scalar beta=1.) + scalar alpha = 1., scalar beta = 1.) { fullMatrix<scalar> temp(a.size1(), b.size2()); a.mult_naive(b, temp); @@ -636,10 +622,12 @@ class fullMatrix add(temp); } void gemm(const fullMatrix<scalar> &a, const fullMatrix<scalar> &b, - scalar alpha=1., scalar beta=1., bool transposeA = false, bool transposeB = false) + scalar alpha = 1., scalar beta = 1., bool transposeA = false, + bool transposeB = false) #if !defined(HAVE_BLAS) { - gemm_naive(transposeA ? a.transpose() : a, transposeB ? b.transpose() : b, alpha, beta); + gemm_naive(transposeA ? a.transpose() : a, transposeB ? b.transpose() : b, + alpha, beta); } #endif ; @@ -650,8 +638,7 @@ class fullMatrix void setAll(const fullMatrix<scalar> &m) #if !defined(HAVE_BLAS) { - if (_r != m._r || _c != m._c ) - Msg::Fatal("fullMatrix size does not match"); + if(_r != m._r || _c != m._c) Msg::Fatal("fullMatrix size does not match"); for(int i = 0; i < _r * _c; i++) _data[i] = m._data[i]; } #endif @@ -659,7 +646,8 @@ class fullMatrix void scale(const double s) #if !defined(HAVE_BLAS) { - if(s == 0.) // this is not really correct nan*0 (or inf*0) is expected to give nan + if(s == 0.) // this is not really correct nan*0 (or inf*0) is expected to + // give nan for(int i = 0; i < _r * _c; ++i) _data[i] = scalar(0.); else for(int i = 0; i < _r * _c; ++i) _data[i] *= s; @@ -673,22 +661,19 @@ class fullMatrix inline void add(const fullMatrix<scalar> &m) { for(int i = 0; i < size1(); i++) - for(int j = 0; j < size2(); j++) - (*this)(i, j) += m(i, j); + for(int j = 0; j < size2(); j++) (*this)(i, j) += m(i, j); } inline void add(const fullMatrix<scalar> &m, const double &a) { for(int i = 0; i < size1(); i++) - for(int j = 0; j < size2(); j++) - (*this)(i, j) += a*m(i, j); + for(int j = 0; j < size2(); j++) (*this)(i, j) += a * m(i, j); } void mult(const fullVector<scalar> &x, fullVector<scalar> &y) const #if !defined(HAVE_BLAS) { y.scale(scalar(0.)); for(int i = 0; i < _r; i++) - for(int j = 0; j < _c; j++) - y._data[i] += (*this)(i, j) * x(j); + for(int j = 0; j < _c; j++) y._data[i] += (*this)(i, j) * x(j); } #endif ; @@ -696,8 +681,7 @@ class fullMatrix #if !defined(HAVE_BLAS) { for(int i = 0; i < _r; i++) - for(int j = 0; j < _c; j++) - y._data[i] += (*this)(i, j) * x(j); + for(int j = 0; j < _c; j++) y._data[i] += (*this)(i, j) * x(j); } #endif ; @@ -705,14 +689,14 @@ class fullMatrix { fullMatrix<scalar> T(size2(), size1()); for(int i = 0; i < size1(); i++) - for(int j = 0; j < size2(); j++) - T(j, i) = (*this)(i, j); + for(int j = 0; j < size2(); j++) T(j, i) = (*this)(i, j); return T; } inline void transposeInPlace() { - if(size1() != size2()){ - Msg::Error("Not a square matrix (size1: %d, size2: %d)", size1(), size2()); + if(size1() != size2()) { + Msg::Error("Not a square matrix (size1: %d, size2: %d)", size1(), + size2()); } scalar t; for(int i = 0; i < size1(); i++) @@ -730,7 +714,7 @@ class fullMatrix } #endif ; - bool luFactor(fullVector<int> &ipiv) + bool luFactor(fullVector<int> &ipiv) #if !defined(HAVE_LAPACK) { Msg::Error("LU factorization requires LAPACK"); @@ -738,7 +722,8 @@ class fullMatrix } #endif ; - bool luSubstitute(const fullVector<scalar> &rhs, fullVector<int> &ipiv, fullVector<scalar> &result) + bool luSubstitute(const fullVector<scalar> &rhs, fullVector<int> &ipiv, + fullVector<scalar> &result) #if !defined(HAVE_LAPACK) { Msg::Error("LU substitution requires LAPACK"); @@ -755,8 +740,8 @@ class fullMatrix #endif ; bool eig(fullVector<double> &eigenValReal, fullVector<double> &eigenValImag, - fullMatrix<scalar> &leftEigenVect, fullMatrix<scalar> &rightEigenVect, - bool sortRealPart=false) + fullMatrix<scalar> &leftEigenVect, + fullMatrix<scalar> &rightEigenVect, bool sortRealPart = false) #if !defined(HAVE_LAPACK) { Msg::Error("Eigenvalue computations requires LAPACK"); @@ -790,55 +775,49 @@ class fullMatrix void print(const std::string name = "", const std::string format = "") const; - void binarySave (FILE *f) const - { - fwrite (_data, sizeof(scalar), _r*_c, f); - } - void binaryLoad (FILE *f) + void binarySave(FILE *f) const { fwrite(_data, sizeof(scalar), _r * _c, f); } + void binaryLoad(FILE *f) { - if(fread (_data, sizeof(scalar), _r*_c, f) != (size_t)_r) return; + if(fread(_data, sizeof(scalar), _r * _c, f) != (size_t)_r) return; } // specific functions for dgshell - void mult_naiveBlock(const fullMatrix<scalar> &b, const int ncol, const int fcol, - const int alpha, const int beta, fullVector<scalar> &c, - const int row=0) const + void mult_naiveBlock(const fullMatrix<scalar> &b, const int ncol, + const int fcol, const int alpha, const int beta, + fullVector<scalar> &c, const int row = 0) const { - if(beta != 1) - c.scale(beta); - for(int j = fcol; j < fcol+ncol; j++) - for(int k = 0; k < _c ; k++) - c._data[j] += alpha*(*this)(row, k) * b(k, j); + if(beta != 1) c.scale(beta); + for(int j = fcol; j < fcol + ncol; j++) + for(int k = 0; k < _c; k++) + c._data[j] += alpha * (*this)(row, k) * b(k, j); } void multOnBlock(const fullMatrix<scalar> &b, const int ncol, const int fcol, const int alpha, const int beta, fullVector<scalar> &c) const #if !defined(HAVE_BLAS) { - mult_naiveBlock(b,ncol,fcol,alpha,beta,c); + mult_naiveBlock(b, ncol, fcol, alpha, beta, c); } #endif ; - void multWithATranspose(const fullVector<scalar> &x, scalar alpha, scalar beta, - fullVector<scalar> &y) const + void multWithATranspose(const fullVector<scalar> &x, scalar alpha, + scalar beta, fullVector<scalar> &y) const #if !defined(HAVE_BLAS) { y.scale(beta); for(int j = 0; j < _c; j++) - for(int i = 0; i < _r; i++) - y._data[j] += alpha * (*this)(i, j) * x(i); + for(int i = 0; i < _r; i++) y._data[j] += alpha * (*this)(i, j) * x(i); } #endif ; void copyOneColumn(const fullVector<scalar> &x, const int ind) const { - int cind = _c*ind; - for(int i = 0; i < _r; i++) - _data[cind+i] = x(i); + int cind = _c * ind; + for(int i = 0; i < _r; i++) _data[cind + i] = x(i); } - bool getOwnData() const {return _own_data;}; - void setOwnData(bool ownData) {_own_data = ownData;}; + bool getOwnData() const { return _own_data; }; + void setOwnData(bool ownData) { _own_data = ownData; }; }; #endif diff --git a/Numeric/hausdorffDistance.cpp b/Numeric/hausdorffDistance.cpp index 02429aa480d84f453e4056ca880275ac5076fc84..e546f7b70163db6f33d12f9f52a6ffb7b4d1399e 100644 --- a/Numeric/hausdorffDistance.cpp +++ b/Numeric/hausdorffDistance.cpp @@ -12,48 +12,49 @@ #include "SVector3.h" #include "hausdorffDistance.h" -static double intersect (SPoint3 &q, SVector3 &n, // a plane - SPoint3 &p1, SPoint3 &p2, // a segment - SPoint3 &result) +static double intersect(SPoint3 &q, SVector3 &n, // a plane + SPoint3 &p1, SPoint3 &p2, // a segment + SPoint3 &result) { // n * (x-q) = 0 // x = p1 + t (p2-p1) // n *(p1 + t (p2-p1) - q) = 0 // t = n*(q-p1) / n*(p2-p1) - const double t = dot(n,q-p1)/dot(n,p2-p1); - result = p1 *(1.-t)+ p2*t; + const double t = dot(n, q - p1) / dot(n, p2 - p1); + result = p1 * (1. - t) + p2 * t; return t; } -static double projection (SPoint3 &p1, SPoint3 &p2, SPoint3 &q, SPoint3 &result) +static double projection(SPoint3 &p1, SPoint3 &p2, SPoint3 &q, SPoint3 &result) { // x = p1 + t (p2 - p1) // (x - q) * (p2 - p1) = 0 // (p1 + t (p2 - p1) - q) (p2 - p1) = 0 // t = (q-p1) * (p2-p1) / (p2-p1)^2 - SVector3 p21 = p2-p1; - const double t = dot(q-p1,p21)/dot(p21,p21); - result = p1 *(1.-t)+ p2*t; + SVector3 p21 = p2 - p1; + const double t = dot(q - p1, p21) / dot(p21, p21); + result = p1 * (1. - t) + p2 * t; return t; } -static SPoint3 closestPoint (SPoint3 &p1, SPoint3 &p2, SPoint3 &q) +static SPoint3 closestPoint(SPoint3 &p1, SPoint3 &p2, SPoint3 &q) { double result; - const double t = projection (p1,p2,q,result); - if (t >= 0.0 && t <= 1.0)return result; - if (t < 0)return p1; + const double t = projection(p1, p2, q, result); + if(t >= 0.0 && t <= 1.0) return result; + if(t < 0) return p1; return p2; } -double closestPoint (const std::vector<SPoint3> &P, const SPoint3 &p, SPoint3 & result) +double closestPoint(const std::vector<SPoint3> &P, const SPoint3 &p, + SPoint3 &result) { double closestDistance = 1.e22; - for (unsigned int i=1;i<P.size();i++){ - SPoint3 q = closestPoint (P[i-1],P[i],p); + for(unsigned int i = 1; i < P.size(); i++) { + SPoint3 q = closestPoint(P[i - 1], P[i], p); const double pq = p.distance(q); - if (pq < closestDistance){ + if(pq < closestDistance) { closestDistance = pq; result = q; } @@ -63,17 +64,17 @@ double closestPoint (const std::vector<SPoint3> &P, const SPoint3 &p, SPoint3 & // we test all points of P plus all points that are the intersections // of angle bissectors of Q with P -double oneSidedHausdorffDistance (const std::vector<SPoint3> &P, - const std::vector<SPoint3> &Q, - SPoint3 &p1, SPoint3 &p2) +double oneSidedHausdorffDistance(const std::vector<SPoint3> &P, + const std::vector<SPoint3> &Q, SPoint3 &p1, + SPoint3 &p2) { const double hausdorffDistance = 0.0; // first test the points - for (unsigned int i=0;i<P.size();i++){ + for(unsigned int i = 0; i < P.size(); i++) { SPoint3 result; - double d = closestPoint (Q, P[i], result); - if (d > hausdorffDistance){ + double d = closestPoint(Q, P[i], result); + if(d > hausdorffDistance) { hausdorffDistance = d; p1 = P[i]; p2 = result; @@ -81,34 +82,34 @@ double oneSidedHausdorffDistance (const std::vector<SPoint3> &P, } // compute angle bissectors intersections std::vector<SPoint3> intersections; - for (unsigned int i=1;i<Q.size()-1;i++){ - SPoint3 a = Q[i-1]; + for(unsigned int i = 1; i < Q.size() - 1; i++) { + SPoint3 a = Q[i - 1]; SPoint3 b = Q[i]; - SPoint3 c = Q[i+1]; - SVector3 ba = b-a; - SVector3 ca = c-a; - SVector3 bissector = (ba+ca); + SPoint3 c = Q[i + 1]; + SVector3 ba = b - a; + SVector3 ca = c - a; + SVector3 bissector = (ba + ca); SVector3 n; // normal to the bissector plane - if (bissector.norm == 0){ + if(bissector.norm == 0) { ba.normalize(); n = ba; } - else{ - SVector3 b = crossprod (bissector,ba); - n = crossprod (b,bissector); + else { + SVector3 b = crossprod(bissector, ba); + n = crossprod(b, bissector); n.normalize(); } - for (unsigned int i=1;i<P.size();i++){ + for(unsigned int i = 1; i < P.size(); i++) { SPoint3 result; - const double t = intersect (b, n, P[i-1],P[i],result); - if (t >=0 && t <=1)intersections.push_back(result); + const double t = intersect(b, n, P[i - 1], P[i], result); + if(t >= 0 && t <= 1) intersections.push_back(result); } } - for (unsigned int i=0;i<intersections.size();i++){ + for(unsigned int i = 0; i < intersections.size(); i++) { SPoint3 result; - double d = closestPoint (Q, intersections[i], result); - if (d > hausdorffDistance){ + double d = closestPoint(Q, intersections[i], result); + if(d > hausdorffDistance) { hausdorffDistance = d; p1 = P[i]; p2 = result; @@ -117,9 +118,9 @@ double oneSidedHausdorffDistance (const std::vector<SPoint3> &P, return hausdorffDistance; } -double hausdorffDistance (const std::vector<SPoint3> &P, - const std::vector<SPoint3> &Q) +double hausdorffDistance(const std::vector<SPoint3> &P, + const std::vector<SPoint3> &Q) { - return std::max(oneSidedHausdorffDistance (P,Q), - oneSidedHausdorffDistance (Q,P)); + return std::max(oneSidedHausdorffDistance(P, Q), + oneSidedHausdorffDistance(Q, P)); } diff --git a/Numeric/hausdorffDistance.h b/Numeric/hausdorffDistance.h index 09f4ef39a213d979bf0dd86aa51a5acbc0bd0b88..80cc260490dec17004b9ea58632500cd3d90dd83 100644 --- a/Numeric/hausdorffDistance.h +++ b/Numeric/hausdorffDistance.h @@ -2,6 +2,6 @@ #define _HAUSDORFF_DISTANCE_H_ #include <vector> #include "SPoint3.h" -double hausdorffDistance (const std::vector<SPoint3> &P, - const std::vector<SPoint3> &Q); +double hausdorffDistance(const std::vector<SPoint3> &P, + const std::vector<SPoint3> &Q); #endif diff --git a/Numeric/incompleteBasis.cpp b/Numeric/incompleteBasis.cpp index fb392674c198bf84789382531c027076ae6ede17..564f33f55846e773438ecdf64080fa87ec929fd7 100644 --- a/Numeric/incompleteBasis.cpp +++ b/Numeric/incompleteBasis.cpp @@ -13,17 +13,17 @@ void incompleteBasis::_computeCoefficientsTriangle() { - if (order < 3) { + if(order < 3) { coefficients.resize(0, 0); return; } int szInc = getNumShapeFunctions(); int szComp = completeBasis->getNumShapeFunctions(); - coefficients.resize(szComp-szInc, szInc, true); + coefficients.resize(szComp - szInc, szInc, true); std::map<std::pair<int, int>, int> coord2idx; - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { int u = static_cast<int>(points(i, 0) * order + .5); int v = static_cast<int>(points(i, 1) * order + .5); coord2idx[std::make_pair(u, v)] = i; @@ -31,83 +31,81 @@ void incompleteBasis::_computeCoefficientsTriangle() int &n = order; fullMatrix<double> pts = completeBasis->getReferenceNodes(); - for (int i = 0; i < szComp-szInc; ++i) { + for(int i = 0; i < szComp - szInc; ++i) { double xi = pts(szInc + i, 0); double eta = pts(szInc + i, 1); int u = static_cast<int>(xi * order + .5); int v = static_cast<int>(eta * order + .5); - coefficients(i, coord2idx[std::make_pair(u+v, 0)]) = xi; - coefficients(i, coord2idx[std::make_pair( n, 0)]) = -xi; - coefficients(i, coord2idx[std::make_pair(n-v, v)]) = xi; - coefficients(i, coord2idx[std::make_pair( u, n-u)]) = eta; - coefficients(i, coord2idx[std::make_pair( 0, n)]) = -eta; - coefficients(i, coord2idx[std::make_pair( 0, u+v)]) = eta; - coefficients(i, coord2idx[std::make_pair( 0, v)]) = 1-xi-eta; - coefficients(i, coord2idx[std::make_pair( 0, 0)]) = -(1-xi-eta); - coefficients(i, coord2idx[std::make_pair( u, 0)]) = 1-xi-eta; + coefficients(i, coord2idx[std::make_pair(u + v, 0)]) = xi; + coefficients(i, coord2idx[std::make_pair(n, 0)]) = -xi; + coefficients(i, coord2idx[std::make_pair(n - v, v)]) = xi; + coefficients(i, coord2idx[std::make_pair(u, n - u)]) = eta; + coefficients(i, coord2idx[std::make_pair(0, n)]) = -eta; + coefficients(i, coord2idx[std::make_pair(0, u + v)]) = eta; + coefficients(i, coord2idx[std::make_pair(0, v)]) = 1 - xi - eta; + coefficients(i, coord2idx[std::make_pair(0, 0)]) = -(1 - xi - eta); + coefficients(i, coord2idx[std::make_pair(u, 0)]) = 1 - xi - eta; } coefficients.print("coefficients"); } incompleteBasis::incompleteBasis(int tag) -// If the element is complete, compute the incomplete basis anyway - : nodalBasis(ElementType::getType(ElementType::getParentType(tag), - ElementType::getOrder(tag), true)), - completeBasis(NULL), polyBasis(NULL) + // If the element is complete, compute the incomplete basis anyway + : nodalBasis(ElementType::getType(ElementType::getParentType(tag), + ElementType::getOrder(tag), true)), + completeBasis(NULL), polyBasis(NULL) { int tagComplete = ElementType::getType(parentType, order, false); - switch (parentType) { - case TYPE_LIN: - case TYPE_PNT: - case TYPE_QUA: - case TYPE_HEX: - polyBasis = new polynomialBasis(type); - break; - case TYPE_TET: - case TYPE_PRI: - case TYPE_PYR: - completeBasis = BasisFactory::getNodalBasis(tagComplete); - break; - case TYPE_TRI: - completeBasis = BasisFactory::getNodalBasis(tagComplete); - _computeCoefficientsTriangle(); - break; + switch(parentType) { + case TYPE_LIN: + case TYPE_PNT: + case TYPE_QUA: + case TYPE_HEX: polyBasis = new polynomialBasis(type); break; + case TYPE_TET: + case TYPE_PRI: + case TYPE_PYR: + completeBasis = BasisFactory::getNodalBasis(tagComplete); + break; + case TYPE_TRI: + completeBasis = BasisFactory::getNodalBasis(tagComplete); + _computeCoefficientsTriangle(); + break; } } -incompleteBasis::~incompleteBasis() -{ - delete polyBasis; -} +incompleteBasis::~incompleteBasis() { delete polyBasis; } void incompleteBasis::f(double u, double v, double w, double *sf) const { - if (polyBasis) polyBasis->f(u, v, w, sf); + if(polyBasis) + polyBasis->f(u, v, w, sf); else { double csf[1331]; completeBasis->f(u, v, w, csf); int szInc = getNumShapeFunctions(); - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { sf[i] = csf[i]; - for (int j = 0; j < coefficients.size1(); ++j) { - sf[i] += csf[szInc+j] * coefficients(j, i); + for(int j = 0; j < coefficients.size1(); ++j) { + sf[i] += csf[szInc + j] * coefficients(j, i); } } } } -void incompleteBasis::f(const fullMatrix<double> &coord, fullMatrix<double> &sf) const +void incompleteBasis::f(const fullMatrix<double> &coord, + fullMatrix<double> &sf) const { - if (polyBasis) polyBasis->f(coord, sf); + if(polyBasis) + polyBasis->f(coord, sf); else { completeBasis->f(coord, sf); int szInc = getNumShapeFunctions(); - for (int k = 0; k < sf.size1(); ++k) { - for (int i = 0; i < szInc; ++i) { - for (int j = 0; j < coefficients.size1(); ++j) { - sf(k, i) += sf(k, szInc+j) * coefficients(j, i); + for(int k = 0; k < sf.size1(); ++k) { + for(int i = 0; i < szInc; ++i) { + for(int j = 0; j < coefficients.size1(); ++j) { + sf(k, i) += sf(k, szInc + j) * coefficients(j, i); } } } @@ -115,16 +113,18 @@ void incompleteBasis::f(const fullMatrix<double> &coord, fullMatrix<double> &sf) } } -void incompleteBasis::df(const fullMatrix<double> &coord, fullMatrix<double> &dfm) const +void incompleteBasis::df(const fullMatrix<double> &coord, + fullMatrix<double> &dfm) const { - if (polyBasis) polyBasis->df(coord, dfm); + if(polyBasis) + polyBasis->df(coord, dfm); else { completeBasis->df(coord, dfm); int szInc = getNumShapeFunctions(); - for (int k = 0; k < dfm.size1(); ++k) { - for (int i = 0; i < szInc; ++i) { - for (int j = 0; j < coefficients.size1(); ++j) { - dfm(k, i) += dfm(k, szInc+j) * coefficients(j, i); + for(int k = 0; k < dfm.size1(); ++k) { + for(int i = 0; i < szInc; ++i) { + for(int j = 0; j < coefficients.size1(); ++j) { + dfm(k, i) += dfm(k, szInc + j) * coefficients(j, i); } } } @@ -134,41 +134,44 @@ void incompleteBasis::df(const fullMatrix<double> &coord, fullMatrix<double> &df void incompleteBasis::df(double u, double v, double w, double grads[][3]) const { - if (polyBasis) polyBasis->df(u, v, w, grads); + if(polyBasis) + polyBasis->df(u, v, w, grads); else { double cgrads[1331][3]; completeBasis->df(u, v, w, cgrads); int szInc = getNumShapeFunctions(); - for (int i = 0; i < szInc; ++i) { + for(int i = 0; i < szInc; ++i) { grads[i][0] = cgrads[i][0]; grads[i][1] = cgrads[i][1]; grads[i][2] = cgrads[i][2]; - for (int j = 0; j < coefficients.size1(); ++j) { - grads[i][0] = cgrads[szInc+j][0] * coefficients(j, i); - grads[i][1] = cgrads[szInc+j][1] * coefficients(j, i); - grads[i][2] = cgrads[szInc+j][2] * coefficients(j, i); + for(int j = 0; j < coefficients.size1(); ++j) { + grads[i][0] = cgrads[szInc + j][0] * coefficients(j, i); + grads[i][1] = cgrads[szInc + j][1] * coefficients(j, i); + grads[i][2] = cgrads[szInc + j][2] * coefficients(j, i); } } } } -void incompleteBasis::ddf(double u, double v, double w, double hess[][3][3]) const +void incompleteBasis::ddf(double u, double v, double w, + double hess[][3][3]) const { - if (polyBasis) polyBasis->ddf(u, v, w, hess); + if(polyBasis) + polyBasis->ddf(u, v, w, hess); else { double chess[1331][3][3]; completeBasis->ddf(u, v, w, chess); int szInc = getNumShapeFunctions(); - for (int i = 0; i < szInc; ++i) { - for (int k = 0; k < 3; ++k) { - for (int l = 0; l < 3; ++l) { + for(int i = 0; i < szInc; ++i) { + for(int k = 0; k < 3; ++k) { + for(int l = 0; l < 3; ++l) { hess[i][k][l] = chess[i][k][l]; } } - for (int j = 0; j < coefficients.size1(); ++j) { - for (int k = 0; k < 3; ++k) { - for (int l = 0; l < 3; ++l) { - hess[i][k][l] = chess[szInc+j][k][l] * coefficients(j, i); + for(int j = 0; j < coefficients.size1(); ++j) { + for(int k = 0; k < 3; ++k) { + for(int l = 0; l < 3; ++l) { + hess[i][k][l] = chess[szInc + j][k][l] * coefficients(j, i); } } } @@ -176,27 +179,29 @@ void incompleteBasis::ddf(double u, double v, double w, double hess[][3][3]) con } } -void incompleteBasis::dddf(double u, double v, double w, double third[][3][3][3]) const +void incompleteBasis::dddf(double u, double v, double w, + double third[][3][3][3]) const { - if (polyBasis) polyBasis->dddf(u, v, w, third); + if(polyBasis) + polyBasis->dddf(u, v, w, third); else { double cthird[1331][3][3][3]; completeBasis->dddf(u, v, w, cthird); int szInc = getNumShapeFunctions(); - for (int i = 0; i < szInc; ++i) { - for (int k = 0; k < 3; ++k) { - for (int l = 0; l < 3; ++l) { - for (int m = 0; m < 3; ++m) { + for(int i = 0; i < szInc; ++i) { + for(int k = 0; k < 3; ++k) { + for(int l = 0; l < 3; ++l) { + for(int m = 0; m < 3; ++m) { third[i][k][l][m] = cthird[i][k][l][m]; } } } - for (int j = 0; j < coefficients.size1(); ++j) { - for (int k = 0; k < 3; ++k) { - for (int l = 0; l < 3; ++l) { - for (int m = 0; m < 3; ++m) { + for(int j = 0; j < coefficients.size1(); ++j) { + for(int k = 0; k < 3; ++k) { + for(int l = 0; l < 3; ++l) { + for(int m = 0; m < 3; ++m) { third[i][k][l][m] = - cthird[szInc+j][k][l][m] * coefficients(j, i); + cthird[szInc + j][k][l][m] * coefficients(j, i); } } } diff --git a/Numeric/mathEvaluator.cpp b/Numeric/mathEvaluator.cpp index af77fc18979a2f8d9476c8297ad59caa0ec2b95e..ce7324471258960fadf6d037eb1b75d24c58cd4e 100644 --- a/Numeric/mathEvaluator.cpp +++ b/Numeric/mathEvaluator.cpp @@ -15,16 +15,15 @@ mathEvaluator::mathEvaluator(std::vector<std::string> &expressions, _expressions.resize(expressions.size()); _variables.resize(variables.size(), 0.); bool error = false; - for(unsigned int i = 0; i < expressions.size(); i++){ + for(unsigned int i = 0; i < expressions.size(); i++) { _expressions[i] = new smlib::mathex(); for(unsigned int j = 0; j < variables.size(); j++) _expressions[i]->addvar(variables[j], &_variables[j]); try { _expressions[i]->expression(expressions[i]); _expressions[i]->parse(); - } - catch(smlib::mathex::error& e) { - if(e.what() + expressions[i] != lastError){ + } catch(smlib::mathex::error &e) { + if(e.what() + expressions[i] != lastError) { lastError = e.what() + expressions[i]; Msg::Error(e.what()); std::string pos(_expressions[i]->stopposition(), ' '); @@ -35,7 +34,7 @@ mathEvaluator::mathEvaluator(std::vector<std::string> &expressions, error = true; } } - if(error){ + if(error) { for(unsigned int i = 0; i < _expressions.size(); i++) delete(_expressions[i]); _expressions.clear(); @@ -45,40 +44,39 @@ mathEvaluator::mathEvaluator(std::vector<std::string> &expressions, mathEvaluator::~mathEvaluator() { - for(unsigned int i = 0; i < _expressions.size(); i++) - delete(_expressions[i]); + for(unsigned int i = 0; i < _expressions.size(); i++) delete(_expressions[i]); } -bool mathEvaluator::eval(const std::vector<double> &values, std::vector<double> &res) +bool mathEvaluator::eval(const std::vector<double> &values, + std::vector<double> &res) { - if(values.size() != _variables.size()){ - Msg::Error("Given %d value(s) for %d variable(s)", values.size(), _variables.size()); + if(values.size() != _variables.size()) { + Msg::Error("Given %d value(s) for %d variable(s)", values.size(), + _variables.size()); return false; } - if(res.size() != _expressions.size()){ - Msg::Error("Given %d result(s) for %d expression(s)", res.size(), _expressions.size()); + if(res.size() != _expressions.size()) { + Msg::Error("Given %d result(s) for %d expression(s)", res.size(), + _expressions.size()); return false; } - for(unsigned int i = 0; i < values.size(); i++) - _variables[i] = values[i]; + for(unsigned int i = 0; i < values.size(); i++) _variables[i] = values[i]; - for(unsigned int i = 0; i < _expressions.size(); i++){ + for(unsigned int i = 0; i < _expressions.size(); i++) { try { res[i] = _expressions[i]->eval(); - } - catch(smlib::mathex::error& e) { + } catch(smlib::mathex::error &e) { Msg::Error(e.what()); double eps = 1.e-20; for(unsigned int j = 0; j < values.size(); j++) - _variables[j] = values[j] + eps; + _variables[j] = values[j] + eps; try { - res[i] = _expressions[i]->eval(); - } - catch(smlib::mathex::error& e2) { - Msg::Error(e2.what()); - return false; + res[i] = _expressions[i]->eval(); + } catch(smlib::mathex::error &e2) { + Msg::Error(e2.what()); + return false; } } } diff --git a/Numeric/mathEvaluator.h b/Numeric/mathEvaluator.h index c6875890836f38bd1d0efb79e3555555a0f0f493..e8664dfd95ef2d664f61599f2d9ce2a6b1149c40 100644 --- a/Numeric/mathEvaluator.h +++ b/Numeric/mathEvaluator.h @@ -15,11 +15,12 @@ #include "mathex.h" -class mathEvaluator{ - private: - std::vector<smlib::mathex*> _expressions; +class mathEvaluator { +private: + std::vector<smlib::mathex *> _expressions; std::vector<double> _variables; - public: + +public: // initialize one or more expressions depending on zero or more // variables. If an error occurs the vector of expressions is // cleared. @@ -33,8 +34,8 @@ class mathEvaluator{ #else -class mathEvaluator{ - public: +class mathEvaluator { +public: mathEvaluator(std::vector<std::string> &expressions, const std::vector<std::string> &variables) { @@ -42,7 +43,7 @@ class mathEvaluator{ "expressions"); expressions.clear(); } - ~mathEvaluator(){} + ~mathEvaluator() {} bool eval(const std::vector<double> &values, std::vector<double> &res) { return false; diff --git a/Numeric/miniBasis.cpp b/Numeric/miniBasis.cpp index c9b2bed70b46723d7d33a8e9e827cb82a9c6337e..10161fb728c02d82b7bae7b1a5e42579a345e108 100644 --- a/Numeric/miniBasis.cpp +++ b/Numeric/miniBasis.cpp @@ -23,10 +23,14 @@ miniBasisTri::miniBasisTri() closureRef = p1.closureRef; points = p1.points; points.resize(4, 2); - points(0, 0) = 0.; points(0, 1) = 0.; - points(1, 0) = 1.; points(1, 1) = 0.; - points(2, 0) = 0.; points(2, 1) = 1.; - points(3, 0) = 1./3; points(3, 1) = 1./3; + points(0, 0) = 0.; + points(0, 1) = 0.; + points(1, 0) = 1.; + points(1, 1) = 0.; + points(2, 0) = 0.; + points(2, 1) = 1.; + points(3, 0) = 1. / 3; + points(3, 1) = 1. / 3; /* monomials : 0 : 1 @@ -42,18 +46,28 @@ miniBasisTri::miniBasisTri() 3 : 0 0 0 1 -1 -1 : xy - x²y - xy² = (1 - x - y) x y */ monomials.resize(6, 2); - monomials(0, 0) = 0.; monomials(0, 1) = 0.; - monomials(1, 0) = 1.; monomials(1, 1) = 0.; - monomials(2, 0) = 0.; monomials(2, 1) = 1.; - monomials(3, 0) = 1.; monomials(3, 1) = 1.; - monomials(4, 0) = 2.; monomials(4, 1) = 1.; - monomials(5, 0) = 1.; monomials(5, 1) = 2.; + monomials(0, 0) = 0.; + monomials(0, 1) = 0.; + monomials(1, 0) = 1.; + monomials(1, 1) = 0.; + monomials(2, 0) = 0.; + monomials(2, 1) = 1.; + monomials(3, 0) = 1.; + monomials(3, 1) = 1.; + monomials(4, 0) = 2.; + monomials(4, 1) = 1.; + monomials(5, 0) = 1.; + monomials(5, 1) = 2.; coefficients.resize(4, 6); coefficients.setAll(0.); - coefficients(0, 0) = 1.; coefficients(0, 1) = -1.; coefficients(0, 2) = -1.; + coefficients(0, 0) = 1.; + coefficients(0, 1) = -1.; + coefficients(0, 2) = -1.; coefficients(1, 1) = 1.; coefficients(2, 2) = 1.; - coefficients(3, 3) = 1.; coefficients(3, 4) = -1.; coefficients(3, 5) = -1.; + coefficients(3, 3) = 1.; + coefficients(3, 4) = -1.; + coefficients(3, 5) = -1.; } miniBasisTet::miniBasisTet() @@ -72,10 +86,9 @@ miniBasisTet::miniBasisTet() } closureRef = p1.closureRef; points.resize(5, 3); - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 3; ++j) - points(i, j) = p1.points(i, j); - points(4, 0) = points(4, 1) = points(4, 2) = 1./4; + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 3; ++j) points(i, j) = p1.points(i, j); + points(4, 0) = points(4, 1) = points(4, 2) = 1. / 4; /* monomials : @@ -92,22 +105,45 @@ miniBasisTet::miniBasisTet() 1 : 0 1 0 0 0 0 0 0 : x 2 : 0 0 1 0 0 0 0 0 : y 3 : 0 0 0 1 0 0 0 0 : z - 4 : 0 0 0 0 1 -1 -1 -1 : xyz - x²yz - xy²z - xyz² = (1 - x - y - z) x y z + 4 : 0 0 0 0 1 -1 -1 -1 : xyz - x²yz - xy²z - xyz² = (1 - x - y - z) x y + z */ monomials.resize(8, 3); - monomials(0, 0) = 0.; monomials(0, 1) = 0.; monomials(0, 2) = 0.; - monomials(1, 0) = 1.; monomials(1, 1) = 0.; monomials(1, 2) = 0.; - monomials(2, 0) = 0.; monomials(2, 1) = 1.; monomials(2, 2) = 0.; - monomials(3, 0) = 0.; monomials(3, 1) = 0.; monomials(3, 2) = 1.; - monomials(4, 0) = 1.; monomials(4, 1) = 1.; monomials(4, 2) = 1.; - monomials(5, 0) = 2.; monomials(5, 1) = 1.; monomials(5, 2) = 1.; - monomials(6, 0) = 1.; monomials(6, 1) = 2.; monomials(6, 2) = 1.; - monomials(7, 0) = 1.; monomials(7, 1) = 1.; monomials(7, 2) = 2.; + monomials(0, 0) = 0.; + monomials(0, 1) = 0.; + monomials(0, 2) = 0.; + monomials(1, 0) = 1.; + monomials(1, 1) = 0.; + monomials(1, 2) = 0.; + monomials(2, 0) = 0.; + monomials(2, 1) = 1.; + monomials(2, 2) = 0.; + monomials(3, 0) = 0.; + monomials(3, 1) = 0.; + monomials(3, 2) = 1.; + monomials(4, 0) = 1.; + monomials(4, 1) = 1.; + monomials(4, 2) = 1.; + monomials(5, 0) = 2.; + monomials(5, 1) = 1.; + monomials(5, 2) = 1.; + monomials(6, 0) = 1.; + monomials(6, 1) = 2.; + monomials(6, 2) = 1.; + monomials(7, 0) = 1.; + monomials(7, 1) = 1.; + monomials(7, 2) = 2.; coefficients.resize(5, 8); coefficients.setAll(0.); - coefficients(0, 0) = 1.; coefficients(0, 1) = -1.; coefficients(0, 2) = -1.; coefficients(0, 3) = -1.; + coefficients(0, 0) = 1.; + coefficients(0, 1) = -1.; + coefficients(0, 2) = -1.; + coefficients(0, 3) = -1.; coefficients(1, 1) = 1.; coefficients(2, 2) = 1.; coefficients(3, 3) = 1.; - coefficients(4, 4) = 1.; coefficients(4, 5) = -1.; coefficients(4, 6) = -1.; coefficients(4, 7) = -1.; + coefficients(4, 4) = 1.; + coefficients(4, 5) = -1.; + coefficients(4, 6) = -1.; + coefficients(4, 7) = -1.; } diff --git a/Numeric/miniBasis.h b/Numeric/miniBasis.h index 3bc83f2bb0370d9e03e2f1fc87bcf4deb0ba77e8..b38344daa10a96056c73bd24866914d09b8c3fa2 100644 --- a/Numeric/miniBasis.h +++ b/Numeric/miniBasis.h @@ -11,12 +11,12 @@ // and mini have closure so... class miniBasisTri : public polynomialBasis { - public: - miniBasisTri(); +public: + miniBasisTri(); }; class miniBasisTet : public polynomialBasis { - public: - miniBasisTet(); +public: + miniBasisTet(); }; #endif diff --git a/Numeric/nodalBasis.cpp b/Numeric/nodalBasis.cpp index 5cffd1a36680bf68f94cc04ecc803f45580af720..827109bfce4324e63a855cc3a1269845fd1a137f 100644 --- a/Numeric/nodalBasis.cpp +++ b/Numeric/nodalBasis.cpp @@ -12,51 +12,96 @@ #include "MPrism.h" namespace ClosureGen { - inline double pow2(double x) - { - return x * x; - } + inline double pow2(double x) { return x * x; } void rotateHex(int iFace, int iRot, int iSign, double uI, double vI, double &uO, double &vO, double &wO) { - if(iSign < 0){ + if(iSign < 0) { double tmp = uI; uI = vI; vI = tmp; } - for(int i = 0; i < iRot; i++){ + for(int i = 0; i < iRot; i++) { double tmp = uI; uI = -vI; vI = tmp; } - switch(iFace){ - case 0: uO = vI; vO = uI; wO = -1; break; - case 1: uO = uI; vO = -1; wO = vI; break; - case 2: uO =-1; vO = vI; wO = uI; break; - case 3: uO = 1; vO = uI; wO = vI; break; - case 4: uO =-uI; vO = 1; wO = vI; break; - case 5: uO =uI; vO = vI; wO = 1; break; + switch(iFace) { + case 0: + uO = vI; + vO = uI; + wO = -1; + break; + case 1: + uO = uI; + vO = -1; + wO = vI; + break; + case 2: + uO = -1; + vO = vI; + wO = uI; + break; + case 3: + uO = 1; + vO = uI; + wO = vI; + break; + case 4: + uO = -uI; + vO = 1; + wO = vI; + break; + case 5: + uO = uI; + vO = vI; + wO = 1; + break; } } void rotateHexFull(int iFace, int iRot, int iSign, double uI, double vI, double wI, double &uO, double &vO, double &wO) { - switch(iFace){ - case 0: uO = uI; vO = vI; wO = wI; break; - case 1: uO = wI; vO = uI; wO = vI; break; - case 2: uO = vI; vO = wI; wO = uI; break; - case 3: uO = wI; vO = vI; wO = -uI; break; - case 4: uO = wI; vO = -uI; wO = -vI; break; - case 5: uO = vI; vO = uI; wO = -wI; break; - } - for(int i = 0; i < iRot; i++){ + switch(iFace) { + case 0: + uO = uI; + vO = vI; + wO = wI; + break; + case 1: + uO = wI; + vO = uI; + wO = vI; + break; + case 2: + uO = vI; + vO = wI; + wO = uI; + break; + case 3: + uO = wI; + vO = vI; + wO = -uI; + break; + case 4: + uO = wI; + vO = -uI; + wO = -vI; + break; + case 5: + uO = vI; + vO = uI; + wO = -wI; + break; + } + for(int i = 0; i < iRot; i++) { double tmp = uO; uO = -vO; vO = tmp; } - if(iSign<0){ + if(iSign < 0) { double tmp = uO; uO = vO; vO = tmp; @@ -66,22 +111,42 @@ namespace ClosureGen { void rotatePyr(int iFace, int iRot, int iSign, double uI, double vI, double &uO, double &vO, double &wO) { - if(iSign < 0){ + if(iSign < 0) { double tmp = uI; uI = vI; vI = tmp; } - for(int i = 0; i < iRot; i++){ + for(int i = 0; i < iRot; i++) { double tmp = uI; uI = -vI; vI = tmp; } - switch(iFace){ - case 0: uO = uI; vO = vI-1; wO = vI; break; - case 1: uO = vI-1; vO = -uI; wO = vI; break; - case 2: uO = 1-vI; vO = uI; wO = vI; break; - case 3: uO = -uI; vO = 1-vI; wO = vI; break; - case 4: uO = vI; vO = uI; wO = 0; break; + switch(iFace) { + case 0: + uO = uI; + vO = vI - 1; + wO = vI; + break; + case 1: + uO = vI - 1; + vO = -uI; + wO = vI; + break; + case 2: + uO = 1 - vI; + vO = uI; + wO = vI; + break; + case 3: + uO = -uI; + vO = 1 - vI; + wO = vI; + break; + case 4: + uO = vI; + vO = uI; + wO = 0; + break; } } @@ -101,12 +166,12 @@ namespace ClosureGen { closure.clear(); closure.resize(2); closure[0].push_back(0); - if(order != 0){ + if(order != 0) { closure[0].push_back(1); closure[1].push_back(1); } closure[1].push_back(0); - for(int i = 0; i < order - 1; i++){ + for(int i = 0; i < order - 1; i++) { closure[0].push_back(2 + i); closure[1].push_back(2 + order - 2 - i); } @@ -122,21 +187,20 @@ namespace ClosureGen { closure.resize((order + 1) * (order + 2) / 2); closure.type = ElementType::getType(TYPE_TRI, order, false); - switch(order){ - case 0: - closure[0] = 0; - break; + switch(order) { + case 0: closure[0] = 0; break; default: int face[4][3] = {{-3, -2, -1}, {1, -6, 4}, {-4, 5, 3}, {6, 2, -5}}; int order1node[4][3] = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2}, {3, 1, 2}}; - for(int i = 0; i < 3; ++i){ - int k = (3 + (iSign * i) + iRotate) % 3; //- iSign * iRotate + for(int i = 0; i < 3; ++i) { + int k = (3 + (iSign * i) + iRotate) % 3; //- iSign * iRotate closure[i] = order1node[iFace][k]; } - for(int i = 0; i < 3; ++i){ - int edgenumber = iSign * - face[iFace][(6 + i * iSign + (-1 + iSign) / 2 + iRotate) % 3]; //- iSign * iRotate - for(int k = 0; k < (order - 1); k++){ + for(int i = 0; i < 3; ++i) { + int edgenumber = + iSign * face[iFace][(6 + i * iSign + (-1 + iSign) / 2 + iRotate) % + 3]; //- iSign * iRotate + for(int k = 0; k < (order - 1); k++) { if(edgenumber > 0) closure[3 + i * (order - 1) + k] = 4 + (edgenumber - 1) * (order - 1) + k; @@ -149,18 +213,20 @@ namespace ClosureGen { int ti = 4 + 6 * (order - 1); int ndofff = (order - 3 + 2) * (order - 3 + 1) / 2; ti = ti + iFace * ndofff; - for(int k = 0; k < order / 3; k++){ + for(int k = 0; k < order / 3; k++) { int orderint = order - 3 - k * 3; - if(orderint > 0){ - for(int ci = 0; ci < 3 ; ci++){ - int shift = (3 + iSign * ci + iRotate) % 3; //- iSign * iRotate + if(orderint > 0) { + for(int ci = 0; ci < 3; ci++) { + int shift = (3 + iSign * ci + iRotate) % 3; //- iSign * iRotate closure[fi + ci] = ti + shift; } - fi = fi + 3; ti = ti + 3; - for(int l = 0; l < orderint - 1; l++){ - for(int ei = 0; ei < 3; ei++){ - int edgenumber = (6 + ei * iSign + (-1 + iSign) / 2 + iRotate) % 3; - //- iSign * iRotate + fi = fi + 3; + ti = ti + 3; + for(int l = 0; l < orderint - 1; l++) { + for(int ei = 0; ei < 3; ei++) { + int edgenumber = + (6 + ei * iSign + (-1 + iSign) / 2 + iRotate) % 3; + //- iSign * iRotate if(iSign > 0) closure[fi + ei * (orderint - 1) + l] = ti + edgenumber * (orderint - 1) + l; @@ -169,7 +235,8 @@ namespace ClosureGen { ti + (1 + edgenumber) * (orderint - 1) - 1 - l; } } - fi = fi + 3 * (orderint - 1); ti = ti + 3 * (orderint - 1); + fi = fi + 3 * (orderint - 1); + ti = ti + 3 * (orderint - 1); } else { closure[fi] = ti; @@ -182,71 +249,70 @@ namespace ClosureGen { } void generate2dEdgeClosureFull(nodalBasis::clCont &closure, - std::vector<int> &closureRef, - int order, int nNod, bool serendip) + std::vector<int> &closureRef, int order, + int nNod, bool serendip) { closure.clear(); - closure.resize(2*nNod); - closureRef.resize(2*nNod); + closure.resize(2 * nNod); + closureRef.resize(2 * nNod); int shift = 0; - for(int corder = order; corder>=0; corder -= (nNod == 3 ? 3 : 2)){ - if(corder == 0){ - for(int r = 0; r < nNod ; r++){ + for(int corder = order; corder >= 0; corder -= (nNod == 3 ? 3 : 2)) { + if(corder == 0) { + for(int r = 0; r < nNod; r++) { closure[r].push_back(shift); - closure[r+nNod].push_back(shift); + closure[r + nNod].push_back(shift); } break; } - for(int r = 0; r < nNod ; r++){ - for(int j = 0; j < nNod; j++){ + for(int r = 0; r < nNod; r++) { + for(int j = 0; j < nNod; j++) { closure[r].push_back(shift + (r + j) % nNod); closure[r + nNod].push_back(shift + (r - j + 1 + nNod) % nNod); } } shift += nNod; - int n = nNod*(corder-1); - for(int r = 0; r < nNod ; r++){ - for(int j = 0; j < n; j++){ + int n = nNod * (corder - 1); + for(int r = 0; r < nNod; r++) { + for(int j = 0; j < n; j++) { closure[r].push_back(shift + (j + (corder - 1) * r) % n); - closure[r + nNod].push_back(shift + (n - j - 1 + (corder - 1) * (r + 1)) % n); + closure[r + nNod].push_back(shift + + (n - j - 1 + (corder - 1) * (r + 1)) % n); } } shift += n; if(serendip) break; } - for(int r = 0; r < nNod*2 ; r++){ + for(int r = 0; r < nNod * 2; r++) { closure[r].type = ElementType::getType(TYPE_LIN, order); closureRef[r] = 0; } } - void addEdgeNodes(nodalBasis::clCont &closureFull, const int *edges, int order) + void addEdgeNodes(nodalBasis::clCont &closureFull, const int *edges, + int order) { - if(order < 2) - return; + if(order < 2) return; int numNodes = 0; - for(int i = 0; edges[i] >= 0; ++i){ + for(int i = 0; edges[i] >= 0; ++i) { numNodes = std::max(numNodes, edges[i] + 1); } - std::vector<std::vector<int> > nodes2edges - (numNodes, std::vector<int>(numNodes, -1)); - for(int i = 0; edges[i] >= 0; i += 2){ + std::vector<std::vector<int> > nodes2edges(numNodes, + std::vector<int>(numNodes, -1)); + for(int i = 0; edges[i] >= 0; i += 2) { nodes2edges[edges[i]][edges[i + 1]] = i; nodes2edges[edges[i + 1]][edges[i]] = i + 1; } - for(unsigned int iClosure = 0; iClosure < closureFull.size(); iClosure++){ + for(unsigned int iClosure = 0; iClosure < closureFull.size(); iClosure++) { std::vector<int> &cl = closureFull[iClosure]; - for(int iEdge = 0; edges[iEdge] >= 0; iEdge += 2){ - if(cl.empty()) - continue; + for(int iEdge = 0; edges[iEdge] >= 0; iEdge += 2) { + if(cl.empty()) continue; int n0 = cl[edges[iEdge]]; int n1 = cl[edges[iEdge + 1]]; int oEdge = nodes2edges[n0][n1]; - if(oEdge == -1) - Msg::Error("invalid p1 closure or invalid edges list"); - for(int i = 0 ; i < order - 1; i++) - cl.push_back(numNodes + oEdge/2 * (order - 1) + - ((oEdge % 2) ? order - 2 - i : i)); + if(oEdge == -1) Msg::Error("invalid p1 closure or invalid edges list"); + for(int i = 0; i < order - 1; i++) + cl.push_back(numNodes + oEdge / 2 * (order - 1) + + ((oEdge % 2) ? order - 2 - i : i)); } } } @@ -254,9 +320,9 @@ namespace ClosureGen { void generateFaceClosureTet(nodalBasis::clCont &closure, int order) { closure.clear(); - for(int iRotate = 0; iRotate < 3; iRotate++){ - for(int iSign = 1; iSign >= -1; iSign -= 2){ - for(int iFace = 0; iFace < 4; iFace++){ + for(int iRotate = 0; iRotate < 3; iRotate++) { + for(int iSign = 1; iSign >= -1; iSign -= 2) { + for(int iFace = 0; iFace < 4; iFace++) { nodalBasis::closure closure_face; getFaceClosureTet(iFace, iSign, iRotate, closure_face, order); closure.push_back(closure_face); @@ -266,42 +332,41 @@ namespace ClosureGen { } void generateFaceClosureTetFull(nodalBasis::clCont &closureFull, - std::vector<int> &closureRef, - int order, bool serendip) + std::vector<int> &closureRef, int order, + bool serendip) { closureFull.clear(); - //input : - static const short int faces[4][3] = {{0,1,2}, {0,3,1}, {0,2,3}, {3,2,1}}; - static const int edges[] = {0, 1, 1, 2, 2, 0, 3, 0, 3, 2, 3, 1, -1}; - static const int faceOrientation[6] = {0,1,2,5,3,4}; + // input : + static const short int faces[4][3] = { + {0, 1, 2}, {0, 3, 1}, {0, 2, 3}, {3, 2, 1}}; + static const int edges[] = {0, 1, 1, 2, 2, 0, 3, 0, 3, 2, 3, 1, -1}; + static const int faceOrientation[6] = {0, 1, 2, 5, 3, 4}; closureFull.resize(24); closureRef.resize(24); - for(int i = 0; i < 24; i ++) - closureRef[i] = 0; - if(order == 0){ - for(int i = 0; i < 24; i ++){ + for(int i = 0; i < 24; i++) closureRef[i] = 0; + if(order == 0) { + for(int i = 0; i < 24; i++) { closureFull[i].push_back(0); } return; } - //Mapping for the p1 nodes + // Mapping for the p1 nodes nodalBasis::clCont closure; generateFaceClosureTet(closure, 1); - for(unsigned int i = 0; i < closureFull.size(); i++){ + for(unsigned int i = 0; i < closureFull.size(); i++) { std::vector<int> &clFull = closureFull[i]; std::vector<int> &cl = closure[i]; clFull.resize(4, -1); closureRef[i] = 0; - for(unsigned int j = 0; j < cl.size(); j ++) - clFull[closure[0][j]] = cl[j]; - for(int j = 0; j < 4; j ++) + for(unsigned int j = 0; j < cl.size(); j++) clFull[closure[0][j]] = cl[j]; + for(int j = 0; j < 4; j++) if(clFull[j] == -1) clFull[j] = (6 - clFull[(j + 1) % 4] - clFull[(j + 2) % 4] - clFull[(j + 3) % 4]); } int nodes2Faces[4][4][4]; - for(int i = 0; i < 4; i++){ - for(int iRotate = 0; iRotate < 3; iRotate ++){ + for(int i = 0; i < 4; i++) { + for(int iRotate = 0; iRotate < 3; iRotate++) { short int n0 = faces[i][(3 - iRotate) % 3]; short int n1 = faces[i][(4 - iRotate) % 3]; short int n2 = faces[i][(5 - iRotate) % 3]; @@ -315,30 +380,31 @@ namespace ClosureGen { generate2dEdgeClosureFull(closureTriangles, closureTrianglesRef, order - 3, 3, false); addEdgeNodes(closureFull, edges, order); - for(unsigned int iClosure = 0; iClosure < closureFull.size(); iClosure++){ + for(unsigned int iClosure = 0; iClosure < closureFull.size(); iClosure++) { // faces std::vector<int> &cl = closureFull[iClosure]; - if(order >= 3){ - for(int iFace = 0; iFace < 4; iFace ++){ + if(order >= 3) { + for(int iFace = 0; iFace < 4; iFace++) { int n0 = cl[faces[iFace][0]]; int n1 = cl[faces[iFace][1]]; int n2 = cl[faces[iFace][2]]; short int id = nodes2Faces[n0][n1][n2]; - short int iTriClosure = faceOrientation [id % 6]; - short int idFace = id/6; + short int iTriClosure = faceOrientation[id % 6]; + short int idFace = id / 6; int nOnFace = closureTriangles[iTriClosure].size(); - for(int i = 0; i < nOnFace; i++){ + for(int i = 0; i < nOnFace; i++) { cl.push_back(4 + 6 * (order - 1) + idFace * nOnFace + closureTriangles[iTriClosure][i]); } } } } - if(order >= 4 && !serendip){ + if(order >= 4 && !serendip) { nodalBasis::clCont insideClosure; std::vector<int> fakeClosureRef; - generateFaceClosureTetFull(insideClosure, fakeClosureRef, order - 4, false); - for(unsigned int i = 0; i < closureFull.size(); i ++){ + generateFaceClosureTetFull(insideClosure, fakeClosureRef, order - 4, + false); + for(unsigned int i = 0; i < closureFull.size(); i++) { unsigned int shift = closureFull[i].size(); for(unsigned int j = 0; j < insideClosure[i].size(); j++) closureFull[i].push_back(insideClosure[i][j] + shift); @@ -371,24 +437,25 @@ namespace ClosureGen { bool serendip, const fullMatrix<double> &points) { closure.clear(); - const nodalBasis &fsFace = *BasisFactory::getNodalBasis - (ElementType::getType(TYPE_QUA, order, serendip)); - for(int iRotate = 0; iRotate < 4; iRotate++){ - for(int iSign = 1; iSign >= -1; iSign -= 2){ - for(int iFace = 0; iFace < 6; iFace++){ + const nodalBasis &fsFace = *BasisFactory::getNodalBasis( + ElementType::getType(TYPE_QUA, order, serendip)); + for(int iRotate = 0; iRotate < 4; iRotate++) { + for(int iSign = 1; iSign >= -1; iSign -= 2) { + for(int iFace = 0; iFace < 6; iFace++) { nodalBasis::closure cl; cl.type = fsFace.type; cl.resize(fsFace.points.size1()); - for(unsigned int iNode = 0; iNode < cl.size(); ++iNode){ - double u,v,w; + for(unsigned int iNode = 0; iNode < cl.size(); ++iNode) { + double u, v, w; rotateHex(iFace, iRotate, iSign, fsFace.points(iNode, 0), fsFace.points(iNode, 1), u, v, w); cl[iNode] = 0; double D = std::numeric_limits<double>::max(); - for(int jNode = 0; jNode < points.size1(); ++jNode){ - double d = pow2(points(jNode, 0) - u) + pow2(points(jNode, 1) - v) + - pow2(points(jNode, 2) - w); - if(d < D){ + for(int jNode = 0; jNode < points.size1(); ++jNode) { + double d = pow2(points(jNode, 0) - u) + + pow2(points(jNode, 1) - v) + + pow2(points(jNode, 2) - w); + if(d < D) { cl[iNode] = jNode; D = d; } @@ -401,27 +468,28 @@ namespace ClosureGen { } void generateFaceClosureHexFull(nodalBasis::clCont &closure, - std::vector<int> &closureRef, - int order, bool serendip, + std::vector<int> &closureRef, int order, + bool serendip, const fullMatrix<double> &points) { closure.clear(); int clId = 0; - for(int iRotate = 0; iRotate < 4; iRotate++){ - for(int iSign = 1; iSign >= -1; iSign -= 2){ - for(int iFace = 0; iFace < 6; iFace++){ + for(int iRotate = 0; iRotate < 4; iRotate++) { + for(int iSign = 1; iSign >= -1; iSign -= 2) { + for(int iFace = 0; iFace < 6; iFace++) { nodalBasis::closure cl; cl.resize(points.size1()); - for(int iNode = 0; iNode < points.size1(); ++iNode){ - double u,v,w; - rotateHexFull(iFace, iRotate, iSign, points(iNode, 0), points(iNode, 1), - points(iNode, 2), u, v, w); + for(int iNode = 0; iNode < points.size1(); ++iNode) { + double u, v, w; + rotateHexFull(iFace, iRotate, iSign, points(iNode, 0), + points(iNode, 1), points(iNode, 2), u, v, w); int J = 0; double D = std::numeric_limits<double>::max(); - for(int jNode = 0; jNode < points.size1(); ++jNode){ - double d = pow2(points(jNode, 0) - u) + pow2(points(jNode, 1) - v) + - pow2(points(jNode, 2) - w); - if(d < D){ + for(int jNode = 0; jNode < points.size1(); ++jNode) { + double d = pow2(points(jNode, 0) - u) + + pow2(points(jNode, 1) - v) + + pow2(points(jNode, 2) - w); + if(d < D) { J = jNode; D = d; } @@ -430,7 +498,7 @@ namespace ClosureGen { } closure.push_back(cl); closureRef.push_back(0); - clId ++; + clId++; } } } @@ -446,8 +514,9 @@ namespace ClosureGen { // Moreover, the numbering of the face interior nodes is coherent with the // numbering of the equivalent 2D element. This explains why this function // is so simple. - int nNodes = isTriangle ? (order-2)*(order-1)/2 : (order-1)*(order-1); - for(int i = 0; i < nNodes; ++i, ++idx, ++start){ + int nNodes = + isTriangle ? (order - 2) * (order - 1) / 2 : (order - 1) * (order - 1); + for(int i = 0; i < nNodes; ++i, ++idx, ++start) { closure[idx] = start; } } @@ -460,40 +529,43 @@ namespace ClosureGen { int start = idx; const int nCorner = isTriangle ? 3 : 4; - for(int i = 0; i < nCorner; ++i, ++idx){ + for(int i = 0; i < nCorner; ++i, ++idx) { closure[idx] = old[start + (nCorner + i * iSign + iRotate) % nCorner]; } const int &nEdge = nCorner; - for(int i = 0; i < nEdge; ++i){ - int iOldEdge = (nEdge + i * iSign + iRotate + (iSign==-1? -1 : 0)) % nEdge; - int startOldEdge = start + nCorner + iOldEdge * (order-1); - if(iSign > 0){ - for(int j = startOldEdge; j < startOldEdge+order-1; ++j, ++idx) + for(int i = 0; i < nEdge; ++i) { + int iOldEdge = + (nEdge + i * iSign + iRotate + (iSign == -1 ? -1 : 0)) % nEdge; + int startOldEdge = start + nCorner + iOldEdge * (order - 1); + if(iSign > 0) { + for(int j = startOldEdge; j < startOldEdge + order - 1; ++j, ++idx) closure[idx] = old[j]; } - else if(iSign < 0){ - for(int j = startOldEdge+order-2; j >= startOldEdge; --j, ++idx) + else if(iSign < 0) { + for(int j = startOldEdge + order - 2; j >= startOldEdge; --j, ++idx) closure[idx] = old[j]; } } if(isTriangle && order > 3) - reorderFaceClosure(iSign, iRotate, closure, idx, order-3, isTriangle); + reorderFaceClosure(iSign, iRotate, closure, idx, order - 3, isTriangle); else if(!isTriangle && order > 2) - reorderFaceClosure(iSign, iRotate, closure, idx, order-2, isTriangle); + reorderFaceClosure(iSign, iRotate, closure, idx, order - 2, isTriangle); } void getFaceClosurePrism(int iFace, int iSign, int iRotate, nodalBasis::closure &closure, int order) { closure.clear(); - bool isTriangle = iFace<2; + bool isTriangle = iFace < 2; if(isTriangle && iRotate > 2) return; - closure.type = ElementType::getType(isTriangle ? TYPE_TRI : TYPE_QUA, order); + closure.type = + ElementType::getType(isTriangle ? TYPE_TRI : TYPE_QUA, order); - int nNodes = isTriangle ? (order+1)*(order+2)/2 : (order+1)*(order+1); + int nNodes = + isTriangle ? (order + 1) * (order + 2) / 2 : (order + 1) * (order + 1); closure.resize(nNodes); - if(order == 0){ + if(order == 0) { closure[0] = 0; return; } @@ -501,35 +573,34 @@ namespace ClosureGen { // map edge number to the nodes number int *edge2nodes[9]; int n = 6; - for(int i = 0; i < 9; ++i){ - edge2nodes[i] = new int[order-1]; - for(int k = 0; k < order-1; ++k, ++n) - edge2nodes[i][k] = n; + for(int i = 0; i < 9; ++i) { + edge2nodes[i] = new int[order - 1]; + for(int k = 0; k < order - 1; ++k, ++n) edge2nodes[i][k] = n; } // fill corner node number const int nCorner = isTriangle ? 3 : 4; - for(int i = 0; i < nCorner; ++i){ + for(int i = 0; i < nCorner; ++i) { closure[i] = MPrism::faces_prism(iFace, i); } // fill high-order nodes number - if(order > 1){ + if(order > 1) { int idx = nCorner; const int &nEdge = nCorner; // fill edge nodes number - for(int i = 0; i < nEdge; ++i){ + for(int i = 0; i < nEdge; ++i) { int edge = MPrism::faceClosureEdge2edge(iFace, i); - if(edge > 0){ - edge = edge-1; - for(int k = 0; k < order-1; ++k, ++idx){ + if(edge > 0) { + edge = edge - 1; + for(int k = 0; k < order - 1; ++k, ++idx) { closure[idx] = edge2nodes[edge][k]; } } - else if(edge < 0){ - edge = -edge-1; - for(int k = order-2; k >= 0; --k, ++idx){ + else if(edge < 0) { + edge = -edge - 1; + for(int k = order - 2; k >= 0; --k, ++idx) { closure[idx] = edge2nodes[edge][k]; } } @@ -537,8 +608,9 @@ namespace ClosureGen { for(int i = 0; i < 9; ++i) delete edge2nodes[i]; // Numbering of nodes inside the face start at - int start = 6 + 9*(order-1) + std::min(iFace, 2) * (order-2)*(order-1)/2 + - std::max(iFace-2, 0) * (order-1)*(order-1); + int start = 6 + 9 * (order - 1) + + std::min(iFace, 2) * (order - 2) * (order - 1) / 2 + + std::max(iFace - 2, 0) * (order - 1) * (order - 1); // fill interior nodes number fillInteriorFaceNodes(closure, idx, order, isTriangle, start); @@ -550,9 +622,9 @@ namespace ClosureGen { void generateFaceClosurePrism(nodalBasis::clCont &closure, int order) { closure.clear(); - for(int iRotate = 0; iRotate < 4; iRotate++){ - for(int iSign = 1; iSign >= -1; iSign -= 2){ - for(int iFace = 0; iFace < 5; iFace++){ + for(int iRotate = 0; iRotate < 4; iRotate++) { + for(int iSign = 1; iSign >= -1; iSign -= 2) { + for(int iFace = 0; iFace < 5; iFace++) { nodalBasis::closure closure_face; getFaceClosurePrism(iFace, iSign, iRotate, closure_face, order); closure.push_back(closure_face); @@ -570,69 +642,66 @@ namespace ClosureGen { closureRef.resize(40); generateFaceClosurePrism(closure, 1); int ref3 = -1, ref4a = -1, ref4b = -1; - for(unsigned int i = 0; i < closure.size(); i++){ + for(unsigned int i = 0; i < closure.size(); i++) { std::vector<int> &clFull = closureFull[i]; std::vector<int> &cl = closure[i]; - if(cl.size() == 0) - continue; + if(cl.size() == 0) continue; clFull.resize(6, -1); - int &ref = cl.size() == 3 ? ref3 : (cl[0] / 3 + cl[1] / 3) % 2 ? ref4b : ref4a; - if(ref == -1) - ref = i; + int &ref = + cl.size() == 3 ? ref3 : (cl[0] / 3 + cl[1] / 3) % 2 ? ref4b : ref4a; + if(ref == -1) ref = i; closureRef[i] = ref; - for(unsigned int j = 0; j < cl.size(); j ++) + for(unsigned int j = 0; j < cl.size(); j++) clFull[closure[ref][j]] = cl[j]; - for(int j = 0; j < 6; j ++){ - if(clFull[j] == -1){ + for(int j = 0; j < 6; j++) { + if(clFull[j] == -1) { int k = ((j / 3) + 1) % 2 * 3; int sum = (clFull[k + (j + 1) % 3] + clFull[k + (j + 2) % 3]); clFull[j] = ((sum / 6 + 1) % 2) * 3 + (12 - sum) % 3; } } } - static const int edges[] = {0, 1, 0, 2, 0, 3, 1, 2, 1, 4, 2, 5, - 3, 4, 3, 5, 4, 5, -1}; + static const int edges[] = {0, 1, 0, 2, 0, 3, 1, 2, 1, 4, + 2, 5, 3, 4, 3, 5, 4, 5, -1}; addEdgeNodes(closureFull, edges, order); - if(order < 2) - return; + if(order < 2) return; // face center nodes for p2 prism - static const int faces[5][4] = {{0, 2, 1, -1}, {3, 4, 5, -1}, {0, 1, 4, 3}, - {0, 3, 5, 2}, {1, 2, 5, 4}}; + static const int faces[5][4] = { + {0, 2, 1, -1}, {3, 4, 5, -1}, {0, 1, 4, 3}, {0, 3, 5, 2}, {1, 2, 5, 4}}; - if(order == 2){ + if(order == 2) { int nextFaceNode = 15; int numFaces = 5; int numFaceNodes = 4; - std::map<int,int> nodeSum2Face; - for(int iFace = 0; iFace < numFaces ; iFace ++){ + std::map<int, int> nodeSum2Face; + for(int iFace = 0; iFace < numFaces; iFace++) { int nodeSum = 0; - for(int iNode = 0; iNode < numFaceNodes; iNode++ ){ + for(int iNode = 0; iNode < numFaceNodes; iNode++) { nodeSum += faces[iFace][iNode]; } nodeSum2Face[nodeSum] = iFace; } - for(unsigned int i = 0; i < closureFull.size(); i++ ){ - if(closureFull[i].empty()) - continue; - for(int iFace = 0; iFace < numFaces; iFace++ ){ + for(unsigned int i = 0; i < closureFull.size(); i++) { + if(closureFull[i].empty()) continue; + for(int iFace = 0; iFace < numFaces; iFace++) { int nodeSum = 0; for(int iNode = 0; iNode < numFaceNodes; iNode++) - nodeSum += faces[iFace][iNode] < 0 ? faces[iFace][iNode] : - closureFull[i][ faces[iFace][iNode] ]; - std::map<int,int>::iterator it = nodeSum2Face.find(nodeSum); - if(it == nodeSum2Face.end() ) - Msg::Error("Prism face not found"); + nodeSum += faces[iFace][iNode] < 0 ? + faces[iFace][iNode] : + closureFull[i][faces[iFace][iNode]]; + std::map<int, int>::iterator it = nodeSum2Face.find(nodeSum); + if(it == nodeSum2Face.end()) Msg::Error("Prism face not found"); int mappedFaceId = it->second; - if(mappedFaceId > 1){ + if(mappedFaceId > 1) { closureFull[i].push_back(nextFaceNode + mappedFaceId - 2); } } } } else { - Msg::Error("FaceClosureFull not implemented for prisms of order %d",order); + Msg::Error("FaceClosureFull not implemented for prisms of order %d", + order); } - } void generateFaceClosurePyr(nodalBasis::clCont &closure, int order, @@ -644,27 +713,28 @@ namespace ClosureGen { const nodalBasis *fsFaceTri = BasisFactory::getNodalBasis(typeTri); const nodalBasis *fsFaceQua = BasisFactory::getNodalBasis(typeQua); - for(int iRotate = 0; iRotate < 4; iRotate++){ - for(int iSign = 1; iSign >= -1; iSign -= 2){ - for(int iFace = 0; iFace < 5; iFace++){ + for(int iRotate = 0; iRotate < 4; iRotate++) { + for(int iSign = 1; iSign >= -1; iSign -= 2) { + for(int iFace = 0; iFace < 5; iFace++) { const nodalBasis *fsFace; - if (iFace < 4) + if(iFace < 4) fsFace = fsFaceTri; else fsFace = fsFaceQua; nodalBasis::closure cl; cl.type = fsFace->type; cl.resize(fsFace->points.size1()); - for(unsigned int iNode = 0; iNode < cl.size(); ++iNode){ - double u,v,w; + for(unsigned int iNode = 0; iNode < cl.size(); ++iNode) { + double u, v, w; rotatePyr(iFace, iRotate, iSign, fsFace->points(iNode, 0), fsFace->points(iNode, 1), u, v, w); cl[iNode] = 0; double D = std::numeric_limits<double>::max(); - for(int jNode = 0; jNode < points.size1(); ++jNode){ - double d = pow2(points(jNode, 0) - u) + pow2(points(jNode, 1) - v) + + for(int jNode = 0; jNode < points.size1(); ++jNode) { + double d = pow2(points(jNode, 0) - u) + + pow2(points(jNode, 1) - v) + pow2(points(jNode, 2) - w); - if(d < D){ + if(d < D) { cl[iNode] = jNode; D = d; } @@ -676,20 +746,22 @@ namespace ClosureGen { } } - void generate2dEdgeClosure(nodalBasis::clCont &closure, int order, int nNod = 3) + void generate2dEdgeClosure(nodalBasis::clCont &closure, int order, + int nNod = 3) { closure.clear(); - closure.resize(2*nNod); - for(int j = 0; j < nNod ; j++){ + closure.resize(2 * nNod); + for(int j = 0; j < nNod; j++) { closure[j].push_back(j); - closure[j].push_back((j+1)%nNod); - closure[nNod+j].push_back((j+1)%nNod); - closure[nNod+j].push_back(j); - for(int i=0; i < order-1; i++){ - closure[j].push_back(nNod + (order-1)*j + i); - closure[nNod+j].push_back(nNod + (order-1)*(j+1) -i -1); + closure[j].push_back((j + 1) % nNod); + closure[nNod + j].push_back((j + 1) % nNod); + closure[nNod + j].push_back(j); + for(int i = 0; i < order - 1; i++) { + closure[j].push_back(nNod + (order - 1) * j + i); + closure[nNod + j].push_back(nNod + (order - 1) * (j + 1) - i - 1); } - closure[j].type = closure[nNod+j].type = ElementType::getType(TYPE_LIN, order); + closure[j].type = closure[nNod + j].type = + ElementType::getType(TYPE_LIN, order); } } @@ -697,12 +769,12 @@ namespace ClosureGen { { closure.clear(); closure.resize(nb); - for(int i=0; i < nb; i++){ + for(int i = 0; i < nb; i++) { closure[i].push_back(0); closure[i].type = MSH_PNT; } } -} +} // namespace ClosureGen nodalBasis::nodalBasis(int tag) { @@ -713,21 +785,21 @@ nodalBasis::nodalBasis(int tag) serendip = ElementType::getSerendipity(tag) > 1; dimension = ElementType::getDimension(tag); - switch(parentType){ - case TYPE_PNT : + switch(parentType) { + case TYPE_PNT: numFaces = 1; points = gmshGeneratePointsLine(0); break; - case TYPE_LIN : + case TYPE_LIN: numFaces = 2; points = gmshGeneratePointsLine(order); generate1dVertexClosure(closures, order); generate1dVertexClosureFull(fullClosures, closureRef, order); break; - case TYPE_TRI : + case TYPE_TRI: numFaces = 3; points = gmshGeneratePointsTriangle(order, serendip); - if(order == 0){ + if(order == 0) { generateClosureOrder0(closures, 6); generateClosureOrder0(fullClosures, 6); closureRef.resize(6, 0); @@ -737,10 +809,10 @@ nodalBasis::nodalBasis(int tag) generate2dEdgeClosureFull(fullClosures, closureRef, order, 3, serendip); } break; - case TYPE_QUA : + case TYPE_QUA: numFaces = 4; points = gmshGeneratePointsQuadrangle(order, serendip); - if(order == 0){ + if(order == 0) { generateClosureOrder0(closures, 8); generateClosureOrder0(fullClosures, 8); closureRef.resize(8, 0); @@ -750,11 +822,11 @@ nodalBasis::nodalBasis(int tag) generate2dEdgeClosureFull(fullClosures, closureRef, order, 4, serendip); } break; - case TYPE_TET : + case TYPE_TET: numFaces = 4; points = gmshGeneratePointsTetrahedron(order, serendip); - if(order == 0){ - generateClosureOrder0(closures,24); + if(order == 0) { + generateClosureOrder0(closures, 24); generateClosureOrder0(fullClosures, 24); closureRef.resize(24, 0); } @@ -763,12 +835,12 @@ nodalBasis::nodalBasis(int tag) generateFaceClosureTetFull(fullClosures, closureRef, order, serendip); } break; - case TYPE_PRI : + case TYPE_PRI: numFaces = 5; points = gmshGeneratePointsPrism(order, serendip); - if(order == 0){ - generateClosureOrder0(closures,48); - generateClosureOrder0(fullClosures,48); + if(order == 0) { + generateClosureOrder0(closures, 48); + generateClosureOrder0(fullClosures, 48); closureRef.resize(48, 0); } else { @@ -776,13 +848,14 @@ nodalBasis::nodalBasis(int tag) generateFaceClosurePrismFull(fullClosures, closureRef, order); } break; - case TYPE_HEX : + case TYPE_HEX: numFaces = 6; points = gmshGeneratePointsHexahedron(order, serendip); generateFaceClosureHex(closures, order, serendip, points); - generateFaceClosureHexFull(fullClosures, closureRef, order, serendip, points); + generateFaceClosureHexFull(fullClosures, closureRef, order, serendip, + points); break; - case TYPE_PYR : + case TYPE_PYR: numFaces = 5; points = gmshGeneratePointsPyramid(order, serendip); generateFaceClosurePyr(closures, order, serendip, points); @@ -792,12 +865,12 @@ nodalBasis::nodalBasis(int tag) void nodalBasis::getReferenceNodesForBezier(fullMatrix<double> &nodes) const { - if(parentType != TYPE_PYR && !serendip){ + if(parentType != TYPE_PYR && !serendip) { nodes = points; } else { const bool serendipSpace = false; - if(parentType != TYPE_PYR){ + if(parentType != TYPE_PYR) { FuncSpaceData data(true, type, order, &serendipSpace); gmshGeneratePoints(data, nodes); } @@ -808,55 +881,58 @@ void nodalBasis::getReferenceNodesForBezier(fullMatrix<double> &nodes) const } } -bool nodalBasis::forwardTransformation(const fullMatrix<double>& nodes, - fullMatrix<double>& projection, - int elementType) const { - - if (elementType != -1 && elementType != type) { +bool nodalBasis::forwardTransformation(const fullMatrix<double> &nodes, + fullMatrix<double> &projection, + int elementType) const +{ + if(elementType != -1 && elementType != type) { std::cout << "Incorrect element type " << std::endl; return false; } - if (nodes.size1() != points.size1()) return false; - - projection.resize(nodes.size1(),points.size1()); - f(nodes,projection); - + if(nodes.size1() != points.size1()) return false; + + projection.resize(nodes.size1(), points.size1()); + f(nodes, projection); + projection.invertInPlace(); // projection.transposeInPlace(); return true; } - -bool nodalBasis::forwardRenumbering(const fullMatrix<double>& nodes,int* renum, - int elementType) const { - - if (nodes.size1() != points.size1()) { - std::cout << "Non-matching node counts " - << nodes.size1() << " vs " +bool nodalBasis::forwardRenumbering(const fullMatrix<double> &nodes, int *renum, + int elementType) const +{ + if(nodes.size1() != points.size1()) { + std::cout << "Non-matching node counts " << nodes.size1() << " vs " << points.size1() << std::endl; return false; } - + double tol = 1e-10; fullMatrix<double> tfo; - if (!forwardTransformation(nodes,tfo, elementType)) { + if(!forwardTransformation(nodes, tfo, elementType)) { std::cout << "Could not find forward transformation " << std::endl; return false; } // tfo.print("Projection matrix","%1.f"); - - for (int i=0;i<nodes.size1();i++) { + + for(int i = 0; i < nodes.size1(); i++) { int idx = -1; int nbOnes = 0; int nbZeroes = 0; - for (int j=0;j<nodes.size1();j++) { - if (fabs(tfo(i,j)-1.0) < tol) {idx = j; nbOnes++;} - if (fabs(tfo(i,j)) < tol) {nbZeroes++;} + for(int j = 0; j < nodes.size1(); j++) { + if(fabs(tfo(i, j) - 1.0) < tol) { + idx = j; + nbOnes++; + } + if(fabs(tfo(i, j)) < tol) { + nbZeroes++; + } } - if (nbOnes != 1 ) return false; - if (nbZeroes != nodes.size1() - 1) return false; + if(nbOnes != 1) return false; + if(nbZeroes != nodes.size1() - 1) return false; renum[i] = idx; } diff --git a/Numeric/nodalBasis.h b/Numeric/nodalBasis.h index 8df4e60505477a12d64435eaed530798b9d6536d..c4b1838aea62978b116e02132ba99886d02bbbbd 100644 --- a/Numeric/nodalBasis.h +++ b/Numeric/nodalBasis.h @@ -10,7 +10,7 @@ #include "GmshDefines.h" class nodalBasis { - public: +public: int type, parentType, order, dimension, numFaces; bool serendip; fullMatrix<double> points; @@ -19,35 +19,35 @@ class nodalBasis { nodalBasis(int tag); virtual ~nodalBasis() {} virtual int getNumShapeFunctions() const = 0; - void getReferenceNodes(fullMatrix<double> &nodes) const - { - nodes = points; - } - const fullMatrix<double>& getReferenceNodes() const - { - return points; - } + void getReferenceNodes(fullMatrix<double> &nodes) const { nodes = points; } + const fullMatrix<double> &getReferenceNodes() const { return points; } - // compute the matrix that projects the provided points on the current control points - bool forwardTransformation(const fullMatrix<double>& otherPoints, - fullMatrix<double>& projection, - int elementType=-1) const; + // compute the matrix that projects the provided points on the current control + // points + bool forwardTransformation(const fullMatrix<double> &otherPoints, + fullMatrix<double> &projection, + int elementType = -1) const; - // compute the renumbering vector to map the provided points on the current control points - bool forwardRenumbering(const fullMatrix<double>& otherPoints,int* renum, - int elemenType=-1) const; + // compute the renumbering vector to map the provided points on the current + // control points + bool forwardRenumbering(const fullMatrix<double> &otherPoints, int *renum, + int elemenType = -1) const; void getReferenceNodesForBezier(fullMatrix<double> &nodes) const; // Basis functions & gradients evaluation virtual void f(double u, double v, double w, double *sf) const = 0; - virtual void f(const fullMatrix<double> &coord, fullMatrix<double> &sf) const = 0; + virtual void f(const fullMatrix<double> &coord, + fullMatrix<double> &sf) const = 0; virtual void df(double u, double v, double w, double grads[][3]) const = 0; - virtual void df(const fullMatrix<double> &coord, fullMatrix<double> &dfm) const = 0; - virtual void ddf(double u, double v, double w, double grads[][3][3]) const { + virtual void df(const fullMatrix<double> &coord, + fullMatrix<double> &dfm) const = 0; + virtual void ddf(double u, double v, double w, double grads[][3][3]) const + { Msg::Error("ddf not implemented for this basis"); } - virtual void dddf(double u, double v, double w, double grads[][3][3][3]) const { + virtual void dddf(double u, double v, double w, double grads[][3][3][3]) const + { Msg::Error("dddf not implemented for this basis"); } @@ -59,7 +59,7 @@ class nodalBasis { // considered face becomes the closureRef[i]-th face (the first triangle or // the first quad face) class closure : public std::vector<int> { - public: + public: int type; }; typedef std::vector<closure> clCont; @@ -86,7 +86,8 @@ inline int nodalBasis::getClosureId(int iFace, int iSign, int iRot) const return iFace + numFaces * (iSign == 1 ? 0 : 1) + 2 * numFaces * iRot; } -inline void nodalBasis::breakClosureId(int i, int &iFace, int &iSign, int &iRot) const +inline void nodalBasis::breakClosureId(int i, int &iFace, int &iSign, + int &iRot) const { iFace = i % numFaces; i = (i - iFace) / numFaces; diff --git a/Numeric/orthogonalBasis.cpp b/Numeric/orthogonalBasis.cpp index a12023c6ddf6a11ce8c3577124d71f8c209683c3..5277c25dbac1132d31825f0556712c327968d2b8 100644 --- a/Numeric/orthogonalBasis.cpp +++ b/Numeric/orthogonalBasis.cpp @@ -9,93 +9,89 @@ #include "FuncSpaceData.h" #include "Numeric.h" - orthogonalBasis::orthogonalBasis(const FuncSpaceData &_data) - : _type(_data.elementType()), _order(_data.spaceOrder()) -{} + : _type(_data.elementType()), _order(_data.spaceOrder()) +{ +} void orthogonalBasis::f(double u, double v, double w, double *sf) const { static double sf0[100]; static double sf1[100]; int k = 0; - switch (_type) { - case TYPE_LIN: - LegendrePolynomials::f(_order, u, sf); - return; - case TYPE_TRI: - if (u >= 1.) { - for (int k = 0; k <= _order; ++k) { - sf[k] = k+1; - } - for (int k = _order; k < (_order + 1) * (_order + 2) / 2; ++k) { - sf[k] = 0; - } - return; + switch(_type) { + case TYPE_LIN: LegendrePolynomials::f(_order, u, sf); return; + case TYPE_TRI: + if(u >= 1.) { + for(int k = 0; k <= _order; ++k) { + sf[k] = k + 1; } - LegendrePolynomials::f(_order, 2*v/(1-u)-1, sf0); - for (int i = 0; i <= _order; ++i) { - JacobiPolynomials::f(_order-i, 2*i+1, 0, 2*u-1, sf1); - double coeff = pow_int(1-u, i); - for (int j = 0; j <= _order-i; ++j) { - sf1[j] *= coeff; - } - for (int j = 0; j <= _order-i; ++j) { - sf[k++] = sf0[i] * sf1[j]; - } + for(int k = _order; k < (_order + 1) * (_order + 2) / 2; ++k) { + sf[k] = 0; } return; - case TYPE_QUA: - LegendrePolynomials::f(_order, u, sf0); - LegendrePolynomials::f(_order, v, sf1); - for (int i = 0; i <= _order; ++i) { - for (int j = 0; j <= _order; ++j) { - sf[k++] = sf0[i] * sf1[j]; - } + } + LegendrePolynomials::f(_order, 2 * v / (1 - u) - 1, sf0); + for(int i = 0; i <= _order; ++i) { + JacobiPolynomials::f(_order - i, 2 * i + 1, 0, 2 * u - 1, sf1); + double coeff = pow_int(1 - u, i); + for(int j = 0; j <= _order - i; ++j) { + sf1[j] *= coeff; } - return; + for(int j = 0; j <= _order - i; ++j) { + sf[k++] = sf0[i] * sf1[j]; + } + } + return; + case TYPE_QUA: + LegendrePolynomials::f(_order, u, sf0); + LegendrePolynomials::f(_order, v, sf1); + for(int i = 0; i <= _order; ++i) { + for(int j = 0; j <= _order; ++j) { + sf[k++] = sf0[i] * sf1[j]; + } + } + return; } } void orthogonalBasis::integralfSquared(double *val) const { int k = 0; - switch (_type) { - case TYPE_LIN: - for (int i = 0; i <= _order; ++i) { - val[i] = 2. / (1 + 2*i); - } - return; - case TYPE_TRI: - for (int i = 0; i <= _order; ++i) { - for (int j = 0; j <= _order-i; ++j) { - val[k++] = .5 / (1 + i+j) / (1 + 2*i); - } + switch(_type) { + case TYPE_LIN: + for(int i = 0; i <= _order; ++i) { + val[i] = 2. / (1 + 2 * i); + } + return; + case TYPE_TRI: + for(int i = 0; i <= _order; ++i) { + for(int j = 0; j <= _order - i; ++j) { + val[k++] = .5 / (1 + i + j) / (1 + 2 * i); } - return; - case TYPE_QUA: - for (int i = 0; i <= _order; ++i) { - for (int j = 0; j <= _order; ++j) { - val[k++] = 4. / (1 + 2*i) / (1 + 2*j); - } + } + return; + case TYPE_QUA: + for(int i = 0; i <= _order; ++i) { + for(int j = 0; j <= _order; ++j) { + val[k++] = 4. / (1 + 2 * i) / (1 + 2 * j); } + } } } - namespace LegendrePolynomials { void f(int n, double u, double *val) { val[0] = 1; - for (int i = 0; i < n; i++) { - + for(int i = 0; i < n; i++) { double a1i = i + 1; double a3i = 2. * i + 1; double a4i = i; val[i + 1] = a3i * u * val[i]; - if (i > 0) val[i + 1] -= a4i * val[i - 1]; + if(i > 0) val[i + 1] -= a4i * val[i - 1]; val[i + 1] /= a1i; } } @@ -103,20 +99,21 @@ namespace LegendrePolynomials { void fc(int n, double u, double *val) { f(n, u, val); - for (int i = 2; i < n + 1; ++i) { - if (i % 2) val[i] -= u; - else val[i] -= 1; + for(int i = 2; i < n + 1; ++i) { + if(i % 2) + val[i] -= u; + else + val[i] -= 1; } } void df(int n, double u, double *val) { // Indeterminate form for u == -1 and u == 1 - if ((u == 1.) || (u == -1.)) { - for (int k = 0; k <= n; k++) val[k] = 0.5 * k * (k + 1); - if ((u == -1.) && (n >= 2)) - for (int k = 2; k <= n; k += 2) - val[k] = -val[k]; + if((u == 1.) || (u == -1.)) { + for(int k = 0; k <= n; k++) val[k] = 0.5 * k * (k + 1); + if((u == -1.) && (n >= 2)) + for(int k = 2; k <= n; k += 2) val[k] = -val[k]; return; } @@ -130,34 +127,37 @@ namespace LegendrePolynomials { val[0] = 0; double g2 = (1. - u * u); - // Values of the derivative for orders > 1 computed from the values of the polynomials - for (int i = 1; i <= n; i++) { + // Values of the derivative for orders > 1 computed from the values of the + // polynomials + for(int i = 1; i <= n; i++) { double g1 = -u * i; double g0 = (double)i; val[i] = (g1 * tmp[i] + g0 * tmp[i - 1]) / g2; } } -} +} // namespace LegendrePolynomials namespace JacobiPolynomials { void f(int n, double alpha, double beta, double u, double *val) { const double alphaPlusBeta = alpha + beta; - const double a2MinusB2 = alpha*alpha - beta*beta; + const double a2MinusB2 = alpha * alpha - beta * beta; val[0] = 1.; - if (n>=1) val[1] = 0.5*(2.*(alpha+1.) + (alphaPlusBeta + 2.)*(u-1.)); - - for (int i=1;i<n;i++) { + if(n >= 1) + val[1] = 0.5 * (2. * (alpha + 1.) + (alphaPlusBeta + 2.) * (u - 1.)); - double ii = (double) i; - double twoI = 2.*ii; + for(int i = 1; i < n; i++) { + double ii = (double)i; + double twoI = 2. * ii; - double a1i = 2.*(ii+1.)*(ii+alphaPlusBeta+1.)*(twoI+alphaPlusBeta); - double a2i = (twoI+alphaPlusBeta+1.)*(a2MinusB2); - double a3i = Pochhammer(twoI+alphaPlusBeta,3); - double a4i = 2.*(ii+alpha)*(ii+beta)*(twoI+alphaPlusBeta+2.); + double a1i = + 2. * (ii + 1.) * (ii + alphaPlusBeta + 1.) * (twoI + alphaPlusBeta); + double a2i = (twoI + alphaPlusBeta + 1.) * (a2MinusB2); + double a3i = Pochhammer(twoI + alphaPlusBeta, 3); + double a4i = + 2. * (ii + alpha) * (ii + beta) * (twoI + alphaPlusBeta + 2.); - val[i+1] = ((a2i + a3i * u)* val[i] - a4i * val[i-1])/a1i; + val[i + 1] = ((a2i + a3i * u) * val[i] - a4i * val[i - 1]) / a1i; } } @@ -167,21 +167,23 @@ namespace JacobiPolynomials { // Indeterminate form for u == -1 and u == 1 // TODO: Extend to non-integer alpha & beta? - if ((u == 1.) || (u == -1.)) { - + if((u == 1.) || (u == -1.)) { // alpha or beta in formula, depending on u int coeff = (u == 1.) ? (int)alpha : (int)beta; // Compute factorial - const int fMax = std::max(n,1)+coeff; - std::vector<double> fact(fMax+1); + const int fMax = std::max(n, 1) + coeff; + std::vector<double> fact(fMax + 1); fact[0] = 1.; - for (int i=1;i<=fMax;i++) fact[i] = i*fact[i-1]; + for(int i = 1; i <= fMax; i++) fact[i] = i * fact[i - 1]; // Compute formula (with appropriate sign at even orders for u == -1) val[0] = 0.; - for (int k=1;k<=n;k++) val[k] = 0.5*(k+alphaPlusBeta+1)*fact[k+coeff]/(fact[coeff+1]*fact[k-1]); - if ((u == -1.) && (n >= 2)) for (int k=2;k<=n;k+=2) val[k] = -val[k]; + for(int k = 1; k <= n; k++) + val[k] = 0.5 * (k + alphaPlusBeta + 1) * fact[k + coeff] / + (fact[coeff + 1] * fact[k - 1]); + if((u == -1.) && (n >= 2)) + for(int k = 2; k <= n; k += 2) val[k] = -val[k]; return; } @@ -189,21 +191,22 @@ namespace JacobiPolynomials { // Now general case // Values of the Jacobi polynomials - std::vector<double> tmp(n+1); - f(n, alpha, beta, u,&(tmp[0])); + std::vector<double> tmp(n + 1); + f(n, alpha, beta, u, &(tmp[0])); // First 2 values of the derivatives val[0] = 0; - if (n>=1) val[1] = 0.5*(alphaPlusBeta + 2.); - - // Values of the derivative for orders > 1 computed from the values of the polynomials - for (int i=2;i<=n;i++) { - double ii = (double) i; - double aa = (2.*ii + alphaPlusBeta); - double g2 = aa*(1.-u*u); - double g1 = ii*(alpha - beta - aa*u); - double g0 = 2.*(ii+alpha)*(ii+beta); - val[i] = (g1 * tmp[i] + g0 * tmp[i-1])/g2; + if(n >= 1) val[1] = 0.5 * (alphaPlusBeta + 2.); + + // Values of the derivative for orders > 1 computed from the values of the + // polynomials + for(int i = 2; i <= n; i++) { + double ii = (double)i; + double aa = (2. * ii + alphaPlusBeta); + double g2 = aa * (1. - u * u); + double g1 = ii * (alpha - beta - aa * u); + double g0 = 2. * (ii + alpha) * (ii + beta); + val[i] = (g1 * tmp[i] + g0 * tmp[i - 1]) / g2; } } -} +} // namespace JacobiPolynomials diff --git a/Numeric/orthogonalBasis.h b/Numeric/orthogonalBasis.h index 17cca0e08011f70c02f38e16b40f251b37f859af..40370ba0c5f23f174d93a16aae18b9b20c0c2ec5 100644 --- a/Numeric/orthogonalBasis.h +++ b/Numeric/orthogonalBasis.h @@ -29,19 +29,18 @@ namespace LegendrePolynomials { void f(int n, double u, double *val); void fc(int n, double u, double *val); void df(int n, double u, double *val); -} +} // namespace LegendrePolynomials namespace JacobiPolynomials { void f(int n, double alpha, double beta, double u, double *val); void df(int n, double alpha, double beta, double u, double *val); - inline double Pochhammer(double x,int n) + inline double Pochhammer(double x, int n) { double result = 1; - for (int i = 0; i < n; i++) result *= x + i; + for(int i = 0; i < n; i++) result *= x + i; return result; } -} +} // namespace JacobiPolynomials - -#endif //GMSH_ORTHOGONALBASIS_H +#endif // GMSH_ORTHOGONALBASIS_H diff --git a/Numeric/pointsGenerators.cpp b/Numeric/pointsGenerators.cpp index 96af04c2b262600e932fc529b9681702c81b4cee..0e773e3da77a176df7478183f06b53af07660b74 100644 --- a/Numeric/pointsGenerators.cpp +++ b/Numeric/pointsGenerators.cpp @@ -16,43 +16,38 @@ void gmshGeneratePoints(FuncSpaceData data, fullMatrix<double> &points) { - switch(data.elementType()){ - case TYPE_PNT : - points = gmshGeneratePointsLine(0); - return; - case TYPE_LIN : - points = gmshGeneratePointsLine(data.spaceOrder()); - return; - case TYPE_TRI : - points = gmshGeneratePointsTriangle(data.spaceOrder(), + switch(data.elementType()) { + case TYPE_PNT: points = gmshGeneratePointsLine(0); return; + case TYPE_LIN: points = gmshGeneratePointsLine(data.spaceOrder()); return; + case TYPE_TRI: + points = + gmshGeneratePointsTriangle(data.spaceOrder(), data.spaceIsSerendipity()); + return; + case TYPE_QUA: + points = gmshGeneratePointsQuadrangle(data.spaceOrder(), data.spaceIsSerendipity()); - return; - case TYPE_QUA : - points = gmshGeneratePointsQuadrangle(data.spaceOrder(), - data.spaceIsSerendipity()); - return; - case TYPE_TET : - points = gmshGeneratePointsTetrahedron(data.spaceOrder(), - data.spaceIsSerendipity()); - return; - case TYPE_PRI : - points = gmshGeneratePointsPrism(data.spaceOrder(), - data.spaceIsSerendipity()); - return; - case TYPE_HEX : - points = gmshGeneratePointsHexahedron(data.spaceOrder(), - data.spaceIsSerendipity()); - return; - case TYPE_PYR : - points = gmshGeneratePointsPyramidGeneral(data.isPyramidalSpace(), - data.nij(), - data.nk(), - data.spaceIsSerendipity()); - return; - default : - Msg::Error("Unknown element type %d (tag %d) for points generation", - data.elementType(), data.elementTag()); - return; + return; + case TYPE_TET: + points = gmshGeneratePointsTetrahedron(data.spaceOrder(), + data.spaceIsSerendipity()); + return; + case TYPE_PRI: + points = + gmshGeneratePointsPrism(data.spaceOrder(), data.spaceIsSerendipity()); + return; + case TYPE_HEX: + points = gmshGeneratePointsHexahedron(data.spaceOrder(), + data.spaceIsSerendipity()); + return; + case TYPE_PYR: + points = + gmshGeneratePointsPyramidGeneral(data.isPyramidalSpace(), data.nij(), + data.nk(), data.spaceIsSerendipity()); + return; + default: + Msg::Error("Unknown element type %d (tag %d) for points generation", + data.elementType(), data.elementTag()); + return; } } @@ -60,7 +55,7 @@ fullMatrix<double> gmshGeneratePointsLine(int order) { fullMatrix<double> points = gmshGenerateMonomialsLine(order); if(order == 0) return points; - points.scale(2./order); + points.scale(2. / order); points.add(-1.); return points; } @@ -69,7 +64,7 @@ fullMatrix<double> gmshGeneratePointsTriangle(int order, bool serendip) { fullMatrix<double> points = gmshGenerateMonomialsTriangle(order, serendip); if(order == 0) return points; - points.scale(1./order); + points.scale(1. / order); return points; } @@ -77,7 +72,7 @@ fullMatrix<double> gmshGeneratePointsQuadrangle(int order, bool serendip) { fullMatrix<double> points = gmshGenerateMonomialsQuadrangle(order, serendip); if(order == 0) return points; - points.scale(2./order); + points.scale(2. / order); points.add(-1.); return points; } @@ -86,7 +81,7 @@ fullMatrix<double> gmshGeneratePointsTetrahedron(int order, bool serendip) { fullMatrix<double> points = gmshGenerateMonomialsTetrahedron(order, serendip); if(order == 0) return points; - points.scale(1./order); + points.scale(1. / order); return points; } @@ -94,7 +89,7 @@ fullMatrix<double> gmshGeneratePointsHexahedron(int order, bool serendip) { fullMatrix<double> points = gmshGenerateMonomialsHexahedron(order, serendip); if(order == 0) return points; - points.scale(2./order); + points.scale(2. / order); points.add(-1.); return points; } @@ -105,9 +100,9 @@ fullMatrix<double> gmshGeneratePointsPrism(int order, bool serendip) if(order == 0) return points; fullMatrix<double> tmp; tmp.setAsProxy(points, 0, 2); - tmp.scale(1./order); + tmp.scale(1. / order); tmp.setAsProxy(points, 2, 1); - tmp.scale(2./order); + tmp.scale(2. / order); tmp.add(-1.); return points; } @@ -116,7 +111,7 @@ fullMatrix<double> gmshGeneratePointsPyramid(int order, bool serendip) { fullMatrix<double> points = gmshGenerateMonomialsPyramid(order, serendip); if(order == 0) return points; - for(int i = 0; i < points.size1(); ++i){ + for(int i = 0; i < points.size1(); ++i) { points(i, 2) = 1 - points(i, 2) / order; const double duv = -1. + points(i, 2); points(i, 0) = duv + points(i, 0) * 2. / order; @@ -131,8 +126,8 @@ fullMatrix<double> gmshGeneratePointsPyramidGeneral(bool pyr, int nij, int nk, fullMatrix<double> points = gmshGenerateMonomialsPyramidGeneral(pyr, nij, nk, forSerendipPoints); if(points.size1() == 1) return points; - const int div = pyr ? nk+nij : std::max(nij, nk); - for(int i = 0; i < points.size1(); ++i){ + const int div = pyr ? nk + nij : std::max(nij, nk); + for(int i = 0; i < points.size1(); ++i) { points(i, 2) = (nk - points(i, 2)) / div; const double scale = 1. - points(i, 2); points(i, 0) = scale * (-1 + points(i, 0) * 2. / div); @@ -145,40 +140,37 @@ fullMatrix<double> gmshGeneratePointsPyramidGeneral(bool pyr, int nij, int nk, void gmshGenerateMonomials(FuncSpaceData data, fullMatrix<double> &monomials) { - switch(data.elementType()){ - case TYPE_PNT : - monomials = gmshGenerateMonomialsLine(0); - return; - case TYPE_LIN : + switch(data.elementType()) { + case TYPE_PNT: monomials = gmshGenerateMonomialsLine(0); return; + case TYPE_LIN: monomials = gmshGenerateMonomialsLine(data.spaceOrder()); return; - case TYPE_TRI : + case TYPE_TRI: monomials = gmshGenerateMonomialsTriangle(data.spaceOrder(), data.spaceIsSerendipity()); return; - case TYPE_QUA : + case TYPE_QUA: monomials = gmshGenerateMonomialsQuadrangle(data.spaceOrder(), data.spaceIsSerendipity()); return; - case TYPE_TET : + case TYPE_TET: monomials = gmshGenerateMonomialsTetrahedron(data.spaceOrder(), data.spaceIsSerendipity()); return; - case TYPE_PRI : - monomials = gmshGenerateMonomialsPrism(data.spaceOrder(), - data.spaceIsSerendipity()); + case TYPE_PRI: + monomials = + gmshGenerateMonomialsPrism(data.spaceOrder(), data.spaceIsSerendipity()); return; - case TYPE_HEX : + case TYPE_HEX: monomials = gmshGenerateMonomialsHexahedron(data.spaceOrder(), data.spaceIsSerendipity()); return; - case TYPE_PYR : - monomials = gmshGenerateMonomialsPyramidGeneral(data.isPyramidalSpace(), - data.nij(), - data.nk(), - data.spaceIsSerendipity()); + case TYPE_PYR: + monomials = + gmshGenerateMonomialsPyramidGeneral(data.isPyramidalSpace(), data.nij(), + data.nk(), data.spaceIsSerendipity()); return; - default : + default: Msg::Error("Unknown element type %d (tag %d) for monomials generation", data.elementType(), data.elementTag()); return; @@ -188,10 +180,10 @@ void gmshGenerateMonomials(FuncSpaceData data, fullMatrix<double> &monomials) fullMatrix<double> gmshGenerateMonomialsLine(int order, bool serendip) { fullMatrix<double> monomials(order + 1, 1); - monomials(0,0) = 0; - if(order > 0){ + monomials(0, 0) = 0; + if(order > 0) { monomials(1, 0) = order; - for(int i = 2; i < order + 1; i++) monomials(i, 0) = i-1; + for(int i = 2; i < order + 1; i++) monomials(i, 0) = i - 1; } return monomials; } @@ -205,29 +197,29 @@ fullMatrix<double> gmshGenerateMonomialsTriangle(int order, bool serendip) monomials(0, 0) = 0; monomials(0, 1) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = order; monomials(1, 1) = 0; monomials(2, 0) = 0; monomials(2, 1) = order; - if(order > 1){ + if(order > 1) { int index = 3; - for(int iedge = 0; iedge < 3; ++iedge){ + for(int iedge = 0; iedge < 3; ++iedge) { int i0 = MTriangle::edges_tri(iedge, 0); int i1 = MTriangle::edges_tri(iedge, 1); - int u_0 = (monomials(i1,0)-monomials(i0,0)) / order; - int u_1 = (monomials(i1,1)-monomials(i0,1)) / order; + int u_0 = (monomials(i1, 0) - monomials(i0, 0)) / order; + int u_1 = (monomials(i1, 1) - monomials(i0, 1)) / order; - for(int i = 1; i < order; ++i, ++index){ + for(int i = 1; i < order; ++i, ++index) { monomials(index, 0) = monomials(i0, 0) + u_0 * i; monomials(index, 1) = monomials(i0, 1) + u_1 * i; } } - if(!serendip && order > 2){ - fullMatrix<double> inner = gmshGenerateMonomialsTriangle(order-3); + if(!serendip && order > 2) { + fullMatrix<double> inner = gmshGenerateMonomialsTriangle(order - 3); inner.add(1); monomials.copy(inner, 0, nbMonomials - index, 0, 2, index, 0); } @@ -236,16 +228,17 @@ fullMatrix<double> gmshGenerateMonomialsTriangle(int order, bool serendip) return monomials; } -fullMatrix<double> gmshGenerateMonomialsQuadrangle(int order, bool forSerendipPoints) +fullMatrix<double> gmshGenerateMonomialsQuadrangle(int order, + bool forSerendipPoints) { - int nbMonomials = forSerendipPoints ? order*4 : (order+1)*(order+1); + int nbMonomials = forSerendipPoints ? order * 4 : (order + 1) * (order + 1); if(forSerendipPoints && !order) nbMonomials = 1; fullMatrix<double> monomials(nbMonomials, 2); monomials(0, 0) = 0; monomials(0, 1) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = order; monomials(1, 1) = 0; @@ -255,23 +248,23 @@ fullMatrix<double> gmshGenerateMonomialsQuadrangle(int order, bool forSerendipPo monomials(3, 0) = 0; monomials(3, 1) = order; - if(order > 1){ + if(order > 1) { int index = 4; - for(int iedge = 0; iedge < 4; ++iedge){ + for(int iedge = 0; iedge < 4; ++iedge) { int i0 = MQuadrangle::edges_quad(iedge, 0); int i1 = MQuadrangle::edges_quad(iedge, 1); - int u_0 = (monomials(i1,0)-monomials(i0,0)) / order; - int u_1 = (monomials(i1,1)-monomials(i0,1)) / order; + int u_0 = (monomials(i1, 0) - monomials(i0, 0)) / order; + int u_1 = (monomials(i1, 1) - monomials(i0, 1)) / order; - for(int i = 1; i < order; ++i, ++index){ + for(int i = 1; i < order; ++i, ++index) { monomials(index, 0) = monomials(i0, 0) + u_0 * i; monomials(index, 1) = monomials(i0, 1) + u_1 * i; } } - if(!forSerendipPoints){ - fullMatrix<double> inner = gmshGenerateMonomialsQuadrangle(order-2); + if(!forSerendipPoints) { + fullMatrix<double> inner = gmshGenerateMonomialsQuadrangle(order - 2); inner.add(1); monomials.copy(inner, 0, nbMonomials - index, 0, 2, index, 0); } @@ -291,13 +284,13 @@ fullMatrix<double> gmshGenerateMonomialsQuadrangle(int order, bool forSerendipPo fullMatrix<double> gmshGenerateMonomialsQuadSerendipity(int order) { - int nbMonomials = order ? order*4 : 1; + int nbMonomials = order ? order * 4 : 1; fullMatrix<double> monomials(nbMonomials, 2); monomials(0, 0) = 0; monomials(0, 1) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = 1; monomials(1, 1) = 0; @@ -307,31 +300,33 @@ fullMatrix<double> gmshGenerateMonomialsQuadSerendipity(int order) monomials(3, 0) = 0; monomials(3, 1) = 1; - if(order > 1){ + if(order > 1) { int index = 3; - for(int p = 2; p <= order; ++p){ + for(int p = 2; p <= order; ++p) { monomials(++index, 0) = p; - monomials( index, 1) = 0; + monomials(index, 1) = 0; monomials(++index, 0) = p; - monomials( index, 1) = 1; + monomials(index, 1) = 1; monomials(++index, 0) = 1; - monomials( index, 1) = p; + monomials(index, 1) = p; monomials(++index, 0) = 0; - monomials( index, 1) = p; + monomials(index, 1) = p; } } } return monomials; } -//KH : caveat : node coordinates are not yet coherent with node numbering associated +// KH : caveat : node coordinates are not yet coherent with node numbering +// associated // to numbering of principal vertices of face !!!! fullMatrix<double> gmshGenerateMonomialsTetrahedron(int order, bool serendip) { - int nbMonomials = serendip ? 4 + (order - 1)*6 : (order + 1)*(order + 2)*(order + 3)/6; + int nbMonomials = serendip ? 4 + (order - 1) * 6 : + (order + 1) * (order + 2) * (order + 3) / 6; if(serendip && !order) nbMonomials = 1; fullMatrix<double> monomials(nbMonomials, 3); @@ -339,7 +334,7 @@ fullMatrix<double> gmshGenerateMonomialsTetrahedron(int order, bool serendip) monomials(0, 1) = 0; monomials(0, 2) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = order; monomials(1, 1) = 0; monomials(1, 2) = 0; @@ -352,31 +347,32 @@ fullMatrix<double> gmshGenerateMonomialsTetrahedron(int order, bool serendip) monomials(3, 1) = 0; monomials(3, 2) = order; - // the template has been defined in table edges_tetra and faces_tetra (MElement.h) + // the template has been defined in table edges_tetra and faces_tetra + // (MElement.h) - if(order > 1){ + if(order > 1) { int index = 4; - for(int iedge = 0; iedge < 6; ++iedge){ + for(int iedge = 0; iedge < 6; ++iedge) { int i0 = MTetrahedron::edges_tetra(iedge, 0); int i1 = MTetrahedron::edges_tetra(iedge, 1); int u[3]; - u[0] = (monomials(i1,0)-monomials(i0,0)) / order; - u[1] = (monomials(i1,1)-monomials(i0,1)) / order; - u[2] = (monomials(i1,2)-monomials(i0,2)) / order; + u[0] = (monomials(i1, 0) - monomials(i0, 0)) / order; + u[1] = (monomials(i1, 1) - monomials(i0, 1)) / order; + u[2] = (monomials(i1, 2) - monomials(i0, 2)) / order; - for(int i = 1; i < order; ++i, ++index){ + for(int i = 1; i < order; ++i, ++index) { monomials(index, 0) = monomials(i0, 0) + u[0] * i; monomials(index, 1) = monomials(i0, 1) + u[1] * i; monomials(index, 2) = monomials(i0, 2) + u[2] * i; } } - if(!serendip && order > 2){ + if(!serendip && order > 2) { fullMatrix<double> dudv = gmshGenerateMonomialsTriangle(order - 3); dudv.add(1); - for(int iface = 0; iface < 4; ++iface){ + for(int iface = 0; iface < 4; ++iface) { int i0 = MTetrahedron::faces_tetra(iface, 0); int i1 = MTetrahedron::faces_tetra(iface, 1); int i2 = MTetrahedron::faces_tetra(iface, 2); @@ -390,15 +386,19 @@ fullMatrix<double> gmshGenerateMonomialsTetrahedron(int order, bool serendip) v[1] = (monomials(i2, 1) - monomials(i0, 1)) / order; v[2] = (monomials(i2, 2) - monomials(i0, 2)) / order; - for(int i = 0; i < dudv.size1(); ++i, ++index){ - monomials(index, 0) = monomials(i0, 0) + u[0] * dudv(i, 0) + v[0] * dudv(i, 1); - monomials(index, 1) = monomials(i0, 1) + u[1] * dudv(i, 0) + v[1] * dudv(i, 1); - monomials(index, 2) = monomials(i0, 2) + u[2] * dudv(i, 0) + v[2] * dudv(i, 1); + for(int i = 0; i < dudv.size1(); ++i, ++index) { + monomials(index, 0) = + monomials(i0, 0) + u[0] * dudv(i, 0) + v[0] * dudv(i, 1); + monomials(index, 1) = + monomials(i0, 1) + u[1] * dudv(i, 0) + v[1] * dudv(i, 1); + monomials(index, 2) = + monomials(i0, 2) + u[2] * dudv(i, 0) + v[2] * dudv(i, 1); } } - if(order > 3){ - fullMatrix<double> inner = gmshGenerateMonomialsTetrahedron(order - 4); + if(order > 3) { + fullMatrix<double> inner = + gmshGenerateMonomialsTetrahedron(order - 4); inner.add(1); monomials.copy(inner, 0, nbMonomials - index, 0, 3, index, 0); } @@ -410,8 +410,9 @@ fullMatrix<double> gmshGenerateMonomialsTetrahedron(int order, bool serendip) fullMatrix<double> gmshGenerateMonomialsPrism(int order, bool forSerendipPoints) { - int nbMonomials = forSerendipPoints ? 6 + (order-1)*9 : - (order + 1)*(order + 1)*(order + 2)/2; + int nbMonomials = forSerendipPoints ? + 6 + (order - 1) * 9 : + (order + 1) * (order + 1) * (order + 2) / 2; if(forSerendipPoints && !order) nbMonomials = 1; fullMatrix<double> monomials(nbMonomials, 3); @@ -419,7 +420,7 @@ fullMatrix<double> gmshGenerateMonomialsPrism(int order, bool forSerendipPoints) monomials(0, 1) = 0; monomials(0, 2) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = order; monomials(1, 1) = 0; monomials(1, 2) = 0; @@ -440,47 +441,48 @@ fullMatrix<double> gmshGenerateMonomialsPrism(int order, bool forSerendipPoints) monomials(5, 1) = order; monomials(5, 2) = order; - if(order > 1){ + if(order > 1) { int index = 6; - for(int iedge = 0; iedge < 9; ++iedge){ + for(int iedge = 0; iedge < 9; ++iedge) { int i0 = MPrism::edges_prism(iedge, 0); int i1 = MPrism::edges_prism(iedge, 1); - int u_1 = (monomials(i1,0)-monomials(i0,0)) / order; - int u_2 = (monomials(i1,1)-monomials(i0,1)) / order; - int u_3 = (monomials(i1,2)-monomials(i0,2)) / order; + int u_1 = (monomials(i1, 0) - monomials(i0, 0)) / order; + int u_2 = (monomials(i1, 1) - monomials(i0, 1)) / order; + int u_3 = (monomials(i1, 2) - monomials(i0, 2)) / order; - for(int i = 1; i < order; ++i, ++index){ + for(int i = 1; i < order; ++i, ++index) { monomials(index, 0) = monomials(i0, 0) + i * u_1; monomials(index, 1) = monomials(i0, 1) + i * u_2; monomials(index, 2) = monomials(i0, 2) + i * u_3; } } - if(!forSerendipPoints){ + if(!forSerendipPoints) { fullMatrix<double> dudvQ = gmshGenerateMonomialsQuadrangle(order - 2); dudvQ.add(1); fullMatrix<double> dudvT; - if(order > 2){ + if(order > 2) { dudvT = gmshGenerateMonomialsTriangle(order - 3); dudvT.add(1); } - for(int iface = 0; iface < 5; ++iface){ + for(int iface = 0; iface < 5; ++iface) { int i0, i1, i2; i0 = MPrism::faces_prism(iface, 0); i1 = MPrism::faces_prism(iface, 1); fullMatrix<double> dudv; - if(MPrism::faces_prism(iface, 3) != -1){ + if(MPrism::faces_prism(iface, 3) != -1) { i2 = MPrism::faces_prism(iface, 3); dudv.setAsProxy(dudvQ); } - else if(order > 2){ + else if(order > 2) { i2 = MPrism::faces_prism(iface, 2); dudv.setAsProxy(dudvT); } - else continue; + else + continue; int u[3]; u[0] = (monomials(i1, 0) - monomials(i0, 0)) / order; @@ -491,19 +493,24 @@ fullMatrix<double> gmshGenerateMonomialsPrism(int order, bool forSerendipPoints) v[1] = (monomials(i2, 1) - monomials(i0, 1)) / order; v[2] = (monomials(i2, 2) - monomials(i0, 2)) / order; - for(int i = 0; i < dudv.size1(); ++i, ++index){ - monomials(index, 0) = monomials(i0, 0) + u[0] * dudv(i, 0) + v[0] * dudv(i, 1); - monomials(index, 1) = monomials(i0, 1) + u[1] * dudv(i, 0) + v[1] * dudv(i, 1); - monomials(index, 2) = monomials(i0, 2) + u[2] * dudv(i, 0) + v[2] * dudv(i, 1); + for(int i = 0; i < dudv.size1(); ++i, ++index) { + monomials(index, 0) = + monomials(i0, 0) + u[0] * dudv(i, 0) + v[0] * dudv(i, 1); + monomials(index, 1) = + monomials(i0, 1) + u[1] * dudv(i, 0) + v[1] * dudv(i, 1); + monomials(index, 2) = + monomials(i0, 2) + u[2] * dudv(i, 0) + v[2] * dudv(i, 1); } } - if(order > 2){ - fullMatrix<double> triMonomials = gmshGenerateMonomialsTriangle(order - 3); - fullMatrix<double> lineMonomials = gmshGenerateMonomialsLine(order - 2); + if(order > 2) { + fullMatrix<double> triMonomials = + gmshGenerateMonomialsTriangle(order - 3); + fullMatrix<double> lineMonomials = + gmshGenerateMonomialsLine(order - 2); - for(int i = 0; i < triMonomials.size1(); ++i){ - for(int j = 0; j < lineMonomials.size1(); ++j, ++index){ + for(int i = 0; i < triMonomials.size1(); ++i) { + for(int j = 0; j < lineMonomials.size1(); ++j, ++index) { monomials(index, 0) = 1 + triMonomials(i, 0); monomials(index, 1) = 1 + triMonomials(i, 1); monomials(index, 2) = 1 + lineMonomials(j, 0); @@ -518,14 +525,14 @@ fullMatrix<double> gmshGenerateMonomialsPrism(int order, bool forSerendipPoints) fullMatrix<double> gmshGenerateMonomialsPrismSerendipity(int order) { - int nbMonomials = order ? 6 + (order-1) * 9 : 1; + int nbMonomials = order ? 6 + (order - 1) * 9 : 1; fullMatrix<double> monomials(nbMonomials, 3); monomials(0, 0) = 0; monomials(0, 1) = 0; monomials(0, 2) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = 1; monomials(1, 1) = 0; monomials(1, 2) = 0; @@ -546,39 +553,33 @@ fullMatrix<double> gmshGenerateMonomialsPrismSerendipity(int order) monomials(5, 1) = 1; monomials(5, 2) = 1; - if(order > 1){ - const int ind[7][3] = { - {2, 0, 0}, - {2, 0, 1}, + if(order > 1) { + const int ind[7][3] = {{2, 0, 0}, {2, 0, 1}, - {0, 2, 0}, - {0, 2, 1}, + {0, 2, 0}, {0, 2, 1}, - {0, 0, 2}, - {1, 0, 2}, - {0, 1, 2} - }; + {0, 0, 2}, {1, 0, 2}, {0, 1, 2}}; int val[3] = {0, 1, -1}; int index = 5; - for(int p = 2; p <= order; ++p){ + for(int p = 2; p <= order; ++p) { val[2] = p; - for(int i = 0; i < 7; ++i){ + for(int i = 0; i < 7; ++i) { monomials(++index, 0) = val[ind[i][0]]; - monomials( index, 1) = val[ind[i][1]]; - monomials( index, 2) = val[ind[i][2]]; + monomials(index, 1) = val[ind[i][1]]; + monomials(index, 2) = val[ind[i][2]]; } } int val0 = 1; int val1 = order - 1; - for(int p = 2; p <= order; ++p){ + for(int p = 2; p <= order; ++p) { monomials(++index, 0) = val0; - monomials( index, 1) = val1; - monomials( index, 2) = 0; + monomials(index, 1) = val1; + monomials(index, 2) = 0; monomials(++index, 0) = val0; - monomials( index, 1) = val1; - monomials( index, 2) = 1; + monomials(index, 1) = val1; + monomials(index, 2) = 1; ++val0; --val1; @@ -588,10 +589,11 @@ fullMatrix<double> gmshGenerateMonomialsPrismSerendipity(int order) return monomials; } -fullMatrix<double> gmshGenerateMonomialsHexahedron(int order, bool forSerendipPoints) +fullMatrix<double> gmshGenerateMonomialsHexahedron(int order, + bool forSerendipPoints) { - int nbMonomials = forSerendipPoints ? 8 + (order-1)*12 : - (order+1)*(order+1)*(order+1); + int nbMonomials = forSerendipPoints ? 8 + (order - 1) * 12 : + (order + 1) * (order + 1) * (order + 1); if(forSerendipPoints && !order) nbMonomials = 1; fullMatrix<double> monomials(nbMonomials, 3); @@ -599,7 +601,7 @@ fullMatrix<double> gmshGenerateMonomialsHexahedron(int order, bool forSerendipPo monomials(0, 1) = 0; monomials(0, 2) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = order; monomials(1, 1) = 0; monomials(1, 2) = 0; @@ -628,28 +630,28 @@ fullMatrix<double> gmshGenerateMonomialsHexahedron(int order, bool forSerendipPo monomials(7, 1) = order; monomials(7, 2) = order; - if(order > 1){ + if(order > 1) { int index = 8; - for(int iedge = 0; iedge < 12; ++iedge){ + for(int iedge = 0; iedge < 12; ++iedge) { int i0 = MHexahedron::edges_hexa(iedge, 0); int i1 = MHexahedron::edges_hexa(iedge, 1); - int u_1 = (monomials(i1,0)-monomials(i0,0)) / order; - int u_2 = (monomials(i1,1)-monomials(i0,1)) / order; - int u_3 = (monomials(i1,2)-monomials(i0,2)) / order; + int u_1 = (monomials(i1, 0) - monomials(i0, 0)) / order; + int u_2 = (monomials(i1, 1) - monomials(i0, 1)) / order; + int u_3 = (monomials(i1, 2) - monomials(i0, 2)) / order; - for(int i = 1; i < order; ++i, ++index){ + for(int i = 1; i < order; ++i, ++index) { monomials(index, 0) = monomials(i0, 0) + i * u_1; monomials(index, 1) = monomials(i0, 1) + i * u_2; monomials(index, 2) = monomials(i0, 2) + i * u_3; } } - if(!forSerendipPoints){ + if(!forSerendipPoints) { fullMatrix<double> dudv = gmshGenerateMonomialsQuadrangle(order - 2); dudv.add(1); - for(int iface = 0; iface < 6; ++iface){ + for(int iface = 0; iface < 6; ++iface) { int i0 = MHexahedron::faces_hexa(iface, 0); int i1 = MHexahedron::faces_hexa(iface, 1); int i3 = MHexahedron::faces_hexa(iface, 3); @@ -663,10 +665,13 @@ fullMatrix<double> gmshGenerateMonomialsHexahedron(int order, bool forSerendipPo v[1] = (monomials(i3, 1) - monomials(i0, 1)) / order; v[2] = (monomials(i3, 2) - monomials(i0, 2)) / order; - for(int i = 0; i < dudv.size1(); ++i, ++index){ - monomials(index, 0) = monomials(i0, 0) + u[0] * dudv(i, 0) + v[0] * dudv(i, 1); - monomials(index, 1) = monomials(i0, 1) + u[1] * dudv(i, 0) + v[1] * dudv(i, 1); - monomials(index, 2) = monomials(i0, 2) + u[2] * dudv(i, 0) + v[2] * dudv(i, 1); + for(int i = 0; i < dudv.size1(); ++i, ++index) { + monomials(index, 0) = + monomials(i0, 0) + u[0] * dudv(i, 0) + v[0] * dudv(i, 1); + monomials(index, 1) = + monomials(i0, 1) + u[1] * dudv(i, 0) + v[1] * dudv(i, 1); + monomials(index, 2) = + monomials(i0, 2) + u[2] * dudv(i, 0) + v[2] * dudv(i, 1); } } @@ -681,14 +686,14 @@ fullMatrix<double> gmshGenerateMonomialsHexahedron(int order, bool forSerendipPo fullMatrix<double> gmshGenerateMonomialsHexaSerendipity(int order) { - int nbMonomials = order ? 8 + (order-1) * 12 : 1; + int nbMonomials = order ? 8 + (order - 1) * 12 : 1; fullMatrix<double> monomials(nbMonomials, 3); monomials(0, 0) = 0; monomials(0, 1) = 0; monomials(0, 2) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = 1; monomials(1, 1) = 0; monomials(1, 2) = 0; @@ -717,31 +722,20 @@ fullMatrix<double> gmshGenerateMonomialsHexaSerendipity(int order) monomials(7, 1) = 1; monomials(7, 2) = 1; - if(order > 1){ - const int ind[12][3] = { - {2, 0, 0}, - {2, 0, 1}, - {2, 1, 1}, - {2, 1, 0}, - - {0, 2, 0}, - {0, 2, 1}, - {1, 2, 1}, - {1, 2, 0}, - - {0, 0, 2}, - {0, 1, 2}, - {1, 1, 2}, - {1, 0, 2} - }; + if(order > 1) { + const int ind[12][3] = {{2, 0, 0}, {2, 0, 1}, {2, 1, 1}, {2, 1, 0}, + + {0, 2, 0}, {0, 2, 1}, {1, 2, 1}, {1, 2, 0}, + + {0, 0, 2}, {0, 1, 2}, {1, 1, 2}, {1, 0, 2}}; int val[3] = {0, 1, -1}; int index = 7; - for(int p = 2; p <= order; ++p){ + for(int p = 2; p <= order; ++p) { val[2] = p; - for(int i = 0; i < 12; ++i){ + for(int i = 0; i < 12; ++i) { monomials(++index, 0) = val[ind[i][0]]; - monomials( index, 1) = val[ind[i][1]]; - monomials( index, 2) = val[ind[i][2]]; + monomials(index, 1) = val[ind[i][1]]; + monomials(index, 2) = val[ind[i][2]]; } } } @@ -749,10 +743,12 @@ fullMatrix<double> gmshGenerateMonomialsHexaSerendipity(int order) return monomials; } -fullMatrix<double> gmshGenerateMonomialsPyramid(int order, bool forSerendipPoints) +fullMatrix<double> gmshGenerateMonomialsPyramid(int order, + bool forSerendipPoints) { - int nbMonomials = forSerendipPoints ? 5 + (order-1)*8 : - (order+1)*((order+1)+1)*(2*(order+1)+1)/6; + int nbMonomials = forSerendipPoints ? 5 + (order - 1) * 8 : + (order + 1) * ((order + 1) + 1) * + (2 * (order + 1) + 1) / 6; if(forSerendipPoints && !order) nbMonomials = 1; fullMatrix<double> monomials(nbMonomials, 3); @@ -761,7 +757,7 @@ fullMatrix<double> gmshGenerateMonomialsPyramid(int order, bool forSerendipPoint monomials(0, 1) = 0; monomials(0, 2) = order; - if(order > 0){ + if(order > 0) { monomials(1, 0) = order; monomials(1, 1) = 0; monomials(1, 2) = order; @@ -778,47 +774,48 @@ fullMatrix<double> gmshGenerateMonomialsPyramid(int order, bool forSerendipPoint monomials(4, 1) = 0; monomials(4, 2) = 0; - if(order > 1){ + if(order > 1) { int index = 5; - for(int iedge = 0; iedge < 8; ++iedge){ + for(int iedge = 0; iedge < 8; ++iedge) { int i0 = MPyramid::edges_pyramid(iedge, 0); int i1 = MPyramid::edges_pyramid(iedge, 1); - int u_1 = (monomials(i1,0)-monomials(i0,0)) / order; - int u_2 = (monomials(i1,1)-monomials(i0,1)) / order; - int u_3 = (monomials(i1,2)-monomials(i0,2)) / order; + int u_1 = (monomials(i1, 0) - monomials(i0, 0)) / order; + int u_2 = (monomials(i1, 1) - monomials(i0, 1)) / order; + int u_3 = (monomials(i1, 2) - monomials(i0, 2)) / order; - for(int i = 1; i < order; ++i, ++index){ + for(int i = 1; i < order; ++i, ++index) { monomials(index, 0) = monomials(i0, 0) + i * u_1; monomials(index, 1) = monomials(i0, 1) + i * u_2; monomials(index, 2) = monomials(i0, 2) + i * u_3; } } - if(!forSerendipPoints){ + if(!forSerendipPoints) { fullMatrix<double> dudvQ = gmshGenerateMonomialsQuadrangle(order - 2); dudvQ.add(1); fullMatrix<double> dudvT; - if(order > 2){ + if(order > 2) { dudvT = gmshGenerateMonomialsTriangle(order - 3); dudvT.add(1); } - for(int iface = 0; iface < 5; ++iface){ + for(int iface = 0; iface < 5; ++iface) { int i0, i1, i2; i0 = MPyramid::faces_pyramid(iface, 0); i1 = MPyramid::faces_pyramid(iface, 1); fullMatrix<double> dudv; - if(MPyramid::faces_pyramid(iface, 3) != -1){ + if(MPyramid::faces_pyramid(iface, 3) != -1) { i2 = MPyramid::faces_pyramid(iface, 3); dudv.setAsProxy(dudvQ); } - else if(order > 2){ + else if(order > 2) { i2 = MPyramid::faces_pyramid(iface, 2); dudv.setAsProxy(dudvT); } - else continue; + else + continue; int u[3]; u[0] = (monomials(i1, 0) - monomials(i0, 0)) / order; @@ -829,14 +826,17 @@ fullMatrix<double> gmshGenerateMonomialsPyramid(int order, bool forSerendipPoint v[1] = (monomials(i2, 1) - monomials(i0, 1)) / order; v[2] = (monomials(i2, 2) - monomials(i0, 2)) / order; - for(int i = 0; i < dudv.size1(); ++i, ++index){ - monomials(index, 0) = monomials(i0, 0) + u[0] * dudv(i, 0) + v[0] * dudv(i, 1); - monomials(index, 1) = monomials(i0, 1) + u[1] * dudv(i, 0) + v[1] * dudv(i, 1); - monomials(index, 2) = monomials(i0, 2) + u[2] * dudv(i, 0) + v[2] * dudv(i, 1); + for(int i = 0; i < dudv.size1(); ++i, ++index) { + monomials(index, 0) = + monomials(i0, 0) + u[0] * dudv(i, 0) + v[0] * dudv(i, 1); + monomials(index, 1) = + monomials(i0, 1) + u[1] * dudv(i, 0) + v[1] * dudv(i, 1); + monomials(index, 2) = + monomials(i0, 2) + u[2] * dudv(i, 0) + v[2] * dudv(i, 1); } } - if(order > 2){ + if(order > 2) { fullMatrix<double> inner = gmshGenerateMonomialsPyramid(order - 3); fullMatrix<double> prox; prox.setAsProxy(inner, 0, 2); @@ -853,7 +853,7 @@ fullMatrix<double> gmshGenerateMonomialsPyramid(int order, bool forSerendipPoint fullMatrix<double> gmshGenerateMonomialsPyramidSerendipity(int order) { - int nbMonomials = order ? 5 + (order-1)*8 : 1; + int nbMonomials = order ? 5 + (order - 1) * 8 : 1; fullMatrix<double> monomials(nbMonomials, 3); @@ -861,7 +861,7 @@ fullMatrix<double> gmshGenerateMonomialsPyramidSerendipity(int order) monomials(0, 1) = 0; monomials(0, 2) = 0; - if(order > 0){ + if(order > 0) { monomials(1, 0) = 0; monomials(1, 1) = 0; monomials(1, 2) = 1; @@ -879,44 +879,44 @@ fullMatrix<double> gmshGenerateMonomialsPyramidSerendipity(int order) monomials(4, 2) = 1; // monomials of tetrahedra plus a bit more - if(order > 1){ + if(order > 1) { int idx = 5; - for(int i = 2; i <= order; ++i, ++idx){ + for(int i = 2; i <= order; ++i, ++idx) { monomials(idx, 0) = 0; monomials(idx, 1) = 0; monomials(idx, 2) = i; } - for(int i = 2; i <= order; ++i, ++idx){ + for(int i = 2; i <= order; ++i, ++idx) { monomials(idx, 0) = i; monomials(idx, 1) = 0; monomials(idx, 2) = i; } - for(int i = 2; i <= order; ++i, ++idx){ + for(int i = 2; i <= order; ++i, ++idx) { monomials(idx, 0) = 0; monomials(idx, 1) = i; monomials(idx, 2) = i; } - for(int i = 1; i < order; ++i, ++idx){ + for(int i = 1; i < order; ++i, ++idx) { monomials(idx, 0) = i; monomials(idx, 1) = 0; monomials(idx, 2) = order; } - for(int i = 1; i < order; ++i, ++idx){ + for(int i = 1; i < order; ++i, ++idx) { monomials(idx, 0) = 0; monomials(idx, 1) = i; monomials(idx, 2) = order; } - for(int i = 1; i < order; ++i, ++idx){ + for(int i = 1; i < order; ++i, ++idx) { monomials(idx, 0) = i; - monomials(idx, 1) = order-i; + monomials(idx, 1) = order - i; monomials(idx, 2) = order; } - for(int i = 2; i <= order; ++i, ++idx){ + for(int i = 2; i <= order; ++i, ++idx) { monomials(idx, 0) = i; monomials(idx, 1) = 1; monomials(idx, 2) = i; } - for(int i = 2; i <= order; ++i, ++idx){ + for(int i = 2; i <= order; ++i, ++idx) { monomials(idx, 0) = 1; monomials(idx, 1) = i; monomials(idx, 2) = i; @@ -926,63 +926,64 @@ fullMatrix<double> gmshGenerateMonomialsPyramidSerendipity(int order) monomials.print("monomials"); return monomials; -// // monomials of plus a bit more -// if(order > 1){ -// int idx = 5; -// for(int i = 2; i <= order; ++i, ++idx){ -// monomials(idx, 0) = 0; -// monomials(idx, 1) = 0; -// monomials(idx, 2) = i; -// } -// for(int i = 2; i <= order; ++i, ++idx){ -// monomials(idx, 0) = 1; -// monomials(idx, 1) = 0; -// monomials(idx, 2) = i; -// } -// for(int i = 2; i <= order; ++i, ++idx){ -// monomials(idx, 0) = 0; -// monomials(idx, 1) = 1; -// monomials(idx, 2) = i; -// } -// for(int i = 2; i <= order; ++i, ++idx){ -// monomials(idx, 0) = 1; -// monomials(idx, 1) = 1; -// monomials(idx, 2) = i; -// } -// for(int i = 2; i <= order; ++i, ++idx){ -// monomials(idx, 0) = i; -// monomials(idx, 1) = 0; -// monomials(idx, 2) = order; -// } -// for(int i = 2; i <= order; ++i, ++idx){ -// monomials(idx, 0) = i; -// monomials(idx, 1) = 1; -// monomials(idx, 2) = order; -// } -// for(int i = 2; i <= order; ++i, ++idx){ -// monomials(idx, 0) = 0; -// monomials(idx, 1) = i; -// monomials(idx, 2) = order; -// } -// for(int i = 2; i <= order; ++i, ++idx){ -// monomials(idx, 0) = 1; -// monomials(idx, 1) = i; -// monomials(idx, 2) = order; -// } -// } -// } -// monomials.print("monomials"); -// return monomials; + // // monomials of plus a bit more + // if(order > 1){ + // int idx = 5; + // for(int i = 2; i <= order; ++i, ++idx){ + // monomials(idx, 0) = 0; + // monomials(idx, 1) = 0; + // monomials(idx, 2) = i; + // } + // for(int i = 2; i <= order; ++i, ++idx){ + // monomials(idx, 0) = 1; + // monomials(idx, 1) = 0; + // monomials(idx, 2) = i; + // } + // for(int i = 2; i <= order; ++i, ++idx){ + // monomials(idx, 0) = 0; + // monomials(idx, 1) = 1; + // monomials(idx, 2) = i; + // } + // for(int i = 2; i <= order; ++i, ++idx){ + // monomials(idx, 0) = 1; + // monomials(idx, 1) = 1; + // monomials(idx, 2) = i; + // } + // for(int i = 2; i <= order; ++i, ++idx){ + // monomials(idx, 0) = i; + // monomials(idx, 1) = 0; + // monomials(idx, 2) = order; + // } + // for(int i = 2; i <= order; ++i, ++idx){ + // monomials(idx, 0) = i; + // monomials(idx, 1) = 1; + // monomials(idx, 2) = order; + // } + // for(int i = 2; i <= order; ++i, ++idx){ + // monomials(idx, 0) = 0; + // monomials(idx, 1) = i; + // monomials(idx, 2) = order; + // } + // for(int i = 2; i <= order; ++i, ++idx){ + // monomials(idx, 0) = 1; + // monomials(idx, 1) = i; + // monomials(idx, 2) = order; + // } + // } + // } + // monomials.print("monomials"); + // return monomials; } -fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk, +fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, + int nk, bool forSerendipPoints) { - if(nij < 0 || nk < 0){ + if(nij < 0 || nk < 0) { Msg::Fatal("Wrong arguments for pyramid's monomials generation ! (%d & %d)", nij, nk); } - if(!pyr && nk > 0 && nij == 0){ + if(!pyr && nk > 0 && nij == 0) { Msg::Error("Wrong argument association for pyramid's monomials generation! " "Setting nij to 1"); nij = 1; @@ -996,13 +997,14 @@ fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk // order of others having no importance. int nbMonomials; - if(pyr){ + if(pyr) { nbMonomials = 0; - for(int k = 0; k <= nk; ++k){ - nbMonomials += (k+nij+1) * (k+nij+1); + for(int k = 0; k <= nk; ++k) { + nbMonomials += (k + nij + 1) * (k + nij + 1); } } - else nbMonomials = (nij+1) * (nij+1) * (nk+1); + else + nbMonomials = (nij + 1) * (nij + 1) * (nk + 1); fullMatrix<double> monomials(nbMonomials, 3); @@ -1013,7 +1015,7 @@ fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk if(nk == 0 && nij == 0) return monomials; // Here, nij > 0 - int nijBase = pyr ? nk+nij : nij; + int nijBase = pyr ? nk + nij : nij; // Corners monomials(1, 0) = nijBase; @@ -1030,7 +1032,7 @@ fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk int index = 4; - if(nk > 0){ + if(nk > 0) { monomials(4, 0) = 0; monomials(4, 1) = 0; monomials(4, 2) = 0; @@ -1051,23 +1053,25 @@ fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk } // Base - if(nijBase > 1){ - for(int iedge = 0; iedge < 4; ++iedge){ + if(nijBase > 1) { + for(int iedge = 0; iedge < 4; ++iedge) { int i0 = iedge; - int i1 = (iedge+1) % 4; + int i1 = (iedge + 1) % 4; - int u0 = static_cast<int>( (monomials(i1,0)-monomials(i0,0)) / nijBase ); - int u1 = static_cast<int>( (monomials(i1,1)-monomials(i0,1)) / nijBase ); + int u0 = + static_cast<int>((monomials(i1, 0) - monomials(i0, 0)) / nijBase); + int u1 = + static_cast<int>((monomials(i1, 1) - monomials(i0, 1)) / nijBase); - for(int i = 1; i < nijBase; ++i, ++index){ + for(int i = 1; i < nijBase; ++i, ++index) { monomials(index, 0) = monomials(i0, 0) + i * u0; monomials(index, 1) = monomials(i0, 1) + i * u1; monomials(index, 2) = nk; } } - for(int i = 1; i < nijBase; ++i){ - for(int j = 1; j < nijBase; ++j, ++index){ + for(int i = 1; i < nijBase; ++i) { + for(int j = 1; j < nijBase; ++j, ++index) { monomials(index, 0) = i; monomials(index, 1) = j; monomials(index, 2) = nk; @@ -1076,25 +1080,27 @@ fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk } // Above base - if(nk > 0){ + if(nk > 0) { // Top - if(nij > 1){ - for(int iedge = 0; iedge < 4; ++iedge){ + if(nij > 1) { + for(int iedge = 0; iedge < 4; ++iedge) { int i0 = 4 + iedge; - int i1 = 4 + (iedge+1)%4; + int i1 = 4 + (iedge + 1) % 4; - int u0 = static_cast<int>( (monomials(i1,0)-monomials(i0,0)) / nijBase ); - int u1 = static_cast<int>( (monomials(i1,1)-monomials(i0,1)) / nijBase ); + int u0 = + static_cast<int>((monomials(i1, 0) - monomials(i0, 0)) / nijBase); + int u1 = + static_cast<int>((monomials(i1, 1) - monomials(i0, 1)) / nijBase); - for(int i = 1; i < nij; ++i, ++index){ + for(int i = 1; i < nij; ++i, ++index) { monomials(index, 0) = monomials(i0, 0) + i * u0; monomials(index, 1) = monomials(i0, 1) + i * u1; monomials(index, 2) = 0; } } - for(int i = 1; i < nij; ++i){ - for(int j = 1; j < nij; ++j, ++index){ + for(int i = 1; i < nij; ++i) { + for(int j = 1; j < nij; ++j, ++index) { monomials(index, 0) = i; monomials(index, 1) = j; monomials(index, 2) = 0; @@ -1103,10 +1109,10 @@ fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk } // Between bottom & top - for(int k = nk - 1; k > 0; --k){ - int currentnij = pyr ? k+nij : nij; - for(int i = 0; i <= currentnij; ++i){ - for(int j = 0; j <= currentnij; ++j, ++index){ + for(int k = nk - 1; k > 0; --k) { + int currentnij = pyr ? k + nij : nij; + for(int i = 0; i <= currentnij; ++i) { + for(int j = 0; j <= currentnij; ++j, ++index) { monomials(index, 0) = i; monomials(index, 1) = j; monomials(index, 2) = k; diff --git a/Numeric/pointsGenerators.h b/Numeric/pointsGenerators.h index 33c05c26836390ba9de6dbc22eb55f9e79932ba1..0bffac618726a4e93fbbf1bb946000ae46fdbffd 100644 --- a/Numeric/pointsGenerators.h +++ b/Numeric/pointsGenerators.h @@ -20,10 +20,13 @@ void gmshGeneratePoints(FuncSpaceData, fullMatrix<double> &); fullMatrix<double> gmshGeneratePointsLine(int order); fullMatrix<double> gmshGeneratePointsTriangle(int order, bool serendip = false); -fullMatrix<double> gmshGeneratePointsQuadrangle(int order, bool serendip = false); +fullMatrix<double> gmshGeneratePointsQuadrangle(int order, + bool serendip = false); -fullMatrix<double> gmshGeneratePointsTetrahedron(int order, bool serendip = false); -fullMatrix<double> gmshGeneratePointsHexahedron(int order, bool serendip = false); +fullMatrix<double> gmshGeneratePointsTetrahedron(int order, + bool serendip = false); +fullMatrix<double> gmshGeneratePointsHexahedron(int order, + bool serendip = false); fullMatrix<double> gmshGeneratePointsPrism(int order, bool serendip = false); fullMatrix<double> gmshGeneratePointsPyramid(int order, bool serendip = false); @@ -36,16 +39,19 @@ void gmshGenerateMonomials(FuncSpaceData, fullMatrix<double> &); fullMatrix<double> gmshGenerateMonomialsLine(int order, bool serendip = false); -fullMatrix<double> gmshGenerateMonomialsTriangle(int order, bool serendip = false); -fullMatrix<double> gmshGenerateMonomialsQuadrangle(int order, bool - forSerendipPoints = false); +fullMatrix<double> gmshGenerateMonomialsTriangle(int order, + bool serendip = false); +fullMatrix<double> +gmshGenerateMonomialsQuadrangle(int order, bool forSerendipPoints = false); fullMatrix<double> gmshGenerateMonomialsQuadSerendipity(int order); -fullMatrix<double> gmshGenerateMonomialsTetrahedron(int order, bool serendip = false); -fullMatrix<double> gmshGenerateMonomialsHexahedron(int order, - bool forSerendipPoints = false); +fullMatrix<double> gmshGenerateMonomialsTetrahedron(int order, + bool serendip = false); +fullMatrix<double> +gmshGenerateMonomialsHexahedron(int order, bool forSerendipPoints = false); fullMatrix<double> gmshGenerateMonomialsHexaSerendipity(int order); -fullMatrix<double> gmshGenerateMonomialsPrism(int order, bool forSerendipPoints = false); +fullMatrix<double> gmshGenerateMonomialsPrism(int order, + bool forSerendipPoints = false); fullMatrix<double> gmshGenerateMonomialsPrismSerendipity(int order); // Generate monomials of pyramidal nodal space {X^i Y^j Z^k | i,j <= k, k <= @@ -59,7 +65,8 @@ fullMatrix<double> gmshGenerateMonomialsPyramidSerendipity(int order); // generate monomials of space {X^i Y^j Z^k | i,j <= k+'nij', k <= 'nk'}, // else if 'pyr' == false, // generate monomials of space {X^i Y^j Z^k | i,j <= 'nij', k <= 'nk'} -fullMatrix<double> gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk, - bool forSerendipPoints = false); +fullMatrix<double> +gmshGenerateMonomialsPyramidGeneral(bool pyr, int nij, int nk, + bool forSerendipPoints = false); #endif diff --git a/Numeric/polynomialBasis.cpp b/Numeric/polynomialBasis.cpp index 54d692a479c4233f561e84dd339a8ad71afccd9b..cee002667d7e544d4526492debfe221c28a28d60 100644 --- a/Numeric/polynomialBasis.cpp +++ b/Numeric/polynomialBasis.cpp @@ -19,13 +19,14 @@ #include <limits> namespace { - fullMatrix<double> generateLagrangeMonomialCoefficients - (const fullMatrix<double>& monomial, const fullMatrix<double>& point) + fullMatrix<double> + generateLagrangeMonomialCoefficients(const fullMatrix<double> &monomial, + const fullMatrix<double> &point) { - if(monomial.size1() != point.size1() || monomial.size2() != point.size2()){ - Msg::Error("Wrong sizes for Lagrange coefficients generation %d %d -- %d %d", - monomial.size1(), point.size1(), - monomial.size2(), point.size2()); + if(monomial.size1() != point.size1() || monomial.size2() != point.size2()) { + Msg::Error( + "Wrong sizes for Lagrange coefficients generation %d %d -- %d %d", + monomial.size1(), point.size1(), monomial.size2(), point.size2()); return fullMatrix<double>(1, 1); } @@ -33,8 +34,8 @@ namespace { int dim = monomial.size2(); fullMatrix<double> Vandermonde(ndofs, ndofs); - for(int i = 0; i < ndofs; i++){ - for(int j = 0; j < ndofs; j++){ + for(int i = 0; i < ndofs; i++) { + for(int j = 0; j < ndofs; j++) { double dd = 1.; for(int k = 0; k < dim; k++) dd *= pow_int(point(j, k), monomial(i, k)); Vandermonde(i, j) = dd; @@ -66,61 +67,55 @@ namespace { std::string equalSign = "-"; if(fullClosure[i][closures[closureRef[i]][j]] != closures[i][j]) equalSign = "#"; - printf("%2i%s%2i ", fullClosure[i][closures[closureRef[i]][j]],equalSign.c_str(), - closures[i][j]); + printf("%2i%s%2i ", + fullClosure[i][closures[closureRef[i]][j]],equalSign.c_str(), closures[i][j]); } printf("\n"); } } */ -} +} // namespace polynomialBasis::polynomialBasis(int tag) : nodalBasis(tag) { - switch(parentType){ - case TYPE_PNT : - monomials = gmshGenerateMonomialsLine(0); - break; - case TYPE_LIN : - monomials = gmshGenerateMonomialsLine(order); - break; - case TYPE_TRI : + switch(parentType) { + case TYPE_PNT: monomials = gmshGenerateMonomialsLine(0); break; + case TYPE_LIN: monomials = gmshGenerateMonomialsLine(order); break; + case TYPE_TRI: monomials = gmshGenerateMonomialsTriangle(order, serendip); break; - case TYPE_QUA : + case TYPE_QUA: monomials = serendip ? gmshGenerateMonomialsQuadSerendipity(order) : - gmshGenerateMonomialsQuadrangle(order); + gmshGenerateMonomialsQuadrangle(order); break; - case TYPE_TET : + case TYPE_TET: monomials = gmshGenerateMonomialsTetrahedron(order, serendip); break; - case TYPE_PRI : + case TYPE_PRI: monomials = serendip ? gmshGenerateMonomialsPrismSerendipity(order) : - gmshGenerateMonomialsPrism(order); + gmshGenerateMonomialsPrism(order); break; - case TYPE_HEX : + case TYPE_HEX: monomials = serendip ? gmshGenerateMonomialsHexaSerendipity(order) : - gmshGenerateMonomialsHexahedron(order); + gmshGenerateMonomialsHexahedron(order); break; } coefficients = generateLagrangeMonomialCoefficients(monomials, points); } -polynomialBasis::~polynomialBasis() -{ -} +polynomialBasis::~polynomialBasis() {} -void polynomialBasis::evaluateMonomials(double u, double v, double w, double p[]) const +void polynomialBasis::evaluateMonomials(double u, double v, double w, + double p[]) const { - for(int j = 0; j < monomials.size1(); ++j){ + for(int j = 0; j < monomials.size1(); ++j) { p[j] = 1.; - switch(dimension){ - case 3 : p[j] *= pow_int(w, monomials(j, 2)); - case 2 : p[j] *= pow_int(v, monomials(j, 1)); - case 1 : p[j] *= pow_int(u, monomials(j, 0)); - default : - break; + switch(dimension) { + case 3: p[j] *= pow_int(w, monomials(j, 2)); + case 2: p[j] *= pow_int(v, monomials(j, 1)); + case 1: p[j] *= pow_int(u, monomials(j, 0)); + default: break; } } } @@ -129,38 +124,41 @@ void polynomialBasis::f(double u, double v, double w, double *sf) const { double p[1256]; evaluateMonomials(u, v, w, p); - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { sf[i] = 0.0; - for(int j = 0; j < coefficients.size2(); j++){ + for(int j = 0; j < coefficients.size2(); j++) { sf[i] += coefficients(i, j) * p[j]; } } } -void polynomialBasis::f(const fullMatrix<double> &coord, fullMatrix<double> &sf) const +void polynomialBasis::f(const fullMatrix<double> &coord, + fullMatrix<double> &sf) const { double p[1256]; - sf.resize (coord.size1(), coefficients.size1()); - for(int iPoint = 0; iPoint < coord.size1(); iPoint++){ - evaluateMonomials(coord(iPoint, 0), coord.size2() > 1 ? coord(iPoint, 1) : 0, + sf.resize(coord.size1(), coefficients.size1()); + for(int iPoint = 0; iPoint < coord.size1(); iPoint++) { + evaluateMonomials(coord(iPoint, 0), + coord.size2() > 1 ? coord(iPoint, 1) : 0, coord.size2() > 2 ? coord(iPoint, 2) : 0, p); - for(int i = 0; i < coefficients.size1(); i++){ - sf(iPoint,i) = 0.; + for(int i = 0; i < coefficients.size1(); i++) { + sf(iPoint, i) = 0.; for(int j = 0; j < coefficients.size2(); j++) - sf(iPoint,i) += coefficients(i, j) * p[j]; + sf(iPoint, i) += coefficients(i, j) * p[j]; } } } -void polynomialBasis::df(const fullMatrix<double> &coord, fullMatrix<double> &dfm) const +void polynomialBasis::df(const fullMatrix<double> &coord, + fullMatrix<double> &dfm) const { double dfv[1256][3]; - dfm.resize (coord.size1() * 3, coefficients.size1(), false); + dfm.resize(coord.size1() * 3, coefficients.size1(), false); int dimCoord = coord.size2(); - for(int iPoint=0; iPoint< coord.size1(); iPoint++){ + for(int iPoint = 0; iPoint < coord.size1(); iPoint++) { df(coord(iPoint, 0), dimCoord > 1 ? coord(iPoint, 1) : 0., dimCoord > 2 ? coord(iPoint, 2) : 0., dfv); - for (int i = 0; i < coefficients.size1(); i++) { + for(int i = 0; i < coefficients.size1(); i++) { dfm(iPoint * 3 + 0, i) = dfv[i][0]; dfm(iPoint * 3 + 1, i) = dfv[i][1]; dfm(iPoint * 3 + 2, i) = dfv[i][2]; @@ -170,137 +168,135 @@ void polynomialBasis::df(const fullMatrix<double> &coord, fullMatrix<double> &df void polynomialBasis::df(double u, double v, double w, double grads[][3]) const { - switch(monomials.size2()){ + switch(monomials.size2()) { case 1: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { grads[i][0] = 0; grads[i][1] = 0; grads[i][2] = 0; - for(int j = 0; j < coefficients.size2(); j++){ + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 0) grads[i][0] += coefficients(i, j) * - pow_int(u, (monomials(j, 0) - 1)) * monomials(j, 0); + pow_int(u, (monomials(j, 0) - 1)) * monomials(j, 0); } } break; case 2: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { grads[i][0] = 0; grads[i][1] = 0; grads[i][2] = 0; - for(int j = 0; j < coefficients.size2(); j++){ + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 0) grads[i][0] += coefficients(i, j) * - pow_int(u, (monomials(j, 0) - 1)) * monomials(j, 0) * - pow_int(v, monomials(j, 1)); + pow_int(u, (monomials(j, 0) - 1)) * monomials(j, 0) * + pow_int(v, monomials(j, 1)); if(monomials(j, 1) > 0) - grads[i][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, (monomials(j, 1) - 1)) * monomials(j, 1); + grads[i][1] += coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, (monomials(j, 1) - 1)) * monomials(j, 1); } } break; case 3: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { grads[i][0] = 0; grads[i][1] = 0; grads[i][2] = 0; - for(int j = 0; j < coefficients.size2(); j++){ + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 0) grads[i][0] += coefficients(i, j) * - pow_int(u, (monomials(j, 0) - 1)) * monomials(j, 0) * - pow_int(v, monomials(j, 1)) * - pow_int(w, monomials(j, 2)); + pow_int(u, (monomials(j, 0) - 1)) * monomials(j, 0) * + pow_int(v, monomials(j, 1)) * + pow_int(w, monomials(j, 2)); if(monomials(j, 1) > 0) - grads[i][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, (monomials(j, 1) - 1)) * monomials(j, 1) * - pow_int(w, monomials(j, 2)); + grads[i][1] += coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, (monomials(j, 1) - 1)) * monomials(j, 1) * + pow_int(w, monomials(j, 2)); if(monomials(j, 2) > 0) - grads[i][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1)) * - pow_int(w, (monomials(j, 2) - 1)) * monomials(j, 2); + grads[i][2] += coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1)) * + pow_int(w, (monomials(j, 2) - 1)) * monomials(j, 2); } } break; } } -void polynomialBasis::ddf(double u, double v, double w, double hess[][3][3]) const +void polynomialBasis::ddf(double u, double v, double w, + double hess[][3][3]) const { - switch(monomials.size2()){ + switch(monomials.size2()) { case 1: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { hess[i][0][0] = hess[i][0][1] = hess[i][0][2] = 0; hess[i][1][0] = hess[i][1][1] = hess[i][1][2] = 0; hess[i][2][0] = hess[i][2][1] = hess[i][2][2] = 0; - for(int j = 0; j < coefficients.size2(); j++){ + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 1) // second derivative !=0 - hess[i][0][0] += coefficients(i, j) * pow_int(u, (monomials(j, 0) - 2)) * - monomials(j, 0) * (monomials(j, 0) - 1); + hess[i][0][0] += coefficients(i, j) * + pow_int(u, (monomials(j, 0) - 2)) * monomials(j, 0) * + (monomials(j, 0) - 1); } } break; case 2: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { hess[i][0][0] = hess[i][0][1] = hess[i][0][2] = 0; hess[i][1][0] = hess[i][1][1] = hess[i][1][2] = 0; hess[i][2][0] = hess[i][2][1] = hess[i][2][2] = 0; - for(int j = 0; j < coefficients.size2(); j++){ + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 1) // second derivative !=0 - hess[i][0][0] += coefficients(i, j) * pow_int(u, (monomials(j, 0) - 2)) * - monomials(j, 0) * (monomials(j, 0) - 1) * pow_int(v, monomials(j, 1)); + hess[i][0][0] += coefficients(i, j) * + pow_int(u, (monomials(j, 0) - 2)) * monomials(j, 0) * + (monomials(j, 0) - 1) * pow_int(v, monomials(j, 1)); if((monomials(j, 1) > 0) && (monomials(j, 0) > 0)) hess[i][0][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 1) * monomials(j, 0) * - pow_int(v, monomials(j, 1) - 1) * monomials(j, 1); + pow_int(u, monomials(j, 0) - 1) * monomials(j, 0) * + pow_int(v, monomials(j, 1) - 1) * monomials(j, 1); if(monomials(j, 1) > 1) - hess[i][1][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1) - 2) * monomials(j, 1) * (monomials(j, 1) - 1); + hess[i][1][1] += coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1) - 2) * monomials(j, 1) * + (monomials(j, 1) - 1); } hess[i][1][0] = hess[i][0][1]; } break; case 3: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { hess[i][0][0] = hess[i][0][1] = hess[i][0][2] = 0; hess[i][1][0] = hess[i][1][1] = hess[i][1][2] = 0; hess[i][2][0] = hess[i][2][1] = hess[i][2][2] = 0; - for(int j = 0; j < coefficients.size2(); j++){ + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 1) hess[i][0][0] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 2) * monomials(j, 0) * (monomials(j, 0)-1) * - pow_int(v, monomials(j, 1)) * - pow_int(w, monomials(j, 2)); + pow_int(u, monomials(j, 0) - 2) * monomials(j, 0) * + (monomials(j, 0) - 1) * pow_int(v, monomials(j, 1)) * + pow_int(w, monomials(j, 2)); if((monomials(j, 0) > 0) && (monomials(j, 1) > 0)) hess[i][0][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 1) * monomials(j, 0) * - pow_int(v, monomials(j, 1) - 1) * monomials(j, 1) * - pow_int(w, monomials(j, 2)); + pow_int(u, monomials(j, 0) - 1) * monomials(j, 0) * + pow_int(v, monomials(j, 1) - 1) * monomials(j, 1) * + pow_int(w, monomials(j, 2)); if((monomials(j, 0) > 0) && (monomials(j, 2) > 0)) hess[i][0][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 1) * monomials(j, 0) * - pow_int(v, monomials(j, 1)) * - pow_int(w, monomials(j, 2) - 1) * monomials(j, 2); + pow_int(u, monomials(j, 0) - 1) * monomials(j, 0) * + pow_int(v, monomials(j, 1)) * + pow_int(w, monomials(j, 2) - 1) * monomials(j, 2); if(monomials(j, 1) > 1) - hess[i][1][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1) - 2) * monomials(j, 1) * (monomials(j, 1)-1) * - pow_int(w, monomials(j, 2)); + hess[i][1][1] += coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1) - 2) * monomials(j, 1) * + (monomials(j, 1) - 1) * pow_int(w, monomials(j, 2)); if((monomials(j, 1) > 0) && (monomials(j, 2) > 0)) - hess[i][1][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1) - 1) * monomials(j, 1) * - pow_int(w, monomials(j, 2) - 1) * monomials(j, 2); + hess[i][1][2] += coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1) - 1) * monomials(j, 1) * + pow_int(w, monomials(j, 2) - 1) * monomials(j, 2); if(monomials(j, 2) > 1) - hess[i][2][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1)) * - pow_int(w, monomials(j, 2) - 2) * monomials(j, 2) * (monomials(j, 2) - 1); + hess[i][2][2] += coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1)) * + pow_int(w, monomials(j, 2) - 2) * monomials(j, 2) * + (monomials(j, 2) - 1); } hess[i][1][0] = hess[i][0][1]; hess[i][2][0] = hess[i][0][2]; @@ -310,46 +306,48 @@ void polynomialBasis::ddf(double u, double v, double w, double hess[][3][3]) con } } -void polynomialBasis::dddf(double u, double v, double w, double third[][3][3][3]) const +void polynomialBasis::dddf(double u, double v, double w, + double third[][3][3][3]) const { - switch(monomials.size2()){ + switch(monomials.size2()) { case 1: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { for(int p = 0; p < 3; p++) for(int q = 0; q < 3; q++) - for(int r = 0; r < 3; r++) - third[i][p][q][r] = 0.; + for(int r = 0; r < 3; r++) third[i][p][q][r] = 0.; - for(int j = 0; j < coefficients.size2(); j++){ + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 2) // third derivative !=0 - third[i][0][0][0] += coefficients(i, j) * pow_int(u, (monomials(j, 0) - 3)) * - monomials(j, 0) * (monomials(j, 0) - 1)*(monomials(j, 0) - 2); + third[i][0][0][0] += + coefficients(i, j) * pow_int(u, (monomials(j, 0) - 3)) * + monomials(j, 0) * (monomials(j, 0) - 1) * (monomials(j, 0) - 2); } } break; case 2: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { for(int p = 0; p < 3; p++) for(int q = 0; q < 3; q++) - for(int r = 0; r < 3; r++) - third[i][p][q][r] = 0.; - for(int j = 0; j < coefficients.size2(); j++){ + for(int r = 0; r < 3; r++) third[i][p][q][r] = 0.; + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 2) // second derivative !=0 - third[i][0][0][0] += coefficients(i, j) * - pow_int(u, (monomials(j, 0) - 3))*monomials(j, 0) * - (monomials(j, 0) - 1) *(monomials(j, 0) - 2) * + third[i][0][0][0] += + coefficients(i, j) * pow_int(u, (monomials(j, 0) - 3)) * + monomials(j, 0) * (monomials(j, 0) - 1) * (monomials(j, 0) - 2) * pow_int(v, monomials(j, 1)); if((monomials(j, 0) > 1) && (monomials(j, 1) > 0)) - third[i][0][0][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 2) * monomials(j, 0)*(monomials(j, 0) - 1) * + third[i][0][0][1] += + coefficients(i, j) * pow_int(u, monomials(j, 0) - 2) * + monomials(j, 0) * (monomials(j, 0) - 1) * pow_int(v, monomials(j, 1) - 1) * monomials(j, 1); if((monomials(j, 0) > 0) && (monomials(j, 1) > 1)) - third[i][0][1][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 1) *monomials(j, 0)* - pow_int(v, monomials(j, 1) - 2) * monomials(j, 1) * (monomials(j, 1) - 1); + third[i][0][1][1] += + coefficients(i, j) * pow_int(u, monomials(j, 0) - 1) * + monomials(j, 0) * pow_int(v, monomials(j, 1) - 2) * + monomials(j, 1) * (monomials(j, 1) - 1); if(monomials(j, 1) > 2) - third[i][1][1][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * + third[i][1][1][1] += + coefficients(i, j) * pow_int(u, monomials(j, 0)) * pow_int(v, monomials(j, 1) - 3) * monomials(j, 1) * (monomials(j, 1) - 1) * (monomials(j, 1) - 2); } @@ -360,73 +358,77 @@ void polynomialBasis::dddf(double u, double v, double w, double third[][3][3][3] } break; case 3: - for(int i = 0; i < coefficients.size1(); i++){ + for(int i = 0; i < coefficients.size1(); i++) { for(int p = 0; p < 3; p++) for(int q = 0; q < 3; q++) - for(int r = 0; r < 3; r++) - third[i][p][q][r] = 0.; - for(int j = 0; j < coefficients.size2(); j++){ + for(int r = 0; r < 3; r++) third[i][p][q][r] = 0.; + for(int j = 0; j < coefficients.size2(); j++) { if(monomials(j, 0) > 2) // second derivative !=0 - third[i][0][0][0] += coefficients(i, j) * - pow_int(u, (monomials(j, 0) - 3)) *monomials(j, 0) * - (monomials(j, 0) - 1) * (monomials(j, 0) - 2) * - pow_int(v, monomials(j, 1))* - pow_int(w, monomials(j, 2)); + third[i][0][0][0] += + coefficients(i, j) * pow_int(u, (monomials(j, 0) - 3)) * + monomials(j, 0) * (monomials(j, 0) - 1) * (monomials(j, 0) - 2) * + pow_int(v, monomials(j, 1)) * pow_int(w, monomials(j, 2)); if((monomials(j, 0) > 1) && (monomials(j, 1) > 0)) third[i][0][0][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 2) * monomials(j, 0)*(monomials(j, 0) - 1) * - pow_int(v, monomials(j, 1) - 1) * monomials(j, 1)* - pow_int(w, monomials(j, 2)); + pow_int(u, monomials(j, 0) - 2) * + monomials(j, 0) * (monomials(j, 0) - 1) * + pow_int(v, monomials(j, 1) - 1) * + monomials(j, 1) * pow_int(w, monomials(j, 2)); if((monomials(j, 0) > 1) && (monomials(j, 2) > 0)) - third[i][0][0][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 2) * monomials(j, 0)*(monomials(j, 0) - 1) * - pow_int(v, monomials(j, 1)) * - pow_int(w, monomials(j, 2) - 1)* monomials(j, 2); + third[i][0][0][2] += + coefficients(i, j) * pow_int(u, monomials(j, 0) - 2) * + monomials(j, 0) * (monomials(j, 0) - 1) * + pow_int(v, monomials(j, 1)) * pow_int(w, monomials(j, 2) - 1) * + monomials(j, 2); if((monomials(j, 0) > 0) && (monomials(j, 1) > 1)) - third[i][0][1][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 1) *monomials(j, 0)* - pow_int(v, monomials(j, 1) - 2) * monomials(j, 1) * (monomials(j, 1) - 1)* + third[i][0][1][1] += + coefficients(i, j) * pow_int(u, monomials(j, 0) - 1) * + monomials(j, 0) * pow_int(v, monomials(j, 1) - 2) * + monomials(j, 1) * (monomials(j, 1) - 1) * pow_int(w, monomials(j, 2)); - if((monomials(j, 0) > 0) && (monomials(j, 1) > 0)&& (monomials(j, 2) > 0)) - third[i][0][1][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 1) *monomials(j, 0)* - pow_int(v, monomials(j, 1) - 1) *monomials(j, 1) * - pow_int(w, monomials(j, 2) - 1) *monomials(j, 2); + if((monomials(j, 0) > 0) && (monomials(j, 1) > 0) && + (monomials(j, 2) > 0)) + third[i][0][1][2] += + coefficients(i, j) * pow_int(u, monomials(j, 0) - 1) * + monomials(j, 0) * pow_int(v, monomials(j, 1) - 1) * + monomials(j, 1) * pow_int(w, monomials(j, 2) - 1) * monomials(j, 2); if((monomials(j, 0) > 0) && (monomials(j, 2) > 1)) third[i][0][2][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0) - 1) *monomials(j, 0)* - pow_int(v, monomials(j, 1))* - pow_int(w, monomials(j, 2) - 2) * monomials(j, 2) * (monomials(j, 2) - 1); + pow_int(u, monomials(j, 0) - 1) * + monomials(j, 0) * pow_int(v, monomials(j, 1)) * + pow_int(w, monomials(j, 2) - 2) * + monomials(j, 2) * (monomials(j, 2) - 1); if((monomials(j, 1) > 2)) - third[i][1][1][1] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1)-3) * monomials(j, 1) * - (monomials(j, 1) - 1) * (monomials(j, 1) - 2)* + third[i][1][1][1] += + coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1) - 3) * monomials(j, 1) * + (monomials(j, 1) - 1) * (monomials(j, 1) - 2) * pow_int(w, monomials(j, 2)); if((monomials(j, 1) > 1) && (monomials(j, 2) > 0)) - third[i][1][1][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1)-2) * monomials(j, 1) * (monomials(j, 1) - 1)* - pow_int(w, monomials(j, 2) - 1) *monomials(j, 2) ; + third[i][1][1][2] += + coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1) - 2) * monomials(j, 1) * + (monomials(j, 1) - 1) * pow_int(w, monomials(j, 2) - 1) * + monomials(j, 2); if((monomials(j, 1) > 0) && (monomials(j, 2) > 1)) - third[i][1][2][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1)-1) *monomials(j, 1)* - pow_int(w, monomials(j, 2) - 2) * monomials(j, 2) * (monomials(j, 2) - 1) ; + third[i][1][2][2] += + coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1) - 1) * monomials(j, 1) * + pow_int(w, monomials(j, 2) - 2) * monomials(j, 2) * + (monomials(j, 2) - 1); if((monomials(j, 2) > 2)) - third[i][2][2][2] += coefficients(i, j) * - pow_int(u, monomials(j, 0)) * - pow_int(v, monomials(j, 1))* - pow_int(w, monomials(j, 2) - 3) * monomials(j, 2) * - (monomials(j, 2) - 1) * (monomials(j, 2) - 2); + third[i][2][2][2] += + coefficients(i, j) * pow_int(u, monomials(j, 0)) * + pow_int(v, monomials(j, 1)) * pow_int(w, monomials(j, 2) - 3) * + monomials(j, 2) * (monomials(j, 2) - 1) * (monomials(j, 2) - 2); } third[i][0][1][0] = third[i][0][0][1]; third[i][1][0][0] = third[i][0][0][1]; diff --git a/Numeric/polynomialBasis.h b/Numeric/polynomialBasis.h index 6c984ff232ed56fbc72cdf99957cc659458f0bac..fdac16e11a7acd6cac67b649679dbba359acdb03 100644 --- a/Numeric/polynomialBasis.h +++ b/Numeric/polynomialBasis.h @@ -13,27 +13,30 @@ #include "nodalBasis.h" #include <iostream> - -class polynomialBasis : public nodalBasis -{ - public: +class polynomialBasis : public nodalBasis { +public: // for now the only implemented polynomial basis are nodal poly basis, we use // the type of the corresponding gmsh element as type fullMatrix<double> monomials; fullMatrix<double> coefficients; - polynomialBasis() {}; + polynomialBasis(){}; polynomialBasis(int tag); ~polynomialBasis(); - virtual inline int getNumShapeFunctions() const { return coefficients.size1(); } + virtual inline int getNumShapeFunctions() const + { + return coefficients.size1(); + } virtual void f(double u, double v, double w, double *sf) const; virtual void f(const fullMatrix<double> &coord, fullMatrix<double> &sf) const; - virtual void df(const fullMatrix<double> &coord, fullMatrix<double> &dfm) const; + virtual void df(const fullMatrix<double> &coord, + fullMatrix<double> &dfm) const; virtual void df(double u, double v, double w, double grads[][3]) const; virtual void ddf(double u, double v, double w, double hess[][3][3]) const; - virtual void dddf(double u, double v, double w, double third[][3][3][3]) const; + virtual void dddf(double u, double v, double w, + double third[][3][3][3]) const; void evaluateMonomials(double u, double v, double w, double p[]) const; }; diff --git a/Numeric/pyramidalBasis.cpp b/Numeric/pyramidalBasis.cpp index 6f14967e1ebd8acc7454bf74c0b146c3224ad377..bcde90007332ea2089fe9bc2f4ff481813230f9e 100644 --- a/Numeric/pyramidalBasis.cpp +++ b/Numeric/pyramidalBasis.cpp @@ -10,13 +10,12 @@ pyramidalBasis::pyramidalBasis(int tag) : nodalBasis(tag), bergot(0) { - if (serendip && order > 2) { - Msg::Warning("Serendipity pyramid for order %i not yet implemented", - order); + if(serendip && order > 2) { + Msg::Warning("Serendipity pyramid for order %i not yet implemented", order); return; } - bergot = new BergotBasis(order,serendip); + bergot = new BergotBasis(order, serendip); int num_points = points.size1(); @@ -25,30 +24,30 @@ pyramidalBasis::pyramidalBasis(int tag) : nodalBasis(tag), bergot(0) // Invert the Vandermonde matrix fullMatrix<double> VDM(num_points, num_points); - for (int j = 0; j < num_points; j++) { - bergot->f(points(j,0), points(j,1), points(j, 2), fval); - for (int i = 0; i < num_points; i++) VDM(i,j) = fval[i]; + for(int j = 0; j < num_points; j++) { + bergot->f(points(j, 0), points(j, 1), points(j, 2), fval); + for(int i = 0; i < num_points; i++) VDM(i, j) = fval[i]; } VDM.invert(bergotCoefficients); - coefficients.resize(num_points,num_points); - monomials.resize(num_points,3); + coefficients.resize(num_points, num_points); + monomials.resize(num_points, 3); int idx = 0; - for (int i=0;i<=order;i++) { - for (int j=0;j<=order;j++) { - if (bergot->validIJ(i,j)) { - for (int k=0;k<=order-std::max(i,j);k++,idx++) { - monomials(idx,0) = i; - monomials(idx,1) = j; - monomials(idx,2) = k; - - for (int l=0;l<num_points;l++) { - double oneMinW = std::max(1e-14,1-points(l,2)); - VDM(idx,l) = std::pow(points(l,0),i); - VDM(idx,l) *= std::pow(points(l,1),j); - VDM(idx,l) *= std::pow(points(l,2),k); - VDM(idx,l) *= std::pow(oneMinW,std::max(i,j)-i-j); + for(int i = 0; i <= order; i++) { + for(int j = 0; j <= order; j++) { + if(bergot->validIJ(i, j)) { + for(int k = 0; k <= order - std::max(i, j); k++, idx++) { + monomials(idx, 0) = i; + monomials(idx, 1) = j; + monomials(idx, 2) = k; + + for(int l = 0; l < num_points; l++) { + double oneMinW = std::max(1e-14, 1 - points(l, 2)); + VDM(idx, l) = std::pow(points(l, 0), i); + VDM(idx, l) *= std::pow(points(l, 1), j); + VDM(idx, l) *= std::pow(points(l, 2), k); + VDM(idx, l) *= std::pow(oneMinW, std::max(i, j) - i - j); } } } @@ -75,15 +74,16 @@ void pyramidalBasis::f(double u, double v, double w, double *val) const double *fval = new double[N]; bergot->f(u, v, w, fval); - for (int i = 0; i < N; i++) { + for(int i = 0; i < N; i++) { val[i] = 0.; - for (int j = 0; j < N; j++) val[i] += bergotCoefficients(i,j)*fval[j]; + for(int j = 0; j < N; j++) val[i] += bergotCoefficients(i, j) * fval[j]; } delete[] fval; } -void pyramidalBasis::f(const fullMatrix<double> &coord, fullMatrix<double> &sf) const +void pyramidalBasis::f(const fullMatrix<double> &coord, + fullMatrix<double> &sf) const { if(!bergot) return; @@ -92,11 +92,12 @@ void pyramidalBasis::f(const fullMatrix<double> &coord, fullMatrix<double> &sf) sf.resize(NPts, N); double *fval = new double[N]; - for (int iPt=0; iPt<NPts; iPt++) { - bergot->f(coord(iPt,0), coord(iPt,1), coord(iPt,2), fval); - for (int i = 0; i < N; i++) { - sf(iPt,i) = 0.; - for (int j = 0; j < N; j++) sf(iPt,i) += bergotCoefficients(i,j)*fval[j]; + for(int iPt = 0; iPt < NPts; iPt++) { + bergot->f(coord(iPt, 0), coord(iPt, 1), coord(iPt, 2), fval); + for(int i = 0; i < N; i++) { + sf(iPt, i) = 0.; + for(int j = 0; j < N; j++) + sf(iPt, i) += bergotCoefficients(i, j) * fval[j]; } } @@ -109,36 +110,39 @@ void pyramidalBasis::df(double u, double v, double w, double grads[][3]) const const int N = bergot->size(); - double (*dfval)[3] = new double[N][3]; + double(*dfval)[3] = new double[N][3]; bergot->df(u, v, w, dfval); - for (int i = 0; i < N; i++) { - grads[i][0] = 0.; grads[i][1] = 0.; grads[i][2] = 0.; - for (int j = 0; j < N; j++) { - grads[i][0] += bergotCoefficients(i,j)*dfval[j][0]; - grads[i][1] += bergotCoefficients(i,j)*dfval[j][1]; - grads[i][2] += bergotCoefficients(i,j)*dfval[j][2]; + for(int i = 0; i < N; i++) { + grads[i][0] = 0.; + grads[i][1] = 0.; + grads[i][2] = 0.; + for(int j = 0; j < N; j++) { + grads[i][0] += bergotCoefficients(i, j) * dfval[j][0]; + grads[i][1] += bergotCoefficients(i, j) * dfval[j][1]; + grads[i][2] += bergotCoefficients(i, j) * dfval[j][2]; } } delete[] dfval; } -void pyramidalBasis::df(const fullMatrix<double> &coord, fullMatrix<double> &dfm) const +void pyramidalBasis::df(const fullMatrix<double> &coord, + fullMatrix<double> &dfm) const { if(!bergot) return; const int N = bergot->size(), NPts = coord.size1(); - double (*dfv)[3] = new double[N][3]; - dfm.resize (3*NPts, N, false); + double(*dfv)[3] = new double[N][3]; + dfm.resize(3 * NPts, N, false); - for (int iPt=0; iPt<NPts; iPt++) { - df(coord(iPt,0), coord(iPt,1), coord(iPt,2), dfv); - for (int i = 0; i < N; i++) { - dfm(3*iPt+0, i) = dfv[i][0]; - dfm(3*iPt+1, i) = dfv[i][1]; - dfm(3*iPt+2, i) = dfv[i][2]; + for(int iPt = 0; iPt < NPts; iPt++) { + df(coord(iPt, 0), coord(iPt, 1), coord(iPt, 2), dfv); + for(int i = 0; i < N; i++) { + dfm(3 * iPt + 0, i) = dfv[i][0]; + dfm(3 * iPt + 1, i) = dfv[i][1]; + dfm(3 * iPt + 2, i) = dfv[i][2]; } } diff --git a/Numeric/pyramidalBasis.h b/Numeric/pyramidalBasis.h index 9a3a195a33f625ff820124ee8d28bd41290161fa..b861c7bbcd69a644feba9da41ebf7bab27508a66 100644 --- a/Numeric/pyramidalBasis.h +++ b/Numeric/pyramidalBasis.h @@ -10,24 +10,24 @@ #include "nodalBasis.h" #include "BergotBasis.h" -class pyramidalBasis: public nodalBasis -{ - private: +class pyramidalBasis : public nodalBasis { +private: // Orthogonal basis for the pyramid BergotBasis *bergot; fullMatrix<double> bergotCoefficients; - public: +public: fullMatrix<double> coefficients; fullMatrix<double> monomials; - public: +public: pyramidalBasis(int tag); ~pyramidalBasis(); virtual void f(double u, double v, double w, double *val) const; virtual void f(const fullMatrix<double> &coord, fullMatrix<double> &sf) const; virtual void df(double u, double v, double w, double grads[][3]) const; - virtual void df(const fullMatrix<double> &coord, fullMatrix<double> &dfm) const; + virtual void df(const fullMatrix<double> &coord, + fullMatrix<double> &dfm) const; virtual int getNumShapeFunctions() const; }; diff --git a/Numeric/simpleFunction.h b/Numeric/simpleFunction.h index 5ab01b8fea2e2558699c1a406f9febc62a1d94de..05702c302a09a70b9f7f69e8a126b32d25d462bc 100644 --- a/Numeric/simpleFunction.h +++ b/Numeric/simpleFunction.h @@ -9,65 +9,67 @@ // FIXME: Numeric/ should not depend on Geo/ class MElement; -template <class scalar> -class simpleFunction { - protected: +template <class scalar> class simpleFunction { +protected: scalar _val; bool _hasDerivatives; - public : - simpleFunction(scalar val =0.0) : _val(val), _hasDerivatives(false){} - virtual ~simpleFunction(){} - virtual bool hasDerivatives() {return _hasDerivatives;}; - virtual scalar operator () (double x, double y, double z) const { return _val; } + +public: + simpleFunction(scalar val = 0.0) : _val(val), _hasDerivatives(false) {} + virtual ~simpleFunction() {} + virtual bool hasDerivatives() { return _hasDerivatives; }; + virtual scalar operator()(double x, double y, double z) const { return _val; } virtual void setElement(MElement *e) const {} - virtual void gradient (double x, double y, double z, - scalar & dfdx, scalar & dfdy, scalar & dfdz) const - { dfdx = dfdy = dfdz = 0.0; } - virtual void hessian (double x, double y, double z, - scalar & dfdxx, scalar & dfdxy, scalar & dfdxz, - scalar & dfdyx, scalar & dfdyy, scalar & dfdyz, - scalar & dfdzx, scalar & dfdzy, scalar & dfdzz ) const - { dfdxx = dfdxy = dfdxz = 0.0; + virtual void gradient(double x, double y, double z, scalar &dfdx, + scalar &dfdy, scalar &dfdz) const + { + dfdx = dfdy = dfdz = 0.0; + } + virtual void hessian(double x, double y, double z, scalar &dfdxx, + scalar &dfdxy, scalar &dfdxz, scalar &dfdyx, + scalar &dfdyy, scalar &dfdyz, scalar &dfdzx, + scalar &dfdzy, scalar &dfdzz) const + { + dfdxx = dfdxy = dfdxz = 0.0; dfdyx = dfdyy = dfdyz = 0.0; - dfdzx = dfdzy = dfdzz = 0.0; } + dfdzx = dfdzy = dfdzz = 0.0; + } }; template <class scalar> -class constantPerElement : public simpleFunction<scalar> -{ - std::map<MElement *,scalar> _data; +class constantPerElement : public simpleFunction<scalar> { + std::map<MElement *, scalar> _data; mutable MElement *_e; - public : - constantPerElement () : _e(0){} - void set(MElement *e, scalar v) { - _data[e] = v; - } - void setElement(MElement *e) const { - _e = e; } - virtual scalar operator () (double x, double y, double z) const - { - if (!_e)return 0.0; - typename std::map<MElement *,scalar>::const_iterator it = _data.find(_e); - if (it == _data.end())return 0.0; + +public: + constantPerElement() : _e(0) {} + void set(MElement *e, scalar v) { _data[e] = v; } + void setElement(MElement *e) const { _e = e; } + virtual scalar operator()(double x, double y, double z) const + { + if(!_e) return 0.0; + typename std::map<MElement *, scalar>::const_iterator it = _data.find(_e); + if(it == _data.end()) return 0.0; return it->second; } }; - template <class scalar> -class simpleFunctionOnElement : public simpleFunction<scalar> -{ +class simpleFunctionOnElement : public simpleFunction<scalar> { mutable MElement *_e; - public : - simpleFunctionOnElement(scalar val=0) : simpleFunction<scalar>(val),_e(0) {} - virtual ~simpleFunctionOnElement(){} + +public: + simpleFunctionOnElement(scalar val = 0) : simpleFunction<scalar>(val), _e(0) + { + } + virtual ~simpleFunctionOnElement() {} void setElement(MElement *e) const { _e = e; } - MElement * getElement(void) const { return _e; } - MElement * getElement(double x, double y, double z) const + MElement *getElement(void) const { return _e; } + MElement *getElement(double x, double y, double z) const { - if (_e) return _e; - else - {// search + if(_e) + return _e; + else { // search } } }; diff --git a/Numeric/simpleFunctionPython.h b/Numeric/simpleFunctionPython.h index 56620b82637ffa502861e4581b99af39c47f31e4..6d155e5271eaa35450d687f4214c70814a6954d9 100644 --- a/Numeric/simpleFunctionPython.h +++ b/Numeric/simpleFunctionPython.h @@ -11,25 +11,21 @@ class simpleFunctionPython : public simpleFunction<double> { PyObject *_pycallback; - public: - simpleFunctionPython(PyObject *callback): - _pycallback(callback) + +public: + simpleFunctionPython(PyObject *callback) : _pycallback(callback) { Py_INCREF(_pycallback); } - ~simpleFunctionPython() - { - Py_DECREF(_pycallback); - } + ~simpleFunctionPython() { Py_DECREF(_pycallback); } double operator()(double x, double y, double z) const { PyObject *pyargs = Py_BuildValue("(ddd)", x, y, z); PyObject *result = PyEval_CallObject(_pycallback, pyargs); double r = 0; - if (result) { + if(result) { int ok = PyArg_Parse(result, "d", &r); - if (ok == 0) - Msg::Error("The python function did not return a double."); + if(ok == 0) Msg::Error("The python function did not return a double."); Py_DECREF(result); } else { diff --git a/Plugin/AnalyseCurvedMesh.cpp b/Plugin/AnalyseCurvedMesh.cpp index db19101475e4406f2e229a8e56633ea8b1b313b7..944a224f43b0f9c9d036673c6596d1df1fd7c91a 100644 --- a/Plugin/AnalyseCurvedMesh.cpp +++ b/Plugin/AnalyseCurvedMesh.cpp @@ -7,7 +7,6 @@ #if defined(HAVE_MESH) - #include "AnalyseCurvedMesh.h" #include "OS.h" #include "Context.h" @@ -35,16 +34,16 @@ StringXNumber CurvedMeshOptions_Number[] = { {GMSH_FULLRC, "Recompute", NULL, 0}, {GMSH_FULLRC, "DimensionOfElements", NULL, -1} #if defined(HAVE_VISUDEV) - ,{GMSH_FULLRC, "Element to draw quality", NULL, 0} + , + {GMSH_FULLRC, "Element to draw quality", NULL, 0} #endif }; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterAnalyseCurvedMeshPlugin() { - GMSH_Plugin *GMSH_RegisterAnalyseCurvedMeshPlugin() - { - return new GMSH_AnalyseCurvedMeshPlugin(); - } + return new GMSH_AnalyseCurvedMeshPlugin(); +} } int GMSH_AnalyseCurvedMeshPlugin::getNbOptions() const @@ -60,62 +59,71 @@ StringXNumber *GMSH_AnalyseCurvedMeshPlugin::getOption(int iopt) std::string GMSH_AnalyseCurvedMeshPlugin::getHelp() const { return "Plugin(AnalyseCurvedMesh) analyse all elements of a given dimension. " - "According to what is asked, it computes the minimum of the Jacobian " - "determinant (J), the IGE quality measure (Inverse Gradient Error) and/or " - "the ICN quality measure (Inverse Condition Number). " - "Statistics are printed and, if asked, a Pview is created for each measure. " - "The plugin hides elements for which the measure mu > 'Hiding threshold', " - "where mu is the ICN measure if asked otherwise the IGE measure if " - "asked otherwise the Jacobian determinant.\n" - "\n" - "J is faster to compute but gives information only on validity while the " - "other measure gives also information on quality.\n" - "The IGE measure is related to the error on the gradient of the finite " - "element solution. It is the scaled Jacobian for quads and hexes and a new " - "measure for triangles and tetrahedra.\n" - "The ICN measure is related to the condition number of the stiffness matrix.\n" - "(See article \"Efficient computation of the minimum of shape quality " - "measures on curvilinear finite elements\" for details.)\n" - "\n" - "Parameters:\n" - "\n" - "- JacobianDeterminant = {0, 1}\n" - "\n" - "- IGEMeasure = {0, 1}\n" - "\n" - "- ICNMeasure = {0, 1}\n" - "\n" - "- HidingThreshold = [0, 1]: Hides all element for which min(mu) is " - "strictly greater than the threshold, where mu is the ICN if ICN measure == 1, " - "otherwise mu is the IGE it IGE measure == 1, " - "otherwise mu is the Jacobian determinant.\n" - "If threshold == 0, hides all elements except invalid.\n" - "\n" - "- DrawPView = {0, 1}: Creates a PView of min(J)/max(J), min(IGE) " - "and/or min(ICN) according to what is asked. If 'Recompute' = 1, " - "new PViews are created.\n" - "\n" - "- Recompute = {0,1}: Should be 1 if the mesh has changed.\n" - "\n" - "- DimensionOfElements = {-1, 1, 2, 3, 4}: If == -1, analyse element of the " - "greater dimension. If == 4, analyse 2D and 3D elements."; + "According to what is asked, it computes the minimum of the Jacobian " + "determinant (J), the IGE quality measure (Inverse Gradient Error) " + "and/or " + "the ICN quality measure (Inverse Condition Number). " + "Statistics are printed and, if asked, a Pview is created for each " + "measure. " + "The plugin hides elements for which the measure mu > 'Hiding " + "threshold', " + "where mu is the ICN measure if asked otherwise the IGE measure if " + "asked otherwise the Jacobian determinant.\n" + "\n" + "J is faster to compute but gives information only on validity while " + "the " + "other measure gives also information on quality.\n" + "The IGE measure is related to the error on the gradient of the " + "finite " + "element solution. It is the scaled Jacobian for quads and hexes and " + "a new " + "measure for triangles and tetrahedra.\n" + "The ICN measure is related to the condition number of the stiffness " + "matrix.\n" + "(See article \"Efficient computation of the minimum of shape quality " + "measures on curvilinear finite elements\" for details.)\n" + "\n" + "Parameters:\n" + "\n" + "- JacobianDeterminant = {0, 1}\n" + "\n" + "- IGEMeasure = {0, 1}\n" + "\n" + "- ICNMeasure = {0, 1}\n" + "\n" + "- HidingThreshold = [0, 1]: Hides all element for which min(mu) is " + "strictly greater than the threshold, where mu is the ICN if ICN " + "measure == 1, " + "otherwise mu is the IGE it IGE measure == 1, " + "otherwise mu is the Jacobian determinant.\n" + "If threshold == 0, hides all elements except invalid.\n" + "\n" + "- DrawPView = {0, 1}: Creates a PView of min(J)/max(J), min(IGE) " + "and/or min(ICN) according to what is asked. If 'Recompute' = 1, " + "new PViews are created.\n" + "\n" + "- Recompute = {0,1}: Should be 1 if the mesh has changed.\n" + "\n" + "- DimensionOfElements = {-1, 1, 2, 3, 4}: If == -1, analyse element " + "of the " + "greater dimension. If == 4, analyse 2D and 3D elements."; } -PView* GMSH_AnalyseCurvedMeshPlugin::execute(PView *v) +PView *GMSH_AnalyseCurvedMeshPlugin::execute(PView *v) { _m = GModel::current(); int computeJac = static_cast<int>(CurvedMeshOptions_Number[0].def); int computeIGE = static_cast<int>(CurvedMeshOptions_Number[1].def); int computeICN = static_cast<int>(CurvedMeshOptions_Number[2].def); - _threshold = CurvedMeshOptions_Number[3].def; + _threshold = CurvedMeshOptions_Number[3].def; bool drawPView = static_cast<bool>(CurvedMeshOptions_Number[4].def); bool recompute = static_cast<bool>(CurvedMeshOptions_Number[5].def); - int askedDim = static_cast<int>(CurvedMeshOptions_Number[6].def); + int askedDim = static_cast<int>(CurvedMeshOptions_Number[6].def); #if defined(HAVE_VISUDEV) - _pwJac = computeJac/2; - _pwIGE = computeIGE/2; - _pwICN = computeICN/2; + _pwJac = computeJac / 2; + _pwIGE = computeIGE / 2; + _pwICN = computeICN / 2; _numElementToScan = static_cast<int>(CurvedMeshOptions_Number[7].def); _viewOrder = 0; @@ -124,17 +132,17 @@ PView* GMSH_AnalyseCurvedMeshPlugin::execute(PView *v) _dataPViewICN.clear(); #endif - if (askedDim < 0 || askedDim > 4) askedDim = _m->getDim(); + if(askedDim < 0 || askedDim > 4) askedDim = _m->getDim(); - if (recompute) { + if(recompute) { _data.clear(); - if (askedDim < 4) { - _computedJac[askedDim-1] = false; - _computedIGE[askedDim-1] = false; - _computedICN[askedDim-1] = false; - _PViewJac[askedDim-1] = false; - _PViewIGE[askedDim-1] = false; - _PViewICN[askedDim-1] = false; + if(askedDim < 4) { + _computedJac[askedDim - 1] = false; + _computedIGE[askedDim - 1] = false; + _computedICN[askedDim - 1] = false; + _PViewJac[askedDim - 1] = false; + _PViewIGE[askedDim - 1] = false; + _PViewICN[askedDim - 1] = false; } else { _computedJac[1] = _computedJac[2] = false; @@ -150,101 +158,101 @@ PView* GMSH_AnalyseCurvedMeshPlugin::execute(PView *v) bool printStatJ = false; bool printStatS = false; bool printStatI = false; - for (int dim = 1; dim <= 3 && dim <= _m->getDim(); ++dim) { - if ((askedDim == 4 && dim > 1) || dim == askedDim) { - if (!_computedJac[dim-1]) { + for(int dim = 1; dim <= 3 && dim <= _m->getDim(); ++dim) { + if((askedDim == 4 && dim > 1) || dim == askedDim) { + if(!_computedJac[dim - 1]) { double time = Cpu(); Msg::StatusBar(true, "Computing Jacobian for %dD elements...", dim); _computeMinMaxJandValidity(dim); Msg::StatusBar(true, "Done computing Jacobian for %dD elements (%g s)", - dim, Cpu()-time); + dim, Cpu() - time); printStatJ = true; } - if (computeIGE && !_computedIGE[dim-1]) { + if(computeIGE && !_computedIGE[dim - 1]) { double time = Cpu(); Msg::StatusBar(true, "Computing IGE for %dD elements...", dim); _computeMinIGE(dim); - Msg::StatusBar(true, "Done computing IGE for %dD elements (%g s)", - dim, Cpu()-time); + Msg::StatusBar(true, "Done computing IGE for %dD elements (%g s)", dim, + Cpu() - time); printStatS = true; } - if (computeICN && !_computedICN[dim-1]) { + if(computeICN && !_computedICN[dim - 1]) { double time = Cpu(); Msg::StatusBar(true, "Computing ICN for %dD elements...", dim); _computeMinICN(dim); - Msg::StatusBar(true, "Done computing ICN for %dD elements (%g s)", - dim, Cpu()-time); + Msg::StatusBar(true, "Done computing ICN for %dD elements (%g s)", dim, + Cpu() - time); printStatI = true; } } } - if (printStatJ) _printStatJacobian(); - if (printStatS) _printStatIGE(); - if (printStatI) _printStatICN(); + if(printStatJ) _printStatJacobian(); + if(printStatS) _printStatIGE(); + if(printStatI) _printStatICN(); #if defined(HAVE_VISUDEV) _createPViewPointwise(); #endif // Create PView - if (drawPView) - for (int dim = 1; dim <= 3; ++dim) { - if ((askedDim == 4 && dim > 1) || dim == askedDim) { - if (!_PViewJac[dim-1] && computeJac) { - _PViewJac[dim-1] = true; - std::map<int, std::vector<double> > dataPV; - for (unsigned int i = 0; i < _data.size(); ++i) { - MElement *const el = _data[i].element(); - if (el->getDim() == dim) { - double q = 0; - if (_data[i].maxJ() > 0) q = _data[i].minJ() / _data[i].maxJ(); - else if (_data[i].maxJ() < 0) q = _data[i].maxJ() / _data[i].minJ(); - dataPV[el->getNum()].push_back(q); + if(drawPView) + for(int dim = 1; dim <= 3; ++dim) { + if((askedDim == 4 && dim > 1) || dim == askedDim) { + if(!_PViewJac[dim - 1] && computeJac) { + _PViewJac[dim - 1] = true; + std::map<int, std::vector<double> > dataPV; + for(unsigned int i = 0; i < _data.size(); ++i) { + MElement *const el = _data[i].element(); + if(el->getDim() == dim) { + double q = 0; + if(_data[i].maxJ() > 0) + q = _data[i].minJ() / _data[i].maxJ(); + else if(_data[i].maxJ() < 0) + q = _data[i].maxJ() / _data[i].minJ(); + dataPV[el->getNum()].push_back(q); + } + } + if(dataPV.size()) { + std::stringstream name; + name << "minJ/maxJ " << dim << "D"; + new PView(name.str().c_str(), "ElementData", _m, dataPV); } } - if (dataPV.size()) { - std::stringstream name; - name << "minJ/maxJ " << dim << "D"; - new PView(name.str().c_str(), "ElementData", _m, dataPV); - } - } - if (!_PViewIGE[dim-1] && computeIGE) { - _PViewIGE[dim-1] = true; - std::map<int, std::vector<double> > dataPV; - for (unsigned int i = 0; i < _data.size(); ++i) { - MElement *const el = _data[i].element(); - if (el->getDim() == dim) - dataPV[el->getNum()].push_back(_data[i].minS()); - } - if (dataPV.size()) { - std::stringstream name; - name << "IGE " << dim << "D"; - new PView(name.str().c_str(), "ElementData", _m, dataPV); - } - } - if (!_PViewICN[dim-1] && computeICN) { - _PViewICN[dim-1] = true; - std::map<int, std::vector<double> > dataPV; - for (unsigned int i = 0; i < _data.size(); ++i) { - MElement *const el = _data[i].element(); - if (el->getDim() == dim) - dataPV[el->getNum()].push_back(_data[i].minI()); + if(!_PViewIGE[dim - 1] && computeIGE) { + _PViewIGE[dim - 1] = true; + std::map<int, std::vector<double> > dataPV; + for(unsigned int i = 0; i < _data.size(); ++i) { + MElement *const el = _data[i].element(); + if(el->getDim() == dim) + dataPV[el->getNum()].push_back(_data[i].minS()); + } + if(dataPV.size()) { + std::stringstream name; + name << "IGE " << dim << "D"; + new PView(name.str().c_str(), "ElementData", _m, dataPV); + } } - if (dataPV.size()) { - std::stringstream name; - name << "ICN " << dim << "D"; - new PView(name.str().c_str(), "ElementData", _m, dataPV); + if(!_PViewICN[dim - 1] && computeICN) { + _PViewICN[dim - 1] = true; + std::map<int, std::vector<double> > dataPV; + for(unsigned int i = 0; i < _data.size(); ++i) { + MElement *const el = _data[i].element(); + if(el->getDim() == dim) + dataPV[el->getNum()].push_back(_data[i].minI()); + } + if(dataPV.size()) { + std::stringstream name; + name << "ICN " << dim << "D"; + new PView(name.str().c_str(), "ElementData", _m, dataPV); + } } } } - } - // Hide elements + // Hide elements #if defined(HAVE_OPENGL) _hideWithThreshold(askedDim, - computeICN ? 2 : - computeIGE ? 1 : - computeJac ? 0 : -1); + computeICN ? 2 : computeIGE ? 1 : computeJac ? 0 : -1); CTX::instance()->mesh.changed = (ENT_ALL); drawContext::global()->draw(); #endif @@ -254,116 +262,113 @@ PView* GMSH_AnalyseCurvedMeshPlugin::execute(PView *v) void GMSH_AnalyseCurvedMeshPlugin::_computeMinMaxJandValidity(int dim) { - if (_computedJac[dim-1]) return; - - std::set<GEntity*, GEntityLessThan> entities; - switch (dim) { - case 3: - for (GModel::riter it = _m->firstRegion(); it != _m->lastRegion(); it++) - entities.insert(*it); - break; - case 2: - for (GModel::fiter it = _m->firstFace(); it != _m->lastFace(); it++) - entities.insert(*it); - break; - case 1: - for (GModel::eiter it = _m->firstEdge(); it != _m->lastEdge(); it++) - entities.insert(*it); - break; - default: - Msg::Fatal("This should not happen."); - return; + if(_computedJac[dim - 1]) return; + + std::set<GEntity *, GEntityLessThan> entities; + switch(dim) { + case 3: + for(GModel::riter it = _m->firstRegion(); it != _m->lastRegion(); it++) + entities.insert(*it); + break; + case 2: + for(GModel::fiter it = _m->firstFace(); it != _m->lastFace(); it++) + entities.insert(*it); + break; + case 1: + for(GModel::eiter it = _m->firstEdge(); it != _m->lastEdge(); it++) + entities.insert(*it); + break; + default: Msg::Fatal("This should not happen."); return; } int cntInverted = 0; - std::set<GEntity*, GEntityLessThan>::iterator it; - for (it = entities.begin(); it != entities.end(); ++it) { + std::set<GEntity *, GEntityLessThan>::iterator it; + for(it = entities.begin(); it != entities.end(); ++it) { GEntity *entity = *it; unsigned num = entity->getNumMeshElements(); fullMatrix<double> *normals = NULL; - switch (dim) { - case 3: - Msg::StatusBar(true, "Volume %d: checking the Jacobian of %d elements", - entity->tag(), num); - break; - case 2: - Msg::StatusBar(true, "Surface %d: checking the Jacobian of %d elements", - entity->tag(), num); - if (entity->geomType() == GEntity::Plane && - entity->haveParametrization()) { - double u = entity->parBounds(0).low(); - double v = entity->parBounds(1).low(); - SVector3 n = dynamic_cast<GFace*>(entity)->normal(SPoint2(u, v)); + switch(dim) { + case 3: + Msg::StatusBar(true, "Volume %d: checking the Jacobian of %d elements", + entity->tag(), num); + break; + case 2: + Msg::StatusBar(true, "Surface %d: checking the Jacobian of %d elements", + entity->tag(), num); + if(entity->geomType() == GEntity::Plane && + entity->haveParametrization()) { + double u = entity->parBounds(0).low(); + double v = entity->parBounds(1).low(); + SVector3 n = dynamic_cast<GFace *>(entity)->normal(SPoint2(u, v)); + normals = new fullMatrix<double>(1, 3); + normals->set(0, 0, n[0]); + normals->set(0, 1, n[1]); + normals->set(0, 2, n[2]); + } + else if(entity->geomType() == GEntity::DiscreteSurface) { + SBoundingBox3d bb = entity->bounds(); + // If we don't have the CAD, check if the mesh is 2D: + if(!bb.empty() && bb.max().z() - bb.min().z() == .0) { normals = new fullMatrix<double>(1, 3); - normals->set(0, 0, n[0]); - normals->set(0, 1, n[1]); - normals->set(0, 2, n[2]); - } - else if (entity->geomType() == GEntity::DiscreteSurface) { - SBoundingBox3d bb = entity->bounds(); - // If we don't have the CAD, check if the mesh is 2D: - if (!bb.empty() && bb.max().z() - bb.min().z() == .0) { - normals = new fullMatrix<double>(1, 3); - normals->set(0, 0, 0); - normals->set(0, 1, 0); - normals->set(0, 2, 1); - } + normals->set(0, 0, 0); + normals->set(0, 1, 0); + normals->set(0, 2, 1); } - break; - case 1: - Msg::StatusBar(true, "Line %d: checking the Jacobian of %d elements", - entity->tag(), num); - if (entity->geomType() == GEntity::Line && - entity->haveParametrization()) { - double u = entity->parBounds(0).low(); - SVector3 t = dynamic_cast<GEdge*>(entity)->firstDer(u); - SVector3 dum = SVector3(0, 0, 0); - if(t[0] == 0.) - dum[0] = 1; - else if(t[1] == 0.) - dum[1] = 1; - else - dum[2] = 1; - SVector3 n1, n2; - n1 = crossprod(t, dum); - n1.normalize(); - n2 = crossprod(t, n1); - n2.normalize(); + } + break; + case 1: + Msg::StatusBar(true, "Line %d: checking the Jacobian of %d elements", + entity->tag(), num); + if(entity->geomType() == GEntity::Line && entity->haveParametrization()) { + double u = entity->parBounds(0).low(); + SVector3 t = dynamic_cast<GEdge *>(entity)->firstDer(u); + SVector3 dum = SVector3(0, 0, 0); + if(t[0] == 0.) + dum[0] = 1; + else if(t[1] == 0.) + dum[1] = 1; + else + dum[2] = 1; + SVector3 n1, n2; + n1 = crossprod(t, dum); + n1.normalize(); + n2 = crossprod(t, n1); + n2.normalize(); + normals = new fullMatrix<double>(2, 3); + normals->set(0, 0, n1[0]); + normals->set(0, 1, n1[1]); + normals->set(0, 2, n1[2]); + normals->set(1, 0, n2[0]); + normals->set(1, 1, n2[1]); + normals->set(1, 2, n2[2]); + } + else if(entity->geomType() == GEntity::DiscreteCurve) { + SBoundingBox3d bb = entity->bounds(); + // If we don't have the CAD, check if the mesh is 1D: + if(!bb.empty() && bb.max().y() - bb.min().y() == .0 && + bb.max().z() - bb.min().z() == .0) { normals = new fullMatrix<double>(2, 3); - normals->set(0, 0, n1[0]); - normals->set(0, 1, n1[1]); - normals->set(0, 2, n1[2]); - normals->set(1, 0, n2[0]); - normals->set(1, 1, n2[1]); - normals->set(1, 2, n2[2]); + normals->set(0, 0, 0); + normals->set(0, 1, 1); + normals->set(0, 2, 0); + normals->set(1, 0, 0); + normals->set(1, 1, 0); + normals->set(1, 2, 1); } - else if (entity->geomType() == GEntity::DiscreteCurve) { - SBoundingBox3d bb = entity->bounds(); - // If we don't have the CAD, check if the mesh is 1D: - if (!bb.empty() && bb.max().y() - bb.min().y() == .0 && - bb.max().z() - bb.min().z() == .0) { - normals = new fullMatrix<double>(2, 3); - normals->set(0, 0, 0); - normals->set(0, 1, 1); - normals->set(0, 2, 0); - normals->set(1, 0, 0); - normals->set(1, 1, 0); - normals->set(1, 2, 1); - } - } - break; - default: break; + } + break; + default: break; } MsgProgressStatus progress(num); - _data.reserve(_data.size()+num); - for (unsigned i = 0; i < num; ++i) { + _data.reserve(_data.size() + num); + for(unsigned i = 0; i < num; ++i) { MElement *el = entity->getMeshElement(i); double min, max; jacobianBasedQuality::minMaxJacobianDeterminant(el, min, max, normals); _data.push_back(data_elementMinMax(el, min, max)); - if (min < 0 && max < 0) ++cntInverted; + if(min < 0 && max < 0) ++cntInverted; progress.next(); #if defined(HAVE_VISUDEV) @@ -372,22 +377,22 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinMaxJandValidity(int dim) } delete normals; } - if (cntInverted) { + if(cntInverted) { Msg::Warning("%d elements are completely inverted", cntInverted); } - _computedJac[dim-1] = true; + _computedJac[dim - 1] = true; } void GMSH_AnalyseCurvedMeshPlugin::_computeMinIGE(int dim) { - if (_computedIGE[dim-1]) return; + if(_computedIGE[dim - 1]) return; MsgProgressStatus progress(_data.size()); - for (unsigned int i = 0; i < _data.size(); ++i) { + for(unsigned int i = 0; i < _data.size(); ++i) { MElement *const el = _data[i].element(); - if (el->getDim() != dim) continue; - if (_data[i].minJ() <= 0 && _data[i].maxJ() > 0) { + if(el->getDim() != dim) continue; + if(_data[i].minJ() <= 0 && _data[i].maxJ() > 0) { _data[i].setMinS(0); } else { @@ -396,19 +401,19 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinIGE(int dim) progress.next(); } - _computedIGE[dim-1] = true; + _computedIGE[dim - 1] = true; } void GMSH_AnalyseCurvedMeshPlugin::_computeMinICN(int dim) { - if (_computedICN[dim-1]) return; + if(_computedICN[dim - 1]) return; MsgProgressStatus progress(_data.size()); - for (unsigned int i = 0; i < _data.size(); ++i) { + for(unsigned int i = 0; i < _data.size(); ++i) { MElement *const el = _data[i].element(); - if (el->getDim() != dim) continue; - if (_data[i].minJ() <= 0 && _data[i].maxJ() > 0) { + if(el->getDim() != dim) continue; + if(_data[i].minJ() <= 0 && _data[i].maxJ() > 0) { _data[i].setMinI(0); } else { @@ -417,33 +422,28 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinICN(int dim) progress.next(); } - _computedICN[dim-1] = true; + _computedICN[dim - 1] = true; } -int GMSH_AnalyseCurvedMeshPlugin::_hideWithThreshold(int askedDim, int whichMeasure) +int GMSH_AnalyseCurvedMeshPlugin::_hideWithThreshold(int askedDim, + int whichMeasure) { // only hide for quality measures - if (_threshold > 1 || whichMeasure == 0) return 0; + if(_threshold > 1 || whichMeasure == 0) return 0; int nHidden = 0; - for (unsigned int i = 0; i < _data.size(); ++i) { + for(unsigned int i = 0; i < _data.size(); ++i) { MElement *const el = _data[i].element(); const int dim = el->getDim(); - if ((askedDim == 4 && dim > 1) || dim == askedDim) { + if((askedDim == 4 && dim > 1) || dim == askedDim) { bool toHide = false; - switch (whichMeasure) { - case 2: - toHide = _data[i].minI() > _threshold; - break; - case 1: - toHide = _data[i].minS() > _threshold; - break; - case 0: - toHide = _data[i].minJ() > _threshold; - break; + switch(whichMeasure) { + case 2: toHide = _data[i].minI() > _threshold; break; + case 1: toHide = _data[i].minS() > _threshold; break; + case 0: toHide = _data[i].minJ() > _threshold; break; } - if (toHide) { + if(toHide) { el->setVisibility(0); ++nHidden; } @@ -457,7 +457,7 @@ int GMSH_AnalyseCurvedMeshPlugin::_hideWithThreshold(int askedDim, int whichMeas void GMSH_AnalyseCurvedMeshPlugin::_printStatJacobian() { - if (_data.empty()) { + if(_data.empty()) { Msg::Info("No stat to print."); return; } @@ -470,19 +470,21 @@ void GMSH_AnalyseCurvedMeshPlugin::_printStatJacobian() supminJ = supratJ = -1e10; avgminJ = avgratJ = avgratJc = 0; - for (unsigned int i = 0; i < _data.size(); ++i) { + for(unsigned int i = 0; i < _data.size(); ++i) { infminJ = std::min(infminJ, _data[i].minJ()); supminJ = std::max(supminJ, _data[i].minJ()); avgminJ += _data[i].minJ(); double q = 0; - if (_data[i].maxJ() > 0) q = _data[i].minJ() / _data[i].maxJ(); - else if (_data[i].maxJ() < 0) q = _data[i].maxJ() / _data[i].minJ(); + if(_data[i].maxJ() > 0) + q = _data[i].minJ() / _data[i].maxJ(); + else if(_data[i].maxJ() < 0) + q = _data[i].maxJ() / _data[i].minJ(); infratJ = std::min(infratJ, q); supratJ = std::max(supratJ, q); avgratJ += q; - if (q < 1-1e-5) { - avgratJc += _data[i].minJ()/_data[i].maxJ(); + if(q < 1 - 1e-5) { + avgratJc += _data[i].minJ() / _data[i].maxJ(); ++countc; } @@ -492,132 +494,129 @@ void GMSH_AnalyseCurvedMeshPlugin::_printStatJacobian() avgratJ /= count; avgratJc /= countc; - Msg::Info("minJ = %8.3g, %8.3g, %8.3g (min, avg, max)", - infminJ, avgminJ, supminJ); - if (countc && countc < count) + Msg::Info("minJ = %8.3g, %8.3g, %8.3g (min, avg, max)", infminJ, avgminJ, + supminJ); + if(countc && countc < count) Msg::Info("minJ/maxJ = %8.3f (avg on the %d " - "non-constant elements)", + "non-constant elements)", avgratJc, countc); - Msg::Info("minJ/maxJ = %8.3f, %8.3f, %8.3f (worst, avg, best)", - infratJ, avgratJ, supratJ); + Msg::Info("minJ/maxJ = %8.3f, %8.3f, %8.3f (worst, avg, best)", infratJ, + avgratJ, supratJ); } void GMSH_AnalyseCurvedMeshPlugin::_printStatIGE() { - if (_data.empty()) { + if(_data.empty()) { Msg::Info("No stat to print."); return; } double infminS, supminS, avgminS; infminS = supminS = avgminS = _data[0].minS(); - for (unsigned int i = 1; i < _data.size(); ++i) { + for(unsigned int i = 1; i < _data.size(); ++i) { infminS = std::min(infminS, _data[i].minS()); supminS = std::max(supminS, _data[i].minS()); avgminS += _data[i].minS(); } avgminS /= _data.size(); - Msg::Info("IGE = %8.3f, %8.3f, %8.3f (worst, avg, best)", - infminS, avgminS, supminS); + Msg::Info("IGE = %8.3f, %8.3f, %8.3f (worst, avg, best)", infminS, + avgminS, supminS); } void GMSH_AnalyseCurvedMeshPlugin::_printStatICN() { - if (_data.empty()) { + if(_data.empty()) { Msg::Info("No stat to print."); return; } double infminI, supminI, avgminI; infminI = supminI = avgminI = _data[0].minI(); - for (unsigned int i = 1; i < _data.size(); ++i) { + for(unsigned int i = 1; i < _data.size(); ++i) { infminI = std::min(infminI, _data[i].minI()); supminI = std::max(supminI, _data[i].minI()); avgminI += _data[i].minI(); } avgminI /= _data.size(); - Msg::Info("ICN = %8.3f, %8.3f, %8.3f (worst, avg, best)", - infminI, avgminI, supminI); + Msg::Info("ICN = %8.3f, %8.3f, %8.3f (worst, avg, best)", infminI, + avgminI, supminI); } #if defined(HAVE_VISUDEV) -void GMSH_AnalyseCurvedMeshPlugin::_computePointwiseQuantities(MElement *el, - const fullMatrix<double> *normals) { - if (_numElementToScan != -1 && el->getNum() != _numElementToScan) return; +void GMSH_AnalyseCurvedMeshPlugin::_computePointwiseQuantities( + MElement *el, const fullMatrix<double> *normals) +{ + if(_numElementToScan != -1 && el->getNum() != _numElementToScan) return; - if (!_type2tag[el->getType()]) + if(!_type2tag[el->getType()]) _type2tag[el->getType()] = el->getTypeForMSH(); else // Skip if element tag is different from previous elements of same type - if (_type2tag[el->getType()] != el->getTypeForMSH()) return; + if(_type2tag[el->getType()] != el->getTypeForMSH()) + return; static fullVector<double> tmpVector; int num = el->getNum(); - if (!_viewOrder) { -// _viewOrder = std::min(10, 2 * el->getPolynomialOrder()); + if(!_viewOrder) { + // _viewOrder = std::min(10, 2 * el->getPolynomialOrder()); _viewOrder = 9; } - if (_pwJac) { + if(_pwJac) { jacobianBasedQuality::sampleJacobian(el, _viewOrder, tmpVector, normals); std::vector<double> &vec = _dataPViewJac[num]; - for (int j = 0; j < tmpVector.size(); ++j) - vec.push_back(tmpVector(j)); + for(int j = 0; j < tmpVector.size(); ++j) vec.push_back(tmpVector(j)); } - if (_pwIGE) { + if(_pwIGE) { jacobianBasedQuality::sampleIGEMeasure(el, _viewOrder, tmpVector); std::vector<double> &vec = _dataPViewIGE[num]; - for (int j = 0; j < tmpVector.size(); ++j) - vec.push_back(tmpVector(j)); + for(int j = 0; j < tmpVector.size(); ++j) vec.push_back(tmpVector(j)); } - if (_pwICN) { -// jacobianBasedQuality::sampleICNMeasure(el, _viewOrder, tmpVector); -// std::vector<double> &vec = _dataPViewICN[num]; -// for (int j = 0; j < tmpVector.size(); ++j) -// vec.push_back(tmpVector(j)); + if(_pwICN) { + // jacobianBasedQuality::sampleICNMeasure(el, _viewOrder, tmpVector); + // std::vector<double> &vec = _dataPViewICN[num]; + // for (int j = 0; j < tmpVector.size(); ++j) + // vec.push_back(tmpVector(j)); } } void GMSH_AnalyseCurvedMeshPlugin::_setInterpolationMatrices(PView *view) { PViewData *viewData = view->getData(); - for (int type = 0; type < 20; ++type) { - if (!_type2tag[type]) continue; + for(int type = 0; type < 20; ++type) { + if(!_type2tag[type]) continue; viewData->deleteInterpolationMatrices(type); const nodalBasis *fsE = BasisFactory::getNodalBasis(_type2tag[type]); const polynomialBasis *pfsE = dynamic_cast<const polynomialBasis *>(fsE); const int hoTag = ElementType::getType(type, _viewOrder); const nodalBasis *fsV = BasisFactory::getNodalBasis(hoTag); const polynomialBasis *pfsV = dynamic_cast<const polynomialBasis *>(fsV); - viewData->setInterpolationMatrices(type, - pfsV->coefficients, pfsV->monomials, - pfsE->coefficients, pfsE->monomials); + viewData->setInterpolationMatrices(type, pfsV->coefficients, + pfsV->monomials, pfsE->coefficients, + pfsE->monomials); } } void GMSH_AnalyseCurvedMeshPlugin::_createPViewPointwise() { - if (_pwJac) { - _setInterpolationMatrices( - new PView("Pointwise Jacobian", "ElementNodeData", _m, _dataPViewJac, 0, 1) - ); + if(_pwJac) { + _setInterpolationMatrices(new PView("Pointwise Jacobian", "ElementNodeData", + _m, _dataPViewJac, 0, 1)); } - if (_pwIGE) { + if(_pwIGE) { _setInterpolationMatrices( - new PView("Pointwise IGE", "ElementNodeData", _m, _dataPViewIGE, 0, 1) - ); + new PView("Pointwise IGE", "ElementNodeData", _m, _dataPViewIGE, 0, 1)); } - if (_pwICN) { + if(_pwICN) { _setInterpolationMatrices( - new PView("Pointwise ICN", "ElementNodeData", _m, _dataPViewICN, 0, 1) - ); + new PView("Pointwise ICN", "ElementNodeData", _m, _dataPViewICN, 0, 1)); } } #endif diff --git a/Plugin/AnalyseCurvedMesh.h b/Plugin/AnalyseCurvedMesh.h index 8e93f3b5683c082aea0a98df17fd16f2fea91de1..3b7e9d421bc332ced2a3de67c9dbe8152e4a1380 100644 --- a/Plugin/AnalyseCurvedMesh.h +++ b/Plugin/AnalyseCurvedMesh.h @@ -10,33 +10,32 @@ #include <vector> class MElement; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterAnalyseCurvedMeshPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterAnalyseCurvedMeshPlugin(); } -class data_elementMinMax -{ +class data_elementMinMax { private: MElement *_el; double _minJac, _maxJac, _minIGE, _minICN; + public: - data_elementMinMax(MElement *e, - double minJ = 2, double maxJ = 0, + data_elementMinMax(MElement *e, double minJ = 2, double maxJ = 0, double minIGE = -1, double minICN = -1) - : _el(e), _minJac(minJ), _maxJac(maxJ), _minIGE(minIGE), _minICN(minICN) {} + : _el(e), _minJac(minJ), _maxJac(maxJ), _minIGE(minIGE), _minICN(minICN) + { + } void setMinS(double r) { _minIGE = r; } void setMinI(double r) { _minICN = r; } - MElement* element() { return _el; } + MElement *element() { return _el; } double minJ() { return _minJac; } double maxJ() { return _maxJac; } double minS() { return _minIGE; } double minI() { return _minICN; } }; -class GMSH_AnalyseCurvedMeshPlugin : public GMSH_PostPlugin -{ -private : +class GMSH_AnalyseCurvedMeshPlugin : public GMSH_PostPlugin { +private: GModel *_m; double _threshold; @@ -57,18 +56,18 @@ private : std::vector<data_elementMinMax> _data; -public : +public: GMSH_AnalyseCurvedMeshPlugin() { _m = NULL; _threshold = -1; - for (int i = 0; i < 3; ++i) { + for(int i = 0; i < 3; ++i) { _computedJac[i] = false; _computedIGE[i] = false; _computedICN[i] = false; _PViewJac[i] = false; _PViewIGE[i] = false; - _PViewICN [i] = false; + _PViewICN[i] = false; } } std::string getName() const { return "AnalyseCurvedMesh"; } @@ -79,10 +78,10 @@ public : std::string getHelp() const; std::string getAuthor() const { return "Amaury Johnen"; } int getNbOptions() const; - StringXNumber* getOption(int); - PView* execute(PView *); + StringXNumber *getOption(int); + PView *execute(PView *); -private : +private: void _computeMinMaxJandValidity(int dim); void _computeMinIGE(int dim); void _computeMinICN(int dim); @@ -92,7 +91,8 @@ private : void _printStatICN(); #if defined(HAVE_VISUDEV) - void _computePointwiseQuantities(MElement *, const fullMatrix<double> *normals); + void _computePointwiseQuantities(MElement *, + const fullMatrix<double> *normals); void _createPViewPointwise(); void _setInterpolationMatrices(PView *); #endif diff --git a/Plugin/Annotate.cpp b/Plugin/Annotate.cpp index 38205d9b0ea191a9bc8b86ecf80fef446183dff5..e430093852d398413d95a8f1c3478ff92ce18668 100644 --- a/Plugin/Annotate.cpp +++ b/Plugin/Annotate.cpp @@ -18,33 +18,27 @@ StringXNumber AnnotateOptions_Number[] = { {GMSH_FULLRC, "Z", GMSH_AnnotatePlugin::callbackZ, 0.}, {GMSH_FULLRC, "ThreeD", GMSH_AnnotatePlugin::callback3D, 0.}, {GMSH_FULLRC, "FontSize", GMSH_AnnotatePlugin::callbackFontSize, 14.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; StringXString AnnotateOptions_String[] = { {GMSH_FULLRC, "Text", GMSH_AnnotatePlugin::callbackText, "My Text"}, {GMSH_FULLRC, "Font", GMSH_AnnotatePlugin::callbackFont, "Helvetica"}, - {GMSH_FULLRC, "Align", GMSH_AnnotatePlugin::callbackAlign, "Left"} -}; + {GMSH_FULLRC, "Align", GMSH_AnnotatePlugin::callbackAlign, "Left"}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterAnnotatePlugin() - { - return new GMSH_AnnotatePlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterAnnotatePlugin() { return new GMSH_AnnotatePlugin(); } } static double getStyle() { int fontsize = (int)AnnotateOptions_Number[4].def, font = 0, align = 0; #if defined(HAVE_OPENGL) - font = drawContext::global()->getFontIndex - (AnnotateOptions_String[1].def.c_str()); - align = drawContext::global()->getFontAlign - (AnnotateOptions_String[2].def.c_str()); + font = + drawContext::global()->getFontIndex(AnnotateOptions_String[1].def.c_str()); + align = + drawContext::global()->getFontAlign(AnnotateOptions_String[2].def.c_str()); #endif - return (double)((align<<16)|(font<<8)|(fontsize)); + return (double)((align << 16) | (font << 8) | (fontsize)); } void GMSH_AnnotatePlugin::draw(void *context) @@ -54,20 +48,23 @@ void GMSH_AnnotatePlugin::draw(void *context) double Y = AnnotateOptions_Number[1].def; double Z = AnnotateOptions_Number[2].def; double style = getStyle(); - drawContext *ctx = (drawContext*)context; + drawContext *ctx = (drawContext *)context; - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); - if(AnnotateOptions_Number[3].def){ // 3D + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); + if(AnnotateOptions_Number[3].def) { // 3D ctx->drawString(AnnotateOptions_String[0].def, X, Y, Z, style); // draw 10-pixel marker double d = 10 * ctx->pixel_equiv_x / ctx->s[0]; glBegin(GL_LINES); - glVertex3d(X-d,Y,Z); glVertex3d(X+d,Y,Z); - glVertex3d(X,Y-d,Z); glVertex3d(X,Y+d,Z); - glVertex3d(X,Y,Z-d); glVertex3d(X,Y,Z+d); + glVertex3d(X - d, Y, Z); + glVertex3d(X + d, Y, Z); + glVertex3d(X, Y - d, Z); + glVertex3d(X, Y + d, Z); + glVertex3d(X, Y, Z - d); + glVertex3d(X, Y, Z + d); glEnd(); } - else{ + else { double modelview[16], projection[16]; glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetDoublev(GL_MODELVIEW_MATRIX, modelview); @@ -82,8 +79,10 @@ void GMSH_AnnotatePlugin::draw(void *context) ctx->drawString(AnnotateOptions_String[0].def, X, Y, 0., style); // draw 10-pixel marker glBegin(GL_LINES); - glVertex2d(X-10,Y); glVertex2d(X+10,Y); - glVertex2d(X,Y-10); glVertex2d(X,Y+10); + glVertex2d(X - 10, Y); + glVertex2d(X + 10, Y); + glVertex2d(X, Y - 10); + glVertex2d(X, Y + 10); glEnd(); glMatrixMode(GL_PROJECTION); @@ -94,10 +93,11 @@ void GMSH_AnnotatePlugin::draw(void *context) #endif } -double GMSH_AnnotatePlugin::callback(int num, int action, double value, double *opt, - double step, double min, double max) +double GMSH_AnnotatePlugin::callback(int num, int action, double value, + double *opt, double step, double min, + double max) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return step; case 2: return min; case 3: return max; @@ -108,7 +108,8 @@ double GMSH_AnnotatePlugin::callback(int num, int action, double value, double * return 0.; } -std::string GMSH_AnnotatePlugin::callbackStr(int num, int action, std::string value, +std::string GMSH_AnnotatePlugin::callbackStr(int num, int action, + std::string value, std::string &opt) { opt = value; @@ -121,7 +122,7 @@ double GMSH_AnnotatePlugin::callbackX(int num, int action, double value) // not perfect: the change will only take place if we reopen the dialog... int dim3 = (int)AnnotateOptions_Number[3].def; return callback(num, action, value, &AnnotateOptions_Number[0].def, - dim3 ? CTX::instance()->lc/200. : 0.5, + dim3 ? CTX::instance()->lc / 200. : 0.5, dim3 ? -CTX::instance()->lc : -100., dim3 ? CTX::instance()->lc : 100000.); } @@ -131,7 +132,7 @@ double GMSH_AnnotatePlugin::callbackY(int num, int action, double value) // not perfect: the change will only take place if we reopen the dialog... int dim3 = (int)AnnotateOptions_Number[3].def; return callback(num, action, value, &AnnotateOptions_Number[1].def, - dim3 ? CTX::instance()->lc/200. : 0.5, + dim3 ? CTX::instance()->lc / 200. : 0.5, dim3 ? -CTX::instance()->lc : -100., dim3 ? CTX::instance()->lc : 100000.); } @@ -141,34 +142,36 @@ double GMSH_AnnotatePlugin::callbackZ(int num, int action, double value) // not perfect: the change will only take place if we reopen the dialog... int dim3 = (int)AnnotateOptions_Number[3].def; return callback(num, action, value, &AnnotateOptions_Number[2].def, - dim3 ? CTX::instance()->lc/200. : 0.5, + dim3 ? CTX::instance()->lc / 200. : 0.5, dim3 ? -CTX::instance()->lc : -100., dim3 ? CTX::instance()->lc : 100000.); } double GMSH_AnnotatePlugin::callback3D(int num, int action, double value) { - return callback(num, action, value, &AnnotateOptions_Number[3].def, - 1, 0, 1); + return callback(num, action, value, &AnnotateOptions_Number[3].def, 1, 0, 1); } double GMSH_AnnotatePlugin::callbackFontSize(int num, int action, double value) { - return callback(num, action, value, &AnnotateOptions_Number[4].def, - 1, 5, 100); + return callback(num, action, value, &AnnotateOptions_Number[4].def, 1, 5, + 100); } -std::string GMSH_AnnotatePlugin::callbackText(int num, int action, std::string value) +std::string GMSH_AnnotatePlugin::callbackText(int num, int action, + std::string value) { return callbackStr(num, action, value, AnnotateOptions_String[0].def); } -std::string GMSH_AnnotatePlugin::callbackFont(int num, int action, std::string value) +std::string GMSH_AnnotatePlugin::callbackFont(int num, int action, + std::string value) { return callbackStr(num, action, value, AnnotateOptions_String[1].def); } -std::string GMSH_AnnotatePlugin::callbackAlign(int num, int action, std::string value) +std::string GMSH_AnnotatePlugin::callbackAlign(int num, int action, + std::string value) { return callbackStr(num, action, value, AnnotateOptions_String[2].def); } @@ -176,16 +179,16 @@ std::string GMSH_AnnotatePlugin::callbackAlign(int num, int action, std::string std::string GMSH_AnnotatePlugin::getHelp() const { return "Plugin(Annotate) adds the text string `Text', " - "in font `Font' and size `FontSize', in the view " - "`View'. The string is aligned according to `Align'.\n\n" - "If `ThreeD' is equal to 1, the plugin inserts " - "the string in model coordinates at the position " - "(`X',`Y',`Z'). If `ThreeD' is equal to 0, the plugin " - "inserts the string in screen coordinates at " - "the position (`X',`Y').\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Annotate) is executed in-place for list-based " - "datasets or creates a new view for other datasets."; + "in font `Font' and size `FontSize', in the view " + "`View'. The string is aligned according to `Align'.\n\n" + "If `ThreeD' is equal to 1, the plugin inserts " + "the string in model coordinates at the position " + "(`X',`Y',`Z'). If `ThreeD' is equal to 0, the plugin " + "inserts the string in screen coordinates at " + "the position (`X',`Y').\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Annotate) is executed in-place for list-based " + "datasets or creates a new view for other datasets."; } int GMSH_AnnotatePlugin::getNbOptions() const @@ -224,34 +227,32 @@ PView *GMSH_AnnotatePlugin::execute(PView *v) PView *v2 = v1; PViewDataList *data2 = getDataList(v2, false); - if(!data2){ + if(!data2) { v2 = new PView(); data2 = getDataList(v2); } - if(dim3){ + if(dim3) { data2->T3D.push_back(X); data2->T3D.push_back(Y); data2->T3D.push_back(Z); data2->T3D.push_back(style); data2->T3D.push_back(data2->T3C.size()); - for(unsigned int i = 0; i < text.size(); i++) - data2->T3C.push_back(text[i]); + for(unsigned int i = 0; i < text.size(); i++) data2->T3C.push_back(text[i]); data2->T3C.push_back('\0'); data2->NbT3++; } - else{ + else { data2->T2D.push_back(X); data2->T2D.push_back(Y); data2->T2D.push_back(style); data2->T2D.push_back(data2->T2C.size()); - for(unsigned int i = 0; i < text.size(); i++) - data2->T2C.push_back(text[i]); + for(unsigned int i = 0; i < text.size(); i++) data2->T2C.push_back(text[i]); data2->T2C.push_back('\0'); data2->NbT2++; } - if(v2 != v1){ + if(v2 != v1) { for(int i = 0; i < data1->getNumTimeSteps(); i++) data2->Time.push_back(data1->getTime(i)); data2->setName(data1->getName() + "_Annotate"); diff --git a/Plugin/Annotate.h b/Plugin/Annotate.h index 8cd41a54690b967a099eb4a1af3c2b1fff61d6b6..315226b3106c8fd443e91a2c6a164f0875998a02 100644 --- a/Plugin/Annotate.h +++ b/Plugin/Annotate.h @@ -9,27 +9,26 @@ #include <string> #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterAnnotatePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterAnnotatePlugin(); } -class GMSH_AnnotatePlugin : public GMSH_PostPlugin -{ - private: +class GMSH_AnnotatePlugin : public GMSH_PostPlugin { +private: static double callback(int num, int action, double value, double *opt, double step, double min, double max); static std::string callbackStr(int num, int action, std::string value, std::string &opt); - public: - GMSH_AnnotatePlugin(){} + +public: + GMSH_AnnotatePlugin() {} std::string getName() const { return "Annotate"; } std::string getShortHelp() const { return "Add a text annotation"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString *getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); static double callbackX(int, int, double); diff --git a/Plugin/Bubbles.cpp b/Plugin/Bubbles.cpp index 45c6fe7fdb788395bbe8ac7b78a11036be46589d..cf6b9c78568e970c0e5f37e90de5344f1174205a 100644 --- a/Plugin/Bubbles.cpp +++ b/Plugin/Bubbles.cpp @@ -16,25 +16,20 @@ StringXNumber BubblesOptions_Number[] = { }; StringXString BubblesOptions_String[] = { - {GMSH_FULLRC, "OutputFile", NULL, "bubbles.geo"} -}; + {GMSH_FULLRC, "OutputFile", NULL, "bubbles.geo"}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterBubblesPlugin() - { - return new GMSH_BubblesPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterBubblesPlugin() { return new GMSH_BubblesPlugin(); } } std::string GMSH_BubblesPlugin::getHelp() const { return "Plugin(Bubbles) constructs a geometry consisting of " - "`bubbles' inscribed in the Voronoi of an input triangulation. " - "`ShrinkFactor' allows to change the size of the bubbles. " - "The plugin expects a triangulation in the `z = 0' plane to exist " - "in the current model.\n\n" - "Plugin(Bubbles) creates one `.geo' file."; + "`bubbles' inscribed in the Voronoi of an input triangulation. " + "`ShrinkFactor' allows to change the size of the bubbles. " + "The plugin expects a triangulation in the `z = 0' plane to exist " + "in the current model.\n\n" + "Plugin(Bubbles) creates one `.geo' file."; } int GMSH_BubblesPlugin::getNbOptions() const @@ -61,17 +56,17 @@ static double myangle(double c[3], double p[3]) { double v[3] = {1, 0, 0}; double n[3] = {0, 0, 1}; - if(fabs(c[0] - p[0]) < 1e-12 && - fabs(c[1] - p[1]) < 1e-12 && + if(fabs(c[0] - p[0]) < 1e-12 && fabs(c[1] - p[1]) < 1e-12 && fabs(c[2] - p[2]) < 1e-12) return 0.; return angle_plan(c, v, p, n); } -class compareAngle{ - private: +class compareAngle { +private: SPoint3 v; - public: + +public: compareAngle(SPoint3 vv) : v(vv) {} bool operator()(const SPoint3 &b1, const SPoint3 &b2) { @@ -90,7 +85,7 @@ PView *GMSH_BubblesPlugin::execute(PView *v) std::string fileName = BubblesOptions_String[0].def; FILE *fp = Fopen(fileName.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Could not open output file '%s'", fileName.c_str()); return v; } @@ -112,7 +107,7 @@ PView *GMSH_BubblesPlugin::execute(PView *v) for(GModel::eiter eit = m->firstEdge(); eit != m->lastEdge(); eit++) (*eit)->writeGEO(fp); - for(GModel::fiter fit = m->firstFace(); fit != m->lastFace(); fit++){ + for(GModel::fiter fit = m->firstFace(); fit != m->lastFace(); fit++) { (*fit)->writeGEO(fp); fprintf(fp, "Delete { Surface {%d}; }\n", (*fit)->tag()); @@ -120,32 +115,33 @@ PView *GMSH_BubblesPlugin::execute(PView *v) int llbeg = ll; // compute vertex-to-triangle_barycenter map - std::map<MVertex*, std::vector<SPoint3> > v2t; + std::map<MVertex *, std::vector<SPoint3> > v2t; for(unsigned int i = 0; i < (*fit)->triangles.size(); i++) for(int j = 0; j < 3; j++) - v2t[(*fit)->triangles[i]->getVertex(j)].push_back((*fit)->triangles[i]->barycenter()); + v2t[(*fit)->triangles[i]->getVertex(j)].push_back( + (*fit)->triangles[i]->barycenter()); // add boundary vertices in map to get cells "closer" to the boundary - for(std::map<MVertex*, std::vector<SPoint3> >::iterator it = v2t.begin(); - it != v2t.end(); it++){ + for(std::map<MVertex *, std::vector<SPoint3> >::iterator it = v2t.begin(); + it != v2t.end(); it++) { MVertex *v = it->first; if(v->onWhat() && v->onWhat()->dim() < 2) - it->second.push_back(SPoint3(it->first->x(), it->first->y(), it->first->z())); + it->second.push_back( + SPoint3(it->first->x(), it->first->y(), it->first->z())); } - for(std::map<MVertex*, std::vector<SPoint3> >::iterator it = v2t.begin(); - it != v2t.end(); it++){ - if(it->second.size() > 2){ + for(std::map<MVertex *, std::vector<SPoint3> >::iterator it = v2t.begin(); + it != v2t.end(); it++) { + if(it->second.size() > 2) { // get barycenter of cell boundary points and order them SPoint3 bc; - for(unsigned int i = 0; i < it->second.size(); i++) - bc += it->second[i]; + for(unsigned int i = 0; i < it->second.size(); i++) bc += it->second[i]; bc *= 1. / (double)it->second.size(); compareAngle comp(bc); std::sort(it->second.begin(), it->second.end(), comp); // shrink cells - if(shrink){ - for(unsigned int i = 0; i < it->second.size(); i++){ + if(shrink) { + for(unsigned int i = 0; i < it->second.size(); i++) { double dir[3] = {it->second[i].x() - bc.x(), it->second[i].y() - bc.y(), it->second[i].z() - bc.z()}; @@ -156,13 +152,13 @@ PView *GMSH_BubblesPlugin::execute(PView *v) } // create b-spline bounded surface for each cell int nump = it->second.size(); - for(int i = 0; i < nump; i++){ + for(int i = 0; i < nump; i++) { SPoint3 &b(it->second[i]); - fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, lc};\n", p++, b.x(), b.y(), b.z()); + fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, lc};\n", p++, b.x(), + b.y(), b.z()); } fprintf(fp, "BSpline(%d) = {", l++); - for(int i = nump - 1; i >= 0; i--) - fprintf(fp, "%d,", p - i - 1); + for(int i = nump - 1; i >= 0; i--) fprintf(fp, "%d,", p - i - 1); fprintf(fp, "%d};\n", p - nump); fprintf(fp, "Line Loop(%d) = {%d};\n", ll++, l - 1); fprintf(fp, "Plane Surface(%d) = {%d};\n", s++, ll - 1); @@ -170,7 +166,8 @@ PView *GMSH_BubblesPlugin::execute(PView *v) } fprintf(fp, "Physical Surface(%d) = {%d:%d};\n", ps++, sbeg, s - 1); - fprintf(fp, "Plane Surface(%d) = {%d, %d:%d};\n", s++, (*fit)->tag(), llbeg, ll - 1); + fprintf(fp, "Plane Surface(%d) = {%d, %d:%d};\n", s++, (*fit)->tag(), llbeg, + ll - 1); fprintf(fp, "Physical Surface(%d) = {%d};\n", ps++, s - 1); } diff --git a/Plugin/Bubbles.h b/Plugin/Bubbles.h index d4476a3a1470ca699ede2dc5c054a9d22b5570ae..2da5c0a93932d8c38f3c81186c633e1222365b84 100644 --- a/Plugin/Bubbles.h +++ b/Plugin/Bubbles.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterBubblesPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterBubblesPlugin(); } -class GMSH_BubblesPlugin : public GMSH_PostPlugin -{ - public: - GMSH_BubblesPlugin(){} +class GMSH_BubblesPlugin : public GMSH_PostPlugin { +public: + GMSH_BubblesPlugin() {} std::string getName() const { return "Bubbles"; } std::string getShortHelp() const { @@ -26,7 +24,7 @@ class GMSH_BubblesPlugin : public GMSH_PostPlugin int getNbOptions() const; StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); }; diff --git a/Plugin/CVTRemesh.cpp b/Plugin/CVTRemesh.cpp index 42b3f3b67e8527eb93ee2d996eda6b99274134fc..b5ea5bcb4b291f7674a3eabc28673fab745e3543 100644 --- a/Plugin/CVTRemesh.cpp +++ b/Plugin/CVTRemesh.cpp @@ -33,29 +33,27 @@ StringXNumber CVTRemeshOptions_Number[] = { {GMSH_FULLRC, "Anisotropy", NULL, 0.03}, {GMSH_FULLRC, "Variable density", NULL, 0.3}, {GMSH_FULLRC, "Feature sensitivity", NULL, 5.}, - {GMSH_FULLRC, "Normal computation radius", NULL, 0.005} -}; + {GMSH_FULLRC, "Normal computation radius", NULL, 0.005}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterCVTRemeshPlugin() { - GMSH_Plugin *GMSH_RegisterCVTRemeshPlugin() - { - return new GMSH_CVTRemeshPlugin(); - } + return new GMSH_CVTRemeshPlugin(); +} } std::string GMSH_CVTRemeshPlugin::getHelp() const { return "Plugin(CVTRemesh) triangulates an input geometry using" - "centroïdal Voronoï tesselations. The STL mesh of the geometry" - "is generated and randomly sampled. An objective function derived" - "from centroïdal Voronoï tesselations is then defined on the" - "generated sampling, and optimized through LBFGS to obtain a" - "regular sampling of the surface. The triangulation is extracted" - "as the restricted Delaunay triangulation of the samples and the" - "STL mesh.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Triangulate) creates one new view."; + "centroïdal Voronoï tesselations. The STL mesh of the geometry" + "is generated and randomly sampled. An objective function derived" + "from centroïdal Voronoï tesselations is then defined on the" + "generated sampling, and optimized through LBFGS to obtain a" + "regular sampling of the surface. The triangulation is extracted" + "as the restricted Delaunay triangulation of the samples and the" + "STL mesh.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Triangulate) creates one new view."; } int GMSH_CVTRemeshPlugin::getNbOptions() const @@ -68,259 +66,249 @@ StringXNumber *GMSH_CVTRemeshPlugin::getOption(int iopt) return &CVTRemeshOptions_Number[iopt]; } -//solver callback +// solver callback class SolverCallback { - - public : - - template<typename Data> - void operator()( Data* data ) { - //Output current iteration data - Msg::Info("[CVTRemesh] : iteration %d, objective function value is %f", data->k, data->fx) ; - } - -} ; +public: + template <typename Data> void operator()(Data *data) + { + // Output current iteration data + Msg::Info("[CVTRemesh] : iteration %d, objective function value is %f", + data->k, data->fx); + } +}; PView *GMSH_CVTRemeshPlugin::execute(PView *v) { - //TODO normalization + // TODO normalization - GModel* m = GModel::current() ; + GModel *m = GModel::current(); - std::vector<double> vertices ; - std::vector<unsigned int> faces ; + std::vector<double> vertices; + std::vector<unsigned int> faces; - unsigned int offset = 0 ; + unsigned int offset = 0; for(GModel::fiter it = m->firstFace(); it != m->lastFace(); ++it) { - (*it)->buildSTLTriangulation() ; + (*it)->buildSTLTriangulation(); for(unsigned int i = 0; i < (*it)->stl_vertices.size(); ++i) { - GPoint p = (*it)->point((*it)->stl_vertices[i]) ; - vertices.push_back(p.x()) ; - vertices.push_back(p.y()) ; - vertices.push_back(p.z()) ; + GPoint p = (*it)->point((*it)->stl_vertices[i]); + vertices.push_back(p.x()); + vertices.push_back(p.y()); + vertices.push_back(p.z()); } for(unsigned int i = 0; i < (*it)->stl_triangles.size(); ++i) { - faces.push_back((*it)->stl_triangles[i]+offset) ; + faces.push_back((*it)->stl_triangles[i] + offset); } - offset += (*it)->stl_vertices.size() ; + offset += (*it)->stl_vertices.size(); } - Revoropt::MeshBuilder<3> mesh ; - mesh.swap_vertices(vertices) ; - mesh.swap_faces(faces) ; + Revoropt::MeshBuilder<3> mesh; + mesh.swap_vertices(vertices); + mesh.swap_faces(faces); - double mesh_center[3] ; - double mesh_scale ; - Revoropt::normalize_mesh(&mesh, mesh_center, &mesh_scale) ; + double mesh_center[3]; + double mesh_scale; + Revoropt::normalize_mesh(&mesh, mesh_center, &mesh_scale); - double nradius = (double)CVTRemeshOptions_Number[5].def ; + double nradius = (double)CVTRemeshOptions_Number[5].def; - //normals - std::vector<double> normals(3*mesh.vertices_size()) ; - Revoropt::full_robust_vertex_normals(&mesh,nradius,normals.data()) ; + // normals + std::vector<double> normals(3 * mesh.vertices_size()); + Revoropt::full_robust_vertex_normals(&mesh, nradius, normals.data()); - //lifted vertices - std::vector<double> lifted_vertices(6*mesh.vertices_size(), 0) ; + // lifted vertices + std::vector<double> lifted_vertices(6 * mesh.vertices_size(), 0); for(unsigned int vertex = 0; vertex < mesh.vertices_size(); ++vertex) { - std::copy( mesh.vertex(vertex), - mesh.vertex(vertex)+3, - lifted_vertices.data()+6*vertex - ) ; - std::copy( normals.data()+3*vertex, - normals.data()+3*vertex+3, - lifted_vertices.data()+6*vertex+3 - ) ; + std::copy(mesh.vertex(vertex), mesh.vertex(vertex) + 3, + lifted_vertices.data() + 6 * vertex); + std::copy(normals.data() + 3 * vertex, normals.data() + 3 * vertex + 3, + lifted_vertices.data() + 6 * vertex + 3); } - //setup lifted mesh - Revoropt::ROMeshWrapper<3,6> lifted_mesh( - lifted_vertices.data(), - lifted_vertices.size()/6, - &mesh - ) ; + // setup lifted mesh + Revoropt::ROMeshWrapper<3, 6> lifted_mesh(lifted_vertices.data(), + lifted_vertices.size() / 6, &mesh); - //triangle weight factor - double twfactor = (double)CVTRemeshOptions_Number[3].def ; + // triangle weight factor + double twfactor = (double)CVTRemeshOptions_Number[3].def; - //face ratios - std::vector<double> triangle_weights(lifted_mesh.faces_size()) ; + // face ratios + std::vector<double> triangle_weights(lifted_mesh.faces_size()); if(twfactor > 0) { for(unsigned int f = 0; f < lifted_mesh.faces_size(); ++f) { - //vertices of the initial triangle - const unsigned int* fverts = mesh.face(f) ; + // vertices of the initial triangle + const unsigned int *fverts = mesh.face(f); - //positions - const double* x[3] ; - for(int i=0; i<3; ++i) { - x[i] = lifted_mesh.vertex(fverts[i]) ; + // positions + const double *x[3]; + for(int i = 0; i < 3; ++i) { + x[i] = lifted_mesh.vertex(fverts[i]); } - //ratio - double ratio = 1 ; + // ratio + double ratio = 1; - //vectors - typedef Eigen::Matrix<double,3,1> Vector3 ; + // vectors + typedef Eigen::Matrix<double, 3, 1> Vector3; - Eigen::Map<const Vector3> v0(x[0]) ; - Eigen::Map<const Vector3> v1(x[1]) ; - Eigen::Map<const Vector3> v2(x[2]) ; + Eigen::Map<const Vector3> v0(x[0]); + Eigen::Map<const Vector3> v1(x[1]); + Eigen::Map<const Vector3> v2(x[2]); - //triangle frame - Vector3 U = (v1-v0) ; - const double U_len = U.norm() ; + // triangle frame + Vector3 U = (v1 - v0); + const double U_len = U.norm(); if(U_len > 0) { - U /= U_len ; - Vector3 H = (v2-v0) ; - H = H - H.dot(U)*U ; - const double H_len = H.norm() ; + U /= U_len; + Vector3 H = (v2 - v0); + H = H - H.dot(U) * U; + const double H_len = H.norm(); if(H_len > 0) { - //we know that the triangle is not flat - H /= H_len ; + // we know that the triangle is not flat + H /= H_len; - //gradient of the barycentric weights in the triangle - Eigen::Matrix<double,3,2> bar_grads ; - bar_grads(2,0) = 0 ; - bar_grads(2,1) = 1/H_len ; + // gradient of the barycentric weights in the triangle + Eigen::Matrix<double, 3, 2> bar_grads; + bar_grads(2, 0) = 0; + bar_grads(2, 1) = 1 / H_len; - //gradient norms of every normal component + // gradient norms of every normal component for(int i = 0; i < 2; ++i) { - //reference frame for the vertex - Eigen::Map<const Vector3> vi0(x[(i+1)%3]) ; - Eigen::Map<const Vector3> vi1(x[(i+2)%3]) ; - Eigen::Map<const Vector3> vi2(x[ i ]) ; - - Vector3 Ui = (vi1-vi0) ; - Ui /= Ui.norm() ; - Vector3 Hi = (vi2-vi0) ; - Hi = Hi - Hi.dot(Ui)*Ui ; - const double Hi_invlen = 1/Hi.norm() ; - Hi *= Hi_invlen ; - bar_grads(i,0) = Hi.dot(U)*Hi_invlen ; - bar_grads(i,1) = Hi.dot(H)*Hi_invlen ; + // reference frame for the vertex + Eigen::Map<const Vector3> vi0(x[(i + 1) % 3]); + Eigen::Map<const Vector3> vi1(x[(i + 2) % 3]); + Eigen::Map<const Vector3> vi2(x[i]); + + Vector3 Ui = (vi1 - vi0); + Ui /= Ui.norm(); + Vector3 Hi = (vi2 - vi0); + Hi = Hi - Hi.dot(Ui) * Ui; + const double Hi_invlen = 1 / Hi.norm(); + Hi *= Hi_invlen; + bar_grads(i, 0) = Hi.dot(U) * Hi_invlen; + bar_grads(i, 1) = Hi.dot(H) * Hi_invlen; } - //gradient of each component of the normal - Eigen::Map<const Vector3> n0(x[0]+3) ; - Eigen::Map<const Vector3> n1(x[1]+3) ; - Eigen::Map<const Vector3> n2(x[2]+3) ; + // gradient of each component of the normal + Eigen::Map<const Vector3> n0(x[0] + 3); + Eigen::Map<const Vector3> n1(x[1] + 3); + Eigen::Map<const Vector3> n2(x[2] + 3); - Eigen::Matrix<double,3,2> n_grads = Eigen::Matrix<double,3,2>::Zero() ; + Eigen::Matrix<double, 3, 2> n_grads = + Eigen::Matrix<double, 3, 2>::Zero(); - n_grads = n0*bar_grads.row(0) ; - n_grads += n1*bar_grads.row(1) ; - n_grads += n2*bar_grads.row(2) ; + n_grads = n0 * bar_grads.row(0); + n_grads += n1 * bar_grads.row(1); + n_grads += n2 * bar_grads.row(2); - //maximal gradient norm - double g_max = n_grads.row(0).dot(n_grads.row(0)) ; - double g_other = n_grads.row(1).dot(n_grads.row(1)) ; - g_max = g_max > g_other ? g_max : g_other ; - g_other = n_grads.row(2).dot(n_grads.row(2)) ; - g_max = g_max > g_other ? g_max : g_other ; + // maximal gradient norm + double g_max = n_grads.row(0).dot(n_grads.row(0)); + double g_other = n_grads.row(1).dot(n_grads.row(1)); + g_max = g_max > g_other ? g_max : g_other; + g_other = n_grads.row(2).dot(n_grads.row(2)); + g_max = g_max > g_other ? g_max : g_other; - if(g_max == g_max) { //prevent nan - ratio += g_max ; + if(g_max == g_max) { // prevent nan + ratio += g_max; } } } - triangle_weights[f] = pow(ratio,twfactor) ; + triangle_weights[f] = pow(ratio, twfactor); } } - //normal factor - double nfactor = (double)CVTRemeshOptions_Number[2].def ; ; + // normal factor + double nfactor = (double)CVTRemeshOptions_Number[2].def; + ; - //weight the normal component by the provided factor - for(unsigned int i = 0; i<lifted_mesh.vertices_size(); ++i) { - double* v = lifted_vertices.data() + 6*i ; - v[3]*= nfactor ; - v[4]*= nfactor ; - v[5]*= nfactor ; + // weight the normal component by the provided factor + for(unsigned int i = 0; i < lifted_mesh.vertices_size(); ++i) { + double *v = lifted_vertices.data() + 6 * i; + v[3] *= nfactor; + v[4] *= nfactor; + v[5] *= nfactor; } - //number of sites - unsigned int nsites = (unsigned int)CVTRemeshOptions_Number[0].def ; + // number of sites + unsigned int nsites = (unsigned int)CVTRemeshOptions_Number[0].def; - //lifted sites - std::vector<double> lifted_sites(6*nsites) ; + // lifted sites + std::vector<double> lifted_sites(6 * nsites); if(twfactor > 0) { - Revoropt::generate_random_sites< Revoropt::ROMesh<3,6> >( - &lifted_mesh, nsites, lifted_sites.data(), triangle_weights.data() - ) ; - } else { - Revoropt::generate_random_sites< Revoropt::ROMesh<3,6> >( - &lifted_mesh, nsites, lifted_sites.data() - ) ; + Revoropt::generate_random_sites<Revoropt::ROMesh<3, 6> >( + &lifted_mesh, nsites, lifted_sites.data(), triangle_weights.data()); + } + else { + Revoropt::generate_random_sites<Revoropt::ROMesh<3, 6> >( + &lifted_mesh, nsites, lifted_sites.data()); } - //setup the cvt minimizer - Revoropt::CVT::DirectMinimizer< Revoropt::ROMesh<3,6> > cvt ; - cvt.set_sites(lifted_sites.data(), nsites) ; - cvt.set_mesh(&lifted_mesh) ; + // setup the cvt minimizer + Revoropt::CVT::DirectMinimizer<Revoropt::ROMesh<3, 6> > cvt; + cvt.set_sites(lifted_sites.data(), nsites); + cvt.set_mesh(&lifted_mesh); if(twfactor > 0) { - cvt.set_triangle_weights(triangle_weights.data()) ; + cvt.set_triangle_weights(triangle_weights.data()); } - //setup the callback - SolverCallback callback ; + // setup the callback + SolverCallback callback; - //number of iterations - unsigned int niter = (unsigned int)CVTRemeshOptions_Number[1].def ; ; - unsigned int aniso_niter = std::min<unsigned int>(10,niter) ; + // number of iterations + unsigned int niter = (unsigned int)CVTRemeshOptions_Number[1].def; + ; + unsigned int aniso_niter = std::min<unsigned int>(10, niter); - //solver status - int status = 0 ; + // solver status + int status = 0; - //isotropic iterations + // isotropic iterations if(niter > 10) { - aniso_niter = std::max(aniso_niter,niter*10/100) ; - cvt.set_anisotropy(1) ; - status = cvt.minimize<Revoropt::Solver::AlgLBFGS>(niter-aniso_niter, &callback) ; + aniso_niter = std::max(aniso_niter, niter * 10 / 100); + cvt.set_anisotropy(1); + status = + cvt.minimize<Revoropt::Solver::AlgLBFGS>(niter - aniso_niter, &callback); } - //anisotropic iterations + // anisotropic iterations if(niter > 0) { - //tangent space anisotropy - double tanisotropy = (double)CVTRemeshOptions_Number[4].def ; ; + // tangent space anisotropy + double tanisotropy = (double)CVTRemeshOptions_Number[4].def; + ; - //anisotropic iterations - cvt.set_anisotropy(tanisotropy) ; - status = cvt.minimize<Revoropt::Solver::AlgLBFGS>(aniso_niter, &callback) ; + // anisotropic iterations + cvt.set_anisotropy(tanisotropy); + status = cvt.minimize<Revoropt::Solver::AlgLBFGS>(aniso_niter, &callback); } - //rdt - std::vector<unsigned int> rdt_triangles ; - Revoropt::RDTBuilder< Revoropt::ROMesh<3,6> > build_rdt(rdt_triangles) ; - Revoropt::RVD< Revoropt::ROMesh<3,6> > rvd ; - rvd.set_sites(lifted_sites.data(), nsites) ; - rvd.set_mesh(&lifted_mesh) ; - rvd.compute(build_rdt) ; + // rdt + std::vector<unsigned int> rdt_triangles; + Revoropt::RDTBuilder<Revoropt::ROMesh<3, 6> > build_rdt(rdt_triangles); + Revoropt::RVD<Revoropt::ROMesh<3, 6> > rvd; + rvd.set_sites(lifted_sites.data(), nsites); + rvd.set_mesh(&lifted_mesh); + rvd.compute(build_rdt); - GFace* res_face = new discreteFace(m, m->getMaxElementaryNumber(2)+1) ; - m->add(res_face) ; + GFace *res_face = new discreteFace(m, m->getMaxElementaryNumber(2) + 1); + m->add(res_face); - //scale back and transfer to gmsh - std::vector<MVertex*> m_verts(nsites) ; + // scale back and transfer to gmsh + std::vector<MVertex *> m_verts(nsites); for(unsigned int i = 0; i < nsites; ++i) { - m_verts[i] = new MVertex( - lifted_sites[6*i ]*mesh_scale + mesh_center[0], - lifted_sites[6*i+1]*mesh_scale + mesh_center[1], - lifted_sites[6*i+2]*mesh_scale + mesh_center[2] - ) ; - res_face->addMeshVertex(m_verts[i]) ; + m_verts[i] = + new MVertex(lifted_sites[6 * i] * mesh_scale + mesh_center[0], + lifted_sites[6 * i + 1] * mesh_scale + mesh_center[1], + lifted_sites[6 * i + 2] * mesh_scale + mesh_center[2]); + res_face->addMeshVertex(m_verts[i]); } - for(unsigned int i = 0; i < rdt_triangles.size()/3; ++i) { - res_face->addTriangle( - new MTriangle( - m_verts[rdt_triangles[3*i ]], - m_verts[rdt_triangles[3*i+1]], - m_verts[rdt_triangles[3*i+2]] - ) - ) ; + for(unsigned int i = 0; i < rdt_triangles.size() / 3; ++i) { + res_face->addTriangle(new MTriangle(m_verts[rdt_triangles[3 * i]], + m_verts[rdt_triangles[3 * i + 1]], + m_verts[rdt_triangles[3 * i + 2]])); } - res_face->setAllElementsVisible(true) ; + res_face->setAllElementsVisible(true); - return v ; + return v; } #endif diff --git a/Plugin/CVTRemesh.h b/Plugin/CVTRemesh.h index c3f7540d4e49263797449b58ac7d32954e8a2a8d..d81be8cafac5499367d5fcad77008fc3f53443ca 100644 --- a/Plugin/CVTRemesh.h +++ b/Plugin/CVTRemesh.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCVTRemeshPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterCVTRemeshPlugin(); } -class GMSH_CVTRemeshPlugin : public GMSH_PostPlugin -{ - public: - GMSH_CVTRemeshPlugin(){} +class GMSH_CVTRemeshPlugin : public GMSH_PostPlugin { +public: + GMSH_CVTRemeshPlugin() {} std::string getName() const { return "CVTRemesh"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_CVTRemeshPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Crack.cpp b/Plugin/Crack.cpp index 537a5038e4c52e3bb408f6f51b518ce44fb06e63..d2fb5129a24b94af155143dfaec77400620938be 100644 --- a/Plugin/Crack.cpp +++ b/Plugin/Crack.cpp @@ -20,34 +20,29 @@ StringXNumber CrackOptions_Number[] = { {GMSH_FULLRC, "OpenBoundaryPhysicalGroup", NULL, 0.}, {GMSH_FULLRC, "NormalX", NULL, 0.}, {GMSH_FULLRC, "NormalY", NULL, 0.}, - {GMSH_FULLRC, "NormalZ", NULL, 1.} -}; + {GMSH_FULLRC, "NormalZ", NULL, 1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCrackPlugin() - { - return new GMSH_CrackPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterCrackPlugin() { return new GMSH_CrackPlugin(); } } std::string GMSH_CrackPlugin::getHelp() const { return "Plugin(Crack) creates a crack around the physical " - "group `PhysicalGroup' of dimension `Dimension' (1 or 2), " - "embedded in a mesh of dimension `Dimension' + 1. " - "The plugin duplicates the vertices and the elements on " - "the crack and stores them in a new discrete curve " - "(`Dimension' = 1) or surface (`Dimension' = 2). The " - "elements touching the crack on the ``negative'' side " - "are modified to use the newly generated vertices." - "If `OpenBoundaryPhysicalGroup' is given (> 0), its " - "vertices are duplicated and the crack will be left " - "open on that (part of the) boundary. Otherwise, the " - "lips of the crack are sealed, i.e., its vertices are " - "not duplicated. For 1D cracks, `NormalX', `NormalY' and " - "`NormalZ' provide the reference normal of the surface " - "in which the crack is supposed to be embedded."; + "group `PhysicalGroup' of dimension `Dimension' (1 or 2), " + "embedded in a mesh of dimension `Dimension' + 1. " + "The plugin duplicates the vertices and the elements on " + "the crack and stores them in a new discrete curve " + "(`Dimension' = 1) or surface (`Dimension' = 2). The " + "elements touching the crack on the ``negative'' side " + "are modified to use the newly generated vertices." + "If `OpenBoundaryPhysicalGroup' is given (> 0), its " + "vertices are duplicated and the crack will be left " + "open on that (part of the) boundary. Otherwise, the " + "lips of the crack are sealed, i.e., its vertices are " + "not duplicated. For 1D cracks, `NormalX', `NormalY' and " + "`NormalZ' provide the reference normal of the surface " + "in which the crack is supposed to be embedded."; } int GMSH_CrackPlugin::getNbOptions() const @@ -60,11 +55,11 @@ StringXNumber *GMSH_CrackPlugin::getOption(int iopt) return &CrackOptions_Number[iopt]; } -class EdgeData{ +class EdgeData { public: EdgeData(MEdge e) : edge(e) {} MEdge edge; - std::vector<MVertex*> data; + std::vector<MVertex *> data; }; struct Less_EdgeData : public std::binary_function<EdgeData, EdgeData, bool> { @@ -82,54 +77,53 @@ PView *GMSH_CrackPlugin::execute(PView *view) int dim = (int)CrackOptions_Number[0].def; int physical = (int)CrackOptions_Number[1].def; int open = (int)CrackOptions_Number[2].def; - SVector3 normal1d(CrackOptions_Number[3].def, - CrackOptions_Number[4].def, + SVector3 normal1d(CrackOptions_Number[3].def, CrackOptions_Number[4].def, CrackOptions_Number[5].def); - if(dim != 1 && dim != 2){ + if(dim != 1 && dim != 2) { Msg::Error("Crack dimension should be 1 or 2"); return view; } GModel *m = GModel::current(); - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; m->getPhysicalGroups(groups); - std::vector<GEntity*> entities = groups[dim][physical]; + std::vector<GEntity *> entities = groups[dim][physical]; - if(entities.empty()){ + if(entities.empty()) { Msg::Error("Physical group %d (dimension %d) is empty", physical, dim); return view; } - std::vector<GEntity*> openEntities; - if(open > 0){ + std::vector<GEntity *> openEntities; + if(open > 0) { openEntities = groups[dim - 1][open]; - if(openEntities.empty()){ + if(openEntities.empty()) { Msg::Error("Open boundary physical group %d (dimension %d) is empty", open, dim - 1); return view; } } - std::set<GEntity*> crackEntities; + std::set<GEntity *> crackEntities; crackEntities.insert(entities.begin(), entities.end()); crackEntities.insert(openEntities.begin(), openEntities.end()); // get crack elements - std::vector<MElement*> crackElements; + std::vector<MElement *> crackElements; for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) crackElements.push_back(entities[i]->getMeshElement(j)); // get internal crack vertices and boundary vertices - std::set<MVertex*> crackVertices, bndVertices; - if(dim == 1){ - for(unsigned int i = 0; i < crackElements.size(); i++){ - for(std::size_t j = 0; j < crackElements[i]->getNumVertices(); j++){ + std::set<MVertex *> crackVertices, bndVertices; + if(dim == 1) { + for(unsigned int i = 0; i < crackElements.size(); i++) { + for(std::size_t j = 0; j < crackElements[i]->getNumVertices(); j++) { MVertex *v = crackElements[i]->getVertex(j); crackVertices.insert(v); } - for(int j = 0; j < crackElements[i]->getNumPrimaryVertices(); j++){ + for(int j = 0; j < crackElements[i]->getNumPrimaryVertices(); j++) { MVertex *v = crackElements[i]->getVertex(j); if(bndVertices.find(v) == bndVertices.end()) bndVertices.insert(v); @@ -138,16 +132,16 @@ PView *GMSH_CrackPlugin::execute(PView *view) } } } - else{ + else { std::set<EdgeData, Less_EdgeData> bnd; - for(unsigned int i = 0; i < crackElements.size(); i++){ - for(std::size_t j = 0; j < crackElements[i]->getNumVertices(); j++){ + for(unsigned int i = 0; i < crackElements.size(); i++) { + for(std::size_t j = 0; j < crackElements[i]->getNumVertices(); j++) { MVertex *v = crackElements[i]->getVertex(j); crackVertices.insert(v); } - for(int j = 0; j < crackElements[i]->getNumEdges(); j++){ + for(int j = 0; j < crackElements[i]->getNumEdges(); j++) { EdgeData ed(crackElements[i]->getEdge(j)); - if(bnd.find(ed) == bnd.end()){ + if(bnd.find(ed) == bnd.end()) { crackElements[i]->getEdgeVertices(j, ed.data); bnd.insert(ed); } @@ -155,41 +149,42 @@ PView *GMSH_CrackPlugin::execute(PView *view) bnd.erase(ed); } } - for(std::set<EdgeData, Less_EdgeData>::iterator it = bnd.begin(); it != bnd.end(); it++) + for(std::set<EdgeData, Less_EdgeData>::iterator it = bnd.begin(); + it != bnd.end(); it++) bndVertices.insert(it->data.begin(), it->data.end()); } // get (forced) open boundary vertices and remove them from boundary vertices - for(unsigned int i = 0; i < openEntities.size(); i++){ - for(unsigned int j = 0; j < openEntities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < openEntities.size(); i++) { + for(unsigned int j = 0; j < openEntities[i]->getNumMeshElements(); j++) { MElement *e = openEntities[i]->getMeshElement(j); - for(std::size_t k = 0; k < e->getNumVertices(); k++){ + for(std::size_t k = 0; k < e->getNumVertices(); k++) { MVertex *v = e->getVertex(k); bndVertices.erase(v); } } } - for(std::set<MVertex*>::iterator it = bndVertices.begin(); + for(std::set<MVertex *>::iterator it = bndVertices.begin(); it != bndVertices.end(); it++) crackVertices.erase(*it); // compute elements on one side of the crack - std::set<MElement*> oneside; - std::vector<GEntity*> allentities; + std::set<MElement *> oneside; + std::vector<GEntity *> allentities; m->getEntities(allentities); - for(unsigned int ent = 0; ent < allentities.size(); ent++){ + for(unsigned int ent = 0; ent < allentities.size(); ent++) { if(crackEntities.find(allentities[ent]) != crackEntities.end()) continue; - for(unsigned int i = 0; i < allentities[ent]->getNumMeshElements(); i++){ + for(unsigned int i = 0; i < allentities[ent]->getNumMeshElements(); i++) { MElement *e = allentities[ent]->getMeshElement(i); - for(std::size_t j = 0; j < e->getNumVertices(); j++){ - if(crackVertices.find(e->getVertex(j)) != crackVertices.end()){ + for(std::size_t j = 0; j < e->getNumVertices(); j++) { + if(crackVertices.find(e->getVertex(j)) != crackVertices.end()) { // element touches the crack: find the closest crack element SPoint3 b = e->barycenter(); double d = 1e200; MElement *ce = 0; - for(unsigned int k = 0; k < crackElements.size(); k++){ + for(unsigned int k = 0; k < crackElements.size(); k++) { double d2 = b.distance(crackElements[k]->barycenter()); - if(d2 < d){ + if(d2 < d) { d = d2; ce = crackElements[k]; } @@ -200,7 +195,7 @@ PView *GMSH_CrackPlugin::execute(PView *view) n = crossprod(normal1d, ce->getEdge(0).tangent()); else n = ce->getFace(0).normal(); - if(dot(n, dv) < 0){ + if(dot(n, dv) < 0) { oneside.insert(e); } } @@ -212,7 +207,8 @@ PView *GMSH_CrackPlugin::execute(PView *view) FILE *fp = fopen("debug.pos", "w"); if(fp){ fprintf(fp, "View \"Ele < 0\" {\n"); - for(std::set<MElement*>::iterator it = oneside.begin(); it != oneside.end(); it++) + for(std::set<MElement*>::iterator it = oneside.begin(); it != oneside.end(); + it++) (*it)->writePOS(fp, false, true, false, false, false, false); fprintf(fp, "};\n"); fclose(fp); @@ -222,21 +218,22 @@ PView *GMSH_CrackPlugin::execute(PView *view) // create new crack entity GEdge *crackEdge = 0; GFace *crackFace = 0; - if(dim == 1){ + if(dim == 1) { crackEdge = new discreteEdge(m, m->getMaxElementaryNumber(1) + 1, 0, 0); m->add(crackEdge); } - else{ + else { crackFace = new discreteFace(m, m->getMaxElementaryNumber(2) + 1); m->add(crackFace); } - GEntity *crackEntity = crackEdge ? (GEntity*)crackEdge : (GEntity*)crackFace; + GEntity *crackEntity = + crackEdge ? (GEntity *)crackEdge : (GEntity *)crackFace; crackEntity->physicals.push_back(physical); // duplicate internal crack vertices - std::map<MVertex*, MVertex*> vxv; - for(std::set<MVertex*>::iterator it = crackVertices.begin(); - it != crackVertices.end(); it++){ + std::map<MVertex *, MVertex *> vxv; + for(std::set<MVertex *>::iterator it = crackVertices.begin(); + it != crackVertices.end(); it++) { MVertex *v = *it; MVertex *newv = new MVertex(v->x(), v->y(), v->z(), crackEntity); crackEntity->mesh_vertices.push_back(newv); @@ -244,30 +241,29 @@ PView *GMSH_CrackPlugin::execute(PView *view) } // duplicate crack elements - for(unsigned int i = 0; i < crackElements.size(); i++){ + for(unsigned int i = 0; i < crackElements.size(); i++) { MElement *e = crackElements[i]; - std::vector<MVertex*> verts; + std::vector<MVertex *> verts; e->getVertices(verts); - for(unsigned int j = 0; j < verts.size(); j++){ - if(vxv.count(verts[j])) - verts[j] = vxv[verts[j]]; + for(unsigned int j = 0; j < verts.size(); j++) { + if(vxv.count(verts[j])) verts[j] = vxv[verts[j]]; } MElementFactory f; MElement *newe = f.create(e->getTypeForMSH(), verts, 0, e->getPartition()); if(crackEdge && newe->getType() == TYPE_LIN) - crackEdge->lines.push_back((MLine*)newe); + crackEdge->lines.push_back((MLine *)newe); else if(crackFace && newe->getType() == TYPE_TRI) - crackFace->triangles.push_back((MTriangle*)newe); + crackFace->triangles.push_back((MTriangle *)newe); else if(crackFace && newe->getType() == TYPE_QUA) - crackFace->quadrangles.push_back((MQuadrangle*)newe); + crackFace->quadrangles.push_back((MQuadrangle *)newe); } // replace vertices in elements on one side of the crack - for(std::set<MElement*>::iterator it = oneside.begin(); it != oneside.end(); it++){ + for(std::set<MElement *>::iterator it = oneside.begin(); it != oneside.end(); + it++) { MElement *e = *it; - for(std::size_t i = 0; i < e->getNumVertices(); i++){ - if(vxv.count(e->getVertex(i))) - e->setVertex(i, vxv[e->getVertex(i)]); + for(std::size_t i = 0; i < e->getNumVertices(); i++) { + if(vxv.count(e->getVertex(i))) e->setVertex(i, vxv[e->getVertex(i)]); } } diff --git a/Plugin/Crack.h b/Plugin/Crack.h index 7487439c85e234180c6ffd4e03d24c902871a78f..7339733dca7f319aaa09eda40c768f5a7d7ad504 100644 --- a/Plugin/Crack.h +++ b/Plugin/Crack.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCrackPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterCrackPlugin(); } -class GMSH_CrackPlugin : public GMSH_PostPlugin -{ - public: - GMSH_CrackPlugin(){} +class GMSH_CrackPlugin : public GMSH_PostPlugin { +public: + GMSH_CrackPlugin() {} std::string getName() const { return "Crack"; } - std::string getShortHelp() const - { - return "Crack generator"; - } + std::string getShortHelp() const { return "Crack generator"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Curl.cpp b/Plugin/Curl.cpp index cc590d16b40793ac95d9b7c6a7b07ce23bd0c4b8..64fcb2455494770d1d0d9cb59756f29a9dfc6540 100644 --- a/Plugin/Curl.cpp +++ b/Plugin/Curl.cpp @@ -7,24 +7,18 @@ #include "shapeFunctions.h" #include "GmshDefines.h" -StringXNumber CurlOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.} -}; +StringXNumber CurlOptions_Number[] = {{GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCurlPlugin() - { - return new GMSH_CurlPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterCurlPlugin() { return new GMSH_CurlPlugin(); } } std::string GMSH_CurlPlugin::getHelp() const { return "Plugin(Curl) computes the curl of the field " - "in the view `View'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Curl) creates one new view."; + "in the view `View'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Curl) creates one new view."; } int GMSH_CurlPlugin::getNbOptions() const @@ -45,17 +39,18 @@ PView *GMSH_CurlPlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = getPossiblyAdaptiveData(v1); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("Curl plugin cannot be run on multi-mesh views"); return v; } PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); + int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); - for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++){ - for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++) { + for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); + ele++) { if(data1->skipElement(firstNonEmptyStep, ent, ele)) continue; int numComp = data1->getNumComponents(firstNonEmptyStep, ent, ele); if(numComp != 3) continue; @@ -65,7 +60,8 @@ PView *GMSH_CurlPlugin::execute(PView *v) if(!out) continue; double x[8], y[8], z[8], val[8 * 3]; for(int nod = 0; nod < numNodes; nod++) - data1->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], z[nod]); + data1->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], + z[nod]); int dim = data1->getDimension(firstNonEmptyStep, ent, ele); elementFactory factory; element *element = factory.create(numNodes, dim, x, y, z); @@ -73,12 +69,13 @@ PView *GMSH_CurlPlugin::execute(PView *v) for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); - for(int step = 0; step < data1->getNumTimeSteps(); step++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { if(!data1->hasTimeStep(step)) continue; for(int nod = 0; nod < numNodes; nod++) for(int comp = 0; comp < numComp; comp++) - data1->getValue(step, ent, ele, nod, comp, val[numComp * nod + comp]); - for(int nod = 0; nod < numNodes; nod++){ + data1->getValue(step, ent, ele, nod, comp, + val[numComp * nod + comp]); + for(int nod = 0; nod < numNodes; nod++) { double u, v, w, f[3]; element->getNode(nod, u, v, w); element->interpolateCurl(val, u, v, w, f, 3); @@ -91,7 +88,7 @@ PView *GMSH_CurlPlugin::execute(PView *v) } } - for(int i = 0; i < data1->getNumTimeSteps(); i++){ + for(int i = 0; i < data1->getNumTimeSteps(); i++) { if(!data1->hasTimeStep(i)) continue; double time = data1->getTime(i); data2->Time.push_back(time); diff --git a/Plugin/Curl.h b/Plugin/Curl.h index 3523b72ba1195948ed10d46e6b4d47618cef0404..71de01b3d0c6ed036535f6de5e10f96d49f2f620 100644 --- a/Plugin/Curl.h +++ b/Plugin/Curl.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCurlPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterCurlPlugin(); } -class GMSH_CurlPlugin : public GMSH_PostPlugin -{ - public: - GMSH_CurlPlugin(){} +class GMSH_CurlPlugin : public GMSH_PostPlugin { +public: + GMSH_CurlPlugin() {} std::string getName() const { return "Curl"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_CurlPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/CurvedBndDist.cpp b/Plugin/CurvedBndDist.cpp index eb697fe656b7d633d5a4294c10d7b33530fd350c..99ab2686a327f91f7e87340f2e1af6f52ab7a522 100644 --- a/Plugin/CurvedBndDist.cpp +++ b/Plugin/CurvedBndDist.cpp @@ -15,12 +15,11 @@ #include "OptHomIntegralBoundaryDist.h" #endif -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterCurvedBndDistPlugin() { - GMSH_Plugin *GMSH_RegisterCurvedBndDistPlugin() - { - return new GMSH_CurvedBndDistPlugin(); - } + return new GMSH_CurvedBndDistPlugin(); +} } std::string GMSH_CurvedBndDistPlugin::getHelp() const @@ -30,57 +29,65 @@ std::string GMSH_CurvedBndDistPlugin::getHelp() const #if defined(HAVE_OPTHOM) -static void addLine(PViewDataList *data, const SVector3 &p0, const SVector3 &p1, double v0, double v1) -{ - data->NbSL ++; - data->SL.push_back(p0.x()); data->SL.push_back(p1.x()); - data->SL.push_back(p0.y()); data->SL.push_back(p1.y()); - data->SL.push_back(p0.z()); data->SL.push_back(p1.z()); - data->SL.push_back(v0); data->SL.push_back(v1); -} - -/* -static void addQua(PViewDataList *data, const SVector3 &p0, const SVector3 &p1, - const SVector3 &p2, const SVector3 &p3, double v) +static void addLine(PViewDataList *data, const SVector3 &p0, const SVector3 &p1, + double v0, double v1) { - data->NbSQ ++; - data->SQ.push_back(p0.x()); data->SQ.push_back(p1.x()); data->SQ.push_back(p2.x()); data->SQ.push_back(p3.x()); - data->SQ.push_back(p0.y()); data->SQ.push_back(p1.y()); data->SQ.push_back(p2.y()); data->SQ.push_back(p3.y()); - data->SQ.push_back(p0.z()); data->SQ.push_back(p1.z()); data->SQ.push_back(p2.z()); data->SQ.push_back(p3.z()); - data->SQ.push_back(v); data->SQ.push_back(v); data->SQ.push_back(v); data->SQ.push_back(v); + data->NbSL++; + data->SL.push_back(p0.x()); + data->SL.push_back(p1.x()); + data->SL.push_back(p0.y()); + data->SL.push_back(p1.y()); + data->SL.push_back(p0.z()); + data->SL.push_back(p1.z()); + data->SL.push_back(v0); + data->SL.push_back(v1); } -static void addPoint(PViewDataList *data, const SVector3 &p0, double v0) -{ - data->NbSP ++; - data->SP.push_back(p0.x()); - data->SP.push_back(p0.y()); - data->SP.push_back(p0.z()); - data->SP.push_back(v0); -} + /* + static void addQua(PViewDataList *data, const SVector3 &p0, const SVector3 + &p1, const SVector3 &p2, const SVector3 &p3, double v) + { + data->NbSQ ++; + data->SQ.push_back(p0.x()); data->SQ.push_back(p1.x()); + data->SQ.push_back(p2.x()); data->SQ.push_back(p3.x()); + data->SQ.push_back(p0.y()); data->SQ.push_back(p1.y()); + data->SQ.push_back(p2.y()); data->SQ.push_back(p3.y()); + data->SQ.push_back(p0.z()); data->SQ.push_back(p1.z()); + data->SQ.push_back(p2.z()); data->SQ.push_back(p3.z()); data->SQ.push_back(v); + data->SQ.push_back(v); data->SQ.push_back(v); data->SQ.push_back(v); + } -static void addVP(PViewDataList *data, const SVector3 p0, SVector3 v) -{ - data->NbVP ++; - data->VP.push_back(p0.x()); - data->VP.push_back(p0.y()); - data->VP.push_back(p0.z()); - data->VP.push_back(v.x()); - data->VP.push_back(v.y()); - data->VP.push_back(v.z()); -} -*/ + static void addPoint(PViewDataList *data, const SVector3 &p0, double v0) + { + data->NbSP ++; + data->SP.push_back(p0.x()); + data->SP.push_back(p0.y()); + data->SP.push_back(p0.z()); + data->SP.push_back(v0); + } + static void addVP(PViewDataList *data, const SVector3 p0, SVector3 v) + { + data->NbVP ++; + data->VP.push_back(p0.x()); + data->VP.push_back(p0.y()); + data->VP.push_back(p0.z()); + data->VP.push_back(v.x()); + data->VP.push_back(v.y()); + data->VP.push_back(v.z()); + } + */ #include <limits> static void drawElementDist(PViewDataList *data, GEdge *edge, - const std::vector<MVertex *>&vertices, const nodalBasis &basis) + const std::vector<MVertex *> &vertices, + const nodalBasis &basis) { std::vector<double> gradient; std::vector<double> param(vertices.size()); std::vector<bool> onEdge(vertices.size()); std::vector<SPoint3> xyz(vertices.size()); - for (size_t i = 0; i < vertices.size(); ++i) { + for(size_t i = 0; i < vertices.size(); ++i) { MVertex *v = vertices[i]; reparamMeshVertexOnEdge(v, edge, param[i]); onEdge[i] = v->onWhat() == edge; @@ -89,40 +96,40 @@ static void drawElementDist(PViewDataList *data, GEdge *edge, parametricLineGEdge line0(edge, param[0], param[1]); parametricLineNodalBasis line1(basis, xyz); { - SPoint3 p,p1; - line0.hausdorffDistance(line1,p,p1); + SPoint3 p, p1; + line0.hausdorffDistance(line1, p, p1); addLine(data, p, p1, 0., 1); } } -/* -static void drawElement(PViewDataList *data, GEdge *edge, - const std::vector<MVertex *>&vertices, const nodalBasis &basis) -{ - std::vector<double> gradient; - std::vector<double> param(vertices.size()); - std::vector<bool> onEdge(vertices.size()); - std::vector<SPoint3> xyz(vertices.size()); - for (size_t i = 0; i < vertices.size(); ++i) { - MVertex *v = vertices[i]; - reparamMeshVertexOnEdge(v, edge, param[i]); - onEdge[i] = v->onWhat() == edge; - xyz[i] = v->point(); - } - computeBndDistAndGradient(edge, param, vertices, basis, xyz, onEdge, gradient,1.e-6); - for (size_t i = 0; i < vertices.size(); ++i) { - double t0; - reparamMeshVertexOnEdge(vertices[i], edge, t0); - SPoint3 p = vertices[i]->point(); - GPoint gpt = edge->point(t0 + 1e-8); - SPoint3 pt(gpt.x(), gpt.y(), gpt.z()); - SVector3 t = (pt - p); - t.normalize(); - //addPoint(data, p, 0); - addVP(data, p, t * (-gradient[i])); + /* + static void drawElement(PViewDataList *data, GEdge *edge, + const std::vector<MVertex *>&vertices, const + nodalBasis &basis) + { + std::vector<double> gradient; + std::vector<double> param(vertices.size()); + std::vector<bool> onEdge(vertices.size()); + std::vector<SPoint3> xyz(vertices.size()); + for (size_t i = 0; i < vertices.size(); ++i) { + MVertex *v = vertices[i]; + reparamMeshVertexOnEdge(v, edge, param[i]); + onEdge[i] = v->onWhat() == edge; + xyz[i] = v->point(); + } + computeBndDistAndGradient(edge, param, vertices, basis, xyz, onEdge, + gradient,1.e-6); for (size_t i = 0; i < vertices.size(); ++i) { double t0; + reparamMeshVertexOnEdge(vertices[i], edge, t0); + SPoint3 p = vertices[i]->point(); + GPoint gpt = edge->point(t0 + 1e-8); + SPoint3 pt(gpt.x(), gpt.y(), gpt.z()); + SVector3 t = (pt - p); + t.normalize(); + //addPoint(data, p, 0); + addVP(data, p, t * (-gradient[i])); + } } -} -*/ + */ #endif @@ -133,27 +140,29 @@ PView *GMSH_CurvedBndDistPlugin::execute(PView *v) PViewDataList *data = getDataList(pv); data->Time.push_back(0.); GModel *m = GModel::current(); - for (GModel::fiter iface = m->firstFace(); iface != m->lastFace(); ++iface) { + for(GModel::fiter iface = m->firstFace(); iface != m->lastFace(); ++iface) { GFace *face = *iface; - for (size_t iElement = 0; iElement < face->getNumMeshElements(); ++iElement) { + for(size_t iElement = 0; iElement < face->getNumMeshElements(); + ++iElement) { MElement *element = face->getMeshElement(iElement); const nodalBasis &elbasis = *element->getFunctionSpace(); - for (int iEdge = 0; iEdge < element->getNumEdges(); ++iEdge) { - int clId = elbasis.getClosureId(iEdge, 1); + for(int iEdge = 0; iEdge < element->getNumEdges(); ++iEdge) { + int clId = elbasis.getClosureId(iEdge, 1); const std::vector<int> &closure = elbasis.closures[clId]; std::vector<MVertex *> vertices; GEdge *edge = NULL; - for (size_t i = 0; i < closure.size(); ++i) { + for(size_t i = 0; i < closure.size(); ++i) { MVertex *v = element->getVertex(closure[i]); vertices.push_back(v); - if ((int)i >= 2 && v->onWhat() && v->onWhat()->dim() == 1) { + if((int)i >= 2 && v->onWhat() && v->onWhat()->dim() == 1) { edge = v->onWhat()->cast2Edge(); } } - if (edge){ - drawElementDist(data, edge, vertices, - *BasisFactory::getNodalBasis(elbasis.getClosureType(clId))); - } + if(edge) { + drawElementDist( + data, edge, vertices, + *BasisFactory::getNodalBasis(elbasis.getClosureType(clId))); + } } } } @@ -164,4 +173,3 @@ PView *GMSH_CurvedBndDistPlugin::execute(PView *v) return v; #endif } - diff --git a/Plugin/CurvedBndDist.h b/Plugin/CurvedBndDist.h index 4d1306117087413ac43046abb7ed2508247fa131..20d1d504afe163b53659d9e89e7600ab5dd7769f 100644 --- a/Plugin/CurvedBndDist.h +++ b/Plugin/CurvedBndDist.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCurvedBndDistPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterCurvedBndDistPlugin(); } -class GMSH_CurvedBndDistPlugin : public GMSH_PostPlugin -{ - public : - GMSH_CurvedBndDistPlugin(){} +class GMSH_CurvedBndDistPlugin : public GMSH_PostPlugin { +public: + GMSH_CurvedBndDistPlugin() {} std::string getName() const { return "CurvedBndDist"; } std::string getShortHelp() const { diff --git a/Plugin/CutBox.cpp b/Plugin/CutBox.cpp index 06591788cd5b12c354d60bf7835b086e5f48d56c..73a8895323fa0cfd2f865979d94d4dd4b9c10ee6 100644 --- a/Plugin/CutBox.cpp +++ b/Plugin/CutBox.cpp @@ -30,135 +30,130 @@ StringXNumber CutBoxOptions_Number[] = { {GMSH_FULLRC, "NumPointsW", GMSH_CutBoxPlugin::callbackW, 20}, {GMSH_FULLRC, "ConnectPoints", GMSH_CutBoxPlugin::callbackConnect, 1}, {GMSH_FULLRC, "Boundary", GMSH_CutBoxPlugin::callbackBoundary, 1}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutBoxPlugin() - { - return new GMSH_CutBoxPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterCutBoxPlugin() { return new GMSH_CutBoxPlugin(); } } void GMSH_CutBoxPlugin::draw(void *context) { #if defined(HAVE_OPENGL) - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); double p[3]; - drawContext *ctx = (drawContext*)context; + drawContext *ctx = (drawContext *)context; getPoint(0, 0, 0, p); ctx->drawString("(X0, Y0, Z0)", p[0], p[1], p[2]); - if(getNbU() > 1){ + if(getNbU() > 1) { getPoint(getNbU() - 1, 0, 0, p); ctx->drawString("(X1, Y1, Z1)", p[0], p[1], p[2]); } - if(getNbV() > 1){ + if(getNbV() > 1) { getPoint(0, getNbV() - 1, 0, p); ctx->drawString("(X2, Y2, Z2)", p[0], p[1], p[2]); } - if(getNbW() > 1){ + if(getNbW() > 1) { getPoint(0, 0, getNbW() - 1, p); ctx->drawString("(X3, Y3, Z3)", p[0], p[1], p[2]); } - if(CutBoxOptions_Number[15].def){ + if(CutBoxOptions_Number[15].def) { glBegin(GL_LINES); - //UV - for(int i = 0; i < getNbU(); ++i){ + // UV + for(int i = 0; i < getNbU(); ++i) { getPoint(i, 0, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(i, getNbV()-1, 0, p); + getPoint(i, getNbV() - 1, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(i, 0, getNbW()-1, p); + getPoint(i, 0, getNbW() - 1, p); glVertex3d(p[0], p[1], p[2]); - getPoint(i, getNbV()-1, getNbW()-1, p); + getPoint(i, getNbV() - 1, getNbW() - 1, p); glVertex3d(p[0], p[1], p[2]); } - for(int i = 0; i < getNbV(); ++i){ + for(int i = 0; i < getNbV(); ++i) { getPoint(0, i, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, i, 0, p); + getPoint(getNbU() - 1, i, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(0, i, getNbW()-1, p); + getPoint(0, i, getNbW() - 1, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, i, getNbW()-1, p); + getPoint(getNbU() - 1, i, getNbW() - 1, p); glVertex3d(p[0], p[1], p[2]); } // UW - for(int i = 0; i < getNbU(); ++i){ + for(int i = 0; i < getNbU(); ++i) { getPoint(i, 0, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(i, 0, getNbW()-1, p); + getPoint(i, 0, getNbW() - 1, p); glVertex3d(p[0], p[1], p[2]); - getPoint(i, getNbV()-1, 0, p); + getPoint(i, getNbV() - 1, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(i, getNbV()-1, getNbW()-1, p); + getPoint(i, getNbV() - 1, getNbW() - 1, p); glVertex3d(p[0], p[1], p[2]); } - for(int i = 0; i < getNbW(); ++i){ + for(int i = 0; i < getNbW(); ++i) { getPoint(0, 0, i, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, 0, i, p); + getPoint(getNbU() - 1, 0, i, p); glVertex3d(p[0], p[1], p[2]); - getPoint(0, getNbV()-1, i, p); + getPoint(0, getNbV() - 1, i, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, getNbV()-1, i, p); + getPoint(getNbU() - 1, getNbV() - 1, i, p); glVertex3d(p[0], p[1], p[2]); } // VW - for(int i = 0; i < getNbV(); ++i){ + for(int i = 0; i < getNbV(); ++i) { getPoint(0, i, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(0, i, getNbW()-1, p); + getPoint(0, i, getNbW() - 1, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, i, 0, p); + getPoint(getNbU() - 1, i, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, i, getNbW()-1, p); + getPoint(getNbU() - 1, i, getNbW() - 1, p); glVertex3d(p[0], p[1], p[2]); } - for(int i = 0; i < getNbW(); ++i){ + for(int i = 0; i < getNbW(); ++i) { getPoint(0, 0, i, p); glVertex3d(p[0], p[1], p[2]); - getPoint(0, getNbV()-1, i, p); + getPoint(0, getNbV() - 1, i, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, 0, i, p); + getPoint(getNbU() - 1, 0, i, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, getNbV()-1, i, p); + getPoint(getNbU() - 1, getNbV() - 1, i, p); glVertex3d(p[0], p[1], p[2]); } glEnd(); } - else{ - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ + else { + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { getPoint(i, j, 0, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); - getPoint(i, j, getNbW()-1, p); + getPoint(i, j, getNbW() - 1, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); } } - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbW(); ++j){ + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbW(); ++j) { getPoint(i, 0, j, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); - getPoint(i, getNbV()-1, j, p); + getPoint(i, getNbV() - 1, j, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); } } - for(int i = 0; i < getNbV(); ++i){ - for(int j = 0; j < getNbW(); ++j){ + for(int i = 0; i < getNbV(); ++i) { + for(int j = 0; j < getNbW(); ++j) { getPoint(0, i, j, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); - getPoint(getNbU()-1, i, j, p); + getPoint(getNbU() - 1, i, j, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); } } @@ -166,10 +161,11 @@ void GMSH_CutBoxPlugin::draw(void *context) #endif } -double GMSH_CutBoxPlugin::callback(int num, int action, double value, double *opt, - double step, double min, double max) +double GMSH_CutBoxPlugin::callback(int num, int action, double value, + double *opt, double step, double min, + double max) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return step; case 2: return min; case 3: return max; @@ -266,51 +262,46 @@ double GMSH_CutBoxPlugin::callbackZ3(int num, int action, double value) double GMSH_CutBoxPlugin::callbackU(int num, int action, double value) { - return callback(num, action, value, &CutBoxOptions_Number[12].def, - 1, 1, 200); + return callback(num, action, value, &CutBoxOptions_Number[12].def, 1, 1, 200); } double GMSH_CutBoxPlugin::callbackV(int num, int action, double value) { - return callback(num, action, value, &CutBoxOptions_Number[13].def, - 1, 1, 200); + return callback(num, action, value, &CutBoxOptions_Number[13].def, 1, 1, 200); } double GMSH_CutBoxPlugin::callbackW(int num, int action, double value) { - return callback(num, action, value, &CutBoxOptions_Number[14].def, - 1, 1, 200); + return callback(num, action, value, &CutBoxOptions_Number[14].def, 1, 1, 200); } - double GMSH_CutBoxPlugin::callbackConnect(int num, int action, double value) { - return callback(num, action, value, &CutBoxOptions_Number[15].def, - 1, 0, 1); + return callback(num, action, value, &CutBoxOptions_Number[15].def, 1, 0, 1); } double GMSH_CutBoxPlugin::callbackBoundary(int num, int action, double value) { - return callback(num, action, value, &CutBoxOptions_Number[16].def, - 1, 0, 1); + return callback(num, action, value, &CutBoxOptions_Number[16].def, 1, 0, 1); } std::string GMSH_CutBoxPlugin::getHelp() const { return "Plugin(CutBox) cuts the view `View' with a " - "rectangular box defined by the 4 points " - "(`X0',`Y0',`Z0') (origin), (`X1',`Y1',`Z1') (axis of U), " - "(`X2',`Y2',`Z2') (axis of V) and (`X3',`Y3',`Z3') (axis of W).\n\n" - "The number of points along U, V, W is set with the " - "options `NumPointsU', `NumPointsV' and `NumPointsW'.\n\n" - "If `ConnectPoints' is zero, the plugin creates points; " - "otherwise, the plugin generates hexahedra, quadrangles, lines or " - "points depending on the values of `NumPointsU', " - "`NumPointsV' and `NumPointsW'.\n\n" - "If `Boundary' is zero, the plugin interpolates the view inside " - "the box; otherwise the plugin interpolates the view at its boundary.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(CutBox) creates one new view."; + "rectangular box defined by the 4 points " + "(`X0',`Y0',`Z0') (origin), (`X1',`Y1',`Z1') (axis of U), " + "(`X2',`Y2',`Z2') (axis of V) and (`X3',`Y3',`Z3') (axis of W).\n\n" + "The number of points along U, V, W is set with the " + "options `NumPointsU', `NumPointsV' and `NumPointsW'.\n\n" + "If `ConnectPoints' is zero, the plugin creates points; " + "otherwise, the plugin generates hexahedra, quadrangles, lines or " + "points depending on the values of `NumPointsU', " + "`NumPointsV' and `NumPointsW'.\n\n" + "If `Boundary' is zero, the plugin interpolates the view inside " + "the box; otherwise the plugin interpolates the view at its " + "boundary.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(CutBox) creates one new view."; } int GMSH_CutBoxPlugin::getNbOptions() const @@ -323,21 +314,11 @@ StringXNumber *GMSH_CutBoxPlugin::getOption(int iopt) return &CutBoxOptions_Number[iopt]; } -int GMSH_CutBoxPlugin::getNbU() -{ - return (int)CutBoxOptions_Number[12].def; -} - -int GMSH_CutBoxPlugin::getNbV() -{ - return (int)CutBoxOptions_Number[13].def; -} +int GMSH_CutBoxPlugin::getNbU() { return (int)CutBoxOptions_Number[12].def; } -int GMSH_CutBoxPlugin::getNbW() -{ - return (int)CutBoxOptions_Number[14].def; -} +int GMSH_CutBoxPlugin::getNbV() { return (int)CutBoxOptions_Number[13].def; } +int GMSH_CutBoxPlugin::getNbW() { return (int)CutBoxOptions_Number[14].def; } void GMSH_CutBoxPlugin::getPoint(int iU, int iV, int iW, double *X) { @@ -346,572 +327,684 @@ void GMSH_CutBoxPlugin::getPoint(int iU, int iV, int iW, double *X) double w = getNbW() > 1 ? (double)iW / (double)(getNbW() - 1.) : 0.; X[0] = CutBoxOptions_Number[0].def + - u * (CutBoxOptions_Number[3].def-CutBoxOptions_Number[0].def) + - v * (CutBoxOptions_Number[6].def-CutBoxOptions_Number[0].def) + - w * (CutBoxOptions_Number[9].def-CutBoxOptions_Number[0].def) ; + u * (CutBoxOptions_Number[3].def - CutBoxOptions_Number[0].def) + + v * (CutBoxOptions_Number[6].def - CutBoxOptions_Number[0].def) + + w * (CutBoxOptions_Number[9].def - CutBoxOptions_Number[0].def); X[1] = CutBoxOptions_Number[1].def + - u * (CutBoxOptions_Number[4].def-CutBoxOptions_Number[1].def) + - v * (CutBoxOptions_Number[7].def-CutBoxOptions_Number[1].def) + - w * (CutBoxOptions_Number[10].def-CutBoxOptions_Number[1].def) ; + u * (CutBoxOptions_Number[4].def - CutBoxOptions_Number[1].def) + + v * (CutBoxOptions_Number[7].def - CutBoxOptions_Number[1].def) + + w * (CutBoxOptions_Number[10].def - CutBoxOptions_Number[1].def); X[2] = CutBoxOptions_Number[2].def + - u * (CutBoxOptions_Number[5].def-CutBoxOptions_Number[2].def) + - v * (CutBoxOptions_Number[8].def-CutBoxOptions_Number[2].def) + - w * (CutBoxOptions_Number[11].def-CutBoxOptions_Number[2].def) ; + u * (CutBoxOptions_Number[5].def - CutBoxOptions_Number[2].def) + + v * (CutBoxOptions_Number[8].def - CutBoxOptions_Number[2].def) + + w * (CutBoxOptions_Number[11].def - CutBoxOptions_Number[2].def); } -void GMSH_CutBoxPlugin::addInView( int connect, int boundary, int numsteps, int nbcomp, - double ****pnts, double ****vals, - std::vector<double> &P, int *nP, - std::vector<double> &L, int *nL, - std::vector<double> &Q, int *nQ, - std::vector<double> &H, int *nH) +void GMSH_CutBoxPlugin::addInView(int connect, int boundary, int numsteps, + int nbcomp, double ****pnts, double ****vals, + std::vector<double> &P, int *nP, + std::vector<double> &L, int *nL, + std::vector<double> &Q, int *nQ, + std::vector<double> &H, int *nH) { - if(!connect || (getNbU() == 1 && getNbV() == 1 && getNbW() == 1)){ // generate points + if(!connect || + (getNbU() == 1 && getNbV() == 1 && getNbW() == 1)) { // generate points if(!boundary) - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ - for(int m = 0; m < getNbW(); ++m){ + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { + for(int m = 0; m < getNbW(); ++m) { P.push_back(pnts[i][j][m][0]); P.push_back(pnts[i][j][m][1]); P.push_back(pnts[i][j][m][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[i][j][m][nbcomp*k+l]); + P.push_back(vals[i][j][m][nbcomp * k + l]); } } } } - else{ - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ + else { + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { P.push_back(pnts[i][j][0][0]); P.push_back(pnts[i][j][0][1]); P.push_back(pnts[i][j][0][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[i][j][0][nbcomp*k+l]); + P.push_back(vals[i][j][0][nbcomp * k + l]); } - P.push_back(pnts[i][j][getNbW()-1][0]); - P.push_back(pnts[i][j][getNbW()-1][1]); - P.push_back(pnts[i][j][getNbW()-1][2]); + P.push_back(pnts[i][j][getNbW() - 1][0]); + P.push_back(pnts[i][j][getNbW() - 1][1]); + P.push_back(pnts[i][j][getNbW() - 1][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[i][j][getNbW()-1][nbcomp*k+l]); + P.push_back(vals[i][j][getNbW() - 1][nbcomp * k + l]); } } - }// end UV planes - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbW(); ++j){ + } // end UV planes + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbW(); ++j) { P.push_back(pnts[i][0][j][0]); P.push_back(pnts[i][0][j][1]); P.push_back(pnts[i][0][j][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[i][0][j][nbcomp*k+l]); + P.push_back(vals[i][0][j][nbcomp * k + l]); } - P.push_back(pnts[i][getNbV()-1][j][0]); - P.push_back(pnts[i][getNbV()-1][j][1]); - P.push_back(pnts[i][getNbV()-1][j][2]); + P.push_back(pnts[i][getNbV() - 1][j][0]); + P.push_back(pnts[i][getNbV() - 1][j][1]); + P.push_back(pnts[i][getNbV() - 1][j][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[i][getNbV()-1][j][nbcomp*k+l]); + P.push_back(vals[i][getNbV() - 1][j][nbcomp * k + l]); } } - }// end UW planes - for(int i = 0; i < getNbV(); ++i){ - for(int j = 0; j < getNbW(); ++j){ + } // end UW planes + for(int i = 0; i < getNbV(); ++i) { + for(int j = 0; j < getNbW(); ++j) { P.push_back(pnts[0][i][j][0]); P.push_back(pnts[0][i][j][1]); P.push_back(pnts[0][i][j][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[0][i][j][nbcomp*k+l]); + P.push_back(vals[0][i][j][nbcomp * k + l]); } - P.push_back(pnts[getNbU()-1][i][j][0]); - P.push_back(pnts[getNbU()-1][i][j][1]); - P.push_back(pnts[getNbU()-1][i][j][2]); + P.push_back(pnts[getNbU() - 1][i][j][0]); + P.push_back(pnts[getNbU() - 1][i][j][1]); + P.push_back(pnts[getNbU() - 1][i][j][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[getNbU()-1][i][j][nbcomp*k+l]); + P.push_back(vals[getNbU() - 1][i][j][nbcomp * k + l]); } } - }//end VW planes + } // end VW planes } } - else{ // generate lines or quads - if ( getNbU() == 1 && getNbV() == 1 ){ + else { // generate lines or quads + if(getNbU() == 1 && getNbV() == 1) { if(!boundary) - for(int i = 0; i < getNbW()-1; ++i){ - L.push_back(pnts[0][0][i][0]); L.push_back(pnts[0][0][i+1][0]); - L.push_back(pnts[0][0][i][1]); L.push_back(pnts[0][0][i+1][1]); - L.push_back(pnts[0][0][i][2]); L.push_back(pnts[0][0][i+1][2]); + for(int i = 0; i < getNbW() - 1; ++i) { + L.push_back(pnts[0][0][i][0]); + L.push_back(pnts[0][0][i + 1][0]); + L.push_back(pnts[0][0][i][1]); + L.push_back(pnts[0][0][i + 1][1]); + L.push_back(pnts[0][0][i][2]); + L.push_back(pnts[0][0][i + 1][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][0][i ][nbcomp*k+l]); + L.push_back(vals[0][0][i][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][0][i+1][nbcomp*k+l]); + L.push_back(vals[0][0][i + 1][nbcomp * k + l]); } } - else{ + else { P.push_back(pnts[0][0][0][0]); P.push_back(pnts[0][0][0][1]); P.push_back(pnts[0][0][0][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[0][0][0][nbcomp*k+l]); + P.push_back(vals[0][0][0][nbcomp * k + l]); } - P.push_back(pnts[0][0][getNbW()-1][0]); - P.push_back(pnts[0][0][getNbW()-1][1]); - P.push_back(pnts[0][0][getNbW()-1][2]); + P.push_back(pnts[0][0][getNbW() - 1][0]); + P.push_back(pnts[0][0][getNbW() - 1][1]); + P.push_back(pnts[0][0][getNbW() - 1][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[0][0][getNbW()-1][nbcomp*k+l]); + P.push_back(vals[0][0][getNbW() - 1][nbcomp * k + l]); } } } - else if (getNbU() == 1 && getNbW() == 1){ + else if(getNbU() == 1 && getNbW() == 1) { if(!boundary) - for(int i = 0; i < getNbV()-1; ++i){ - L.push_back(pnts[0][i][0][0]); L.push_back(pnts[0][i+1][0][0]); - L.push_back(pnts[0][i][0][1]); L.push_back(pnts[0][i+1][0][1]); - L.push_back(pnts[0][i][0][2]); L.push_back(pnts[0][i+1][0][2]); + for(int i = 0; i < getNbV() - 1; ++i) { + L.push_back(pnts[0][i][0][0]); + L.push_back(pnts[0][i + 1][0][0]); + L.push_back(pnts[0][i][0][1]); + L.push_back(pnts[0][i + 1][0][1]); + L.push_back(pnts[0][i][0][2]); + L.push_back(pnts[0][i + 1][0][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i ][0][nbcomp*k+l]); + L.push_back(vals[0][i][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i+1][0][nbcomp*k+l]); + L.push_back(vals[0][i + 1][0][nbcomp * k + l]); } } - else{ + else { P.push_back(pnts[0][0][0][0]); P.push_back(pnts[0][0][0][1]); P.push_back(pnts[0][0][0][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[0][0][0][nbcomp*k+l]); + P.push_back(vals[0][0][0][nbcomp * k + l]); } - P.push_back(pnts[0][getNbV()-1][0][0]); - P.push_back(pnts[0][getNbV()-1][0][1]); - P.push_back(pnts[0][getNbV()-1][0][2]); + P.push_back(pnts[0][getNbV() - 1][0][0]); + P.push_back(pnts[0][getNbV() - 1][0][1]); + P.push_back(pnts[0][getNbV() - 1][0][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[0][getNbV()-1][0][nbcomp*k+l]); + P.push_back(vals[0][getNbV() - 1][0][nbcomp * k + l]); } } } - else if (getNbV() == 1 && getNbW() == 1){ + else if(getNbV() == 1 && getNbW() == 1) { if(!boundary) - for(int i = 0; i < getNbU()-1; ++i){ - L.push_back(pnts[i][0][0][0]); L.push_back(pnts[i+1][0][0][0]); - L.push_back(pnts[i][0][0][1]); L.push_back(pnts[i+1][0][0][1]); - L.push_back(pnts[i][0][0][2]); L.push_back(pnts[i+1][0][0][2]); - (*nL)++; - for(int k = 0; k < numsteps; ++k){ - for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i ][0][0][nbcomp*k+l]); - for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i+1][0][0][nbcomp*k+l]); + for(int i = 0; i < getNbU() - 1; ++i) { + L.push_back(pnts[i][0][0][0]); + L.push_back(pnts[i + 1][0][0][0]); + L.push_back(pnts[i][0][0][1]); + L.push_back(pnts[i + 1][0][0][1]); + L.push_back(pnts[i][0][0][2]); + L.push_back(pnts[i + 1][0][0][2]); + (*nL)++; + for(int k = 0; k < numsteps; ++k) { + for(int l = 0; l < nbcomp; ++l) + L.push_back(vals[i][0][0][nbcomp * k + l]); + for(int l = 0; l < nbcomp; ++l) + L.push_back(vals[i + 1][0][0][nbcomp * k + l]); + } } - } - else{ + else { P.push_back(pnts[0][0][0][0]); P.push_back(pnts[0][0][0][1]); P.push_back(pnts[0][0][0][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[0][0][0][nbcomp*k+l]); + P.push_back(vals[0][0][0][nbcomp * k + l]); } - P.push_back(pnts[getNbU()-1][0][0][0]); - P.push_back(pnts[getNbU()-1][0][0][1]); - P.push_back(pnts[getNbU()-1][0][0][2]); + P.push_back(pnts[getNbU() - 1][0][0][0]); + P.push_back(pnts[getNbU() - 1][0][0][1]); + P.push_back(pnts[getNbU() - 1][0][0][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[getNbU()-1][0][0][nbcomp*k+l]); + P.push_back(vals[getNbU() - 1][0][0][nbcomp * k + l]); } } } - else if(getNbU() == 1){ + else if(getNbU() == 1) { if(!boundary) - for(int i = 0; i < getNbV()-1; ++i){ - for(int j = 0; j < getNbW()-1; ++j){ - Q.push_back(pnts[0][i ][j ][0]); Q.push_back(pnts[0][i+1][j ][0]); - Q.push_back(pnts[0][i+1][j+1][0]); Q.push_back(pnts[0][i ][j+1][0]); - Q.push_back(pnts[0][i ][j ][1]); Q.push_back(pnts[0][i+1][j ][1]); - Q.push_back(pnts[0][i+1][j+1][1]); Q.push_back(pnts[0][i ][j+1][1]); - Q.push_back(pnts[0][i ][j ][2]); Q.push_back(pnts[0][i+1][j ][2]); - Q.push_back(pnts[0][i+1][j+1][2]); Q.push_back(pnts[0][i ][j+1][2]); + for(int i = 0; i < getNbV() - 1; ++i) { + for(int j = 0; j < getNbW() - 1; ++j) { + Q.push_back(pnts[0][i][j][0]); + Q.push_back(pnts[0][i + 1][j][0]); + Q.push_back(pnts[0][i + 1][j + 1][0]); + Q.push_back(pnts[0][i][j + 1][0]); + Q.push_back(pnts[0][i][j][1]); + Q.push_back(pnts[0][i + 1][j][1]); + Q.push_back(pnts[0][i + 1][j + 1][1]); + Q.push_back(pnts[0][i][j + 1][1]); + Q.push_back(pnts[0][i][j][2]); + Q.push_back(pnts[0][i + 1][j][2]); + Q.push_back(pnts[0][i + 1][j + 1][2]); + Q.push_back(pnts[0][i][j + 1][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[0][i ][j ][nbcomp*k+l]); + Q.push_back(vals[0][i][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[0][i+1][j ][nbcomp*k+l]); + Q.push_back(vals[0][i + 1][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[0][i+1][j+1][nbcomp*k+l]); + Q.push_back(vals[0][i + 1][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[0][i ][j+1][nbcomp*k+l]); + Q.push_back(vals[0][i][j + 1][nbcomp * k + l]); } } } - else{ - for(int i = 0; i < getNbV()-1; ++i){ - L.push_back(pnts[0][i][0][0]); L.push_back(pnts[0][i+1][0][0]); - L.push_back(pnts[0][i][0][1]); L.push_back(pnts[0][i+1][0][1]); - L.push_back(pnts[0][i][0][2]); L.push_back(pnts[0][i+1][0][2]); + else { + for(int i = 0; i < getNbV() - 1; ++i) { + L.push_back(pnts[0][i][0][0]); + L.push_back(pnts[0][i + 1][0][0]); + L.push_back(pnts[0][i][0][1]); + L.push_back(pnts[0][i + 1][0][1]); + L.push_back(pnts[0][i][0][2]); + L.push_back(pnts[0][i + 1][0][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i ][0][nbcomp*k+l]); + L.push_back(vals[0][i][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i+1][0][nbcomp*k+l]); + L.push_back(vals[0][i + 1][0][nbcomp * k + l]); } - L.push_back(pnts[0][i][getNbW()-1][0]); L.push_back(pnts[0][i+1][getNbW()-1][0]); - L.push_back(pnts[0][i][getNbW()-1][1]); L.push_back(pnts[0][i+1][getNbW()-1][1]); - L.push_back(pnts[0][i][getNbW()-1][2]); L.push_back(pnts[0][i+1][getNbW()-1][2]); + L.push_back(pnts[0][i][getNbW() - 1][0]); + L.push_back(pnts[0][i + 1][getNbW() - 1][0]); + L.push_back(pnts[0][i][getNbW() - 1][1]); + L.push_back(pnts[0][i + 1][getNbW() - 1][1]); + L.push_back(pnts[0][i][getNbW() - 1][2]); + L.push_back(pnts[0][i + 1][getNbW() - 1][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i ][getNbW()][nbcomp*k+l]); + L.push_back(vals[0][i][getNbW()][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i+1][getNbW()][nbcomp*k+l]); + L.push_back(vals[0][i + 1][getNbW()][nbcomp * k + l]); } } - for(int i = 0; i < getNbW()-1; ++i){ - L.push_back(pnts[0][0][i][0]); L.push_back(pnts[0][0][i+1][0]); - L.push_back(pnts[0][0][i][1]); L.push_back(pnts[0][0][i+1][1]); - L.push_back(pnts[0][0][i][2]); L.push_back(pnts[0][0][i+1][2]); + for(int i = 0; i < getNbW() - 1; ++i) { + L.push_back(pnts[0][0][i][0]); + L.push_back(pnts[0][0][i + 1][0]); + L.push_back(pnts[0][0][i][1]); + L.push_back(pnts[0][0][i + 1][1]); + L.push_back(pnts[0][0][i][2]); + L.push_back(pnts[0][0][i + 1][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][0][i ][nbcomp*k+l]); + L.push_back(vals[0][0][i][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][0][i+1][nbcomp*k+l]); + L.push_back(vals[0][0][i + 1][nbcomp * k + l]); } - L.push_back(pnts[0][getNbV()-1][i][0]); L.push_back(pnts[0][getNbV()-1][i+1][0]); - L.push_back(pnts[0][getNbV()-1][i][1]); L.push_back(pnts[0][getNbV()-1][i+1][1]); - L.push_back(pnts[0][getNbV()-1][i][2]); L.push_back(pnts[0][getNbV()-1][i+1][2]); + L.push_back(pnts[0][getNbV() - 1][i][0]); + L.push_back(pnts[0][getNbV() - 1][i + 1][0]); + L.push_back(pnts[0][getNbV() - 1][i][1]); + L.push_back(pnts[0][getNbV() - 1][i + 1][1]); + L.push_back(pnts[0][getNbV() - 1][i][2]); + L.push_back(pnts[0][getNbV() - 1][i + 1][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][getNbV()-1][i ][nbcomp*k+l]); + L.push_back(vals[0][getNbV() - 1][i][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][getNbV()-1][i+1][nbcomp*k+l]); + L.push_back(vals[0][getNbV() - 1][i + 1][nbcomp * k + l]); } } } } - else if(getNbV() == 1){ + else if(getNbV() == 1) { if(!boundary) - for(int i = 0; i < getNbU()-1; ++i){ - for(int j = 0; j < getNbW()-1; ++j){ - Q.push_back(pnts[i ][0][j ][0]); Q.push_back(pnts[i+1][0][j ][0]); - Q.push_back(pnts[i+1][0][j+1][0]); Q.push_back(pnts[i ][0][j+1][0]); - Q.push_back(pnts[i ][0][j ][1]); Q.push_back(pnts[i+1][0][j ][1]); - Q.push_back(pnts[i+1][0][j+1][1]); Q.push_back(pnts[i ][0][j+1][1]); - Q.push_back(pnts[i ][0][j ][2]); Q.push_back(pnts[i+1][0][j ][2]); - Q.push_back(pnts[i+1][0][j+1][2]); Q.push_back(pnts[i ][0][j+1][2]); + for(int i = 0; i < getNbU() - 1; ++i) { + for(int j = 0; j < getNbW() - 1; ++j) { + Q.push_back(pnts[i][0][j][0]); + Q.push_back(pnts[i + 1][0][j][0]); + Q.push_back(pnts[i + 1][0][j + 1][0]); + Q.push_back(pnts[i][0][j + 1][0]); + Q.push_back(pnts[i][0][j][1]); + Q.push_back(pnts[i + 1][0][j][1]); + Q.push_back(pnts[i + 1][0][j + 1][1]); + Q.push_back(pnts[i][0][j + 1][1]); + Q.push_back(pnts[i][0][j][2]); + Q.push_back(pnts[i + 1][0][j][2]); + Q.push_back(pnts[i + 1][0][j + 1][2]); + Q.push_back(pnts[i][0][j + 1][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][0][j ][nbcomp*k+l]); + Q.push_back(vals[i][0][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][0][j ][nbcomp*k+l]); + Q.push_back(vals[i + 1][0][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][0][j+1][nbcomp*k+l]); + Q.push_back(vals[i + 1][0][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][0][j+1][nbcomp*k+l]); + Q.push_back(vals[i][0][j + 1][nbcomp * k + l]); } } } - else{ - for(int i = 0; i < getNbU()-1; ++i){ - L.push_back(pnts[i][0][0][0]); L.push_back(pnts[i+1][0][0][0]); - L.push_back(pnts[i][0][0][1]); L.push_back(pnts[i+1][0][0][1]); - L.push_back(pnts[i][0][0][2]); L.push_back(pnts[i+1][0][0][2]); + else { + for(int i = 0; i < getNbU() - 1; ++i) { + L.push_back(pnts[i][0][0][0]); + L.push_back(pnts[i + 1][0][0][0]); + L.push_back(pnts[i][0][0][1]); + L.push_back(pnts[i + 1][0][0][1]); + L.push_back(pnts[i][0][0][2]); + L.push_back(pnts[i + 1][0][0][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i ][0][0][nbcomp*k+l]); + L.push_back(vals[i][0][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i+1][0][0][nbcomp*k+l]); + L.push_back(vals[i + 1][0][0][nbcomp * k + l]); } - L.push_back(pnts[i][0][getNbW()-1][0]); L.push_back(pnts[i+1][0][getNbW()-1][0]); - L.push_back(pnts[i][0][getNbW()-1][1]); L.push_back(pnts[i+1][0][getNbW()-1][1]); - L.push_back(pnts[i][0][getNbW()-1][2]); L.push_back(pnts[i+1][0][getNbW()-1][2]); + L.push_back(pnts[i][0][getNbW() - 1][0]); + L.push_back(pnts[i + 1][0][getNbW() - 1][0]); + L.push_back(pnts[i][0][getNbW() - 1][1]); + L.push_back(pnts[i + 1][0][getNbW() - 1][1]); + L.push_back(pnts[i][0][getNbW() - 1][2]); + L.push_back(pnts[i + 1][0][getNbW() - 1][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i ][0][getNbW()-1][nbcomp*k+l]); + L.push_back(vals[i][0][getNbW() - 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i+1][0][getNbW()-1][nbcomp*k+l]); + L.push_back(vals[i + 1][0][getNbW() - 1][nbcomp * k + l]); } } - for(int i = 0; i < getNbW()-1; ++i){ - L.push_back(pnts[0][0][i][0]); L.push_back(pnts[0][0][i+1][0]); - L.push_back(pnts[0][0][i][1]); L.push_back(pnts[0][0][i+1][1]); - L.push_back(pnts[0][0][i][2]); L.push_back(pnts[0][0][i+1][2]); + for(int i = 0; i < getNbW() - 1; ++i) { + L.push_back(pnts[0][0][i][0]); + L.push_back(pnts[0][0][i + 1][0]); + L.push_back(pnts[0][0][i][1]); + L.push_back(pnts[0][0][i + 1][1]); + L.push_back(pnts[0][0][i][2]); + L.push_back(pnts[0][0][i + 1][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][0][i ][nbcomp*k+l]); + L.push_back(vals[0][0][i][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][0][i+1][nbcomp*k+l]); + L.push_back(vals[0][0][i + 1][nbcomp * k + l]); } - L.push_back(pnts[getNbU()-1][0][i][0]); L.push_back(pnts[getNbU()-1][0][i+1][0]); - L.push_back(pnts[getNbU()-1][0][i][1]); L.push_back(pnts[getNbU()-1][0][i+1][1]); - L.push_back(pnts[getNbU()-1][0][i][2]); L.push_back(pnts[getNbU()-1][0][i+1][2]); + L.push_back(pnts[getNbU() - 1][0][i][0]); + L.push_back(pnts[getNbU() - 1][0][i + 1][0]); + L.push_back(pnts[getNbU() - 1][0][i][1]); + L.push_back(pnts[getNbU() - 1][0][i + 1][1]); + L.push_back(pnts[getNbU() - 1][0][i][2]); + L.push_back(pnts[getNbU() - 1][0][i + 1][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[getNbU()-1][0][i ][nbcomp*k+l]); + L.push_back(vals[getNbU() - 1][0][i][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[getNbU()-1][0][i+1][nbcomp*k+l]); + L.push_back(vals[getNbU() - 1][0][i + 1][nbcomp * k + l]); } } } } - else if(getNbW() == 1){ + else if(getNbW() == 1) { if(!boundary) - for(int i = 0; i < getNbU()-1; ++i){ - for(int j = 0; j < getNbV()-1; ++j){ - Q.push_back(pnts[i ][j ][0][0]); Q.push_back(pnts[i+1][j ][0][0]); - Q.push_back(pnts[i+1][j+1][0][0]); Q.push_back(pnts[i ][j+1][0][0]); - Q.push_back(pnts[i ][j ][0][1]); Q.push_back(pnts[i+1][j ][0][1]); - Q.push_back(pnts[i+1][j+1][0][1]); Q.push_back(pnts[i ][j+1][0][1]); - Q.push_back(pnts[i ][j ][0][2]); Q.push_back(pnts[i+1][j ][0][2]); - Q.push_back(pnts[i+1][j+1][0][2]); Q.push_back(pnts[i ][j+1][0][2]); + for(int i = 0; i < getNbU() - 1; ++i) { + for(int j = 0; j < getNbV() - 1; ++j) { + Q.push_back(pnts[i][j][0][0]); + Q.push_back(pnts[i + 1][j][0][0]); + Q.push_back(pnts[i + 1][j + 1][0][0]); + Q.push_back(pnts[i][j + 1][0][0]); + Q.push_back(pnts[i][j][0][1]); + Q.push_back(pnts[i + 1][j][0][1]); + Q.push_back(pnts[i + 1][j + 1][0][1]); + Q.push_back(pnts[i][j + 1][0][1]); + Q.push_back(pnts[i][j][0][2]); + Q.push_back(pnts[i + 1][j][0][2]); + Q.push_back(pnts[i + 1][j + 1][0][2]); + Q.push_back(pnts[i][j + 1][0][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][j ][0][nbcomp*k+l]); + Q.push_back(vals[i][j][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][j ][0][nbcomp*k+l]); + Q.push_back(vals[i + 1][j][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][j+1][0][nbcomp*k+l]); + Q.push_back(vals[i + 1][j + 1][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][j+1][0][nbcomp*k+l]); + Q.push_back(vals[i][j + 1][0][nbcomp * k + l]); } } } - else{ - for(int i = 0; i < getNbU()-1; ++i){ - L.push_back(pnts[i][0][0][0]); L.push_back(pnts[i+1][0][0][0]); - L.push_back(pnts[i][0][0][1]); L.push_back(pnts[i+1][0][0][1]); - L.push_back(pnts[i][0][0][2]); L.push_back(pnts[i+1][0][0][2]); + else { + for(int i = 0; i < getNbU() - 1; ++i) { + L.push_back(pnts[i][0][0][0]); + L.push_back(pnts[i + 1][0][0][0]); + L.push_back(pnts[i][0][0][1]); + L.push_back(pnts[i + 1][0][0][1]); + L.push_back(pnts[i][0][0][2]); + L.push_back(pnts[i + 1][0][0][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i ][0][0][nbcomp*k+l]); + L.push_back(vals[i][0][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i+1][0][0][nbcomp*k+l]); + L.push_back(vals[i + 1][0][0][nbcomp * k + l]); } - L.push_back(pnts[i][getNbV()-1][0][0]); L.push_back(pnts[i+1][getNbV()-1][0][0]); - L.push_back(pnts[i][getNbV()-1][0][1]); L.push_back(pnts[i+1][getNbV()-1][0][1]); - L.push_back(pnts[i][getNbV()-1][0][2]); L.push_back(pnts[i+1][getNbV()-1][0][2]); + L.push_back(pnts[i][getNbV() - 1][0][0]); + L.push_back(pnts[i + 1][getNbV() - 1][0][0]); + L.push_back(pnts[i][getNbV() - 1][0][1]); + L.push_back(pnts[i + 1][getNbV() - 1][0][1]); + L.push_back(pnts[i][getNbV() - 1][0][2]); + L.push_back(pnts[i + 1][getNbV() - 1][0][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i ][getNbV()-1][0][nbcomp*k+l]); + L.push_back(vals[i][getNbV() - 1][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i+1][getNbV()-1][0][nbcomp*k+l]); + L.push_back(vals[i + 1][getNbV() - 1][0][nbcomp * k + l]); } } - for(int i = 0; i < getNbV()-1; ++i){ - L.push_back(pnts[0][i][0][0]); L.push_back(pnts[0][i+1][0][0]); - L.push_back(pnts[0][i][0][1]); L.push_back(pnts[0][i+1][0][1]); - L.push_back(pnts[0][i][0][2]); L.push_back(pnts[0][i+1][0][2]); + for(int i = 0; i < getNbV() - 1; ++i) { + L.push_back(pnts[0][i][0][0]); + L.push_back(pnts[0][i + 1][0][0]); + L.push_back(pnts[0][i][0][1]); + L.push_back(pnts[0][i + 1][0][1]); + L.push_back(pnts[0][i][0][2]); + L.push_back(pnts[0][i + 1][0][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i ][0][nbcomp*k+l]); + L.push_back(vals[0][i][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i+1][0][nbcomp*k+l]); + L.push_back(vals[0][i + 1][0][nbcomp * k + l]); } - L.push_back(pnts[getNbU()-1][i][0][0]); L.push_back(pnts[getNbU()-1][i+1][0][0]); - L.push_back(pnts[getNbU()-1][i][0][1]); L.push_back(pnts[getNbU()-1][i+1][0][1]); - L.push_back(pnts[getNbU()-1][i][0][2]); L.push_back(pnts[getNbU()-1][i+1][0][2]); + L.push_back(pnts[getNbU() - 1][i][0][0]); + L.push_back(pnts[getNbU() - 1][i + 1][0][0]); + L.push_back(pnts[getNbU() - 1][i][0][1]); + L.push_back(pnts[getNbU() - 1][i + 1][0][1]); + L.push_back(pnts[getNbU() - 1][i][0][2]); + L.push_back(pnts[getNbU() - 1][i + 1][0][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[getNbU()-1][i ][0][nbcomp*k+l]); + L.push_back(vals[getNbU() - 1][i][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[getNbU()-1][i+1][0][nbcomp*k+l]); + L.push_back(vals[getNbU() - 1][i + 1][0][nbcomp * k + l]); } } } } // from here, general case - else{ - if (!boundary){ //Hexaedra in the box - for(int i = 0; i < getNbU()-1; ++i){ - for(int j = 0; j < getNbV()-1; ++j){ - for(int m = 0; m < getNbW()-1; ++m){ - H.push_back(pnts[i ][j ][m ][0]); H.push_back(pnts[i+1][j ][m ][0]); - H.push_back(pnts[i+1][j+1][m ][0]); H.push_back(pnts[i ][j+1][m ][0]); - H.push_back(pnts[i ][j ][m+1][0]); H.push_back(pnts[i+1][j ][m+1][0]); - H.push_back(pnts[i+1][j+1][m+1][0]); H.push_back(pnts[i ][j+1][m+1][0]); - - H.push_back(pnts[i ][j ][m ][1]); H.push_back(pnts[i+1][j ][m ][1]); - H.push_back(pnts[i+1][j+1][m ][1]); H.push_back(pnts[i ][j+1][m ][1]); - H.push_back(pnts[i ][j ][m+1][1]); H.push_back(pnts[i+1][j ][m+1][1]); - H.push_back(pnts[i+1][j+1][m+1][1]); H.push_back(pnts[i ][j+1][m+1][1]); - - H.push_back(pnts[i ][j ][m ][2]); H.push_back(pnts[i+1][j ][m ][2]); - H.push_back(pnts[i+1][j+1][m ][2]); H.push_back(pnts[i ][j+1][m ][2]); - H.push_back(pnts[i ][j ][m+1][2]); H.push_back(pnts[i+1][j ][m+1][2]); - H.push_back(pnts[i+1][j+1][m+1][2]); H.push_back(pnts[i ][j+1][m+1][2]); + else { + if(!boundary) { // Hexaedra in the box + for(int i = 0; i < getNbU() - 1; ++i) { + for(int j = 0; j < getNbV() - 1; ++j) { + for(int m = 0; m < getNbW() - 1; ++m) { + H.push_back(pnts[i][j][m][0]); + H.push_back(pnts[i + 1][j][m][0]); + H.push_back(pnts[i + 1][j + 1][m][0]); + H.push_back(pnts[i][j + 1][m][0]); + H.push_back(pnts[i][j][m + 1][0]); + H.push_back(pnts[i + 1][j][m + 1][0]); + H.push_back(pnts[i + 1][j + 1][m + 1][0]); + H.push_back(pnts[i][j + 1][m + 1][0]); + + H.push_back(pnts[i][j][m][1]); + H.push_back(pnts[i + 1][j][m][1]); + H.push_back(pnts[i + 1][j + 1][m][1]); + H.push_back(pnts[i][j + 1][m][1]); + H.push_back(pnts[i][j][m + 1][1]); + H.push_back(pnts[i + 1][j][m + 1][1]); + H.push_back(pnts[i + 1][j + 1][m + 1][1]); + H.push_back(pnts[i][j + 1][m + 1][1]); + + H.push_back(pnts[i][j][m][2]); + H.push_back(pnts[i + 1][j][m][2]); + H.push_back(pnts[i + 1][j + 1][m][2]); + H.push_back(pnts[i][j + 1][m][2]); + H.push_back(pnts[i][j][m + 1][2]); + H.push_back(pnts[i + 1][j][m + 1][2]); + H.push_back(pnts[i + 1][j + 1][m + 1][2]); + H.push_back(pnts[i][j + 1][m + 1][2]); (*nH)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - H.push_back(vals[i ][j ][m ][nbcomp*k+l]); + H.push_back(vals[i][j][m][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - H.push_back(vals[i+1][j ][m ][nbcomp*k+l]); + H.push_back(vals[i + 1][j][m][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - H.push_back(vals[i+1][j+1][m ][nbcomp*k+l]); + H.push_back(vals[i + 1][j + 1][m][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - H.push_back(vals[i ][j+1][m ][nbcomp*k+l]); + H.push_back(vals[i][j + 1][m][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - H.push_back(vals[i ][j ][m+1][nbcomp*k+l]); + H.push_back(vals[i][j][m + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - H.push_back(vals[i+1][j ][m+1][nbcomp*k+l]); + H.push_back(vals[i + 1][j][m + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - H.push_back(vals[i+1][j+1][m+1][nbcomp*k+l]); + H.push_back(vals[i + 1][j + 1][m + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - H.push_back(vals[i ][j+1][m+1][nbcomp*k+l]); + H.push_back(vals[i][j + 1][m + 1][nbcomp * k + l]); } } } } } - else{//Quadrangles at boundary of the box + forcing exterior normals - for(int i = 0; i < getNbU()-1; ++i){ - for(int j = 0; j < getNbV()-1; ++j){ - Q.push_back(pnts[i ][j ][0][0]); Q.push_back(pnts[i ][j+1][0][0]); - Q.push_back(pnts[i+1][j+1][0][0]); Q.push_back(pnts[i+1][j ][0][0]); - Q.push_back(pnts[i ][j ][0][1]); Q.push_back(pnts[i ][j+1][0][1]); - Q.push_back(pnts[i+1][j+1][0][1]); Q.push_back(pnts[i+1][j ][0][1]); - Q.push_back(pnts[i ][j ][0][2]); Q.push_back(pnts[i ][j+1][0][2]); - Q.push_back(pnts[i+1][j+1][0][2]); Q.push_back(pnts[i+1][j ][0][2]); + else { // Quadrangles at boundary of the box + forcing exterior normals + for(int i = 0; i < getNbU() - 1; ++i) { + for(int j = 0; j < getNbV() - 1; ++j) { + Q.push_back(pnts[i][j][0][0]); + Q.push_back(pnts[i][j + 1][0][0]); + Q.push_back(pnts[i + 1][j + 1][0][0]); + Q.push_back(pnts[i + 1][j][0][0]); + Q.push_back(pnts[i][j][0][1]); + Q.push_back(pnts[i][j + 1][0][1]); + Q.push_back(pnts[i + 1][j + 1][0][1]); + Q.push_back(pnts[i + 1][j][0][1]); + Q.push_back(pnts[i][j][0][2]); + Q.push_back(pnts[i][j + 1][0][2]); + Q.push_back(pnts[i + 1][j + 1][0][2]); + Q.push_back(pnts[i + 1][j][0][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][j ][0][nbcomp*k+l]); + Q.push_back(vals[i][j][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][j+1][0][nbcomp*k+l]); + Q.push_back(vals[i][j + 1][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][j+1][0][nbcomp*k+l]); + Q.push_back(vals[i + 1][j + 1][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][j ][0][nbcomp*k+l]); + Q.push_back(vals[i + 1][j][0][nbcomp * k + l]); } - Q.push_back(pnts[i ][j ][getNbW()-1][0]); Q.push_back(pnts[i+1][j ][getNbW()-1][0]); - Q.push_back(pnts[i+1][j+1][getNbW()-1][0]); Q.push_back(pnts[i ][j+1][getNbW()-1][0]); - Q.push_back(pnts[i ][j ][getNbW()-1][1]); Q.push_back(pnts[i+1][j ][getNbW()-1][1]); - Q.push_back(pnts[i+1][j+1][getNbW()-1][1]); Q.push_back(pnts[i ][j+1][getNbW()-1][1]); - Q.push_back(pnts[i ][j ][getNbW()-1][2]); Q.push_back(pnts[i+1][j ][getNbW()-1][2]); - Q.push_back(pnts[i+1][j+1][getNbW()-1][2]); Q.push_back(pnts[i ][j+1][getNbW()-1][2]); + Q.push_back(pnts[i][j][getNbW() - 1][0]); + Q.push_back(pnts[i + 1][j][getNbW() - 1][0]); + Q.push_back(pnts[i + 1][j + 1][getNbW() - 1][0]); + Q.push_back(pnts[i][j + 1][getNbW() - 1][0]); + Q.push_back(pnts[i][j][getNbW() - 1][1]); + Q.push_back(pnts[i + 1][j][getNbW() - 1][1]); + Q.push_back(pnts[i + 1][j + 1][getNbW() - 1][1]); + Q.push_back(pnts[i][j + 1][getNbW() - 1][1]); + Q.push_back(pnts[i][j][getNbW() - 1][2]); + Q.push_back(pnts[i + 1][j][getNbW() - 1][2]); + Q.push_back(pnts[i + 1][j + 1][getNbW() - 1][2]); + Q.push_back(pnts[i][j + 1][getNbW() - 1][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][j ][getNbW()-1][nbcomp*k+l]); + Q.push_back(vals[i][j][getNbW() - 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][j ][getNbW()-1][nbcomp*k+l]); + Q.push_back(vals[i + 1][j][getNbW() - 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][j+1][getNbW()-1][nbcomp*k+l]); + Q.push_back(vals[i + 1][j + 1][getNbW() - 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][j+1][getNbW()-1][nbcomp*k+l]); + Q.push_back(vals[i][j + 1][getNbW() - 1][nbcomp * k + l]); } } } - for(int i = 0; i < getNbU()-1; ++i){ - for(int j = 0; j < getNbW()-1; ++j){ - Q.push_back(pnts[i ][0][j ][0]); Q.push_back(pnts[i+1][0][j ][0]); - Q.push_back(pnts[i+1][0][j+1][0]); Q.push_back(pnts[i ][0][j+1][0]); - Q.push_back(pnts[i ][0][j ][1]); Q.push_back(pnts[i+1][0][j ][1]); - Q.push_back(pnts[i+1][0][j+1][1]); Q.push_back(pnts[i ][0][j+1][1]); - Q.push_back(pnts[i ][0][j ][2]); Q.push_back(pnts[i+1][0][j ][2]); - Q.push_back(pnts[i+1][0][j+1][2]); Q.push_back(pnts[i ][0][j+1][2]); + for(int i = 0; i < getNbU() - 1; ++i) { + for(int j = 0; j < getNbW() - 1; ++j) { + Q.push_back(pnts[i][0][j][0]); + Q.push_back(pnts[i + 1][0][j][0]); + Q.push_back(pnts[i + 1][0][j + 1][0]); + Q.push_back(pnts[i][0][j + 1][0]); + Q.push_back(pnts[i][0][j][1]); + Q.push_back(pnts[i + 1][0][j][1]); + Q.push_back(pnts[i + 1][0][j + 1][1]); + Q.push_back(pnts[i][0][j + 1][1]); + Q.push_back(pnts[i][0][j][2]); + Q.push_back(pnts[i + 1][0][j][2]); + Q.push_back(pnts[i + 1][0][j + 1][2]); + Q.push_back(pnts[i][0][j + 1][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][0][j ][nbcomp*k+l]); + Q.push_back(vals[i][0][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][0][j ][nbcomp*k+l]); + Q.push_back(vals[i + 1][0][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][0][j+1][nbcomp*k+l]); + Q.push_back(vals[i + 1][0][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][0][j+1][nbcomp*k+l]); + Q.push_back(vals[i][0][j + 1][nbcomp * k + l]); } - Q.push_back(pnts[i ][getNbV()-1][j ][0]); Q.push_back(pnts[i ][getNbV()-1][j+1][0]); - Q.push_back(pnts[i+1][getNbV()-1][j+1][0]); Q.push_back(pnts[i+1][getNbV()-1][j ][0]); - Q.push_back(pnts[i ][getNbV()-1][j ][1]); Q.push_back(pnts[i ][getNbV()-1][j+1][1]); - Q.push_back(pnts[i+1][getNbV()-1][j+1][1]); Q.push_back(pnts[i+1][getNbV()-1][j ][1]); - Q.push_back(pnts[i ][getNbV()-1][j ][2]); Q.push_back(pnts[i ][getNbV()-1][j+1][2]); - Q.push_back(pnts[i+1][getNbV()-1][j+1][2]); Q.push_back(pnts[i+1][getNbV()-1][j ][2]); + Q.push_back(pnts[i][getNbV() - 1][j][0]); + Q.push_back(pnts[i][getNbV() - 1][j + 1][0]); + Q.push_back(pnts[i + 1][getNbV() - 1][j + 1][0]); + Q.push_back(pnts[i + 1][getNbV() - 1][j][0]); + Q.push_back(pnts[i][getNbV() - 1][j][1]); + Q.push_back(pnts[i][getNbV() - 1][j + 1][1]); + Q.push_back(pnts[i + 1][getNbV() - 1][j + 1][1]); + Q.push_back(pnts[i + 1][getNbV() - 1][j][1]); + Q.push_back(pnts[i][getNbV() - 1][j][2]); + Q.push_back(pnts[i][getNbV() - 1][j + 1][2]); + Q.push_back(pnts[i + 1][getNbV() - 1][j + 1][2]); + Q.push_back(pnts[i + 1][getNbV() - 1][j][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][getNbV()-1][j ][nbcomp*k+l]); + Q.push_back(vals[i][getNbV() - 1][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][getNbV()-1][j+1][nbcomp*k+l]); + Q.push_back(vals[i][getNbV() - 1][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][getNbV()-1][j+1][nbcomp*k+l]); + Q.push_back(vals[i + 1][getNbV() - 1][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][getNbV()-1][j ][nbcomp*k+l]); + Q.push_back(vals[i + 1][getNbV() - 1][j][nbcomp * k + l]); } } } - for(int i = 0; i < getNbV()-1; ++i){ - for(int j = 0; j < getNbW()-1; ++j){ - Q.push_back(pnts[0][i ][j ][0]); Q.push_back(pnts[0][i ][j+1][0]); - Q.push_back(pnts[0][i+1][j+1][0]); Q.push_back(pnts[0][i+1][j ][0]); - Q.push_back(pnts[0][i ][j ][1]); Q.push_back(pnts[0][i ][j+1][1]); - Q.push_back(pnts[0][i+1][j+1][1]); Q.push_back(pnts[0][i+1][j ][1]); - Q.push_back(pnts[0][i ][j ][2]); Q.push_back(pnts[0][i ][j+1][2]); - Q.push_back(pnts[0][i+1][j+1][2]); Q.push_back(pnts[0][i+1][j ][2]); + for(int i = 0; i < getNbV() - 1; ++i) { + for(int j = 0; j < getNbW() - 1; ++j) { + Q.push_back(pnts[0][i][j][0]); + Q.push_back(pnts[0][i][j + 1][0]); + Q.push_back(pnts[0][i + 1][j + 1][0]); + Q.push_back(pnts[0][i + 1][j][0]); + Q.push_back(pnts[0][i][j][1]); + Q.push_back(pnts[0][i][j + 1][1]); + Q.push_back(pnts[0][i + 1][j + 1][1]); + Q.push_back(pnts[0][i + 1][j][1]); + Q.push_back(pnts[0][i][j][2]); + Q.push_back(pnts[0][i][j + 1][2]); + Q.push_back(pnts[0][i + 1][j + 1][2]); + Q.push_back(pnts[0][i + 1][j][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[0][i ][j ][nbcomp*k+l]); + Q.push_back(vals[0][i][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[0][i ][j+1][nbcomp*k+l]); + Q.push_back(vals[0][i][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[0][i+1][j+1][nbcomp*k+l]); + Q.push_back(vals[0][i + 1][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[0][i+1][j ][nbcomp*k+l]); + Q.push_back(vals[0][i + 1][j][nbcomp * k + l]); } - Q.push_back(pnts[getNbU()-1][i ][j ][0]); Q.push_back(pnts[getNbU()-1][i+1][j ][0]); - Q.push_back(pnts[getNbU()-1][i+1][j+1][0]); Q.push_back(pnts[getNbU()-1][i ][j+1][0]); - Q.push_back(pnts[getNbU()-1][i ][j ][1]); Q.push_back(pnts[getNbU()-1][i+1][j ][1]); - Q.push_back(pnts[getNbU()-1][i+1][j+1][1]); Q.push_back(pnts[getNbU()-1][i ][j+1][1]); - Q.push_back(pnts[getNbU()-1][i ][j ][2]); Q.push_back(pnts[getNbU()-1][i+1][j ][2]); - Q.push_back(pnts[getNbU()-1][i+1][j+1][2]); Q.push_back(pnts[getNbU()-1][i ][j+1][2]); + Q.push_back(pnts[getNbU() - 1][i][j][0]); + Q.push_back(pnts[getNbU() - 1][i + 1][j][0]); + Q.push_back(pnts[getNbU() - 1][i + 1][j + 1][0]); + Q.push_back(pnts[getNbU() - 1][i][j + 1][0]); + Q.push_back(pnts[getNbU() - 1][i][j][1]); + Q.push_back(pnts[getNbU() - 1][i + 1][j][1]); + Q.push_back(pnts[getNbU() - 1][i + 1][j + 1][1]); + Q.push_back(pnts[getNbU() - 1][i][j + 1][1]); + Q.push_back(pnts[getNbU() - 1][i][j][2]); + Q.push_back(pnts[getNbU() - 1][i + 1][j][2]); + Q.push_back(pnts[getNbU() - 1][i + 1][j + 1][2]); + Q.push_back(pnts[getNbU() - 1][i][j + 1][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[getNbU()-1][i ][j ][nbcomp*k+l]); + Q.push_back(vals[getNbU() - 1][i][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[getNbU()-1][i+1][j ][nbcomp*k+l]); + Q.push_back(vals[getNbU() - 1][i + 1][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[getNbU()-1][i+1][j+1][nbcomp*k+l]); + Q.push_back(vals[getNbU() - 1][i + 1][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[getNbU()-1][i ][j+1][nbcomp*k+l]); + Q.push_back(vals[getNbU() - 1][i][j + 1][nbcomp * k + l]); } } } @@ -922,8 +1015,7 @@ void GMSH_CutBoxPlugin::addInView( int connect, int boundary, int numsteps, int PView *GMSH_CutBoxPlugin::GenerateView(PView *v1, int connect, int boundary) { - if(getNbU() <= 0 || getNbV() <= 0 || getNbW() <= 0) - return v1; + if(getNbU() <= 0 || getNbV() <= 0 || getNbW() <= 0) return v1; PViewData *data1 = getPossiblyAdaptiveData(v1); @@ -938,15 +1030,15 @@ PView *GMSH_CutBoxPlugin::GenerateView(PView *v1, int connect, int boundary) int maxcomp = nbt ? 9 : (nbv ? 3 : 1); int numsteps = data1->getNumTimeSteps(); - double ****pnts = new double*** [getNbU()]; - double ****vals = new double*** [getNbU()]; - for(int i = 0; i < getNbU(); i++){ - pnts[i] = new double** [getNbV()]; - vals[i] = new double** [getNbV()]; - for(int j = 0; j < getNbV(); j++){ - pnts[i][j] = new double* [getNbW()]; - vals[i][j] = new double* [getNbW()]; - for(int k = 0; k < getNbW(); k++){ + double ****pnts = new double ***[getNbU()]; + double ****vals = new double ***[getNbU()]; + for(int i = 0; i < getNbU(); i++) { + pnts[i] = new double **[getNbV()]; + vals[i] = new double **[getNbV()]; + for(int j = 0; j < getNbV(); j++) { + pnts[i][j] = new double *[getNbW()]; + vals[i][j] = new double *[getNbW()]; + for(int k = 0; k < getNbW(); k++) { pnts[i][j][k] = new double[3]; vals[i][j][k] = new double[maxcomp * numsteps]; getPoint(i, j, k, pnts[i][j][k]); @@ -954,47 +1046,53 @@ PView *GMSH_CutBoxPlugin::GenerateView(PView *v1, int connect, int boundary) } } - if(nbs){ + if(nbs) { for(int i = 0; i < getNbU(); i++) for(int j = 0; j < getNbV(); j++) for(int k = 0; k < getNbW(); k++) - o.searchScalar(pnts[i][j][k][0], pnts[i][j][k][1], pnts[i][j][k][2], vals[i][j][k]); - addInView(connect, boundary, numsteps, 1, pnts, vals, data2->SP, &data2->NbSP, - data2->SL, &data2->NbSL, data2->SQ, &data2->NbSQ, data2->SH, &data2->NbSH); + o.searchScalar(pnts[i][j][k][0], pnts[i][j][k][1], pnts[i][j][k][2], + vals[i][j][k]); + addInView(connect, boundary, numsteps, 1, pnts, vals, data2->SP, + &data2->NbSP, data2->SL, &data2->NbSL, data2->SQ, &data2->NbSQ, + data2->SH, &data2->NbSH); } - if(nbv){ + if(nbv) { for(int i = 0; i < getNbU(); i++) for(int j = 0; j < getNbV(); j++) for(int k = 0; k < getNbW(); k++) - o.searchVector(pnts[i][j][k][0], pnts[i][j][k][1], pnts[i][j][k][2], vals[i][j][k]); - addInView(connect, boundary, numsteps, 3, pnts, vals, data2->VP, &data2->NbVP, - data2->VL, &data2->NbVL, data2->VQ, &data2->NbVQ, data2->VH, &data2->NbVH); + o.searchVector(pnts[i][j][k][0], pnts[i][j][k][1], pnts[i][j][k][2], + vals[i][j][k]); + addInView(connect, boundary, numsteps, 3, pnts, vals, data2->VP, + &data2->NbVP, data2->VL, &data2->NbVL, data2->VQ, &data2->NbVQ, + data2->VH, &data2->NbVH); } - if(nbt){ + if(nbt) { for(int i = 0; i < getNbU(); i++) for(int j = 0; j < getNbV(); j++) for(int k = 0; k < getNbW(); k++) - o.searchTensor(pnts[i][j][k][0], pnts[i][j][k][1], pnts[i][j][k][2], vals[i][j][k]); - addInView(connect, boundary, numsteps, 9, pnts, vals, data2->TP, &data2->NbTP, - data2->TL, &data2->NbTL, data2->TQ, &data2->NbTQ, data2->TH, &data2->NbTH); + o.searchTensor(pnts[i][j][k][0], pnts[i][j][k][1], pnts[i][j][k][2], + vals[i][j][k]); + addInView(connect, boundary, numsteps, 9, pnts, vals, data2->TP, + &data2->NbTP, data2->TL, &data2->NbTL, data2->TQ, &data2->NbTQ, + data2->TH, &data2->NbTH); } - for(int i = 0; i < getNbU(); i++){ - for(int j = 0; j < getNbV(); j++){ - for(int k = 0; k < getNbW(); k++){ - delete [] pnts[i][j][k]; - delete [] vals[i][j][k]; + for(int i = 0; i < getNbU(); i++) { + for(int j = 0; j < getNbV(); j++) { + for(int k = 0; k < getNbW(); k++) { + delete[] pnts[i][j][k]; + delete[] vals[i][j][k]; } - delete [] pnts[i][j]; - delete [] vals[i][j]; + delete[] pnts[i][j]; + delete[] vals[i][j]; } - delete [] pnts[i]; - delete [] vals[i]; + delete[] pnts[i]; + delete[] vals[i]; } - delete [] pnts; - delete [] vals; + delete[] pnts; + delete[] vals; data2->setName(data1->getName() + "_CutBox"); data2->setFileName(data1->getName() + "_CutBox.pos"); diff --git a/Plugin/CutBox.h b/Plugin/CutBox.h index ef465ace7ddb33fbdae53526dceab0c252c97ddb..50dc551adaaed91402524bea74d1c4ef9f6f53b7 100644 --- a/Plugin/CutBox.h +++ b/Plugin/CutBox.h @@ -8,24 +8,22 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutBoxPlugin (); +extern "C" { +GMSH_Plugin *GMSH_RegisterCutBoxPlugin(); } -class GMSH_CutBoxPlugin : public GMSH_PostPlugin -{ +class GMSH_CutBoxPlugin : public GMSH_PostPlugin { static double callback(int num, int action, double value, double *opt, double step, double min, double max); - void addInView(int connect, int boundary, int numsteps, int nbcomp, - double ****pnts, double ****vals, - std::vector<double> &P, int *nP, - std::vector<double> &L, int *nL, - std::vector<double> &Q, int *nQ, - std::vector<double> &H, int *nH); - PView *GenerateView (PView *v, int connectPoints, int boundary); - public: - GMSH_CutBoxPlugin(){} + void addInView(int connect, int boundary, int numsteps, int nbcomp, + double ****pnts, double ****vals, std::vector<double> &P, + int *nP, std::vector<double> &L, int *nL, + std::vector<double> &Q, int *nQ, std::vector<double> &H, + int *nH); + PView *GenerateView(PView *v, int connectPoints, int boundary); + +public: + GMSH_CutBoxPlugin() {} std::string getName() const { return "CutBox"; } std::string getShortHelp() const { @@ -33,13 +31,13 @@ class GMSH_CutBoxPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); - static int getNbU (); - static int getNbV (); - static int getNbW (); - static void getPoint(int iU, int iV, int iW, double *X ); + static int getNbU(); + static int getNbV(); + static int getNbW(); + static void getPoint(int iU, int iV, int iW, double *X); static double callbackX0(int, int, double); static double callbackY0(int, int, double); diff --git a/Plugin/CutGrid.cpp b/Plugin/CutGrid.cpp index 300574f6808c1e3ca4a1aa6126a3f94e5b23623c..8e3e77a5498d969f0ac78b1c8569c102d61a97e2 100644 --- a/Plugin/CutGrid.cpp +++ b/Plugin/CutGrid.cpp @@ -25,54 +25,49 @@ StringXNumber CutGridOptions_Number[] = { {GMSH_FULLRC, "NumPointsU", GMSH_CutGridPlugin::callbackU, 20}, {GMSH_FULLRC, "NumPointsV", GMSH_CutGridPlugin::callbackV, 20}, {GMSH_FULLRC, "ConnectPoints", GMSH_CutGridPlugin::callbackConnect, 1}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutGridPlugin() - { - return new GMSH_CutGridPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterCutGridPlugin() { return new GMSH_CutGridPlugin(); } } void GMSH_CutGridPlugin::draw(void *context) { #if defined(HAVE_OPENGL) - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); double p[3]; - drawContext *ctx = (drawContext*)context; + drawContext *ctx = (drawContext *)context; getPoint(0, 0, p); ctx->drawString("(X0, Y0, Z0)", p[0], p[1], p[2]); - if(getNbU() > 1){ + if(getNbU() > 1) { getPoint(getNbU() - 1, 0, p); ctx->drawString("(X1, Y1, Z1)", p[0], p[1], p[2]); } - if(getNbV() > 1){ + if(getNbV() > 1) { getPoint(0, getNbV() - 1, p); ctx->drawString("(X2, Y2, Z2)", p[0], p[1], p[2]); } - if(CutGridOptions_Number[11].def){ + if(CutGridOptions_Number[11].def) { glBegin(GL_LINES); - for(int i = 0; i < getNbU(); ++i){ + for(int i = 0; i < getNbU(); ++i) { getPoint(i, 0, p); glVertex3d(p[0], p[1], p[2]); - getPoint(i, getNbV()-1, p); + getPoint(i, getNbV() - 1, p); glVertex3d(p[0], p[1], p[2]); } - for(int i = 0; i < getNbV(); ++i){ + for(int i = 0; i < getNbV(); ++i) { getPoint(0, i, p); glVertex3d(p[0], p[1], p[2]); - getPoint(getNbU()-1, i, p); + getPoint(getNbU() - 1, i, p); glVertex3d(p[0], p[1], p[2]); } glEnd(); } - else{ - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ + else { + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { getPoint(i, j, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); } @@ -81,10 +76,11 @@ void GMSH_CutGridPlugin::draw(void *context) #endif } -double GMSH_CutGridPlugin::callback(int num, int action, double value, double *opt, - double step, double min, double max) +double GMSH_CutGridPlugin::callback(int num, int action, double value, + double *opt, double step, double min, + double max) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return step; case 2: return min; case 3: return max; @@ -160,36 +156,34 @@ double GMSH_CutGridPlugin::callbackZ2(int num, int action, double value) double GMSH_CutGridPlugin::callbackU(int num, int action, double value) { - return callback(num, action, value, &CutGridOptions_Number[9].def, - 1, 1, 200); + return callback(num, action, value, &CutGridOptions_Number[9].def, 1, 1, 200); } double GMSH_CutGridPlugin::callbackV(int num, int action, double value) { - return callback(num, action, value, &CutGridOptions_Number[10].def, - 1, 1, 200); + return callback(num, action, value, &CutGridOptions_Number[10].def, 1, 1, + 200); } double GMSH_CutGridPlugin::callbackConnect(int num, int action, double value) { - return callback(num, action, value, &CutGridOptions_Number[11].def, - 1, 0, 1); + return callback(num, action, value, &CutGridOptions_Number[11].def, 1, 0, 1); } std::string GMSH_CutGridPlugin::getHelp() const { return "Plugin(CutGrid) cuts the view `View' with a " - "rectangular grid defined by the 3 points " - "(`X0',`Y0',`Z0') (origin), (`X1',`Y1',`Z1') (axis of U) " - "and (`X2',`Y2',`Z2') (axis of V).\n\n" - "The number of points along U and V is set with the " - "options `NumPointsU' and `NumPointsV'.\n\n" - "If `ConnectPoints' is zero, the plugin creates points; " - "otherwise, the plugin generates quadrangles, lines or " - "points depending on the values of `NumPointsU' and " - "`NumPointsV'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(CutGrid) creates one new view."; + "rectangular grid defined by the 3 points " + "(`X0',`Y0',`Z0') (origin), (`X1',`Y1',`Z1') (axis of U) " + "and (`X2',`Y2',`Z2') (axis of V).\n\n" + "The number of points along U and V is set with the " + "options `NumPointsU' and `NumPointsV'.\n\n" + "If `ConnectPoints' is zero, the plugin creates points; " + "otherwise, the plugin generates quadrangles, lines or " + "points depending on the values of `NumPointsU' and " + "`NumPointsV'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(CutGrid) creates one new view."; } int GMSH_CutGridPlugin::getNbOptions() const @@ -202,29 +196,23 @@ StringXNumber *GMSH_CutGridPlugin::getOption(int iopt) return &CutGridOptions_Number[iopt]; } -int GMSH_CutGridPlugin::getNbU() -{ - return (int)CutGridOptions_Number[9].def; -} +int GMSH_CutGridPlugin::getNbU() { return (int)CutGridOptions_Number[9].def; } -int GMSH_CutGridPlugin::getNbV() -{ - return (int)CutGridOptions_Number[10].def; -} +int GMSH_CutGridPlugin::getNbV() { return (int)CutGridOptions_Number[10].def; } void GMSH_CutGridPlugin::getPoint(int iU, int iV, double *X) { double u = getNbU() > 1 ? (double)iU / (double)(getNbU() - 1.) : 0.; double v = getNbV() > 1 ? (double)iV / (double)(getNbV() - 1.) : 0.; X[0] = CutGridOptions_Number[0].def + - u * (CutGridOptions_Number[3].def-CutGridOptions_Number[0].def) + - v * (CutGridOptions_Number[6].def-CutGridOptions_Number[0].def); + u * (CutGridOptions_Number[3].def - CutGridOptions_Number[0].def) + + v * (CutGridOptions_Number[6].def - CutGridOptions_Number[0].def); X[1] = CutGridOptions_Number[1].def + - u * (CutGridOptions_Number[4].def-CutGridOptions_Number[1].def) + - v * (CutGridOptions_Number[7].def-CutGridOptions_Number[1].def); + u * (CutGridOptions_Number[4].def - CutGridOptions_Number[1].def) + + v * (CutGridOptions_Number[7].def - CutGridOptions_Number[1].def); X[2] = CutGridOptions_Number[2].def + - u * (CutGridOptions_Number[5].def-CutGridOptions_Number[2].def) + - v * (CutGridOptions_Number[8].def-CutGridOptions_Number[2].def); + u * (CutGridOptions_Number[5].def - CutGridOptions_Number[2].def) + + v * (CutGridOptions_Number[8].def - CutGridOptions_Number[2].def); } void GMSH_CutGridPlugin::addInView(int numsteps, int connect, int nbcomp, @@ -233,71 +221,82 @@ void GMSH_CutGridPlugin::addInView(int numsteps, int connect, int nbcomp, std::vector<double> &L, int *nL, std::vector<double> &Q, int *nQ) { - if(!connect || (getNbU() == 1 && getNbV() == 1)){ // generate points + if(!connect || (getNbU() == 1 && getNbV() == 1)) { // generate points - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { P.push_back(pnts[i][j][0]); P.push_back(pnts[i][j][1]); P.push_back(pnts[i][j][2]); (*nP)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - P.push_back(vals[i][j][nbcomp*k+l]); + P.push_back(vals[i][j][nbcomp * k + l]); } } } - } - else{ // generate lines or quads - - if(getNbU() == 1){ - for(int i = 0; i < getNbV()-1; ++i){ - L.push_back(pnts[0][i][0]); L.push_back(pnts[0][i+1][0]); - L.push_back(pnts[0][i][1]); L.push_back(pnts[0][i+1][1]); - L.push_back(pnts[0][i][2]); L.push_back(pnts[0][i+1][2]); + else { // generate lines or quads + + if(getNbU() == 1) { + for(int i = 0; i < getNbV() - 1; ++i) { + L.push_back(pnts[0][i][0]); + L.push_back(pnts[0][i + 1][0]); + L.push_back(pnts[0][i][1]); + L.push_back(pnts[0][i + 1][1]); + L.push_back(pnts[0][i][2]); + L.push_back(pnts[0][i + 1][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i ][nbcomp*k+l]); + L.push_back(vals[0][i][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[0][i+1][nbcomp*k+l]); + L.push_back(vals[0][i + 1][nbcomp * k + l]); } } } - else if(getNbV() == 1){ - for(int i = 0; i < getNbU()-1; ++i){ - L.push_back(pnts[i][0][0]); L.push_back(pnts[i+1][0][0]); - L.push_back(pnts[i][0][1]); L.push_back(pnts[i+1][0][1]); - L.push_back(pnts[i][0][2]); L.push_back(pnts[i+1][0][2]); + else if(getNbV() == 1) { + for(int i = 0; i < getNbU() - 1; ++i) { + L.push_back(pnts[i][0][0]); + L.push_back(pnts[i + 1][0][0]); + L.push_back(pnts[i][0][1]); + L.push_back(pnts[i + 1][0][1]); + L.push_back(pnts[i][0][2]); + L.push_back(pnts[i + 1][0][2]); (*nL)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i ][0][nbcomp*k+l]); + L.push_back(vals[i][0][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - L.push_back(vals[i+1][0][nbcomp*k+l]); + L.push_back(vals[i + 1][0][nbcomp * k + l]); } } } - else{ - for(int i = 0; i < getNbU()-1; ++i){ - for(int j = 0; j < getNbV()-1; ++j){ - Q.push_back(pnts[i ][j ][0]); Q.push_back(pnts[i+1][j ][0]); - Q.push_back(pnts[i+1][j+1][0]); Q.push_back(pnts[i ][j+1][0]); - Q.push_back(pnts[i ][j ][1]); Q.push_back(pnts[i+1][j ][1]); - Q.push_back(pnts[i+1][j+1][1]); Q.push_back(pnts[i ][j+1][1]); - Q.push_back(pnts[i ][j ][2]); Q.push_back(pnts[i+1][j ][2]); - Q.push_back(pnts[i+1][j+1][2]); Q.push_back(pnts[i ][j+1][2]); + else { + for(int i = 0; i < getNbU() - 1; ++i) { + for(int j = 0; j < getNbV() - 1; ++j) { + Q.push_back(pnts[i][j][0]); + Q.push_back(pnts[i + 1][j][0]); + Q.push_back(pnts[i + 1][j + 1][0]); + Q.push_back(pnts[i][j + 1][0]); + Q.push_back(pnts[i][j][1]); + Q.push_back(pnts[i + 1][j][1]); + Q.push_back(pnts[i + 1][j + 1][1]); + Q.push_back(pnts[i][j + 1][1]); + Q.push_back(pnts[i][j][2]); + Q.push_back(pnts[i + 1][j][2]); + Q.push_back(pnts[i + 1][j + 1][2]); + Q.push_back(pnts[i][j + 1][2]); (*nQ)++; - for(int k = 0; k < numsteps; ++k){ + for(int k = 0; k < numsteps; ++k) { for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][j ][nbcomp*k+l]); + Q.push_back(vals[i][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][j ][nbcomp*k+l]); + Q.push_back(vals[i + 1][j][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i+1][j+1][nbcomp*k+l]); + Q.push_back(vals[i + 1][j + 1][nbcomp * k + l]); for(int l = 0; l < nbcomp; ++l) - Q.push_back(vals[i ][j+1][nbcomp*k+l]); + Q.push_back(vals[i][j + 1][nbcomp * k + l]); } } } @@ -307,8 +306,7 @@ void GMSH_CutGridPlugin::addInView(int numsteps, int connect, int nbcomp, PView *GMSH_CutGridPlugin::GenerateView(PView *v1, int connect) { - if(getNbU() <= 0 || getNbV() <= 0) - return v1; + if(getNbU() <= 0 || getNbV() <= 0) return v1; PViewData *data1 = getPossiblyAdaptiveData(v1); @@ -323,19 +321,19 @@ PView *GMSH_CutGridPlugin::GenerateView(PView *v1, int connect) int maxcomp = nbt ? 9 : (nbv ? 3 : 1); int numsteps = data1->getNumTimeSteps(); - double ***pnts = new double** [getNbU()]; - double ***vals = new double** [getNbU()]; - for(int i = 0; i < getNbU(); i++){ - pnts[i] = new double* [getNbV()]; - vals[i] = new double* [getNbV()]; - for(int j = 0; j < getNbV(); j++){ + double ***pnts = new double **[getNbU()]; + double ***vals = new double **[getNbU()]; + for(int i = 0; i < getNbU(); i++) { + pnts[i] = new double *[getNbV()]; + vals[i] = new double *[getNbV()]; + for(int j = 0; j < getNbV(); j++) { pnts[i][j] = new double[3]; vals[i][j] = new double[maxcomp * numsteps]; getPoint(i, j, pnts[i][j]); } } - if(nbs){ + if(nbs) { for(int i = 0; i < getNbU(); i++) for(int j = 0; j < getNbV(); j++) o.searchScalar(pnts[i][j][0], pnts[i][j][1], pnts[i][j][2], vals[i][j]); @@ -343,7 +341,7 @@ PView *GMSH_CutGridPlugin::GenerateView(PView *v1, int connect) data2->SL, &data2->NbSL, data2->SQ, &data2->NbSQ); } - if(nbv){ + if(nbv) { for(int i = 0; i < getNbU(); i++) for(int j = 0; j < getNbV(); j++) o.searchVector(pnts[i][j][0], pnts[i][j][1], pnts[i][j][2], vals[i][j]); @@ -351,7 +349,7 @@ PView *GMSH_CutGridPlugin::GenerateView(PView *v1, int connect) data2->VL, &data2->NbVL, data2->VQ, &data2->NbVQ); } - if(nbt){ + if(nbt) { for(int i = 0; i < getNbU(); i++) for(int j = 0; j < getNbV(); j++) o.searchTensor(pnts[i][j][0], pnts[i][j][1], pnts[i][j][2], vals[i][j]); @@ -359,16 +357,16 @@ PView *GMSH_CutGridPlugin::GenerateView(PView *v1, int connect) data2->TL, &data2->NbTL, data2->TQ, &data2->NbTQ); } - for(int i = 0; i < getNbU(); i++){ - for(int j = 0; j < getNbV(); j++){ - delete [] pnts[i][j]; - delete [] vals[i][j]; + for(int i = 0; i < getNbU(); i++) { + for(int j = 0; j < getNbV(); j++) { + delete[] pnts[i][j]; + delete[] vals[i][j]; } - delete [] pnts[i]; - delete [] vals[i]; + delete[] pnts[i]; + delete[] vals[i]; } - delete [] pnts; - delete [] vals; + delete[] pnts; + delete[] vals; data2->setName(data1->getName() + "_CutGrid"); data2->setFileName(data1->getName() + "_CutGrid.pos"); diff --git a/Plugin/CutGrid.h b/Plugin/CutGrid.h index 57a511d6d3597324049e68037ddc43a9fb5738f1..e42278c189c1f9b123e171441ba043b354f630d2 100644 --- a/Plugin/CutGrid.h +++ b/Plugin/CutGrid.h @@ -8,23 +8,21 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutGridPlugin (); +extern "C" { +GMSH_Plugin *GMSH_RegisterCutGridPlugin(); } -class GMSH_CutGridPlugin : public GMSH_PostPlugin -{ +class GMSH_CutGridPlugin : public GMSH_PostPlugin { static double callback(int num, int action, double value, double *opt, double step, double min, double max); - void addInView(int numsteps, int connect, int nbcomp, - double ***pnts, double ***vals, - std::vector<double> &P, int *nP, - std::vector<double> &L, int *nL, - std::vector<double> &Q, int *nQ); - PView *GenerateView (PView *v, int connectPoints); - public: - GMSH_CutGridPlugin(){} + void addInView(int numsteps, int connect, int nbcomp, double ***pnts, + double ***vals, std::vector<double> &P, int *nP, + std::vector<double> &L, int *nL, std::vector<double> &Q, + int *nQ); + PView *GenerateView(PView *v, int connectPoints); + +public: + GMSH_CutGridPlugin() {} std::string getName() const { return "CutGrid"; } std::string getShortHelp() const { @@ -32,12 +30,12 @@ class GMSH_CutGridPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); - static int getNbU (); - static int getNbV (); - static void getPoint(int iU, int iV, double *X ); + static int getNbU(); + static int getNbV(); + static void getPoint(int iU, int iV, double *X); static double callbackX0(int, int, double); static double callbackY0(int, int, double); diff --git a/Plugin/CutMesh.cpp b/Plugin/CutMesh.cpp index e5da525c359793dcd9dd0a06905beab225324197..2dfcd1760b910ab247ccecffaacfb447e186eb02 100644 --- a/Plugin/CutMesh.cpp +++ b/Plugin/CutMesh.cpp @@ -7,30 +7,25 @@ #include "GModel.h" #include "gmshLevelset.h" +StringXNumber CutMeshOptions_Number[] = {{GMSH_FULLRC, "View", NULL, -1.}, + {GMSH_FULLRC, "Split", NULL, 0.}, + {GMSH_FULLRC, "SaveTri", NULL, 0.}}; -StringXNumber CutMeshOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.}, - {GMSH_FULLRC, "Split", NULL, 0.}, - {GMSH_FULLRC, "SaveTri", NULL, 0.} -}; - -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutMeshPlugin() { - return new GMSH_CutMeshPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterCutMeshPlugin() { return new GMSH_CutMeshPlugin(); } } std::string GMSH_CutMeshPlugin::getHelp() const { return "Plugin(CutMesh) cuts the mesh of the current GModel with " - "the zero value of the levelset defined with the view 'View'." - "Sub-elements are created in the new model (polygons in 2D and " - "polyhedra in 3D) and border elements are created on the zero-levelset.\n\n" - "If `Split' is nonzero, the plugin splits the mesh" - "along the edges of the cut elements in the positive side.\n\n" - "If 'SaveTri' is nonzero, the sub-elements are saved as simplices.\n\n" - "Plugin(CutMesh) creates one new GModel."; + "the zero value of the levelset defined with the view 'View'." + "Sub-elements are created in the new model (polygons in 2D and " + "polyhedra in 3D) and border elements are created on the " + "zero-levelset.\n\n" + "If `Split' is nonzero, the plugin splits the mesh" + "along the edges of the cut elements in the positive side.\n\n" + "If 'SaveTri' is nonzero, the sub-elements are saved as simplices.\n\n" + "Plugin(CutMesh) creates one new GModel."; } int GMSH_CutMeshPlugin::getNbOptions() const @@ -46,8 +41,7 @@ StringXNumber *GMSH_CutMeshPlugin::getOption(int iopt) void GMSH_CutMeshPlugin::run() { int iView = (int)CutMeshOptions_Number[0].def; - if(iView < 0) - iView = PView::list.size() - 1; + if(iView < 0) iView = PView::list.size() - 1; gLevelsetPostView *gLs = new gLevelsetPostView(iView); @@ -57,4 +51,3 @@ void GMSH_CutMeshPlugin::run() GModel *cgm = gm->buildCutGModel(gLs, !split, saveTri); cgm->setVisibility(1); } - diff --git a/Plugin/CutMesh.h b/Plugin/CutMesh.h index f217c662149c0b27e0cb8a3a951ea90830bdfebe..5758c6c8fe731bb58f0abd59d6f6af75674e018a 100644 --- a/Plugin/CutMesh.h +++ b/Plugin/CutMesh.h @@ -8,24 +8,19 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutMeshPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterCutMeshPlugin(); } -class GMSH_CutMeshPlugin : public GMSH_MeshPlugin -{ - public: - GMSH_CutMeshPlugin(){} +class GMSH_CutMeshPlugin : public GMSH_MeshPlugin { +public: + GMSH_CutMeshPlugin() {} std::string getName() const { return "CutMesh"; } - std::string getShortHelp() const - { - return "Cut mesh along a levelset"; - } + std::string getShortHelp() const { return "Cut mesh along a levelset"; } std::string getHelp() const; std::string getAuthor() const { return "G. Bricteux"; } int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); void run(); }; diff --git a/Plugin/CutParametric.cpp b/Plugin/CutParametric.cpp index acfeaebb6f13296248a4fb6e6a136cc5bd96f2d6..64d72398b3a15da94f492cfc13e2164859f6799c 100644 --- a/Plugin/CutParametric.cpp +++ b/Plugin/CutParametric.cpp @@ -22,21 +22,21 @@ StringXNumber CutParametricOptions_Number[] = { {GMSH_FULLRC, "MaxV", GMSH_CutParametricPlugin::callbackMaxV, 2 * 3.1416}, {GMSH_FULLRC, "NumPointsV", GMSH_CutParametricPlugin::callbackNV, 180.}, {GMSH_FULLRC, "ConnectPoints", GMSH_CutParametricPlugin::callbackConnect, 0.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; StringXString CutParametricOptions_String[] = { - {GMSH_FULLRC, "X", GMSH_CutParametricPlugin::callbackX, "2 * Cos(u) * Sin(v)"}, - {GMSH_FULLRC, "Y", GMSH_CutParametricPlugin::callbackY, "4 * Sin(u) * Sin(v)"}, - {GMSH_FULLRC, "Z", GMSH_CutParametricPlugin::callbackZ, "0.1 + 0.5 * Cos(v)"} -}; - -extern "C" + {GMSH_FULLRC, "X", GMSH_CutParametricPlugin::callbackX, + "2 * Cos(u) * Sin(v)"}, + {GMSH_FULLRC, "Y", GMSH_CutParametricPlugin::callbackY, + "4 * Sin(u) * Sin(v)"}, + {GMSH_FULLRC, "Z", GMSH_CutParametricPlugin::callbackZ, + "0.1 + 0.5 * Cos(v)"}}; + +extern "C" { +GMSH_Plugin *GMSH_RegisterCutParametricPlugin() { - GMSH_Plugin *GMSH_RegisterCutParametricPlugin() - { - return new GMSH_CutParametricPlugin(); - } + return new GMSH_CutParametricPlugin(); +} } static double getU(int i) @@ -48,7 +48,7 @@ static double getU(int i) if(nbU == 1) return minU; else - return minU + (double)(i)/(double)(nbU-1) * (maxU - minU); + return minU + (double)(i) / (double)(nbU - 1) * (maxU - minU); } static double getV(int i) @@ -60,7 +60,7 @@ static double getV(int i) if(nbV == 1) return minV; else - return minV + (double)(i)/(double)(nbV-1) * (maxV - minV); + return minV + (double)(i) / (double)(nbV - 1) * (maxV - minV); } int GMSH_CutParametricPlugin::recompute = 1; @@ -84,11 +84,11 @@ int GMSH_CutParametricPlugin::fillXYZ() y.resize(nbU * nbV); z.resize(nbU * nbV); std::vector<double> val(2), res(3); - for(int i = 0; i < nbU; ++i){ + for(int i = 0; i < nbU; ++i) { val[0] = getU(i); - for(int j = 0; j < nbV; ++j){ + for(int j = 0; j < nbV; ++j) { val[1] = getV(j); - if(f.eval(val, res)){ + if(f.eval(val, res)) { x[i * nbV + j] = res[0]; y[i * nbV + j] = res[1]; z[i * nbV + j] = res[2]; @@ -101,51 +101,52 @@ int GMSH_CutParametricPlugin::fillXYZ() void GMSH_CutParametricPlugin::draw(void *context) { #if defined(HAVE_OPENGL) - if(recompute){ + if(recompute) { fillXYZ(); recompute = 0; } - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); int nbU = CutParametricOptions_Number[2].def; int nbV = CutParametricOptions_Number[5].def; - if(CutParametricOptions_Number[6].def && x.size() > 1){ - if(nbU == 1 || nbV == 1){ + if(CutParametricOptions_Number[6].def && x.size() > 1) { + if(nbU == 1 || nbV == 1) { glBegin(GL_LINES); - for(unsigned int i = 1; i < x.size(); ++i){ - glVertex3d(x[i-1], y[i-1], z[i-1]); + for(unsigned int i = 1; i < x.size(); ++i) { + glVertex3d(x[i - 1], y[i - 1], z[i - 1]); glVertex3d(x[i], y[i], z[i]); } glEnd(); } - else{ + else { glBegin(GL_TRIANGLES); - for(int i = 0; i < nbU - 1; ++i){ - for(int j = 0; j < nbV - 1; ++j){ + for(int i = 0; i < nbU - 1; ++i) { + for(int j = 0; j < nbV - 1; ++j) { int v = i * nbV + j; glVertex3d(x[v], y[v], z[v]); - glVertex3d(x[v+1], y[v+1], z[v+1]); - glVertex3d(x[v+1+nbV], y[v+1+nbV], z[v+1+nbV]); + glVertex3d(x[v + 1], y[v + 1], z[v + 1]); + glVertex3d(x[v + 1 + nbV], y[v + 1 + nbV], z[v + 1 + nbV]); glVertex3d(x[v], y[v], z[v]); - glVertex3d(x[v+nbV], y[v+nbV], z[v+nbV]); - glVertex3d(x[v+1+nbV], y[v+1+nbV], z[v+1+nbV]); + glVertex3d(x[v + nbV], y[v + nbV], z[v + nbV]); + glVertex3d(x[v + 1 + nbV], y[v + 1 + nbV], z[v + 1 + nbV]); } } glEnd(); } } - else{ - drawContext *ctx = (drawContext*)context; + else { + drawContext *ctx = (drawContext *)context; for(unsigned int i = 0; i < x.size(); ++i) ctx->drawSphere(CTX::instance()->pointSize, x[i], y[i], z[i], 1); } #endif } -double GMSH_CutParametricPlugin::callback(int num, int action, double value, double *opt, - double step, double min, double max) +double GMSH_CutParametricPlugin::callback(int num, int action, double value, + double *opt, double step, double min, + double max) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return step; case 2: return min; case 3: return max; @@ -157,7 +158,8 @@ double GMSH_CutParametricPlugin::callback(int num, int action, double value, dou return 0.; } -std::string GMSH_CutParametricPlugin::callbackStr(int num, int action, std::string value, +std::string GMSH_CutParametricPlugin::callbackStr(int num, int action, + std::string value, std::string &opt) { opt = value; @@ -168,57 +170,61 @@ std::string GMSH_CutParametricPlugin::callbackStr(int num, int action, std::stri double GMSH_CutParametricPlugin::callbackMinU(int num, int action, double value) { - return callback(num, action, value, &CutParametricOptions_Number[0].def, - 0.01, 0., 10.); + return callback(num, action, value, &CutParametricOptions_Number[0].def, 0.01, + 0., 10.); } double GMSH_CutParametricPlugin::callbackMaxU(int num, int action, double value) { - return callback(num, action, value, &CutParametricOptions_Number[1].def, - 0.01, 0., 10.); + return callback(num, action, value, &CutParametricOptions_Number[1].def, 0.01, + 0., 10.); } double GMSH_CutParametricPlugin::callbackNU(int num, int action, double value) { - return callback(num, action, value, &CutParametricOptions_Number[2].def, - 1, 1, 1000); + return callback(num, action, value, &CutParametricOptions_Number[2].def, 1, 1, + 1000); } double GMSH_CutParametricPlugin::callbackMinV(int num, int action, double value) { - return callback(num, action, value, &CutParametricOptions_Number[3].def, - 0.01, 0., 10.); + return callback(num, action, value, &CutParametricOptions_Number[3].def, 0.01, + 0., 10.); } double GMSH_CutParametricPlugin::callbackMaxV(int num, int action, double value) { - return callback(num, action, value, &CutParametricOptions_Number[4].def, - 0.01, 0., 10.); + return callback(num, action, value, &CutParametricOptions_Number[4].def, 0.01, + 0., 10.); } double GMSH_CutParametricPlugin::callbackNV(int num, int action, double value) { - return callback(num, action, value, &CutParametricOptions_Number[5].def, - 1, 1, 1000); + return callback(num, action, value, &CutParametricOptions_Number[5].def, 1, 1, + 1000); } -double GMSH_CutParametricPlugin::callbackConnect(int num, int action, double value) +double GMSH_CutParametricPlugin::callbackConnect(int num, int action, + double value) { - return callback(num, action, value, &CutParametricOptions_Number[6].def, - 1, 0, 1); + return callback(num, action, value, &CutParametricOptions_Number[6].def, 1, 0, + 1); } -std::string GMSH_CutParametricPlugin::callbackX(int num, int action, std::string value) +std::string GMSH_CutParametricPlugin::callbackX(int num, int action, + std::string value) { return callbackStr(num, action, value, CutParametricOptions_String[0].def); } -std::string GMSH_CutParametricPlugin::callbackY(int num, int action, std::string value) +std::string GMSH_CutParametricPlugin::callbackY(int num, int action, + std::string value) { return callbackStr(num, action, value, CutParametricOptions_String[1].def); } -std::string GMSH_CutParametricPlugin::callbackZ(int num, int action, std::string value) +std::string GMSH_CutParametricPlugin::callbackZ(int num, int action, + std::string value) { return callbackStr(num, action, value, CutParametricOptions_String[2].def); } @@ -226,14 +232,14 @@ std::string GMSH_CutParametricPlugin::callbackZ(int num, int action, std::string std::string GMSH_CutParametricPlugin::getHelp() const { return "Plugin(CutParametric) cuts the view `View' with " - "the parametric function (`X'(u,v), `Y'(u,v), `Z'(u,v)), " - "using `NumPointsU' values of the parameter u in " - "[`MinU', `MaxU'] and `NumPointsV' values of the parameter v in " - "[`MinV', `MaxV'].\n\n" - "If `ConnectPoints' is set, the plugin creates surface or line " - "elements; otherwise, the plugin generates points.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(CutParametric) creates one new view."; + "the parametric function (`X'(u,v), `Y'(u,v), `Z'(u,v)), " + "using `NumPointsU' values of the parameter u in " + "[`MinU', `MaxU'] and `NumPointsV' values of the parameter v in " + "[`MinV', `MaxV'].\n\n" + "If `ConnectPoints' is set, the plugin creates surface or line " + "elements; otherwise, the plugin generates points.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(CutParametric) creates one new view."; } int GMSH_CutParametricPlugin::getNbOptions() const @@ -256,56 +262,59 @@ StringXString *GMSH_CutParametricPlugin::getOptionStr(int iopt) return &CutParametricOptions_String[iopt]; } -static void addInView(int connect, int i, int nbcomp, int nbtime, - double x0, double y0, double z0, double *res0, - double x, double y, double z, double *res, - std::vector<double> &P, int *nP, +static void addInView(int connect, int i, int nbcomp, int nbtime, double x0, + double y0, double z0, double *res0, double x, double y, + double z, double *res, std::vector<double> &P, int *nP, std::vector<double> &L, int *nL) { - if(connect){ - if(i){ - L.push_back(x0); L.push_back(x); - L.push_back(y0); L.push_back(y); - L.push_back(z0); L.push_back(z); - for(int k = 0; k < nbtime; ++k){ - for(int l = 0; l < nbcomp; ++l) - L.push_back(res0[nbcomp * k + l]); - for(int l = 0; l < nbcomp; ++l) - L.push_back(res[nbcomp * k + l]); + if(connect) { + if(i) { + L.push_back(x0); + L.push_back(x); + L.push_back(y0); + L.push_back(y); + L.push_back(z0); + L.push_back(z); + for(int k = 0; k < nbtime; ++k) { + for(int l = 0; l < nbcomp; ++l) L.push_back(res0[nbcomp * k + l]); + for(int l = 0; l < nbcomp; ++l) L.push_back(res[nbcomp * k + l]); } (*nL)++; } } - else{ + else { P.push_back(x); P.push_back(y); P.push_back(z); for(int k = 0; k < nbtime; ++k) - for(int l = 0; l < nbcomp; ++l) - P.push_back(res[nbcomp * k + l]); + for(int l = 0; l < nbcomp; ++l) P.push_back(res[nbcomp * k + l]); (*nP)++; } } -static void addInView(int nbcomp, int nbtime, - double x0, double y0, double z0, double *res0, - double x1, double y1, double z1, double *res1, - double x2, double y2, double z2, double *res2, - double x3, double y3, double z3, double *res3, - std::vector<double> &Q, int *nQ) +static void addInView(int nbcomp, int nbtime, double x0, double y0, double z0, + double *res0, double x1, double y1, double z1, + double *res1, double x2, double y2, double z2, + double *res2, double x3, double y3, double z3, + double *res3, std::vector<double> &Q, int *nQ) { - Q.push_back(x0); Q.push_back(x1); Q.push_back(x2); Q.push_back(x3); - Q.push_back(y0); Q.push_back(y1); Q.push_back(y2); Q.push_back(y3); - Q.push_back(z0); Q.push_back(z1); Q.push_back(z2); Q.push_back(z3); - for(int k = 0; k < nbtime; ++k){ - for(int l = 0; l < nbcomp; ++l) - Q.push_back(res0[nbcomp * k + l]); - for(int l = 0; l < nbcomp; ++l) - Q.push_back(res1[nbcomp * k + l]); - for(int l = 0; l < nbcomp; ++l) - Q.push_back(res2[nbcomp * k + l]); - for(int l = 0; l < nbcomp; ++l) - Q.push_back(res3[nbcomp * k + l]); + Q.push_back(x0); + Q.push_back(x1); + Q.push_back(x2); + Q.push_back(x3); + Q.push_back(y0); + Q.push_back(y1); + Q.push_back(y2); + Q.push_back(y3); + Q.push_back(z0); + Q.push_back(z1); + Q.push_back(z2); + Q.push_back(z3); + for(int k = 0; k < nbtime; ++k) { + for(int l = 0; l < nbcomp; ++l) Q.push_back(res0[nbcomp * k + l]); + for(int l = 0; l < nbcomp; ++l) Q.push_back(res1[nbcomp * k + l]); + for(int l = 0; l < nbcomp; ++l) Q.push_back(res2[nbcomp * k + l]); + for(int l = 0; l < nbcomp; ++l) Q.push_back(res3[nbcomp * k + l]); } (*nQ)++; } @@ -341,9 +350,9 @@ PView *GMSH_CutParametricPlugin::execute(PView *v) for(int k = 0; k < 9 * numSteps; ++k) res0[k] = res1[k] = 0.; - if(nbU == 1 || nbV == 1 || !connect){ - for(unsigned int i = 0; i < x.size(); ++i){ - if(i && connect){ + if(nbU == 1 || nbV == 1 || !connect) { + for(unsigned int i = 0; i < x.size(); ++i) { + if(i && connect) { x0 = x1; y0 = y1; z0 = z1; @@ -354,67 +363,72 @@ PView *GMSH_CutParametricPlugin::execute(PView *v) y1 = y[i]; z1 = z[i]; - if(data1->getNumScalars()){ + if(data1->getNumScalars()) { o.searchScalar(x1, y1, z1, res1); addInView(connect, i, 1, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, data2->SP, &data2->NbSP, data2->SL, &data2->NbSL); } - if(data1->getNumVectors()){ + if(data1->getNumVectors()) { o.searchVector(x1, y1, z1, res1); addInView(connect, i, 3, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, data2->VP, &data2->NbVP, data2->VL, &data2->NbVL); } - if(data1->getNumTensors()){ + if(data1->getNumTensors()) { o.searchTensor(x1, y1, z1, res1); addInView(connect, i, 9, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, data2->TP, &data2->NbTP, data2->TL, &data2->NbTL); } } } - else{ - for(int i = 0; i < nbU - 1; ++i){ - for(int j = 0; j < nbV - 1; ++j){ + else { + for(int i = 0; i < nbU - 1; ++i) { + for(int j = 0; j < nbV - 1; ++j) { int v = i * nbV + j; - x0 = x[v]; y0 = y[v]; z0 = z[v]; - x1 = x[v+1]; y1 = y[v+1]; z1 = z[v+1]; - x2 = x[v+nbV+1]; y2 = y[v+nbV+1]; z2 = z[v+nbV+1]; - x3 = x[v+nbV]; y3 = y[v+nbV]; z3 = z[v+nbV]; - - if(data1->getNumScalars()){ + x0 = x[v]; + y0 = y[v]; + z0 = z[v]; + x1 = x[v + 1]; + y1 = y[v + 1]; + z1 = z[v + 1]; + x2 = x[v + nbV + 1]; + y2 = y[v + nbV + 1]; + z2 = z[v + nbV + 1]; + x3 = x[v + nbV]; + y3 = y[v + nbV]; + z3 = z[v + nbV]; + + if(data1->getNumScalars()) { o.searchScalar(x0, y0, z0, res0); o.searchScalar(x1, y1, z1, res1); o.searchScalar(x2, y2, z2, res2); o.searchScalar(x3, y3, z3, res3); - addInView(1, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, - x2, y2, z2, res2, x3, y3, z3, res3, - data2->SQ, &data2->NbSQ); + addInView(1, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, x2, y2, z2, + res2, x3, y3, z3, res3, data2->SQ, &data2->NbSQ); } - if(data1->getNumVectors()){ + if(data1->getNumVectors()) { o.searchVector(x0, y0, z0, res0); o.searchVector(x1, y1, z1, res1); o.searchVector(x2, y2, z2, res2); o.searchVector(x3, y3, z3, res3); - addInView(3, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, - x2, y2, z2, res2, x3, y3, z3, res3, - data2->VQ, &data2->NbVQ); + addInView(3, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, x2, y2, z2, + res2, x3, y3, z3, res3, data2->VQ, &data2->NbVQ); } - if(data1->getNumTensors()){ + if(data1->getNumTensors()) { o.searchTensor(x0, y0, z0, res0); o.searchTensor(x1, y1, z1, res1); o.searchTensor(x2, y2, z2, res2); o.searchTensor(x3, y3, z3, res3); - addInView(9, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, - x2, y2, z2, res2, x3, y3, z3, res3, - data2->TQ, &data2->NbTQ); + addInView(9, numSteps, x0, y0, z0, res0, x1, y1, z1, res1, x2, y2, z2, + res2, x3, y3, z3, res3, data2->TQ, &data2->NbTQ); } } } } - delete [] res0; - delete [] res1; - delete [] res2; - delete [] res3; + delete[] res0; + delete[] res1; + delete[] res2; + delete[] res3; data2->setName(data1->getName() + "_CutParametric"); data2->setFileName(data1->getName() + "_CutParametric.pos"); diff --git a/Plugin/CutParametric.h b/Plugin/CutParametric.h index 20cdcf8d9495b27099f81e8be1072339e582cb5f..2d32c6eb4d8cdcd065bedffe1db3d0196309efb5 100644 --- a/Plugin/CutParametric.h +++ b/Plugin/CutParametric.h @@ -10,23 +10,22 @@ #include <vector> #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutParametricPlugin (); +extern "C" { +GMSH_Plugin *GMSH_RegisterCutParametricPlugin(); } -class GMSH_CutParametricPlugin : public GMSH_PostPlugin -{ - private: +class GMSH_CutParametricPlugin : public GMSH_PostPlugin { +private: static double callback(int num, int action, double value, double *opt, double step, double min, double max); - static std::string callbackStr(int num, int action, std::string value, + static std::string callbackStr(int num, int action, std::string value, std::string &opt); static int fillXYZ(); static int recompute; static std::vector<double> x, y, z; - public: - GMSH_CutParametricPlugin(){} + +public: + GMSH_CutParametricPlugin() {} std::string getName() const { return "CutParametric"; } std::string getShortHelp() const { @@ -34,9 +33,9 @@ class GMSH_CutParametricPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString *getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); static double callbackMinU(int, int, double); diff --git a/Plugin/CutPlane.cpp b/Plugin/CutPlane.cpp index 756019f88fa39c54719aa362f2f1b942ad8b2610..956cc4e32cde1f1233b77ead96eb5739d95b812a 100644 --- a/Plugin/CutPlane.cpp +++ b/Plugin/CutPlane.cpp @@ -21,42 +21,37 @@ StringXNumber CutPlaneOptions_Number[] = { {GMSH_FULLRC, "ExtractVolume", GMSH_CutPlanePlugin::callbackVol, 0}, {GMSH_FULLRC, "RecurLevel", GMSH_CutPlanePlugin::callbackRecur, 4}, {GMSH_FULLRC, "TargetError", GMSH_CutPlanePlugin::callbackTarget, 0.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutPlanePlugin() - { - return new GMSH_CutPlanePlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterCutPlanePlugin() { return new GMSH_CutPlanePlugin(); } } void GMSH_CutPlanePlugin::draw(void *context) { #if defined(HAVE_OPENGL) int num = (int)CutPlaneOptions_Number[7].def; - drawContext *ctx = (drawContext*)context; + drawContext *ctx = (drawContext *)context; if(num < 0) num = iview; - if(num >= 0 && num < (int)PView::list.size()){ - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + if(num >= 0 && num < (int)PView::list.size()) { + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); glLineWidth((float)CTX::instance()->lineWidth); SBoundingBox3d bb = PView::list[num]->getData()->getBoundingBox(); - ctx->drawPlaneInBoundingBox(bb.min().x(), bb.min().y(), bb.min().z(), - bb.max().x(), bb.max().y(), bb.max().z(), - CutPlaneOptions_Number[0].def, - CutPlaneOptions_Number[1].def, - CutPlaneOptions_Number[2].def, - CutPlaneOptions_Number[3].def); + ctx->drawPlaneInBoundingBox( + bb.min().x(), bb.min().y(), bb.min().z(), bb.max().x(), bb.max().y(), + bb.max().z(), CutPlaneOptions_Number[0].def, + CutPlaneOptions_Number[1].def, CutPlaneOptions_Number[2].def, + CutPlaneOptions_Number[3].def); } #endif } -double GMSH_CutPlanePlugin::callback(int num, int action, double value, double *opt, - double step, double min, double max) +double GMSH_CutPlanePlugin::callback(int num, int action, double value, + double *opt, double step, double min, + double max) { if(action > 0) iview = num; - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return step; case 2: return min; case 3: return max; @@ -69,56 +64,55 @@ double GMSH_CutPlanePlugin::callback(int num, int action, double value, double * double GMSH_CutPlanePlugin::callbackA(int num, int action, double value) { - return callback(num, action, value, &CutPlaneOptions_Number[0].def, - 0.01, -1, 1); + return callback(num, action, value, &CutPlaneOptions_Number[0].def, 0.01, -1, + 1); } double GMSH_CutPlanePlugin::callbackB(int num, int action, double value) { - return callback(num, action, value, &CutPlaneOptions_Number[1].def, - 0.01, -1, 1); + return callback(num, action, value, &CutPlaneOptions_Number[1].def, 0.01, -1, + 1); } double GMSH_CutPlanePlugin::callbackC(int num, int action, double value) { - return callback(num, action, value, &CutPlaneOptions_Number[2].def, - 0.01, -1, 1); + return callback(num, action, value, &CutPlaneOptions_Number[2].def, 0.01, -1, + 1); } double GMSH_CutPlanePlugin::callbackD(int num, int action, double value) { return callback(num, action, value, &CutPlaneOptions_Number[3].def, - CTX::instance()->lc / 200., -CTX::instance()->lc, + CTX::instance()->lc / 200., -CTX::instance()->lc, CTX::instance()->lc); } double GMSH_CutPlanePlugin::callbackVol(int num, int action, double value) { - return callback(num, action, value, &CutPlaneOptions_Number[4].def, - 1., -1, 1); + return callback(num, action, value, &CutPlaneOptions_Number[4].def, 1., -1, + 1); } double GMSH_CutPlanePlugin::callbackRecur(int num, int action, double value) { - return callback(num, action, value, &CutPlaneOptions_Number[5].def, - 1, 0, 10); + return callback(num, action, value, &CutPlaneOptions_Number[5].def, 1, 0, 10); } double GMSH_CutPlanePlugin::callbackTarget(int num, int action, double value) { - return callback(num, action, value, &CutPlaneOptions_Number[6].def, - 0.01, 0., 1.); + return callback(num, action, value, &CutPlaneOptions_Number[6].def, 0.01, 0., + 1.); } std::string GMSH_CutPlanePlugin::getHelp() const { return "Plugin(CutPlane) cuts the view `View' with " - "the plane `A'*X + `B'*Y + `C'*Z + `D' = 0.\n\n" - "If `ExtractVolume' is nonzero, the plugin extracts " - "the elements on one side of the plane (depending " - "on the sign of `ExtractVolume').\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(CutPlane) creates one new view."; + "the plane `A'*X + `B'*Y + `C'*Z + `D' = 0.\n\n" + "If `ExtractVolume' is nonzero, the plugin extracts " + "the elements on one side of the plane (depending " + "on the sign of `ExtractVolume').\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(CutPlane) creates one new view."; } int GMSH_CutPlanePlugin::getNbOptions() const @@ -131,21 +125,24 @@ StringXNumber *GMSH_CutPlanePlugin::getOption(int iopt) return &CutPlaneOptions_Number[iopt]; } -double GMSH_CutPlanePlugin::levelset(double x, double y, double z, double val) const +double GMSH_CutPlanePlugin::levelset(double x, double y, double z, + double val) const { return CutPlaneOptions_Number[0].def * x + CutPlaneOptions_Number[1].def * y + - CutPlaneOptions_Number[2].def * z + CutPlaneOptions_Number[3].def; + CutPlaneOptions_Number[2].def * z + CutPlaneOptions_Number[3].def; } -bool GMSH_CutPlanePlugin::geometricalFilter(fullMatrix<double> *node_positions) const +bool GMSH_CutPlanePlugin::geometricalFilter( + fullMatrix<double> *node_positions) const { - const double l0 = levelset((*node_positions)(0, 0), - (*node_positions)(0, 1), + const double l0 = levelset((*node_positions)(0, 0), (*node_positions)(0, 1), (*node_positions)(0, 2), 1); - for (int i = 1; i < node_positions->size1(); i++) - if (levelset((*node_positions)(i, 0), - (*node_positions)(i, 1), - (*node_positions)(i, 2), 1) * l0 < 0) return true; + for(int i = 1; i < node_positions->size1(); i++) + if(levelset((*node_positions)(i, 0), (*node_positions)(i, 1), + (*node_positions)(i, 2), 1) * + l0 < + 0) + return true; return false; } @@ -162,7 +159,7 @@ PView *GMSH_CutPlanePlugin::execute(PView *v) _extractVolume = (int)CutPlaneOptions_Number[4].def; _recurLevel = (int)CutPlaneOptions_Number[5].def; _targetError = CutPlaneOptions_Number[6].def; - + PView *v1 = getView(iView, v); if(!v1) return v; diff --git a/Plugin/CutPlane.h b/Plugin/CutPlane.h index bac8258de191299d013ad65247ad6fd37a68340c..b39427b6f26025bb44261c68e357ab913ffbf439 100644 --- a/Plugin/CutPlane.h +++ b/Plugin/CutPlane.h @@ -8,19 +8,18 @@ #include "Levelset.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutPlanePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterCutPlanePlugin(); } -class GMSH_CutPlanePlugin : public GMSH_LevelsetPlugin -{ +class GMSH_CutPlanePlugin : public GMSH_LevelsetPlugin { double levelset(double x, double y, double z, double val) const; static double callback(int num, int action, double value, double *opt, double step, double min, double max); static int iview; - public: - GMSH_CutPlanePlugin(){} + +public: + GMSH_CutPlanePlugin() {} std::string getName() const { return "CutPlane"; } std::string getShortHelp() const { @@ -28,7 +27,7 @@ class GMSH_CutPlanePlugin : public GMSH_LevelsetPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); virtual bool geometricalFilter(fullMatrix<double> *) const; diff --git a/Plugin/CutSphere.cpp b/Plugin/CutSphere.cpp index 14a31c79d707803cce754ddedaceb638d00bd27b..916c654512d670ba7598f228cc670ec60af11186 100644 --- a/Plugin/CutSphere.cpp +++ b/Plugin/CutSphere.cpp @@ -20,15 +20,13 @@ StringXNumber CutSphereOptions_Number[] = { {GMSH_FULLRC, "ExtractVolume", GMSH_CutSpherePlugin::callbackVol, 0.}, {GMSH_FULLRC, "RecurLevel", GMSH_CutSpherePlugin::callbackRecur, 4}, {GMSH_FULLRC, "TargetError", GMSH_CutSpherePlugin::callbackTarget, 0.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterCutSpherePlugin() { - GMSH_Plugin *GMSH_RegisterCutSpherePlugin() - { - return new GMSH_CutSpherePlugin(); - } + return new GMSH_CutSpherePlugin(); +} } void GMSH_CutSpherePlugin::draw(void *context) @@ -37,21 +35,21 @@ void GMSH_CutSpherePlugin::draw(void *context) GLint mode[2]; glGetIntegerv(GL_POLYGON_MODE, mode); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); glLineWidth((float)CTX::instance()->lineWidth); - drawContext *ctx = (drawContext*)context; - ctx->drawSphere(CutSphereOptions_Number[3].def, - CutSphereOptions_Number[0].def, - CutSphereOptions_Number[1].def, - CutSphereOptions_Number[2].def, 40, 40, 1); + drawContext *ctx = (drawContext *)context; + ctx->drawSphere( + CutSphereOptions_Number[3].def, CutSphereOptions_Number[0].def, + CutSphereOptions_Number[1].def, CutSphereOptions_Number[2].def, 40, 40, 1); glPolygonMode(GL_FRONT_AND_BACK, mode[1]); #endif } -double GMSH_CutSpherePlugin::callback(int num, int action, double value, double *opt, - double step, double min, double max) +double GMSH_CutSpherePlugin::callback(int num, int action, double value, + double *opt, double step, double min, + double max) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return step; case 2: return min; case 3: return max; @@ -65,7 +63,7 @@ double GMSH_CutSpherePlugin::callback(int num, int action, double value, double double GMSH_CutSpherePlugin::callbackX(int num, int action, double value) { return callback(num, action, value, &CutSphereOptions_Number[0].def, - CTX::instance()->lc / 100., - 2 * CTX::instance()->lc, + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, 2 * CTX::instance()->lc); } @@ -91,31 +89,31 @@ double GMSH_CutSpherePlugin::callbackR(int num, int action, double value) double GMSH_CutSpherePlugin::callbackVol(int num, int action, double value) { - return callback(num, action, value, &CutSphereOptions_Number[4].def, - 1., -1., 1.); + return callback(num, action, value, &CutSphereOptions_Number[4].def, 1., -1., + 1.); } double GMSH_CutSpherePlugin::callbackRecur(int num, int action, double value) { - return callback(num, action, value, &CutSphereOptions_Number[5].def, - 1, 0, 10); + return callback(num, action, value, &CutSphereOptions_Number[5].def, 1, 0, + 10); } double GMSH_CutSpherePlugin::callbackTarget(int num, int action, double value) { - return callback(num, action, value, &CutSphereOptions_Number[6].def, - 0.01, 0., 1.); + return callback(num, action, value, &CutSphereOptions_Number[6].def, 0.01, 0., + 1.); } std::string GMSH_CutSpherePlugin::getHelp() const { return "Plugin(CutSphere) cuts the view `View' with the " - "sphere (X-`Xc')^2 + (Y-`Yc')^2 + (Z-`Zc')^2 = `R'^2.\n\n" - "If `ExtractVolume' is nonzero, the plugin extracts " - "the elements inside (if `ExtractVolume' < 0) or " - "outside (if `ExtractVolume' > 0) the sphere.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(CutSphere) creates one new view."; + "sphere (X-`Xc')^2 + (Y-`Yc')^2 + (Z-`Zc')^2 = `R'^2.\n\n" + "If `ExtractVolume' is nonzero, the plugin extracts " + "the elements inside (if `ExtractVolume' < 0) or " + "outside (if `ExtractVolume' > 0) the sphere.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(CutSphere) creates one new view."; } int GMSH_CutSpherePlugin::getNbOptions() const diff --git a/Plugin/CutSphere.h b/Plugin/CutSphere.h index 93ac67098d3619b098ce202bf3355e18c367d69a..456c4794975afb1b29439a92ce704178e99251f3 100644 --- a/Plugin/CutSphere.h +++ b/Plugin/CutSphere.h @@ -8,18 +8,17 @@ #include "Levelset.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterCutSpherePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterCutSpherePlugin(); } -class GMSH_CutSpherePlugin : public GMSH_LevelsetPlugin -{ +class GMSH_CutSpherePlugin : public GMSH_LevelsetPlugin { double levelset(double x, double y, double z, double val) const; static double callback(int num, int action, double value, double *opt, double step, double min, double max); - public: - GMSH_CutSpherePlugin(){} + +public: + GMSH_CutSpherePlugin() {} std::string getName() const { return "CutSphere"; } std::string getShortHelp() const { @@ -27,7 +26,7 @@ class GMSH_CutSpherePlugin : public GMSH_LevelsetPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); static double callbackX(int, int, double); diff --git a/Plugin/DiscretizationError.cpp b/Plugin/DiscretizationError.cpp index c51b839cd942e13a1a6d8ebb0b4d7a5199945e77..02733dea3fb7eda1914df7640a3380667c8e19c5 100644 --- a/Plugin/DiscretizationError.cpp +++ b/Plugin/DiscretizationError.cpp @@ -14,22 +14,23 @@ #include <MTriangle.h> StringXNumber DiscretizationErrorOptions_Number[] = { - {GMSH_FULLRC, "SuperSamplingNodes", NULL, 10.} -}; + {GMSH_FULLRC, "SuperSamplingNodes", NULL, 10.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterDiscretizationErrorPlugin() { - GMSH_Plugin *GMSH_RegisterDiscretizationErrorPlugin() { - return new GMSH_DiscretizationErrorPlugin(); - } + return new GMSH_DiscretizationErrorPlugin(); +} } std::string GMSH_DiscretizationErrorPlugin::getHelp() const { return "Plugin(DiscretizationError) computes the error between the mesh " - "and the geometry. It does so by supersampling the elements and computing " - "the distance between the supersampled points dans their projection on " - "the geometry."; + "and the geometry. It does so by supersampling the elements and " + "computing " + "the distance between the supersampled points dans their projection " + "on " + "the geometry."; } int GMSH_DiscretizationErrorPlugin::getNbOptions() const @@ -46,51 +47,55 @@ PView *GMSH_DiscretizationErrorPlugin::execute(PView *v) { double tol = CTX::instance()->geom.tolerance; int nEdgeNodes = (int)DiscretizationErrorOptions_Number[0].def; - double paramQuandt = 1.0 / (nEdgeNodes -1) - 10*tol; - double paramQuandtQuad = 2.0 / (nEdgeNodes - 1) - 10*tol; + double paramQuandt = 1.0 / (nEdgeNodes - 1) - 10 * tol; + double paramQuandtQuad = 2.0 / (nEdgeNodes - 1) - 10 * tol; int i, j, k, counter; // used as a start estimate for u,v when performing an orthogonal projection double startEstimate[2] = {0.5, 0.5}; double dx, dy, dz; - std::vector< std::pair<SPoint3,double> > quadDist(nEdgeNodes*nEdgeNodes); - std::vector< std::pair<SPoint3,double> > triDist((nEdgeNodes + 1)*nEdgeNodes / 2); + std::vector<std::pair<SPoint3, double> > quadDist(nEdgeNodes * nEdgeNodes); + std::vector<std::pair<SPoint3, double> > triDist((nEdgeNodes + 1) * + nEdgeNodes / 2); PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - for (GModel::fiter itFace = GModel::current()->firstFace(); - itFace != GModel::current()->lastFace(); ++itFace) { - + for(GModel::fiter itFace = GModel::current()->firstFace(); + itFace != GModel::current()->lastFace(); ++itFace) { // sample quadrangles /* 13 14 15 16 * 9 10 11 12 * 5 6 7 8 * 1 2 3 4 */ - for (std::vector<MQuadrangle*>::iterator itQuad = (*itFace)->quadrangles.begin(); - itQuad != (*itFace)->quadrangles.end(); ++itQuad) { - for (j = 0; j < nEdgeNodes; j++) { // u - for (i = 0; i < nEdgeNodes; i++) { // v - (*itQuad)->pnt(-1+5*tol+paramQuandtQuad*i, -1+5*tol+paramQuandtQuad*j, - 0.0, quadDist[j*(nEdgeNodes) + i].first); - SPoint3 *point = &quadDist[j*(nEdgeNodes) + i].first; - GPoint closest = (*itFace)->closestPoint(*point,startEstimate); + for(std::vector<MQuadrangle *>::iterator itQuad = + (*itFace)->quadrangles.begin(); + itQuad != (*itFace)->quadrangles.end(); ++itQuad) { + for(j = 0; j < nEdgeNodes; j++) { // u + for(i = 0; i < nEdgeNodes; i++) { // v + (*itQuad)->pnt(-1 + 5 * tol + paramQuandtQuad * i, + -1 + 5 * tol + paramQuandtQuad * j, 0.0, + quadDist[j * (nEdgeNodes) + i].first); + SPoint3 *point = &quadDist[j * (nEdgeNodes) + i].first; + GPoint closest = (*itFace)->closestPoint(*point, startEstimate); dx = closest.x() - point->x(); dy = closest.y() - point->y(); dz = closest.z() - point->z(); - quadDist[j*(nEdgeNodes) + i].second = sqrt(dx*dx + dy*dy + dz*dz); + quadDist[j * (nEdgeNodes) + i].second = + sqrt(dx * dx + dy * dy + dz * dz); } } - for (j = 0; j < nEdgeNodes - 1; j++) { - for (i = 0; i < nEdgeNodes - 1; i++) { + for(j = 0; j < nEdgeNodes - 1; j++) { + for(i = 0; i < nEdgeNodes - 1; i++) { std::vector<double> *out = data2->incrementList(1, TYPE_QUA); - int indices[4] = {i+j*nEdgeNodes, i+j*nEdgeNodes+1, i+(j+1)*nEdgeNodes+1, - i+(j+1)*nEdgeNodes}; - for (k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.x()); - for (k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.y()); - for (k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.z()); - for (k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].second); + int indices[4] = {i + j * nEdgeNodes, i + j * nEdgeNodes + 1, + i + (j + 1) * nEdgeNodes + 1, + i + (j + 1) * nEdgeNodes}; + for(k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.x()); + for(k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.y()); + for(k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.z()); + for(k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].second); } } } @@ -101,48 +106,49 @@ PView *GMSH_DiscretizationErrorPlugin::execute(PView *v) * 3 5 8 * 1 2 4 7 */ - for (std::vector<MTriangle*>::iterator itTri = (*itFace)->triangles.begin(); - itTri != (*itFace)->triangles.end(); ++itTri) { + for(std::vector<MTriangle *>::iterator itTri = (*itFace)->triangles.begin(); + itTri != (*itFace)->triangles.end(); ++itTri) { counter = 0; - for (i = 0; i < nEdgeNodes; i++) { - for (j = 0; j < (i + 1); j++) { - (*itTri)->pnt(5*tol + paramQuandt*(i - j), 5*tol + paramQuandt*j, 0.0, - triDist[counter].first); - SPoint3 *point = &triDist[counter].first; // Check : the points are good - GPoint closest = (*itFace)->closestPoint(*point,startEstimate); + for(i = 0; i < nEdgeNodes; i++) { + for(j = 0; j < (i + 1); j++) { + (*itTri)->pnt(5 * tol + paramQuandt * (i - j), + 5 * tol + paramQuandt * j, 0.0, triDist[counter].first); + SPoint3 *point = + &triDist[counter].first; // Check : the points are good + GPoint closest = (*itFace)->closestPoint(*point, startEstimate); dx = (closest.x() - point->x()); dy = (closest.y() - point->y()); dz = (closest.z() - point->z()); - triDist[counter].second = sqrt(dx*dx + dy*dy + dz*dz); + triDist[counter].second = sqrt(dx * dx + dy * dy + dz * dz); counter++; } } int indices[3]; - for (j = 0; j < nEdgeNodes - 1; j++) { // row in the triangle + for(j = 0; j < nEdgeNodes - 1; j++) { // row in the triangle bool odd = false; - for (i = 0; i < j*2 + 1; i ++) { // small tri in the row - if (!odd) { - indices[0] = i / 2 + (j+1)*j/2; - indices[1] = i / 2 + (j+1)*j/2 + j+1; - indices[2] = i / 2 + (j+1)*j/2 + j+2; + for(i = 0; i < j * 2 + 1; i++) { // small tri in the row + if(!odd) { + indices[0] = i / 2 + (j + 1) * j / 2; + indices[1] = i / 2 + (j + 1) * j / 2 + j + 1; + indices[2] = i / 2 + (j + 1) * j / 2 + j + 2; } else { - indices[0] = (i-1)/2 + (j+1)*j/2; - indices[1] = (i-1)/2 + (j+1)*j/2 + j+2; - indices[2] = (i-1)/2 + (j+1)*j/2 + 1; + indices[0] = (i - 1) / 2 + (j + 1) * j / 2; + indices[1] = (i - 1) / 2 + (j + 1) * j / 2 + j + 2; + indices[2] = (i - 1) / 2 + (j + 1) * j / 2 + 1; } std::vector<double> *out = data2->incrementList(1, TYPE_TRI); - for (k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.x()); - for (k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.y()); - for (k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.z()); - for (k = 0; k < 3; k++) out->push_back(triDist[indices[k]].second); + for(k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.x()); + for(k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.y()); + for(k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.z()); + for(k = 0; k < 3; k++) out->push_back(triDist[indices[k]].second); odd = !odd; } } } - //viusalize stuff + // viusalize stuff } data2->setName("Discretization Error"); diff --git a/Plugin/DiscretizationError.h b/Plugin/DiscretizationError.h index 33196da224fe764b8635ee6fb45dcd4c90ce0e95..556a7a7a109bfef5b2500aee9cf4db9db31d7ed0 100644 --- a/Plugin/DiscretizationError.h +++ b/Plugin/DiscretizationError.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterDiscretizationErrorPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterDiscretizationErrorPlugin(); } -class GMSH_DiscretizationErrorPlugin : public GMSH_PostPlugin -{ +class GMSH_DiscretizationErrorPlugin : public GMSH_PostPlugin { public: - GMSH_DiscretizationErrorPlugin(){} + GMSH_DiscretizationErrorPlugin() {} std::string getName() const { return "DiscretizationError"; } std::string getShortHelp() const { @@ -25,7 +23,7 @@ public: std::string getHelp() const; std::string getAuthor() const { return "B. Gorissen, T. Bolemann"; } int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Distance.cpp b/Plugin/Distance.cpp index ca382522cde74e8cda24068765c4cabe28f123bb..ba09bf735904885d2ceab5eb8a6ed095ca4339b0 100644 --- a/Plugin/Distance.cpp +++ b/Plugin/Distance.cpp @@ -33,19 +33,13 @@ StringXNumber DistanceOptions_Number[] = { {GMSH_FULLRC, "Computation", NULL, -1}, {GMSH_FULLRC, "MinScale", NULL, -1}, {GMSH_FULLRC, "MaxScale", NULL, -1}, - {GMSH_FULLRC, "Orthogonal", NULL, -1} -}; + {GMSH_FULLRC, "Orthogonal", NULL, -1}}; StringXString DistanceOptions_String[] = { - {GMSH_FULLRC, "Filename", NULL, "distance.pos"} -}; + {GMSH_FULLRC, "Filename", NULL, "distance.pos"}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterDistancePlugin() - { - return new GMSH_DistancePlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterDistancePlugin() { return new GMSH_DistancePlugin(); } } GMSH_DistancePlugin::GMSH_DistancePlugin() @@ -60,19 +54,22 @@ GMSH_DistancePlugin::GMSH_DistancePlugin() std::string GMSH_DistancePlugin::getHelp() const { return "Plugin(Distance) computes distances to physical entities in " - "a mesh.\n\n" - "Define the physical entities to which the distance is computed. " - "If Point=0, Line=0, and Surface=0, then the distance is computed " - "to all the boundaries of the mesh (edges in 2D and faces in 3D).\n\n" - "Computation<0. computes the geometrical euclidian distance " - "(warning: different than the geodesic distance), and Computation=a>0.0 " - "solves a PDE on the mesh with the diffusion constant mu = a*bbox, with " - "bbox being the max size of the bounding box of the mesh (see paper " - "Legrand 2006).\n\n" - "Min Scale and max Scale, scale the distance function. If min Scale<0 " - "and max Scale<0, then no scaling is applied to the distance function.\n\n" - "Plugin(Distance) creates a new distance view and also saves the view " - "in the fileName.pos file."; + "a mesh.\n\n" + "Define the physical entities to which the distance is computed. " + "If Point=0, Line=0, and Surface=0, then the distance is computed " + "to all the boundaries of the mesh (edges in 2D and faces in 3D).\n\n" + "Computation<0. computes the geometrical euclidian distance " + "(warning: different than the geodesic distance), and " + "Computation=a>0.0 " + "solves a PDE on the mesh with the diffusion constant mu = a*bbox, " + "with " + "bbox being the max size of the bounding box of the mesh (see paper " + "Legrand 2006).\n\n" + "Min Scale and max Scale, scale the distance function. If min Scale<0 " + "and max Scale<0, then no scaling is applied to the distance " + "function.\n\n" + "Plugin(Distance) creates a new distance view and also saves the view " + "in the fileName.pos file."; } int GMSH_DistancePlugin::getNbOptions() const @@ -95,120 +92,123 @@ StringXString *GMSH_DistancePlugin::getOptionStr(int iopt) return &DistanceOptions_String[iopt]; } -void GMSH_DistancePlugin::printView(std::vector<GEntity*> _entities, - std::map<MVertex*, double > _distance_map) +void GMSH_DistancePlugin::printView(std::vector<GEntity *> _entities, + std::map<MVertex *, double> _distance_map) { _fileName = DistanceOptions_String[0].def; - _minScale = (double) DistanceOptions_Number[4].def; - _maxScale = (double) DistanceOptions_Number[5].def; + _minScale = (double)DistanceOptions_Number[4].def; + _maxScale = (double)DistanceOptions_Number[5].def; - double minDist=1.e4; - double maxDist=0.0; - for (std::map<MVertex*,double >::iterator itv=_distance_map.begin(); - itv != _distance_map.end(); ++itv){ + double minDist = 1.e4; + double maxDist = 0.0; + for(std::map<MVertex *, double>::iterator itv = _distance_map.begin(); + itv != _distance_map.end(); ++itv) { double dist = itv->second; - if (dist>maxDist) maxDist = dist; - if (dist<minDist) minDist = dist; + if(dist > maxDist) maxDist = dist; + if(dist < minDist) minDist = dist; itv->second = dist; } Msg::Info("Writing %s", _fileName.c_str()); - FILE *fName = Fopen(_fileName.c_str(),"w"); - if(!fName){ + FILE *fName = Fopen(_fileName.c_str(), "w"); + if(!fName) { Msg::Error("Could not open file '%s'", _fileName.c_str()); return; } fprintf(fName, "View \"distance \"{\n"); - for (unsigned int ii=0; ii<_entities.size(); ii++) { - if (_entities[ii]->dim() == _maxDim) { - for (unsigned int i=0; i<_entities[ii]->getNumMeshElements(); i++) { + for(unsigned int ii = 0; ii < _entities.size(); ii++) { + if(_entities[ii]->dim() == _maxDim) { + for(unsigned int i = 0; i < _entities[ii]->getNumMeshElements(); i++) { MElement *e = _entities[ii]->getMeshElement(i); int numNodes = e->getNumVertices(); - if (e->getNumChildren()) + if(e->getNumChildren()) numNodes = e->getNumChildren() * e->getChild(0)->getNumVertices(); std::vector<double> x(numNodes), y(numNodes), z(numNodes); - std::vector<double> *out = _data->incrementList(1, e->getType(), numNodes); - std::vector<MVertex*> nods; + std::vector<double> *out = + _data->incrementList(1, e->getType(), numNodes); + std::vector<MVertex *> nods; - if (!e->getNumChildren()) - for(int i = 0; i < numNodes; i++) - nods.push_back(e->getVertex(i)); + if(!e->getNumChildren()) + for(int i = 0; i < numNodes; i++) nods.push_back(e->getVertex(i)); else for(int i = 0; i < e->getNumChildren(); i++) for(std::size_t j = 0; j < e->getChild(i)->getNumVertices(); j++) nods.push_back(e->getChild(i)->getVertex(j)); - for (int nod = 0; nod < numNodes; nod++) out->push_back((nods[nod])->x()); - for (int nod = 0; nod < numNodes; nod++) out->push_back((nods[nod])->y()); - for (int nod = 0; nod < numNodes; nod++) out->push_back((nods[nod])->z()); - - if (_maxDim == 2) - switch (numNodes) { - case 2: fprintf(fName,"SL("); break; - case 3: fprintf(fName,"ST("); break; - case 4: fprintf(fName,"SQ("); break; - default: Msg::Error("Error in Plugin 'Distance' (numNodes=%d)", - numNodes); break; + for(int nod = 0; nod < numNodes; nod++) + out->push_back((nods[nod])->x()); + for(int nod = 0; nod < numNodes; nod++) + out->push_back((nods[nod])->y()); + for(int nod = 0; nod < numNodes; nod++) + out->push_back((nods[nod])->z()); + + if(_maxDim == 2) switch(numNodes) { + case 2: fprintf(fName, "SL("); break; + case 3: fprintf(fName, "ST("); break; + case 4: fprintf(fName, "SQ("); break; + default: + Msg::Error("Error in Plugin 'Distance' (numNodes=%d)", numNodes); + break; } - else if (_maxDim == 3) - switch (numNodes) { - case 4: fprintf(fName,"SS("); break; - case 8: fprintf(fName,"SH("); break; - case 6: fprintf(fName,"SI("); break; - case 5: fprintf(fName,"SY("); break; - default: Msg::Error("Error in Plugin 'Distance' (numNodes=%d)", - numNodes); break; + else if(_maxDim == 3) + switch(numNodes) { + case 4: fprintf(fName, "SS("); break; + case 8: fprintf(fName, "SH("); break; + case 6: fprintf(fName, "SI("); break; + case 5: fprintf(fName, "SY("); break; + default: + Msg::Error("Error in Plugin 'Distance' (numNodes=%d)", numNodes); + break; } std::vector<double> dist; - for (int j=0; j<numNodes; j++) { - MVertex *v = nods[j]; - if (j) + for(int j = 0; j < numNodes; j++) { + MVertex *v = nods[j]; + if(j) fprintf(fName, ",%.16g,%.16g,%.16g", v->x(), v->y(), v->z()); else fprintf(fName, "%.16g,%.16g,%.16g", v->x(), v->y(), v->z()); - std::map<MVertex*, double>::iterator it = _distance_map.find(v); + std::map<MVertex *, double>::iterator it = _distance_map.find(v); dist.push_back(it->second); } - fprintf(fName,"){"); - for (unsigned int i=0; i<dist.size(); i++) { - if (_minScale>0 && _maxScale>0) + fprintf(fName, "){"); + for(unsigned int i = 0; i < dist.size(); i++) { + if(_minScale > 0 && _maxScale > 0) dist[i] = _minScale + ((dist[i] - minDist) / (maxDist - minDist)) * - (_maxScale - _minScale); - else if (_minScale>0 && _maxScale<0) + (_maxScale - _minScale); + else if(_minScale > 0 && _maxScale < 0) dist[i] = _minScale + dist[i]; out->push_back(dist[i]); - if (i) + if(i) fprintf(fName, ",%.16g", dist[i]); else fprintf(fName, "%.16g", dist[i]); } - fprintf(fName,"};\n"); - + fprintf(fName, "};\n"); } } } - fprintf(fName,"};\n"); + fprintf(fName, "};\n"); fclose(fName); } PView *GMSH_DistancePlugin::execute(PView *v) { - int id_pt = (int) DistanceOptions_Number[0].def; - int id_line = (int) DistanceOptions_Number[1].def; - int id_face = (int) DistanceOptions_Number[2].def; - double type = (double) DistanceOptions_Number[3].def; - int ortho = (int) DistanceOptions_Number[6].def; + int id_pt = (int)DistanceOptions_Number[0].def; + int id_line = (int)DistanceOptions_Number[1].def; + int id_face = (int)DistanceOptions_Number[2].def; + double type = (double)DistanceOptions_Number[3].def; + int ortho = (int)DistanceOptions_Number[6].def; PView *view = new PView(); _data = getDataList(view); - std::vector<GEntity*> _entities; + std::vector<GEntity *> _entities; GModel::current()->getEntities(_entities); - if (!_entities.size() || !_entities[_entities.size()-1]->getMeshElement(0)) { + if(!_entities.size() || !_entities[_entities.size() - 1]->getMeshElement(0)) { Msg::Error("This plugin needs a mesh!"); return view; } @@ -227,19 +227,21 @@ PView *GMSH_DistancePlugin::execute(PView *v) dofManager<double> *dofView = new dofManager<double>(lsys); #endif - GEntity* ge = _entities[_entities.size()-1]; - int integrationPointTetra[2] = {0,0}; + GEntity *ge = _entities[_entities.size() - 1]; + int integrationPointTetra[2] = {0, 0}; int numnodes = 0; - for (unsigned int i = 0; i < _entities.size()-1; i++) + for(unsigned int i = 0; i < _entities.size() - 1; i++) numnodes += _entities[i]->mesh_vertices.size(); - int totNodes = numnodes + _entities[_entities.size()-1]->mesh_vertices.size(); + int totNodes = + numnodes + _entities[_entities.size() - 1]->mesh_vertices.size(); int order = ge->getMeshElement(0)->getPolynomialOrder(); - int totNumNodes = totNodes + ge->getNumMeshElements()*integrationPointTetra[order-1]; + int totNumNodes = + totNodes + ge->getNumMeshElements() * integrationPointTetra[order - 1]; std::vector<SPoint3> pts; std::vector<double> distances; - std::vector<MVertex* > pt2Vertex; + std::vector<MVertex *> pt2Vertex; pts.clear(); distances.clear(); pt2Vertex.clear(); @@ -247,8 +249,8 @@ PView *GMSH_DistancePlugin::execute(PView *v) distances.reserve(totNumNodes); pt2Vertex.reserve(totNumNodes); - std::map<MVertex*,double> _distanceE_map; - std::map<MVertex*,int> _isInYarn_map; + std::map<MVertex *, double> _distanceE_map; + std::map<MVertex *, int> _isInYarn_map; std::vector<int> index; std::vector<double> distancesE; std::vector<double> distances2; @@ -258,22 +260,22 @@ PView *GMSH_DistancePlugin::execute(PView *v) std::vector<SPoint3> closePts; std::vector<SPoint3> closePts2; - for (int i=0; i<totNumNodes; i++) { + for(int i = 0; i < totNumNodes; i++) { distances.push_back(1.e22); } int k = 0; - for (unsigned int i=0; i<_entities.size(); i++){ - GEntity* ge = _entities[i]; + for(unsigned int i = 0; i < _entities.size(); i++) { + GEntity *ge = _entities[i]; _maxDim = std::max(_maxDim, ge->dim()); - for (unsigned int j=0; j<ge->mesh_vertices.size(); j++) { + for(unsigned int j = 0; j < ge->mesh_vertices.size(); j++) { MVertex *v = ge->mesh_vertices[j]; pts.push_back(SPoint3(v->x(), v->y(), v->z())); _distance_map.insert(std::make_pair(v, 0.0)); -/* TO DO (by AM) - SPoint3 p_empty(); - _closePts_map.insert(std::make_pair(v, p_empty)); -*/ + /* TO DO (by AM) + SPoint3 p_empty(); + _closePts_map.insert(std::make_pair(v, p_empty)); + */ pt2Vertex[k] = v; k++; } @@ -281,26 +283,26 @@ PView *GMSH_DistancePlugin::execute(PView *v) // Compute geometrical distance to mesh boundaries //------------------------------------------------------ - if (type < 0.0 ) { - + if(type < 0.0) { bool existEntity = false; - for (unsigned int i=0; i<_entities.size(); i++) { - GEntity* g2 = _entities[i]; + for(unsigned int i = 0; i < _entities.size(); i++) { + GEntity *g2 = _entities[i]; int gDim = g2->dim(); std::vector<int> phys = g2->getPhysicalEntities(); bool computeForEntity = false; - for(unsigned int k = 0; k<phys.size(); k++) { + for(unsigned int k = 0; k < phys.size(); k++) { int tagp = phys[k]; - if (id_pt == 0 && id_line == 0 && id_face == 0 && gDim == _maxDim - 1) + if(id_pt == 0 && id_line == 0 && id_face == 0 && gDim == _maxDim - 1) computeForEntity = true; - else if ((tagp == id_pt && gDim == 0) || (tagp == id_line && gDim == 1) || - (tagp == id_face && gDim == 2)) + else if((tagp == id_pt && gDim == 0) || + (tagp == id_line && gDim == 1) || + (tagp == id_face && gDim == 2)) computeForEntity = true; } - if (computeForEntity) { + if(computeForEntity) { existEntity = true; - for (unsigned int k = 0; k < g2->getNumMeshElements(); k++) { + for(unsigned int k = 0; k < g2->getNumMeshElements(); k++) { std::vector<double> iDistances; std::vector<SPoint3> iClosePts; std::vector<double> iDistancesE; @@ -310,18 +312,19 @@ PView *GMSH_DistancePlugin::execute(PView *v) MVertex *v2 = e->getVertex(1); SPoint3 p1(v1->x(), v1->y(), v1->z()); SPoint3 p2(v2->x(), v2->y(), v2->z()); - if ((e->getNumVertices() == 2 && order == 1) || - (e->getNumVertices() == 3 && order == 2)) { + if((e->getNumVertices() == 2 && order == 1) || + (e->getNumVertices() == 3 && order == 2)) { signedDistancesPointsLine(iDistances, iClosePts, pts, p1, p2); } - else if ((e->getNumVertices() == 3 && order == 1) || - (e->getNumVertices() == 6 && order == 2)) { + else if((e->getNumVertices() == 3 && order == 1) || + (e->getNumVertices() == 6 && order == 2)) { MVertex *v3 = e->getVertex(2); - SPoint3 p3 (v3->x(),v3->y(),v3->z()); - signedDistancesPointsTriangle(iDistances, iClosePts, pts, p1, p2, p3); + SPoint3 p3(v3->x(), v3->y(), v3->z()); + signedDistancesPointsTriangle(iDistances, iClosePts, pts, p1, p2, + p3); } - for (unsigned int kk=0; kk<pts.size(); kk++) { - if (std::abs(iDistances[kk]) < distances[kk]) { + for(unsigned int kk = 0; kk < pts.size(); kk++) { + if(std::abs(iDistances[kk]) < distances[kk]) { distances[kk] = std::abs(iDistances[kk]); MVertex *v = pt2Vertex[kk]; _distance_map[v] = distances[kk]; @@ -333,12 +336,12 @@ PView *GMSH_DistancePlugin::execute(PView *v) } } } - if (!existEntity){ - if (id_pt != 0) Msg::Error("The Physical Point does not exist !"); - if (id_line != 0) Msg::Error("The Physical Line does not exist !"); - if (id_face != 0) Msg::Error("The Physical Surface does not exist !"); + if(!existEntity) { + if(id_pt != 0) Msg::Error("The Physical Point does not exist !"); + if(id_line != 0) Msg::Error("The Physical Line does not exist !"); + if(id_face != 0) Msg::Error("The Physical Surface does not exist !"); } - else{ + else { printView(_entities, _distance_map); } @@ -349,30 +352,30 @@ PView *GMSH_DistancePlugin::execute(PView *v) // Compute PDE for distance function //----------------------------------- - else if (type > 0.0) { - + else if(type > 0.0) { #if defined(HAVE_SOLVER) bool existEntity = false; SBoundingBox3d bbox; - for(unsigned int i = 0; i < _entities.size(); i++){ - GEntity* ge = _entities[i]; + for(unsigned int i = 0; i < _entities.size(); i++) { + GEntity *ge = _entities[i]; int gDim = ge->dim(); bool fixForEntity = false; std::vector<int> phys = ge->getPhysicalEntities(); for(unsigned int k = 0; k < phys.size(); k++) { int tagp = phys[k]; - if (id_pt == 0 && id_line == 0 && id_face == 0 && gDim == _maxDim - 1) + if(id_pt == 0 && id_line == 0 && id_face == 0 && gDim == _maxDim - 1) fixForEntity = true; - else if ((tagp == id_pt && gDim == 0) || (tagp == id_line && gDim == 1) || - (tagp == id_face && gDim == 2) ) + else if((tagp == id_pt && gDim == 0) || + (tagp == id_line && gDim == 1) || + (tagp == id_face && gDim == 2)) fixForEntity = true; } - if (fixForEntity) { + if(fixForEntity) { existEntity = true; - for (unsigned int i = 0; i < ge->getNumMeshElements(); ++i) { + for(unsigned int i = 0; i < ge->getNumMeshElements(); ++i) { MElement *t = ge->getMeshElement(i); - for (std::size_t k=0; k<t->getNumVertices(); k++) { + for(std::size_t k = 0; k < t->getNumVertices(); k++) { MVertex *v = t->getVertex(k); dofView->fixVertex(v, 0, 1, 0.); bbox += SPoint3(v->x(), v->y(), v->z()); @@ -381,30 +384,30 @@ PView *GMSH_DistancePlugin::execute(PView *v) } } - if (!existEntity){ - if (id_pt != 0) Msg::Error("The Physical Point does not exist !"); - if (id_line != 0) Msg::Error("The Physical Line does not exist !"); - if (id_face != 0) Msg::Error("The Physical Surface does not exist !"); + if(!existEntity) { + if(id_pt != 0) Msg::Error("The Physical Point does not exist !"); + if(id_line != 0) Msg::Error("The Physical Line does not exist !"); + if(id_face != 0) Msg::Error("The Physical Surface does not exist !"); } - else{ + else { std::vector<MElement *> allElems; - for(unsigned int ii = 0; ii < _entities.size(); ii++){ + for(unsigned int ii = 0; ii < _entities.size(); ii++) { if(_entities[ii]->dim() == _maxDim) { GEntity *ge = _entities[ii]; for(unsigned int i = 0; i < ge->getNumMeshElements(); ++i) { MElement *t = ge->getMeshElement(i); allElems.push_back(t); - for (std::size_t k = 0; k < t->getNumVertices(); k++) + for(std::size_t k = 0; k < t->getNumVertices(); k++) dofView->numberVertex(t->getVertex(k), 0, 1); } } } double L = norm(SVector3(bbox.max(), bbox.min())); - double mu = type*L; - simpleFunction<double> DIFF(mu*mu), ONE(1.0); + double mu = type * L; + simpleFunction<double> DIFF(mu * mu), ONE(1.0); distanceTerm distance(GModel::current(), 1, &DIFF, &ONE); - for (std::vector<MElement* >::iterator it = allElems.begin(); - it != allElems.end(); it++){ + for(std::vector<MElement *>::iterator it = allElems.begin(); + it != allElems.end(); it++) { SElement se((*it)); distance.addToMatrix(*dofView, &se); } @@ -413,8 +416,8 @@ PView *GMSH_DistancePlugin::execute(PView *v) Msg::Info("Distance Computation: Assembly done"); lsys->systemSolve(); Msg::Info("Distance Computation: System solved"); - for (std::map<MVertex*,double >::iterator itv = _distance_map.begin(); - itv != _distance_map.end() ; ++itv) { + for(std::map<MVertex *, double>::iterator itv = _distance_map.begin(); + itv != _distance_map.end(); ++itv) { MVertex *v = itv->first; double value; dofView->getDofValue(v, 0, 1, value); @@ -435,7 +438,7 @@ PView *GMSH_DistancePlugin::execute(PView *v) // compute also orthogonal vector to distance field // A Uortho = -C DIST //------------------------------------------------ - if (ortho > 0) { + if(ortho > 0) { #if defined(HAVE_SOLVER) #if defined(HAVE_PETSC) @@ -451,22 +454,22 @@ PView *GMSH_DistancePlugin::execute(PView *v) dofManager<double> myAssembler(lsys2); simpleFunction<double> ONE(1.0); - double dMax = 1.0; //EMI TO CHANGE + double dMax = 1.0; // EMI TO CHANGE std::vector<MElement *> allElems; - for(unsigned int ii = 0; ii < _entities.size(); ii++){ - if (_entities[ii]->dim() == _maxDim) { + for(unsigned int ii = 0; ii < _entities.size(); ii++) { + if(_entities[ii]->dim() == _maxDim) { GEntity *ge = _entities[ii]; - for (unsigned int i=0; i<ge->getNumMeshElements(); ++i) { + for(unsigned int i = 0; i < ge->getNumMeshElements(); ++i) { MElement *t = ge->getMeshElement(i); double vMean = 0.0; - for (std::size_t k = 0; k < t->getNumVertices(); k++) { - std::map<MVertex*, double>::iterator it = _distance_map.find(t->getVertex(k)); + for(std::size_t k = 0; k < t->getNumVertices(); k++) { + std::map<MVertex *, double>::iterator it = + _distance_map.find(t->getVertex(k)); vMean += it->second; } vMean /= t->getNumVertices(); - if (vMean < dMax) - allElems.push_back(ge->getMeshElement(i)); + if(vMean < dMax) allElems.push_back(ge->getMeshElement(i)); } } } @@ -476,22 +479,22 @@ PView *GMSH_DistancePlugin::execute(PView *v) MVertex *vFIX = e->getVertex(0); myAssembler.fixVertex(vFIX, 0, 1, 0.0); - for (std::vector<MElement* >::iterator it = allElems.begin(); - it != allElems.end(); it++){ + for(std::vector<MElement *>::iterator it = allElems.begin(); + it != allElems.end(); it++) { MElement *t = *it; for(std::size_t k = 0; k < t->getNumVertices(); k++) myAssembler.numberVertex(t->getVertex(k), 0, 1); } orthogonalTerm *ortho; - ortho = new orthogonalTerm(GModel::current(), 1, &ONE, &_distance_map); + ortho = new orthogonalTerm(GModel::current(), 1, &ONE, &_distance_map); // if (type < 0) // ortho = new orthogonalTerm(GModel::current(), 1, &ONE, view); // else // ortho = new orthogonalTerm(GModel::current(), 1, &ONE, dofView); - for (std::vector<MElement* >::iterator it = allElems.begin(); - it != allElems.end(); it++){ + for(std::vector<MElement *>::iterator it = allElems.begin(); + it != allElems.end(); it++) { SElement se((*it)); ortho->addToMatrix(myAssembler, &se); } @@ -507,8 +510,8 @@ PView *GMSH_DistancePlugin::execute(PView *v) data2->setName("ortogonal field"); Msg::Info("Writing orthogonal.pos"); - FILE *f5 = Fopen("orthogonal.pos","w"); - if(!f5){ + FILE *f5 = Fopen("orthogonal.pos", "w"); + if(!f5) { Msg::Error("Could not open file 'orthogonal.pos'"); #if defined(HAVE_SOLVER) delete lsys; @@ -517,82 +520,83 @@ PView *GMSH_DistancePlugin::execute(PView *v) return view; } - fprintf(f5,"View \"orthogonal\"{\n"); - for (std::vector<MElement* >::iterator it = allElems.begin(); - it != allElems.end(); it++){ + fprintf(f5, "View \"orthogonal\"{\n"); + for(std::vector<MElement *>::iterator it = allElems.begin(); + it != allElems.end(); it++) { MElement *e = *it; - int numNodes = e->getNumVertices(); - if (e->getType() == TYPE_POLYG) - numNodes = e->getNumChildren() * e->getChild(0)->getNumVertices(); - std::vector<double> x(numNodes), y(numNodes), z(numNodes); - std::vector<double> *out2 = data2->incrementList(1, e->getType(), numNodes); - std::vector<MVertex*> nods; - std::vector<double> orth; - - if(!e->getNumChildren()) - for(int i=0; i<numNodes; i++) - nods.push_back(e->getVertex(i)); - else - for(int i = 0; i < e->getNumChildren(); i++) - for(std::size_t j = 0; j < e->getChild(i)->getNumVertices(); j++) - nods.push_back(e->getChild(i)->getVertex(j)); - - for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->x()); - for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->y()); - for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->z()); - - if (_maxDim == 2) - switch (numNodes) { - case 2: fprintf(f5,"SL("); break; - case 3: fprintf(f5,"ST("); break; - case 4: fprintf(f5,"SQ("); break; - default: Msg::Fatal("Error in Plugin 'Distance' (numNodes=%g).",numNodes); break; + int numNodes = e->getNumVertices(); + if(e->getType() == TYPE_POLYG) + numNodes = e->getNumChildren() * e->getChild(0)->getNumVertices(); + std::vector<double> x(numNodes), y(numNodes), z(numNodes); + std::vector<double> *out2 = + data2->incrementList(1, e->getType(), numNodes); + std::vector<MVertex *> nods; + std::vector<double> orth; + + if(!e->getNumChildren()) + for(int i = 0; i < numNodes; i++) nods.push_back(e->getVertex(i)); + else + for(int i = 0; i < e->getNumChildren(); i++) + for(std::size_t j = 0; j < e->getChild(i)->getNumVertices(); j++) + nods.push_back(e->getChild(i)->getVertex(j)); + + for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->x()); + for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->y()); + for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->z()); + + if(_maxDim == 2) switch(numNodes) { + case 2: fprintf(f5, "SL("); break; + case 3: fprintf(f5, "ST("); break; + case 4: fprintf(f5, "SQ("); break; + default: + Msg::Fatal("Error in Plugin 'Distance' (numNodes=%g).", numNodes); + break; + } + else if(_maxDim == 3) + switch(numNodes) { + case 4: fprintf(f5, "SS("); break; + case 8: fprintf(f5, "SH("); break; + case 6: fprintf(f5, "SI("); break; + case 5: fprintf(f5, "SY("); break; + default: + Msg::Fatal("Error in Plugin 'Distance' (numNodes=%g).", numNodes); + break; + } + + for(int j = 0; j < numNodes; j++) { + MVertex *v = nods[j]; + if(j) + fprintf(f5, ",%g,%g,%g", v->x(), v->y(), v->z()); + else + fprintf(f5, "%g,%g,%g", v->x(), v->y(), v->z()); + double value; + myAssembler.getDofValue(v, 0, 1, value); + orth.push_back(value); } - else if (_maxDim == 3) - switch (numNodes) { - case 4: fprintf(f5,"SS("); break; - case 8: fprintf(f5,"SH("); break; - case 6: fprintf(f5,"SI("); break; - case 5: fprintf(f5,"SY("); break; - default: Msg::Fatal("Error in Plugin 'Distance' (numNodes=%g).",numNodes); break; + fprintf(f5, "){"); + for(unsigned int i = 0; i < orth.size(); i++) { + out2->push_back(orth[i]); + if(i) + fprintf(f5, ",%g", orth[i]); + else + fprintf(f5, "%g", orth[i]); } - - for (int j=0; j<numNodes; j++) { - MVertex *v = nods[j]; - if (j) - fprintf(f5, ",%g,%g,%g", v->x(), v->y(), v->z()); - else - fprintf(f5, "%g,%g,%g", v->x(), v->y(), v->z()); - double value; - myAssembler.getDofValue(v, 0, 1, value); - orth.push_back(value); + fprintf(f5, "};\n"); } - fprintf(f5,"){"); - for (unsigned int i=0; i<orth.size(); i++) { - out2->push_back(orth[i]); - if (i) - fprintf(f5,",%g", orth[i]); - else - fprintf(f5,"%g", orth[i]); - } - fprintf(f5,"};\n"); + fprintf(f5, "};\n"); + fclose(f5); - } - fprintf(f5,"};\n"); - fclose(f5); + lsys->clear(); + lsys2->clear(); - lsys->clear(); - lsys2->clear(); - - data2->Time.push_back(0); - data2->setFileName("orthogonal.pos"); - data2->finalize(); + data2->Time.push_back(0); + data2->setFileName("orthogonal.pos"); + data2->finalize(); #endif } - #if defined(HAVE_SOLVER) delete lsys; delete dofView; diff --git a/Plugin/Distance.h b/Plugin/Distance.h index 5b5c7ec14f96feefcb4c05e7681c1da50aea07b0..4f692790d22bae5200fc92c578f68deabd2becea 100644 --- a/Plugin/Distance.h +++ b/Plugin/Distance.h @@ -10,37 +10,33 @@ #include "Plugin.h" #include "MVertex.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterDistancePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterDistancePlugin(); } -class GMSH_DistancePlugin : public GMSH_PostPlugin -{ - private: +class GMSH_DistancePlugin : public GMSH_PostPlugin { +private: std::string _fileName; double _minScale; double _maxScale; int _maxDim; PViewDataList *_data; - public: - std::map<MVertex*,double > _distance_map; - std::map<MVertex*,SPoint3 > _closePts_map; - GMSH_DistancePlugin(); + +public: + std::map<MVertex *, double> _distance_map; + std::map<MVertex *, SPoint3> _closePts_map; + GMSH_DistancePlugin(); std::string getName() const { return "Distance"; } - std::string getShortHelp() const - { - return "Compute distance to boundaries"; - } + std::string getShortHelp() const { return "Compute distance to boundaries"; } std::string getHelp() const; std::string getAuthor() const { return "E. Marchandise"; } int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; StringXString *getOptionStr(int iopt); PView *execute(PView *); - void printView(std::vector<GEntity*> _entities, - std::map<MVertex*,double > _distance_map ); + void printView(std::vector<GEntity *> _entities, + std::map<MVertex *, double> _distance_map); }; #endif diff --git a/Plugin/Divergence.cpp b/Plugin/Divergence.cpp index fd4e230effaa86cb2fc88ff4d6a8ce4683ebd4e4..656f39cc7094d2ff4be7e1f5a598e73d465275d9 100644 --- a/Plugin/Divergence.cpp +++ b/Plugin/Divergence.cpp @@ -7,24 +7,21 @@ #include "shapeFunctions.h" #include "GmshDefines.h" -StringXNumber DivergenceOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.} -}; +StringXNumber DivergenceOptions_Number[] = {{GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterDivergencePlugin() { - GMSH_Plugin *GMSH_RegisterDivergencePlugin() - { - return new GMSH_DivergencePlugin(); - } + return new GMSH_DivergencePlugin(); +} } std::string GMSH_DivergencePlugin::getHelp() const { return "Plugin(Divergence) computes the divergence of the " - "field in the view `View'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Divergence) creates one new view."; + "field in the view `View'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Divergence) creates one new view."; } int GMSH_DivergencePlugin::getNbOptions() const @@ -45,17 +42,18 @@ PView *GMSH_DivergencePlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = getPossiblyAdaptiveData(v1); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("Divergence plugin cannot be run on multi-mesh views"); return v; } PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); + int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); - for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++){ - for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++) { + for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); + ele++) { if(data1->skipElement(firstNonEmptyStep, ent, ele)) continue; int numComp = data1->getNumComponents(firstNonEmptyStep, ent, ele); if(numComp != 3) continue; @@ -65,7 +63,8 @@ PView *GMSH_DivergencePlugin::execute(PView *v) if(!out) continue; double x[8], y[8], z[8], val[8 * 3]; for(int nod = 0; nod < numNodes; nod++) - data1->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], z[nod]); + data1->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], + z[nod]); int dim = data1->getDimension(firstNonEmptyStep, ent, ele); elementFactory factory; element *element = factory.create(numNodes, dim, x, y, z); @@ -73,12 +72,13 @@ PView *GMSH_DivergencePlugin::execute(PView *v) for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); - for(int step = 0; step < data1->getNumTimeSteps(); step++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { if(!data1->hasTimeStep(step)) continue; for(int nod = 0; nod < numNodes; nod++) for(int comp = 0; comp < numComp; comp++) - data1->getValue(step, ent, ele, nod, comp, val[numComp * nod + comp]); - for(int nod = 0; nod < numNodes; nod++){ + data1->getValue(step, ent, ele, nod, comp, + val[numComp * nod + comp]); + for(int nod = 0; nod < numNodes; nod++) { double u, v, w; element->getNode(nod, u, v, w); double f = element->interpolateDiv(val, u, v, w, 3); @@ -89,7 +89,7 @@ PView *GMSH_DivergencePlugin::execute(PView *v) } } - for(int i = 0; i < data1->getNumTimeSteps(); i++){ + for(int i = 0; i < data1->getNumTimeSteps(); i++) { if(!data1->hasTimeStep(i)) continue; double time = data1->getTime(i); data2->Time.push_back(time); diff --git a/Plugin/Divergence.h b/Plugin/Divergence.h index 0acce167212ae434300fdf845fd56c1a64510c04..2faabf2e226ec9b36f8933288f55fb935f2f9522 100644 --- a/Plugin/Divergence.h +++ b/Plugin/Divergence.h @@ -8,23 +8,21 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterDivergencePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterDivergencePlugin(); } -class GMSH_DivergencePlugin : public GMSH_PostPlugin -{ - public: - GMSH_DivergencePlugin(){} +class GMSH_DivergencePlugin : public GMSH_PostPlugin { +public: + GMSH_DivergencePlugin() {} std::string getName() const { return "Divergence"; } - std::string getShortHelp() const - { + std::string getShortHelp() const + { return "Compute the divergence of a vector view"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Eigenvalues.cpp b/Plugin/Eigenvalues.cpp index 4bd2408dab9bbdd72e3230b7f75fac56e3c93b4b..05317355324593e09b5c993a151895c855b690b1 100644 --- a/Plugin/Eigenvalues.cpp +++ b/Plugin/Eigenvalues.cpp @@ -7,24 +7,21 @@ #include "Numeric.h" #include "GmshDefines.h" -StringXNumber EigenvaluesOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.} -}; +StringXNumber EigenvaluesOptions_Number[] = {{GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterEigenvaluesPlugin() { - GMSH_Plugin *GMSH_RegisterEigenvaluesPlugin() - { - return new GMSH_EigenvaluesPlugin(); - } + return new GMSH_EigenvaluesPlugin(); +} } std::string GMSH_EigenvaluesPlugin::getHelp() const { return "Plugin(Eigenvalues) computes the three real " - "eigenvalues of each tensor in the view `View'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Eigenvalues) creates three new scalar views."; + "eigenvalues of each tensor in the view `View'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Eigenvalues) creates three new scalar views."; } int GMSH_EigenvaluesPlugin::getNbOptions() const @@ -45,7 +42,7 @@ PView *GMSH_EigenvaluesPlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = getPossiblyAdaptiveData(v1); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("Eigenvalues plugin cannot be run on multi-mesh views"); return v; } @@ -58,8 +55,8 @@ PView *GMSH_EigenvaluesPlugin::execute(PView *v) PViewDataList *dmid = getDataList(mid); PViewDataList *dmax = getDataList(max); - for(int ent = 0; ent < data1->getNumEntities(0); ent++){ - for(int ele = 0; ele < data1->getNumElements(0, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(0); ent++) { + for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) { if(data1->skipElement(0, ent, ele)) continue; int numComp = data1->getNumComponents(0, ent, ele); if(numComp != 9) continue; @@ -72,15 +69,15 @@ PView *GMSH_EigenvaluesPlugin::execute(PView *v) double xyz[3][8]; for(int nod = 0; nod < numNodes; nod++) data1->getNode(0, ent, ele, nod, xyz[0][nod], xyz[1][nod], xyz[2][nod]); - for(int i = 0; i < 3; i++){ - for(int nod = 0; nod < numNodes; nod++){ + for(int i = 0; i < 3; i++) { + for(int nod = 0; nod < numNodes; nod++) { outmin->push_back(xyz[i][nod]); outmid->push_back(xyz[i][nod]); outmax->push_back(xyz[i][nod]); } } - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int nod = 0; nod < numNodes; nod++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int nod = 0; nod < numNodes; nod++) { double val[9], w[3]; for(int comp = 0; comp < numComp; comp++) data1->getValue(step, ent, ele, nod, comp, val[comp]); @@ -95,8 +92,8 @@ PView *GMSH_EigenvaluesPlugin::execute(PView *v) } } } - - for(int i = 0; i < data1->getNumTimeSteps(); i++){ + + for(int i = 0; i < data1->getNumTimeSteps(); i++) { double time = data1->getTime(i); dmin->Time.push_back(time); dmid->Time.push_back(time); diff --git a/Plugin/Eigenvalues.h b/Plugin/Eigenvalues.h index 9a9f6c11f0947e490574e8952eca6fb857a31d1c..872bc4ddf0ae48953445fec3a287961a625c421a 100644 --- a/Plugin/Eigenvalues.h +++ b/Plugin/Eigenvalues.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterEigenvaluesPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterEigenvaluesPlugin(); } -class GMSH_EigenvaluesPlugin : public GMSH_PostPlugin -{ - public: - GMSH_EigenvaluesPlugin(){} +class GMSH_EigenvaluesPlugin : public GMSH_PostPlugin { +public: + GMSH_EigenvaluesPlugin() {} std::string getName() const { return "Eigenvalues"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_EigenvaluesPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Eigenvectors.cpp b/Plugin/Eigenvectors.cpp index e496bed12a2b4d67b61c23f4c89f1d539928bcc1..b591a0285b82ffbecef1a8ce0e1d9cab0764f07b 100644 --- a/Plugin/Eigenvectors.cpp +++ b/Plugin/Eigenvectors.cpp @@ -10,28 +10,26 @@ StringXNumber EigenvectorsOptions_Number[] = { {GMSH_FULLRC, "ScaleByEigenvalues", NULL, 1.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterEigenvectorsPlugin() { - GMSH_Plugin *GMSH_RegisterEigenvectorsPlugin() - { - return new GMSH_EigenvectorsPlugin(); - } + return new GMSH_EigenvectorsPlugin(); +} } std::string GMSH_EigenvectorsPlugin::getHelp() const { return "Plugin(Eigenvectors) computes the three (right) " - "eigenvectors of each tensor in the view `View' " - "and sorts them according to the value of the " - "associated eigenvalues.\n\n" - "If `ScaleByEigenvalues' is set, each eigenvector is " - "scaled by its associated eigenvalue. The plugin " - "gives an error if the eigenvectors are complex.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Eigenvectors) creates three new vector view."; + "eigenvectors of each tensor in the view `View' " + "and sorts them according to the value of the " + "associated eigenvalues.\n\n" + "If `ScaleByEigenvalues' is set, each eigenvector is " + "scaled by its associated eigenvalue. The plugin " + "gives an error if the eigenvectors are complex.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Eigenvectors) creates three new vector view."; } int GMSH_EigenvectorsPlugin::getNbOptions() const @@ -53,7 +51,7 @@ PView *GMSH_EigenvectorsPlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = getPossiblyAdaptiveData(v1); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("Eigenvectors plugin cannot be run on multi-mesh views"); return v; } @@ -69,8 +67,8 @@ PView *GMSH_EigenvectorsPlugin::execute(PView *v) int nbcomplex = 0; fullMatrix<double> mat(3, 3), vl(3, 3), vr(3, 3); fullVector<double> dr(3), di(3); - for(int ent = 0; ent < data1->getNumEntities(0); ent++){ - for(int ele = 0; ele < data1->getNumElements(0, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(0); ent++) { + for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) { if(data1->skipElement(0, ent, ele)) continue; int numComp = data1->getNumComponents(0, ent, ele); if(numComp != 9) continue; @@ -83,29 +81,32 @@ PView *GMSH_EigenvectorsPlugin::execute(PView *v) double xyz[3][8]; for(int nod = 0; nod < numNodes; nod++) data1->getNode(0, ent, ele, nod, xyz[0][nod], xyz[1][nod], xyz[2][nod]); - for(int i = 0; i < 3; i++){ - for(int nod = 0; nod < numNodes; nod++){ + for(int i = 0; i < 3; i++) { + for(int nod = 0; nod < numNodes; nod++) { outmin->push_back(xyz[i][nod]); outmid->push_back(xyz[i][nod]); outmax->push_back(xyz[i][nod]); } } - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int nod = 0; nod < numNodes; nod++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int nod = 0; nod < numNodes; nod++) { for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) data1->getValue(step, ent, ele, nod, 3 * i + j, mat(i, j)); - if(mat.eig(dr, di, vl, vr, true)){ + if(mat.eig(dr, di, vl, vr, true)) { if(!scale) dr(0) = dr(1) = dr(2) = 1.; - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { double res; - res = dr(0) * vr(i, 0); outmin->push_back(res); - res = dr(1) * vr(i, 1); outmid->push_back(res); - res = dr(2) * vr(i, 2); outmax->push_back(res); + res = dr(0) * vr(i, 0); + outmin->push_back(res); + res = dr(1) * vr(i, 1); + outmid->push_back(res); + res = dr(2) * vr(i, 2); + outmax->push_back(res); } if(di(0) || di(1) || di(2)) nbcomplex++; } - else{ + else { Msg::Error("Could not compute eigenvalues/vectors"); } } @@ -113,10 +114,9 @@ PView *GMSH_EigenvectorsPlugin::execute(PView *v) } } - if(nbcomplex) - Msg::Error("%d tensors have complex eigenvalues", nbcomplex); - - for(int i = 0; i < data1->getNumTimeSteps(); i++){ + if(nbcomplex) Msg::Error("%d tensors have complex eigenvalues", nbcomplex); + + for(int i = 0; i < data1->getNumTimeSteps(); i++) { double time = data1->getTime(i); dmin->Time.push_back(time); dmid->Time.push_back(time); diff --git a/Plugin/Eigenvectors.h b/Plugin/Eigenvectors.h index 161d0cfbd0202587ab3a7ecc958cfcf769a7d8a9..ea2685d066f63e55f8aea8a9d041186b0b33659e 100644 --- a/Plugin/Eigenvectors.h +++ b/Plugin/Eigenvectors.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterEigenvectorsPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterEigenvectorsPlugin(); } -class GMSH_EigenvectorsPlugin : public GMSH_PostPlugin -{ - public: - GMSH_EigenvectorsPlugin(){} +class GMSH_EigenvectorsPlugin : public GMSH_PostPlugin { +public: + GMSH_EigenvectorsPlugin() {} std::string getName() const { return "Eigenvectors"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_EigenvectorsPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/ExtractEdges.cpp b/Plugin/ExtractEdges.cpp index cd23816ba9fd3900c92d014b35da9144cb253488..7013c65bcb9a7bac2e645a7b810efa772abd16c7 100644 --- a/Plugin/ExtractEdges.cpp +++ b/Plugin/ExtractEdges.cpp @@ -16,19 +16,18 @@ StringXNumber ExtractEdgesOptions_Number[] = { {GMSH_FULLRC, "IncludeBoundary", NULL, 1.}, }; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin() { - GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin() - { - return new GMSH_ExtractEdgesPlugin(); - } + return new GMSH_ExtractEdgesPlugin(); +} } std::string GMSH_ExtractEdgesPlugin::getHelp() const { return "Plugin(ExtractEdges) extracts sharp edges " - "from a triangular mesh.\n\n" - "Plugin(ExtractEdges) creates one new view."; + "from a triangular mesh.\n\n" + "Plugin(ExtractEdges) creates one new view."; } int GMSH_ExtractEdgesPlugin::getNbOptions() const @@ -58,13 +57,13 @@ static void add_edge(edge_angle &ea, PViewDataList *data) PView *GMSH_ExtractEdgesPlugin::execute(PView *v) { - std::vector<MTriangle*> elements; + std::vector<MTriangle *> elements; for(GModel::fiter it = GModel::current()->firstFace(); it != GModel::current()->lastFace(); ++it) elements.insert(elements.end(), (*it)->triangles.begin(), (*it)->triangles.end()); - if(elements.empty()){ + if(elements.empty()) { Msg::Error("No triangles in mesh to extract edges from"); return 0; } @@ -78,13 +77,13 @@ PView *GMSH_ExtractEdgesPlugin::execute(PView *v) buildListOfEdgeAngle(adj, edges_detected, edges_lonly); double threshold = ExtractEdgesOptions_Number[0].def / 180. * M_PI; - for(unsigned int i = 0; i < edges_detected.size(); i++){ + for(unsigned int i = 0; i < edges_detected.size(); i++) { if(edges_detected[i].angle <= threshold) break; add_edge(edges_detected[i], data2); } - if(ExtractEdgesOptions_Number[1].def){ - for(unsigned int i = 0; i < edges_lonly.size(); i++){ + if(ExtractEdgesOptions_Number[1].def) { + for(unsigned int i = 0; i < edges_lonly.size(); i++) { add_edge(edges_lonly[i], data2); } } diff --git a/Plugin/ExtractEdges.h b/Plugin/ExtractEdges.h index eb63f2beaee4225e1e7bfd65078fa9eac747998e..1e1aa2367e50810c7e5080af7035d1c63afabf61 100644 --- a/Plugin/ExtractEdges.h +++ b/Plugin/ExtractEdges.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterExtractEdgesPlugin(); } -class GMSH_ExtractEdgesPlugin : public GMSH_PostPlugin -{ - public: - GMSH_ExtractEdgesPlugin(){} +class GMSH_ExtractEdgesPlugin : public GMSH_PostPlugin { +public: + GMSH_ExtractEdgesPlugin() {} std::string getName() const { return "ExtractEdges"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_ExtractEdgesPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/ExtractElements.cpp b/Plugin/ExtractElements.cpp index 2811032a4fd237ccc2498bbede473e82b15c167d..ea185bdeaad9a173aeea0f26b8b7671033def844 100644 --- a/Plugin/ExtractElements.cpp +++ b/Plugin/ExtractElements.cpp @@ -7,32 +7,27 @@ #include "Numeric.h" StringXNumber ExtractElementsOptions_Number[] = { - {GMSH_FULLRC, "MinVal", NULL, 0.}, - {GMSH_FULLRC, "MaxVal", NULL, 0.}, - {GMSH_FULLRC, "TimeStep", NULL, 0.}, - {GMSH_FULLRC, "Visible", NULL, 1.}, - {GMSH_FULLRC, "Dimension", NULL, -1.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; - -extern "C" + {GMSH_FULLRC, "MinVal", NULL, 0.}, {GMSH_FULLRC, "MaxVal", NULL, 0.}, + {GMSH_FULLRC, "TimeStep", NULL, 0.}, {GMSH_FULLRC, "Visible", NULL, 1.}, + {GMSH_FULLRC, "Dimension", NULL, -1.}, {GMSH_FULLRC, "View", NULL, -1.}}; + +extern "C" { +GMSH_Plugin *GMSH_RegisterExtractElementsPlugin() { - GMSH_Plugin *GMSH_RegisterExtractElementsPlugin() - { - return new GMSH_ExtractElementsPlugin(); - } + return new GMSH_ExtractElementsPlugin(); +} } std::string GMSH_ExtractElementsPlugin::getHelp() const { return "Plugin(ExtractElements) extracts some elements " - "from the view `View'. If `MinVal' != `MaxVal', it extracts " - "the elements whose `TimeStep'-th values (averaged by element) " - "are comprised between `MinVal' and `MaxVal'. If `Visible' != 0, " - "it extracts visible elements. " - "\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(ExtractElements) creates one new view."; + "from the view `View'. If `MinVal' != `MaxVal', it extracts " + "the elements whose `TimeStep'-th values (averaged by element) " + "are comprised between `MinVal' and `MaxVal'. If `Visible' != 0, " + "it extracts visible elements. " + "\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(ExtractElements) creates one new view."; } int GMSH_ExtractElementsPlugin::getNbOptions() const @@ -60,7 +55,7 @@ PView *GMSH_ExtractElementsPlugin::execute(PView *v) bool checkMinMax = MinVal != MaxVal; int step = (thisStep < 0) ? 0 : thisStep; - if(thisStep > data1->getNumTimeSteps() - 1){ + if(thisStep > data1->getNumTimeSteps() - 1) { Msg::Error("Invalid time step (%d) in View[%d]: using first step instead", thisStep, v1->getIndex()); step = 0; @@ -69,26 +64,26 @@ PView *GMSH_ExtractElementsPlugin::execute(PView *v) PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { if(visible && data1->skipEntity(step, ent)) continue; - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele, visible)) continue; int dim = data1->getDimension(step, ent, ele); - if((dimension>0) && (dim!=dimension)) continue; + if((dimension > 0) && (dim != dimension)) continue; int numNodes = data1->getNumNodes(step, ent, ele); - if(checkMinMax){ - double d = 0.; - for(int nod = 0; nod < numNodes; nod++){ - double val; - data1->getScalarValue(step, ent, ele, nod, val); - d += val; - } - d /= (double)numNodes; - // use '>=' and '<' so that we can do segmentation without - // worrying about roundoff errors - if(d < MinVal || d >= MaxVal) continue; + if(checkMinMax) { + double d = 0.; + for(int nod = 0; nod < numNodes; nod++) { + double val; + data1->getScalarValue(step, ent, ele, nod, val); + d += val; + } + d /= (double)numNodes; + // use '>=' and '<' so that we can do segmentation without + // worrying about roundoff errors + if(d < MinVal || d >= MaxVal) continue; } int type = data1->getType(step, ent, ele); @@ -97,31 +92,30 @@ PView *GMSH_ExtractElementsPlugin::execute(PView *v) std::vector<double> x(numNodes), y(numNodes), z(numNodes); std::vector<double> v(numNodes * numComp); for(int nod = 0; nod < numNodes; nod++) - data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); + data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - if(!data1->hasTimeStep(step)) continue; - if ((thisStep>=0) && (thisStep!=step)) continue; - - for(int nod = 0; nod < numNodes; nod++){ - for(int comp = 0; comp < numComp; comp++){ - double temp; - data1->getValue(step, ent, ele, nod, comp, temp); - out->push_back(temp); - } - } + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + if(!data1->hasTimeStep(step)) continue; + if((thisStep >= 0) && (thisStep != step)) continue; + + for(int nod = 0; nod < numNodes; nod++) { + for(int comp = 0; comp < numComp; comp++) { + double temp; + data1->getValue(step, ent, ele, nod, comp, temp); + out->push_back(temp); + } + } } } } - - if(thisStep>=0) + if(thisStep >= 0) data2->Time.push_back(data1->getTime(thisStep)); - else{ - for(int step = 0; step < data1->getNumTimeSteps(); step++){ + else { + for(int step = 0; step < data1->getNumTimeSteps(); step++) { data2->Time.push_back(data1->getTime(step)); } } diff --git a/Plugin/ExtractElements.h b/Plugin/ExtractElements.h index 37568171adb512b2563957d542eeb66972fe9e39..df493410923728d0d80973eb026d853d94b495ce 100644 --- a/Plugin/ExtractElements.h +++ b/Plugin/ExtractElements.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterExtractElementsPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterExtractElementsPlugin(); } -class GMSH_ExtractElementsPlugin : public GMSH_PostPlugin -{ - public: - GMSH_ExtractElementsPlugin(){} +class GMSH_ExtractElementsPlugin : public GMSH_PostPlugin { +public: + GMSH_ExtractElementsPlugin() {} std::string getName() const { return "ExtractElements"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_ExtractElementsPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/FaultZone.cpp b/Plugin/FaultZone.cpp index a728d26c1e8097ab5e89d50a5f9f3dd555008e51..8b564fc54d7c04b8e2f63aaea62df1ce6b1a226c 100644 --- a/Plugin/FaultZone.cpp +++ b/Plugin/FaultZone.cpp @@ -30,31 +30,33 @@ StringXString FaultZoneOptions_String[] = { {GMSH_FULLRC, "Prefix", NULL, "FAMI_"}, }; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterFaultZonePlugin() { - GMSH_Plugin *GMSH_RegisterFaultZonePlugin() - { - return new GMSH_FaultZonePlugin(); - } + return new GMSH_FaultZonePlugin(); +} } std::string GMSH_FaultZonePlugin::getHelp() const { return "Plugin(FaultZone) convert all the embedded lines of an existing " - "surfacic mesh to flat quadrangles. Flat quadrangles represent joint " - "elements suitable to model a fault zone with Code_Aster." - "\n\n" - "`SurfaceTag' must be an existing plane surface containing embedded " - "lines. Embedded lines must have been added to the surface via the " - "command Line In Surface. " - "The surface must be meshed with quadratic incomplete elements." - "\n\n" - "`Thickness' is the thickness of the flat quadrangles. " - "Set a value different to zero can be helpful to check the connectivity. " - "\n\n" - "`Prefix' is the prefix of the name of physicals containing the new embedded. " - "All physicals containing embedded lines are replaced by physicals containing " - "the corresponding joint elements."; + "surfacic mesh to flat quadrangles. Flat quadrangles represent joint " + "elements suitable to model a fault zone with Code_Aster." + "\n\n" + "`SurfaceTag' must be an existing plane surface containing embedded " + "lines. Embedded lines must have been added to the surface via the " + "command Line In Surface. " + "The surface must be meshed with quadratic incomplete elements." + "\n\n" + "`Thickness' is the thickness of the flat quadrangles. " + "Set a value different to zero can be helpful to check the " + "connectivity. " + "\n\n" + "`Prefix' is the prefix of the name of physicals containing the new " + "embedded. " + "All physicals containing embedded lines are replaced by physicals " + "containing " + "the corresponding joint elements."; } int GMSH_FaultZonePlugin::getNbOptions() const @@ -94,51 +96,52 @@ PView *GMSH_FaultZonePlugin::execute(PView *view) GFace *gFace = gModel->getFaceByTag(tag); - if (!gFace){ - Msg::Error("Face %d does not exist or was not meshed",tag); + if(!gFace) { + Msg::Error("Face %d does not exist or was not meshed", tag); return view; } - if (!gFace->embeddedEdges().size()){ + if(!gFace->embeddedEdges().size()) { Msg::Error("No line to treat in this surface"); return view; } - std::vector<GEdge*> const& embeddedEdges = gFace->embeddedEdges(); - std::vector<GEdge*>::const_iterator itl; - for(itl = embeddedEdges.begin();itl != embeddedEdges.end(); ++itl) - if ((*itl)->length() != 0) break; - if (itl == embeddedEdges.end()){ + std::vector<GEdge *> const &embeddedEdges = gFace->embeddedEdges(); + std::vector<GEdge *>::const_iterator itl; + for(itl = embeddedEdges.begin(); itl != embeddedEdges.end(); ++itl) + if((*itl)->length() != 0) break; + if(itl == embeddedEdges.end()) { Msg::Error("No line to treat in this surface"); - Msg::Error("The plugin FaultZone may have been already run for this surface. " - "Reload your geometry"); + Msg::Error( + "The plugin FaultZone may have been already run for this surface. " + "Reload your geometry"); return view; } - for(itl = embeddedEdges.begin();itl != embeddedEdges.end(); ++itl) - if ((*itl)->geomType() != GEntity::Line) break; - if (itl != embeddedEdges.end()){ + for(itl = embeddedEdges.begin(); itl != embeddedEdges.end(); ++itl) + if((*itl)->geomType() != GEntity::Line) break; + if(itl != embeddedEdges.end()) { Msg::Error("All the embedded edges must be straight lines"); return view; } - for(itl = embeddedEdges.begin();itl != embeddedEdges.end(); ++itl){ - Curve* c = FindCurve((*itl)->tag()); - if (c && List_Nbr(c->Control_Points) > 2) break; + for(itl = embeddedEdges.begin(); itl != embeddedEdges.end(); ++itl) { + Curve *c = FindCurve((*itl)->tag()); + if(c && List_Nbr(c->Control_Points) > 2) break; } - if (itl != embeddedEdges.end()){ + if(itl != embeddedEdges.end()) { Msg::Error("The embedded edges must not contain control points"); return view; } - for(itl = embeddedEdges.begin();itl != embeddedEdges.end(); ++itl){ - GEdge* gEdge = *itl; + for(itl = embeddedEdges.begin(); itl != embeddedEdges.end(); ++itl) { + GEdge *gEdge = *itl; unsigned int i = 0; for(; i < gEdge->getNumMeshElements(); i++) - if (gEdge->getMeshElement(i)->getNumVertices() == 3) break; - if (i == gEdge->getNumMeshElements()) break; + if(gEdge->getMeshElement(i)->getNumVertices() == 3) break; + if(i == gEdge->getNumMeshElements()) break; } - if (itl != embeddedEdges.end()){ + if(itl != embeddedEdges.end()) { Msg::Error("The mesh must be order 2"); return view; } @@ -157,8 +160,7 @@ PView *GMSH_FaultZonePlugin::execute(PView *view) faultZoneMesher.ModifyElementsConnectivity(gFace); - if (eps) - faultZoneMesher.ModifyJointNodePosition(eps/2); + if(eps) faultZoneMesher.ModifyJointNodePosition(eps / 2); CTX::instance()->mesh.changed = ENT_ALL; @@ -177,17 +179,17 @@ PView *GMSH_FaultZonePlugin::execute(PView *view) * _connectedElements */ //================================================================================ -void GMSH_FaultZoneMesher::RetriveFissuresInfos(GFace* gFace){ - - std::vector<GEdge*> const& embeddedEdges = gFace->embeddedEdges(); - std::vector<GEdge*> const& edges = gFace->edges(); +void GMSH_FaultZoneMesher::RetriveFissuresInfos(GFace *gFace) +{ + std::vector<GEdge *> const &embeddedEdges = gFace->embeddedEdges(); + std::vector<GEdge *> const &edges = gFace->edges(); // set with all the MVertex of the fissures - std::set < MVertex* > allFissuresVertices; - for(std::vector<GEdge*>::const_iterator itl = embeddedEdges.begin(); - itl != embeddedEdges.end(); ++itl){ + std::set<MVertex *> allFissuresVertices; + for(std::vector<GEdge *>::const_iterator itl = embeddedEdges.begin(); + itl != embeddedEdges.end(); ++itl) { GEdge *gEdge = *itl; - for (unsigned int i = 0; i < gEdge->getNumMeshVertices(); i++){ + for(unsigned int i = 0; i < gEdge->getNumMeshVertices(); i++) { allFissuresVertices.insert(gEdge->getMeshVertex(i)); } allFissuresVertices.insert(gEdge->getBeginVertex()->getMeshVertex(0)); @@ -195,39 +197,40 @@ void GMSH_FaultZoneMesher::RetriveFissuresInfos(GFace* gFace){ } // set with all quadratic MVertex of the fissures connected to the surface - std::set < MVertex* > allConnectedQuadraticVertices; + std::set<MVertex *> allConnectedQuadraticVertices; // fill _connectedElements - for(unsigned int i = 0; i < gFace->getNumMeshElements(); i++){ + for(unsigned int i = 0; i < gFace->getNumMeshElements(); i++) { MElement *mElem = gFace->getMeshElement(i); - for (std::size_t j = 0; j < mElem->getNumVertices(); j++){ + for(std::size_t j = 0; j < mElem->getNumVertices(); j++) { MVertex *mVert = mElem->getVertex(j); - std::set < MVertex* >::iterator its = allFissuresVertices.find( mVert ); - if (its != allFissuresVertices.end()){ + std::set<MVertex *>::iterator its = allFissuresVertices.find(mVert); + if(its != allFissuresVertices.end()) { _connectedElements.insert(mElem); - if (mVert->getPolynomialOrder() == 2) - allConnectedQuadraticVertices.insert( mVert ); + if(mVert->getPolynomialOrder() == 2) + allConnectedQuadraticVertices.insert(mVert); } } } // for the generatrices - for(std::vector<GEdge*>::const_iterator itl = edges.begin();itl != edges.end(); ++itl){ + for(std::vector<GEdge *>::const_iterator itl = edges.begin(); + itl != edges.end(); ++itl) { GEdge *gEdge = *itl; - for(unsigned int i = 0; i < gEdge->getNumMeshElements(); i++){ + for(unsigned int i = 0; i < gEdge->getNumMeshElements(); i++) { MElement *mElem = gEdge->getMeshElement(i); - for (std::size_t j = 0; j < mElem->getNumVertices(); j++){ + for(std::size_t j = 0; j < mElem->getNumVertices(); j++) { MVertex *mVert = mElem->getVertex(j); - std::set < MVertex* >::iterator its = allFissuresVertices.find( mVert ); - if (its != allFissuresVertices.end()){ + std::set<MVertex *>::iterator its = allFissuresVertices.find(mVert); + if(its != allFissuresVertices.end()) { _connectedElements.insert(mElem); } } } } - for(std::vector<GEdge*>::const_iterator itl = embeddedEdges.begin(); - itl != embeddedEdges.end(); ++itl){ + for(std::vector<GEdge *>::const_iterator itl = embeddedEdges.begin(); + itl != embeddedEdges.end(); ++itl) { GEdge *gEdge = *itl; - if (gEdge->length() == 0)// nothing to do if there is no element + if(gEdge->length() == 0) // nothing to do if there is no element continue; MVertex *mVertexBegin = gEdge->getBeginVertex()->getMeshVertex(0); @@ -238,7 +241,7 @@ void GMSH_FaultZoneMesher::RetriveFissuresInfos(GFace* gFace){ SVector3 vectTanBegin = SVector3(pointEnd, pointBegin); SVector3 vectTanEnd = SVector3(pointBegin, pointEnd); - SVector3 vectNorm = crossprod(vectZ , vectTanEnd); + SVector3 vectNorm = crossprod(vectZ, vectTanEnd); vectTanBegin.normalize(); vectTanEnd.normalize(); @@ -246,34 +249,38 @@ void GMSH_FaultZoneMesher::RetriveFissuresInfos(GFace* gFace){ if(!norm) Msg::Error("norm == 0 in Plugin(FaultZone)"); // fill _jointElements and _fissureByHeavNode - for(unsigned int i = 0; i < gEdge->getNumMeshElements(); i++){ + for(unsigned int i = 0; i < gEdge->getNumMeshElements(); i++) { MElement *mElem = gEdge->getMeshElement(i); assert(mElem->getNumVertices() == 3); elementsIt its; - for (its = _jointElements.begin(); its != _jointElements.end(); its++){ + for(its = _jointElements.begin(); its != _jointElements.end(); its++) { assert((*its)->getNumVertices() == 3); - // the MElements are considered the same if the quadratic node is the same - if ((*its)->getVertex(2) == mElem->getVertex(2)){ + // the MElements are considered the same if the quadratic node is the + // same + if((*its)->getVertex(2) == mElem->getVertex(2)) { break; } } - if (its != _jointElements.end()){ - Msg::Warning("Element edge %d appears in a second GEntity", mElem->getNum()); + if(its != _jointElements.end()) { + Msg::Warning("Element edge %d appears in a second GEntity", + mElem->getNum()); continue; } - // the MElements are considered connected if the quadratic node is connected - std::set < MVertex* >::iterator its2 = allConnectedQuadraticVertices.find - (mElem->getVertex(2)); - if (its2 == allConnectedQuadraticVertices.end()){ - Msg::Warning("Element edge %d seams to be not connected, it will be ignored", - mElem->getNum()); + // the MElements are considered connected if the quadratic node is + // connected + std::set<MVertex *>::iterator its2 = + allConnectedQuadraticVertices.find(mElem->getVertex(2)); + if(its2 == allConnectedQuadraticVertices.end()) { + Msg::Warning( + "Element edge %d seams to be not connected, it will be ignored", + mElem->getNum()); continue; } _jointElements.insert(mElem); - for(std::size_t j = 0; j < mElem->getNumVertices(); j++){ + for(std::size_t j = 0; j < mElem->getNumVertices(); j++) { MVertex *mVert = mElem->getVertex(j); _fissureByHeavNode[mVert] = gEdge; } @@ -283,16 +290,17 @@ void GMSH_FaultZoneMesher::RetriveFissuresInfos(GFace* gFace){ _vectNormByFissure[gEdge] = vectNorm; // fill _fissuresByJunctionNode and _vectsTanByJunctionNode - std::map < MVertex* , GEdge* >::iterator itm = _fissureByHeavNode.find(mVertexBegin); - if (itm != _fissureByHeavNode.end()){ + std::map<MVertex *, GEdge *>::iterator itm = + _fissureByHeavNode.find(mVertexBegin); + if(itm != _fissureByHeavNode.end()) { _fissuresByJunctionNode[mVertexBegin].push_back(gEdge); - _vectsTanByJunctionNode[mVertexBegin].push_back( vectTanBegin ); + _vectsTanByJunctionNode[mVertexBegin].push_back(vectTanBegin); _fissureByHeavNode.erase(mVertexBegin); } itm = _fissureByHeavNode.find(mVertexEnd); - if (itm != _fissureByHeavNode.end()){ - _fissuresByJunctionNode[mVertexEnd].push_back( gEdge ); - _vectsTanByJunctionNode[mVertexEnd].push_back( vectTanEnd ); + if(itm != _fissureByHeavNode.end()) { + _fissuresByJunctionNode[mVertexEnd].push_back(gEdge); + _vectsTanByJunctionNode[mVertexEnd].push_back(vectTanEnd); _fissureByHeavNode.erase(mVertexEnd); } } @@ -302,7 +310,7 @@ void GMSH_FaultZoneMesher::RetriveFissuresInfos(GFace* gFace){ /*! * \brief vectZ */ -const SVector3 GMSH_FaultZoneMesher::vectZ = SVector3(0,0,1); +const SVector3 GMSH_FaultZoneMesher::vectZ = SVector3(0, 0, 1); //================================================================================ /*! @@ -310,7 +318,6 @@ const SVector3 GMSH_FaultZoneMesher::vectZ = SVector3(0,0,1); */ const double GMSH_FaultZoneMesher::tolerance = 1.e-12; - //================================================================================ /*! * \brief duplicates nodes of the embedded edges to model the joints @@ -324,25 +331,27 @@ const double GMSH_FaultZoneMesher::tolerance = 1.e-12; * will be done in the CreateJointElements function. */ //================================================================================ -void GMSH_FaultZoneMesher::DuplicateNodes(){ - +void GMSH_FaultZoneMesher::DuplicateNodes() +{ // fill _nodeJointByHeavOrJunctionNode and _nodesByJunctionNode - for(std::map<MVertex*,std::vector<GEdge*> >::iterator itm = - _fissuresByJunctionNode.begin();itm != _fissuresByJunctionNode.end();){ + for(std::map<MVertex *, std::vector<GEdge *> >::iterator itm = + _fissuresByJunctionNode.begin(); + itm != _fissuresByJunctionNode.end();) { MVertex *mVert = itm->first; - std::vector < GEdge* > fissures = itm->second; + std::vector<GEdge *> fissures = itm->second; unsigned int nbFiss = fissures.size(); - if (nbFiss == 1){ // if only one fissure, the node will be treated in _fissureByHeavNode + if(nbFiss == 1) { // if only one fissure, the node will be treated in + // _fissureByHeavNode _fissureByHeavNode[mVert] = fissures.front(); _vectsTanByTipNode[mVert] = _vectsTanByJunctionNode[mVert][0]; _vectsTanByJunctionNode.erase(mVert); _fissuresByJunctionNode.erase(itm++); } - else{ - std::vector < MVertex* > mVertices; + else { + std::vector<MVertex *> mVertices; mVertices.push_back(mVert); - for (unsigned int i = 0; i < nbFiss-1; i++){ + for(unsigned int i = 0; i < nbFiss - 1; i++) { MVertex *mVertJonc = new MVertex(mVert->x(), mVert->y(), mVert->z()); mVertices.push_back(mVertJonc); } @@ -355,10 +364,10 @@ void GMSH_FaultZoneMesher::DuplicateNodes(){ } // fill _nodeJointByHeavOrJunctionNode and _nodeByHeavNode - for(std::map<MVertex*,GEdge*>::iterator itm=_fissureByHeavNode.begin(); - itm != _fissureByHeavNode.end(); itm++){ + for(std::map<MVertex *, GEdge *>::iterator itm = _fissureByHeavNode.begin(); + itm != _fissureByHeavNode.end(); itm++) { MVertex *mVert = itm->first; - if (mVert->getPolynomialOrder() == 1){ + if(mVert->getPolynomialOrder() == 1) { MVertex *mVertJoint; mVertJoint = new MVertex(mVert->x(), mVert->y(), mVert->z()); mVertJoint->setPolynomialOrder(2); @@ -368,7 +377,6 @@ void GMSH_FaultZoneMesher::DuplicateNodes(){ mVertHeav = new MVertex(mVert->x(), mVert->y(), mVert->z()); _nodeByHeavNode[mVert] = mVertHeav; } - } //================================================================================ @@ -385,28 +393,30 @@ void GMSH_FaultZoneMesher::DuplicateNodes(){ * 0 (undeterminate, can be upper or under). */ //================================================================================ -void GMSH_FaultZoneMesher::ComputeHeavisideFunction(){ - - for (std::map<MVertex*,std::vector<GEdge*> >::iterator itm = - _fissuresByJunctionNode.begin(); itm != _fissuresByJunctionNode.end(); itm++){ +void GMSH_FaultZoneMesher::ComputeHeavisideFunction() +{ + for(std::map<MVertex *, std::vector<GEdge *> >::iterator itm = + _fissuresByJunctionNode.begin(); + itm != _fissuresByJunctionNode.end(); itm++) { MVertex *mVert = itm->first; - std::vector < GEdge* > fissures = itm->second; + std::vector<GEdge *> fissures = itm->second; unsigned int size = fissures.size(); assert(size >= 2); - std::vector < SVector3 > vectsTan = _vectsTanByJunctionNode[mVert]; + std::vector<SVector3> vectsTan = _vectsTanByJunctionNode[mVert]; assert(vectsTan.size() == size); - std::vector < SVector3 > vectsNor; - for (std::vector<GEdge*>::iterator itl = fissures.begin(); itl != fissures.end(); itl++){ + std::vector<SVector3> vectsNor; + for(std::vector<GEdge *>::iterator itl = fissures.begin(); + itl != fissures.end(); itl++) { vectsNor.push_back(_vectNormByFissure[*itl]); } assert(vectsNor.size() == size); - std::vector < std::vector< int> > heavFunc; + std::vector<std::vector<int> > heavFunc; - for (unsigned int i=0; i < size; i++){ - std::vector < int > heav(size, 0); + for(unsigned int i = 0; i < size; i++) { + std::vector<int> heav(size, 0); - if (i == 0){ + if(i == 0) { heavFunc.insert(heavFunc.begin(), heav); continue; } @@ -414,26 +424,26 @@ void GMSH_FaultZoneMesher::ComputeHeavisideFunction(){ // upper = 1, under = -1, both = 0 bool upper = false; bool under = false; - for (unsigned int j=0; j<i; j++){ + for(unsigned int j = 0; j < i; j++) { double lsn = -dot(vectsNor[i], vectsTan[j]); upper = (upper || lsn > tolerance); under = (under || lsn < -tolerance); } - if (!under) heav[i] = 1; - if (under && !upper) heav[i] = -1; + if(!under) heav[i] = 1; + if(under && !upper) heav[i] = -1; // compute the heaviside functions of the precedent fissures for a point // located on fissure i - for (unsigned int j=0; j < i;j++){ + for(unsigned int j = 0; j < i; j++) { double lsn = -dot(vectsNor[j], vectsTan[i]); - if (fabs(lsn) < tolerance){ - lsn = dot(vectsNor[j], vectsNor[i])*heav[i]; + if(fabs(lsn) < tolerance) { + lsn = dot(vectsNor[j], vectsNor[i]) * heav[i]; assert(fabs(lsn) > tolerance || heav[i] == 0); } heav[j] = gmsh_sign(lsn); } - if (heav[i] != 0){ + if(heav[i] != 0) { // add the new domain on the side where the precedent fissure are // // Fissure2 @@ -448,7 +458,7 @@ void GMSH_FaultZoneMesher::ComputeHeavisideFunction(){ // heavFunc.insert(heavFunc.begin(), heav); } - else{ + else { // find the domain where the fissure i is and duplicates it with value // -1 and +1 for the fissure i // @@ -468,12 +478,12 @@ void GMSH_FaultZoneMesher::ComputeHeavisideFunction(){ // Fissure2 // bool isDomain = false; - for (unsigned int j=0; j < i;j++){ + for(unsigned int j = 0; j < i; j++) { isDomain = compareHeav(heavFunc[j], heav); - if (isDomain){ - heavFunc.insert(heavFunc.begin()+j, heavFunc[j]); + if(isDomain) { + heavFunc.insert(heavFunc.begin() + j, heavFunc[j]); heavFunc[j][i] = -1; - heavFunc[j+1][i] = 1; + heavFunc[j + 1][i] = 1; break; } } @@ -486,44 +496,45 @@ void GMSH_FaultZoneMesher::ComputeHeavisideFunction(){ //================================================================================ /*! - * \brief Return the value of the heaviside function associated to mVert evaluated - * on point sPoint. + * \brief Return the value of the heaviside function associated to mVert + * evaluated on point sPoint. */ //================================================================================ -std::vector < int > GMSH_FaultZoneMesher::HeavisideFunc(MVertex* mVert, SPoint3& sPoint){ - +std::vector<int> GMSH_FaultZoneMesher::HeavisideFunc(MVertex *mVert, + SPoint3 &sPoint) +{ SVector3 vectPoint = SVector3(mVert->point(), sPoint); double norm = vectPoint.normalize(); if(!norm) Msg::Error("norm == 0 in Plugin(FaultZone)"); - std::vector < int > heav; - if (_nodeByHeavNode.find( mVert ) != _nodeByHeavNode.end()){ + std::vector<int> heav; + if(_nodeByHeavNode.find(mVert) != _nodeByHeavNode.end()) { // if it is a pure heaviside node SVector3 vectNorm = _vectNormByFissure[_fissureByHeavNode[mVert]]; double lsn = dot(vectPoint, vectNorm); - if (fabs(lsn) < tolerance){ + if(fabs(lsn) < tolerance) { // verify the point is outside the fissure - assert(_vectsTanByTipNode.find( mVert ) != _vectsTanByTipNode.end()); + assert(_vectsTanByTipNode.find(mVert) != _vectsTanByTipNode.end()); SVector3 vectTan = _vectsTanByTipNode[mVert]; assert(dot(vectPoint, vectTan) > 0); lsn = 0; } heav.push_back(gmsh_sign(lsn)); } - else if (_nodesByJunctionNode.find( mVert ) != _nodesByJunctionNode.end()){ + else if(_nodesByJunctionNode.find(mVert) != _nodesByJunctionNode.end()) { // if it is a junction node - std::vector < GEdge* > fissures = _fissuresByJunctionNode[mVert]; + std::vector<GEdge *> fissures = _fissuresByJunctionNode[mVert]; unsigned int size = fissures.size(); - for (unsigned int i=0; i < size; i++){ + for(unsigned int i = 0; i < size; i++) { SVector3 vectNorm = _vectNormByFissure[fissures[i]]; double lsn = dot(vectPoint, vectNorm); - if (fabs(lsn) > tolerance) // tolerance seems to be ok + if(fabs(lsn) > tolerance) // tolerance seems to be ok heav.push_back(gmsh_sign(lsn)); else heav.push_back(0); } } - else// if it is not a heaviside node + else // if it is not a heaviside node assert(false); return heav; @@ -532,77 +543,79 @@ std::vector < int > GMSH_FaultZoneMesher::HeavisideFunc(MVertex* mVert, SPoint3& //================================================================================ /*! * \brief create joint Elements. For each element in the embedded edges, - * a corresponding face element is created, based on the nodes of the edge element. - * additionnal nodes are picked in the _nodeJointByHeavOrJunctionNode, - * _nodeByHeavNode and _nodesByJunctionNode maps. In case of _nodesByJunctionNode, - * the _heavFuncByJunctionNode map is used to found the corresponding node. + * a corresponding face element is created, based on the nodes of the edge + * element. additionnal nodes are picked in the _nodeJointByHeavOrJunctionNode, + * _nodeByHeavNode and _nodesByJunctionNode maps. In case of + * _nodesByJunctionNode, the _heavFuncByJunctionNode map is used to found the + * corresponding node. * * this function also replace physical edges containning the embedded edges by * new corresponding physical faces */ //================================================================================ -void GMSH_FaultZoneMesher::CreateJointElements(GModel* gModel, GFace* gFace, - std::string prefix){ - - std::vector<GEdge*> const& embeddedEdges = gFace->embeddedEdges(); - std::map < int , int > discreteFaceEntityByEmbeddedEdgeEntity; - for(std::vector<GEdge*>::const_iterator itl = embeddedEdges.begin(); - itl != embeddedEdges.end(); ++itl){ +void GMSH_FaultZoneMesher::CreateJointElements(GModel *gModel, GFace *gFace, + std::string prefix) +{ + std::vector<GEdge *> const &embeddedEdges = gFace->embeddedEdges(); + std::map<int, int> discreteFaceEntityByEmbeddedEdgeEntity; + for(std::vector<GEdge *>::const_iterator itl = embeddedEdges.begin(); + itl != embeddedEdges.end(); ++itl) { GEdge *gEdge = *itl; - if (gEdge->length() == 0)// nothing to do if there is no element + if(gEdge->length() == 0) // nothing to do if there is no element continue; // creation of a new GFace - GFace *jointFace = new discreteFace(gModel, gModel->getMaxElementaryNumber(2) + 1); + GFace *jointFace = + new discreteFace(gModel, gModel->getMaxElementaryNumber(2) + 1); discreteFaceEntityByEmbeddedEdgeEntity[gEdge->tag()] = jointFace->tag(); gModel->add(jointFace); - // for each MElement in the GEdge, a new MElement is created and inserted in GFace - for(unsigned int i = 0; i < gEdge->getNumMeshElements(); i++){ + // for each MElement in the GEdge, a new MElement is created and inserted in + // GFace + for(unsigned int i = 0; i < gEdge->getNumMeshElements(); i++) { MElement *mElem = gEdge->getMeshElement(i); elementsIt its = _jointElements.find(mElem); - if (its == _jointElements.end()) - continue; + if(its == _jointElements.end()) continue; SPoint3 bary = mElem->barycenter(); - std::vector<MVertex*> mVerts(8, (MVertex*)0); + std::vector<MVertex *> mVerts(8, (MVertex *)0); // check orientation SVector3 nor = _vectNormByFissure[gEdge]; SVector3 tan = mElem->getEdge(0).tangent(); int changeOri = (dot(crossprod(nor, tan), vectZ) > 0); - if (changeOri) + if(changeOri) Msg::Warning("Reverting local numbering node for element %d to set " "outgoing normal for its corresponding joint element", mElem->getNum()); // retriving MVertices to create the new MElement - for(std::size_t i = 0; i < mElem->getNumVertices(); i++){ + for(std::size_t i = 0; i < mElem->getNumVertices(); i++) { MVertex *mVert = mElem->getVertex(i); int j = (changeOri && i < 2) ? !i : i; - if (j < 2) // adding intern node + if(j < 2) // adding intern node mVerts[_numNodeJoint[j]] = _nodeJointByHeavOrJunctionNode[mVert]; - if (_nodeByHeavNode.find(mVert) != _nodeByHeavNode.end()){ + if(_nodeByHeavNode.find(mVert) != _nodeByHeavNode.end()) { // adding upper and under nodes mVerts[_numNodeHeavInf[j]] = mVert; mVerts[_numNodeHeavSup[j]] = _nodeByHeavNode[mVert]; } - else{ - std::vector < int > heav = HeavisideFunc(mVert, bary); + else { + std::vector<int> heav = HeavisideFunc(mVert, bary); unsigned int size = heav.size(); assert(size > 1); - std::vector < GEdge* > fissures = _fissuresByJunctionNode[mVert]; - assert (fissures.size() == size); - std::vector <std::vector< int > > heavFunc = _heavFuncByJunctionNode[mVert]; - assert (heavFunc.size() == size); - std::vector < MVertex*> nodes = _nodesByJunctionNode[mVert]; - assert (nodes.size() == size); + std::vector<GEdge *> fissures = _fissuresByJunctionNode[mVert]; + assert(fissures.size() == size); + std::vector<std::vector<int> > heavFunc = + _heavFuncByJunctionNode[mVert]; + assert(heavFunc.size() == size); + std::vector<MVertex *> nodes = _nodesByJunctionNode[mVert]; + assert(nodes.size() == size); unsigned int k; - for (k=0; k < size; k++){ - if (fissures[k]->tag() == gEdge->tag()) - break; + for(k = 0; k < size; k++) { + if(fissures[k]->tag() == gEdge->tag()) break; } assert(k < size); @@ -611,23 +624,24 @@ void GMSH_FaultZoneMesher::CreateJointElements(GModel* gModel, GFace* gFace, mVerts[_numNodeHeavInf[j]] = nodes[findMatchingHeav(heavFunc, heav)]; // adding upper node - heav[k] = 1; + heav[k] = 1; mVerts[_numNodeHeavSup[j]] = nodes[findMatchingHeav(heavFunc, heav)]; } } // association of the MVertices (created in function DuplicateNodes) to // the new GEntity (created here) - for(int j =0; j<8; j++){ + for(int j = 0; j < 8; j++) { MVertex *mVert = mVerts[j]; assert(mVert != NULL); - if (mVert->onWhat() == 0){ + if(mVert->onWhat() == 0) { mVert->setEntity(jointFace); jointFace->addMeshVertex(mVert); } } // creation of the new MElement and push into the new GEntity - MQuadrangle8* mQuad8 = new MQuadrangle8(mVerts[0], mVerts[1], mVerts[2], mVerts[3], - mVerts[4], mVerts[5], mVerts[6], mVerts[7]); + MQuadrangle8 *mQuad8 = + new MQuadrangle8(mVerts[0], mVerts[1], mVerts[2], mVerts[3], mVerts[4], + mVerts[5], mVerts[6], mVerts[7]); jointFace->quadrangles.push_back(mQuad8); } // hide gEdge and set lenght to zero to detect that this edge was treated @@ -635,46 +649,46 @@ void GMSH_FaultZoneMesher::CreateJointElements(GModel* gModel, GFace* gFace, gEdge->setLength(0); } - // replace physical edges by physical surfaces + // replace physical edges by physical surfaces #if 1 // FIXME this is wrong !?! - for(int i = 0; i < List_Nbr(gModel->getGEOInternals()->PhysicalGroups); i++){ - PhysicalGroup *p = *(PhysicalGroup**)List_Pointer - (GModel::current()->getGEOInternals()->PhysicalGroups, i); - if(p->Typ == MSH_PHYSICAL_LINE){ + for(int i = 0; i < List_Nbr(gModel->getGEOInternals()->PhysicalGroups); i++) { + PhysicalGroup *p = *(PhysicalGroup **)List_Pointer( + GModel::current()->getGEOInternals()->PhysicalGroups, i); + if(p->Typ == MSH_PHYSICAL_LINE) { List_T *faceEntities = List_Create(2, 1, sizeof(int)); - for(int j = 0; j < List_Nbr(p->Entities); j++){ + for(int j = 0; j < List_Nbr(p->Entities); j++) { int num; List_Read(p->Entities, j, &num); - std::map < int ,int >::iterator itm = + std::map<int, int>::iterator itm = discreteFaceEntityByEmbeddedEdgeEntity.find(num); - if (itm != discreteFaceEntityByEmbeddedEdgeEntity.end()){ + if(itm != discreteFaceEntityByEmbeddedEdgeEntity.end()) { List_Add(faceEntities, &itm->second); } } - if (List_Nbr(faceEntities) > 0){ + if(List_Nbr(faceEntities) > 0) { std::stringstream sufix; sufix << p->Num; int t = GModel::current()->getGEOInternals()->getMaxPhysicalTag(); GModel::current()->getGEOInternals()->setMaxPhysicalTag(t + 1); - int num = gModel->setPhysicalName(prefix+sufix.str(), 2, t + 1); - PhysicalGroup *pnew = CreatePhysicalGroup(num, MSH_PHYSICAL_SURFACE, faceEntities); + int num = gModel->setPhysicalName(prefix + sufix.str(), 2, t + 1); + PhysicalGroup *pnew = + CreatePhysicalGroup(num, MSH_PHYSICAL_SURFACE, faceEntities); List_Add(gModel->getGEOInternals()->PhysicalGroups, &pnew); - for(int j = 0; j < List_Nbr(faceEntities); j++){ + for(int j = 0; j < List_Nbr(faceEntities); j++) { int num; List_Read(faceEntities, j, &num); - GFace* gFace = gModel->getFaceByTag(num); + GFace *gFace = gModel->getFaceByTag(num); gFace->physicals.push_back(pnew->Num); } List_Remove(gModel->getGEOInternals()->PhysicalGroups, i); gModel->removePhysicalGroup(1, p->Num); - i-=1; + i -= 1; } List_Delete(faceEntities); } } #endif - } //================================================================================ @@ -691,42 +705,45 @@ const int GMSH_FaultZoneMesher::_numNodeHeavSup[3] = {3, 2, 6}; /*! * \brief corresponding quad8 node number to seg3 node number for middle side */ -const int GMSH_FaultZoneMesher::_numNodeJoint[2] = {7, 5}; +const int GMSH_FaultZoneMesher::_numNodeJoint[2] = {7, 5}; //================================================================================ /*! - * \brief modify the connectivity of face elements connected to the joint elements - * to take into account the duplicates nodes. Nodes are picked in the _nodeByHeavNode - * and _nodesByJunctionNode maps. In case of _nodesByJunctionNode, the - * _heavFuncByJunctionNode map is used to determinate the corresponding node. + * \brief modify the connectivity of face elements connected to the joint + * elements to take into account the duplicates nodes. Nodes are picked in the + * _nodeByHeavNode and _nodesByJunctionNode maps. In case of + * _nodesByJunctionNode, the _heavFuncByJunctionNode map is used to determinate + * the corresponding node. */ //================================================================================ -void GMSH_FaultZoneMesher::ModifyElementsConnectivity(GFace* gFace){ - +void GMSH_FaultZoneMesher::ModifyElementsConnectivity(GFace *gFace) +{ // modif connectivity in _connectedElements - for(elementsIt its = _connectedElements.begin();its != _connectedElements.end(); ++its){ + for(elementsIt its = _connectedElements.begin(); + its != _connectedElements.end(); ++its) { MElement *mElem = *its; SPoint3 bary = mElem->barycenter(); - std::vector<MVertex*> mVerts; + std::vector<MVertex *> mVerts; mElem->getVertices(mVerts); - for (unsigned j = 0; j < mVerts.size(); j++){ + for(unsigned j = 0; j < mVerts.size(); j++) { MVertex *mVert = mVerts[j]; - if (_nodeByHeavNode.find( mVert ) == _nodeByHeavNode.end() && - _nodesByJunctionNode.find( mVert ) == _nodesByJunctionNode.end()) + if(_nodeByHeavNode.find(mVert) == _nodeByHeavNode.end() && + _nodesByJunctionNode.find(mVert) == _nodesByJunctionNode.end()) continue; - std::vector < int > heav = HeavisideFunc(mVert, bary); + std::vector<int> heav = HeavisideFunc(mVert, bary); unsigned int size = heav.size(); - if (size == 1){ // if it is a pure heaviside node - if (heav[0] == 1) // modifying connectivity only if upper side + if(size == 1) { // if it is a pure heaviside node + if(heav[0] == 1) // modifying connectivity only if upper side mElem->setVertex(j, _nodeByHeavNode[mVert]); } - else{ // if it is a junction node - std::vector <std::vector< int > > heavFunc = _heavFuncByJunctionNode[mVert]; - assert (heavFunc.size() == size); + else { // if it is a junction node + std::vector<std::vector<int> > heavFunc = + _heavFuncByJunctionNode[mVert]; + assert(heavFunc.size() == size); int i = findMatchingHeav(heavFunc, heav); - std::vector < MVertex*> nodes = _nodesByJunctionNode[mVert]; - assert (nodes.size() == size); + std::vector<MVertex *> nodes = _nodesByJunctionNode[mVert]; + assert(nodes.size() == size); assert(nodes[i]->onWhat() != 0); mElem->setVertex(j, nodes[i]); } @@ -736,17 +753,17 @@ void GMSH_FaultZoneMesher::ModifyElementsConnectivity(GFace* gFace){ //================================================================================ /*! - * \brief modify node positions of the joint elements with distance eps. This function - * is optional, it give a thickness to the joint elements that helps to view the joint - * elements appear on the mesh. - * Nodes in the _nodeByHeavNode and _nodesByJunctionNode maps are moved. + * \brief modify node positions of the joint elements with distance eps. This + * function is optional, it give a thickness to the joint elements that helps to + * view the joint elements appear on the mesh. Nodes in the _nodeByHeavNode and + * _nodesByJunctionNode maps are moved. */ //================================================================================ -void GMSH_FaultZoneMesher::ModifyJointNodePosition(double eps){ - +void GMSH_FaultZoneMesher::ModifyJointNodePosition(double eps) +{ // for pure heaviside nodes - for (std::map<MVertex*,MVertex*>::iterator itm = _nodeByHeavNode.begin(); - itm != _nodeByHeavNode.end(); itm++){ + for(std::map<MVertex *, MVertex *>::iterator itm = _nodeByHeavNode.begin(); + itm != _nodeByHeavNode.end(); itm++) { // under side MVertex *mVert = itm->first; SVector3 vectNorm = _vectNormByFissure[_fissureByHeavNode[mVert]]; @@ -762,43 +779,44 @@ void GMSH_FaultZoneMesher::ModifyJointNodePosition(double eps){ } // for junction nodes - std::map < MVertex*, std::set < MElement* > > connectedElementsByJunctionNode; - for (std::map<MVertex*,std::vector<MVertex*> >::iterator itm = - _nodesByJunctionNode.begin(); itm != _nodesByJunctionNode.end(); itm++){ - std::vector < MVertex* > nodes = itm->second; - for (unsigned int i=0; i< nodes.size(); i++){ - std::set < MElement* > mElements; + std::map<MVertex *, std::set<MElement *> > connectedElementsByJunctionNode; + for(std::map<MVertex *, std::vector<MVertex *> >::iterator itm = + _nodesByJunctionNode.begin(); + itm != _nodesByJunctionNode.end(); itm++) { + std::vector<MVertex *> nodes = itm->second; + for(unsigned int i = 0; i < nodes.size(); i++) { + std::set<MElement *> mElements; connectedElementsByJunctionNode[nodes[i]] = mElements; } } - std::map<MVertex*,std::set<MElement*> >::iterator itm; + std::map<MVertex *, std::set<MElement *> >::iterator itm; for(elementsIt its = _connectedElements.begin(); - its != _connectedElements.end(); ++its){ + its != _connectedElements.end(); ++its) { MElement *mElem = *its; - std::vector<MVertex*> mVerts; + std::vector<MVertex *> mVerts; mElem->getVertices(mVerts); - for (unsigned j = 0; j < mVerts.size(); j++){ - itm = connectedElementsByJunctionNode.find( mVerts[j] ); - if (itm != connectedElementsByJunctionNode.end()){ + for(unsigned j = 0; j < mVerts.size(); j++) { + itm = connectedElementsByJunctionNode.find(mVerts[j]); + if(itm != connectedElementsByJunctionNode.end()) { itm->second.insert(mElem); } } } - for (itm = connectedElementsByJunctionNode.begin(); - itm != connectedElementsByJunctionNode.end(); itm++){ + for(itm = connectedElementsByJunctionNode.begin(); + itm != connectedElementsByJunctionNode.end(); itm++) { MVertex *mVert = itm->first; SPoint3 point = mVert->point(); - std::set < MElement* > mElements = itm->second; + std::set<MElement *> mElements = itm->second; assert(mElements.size() > 0); - SVector3 vect = SVector3(0,0,0); - for (std::set < MElement* >::iterator its = mElements.begin(); - its != mElements.end(); its++){ + SVector3 vect = SVector3(0, 0, 0); + for(std::set<MElement *>::iterator its = mElements.begin(); + its != mElements.end(); its++) { MElement *mElem = *its; SPoint3 bary = mElem->barycenter(); - SVector3 vectPointBary = SVector3(point, bary)*fabs(mElem->getVolume()); + SVector3 vectPointBary = SVector3(point, bary) * fabs(mElem->getVolume()); vect += vectPointBary; } vect.normalize(); diff --git a/Plugin/FaultZone.h b/Plugin/FaultZone.h index 2ef47273af396bed3971da723e839c8b9ce6816f..9b7ddea7f6c44d3764cc095c7784032b75e7b930 100644 --- a/Plugin/FaultZone.h +++ b/Plugin/FaultZone.h @@ -15,22 +15,21 @@ class GFace; class MVertex; class MElement; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterFaultZonePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterFaultZonePlugin(); } -class GMSH_FaultZonePlugin : public GMSH_PostPlugin{ - public: - GMSH_FaultZonePlugin(){} +class GMSH_FaultZonePlugin : public GMSH_PostPlugin { +public: + GMSH_FaultZonePlugin() {} std::string getName() const { return "FaultZone"; } - std::string getShortHelp() const{ return "FaultZone generator"; } + std::string getShortHelp() const { return "FaultZone generator"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; StringXString *getOptionStr(int iopt); - PView* execute(PView*); + PView *execute(PView *); }; //============================================================================= @@ -38,34 +37,36 @@ class GMSH_FaultZonePlugin : public GMSH_PostPlugin{ * \brief This class creates joint elements over the embedded edges of a GFace */ //============================================================================= -class GMSH_FaultZoneMesher{ - public: - GMSH_FaultZoneMesher(){} - void RetriveFissuresInfos(GFace* gFace); +class GMSH_FaultZoneMesher { +public: + GMSH_FaultZoneMesher() {} + void RetriveFissuresInfos(GFace *gFace); void DuplicateNodes(); void ComputeHeavisideFunction(); - void CreateJointElements(GModel* gModel, GFace* gFace, const std::string prefix); - void ModifyElementsConnectivity(GFace* gFace); + void CreateJointElements(GModel *gModel, GFace *gFace, + const std::string prefix); + void ModifyElementsConnectivity(GFace *gFace); void ModifyJointNodePosition(const double eps); - private: - std::set < MElement* > _jointElements; - std::map < GEdge* , SVector3 > _vectNormByFissure; - std::map < MVertex* , GEdge* > _fissureByHeavNode; - std::map < MVertex* , std::vector < GEdge* > > _fissuresByJunctionNode; - std::map < MVertex* , std::vector < SVector3 > > _vectsTanByJunctionNode; - std::set < MElement* > _connectedElements; - typedef std::set<MElement*>::iterator elementsIt; + +private: + std::set<MElement *> _jointElements; + std::map<GEdge *, SVector3> _vectNormByFissure; + std::map<MVertex *, GEdge *> _fissureByHeavNode; + std::map<MVertex *, std::vector<GEdge *> > _fissuresByJunctionNode; + std::map<MVertex *, std::vector<SVector3> > _vectsTanByJunctionNode; + std::set<MElement *> _connectedElements; + typedef std::set<MElement *>::iterator elementsIt; static const SVector3 vectZ; static const double tolerance; - std::map < MVertex* , SVector3 > _vectsTanByTipNode; - std::map < MVertex*, MVertex* > _nodeByHeavNode; - std::map < MVertex*, MVertex* > _nodeJointByHeavOrJunctionNode; - std::map < MVertex*, std::vector < MVertex*> > _nodesByJunctionNode; + std::map<MVertex *, SVector3> _vectsTanByTipNode; + std::map<MVertex *, MVertex *> _nodeByHeavNode; + std::map<MVertex *, MVertex *> _nodeJointByHeavOrJunctionNode; + std::map<MVertex *, std::vector<MVertex *> > _nodesByJunctionNode; - std::map < MVertex*, std::vector <std::vector< int > > > _heavFuncByJunctionNode; + std::map<MVertex *, std::vector<std::vector<int> > > _heavFuncByJunctionNode; - std::vector < int > HeavisideFunc(MVertex* mVert, SPoint3& sPoint); + std::vector<int> HeavisideFunc(MVertex *mVert, SPoint3 &sPoint); static const int _numNodeHeavInf[3]; static const int _numNodeHeavSup[3]; @@ -77,10 +78,12 @@ class GMSH_FaultZoneMesher{ * \brief Compare two heaviside functions */ //============================================================================= -inline bool compareHeav(const std::vector< int > heav1, const std::vector< int > heav2){ +inline bool compareHeav(const std::vector<int> heav1, + const std::vector<int> heav2) +{ assert(heav1.size() >= heav2.size()); - for (unsigned int i=0; i< heav2.size(); i++){ - if (heav1[i] != 0 && heav1[i] != heav2[i] && heav2[i] != 0){ + for(unsigned int i = 0; i < heav2.size(); i++) { + if(heav1[i] != 0 && heav1[i] != heav2[i] && heav2[i] != 0) { return false; } } @@ -92,12 +95,13 @@ inline bool compareHeav(const std::vector< int > heav1, const std::vector< int > * \brief Find the matching heaviside function heav, in the vector heavFunc */ //============================================================================= -inline int findMatchingHeav(const std::vector< std::vector < int > >& heavFunc, - const std::vector< int >& heav){ - unsigned int i=0; - for (; i < heavFunc.size();i++) +inline int findMatchingHeav(const std::vector<std::vector<int> > &heavFunc, + const std::vector<int> &heav) +{ + unsigned int i = 0; + for(; i < heavFunc.size(); i++) if(compareHeav(heavFunc[i], heav)) break; - assert(i<heavFunc.size()); + assert(i < heavFunc.size()); return i; } diff --git a/Plugin/FieldFromAmplitudePhase.cpp b/Plugin/FieldFromAmplitudePhase.cpp index 4db7934a4b7a55c6192cd60b5dc64b7eb1291802..1f3713222929601d0a6537056102ec3029c3ba80 100644 --- a/Plugin/FieldFromAmplitudePhase.cpp +++ b/Plugin/FieldFromAmplitudePhase.cpp @@ -11,7 +11,6 @@ #include "OctreePost.h" #include "FieldFromAmplitudePhase.h" - StringXNumber FieldFromAmplitudePhaseOptions_Number[] = { {GMSH_FULLRC, "Wavenumber", NULL, 5.}, {GMSH_FULLRC, "AmplitudeView", NULL, 0.}, @@ -19,26 +18,24 @@ StringXNumber FieldFromAmplitudePhaseOptions_Number[] = { }; StringXString FieldFromAmplitudePhaseOptions_String[] = { - {GMSH_FULLRC, "MeshFile", NULL, "fine.msh"} -}; - + {GMSH_FULLRC, "MeshFile", NULL, "fine.msh"}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterFieldFromAmplitudePhasePlugin() { - GMSH_Plugin *GMSH_RegisterFieldFromAmplitudePhasePlugin() - { - return new GMSH_FieldFromAmplitudePhasePlugin(); - } + return new GMSH_FieldFromAmplitudePhasePlugin(); +} } std::string GMSH_FieldFromAmplitudePhasePlugin::getHelp() const { return "Plugin(FieldFromAmplitudePhase) builds a complex field 'u' from " - "amplitude 'a' (complex) and phase 'phi' given in two different 'Views' " - "u = a * exp(k*phi), with k the wavenumber. \n\n" - "The result is to be interpolated in a sufficiently fine mesh: " - "'MeshFile'. \n\n" - "Plugin(FieldFromAmplitudePhase) generates one new view."; + "amplitude 'a' (complex) and phase 'phi' given in two different " + "'Views' " + "u = a * exp(k*phi), with k the wavenumber. \n\n" + "The result is to be interpolated in a sufficiently fine mesh: " + "'MeshFile'. \n\n" + "Plugin(FieldFromAmplitudePhase) generates one new view."; } int GMSH_FieldFromAmplitudePhasePlugin::getNbOptions() const @@ -63,80 +60,83 @@ StringXString *GMSH_FieldFromAmplitudePhasePlugin::getOptionStr(int iopt) PView *GMSH_FieldFromAmplitudePhasePlugin::execute(PView *v) { - double k = (double)FieldFromAmplitudePhaseOptions_Number[0].def; - int aView = (int)FieldFromAmplitudePhaseOptions_Number[1].def; + double k = (double)FieldFromAmplitudePhaseOptions_Number[0].def; + int aView = (int)FieldFromAmplitudePhaseOptions_Number[1].def; int phiView = (int)FieldFromAmplitudePhaseOptions_Number[2].def; std::string fileName = FieldFromAmplitudePhaseOptions_String[0].def; - std::string name_model("") ; + std::string name_model(""); - if(fileName==""){ + if(fileName == "") { Msg::Info("Could not find mesh file for interpolating U=A*exp(j*k*phi)." - " Trying to use current model mesh, instead.") ; - name_model = GModel::current()->getName() ; - fileName = name_model + ".msh" ; + " Trying to use current model mesh, instead."); + name_model = GModel::current()->getName(); + fileName = name_model + ".msh"; } PView *va = getView(aView, v); if(!va) return v; PViewData *aData = va->getData(); - if(aData->getNumTimeSteps() != 2){ + if(aData->getNumTimeSteps() != 2) { Msg::Error("Invalid number of time steps for AView, it must be complex!"); - return v ; + return v; } PView *vphi = getView(phiView, v); - if(!vphi){ - Msg::Error("FieldFromAmplitudePhase plugin could not find PhiView %i", phiView); + if(!vphi) { + Msg::Error("FieldFromAmplitudePhase plugin could not find PhiView %i", + phiView); return v; } PViewData *phiData = vphi->getData(); - if(aData->hasMultipleMeshes() || phiData->hasMultipleMeshes()){ - Msg::Error("FieldFromAmplitudePhase plugin cannot be run on multi-mesh views"); + if(aData->hasMultipleMeshes() || phiData->hasMultipleMeshes()) { + Msg::Error( + "FieldFromAmplitudePhase plugin cannot be run on multi-mesh views"); return v; } - OctreePost *oA = 0, *oPhi = 0 ; + OctreePost *oA = 0, *oPhi = 0; oA = new OctreePost(va); oPhi = new OctreePost(vphi); GModel::current()->setVisibility(0); - GModel *umodel = new GModel ; - umodel->readMSH(fileName) ; - std::vector<GEntity*> _entities ; - umodel->getEntities(_entities) ; + GModel *umodel = new GModel; + umodel->readMSH(fileName); + std::vector<GEntity *> _entities; + umodel->getEntities(_entities); - std::set<MVertex*> ve; - std::map<int, std::vector<double> > dataR ; - std::map<int, std::vector<double> > dataI ; + std::set<MVertex *> ve; + std::map<int, std::vector<double> > dataR; + std::map<int, std::vector<double> > dataI; for(unsigned int ent = 0; ent < _entities.size(); ent++) - for(unsigned int ele = 0; ele < _entities[ent]->getNumMeshElements(); ele++){ + for(unsigned int ele = 0; ele < _entities[ent]->getNumMeshElements(); + ele++) { MElement *e = _entities[ent]->getMeshElement(ele); - for(std::size_t nod = 0; nod < e->getNumVertices() ; nod++) + for(std::size_t nod = 0; nod < e->getNumVertices(); nod++) ve.insert(e->getVertex(nod)); } - for (std::set<MVertex*>::iterator it = ve.begin(); it != ve.end(); ++it){ - double phi, ar, ai ; - std::vector<double> uR(1) ; - std::vector<double> uI(1) ; + for(std::set<MVertex *>::iterator it = ve.begin(); it != ve.end(); ++it) { + double phi, ar, ai; + std::vector<double> uR(1); + std::vector<double> uI(1); oPhi->searchScalarWithTol((*it)->x(), (*it)->y(), (*it)->z(), &phi, 0); oA->searchScalarWithTol((*it)->x(), (*it)->y(), (*it)->z(), &ar, 0); oA->searchScalarWithTol((*it)->x(), (*it)->y(), (*it)->z(), &ai, 1); - uR[0] = ar * cos(k*phi) - ai * sin(k*phi) ; - uI[0] = ar * sin(k*phi) + ai* cos(k*phi) ; + uR[0] = ar * cos(k * phi) - ai * sin(k * phi); + uI[0] = ar * sin(k * phi) + ai * cos(k * phi); - dataR[(*it)->getNum()] = uR ; - dataI[(*it)->getNum()] = uI ; + dataR[(*it)->getNum()] = uR; + dataI[(*it)->getNum()] = uI; } - delete oA ; + delete oA; delete oPhi; - PView *vu = new PView("FieldFromAPhi", "NodeData", umodel, dataR, 0.0, 1) ; + PView *vu = new PView("FieldFromAPhi", "NodeData", umodel, dataR, 0.0, 1); vu->addStep(umodel, dataI, 1); if(name_model.empty()) diff --git a/Plugin/FieldFromAmplitudePhase.h b/Plugin/FieldFromAmplitudePhase.h index c55ffc39e7fa276a772c485da5bdb2ca7e5ec132..8919fd07b40790220bc4fb4bd9b9e31f9b9490eb 100644 --- a/Plugin/FieldFromAmplitudePhase.h +++ b/Plugin/FieldFromAmplitudePhase.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterFieldFromAmplitudePhasePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterFieldFromAmplitudePhasePlugin(); } -class GMSH_FieldFromAmplitudePhasePlugin : public GMSH_PostPlugin -{ - public: - GMSH_FieldFromAmplitudePhasePlugin(){} +class GMSH_FieldFromAmplitudePhasePlugin : public GMSH_PostPlugin { +public: + GMSH_FieldFromAmplitudePhasePlugin() {} std::string getName() const { return "FieldFromAmplitudePhase"; } std::string getShortHelp() const { @@ -26,7 +24,7 @@ class GMSH_FieldFromAmplitudePhasePlugin : public GMSH_PostPlugin int getNbOptions() const; StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); }; diff --git a/Plugin/GaussPoints.cpp b/Plugin/GaussPoints.cpp index 66c033035535bd1eeaec6dcd4bcb654be43df722..3ebc11815e8d64881b915231d562a3bc9b5adc34 100644 --- a/Plugin/GaussPoints.cpp +++ b/Plugin/GaussPoints.cpp @@ -11,15 +11,13 @@ StringXNumber GaussPointsOptions_Number[] = { {GMSH_FULLRC, "Order", NULL, 0}, {GMSH_FULLRC, "Dimension", NULL, 2}, - {GMSH_FULLRC, "PhysicalGroup", NULL, 0} -}; + {GMSH_FULLRC, "PhysicalGroup", NULL, 0}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterGaussPointsPlugin() { - GMSH_Plugin *GMSH_RegisterGaussPointsPlugin() - { - return new GMSH_GaussPointsPlugin(); - } + return new GMSH_GaussPointsPlugin(); +} } int GMSH_GaussPointsPlugin::getNbOptions() const @@ -35,45 +33,47 @@ StringXNumber *GMSH_GaussPointsPlugin::getOption(int iopt) std::string GMSH_GaussPointsPlugin::getHelp() const { return "Given an input mesh, Plugin(GaussPoints) creates a view containing " - "the Gauss points for a given polynomial `Order'.\n\n" - "If `PhysicalGroup' is nonzero, the plugin only creates points for the " - "elements belonging to the group."; + "the Gauss points for a given polynomial `Order'.\n\n" + "If `PhysicalGroup' is nonzero, the plugin only creates points for " + "the " + "elements belonging to the group."; } -PView* GMSH_GaussPointsPlugin::execute(PView *v) +PView *GMSH_GaussPointsPlugin::execute(PView *v) { int order = (int)GaussPointsOptions_Number[0].def; int dim = (int)GaussPointsOptions_Number[1].def; int physical = (int)GaussPointsOptions_Number[2].def; GModel *m = GModel::current(); - std::vector<GEntity*> entities; - if(physical){ - std::map<int, std::vector<GEntity*> > groups[4]; + std::vector<GEntity *> entities; + if(physical) { + std::map<int, std::vector<GEntity *> > groups[4]; m->getPhysicalGroups(groups); entities = groups[dim][physical]; } - else{ + else { m->getEntities(entities, dim); } - if(entities.empty()){ + if(entities.empty()) { Msg::Error("No entities"); return v; } PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) { MElement *e = entities[i]->getMeshElement(j); - int npts; IntPt *gp; + int npts; + IntPt *gp; e->getIntegrationPoints(order, &npts, &gp); - for (int i = 0; i < npts; i++){ + for(int i = 0; i < npts; i++) { double u = gp[i].pt[0]; double v = gp[i].pt[1]; double w = gp[i].pt[2]; - //double weight = gp[i].weight; + // double weight = gp[i].weight; SPoint3 p; e->pnt(u, v, w, p); data2->SP.push_back(p.x()); diff --git a/Plugin/GaussPoints.h b/Plugin/GaussPoints.h index 14430346cc126eda0c3e934cc4a2ef54698075f0..34dd4c7fcef1e12029fb3b91baf88407baf850e1 100644 --- a/Plugin/GaussPoints.h +++ b/Plugin/GaussPoints.h @@ -8,24 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterGaussPointsPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterGaussPointsPlugin(); } - -class GMSH_GaussPointsPlugin : public GMSH_PostPlugin -{ - public: - GMSH_GaussPointsPlugin(){} +class GMSH_GaussPointsPlugin : public GMSH_PostPlugin { +public: + GMSH_GaussPointsPlugin() {} std::string getName() const { return "GaussPoints"; } - std::string getShortHelp() const - { - return "Gauss points"; - } + std::string getShortHelp() const { return "Gauss points"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Gradient.cpp b/Plugin/Gradient.cpp index 7f681cf71a1f7726c66dbf2452597d8e060b7c15..2a0af546752e5f0828de194fc47e8dfa129c10b7 100644 --- a/Plugin/Gradient.cpp +++ b/Plugin/Gradient.cpp @@ -7,24 +7,18 @@ #include "shapeFunctions.h" #include "GmshDefines.h" -StringXNumber GradientOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.} -}; +StringXNumber GradientOptions_Number[] = {{GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterGradientPlugin() - { - return new GMSH_GradientPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterGradientPlugin() { return new GMSH_GradientPlugin(); } } std::string GMSH_GradientPlugin::getHelp() const { return "Plugin(Gradient) computes the gradient of the " - "field in the view `View'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Gradient) creates one new view."; + "field in the view `View'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Gradient) creates one new view."; } int GMSH_GradientPlugin::getNbOptions() const @@ -45,27 +39,30 @@ PView *GMSH_GradientPlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = getPossiblyAdaptiveData(v1); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("Gradient plugin cannot be run on multi-mesh views"); return v; } PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); + int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); - for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++){ - for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++) { + for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); + ele++) { if(data1->skipElement(firstNonEmptyStep, ent, ele)) continue; int numComp = data1->getNumComponents(firstNonEmptyStep, ent, ele); if(numComp != 1 && numComp != 3) continue; int type = data1->getType(firstNonEmptyStep, ent, ele); int numNodes = data1->getNumNodes(firstNonEmptyStep, ent, ele); - std::vector<double> *out = data2->incrementList((numComp == 1) ? 3 : 9, type, numNodes); + std::vector<double> *out = + data2->incrementList((numComp == 1) ? 3 : 9, type, numNodes); if(!out) continue; double x[8], y[8], z[8], val[8 * 3]; for(int nod = 0; nod < numNodes; nod++) - data1->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], z[nod]); + data1->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], + z[nod]); int dim = data1->getDimension(firstNonEmptyStep, ent, ele); elementFactory factory; element *element = factory.create(numNodes, dim, x, y, z); @@ -73,15 +70,16 @@ PView *GMSH_GradientPlugin::execute(PView *v) for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); - for(int step = 0; step < data1->getNumTimeSteps(); step++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { if(!data1->hasTimeStep(step)) continue; for(int nod = 0; nod < numNodes; nod++) for(int comp = 0; comp < numComp; comp++) - data1->getValue(step, ent, ele, nod, comp, val[numComp * nod + comp]); - for(int nod = 0; nod < numNodes; nod++){ + data1->getValue(step, ent, ele, nod, comp, + val[numComp * nod + comp]); + for(int nod = 0; nod < numNodes; nod++) { double u, v, w, f[3]; element->getNode(nod, u, v, w); - for(int comp = 0; comp < numComp; comp++){ + for(int comp = 0; comp < numComp; comp++) { element->interpolateGrad(val + comp, u, v, w, f, numComp); out->push_back(f[0]); out->push_back(f[1]); @@ -93,7 +91,7 @@ PView *GMSH_GradientPlugin::execute(PView *v) } } - for(int i = 0; i < data1->getNumTimeSteps(); i++){ + for(int i = 0; i < data1->getNumTimeSteps(); i++) { if(!data1->hasTimeStep(i)) continue; double time = data1->getTime(i); data2->Time.push_back(time); diff --git a/Plugin/Gradient.h b/Plugin/Gradient.h index 21906e91711e612fee79bc3bb03c569fcf44cb8c..9d2b8addcc6f7ae9c5ba425f52620df2ac4ddab3 100644 --- a/Plugin/Gradient.h +++ b/Plugin/Gradient.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterGradientPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterGradientPlugin(); } -class GMSH_GradientPlugin : public GMSH_PostPlugin -{ - public: - GMSH_GradientPlugin(){} +class GMSH_GradientPlugin : public GMSH_PostPlugin { +public: + GMSH_GradientPlugin() {} std::string getName() const { return "Gradient"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_GradientPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/HarmonicToTime.cpp b/Plugin/HarmonicToTime.cpp index 3a67998d7699625cef245c07864a12b3860c7dd3..8483d4c4ac78ef26bb57a306dcfb1c55298e94af 100644 --- a/Plugin/HarmonicToTime.cpp +++ b/Plugin/HarmonicToTime.cpp @@ -13,30 +13,28 @@ StringXNumber HarmonicToTimeOptions_Number[] = { {GMSH_FULLRC, "TimeSign", NULL, -1.}, {GMSH_FULLRC, "Frequency", NULL, 1}, {GMSH_FULLRC, "NumPeriods", NULL, 1}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterHarmonicToTimePlugin() { - GMSH_Plugin *GMSH_RegisterHarmonicToTimePlugin() - { - return new GMSH_HarmonicToTimePlugin(); - } + return new GMSH_HarmonicToTimePlugin(); +} } std::string GMSH_HarmonicToTimePlugin::getHelp() const { return "Plugin(HarmonicToTime) takes the values in the " - "time steps `RealPart' and `ImaginaryPart' of " - "the view `View', and creates a new view " - "containing\n\n" - "`View'[`RealPart'] * cos(p) +- `View'[`ImaginaryPart'] * sin(p)\n" - "with\n p = 2*Pi*k/`NumSteps', k = 0, ..., `NumSteps'-1\n" - "and 'NumSteps' the total number of time steps\n" - "over 'NumPeriods' periods at frequency 'Frequency' [Hz].\n" - "The '+' sign is used if `TimeSign'>0, the '-' sign otherwise.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(HarmonicToTime) creates one new view."; + "time steps `RealPart' and `ImaginaryPart' of " + "the view `View', and creates a new view " + "containing\n\n" + "`View'[`RealPart'] * cos(p) +- `View'[`ImaginaryPart'] * sin(p)\n" + "with\n p = 2*Pi*k/`NumSteps', k = 0, ..., `NumSteps'-1\n" + "and 'NumSteps' the total number of time steps\n" + "over 'NumPeriods' periods at frequency 'Frequency' [Hz].\n" + "The '+' sign is used if `TimeSign'>0, the '-' sign otherwise.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(HarmonicToTime) creates one new view."; } int GMSH_HarmonicToTimePlugin::getNbOptions() const @@ -49,7 +47,7 @@ StringXNumber *GMSH_HarmonicToTimePlugin::getOption(int iopt) return &HarmonicToTimeOptions_Number[iopt]; } -PView *GMSH_HarmonicToTimePlugin::execute(PView * v) +PView *GMSH_HarmonicToTimePlugin::execute(PView *v) { int rIndex = (int)HarmonicToTimeOptions_Number[0].def; int iIndex = (int)HarmonicToTimeOptions_Number[1].def; @@ -63,22 +61,22 @@ PView *GMSH_HarmonicToTimePlugin::execute(PView * v) if(!v1) return v; PViewData *data1 = v1->getData(true); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("HarmonicToTime plugin cannot be applied to multi-mesh views"); return v1; } - if(frequency==0){ + if(frequency == 0) { Msg::Error("HarmonicToTime plugin: null frequency is forbidden"); return v1; } - if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || - iIndex < 0 || iIndex >= data1->getNumTimeSteps()){ + if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || iIndex < 0 || + iIndex >= data1->getNumTimeSteps()) { Msg::Error("Wrong real or imaginary part index"); return v1; } - if(nSteps <= 0){ + if(nSteps <= 0) { Msg::Error("nSteps should be > 0"); return v1; } @@ -86,8 +84,8 @@ PView *GMSH_HarmonicToTimePlugin::execute(PView * v) PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - for(int ent = 0; ent < data1->getNumEntities(0); ent++){ - for(int ele = 0; ele < data1->getNumElements(0, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(0); ent++) { + for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) { if(data1->skipElement(0, ent, ele)) continue; int numNodes = data1->getNumNodes(0, ent, ele); int type = data1->getType(0, ent, ele); @@ -95,11 +93,13 @@ PView *GMSH_HarmonicToTimePlugin::execute(PView * v) std::vector<double> *out = data2->incrementList(numComp, type, numNodes); std::vector<double> x(numNodes), y(numNodes), z(numNodes); std::vector<double> vr(numNodes * numComp), vi(numNodes * numComp); - for(int nod = 0; nod < numNodes; nod++){ + for(int nod = 0; nod < numNodes; nod++) { data1->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]); - for(int comp = 0; comp < numComp; comp++){ - data1->getValue(rIndex, ent, ele, nod, comp, vr[numComp * nod + comp]); - data1->getValue(iIndex, ent, ele, nod, comp, vi[numComp * nod + comp]); + for(int comp = 0; comp < numComp; comp++) { + data1->getValue(rIndex, ent, ele, nod, comp, + vr[numComp * nod + comp]); + data1->getValue(iIndex, ent, ele, nod, comp, + vi[numComp * nod + comp]); } } for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); @@ -109,9 +109,8 @@ PView *GMSH_HarmonicToTimePlugin::execute(PView * v) double p = 2. * M_PI * nPeriods * k / nSteps; for(int nod = 0; nod < numNodes; nod++) { for(int comp = 0; comp < numComp; comp++) { - double val = - vr[numComp * nod + comp] * cos(p) + tsign * - vi[numComp * nod + comp] * sin(p); + double val = vr[numComp * nod + comp] * cos(p) + + tsign * vi[numComp * nod + comp] * sin(p); out->push_back(val); } } @@ -119,7 +118,7 @@ PView *GMSH_HarmonicToTimePlugin::execute(PView * v) } } - for(int k = 0; k < nSteps; k++){ + for(int k = 0; k < nSteps; k++) { double t = 2. * M_PI * nPeriods * k / frequency / (double)nSteps; data2->Time.push_back(t); } diff --git a/Plugin/HarmonicToTime.h b/Plugin/HarmonicToTime.h index 02a2a55148e9f8e10349d666d506fd1d69e7217b..f0ebbc5f4192304e25067e097919419a0fabd9b8 100644 --- a/Plugin/HarmonicToTime.h +++ b/Plugin/HarmonicToTime.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterHarmonicToTimePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterHarmonicToTimePlugin(); } -class GMSH_HarmonicToTimePlugin : public GMSH_PostPlugin -{ - public: - GMSH_HarmonicToTimePlugin(){} +class GMSH_HarmonicToTimePlugin : public GMSH_PostPlugin { +public: + GMSH_HarmonicToTimePlugin() {} std::string getName() const { return "HarmonicToTime"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_HarmonicToTimePlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/HomologyComputation.cpp b/Plugin/HomologyComputation.cpp index 1bfb2d6cf2e2b646fb4bc828ca0ffd93e1bcc9d0..27e3051078eab5325fc00bc7ee678a67f90e53c9 100644 --- a/Plugin/HomologyComputation.cpp +++ b/Plugin/HomologyComputation.cpp @@ -26,37 +26,34 @@ StringXNumber HomologyComputationOptions_Number[] = { {GMSH_FULLRC, "ReductionOmit", NULL, 1.}, {GMSH_FULLRC, "ReductionCombine", NULL, 3.}, {GMSH_FULLRC, "PostProcessSimplify", NULL, 1.}, - {GMSH_FULLRC, "ReductionHeuristic", NULL, 1.} -}; + {GMSH_FULLRC, "ReductionHeuristic", NULL, 1.}}; StringXString HomologyComputationOptions_String[] = { {GMSH_FULLRC, "DomainPhysicalGroups", NULL, ""}, {GMSH_FULLRC, "SubdomainPhysicalGroups", NULL, ""}, {GMSH_FULLRC, "ReductionImmunePhysicalGroups", NULL, ""}, {GMSH_FULLRC, "DimensionOfChainsToSave", NULL, "0, 1, 2, 3"}, - {GMSH_FULLRC, "Filename", NULL, "homology.msh"} -}; + {GMSH_FULLRC, "Filename", NULL, "homology.msh"}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterHomologyComputationPlugin() { - GMSH_Plugin *GMSH_RegisterHomologyComputationPlugin() - { - return new GMSH_HomologyComputationPlugin(); - } + return new GMSH_HomologyComputationPlugin(); +} } std::string GMSH_HomologyComputationPlugin::getHelp() const { return "Plugin(HomologyComputation) computes representative chains " - "of basis elements of (relative) homology and cohomology spaces.\n\n" + "of basis elements of (relative) homology and cohomology spaces.\n\n" - "Define physical groups in order to specify the computation " - "domain and the relative subdomain. Otherwise the whole mesh " - "is the domain and the relative subdomain is empty. \n\n" + "Define physical groups in order to specify the computation " + "domain and the relative subdomain. Otherwise the whole mesh " + "is the domain and the relative subdomain is empty. \n\n" - "Plugin(HomologyComputation) creates new views, one for each " - "basis element. The resulting basis chains of desired dimension " - "together with the mesh are saved to the given file."; + "Plugin(HomologyComputation) creates new views, one for each " + "basis element. The resulting basis chains of desired dimension " + "together with the mesh are saved to the given file."; } int GMSH_HomologyComputationPlugin::getNbOptions() const @@ -79,8 +76,8 @@ StringXString *GMSH_HomologyComputationPlugin::getOptionStr(int iopt) return &HomologyComputationOptions_String[iopt]; } -bool GMSH_HomologyComputationPlugin::parseStringOpt -(int stringOpt, std::vector<int>& intList) +bool GMSH_HomologyComputationPlugin::parseStringOpt(int stringOpt, + std::vector<int> &intList) { std::string list = HomologyComputationOptions_String[stringOpt].def; intList.clear(); @@ -88,9 +85,9 @@ bool GMSH_HomologyComputationPlugin::parseStringOpt int n; char a; std::istringstream ss(list); - while(ss >> n){ + while(ss >> n) { intList.push_back(n); - if(ss >> a){ + if(ss >> a) { if(a != ',') { Msg::Error("Unexpected character \'%c\' while parsing \'%s\'", a, HomologyComputationOptions_String[stringOpt].str); @@ -123,10 +120,10 @@ PView *GMSH_HomologyComputationPlugin::execute(PView *v) if(!parseStringOpt(2, imdomain)) return 0; if(!parseStringOpt(3, dimsave)) return 0; - GModel* m = GModel::current(); + GModel *m = GModel::current(); - Homology* homology = new Homology(m, domain, subdomain, imdomain, - true, combine, omit, smoothen, heuristic); + Homology *homology = new Homology(m, domain, subdomain, imdomain, true, + combine, omit, smoothen, heuristic); homology->setFileName(fileName); if(hom != 0) homology->findHomologyBasis(dimsave); diff --git a/Plugin/HomologyComputation.h b/Plugin/HomologyComputation.h index 58311b48dcf987d043a4d8a7724238b88a5498bd..41272e1f208a5902a8a63909aa950f7b0782f318 100644 --- a/Plugin/HomologyComputation.h +++ b/Plugin/HomologyComputation.h @@ -13,15 +13,13 @@ #if defined(HAVE_KBIPACK) -extern "C" -{ - GMSH_Plugin *GMSH_RegisterHomologyComputationPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterHomologyComputationPlugin(); } -class GMSH_HomologyComputationPlugin : public GMSH_PostPlugin -{ - public: - GMSH_HomologyComputationPlugin(){} +class GMSH_HomologyComputationPlugin : public GMSH_PostPlugin { +public: + GMSH_HomologyComputationPlugin() {} std::string getName() const { return "HomologyComputation"; } std::string getShortHelp() const { @@ -34,7 +32,7 @@ class GMSH_HomologyComputationPlugin : public GMSH_PostPlugin int getNbOptionsStr() const; StringXString *getOptionStr(int iopt); PView *execute(PView *); - bool parseStringOpt(int stringOpt, std::vector<int>& intList); + bool parseStringOpt(int stringOpt, std::vector<int> &intList); }; #endif diff --git a/Plugin/HomologyPostProcessing.cpp b/Plugin/HomologyPostProcessing.cpp index 87a837a80cf5623d82bc68cf7c8c8a36fc9ad86a..b3625bec01c22eca031f5726426cee19cdb1e0d2 100644 --- a/Plugin/HomologyPostProcessing.cpp +++ b/Plugin/HomologyPostProcessing.cpp @@ -18,8 +18,7 @@ #if defined(HAVE_KBIPACK) StringXNumber HomologyPostProcessingOptions_Number[] = { - {GMSH_FULLRC, "ApplyBoundaryOperatorToResults", NULL, 0} -}; + {GMSH_FULLRC, "ApplyBoundaryOperatorToResults", NULL, 0}}; StringXString HomologyPostProcessingOptions_String[] = { {GMSH_FULLRC, "TransformationMatrix", NULL, "1, 0; 0, 1"}, @@ -30,36 +29,44 @@ StringXString HomologyPostProcessingOptions_String[] = { {GMSH_FULLRC, "NameForResultChains", NULL, "c"}, }; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterHomologyPostProcessingPlugin() { - GMSH_Plugin *GMSH_RegisterHomologyPostProcessingPlugin() - { - return new GMSH_HomologyPostProcessingPlugin(); - } + return new GMSH_HomologyPostProcessingPlugin(); +} } std::string GMSH_HomologyPostProcessingPlugin::getHelp() const { return "Plugin(HomologyPostProcessing) operates on representative " - "basis chains of homology and cohomology spaces. Functionality:\n\n" - - "1. (co)homology basis transformation:\n " - "'TransformationMatrix': Integer matrix of the transformation.\n " - "'PhysicalGroupsOfOperatedChains': (Co)chains of a (co)homology space basis to be transformed.\n " - "Results a new (co)chain basis that is an integer cobination of the given basis. \n\n" - - "2. Make basis representations of a homology space and a cohomology space " - "compatible: \n" - "'PhysicalGroupsOfOperatedChains': Chains of a homology space basis.\n" - "'PhysicalGroupsOfOperatedChains2': Cochains of a cohomology space basis.\n" - "Results a new basis for the homology space such that the incidence matrix of the new basis and the basis of the cohomology space is the identity matrix.\n\n" - - "Options:\n" - "'PhysicalGroupsToTraceResults': Trace the resulting (co)chains to the given physical groups.\n" - "'PhysicalGroupsToProjectResults': Project the resulting (co)chains to the complement of the given physical groups.\n" - "'NameForResultChains': Post-processing view name prefix for the results.\n" - "'ApplyBoundaryOperatorToResults': Apply boundary operator to the resulting chains.\n"; - + "basis chains of homology and cohomology spaces. Functionality:\n\n" + + "1. (co)homology basis transformation:\n " + "'TransformationMatrix': Integer matrix of the transformation.\n " + "'PhysicalGroupsOfOperatedChains': (Co)chains of a (co)homology space " + "basis to be transformed.\n " + "Results a new (co)chain basis that is an integer cobination of the " + "given basis. \n\n" + + "2. Make basis representations of a homology space and a cohomology " + "space " + "compatible: \n" + "'PhysicalGroupsOfOperatedChains': Chains of a homology space basis.\n" + "'PhysicalGroupsOfOperatedChains2': Cochains of a cohomology space " + "basis.\n" + "Results a new basis for the homology space such that the incidence " + "matrix of the new basis and the basis of the cohomology space is the " + "identity matrix.\n\n" + + "Options:\n" + "'PhysicalGroupsToTraceResults': Trace the resulting (co)chains to " + "the given physical groups.\n" + "'PhysicalGroupsToProjectResults': Project the resulting (co)chains " + "to the complement of the given physical groups.\n" + "'NameForResultChains': Post-processing view name prefix for the " + "results.\n" + "'ApplyBoundaryOperatorToResults': Apply boundary operator to the " + "resulting chains.\n"; } int GMSH_HomologyPostProcessingPlugin::getNbOptions() const @@ -82,8 +89,8 @@ StringXString *GMSH_HomologyPostProcessingPlugin::getOptionStr(int iopt) return &HomologyPostProcessingOptions_String[iopt]; } -bool GMSH_HomologyPostProcessingPlugin::parseStringOpt -(int stringOpt, std::vector<int>& intList) +bool GMSH_HomologyPostProcessingPlugin::parseStringOpt( + int stringOpt, std::vector<int> &intList) { std::string list = HomologyPostProcessingOptions_String[stringOpt].def; intList.clear(); @@ -91,9 +98,9 @@ bool GMSH_HomologyPostProcessingPlugin::parseStringOpt int n; char a; std::istringstream ss(list); - while(ss >> n){ + while(ss >> n) { intList.push_back(n); - if(ss >> a){ + if(ss >> a) { if(a != ',') { Msg::Error("Unexpected character \'%c\' while parsing \'%s\'", a, HomologyPostProcessingOptions_String[stringOpt].str); @@ -104,35 +111,32 @@ bool GMSH_HomologyPostProcessingPlugin::parseStringOpt return true; } -int GMSH_HomologyPostProcessingPlugin::detIntegerMatrix -(std::vector<int>& matrix) +int GMSH_HomologyPostProcessingPlugin::detIntegerMatrix( + std::vector<int> &matrix) { int n = sqrt((double)matrix.size()); - fullMatrix<double> m(n,n); + fullMatrix<double> m(n, n); for(int i = 0; i < n; i++) - for(int j = 0; j < n; j++) - m(i,j) = matrix.at(i*n+j); + for(int j = 0; j < n; j++) m(i, j) = matrix.at(i * n + j); return m.determinant(); } -bool GMSH_HomologyPostProcessingPlugin::invertIntegerMatrix -(std::vector<int>& matrix) +bool GMSH_HomologyPostProcessingPlugin::invertIntegerMatrix( + std::vector<int> &matrix) { int n = sqrt((double)matrix.size()); - fullMatrix<double> m(n,n); + fullMatrix<double> m(n, n); for(int i = 0; i < n; i++) - for(int j = 0; j < n; j++) - m(i,j) = matrix.at(i*n+j); + for(int j = 0; j < n; j++) m(i, j) = matrix.at(i * n + j); - if(!m.invertInPlace()){ + if(!m.invertInPlace()) { Msg::Error("Matrix is not unimodular"); return false; } for(int i = 0; i < n; i++) - for(int j = 0; j < n; j++) - matrix.at(i*n+j) = m(i,j); + for(int j = 0; j < n; j++) matrix.at(i * n + j) = m(i, j); return true; } @@ -146,7 +150,7 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) std::string projectString = HomologyPostProcessingOptions_String[4].def; int bd = (int)HomologyPostProcessingOptions_Number[0].def; - GModel* m = GModel::current(); + GModel *m = GModel::current(); int n; char a; @@ -155,10 +159,10 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) std::vector<int> matrix; if(matrixString != "I") { std::istringstream ss(matrixString); - while(ss >> n){ + while(ss >> n) { matrix.push_back(n); col++; - if(ss >> a){ + if(ss >> a) { if(a != ',' && a != ';') { Msg::Error("Unexpected character \'%c\' while parsing \'%s\'", a, HomologyPostProcessingOptions_String[0].str); @@ -183,10 +187,11 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) int rows = 0; if(!matrix.empty()) { - rows = matrix.size()/cols; + rows = matrix.size() / cols; if((int)matrix.size() % cols != 0) { - Msg::Error("Number of matrix rows and columns aren't compatible (residual: %d)", - (int)matrix.size() % cols); + Msg::Error( + "Number of matrix rows and columns aren't compatible (residual: %d)", + (int)matrix.size() % cols); return 0; } } @@ -196,18 +201,18 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) std::vector<int> basisPhysicals2; if(!parseStringOpt(2, basisPhysicals2)) return 0; - if(matrixString != "I" && - (int)basisPhysicals.size() != cols && + if(matrixString != "I" && (int)basisPhysicals.size() != cols && basisPhysicals2.empty()) { - Msg::Error("Number of matrix columns and operated chains must match (%d != %d)", cols, basisPhysicals.size()); + Msg::Error( + "Number of matrix columns and operated chains must match (%d != %d)", + cols, basisPhysicals.size()); return 0; } else if(matrixString == "I") { cols = basisPhysicals.size(); rows = cols; - matrix = std::vector<int>(cols*cols, 0); - for(int i = 0; i < cols; i++) - matrix.at(i*cols+i) = 1; + matrix = std::vector<int>(cols * cols, 0); + for(int i = 0; i < cols; i++) matrix.at(i * cols + i) = 1; } if(!basisPhysicals2.empty() && @@ -223,7 +228,7 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) if(!parseStringOpt(4, projectPhysicals)) return 0; std::vector<Chain<int> > curBasis; - for(unsigned int i = 0; i < basisPhysicals.size(); i++){ + for(unsigned int i = 0; i < basisPhysicals.size(); i++) { curBasis.push_back(Chain<int>(m, basisPhysicals.at(i))); } if(curBasis.empty()) { @@ -233,17 +238,17 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) int dim = curBasis.at(0).getDim(); std::vector<Chain<int> > curBasis2; - for(unsigned int i = 0; i < basisPhysicals2.size(); i++){ + for(unsigned int i = 0; i < basisPhysicals2.size(); i++) { curBasis2.push_back(Chain<int>(m, basisPhysicals2.at(i))); } if(!curBasis2.empty()) { rows = curBasis2.size(); cols = curBasis.size(); - matrix = std::vector<int>(rows*cols, 0); + matrix = std::vector<int>(rows * cols, 0); for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) - matrix.at(i*cols+j) = incidence(curBasis2.at(i), curBasis.at(j)); + matrix.at(i * cols + j) = incidence(curBasis2.at(i), curBasis.at(j)); } if(!curBasis2.empty()) @@ -252,11 +257,12 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) Msg::Debug("Transformation matrix: "); for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) - Msg::Debug("(%d, %d) = %d", i, j, matrix.at(i*cols+j)); + Msg::Debug("(%d, %d) = %d", i, j, matrix.at(i * cols + j)); std::vector<Chain<int> > newBasis(rows, Chain<int>()); if(!curBasis2.empty()) { - Msg::Info("Computing new basis %d-chains such that the incidence matrix of %d-chain bases %s and %s is the indentity matrix", + Msg::Info("Computing new basis %d-chains such that the incidence matrix of " + "%d-chain bases %s and %s is the indentity matrix", dim, dim, opString1.c_str(), opString2.c_str()); int det = detIntegerMatrix(matrix); if(det != 1 && det != -1) @@ -264,7 +270,8 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) if(!invertIntegerMatrix(matrix)) return 0; for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) - newBasis.at(i) += matrix.at(i*cols+j)*curBasis2.at(j); } + newBasis.at(i) += matrix.at(i * cols + j) * curBasis2.at(j); + } else { Msg::Info("Applying transformation matrix [%s] to %d-chains %s", matrixString.c_str(), dim, opString1.c_str()); @@ -275,8 +282,7 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) } for(int i = 0; i < rows; i++) for(int j = 0; j < cols; j++) - newBasis.at(i) += matrix.at(i*cols+j)*curBasis.at(j); - + newBasis.at(i) += matrix.at(i * cols + j) * curBasis.at(j); } if(bd) { @@ -286,23 +292,24 @@ PView *GMSH_HomologyPostProcessingPlugin::execute(PView *v) } if(!tracePhysicals.empty()) { - Msg::Info("Taking trace of result %d-chains to domain %s", - dim, traceString.c_str()); + Msg::Info("Taking trace of result %d-chains to domain %s", dim, + traceString.c_str()); for(unsigned int i = 0; i < newBasis.size(); i++) newBasis.at(i) = newBasis.at(i).getTrace(m, tracePhysicals); } if(!projectPhysicals.empty()) { - Msg::Info("Taking projection of result %d-chains to the complement of the domain %s", dim, projectString.c_str()); + Msg::Info("Taking projection of result %d-chains to the complement of the " + "domain %s", + dim, projectString.c_str()); for(unsigned int i = 0; i < newBasis.size(); i++) newBasis.at(i) = newBasis.at(i).getProject(m, projectPhysicals); } if(!tracePhysicals.empty() || !projectPhysicals.empty()) ElemChain::clearVertexCache(); - for(unsigned int i = 0; i < newBasis.size(); i++) { std::string dims = convertInt(newBasis.at(i).getDim()); - std::string nums = convertInt(i+1); + std::string nums = convertInt(i + 1); newBasis.at(i).setName("C" + dims + " " + cname + nums); newBasis.at(i).addToModel(m); } diff --git a/Plugin/HomologyPostProcessing.h b/Plugin/HomologyPostProcessing.h index 71a889120bdeb03ef75ce583f208a6929473fd9f..35032c99c69df8cff5cc5d69909aa9c84bc3c4ad 100644 --- a/Plugin/HomologyPostProcessing.h +++ b/Plugin/HomologyPostProcessing.h @@ -14,15 +14,13 @@ #if defined(HAVE_KBIPACK) -extern "C" -{ - GMSH_Plugin *GMSH_RegisterHomologyPostProcessingPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterHomologyPostProcessingPlugin(); } -class GMSH_HomologyPostProcessingPlugin : public GMSH_PostPlugin -{ - public: - GMSH_HomologyPostProcessingPlugin(){} +class GMSH_HomologyPostProcessingPlugin : public GMSH_PostPlugin { +public: + GMSH_HomologyPostProcessingPlugin() {} std::string getName() const { return "HomologyPostProcessing"; } std::string getShortHelp() const { @@ -35,9 +33,9 @@ class GMSH_HomologyPostProcessingPlugin : public GMSH_PostPlugin int getNbOptionsStr() const; StringXString *getOptionStr(int iopt); PView *execute(PView *); - bool parseStringOpt(int stringOpt, std::vector<int>& intList); - bool invertIntegerMatrix(std::vector<int>& matrix); - int detIntegerMatrix(std::vector<int>& matrix); + bool parseStringOpt(int stringOpt, std::vector<int> &intList); + bool invertIntegerMatrix(std::vector<int> &matrix); + int detIntegerMatrix(std::vector<int> &matrix); }; #endif diff --git a/Plugin/Integrate.cpp b/Plugin/Integrate.cpp index 6785f1a31ccf86ae00f3f5f9288cfbd2151b1a47..5344c4c22cbfab6122cd7661b5ed2a1123b7a4bf 100644 --- a/Plugin/Integrate.cpp +++ b/Plugin/Integrate.cpp @@ -11,31 +11,29 @@ StringXNumber IntegrateOptions_Number[] = { {GMSH_FULLRC, "View", NULL, -1.}, {GMSH_FULLRC, "OverTime", NULL, -1.}, {GMSH_FULLRC, "Dimension", NULL, -1.}, - {GMSH_FULLRC, "Visible", NULL, 1.} -}; + {GMSH_FULLRC, "Visible", NULL, 1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterIntegratePlugin() { - GMSH_Plugin *GMSH_RegisterIntegratePlugin() - { - return new GMSH_IntegratePlugin(); - } + return new GMSH_IntegratePlugin(); +} } std::string GMSH_IntegratePlugin::getHelp() const { return "Plugin(Integrate) integrates a scalar field over " - "all the elements of the view `View' (if `Dimension' < 0), " - "or over all elements of the prescribed dimension " - "(if `Dimension' > 0). If the field is a vector field," - "the circulation/flux of the field over " - "line/surface elements is calculated.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "If `OverTime' = i > -1 , the plugin integrates the scalar view " - "over time instead of over space, starting at iteration i." - "If `Visible' = 1, the plugin only integrates over" - "visible entities.\n\n" - "Plugin(Integrate) creates one new view."; + "all the elements of the view `View' (if `Dimension' < 0), " + "or over all elements of the prescribed dimension " + "(if `Dimension' > 0). If the field is a vector field," + "the circulation/flux of the field over " + "line/surface elements is calculated.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "If `OverTime' = i > -1 , the plugin integrates the scalar view " + "over time instead of over space, starting at iteration i." + "If `Visible' = 1, the plugin only integrates over" + "visible entities.\n\n" + "Plugin(Integrate) creates one new view."; } int GMSH_IntegratePlugin::getNbOptions() const @@ -48,7 +46,7 @@ StringXNumber *GMSH_IntegratePlugin::getOption(int iopt) return &IntegrateOptions_Number[iopt]; } -PView *GMSH_IntegratePlugin::execute(PView * v) +PView *GMSH_IntegratePlugin::execute(PView *v) { int iView = (int)IntegrateOptions_Number[0].def; int overTime = (int)IntegrateOptions_Number[1].def; @@ -62,107 +60,109 @@ PView *GMSH_IntegratePlugin::execute(PView * v) PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - if (overTime == -1) { + if(overTime == -1) { double x = data1->getBoundingBox().center().x(); double y = data1->getBoundingBox().center().y(); double z = data1->getBoundingBox().center().z(); data2->SP.push_back(x); data2->SP.push_back(y); data2->SP.push_back(z); - for(int step = 0; step < data1->getNumTimeSteps(); step++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { double res = 0, resv[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; bool simpleSum = false; - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { if(visible && data1->skipEntity(step, ent)) continue; - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ - if(data1->skipElement(step, ent, ele, visible)) continue; - int numComp = data1->getNumComponents(step, ent, ele); - int numEdges = data1->getNumEdges(step, ent, ele); - bool scalar = (numComp == 1); - bool circulation = (numComp == 3 && numEdges == 1); - bool flux = (numComp == 3 && (numEdges == 3 || numEdges == 4)); - int numNodes = data1->getNumNodes(step, ent, ele); - int dim = data1->getDimension(step, ent, ele); - if((dimension>0) && (dim!=dimension)) continue; - double x[8], y[8], z[8], val[8 * 3] = {0.}; - for(int nod = 0; nod < numNodes; nod++){ - data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); - for(int comp = 0; comp < numComp; comp++) - data1->getValue(step, ent, ele, nod, comp, val[numComp * nod + comp]); - } - if(numNodes == 1){ - simpleSum = true; - res += val[0]; - for(int comp = 0; comp < numComp; comp++) - resv[comp] += val[comp]; - } - else{ - elementFactory factory; - element *element = factory.create(numNodes, dim, x, y, z); - if(!element) continue; - if(scalar) - res += element->integrate(val); - else if(circulation) - res += element->integrateCirculation(val); - else if(flux) - res += element->integrateFlux(val); - delete element; - } - } + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { + if(data1->skipElement(step, ent, ele, visible)) continue; + int numComp = data1->getNumComponents(step, ent, ele); + int numEdges = data1->getNumEdges(step, ent, ele); + bool scalar = (numComp == 1); + bool circulation = (numComp == 3 && numEdges == 1); + bool flux = (numComp == 3 && (numEdges == 3 || numEdges == 4)); + int numNodes = data1->getNumNodes(step, ent, ele); + int dim = data1->getDimension(step, ent, ele); + if((dimension > 0) && (dim != dimension)) continue; + double x[8], y[8], z[8], val[8 * 3] = {0.}; + for(int nod = 0; nod < numNodes; nod++) { + data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); + for(int comp = 0; comp < numComp; comp++) + data1->getValue(step, ent, ele, nod, comp, + val[numComp * nod + comp]); + } + if(numNodes == 1) { + simpleSum = true; + res += val[0]; + for(int comp = 0; comp < numComp; comp++) resv[comp] += val[comp]; + } + else { + elementFactory factory; + element *element = factory.create(numNodes, dim, x, y, z); + if(!element) continue; + if(scalar) + res += element->integrate(val); + else if(circulation) + res += element->integrateCirculation(val); + else if(flux) + res += element->integrateFlux(val); + delete element; + } + } } if(simpleSum) - Msg::Info("Step %d: sum = %g %g %g %g %g %g %g %g %g", step, resv[0], - resv[1], resv[2], resv[3], resv[4], resv[5], resv[6], resv[7], - resv[8]); + Msg::Info("Step %d: sum = %g %g %g %g %g %g %g %g %g", step, resv[0], + resv[1], resv[2], resv[3], resv[4], resv[5], resv[6], resv[7], + resv[8]); else - Msg::Info("Step %d: integral = %.16g", step, res); + Msg::Info("Step %d: integral = %.16g", step, res); data2->SP.push_back(res); } data2->NbSP = 1; v2->getOptions()->intervalsType = PViewOptions::Numeric; - for(int i = 0; i < data1->getNumTimeSteps(); i++){ + for(int i = 0; i < data1->getNumTimeSteps(); i++) { double time = data1->getTime(i); data2->Time.push_back(time); } - } - else{ + else { int timeBeg = data1->getFirstNonEmptyTimeStep(); int timeEnd = data1->getNumTimeSteps(); - for(int ent = 0; ent < data1->getNumEntities(timeBeg); ent++){ - for(int ele = 0; ele < data1->getNumElements(timeBeg, ent); ele++){ - if(data1->skipElement(timeBeg, ent, ele)) continue; - int dim = data1->getDimension(timeBeg, ent, ele); - if((dimension>0) && (dim!=dimension)) continue; - - int numNodes = data1->getNumNodes(timeBeg, ent, ele); - int type = data1->getType(timeBeg, ent, ele); - int numComp = data1->getNumComponents(timeBeg, ent, ele); - if (numComp != 1) Msg::Error("Can only integrate scalar views over time"); - std::vector<double> *out = data2->incrementList(numComp, type, numNodes); - std::vector<double> x(numNodes), y(numNodes), z(numNodes); - for(int nod = 0; nod < numNodes; nod++) - data1->getNode(timeBeg, ent, ele, nod, x[nod], y[nod], z[nod]); - for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); - for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); - for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); - - std::vector<double> timeIntegral(numNodes, 0.); - double time = (overTime > 0) ? data1->getTime(timeBeg+overTime-1) : 0.0; - for(int step = timeBeg + overTime; step < timeEnd; step++){ - if(!data1->hasTimeStep(step)) continue; - double newTime = data1->getTime(step); - double dt = newTime - time; - time = newTime; - for(int nod = 0; nod < numNodes; nod++){ - double val; - data1->getValue(step, ent, ele, nod, 0, val); - timeIntegral[nod] += val * dt; - } - } - for(int nod = 0; nod < numNodes; nod++) - out->push_back(timeIntegral[nod]); + for(int ent = 0; ent < data1->getNumEntities(timeBeg); ent++) { + for(int ele = 0; ele < data1->getNumElements(timeBeg, ent); ele++) { + if(data1->skipElement(timeBeg, ent, ele)) continue; + int dim = data1->getDimension(timeBeg, ent, ele); + if((dimension > 0) && (dim != dimension)) continue; + + int numNodes = data1->getNumNodes(timeBeg, ent, ele); + int type = data1->getType(timeBeg, ent, ele); + int numComp = data1->getNumComponents(timeBeg, ent, ele); + if(numComp != 1) + Msg::Error("Can only integrate scalar views over time"); + std::vector<double> *out = + data2->incrementList(numComp, type, numNodes); + std::vector<double> x(numNodes), y(numNodes), z(numNodes); + for(int nod = 0; nod < numNodes; nod++) + data1->getNode(timeBeg, ent, ele, nod, x[nod], y[nod], z[nod]); + for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); + for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); + for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); + + std::vector<double> timeIntegral(numNodes, 0.); + double time = + (overTime > 0) ? data1->getTime(timeBeg + overTime - 1) : 0.0; + for(int step = timeBeg + overTime; step < timeEnd; step++) { + if(!data1->hasTimeStep(step)) continue; + double newTime = data1->getTime(step); + double dt = newTime - time; + time = newTime; + for(int nod = 0; nod < numNodes; nod++) { + double val; + data1->getValue(step, ent, ele, nod, 0, val); + timeIntegral[nod] += val * dt; + } + } + for(int nod = 0; nod < numNodes; nod++) + out->push_back(timeIntegral[nod]); } } } diff --git a/Plugin/Integrate.h b/Plugin/Integrate.h index 4bca9a79ffb84264cf928e43c84559d935850457..92c7b39d85b0de5c5561c904c900792a9dace649 100644 --- a/Plugin/Integrate.h +++ b/Plugin/Integrate.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterIntegratePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterIntegratePlugin(); } -class GMSH_IntegratePlugin : public GMSH_PostPlugin -{ - public: - GMSH_IntegratePlugin(){} +class GMSH_IntegratePlugin : public GMSH_PostPlugin { +public: + GMSH_IntegratePlugin() {} std::string getName() const { return "Integrate"; } - std::string getShortHelp() const - { - return "Integrate data"; - } + std::string getShortHelp() const { return "Integrate data"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Isosurface.cpp b/Plugin/Isosurface.cpp index 2a4f84d3f8fb9eeb6ce4ccdfd086833fbf37774c..15d575a7d95749dc491b6c32e4185da4434fcebb 100644 --- a/Plugin/Isosurface.cpp +++ b/Plugin/Isosurface.cpp @@ -13,29 +13,27 @@ StringXNumber IsosurfaceOptions_Number[] = { {GMSH_FULLRC, "TargetError", GMSH_IsosurfacePlugin::callbackTarget, 0}, {GMSH_FULLRC, "View", NULL, -1.}, {GMSH_FULLRC, "OtherTimeStep", NULL, -1.}, - {GMSH_FULLRC, "OtherView", NULL, -1.} -}; + {GMSH_FULLRC, "OtherView", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterIsosurfacePlugin() { - GMSH_Plugin *GMSH_RegisterIsosurfacePlugin() - { - return new GMSH_IsosurfacePlugin(); - } + return new GMSH_IsosurfacePlugin(); +} } double GMSH_IsosurfacePlugin::callbackValue(int num, int action, double value) { double min = 0., max = 1.; - if(action > 0){ + if(action > 0) { int iview = (int)IsosurfaceOptions_Number[4].def; if(iview < 0) iview = num; - if(iview >= 0 && iview < (int)PView::list.size()){ + if(iview >= 0 && iview < (int)PView::list.size()) { min = PView::list[iview]->getData()->getMin(); max = PView::list[iview]->getData()->getMax(); } } - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return (min - max) / 200.; case 2: return min; case 3: return max; @@ -46,7 +44,7 @@ double GMSH_IsosurfacePlugin::callbackValue(int num, int action, double value) double GMSH_IsosurfacePlugin::callbackVol(int num, int action, double value) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return 1.; case 2: return -1.; case 3: return 1.; @@ -57,7 +55,7 @@ double GMSH_IsosurfacePlugin::callbackVol(int num, int action, double value) double GMSH_IsosurfacePlugin::callbackRecur(int num, int action, double value) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return 1.; case 2: return 0.; case 3: return 10.; @@ -68,7 +66,7 @@ double GMSH_IsosurfacePlugin::callbackRecur(int num, int action, double value) double GMSH_IsosurfacePlugin::callbackTarget(int num, int action, double value) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return 0.01; case 2: return 0.; case 3: return 1.; @@ -80,20 +78,20 @@ double GMSH_IsosurfacePlugin::callbackTarget(int num, int action, double value) std::string GMSH_IsosurfacePlugin::getHelp() const { return "Plugin(Isosurface) extracts the isosurface of value " - "`Value' from the view `View', and draws the " - "`OtherTimeStep'-th step of the view `OtherView' on " - "this isosurface.\n\n" - "If `ExtractVolume' is nonzero, the plugin extracts the " - "isovolume with values greater (if `ExtractVolume' > 0) " - "or smaller (if `ExtractVolume' < 0) than the isosurface " - "`Value'.\n\n" - "If `OtherTimeStep' < 0, the plugin uses, for each time " - "step in `View', the corresponding time step in `OtherView'. " - "If `OtherView' < 0, the plugin uses `View' as the value " - "source.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Isosurface) creates as many views as there are " - "time steps in `View'."; + "`Value' from the view `View', and draws the " + "`OtherTimeStep'-th step of the view `OtherView' on " + "this isosurface.\n\n" + "If `ExtractVolume' is nonzero, the plugin extracts the " + "isovolume with values greater (if `ExtractVolume' > 0) " + "or smaller (if `ExtractVolume' < 0) than the isosurface " + "`Value'.\n\n" + "If `OtherTimeStep' < 0, the plugin uses, for each time " + "step in `View', the corresponding time step in `OtherView'. " + "If `OtherView' < 0, the plugin uses `View' as the value " + "source.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Isosurface) creates as many views as there are " + "time steps in `View'."; } int GMSH_IsosurfacePlugin::getNbOptions() const @@ -106,7 +104,8 @@ StringXNumber *GMSH_IsosurfacePlugin::getOption(int iopt) return &IsosurfaceOptions_Number[iopt]; } -double GMSH_IsosurfacePlugin::levelset(double x, double y, double z, double val) const +double GMSH_IsosurfacePlugin::levelset(double x, double y, double z, + double val) const { // we must look into the map for Map(x,y,z) - Value // this is the case when the map is the same as the view, @@ -124,7 +123,7 @@ PView *GMSH_IsosurfacePlugin::execute(PView *v) _valueTimeStep = (int)IsosurfaceOptions_Number[5].def; _valueView = (int)IsosurfaceOptions_Number[6].def; _orientation = GMSH_LevelsetPlugin::MAP; - + PView *v1 = getView(iView, v); if(!v1) return v; diff --git a/Plugin/Isosurface.h b/Plugin/Isosurface.h index 260aabe1b7636b1df5c8b9536bea8ede131d8c8c..eba608aad360d4723e47ff56f13be72de0247b67 100644 --- a/Plugin/Isosurface.h +++ b/Plugin/Isosurface.h @@ -8,20 +8,16 @@ #include "Levelset.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterIsosurfacePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterIsosurfacePlugin(); } -class GMSH_IsosurfacePlugin : public GMSH_LevelsetPlugin -{ +class GMSH_IsosurfacePlugin : public GMSH_LevelsetPlugin { double levelset(double x, double y, double z, double val) const; - public: - GMSH_IsosurfacePlugin(){} - std::string getShortHelp() const - { - return "Extract a single isosurface"; - } + +public: + GMSH_IsosurfacePlugin() {} + std::string getShortHelp() const { return "Extract a single isosurface"; } std::string getName() const { return "Isosurface"; } std::string getHelp() const; int getNbOptions() const; diff --git a/Plugin/Lambda2.cpp b/Plugin/Lambda2.cpp index dbd9cac062a7d7a3671f0bdb2ab363b70d372d7b..2545317766a619597e1463afb8748e0aff3ad7df 100644 --- a/Plugin/Lambda2.cpp +++ b/Plugin/Lambda2.cpp @@ -6,37 +6,31 @@ #include "Lambda2.h" #include "Numeric.h" -StringXNumber Lambda2Options_Number[] = { - {GMSH_FULLRC, "Eigenvalue", NULL, 2.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; +StringXNumber Lambda2Options_Number[] = {{GMSH_FULLRC, "Eigenvalue", NULL, 2.}, + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterLambda2Plugin() - { - return new GMSH_Lambda2Plugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterLambda2Plugin() { return new GMSH_Lambda2Plugin(); } } std::string GMSH_Lambda2Plugin::getHelp() const { return "Plugin(Lambda2) computes the eigenvalues " - "Lambda(1,2,3) of the tensor (S_ik S_kj + " - "Om_ik Om_kj), where S_ij = 0.5 (ui,j + uj,i) " - "and Om_ij = 0.5 (ui,j - uj,i) are respectively " - "the symmetric and antisymmetric parts of the " - "velocity gradient tensor.\n\n" - "Vortices are well represented by regions where " - "Lambda(2) is negative.\n\n" - "If `View' contains tensor elements, the plugin " - "directly uses the tensors as the values of the " - "velocity gradient tensor; if `View' contains " - "vector elements, the plugin uses them as the " - "velocities from which to derive the velocity " - "gradient tensor.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Lambda2) creates one new view."; + "Lambda(1,2,3) of the tensor (S_ik S_kj + " + "Om_ik Om_kj), where S_ij = 0.5 (ui,j + uj,i) " + "and Om_ij = 0.5 (ui,j - uj,i) are respectively " + "the symmetric and antisymmetric parts of the " + "velocity gradient tensor.\n\n" + "Vortices are well represented by regions where " + "Lambda(2) is negative.\n\n" + "If `View' contains tensor elements, the plugin " + "directly uses the tensors as the values of the " + "velocity gradient tensor; if `View' contains " + "vector elements, the plugin uses them as the " + "velocities from which to derive the velocity " + "gradient tensor.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Lambda2) creates one new view."; } int GMSH_Lambda2Plugin::getNbOptions() const @@ -55,8 +49,7 @@ static int inv3x3tran(double mat[3][3], double inv[3][3], double *det) *det = det3x3(mat); - if(*det == 0.0) - return (0); + if(*det == 0.0) return (0); ud = 1. / (*det); @@ -72,50 +65,51 @@ static int inv3x3tran(double mat[3][3], double inv[3][3], double *det) return 1; } -static void eigen(std::vector<double> &inList, int inNb, - std::vector<double> &outList, int *outNb, - int nbTime, int nbNod, int nbComp, int lam) +static void eigen(std::vector<double> &inList, int inNb, + std::vector<double> &outList, int *outNb, int nbTime, + int nbNod, int nbComp, int lam) { - if(!inNb || (nbComp != 3 && nbComp != 9) || lam < 1 || lam > 3) - return; + if(!inNb || (nbComp != 3 && nbComp != 9) || lam < 1 || lam > 3) return; - // loop on elements + // loop on elements int nb = inList.size() / inNb; for(unsigned int i = 0; i < inList.size(); i += nb) { - // copy node coordinates - for(int j = 0; j < 3 * nbNod; j++) - outList.push_back(inList[i + j]); - - // loop on time steps - for(int j = 0; j < nbTime; j++){ + for(int j = 0; j < 3 * nbNod; j++) outList.push_back(inList[i + j]); + // loop on time steps + for(int j = 0; j < nbTime; j++) { double *x = &inList[i]; double *y = &inList[i + nbNod]; double *z = &inList[i + 2 * nbNod]; double GradVel[3][3]; - if(nbComp == 9) - { + if(nbComp == 9) { // val is the velocity gradient tensor: we assume that it is // constant per element double *v = &inList[i + 3 * nbNod + nbNod * nbComp * j + nbComp * 0]; - GradVel[0][0] = v[0]; GradVel[0][1] = v[1]; GradVel[0][2] = v[2]; - GradVel[1][0] = v[3]; GradVel[1][1] = v[4]; GradVel[1][2] = v[5]; - GradVel[2][0] = v[6]; GradVel[2][1] = v[7]; GradVel[2][2] = v[8]; + GradVel[0][0] = v[0]; + GradVel[0][1] = v[1]; + GradVel[0][2] = v[2]; + GradVel[1][0] = v[3]; + GradVel[1][1] = v[4]; + GradVel[1][2] = v[5]; + GradVel[2][0] = v[6]; + GradVel[2][1] = v[7]; + GradVel[2][2] = v[8]; } - else if(nbComp == 3){ + else if(nbComp == 3) { // FIXME: the following could be greatly simplified and // generalized by using the classes in shapeFunctions.h // val contains the velocities: compute the gradient tensor // from them - const int MAX_NOD = 4; + const int MAX_NOD = 4; double val[3][MAX_NOD]; - for(int k = 0; k < nbNod; k++){ + for(int k = 0; k < nbNod; k++) { double *v = &inList[i + 3 * nbNod + nbNod * nbComp * j + nbComp * k]; - for(int l = 0; l < 3; l++){ + for(int l = 0; l < 3; l++) { val[l][k] = v[l]; } } @@ -125,83 +119,110 @@ static void eigen(std::vector<double> &inList, int inNb, double dx_dksi[3][3]; double dksi_dx[3][3]; double det; - if(nbNod == 3){ // triangles + if(nbNod == 3) { // triangles double a[3], b[3], cross[3]; - a[0]= x[1]-x[0]; a[1]= y[1]-y[0]; a[2]= z[1]-z[0]; - b[0]= x[2]-x[0]; b[1]= y[2]-y[0]; b[2]= z[2]-z[0]; + a[0] = x[1] - x[0]; + a[1] = y[1] - y[0]; + a[2] = z[1] - z[0]; + b[0] = x[2] - x[0]; + b[1] = y[2] - y[0]; + b[2] = z[2] - z[0]; prodve(a, b, cross); - dx_dksi[0][0] = x[1] - x[0]; dx_dksi[0][1] = x[2]-x[0]; dx_dksi[0][2] = cross[0]; - dx_dksi[1][0] = y[1] - y[0]; dx_dksi[1][1] = y[2]-y[0]; dx_dksi[1][2] = cross[1]; - dx_dksi[2][0] = z[1] - z[0]; dx_dksi[2][1] = z[2]-z[0]; dx_dksi[2][2] = cross[2]; + dx_dksi[0][0] = x[1] - x[0]; + dx_dksi[0][1] = x[2] - x[0]; + dx_dksi[0][2] = cross[0]; + dx_dksi[1][0] = y[1] - y[0]; + dx_dksi[1][1] = y[2] - y[0]; + dx_dksi[1][2] = cross[1]; + dx_dksi[2][0] = z[1] - z[0]; + dx_dksi[2][1] = z[2] - z[0]; + dx_dksi[2][2] = cross[2]; inv3x3tran(dx_dksi, dksi_dx, &det); - GradPhi_ksi[0][0]= -1; GradPhi_ksi[0][1]= -1; GradPhi_ksi[0][2]= 0; - GradPhi_ksi[1][0]= 1; GradPhi_ksi[1][1]= 0; GradPhi_ksi[1][2]= 0; - GradPhi_ksi[2][0]= 0; GradPhi_ksi[2][1]= 1; GradPhi_ksi[2][2]= 0; + GradPhi_ksi[0][0] = -1; + GradPhi_ksi[0][1] = -1; + GradPhi_ksi[0][2] = 0; + GradPhi_ksi[1][0] = 1; + GradPhi_ksi[1][1] = 0; + GradPhi_ksi[1][2] = 0; + GradPhi_ksi[2][0] = 0; + GradPhi_ksi[2][1] = 1; + GradPhi_ksi[2][2] = 0; } - else if (nbNod == 4){ // tetrahedra - dx_dksi[0][0] = x[1] - x[0]; dx_dksi[0][1] = x[2]-x[0]; dx_dksi[0][2] = x[3]-x[0]; - dx_dksi[1][0] = y[1] - y[0]; dx_dksi[1][1] = y[2]-y[0]; dx_dksi[1][2] = y[3]-y[0]; - dx_dksi[2][0] = z[1] - z[0]; dx_dksi[2][1] = z[2]-z[0]; dx_dksi[2][2] = z[3]-z[0]; + else if(nbNod == 4) { // tetrahedra + dx_dksi[0][0] = x[1] - x[0]; + dx_dksi[0][1] = x[2] - x[0]; + dx_dksi[0][2] = x[3] - x[0]; + dx_dksi[1][0] = y[1] - y[0]; + dx_dksi[1][1] = y[2] - y[0]; + dx_dksi[1][2] = y[3] - y[0]; + dx_dksi[2][0] = z[1] - z[0]; + dx_dksi[2][1] = z[2] - z[0]; + dx_dksi[2][2] = z[3] - z[0]; inv3x3tran(dx_dksi, dksi_dx, &det); - GradPhi_ksi[0][0]= -1; GradPhi_ksi[0][1]= -1; GradPhi_ksi[0][2]= -1; - GradPhi_ksi[1][0]= 1; GradPhi_ksi[1][1]= 0; GradPhi_ksi[1][2]= 0; - GradPhi_ksi[2][0]= 0; GradPhi_ksi[2][1]= 1; GradPhi_ksi[2][2]= 0; - GradPhi_ksi[3][0]= 0; GradPhi_ksi[3][1]= 0; GradPhi_ksi[3][2]= 1; + GradPhi_ksi[0][0] = -1; + GradPhi_ksi[0][1] = -1; + GradPhi_ksi[0][2] = -1; + GradPhi_ksi[1][0] = 1; + GradPhi_ksi[1][1] = 0; + GradPhi_ksi[1][2] = 0; + GradPhi_ksi[2][0] = 0; + GradPhi_ksi[2][1] = 1; + GradPhi_ksi[2][2] = 0; + GradPhi_ksi[3][0] = 0; + GradPhi_ksi[3][1] = 0; + GradPhi_ksi[3][2] = 1; } - else{ + else { Msg::Error("Lambda2 not ready for this type of element"); return; } - for(int k = 0; k < nbNod ; k++){ - for(int l = 0; l < 3; l++){ + for(int k = 0; k < nbNod; k++) { + for(int l = 0; l < 3; l++) { GradPhi_x[k][l] = 0.0; - for(int m = 0; m < 3; m++){ + for(int m = 0; m < 3; m++) { GradPhi_x[k][l] += GradPhi_ksi[k][m] * dksi_dx[l][m]; } } } // compute gradient of velocities - for(int k = 0; k < 3; k++){ - for(int l = 0; l < 3; l++){ + for(int k = 0; k < 3; k++) { + for(int l = 0; l < 3; l++) { GradVel[k][l] = 0.0; - for(int m = 0; m < nbNod; m++){ - GradVel[k][l] += val[k][m]* GradPhi_x[m][l]; + for(int m = 0; m < nbNod; m++) { + GradVel[k][l] += val[k][m] * GradPhi_x[m][l]; } } } } else for(int k = 0; k < 3; k++) - for(int l = 0; l < 3; l++) - GradVel[k][l] = 0.0; + for(int l = 0; l < 3; l++) GradVel[k][l] = 0.0; // compute the sym and antisymetric parts double sym[3][3]; double asym[3][3]; - for(int m = 0; m < 3; m++){ - for(int n = 0; n < 3; n++){ - sym[m][n] = 0.5 * (GradVel[m][n] + GradVel[n][m]); + for(int m = 0; m < 3; m++) { + for(int n = 0; n < 3; n++) { + sym[m][n] = 0.5 * (GradVel[m][n] + GradVel[n][m]); asym[m][n] = 0.5 * (GradVel[m][n] - GradVel[n][m]); } } double a[3][3]; - for(int m = 0; m < 3; m++){ - for(int n = 0; n < 3; n++){ + for(int m = 0; m < 3; m++) { + for(int n = 0; n < 3; n++) { a[m][n] = 0.0; for(int l = 0; l < 3; l++) a[m][n] += sym[m][l] * sym[l][n] + asym[m][l] * asym[l][n]; } } - + // compute the eigenvalues double lambda[3]; eigenvalue(a, lambda); - for(int k = 0; k < nbNod; k++) - outList.push_back(lambda[lam-1]); + for(int k = 0; k < nbNod; k++) outList.push_back(lambda[lam - 1]); } (*outNb)++; - } } @@ -209,7 +230,7 @@ PView *GMSH_Lambda2Plugin::execute(PView *v) { int ev = (int)Lambda2Options_Number[0].def; int iView = (int)Lambda2Options_Number[1].def; - + PView *v1 = getView(iView, v); if(!v1) return v; @@ -220,7 +241,7 @@ PView *GMSH_Lambda2Plugin::execute(PView *v) PViewDataList *data2 = getDataList(v2); if(!data2) return v; - + // assume that the tensors contain the velocity gradient tensor int nts = data1->getNumTimeSteps(); eigen(data1->TP, data1->NbTP, data2->SP, &data2->NbSP, nts, 1, 9, ev); @@ -234,14 +255,14 @@ PView *GMSH_Lambda2Plugin::execute(PView *v) // assume that the vectors contain the velocities // FIXME: only implemented for tri/tet at the moment - //eigen(data1->VP, data1->NbVP, data2->SP, &data2->NbSP, nts, 1, 3, ev); - //eigen(data1->VL, data1->NbVL, data2->SL, &data2->NbSL, nts, 2, 3, ev); + // eigen(data1->VP, data1->NbVP, data2->SP, &data2->NbSP, nts, 1, 3, ev); + // eigen(data1->VL, data1->NbVL, data2->SL, &data2->NbSL, nts, 2, 3, ev); eigen(data1->VT, data1->NbVT, data2->ST, &data2->NbST, nts, 3, 3, ev); - //eigen(data1->VQ, data1->NbVQ, data2->SQ, &data2->NbSQ, nts, 4, 3, ev); + // eigen(data1->VQ, data1->NbVQ, data2->SQ, &data2->NbSQ, nts, 4, 3, ev); eigen(data1->VS, data1->NbVS, data2->SS, &data2->NbSS, nts, 4, 3, ev); - //eigen(data1->VH, data1->NbVH, data2->SH, &data2->NbSH, nts, 8, 3, ev); - //eigen(data1->VI, data1->NbVI, data2->SI, &data2->NbSI, nts, 6, 3, ev); - //eigen(data1->VY, data1->NbVY, data2->SY, &data2->NbSY, nts, 5, 3, ev); + // eigen(data1->VH, data1->NbVH, data2->SH, &data2->NbSH, nts, 8, 3, ev); + // eigen(data1->VI, data1->NbVI, data2->SI, &data2->NbSI, nts, 6, 3, ev); + // eigen(data1->VY, data1->NbVY, data2->SY, &data2->NbSY, nts, 5, 3, ev); data2->Time = data1->Time; data2->setName(data1->getName() + "_Lambda2"); diff --git a/Plugin/Lambda2.h b/Plugin/Lambda2.h index 31337e418f33493171ba1b07d6143e28de106b18..46edea939bad7b5e81cf972a5dd98f059c0f2390 100644 --- a/Plugin/Lambda2.h +++ b/Plugin/Lambda2.h @@ -8,24 +8,19 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterLambda2Plugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterLambda2Plugin(); } -class GMSH_Lambda2Plugin : public GMSH_PostPlugin -{ - public: - GMSH_Lambda2Plugin(){} +class GMSH_Lambda2Plugin : public GMSH_PostPlugin { +public: + GMSH_Lambda2Plugin() {} std::string getName() const { return "Lambda2"; } - std::string getShortHelp() const - { - return "Detect vortices"; - } + std::string getShortHelp() const { return "Detect vortices"; } std::string getHelp() const; std::string getAuthor() const { return "E. Marchandise"; } int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Levelset.cpp b/Plugin/Levelset.cpp index 9313c880591126f65f8d8dc8ebda8a87598cc60f..c30b027eff1c194a8a47173a6d62f8ae74b566b2 100644 --- a/Plugin/Levelset.cpp +++ b/Plugin/Levelset.cpp @@ -12,24 +12,43 @@ #include "PViewOptions.h" static const int exn[13][12][2] = { - {{0,0}}, // point - {{0,1}}, // line + {{0, 0}}, // point + {{0, 1}}, // line {{}}, // - - {{0,1}, {0,2}, {1,2}}, // triangle - {{0,1}, {0,3}, {1,2}, {2,3}}, // quad + {{0, 1}, {0, 2}, {1, 2}}, // triangle + {{0, 1}, {0, 3}, {1, 2}, {2, 3}}, // quad {{}}, // - - {{0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3}}, // tetra + {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}}, // tetra {{}}, // - - {{0,1}, {0,3}, {0,4}, {1,2}, {1,4}, {2,3}, {2,4}, {3,4}}, // pyramid - {{0,1}, {0,2}, {0,3}, {1,2}, {1,4}, {2,5}, {3,4}, {3,5}, {4,5}}, // prism - {{}}, {{}}, // - - {{0,1}, {0,3}, {0,4}, {1,2}, {1,5}, {2,3}, - {2,6}, {3,7}, {4,5}, {4,7}, {5,6}, {6,7}} // hexa + {{0, 1}, {0, 3}, {0, 4}, {1, 2}, {1, 4}, {2, 3}, {2, 4}, {3, 4}}, // pyramid + {{0, 1}, + {0, 2}, + {0, 3}, + {1, 2}, + {1, 4}, + {2, 5}, + {3, 4}, + {3, 5}, + {4, 5}}, // prism + {{}}, + {{}}, // - + {{0, 1}, + {0, 3}, + {0, 4}, + {1, 2}, + {1, 5}, + {2, 3}, + {2, 6}, + {3, 7}, + {4, 5}, + {4, 7}, + {5, 6}, + {6, 7}} // hexa }; static int numSimplexDec(int type) { - switch(type){ + switch(type) { case TYPE_QUA: return 2; case TYPE_HEX: return 6; case TYPE_PRI: return 3; @@ -38,37 +57,59 @@ static int numSimplexDec(int type) } } -static void getSimplexDec(int numNodes, int numEdges, int type, int i, - int &n0, int &n1, int &n2, int &n3, - int &nn, int &ne) +static void getSimplexDec(int numNodes, int numEdges, int type, int i, int &n0, + int &n1, int &n2, int &n3, int &nn, int &ne) { - static const int qua[2][3] = {{0,1,2}, {0,2,3}}; - static const int hex[6][4] = {{0,1,3,7}, {0,4,1,7}, {1,4,5,7}, - {1,2,3,7}, {1,6,2,7}, {1,5,6,7}}; - static const int pri[3][4] = {{0,1,2,4}, {0,2,4,5}, {0,3,4,5}}; - static const int pyr[2][4] = {{0,1,3,4}, {1,2,3,4}}; - switch(type){ + static const int qua[2][3] = {{0, 1, 2}, {0, 2, 3}}; + static const int hex[6][4] = {{0, 1, 3, 7}, {0, 4, 1, 7}, {1, 4, 5, 7}, + {1, 2, 3, 7}, {1, 6, 2, 7}, {1, 5, 6, 7}}; + static const int pri[3][4] = {{0, 1, 2, 4}, {0, 2, 4, 5}, {0, 3, 4, 5}}; + static const int pyr[2][4] = {{0, 1, 3, 4}, {1, 2, 3, 4}}; + switch(type) { case TYPE_QUA: - n0 = qua[i][0]; n1 = qua[i][1]; n2 = qua[i][2]; nn = 3; ne = 3; + n0 = qua[i][0]; + n1 = qua[i][1]; + n2 = qua[i][2]; + nn = 3; + ne = 3; break; case TYPE_HEX: - n0 = hex[i][0]; n1 = hex[i][1]; n2 = hex[i][2]; n3 = hex[i][3]; nn = 4; ne = 6; + n0 = hex[i][0]; + n1 = hex[i][1]; + n2 = hex[i][2]; + n3 = hex[i][3]; + nn = 4; + ne = 6; break; case TYPE_PRI: - n0 = pri[i][0]; n1 = pri[i][1]; n2 = pri[i][2]; n3 = pri[i][3]; nn = 4; ne = 6; + n0 = pri[i][0]; + n1 = pri[i][1]; + n2 = pri[i][2]; + n3 = pri[i][3]; + nn = 4; + ne = 6; break; case TYPE_PYR: - n0 = pyr[i][0]; n1 = pyr[i][1]; n2 = pyr[i][2]; n3 = pyr[i][3]; nn = 4; ne = 6; + n0 = pyr[i][0]; + n1 = pyr[i][1]; + n2 = pyr[i][2]; + n3 = pyr[i][3]; + nn = 4; + ne = 6; break; default: - n0 = 0; n1 = 1; n2 = 2; n3 = 3; nn = numNodes; ne = numEdges; + n0 = 0; + n1 = 1; + n2 = 2; + n3 = 3; + nn = numNodes; + ne = numEdges; break; } } -static void affect(double *xpi, double *ypi, double *zpi, - double valpi[12][9], int epi[12], int i, - double *xp, double *yp, double *zp, +static void affect(double *xpi, double *ypi, double *zpi, double valpi[12][9], + int epi[12], int i, double *xp, double *yp, double *zp, double valp[12][9], int ep[12], int j, int nb) { xpi[i] = xp[j]; @@ -78,8 +119,8 @@ static void affect(double *xpi, double *ypi, double *zpi, epi[i] = ep[j]; } -static void removeIdenticalNodes(int *np, int numComp, - double xp[12], double yp[12], double zp[12], +static void removeIdenticalNodes(int *np, int numComp, double xp[12], + double yp[12], double zp[12], double valp[12][9], int ep[12]) { double xpi[12], ypi[12], zpi[12], valpi[12][9]; @@ -89,13 +130,13 @@ static void removeIdenticalNodes(int *np, int numComp, int npi = 1; for(int j = 1; j < *np; j++) { for(int i = 0; i < npi; i++) { - if(fabs(xp[j] - xpi[i]) < 1.e-12 && - fabs(yp[j] - ypi[i]) < 1.e-12 && + if(fabs(xp[j] - xpi[i]) < 1.e-12 && fabs(yp[j] - ypi[i]) < 1.e-12 && fabs(zp[j] - zpi[i]) < 1.e-12) { break; } if(i == npi - 1) { - affect(xpi, ypi, zpi, valpi, epi, npi, xp, yp, zp, valp, ep, j, numComp); + affect(xpi, ypi, zpi, valpi, epi, npi, xp, yp, zp, valp, ep, j, + numComp); npi++; break; } @@ -106,8 +147,8 @@ static void removeIdenticalNodes(int *np, int numComp, *np = npi; } -static void reorderQuad(int numComp, double xp[12], double yp[12], double zp[12], - double valp[12][9], int ep[12]) +static void reorderQuad(int numComp, double xp[12], double yp[12], + double zp[12], double valp[12][9], int ep[12]) { double xpi[1], ypi[1], zpi[1], valpi[1][9]; int epi[12]; @@ -116,57 +157,59 @@ static void reorderQuad(int numComp, double xp[12], double yp[12], double zp[12] affect(xp, yp, zp, valp, ep, 2, xpi, ypi, zpi, valpi, epi, 0, numComp); } -static void reorderPrism(int numComp, double xp[12], double yp[12], double zp[12], - double valp[12][9], int ep[12], int nbCut) +static void reorderPrism(int numComp, double xp[12], double yp[12], + double zp[12], double valp[12][9], int ep[12], + int nbCut) { double xpi[6], ypi[6], zpi[6], valpi[6][9]; int epi[12]; - if(nbCut == 3){ + if(nbCut == 3) { // 3 first nodes come from zero levelset intersection, next 3 are // endpoints of relative edges affect(xpi, ypi, zpi, valpi, epi, 0, xp, yp, zp, valp, ep, 3, numComp); affect(xpi, ypi, zpi, valpi, epi, 1, xp, yp, zp, valp, ep, 4, numComp); affect(xpi, ypi, zpi, valpi, epi, 2, xp, yp, zp, valp, ep, 5, numComp); - for(int i = 0; i < 3; i++){ - int edgecut = ep[i]-1; - for(int j = 0; j < 3; j++){ - int p = -epi[j]-1; + for(int i = 0; i < 3; i++) { + int edgecut = ep[i] - 1; + for(int j = 0; j < 3; j++) { + int p = -epi[j] - 1; if(exn[9][edgecut][0] == p || exn[9][edgecut][1] == p) - affect(xp, yp, zp, valp, ep, 3+i, xpi, ypi, zpi, valpi, epi, j, numComp); + affect(xp, yp, zp, valp, ep, 3 + i, xpi, ypi, zpi, valpi, epi, j, + numComp); } } } - else if(nbCut == 4){ + else if(nbCut == 4) { // 4 first nodes come from zero levelset intersection affect(xpi, ypi, zpi, valpi, epi, 0, xp, yp, zp, valp, ep, 0, numComp); - int edgecut = ep[0]-1; - int p0 = -ep[4]-1; + int edgecut = ep[0] - 1; + int p0 = -ep[4] - 1; - if(exn[9][edgecut][0] == p0 || exn[9][edgecut][1] == p0){ + if(exn[9][edgecut][0] == p0 || exn[9][edgecut][1] == p0) { affect(xpi, ypi, zpi, valpi, epi, 1, xp, yp, zp, valp, ep, 4, numComp); - if(exn[9][ep[1]-1][0] == p0 || exn[9][ep[1]-1][1] == p0){ + if(exn[9][ep[1] - 1][0] == p0 || exn[9][ep[1] - 1][1] == p0) { affect(xpi, ypi, zpi, valpi, epi, 2, xp, yp, zp, valp, ep, 1, numComp); affect(xpi, ypi, zpi, valpi, epi, 3, xp, yp, zp, valp, ep, 3, numComp); affect(xpi, ypi, zpi, valpi, epi, 4, xp, yp, zp, valp, ep, 5, numComp); affect(xpi, ypi, zpi, valpi, epi, 5, xp, yp, zp, valp, ep, 2, numComp); } - else{ + else { affect(xpi, ypi, zpi, valpi, epi, 2, xp, yp, zp, valp, ep, 3, numComp); affect(xpi, ypi, zpi, valpi, epi, 3, xp, yp, zp, valp, ep, 1, numComp); affect(xpi, ypi, zpi, valpi, epi, 4, xp, yp, zp, valp, ep, 5, numComp); affect(xpi, ypi, zpi, valpi, epi, 5, xp, yp, zp, valp, ep, 2, numComp); } } - else{ + else { affect(xpi, ypi, zpi, valpi, epi, 1, xp, yp, zp, valp, ep, 5, numComp); - if(exn[9][ep[1]-1][0] == p0 || exn[9][ep[1]-1][1] == p0){ + if(exn[9][ep[1] - 1][0] == p0 || exn[9][ep[1] - 1][1] == p0) { affect(xpi, ypi, zpi, valpi, epi, 2, xp, yp, zp, valp, ep, 1, numComp); affect(xpi, ypi, zpi, valpi, epi, 3, xp, yp, zp, valp, ep, 3, numComp); affect(xpi, ypi, zpi, valpi, epi, 4, xp, yp, zp, valp, ep, 4, numComp); affect(xpi, ypi, zpi, valpi, epi, 5, xp, yp, zp, valp, ep, 2, numComp); } - else{ + else { affect(xpi, ypi, zpi, valpi, epi, 2, xp, yp, zp, valp, ep, 3, numComp); affect(xpi, ypi, zpi, valpi, epi, 3, xp, yp, zp, valp, ep, 1, numComp); affect(xpi, ypi, zpi, valpi, epi, 4, xp, yp, zp, valp, ep, 4, numComp); @@ -187,87 +230,154 @@ GMSH_LevelsetPlugin::GMSH_LevelsetPlugin() _valueTimeStep = -1; // use same time step in levelset and field data views _recurLevel = 4; _targetError = 0.; - _extractVolume = 0; // to create isovolumes (keep all elements < or > levelset) + _extractVolume = + 0; // to create isovolumes (keep all elements < or > levelset) _orientation = GMSH_LevelsetPlugin::NONE; } void GMSH_LevelsetPlugin::_addElement(int np, int numEdges, int numComp, - double xp[12], double yp[12], double zp[12], - double valp[12][9], PViewDataList *out, - bool firstStep) + double xp[12], double yp[12], + double zp[12], double valp[12][9], + PViewDataList *out, bool firstStep) { std::vector<double> *list; int *nbPtr; - switch(np){ + switch(np) { case 1: - if(numComp == 1) { list = &out->SP; nbPtr = &out->NbSP; } - else if(numComp == 3) { list = &out->VP; nbPtr = &out->NbVP; } - else { list = &out->TP; nbPtr = &out->NbTP; } + if(numComp == 1) { + list = &out->SP; + nbPtr = &out->NbSP; + } + else if(numComp == 3) { + list = &out->VP; + nbPtr = &out->NbVP; + } + else { + list = &out->TP; + nbPtr = &out->NbTP; + } break; case 2: - if(numComp == 1) { list = &out->SL; nbPtr = &out->NbSL; } - else if(numComp == 3) { list = &out->VL; nbPtr = &out->NbVL; } - else { list = &out->TL; nbPtr = &out->NbTL; } + if(numComp == 1) { + list = &out->SL; + nbPtr = &out->NbSL; + } + else if(numComp == 3) { + list = &out->VL; + nbPtr = &out->NbVL; + } + else { + list = &out->TL; + nbPtr = &out->NbTL; + } break; case 3: - if(numComp == 1) { list = &out->ST; nbPtr = &out->NbST; } - else if(numComp == 3) { list = &out->VT; nbPtr = &out->NbVT; } - else { list = &out->TT; nbPtr = &out->NbTT; } + if(numComp == 1) { + list = &out->ST; + nbPtr = &out->NbST; + } + else if(numComp == 3) { + list = &out->VT; + nbPtr = &out->NbVT; + } + else { + list = &out->TT; + nbPtr = &out->NbTT; + } break; case 4: - if(!_extractVolume || numEdges <= 4){ - if(numComp == 1) { list = &out->SQ; nbPtr = &out->NbSQ; } - else if(numComp == 3) { list = &out->VQ; nbPtr = &out->NbVQ; } - else { list = &out->TQ; nbPtr = &out->NbTQ; } + if(!_extractVolume || numEdges <= 4) { + if(numComp == 1) { + list = &out->SQ; + nbPtr = &out->NbSQ; + } + else if(numComp == 3) { + list = &out->VQ; + nbPtr = &out->NbVQ; + } + else { + list = &out->TQ; + nbPtr = &out->NbTQ; + } } - else{ - if(numComp == 1) { list = &out->SS; nbPtr = &out->NbSS; } - else if(numComp == 3) { list = &out->VS; nbPtr = &out->NbVS; } - else { list = &out->TS; nbPtr = &out->NbTS; } + else { + if(numComp == 1) { + list = &out->SS; + nbPtr = &out->NbSS; + } + else if(numComp == 3) { + list = &out->VS; + nbPtr = &out->NbVS; + } + else { + list = &out->TS; + nbPtr = &out->NbTS; + } } break; case 5: - if(numComp == 1) { list = &out->SY; nbPtr = &out->NbSY; } - else if(numComp == 3) { list = &out->VY; nbPtr = &out->NbVY; } - else { list = &out->TY; nbPtr = &out->NbTY; } + if(numComp == 1) { + list = &out->SY; + nbPtr = &out->NbSY; + } + else if(numComp == 3) { + list = &out->VY; + nbPtr = &out->NbVY; + } + else { + list = &out->TY; + nbPtr = &out->NbTY; + } break; case 6: - if(numComp == 1) { list = &out->SI; nbPtr = &out->NbSI; } - else if(numComp == 3) { list = &out->VI; nbPtr = &out->NbVI; } - else { list = &out->TI; nbPtr = &out->NbTI; } + if(numComp == 1) { + list = &out->SI; + nbPtr = &out->NbSI; + } + else if(numComp == 3) { + list = &out->VI; + nbPtr = &out->NbVI; + } + else { + list = &out->TI; + nbPtr = &out->NbTI; + } break; case 8: - if(numComp == 1) { list = &out->SH; nbPtr = &out->NbSH; } - else if(numComp == 3) { list = &out->VH; nbPtr = &out->NbVH; } - else { list = &out->TH; nbPtr = &out->NbTH; } + if(numComp == 1) { + list = &out->SH; + nbPtr = &out->NbSH; + } + else if(numComp == 3) { + list = &out->VH; + nbPtr = &out->NbVH; + } + else { + list = &out->TH; + nbPtr = &out->NbTH; + } break; - default: - return; + default: return; } // copy the elements in the output data if(firstStep || !_valueIndependent) { - for(int k = 0; k < np; k++) - list->push_back(xp[k]); - for(int k = 0; k < np; k++) - list->push_back(yp[k]); - for(int k = 0; k < np; k++) - list->push_back(zp[k]); + for(int k = 0; k < np; k++) list->push_back(xp[k]); + for(int k = 0; k < np; k++) list->push_back(yp[k]); + for(int k = 0; k < np; k++) list->push_back(zp[k]); (*nbPtr)++; } for(int k = 0; k < np; k++) - for(int l = 0; l < numComp; l++) - list->push_back(valp[k][l]); + for(int l = 0; l < numComp; l++) list->push_back(valp[k][l]); } -void GMSH_LevelsetPlugin::_cutAndAddElements(PViewData *vdata, PViewData *wdata, - int ent, int ele, int vstep, int wstep, - double x[8], double y[8], double z[8], - double levels[8], double scalarValues[8], - PViewDataList* out) +void GMSH_LevelsetPlugin::_cutAndAddElements( + PViewData *vdata, PViewData *wdata, int ent, int ele, int vstep, int wstep, + double x[8], double y[8], double z[8], double levels[8], + double scalarValues[8], PViewDataList *out) { int stepmin = vstep, stepmax = vstep + 1, otherstep = wstep; - if(stepmin < 0){ + if(stepmin < 0) { stepmin = vdata->getFirstNonEmptyTimeStep(); stepmax = vdata->getNumTimeSteps(); } @@ -279,15 +389,13 @@ void GMSH_LevelsetPlugin::_cutAndAddElements(PViewData *vdata, PViewData *wdata, int type = vdata->getType(stepmin, ent, ele); // decompose the element into simplices - for(int simplex = 0; simplex < numSimplexDec(type); simplex++){ - + for(int simplex = 0; simplex < numSimplexDec(type); simplex++) { int n[4], ep[12], nsn, nse; getSimplexDec(numNodes, numEdges, type, simplex, n[0], n[1], n[2], n[3], nsn, nse); // loop over time steps - for(int step = stepmin; step < stepmax; step++){ - + for(int step = stepmin; step < stepmax; step++) { // check which edges cut the iso and interpolate the value if(wstep < 0) otherstep = step; @@ -295,12 +403,12 @@ void GMSH_LevelsetPlugin::_cutAndAddElements(PViewData *vdata, PViewData *wdata, int np = 0; double xp[12], yp[12], zp[12], valp[12][9]; - for(int i = 0; i < nse; i++){ + for(int i = 0; i < nse; i++) { int n0 = exn[nse][i][0], n1 = exn[nse][i][1]; if(levels[n[n0]] * levels[n[n1]] <= 0.) { - double c = InterpolateIso(x, y, z, levels, 0., n[n0], n[n1], - &xp[np], &yp[np], &zp[np]); - for(int comp = 0; comp < numComp; comp++){ + double c = InterpolateIso(x, y, z, levels, 0., n[n0], n[n1], &xp[np], + &yp[np], &zp[np]); + for(int comp = 0; comp < numComp; comp++) { double v0, v1; wdata->getValue(otherstep, ent, ele, n[n0], comp, v0); wdata->getValue(otherstep, ent, ele, n[n1], comp, v1); @@ -316,24 +424,26 @@ void GMSH_LevelsetPlugin::_cutAndAddElements(PViewData *vdata, PViewData *wdata, // if there are no cuts and we extract the volume, save the full // element if it is on the correct side of the levelset - if(np <= 1 && _extractVolume){ + if(np <= 1 && _extractVolume) { bool add = true; - for(int nod = 0; nod < nsn; nod++){ + for(int nod = 0; nod < nsn; nod++) { if((_extractVolume < 0. && levels[n[nod]] > 0.) || - (_extractVolume > 0. && levels[n[nod]] < 0.)){ + (_extractVolume > 0. && levels[n[nod]] < 0.)) { add = false; break; } } - if(add){ - for(int nod = 0; nod < nsn; nod++){ + if(add) { + for(int nod = 0; nod < nsn; nod++) { xp[nod] = x[n[nod]]; yp[nod] = y[n[nod]]; zp[nod] = z[n[nod]]; for(int comp = 0; comp < numComp; comp++) - wdata->getValue(otherstep, ent, ele, n[nod], comp, valp[nod][comp]); + wdata->getValue(otherstep, ent, ele, n[nod], comp, + valp[nod][comp]); } - _addElement(nsn, nse, numComp, xp, yp, zp, valp, out, step == stepmin); + _addElement(nsn, nse, numComp, xp, yp, zp, valp, out, + step == stepmin); } continue; } @@ -357,81 +467,78 @@ void GMSH_LevelsetPlugin::_cutAndAddElements(PViewData *vdata, PViewData *wdata, double v2[3] = {xp[1] - xp[0], yp[1] - yp[0], zp[1] - zp[0]}; double gr[3], normal[3]; prodve(v1, v2, normal); - switch (_orientation) { + switch(_orientation) { case MAP: gradSimplex(x, y, z, scalarValues, gr); _invert = prosca(gr, normal); break; - case PLANE: - _invert = prosca(normal, _ref); - break; + case PLANE: _invert = prosca(normal, _ref); break; case SPHERE: gr[0] = xp[0] - _ref[0]; gr[1] = yp[0] - _ref[1]; gr[2] = zp[0] - _ref[2]; _invert = prosca(gr, normal); case NONE: - default: - break; + default: break; } } if(_invert > 0.) { double xpi[12], ypi[12], zpi[12], valpi[12][9]; int epi[12]; for(int k = 0; k < np; k++) - affect(xpi, ypi, zpi, valpi, epi, k, xp, yp, zp, valp, ep, k, numComp); + affect(xpi, ypi, zpi, valpi, epi, k, xp, yp, zp, valp, ep, k, + numComp); for(int k = 0; k < np; k++) - affect(xp, yp, zp, valp, ep, k, xpi, ypi, zpi, valpi, epi, np - k - 1, numComp); + affect(xp, yp, zp, valp, ep, k, xpi, ypi, zpi, valpi, epi, + np - k - 1, numComp); } } // if we extract volumes, add the nodes on the chosen side // (FIXME: when cutting 2D views, the elts can have the wrong // orientation) - if(_extractVolume){ + if(_extractVolume) { int nbCut = np; - for(int nod = 0; nod < nsn; nod++){ + for(int nod = 0; nod < nsn; nod++) { if((_extractVolume < 0. && levels[n[nod]] < 0.) || - (_extractVolume > 0. && levels[n[nod]] > 0.)){ + (_extractVolume > 0. && levels[n[nod]] > 0.)) { xp[np] = x[n[nod]]; yp[np] = y[n[nod]]; zp[np] = z[n[nod]]; for(int comp = 0; comp < numComp; comp++) - wdata->getValue(otherstep, ent, ele, n[nod], comp, valp[np][comp]); + wdata->getValue(otherstep, ent, ele, n[nod], comp, + valp[np][comp]); ep[np] = -(nod + 1); // store node num! np++; } } removeIdenticalNodes(&np, numComp, xp, yp, zp, valp, ep); - if(np == 4 && numEdges <= 4) - reorderQuad(numComp, xp, yp, zp, valp, ep); - if(np == 6) - reorderPrism(numComp, xp, yp, zp, valp, ep, nbCut); + if(np == 4 && numEdges <= 4) reorderQuad(numComp, xp, yp, zp, valp, ep); + if(np == 6) reorderPrism(numComp, xp, yp, zp, valp, ep, nbCut); if(np > 8) // can't deal with this continue; } // finally, add the new element - _addElement(np, numEdges, numComp, xp, yp, zp, valp, out, step == stepmin); - + _addElement(np, numEdges, numComp, xp, yp, zp, valp, out, + step == stepmin); } - if(vstep < 0){ + if(vstep < 0) { for(int i = stepmin; i < stepmax; i++) { - out->Time.push_back(vdata->getTime(i)); + out->Time.push_back(vdata->getTime(i)); } } - } } PView *GMSH_LevelsetPlugin::execute(PView *v) { // for adapted views we can only run the plugin on one step at a time - if(v->getData()->getAdaptiveData()){ + if(v->getData()->getAdaptiveData()) { PViewOptions *opt = v->getOptions(); - v->getData()->getAdaptiveData()->changeResolution - (opt->timeStep, _recurLevel, _targetError, this); + v->getData()->getAdaptiveData()->changeResolution( + opt->timeStep, _recurLevel, _targetError, this); v->setChanged(true); } @@ -439,18 +546,18 @@ PView *GMSH_LevelsetPlugin::execute(PView *v) if(_valueView < 0) { wdata = vdata; } - else if(_valueView > (int)PView::list.size() - 1){ - Msg::Error("View[%d] does not exist: reverting to View[%d]", - _valueView, v->getIndex()); + else if(_valueView > (int)PView::list.size() - 1) { + Msg::Error("View[%d] does not exist: reverting to View[%d]", _valueView, + v->getIndex()); wdata = vdata; } - else{ + else { wdata = getPossiblyAdaptiveData(PView::list[_valueView]); } // sanity checks if(vdata->getNumEntities() != wdata->getNumEntities() || - vdata->getNumElements() != wdata->getNumElements()){ + vdata->getNumElements() != wdata->getNumElements()) { Msg::Error("Incompatible views"); return v; } @@ -469,11 +576,14 @@ PView *GMSH_LevelsetPlugin::execute(PView *v) // create a single output view containing the (possibly multi-step) levelset int firstNonEmptyStep = vdata->getFirstNonEmptyTimeStep(); PViewDataList *out = getDataList(new PView()); - for(int ent = 0; ent < vdata->getNumEntities(firstNonEmptyStep); ent++){ - for(int ele = 0; ele < vdata->getNumElements(firstNonEmptyStep, ent); ele++){ + for(int ent = 0; ent < vdata->getNumEntities(firstNonEmptyStep); ent++) { + for(int ele = 0; ele < vdata->getNumElements(firstNonEmptyStep, ent); + ele++) { if(vdata->skipElement(firstNonEmptyStep, ent, ele)) continue; - for(int nod = 0; nod < vdata->getNumNodes(firstNonEmptyStep, ent, ele); nod++){ - vdata->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], z[nod]); + for(int nod = 0; nod < vdata->getNumNodes(firstNonEmptyStep, ent, ele); + nod++) { + vdata->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], + z[nod]); levels[nod] = levelset(x[nod], y[nod], z[nod], 0.); } _cutAndAddElements(vdata, wdata, ent, ele, -1, _valueTimeStep, x, y, z, @@ -484,15 +594,15 @@ PView *GMSH_LevelsetPlugin::execute(PView *v) out->setFileName(vdata->getFileName() + "_Levelset.pos"); out->finalize(); } - else{ + else { // create one view per timestep - for(int step = 0; step < vdata->getNumTimeSteps(); step++){ + for(int step = 0; step < vdata->getNumTimeSteps(); step++) { if(!vdata->hasTimeStep(step)) continue; PViewDataList *out = getDataList(new PView()); - for(int ent = 0; ent < vdata->getNumEntities(step); ent++){ - for(int ele = 0; ele < vdata->getNumElements(step, ent); ele++){ + for(int ent = 0; ent < vdata->getNumEntities(step); ent++) { + for(int ele = 0; ele < vdata->getNumElements(step, ent); ele++) { if(vdata->skipElement(step, ent, ele)) continue; - for(int nod = 0; nod < vdata->getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < vdata->getNumNodes(step, ent, ele); nod++) { vdata->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); vdata->getScalarValue(step, ent, ele, nod, scalarValues[nod]); levels[nod] = levelset(x[nod], y[nod], z[nod], scalarValues[nod]); @@ -519,22 +629,25 @@ PView *GMSH_LevelsetPlugin::execute(PView *v) static bool recur_sign_change(adaptiveTriangle *t, const GMSH_LevelsetPlugin *plug) { - if(!t->e[0] || t->visible){ - double v1 = plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); - double v2 = plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); - double v3 = plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); + if(!t->e[0] || t->visible) { + double v1 = + plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); + double v2 = + plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); + double v3 = + plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); if(v1 * v2 > 0 && v1 * v3 > 0) t->visible = false; else t->visible = true; return t->visible; } - else{ + else { bool sc1 = recur_sign_change(t->e[0], plug); bool sc2 = recur_sign_change(t->e[1], plug); bool sc3 = recur_sign_change(t->e[2], plug); bool sc4 = recur_sign_change(t->e[3], plug); - if(sc1 || sc2 || sc3 || sc4){ + if(sc1 || sc2 || sc3 || sc4) { if(!sc1) t->e[0]->visible = true; if(!sc2) t->e[1]->visible = true; if(!sc3) t->e[2]->visible = true; @@ -549,23 +662,27 @@ static bool recur_sign_change(adaptiveTriangle *t, static bool recur_sign_change(adaptiveQuadrangle *q, const GMSH_LevelsetPlugin *plug) { - if(!q->e[0] || q->visible){ - double v1 = plug->levelset(q->p[0]->X, q->p[0]->Y, q->p[0]->Z, q->p[0]->val); - double v2 = plug->levelset(q->p[1]->X, q->p[1]->Y, q->p[1]->Z, q->p[1]->val); - double v3 = plug->levelset(q->p[2]->X, q->p[2]->Y, q->p[2]->Z, q->p[2]->val); - double v4 = plug->levelset(q->p[3]->X, q->p[3]->Y, q->p[3]->Z, q->p[3]->val); + if(!q->e[0] || q->visible) { + double v1 = + plug->levelset(q->p[0]->X, q->p[0]->Y, q->p[0]->Z, q->p[0]->val); + double v2 = + plug->levelset(q->p[1]->X, q->p[1]->Y, q->p[1]->Z, q->p[1]->val); + double v3 = + plug->levelset(q->p[2]->X, q->p[2]->Y, q->p[2]->Z, q->p[2]->val); + double v4 = + plug->levelset(q->p[3]->X, q->p[3]->Y, q->p[3]->Z, q->p[3]->val); if(v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0) q->visible = false; else q->visible = true; return q->visible; } - else{ + else { bool sc1 = recur_sign_change(q->e[0], plug); bool sc2 = recur_sign_change(q->e[1], plug); bool sc3 = recur_sign_change(q->e[2], plug); bool sc4 = recur_sign_change(q->e[3], plug); - if(sc1 || sc2 || sc3 || sc4 ){ + if(sc1 || sc2 || sc3 || sc4) { if(!sc1) q->e[0]->visible = true; if(!sc2) q->e[1]->visible = true; if(!sc3) q->e[2]->visible = true; @@ -580,18 +697,22 @@ static bool recur_sign_change(adaptiveQuadrangle *q, static bool recur_sign_change(adaptiveTetrahedron *t, const GMSH_LevelsetPlugin *plug) { - if(!t->e[0] || t->visible){ - double v1 = plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); - double v2 = plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); - double v3 = plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); - double v4 = plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); + if(!t->e[0] || t->visible) { + double v1 = + plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); + double v2 = + plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); + double v3 = + plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); + double v4 = + plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); if(v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0) t->visible = false; else t->visible = true; return t->visible; } - else{ + else { bool sc1 = recur_sign_change(t->e[0], plug); bool sc2 = recur_sign_change(t->e[1], plug); bool sc3 = recur_sign_change(t->e[2], plug); @@ -600,7 +721,7 @@ static bool recur_sign_change(adaptiveTetrahedron *t, bool sc6 = recur_sign_change(t->e[5], plug); bool sc7 = recur_sign_change(t->e[6], plug); bool sc8 = recur_sign_change(t->e[7], plug); - if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8){ + if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8) { if(!sc1) t->e[0]->visible = true; if(!sc2) t->e[1]->visible = true; if(!sc3) t->e[2]->visible = true; @@ -619,15 +740,23 @@ static bool recur_sign_change(adaptiveTetrahedron *t, static bool recur_sign_change(adaptiveHexahedron *t, const GMSH_LevelsetPlugin *plug) { - if (!t->e[0] || t->visible){ - double v1 = plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); - double v2 = plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); - double v3 = plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); - double v4 = plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); - double v5 = plug->levelset(t->p[4]->X, t->p[4]->Y, t->p[4]->Z, t->p[4]->val); - double v6 = plug->levelset(t->p[5]->X, t->p[5]->Y, t->p[5]->Z, t->p[5]->val); - double v7 = plug->levelset(t->p[6]->X, t->p[6]->Y, t->p[6]->Z, t->p[6]->val); - double v8 = plug->levelset(t->p[7]->X, t->p[7]->Y, t->p[7]->Z, t->p[7]->val); + if(!t->e[0] || t->visible) { + double v1 = + plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); + double v2 = + plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); + double v3 = + plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); + double v4 = + plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); + double v5 = + plug->levelset(t->p[4]->X, t->p[4]->Y, t->p[4]->Z, t->p[4]->val); + double v6 = + plug->levelset(t->p[5]->X, t->p[5]->Y, t->p[5]->Z, t->p[5]->val); + double v7 = + plug->levelset(t->p[6]->X, t->p[6]->Y, t->p[6]->Z, t->p[6]->val); + double v8 = + plug->levelset(t->p[7]->X, t->p[7]->Y, t->p[7]->Z, t->p[7]->val); if(v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0 && v1 * v5 > 0 && v1 * v6 > 0 && v1 * v7 > 0 && v1 * v8 > 0) t->visible = false; @@ -635,7 +764,7 @@ static bool recur_sign_change(adaptiveHexahedron *t, t->visible = true; return t->visible; } - else{ + else { bool sc1 = recur_sign_change(t->e[0], plug); bool sc2 = recur_sign_change(t->e[1], plug); bool sc3 = recur_sign_change(t->e[2], plug); @@ -644,15 +773,15 @@ static bool recur_sign_change(adaptiveHexahedron *t, bool sc6 = recur_sign_change(t->e[5], plug); bool sc7 = recur_sign_change(t->e[6], plug); bool sc8 = recur_sign_change(t->e[7], plug); - if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8){ - if (!sc1) t->e[0]->visible = true; - if (!sc2) t->e[1]->visible = true; - if (!sc3) t->e[2]->visible = true; - if (!sc4) t->e[3]->visible = true; - if (!sc5) t->e[4]->visible = true; - if (!sc6) t->e[5]->visible = true; - if (!sc7) t->e[6]->visible = true; - if (!sc8) t->e[7]->visible = true; + if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8) { + if(!sc1) t->e[0]->visible = true; + if(!sc2) t->e[1]->visible = true; + if(!sc3) t->e[2]->visible = true; + if(!sc4) t->e[3]->visible = true; + if(!sc5) t->e[4]->visible = true; + if(!sc6) t->e[5]->visible = true; + if(!sc7) t->e[6]->visible = true; + if(!sc8) t->e[7]->visible = true; return true; } t->visible = false; @@ -660,23 +789,28 @@ static bool recur_sign_change(adaptiveHexahedron *t, } } -static bool recur_sign_change(adaptivePrism *t, - const GMSH_LevelsetPlugin *plug) +static bool recur_sign_change(adaptivePrism *t, const GMSH_LevelsetPlugin *plug) { - if (!t->e[0] || t->visible){ - double v1 = plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); - double v2 = plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); - double v3 = plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); - double v4 = plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); - double v5 = plug->levelset(t->p[4]->X, t->p[4]->Y, t->p[4]->Z, t->p[4]->val); - double v6 = plug->levelset(t->p[5]->X, t->p[5]->Y, t->p[5]->Z, t->p[5]->val); + if(!t->e[0] || t->visible) { + double v1 = + plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); + double v2 = + plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); + double v3 = + plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); + double v4 = + plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); + double v5 = + plug->levelset(t->p[4]->X, t->p[4]->Y, t->p[4]->Z, t->p[4]->val); + double v6 = + plug->levelset(t->p[5]->X, t->p[5]->Y, t->p[5]->Z, t->p[5]->val); if(v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0 && v1 * v5 > 0 && v1 * v6 > 0) t->visible = false; else t->visible = true; return t->visible; } - else{ + else { bool sc1 = recur_sign_change(t->e[0], plug); bool sc2 = recur_sign_change(t->e[1], plug); bool sc3 = recur_sign_change(t->e[2], plug); @@ -685,15 +819,15 @@ static bool recur_sign_change(adaptivePrism *t, bool sc6 = recur_sign_change(t->e[5], plug); bool sc7 = recur_sign_change(t->e[6], plug); bool sc8 = recur_sign_change(t->e[7], plug); - if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8){ - if (!sc1) t->e[0]->visible = true; - if (!sc2) t->e[1]->visible = true; - if (!sc3) t->e[2]->visible = true; - if (!sc4) t->e[3]->visible = true; - if (!sc5) t->e[4]->visible = true; - if (!sc6) t->e[5]->visible = true; - if (!sc7) t->e[6]->visible = true; - if (!sc8) t->e[7]->visible = true; + if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8) { + if(!sc1) t->e[0]->visible = true; + if(!sc2) t->e[1]->visible = true; + if(!sc3) t->e[2]->visible = true; + if(!sc4) t->e[3]->visible = true; + if(!sc5) t->e[4]->visible = true; + if(!sc6) t->e[5]->visible = true; + if(!sc7) t->e[6]->visible = true; + if(!sc8) t->e[7]->visible = true; return true; } t->visible = false; @@ -704,40 +838,45 @@ static bool recur_sign_change(adaptivePrism *t, static bool recur_sign_change(adaptivePyramid *t, const GMSH_LevelsetPlugin *plug) { - if (!t->e[0] || t->visible){ - double v1 = plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); - double v2 = plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); - double v3 = plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); - double v4 = plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); - double v5 = plug->levelset(t->p[4]->X, t->p[4]->Y, t->p[4]->Z, t->p[4]->val); + if(!t->e[0] || t->visible) { + double v1 = + plug->levelset(t->p[0]->X, t->p[0]->Y, t->p[0]->Z, t->p[0]->val); + double v2 = + plug->levelset(t->p[1]->X, t->p[1]->Y, t->p[1]->Z, t->p[1]->val); + double v3 = + plug->levelset(t->p[2]->X, t->p[2]->Y, t->p[2]->Z, t->p[2]->val); + double v4 = + plug->levelset(t->p[3]->X, t->p[3]->Y, t->p[3]->Z, t->p[3]->val); + double v5 = + plug->levelset(t->p[4]->X, t->p[4]->Y, t->p[4]->Z, t->p[4]->val); if(v1 * v2 > 0 && v1 * v3 > 0 && v1 * v4 > 0 && v1 * v5 > 0) t->visible = false; else t->visible = true; return t->visible; } - else{ - bool sc1 = recur_sign_change(t->e[0], plug); - bool sc2 = recur_sign_change(t->e[1], plug); - bool sc3 = recur_sign_change(t->e[2], plug); - bool sc4 = recur_sign_change(t->e[3], plug); - bool sc5 = recur_sign_change(t->e[4], plug); - bool sc6 = recur_sign_change(t->e[5], plug); - bool sc7 = recur_sign_change(t->e[6], plug); - bool sc8 = recur_sign_change(t->e[7], plug); - bool sc9 = recur_sign_change(t->e[8], plug); + else { + bool sc1 = recur_sign_change(t->e[0], plug); + bool sc2 = recur_sign_change(t->e[1], plug); + bool sc3 = recur_sign_change(t->e[2], plug); + bool sc4 = recur_sign_change(t->e[3], plug); + bool sc5 = recur_sign_change(t->e[4], plug); + bool sc6 = recur_sign_change(t->e[5], plug); + bool sc7 = recur_sign_change(t->e[6], plug); + bool sc8 = recur_sign_change(t->e[7], plug); + bool sc9 = recur_sign_change(t->e[8], plug); bool sc10 = recur_sign_change(t->e[9], plug); - if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8 || sc9 || sc10){ - if (!sc1) t->e[0]->visible = true; - if (!sc2) t->e[1]->visible = true; - if (!sc3) t->e[2]->visible = true; - if (!sc4) t->e[3]->visible = true; - if (!sc5) t->e[4]->visible = true; - if (!sc6) t->e[5]->visible = true; - if (!sc7) t->e[6]->visible = true; - if (!sc8) t->e[7]->visible = true; - if (!sc9) t->e[8]->visible = true; - if (!sc10) t->e[9]->visible = true; + if(sc1 || sc2 || sc3 || sc4 || sc5 || sc6 || sc7 || sc8 || sc9 || sc10) { + if(!sc1) t->e[0]->visible = true; + if(!sc2) t->e[1]->visible = true; + if(!sc3) t->e[2]->visible = true; + if(!sc4) t->e[3]->visible = true; + if(!sc5) t->e[4]->visible = true; + if(!sc6) t->e[5]->visible = true; + if(!sc7) t->e[6]->visible = true; + if(!sc8) t->e[7]->visible = true; + if(!sc9) t->e[8]->visible = true; + if(!sc10) t->e[9]->visible = true; return true; } t->visible = false; @@ -747,27 +886,27 @@ static bool recur_sign_change(adaptivePyramid *t, void GMSH_LevelsetPlugin::assignSpecificVisibility() const { - if(adaptiveTriangle::all.size()){ + if(adaptiveTriangle::all.size()) { adaptiveTriangle *t = *adaptiveTriangle::all.begin(); if(!t->visible) t->visible = !recur_sign_change(t, this); } - if(adaptiveQuadrangle::all.size()){ + if(adaptiveQuadrangle::all.size()) { adaptiveQuadrangle *q = *adaptiveQuadrangle::all.begin(); if(!q->visible) q->visible = !recur_sign_change(q, this); } - if(adaptiveTetrahedron::all.size()){ + if(adaptiveTetrahedron::all.size()) { adaptiveTetrahedron *t = *adaptiveTetrahedron::all.begin(); if(!t->visible) t->visible = !recur_sign_change(t, this); } - if(adaptiveHexahedron::all.size()){ + if(adaptiveHexahedron::all.size()) { adaptiveHexahedron *h = *adaptiveHexahedron::all.begin(); if(!h->visible) h->visible = !recur_sign_change(h, this); } - if(adaptivePrism::all.size()){ + if(adaptivePrism::all.size()) { adaptivePrism *p = *adaptivePrism::all.begin(); if(!p->visible) p->visible = !recur_sign_change(p, this); } - if(adaptivePyramid::all.size()){ + if(adaptivePyramid::all.size()) { adaptivePyramid *p = *adaptivePyramid::all.begin(); if(!p->visible) p->visible = !recur_sign_change(p, this); } diff --git a/Plugin/Levelset.h b/Plugin/Levelset.h index 335e80c028dfe8c37a4a2a74e4af0d977f26f02b..ff025f687e0363dea38e84edbc7c710c036b3004 100644 --- a/Plugin/Levelset.h +++ b/Plugin/Levelset.h @@ -8,25 +8,25 @@ #include "Plugin.h" -class GMSH_LevelsetPlugin : public GMSH_PostPlugin -{ - private: +class GMSH_LevelsetPlugin : public GMSH_PostPlugin { +private: double _invert; - void _addElement(int np, int numEdges, int numComp, - double xp[12], double yp[12], double zp[12], - double valp[12][9], PViewDataList *out, - bool firstStep); - void _cutAndAddElements(PViewData *vdata, PViewData *wdata, - int ent, int ele, int step, int wstep, - double x[8], double y[8], double z[8], - double levels[8], double scalarValues[8], + void _addElement(int np, int numEdges, int numComp, double xp[12], + double yp[12], double zp[12], double valp[12][9], + PViewDataList *out, bool firstStep); + void _cutAndAddElements(PViewData *vdata, PViewData *wdata, int ent, int ele, + int step, int wstep, double x[8], double y[8], + double z[8], double levels[8], double scalarValues[8], PViewDataList *out); - protected: + +protected: double _ref[3], _targetError; - int _valueTimeStep, _valueView, _valueIndependent, _recurLevel, _extractVolume; - typedef enum {NONE, PLANE, SPHERE, MAP} ORIENTATION; + int _valueTimeStep, _valueView, _valueIndependent, _recurLevel, + _extractVolume; + typedef enum { NONE, PLANE, SPHERE, MAP } ORIENTATION; ORIENTATION _orientation; - public: + +public: GMSH_LevelsetPlugin(); virtual double levelset(double x, double y, double z, double val) const = 0; virtual PView *execute(PView *); diff --git a/Plugin/LongitudeLatitude.cpp b/Plugin/LongitudeLatitude.cpp index a799f3ceb628c44fac0ad196787ebf03a2372a32..2ba794948683025c2b427ec7e8ac5a2bdd393cac 100644 --- a/Plugin/LongitudeLatitude.cpp +++ b/Plugin/LongitudeLatitude.cpp @@ -8,23 +8,21 @@ #include "OpenFile.h" StringXNumber LongituteLatitudeOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterLongituteLatitudePlugin() { - GMSH_Plugin *GMSH_RegisterLongituteLatitudePlugin() - { - return new GMSH_LongituteLatitudePlugin(); - } + return new GMSH_LongituteLatitudePlugin(); +} } std::string GMSH_LongituteLatitudePlugin::getHelp() const { return "Plugin(LongituteLatitude) projects the view `View' " - "in longitude-latitude.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(LongituteLatitude) is executed in place."; + "in longitude-latitude.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(LongituteLatitude) is executed in place."; } int GMSH_LongituteLatitudePlugin::getNbOptions() const @@ -45,11 +43,11 @@ PView *GMSH_LongituteLatitudePlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = v1->getData(); - if(data1->isNodeData()){ + if(data1->isNodeData()) { // tag all the nodes with "0" (the default tag) - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) data1->tagNode(step, ent, ele, nod, 0); @@ -59,14 +57,14 @@ PView *GMSH_LongituteLatitudePlugin::execute(PView *v) } double gxmin = 180, gxmax = -180, gymin = 90, gymax = -90; // transform all "0" nodes - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; int nbComp = data1->getNumComponents(step, ent, ele); double vin[3], vout[3]; double xmin = M_PI, xmax = -M_PI; - for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) { double x, y, z; int tag = data1->getNode(step, ent, ele, nod, x, y, z); if(data1->isNodeData() && tag) continue; @@ -74,30 +72,30 @@ PView *GMSH_LongituteLatitudePlugin::execute(PView *v) z2 = sqrt(x * x + y * y + z * z); y2 = asin(z / z2); x2 = atan2(y, x); - xmin=std::min(x2, xmin); - xmax=std::max(x2, xmax); + xmin = std::min(x2, xmin); + xmax = std::max(x2, xmax); gxmin = std::min(x2 * 180 / M_PI, gxmin); gxmax = std::max(x2 * 180 / M_PI, gxmax); gymin = std::min(y2 * 180 / M_PI, gymin); gymax = std::max(y2 * 180 / M_PI, gymax); - data1->setNode(step, ent, ele, nod, x2 * 180 / M_PI, y2 * 180 / M_PI, 0); + data1->setNode(step, ent, ele, nod, x2 * 180 / M_PI, y2 * 180 / M_PI, + 0); if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1); - if(nbComp == 3){ + if(nbComp == 3) { for(int i = 0; i < 3; i++) data1->getValue(step, ent, ele, nod, i, vin[i]); vout[0] = -sin(x2) * vin[0] + cos(x2) * vin[1]; - vout[1] = - -sin(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) + - cos(y2) * vin[2]; - vout[2] = - cos(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) + - sin(y2) * vin[2]; + vout[1] = -sin(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) + + cos(y2) * vin[2]; + vout[2] = cos(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) + + sin(y2) * vin[2]; for(int i = 0; i < 3; i++) data1->setValue(step, ent, ele, nod, i, vout[i]); } } - if(xmax - xmin > M_PI){ // periodicity check (broken for continuous views) - for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){ + if(xmax - xmin > + M_PI) { // periodicity check (broken for continuous views) + for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) { double x, y, z; data1->getNode(step, ent, ele, nod, x, y, z); if(xmax * 180 / M_PI - x > 180) x += 360; diff --git a/Plugin/LongitudeLatitude.h b/Plugin/LongitudeLatitude.h index 0f8fd091277aaf9f04e4d27032bfc3051f117363..c6a6c69ae7bc7fea06ecf8de149fc07250de32b8 100644 --- a/Plugin/LongitudeLatitude.h +++ b/Plugin/LongitudeLatitude.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterLongituteLatitudePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterLongituteLatitudePlugin(); } -class GMSH_LongituteLatitudePlugin : public GMSH_PostPlugin -{ - public: +class GMSH_LongituteLatitudePlugin : public GMSH_PostPlugin { +public: std::string getName() const { return "LongitudeLatitude"; } - std::string getShortHelp() const - { - return "Project in longitude-latitude"; - } + std::string getShortHelp() const { return "Project in longitude-latitude"; } std::string getHelp() const; std::string getAuthor() const { return "J. Lambrechts"; } int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/MakeSimplex.cpp b/Plugin/MakeSimplex.cpp index dd2f2ddaa435cb3c61828ce3e4c3eff49491437a..b03479070364f5eda5c5c5e6ec13f1b1b57a2fdd 100644 --- a/Plugin/MakeSimplex.cpp +++ b/Plugin/MakeSimplex.cpp @@ -5,25 +5,22 @@ #include "MakeSimplex.h" -StringXNumber MakeSimplexOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.} -}; +StringXNumber MakeSimplexOptions_Number[] = {{GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterMakeSimplexPlugin() { - GMSH_Plugin *GMSH_RegisterMakeSimplexPlugin() - { - return new GMSH_MakeSimplexPlugin(); - } + return new GMSH_MakeSimplexPlugin(); +} } std::string GMSH_MakeSimplexPlugin::getHelp() const { return "Plugin(MakeSimplex) decomposes all non-simplectic " - "elements (quadrangles, prisms, hexahedra, pyramids) in the " - "view `View' into simplices (triangles, tetrahedra).\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(MakeSimplex) is executed in-place."; + "elements (quadrangles, prisms, hexahedra, pyramids) in the " + "view `View' into simplices (triangles, tetrahedra).\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(MakeSimplex) is executed in-place."; } int GMSH_MakeSimplexPlugin::getNbOptions() const @@ -40,33 +37,31 @@ static void decomposeList(PViewDataList *data, int nbNod, int nbComp, std::vector<double> &listIn, int *nbIn, std::vector<double> &listOut, int *nbOut) { - if(!(*nbIn)) return; + if(!(*nbIn)) return; double xNew[4], yNew[4], zNew[4]; double *valNew = new double[data->getNumTimeSteps() * nbComp * nbNod]; MakeSimplex dec(nbNod, nbComp, data->getNumTimeSteps()); int nb = listIn.size() / (*nbIn); - for(unsigned int i = 0; i < listIn.size(); i += nb){ + for(unsigned int i = 0; i < listIn.size(); i += nb) { double *x = &listIn[i]; double *y = &listIn[i + nbNod]; double *z = &listIn[i + 2 * nbNod]; double *val = &listIn[i + 3 * nbNod]; - for(int j = 0; j < dec.numSimplices(); j++){ + for(int j = 0; j < dec.numSimplices(); j++) { dec.decompose(j, x, y, z, val, xNew, yNew, zNew, valNew); - for(int k = 0; k < dec.numSimplexNodes(); k++) - listOut.push_back(xNew[k]); - for(int k = 0; k < dec.numSimplexNodes(); k++) - listOut.push_back(yNew[k]); - for(int k = 0; k < dec.numSimplexNodes(); k++) - listOut.push_back(zNew[k]); - for(int k = 0; k < dec.numSimplexNodes() * data->getNumTimeSteps() * nbComp; k++) + for(int k = 0; k < dec.numSimplexNodes(); k++) listOut.push_back(xNew[k]); + for(int k = 0; k < dec.numSimplexNodes(); k++) listOut.push_back(yNew[k]); + for(int k = 0; k < dec.numSimplexNodes(); k++) listOut.push_back(zNew[k]); + for(int k = 0; + k < dec.numSimplexNodes() * data->getNumTimeSteps() * nbComp; k++) listOut.push_back(valNew[k]); (*nbOut)++; } } - delete [] valNew; + delete[] valNew; listIn.clear(); *nbIn = 0; @@ -111,7 +106,8 @@ PView *GMSH_MakeSimplexPlugin::execute(PView *v) // Utility class MakeSimplex::MakeSimplex(int numNodes, int numComponents, int numTimeSteps) - : _numNodes(numNodes), _numComponents(numComponents), _numTimeSteps(numTimeSteps) + : _numNodes(numNodes), _numComponents(numComponents), + _numTimeSteps(numTimeSteps) { ; } @@ -119,10 +115,14 @@ MakeSimplex::MakeSimplex(int numNodes, int numComponents, int numTimeSteps) int MakeSimplex::numSimplices() { switch(_numNodes) { - case 4: return 2; // quad -> 2 tris - case 5: return 2; // pyramid -> 2 tets - case 6: return 3; // prism -> 3 tets - case 8: return 6; // hexa -> 6 tets + case 4: + return 2; // quad -> 2 tris + case 5: + return 2; // pyramid -> 2 tets + case 6: + return 3; // prism -> 3 tets + case 8: + return 6; // hexa -> 6 tets } return 0; } @@ -135,9 +135,9 @@ int MakeSimplex::numSimplexNodes() return 4; // all others -> tets } -void MakeSimplex::reorder(int map[4], int n, - double *x, double *y, double *z, double *val, - double *xn, double *yn, double *zn, double *valn) +void MakeSimplex::reorder(int map[4], int n, double *x, double *y, double *z, + double *val, double *xn, double *yn, double *zn, + double *valn) { for(int i = 0; i < n; i++) { xn[i] = x[map[i]]; @@ -149,29 +149,30 @@ void MakeSimplex::reorder(int map[4], int n, for(int ts = 0; ts < _numTimeSteps; ts++) for(int i = 0; i < n; i++) { for(int j = 0; j < _numComponents; j++) - valn[ts*n*_numComponents + i*_numComponents + j] = - val[ts*_numNodes*_numComponents + map2[i]*_numComponents + j]; - } + valn[ts * n * _numComponents + i * _numComponents + j] = + val[ts * _numNodes * _numComponents + map2[i] * _numComponents + j]; + } } -void MakeSimplex::decompose(int num, - double *x, double *y, double *z, double *val, - double *xn, double *yn, double *zn, double *valn) +void MakeSimplex::decompose(int num, double *x, double *y, double *z, + double *val, double *xn, double *yn, double *zn, + double *valn) { - int quadTri[2][4] = {{0,1,2,-1}, {0,2,3,-1}}; - int hexaTet[6][4] = {{0,1,3,7}, {0,4,1,7}, {1,4,5,7}, {1,2,3,7}, {1,6,2,7}, {1,5,6,7}}; - int prisTet[3][4] = {{0,1,2,4}, {0,2,4,5}, {0,3,4,5}}; - int pyraTet[2][4] = {{0,1,3,4}, {1,2,3,4}}; + int quadTri[2][4] = {{0, 1, 2, -1}, {0, 2, 3, -1}}; + int hexaTet[6][4] = {{0, 1, 3, 7}, {0, 4, 1, 7}, {1, 4, 5, 7}, + {1, 2, 3, 7}, {1, 6, 2, 7}, {1, 5, 6, 7}}; + int prisTet[3][4] = {{0, 1, 2, 4}, {0, 2, 4, 5}, {0, 3, 4, 5}}; + int pyraTet[2][4] = {{0, 1, 3, 4}, {1, 2, 3, 4}}; - if(num < 0 || num > numSimplices()-1) { + if(num < 0 || num > numSimplices() - 1) { Msg::Error("Invalid decomposition"); num = 0; } switch(_numNodes) { - case 4: reorder(quadTri[num], 3, x, y, z, val, xn, yn, zn, valn); break ; - case 8: reorder(hexaTet[num], 4, x, y, z, val, xn, yn, zn, valn); break ; - case 6: reorder(prisTet[num], 4, x, y, z, val, xn, yn, zn, valn); break ; - case 5: reorder(pyraTet[num], 4, x, y, z, val, xn, yn, zn, valn); break ; + case 4: reorder(quadTri[num], 3, x, y, z, val, xn, yn, zn, valn); break; + case 8: reorder(hexaTet[num], 4, x, y, z, val, xn, yn, zn, valn); break; + case 6: reorder(prisTet[num], 4, x, y, z, val, xn, yn, zn, valn); break; + case 5: reorder(pyraTet[num], 4, x, y, z, val, xn, yn, zn, valn); break; } } diff --git a/Plugin/MakeSimplex.h b/Plugin/MakeSimplex.h index 2f692acb0f55fc0599b2772656a1a0d62c71faea..d351ab4d5caf77f290482cf03873a3b06f3c9dac 100644 --- a/Plugin/MakeSimplex.h +++ b/Plugin/MakeSimplex.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterMakeSimplexPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterMakeSimplexPlugin(); } -class GMSH_MakeSimplexPlugin : public GMSH_PostPlugin -{ +class GMSH_MakeSimplexPlugin : public GMSH_PostPlugin { public: - GMSH_MakeSimplexPlugin(){} + GMSH_MakeSimplexPlugin() {} std::string getName() const { return "MakeSimplex"; } std::string getShortHelp() const { @@ -24,12 +22,12 @@ public: } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; -class MakeSimplex{ - private: +class MakeSimplex { +private: // how many nodes in the element to decompose int _numNodes; // how many field components @@ -37,19 +35,18 @@ class MakeSimplex{ // how many time steps int _numTimeSteps; // create a simplex - void reorder(int map[4], int n, - double *x, double *y, double *z, double *val, + void reorder(int map[4], int n, double *x, double *y, double *z, double *val, double *xn, double *yn, double *zn, double *valn); - public: + +public: // default constructor - MakeSimplex(int numNodes, int numComponents, int numTimeSteps=1); + MakeSimplex(int numNodes, int numComponents, int numTimeSteps = 1); // the number of simplices into which the element is decomposed int numSimplices(); // the number of nodes of the simplex int numSimplexNodes(); // returns the i-th simplex in the decomposition - void decompose(int num, - double *x, double *y, double *z, double *val, + void decompose(int num, double *x, double *y, double *z, double *val, double *xn, double *yn, double *zn, double *valn); }; diff --git a/Plugin/MathEval.cpp b/Plugin/MathEval.cpp index 9e730670b2cd85e87aa28716d3201e81440414c8..f06214bb4080518cda14bf3760e15390b65120af 100644 --- a/Plugin/MathEval.cpp +++ b/Plugin/MathEval.cpp @@ -17,8 +17,7 @@ StringXNumber MathEvalOptions_Number[] = { {GMSH_FULLRC, "OtherTimeStep", NULL, -1.}, {GMSH_FULLRC, "OtherView", NULL, -1.}, {GMSH_FULLRC, "ForceInterpolation", NULL, 0.}, - {GMSH_FULLRC, "PhysicalRegion", NULL, -1.} -}; + {GMSH_FULLRC, "PhysicalRegion", NULL, -1.}}; StringXString MathEvalOptions_String[] = { {GMSH_FULLRC, "Expression0", NULL, "Sqrt(v0^2+v1^2+v2^2)"}, @@ -29,46 +28,41 @@ StringXString MathEvalOptions_String[] = { {GMSH_FULLRC, "Expression5", NULL, ""}, {GMSH_FULLRC, "Expression6", NULL, ""}, {GMSH_FULLRC, "Expression7", NULL, ""}, - {GMSH_FULLRC, "Expression8", NULL, ""} -}; + {GMSH_FULLRC, "Expression8", NULL, ""}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterMathEvalPlugin() - { - return new GMSH_MathEvalPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterMathEvalPlugin() { return new GMSH_MathEvalPlugin(); } } std::string GMSH_MathEvalPlugin::getHelp() const { return "Plugin(MathEval) creates a new view using " - "data from the time step `TimeStep' in the view " - "`View'.\n\n" - "If only `Expression0' is given (and `Expression1', " - "..., `Expression8' are all empty), the plugin " - "creates a scalar view. If `Expression0', `Expression1' " - "and/or `Expression2' are given (and `Expression3', " - "..., `Expression8' are all empty) the plugin creates " - "a vector view. Otherwise the plugin creates a tensor " - "view.\n\n" - "In addition to the usual mathematical functions " - "(Exp, Log, Sqrt, Sin, Cos, Fabs, etc.) and operators " - "(+, -, *, /, ^), all expressions can contain:\n\n" - "- the symbols v0, v1, v2, ..., vn, which represent " - "the n components in `View';\n\n" - "- the symbols w0, w1, w2, ..., wn, which represent " - "the n components of `OtherView', at time step " - "`OtherTimeStep';\n\n" - "- the symbols x, y and z, which represent the three " - "spatial coordinates.\n\n" - "If `TimeStep' < 0, the plugin extracts data from all " - "the time steps in the view.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(MathEval) creates one new view." - "If `PhysicalRegion' < 0, the plugin is run " - "on all physical regions.\n\n" - "Plugin(MathEval) creates one new view."; + "data from the time step `TimeStep' in the view " + "`View'.\n\n" + "If only `Expression0' is given (and `Expression1', " + "..., `Expression8' are all empty), the plugin " + "creates a scalar view. If `Expression0', `Expression1' " + "and/or `Expression2' are given (and `Expression3', " + "..., `Expression8' are all empty) the plugin creates " + "a vector view. Otherwise the plugin creates a tensor " + "view.\n\n" + "In addition to the usual mathematical functions " + "(Exp, Log, Sqrt, Sin, Cos, Fabs, etc.) and operators " + "(+, -, *, /, ^), all expressions can contain:\n\n" + "- the symbols v0, v1, v2, ..., vn, which represent " + "the n components in `View';\n\n" + "- the symbols w0, w1, w2, ..., wn, which represent " + "the n components of `OtherView', at time step " + "`OtherTimeStep';\n\n" + "- the symbols x, y and z, which represent the three " + "spatial coordinates.\n\n" + "If `TimeStep' < 0, the plugin extracts data from all " + "the time steps in the view.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(MathEval) creates one new view." + "If `PhysicalRegion' < 0, the plugin is run " + "on all physical regions.\n\n" + "Plugin(MathEval) creates one new view."; } int GMSH_MathEvalPlugin::getNbOptions() const @@ -106,56 +100,57 @@ PView *GMSH_MathEvalPlugin::execute(PView *view) if(!v1) return view; PViewData *data1 = getPossiblyAdaptiveData(v1); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("MathEval plugin cannot be applied to multi-mesh views"); return view; } PView *otherView = v1; - if(iOtherView >= 0){ + if(iOtherView >= 0) { otherView = getView(iOtherView, view); - if(!otherView){ + if(!otherView) { Msg::Error("MathEval plugin could not find other view %i", iOtherView); return view; } } PViewData *otherData = getPossiblyAdaptiveData(otherView); - if(otherData->hasMultipleMeshes()){ + if(otherData->hasMultipleMeshes()) { Msg::Error("MathEval plugin cannot be applied to multi-mesh views"); return view; } - if(otherTimeStep < 0 && otherData->getNumTimeSteps() != data1->getNumTimeSteps()){ + if(otherTimeStep < 0 && + otherData->getNumTimeSteps() != data1->getNumTimeSteps()) { Msg::Error("Number of time steps don't match: using step 0"); otherTimeStep = 0; } - else if(otherTimeStep > otherData->getNumTimeSteps() - 1){ + else if(otherTimeStep > otherData->getNumTimeSteps() - 1) { Msg::Error("Invalid time step (%d) in View[%d]: using step 0 instead", otherTimeStep, otherView->getIndex()); otherTimeStep = 0; } int numComp2; - if(expr[3].size() || expr[4].size() || expr[5].size() || - expr[6].size() || expr[7].size() || expr[8].size()){ + if(expr[3].size() || expr[4].size() || expr[5].size() || expr[6].size() || + expr[7].size() || expr[8].size()) { numComp2 = 9; for(int i = 0; i < 9; i++) if(expr[i].empty()) expr[i] = "0"; } - else if(expr[1].size() || expr[2].size()){ + else if(expr[1].size() || expr[2].size()) { numComp2 = 3; for(int i = 0; i < 3; i++) if(expr[i].empty()) expr[i] = "0"; } - else{ + else { numComp2 = 1; } expr.resize(numComp2); - const char *names[] = - { "x", "y", "z", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", - "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8" }; + const char *names[] = {"x", "y", "z", "v0", "v1", "v2", "v3", + "v4", "v5", "v6", "v7", "v8", "w0", "w1", + "w2", "w3", "w4", "w5", "w6", "w7", "w8"}; unsigned int numVariables = sizeof(names) / sizeof(names[0]); std::vector<std::string> variables(numVariables); for(unsigned int i = 0; i < numVariables; i++) variables[i] = names[i]; @@ -166,7 +161,7 @@ PView *GMSH_MathEvalPlugin::execute(PView *view) OctreePost *octree = 0; if(forceInterpolation || (data1->getNumEntities() != otherData->getNumEntities()) || - (data1->getNumElements() != otherData->getNumElements())){ + (data1->getNumElements() != otherData->getNumElements())) { Msg::Info("Other view based on different grid: interpolating..."); octree = new OctreePost(otherView); } @@ -174,36 +169,37 @@ PView *GMSH_MathEvalPlugin::execute(PView *view) PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - if(timeStep < 0){ - timeStep = - data1->getNumTimeSteps(); + if(timeStep < 0) { + timeStep = -data1->getNumTimeSteps(); } - else if(timeStep > data1->getNumTimeSteps() - 1){ + else if(timeStep > data1->getNumTimeSteps() - 1) { Msg::Error("Invalid time step (%d) in View[%d]: using all steps instead", timeStep, v1->getIndex()); - timeStep = - data1->getNumTimeSteps(); + timeStep = -data1->getNumTimeSteps(); } - int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); + int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); int timeBeg = (timeStep < 0) ? firstNonEmptyStep : timeStep; int timeEnd = (timeStep < 0) ? -timeStep : timeStep + 1; - for(int ent = 0; ent < data1->getNumEntities(timeBeg); ent++){ + for(int ent = 0; ent < data1->getNumEntities(timeBeg); ent++) { bool ok = (physicalRegion <= 0); - if(physicalRegion > 0){ + if(physicalRegion > 0) { GEntity *ge = data1->getEntity(timeBeg, ent); - if(ge){ - std::vector<int>::iterator it = std::find - (ge->physicals.begin(), ge->physicals.end(), physicalRegion); + if(ge) { + std::vector<int>::iterator it = + std::find(ge->physicals.begin(), ge->physicals.end(), physicalRegion); ok = (it != ge->physicals.end()); } } if(!ok) continue; - for(int ele = 0; ele < data1->getNumElements(timeBeg, ent); ele++){ + for(int ele = 0; ele < data1->getNumElements(timeBeg, ent); ele++) { if(data1->skipElement(timeBeg, ent, ele)) continue; int numNodes = data1->getNumNodes(timeBeg, ent, ele); int type = data1->getType(timeBeg, ent, ele); int numComp = data1->getNumComponents(timeBeg, ent, ele); - int otherNumComp = (!otherData || octree) ? 9 : - otherData->getNumComponents(timeBeg, ent, ele); + int otherNumComp = (!otherData || octree) ? + 9 : + otherData->getNumComponents(timeBeg, ent, ele); std::vector<double> *out = data2->incrementList(numComp2, type, numNodes); std::vector<double> v(std::max(9, numComp), 0.); std::vector<double> w(std::max(9, otherNumComp), 0.); @@ -213,34 +209,35 @@ PView *GMSH_MathEvalPlugin::execute(PView *view) for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); - for(int step = timeBeg; step < timeEnd; step++){ - if(!data1->hasTimeStep(step)) continue; + for(int step = timeBeg; step < timeEnd; step++) { + if(!data1->hasTimeStep(step)) continue; int step2 = (otherTimeStep < 0) ? step : otherTimeStep; - for(int nod = 0; nod < numNodes; nod++){ + for(int nod = 0; nod < numNodes; nod++) { for(int comp = 0; comp < numComp; comp++) data1->getValue(step, ent, ele, nod, comp, v[comp]); - if(otherData){ - if(octree){ + if(otherData) { + if(octree) { int qn = forceInterpolation ? numNodes : 0; - if(!octree->searchScalar(x[nod], y[nod], z[nod], &w[0], step2, - 0, qn, &x[0], &y[0], &z[0])) + if(!octree->searchScalar(x[nod], y[nod], z[nod], &w[0], step2, 0, + qn, &x[0], &y[0], &z[0])) if(!octree->searchVector(x[nod], y[nod], z[nod], &w[0], step2, 0, qn, &x[0], &y[0], &z[0])) - octree->searchTensor(x[nod], y[nod], z[nod], &w[0], step2, - 0, qn, &x[0], &y[0], &z[0]); + octree->searchTensor(x[nod], y[nod], z[nod], &w[0], step2, 0, + qn, &x[0], &y[0], &z[0]); } else for(int comp = 0; comp < otherNumComp; comp++) otherData->getValue(step2, ent, ele, nod, comp, w[comp]); } - values[0] = x[nod]; values[1] = y[nod]; values[2] = z[nod]; + values[0] = x[nod]; + values[1] = y[nod]; + values[2] = z[nod]; for(int i = 0; i < 9; i++) values[3 + i] = v[i]; for(int i = 0; i < 9; i++) values[12 + i] = w[i]; - if(f.eval(values, res)){ - for(int i = 0; i < numComp2; i++) - out->push_back(res[i]); + if(f.eval(values, res)) { + for(int i = 0; i < numComp2; i++) out->push_back(res[i]); } - else{ + else { goto end; } } @@ -248,10 +245,10 @@ PView *GMSH_MathEvalPlugin::execute(PView *view) } } - end: +end: if(octree) delete octree; - if(timeStep < 0){ + if(timeStep < 0) { for(int i = firstNonEmptyStep; i < data1->getNumTimeSteps(); i++) { if(!data1->hasTimeStep(i)) continue; data2->Time.push_back(data1->getTime(i)); diff --git a/Plugin/MathEval.h b/Plugin/MathEval.h index 25c2e5f6c1cf8f6ca14c77ef0c1573e0e86834bf..859588664e88ea328d41c3a936679d10e774d61d 100644 --- a/Plugin/MathEval.h +++ b/Plugin/MathEval.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterMathEvalPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterMathEvalPlugin(); } -class GMSH_MathEvalPlugin : public GMSH_PostPlugin -{ - public: - GMSH_MathEvalPlugin(){} +class GMSH_MathEvalPlugin : public GMSH_PostPlugin { +public: + GMSH_MathEvalPlugin() {} std::string getName() const { return "MathEval"; } std::string getShortHelp() const { @@ -24,9 +22,9 @@ class GMSH_MathEvalPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); }; diff --git a/Plugin/MeshSubEntities.cpp b/Plugin/MeshSubEntities.cpp index 7e9f5039944a1ef0528a61998a185e7a6279f828..c1139a90e8849554717815c8a02df7b4fcd28331 100644 --- a/Plugin/MeshSubEntities.cpp +++ b/Plugin/MeshSubEntities.cpp @@ -24,21 +24,20 @@ StringXNumber MeshSubEntitiesOptions_Number[] = { {GMSH_FULLRC, "OuputPhysicalGroup", NULL, 2000.}, }; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterMeshSubEntitiesPlugin() { - GMSH_Plugin *GMSH_RegisterMeshSubEntitiesPlugin() - { - return new GMSH_MeshSubEntitiesPlugin(); - } + return new GMSH_MeshSubEntitiesPlugin(); +} } std::string GMSH_MeshSubEntitiesPlugin::getHelp() const { return "Plugin(MeshSubEntities) creates mesh elements for the " - "entities of dimension `OutputDimension' (0 for vertices, " - "1 for edges, 2 for faces) of the `InputPhysicalGroup' of " - "dimension `InputDimension'. The plugin creates new elements " - "belonging to `OutputPhysicalGroup'."; + "entities of dimension `OutputDimension' (0 for vertices, " + "1 for edges, 2 for faces) of the `InputPhysicalGroup' of " + "dimension `InputDimension'. The plugin creates new elements " + "belonging to `OutputPhysicalGroup'."; } int GMSH_MeshSubEntitiesPlugin::getNbOptions() const @@ -59,88 +58,87 @@ PView *GMSH_MeshSubEntitiesPlugin::execute(PView *view) int outphysical = (int)MeshSubEntitiesOptions_Number[3].def; if(inputdim < 0 || inputdim > 3 || outputdim < 0 || outputdim > 3 || - outputdim > inputdim){ + outputdim > inputdim) { Msg::Error("Bad dimensions"); return view; } GModel *m = GModel::current(); - std::map<int, std::vector<GEntity*> > groups; + std::map<int, std::vector<GEntity *> > groups; m->getPhysicalGroups(inputdim, groups); - std::vector<GEntity*> entities = groups[inputphysical]; + std::vector<GEntity *> entities = groups[inputphysical]; - if(entities.empty()){ - Msg::Error("Physical group %d (dimension %d) is empty", inputphysical, inputdim); + if(entities.empty()) { + Msg::Error("Physical group %d (dimension %d) is empty", inputphysical, + inputdim); return view; } // get input elements - std::vector<MElement*> elements; + std::vector<MElement *> elements; for(unsigned int i = 0; i < entities.size(); i++) for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++) elements.push_back(entities[i]->getMeshElement(j)); - if(outputdim == 0){ // create point elements for mesh vertices - std::set<MVertex*> vertices; - for(unsigned int i = 0; i < elements.size(); i++){ - for(std::size_t j = 0; j < elements[i]->getNumVertices(); j++){ + if(outputdim == 0) { // create point elements for mesh vertices + std::set<MVertex *> vertices; + for(unsigned int i = 0; i < elements.size(); i++) { + for(std::size_t j = 0; j < elements[i]->getNumVertices(); j++) { MVertex *v = elements[i]->getVertex(j); vertices.insert(v); } } - for(std::set<MVertex*>::const_iterator it = vertices.begin(); - it != vertices.end(); ++it){ + for(std::set<MVertex *>::const_iterator it = vertices.begin(); + it != vertices.end(); ++it) { MVertex *v = *it; GVertex *gv = 0; - if(v->onWhat() && v->onWhat()->dim() == 0){ - gv = (GVertex*)v->onWhat(); + if(v->onWhat() && v->onWhat()->dim() == 0) { + gv = (GVertex *)v->onWhat(); } - else{ + else { gv = new discreteVertex(m, m->getMaxElementaryNumber(0) + 1); v->setEntity(gv); m->add(gv); } gv->physicals.push_back(outphysical); - if(gv->points.empty()) - gv->points.push_back(new MPoint(v)); + if(gv->points.empty()) gv->points.push_back(new MPoint(v)); } m->pruneMeshVertexAssociations(); } - else if(outputdim == 1){ // create line elements for mesh edges + else if(outputdim == 1) { // create line elements for mesh edges std::set<MEdge, Less_Edge> edges; - for(unsigned int i = 0; i < elements.size(); i++){ - for(int j = 0; j < elements[i]->getNumEdges(); j++){ + for(unsigned int i = 0; i < elements.size(); i++) { + for(int j = 0; j < elements[i]->getNumEdges(); j++) { MEdge e = elements[i]->getEdge(j); edges.insert(e); } } for(std::set<MEdge, Less_Edge>::const_iterator it = edges.begin(); - it != edges.end(); ++it){ + it != edges.end(); ++it) { const MEdge &e = *it; GEdge *ge = 0; MVertex *v0 = e.getVertex(0), *v1 = e.getVertex(1); - if(v0->onWhat() && v1->onWhat()){ + if(v0->onWhat() && v1->onWhat()) { if(v0->onWhat()->dim() == 1 && ((v1->onWhat()->dim() == 1 && v0->onWhat() == v1->onWhat()) || - v1->onWhat()->dim() == 0)) - ge = (GEdge*)v0->onWhat(); + v1->onWhat()->dim() == 0)) + ge = (GEdge *)v0->onWhat(); else if(v1->onWhat()->dim() == 1 && ((v0->onWhat()->dim() == 1 && v0->onWhat() == v1->onWhat()) || - v0->onWhat()->dim() == 0)) - ge = (GEdge*)v1->onWhat(); + v0->onWhat()->dim() == 0)) + ge = (GEdge *)v1->onWhat(); } - if(!ge){ + if(!ge) { ge = new discreteEdge(m, m->getMaxElementaryNumber(1) + 1, 0, 0); v0->setEntity(ge); v1->setEntity(ge); m->add(ge); } ge->physicals.push_back(outphysical); - if(ge->lines.empty()) - ge->lines.push_back(new MLine(v0, v1)); + if(ge->lines.empty()) ge->lines.push_back(new MLine(v0, v1)); } } - else{ + else { Msg::Error("Plugin(MeshSubEntities) not coded yet for output dim %d", outputdim); } diff --git a/Plugin/MeshSubEntities.h b/Plugin/MeshSubEntities.h index 0e95a6484c5f2dbe2b8cabea34e1532347147750..826e2aa6972a897ccec5521792f39192b2e20fae 100644 --- a/Plugin/MeshSubEntities.h +++ b/Plugin/MeshSubEntities.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterMeshSubEntitiesPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterMeshSubEntitiesPlugin(); } -class GMSH_MeshSubEntitiesPlugin : public GMSH_PostPlugin -{ - public: - GMSH_MeshSubEntitiesPlugin(){} +class GMSH_MeshSubEntitiesPlugin : public GMSH_PostPlugin { +public: + GMSH_MeshSubEntitiesPlugin() {} std::string getName() const { return "MeshSubEntities"; } - std::string getShortHelp() const - { - return "Mesh subentities generator"; - } + std::string getShortHelp() const { return "Mesh subentities generator"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/MinMax.cpp b/Plugin/MinMax.cpp index cfa80202906f225ea56763581c0d31035d0f5ec3..279288d809b329db04f7df72778318d9a66c687a 100644 --- a/Plugin/MinMax.cpp +++ b/Plugin/MinMax.cpp @@ -6,30 +6,24 @@ #include "MinMax.h" #include "PViewOptions.h" -StringXNumber MinMaxOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.}, - {GMSH_FULLRC, "OverTime", NULL, 0}, - {GMSH_FULLRC, "Argument", NULL, 0}, - {GMSH_FULLRC, "Visible", NULL, 1} -}; - -extern "C" -{ - GMSH_Plugin *GMSH_RegisterMinMaxPlugin() - { - return new GMSH_MinMaxPlugin(); - } +StringXNumber MinMaxOptions_Number[] = {{GMSH_FULLRC, "View", NULL, -1.}, + {GMSH_FULLRC, "OverTime", NULL, 0}, + {GMSH_FULLRC, "Argument", NULL, 0}, + {GMSH_FULLRC, "Visible", NULL, 1}}; + +extern "C" { +GMSH_Plugin *GMSH_RegisterMinMaxPlugin() { return new GMSH_MinMaxPlugin(); } } std::string GMSH_MinMaxPlugin::getHelp() const { return "Plugin(MinMax) computes the min/max of a view.\n\n" - "If `View' < 0, the plugin is run on the current view. " - "If `OverTime' = 1, the plugin calculates the min/max over " - "space and time. If `Argument' = 1, the plugin calculates the " - "min/max and the argmin/argmax. If `Visible' = 1, the plugin " - "is only applied to visible entities.\n\n" - "Plugin(MinMax) creates two new views."; + "If `View' < 0, the plugin is run on the current view. " + "If `OverTime' = 1, the plugin calculates the min/max over " + "space and time. If `Argument' = 1, the plugin calculates the " + "min/max and the argmin/argmax. If `Visible' = 1, the plugin " + "is only applied to visible entities.\n\n" + "Plugin(MinMax) creates two new views."; } int GMSH_MinMaxPlugin::getNbOptions() const @@ -42,7 +36,7 @@ StringXNumber *GMSH_MinMaxPlugin::getOption(int iopt) return &MinMaxOptions_Number[iopt]; } -PView *GMSH_MinMaxPlugin::execute(PView * v) +PView *GMSH_MinMaxPlugin::execute(PView *v) { int iView = (int)MinMaxOptions_Number[0].def; int overTime = (int)MinMaxOptions_Number[1].def; @@ -58,70 +52,78 @@ PView *GMSH_MinMaxPlugin::execute(PView * v) PViewDataList *dataMin = getDataList(vMin); PViewDataList *dataMax = getDataList(vMax); - if(!argument){ + if(!argument) { double x = data1->getBoundingBox().center().x(); double y = data1->getBoundingBox().center().y(); double z = data1->getBoundingBox().center().z(); - dataMin->SP.push_back(x); dataMin->SP.push_back(y); dataMin->SP.push_back(z); - dataMax->SP.push_back(x); dataMax->SP.push_back(y); dataMax->SP.push_back(z); + dataMin->SP.push_back(x); + dataMin->SP.push_back(y); + dataMin->SP.push_back(z); + dataMax->SP.push_back(x); + dataMax->SP.push_back(y); + dataMax->SP.push_back(z); dataMin->NbSP = 1; dataMax->NbSP = 1; } double min = VAL_INF, max = -VAL_INF, timeMin = 0, timeMax = 0; - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - if(data1->hasTimeStep(step)){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + if(data1->hasTimeStep(step)) { double minView = VAL_INF, maxView = -VAL_INF; double xmin = 0., ymin = 0., zmin = 0., xmax = 0., ymax = 0., zmax = 0.; - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { if(visible && data1->skipEntity(step, ent)) continue; - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ - if(data1->skipElement(step, ent, ele, visible)) continue; - for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){ - double val; - data1->getScalarValue(step, ent, ele, nod, val); - if(val < minView){ - data1->getNode(step, ent, ele, nod, xmin, ymin, zmin); - minView = val; - } - if(val > maxView){ - data1->getNode(step, ent, ele, nod, xmax, ymax, zmax); - maxView = val; - } - } - } + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { + if(data1->skipElement(step, ent, ele, visible)) continue; + for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) { + double val; + data1->getScalarValue(step, ent, ele, nod, val); + if(val < minView) { + data1->getNode(step, ent, ele, nod, xmin, ymin, zmin); + minView = val; + } + if(val > maxView) { + data1->getNode(step, ent, ele, nod, xmax, ymax, zmax); + maxView = val; + } + } + } } - if(!overTime){ - if(argument){ - dataMin->SP.push_back(xmin); dataMin->SP.push_back(ymin); dataMin->SP.push_back(zmin); - dataMax->SP.push_back(xmax); dataMax->SP.push_back(ymax); dataMax->SP.push_back(zmax); - (dataMin->NbSP)++; - (dataMax->NbSP)++; - } - else{ + if(!overTime) { + if(argument) { + dataMin->SP.push_back(xmin); + dataMin->SP.push_back(ymin); + dataMin->SP.push_back(zmin); + dataMax->SP.push_back(xmax); + dataMax->SP.push_back(ymax); + dataMax->SP.push_back(zmax); + (dataMin->NbSP)++; + (dataMax->NbSP)++; + } + else { double time = data1->getTime(step); dataMin->Time.push_back(time); dataMax->Time.push_back(time); } - dataMin->SP.push_back(minView); - dataMax->SP.push_back(maxView); + dataMin->SP.push_back(minView); + dataMax->SP.push_back(maxView); } - else{ - if(minView < min){ - min = minView; - timeMin = data1->getTime(step); - } - if(maxView > max){ - max = maxView; - timeMax = data1->getTime(step); - } + else { + if(minView < min) { + min = minView; + timeMin = data1->getTime(step); + } + if(maxView > max) { + max = maxView; + timeMax = data1->getTime(step); + } } } } - if(overTime){ + if(overTime) { dataMin->SP.push_back(min); dataMax->SP.push_back(max); dataMin->Time.push_back(timeMin); diff --git a/Plugin/MinMax.h b/Plugin/MinMax.h index 7fdcda3c78f42a296bc1e6c4366336810e882325..13dc72baa0ae9f8d4c7eae91b0a10148adbb6a96 100644 --- a/Plugin/MinMax.h +++ b/Plugin/MinMax.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterMinMaxPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterMinMaxPlugin(); } -class GMSH_MinMaxPlugin : public GMSH_PostPlugin -{ - public: - GMSH_MinMaxPlugin(){} +class GMSH_MinMaxPlugin : public GMSH_PostPlugin { +public: + GMSH_MinMaxPlugin() {} std::string getName() const { return "MinMax"; } - std::string getShortHelp() const - { - return "Get the min/max of a dataset"; - } + std::string getShortHelp() const { return "Get the min/max of a dataset"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/ModifyComponents.cpp b/Plugin/ModifyComponents.cpp index f6f116b4dab7f7687d9b6b425c593f98fff1a943..ee0d75ed8cc1fd4ecaa1503f3825acb16a4a40d2 100644 --- a/Plugin/ModifyComponents.cpp +++ b/Plugin/ModifyComponents.cpp @@ -15,8 +15,7 @@ StringXNumber ModifyComponentsOptions_Number[] = { {GMSH_FULLRC, "View", NULL, -1.}, {GMSH_FULLRC, "OtherTimeStep", NULL, -1.}, {GMSH_FULLRC, "OtherView", NULL, -1.}, - {GMSH_FULLRC, "ForceInterpolation", NULL, 0.} -}; + {GMSH_FULLRC, "ForceInterpolation", NULL, 0.}}; StringXString ModifyComponentsOptions_String[] = { {GMSH_FULLRC, "Expression0", NULL, "v0 * Sin(x)"}, @@ -27,48 +26,46 @@ StringXString ModifyComponentsOptions_String[] = { {GMSH_FULLRC, "Expression5", NULL, ""}, {GMSH_FULLRC, "Expression6", NULL, ""}, {GMSH_FULLRC, "Expression7", NULL, ""}, - {GMSH_FULLRC, "Expression8", NULL, ""} -}; + {GMSH_FULLRC, "Expression8", NULL, ""}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterModifyComponentsPlugin() { - GMSH_Plugin *GMSH_RegisterModifyComponentsPlugin() - { - return new GMSH_ModifyComponentsPlugin(); - } + return new GMSH_ModifyComponentsPlugin(); +} } std::string GMSH_ModifyComponentsPlugin::getHelp() const { return "Plugin(ModifyComponents) modifies the components of " - "the `TimeStep'-th time step in the view `View', using the " - "expressions provided in `Expression0', ..., `Expression8'. " - "If an expression is empty, the corresponding component in " - "the view is not modified.\n\n" - "The expressions can contain:\n\n" - "- the usual mathematical functions (Log, Sqrt, " - "Sin, Cos, Fabs, ...) and operators (+, -, *, /, ^);\n\n" - "- the symbols x, y and z, to retrieve the " - "coordinates of the current node;\n\n" - "- the symbols Time and TimeStep, to retrieve the " - "current time and time step values;\n\n" - "- the symbols v0, v1, v2, ..., v8, to retrieve each " - "component of the field in `View' at the " - "`TimeStep'-th time step;\n\n" - "- the symbols w0, w1, w2, ..., w8, to retrieve each " - "component of the field in `OtherView' at the " - "`OtherTimeStep'-th time step. If `OtherView' " - "and `View' are based on different spatial grids, " - "or if their data types are different, `OtherView' " - "is interpolated onto `View'.\n\n" - "If `TimeStep' < 0, the plugin automatically loops " - "over all the time steps in `View' and evaluates " - "the expressions for each one.\n\n" - "If `OtherTimeStep' < 0, the plugin uses `TimeStep' " - "instead.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "If `OtherView' < 0, the plugin uses `View' instead.\n\n" - "Plugin(ModifyComponents) is executed in-place."; + "the `TimeStep'-th time step in the view `View', using the " + "expressions provided in `Expression0', ..., `Expression8'. " + "If an expression is empty, the corresponding component in " + "the view is not modified.\n\n" + "The expressions can contain:\n\n" + "- the usual mathematical functions (Log, Sqrt, " + "Sin, Cos, Fabs, ...) and operators (+, -, *, /, ^);\n\n" + "- the symbols x, y and z, to retrieve the " + "coordinates of the current node;\n\n" + "- the symbols Time and TimeStep, to retrieve the " + "current time and time step values;\n\n" + "- the symbols v0, v1, v2, ..., v8, to retrieve each " + "component of the field in `View' at the " + "`TimeStep'-th time step;\n\n" + "- the symbols w0, w1, w2, ..., w8, to retrieve each " + "component of the field in `OtherView' at the " + "`OtherTimeStep'-th time step. If `OtherView' " + "and `View' are based on different spatial grids, " + "or if their data types are different, `OtherView' " + "is interpolated onto `View'.\n\n" + "If `TimeStep' < 0, the plugin automatically loops " + "over all the time steps in `View' and evaluates " + "the expressions for each one.\n\n" + "If `OtherTimeStep' < 0, the plugin uses `TimeStep' " + "instead.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "If `OtherView' < 0, the plugin uses `View' instead.\n\n" + "Plugin(ModifyComponents) is executed in-place."; } int GMSH_ModifyComponentsPlugin::getNbOptions() const @@ -104,7 +101,7 @@ PView *GMSH_ModifyComponentsPlugin::execute(PView *view) PViewData *data1 = v1->getData(); - if(timeStep > data1->getNumTimeSteps() - 1){ + if(timeStep > data1->getNumTimeSteps() - 1) { Msg::Error("Invalid time step (%d) in View[%d]: using step 0 instead", timeStep, v1->getIndex()); timeStep = 0; @@ -112,7 +109,7 @@ PView *GMSH_ModifyComponentsPlugin::execute(PView *view) PView *v2 = v1; - if(otherView >= 0){ + if(otherView >= 0) { if(otherView < (int)PView::list.size()) v2 = PView::list[otherView]; else @@ -121,18 +118,19 @@ PView *GMSH_ModifyComponentsPlugin::execute(PView *view) PViewData *data2 = getPossiblyAdaptiveData(v2); - if(otherTimeStep < 0 && data2->getNumTimeSteps() != data1->getNumTimeSteps()){ + if(otherTimeStep < 0 && + data2->getNumTimeSteps() != data1->getNumTimeSteps()) { Msg::Error("Number of time steps don't match: using step 0"); otherTimeStep = 0; } - else if(otherTimeStep > data2->getNumTimeSteps() - 1){ + else if(otherTimeStep > data2->getNumTimeSteps() - 1) { Msg::Error("Invalid time step (%d) in View[%d]: using step 0 instead", otherTimeStep, v2->getIndex()); otherTimeStep = 0; } std::vector<std::string> expressions(9), expressions0(9); - for(int i = 0; i < 9; i++){ + for(int i = 0; i < 9; i++) { expressions[i] = ModifyComponentsOptions_String[i].def; if(expressions[i].size()) expressions0[i] = expressions[i]; @@ -140,10 +138,9 @@ PView *GMSH_ModifyComponentsPlugin::execute(PView *view) expressions0[i] = "0."; } - const char *names[] = - {"x", "y", "z", "Time", "TimeStep", - "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", - "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8"}; + const char *names[] = {"x", "y", "z", "Time", "TimeStep", "v0", "v1", "v2", + "v3", "v4", "v5", "v6", "v7", "v8", "w0", "w1", + "w2", "w3", "w4", "w5", "w6", "w7", "w8"}; unsigned int numVariables = sizeof(names) / sizeof(names[0]); std::vector<std::string> variables(numVariables); for(unsigned int i = 0; i < numVariables; i++) variables[i] = names[i]; @@ -154,21 +151,21 @@ PView *GMSH_ModifyComponentsPlugin::execute(PView *view) OctreePost *octree = 0; if(forceInterpolation || (data1->getNumEntities() != data2->getNumEntities()) || - (data1->getNumElements() != data2->getNumElements())){ + (data1->getNumElements() != data2->getNumElements())) { Msg::Info("Other view based on different grid: interpolating..."); octree = new OctreePost(v2); } - for(int step = 0; step < data1->getNumTimeSteps(); step++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { if(timeStep >= 0 && timeStep != step) continue; double time = data1->getTime(step); int step2 = (otherTimeStep < 0) ? step : otherTimeStep; - if(data1->isNodeData()){ + if(data1->isNodeData()) { // tag all the nodes with "0" (the default tag) - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) data1->tagNode(step, ent, ele, nod, 0); @@ -176,8 +173,8 @@ PView *GMSH_ModifyComponentsPlugin::execute(PView *view) } } - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; int numComp = data1->getNumComponents(step, ent, ele); int numComp2 = octree ? 9 : data2->getNumComponents(step2, ent, ele); @@ -185,33 +182,38 @@ PView *GMSH_ModifyComponentsPlugin::execute(PView *view) std::vector<double> x(numNodes), y(numNodes), z(numNodes); std::vector<int> tag(numNodes); for(int nod = 0; nod < numNodes; nod++) - tag[nod] = data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); - for(int nod = 0; nod < numNodes; nod++){ - if(data1->isNodeData() && tag[nod]) continue; // node has already been modified + tag[nod] = + data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); + for(int nod = 0; nod < numNodes; nod++) { + if(data1->isNodeData() && tag[nod]) + continue; // node has already been modified std::vector<double> v(std::max(9, numComp), 0.); for(int comp = 0; comp < numComp; comp++) data1->getValue(step, ent, ele, nod, comp, v[comp]); std::vector<double> w(std::max(9, numComp2), 0.); - if(octree){ + if(octree) { int qn = forceInterpolation ? numNodes : 0; - if(!octree->searchScalar(x[nod], y[nod], z[nod], &w[0], step2, - 0, qn, &x[0], &y[0], &z[0])) - if(!octree->searchVector(x[nod], y[nod], z[nod], &w[0], step2, - 0, qn, &x[0], &y[0], &z[0])) - octree->searchTensor(x[nod], y[nod], z[nod], &w[0], step2, - 0, qn, &x[0], &y[0], &z[0]); + if(!octree->searchScalar(x[nod], y[nod], z[nod], &w[0], step2, 0, + qn, &x[0], &y[0], &z[0])) + if(!octree->searchVector(x[nod], y[nod], z[nod], &w[0], step2, 0, + qn, &x[0], &y[0], &z[0])) + octree->searchTensor(x[nod], y[nod], z[nod], &w[0], step2, 0, + qn, &x[0], &y[0], &z[0]); } - else{ + else { for(int comp = 0; comp < numComp2; comp++) data2->getValue(step2, ent, ele, nod, comp, w[comp]); } - values[0] = x[nod]; values[1] = y[nod]; values[2] = z[nod]; - values[3] = time; values[4] = step; + values[0] = x[nod]; + values[1] = y[nod]; + values[2] = z[nod]; + values[3] = time; + values[4] = step; for(int i = 0; i < 9; i++) values[5 + i] = v[i]; for(int i = 0; i < 9; i++) values[14 + i] = w[i]; - if(f.eval(values, res)){ - for(int comp = 0; comp < numComp; comp++){ - if(expressions[comp].size()){ + if(f.eval(values, res)) { + for(int comp = 0; comp < numComp; comp++) { + if(expressions[comp].size()) { data1->setValue(step, ent, ele, nod, comp, res[comp]); } } diff --git a/Plugin/ModifyComponents.h b/Plugin/ModifyComponents.h index 0e53acbeb6d28641c2e8df3187bf7b63b9db09cc..a8a13ec3519670e9c8475d4518f9578634fd2369 100644 --- a/Plugin/ModifyComponents.h +++ b/Plugin/ModifyComponents.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterModifyComponentsPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterModifyComponentsPlugin(); } -class GMSH_ModifyComponentsPlugin : public GMSH_PostPlugin -{ - public: - GMSH_ModifyComponentsPlugin(){} +class GMSH_ModifyComponentsPlugin : public GMSH_PostPlugin { +public: + GMSH_ModifyComponentsPlugin() {} std::string getName() const { return "ModifyComponents"; } std::string getShortHelp() const { @@ -24,9 +22,9 @@ class GMSH_ModifyComponentsPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); }; diff --git a/Plugin/ModulusPhase.cpp b/Plugin/ModulusPhase.cpp index 745b2355ed3eb72f55532bdcc7f7cd720172f02d..2be2d756d1c6986b4cd5a3c1259ffa37714c5c77 100644 --- a/Plugin/ModulusPhase.cpp +++ b/Plugin/ModulusPhase.cpp @@ -8,26 +8,24 @@ StringXNumber ModulusPhaseOptions_Number[] = { {GMSH_FULLRC, "RealPart", NULL, 0.}, {GMSH_FULLRC, "ImaginaryPart", NULL, 1.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterModulusPhasePlugin() { - GMSH_Plugin *GMSH_RegisterModulusPhasePlugin() - { - return new GMSH_ModulusPhasePlugin(); - } + return new GMSH_ModulusPhasePlugin(); +} } std::string GMSH_ModulusPhasePlugin::getHelp() const { return "Plugin(ModulusPhase) interprets the time steps " - "`realPart' and `imaginaryPart' in the view `View' " - "as the real and imaginary parts of a complex field " - "and replaces them with their corresponding " - "modulus and phase.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(ModulusPhase) is executed in-place."; + "`realPart' and `imaginaryPart' in the view `View' " + "as the real and imaginary parts of a complex field " + "and replaces them with their corresponding " + "modulus and phase.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(ModulusPhase) is executed in-place."; } int GMSH_ModulusPhasePlugin::getNbOptions() const @@ -50,22 +48,22 @@ PView *GMSH_ModulusPhasePlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = v1->getData(); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("ModulusPhase plugin cannot be run on multi-mesh views"); return v; } - if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || - iIndex < 0 || iIndex >= data1->getNumTimeSteps()){ + if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || iIndex < 0 || + iIndex >= data1->getNumTimeSteps()) { Msg::Error("Wrong real or imaginary part index"); return v1; } - if(data1->isNodeData()){ + if(data1->isNodeData()) { // tag all the nodes with "0" (the default tag) - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) data1->tagNode(step, ent, ele, nod, 0); @@ -75,14 +73,15 @@ PView *GMSH_ModulusPhasePlugin::execute(PView *v) } // transform all "0" nodes - for(int ent = 0; ent < data1->getNumEntities(rIndex); ent++){ - for(int ele = 0; ele < data1->getNumElements(rIndex, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(rIndex); ent++) { + for(int ele = 0; ele < data1->getNumElements(rIndex, ent); ele++) { if(data1->skipElement(rIndex, ent, ele)) continue; - for(int nod = 0; nod < data1->getNumNodes(rIndex, ent, ele); nod++){ + for(int nod = 0; nod < data1->getNumNodes(rIndex, ent, ele); nod++) { double x, y, z; int tag = data1->getNode(rIndex, ent, ele, nod, x, y, z); if(data1->isNodeData() && tag) continue; - for(int comp = 0; comp < data1->getNumComponents(rIndex, ent, ele); comp++){ + for(int comp = 0; comp < data1->getNumComponents(rIndex, ent, ele); + comp++) { double vr, vi; data1->getValue(rIndex, ent, ele, nod, comp, vr); data1->getValue(iIndex, ent, ele, nod, comp, vi); @@ -90,7 +89,7 @@ PView *GMSH_ModulusPhasePlugin::execute(PView *v) double phase = atan2(vi, vr); data1->setValue(rIndex, ent, ele, nod, comp, modulus); data1->setValue(iIndex, ent, ele, nod, comp, phase); - if(data1->isNodeData()){ + if(data1->isNodeData()) { data1->tagNode(rIndex, ent, ele, nod, 1); data1->tagNode(iIndex, ent, ele, nod, 1); } diff --git a/Plugin/ModulusPhase.h b/Plugin/ModulusPhase.h index 7723685c86883e1ee3f1d0ad9d14028e0eadf4a8..dad72e4c9da6da1e267caa7f0b559c2ebcb98fdd 100644 --- a/Plugin/ModulusPhase.h +++ b/Plugin/ModulusPhase.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterModulusPhasePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterModulusPhasePlugin(); } -class GMSH_ModulusPhasePlugin : public GMSH_PostPlugin -{ - public: - GMSH_ModulusPhasePlugin(){} +class GMSH_ModulusPhasePlugin : public GMSH_PostPlugin { +public: + GMSH_ModulusPhasePlugin() {} std::string getName() const { return "ModulusPhase"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_ModulusPhasePlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/NearToFarField.cpp b/Plugin/NearToFarField.cpp index 6f916de924c42f3bc6c47fc0e124b3e578280890..90521f51788fad46d10ec5da545866bf659b8858 100644 --- a/Plugin/NearToFarField.cpp +++ b/Plugin/NearToFarField.cpp @@ -12,48 +12,47 @@ #include "OS.h" StringXNumber NearToFarFieldOptions_Number[] = { - {GMSH_FULLRC, "Wavenumber", NULL, 1.}, - {GMSH_FULLRC, "PhiStart", NULL, 0.}, - {GMSH_FULLRC, "PhiEnd", NULL, 2. * M_PI}, - {GMSH_FULLRC, "NumPointsPhi", NULL, 60}, - {GMSH_FULLRC, "ThetaStart", NULL, 0.}, - {GMSH_FULLRC, "ThetaEnd", NULL, M_PI}, - {GMSH_FULLRC, "NumPointsTheta", NULL, 30}, - {GMSH_FULLRC, "EView", NULL, 0}, - {GMSH_FULLRC, "HView", NULL, 1}, - {GMSH_FULLRC, "Normalize", NULL, 1}, - {GMSH_FULLRC, "dB", NULL, 1}, - {GMSH_FULLRC, "NegativeTime", NULL, 0.}, - {GMSH_FULLRC, "RFar", NULL, 0}, + {GMSH_FULLRC, "Wavenumber", NULL, 1.}, + {GMSH_FULLRC, "PhiStart", NULL, 0.}, + {GMSH_FULLRC, "PhiEnd", NULL, 2. * M_PI}, + {GMSH_FULLRC, "NumPointsPhi", NULL, 60}, + {GMSH_FULLRC, "ThetaStart", NULL, 0.}, + {GMSH_FULLRC, "ThetaEnd", NULL, M_PI}, + {GMSH_FULLRC, "NumPointsTheta", NULL, 30}, + {GMSH_FULLRC, "EView", NULL, 0}, + {GMSH_FULLRC, "HView", NULL, 1}, + {GMSH_FULLRC, "Normalize", NULL, 1}, + {GMSH_FULLRC, "dB", NULL, 1}, + {GMSH_FULLRC, "NegativeTime", NULL, 0.}, + {GMSH_FULLRC, "RFar", NULL, 0}, }; StringXString NearToFarFieldOptions_String[] = { - {GMSH_FULLRC, "MatlabOutputFile", NULL, "farfield.m"}, + {GMSH_FULLRC, "MatlabOutputFile", NULL, "farfield.m"}, }; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterNearToFarFieldPlugin() { - GMSH_Plugin *GMSH_RegisterNearToFarFieldPlugin() - { - return new GMSH_NearToFarFieldPlugin(); - } + return new GMSH_NearToFarFieldPlugin(); +} } std::string GMSH_NearToFarFieldPlugin::getHelp() const { return "Plugin(NearToFarField) computes the far field pattern " - "from the near electric E and magnetic H fields on a surface " - "enclosing the radiating device (antenna).\n\n" - "Parameters: the wavenumber, the " - "angular discretisation (phi in [0, 2*Pi] and theta in [0, Pi]) " - "of the far field sphere and the indices of the views containing the " - "complex-valued E and H fields. If `Normalize' is set, the far field " - "is normalized to 1. If `dB' is set, the far field is computed in dB. " - "If `NegativeTime' is set, E and H are assumed to have exp(-iwt) time " - "dependency; otherwise they are assume to have exp(+iwt) time " - "dependency. If `MatlabOutputFile' is given the raw far field data is " - "also exported in Matlab format.\n\n" - "Plugin(NearToFarField) creates one new view."; + "from the near electric E and magnetic H fields on a surface " + "enclosing the radiating device (antenna).\n\n" + "Parameters: the wavenumber, the " + "angular discretisation (phi in [0, 2*Pi] and theta in [0, Pi]) " + "of the far field sphere and the indices of the views containing the " + "complex-valued E and H fields. If `Normalize' is set, the far field " + "is normalized to 1. If `dB' is set, the far field is computed in dB. " + "If `NegativeTime' is set, E and H are assumed to have exp(-iwt) time " + "dependency; otherwise they are assume to have exp(+iwt) time " + "dependency. If `MatlabOutputFile' is given the raw far field data is " + "also exported in Matlab format.\n\n" + "Plugin(NearToFarField) creates one new view."; } int GMSH_NearToFarFieldPlugin::getNbOptions() const @@ -79,127 +78,148 @@ StringXString *GMSH_NearToFarFieldPlugin::getOptionStr(int iopt) // Compute field using e^{j\omega t} time dependency, following Jin in "Finite // Element Analysis of Antennas and Arrays", p. 176. This is not the usual `far // field', as it still contains the e^{ikr}/r factor. -double GMSH_NearToFarFieldPlugin::getFarFieldJin(std::vector<element*> &allElems, - std::vector<std::vector<double> > &js, - std::vector<std::vector<double> > &ms, - double k0, double rFar, double theta, - double phi) +double GMSH_NearToFarFieldPlugin::getFarFieldJin( + std::vector<element *> &allElems, std::vector<std::vector<double> > &js, + std::vector<std::vector<double> > &ms, double k0, double rFar, double theta, + double phi) { // theta in [0, pi] (elevation/polar angle) // phi in [0, 2*pi] (azimuthal angle) - double sTheta = sin(theta) ; double cTheta = cos(theta) ; - double sPhi = sin(phi) ; double cPhi = cos(phi) ; - double r[3] = {sTheta*cPhi, sTheta*sPhi, cTheta}; // Unit vector position - - double Z0 = 120 * M_PI ; // free-space impedance - - int numComps = 3, numSteps = 2 ; - std::vector<std::vector<double> > N ; - std::vector<std::vector<double> > Ns ; - std::vector<std::vector<double> > L ; - std::vector<std::vector<double> > Ls ; - - N.resize(numSteps); Ns.resize(numSteps); - L.resize(numSteps); Ls.resize(numSteps); - for (int step = 0; step < numSteps; step++){ - N[step].resize(numComps, 0.); Ns[step].resize(numComps); - L[step].resize(numComps, 0.); Ls[step].resize(numComps); + double sTheta = sin(theta); + double cTheta = cos(theta); + double sPhi = sin(phi); + double cPhi = cos(phi); + double r[3] = {sTheta * cPhi, sTheta * sPhi, cTheta}; // Unit vector position + + double Z0 = 120 * M_PI; // free-space impedance + + int numComps = 3, numSteps = 2; + std::vector<std::vector<double> > N; + std::vector<std::vector<double> > Ns; + std::vector<std::vector<double> > L; + std::vector<std::vector<double> > Ls; + + N.resize(numSteps); + Ns.resize(numSteps); + L.resize(numSteps); + Ls.resize(numSteps); + for(int step = 0; step < numSteps; step++) { + N[step].resize(numComps, 0.); + Ns[step].resize(numComps); + L[step].resize(numComps, 0.); + Ls[step].resize(numComps); } - int i = 0 ; - for(unsigned int ele = 0; ele < allElems.size(); ele++){ - element* e = allElems[ele] ; - int numNodes = e->getNumNodes() ; + int i = 0; + for(unsigned int ele = 0; ele < allElems.size(); ele++) { + element *e = allElems[ele]; + int numNodes = e->getNumNodes(); - std::vector<double > valN0(numNodes*numComps), valN1(numNodes*numComps); - std::vector<double > valL0(numNodes*numComps), valL1(numNodes*numComps) ; + std::vector<double> valN0(numNodes * numComps), valN1(numNodes * numComps); + std::vector<double> valL0(numNodes * numComps), valL1(numNodes * numComps); - for(int nod = 0; nod < numNodes; nod++){ + for(int nod = 0; nod < numNodes; nod++) { double x, y, z; - e->getXYZ(nod, x, y, z) ; + e->getXYZ(nod, x, y, z); double r_nod[3] = {x, y, z}; - double rr = prosca(r_nod, r) ; - double e_jk0rr[2] = {cos(k0*rr), sin(k0*rr)} ; - - for(int comp = 0; comp < numComps; comp++){ - if(i < (int)js[0].size()){ - valN0[numComps * nod + comp] = js[0][i] * e_jk0rr[0] - js[1][i] * e_jk0rr[1]; - valN1[numComps * nod + comp] = js[0][i] * e_jk0rr[1] + js[1][i] * e_jk0rr[0]; - valL0[numComps * nod + comp] = ms[0][i] * e_jk0rr[0] - ms[1][i] * e_jk0rr[1]; - valL1[numComps * nod + comp] = ms[0][i] * e_jk0rr[1] + ms[1][i] * e_jk0rr[0]; + double rr = prosca(r_nod, r); + double e_jk0rr[2] = {cos(k0 * rr), sin(k0 * rr)}; + + for(int comp = 0; comp < numComps; comp++) { + if(i < (int)js[0].size()) { + valN0[numComps * nod + comp] = + js[0][i] * e_jk0rr[0] - js[1][i] * e_jk0rr[1]; + valN1[numComps * nod + comp] = + js[0][i] * e_jk0rr[1] + js[1][i] * e_jk0rr[0]; + valL0[numComps * nod + comp] = + ms[0][i] * e_jk0rr[0] - ms[1][i] * e_jk0rr[1]; + valL1[numComps * nod + comp] = + ms[0][i] * e_jk0rr[1] + ms[1][i] * e_jk0rr[0]; i++; } } } - N[0][0] += e->integrate(&valN0[0], 3) ; N[1][0] += e->integrate(&valN1[0], 3) ; - N[0][1] += e->integrate(&valN0[1], 3) ; N[1][1] += e->integrate(&valN1[1], 3) ; - N[0][2] += e->integrate(&valN0[2], 3) ; N[1][2] += e->integrate(&valN1[2], 3) ; - - L[0][0] += e->integrate(&valL0[0], 3) ; L[1][0] += e->integrate(&valL1[0], 3) ; - L[0][1] += e->integrate(&valL0[1], 3) ; L[1][1] += e->integrate(&valL1[1], 3) ; - L[0][2] += e->integrate(&valL0[2], 3) ; L[1][2] += e->integrate(&valL1[2], 3) ; + N[0][0] += e->integrate(&valN0[0], 3); + N[1][0] += e->integrate(&valN1[0], 3); + N[0][1] += e->integrate(&valN0[1], 3); + N[1][1] += e->integrate(&valN1[1], 3); + N[0][2] += e->integrate(&valN0[2], 3); + N[1][2] += e->integrate(&valN1[2], 3); + + L[0][0] += e->integrate(&valL0[0], 3); + L[1][0] += e->integrate(&valL1[0], 3); + L[0][1] += e->integrate(&valL0[1], 3); + L[1][1] += e->integrate(&valL1[1], 3); + L[0][2] += e->integrate(&valL0[2], 3); + L[1][2] += e->integrate(&valL1[2], 3); } // From Cartesian to spherical coordinates - for(int step = 0; step < 2; step++){ - Ns[step][0] = N[step][0] * sTheta * cPhi + N[step][1] * sTheta * sPhi + N[step][2] *cTheta ; - Ns[step][1] = N[step][0] * cTheta * cPhi + N[step][1] * cTheta * sPhi - N[step][2]* sTheta ; - Ns[step][2] =-N[step][0] * sPhi + N[step][1] * cPhi ; - - Ls[step][0] = L[step][0] * sTheta * cPhi + L[step][1] * sTheta * sPhi + L[step][2] *cTheta ; - Ls[step][1] = L[step][0] * cTheta * cPhi + L[step][1] * cTheta * sPhi - L[step][2]* sTheta ; - Ls[step][2] =-L[step][0] * sPhi + L[step][1] * cPhi ; + for(int step = 0; step < 2; step++) { + Ns[step][0] = N[step][0] * sTheta * cPhi + N[step][1] * sTheta * sPhi + + N[step][2] * cTheta; + Ns[step][1] = N[step][0] * cTheta * cPhi + N[step][1] * cTheta * sPhi - + N[step][2] * sTheta; + Ns[step][2] = -N[step][0] * sPhi + N[step][1] * cPhi; + + Ls[step][0] = L[step][0] * sTheta * cPhi + L[step][1] * sTheta * sPhi + + L[step][2] * cTheta; + Ls[step][1] = L[step][0] * cTheta * cPhi + L[step][1] * cTheta * sPhi - + L[step][2] * sTheta; + Ls[step][2] = -L[step][0] * sPhi + L[step][1] * cPhi; } // E_r radial component is negligible in far field - double E_theta[2] ; - double E_phi[2] ; - double k0_over_4pir = k0/(4*M_PI*rFar) ; - double cos_k0r = cos(k0*rFar) ; - double sin_k0r = sin(k0*rFar) ; + double E_theta[2]; + double E_phi[2]; + double k0_over_4pir = k0 / (4 * M_PI * rFar); + double cos_k0r = cos(k0 * rFar); + double sin_k0r = sin(k0 * rFar); // Elevation component - E_theta[0] = -k0_over_4pir * ( (Ls[0][2] + Z0 * Ns[0][1]) * sin_k0r - - (Ls[1][2] + Z0 * Ns[1][1]) * cos_k0r ) ; - E_theta[1] = -k0_over_4pir * ( (Ls[0][2] + Z0 * Ns[0][1]) * cos_k0r + - (Ls[1][2] + Z0 * Ns[1][1]) * sin_k0r ) ; + E_theta[0] = -k0_over_4pir * ((Ls[0][2] + Z0 * Ns[0][1]) * sin_k0r - + (Ls[1][2] + Z0 * Ns[1][1]) * cos_k0r); + E_theta[1] = -k0_over_4pir * ((Ls[0][2] + Z0 * Ns[0][1]) * cos_k0r + + (Ls[1][2] + Z0 * Ns[1][1]) * sin_k0r); // Azimuthal component - E_phi[0] = k0_over_4pir * ( (Ls[0][1] - Z0 * Ns[0][2]) * sin_k0r - - (Ls[1][1] - Z0 * Ns[1][2]) * cos_k0r ) ; - E_phi[1] = k0_over_4pir * ( (Ls[0][1] - Z0 * Ns[0][2]) * cos_k0r + - (Ls[1][1] - Z0 * Ns[1][2]) * sin_k0r ) ; + E_phi[0] = k0_over_4pir * ((Ls[0][1] - Z0 * Ns[0][2]) * sin_k0r - + (Ls[1][1] - Z0 * Ns[1][2]) * cos_k0r); + E_phi[1] = k0_over_4pir * ((Ls[0][1] - Z0 * Ns[0][2]) * cos_k0r + + (Ls[1][1] - Z0 * Ns[1][2]) * sin_k0r); - double farF = 1./2./Z0 * ( (E_theta[0] * E_theta[0] + E_theta[1] * E_theta[1]) + - (E_phi[0] * E_phi[0] + E_phi[1] * E_phi[1]) ) ; + double farF = 1. / 2. / Z0 * + ((E_theta[0] * E_theta[0] + E_theta[1] * E_theta[1]) + + (E_phi[0] * E_phi[0] + E_phi[1] * E_phi[1])); - return farF ; + return farF; } // Compute far field using e^{-i\omega t} time dependency, following Monk in // "Finite Element Methods for Maxwell's equations", p. 233 -double GMSH_NearToFarFieldPlugin::getFarFieldMonk(std::vector<element*> &allElems, - std::vector<std::vector<double> > &ffvec, - std::vector<std::vector<double> > &js, - std::vector<std::vector<double> > &ms, - double k0, double theta, double phi) +double GMSH_NearToFarFieldPlugin::getFarFieldMonk( + std::vector<element *> &allElems, std::vector<std::vector<double> > &ffvec, + std::vector<std::vector<double> > &js, std::vector<std::vector<double> > &ms, + double k0, double theta, double phi) { - double sTheta = sin(theta) ; double cTheta = cos(theta) ; - double sPhi = sin(phi) ; double cPhi = cos(phi) ; + double sTheta = sin(theta); + double cTheta = cos(theta); + double sPhi = sin(phi); + double cPhi = cos(phi); double xHat[3] = {sTheta * cPhi, sTheta * sPhi, cTheta}; std::complex<double> I(0., 1.); - double Z0 = 120 * M_PI ; // free-space impedance + double Z0 = 120 * M_PI; // free-space impedance double integral_r[3] = {0., 0., 0.}, integral_i[3] = {0., 0., 0.}; - int i = 0 ; - for(unsigned int ele = 0; ele < allElems.size(); ele++){ - element* e = allElems[ele] ; - int numNodes = e->getNumNodes() ; + int i = 0; + for(unsigned int ele = 0; ele < allElems.size(); ele++) { + element *e = allElems[ele]; + int numNodes = e->getNumNodes(); std::vector<double> integrand_r(numNodes * 3), integrand_i(numNodes * 3); - for(int nod = 0; nod < numNodes; nod++){ + for(int nod = 0; nod < numNodes; nod++) { double y[3]; - e->getXYZ(nod, y[0], y[1], y[2]) ; + e->getXYZ(nod, y[0], y[1], y[2]); double const xHat_dot_y = prosca(xHat, y); double n_x_e_r[3] = {-ms[0][i], -ms[0][i + 1], -ms[0][i + 2]}; double n_x_e_i[3] = {-ms[1][i], -ms[1][i + 1], -ms[1][i + 2]}; @@ -208,18 +228,20 @@ double GMSH_NearToFarFieldPlugin::getFarFieldMonk(std::vector<element*> &allElem double n_x_h_x_xHat_r[3], n_x_h_x_xHat_i[3]; prodve(n_x_h_r, xHat, n_x_h_x_xHat_r); prodve(n_x_h_i, xHat, n_x_h_x_xHat_i); - for(int comp = 0; comp < 3; comp++){ + for(int comp = 0; comp < 3; comp++) { std::complex<double> n_x_e(n_x_e_r[comp], n_x_e_i[comp]); - std::complex<double> n_x_h_x_xHat(n_x_h_x_xHat_r[comp], n_x_h_x_xHat_i[comp]); + std::complex<double> n_x_h_x_xHat(n_x_h_x_xHat_r[comp], + n_x_h_x_xHat_i[comp]); // Warning: Z0 == 1 in Monk - std::complex<double> integrand = (n_x_e + Z0 * n_x_h_x_xHat) * + std::complex<double> integrand = + (n_x_e + Z0 * n_x_h_x_xHat) * (cos(-k0 * xHat_dot_y) + I * sin(-k0 * xHat_dot_y)); integrand_r[3 * nod + comp] = integrand.real(); integrand_i[3 * nod + comp] = integrand.imag(); } i += 3; } - for(int comp = 0; comp < 3; comp++){ + for(int comp = 0; comp < 3; comp++) { integral_r[comp] += e->integrate(&integrand_r[comp], 3); integral_i[comp] += e->integrate(&integrand_i[comp], 3); } @@ -229,14 +251,15 @@ double GMSH_NearToFarFieldPlugin::getFarFieldMonk(std::vector<element*> &allElem prodve(xHat, integral_r, xHat_x_integral_r); prodve(xHat, integral_i, xHat_x_integral_i); std::complex<double> coef = I * k0 / 4. / M_PI; - std::complex<double> einf[3] = {coef * (xHat_x_integral_r[0] + I * xHat_x_integral_i[0]), - coef * (xHat_x_integral_r[1] + I * xHat_x_integral_i[1]), - coef * (xHat_x_integral_r[2] + I * xHat_x_integral_i[2])}; + std::complex<double> einf[3] = { + coef * (xHat_x_integral_r[0] + I * xHat_x_integral_i[0]), + coef * (xHat_x_integral_r[1] + I * xHat_x_integral_i[1]), + coef * (xHat_x_integral_r[2] + I * xHat_x_integral_i[2])}; - double coef1 = k0 / 4. / M_PI; - for(int comp = 0; comp < 3; comp++){ + double coef1 = k0 / 4. / M_PI; + for(int comp = 0; comp < 3; comp++) { ffvec[comp][0] = -coef1 * xHat_x_integral_i[comp]; - ffvec[comp][1] = coef1 * xHat_x_integral_r[comp]; + ffvec[comp][1] = coef1 * xHat_x_integral_r[comp]; } return (norm(einf[0]) + norm(einf[1]) + norm(einf[2])); @@ -246,13 +269,13 @@ static void printVector(FILE *fp, const std::string &name, std::vector<std::vector<double> > &vec) { fprintf(fp, "%s = [", name.c_str()); - for (unsigned int i = 0; i < vec.size(); i++) - for (unsigned int j = 0; j < vec[i].size(); j++) + for(unsigned int i = 0; i < vec.size(); i++) + for(unsigned int j = 0; j < vec[i].size(); j++) fprintf(fp, "%.16g ", vec[i][j]); fprintf(fp, "];\n"); } -PView *GMSH_NearToFarFieldPlugin::execute(PView * v) +PView *GMSH_NearToFarFieldPlugin::execute(PView *v) { double _k0 = (double)NearToFarFieldOptions_Number[0].def; double _phiStart = (double)NearToFarFieldOptions_Number[1].def; @@ -271,26 +294,26 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) std::string _outFile = NearToFarFieldOptions_String[0].def; PView *ve = getView(_eView, v); - if(!ve){ - Msg::Error("NearToFarField plugin could not find EView %i", _eView); + if(!ve) { + Msg::Error("NearToFarField plugin could not find EView %i", _eView); return v; } PView *vh = getView(_hView, v); - if(!vh){ + if(!vh) { Msg::Error("NearToFarField plugin could not find HView %i", _hView); return v; } - PViewData *eData = ve->getData() ; - PViewData *hData = vh->getData() ; + PViewData *eData = ve->getData(); + PViewData *hData = vh->getData(); if(eData->getNumEntities() != hData->getNumEntities() || eData->getNumElements() != hData->getNumElements() || - eData->getNumTimeSteps()!= hData->getNumTimeSteps()){ + eData->getNumTimeSteps() != hData->getNumTimeSteps()) { Msg::Error("Incompatible views for E field and H field"); return v; } - if(eData->getNumTimeSteps() != 2 || hData->getNumTimeSteps() != 2){ + if(eData->getNumTimeSteps() != 2 || hData->getNumTimeSteps() != 2) { Msg::Error("Invalid number of steps for E or H fields (must be complex)"); return v; } @@ -305,22 +328,22 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) if(x0 != hData->getBoundingBox().center().x() || y0 != hData->getBoundingBox().center().y() || - z0 != hData->getBoundingBox().center().z()){ + z0 != hData->getBoundingBox().center().z()) { Msg::Error("E and H fields must be given on the same grid"); return v; } // compute surface currents on all input elements - std::vector<element*> allElems ; - std::vector<std::vector<double> > js(2) ; - std::vector<std::vector<double> > ms(2) ; + std::vector<element *> allElems; + std::vector<std::vector<double> > js(2); + std::vector<std::vector<double> > ms(2); - for(int ent = 0; ent < eData->getNumEntities(0); ent++){ - for(int ele = 0; ele < eData->getNumElements(0, ent); ele++){ + for(int ent = 0; ent < eData->getNumEntities(0); ent++) { + for(int ele = 0; ele < eData->getNumElements(0, ent); ele++) { if(eData->skipElement(0, ent, ele)) continue; if(hData->skipElement(0, ent, ele)) continue; int numComp = eData->getNumComponents(0, ent, ele); - if(numComp != 3) continue ; + if(numComp != 3) continue; int dim = eData->getDimension(0, ent, ele); if(dim != 1 && dim != 2) continue; int numNodes = eData->getNumNodes(0, ent, ele); @@ -329,7 +352,8 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) eData->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]); elementFactory factory; - allElems.push_back(factory.create(numNodes, dim, &x[0], &y[0], &z[0], true)); + allElems.push_back( + factory.create(numNodes, dim, &x[0], &y[0], &z[0], true)); double n[3] = {0., 0., 0.}; if(numNodes > 2) @@ -337,25 +361,28 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) else normal2points(x[0], y[0], z[0], x[1], y[1], z[1], n); - for(int step = 0; step < 2; step++){ - for(int nod = 0; nod < numNodes; nod++){ + for(int step = 0; step < 2; step++) { + for(int nod = 0; nod < numNodes; nod++) { double h[3], e[3]; - for(int comp = 0; comp < numComp; comp++){ + for(int comp = 0; comp < numComp; comp++) { eData->getValue(step, ent, ele, nod, comp, e[comp]); hData->getValue(step, ent, ele, nod, comp, h[comp]); } - double j[3], m[3] ; - prodve(n, h, j) ; // Js = n x H ; Surface electric current - prodve(e, n, m) ; // Ms = - n x E ; Surface magnetic current - js[step].push_back(j[0]) ; js[step].push_back(j[1]) ; js[step].push_back(j[2]) ; - ms[step].push_back(m[0]) ; ms[step].push_back(m[1]) ; ms[step].push_back(m[2]) ; + double j[3], m[3]; + prodve(n, h, j); // Js = n x H ; Surface electric current + prodve(e, n, m); // Ms = - n x E ; Surface magnetic current + js[step].push_back(j[0]); + js[step].push_back(j[1]); + js[step].push_back(j[2]); + ms[step].push_back(m[0]); + ms[step].push_back(m[1]); + ms[step].push_back(m[2]); } } - } } - if(allElems.empty()){ + if(allElems.empty()) { Msg::Error("No valid elements found to compute far field"); return v; } @@ -374,11 +401,11 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) std::vector<std::vector<double> > farField2i(_NbPhi + 1); std::vector<std::vector<double> > farField3i(_NbPhi + 1); std::vector<std::vector<double> > farFieldVec(3); - for(int comp = 0; comp < 3; comp++){ + for(int comp = 0; comp < 3; comp++) { farFieldVec[comp].resize(2, 0.); } - for (int i = 0; i <= _NbPhi; i++){ + for(int i = 0; i <= _NbPhi; i++) { phi[i].resize(_NbThe + 1); theta[i].resize(_NbThe + 1); x[i].resize(_NbThe + 1); @@ -398,11 +425,11 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) double dTheta = (_thetaEnd - _thetaStart) / _NbThe; double ffmin = 1e200, ffmax = -1e200; Msg::ResetProgressMeter(); - for (int i = 0; i <= _NbPhi; i++){ - for (int j = 0; j <= _NbThe; j++){ - phi[i][j] = _phiStart + i * dPhi ; - theta[i][j] = _thetaStart + j * dTheta ; - if(_negativeTime){ + for(int i = 0; i <= _NbPhi; i++) { + for(int j = 0; j <= _NbThe; j++) { + phi[i][j] = _phiStart + i * dPhi; + theta[i][j] = _thetaStart + j * dTheta; + if(_negativeTime) { farField[i][j] = getFarFieldMonk(allElems, farFieldVec, js, ms, _k0, theta[i][j], phi[i][j]); farField1r[i][j] = farFieldVec[0][0]; @@ -412,33 +439,31 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) farField2i[i][j] = farFieldVec[1][1]; farField3i[i][j] = farFieldVec[2][1]; } - else{ + else { double rfar = (_rfar ? _rfar : 10 * lc); - farField[i][j] = getFarFieldJin(allElems, js, ms, _k0, rfar, - theta[i][j], phi[i][j]); + farField[i][j] = + getFarFieldJin(allElems, js, ms, _k0, rfar, theta[i][j], phi[i][j]); } ffmin = std::min(ffmin, farField[i][j]); ffmax = std::max(ffmax, farField[i][j]); } Msg::ProgressMeter(i, _NbPhi, true, "Computing far field"); } - for(unsigned int i = 0; i < allElems.size(); i++) - delete allElems[i]; + for(unsigned int i = 0; i < allElems.size(); i++) delete allElems[i]; - if(_normalize){ + if(_normalize) { if(!ffmax) Msg::Warning("Cannot normalize far field (max = 0)"); else - for (int i = 0; i <= _NbPhi; i++) - for (int j = 0; j <= _NbThe; j++) - farField[i][j] /= ffmax ; + for(int i = 0; i <= _NbPhi; i++) + for(int j = 0; j <= _NbThe; j++) farField[i][j] /= ffmax; } - if(_dB){ + if(_dB) { ffmin = 1e200; ffmax = -1e200; - for (int i = 0; i <= _NbPhi; i++){ - for (int j = 0; j <= _NbThe; j++){ + for(int i = 0; i <= _NbPhi; i++) { + for(int j = 0; j <= _NbThe; j++) { farField[i][j] = 10 * log10(farField[i][j]); ffmin = std::min(ffmin, farField[i][j]); ffmax = std::max(ffmax, farField[i][j]); @@ -446,10 +471,10 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) } } - for (int i = 0; i <= _NbPhi; i++){ - for (int j = 0; j <= _NbThe; j++){ + for(int i = 0; i <= _NbPhi; i++) { + for(int j = 0; j <= _NbThe; j++) { double df = (ffmax - ffmin); - if(!df){ + if(!df) { Msg::Warning("zero far field range"); df = 1.; } @@ -460,14 +485,14 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) } } - if(_outFile.size()){ + if(_outFile.size()) { FILE *fp = Fopen(_outFile.c_str(), "w"); - if(fp){ + if(fp) { printVector(fp, "phi", phi); printVector(fp, "theta", theta); printVector(fp, "farField", farField); - if(_negativeTime){ + if(_negativeTime) { printVector(fp, "farField1r", farField1r); printVector(fp, "farField2r", farField2r); printVector(fp, "farField3r", farField3r); @@ -485,29 +510,37 @@ PView *GMSH_NearToFarFieldPlugin::execute(PView * v) Msg::Error("Could not open file '%s'", _outFile.c_str()); } - for (int i = 0; i < _NbPhi; i++){ - for (int j = 0; j < _NbThe; j++){ - if(_NbPhi == 1 || _NbThe == 1){ + for(int i = 0; i < _NbPhi; i++) { + for(int j = 0; j < _NbThe; j++) { + if(_NbPhi == 1 || _NbThe == 1) { dataFar->NbSP++; - dataFar->SP.push_back(x[i][j]); dataFar->SP.push_back(y[i][j]); - dataFar->SP.push_back(z[i][j]); dataFar->SP.push_back(farField[i][j]); + dataFar->SP.push_back(x[i][j]); + dataFar->SP.push_back(y[i][j]); + dataFar->SP.push_back(z[i][j]); + dataFar->SP.push_back(farField[i][j]); } - else{ + else { double P1[3] = {x[i][j], y[i][j], z[i][j]}; - double P2[3] = {x[i+1][j], y[i+1][j], z[i+1][j]}; - double P3[3] = {x[i+1][j+1], y[i+1][j+1], z[i+1][j+1]}; - double P4[3] = {x[i][j+1], y[i][j+1], z[i][j+1]}; + double P2[3] = {x[i + 1][j], y[i + 1][j], z[i + 1][j]}; + double P3[3] = {x[i + 1][j + 1], y[i + 1][j + 1], z[i + 1][j + 1]}; + double P4[3] = {x[i][j + 1], y[i][j + 1], z[i][j + 1]}; dataFar->NbSQ++; - dataFar->SQ.push_back(P1[0]); dataFar->SQ.push_back(P2[0]); - dataFar->SQ.push_back(P3[0]); dataFar->SQ.push_back(P4[0]); - dataFar->SQ.push_back(P1[1]); dataFar->SQ.push_back(P2[1]); - dataFar->SQ.push_back(P3[1]); dataFar->SQ.push_back(P4[1]); - dataFar->SQ.push_back(P1[2]); dataFar->SQ.push_back(P2[2]); - dataFar->SQ.push_back(P3[2]); dataFar->SQ.push_back(P4[2]); + dataFar->SQ.push_back(P1[0]); + dataFar->SQ.push_back(P2[0]); + dataFar->SQ.push_back(P3[0]); + dataFar->SQ.push_back(P4[0]); + dataFar->SQ.push_back(P1[1]); + dataFar->SQ.push_back(P2[1]); + dataFar->SQ.push_back(P3[1]); + dataFar->SQ.push_back(P4[1]); + dataFar->SQ.push_back(P1[2]); + dataFar->SQ.push_back(P2[2]); + dataFar->SQ.push_back(P3[2]); + dataFar->SQ.push_back(P4[2]); dataFar->SQ.push_back(farField[i][j]); - dataFar->SQ.push_back(farField[i+1][j]); - dataFar->SQ.push_back(farField[i+1][j+1]); - dataFar->SQ.push_back(farField[i][j+1]); + dataFar->SQ.push_back(farField[i + 1][j]); + dataFar->SQ.push_back(farField[i + 1][j + 1]); + dataFar->SQ.push_back(farField[i][j + 1]); } } } diff --git a/Plugin/NearToFarField.h b/Plugin/NearToFarField.h index 91b1b7925f9f64ed2c17386c76db50ff5bde95f5..19289bb048e62e8f2e01652ac22b02b52e1a174d 100644 --- a/Plugin/NearToFarField.h +++ b/Plugin/NearToFarField.h @@ -13,15 +13,13 @@ #include "MElement.h" #include "GModel.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterNearToFarFieldPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterNearToFarFieldPlugin(); } -class GMSH_NearToFarFieldPlugin : public GMSH_PostPlugin -{ - public: - GMSH_NearToFarFieldPlugin(){} +class GMSH_NearToFarFieldPlugin : public GMSH_PostPlugin { +public: + GMSH_NearToFarFieldPlugin() {} std::string getName() const { return "NearToFarField"; } std::string getShortHelp() const { @@ -30,21 +28,21 @@ class GMSH_NearToFarFieldPlugin : public GMSH_PostPlugin std::string getHelp() const; virtual std::string getAuthor() const { return "R. Sabariego, C. Geuzaine"; } int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; StringXString *getOptionStr(int iopt); PView *execute(PView *); - double getFarFieldJin(std::vector<element*> &allElems, + double getFarFieldJin(std::vector<element *> &allElems, std::vector<std::vector<double> > &js, - std::vector<std::vector<double> > &ms, - double k0, double r_far, double theta, double phi); + std::vector<std::vector<double> > &ms, double k0, + double r_far, double theta, double phi); - double getFarFieldMonk(std::vector<element*> &allElems, + double getFarFieldMonk(std::vector<element *> &allElems, std::vector<std::vector<double> > &farfieldvector, std::vector<std::vector<double> > &js, - std::vector<std::vector<double> > &ms, - double k0, double theta, double phi); + std::vector<std::vector<double> > &ms, double k0, + double theta, double phi); }; #endif diff --git a/Plugin/NearestNeighbor.cpp b/Plugin/NearestNeighbor.cpp index aeef99e3a87c4fecd372f940cc8d2fc4707a0afb..7fd338d18d9cbb3e0baf1ad1b869e89602636b77 100644 --- a/Plugin/NearestNeighbor.cpp +++ b/Plugin/NearestNeighbor.cpp @@ -14,20 +14,19 @@ StringXNumber NearestNeighborOptions_Number[] = { {GMSH_FULLRC, "View", NULL, -1.}, }; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterNearestNeighborPlugin() { - GMSH_Plugin *GMSH_RegisterNearestNeighborPlugin() - { - return new GMSH_NearestNeighborPlugin(); - } + return new GMSH_NearestNeighborPlugin(); +} } std::string GMSH_NearestNeighborPlugin::getHelp() const { return "Plugin(NearestNeighbor) computes the distance from each " - "point in `View' to its nearest neighbor.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(NearestNeighbor) is executed in-place."; + "point in `View' to its nearest neighbor.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(NearestNeighbor) is executed in-place."; } int GMSH_NearestNeighborPlugin::getNbOptions() const @@ -49,7 +48,7 @@ PView *GMSH_NearestNeighborPlugin::execute(PView *v) PViewData *data1 = v1->getData(); int totpoints = data1->getNumPoints(); - if(!totpoints){ + if(!totpoints) { Msg::Error("View[%d] contains no points", iView); return 0; } @@ -57,8 +56,8 @@ PView *GMSH_NearestNeighborPlugin::execute(PView *v) #if defined(HAVE_ANN) ANNpointArray zeronodes = annAllocPts(totpoints, 3); int k = 0, step = 0; - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; int numNodes = data1->getNumNodes(step, ent, ele); if(numNodes != 1) continue; @@ -72,8 +71,8 @@ PView *GMSH_NearestNeighborPlugin::execute(PView *v) ANNdistArray dist = new ANNdist[2]; v1->setChanged(true); - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; int numNodes = data1->getNumNodes(step, ent, ele); if(numNodes != 1) continue; @@ -86,8 +85,8 @@ PView *GMSH_NearestNeighborPlugin::execute(PView *v) delete kdtree; annDeallocPts(zeronodes); - delete [] index; - delete [] dist; + delete[] index; + delete[] dist; #else Msg::Error("Nearest neighbor computation requires ANN"); #endif diff --git a/Plugin/NearestNeighbor.h b/Plugin/NearestNeighbor.h index 266f9d56b5f17964ea88596eefe067d047f400ae..f1c4ed5c624e78ddc701cdd7796c7fa7d011dca1 100644 --- a/Plugin/NearestNeighbor.h +++ b/Plugin/NearestNeighbor.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterNearestNeighborPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterNearestNeighborPlugin(); } -class GMSH_NearestNeighborPlugin : public GMSH_PostPlugin -{ - public: - GMSH_NearestNeighborPlugin(){} +class GMSH_NearestNeighborPlugin : public GMSH_PostPlugin { +public: + GMSH_NearestNeighborPlugin() {} std::string getName() const { return "NearestNeighbor"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_NearestNeighborPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/NewView.cpp b/Plugin/NewView.cpp index 044c0e4479880d962857dc1aa4a1cc57976f5330..f30392ad2b14cfab783c433fd1883916b405e566 100644 --- a/Plugin/NewView.cpp +++ b/Plugin/NewView.cpp @@ -11,28 +11,21 @@ #include "GModel.h" #include "MElement.h" -StringXNumber NewViewOptions_Number[] = { - {GMSH_FULLRC, "NumComp", NULL, 1.}, - {GMSH_FULLRC, "ViewTag", NULL, -1.} -}; +StringXNumber NewViewOptions_Number[] = {{GMSH_FULLRC, "NumComp", NULL, 1.}, + {GMSH_FULLRC, "ViewTag", NULL, -1.}}; StringXString NewViewOptions_String[] = { - {GMSH_FULLRC, "Type", NULL, "NodeData"} -}; + {GMSH_FULLRC, "Type", NULL, "NodeData"}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterNewViewPlugin() - { - return new GMSH_NewViewPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterNewViewPlugin() { return new GMSH_NewViewPlugin(); } } std::string GMSH_NewViewPlugin::getHelp() const { return "Plugin(NewView) creates a new model-based view from the " - "current mesh, with `NumComp' field components.\n\n" - "If `ViewTag' is positive, force that tag for the created view."; + "current mesh, with `NumComp' field components.\n\n" + "If `ViewTag' is positive, force that tag for the created view."; } int GMSH_NewViewPlugin::getNbOptions() const @@ -55,34 +48,34 @@ StringXString *GMSH_NewViewPlugin::getOptionStr(int iopt) return &NewViewOptions_String[iopt]; } -PView *GMSH_NewViewPlugin::execute(PView * v) +PView *GMSH_NewViewPlugin::execute(PView *v) { int numComp = (int)NewViewOptions_Number[0].def; int tag = (int)NewViewOptions_Number[1].def; std::string type = NewViewOptions_String[0].def; - if(GModel::current()->getMeshStatus() < 1){ + if(GModel::current()->getMeshStatus() < 1) { Msg::Error("No mesh available to create the view: please mesh your model!"); - return v ; + return v; } - if(numComp < 1){ + if(numComp < 1) { Msg::Error("Bad number of components for Plugin(NewView)"); return v; } - if(type != "NodeData"){ + if(type != "NodeData") { Msg::Error("Unknown data type for Plugin(NewView)"); return v; } std::map<int, std::vector<double> > d; - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; GModel::current()->getEntities(entities); - for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){ + for(unsigned int i = 0; i < entities.size(); i++) { + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) { MVertex *ve = entities[i]->mesh_vertices[j]; d[ve->getNum()].resize(numComp); } } PView *vn = new PView("New view", "NodeData", GModel::current(), d, tag); - return vn ; + return vn; } diff --git a/Plugin/NewView.h b/Plugin/NewView.h index 0584da5bef22f5f194c6c69677e22fd488394f59..c4605fd224d1dfb243b0871f4f9662c3d8918065 100644 --- a/Plugin/NewView.h +++ b/Plugin/NewView.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterNewViewPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterNewViewPlugin(); } -class GMSH_NewViewPlugin : public GMSH_PostPlugin -{ - public: - GMSH_NewViewPlugin(){} +class GMSH_NewViewPlugin : public GMSH_PostPlugin { +public: + GMSH_NewViewPlugin() {} std::string getName() const { return "NewView"; } std::string getShortHelp() const { @@ -26,7 +24,7 @@ class GMSH_NewViewPlugin : public GMSH_PostPlugin int getNbOptions() const; StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Particles.cpp b/Plugin/Particles.cpp index a80ef8db281e05c5f18a78d53365c95b46b64f16..8b8724e5b4edab0661dd120e03b48115d9a33457 100644 --- a/Plugin/Particles.cpp +++ b/Plugin/Particles.cpp @@ -26,31 +26,29 @@ StringXNumber ParticlesOptions_Number[] = { {GMSH_FULLRC, "Z2", GMSH_ParticlesPlugin::callbackZ2, 0.}, {GMSH_FULLRC, "NumPointsU", GMSH_ParticlesPlugin::callbackU, 10}, {GMSH_FULLRC, "NumPointsV", GMSH_ParticlesPlugin::callbackV, 1}, - {GMSH_FULLRC, "A2", NULL, 1. }, - {GMSH_FULLRC, "A1", NULL, 0. }, - {GMSH_FULLRC, "A0", NULL, 0. }, + {GMSH_FULLRC, "A2", NULL, 1.}, + {GMSH_FULLRC, "A1", NULL, 0.}, + {GMSH_FULLRC, "A0", NULL, 0.}, {GMSH_FULLRC, "DT", NULL, .1}, {GMSH_FULLRC, "MaxIter", NULL, 100}, {GMSH_FULLRC, "TimeStep", NULL, 0}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterParticlesPlugin() { - GMSH_Plugin *GMSH_RegisterParticlesPlugin() - { - return new GMSH_ParticlesPlugin(); - } + return new GMSH_ParticlesPlugin(); +} } void GMSH_ParticlesPlugin::draw(void *context) { #if defined(HAVE_OPENGL) - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); - drawContext *ctx = (drawContext*)context; + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); + drawContext *ctx = (drawContext *)context; double p[3]; - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { getPoint(i, j, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); } @@ -58,10 +56,11 @@ void GMSH_ParticlesPlugin::draw(void *context) #endif } -double GMSH_ParticlesPlugin::callback(int num, int action, double value, double *opt, - double step, double min, double max) +double GMSH_ParticlesPlugin::callback(int num, int action, double value, + double *opt, double step, double min, + double max) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return step; case 2: return min; case 3: return max; @@ -75,99 +74,100 @@ double GMSH_ParticlesPlugin::callback(int num, int action, double value, double double GMSH_ParticlesPlugin::callbackX0(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[0].def, - CTX::instance()->lc / 100., - -2 * CTX::instance()->lc, 2 * CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackY0(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[1].def, - CTX::instance()->lc / 100., - -2 * CTX::instance()->lc, 2 * CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackZ0(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[2].def, - CTX::instance()->lc / 100., - -2 * CTX::instance()->lc, 2 * CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackX1(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[3].def, - CTX::instance()->lc / 100., - -2 * CTX::instance()->lc, 2 * CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackY1(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[4].def, - CTX::instance()->lc / 100., - -2 * CTX::instance()->lc, 2 * CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackZ1(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[5].def, - CTX::instance()->lc / 100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackX2(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[6].def, - CTX::instance()->lc / 100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackY2(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[7].def, - CTX::instance()->lc / 100., - -2 * CTX::instance()->lc, 2 * CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackZ2(int num, int action, double value) { return callback(num, action, value, &ParticlesOptions_Number[8].def, - CTX::instance()->lc / 100., - -2 * CTX::instance()->lc, 2 * CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_ParticlesPlugin::callbackU(int num, int action, double value) { - return callback(num, action, value, &ParticlesOptions_Number[9].def, - 1, 1, 100); + return callback(num, action, value, &ParticlesOptions_Number[9].def, 1, 1, + 100); } double GMSH_ParticlesPlugin::callbackV(int num, int action, double value) { - return callback(num, action, value, &ParticlesOptions_Number[10].def, - 1, 1, 100); + return callback(num, action, value, &ParticlesOptions_Number[10].def, 1, 1, + 100); } std::string GMSH_ParticlesPlugin::getHelp() const { - return - "Plugin(Particles) computes the trajectory " - "of particules in the force field given by the " - "`TimeStep'-th time step of a vector view " - "`View'.\n\n" - "The plugin takes as input a grid defined by the " - "3 points (`X0',`Y0',`Z0') (origin), (`X1',`Y1',`Z1') " - "(axis of U) and (`X2',`Y2',`Z2') (axis of V).\n\n" - "The number of particles along U and V that are to " - "be transported is set with the options `NumPointsU' " - "and `NumPointsV'. The equation\n\n" - "A2 * d^2X(t)/dt^2 + A1 * dX(t)/dt + A0 * X(t) = F\n\n" - "is then solved with the initial conditions X(t=0) " - "chosen as the grid, dX/dt(t=0)=0, and with F " - "interpolated from the vector view.\n\n" - "Time stepping is done using a Newmark scheme with " - "step size `DT' and `MaxIter' maximum number of " - "iterations.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Particles) creates one new view containing " - "multi-step vector points."; + return "Plugin(Particles) computes the trajectory " + "of particules in the force field given by the " + "`TimeStep'-th time step of a vector view " + "`View'.\n\n" + "The plugin takes as input a grid defined by the " + "3 points (`X0',`Y0',`Z0') (origin), (`X1',`Y1',`Z1') " + "(axis of U) and (`X2',`Y2',`Z2') (axis of V).\n\n" + "The number of particles along U and V that are to " + "be transported is set with the options `NumPointsU' " + "and `NumPointsV'. The equation\n\n" + "A2 * d^2X(t)/dt^2 + A1 * dX(t)/dt + A0 * X(t) = F\n\n" + "is then solved with the initial conditions X(t=0) " + "chosen as the grid, dX/dt(t=0)=0, and with F " + "interpolated from the vector view.\n\n" + "Time stepping is done using a Newmark scheme with " + "step size `DT' and `MaxIter' maximum number of " + "iterations.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Particles) creates one new view containing " + "multi-step vector points."; } int GMSH_ParticlesPlugin::getNbOptions() const @@ -194,15 +194,15 @@ void GMSH_ParticlesPlugin::getPoint(int iU, int iV, double *X) { double u = getNbU() > 1 ? (double)iU / (double)(getNbU() - 1.) : 0.; double v = getNbV() > 1 ? (double)iV / (double)(getNbV() - 1.) : 0.; - X[0] = ParticlesOptions_Number[0].def + - u * (ParticlesOptions_Number[3].def - ParticlesOptions_Number[0].def) + - v * (ParticlesOptions_Number[6].def - ParticlesOptions_Number[0].def); - X[1] = ParticlesOptions_Number[1].def + - u * (ParticlesOptions_Number[4].def - ParticlesOptions_Number[1].def) + - v * (ParticlesOptions_Number[7].def - ParticlesOptions_Number[1].def); - X[2] = ParticlesOptions_Number[2].def + - u * (ParticlesOptions_Number[5].def - ParticlesOptions_Number[2].def) + - v * (ParticlesOptions_Number[8].def - ParticlesOptions_Number[2].def); + X[0] = ParticlesOptions_Number[0].def + + u * (ParticlesOptions_Number[3].def - ParticlesOptions_Number[0].def) + + v * (ParticlesOptions_Number[6].def - ParticlesOptions_Number[0].def); + X[1] = ParticlesOptions_Number[1].def + + u * (ParticlesOptions_Number[4].def - ParticlesOptions_Number[1].def) + + v * (ParticlesOptions_Number[7].def - ParticlesOptions_Number[1].def); + X[2] = ParticlesOptions_Number[2].def + + u * (ParticlesOptions_Number[5].def - ParticlesOptions_Number[2].def) + + v * (ParticlesOptions_Number[8].def - ParticlesOptions_Number[2].def); } PView *GMSH_ParticlesPlugin::execute(PView *v) @@ -220,7 +220,7 @@ PView *GMSH_ParticlesPlugin::execute(PView *v) PViewData *data1 = getPossiblyAdaptiveData(v1); // sanity checks - if(timeStep > data1->getNumTimeSteps() - 1){ + if(timeStep > data1->getNumTimeSteps() - 1) { Msg::Error("Invalid time step (%d) in view[%d]: using 0", v1->getIndex()); timeStep = 0; } @@ -235,17 +235,21 @@ PView *GMSH_ParticlesPlugin::execute(PView *v) // (A2 + gamma DT A1 + beta DT^2 A0) x^{n+1} = // (2 A2 - (1 - 2 gamma) DT A1 - (0.5 + gamma - 2 beta) DT^2 A0) x^n + // (-A2 - (gamma - 1) DT A1 - (0.5 - gamma + beta) DT^2 A0) x^{n-1} + - // DT^2 (beta b^{n+1} + (0.5 + gamma - 2 beta) b^n + (0.5 - gamma + beta) b^{n-1}) + // DT^2 (beta b^{n+1} + (0.5 + gamma - 2 beta) b^n + (0.5 - gamma + beta) + // b^{n-1}) // // coefs for constant acceleration (unconditinonally stable) - const double gamma = 0.5, beta = 0.25; + const double gamma = 0.5, beta = 0.25; double c1 = (A2 + gamma * DT * A1 + beta * DT * DT * A0); - double c2 = (2 * A2 - (1 - 2 * gamma) * DT * A1 - (0.5 + gamma - 2 * beta) * DT * DT * A0); - double c3 = (-A2 - (gamma - 1) * DT * A1 - (0.5 - gamma + beta) * DT * DT * A0); - double c4 = DT * DT * (beta + (0.5 + gamma - 2 * beta) + (0.5 - gamma + beta)); - - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ + double c2 = (2 * A2 - (1 - 2 * gamma) * DT * A1 - + (0.5 + gamma - 2 * beta) * DT * DT * A0); + double c3 = + (-A2 - (gamma - 1) * DT * A1 - (0.5 - gamma + beta) * DT * DT * A0); + double c4 = + DT * DT * (beta + (0.5 + gamma - 2 * beta) + (0.5 - gamma + beta)); + + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { double XINIT[3], X0[3], X1[3]; getPoint(i, j, XINIT); getPoint(i, j, X0); @@ -254,7 +258,7 @@ PView *GMSH_ParticlesPlugin::execute(PView *v) data2->VP.push_back(XINIT[0]); data2->VP.push_back(XINIT[1]); data2->VP.push_back(XINIT[2]); - for(int iter = 0; iter < maxIter; iter++){ + for(int iter = 0; iter < maxIter; iter++) { double F[3], X[3]; o1.searchVector(X1[0], X1[1], X1[2], F, timeStep); for(int k = 0; k < 3; k++) @@ -262,10 +266,10 @@ PView *GMSH_ParticlesPlugin::execute(PView *v) data2->VP.push_back(X[0] - XINIT[0]); data2->VP.push_back(X[1] - XINIT[1]); data2->VP.push_back(X[2] - XINIT[2]); - for(int k = 0; k < 3; k++){ + for(int k = 0; k < 3; k++) { X0[k] = X1[k]; X1[k] = X[k]; - } + } } } } diff --git a/Plugin/Particles.h b/Plugin/Particles.h index 2458035f01920f2b39fa0ac6d19aa7a022a3f0b2..a6d9194aa86d4f7e66948ac1043bc91952a82aa8 100644 --- a/Plugin/Particles.h +++ b/Plugin/Particles.h @@ -8,17 +8,16 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterParticlesPlugin (); +extern "C" { +GMSH_Plugin *GMSH_RegisterParticlesPlugin(); } -class GMSH_ParticlesPlugin : public GMSH_PostPlugin -{ +class GMSH_ParticlesPlugin : public GMSH_PostPlugin { static double callback(int num, int action, double value, double *opt, double step, double min, double max); - public: - GMSH_ParticlesPlugin(){} + +public: + GMSH_ParticlesPlugin() {} std::string getName() const { return "Particles"; } std::string getShortHelp() const { diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index be9827795091031b6c24bb1a5b98ce3ae05311c6..b1a57c5e8420de72e50b85bbf0e9de0669af7849 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -16,7 +16,7 @@ #include "drawContext.h" #endif -void (*GMSH_Plugin::draw)(void*) = 0; +void (*GMSH_Plugin::draw)(void *) = 0; void GMSH_Plugin::setDrawFunction(void (*fct)(void *)) { @@ -24,7 +24,7 @@ void GMSH_Plugin::setDrawFunction(void (*fct)(void *)) draw = fct; int old = CTX::instance()->drawBBox; CTX::instance()->drawBBox = 1; - if(CTX::instance()->fastRedraw){ + if(CTX::instance()->fastRedraw) { CTX::instance()->post.draw = 0; CTX::instance()->mesh.draw = 0; } @@ -45,11 +45,11 @@ std::string GMSH_Plugin::serialize() { std::ostringstream sstream; for(int i = 0; i < getNbOptionsStr(); i++) - sstream << "Plugin(" << getName() << ")." << getOptionStr(i)->str - << "= \"" << getOptionStr(i)->def << "\";\n"; + sstream << "Plugin(" << getName() << ")." << getOptionStr(i)->str << "= \"" + << getOptionStr(i)->def << "\";\n"; for(int i = 0; i < getNbOptions(); i++) - sstream << "Plugin(" << getName() << ")." << getOption(i)->str - << "=" << getOption(i)->def << ";\n"; + sstream << "Plugin(" << getName() << ")." << getOption(i)->str << "=" + << getOption(i)->def << ";\n"; sstream << "Plugin(" << getName() << ").Run;\n"; return sstream.str(); } @@ -57,14 +57,14 @@ std::string GMSH_Plugin::serialize() PView *GMSH_PostPlugin::executeRemote(PView *view) { int j = -1, remoteIndex = -1; - for(unsigned int i = 0; i < PView::list.size(); i++){ + for(unsigned int i = 0; i < PView::list.size(); i++) { if(PView::list[i]->getData()->isRemote()) j++; - if(PView::list[i]->getTag() == view->getTag()){ + if(PView::list[i]->getTag() == view->getTag()) { remoteIndex = j; break; } } - if(remoteIndex < 0){ + if(remoteIndex < 0) { Msg::Error("Unable to determine index of remote view"); return view; } @@ -80,13 +80,12 @@ PView *GMSH_PostPlugin::executeRemote(PView *view) PView *GMSH_PostPlugin::getView(int index, PView *view) { - if(index < 0) - index = view ? view->getIndex() : PView::list.size() - 1; + if(index < 0) index = view ? view->getIndex() : PView::list.size() - 1; - if(index >= 0 && index < (int)PView::list.size()){ + if(index >= 0 && index < (int)PView::list.size()) { return PView::list[index]; } - else{ + else { Msg::Error("View[%d] does not exist", index); return 0; } @@ -97,9 +96,11 @@ PViewData *GMSH_PostPlugin::getPossiblyAdaptiveData(PView *view) if(!view) return 0; PViewData *data = view->getData(); if(data->getAdaptiveData() && data->getNumTimeSteps() > 1) - Msg::Warning("Using adapted data from view '%s': only the current time step (%d/%d) " - "is available to the plugin", view->getData()->getName().c_str(), - view->getOptions()->timeStep, data->getNumTimeSteps()); + Msg::Warning( + "Using adapted data from view '%s': only the current time step (%d/%d) " + "is available to the plugin", + view->getData()->getName().c_str(), view->getOptions()->timeStep, + data->getNumTimeSteps()); return view->getData(true); } @@ -107,10 +108,11 @@ PViewDataList *GMSH_PostPlugin::getDataList(PView *view, bool showError) { if(!view) return 0; - PViewDataList *data = dynamic_cast<PViewDataList*>(view->getData()); + PViewDataList *data = dynamic_cast<PViewDataList *>(view->getData()); if(data) return data; else if(showError) - Msg::Error("This plugin can only be run on list-based views (`.pos' files)"); + Msg::Error( + "This plugin can only be run on list-based views (`.pos' files)"); return 0; } diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index 0e6180be9cc75c41adafe49ca4e71a3ac75ca8df..20ff3cddab21a857aed308b53150c780e123c185 100644 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -23,9 +23,8 @@ class PluginDialogBox; class Vertex; -class GMSH_Plugin -{ - public : +class GMSH_Plugin { +public: // 4 kinds of plugins typedef enum { GMSH_CAD_PLUGIN, @@ -41,7 +40,7 @@ class GMSH_Plugin void *hlib; GMSH_Plugin() : dialogBox(0), hlib(0) {} - virtual ~GMSH_Plugin(){} + virtual ~GMSH_Plugin() {} // return plugin type, name and info virtual GMSH_PLUGIN_TYPE getType() const = 0; @@ -49,7 +48,10 @@ class GMSH_Plugin virtual std::string getShortHelp() const = 0; virtual std::string getHelp() const = 0; virtual std::string getAuthor() const { return "C. Geuzaine, J.-F. Remacle"; } - virtual std::string getCopyright() const { return "C. Geuzaine, J.-F. Remacle"; } + virtual std::string getCopyright() const + { + return "C. Geuzaine, J.-F. Remacle"; + } // when an error is thrown by the plugin, the plugin manager will // show the message and hopefully continue @@ -72,18 +74,20 @@ class GMSH_Plugin // dynamic pointer to a drawing function static void setDrawFunction(void (*fct)(void *)); #ifndef SWIG - static void (*draw)(void*); + static void (*draw)(void *); #endif }; // The base class for post-processing plugins. The user can either // modify or duplicate a post-processing view -class GMSH_PostPlugin : public GMSH_Plugin -{ - public: - inline GMSH_PLUGIN_TYPE getType() const { return GMSH_Plugin::GMSH_POST_PLUGIN; } +class GMSH_PostPlugin : public GMSH_Plugin { +public: + inline GMSH_PLUGIN_TYPE getType() const + { + return GMSH_Plugin::GMSH_POST_PLUGIN; + } // run the plugin - virtual void run(){ execute(0); } + virtual void run() { execute(0); } // if the returned pointer is the same as the argument, then the // view is simply modified, else, a new view is added in the view // list @@ -95,7 +99,7 @@ class GMSH_PostPlugin : public GMSH_Plugin // list) virtual PView *getView(int index, PView *view); // get the data in list format - virtual PViewDataList *getDataList(PView *view, bool showError=true); + virtual PViewDataList *getDataList(PView *view, bool showError = true); // get the the adapted data (i.e. linear, on refined mesh) if // available, otherwise get the original data virtual PViewData *getPossiblyAdaptiveData(PView *view); @@ -107,10 +111,12 @@ class GMSH_PostPlugin : public GMSH_Plugin // associate some properties to physical entities, so that we can // interface gmsh with a solver (ABAQUS...), i.e., create the input // file for the solver -class GMSH_SolverPlugin : public GMSH_Plugin -{ - public: - inline GMSH_PLUGIN_TYPE getType() const { return GMSH_Plugin::GMSH_SOLVER_PLUGIN; } +class GMSH_SolverPlugin : public GMSH_Plugin { +public: + inline GMSH_PLUGIN_TYPE getType() const + { + return GMSH_Plugin::GMSH_SOLVER_PLUGIN; + } virtual void run() {} // popup dialog box virtual void popupPropertiesForPhysicalEntity(int dim) = 0; @@ -123,12 +129,17 @@ class GMSH_SolverPlugin : public GMSH_Plugin // enhance graphics for a giver geo point virtual bool GL_enhancePoint(Vertex *v) { return false; } // enhance graphics for a giver geo line - virtual bool GL_enhanceLine(int CurveId, Vertex *v1, Vertex *v2) { return false; } + virtual bool GL_enhanceLine(int CurveId, Vertex *v1, Vertex *v2) + { + return false; + } }; -class GMSH_MeshPlugin : public GMSH_Plugin -{ - inline GMSH_PLUGIN_TYPE getType() const { return GMSH_Plugin::GMSH_MESH_PLUGIN; } +class GMSH_MeshPlugin : public GMSH_Plugin { + inline GMSH_PLUGIN_TYPE getType() const + { + return GMSH_Plugin::GMSH_MESH_PLUGIN; + } virtual void run() {} }; diff --git a/Plugin/PluginManager.cpp b/Plugin/PluginManager.cpp index 18cbfadacc3521780d365aef08e1c6aefa6d744a..232d85c340996c3ad29f7fd229547644dc10d265 100644 --- a/Plugin/PluginManager.cpp +++ b/Plugin/PluginManager.cpp @@ -87,38 +87,39 @@ PluginManager *PluginManager::_instance = 0; PluginManager::~PluginManager() { - for(std::map<std::string, GMSH_Plugin*>::iterator it = allPlugins.begin(); + for(std::map<std::string, GMSH_Plugin *>::iterator it = allPlugins.begin(); it != allPlugins.end(); ++it) delete it->second; } GMSH_Plugin *PluginManager::find(std::string pluginName) { - std::map<std::string, GMSH_Plugin*>::iterator it = allPlugins.find(pluginName); - if(it == allPlugins.end()) - return 0; + std::map<std::string, GMSH_Plugin *>::iterator it = + allPlugins.find(pluginName); + if(it == allPlugins.end()) return 0; return it->second; } GMSH_SolverPlugin *PluginManager::findSolverPlugin() { - std::map<std::string, GMSH_Plugin*>::iterator it = allPlugins.begin(); - std::map<std::string, GMSH_Plugin*>::iterator ite = allPlugins.end(); - for (; it != ite; ++it) { + std::map<std::string, GMSH_Plugin *>::iterator it = allPlugins.begin(); + std::map<std::string, GMSH_Plugin *>::iterator ite = allPlugins.end(); + for(; it != ite; ++it) { GMSH_Plugin *p = it->second; if(p->getType() == GMSH_Plugin::GMSH_SOLVER_PLUGIN) { - return (GMSH_SolverPlugin*)(p); + return (GMSH_SolverPlugin *)(p); } } return 0; } -void PluginManager::action(std::string pluginName, std::string action, void *data) +void PluginManager::action(std::string pluginName, std::string action, + void *data) { GMSH_Plugin *plugin = find(pluginName); if(!plugin) throw "Unknown plugin name"; - if(action == "Run"){ + if(action == "Run") { Msg::Info("Running Plugin(%s)...", pluginName.c_str()); plugin->run(); Msg::Info("Done running Plugin(%s)", pluginName.c_str()); @@ -167,138 +168,138 @@ PluginManager *PluginManager::instance() void PluginManager::registerDefaultPlugins() { - if(CTX::instance()->solver.plugins){ + if(CTX::instance()->solver.plugins) { // nothing here yet } - if(CTX::instance()->post.plugins){ - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("StreamLines", GMSH_RegisterStreamLinesPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Particles", GMSH_RegisterParticlesPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("CutGrid", GMSH_RegisterCutGridPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Isosurface", GMSH_RegisterIsosurfacePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("CutPlane", GMSH_RegisterCutPlanePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("CutSphere", GMSH_RegisterCutSpherePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("CutBox", GMSH_RegisterCutBoxPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Skin", GMSH_RegisterSkinPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("MathEval", GMSH_RegisterMathEvalPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("CurvedBndDist", GMSH_RegisterCurvedBndDistPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("ModifyComponents", GMSH_RegisterModifyComponentsPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("ExtractElements", GMSH_RegisterExtractElementsPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("CutParametric", GMSH_RegisterCutParametricPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("MakeSimplex", GMSH_RegisterMakeSimplexPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Smooth", GMSH_RegisterSmoothPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Transform", GMSH_RegisterTransformPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("LongitudeLatitude",GMSH_RegisterLongituteLatitudePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Warp", GMSH_RegisterWarpPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("SphericalRaise", GMSH_RegisterSphericalRaisePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("HarmonicToTime", GMSH_RegisterHarmonicToTimePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("ModulusPhase", GMSH_RegisterModulusPhasePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Integrate", GMSH_RegisterIntegratePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("MinMax", GMSH_RegisterMinMaxPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Gradient", GMSH_RegisterGradientPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Curl", GMSH_RegisterCurlPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Divergence", GMSH_RegisterDivergencePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Annotate", GMSH_RegisterAnnotatePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Remove", GMSH_RegisterRemovePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Eigenvectors", GMSH_RegisterEigenvectorsPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Eigenvalues", GMSH_RegisterEigenvaluesPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Lambda2", GMSH_RegisterLambda2Plugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Probe", GMSH_RegisterProbePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Triangulate", GMSH_RegisterTriangulatePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("ExtractEdges", GMSH_RegisterExtractEdgesPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("FieldFromAmplitudePhase", GMSH_RegisterFieldFromAmplitudePhasePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("NearToFarField", GMSH_RegisterNearToFarFieldPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Bubbles", GMSH_RegisterBubblesPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("DiscretizationError", GMSH_RegisterDiscretizationErrorPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Scal2Tens", GMSH_RegisterScal2TensPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Scal2Vec", GMSH_RegisterScal2VecPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("NewView", GMSH_RegisterNewViewPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("SimplePartition", GMSH_RegisterSimplePartitionPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Crack", GMSH_RegisterCrackPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("FaultZone", GMSH_RegisterFaultZonePlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("ThinLayerFixMesh", GMSH_RegisterThinLayerFixMeshPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("ShowNeighborElements", GMSH_RegisterShowNeighborElementsPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("MeshSubEntities", GMSH_RegisterMeshSubEntitiesPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("GaussPoints", GMSH_RegisterGaussPointsPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Summation", GMSH_RegisterSummationPlugin())); + if(CTX::instance()->post.plugins) { + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "StreamLines", GMSH_RegisterStreamLinesPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Particles", GMSH_RegisterParticlesPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "CutGrid", GMSH_RegisterCutGridPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Isosurface", GMSH_RegisterIsosurfacePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "CutPlane", GMSH_RegisterCutPlanePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "CutSphere", GMSH_RegisterCutSpherePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "CutBox", GMSH_RegisterCutBoxPlugin())); + allPlugins.insert( + std::pair<std::string, GMSH_Plugin *>("Skin", GMSH_RegisterSkinPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "MathEval", GMSH_RegisterMathEvalPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "CurvedBndDist", GMSH_RegisterCurvedBndDistPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "ModifyComponents", GMSH_RegisterModifyComponentsPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "ExtractElements", GMSH_RegisterExtractElementsPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "CutParametric", GMSH_RegisterCutParametricPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "MakeSimplex", GMSH_RegisterMakeSimplexPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Smooth", GMSH_RegisterSmoothPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Transform", GMSH_RegisterTransformPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "LongitudeLatitude", GMSH_RegisterLongituteLatitudePlugin())); + allPlugins.insert( + std::pair<std::string, GMSH_Plugin *>("Warp", GMSH_RegisterWarpPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "SphericalRaise", GMSH_RegisterSphericalRaisePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "HarmonicToTime", GMSH_RegisterHarmonicToTimePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "ModulusPhase", GMSH_RegisterModulusPhasePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Integrate", GMSH_RegisterIntegratePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "MinMax", GMSH_RegisterMinMaxPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Gradient", GMSH_RegisterGradientPlugin())); + allPlugins.insert( + std::pair<std::string, GMSH_Plugin *>("Curl", GMSH_RegisterCurlPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Divergence", GMSH_RegisterDivergencePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Annotate", GMSH_RegisterAnnotatePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Remove", GMSH_RegisterRemovePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Eigenvectors", GMSH_RegisterEigenvectorsPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Eigenvalues", GMSH_RegisterEigenvaluesPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Lambda2", GMSH_RegisterLambda2Plugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Probe", GMSH_RegisterProbePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Triangulate", GMSH_RegisterTriangulatePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "ExtractEdges", GMSH_RegisterExtractEdgesPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "FieldFromAmplitudePhase", GMSH_RegisterFieldFromAmplitudePhasePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "NearToFarField", GMSH_RegisterNearToFarFieldPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Bubbles", GMSH_RegisterBubblesPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "DiscretizationError", GMSH_RegisterDiscretizationErrorPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Scal2Tens", GMSH_RegisterScal2TensPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Scal2Vec", GMSH_RegisterScal2VecPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "NewView", GMSH_RegisterNewViewPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "SimplePartition", GMSH_RegisterSimplePartitionPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Crack", GMSH_RegisterCrackPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "FaultZone", GMSH_RegisterFaultZonePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "ThinLayerFixMesh", GMSH_RegisterThinLayerFixMeshPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "ShowNeighborElements", GMSH_RegisterShowNeighborElementsPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "MeshSubEntities", GMSH_RegisterMeshSubEntitiesPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "GaussPoints", GMSH_RegisterGaussPointsPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Summation", GMSH_RegisterSummationPlugin())); #if defined(HAVE_MESH) - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("AnalyseCurvedMesh", GMSH_RegisterAnalyseCurvedMeshPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("VoroMetal", GMSH_RegisterVoroMetalPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Tetrahedralize", GMSH_RegisterTetrahedralizePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "AnalyseCurvedMesh", GMSH_RegisterAnalyseCurvedMeshPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "VoroMetal", GMSH_RegisterVoroMetalPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Tetrahedralize", GMSH_RegisterTetrahedralizePlugin())); #endif #if defined(HAVE_REVOROPT) - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("CVTRemesh", GMSH_RegisterCVTRemeshPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "CVTRemesh", GMSH_RegisterCVTRemeshPlugin())); #endif #if defined(HAVE_KBIPACK) - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Homology", GMSH_RegisterHomologyComputationPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("HomologyPost", GMSH_RegisterHomologyPostProcessingPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Homology", GMSH_RegisterHomologyComputationPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "HomologyPost", GMSH_RegisterHomologyPostProcessingPlugin())); #endif #if defined(HAVE_SOLVER) - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Distance", GMSH_RegisterDistancePlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "Distance", GMSH_RegisterDistancePlugin())); #endif #if defined(HAVE_ANN) - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("NearestNeighbor", GMSH_RegisterNearestNeighborPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "NearestNeighbor", GMSH_RegisterNearestNeighborPlugin())); #endif #if defined(HAVE_DINTEGRATION) - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("CutMesh", GMSH_RegisterCutMeshPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>( + "CutMesh", GMSH_RegisterCutMeshPlugin())); #endif } @@ -307,15 +308,12 @@ void PluginManager::registerDefaultPlugins() if(!pluginsHome) return; struct dirent **list; int nbFiles = fl_filename_list(pluginsHome, &list); - if(nbFiles <= 0) - return; + if(nbFiles <= 0) return; for(int i = 0; i < nbFiles; i++) { std::string ext = SplitFileName(list[i]->d_name)[2]; - if(ext == ".so" || ext == ".dll") - addPlugin(list[i]->d_name); + if(ext == ".so" || ext == ".dll") addPlugin(list[i]->d_name); } - for(int i = 0; i < nbFiles; i++) - free(list[i]); + for(int i = 0; i < nbFiles; i++) free(list[i]); free(list); #endif } @@ -328,17 +326,18 @@ void PluginManager::addPlugin(std::string fileName) Msg::Info("Opening Plugin '%s'", fileName.c_str()); void *hlib = dlopen(fileName.c_str(), RTLD_NOW); const char *err = dlerror(); - if(!hlib){ + if(!hlib) { Msg::Warning("Could not open '%s' (dlerror = %s)", fileName.c_str(), err); return; } - class GMSH_Plugin *(*registerPlugin) (void); - registerPlugin = (class GMSH_Plugin * (*)(void))dlsym(hlib, GMSH_PluginEntry); + class GMSH_Plugin *(*registerPlugin)(void); + registerPlugin = + (class GMSH_Plugin * (*)(void)) dlsym(hlib, GMSH_PluginEntry); err = dlerror(); - if(err){ - Msg::Warning("Symbol '%s' missing in '%s' (dlerror = %s)", - GMSH_PluginEntry, fileName.c_str(), err); + if(err) { + Msg::Warning("Symbol '%s' missing in '%s' (dlerror = %s)", GMSH_PluginEntry, + fileName.c_str(), err); return; } @@ -349,7 +348,8 @@ void PluginManager::addPlugin(std::string fileName) return; } - allPlugins.insert(std::pair<std::string, GMSH_Plugin*>(p->getName(), p)); - Msg::Info("Loaded Plugin '%s' (%s)", p->getName().c_str(), p->getAuthor().c_str()); + allPlugins.insert(std::pair<std::string, GMSH_Plugin *>(p->getName(), p)); + Msg::Info("Loaded Plugin '%s' (%s)", p->getName().c_str(), + p->getAuthor().c_str()); #endif } diff --git a/Plugin/PluginManager.h b/Plugin/PluginManager.h index db959a379c7b02dc4fc82adff774d797719cdcc6..d5f2cb5bb9c628cc00417033b7b85e9874c52fc6 100644 --- a/Plugin/PluginManager.h +++ b/Plugin/PluginManager.h @@ -12,16 +12,15 @@ class GMSH_Plugin; class GMSH_SolverPlugin; -class PluginManager -{ - private: - PluginManager(){} +class PluginManager { +private: + PluginManager() {} static PluginManager *_instance; - std::map<std::string, GMSH_Plugin*> allPlugins; + std::map<std::string, GMSH_Plugin *> allPlugins; - public : +public: virtual ~PluginManager(); - + // register all the plugins that are in $(GMSHPLUGINSHOME). (Note // that loading a .so is not what is usually called a 'plugin': we // should call the plugins 'modules'... A plugin is an executable, @@ -36,14 +35,20 @@ class PluginManager void uninstallPlugin(std::string pluginName){}; // Set an option to a value in plugin named pluginName - void setPluginOption(std::string pluginName, std::string option, + void setPluginOption(std::string pluginName, std::string option, double value); - void setPluginOption(std::string pluginName, std::string option, + void setPluginOption(std::string pluginName, std::string option, std::string value); // Iterator on plugins - std::map<std::string, GMSH_Plugin*>::iterator begin(){ return allPlugins.begin(); } - std::map<std::string, GMSH_Plugin*>::iterator end(){ return allPlugins.end(); } + std::map<std::string, GMSH_Plugin *>::iterator begin() + { + return allPlugins.begin(); + } + std::map<std::string, GMSH_Plugin *>::iterator end() + { + return allPlugins.end(); + } // Find a plugin named pluginName GMSH_Plugin *find(std::string pluginName); diff --git a/Plugin/Probe.cpp b/Plugin/Probe.cpp index 9006b0a4304ba08b938c711c0bf95598f9732978..a9388079245c5c7b41e001680547892e69caf1ca 100644 --- a/Plugin/Probe.cpp +++ b/Plugin/Probe.cpp @@ -21,12 +21,8 @@ StringXNumber ProbeOptions_Number[] = { {GMSH_FULLRC, "View", NULL, -1.}, }; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterProbePlugin() - { - return new GMSH_ProbePlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterProbePlugin() { return new GMSH_ProbePlugin(); } } void GMSH_ProbePlugin::draw(void *context) @@ -34,31 +30,36 @@ void GMSH_ProbePlugin::draw(void *context) #if defined(HAVE_OPENGL) int num = (int)ProbeOptions_Number[3].def; if(num < 0) num = iview; - if(num >= 0 && num < (int)PView::list.size()){ + if(num >= 0 && num < (int)PView::list.size()) { double x = ProbeOptions_Number[0].def; double y = ProbeOptions_Number[1].def; double z = ProbeOptions_Number[2].def; - drawContext *ctx = (drawContext*)context; - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); + drawContext *ctx = (drawContext *)context; + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); glLineWidth((float)CTX::instance()->lineWidth); SBoundingBox3d bb = PView::list[num]->getData()->getBoundingBox(); - if(x >= bb.min().x() && x <= bb.max().x() && - y >= bb.min().y() && y <= bb.max().y() && - z >= bb.min().z() && z <= bb.max().z()){ + if(x >= bb.min().x() && x <= bb.max().x() && y >= bb.min().y() && + y <= bb.max().y() && z >= bb.min().z() && z <= bb.max().z()) { // we're inside the bounding box: draw a large cross glBegin(GL_LINES); - glVertex3d(bb.min().x(), y, z); glVertex3d(bb.max().x(), y, z); - glVertex3d(x, bb.min().y(), z); glVertex3d(x, bb.max().y(), z); - glVertex3d(x, y, bb.min().z()); glVertex3d(x, y, bb.max().z()); + glVertex3d(bb.min().x(), y, z); + glVertex3d(bb.max().x(), y, z); + glVertex3d(x, bb.min().y(), z); + glVertex3d(x, bb.max().y(), z); + glVertex3d(x, y, bb.min().z()); + glVertex3d(x, y, bb.max().z()); glEnd(); } - else{ + else { // draw 10-pixel marker double d = 10 * ctx->pixel_equiv_x / ctx->s[0]; glBegin(GL_LINES); - glVertex3d(x - d, y, z); glVertex3d(x + d, y, z); - glVertex3d(x, y - d, z); glVertex3d(x, y + d, z); - glVertex3d(x, y, z - d); glVertex3d(x, y, z + d); + glVertex3d(x - d, y, z); + glVertex3d(x + d, y, z); + glVertex3d(x, y - d, z); + glVertex3d(x, y + d, z); + glVertex3d(x, y, z - d); + glVertex3d(x, y, z + d); glEnd(); } ctx->drawSphere(CTX::instance()->pointSize, x, y, z, 1); @@ -66,10 +67,11 @@ void GMSH_ProbePlugin::draw(void *context) #endif } -double GMSH_ProbePlugin::callback(int num, int action, double value, double *opt) +double GMSH_ProbePlugin::callback(int num, int action, double value, + double *opt) { if(action > 0) iview = num; - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return CTX::instance()->lc / 100.; case 2: return -2 * CTX::instance()->lc; case 3: return 2 * CTX::instance()->lc; @@ -98,9 +100,9 @@ double GMSH_ProbePlugin::callbackZ(int num, int action, double value) std::string GMSH_ProbePlugin::getHelp() const { return "Plugin(Probe) gets the value of the view `View' at " - "the point (`X',`Y',`Z').\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Probe) creates one new view."; + "the point (`X',`Y',`Z').\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Probe) creates one new view."; } int GMSH_ProbePlugin::getNbOptions() const @@ -131,40 +133,37 @@ PView *GMSH_ProbePlugin::execute(PView *v) OctreePost o(v1); - if(o.searchScalar(x, y, z, val)){ + if(o.searchScalar(x, y, z, val)) { data2->SP.push_back(x); data2->SP.push_back(y); data2->SP.push_back(z); - for(int i = 0; i < numSteps; i++) - data2->SP.push_back(val[i]); + for(int i = 0; i < numSteps; i++) data2->SP.push_back(val[i]); data2->NbSP++; } - if(o.searchVector(x, y, z, val)){ + if(o.searchVector(x, y, z, val)) { data2->VP.push_back(x); data2->VP.push_back(y); data2->VP.push_back(z); - for(int i = 0; i < numSteps; i++){ - for(int j = 0; j < 3; j++) - data2->VP.push_back(val[3 * i + j]); + for(int i = 0; i < numSteps; i++) { + for(int j = 0; j < 3; j++) data2->VP.push_back(val[3 * i + j]); } data2->NbVP++; } - if(o.searchTensor(x, y, z, val)){ + if(o.searchTensor(x, y, z, val)) { data2->TP.push_back(x); data2->TP.push_back(y); data2->TP.push_back(z); - for(int i = 0; i < numSteps; i++){ - for(int j = 0; j < 9; j++) - data2->TP.push_back(val[9 * i + j]); + for(int i = 0; i < numSteps; i++) { + for(int j = 0; j < 9; j++) data2->TP.push_back(val[9 * i + j]); } data2->NbTP++; } - delete [] val; + delete[] val; - for(int i = 0; i < numSteps; i++){ + for(int i = 0; i < numSteps; i++) { double time = v1->getData()->getTime(i); data2->Time.push_back(time); } diff --git a/Plugin/Probe.h b/Plugin/Probe.h index 2390c62e2ba9d34a4ec3e8b51665390f19c49b70..7a04a814fc12457532a79f270a0140d7d7f23811 100644 --- a/Plugin/Probe.h +++ b/Plugin/Probe.h @@ -8,26 +8,22 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterProbePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterProbePlugin(); } -class GMSH_ProbePlugin : public GMSH_PostPlugin -{ +class GMSH_ProbePlugin : public GMSH_PostPlugin { double levelset(double x, double y, double z, double val) const; static double callback(int num, int action, double value, double *opt); static int iview; - public: - GMSH_ProbePlugin(){} + +public: + GMSH_ProbePlugin() {} std::string getName() const { return "Probe"; } - std::string getShortHelp() const - { - return "Get value at point (X, Y, Z)"; - } + std::string getShortHelp() const { return "Get value at point (X, Y, Z)"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); static double callbackX(int, int, double); diff --git a/Plugin/Remove.cpp b/Plugin/Remove.cpp index 51928c0c19d75812ea3cfafa2d6940d7b9f4d347..f150c333720a50c2300bde8b6ab9af7667c5c8d8 100644 --- a/Plugin/Remove.cpp +++ b/Plugin/Remove.cpp @@ -6,36 +6,24 @@ #include "Remove.h" StringXNumber RemoveOptions_Number[] = { - {GMSH_FULLRC, "Text2D", NULL, 1.}, - {GMSH_FULLRC, "Text3D", NULL, 1.}, - {GMSH_FULLRC, "Points", NULL, 0.}, - {GMSH_FULLRC, "Lines", NULL, 0.}, - {GMSH_FULLRC, "Triangles", NULL, 0.}, - {GMSH_FULLRC, "Quadrangles", NULL, 0.}, - {GMSH_FULLRC, "Tetrahedra", NULL, 0.}, - {GMSH_FULLRC, "Hexahedra", NULL, 0.}, - {GMSH_FULLRC, "Prisms", NULL, 0.}, - {GMSH_FULLRC, "Pyramids", NULL, 0.}, - {GMSH_FULLRC, "Scalar", NULL, 1.}, - {GMSH_FULLRC, "Vector", NULL, 1.}, - {GMSH_FULLRC, "Tensor", NULL, 1.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "Text2D", NULL, 1.}, {GMSH_FULLRC, "Text3D", NULL, 1.}, + {GMSH_FULLRC, "Points", NULL, 0.}, {GMSH_FULLRC, "Lines", NULL, 0.}, + {GMSH_FULLRC, "Triangles", NULL, 0.}, {GMSH_FULLRC, "Quadrangles", NULL, 0.}, + {GMSH_FULLRC, "Tetrahedra", NULL, 0.}, {GMSH_FULLRC, "Hexahedra", NULL, 0.}, + {GMSH_FULLRC, "Prisms", NULL, 0.}, {GMSH_FULLRC, "Pyramids", NULL, 0.}, + {GMSH_FULLRC, "Scalar", NULL, 1.}, {GMSH_FULLRC, "Vector", NULL, 1.}, + {GMSH_FULLRC, "Tensor", NULL, 1.}, {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterRemovePlugin() - { - return new GMSH_RemovePlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterRemovePlugin() { return new GMSH_RemovePlugin(); } } std::string GMSH_RemovePlugin::getHelp() const { return "Plugin(Remove) removes the marked items " - "from the view `View'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Remove) is executed in-place."; + "from the view `View'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Remove) is executed in-place."; } int GMSH_RemovePlugin::getNbOptions() const @@ -57,56 +45,132 @@ PView *GMSH_RemovePlugin::execute(PView *v) PViewDataList *data1 = getDataList(v1); if(!data1) return v; - + int scalar = (int)RemoveOptions_Number[10].def; int vector = (int)RemoveOptions_Number[11].def; int tensor = (int)RemoveOptions_Number[12].def; - if(RemoveOptions_Number[0].def){ - data1->NbT2 = 0; data1->T2D.clear(); data1->T2C.clear(); + if(RemoveOptions_Number[0].def) { + data1->NbT2 = 0; + data1->T2D.clear(); + data1->T2C.clear(); } - if(RemoveOptions_Number[1].def){ - data1->NbT3 = 0; data1->T3D.clear(); data1->T3C.clear(); + if(RemoveOptions_Number[1].def) { + data1->NbT3 = 0; + data1->T3D.clear(); + data1->T3C.clear(); } - if(RemoveOptions_Number[2].def){ - if(scalar){ data1->NbSP = 0; data1->SP.clear(); } - if(vector){ data1->NbVP = 0; data1->VP.clear(); } - if(tensor){ data1->NbTP = 0; data1->TP.clear(); } + if(RemoveOptions_Number[2].def) { + if(scalar) { + data1->NbSP = 0; + data1->SP.clear(); + } + if(vector) { + data1->NbVP = 0; + data1->VP.clear(); + } + if(tensor) { + data1->NbTP = 0; + data1->TP.clear(); + } } - if(RemoveOptions_Number[3].def){ - if(scalar){ data1->NbSL = 0; data1->SL.clear(); } - if(vector){ data1->NbVL = 0; data1->VL.clear(); } - if(tensor){ data1->NbTL = 0; data1->TL.clear(); } + if(RemoveOptions_Number[3].def) { + if(scalar) { + data1->NbSL = 0; + data1->SL.clear(); + } + if(vector) { + data1->NbVL = 0; + data1->VL.clear(); + } + if(tensor) { + data1->NbTL = 0; + data1->TL.clear(); + } } - if(RemoveOptions_Number[4].def){ - if(scalar){ data1->NbST = 0; data1->ST.clear(); } - if(vector){ data1->NbVT = 0; data1->VT.clear(); } - if(tensor){ data1->NbTT = 0; data1->TT.clear(); } + if(RemoveOptions_Number[4].def) { + if(scalar) { + data1->NbST = 0; + data1->ST.clear(); + } + if(vector) { + data1->NbVT = 0; + data1->VT.clear(); + } + if(tensor) { + data1->NbTT = 0; + data1->TT.clear(); + } } - if(RemoveOptions_Number[5].def){ - if(scalar){ data1->NbSQ = 0; data1->SQ.clear(); } - if(vector){ data1->NbVQ = 0; data1->VQ.clear(); } - if(tensor){ data1->NbTQ = 0; data1->TQ.clear(); } + if(RemoveOptions_Number[5].def) { + if(scalar) { + data1->NbSQ = 0; + data1->SQ.clear(); + } + if(vector) { + data1->NbVQ = 0; + data1->VQ.clear(); + } + if(tensor) { + data1->NbTQ = 0; + data1->TQ.clear(); + } } - if(RemoveOptions_Number[6].def){ - if(scalar){ data1->NbSS = 0; data1->SS.clear(); } - if(vector){ data1->NbVS = 0; data1->VS.clear(); } - if(tensor){ data1->NbTS = 0; data1->TS.clear(); } + if(RemoveOptions_Number[6].def) { + if(scalar) { + data1->NbSS = 0; + data1->SS.clear(); + } + if(vector) { + data1->NbVS = 0; + data1->VS.clear(); + } + if(tensor) { + data1->NbTS = 0; + data1->TS.clear(); + } } - if(RemoveOptions_Number[7].def){ - if(scalar){ data1->NbSH = 0; data1->SH.clear(); } - if(vector){ data1->NbVH = 0; data1->VH.clear(); } - if(tensor){ data1->NbTH = 0; data1->TH.clear(); } + if(RemoveOptions_Number[7].def) { + if(scalar) { + data1->NbSH = 0; + data1->SH.clear(); + } + if(vector) { + data1->NbVH = 0; + data1->VH.clear(); + } + if(tensor) { + data1->NbTH = 0; + data1->TH.clear(); + } } - if(RemoveOptions_Number[8].def){ - if(scalar){ data1->NbSI = 0; data1->SI.clear(); } - if(vector){ data1->NbVI = 0; data1->VI.clear(); } - if(tensor){ data1->NbTI = 0; data1->TI.clear(); } + if(RemoveOptions_Number[8].def) { + if(scalar) { + data1->NbSI = 0; + data1->SI.clear(); + } + if(vector) { + data1->NbVI = 0; + data1->VI.clear(); + } + if(tensor) { + data1->NbTI = 0; + data1->TI.clear(); + } } - if(RemoveOptions_Number[9].def){ - if(scalar){ data1->NbSY = 0; data1->SY.clear(); } - if(vector){ data1->NbVY = 0; data1->VY.clear(); } - if(tensor){ data1->NbTY = 0; data1->TY.clear(); } + if(RemoveOptions_Number[9].def) { + if(scalar) { + data1->NbSY = 0; + data1->SY.clear(); + } + if(vector) { + data1->NbVY = 0; + data1->VY.clear(); + } + if(tensor) { + data1->NbTY = 0; + data1->TY.clear(); + } } data1->finalize(); diff --git a/Plugin/Remove.h b/Plugin/Remove.h index aeb7248a36582da413c87a88ee963eb100fbf6b2..faadafeba8edee9dd908cce0b0b8cf2a3fbdbe2a 100644 --- a/Plugin/Remove.h +++ b/Plugin/Remove.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterRemovePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterRemovePlugin(); } -class GMSH_RemovePlugin : public GMSH_PostPlugin -{ - public: - GMSH_RemovePlugin(){} +class GMSH_RemovePlugin : public GMSH_PostPlugin { +public: + GMSH_RemovePlugin() {} std::string getName() const { return "Remove"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_RemovePlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Scal2Tens.cpp b/Plugin/Scal2Tens.cpp index 085e60c8340918caee95168ba351b752d8e363be..3c551c9a5aa5b9b73dd965ff9a543ce0a7abd22f 100644 --- a/Plugin/Scal2Tens.cpp +++ b/Plugin/Scal2Tens.cpp @@ -17,26 +17,24 @@ StringXNumber Scal2TensOptions_Number[] = { {GMSH_FULLRC, "View5", NULL, -1}, {GMSH_FULLRC, "View6", NULL, -1}, {GMSH_FULLRC, "View7", NULL, -1}, - {GMSH_FULLRC, "View8", NULL, -1} -}; + {GMSH_FULLRC, "View8", NULL, -1}}; StringXString Scal2TensOptions_String[] = { - {GMSH_FULLRC, "NameNewView", NULL, "NewView"} -}; + {GMSH_FULLRC, "NameNewView", NULL, "NewView"}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterScal2TensPlugin() { - GMSH_Plugin *GMSH_RegisterScal2TensPlugin() - { - return new GMSH_Scal2TensPlugin(); - } + return new GMSH_Scal2TensPlugin(); +} } std::string GMSH_Scal2TensPlugin::getHelp() const { return "Plugin(Scal2Tens) converts some scalar fields into a tensor field. " "The number of components must be given (max. 9). " - "The new view 'NameNewView' contains the new tensor field. If the number " + "The new view 'NameNewView' contains the new tensor field. If the " + "number " "of a view is -1, the value of the corresponding component is 0."; } @@ -60,66 +58,71 @@ StringXString *GMSH_Scal2TensPlugin::getOptionStr(int iopt) return &Scal2TensOptions_String[iopt]; } - PView *GMSH_Scal2TensPlugin::execute(PView *v) { // Load options int numComp = (int)Scal2TensOptions_Number[0].def; - if ((numComp<1) || (numComp>9)) { - Msg::Error("Scal2Tens plugin: NumberOfComponents must be between 1 and 9 (not '%i')", numComp); + if((numComp < 1) || (numComp > 9)) { + Msg::Error( + "Scal2Tens plugin: NumberOfComponents must be between 1 and 9 (not '%i')", + numComp); return v; } int iView[9]; - for (int comp=0; comp<numComp; comp++) - iView[comp] = (int)Scal2TensOptions_Number[comp+1].def; - + for(int comp = 0; comp < numComp; comp++) + iView[comp] = (int)Scal2TensOptions_Number[comp + 1].def; + // Load data - PView *vRef=0, *vComp[9]; - for (int comp=0; comp<numComp; comp++) { - if (iView[comp]<0) vComp[comp] = 0; + PView *vRef = 0, *vComp[9]; + for(int comp = 0; comp < numComp; comp++) { + if(iView[comp] < 0) + vComp[comp] = 0; else { vComp[comp] = getView(iView[comp], v); - if (!vComp[comp]) { + if(!vComp[comp]) { Msg::Error("Scal2Tens plugin could not find View '%i'", iView[comp]); return v; } - if (!vRef) vRef = vComp[comp]; + if(!vRef) vRef = vComp[comp]; } } - if (!vRef) { + if(!vRef) { Msg::Error("Scal2Tens plugin could not find any view."); return v; } PViewData *dataRef = vRef->getData(); - + // Initialize the new view PView *vNew = new PView(); PViewDataList *dataNew = getDataList(vNew); - + int step0 = dataRef->getFirstNonEmptyTimeStep(); - for (int ent=0; ent < dataRef->getNumEntities(step0); ent++) { - for (int ele=0; ele < dataRef->getNumElements(step0, ent); ele++) { - if (dataRef->skipElement(step0, ent, ele)) continue; + for(int ent = 0; ent < dataRef->getNumEntities(step0); ent++) { + for(int ele = 0; ele < dataRef->getNumElements(step0, ent); ele++) { + if(dataRef->skipElement(step0, ent, ele)) continue; int type = dataRef->getType(step0, ent, ele); int numNodes = dataRef->getNumNodes(step0, ent, ele); - std::vector<double> *out = dataNew->incrementList(numComp, type, numNodes); // Pointer in data of the new view - if (!out) continue; + std::vector<double> *out = dataNew->incrementList( + numComp, type, numNodes); // Pointer in data of the new view + if(!out) continue; double x[8], y[8], z[8]; - for (int nod=0; nod<numNodes; nod++) + for(int nod = 0; nod < numNodes; nod++) dataRef->getNode(step0, ent, ele, nod, x[nod], y[nod], z[nod]); int dim = dataRef->getDimension(step0, ent, ele); elementFactory factory; element *element = factory.create(numNodes, dim, x, y, z); - if (!element) continue; - for (int nod=0; nod<numNodes; nod++) out->push_back(x[nod]); // Save coordinates (x,y,z) - for (int nod=0; nod<numNodes; nod++) out->push_back(y[nod]); - for (int nod=0; nod<numNodes; nod++) out->push_back(z[nod]); - for (int step=step0; step < dataRef->getNumTimeSteps(); step++) { - if (!dataRef->hasTimeStep(step)) continue; - for (int nod=0; nod<numNodes; nod++) { - for (int comp=0; comp<numComp; comp++) { - double val=0.; - if(vComp[comp]) vComp[comp]->getData()->getValue(step, ent, ele, nod, 0, val); + if(!element) continue; + for(int nod = 0; nod < numNodes; nod++) + out->push_back(x[nod]); // Save coordinates (x,y,z) + for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); + for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); + for(int step = step0; step < dataRef->getNumTimeSteps(); step++) { + if(!dataRef->hasTimeStep(step)) continue; + for(int nod = 0; nod < numNodes; nod++) { + for(int comp = 0; comp < numComp; comp++) { + double val = 0.; + if(vComp[comp]) + vComp[comp]->getData()->getValue(step, ent, ele, nod, 0, val); out->push_back(val); // Save value } } @@ -127,16 +130,16 @@ PView *GMSH_Scal2TensPlugin::execute(PView *v) delete element; } } - - for (int step=step0; step < dataRef->getNumTimeSteps(); step++) { - if (!dataRef->hasTimeStep(step)) continue; + + for(int step = step0; step < dataRef->getNumTimeSteps(); step++) { + if(!dataRef->hasTimeStep(step)) continue; dataNew->Time.push_back(dataRef->getTime(step)); } - + std::string nameNewView = Scal2TensOptions_String[0].def; dataNew->setName(nameNewView); dataNew->setFileName(nameNewView + ".pos"); dataNew->finalize(); - + return vNew; } diff --git a/Plugin/Scal2Tens.h b/Plugin/Scal2Tens.h index 8700b01408b2f0966db012658d55634084137436..877211c8595724b787f83a79136f08f6d9718521 100644 --- a/Plugin/Scal2Tens.h +++ b/Plugin/Scal2Tens.h @@ -8,25 +8,24 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterScal2TensPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterScal2TensPlugin(); } -class GMSH_Scal2TensPlugin : public GMSH_PostPlugin -{ - public: - GMSH_Scal2TensPlugin(){} +class GMSH_Scal2TensPlugin : public GMSH_PostPlugin { +public: + GMSH_Scal2TensPlugin() {} std::string getName() const { return "Scal2Tens"; } std::string getShortHelp() const { - return "Convert some scalar fields into a tensor field with several components"; + return "Convert some scalar fields into a tensor field with several " + "components"; } std::string getHelp() const; int getNbOptions() const; StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Scal2Vec.cpp b/Plugin/Scal2Vec.cpp index 6e11d2e22c2e9ddf35b3edf3ceda020ee8fb987c..c91a17e4cf3ed5d3ce44dea3681a95f2aab1950e 100644 --- a/Plugin/Scal2Vec.cpp +++ b/Plugin/Scal2Vec.cpp @@ -7,22 +7,15 @@ #include "PViewOptions.h" #include "shapeFunctions.h" -StringXNumber Scal2VecOptions_Number[] = { - {GMSH_FULLRC, "ViewX", NULL, -1}, - {GMSH_FULLRC, "ViewY", NULL, -1}, - {GMSH_FULLRC, "ViewZ", NULL, -1} -}; +StringXNumber Scal2VecOptions_Number[] = {{GMSH_FULLRC, "ViewX", NULL, -1}, + {GMSH_FULLRC, "ViewY", NULL, -1}, + {GMSH_FULLRC, "ViewZ", NULL, -1}}; StringXString Scal2VecOptions_String[] = { - {GMSH_FULLRC, "NameNewView", NULL, "NewView"} -}; + {GMSH_FULLRC, "NameNewView", NULL, "NewView"}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterScal2VecPlugin() - { - return new GMSH_Scal2VecPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterScal2VecPlugin() { return new GMSH_Scal2VecPlugin(); } } std::string GMSH_Scal2VecPlugin::getHelp() const @@ -53,61 +46,64 @@ StringXString *GMSH_Scal2VecPlugin::getOptionStr(int iopt) return &Scal2VecOptions_String[iopt]; } - PView *GMSH_Scal2VecPlugin::execute(PView *v) { // Load options int iView[3]; - for (int comp=0; comp<3; comp++) + for(int comp = 0; comp < 3; comp++) iView[comp] = (int)Scal2VecOptions_Number[comp].def; - + // Load data - PView *vRef=0, *vComp[3]; - for (int comp=0; comp<3; comp++) { - if (iView[comp]<0) vComp[comp] = 0; + PView *vRef = 0, *vComp[3]; + for(int comp = 0; comp < 3; comp++) { + if(iView[comp] < 0) + vComp[comp] = 0; else { vComp[comp] = getView(iView[comp], v); - if (!vComp[comp]) { + if(!vComp[comp]) { Msg::Error("Scal2Vec plugin could not find View '%i'", iView[comp]); return v; } - if (!vRef) vRef = vComp[comp]; + if(!vRef) vRef = vComp[comp]; } } - if (!vRef) { + if(!vRef) { Msg::Error("Scal2Vec plugin could not find any view."); return v; } PViewData *dataRef = vRef->getData(); - + // Initialize the new view PView *vNew = new PView(); PViewDataList *dataNew = getDataList(vNew); - + int step0 = dataRef->getFirstNonEmptyTimeStep(); - for (int ent=0; ent < dataRef->getNumEntities(step0); ent++) { - for (int ele=0; ele < dataRef->getNumElements(step0, ent); ele++) { - if (dataRef->skipElement(step0, ent, ele)) continue; + for(int ent = 0; ent < dataRef->getNumEntities(step0); ent++) { + for(int ele = 0; ele < dataRef->getNumElements(step0, ent); ele++) { + if(dataRef->skipElement(step0, ent, ele)) continue; int type = dataRef->getType(step0, ent, ele); int numNodes = dataRef->getNumNodes(step0, ent, ele); - std::vector<double> *out = dataNew->incrementList(3, type, numNodes); // Pointer in data of the new view - if (!out) continue; + std::vector<double> *out = dataNew->incrementList( + 3, type, numNodes); // Pointer in data of the new view + if(!out) continue; double x[8], y[8], z[8]; - for (int nod=0; nod<numNodes; nod++) + for(int nod = 0; nod < numNodes; nod++) dataRef->getNode(step0, ent, ele, nod, x[nod], y[nod], z[nod]); int dim = dataRef->getDimension(step0, ent, ele); elementFactory factory; element *element = factory.create(numNodes, dim, x, y, z); - if (!element) continue; - for (int nod=0; nod<numNodes; nod++) out->push_back(x[nod]); // Save coordinates (x,y,z) - for (int nod=0; nod<numNodes; nod++) out->push_back(y[nod]); - for (int nod=0; nod<numNodes; nod++) out->push_back(z[nod]); - for (int step=step0; step < dataRef->getNumTimeSteps(); step++) { - if (!dataRef->hasTimeStep(step)) continue; - for (int nod=0; nod<numNodes; nod++) { - for (int comp=0; comp<3; comp++) { - double val=0.; - if(vComp[comp]) vComp[comp]->getData()->getValue(step, ent, ele, nod, 0, val); + if(!element) continue; + for(int nod = 0; nod < numNodes; nod++) + out->push_back(x[nod]); // Save coordinates (x,y,z) + for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); + for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); + for(int step = step0; step < dataRef->getNumTimeSteps(); step++) { + if(!dataRef->hasTimeStep(step)) continue; + for(int nod = 0; nod < numNodes; nod++) { + for(int comp = 0; comp < 3; comp++) { + double val = 0.; + if(vComp[comp]) + vComp[comp]->getData()->getValue(step, ent, ele, nod, 0, val); out->push_back(val); // Save value } } @@ -115,16 +111,16 @@ PView *GMSH_Scal2VecPlugin::execute(PView *v) delete element; } } - - for (int step=step0; step < dataRef->getNumTimeSteps(); step++) { - if (!dataRef->hasTimeStep(step)) continue; + + for(int step = step0; step < dataRef->getNumTimeSteps(); step++) { + if(!dataRef->hasTimeStep(step)) continue; dataNew->Time.push_back(dataRef->getTime(step)); } - + std::string nameNewView = Scal2VecOptions_String[0].def; dataNew->setName(nameNewView); dataNew->setFileName(nameNewView + ".pos"); dataNew->finalize(); - + return vNew; } diff --git a/Plugin/Scal2Vec.h b/Plugin/Scal2Vec.h index 8ecda7bff20d0d167d3bb082d68736108f29ab13..f124857a5f503fd4f8213a51fd383e07a13be83f 100644 --- a/Plugin/Scal2Vec.h +++ b/Plugin/Scal2Vec.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterScal2VecPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterScal2VecPlugin(); } -class GMSH_Scal2VecPlugin : public GMSH_PostPlugin -{ - public: - GMSH_Scal2VecPlugin(){} +class GMSH_Scal2VecPlugin : public GMSH_PostPlugin { +public: + GMSH_Scal2VecPlugin() {} std::string getName() const { return "Scal2Vec"; } std::string getShortHelp() const { @@ -26,7 +24,7 @@ class GMSH_Scal2VecPlugin : public GMSH_PostPlugin int getNbOptions() const; StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); }; diff --git a/Plugin/ShowNeighborElements.cpp b/Plugin/ShowNeighborElements.cpp index 280d2f4c8ece98735ebf28052161d824674b2576..06f4bb3bc0efa3215e3b6f300f2f22494f4a8352 100644 --- a/Plugin/ShowNeighborElements.cpp +++ b/Plugin/ShowNeighborElements.cpp @@ -15,19 +15,14 @@ #endif StringXNumber ShowNeighborElementsOptions_Number[] = { - {GMSH_FULLRC, "NumLayers", NULL, 1}, - {GMSH_FULLRC, "Element1", NULL, 0}, - {GMSH_FULLRC, "Element2", NULL, 0}, - {GMSH_FULLRC, "Element3", NULL, 0}, - {GMSH_FULLRC, "Element4", NULL, 0}, - {GMSH_FULLRC, "Element5", NULL, 0} -}; -extern "C" + {GMSH_FULLRC, "NumLayers", NULL, 1}, {GMSH_FULLRC, "Element1", NULL, 0}, + {GMSH_FULLRC, "Element2", NULL, 0}, {GMSH_FULLRC, "Element3", NULL, 0}, + {GMSH_FULLRC, "Element4", NULL, 0}, {GMSH_FULLRC, "Element5", NULL, 0}}; +extern "C" { +GMSH_Plugin *GMSH_RegisterShowNeighborElementsPlugin() { - GMSH_Plugin *GMSH_RegisterShowNeighborElementsPlugin() - { - return new GMSH_ShowNeighborElementsPlugin(); - } + return new GMSH_ShowNeighborElementsPlugin(); +} } int GMSH_ShowNeighborElementsPlugin::getNbOptions() const { @@ -39,12 +34,13 @@ StringXNumber *GMSH_ShowNeighborElementsPlugin::getOption(int iopt) } std::string GMSH_ShowNeighborElementsPlugin::getHelp() const { - return "Plugin(ShowNeighborElements) allows to set visible some given elements " - " and a layer of elements around them, the other being set invisible."; + return "Plugin(ShowNeighborElements) allows to set visible some given " + "elements " + " and a layer of elements around them, the other being set invisible."; } // Execution -PView* GMSH_ShowNeighborElementsPlugin::execute(PView *v) +PView *GMSH_ShowNeighborElementsPlugin::execute(PView *v) { GModel *m = GModel::current(); @@ -55,13 +51,13 @@ PView* GMSH_ShowNeighborElementsPlugin::execute(PView *v) _nel4 = static_cast<int>(ShowNeighborElementsOptions_Number[4].def); _nel5 = static_cast<int>(ShowNeighborElementsOptions_Number[5].def); - for (GModel::fiter it = m->firstFace(); it != m->lastFace(); it++) { + for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++) { GFace *f = *it; _init(f); _showLayers(f, _nLayers); } - for (GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++) { + for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++) { GRegion *r = *it; _init(r); _showLayers(r, _nLayers); @@ -78,21 +74,21 @@ PView* GMSH_ShowNeighborElementsPlugin::execute(PView *v) void GMSH_ShowNeighborElementsPlugin::_init(GEntity *ent) { _vert2elem.clear(); - for (unsigned i = 0; i < ent->getNumMeshElements(); ++i) { + for(unsigned i = 0; i < ent->getNumMeshElements(); ++i) { MElement *el = ent->getMeshElement(i); - if (el->getNum() == _nel1 || - el->getNum() == _nel2 || - el->getNum() == _nel3 || - el->getNum() == _nel4 || - el->getNum() == _nel5) { + if(el->getNum() == _nel1 || el->getNum() == _nel2 || + el->getNum() == _nel3 || el->getNum() == _nel4 || + el->getNum() == _nel5) { el->setVisibility(true); - for (std::size_t k = 0; k < el->getNumVertices(); ++k) { // TODO only corner vertices? + for(std::size_t k = 0; k < el->getNumVertices(); + ++k) { // TODO only corner vertices? _vertices.insert(el->getVertex(k)); } } else { el->setVisibility(false); - for (std::size_t k = 0; k < el->getNumVertices(); ++k) { // TODO only corner vertices? + for(std::size_t k = 0; k < el->getNumVertices(); + ++k) { // TODO only corner vertices? _vert2elem.insert(std::make_pair(el->getVertex(k), el)); } } @@ -101,35 +97,36 @@ void GMSH_ShowNeighborElementsPlugin::_init(GEntity *ent) void GMSH_ShowNeighborElementsPlugin::_showLayers(GEntity *ent, int nLayer) { -// std::pair<std::multimap<MVertex*, MElement*>::iterator, -// std::multimap<MVertex*, MElement*>::iterator> lowUpBound; + // std::pair<std::multimap<MVertex*, MElement*>::iterator, + // std::multimap<MVertex*, MElement*>::iterator> lowUpBound; - if (_vertices.empty() || nLayer < 1) return; + if(_vertices.empty() || nLayer < 1) return; - std::set<MVertex*> &vert = _vertices; -// _vertices.clear(); - std::map<MElement*, int> el2cnt; + std::set<MVertex *> &vert = _vertices; + // _vertices.clear(); + std::map<MElement *, int> el2cnt; - std::set<MVertex*>::iterator it; - for (it = vert.begin(); it != vert.end(); ++it) { + std::set<MVertex *>::iterator it; + for(it = vert.begin(); it != vert.end(); ++it) { MVertex *v = *it; - std::multimap<MVertex*, MElement*>::iterator ite, itstop; + std::multimap<MVertex *, MElement *>::iterator ite, itstop; ite = _vert2elem.lower_bound(v); itstop = _vert2elem.upper_bound(v); - for (; ite != itstop; ++ite) { + for(; ite != itstop; ++ite) { MElement *el = ite->second; - if (el2cnt.find(el) == el2cnt.end()) el2cnt[el] = 0; + if(el2cnt.find(el) == el2cnt.end()) el2cnt[el] = 0; ++el2cnt[el]; -// el->setVisibility(true); -// for (int k = 0; k < el->getNumVertices(); ++k) { // TODO only corner vertices? -// _vertices.insert(el->getVertex(k)); -// } + // el->setVisibility(true); + // for (int k = 0; k < el->getNumVertices(); ++k) { // TODO only + // corner vertices? + // _vertices.insert(el->getVertex(k)); + // } } } - std::map<MElement*, int>::iterator it2; - for (it2 = el2cnt.begin(); it2 != el2cnt.end(); ++it2) { - if (it2->second && it2->second > 3-nLayer) { + std::map<MElement *, int>::iterator it2; + for(it2 = el2cnt.begin(); it2 != el2cnt.end(); ++it2) { + if(it2->second && it2->second > 3 - nLayer) { it2->first->setVisibility(true); } } diff --git a/Plugin/ShowNeighborElements.h b/Plugin/ShowNeighborElements.h index 8b2d045d6d1d73f9e889bef566c5df00d1a877e1..7b287fc973f4c558b074006b047ae9c475994a8a 100644 --- a/Plugin/ShowNeighborElements.h +++ b/Plugin/ShowNeighborElements.h @@ -11,32 +11,31 @@ class MVertex; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterShowNeighborElementsPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterShowNeighborElementsPlugin(); } -class GMSH_ShowNeighborElementsPlugin : public GMSH_PostPlugin -{ -private : +class GMSH_ShowNeighborElementsPlugin : public GMSH_PostPlugin { +private: int _nLayers; int _nel1, _nel2, _nel3, _nel4, _nel5; - std::multimap<MVertex*, MElement*> _vert2elem; - std::set<MVertex*> _vertices; + std::multimap<MVertex *, MElement *> _vert2elem; + std::set<MVertex *> _vertices; -public : +public: GMSH_ShowNeighborElementsPlugin() {} std::string getName() const { return "ShowNeighborElements"; } - std::string getShortHelp() const { + std::string getShortHelp() const + { return "Choose which type of element to hide."; } std::string getHelp() const; std::string getAuthor() const { return "Amaury Johnen"; } int getNbOptions() const; - StringXNumber* getOption(int); - PView* execute(PView *); + StringXNumber *getOption(int); + PView *execute(PView *); -private : +private: void _init(GEntity *); void _showLayers(GEntity *, int nLayer); }; diff --git a/Plugin/SimplePartition.cpp b/Plugin/SimplePartition.cpp index a28973d86793f1b24b33263a5a6079a480630727..4aafd63bdb2e934b1ba95135f1f6b79f2c4e1166 100644 --- a/Plugin/SimplePartition.cpp +++ b/Plugin/SimplePartition.cpp @@ -28,7 +28,7 @@ #endif int PartitionUsingThisSplit(GModel *const model, unsigned int npart, - hashmap<MElement*, unsigned int> &elmToPartition); + hashmap<MElement *, unsigned int> &elmToPartition); StringXNumber SimplePartitionOptions_Number[] = { {GMSH_FULLRC, "NumSlices", NULL, 4.}, @@ -37,23 +37,21 @@ StringXNumber SimplePartitionOptions_Number[] = { }; StringXString SimplePartitionOptions_String[] = { - {GMSH_FULLRC, "Mapping", NULL, "t"} -}; + {GMSH_FULLRC, "Mapping", NULL, "t"}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterSimplePartitionPlugin() { - GMSH_Plugin *GMSH_RegisterSimplePartitionPlugin() - { - return new GMSH_SimplePartitionPlugin(); - } + return new GMSH_SimplePartitionPlugin(); +} } std::string GMSH_SimplePartitionPlugin::getHelp() const { return "Plugin(SimplePartition) partitions the current mesh into " - "`NumSlices' slices, along the X-, Y- or Z-axis depending on " - "the value of `Direction' (0,1,2). The plugin creates partition " - "topology if `CreateTopology' is set."; + "`NumSlices' slices, along the X-, Y- or Z-axis depending on " + "the value of `Direction' (0,1,2). The plugin creates partition " + "topology if `CreateTopology' is set."; } int GMSH_SimplePartitionPlugin::getNbOptions() const @@ -99,27 +97,27 @@ void GMSH_SimplePartitionPlugin::run() mathEvaluator f(expr, variables); if(expr.empty()) return; std::vector<double> values(1), res(1); - for(int p = 0; p <= numSlices; p++){ + for(int p = 0; p <= numSlices; p++) { double t = values[0] = (double)p / (double)numSlices; if(f.eval(values, res)) t = res[0]; pp[p] = pmin + t * (pmax - pmin); } - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; m->getEntities(entities); - hashmap<MElement*, unsigned int> elmToPartition; - for(unsigned int i = 0; i < entities.size(); i++){ + hashmap<MElement *, unsigned int> elmToPartition; + for(unsigned int i = 0; i < entities.size(); i++) { GEntity *ge = entities[i]; - for(unsigned int j = 0; j < ge->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < ge->getNumMeshElements(); j++) { MElement *e = ge->getMeshElement(j); SPoint3 point = e->barycenter(); - for(int k = 0; k < numSlices; k++){ - if(pp[k] < point[direction] && pp[k+1] >= point[direction]){ - elmToPartition.insert(std::pair<MElement*, unsigned int>(e, k+1)); + for(int k = 0; k < numSlices; k++) { + if(pp[k] < point[direction] && pp[k + 1] >= point[direction]) { + elmToPartition.insert(std::pair<MElement *, unsigned int>(e, k + 1)); break; } - if(pp[0] == point[direction]){ - elmToPartition.insert(std::pair<MElement*, unsigned int>(e, 0+1)); + if(pp[0] == point[direction]) { + elmToPartition.insert(std::pair<MElement *, unsigned int>(e, 0 + 1)); break; } } @@ -131,6 +129,7 @@ void GMSH_SimplePartitionPlugin::run() PartitionUsingThisSplit(m, numSlices, elmToPartition); #else - Msg::Error("Gmsh must be compiled with Mesh and METIS support to partition meshes"); + Msg::Error( + "Gmsh must be compiled with Mesh and METIS support to partition meshes"); #endif } diff --git a/Plugin/SimplePartition.h b/Plugin/SimplePartition.h index 81f237f28a6f888c327b64f62b6b5e0ecc5ad81e..e7ab5fb656728f16ae5989c2795acc1ffd967666 100644 --- a/Plugin/SimplePartition.h +++ b/Plugin/SimplePartition.h @@ -8,25 +8,20 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSimplePartitionPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterSimplePartitionPlugin(); } -class GMSH_SimplePartitionPlugin : public GMSH_MeshPlugin -{ - public: - GMSH_SimplePartitionPlugin(){} +class GMSH_SimplePartitionPlugin : public GMSH_MeshPlugin { +public: + GMSH_SimplePartitionPlugin() {} std::string getName() const { return "SimplePartition"; } - std::string getShortHelp() const - { - return "Simple mesh partitioner"; - } + std::string getShortHelp() const { return "Simple mesh partitioner"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); void run(); }; diff --git a/Plugin/Skin.cpp b/Plugin/Skin.cpp index 25c7ca12f2d9337b5c3dc8933e323161f444f2a2..00b5b5f54b6a845093ec6a400c15e1a76614258e 100644 --- a/Plugin/Skin.cpp +++ b/Plugin/Skin.cpp @@ -15,28 +15,22 @@ #include "discreteFace.h" #include "discreteEdge.h" -StringXNumber SkinOptions_Number[] = { - {GMSH_FULLRC, "Visible", NULL, 1.}, - {GMSH_FULLRC, "FromMesh", NULL, 0.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; +StringXNumber SkinOptions_Number[] = {{GMSH_FULLRC, "Visible", NULL, 1.}, + {GMSH_FULLRC, "FromMesh", NULL, 0.}, + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSkinPlugin() - { - return new GMSH_SkinPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterSkinPlugin() { return new GMSH_SkinPlugin(); } } std::string GMSH_SkinPlugin::getHelp() const { return "Plugin(Skin) extracts the boundary (skin) of the current " - "mesh (if `FromMesh' = 1), or from the the view `View' (in which " - "case it creates a new view). If `View' < 0 and `FromMesh' = 0, " - "the plugin is run on the current view.\n" - "If `Visible' is set, the plugin only extracts the skin of visible " - "entities."; + "mesh (if `FromMesh' = 1), or from the the view `View' (in which " + "case it creates a new view). If `View' < 0 and `FromMesh' = 0, " + "the plugin is run on the current view.\n" + "If `Visible' is set, the plugin only extracts the skin of visible " + "entities."; } int GMSH_SkinPlugin::getNbOptions() const @@ -50,7 +44,7 @@ StringXNumber *GMSH_SkinPlugin::getOption(int iopt) } class ElmData { - public: +public: int numComp; std::vector<double> x, y, z; std::vector<double> v; @@ -59,7 +53,7 @@ class ElmData { { SPoint3 p(0., 0., 0.); int N = x.size(); - for(int i = 0; i < N; i++){ + for(int i = 0; i < N; i++) { p[0] += x[i]; p[1] += y[i]; p[2] += z[i]; @@ -72,26 +66,74 @@ class ElmData { void addInView(PViewDataList *data) const { std::vector<double> *vec = 0; - switch(x.size()){ + switch(x.size()) { case 1: - if (numComp == 1){ data->NbSP++; vec = &data->SP; break; } - else if(numComp == 3){ data->NbVP++; vec = &data->VP; break; } - else if(numComp == 9){ data->NbTP++; vec = &data->TP; break; } + if(numComp == 1) { + data->NbSP++; + vec = &data->SP; + break; + } + else if(numComp == 3) { + data->NbVP++; + vec = &data->VP; + break; + } + else if(numComp == 9) { + data->NbTP++; + vec = &data->TP; + break; + } break; case 2: - if (numComp == 1){ data->NbSL++; vec = &data->SL; break; } - else if(numComp == 3){ data->NbVL++; vec = &data->VL; break; } - else if(numComp == 9){ data->NbTL++; vec = &data->TL; break; } + if(numComp == 1) { + data->NbSL++; + vec = &data->SL; + break; + } + else if(numComp == 3) { + data->NbVL++; + vec = &data->VL; + break; + } + else if(numComp == 9) { + data->NbTL++; + vec = &data->TL; + break; + } break; case 3: - if (numComp == 1){ data->NbST++; vec = &data->ST; break; } - else if(numComp == 3){ data->NbVT++; vec = &data->VT; break; } - else if(numComp == 9){ data->NbTT++; vec = &data->TT; break; } + if(numComp == 1) { + data->NbST++; + vec = &data->ST; + break; + } + else if(numComp == 3) { + data->NbVT++; + vec = &data->VT; + break; + } + else if(numComp == 9) { + data->NbTT++; + vec = &data->TT; + break; + } break; case 4: - if (numComp == 1){ data->NbSQ++; vec = &data->SQ; break; } - else if(numComp == 3){ data->NbVQ++; vec = &data->VQ; break; } - else if(numComp == 9){ data->NbTQ++; vec = &data->TQ; break; } + if(numComp == 1) { + data->NbSQ++; + vec = &data->SQ; + break; + } + else if(numComp == 3) { + data->NbVQ++; + vec = &data->VQ; + break; + } + else if(numComp == 9) { + data->NbTQ++; + vec = &data->TQ; + break; + } break; } if(!vec) return; @@ -102,18 +144,18 @@ class ElmData { } }; -class ElmDataLessThan{ - public: +class ElmDataLessThan { +public: static double tolerance; bool operator()(const ElmData &e1, const ElmData &e2) const { SPoint3 p1 = e1.barycenter(); SPoint3 p2 = e2.barycenter(); - if(p1.x() - p2.x() > tolerance) return true; + if(p1.x() - p2.x() > tolerance) return true; if(p1.x() - p2.x() < -tolerance) return false; - if(p1.y() - p2.y() > tolerance) return true; + if(p1.y() - p2.y() > tolerance) return true; if(p1.y() - p2.y() < -tolerance) return false; - if(p1.z() - p2.z() > tolerance) return true; + if(p1.z() - p2.z() > tolerance) return true; return false; } }; @@ -122,44 +164,43 @@ double ElmDataLessThan::tolerance = 1.e-12; static int getBoundary(int type, const int (**boundary)[6][4]) { - static const int tri[6][4] = - {{0,1,-1,-1}, {1,2,-1,-1}, {2,0,-1,-1}}; - static const int qua[6][4] = - {{0,1,-1,-1}, {1,2,-1,-1}, {2,3,-1,-1}, {3,0,-1,-1}}; - static const int tet[6][4] = - {{0,1,3,-1}, {0,2,1,-1}, {0,3,2,-1}, {1,2,3,-1}}; - static const int hex[6][4] = - {{0,1,5,4}, {0,3,2,1}, {0,4,7,3}, {1,2,6,5}, {2,3,7,6}, {4,5,6,7}}; - static const int pri[6][4] = - {{0,1,4,3}, {0,3,5,2}, {1,2,5,4}, {0,2,1,-1}, {3,4,5,-1}}; - static const int pyr[6][4] = - {{0,3,2,1}, {0,1,4,-1}, {0,4,3,-1}, {1,2,4,-1}, {2,3,4,-1}}; - switch(type){ + static const int tri[6][4] = {{0, 1, -1, -1}, {1, 2, -1, -1}, {2, 0, -1, -1}}; + static const int qua[6][4] = { + {0, 1, -1, -1}, {1, 2, -1, -1}, {2, 3, -1, -1}, {3, 0, -1, -1}}; + static const int tet[6][4] = { + {0, 1, 3, -1}, {0, 2, 1, -1}, {0, 3, 2, -1}, {1, 2, 3, -1}}; + static const int hex[6][4] = {{0, 1, 5, 4}, {0, 3, 2, 1}, {0, 4, 7, 3}, + {1, 2, 6, 5}, {2, 3, 7, 6}, {4, 5, 6, 7}}; + static const int pri[6][4] = { + {0, 1, 4, 3}, {0, 3, 5, 2}, {1, 2, 5, 4}, {0, 2, 1, -1}, {3, 4, 5, -1}}; + static const int pyr[6][4] = { + {0, 3, 2, 1}, {0, 1, 4, -1}, {0, 4, 3, -1}, {1, 2, 4, -1}, {2, 3, 4, -1}}; + switch(type) { case TYPE_TRI: *boundary = &tri; return 3; case TYPE_QUA: *boundary = &qua; return 4; case TYPE_TET: *boundary = &tet; return 4; case TYPE_HEX: *boundary = &hex; return 6; case TYPE_PRI: *boundary = &pri; return 5; case TYPE_PYR: *boundary = &pyr; return 5; - default : return 0; + default: return 0; } } static void getBoundaryFromMesh(GModel *m, int visible) { int dim = m->getDim(); - std::vector<GEntity*> entities; + std::vector<GEntity *> entities; m->getEntities(entities); std::set<MFace, Less_Face> bndFaces; std::set<MEdge, Less_Edge> bndEdges; - for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int i = 0; i < entities.size(); i++) { GEntity *ge = entities[i]; if(ge->dim() != dim) continue; if(visible && !ge->getVisibility()) continue; - for(unsigned int j = 0; j < ge->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < ge->getNumMeshElements(); j++) { MElement *e = ge->getMeshElement(j); - if(dim == 2){ - for(int i = 0; i < e->getNumEdges(); i++){ + if(dim == 2) { + for(int i = 0; i < e->getNumEdges(); i++) { MEdge f = e->getEdge(i); if(bndEdges.find(f) == bndEdges.end()) bndEdges.insert(f); @@ -167,8 +208,8 @@ static void getBoundaryFromMesh(GModel *m, int visible) bndEdges.erase(f); } } - else if(dim == 3){ - for(int i = 0; i < e->getNumFaces(); i++){ + else if(dim == 3) { + for(int i = 0; i < e->getNumFaces(); i++) { MFace f = e->getFace(i); if(bndFaces.find(f) == bndFaces.end()) bndFaces.insert(f); @@ -179,25 +220,27 @@ static void getBoundaryFromMesh(GModel *m, int visible) } } - if(dim == 2){ - discreteEdge *e = new discreteEdge(m, m->getMaxElementaryNumber(1) + 1, 0, 0); + if(dim == 2) { + discreteEdge *e = + new discreteEdge(m, m->getMaxElementaryNumber(1) + 1, 0, 0); m->add(e); for(std::set<MEdge, Less_Edge>::iterator it = bndEdges.begin(); - it != bndEdges.end(); it++){ + it != bndEdges.end(); it++) { e->lines.push_back(new MLine(it->getVertex(0), it->getVertex(1))); } } - else if(dim == 3){ + else if(dim == 3) { discreteFace *f = new discreteFace(m, m->getMaxElementaryNumber(2) + 1); m->add(f); for(std::set<MFace, Less_Face>::iterator it = bndFaces.begin(); - it != bndFaces.end(); it++){ + it != bndFaces.end(); it++) { if(it->getNumVertices() == 3) - f->triangles.push_back(new MTriangle(it->getVertex(0), it->getVertex(1), - it->getVertex(2))); + f->triangles.push_back( + new MTriangle(it->getVertex(0), it->getVertex(1), it->getVertex(2))); else if(it->getNumVertices() == 4) - f->quadrangles.push_back(new MQuadrangle(it->getVertex(0), it->getVertex(1), - it->getVertex(2), it->getVertex(3))); + f->quadrangles.push_back( + new MQuadrangle(it->getVertex(0), it->getVertex(1), it->getVertex(2), + it->getVertex(3))); } } } @@ -209,7 +252,7 @@ PView *GMSH_SkinPlugin::execute(PView *v) int iView = (int)SkinOptions_Number[2].def; // compute boundary of current mesh - if(fromMesh){ + if(fromMesh) { getBoundaryFromMesh(GModel::current(), visible); return v; } @@ -219,7 +262,7 @@ PView *GMSH_SkinPlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = getPossiblyAdaptiveData(v1); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("Skin plugin cannot be applied to multi-mesh views"); return v; } @@ -233,18 +276,19 @@ PView *GMSH_SkinPlugin::execute(PView *v) ElmDataLessThan::tolerance = CTX::instance()->lc * 1.e-12; int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep(); - for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++){ + for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++) { if(visible && data1->skipEntity(firstNonEmptyStep, ent)) continue; - for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); ele++){ + for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent); + ele++) { if(data1->skipElement(firstNonEmptyStep, ent, ele, visible)) continue; int numComp = data1->getNumComponents(firstNonEmptyStep, ent, ele); int type = data1->getType(firstNonEmptyStep, ent, ele); - const int (*boundary)[6][4]; + const int(*boundary)[6][4]; int numBoundary = getBoundary(type, &boundary); if(!numBoundary) continue; - for(int i = 0; i < numBoundary; i++){ + for(int i = 0; i < numBoundary; i++) { ElmData e(numComp); - for(int j = 0; j < 4; j++){ + for(int j = 0; j < 4; j++) { int nod = (*boundary)[i][j]; if(nod < 0) continue; double x, y, z; @@ -254,14 +298,14 @@ PView *GMSH_SkinPlugin::execute(PView *v) e.z.push_back(z); } std::set<ElmData, ElmDataLessThan>::iterator it = skin.find(e); - if(it == skin.end()){ - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - if(data1->hasTimeStep(step)){ - for(int j = 0; j < 4; j++){ + if(it == skin.end()) { + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + if(data1->hasTimeStep(step)) { + for(int j = 0; j < 4; j++) { int nod = (*boundary)[i][j]; if(nod < 0) continue; double v; - for(int comp = 0; comp < numComp; comp++){ + for(int comp = 0; comp < numComp; comp++) { data1->getValue(step, ent, ele, nod, comp, v); e.v.push_back(v); } @@ -281,8 +325,7 @@ PView *GMSH_SkinPlugin::execute(PView *v) it->addInView(data2); for(int i = 0; i < data1->getNumTimeSteps(); i++) - if(data1->hasTimeStep(i)) - data2->Time.push_back(data1->getTime(i)); + if(data1->hasTimeStep(i)) data2->Time.push_back(data1->getTime(i)); data2->setName(data1->getName() + "_Skin"); data2->setFileName(data1->getName() + "_Skin.pos"); data2->finalize(); diff --git a/Plugin/Skin.h b/Plugin/Skin.h index 7110e0ca550dd247cd9ccac6fe63a8aa7957c182..60fddd67c828780e6a1ca4e19b243ae7617682cd 100644 --- a/Plugin/Skin.h +++ b/Plugin/Skin.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSkinPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterSkinPlugin(); } -class GMSH_SkinPlugin : public GMSH_PostPlugin -{ - public: - GMSH_SkinPlugin(){} +class GMSH_SkinPlugin : public GMSH_PostPlugin { +public: + GMSH_SkinPlugin() {} std::string getName() const { return "Skin"; } - std::string getShortHelp() const - { - return "Extract boundary of a view"; - } + std::string getShortHelp() const { return "Extract boundary of a view"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Smooth.cpp b/Plugin/Smooth.cpp index dbb78b4b69ccc86e5a22e0e590a3925fe3a53f09..4baee55d3b4eb713c1d1c26e7d6e7232cf522623 100644 --- a/Plugin/Smooth.cpp +++ b/Plugin/Smooth.cpp @@ -5,24 +5,18 @@ #include "Smooth.h" -StringXNumber SmoothOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.} -}; +StringXNumber SmoothOptions_Number[] = {{GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSmoothPlugin() - { - return new GMSH_SmoothPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterSmoothPlugin() { return new GMSH_SmoothPlugin(); } } std::string GMSH_SmoothPlugin::getHelp() const { return "Plugin(Smooth) averages the values at the nodes " - "of the view `View'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Smooth) is executed in-place."; + "of the view `View'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Smooth) is executed in-place."; } int GMSH_SmoothPlugin::getNbOptions() const diff --git a/Plugin/Smooth.h b/Plugin/Smooth.h index 6cd84866bc513db0d07d2360fd391e5d05949569..87b87fd91dca9f476127fa7681b56249def6f987 100644 --- a/Plugin/Smooth.h +++ b/Plugin/Smooth.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSmoothPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterSmoothPlugin(); } -class GMSH_SmoothPlugin : public GMSH_PostPlugin -{ - public: - GMSH_SmoothPlugin(){} +class GMSH_SmoothPlugin : public GMSH_PostPlugin { +public: + GMSH_SmoothPlugin() {} std::string getName() const { return "Smooth"; } - std::string getShortHelp() const - { - return "Apply nodal smoothing"; - } + std::string getShortHelp() const { return "Apply nodal smoothing"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/SphericalRaise.cpp b/Plugin/SphericalRaise.cpp index ea82683a61e730b5745df6ad5b5d1c83731e0621..e126ee9bf183f1ff29a8a44980d7baf61a4eed03 100644 --- a/Plugin/SphericalRaise.cpp +++ b/Plugin/SphericalRaise.cpp @@ -7,39 +7,34 @@ #include "Numeric.h" StringXNumber SphericalRaiseOptions_Number[] = { - {GMSH_FULLRC, "Xc", NULL, 0.}, - {GMSH_FULLRC, "Yc", NULL, 0.}, - {GMSH_FULLRC, "Zc", NULL, 0.}, - {GMSH_FULLRC, "Raise", NULL, 1.}, - {GMSH_FULLRC, "Offset", NULL, 0.}, - {GMSH_FULLRC, "TimeStep", NULL, 0.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "Xc", NULL, 0.}, {GMSH_FULLRC, "Yc", NULL, 0.}, + {GMSH_FULLRC, "Zc", NULL, 0.}, {GMSH_FULLRC, "Raise", NULL, 1.}, + {GMSH_FULLRC, "Offset", NULL, 0.}, {GMSH_FULLRC, "TimeStep", NULL, 0.}, + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin() { - GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin() - { - return new GMSH_SphericalRaisePlugin(); - } + return new GMSH_SphericalRaisePlugin(); +} } std::string GMSH_SphericalRaisePlugin::getHelp() const { return "Plugin(SphericalRaise) transforms the " - "coordinates of the elements in the view " - "`View' using the values associated with the " - "`TimeStep'-th time step.\n\n" - "Instead of elevating the nodes along the X, Y " - "and Z axes as with the View[`View'].RaiseX, " - "View[`View'].RaiseY and View[`View'].RaiseZ " - "options, the raise is applied along the radius " - "of a sphere centered at (`Xc', `Yc', `Zc').\n\n" - "To produce a standard radiation pattern, set " - "`Offset' to minus the radius of the sphere the " - "original data lives on.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(SphericalRaise) is executed in-place."; + "coordinates of the elements in the view " + "`View' using the values associated with the " + "`TimeStep'-th time step.\n\n" + "Instead of elevating the nodes along the X, Y " + "and Z axes as with the View[`View'].RaiseX, " + "View[`View'].RaiseY and View[`View'].RaiseZ " + "options, the raise is applied along the radius " + "of a sphere centered at (`Xc', `Yc', `Zc').\n\n" + "To produce a standard radiation pattern, set " + "`Offset' to minus the radius of the sphere the " + "original data lives on.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(SphericalRaise) is executed in-place."; } int GMSH_SphericalRaisePlugin::getNbOptions() const @@ -69,16 +64,16 @@ PView *GMSH_SphericalRaisePlugin::execute(PView *v) PViewData *data1 = v1->getData(); // sanity checks - if(timeStep < 0 || timeStep > data1->getNumTimeSteps() - 1){ + if(timeStep < 0 || timeStep > data1->getNumTimeSteps() - 1) { Msg::Error("Invalid TimeStep (%d) in view", timeStep); return v; } - if(data1->isNodeData()){ + if(data1->isNodeData()) { // tag all the nodes with "0" (the default tag) - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) data1->tagNode(step, ent, ele, nod, 0); @@ -88,11 +83,11 @@ PView *GMSH_SphericalRaisePlugin::execute(PView *v) } // transform all "0" nodes - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; - for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) { double x, y, z; int tag = data1->getNode(step, ent, ele, nod, x, y, z); if(data1->isNodeData() && tag) continue; diff --git a/Plugin/SphericalRaise.h b/Plugin/SphericalRaise.h index 8e769dc851208e7eaae6a20af358e183915ded39..c6edee9066cd33349958050a04911a4584997fb6 100644 --- a/Plugin/SphericalRaise.h +++ b/Plugin/SphericalRaise.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin(); } -class GMSH_SphericalRaisePlugin : public GMSH_PostPlugin -{ - public: - GMSH_SphericalRaisePlugin(){} +class GMSH_SphericalRaisePlugin : public GMSH_PostPlugin { +public: + GMSH_SphericalRaisePlugin() {} std::string getName() const { return "SphericalRaise"; } - std::string getShortHelp() const - { - return "Create spherical elevation plot"; - } + std::string getShortHelp() const { return "Create spherical elevation plot"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/StreamLines.cpp b/Plugin/StreamLines.cpp index 7196a672f5fbb09b85799a4d4a26759da6bae588..68f3d79df6698e52083eff92758f2902170a37ad 100644 --- a/Plugin/StreamLines.cpp +++ b/Plugin/StreamLines.cpp @@ -30,25 +30,23 @@ StringXNumber StreamLinesOptions_Number[] = { {GMSH_FULLRC, "MaxIter", NULL, 100}, {GMSH_FULLRC, "TimeStep", NULL, 0}, {GMSH_FULLRC, "View", NULL, -1.}, - {GMSH_FULLRC, "OtherView", NULL, -1.} -}; + {GMSH_FULLRC, "OtherView", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterStreamLinesPlugin() { - GMSH_Plugin *GMSH_RegisterStreamLinesPlugin() - { - return new GMSH_StreamLinesPlugin(); - } + return new GMSH_StreamLinesPlugin(); +} } void GMSH_StreamLinesPlugin::draw(void *context) { #if defined(HAVE_OPENGL) - glColor4ubv((GLubyte *) & CTX::instance()->color.fg); - drawContext *ctx = (drawContext*)context; + glColor4ubv((GLubyte *)&CTX::instance()->color.fg); + drawContext *ctx = (drawContext *)context; double p[3]; - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { getPoint(i, j, p); ctx->drawSphere(CTX::instance()->pointSize, p[0], p[1], p[2], 1); } @@ -56,10 +54,11 @@ void GMSH_StreamLinesPlugin::draw(void *context) #endif } -double GMSH_StreamLinesPlugin::callback(int num, int action, double value, double *opt, - double step, double min, double max) +double GMSH_StreamLinesPlugin::callback(int num, int action, double value, + double *opt, double step, double min, + double max) { - switch(action){ // configure the input field + switch(action) { // configure the input field case 1: return step; case 2: return min; case 3: return max; @@ -73,94 +72,103 @@ double GMSH_StreamLinesPlugin::callback(int num, int action, double value, doubl double GMSH_StreamLinesPlugin::callbackX0(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[0].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackY0(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[1].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackZ0(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[2].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackX1(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[3].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackY1(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[4].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackZ1(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[5].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackX2(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[6].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackY2(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[7].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackZ2(int num, int action, double value) { return callback(num, action, value, &StreamLinesOptions_Number[8].def, - CTX::instance()->lc/100., -2*CTX::instance()->lc, 2*CTX::instance()->lc); + CTX::instance()->lc / 100., -2 * CTX::instance()->lc, + 2 * CTX::instance()->lc); } double GMSH_StreamLinesPlugin::callbackU(int num, int action, double value) { - return callback(num, action, value, &StreamLinesOptions_Number[9].def, - 1, 1, 100); + return callback(num, action, value, &StreamLinesOptions_Number[9].def, 1, 1, + 100); } double GMSH_StreamLinesPlugin::callbackV(int num, int action, double value) { - return callback(num, action, value, &StreamLinesOptions_Number[10].def, - 1, 1, 100); + return callback(num, action, value, &StreamLinesOptions_Number[10].def, 1, 1, + 100); } std::string GMSH_StreamLinesPlugin::getHelp() const { return "Plugin(StreamLines) computes stream lines " - "from the `TimeStep'-th time step of a vector " - "view `View' and optionally interpolates the " - "scalar view `OtherView' on the resulting stream " - "lines.\n\n" - "The plugin takes as input a grid defined by the " - "3 points (`X0',`Y0',`Z0') (origin), (`X1',`Y1',`Z1') " - "(axis of U) and (`X2',`Y2',`Z2') (axis of V).\n\n" - "The number of points along U and V that are to be " - "transported is set with the options `NumPointsU' " - "and `NumPointsV'. The equation\n\n" - "dX(t)/dt = V(x,y,z)\n\n" - "is then solved with the initial condition X(t=0) " - "chosen as the grid and with V(x,y,z) interpolated " - "on the vector view.\n\n" - "The time stepping scheme is a RK44 with step size " - "`DT' and `MaxIter' maximum number of iterations.\n\n" - "If `TimeStep' < 0, the plugin tries to compute " - "streamlines of the unsteady flow.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(StreamLines) creates one new view. This " - "view contains multi-step vector points if `OtherView' " - "< 0, or single-step scalar lines if `OtherView' >= 0."; + "from the `TimeStep'-th time step of a vector " + "view `View' and optionally interpolates the " + "scalar view `OtherView' on the resulting stream " + "lines.\n\n" + "The plugin takes as input a grid defined by the " + "3 points (`X0',`Y0',`Z0') (origin), (`X1',`Y1',`Z1') " + "(axis of U) and (`X2',`Y2',`Z2') (axis of V).\n\n" + "The number of points along U and V that are to be " + "transported is set with the options `NumPointsU' " + "and `NumPointsV'. The equation\n\n" + "dX(t)/dt = V(x,y,z)\n\n" + "is then solved with the initial condition X(t=0) " + "chosen as the grid and with V(x,y,z) interpolated " + "on the vector view.\n\n" + "The time stepping scheme is a RK44 with step size " + "`DT' and `MaxIter' maximum number of iterations.\n\n" + "If `TimeStep' < 0, the plugin tries to compute " + "streamlines of the unsteady flow.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(StreamLines) creates one new view. This " + "view contains multi-step vector points if `OtherView' " + "< 0, or single-step scalar lines if `OtherView' >= 0."; } int GMSH_StreamLinesPlugin::getNbOptions() const @@ -187,15 +195,18 @@ void GMSH_StreamLinesPlugin::getPoint(int iU, int iV, double *X) { double u = getNbU() > 1 ? (double)iU / (double)(getNbU() - 1.) : 0.; double v = getNbV() > 1 ? (double)iV / (double)(getNbV() - 1.) : 0.; - X[0] = StreamLinesOptions_Number[0].def + - u * (StreamLinesOptions_Number[3].def - StreamLinesOptions_Number[0].def) + - v * (StreamLinesOptions_Number[6].def - StreamLinesOptions_Number[0].def); - X[1] = StreamLinesOptions_Number[1].def + - u * (StreamLinesOptions_Number[4].def - StreamLinesOptions_Number[1].def) + - v * (StreamLinesOptions_Number[7].def - StreamLinesOptions_Number[1].def); - X[2] = StreamLinesOptions_Number[2].def + - u * (StreamLinesOptions_Number[5].def - StreamLinesOptions_Number[2].def) + - v * (StreamLinesOptions_Number[8].def - StreamLinesOptions_Number[2].def); + X[0] = + StreamLinesOptions_Number[0].def + + u * (StreamLinesOptions_Number[3].def - StreamLinesOptions_Number[0].def) + + v * (StreamLinesOptions_Number[6].def - StreamLinesOptions_Number[0].def); + X[1] = + StreamLinesOptions_Number[1].def + + u * (StreamLinesOptions_Number[4].def - StreamLinesOptions_Number[1].def) + + v * (StreamLinesOptions_Number[7].def - StreamLinesOptions_Number[1].def); + X[2] = + StreamLinesOptions_Number[2].def + + u * (StreamLinesOptions_Number[5].def - StreamLinesOptions_Number[2].def) + + v * (StreamLinesOptions_Number[8].def - StreamLinesOptions_Number[2].def); } PView *GMSH_StreamLinesPlugin::execute(PView *v) @@ -214,7 +225,7 @@ PView *GMSH_StreamLinesPlugin::execute(PView *v) PViewData *data2 = v2 ? getPossiblyAdaptiveData(v2) : 0; // sanity checks - if(timeStep > data1->getNumTimeSteps() - 1){ + if(timeStep > data1->getNumTimeSteps() - 1) { Msg::Error("Invalid time step (%d) in view[%d]", v1->getIndex()); return v; } @@ -222,7 +233,7 @@ PView *GMSH_StreamLinesPlugin::execute(PView *v) OctreePost o1(v1); double *val2 = 0; OctreePost *o2 = 0; - if(data2){ + if(data2) { val2 = new double[data2->getNumTimeSteps()]; o2 = new OctreePost(v2); } @@ -234,15 +245,15 @@ PView *GMSH_StreamLinesPlugin::execute(PView *v) const double a1 = 0.5, a2 = 0.5, a3 = 1., a4 = 1.; double XINIT[3], X[3], DX[3], X1[3], X2[3], X3[3], X4[3]; - for(int i = 0; i < getNbU(); ++i){ - for(int j = 0; j < getNbV(); ++j){ + for(int i = 0; i < getNbU(); ++i) { + for(int j = 0; j < getNbV(); ++j) { getPoint(i, j, XINIT); getPoint(i, j, X); - - if(data2){ + + if(data2) { o2->searchScalar(X[0], X[1], X[2], val2, -1); } - else{ + else { data3->NbVP++; data3->VP.push_back(X[0]); data3->VP.push_back(X[1]); @@ -251,20 +262,20 @@ PView *GMSH_StreamLinesPlugin::execute(PView *v) int currentTimeStep = 0; - for(int iter = 0; iter < maxIter; iter++){ - + for(int iter = 0; iter < maxIter; iter++) { double XPREV[3] = {X[0], X[1], X[2]}; - if(timeStep < 0){ + if(timeStep < 0) { double T0 = data1->getTime(0); double currentT = T0 + DT * iter; data3->Time.push_back(currentT); - for(; currentTimeStep < data1->getNumTimeSteps() - 1 && - currentT > 0.5 * (data1->getTime(currentTimeStep) + + for(; currentTimeStep < data1->getNumTimeSteps() - 1 && + currentT > 0.5 * (data1->getTime(currentTimeStep) + data1->getTime(currentTimeStep + 1)); - currentTimeStep++); + currentTimeStep++) + ; } - else{ + else { currentTimeStep = timeStep; } @@ -284,23 +295,26 @@ PView *GMSH_StreamLinesPlugin::execute(PView *v) o1.searchVector(X3[0], X3[1], X3[2], val, currentTimeStep); for(int k = 0; k < 3; k++) X4[k] = X[k] + DT * val[k] * a4; - for(int k = 0; k < 3; k++) - X[k] += (b1 * (X1[k] - X[k]) + b2 * (X2[k] - X[k]) + + for(int k = 0; k < 3; k++) + X[k] += (b1 * (X1[k] - X[k]) + b2 * (X2[k] - X[k]) + b3 * (X3[k] - X[k]) + b4 * (X4[k] - X[k])); for(int k = 0; k < 3; k++) DX[k] = X[k] - XINIT[k]; - if(data2){ + if(data2) { data3->NbSL++; - data3->SL.push_back(XPREV[0]); data3->SL.push_back(X[0]); - data3->SL.push_back(XPREV[1]); data3->SL.push_back(X[1]); - data3->SL.push_back(XPREV[2]); data3->SL.push_back(X[2]); + data3->SL.push_back(XPREV[0]); + data3->SL.push_back(X[0]); + data3->SL.push_back(XPREV[1]); + data3->SL.push_back(X[1]); + data3->SL.push_back(XPREV[2]); + data3->SL.push_back(X[2]); for(int k = 0; k < data2->getNumTimeSteps(); k++) data3->SL.push_back(val2[k]); o2->searchScalar(X[0], X[1], X[2], val2, -1); for(int k = 0; k < data2->getNumTimeSteps(); k++) data3->SL.push_back(val2[k]); } - else{ + else { data3->VP.push_back(DX[0]); data3->VP.push_back(DX[1]); data3->VP.push_back(DX[2]); @@ -309,11 +323,11 @@ PView *GMSH_StreamLinesPlugin::execute(PView *v) } } - if(data2){ - delete [] val2; + if(data2) { + delete[] val2; delete o2; } - else{ + else { v3->getOptions()->vectorType = PViewOptions::Displacement; } diff --git a/Plugin/StreamLines.h b/Plugin/StreamLines.h index 5ba9a5f6610ffb22d6b21ce2f0ae418516419018..3914ece895c1614c6ad67d02764debf020cd2289 100644 --- a/Plugin/StreamLines.h +++ b/Plugin/StreamLines.h @@ -8,17 +8,16 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterStreamLinesPlugin (); +extern "C" { +GMSH_Plugin *GMSH_RegisterStreamLinesPlugin(); } -class GMSH_StreamLinesPlugin : public GMSH_PostPlugin -{ +class GMSH_StreamLinesPlugin : public GMSH_PostPlugin { static double callback(int num, int action, double value, double *opt, double step, double min, double max); - public: - GMSH_StreamLinesPlugin(){} + +public: + GMSH_StreamLinesPlugin() {} std::string getName() const { return "StreamLines"; } std::string getShortHelp() const { diff --git a/Plugin/Summation.cpp b/Plugin/Summation.cpp index d3f7b0cbca45d7dd221d92d4ed89e1b57a5528e4..10dcef930097fba3791bc5fa3fb596e33f663652 100644 --- a/Plugin/Summation.cpp +++ b/Plugin/Summation.cpp @@ -11,39 +11,31 @@ #include <algorithm> StringXNumber SummationOptions_Number[] = { - {GMSH_FULLRC, "View 0", NULL, -1.}, - {GMSH_FULLRC, "View 1", NULL, -1.}, - {GMSH_FULLRC, "View 2", NULL, -1.}, - {GMSH_FULLRC, "View 3", NULL, -1.}, - {GMSH_FULLRC, "View 4", NULL, -1.}, - {GMSH_FULLRC, "View 5", NULL, -1.}, - {GMSH_FULLRC, "View 6", NULL, -1.}, - {GMSH_FULLRC, "View 7", NULL, -1.} -}; + {GMSH_FULLRC, "View 0", NULL, -1.}, {GMSH_FULLRC, "View 1", NULL, -1.}, + {GMSH_FULLRC, "View 2", NULL, -1.}, {GMSH_FULLRC, "View 3", NULL, -1.}, + {GMSH_FULLRC, "View 4", NULL, -1.}, {GMSH_FULLRC, "View 5", NULL, -1.}, + {GMSH_FULLRC, "View 6", NULL, -1.}, {GMSH_FULLRC, "View 7", NULL, -1.}}; StringXString SummationOptions_String[] = { - {GMSH_FULLRC, "Resuling View Name", NULL, "default"} -}; + {GMSH_FULLRC, "Resuling View Name", NULL, "default"}}; - -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterSummationPlugin() { - GMSH_Plugin *GMSH_RegisterSummationPlugin() - { - return new GMSH_SummationPlugin(); - } + return new GMSH_SummationPlugin(); +} } std::string GMSH_SummationPlugin::getHelp() const { return "Plugin(Summation) sums every time steps " - "of 'Reference View' and (every) 'Other View X'" - "and store the result in a new view.\n" - "If 'View 0' < 0 then the current view is selected.\n" - "If 'View 1...8' < 0 then this view is skipped.\n" - "Views can have diffrent number of time steps\n" - "Warning: the Plugin assume that every views share" - "the same mesh and that meshes do not move between time steps!"; + "of 'Reference View' and (every) 'Other View X'" + "and store the result in a new view.\n" + "If 'View 0' < 0 then the current view is selected.\n" + "If 'View 1...8' < 0 then this view is skipped.\n" + "Views can have diffrent number of time steps\n" + "Warning: the Plugin assume that every views share" + "the same mesh and that meshes do not move between time steps!"; } int GMSH_SummationPlugin::getNbOptions() const @@ -70,64 +62,60 @@ PView *GMSH_SummationPlugin::execute(PView *view) { int nviewmax = 8; std::vector<int> views_indices; - std::vector<PView*> pviews; - std::vector<PViewData*> pviewsdata; - - //Get view indices and PViews - for (int i =0; i < nviewmax; i++) - { - int iview = (int)SummationOptions_Number[i].def; - if(i == 0 || iview > -1) - { - views_indices.push_back(iview); - pviews.push_back(getView(iview, view)); - if(!pviews.back()){ - Msg::Error("Summation plugin could not find view %i", iview); - return view; - } - pviewsdata.push_back(getPossiblyAdaptiveData(pviews.back())); - if(pviewsdata.back()->hasMultipleMeshes()){ - Msg::Error("Summation plugin cannot be applied to multi-mesh views"); - return view; - } - } + std::vector<PView *> pviews; + std::vector<PViewData *> pviewsdata; + + // Get view indices and PViews + for(int i = 0; i < nviewmax; i++) { + int iview = (int)SummationOptions_Number[i].def; + if(i == 0 || iview > -1) { + views_indices.push_back(iview); + pviews.push_back(getView(iview, view)); + if(!pviews.back()) { + Msg::Error("Summation plugin could not find view %i", iview); + return view; + } + pviewsdata.push_back(getPossiblyAdaptiveData(pviews.back())); + if(pviewsdata.back()->hasMultipleMeshes()) { + Msg::Error("Summation plugin cannot be applied to multi-mesh views"); + return view; + } } - //Number of view to sum + } + // Number of view to sum int nviews = pviews.size(); - //Check if the views share the same mesh + // Check if the views share the same mesh //(at least same number of elements and entities) - //If a view has an empty timestep: skip it, no problem. - for (int j = 1; j<nviews; j++) - { - if( pviewsdata[j]->getNumEntities() == 0 && - pviewsdata[j]->getNumElements() == 0) - continue; // empty time step - if((pviewsdata[0]->getNumEntities() != pviewsdata[j]->getNumEntities()) || - (pviewsdata[0]->getNumElements() != pviewsdata[j]->getNumElements())){ - Msg::Error("Summation plugin: views based on different grid."); - } + // If a view has an empty timestep: skip it, no problem. + for(int j = 1; j < nviews; j++) { + if(pviewsdata[j]->getNumEntities() == 0 && + pviewsdata[j]->getNumElements() == 0) + continue; // empty time step + if((pviewsdata[0]->getNumEntities() != pviewsdata[j]->getNumEntities()) || + (pviewsdata[0]->getNumElements() != pviewsdata[j]->getNumElements())) { + Msg::Error("Summation plugin: views based on different grid."); } - //get min/max indices of time steps + } + // get min/max indices of time steps int timeBeg = pviewsdata[0]->getFirstNonEmptyTimeStep(); int timeEnd = pviewsdata[0]->getNumTimeSteps(); - int iref = 0; //reference view and time step to get mesh's info - int stepref=timeBeg; - for (int i = 1; i < nviews; i ++) - { - if (timeBeg > pviewsdata[i]->getFirstNonEmptyTimeStep()) - { - timeBeg = pviewsdata[i]->getFirstNonEmptyTimeStep(); - iref = i; - stepref = timeBeg; - } - timeEnd = std::max(timeEnd, pviewsdata[i]->getNumTimeSteps()); + int iref = 0; // reference view and time step to get mesh's info + int stepref = timeBeg; + for(int i = 1; i < nviews; i++) { + if(timeBeg > pviewsdata[i]->getFirstNonEmptyTimeStep()) { + timeBeg = pviewsdata[i]->getFirstNonEmptyTimeStep(); + iref = i; + stepref = timeBeg; } - //Init result + timeEnd = std::max(timeEnd, pviewsdata[i]->getNumTimeSteps()); + } + // Init result PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - - for(int ent = 0; ent < pviewsdata[iref]->getNumEntities(stepref); ent++){ - for(int ele = 0; ele < pviewsdata[iref]->getNumElements(stepref, ent); ele++){ + + for(int ent = 0; ent < pviewsdata[iref]->getNumEntities(stepref); ent++) { + for(int ele = 0; ele < pviewsdata[iref]->getNumElements(stepref, ent); + ele++) { // if(pviewsdata[0]->skipElement(timeBeg, ent, ele)) continue; int numNodes = pviewsdata[iref]->getNumNodes(stepref, ent, ele); int type = pviewsdata[iref]->getType(stepref, ent, ele); @@ -137,46 +125,42 @@ PView *GMSH_SummationPlugin::execute(PView *view) std::vector<double> v(std::max(9, numComp), 0.); std::vector<double> x(numNodes), y(numNodes), z(numNodes); for(int nod = 0; nod < numNodes; nod++) - pviewsdata[iref]->getNode(stepref, ent, ele, nod, x[nod], y[nod], z[nod]); + pviewsdata[iref]->getNode(stepref, ent, ele, nod, x[nod], y[nod], + z[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); - for(int step = timeBeg; step < timeEnd; step++){ - for(int nod = 0; nod < numNodes; nod++){ - for(int comp = 0; comp < numComp; comp++){ - v[comp]=0; - for(int iview = 0; iview < nviews; iview++) - { - if(!pviewsdata[iview]->hasTimeStep(step)) continue; - double d; - pviewsdata[iview]->getValue(step, ent, ele, nod, comp, d); - v[comp] +=d; - } - } - for(int i = 0; i < numComp2; i++) - out->push_back(v[i]); - } + for(int step = timeBeg; step < timeEnd; step++) { + for(int nod = 0; nod < numNodes; nod++) { + for(int comp = 0; comp < numComp; comp++) { + v[comp] = 0; + for(int iview = 0; iview < nviews; iview++) { + if(!pviewsdata[iview]->hasTimeStep(step)) continue; + double d; + pviewsdata[iview]->getValue(step, ent, ele, nod, comp, d); + v[comp] += d; + } + } + for(int i = 0; i < numComp2; i++) out->push_back(v[i]); + } } } } - //Set time - for (int step =timeBeg; step < timeEnd; step++) - { - int iview = 0; - for (iview =0; iview < nviews; iview ++) - { - if(!pviewsdata[iview]->hasTimeStep(step)) continue; - break; - } - data2->Time.push_back(pviewsdata[iview]->getTime(step)); + // Set time + for(int step = timeBeg; step < timeEnd; step++) { + int iview = 0; + for(iview = 0; iview < nviews; iview++) { + if(!pviewsdata[iview]->hasTimeStep(step)) continue; + break; } - + data2->Time.push_back(pviewsdata[iview]->getTime(step)); + } std::string outputname = SummationOptions_String[0].def; - if(outputname =="default") + if(outputname == "default") outputname = pviewsdata[0]->getName() + "_Summation"; - + data2->setName(outputname); data2->setFileName(outputname + "_Summation.pos"); data2->finalize(); diff --git a/Plugin/Summation.h b/Plugin/Summation.h index f73374e8d98bd4641a00b7368ff014ccb01825eb..fc2e0f0a49e6f29140b8f225546c6859ef0778f5 100644 --- a/Plugin/Summation.h +++ b/Plugin/Summation.h @@ -8,25 +8,24 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSummationPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterSummationPlugin(); } -class GMSH_SummationPlugin : public GMSH_PostPlugin -{ - public: - GMSH_SummationPlugin(){} +class GMSH_SummationPlugin : public GMSH_PostPlugin { +public: + GMSH_SummationPlugin() {} std::string getName() const { return "Summation"; } std::string getShortHelp() const { - return "Create a view by summing different views (TimeStep per TimeStep and Component by Component)"; + return "Create a view by summing different views (TimeStep per TimeStep " + "and Component by Component)"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; - StringXString* getOptionStr(int iopt); + StringXString *getOptionStr(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Tetrahedralize.cpp b/Plugin/Tetrahedralize.cpp index f32557f4c94833e4bc261076775abafd42c2d9dc..34f84a3dcd82a5b9b50b9061b43c2a10df081a87 100644 --- a/Plugin/Tetrahedralize.cpp +++ b/Plugin/Tetrahedralize.cpp @@ -14,23 +14,21 @@ #endif StringXNumber TetrahedralizeOptions_Number[] = { - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterTetrahedralizePlugin() { - GMSH_Plugin *GMSH_RegisterTetrahedralizePlugin() - { - return new GMSH_TetrahedralizePlugin(); - } + return new GMSH_TetrahedralizePlugin(); +} } std::string GMSH_TetrahedralizePlugin::getHelp() const { return "Plugin(Tetrahedralize) tetrahedralizes the points in " - "the view `View'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Tetrahedralize) creates one new view."; + "the view `View'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Tetrahedralize) creates one new view."; } int GMSH_TetrahedralizePlugin::getNbOptions() const @@ -46,10 +44,9 @@ StringXNumber *GMSH_TetrahedralizePlugin::getOption(int iopt) #if defined(HAVE_MESH) class PointData : public MVertex { - public: +public: std::vector<double> val; - PointData(double x, double y, double z, int numVal) - : MVertex(x, y, z) + PointData(double x, double y, double z, int numVal) : MVertex(x, y, z) { val.resize(numVal); } @@ -63,16 +60,16 @@ PView *GMSH_TetrahedralizePlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = v1->getData(); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("Tetrahedralize plugin cannot be applied to multi-mesh views"); return v1; } // create list of points with associated data - std::vector<MVertex*> points; + std::vector<MVertex *> points; int numSteps = data1->getNumTimeSteps(); - for(int ent = 0; ent < data1->getNumEntities(0); ent++){ - for(int ele = 0; ele < data1->getNumElements(0, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(0); ent++) { + for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) { if(data1->skipElement(0, ent, ele)) continue; if(data1->getNumNodes(0, ent, ele) != 1) continue; int numComp = data1->getNumComponents(0, ent, ele); @@ -81,50 +78,57 @@ PView *GMSH_TetrahedralizePlugin::execute(PView *v) PointData *p = new PointData(x, y, z, numComp * numSteps); for(int step = 0; step < numSteps; step++) for(int comp = 0; comp < numComp; comp++) - data1->getValue(step, ent, ele, 0, comp, p->val[numComp * step + comp]); + data1->getValue(step, ent, ele, 0, comp, + p->val[numComp * step + comp]); points.push_back(p); } } - if(points.size() < 4){ + if(points.size() < 4) { Msg::Error("Need at least 4 points to tetrahedralize"); for(unsigned int i = 0; i < points.size(); i++) delete points[i]; return v1; } - std::vector<MTetrahedron*> tets; + std::vector<MTetrahedron *> tets; delaunayMeshIn3D(points, tets); // create output PView *v2 = new PView(); PViewDataList *data2 = getDataList(v2); - for(unsigned int i = 0; i < tets.size(); i++){ + for(unsigned int i = 0; i < tets.size(); i++) { PointData *p[4]; - p[0] = (PointData*)tets[i]->getVertex(0); - p[1] = (PointData*)tets[i]->getVertex(1); - p[2] = (PointData*)tets[i]->getVertex(2); - p[3] = (PointData*)tets[i]->getVertex(3); + p[0] = (PointData *)tets[i]->getVertex(0); + p[1] = (PointData *)tets[i]->getVertex(1); + p[2] = (PointData *)tets[i]->getVertex(2); + p[3] = (PointData *)tets[i]->getVertex(3); int numComp = 0; std::vector<double> *vec = 0; if((int)p[0]->val.size() == 9 * numSteps && (int)p[1]->val.size() == 9 * numSteps && (int)p[2]->val.size() == 9 * numSteps && - (int)p[3]->val.size() == 9 * numSteps){ - numComp = 9; data2->NbTS++; vec = &data2->TS; + (int)p[3]->val.size() == 9 * numSteps) { + numComp = 9; + data2->NbTS++; + vec = &data2->TS; } else if((int)p[0]->val.size() == 3 * numSteps && (int)p[1]->val.size() == 3 * numSteps && (int)p[2]->val.size() == 3 * numSteps && - (int)p[3]->val.size() == 3 * numSteps){ - numComp = 3; data2->NbVS++; vec = &data2->VS; + (int)p[3]->val.size() == 3 * numSteps) { + numComp = 3; + data2->NbVS++; + vec = &data2->VS; } else if((int)p[0]->val.size() == numSteps && (int)p[1]->val.size() == numSteps && (int)p[2]->val.size() == numSteps && - (int)p[3]->val.size() == numSteps){ - numComp = 1; data2->NbSS++; vec = &data2->SS; + (int)p[3]->val.size() == numSteps) { + numComp = 1; + data2->NbSS++; + vec = &data2->SS; } - else{ + else { Msg::Warning("Bad data in tetrahedralization"); continue; } diff --git a/Plugin/Tetrahedralize.h b/Plugin/Tetrahedralize.h index d0ee318a775144e2221afb7587e89483e63db28f..4663ad03698d29b2f14dc412d6a4e7c49863279e 100644 --- a/Plugin/Tetrahedralize.h +++ b/Plugin/Tetrahedralize.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterTetrahedralizePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterTetrahedralizePlugin(); } -class GMSH_TetrahedralizePlugin : public GMSH_PostPlugin -{ - public: - GMSH_TetrahedralizePlugin(){} +class GMSH_TetrahedralizePlugin : public GMSH_PostPlugin { +public: + GMSH_TetrahedralizePlugin() {} std::string getName() const { return "Tetrahedralize"; } - std::string getShortHelp() const - { - return "Mesh 3D point cloud"; - } + std::string getShortHelp() const { return "Mesh 3D point cloud"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/ThinLayerFixMesh.cpp b/Plugin/ThinLayerFixMesh.cpp index f828d982f8c229ea934cf6b86f02ca395913feae..db4518ab690f025bbd3fe709282610b076884a36 100644 --- a/Plugin/ThinLayerFixMesh.cpp +++ b/Plugin/ThinLayerFixMesh.cpp @@ -13,12 +13,11 @@ #include "meshGFaceDelaunayInsertion.h" #endif -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterThinLayerFixMeshPlugin() { - GMSH_Plugin *GMSH_RegisterThinLayerFixMeshPlugin() - { - return new GMSH_ThinLayerFixMeshPlugin(); - } + return new GMSH_ThinLayerFixMeshPlugin(); +} } std::string GMSH_ThinLayerFixMeshPlugin::getHelp() const @@ -26,16 +25,9 @@ std::string GMSH_ThinLayerFixMeshPlugin::getHelp() const return "Fix the mesh in thin parts"; } -int GMSH_ThinLayerFixMeshPlugin::getNbOptions() const -{ - return 0; -} - -StringXNumber *GMSH_ThinLayerFixMeshPlugin::getOption(int iopt) -{ - return 0; -} +int GMSH_ThinLayerFixMeshPlugin::getNbOptions() const { return 0; } +StringXNumber *GMSH_ThinLayerFixMeshPlugin::getOption(int iopt) { return 0; } #if defined(HAVE_MESH) @@ -43,7 +35,8 @@ const double GMSH_ThinLayerFixMeshPlugin::epsilon = 0.00000000001; const double GMSH_ThinLayerFixMeshPlugin::angleMax = 0.9; const double GMSH_ThinLayerFixMeshPlugin::distP2PMax = 5.0; -CorrespVerticesFixMesh::CorrespVerticesFixMesh(){ +CorrespVerticesFixMesh::CorrespVerticesFixMesh() +{ // std::cout<<"started init CorrespVerticesFixMesh"<<std::endl; // this->EndTriangle = faceXtetFM(); // this->StartPoint = 0; @@ -58,92 +51,66 @@ CorrespVerticesFixMesh::CorrespVerticesFixMesh(){ // this->tagMaster = 0; // std::cout<<"completed init CorrespVerticesFixMesh"<<std::endl; } -CorrespVerticesFixMesh::~CorrespVerticesFixMesh(){} -void CorrespVerticesFixMesh::setStartPoint(MVertex* v){ - this->StartPoint = v; -} -void CorrespVerticesFixMesh::setEndPoint(SPoint3 p){ - this->EndPoint = p; -} -void CorrespVerticesFixMesh::setStartNormal(SVector3 v){ +CorrespVerticesFixMesh::~CorrespVerticesFixMesh() {} +void CorrespVerticesFixMesh::setStartPoint(MVertex *v) { this->StartPoint = v; } +void CorrespVerticesFixMesh::setEndPoint(SPoint3 p) { this->EndPoint = p; } +void CorrespVerticesFixMesh::setStartNormal(SVector3 v) +{ this->StartNormal = v; } -void CorrespVerticesFixMesh::setEndNormal(SVector3 v){ - this->EndNormal = v; -} -//void CorrespVerticesFixMesh::setEndTriangle(faceXtetFM f){ +void CorrespVerticesFixMesh::setEndNormal(SVector3 v) { this->EndNormal = v; } +// void CorrespVerticesFixMesh::setEndTriangle(faceXtetFM f){ // this->EndTriangle(f.t1,f.i1); //} -void CorrespVerticesFixMesh::setEndTrianglePoint1(MVertex* v){ +void CorrespVerticesFixMesh::setEndTrianglePoint1(MVertex *v) +{ this->EndTrianglePoint1 = v; } -void CorrespVerticesFixMesh::setEndTrianglePoint2(MVertex* v){ +void CorrespVerticesFixMesh::setEndTrianglePoint2(MVertex *v) +{ this->EndTrianglePoint2 = v; } -void CorrespVerticesFixMesh::setEndTrianglePoint3(MVertex* v){ +void CorrespVerticesFixMesh::setEndTrianglePoint3(MVertex *v) +{ this->EndTrianglePoint3 = v; } -void CorrespVerticesFixMesh::setdistP2P(double d){ - this->distP2P = d; -} -void CorrespVerticesFixMesh::setangleProd(double a){ - this->angleProd = a; -} -void CorrespVerticesFixMesh::setActive(bool b){ - this->Active = b; -} -void CorrespVerticesFixMesh::setEndTriangleActive(bool b){ +void CorrespVerticesFixMesh::setdistP2P(double d) { this->distP2P = d; } +void CorrespVerticesFixMesh::setangleProd(double a) { this->angleProd = a; } +void CorrespVerticesFixMesh::setActive(bool b) { this->Active = b; } +void CorrespVerticesFixMesh::setEndTriangleActive(bool b) +{ this->EndTriangleActive = b; } -void CorrespVerticesFixMesh::setIsMaster(bool b){ - this->IsMaster = b; -} -void CorrespVerticesFixMesh::setTagMaster(int i){ - this->tagMaster = i; -} -MVertex* CorrespVerticesFixMesh::getStartPoint(){ - return StartPoint; -} -SPoint3 CorrespVerticesFixMesh::getEndPoint(){ - return EndPoint; -} -SVector3 CorrespVerticesFixMesh::getStartNormal(){ - return StartNormal; -} -SVector3 CorrespVerticesFixMesh::getEndNormal(){ - return EndNormal; -} -//faceXtetFM CorrespVerticesFixMesh::getEndTriangle(){ +void CorrespVerticesFixMesh::setIsMaster(bool b) { this->IsMaster = b; } +void CorrespVerticesFixMesh::setTagMaster(int i) { this->tagMaster = i; } +MVertex *CorrespVerticesFixMesh::getStartPoint() { return StartPoint; } +SPoint3 CorrespVerticesFixMesh::getEndPoint() { return EndPoint; } +SVector3 CorrespVerticesFixMesh::getStartNormal() { return StartNormal; } +SVector3 CorrespVerticesFixMesh::getEndNormal() { return EndNormal; } +// faceXtetFM CorrespVerticesFixMesh::getEndTriangle(){ // return EndTriangle; //} -MVertex* CorrespVerticesFixMesh::getEndTrianglePoint1(){ +MVertex *CorrespVerticesFixMesh::getEndTrianglePoint1() +{ return EndTrianglePoint1; } -MVertex* CorrespVerticesFixMesh::getEndTrianglePoint2(){ +MVertex *CorrespVerticesFixMesh::getEndTrianglePoint2() +{ return EndTrianglePoint2; } -MVertex* CorrespVerticesFixMesh::getEndTrianglePoint3(){ +MVertex *CorrespVerticesFixMesh::getEndTrianglePoint3() +{ return EndTrianglePoint3; } -double CorrespVerticesFixMesh::getdistP2P(){ - return distP2P; -} -double CorrespVerticesFixMesh::getangleProd(){ - return angleProd; -} -bool CorrespVerticesFixMesh::getActive(){ - return Active; -} -bool CorrespVerticesFixMesh::getEndTriangleActive(){ +double CorrespVerticesFixMesh::getdistP2P() { return distP2P; } +double CorrespVerticesFixMesh::getangleProd() { return angleProd; } +bool CorrespVerticesFixMesh::getActive() { return Active; } +bool CorrespVerticesFixMesh::getEndTriangleActive() +{ return EndTriangleActive; } -bool CorrespVerticesFixMesh::getIsMaster(){ - return IsMaster; -} -int CorrespVerticesFixMesh::getTagMaster(){ - return tagMaster; -} - +bool CorrespVerticesFixMesh::getIsMaster() { return IsMaster; } +int CorrespVerticesFixMesh::getTagMaster() { return tagMaster; } PView *GMSH_ThinLayerFixMeshPlugin::execute(PView *view) { @@ -158,62 +125,88 @@ PView *GMSH_ThinLayerFixMeshPlugin::execute(PView *view) return view; } -void GMSH_ThinLayerFixMeshPlugin::perform(){ +void GMSH_ThinLayerFixMeshPlugin::perform() +{ VertexToTets.clear(); TetToTet4.clear(); VertexToCorresp.clear(); vecOfThinSheets.clear(); GMSH_ThinLayerFixMeshPlugin::fillVertexToTets(); GMSH_ThinLayerFixMeshPlugin::fillTetToTet4(); - //std::cout<<"computeAllDistToOppSide"<<std::endl; - std::map<MVertex*,double> AllDist = GMSH_ThinLayerFixMeshPlugin::computeAllDistToOppSide(); - for (std::map<MVertex*,double>::iterator allDistIt = AllDist.begin();allDistIt != AllDist.end();allDistIt++){ - //std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl; - //std::cout<<" Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl; - // //std::cout<<" Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl; - //std::cout<<" Testing StartPoint "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getStartPoint()->getNum()<<std::endl; - //std::cout<<" Testing StartNormal "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getStartNormal().norm()<<std::endl; + // std::cout<<"computeAllDistToOppSide"<<std::endl; + std::map<MVertex *, double> AllDist = + GMSH_ThinLayerFixMeshPlugin::computeAllDistToOppSide(); + for(std::map<MVertex *, double>::iterator allDistIt = AllDist.begin(); + allDistIt != AllDist.end(); allDistIt++) { + // std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos + // "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; + // "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl; + // std::cout<<" Size of vertexToCorresp + // "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl; + // //std::cout<<" Testing FaceXTet out of while fourth time + //"<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() + //- 1]->getEndTriangle().t1->tet()->getNum()<<std::endl; std::cout<<" + // Testing StartPoint + // "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() + // - 1]->getStartPoint()->getNum()<<std::endl; std::cout<<" Testing + // StartNormal + // "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() + // - 1]->getStartNormal().norm()<<std::endl; } - //std::cout<<"checkOppositeTriangles !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl; + // std::cout<<"checkOppositeTriangles + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl; GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles(); - //std::cout<<"fillvecOfThinSheets !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl; + // std::cout<<"fillvecOfThinSheets + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl; GMSH_ThinLayerFixMeshPlugin::fillvecOfThinSheets(); - //std::cout<<"Out of fillvecOfThinSheets"<<std::endl; + // std::cout<<"Out of fillvecOfThinSheets"<<std::endl; // std::set<MVertex*> constr_vertices; - for (unsigned int i = 0;i < vecOfThinSheets.size();i++){ - if (vecOfThinSheets[i].size() > 1){ - GFace* OnSurf; - for (unsigned int j = 0;j < vecOfThinSheets[i].size();j++){ - //find a point on the surface - MVertex* vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint1(); - if (vertOnSurf->onWhat()->dim() < 2){ + for(unsigned int i = 0; i < vecOfThinSheets.size(); i++) { + if(vecOfThinSheets[i].size() > 1) { + GFace *OnSurf; + for(unsigned int j = 0; j < vecOfThinSheets[i].size(); j++) { + // find a point on the surface + MVertex *vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint1(); + if(vertOnSurf->onWhat()->dim() < 2) { vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint2(); } - if (vertOnSurf->onWhat()->dim() < 2){ + if(vertOnSurf->onWhat()->dim() < 2) { vertOnSurf = vecOfThinSheets[i][j]->getEndTrianglePoint3(); } - OnSurf = dynamic_cast<GFace*>(vertOnSurf->onWhat()); - SPoint2 ParOnSurf = OnSurf->parFromPoint(vecOfThinSheets[i][j]->getEndPoint(),1); - MVertex* StartPo = vecOfThinSheets[i][j]->getStartPoint(); + OnSurf = dynamic_cast<GFace *>(vertOnSurf->onWhat()); + SPoint2 ParOnSurf = + OnSurf->parFromPoint(vecOfThinSheets[i][j]->getEndPoint(), 1); + MVertex *StartPo = vecOfThinSheets[i][j]->getStartPoint(); double param1 = 0.0; double param2 = 0.0; - StartPo->getParameter(0,param1); - StartPo->getParameter(1,param2); - //std::cout<<" PointBegin is "<<StartPo->x()<<" ; "<<StartPo->y()<<" ; "<<StartPo->z()<<" with param "<<param1<<" ; "<<param2<<std::endl; - //std::cout<<"insertion of point "<<vecOfThinSheets[i][j]->getEndPoint().x()<<" ; "<<vecOfThinSheets[i][j]->getEndPoint().y()<<" ; "<<vecOfThinSheets[i][j]->getEndPoint().z()<<" with param "<<ParOnSurf.x()<<" ; "<<ParOnSurf.y()<<std::endl; - MFaceVertex *v = new MFaceVertex(vecOfThinSheets[i][j]->getEndPoint().x(),vecOfThinSheets[i][j]->getEndPoint().y(),vecOfThinSheets[i][j]->getEndPoint().z(),OnSurf,ParOnSurf.x(),ParOnSurf.y()); + StartPo->getParameter(0, param1); + StartPo->getParameter(1, param2); + // std::cout<<" PointBegin is "<<StartPo->x()<<" ; "<<StartPo->y()<<" ; + // "<<StartPo->z()<<" with param "<<param1<<" ; "<<param2<<std::endl; + // std::cout<<"insertion of point + // "<<vecOfThinSheets[i][j]->getEndPoint().x()<<" ; + // "<<vecOfThinSheets[i][j]->getEndPoint().y()<<" ; + // "<<vecOfThinSheets[i][j]->getEndPoint().z()<<" with param + // "<<ParOnSurf.x()<<" ; "<<ParOnSurf.y()<<std::endl; + MFaceVertex *v = + new MFaceVertex(vecOfThinSheets[i][j]->getEndPoint().x(), + vecOfThinSheets[i][j]->getEndPoint().y(), + vecOfThinSheets[i][j]->getEndPoint().z(), OnSurf, + ParOnSurf.x(), ParOnSurf.y()); OnSurf->setMeshingAlgo(ALGO_2D_PACK_PRLGRMS_CSTR); OnSurf->constr_vertices.insert(v); // OnSurf->addMeshVertex(v); // constr_vertices.insert(v); - //std::cout<<"inserted point with tag "<<v->getNum()<<" on surface "<<OnSurf->tag()<<std::endl; + // std::cout<<"inserted point with tag "<<v->getNum()<<" on surface + // "<<OnSurf->tag()<<std::endl; } // OnSurf->setMeshingAlgo(ALGO_2D_PACK_PRLGRMS_CSTR); // OnSurf->GFace::deleteMesh(); // buildBackGroundMesh (OnSurf); // meshGFace::modifyInitialMeshForTakingIntoAccountBoundaryLayers(OnSurf); // OnSurf->meshStatistics.status = GFace::PENDING; - // OnSurf->meshStatistics.nbTriangle = OnSurf->meshStatistics.nbEdge = 0; + // OnSurf->meshStatistics.nbTriangle = + //OnSurf->meshStatistics.nbEdge = 0; // OnSurf->correspondingVertices.clear(); // std::map<MVertex* , MVertex*>* equivalence; // std::map<MVertex*, SPoint2> * parametricCoordinates; @@ -221,96 +214,118 @@ void GMSH_ThinLayerFixMeshPlugin::perform(){ } // constr_vertices.clear(); } - for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){ - std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second; - for (unsigned int i = 0;i < vecCorr.size();i++){ + for(std::map<MVertex *, std::vector<CorrespVerticesFixMesh *> >::iterator + it1 = VertexToCorresp.begin(); + it1 != VertexToCorresp.end(); it1++) { + std::vector<CorrespVerticesFixMesh *> vecCorr = (*it1).second; + for(unsigned int i = 0; i < vecCorr.size(); i++) { delete vecCorr[i]; } } } -void GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles(){ - //all endTriangle will be set to active or not - for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){ +void GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles() +{ + // all endTriangle will be set to active or not + for(std::map<MVertex *, std::vector<CorrespVerticesFixMesh *> >::iterator + it1 = VertexToCorresp.begin(); + it1 != VertexToCorresp.end(); it1++) { // std::cout<<" Entering For"<<std::endl; // MVertex* vertTmp = (*it1).first; - //std::cout<<" Vert Tested is "<<vertTmp->getNum()<<" and its vector size is "<<(*it1).second.size()<<" pos "<<vertTmp->x()<<" ; "<<vertTmp->y()<<" ; "<<vertTmp->z()<<std::endl; - std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second; - for (unsigned int i = 0;i < vecCorr.size();i++){ - //std::cout<<" Entering deeper For"<<std::endl; - CorrespVerticesFixMesh* currentCorr = vecCorr[i]; + // std::cout<<" Vert Tested is "<<vertTmp->getNum()<<" and its vector size + // is "<<(*it1).second.size()<<" pos "<<vertTmp->x()<<" ; "<<vertTmp->y()<<" + // ; "<<vertTmp->z()<<std::endl; + std::vector<CorrespVerticesFixMesh *> vecCorr = (*it1).second; + for(unsigned int i = 0; i < vecCorr.size(); i++) { + // std::cout<<" Entering deeper For"<<std::endl; + CorrespVerticesFixMesh *currentCorr = vecCorr[i]; // std::cout<<" Step 1"<<std::endl; - // faceXtetFM currentEndTri = (*(currentCorr->getEndTriangle())); - // std::cout<<" Step 2"<<std::endl; - MVertex* endP0 = currentCorr->getEndTrianglePoint1(); + // faceXtetFM currentEndTri = + //(*(currentCorr->getEndTriangle())); std::cout<<" Step + //2"<<std::endl; + MVertex *endP0 = currentCorr->getEndTrianglePoint1(); // std::cout<<" Step 3"<<std::endl; - MVertex* endP1 = currentCorr->getEndTrianglePoint2(); + MVertex *endP1 = currentCorr->getEndTrianglePoint2(); // std::cout<<" Step 4"<<std::endl; - MVertex* endP2 = currentCorr->getEndTrianglePoint3(); + MVertex *endP2 = currentCorr->getEndTrianglePoint3(); // std::cout<<" Step 5"<<std::endl; - std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(endP0); + std::map<MVertex *, std::vector<CorrespVerticesFixMesh *> >::iterator + it2 = VertexToCorresp.find(endP0); // std::cout<<" Step 6 ?"<<std::endl; - // std::cout<<" Tet is "<<currentCorr->getEndTriangle().t1->tet()->getNum()<<std::endl; - // std::cout<<" Face number is "<<currentCorr->getEndTriangle().i1<<std::endl; - // std::cout<<" Tet is made of vertex 0 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(0)->getNum()<<std::endl; - // std::cout<<" Tet is made of vertex 1 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(1)->getNum()<<std::endl; - // std::cout<<" Tet is made of vertex 2 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(2)->getNum()<<std::endl; - // std::cout<<" Tet is made of vertex 3 "<<currentCorr->getEndTriangle().t1->tet()->getVertex(3)->getNum()<<std::endl; - // std::cout<<" Adresses of endP0 "<<endP0<<" and endP1 "<<endP1<<" and endP2 "<<endP2<<std::endl; - //std::cout<<" endP0 is "<<endP0->getNum()<<" pos "<<endP0->x()<<" ; "<<endP0->y()<<" ; "<<endP0->z()<<std::endl; - // std::cout<<" Step 6"<<std::endl; - std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find(endP1); - //std::cout<<" endP1 is "<<endP1->getNum()<<" pos "<<endP1->x()<<" ; "<<endP1->y()<<" ; "<<endP1->z()<<std::endl; - // std::cout<<" Step 7"<<std::endl; - std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it4 = VertexToCorresp.find(endP2); - //std::cout<<" endP2 is "<<endP2->getNum()<<" pos "<<endP2->x()<<" ; "<<endP2->y()<<" ; "<<endP2->z()<<std::endl; - // std::cout<<" Step 8"<<std::endl; + // std::cout<<" Tet is + //"<<currentCorr->getEndTriangle().t1->tet()->getNum()<<std::endl; + // std::cout<<" Face number is + //"<<currentCorr->getEndTriangle().i1<<std::endl; std::cout<<" + //Tet is made of vertex 0 + //"<<currentCorr->getEndTriangle().t1->tet()->getVertex(0)->getNum()<<std::endl; + // std::cout<<" Tet is made of vertex 1 + //"<<currentCorr->getEndTriangle().t1->tet()->getVertex(1)->getNum()<<std::endl; + // std::cout<<" Tet is made of vertex 2 + //"<<currentCorr->getEndTriangle().t1->tet()->getVertex(2)->getNum()<<std::endl; + // std::cout<<" Tet is made of vertex 3 + //"<<currentCorr->getEndTriangle().t1->tet()->getVertex(3)->getNum()<<std::endl; + // std::cout<<" Adresses of endP0 "<<endP0<<" and endP1 + //"<<endP1<<" and endP2 "<<endP2<<std::endl; std::cout<<" endP0 is + // "<<endP0->getNum()<<" pos "<<endP0->x()<<" ; "<<endP0->y()<<" ; + // "<<endP0->z()<<std::endl; std::cout<<" Step + //6"<<std::endl; + std::map<MVertex *, std::vector<CorrespVerticesFixMesh *> >::iterator + it3 = VertexToCorresp.find(endP1); + // std::cout<<" endP1 is "<<endP1->getNum()<<" pos "<<endP1->x()<<" ; + // "<<endP1->y()<<" ; "<<endP1->z()<<std::endl; std::cout<<" + //Step 7"<<std::endl; + std::map<MVertex *, std::vector<CorrespVerticesFixMesh *> >::iterator + it4 = VertexToCorresp.find(endP2); + // std::cout<<" endP2 is "<<endP2->getNum()<<" pos "<<endP2->x()<<" ; + // "<<endP2->y()<<" ; "<<endP2->z()<<std::endl; std::cout<<" + //Step 8"<<std::endl; (*it1).second[i]->setEndTriangleActive(false); - //std::cout<<" Starting tests"<<std::endl; + // std::cout<<" Starting tests"<<std::endl; bool test0 = false; bool test1 = false; bool test2 = false; - if (endP0->onWhat()->dim() < 2){ + if(endP0->onWhat()->dim() < 2) { test0 = true; - //std::cout<<" test0 true by dim"<<std::endl; + // std::cout<<" test0 true by dim"<<std::endl; } - if (endP1->onWhat()->dim() < 2){ + if(endP1->onWhat()->dim() < 2) { test1 = true; - //std::cout<<" test1 true by dim"<<std::endl; + // std::cout<<" test1 true by dim"<<std::endl; } - if (endP2->onWhat()->dim() < 2){ + if(endP2->onWhat()->dim() < 2) { test2 = true; - //std::cout<<" test2 true by dim"<<std::endl; + // std::cout<<" test2 true by dim"<<std::endl; } - if (it2 != VertexToCorresp.end()){ - if ((*it2).second.size() > 0){ - if ((*it2).second[0]->getActive()){ + if(it2 != VertexToCorresp.end()) { + if((*it2).second.size() > 0) { + if((*it2).second[0]->getActive()) { test0 = true; - //std::cout<<" test0 true by active"<<std::endl; + // std::cout<<" test0 true by active"<<std::endl; } } } - if (it3 != VertexToCorresp.end()){ - if ((*it3).second.size() > 0){ - if ((*it3).second[0]->getActive()){ + if(it3 != VertexToCorresp.end()) { + if((*it3).second.size() > 0) { + if((*it3).second[0]->getActive()) { test1 = true; - //std::cout<<" test1 true by active"<<std::endl; + // std::cout<<" test1 true by active"<<std::endl; } } } - if (it4 != VertexToCorresp.end()){ - if ((*it4).second.size() > 0){ - if ((*it4).second[0]->getActive()){ + if(it4 != VertexToCorresp.end()) { + if((*it4).second.size() > 0) { + if((*it4).second[0]->getActive()) { test2 = true; - //std::cout<<" test2 true by active"<<std::endl; + // std::cout<<" test2 true by active"<<std::endl; } } } - if (test0){ - if (test1){ - if (test2){ + if(test0) { + if(test1) { + if(test2) { (*it1).second[i]->setEndTriangleActive(true); - //std::cout<<" EndTriangle Activated"<<std::endl; + // std::cout<<" EndTriangle + // Activated"<<std::endl; } } } @@ -319,19 +334,30 @@ void GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles(){ // if (it3 != VertexToCorresp.end()){ //// std::cout<<" Passed Number 2"<<std::endl; // if (it4 != VertexToCorresp.end()){ - //// std::cout<<" Passed Number 3"<<std::endl; - // if (((*it2).second.size() > 0) || (endP0->onWhat()->dim() < 2)){ - // std::cout<<" Passed Number 1 Bis"<<std::endl; - // if (((*it3).second.size() > 0) || (endP1->onWhat()->dim() < 2)){ - // std::cout<<" Passed Number 2 Bis"<<std::endl; - // if (((*it4).second.size() > 0) || (endP2->onWhat()->dim() < 2)){ - // std::cout<<" Passed Number 3 Bis"<<std::endl; - // if (((*it2).second[0]->getActive()) || (endP0->onWhat()->dim() < 2)){ - // std::cout<<" Passed Number 4"<<std::endl; - // if (((*it3).second[0]->getActive()) || (endP1->onWhat()->dim() < 2)){ - // std::cout<<" Passed Number 5"<<std::endl; - // if (((*it4).second[0]->getActive()) || (endP2->onWhat()->dim() < 2)){ - // std::cout<<" Passed Number 6"<<std::endl; + //// std::cout<<" Passed Number + ///3"<<std::endl; + // if (((*it2).second.size() > 0) || + //(endP0->onWhat()->dim() < 2)){ + // std::cout<<" Passed Number 1 + //Bis"<<std::endl; + // if (((*it3).second.size() > 0) || + //(endP1->onWhat()->dim() < 2)){ + // std::cout<<" Passed Number 2 + //Bis"<<std::endl; + // if (((*it4).second.size() > 0) || + //(endP2->onWhat()->dim() < 2)){ + // std::cout<<" Passed + //Number 3 Bis"<<std::endl; if + //(((*it2).second[0]->getActive()) || (endP0->onWhat()->dim() < 2)){ + // std::cout<<" + //Passed Number 4"<<std::endl; if + //(((*it3).second[0]->getActive()) || (endP1->onWhat()->dim() < 2)){ + // std::cout<<" + //Passed Number 5"<<std::endl; + // if + //(((*it4).second[0]->getActive()) || (endP2->onWhat()->dim() < 2)){ + // std::cout<<" + //Passed Number 6"<<std::endl; // (*it1).second[i]->setEndTriangleActive(true); // } // } @@ -342,7 +368,7 @@ void GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles(){ // } // } // } - //std::cout<<" Exiting out of deeper For"<<std::endl; + // std::cout<<" Exiting out of deeper For"<<std::endl; } // std::cout<<" Getting Out Of For"<<std::endl; } @@ -350,123 +376,224 @@ void GMSH_ThinLayerFixMeshPlugin::checkOppositeTriangles(){ void GMSH_ThinLayerFixMeshPlugin::fillvecOfThinSheets() { - for (std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it1 = VertexToCorresp.begin();it1 != VertexToCorresp.end();it1++){ + for(std::map<MVertex *, std::vector<CorrespVerticesFixMesh *> >::iterator + it1 = VertexToCorresp.begin(); + it1 != VertexToCorresp.end(); it1++) { // MVertex* vertTmp = (*it1).first; - std::vector<CorrespVerticesFixMesh*> vecCorr = (*it1).second; - for (unsigned int i = 0;i < vecCorr.size();i++){ - CorrespVerticesFixMesh* currentCorr = vecCorr[i]; - //std::cout<<"going to test vecCorr["<<i<<"]"<<" vertex "<<currentCorr->getStartPoint()->getNum()<<" and pos "<<currentCorr->getStartPoint()->x()<<" ; "<<currentCorr->getStartPoint()->y()<<" ; "<<currentCorr->getStartPoint()->z()<<std::endl; - if (currentCorr->getStartPoint()->onWhat()->dim() == 2) - //std::cout<<"On a surface ; "; - if (currentCorr->getActive()) - //std::cout<<"Is active ; "; - if (currentCorr->getEndTriangleActive()) - //std::cout<<"End Triangle active ; "; - if (currentCorr->getTagMaster() == (-2)) - //std::cout<<"Has yet to be used ; "; - //std::cout<<std::endl; - if ((currentCorr->getStartPoint()->onWhat()->dim() == 2) && (currentCorr->getActive()) && (currentCorr->getEndTriangleActive()) && (currentCorr->getTagMaster() == (-2))){ - //Found the first node of a new master sheet - //std::cout<<"entering a new master sheet !"<<std::endl; - std::vector<CorrespVerticesFixMesh*> MasterSheet; + std::vector<CorrespVerticesFixMesh *> vecCorr = (*it1).second; + for(unsigned int i = 0; i < vecCorr.size(); i++) { + CorrespVerticesFixMesh *currentCorr = vecCorr[i]; + // std::cout<<"going to test vecCorr["<<i<<"]"<<" vertex + // "<<currentCorr->getStartPoint()->getNum()<<" and pos + // "<<currentCorr->getStartPoint()->x()<<" ; + // "<<currentCorr->getStartPoint()->y()<<" ; + // "<<currentCorr->getStartPoint()->z()<<std::endl; + if(currentCorr->getStartPoint()->onWhat()->dim() == 2) + // std::cout<<"On a surface ; "; + if(currentCorr->getActive()) + // std::cout<<"Is active ; "; + if(currentCorr->getEndTriangleActive()) + // std::cout<<"End Triangle active ; "; + if(currentCorr->getTagMaster() == (-2)) + // std::cout<<"Has yet to be used ; "; + // std::cout<<std::endl; + if((currentCorr->getStartPoint()->onWhat()->dim() == 2) && + (currentCorr->getActive()) && + (currentCorr->getEndTriangleActive()) && + (currentCorr->getTagMaster() == (-2))) { + // Found the first node of a new master sheet + // std::cout<<"entering a new master sheet !"<<std::endl; + std::vector<CorrespVerticesFixMesh *> MasterSheet; MasterSheet.clear(); (*it1).second[i]->setTagMaster(-1); - // faceXtetFM faceEndSlave = (*((*it1).second[i]->getEndTriangle())); - // faceXtetFM faceEndSlave = ((*it1).second[i]->getEndTriangle()); + // faceXtetFM faceEndSlave = + //(*((*it1).second[i]->getEndTriangle())); + // faceXtetFM faceEndSlave = + //((*it1).second[i]->getEndTriangle()); { - std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint1()); - if (it2 != VertexToCorresp.end()){ - if ((*it2).second.size() > 0){ - if ((*it1).second[i]->getEndTrianglePoint1()->onWhat()->dim() == 2){ - (*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag()); + std::map<MVertex *, + std::vector<CorrespVerticesFixMesh *> >::iterator + it2 = VertexToCorresp.find( + (*it1).second[i]->getEndTrianglePoint1()); + if(it2 != VertexToCorresp.end()) { + if((*it2).second.size() > 0) { + if((*it1) + .second[i] + ->getEndTrianglePoint1() + ->onWhat() + ->dim() == 2) { + (*it2).second[0]->setTagMaster( + (*it1).second[i]->getStartPoint()->onWhat()->tag()); } } } - it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint2()); - if (it2 != VertexToCorresp.end()){ - if ((*it2).second.size() > 0){ - if ((*it1).second[i]->getEndTrianglePoint2()->onWhat()->dim() == 2){ - (*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag()); + it2 = VertexToCorresp.find( + (*it1).second[i]->getEndTrianglePoint2()); + if(it2 != VertexToCorresp.end()) { + if((*it2).second.size() > 0) { + if((*it1) + .second[i] + ->getEndTrianglePoint2() + ->onWhat() + ->dim() == 2) { + (*it2).second[0]->setTagMaster( + (*it1).second[i]->getStartPoint()->onWhat()->tag()); } } } - it2 = VertexToCorresp.find((*it1).second[i]->getEndTrianglePoint3()); - if (it2 != VertexToCorresp.end()){ - if ((*it2).second.size() > 0){ - if ((*it1).second[i]->getEndTrianglePoint3()->onWhat()->dim() == 2){ - (*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag()); + it2 = VertexToCorresp.find( + (*it1).second[i]->getEndTrianglePoint3()); + if(it2 != VertexToCorresp.end()) { + if((*it2).second.size() > 0) { + if((*it1) + .second[i] + ->getEndTrianglePoint3() + ->onWhat() + ->dim() == 2) { + (*it2).second[0]->setTagMaster( + (*it1).second[i]->getStartPoint()->onWhat()->tag()); } } } } // for (unsigned int j = 0;j < 3;j++){ - // std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(faceEndSlave.v[j]); + // std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> + //>::iterator it2 = VertexToCorresp.find(faceEndSlave.v[j]); // if (it2 != VertexToCorresp.end()){ - // if (faceEndSlave.v[j]->onWhat()->dim() == 2){ + // if (faceEndSlave.v[j]->onWhat()->dim() == + //2){ // (*it2).second[0]->setTagMaster((*it1).second[i]->getStartPoint()->onWhat()->tag()); // } // } // } MasterSheet.push_back((*it1).second[i]); - std::set<MVertex*> CurrentSheet; + std::set<MVertex *> CurrentSheet; CurrentSheet.clear(); CurrentSheet.insert((*it1).second[i]->getStartPoint()); - while (CurrentSheet.size() != 0){ - MVertex* VToDo = (*CurrentSheet.begin()); - std::vector<MTetrahedron*> surroundingTet = VertexToTets[VToDo]; - for (unsigned int j = 0;j < surroundingTet.size();j++){ - for (std::size_t k = 0;k < surroundingTet[j]->getNumVertices();k++){ - MVertex* ToInsertTmp = surroundingTet[j]->getVertex(k); - std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it2 = VertexToCorresp.find(ToInsertTmp); - if (ToInsertTmp->onWhat()->tag() == VToDo->onWhat()->tag()){//TODO: OR that onwhat -> dim <, for edges - if (it2 != VertexToCorresp.end()){ - if ((*it2).second.size() > 0){ - CorrespVerticesFixMesh* correspToInsert = ((*it2).second)[0]; - //std::cout<<" Testing "<<((*it2).second)[0]->getStartPoint()->getNum()<<" with "; - if (correspToInsert->getStartPoint()->onWhat()->dim() == 2) - //std::cout<<"On a surface ; "; - if (correspToInsert->getActive()) - //std::cout<<"Is active ; "; - if (correspToInsert->getEndTriangleActive()) - //std::cout<<"End Triangle active ; "; - if (correspToInsert->getTagMaster() == (-2)) - //std::cout<<"Has yet to be used ; "; - //std::cout<<std::endl; - if ((correspToInsert->getStartPoint()->onWhat()->dim() == 2) && (correspToInsert->getActive()) && (correspToInsert->getEndTriangleActive()) && (correspToInsert->getTagMaster() == (-2))){ + while(CurrentSheet.size() != 0) { + MVertex *VToDo = (*CurrentSheet.begin()); + std::vector<MTetrahedron *> surroundingTet = + VertexToTets[VToDo]; + for(unsigned int j = 0; j < surroundingTet.size(); j++) { + for(std::size_t k = 0; + k < surroundingTet[j]->getNumVertices(); k++) { + MVertex *ToInsertTmp = surroundingTet[j]->getVertex(k); + std::map<MVertex *, + std::vector<CorrespVerticesFixMesh *> >::iterator + it2 = VertexToCorresp.find(ToInsertTmp); + if(ToInsertTmp->onWhat()->tag() == + VToDo->onWhat()->tag()) { // TODO: OR that onwhat -> + // dim <, for edges + if(it2 != VertexToCorresp.end()) { + if((*it2).second.size() > 0) { + CorrespVerticesFixMesh *correspToInsert = + ((*it2).second)[0]; + // std::cout<<" Testing + // "<<((*it2).second)[0]->getStartPoint()->getNum()<<" + // with "; + if(correspToInsert->getStartPoint() + ->onWhat() + ->dim() == 2) + // std::cout<<"On a surface ; "; + if(correspToInsert->getActive()) + // std::cout<<"Is active ; "; + if(correspToInsert->getEndTriangleActive()) + // std::cout<<"End Triangle active ; "; + if(correspToInsert->getTagMaster() == (-2)) + // std::cout<<"Has yet to be used ; "; + // std::cout<<std::endl; + if((correspToInsert->getStartPoint() + ->onWhat() + ->dim() == 2) && + (correspToInsert->getActive()) && + (correspToInsert + ->getEndTriangleActive()) && + (correspToInsert->getTagMaster() == + (-2))) { MasterSheet.push_back((*it2).second[0]); (*it2).second[0]->setTagMaster(-1); - // faceXtetFM faceEndSlave2 = (*((*it2).second[0]->getEndTriangle())); - // faceXtetFM faceEndSlave2 = ((*it2).second[0]->getEndTriangle()); + // faceXtetFM + //faceEndSlave2 = + //(*((*it2).second[0]->getEndTriangle())); + // faceXtetFM + //faceEndSlave2 = + //((*it2).second[0]->getEndTriangle()); { - std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint1()); - if (it3 != VertexToCorresp.end()){ - if ((*it3).second.size() > 0){ - if ((*it2).second[0]->getEndTrianglePoint1()->onWhat()->dim() == 2){ - (*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag()); + std::map< + MVertex *, + std::vector<CorrespVerticesFixMesh + *> >::iterator it3 = + VertexToCorresp.find( + (*it2) + .second[0] + ->getEndTrianglePoint1()); + if(it3 != VertexToCorresp.end()) { + if((*it3).second.size() > 0) { + if((*it2) + .second[0] + ->getEndTrianglePoint1() + ->onWhat() + ->dim() == 2) { + (*it3).second[0]->setTagMaster( + (*it2) + .second[i] + ->getStartPoint() + ->onWhat() + ->tag()); } } } - it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint2()); - if (it3 != VertexToCorresp.end()){ - if ((*it3).second.size() > 0){ - if ((*it2).second[0]->getEndTrianglePoint2()->onWhat()->dim() == 2){ - (*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag()); + it3 = VertexToCorresp.find( + (*it2) + .second[0] + ->getEndTrianglePoint2()); + if(it3 != VertexToCorresp.end()) { + if((*it3).second.size() > 0) { + if((*it2) + .second[0] + ->getEndTrianglePoint2() + ->onWhat() + ->dim() == 2) { + (*it3).second[0]->setTagMaster( + (*it2) + .second[i] + ->getStartPoint() + ->onWhat() + ->tag()); } } } - it3 = VertexToCorresp.find((*it2).second[0]->getEndTrianglePoint3()); - if (it3 != VertexToCorresp.end()){ - if ((*it3).second.size() > 0){ - if ((*it2).second[0]->getEndTrianglePoint3()->onWhat()->dim() == 2){ - (*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag()); + it3 = VertexToCorresp.find( + (*it2) + .second[0] + ->getEndTrianglePoint3()); + if(it3 != VertexToCorresp.end()) { + if((*it3).second.size() > 0) { + if((*it2) + .second[0] + ->getEndTrianglePoint3() + ->onWhat() + ->dim() == 2) { + (*it3).second[0]->setTagMaster( + (*it2) + .second[i] + ->getStartPoint() + ->onWhat() + ->tag()); } } } } - // for (unsigned int j = 0;j < 3;j++){ - // std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> >::iterator it3 = VertexToCorresp.find(faceEndSlave2.v[j]); - // if (it3 != VertexToCorresp.end()){ - // if (faceEndSlave2.v[j]->onWhat()->dim() == 2){ + // for + //(unsigned int j = 0;j < 3;j++){ + // std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> + //>::iterator it3 = + //VertexToCorresp.find(faceEndSlave2.v[j]); + // if + //(it3 != VertexToCorresp.end()){ + // if + //(faceEndSlave2.v[j]->onWhat()->dim() == + //2){ // (*it3).second[0]->setTagMaster((*it2).second[i]->getStartPoint()->onWhat()->tag()); // } // } @@ -481,410 +608,622 @@ void GMSH_ThinLayerFixMeshPlugin::fillvecOfThinSheets() CurrentSheet.erase(VToDo); } vecOfThinSheets.push_back(MasterSheet); - //std::cout<<"describing new MasterSheet !"<<std::endl; - for (unsigned int j = 0;j < MasterSheet.size();j++){ - //std::cout<<"Number "<<j<<" is "<<MasterSheet[j]->getStartPoint()->getNum()<<" with position "<<MasterSheet[j]->getStartPoint()->x()<<" ; "<<MasterSheet[j]->getStartPoint()->y()<<" ; "<<MasterSheet[j]->getStartPoint()->z()<<std::endl; + // std::cout<<"describing new MasterSheet !"<<std::endl; + for(unsigned int j = 0; j < MasterSheet.size(); j++) { + // std::cout<<"Number "<<j<<" is + // "<<MasterSheet[j]->getStartPoint()->getNum()<<" with + // position "<<MasterSheet[j]->getStartPoint()->x()<<" ; + // "<<MasterSheet[j]->getStartPoint()->y()<<" ; + // "<<MasterSheet[j]->getStartPoint()->z()<<std::endl; } - //std::cout<<"exiting the master sheet !"<<std::endl; + // std::cout<<"exiting the master sheet !"<<std::endl; } } } } -std::map<MVertex*,double> GMSH_ThinLayerFixMeshPlugin::computeAllDistToOppSide(){ - std::map<MVertex*,double> AllDistToOppSide; +std::map<MVertex *, double> +GMSH_ThinLayerFixMeshPlugin::computeAllDistToOppSide() +{ + std::map<MVertex *, double> AllDistToOppSide; AllDistToOppSide.clear(); GModel *m = GModel::current(); // std::vector<MElement*> crackElements; - std::set<MVertex*> BoundaryVertices; + std::set<MVertex *> BoundaryVertices; int countdown = 0; - - - for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){ - GRegion* rTmp = (*itr); - //std::cout<<" Entering region "<<rTmp->tag()<<std::endl; - for(unsigned int i = 0; i < rTmp->tetrahedra.size(); i++){ + for(GModel::riter itr = m->firstRegion(); itr != m->lastRegion(); itr++) { + GRegion *rTmp = (*itr); + // std::cout<<" Entering region "<<rTmp->tag()<<std::endl; + for(unsigned int i = 0; i < rTmp->tetrahedra.size(); i++) { countdown++; - //std::cout<<" Entering tet "<<rTmp->tetrahedra[i]->getNum()<<" its the "<<countdown<<"st"<<std::endl; - MTet4* tet4Tmp = TetToTet4[rTmp->tetrahedra[i]]; - //std::cout<<" Neighbours 0: "<<tet4Tmp->getNeigh(0)<<" Neighbours 1: "<<tet4Tmp->getNeigh(1)<<" Neighbours 2: "<<tet4Tmp->getNeigh(2)<<" Neighbours 3: "<<tet4Tmp->getNeigh(3)<<std::endl; - for (unsigned int j = 0;j < 4;j++){ - //std::cout<<" Entering neighbour "<<j<<std::endl; - if (tet4Tmp->getNeigh(j) == 0){ - //std::cout<<" Test Passed "<<std::endl; - //find the 4th point,and fill the two vector of the boundary triangle - faceXtetFM fxtTmp(tet4Tmp,j); - //std::cout<<" fxtTmp created "<<std::endl; - for (int k = 0;k < 3;k++){ - //std::cout<<" Entering Point "<<k<<std::endl; - MVertex* toTest = fxtTmp.v[k]; - if (toTest->onWhat()->dim() == 2){ - //std::cout<<" Passed First test "<<std::endl; - if(BoundaryVertices.find(toTest) == BoundaryVertices.end()){ - //std::cout<<" Passed Second test "<<std::endl; + // std::cout<<" Entering tet "<<rTmp->tetrahedra[i]->getNum()<<" its + // the "<<countdown<<"st"<<std::endl; + MTet4 *tet4Tmp = TetToTet4[rTmp->tetrahedra[i]]; + // std::cout<<" Neighbours 0: "<<tet4Tmp->getNeigh(0)<<" Neighbours + // 1: "<<tet4Tmp->getNeigh(1)<<" Neighbours 2: "<<tet4Tmp->getNeigh(2)<<" + // Neighbours 3: "<<tet4Tmp->getNeigh(3)<<std::endl; + for(unsigned int j = 0; j < 4; j++) { + // std::cout<<" Entering neighbour "<<j<<std::endl; + if(tet4Tmp->getNeigh(j) == 0) { + // std::cout<<" Test Passed "<<std::endl; + // find the 4th point,and fill the two vector of the boundary triangle + faceXtetFM fxtTmp(tet4Tmp, j); + // std::cout<<" fxtTmp created "<<std::endl; + for(int k = 0; k < 3; k++) { + // std::cout<<" Entering Point "<<k<<std::endl; + MVertex *toTest = fxtTmp.v[k]; + if(toTest->onWhat()->dim() == 2) { + // std::cout<<" Passed First test "<<std::endl; + if(BoundaryVertices.find(toTest) == BoundaryVertices.end()) { + // std::cout<<" Passed Second test + // "<<std::endl; BoundaryVertices.insert(toTest); } } - //std::cout<<" Exiting Point "<<k<<std::endl; + // std::cout<<" Exiting Point "<<k<<std::endl; } // crackElements.push_back(rTmp->getMeshElement(j)); } - //std::cout<<" Exiting neighbour "<<j<<std::endl; + // std::cout<<" Exiting neighbour "<<j<<std::endl; } - //std::cout<<" Exiting tet "<<rTmp->tetrahedra[i]->getNum()<<std::endl; + // std::cout<<" Exiting tet + // "<<rTmp->tetrahedra[i]->getNum()<<std::endl; } - //std::cout<<" Exiting region "<<rTmp->tag()<<std::endl; + // std::cout<<" Exiting region "<<rTmp->tag()<<std::endl; } - //std::cout<<"Entering computeDistToOppSide"<<std::endl; + // std::cout<<"Entering computeDistToOppSide"<<std::endl; countdown = 0; - for(std::set<MVertex*>::iterator it = BoundaryVertices.begin(); it != BoundaryVertices.end(); it++){ + for(std::set<MVertex *>::iterator it = BoundaryVertices.begin(); + it != BoundaryVertices.end(); it++) { countdown++; - //std::cout<<" entering Bound Vert "<<(*it)->getNum()<<" it's the "<<countdown<<"st"<<std::endl; - MVertex* toCompute = (*it); + // std::cout<<" entering Bound Vert "<<(*it)->getNum()<<" it's the + // "<<countdown<<"st"<<std::endl; + MVertex *toCompute = (*it); double resultTmp = computeDistToOppSide(toCompute); // int lastTmp = VertexToCorresp[toCompute].size() - 1; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; - // std::cout<<" Testing FaceXTet out of while third time "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; - //std::cout<<" LastTmp is "<<lastTmp<<std::endl; - //std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; - //std::cout<<" ToCompute adress is "<<toCompute<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; - // std::cout<<" tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; - // std::cout<<" Testing FaceXTet out of while popo "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; - //std::cout<<" size of AllDistToOppSide is "<<AllDistToOppSide.size()<<std::endl; - //std::cout<<" LastTmp is "<<lastTmp<<std::endl; - //std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; - //std::cout<<" ToCompute adress is "<<toCompute<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; - // std::cout<<" t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; - // std::cout<<" tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; - // std::cout<<" VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; - // std::cout<<" VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; - //std::cout<<" ToCompute adress is "<<toCompute<<std::endl; - // std::cout<<" Testing FaceXTet out of while popo 2 "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; + // std::cout<<" Testing FaceXTet out of while third time + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; + // std::cout<<" LastTmp is "<<lastTmp<<std::endl; + // std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; + // std::cout<<" ToCompute adress is "<<toCompute<<std::endl; + // std::cout<<" VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" t1 is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; + // std::cout<<" tet is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; + // std::cout<<" Testing FaceXTet out of while popo + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; + // std::cout<<" size of AllDistToOppSide is + // "<<AllDistToOppSide.size()<<std::endl; std::cout<<" LastTmp is + // "<<lastTmp<<std::endl; std::cout<<" ToCompute is + // "<<toCompute->getNum()<<std::endl; std::cout<<" ToCompute + // adress is "<<toCompute<<std::endl; std::cout<<" + // VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; + // std::cout<<" t1 is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; + // std::cout<<" tet is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; + // std::cout<<" VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; + // std::cout<<" + //VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is + //"<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; + // std::cout<<" VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; + // std::cout<<" + //VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is + //"<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; + // std::cout<<" ToCompute adress is "<<toCompute<<std::endl; + // std::cout<<" Testing FaceXTet out of while popo 2 + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; AllDistToOppSide.insert(std::make_pair(toCompute, resultTmp)); - //std::cout<<" AllDistToOppSide[toCompute] is "<<AllDistToOppSide[toCompute]<<std::endl; - //std::cout<<" ToCompute adress is "<<toCompute<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; - // std::cout<<" VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; - //std::cout<<" ToCompute adress is "<<toCompute<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; - //std::cout<<" AllDistToOppSide[toCompute] adress is "<<&AllDistToOppSide[toCompute]<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is "<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; - //std::cout<<" LastTmp is "<<lastTmp<<std::endl; - //std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; - //std::cout<<" ToCompute adress is "<<toCompute<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; - // std::cout<<" tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; - // std::cout<<" Testing FaceXTet out of while popo 3 "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; + // std::cout<<" AllDistToOppSide[toCompute] is + // "<<AllDistToOppSide[toCompute]<<std::endl; std::cout<<" + // ToCompute adress is "<<toCompute<<std::endl; std::cout<<" + // VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal()<<std::endl; + // std::cout<<" getEndNormal is + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().x()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[toCompute][lastTmp]->getEndNormal().z()<<std::endl; + // std::cout<<" + //VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is + //"<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; + // std::cout<<" ToCompute adress is "<<toCompute<<std::endl; + // std::cout<<" VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" + //VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is + //"<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; + // std::cout<<" AllDistToOppSide[toCompute] adress is + // "<<&AllDistToOppSide[toCompute]<<std::endl; std::cout<<" + // VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" + //VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is + //"<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; + // std::cout<<" VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" + //VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is + //"<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; + // std::cout<<" VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" + //VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1 adress is + //"<<&(VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1)<<std::endl; + // std::cout<<" LastTmp is "<<lastTmp<<std::endl; + // std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; + // std::cout<<" ToCompute adress is "<<toCompute<<std::endl; + // std::cout<<" VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" t1 is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; + // std::cout<<" tet is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; + // std::cout<<" Testing FaceXTet out of while popo 3 + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; // AllDistToOppSide[toCompute] = 0.0; // std::cout<<" LastTmp is "<<lastTmp<<std::endl; - // std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; - // std::cout<<" tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; - // std::cout<<" size of AllDistToOppSide is "<<AllDistToOppSide.size()<<std::endl; - // std::cout<<" LastTmp is "<<lastTmp<<std::endl; - // std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; - // std::cout<<" tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; + // std::cout<<" ToCompute is + //"<<toCompute->getNum()<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" t1 is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; + // std::cout<<" tet is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; + // std::cout<<" size of AllDistToOppSide is + //"<<AllDistToOppSide.size()<<std::endl; std::cout<<" + //LastTmp is "<<lastTmp<<std::endl; std::cout<<" + //ToCompute is "<<toCompute->getNum()<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" t1 is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; + // std::cout<<" tet is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; AllDistToOppSide[toCompute] = resultTmp; - //std::cout<<" observation "<<countdown<<std::endl; - //std::cout<<" LastTmp is "<<lastTmp<<std::endl; - //std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; - //std::cout<<" VertexToCorresp[toCompute][lastTmp] is "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; - // std::cout<<" getEndTriangle is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; - // std::cout<<" t1 is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; - // std::cout<<" tet is "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; - // std::cout<<" Testing FaceXTet out of while bis repetita "<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; - for (std::map<MVertex*,double>::iterator allDistIt = AllDistToOppSide.begin();allDistIt != AllDistToOppSide.end();allDistIt++){ - //std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl; - //std::cout<<" Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl; + // std::cout<<" observation "<<countdown<<std::endl; + // std::cout<<" LastTmp is "<<lastTmp<<std::endl; + // std::cout<<" ToCompute is "<<toCompute->getNum()<<std::endl; + // std::cout<<" VertexToCorresp[toCompute][lastTmp] is + // "<<VertexToCorresp[toCompute][lastTmp]<<std::endl; std::cout<<" + //getEndTriangle is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle()<<std::endl; + // std::cout<<" t1 is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1<<std::endl; + // std::cout<<" tet is + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()<<std::endl; + // std::cout<<" Testing FaceXTet out of while bis repetita + //"<<VertexToCorresp[toCompute][lastTmp]->getEndTriangle().t1->tet()->getNum()<<std::endl; + for(std::map<MVertex *, double>::iterator allDistIt = + AllDistToOppSide.begin(); + allDistIt != AllDistToOppSide.end(); allDistIt++) { + // std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with + // Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; + // "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl; + // std::cout<<" Size of vertexToCorresp + // "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl; // MVertex* toComputeTest = (*allDistIt).first; - //std::cout<<" ToComputeTest is "<<toComputeTest->getNum()<<std::endl; + // std::cout<<" ToComputeTest is "<<toComputeTest->getNum()<<std::endl; // int lastTmpTest = VertexToCorresp[toComputeTest].size() - 1; - // std::cout<<" Testing FaceXTet out of while ter repetita "<<VertexToCorresp[toComputeTest][lastTmpTest]->getEndTriangle().t1->tet()->getNum()<<std::endl; - // std::cout<<" Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl; + // std::cout<<" Testing FaceXTet out of while ter + //repetita + //"<<VertexToCorresp[toComputeTest][lastTmpTest]->getEndTriangle().t1->tet()->getNum()<<std::endl; + // std::cout<<" Testing FaceXTet out of while fourth time + //"<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() + //- 1]->getEndTriangle().t1->tet()->getNum()<<std::endl; } } - //std::cout<<"first observation"<<std::endl; - for (std::map<MVertex*,double>::iterator allDistIt = AllDistToOppSide.begin();allDistIt != AllDistToOppSide.end();allDistIt++){ - //std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl; - //std::cout<<" Size of vertexToCorresp "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl; - // std::cout<<" Testing FaceXTet out of while fourth time "<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() - 1]->getEndTriangle().t1->tet()->getNum()<<std::endl; + // std::cout<<"first observation"<<std::endl; + for(std::map<MVertex *, double>::iterator allDistIt = + AllDistToOppSide.begin(); + allDistIt != AllDistToOppSide.end(); allDistIt++) { + // std::cout<<"allDist of point "<<(*allDistIt).first->getNum()<<" with Pos + // "<<(*allDistIt).first->x()<<" ; "<<(*allDistIt).first->z()<<" ; + // "<<(*allDistIt).first->y()<<" is "<<(*allDistIt).second<<std::endl; + // std::cout<<" Size of vertexToCorresp + // "<<VertexToCorresp[(*allDistIt).first].size()<<std::endl; + // std::cout<<" Testing FaceXTet out of while fourth time + //"<<VertexToCorresp[(*allDistIt).first][VertexToCorresp[(*allDistIt).first].size() + //- 1]->getEndTriangle().t1->tet()->getNum()<<std::endl; } return AllDistToOppSide; } -double GMSH_ThinLayerFixMeshPlugin::computeDistToOppSide(MVertex* v){ +double GMSH_ThinLayerFixMeshPlugin::computeDistToOppSide(MVertex *v) +{ double DistToOppSide = 0.0; - //We assume v is on the boundary - //First we need to get the internal normal - //std::cout<<" Entering ComputeDistToOppSide Function"<<std::endl; - SVector3 InteriorNormal = GMSH_ThinLayerFixMeshPlugin::computeInteriorNormal(v); - //std::cout<<" Normal computed"<<std::endl; - //Then we find the first triangle - MTet4* FirstTet = GMSH_ThinLayerFixMeshPlugin::getTetFromPoint(v,InteriorNormal); - //std::cout<<" FirstTet is tet "<<FirstTet->tet()->getNum()<<std::endl; - //std::cout<<" got FirstTet"<<std::endl; - MTet4* CurrentTet = FirstTet; - //std::cout<<" set currentTet"<<std::endl; - MTet4* PastTet = FirstTet; - //std::cout<<" set PastTet"<<std::endl; - SPoint3 CurrentPos = SPoint3(v->x(),v->y(),v->z()); - //std::cout<<" set CurrentPos"<<std::endl; + // We assume v is on the boundary + // First we need to get the internal normal + // std::cout<<" Entering ComputeDistToOppSide Function"<<std::endl; + SVector3 InteriorNormal = + GMSH_ThinLayerFixMeshPlugin::computeInteriorNormal(v); + // std::cout<<" Normal computed"<<std::endl; + // Then we find the first triangle + MTet4 *FirstTet = + GMSH_ThinLayerFixMeshPlugin::getTetFromPoint(v, InteriorNormal); + // std::cout<<" FirstTet is tet "<<FirstTet->tet()->getNum()<<std::endl; + // std::cout<<" got FirstTet"<<std::endl; + MTet4 *CurrentTet = FirstTet; + // std::cout<<" set currentTet"<<std::endl; + MTet4 *PastTet = FirstTet; + // std::cout<<" set PastTet"<<std::endl; + SPoint3 CurrentPos = SPoint3(v->x(), v->y(), v->z()); + // std::cout<<" set CurrentPos"<<std::endl; SPoint3 LastPos = CurrentPos; - //std::cout<<" set LasPos"<<std::endl; + // std::cout<<" set LasPos"<<std::endl; int CurrentTriValue = 0; - int* CurrentTri = &CurrentTriValue; - //std::cout<<" set CurrentTri"<<std::endl; - CorrespVerticesFixMesh* CVTemp = new CorrespVerticesFixMesh(); - //std::cout<<" Created CVTemp"<<std::endl; + int *CurrentTri = &CurrentTriValue; + // std::cout<<" set CurrentTri"<<std::endl; + CorrespVerticesFixMesh *CVTemp = new CorrespVerticesFixMesh(); + // std::cout<<" Created CVTemp"<<std::endl; CorrespVerticesFixMesh CVTemp2; - //std::cout<<" Created CVTemp2"<<std::endl; + // std::cout<<" Created CVTemp2"<<std::endl; CVTemp->setStartPoint(v); CVTemp2.setStartPoint(v); - //std::cout<<" setStartPoint"<<std::endl; + // std::cout<<" setStartPoint"<<std::endl; CVTemp->setStartNormal(InteriorNormal); CVTemp2.setStartNormal(InteriorNormal); - //std::cout<<" setStartNormal"<<std::endl; - FindNewPoint((&CurrentPos),CurrentTri,&CurrentTet,InteriorNormal); + // std::cout<<" setStartNormal"<<std::endl; + FindNewPoint((&CurrentPos), CurrentTri, &CurrentTet, InteriorNormal); DistToOppSide += CurrentPos.distance(LastPos); LastPos = CurrentPos; - //std::cout<<" Found New Point"<<std::endl; + // std::cout<<" Found New Point"<<std::endl; // faceXtetFM fxtCV(PastTet,(*CurrentTri)); // CVTemp->setEndTriangle(&fxtCV); // while(CurrentTet->getNeigh((*CurrentTri)) != 0){ int countWhile = 0; int prevprevtet = 1; int prevtet = 2; - while((CurrentTet != 0) && (countWhile < 50)){ - //std::cout<<" Entering While"<<std::endl; - //std::cout<<"CurrentTet is "<<CurrentTet->tet()->getNum()<< "adress "<<CurrentTet<< " and currentTri "<<(*CurrentTri)<<std::endl; - //std::cout<<"currentPos is "<<CurrentPos.x()<<" ; "<<CurrentPos.y()<<" ; "<<CurrentPos.z()<<std::endl; + while((CurrentTet != 0) && (countWhile < 50)) { + // std::cout<<" Entering + // While"<<std::endl; std::cout<<"CurrentTet is + // "<<CurrentTet->tet()->getNum()<< "adress "<<CurrentTet<< " and currentTri + // "<<(*CurrentTri)<<std::endl; std::cout<<"currentPos is + // "<<CurrentPos.x()<<" ; "<<CurrentPos.y()<<" ; + // "<<CurrentPos.z()<<std::endl; countWhile++; - faceXtetFM fxtCVtmp(PastTet,(*CurrentTri)); + faceXtetFM fxtCVtmp(PastTet, (*CurrentTri)); PastTet = CurrentTet; - CVTemp->setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0])); - CVTemp->setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1])); - CVTemp->setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2])); - CVTemp2.setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0])); - CVTemp2.setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1])); - CVTemp2.setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2])); + CVTemp->setEndTrianglePoint1( + PastTet->tet()->getVertex(faces[(*CurrentTri)][0])); + CVTemp->setEndTrianglePoint2( + PastTet->tet()->getVertex(faces[(*CurrentTri)][1])); + CVTemp->setEndTrianglePoint3( + PastTet->tet()->getVertex(faces[(*CurrentTri)][2])); + CVTemp2.setEndTrianglePoint1( + PastTet->tet()->getVertex(faces[(*CurrentTri)][0])); + CVTemp2.setEndTrianglePoint2( + PastTet->tet()->getVertex(faces[(*CurrentTri)][1])); + CVTemp2.setEndTrianglePoint3( + PastTet->tet()->getVertex(faces[(*CurrentTri)][2])); // CVTemp->setEndTriangle(fxtCVtmp); // CVTemp2.setEndTriangle(fxtCVtmp); - //std::cout<<" FaceXTetCreated"<<std::endl; - //std::cout<<" Testing FaceXTet in while "<<fxtCVtmp.t1->tet()->getNum()<<std::endl; - //std::cout<<" CurrentTet before FindNewPoint "<<CurrentTet<<std::endl; - FindNewPoint((&CurrentPos),CurrentTri,&CurrentTet,InteriorNormal); - //std::cout<<" CurrentTet after FindNewPoint "<<CurrentTet<<std::endl; - //std::cout<<" FoundNewPoint While"<<std::endl; - // CurrentTet = CurrentTet->getNeigh((*CurrentTri)); + // std::cout<<" FaceXTetCreated"<<std::endl; + // std::cout<<" Testing FaceXTet in while + // "<<fxtCVtmp.t1->tet()->getNum()<<std::endl; std::cout<<" + // CurrentTet before FindNewPoint "<<CurrentTet<<std::endl; + FindNewPoint((&CurrentPos), CurrentTri, &CurrentTet, InteriorNormal); + // std::cout<<" CurrentTet after FindNewPoint + // "<<CurrentTet<<std::endl; std::cout<<" FoundNewPoint + // While"<<std::endl; CurrentTet = + //CurrentTet->getNeigh((*CurrentTri)); // //std::cout<<" GotNeigh While"<<std::endl; DistToOppSide += CurrentPos.distance(LastPos); LastPos = CurrentPos; - if (CurrentTet != 0){ - if ((CurrentTet->tet()->getNum()) == prevprevtet){ - //std::cout<<"reached standstill"<<std::endl; - while (1){ - + if(CurrentTet != 0) { + if((CurrentTet->tet()->getNum()) == prevprevtet) { + // std::cout<<"reached standstill"<<std::endl; + while(1) { } } prevprevtet = prevtet; - prevtet=CurrentTet->tet()->getNum(); + prevtet = CurrentTet->tet()->getNum(); } - //std::cout<<" Exiting While"<<std::endl; + // std::cout<<" Exiting + // While"<<std::endl; } - //std::cout<<" Out Of While"<<std::endl; + // std::cout<<" Out Of While"<<std::endl; CVTemp->setEndPoint(LastPos); CVTemp2.setEndPoint(LastPos); - faceXtetFM fxtCV(PastTet,(*CurrentTri)); - //std::cout<<" Testing FaceXTet out of while "<<fxtCV.t1->tet()->getNum()<<std::endl; - CVTemp->setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0])); - CVTemp->setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1])); - CVTemp->setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2])); - CVTemp2.setEndTrianglePoint1(PastTet->tet()->getVertex(faces[(*CurrentTri)][0])); - CVTemp2.setEndTrianglePoint2(PastTet->tet()->getVertex(faces[(*CurrentTri)][1])); - CVTemp2.setEndTrianglePoint3(PastTet->tet()->getVertex(faces[(*CurrentTri)][2])); + faceXtetFM fxtCV(PastTet, (*CurrentTri)); + // std::cout<<" Testing FaceXTet out of while + // "<<fxtCV.t1->tet()->getNum()<<std::endl; + CVTemp->setEndTrianglePoint1( + PastTet->tet()->getVertex(faces[(*CurrentTri)][0])); + CVTemp->setEndTrianglePoint2( + PastTet->tet()->getVertex(faces[(*CurrentTri)][1])); + CVTemp->setEndTrianglePoint3( + PastTet->tet()->getVertex(faces[(*CurrentTri)][2])); + CVTemp2.setEndTrianglePoint1( + PastTet->tet()->getVertex(faces[(*CurrentTri)][0])); + CVTemp2.setEndTrianglePoint2( + PastTet->tet()->getVertex(faces[(*CurrentTri)][1])); + CVTemp2.setEndTrianglePoint3( + PastTet->tet()->getVertex(faces[(*CurrentTri)][2])); // CVTemp->setEndTriangle(fxtCV); // CVTemp2.setEndTriangle(fxtCV); - // //std::cout<<" Testing FaceXTet out of while second time "<<CVTemp->getEndTriangle().t1->tet()->getNum()<<std::endl; - // //std::cout<<" Testing FaceXTet out of while second time CVTemp2 "<<CVTemp2.getEndTriangle().t1->tet()->getNum()<<std::endl; + // //std::cout<<" Testing FaceXTet out of while second time + //"<<CVTemp->getEndTriangle().t1->tet()->getNum()<<std::endl; + // //std::cout<<" Testing FaceXTet out of while second time CVTemp2 + //"<<CVTemp2.getEndTriangle().t1->tet()->getNum()<<std::endl; // CVTemp->setEndTriangle(&fxtCV); - // SVector3 EndDir1(fxtCV.v[1]->x() - fxtCV.v[0]->x(),fxtCV.v[1]->y() - fxtCV.v[0]->y(),fxtCV.v[1]->z() - fxtCV.v[0]->z()); - // SVector3 EndDir2(fxtCV.v[2]->x() - fxtCV.v[0]->x(),fxtCV.v[2]->y() - fxtCV.v[0]->y(),fxtCV.v[2]->z() - fxtCV.v[0]->z()); - // SVector3 EndNormal(EndDir1.y() * EndDir2.z() - EndDir1.z() * EndDir2.y(),EndDir1.z() * EndDir2.x() - EndDir1.x() * EndDir2.z(),EndDir1.x() * EndDir2.y() - EndDir1.y() * EndDir2.x()); - SVector3 EndNormal(-InteriorNormal.x(),-InteriorNormal.y(),-InteriorNormal.z()); + // SVector3 EndDir1(fxtCV.v[1]->x() - fxtCV.v[0]->x(),fxtCV.v[1]->y() - + //fxtCV.v[0]->y(),fxtCV.v[1]->z() - fxtCV.v[0]->z()); SVector3 + //EndDir2(fxtCV.v[2]->x() - fxtCV.v[0]->x(),fxtCV.v[2]->y() - + //fxtCV.v[0]->y(),fxtCV.v[2]->z() - fxtCV.v[0]->z()); SVector3 + //EndNormal(EndDir1.y() * EndDir2.z() - EndDir1.z() * EndDir2.y(),EndDir1.z() + //* EndDir2.x() - EndDir1.x() * EndDir2.z(),EndDir1.x() * EndDir2.y() - + //EndDir1.y() * EndDir2.x()); + SVector3 EndNormal(-InteriorNormal.x(), -InteriorNormal.y(), + -InteriorNormal.z()); EndNormal.normalize(); CVTemp->setEndNormal(EndNormal); CVTemp2.setEndNormal(EndNormal); - CVTemp->setangleProd(fabs(CVTemp->getStartNormal().x() * CVTemp->getEndNormal().x() + CVTemp->getStartNormal().y() * CVTemp->getEndNormal().y() + CVTemp->getStartNormal().z() * CVTemp->getEndNormal().z())); - CVTemp2.setangleProd(fabs(CVTemp2.getStartNormal().x() * CVTemp2.getEndNormal().x() + CVTemp2.getStartNormal().y() * CVTemp2.getEndNormal().y() + CVTemp2.getStartNormal().z() * CVTemp2.getEndNormal().z())); + CVTemp->setangleProd( + fabs(CVTemp->getStartNormal().x() * CVTemp->getEndNormal().x() + + CVTemp->getStartNormal().y() * CVTemp->getEndNormal().y() + + CVTemp->getStartNormal().z() * CVTemp->getEndNormal().z())); + CVTemp2.setangleProd( + fabs(CVTemp2.getStartNormal().x() * CVTemp2.getEndNormal().x() + + CVTemp2.getStartNormal().y() * CVTemp2.getEndNormal().y() + + CVTemp2.getStartNormal().z() * CVTemp2.getEndNormal().z())); CVTemp->setdistP2P(DistToOppSide); CVTemp2.setdistP2P(DistToOppSide); - if ((CVTemp->getangleProd() > angleMax) &&(CVTemp->getdistP2P() < distP2PMax)){ + if((CVTemp->getangleProd() > angleMax) && + (CVTemp->getdistP2P() < distP2PMax)) { CVTemp->setActive(true); } - else{ + else { CVTemp->setActive(false); } - if ((CVTemp2.getangleProd() > angleMax) &&(CVTemp2.getdistP2P() < distP2PMax)){ + if((CVTemp2.getangleProd() > angleMax) && + (CVTemp2.getdistP2P() < distP2PMax)) { CVTemp2.setActive(true); } - else{ + else { CVTemp2.setActive(false); } CVTemp->setTagMaster(-2); CVTemp2.setTagMaster(-2); - //std::cout<<" getEndNormal is "<<CVTemp2.getEndNormal().x()<<" ; "<<CVTemp2.getEndNormal().y()<<" ; "<<CVTemp2.getEndNormal().z()<<std::endl; - //std::cout<<" getEndNormal is "<<CVTemp2.getEndNormal().x()<<" ; "<<CVTemp2.getEndNormal().y()<<" ; "<<CVTemp2.getEndNormal().z()<<std::endl; + // std::cout<<" getEndNormal is "<<CVTemp2.getEndNormal().x()<<" ; + // "<<CVTemp2.getEndNormal().y()<<" ; "<<CVTemp2.getEndNormal().z()<<std::endl; + // std::cout<<" getEndNormal is "<<CVTemp2.getEndNormal().x()<<" ; + // "<<CVTemp2.getEndNormal().y()<<" ; "<<CVTemp2.getEndNormal().z()<<std::endl; VertexToCorresp[v].push_back(CVTemp); // VertexToCorresp[v].push_back(&CVTemp2); - //std::cout<<" getEndNormal test is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl; - //std::cout<<" getEndNormal is "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().z()<<std::endl; + // std::cout<<" getEndNormal test is + // "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" + // ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - + // 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() + // - 1]->getEndNormal().z()<<std::endl; std::cout<<" getEndNormal + // is "<<VertexToCorresp[v][VertexToCorresp[v].size() - + // 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() + // - 1]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[v][VertexToCorresp[v].size() - + // 1]->getEndNormal().z()<<std::endl; std::cout<<" getEndNormal is + // "<<VertexToCorresp[v][VertexToCorresp[v].size() - 1]->getEndNormal().x()<<" + // ; "<<VertexToCorresp[v][VertexToCorresp[v].size() - + // 1]->getEndNormal().y()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() + // - 1]->getEndNormal().z()<<std::endl; std::cout<<" getEndNormal + // is "<<VertexToCorresp[v][VertexToCorresp[v].size() - + // 1]->getEndNormal().x()<<" ; "<<VertexToCorresp[v][VertexToCorresp[v].size() + // - 1]->getEndNormal().y()<<" ; + // "<<VertexToCorresp[v][VertexToCorresp[v].size() - + // 1]->getEndNormal().z()<<std::endl; return DistToOppSide; } -SVector3 GMSH_ThinLayerFixMeshPlugin::computeInteriorNormal(MVertex* v){ - SPoint3 InteriorNormal(0.0,0.0,0.0); - //std::cout<<" Entering computeInteriorNormal"<<std::endl; - std::vector<MTetrahedron*> currentVecTet = VertexToTets[v]; +SVector3 GMSH_ThinLayerFixMeshPlugin::computeInteriorNormal(MVertex *v) +{ + SPoint3 InteriorNormal(0.0, 0.0, 0.0); + // std::cout<<" Entering computeInteriorNormal"<<std::endl; + std::vector<MTetrahedron *> currentVecTet = VertexToTets[v]; std::vector<SPoint3> vecInteriorNodes; std::vector<SPoint3> vecFirstDir; std::vector<SPoint3> vecSecondDir; - for (unsigned int i = 0;i < currentVecTet.size();i++){ - //std::cout<<" Entering for "<<i<<std::endl; - MTet4* tet4Tmp = TetToTet4[currentVecTet[i]]; - for (int j = 0;j < 4 ; j++){ - //std::cout<<" Entering for "<<j<<std::endl; - if (tet4Tmp->getNeigh(j) == 0){ - //std::cout<<" Test Passed neigh zero "<<std::endl; - //find the 4th point,and fill the two vector of the boundary triangle - faceXtetFM fxtTmp(tet4Tmp,j); - //std::cout<<" Face Created "<<j<<std::endl; - for (int k = 0;k < 4;k++){ - //std::cout<<" Entering for "<<k<<std::endl; + for(unsigned int i = 0; i < currentVecTet.size(); i++) { + // std::cout<<" Entering for "<<i<<std::endl; + MTet4 *tet4Tmp = TetToTet4[currentVecTet[i]]; + for(int j = 0; j < 4; j++) { + // std::cout<<" Entering for "<<j<<std::endl; + if(tet4Tmp->getNeigh(j) == 0) { + // std::cout<<" Test Passed neigh zero "<<std::endl; + // find the 4th point,and fill the two vector of the boundary triangle + faceXtetFM fxtTmp(tet4Tmp, j); + // std::cout<<" Face Created "<<j<<std::endl; + for(int k = 0; k < 4; k++) { + // std::cout<<" Entering for "<<k<<std::endl; bool foundInteriorPoint = true; - for (int l = 0;l < 3;l++){ - if (tet4Tmp->tet()->getVertex(k) == fxtTmp.v[l]){ + for(int l = 0; l < 3; l++) { + if(tet4Tmp->tet()->getVertex(k) == fxtTmp.v[l]) { foundInteriorPoint = false; } } - if (foundInteriorPoint){ - SPoint3 pointTmp(tet4Tmp->tet()->getVertex(k)->x(),tet4Tmp->tet()->getVertex(k)->y(),tet4Tmp->tet()->getVertex(k)->z()); + if(foundInteriorPoint) { + SPoint3 pointTmp(tet4Tmp->tet()->getVertex(k)->x(), + tet4Tmp->tet()->getVertex(k)->y(), + tet4Tmp->tet()->getVertex(k)->z()); vecInteriorNodes.push_back(pointTmp); } } - SPoint3 pointTmp1(fxtTmp.v[1]->x() - fxtTmp.v[0]->x(),fxtTmp.v[1]->y() - fxtTmp.v[0]->y(),fxtTmp.v[1]->z() - fxtTmp.v[0]->z()); - SPoint3 pointTmp2(fxtTmp.v[2]->x() - fxtTmp.v[0]->x(),fxtTmp.v[2]->y() - fxtTmp.v[0]->y(),fxtTmp.v[2]->z() - fxtTmp.v[0]->z()); + SPoint3 pointTmp1(fxtTmp.v[1]->x() - fxtTmp.v[0]->x(), + fxtTmp.v[1]->y() - fxtTmp.v[0]->y(), + fxtTmp.v[1]->z() - fxtTmp.v[0]->z()); + SPoint3 pointTmp2(fxtTmp.v[2]->x() - fxtTmp.v[0]->x(), + fxtTmp.v[2]->y() - fxtTmp.v[0]->y(), + fxtTmp.v[2]->z() - fxtTmp.v[0]->z()); vecFirstDir.push_back(pointTmp1); vecSecondDir.push_back(pointTmp2); } } } - //std::cout<<" Out of loop for "<<std::endl; - //at this point we have all the info necessary. - SPoint3 pointInteriorAverage(0.0,0.0,0.0); - for (unsigned int i = 0;i < vecInteriorNodes.size();i++){ - pointInteriorAverage += SPoint3(vecInteriorNodes[i].x(),vecInteriorNodes[i].y(),vecInteriorNodes[i].z()); + // std::cout<<" Out of loop for "<<std::endl; + // at this point we have all the info necessary. + SPoint3 pointInteriorAverage(0.0, 0.0, 0.0); + for(unsigned int i = 0; i < vecInteriorNodes.size(); i++) { + pointInteriorAverage += + SPoint3(vecInteriorNodes[i].x(), vecInteriorNodes[i].y(), + vecInteriorNodes[i].z()); // pointInteriorAverage.x() += vecInteriorNodes[i].x(); // pointInteriorAverage.y() += vecInteriorNodes[i].y(); // pointInteriorAverage.z() += vecInteriorNodes[i].z(); } - pointInteriorAverage = SPoint3(pointInteriorAverage.x() / (double(vecInteriorNodes.size())),pointInteriorAverage.y() / (double(vecInteriorNodes.size())),pointInteriorAverage.z() / (double(vecInteriorNodes.size()))); - // pointInteriorAverage.x() = pointInteriorAverage.x() / (double(vecInteriorNodes.size())); - // pointInteriorAverage.y() = pointInteriorAverage.y() / (double(vecInteriorNodes.size())); - // pointInteriorAverage.z() = pointInteriorAverage.z() / (double(vecInteriorNodes.size())); - SPoint3 dirInteriorAverage(pointInteriorAverage.x() - v->x(),pointInteriorAverage.y() - v->y(),pointInteriorAverage.z() - v->z()); - double norme = sqrt(dirInteriorAverage.x() * dirInteriorAverage.x() + dirInteriorAverage.y() * dirInteriorAverage.y() + dirInteriorAverage.z() * dirInteriorAverage.z()); - dirInteriorAverage = SPoint3(dirInteriorAverage.x() / norme,dirInteriorAverage.y() / norme,dirInteriorAverage.z() / norme); + pointInteriorAverage = + SPoint3(pointInteriorAverage.x() / (double(vecInteriorNodes.size())), + pointInteriorAverage.y() / (double(vecInteriorNodes.size())), + pointInteriorAverage.z() / (double(vecInteriorNodes.size()))); + // pointInteriorAverage.x() = pointInteriorAverage.x() / + //(double(vecInteriorNodes.size())); pointInteriorAverage.y() = + //pointInteriorAverage.y() / (double(vecInteriorNodes.size())); + // pointInteriorAverage.z() = pointInteriorAverage.z() / + //(double(vecInteriorNodes.size())); + SPoint3 dirInteriorAverage(pointInteriorAverage.x() - v->x(), + pointInteriorAverage.y() - v->y(), + pointInteriorAverage.z() - v->z()); + double norme = sqrt(dirInteriorAverage.x() * dirInteriorAverage.x() + + dirInteriorAverage.y() * dirInteriorAverage.y() + + dirInteriorAverage.z() * dirInteriorAverage.z()); + dirInteriorAverage = + SPoint3(dirInteriorAverage.x() / norme, dirInteriorAverage.y() / norme, + dirInteriorAverage.z() / norme); // dirInteriorAverage.x() = dirInteriorAverage.x() / norme; // dirInteriorAverage.y() = dirInteriorAverage.y() / norme; // dirInteriorAverage.z() = dirInteriorAverage.z() / norme; std::vector<SPoint3> vecOrthogDir; - for(unsigned int i = 0;i < vecFirstDir.size();i++){ - SPoint3 pointTmp(vecFirstDir[i].y() * vecSecondDir[i].z() - vecFirstDir[i].z() * vecSecondDir[i].y(),vecFirstDir[i].z() * vecSecondDir[i].x() - vecFirstDir[i].x() * vecSecondDir[i].z(),vecFirstDir[i].x() * vecSecondDir[i].y() - vecFirstDir[i].y() * vecSecondDir[i].x()); + for(unsigned int i = 0; i < vecFirstDir.size(); i++) { + SPoint3 pointTmp(vecFirstDir[i].y() * vecSecondDir[i].z() - + vecFirstDir[i].z() * vecSecondDir[i].y(), + vecFirstDir[i].z() * vecSecondDir[i].x() - + vecFirstDir[i].x() * vecSecondDir[i].z(), + vecFirstDir[i].x() * vecSecondDir[i].y() - + vecFirstDir[i].y() * vecSecondDir[i].x()); vecOrthogDir.push_back(pointTmp); } - for(unsigned int i = 0;i < vecOrthogDir.size();i++){ - double prodScalTmp = vecOrthogDir[i].x() * dirInteriorAverage.x() + vecOrthogDir[i].y() * dirInteriorAverage.y() + vecOrthogDir[i].z() * dirInteriorAverage.z(); - if (prodScalTmp < 0.0){ - vecOrthogDir[i] = SPoint3(- vecOrthogDir[i].x(),- vecOrthogDir[i].y(),- vecOrthogDir[i].z()); + for(unsigned int i = 0; i < vecOrthogDir.size(); i++) { + double prodScalTmp = vecOrthogDir[i].x() * dirInteriorAverage.x() + + vecOrthogDir[i].y() * dirInteriorAverage.y() + + vecOrthogDir[i].z() * dirInteriorAverage.z(); + if(prodScalTmp < 0.0) { + vecOrthogDir[i] = SPoint3(-vecOrthogDir[i].x(), -vecOrthogDir[i].y(), + -vecOrthogDir[i].z()); // vecOrthogDir[i].x() = - vecOrthogDir[i].x(); // vecOrthogDir[i].y() = - vecOrthogDir[i].y(); // vecOrthogDir[i].z() = - vecOrthogDir[i].z(); } - double normeTmp = sqrt(vecOrthogDir[i].x() * vecOrthogDir[i].x() + vecOrthogDir[i].y() * vecOrthogDir[i].y() + vecOrthogDir[i].z() * vecOrthogDir[i].z()); - vecOrthogDir[i] = SPoint3(vecOrthogDir[i].x() / normeTmp,vecOrthogDir[i].y() / normeTmp,vecOrthogDir[i].z() / normeTmp); + double normeTmp = sqrt(vecOrthogDir[i].x() * vecOrthogDir[i].x() + + vecOrthogDir[i].y() * vecOrthogDir[i].y() + + vecOrthogDir[i].z() * vecOrthogDir[i].z()); + vecOrthogDir[i] = + SPoint3(vecOrthogDir[i].x() / normeTmp, vecOrthogDir[i].y() / normeTmp, + vecOrthogDir[i].z() / normeTmp); // vecOrthogDir[i].x() = vecOrthogDir[i].x() / normeTmp; // vecOrthogDir[i].y() = vecOrthogDir[i].y() / normeTmp; // vecOrthogDir[i].z() = vecOrthogDir[i].z() / normeTmp; - InteriorNormal += SPoint3(vecOrthogDir[i].x(),vecOrthogDir[i].y(),vecOrthogDir[i].z()); + InteriorNormal += + SPoint3(vecOrthogDir[i].x(), vecOrthogDir[i].y(), vecOrthogDir[i].z()); // InteriorNormal.x() += vecOrthogDir[i].x(); // InteriorNormal.y() += vecOrthogDir[i].y(); // InteriorNormal.z() += vecOrthogDir[i].z(); } - norme = sqrt(InteriorNormal.x() * InteriorNormal.x() + InteriorNormal.y() * InteriorNormal.y() + InteriorNormal.z() * InteriorNormal.z()); - InteriorNormal = SPoint3(InteriorNormal.x() / norme,InteriorNormal.y() / norme,InteriorNormal.z() / norme); + norme = sqrt(InteriorNormal.x() * InteriorNormal.x() + + InteriorNormal.y() * InteriorNormal.y() + + InteriorNormal.z() * InteriorNormal.z()); + InteriorNormal = + SPoint3(InteriorNormal.x() / norme, InteriorNormal.y() / norme, + InteriorNormal.z() / norme); // InteriorNormal.x() = InteriorNormal.x() / norme; // InteriorNormal.y() = InteriorNormal.y() / norme; // InteriorNormal.z() = InteriorNormal.z() / norme; return InteriorNormal; } -MTet4* GMSH_ThinLayerFixMeshPlugin::getTetFromPoint(MVertex* v, SVector3 InteriorNormal){ - MTet4* TetToGet = 0; - std::vector<MTetrahedron*> currentVecTet = VertexToTets[v]; - //std::cout<<" entering getTetFromPoint, vertex "<<v->x()<<" ; "<<v->y()<<" ; "<<v->z()<<" and dir "<<InteriorNormal.x()<<" ; "<<InteriorNormal.y()<<" ; "<<InteriorNormal.z()<<std::endl; - for (unsigned int i = 0;i < currentVecTet.size();i++){ +MTet4 *GMSH_ThinLayerFixMeshPlugin::getTetFromPoint(MVertex *v, + SVector3 InteriorNormal) +{ + MTet4 *TetToGet = 0; + std::vector<MTetrahedron *> currentVecTet = VertexToTets[v]; + // std::cout<<" entering getTetFromPoint, vertex "<<v->x()<<" ; "<<v->y()<<" + // ; "<<v->z()<<" and dir "<<InteriorNormal.x()<<" ; "<<InteriorNormal.y()<<" ; + // "<<InteriorNormal.z()<<std::endl; + for(unsigned int i = 0; i < currentVecTet.size(); i++) { std::vector<SVector3> vecDir; - for (int j = 0;j < 4 ; j++){ - if (currentVecTet[i]->getVertex(j) != v){ - SVector3 DirTmp(currentVecTet[i]->getVertex(j)->x() - v->x(),currentVecTet[i]->getVertex(j)->y() - v->y(),currentVecTet[i]->getVertex(j)->z() - v->z()); + for(int j = 0; j < 4; j++) { + if(currentVecTet[i]->getVertex(j) != v) { + SVector3 DirTmp(currentVecTet[i]->getVertex(j)->x() - v->x(), + currentVecTet[i]->getVertex(j)->y() - v->y(), + currentVecTet[i]->getVertex(j)->z() - v->z()); vecDir.push_back(DirTmp); } } - bool IsPositiv = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[0],vecDir[1],vecDir[2]); - if (!IsPositiv){ + bool IsPositiv = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation( + vecDir[0], vecDir[1], vecDir[2]); + if(!IsPositiv) { SVector3 DirTmp1 = vecDir[1]; SVector3 DirTmp2 = vecDir[0]; SVector3 DirTmp3 = vecDir[2]; @@ -893,44 +1232,56 @@ MTet4* GMSH_ThinLayerFixMeshPlugin::getTetFromPoint(MVertex* v, SVector3 Interio vecDir.push_back(DirTmp2); vecDir.push_back(DirTmp3); } - bool isPositiv1 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[0],vecDir[1],InteriorNormal); - bool isPositiv2 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[1],vecDir[2],InteriorNormal); - bool isPositiv3 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(vecDir[2],vecDir[0],InteriorNormal); - if (isPositiv1){ - if (isPositiv2){ - if (isPositiv3){ + bool isPositiv1 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation( + vecDir[0], vecDir[1], InteriorNormal); + bool isPositiv2 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation( + vecDir[1], vecDir[2], InteriorNormal); + bool isPositiv3 = GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation( + vecDir[2], vecDir[0], InteriorNormal); + if(isPositiv1) { + if(isPositiv2) { + if(isPositiv3) { TetToGet = TetToTet4[currentVecTet[i]]; - //std::cout<<" Found one fitting ! "<<TetToGet->tet()->getNum()<<std::endl; + // std::cout<<" Found one fitting ! + // "<<TetToGet->tet()->getNum()<<std::endl; } } } } - //std::cout<<" exiting getTetFromPoint with result "<<TetToGet<<std::endl; - //std::cout<<" getTetFromPoint is tet "<<TetToGet->tet()->getNum()<<std::endl; + // std::cout<<" exiting getTetFromPoint with result "<<TetToGet<<std::endl; + // std::cout<<" getTetFromPoint is tet + // "<<TetToGet->tet()->getNum()<<std::endl; return TetToGet; } -bool GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c){ +bool GMSH_ThinLayerFixMeshPlugin::IsPositivOrientation(SVector3 a, SVector3 b, + SVector3 c) +{ bool result = false; - SPoint3 ProdVec(a.y() * b.z() - a.z() * b.y(),a.z() * b.x() - a.x() * b.z(),a.x() * b.y() - a.y() * b.x()); - double ProdScal = ProdVec.x() * c.x() + ProdVec.y() * c.y() + ProdVec.z() * c.z(); - if (ProdScal >= 0.0){ + SPoint3 ProdVec(a.y() * b.z() - a.z() * b.y(), a.z() * b.x() - a.x() * b.z(), + a.x() * b.y() - a.y() * b.x()); + double ProdScal = + ProdVec.x() * c.x() + ProdVec.y() * c.y() + ProdVec.z() * c.z(); + if(ProdScal >= 0.0) { result = true; } return result; } - -void GMSH_ThinLayerFixMeshPlugin::FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri, MTet4** CurrentTet, SVector3 InteriorNormal){ +void GMSH_ThinLayerFixMeshPlugin::FindNewPoint(SPoint3 *CurrentPoint, + int *CurrentTri, + MTet4 **CurrentTet, + SVector3 InteriorNormal) +{ double distanceP2P = 0.0; double alphaMax = 0.0; double betaMax = 0.0; SPoint3 ResultPoint; int triToGet = -1; - //std::cout<<" Entered FindNewPoint"<<std::endl; - for (unsigned int n = 0;n < 4 ; n++){ - //calculer matrice a inverser - faceXtetFM fxt((*CurrentTet),n); + // std::cout<<" Entered FindNewPoint"<<std::endl; + for(unsigned int n = 0; n < 4; n++) { + // calculer matrice a inverser + faceXtetFM fxt((*CurrentTet), n); double a = fxt.v[1]->x() - fxt.v[0]->x(); double b = fxt.v[2]->x() - fxt.v[0]->x(); double c = InteriorNormal.x(); @@ -940,8 +1291,9 @@ void GMSH_ThinLayerFixMeshPlugin::FindNewPoint(SPoint3* CurrentPoint, int* Curre double g = fxt.v[1]->z() - fxt.v[0]->z(); double h = fxt.v[2]->z() - fxt.v[0]->z(); double i = InteriorNormal.z(); - //produit matrice inverse par vecteur donne poids - double detMat = a * e * i + b * f * g + c * d * h - c * e * g - f * h * a - i * b * d; + // produit matrice inverse par vecteur donne poids + double detMat = + a * e * i + b * f * g + c * d * h - c * e * g - f * h * a - i * b * d; double ai = e * i - f * h; double bi = c * h - b * i; double ci = b * f - c * e; @@ -956,14 +1308,21 @@ void GMSH_ThinLayerFixMeshPlugin::FindNewPoint(SPoint3* CurrentPoint, int* Curre double oppz = (*CurrentPoint).z() - fxt.v[0]->z(); double alpha = ai / detMat * oppx + bi / detMat * oppy + ci / detMat * oppz; double beta = di / detMat * oppx + ei / detMat * oppy + fi / detMat * oppz; - // double gamma = gi / detMat * oppx + hi / detMat * oppy + ii / detMat * oppz; - //Test si poids entre 0 et 1 et si length maximale - if ((alpha >= (0.0-epsilon)) && (alpha <= (1.0 + epsilon))){ - if ((beta >= (0.0-epsilon)) && (beta <= (1.0 + epsilon))){ - if (((1.0 - alpha - beta) >= (0.0-epsilon)) && ((1.0 - alpha - beta) <= (1.0 + epsilon))){ - SPoint3 PointTmp(fxt.v[0]->x() + alpha * (fxt.v[1]->x() - fxt.v[0]->x()) + beta * (fxt.v[2]->x() - fxt.v[0]->x()),fxt.v[0]->y() + alpha * (fxt.v[1]->y() - fxt.v[0]->y()) + beta * (fxt.v[2]->y() - fxt.v[0]->y()),fxt.v[0]->z() + alpha * (fxt.v[1]->z() - fxt.v[0]->z()) + beta * (fxt.v[2]->z() - fxt.v[0]->z())); + // double gamma = gi / detMat * oppx + hi / detMat * oppy + ii / detMat * + //oppz; Test si poids entre 0 et 1 et si length maximale + if((alpha >= (0.0 - epsilon)) && (alpha <= (1.0 + epsilon))) { + if((beta >= (0.0 - epsilon)) && (beta <= (1.0 + epsilon))) { + if(((1.0 - alpha - beta) >= (0.0 - epsilon)) && + ((1.0 - alpha - beta) <= (1.0 + epsilon))) { + SPoint3 PointTmp( + fxt.v[0]->x() + alpha * (fxt.v[1]->x() - fxt.v[0]->x()) + + beta * (fxt.v[2]->x() - fxt.v[0]->x()), + fxt.v[0]->y() + alpha * (fxt.v[1]->y() - fxt.v[0]->y()) + + beta * (fxt.v[2]->y() - fxt.v[0]->y()), + fxt.v[0]->z() + alpha * (fxt.v[1]->z() - fxt.v[0]->z()) + + beta * (fxt.v[2]->z() - fxt.v[0]->z())); double distanceTmp = PointTmp.distance((*CurrentPoint)); - if (distanceTmp > distanceP2P){ + if(distanceTmp > distanceP2P) { distanceP2P = distanceTmp; ResultPoint = PointTmp; triToGet = n; @@ -974,167 +1333,186 @@ void GMSH_ThinLayerFixMeshPlugin::FindNewPoint(SPoint3* CurrentPoint, int* Curre } } } - //std::cout<<" End of For loop"<<std::endl; - //test si trop proche d'un point / une arete - if (((alphaMax < epsilon) && (betaMax < epsilon)) || ((alphaMax < epsilon) && ((1.0 - alphaMax - betaMax) < epsilon)) || (((1.0 - alphaMax - betaMax) < epsilon) && (betaMax < epsilon))){ - //proche d'un point - //std::cout<<" Close to point"<<std::endl; + // std::cout<<" End of For loop"<<std::endl; + // test si trop proche d'un point / une arete + if(((alphaMax < epsilon) && (betaMax < epsilon)) || + ((alphaMax < epsilon) && ((1.0 - alphaMax - betaMax) < epsilon)) || + (((1.0 - alphaMax - betaMax) < epsilon) && (betaMax < epsilon))) { + // proche d'un point + // std::cout<<" Close to point"<<std::endl; double DistMinTmp = 10000000.0; int indexMinTmp = 0; - for (unsigned int i = 0;i < 4;i++){ - double distanceTmp = sqrt(((*CurrentTet)->tet()->getVertex(i)->x() - ResultPoint.x()) * ((*CurrentTet)->tet()->getVertex(i)->x() - ResultPoint.x()) + ((*CurrentTet)->tet()->getVertex(i)->y() - ResultPoint.y()) * ((*CurrentTet)->tet()->getVertex(i)->y() - ResultPoint.y()) + ((*CurrentTet)->tet()->getVertex(i)->z() - ResultPoint.z()) * ((*CurrentTet)->tet()->getVertex(i)->z() - ResultPoint.z())); - if (distanceTmp < DistMinTmp){ + for(unsigned int i = 0; i < 4; i++) { + double distanceTmp = + sqrt(((*CurrentTet)->tet()->getVertex(i)->x() - ResultPoint.x()) * + ((*CurrentTet)->tet()->getVertex(i)->x() - ResultPoint.x()) + + ((*CurrentTet)->tet()->getVertex(i)->y() - ResultPoint.y()) * + ((*CurrentTet)->tet()->getVertex(i)->y() - ResultPoint.y()) + + ((*CurrentTet)->tet()->getVertex(i)->z() - ResultPoint.z()) * + ((*CurrentTet)->tet()->getVertex(i)->z() - ResultPoint.z())); + if(distanceTmp < DistMinTmp) { DistMinTmp = distanceTmp; indexMinTmp = i; } } ////std::cout<<"NewTet before is "<<NewTet<<std::endl; - MTet4* NewTet = GMSH_ThinLayerFixMeshPlugin::getTetFromPoint((*CurrentTet)->tet()->getVertex(indexMinTmp),InteriorNormal); - //std::cout<<"NewTet after is "<<NewTet<<std::endl; - SPoint3 PointTmp((*CurrentTet)->tet()->getVertex(indexMinTmp)->x(),(*CurrentTet)->tet()->getVertex(indexMinTmp)->y(),(*CurrentTet)->tet()->getVertex(indexMinTmp)->z()); + MTet4 *NewTet = GMSH_ThinLayerFixMeshPlugin::getTetFromPoint( + (*CurrentTet)->tet()->getVertex(indexMinTmp), InteriorNormal); + // std::cout<<"NewTet after is "<<NewTet<<std::endl; + SPoint3 PointTmp((*CurrentTet)->tet()->getVertex(indexMinTmp)->x(), + (*CurrentTet)->tet()->getVertex(indexMinTmp)->y(), + (*CurrentTet)->tet()->getVertex(indexMinTmp)->z()); (*CurrentPoint) = PointTmp; (*CurrentTet) = NewTet; } - else if ((alphaMax < epsilon) || (betaMax < epsilon) || ((1.0 - alphaMax - betaMax) < epsilon)){ - //trop proche d'une arete - //std::cout<<" Close to edge"<<std::endl; + else if((alphaMax < epsilon) || (betaMax < epsilon) || + ((1.0 - alphaMax - betaMax) < epsilon)) { + // trop proche d'une arete + // std::cout<<" Close to edge"<<std::endl; } - else{ - //std::cout<<" Close to nothing"<<std::endl; - //std::cout<<" ResultPoint is "<<ResultPoint.x()<<"; "<<ResultPoint.y()<<"; "<<ResultPoint.z()<<"; "<<" and tritoget is "<<triToGet<<std::endl; - //std::cout<<" CurrentPoint is "<<(*CurrentPoint).x()<<"; "<<(*CurrentPoint).y()<<"; "<<(*CurrentPoint).z()<<std::endl; + else { + // std::cout<<" Close to nothing"<<std::endl; + // std::cout<<" ResultPoint is "<<ResultPoint.x()<<"; + // "<<ResultPoint.y()<<"; "<<ResultPoint.z()<<"; "<<" and tritoget is + // "<<triToGet<<std::endl; std::cout<<" CurrentPoint is + // "<<(*CurrentPoint).x()<<"; "<<(*CurrentPoint).y()<<"; + // "<<(*CurrentPoint).z()<<std::endl; (*CurrentPoint) = ResultPoint; - //std::cout<<" test 1"<<std::endl; - //std::cout<<" CurrentTri is "<<(*CurrentTri)<<std::endl; + // std::cout<<" test 1"<<std::endl; + // std::cout<<" CurrentTri is "<<(*CurrentTri)<<std::endl; (*CurrentTri) = triToGet; - //std::cout<<" test 2"<<std::endl; - //std::cout<<" CurrentTet is "<<(*CurrentTet)<<" and has neighbours "<< (*CurrentTet)->getNeigh(0)<<" ; "<< (*CurrentTet)->getNeigh(1)<<" ; "<< (*CurrentTet)->getNeigh(2)<<" ; "<< (*CurrentTet)->getNeigh(3)<<std::endl; + // std::cout<<" test 2"<<std::endl; + // std::cout<<" CurrentTet is "<<(*CurrentTet)<<" and has neighbours + // "<< (*CurrentTet)->getNeigh(0)<<" ; "<< (*CurrentTet)->getNeigh(1)<<" ; + // "<< (*CurrentTet)->getNeigh(2)<<" ; "<< + // (*CurrentTet)->getNeigh(3)<<std::endl; (*CurrentTet) = (*CurrentTet)->getNeigh(triToGet); - //std::cout<<" CurrentTet has been changed to "<<(*CurrentTet)<<std::endl; - //std::cout<<" test 3"<<std::endl; + // std::cout<<" CurrentTet has been changed to + // "<<(*CurrentTet)<<std::endl; std::cout<<" test 3"<<std::endl; } - //std::cout<<" Exit FindNewPoint"<<std::endl; + // std::cout<<" Exit FindNewPoint"<<std::endl; } -void GMSH_ThinLayerFixMeshPlugin::fillVertexToTets(){ +void GMSH_ThinLayerFixMeshPlugin::fillVertexToTets() +{ GModel *m = GModel::current(); - for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){ - GRegion* rTmp = (*itr); - for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){ - MTetrahedron* elem = rTmp->tetrahedra[i]; - for (unsigned int j = 0; j < 4;j++){ - std::vector<MTetrahedron*> emptyTetVec; + for(GModel::riter itr = m->firstRegion(); itr != m->lastRegion(); itr++) { + GRegion *rTmp = (*itr); + for(unsigned int i = 0; i < rTmp->tetrahedra.size(); i++) { + MTetrahedron *elem = rTmp->tetrahedra[i]; + for(unsigned int j = 0; j < 4; j++) { + std::vector<MTetrahedron *> emptyTetVec; emptyTetVec.clear(); VertexToTets[elem->getVertex(j)] = emptyTetVec; - std::vector<CorrespVerticesFixMesh*> emptyCVVec; + std::vector<CorrespVerticesFixMesh *> emptyCVVec; emptyCVVec.clear(); VertexToCorresp[elem->getVertex(j)] = emptyCVVec; } } } - for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){ - GRegion* rTmp = (*itr); - for (unsigned int i = 0; i < rTmp->tetrahedra.size();i++){ - MTetrahedron* elem = rTmp->tetrahedra[i]; - for (unsigned int j = 0; j < 4;j++){ + for(GModel::riter itr = m->firstRegion(); itr != m->lastRegion(); itr++) { + GRegion *rTmp = (*itr); + for(unsigned int i = 0; i < rTmp->tetrahedra.size(); i++) { + MTetrahedron *elem = rTmp->tetrahedra[i]; + for(unsigned int j = 0; j < 4; j++) { VertexToTets[elem->getVertex(j)].push_back(elem); } } } } -static void setLcsFM(MTriangle *t, std::map<MVertex*, double> &vSizes, - std::set<MVertex*> &bndVertices) +static void setLcsFM(MTriangle *t, std::map<MVertex *, double> &vSizes, + std::set<MVertex *> &bndVertices) { - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { bndVertices.insert(t->getVertex(i)); MEdge e = t->getEdge(i); MVertex *vi = e.getVertex(0); MVertex *vj = e.getVertex(1); - double dx = vi->x()-vj->x(); - double dy = vi->y()-vj->y(); - double dz = vi->z()-vj->z(); + double dx = vi->x() - vj->x(); + double dy = vi->y() - vj->y(); + double dz = vi->z() - vj->z(); double l = sqrt(dx * dx + dy * dy + dz * dz); - std::map<MVertex*,double>::iterator iti = vSizes.find(vi); - std::map<MVertex*,double>::iterator itj = vSizes.find(vj); + std::map<MVertex *, double>::iterator iti = vSizes.find(vi); + std::map<MVertex *, double>::iterator itj = vSizes.find(vj); // use largest edge length - if (iti == vSizes.end() || iti->second < l) vSizes[vi] = l; - if (itj == vSizes.end() || itj->second < l) vSizes[vj] = l; + if(iti == vSizes.end() || iti->second < l) vSizes[vi] = l; + if(itj == vSizes.end() || itj->second < l) vSizes[vj] = l; } } -static void setLcsFM(MTetrahedron *t, std::map<MVertex*, double> &vSizes, - std::set<MVertex*> &bndVertices) +static void setLcsFM(MTetrahedron *t, std::map<MVertex *, double> &vSizes, + std::set<MVertex *> &bndVertices) { - for (int i = 0; i < 4; i++){ - for (int j = i + 1; j < 4; j++){ + for(int i = 0; i < 4; i++) { + for(int j = i + 1; j < 4; j++) { MVertex *vi = t->getVertex(i); MVertex *vj = t->getVertex(j); - double dx = vi->x()-vj->x(); - double dy = vi->y()-vj->y(); - double dz = vi->z()-vj->z(); + double dx = vi->x() - vj->x(); + double dy = vi->y() - vj->y(); + double dz = vi->z() - vj->z(); double l = sqrt(dx * dx + dy * dy + dz * dz); - std::map<MVertex*,double>::iterator iti = vSizes.find(vi); - std::map<MVertex*,double>::iterator itj = vSizes.find(vj); - std::set<MVertex*>::iterator itvi = bndVertices.find(vi); - std::set<MVertex*>::iterator itvj = bndVertices.find(vj); + std::map<MVertex *, double>::iterator iti = vSizes.find(vi); + std::map<MVertex *, double>::iterator itj = vSizes.find(vj); + std::set<MVertex *>::iterator itvi = bndVertices.find(vi); + std::set<MVertex *>::iterator itvj = bndVertices.find(vj); // smallest tet edge - if (itvi == bndVertices.end() && - (iti == vSizes.end() || iti->second > l)) vSizes[vi] = l; - if (itvj == bndVertices.end() && - (itj == vSizes.end() || itj->second > l)) vSizes[vj] = l; + if(itvi == bndVertices.end() && (iti == vSizes.end() || iti->second > l)) + vSizes[vi] = l; + if(itvj == bndVertices.end() && (itj == vSizes.end() || itj->second > l)) + vSizes[vj] = l; } } } -void GMSH_ThinLayerFixMeshPlugin::fillTetToTet4(){ +void GMSH_ThinLayerFixMeshPlugin::fillTetToTet4() +{ GModel *m = GModel::current(); std::vector<double> vSizes; std::vector<double> vSizesBGM; MTet4Factory myFactory(1600000); - std::set<MTet4*, compareTet4Ptr> &allTets = myFactory.getAllTets(); - std::set<MTet4*, compareTet4Ptr> activeTets; + std::set<MTet4 *, compareTet4Ptr> &allTets = myFactory.getAllTets(); + std::set<MTet4 *, compareTet4Ptr> activeTets; int NUM = 0; - for (GModel::riter itr= m->firstRegion();itr != m->lastRegion();itr++){ - GRegion* gr = (*itr); + for(GModel::riter itr = m->firstRegion(); itr != m->lastRegion(); itr++) { + GRegion *gr = (*itr); { // leave this in a block so the map gets deallocated directly - std::map<MVertex*, double> vSizesMap; - std::set<MVertex*> bndVertices; - for(GModel::fiter it = gr->model()->firstFace(); it != gr->model()->lastFace(); ++it){ + std::map<MVertex *, double> vSizesMap; + std::set<MVertex *> bndVertices; + for(GModel::fiter it = gr->model()->firstFace(); + it != gr->model()->lastFace(); ++it) { GFace *gf = *it; - for(unsigned int i = 0; i < gf->triangles.size(); i++){ + for(unsigned int i = 0; i < gf->triangles.size(); i++) { setLcsFM(gf->triangles[i], vSizesMap, bndVertices); } } for(unsigned int i = 0; i < gr->tetrahedra.size(); i++) setLcsFM(gr->tetrahedra[i], vSizesMap, bndVertices); - for(std::map<MVertex*, double>::iterator it = vSizesMap.begin(); - it != vSizesMap.end(); ++it){ + for(std::map<MVertex *, double>::iterator it = vSizesMap.begin(); + it != vSizesMap.end(); ++it) { it->first->setIndex(NUM++); vSizes.push_back(it->second); vSizesBGM.push_back(it->second); } } - for(unsigned int i = 0; i < gr->tetrahedra.size(); i++) - { - MTet4* currentTet4 = myFactory.Create(gr->tetrahedra[i], vSizes,vSizesBGM); - TetToTet4[gr->tetrahedra[i]] = currentTet4; - allTets.insert(currentTet4); - } + for(unsigned int i = 0; i < gr->tetrahedra.size(); i++) { + MTet4 *currentTet4 = + myFactory.Create(gr->tetrahedra[i], vSizes, vSizesBGM); + TetToTet4[gr->tetrahedra[i]] = currentTet4; + allTets.insert(currentTet4); + } } - - std::vector<MTet4*> vecAllTet4; + std::vector<MTet4 *> vecAllTet4; vecAllTet4.clear(); - for (std::set<MTet4*, compareTet4Ptr>::iterator itTp = allTets.begin();itTp != allTets.end();itTp++){ + for(std::set<MTet4 *, compareTet4Ptr>::iterator itTp = allTets.begin(); + itTp != allTets.end(); itTp++) { vecAllTet4.push_back((*itTp)); // //std::cout<<"inserted "<<(*itTp)->tet()->getNum()<<std::endl; } connectTets(vecAllTet4); - - // GModel *m = GModel::current(); // std::vector<MTet4*> vecAllTet4; // vecAllTet4.clear(); @@ -1153,11 +1531,13 @@ void GMSH_ThinLayerFixMeshPlugin::fillTetToTet4(){ /****************static declarations****************/ -std::map<MVertex*,std::vector<MTetrahedron*> > GMSH_ThinLayerFixMeshPlugin::VertexToTets; -std::map<MTetrahedron*,MTet4*> GMSH_ThinLayerFixMeshPlugin::TetToTet4; -std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> > GMSH_ThinLayerFixMeshPlugin::VertexToCorresp; -std::vector<std::vector<CorrespVerticesFixMesh*> > GMSH_ThinLayerFixMeshPlugin::vecOfThinSheets; - +std::map<MVertex *, std::vector<MTetrahedron *> > + GMSH_ThinLayerFixMeshPlugin::VertexToTets; +std::map<MTetrahedron *, MTet4 *> GMSH_ThinLayerFixMeshPlugin::TetToTet4; +std::map<MVertex *, std::vector<CorrespVerticesFixMesh *> > + GMSH_ThinLayerFixMeshPlugin::VertexToCorresp; +std::vector<std::vector<CorrespVerticesFixMesh *> > + GMSH_ThinLayerFixMeshPlugin::vecOfThinSheets; #else diff --git a/Plugin/ThinLayerFixMesh.h b/Plugin/ThinLayerFixMesh.h index 934f63638dc7b5a817bbb245e4349fb858b2e7b1..8c46b214423fb4846fb8b1e8120a923a1e6cdee7 100644 --- a/Plugin/ThinLayerFixMesh.h +++ b/Plugin/ThinLayerFixMesh.h @@ -15,26 +15,27 @@ #include "meshGRegionDelaunayInsertion.h" #endif -extern "C" -{ - GMSH_Plugin *GMSH_RegisterThinLayerFixMeshPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterThinLayerFixMeshPlugin(); } #if defined(HAVE_MESH) -static int faces[4][3] = {{0,1,2}, {0,2,3}, {0,3,1}, {1,3,2}}; +static int faces[4][3] = {{0, 1, 2}, {0, 2, 3}, {0, 3, 1}, {1, 3, 2}}; -struct faceXtetFM{ - MVertex *v[3],*unsorted[3]; +struct faceXtetFM { + MVertex *v[3], *unsorted[3]; MTet4 *t1; int i1; - faceXtetFM(MTet4 *_t=0, int iFac=0) : t1(_t), i1(iFac) + faceXtetFM(MTet4 *_t = 0, int iFac = 0) : t1(_t), i1(iFac) { // std::cout<<"entering faceXTet"<<std::endl; // std::cout<<"tag of tet is "<<t1->tet()->getNum()<<std::endl; - // std::cout<<"first vec of tet is "<<t1->tet()->getVertex(0)->getNum()<<std::endl; - // std::cout<<"second vec of tet is "<<t1->tet()->getVertex(1)->getNum()<<std::endl; - // std::cout<<"third vec of tet is "<<t1->tet()->getVertex(2)->getNum()<<std::endl; - // std::cout<<"fourth vec of tet is "<<t1->tet()->getVertex(3)->getNum()<<std::endl; + // std::cout<<"first vec of tet is + //"<<t1->tet()->getVertex(0)->getNum()<<std::endl; std::cout<<"second vec + //of tet is "<<t1->tet()->getVertex(1)->getNum()<<std::endl; + // std::cout<<"third vec of tet is + //"<<t1->tet()->getVertex(2)->getNum()<<std::endl; std::cout<<"fourth vec + //of tet is "<<t1->tet()->getVertex(3)->getNum()<<std::endl; MVertex *v0 = t1->tet()->getVertex(faces[iFac][0]); // std::cout<<"after first vert"<<std::endl; MVertex *v1 = t1->tet()->getVertex(faces[iFac][1]); @@ -49,55 +50,55 @@ struct faceXtetFM{ unsorted[2] = v2; // std::cout<<"after third unsorted"<<std::endl; - v[0] = std::min(std::min(v0,v1),v2); + v[0] = std::min(std::min(v0, v1), v2); // std::cout<<"after min"<<std::endl; - v[2] = std::max(std::max(v0,v1),v2); + v[2] = std::max(std::max(v0, v1), v2); // std::cout<<"after max"<<std::endl; - v[1] = (v0 != v[0] && v0 != v[2]) ? v0 : (v1 != v[0] && v1 != v[2]) ? v1 : v2; + v[1] = + (v0 != v[0] && v0 != v[2]) ? v0 : (v1 != v[0] && v1 != v[2]) ? v1 : v2; // std::cout<<"after minimax"<<std::endl; // // std::sort(v, v + 3); } - inline MVertex * getVertex (int i) const { return unsorted[i];} + inline MVertex *getVertex(int i) const { return unsorted[i]; } - inline bool operator < (const faceXtetFM & other) const + inline bool operator<(const faceXtetFM &other) const { - if (v[0] < other.v[0]) return true; - if (v[0] > other.v[0]) return false; - if (v[1] < other.v[1]) return true; - if (v[1] > other.v[1]) return false; - if (v[2] < other.v[2]) return true; + if(v[0] < other.v[0]) return true; + if(v[0] > other.v[0]) return false; + if(v[1] < other.v[1]) return true; + if(v[1] > other.v[1]) return false; + if(v[2] < other.v[2]) return true; return false; } - inline bool operator == (const faceXtetFM & other) const + inline bool operator==(const faceXtetFM &other) const { - return (v[0] == other.v[0] && - v[1] == other.v[1] && - v[2] == other.v[2] ); + return (v[0] == other.v[0] && v[1] == other.v[1] && v[2] == other.v[2]); } - bool visible (MVertex *v){ - MVertex* v0 = t1->tet()->getVertex(faces[i1][0]); - MVertex* v1 = t1->tet()->getVertex(faces[i1][1]); - MVertex* v2 = t1->tet()->getVertex(faces[i1][2]); - double a[3] = {v0->x(),v0->y(),v0->z()}; - double b[3] = {v1->x(),v1->y(),v1->z()}; - double c[3] = {v2->x(),v2->y(),v2->z()}; - double d[3] = {v->x(),v->y(),v->z()}; - double o = robustPredicates :: orient3d(a,b,c,d); + bool visible(MVertex *v) + { + MVertex *v0 = t1->tet()->getVertex(faces[i1][0]); + MVertex *v1 = t1->tet()->getVertex(faces[i1][1]); + MVertex *v2 = t1->tet()->getVertex(faces[i1][2]); + double a[3] = {v0->x(), v0->y(), v0->z()}; + double b[3] = {v1->x(), v1->y(), v1->z()}; + double c[3] = {v2->x(), v2->y(), v2->z()}; + double d[3] = {v->x(), v->y(), v->z()}; + double o = robustPredicates ::orient3d(a, b, c, d); return o < 0; } }; -class CorrespVerticesFixMesh{ +class CorrespVerticesFixMesh { private: - MVertex* StartPoint; + MVertex *StartPoint; SPoint3 EndPoint; SVector3 StartNormal; SVector3 EndNormal; - MVertex* EndTrianglePoint1; - MVertex* EndTrianglePoint2; - MVertex* EndTrianglePoint3; + MVertex *EndTrianglePoint1; + MVertex *EndTrianglePoint2; + MVertex *EndTrianglePoint3; // faceXtetFM EndTriangle; double distP2P; double angleProd; @@ -105,31 +106,32 @@ private: bool EndTriangleActive; bool IsMaster; int tagMaster; + public: CorrespVerticesFixMesh(); ~CorrespVerticesFixMesh(); - void setStartPoint(MVertex* v); + void setStartPoint(MVertex *v); void setEndPoint(SPoint3 p); void setStartNormal(SVector3 v); void setEndNormal(SVector3 v); // void setEndTriangle(faceXtetFM f); - void setEndTrianglePoint1(MVertex* v); - void setEndTrianglePoint2(MVertex* v); - void setEndTrianglePoint3(MVertex* v); + void setEndTrianglePoint1(MVertex *v); + void setEndTrianglePoint2(MVertex *v); + void setEndTrianglePoint3(MVertex *v); void setdistP2P(double d); void setangleProd(double a); void setActive(bool b); void setEndTriangleActive(bool b); void setIsMaster(bool b); void setTagMaster(int i); - MVertex* getStartPoint(); + MVertex *getStartPoint(); SPoint3 getEndPoint(); SVector3 getStartNormal(); SVector3 getEndNormal(); // faceXtetFM getEndTriangle(); - MVertex* getEndTrianglePoint1(); - MVertex* getEndTrianglePoint2(); - MVertex* getEndTrianglePoint3(); + MVertex *getEndTrianglePoint1(); + MVertex *getEndTrianglePoint2(); + MVertex *getEndTrianglePoint3(); double getdistP2P(); double getangleProd(); bool getActive(); @@ -139,36 +141,33 @@ public: }; #endif -class GMSH_ThinLayerFixMeshPlugin : public GMSH_PostPlugin -{ +class GMSH_ThinLayerFixMeshPlugin : public GMSH_PostPlugin { private: public: - GMSH_ThinLayerFixMeshPlugin(){} + GMSH_ThinLayerFixMeshPlugin() {} //~GMSH_ThinLayerFixMeshPlugin(); std::string getName() const { return "ThinLayerFixMesh"; } - std::string getShortHelp() const - { - return "Fix the mesh in thin parts"; - } + std::string getShortHelp() const { return "Fix the mesh in thin parts"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); #if defined(HAVE_MESH) static void perform(); static void checkOppositeTriangles(); static void fillvecOfThinSheets(); - static std::map<MVertex*,double> computeAllDistToOppSide(); - static double computeDistToOppSide(MVertex* v); - static SVector3 computeInteriorNormal(MVertex* v); - static MTet4* getTetFromPoint(MVertex* v, SVector3 InteriorNormal); + static std::map<MVertex *, double> computeAllDistToOppSide(); + static double computeDistToOppSide(MVertex *v); + static SVector3 computeInteriorNormal(MVertex *v); + static MTet4 *getTetFromPoint(MVertex *v, SVector3 InteriorNormal); static bool IsPositivOrientation(SVector3 a, SVector3 b, SVector3 c); - static void FindNewPoint(SPoint3* CurrentPoint, int* CurrentTri, - MTet4** CurrentTet, SVector3 InteriorNormal); - static std::map<MVertex*,std::vector<MTetrahedron*> > VertexToTets; - static std::map<MTetrahedron*,MTet4*> TetToTet4; - static std::map<MVertex*,std::vector<CorrespVerticesFixMesh*> > VertexToCorresp; - static std::vector<std::vector<CorrespVerticesFixMesh*> > vecOfThinSheets; + static void FindNewPoint(SPoint3 *CurrentPoint, int *CurrentTri, + MTet4 **CurrentTet, SVector3 InteriorNormal); + static std::map<MVertex *, std::vector<MTetrahedron *> > VertexToTets; + static std::map<MTetrahedron *, MTet4 *> TetToTet4; + static std::map<MVertex *, std::vector<CorrespVerticesFixMesh *> > + VertexToCorresp; + static std::vector<std::vector<CorrespVerticesFixMesh *> > vecOfThinSheets; static const double epsilon; static const double angleMax; static const double distP2PMax; diff --git a/Plugin/Transform.cpp b/Plugin/Transform.cpp index ccf17bcb962151abc1328f8b7d48672caf5609d0..269074b7ba1393dc0a856f37cf427a901bca0522 100644 --- a/Plugin/Transform.cpp +++ b/Plugin/Transform.cpp @@ -19,29 +19,27 @@ StringXNumber TransformOptions_Number[] = { {GMSH_FULLRC, "Ty", NULL, 0.}, // cannot use T2 (reserved token in parser) {GMSH_FULLRC, "Tz", NULL, 0.}, // cannot use T3 (reserved token in parser) {GMSH_FULLRC, "SwapOrientation", NULL, 0.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterTransformPlugin() { - GMSH_Plugin *GMSH_RegisterTransformPlugin() - { - return new GMSH_TransformPlugin(); - } + return new GMSH_TransformPlugin(); +} } std::string GMSH_TransformPlugin::getHelp() const { return "Plugin(Transform) transforms the homogeneous " - "node coordinates (x,y,z,1) of the elements in " - "the view `View' by the matrix\n\n" - "[`A11' `A12' `A13' `Tx']\n" - "[`A21' `A22' `A23' `Ty']\n" - "[`A31' `A32' `A33' `Tz'].\n\n" - "If `SwapOrientation' is set, the orientation of the " - "elements is reversed.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Transform) is executed in-place."; + "node coordinates (x,y,z,1) of the elements in " + "the view `View' by the matrix\n\n" + "[`A11' `A12' `A13' `Tx']\n" + "[`A21' `A22' `A23' `Ty']\n" + "[`A31' `A32' `A33' `Tz'].\n\n" + "If `SwapOrientation' is set, the orientation of the " + "elements is reversed.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Transform) is executed in-place."; } int GMSH_TransformPlugin::getNbOptions() const @@ -80,11 +78,11 @@ PView *GMSH_TransformPlugin::execute(PView *v) PViewData *data1 = v1->getData(); - if(data1->isNodeData()){ + if(data1->isNodeData()) { // tag all the nodes with "0" (the default tag) - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; if(swap) data1->reverseElement(step, ent, ele); for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) @@ -95,11 +93,11 @@ PView *GMSH_TransformPlugin::execute(PView *v) } // transform all "0" nodes - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; - for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) { double x, y, z; int tag = data1->getNode(step, ent, ele, nod, x, y, z); if(data1->isNodeData() && tag) continue; diff --git a/Plugin/Transform.h b/Plugin/Transform.h index 0389b6d038b763c919116e0131a8eb27c6936d5a..f5b844bb5b9f4a87e1ea1a2632172de68809d94d 100644 --- a/Plugin/Transform.h +++ b/Plugin/Transform.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterTransformPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterTransformPlugin(); } -class GMSH_TransformPlugin : public GMSH_PostPlugin -{ - public: - GMSH_TransformPlugin(){} +class GMSH_TransformPlugin : public GMSH_PostPlugin { +public: + GMSH_TransformPlugin() {} std::string getName() const { return "Transform"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_TransformPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/Triangulate.cpp b/Plugin/Triangulate.cpp index a8b234cb5186c9954d52f2d2300bb9d299a61841..6c5a4ece8204752f17c86aad4cb52fc231fddf41 100644 --- a/Plugin/Triangulate.cpp +++ b/Plugin/Triangulate.cpp @@ -19,27 +19,24 @@ #endif StringXNumber TriangulateOptions_Number[] = { - {GMSH_FULLRC, "Algorithm", NULL, 0.}, - {GMSH_FULLRC, "View", NULL, -1.} -}; + {GMSH_FULLRC, "Algorithm", NULL, 0.}, {GMSH_FULLRC, "View", NULL, -1.}}; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterTriangulatePlugin() { - GMSH_Plugin *GMSH_RegisterTriangulatePlugin() - { - return new GMSH_TriangulatePlugin(); - } + return new GMSH_TriangulatePlugin(); +} } std::string GMSH_TriangulatePlugin::getHelp() const { return "Plugin(Triangulate) triangulates the points in the " - "view `View', assuming that all the points belong " - "to a surface that can be projected one-to-one " - "onto a plane. Algorithm selects the old (0) or new (1) " - "meshing algorithm.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "Plugin(Triangulate) creates one new view."; + "view `View', assuming that all the points belong " + "to a surface that can be projected one-to-one " + "onto a plane. Algorithm selects the old (0) or new (1) " + "meshing algorithm.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "Plugin(Triangulate) creates one new view."; } int GMSH_TriangulatePlugin::getNbOptions() const @@ -55,10 +52,9 @@ StringXNumber *GMSH_TriangulatePlugin::getOption(int iopt) #if defined(HAVE_MESH) class PointData : public MVertex { - public: +public: std::vector<double> v; - PointData(double x, double y, double z, int numVal) - : MVertex(x, y, z) + PointData(double x, double y, double z, int numVal) : MVertex(x, y, z) { v.resize(3 + numVal); v[0] = x; @@ -76,16 +72,16 @@ PView *GMSH_TriangulatePlugin::execute(PView *v) if(!v1) return v; PViewData *data1 = v1->getData(); - if(data1->hasMultipleMeshes()){ + if(data1->hasMultipleMeshes()) { Msg::Error("Triangulate plugin cannot be applied to multi-mesh views"); return v1; } // create list of points with associated data - std::vector<MVertex*> points; + std::vector<MVertex *> points; int numSteps = data1->getNumTimeSteps(); - for(int ent = 0; ent < data1->getNumEntities(0); ent++){ - for(int ele = 0; ele < data1->getNumElements(0, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(0); ent++) { + for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) { if(data1->skipElement(0, ent, ele)) continue; if(data1->getNumNodes(0, ent, ele) != 1) continue; int numComp = data1->getNumComponents(0, ent, ele); @@ -94,12 +90,13 @@ PView *GMSH_TriangulatePlugin::execute(PView *v) PointData *p = new PointData(x, y, z, numComp * numSteps); for(int step = 0; step < numSteps; step++) for(int comp = 0; comp < numComp; comp++) - data1->getValue(step, ent, ele, 0, comp, p->v[3 + numComp * step + comp]); + data1->getValue(step, ent, ele, 0, comp, + p->v[3 + numComp * step + comp]); points.push_back(p); } } - if(points.size() < 3){ + if(points.size() < 3) { Msg::Error("Need at least 3 points to triangulate"); for(unsigned int i = 0; i < points.size(); i++) delete points[i]; return v1; @@ -111,13 +108,14 @@ PView *GMSH_TriangulatePlugin::execute(PView *v) double lc = 10 * norm(SVector3(bbox.max(), bbox.min())); // project points onto plane - discreteFace *s = new discreteFace - (GModel::current(), GModel::current()->getNumFaces() + 1); + discreteFace *s = + new discreteFace(GModel::current(), GModel::current()->getNumFaces() + 1); s->computeMeanPlane(points); double x, y, z, VX[3], VY[3]; s->getMeanPlaneData(VX, VY, x, y, z); for(unsigned int i = 0; i < points.size(); i++) { - double vec[3] = {points[i]->x() - x, points[i]->y() - y, points[i]->z() - z}; + double vec[3] = {points[i]->x() - x, points[i]->y() - y, + points[i]->z() - z}; double u = prosca(vec, VX); double v = prosca(vec, VY); points[i]->x() = u; @@ -129,57 +127,64 @@ PView *GMSH_TriangulatePlugin::execute(PView *v) PView *v2; PViewDataList *data2; - if(algo == 0) {// using old code + if(algo == 0) { // using old code // build a point record structure for the divide and conquer algorithm DocRecord doc(points.size()); - for(unsigned int i = 0; i < points.size(); i++){ - double XX = CTX::instance()->mesh.randFactor * lc * (double)rand() / (double)RAND_MAX; - double YY = CTX::instance()->mesh.randFactor * lc * (double)rand() / (double)RAND_MAX; + for(unsigned int i = 0; i < points.size(); i++) { + double XX = CTX::instance()->mesh.randFactor * lc * (double)rand() / + (double)RAND_MAX; + double YY = CTX::instance()->mesh.randFactor * lc * (double)rand() / + (double)RAND_MAX; doc.points[i].where.h = points[i]->x() + XX; doc.points[i].where.v = points[i]->y() + YY; doc.points[i].adjacent = NULL; - doc.points[i].data = (void*)points[i]; + doc.points[i].data = (void *)points[i]; } // triangulate - try{ + try { doc.MakeMeshWithPoints(); - } - catch(const char *err){ + } catch(const char *err) { Msg::Error("%s", err); } // create output (using unperturbed data) v2 = new PView(); data2 = getDataList(v2); - for(int i = 0; i < doc.numTriangles; i++){ + for(int i = 0; i < doc.numTriangles; i++) { int a = doc.triangles[i].a; int b = doc.triangles[i].b; int c = doc.triangles[i].c; int n = doc.numPoints; - if(a < 0 || a >= n || b < 0 || b >= n || c < 0 || c >= n){ + if(a < 0 || a >= n || b < 0 || b >= n || c < 0 || c >= n) { Msg::Warning("Skipping bad triangle %d", i); continue; } PointData *p[3]; - p[0] = (PointData*)doc.points[doc.triangles[i].a].data; - p[1] = (PointData*)doc.points[doc.triangles[i].b].data; - p[2] = (PointData*)doc.points[doc.triangles[i].c].data; + p[0] = (PointData *)doc.points[doc.triangles[i].a].data; + p[1] = (PointData *)doc.points[doc.triangles[i].b].data; + p[2] = (PointData *)doc.points[doc.triangles[i].c].data; int numComp = 0; std::vector<double> *vec = 0; if((int)p[0]->v.size() == 3 + 9 * numSteps && (int)p[1]->v.size() == 3 + 9 * numSteps && - (int)p[2]->v.size() == 3 + 9 * numSteps){ - numComp = 9; data2->NbTT++; vec = &data2->TT; + (int)p[2]->v.size() == 3 + 9 * numSteps) { + numComp = 9; + data2->NbTT++; + vec = &data2->TT; } else if((int)p[0]->v.size() == 3 + 3 * numSteps && (int)p[1]->v.size() == 3 + 3 * numSteps && - (int)p[2]->v.size() == 3 + 3 * numSteps){ - numComp = 3; data2->NbVT++; vec = &data2->VT; + (int)p[2]->v.size() == 3 + 3 * numSteps) { + numComp = 3; + data2->NbVT++; + vec = &data2->VT; } - else{ - numComp = 1; data2->NbST++; vec = &data2->ST; + else { + numComp = 1; + data2->NbST++; + vec = &data2->ST; } for(int nod = 0; nod < 3; nod++) vec->push_back(p[nod]->v[0]); for(int nod = 0; nod < 3; nod++) vec->push_back(p[nod]->v[1]); @@ -189,12 +194,11 @@ PView *GMSH_TriangulatePlugin::execute(PView *v) for(int comp = 0; comp < numComp; comp++) vec->push_back(p[nod]->v[3 + numComp * step + comp]); } - } - else{ // new code + else { // new code Msg::Info("Using new triangulation code"); - std::vector<MTriangle*> tris; + std::vector<MTriangle *> tris; for(unsigned int i = 0; i < points.size(); i++) { double XX = 1.e-12 * lc * (double)rand() / (double)RAND_MAX; double YY = 1.e-12 * lc * (double)rand() / (double)RAND_MAX; @@ -205,25 +209,31 @@ PView *GMSH_TriangulatePlugin::execute(PView *v) v2 = new PView(); data2 = getDataList(v2); - for(unsigned int i = 0; i < tris.size(); i++){ + for(unsigned int i = 0; i < tris.size(); i++) { PointData *p[3]; - p[0] = (PointData*)tris[i]->getVertex(0); - p[1] = (PointData*)tris[i]->getVertex(1); - p[2] = (PointData*)tris[i]->getVertex(2); + p[0] = (PointData *)tris[i]->getVertex(0); + p[1] = (PointData *)tris[i]->getVertex(1); + p[2] = (PointData *)tris[i]->getVertex(2); int numComp = 0; std::vector<double> *vec = 0; if((int)p[0]->v.size() == 3 + 9 * numSteps && (int)p[1]->v.size() == 3 + 9 * numSteps && - (int)p[2]->v.size() == 3 + 9 * numSteps){ - numComp = 9; data2->NbTT++; vec = &data2->TT; + (int)p[2]->v.size() == 3 + 9 * numSteps) { + numComp = 9; + data2->NbTT++; + vec = &data2->TT; } else if((int)p[0]->v.size() == 3 + 3 * numSteps && (int)p[1]->v.size() == 3 + 3 * numSteps && - (int)p[2]->v.size() == 3 + 3 * numSteps){ - numComp = 3; data2->NbVT++; vec = &data2->VT; + (int)p[2]->v.size() == 3 + 3 * numSteps) { + numComp = 3; + data2->NbVT++; + vec = &data2->VT; } - else{ - numComp = 1; data2->NbST++; vec = &data2->ST; + else { + numComp = 1; + data2->NbST++; + vec = &data2->ST; } for(int nod = 0; nod < 3; nod++) vec->push_back(p[nod]->v[0]); for(int nod = 0; nod < 3; nod++) vec->push_back(p[nod]->v[1]); @@ -234,11 +244,9 @@ PView *GMSH_TriangulatePlugin::execute(PView *v) vec->push_back(p[nod]->v[3 + numComp * step + comp]); delete tris[i]; } - } - for(unsigned int i = 0; i < points.size(); i++) - delete points[i]; + for(unsigned int i = 0; i < points.size(); i++) delete points[i]; for(int i = 0; i < data1->getNumTimeSteps(); i++) data2->Time.push_back(data1->getTime(i)); diff --git a/Plugin/Triangulate.h b/Plugin/Triangulate.h index 588af39a44ab98043729747ea9e9e3d804c536a5..b11c30cd117735578f10ed0845b6dfcd06e3889b 100644 --- a/Plugin/Triangulate.h +++ b/Plugin/Triangulate.h @@ -8,23 +8,18 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterTriangulatePlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterTriangulatePlugin(); } -class GMSH_TriangulatePlugin : public GMSH_PostPlugin -{ - public: - GMSH_TriangulatePlugin(){} +class GMSH_TriangulatePlugin : public GMSH_PostPlugin { +public: + GMSH_TriangulatePlugin() {} std::string getName() const { return "Triangulate"; } - std::string getShortHelp() const - { - return "Mesh 2D point cloud"; - } + std::string getShortHelp() const { return "Mesh 2D point cloud"; } std::string getHelp() const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/VoroMetal.cpp b/Plugin/VoroMetal.cpp index f7f80d361458bf993852404f116ac9bd3f89c9d0..20810f1f0ffaea8afbc5fde53dd38028f967f59f 100644 --- a/Plugin/VoroMetal.cpp +++ b/Plugin/VoroMetal.cpp @@ -17,24 +17,23 @@ StringXNumber VoroMetalOptions_Number[] = { {GMSH_FULLRC, "ComputeBestSeeds", NULL, 0.}, - {GMSH_FULLRC, "ComputeMicrostructure", NULL, 1.} -}; + {GMSH_FULLRC, "ComputeMicrostructure", NULL, 1.}}; StringXString VoroMetalOptions_String[] = { {GMSH_FULLRC, "SeedsFile", NULL, "seeds.txt"}, }; -extern "C" +extern "C" { +GMSH_Plugin *GMSH_RegisterVoroMetalPlugin() { - GMSH_Plugin *GMSH_RegisterVoroMetalPlugin() - { - return new GMSH_VoroMetalPlugin(); - } + return new GMSH_VoroMetalPlugin(); +} } std::string GMSH_VoroMetalPlugin::getHelp() const { - return "Plugin(VoroMetal) creates microstructures using Voronoi diagrams.\n\n"; + return "Plugin(VoroMetal) creates microstructures using Voronoi " + "diagrams.\n\n"; } int GMSH_VoroMetalPlugin::getNbOptions() const @@ -66,26 +65,26 @@ using namespace voro; void voroMetal3D::execute(double h) { - GRegion* gr; - GModel* model = GModel::current(); + GRegion *gr; + GModel *model = GModel::current(); GModel::riter it; - for(it = model->firstRegion(); it != model->lastRegion(); it++){ + for(it = model->firstRegion(); it != model->lastRegion(); it++) { gr = *it; - if(gr->getNumMeshElements() > 0){ + if(gr->getNumMeshElements() > 0) { execute(gr, h); } } } -void voroMetal3D::execute(GRegion* gr,double h) +void voroMetal3D::execute(GRegion *gr, double h) { - std::set<MVertex*> vertices; - std::set<MVertex*>::iterator it; + std::set<MVertex *> vertices; + std::set<MVertex *>::iterator it; - for(GRegion::size_type i = 0; i < gr->getNumMeshElements(); i++){ - MElement* element = gr->getMeshElement(i); - for(std::size_t j = 0; j < element->getNumVertices(); j++){ - MVertex* vertex = element->getVertex(j); + for(GRegion::size_type i = 0; i < gr->getNumMeshElements(); i++) { + MElement *element = gr->getMeshElement(i); + for(std::size_t j = 0; j < element->getNumVertices(); j++) { + MVertex *vertex = element->getVertex(j); vertices.insert(vertex); } } @@ -95,31 +94,33 @@ void voroMetal3D::execute(GRegion* gr,double h) std::vector<double> radii(vertices.size(), 1.0); - for(it = vertices.begin(); it != vertices.end(); it++){ - vertices2.push_back(SPoint3((*it)->x(),(*it)->y(),(*it)->z())); + for(it = vertices.begin(); it != vertices.end(); it++) { + vertices2.push_back(SPoint3((*it)->x(), (*it)->y(), (*it)->z())); } double xMax = 1.0; double yMax = 1.0; double zMax = 1.0; - execute(vertices2,radii,0,h,xMax,yMax,zMax); + execute(vertices2, radii, 0, h, xMax, yMax, zMax); } -void voroMetal3D::execute(std::vector<double>& properties, int radical, double h, - double xMax, double yMax, double zMax) +void voroMetal3D::execute(std::vector<double> &properties, int radical, + double h, double xMax, double yMax, double zMax) { unsigned int i; std::vector<SPoint3> vertices; std::vector<double> radii; - for(i = 0; i < properties.size()/4; i++){ - vertices.push_back(SPoint3(properties[4*i], properties[4*i+1], properties[4*i+2])); - radii.push_back(properties[4*i+3]); + for(i = 0; i < properties.size() / 4; i++) { + vertices.push_back( + SPoint3(properties[4 * i], properties[4 * i + 1], properties[4 * i + 2])); + radii.push_back(properties[4 * i + 3]); } execute(vertices, radii, radical, h, xMax, yMax, zMax); } -void voroMetal3D::execute(std::vector<SPoint3>& vertices, std::vector<double>& radii, - int radical, double h, double xMax, double yMax, double zMax) +void voroMetal3D::execute(std::vector<SPoint3> &vertices, + std::vector<double> &radii, int radical, double h, + double xMax, double yMax, double zMax) { unsigned int i; unsigned int j; @@ -133,24 +134,24 @@ void voroMetal3D::execute(std::vector<SPoint3>& vertices, std::vector<double>& r int last; int mem; int number; - double x,y,z; - double x1,y1,z1; - double x2,y2,z2; + double x, y, z; + double x1, y1, z1; + double x2, y2, z2; double delta; - double min_x,max_x; - double min_y,max_y; - double min_z,max_z; + double min_x, max_x; + double min_y, max_y; + double min_z, max_z; double min_area; - voronoicell_neighbor* pointer; + voronoicell_neighbor *pointer; voronoicell_neighbor cell; std::vector<int> faces; std::vector<double> voronoi_vertices; - std::vector<voronoicell_neighbor*> pointers; + std::vector<voronoicell_neighbor *> pointers; std::vector<SPoint3> generators; std::vector<int> temp; std::vector<int> temp2; std::vector<double> areas; - std::map<int,int> table; + std::map<int, int> table; geo_cell obj; min_x = 1000000000.0; @@ -159,36 +160,36 @@ void voroMetal3D::execute(std::vector<SPoint3>& vertices, std::vector<double>& r max_y = -1000000000.0; min_z = 1000000000.0; max_z = -1000000000.0; - for(i=0;i<vertices.size();i++){ - min_x = std::min(vertices[i].x(),min_x); - max_x = std::max(vertices[i].x(),max_x); - min_y = std::min(vertices[i].y(),min_y); - max_y = std::max(vertices[i].y(),max_y); - min_z = std::min(vertices[i].z(),min_z); - max_z = std::max(vertices[i].z(),max_z); + for(i = 0; i < vertices.size(); i++) { + min_x = std::min(vertices[i].x(), min_x); + max_x = std::max(vertices[i].x(), max_x); + min_y = std::min(vertices[i].y(), min_y); + max_y = std::max(vertices[i].y(), max_y); + min_z = std::min(vertices[i].z(), min_z); + max_z = std::max(vertices[i].z(), max_z); } - delta = 0.2*(max_x - min_x); - min_x=min_y=min_z = 0; + delta = 0.2 * (max_x - min_x); + min_x = min_y = min_z = 0; // max_x=max_y=max_z = 1; max_x = xMax; max_y = yMax; max_z = zMax; delta = 0; - container contA(min_x-delta, max_x+delta, min_y-delta, max_y+delta, - min_z-delta, max_z+delta, 6, 6, 6, true, true, true, + container contA(min_x - delta, max_x + delta, min_y - delta, max_y + delta, + min_z - delta, max_z + delta, 6, 6, 6, true, true, true, vertices.size()); - container_poly contB(min_x-delta, max_x+delta, min_y-delta, max_y+delta, - min_z-delta, max_z+delta, 6, 6, 6, true, true, true, - vertices.size()); + container_poly contB(min_x - delta, max_x + delta, min_y - delta, + max_y + delta, min_z - delta, max_z + delta, 6, 6, 6, + true, true, true, vertices.size()); - for(i = 0; i < vertices.size(); i++){ - if(radical==0){ - contA.put(i,vertices[i].x(),vertices[i].y(),vertices[i].z()); + for(i = 0; i < vertices.size(); i++) { + if(radical == 0) { + contA.put(i, vertices[i].x(), vertices[i].y(), vertices[i].z()); } - else{ - contB.put(i,vertices[i].x(),vertices[i].y(),vertices[i].z(),radii[i]); + else { + contB.put(i, vertices[i].x(), vertices[i].y(), vertices[i].z(), radii[i]); } } @@ -197,139 +198,139 @@ void voroMetal3D::execute(std::vector<SPoint3>& vertices, std::vector<double>& r c_loop_all loopA(contA); c_loop_all loopB(contB); - if(radical == 0){ + if(radical == 0) { loopA.start(); - do{ - contA.compute_cell(cell,loopA); - loopA.pos(x,y,z); + do { + contA.compute_cell(cell, loopA); + loopA.pos(x, y, z); pointer = new voronoicell_neighbor(); *pointer = cell; pointers.push_back(pointer); - generators.push_back(SPoint3(x,y,z)); - table.insert(std::pair<int,int>(loopA.pid(),number)); + generators.push_back(SPoint3(x, y, z)); + table.insert(std::pair<int, int>(loopA.pid(), number)); number++; } while(loopA.inc()); } - else{ + else { loopB.start(); - do{ - contB.compute_cell(cell,loopB); - loopB.pos(x,y,z); + do { + contB.compute_cell(cell, loopB); + loopB.pos(x, y, z); pointer = new voronoicell_neighbor(); *pointer = cell; pointers.push_back(pointer); - generators.push_back(SPoint3(x,y,z)); - table.insert(std::pair<int,int>(loopB.pid(),number)); + generators.push_back(SPoint3(x, y, z)); + table.insert(std::pair<int, int>(loopB.pid(), number)); number++; } while(loopB.inc()); } std::ofstream file6("table.txt"); - if(!file6.is_open()){ + if(!file6.is_open()) { Msg::Error("Could not open file 'table.txt'"); return; } - for(i = 0; i < vertices.size(); i++){ - file6 << i+1 << " " << table[i]+1 << "\n"; + for(i = 0; i < vertices.size(); i++) { + file6 << i + 1 << " " << table[i] + 1 << "\n"; } initialize_counter(); min_area = 1000000000.0; - for(i = 0; i < pointers.size(); i++){ + for(i = 0; i < pointers.size(); i++) { areas.clear(); pointers[i]->face_areas(areas); - for(j = 0; j < areas.size(); j++){ - if(areas[j] < min_area){ + for(j = 0; j < areas.size(); j++) { + if(areas[j] < min_area) { min_area = areas[j]; } } } std::ofstream file("MicrostructurePolycrystal3D.pos"); - if(!file.is_open()){ + if(!file.is_open()) { Msg::Error("Could not open file 'MicrostructurePolycrystal3D.pos'"); return; } file << "View \"test\" {\n"; std::ofstream file2("MicrostructurePolycrystal3D.geo"); - if(!file2.is_open()){ + if(!file2.is_open()) { Msg::Error("Could not open file 'MicrostructurePolycrystal3D.geo'"); return; } std::ofstream file5("SET.map"); - if(!file5.is_open()){ + if(!file5.is_open()) { Msg::Error("Could not open file 'SET.map'"); return; } file2 << "c=" << h << ";\n"; - int countPeriodSurf=0; - int countVolume=0; - for(i = 0; i < pointers.size(); i++){ + int countPeriodSurf = 0; + int countVolume = 0; + for(i = 0; i < pointers.size(); i++) { obj = geo_cell(); faces.clear(); voronoi_vertices.clear(); pointers[i]->face_vertices(faces); - pointers[i]->vertices(generators[i].x(), generators[i].y(), generators[i].z(), - voronoi_vertices); + pointers[i]->vertices(generators[i].x(), generators[i].y(), + generators[i].z(), voronoi_vertices); obj.line_loops.resize(pointers[i]->number_of_faces()); obj.orientations.resize(pointers[i]->number_of_faces()); face_number = 0; end = 0; - while(end < faces.size()){ + while(end < faces.size()) { start = end + 1; end = start + faces[end]; - for(j=start;j<end;j++){ - if(j<end-1){ + for(j = start; j < end; j++) { + if(j < end - 1) { index1 = faces[j]; - index2 = faces[j+1]; + index2 = faces[j + 1]; } - else{ - index1 = faces[end-1]; + else { + index1 = faces[end - 1]; index2 = faces[start]; } - x1 = voronoi_vertices[3*index1]; - y1 = voronoi_vertices[3*index1+1]; - z1 = voronoi_vertices[3*index1+2]; - x2 = voronoi_vertices[3*index2]; - y2 = voronoi_vertices[3*index2+1]; - z2 = voronoi_vertices[3*index2+2]; - print_segment(SPoint3(x1,y1,z1),SPoint3(x2,y2,z2),file); - - val = obj.search_line(std::pair<int,int>(index1,index2)); - if(val==-1){ - obj.lines.push_back(std::pair<int,int>(index1,index2)); - obj.line_loops[face_number].push_back(obj.lines.size()-1); - val = obj.lines.size()-1; + x1 = voronoi_vertices[3 * index1]; + y1 = voronoi_vertices[3 * index1 + 1]; + z1 = voronoi_vertices[3 * index1 + 2]; + x2 = voronoi_vertices[3 * index2]; + y2 = voronoi_vertices[3 * index2 + 1]; + z2 = voronoi_vertices[3 * index2 + 2]; + print_segment(SPoint3(x1, y1, z1), SPoint3(x2, y2, z2), file); + + val = obj.search_line(std::pair<int, int>(index1, index2)); + if(val == -1) { + obj.lines.push_back(std::pair<int, int>(index1, index2)); + obj.line_loops[face_number].push_back(obj.lines.size() - 1); + val = obj.lines.size() - 1; } - else{ + else { obj.line_loops[face_number].push_back(val); } - last = obj.line_loops[face_number].size()-1; - if(last==0){ + last = obj.line_loops[face_number].size() - 1; + if(last == 0) { obj.orientations[face_number].push_back(0); } - else if(obj.lines[obj.line_loops[face_number][last-1]].second == - obj.lines[val].first){ - obj.orientations[face_number][last-1] = 0; + else if(obj.lines[obj.line_loops[face_number][last - 1]].second == + obj.lines[val].first) { + obj.orientations[face_number][last - 1] = 0; obj.orientations[face_number].push_back(0); } - else if(obj.lines[obj.line_loops[face_number][last-1]].first == - obj.lines[val].first){ - obj.orientations[face_number][last-1] = 1; + else if(obj.lines[obj.line_loops[face_number][last - 1]].first == + obj.lines[val].first) { + obj.orientations[face_number][last - 1] = 1; obj.orientations[face_number].push_back(0); } - else if(obj.lines[obj.line_loops[face_number][last-1]].second == - obj.lines[val].second){ - obj.orientations[face_number][last-1] = 0; + else if(obj.lines[obj.line_loops[face_number][last - 1]].second == + obj.lines[val].second) { + obj.orientations[face_number][last - 1] = 0; obj.orientations[face_number].push_back(1); } - else{ - obj.orientations[face_number][last-1] = 1; + else { + obj.orientations[face_number][last - 1] = 1; obj.orientations[face_number].push_back(1); } } @@ -337,24 +338,25 @@ void voroMetal3D::execute(std::vector<SPoint3>& vertices, std::vector<double>& r face_number++; } - for(j=0;j<voronoi_vertices.size()/3;j++){ - print_geo_point(get_counter(), voronoi_vertices[3*j], voronoi_vertices[3*j+1], - voronoi_vertices[3*j+2], file2); + for(j = 0; j < voronoi_vertices.size() / 3; j++) { + print_geo_point(get_counter(), voronoi_vertices[3 * j], + voronoi_vertices[3 * j + 1], voronoi_vertices[3 * j + 2], + file2); obj.points2.push_back(get_counter()); increase_counter(); } - for(j=0;j<obj.lines.size();j++){ + for(j = 0; j < obj.lines.size(); j++) { print_geo_line(get_counter(), obj.points2[obj.lines[j].first], obj.points2[obj.lines[j].second], file2); obj.lines2.push_back(get_counter()); increase_counter(); } - for(j = 0; j < obj.line_loops.size(); j++){ + for(j = 0; j < obj.line_loops.size(); j++) { temp.clear(); temp2.clear(); - for(k = 0; k < obj.line_loops[j].size(); k++){ + for(k = 0; k < obj.line_loops[j].size(); k++) { temp.push_back(obj.lines2[obj.line_loops[j][k]]); temp2.push_back(obj.orientations[j][k]); } @@ -363,10 +365,12 @@ void voroMetal3D::execute(std::vector<SPoint3>& vertices, std::vector<double>& r increase_counter(); } - for(j = 0; j < obj.line_loops2.size(); j++){ - print_geo_face(get_counter(),obj.line_loops2[j],file2); + for(j = 0; j < obj.line_loops2.size(); j++) { + print_geo_face(get_counter(), obj.line_loops2[j], file2); countPeriodSurf++; - file5 <<get_counter()<< "\t" <<"SURFACE"<<get_counter()<<"\t"<<"NSET\n"; + file5 << get_counter() << "\t" + << "SURFACE" << get_counter() << "\t" + << "NSET\n"; obj.faces2.push_back(get_counter()); increase_counter(); } @@ -378,7 +382,9 @@ void voroMetal3D::execute(std::vector<SPoint3>& vertices, std::vector<double>& r print_geo_volume(get_counter(), obj.face_loops2, file2); mem = get_counter(); countVolume++; - file5 <<get_counter()<< "\t" <<"GRAIN"<<countVolume<<"\t"<<"ELSET\n"; + file5 << get_counter() << "\t" + << "GRAIN" << countVolume << "\t" + << "ELSET\n"; increase_counter(); print_geo_physical_volume(get_counter(), mem, file2); increase_counter(); @@ -390,102 +396,82 @@ void voroMetal3D::execute(std::vector<SPoint3>& vertices, std::vector<double>& r for(i = 0; i < pointers.size(); i++) delete pointers[i]; } -void voroMetal3D::print_segment(SPoint3 p1,SPoint3 p2,std::ofstream& file) +void voroMetal3D::print_segment(SPoint3 p1, SPoint3 p2, std::ofstream &file) { - file << "SL (" - << p1.x() << ", " << p1.y() << ", " << p1.z() << ", " - << p2.x() << ", " << p2.y() << ", " << p2.z() - << "){10, 20};\n"; + file << "SL (" << p1.x() << ", " << p1.y() << ", " << p1.z() << ", " << p2.x() + << ", " << p2.y() << ", " << p2.z() << "){10, 20};\n"; } -void voroMetal3D::initialize_counter() -{ - counter = 12; -} +void voroMetal3D::initialize_counter() { counter = 12; } -void voroMetal3D::increase_counter() -{ - counter = counter+1; -} +void voroMetal3D::increase_counter() { counter = counter + 1; } -int voroMetal3D::get_counter() -{ - return counter; -} +int voroMetal3D::get_counter() { return counter; } -void voroMetal3D::print_geo_point(int index,double x,double y,double z, - std::ofstream& file) +void voroMetal3D::print_geo_point(int index, double x, double y, double z, + std::ofstream &file) { file.precision(17); - file << "Point(" << index << ")={" - << x << "," << y << "," << z - << ",c};\n"; + file << "Point(" << index << ")={" << x << "," << y << "," << z << ",c};\n"; } -void voroMetal3D::print_geo_line(int index1,int index2,int index3, - std::ofstream& file) +void voroMetal3D::print_geo_line(int index1, int index2, int index3, + std::ofstream &file) { - file << "Line(" << index1 << ")={" - << index2 << "," << index3 - << "};\n"; + file << "Line(" << index1 << ")={" << index2 << "," << index3 << "};\n"; } -void voroMetal3D::print_geo_face(int index1,int index2,std::ofstream& file) +void voroMetal3D::print_geo_face(int index1, int index2, std::ofstream &file) { - file << "Plane Surface(" << index1 << ")={" - << index2 - << "};\n"; + file << "Plane Surface(" << index1 << ")={" << index2 << "};\n"; } -void voroMetal3D::print_geo_physical_face(int index1,int index2,std::ofstream& file) +void voroMetal3D::print_geo_physical_face(int index1, int index2, + std::ofstream &file) { - file << "Physical Surface(" << index1 << ")={" - << index2 - << "};\n"; + file << "Physical Surface(" << index1 << ")={" << index2 << "};\n"; } -void voroMetal3D::print_geo_volume(int index1,int index2,std::ofstream& file) +void voroMetal3D::print_geo_volume(int index1, int index2, std::ofstream &file) { - file << "Volume(" << index1 << ")={" - << index2 - << "};\n"; + file << "Volume(" << index1 << ")={" << index2 << "};\n"; } -void voroMetal3D::print_geo_physical_volume(int index1,int index2,std::ofstream& file) +void voroMetal3D::print_geo_physical_volume(int index1, int index2, + std::ofstream &file) { - file << "Physical Volume(" << index1 << ")={" - << index2 - << "};\n"; + file << "Physical Volume(" << index1 << ")={" << index2 << "};\n"; } -void voroMetal3D::print_geo_line_loop(int index,std::vector<int>& indices, - std::vector<int>& orientations, - std::ofstream& file) +void voroMetal3D::print_geo_line_loop(int index, std::vector<int> &indices, + std::vector<int> &orientations, + std::ofstream &file) { unsigned int i; file << "Line Loop(" << index << ")={"; - for(i = 0; i < indices.size(); i++){ - if(orientations[i]==1) file << "-"; + for(i = 0; i < indices.size(); i++) { + if(orientations[i] == 1) file << "-"; file << indices[i]; - if(i<indices.size()-1) file << ","; + if(i < indices.size() - 1) file << ","; } file << "};\n"; } -void voroMetal3D::print_geo_face_loop(int index,std::vector<int>& indices, - std::ofstream& file) +void voroMetal3D::print_geo_face_loop(int index, std::vector<int> &indices, + std::ofstream &file) { unsigned int i; file << "Surface Loop(" << index << ")={"; - for(i=0;i<indices.size();i++){ + for(i = 0; i < indices.size(); i++) { file << indices[i]; - if(i<indices.size()-1) file << ","; + if(i < indices.size() - 1) file << ","; } file << "};\n"; } -void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax) +void voroMetal3D::correspondance(double e, double xMax, double yMax, + double zMax) { unsigned int i; unsigned int j; @@ -497,50 +483,50 @@ void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax bool flag2; bool flag3; bool flag4; - double x,y,z; + double x, y, z; double delta_x; double delta_y; double delta_z; SPoint3 p1; SPoint3 p2; - GFace* gf; - GFace* gf1; - GFace* gf2; - GVertex* v1; - GVertex* v2; - GVertex* v3; - GVertex* v4; - GModel* model = GModel::current(); + GFace *gf; + GFace *gf1; + GFace *gf2; + GVertex *v1; + GVertex *v2; + GVertex *v3; + GVertex *v4; + GModel *model = GModel::current(); GModel::fiter it; - std::vector<GFace*> faces; - std::vector<std::pair<GFace*,GFace*> > pairs; + std::vector<GFace *> faces; + std::vector<std::pair<GFace *, GFace *> > pairs; std::vector<int> categories; std::vector<int> indices1; std::vector<int> indices2; std::vector<int> indices3; - std::vector<GVertex*> vertices; - std::vector<GEdge*> edges1; - std::vector<GEdge*> edges2; + std::vector<GVertex *> vertices; + std::vector<GEdge *> edges1; + std::vector<GEdge *> edges2; std::vector<int> orientations1; std::vector<int> orientations2; - std::map<GFace*,SPoint3> centers; - std::map<GFace*,bool> markings; - std::vector<GVertex*>::iterator it2; - std::map<GFace*,SPoint3>::iterator it3; - std::map<GFace*,SPoint3>::iterator it4; - std::map<GFace*,bool>::iterator it5; - std::map<GFace*,bool>::iterator it6; - std::vector<GEdge*>::iterator it7; - std::vector<GEdge*>::iterator it8; + std::map<GFace *, SPoint3> centers; + std::map<GFace *, bool> markings; + std::vector<GVertex *>::iterator it2; + std::map<GFace *, SPoint3>::iterator it3; + std::map<GFace *, SPoint3>::iterator it4; + std::map<GFace *, bool>::iterator it5; + std::map<GFace *, bool>::iterator it6; + std::vector<GEdge *>::iterator it7; + std::vector<GEdge *>::iterator it8; std::vector<int>::iterator it9; std::vector<int>::iterator it10; - std::vector<GEdge*>::iterator mem; + std::vector<GEdge *>::iterator mem; faces.clear(); - for(it = model->firstFace(); it != model->lastFace(); it++){ + for(it = model->firstFace(); it != model->lastFace(); it++) { gf = *it; - if(gf->numRegions()==1){ + if(gf->numRegions() == 1) { faces.push_back(gf); } } @@ -550,184 +536,236 @@ void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax pairs.clear(); categories.clear(); - for(i = 0; i < faces.size(); i++){ + for(i = 0; i < faces.size(); i++) { x = 0.0; y = 0.0; z = 0.0; vertices.clear(); vertices = faces[i]->vertices(); - for(it2=vertices.begin();it2!=vertices.end();it2++){ + for(it2 = vertices.begin(); it2 != vertices.end(); it2++) { x = x + (*it2)->x(); y = y + (*it2)->y(); z = z + (*it2)->z(); } - x = x/vertices.size(); - y = y/vertices.size(); - z = z/vertices.size(); - centers.insert(std::pair<GFace*,SPoint3>(faces[i],SPoint3(x,y,z))); + x = x / vertices.size(); + y = y / vertices.size(); + z = z / vertices.size(); + centers.insert(std::pair<GFace *, SPoint3>(faces[i], SPoint3(x, y, z))); } - for(i = 0; i < faces.size(); i++){ - markings.insert(std::pair<GFace*,bool>(faces[i], false)); + for(i = 0; i < faces.size(); i++) { + markings.insert(std::pair<GFace *, bool>(faces[i], false)); } count = 0; std::ofstream file("MicrostructurePolycrystal3D.pos"); - if(!file.is_open()){ + if(!file.is_open()) { Msg::Error("Could not open file 'MicrostructurePolycrystal3D.pos'"); return; } file << "View \"test\" {\n"; std::ofstream file2("PERIODIC.map"); - if(!file2.is_open()){ + if(!file2.is_open()) { Msg::Error("Could not open file 'PERIODIC.map'"); return; } - for(i = 0; i < faces.size(); i++){ - for(j = 0; j < faces.size(); j++){ + for(i = 0; i < faces.size(); i++) { + for(j = 0; j < faces.size(); j++) { it3 = centers.find(faces[i]); it4 = centers.find(faces[j]); p1 = it3->second; p2 = it4->second; - delta_x = std::abs(p2.x()-p1.x()); - delta_y = std::abs(p2.y()-p1.y()); - delta_z = std::abs(p2.z()-p1.z()); - flag = correspondance(delta_x,delta_y,delta_z,e,val,xMax,yMax,zMax); - if(flag){ + delta_x = std::abs(p2.x() - p1.x()); + delta_y = std::abs(p2.y() - p1.y()); + delta_z = std::abs(p2.z() - p1.z()); + flag = + correspondance(delta_x, delta_y, delta_z, e, val, xMax, yMax, zMax); + if(flag) { it5 = markings.find(faces[i]); it6 = markings.find(faces[j]); - if(it5->second==0 && it6->second==0){ + if(it5->second == 0 && it6->second == 0) { it5->second = 1; it6->second = 1; - pairs.push_back(std::pair<GFace*,GFace*>(faces[i],faces[j])); + pairs.push_back(std::pair<GFace *, GFace *>(faces[i], faces[j])); categories.push_back(val); - print_segment(p1,p2,file); - if (std::abs((p2.x()-p1.x()-1.0)) < 0.0001){ - if (std::abs((p2.y()-p1.y())) < 0.0001){ - if (std::abs((p2.z()-p1.z())) < 0.0001){ - file2 << "NSET\tFRONT = FRONT + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACK = BACK + SURFACE"<<faces[i]->tag()<<"\n"; + print_segment(p1, p2, file); + if(std::abs((p2.x() - p1.x() - 1.0)) < 0.0001) { + if(std::abs((p2.y() - p1.y())) < 0.0001) { + if(std::abs((p2.z() - p1.z())) < 0.0001) { + file2 << "NSET\tFRONT = FRONT + SURFACE" << faces[j]->tag() + << "\n"; + file2 << "NSET\tBACK = BACK + SURFACE" << faces[i]->tag() + << "\n"; } - else if(std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE" + << faces[i]->tag() << "\n"; } - else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tBACKTOP = BACKTOP + SURFACE" << faces[i]->tag() + << "\n"; } } - else if (std::abs((p2.y()-p1.y()-1.0))<0.0001){ - if (std::abs((p2.z()-p1.z()))<0.0001){ - file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p2.y() - p1.y() - 1.0)) < 0.0001) { + if(std::abs((p2.z() - p1.z())) < 0.0001) { + file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE" + << faces[i]->tag() << "\n"; } - else if (std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; - }else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE" + << faces[i]->tag() << "\n"; + } + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE" + << faces[i]->tag() << "\n"; } } - else if (std::abs((p1.y()-p2.y()-1.0))<0.0001){ - if (std::abs((p2.z()-p1.z()))<0.0001){ - file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p1.y() - p2.y() - 1.0)) < 0.0001) { + if(std::abs((p2.z() - p1.z())) < 0.0001) { + file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE" + << faces[i]->tag() << "\n"; } - else if (std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE" + << faces[i]->tag() << "\n"; } - else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE" + << faces[i]->tag() << "\n"; } } } - else if (std::abs((p1.x()-p2.x()-1.0))<0.0001){ - if (std::abs((p2.y()-p1.y()))<0.0001){ - if (std::abs((p2.z()-p1.z()))<0.0001){ - file2 << "NSET\tFRONT = FRONT + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACK = BACK + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p1.x() - p2.x() - 1.0)) < 0.0001) { + if(std::abs((p2.y() - p1.y())) < 0.0001) { + if(std::abs((p2.z() - p1.z())) < 0.0001) { + file2 << "NSET\tFRONT = FRONT + SURFACE" << faces[i]->tag() + << "\n"; + file2 << "NSET\tBACK = BACK + SURFACE" << faces[j]->tag() + << "\n"; } - else if(std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACKTOP = BACKTOP + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTBOTTOM = FRONTBOTTOM + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tBACKTOP = BACKTOP + SURFACE" << faces[j]->tag() + << "\n"; } - else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTTOP = FRONTTOP + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tBACKBOTTOM = BACKBOTTOM + SURFACE" + << faces[j]->tag() << "\n"; } } - else if (std::abs((p2.y()-p1.y()-1.0))<0.0001){ - if (std::abs((p2.z()-p1.z()))<0.0001){ - file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p2.y() - p1.y() - 1.0)) < 0.0001) { + if(std::abs((p2.z() - p1.z())) < 0.0001) { + file2 << "NSET\tFRONTLEFT = FRONTLEFT + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tBACKRIGHT = BACKRIGHT + SURFACE" + << faces[j]->tag() << "\n"; } - else if (std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTLEFTBOTTOM = FRONTLEFTBOTTOM + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tBACKRIGHTTOP = BACKRIGHTTOP + SURFACE" + << faces[j]->tag() << "\n"; } - else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTLEFTTOP = FRONTLEFTTOP + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tBACKRIGHTBOTTOM = BACKRIGHTBOTTOM + SURFACE" + << faces[j]->tag() << "\n"; } } - else if (std::abs((p1.y()-p2.y()-1.0))<0.0001){ - if (std::abs((p2.z()-p1.z()))<0.0001){ - file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p1.y() - p2.y() - 1.0)) < 0.0001) { + if(std::abs((p2.z() - p1.z())) < 0.0001) { + file2 << "NSET\tFRONTRIGHT = FRONTRIGHT + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tBACKLEFT = BACKLEFT + SURFACE" + << faces[j]->tag() << "\n"; } - else if (std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTRIGHTBOTTOM = FRONTRIGHTBOTTOM + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tBACKLEFTTOP = BACKLEFTTOP + SURFACE" + << faces[j]->tag() << "\n"; } - else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tFRONTRIGHTTOP = FRONTRIGHTTOP + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tBACKLEFTBOTTOM = BACKLEFTBOTTOM + SURFACE" + << faces[j]->tag() << "\n"; } } } - else if (std::abs((p1.x()-p2.x()))<0.0001){ - if (std::abs((p2.y()-p1.y()-1.0))<0.0001){ - if (std::abs((p2.z()-p1.z()))<0.0001){ - file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tLEFT = LEFT + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p1.x() - p2.x())) < 0.0001) { + if(std::abs((p2.y() - p1.y() - 1.0)) < 0.0001) { + if(std::abs((p2.z() - p1.z())) < 0.0001) { + file2 << "NSET\tRIGHT = RIGHT + SURFACE" << faces[j]->tag() + << "\n"; + file2 << "NSET\tLEFT = LEFT + SURFACE" << faces[i]->tag() + << "\n"; } - else if (std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE" + << faces[i]->tag() << "\n"; } - else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE" + << faces[j]->tag() << "\n"; + file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE" << faces[i]->tag() + << "\n"; } } - else if (std::abs((p1.y()-p2.y()-1.0))<0.0001){ - if (std::abs((p2.z()-p1.z()))<0.0001){ - file2 << "NSET\tRIGHT = RIGHT + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tLEFT = LEFT + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p1.y() - p2.y() - 1.0)) < 0.0001) { + if(std::abs((p2.z() - p1.z())) < 0.0001) { + file2 << "NSET\tRIGHT = RIGHT + SURFACE" << faces[i]->tag() + << "\n"; + file2 << "NSET\tLEFT = LEFT + SURFACE" << faces[j]->tag() + << "\n"; } - else if (std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tRIGHTBOTTOM = RIGHTBOTTOM + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tLEFTTOP = LEFTTOP + SURFACE" << faces[j]->tag() + << "\n"; } - else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tRIGHTTOP = RIGHTTOP + SURFACE" + << faces[i]->tag() << "\n"; + file2 << "NSET\tLEFTBOTTOM = LEFTBOTTOM + SURFACE" + << faces[j]->tag() << "\n"; } } - else if (std::abs((p1.y()-p2.y()))<0.0001){ - if (std::abs((p2.z()-p1.z()-1.0))<0.0001){ - file2 << "NSET\tTOP = TOP + SURFACE"<<faces[j]->tag()<<"\n"; - file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<faces[i]->tag()<<"\n"; + else if(std::abs((p1.y() - p2.y())) < 0.0001) { + if(std::abs((p2.z() - p1.z() - 1.0)) < 0.0001) { + file2 << "NSET\tTOP = TOP + SURFACE" << faces[j]->tag() << "\n"; + file2 << "NSET\tBOTTOM = BOTTOM + SURFACE" << faces[i]->tag() + << "\n"; } - else if (std::abs((p1.z()-p2.z()-1.0))<0.0001){ - file2 << "NSET\tTOP = TOP + SURFACE"<<faces[i]->tag()<<"\n"; - file2 << "NSET\tBOTTOM = BOTTOM + SURFACE"<<faces[j]->tag()<<"\n"; + else if(std::abs((p1.z() - p2.z() - 1.0)) < 0.0001) { + file2 << "NSET\tTOP = TOP + SURFACE" << faces[i]->tag() << "\n"; + file2 << "NSET\tBOTTOM = BOTTOM + SURFACE" << faces[j]->tag() + << "\n"; } } } @@ -740,15 +778,15 @@ void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax file << "};\n"; std::ofstream file3; - file3.open("MicrostructurePolycrystal3D.geo",std::ios::out | std::ios::app); - if(!file3.is_open()){ + file3.open("MicrostructurePolycrystal3D.geo", std::ios::out | std::ios::app); + if(!file3.is_open()) { Msg::Error("Could not open file 'MicrostructurePolycrystal3D.geo'"); return; } file3.precision(17); std::ofstream file4("MicrostructurePolycrystal3D2.pos"); - if(!file4.is_open()){ + if(!file4.is_open()) { Msg::Error("Could not open file 'MicrostructurePolycrystal3D2.pos'"); return; } @@ -757,29 +795,29 @@ void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax file3 << "Physical Surface(11)={"; count = 0; - for(it=model->firstFace();it!=model->lastFace();it++){ + for(it = model->firstFace(); it != model->lastFace(); it++) { gf = *it; - if(count>0) file3 << ","; + if(count > 0) file3 << ","; file3 << gf->tag(); count++; } file3 << "};\n"; - for(i = 0; i < pairs.size(); i++){ + for(i = 0; i < pairs.size(); i++) { gf1 = pairs[i].first; gf2 = pairs[i].second; - std::vector<GVertex*> gv1 = gf1->vertices(); - std::vector<GVertex*> gv2 = gf2->vertices(); - std::vector<GVertex*>::iterator it1 = gv1.begin(); - std::vector<GVertex*>::iterator it2 = gv2.begin(); - SPoint3 cg1 (0,0,0); - SPoint3 cg2 (0,0,0); - for (; it1 != gv1.end(); it1++,it2++){ - cg1 += SPoint3((*it1)->x(),(*it1)->y(),(*it1)->z()); - cg2 += SPoint3((*it2)->x(),(*it2)->y(),(*it2)->z()); + std::vector<GVertex *> gv1 = gf1->vertices(); + std::vector<GVertex *> gv2 = gf2->vertices(); + std::vector<GVertex *>::iterator it1 = gv1.begin(); + std::vector<GVertex *>::iterator it2 = gv2.begin(); + SPoint3 cg1(0, 0, 0); + SPoint3 cg2(0, 0, 0); + for(; it1 != gv1.end(); it1++, it2++) { + cg1 += SPoint3((*it1)->x(), (*it1)->y(), (*it1)->z()); + cg2 += SPoint3((*it2)->x(), (*it2)->y(), (*it2)->z()); } - SVector3 dx = (cg2-cg1) * (1./gv1.size()); + SVector3 dx = (cg2 - cg1) * (1. / gv1.size()); edges1 = gf1->edges(); edges2 = gf2->edges(); orientations1 = gf1->edgeOrientations(); @@ -791,17 +829,17 @@ void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax it9 = orientations1.begin(); it10 = orientations2.begin(); - for(it8=edges2.begin();it8!=edges2.end();it8++,it10++){ - if (*it10==1) + for(it8 = edges2.begin(); it8 != edges2.end(); it8++, it10++) { + if(*it10 == 1) indices3.push_back((*it8)->tag()); else indices3.push_back(-(*it8)->tag()); } - int countReverseEdge=0; - for(it7 = edges1.begin(); it7 != edges1.end(); it7++,it9++){ + int countReverseEdge = 0; + for(it7 = edges1.begin(); it7 != edges1.end(); it7++, it9++) { v1 = (*it7)->getBeginVertex(); v2 = (*it7)->getEndVertex(); - if (*it9==1) + if(*it9 == 1) indices1.push_back((*it7)->tag()); else indices1.push_back(-(*it7)->tag()); @@ -810,24 +848,28 @@ void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax flag3 = 0; flag4 = 0; it10 = orientations2.begin(); - for(it8=edges2.begin();it8!=edges2.end();it8++,it10++){ + for(it8 = edges2.begin(); it8 != edges2.end(); it8++, it10++) { v3 = (*it8)->getBeginVertex(); v4 = (*it8)->getEndVertex(); - correspondance(fabs(v3->x()-v1->x()),fabs(v3->y()-v1->y()),fabs(v3->z()-v1->z()), - e,categories[i],flag1,xMax,yMax,zMax); - correspondance(fabs(v4->x()-v2->x()),fabs(v4->y()-v2->y()),fabs(v4->z()-v2->z()), - e,categories[i],flag2,xMax,yMax,zMax); - - correspondance(fabs(v4->x()-v1->x()),fabs(v4->y()-v1->y()),fabs(v4->z()-v1->z()), - e,categories[i],flag3,xMax,yMax,zMax); - correspondance(fabs(v3->x()-v2->x()),fabs(v3->y()-v2->y()),fabs(v3->z()-v2->z()), - e,categories[i],flag4,xMax,yMax,zMax); - if(flag1 && flag2){ - if(phase==1){ + correspondance(fabs(v3->x() - v1->x()), fabs(v3->y() - v1->y()), + fabs(v3->z() - v1->z()), e, categories[i], flag1, xMax, + yMax, zMax); + correspondance(fabs(v4->x() - v2->x()), fabs(v4->y() - v2->y()), + fabs(v4->z() - v2->z()), e, categories[i], flag2, xMax, + yMax, zMax); + + correspondance(fabs(v4->x() - v1->x()), fabs(v4->y() - v1->y()), + fabs(v4->z() - v1->z()), e, categories[i], flag3, xMax, + yMax, zMax); + correspondance(fabs(v3->x() - v2->x()), fabs(v3->y() - v2->y()), + fabs(v3->z() - v2->z()), e, categories[i], flag4, xMax, + yMax, zMax); + if(flag1 && flag2) { + if(phase == 1) { mem = it8; phase = 2; } - else if(phase==2){ + else if(phase == 2) { mem++; /*if(it8==mem){ normal = 1; @@ -837,21 +879,22 @@ void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax }*/ phase = 3; } - if (*it9==1) + if(*it9 == 1) indices2.push_back((*it8)->tag()); else indices2.push_back(-(*it8)->tag()); - if (*it9!=*it10) - countReverseEdge++; - print_segment(SPoint3(v3->x(),v3->y(),v3->z()),SPoint3(v1->x(),v1->y(),v1->z()),file4); - print_segment(SPoint3(v4->x(),v4->y(),v4->z()),SPoint3(v2->x(),v2->y(),v2->z()),file4); + if(*it9 != *it10) countReverseEdge++; + print_segment(SPoint3(v3->x(), v3->y(), v3->z()), + SPoint3(v1->x(), v1->y(), v1->z()), file4); + print_segment(SPoint3(v4->x(), v4->y(), v4->z()), + SPoint3(v2->x(), v2->y(), v2->z()), file4); } - else if(flag3 && flag4){ - if(phase==1){ + else if(flag3 && flag4) { + if(phase == 1) { mem = it8; phase = 2; } - else if(phase==2){ + else if(phase == 2) { mem++; /*if(it8==mem){ normal = 1; @@ -861,105 +904,123 @@ void voroMetal3D::correspondance(double e, double xMax, double yMax, double zMax }*/ phase = 3; } - if (*it9==1) + if(*it9 == 1) indices2.push_back(-(*it8)->tag()); else indices2.push_back((*it8)->tag()); - if (*it9!=*it10) - countReverseEdge++; - print_segment(SPoint3(v4->x(),v4->y(),v4->z()),SPoint3(v1->x(),v1->y(),v1->z()),file4); - print_segment(SPoint3(v3->x(),v3->y(),v3->z()),SPoint3(v2->x(),v2->y(),v2->z()),file4); + if(*it9 != *it10) countReverseEdge++; + print_segment(SPoint3(v4->x(), v4->y(), v4->z()), + SPoint3(v1->x(), v1->y(), v1->z()), file4); + print_segment(SPoint3(v3->x(), v3->y(), v3->z()), + SPoint3(v2->x(), v2->y(), v2->z()), file4); } } } - if(indices1.size()!=indices2.size()){ + if(indices1.size() != indices2.size()) { printf("Error\n\n"); } file3 << "Periodic Surface {" << gf1->tag() << " }={ " << gf2->tag() - << " } Translate { " << -dx.x() << "," << -dx.y() << "," << -dx.z() << "};\n"; + << " } Translate { " << -dx.x() << "," << -dx.y() << "," << -dx.z() + << "};\n"; } file4 << "};\n"; } -bool voroMetal3D::correspondance(double delta_x,double delta_y,double delta_z,double e, - int& val,double xMax,double yMax,double zMax) +bool voroMetal3D::correspondance(double delta_x, double delta_y, double delta_z, + double e, int &val, double xMax, double yMax, + double zMax) { bool flag; flag = 0; val = 1000; - if(equal(delta_x,xMax,e) && equal(delta_y,0.0,e) && equal(delta_z,0.0,e)){ + if(equal(delta_x, xMax, e) && equal(delta_y, 0.0, e) && + equal(delta_z, 0.0, e)) { flag = 1; val = 1; } - if(equal(delta_x,0.0,e) && equal(delta_y,yMax,e) && equal(delta_z,0.0,e)){ + if(equal(delta_x, 0.0, e) && equal(delta_y, yMax, e) && + equal(delta_z, 0.0, e)) { flag = 1; val = 2; } - if(equal(delta_x,0.0,e) && equal(delta_y,0.0,e) && equal(delta_z,zMax,e)){ + if(equal(delta_x, 0.0, e) && equal(delta_y, 0.0, e) && + equal(delta_z, zMax, e)) { flag = 1; val = 3; } - if(equal(delta_x,xMax,e) && equal(delta_y,yMax,e) && equal(delta_z,0.0,e)){ + if(equal(delta_x, xMax, e) && equal(delta_y, yMax, e) && + equal(delta_z, 0.0, e)) { flag = 1; val = 4; } - if(equal(delta_x,0.0,e) && equal(delta_y,yMax,e) && equal(delta_z,zMax,e)){ + if(equal(delta_x, 0.0, e) && equal(delta_y, yMax, e) && + equal(delta_z, zMax, e)) { flag = 1; val = 5; } - if(equal(delta_x,xMax,e) && equal(delta_y,0.0,e) && equal(delta_z,zMax,e)){ + if(equal(delta_x, xMax, e) && equal(delta_y, 0.0, e) && + equal(delta_z, zMax, e)) { flag = 1; val = 6; } - if(equal(delta_x,xMax,e) && equal(delta_y,yMax,e) && equal(delta_z,zMax,e)){ + if(equal(delta_x, xMax, e) && equal(delta_y, yMax, e) && + equal(delta_z, zMax, e)) { flag = 1; val = 7; } return flag; } -void voroMetal3D::correspondance(double delta_x,double delta_y,double delta_z, - double e,int val,bool& flag,double xMax,double yMax,double zMax) +void voroMetal3D::correspondance(double delta_x, double delta_y, double delta_z, + double e, int val, bool &flag, double xMax, + double yMax, double zMax) { flag = 0; - if(val==1 && equal(delta_x,xMax,e) && equal(delta_y,0.0,e) && equal(delta_z,0.0,e)){ + if(val == 1 && equal(delta_x, xMax, e) && equal(delta_y, 0.0, e) && + equal(delta_z, 0.0, e)) { flag = 1; } - if(val==2 && equal(delta_x,0.0,e) && equal(delta_y,yMax,e) && equal(delta_z,0.0,e)){ + if(val == 2 && equal(delta_x, 0.0, e) && equal(delta_y, yMax, e) && + equal(delta_z, 0.0, e)) { flag = 1; } - if(val==3 && equal(delta_x,0.0,e) && equal(delta_y,0.0,e) && equal(delta_z,zMax,e)){ + if(val == 3 && equal(delta_x, 0.0, e) && equal(delta_y, 0.0, e) && + equal(delta_z, zMax, e)) { flag = 1; } - if(val==4 && equal(delta_x,xMax,e) && equal(delta_y,yMax,e) && equal(delta_z,0.0,e)){ + if(val == 4 && equal(delta_x, xMax, e) && equal(delta_y, yMax, e) && + equal(delta_z, 0.0, e)) { flag = 1; } - if(val==5 && equal(delta_x,0.0,e) && equal(delta_y,yMax,e) && equal(delta_z,zMax,e)){ + if(val == 5 && equal(delta_x, 0.0, e) && equal(delta_y, yMax, e) && + equal(delta_z, zMax, e)) { flag = 1; } - if(val==6 && equal(delta_x,xMax,e) && equal(delta_y,0.0,e) && equal(delta_z,zMax,e)){ + if(val == 6 && equal(delta_x, xMax, e) && equal(delta_y, 0.0, e) && + equal(delta_z, zMax, e)) { flag = 1; } - if(val==7 && equal(delta_x,xMax,e) && equal(delta_y,yMax,e) && equal(delta_z,zMax,e)){ + if(val == 7 && equal(delta_x, xMax, e) && equal(delta_y, yMax, e) && + equal(delta_z, zMax, e)) { flag = 1; } } -bool voroMetal3D::equal(double x,double y,double e) +bool voroMetal3D::equal(double x, double y, double e) { bool flag; - if(x>y-e && x<y+e){ + if(x > y - e && x < y + e) { flag = 1; } - else{ + else { flag = 0; } return flag; @@ -974,9 +1035,9 @@ static void microstructure(const char *filename) double yMax; double zMax; std::vector<double> properties; - if(filename){ + if(filename) { std::ifstream file(filename); - if(!file.is_open()){ + if(!file.is_open()) { Msg::Error("Could not open file '%s'", filename); return; } @@ -986,18 +1047,18 @@ static void microstructure(const char *filename) file >> yMax; file >> zMax; properties.clear(); - properties.resize(4*max); - for(j=0;j<max;j++){ - file >> properties[4*j]; - file >> properties[4*j+1]; - file >> properties[4*j+2]; - file >> properties[4*j+3]; + properties.resize(4 * max); + for(j = 0; j < max; j++) { + file >> properties[4 * j]; + file >> properties[4 * j + 1]; + file >> properties[4 * j + 2]; + file >> properties[4 * j + 3]; } voroMetal3D vm1; - vm1.execute(properties,radical,0.1,xMax,yMax,zMax); + vm1.execute(properties, radical, 0.1, xMax, yMax, zMax); GModel::current()->load("MicrostructurePolycrystal3D.geo"); voroMetal3D vm2; - vm2.correspondance(0.00001,xMax,yMax,zMax); + vm2.correspondance(0.00001, xMax, yMax, zMax); } } @@ -1010,10 +1071,10 @@ static void computeBestSeeds(const char *filename) double yMax; double zMax; std::vector<double> properties; - std::cout<<"entree dans computeBestSeeds"<<std::endl; - if(filename){ + std::cout << "entree dans computeBestSeeds" << std::endl; + if(filename) { std::ifstream file(filename); - if(!file.is_open()){ + if(!file.is_open()) { Msg::Error("Could not open file '%s'", filename); return; } @@ -1023,57 +1084,58 @@ static void computeBestSeeds(const char *filename) file >> yMax; file >> zMax; properties.clear(); - properties.resize(4*max); - for(j=0;j<max;j++){ - file >> properties[4*j]; - file >> properties[4*j+1]; - file >> properties[4*j+2]; - file >> properties[4*j+3]; + properties.resize(4 * max); + for(j = 0; j < max; j++) { + file >> properties[4 * j]; + file >> properties[4 * j + 1]; + file >> properties[4 * j + 2]; + file >> properties[4 * j + 3]; } - std::cout<<"Before count"<<std::endl; + std::cout << "Before count" << std::endl; std::vector<double> listDistances; listDistances.clear(); int nbOfCount = 17; listDistances.resize(nbOfCount); - for (int Count = 0; Count < nbOfCount; Count++){ - std::cout<<"Count"<<Count<<std::endl; + for(int Count = 0; Count < nbOfCount; Count++) { + std::cout << "Count" << Count << std::endl; double distMinGlobal = 0.0; int jMinGlobal = 0; int xORyORz = 0; int posORneg = 0; - for(j=0;j<max;j++){ - std::cout<<"j "<<j<<std::endl; + for(j = 0; j < max; j++) { + std::cout << "j " << j << std::endl; std::vector<double> propertiesModified; propertiesModified.clear(); - propertiesModified.resize(4*max); - std::cout<<"before assign propModif"<<std::endl; - for(unsigned int k=0;k < properties.size();k++){ + propertiesModified.resize(4 * max); + std::cout << "before assign propModif" << std::endl; + for(unsigned int k = 0; k < properties.size(); k++) { propertiesModified[k] = properties[k]; } - std::cout<<"after assign propModif"<<std::endl; - propertiesModified[4*j] += 0.01; + std::cout << "after assign propModif" << std::endl; + propertiesModified[4 * j] += 0.01; voroMetal3D vm1; - std::cout<<"before execute"<<std::endl; - //std::remove("MicrostructurePolycrystal3D.geo"); - vm1.execute(propertiesModified,radical,0.1,xMax,yMax,zMax); - //GModel::current()->destroy(); + std::cout << "before execute" << std::endl; + // std::remove("MicrostructurePolycrystal3D.geo"); + vm1.execute(propertiesModified, radical, 0.1, xMax, yMax, zMax); + // GModel::current()->destroy(); GModel *m = new GModel(); - //GModel::current()->load("MicrostructurePolycrystal3D.geo"); + // GModel::current()->load("MicrostructurePolycrystal3D.geo"); m->load("MicrostructurePolycrystal3D.geo"); double distMinTmp = 1000.0; - //GModel *m = GModel::current(); - for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){ - GEdge* eTmp = (*ite); - GVertex* vTmp1 = eTmp->getBeginVertex(); - GVertex* vTmp2 = eTmp->getEndVertex(); - double distTmp = sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + - (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + - (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); - if (distTmp < distMinTmp){ + // GModel *m = GModel::current(); + for(GModel::eiter ite = m->firstEdge(); ite != m->lastEdge(); ite++) { + GEdge *eTmp = (*ite); + GVertex *vTmp1 = eTmp->getBeginVertex(); + GVertex *vTmp2 = eTmp->getEndVertex(); + double distTmp = + sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + + (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + + (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); + if(distTmp < distMinTmp) { distMinTmp = distTmp; } } - if (distMinTmp > distMinGlobal){ + if(distMinTmp > distMinGlobal) { distMinGlobal = distMinTmp; jMinGlobal = j; xORyORz = 1; @@ -1081,39 +1143,40 @@ static void computeBestSeeds(const char *filename) } delete m; } - for(j = 0; j < max; j++){ - std::cout<<"j "<<j<<std::endl; + for(j = 0; j < max; j++) { + std::cout << "j " << j << std::endl; std::vector<double> propertiesModified; propertiesModified.clear(); - propertiesModified.resize(4*max); - std::cout<<"before assign propModif"<<std::endl; - for(unsigned int k=0;k < properties.size();k++){ + propertiesModified.resize(4 * max); + std::cout << "before assign propModif" << std::endl; + for(unsigned int k = 0; k < properties.size(); k++) { propertiesModified[k] = properties[k]; } - std::cout<<"after assign propModif"<<std::endl; - propertiesModified[4*j + 1] += 0.01; + std::cout << "after assign propModif" << std::endl; + propertiesModified[4 * j + 1] += 0.01; voroMetal3D vm1; - std::cout<<"before execute"<<std::endl; - //std::remove("MicrostructurePolycrystal3D.geo"); - vm1.execute(propertiesModified,radical,0.1,xMax,yMax,zMax); - //GModel::current()->destroy(); + std::cout << "before execute" << std::endl; + // std::remove("MicrostructurePolycrystal3D.geo"); + vm1.execute(propertiesModified, radical, 0.1, xMax, yMax, zMax); + // GModel::current()->destroy(); GModel *m = new GModel(); - //GModel::current()->load("MicrostructurePolycrystal3D.geo"); + // GModel::current()->load("MicrostructurePolycrystal3D.geo"); m->load("MicrostructurePolycrystal3D.geo"); double distMinTmp = 1000.0; - //GModel *m = GModel::current(); - for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){ - GEdge* eTmp = (*ite); - GVertex* vTmp1 = eTmp->getBeginVertex(); - GVertex* vTmp2 = eTmp->getEndVertex(); - double distTmp = sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + - (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + - (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); - if (distTmp < distMinTmp){ + // GModel *m = GModel::current(); + for(GModel::eiter ite = m->firstEdge(); ite != m->lastEdge(); ite++) { + GEdge *eTmp = (*ite); + GVertex *vTmp1 = eTmp->getBeginVertex(); + GVertex *vTmp2 = eTmp->getEndVertex(); + double distTmp = + sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + + (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + + (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); + if(distTmp < distMinTmp) { distMinTmp = distTmp; } } - if(distMinTmp > distMinGlobal){ + if(distMinTmp > distMinGlobal) { distMinGlobal = distMinTmp; jMinGlobal = j; xORyORz = 2; @@ -1121,39 +1184,40 @@ static void computeBestSeeds(const char *filename) } delete m; } - for(j = 0; j < max; j++){ - std::cout<<"j "<<j<<std::endl; + for(j = 0; j < max; j++) { + std::cout << "j " << j << std::endl; std::vector<double> propertiesModified; propertiesModified.clear(); - propertiesModified.resize(4*max); - std::cout<<"before assign propModif"<<std::endl; - for(unsigned int k=0;k < properties.size();k++){ + propertiesModified.resize(4 * max); + std::cout << "before assign propModif" << std::endl; + for(unsigned int k = 0; k < properties.size(); k++) { propertiesModified[k] = properties[k]; } - std::cout<<"after assign propModif"<<std::endl; - propertiesModified[4*j + 2] += 0.01; + std::cout << "after assign propModif" << std::endl; + propertiesModified[4 * j + 2] += 0.01; voroMetal3D vm1; - std::cout<<"before execute"<<std::endl; - //std::remove("MicrostructurePolycrystal3D.geo"); - vm1.execute(propertiesModified,radical,0.1,xMax,yMax,zMax); - //GModel::current()->destroy(); + std::cout << "before execute" << std::endl; + // std::remove("MicrostructurePolycrystal3D.geo"); + vm1.execute(propertiesModified, radical, 0.1, xMax, yMax, zMax); + // GModel::current()->destroy(); GModel *m = new GModel(); - //GModel::current()->load("MicrostructurePolycrystal3D.geo"); + // GModel::current()->load("MicrostructurePolycrystal3D.geo"); m->load("MicrostructurePolycrystal3D.geo"); double distMinTmp = 1000.0; - //GModel *m = GModel::current(); - for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){ - GEdge* eTmp = (*ite); - GVertex* vTmp1 = eTmp->getBeginVertex(); - GVertex* vTmp2 = eTmp->getEndVertex(); - double distTmp = sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + - (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + - (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); - if (distTmp < distMinTmp){ + // GModel *m = GModel::current(); + for(GModel::eiter ite = m->firstEdge(); ite != m->lastEdge(); ite++) { + GEdge *eTmp = (*ite); + GVertex *vTmp1 = eTmp->getBeginVertex(); + GVertex *vTmp2 = eTmp->getEndVertex(); + double distTmp = + sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + + (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + + (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); + if(distTmp < distMinTmp) { distMinTmp = distTmp; } } - if (distMinTmp > distMinGlobal){ + if(distMinTmp > distMinGlobal) { distMinGlobal = distMinTmp; jMinGlobal = j; xORyORz = 3; @@ -1161,39 +1225,40 @@ static void computeBestSeeds(const char *filename) } delete m; } - for(j = 0; j < max; j++){ - std::cout<<"j "<<j<<std::endl; + for(j = 0; j < max; j++) { + std::cout << "j " << j << std::endl; std::vector<double> propertiesModified; propertiesModified.clear(); - propertiesModified.resize(4*max); - std::cout<<"before assign propModif"<<std::endl; - for(unsigned int k=0;k < properties.size();k++){ + propertiesModified.resize(4 * max); + std::cout << "before assign propModif" << std::endl; + for(unsigned int k = 0; k < properties.size(); k++) { propertiesModified[k] = properties[k]; } - std::cout<<"after assign propModif"<<std::endl; - propertiesModified[4*j] -= 0.01; + std::cout << "after assign propModif" << std::endl; + propertiesModified[4 * j] -= 0.01; voroMetal3D vm1; - std::cout<<"before execute"<<std::endl; - //std::remove("MicrostructurePolycrystal3D.geo"); - vm1.execute(propertiesModified,radical,0.1,xMax,yMax,zMax); - //GModel::current()->destroy(); + std::cout << "before execute" << std::endl; + // std::remove("MicrostructurePolycrystal3D.geo"); + vm1.execute(propertiesModified, radical, 0.1, xMax, yMax, zMax); + // GModel::current()->destroy(); GModel *m = new GModel(); - //GModel::current()->load("MicrostructurePolycrystal3D.geo"); + // GModel::current()->load("MicrostructurePolycrystal3D.geo"); m->load("MicrostructurePolycrystal3D.geo"); double distMinTmp = 1000.0; - //GModel *m = GModel::current(); - for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){ - GEdge* eTmp = (*ite); - GVertex* vTmp1 = eTmp->getBeginVertex(); - GVertex* vTmp2 = eTmp->getEndVertex(); - double distTmp = sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + - (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + - (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); - if (distTmp < distMinTmp){ + // GModel *m = GModel::current(); + for(GModel::eiter ite = m->firstEdge(); ite != m->lastEdge(); ite++) { + GEdge *eTmp = (*ite); + GVertex *vTmp1 = eTmp->getBeginVertex(); + GVertex *vTmp2 = eTmp->getEndVertex(); + double distTmp = + sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + + (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + + (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); + if(distTmp < distMinTmp) { distMinTmp = distTmp; } } - if (distMinTmp > distMinGlobal){ + if(distMinTmp > distMinGlobal) { distMinGlobal = distMinTmp; jMinGlobal = j; xORyORz = 1; @@ -1201,39 +1266,40 @@ static void computeBestSeeds(const char *filename) } delete m; } - for(j=0;j<max;j++){ - std::cout<<"j "<<j<<std::endl; + for(j = 0; j < max; j++) { + std::cout << "j " << j << std::endl; std::vector<double> propertiesModified; propertiesModified.clear(); - propertiesModified.resize(4*max); - std::cout<<"before assign propModif"<<std::endl; - for(unsigned int k=0;k < properties.size();k++){ + propertiesModified.resize(4 * max); + std::cout << "before assign propModif" << std::endl; + for(unsigned int k = 0; k < properties.size(); k++) { propertiesModified[k] = properties[k]; } - std::cout<<"after assign propModif"<<std::endl; - propertiesModified[4*j + 1] -= 0.01; + std::cout << "after assign propModif" << std::endl; + propertiesModified[4 * j + 1] -= 0.01; voroMetal3D vm1; - std::cout<<"before execute"<<std::endl; - //std::remove("MicrostructurePolycrystal3D.geo"); - vm1.execute(propertiesModified,radical,0.1,xMax,yMax,zMax); - //GModel::current()->destroy(); + std::cout << "before execute" << std::endl; + // std::remove("MicrostructurePolycrystal3D.geo"); + vm1.execute(propertiesModified, radical, 0.1, xMax, yMax, zMax); + // GModel::current()->destroy(); GModel *m = new GModel(); - //GModel::current()->load("MicrostructurePolycrystal3D.geo"); + // GModel::current()->load("MicrostructurePolycrystal3D.geo"); m->load("MicrostructurePolycrystal3D.geo"); double distMinTmp = 1000.0; - //GModel *m = GModel::current(); - for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){ - GEdge* eTmp = (*ite); - GVertex* vTmp1 = eTmp->getBeginVertex(); - GVertex* vTmp2 = eTmp->getEndVertex(); - double distTmp = sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + - (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + - (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); - if (distTmp < distMinTmp){ + // GModel *m = GModel::current(); + for(GModel::eiter ite = m->firstEdge(); ite != m->lastEdge(); ite++) { + GEdge *eTmp = (*ite); + GVertex *vTmp1 = eTmp->getBeginVertex(); + GVertex *vTmp2 = eTmp->getEndVertex(); + double distTmp = + sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + + (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + + (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); + if(distTmp < distMinTmp) { distMinTmp = distTmp; } } - if (distMinTmp > distMinGlobal){ + if(distMinTmp > distMinGlobal) { distMinGlobal = distMinTmp; jMinGlobal = j; xORyORz = 2; @@ -1241,39 +1307,40 @@ static void computeBestSeeds(const char *filename) } delete m; } - for(j=0;j<max;j++){ - std::cout<<"j "<<j<<std::endl; + for(j = 0; j < max; j++) { + std::cout << "j " << j << std::endl; std::vector<double> propertiesModified; propertiesModified.clear(); - propertiesModified.resize(4*max); - std::cout<<"before assign propModif"<<std::endl; - for(unsigned int k=0;k < properties.size();k++){ + propertiesModified.resize(4 * max); + std::cout << "before assign propModif" << std::endl; + for(unsigned int k = 0; k < properties.size(); k++) { propertiesModified[k] = properties[k]; } - std::cout<<"after assign propModif"<<std::endl; - propertiesModified[4*j + 2] -= 0.01; + std::cout << "after assign propModif" << std::endl; + propertiesModified[4 * j + 2] -= 0.01; voroMetal3D vm1; - std::cout<<"before execute"<<std::endl; - //std::remove("MicrostructurePolycrystal3D.geo"); - vm1.execute(propertiesModified,radical,0.1,xMax,yMax,zMax); - //GModel::current()->destroy(); + std::cout << "before execute" << std::endl; + // std::remove("MicrostructurePolycrystal3D.geo"); + vm1.execute(propertiesModified, radical, 0.1, xMax, yMax, zMax); + // GModel::current()->destroy(); GModel *m = new GModel(); - //GModel::current()->load("MicrostructurePolycrystal3D.geo"); + // GModel::current()->load("MicrostructurePolycrystal3D.geo"); m->load("MicrostructurePolycrystal3D.geo"); double distMinTmp = 1000.0; - //GModel *m = GModel::current(); - for (GModel::eiter ite= m->firstEdge();ite != m->lastEdge();ite++){ - GEdge* eTmp = (*ite); - GVertex* vTmp1 = eTmp->getBeginVertex(); - GVertex* vTmp2 = eTmp->getEndVertex(); - double distTmp = sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + - (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + - (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); - if (distTmp < distMinTmp){ + // GModel *m = GModel::current(); + for(GModel::eiter ite = m->firstEdge(); ite != m->lastEdge(); ite++) { + GEdge *eTmp = (*ite); + GVertex *vTmp1 = eTmp->getBeginVertex(); + GVertex *vTmp2 = eTmp->getEndVertex(); + double distTmp = + sqrt((vTmp1->x() - vTmp2->x()) * (vTmp1->x() - vTmp2->x()) + + (vTmp1->y() - vTmp2->y()) * (vTmp1->y() - vTmp2->y()) + + (vTmp1->z() - vTmp2->z()) * (vTmp1->z() - vTmp2->z())); + if(distTmp < distMinTmp) { distMinTmp = distTmp; } } - if (distMinTmp > distMinGlobal){ + if(distMinTmp > distMinGlobal) { distMinGlobal = distMinTmp; jMinGlobal = j; xORyORz = 3; @@ -1281,40 +1348,47 @@ static void computeBestSeeds(const char *filename) } delete m; } - std::cout<<"distance minimale de "<<distMinGlobal<<std::endl; + std::cout << "distance minimale de " << distMinGlobal << std::endl; listDistances[Count] = distMinGlobal; - if (xORyORz == 1){ - if (posORneg == 1){ - properties[4*jMinGlobal] += 0.01; - } else if (posORneg == 2){ - properties[4*jMinGlobal] -= 0.01; + if(xORyORz == 1) { + if(posORneg == 1) { + properties[4 * jMinGlobal] += 0.01; + } + else if(posORneg == 2) { + properties[4 * jMinGlobal] -= 0.01; } - } else if (xORyORz == 2){ - if (posORneg == 1){ - properties[4*jMinGlobal + 1] += 0.01; - } else if (posORneg == 2){ - properties[4*jMinGlobal + 1] -= 0.01; + } + else if(xORyORz == 2) { + if(posORneg == 1) { + properties[4 * jMinGlobal + 1] += 0.01; + } + else if(posORneg == 2) { + properties[4 * jMinGlobal + 1] -= 0.01; + } + } + else if(xORyORz == 3) { + if(posORneg == 1) { + properties[4 * jMinGlobal + 2] += 0.01; } - } else if (xORyORz == 3){ - if (posORneg == 1){ - properties[4*jMinGlobal + 2] += 0.01; - } else if (posORneg == 2){ - properties[4*jMinGlobal + 2] -= 0.01; + else if(posORneg == 2) { + properties[4 * jMinGlobal + 2] -= 0.01; } } } voroMetal3D vm1; - vm1.execute(properties,radical,0.1,xMax,yMax,zMax); + vm1.execute(properties, radical, 0.1, xMax, yMax, zMax); GModel::current()->load("MicrostructurePolycrystal3D.geo"); voroMetal3D vm2; - vm2.correspondance(0.00001,xMax,yMax,zMax); - for (unsigned int iTmp = 0; iTmp < listDistances.size();iTmp++){ - std::cout<<"distMinGlobal "<<iTmp<<" egale a "<<listDistances[iTmp]<<std::endl; + vm2.correspondance(0.00001, xMax, yMax, zMax); + for(unsigned int iTmp = 0; iTmp < listDistances.size(); iTmp++) { + std::cout << "distMinGlobal " << iTmp << " egale a " + << listDistances[iTmp] << std::endl; } - std::cout<<"liste des nouveaux seeds :"<<std::endl; - for(unsigned int iTmp = 0; iTmp < max;iTmp++){ - std::cout<<properties[4*iTmp]<<" "<<properties[4*iTmp + 1]<<" " - <<properties[4*iTmp + 2]<<" "<<properties[4*iTmp + 3]<<std::endl; + std::cout << "liste des nouveaux seeds :" << std::endl; + for(unsigned int iTmp = 0; iTmp < max; iTmp++) { + std::cout << properties[4 * iTmp] << " " << properties[4 * iTmp + 1] + << " " << properties[4 * iTmp + 2] << " " + << properties[4 * iTmp + 3] << std::endl; } } } diff --git a/Plugin/VoroMetal.h b/Plugin/VoroMetal.h index f8d0b982c00b96e94d6d66cd06fe4b854b2c6a29..6903c60ad358963e639e0cf513e9abef6f8264ca 100644 --- a/Plugin/VoroMetal.h +++ b/Plugin/VoroMetal.h @@ -9,9 +9,9 @@ #include <vector> #include "Plugin.h" -class geo_cell{ - public: - std::vector<std::pair<int,int> > lines; +class geo_cell { +public: + std::vector<std::pair<int, int> > lines; std::vector<std::vector<int> > line_loops; std::vector<std::vector<int> > orientations; std::vector<int> points2; @@ -19,65 +19,67 @@ class geo_cell{ std::vector<int> line_loops2; std::vector<int> faces2; int face_loops2; - geo_cell(){} - ~geo_cell(){} - int search_line(std::pair<int,int> line) + geo_cell() {} + ~geo_cell() {} + int search_line(std::pair<int, int> line) { unsigned int i; - for(i=0;i<lines.size();i++){ - if(lines[i].first==line.first && lines[i].second==line.second) return i; - if(lines[i].first==line.second && lines[i].second==line.first) return i; + for(i = 0; i < lines.size(); i++) { + if(lines[i].first == line.first && lines[i].second == line.second) + return i; + if(lines[i].first == line.second && lines[i].second == line.first) + return i; } return -1; } }; -class voroMetal3D{ - private: +class voroMetal3D { +private: int counter; - public: - voroMetal3D(){} - ~voroMetal3D(){} + +public: + voroMetal3D() {} + ~voroMetal3D() {} void execute(double); - void execute(GRegion*,double); - void execute(std::vector<SPoint3>&,std::vector<double>&,int,double,double,double,double); - void execute(std::vector<double>&,int,double,double,double,double); - void print_segment(SPoint3,SPoint3,std::ofstream&); + void execute(GRegion *, double); + void execute(std::vector<SPoint3> &, std::vector<double> &, int, double, + double, double, double); + void execute(std::vector<double> &, int, double, double, double, double); + void print_segment(SPoint3, SPoint3, std::ofstream &); void initialize_counter(); void increase_counter(); int get_counter(); - void print_geo_point(int,double,double,double,std::ofstream&); - void print_geo_line(int,int,int,std::ofstream&); - void print_geo_face(int,int,std::ofstream&); - void print_geo_physical_face(int,int,std::ofstream&); - void print_geo_volume(int,int,std::ofstream&); - void print_geo_physical_volume(int,int,std::ofstream&); - void print_geo_line_loop(int,std::vector<int>&,std::vector<int>&,std::ofstream&); - void print_geo_face_loop(int,std::vector<int>&,std::ofstream&); - void correspondance(double,double,double,double); - bool correspondance(double,double,double,double,int&,double,double,double); - void correspondance(double,double,double,double,int,bool&,double,double,double); - bool equal(double,double,double); + void print_geo_point(int, double, double, double, std::ofstream &); + void print_geo_line(int, int, int, std::ofstream &); + void print_geo_face(int, int, std::ofstream &); + void print_geo_physical_face(int, int, std::ofstream &); + void print_geo_volume(int, int, std::ofstream &); + void print_geo_physical_volume(int, int, std::ofstream &); + void print_geo_line_loop(int, std::vector<int> &, std::vector<int> &, + std::ofstream &); + void print_geo_face_loop(int, std::vector<int> &, std::ofstream &); + void correspondance(double, double, double, double); + bool correspondance(double, double, double, double, int &, double, double, + double); + void correspondance(double, double, double, double, int, bool &, double, + double, double); + bool equal(double, double, double); }; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterVoroMetalPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterVoroMetalPlugin(); } -class GMSH_VoroMetalPlugin : public GMSH_PostPlugin -{ - public: - GMSH_VoroMetalPlugin(){} +class GMSH_VoroMetalPlugin : public GMSH_PostPlugin { +public: + GMSH_VoroMetalPlugin() {} std::string getName() const { return "VoroMetal"; } - std::string getShortHelp() const - { - return "Voronoi microstructures"; - } + std::string getShortHelp() const { return "Voronoi microstructures"; } std::string getHelp() const; std::string getAuthor() const { return "Tristan Carrier & Maxime Melchior"; } int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); int getNbOptionsStr() const; StringXString *getOptionStr(int iopt); PView *execute(PView *); diff --git a/Plugin/Warp.cpp b/Plugin/Warp.cpp index c401eb84c6897575cba8a421a004d25ce0279281..5e1a01ddf48eebbfd6e32782cf2290d683bee6a7 100644 --- a/Plugin/Warp.cpp +++ b/Plugin/Warp.cpp @@ -12,30 +12,25 @@ StringXNumber WarpOptions_Number[] = { {GMSH_FULLRC, "TimeStep", NULL, 0.}, {GMSH_FULLRC, "SmoothingAngle", NULL, 180.}, {GMSH_FULLRC, "View", NULL, -1.}, - {GMSH_FULLRC, "OtherView", NULL, -1.} -}; + {GMSH_FULLRC, "OtherView", NULL, -1.}}; -extern "C" -{ - GMSH_Plugin *GMSH_RegisterWarpPlugin() - { - return new GMSH_WarpPlugin(); - } +extern "C" { +GMSH_Plugin *GMSH_RegisterWarpPlugin() { return new GMSH_WarpPlugin(); } } std::string GMSH_WarpPlugin::getHelp() const { return "Plugin(Warp) transforms the elements in the " - "view `View' by adding to their node coordinates " - "the vector field stored in the `TimeStep'-th time " - "step of the view `OtherView', scaled by `Factor'.\n\n" - "If `View' < 0, the plugin is run on the current view.\n\n" - "If `OtherView' < 0, the vector field is taken as the " - "field of surface normals multiplied by the `TimeStep' " - "value in `View'. (The smoothing of the surface " - "normals is controlled by the `SmoothingAngle' " - "parameter.)\n\n" - "Plugin(Warp) is executed in-place."; + "view `View' by adding to their node coordinates " + "the vector field stored in the `TimeStep'-th time " + "step of the view `OtherView', scaled by `Factor'.\n\n" + "If `View' < 0, the plugin is run on the current view.\n\n" + "If `OtherView' < 0, the vector field is taken as the " + "field of surface normals multiplied by the `TimeStep' " + "value in `View'. (The smoothing of the surface " + "normals is controlled by the `SmoothingAngle' " + "parameter.)\n\n" + "Plugin(Warp) is executed in-place."; } int GMSH_WarpPlugin::getNbOptions() const @@ -67,28 +62,29 @@ PView *GMSH_WarpPlugin::execute(PView *v) // sanity checks if(data1->getNumEntities() != data2->getNumEntities() || - data1->getNumElements() != data2->getNumElements()){ + data1->getNumElements() != data2->getNumElements()) { Msg::Error("Incompatible views"); return v; } - if(TimeStep < 0 || TimeStep > data2->getNumTimeSteps() - 1){ + if(TimeStep < 0 || TimeStep > data2->getNumTimeSteps() - 1) { Msg::Error("Invalid TimeStep (%d) in View[%d]", TimeStep, v2->getIndex()); return v; } // create smooth normal field if we don't have an explicit warp field smooth_normals *normals = 0; - if(otherView < 0){ + if(otherView < 0) { normals = new smooth_normals(AngleTol); - for(int ent = 0; ent < data1->getNumEntities(0); ent++){ - for(int ele = 0; ele < data1->getNumElements(0, ent); ele++){ + for(int ent = 0; ent < data1->getNumEntities(0); ent++) { + for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) { if(data1->skipElement(0, ent, ele)) continue; int numEdges = data1->getNumEdges(0, ent, ele); - if(numEdges == 3 || numEdges == 4){ + if(numEdges == 3 || numEdges == 4) { double x[4], y[4], z[4], n[4]; for(int nod = 0; nod < numEdges; nod++) data1->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]); - normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], n); + normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], + n); for(int nod = 0; nod < numEdges; nod++) normals->add(x[nod], y[nod], z[nod], n[0], n[1], n[2]); } @@ -96,11 +92,11 @@ PView *GMSH_WarpPlugin::execute(PView *v) } } - if(data1->isNodeData()){ + if(data1->isNodeData()) { // tag all the nodes with "0" (the default tag) - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) data1->tagNode(step, ent, ele, nod, 0); @@ -110,30 +106,32 @@ PView *GMSH_WarpPlugin::execute(PView *v) } // transform each "0" node: (x,y,z) += factor * mult * (valx, valy, valz) - for(int step = 0; step < data1->getNumTimeSteps(); step++){ - for(int ent = 0; ent < data1->getNumEntities(step); ent++){ - for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ + for(int step = 0; step < data1->getNumTimeSteps(); step++) { + for(int ent = 0; ent < data1->getNumEntities(step); ent++) { + for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) { if(data1->skipElement(step, ent, ele)) continue; int numNodes = data1->getNumNodes(step, ent, ele); if(numNodes < 2) continue; double x[8], y[8], z[8], n[3] = {0., 0., 0.}; int tag[8]; for(int nod = 0; nod < numNodes; nod++) - tag[nod] = data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); + tag[nod] = + data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); int dim = data1->getDimension(step, ent, ele); if(normals && dim == 2) - normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], n); - for(int nod = 0; nod < numNodes; nod++){ + normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], + n); + for(int nod = 0; nod < numNodes; nod++) { if(data1->isNodeData() && tag[nod]) continue; // already transformed double mult = 1., val[3] = {n[0], n[1], n[2]}; - if(normals){ - if(dim == 2){ + if(normals) { + if(dim == 2) { normals->get(x[nod], y[nod], z[nod], val[0], val[1], val[2]); data1->getScalarValue(step, ent, ele, nod, mult); } } else if(data2->getNumComponents(TimeStep, ent, ele) == 3 && - data2->getNumNodes(TimeStep, ent, ele) == numNodes){ + data2->getNumNodes(TimeStep, ent, ele) == numNodes) { for(int comp = 0; comp < 3; comp++) data2->getValue(TimeStep, ent, ele, nod, comp, val[comp]); } diff --git a/Plugin/Warp.h b/Plugin/Warp.h index 805580f33189715c5d3f7fa5bf9de65dd89a7934..e48b3731b34c20204c8c57df8fd204cd30fbe35c 100644 --- a/Plugin/Warp.h +++ b/Plugin/Warp.h @@ -8,15 +8,13 @@ #include "Plugin.h" -extern "C" -{ - GMSH_Plugin *GMSH_RegisterWarpPlugin(); +extern "C" { +GMSH_Plugin *GMSH_RegisterWarpPlugin(); } -class GMSH_WarpPlugin : public GMSH_PostPlugin -{ - public: - GMSH_WarpPlugin(){} +class GMSH_WarpPlugin : public GMSH_PostPlugin { +public: + GMSH_WarpPlugin() {} std::string getName() const { return "Warp"; } std::string getShortHelp() const { @@ -24,7 +22,7 @@ class GMSH_WarpPlugin : public GMSH_PostPlugin } std::string getHelp() const; int getNbOptions() const; - StringXNumber *getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Post/ColorTable.cpp b/Post/ColorTable.cpp index 7f253ddd1a3bb02f2555189fdf32b9aeb382cd4c..1c227175cb37b5302bbd7429759fe5975c28c24c 100644 --- a/Post/ColorTable.cpp +++ b/Post/ColorTable.cpp @@ -22,7 +22,7 @@ void ColorTable_InitParam(int number, GmshColorTable *ct) { ct->size = 255; - for(int i = 0; i < COLORTABLE_NBMAX_PARAM; i++){ + for(int i = 0; i < COLORTABLE_NBMAX_PARAM; i++) { ct->ipar[i] = 0; ct->dpar[i] = 0.; } @@ -31,10 +31,7 @@ void ColorTable_InitParam(int number, GmshColorTable *ct) ct->dpar[COLORTABLE_ALPHA] = 1.0; } -static double gray(double s) -{ - return s < 0. ? 0. : (s < 1. ? s : 1.); -} +static double gray(double s) { return s < 0. ? 0. : (s < 1. ? s : 1.); } static double hot_r(double s) { @@ -70,1039 +67,527 @@ static double cubic(double a, double b, double c, double d, double x) // You should have received a copy of the CC0 legalcode along with this // work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. -static double _magma_data[][3] = - {{0.001462, 0.000466, 0.013866}, - {0.002258, 0.001295, 0.018331}, - {0.003279, 0.002305, 0.023708}, - {0.004512, 0.003490, 0.029965}, - {0.005950, 0.004843, 0.037130}, - {0.007588, 0.006356, 0.044973}, - {0.009426, 0.008022, 0.052844}, - {0.011465, 0.009828, 0.060750}, - {0.013708, 0.011771, 0.068667}, - {0.016156, 0.013840, 0.076603}, - {0.018815, 0.016026, 0.084584}, - {0.021692, 0.018320, 0.092610}, - {0.024792, 0.020715, 0.100676}, - {0.028123, 0.023201, 0.108787}, - {0.031696, 0.025765, 0.116965}, - {0.035520, 0.028397, 0.125209}, - {0.039608, 0.031090, 0.133515}, - {0.043830, 0.033830, 0.141886}, - {0.048062, 0.036607, 0.150327}, - {0.052320, 0.039407, 0.158841}, - {0.056615, 0.042160, 0.167446}, - {0.060949, 0.044794, 0.176129}, - {0.065330, 0.047318, 0.184892}, - {0.069764, 0.049726, 0.193735}, - {0.074257, 0.052017, 0.202660}, - {0.078815, 0.054184, 0.211667}, - {0.083446, 0.056225, 0.220755}, - {0.088155, 0.058133, 0.229922}, - {0.092949, 0.059904, 0.239164}, - {0.097833, 0.061531, 0.248477}, - {0.102815, 0.063010, 0.257854}, - {0.107899, 0.064335, 0.267289}, - {0.113094, 0.065492, 0.276784}, - {0.118405, 0.066479, 0.286321}, - {0.123833, 0.067295, 0.295879}, - {0.129380, 0.067935, 0.305443}, - {0.135053, 0.068391, 0.315000}, - {0.140858, 0.068654, 0.324538}, - {0.146785, 0.068738, 0.334011}, - {0.152839, 0.068637, 0.343404}, - {0.159018, 0.068354, 0.352688}, - {0.165308, 0.067911, 0.361816}, - {0.171713, 0.067305, 0.370771}, - {0.178212, 0.066576, 0.379497}, - {0.184801, 0.065732, 0.387973}, - {0.191460, 0.064818, 0.396152}, - {0.198177, 0.063862, 0.404009}, - {0.204935, 0.062907, 0.411514}, - {0.211718, 0.061992, 0.418647}, - {0.218512, 0.061158, 0.425392}, - {0.225302, 0.060445, 0.431742}, - {0.232077, 0.059889, 0.437695}, - {0.238826, 0.059517, 0.443256}, - {0.245543, 0.059352, 0.448436}, - {0.252220, 0.059415, 0.453248}, - {0.258857, 0.059706, 0.457710}, - {0.265447, 0.060237, 0.461840}, - {0.271994, 0.060994, 0.465660}, - {0.278493, 0.061978, 0.469190}, - {0.284951, 0.063168, 0.472451}, - {0.291366, 0.064553, 0.475462}, - {0.297740, 0.066117, 0.478243}, - {0.304081, 0.067835, 0.480812}, - {0.310382, 0.069702, 0.483186}, - {0.316654, 0.071690, 0.485380}, - {0.322899, 0.073782, 0.487408}, - {0.329114, 0.075972, 0.489287}, - {0.335308, 0.078236, 0.491024}, - {0.341482, 0.080564, 0.492631}, - {0.347636, 0.082946, 0.494121}, - {0.353773, 0.085373, 0.495501}, - {0.359898, 0.087831, 0.496778}, - {0.366012, 0.090314, 0.497960}, - {0.372116, 0.092816, 0.499053}, - {0.378211, 0.095332, 0.500067}, - {0.384299, 0.097855, 0.501002}, - {0.390384, 0.100379, 0.501864}, - {0.396467, 0.102902, 0.502658}, - {0.402548, 0.105420, 0.503386}, - {0.408629, 0.107930, 0.504052}, - {0.414709, 0.110431, 0.504662}, - {0.420791, 0.112920, 0.505215}, - {0.426877, 0.115395, 0.505714}, - {0.432967, 0.117855, 0.506160}, - {0.439062, 0.120298, 0.506555}, - {0.445163, 0.122724, 0.506901}, - {0.451271, 0.125132, 0.507198}, - {0.457386, 0.127522, 0.507448}, - {0.463508, 0.129893, 0.507652}, - {0.469640, 0.132245, 0.507809}, - {0.475780, 0.134577, 0.507921}, - {0.481929, 0.136891, 0.507989}, - {0.488088, 0.139186, 0.508011}, - {0.494258, 0.141462, 0.507988}, - {0.500438, 0.143719, 0.507920}, - {0.506629, 0.145958, 0.507806}, - {0.512831, 0.148179, 0.507648}, - {0.519045, 0.150383, 0.507443}, - {0.525270, 0.152569, 0.507192}, - {0.531507, 0.154739, 0.506895}, - {0.537755, 0.156894, 0.506551}, - {0.544015, 0.159033, 0.506159}, - {0.550287, 0.161158, 0.505719}, - {0.556571, 0.163269, 0.505230}, - {0.562866, 0.165368, 0.504692}, - {0.569172, 0.167454, 0.504105}, - {0.575490, 0.169530, 0.503466}, - {0.581819, 0.171596, 0.502777}, - {0.588158, 0.173652, 0.502035}, - {0.594508, 0.175701, 0.501241}, - {0.600868, 0.177743, 0.500394}, - {0.607238, 0.179779, 0.499492}, - {0.613617, 0.181811, 0.498536}, - {0.620005, 0.183840, 0.497524}, - {0.626401, 0.185867, 0.496456}, - {0.632805, 0.187893, 0.495332}, - {0.639216, 0.189921, 0.494150}, - {0.645633, 0.191952, 0.492910}, - {0.652056, 0.193986, 0.491611}, - {0.658483, 0.196027, 0.490253}, - {0.664915, 0.198075, 0.488836}, - {0.671349, 0.200133, 0.487358}, - {0.677786, 0.202203, 0.485819}, - {0.684224, 0.204286, 0.484219}, - {0.690661, 0.206384, 0.482558}, - {0.697098, 0.208501, 0.480835}, - {0.703532, 0.210638, 0.479049}, - {0.709962, 0.212797, 0.477201}, - {0.716387, 0.214982, 0.475290}, - {0.722805, 0.217194, 0.473316}, - {0.729216, 0.219437, 0.471279}, - {0.735616, 0.221713, 0.469180}, - {0.742004, 0.224025, 0.467018}, - {0.748378, 0.226377, 0.464794}, - {0.754737, 0.228772, 0.462509}, - {0.761077, 0.231214, 0.460162}, - {0.767398, 0.233705, 0.457755}, - {0.773695, 0.236249, 0.455289}, - {0.779968, 0.238851, 0.452765}, - {0.786212, 0.241514, 0.450184}, - {0.792427, 0.244242, 0.447543}, - {0.798608, 0.247040, 0.444848}, - {0.804752, 0.249911, 0.442102}, - {0.810855, 0.252861, 0.439305}, - {0.816914, 0.255895, 0.436461}, - {0.822926, 0.259016, 0.433573}, - {0.828886, 0.262229, 0.430644}, - {0.834791, 0.265540, 0.427671}, - {0.840636, 0.268953, 0.424666}, - {0.846416, 0.272473, 0.421631}, - {0.852126, 0.276106, 0.418573}, - {0.857763, 0.279857, 0.415496}, - {0.863320, 0.283729, 0.412403}, - {0.868793, 0.287728, 0.409303}, - {0.874176, 0.291859, 0.406205}, - {0.879464, 0.296125, 0.403118}, - {0.884651, 0.300530, 0.400047}, - {0.889731, 0.305079, 0.397002}, - {0.894700, 0.309773, 0.393995}, - {0.899552, 0.314616, 0.391037}, - {0.904281, 0.319610, 0.388137}, - {0.908884, 0.324755, 0.385308}, - {0.913354, 0.330052, 0.382563}, - {0.917689, 0.335500, 0.379915}, - {0.921884, 0.341098, 0.377376}, - {0.925937, 0.346844, 0.374959}, - {0.929845, 0.352734, 0.372677}, - {0.933606, 0.358764, 0.370541}, - {0.937221, 0.364929, 0.368567}, - {0.940687, 0.371224, 0.366762}, - {0.944006, 0.377643, 0.365136}, - {0.947180, 0.384178, 0.363701}, - {0.950210, 0.390820, 0.362468}, - {0.953099, 0.397563, 0.361438}, - {0.955849, 0.404400, 0.360619}, - {0.958464, 0.411324, 0.360014}, - {0.960949, 0.418323, 0.359630}, - {0.963310, 0.425390, 0.359469}, - {0.965549, 0.432519, 0.359529}, - {0.967671, 0.439703, 0.359810}, - {0.969680, 0.446936, 0.360311}, - {0.971582, 0.454210, 0.361030}, - {0.973381, 0.461520, 0.361965}, - {0.975082, 0.468861, 0.363111}, - {0.976690, 0.476226, 0.364466}, - {0.978210, 0.483612, 0.366025}, - {0.979645, 0.491014, 0.367783}, - {0.981000, 0.498428, 0.369734}, - {0.982279, 0.505851, 0.371874}, - {0.983485, 0.513280, 0.374198}, - {0.984622, 0.520713, 0.376698}, - {0.985693, 0.528148, 0.379371}, - {0.986700, 0.535582, 0.382210}, - {0.987646, 0.543015, 0.385210}, - {0.988533, 0.550446, 0.388365}, - {0.989363, 0.557873, 0.391671}, - {0.990138, 0.565296, 0.395122}, - {0.990871, 0.572706, 0.398714}, - {0.991558, 0.580107, 0.402441}, - {0.992196, 0.587502, 0.406299}, - {0.992785, 0.594891, 0.410283}, - {0.993326, 0.602275, 0.414390}, - {0.993834, 0.609644, 0.418613}, - {0.994309, 0.616999, 0.422950}, - {0.994738, 0.624350, 0.427397}, - {0.995122, 0.631696, 0.431951}, - {0.995480, 0.639027, 0.436607}, - {0.995810, 0.646344, 0.441361}, - {0.996096, 0.653659, 0.446213}, - {0.996341, 0.660969, 0.451160}, - {0.996580, 0.668256, 0.456192}, - {0.996775, 0.675541, 0.461314}, - {0.996925, 0.682828, 0.466526}, - {0.997077, 0.690088, 0.471811}, - {0.997186, 0.697349, 0.477182}, - {0.997254, 0.704611, 0.482635}, - {0.997325, 0.711848, 0.488154}, - {0.997351, 0.719089, 0.493755}, - {0.997351, 0.726324, 0.499428}, - {0.997341, 0.733545, 0.505167}, - {0.997285, 0.740772, 0.510983}, - {0.997228, 0.747981, 0.516859}, - {0.997138, 0.755190, 0.522806}, - {0.997019, 0.762398, 0.528821}, - {0.996898, 0.769591, 0.534892}, - {0.996727, 0.776795, 0.541039}, - {0.996571, 0.783977, 0.547233}, - {0.996369, 0.791167, 0.553499}, - {0.996162, 0.798348, 0.559820}, - {0.995932, 0.805527, 0.566202}, - {0.995680, 0.812706, 0.572645}, - {0.995424, 0.819875, 0.579140}, - {0.995131, 0.827052, 0.585701}, - {0.994851, 0.834213, 0.592307}, - {0.994524, 0.841387, 0.598983}, - {0.994222, 0.848540, 0.605696}, - {0.993866, 0.855711, 0.612482}, - {0.993545, 0.862859, 0.619299}, - {0.993170, 0.870024, 0.626189}, - {0.992831, 0.877168, 0.633109}, - {0.992440, 0.884330, 0.640099}, - {0.992089, 0.891470, 0.647116}, - {0.991688, 0.898627, 0.654202}, - {0.991332, 0.905763, 0.661309}, - {0.990930, 0.912915, 0.668481}, - {0.990570, 0.920049, 0.675675}, - {0.990175, 0.927196, 0.682926}, - {0.989815, 0.934329, 0.690198}, - {0.989434, 0.941470, 0.697519}, - {0.989077, 0.948604, 0.704863}, - {0.988717, 0.955742, 0.712242}, - {0.988367, 0.962878, 0.719649}, - {0.988033, 0.970012, 0.727077}, - {0.987691, 0.977154, 0.734536}, - {0.987387, 0.984288, 0.742002}, - {0.987053, 0.991438, 0.749504}}; +static double _magma_data[][3] = { + {0.001462, 0.000466, 0.013866}, {0.002258, 0.001295, 0.018331}, + {0.003279, 0.002305, 0.023708}, {0.004512, 0.003490, 0.029965}, + {0.005950, 0.004843, 0.037130}, {0.007588, 0.006356, 0.044973}, + {0.009426, 0.008022, 0.052844}, {0.011465, 0.009828, 0.060750}, + {0.013708, 0.011771, 0.068667}, {0.016156, 0.013840, 0.076603}, + {0.018815, 0.016026, 0.084584}, {0.021692, 0.018320, 0.092610}, + {0.024792, 0.020715, 0.100676}, {0.028123, 0.023201, 0.108787}, + {0.031696, 0.025765, 0.116965}, {0.035520, 0.028397, 0.125209}, + {0.039608, 0.031090, 0.133515}, {0.043830, 0.033830, 0.141886}, + {0.048062, 0.036607, 0.150327}, {0.052320, 0.039407, 0.158841}, + {0.056615, 0.042160, 0.167446}, {0.060949, 0.044794, 0.176129}, + {0.065330, 0.047318, 0.184892}, {0.069764, 0.049726, 0.193735}, + {0.074257, 0.052017, 0.202660}, {0.078815, 0.054184, 0.211667}, + {0.083446, 0.056225, 0.220755}, {0.088155, 0.058133, 0.229922}, + {0.092949, 0.059904, 0.239164}, {0.097833, 0.061531, 0.248477}, + {0.102815, 0.063010, 0.257854}, {0.107899, 0.064335, 0.267289}, + {0.113094, 0.065492, 0.276784}, {0.118405, 0.066479, 0.286321}, + {0.123833, 0.067295, 0.295879}, {0.129380, 0.067935, 0.305443}, + {0.135053, 0.068391, 0.315000}, {0.140858, 0.068654, 0.324538}, + {0.146785, 0.068738, 0.334011}, {0.152839, 0.068637, 0.343404}, + {0.159018, 0.068354, 0.352688}, {0.165308, 0.067911, 0.361816}, + {0.171713, 0.067305, 0.370771}, {0.178212, 0.066576, 0.379497}, + {0.184801, 0.065732, 0.387973}, {0.191460, 0.064818, 0.396152}, + {0.198177, 0.063862, 0.404009}, {0.204935, 0.062907, 0.411514}, + {0.211718, 0.061992, 0.418647}, {0.218512, 0.061158, 0.425392}, + {0.225302, 0.060445, 0.431742}, {0.232077, 0.059889, 0.437695}, + {0.238826, 0.059517, 0.443256}, {0.245543, 0.059352, 0.448436}, + {0.252220, 0.059415, 0.453248}, {0.258857, 0.059706, 0.457710}, + {0.265447, 0.060237, 0.461840}, {0.271994, 0.060994, 0.465660}, + {0.278493, 0.061978, 0.469190}, {0.284951, 0.063168, 0.472451}, + {0.291366, 0.064553, 0.475462}, {0.297740, 0.066117, 0.478243}, + {0.304081, 0.067835, 0.480812}, {0.310382, 0.069702, 0.483186}, + {0.316654, 0.071690, 0.485380}, {0.322899, 0.073782, 0.487408}, + {0.329114, 0.075972, 0.489287}, {0.335308, 0.078236, 0.491024}, + {0.341482, 0.080564, 0.492631}, {0.347636, 0.082946, 0.494121}, + {0.353773, 0.085373, 0.495501}, {0.359898, 0.087831, 0.496778}, + {0.366012, 0.090314, 0.497960}, {0.372116, 0.092816, 0.499053}, + {0.378211, 0.095332, 0.500067}, {0.384299, 0.097855, 0.501002}, + {0.390384, 0.100379, 0.501864}, {0.396467, 0.102902, 0.502658}, + {0.402548, 0.105420, 0.503386}, {0.408629, 0.107930, 0.504052}, + {0.414709, 0.110431, 0.504662}, {0.420791, 0.112920, 0.505215}, + {0.426877, 0.115395, 0.505714}, {0.432967, 0.117855, 0.506160}, + {0.439062, 0.120298, 0.506555}, {0.445163, 0.122724, 0.506901}, + {0.451271, 0.125132, 0.507198}, {0.457386, 0.127522, 0.507448}, + {0.463508, 0.129893, 0.507652}, {0.469640, 0.132245, 0.507809}, + {0.475780, 0.134577, 0.507921}, {0.481929, 0.136891, 0.507989}, + {0.488088, 0.139186, 0.508011}, {0.494258, 0.141462, 0.507988}, + {0.500438, 0.143719, 0.507920}, {0.506629, 0.145958, 0.507806}, + {0.512831, 0.148179, 0.507648}, {0.519045, 0.150383, 0.507443}, + {0.525270, 0.152569, 0.507192}, {0.531507, 0.154739, 0.506895}, + {0.537755, 0.156894, 0.506551}, {0.544015, 0.159033, 0.506159}, + {0.550287, 0.161158, 0.505719}, {0.556571, 0.163269, 0.505230}, + {0.562866, 0.165368, 0.504692}, {0.569172, 0.167454, 0.504105}, + {0.575490, 0.169530, 0.503466}, {0.581819, 0.171596, 0.502777}, + {0.588158, 0.173652, 0.502035}, {0.594508, 0.175701, 0.501241}, + {0.600868, 0.177743, 0.500394}, {0.607238, 0.179779, 0.499492}, + {0.613617, 0.181811, 0.498536}, {0.620005, 0.183840, 0.497524}, + {0.626401, 0.185867, 0.496456}, {0.632805, 0.187893, 0.495332}, + {0.639216, 0.189921, 0.494150}, {0.645633, 0.191952, 0.492910}, + {0.652056, 0.193986, 0.491611}, {0.658483, 0.196027, 0.490253}, + {0.664915, 0.198075, 0.488836}, {0.671349, 0.200133, 0.487358}, + {0.677786, 0.202203, 0.485819}, {0.684224, 0.204286, 0.484219}, + {0.690661, 0.206384, 0.482558}, {0.697098, 0.208501, 0.480835}, + {0.703532, 0.210638, 0.479049}, {0.709962, 0.212797, 0.477201}, + {0.716387, 0.214982, 0.475290}, {0.722805, 0.217194, 0.473316}, + {0.729216, 0.219437, 0.471279}, {0.735616, 0.221713, 0.469180}, + {0.742004, 0.224025, 0.467018}, {0.748378, 0.226377, 0.464794}, + {0.754737, 0.228772, 0.462509}, {0.761077, 0.231214, 0.460162}, + {0.767398, 0.233705, 0.457755}, {0.773695, 0.236249, 0.455289}, + {0.779968, 0.238851, 0.452765}, {0.786212, 0.241514, 0.450184}, + {0.792427, 0.244242, 0.447543}, {0.798608, 0.247040, 0.444848}, + {0.804752, 0.249911, 0.442102}, {0.810855, 0.252861, 0.439305}, + {0.816914, 0.255895, 0.436461}, {0.822926, 0.259016, 0.433573}, + {0.828886, 0.262229, 0.430644}, {0.834791, 0.265540, 0.427671}, + {0.840636, 0.268953, 0.424666}, {0.846416, 0.272473, 0.421631}, + {0.852126, 0.276106, 0.418573}, {0.857763, 0.279857, 0.415496}, + {0.863320, 0.283729, 0.412403}, {0.868793, 0.287728, 0.409303}, + {0.874176, 0.291859, 0.406205}, {0.879464, 0.296125, 0.403118}, + {0.884651, 0.300530, 0.400047}, {0.889731, 0.305079, 0.397002}, + {0.894700, 0.309773, 0.393995}, {0.899552, 0.314616, 0.391037}, + {0.904281, 0.319610, 0.388137}, {0.908884, 0.324755, 0.385308}, + {0.913354, 0.330052, 0.382563}, {0.917689, 0.335500, 0.379915}, + {0.921884, 0.341098, 0.377376}, {0.925937, 0.346844, 0.374959}, + {0.929845, 0.352734, 0.372677}, {0.933606, 0.358764, 0.370541}, + {0.937221, 0.364929, 0.368567}, {0.940687, 0.371224, 0.366762}, + {0.944006, 0.377643, 0.365136}, {0.947180, 0.384178, 0.363701}, + {0.950210, 0.390820, 0.362468}, {0.953099, 0.397563, 0.361438}, + {0.955849, 0.404400, 0.360619}, {0.958464, 0.411324, 0.360014}, + {0.960949, 0.418323, 0.359630}, {0.963310, 0.425390, 0.359469}, + {0.965549, 0.432519, 0.359529}, {0.967671, 0.439703, 0.359810}, + {0.969680, 0.446936, 0.360311}, {0.971582, 0.454210, 0.361030}, + {0.973381, 0.461520, 0.361965}, {0.975082, 0.468861, 0.363111}, + {0.976690, 0.476226, 0.364466}, {0.978210, 0.483612, 0.366025}, + {0.979645, 0.491014, 0.367783}, {0.981000, 0.498428, 0.369734}, + {0.982279, 0.505851, 0.371874}, {0.983485, 0.513280, 0.374198}, + {0.984622, 0.520713, 0.376698}, {0.985693, 0.528148, 0.379371}, + {0.986700, 0.535582, 0.382210}, {0.987646, 0.543015, 0.385210}, + {0.988533, 0.550446, 0.388365}, {0.989363, 0.557873, 0.391671}, + {0.990138, 0.565296, 0.395122}, {0.990871, 0.572706, 0.398714}, + {0.991558, 0.580107, 0.402441}, {0.992196, 0.587502, 0.406299}, + {0.992785, 0.594891, 0.410283}, {0.993326, 0.602275, 0.414390}, + {0.993834, 0.609644, 0.418613}, {0.994309, 0.616999, 0.422950}, + {0.994738, 0.624350, 0.427397}, {0.995122, 0.631696, 0.431951}, + {0.995480, 0.639027, 0.436607}, {0.995810, 0.646344, 0.441361}, + {0.996096, 0.653659, 0.446213}, {0.996341, 0.660969, 0.451160}, + {0.996580, 0.668256, 0.456192}, {0.996775, 0.675541, 0.461314}, + {0.996925, 0.682828, 0.466526}, {0.997077, 0.690088, 0.471811}, + {0.997186, 0.697349, 0.477182}, {0.997254, 0.704611, 0.482635}, + {0.997325, 0.711848, 0.488154}, {0.997351, 0.719089, 0.493755}, + {0.997351, 0.726324, 0.499428}, {0.997341, 0.733545, 0.505167}, + {0.997285, 0.740772, 0.510983}, {0.997228, 0.747981, 0.516859}, + {0.997138, 0.755190, 0.522806}, {0.997019, 0.762398, 0.528821}, + {0.996898, 0.769591, 0.534892}, {0.996727, 0.776795, 0.541039}, + {0.996571, 0.783977, 0.547233}, {0.996369, 0.791167, 0.553499}, + {0.996162, 0.798348, 0.559820}, {0.995932, 0.805527, 0.566202}, + {0.995680, 0.812706, 0.572645}, {0.995424, 0.819875, 0.579140}, + {0.995131, 0.827052, 0.585701}, {0.994851, 0.834213, 0.592307}, + {0.994524, 0.841387, 0.598983}, {0.994222, 0.848540, 0.605696}, + {0.993866, 0.855711, 0.612482}, {0.993545, 0.862859, 0.619299}, + {0.993170, 0.870024, 0.626189}, {0.992831, 0.877168, 0.633109}, + {0.992440, 0.884330, 0.640099}, {0.992089, 0.891470, 0.647116}, + {0.991688, 0.898627, 0.654202}, {0.991332, 0.905763, 0.661309}, + {0.990930, 0.912915, 0.668481}, {0.990570, 0.920049, 0.675675}, + {0.990175, 0.927196, 0.682926}, {0.989815, 0.934329, 0.690198}, + {0.989434, 0.941470, 0.697519}, {0.989077, 0.948604, 0.704863}, + {0.988717, 0.955742, 0.712242}, {0.988367, 0.962878, 0.719649}, + {0.988033, 0.970012, 0.727077}, {0.987691, 0.977154, 0.734536}, + {0.987387, 0.984288, 0.742002}, {0.987053, 0.991438, 0.749504}}; -static double _inferno_data[][3] = - {{0.001462, 0.000466, 0.013866}, - {0.002267, 0.001270, 0.018570}, - {0.003299, 0.002249, 0.024239}, - {0.004547, 0.003392, 0.030909}, - {0.006006, 0.004692, 0.038558}, - {0.007676, 0.006136, 0.046836}, - {0.009561, 0.007713, 0.055143}, - {0.011663, 0.009417, 0.063460}, - {0.013995, 0.011225, 0.071862}, - {0.016561, 0.013136, 0.080282}, - {0.019373, 0.015133, 0.088767}, - {0.022447, 0.017199, 0.097327}, - {0.025793, 0.019331, 0.105930}, - {0.029432, 0.021503, 0.114621}, - {0.033385, 0.023702, 0.123397}, - {0.037668, 0.025921, 0.132232}, - {0.042253, 0.028139, 0.141141}, - {0.046915, 0.030324, 0.150164}, - {0.051644, 0.032474, 0.159254}, - {0.056449, 0.034569, 0.168414}, - {0.061340, 0.036590, 0.177642}, - {0.066331, 0.038504, 0.186962}, - {0.071429, 0.040294, 0.196354}, - {0.076637, 0.041905, 0.205799}, - {0.081962, 0.043328, 0.215289}, - {0.087411, 0.044556, 0.224813}, - {0.092990, 0.045583, 0.234358}, - {0.098702, 0.046402, 0.243904}, - {0.104551, 0.047008, 0.253430}, - {0.110536, 0.047399, 0.262912}, - {0.116656, 0.047574, 0.272321}, - {0.122908, 0.047536, 0.281624}, - {0.129285, 0.047293, 0.290788}, - {0.135778, 0.046856, 0.299776}, - {0.142378, 0.046242, 0.308553}, - {0.149073, 0.045468, 0.317085}, - {0.155850, 0.044559, 0.325338}, - {0.162689, 0.043554, 0.333277}, - {0.169575, 0.042489, 0.340874}, - {0.176493, 0.041402, 0.348111}, - {0.183429, 0.040329, 0.354971}, - {0.190367, 0.039309, 0.361447}, - {0.197297, 0.038400, 0.367535}, - {0.204209, 0.037632, 0.373238}, - {0.211095, 0.037030, 0.378563}, - {0.217949, 0.036615, 0.383522}, - {0.224763, 0.036405, 0.388129}, - {0.231538, 0.036405, 0.392400}, - {0.238273, 0.036621, 0.396353}, - {0.244967, 0.037055, 0.400007}, - {0.251620, 0.037705, 0.403378}, - {0.258234, 0.038571, 0.406485}, - {0.264810, 0.039647, 0.409345}, - {0.271347, 0.040922, 0.411976}, - {0.277850, 0.042353, 0.414392}, - {0.284321, 0.043933, 0.416608}, - {0.290763, 0.045644, 0.418637}, - {0.297178, 0.047470, 0.420491}, - {0.303568, 0.049396, 0.422182}, - {0.309935, 0.051407, 0.423721}, - {0.316282, 0.053490, 0.425116}, - {0.322610, 0.055634, 0.426377}, - {0.328921, 0.057827, 0.427511}, - {0.335217, 0.060060, 0.428524}, - {0.341500, 0.062325, 0.429425}, - {0.347771, 0.064616, 0.430217}, - {0.354032, 0.066925, 0.430906}, - {0.360284, 0.069247, 0.431497}, - {0.366529, 0.071579, 0.431994}, - {0.372768, 0.073915, 0.432400}, - {0.379001, 0.076253, 0.432719}, - {0.385228, 0.078591, 0.432955}, - {0.391453, 0.080927, 0.433109}, - {0.397674, 0.083257, 0.433183}, - {0.403894, 0.085580, 0.433179}, - {0.410113, 0.087896, 0.433098}, - {0.416331, 0.090203, 0.432943}, - {0.422549, 0.092501, 0.432714}, - {0.428768, 0.094790, 0.432412}, - {0.434987, 0.097069, 0.432039}, - {0.441207, 0.099338, 0.431594}, - {0.447428, 0.101597, 0.431080}, - {0.453651, 0.103848, 0.430498}, - {0.459875, 0.106089, 0.429846}, - {0.466100, 0.108322, 0.429125}, - {0.472328, 0.110547, 0.428334}, - {0.478558, 0.112764, 0.427475}, - {0.484789, 0.114974, 0.426548}, - {0.491022, 0.117179, 0.425552}, - {0.497257, 0.119379, 0.424488}, - {0.503493, 0.121575, 0.423356}, - {0.509730, 0.123769, 0.422156}, - {0.515967, 0.125960, 0.420887}, - {0.522206, 0.128150, 0.419549}, - {0.528444, 0.130341, 0.418142}, - {0.534683, 0.132534, 0.416667}, - {0.540920, 0.134729, 0.415123}, - {0.547157, 0.136929, 0.413511}, - {0.553392, 0.139134, 0.411829}, - {0.559624, 0.141346, 0.410078}, - {0.565854, 0.143567, 0.408258}, - {0.572081, 0.145797, 0.406369}, - {0.578304, 0.148039, 0.404411}, - {0.584521, 0.150294, 0.402385}, - {0.590734, 0.152563, 0.400290}, - {0.596940, 0.154848, 0.398125}, - {0.603139, 0.157151, 0.395891}, - {0.609330, 0.159474, 0.393589}, - {0.615513, 0.161817, 0.391219}, - {0.621685, 0.164184, 0.388781}, - {0.627847, 0.166575, 0.386276}, - {0.633998, 0.168992, 0.383704}, - {0.640135, 0.171438, 0.381065}, - {0.646260, 0.173914, 0.378359}, - {0.652369, 0.176421, 0.375586}, - {0.658463, 0.178962, 0.372748}, - {0.664540, 0.181539, 0.369846}, - {0.670599, 0.184153, 0.366879}, - {0.676638, 0.186807, 0.363849}, - {0.682656, 0.189501, 0.360757}, - {0.688653, 0.192239, 0.357603}, - {0.694627, 0.195021, 0.354388}, - {0.700576, 0.197851, 0.351113}, - {0.706500, 0.200728, 0.347777}, - {0.712396, 0.203656, 0.344383}, - {0.718264, 0.206636, 0.340931}, - {0.724103, 0.209670, 0.337424}, - {0.729909, 0.212759, 0.333861}, - {0.735683, 0.215906, 0.330245}, - {0.741423, 0.219112, 0.326576}, - {0.747127, 0.222378, 0.322856}, - {0.752794, 0.225706, 0.319085}, - {0.758422, 0.229097, 0.315266}, - {0.764010, 0.232554, 0.311399}, - {0.769556, 0.236077, 0.307485}, - {0.775059, 0.239667, 0.303526}, - {0.780517, 0.243327, 0.299523}, - {0.785929, 0.247056, 0.295477}, - {0.791293, 0.250856, 0.291390}, - {0.796607, 0.254728, 0.287264}, - {0.801871, 0.258674, 0.283099}, - {0.807082, 0.262692, 0.278898}, - {0.812239, 0.266786, 0.274661}, - {0.817341, 0.270954, 0.270390}, - {0.822386, 0.275197, 0.266085}, - {0.827372, 0.279517, 0.261750}, - {0.832299, 0.283913, 0.257383}, - {0.837165, 0.288385, 0.252988}, - {0.841969, 0.292933, 0.248564}, - {0.846709, 0.297559, 0.244113}, - {0.851384, 0.302260, 0.239636}, - {0.855992, 0.307038, 0.235133}, - {0.860533, 0.311892, 0.230606}, - {0.865006, 0.316822, 0.226055}, - {0.869409, 0.321827, 0.221482}, - {0.873741, 0.326906, 0.216886}, - {0.878001, 0.332060, 0.212268}, - {0.882188, 0.337287, 0.207628}, - {0.886302, 0.342586, 0.202968}, - {0.890341, 0.347957, 0.198286}, - {0.894305, 0.353399, 0.193584}, - {0.898192, 0.358911, 0.188860}, - {0.902003, 0.364492, 0.184116}, - {0.905735, 0.370140, 0.179350}, - {0.909390, 0.375856, 0.174563}, - {0.912966, 0.381636, 0.169755}, - {0.916462, 0.387481, 0.164924}, - {0.919879, 0.393389, 0.160070}, - {0.923215, 0.399359, 0.155193}, - {0.926470, 0.405389, 0.150292}, - {0.929644, 0.411479, 0.145367}, - {0.932737, 0.417627, 0.140417}, - {0.935747, 0.423831, 0.135440}, - {0.938675, 0.430091, 0.130438}, - {0.941521, 0.436405, 0.125409}, - {0.944285, 0.442772, 0.120354}, - {0.946965, 0.449191, 0.115272}, - {0.949562, 0.455660, 0.110164}, - {0.952075, 0.462178, 0.105031}, - {0.954506, 0.468744, 0.099874}, - {0.956852, 0.475356, 0.094695}, - {0.959114, 0.482014, 0.089499}, - {0.961293, 0.488716, 0.084289}, - {0.963387, 0.495462, 0.079073}, - {0.965397, 0.502249, 0.073859}, - {0.967322, 0.509078, 0.068659}, - {0.969163, 0.515946, 0.063488}, - {0.970919, 0.522853, 0.058367}, - {0.972590, 0.529798, 0.053324}, - {0.974176, 0.536780, 0.048392}, - {0.975677, 0.543798, 0.043618}, - {0.977092, 0.550850, 0.039050}, - {0.978422, 0.557937, 0.034931}, - {0.979666, 0.565057, 0.031409}, - {0.980824, 0.572209, 0.028508}, - {0.981895, 0.579392, 0.026250}, - {0.982881, 0.586606, 0.024661}, - {0.983779, 0.593849, 0.023770}, - {0.984591, 0.601122, 0.023606}, - {0.985315, 0.608422, 0.024202}, - {0.985952, 0.615750, 0.025592}, - {0.986502, 0.623105, 0.027814}, - {0.986964, 0.630485, 0.030908}, - {0.987337, 0.637890, 0.034916}, - {0.987622, 0.645320, 0.039886}, - {0.987819, 0.652773, 0.045581}, - {0.987926, 0.660250, 0.051750}, - {0.987945, 0.667748, 0.058329}, - {0.987874, 0.675267, 0.065257}, - {0.987714, 0.682807, 0.072489}, - {0.987464, 0.690366, 0.079990}, - {0.987124, 0.697944, 0.087731}, - {0.986694, 0.705540, 0.095694}, - {0.986175, 0.713153, 0.103863}, - {0.985566, 0.720782, 0.112229}, - {0.984865, 0.728427, 0.120785}, - {0.984075, 0.736087, 0.129527}, - {0.983196, 0.743758, 0.138453}, - {0.982228, 0.751442, 0.147565}, - {0.981173, 0.759135, 0.156863}, - {0.980032, 0.766837, 0.166353}, - {0.978806, 0.774545, 0.176037}, - {0.977497, 0.782258, 0.185923}, - {0.976108, 0.789974, 0.196018}, - {0.974638, 0.797692, 0.206332}, - {0.973088, 0.805409, 0.216877}, - {0.971468, 0.813122, 0.227658}, - {0.969783, 0.820825, 0.238686}, - {0.968041, 0.828515, 0.249972}, - {0.966243, 0.836191, 0.261534}, - {0.964394, 0.843848, 0.273391}, - {0.962517, 0.851476, 0.285546}, - {0.960626, 0.859069, 0.298010}, - {0.958720, 0.866624, 0.310820}, - {0.956834, 0.874129, 0.323974}, - {0.954997, 0.881569, 0.337475}, - {0.953215, 0.888942, 0.351369}, - {0.951546, 0.896226, 0.365627}, - {0.950018, 0.903409, 0.380271}, - {0.948683, 0.910473, 0.395289}, - {0.947594, 0.917399, 0.410665}, - {0.946809, 0.924168, 0.426373}, - {0.946392, 0.930761, 0.442367}, - {0.946403, 0.937159, 0.458592}, - {0.946903, 0.943348, 0.474970}, - {0.947937, 0.949318, 0.491426}, - {0.949545, 0.955063, 0.507860}, - {0.951740, 0.960587, 0.524203}, - {0.954529, 0.965896, 0.540361}, - {0.957896, 0.971003, 0.556275}, - {0.961812, 0.975924, 0.571925}, - {0.966249, 0.980678, 0.587206}, - {0.971162, 0.985282, 0.602154}, - {0.976511, 0.989753, 0.616760}, - {0.982257, 0.994109, 0.631017}, - {0.988362, 0.998364, 0.644924}}; +static double _inferno_data[][3] = { + {0.001462, 0.000466, 0.013866}, {0.002267, 0.001270, 0.018570}, + {0.003299, 0.002249, 0.024239}, {0.004547, 0.003392, 0.030909}, + {0.006006, 0.004692, 0.038558}, {0.007676, 0.006136, 0.046836}, + {0.009561, 0.007713, 0.055143}, {0.011663, 0.009417, 0.063460}, + {0.013995, 0.011225, 0.071862}, {0.016561, 0.013136, 0.080282}, + {0.019373, 0.015133, 0.088767}, {0.022447, 0.017199, 0.097327}, + {0.025793, 0.019331, 0.105930}, {0.029432, 0.021503, 0.114621}, + {0.033385, 0.023702, 0.123397}, {0.037668, 0.025921, 0.132232}, + {0.042253, 0.028139, 0.141141}, {0.046915, 0.030324, 0.150164}, + {0.051644, 0.032474, 0.159254}, {0.056449, 0.034569, 0.168414}, + {0.061340, 0.036590, 0.177642}, {0.066331, 0.038504, 0.186962}, + {0.071429, 0.040294, 0.196354}, {0.076637, 0.041905, 0.205799}, + {0.081962, 0.043328, 0.215289}, {0.087411, 0.044556, 0.224813}, + {0.092990, 0.045583, 0.234358}, {0.098702, 0.046402, 0.243904}, + {0.104551, 0.047008, 0.253430}, {0.110536, 0.047399, 0.262912}, + {0.116656, 0.047574, 0.272321}, {0.122908, 0.047536, 0.281624}, + {0.129285, 0.047293, 0.290788}, {0.135778, 0.046856, 0.299776}, + {0.142378, 0.046242, 0.308553}, {0.149073, 0.045468, 0.317085}, + {0.155850, 0.044559, 0.325338}, {0.162689, 0.043554, 0.333277}, + {0.169575, 0.042489, 0.340874}, {0.176493, 0.041402, 0.348111}, + {0.183429, 0.040329, 0.354971}, {0.190367, 0.039309, 0.361447}, + {0.197297, 0.038400, 0.367535}, {0.204209, 0.037632, 0.373238}, + {0.211095, 0.037030, 0.378563}, {0.217949, 0.036615, 0.383522}, + {0.224763, 0.036405, 0.388129}, {0.231538, 0.036405, 0.392400}, + {0.238273, 0.036621, 0.396353}, {0.244967, 0.037055, 0.400007}, + {0.251620, 0.037705, 0.403378}, {0.258234, 0.038571, 0.406485}, + {0.264810, 0.039647, 0.409345}, {0.271347, 0.040922, 0.411976}, + {0.277850, 0.042353, 0.414392}, {0.284321, 0.043933, 0.416608}, + {0.290763, 0.045644, 0.418637}, {0.297178, 0.047470, 0.420491}, + {0.303568, 0.049396, 0.422182}, {0.309935, 0.051407, 0.423721}, + {0.316282, 0.053490, 0.425116}, {0.322610, 0.055634, 0.426377}, + {0.328921, 0.057827, 0.427511}, {0.335217, 0.060060, 0.428524}, + {0.341500, 0.062325, 0.429425}, {0.347771, 0.064616, 0.430217}, + {0.354032, 0.066925, 0.430906}, {0.360284, 0.069247, 0.431497}, + {0.366529, 0.071579, 0.431994}, {0.372768, 0.073915, 0.432400}, + {0.379001, 0.076253, 0.432719}, {0.385228, 0.078591, 0.432955}, + {0.391453, 0.080927, 0.433109}, {0.397674, 0.083257, 0.433183}, + {0.403894, 0.085580, 0.433179}, {0.410113, 0.087896, 0.433098}, + {0.416331, 0.090203, 0.432943}, {0.422549, 0.092501, 0.432714}, + {0.428768, 0.094790, 0.432412}, {0.434987, 0.097069, 0.432039}, + {0.441207, 0.099338, 0.431594}, {0.447428, 0.101597, 0.431080}, + {0.453651, 0.103848, 0.430498}, {0.459875, 0.106089, 0.429846}, + {0.466100, 0.108322, 0.429125}, {0.472328, 0.110547, 0.428334}, + {0.478558, 0.112764, 0.427475}, {0.484789, 0.114974, 0.426548}, + {0.491022, 0.117179, 0.425552}, {0.497257, 0.119379, 0.424488}, + {0.503493, 0.121575, 0.423356}, {0.509730, 0.123769, 0.422156}, + {0.515967, 0.125960, 0.420887}, {0.522206, 0.128150, 0.419549}, + {0.528444, 0.130341, 0.418142}, {0.534683, 0.132534, 0.416667}, + {0.540920, 0.134729, 0.415123}, {0.547157, 0.136929, 0.413511}, + {0.553392, 0.139134, 0.411829}, {0.559624, 0.141346, 0.410078}, + {0.565854, 0.143567, 0.408258}, {0.572081, 0.145797, 0.406369}, + {0.578304, 0.148039, 0.404411}, {0.584521, 0.150294, 0.402385}, + {0.590734, 0.152563, 0.400290}, {0.596940, 0.154848, 0.398125}, + {0.603139, 0.157151, 0.395891}, {0.609330, 0.159474, 0.393589}, + {0.615513, 0.161817, 0.391219}, {0.621685, 0.164184, 0.388781}, + {0.627847, 0.166575, 0.386276}, {0.633998, 0.168992, 0.383704}, + {0.640135, 0.171438, 0.381065}, {0.646260, 0.173914, 0.378359}, + {0.652369, 0.176421, 0.375586}, {0.658463, 0.178962, 0.372748}, + {0.664540, 0.181539, 0.369846}, {0.670599, 0.184153, 0.366879}, + {0.676638, 0.186807, 0.363849}, {0.682656, 0.189501, 0.360757}, + {0.688653, 0.192239, 0.357603}, {0.694627, 0.195021, 0.354388}, + {0.700576, 0.197851, 0.351113}, {0.706500, 0.200728, 0.347777}, + {0.712396, 0.203656, 0.344383}, {0.718264, 0.206636, 0.340931}, + {0.724103, 0.209670, 0.337424}, {0.729909, 0.212759, 0.333861}, + {0.735683, 0.215906, 0.330245}, {0.741423, 0.219112, 0.326576}, + {0.747127, 0.222378, 0.322856}, {0.752794, 0.225706, 0.319085}, + {0.758422, 0.229097, 0.315266}, {0.764010, 0.232554, 0.311399}, + {0.769556, 0.236077, 0.307485}, {0.775059, 0.239667, 0.303526}, + {0.780517, 0.243327, 0.299523}, {0.785929, 0.247056, 0.295477}, + {0.791293, 0.250856, 0.291390}, {0.796607, 0.254728, 0.287264}, + {0.801871, 0.258674, 0.283099}, {0.807082, 0.262692, 0.278898}, + {0.812239, 0.266786, 0.274661}, {0.817341, 0.270954, 0.270390}, + {0.822386, 0.275197, 0.266085}, {0.827372, 0.279517, 0.261750}, + {0.832299, 0.283913, 0.257383}, {0.837165, 0.288385, 0.252988}, + {0.841969, 0.292933, 0.248564}, {0.846709, 0.297559, 0.244113}, + {0.851384, 0.302260, 0.239636}, {0.855992, 0.307038, 0.235133}, + {0.860533, 0.311892, 0.230606}, {0.865006, 0.316822, 0.226055}, + {0.869409, 0.321827, 0.221482}, {0.873741, 0.326906, 0.216886}, + {0.878001, 0.332060, 0.212268}, {0.882188, 0.337287, 0.207628}, + {0.886302, 0.342586, 0.202968}, {0.890341, 0.347957, 0.198286}, + {0.894305, 0.353399, 0.193584}, {0.898192, 0.358911, 0.188860}, + {0.902003, 0.364492, 0.184116}, {0.905735, 0.370140, 0.179350}, + {0.909390, 0.375856, 0.174563}, {0.912966, 0.381636, 0.169755}, + {0.916462, 0.387481, 0.164924}, {0.919879, 0.393389, 0.160070}, + {0.923215, 0.399359, 0.155193}, {0.926470, 0.405389, 0.150292}, + {0.929644, 0.411479, 0.145367}, {0.932737, 0.417627, 0.140417}, + {0.935747, 0.423831, 0.135440}, {0.938675, 0.430091, 0.130438}, + {0.941521, 0.436405, 0.125409}, {0.944285, 0.442772, 0.120354}, + {0.946965, 0.449191, 0.115272}, {0.949562, 0.455660, 0.110164}, + {0.952075, 0.462178, 0.105031}, {0.954506, 0.468744, 0.099874}, + {0.956852, 0.475356, 0.094695}, {0.959114, 0.482014, 0.089499}, + {0.961293, 0.488716, 0.084289}, {0.963387, 0.495462, 0.079073}, + {0.965397, 0.502249, 0.073859}, {0.967322, 0.509078, 0.068659}, + {0.969163, 0.515946, 0.063488}, {0.970919, 0.522853, 0.058367}, + {0.972590, 0.529798, 0.053324}, {0.974176, 0.536780, 0.048392}, + {0.975677, 0.543798, 0.043618}, {0.977092, 0.550850, 0.039050}, + {0.978422, 0.557937, 0.034931}, {0.979666, 0.565057, 0.031409}, + {0.980824, 0.572209, 0.028508}, {0.981895, 0.579392, 0.026250}, + {0.982881, 0.586606, 0.024661}, {0.983779, 0.593849, 0.023770}, + {0.984591, 0.601122, 0.023606}, {0.985315, 0.608422, 0.024202}, + {0.985952, 0.615750, 0.025592}, {0.986502, 0.623105, 0.027814}, + {0.986964, 0.630485, 0.030908}, {0.987337, 0.637890, 0.034916}, + {0.987622, 0.645320, 0.039886}, {0.987819, 0.652773, 0.045581}, + {0.987926, 0.660250, 0.051750}, {0.987945, 0.667748, 0.058329}, + {0.987874, 0.675267, 0.065257}, {0.987714, 0.682807, 0.072489}, + {0.987464, 0.690366, 0.079990}, {0.987124, 0.697944, 0.087731}, + {0.986694, 0.705540, 0.095694}, {0.986175, 0.713153, 0.103863}, + {0.985566, 0.720782, 0.112229}, {0.984865, 0.728427, 0.120785}, + {0.984075, 0.736087, 0.129527}, {0.983196, 0.743758, 0.138453}, + {0.982228, 0.751442, 0.147565}, {0.981173, 0.759135, 0.156863}, + {0.980032, 0.766837, 0.166353}, {0.978806, 0.774545, 0.176037}, + {0.977497, 0.782258, 0.185923}, {0.976108, 0.789974, 0.196018}, + {0.974638, 0.797692, 0.206332}, {0.973088, 0.805409, 0.216877}, + {0.971468, 0.813122, 0.227658}, {0.969783, 0.820825, 0.238686}, + {0.968041, 0.828515, 0.249972}, {0.966243, 0.836191, 0.261534}, + {0.964394, 0.843848, 0.273391}, {0.962517, 0.851476, 0.285546}, + {0.960626, 0.859069, 0.298010}, {0.958720, 0.866624, 0.310820}, + {0.956834, 0.874129, 0.323974}, {0.954997, 0.881569, 0.337475}, + {0.953215, 0.888942, 0.351369}, {0.951546, 0.896226, 0.365627}, + {0.950018, 0.903409, 0.380271}, {0.948683, 0.910473, 0.395289}, + {0.947594, 0.917399, 0.410665}, {0.946809, 0.924168, 0.426373}, + {0.946392, 0.930761, 0.442367}, {0.946403, 0.937159, 0.458592}, + {0.946903, 0.943348, 0.474970}, {0.947937, 0.949318, 0.491426}, + {0.949545, 0.955063, 0.507860}, {0.951740, 0.960587, 0.524203}, + {0.954529, 0.965896, 0.540361}, {0.957896, 0.971003, 0.556275}, + {0.961812, 0.975924, 0.571925}, {0.966249, 0.980678, 0.587206}, + {0.971162, 0.985282, 0.602154}, {0.976511, 0.989753, 0.616760}, + {0.982257, 0.994109, 0.631017}, {0.988362, 0.998364, 0.644924}}; -static double _plasma_data[][3] = - {{0.050383, 0.029803, 0.527975}, - {0.063536, 0.028426, 0.533124}, - {0.075353, 0.027206, 0.538007}, - {0.086222, 0.026125, 0.542658}, - {0.096379, 0.025165, 0.547103}, - {0.105980, 0.024309, 0.551368}, - {0.115124, 0.023556, 0.555468}, - {0.123903, 0.022878, 0.559423}, - {0.132381, 0.022258, 0.563250}, - {0.140603, 0.021687, 0.566959}, - {0.148607, 0.021154, 0.570562}, - {0.156421, 0.020651, 0.574065}, - {0.164070, 0.020171, 0.577478}, - {0.171574, 0.019706, 0.580806}, - {0.178950, 0.019252, 0.584054}, - {0.186213, 0.018803, 0.587228}, - {0.193374, 0.018354, 0.590330}, - {0.200445, 0.017902, 0.593364}, - {0.207435, 0.017442, 0.596333}, - {0.214350, 0.016973, 0.599239}, - {0.221197, 0.016497, 0.602083}, - {0.227983, 0.016007, 0.604867}, - {0.234715, 0.015502, 0.607592}, - {0.241396, 0.014979, 0.610259}, - {0.248032, 0.014439, 0.612868}, - {0.254627, 0.013882, 0.615419}, - {0.261183, 0.013308, 0.617911}, - {0.267703, 0.012716, 0.620346}, - {0.274191, 0.012109, 0.622722}, - {0.280648, 0.011488, 0.625038}, - {0.287076, 0.010855, 0.627295}, - {0.293478, 0.010213, 0.629490}, - {0.299855, 0.009561, 0.631624}, - {0.306210, 0.008902, 0.633694}, - {0.312543, 0.008239, 0.635700}, - {0.318856, 0.007576, 0.637640}, - {0.325150, 0.006915, 0.639512}, - {0.331426, 0.006261, 0.641316}, - {0.337683, 0.005618, 0.643049}, - {0.343925, 0.004991, 0.644710}, - {0.350150, 0.004382, 0.646298}, - {0.356359, 0.003798, 0.647810}, - {0.362553, 0.003243, 0.649245}, - {0.368733, 0.002724, 0.650601}, - {0.374897, 0.002245, 0.651876}, - {0.381047, 0.001814, 0.653068}, - {0.387183, 0.001434, 0.654177}, - {0.393304, 0.001114, 0.655199}, - {0.399411, 0.000859, 0.656133}, - {0.405503, 0.000678, 0.656977}, - {0.411580, 0.000577, 0.657730}, - {0.417642, 0.000564, 0.658390}, - {0.423689, 0.000646, 0.658956}, - {0.429719, 0.000831, 0.659425}, - {0.435734, 0.001127, 0.659797}, - {0.441732, 0.001540, 0.660069}, - {0.447714, 0.002080, 0.660240}, - {0.453677, 0.002755, 0.660310}, - {0.459623, 0.003574, 0.660277}, - {0.465550, 0.004545, 0.660139}, - {0.471457, 0.005678, 0.659897}, - {0.477344, 0.006980, 0.659549}, - {0.483210, 0.008460, 0.659095}, - {0.489055, 0.010127, 0.658534}, - {0.494877, 0.011990, 0.657865}, - {0.500678, 0.014055, 0.657088}, - {0.506454, 0.016333, 0.656202}, - {0.512206, 0.018833, 0.655209}, - {0.517933, 0.021563, 0.654109}, - {0.523633, 0.024532, 0.652901}, - {0.529306, 0.027747, 0.651586}, - {0.534952, 0.031217, 0.650165}, - {0.540570, 0.034950, 0.648640}, - {0.546157, 0.038954, 0.647010}, - {0.551715, 0.043136, 0.645277}, - {0.557243, 0.047331, 0.643443}, - {0.562738, 0.051545, 0.641509}, - {0.568201, 0.055778, 0.639477}, - {0.573632, 0.060028, 0.637349}, - {0.579029, 0.064296, 0.635126}, - {0.584391, 0.068579, 0.632812}, - {0.589719, 0.072878, 0.630408}, - {0.595011, 0.077190, 0.627917}, - {0.600266, 0.081516, 0.625342}, - {0.605485, 0.085854, 0.622686}, - {0.610667, 0.090204, 0.619951}, - {0.615812, 0.094564, 0.617140}, - {0.620919, 0.098934, 0.614257}, - {0.625987, 0.103312, 0.611305}, - {0.631017, 0.107699, 0.608287}, - {0.636008, 0.112092, 0.605205}, - {0.640959, 0.116492, 0.602065}, - {0.645872, 0.120898, 0.598867}, - {0.650746, 0.125309, 0.595617}, - {0.655580, 0.129725, 0.592317}, - {0.660374, 0.134144, 0.588971}, - {0.665129, 0.138566, 0.585582}, - {0.669845, 0.142992, 0.582154}, - {0.674522, 0.147419, 0.578688}, - {0.679160, 0.151848, 0.575189}, - {0.683758, 0.156278, 0.571660}, - {0.688318, 0.160709, 0.568103}, - {0.692840, 0.165141, 0.564522}, - {0.697324, 0.169573, 0.560919}, - {0.701769, 0.174005, 0.557296}, - {0.706178, 0.178437, 0.553657}, - {0.710549, 0.182868, 0.550004}, - {0.714883, 0.187299, 0.546338}, - {0.719181, 0.191729, 0.542663}, - {0.723444, 0.196158, 0.538981}, - {0.727670, 0.200586, 0.535293}, - {0.731862, 0.205013, 0.531601}, - {0.736019, 0.209439, 0.527908}, - {0.740143, 0.213864, 0.524216}, - {0.744232, 0.218288, 0.520524}, - {0.748289, 0.222711, 0.516834}, - {0.752312, 0.227133, 0.513149}, - {0.756304, 0.231555, 0.509468}, - {0.760264, 0.235976, 0.505794}, - {0.764193, 0.240396, 0.502126}, - {0.768090, 0.244817, 0.498465}, - {0.771958, 0.249237, 0.494813}, - {0.775796, 0.253658, 0.491171}, - {0.779604, 0.258078, 0.487539}, - {0.783383, 0.262500, 0.483918}, - {0.787133, 0.266922, 0.480307}, - {0.790855, 0.271345, 0.476706}, - {0.794549, 0.275770, 0.473117}, - {0.798216, 0.280197, 0.469538}, - {0.801855, 0.284626, 0.465971}, - {0.805467, 0.289057, 0.462415}, - {0.809052, 0.293491, 0.458870}, - {0.812612, 0.297928, 0.455338}, - {0.816144, 0.302368, 0.451816}, - {0.819651, 0.306812, 0.448306}, - {0.823132, 0.311261, 0.444806}, - {0.826588, 0.315714, 0.441316}, - {0.830018, 0.320172, 0.437836}, - {0.833422, 0.324635, 0.434366}, - {0.836801, 0.329105, 0.430905}, - {0.840155, 0.333580, 0.427455}, - {0.843484, 0.338062, 0.424013}, - {0.846788, 0.342551, 0.420579}, - {0.850066, 0.347048, 0.417153}, - {0.853319, 0.351553, 0.413734}, - {0.856547, 0.356066, 0.410322}, - {0.859750, 0.360588, 0.406917}, - {0.862927, 0.365119, 0.403519}, - {0.866078, 0.369660, 0.400126}, - {0.869203, 0.374212, 0.396738}, - {0.872303, 0.378774, 0.393355}, - {0.875376, 0.383347, 0.389976}, - {0.878423, 0.387932, 0.386600}, - {0.881443, 0.392529, 0.383229}, - {0.884436, 0.397139, 0.379860}, - {0.887402, 0.401762, 0.376494}, - {0.890340, 0.406398, 0.373130}, - {0.893250, 0.411048, 0.369768}, - {0.896131, 0.415712, 0.366407}, - {0.898984, 0.420392, 0.363047}, - {0.901807, 0.425087, 0.359688}, - {0.904601, 0.429797, 0.356329}, - {0.907365, 0.434524, 0.352970}, - {0.910098, 0.439268, 0.349610}, - {0.912800, 0.444029, 0.346251}, - {0.915471, 0.448807, 0.342890}, - {0.918109, 0.453603, 0.339529}, - {0.920714, 0.458417, 0.336166}, - {0.923287, 0.463251, 0.332801}, - {0.925825, 0.468103, 0.329435}, - {0.928329, 0.472975, 0.326067}, - {0.930798, 0.477867, 0.322697}, - {0.933232, 0.482780, 0.319325}, - {0.935630, 0.487712, 0.315952}, - {0.937990, 0.492667, 0.312575}, - {0.940313, 0.497642, 0.309197}, - {0.942598, 0.502639, 0.305816}, - {0.944844, 0.507658, 0.302433}, - {0.947051, 0.512699, 0.299049}, - {0.949217, 0.517763, 0.295662}, - {0.951344, 0.522850, 0.292275}, - {0.953428, 0.527960, 0.288883}, - {0.955470, 0.533093, 0.285490}, - {0.957469, 0.538250, 0.282096}, - {0.959424, 0.543431, 0.278701}, - {0.961336, 0.548636, 0.275305}, - {0.963203, 0.553865, 0.271909}, - {0.965024, 0.559118, 0.268513}, - {0.966798, 0.564396, 0.265118}, - {0.968526, 0.569700, 0.261721}, - {0.970205, 0.575028, 0.258325}, - {0.971835, 0.580382, 0.254931}, - {0.973416, 0.585761, 0.251540}, - {0.974947, 0.591165, 0.248151}, - {0.976428, 0.596595, 0.244767}, - {0.977856, 0.602051, 0.241387}, - {0.979233, 0.607532, 0.238013}, - {0.980556, 0.613039, 0.234646}, - {0.981826, 0.618572, 0.231287}, - {0.983041, 0.624131, 0.227937}, - {0.984199, 0.629718, 0.224595}, - {0.985301, 0.635330, 0.221265}, - {0.986345, 0.640969, 0.217948}, - {0.987332, 0.646633, 0.214648}, - {0.988260, 0.652325, 0.211364}, - {0.989128, 0.658043, 0.208100}, - {0.989935, 0.663787, 0.204859}, - {0.990681, 0.669558, 0.201642}, - {0.991365, 0.675355, 0.198453}, - {0.991985, 0.681179, 0.195295}, - {0.992541, 0.687030, 0.192170}, - {0.993032, 0.692907, 0.189084}, - {0.993456, 0.698810, 0.186041}, - {0.993814, 0.704741, 0.183043}, - {0.994103, 0.710698, 0.180097}, - {0.994324, 0.716681, 0.177208}, - {0.994474, 0.722691, 0.174381}, - {0.994553, 0.728728, 0.171622}, - {0.994561, 0.734791, 0.168938}, - {0.994495, 0.740880, 0.166335}, - {0.994355, 0.746995, 0.163821}, - {0.994141, 0.753137, 0.161404}, - {0.993851, 0.759304, 0.159092}, - {0.993482, 0.765499, 0.156891}, - {0.993033, 0.771720, 0.154808}, - {0.992505, 0.777967, 0.152855}, - {0.991897, 0.784239, 0.151042}, - {0.991209, 0.790537, 0.149377}, - {0.990439, 0.796859, 0.147870}, - {0.989587, 0.803205, 0.146529}, - {0.988648, 0.809579, 0.145357}, - {0.987621, 0.815978, 0.144363}, - {0.986509, 0.822401, 0.143557}, - {0.985314, 0.828846, 0.142945}, - {0.984031, 0.835315, 0.142528}, - {0.982653, 0.841812, 0.142303}, - {0.981190, 0.848329, 0.142279}, - {0.979644, 0.854866, 0.142453}, - {0.977995, 0.861432, 0.142808}, - {0.976265, 0.868016, 0.143351}, - {0.974443, 0.874622, 0.144061}, - {0.972530, 0.881250, 0.144923}, - {0.970533, 0.887896, 0.145919}, - {0.968443, 0.894564, 0.147014}, - {0.966271, 0.901249, 0.148180}, - {0.964021, 0.907950, 0.149370}, - {0.961681, 0.914672, 0.150520}, - {0.959276, 0.921407, 0.151566}, - {0.956808, 0.928152, 0.152409}, - {0.954287, 0.934908, 0.152921}, - {0.951726, 0.941671, 0.152925}, - {0.949151, 0.948435, 0.152178}, - {0.946602, 0.955190, 0.150328}, - {0.944152, 0.961916, 0.146861}, - {0.941896, 0.968590, 0.140956}, - {0.940015, 0.975158, 0.131326}}; +static double _plasma_data[][3] = { + {0.050383, 0.029803, 0.527975}, {0.063536, 0.028426, 0.533124}, + {0.075353, 0.027206, 0.538007}, {0.086222, 0.026125, 0.542658}, + {0.096379, 0.025165, 0.547103}, {0.105980, 0.024309, 0.551368}, + {0.115124, 0.023556, 0.555468}, {0.123903, 0.022878, 0.559423}, + {0.132381, 0.022258, 0.563250}, {0.140603, 0.021687, 0.566959}, + {0.148607, 0.021154, 0.570562}, {0.156421, 0.020651, 0.574065}, + {0.164070, 0.020171, 0.577478}, {0.171574, 0.019706, 0.580806}, + {0.178950, 0.019252, 0.584054}, {0.186213, 0.018803, 0.587228}, + {0.193374, 0.018354, 0.590330}, {0.200445, 0.017902, 0.593364}, + {0.207435, 0.017442, 0.596333}, {0.214350, 0.016973, 0.599239}, + {0.221197, 0.016497, 0.602083}, {0.227983, 0.016007, 0.604867}, + {0.234715, 0.015502, 0.607592}, {0.241396, 0.014979, 0.610259}, + {0.248032, 0.014439, 0.612868}, {0.254627, 0.013882, 0.615419}, + {0.261183, 0.013308, 0.617911}, {0.267703, 0.012716, 0.620346}, + {0.274191, 0.012109, 0.622722}, {0.280648, 0.011488, 0.625038}, + {0.287076, 0.010855, 0.627295}, {0.293478, 0.010213, 0.629490}, + {0.299855, 0.009561, 0.631624}, {0.306210, 0.008902, 0.633694}, + {0.312543, 0.008239, 0.635700}, {0.318856, 0.007576, 0.637640}, + {0.325150, 0.006915, 0.639512}, {0.331426, 0.006261, 0.641316}, + {0.337683, 0.005618, 0.643049}, {0.343925, 0.004991, 0.644710}, + {0.350150, 0.004382, 0.646298}, {0.356359, 0.003798, 0.647810}, + {0.362553, 0.003243, 0.649245}, {0.368733, 0.002724, 0.650601}, + {0.374897, 0.002245, 0.651876}, {0.381047, 0.001814, 0.653068}, + {0.387183, 0.001434, 0.654177}, {0.393304, 0.001114, 0.655199}, + {0.399411, 0.000859, 0.656133}, {0.405503, 0.000678, 0.656977}, + {0.411580, 0.000577, 0.657730}, {0.417642, 0.000564, 0.658390}, + {0.423689, 0.000646, 0.658956}, {0.429719, 0.000831, 0.659425}, + {0.435734, 0.001127, 0.659797}, {0.441732, 0.001540, 0.660069}, + {0.447714, 0.002080, 0.660240}, {0.453677, 0.002755, 0.660310}, + {0.459623, 0.003574, 0.660277}, {0.465550, 0.004545, 0.660139}, + {0.471457, 0.005678, 0.659897}, {0.477344, 0.006980, 0.659549}, + {0.483210, 0.008460, 0.659095}, {0.489055, 0.010127, 0.658534}, + {0.494877, 0.011990, 0.657865}, {0.500678, 0.014055, 0.657088}, + {0.506454, 0.016333, 0.656202}, {0.512206, 0.018833, 0.655209}, + {0.517933, 0.021563, 0.654109}, {0.523633, 0.024532, 0.652901}, + {0.529306, 0.027747, 0.651586}, {0.534952, 0.031217, 0.650165}, + {0.540570, 0.034950, 0.648640}, {0.546157, 0.038954, 0.647010}, + {0.551715, 0.043136, 0.645277}, {0.557243, 0.047331, 0.643443}, + {0.562738, 0.051545, 0.641509}, {0.568201, 0.055778, 0.639477}, + {0.573632, 0.060028, 0.637349}, {0.579029, 0.064296, 0.635126}, + {0.584391, 0.068579, 0.632812}, {0.589719, 0.072878, 0.630408}, + {0.595011, 0.077190, 0.627917}, {0.600266, 0.081516, 0.625342}, + {0.605485, 0.085854, 0.622686}, {0.610667, 0.090204, 0.619951}, + {0.615812, 0.094564, 0.617140}, {0.620919, 0.098934, 0.614257}, + {0.625987, 0.103312, 0.611305}, {0.631017, 0.107699, 0.608287}, + {0.636008, 0.112092, 0.605205}, {0.640959, 0.116492, 0.602065}, + {0.645872, 0.120898, 0.598867}, {0.650746, 0.125309, 0.595617}, + {0.655580, 0.129725, 0.592317}, {0.660374, 0.134144, 0.588971}, + {0.665129, 0.138566, 0.585582}, {0.669845, 0.142992, 0.582154}, + {0.674522, 0.147419, 0.578688}, {0.679160, 0.151848, 0.575189}, + {0.683758, 0.156278, 0.571660}, {0.688318, 0.160709, 0.568103}, + {0.692840, 0.165141, 0.564522}, {0.697324, 0.169573, 0.560919}, + {0.701769, 0.174005, 0.557296}, {0.706178, 0.178437, 0.553657}, + {0.710549, 0.182868, 0.550004}, {0.714883, 0.187299, 0.546338}, + {0.719181, 0.191729, 0.542663}, {0.723444, 0.196158, 0.538981}, + {0.727670, 0.200586, 0.535293}, {0.731862, 0.205013, 0.531601}, + {0.736019, 0.209439, 0.527908}, {0.740143, 0.213864, 0.524216}, + {0.744232, 0.218288, 0.520524}, {0.748289, 0.222711, 0.516834}, + {0.752312, 0.227133, 0.513149}, {0.756304, 0.231555, 0.509468}, + {0.760264, 0.235976, 0.505794}, {0.764193, 0.240396, 0.502126}, + {0.768090, 0.244817, 0.498465}, {0.771958, 0.249237, 0.494813}, + {0.775796, 0.253658, 0.491171}, {0.779604, 0.258078, 0.487539}, + {0.783383, 0.262500, 0.483918}, {0.787133, 0.266922, 0.480307}, + {0.790855, 0.271345, 0.476706}, {0.794549, 0.275770, 0.473117}, + {0.798216, 0.280197, 0.469538}, {0.801855, 0.284626, 0.465971}, + {0.805467, 0.289057, 0.462415}, {0.809052, 0.293491, 0.458870}, + {0.812612, 0.297928, 0.455338}, {0.816144, 0.302368, 0.451816}, + {0.819651, 0.306812, 0.448306}, {0.823132, 0.311261, 0.444806}, + {0.826588, 0.315714, 0.441316}, {0.830018, 0.320172, 0.437836}, + {0.833422, 0.324635, 0.434366}, {0.836801, 0.329105, 0.430905}, + {0.840155, 0.333580, 0.427455}, {0.843484, 0.338062, 0.424013}, + {0.846788, 0.342551, 0.420579}, {0.850066, 0.347048, 0.417153}, + {0.853319, 0.351553, 0.413734}, {0.856547, 0.356066, 0.410322}, + {0.859750, 0.360588, 0.406917}, {0.862927, 0.365119, 0.403519}, + {0.866078, 0.369660, 0.400126}, {0.869203, 0.374212, 0.396738}, + {0.872303, 0.378774, 0.393355}, {0.875376, 0.383347, 0.389976}, + {0.878423, 0.387932, 0.386600}, {0.881443, 0.392529, 0.383229}, + {0.884436, 0.397139, 0.379860}, {0.887402, 0.401762, 0.376494}, + {0.890340, 0.406398, 0.373130}, {0.893250, 0.411048, 0.369768}, + {0.896131, 0.415712, 0.366407}, {0.898984, 0.420392, 0.363047}, + {0.901807, 0.425087, 0.359688}, {0.904601, 0.429797, 0.356329}, + {0.907365, 0.434524, 0.352970}, {0.910098, 0.439268, 0.349610}, + {0.912800, 0.444029, 0.346251}, {0.915471, 0.448807, 0.342890}, + {0.918109, 0.453603, 0.339529}, {0.920714, 0.458417, 0.336166}, + {0.923287, 0.463251, 0.332801}, {0.925825, 0.468103, 0.329435}, + {0.928329, 0.472975, 0.326067}, {0.930798, 0.477867, 0.322697}, + {0.933232, 0.482780, 0.319325}, {0.935630, 0.487712, 0.315952}, + {0.937990, 0.492667, 0.312575}, {0.940313, 0.497642, 0.309197}, + {0.942598, 0.502639, 0.305816}, {0.944844, 0.507658, 0.302433}, + {0.947051, 0.512699, 0.299049}, {0.949217, 0.517763, 0.295662}, + {0.951344, 0.522850, 0.292275}, {0.953428, 0.527960, 0.288883}, + {0.955470, 0.533093, 0.285490}, {0.957469, 0.538250, 0.282096}, + {0.959424, 0.543431, 0.278701}, {0.961336, 0.548636, 0.275305}, + {0.963203, 0.553865, 0.271909}, {0.965024, 0.559118, 0.268513}, + {0.966798, 0.564396, 0.265118}, {0.968526, 0.569700, 0.261721}, + {0.970205, 0.575028, 0.258325}, {0.971835, 0.580382, 0.254931}, + {0.973416, 0.585761, 0.251540}, {0.974947, 0.591165, 0.248151}, + {0.976428, 0.596595, 0.244767}, {0.977856, 0.602051, 0.241387}, + {0.979233, 0.607532, 0.238013}, {0.980556, 0.613039, 0.234646}, + {0.981826, 0.618572, 0.231287}, {0.983041, 0.624131, 0.227937}, + {0.984199, 0.629718, 0.224595}, {0.985301, 0.635330, 0.221265}, + {0.986345, 0.640969, 0.217948}, {0.987332, 0.646633, 0.214648}, + {0.988260, 0.652325, 0.211364}, {0.989128, 0.658043, 0.208100}, + {0.989935, 0.663787, 0.204859}, {0.990681, 0.669558, 0.201642}, + {0.991365, 0.675355, 0.198453}, {0.991985, 0.681179, 0.195295}, + {0.992541, 0.687030, 0.192170}, {0.993032, 0.692907, 0.189084}, + {0.993456, 0.698810, 0.186041}, {0.993814, 0.704741, 0.183043}, + {0.994103, 0.710698, 0.180097}, {0.994324, 0.716681, 0.177208}, + {0.994474, 0.722691, 0.174381}, {0.994553, 0.728728, 0.171622}, + {0.994561, 0.734791, 0.168938}, {0.994495, 0.740880, 0.166335}, + {0.994355, 0.746995, 0.163821}, {0.994141, 0.753137, 0.161404}, + {0.993851, 0.759304, 0.159092}, {0.993482, 0.765499, 0.156891}, + {0.993033, 0.771720, 0.154808}, {0.992505, 0.777967, 0.152855}, + {0.991897, 0.784239, 0.151042}, {0.991209, 0.790537, 0.149377}, + {0.990439, 0.796859, 0.147870}, {0.989587, 0.803205, 0.146529}, + {0.988648, 0.809579, 0.145357}, {0.987621, 0.815978, 0.144363}, + {0.986509, 0.822401, 0.143557}, {0.985314, 0.828846, 0.142945}, + {0.984031, 0.835315, 0.142528}, {0.982653, 0.841812, 0.142303}, + {0.981190, 0.848329, 0.142279}, {0.979644, 0.854866, 0.142453}, + {0.977995, 0.861432, 0.142808}, {0.976265, 0.868016, 0.143351}, + {0.974443, 0.874622, 0.144061}, {0.972530, 0.881250, 0.144923}, + {0.970533, 0.887896, 0.145919}, {0.968443, 0.894564, 0.147014}, + {0.966271, 0.901249, 0.148180}, {0.964021, 0.907950, 0.149370}, + {0.961681, 0.914672, 0.150520}, {0.959276, 0.921407, 0.151566}, + {0.956808, 0.928152, 0.152409}, {0.954287, 0.934908, 0.152921}, + {0.951726, 0.941671, 0.152925}, {0.949151, 0.948435, 0.152178}, + {0.946602, 0.955190, 0.150328}, {0.944152, 0.961916, 0.146861}, + {0.941896, 0.968590, 0.140956}, {0.940015, 0.975158, 0.131326}}; -static double _viridis_data[][3] = - {{0.267004, 0.004874, 0.329415}, - {0.268510, 0.009605, 0.335427}, - {0.269944, 0.014625, 0.341379}, - {0.271305, 0.019942, 0.347269}, - {0.272594, 0.025563, 0.353093}, - {0.273809, 0.031497, 0.358853}, - {0.274952, 0.037752, 0.364543}, - {0.276022, 0.044167, 0.370164}, - {0.277018, 0.050344, 0.375715}, - {0.277941, 0.056324, 0.381191}, - {0.278791, 0.062145, 0.386592}, - {0.279566, 0.067836, 0.391917}, - {0.280267, 0.073417, 0.397163}, - {0.280894, 0.078907, 0.402329}, - {0.281446, 0.084320, 0.407414}, - {0.281924, 0.089666, 0.412415}, - {0.282327, 0.094955, 0.417331}, - {0.282656, 0.100196, 0.422160}, - {0.282910, 0.105393, 0.426902}, - {0.283091, 0.110553, 0.431554}, - {0.283197, 0.115680, 0.436115}, - {0.283229, 0.120777, 0.440584}, - {0.283187, 0.125848, 0.444960}, - {0.283072, 0.130895, 0.449241}, - {0.282884, 0.135920, 0.453427}, - {0.282623, 0.140926, 0.457517}, - {0.282290, 0.145912, 0.461510}, - {0.281887, 0.150881, 0.465405}, - {0.281412, 0.155834, 0.469201}, - {0.280868, 0.160771, 0.472899}, - {0.280255, 0.165693, 0.476498}, - {0.279574, 0.170599, 0.479997}, - {0.278826, 0.175490, 0.483397}, - {0.278012, 0.180367, 0.486697}, - {0.277134, 0.185228, 0.489898}, - {0.276194, 0.190074, 0.493001}, - {0.275191, 0.194905, 0.496005}, - {0.274128, 0.199721, 0.498911}, - {0.273006, 0.204520, 0.501721}, - {0.271828, 0.209303, 0.504434}, - {0.270595, 0.214069, 0.507052}, - {0.269308, 0.218818, 0.509577}, - {0.267968, 0.223549, 0.512008}, - {0.266580, 0.228262, 0.514349}, - {0.265145, 0.232956, 0.516599}, - {0.263663, 0.237631, 0.518762}, - {0.262138, 0.242286, 0.520837}, - {0.260571, 0.246922, 0.522828}, - {0.258965, 0.251537, 0.524736}, - {0.257322, 0.256130, 0.526563}, - {0.255645, 0.260703, 0.528312}, - {0.253935, 0.265254, 0.529983}, - {0.252194, 0.269783, 0.531579}, - {0.250425, 0.274290, 0.533103}, - {0.248629, 0.278775, 0.534556}, - {0.246811, 0.283237, 0.535941}, - {0.244972, 0.287675, 0.537260}, - {0.243113, 0.292092, 0.538516}, - {0.241237, 0.296485, 0.539709}, - {0.239346, 0.300855, 0.540844}, - {0.237441, 0.305202, 0.541921}, - {0.235526, 0.309527, 0.542944}, - {0.233603, 0.313828, 0.543914}, - {0.231674, 0.318106, 0.544834}, - {0.229739, 0.322361, 0.545706}, - {0.227802, 0.326594, 0.546532}, - {0.225863, 0.330805, 0.547314}, - {0.223925, 0.334994, 0.548053}, - {0.221989, 0.339161, 0.548752}, - {0.220057, 0.343307, 0.549413}, - {0.218130, 0.347432, 0.550038}, - {0.216210, 0.351535, 0.550627}, - {0.214298, 0.355619, 0.551184}, - {0.212395, 0.359683, 0.551710}, - {0.210503, 0.363727, 0.552206}, - {0.208623, 0.367752, 0.552675}, - {0.206756, 0.371758, 0.553117}, - {0.204903, 0.375746, 0.553533}, - {0.203063, 0.379716, 0.553925}, - {0.201239, 0.383670, 0.554294}, - {0.199430, 0.387607, 0.554642}, - {0.197636, 0.391528, 0.554969}, - {0.195860, 0.395433, 0.555276}, - {0.194100, 0.399323, 0.555565}, - {0.192357, 0.403199, 0.555836}, - {0.190631, 0.407061, 0.556089}, - {0.188923, 0.410910, 0.556326}, - {0.187231, 0.414746, 0.556547}, - {0.185556, 0.418570, 0.556753}, - {0.183898, 0.422383, 0.556944}, - {0.182256, 0.426184, 0.557120}, - {0.180629, 0.429975, 0.557282}, - {0.179019, 0.433756, 0.557430}, - {0.177423, 0.437527, 0.557565}, - {0.175841, 0.441290, 0.557685}, - {0.174274, 0.445044, 0.557792}, - {0.172719, 0.448791, 0.557885}, - {0.171176, 0.452530, 0.557965}, - {0.169646, 0.456262, 0.558030}, - {0.168126, 0.459988, 0.558082}, - {0.166617, 0.463708, 0.558119}, - {0.165117, 0.467423, 0.558141}, - {0.163625, 0.471133, 0.558148}, - {0.162142, 0.474838, 0.558140}, - {0.160665, 0.478540, 0.558115}, - {0.159194, 0.482237, 0.558073}, - {0.157729, 0.485932, 0.558013}, - {0.156270, 0.489624, 0.557936}, - {0.154815, 0.493313, 0.557840}, - {0.153364, 0.497000, 0.557724}, - {0.151918, 0.500685, 0.557587}, - {0.150476, 0.504369, 0.557430}, - {0.149039, 0.508051, 0.557250}, - {0.147607, 0.511733, 0.557049}, - {0.146180, 0.515413, 0.556823}, - {0.144759, 0.519093, 0.556572}, - {0.143343, 0.522773, 0.556295}, - {0.141935, 0.526453, 0.555991}, - {0.140536, 0.530132, 0.555659}, - {0.139147, 0.533812, 0.555298}, - {0.137770, 0.537492, 0.554906}, - {0.136408, 0.541173, 0.554483}, - {0.135066, 0.544853, 0.554029}, - {0.133743, 0.548535, 0.553541}, - {0.132444, 0.552216, 0.553018}, - {0.131172, 0.555899, 0.552459}, - {0.129933, 0.559582, 0.551864}, - {0.128729, 0.563265, 0.551229}, - {0.127568, 0.566949, 0.550556}, - {0.126453, 0.570633, 0.549841}, - {0.125394, 0.574318, 0.549086}, - {0.124395, 0.578002, 0.548287}, - {0.123463, 0.581687, 0.547445}, - {0.122606, 0.585371, 0.546557}, - {0.121831, 0.589055, 0.545623}, - {0.121148, 0.592739, 0.544641}, - {0.120565, 0.596422, 0.543611}, - {0.120092, 0.600104, 0.542530}, - {0.119738, 0.603785, 0.541400}, - {0.119512, 0.607464, 0.540218}, - {0.119423, 0.611141, 0.538982}, - {0.119483, 0.614817, 0.537692}, - {0.119699, 0.618490, 0.536347}, - {0.120081, 0.622161, 0.534946}, - {0.120638, 0.625828, 0.533488}, - {0.121380, 0.629492, 0.531973}, - {0.122312, 0.633153, 0.530398}, - {0.123444, 0.636809, 0.528763}, - {0.124780, 0.640461, 0.527068}, - {0.126326, 0.644107, 0.525311}, - {0.128087, 0.647749, 0.523491}, - {0.130067, 0.651384, 0.521608}, - {0.132268, 0.655014, 0.519661}, - {0.134692, 0.658636, 0.517649}, - {0.137339, 0.662252, 0.515571}, - {0.140210, 0.665859, 0.513427}, - {0.143303, 0.669459, 0.511215}, - {0.146616, 0.673050, 0.508936}, - {0.150148, 0.676631, 0.506589}, - {0.153894, 0.680203, 0.504172}, - {0.157851, 0.683765, 0.501686}, - {0.162016, 0.687316, 0.499129}, - {0.166383, 0.690856, 0.496502}, - {0.170948, 0.694384, 0.493803}, - {0.175707, 0.697900, 0.491033}, - {0.180653, 0.701402, 0.488189}, - {0.185783, 0.704891, 0.485273}, - {0.191090, 0.708366, 0.482284}, - {0.196571, 0.711827, 0.479221}, - {0.202219, 0.715272, 0.476084}, - {0.208030, 0.718701, 0.472873}, - {0.214000, 0.722114, 0.469588}, - {0.220124, 0.725509, 0.466226}, - {0.226397, 0.728888, 0.462789}, - {0.232815, 0.732247, 0.459277}, - {0.239374, 0.735588, 0.455688}, - {0.246070, 0.738910, 0.452024}, - {0.252899, 0.742211, 0.448284}, - {0.259857, 0.745492, 0.444467}, - {0.266941, 0.748751, 0.440573}, - {0.274149, 0.751988, 0.436601}, - {0.281477, 0.755203, 0.432552}, - {0.288921, 0.758394, 0.428426}, - {0.296479, 0.761561, 0.424223}, - {0.304148, 0.764704, 0.419943}, - {0.311925, 0.767822, 0.415586}, - {0.319809, 0.770914, 0.411152}, - {0.327796, 0.773980, 0.406640}, - {0.335885, 0.777018, 0.402049}, - {0.344074, 0.780029, 0.397381}, - {0.352360, 0.783011, 0.392636}, - {0.360741, 0.785964, 0.387814}, - {0.369214, 0.788888, 0.382914}, - {0.377779, 0.791781, 0.377939}, - {0.386433, 0.794644, 0.372886}, - {0.395174, 0.797475, 0.367757}, - {0.404001, 0.800275, 0.362552}, - {0.412913, 0.803041, 0.357269}, - {0.421908, 0.805774, 0.351910}, - {0.430983, 0.808473, 0.346476}, - {0.440137, 0.811138, 0.340967}, - {0.449368, 0.813768, 0.335384}, - {0.458674, 0.816363, 0.329727}, - {0.468053, 0.818921, 0.323998}, - {0.477504, 0.821444, 0.318195}, - {0.487026, 0.823929, 0.312321}, - {0.496615, 0.826376, 0.306377}, - {0.506271, 0.828786, 0.300362}, - {0.515992, 0.831158, 0.294279}, - {0.525776, 0.833491, 0.288127}, - {0.535621, 0.835785, 0.281908}, - {0.545524, 0.838039, 0.275626}, - {0.555484, 0.840254, 0.269281}, - {0.565498, 0.842430, 0.262877}, - {0.575563, 0.844566, 0.256415}, - {0.585678, 0.846661, 0.249897}, - {0.595839, 0.848717, 0.243329}, - {0.606045, 0.850733, 0.236712}, - {0.616293, 0.852709, 0.230052}, - {0.626579, 0.854645, 0.223353}, - {0.636902, 0.856542, 0.216620}, - {0.647257, 0.858400, 0.209861}, - {0.657642, 0.860219, 0.203082}, - {0.668054, 0.861999, 0.196293}, - {0.678489, 0.863742, 0.189503}, - {0.688944, 0.865448, 0.182725}, - {0.699415, 0.867117, 0.175971}, - {0.709898, 0.868751, 0.169257}, - {0.720391, 0.870350, 0.162603}, - {0.730889, 0.871916, 0.156029}, - {0.741388, 0.873449, 0.149561}, - {0.751884, 0.874951, 0.143228}, - {0.762373, 0.876424, 0.137064}, - {0.772852, 0.877868, 0.131109}, - {0.783315, 0.879285, 0.125405}, - {0.793760, 0.880678, 0.120005}, - {0.804182, 0.882046, 0.114965}, - {0.814576, 0.883393, 0.110347}, - {0.824940, 0.884720, 0.106217}, - {0.835270, 0.886029, 0.102646}, - {0.845561, 0.887322, 0.099702}, - {0.855810, 0.888601, 0.097452}, - {0.866013, 0.889868, 0.095953}, - {0.876168, 0.891125, 0.095250}, - {0.886271, 0.892374, 0.095374}, - {0.896320, 0.893616, 0.096335}, - {0.906311, 0.894855, 0.098125}, - {0.916242, 0.896091, 0.100717}, - {0.926106, 0.897330, 0.104071}, - {0.935904, 0.898570, 0.108131}, - {0.945636, 0.899815, 0.112838}, - {0.955300, 0.901065, 0.118128}, - {0.964894, 0.902323, 0.123941}, - {0.974417, 0.903590, 0.130215}, - {0.983868, 0.904867, 0.136897}, - {0.993248, 0.906157, 0.143936}}; +static double _viridis_data[][3] = { + {0.267004, 0.004874, 0.329415}, {0.268510, 0.009605, 0.335427}, + {0.269944, 0.014625, 0.341379}, {0.271305, 0.019942, 0.347269}, + {0.272594, 0.025563, 0.353093}, {0.273809, 0.031497, 0.358853}, + {0.274952, 0.037752, 0.364543}, {0.276022, 0.044167, 0.370164}, + {0.277018, 0.050344, 0.375715}, {0.277941, 0.056324, 0.381191}, + {0.278791, 0.062145, 0.386592}, {0.279566, 0.067836, 0.391917}, + {0.280267, 0.073417, 0.397163}, {0.280894, 0.078907, 0.402329}, + {0.281446, 0.084320, 0.407414}, {0.281924, 0.089666, 0.412415}, + {0.282327, 0.094955, 0.417331}, {0.282656, 0.100196, 0.422160}, + {0.282910, 0.105393, 0.426902}, {0.283091, 0.110553, 0.431554}, + {0.283197, 0.115680, 0.436115}, {0.283229, 0.120777, 0.440584}, + {0.283187, 0.125848, 0.444960}, {0.283072, 0.130895, 0.449241}, + {0.282884, 0.135920, 0.453427}, {0.282623, 0.140926, 0.457517}, + {0.282290, 0.145912, 0.461510}, {0.281887, 0.150881, 0.465405}, + {0.281412, 0.155834, 0.469201}, {0.280868, 0.160771, 0.472899}, + {0.280255, 0.165693, 0.476498}, {0.279574, 0.170599, 0.479997}, + {0.278826, 0.175490, 0.483397}, {0.278012, 0.180367, 0.486697}, + {0.277134, 0.185228, 0.489898}, {0.276194, 0.190074, 0.493001}, + {0.275191, 0.194905, 0.496005}, {0.274128, 0.199721, 0.498911}, + {0.273006, 0.204520, 0.501721}, {0.271828, 0.209303, 0.504434}, + {0.270595, 0.214069, 0.507052}, {0.269308, 0.218818, 0.509577}, + {0.267968, 0.223549, 0.512008}, {0.266580, 0.228262, 0.514349}, + {0.265145, 0.232956, 0.516599}, {0.263663, 0.237631, 0.518762}, + {0.262138, 0.242286, 0.520837}, {0.260571, 0.246922, 0.522828}, + {0.258965, 0.251537, 0.524736}, {0.257322, 0.256130, 0.526563}, + {0.255645, 0.260703, 0.528312}, {0.253935, 0.265254, 0.529983}, + {0.252194, 0.269783, 0.531579}, {0.250425, 0.274290, 0.533103}, + {0.248629, 0.278775, 0.534556}, {0.246811, 0.283237, 0.535941}, + {0.244972, 0.287675, 0.537260}, {0.243113, 0.292092, 0.538516}, + {0.241237, 0.296485, 0.539709}, {0.239346, 0.300855, 0.540844}, + {0.237441, 0.305202, 0.541921}, {0.235526, 0.309527, 0.542944}, + {0.233603, 0.313828, 0.543914}, {0.231674, 0.318106, 0.544834}, + {0.229739, 0.322361, 0.545706}, {0.227802, 0.326594, 0.546532}, + {0.225863, 0.330805, 0.547314}, {0.223925, 0.334994, 0.548053}, + {0.221989, 0.339161, 0.548752}, {0.220057, 0.343307, 0.549413}, + {0.218130, 0.347432, 0.550038}, {0.216210, 0.351535, 0.550627}, + {0.214298, 0.355619, 0.551184}, {0.212395, 0.359683, 0.551710}, + {0.210503, 0.363727, 0.552206}, {0.208623, 0.367752, 0.552675}, + {0.206756, 0.371758, 0.553117}, {0.204903, 0.375746, 0.553533}, + {0.203063, 0.379716, 0.553925}, {0.201239, 0.383670, 0.554294}, + {0.199430, 0.387607, 0.554642}, {0.197636, 0.391528, 0.554969}, + {0.195860, 0.395433, 0.555276}, {0.194100, 0.399323, 0.555565}, + {0.192357, 0.403199, 0.555836}, {0.190631, 0.407061, 0.556089}, + {0.188923, 0.410910, 0.556326}, {0.187231, 0.414746, 0.556547}, + {0.185556, 0.418570, 0.556753}, {0.183898, 0.422383, 0.556944}, + {0.182256, 0.426184, 0.557120}, {0.180629, 0.429975, 0.557282}, + {0.179019, 0.433756, 0.557430}, {0.177423, 0.437527, 0.557565}, + {0.175841, 0.441290, 0.557685}, {0.174274, 0.445044, 0.557792}, + {0.172719, 0.448791, 0.557885}, {0.171176, 0.452530, 0.557965}, + {0.169646, 0.456262, 0.558030}, {0.168126, 0.459988, 0.558082}, + {0.166617, 0.463708, 0.558119}, {0.165117, 0.467423, 0.558141}, + {0.163625, 0.471133, 0.558148}, {0.162142, 0.474838, 0.558140}, + {0.160665, 0.478540, 0.558115}, {0.159194, 0.482237, 0.558073}, + {0.157729, 0.485932, 0.558013}, {0.156270, 0.489624, 0.557936}, + {0.154815, 0.493313, 0.557840}, {0.153364, 0.497000, 0.557724}, + {0.151918, 0.500685, 0.557587}, {0.150476, 0.504369, 0.557430}, + {0.149039, 0.508051, 0.557250}, {0.147607, 0.511733, 0.557049}, + {0.146180, 0.515413, 0.556823}, {0.144759, 0.519093, 0.556572}, + {0.143343, 0.522773, 0.556295}, {0.141935, 0.526453, 0.555991}, + {0.140536, 0.530132, 0.555659}, {0.139147, 0.533812, 0.555298}, + {0.137770, 0.537492, 0.554906}, {0.136408, 0.541173, 0.554483}, + {0.135066, 0.544853, 0.554029}, {0.133743, 0.548535, 0.553541}, + {0.132444, 0.552216, 0.553018}, {0.131172, 0.555899, 0.552459}, + {0.129933, 0.559582, 0.551864}, {0.128729, 0.563265, 0.551229}, + {0.127568, 0.566949, 0.550556}, {0.126453, 0.570633, 0.549841}, + {0.125394, 0.574318, 0.549086}, {0.124395, 0.578002, 0.548287}, + {0.123463, 0.581687, 0.547445}, {0.122606, 0.585371, 0.546557}, + {0.121831, 0.589055, 0.545623}, {0.121148, 0.592739, 0.544641}, + {0.120565, 0.596422, 0.543611}, {0.120092, 0.600104, 0.542530}, + {0.119738, 0.603785, 0.541400}, {0.119512, 0.607464, 0.540218}, + {0.119423, 0.611141, 0.538982}, {0.119483, 0.614817, 0.537692}, + {0.119699, 0.618490, 0.536347}, {0.120081, 0.622161, 0.534946}, + {0.120638, 0.625828, 0.533488}, {0.121380, 0.629492, 0.531973}, + {0.122312, 0.633153, 0.530398}, {0.123444, 0.636809, 0.528763}, + {0.124780, 0.640461, 0.527068}, {0.126326, 0.644107, 0.525311}, + {0.128087, 0.647749, 0.523491}, {0.130067, 0.651384, 0.521608}, + {0.132268, 0.655014, 0.519661}, {0.134692, 0.658636, 0.517649}, + {0.137339, 0.662252, 0.515571}, {0.140210, 0.665859, 0.513427}, + {0.143303, 0.669459, 0.511215}, {0.146616, 0.673050, 0.508936}, + {0.150148, 0.676631, 0.506589}, {0.153894, 0.680203, 0.504172}, + {0.157851, 0.683765, 0.501686}, {0.162016, 0.687316, 0.499129}, + {0.166383, 0.690856, 0.496502}, {0.170948, 0.694384, 0.493803}, + {0.175707, 0.697900, 0.491033}, {0.180653, 0.701402, 0.488189}, + {0.185783, 0.704891, 0.485273}, {0.191090, 0.708366, 0.482284}, + {0.196571, 0.711827, 0.479221}, {0.202219, 0.715272, 0.476084}, + {0.208030, 0.718701, 0.472873}, {0.214000, 0.722114, 0.469588}, + {0.220124, 0.725509, 0.466226}, {0.226397, 0.728888, 0.462789}, + {0.232815, 0.732247, 0.459277}, {0.239374, 0.735588, 0.455688}, + {0.246070, 0.738910, 0.452024}, {0.252899, 0.742211, 0.448284}, + {0.259857, 0.745492, 0.444467}, {0.266941, 0.748751, 0.440573}, + {0.274149, 0.751988, 0.436601}, {0.281477, 0.755203, 0.432552}, + {0.288921, 0.758394, 0.428426}, {0.296479, 0.761561, 0.424223}, + {0.304148, 0.764704, 0.419943}, {0.311925, 0.767822, 0.415586}, + {0.319809, 0.770914, 0.411152}, {0.327796, 0.773980, 0.406640}, + {0.335885, 0.777018, 0.402049}, {0.344074, 0.780029, 0.397381}, + {0.352360, 0.783011, 0.392636}, {0.360741, 0.785964, 0.387814}, + {0.369214, 0.788888, 0.382914}, {0.377779, 0.791781, 0.377939}, + {0.386433, 0.794644, 0.372886}, {0.395174, 0.797475, 0.367757}, + {0.404001, 0.800275, 0.362552}, {0.412913, 0.803041, 0.357269}, + {0.421908, 0.805774, 0.351910}, {0.430983, 0.808473, 0.346476}, + {0.440137, 0.811138, 0.340967}, {0.449368, 0.813768, 0.335384}, + {0.458674, 0.816363, 0.329727}, {0.468053, 0.818921, 0.323998}, + {0.477504, 0.821444, 0.318195}, {0.487026, 0.823929, 0.312321}, + {0.496615, 0.826376, 0.306377}, {0.506271, 0.828786, 0.300362}, + {0.515992, 0.831158, 0.294279}, {0.525776, 0.833491, 0.288127}, + {0.535621, 0.835785, 0.281908}, {0.545524, 0.838039, 0.275626}, + {0.555484, 0.840254, 0.269281}, {0.565498, 0.842430, 0.262877}, + {0.575563, 0.844566, 0.256415}, {0.585678, 0.846661, 0.249897}, + {0.595839, 0.848717, 0.243329}, {0.606045, 0.850733, 0.236712}, + {0.616293, 0.852709, 0.230052}, {0.626579, 0.854645, 0.223353}, + {0.636902, 0.856542, 0.216620}, {0.647257, 0.858400, 0.209861}, + {0.657642, 0.860219, 0.203082}, {0.668054, 0.861999, 0.196293}, + {0.678489, 0.863742, 0.189503}, {0.688944, 0.865448, 0.182725}, + {0.699415, 0.867117, 0.175971}, {0.709898, 0.868751, 0.169257}, + {0.720391, 0.870350, 0.162603}, {0.730889, 0.871916, 0.156029}, + {0.741388, 0.873449, 0.149561}, {0.751884, 0.874951, 0.143228}, + {0.762373, 0.876424, 0.137064}, {0.772852, 0.877868, 0.131109}, + {0.783315, 0.879285, 0.125405}, {0.793760, 0.880678, 0.120005}, + {0.804182, 0.882046, 0.114965}, {0.814576, 0.883393, 0.110347}, + {0.824940, 0.884720, 0.106217}, {0.835270, 0.886029, 0.102646}, + {0.845561, 0.887322, 0.099702}, {0.855810, 0.888601, 0.097452}, + {0.866013, 0.889868, 0.095953}, {0.876168, 0.891125, 0.095250}, + {0.886271, 0.892374, 0.095374}, {0.896320, 0.893616, 0.096335}, + {0.906311, 0.894855, 0.098125}, {0.916242, 0.896091, 0.100717}, + {0.926106, 0.897330, 0.104071}, {0.935904, 0.898570, 0.108131}, + {0.945636, 0.899815, 0.112838}, {0.955300, 0.901065, 0.118128}, + {0.964894, 0.902323, 0.123941}, {0.974417, 0.903590, 0.130215}, + {0.983868, 0.904867, 0.136897}, {0.993248, 0.906157, 0.143936}}; -void ColorTable_Recompute(GmshColorTable * ct) +void ColorTable_Recompute(GmshColorTable *ct) { double s, t, gamma; int r, g, b, a; @@ -1112,15 +597,14 @@ void ColorTable_Recompute(GmshColorTable * ct) int rotation = ct->ipar[COLORTABLE_ROTATION]; // resize fixed-size colormaps: - switch (ct->ipar[COLORTABLE_NUMBER]) { - case 20: ct->size = sizeof(_magma_data)/(3*sizeof(double)); break; - case 21: ct->size = sizeof(_inferno_data)/(3*sizeof(double)); break; - case 22: ct->size = sizeof(_plasma_data)/(3*sizeof(double)); break; - case 23: ct->size = sizeof(_viridis_data)/(3*sizeof(double)); break; + switch(ct->ipar[COLORTABLE_NUMBER]) { + case 20: ct->size = sizeof(_magma_data) / (3 * sizeof(double)); break; + case 21: ct->size = sizeof(_inferno_data) / (3 * sizeof(double)); break; + case 22: ct->size = sizeof(_plasma_data) / (3 * sizeof(double)); break; + case 23: ct->size = sizeof(_viridis_data) / (3 * sizeof(double)); break; } for(int i = 0; i < ct->size; i++) { - if(ct->size > 1) { if(i + rotation < 0) s = (double)(i + rotation + ct->size) / (double)(ct->size - 1); @@ -1132,44 +616,38 @@ void ColorTable_Recompute(GmshColorTable * ct) else s = 0.; - if(ct->ipar[COLORTABLE_SWAP]) - s = 1.0 - s; + if(ct->ipar[COLORTABLE_SWAP]) s = 1.0 - s; - switch (ct->ipar[COLORTABLE_NUMBER]) { - case 0: // all black + switch(ct->ipar[COLORTABLE_NUMBER]) { + case 0: // all black r = g = b = 0; break; - case 1: // vis5d + case 1: // vis5d t = (curvature + 1.4) * (s - (1. + bias) / 2.); r = (int)(128.0 + 127.0 * atan(7.0 * t) / 1.57); g = (int)(128.0 + 127.0 * (2 * exp(-7 * t * t) - 1)); b = (int)(128.0 + 127.0 * atan(-7.0 * t) / 1.57); break; case 2: // matlab "jet" - { - double ii = (double)(s - bias) * 128.; - if(ii < 0) ii = 0; - if(ii > 128) ii = 128; - double rr = - ii <= 46 ? 0. : - ii >= 111 ? -0.03125 * (ii - 111) + 1. : - ii >= 78 ? 1. : - 0.03125 * (ii - 46); - double gg = - ii <= 14 || ii >= 111 ? 0. : - ii >= 79 ? -0.03125 * (ii - 111) : - ii <= 46 ? 0.03125 * (ii - 14) : - 1.; - double bb = - ii >= 79 ? 0. : - ii >= 47 ? -0.03125 * (ii - 79) : - ii <= 14 ? 0.03125 * (ii - 14) + 1.: - 1.; - r = (int)(rr * 255.); - g = (int)(gg * 255.); - b = (int)(bb * 255.); - } - break; + { + double ii = (double)(s - bias) * 128.; + if(ii < 0) ii = 0; + if(ii > 128) ii = 128; + double rr = ii <= 46 ? 0. : + ii >= 111 ? -0.03125 * (ii - 111) + 1. : + ii >= 78 ? 1. : 0.03125 * (ii - 46); + double gg = ii <= 14 || ii >= 111 ? + 0. : + ii >= 79 ? -0.03125 * (ii - 111) : + ii <= 46 ? 0.03125 * (ii - 14) : 1.; + double bb = ii >= 79 ? + 0. : + ii >= 47 ? -0.03125 * (ii - 79) : + ii <= 14 ? 0.03125 * (ii - 14) + 1. : 1.; + r = (int)(rr * 255.); + g = (int)(gg * 255.); + b = (int)(bb * 255.); + } break; case 3: // lucie, samcef (?) if(s - bias <= 0.) { r = 0; @@ -1213,7 +691,8 @@ void ColorTable_Recompute(GmshColorTable * ct) curvature = (curvature == 0.25) ? 0.26 : curvature; r = 0; g = 255; - b = (int)(255. - (255. / (0.25 - curvature)) * (s - bias - 0.25 - curvature)); + b = (int)(255. - + (255. / (0.25 - curvature)) * (s - bias - 0.25 - curvature)); } else if(s - bias <= 0.75 - curvature) { curvature = (curvature == 0.25) ? 0.26 : curvature; @@ -1224,7 +703,8 @@ void ColorTable_Recompute(GmshColorTable * ct) else if(s - bias <= 1.) { curvature = (curvature == -0.25) ? -0.26 : curvature; r = 255; - g = (int)(255. - (255. / (0.25 + curvature)) * (s - bias - 0.75 + curvature)); + g = (int)(255. - + (255. / (0.25 + curvature)) * (s - bias - 0.75 + curvature)); b = 0; } else { @@ -1267,7 +747,8 @@ void ColorTable_Recompute(GmshColorTable * ct) else if(s - bias <= 1.0) { r = 255; g = (int)((255. / 0.2) * (s - bias - 0.8)); - b = (int)(-3187.66 * (s - bias) * (s - bias) + 7012.76 * (s - bias) - 3570.61); + b = (int)(-3187.66 * (s - bias) * (s - bias) + 7012.76 * (s - bias) - + 3570.61); } else { r = 255; @@ -1276,14 +757,15 @@ void ColorTable_Recompute(GmshColorTable * ct) } break; case 6: // incandescent (darkblue->red->yellow->white) - r = (int)(255. * cubic(-0.0506169, 2.81633, -1.87033, 0.0524573, s-bias)); - g = (int)(255. * cubic(0.0485868, -1.26109, 6.3074, -4.12498, s-bias)); - b = (int)(255. * cubic(0.364662, 1.50814, -7.36756, 6.51847, s-bias)); + r = + (int)(255. * cubic(-0.0506169, 2.81633, -1.87033, 0.0524573, s - bias)); + g = (int)(255. * cubic(0.0485868, -1.26109, 6.3074, -4.12498, s - bias)); + b = (int)(255. * cubic(0.364662, 1.50814, -7.36756, 6.51847, s - bias)); break; case 7: // matlab "hot" - r = (int)(255. * hot_r(s-bias)); - g = (int)(255. * hot_g(s-bias)); - b = (int)(255. * hot_b(s-bias)); + r = (int)(255. * hot_r(s - bias)); + g = (int)(255. * hot_g(s - bias)); + b = (int)(255. * hot_b(s - bias)); break; case 8: // matlab "pink" r = (int)(255. * sqrt((2. * gray(s - bias) + hot_r(s - bias)) / 3.)); @@ -1302,52 +784,43 @@ void ColorTable_Recompute(GmshColorTable * ct) } break; case 10: // "french flag" - { - double ii = (double)(s - bias); - if(ii < 0) ii = 0; - if(ii > 1) ii = 1; - double rr = - ii >= .75 ? 2*(0.75-ii) + 1.: - ii >= .5 ? 1. : - ii >= .25 ? 4. * (ii-0.25) : - 0.; - double gg = - ii <= .25 ? 1.33333 * ii : - ii <= .5 ? 0.33333 + 2.66667 * (ii-0.25) : - ii <= .75 ? 1 - 2.66667 * (ii-0.5) : - 1.33333 * (1.-ii); - double bb = - ii <= 0.25 ? 2*ii + 0.5 : - ii <= 0.5 ? 1. : - ii <= 0.75 ? 4*(0.75-ii) : - 0.; - r = (int)(rr * 255.); - g = (int)(gg * 255.); - b = (int)(bb * 255.); - } - break; + { + double ii = (double)(s - bias); + if(ii < 0) ii = 0; + if(ii > 1) ii = 1; + double rr = ii >= .75 ? 2 * (0.75 - ii) + 1. : + ii >= .5 ? 1. : ii >= .25 ? 4. * (ii - 0.25) : 0.; + double gg = ii <= .25 ? 1.33333 * ii : + ii <= .5 ? 0.33333 + 2.66667 * (ii - 0.25) : + ii <= .75 ? 1 - 2.66667 * (ii - 0.5) : + 1.33333 * (1. - ii); + double bb = ii <= 0.25 ? + 2 * ii + 0.5 : + ii <= 0.5 ? 1. : ii <= 0.75 ? 4 * (0.75 - ii) : 0.; + r = (int)(rr * 255.); + g = (int)(gg * 255.); + b = (int)(bb * 255.); + } break; case 11: // matlab "hsv" - { - double H = 6. * s + 1.e-10, R, G, B; - HSV_to_RGB(H, 1., 1., &R, &G, &B); - r = (int)(255 * R); - g = (int)(255 * G); - b = (int)(255 * B); - } - break; + { + double H = 6. * s + 1.e-10, R, G, B; + HSV_to_RGB(H, 1., 1., &R, &G, &B); + r = (int)(255 * R); + g = (int)(255 * G); + b = (int)(255 * B); + } break; case 12: // spectrum (truncated hsv) - { - double H = 5. * s + 1.e-10, R, G, B; - HSV_to_RGB(H, 1., 1., &R, &G, &B); - r = (int)(255 * R); - g = (int)(255 * G); - b = (int)(255 * B); - } - break; + { + double H = 5. * s + 1.e-10, R, G, B; + HSV_to_RGB(H, 1., 1., &R, &G, &B); + r = (int)(255 * R); + g = (int)(255 * G); + b = (int)(255 * B); + } break; case 13: // matlab "bone" - r = (int)(255. * (7. * gray(s-bias) + hot_b(s - bias)) / 8.); - g = (int)(255. * (7. * gray(s-bias) + hot_g(s - bias)) / 8.); - b = (int)(255. * (7. * gray(s-bias) + hot_r(s - bias)) / 8.); + r = (int)(255. * (7. * gray(s - bias) + hot_b(s - bias)) / 8.); + g = (int)(255. * (7. * gray(s - bias) + hot_g(s - bias)) / 8.); + b = (int)(255. * (7. * gray(s - bias) + hot_r(s - bias)) / 8.); break; case 14: // matlab "spring" r = (int)(255. * 1.); @@ -1399,9 +872,7 @@ void ColorTable_Recompute(GmshColorTable * ct) g = (int)(255. * _viridis_data[i][1]); b = (int)(255. * _viridis_data[i][2]); break; - default: - r = g = b = 0; - break; + default: r = g = b = 0; break; } double aa = 1.0; @@ -1413,7 +884,9 @@ void ColorTable_Recompute(GmshColorTable * ct) if(ct->dpar[COLORTABLE_BETA] > 0.0) gamma = 1. - ct->dpar[COLORTABLE_BETA]; else - gamma = 1. / (1.001 + ct->dpar[COLORTABLE_BETA]); // beta is thresholded to [-1,1] + gamma = + 1. / + (1.001 + ct->dpar[COLORTABLE_BETA]); // beta is thresholded to [-1,1] r = (int)(255. * pow((double)r / 255., gamma)); g = (int)(255. * pow((double)g / 255., gamma)); b = (int)(255. * pow((double)b / 255., gamma)); @@ -1433,12 +906,11 @@ void ColorTable_Recompute(GmshColorTable * ct) ct->table[i] = CTX::instance()->packColor(r, g, b, a); } - } static GmshColorTable clip; -void ColorTable_Copy(GmshColorTable * ct) +void ColorTable_Copy(GmshColorTable *ct) { clip.size = ct->size; memcpy(clip.table, ct->table, ct->size * sizeof(unsigned int)); @@ -1446,7 +918,7 @@ void ColorTable_Copy(GmshColorTable * ct) memcpy(clip.dpar, ct->dpar, COLORTABLE_NBMAX_PARAM * sizeof(double)); } -void ColorTable_Paste(GmshColorTable * ct) +void ColorTable_Paste(GmshColorTable *ct) { ct->size = clip.size; memcpy(ct->table, clip.table, clip.size * sizeof(unsigned int)); @@ -1454,7 +926,7 @@ void ColorTable_Paste(GmshColorTable * ct) memcpy(ct->dpar, clip.dpar, COLORTABLE_NBMAX_PARAM * sizeof(double)); } -int ColorTable_Diff(GmshColorTable * ct1, GmshColorTable * ct2) +int ColorTable_Diff(GmshColorTable *ct1, GmshColorTable *ct2) { if(ct1->size != ct2->size) return 1; for(int i = 0; i < ct1->size; i++) @@ -1462,7 +934,8 @@ int ColorTable_Diff(GmshColorTable * ct1, GmshColorTable * ct2) return 0; } -void ColorTable_Print(GmshColorTable * ct, FILE * fp, std::vector<std::string> *vec) +void ColorTable_Print(GmshColorTable *ct, FILE *fp, + std::vector<std::string> *vec) { int i, r, g, b, a; char tmp1[1024], tmp2[1024]; @@ -1484,8 +957,7 @@ void ColorTable_Print(GmshColorTable * ct, FILE * fp, std::vector<std::string> * } sprintf(tmp2, "{%d, %d, %d, %d}", r, g, b, a); strcat(tmp1, tmp2); - if(i != ct->size - 1) - strcat(tmp1, ", "); + if(i != ct->size - 1) strcat(tmp1, ", "); } if(fp) fprintf(fp, "%s\n", tmp1); @@ -1495,21 +967,19 @@ void ColorTable_Print(GmshColorTable * ct, FILE * fp, std::vector<std::string> * Msg::Direct(tmp1); } -int ColorTable_IsAlpha(GmshColorTable * ct) +int ColorTable_IsAlpha(GmshColorTable *ct) { int i, a; for(i = 0; i < ct->size; i++) { a = CTX::instance()->unpackAlpha(ct->table[i]); - if(a < 255) - return 1; + if(a < 255) return 1; } return 0; } // HSV/RBG conversion routines -void HSV_to_RGB(double H, double S, double V, - double *R, double *G, double *B) +void HSV_to_RGB(double H, double S, double V, double *R, double *G, double *B) { if(S < 5.0e-6) { *R = *G = *B = V; @@ -1520,30 +990,64 @@ void HSV_to_RGB(double H, double S, double V, double p1 = V * (1.0 - S); double p2 = V * (1.0 - S * f); double p3 = V * (1.0 - S * (1.0 - f)); - switch(i){ - case 0: *R = V; *G = p3; *B = p1; break; - case 1: *R = p2; *G = V; *B = p1; break; - case 2: *R = p1; *G = V; *B = p3; break; - case 3: *R = p1; *G = p2; *B = V; break; - case 4: *R = p3; *G = p1; *B = V; break; - case 5: *R = V; *G = p1; *B = p2; break; - default : *R = V; *G = V; *B = V; break; + switch(i) { + case 0: + *R = V; + *G = p3; + *B = p1; + break; + case 1: + *R = p2; + *G = V; + *B = p1; + break; + case 2: + *R = p1; + *G = V; + *B = p3; + break; + case 3: + *R = p1; + *G = p2; + *B = V; + break; + case 4: + *R = p3; + *G = p1; + *B = V; + break; + case 5: + *R = V; + *G = p1; + *B = p2; + break; + default: + *R = V; + *G = V; + *B = V; + break; } } } -void RGB_to_HSV(double R, double G, double B, - double *H, double *S, double *V) +void RGB_to_HSV(double R, double G, double B, double *H, double *S, double *V) { - double maxv = R > G ? R : G; if(B > maxv) maxv = B; + double maxv = R > G ? R : G; + if(B > maxv) maxv = B; *V = maxv; - if(maxv > 0){ - double minv = R < G ? R : G; if(B < minv) minv = B; - *S = 1.0 - double(minv)/maxv; - if(maxv > minv){ - if(maxv == R){ *H = (G-B)/double(maxv-minv); if (*H<0) *H += 6.0; } - else if(maxv == G) *H = 2.0 + (B - R) / double(maxv - minv); - else *H = 4.0 + (R - G) / double(maxv - minv); + if(maxv > 0) { + double minv = R < G ? R : G; + if(B < minv) minv = B; + *S = 1.0 - double(minv) / maxv; + if(maxv > minv) { + if(maxv == R) { + *H = (G - B) / double(maxv - minv); + if(*H < 0) *H += 6.0; + } + else if(maxv == G) + *H = 2.0 + (B - R) / double(maxv - minv); + else + *H = 4.0 + (R - G) / double(maxv - minv); } } } diff --git a/Post/ColorTable.h b/Post/ColorTable.h index bb3d454607c1b07d659223349497d88e5ff153c1..d21eb1a6b61699814d3e0fa1c15331341ec007a5 100644 --- a/Post/ColorTable.h +++ b/Post/ColorTable.h @@ -13,45 +13,44 @@ #define COLORTABLE_NBMAX_PARAM 10 #define COLORTABLE_NBMAX_COLOR 1024 -typedef struct{ +typedef struct { unsigned int table[COLORTABLE_NBMAX_COLOR]; int size; // must be >= 2 int ipar[COLORTABLE_NBMAX_PARAM]; double dpar[COLORTABLE_NBMAX_PARAM]; -}GmshColorTable; +} GmshColorTable; // COLORTABLE_MODE -#define COLORTABLE_RGB 1 -#define COLORTABLE_HSV 2 +#define COLORTABLE_RGB 1 +#define COLORTABLE_HSV 2 // integer parameters indices -#define COLORTABLE_NUMBER 0 // predefined curve index -#define COLORTABLE_INVERT 1 // invert (rbg<->255-rgb) -#define COLORTABLE_SWAP 2 // swap (min<->max) -#define COLORTABLE_ROTATION 3 // rotation -#define COLORTABLE_MODE 4 // mode (rgb, hsv) +#define COLORTABLE_NUMBER 0 // predefined curve index +#define COLORTABLE_INVERT 1 // invert (rbg<->255-rgb) +#define COLORTABLE_SWAP 2 // swap (min<->max) +#define COLORTABLE_ROTATION 3 // rotation +#define COLORTABLE_MODE 4 // mode (rgb, hsv) // double parameters indices -#define COLORTABLE_CURVATURE 0 // curvature -#define COLORTABLE_BIAS 1 // offset -#define COLORTABLE_ALPHA 2 // alpha channel value -#define COLORTABLE_BETA 3 // beta coeff for brighten -#define COLORTABLE_ALPHAPOW 4 // alpha channel power value +#define COLORTABLE_CURVATURE 0 // curvature +#define COLORTABLE_BIAS 1 // offset +#define COLORTABLE_ALPHA 2 // alpha channel value +#define COLORTABLE_BETA 3 // beta coeff for brighten +#define COLORTABLE_ALPHAPOW 4 // alpha channel power value void ColorTable_InitParam(int number, GmshColorTable *ct); void ColorTable_Recompute(GmshColorTable *ct); void ColorTable_Copy(GmshColorTable *ct); void ColorTable_Paste(GmshColorTable *ct); -void ColorTable_Print(GmshColorTable *ct, FILE *fp, std::vector<std::string> *vec=0) ; -int ColorTable_IsAlpha(GmshColorTable *ct) ; -int ColorTable_Diff(GmshColorTable *ct1, GmshColorTable *ct2); - -void RGB_to_HSV(double R, double G, double B, - double *H, double *S, double *V); -void HSV_to_RGB(double H, double S, double V, - double *R, double *G, double *B); +void ColorTable_Print(GmshColorTable *ct, FILE *fp, + std::vector<std::string> *vec = 0); +int ColorTable_IsAlpha(GmshColorTable *ct); +int ColorTable_Diff(GmshColorTable *ct1, GmshColorTable *ct2); + +void RGB_to_HSV(double R, double G, double B, double *H, double *S, double *V); +void HSV_to_RGB(double H, double S, double V, double *R, double *G, double *B); #endif diff --git a/Post/OctreePost.cpp b/Post/OctreePost.cpp index 357f0b8ab4f2b1044d888cf3f28876596fc94b9f..446ad3d94408cb368f7ad0525fef8b1662f6ff38 100644 --- a/Post/OctreePost.cpp +++ b/Post/OctreePost.cpp @@ -18,8 +18,8 @@ // helper routines for list-based views -static void minmax(int n, double *X, double *Y, double *Z, - double *min, double *max) +static void minmax(int n, double *X, double *Y, double *Z, double *min, + double *max) { min[0] = X[0]; min[1] = Y[0]; @@ -38,7 +38,7 @@ static void minmax(int n, double *X, double *Y, double *Z, // make bounding boxes larger up to (absolute) geometrical tolerance double eps = CTX::instance()->geom.tolerance; - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { min[i] -= eps; max[i] += eps; } @@ -46,7 +46,7 @@ static void minmax(int n, double *X, double *Y, double *Z, static void centroid(int n, double *X, double *Y, double *Z, double *c) { - const double oc = 1./(double)n; + const double oc = 1. / (double)n; c[0] = X[0]; c[1] = Y[0]; c[2] = Z[0]; @@ -62,60 +62,57 @@ static void centroid(int n, double *X, double *Y, double *Z, double *c) static void pntBB(void *a, double *min, double *max) { - double *X = (double*) a, *Y = &X[1], *Z = &X[2]; + double *X = (double *)a, *Y = &X[1], *Z = &X[2]; minmax(1, X, Y, Z, min, max); } static void linBB(void *a, double *min, double *max) { - double *X = (double*) a, *Y = &X[2], *Z = &X[4]; + double *X = (double *)a, *Y = &X[2], *Z = &X[4]; minmax(2, X, Y, Z, min, max); } static void triBB(void *a, double *min, double *max) { - double *X = (double*) a, *Y = &X[3], *Z = &X[6]; + double *X = (double *)a, *Y = &X[3], *Z = &X[6]; minmax(3, X, Y, Z, min, max); } static void quaBB(void *a, double *min, double *max) { - double *X = (double*) a, *Y = &X[4], *Z = &X[8]; + double *X = (double *)a, *Y = &X[4], *Z = &X[8]; minmax(4, X, Y, Z, min, max); } static void tetBB(void *a, double *min, double *max) { - double *X = (double*) a, *Y = &X[4], *Z = &X[8]; + double *X = (double *)a, *Y = &X[4], *Z = &X[8]; minmax(4, X, Y, Z, min, max); } static void hexBB(void *a, double *min, double *max) { - double *X = (double*) a, *Y = &X[8], *Z = &X[16]; + double *X = (double *)a, *Y = &X[8], *Z = &X[16]; minmax(8, X, Y, Z, min, max); } static void priBB(void *a, double *min, double *max) { - double *X = (double*) a, *Y = &X[6], *Z = &X[12]; + double *X = (double *)a, *Y = &X[6], *Z = &X[12]; minmax(6, X, Y, Z, min, max); } static void pyrBB(void *a, double *min, double *max) { - double *X = (double*) a, *Y = &X[5], *Z = &X[10]; + double *X = (double *)a, *Y = &X[5], *Z = &X[10]; minmax(5, X, Y, Z, min, max); } -static int pntInEle(void *a, double *x) -{ - return 1; -} +static int pntInEle(void *a, double *x) { return 1; } static int linInEle(void *a, double *x) { - double *X = (double*) a, *Y = &X[2], *Z = &X[4], uvw[3]; + double *X = (double *)a, *Y = &X[2], *Z = &X[4], uvw[3]; line lin(X, Y, Z); lin.xyz2uvw(x, uvw); return lin.isInside(uvw[0], uvw[1], uvw[2]); @@ -123,7 +120,7 @@ static int linInEle(void *a, double *x) static int triInEle(void *a, double *x) { - double *X = (double*) a, *Y = &X[3], *Z = &X[6], uvw[3]; + double *X = (double *)a, *Y = &X[3], *Z = &X[6], uvw[3]; triangle tri(X, Y, Z); tri.xyz2uvw(x, uvw); return tri.isInside(uvw[0], uvw[1], uvw[2]); @@ -131,7 +128,7 @@ static int triInEle(void *a, double *x) static int quaInEle(void *a, double *x) { - double *X = (double*) a, *Y = &X[4], *Z = &X[8], uvw[3]; + double *X = (double *)a, *Y = &X[4], *Z = &X[8], uvw[3]; quadrangle qua(X, Y, Z); qua.xyz2uvw(x, uvw); return qua.isInside(uvw[0], uvw[1], uvw[2]); @@ -139,7 +136,7 @@ static int quaInEle(void *a, double *x) static int tetInEle(void *a, double *x) { - double *X = (double*) a, *Y = &X[4], *Z = &X[8], uvw[3]; + double *X = (double *)a, *Y = &X[4], *Z = &X[8], uvw[3]; tetrahedron tet(X, Y, Z); tet.xyz2uvw(x, uvw); return tet.isInside(uvw[0], uvw[1], uvw[2]); @@ -147,7 +144,7 @@ static int tetInEle(void *a, double *x) static int hexInEle(void *a, double *x) { - double *X = (double*) a, *Y = &X[8], *Z = &X[16], uvw[3]; + double *X = (double *)a, *Y = &X[8], *Z = &X[16], uvw[3]; hexahedron hex(X, Y, Z); hex.xyz2uvw(x, uvw); return hex.isInside(uvw[0], uvw[1], uvw[2]); @@ -155,7 +152,7 @@ static int hexInEle(void *a, double *x) static int priInEle(void *a, double *x) { - double *X = (double*) a, *Y = &X[6], *Z = &X[12], uvw[3]; + double *X = (double *)a, *Y = &X[6], *Z = &X[12], uvw[3]; prism pri(X, Y, Z); pri.xyz2uvw(x, uvw); return pri.isInside(uvw[0], uvw[1], uvw[2]); @@ -163,7 +160,7 @@ static int priInEle(void *a, double *x) static int pyrInEle(void *a, double *x) { - double *X = (double*) a, *Y = &X[5], *Z = &X[10], uvw[3]; + double *X = (double *)a, *Y = &X[5], *Z = &X[10], uvw[3]; pyramid pyr(X, Y, Z); pyr.xyz2uvw(x, uvw); return pyr.isInside(uvw[0], uvw[1], uvw[2]); @@ -171,70 +168,85 @@ static int pyrInEle(void *a, double *x) static void pntCentroid(void *a, double *x) { - double *X = (double*) a, *Y = &X[1], *Z = &X[2]; + double *X = (double *)a, *Y = &X[1], *Z = &X[2]; centroid(1, X, Y, Z, x); } static void linCentroid(void *a, double *x) { - double *X = (double*) a, *Y = &X[2], *Z = &X[4]; + double *X = (double *)a, *Y = &X[2], *Z = &X[4]; centroid(2, X, Y, Z, x); } static void triCentroid(void *a, double *x) { - double *X = (double*) a, *Y = &X[3], *Z = &X[6]; + double *X = (double *)a, *Y = &X[3], *Z = &X[6]; centroid(3, X, Y, Z, x); } static void quaCentroid(void *a, double *x) { - double *X = (double*) a, *Y = &X[4], *Z = &X[8]; + double *X = (double *)a, *Y = &X[4], *Z = &X[8]; centroid(4, X, Y, Z, x); } static void tetCentroid(void *a, double *x) { - double *X = (double*) a, *Y = &X[4], *Z = &X[8]; + double *X = (double *)a, *Y = &X[4], *Z = &X[8]; centroid(4, X, Y, Z, x); } static void hexCentroid(void *a, double *x) { - double *X = (double*) a, *Y = &X[8], *Z = &X[16]; + double *X = (double *)a, *Y = &X[8], *Z = &X[16]; centroid(8, X, Y, Z, x); } static void priCentroid(void *a, double *x) { - double *X = (double*) a, *Y = &X[6], *Z = &X[12]; + double *X = (double *)a, *Y = &X[6], *Z = &X[12]; centroid(6, X, Y, Z, x); } static void pyrCentroid(void *a, double *x) { - double *X = (double*) a, *Y = &X[5], *Z = &X[10]; + double *X = (double *)a, *Y = &X[5], *Z = &X[10]; centroid(5, X, Y, Z, x); } static void addListOfStuff(Octree *o, std::vector<double> &l, int nbelm) { - for(unsigned int i = 0; i < l.size(); i += nbelm) - Octree_Insert(&l[i], o); + for(unsigned int i = 0; i < l.size(); i += nbelm) Octree_Insert(&l[i], o); } // OctreePost implementation OctreePost::~OctreePost() { - Octree_Delete(_SPP); Octree_Delete(_VPP); Octree_Delete(_TPP); - Octree_Delete(_SL); Octree_Delete(_VL); Octree_Delete(_TL); - Octree_Delete(_ST); Octree_Delete(_VT); Octree_Delete(_TT); - Octree_Delete(_SQ); Octree_Delete(_VQ); Octree_Delete(_TQ); - Octree_Delete(_SS); Octree_Delete(_VS); Octree_Delete(_TS); - Octree_Delete(_SH); Octree_Delete(_VH); Octree_Delete(_TH); - Octree_Delete(_SI); Octree_Delete(_VI); Octree_Delete(_TI); - Octree_Delete(_SY); Octree_Delete(_VY); Octree_Delete(_TY); + Octree_Delete(_SPP); + Octree_Delete(_VPP); + Octree_Delete(_TPP); + Octree_Delete(_SL); + Octree_Delete(_VL); + Octree_Delete(_TL); + Octree_Delete(_ST); + Octree_Delete(_VT); + Octree_Delete(_TT); + Octree_Delete(_SQ); + Octree_Delete(_VQ); + Octree_Delete(_TQ); + Octree_Delete(_SS); + Octree_Delete(_VS); + Octree_Delete(_TS); + Octree_Delete(_SH); + Octree_Delete(_VH); + Octree_Delete(_TH); + Octree_Delete(_SI); + Octree_Delete(_VI); + Octree_Delete(_TI); + Octree_Delete(_SY); + Octree_Delete(_VY); + Octree_Delete(_TY); } OctreePost::OctreePost(PView *v) @@ -242,10 +254,7 @@ OctreePost::OctreePost(PView *v) _create(v->getData(true)); // use adaptive data if available } -OctreePost::OctreePost(PViewData *data) -{ - _create(data); -} +OctreePost::OctreePost(PViewData *data) { _create(data); } void OctreePost::_create(PViewData *data) { @@ -255,17 +264,18 @@ void OctreePost::_create(PViewData *data) _theViewDataList = 0; _theViewDataGModel = 0; - _theViewDataGModel = dynamic_cast<PViewDataGModel*>(data); + _theViewDataGModel = dynamic_cast<PViewDataGModel *>(data); if(_theViewDataGModel) return; // the octree is already available in the model - _theViewDataList = dynamic_cast<PViewDataList*>(data); + _theViewDataList = dynamic_cast<PViewDataList *>(data); - if(_theViewDataList){ + if(_theViewDataList) { PViewDataList *l = _theViewDataList; - if(l->haveInterpolationMatrices() && !l->isAdapted()){ - Msg::Error("Cannot create octree for non-adapted high-order list-based view: you need"); + if(l->haveInterpolationMatrices() && !l->isAdapted()) { + Msg::Error("Cannot create octree for non-adapted high-order list-based " + "view: you need"); Msg::Error("to select 'Adapt visualization grid' first"); return; } @@ -277,109 +287,131 @@ void OctreePost::_create(PViewData *data) bbmin -= bbeps; bbmax += bbeps; double min[3] = {bbmin.x(), bbmin.y(), bbmin.z()}; - double size[3] = {bbmax.x() - bbmin.x(), - bbmax.y() - bbmin.y(), + double size[3] = {bbmax.x() - bbmin.x(), bbmax.y() - bbmin.y(), bbmax.z() - bbmin.z()}; const int maxElePerBucket = 100; // memory vs. speed trade-off - _SPP = Octree_Create(maxElePerBucket, min, size, pntBB, pntCentroid, pntInEle); + _SPP = + Octree_Create(maxElePerBucket, min, size, pntBB, pntCentroid, pntInEle); addListOfStuff(_SPP, l->SP, 3 + 1 * l->getNumTimeSteps()); Octree_Arrange(_SPP); - _VPP = Octree_Create(maxElePerBucket, min, size, pntBB, pntCentroid, pntInEle); + _VPP = + Octree_Create(maxElePerBucket, min, size, pntBB, pntCentroid, pntInEle); addListOfStuff(_VPP, l->VP, 3 + 3 * l->getNumTimeSteps()); Octree_Arrange(_VPP); - _TPP = Octree_Create(maxElePerBucket, min, size, pntBB, pntCentroid, pntInEle); + _TPP = + Octree_Create(maxElePerBucket, min, size, pntBB, pntCentroid, pntInEle); addListOfStuff(_TPP, l->TP, 3 + 9 * l->getNumTimeSteps()); Octree_Arrange(_TPP); - _SL = Octree_Create(maxElePerBucket, min, size, linBB, linCentroid, linInEle); + _SL = + Octree_Create(maxElePerBucket, min, size, linBB, linCentroid, linInEle); addListOfStuff(_SL, l->SL, 6 + 2 * l->getNumTimeSteps()); Octree_Arrange(_SL); - _VL = Octree_Create(maxElePerBucket, min, size, linBB, linCentroid, linInEle); + _VL = + Octree_Create(maxElePerBucket, min, size, linBB, linCentroid, linInEle); addListOfStuff(_VL, l->VL, 6 + 6 * l->getNumTimeSteps()); Octree_Arrange(_VL); - _TL = Octree_Create(maxElePerBucket, min, size, linBB, linCentroid, linInEle); + _TL = + Octree_Create(maxElePerBucket, min, size, linBB, linCentroid, linInEle); addListOfStuff(_TL, l->TL, 6 + 18 * l->getNumTimeSteps()); Octree_Arrange(_TL); - _ST = Octree_Create(maxElePerBucket, min, size, triBB, triCentroid, triInEle); + _ST = + Octree_Create(maxElePerBucket, min, size, triBB, triCentroid, triInEle); addListOfStuff(_ST, l->ST, 9 + 3 * l->getNumTimeSteps()); Octree_Arrange(_ST); - _VT = Octree_Create(maxElePerBucket, min, size, triBB, triCentroid, triInEle); + _VT = + Octree_Create(maxElePerBucket, min, size, triBB, triCentroid, triInEle); addListOfStuff(_VT, l->VT, 9 + 9 * l->getNumTimeSteps()); Octree_Arrange(_VT); - _TT = Octree_Create(maxElePerBucket, min, size, triBB, triCentroid, triInEle); + _TT = + Octree_Create(maxElePerBucket, min, size, triBB, triCentroid, triInEle); addListOfStuff(_TT, l->TT, 9 + 27 * l->getNumTimeSteps()); Octree_Arrange(_TT); - _SQ = Octree_Create(maxElePerBucket, min, size, quaBB, quaCentroid, quaInEle); + _SQ = + Octree_Create(maxElePerBucket, min, size, quaBB, quaCentroid, quaInEle); addListOfStuff(_SQ, l->SQ, 12 + 4 * l->getNumTimeSteps()); Octree_Arrange(_SQ); - _VQ = Octree_Create(maxElePerBucket, min, size, quaBB, quaCentroid, quaInEle); + _VQ = + Octree_Create(maxElePerBucket, min, size, quaBB, quaCentroid, quaInEle); addListOfStuff(_VQ, l->VQ, 12 + 12 * l->getNumTimeSteps()); Octree_Arrange(_VQ); - _TQ = Octree_Create(maxElePerBucket, min, size, quaBB, quaCentroid, quaInEle); + _TQ = + Octree_Create(maxElePerBucket, min, size, quaBB, quaCentroid, quaInEle); addListOfStuff(_TQ, l->TQ, 12 + 36 * l->getNumTimeSteps()); Octree_Arrange(_TQ); - _SS = Octree_Create(maxElePerBucket, min, size, tetBB, tetCentroid, tetInEle); + _SS = + Octree_Create(maxElePerBucket, min, size, tetBB, tetCentroid, tetInEle); addListOfStuff(_SS, l->SS, 12 + 4 * l->getNumTimeSteps()); Octree_Arrange(_SS); - _VS = Octree_Create(maxElePerBucket, min, size, tetBB, tetCentroid, tetInEle); + _VS = + Octree_Create(maxElePerBucket, min, size, tetBB, tetCentroid, tetInEle); addListOfStuff(_VS, l->VS, 12 + 12 * l->getNumTimeSteps()); Octree_Arrange(_VS); - _TS = Octree_Create(maxElePerBucket, min, size, tetBB, tetCentroid, tetInEle); + _TS = + Octree_Create(maxElePerBucket, min, size, tetBB, tetCentroid, tetInEle); addListOfStuff(_TS, l->TS, 12 + 36 * l->getNumTimeSteps()); Octree_Arrange(_TS); - _SH = Octree_Create(maxElePerBucket, min, size, hexBB, hexCentroid, hexInEle); + _SH = + Octree_Create(maxElePerBucket, min, size, hexBB, hexCentroid, hexInEle); addListOfStuff(_SH, l->SH, 24 + 8 * l->getNumTimeSteps()); Octree_Arrange(_SH); - _VH = Octree_Create(maxElePerBucket, min, size, hexBB, hexCentroid, hexInEle); + _VH = + Octree_Create(maxElePerBucket, min, size, hexBB, hexCentroid, hexInEle); addListOfStuff(_VH, l->VH, 24 + 24 * l->getNumTimeSteps()); Octree_Arrange(_VH); - _TH = Octree_Create(maxElePerBucket, min, size, hexBB, hexCentroid, hexInEle); + _TH = + Octree_Create(maxElePerBucket, min, size, hexBB, hexCentroid, hexInEle); addListOfStuff(_TH, l->TH, 24 + 72 * l->getNumTimeSteps()); Octree_Arrange(_TH); - _SI = Octree_Create(maxElePerBucket, min, size, priBB, priCentroid, priInEle); + _SI = + Octree_Create(maxElePerBucket, min, size, priBB, priCentroid, priInEle); addListOfStuff(_SI, l->SI, 18 + 6 * l->getNumTimeSteps()); Octree_Arrange(_SI); - _VI = Octree_Create(maxElePerBucket, min, size, priBB, priCentroid, priInEle); + _VI = + Octree_Create(maxElePerBucket, min, size, priBB, priCentroid, priInEle); addListOfStuff(_VI, l->VI, 18 + 18 * l->getNumTimeSteps()); Octree_Arrange(_VI); - _TI = Octree_Create(maxElePerBucket, min, size, priBB, priCentroid, priInEle); + _TI = + Octree_Create(maxElePerBucket, min, size, priBB, priCentroid, priInEle); addListOfStuff(_TI, l->TI, 18 + 54 * l->getNumTimeSteps()); Octree_Arrange(_TI); - _SY = Octree_Create(maxElePerBucket, min, size, pyrBB, pyrCentroid, pyrInEle); + _SY = + Octree_Create(maxElePerBucket, min, size, pyrBB, pyrCentroid, pyrInEle); addListOfStuff(_SY, l->SY, 15 + 5 * l->getNumTimeSteps()); Octree_Arrange(_SY); - _VY = Octree_Create(maxElePerBucket, min, size, pyrBB, pyrCentroid, pyrInEle); + _VY = + Octree_Create(maxElePerBucket, min, size, pyrBB, pyrCentroid, pyrInEle); addListOfStuff(_VY, l->VY, 15 + 15 * l->getNumTimeSteps()); Octree_Arrange(_VY); - _TY = Octree_Create(maxElePerBucket, min, size, pyrBB, pyrCentroid, pyrInEle); + _TY = + Octree_Create(maxElePerBucket, min, size, pyrBB, pyrCentroid, pyrInEle); addListOfStuff(_TY, l->TY, 15 + 45 * l->getNumTimeSteps()); Octree_Arrange(_TY); } } -static void *getElement(double P[3], Octree *octree, int nbNod, - int qn, double *qx, double *qy, double *qz) +static void *getElement(double P[3], Octree *octree, int nbNod, int qn, + double *qx, double *qy, double *qz) { - if(qn && qx && qy && qz){ - std::vector<void*> v; + if(qn && qx && qy && qz) { + std::vector<void *> v; Octree_SearchAll(P, octree, &v); - if(nbNod == qn){ + if(nbNod == qn) { // try to use the value from the same geometrical element as the one // provided in qx/y/z double eps = CTX::instance()->geom.tolerance; - for(unsigned int i = 0; i < v.size(); i++){ - double *X = (double*)v[i], *Y = &X[qn], *Z = &X[2 * qn]; + for(unsigned int i = 0; i < v.size(); i++) { + double *X = (double *)v[i], *Y = &X[qn], *Z = &X[2 * qn]; bool ok = true; - for(int j = 0; j < qn; j++){ - ok &= (fabs(X[j] - qx[j]) < eps && - fabs(Y[j] - qy[j]) < eps && + for(int j = 0; j < qn; j++) { + ok &= (fabs(X[j] - qx[j]) < eps && fabs(Y[j] - qy[j]) < eps && fabs(Z[j] - qz[j]) < eps); } if(ok) return v[i]; @@ -387,36 +419,36 @@ static void *getElement(double P[3], Octree *octree, int nbNod, } if(v.size()) return v[0]; } - else{ + else { return Octree_Search(P, octree); } return 0; } -static MElement *getElement(double P[3], GModel *m, - int qn, double *qx, double *qy, double *qz) +static MElement *getElement(double P[3], GModel *m, int qn, double *qx, + double *qy, double *qz) { SPoint3 pt(P); - if(qn && qx && qy && qz){ + if(qn && qx && qy && qz) { // try to use the value from the same geometrical element as the one // provided in qx/y/z double eps = CTX::instance()->geom.tolerance; - std::vector<MElement*> elements = m->getMeshElementsByCoord(pt); - for(unsigned int i = 0; i < elements.size(); i++){ - if(qn == static_cast<int>(elements[i]->getNumVertices())){ + std::vector<MElement *> elements = m->getMeshElementsByCoord(pt); + for(unsigned int i = 0; i < elements.size(); i++) { + if(qn == static_cast<int>(elements[i]->getNumVertices())) { bool ok = true; - for(int j = 0; j < qn; j++){ + for(int j = 0; j < qn; j++) { MVertex *v = elements[i]->getVertex(j); - ok &= (std::abs(v->x() - qx[j]) < eps && - std::abs(v->y() - qy[j]) < eps && - std::abs(v->z() - qz[j]) < eps); + ok &= + (std::abs(v->x() - qx[j]) < eps && std::abs(v->y() - qy[j]) < eps && + std::abs(v->z() - qz[j]) < eps); } if(ok) return elements[i]; } } if(elements.size()) return elements[0]; } - else{ + else { return m->getMeshElementByCoord(pt); } return 0; @@ -428,36 +460,36 @@ bool OctreePost::_getValue(void *in, int dim, int nbNod, int nbComp, { if(!in) return false; - double *X = (double*)in, *Y = &X[nbNod], *Z = &X[2*nbNod], *V = &X[3*nbNod], U[3]; + double *X = (double *)in, *Y = &X[nbNod], *Z = &X[2 * nbNod], + *V = &X[3 * nbNod], U[3]; // for (int i=0;i<3*9*3;i++)printf("%g ", X[i]); // printf("\n"); - elementFactory factory; element *e = factory.create(nbNod, dim, X, Y, Z); if(!e) return false; e->xyz2uvw(P, U); - if(step < 0){ - for(int i = 0; i < _theViewDataList->getNumTimeSteps(); i++){ - for(int j = 0; j < nbComp; j++){ - if(!grad){ + if(step < 0) { + for(int i = 0; i < _theViewDataList->getNumTimeSteps(); i++) { + for(int j = 0; j < nbComp; j++) { + if(!grad) { values[nbComp * i + j] = e->interpolate(&V[nbNod * nbComp * i + j], U[0], U[1], U[2], nbComp); } - else{ + else { e->interpolateGrad(&V[nbNod * nbComp * i + j], U[0], U[1], U[2], &values[3 * (nbComp * i + j)], nbComp); } } } } - else{ - for(int j = 0; j < nbComp; j++){ - if(!grad){ - values[j] = e->interpolate(&V[nbNod * nbComp * step + j], - U[0], U[1], U[2], nbComp); + else { + for(int j = 0; j < nbComp; j++) { + if(!grad) { + values[j] = e->interpolate(&V[nbNod * nbComp * step + j], U[0], U[1], + U[2], nbComp); } else e->interpolateGrad(&V[nbNod * nbComp * step + j], U[0], U[1], U[2], @@ -478,7 +510,7 @@ bool OctreePost::_getValue(void *in, int nbComp, double P[3], int timestep, if(_theViewDataGModel->getNumComponents(0, 0, 0) != nbComp) return false; - MElement *e = (MElement*)in; + MElement *e = (MElement *)in; std::vector<int> dataIndex(e->getNumVertices()); if(_theViewDataGModel->getType() == PViewDataGModel::NodeData) @@ -492,23 +524,23 @@ bool OctreePost::_getValue(void *in, int nbComp, double P[3], int timestep, e->xyz2uvw(P, U); std::vector<double> nodeval(e->getNumVertices() * 9); - for(int step = 0; step < _theViewDataGModel->getNumTimeSteps(); step++){ + for(int step = 0; step < _theViewDataGModel->getNumTimeSteps(); step++) { if(!_theViewDataGModel->hasTimeStep(step)) continue; - if(timestep < 0 || step == timestep){ - for(std::size_t nod = 0; nod < e->getNumVertices(); nod++){ + if(timestep < 0 || step == timestep) { + for(std::size_t nod = 0; nod < e->getNumVertices(); nod++) { for(int comp = 0; comp < nbComp; comp++) _theViewDataGModel->getValueByIndex(step, dataIndex[nod], nod, comp, nodeval[nod * nbComp + comp]); } - for(int comp = 0; comp < nbComp; comp++){ - if(!grad){ + for(int comp = 0; comp < nbComp; comp++) { + if(!grad) { double val = e->interpolate(&nodeval[comp], U[0], U[1], U[2], nbComp); if(timestep < 0) values[nbComp * step + comp] = val; else values[comp] = val; } - else{ + else { if(timestep < 0) e->interpolateGrad(&nodeval[comp], U[0], U[1], U[2], &values[3 * (nbComp * step + comp)], nbComp); @@ -525,62 +557,71 @@ bool OctreePost::_getValue(void *in, int nbComp, double P[3], int timestep, } bool OctreePost::searchScalar(double x, double y, double z, double *values, - int step, double *size, - int qn, double *qx, double *qy, double *qz, - bool grad) + int step, double *size, int qn, double *qx, + double *qy, double *qz, bool grad) { double P[3] = {x, y, z}; int mult = grad ? 3 : 1; - if(step < 0){ + if(step < 0) { int numSteps = 1; - if(_theViewDataList) numSteps = _theViewDataList->getNumTimeSteps(); - else if(_theViewDataGModel) numSteps = _theViewDataGModel->getNumTimeSteps(); - for(int i = 0; i < numSteps * mult; i++){ + if(_theViewDataList) + numSteps = _theViewDataList->getNumTimeSteps(); + else if(_theViewDataGModel) + numSteps = _theViewDataGModel->getNumTimeSteps(); + for(int i = 0; i < numSteps * mult; i++) { values[i] = 0.; } } - else{ - for(int i = 0; i < mult; i++) - values[i] = 0.; + else { + for(int i = 0; i < mult; i++) values[i] = 0.; } - if(_theViewDataList){ - if(_getValue(getElement(P, _SS, 4, qn, qx, qy, qz), - 3, 4, 1, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _SH, 8, qn, qx, qy, qz), - 3, 8, 1, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _SI, 6, qn, qx, qy, qz), - 3, 6, 1, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _SY, 5, qn, qx, qy, qz), - 3, 5, 1, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _ST, 3, qn, qx, qy, qz), - 2, 3, 1, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _SQ, 4, qn, qx, qy, qz), - 2, 4, 1, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _SL, 2, qn, qx, qy, qz), - 1, 2, 1, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _SPP, 1, qn, qx, qy, qz), - 0, 1, 1, P, step, values, size, grad)) return true; + if(_theViewDataList) { + if(_getValue(getElement(P, _SS, 4, qn, qx, qy, qz), 3, 4, 1, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _SH, 8, qn, qx, qy, qz), 3, 8, 1, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _SI, 6, qn, qx, qy, qz), 3, 6, 1, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _SY, 5, qn, qx, qy, qz), 3, 5, 1, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _ST, 3, qn, qx, qy, qz), 2, 3, 1, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _SQ, 4, qn, qx, qy, qz), 2, 4, 1, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _SL, 2, qn, qx, qy, qz), 1, 2, 1, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _SPP, 1, qn, qx, qy, qz), 0, 1, 1, P, step, + values, size, grad)) + return true; } - else if(_theViewDataGModel){ + else if(_theViewDataGModel) { GModel *m = _theViewDataGModel->getModel((step < 0) ? 0 : step); - if(m){ - if(_getValue(getElement(P, m, qn, qx, qy, qz), - 1, P, step, values, size, grad)) return true; + if(m) { + if(_getValue(getElement(P, m, qn, qx, qy, qz), 1, P, step, values, size, + grad)) + return true; } } return false; } -bool OctreePost::searchScalarWithTol(double x, double y, double z, double *values, - int step, double *size, double tol, - int qn, double *qx, double *qy, double *qz, - bool grad) +bool OctreePost::searchScalarWithTol(double x, double y, double z, + double *values, int step, double *size, + double tol, int qn, double *qx, double *qy, + double *qz, bool grad) { bool a = searchScalar(x, y, z, values, step, size, qn, qx, qy, qz, grad); - if(!a && tol != 0.){ + if(!a && tol != 0.) { double oldtol1 = element::getTolerance(); double oldtol2 = MElement::getTolerance(); element::setTolerance(tol); @@ -593,61 +634,69 @@ bool OctreePost::searchScalarWithTol(double x, double y, double z, double *value } bool OctreePost::searchVector(double x, double y, double z, double *values, - int step, double *size, - int qn, double *qx, double *qy, double *qz, - bool grad) + int step, double *size, int qn, double *qx, + double *qy, double *qz, bool grad) { double P[3] = {x, y, z}; int mult = grad ? 3 : 1; - if(step < 0){ + if(step < 0) { int numSteps = 1; - if(_theViewDataList) numSteps = _theViewDataList->getNumTimeSteps(); - else if(_theViewDataGModel) numSteps = _theViewDataGModel->getNumTimeSteps(); - for(int i = 0; i < 3 * numSteps * mult; i++) - values[i] = 0.; + if(_theViewDataList) + numSteps = _theViewDataList->getNumTimeSteps(); + else if(_theViewDataGModel) + numSteps = _theViewDataGModel->getNumTimeSteps(); + for(int i = 0; i < 3 * numSteps * mult; i++) values[i] = 0.; } - else{ - for(int i = 0; i < 3 * mult; i++) - values[i] = 0.; + else { + for(int i = 0; i < 3 * mult; i++) values[i] = 0.; } - if(_theViewDataList){ - if(_getValue(getElement(P, _VS, 4, qn, qx, qy, qz), - 3, 4, 3, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _VH, 8, qn, qx, qy, qz), - 3, 8, 3, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _VI, 6, qn, qx, qy, qz), - 3, 6, 3, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _VY, 5, qn, qx, qy, qz), - 3, 5, 3, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _VT, 3, qn, qx, qy, qz), - 2, 3, 3, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _VQ, 4, qn, qx, qy, qz), - 2, 4, 3, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _VL, 2, qn, qx, qy, qz), - 1, 2, 3, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _VPP, 1, qn, qx, qy, qz), - 0, 1, 3, P, step, values, size, grad)) return true; + if(_theViewDataList) { + if(_getValue(getElement(P, _VS, 4, qn, qx, qy, qz), 3, 4, 3, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _VH, 8, qn, qx, qy, qz), 3, 8, 3, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _VI, 6, qn, qx, qy, qz), 3, 6, 3, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _VY, 5, qn, qx, qy, qz), 3, 5, 3, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _VT, 3, qn, qx, qy, qz), 2, 3, 3, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _VQ, 4, qn, qx, qy, qz), 2, 4, 3, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _VL, 2, qn, qx, qy, qz), 1, 2, 3, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _VPP, 1, qn, qx, qy, qz), 0, 1, 3, P, step, + values, size, grad)) + return true; } - else if(_theViewDataGModel){ + else if(_theViewDataGModel) { GModel *m = _theViewDataGModel->getModel((step < 0) ? 0 : step); - if(m){ - if(_getValue(getElement(P, m, qn, qx, qy, qz), - 3, P, step, values, size, grad)) return true; + if(m) { + if(_getValue(getElement(P, m, qn, qx, qy, qz), 3, P, step, values, size, + grad)) + return true; } } return false; } -bool OctreePost::searchVectorWithTol(double x, double y, double z, double *values, - int step, double *size, double tol, - int qn, double *qx, double *qy, double *qz, - bool grad) +bool OctreePost::searchVectorWithTol(double x, double y, double z, + double *values, int step, double *size, + double tol, int qn, double *qx, double *qy, + double *qz, bool grad) { bool a = searchVector(x, y, z, values, step, size, qn, qx, qy, qz, grad); - if(!a && tol != 0.){ + if(!a && tol != 0.) { double oldtol1 = element::getTolerance(); double oldtol2 = MElement::getTolerance(); element::setTolerance(tol); @@ -660,61 +709,69 @@ bool OctreePost::searchVectorWithTol(double x, double y, double z, double *value } bool OctreePost::searchTensor(double x, double y, double z, double *values, - int step, double *size, - int qn, double *qx, double *qy, double *qz, - bool grad) + int step, double *size, int qn, double *qx, + double *qy, double *qz, bool grad) { double P[3] = {x, y, z}; int mult = grad ? 3 : 1; - if(step < 0){ + if(step < 0) { int numSteps = 1; - if(_theViewDataList) numSteps = _theViewDataList->getNumTimeSteps(); - else if(_theViewDataGModel) numSteps = _theViewDataGModel->getNumTimeSteps(); - for(int i = 0; i < 9 * numSteps * mult; i++) - values[i] = 0.; + if(_theViewDataList) + numSteps = _theViewDataList->getNumTimeSteps(); + else if(_theViewDataGModel) + numSteps = _theViewDataGModel->getNumTimeSteps(); + for(int i = 0; i < 9 * numSteps * mult; i++) values[i] = 0.; } - else{ - for(int i = 0; i < 9 * mult; i++) - values[i] = 0.; + else { + for(int i = 0; i < 9 * mult; i++) values[i] = 0.; } - if(_theViewDataList){ - if(_getValue(getElement(P, _TS, 4, qn, qx, qy, qz), - 3, 4, 9, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _TH, 8, qn, qx, qy, qz), - 3, 8, 9, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _TI, 6, qn, qx, qy, qz), - 3, 6, 9, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _TY, 5, qn, qx, qy, qz), - 3, 5, 9, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _TT, 3, qn, qx, qy, qz), - 2, 3, 9, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _TQ, 4, qn, qx, qy, qz), - 2, 4, 9, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _TL, 2, qn, qx, qy, qz), - 1, 2, 9, P, step, values, size, grad)) return true; - if(_getValue(getElement(P, _TPP, 1, qn, qx, qy, qz), - 0, 1, 9, P, step, values, size, grad)) return true; + if(_theViewDataList) { + if(_getValue(getElement(P, _TS, 4, qn, qx, qy, qz), 3, 4, 9, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _TH, 8, qn, qx, qy, qz), 3, 8, 9, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _TI, 6, qn, qx, qy, qz), 3, 6, 9, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _TY, 5, qn, qx, qy, qz), 3, 5, 9, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _TT, 3, qn, qx, qy, qz), 2, 3, 9, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _TQ, 4, qn, qx, qy, qz), 2, 4, 9, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _TL, 2, qn, qx, qy, qz), 1, 2, 9, P, step, + values, size, grad)) + return true; + if(_getValue(getElement(P, _TPP, 1, qn, qx, qy, qz), 0, 1, 9, P, step, + values, size, grad)) + return true; } - else if(_theViewDataGModel){ + else if(_theViewDataGModel) { GModel *m = _theViewDataGModel->getModel((step < 0) ? 0 : step); - if(m){ - if(_getValue(getElement(P, m, qn, qx, qy, qz), - 9, P, step, values, size, grad)) return true; + if(m) { + if(_getValue(getElement(P, m, qn, qx, qy, qz), 9, P, step, values, size, + grad)) + return true; } } return false; } -bool OctreePost::searchTensorWithTol(double x, double y, double z, double *values, - int step, double *size, double tol, - int qn, double *qx, double *qy, double *qz, - bool grad) +bool OctreePost::searchTensorWithTol(double x, double y, double z, + double *values, int step, double *size, + double tol, int qn, double *qx, double *qy, + double *qz, bool grad) { bool a = searchTensor(x, y, z, values, step, size, qn, qx, qy, qz, grad); - if(!a && tol != 0.){ + if(!a && tol != 0.) { double oldtol1 = element::getTolerance(); double oldtol2 = MElement::getTolerance(); element::setTolerance(tol); diff --git a/Post/OctreePost.h b/Post/OctreePost.h index f64eb0fd0772d61a4dce449a0eb2646026b8855e..8374a5814a442c4f5d1e828cd479d323da1a46b7 100644 --- a/Post/OctreePost.h +++ b/Post/OctreePost.h @@ -13,9 +13,8 @@ class PViewData; class PViewDataList; class PViewDataGModel; -class OctreePost -{ - private: +class OctreePost { +private: Octree *_SPP, *_VPP, *_TPP; // _SP & co reserved by win32 Octree *_SL, *_VL, *_TL; Octree *_ST, *_VT, *_TT; @@ -27,12 +26,12 @@ class OctreePost PViewDataList *_theViewDataList; PViewDataGModel *_theViewDataGModel; void _create(PViewData *data); - bool _getValue(void *in, int dim, int nbNod, int nbComp, - double P[3], int step, double *values, + bool _getValue(void *in, int dim, int nbNod, int nbComp, double P[3], + int step, double *values, double *elementSize, bool grad); + bool _getValue(void *in, int nbComp, double P[3], int step, double *values, double *elementSize, bool grad); - bool _getValue(void *in, int nbComp, double P[3], int step, - double *values, double *elementSize, bool grad); - public : + +public: OctreePost(PView *v); OctreePost(PViewData *data); ~OctreePost(); @@ -43,30 +42,27 @@ class OctreePost // qx/y/z are used to select which element is used to interpolate (if the // query returned more than one). If grad is true, return the component-wise // derivative (gradient) in xyz coordinates instead of the value. - bool searchScalar(double x, double y, double z, double *values, - int step=-1, double *size=0, - int qn=0, double *qx=0, double *qy=0, double *qz=0, - bool grad=false); + bool searchScalar(double x, double y, double z, double *values, int step = -1, + double *size = 0, int qn = 0, double *qx = 0, + double *qy = 0, double *qz = 0, bool grad = false); bool searchScalarWithTol(double x, double y, double z, double *values, - int step=-1, double *size=0, double tol=1.e-2, - int qn=0, double *qx=0, double *qy=0, double *qz=0, - bool grad=false); - bool searchVector(double x, double y, double z, double *values, - int step=-1, double *size=0, - int qn=0, double *qx=0, double *qy=0, double *qz=0, - bool grad=false); + int step = -1, double *size = 0, double tol = 1.e-2, + int qn = 0, double *qx = 0, double *qy = 0, + double *qz = 0, bool grad = false); + bool searchVector(double x, double y, double z, double *values, int step = -1, + double *size = 0, int qn = 0, double *qx = 0, + double *qy = 0, double *qz = 0, bool grad = false); bool searchVectorWithTol(double x, double y, double z, double *values, - int step=-1, double *size=0, double tol=1.e-2, - int qn=0, double *qx=0, double *qy=0, double *qz=0, - bool grad=false); - bool searchTensor(double x, double y, double z, double *values, - int step=-1, double *size=0, - int qn=0, double *qx=0, double *qy=0, double *qz=0, - bool grad=false); + int step = -1, double *size = 0, double tol = 1.e-2, + int qn = 0, double *qx = 0, double *qy = 0, + double *qz = 0, bool grad = false); + bool searchTensor(double x, double y, double z, double *values, int step = -1, + double *size = 0, int qn = 0, double *qx = 0, + double *qy = 0, double *qz = 0, bool grad = false); bool searchTensorWithTol(double x, double y, double z, double *values, - int step=-1, double *size=0, double tol=1.e-2, - int qn=0, double *qx=0, double *qy=0, double *qz=0, - bool grad=false); + int step = -1, double *size = 0, double tol = 1.e-2, + int qn = 0, double *qx = 0, double *qy = 0, + double *qz = 0, bool grad = false); }; #endif diff --git a/Post/PView.cpp b/Post/PView.cpp index ebe317dd58bec2eaa07f131633e0ec6152f7d1f1..4d11a8d1a02c550a3ec6596267befb6aea92aa38 100644 --- a/Post/PView.cpp +++ b/Post/PView.cpp @@ -15,15 +15,15 @@ #include "GmshMessage.h" int PView::_globalTag = 0; -std::vector<PView*> PView::list; +std::vector<PView *> PView::list; void PView::_init(int tag) { - if(tag >= 0){ + if(tag >= 0) { _tag = tag; _globalTag = std::max(_globalTag, _tag) + 1; } - else{ + else { _tag = _globalTag++; } @@ -33,8 +33,8 @@ void PView::_init(int tag) va_points = va_lines = va_triangles = va_vectors = va_ellipses = 0; normals = 0; - for(unsigned int i = 0; i < list.size(); i++){ - if(list[i]->getTag() == _tag){ + for(unsigned int i = 0; i < list.size(); i++) { + if(list[i]->getTag() == _tag) { // in normal operation this should not happen, but we allow it when // programmatically forcing view tags (e.g. when using the views from // within getdp's post-processing operations); this is dangerous, as it @@ -72,10 +72,11 @@ PView::PView(PView *ref, bool copyOptions) { _init(); - if(ref->getAliasOf() >= 0){ // alias of an alias + if(ref->getAliasOf() >= 0) { // alias of an alias PView *orig = getViewByTag(ref->getAliasOf()); - if(orig) _aliasOf = orig->getTag(); - else{ + if(orig) + _aliasOf = orig->getTag(); + else { Msg::Warning("Original view for alias does not exist anymore"); _aliasOf = ref->getTag(); } @@ -109,8 +110,9 @@ PView::PView(const std::string &xname, const std::string &yname, _options->axesLabel[0] = xname; } -PView::PView(const std::string &name, std::vector<double> &x, std::vector<double> &y, - std::vector<double> &z, std::vector<double> &v) +PView::PView(const std::string &name, std::vector<double> &x, + std::vector<double> &y, std::vector<double> &z, + std::vector<double> &v) { _init(); _data = new PViewDataList(); @@ -123,9 +125,9 @@ PView::PView(const std::string &name, std::vector<double> &x, std::vector<double _options->pointType = 1.; } -PView::PView(const std::string &name, const std::string &type, - GModel *model, std::map<int, std::vector<double> > &data, - double time, int numComp, int tag) +PView::PView(const std::string &name, const std::string &type, GModel *model, + std::map<int, std::vector<double> > &data, double time, + int numComp, int tag) { _init(tag); PViewDataGModel::DataType t; @@ -137,7 +139,7 @@ PView::PView(const std::string &name, const std::string &type, t = PViewDataGModel::ElementNodeData; else if(type == "Beam") t = PViewDataGModel::BeamData; - else{ + else { Msg::Error("Unknown type of view to create '%s'", type.c_str()); return; } @@ -152,12 +154,15 @@ PView::PView(const std::string &name, const std::string &type, _options->targetError); } -void PView::addStep(GModel *model, const std::map<int, std::vector<double> > &data, +void PView::addStep(GModel *model, + const std::map<int, std::vector<double> > &data, double time, int numComp) { - PViewDataGModel *d = dynamic_cast<PViewDataGModel*>(_data); - if(d) d->addData(model, data, d->getNumTimeSteps(), time, 1, numComp); - else Msg::Error("Can only add step data to mesh-based datasets"); + PViewDataGModel *d = dynamic_cast<PViewDataGModel *>(_data); + if(d) + d->addData(model, data, d->getNumTimeSteps(), time, 1, numComp); + else + Msg::Error("Can only add step data to mesh-based datasets"); } PView::~PView() @@ -166,7 +171,7 @@ PView::~PView() if(normals) delete normals; if(_options) delete _options; - std::vector<PView*>::iterator it = std::find(list.begin(), list.end(), this); + std::vector<PView *>::iterator it = std::find(list.begin(), list.end(), this); if(it != list.end()) list.erase(it); for(unsigned int i = 0; i < list.size(); i++) list[i]->setIndex(i); @@ -174,8 +179,7 @@ PView::~PView() // do not delete if another view is an alias of this one for(unsigned int i = 0; i < list.size(); i++) - if(list[i]->getAliasOf() == _tag) - return; + if(list[i]->getAliasOf() == _tag) return; // do not delete if this view is an alias and 1) if the original // still exists, or 2) if there are other aliases to the same view @@ -188,23 +192,22 @@ PView::~PView() delete _data; } -int PView::getGlobalTag() -{ - return _globalTag; -} +int PView::getGlobalTag() { return _globalTag; } -void PView::setGlobalTag(int tag) -{ - _globalTag = tag; -} +void PView::setGlobalTag(int tag) { _globalTag = tag; } void PView::deleteVertexArrays() { - if(va_points) delete va_points; va_points = 0; - if(va_lines) delete va_lines; va_lines = 0; - if(va_triangles) delete va_triangles; va_triangles = 0; - if(va_vectors) delete va_vectors; va_vectors = 0; - if(va_ellipses) delete va_ellipses; va_ellipses = 0; + if(va_points) delete va_points; + va_points = 0; + if(va_lines) delete va_lines; + va_lines = 0; + if(va_triangles) delete va_triangles; + va_triangles = 0; + if(va_vectors) delete va_vectors; + va_vectors = 0; + if(va_ellipses) delete va_ellipses; + va_ellipses = 0; } void PView::setOptions(PViewOptions *val) @@ -254,15 +257,15 @@ void PView::combine(bool time, int how, bool remove) else nd.name = "__vis__"; unsigned int j = 0; - while(j < nds.size()){ - if(nds[j].name == nd.name){ + while(j < nds.size()) { + if(nds[j].name == nd.name) { nds[j].data.push_back(data); nds[j].indices.push_back(i); break; } j++; } - if(j == nds.size()){ + if(j == nds.size()) { nd.data.push_back(data); nd.indices.push_back(i); nds.push_back(nd); @@ -270,41 +273,41 @@ void PView::combine(bool time, int how, bool remove) } } - std::set<PView*> rm; - for(unsigned int i = 0; i < nds.size(); i++){ - if(nds[i].data.size() > 1){ // there's potentially something to combine + std::set<PView *> rm; + for(unsigned int i = 0; i < nds.size(); i++) { + if(nds[i].data.size() > 1) { // there's potentially something to combine // sanity checks: bool allListBased = true, allModelBased = true; - for(unsigned int j = 0; j < nds[i].data.size(); j++){ - PViewDataList *d1 = dynamic_cast<PViewDataList*>(nds[i].data[j]); + for(unsigned int j = 0; j < nds[i].data.size(); j++) { + PViewDataList *d1 = dynamic_cast<PViewDataList *>(nds[i].data[j]); if(!d1) allListBased = false; - PViewDataGModel *d2 = dynamic_cast<PViewDataGModel*>(nds[i].data[j]); + PViewDataGModel *d2 = dynamic_cast<PViewDataGModel *>(nds[i].data[j]); if(!d2) allModelBased = false; } PViewData *data = 0; - if(allListBased){ + if(allListBased) { data = new PViewDataList(); } - else if(allModelBased){ - PViewDataGModel *d2 = dynamic_cast<PViewDataGModel*>(nds[i].data[0]); + else if(allModelBased) { + PViewDataGModel *d2 = dynamic_cast<PViewDataGModel *>(nds[i].data[0]); data = new PViewDataGModel(d2->getType()); } - else{ + else { Msg::Error("Cannot combine hybrid list/mesh-based datasets"); continue; } PView *p = new PView(data); bool res = time ? data->combineTime(nds[i]) : data->combineSpace(nds[i]); - if(res){ + if(res) { for(unsigned int j = 0; j < nds[i].indices.size(); j++) rm.insert(list[nds[i].indices[j]]); PViewOptions *opt = p->getOptions(); - if(opt->adaptVisualizationGrid){ + if(opt->adaptVisualizationGrid) { // the (empty) adaptive data created in PView() must be // recreated, since we added some data data->destroyAdaptiveData(); - data->initAdaptiveData - (opt->timeStep, opt->maxRecursionLevel, opt->targetError); + data->initAdaptiveData(opt->timeStep, opt->maxRecursionLevel, + opt->targetError); } } else @@ -312,7 +315,7 @@ void PView::combine(bool time, int how, bool remove) } } if(remove) - for(std::set<PView*>::iterator it = rm.begin(); it != rm.end(); it++) + for(std::set<PView *>::iterator it = rm.begin(); it != rm.end(); it++) delete *it; } @@ -330,27 +333,30 @@ void PView::sortByName() for(unsigned int i = 0; i < list.size(); i++) list[i]->setIndex(i); } -PView *PView::getViewByName(const std::string &name, int timeStep, int partition, - const std::string &fileName) +PView *PView::getViewByName(const std::string &name, int timeStep, + int partition, const std::string &fileName) { // search views from most recently to least recently added - for(int i = list.size() - 1; i >= 0; i--){ + for(int i = list.size() - 1; i >= 0; i--) { if(list[i]->getData()->getName() == name && ((timeStep < 0 || !list[i]->getData()->hasTimeStep(timeStep)) || - (partition < 0 || !list[i]->getData()->hasPartition(timeStep, partition))) && + (partition < 0 || + !list[i]->getData()->hasPartition(timeStep, partition))) && (fileName.empty() || !list[i]->getData()->hasFileName(fileName))) return list[i]; } return 0; } -PView *PView::getViewByFileName(const std::string &fileName, int timeStep, int partition) +PView *PView::getViewByFileName(const std::string &fileName, int timeStep, + int partition) { // search views from most recently to least recently added - for(int i = list.size() - 1; i >= 0; i--){ + for(int i = list.size() - 1; i >= 0; i--) { if(list[i]->getData()->getFileName() == fileName && ((timeStep < 0 || !list[i]->getData()->hasTimeStep(timeStep)) || - (partition < 0 || !list[i]->getData()->hasPartition(timeStep, partition)))) + (partition < 0 || + !list[i]->getData()->hasPartition(timeStep, partition)))) return list[i]; } return 0; @@ -358,10 +364,11 @@ PView *PView::getViewByFileName(const std::string &fileName, int timeStep, int p PView *PView::getViewByTag(int tag, int timeStep, int partition) { - for(unsigned int i = 0; i < list.size(); i++){ + for(unsigned int i = 0; i < list.size(); i++) { if(list[i]->getTag() == tag && ((timeStep < 0 || !list[i]->getData()->hasTimeStep(timeStep)) || - (partition < 0 || !list[i]->getData()->hasPartition(timeStep, partition)))) + (partition < 0 || + !list[i]->getData()->hasPartition(timeStep, partition)))) return list[i]; } return 0; diff --git a/Post/PView.h b/Post/PView.h index f1ea507d5457f8b04c8cf72a758d9218ecf16d09..2397ff6dc1498472ec04ca82d52cdcd2580a2c54 100644 --- a/Post/PView.h +++ b/Post/PView.h @@ -17,11 +17,13 @@ class VertexArray; class smooth_normals; class GModel; class GMSH_PostPlugin; -namespace onelab{ class localNetworkClient; } +namespace onelab { + class localNetworkClient; +} // A post-processing view. -class PView{ - private: +class PView { +private: static int _globalTag; // unique tag of the view (>= 0) int _tag; @@ -38,15 +40,15 @@ class PView{ // the data PViewData *_data; // initialize private stuff - void _init(int tag=-1); + void _init(int tag = -1); - public: +public: // create a new view with list-based data - PView(int tag=-1); + PView(int tag = -1); // construct a new view using the given data - PView(PViewData *data, int tag=-1); + PView(PViewData *data, int tag = -1); // construct a new view, alias of the view "ref" - PView(PView *ref, bool copyOptions=true); + PView(PView *ref, bool copyOptions = true); // construct a new list-based view from a simple 2D point dataset PView(const std::string &xname, const std::string &yname, std::vector<double> &x, std::vector<double> &y); @@ -55,11 +57,11 @@ class PView{ std::vector<double> &z, std::vector<double> &v); // construct a new mesh-based view from a bunch of data PView(const std::string &name, const std::string &type, GModel *model, - std::map<int, std::vector<double> > &data, double time=0., + std::map<int, std::vector<double> > &data, double time = 0., int numComp = -1, int tag = -1); // add a new time step to a given mesh-based view void addStep(GModel *model, const std::map<int, std::vector<double> > &data, - double time=0.,int numComp = -1); + double time = 0., int numComp = -1); // default destructor ~PView(); @@ -72,30 +74,30 @@ class PView{ void deleteVertexArrays(); // get/set the display options - PViewOptions *getOptions(){ return _options; } - void setOptions(PViewOptions *val=0); + PViewOptions *getOptions() { return _options; } + void setOptions(PViewOptions *val = 0); // get/set the view data - PViewData *getData(bool useAdaptiveIfAvailable=false); - void setData(PViewData *val){ _data = val; } + PViewData *getData(bool useAdaptiveIfAvailable = false); + void setData(PViewData *val) { _data = val; } // get the view tag (unique and immutable) - int getTag(){ return _tag; } + int getTag() { return _tag; } // get/set the view index (in the view list) - int getIndex(){ return _index; } - void setIndex(int val){ _index = val; } + int getIndex() { return _index; } + void setIndex(int val) { _index = val; } // get/set the changed flag - bool &getChanged(){ return _changed; } + bool &getChanged() { return _changed; } void setChanged(bool val); // check if the view is an alias ("light copy") of another view - int getAliasOf(){ return _aliasOf; } + int getAliasOf() { return _aliasOf; } // get/set the eye position (for transparency calculations) - SPoint3 &getEye(){ return _eye; } - void setEye(SPoint3 &p){ _eye = p; } + SPoint3 &getEye() { return _eye; } + void setEye(SPoint3 &p) { _eye = p; } // void setDrawContext(drawContext *ctx){_ctx=ctx;} // get (approx.) memory used by the view, in Mb @@ -103,7 +105,7 @@ class PView{ #ifndef SWIG // the static list of all loaded views - static std::vector<PView*> list; + static std::vector<PView *> list; #endif // combine view @@ -113,28 +115,30 @@ class PView{ // only if it does *not* contain that timestep; if partition >= 0, return view // only if it does *not* contain that partition, if fileName is not empty, // return view only if it does *not* have that fileName. - static PView *getViewByName(const std::string &name, int timeStep=-1, - int partition=-1, const std::string &fileName=""); - static PView *getViewByFileName(const std::string &fileName, int timeStep=-1, - int partition=-1); - static PView *getViewByTag(int tag, int timeStep=-1, int partition=-1); + static PView *getViewByName(const std::string &name, int timeStep = -1, + int partition = -1, + const std::string &fileName = ""); + static PView *getViewByFileName(const std::string &fileName, + int timeStep = -1, int partition = -1); + static PView *getViewByTag(int tag, int timeStep = -1, int partition = -1); // sort views in ::list by name static void sortByName(); // IO read routines (these are global: they can create multiple // views) - static bool readPOS(const std::string &fileName, int fileIndex=-1); - static bool readMSH(const std::string &fileName, int fileIndex=-1); - static bool readMED(const std::string &fileName, int fileIndex=-1); - static bool writeX3D(const std::string &fileName ); + static bool readPOS(const std::string &fileName, int fileIndex = -1); + static bool readMSH(const std::string &fileName, int fileIndex = -1); + static bool readMED(const std::string &fileName, int fileIndex = -1); + static bool writeX3D(const std::string &fileName); // IO write routine - bool write(const std::string &fileName, int format, bool append=false); + bool write(const std::string &fileName, int format, bool append = false); // Routines for export of adapted views to pvtu file format for parallel // visualization with paraview - bool writeAdapt(const std::string &fileName, int useDefaultName, bool isBinary, - int adaptLev, double adaptErr, int npart, bool append=false); + bool writeAdapt(const std::string &fileName, int useDefaultName, + bool isBinary, int adaptLev, double adaptErr, int npart, + bool append = false); // vertex arrays to draw the elements efficiently VertexArray *va_points, *va_lines, *va_triangles, *va_vectors, *va_ellipses; @@ -153,10 +157,8 @@ class PView{ // this is the maximum number of nodes of elements we actually *draw* // (high order elements are always subdivided before drawing) #define PVIEW_NMAX 8 -void changeCoordinates(PView *p, int ient, int iele, - int numNodes, int type, int numComp, - double **xyz, double **val); -bool isElementVisible(PViewOptions *opt, int dim, int numNodes, - double **xyz); +void changeCoordinates(PView *p, int ient, int iele, int numNodes, int type, + int numComp, double **xyz, double **val); +bool isElementVisible(PViewOptions *opt, int dim, int numNodes, double **xyz); #endif diff --git a/Post/PViewAsSimpleFunction.cpp b/Post/PViewAsSimpleFunction.cpp index aa8a7b565a538cc40894dffdd4c9b68ad36e1045..0efe8e15fdc0f687757ba0773c96d418d5c96d43 100644 --- a/Post/PViewAsSimpleFunction.cpp +++ b/Post/PViewAsSimpleFunction.cpp @@ -7,12 +7,12 @@ #include "PViewData.h" #include "PViewAsSimpleFunction.h" -double PViewEvaluator::operator() (double x, double y, double z) const +double PViewEvaluator::operator()(double x, double y, double z) const { - PViewData * pvd = _pv->getData(); + PViewData *pvd = _pv->getData(); double value; bool found = pvd->searchScalar(x, y, z, &value, _step); // printf("found %d %g %g %g %g\n",found,x,y,value,x*x+y*y); - if (found) return value; + if(found) return value; return 1.e22; } diff --git a/Post/PViewAsSimpleFunction.h b/Post/PViewAsSimpleFunction.h index 1b9ceff011870513d7d1169d290febd294d3122a..d996a05ef5cafbec38729de049c6f37b44489475 100644 --- a/Post/PViewAsSimpleFunction.h +++ b/Post/PViewAsSimpleFunction.h @@ -13,10 +13,11 @@ class PView; class PViewEvaluator : public simpleFunction<double> { PView *_pv; int _step; - public: - PViewEvaluator (PView *pv) : _pv(pv), _step(0) {} - double operator() (double x, double y, double z) const; - void setStep (int s) { _step = s; } + +public: + PViewEvaluator(PView *pv) : _pv(pv), _step(0) {} + double operator()(double x, double y, double z) const; + void setStep(int s) { _step = s; } }; #endif diff --git a/Post/PViewData.cpp b/Post/PViewData.cpp index 5b8948a1defc369dfe3c9c4de42ef9ef77441c8e..5f0e3586e3fc3e4c9898a69e791c5b76b4fbd7b1 100644 --- a/Post/PViewData.cpp +++ b/Post/PViewData.cpp @@ -11,8 +11,7 @@ std::map<std::string, interpolationMatrices> PViewData::_interpolationSchemes; -PViewData::PViewData() - : _dirty(true), _fileIndex(0), _octree(0), _adaptive(0) +PViewData::PViewData() : _dirty(true), _fileIndex(0), _octree(0), _adaptive(0) { } @@ -21,12 +20,12 @@ PViewData::~PViewData() if(_adaptive) delete _adaptive; for(interpolationMatrices::iterator it = _interpolation.begin(); it != _interpolation.end(); it++) - for(unsigned int i = 0; i < it->second.size(); i++) - delete it->second[i]; + for(unsigned int i = 0; i < it->second.size(); i++) delete it->second[i]; if(_octree) delete _octree; } -bool PViewData::finalize(bool computeMinMax, const std::string &interpolationScheme) +bool PViewData::finalize(bool computeMinMax, + const std::string &interpolationScheme) { _dirty = false; return true; @@ -34,8 +33,9 @@ bool PViewData::finalize(bool computeMinMax, const std::string &interpolationSch void PViewData::initAdaptiveData(int step, int level, double tol) { - if(!_adaptive){ - Msg::Info("Initializing adaptive data %p interp size=%d", this, _interpolation.size()); + if(!_adaptive) { + Msg::Info("Initializing adaptive data %p interp size=%d", this, + _interpolation.size()); _adaptive = new adaptiveData(this); _adaptive->changeResolution(step, level, tol); } @@ -43,36 +43,36 @@ void PViewData::initAdaptiveData(int step, int level, double tol) void PViewData::initAdaptiveDataLight(int step, int level, double tol) { - if(!_adaptive){ - Msg::Info("Initializing adaptive data %p interp size=%d", this, _interpolation.size()); + if(!_adaptive) { + Msg::Info("Initializing adaptive data %p interp size=%d", this, + _interpolation.size()); // _outData in adaptive.h is only used for visualization of adapted views in // the GMSH GUI. In some cases (export of adapted views under pvtu format, // use of GMSH as external lib), this object is not needed so avoid its // allocation in order to limit memory consumption bool outDataInit = false; - _adaptive = new adaptiveData(this,outDataInit); + _adaptive = new adaptiveData(this, outDataInit); } } -void PViewData::saveAdaptedViewForVTK(const std::string &guifileName, int useDefaultName, - int step, int level, double tol, int npart, - bool isBinary) +void PViewData::saveAdaptedViewForVTK(const std::string &guifileName, + int useDefaultName, int step, int level, + double tol, int npart, bool isBinary) { if(_adaptive) { // _adaptiveData has already been allocated from the adaptive view panel of // the GUI for instance. - _adaptive->changeResolutionForVTK(step, level, tol, npart, isBinary, guifileName, - useDefaultName); + _adaptive->changeResolutionForVTK(step, level, tol, npart, isBinary, + guifileName, useDefaultName); } else { initAdaptiveDataLight(step, level, tol); - _adaptive->changeResolutionForVTK(step, level, tol, npart, isBinary, guifileName, - useDefaultName); + _adaptive->changeResolutionForVTK(step, level, tol, npart, isBinary, + guifileName, useDefaultName); destroyAdaptiveData(); } } - void PViewData::destroyAdaptiveData() { if(_adaptive) delete _adaptive; @@ -95,9 +95,9 @@ void PViewData::getScalarValue(int step, int ent, int ele, int nod, double &val, int forceNumComponents, int componentMap[9]) { int numComp = getNumComponents(step, ent, ele); - if(forceNumComponents && componentMap){ + if(forceNumComponents && componentMap) { std::vector<double> d(forceNumComponents); - for(int i = 0; i < forceNumComponents; i++){ + for(int i = 0; i < forceNumComponents; i++) { int comp = componentMap[i]; if(comp >= 0 && comp < numComp) getValue(step, ent, ele, nod, comp, d[i]); @@ -106,10 +106,10 @@ void PViewData::getScalarValue(int step, int ent, int ele, int nod, double &val, } val = ComputeScalarRep(forceNumComponents, &d[0]); } - else if(numComp == 1){ + else if(numComp == 1) { getValue(step, ent, ele, nod, 0, val); } - else{ + else { std::vector<double> d(numComp); for(int comp = 0; comp < numComp; comp++) getValue(step, ent, ele, nod, comp, d[comp]); @@ -117,12 +117,14 @@ void PViewData::getScalarValue(int step, int ent, int ele, int nod, double &val, } } -void PViewData::setNode(int step, int ent, int ele, int nod, double x, double y, double z) +void PViewData::setNode(int step, int ent, int ele, int nod, double x, double y, + double z) { Msg::Error("Cannot change node coordinates in this view"); } -void PViewData::setValue(int step, int ent, int ele, int nod, int comp, double val) +void PViewData::setValue(int step, int ent, int ele, int nod, int comp, + double val) { Msg::Error("Cannot change field value in this view"); } @@ -167,9 +169,10 @@ void PViewData::setInterpolationMatrices(int type, _interpolation[type].push_back(new fullMatrix<double>(expGeo)); } -int PViewData::getInterpolationMatrices(int type, std::vector<fullMatrix<double>*> &p) +int PViewData::getInterpolationMatrices(int type, + std::vector<fullMatrix<double> *> &p) { - if(_interpolation.count(type)){ + if(_interpolation.count(type)) { p = _interpolation[type]; return p.size(); } @@ -191,8 +194,9 @@ void PViewData::deleteInterpolationMatrices(int type) void PViewData::removeInterpolationScheme(const std::string &name) { - std::map<std::string, interpolationMatrices>::iterator it = _interpolationSchemes.find(name); - if(it != _interpolationSchemes.end()){ + std::map<std::string, interpolationMatrices>::iterator it = + _interpolationSchemes.find(name); + if(it != _interpolationSchemes.end()) { for(interpolationMatrices::iterator it2 = it->second.begin(); it2 != it->second.end(); it2++) for(unsigned int i = 0; i < it2->second.size(); i++) @@ -203,17 +207,19 @@ void PViewData::removeInterpolationScheme(const std::string &name) void PViewData::removeAllInterpolationSchemes() { - std::map<std::string, interpolationMatrices>::iterator it = _interpolationSchemes.begin(); - for(;it!=_interpolationSchemes.end();it++) + std::map<std::string, interpolationMatrices>::iterator it = + _interpolationSchemes.begin(); + for(; it != _interpolationSchemes.end(); it++) for(interpolationMatrices::iterator it2 = it->second.begin(); it2 != it->second.end(); it2++) - for(unsigned int i = 0; i < it2->second.size(); i++) - delete it2->second[i]; + for(unsigned int i = 0; i < it2->second.size(); i++) + delete it2->second[i]; _interpolationSchemes.clear(); std::map<std::string, interpolationMatrices>().swap(_interpolationSchemes); } -void PViewData::addMatrixToInterpolationScheme(const std::string &name, int type, +void PViewData::addMatrixToInterpolationScheme(const std::string &name, + int type, fullMatrix<double> &mat) { _interpolationSchemes[name][type].push_back(new fullMatrix<double>(mat)); @@ -224,7 +230,6 @@ int PViewData::getSizeInterpolationScheme() return _interpolationSchemes.size(); } - void PViewData::smooth() { Msg::Error("Smoothing is not implemented for this type of data"); @@ -243,55 +248,58 @@ bool PViewData::combineSpace(nameData &nd) } bool PViewData::searchScalar(double x, double y, double z, double *values, - int step, double *size, int qn, - double *qx, double *qy, double *qz, bool grad) + int step, double *size, int qn, double *qx, + double *qy, double *qz, bool grad) { if(!_octree) _octree = new OctreePost(this); - return _octree->searchScalar(x, y, z, values, step, size, - qn, qx, qy, qz, grad); + return _octree->searchScalar(x, y, z, values, step, size, qn, qx, qy, qz, + grad); } -bool PViewData::searchScalarWithTol(double x, double y, double z, double *values, - int step, double *size, double tol, int qn, - double *qx, double *qy, double *qz, bool grad) +bool PViewData::searchScalarWithTol(double x, double y, double z, + double *values, int step, double *size, + double tol, int qn, double *qx, double *qy, + double *qz, bool grad) { if(!_octree) _octree = new OctreePost(this); - return _octree->searchScalarWithTol(x, y, z, values, step, size, tol, - qn, qx, qy, qz, grad); + return _octree->searchScalarWithTol(x, y, z, values, step, size, tol, qn, qx, + qy, qz, grad); } bool PViewData::searchVector(double x, double y, double z, double *values, - int step, double *size, int qn, - double *qx, double *qy, double *qz, bool grad) + int step, double *size, int qn, double *qx, + double *qy, double *qz, bool grad) { if(!_octree) _octree = new OctreePost(this); - return _octree->searchVector(x, y, z, values, step, size, - qn, qx, qy, qz, grad); + return _octree->searchVector(x, y, z, values, step, size, qn, qx, qy, qz, + grad); } -bool PViewData::searchVectorWithTol(double x, double y, double z, double *values, - int step, double *size, double tol, int qn, - double *qx, double *qy, double *qz, bool grad) +bool PViewData::searchVectorWithTol(double x, double y, double z, + double *values, int step, double *size, + double tol, int qn, double *qx, double *qy, + double *qz, bool grad) { if(!_octree) _octree = new OctreePost(this); - return _octree->searchVectorWithTol(x, y, z, values, step, size, tol, - qn, qx, qy, qz, grad); + return _octree->searchVectorWithTol(x, y, z, values, step, size, tol, qn, qx, + qy, qz, grad); } bool PViewData::searchTensor(double x, double y, double z, double *values, - int step, double *size, int qn, - double *qx, double *qy, double *qz, bool grad) + int step, double *size, int qn, double *qx, + double *qy, double *qz, bool grad) { if(!_octree) _octree = new OctreePost(this); - return _octree->searchTensor(x, y, z, values, step, size, - qn, qx, qy, qz, grad); + return _octree->searchTensor(x, y, z, values, step, size, qn, qx, qy, qz, + grad); } -bool PViewData::searchTensorWithTol(double x, double y, double z, double *values, - int step, double *size, double tol, int qn, - double *qx, double *qy, double *qz, bool grad) +bool PViewData::searchTensorWithTol(double x, double y, double z, + double *values, int step, double *size, + double tol, int qn, double *qx, double *qy, + double *qz, bool grad) { if(!_octree) _octree = new OctreePost(this); - return _octree->searchTensorWithTol(x, y, z, values, step, size, tol, - qn, qx, qy, qz, grad); + return _octree->searchTensorWithTol(x, y, z, values, step, size, tol, qn, qx, + qy, qz, grad); } diff --git a/Post/PViewData.h b/Post/PViewData.h index a6c4ce54b7cca897487a403d98ff6ef0b3ac4322..e31f53e390b9032c6e3076cf6ca7a38af8051312 100644 --- a/Post/PViewData.h +++ b/Post/PViewData.h @@ -22,11 +22,11 @@ class MElement; class nameData; class OctreePost; -typedef std::map<int, std::vector<fullMatrix<double>*> > interpolationMatrices; +typedef std::map<int, std::vector<fullMatrix<double> *> > interpolationMatrices; // The abstract interface to post-processing view data. class PViewData { - private: +private: // flag to mark that the data is 'dirty' and should not be displayed bool _dirty; // name of the view @@ -39,7 +39,7 @@ class PViewData { // octree for rapid search OctreePost *_octree; - protected: +protected: // adaptive visualization data adaptiveData *_adaptive; // interpolation matrices, indexed by the type of element @@ -49,24 +49,24 @@ class PViewData { // string for the name of the interpolation scheme std::string _interpolationSchemeName; - public: +public: PViewData(); virtual ~PViewData(); // get/set the dirty ("not ready for display") flag - virtual bool getDirty(){ return _dirty; } - virtual void setDirty(bool val){ _dirty = val; } + virtual bool getDirty() { return _dirty; } + virtual void setDirty(bool val) { _dirty = val; } // finalize the view data (compute min/max, etc.) - virtual bool finalize(bool computeMinMax=true, - const std::string &interpolationScheme=""); + virtual bool finalize(bool computeMinMax = true, + const std::string &interpolationScheme = ""); // get/set name - virtual std::string getName(){ return _name; } - virtual void setName(const std::string &val){ _name = val; } + virtual std::string getName() { return _name; } + virtual void setName(const std::string &val) { _name = val; } // get/set (the main) filename containing the data - virtual std::string getFileName(int step=-1){ return _fileName; } + virtual std::string getFileName(int step = -1) { return _fileName; } virtual void setFileName(const std::string &val) { _fileName = val; @@ -78,124 +78,140 @@ class PViewData { } // get/set index of view data in file - virtual int getFileIndex(){ return _fileIndex; } - virtual void setFileIndex(int val){ _fileIndex = val; } + virtual int getFileIndex() { return _fileIndex; } + virtual void setFileIndex(int val) { _fileIndex = val; } // get number of time steps in the data virtual int getNumTimeSteps() = 0; - virtual int getFirstNonEmptyTimeStep(int start=0){ return start; } + virtual int getFirstNonEmptyTimeStep(int start = 0) { return start; } // get the time value associated with the step-th time step - virtual double getTime(int step){ return 0.; } + virtual double getTime(int step) { return 0.; } // get/set min/max for given step (global over all steps if step=-1) - virtual double getMin(int step=-1, bool onlyVisible=false, - int forceNumComponents=0, int componentMap[9]=0) = 0; - virtual double getMax(int step=-1, bool onlyVisible=false, - int forceNumComponents=0, int componentMap[9]=0) = 0; + virtual double getMin(int step = -1, bool onlyVisible = false, + int forceNumComponents = 0, + int componentMap[9] = 0) = 0; + virtual double getMax(int step = -1, bool onlyVisible = false, + int forceNumComponents = 0, + int componentMap[9] = 0) = 0; virtual void setMin(double min) = 0; virtual void setMax(double max) = 0; // get/set the bounding box - virtual SBoundingBox3d getBoundingBox(int step=-1) = 0; - virtual void setBoundingBox(SBoundingBox3d& box) = 0; + virtual SBoundingBox3d getBoundingBox(int step = -1) = 0; + virtual void setBoundingBox(SBoundingBox3d &box) = 0; // get the number of elements of a given type, for a given step - virtual int getNumScalars(int step=-1){ return 0; } - virtual int getNumVectors(int step=-1){ return 0; } - virtual int getNumTensors(int step=-1){ return 0; } - virtual int getNumPoints(int step=-1){ return 0; } - virtual int getNumLines(int step=-1){ return 0; } - virtual int getNumTriangles(int step=-1){ return 0; } - virtual int getNumQuadrangles(int step=-1){ return 0; } - virtual int getNumPolygons(int step=-1){ return 0; } - virtual int getNumTetrahedra(int step=-1){ return 0; } - virtual int getNumHexahedra(int step=-1){ return 0; } - virtual int getNumPrisms(int step=-1){ return 0; } - virtual int getNumPyramids(int step=-1){ return 0; } - virtual int getNumTrihedra(int step=-1){ return 0; } - virtual int getNumPolyhedra(int step=-1){ return 0; } + virtual int getNumScalars(int step = -1) { return 0; } + virtual int getNumVectors(int step = -1) { return 0; } + virtual int getNumTensors(int step = -1) { return 0; } + virtual int getNumPoints(int step = -1) { return 0; } + virtual int getNumLines(int step = -1) { return 0; } + virtual int getNumTriangles(int step = -1) { return 0; } + virtual int getNumQuadrangles(int step = -1) { return 0; } + virtual int getNumPolygons(int step = -1) { return 0; } + virtual int getNumTetrahedra(int step = -1) { return 0; } + virtual int getNumHexahedra(int step = -1) { return 0; } + virtual int getNumPrisms(int step = -1) { return 0; } + virtual int getNumPyramids(int step = -1) { return 0; } + virtual int getNumTrihedra(int step = -1) { return 0; } + virtual int getNumPolyhedra(int step = -1) { return 0; } // return the number of geometrical entities in the view - virtual int getNumEntities(int step=-1){ return 0; } + virtual int getNumEntities(int step = -1) { return 0; } // return the number of elements in the ent-th entity, or the total number of // elements if ent < 0 - virtual int getNumElements(int step=-1, int ent=-1){ return 0; } + virtual int getNumElements(int step = -1, int ent = -1) { return 0; } // return the geometrical dimension of the ele-th element in the ent-th entity - virtual int getDimension(int step, int ent, int ele){ return 0; } + virtual int getDimension(int step, int ent, int ele) { return 0; } // return the number of nodes of the ele-th element in the ent-th entity - virtual int getNumNodes(int step, int ent, int ele){ return 0; } + virtual int getNumNodes(int step, int ent, int ele) { return 0; } // get/set the coordinates and tag of the nod-th node from the ele-th element // in the ent-th entity (if the node has a tag, getNode returns it) - virtual int getNode(int step, int ent, int ele, int nod, - double &x, double &y, double &z){ return 0; } - virtual void setNode(int step, int ent, int ele, int nod, - double x, double y, double z); - virtual void tagNode(int step, int ent, int ele, int nod, int tag){} + virtual int getNode(int step, int ent, int ele, int nod, double &x, double &y, + double &z) + { + return 0; + } + virtual void setNode(int step, int ent, int ele, int nod, double x, double y, + double z); + virtual void tagNode(int step, int ent, int ele, int nod, int tag) {} // return the number of components available for the ele-th element in the // ent-th entity - virtual int getNumComponents(int step, int ent, int ele){ return 0; } + virtual int getNumComponents(int step, int ent, int ele) { return 0; } // return the number of values available for the ele-th element in the ent-th // entity - virtual int getNumValues(int step, int ent, int ele){ return 0; } + virtual int getNumValues(int step, int ent, int ele) { return 0; } // get the idx'th value for the ele-th element in the ent-th entity - virtual void getValue(int step, int ent, int ele, int idx, double &val){} + virtual void getValue(int step, int ent, int ele, int idx, double &val) {} // gets/set the comp-th component (at the step-th time step) associated with // the node-th node from the ele-th element in the ent-th entity - virtual void getValue(int step, int ent, int ele, int nod, int comp, double &val){} - virtual void setValue(int step, int ent, int ele, int nod, int comp, double val); + virtual void getValue(int step, int ent, int ele, int nod, int comp, + double &val) + { + } + virtual void setValue(int step, int ent, int ele, int nod, int comp, + double val); // return a scalar value (same as value for scalars, norm for vectors, etc.) // associated with the node-th node from the ele-th element in the ent-th // entity void getScalarValue(int step, int ent, int ele, int nod, double &val, - int forceNumComponents=0, int componentMap[9]=0); + int forceNumComponents = 0, int componentMap[9] = 0); // return the number of edges of the ele-th element in the ent-th // entity - virtual int getNumEdges(int step, int ent, int ele){ return 0; } + virtual int getNumEdges(int step, int ent, int ele) { return 0; } // return the type of the ele-th element in the ent-th entity - virtual int getType(int step, int ent, int ele){ return 0; } + virtual int getType(int step, int ent, int ele) { return 0; } // return the number of 2D/3D strings in the view - virtual int getNumStrings2D(){ return 0; } - virtual int getNumStrings3D(){ return 0; } + virtual int getNumStrings2D() { return 0; } + virtual int getNumStrings3D() { return 0; } // return the i-th 2D/3D string in the view - virtual void getString2D(int i, int step, std::string &str, - double &x, double &y, double &style){} - virtual void getString3D(int i, int step, std::string &str, - double &x, double &y, double &z, double &style){} + virtual void getString2D(int i, int step, std::string &str, double &x, + double &y, double &style) + { + } + virtual void getString3D(int i, int step, std::string &str, double &x, + double &y, double &z, double &style) + { + } // change the orientation of the ele-th element - virtual void reverseElement(int step, int ent, int ele){} + virtual void reverseElement(int step, int ent, int ele) {} // check if the view is empty virtual bool empty(); // check if we should skip the given entity/element - virtual bool skipEntity(int step, int ent){ return false; } - virtual bool skipElement(int step, int ent, int ele, bool checkVisibility=false, - int samplingRate=1); + virtual bool skipEntity(int step, int ent) { return false; } + virtual bool skipElement(int step, int ent, int ele, + bool checkVisibility = false, int samplingRate = 1); // check if the data has the given step/partition/etc. - virtual bool hasTimeStep(int step){ return step >= 0 && step < getNumTimeSteps(); } - virtual bool hasPartition(int step, int part){ return false; } - virtual bool hasMultipleMeshes(){ return false; } - virtual bool hasModel(GModel *model, int step=-1){ return false; } - virtual bool isNodeData(){ return false; } + virtual bool hasTimeStep(int step) + { + return step >= 0 && step < getNumTimeSteps(); + } + virtual bool hasPartition(int step, int part) { return false; } + virtual bool hasMultipleMeshes() { return false; } + virtual bool hasModel(GModel *model, int step = -1) { return false; } + virtual bool isNodeData() { return false; } // true if data is given at Gauss points (instead of vertices) - virtual bool useGaussPoints(){ return false; } + virtual bool useGaussPoints() { return false; } // initialize/destroy adaptive data void initAdaptiveData(int step, int level, double tol); @@ -206,26 +222,25 @@ class PViewData { // - and/or generation of VTK data structure for ParaView plugin. void initAdaptiveDataLight(int step, int level, double tol); void saveAdaptedViewForVTK(const std::string &guifileName, int useDefaultName, - int step, int level, double tol, int npart, bool isBinary); + int step, int level, double tol, int npart, + bool isBinary); void destroyAdaptiveData(); // return the adaptive data - adaptiveData *getAdaptiveData(){ return _adaptive; } + adaptiveData *getAdaptiveData() { return _adaptive; } // set/get the interpolation matrices for elements with type "type" // FIXME : too much overload :( - void setInterpolationMatrices(int type, - const fullMatrix<double> &coefVal, + void setInterpolationMatrices(int type, const fullMatrix<double> &coefVal, const fullMatrix<double> &expVal); - void setInterpolationMatrices(int type, - const fullMatrix<double> &coefVal, + void setInterpolationMatrices(int type, const fullMatrix<double> &coefVal, const fullMatrix<double> &expVal, const fullMatrix<double> &coefGeo, const fullMatrix<double> &expGeo); - int getInterpolationMatrices(int type, std::vector<fullMatrix<double>*> &p); - bool haveInterpolationMatrices(int type=0); - void deleteInterpolationMatrices(int type=0); + int getInterpolationMatrices(int type, std::vector<fullMatrix<double> *> &p); + bool haveInterpolationMatrices(int type = 0); + void deleteInterpolationMatrices(int type = 0); // access to global interpolation schemes static void removeInterpolationScheme(const std::string &name); @@ -234,7 +249,10 @@ class PViewData { fullMatrix<double> &mat); static int getSizeInterpolationScheme(); std::string getInterpolationSchemeName() { return _interpolationSchemeName; } - void setInterpolationSchemeName(std::string name) { _interpolationSchemeName = name; } + void setInterpolationSchemeName(std::string name) + { + _interpolationSchemeName = name; + } // smooth the data in the view (makes it C0) virtual void smooth(); @@ -244,21 +262,23 @@ class PViewData { virtual bool combineSpace(nameData &nd); // set simple X-Y data - virtual void setXY(std::vector<double> &x, std::vector<double> &y){} + virtual void setXY(std::vector<double> &x, std::vector<double> &y) {} // set simple pointwise XYZ data virtual void setXYZV(std::vector<double> &x, std::vector<double> &y, - std::vector<double> &z, std::vector<double> &v){} + std::vector<double> &z, std::vector<double> &v) + { + } // ask to fill vertex arrays remotely - virtual bool isRemote(){ return false; } - virtual int fillRemoteVertexArrays(std::string &options){ return 0; } + virtual bool isRemote() { return false; } + virtual int fillRemoteVertexArrays(std::string &options) { return 0; } // is the view a list-based dataset - virtual bool isListBased(){ return false; } + virtual bool isListBased() { return false; } // get (approx) memry used by data in Mb - virtual double getMemoryInMb(){ return 0; } + virtual double getMemoryInMb() { return 0; } // get GModel (if view supports it) virtual GModel *getModel(int step); @@ -273,34 +293,39 @@ class PViewData { // using standard first order shape functions in the post element. If several // time steps are present, they are all interpolated unless time step is set // to a different value than -1. - bool searchScalar(double x, double y, double z, double *values, - int step=-1, double *size=0, int qn=0, - double *qx=0, double *qy=0, double *qz=0, bool grad=false); + bool searchScalar(double x, double y, double z, double *values, int step = -1, + double *size = 0, int qn = 0, double *qx = 0, + double *qy = 0, double *qz = 0, bool grad = false); bool searchScalarWithTol(double x, double y, double z, double *values, - int step=-1, double *size=0, double tol=1.e-2, int qn=0, - double *qx=0, double *qy=0, double *qz=0, bool grad=false); - bool searchVector(double x, double y, double z, double *values, - int step=-1, double *size=0, int qn=0, - double *qx=0, double *qy=0, double *qz=0, bool grad=false); + int step = -1, double *size = 0, double tol = 1.e-2, + int qn = 0, double *qx = 0, double *qy = 0, + double *qz = 0, bool grad = false); + bool searchVector(double x, double y, double z, double *values, int step = -1, + double *size = 0, int qn = 0, double *qx = 0, + double *qy = 0, double *qz = 0, bool grad = false); bool searchVectorWithTol(double x, double y, double z, double *values, - int step=-1, double *size=0, double tol=1.e-2, int qn=0, - double *qx=0, double *qy=0, double *qz=0, bool grad=false); - bool searchTensor(double x, double y, double z, double *values, - int step=-1, double *size=0, int qn=0, - double *qx=0, double *qy=0, double *qz=0, bool grad=false); + int step = -1, double *size = 0, double tol = 1.e-2, + int qn = 0, double *qx = 0, double *qy = 0, + double *qz = 0, bool grad = false); + bool searchTensor(double x, double y, double z, double *values, int step = -1, + double *size = 0, int qn = 0, double *qx = 0, + double *qy = 0, double *qz = 0, bool grad = false); bool searchTensorWithTol(double x, double y, double z, double *values, - int step=-1, double *size=0, double tol=1.e-2, int qn=0, - double *qx=0, double *qy=0, double *qz=0, bool grad=false); + int step = -1, double *size = 0, double tol = 1.e-2, + int qn = 0, double *qx = 0, double *qy = 0, + double *qz = 0, bool grad = false); // I/O routines virtual bool writeSTL(const std::string &fileName); virtual bool writeTXT(const std::string &fileName); - virtual bool writePOS(const std::string &fileName, bool binary=false, - bool parsed=true, bool append=false); - virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false, - bool saveMesh=true, bool multipleView=false, - int partitionNum=0, bool saveInterpolationMatrices=true, - bool forceNodeData=false, bool forceElementData=false); + virtual bool writePOS(const std::string &fileName, bool binary = false, + bool parsed = true, bool append = false); + virtual bool writeMSH(const std::string &fileName, double version = 2.2, + bool binary = false, bool saveMesh = true, + bool multipleView = false, int partitionNum = 0, + bool saveInterpolationMatrices = true, + bool forceNodeData = false, + bool forceElementData = false); virtual bool writeMED(const std::string &fileName); virtual bool toVector(std::vector<std::vector<double> > &vec); virtual bool fromVector(const std::vector<std::vector<double> > &vec); @@ -308,11 +333,11 @@ class PViewData { virtual void getListPointers(int N[24], std::vector<double> *V[24]); }; -class nameData{ - public: +class nameData { +public: std::string name; std::vector<int> indices; - std::vector<PViewData*> data; + std::vector<PViewData *> data; }; #endif diff --git a/Post/PViewDataGModel.cpp b/Post/PViewDataGModel.cpp index bfa49e4bcc81ceeac769c73e8e70eab2a6d724d8..6961e49c29a5e50153a4c055e07ca0896f2ce461 100644 --- a/Post/PViewDataGModel.cpp +++ b/Post/PViewDataGModel.cpp @@ -29,54 +29,54 @@ PViewDataGModel::~PViewDataGModel() static MElement *_getOneElementOfGivenType(GModel *m, int type) { - switch(type){ + switch(type) { case TYPE_PNT: - for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++){ + for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++) { if((*it)->points.size()) return (*it)->points[0]; } break; case TYPE_LIN: - for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){ + for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++) { if((*it)->lines.size()) return (*it)->lines[0]; } break; case TYPE_TRI: - for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){ + for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++) { if((*it)->triangles.size()) return (*it)->triangles[0]; } break; case TYPE_QUA: - for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){ + for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++) { if((*it)->quadrangles.size()) return (*it)->quadrangles[0]; } break; case TYPE_POLYG: - for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){ + for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++) { if((*it)->polygons.size()) return (*it)->polygons[0]; } break; case TYPE_TET: - for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){ + for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++) { if((*it)->tetrahedra.size()) return (*it)->tetrahedra[0]; } break; case TYPE_HEX: - for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){ + for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++) { if((*it)->hexahedra.size()) return (*it)->hexahedra[0]; } break; case TYPE_PRI: - for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){ + for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++) { if((*it)->prisms.size()) return (*it)->prisms[0]; } break; case TYPE_PYR: - for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){ + for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++) { if((*it)->pyramids.size()) return (*it)->pyramids[0]; } break; case TYPE_POLYH: - for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){ + for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++) { if((*it)->polyhedra.size()) return (*it)->polyhedra[0]; } break; @@ -84,32 +84,33 @@ static MElement *_getOneElementOfGivenType(GModel *m, int type) return 0; } -bool PViewDataGModel::finalize(bool computeMinMax, const std::string &interpolationScheme) +bool PViewDataGModel::finalize(bool computeMinMax, + const std::string &interpolationScheme) { - if(computeMinMax){ + if(computeMinMax) { _min = VAL_INF; _max = -VAL_INF; - for(int step = 0; step < getNumTimeSteps(); step++){ + for(int step = 0; step < getNumTimeSteps(); step++) { _steps[step]->setMin(VAL_INF); _steps[step]->setMax(-VAL_INF); - if(_type == NodeData || _type == ElementData){ + if(_type == NodeData || _type == ElementData) { // treat these 2 special cases separately for maximum efficiency int numComp = _steps[step]->getNumComponents(); - for(int i = 0; i < _steps[step]->getNumData(); i++){ + for(int i = 0; i < _steps[step]->getNumData(); i++) { double *d = _steps[step]->getData(i); - if(d){ + if(d) { double val = ComputeScalarRep(numComp, d); _steps[step]->setMin(std::min(_steps[step]->getMin(), val)); _steps[step]->setMax(std::max(_steps[step]->getMax(), val)); } } } - else{ + else { // general case (slower) - for(int ent = 0; ent < getNumEntities(step); ent++){ - for(int ele = 0; ele < getNumElements(step, ent); ele++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { + for(int ele = 0; ele < getNumElements(step, ent); ele++) { if(skipElement(step, ent, ele)) continue; - for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) { double val; getScalarValue(step, ent, ele, nod, val); _steps[step]->setMin(std::min(_steps[step]->getMin(), val)); @@ -124,15 +125,14 @@ bool PViewDataGModel::finalize(bool computeMinMax, const std::string &interpolat } // set up interpolation matrices - if(!haveInterpolationMatrices()){ - + if(!haveInterpolationMatrices()) { GModel *model = _steps[0]->getModel(); // Required for ParaView plugin linked to GMSH as external library. setInterpolationSchemeName(interpolationScheme); // if an interpolation scheme is explicitly provided, use it - if(interpolationScheme.size()){ + if(interpolationScheme.size()) { interpolationMatrices m = _interpolationSchemes[interpolationScheme]; if(m.size()) Msg::Info("Setting interpolation matrices from scheme '%s'", @@ -140,54 +140,63 @@ bool PViewDataGModel::finalize(bool computeMinMax, const std::string &interpolat else Msg::Error("Could not find interpolation scheme '%s'", interpolationScheme.c_str()); - for(interpolationMatrices::iterator it = m.begin(); it != m.end(); it++){ - if(it->second.size() == 2){ + for(interpolationMatrices::iterator it = m.begin(); it != m.end(); it++) { + if(it->second.size() == 2) { // use provided interpolation matrices for field interpolation and use // geometrical interpolation matrices from the mesh if the mesh is // curved MElement *e = _getOneElementOfGivenType(model, it->first); - if(e && e->getPolynomialOrder() > 1 && e->getFunctionSpace()){ - if (it->first == TYPE_PYR) { // nasty fix since pyramids /= polynomial - const pyramidalBasis *fs = (pyramidalBasis*) e->getFunctionSpace(); - setInterpolationMatrices(it->first, *(it->second[0]), *(it->second[1]), - fs->coefficients, fs->monomials); + if(e && e->getPolynomialOrder() > 1 && e->getFunctionSpace()) { + if(it->first == + TYPE_PYR) { // nasty fix since pyramids /= polynomial + const pyramidalBasis *fs = + (pyramidalBasis *)e->getFunctionSpace(); + setInterpolationMatrices(it->first, *(it->second[0]), + *(it->second[1]), fs->coefficients, + fs->monomials); } else { - const polynomialBasis *fs = (polynomialBasis*) e->getFunctionSpace(); - setInterpolationMatrices(it->first, *(it->second[0]), *(it->second[1]), - fs->coefficients, fs->monomials); + const polynomialBasis *fs = + (polynomialBasis *)e->getFunctionSpace(); + setInterpolationMatrices(it->first, *(it->second[0]), + *(it->second[1]), fs->coefficients, + fs->monomials); } } - else setInterpolationMatrices(it->first, *(it->second[0]), *(it->second[1])); + else + setInterpolationMatrices(it->first, *(it->second[0]), + *(it->second[1])); } - else if(it->second.size() == 4){ + else if(it->second.size() == 4) { // use provided matrices for field and geometry - Msg::Warning("You should not specify the geometrical interpolation " - "in ElementNodeData: the geometry is completely determined " - "by the mesh element type. This feature will be removed"); + Msg::Warning( + "You should not specify the geometrical interpolation " + "in ElementNodeData: the geometry is completely determined " + "by the mesh element type. This feature will be removed"); setInterpolationMatrices(it->first, *it->second[0], *it->second[1], *it->second[2], *it->second[3]); } else - Msg::Error("Wrong number of interpolation matrices (%d) for scheme '%s'", - (int)it->second.size(), interpolationScheme.c_str()); + Msg::Error( + "Wrong number of interpolation matrices (%d) for scheme '%s'", + (int)it->second.size(), interpolationScheme.c_str()); } } // if we don't have interpolation matrices for a given element type, assume // isoparametric elements (except for ElementData, for which we know the // interpolation: it's constant) - int types[] = {TYPE_PNT, TYPE_LIN, TYPE_TRI, TYPE_QUA, TYPE_TET, TYPE_HEX, - TYPE_PRI,TYPE_PYR, TYPE_POLYG, TYPE_POLYH}; - for(unsigned int i = 0; i < sizeof(types) / sizeof(types[0]); i++){ - if(!haveInterpolationMatrices(types[i])){ + int types[] = {TYPE_PNT, TYPE_LIN, TYPE_TRI, TYPE_QUA, TYPE_TET, + TYPE_HEX, TYPE_PRI, TYPE_PYR, TYPE_POLYG, TYPE_POLYH}; + for(unsigned int i = 0; i < sizeof(types) / sizeof(types[0]); i++) { + if(!haveInterpolationMatrices(types[i])) { MElement *e = _getOneElementOfGivenType(model, types[i]); - if(e){ + if(e) { const polynomialBasis *fs = - dynamic_cast<const polynomialBasis*>(e->getFunctionSpace()); - if(fs){ - if(e->getPolynomialOrder() > 1){ - if(_type == ElementData){ + dynamic_cast<const polynomialBasis *>(e->getFunctionSpace()); + if(fs) { + if(e->getPolynomialOrder() > 1) { + if(_type == ElementData) { // data is constant per element: force the interpolation matrix fullMatrix<double> coef(1, 1); coef(0, 0) = 1.; @@ -195,24 +204,26 @@ bool PViewDataGModel::finalize(bool computeMinMax, const std::string &interpolat mono(0, 0) = 0.; mono(0, 1) = 0.; mono(0, 2) = 0.; - setInterpolationMatrices(types[i], coef, mono, - fs->coefficients, fs->monomials); + setInterpolationMatrices(types[i], coef, mono, fs->coefficients, + fs->monomials); } else - setInterpolationMatrices(types[i], - fs->coefficients, fs->monomials, - fs->coefficients, fs->monomials); + setInterpolationMatrices(types[i], fs->coefficients, + fs->monomials, fs->coefficients, + fs->monomials); } else - setInterpolationMatrices(types[i], fs->coefficients, fs->monomials); + setInterpolationMatrices(types[i], fs->coefficients, + fs->monomials); } else { const pyramidalBasis *fs = - dynamic_cast<const pyramidalBasis*>(e->getFunctionSpace()); - if(fs){ - if(e->getPolynomialOrder() > 1){ - if(_type == ElementData){ - // data is constant per element: force the interpolation matrix + dynamic_cast<const pyramidalBasis *>(e->getFunctionSpace()); + if(fs) { + if(e->getPolynomialOrder() > 1) { + if(_type == ElementData) { + // data is constant per element: force the interpolation + // matrix fullMatrix<double> coef(1, 1); coef(0, 0) = 1.; fullMatrix<double> mono(1, 3); @@ -223,12 +234,13 @@ bool PViewDataGModel::finalize(bool computeMinMax, const std::string &interpolat fs->coefficients, fs->monomials); } else - setInterpolationMatrices(types[i], - fs->coefficients, fs->monomials, - fs->coefficients, fs->monomials); + setInterpolationMatrices(types[i], fs->coefficients, + fs->monomials, fs->coefficients, + fs->monomials); } else - setInterpolationMatrices(types[i], fs->coefficients, fs->monomials); + setInterpolationMatrices(types[i], fs->coefficients, + fs->monomials); } } } @@ -253,10 +265,7 @@ std::string PViewDataGModel::getFileName(int step) return _steps[step]->getFileName(); } -int PViewDataGModel::getNumTimeSteps() -{ - return _steps.size(); -} +int PViewDataGModel::getNumTimeSteps() { return _steps.size(); } int PViewDataGModel::getFirstNonEmptyTimeStep(int start) { @@ -271,21 +280,21 @@ double PViewDataGModel::getTime(int step) return _steps[step]->getTime(); } -double PViewDataGModel::getMin(int step, bool onlyVisible, int forceNumComponents, - int componentMap[9]) +double PViewDataGModel::getMin(int step, bool onlyVisible, + int forceNumComponents, int componentMap[9]) { if(_steps.empty()) return _min; - if(onlyVisible || forceNumComponents){ + if(onlyVisible || forceNumComponents) { double vmin = VAL_INF; - for(int ent = 0; ent < getNumEntities(step); ent++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { if(onlyVisible && skipEntity(step, ent)) continue; - for(int ele = 0; ele < getNumElements(step, ent); ele++){ + for(int ele = 0; ele < getNumElements(step, ent); ele++) { if(skipElement(step, ent, ele, onlyVisible)) continue; - for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) { double val; - getScalarValue(step, ent, ele, nod, val, - forceNumComponents, componentMap); + getScalarValue(step, ent, ele, nod, val, forceNumComponents, + componentMap); vmin = std::min(vmin, val); } } @@ -297,21 +306,21 @@ double PViewDataGModel::getMin(int step, bool onlyVisible, int forceNumComponent return _steps[step]->getMin(); } -double PViewDataGModel::getMax(int step, bool onlyVisible, int forceNumComponents, - int componentMap[9]) +double PViewDataGModel::getMax(int step, bool onlyVisible, + int forceNumComponents, int componentMap[9]) { if(_steps.empty()) return _max; - if(onlyVisible || forceNumComponents){ + if(onlyVisible || forceNumComponents) { double vmax = -VAL_INF; - for(int ent = 0; ent < getNumEntities(step); ent++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { if(onlyVisible && skipEntity(step, ent)) continue; - for(int ele = 0; ele < getNumElements(step, ent); ele++){ + for(int ele = 0; ele < getNumElements(step, ent); ele++) { if(skipElement(step, ent, ele, onlyVisible)) continue; - for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) { double val; - getScalarValue(step, ent, ele, nod, val, - forceNumComponents, componentMap); + getScalarValue(step, ent, ele, nod, val, forceNumComponents, + componentMap); vmax = std::max(vmax, val); } } @@ -325,9 +334,9 @@ double PViewDataGModel::getMax(int step, bool onlyVisible, int forceNumComponent SBoundingBox3d PViewDataGModel::getBoundingBox(int step) { - if(step < 0 || _steps.empty()){ + if(step < 0 || _steps.empty()) { SBoundingBox3d tmp; - for(unsigned int i = 0; i < _steps.size(); i++){ + for(unsigned int i = 0; i < _steps.size(); i++) { if(!_steps[i]->getBoundingBox().empty()) tmp += _steps[i]->getBoundingBox(); } @@ -509,14 +518,13 @@ int PViewDataGModel::getDimension(int step, int ent, int ele) int PViewDataGModel::getNumNodes(int step, int ent, int ele) { MElement *e = _getElement(step, ent, ele); - if(_type == GaussPointData){ + if(_type == GaussPointData) { return _steps[step]->getGaussPoints(e->getTypeForMSH()).size() / 3; } - else{ + else { if(e->getNumChildren()) return e->getNumChildren() * e->getChild(0)->getNumVertices(); - if(getAdaptiveData()) - return e->getNumVertices(); + if(getAdaptiveData()) return e->getNumVertices(); return e->getNumPrimaryVertices(); } } @@ -533,22 +541,22 @@ MVertex *PViewDataGModel::_getNode(MElement *e, int nod) return v; } -int PViewDataGModel::getNode(int step, int ent, int ele, int nod, - double &x, double &y, double &z) +int PViewDataGModel::getNode(int step, int ent, int ele, int nod, double &x, + double &y, double &z) { MElement *e = _getElement(step, ent, ele); MVertex *v = _getNode(e, nod); - if(_type == GaussPointData){ + if(_type == GaussPointData) { std::vector<double> &p(_steps[step]->getGaussPoints(e->getTypeForMSH())); - if(p[0] == 1.e22){ + if(p[0] == 1.e22) { // hack: the points are the element vertices x = v->x(); y = v->y(); z = v->z(); } - else{ + else { double vx[8], vy[8], vz[8]; - for(int i = 0; i < e->getNumPrimaryVertices(); i++){ + for(int i = 0; i < e->getNumPrimaryVertices(); i++) { vx[i] = e->getVertex(i)->x(); vy[i] = e->getVertex(i)->y(); vz[i] = e->getVertex(i)->z(); @@ -559,7 +567,7 @@ int PViewDataGModel::getNode(int step, int ent, int ele, int nod, } return 0; } - else{ + else { x = v->x(); y = v->y(); z = v->z(); @@ -567,8 +575,8 @@ int PViewDataGModel::getNode(int step, int ent, int ele, int nod, } } -void PViewDataGModel::setNode(int step, int ent, int ele, int nod, - double x, double y, double z) +void PViewDataGModel::setNode(int step, int ent, int ele, int nod, double x, + double y, double z) { MElement *e = _getElement(step, ent, ele); MVertex *v = _getNode(e, nod); @@ -591,17 +599,18 @@ int PViewDataGModel::getNumComponents(int step, int ent, int ele) int PViewDataGModel::getNumValues(int step, int ent, int ele) { - if(_type == ElementNodeData){ + if(_type == ElementNodeData) { MElement *e = _getElement(step, ent, ele); - return _steps[step]->getMult(e->getNum()) * getNumComponents(step, ent, ele); + return _steps[step]->getMult(e->getNum()) * + getNumComponents(step, ent, ele); } - else if(_type == NodeData){ + else if(_type == NodeData) { return getNumNodes(step, ent, ele) * getNumComponents(step, ent, ele); } - else if(_type == ElementData){ + else if(_type == ElementData) { return getNumComponents(step, ent, ele); } - else{ + else { Msg::Error("getNumValues() should not be used on this type of view"); return getNumComponents(step, ent, ele); } @@ -610,76 +619,74 @@ int PViewDataGModel::getNumValues(int step, int ent, int ele) void PViewDataGModel::getValue(int step, int ent, int ele, int idx, double &val) { MElement *e = _getElement(step, ent, ele); - if(_type == ElementNodeData || _type == ElementData){ + if(_type == ElementNodeData || _type == ElementData) { val = _steps[step]->getData(e->getNum())[idx]; } - else if(_type == NodeData){ + else if(_type == NodeData) { int numcomp = _steps[step]->getNumComponents(); int nod = idx / numcomp; int comp = idx % numcomp; int num = _getNode(e, nod)->getNum(); val = _steps[step]->getData(num)[comp]; } - else{ + else { Msg::Error("getValue(index) should not be used on this type of view"); } } -void PViewDataGModel::getValue(int step, int ent, int ele, int nod, int comp, double &val) +void PViewDataGModel::getValue(int step, int ent, int ele, int nod, int comp, + double &val) { MElement *e = _getElement(step, ent, ele); - switch(_type){ - case NodeData: - { - int num = _getNode(e, nod)->getNum(); - val = _steps[step]->getData(num)[comp]; - } - break; + switch(_type) { + case NodeData: { + int num = _getNode(e, nod)->getNum(); + val = _steps[step]->getData(num)[comp]; + } break; case ElementNodeData: case GaussPointData: - if(_steps[step]->getMult(e->getNum()) < nod + 1){ + if(_steps[step]->getMult(e->getNum()) < nod + 1) { nod = 0; static bool first = true; - if(first){ - Msg::Warning("Some elements in ElementNodeData have less values than number of nodes"); + if(first) { + Msg::Warning("Some elements in ElementNodeData have less values than " + "number of nodes"); first = false; } } - val = _steps[step]->getData(e->getNum())[_steps[step]->getNumComponents() * nod + comp]; + val = _steps[step]->getData( + e->getNum())[_steps[step]->getNumComponents() * nod + comp]; break; case ElementData: - default: - val = _steps[step]->getData(e->getNum())[comp]; - break; + default: val = _steps[step]->getData(e->getNum())[comp]; break; } } -void PViewDataGModel::setValue(int step, int ent, int ele, int nod, int comp, double val) +void PViewDataGModel::setValue(int step, int ent, int ele, int nod, int comp, + double val) { MElement *e = _getElement(step, ent, ele); - switch(_type){ - case NodeData: - { - int num = _getNode(e, nod)->getNum(); - _steps[step]->getData(num)[comp] = val; - } - break; + switch(_type) { + case NodeData: { + int num = _getNode(e, nod)->getNum(); + _steps[step]->getData(num)[comp] = val; + } break; case ElementNodeData: case GaussPointData: - if(_steps[step]->getMult(e->getNum()) < nod + 1){ + if(_steps[step]->getMult(e->getNum()) < nod + 1) { nod = 0; static bool first = true; - if(first){ - Msg::Warning("Some elements in ElementNodeData have less values than number of nodes"); + if(first) { + Msg::Warning("Some elements in ElementNodeData have less values than " + "number of nodes"); first = false; } } - _steps[step]->getData(e->getNum())[_steps[step]->getNumComponents() * nod + comp] = val; + _steps[step]->getData( + e->getNum())[_steps[step]->getNumComponents() * nod + comp] = val; break; case ElementData: - default: - _steps[step]->getData(e->getNum())[comp] = val; - break; + default: _steps[step]->getData(e->getNum())[comp] = val; break; } } @@ -701,23 +708,23 @@ void PViewDataGModel::reverseElement(int step, int ent, int ele) void PViewDataGModel::smooth() { if(_type == NodeData || _type == GaussPointData) return; - std::vector<stepData<double>*> _steps2; - for(unsigned int step = 0; step < _steps.size(); step++){ + std::vector<stepData<double> *> _steps2; + for(unsigned int step = 0; step < _steps.size(); step++) { GModel *m = _steps[step]->getModel(); int numComp = _steps[step]->getNumComponents(); - _steps2.push_back(new stepData<double>(m, numComp, _steps[step]->getFileName(), - _steps[step]->getFileIndex(), - _steps[step]->getTime())); + _steps2.push_back(new stepData<double>( + m, numComp, _steps[step]->getFileName(), _steps[step]->getFileIndex(), + _steps[step]->getTime())); _steps2.back()->fillEntities(); _steps2.back()->computeBoundingBox(); std::map<int, int> nodeConnect; - for(int ent = 0; ent < getNumEntities(step); ent++){ - for(int ele = 0; ele < getNumElements(step, ent); ele++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { + for(int ele = 0; ele < getNumElements(step, ent); ele++) { MElement *e = _steps[step]->getEntity(ent)->getMeshElement(ele); double val; if(!getValueByIndex(step, e->getNum(), 0, 0, val)) continue; - for(std::size_t nod = 0; nod < e->getNumVertices(); nod++){ + for(std::size_t nod = 0; nod < e->getNumVertices(); nod++) { MVertex *v = e->getVertex(nod); if(nodeConnect.count(v->getNum())) nodeConnect[v->getNum()]++; @@ -729,11 +736,12 @@ void PViewDataGModel::smooth() } } } - for(int i = 0; i < _steps2.back()->getNumData(); i++){ + for(int i = 0; i < _steps2.back()->getNumData(); i++) { double *d = _steps2.back()->getData(i); - if(d){ + if(d) { double f = nodeConnect[i]; - if(f) for(int j = 0; j < numComp; j++) d[j] /= f; + if(f) + for(int j = 0; j < numComp; j++) d[j] /= f; } } } @@ -755,21 +763,23 @@ bool PViewDataGModel::combineTime(nameData &nd) { // sanity checks if(nd.data.size() < 2) return false; - std::vector<PViewDataGModel*> data(nd.data.size()); - for(unsigned int i = 0; i < nd.data.size(); i++){ - data[i] = dynamic_cast<PViewDataGModel*>(nd.data[i]); - if(!data[i]){ + std::vector<PViewDataGModel *> data(nd.data.size()); + for(unsigned int i = 0; i < nd.data.size(); i++) { + data[i] = dynamic_cast<PViewDataGModel *>(nd.data[i]); + if(!data[i]) { Msg::Error("Cannot combine hybrid data"); return false; } } // copy interpolation matrices - for(std::map<int, std::vector<fullMatrix<double>*> >::iterator it = - data[0]->_interpolation.begin(); it != data[0]->_interpolation.end(); it++) + for(std::map<int, std::vector<fullMatrix<double> *> >::iterator it = + data[0]->_interpolation.begin(); + it != data[0]->_interpolation.end(); it++) if(_interpolation[it->first].empty()) for(unsigned int i = 0; i < it->second.size(); i++) - _interpolation[it->first].push_back(new fullMatrix<double>(*it->second[i])); + _interpolation[it->first].push_back( + new fullMatrix<double>(*it->second[i])); // (deep) copy step data for(unsigned int i = 0; i < data.size(); i++) @@ -798,19 +808,19 @@ bool PViewDataGModel::skipEntity(int step, int ent) return !_steps[step]->getEntity(ent)->getVisibility(); } -bool PViewDataGModel::skipElement(int step, int ent, int ele, bool checkVisibility, - int samplingRate) +bool PViewDataGModel::skipElement(int step, int ent, int ele, + bool checkVisibility, int samplingRate) { if(step >= getNumTimeSteps()) return true; stepData<double> *sd = _steps[step]; if(!_steps[step]->getNumData()) return true; MElement *e = _getElement(step, ent, ele); if(checkVisibility && !e->getVisibility()) return true; - if(_type == NodeData){ + if(_type == NodeData) { for(int i = 0; i < getNumNodes(step, ent, ele); i++) if(!sd->getData(_getNode(e, i)->getNum())) return true; } - else{ + else { if(!sd->getData(e->getNum())) return true; } return PViewData::skipElement(step, ent, ele, checkVisibility, samplingRate); @@ -825,9 +835,9 @@ bool PViewDataGModel::hasTimeStep(int step) bool PViewDataGModel::hasPartition(int step, int part) { - if(step < 0 || step >= getNumTimeSteps()) - return false; - return _steps[step]->getPartitions().find(part) != _steps[step]->getPartitions().end(); + if(step < 0 || step >= getNumTimeSteps()) return false; + return _steps[step]->getPartitions().find(part) != + _steps[step]->getPartitions().end(); } bool PViewDataGModel::hasMultipleMeshes() @@ -841,7 +851,7 @@ bool PViewDataGModel::hasMultipleMeshes() bool PViewDataGModel::hasModel(GModel *model, int step) { - if(step < 0){ + if(step < 0) { for(unsigned int i = 0; i < _steps.size(); i++) if(model == _steps[i]->getModel()) return true; return false; @@ -849,7 +859,8 @@ bool PViewDataGModel::hasModel(GModel *model, int step) return (model == _steps[step]->getModel()); } -bool PViewDataGModel::getValueByIndex(int step, int dataIndex, int nod, int comp, double &val) +bool PViewDataGModel::getValueByIndex(int step, int dataIndex, int nod, + int comp, double &val) { double *d = _steps[step]->getData(dataIndex); if(!d) return false; diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index f5db135b7364015dab804e9079e35874c3e3052d..f2cf48ea404f0d24e931f57eadb2547bd5b9938c 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -10,13 +10,12 @@ #include "GModel.h" #include "SBoundingBox3d.h" -template<class Real> -class stepData{ - private: +template <class Real> class stepData { +private: // a pointer to the underlying model GModel *_model; // the unrolled list of all geometrical entities in the model - std::vector<GEntity*> _entities; + std::vector<GEntity *> _entities; // the bounding box of the view SBoundingBox3d _bbox; // the file the data was read from (if empty, refer to PViewData) @@ -37,7 +36,7 @@ class stepData{ // // FIXME: we should change this design and store a vector<int> of tags, and do // indirect addressing, even if it's a bit slower... - std::vector<Real*> *_data; + std::vector<Real *> *_data; // a vector containing the multiplying factor allowing to compute // the number of values stored in _data for each index (number of // values = getMult() * getNumComponents()). If _mult is empty, a @@ -48,7 +47,8 @@ class stepData{ std::vector<std::vector<double> > _gaussPoints; // a set of all "partitions" encountered in the data std::set<int> _partitions; - public: + +public: stepData(GModel *model, int numComp, const std::string &fileName = "", int fileIndex = -1, double time = 0., double min = VAL_INF, double max = -VAL_INF) @@ -67,12 +67,12 @@ class stepData{ _min = other._min; _max = other._max; _numComp = other._numComp; - if(other._data){ + if(other._data) { int n = other.getNumData(); - _data = new std::vector<Real*>(n, (Real*)0); - for(int i = 0; i < n; i++){ + _data = new std::vector<Real *>(n, (Real *)0); + for(int i = 0; i < n; i++) { Real *d = other.getData(i); - if(d){ + if(d) { int m = other.getMult(i) * _numComp; (*_data)[i] = new Real[m]; for(int j = 0; j < m; j++) (*_data)[i][j] = d[j]; @@ -83,29 +83,29 @@ class stepData{ _gaussPoints = other._gaussPoints; _partitions = other._partitions; } - ~stepData(){ destroyData(); } - void fillEntities(){ _model->getEntities(_entities); } - void computeBoundingBox(){ _bbox = _model->bounds(); } - GModel *getModel(){ return _model; } - SBoundingBox3d getBoundingBox(){ return _bbox; } - int getNumEntities(){ return _entities.size(); } - GEntity *getEntity(int ent){ return _entities[ent]; } - int getNumComponents(){ return _numComp; } + ~stepData() { destroyData(); } + void fillEntities() { _model->getEntities(_entities); } + void computeBoundingBox() { _bbox = _model->bounds(); } + GModel *getModel() { return _model; } + SBoundingBox3d getBoundingBox() { return _bbox; } + int getNumEntities() { return _entities.size(); } + GEntity *getEntity(int ent) { return _entities[ent]; } + int getNumComponents() { return _numComp; } int getMult(int index) { if(index < 0 || index >= (int)_mult.size()) return 1; return _mult[index]; } - std::string getFileName(){ return _fileName; } - void setFileName(const std::string &name){ _fileName = name; } - int getFileIndex(){ return _fileIndex; } - void setFileIndex(int index){ _fileIndex = index; } - double getTime(){ return _time; } - void setTime(double time){ _time = time; } - double getMin(){ return _min; } - void setMin(double min){ _min = min; } - double getMax(){ return _max; } - void setMax(double max){ _max = max; } + std::string getFileName() { return _fileName; } + void setFileName(const std::string &name) { _fileName = name; } + int getFileIndex() { return _fileIndex; } + void setFileIndex(int index) { _fileIndex = index; } + double getTime() { return _time; } + void setTime(double time) { _time = time; } + double getMin() { return _min; } + void setMin(double min) { _min = min; } + double getMax() { return _max; } + void setMax(double max) { _max = max; } int getNumData() { if(!_data) return 0; @@ -113,33 +113,34 @@ class stepData{ } void resizeData(int n) { - if(!_data) _data = new std::vector<Real*>(n, (Real*)0); - if(n > (int)_data->size()) _data->resize(n, (Real*)0); + if(!_data) _data = new std::vector<Real *>(n, (Real *)0); + if(n > (int)_data->size()) _data->resize(n, (Real *)0); } Real *getData(int index, bool allocIfNeeded = false, int mult = 1) { if(index < 0) return 0; - if(allocIfNeeded){ + if(allocIfNeeded) { if(index >= getNumData()) resizeData(index + 100); // optimize this - if(!(*_data)[index]){ + if(!(*_data)[index]) { (*_data)[index] = new Real[_numComp * mult]; for(int i = 0; i < _numComp * mult; i++) (*_data)[index][i] = 0.; } - if(mult > 1){ - if(index >= (int)_mult.size()) _mult.resize(index + 100, 1); // optimize this + if(mult > 1) { + if(index >= (int)_mult.size()) + _mult.resize(index + 100, 1); // optimize this _mult[index] = mult; } } - else{ + else { if(index >= getNumData()) return 0; } return (*_data)[index]; } void destroyData() { - if(_data){ + if(_data) { for(unsigned int i = 0; i < _data->size(); i++) - if((*_data)[i]) delete [] (*_data)[i]; + if((*_data)[i]) delete[](*_data)[i]; delete _data; _data = 0; } @@ -149,7 +150,7 @@ class stepData{ if((int)_gaussPoints.size() <= msh) _gaussPoints.resize(msh + 1); return _gaussPoints[msh]; } - std::set<int> &getPartitions(){ return _partitions; } + std::set<int> &getPartitions() { return _partitions; } double getMemoryInMb() { double b = 0.; @@ -160,7 +161,7 @@ class stepData{ // The data container using elements from one or more GModel(s). class PViewDataGModel : public PViewData { - public: +public: enum DataType { NodeData = 1, ElementData = 2, @@ -168,9 +169,10 @@ class PViewDataGModel : public PViewData { GaussPointData = 4, BeamData = 5 }; - private: + +private: // the data, indexed by time step - std::vector<stepData<double>*> _steps; + std::vector<stepData<double> *> _steps; // the global min/max of the view double _min, _max; // the type of the dataset @@ -178,42 +180,46 @@ class PViewDataGModel : public PViewData { // cache last element to speed up loops MElement *_getElement(int step, int ent, int ele); MVertex *_getNode(MElement *e, int nod); - public: - PViewDataGModel(DataType type=NodeData); + +public: + PViewDataGModel(DataType type = NodeData); ~PViewDataGModel(); - bool finalize(bool computeMinMax = true, const std::string &interpolationScheme = ""); + bool finalize(bool computeMinMax = true, + const std::string &interpolationScheme = ""); std::string getFileName(int step = -1); int getNumTimeSteps(); int getFirstNonEmptyTimeStep(int start = 0); double getTime(int step); - double getMin(int step = -1, bool onlyVisible = false, int forceNumComponents = 0, - int componentMap[9]=0); - double getMax(int step = -1, bool onlyVisible=false, int forceNumComponents = 0, - int componentMap[9]=0); - void setMin(double min){ _min = min; } - void setMax(double max){ _max = max; } - SBoundingBox3d getBoundingBox(int step=-1); - void setBoundingBox(SBoundingBox3d& box){} - int getNumScalars(int step=-1); - int getNumVectors(int step=-1); - int getNumTensors(int step=-1); - int getNumPoints(int step=-1); - int getNumLines(int step=-1); - int getNumTriangles(int step=-1); - int getNumQuadrangles(int step=-1); - int getNumPolygons(int step=-1); - int getNumTetrahedra(int step=-1); - int getNumHexahedra(int step=-1); - int getNumPrisms(int step=-1); - int getNumPyramids(int step=-1); - int getNumTrihedra(int step=-1); - int getNumPolyhedra(int step=-1); - int getNumEntities(int step=-1); - int getNumElements(int step=-1, int ent=-1); + double getMin(int step = -1, bool onlyVisible = false, + int forceNumComponents = 0, int componentMap[9] = 0); + double getMax(int step = -1, bool onlyVisible = false, + int forceNumComponents = 0, int componentMap[9] = 0); + void setMin(double min) { _min = min; } + void setMax(double max) { _max = max; } + SBoundingBox3d getBoundingBox(int step = -1); + void setBoundingBox(SBoundingBox3d &box) {} + int getNumScalars(int step = -1); + int getNumVectors(int step = -1); + int getNumTensors(int step = -1); + int getNumPoints(int step = -1); + int getNumLines(int step = -1); + int getNumTriangles(int step = -1); + int getNumQuadrangles(int step = -1); + int getNumPolygons(int step = -1); + int getNumTetrahedra(int step = -1); + int getNumHexahedra(int step = -1); + int getNumPrisms(int step = -1); + int getNumPyramids(int step = -1); + int getNumTrihedra(int step = -1); + int getNumPolyhedra(int step = -1); + int getNumEntities(int step = -1); + int getNumElements(int step = -1, int ent = -1); int getDimension(int step, int ent, int ele); int getNumNodes(int step, int ent, int ele); - int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z); - void setNode(int step, int ent, int ele, int nod, double x, double y, double z); + int getNode(int step, int ent, int ele, int nod, double &x, double &y, + double &z); + void setNode(int step, int ent, int ele, int nod, double x, double y, + double z); void tagNode(int step, int ent, int ele, int nod, int tag); int getNumComponents(int step, int ent, int ele); int getNumValues(int step, int ent, int ele); @@ -233,16 +239,17 @@ class PViewDataGModel : public PViewData { bool hasPartition(int step, int part); bool hasMultipleMeshes(); bool hasModel(GModel *model, int step = -1); - bool isNodeData(){ return _type == NodeData; } - bool useGaussPoints(){ return _type == GaussPointData; } - GModel* getModel(int step){ return _steps[step]->getModel(); } + bool isNodeData() { return _type == NodeData; } + bool useGaussPoints() { return _type == GaussPointData; } + GModel *getModel(int step) { return _steps[step]->getModel(); } GEntity *getEntity(int step, int ent); MElement *getElement(int step, int entity, int element); // get the data type - DataType getType(){ return _type; } + DataType getType() { return _type; } // direct access to value by index - bool getValueByIndex(int step, int dataIndex, int node, int comp, double &val); + bool getValueByIndex(int step, int dataIndex, int node, int comp, + double &val); // Add some data "on the fly" (data is stored in a map, indexed by // node or element number depending on the type of dataset) @@ -251,8 +258,8 @@ class PViewDataGModel : public PViewData { // Add some data "on the fly", without a map bool addData(GModel *model, const std::vector<int> &tags, - const std::vector<std::vector<double> > &data, - int step, double time, int partition, int numComp); + const std::vector<std::vector<double> > &data, int step, + double time, int partition, int numComp); // Allow to destroy the data void destroyData(); @@ -265,7 +272,8 @@ class PViewDataGModel : public PViewData { bool binary = false, bool savemesh = true, bool multipleView = false, int partitionNum = 0, bool saveInterpolationMatrices = true, - bool forceNodeData = false, bool forceElementData = false); + bool forceNodeData = false, + bool forceElementData = false); bool readMED(const std::string &fileName, int fileIndex); bool writeMED(const std::string &fileName); void importLists(int N[24], std::vector<double> *V[24]); diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index 5305ccf2f1f21a0f2600c5bde071ce87c401c952..275e1d4c9880020d9c1c136ff2dd2d39e24f663f 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -19,7 +19,7 @@ bool PViewDataGModel::addData(GModel *model, if(data.empty()) return false; if(step < 0) return false; - if (numComp < 0){ + if(numComp < 0) { numComp = 9; for(std::map<int, std::vector<double> >::const_iterator it = data.begin(); it != data.end(); it++) @@ -33,33 +33,30 @@ bool PViewDataGModel::addData(GModel *model, _steps[step]->setTime(time); int numEnt = (_type == NodeData) ? model->getNumMeshVertices() : - model->getNumMeshElements(); + model->getNumMeshElements(); _steps[step]->resizeData(numEnt); for(std::map<int, std::vector<double> >::const_iterator it = data.begin(); - it != data.end(); it++){ + it != data.end(); it++) { int mult = it->second.size() / numComp; - double *d = _steps[step]->getData(it->first, true, mult); - for(int j = 0; j < numComp * mult; j++) - d[j] = it->second[j]; + double *d = _steps[step]->getData(it->first, true, mult); + for(int j = 0; j < numComp * mult; j++) d[j] = it->second[j]; } - if(partition >= 0) - _steps[step]->getPartitions().insert(partition); + if(partition >= 0) _steps[step]->getPartitions().insert(partition); finalize(); return true; } -bool PViewDataGModel::addData(GModel *model, - const std::vector<int> &tags, +bool PViewDataGModel::addData(GModel *model, const std::vector<int> &tags, const std::vector<std::vector<double> > &data, int step, double time, int partition, int numComp) { if(data.empty() || tags.empty() || data.size() != tags.size()) return false; - if (numComp < 0){ + if(numComp < 0) { numComp = 9; for(unsigned int i = 0; i < data.size(); i++) - numComp = std::min(numComp, (int)data[i].size()); + numComp = std::min(numComp, (int)data[i].size()); } while(step >= (int)_steps.size()) @@ -69,31 +66,30 @@ bool PViewDataGModel::addData(GModel *model, _steps[step]->setTime(time); int numEnt = (_type == NodeData) ? model->getNumMeshVertices() : - model->getNumMeshElements(); + model->getNumMeshElements(); _steps[step]->resizeData(numEnt); - for(unsigned int i = 0; i < data.size(); i++){ + for(unsigned int i = 0; i < data.size(); i++) { int mult = data[i].size() / numComp; - double *d = _steps[step]->getData(tags[i], true, mult); - for(int j = 0; j < numComp * mult; j++) - d[j] = data[i][j]; + double *d = _steps[step]->getData(tags[i], true, mult); + for(int j = 0; j < numComp * mult; j++) d[j] = data[i][j]; } - if(partition >= 0) - _steps[step]->getPartitions().insert(partition); + if(partition >= 0) _steps[step]->getPartitions().insert(partition); finalize(); return true; } void PViewDataGModel::destroyData() { - for(unsigned int i = 0; i < _steps.size(); i++) - _steps[i]->destroyData(); + for(unsigned int i = 0; i < _steps.size(); i++) _steps[i]->destroyData(); } -bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fileName, - int fileIndex, FILE *fp, bool binary, bool swap, - int step, double time, int partition, int numComp, - int numEnt, const std::string &interpolationScheme) +bool PViewDataGModel::readMSH(const std::string &viewName, + const std::string &fileName, int fileIndex, + FILE *fp, bool binary, bool swap, int step, + double time, int partition, int numComp, + int numEnt, + const std::string &interpolationScheme) { Msg::Debug("Reading view `%s' step %d (time %g) partition %d: %d records", viewName.c_str(), step, time, partition, numEnt); @@ -117,33 +113,33 @@ bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fi _steps[step]->resizeData(numEnt); Msg::ResetProgressMeter(); - for(int i = 0; i < numEnt; i++){ + for(int i = 0; i < numEnt; i++) { int num; - if(binary){ + if(binary) { if(fread(&num, sizeof(int), 1, fp) != 1) return false; - if(swap) SwapBytes((char*)&num, sizeof(int), 1); + if(swap) SwapBytes((char *)&num, sizeof(int), 1); } - else{ + else { if(fscanf(fp, "%d", &num) != 1) return false; } if(num < 0) return false; int mult = 1; - if(_type == ElementNodeData || _type == GaussPointData){ - if(binary){ + if(_type == ElementNodeData || _type == GaussPointData) { + if(binary) { if(fread(&mult, sizeof(int), 1, fp) != 1) return false; - if(swap) SwapBytes((char*)&mult, sizeof(int), 1); + if(swap) SwapBytes((char *)&mult, sizeof(int), 1); } - else{ + else { if(fscanf(fp, "%d", &mult) != 1) return false; } } double *d = _steps[step]->getData(num, true, mult); - if(binary){ + if(binary) { if((int)fread(d, sizeof(double), numComp * mult, fp) != numComp * mult) return false; - if(swap) SwapBytes((char*)d, sizeof(double), numComp * mult); + if(swap) SwapBytes((char *)d, sizeof(double), numComp * mult); } - else{ + else { for(int j = 0; j < numComp * mult; j++) if(fscanf(fp, "%lf", &d[j]) != 1) return false; } @@ -152,74 +148,74 @@ bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fi // datasets (since we would recompute the min/max for all the // previously loaded steps/partitions, and thus loop over all the // elements many times) - for(int j = 0; j < mult; j++){ + for(int j = 0; j < mult; j++) { double val = ComputeScalarRep(numComp, &d[numComp * j]); _steps[step]->setMin(std::min(_steps[step]->getMin(), val)); _steps[step]->setMax(std::max(_steps[step]->getMax(), val)); _min = std::min(_min, val); _max = std::max(_max, val); } - if(numEnt > 100000) - Msg::ProgressMeter(i + 1, numEnt, true, "Reading data"); + if(numEnt > 100000) Msg::ProgressMeter(i + 1, numEnt, true, "Reading data"); } - if(partition >= 0) - _steps[step]->getPartitions().insert(partition); + if(partition >= 0) _steps[step]->getPartitions().insert(partition); finalize(false, interpolationScheme); return true; } -bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool binary, - bool saveMesh, bool multipleView, int partitionNum, - bool saveInterpolationMatrices, bool forceNodeData, - bool forceElementData) +bool PViewDataGModel::writeMSH(const std::string &fileName, double version, + bool binary, bool saveMesh, bool multipleView, + int partitionNum, bool saveInterpolationMatrices, + bool forceNodeData, bool forceElementData) { if(_steps.empty()) return true; - if(hasMultipleMeshes()){ + if(hasMultipleMeshes()) { Msg::Error("Export not done for multi-mesh views"); return false; } - if(forceNodeData && _type != NodeData){ + if(forceNodeData && _type != NodeData) { Msg::Warning("Cannot force NodeData for this dataset: saving native data"); } - if(forceElementData && _type != ElementData){ - Msg::Warning("Cannot force ElementData for this dataset: saving native data"); + if(forceElementData && _type != ElementData) { + Msg::Warning( + "Cannot force ElementData for this dataset: saving native data"); } GModel *model = _steps[0]->getModel(); FILE *fp; - if(saveMesh){ - if(!model->writeMSH(fileName, version, binary, false, false, 1.0, 0, - 0, multipleView)) return false; + if(saveMesh) { + if(!model->writeMSH(fileName, version, binary, false, false, 1.0, 0, 0, + multipleView)) + return false; // append data fp = Fopen(fileName.c_str(), binary ? "ab" : "a"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } } - else{ - if(multipleView){ + else { + if(multipleView) { fp = Fopen(fileName.c_str(), binary ? "ab" : "a"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } } - else{ + else { fp = Fopen(fileName.c_str(), binary ? "wb" : "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } fprintf(fp, "$MeshFormat\n"); fprintf(fp, "%g %d %d\n", 2.2, binary ? 1 : 0, (int)sizeof(double)); - if(binary){ + if(binary) { int one = 1; fwrite(&one, sizeof(int), 1, fp); fprintf(fp, "\n"); @@ -228,18 +224,18 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool } } - if(saveInterpolationMatrices && haveInterpolationMatrices()){ + if(saveInterpolationMatrices && haveInterpolationMatrices()) { fprintf(fp, "$InterpolationScheme\n"); fprintf(fp, "\"INTERPOLATION_SCHEME\"\n"); fprintf(fp, "%d\n", (int)_interpolation.size()); for(interpolationMatrices::iterator it = _interpolation.begin(); - it != _interpolation.end(); it++){ - if(it->second.size() >= 2){ + it != _interpolation.end(); it++) { + if(it->second.size() >= 2) { fprintf(fp, "%d\n2\n", it->first); - for(int mat = 0; mat < 2; mat++){ + for(int mat = 0; mat < 2; mat++) { int m = it->second[mat]->size1(), n = it->second[mat]->size2(); fprintf(fp, "%d %d\n", m, n); - for(int i = 0; i < m; i++){ + for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) fprintf(fp, "%.16g ", it->second[mat]->get(i, j)); fprintf(fp, "\n"); @@ -250,33 +246,34 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool fprintf(fp, "$EndInterpolationScheme\n"); } - for(unsigned int step = 0; step < _steps.size(); step++){ + for(unsigned int step = 0; step < _steps.size(); step++) { int numEnt = 0, numComp = _steps[step]->getNumComponents(); for(int i = 0; i < _steps[step]->getNumData(); i++) if(_steps[step]->getData(i)) numEnt++; - if(numEnt){ - if(_type == NodeData){ + if(numEnt) { + if(_type == NodeData) { fprintf(fp, "$NodeData\n"); fprintf(fp, "1\n\"%s\"\n", getName().c_str()); fprintf(fp, "1\n%.16g\n", _steps[step]->getTime()); if(partitionNum) - fprintf(fp, "4\n%d\n%d\n%d\n%d\n", step, numComp, numEnt, partitionNum); + fprintf(fp, "4\n%d\n%d\n%d\n%d\n", step, numComp, numEnt, + partitionNum); else fprintf(fp, "3\n%d\n%d\n%d\n", step, numComp, numEnt); - for(int i = 0; i < _steps[step]->getNumData(); i++){ - if(_steps[step]->getData(i)){ + for(int i = 0; i < _steps[step]->getNumData(); i++) { + if(_steps[step]->getData(i)) { MVertex *v = _steps[step]->getModel()->getMeshVertexByTag(i); - if(!v){ + if(!v) { Msg::Error("Unknown vertex %d in data", i); fclose(fp); return false; } int num = v->getIndex(); - if(binary){ + if(binary) { fwrite(&num, sizeof(int), 1, fp); fwrite(_steps[step]->getData(i), sizeof(double), numComp, fp); } - else{ + else { fprintf(fp, "%d", num); for(int k = 0; k < numComp; k++) fprintf(fp, " %.16g", _steps[step]->getData(i)[k]); @@ -287,41 +284,42 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool if(binary) fprintf(fp, "\n"); fprintf(fp, "$EndNodeData\n"); } - else{ + else { if(_type == ElementNodeData) fprintf(fp, "$ElementNodeData\n"); else fprintf(fp, "$ElementData\n"); if(saveInterpolationMatrices && haveInterpolationMatrices()) - fprintf(fp, "2\n\"%s\"\n\"INTERPOLATION_SCHEME\"\n", getName().c_str()); + fprintf(fp, "2\n\"%s\"\n\"INTERPOLATION_SCHEME\"\n", + getName().c_str()); else fprintf(fp, "1\n\"%s\"\n", getName().c_str()); fprintf(fp, "1\n%.16g\n", _steps[step]->getTime()); if(partitionNum) - fprintf(fp, "4\n%d\n%d\n%d\n%d\n", step, numComp, numEnt, partitionNum); + fprintf(fp, "4\n%d\n%d\n%d\n%d\n", step, numComp, numEnt, + partitionNum); else fprintf(fp, "3\n%d\n%d\n%d\n", step, numComp, numEnt); - for(int i = 0; i < _steps[step]->getNumData(); i++){ - if(_steps[step]->getData(i)){ + for(int i = 0; i < _steps[step]->getNumData(); i++) { + if(_steps[step]->getData(i)) { MElement *e = model->getMeshElementByTag(i); - if(!e){ + if(!e) { Msg::Error("Unknown element %d in data", i); fclose(fp); return false; } int mult = _steps[step]->getMult(i); int num = model->getMeshElementIndex(e); - if(binary){ + if(binary) { fwrite(&num, sizeof(int), 1, fp); - if(_type == ElementNodeData) - fwrite(&mult, sizeof(int), 1, fp); - fwrite(_steps[step]->getData(i), sizeof(double), numComp * mult, fp); + if(_type == ElementNodeData) fwrite(&mult, sizeof(int), 1, fp); + fwrite(_steps[step]->getData(i), sizeof(double), numComp * mult, + fp); } - else{ + else { fprintf(fp, "%d", num); - if(_type == ElementNodeData) - fprintf(fp, " %d", mult); + if(_type == ElementNodeData) fprintf(fp, " %d", mult); for(int k = 0; k < numComp * mult; k++) fprintf(fp, " %.16g", _steps[step]->getData(i)[k]); fprintf(fp, "\n"); @@ -343,50 +341,122 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool void PViewDataGModel::importLists(int N[24], std::vector<double> *V[24]) { - for(int idxtype = 0; idxtype < 24; idxtype++){ + for(int idxtype = 0; idxtype < 24; idxtype++) { int nbe = N[idxtype]; if(!nbe) continue; std::vector<double> *list = V[idxtype]; int nc = 0, nn = 0; - switch(idxtype){ - case 0 : nc = 1; nn = 1; break; // SP - case 1 : nc = 3; nn = 1; break; // VP - case 2 : nc = 9; nn = 1; break; // TP - case 3 : nc = 1; nn = 2; break; // SL - case 4 : nc = 3; nn = 2; break; // VL - case 5 : nc = 9; nn = 2; break; // TL - case 6 : nc = 1; nn = 3; break; // ST - case 7 : nc = 3; nn = 3; break; // VT - case 8 : nc = 9; nn = 3; break; // TT - case 9 : nc = 1; nn = 4; break; // SQ - case 10: nc = 3; nn = 4; break; // VQ - case 11: nc = 9; nn = 4; break; // TQ - case 12: nc = 1; nn = 4; break; // SS - case 13: nc = 3; nn = 4; break; // VS - case 14: nc = 9; nn = 4; break; // TS - case 15: nc = 1; nn = 8; break; // SH - case 16: nc = 3; nn = 8; break; // VH - case 17: nc = 9; nn = 8; break; // TH - case 18: nc = 1; nn = 6; break; // SI - case 19: nc = 3; nn = 6; break; // VI - case 20: nc = 9; nn = 6; break; // TI - case 21: nc = 1; nn = 5; break; // SY - case 22: nc = 3; nn = 5; break; // VY - case 23: nc = 9; nn = 5; break; // TY + switch(idxtype) { + case 0: + nc = 1; + nn = 1; + break; // SP + case 1: + nc = 3; + nn = 1; + break; // VP + case 2: + nc = 9; + nn = 1; + break; // TP + case 3: + nc = 1; + nn = 2; + break; // SL + case 4: + nc = 3; + nn = 2; + break; // VL + case 5: + nc = 9; + nn = 2; + break; // TL + case 6: + nc = 1; + nn = 3; + break; // ST + case 7: + nc = 3; + nn = 3; + break; // VT + case 8: + nc = 9; + nn = 3; + break; // TT + case 9: + nc = 1; + nn = 4; + break; // SQ + case 10: + nc = 3; + nn = 4; + break; // VQ + case 11: + nc = 9; + nn = 4; + break; // TQ + case 12: + nc = 1; + nn = 4; + break; // SS + case 13: + nc = 3; + nn = 4; + break; // VS + case 14: + nc = 9; + nn = 4; + break; // TS + case 15: + nc = 1; + nn = 8; + break; // SH + case 16: + nc = 3; + nn = 8; + break; // VH + case 17: + nc = 9; + nn = 8; + break; // TH + case 18: + nc = 1; + nn = 6; + break; // SI + case 19: + nc = 3; + nn = 6; + break; // VI + case 20: + nc = 9; + nn = 6; + break; // TI + case 21: + nc = 1; + nn = 5; + break; // SY + case 22: + nc = 3; + nn = 5; + break; // VY + case 23: + nc = 9; + nn = 5; + break; // TY } int stride = list->size() / nbe; int numSteps = (stride - 1) / nc / nn; - for(int step = 0; step < numSteps; step++){ + for(int step = 0; step < numSteps; step++) { _steps.push_back(new stepData<double>(GModel::current(), nc)); _steps[step]->fillEntities(); _steps[step]->computeBoundingBox(); _steps[step]->setTime(step); _steps[step]->resizeData(nbe); - for(unsigned int j = 0; j < list->size(); j += stride){ + for(unsigned int j = 0; j < list->size(); j += stride) { double *tmp = &(*list)[j]; int num = (int)tmp[0]; - double *d = _steps[step]->getData(num, true, nn); - for(int k = 0; k < nc * nn; k++){ + double *d = _steps[step]->getData(num, true, nn); + for(int k = 0; k < nc * nn; k++) { d[k] = tmp[1 + nc * nn * step + k]; } } @@ -402,7 +472,7 @@ extern "C" { #include <med.h> } -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) // To avoid too many ifdefs below we use defines for the bits of the // API that did not change too much between MED2 and MED3. If we // remove MED2 support at some point, please remove these defines and @@ -431,26 +501,25 @@ std::vector<std::string> medGetFieldNames(const std::string &fileName) { std::vector<std::string> fieldNames; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_idt fid = MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY); #else - med_idt fid = MEDouvrir((char*)fileName.c_str(), MED_LECTURE); + med_idt fid = MEDouvrir((char *)fileName.c_str(), MED_LECTURE); #endif if(fid < 0) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return fieldNames; } -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_int numFields = MEDnField(fid); #else med_int numFields = MEDnChamp(fid, 0); #endif - for(int index = 0; index < numFields; index++){ - + for(int index = 0; index < numFields; index++) { med_int numComp = MEDnChamp(fid, index + 1); - if(numComp <= 0){ + if(numComp <= 0) { Msg::Error("Could not get number of components for MED field"); return fieldNames; } @@ -461,13 +530,13 @@ std::vector<std::string> medGetFieldNames(const std::string &fileName) std::vector<char> compUnit(numComp * MED_TAILLE_PNOM + 1); med_int numSteps = 0; med_type_champ type; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_bool localMesh; if(MEDfieldInfo(fid, index + 1, name, meshName, &localMesh, &type, - &compName[0], &compUnit[0], dtUnit, &numSteps) < 0){ + &compName[0], &compUnit[0], dtUnit, &numSteps) < 0) { #else if(MEDchampInfo(fid, index + 1, name, &type, &compName[0], &compUnit[0], - numComp) < 0){ + numComp) < 0) { #endif Msg::Error("Could not get MED field info"); return fieldNames; @@ -475,10 +544,10 @@ std::vector<std::string> medGetFieldNames(const std::string &fileName) fieldNames.push_back(name); } -#if (MED_MAJOR_NUM == 3) - if(MEDfileClose(fid) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDfileClose(fid) < 0) { #else - if(MEDfermer(fid) < 0){ + if(MEDfermer(fid) < 0) { #endif Msg::Error("Unable to close file '%s'", fileName.c_str()); } @@ -487,14 +556,14 @@ std::vector<std::string> medGetFieldNames(const std::string &fileName) bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) { - med_idt fid = MEDouvrir((char*)fileName.c_str(), MED_LECTURE); - if(fid < 0){ + med_idt fid = MEDouvrir((char *)fileName.c_str(), MED_LECTURE); + if(fid < 0) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } med_int numComp = MEDnChamp(fid, fileIndex + 1); - if(numComp <= 0){ + if(numComp <= 0) { Msg::Error("Could not get number of components for MED field"); return false; } @@ -505,13 +574,13 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) std::vector<char> compUnit(numComp * MED_TAILLE_PNOM + 1); med_int numSteps = 0; med_type_champ type; -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_bool localMesh; if(MEDfieldInfo(fid, fileIndex + 1, name, meshName, &localMesh, &type, - &compName[0], &compUnit[0], dtUnit, &numSteps) < 0){ + &compName[0], &compUnit[0], dtUnit, &numSteps) < 0) { #else if(MEDchampInfo(fid, fileIndex + 1, name, &type, &compName[0], &compUnit[0], - numComp) < 0){ + numComp) < 0) { #endif Msg::Error("Could not get MED field info"); return false; @@ -526,41 +595,42 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) (numComp <= 1) ? 1 : (numComp <= 3) ? 3 : (numComp <= 9) ? 9 : numComp; if(numCompMsh > 9) - Msg::Info("More than 9 components in field: you will probably want to force " - "the field type to scalar, vector or tensor in the options"); + Msg::Info( + "More than 9 components in field: you will probably want to force " + "the field type to scalar, vector or tensor in the options"); // Warning! The ordering of the elements in the last two lists is // important: it should match the ordering of the MSH element types // (when elements are saved without tags, this governs the order // with which we implicitly index them in GModel::readMED) - const med_entite_maillage entType[] = - {MED_NOEUD, MED_MAILLE, MED_NOEUD_MAILLE}; -#if (MED_MAJOR_NUM == 3) - const med_geometrie_element eleType[] = - {MED_NONE, MED_SEG2, MED_TRIA3, MED_QUAD4, MED_TETRA4, MED_HEXA8, - MED_PENTA6, MED_PYRA5, MED_SEG3, MED_TRIA6, MED_QUAD9, MED_TETRA10, - MED_HEXA27, MED_POINT1, MED_QUAD8, MED_HEXA20, MED_PENTA15, MED_PYRA13}; - const int nodesPerEle[] = - {0, 2, 3, 4, 4, 8, 6, 5, 3, 6, 9, 10, 27, 1, 8, 20, 15, 13}; + const med_entite_maillage entType[] = {MED_NOEUD, MED_MAILLE, + MED_NOEUD_MAILLE}; +#if(MED_MAJOR_NUM == 3) + const med_geometrie_element eleType[] = { + MED_NONE, MED_SEG2, MED_TRIA3, MED_QUAD4, MED_TETRA4, MED_HEXA8, + MED_PENTA6, MED_PYRA5, MED_SEG3, MED_TRIA6, MED_QUAD9, MED_TETRA10, + MED_HEXA27, MED_POINT1, MED_QUAD8, MED_HEXA20, MED_PENTA15, MED_PYRA13}; + const int nodesPerEle[] = {0, 2, 3, 4, 4, 8, 6, 5, 3, + 6, 9, 10, 27, 1, 8, 20, 15, 13}; #else - const med_geometrie_element eleType[] = - {MED_NONE, MED_SEG2, MED_TRIA3, MED_QUAD4, MED_TETRA4, MED_HEXA8, - MED_PENTA6, MED_PYRA5, MED_SEG3, MED_TRIA6, MED_TETRA10, - MED_POINT1, MED_QUAD8, MED_HEXA20, MED_PENTA15, MED_PYRA13}; - const int nodesPerEle[] = - {0, 2, 3, 4, 4, 8, 6, 5, 3, 6, 10, 1, 8, 20, 15, 13}; + const med_geometrie_element eleType[] = { + MED_NONE, MED_SEG2, MED_TRIA3, MED_QUAD4, MED_TETRA4, MED_HEXA8, + MED_PENTA6, MED_PYRA5, MED_SEG3, MED_TRIA6, MED_TETRA10, MED_POINT1, + MED_QUAD8, MED_HEXA20, MED_PENTA15, MED_PYRA13}; + const int nodesPerEle[] = {0, 2, 3, 4, 4, 8, 6, 5, + 3, 6, 10, 1, 8, 20, 15, 13}; #endif std::vector<std::pair<int, int> > pairs; - for(unsigned int i = 0; i < sizeof(entType) / sizeof(entType[0]); i++){ - for(unsigned int j = 0; j < sizeof(eleType) / sizeof(eleType[0]); j++){ - if((!i && !j) || j){ -#if (MED_MAJOR_NUM == 3) + for(unsigned int i = 0; i < sizeof(entType) / sizeof(entType[0]); i++) { + for(unsigned int j = 0; j < sizeof(eleType) / sizeof(eleType[0]); j++) { + if((!i && !j) || j) { +#if(MED_MAJOR_NUM == 3) med_int n = numSteps; #else med_int n = MEDnPasdetemps(fid, name, entType[i], eleType[j]); #endif - if(n > 0){ + if(n > 0) { pairs.push_back(std::pair<int, int>(i, j)); numSteps = std::max(numSteps, n); } @@ -569,41 +639,42 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) } } - if(numSteps < 1 || pairs.empty()){ + if(numSteps < 1 || pairs.empty()) { Msg::Error("Nothing to import from MED file"); return false; } - for(int step = 0; step < numSteps; step++){ - + for(int step = 0; step < numSteps; step++) { // FIXME: in MED3 we might want to loop over all profiles instead // of relying of the default one // FIXME: MED3 allows to store multi-step meshes; we should // interface this with our own gmodel-per-step structure - for(unsigned int pair = 0; pair < pairs.size(); pair++){ + for(unsigned int pair = 0; pair < pairs.size(); pair++) { // get step info med_entite_maillage ent = entType[pairs[pair].first]; med_geometrie_element ele = eleType[pairs[pair].second]; med_int numdt, numit, ngauss; med_float dt; -#if (MED_MAJOR_NUM == 3) - if(MEDfieldComputingStepInfo(fid, name, step + 1, &numdt, &numit, &dt) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDfieldComputingStepInfo(fid, name, step + 1, &numdt, &numit, &dt) < + 0) { #else char dtunit[MED_TAILLE_PNOM + 1]; med_booleen local; med_int numMeshes; - if(MEDpasdetempsInfo(fid, name, ent, ele, step + 1, &ngauss, &numdt, &numit, - dtunit, &dt, meshName, &local, &numMeshes) < 0){ + if(MEDpasdetempsInfo(fid, name, ent, ele, step + 1, &ngauss, &numdt, + &numit, dtunit, &dt, meshName, &local, + &numMeshes) < 0) { #endif Msg::Error("Could not read step info"); return false; } // create step data - if(!pair){ + if(!pair) { GModel *m = GModel::findByName(meshName); - if(!m){ + if(!m) { Msg::Error("Could not find mesh <<%s>>", meshName); return false; } @@ -621,25 +692,26 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) // get number of values in the field (numVal takes the number of // Gauss points or the number of nodes per element into account, // but not the number of components) -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_int profileSize; - med_int numVal = MEDfieldnValueWithProfile(fid, name, numdt, numit, ent, ele, - 1, MED_COMPACT_STMODE, profileName, - &profileSize, locName, &ngauss); + med_int numVal = MEDfieldnValueWithProfile( + fid, name, numdt, numit, ent, ele, 1, MED_COMPACT_STMODE, profileName, + &profileSize, locName, &ngauss); numVal *= ngauss; #else - med_int numVal = MEDnVal(fid, name, ent, ele, numdt, numit, meshName, - MED_COMPACT); + med_int numVal = + MEDnVal(fid, name, ent, ele, numdt, numit, meshName, MED_COMPACT); #endif if(numVal <= 0) continue; - _type = (ent == MED_NOEUD) ? NodeData : (ent == MED_MAILLE) ? - ElementData : ElementNodeData; + _type = (ent == MED_NOEUD) ? + NodeData : + (ent == MED_MAILLE) ? ElementData : ElementNodeData; int mult = 1; - if(ent == MED_NOEUD_MAILLE){ + if(ent == MED_NOEUD_MAILLE) { mult = nodesPerEle[pairs[pair].second]; } - else if(ngauss != 1){ + else if(ngauss != 1) { mult = ngauss; _type = GaussPointData; } @@ -647,123 +719,124 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) // read field data std::vector<double> val(numVal * numComp); -#if (MED_MAJOR_NUM == 3) - if(MEDfieldValueWithProfileRd(fid, name, numdt, numit, ent, ele, MED_COMPACT_STMODE, - profileName, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, - (unsigned char*)&val[0]) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDfieldValueWithProfileRd(fid, name, numdt, numit, ent, ele, + MED_COMPACT_STMODE, profileName, + MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, + (unsigned char *)&val[0]) < 0) { #else - if(MEDchampLire(fid, meshName, name, (unsigned char*)&val[0], MED_FULL_INTERLACE, - MED_ALL, locName, profileName, MED_COMPACT, ent, ele, - numdt, numit) < 0){ + if(MEDchampLire(fid, meshName, name, (unsigned char *)&val[0], + MED_FULL_INTERLACE, MED_ALL, locName, profileName, + MED_COMPACT, ent, ele, numdt, numit) < 0) { #endif Msg::Error("Could not read field values"); return false; } - Msg::Debug("MED: eletyp=%d entity=%d (0:cell, 3:node, 4:elenode) ngauss=%d " - "localizationName=%s profileName=%s -- stepDataType=%d", - ele, ent, ngauss, locName, profileName, _type); + Msg::Debug( + "MED: eletyp=%d entity=%d (0:cell, 3:node, 4:elenode) ngauss=%d " + "localizationName=%s profileName=%s -- stepDataType=%d", + ele, ent, ngauss, locName, profileName, _type); // read Gauss point data - if(_type == GaussPointData){ - std::vector<double> &p(_steps[step]->getGaussPoints(med2mshElementType(ele))); - if(std::string(locName) == MED_GAUSS_ELNO){ + if(_type == GaussPointData) { + std::vector<double> &p( + _steps[step]->getGaussPoints(med2mshElementType(ele))); + if(std::string(locName) == MED_GAUSS_ELNO) { // special case: the gauss points are the vertices of the // element; in this case no explicit localization has to be // created in MED p.resize(ngauss * 3, 1.e22); } - else{ + else { int dim = ele / 100; std::vector<med_float> refcoo((ele % 100) * dim); std::vector<med_float> gscoo(ngauss * dim); std::vector<med_float> wg(ngauss); -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) if(MEDlocalizationRd(fid, locName, MED_FULL_INTERLACE, &refcoo[0], - &gscoo[0], &wg[0]) < 0){ + &gscoo[0], &wg[0]) < 0) { #else - if(MEDgaussLire(fid, &refcoo[0], &gscoo[0], &wg[0], MED_FULL_INTERLACE, - locName) < 0){ + if(MEDgaussLire(fid, &refcoo[0], &gscoo[0], &wg[0], + MED_FULL_INTERLACE, locName) < 0) { #endif Msg::Error("Could not read Gauss points"); return false; } // FIXME: we should check that refcoo corresponds to our // internal reference element - for(int i = 0; i < (int)gscoo.size(); i++){ + for(int i = 0; i < (int)gscoo.size(); i++) { p.push_back(gscoo[i]); - if(i % dim == dim - 1) for(int j = 0; j < 3 - dim; j++) p.push_back(0.); + if(i % dim == dim - 1) + for(int j = 0; j < 3 - dim; j++) p.push_back(0.); } } } // compute profile (indices in full array of entities of given type) std::vector<med_int> profile; - if(std::string(profileName) != MED_NOPFL){ + if(std::string(profileName) != MED_NOPFL) { med_int n = MEDnValProfil(fid, profileName); - if(n > 0){ + if(n > 0) { Msg::Debug("MED has full profile"); profile.resize(n); -#if (MED_MAJOR_NUM == 3) - if(MEDprofileRd(fid, profileName, &profile[0]) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDprofileRd(fid, profileName, &profile[0]) < 0) { #else - if(MEDprofilLire(fid, &profile[0], profileName) < 0){ + if(MEDprofilLire(fid, &profile[0], profileName) < 0) { #endif Msg::Error("Could not read profile"); return false; } } } - if(profile.empty()){ + if(profile.empty()) { Msg::Debug("MED profile is empty -- using continuous sequence"); profile.resize(numVal / mult); - for(unsigned int i = 0; i < profile.size(); i++) - profile[i] = i + 1; + for(unsigned int i = 0; i < profile.size(); i++) profile[i] = i + 1; } // get size of full array and tags (if any) of entities bool nodal = (ent == MED_NOEUD); -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_bool changeOfCoord; med_bool geoTransform; - med_int numEnt = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, - nodal ? MED_NODE : MED_CELL, - nodal ? MED_NO_GEOTYPE : ele, - nodal ? MED_COORDINATE : MED_CONNECTIVITY, - nodal ? MED_NO_CMODE : MED_NODAL, - &changeOfCoord, &geoTransform); + med_int numEnt = MEDmeshnEntity( + fid, meshName, MED_NO_DT, MED_NO_IT, nodal ? MED_NODE : MED_CELL, + nodal ? MED_NO_GEOTYPE : ele, nodal ? MED_COORDINATE : MED_CONNECTIVITY, + nodal ? MED_NO_CMODE : MED_NODAL, &changeOfCoord, &geoTransform); #else - med_int numEnt = MEDnEntMaa(fid, meshName, nodal ? MED_COOR : MED_CONN, - nodal ? MED_NOEUD : MED_MAILLE, - nodal ? MED_NONE : ele, - nodal ? (med_connectivite)0 : MED_NOD); + med_int numEnt = + MEDnEntMaa(fid, meshName, nodal ? MED_COOR : MED_CONN, + nodal ? MED_NOEUD : MED_MAILLE, nodal ? MED_NONE : ele, + nodal ? (med_connectivite)0 : MED_NOD); #endif std::vector<med_int> tags(numEnt); -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, nodal ? MED_NODE : MED_CELL, nodal ? MED_NO_GEOTYPE : ele, &tags[0]) < 0) #else - if(MEDnumLire(fid, meshName, &tags[0], numEnt, nodal ? MED_NOEUD : MED_MAILLE, - nodal ? MED_NONE : ele) < 0) + if(MEDnumLire(fid, meshName, &tags[0], numEnt, + nodal ? MED_NOEUD : MED_MAILLE, nodal ? MED_NONE : ele) < 0) #endif tags.clear(); // if we don't have tags, compute the starting index (i.e., how many // elements of different type are in the mesh before these ones) int startIndex = 0; - if(tags.empty()){ + if(tags.empty()) { int maxv, maxe; _steps[step]->getModel()->getCheckPointedMaxNumbers(maxv, maxe); - if(nodal){ + if(nodal) { startIndex += maxv; } - else{ - for(int i = 1; i < pairs[pair].second; i++){ -#if (MED_MAJOR_NUM == 3) - med_int n = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, - MED_CELL, eleType[i], MED_CONNECTIVITY, - MED_NODAL, &changeOfCoord, &geoTransform); + else { + for(int i = 1; i < pairs[pair].second; i++) { +#if(MED_MAJOR_NUM == 3) + med_int n = MEDmeshnEntity( + fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, eleType[i], + MED_CONNECTIVITY, MED_NODAL, &changeOfCoord, &geoTransform); #else med_int n = MEDnEntMaa(fid, meshName, MED_CONN, MED_MAILLE, eleType[i], MED_NOD); @@ -776,13 +849,13 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) } // compute entity numbers using profile, then fill step data - for(unsigned int i = 0; i < profile.size(); i++){ + for(unsigned int i = 0; i < profile.size(); i++) { int num; - if(tags.empty()){ + if(tags.empty()) { num = startIndex + profile[i]; } - else{ - if(profile[i] == 0 || profile[i] > (int)tags.size()){ + else { + if(profile[i] == 0 || profile[i] > (int)tags.size()) { Msg::Error("Wrong index in profile"); return false; } @@ -790,7 +863,7 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) } double *d = _steps[step]->getData(num, true, mult); - for(int j = 0; j < mult; j++){ + for(int j = 0; j < mult; j++) { // reorder nodes if we have ElementNode data int j2 = (ent == MED_NOEUD_MAILLE) ? med2mshNodeIndex(ele, j) : j; for(int k = 0; k < numComp; k++) @@ -802,8 +875,8 @@ bool PViewDataGModel::readMED(const std::string &fileName, int fileIndex) finalize(); - if(MEDfermer(fid) < 0){ - Msg::Error("Unable to close file '%s'", (char*)fileName.c_str()); + if(MEDfermer(fid) < 0) { + Msg::Error("Unable to close file '%s'", (char *)fileName.c_str()); return false; } return true; @@ -813,12 +886,12 @@ bool PViewDataGModel::writeMED(const std::string &fileName) { if(_steps.empty()) return true; - if(hasMultipleMeshes()){ + if(hasMultipleMeshes()) { Msg::Error("Export not done for multi-mesh views"); return false; } - if(_type != NodeData){ + if(_type != NodeData) { Msg::Error("Can only export node-based datasets for now"); return false; } @@ -831,19 +904,19 @@ bool PViewDataGModel::writeMED(const std::string &fileName) std::string meshName(model->getName()); std::string fieldName(getName()); - med_idt fid = MEDouvrir((char*)fileName.c_str(), MED_LECTURE_AJOUT); - if(fid < 0){ + med_idt fid = MEDouvrir((char *)fileName.c_str(), MED_LECTURE_AJOUT); + if(fid < 0) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } // compute profile - char *profileName = (char*)"nodeProfile"; + char *profileName = (char *)"nodeProfile"; std::vector<med_int> profile, indices; - for(int i = 0; i < _steps[0]->getNumData(); i++){ - if(_steps[0]->getData(i)){ + for(int i = 0; i < _steps[0]->getNumData(); i++) { + if(_steps[0]->getData(i)) { MVertex *v = _steps[0]->getModel()->getMeshVertexByTag(i); - if(!v){ + if(!v) { Msg::Error("Unknown vertex %d in data", i); return false; } @@ -852,52 +925,52 @@ bool PViewDataGModel::writeMED(const std::string &fileName) } } - if(profile.empty()){ + if(profile.empty()) { Msg::Error("Nothing to save"); return false; } -#if (MED_MAJOR_NUM == 3) - if(MEDprofileWr(fid, profileName, (med_int)profile.size(), &profile[0]) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDprofileWr(fid, profileName, (med_int)profile.size(), &profile[0]) < 0) { #else - if(MEDprofilEcr(fid, &profile[0], (med_int)profile.size(), profileName) < 0){ + if(MEDprofilEcr(fid, &profile[0], (med_int)profile.size(), profileName) < 0) { #endif Msg::Error("Could not create MED profile"); return false; } int numComp = _steps[0]->getNumComponents(); -#if (MED_MAJOR_NUM == 3) - if(MEDfieldCr(fid, (char*)fieldName.c_str(), MED_FLOAT64, (med_int)numComp, - "unknown", "unknown", "unknown", (char*)meshName.c_str()) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDfieldCr(fid, (char *)fieldName.c_str(), MED_FLOAT64, (med_int)numComp, + "unknown", "unknown", "unknown", + (char *)meshName.c_str()) < 0) { #else - if(MEDchampCr(fid, (char*)fieldName.c_str(), MED_FLOAT64, - (char*)"unknown", (char*)"unknown", - (med_int)numComp) < 0){ + if(MEDchampCr(fid, (char *)fieldName.c_str(), MED_FLOAT64, (char *)"unknown", + (char *)"unknown", (med_int)numComp) < 0) { #endif Msg::Error("Could not create MED field"); return false; } -#if (MED_MAJOR_NUM == 3) +#if(MED_MAJOR_NUM == 3) med_bool changeOfCoord, geoTransform; - med_int numNodes = MEDmeshnEntity(fid, (char*)meshName.c_str(), - MED_NO_DT, MED_NO_IT, MED_NODE, - MED_NO_GEOTYPE, MED_COORDINATE, MED_NO_CMODE, - &changeOfCoord, &geoTransform); + med_int numNodes = + MEDmeshnEntity(fid, (char *)meshName.c_str(), MED_NO_DT, MED_NO_IT, + MED_NODE, MED_NO_GEOTYPE, MED_COORDINATE, MED_NO_CMODE, + &changeOfCoord, &geoTransform); #else - med_int numNodes = MEDnEntMaa(fid, (char*)meshName.c_str(), MED_COOR, MED_NOEUD, - MED_NONE, (med_connectivite)0); + med_int numNodes = MEDnEntMaa(fid, (char *)meshName.c_str(), MED_COOR, + MED_NOEUD, MED_NONE, (med_connectivite)0); #endif - if(numNodes <= 0){ + if(numNodes <= 0) { Msg::Error("Could not get valid number of nodes in mesh"); return false; } - for(unsigned int step = 0; step < _steps.size(); step++){ + for(unsigned int step = 0; step < _steps.size(); step++) { unsigned int n = 0; for(int i = 0; i < _steps[step]->getNumData(); i++) if(_steps[step]->getData(i)) n++; - if(n != profile.size() || numComp != _steps[step]->getNumComponents()){ + if(n != profile.size() || numComp != _steps[step]->getNumComponents()) { Msg::Error("Skipping incompatible step"); continue; } @@ -906,27 +979,26 @@ bool PViewDataGModel::writeMED(const std::string &fileName) for(unsigned int i = 0; i < profile.size(); i++) for(int k = 0; k < numComp; k++) val[i * numComp + k] = _steps[step]->getData(indices[i])[k]; -#if (MED_MAJOR_NUM == 3) - if(MEDfieldValueWithProfileWr(fid, (char*)fieldName.c_str(), (med_int)(step + 1), - MED_NO_IT, - time, MED_NODE, MED_NO_GEOTYPE, MED_COMPACT_STMODE, - profileName, "", MED_FULL_INTERLACE, - MED_ALL_CONSTITUENT, numNodes, - (unsigned char*)&val[0]) < 0){ +#if(MED_MAJOR_NUM == 3) + if(MEDfieldValueWithProfileWr( + fid, (char *)fieldName.c_str(), (med_int)(step + 1), MED_NO_IT, time, + MED_NODE, MED_NO_GEOTYPE, MED_COMPACT_STMODE, profileName, "", + MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, numNodes, + (unsigned char *)&val[0]) < 0) { #else - if(MEDchampEcr(fid, (char*)meshName.c_str(), (char*)fieldName.c_str(), - (unsigned char*)&val[0], - MED_FULL_INTERLACE, numNodes, (char*)MED_NOGAUSS, MED_ALL, - profileName, MED_COMPACT, MED_NOEUD, MED_NONE, (med_int)step, - (char*)"unknown", time, MED_NONOR) < 0){ + if(MEDchampEcr(fid, (char *)meshName.c_str(), (char *)fieldName.c_str(), + (unsigned char *)&val[0], MED_FULL_INTERLACE, numNodes, + (char *)MED_NOGAUSS, MED_ALL, profileName, MED_COMPACT, + MED_NOEUD, MED_NONE, (med_int)step, (char *)"unknown", time, + MED_NONOR) < 0) { #endif Msg::Error("Could not write MED field"); return false; } } - if(MEDfermer(fid) < 0){ - Msg::Error("Unable to close file '%s'", (char*)fileName.c_str()); + if(MEDfermer(fid) < 0) { + Msg::Error("Unable to close file '%s'", (char *)fileName.c_str()); return false; } return true; diff --git a/Post/PViewDataIO.cpp b/Post/PViewDataIO.cpp index 904fbd67e32d5fe32b775f05d5333db80de3f751..e4016b5fb95bfcc5e4e994730ae297295feff555 100644 --- a/Post/PViewDataIO.cpp +++ b/Post/PViewDataIO.cpp @@ -15,12 +15,12 @@ bool PViewData::writeSTL(const std::string &fileName) { FILE *fp = Fopen(fileName.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } - if(!getNumTriangles() && !getNumQuadrangles()){ + if(!getNumTriangles() && !getNumQuadrangles()) { Msg::Error("No surface elements to save"); fclose(fp); return false; @@ -29,17 +29,16 @@ bool PViewData::writeSTL(const std::string &fileName) int step = getFirstNonEmptyTimeStep(); fprintf(fp, "solid Created by Gmsh\n"); - for(int ent = 0; ent < getNumEntities(step); ent++){ - for(int ele = 0; ele < getNumElements(step, ent); ele++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { + for(int ele = 0; ele < getNumElements(step, ent); ele++) { if(getDimension(step, ent, ele) != 2) continue; if(skipElement(step, ent, ele)) continue; int N = getNumNodes(step, ent, ele); if(N != 3 && N != 4) continue; double x[4], y[4], z[4], n[3]; - for(int i = 0; i < N; i++) - getNode(step, ent, ele, i, x[i], y[i], z[i]); + for(int i = 0; i < N; i++) getNode(step, ent, ele, i, x[i], y[i], z[i]); normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], n); - if(N == 3){ + if(N == 3) { fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]); fprintf(fp, " outer loop\n"); fprintf(fp, " vertex %g %g %g\n", x[0], y[0], z[0]); @@ -48,7 +47,7 @@ bool PViewData::writeSTL(const std::string &fileName) fprintf(fp, " endloop\n"); fprintf(fp, "endfacet\n"); } - else{ + else { fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]); fprintf(fp, " outer loop\n"); fprintf(fp, " vertex %g %g %g\n", x[0], y[0], z[0]); @@ -75,21 +74,21 @@ bool PViewData::writeSTL(const std::string &fileName) bool PViewData::writeTXT(const std::string &fileName) { FILE *fp = Fopen(fileName.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } - for(int step = 0; step < getNumTimeSteps(); step++){ - for(int ent = 0; ent < getNumEntities(step); ent++){ - for(int ele = 0; ele < getNumElements(step, ent); ele++){ + for(int step = 0; step < getNumTimeSteps(); step++) { + for(int ent = 0; ent < getNumEntities(step); ent++) { + for(int ele = 0; ele < getNumElements(step, ent); ele++) { if(skipElement(step, ent, ele)) continue; - for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) { double x, y, z; getNode(step, ent, ele, nod, x, y, z); fprintf(fp, "%d %.16g %d %d %.16g %.16g %.16g ", step, getTime(step), ent, ele, x, y, z); - for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++){ + for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++) { double val; getValue(step, ent, ele, nod, comp, val); fprintf(fp, "%.16g ", val); @@ -107,21 +106,23 @@ bool PViewData::writeTXT(const std::string &fileName) bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed, bool append) { - if(_adaptive){ - Msg::Warning("Writing adapted dataset (will only export current time step)"); + if(_adaptive) { + Msg::Warning( + "Writing adapted dataset (will only export current time step)"); return _adaptive->getData()->writePOS(fileName, binary, parsed, append); } - if(hasMultipleMeshes()){ + if(hasMultipleMeshes()) { Msg::Error("Cannot export multi-mesh datasets in .pos format"); return false; } if(haveInterpolationMatrices()) - Msg::Warning("Discarding interpolation matrices when saving in .pos format"); + Msg::Warning( + "Discarding interpolation matrices when saving in .pos format"); if(binary || !parsed) Msg::Warning("Only parsed .pos files can be exported for this view type"); FILE *fp = Fopen(fileName.c_str(), append ? "a" : "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } @@ -129,40 +130,60 @@ bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed, fprintf(fp, "View \"%s\" {\n", getName().c_str()); int firstNonEmptyStep = getFirstNonEmptyTimeStep(); - for(int ent = 0; ent < getNumEntities(firstNonEmptyStep); ent++){ - for(int ele = 0; ele < getNumElements(firstNonEmptyStep, ent); ele++){ + for(int ent = 0; ent < getNumEntities(firstNonEmptyStep); ent++) { + for(int ele = 0; ele < getNumElements(firstNonEmptyStep, ent); ele++) { if(skipElement(firstNonEmptyStep, ent, ele)) continue; int type = getType(firstNonEmptyStep, ent, ele); int numComp = getNumComponents(firstNonEmptyStep, ent, ele); const char *s = 0; - switch(type){ - case TYPE_PNT: s = (numComp == 9) ? "TP" : (numComp == 3) ? "VP" : "SP"; break; - case TYPE_LIN: s = (numComp == 9) ? "TL" : (numComp == 3) ? "VL" : "SL"; break; - case TYPE_TRI: s = (numComp == 9) ? "TT" : (numComp == 3) ? "VT" : "ST"; break; - case TYPE_QUA: s = (numComp == 9) ? "TQ" : (numComp == 3) ? "VQ" : "SQ"; break; - case TYPE_TET: s = (numComp == 9) ? "TS" : (numComp == 3) ? "VS" : "SS"; break; - case TYPE_HEX: s = (numComp == 9) ? "TH" : (numComp == 3) ? "VH" : "SH"; break; - case TYPE_PRI: s = (numComp == 9) ? "TI" : (numComp == 3) ? "VI" : "SI"; break; - case TYPE_PYR: s = (numComp == 9) ? "TY" : (numComp == 3) ? "VY" : "SY"; break; + switch(type) { + case TYPE_PNT: + s = (numComp == 9) ? "TP" : (numComp == 3) ? "VP" : "SP"; + break; + case TYPE_LIN: + s = (numComp == 9) ? "TL" : (numComp == 3) ? "VL" : "SL"; + break; + case TYPE_TRI: + s = (numComp == 9) ? "TT" : (numComp == 3) ? "VT" : "ST"; + break; + case TYPE_QUA: + s = (numComp == 9) ? "TQ" : (numComp == 3) ? "VQ" : "SQ"; + break; + case TYPE_TET: + s = (numComp == 9) ? "TS" : (numComp == 3) ? "VS" : "SS"; + break; + case TYPE_HEX: + s = (numComp == 9) ? "TH" : (numComp == 3) ? "VH" : "SH"; + break; + case TYPE_PRI: + s = (numComp == 9) ? "TI" : (numComp == 3) ? "VI" : "SI"; + break; + case TYPE_PYR: + s = (numComp == 9) ? "TY" : (numComp == 3) ? "VY" : "SY"; + break; } - if(s){ + if(s) { fprintf(fp, "%s(", s); int numNod = getNumNodes(firstNonEmptyStep, ent, ele); - for(int nod = 0; nod < numNod; nod++){ + for(int nod = 0; nod < numNod; nod++) { double x, y, z; getNode(firstNonEmptyStep, ent, ele, nod, x, y, z); fprintf(fp, "%.16g,%.16g,%.16g", x, y, z); if(nod != numNod - 1) fprintf(fp, ","); } bool first = true; - for(int step = 0; step < getNumTimeSteps(); step++){ - if(hasTimeStep(step)){ - for(int nod = 0; nod < numNod; nod++){ - for(int comp = 0; comp < numComp; comp++){ + for(int step = 0; step < getNumTimeSteps(); step++) { + if(hasTimeStep(step)) { + for(int nod = 0; nod < numNod; nod++) { + for(int comp = 0; comp < numComp; comp++) { double val; getValue(step, ent, ele, nod, comp, val); - if(first){ fprintf(fp, "){%.16g", val); first = false; } - else fprintf(fp, ",%.16g", val); + if(first) { + fprintf(fp, "){%.16g", val); + first = false; + } + else + fprintf(fp, ",%.16g", val); } } } @@ -178,10 +199,10 @@ bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed, return true; } -bool PViewData::writeMSH(const std::string &fileName, double version, bool binary, - bool saveMesh, bool multipleView, int partitionNum, - bool saveInterpolationMatrices, bool forceNodeData, - bool forceElementData) +bool PViewData::writeMSH(const std::string &fileName, double version, + bool binary, bool saveMesh, bool multipleView, + int partitionNum, bool saveInterpolationMatrices, + bool forceNodeData, bool forceElementData) { Msg::Error("MSH export not implemented for this view type"); return false; @@ -196,13 +217,13 @@ bool PViewData::writeMED(const std::string &fileName) bool PViewData::toVector(std::vector<std::vector<double> > &vec) { vec.resize(getNumTimeSteps()); - for(int step = 0; step < getNumTimeSteps(); step++){ + for(int step = 0; step < getNumTimeSteps(); step++) { vec[step].clear(); - for(int ent = 0; ent < getNumEntities(step); ent++){ - for(int ele = 0; ele < getNumElements(step, ent); ele++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { + for(int ele = 0; ele < getNumElements(step, ent); ele++) { if(skipElement(step, ent, ele)) continue; - for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ - for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++){ + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) { + for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++) { double val; getValue(step, ent, ele, nod, comp, val); vec[step].push_back(val); @@ -216,32 +237,33 @@ bool PViewData::toVector(std::vector<std::vector<double> > &vec) bool PViewData::fromVector(const std::vector<std::vector<double> > &vec) { - if(empty() || !getNumTimeSteps()){ + if(empty() || !getNumTimeSteps()) { Msg::Warning("Cannot import vector in an empty view; skipping"); return false; } - if((int)vec.size() != getNumTimeSteps()){ - Msg::Error("Incompatible number of steps in vector for view import (%d!=%d)", - (int)vec.size(), getNumTimeSteps()); + if((int)vec.size() != getNumTimeSteps()) { + Msg::Error( + "Incompatible number of steps in vector for view import (%d!=%d)", + (int)vec.size(), getNumTimeSteps()); return false; } - for(int step = 0; step < getNumTimeSteps(); step++){ + for(int step = 0; step < getNumTimeSteps(); step++) { int i = 0; - for(int ent = 0; ent < getNumEntities(step); ent++){ - for(int ele = 0; ele < getNumElements(step, ent); ele++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { + for(int ele = 0; ele < getNumElements(step, ent); ele++) { if(skipElement(step, ent, ele)) continue; - for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) { double x, y, z; getNode(step, ent, ele, nod, x, y, z); - for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++){ - if(i < (int)vec[step].size()){ + for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++) { + if(i < (int)vec[step].size()) { setValue(step, ent, ele, nod, comp, vec[step][i++]); } - else{ - Msg::Error("Bad index (%d) in vector (%d) for view import", - i, (int)vec[step].size()); + else { + Msg::Error("Bad index (%d) in vector (%d) for view import", i, + (int)vec[step].size()); return false; } } diff --git a/Post/PViewDataList.cpp b/Post/PViewDataList.cpp index 32ab7b862aaf5b94d220b806aa4f39229ebd2ddd..86f0bec84ab6d881ca7dce9a9a027ac783ea39e5 100644 --- a/Post/PViewDataList.cpp +++ b/Post/PViewDataList.cpp @@ -14,28 +14,27 @@ #include "polynomialBasis.h" PViewDataList::PViewDataList(bool isAdapted) - : PViewData(), NbTimeStep(0), Min(VAL_INF), Max(-VAL_INF), - NbSP(0), NbVP(0), NbTP(0), NbSL(0), NbVL(0), NbTL(0), - NbST(0), NbVT(0), NbTT(0), NbSQ(0), NbVQ(0), NbTQ(0), - NbSG(0), NbVG(0), NbTG(0), - NbSS(0), NbVS(0), NbTS(0), NbSH(0), NbVH(0), NbTH(0), - NbSI(0), NbVI(0), NbTI(0), NbSY(0), NbVY(0), NbTY(0), - NbSR(0), NbVR(0), NbTR(0), NbSD(0), NbVD(0), NbTD(0), - NbT2(0), NbT3(0), - _lastElement(-1), _lastDimension(-1), _lastNumNodes(-1), + : PViewData(), NbTimeStep(0), Min(VAL_INF), Max(-VAL_INF), NbSP(0), NbVP(0), + NbTP(0), NbSL(0), NbVL(0), NbTL(0), NbST(0), NbVT(0), NbTT(0), NbSQ(0), + NbVQ(0), NbTQ(0), NbSG(0), NbVG(0), NbTG(0), NbSS(0), NbVS(0), NbTS(0), + NbSH(0), NbVH(0), NbTH(0), NbSI(0), NbVI(0), NbTI(0), NbSY(0), NbVY(0), + NbTY(0), NbSR(0), NbVR(0), NbTR(0), NbSD(0), NbVD(0), NbTD(0), NbT2(0), + NbT3(0), _lastElement(-1), _lastDimension(-1), _lastNumNodes(-1), _lastNumComponents(-1), _lastNumValues(-1), _lastNumEdges(-1), _lastType(-1), _lastXYZ(0), _lastVal(0), _isAdapted(isAdapted) { for(int i = 0; i < 33; i++) _index[i] = 0; - polyTotNumNodes[0] = 0.; polyTotNumNodes[1] = 0.; - polyAgNumNodes[0].push_back(0.); polyAgNumNodes[1].push_back(0.); + polyTotNumNodes[0] = 0.; + polyTotNumNodes[1] = 0.; + polyAgNumNodes[0].push_back(0.); + polyAgNumNodes[1].push_back(0.); } void PViewDataList::setXY(std::vector<double> &x, std::vector<double> &y) { NbSP = 0; SP.clear(); - for(unsigned int i = 0; i < std::min(x.size(), y.size()); i++){ + for(unsigned int i = 0; i < std::min(x.size(), y.size()); i++) { SP.push_back(x[i]); SP.push_back(0.); SP.push_back(0.); @@ -51,7 +50,7 @@ void PViewDataList::setXYZV(std::vector<double> &x, std::vector<double> &y, NbSP = 0; SP.clear(); int n = std::min(std::min(std::min(x.size(), y.size()), z.size()), v.size()); - for(int i = 0; i < n; i++){ + for(int i = 0; i < n; i++) { SP.push_back(x[i]); SP.push_back(y[i]); SP.push_back(z[i]); @@ -61,7 +60,8 @@ void PViewDataList::setXYZV(std::vector<double> &x, std::vector<double> &y, finalize(); } -bool PViewDataList::finalize(bool computeMinMax, const std::string &interpolationScheme) +bool PViewDataList::finalize(bool computeMinMax, + const std::string &interpolationScheme) { BBox.reset(); Min = VAL_INF; @@ -72,48 +72,58 @@ bool PViewDataList::finalize(bool computeMinMax, const std::string &interpolatio // gracefully when some have fewer time steps than others). If there // are any elements in the view, this value will be replaced by the // minimum number of time steps common to all elements. - _stat(T2D, T2C, 4); _stat(T3D, T3C, 5); + _stat(T2D, T2C, 4); + _stat(T3D, T3C, 5); // compute min/max and other statistics for all element lists - _stat(SP, 1, NbSP, 1, TYPE_PNT); _stat(VP, 3, NbVP, 1, TYPE_PNT); + _stat(SP, 1, NbSP, 1, TYPE_PNT); + _stat(VP, 3, NbVP, 1, TYPE_PNT); _stat(TP, 9, NbTP, 1, TYPE_PNT); - _stat(SL, 1, NbSL, 2, TYPE_LIN); _stat(VL, 3, NbVL, 2, TYPE_LIN); + _stat(SL, 1, NbSL, 2, TYPE_LIN); + _stat(VL, 3, NbVL, 2, TYPE_LIN); _stat(TL, 9, NbTL, 2, TYPE_LIN); - _stat(ST, 1, NbST, 3, TYPE_TRI); _stat(VT, 3, NbVT, 3, TYPE_TRI); + _stat(ST, 1, NbST, 3, TYPE_TRI); + _stat(VT, 3, NbVT, 3, TYPE_TRI); _stat(TT, 9, NbTT, 3, TYPE_TRI); - _stat(SQ, 1, NbSQ, 4, TYPE_QUA); _stat(VQ, 3, NbVQ, 4, TYPE_QUA); + _stat(SQ, 1, NbSQ, 4, TYPE_QUA); + _stat(VQ, 3, NbVQ, 4, TYPE_QUA); _stat(TQ, 9, NbTQ, 4, TYPE_QUA); - _stat(SS, 1, NbSS, 4, TYPE_TET); _stat(VS, 3, NbVS, 4, TYPE_TET); + _stat(SS, 1, NbSS, 4, TYPE_TET); + _stat(VS, 3, NbVS, 4, TYPE_TET); _stat(TS, 9, NbTS, 4, TYPE_TET); - _stat(SH, 1, NbSH, 8, TYPE_HEX); _stat(VH, 3, NbVH, 8, TYPE_HEX); + _stat(SH, 1, NbSH, 8, TYPE_HEX); + _stat(VH, 3, NbVH, 8, TYPE_HEX); _stat(TH, 9, NbTH, 8, TYPE_HEX); - _stat(SI, 1, NbSI, 6, TYPE_PRI); _stat(VI, 3, NbVI, 6, TYPE_PRI); + _stat(SI, 1, NbSI, 6, TYPE_PRI); + _stat(VI, 3, NbVI, 6, TYPE_PRI); _stat(TI, 9, NbTI, 6, TYPE_PRI); - _stat(SY, 1, NbSY, 5, TYPE_PYR); _stat(VY, 3, NbVY, 5, TYPE_PYR); + _stat(SY, 1, NbSY, 5, TYPE_PYR); + _stat(VY, 3, NbVY, 5, TYPE_PYR); _stat(TY, 9, NbTY, 5, TYPE_PYR); - _stat(SY, 1, NbSR, 4, TYPE_TRIH); _stat(VY, 3, NbVR, 4, TYPE_TRIH); + _stat(SY, 1, NbSR, 4, TYPE_TRIH); + _stat(VY, 3, NbVR, 4, TYPE_TRIH); _stat(TY, 9, NbTR, 4, TYPE_TRIH); - _stat(SG, 1, NbSG, 3, TYPE_POLYG); _stat(VG, 3, NbVG, 3, TYPE_POLYG); + _stat(SG, 1, NbSG, 3, TYPE_POLYG); + _stat(VG, 3, NbVG, 3, TYPE_POLYG); _stat(TG, 9, NbTG, 3, TYPE_POLYG); - _stat(SD, 1, NbSD, 4, TYPE_POLYH); _stat(VD, 3, NbVD, 4, TYPE_POLYH); + _stat(SD, 1, NbSD, 4, TYPE_POLYH); + _stat(VD, 3, NbVD, 4, TYPE_POLYH); _stat(TD, 9, NbTD, 4, TYPE_POLYH); // add dummy time values if none (or too few) time values are // provided (e.g. using the old parsed format) if((int)Time.size() < NbTimeStep) { - for(int i = Time.size(); i < NbTimeStep; i++) - Time.push_back(i); + for(int i = Time.size(); i < NbTimeStep; i++) Time.push_back(i); } // compute starting element indices - int nb[33] = {NbSP, NbVP, NbTP, NbSL, NbVL, NbTL, NbST, NbVT, NbTT, - NbSQ, NbVQ, NbTQ, NbSS, NbVS, NbTS, NbSH, NbVH, NbTH, - NbSI, NbVI, NbTI, NbSY, NbVY, NbTY, NbSR, NbVR, NbTR, - NbSG, NbVG, NbTG, NbSD, NbVD, NbTD}; - for(int i = 0; i < 33; i++){ + int nb[33] = {NbSP, NbVP, NbTP, NbSL, NbVL, NbTL, NbST, NbVT, NbTT, + NbSQ, NbVQ, NbTQ, NbSS, NbVS, NbTS, NbSH, NbVH, NbTH, + NbSI, NbVI, NbTI, NbSY, NbVY, NbTY, NbSR, NbVR, NbTR, + NbSG, NbVG, NbTG, NbSD, NbVD, NbTD}; + for(int i = 0; i < 33; i++) { _index[i] = 0; - for(int j = 0; j <= i; j++) - _index[i] += nb[j]; + for(int j = 0; j <= i; j++) _index[i] += nb[j]; } if(CTX::instance()->post.smooth) smooth(); @@ -123,17 +133,20 @@ bool PViewDataList::finalize(bool computeMinMax, const std::string &interpolatio int PViewDataList::getNumScalars(int step) { - return NbSP + NbSL + NbST + NbSQ + NbSS + NbSH + NbSI + NbSY + NbSR + NbSG + NbSD; + return NbSP + NbSL + NbST + NbSQ + NbSS + NbSH + NbSI + NbSY + NbSR + NbSG + + NbSD; } int PViewDataList::getNumVectors(int step) { - return NbVP + NbVL + NbVT + NbVQ + NbVS + NbVH + NbVI + NbVY + NbVR + NbVG + NbVD; + return NbVP + NbVL + NbVT + NbVQ + NbVS + NbVH + NbVI + NbVY + NbVR + NbVG + + NbVD; } int PViewDataList::getNumTensors(int step) { - return NbTP + NbTL + NbTT + NbTQ + NbTS + NbTH + NbTI + NbTY + NbTR + NbTG + NbTD; + return NbTP + NbTL + NbTT + NbTQ + NbTS + NbTH + NbTI + NbTY + NbTR + NbTG + + NbTD; } int PViewDataList::getNumElements(int step, int ent) @@ -152,14 +165,14 @@ double PViewDataList::getMin(int step, bool onlyVisible, int forceNumComponents, { if(step >= (int)TimeStepMin.size()) return Min; - if(forceNumComponents){ + if(forceNumComponents) { double vmin = VAL_INF; - for(int ent = 0; ent < getNumEntities(step); ent++){ - for(int ele = 0; ele < getNumElements(step, ent); ele++){ - for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { + for(int ele = 0; ele < getNumElements(step, ent); ele++) { + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) { double val; - getScalarValue(step, ent, ele, nod, val, - forceNumComponents, componentMap); + getScalarValue(step, ent, ele, nod, val, forceNumComponents, + componentMap); vmin = std::min(vmin, val); } } @@ -176,14 +189,14 @@ double PViewDataList::getMax(int step, bool onlyVisible, int forceNumComponents, { if(step >= (int)TimeStepMax.size()) return Max; - if(forceNumComponents){ + if(forceNumComponents) { double vmax = -VAL_INF; - for(int ent = 0; ent < getNumEntities(step); ent++){ - for(int ele = 0; ele < getNumElements(step, ent); ele++){ - for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ + for(int ent = 0; ent < getNumEntities(step); ent++) { + for(int ele = 0; ele < getNumElements(step, ent); ele++) { + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) { double val; - getScalarValue(step, ent, ele, nod, val, - forceNumComponents, componentMap); + getScalarValue(step, ent, ele, nod, val, forceNumComponents, + componentMap); vmax = std::max(vmax, val); } } @@ -198,7 +211,7 @@ double PViewDataList::getMax(int step, bool onlyVisible, int forceNumComponents, void PViewDataList::_stat(std::vector<double> &D, std::vector<char> &C, int nb) { // compute statistics for text lists - for(unsigned int i = 0; i < D.size(); i += nb){ + for(unsigned int i = 0; i < D.size(); i += nb) { double beg = D[i + nb - 1]; double end; if(i + 2 * nb > D.size()) @@ -209,10 +222,9 @@ void PViewDataList::_stat(std::vector<double> &D, std::vector<char> &C, int nb) int nbtime = 0; for(int j = 0; j < (int)(end - beg); j++) if(c[j] == '\0') nbtime++; - if(nbtime > NbTimeStep) - NbTimeStep = nbtime; + if(nbtime > NbTimeStep) NbTimeStep = nbtime; } - if(nb == 5){ + if(nb == 5) { for(unsigned int i = 0; i < D.size(); i += nb) BBox += SPoint3(D[i], D[i + 1], D[i + 2]); } @@ -226,19 +238,17 @@ void PViewDataList::_stat(std::vector<double> &list, int nbcomp, int nbelm, int nbval = nbcomp * nbnod; - if(haveInterpolationMatrices()){ - std::vector<fullMatrix<double>*> im; + if(haveInterpolationMatrices()) { + std::vector<fullMatrix<double> *> im; int nim = getInterpolationMatrices(type, im); - if(nim == 4) - nbnod = im[2]->size1(); - if(nim) - nbval = nbcomp * im[0]->size1(); + if(nim == 4) nbnod = im[2]->size1(); + if(nim) nbval = nbcomp * im[0]->size1(); } int nb = list.size() / nbelm; - for(int ele = 0; ele < nbelm; ele ++){ + for(int ele = 0; ele < nbelm; ele++) { int i = ele * nb; - if(type == TYPE_POLYG || type == TYPE_POLYH){ + if(type == TYPE_POLYG || type == TYPE_POLYH) { int t = (type == TYPE_POLYG) ? 0 : 1; nbnod = polyNumNodes[t][ele]; nb = list.size() / polyTotNumNodes[t] * nbnod; @@ -252,20 +262,19 @@ void PViewDataList::_stat(std::vector<double> &list, int nbcomp, int nbelm, double *V = &list[i + 3 * nbnod]; // update bounding box - for(int j = 0; j < nbnod; j++) - BBox += SPoint3(X[j], Y[j], Z[j]); + for(int j = 0; j < nbnod; j++) BBox += SPoint3(X[j], Y[j], Z[j]); // update num time steps - if(Min == VAL_INF || Max == -VAL_INF){ + if(Min == VAL_INF || Max == -VAL_INF) { NbTimeStep = N / nbval; TimeStepMin.clear(); TimeStepMax.clear(); - for(int j = 0; j < NbTimeStep; j++){ + for(int j = 0; j < NbTimeStep; j++) { TimeStepMin.push_back(VAL_INF); TimeStepMax.push_back(-VAL_INF); } } - else if(N / nbval < NbTimeStep){ + else if(N / nbval < NbTimeStep) { // if some elts have less steps, reduce the total number! NbTimeStep = N / nbval; } @@ -276,7 +285,7 @@ void PViewDataList::_stat(std::vector<double> &list, int nbcomp, int nbelm, Min = std::min(l0, Min); Max = std::max(l0, Max); int ts = j / nbval; - if(ts < NbTimeStep){ // security + if(ts < NbTimeStep) { // security TimeStepMin[ts] = std::min(l0, TimeStepMin[ts]); TimeStepMax[ts] = std::max(l0, TimeStepMax[ts]); } @@ -284,13 +293,12 @@ void PViewDataList::_stat(std::vector<double> &list, int nbcomp, int nbelm, } } -void PViewDataList::_setLast(int ele, int dim, int nbnod, int nbcomp, int nbedg, int type, - std::vector<double> &list, int nblist) +void PViewDataList::_setLast(int ele, int dim, int nbnod, int nbcomp, int nbedg, + int type, std::vector<double> &list, int nblist) { - if(haveInterpolationMatrices()){ - std::vector<fullMatrix<double>*> im; - if(getInterpolationMatrices(type, im) == 4) - nbnod = im[2]->size1(); + if(haveInterpolationMatrices()) { + std::vector<fullMatrix<double> *> im; + if(getInterpolationMatrices(type, im) == 4) nbnod = im[2]->size1(); } _lastDimension = dim; @@ -299,8 +307,9 @@ void PViewDataList::_setLast(int ele, int dim, int nbnod, int nbcomp, int nbedg, _lastNumEdges = nbedg; _lastType = type; int nb = list.size() / nblist; // number of coords and values for the element - int nbAg = ele * nb; // number of coords and values before the ones of the element - if(type == TYPE_POLYG || type == TYPE_POLYH){ + int nbAg = + ele * nb; // number of coords and values before the ones of the element + if(type == TYPE_POLYG || type == TYPE_POLYH) { int t = (type == TYPE_POLYG) ? 0 : 1; nb = list.size() / polyTotNumNodes[t] * nbnod; nbAg = polyAgNumNodes[t][ele] * nb / nbnod; @@ -313,62 +322,95 @@ void PViewDataList::_setLast(int ele, int dim, int nbnod, int nbcomp, int nbedg, void PViewDataList::_setLast(int ele) { _lastElement = ele; - if(ele < _index[2]){ // points - if(ele < _index[0]) _setLast(ele, 0, 1, 1, 0, TYPE_PNT, SP, NbSP); - else if(ele < _index[1]) _setLast(ele - _index[0], 0, 1, 3, 0, TYPE_PNT, VP, NbVP); - else _setLast(ele - _index[1], 0, 1, 9, 0, TYPE_PNT, TP, NbTP); - } - else if(ele < _index[5]){ // lines - if(ele < _index[3]) _setLast(ele - _index[2], 1, 2, 1, 1, TYPE_LIN, SL, NbSL); - else if(ele < _index[4]) _setLast(ele - _index[3], 1, 2, 3, 1, TYPE_LIN, VL, NbVL); - else _setLast(ele - _index[4], 1, 2, 9, 1, TYPE_LIN, TL, NbTL); - } - else if(ele < _index[8]){ // triangles - if(ele < _index[6]) _setLast(ele - _index[5], 2, 3, 1, 3, TYPE_TRI, ST, NbST); - else if(ele < _index[7]) _setLast(ele - _index[6], 2, 3, 3, 3, TYPE_TRI, VT, NbVT); - else _setLast(ele - _index[7], 2, 3, 9, 3, TYPE_TRI, TT, NbTT); - } - else if(ele < _index[11]){ // quadrangles - if(ele < _index[9]) _setLast(ele - _index[8], 2, 4, 1, 4, TYPE_QUA, SQ, NbSQ); - else if(ele < _index[10]) _setLast(ele - _index[9], 2, 4, 3, 4, TYPE_QUA, VQ, NbVQ); - else _setLast(ele - _index[10], 2, 4, 9, 4, TYPE_QUA, TQ, NbTQ); - } - else if(ele < _index[14]){ // tetrahedra - if(ele < _index[12]) _setLast(ele - _index[11], 3, 4, 1, 6, TYPE_TET, SS, NbSS); - else if(ele < _index[13]) _setLast(ele - _index[12], 3, 4, 3, 6, TYPE_TET, VS, NbVS); - else _setLast(ele - _index[13], 3, 4, 9, 6, TYPE_TET, TS, NbTS); - } - else if(ele < _index[17]){ // hexahedra - if(ele < _index[15]) _setLast(ele - _index[14], 3, 8, 1, 12, TYPE_HEX, SH, NbSH); - else if(ele < _index[16]) _setLast(ele - _index[15], 3, 8, 3, 12, TYPE_HEX, VH, NbVH); - else _setLast(ele - _index[16], 3, 8, 9, 12, TYPE_HEX, TH, NbTH); - } - else if(ele < _index[20]){ // prisms - if(ele < _index[18]) _setLast(ele - _index[17], 3, 6, 1, 9, TYPE_PRI, SI, NbSI); - else if(ele < _index[19]) _setLast(ele - _index[18], 3, 6, 3, 9, TYPE_PRI, VI, NbVI); - else _setLast(ele - _index[19], 3, 6, 9, 9, TYPE_PRI, TI, NbTI); - } - else if(ele < _index[23]){ // pyramids - if(ele < _index[21]) _setLast(ele - _index[20], 3, 5, 1, 8, TYPE_PYR, SY, NbSY); - else if(ele < _index[22]) _setLast(ele - _index[21], 3, 5, 3, 8, TYPE_PYR, VY, NbVY); - else _setLast(ele - _index[22], 3, 5, 9, 8, TYPE_PYR, TY, NbTY); - } - else if(ele < _index[26]){ // trihedra - if(ele < _index[24]) _setLast(ele - _index[23], 3, 4, 1, 5, TYPE_TRIH, SR, NbSR); - else if(ele < _index[25]) _setLast(ele - _index[24], 3, 4, 3, 5, TYPE_TRIH, VR, NbVR); - else _setLast(ele - _index[25], 3, 4, 9, 5, TYPE_TRIH, TR, NbTR); - } - else if(ele < _index[29]){ // polygons + if(ele < _index[2]) { // points + if(ele < _index[0]) + _setLast(ele, 0, 1, 1, 0, TYPE_PNT, SP, NbSP); + else if(ele < _index[1]) + _setLast(ele - _index[0], 0, 1, 3, 0, TYPE_PNT, VP, NbVP); + else + _setLast(ele - _index[1], 0, 1, 9, 0, TYPE_PNT, TP, NbTP); + } + else if(ele < _index[5]) { // lines + if(ele < _index[3]) + _setLast(ele - _index[2], 1, 2, 1, 1, TYPE_LIN, SL, NbSL); + else if(ele < _index[4]) + _setLast(ele - _index[3], 1, 2, 3, 1, TYPE_LIN, VL, NbVL); + else + _setLast(ele - _index[4], 1, 2, 9, 1, TYPE_LIN, TL, NbTL); + } + else if(ele < _index[8]) { // triangles + if(ele < _index[6]) + _setLast(ele - _index[5], 2, 3, 1, 3, TYPE_TRI, ST, NbST); + else if(ele < _index[7]) + _setLast(ele - _index[6], 2, 3, 3, 3, TYPE_TRI, VT, NbVT); + else + _setLast(ele - _index[7], 2, 3, 9, 3, TYPE_TRI, TT, NbTT); + } + else if(ele < _index[11]) { // quadrangles + if(ele < _index[9]) + _setLast(ele - _index[8], 2, 4, 1, 4, TYPE_QUA, SQ, NbSQ); + else if(ele < _index[10]) + _setLast(ele - _index[9], 2, 4, 3, 4, TYPE_QUA, VQ, NbVQ); + else + _setLast(ele - _index[10], 2, 4, 9, 4, TYPE_QUA, TQ, NbTQ); + } + else if(ele < _index[14]) { // tetrahedra + if(ele < _index[12]) + _setLast(ele - _index[11], 3, 4, 1, 6, TYPE_TET, SS, NbSS); + else if(ele < _index[13]) + _setLast(ele - _index[12], 3, 4, 3, 6, TYPE_TET, VS, NbVS); + else + _setLast(ele - _index[13], 3, 4, 9, 6, TYPE_TET, TS, NbTS); + } + else if(ele < _index[17]) { // hexahedra + if(ele < _index[15]) + _setLast(ele - _index[14], 3, 8, 1, 12, TYPE_HEX, SH, NbSH); + else if(ele < _index[16]) + _setLast(ele - _index[15], 3, 8, 3, 12, TYPE_HEX, VH, NbVH); + else + _setLast(ele - _index[16], 3, 8, 9, 12, TYPE_HEX, TH, NbTH); + } + else if(ele < _index[20]) { // prisms + if(ele < _index[18]) + _setLast(ele - _index[17], 3, 6, 1, 9, TYPE_PRI, SI, NbSI); + else if(ele < _index[19]) + _setLast(ele - _index[18], 3, 6, 3, 9, TYPE_PRI, VI, NbVI); + else + _setLast(ele - _index[19], 3, 6, 9, 9, TYPE_PRI, TI, NbTI); + } + else if(ele < _index[23]) { // pyramids + if(ele < _index[21]) + _setLast(ele - _index[20], 3, 5, 1, 8, TYPE_PYR, SY, NbSY); + else if(ele < _index[22]) + _setLast(ele - _index[21], 3, 5, 3, 8, TYPE_PYR, VY, NbVY); + else + _setLast(ele - _index[22], 3, 5, 9, 8, TYPE_PYR, TY, NbTY); + } + else if(ele < _index[26]) { // trihedra + if(ele < _index[24]) + _setLast(ele - _index[23], 3, 4, 1, 5, TYPE_TRIH, SR, NbSR); + else if(ele < _index[25]) + _setLast(ele - _index[24], 3, 4, 3, 5, TYPE_TRIH, VR, NbVR); + else + _setLast(ele - _index[25], 3, 4, 9, 5, TYPE_TRIH, TR, NbTR); + } + else if(ele < _index[29]) { // polygons int nN = polyNumNodes[0][ele - _index[26]]; - if(ele < _index[27]) _setLast(ele - _index[26], 2, nN, 1, nN, TYPE_POLYG, SG, NbSG); - else if(ele < _index[28]) _setLast(ele - _index[27], 2, nN, 3, nN, TYPE_POLYG, VG, NbVG); - else _setLast(ele - _index[28], 2, nN, 9, nN, TYPE_POLYG, TG, NbTG); + if(ele < _index[27]) + _setLast(ele - _index[26], 2, nN, 1, nN, TYPE_POLYG, SG, NbSG); + else if(ele < _index[28]) + _setLast(ele - _index[27], 2, nN, 3, nN, TYPE_POLYG, VG, NbVG); + else + _setLast(ele - _index[28], 2, nN, 9, nN, TYPE_POLYG, TG, NbTG); } - else if(ele < _index[32]){ // polyhedra + else if(ele < _index[32]) { // polyhedra int nN = polyNumNodes[1][ele - _index[29]]; - if(ele < _index[30]) _setLast(ele - _index[29], 3, nN, 1, nN*1.5, TYPE_POLYH, SD, NbSD); - else if(ele < _index[32]) _setLast(ele - _index[30], 3, nN, 3, nN*1.5, TYPE_POLYH, VD, NbVD); - else _setLast(ele - _index[31], 3, nN, 9, nN*1.5, TYPE_POLYH, TD, NbTD); + if(ele < _index[30]) + _setLast(ele - _index[29], 3, nN, 1, nN * 1.5, TYPE_POLYH, SD, NbSD); + else if(ele < _index[32]) + _setLast(ele - _index[30], 3, nN, 3, nN * 1.5, TYPE_POLYH, VD, NbVD); + else + _setLast(ele - _index[31], 3, nN, 9, nN * 1.5, TYPE_POLYH, TD, NbTD); } } @@ -384,8 +426,8 @@ int PViewDataList::getNumNodes(int step, int ent, int ele) return _lastNumNodes; } -int PViewDataList::getNode(int step, int ent, int ele, int nod, - double &x, double &y, double &z) +int PViewDataList::getNode(int step, int ent, int ele, int nod, double &x, + double &y, double &z) { if(ele != _lastElement) _setLast(ele); x = _lastXYZ[nod]; @@ -394,8 +436,8 @@ int PViewDataList::getNode(int step, int ent, int ele, int nod, return 0; } -void PViewDataList::setNode(int step, int ent, int ele, int nod, - double x, double y, double z) +void PViewDataList::setNode(int step, int ent, int ele, int nod, double x, + double y, double z) { if(step) return; if(ele != _lastElement) _setLast(ele); @@ -423,22 +465,22 @@ void PViewDataList::getValue(int step, int ent, int ele, int idx, double &val) val = _lastVal[step * _lastNumValues + idx]; } -void PViewDataList::getValue(int step, int ent, int ele, int nod, int comp, double &val) +void PViewDataList::getValue(int step, int ent, int ele, int nod, int comp, + double &val) { if(ele != _lastElement) _setLast(ele); if(step >= NbTimeStep) step = 0; - val = _lastVal[step * _lastNumNodes * _lastNumComponents + - nod * _lastNumComponents + - comp]; + val = _lastVal[step * _lastNumNodes * _lastNumComponents + + nod * _lastNumComponents + comp]; } -void PViewDataList::setValue(int step, int ent, int ele, int nod, int comp, double val) +void PViewDataList::setValue(int step, int ent, int ele, int nod, int comp, + double val) { if(ele != _lastElement) _setLast(ele); if(step >= NbTimeStep) step = 0; - _lastVal[step * _lastNumNodes * _lastNumComponents + - nod * _lastNumComponents + - comp] = val; + _lastVal[step * _lastNumNodes * _lastNumComponents + + nod * _lastNumComponents + comp] = val; } int PViewDataList::getNumEdges(int step, int ent, int ele) @@ -497,8 +539,7 @@ void PViewDataList::_getString(int dim, int i, int step, std::string &str, char *c = &tc[index]; int k = 0, l = 0; while(k < nbchar && l != step) { - if(c[k++] == '\0') - l++; + if(c[k++] == '\0') l++; } if(k < nbchar && l == step) str = std::string(&c[k]); @@ -506,15 +547,15 @@ void PViewDataList::_getString(int dim, int i, int step, std::string &str, str = std::string(c); } -void PViewDataList::getString2D(int i, int step, std::string &str, - double &x, double &y, double &style) +void PViewDataList::getString2D(int i, int step, std::string &str, double &x, + double &y, double &style) { double z; _getString(2, i, step, str, x, y, z, style); } -void PViewDataList::getString3D(int i, int step, std::string &str, - double &x, double &y, double &z, double &style) +void PViewDataList::getString3D(int i, int step, std::string &str, double &x, + double &y, double &z, double &style) { _getString(3, i, step, str, x, y, z, style); } @@ -526,15 +567,13 @@ void PViewDataList::reverseElement(int step, int ent, int ele) // copy data std::vector<double> XYZ(3 * _lastNumNodes); - for(unsigned int i = 0; i < XYZ.size(); i++) - XYZ[i] = _lastXYZ[i]; + for(unsigned int i = 0; i < XYZ.size(); i++) XYZ[i] = _lastXYZ[i]; std::vector<double> V(_lastNumNodes * _lastNumComponents * getNumTimeSteps()); - for(unsigned int i = 0; i < V.size(); i++) - V[i] = _lastVal[i]; + for(unsigned int i = 0; i < V.size(); i++) V[i] = _lastVal[i]; // reverse node order - for(int i = 0; i < _lastNumNodes; i++){ + for(int i = 0; i < _lastNumNodes; i++) { _lastXYZ[i] = XYZ[_lastNumNodes - i - 1]; _lastXYZ[_lastNumNodes + i] = XYZ[2 * _lastNumNodes - i - 1]; _lastXYZ[2 * _lastNumNodes + i] = XYZ[3 * _lastNumNodes - i - 1]; @@ -549,8 +588,9 @@ void PViewDataList::reverseElement(int step, int ent, int ele) _lastNumComponents * (_lastNumNodes - i - 1) + k]; } -static void generateConnectivities(std::vector<double> &list, int nbList, int nbTimeStep, - int nbVert, int nbComp, smooth_data &data) +static void generateConnectivities(std::vector<double> &list, int nbList, + int nbTimeStep, int nbVert, int nbComp, + smooth_data &data) { if(!nbList) return; double *vals = new double[nbTimeStep * nbComp]; @@ -567,7 +607,7 @@ static void generateConnectivities(std::vector<double> &list, int nbList, int nb data.add(x[j], y[j], z[j], nbTimeStep * nbComp, vals); } } - delete [] vals; + delete[] vals; } static void smoothList(std::vector<double> &list, int nbList, int nbTimeStep, @@ -582,14 +622,14 @@ static void smoothList(std::vector<double> &list, int nbList, int nbTimeStep, double *z = &list[i + 2 * nbVert]; double *v = &list[i + 3 * nbVert]; for(int j = 0; j < nbVert; j++) { - if(data.get(x[j], y[j], z[j], nbTimeStep * nbComp, vals)){ + if(data.get(x[j], y[j], z[j], nbTimeStep * nbComp, vals)) { for(int ts = 0; ts < nbTimeStep; ts++) for(int k = 0; k < nbComp; k++) v[nbVert * nbComp * ts + nbComp * j + k] = vals[nbComp * ts + k]; } } } - delete [] vals; + delete[] vals; } void PViewDataList::smooth() @@ -600,15 +640,13 @@ void PViewDataList::smooth() std::vector<double> *list = 0; int *nbe = 0, nbc, nbn; - for(int i = 0; i < 27; i++){ + for(int i = 0; i < 27; i++) { _getRawData(i, &list, &nbe, &nbc, &nbn); - if(nbn > 1) - generateConnectivities(*list, *nbe, NbTimeStep, nbn, nbc, data); + if(nbn > 1) generateConnectivities(*list, *nbe, NbTimeStep, nbn, nbc, data); } - for(int i = 0; i < 27; i++){ + for(int i = 0; i < 27; i++) { _getRawData(i, &list, &nbe, &nbc, &nbn); - if(nbn > 1) - smoothList(*list, *nbe, NbTimeStep, nbn, nbc, data); + if(nbn > 1) smoothList(*list, *nbe, NbTimeStep, nbn, nbc, data); } xyzv::eps = old_eps; finalize(); @@ -644,47 +682,88 @@ bool PViewDataList::combineSpace(nameData &nd) if(nd.data.size() < 2) return false; int ts = nd.data[0]->getNumTimeSteps(); for(unsigned int i = 1; i < nd.data.size(); i++) { - if(!nd.data[i]->empty() && nd.data[i]->getNumTimeSteps() != ts){ + if(!nd.data[i]->empty() && nd.data[i]->getNumTimeSteps() != ts) { Msg::Error("Cannot combine views having different number of time steps"); return false; } } for(unsigned int i = 0; i < nd.data.size(); i++) { - PViewDataList *l = dynamic_cast<PViewDataList*>(nd.data[i]); - if(!l){ + PViewDataList *l = dynamic_cast<PViewDataList *>(nd.data[i]); + if(!l) { Msg::Error("Cannot combine hybrid data"); return false; } // copy interpolation matrices - for(std::map<int, std::vector<fullMatrix<double>*> >::iterator it = - l->_interpolation.begin(); it != l->_interpolation.end(); it++) + for(std::map<int, std::vector<fullMatrix<double> *> >::iterator it = + l->_interpolation.begin(); + it != l->_interpolation.end(); it++) if(_interpolation[it->first].empty()) for(unsigned int i = 0; i < it->second.size(); i++) - _interpolation[it->first].push_back(new fullMatrix<double>(*it->second[i])); + _interpolation[it->first].push_back( + new fullMatrix<double>(*it->second[i])); // copy time values if(!i) Time = l->Time; // merge elememts - dVecMerge(l->SP, SP); NbSP += l->NbSP; dVecMerge(l->VP, VP); NbVP += l->NbVP; - dVecMerge(l->TP, TP); NbTP += l->NbTP; dVecMerge(l->SL, SL); NbSL += l->NbSL; - dVecMerge(l->VL, VL); NbVL += l->NbVL; dVecMerge(l->TL, TL); NbTL += l->NbTL; - dVecMerge(l->ST, ST); NbST += l->NbST; dVecMerge(l->VT, VT); NbVT += l->NbVT; - dVecMerge(l->TT, TT); NbTT += l->NbTT; dVecMerge(l->SQ, SQ); NbSQ += l->NbSQ; - dVecMerge(l->VQ, VQ); NbVQ += l->NbVQ; dVecMerge(l->TQ, TQ); NbTQ += l->NbTQ; - dVecMerge(l->SS, SS); NbSS += l->NbSS; dVecMerge(l->VS, VS); NbVS += l->NbVS; - dVecMerge(l->TS, TS); NbTS += l->NbTS; dVecMerge(l->SH, SH); NbSH += l->NbSH; - dVecMerge(l->VH, VH); NbVH += l->NbVH; dVecMerge(l->TH, TH); NbTH += l->NbTH; - dVecMerge(l->SI, SI); NbSI += l->NbSI; dVecMerge(l->VI, VI); NbVI += l->NbVI; - dVecMerge(l->TI, TI); NbTI += l->NbTI; dVecMerge(l->SY, SY); NbSY += l->NbSY; - dVecMerge(l->VY, VY); NbVY += l->NbVY; dVecMerge(l->TY, TY); NbTY += l->NbTY; - dVecMerge(l->VR, VR); NbVR += l->NbVR; dVecMerge(l->TR, TR); NbTR += l->NbTR; + dVecMerge(l->SP, SP); + NbSP += l->NbSP; + dVecMerge(l->VP, VP); + NbVP += l->NbVP; + dVecMerge(l->TP, TP); + NbTP += l->NbTP; + dVecMerge(l->SL, SL); + NbSL += l->NbSL; + dVecMerge(l->VL, VL); + NbVL += l->NbVL; + dVecMerge(l->TL, TL); + NbTL += l->NbTL; + dVecMerge(l->ST, ST); + NbST += l->NbST; + dVecMerge(l->VT, VT); + NbVT += l->NbVT; + dVecMerge(l->TT, TT); + NbTT += l->NbTT; + dVecMerge(l->SQ, SQ); + NbSQ += l->NbSQ; + dVecMerge(l->VQ, VQ); + NbVQ += l->NbVQ; + dVecMerge(l->TQ, TQ); + NbTQ += l->NbTQ; + dVecMerge(l->SS, SS); + NbSS += l->NbSS; + dVecMerge(l->VS, VS); + NbVS += l->NbVS; + dVecMerge(l->TS, TS); + NbTS += l->NbTS; + dVecMerge(l->SH, SH); + NbSH += l->NbSH; + dVecMerge(l->VH, VH); + NbVH += l->NbVH; + dVecMerge(l->TH, TH); + NbTH += l->NbTH; + dVecMerge(l->SI, SI); + NbSI += l->NbSI; + dVecMerge(l->VI, VI); + NbVI += l->NbVI; + dVecMerge(l->TI, TI); + NbTI += l->NbTI; + dVecMerge(l->SY, SY); + NbSY += l->NbSY; + dVecMerge(l->VY, VY); + NbVY += l->NbVY; + dVecMerge(l->TY, TY); + NbTY += l->NbTY; + dVecMerge(l->VR, VR); + NbVR += l->NbVR; + dVecMerge(l->TR, TR); + NbTR += l->NbTR; // merge strings - for(unsigned int i = 0; i < l->T2D.size(); i += 4){ + for(unsigned int i = 0; i < l->T2D.size(); i += 4) { T2D.push_back(l->T2D[i]); T2D.push_back(l->T2D[i + 1]); T2D.push_back(l->T2D[i + 2]); @@ -696,11 +775,10 @@ bool PViewDataList::combineSpace(nameData &nd) else end = l->T2D[i + 3 + 4]; char *c = &l->T2C[(int)beg]; - for(int j = 0; j < (int)(end - beg); j++) - T2C.push_back(c[j]); + for(int j = 0; j < (int)(end - beg); j++) T2C.push_back(c[j]); NbT2++; } - for(unsigned int i = 0; i < l->T3D.size(); i += 5){ + for(unsigned int i = 0; i < l->T3D.size(); i += 5) { T3D.push_back(l->T3D[i]); T3D.push_back(l->T3D[i + 1]); T3D.push_back(l->T3D[i + 2]); @@ -713,8 +791,7 @@ bool PViewDataList::combineSpace(nameData &nd) else end = l->T3D[i + 4 + 5]; char *c = &l->T3C[(int)beg]; - for(int j = 0; j < (int)(end-beg); j++) - T3C.push_back(c[j]); + for(int j = 0; j < (int)(end - beg); j++) T3C.push_back(c[j]); NbT3++; } } @@ -738,10 +815,10 @@ bool PViewDataList::combineTime(nameData &nd) { // sanity checks if(nd.data.size() < 2) return false; - std::vector<PViewDataList*> data(nd.data.size()); - for(unsigned int i = 0; i < nd.data.size(); i++){ - data[i] = dynamic_cast<PViewDataList*>(nd.data[i]); - if(!data[i]){ + std::vector<PViewDataList *> data(nd.data.size()); + for(unsigned int i = 0; i < nd.data.size(); i++) { + data[i] = dynamic_cast<PViewDataList *>(nd.data[i]); + if(!data[i]) { Msg::Error("Cannot combine hybrid data"); return false; } @@ -751,28 +828,30 @@ bool PViewDataList::combineTime(nameData &nd) std::vector<double> *list = 0, *list2 = 0; // use the first data set as the reference - for(int i = 0; i < 27; i++){ + for(int i = 0; i < 27; i++) { _getRawData(i, &list, &nbe, &nbc, &nbn); data[0]->_getRawData(i, &list2, &nbe2, &nbc2, &nbn2); *nbe = *nbe2; } NbT2 = data[0]->NbT2; NbT3 = data[0]->NbT3; - for(std::map<int, std::vector<fullMatrix<double>*> >::iterator it = - data[0]->_interpolation.begin(); it != data[0]->_interpolation.end(); it++) + for(std::map<int, std::vector<fullMatrix<double> *> >::iterator it = + data[0]->_interpolation.begin(); + it != data[0]->_interpolation.end(); it++) if(_interpolation[it->first].empty()) for(unsigned int i = 0; i < it->second.size(); i++) - _interpolation[it->first].push_back(new fullMatrix<double>(*it->second[i])); + _interpolation[it->first].push_back( + new fullMatrix<double>(*it->second[i])); // merge values for all element types - for(int i = 0; i < 27; i++){ + for(int i = 0; i < 27; i++) { _getRawData(i, &list, &nbe, &nbc, &nbn); - for(int j = 0; j < *nbe; j++){ - for(unsigned int k = 0; k < data.size(); k++){ + for(int j = 0; j < *nbe; j++) { + for(unsigned int k = 0; k < data.size(); k++) { data[k]->_getRawData(i, &list2, &nbe2, &nbc2, &nbn2); - if(*nbe && *nbe == *nbe2){ + if(*nbe && *nbe == *nbe2) { int nb2 = list2->size() / *nbe2; - if(!k){ + if(!k) { // copy coordinates of elm j (we are always here as // expected, since the ref view is the first one) for(int l = 0; l < 3 * nbn2; l++) @@ -787,10 +866,10 @@ bool PViewDataList::combineTime(nameData &nd) } // merge 2d strings - for(int j = 0; j < NbT2; j++){ - for(unsigned int k = 0; k < data.size(); k++){ - if(NbT2 == data[k]->NbT2){ - if(!k){ + for(int j = 0; j < NbT2; j++) { + for(unsigned int k = 0; k < data.size(); k++) { + if(NbT2 == data[k]->NbT2) { + if(!k) { // copy coordinates T2D.push_back(data[k]->T2D[j * 4]); T2D.push_back(data[k]->T2D[j * 4 + 1]); @@ -806,17 +885,16 @@ bool PViewDataList::combineTime(nameData &nd) else end = data[k]->T2D[j * 4 + 4 + 3]; char *c = &data[k]->T2C[(int)beg]; - for(int l = 0; l < (int)(end - beg); l++) - T2C.push_back(c[l]); + for(int l = 0; l < (int)(end - beg); l++) T2C.push_back(c[l]); } } } // merge 3d strings - for(int j = 0; j < NbT3; j++){ - for(unsigned int k = 0; k < data.size(); k++){ - if(NbT3 == data[k]->NbT3){ - if(!k){ + for(int j = 0; j < NbT3; j++) { + for(unsigned int k = 0; k < data.size(); k++) { + if(NbT3 == data[k]->NbT3) { + if(!k) { // copy coordinates T3D.push_back(data[k]->T3D[j * 5]); T3D.push_back(data[k]->T3D[j * 5 + 1]); @@ -833,25 +911,23 @@ bool PViewDataList::combineTime(nameData &nd) else end = data[k]->T3D[j * 5 + 5 + 4]; char *c = &data[k]->T3C[(int)beg]; - for(int l = 0; l < (int)(end - beg); l++) - T3C.push_back(c[l]); + for(int l = 0; l < (int)(end - beg); l++) T3C.push_back(c[l]); } } } // create the time data - for(unsigned int i = 0; i < data.size(); i++) - dVecMerge(data[i]->Time, Time); + for(unsigned int i = 0; i < data.size(); i++) dVecMerge(data[i]->Time, Time); // if all the time values are the same, it probably means that the // original views didn't have any time data: then we'll just use // time step values - if(Time.size()){ + if(Time.size()) { double t0 = Time[0], ti; bool allTheSame = true; - for(unsigned int i = 1; i < Time.size(); i++){ + for(unsigned int i = 1; i < Time.size(); i++) { ti = Time[i]; - if(ti != t0){ + if(ti != t0) { allTheSame = false; break; } @@ -881,45 +957,243 @@ int PViewDataList::_getRawData(int idxtype, std::vector<double> **l, int **ne, // No constant nn for polygons! if(idxtype > 26 && idxtype < 33) Msg::Warning("No constant number of nodes for polygons and polyhedra"); - switch(idxtype){ - case 0 : *l = &SP; *ne = &NbSP; *nc = 1; *nn = 1; type = TYPE_PNT; break; - case 1 : *l = &VP; *ne = &NbVP; *nc = 3; *nn = 1; type = TYPE_PNT; break; - case 2 : *l = &TP; *ne = &NbTP; *nc = 9; *nn = 1; type = TYPE_PNT; break; - case 3 : *l = &SL; *ne = &NbSL; *nc = 1; *nn = 2; type = TYPE_LIN; break; - case 4 : *l = &VL; *ne = &NbVL; *nc = 3; *nn = 2; type = TYPE_LIN; break; - case 5 : *l = &TL; *ne = &NbTL; *nc = 9; *nn = 2; type = TYPE_LIN; break; - case 6 : *l = &ST; *ne = &NbST; *nc = 1; *nn = 3; type = TYPE_TRI; break; - case 7 : *l = &VT; *ne = &NbVT; *nc = 3; *nn = 3; type = TYPE_TRI; break; - case 8 : *l = &TT; *ne = &NbTT; *nc = 9; *nn = 3; type = TYPE_TRI; break; - case 9 : *l = &SQ; *ne = &NbSQ; *nc = 1; *nn = 4; type = TYPE_QUA; break; - case 10: *l = &VQ; *ne = &NbVQ; *nc = 3; *nn = 4; type = TYPE_QUA; break; - case 11: *l = &TQ; *ne = &NbTQ; *nc = 9; *nn = 4; type = TYPE_QUA; break; - case 12: *l = &SS; *ne = &NbSS; *nc = 1; *nn = 4; type = TYPE_TET; break; - case 13: *l = &VS; *ne = &NbVS; *nc = 3; *nn = 4; type = TYPE_TET; break; - case 14: *l = &TS; *ne = &NbTS; *nc = 9; *nn = 4; type = TYPE_TET; break; - case 15: *l = &SH; *ne = &NbSH; *nc = 1; *nn = 8; type = TYPE_HEX; break; - case 16: *l = &VH; *ne = &NbVH; *nc = 3; *nn = 8; type = TYPE_HEX; break; - case 17: *l = &TH; *ne = &NbTH; *nc = 9; *nn = 8; type = TYPE_HEX; break; - case 18: *l = &SI; *ne = &NbSI; *nc = 1; *nn = 6; type = TYPE_PRI; break; - case 19: *l = &VI; *ne = &NbVI; *nc = 3; *nn = 6; type = TYPE_PRI; break; - case 20: *l = &TI; *ne = &NbTI; *nc = 9; *nn = 6; type = TYPE_PRI; break; - case 21: *l = &SY; *ne = &NbSY; *nc = 1; *nn = 5; type = TYPE_PYR; break; - case 22: *l = &VY; *ne = &NbVY; *nc = 3; *nn = 5; type = TYPE_PYR; break; - case 23: *l = &TY; *ne = &NbTY; *nc = 9; *nn = 5; type = TYPE_PYR; break; - case 24: *l = &SR; *ne = &NbSR; *nc = 1; *nn = 4; type = TYPE_TRIH; break; - case 25: *l = &VR; *ne = &NbVR; *nc = 3; *nn = 4; type = TYPE_TRIH; break; - case 26: *l = &TR; *ne = &NbTR; *nc = 9; *nn = 4; type = TYPE_TRIH; break; - case 27: *l = &SG; *ne = &NbSG; *nc = 1; *nn = 3; type = TYPE_POLYG; break; - case 28: *l = &VG; *ne = &NbVG; *nc = 3; *nn = 3; type = TYPE_POLYG; break; - case 29: *l = &TG; *ne = &NbTG; *nc = 9; *nn = 3; type = TYPE_POLYG; break; - case 30: *l = &SD; *ne = &NbSD; *nc = 1; *nn = 4; type = TYPE_POLYH; break; - case 31: *l = &VD; *ne = &NbVD; *nc = 3; *nn = 4; type = TYPE_POLYH; break; - case 32: *l = &TD; *ne = &NbTD; *nc = 9; *nn = 4; type = TYPE_POLYH; break; + switch(idxtype) { + case 0: + *l = &SP; + *ne = &NbSP; + *nc = 1; + *nn = 1; + type = TYPE_PNT; + break; + case 1: + *l = &VP; + *ne = &NbVP; + *nc = 3; + *nn = 1; + type = TYPE_PNT; + break; + case 2: + *l = &TP; + *ne = &NbTP; + *nc = 9; + *nn = 1; + type = TYPE_PNT; + break; + case 3: + *l = &SL; + *ne = &NbSL; + *nc = 1; + *nn = 2; + type = TYPE_LIN; + break; + case 4: + *l = &VL; + *ne = &NbVL; + *nc = 3; + *nn = 2; + type = TYPE_LIN; + break; + case 5: + *l = &TL; + *ne = &NbTL; + *nc = 9; + *nn = 2; + type = TYPE_LIN; + break; + case 6: + *l = &ST; + *ne = &NbST; + *nc = 1; + *nn = 3; + type = TYPE_TRI; + break; + case 7: + *l = &VT; + *ne = &NbVT; + *nc = 3; + *nn = 3; + type = TYPE_TRI; + break; + case 8: + *l = &TT; + *ne = &NbTT; + *nc = 9; + *nn = 3; + type = TYPE_TRI; + break; + case 9: + *l = &SQ; + *ne = &NbSQ; + *nc = 1; + *nn = 4; + type = TYPE_QUA; + break; + case 10: + *l = &VQ; + *ne = &NbVQ; + *nc = 3; + *nn = 4; + type = TYPE_QUA; + break; + case 11: + *l = &TQ; + *ne = &NbTQ; + *nc = 9; + *nn = 4; + type = TYPE_QUA; + break; + case 12: + *l = &SS; + *ne = &NbSS; + *nc = 1; + *nn = 4; + type = TYPE_TET; + break; + case 13: + *l = &VS; + *ne = &NbVS; + *nc = 3; + *nn = 4; + type = TYPE_TET; + break; + case 14: + *l = &TS; + *ne = &NbTS; + *nc = 9; + *nn = 4; + type = TYPE_TET; + break; + case 15: + *l = &SH; + *ne = &NbSH; + *nc = 1; + *nn = 8; + type = TYPE_HEX; + break; + case 16: + *l = &VH; + *ne = &NbVH; + *nc = 3; + *nn = 8; + type = TYPE_HEX; + break; + case 17: + *l = &TH; + *ne = &NbTH; + *nc = 9; + *nn = 8; + type = TYPE_HEX; + break; + case 18: + *l = &SI; + *ne = &NbSI; + *nc = 1; + *nn = 6; + type = TYPE_PRI; + break; + case 19: + *l = &VI; + *ne = &NbVI; + *nc = 3; + *nn = 6; + type = TYPE_PRI; + break; + case 20: + *l = &TI; + *ne = &NbTI; + *nc = 9; + *nn = 6; + type = TYPE_PRI; + break; + case 21: + *l = &SY; + *ne = &NbSY; + *nc = 1; + *nn = 5; + type = TYPE_PYR; + break; + case 22: + *l = &VY; + *ne = &NbVY; + *nc = 3; + *nn = 5; + type = TYPE_PYR; + break; + case 23: + *l = &TY; + *ne = &NbTY; + *nc = 9; + *nn = 5; + type = TYPE_PYR; + break; + case 24: + *l = &SR; + *ne = &NbSR; + *nc = 1; + *nn = 4; + type = TYPE_TRIH; + break; + case 25: + *l = &VR; + *ne = &NbVR; + *nc = 3; + *nn = 4; + type = TYPE_TRIH; + break; + case 26: + *l = &TR; + *ne = &NbTR; + *nc = 9; + *nn = 4; + type = TYPE_TRIH; + break; + case 27: + *l = &SG; + *ne = &NbSG; + *nc = 1; + *nn = 3; + type = TYPE_POLYG; + break; + case 28: + *l = &VG; + *ne = &NbVG; + *nc = 3; + *nn = 3; + type = TYPE_POLYG; + break; + case 29: + *l = &TG; + *ne = &NbTG; + *nc = 9; + *nn = 3; + type = TYPE_POLYG; + break; + case 30: + *l = &SD; + *ne = &NbSD; + *nc = 1; + *nn = 4; + type = TYPE_POLYH; + break; + case 31: + *l = &VD; + *ne = &NbVD; + *nc = 3; + *nn = 4; + type = TYPE_POLYH; + break; + case 32: + *l = &TD; + *ne = &NbTD; + *nc = 9; + *nn = 4; + type = TYPE_POLYH; + break; default: Msg::Error("Wrong type in PViewDataList"); break; } - if(haveInterpolationMatrices()){ - std::vector<fullMatrix<double>*> im; + if(haveInterpolationMatrices()) { + std::vector<fullMatrix<double> *> im; int nim = getInterpolationMatrices(type, im); if(nim == 4) *nn = im[2]->size1(); } @@ -929,7 +1203,7 @@ int PViewDataList::_getRawData(int idxtype, std::vector<double> **l, int **ne, void PViewDataList::setOrder2(int type) { int typeMSH = 0; - switch(type){ + switch(type) { case TYPE_LIN: typeMSH = MSH_LIN_3; break; case TYPE_TRI: typeMSH = MSH_TRI_6; break; case TYPE_QUA: typeMSH = MSH_QUA_9; break; @@ -938,8 +1212,9 @@ void PViewDataList::setOrder2(int type) case TYPE_PRI: typeMSH = MSH_PRI_18; break; case TYPE_PYR: typeMSH = MSH_PYR_14; break; } - const polynomialBasis *fs = (polynomialBasis*)BasisFactory::getNodalBasis(typeMSH); - if(!fs){ + const polynomialBasis *fs = + (polynomialBasis *)BasisFactory::getNodalBasis(typeMSH); + if(!fs) { Msg::Error("Could not find polynomial function space for element type %d", typeMSH); return; @@ -948,74 +1223,173 @@ void PViewDataList::setOrder2(int type) fs->coefficients, fs->monomials); } -std::vector<double> *PViewDataList::incrementList(int numComp, int type, int numNodes) +std::vector<double> *PViewDataList::incrementList(int numComp, int type, + int numNodes) { int nb; - switch(type){ + switch(type) { case TYPE_PNT: - if (numComp == 1){ NbSP++; return &SP; } - else if(numComp == 3){ NbVP++; return &VP; } - else if(numComp == 9){ NbTP++; return &TP; } + if(numComp == 1) { + NbSP++; + return &SP; + } + else if(numComp == 3) { + NbVP++; + return &VP; + } + else if(numComp == 9) { + NbTP++; + return &TP; + } break; case TYPE_LIN: - if (numComp == 1){ NbSL++; return &SL; } - else if(numComp == 3){ NbVL++; return &VL; } - else if(numComp == 9){ NbTL++; return &TL; } + if(numComp == 1) { + NbSL++; + return &SL; + } + else if(numComp == 3) { + NbVL++; + return &VL; + } + else if(numComp == 9) { + NbTL++; + return &TL; + } break; case TYPE_TRI: - if (numComp == 1){ NbST++; return &ST; } - else if(numComp == 3){ NbVT++; return &VT; } - else if(numComp == 9){ NbTT++; return &TT; } + if(numComp == 1) { + NbST++; + return &ST; + } + else if(numComp == 3) { + NbVT++; + return &VT; + } + else if(numComp == 9) { + NbTT++; + return &TT; + } break; case TYPE_QUA: - if (numComp == 1){ NbSQ++; return &SQ; } - else if(numComp == 3){ NbVQ++; return &VQ; } - else if(numComp == 9){ NbTQ++; return &TQ; } + if(numComp == 1) { + NbSQ++; + return &SQ; + } + else if(numComp == 3) { + NbVQ++; + return &VQ; + } + else if(numComp == 9) { + NbTQ++; + return &TQ; + } break; case TYPE_TET: - if (numComp == 1){ NbSS++; return &SS; } - else if(numComp == 3){ NbVS++; return &VS; } - else if(numComp == 9){ NbTS++; return &TS; } + if(numComp == 1) { + NbSS++; + return &SS; + } + else if(numComp == 3) { + NbVS++; + return &VS; + } + else if(numComp == 9) { + NbTS++; + return &TS; + } break; case TYPE_HEX: - if (numComp == 1){ NbSH++; return &SH; } - else if(numComp == 3){ NbVH++; return &VH; } - else if(numComp == 9){ NbTH++; return &TH; } + if(numComp == 1) { + NbSH++; + return &SH; + } + else if(numComp == 3) { + NbVH++; + return &VH; + } + else if(numComp == 9) { + NbTH++; + return &TH; + } break; case TYPE_PRI: - if (numComp == 1){ NbSI++; return &SI; } - else if(numComp == 3){ NbVI++; return &VI; } - else if(numComp == 9){ NbTI++; return &TI; } + if(numComp == 1) { + NbSI++; + return &SI; + } + else if(numComp == 3) { + NbVI++; + return &VI; + } + else if(numComp == 9) { + NbTI++; + return &TI; + } break; case TYPE_PYR: - if (numComp == 1){ NbSY++; return &SY; } - else if(numComp == 3){ NbVY++; return &VY; } - else if(numComp == 9){ NbTY++; return &TY; } + if(numComp == 1) { + NbSY++; + return &SY; + } + else if(numComp == 3) { + NbVY++; + return &VY; + } + else if(numComp == 9) { + NbTY++; + return &TY; + } break; case TYPE_TRIH: - if (numComp == 1){ NbSR++; return &SR; } - else if(numComp == 3){ NbVR++; return &VR; } - else if(numComp == 9){ NbTR++; return &TR; } + if(numComp == 1) { + NbSR++; + return &SR; + } + else if(numComp == 3) { + NbVR++; + return &VR; + } + else if(numComp == 9) { + NbTR++; + return &TR; + } break; case TYPE_POLYG: polyNumNodes[0].push_back(numNodes); nb = (polyAgNumNodes[0].size()) ? polyAgNumNodes[0].back() : 0; polyAgNumNodes[0].push_back(numNodes + nb); polyTotNumNodes[0] += numNodes; - if (numComp == 1){ NbSG++; return &SG; } - else if(numComp == 3){ NbVG++; return &VG; } - else if(numComp == 9){ NbTG++; return &TG; } + if(numComp == 1) { + NbSG++; + return &SG; + } + else if(numComp == 3) { + NbVG++; + return &VG; + } + else if(numComp == 9) { + NbTG++; + return &TG; + } break; case TYPE_POLYH: polyNumNodes[1].push_back(numNodes); nb = (polyAgNumNodes[1].size()) ? polyAgNumNodes[1].back() : 0; polyAgNumNodes[1].push_back(numNodes + nb); polyTotNumNodes[1] += numNodes; - if (numComp == 1){ NbSD++; return &SD; } - else if(numComp == 3){ NbVD++; return &VD; } - else if(numComp == 9){ NbTD++; return &TD; } + if(numComp == 1) { + NbSD++; + return &SD; + } + else if(numComp == 3) { + NbVD++; + return &VD; + } + else if(numComp == 9) { + NbTD++; + return &TD; + } break; } return 0; } - diff --git a/Post/PViewDataList.h b/Post/PViewDataList.h index b2ef98a894257bf4c4c5e4c04455f4202879d931..82157088138b11491318e63f3916f3da635983fe 100644 --- a/Post/PViewDataList.h +++ b/Post/PViewDataList.h @@ -15,7 +15,7 @@ // The container for list-based datasets (for which all elements are // discontinuous). class PViewDataList : public PViewData { - public: +public: // FIXME: all these members will be made private once the plugins // have been rewritten int NbTimeStep; @@ -51,55 +51,63 @@ class PViewDataList : public PViewData { std::vector<int> polyNumNodes[2]; std::vector<int> polyAgNumNodes[2]; int polyTotNumNodes[2]; - private: + +private: int _index[33]; int _lastElement, _lastDimension; - int _lastNumNodes, _lastNumComponents, _lastNumValues, _lastNumEdges, _lastType; + int _lastNumNodes, _lastNumComponents, _lastNumValues, _lastNumEdges, + _lastType; double *_lastXYZ, *_lastVal; bool _isAdapted; void _stat(std::vector<double> &D, std::vector<char> &C, int nb); - void _stat(std::vector<double> &list, int nbcomp, int nbelm, int nbnod, int type); + void _stat(std::vector<double> &list, int nbcomp, int nbelm, int nbnod, + int type); void _setLast(int ele); void _setLast(int ele, int dim, int nbnod, int nbcomp, int nbedg, int type, std::vector<double> &list, int nblist); - void _getString(int dim, int i, int timestep, std::string &str, - double &x, double &y, double &z, double &style); - int _getRawData(int idxtype, std::vector<double> **l, int **ne, int *nc, int *nn); - public: - PViewDataList(bool isAdapted=false); - ~PViewDataList(){} - bool isAdapted(){ return _isAdapted; } - bool finalize(bool computeMinMax=true, const std::string &interpolationScheme=""); - int getNumTimeSteps(){ return NbTimeStep; } + void _getString(int dim, int i, int timestep, std::string &str, double &x, + double &y, double &z, double &style); + int _getRawData(int idxtype, std::vector<double> **l, int **ne, int *nc, + int *nn); + +public: + PViewDataList(bool isAdapted = false); + ~PViewDataList() {} + bool isAdapted() { return _isAdapted; } + bool finalize(bool computeMinMax = true, + const std::string &interpolationScheme = ""); + int getNumTimeSteps() { return NbTimeStep; } double getTime(int step); - double getMin(int step = -1, bool onlyVisible = false, int forceNumComponents = 0, - int componentMap[9] = 0); - double getMax(int step = -1, bool onlyVisible = false, int forceNumComponents = 0, - int componentMap[9] = 0); - void setMin(double min) {Min = min;} - void setMax(double max) {Max = max;} - SBoundingBox3d getBoundingBox(int step = -1){ return BBox; } - void setBoundingBox(SBoundingBox3d& box) {BBox = box;} - int getNumScalars(int step=-1); - int getNumVectors(int step=-1); - int getNumTensors(int step=-1); - int getNumPoints(int step=-1){ return NbSP + NbVP + NbTP; } - int getNumLines(int step=-1){ return NbSL + NbVL + NbTL; } - int getNumTriangles(int step=-1){ return NbST + NbVT + NbTT; } - int getNumQuadrangles(int step=-1){ return NbSQ + NbVQ + NbTQ; } - int getNumPolygons(int step=-1){ return NbSG + NbVG + NbTG; } - int getNumTetrahedra(int step=-1){ return NbSS + NbVS + NbTS; } - int getNumHexahedra(int step=-1){ return NbSH + NbVH + NbTH; } - int getNumPrisms(int step=-1){ return NbSI + NbVI + NbTI; } - int getNumPyramids(int step=-1){ return NbSY + NbVY + NbTY; } - int getNumTrihedra(int step=-1){ return NbSR + NbVR + NbTR; } - int getNumPolyhedra(int step=-1){ return NbSD + NbVD + NbTD; } - int getNumEntities(int step=-1){ return 1; } - int getNumElements(int step=-1, int ent=-1); + double getMin(int step = -1, bool onlyVisible = false, + int forceNumComponents = 0, int componentMap[9] = 0); + double getMax(int step = -1, bool onlyVisible = false, + int forceNumComponents = 0, int componentMap[9] = 0); + void setMin(double min) { Min = min; } + void setMax(double max) { Max = max; } + SBoundingBox3d getBoundingBox(int step = -1) { return BBox; } + void setBoundingBox(SBoundingBox3d &box) { BBox = box; } + int getNumScalars(int step = -1); + int getNumVectors(int step = -1); + int getNumTensors(int step = -1); + int getNumPoints(int step = -1) { return NbSP + NbVP + NbTP; } + int getNumLines(int step = -1) { return NbSL + NbVL + NbTL; } + int getNumTriangles(int step = -1) { return NbST + NbVT + NbTT; } + int getNumQuadrangles(int step = -1) { return NbSQ + NbVQ + NbTQ; } + int getNumPolygons(int step = -1) { return NbSG + NbVG + NbTG; } + int getNumTetrahedra(int step = -1) { return NbSS + NbVS + NbTS; } + int getNumHexahedra(int step = -1) { return NbSH + NbVH + NbTH; } + int getNumPrisms(int step = -1) { return NbSI + NbVI + NbTI; } + int getNumPyramids(int step = -1) { return NbSY + NbVY + NbTY; } + int getNumTrihedra(int step = -1) { return NbSR + NbVR + NbTR; } + int getNumPolyhedra(int step = -1) { return NbSD + NbVD + NbTD; } + int getNumEntities(int step = -1) { return 1; } + int getNumElements(int step = -1, int ent = -1); int getDimension(int step, int ent, int ele); int getNumNodes(int step, int ent, int ele); - int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z); - void setNode(int step, int ent, int ele, int nod, double x, double y, double z); + int getNode(int step, int ent, int ele, int nod, double &x, double &y, + double &z); + void setNode(int step, int ent, int ele, int nod, double x, double y, + double z); int getNumComponents(int step, int ent, int ele); int getNumValues(int step, int ent, int ele); void getValue(int step, int ent, int ele, int idx, double &val); @@ -107,20 +115,20 @@ class PViewDataList : public PViewData { void setValue(int step, int ent, int ele, int nod, int comp, double val); int getNumEdges(int step, int ent, int ele); int getType(int step, int ent, int ele); - int getNumStrings2D(){ return NbT2; } - int getNumStrings3D(){ return NbT3; } - void getString2D(int i, int step, std::string &str, - double &x, double &y, double &style); - void getString3D(int i, int step, std::string &str, - double &x, double &y, double &z, double &style); + int getNumStrings2D() { return NbT2; } + int getNumStrings3D() { return NbT3; } + void getString2D(int i, int step, std::string &str, double &x, double &y, + double &style); + void getString3D(int i, int step, std::string &str, double &x, double &y, + double &z, double &style); void reverseElement(int step, int ent, int ele); void smooth(); bool combineTime(nameData &nd); bool combineSpace(nameData &nd); void setXY(std::vector<double> &x, std::vector<double> &y); - void setXYZV(std::vector<double> &x, std::vector<double> &y, std::vector<double> &z, - std::vector<double> &v); - bool isListBased(){ return true; } + void setXYZV(std::vector<double> &x, std::vector<double> &y, + std::vector<double> &z, std::vector<double> &v); + bool isListBased() { return true; } double getMemoryInMb(); // specific to list-based data sets @@ -129,16 +137,18 @@ class PViewDataList : public PViewData { // I/O routines bool readPOS(FILE *fp, double version, bool binary); - bool writePOS(const std::string &fileName, bool binary=false, bool parsed=true, - bool append=false); + bool writePOS(const std::string &fileName, bool binary = false, + bool parsed = true, bool append = false); virtual bool writeMSH(const std::string &fileName, double version = 2.2, bool binary = false, bool savemesh = true, bool multipleView = false, int partitionNum = 0, bool saveInterpolationMatrices = true, - bool forceNodeData = false, bool forceElementData = false); + bool forceNodeData = false, + bool forceElementData = false); virtual void importLists(int N[24], std::vector<double> *V[24]); virtual void getListPointers(int N[24], std::vector<double> *V[24]); - void importList(int index, int n, const std::vector<double> &v, bool finalize); + void importList(int index, int n, const std::vector<double> &v, + bool finalize); }; #endif diff --git a/Post/PViewDataListIO.cpp b/Post/PViewDataListIO.cpp index c6c8a876d79dcb4ad55855af23a36f20ee48873d..a00ecb4e5cf8ce95ac28622f8f5812c8696d845d 100644 --- a/Post/PViewDataListIO.cpp +++ b/Post/PViewDataListIO.cpp @@ -16,19 +16,18 @@ #include "adaptiveData.h" #include "OS.h" -static void dVecRead(std::vector<double> &v, int n, FILE *fp, - bool binary, int swap) +static void dVecRead(std::vector<double> &v, int n, FILE *fp, bool binary, + int swap) { if(!n) return; v.resize(n); - if(binary){ - if(!fread(&v[0], sizeof(double), n, fp)) - Msg::Error("Read error"); - if(swap) SwapBytes((char*)&v[0], sizeof(double), n); + if(binary) { + if(!fread(&v[0], sizeof(double), n, fp)) Msg::Error("Read error"); + if(swap) SwapBytes((char *)&v[0], sizeof(double), n); } - else{ - for(int i = 0; i < n; i++){ - if(!fscanf(fp, "%lf", &v[i])){ + else { + for(int i = 0; i < n; i++) { + if(!fscanf(fp, "%lf", &v[i])) { Msg::Error("Read error"); break; } @@ -36,34 +35,33 @@ static void dVecRead(std::vector<double> &v, int n, FILE *fp, } } -static void cVecRead(std::vector<char> &v, int n, FILE *fp, - bool binary, int swap, bool oldStyle) +static void cVecRead(std::vector<char> &v, int n, FILE *fp, bool binary, + int swap, bool oldStyle) { if(!n) return; v.resize(n); - if(binary){ - if(!fread(&v[0], sizeof(char), n, fp)) - Msg::Error("Read error"); - if(swap) SwapBytes((char*)&v[0], sizeof(char), n); + if(binary) { + if(!fread(&v[0], sizeof(char), n, fp)) Msg::Error("Read error"); + if(swap) SwapBytes((char *)&v[0], sizeof(char), n); } - else{ - if(oldStyle){ - for(int i = 0; i < n; i++){ - if(!fscanf(fp, "%c", &v[i])){ + else { + if(oldStyle) { + for(int i = 0; i < n; i++) { + if(!fscanf(fp, "%c", &v[i])) { Msg::Error("Read error"); break; } if(v[i] == '^') v[i] = '\0'; } } - else{ - for(int i = 0; i < n; i++){ + else { + for(int i = 0; i < n; i++) { char c = (char)fgetc(fp); - if(c == EOF){ + if(c == EOF) { Msg::Error("Read error"); break; } - else{ + else { v[i] = c; } } @@ -77,8 +75,7 @@ static void dVecWrite(std::vector<double> &v, FILE *fp, bool binary) if(binary) fwrite(&v[0], sizeof(double), v.size(), fp); else - for(unsigned i = 0; i < v.size(); i++) - fprintf(fp, " %.16g", v[i]); + for(unsigned i = 0; i < v.size(); i++) fprintf(fp, " %.16g", v[i]); } static void cVecWrite(std::vector<char> &v, FILE *fp, bool binary) @@ -87,8 +84,7 @@ static void cVecWrite(std::vector<char> &v, FILE *fp, bool binary) if(binary) fwrite(&v[0], sizeof(char), v.size(), fp); else - for(unsigned i = 0; i < v.size(); i++) - fputc(v[i], fp); + for(unsigned i = 0; i < v.size(); i++) fputc(v[i], fp); } bool PViewDataList::readPOS(FILE *fp, double version, bool binary) @@ -107,9 +103,9 @@ bool PViewDataList::readPOS(FILE *fp, double version, bool binary) if(version <= 1.0) { Msg::Debug("Detected post-processing view format <= 1.0"); - if(!fscanf(fp, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d\n", - name, &NbTimeStep, &NbSP, &NbVP, &NbTP, &NbSL, &NbVL, &NbTL, - &NbST, &NbVT, &NbTT, &NbSS, &NbVS, &NbTS)){ + if(!fscanf(fp, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d\n", name, + &NbTimeStep, &NbSP, &NbVP, &NbTP, &NbSL, &NbVL, &NbTL, &NbST, + &NbVT, &NbTT, &NbSS, &NbVS, &NbTS)) { Msg::Error("Read error"); return false; } @@ -120,26 +116,28 @@ bool PViewDataList::readPOS(FILE *fp, double version, bool binary) if(!fscanf(fp, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", name, &NbTimeStep, &NbSP, &NbVP, &NbTP, &NbSL, &NbVL, &NbTL, &NbST, &NbVT, &NbTT, &NbSS, &NbVS, &NbTS, &NbT2, &t2l, &NbT3, - &t3l)){ + &t3l)) { Msg::Error("Read error"); return false; } } else if(version == 1.2 || version == 1.3) { Msg::Debug("Detected post-processing view format %g", version); - if(!fscanf(fp, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " + if(!fscanf(fp, + "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d %d %d %d %d\n", name, &NbTimeStep, &NbSP, &NbVP, &NbTP, &NbSL, &NbVL, &NbTL, &NbST, &NbVT, &NbTT, &NbSQ, &NbVQ, &NbTQ, &NbSS, &NbVS, &NbTS, &NbSH, &NbVH, &NbTH, &NbSI, &NbVI, &NbTI, &NbSY, &NbVY, &NbTY, - &NbT2, &t2l, &NbT3, &t3l)){ + &NbT2, &t2l, &NbT3, &t3l)) { Msg::Error("Read error"); return false; } } else if(version == 1.4) { Msg::Debug("Detected post-processing view format 1.4"); - if(!fscanf(fp, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " + if(!fscanf(fp, + "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", name, &NbTimeStep, &NbSP, &NbVP, &NbTP, &NbSL, &NbVL, &NbTL, @@ -147,7 +145,8 @@ bool PViewDataList::readPOS(FILE *fp, double version, bool binary) &NbSH, &NbVH, &NbTH, &NbSI, &NbVI, &NbTI, &NbSY, &NbVY, &NbTY, &NbSL2, &NbVL2, &NbTL2, &NbST2, &NbVT2, &NbTT2, &NbSQ2, &NbVQ2, &NbTQ2, &NbSS2, &NbVS2, &NbTS2, &NbSH2, &NbVH2, &NbTH2, &NbSI2, - &NbVI2, &NbTI2, &NbSY2, &NbVY2, &NbTY2, &NbT2, &t2l, &NbT3, &t3l)){ + &NbVI2, &NbTI2, &NbSY2, &NbVY2, &NbTY2, &NbT2, &t2l, &NbT3, + &t3l)) { Msg::Error("Read error"); return false; } @@ -158,13 +157,12 @@ bool PViewDataList::readPOS(FILE *fp, double version, bool binary) } for(int i = 0; i < (int)strlen(name); i++) - if(name[i] == '^') - name[i] = ' '; + if(name[i] == '^') name[i] = ' '; int swap = 0; if(binary) { int testone; - if(!fread(&testone, sizeof(int), 1, fp)){ + if(!fread(&testone, sizeof(int), 1, fp)) { Msg::Error("Read error"); return false; } @@ -222,27 +220,90 @@ bool PViewDataList::readPOS(FILE *fp, double version, bool binary) dVecRead(SY, NbSY2 * (NbTimeStep * 14 * 1 + 42), fp, binary, swap); dVecRead(VY, NbVY2 * (NbTimeStep * 14 * 3 + 42), fp, binary, swap); dVecRead(TY, NbTY2 * (NbTimeStep * 14 * 9 + 42), fp, binary, swap); - if(NbSL2){ NbSL = NbSL2; setOrder2(TYPE_LIN); } - if(NbVL2){ NbVL = NbVL2; setOrder2(TYPE_LIN); } - if(NbTL2){ NbTL = NbTL2; setOrder2(TYPE_LIN); } - if(NbST2){ NbST = NbST2; setOrder2(TYPE_TRI); } - if(NbVT2){ NbVT = NbVT2; setOrder2(TYPE_TRI); } - if(NbTT2){ NbTT = NbTT2; setOrder2(TYPE_TRI); } - if(NbSQ2){ NbSQ = NbSQ2; setOrder2(TYPE_QUA); } - if(NbVQ2){ NbVQ = NbVQ2; setOrder2(TYPE_QUA); } - if(NbTQ2){ NbTQ = NbTQ2; setOrder2(TYPE_QUA); } - if(NbSS2){ NbSS = NbSS2; setOrder2(TYPE_TET); } - if(NbVS2){ NbVS = NbVS2; setOrder2(TYPE_TET); } - if(NbTS2){ NbTS = NbTS2; setOrder2(TYPE_TET); } - if(NbSH2){ NbSH = NbSH2; setOrder2(TYPE_HEX); } - if(NbVH2){ NbVH = NbVH2; setOrder2(TYPE_HEX); } - if(NbTH2){ NbTH = NbTH2; setOrder2(TYPE_HEX); } - if(NbSI2){ NbSI = NbSI2; setOrder2(TYPE_PRI); } - if(NbVI2){ NbVI = NbVI2; setOrder2(TYPE_PRI); } - if(NbTI2){ NbTI = NbTI2; setOrder2(TYPE_PRI); } - if(NbSY2){ NbSY = NbSY2; setOrder2(TYPE_PYR); } - if(NbVY2){ NbVY = NbVY2; setOrder2(TYPE_PYR); } - if(NbTY2){ NbTY = NbTY2; setOrder2(TYPE_PYR); } + if(NbSL2) { + NbSL = NbSL2; + setOrder2(TYPE_LIN); + } + if(NbVL2) { + NbVL = NbVL2; + setOrder2(TYPE_LIN); + } + if(NbTL2) { + NbTL = NbTL2; + setOrder2(TYPE_LIN); + } + if(NbST2) { + NbST = NbST2; + setOrder2(TYPE_TRI); + } + if(NbVT2) { + NbVT = NbVT2; + setOrder2(TYPE_TRI); + } + if(NbTT2) { + NbTT = NbTT2; + setOrder2(TYPE_TRI); + } + if(NbSQ2) { + NbSQ = NbSQ2; + setOrder2(TYPE_QUA); + } + if(NbVQ2) { + NbVQ = NbVQ2; + setOrder2(TYPE_QUA); + } + if(NbTQ2) { + NbTQ = NbTQ2; + setOrder2(TYPE_QUA); + } + if(NbSS2) { + NbSS = NbSS2; + setOrder2(TYPE_TET); + } + if(NbVS2) { + NbVS = NbVS2; + setOrder2(TYPE_TET); + } + if(NbTS2) { + NbTS = NbTS2; + setOrder2(TYPE_TET); + } + if(NbSH2) { + NbSH = NbSH2; + setOrder2(TYPE_HEX); + } + if(NbVH2) { + NbVH = NbVH2; + setOrder2(TYPE_HEX); + } + if(NbTH2) { + NbTH = NbTH2; + setOrder2(TYPE_HEX); + } + if(NbSI2) { + NbSI = NbSI2; + setOrder2(TYPE_PRI); + } + if(NbVI2) { + NbVI = NbVI2; + setOrder2(TYPE_PRI); + } + if(NbTI2) { + NbTI = NbTI2; + setOrder2(TYPE_PRI); + } + if(NbSY2) { + NbSY = NbSY2; + setOrder2(TYPE_PYR); + } + if(NbVY2) { + NbVY = NbVY2; + setOrder2(TYPE_PYR); + } + if(NbTY2) { + NbTY = NbTY2; + setOrder2(TYPE_PYR); + } dVecRead(T2D, NbT2 * 4, fp, binary, swap); cVecRead(T2C, t2l, fp, binary, swap, (version <= 1.2)); @@ -259,17 +320,14 @@ bool PViewDataList::readPOS(FILE *fp, double version, bool binary) "SI(%d/%d) VI(%d/%d) TI(%d/%d) " "SY(%d/%d) VY(%d/%d) TY(%d/%d) " "T2(%d/%d/%d) T3(%d/%d/%d) ", - name, NbTimeStep, - NbSP, SP.size(), NbVP, VP.size(), NbTP, TP.size(), - NbSL, SL.size(), NbVL, VL.size(), NbTL, TL.size(), - NbST, ST.size(), NbVT, VT.size(), NbTT, TT.size(), - NbSQ, SQ.size(), NbVQ, VQ.size(), NbTQ, TQ.size(), - NbSS, SS.size(), NbVS, VS.size(), NbTS, TS.size(), - NbSH, SH.size(), NbVH, VH.size(), NbTH, TH.size(), - NbSI, SI.size(), NbVI, VI.size(), NbTI, TI.size(), - NbSY, SY.size(), NbVY, VY.size(), NbTY, TY.size(), - NbT2, T2D.size(), T2C.size(), - NbT3, T3D.size(), T3C.size()); + name, NbTimeStep, NbSP, SP.size(), NbVP, VP.size(), NbTP, + TP.size(), NbSL, SL.size(), NbVL, VL.size(), NbTL, TL.size(), NbST, + ST.size(), NbVT, VT.size(), NbTT, TT.size(), NbSQ, SQ.size(), NbVQ, + VQ.size(), NbTQ, TQ.size(), NbSS, SS.size(), NbVS, VS.size(), NbTS, + TS.size(), NbSH, SH.size(), NbVH, VH.size(), NbTH, TH.size(), NbSI, + SI.size(), NbVI, VI.size(), NbTI, TI.size(), NbSY, SY.size(), NbVY, + VY.size(), NbTY, TY.size(), NbT2, T2D.size(), T2C.size(), NbT3, + T3D.size(), T3C.size()); setName(name); finalize(); @@ -278,9 +336,9 @@ bool PViewDataList::readPOS(FILE *fp, double version, bool binary) static void writeTimePOS(FILE *fp, std::vector<double> &list) { - if(list.size() > 1){ + if(list.size() > 1) { fprintf(fp, "TIME{"); - for(unsigned int i = 0; i < list.size(); i++){ + for(unsigned int i = 0; i < list.size(); i++) { if(i) fprintf(fp, ","); fprintf(fp, "%.16g", list[i]); } @@ -291,7 +349,7 @@ static void writeTimePOS(FILE *fp, std::vector<double> &list) static void writeElementPOS(FILE *fp, const char *str, int nbnod, int nb, std::vector<double> &list) { - if(nb){ + if(nb) { int n = list.size() / nb; for(unsigned int i = 0; i < list.size(); i += n) { double *x = &list[i]; @@ -316,7 +374,7 @@ static void writeTextPOS(FILE *fp, int nbc, int nb, std::vector<double> &TD, std::vector<char> &TC) { if(!nb || (nbc != 4 && nbc != 5)) return; - for(unsigned int j = 0; j < TD.size(); j += nbc){ + for(unsigned int j = 0; j < TD.size(); j += nbc) { double x = TD[j]; double y = TD[j + 1]; double z = (nbc == 5) ? TD[j + 2] : 0.; @@ -332,7 +390,7 @@ static void writeTextPOS(FILE *fp, int nbc, int nb, std::vector<double> &TD, else end = TC.size(); int l = 0; - while(l < end - start){ + while(l < end - start) { char *str = &TC[(int)start + l]; if(l) fprintf(fp, ","); fprintf(fp, "\"%s\"", str); @@ -342,30 +400,33 @@ static void writeTextPOS(FILE *fp, int nbc, int nb, std::vector<double> &TD, } } -bool PViewDataList::writePOS(const std::string &fileName, bool binary, bool parsed, - bool append) +bool PViewDataList::writePOS(const std::string &fileName, bool binary, + bool parsed, bool append) { - if(_adaptive){ - Msg::Warning("Writing adapted dataset (will only export current time step)"); + if(_adaptive) { + Msg::Warning( + "Writing adapted dataset (will only export current time step)"); return _adaptive->getData()->writePOS(fileName, binary, parsed, append); } - if(haveInterpolationMatrices()){ - Msg::Error("Cannot export datasets with interpolation matrices in old POS format: " - "consider using the new mesh-based format instead, or select 'Adapt " - "post-processing data' before exporting"); + if(haveInterpolationMatrices()) { + Msg::Error( + "Cannot export datasets with interpolation matrices in old POS format: " + "consider using the new mesh-based format instead, or select 'Adapt " + "post-processing data' before exporting"); return false; } FILE *fp = Fopen(fileName.c_str(), append ? (binary ? "ab" : "a") : (binary ? "wb" : "w")); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } - if(!parsed && !append){ - fprintf(fp, "$PostFormat /* Gmsh 1.3, %s */\n", binary ? "binary" : "ascii"); + if(!parsed && !append) { + fprintf(fp, "$PostFormat /* Gmsh 1.3, %s */\n", + binary ? "binary" : "ascii"); fprintf(fp, "1.3 %d %d\n", binary, (int)sizeof(double)); fprintf(fp, "$EndPostFormat\n"); } @@ -374,62 +435,88 @@ bool PViewDataList::writePOS(const std::string &fileName, bool binary, bool pars for(unsigned int i = 0; i < str.size(); i++) if(str[i] == ' ') str[i] = '^'; - if(!parsed){ + if(!parsed) { fprintf(fp, "$View /* %s */\n", getName().c_str()); - if (str.empty()) + if(str.empty()) fprintf(fp, "noname "); else fprintf(fp, "%s ", str.c_str()); - fprintf(fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " + fprintf(fp, + "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d %d %d %d\n", - (int)Time.size(), - NbSP, NbVP, NbTP, NbSL, NbVL, NbTL, - NbST, NbVT, NbTT, NbSQ, NbVQ, NbTQ, - NbSS, NbVS, NbTS, NbSH, NbVH, NbTH, - NbSI, NbVI, NbTI, NbSY, NbVY, NbTY, - NbT2, (int)T2C.size(), NbT3, (int)T3C.size()); + (int)Time.size(), NbSP, NbVP, NbTP, NbSL, NbVL, NbTL, NbST, NbVT, + NbTT, NbSQ, NbVQ, NbTQ, NbSS, NbVS, NbTS, NbSH, NbVH, NbTH, NbSI, + NbVI, NbTI, NbSY, NbVY, NbTY, NbT2, (int)T2C.size(), NbT3, + (int)T3C.size()); if(binary) { int one = 1; - if(!fwrite(&one, sizeof(int), 1, fp)){ + if(!fwrite(&one, sizeof(int), 1, fp)) { Msg::Error("Write error"); fclose(fp); return false; } } dVecWrite(Time, fp, binary); - dVecWrite(SP, fp, binary); dVecWrite(VP, fp, binary); - dVecWrite(TP, fp, binary); dVecWrite(SL, fp, binary); - dVecWrite(VL, fp, binary); dVecWrite(TL, fp, binary); - dVecWrite(ST, fp, binary); dVecWrite(VT, fp, binary); - dVecWrite(TT, fp, binary); dVecWrite(SQ, fp, binary); - dVecWrite(VQ, fp, binary); dVecWrite(TQ, fp, binary); - dVecWrite(SS, fp, binary); dVecWrite(VS, fp, binary); - dVecWrite(TS, fp, binary); dVecWrite(SH, fp, binary); - dVecWrite(VH, fp, binary); dVecWrite(TH, fp, binary); - dVecWrite(SI, fp, binary); dVecWrite(VI, fp, binary); - dVecWrite(TI, fp, binary); dVecWrite(SY, fp, binary); - dVecWrite(VY, fp, binary); dVecWrite(TY, fp, binary); - dVecWrite(T2D, fp, binary); cVecWrite(T2C, fp, binary); - dVecWrite(T3D, fp, binary); cVecWrite(T3C, fp, binary); + dVecWrite(SP, fp, binary); + dVecWrite(VP, fp, binary); + dVecWrite(TP, fp, binary); + dVecWrite(SL, fp, binary); + dVecWrite(VL, fp, binary); + dVecWrite(TL, fp, binary); + dVecWrite(ST, fp, binary); + dVecWrite(VT, fp, binary); + dVecWrite(TT, fp, binary); + dVecWrite(SQ, fp, binary); + dVecWrite(VQ, fp, binary); + dVecWrite(TQ, fp, binary); + dVecWrite(SS, fp, binary); + dVecWrite(VS, fp, binary); + dVecWrite(TS, fp, binary); + dVecWrite(SH, fp, binary); + dVecWrite(VH, fp, binary); + dVecWrite(TH, fp, binary); + dVecWrite(SI, fp, binary); + dVecWrite(VI, fp, binary); + dVecWrite(TI, fp, binary); + dVecWrite(SY, fp, binary); + dVecWrite(VY, fp, binary); + dVecWrite(TY, fp, binary); + dVecWrite(T2D, fp, binary); + cVecWrite(T2C, fp, binary); + dVecWrite(T3D, fp, binary); + cVecWrite(T3C, fp, binary); fprintf(fp, "\n"); fprintf(fp, "$EndView\n"); } - else{ + else { fprintf(fp, "View \"%s\" {\n", getName().c_str()); writeTimePOS(fp, Time); - writeElementPOS(fp, "SP", 1, NbSP, SP); writeElementPOS(fp, "VP", 1, NbVP, VP); - writeElementPOS(fp, "TP", 1, NbTP, TP); writeElementPOS(fp, "SL", 2, NbSL, SL); - writeElementPOS(fp, "VL", 2, NbVL, VL); writeElementPOS(fp, "TL", 2, NbTL, TL); - writeElementPOS(fp, "ST", 3, NbST, ST); writeElementPOS(fp, "VT", 3, NbVT, VT); - writeElementPOS(fp, "TT", 3, NbTT, TT); writeElementPOS(fp, "SQ", 4, NbSQ, SQ); - writeElementPOS(fp, "VQ", 4, NbVQ, VQ); writeElementPOS(fp, "TQ", 4, NbTQ, TQ); - writeElementPOS(fp, "SS", 4, NbSS, SS); writeElementPOS(fp, "VS", 4, NbVS, VS); - writeElementPOS(fp, "TS", 4, NbTS, TS); writeElementPOS(fp, "SH", 8, NbSH, SH); - writeElementPOS(fp, "VH", 8, NbVH, VH); writeElementPOS(fp, "TH", 8, NbTH, TH); - writeElementPOS(fp, "SI", 6, NbSI, SI); writeElementPOS(fp, "VI", 6, NbVI, VI); - writeElementPOS(fp, "TI", 6, NbTI, TI); writeElementPOS(fp, "SY", 5, NbSY, SY); - writeElementPOS(fp, "VY", 5, NbVY, VY); writeElementPOS(fp, "TY", 5, NbTY, TY); - writeTextPOS(fp, 4, NbT2, T2D, T2C); writeTextPOS(fp, 5, NbT3, T3D, T3C); + writeElementPOS(fp, "SP", 1, NbSP, SP); + writeElementPOS(fp, "VP", 1, NbVP, VP); + writeElementPOS(fp, "TP", 1, NbTP, TP); + writeElementPOS(fp, "SL", 2, NbSL, SL); + writeElementPOS(fp, "VL", 2, NbVL, VL); + writeElementPOS(fp, "TL", 2, NbTL, TL); + writeElementPOS(fp, "ST", 3, NbST, ST); + writeElementPOS(fp, "VT", 3, NbVT, VT); + writeElementPOS(fp, "TT", 3, NbTT, TT); + writeElementPOS(fp, "SQ", 4, NbSQ, SQ); + writeElementPOS(fp, "VQ", 4, NbVQ, VQ); + writeElementPOS(fp, "TQ", 4, NbTQ, TQ); + writeElementPOS(fp, "SS", 4, NbSS, SS); + writeElementPOS(fp, "VS", 4, NbVS, VS); + writeElementPOS(fp, "TS", 4, NbTS, TS); + writeElementPOS(fp, "SH", 8, NbSH, SH); + writeElementPOS(fp, "VH", 8, NbVH, VH); + writeElementPOS(fp, "TH", 8, NbTH, TH); + writeElementPOS(fp, "SI", 6, NbSI, SI); + writeElementPOS(fp, "VI", 6, NbVI, VI); + writeElementPOS(fp, "TI", 6, NbTI, TI); + writeElementPOS(fp, "SY", 5, NbSY, SY); + writeElementPOS(fp, "VY", 5, NbVY, VY); + writeElementPOS(fp, "TY", 5, NbTY, TY); + writeTextPOS(fp, 4, NbT2, T2D, T2C); + writeTextPOS(fp, 5, NbT3, T3D, T3C); fprintf(fp, "};\n"); } @@ -438,11 +525,11 @@ bool PViewDataList::writePOS(const std::string &fileName, bool binary, bool pars } static void createVertices(std::vector<double> &list, int nbelm, int nbnod, - std::vector<MVertex*> &nodes) + std::vector<MVertex *> &nodes) { if(!nbelm) return; int nb = list.size() / nbelm; - for(unsigned int i = 0; i < list.size(); i += nb){ + for(unsigned int i = 0; i < list.size(); i += nb) { double *x = &list[i]; double *y = &list[i + nbnod]; double *z = &list[i + 2 * nbnod]; @@ -451,87 +538,88 @@ static void createVertices(std::vector<double> &list, int nbelm, int nbnod, } } -class nodeData{ +class nodeData { public: int nbnod; int nod; double *data; - nodeData() - : nbnod(0), nod(0), data(0) {} + nodeData() : nbnod(0), nod(0), data(0) {} nodeData(int _nbnod, int _nod, double *_data) - : nbnod(_nbnod), nod(_nod), data(_data) {} + : nbnod(_nbnod), nod(_nod), data(_data) + { + } }; static void createElements(std::vector<double> &list, int nbelm, int nbnod, - MVertexRTree &pos, std::vector<MElement*> &elements, - int type, std::map<MVertex*, nodeData> *vertexData) + MVertexRTree &pos, std::vector<MElement *> &elements, + int type, std::map<MVertex *, nodeData> *vertexData) { if(!nbelm) return; int t = 0; // reverse-engineer geometrical element type according to the number // of nodes (this should be completed, but is likely enough for most // legacy .pos files out there...) - switch(type){ - case TYPE_PNT : t = MSH_PNT; break; - case TYPE_LIN : - switch(nbnod){ + switch(type) { + case TYPE_PNT: t = MSH_PNT; break; + case TYPE_LIN: + switch(nbnod) { case 2: t = MSH_LIN_2; break; case 3: t = MSH_LIN_3; break; } break; - case TYPE_TRI : - switch(nbnod){ + case TYPE_TRI: + switch(nbnod) { case 3: t = MSH_TRI_3; break; case 6: t = MSH_TRI_6; break; } break; - case TYPE_QUA : - switch(nbnod){ + case TYPE_QUA: + switch(nbnod) { case 4: t = MSH_QUA_4; break; case 8: t = MSH_QUA_8; break; case 9: t = MSH_QUA_9; break; } break; - case TYPE_TET : - switch(nbnod){ + case TYPE_TET: + switch(nbnod) { case 4: t = MSH_TET_4; break; case 10: t = MSH_TET_10; break; } break; - case TYPE_HEX : - switch(nbnod){ + case TYPE_HEX: + switch(nbnod) { case 8: t = MSH_HEX_8; break; case 20: t = MSH_HEX_20; break; case 27: t = MSH_HEX_27; break; } break; - case TYPE_PRI : - switch(nbnod){ + case TYPE_PRI: + switch(nbnod) { case 6: t = MSH_PRI_6; break; case 15: t = MSH_PRI_15; break; case 18: t = MSH_PRI_18; break; } break; - case TYPE_PYR : - switch(nbnod){ + case TYPE_PYR: + switch(nbnod) { case 5: t = MSH_PYR_5; break; case 13: t = MSH_PYR_13; break; case 14: t = MSH_PYR_14; break; } break; } - if(!t){ + if(!t) { Msg::Warning("Discarding elements of type (%d nodes)", nbnod); return; } MElementFactory factory; int nb = list.size() / nbelm; - for(unsigned int i = 0; i < list.size(); i += nb){ + for(unsigned int i = 0; i < list.size(); i += nb) { double *x = &list[i]; double *y = &list[i + nbnod]; double *z = &list[i + 2 * nbnod]; - std::vector<MVertex*> verts(nbnod); - for(int j = 0; j < nbnod; j++){ + std::vector<MVertex *> verts(nbnod); + for(int j = 0; j < nbnod; j++) { verts[j] = pos.find(x[j], y[j], z[j]); if(vertexData) (*vertexData)[verts[j]] = nodeData(nbnod, j, &list[i + 3 * nbnod]); @@ -541,18 +629,19 @@ static void createElements(std::vector<double> &list, int nbelm, int nbnod, } } -bool PViewDataList::writeMSH(const std::string &fileName, double version, bool binary, - bool saveMesh, bool multipleView, +bool PViewDataList::writeMSH(const std::string &fileName, double version, + bool binary, bool saveMesh, bool multipleView, int partitionNum, bool saveInterpolationMatrices, bool forceNodeData, bool forceElementData) { - if(_adaptive){ - Msg::Warning("Writing adapted dataset (will only export current time step)"); + if(_adaptive) { + Msg::Warning( + "Writing adapted dataset (will only export current time step)"); return _adaptive->getData()->writeMSH(fileName, version, binary); } FILE *fp = Fopen(fileName.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } @@ -560,11 +649,11 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b double tol = CTX::instance()->geom.tolerance; double eps = norm(SVector3(BBox.max(), BBox.min())) * tol; - std::vector<MVertex*> vertices; - std::vector<MElement*> elements; + std::vector<MVertex *> vertices; + std::vector<MElement *> elements; int numComponents = 9; - for(int i = 0; i < 24; i++){ + for(int i = 0; i < 24; i++) { std::vector<double> *list = 0; int *numEle = 0, numNodes, numComp; _getRawData(i, &list, &numEle, &numComp, &numNodes); @@ -572,16 +661,15 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b createVertices(*list, *numEle, numNodes, vertices); } MVertexRTree pos(eps); - std::vector<MVertex*> unique; - for(unsigned int i = 0; i < vertices.size(); i++){ - if(!pos.insert(vertices[i])) - unique.push_back(vertices[i]); + std::vector<MVertex *> unique; + for(unsigned int i = 0; i < vertices.size(); i++) { + if(!pos.insert(vertices[i])) unique.push_back(vertices[i]); } vertices.clear(); std::map<MVertex *, nodeData> vertexData; - for(int i = 0; i < 24; i++){ + for(int i = 0; i < 24; i++) { std::vector<double> *list = 0; int *numEle = 0, numComp, numNodes; int typ = _getRawData(i, &list, &numEle, &numComp, &numNodes); @@ -590,23 +678,23 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b } int num = 0; - for(unsigned int i = 0; i < unique.size(); i++) - unique[i]->setIndex(++num); + for(unsigned int i = 0; i < unique.size(); i++) unique[i]->setIndex(++num); fprintf(fp, "$MeshFormat\n2.2 0 8\n$EndMeshFormat\n"); - if(saveMesh){ + if(saveMesh) { fprintf(fp, "$Nodes\n"); fprintf(fp, "%d\n", (int)unique.size()); - for(unsigned int i = 0; i < unique.size(); i++){ + for(unsigned int i = 0; i < unique.size(); i++) { MVertex *v = unique[i]; - fprintf(fp, "%d %.16g %.16g %.16g\n", v->getIndex(), v->x(), v->y(), v->z()); + fprintf(fp, "%d %.16g %.16g %.16g\n", v->getIndex(), v->x(), v->y(), + v->z()); } fprintf(fp, "$EndNodes\n"); fprintf(fp, "$Elements\n"); fprintf(fp, "%d\n", (int)elements.size()); - for(unsigned int i = 0; i < elements.size(); i++){ + for(unsigned int i = 0; i < elements.size(); i++) { if(version > 2.2) Msg::Warning("Unable to write file in version '%g': using version 2.2", version); @@ -616,18 +704,18 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b } if(saveInterpolationMatrices && haveInterpolationMatrices() && - !forceNodeData && !forceElementData){ + !forceNodeData && !forceElementData) { fprintf(fp, "$InterpolationScheme\n"); fprintf(fp, "\"INTERPOLATION_SCHEME\"\n"); fprintf(fp, "%d\n", (int)_interpolation.size()); for(interpolationMatrices::iterator it = _interpolation.begin(); - it != _interpolation.end(); it++){ - if(it->second.size() >= 2){ + it != _interpolation.end(); it++) { + if(it->second.size() >= 2) { fprintf(fp, "%d\n2\n", it->first); - for(int mat = 0; mat < 2; mat++){ + for(int mat = 0; mat < 2; mat++) { int m = it->second[mat]->size1(), n = it->second[mat]->size2(); fprintf(fp, "%d %d\n", m, n); - for(int i = 0; i < m; i++){ + for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) fprintf(fp, "%.16g ", it->second[mat]->get(i, j)); fprintf(fp, "\n"); @@ -638,7 +726,7 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b fprintf(fp, "$EndInterpolationScheme\n"); } - for(int ts = 0; ts < NbTimeStep; ts++){ + for(int ts = 0; ts < NbTimeStep; ts++) { if(forceNodeData) fprintf(fp, "$NodeData\n"); else if(forceElementData) @@ -653,13 +741,12 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b fprintf(fp, "1\n%.16g\n", getTime(ts)); int size = forceNodeData ? (int)unique.size() : (int)elements.size(); if(partitionNum) - fprintf(fp, "4\n%d\n%d\n%d\n%d\n", ts, numComponents, size, - partitionNum); + fprintf(fp, "4\n%d\n%d\n%d\n%d\n", ts, numComponents, size, partitionNum); else fprintf(fp, "3\n%d\n%d\n%d\n", ts, numComponents, size); - if(forceNodeData){ - for(unsigned int i = 0; i < unique.size(); i++){ + if(forceNodeData) { + for(unsigned int i = 0; i < unique.size(); i++) { MVertex *v = unique[i]; fprintf(fp, "%d", v->getIndex()); int nbnod = vertexData[v].nbnod; @@ -672,25 +759,24 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b } fprintf(fp, "$EndNodeData\n"); } - else{ + else { int n = 0; - for(int i = 0; i < 24; i++){ + for(int i = 0; i < 24; i++) { std::vector<double> *list = 0; int *numEle = 0, numComp, numNodes; int typ = _getRawData(i, &list, &numEle, &numComp, &numNodes); - if(*numEle){ + if(*numEle) { int mult = numNodes; - if(_interpolation.count(typ)) - mult = _interpolation[typ][0]->size1(); + if(_interpolation.count(typ)) mult = _interpolation[typ][0]->size1(); int nb = list->size() / *numEle; - for(unsigned int i = 0; i < list->size(); i += nb){ + for(unsigned int i = 0; i < list->size(); i += nb) { double *v = &(*list)[i + 3 * numNodes]; - if(forceElementData){ // just keep first vertex value + if(forceElementData) { // just keep first vertex value fprintf(fp, "%d", ++n); for(int j = 0; j < numComponents; j++) fprintf(fp, " %.16g", v[numComponents * mult * ts + j]); } - else{ + else { fprintf(fp, "%d %d", ++n, mult); for(int j = 0; j < numComponents * mult; j++) fprintf(fp, " %.16g", v[numComponents * mult * ts + j]); @@ -704,7 +790,6 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b else fprintf(fp, "$EndElementNodeData\n"); } - } fclose(fp); @@ -713,7 +798,7 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b void PViewDataList::importLists(int N[24], std::vector<double> *V[24]) { - for(int i = 0; i < 24; i++){ + for(int i = 0; i < 24; i++) { std::vector<double> *list = 0; int *nbe = 0, nbc, nbn; _getRawData(i, &list, &nbe, &nbc, &nbn); @@ -726,7 +811,7 @@ void PViewDataList::importLists(int N[24], std::vector<double> *V[24]) void PViewDataList::importList(int index, int n, const std::vector<double> &v, bool fin) { - if(index < 0 || index >= 24){ + if(index < 0 || index >= 24) { Msg::Error("Wrong list index to import"); return; } @@ -740,7 +825,7 @@ void PViewDataList::importList(int index, int n, const std::vector<double> &v, void PViewDataList::getListPointers(int N[24], std::vector<double> *V[24]) { - for(int i = 0; i < 24; i++){ + for(int i = 0; i < 24; i++) { std::vector<double> *list = 0; int *nbe = 0, nbc, nbn; _getRawData(i, &list, &nbe, &nbc, &nbn); diff --git a/Post/PViewDataRemote.h b/Post/PViewDataRemote.h index 2367a064e6c2f3b7aa76522b5dc4beb3dd07aadf..e9d76928ba2dc574e5fbfe69c2de0eac7677f7ea 100644 --- a/Post/PViewDataRemote.h +++ b/Post/PViewDataRemote.h @@ -16,40 +16,50 @@ // The container for a remote dataset (does not contain any actual // data) class PViewDataRemote : public PViewData { - private: +private: onelab::localNetworkClient *_remote; double _min, _max; int _numTimeSteps; double _time; SBoundingBox3d _bbox; - public: + +public: PViewDataRemote(onelab::localNetworkClient *remote, double min, double max, int numsteps, double time, SBoundingBox3d &bbox) : _remote(remote), _min(min), _max(max), _numTimeSteps(numsteps), - _time(time), _bbox(bbox) {} - ~PViewDataRemote(){} - bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="") + _time(time), _bbox(bbox) + { + } + ~PViewDataRemote() {} + bool finalize(bool computeMinMax = true, + const std::string &interpolationScheme = "") { return true; } - int getNumTimeSteps(){ return _numTimeSteps; } - double getMin(int step=-1, bool onlyVisible=false, int forceNumComponents=0, - int componentMap[9]=0){ return _min; } - double getMax(int step=-1, bool onlyVisible=false, int forceNumComponents=0, - int componentMap[9]=0){ return _max; } - SBoundingBox3d getBoundingBox(int step=-1){ return _bbox; } - double getTime(int step){ return _time; } + int getNumTimeSteps() { return _numTimeSteps; } + double getMin(int step = -1, bool onlyVisible = false, + int forceNumComponents = 0, int componentMap[9] = 0) + { + return _min; + } + double getMax(int step = -1, bool onlyVisible = false, + int forceNumComponents = 0, int componentMap[9] = 0) + { + return _max; + } + SBoundingBox3d getBoundingBox(int step = -1) { return _bbox; } + double getTime(int step) { return _time; } // need to return != 0 for "empty" tests - int getNumElements(int step=-1, int ent=-1){ return -1; } - void setMin(double min){ _min = min; } - void setMax(double max){ _max = max; } - void setBoundingBox(SBoundingBox3d &bbox){ _bbox = bbox; } - void setTime(double time){ _time = time; } - bool isRemote(){ return true; } + int getNumElements(int step = -1, int ent = -1) { return -1; } + void setMin(double min) { _min = min; } + void setMax(double max) { _max = max; } + void setBoundingBox(SBoundingBox3d &bbox) { _bbox = bbox; } + void setTime(double time) { _time = time; } + bool isRemote() { return true; } int fillRemoteVertexArrays(std::string &options) { GmshServer *server = _remote->getGmshServer(); - if(!server){ + if(!server) { Msg::Error("Remote server not running: please start server"); return 1; } diff --git a/Post/PViewFactory.cpp b/Post/PViewFactory.cpp index 2dee440d32fd7545aed681ed0ca80da40781dee2..cda018a669df485b93a6efb3f7d1c9faff2c38d4 100644 --- a/Post/PViewFactory.cpp +++ b/Post/PViewFactory.cpp @@ -9,26 +9,25 @@ #include "PView.h" #include <vector> -PViewFactory::PViewFactory (std::string name, std::string type, GModel *model, - int timeStep, int dim) +PViewFactory::PViewFactory(std::string name, std::string type, GModel *model, + int timeStep, int dim) : _name(name), _type(type), _dim(dim), _timeStep(timeStep), _model(model) { } -void PViewFactory::setEntry (int id, const fullMatrix<double> &val) +void PViewFactory::setEntry(int id, const fullMatrix<double> &val) { std::vector<double> &vv = _values[id]; - vv.resize(val.size1()*val.size2()); - int k=0; - for (int i=0;i<val.size1(); i++) { - for (int j=0;j<val.size2(); j++) { - vv[k++] = val(i,j); + vv.resize(val.size1() * val.size2()); + int k = 0; + for(int i = 0; i < val.size1(); i++) { + for(int j = 0; j < val.size2(); j++) { + vv[k++] = val(i, j); } } } -PView *PViewFactory::createView () +PView *PViewFactory::createView() { - return new PView(_name,_type,_model,_values,_timeStep,_dim); + return new PView(_name, _type, _model, _values, _timeStep, _dim); } - diff --git a/Post/PViewFactory.h b/Post/PViewFactory.h index 2e0e8eff7db1709c5cefc1cb930a58f14a8f2f69..ea012f395fe8004590dc9ff5b12652452bd8005d 100644 --- a/Post/PViewFactory.h +++ b/Post/PViewFactory.h @@ -9,22 +9,23 @@ // quick hack to have something that we can bind for the summer // school... this class has probably to be removed or rewritten -#include<map> -#include<vector> -#include<string> +#include <map> +#include <vector> +#include <string> class GModel; class PView; template <class t> class fullMatrix; class PViewFactory { - std::map<int,std::vector<double> > _values; + std::map<int, std::vector<double> > _values; std::string _name, _type; int _dim, _timeStep; GModel *_model; - public: + +public: PViewFactory(std::string name, std::string type, GModel *model, int timeStep, - int dim=3); + int dim = 3); void setEntry(int id, const fullMatrix<double> &val); PView *createView(); }; diff --git a/Post/PViewIO.cpp b/Post/PViewIO.cpp index dd65aee21283f4b4eef9a9114573318678953dc4..c8cc4830951ef0e0653087a386423f79b735e32f 100644 --- a/Post/PViewIO.cpp +++ b/Post/PViewIO.cpp @@ -19,7 +19,7 @@ bool PView::readPOS(const std::string &fileName, int fileIndex) { FILE *fp = Fopen(fileName.c_str(), "rb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } @@ -29,18 +29,14 @@ bool PView::readPOS(const std::string &fileName, int fileIndex) int format = -1, size = -1, index = -1; while(1) { - - while(str[0] != '$'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(str[0] != '$') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } - if(feof(fp)) - break; + if(feof(fp)) break; if(!strncmp(&str[1], "PostFormat", 10)) { - - if(!fscanf(fp, "%lf %d %d\n", &version, &format, &size)){ + if(!fscanf(fp, "%lf %d %d\n", &version, &format, &size)) { Msg::Error("Read error"); fclose(fp); return false; @@ -57,32 +53,28 @@ bool PView::readPOS(const std::string &fileName, int fileIndex) fclose(fp); return false; } - } - else if(!strncmp(&str[1], "View", 4)){ + else if(!strncmp(&str[1], "View", 4)) { index++; - if(fileIndex < 0 || fileIndex == index){ + if(fileIndex < 0 || fileIndex == index) { PViewDataList *d = new PViewDataList(); - if(!d->readPOS(fp, version, format ? true : false)){ + if(!d->readPOS(fp, version, format ? true : false)) { Msg::Error("Could not read data in list format"); delete d; fclose(fp); return false; } - else{ + else { d->setFileName(fileName); d->setFileIndex(index); new PView(d); } } - } do { - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } while(str[0] != '$'); - } fclose(fp); @@ -92,13 +84,13 @@ bool PView::readPOS(const std::string &fileName, int fileIndex) bool PView::readMSH(const std::string &fileName, int fileIndex) { FILE *fp = Fopen(fileName.c_str(), "rb"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } GModel *model = GModel::current(); - if(model->empty()){ + if(model->empty()) { Msg::Error("Model is empty: please load a mesh before loading the dataset"); fclose(fp); return false; @@ -109,53 +101,71 @@ bool PView::readMSH(const std::string &fileName, int fileIndex) bool binary = false, swap = false; while(1) { - - while(str[0] != '$'){ - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + while(str[0] != '$') { + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } - if(feof(fp)) - break; + if(feof(fp)) break; if(!strncmp(&str[1], "MeshFormat", 10)) { double version; - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return false; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return false; + } int format, size; - if(sscanf(str, "%lf %d %d", &version, &format, &size) != 3){ + if(sscanf(str, "%lf %d %d", &version, &format, &size) != 3) { fclose(fp); return false; } - if(format){ + if(format) { binary = true; Msg::Debug("View data is in binary format"); int one; - if(fread(&one, sizeof(int), 1, fp) != 1){ fclose(fp); return 0; } - if(one != 1){ + if(fread(&one, sizeof(int), 1, fp) != 1) { + fclose(fp); + return 0; + } + if(one != 1) { swap = true; Msg::Debug("Swapping bytes from binary file"); } } } - else if(!strncmp(&str[1], "InterpolationScheme", 19)){ + else if(!strncmp(&str[1], "InterpolationScheme", 19)) { std::string name; - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return false; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return false; + } name = ExtractDoubleQuotedString(str, sizeof(str)); Msg::Debug("Reading interpolation scheme '%s'", name.c_str()); PViewData::removeInterpolationScheme(name); int numTypes; - if(fscanf(fp, "%d", &numTypes) != 1){ fclose(fp); return false; } - for(int i = 0; i < numTypes; i++){ + if(fscanf(fp, "%d", &numTypes) != 1) { + fclose(fp); + return false; + } + for(int i = 0; i < numTypes; i++) { int type, numMatrices; - if(fscanf(fp, "%d %d", &type, &numMatrices) != 2){ fclose(fp); return false; } - for(int j = 0; j < numMatrices; j++){ + if(fscanf(fp, "%d %d", &type, &numMatrices) != 2) { + fclose(fp); + return false; + } + for(int j = 0; j < numMatrices; j++) { int m, n; - if(fscanf(fp, "%d %d", &m, &n) != 2){ fclose(fp); return false; } + if(fscanf(fp, "%d %d", &m, &n) != 2) { + fclose(fp); + return false; + } fullMatrix<double> mat(m, n); - for(int k = 0; k < m; k++){ - for(int l = 0; l < n; l++){ + for(int k = 0; k < m; k++) { + for(int l = 0; l < n; l++) { double d; - if(fscanf(fp, "%lf", &d) != 1){ fclose(fp); return false; } + if(fscanf(fp, "%lf", &d) != 1) { + fclose(fp); + return false; + } mat.set(k, l, d); } } @@ -167,7 +177,7 @@ bool PView::readMSH(const std::string &fileName, int fileIndex) !strncmp(&str[1], "ElementData", 11) || !strncmp(&str[1], "ElementNodeData", 15)) { index++; - if(fileIndex < 0 || fileIndex == index){ + if(fileIndex < 0 || fileIndex == index) { PViewDataGModel::DataType type; if(!strncmp(&str[1], "NodeData", 8)) type = PViewDataGModel::NodeData; @@ -178,10 +188,19 @@ bool PView::readMSH(const std::string &fileName, int fileIndex) int numTags; // string tags std::string viewName, interpolationScheme; - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return false; } - if(sscanf(str, "%d", &numTags) != 1){ fclose(fp); return false; } - for(int i = 0; i < numTags; i++){ - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return false; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return false; + } + if(sscanf(str, "%d", &numTags) != 1) { + fclose(fp); + return false; + } + for(int i = 0; i < numTags; i++) { + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return false; + } if(i == 0) viewName = ExtractDoubleQuotedString(str, sizeof(str)); else if(i == 1) @@ -189,47 +208,81 @@ bool PView::readMSH(const std::string &fileName, int fileIndex) } // double tags double time = 0.; - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return false; } - if(sscanf(str, "%d", &numTags) != 1){ fclose(fp); return false; } - for(int i = 0; i < numTags; i++){ - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return false; } - if(i == 0){ - if(sscanf(str, "%lf", &time) != 1){ fclose(fp); return false; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return false; + } + if(sscanf(str, "%d", &numTags) != 1) { + fclose(fp); + return false; + } + for(int i = 0; i < numTags; i++) { + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return false; + } + if(i == 0) { + if(sscanf(str, "%lf", &time) != 1) { + fclose(fp); + return false; + } } } // integer tags int timeStep = 0, numComp = 0, numEnt = 0, partition = 0; - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return false; } - if(sscanf(str, "%d", &numTags) != 1){ fclose(fp); return false; } - for(int i = 0; i < numTags; i++){ - if(!fgets(str, sizeof(str), fp)){ fclose(fp); return false; } - if(i == 0){ - if(sscanf(str, "%d", &timeStep) != 1){ fclose(fp); return false; } + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return false; + } + if(sscanf(str, "%d", &numTags) != 1) { + fclose(fp); + return false; + } + for(int i = 0; i < numTags; i++) { + if(!fgets(str, sizeof(str), fp)) { + fclose(fp); + return false; + } + if(i == 0) { + if(sscanf(str, "%d", &timeStep) != 1) { + fclose(fp); + return false; + } } - else if(i == 1){ - if(sscanf(str, "%d", &numComp) != 1){ fclose(fp); return false; } + else if(i == 1) { + if(sscanf(str, "%d", &numComp) != 1) { + fclose(fp); + return false; + } } - else if(i == 2){ - if(sscanf(str, "%d", &numEnt) != 1){ fclose(fp); return false; } + else if(i == 2) { + if(sscanf(str, "%d", &numEnt) != 1) { + fclose(fp); + return false; + } } - else if(i == 3){ - if(sscanf(str, "%d", &partition) != 1){ fclose(fp); return false; } + else if(i == 3) { + if(sscanf(str, "%d", &partition) != 1) { + fclose(fp); + return false; + } } } // either get existing viewData, or create new one PView *p = getViewByName(viewName, timeStep, partition); PViewDataGModel *d = 0; - if(p) d = dynamic_cast<PViewDataGModel*>(p->getData()); + if(p) d = dynamic_cast<PViewDataGModel *>(p->getData()); bool create = d ? false : true; if(create) d = new PViewDataGModel(type); - if(!d->readMSH(viewName, fileName, fileIndex, fp, binary, swap, timeStep, - time, partition, numComp, numEnt, interpolationScheme)){ + if(!d->readMSH(viewName, fileName, fileIndex, fp, binary, swap, + timeStep, time, partition, numComp, numEnt, + interpolationScheme)) { Msg::Error("Could not read data in msh file"); if(create) delete d; fclose(fp); return false; } - else{ + else { d->setName(viewName); d->setFileName(fileName); d->setFileIndex(index); @@ -239,8 +292,7 @@ bool PView::readMSH(const std::string &fileName, int fileIndex) } do { - if(!fgets(str, sizeof(str), fp) || feof(fp)) - break; + if(!fgets(str, sizeof(str), fp) || feof(fp)) break; } while(str[0] != '$'); } @@ -256,21 +308,21 @@ bool PView::readMED(const std::string &fileName, int fileIndex) { std::vector<std::string> fieldNames = medGetFieldNames(fileName); - for(unsigned int index = 0; index < fieldNames.size(); index++){ - if(fileIndex < 0 || (int)index == fileIndex){ + for(unsigned int index = 0; index < fieldNames.size(); index++) { + if(fileIndex < 0 || (int)index == fileIndex) { PViewDataGModel *d = 0; // we use the filename as a kind of "partition" indicator, allowing to // complete datasets provided in separate files (e.g. coming from DDM) PView *p = getViewByName(fieldNames[index], -1, -1, fileName); - if(p) d = dynamic_cast<PViewDataGModel*>(p->getData()); + if(p) d = dynamic_cast<PViewDataGModel *>(p->getData()); bool create = d ? false : true; if(create) d = new PViewDataGModel(); - if(!d->readMED(fileName, index)){ + if(!d->readMED(fileName, index)) { Msg::Error("Could not read data in MED file"); if(create) delete d; return false; } - else{ + else { if(create) new PView(d); } } @@ -295,41 +347,51 @@ bool PView::write(const std::string &fileName, int format, bool append) Msg::StatusBar(true, "Writing '%s'...", fileName.c_str()); bool ret; - switch(format){ - case 0: ret = _data->writePOS(fileName, false, false, append); break; // ASCII - case 1: ret = _data->writePOS(fileName, true, false, append); break; // binary - case 2: ret = _data->writePOS(fileName, false, true, append); break; // parsed + switch(format) { + case 0: + ret = _data->writePOS(fileName, false, false, append); + break; // ASCII + case 1: + ret = _data->writePOS(fileName, true, false, append); + break; // binary + case 2: + ret = _data->writePOS(fileName, false, true, append); + break; // parsed case 3: ret = _data->writeSTL(fileName); break; case 4: ret = _data->writeTXT(fileName); break; - case 5: ret = _data->writeMSH(fileName, CTX::instance()->mesh.mshFileVersion, - CTX::instance()->mesh.binary, - CTX::instance()->post.saveMesh, append, 0, - CTX::instance()->post.saveInterpolationMatrices, - CTX::instance()->post.forceNodeData, - CTX::instance()->post.forceElementData); break; + case 5: + ret = _data->writeMSH(fileName, CTX::instance()->mesh.mshFileVersion, + CTX::instance()->mesh.binary, + CTX::instance()->post.saveMesh, append, 0, + CTX::instance()->post.saveInterpolationMatrices, + CTX::instance()->post.forceNodeData, + CTX::instance()->post.forceElementData); + break; case 6: ret = _data->writeMED(fileName); break; case 7: ret = writeX3D(fileName); break; - case 10: - { - std::string ext = SplitFileName(fileName)[2]; - if(ext == ".pos") - ret = _data->writePOS(fileName, false, true, append); - else if(ext == ".stl") - ret = _data->writeSTL(fileName); - else if(ext == ".msh") - ret = _data->writeMSH(fileName, CTX::instance()->mesh.mshFileVersion, - CTX::instance()->mesh.binary, - CTX::instance()->post.saveMesh, append, 0, - CTX::instance()->post.saveInterpolationMatrices, - CTX::instance()->post.forceNodeData, - CTX::instance()->post.forceElementData); - else if(ext == ".med") - ret = _data->writeMED(fileName); - else - ret = _data->writeTXT(fileName); - break; - } - default: ret = false; Msg::Error("Unknown view format %d", format); break; + case 10: { + std::string ext = SplitFileName(fileName)[2]; + if(ext == ".pos") + ret = _data->writePOS(fileName, false, true, append); + else if(ext == ".stl") + ret = _data->writeSTL(fileName); + else if(ext == ".msh") + ret = _data->writeMSH(fileName, CTX::instance()->mesh.mshFileVersion, + CTX::instance()->mesh.binary, + CTX::instance()->post.saveMesh, append, 0, + CTX::instance()->post.saveInterpolationMatrices, + CTX::instance()->post.forceNodeData, + CTX::instance()->post.forceElementData); + else if(ext == ".med") + ret = _data->writeMED(fileName); + else + ret = _data->writeTXT(fileName); + break; + } + default: + ret = false; + Msg::Error("Unknown view format %d", format); + break; } if(ret) Msg::StatusBar(true, "Done writing '%s'", fileName.c_str()); diff --git a/Post/PViewOptions.cpp b/Post/PViewOptions.cpp index d7871c057f25be08bc7b1049ad8de4073f536455..abb76bbacdd06e505aa9c7b99ccdb34420115632 100644 --- a/Post/PViewOptions.cpp +++ b/Post/PViewOptions.cpp @@ -34,24 +34,29 @@ double PViewOptions::getScaleValue(int iso, int numIso, double min, double max) { if(numIso == 1) return (min + max) / 2.; - if(scaleType == Linear){ + if(scaleType == Linear) { // treat min/max separately to avoid numerical errors (important // not to miss first/last discrete iso on piece-wise constant // datasets) - if(iso == 0) return min; - else if(iso == numIso - 1) return max; - else return min + iso * (max - min) / (numIso - 1.); + if(iso == 0) + return min; + else if(iso == numIso - 1) + return max; + else + return min + iso * (max - min) / (numIso - 1.); } - else if(scaleType == Logarithmic){ + else if(scaleType == Logarithmic) { // should translate scale instead, with smallest val an option! if(min <= 0.) return 0; - return pow(10., log10(min) + iso * (log10(max) - log10(min)) / (numIso - 1.)); + return pow(10., + log10(min) + iso * (log10(max) - log10(min)) / (numIso - 1.)); } - else if(scaleType == DoubleLogarithmic){ + else if(scaleType == DoubleLogarithmic) { if(min <= 0.) return 0; double iso2 = iso / 2.; double numIso2 = numIso / 2.; - return pow(10., log10(min) + iso2 * (log10(max) - log10(min)) / (numIso2 - 1.)); + return pow(10., + log10(min) + iso2 * (log10(max) - log10(min)) / (numIso2 - 1.)); } return 0.; } @@ -61,17 +66,19 @@ int PViewOptions::getScaleIndex(double val, int numIso, double min, double max, { if(min == max) return numIso / 2; - if(forceLinear || scaleType == Linear){ + if(forceLinear || scaleType == Linear) { return (int)((val - min) * (numIso - 1) / (max - min)); } - else if(scaleType == Logarithmic){ + else if(scaleType == Logarithmic) { if(min <= 0.) return 0; - return (int)((log10(val) - log10(min)) * (numIso - 1) / (log10(max) - log10(min))); + return (int)((log10(val) - log10(min)) * (numIso - 1) / + (log10(max) - log10(min))); } - else if(scaleType == DoubleLogarithmic){ + else if(scaleType == DoubleLogarithmic) { // FIXME if(min <= 0.) return 0; - return (int)((log10(val) - log10(min)) * (numIso - 1) / (log10(max) - log10(min))); + return (int)((log10(val) - log10(min)) * (numIso - 1) / + (log10(max) - log10(min))); } return 0; } @@ -81,13 +88,15 @@ unsigned int PViewOptions::getColor(double val, double min, double max, { if(colorTable.size == 1) return colorTable.table[0]; - if(numColors <= 0){ // use full colormap + if(numColors <= 0) { // use full colormap int index = getScaleIndex(val, colorTable.size, min, max, forceLinear); - if(index < 0) index = 0; - else if(index > colorTable.size - 1) index = colorTable.size - 1; + if(index < 0) + index = 0; + else if(index > colorTable.size - 1) + index = colorTable.size - 1; return colorTable.table[index]; } - else{ + else { // the maximum should belong to the last interval: so use // numColors + 1 and correct afterwards int index = getScaleIndex(val, numColors + 1, min, max, forceLinear); @@ -98,18 +107,20 @@ unsigned int PViewOptions::getColor(double val, double min, double max, unsigned int PViewOptions::getColor(int i, int nb) { - int index = (nb == 1) ? colorTable.size / 2 : - (int)(i / (double)(nb - 1) * (colorTable.size - 1) + 0.5); - if(index < 0) index = 0; - else if(index > colorTable.size - 1) index = colorTable.size - 1; + int index = (nb == 1) ? + colorTable.size / 2 : + (int)(i / (double)(nb - 1) * (colorTable.size - 1) + 0.5); + if(index < 0) + index = 0; + else if(index > colorTable.size - 1) + index = colorTable.size - 1; return colorTable.table[index]; } void PViewOptions::createGeneralRaise() { - const char *names[] = - { "x", "y", "z", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", - "s", "t"}; + const char *names[] = {"x", "y", "z", "v0", "v1", "v2", "v3", + "v4", "v5", "v6", "v7", "v8", "s", "t"}; unsigned int numVariables = sizeof(names) / sizeof(names[0]); std::vector<std::string> expressions(3), variables(numVariables); expressions[0] = genRaiseX; @@ -119,7 +130,7 @@ void PViewOptions::createGeneralRaise() if(genRaiseEvaluator) delete genRaiseEvaluator; genRaiseEvaluator = new mathEvaluator(expressions, variables); - if(expressions.empty()){ + if(expressions.empty()) { delete genRaiseEvaluator; genRaiseEvaluator = 0; } @@ -127,7 +138,7 @@ void PViewOptions::createGeneralRaise() bool PViewOptions::skipElement(int type) { - switch(type){ + switch(type) { case TYPE_PNT: return !drawPoints; case TYPE_LIN: return !drawLines; case TYPE_TRI: return !drawTriangles; diff --git a/Post/PViewOptions.h b/Post/PViewOptions.h index b29b91b17fc6ced982424f67730f065e57396150..8f300eb772c0b84b0edc85c82bf35c5c6d0df7db 100644 --- a/Post/PViewOptions.h +++ b/Post/PViewOptions.h @@ -14,19 +14,9 @@ class mathEvaluator; // The display options of a post-processing view. class PViewOptions { - public: - enum PlotType { - Plot3D = 1, - Plot2DSpace = 2, - Plot2DTime = 3, - Plot2D = 4 - }; - enum IntervalsType { - Iso = 1, - Continuous = 2, - Discrete = 3, - Numeric = 4 - }; +public: + enum PlotType { Plot3D = 1, Plot2DSpace = 2, Plot2DTime = 3, Plot2D = 4 }; + enum IntervalsType { Iso = 1, Continuous = 2, Discrete = 3, Numeric = 4 }; enum VectorType { Segment = 1, Arrow = 2, @@ -43,20 +33,9 @@ class PViewOptions { Ellipsoid = 6, Frame = 7 }; - enum GlyphLocation { - COG = 1, - Vertex = 2 - }; - enum RangeType { - Default = 1, - Custom = 2, - PerTimeStep = 3 - }; - enum ScaleType { - Linear = 1, - Logarithmic = 2, - DoubleLogarithmic = 3 - }; + enum GlyphLocation { COG = 1, Vertex = 2 }; + enum RangeType { Default = 1, Custom = 2, PerTimeStep = 3 }; + enum ScaleType { Linear = 1, Logarithmic = 2, DoubleLogarithmic = 3 }; int type, autoPosition; double position[2], size[2]; @@ -83,7 +62,8 @@ class PViewOptions { double currentTime; int drawStrings; int drawPoints, drawLines, drawTriangles, drawQuadrangles, drawPolygons; - int drawTetrahedra, drawHexahedra, drawPrisms, drawPyramids, drawTrihedra, drawPolyhedra; + int drawTetrahedra, drawHexahedra, drawPrisms, drawPyramids, drawTrihedra, + drawPolyhedra; int drawScalars, drawVectors, drawTensors; int boundary, pointType, lineType, drawSkinOnly; double pointSize, lineWidth; @@ -102,16 +82,18 @@ class PViewOptions { int sampling; std::string attributes, doubleClickedCommand, group; int closed; - struct{ + struct { unsigned int point, line, triangle, quadrangle; unsigned int tetrahedron, hexahedron, prism, pyramid, trihedron; unsigned int tangents, normals; unsigned int text2d, text3d, axes, background2d; } color; - private: + +private: // static reference that contains default values static PViewOptions *_reference; - public: + +public: PViewOptions(); ~PViewOptions(); static PViewOptions *reference(); @@ -121,11 +103,11 @@ class PViewOptions { // return an integer in [0, numIso - 1] corresponding to the // floating point value val in [min, max] int getScaleIndex(double val, int numIso, double min, double max, - bool forceLinear=false); + bool forceLinear = false); // get color for val in [min, max] (only use numColors if > 0 // instead of all available colors) unsigned int getColor(double val, double min, double max, - bool forceLinear=false, int numColors=-1); + bool forceLinear = false, int numColors = -1); // get i-th color amongst nb (i in [0, nb - 1]) unsigned int getColor(int i, int nb); // create math evaluator for general raise option diff --git a/Post/PViewVertexArrays.cpp b/Post/PViewVertexArrays.cpp index 3fb5a1f62a6bd3337560537ff0f4926f31178d3c..757a1a6b86bbb10f042795e076d84f357bff7fcc 100644 --- a/Post/PViewVertexArrays.cpp +++ b/Post/PViewVertexArrays.cpp @@ -24,34 +24,34 @@ #include "Options.h" #include "StringUtils.h" -static void saturate(int nb, double **val, double vmin, double vmax, - int i0=0, int i1=1, int i2=2, int i3=3, - int i4=4, int i5=5, int i6=6, int i7=7) +static void saturate(int nb, double **val, double vmin, double vmax, int i0 = 0, + int i1 = 1, int i2 = 2, int i3 = 3, int i4 = 4, int i5 = 5, + int i6 = 6, int i7 = 7) { int id[8] = {i0, i1, i2, i3, i4, i5, i6, i7}; - for(int i = 0; i < nb; i++){ - if(val[id[i]][0] > vmax) val[id[i]][0] = vmax; - else if(val[id[i]][0] < vmin) val[id[i]][0] = vmin; + for(int i = 0; i < nb; i++) { + if(val[id[i]][0] > vmax) + val[id[i]][0] = vmax; + else if(val[id[i]][0] < vmin) + val[id[i]][0] = vmin; } } static double saturateVector(double *val, int numComp2, double *val2, double min, double max) { - double v = ComputeScalarRep(numComp2, val2); // v >= 0 - if (v < min && v > 1e-15) { + double v = ComputeScalarRep(numComp2, val2); // v >= 0 + if(v < min && v > 1e-15) { double f = min / v; - for (int iComp = 0; iComp < numComp2; ++iComp) - val2[iComp] *= f; + for(int iComp = 0; iComp < numComp2; ++iComp) val2[iComp] *= f; val[0] *= f; val[1] *= f; val[2] *= f; return min; } - if (v > max && v > 1e-15) { + if(v > max && v > 1e-15) { double f = max / v; - for (int iComp = 0; iComp < numComp2; ++iComp) - val2[iComp] *= f; + for(int iComp = 0; iComp < numComp2; ++iComp) val2[iComp] *= f; val[0] *= f; val[1] *= f; val[2] *= f; @@ -60,13 +60,11 @@ static double saturateVector(double *val, int numComp2, double *val2, return v; } -static SVector3 normal3(double **xyz, int i0=0, int i1=1, int i2=2) +static SVector3 normal3(double **xyz, int i0 = 0, int i1 = 1, int i2 = 2) { - SVector3 t1(xyz[i1][0] - xyz[i0][0], - xyz[i1][1] - xyz[i0][1], + SVector3 t1(xyz[i1][0] - xyz[i0][0], xyz[i1][1] - xyz[i0][1], xyz[i1][2] - xyz[i0][2]); - SVector3 t2(xyz[i2][0] - xyz[i0][0], - xyz[i2][1] - xyz[i0][1], + SVector3 t2(xyz[i2][0] - xyz[i0][0], xyz[i2][1] - xyz[i0][1], xyz[i2][2] - xyz[i0][2]); SVector3 n = crossprod(t1, t2); n.normalize(); @@ -77,7 +75,7 @@ static SVector3 getPointNormal(PView *p, double v) { PViewOptions *opt = p->getOptions(); SVector3 n(0., 0., 0.); - if(opt->pointType > 0){ + if(opt->pointType > 0) { // when we draw spheres, we use the normalized value (between 0 // and 1) stored in the first component of the normal to modulate // the radius @@ -92,8 +90,8 @@ static void getLineNormal(PView *p, double x[2], double y[2], double z[2], { PViewOptions *opt = p->getOptions(); - if(opt->lineType > 0){ - if(v){ + if(opt->lineType > 0) { + if(v) { // when we draw tapered cylinders, we use the normalized values // (between 0 and 1) stored in the first component of the // normals to modulate the width @@ -101,12 +99,12 @@ static void getLineNormal(PView *p, double x[2], double y[2], double z[2], n[0][0] = (v[0] - opt->tmpMin) / (d ? d : 1.); n[1][0] = (v[1] - opt->tmpMin) / (d ? d : 1.); } - else{ + else { // when we don't have values we use maximum width cylinders n[0][0] = n[1][0] = 1.; } } - else if(computeNormal){ + else if(computeNormal) { SBoundingBox3d bb = p->getData()->getBoundingBox(); if(bb.min().z() == bb.max().z()) n[0] = n[1] = SVector3(0., 0., 1.); @@ -114,7 +112,7 @@ static void getLineNormal(PView *p, double x[2], double y[2], double z[2], n[0] = n[1] = SVector3(0., 1., 0.); else if(bb.min().x() == bb.max().x()) n[0] = n[1] = SVector3(1., 0., 0.); - else{ + else { // we don't have any info about the normal, just pick one SVector3 t(x[1] - x[0], y[1] - y[0], z[1] - z[0]); SVector3 ex(0., 0., 0.); @@ -140,8 +138,7 @@ static bool getExternalValues(PView *p, int index, int ient, int iele, // use self by default numComp2 = numComp; for(int i = 0; i < numNodes; i++) - for(int j = 0; j < numComp; j++) - val2[i][j] = val[i][j]; + for(int j = 0; j < numComp; j++) val2[i][j] = val[i][j]; opt->externalMin = opt->tmpMin; opt->externalMax = opt->tmpMax; @@ -153,20 +150,20 @@ static bool getExternalValues(PView *p, int index, int ient, int iele, if(iele >= data2->getNumElements(opt->timeStep, ient)) return false; if(!data2->skipElement(opt->timeStep, ient, iele) && - data2->getNumNodes(opt->timeStep, ient, iele) == numNodes){ + data2->getNumNodes(opt->timeStep, ient, iele) == numNodes) { numComp2 = data2->getNumComponents(opt->timeStep, ient, iele); for(int i = 0; i < numNodes; i++) for(int j = 0; j < numComp2; j++) data2->getValue(opt->timeStep, ient, iele, i, j, val2[i][j]); - if(opt->rangeType == PViewOptions::Custom){ + if(opt->rangeType == PViewOptions::Custom) { opt->externalMin = opt->customMin; opt->externalMax = opt->customMax; } - else if(opt->rangeType == PViewOptions::PerTimeStep){ + else if(opt->rangeType == PViewOptions::PerTimeStep) { opt->externalMin = data2->getMin(opt->timeStep); opt->externalMax = data2->getMax(opt->timeStep); } - else{ + else { opt->externalMin = data2->getMin(); opt->externalMax = data2->getMax(); } @@ -188,24 +185,20 @@ static void applyGeneralRaise(PView *p, int numNodes, int numComp, values[12] = p->getOptions()->timeStep; values[13] = p->getOptions()->currentTime; if(opt->genRaiseEvaluator->eval(values, res)) - for(int i = 0; i < 3; i++) - xyz[k][i] += opt->genRaiseFactor * res[i]; + for(int i = 0; i < 3; i++) xyz[k][i] += opt->genRaiseFactor * res[i]; } } -void changeCoordinates(PView *p, int ient, int iele, - int numNodes, int type, int numComp, - double **xyz, double **val) +void changeCoordinates(PView *p, int ient, int iele, int numNodes, int type, + int numComp, double **xyz, double **val) { PViewOptions *opt = p->getOptions(); if(opt->explode != 1.) { double barycenter[3] = {0., 0., 0.}; for(int i = 0; i < numNodes; i++) - for(int j = 0; j < 3; j++) - barycenter[j] += xyz[i][j]; - for(int j = 0; j < 3; j++) - barycenter[j] /= (double)numNodes; + for(int j = 0; j < 3; j++) barycenter[j] += xyz[i][j]; + for(int j = 0; j < 3; j++) barycenter[j] /= (double)numNodes; for(int i = 0; i < numNodes; i++) for(int j = 0; j < 3; j++) xyz[i][j] = barycenter[j] + opt->explode * (xyz[i][j] - barycenter[j]); @@ -215,34 +208,32 @@ void changeCoordinates(PView *p, int ient, int iele, opt->transform[0][2] != 0. || opt->transform[1][0] != 0. || opt->transform[1][1] != 1. || opt->transform[1][2] != 0. || opt->transform[2][0] != 0. || opt->transform[2][1] != 0. || - opt->transform[2][2] != 1.){ + opt->transform[2][2] != 1.) { for(int i = 0; i < numNodes; i++) { double old[3] = {xyz[i][0], xyz[i][1], xyz[i][2]}; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { xyz[i][j] = 0.; - for(int k = 0; k < 3; k++) - xyz[i][j] += opt->transform[j][k] * old[k]; + for(int k = 0; k < 3; k++) xyz[i][j] += opt->transform[j][k] * old[k]; } } } - if(opt->offset[0] || opt->offset[1] || opt->offset[2]){ + if(opt->offset[0] || opt->offset[1] || opt->offset[2]) { for(int i = 0; i < numNodes; i++) - for(int j = 0; j < 3; j++) - xyz[i][j] += opt->offset[j]; + for(int j = 0; j < 3; j++) xyz[i][j] += opt->offset[j]; } - if(opt->raise[0] || opt->raise[1] || opt->raise[2]){ - for(int i = 0; i < numNodes; i++){ + if(opt->raise[0] || opt->raise[1] || opt->raise[2]) { + for(int i = 0; i < numNodes; i++) { double v = ComputeScalarRep(numComp, val[i]); - for(int j = 0; j < 3; j++) - xyz[i][j] += opt->raise[j] * v; + for(int j = 0; j < 3; j++) xyz[i][j] += opt->raise[j] * v; } } - if(opt->normalRaise && (type == TYPE_LIN || type == TYPE_TRI || type ==TYPE_QUA)){ + if(opt->normalRaise && + (type == TYPE_LIN || type == TYPE_TRI || type == TYPE_QUA)) { SVector3 n; - if(type == TYPE_LIN){ + if(type == TYPE_LIN) { // assumes lines in z=const plane, and raises in that plane double x[2] = {xyz[0][0], xyz[1][0]}; double y[2] = {xyz[0][1], xyz[1][1]}; @@ -254,68 +245,64 @@ void changeCoordinates(PView *p, int ient, int iele, } else n = normal3(xyz); - for(int i = 0; i < numNodes; i++){ + for(int i = 0; i < numNodes; i++) { double v = ComputeScalarRep(numComp, val[i]); - for(int j = 0; j < 3; j++) - xyz[i][j] += n[j] * opt->normalRaise * v; + for(int j = 0; j < 3; j++) xyz[i][j] += n[j] * opt->normalRaise * v; } } - if(numComp == 3 && opt->vectorType == PViewOptions::Displacement){ - for(int i = 0; i < numNodes; i++){ + if(numComp == 3 && opt->vectorType == PViewOptions::Displacement) { + for(int i = 0; i < numNodes; i++) { for(int j = 0; j < 3; j++) xyz[i][j] += opt->displacementFactor * val[i][j]; } } - if(opt->useGenRaise){ + if(opt->useGenRaise) { int numComp2; - double **val2 = new double*[numNodes]; - for(int i = 0; i < numNodes; i++) - val2[i] = new double[9]; + double **val2 = new double *[numNodes]; + for(int i = 0; i < numNodes; i++) val2[i] = new double[9]; getExternalValues(p, opt->viewIndexForGenRaise, ient, iele, numNodes, numComp, val, numComp2, val2); applyGeneralRaise(p, numNodes, numComp2, val2, xyz); - for(int i = 0; i < numNodes; i++) - delete [] val2[i]; - delete [] val2; + for(int i = 0; i < numNodes; i++) delete[] val2[i]; + delete[] val2; } } static double evalClipPlane(int clip, double x, double y, double z) { return CTX::instance()->clipPlane[clip][0] * x + - CTX::instance()->clipPlane[clip][1] * y + - CTX::instance()->clipPlane[clip][2] * z + - CTX::instance()->clipPlane[clip][3]; + CTX::instance()->clipPlane[clip][1] * y + + CTX::instance()->clipPlane[clip][2] * z + + CTX::instance()->clipPlane[clip][3]; } static double intersectClipPlane(int clip, int numNodes, double **xyz) { double val = evalClipPlane(clip, xyz[0][0], xyz[0][1], xyz[0][2]); - for(int i = 1; i < numNodes; i++){ + for(int i = 1; i < numNodes; i++) { if(val * evalClipPlane(clip, xyz[i][0], xyz[i][1], xyz[i][2]) <= 0) return 0.; // the element intersects the cut plane } return val; } -bool isElementVisible(PViewOptions *opt, int dim, int numNodes, - double **xyz) +bool isElementVisible(PViewOptions *opt, int dim, int numNodes, double **xyz) { if(!CTX::instance()->clipWholeElements) return true; bool hidden = false; - for(int clip = 0; clip < 6; clip++){ - if(opt->clip & (1 << clip)){ - if(dim < 3 && CTX::instance()->clipOnlyVolume){ + for(int clip = 0; clip < 6; clip++) { + if(opt->clip & (1 << clip)) { + if(dim < 3 && CTX::instance()->clipOnlyVolume) { } - else{ + else { double d = intersectClipPlane(clip, numNodes, xyz); - if(dim == 3 && CTX::instance()->clipOnlyDrawIntersectingVolume && d){ + if(dim == 3 && CTX::instance()->clipOnlyDrawIntersectingVolume && d) { hidden = true; break; } - else if(d < 0){ + else if(d < 0) { hidden = true; break; } @@ -326,16 +313,15 @@ bool isElementVisible(PViewOptions *opt, int dim, int numNodes, } static void addOutlinePoint(PView *p, double **xyz, unsigned int color, - bool pre, int i0=0) + bool pre, int i0 = 0) { if(pre) return; SVector3 n = getPointNormal(p, 1.); p->va_points->add(&xyz[i0][0], &xyz[i0][1], &xyz[i0][2], &n, &color, 0, true); } -static void addScalarPoint(PView *p, double **xyz, - double **val, bool pre, int i0=0, - bool unique=false) +static void addScalarPoint(PView *p, double **xyz, double **val, bool pre, + int i0 = 0, bool unique = false) { if(pre) return; @@ -344,25 +330,28 @@ static void addScalarPoint(PView *p, double **xyz, double vmin = opt->tmpMin, vmax = opt->tmpMax; if(opt->saturateValues) saturate(1, val, vmin, vmax, i0); - if(val[i0][0] >= vmin && val[i0][0] <= vmax){ - unsigned int col = opt->getColor(val[i0][0], vmin, vmax, false, - (opt->intervalsType == PViewOptions::Discrete) ? - opt->nbIso : -1); + if(val[i0][0] >= vmin && val[i0][0] <= vmax) { + unsigned int col = opt->getColor( + val[i0][0], vmin, vmax, false, + (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); SVector3 n = getPointNormal(p, val[i0][0]); - p->va_points->add(&xyz[i0][0], &xyz[i0][1], &xyz[i0][2], &n, &col, 0, unique); + p->va_points->add(&xyz[i0][0], &xyz[i0][1], &xyz[i0][2], &n, &col, 0, + unique); } } -static void addOutlineLine(PView *p, double **xyz, unsigned int color, - bool pre, int i0=0, int i1=1) +static void addOutlineLine(PView *p, double **xyz, unsigned int color, bool pre, + int i0 = 0, int i1 = 1) { if(pre) return; const int in[2] = {i0, i1}; unsigned int col[2]; double x[2], y[2], z[2]; - for(int i = 0; i < 2; i++){ - x[i] = xyz[in[i]][0]; y[i] = xyz[in[i]][1]; z[i] = xyz[in[i]][2]; + for(int i = 0; i < 2; i++) { + x[i] = xyz[in[i]][0]; + y[i] = xyz[in[i]][1]; + z[i] = xyz[in[i]][2]; col[i] = color; } SVector3 n[2]; @@ -370,15 +359,14 @@ static void addOutlineLine(PView *p, double **xyz, unsigned int color, p->va_lines->add(x, y, z, n, col, 0, true); } -static void addScalarLine(PView *p, double **xyz, - double **val, bool pre, int i0=0, int i1=1, - bool unique=false) +static void addScalarLine(PView *p, double **xyz, double **val, bool pre, + int i0 = 0, int i1 = 1, bool unique = false) { if(pre) return; PViewOptions *opt = p->getOptions(); - if(opt->boundary > 0){ + if(opt->boundary > 0) { opt->boundary--; addScalarPoint(p, xyz, val, pre, i0, true); addScalarPoint(p, xyz, val, pre, i1, true); @@ -394,36 +382,34 @@ static void addScalarLine(PView *p, double **xyz, double z[2] = {xyz[i0][2], xyz[i1][2]}; double v[2] = {val[i0][0], val[i1][0]}; - if(opt->intervalsType == PViewOptions::Continuous){ + if(opt->intervalsType == PViewOptions::Continuous) { SVector3 n[2]; getLineNormal(p, x, y, z, v, n, true); - if(val[i0][0] >= vmin && val[i0][0] <= vmax && - val[i1][0] >= vmin && val[i1][0] <= vmax){ + if(val[i0][0] >= vmin && val[i0][0] <= vmax && val[i1][0] >= vmin && + val[i1][0] <= vmax) { unsigned int col[2]; - for(int i = 0; i < 2; i++) - col[i] = opt->getColor(v[i], vmin, vmax); + for(int i = 0; i < 2; i++) col[i] = opt->getColor(v[i], vmin, vmax); p->va_lines->add(x, y, z, n, col, 0, unique); } - else{ + else { double x2[2], y2[2], z2[2], v2[2]; int nb = CutLine(x, y, z, v, vmin, vmax, x2, y2, z2, v2); - if(nb == 2){ + if(nb == 2) { unsigned int col[2]; - for(int i = 0; i < 2; i++) - col[i] = opt->getColor(v2[i], vmin, vmax); + for(int i = 0; i < 2; i++) col[i] = opt->getColor(v2[i], vmin, vmax); p->va_lines->add(x2, y2, z2, n, col, 0, unique); } } } - if(opt->intervalsType == PViewOptions::Discrete){ - for(int k = 0; k < opt->nbIso; k++){ + if(opt->intervalsType == PViewOptions::Discrete) { + for(int k = 0; k < opt->nbIso; k++) { if(vmin == vmax) k = opt->nbIso / 2; double min = opt->getScaleValue(k, opt->nbIso + 1, vmin, vmax); double max = opt->getScaleValue(k + 1, opt->nbIso + 1, vmin, vmax); double x2[2], y2[2], z2[2], v2[2]; int nb = CutLine(x, y, z, v, min, max, x2, y2, z2, v2); - if(nb == 2){ + if(nb == 2) { unsigned int color = opt->getColor(k, opt->nbIso); unsigned int col[2] = {color, color}; SVector3 n[2]; @@ -434,13 +420,13 @@ static void addScalarLine(PView *p, double **xyz, } } - if(opt->intervalsType == PViewOptions::Iso){ + if(opt->intervalsType == PViewOptions::Iso) { for(int k = 0; k < opt->nbIso; k++) { if(vmin == vmax) k = opt->nbIso / 2; double iso = opt->getScaleValue(k, opt->nbIso, vmin, vmax); double x2[1], y2[1], z2[1]; int nb = IsoLine(x, y, z, v, iso, x2, y2, z2); - if(nb == 1){ + if(nb == 1) { unsigned int color = opt->getColor(k, opt->nbIso); SVector3 n = getPointNormal(p, iso); p->va_points->add(x2, y2, z2, &n, &color, 0, unique); @@ -450,9 +436,8 @@ static void addScalarLine(PView *p, double **xyz, } } -static void addOutlineTriangle(PView *p, double **xyz, - unsigned int color, bool pre, int i0=0, - int i1=1, int i2=2) +static void addOutlineTriangle(PView *p, double **xyz, unsigned int color, + bool pre, int i0 = 0, int i1 = 1, int i2 = 2) { PViewOptions *opt = p->getOptions(); @@ -460,16 +445,18 @@ static void addOutlineTriangle(PView *p, double **xyz, SVector3 nfac = normal3(xyz, i0, i1, i2); - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { double x[2] = {xyz[il[i][0]][0], xyz[il[i][1]][0]}; double y[2] = {xyz[il[i][0]][1], xyz[il[i][1]][1]}; double z[2] = {xyz[il[i][0]][2], xyz[il[i][1]][2]}; SVector3 n[2] = {nfac, nfac}; unsigned int col[2] = {color, color}; - if(opt->smoothNormals){ - for(int j = 0; j < 2; j++){ - if(pre) p->normals->add(x[j], y[j], z[j], n[j][0], n[j][1], n[j][2]); - else p->normals->get(x[j], y[j], z[j], n[j][0], n[j][1], n[j][2]); + if(opt->smoothNormals) { + for(int j = 0; j < 2; j++) { + if(pre) + p->normals->add(x[j], y[j], z[j], n[j][0], n[j][1], n[j][2]); + else + p->normals->get(x[j], y[j], z[j], n[j][0], n[j][1], n[j][2]); } } getLineNormal(p, x, y, z, 0, n, false); @@ -477,15 +464,15 @@ static void addOutlineTriangle(PView *p, double **xyz, } } -static void addScalarTriangle(PView *p, double **xyz, double **val, - bool pre, int i0=0, int i1=1, int i2=2, - bool unique=false, bool skin=false) +static void addScalarTriangle(PView *p, double **xyz, double **val, bool pre, + int i0 = 0, int i1 = 1, int i2 = 2, + bool unique = false, bool skin = false) { PViewOptions *opt = p->getOptions(); const int il[3][2] = {{i0, i1}, {i1, i2}, {i2, i0}}; - if(opt->boundary > 0){ + if(opt->boundary > 0) { opt->boundary--; for(int i = 0; i < 3; i++) addScalarLine(p, xyz, val, pre, il[i][0], il[i][1], true); @@ -503,36 +490,39 @@ static void addScalarTriangle(PView *p, double **xyz, double **val, SVector3 nfac = normal3(xyz, i0, i1, i2); - if(opt->intervalsType == PViewOptions::Continuous){ - if(val[i0][0] >= vmin && val[i0][0] <= vmax && - val[i1][0] >= vmin && val[i1][0] <= vmax && - val[i2][0] >= vmin && val[i2][0] <= vmax){ + if(opt->intervalsType == PViewOptions::Continuous) { + if(val[i0][0] >= vmin && val[i0][0] <= vmax && val[i1][0] >= vmin && + val[i1][0] <= vmax && val[i2][0] >= vmin && val[i2][0] <= vmax) { SVector3 n[3] = {nfac, nfac, nfac}; unsigned int col[3]; - for(int i = 0; i < 3; i++){ - if(opt->smoothNormals){ - if(pre) p->normals->add(x[i], y[i], z[i], n[i][0], n[i][1], n[i][2]); - else p->normals->get(x[i], y[i], z[i], n[i][0], n[i][1], n[i][2]); + for(int i = 0; i < 3; i++) { + if(opt->smoothNormals) { + if(pre) + p->normals->add(x[i], y[i], z[i], n[i][0], n[i][1], n[i][2]); + else + p->normals->get(x[i], y[i], z[i], n[i][0], n[i][1], n[i][2]); } col[i] = opt->getColor(v[i], vmin, vmax); } if(!pre) p->va_triangles->add(x, y, z, n, col, 0, unique, skin); } - else{ + else { double x2[10], y2[10], z2[10], v2[10]; int nb = CutTriangle(x, y, z, v, vmin, vmax, x2, y2, z2, v2); - if(nb >= 3){ - for(int j = 2; j < nb; j++){ + if(nb >= 3) { + for(int j = 2; j < nb; j++) { double x3[3] = {x2[0], x2[j - 1], x2[j]}; double y3[3] = {y2[0], y2[j - 1], y2[j]}; double z3[3] = {z2[0], z2[j - 1], z2[j]}; double v3[3] = {v2[0], v2[j - 1], v2[j]}; SVector3 n[3] = {nfac, nfac, nfac}; unsigned int col[3]; - for(int i = 0; i < 3; i++){ - if(opt->smoothNormals){ - if(pre) p->normals->add(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); - else p->normals->get(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); + for(int i = 0; i < 3; i++) { + if(opt->smoothNormals) { + if(pre) + p->normals->add(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); + else + p->normals->get(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); } col[i] = opt->getColor(v3[i], vmin, vmax); } @@ -542,25 +532,27 @@ static void addScalarTriangle(PView *p, double **xyz, double **val, } } - if(opt->intervalsType == PViewOptions::Discrete){ - for(int k = 0; k < opt->nbIso; k++){ + if(opt->intervalsType == PViewOptions::Discrete) { + for(int k = 0; k < opt->nbIso; k++) { if(vmin == vmax) k = opt->nbIso / 2; double min = opt->getScaleValue(k, opt->nbIso + 1, vmin, vmax); double max = opt->getScaleValue(k + 1, opt->nbIso + 1, vmin, vmax); double x2[10], y2[10], z2[10], v2[10]; int nb = CutTriangle(x, y, z, v, min, max, x2, y2, z2, v2); - if(nb >= 3){ + if(nb >= 3) { unsigned int color = opt->getColor(k, opt->nbIso); unsigned int col[3] = {color, color, color}; - for(int j = 2; j < nb; j++){ + for(int j = 2; j < nb; j++) { double x3[3] = {x2[0], x2[j - 1], x2[j]}; double y3[3] = {y2[0], y2[j - 1], y2[j]}; double z3[3] = {z2[0], z2[j - 1], z2[j]}; SVector3 n[3] = {nfac, nfac, nfac}; - if(opt->smoothNormals){ - for(int i = 0; i < 3; i++){ - if(pre) p->normals->add(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); - else p->normals->get(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); + if(opt->smoothNormals) { + for(int i = 0; i < 3; i++) { + if(pre) + p->normals->add(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); + else + p->normals->get(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); } } if(!pre) p->va_triangles->add(x3, y3, z3, n, col, 0, unique, skin); @@ -570,20 +562,22 @@ static void addScalarTriangle(PView *p, double **xyz, double **val, } } - if(opt->intervalsType == PViewOptions::Iso){ + if(opt->intervalsType == PViewOptions::Iso) { for(int k = 0; k < opt->nbIso; k++) { if(vmin == vmax) k = opt->nbIso / 2; double iso = opt->getScaleValue(k, opt->nbIso, vmin, vmax); double x2[3], y2[3], z2[3]; int nb = IsoTriangle(x, y, z, v, iso, x2, y2, z2); - if(nb == 2){ + if(nb == 2) { unsigned int color = opt->getColor(k, opt->nbIso); unsigned int col[2] = {color, color}; SVector3 n[2] = {nfac, nfac}; - if(opt->smoothNormals){ - for(int i = 0; i < 2; i++){ - if(pre) p->normals->add(x2[i], y2[i], z2[i], n[i][0], n[i][1], n[i][2]); - else p->normals->get(x2[i], y2[i], z2[i], n[i][0], n[i][1], n[i][2]); + if(opt->smoothNormals) { + for(int i = 0; i < 2; i++) { + if(pre) + p->normals->add(x2[i], y2[i], z2[i], n[i][0], n[i][1], n[i][2]); + else + p->normals->get(x2[i], y2[i], z2[i], n[i][0], n[i][1], n[i][2]); } } double v[2] = {iso, iso}; @@ -595,9 +589,9 @@ static void addScalarTriangle(PView *p, double **xyz, double **val, } } -static void addOutlineQuadrangle(PView *p, double **xyz, - unsigned int color, bool pre, int i0=0, int i1=1, - int i2=2, int i3=3) +static void addOutlineQuadrangle(PView *p, double **xyz, unsigned int color, + bool pre, int i0 = 0, int i1 = 1, int i2 = 2, + int i3 = 3) { PViewOptions *opt = p->getOptions(); @@ -605,16 +599,18 @@ static void addOutlineQuadrangle(PView *p, double **xyz, SVector3 nfac = normal3(xyz, i0, i1, i2); - for(int i = 0; i < 4; i++){ + for(int i = 0; i < 4; i++) { double x[2] = {xyz[il[i][0]][0], xyz[il[i][1]][0]}; double y[2] = {xyz[il[i][0]][1], xyz[il[i][1]][1]}; double z[2] = {xyz[il[i][0]][2], xyz[il[i][1]][2]}; SVector3 n[2] = {nfac, nfac}; unsigned int col[2] = {color, color}; - if(opt->smoothNormals){ - for(int j = 0; j < 2; j++){ - if(pre) p->normals->add(x[j], y[j], z[j], n[j][0], n[j][1], n[j][2]); - else p->normals->get(x[j], y[j], z[j], n[j][0], n[j][1], n[j][2]); + if(opt->smoothNormals) { + for(int j = 0; j < 2; j++) { + if(pre) + p->normals->add(x[j], y[j], z[j], n[j][0], n[j][1], n[j][2]); + else + p->normals->get(x[j], y[j], z[j], n[j][0], n[j][1], n[j][2]); } } getLineNormal(p, x, y, z, 0, n, false); @@ -622,16 +618,16 @@ static void addOutlineQuadrangle(PView *p, double **xyz, } } -static void addScalarQuadrangle(PView *p, double **xyz, - double **val, bool pre, int i0=0, - int i1=1, int i2=2, int i3=3, bool unique=false) +static void addScalarQuadrangle(PView *p, double **xyz, double **val, bool pre, + int i0 = 0, int i1 = 1, int i2 = 2, int i3 = 3, + bool unique = false) { PViewOptions *opt = p->getOptions(); const int il[4][2] = {{i0, i1}, {i1, i2}, {i2, i3}, {i3, i0}}; const int it[2][3] = {{i0, i1, i2}, {i0, i2, i3}}; - if(opt->boundary > 0){ + if(opt->boundary > 0) { opt->boundary--; for(int i = 0; i < 4; i++) addScalarLine(p, xyz, val, pre, il[i][0], il[i][1], true); @@ -643,79 +639,79 @@ static void addScalarQuadrangle(PView *p, double **xyz, addScalarTriangle(p, xyz, val, pre, it[i][0], it[i][1], it[i][2], unique); } -static void addOutlinePolygon(PView *p, double **xyz, - unsigned int color, bool pre, int numNodes) +static void addOutlinePolygon(PView *p, double **xyz, unsigned int color, + bool pre, int numNodes) { for(int i = 0; i < numNodes / 3; i++) - addOutlineTriangle(p, xyz, color, pre, 3*i, 3*i + 1, 3*i + 2); + addOutlineTriangle(p, xyz, color, pre, 3 * i, 3 * i + 1, 3 * i + 2); } -static void addScalarPolygon(PView *p, double **xyz, - double **val, bool pre, int numNodes) +static void addScalarPolygon(PView *p, double **xyz, double **val, bool pre, + int numNodes) { PViewOptions *opt = p->getOptions(); - if(opt->boundary > 0){ + if(opt->boundary > 0) { const int il[3][2] = {{0, 1}, {1, 2}, {2, 0}}; std::map<MEdge, int, Less_Edge> edges; std::vector<MVertex *> verts; verts.reserve(numNodes); for(int i = 0; i < numNodes; i++) verts.push_back(new MVertex(xyz[i][0], xyz[i][1], xyz[i][2])); - for(int i = 0; i < numNodes / 3; i++){ + for(int i = 0; i < numNodes / 3; i++) { for(int j = 0; j < 3; j++) { - MEdge ed(verts[3*i+il[j][0]], verts[3*i+il[j][1]]); + MEdge ed(verts[3 * i + il[j][0]], verts[3 * i + il[j][1]]); std::map<MEdge, int, Less_Edge>::iterator ite; for(ite = edges.begin(); ite != edges.end(); ite++) if((*ite).first == ed) break; if(ite == edges.end()) - edges[ed] = 100*i+j; - else edges.erase(ite); + edges[ed] = 100 * i + j; + else + edges.erase(ite); } } opt->boundary--; for(std::map<MEdge, int, Less_Edge>::iterator ite = edges.begin(); - ite != edges.end(); ite++){ - int i = (int) (*ite).second / 100; + ite != edges.end(); ite++) { + int i = (int)(*ite).second / 100; int j = (*ite).second % 100; if(j < 3) - addScalarLine(p, xyz, val, pre, 3*i+il[j][0], 3*i+il[j][0], true); + addScalarLine(p, xyz, val, pre, 3 * i + il[j][0], 3 * i + il[j][0], + true); } opt->boundary++; - for(int i = 0; i < numNodes; i++) - delete verts[i]; + for(int i = 0; i < numNodes; i++) delete verts[i]; return; } for(int i = 0; i < numNodes / 3; i++) - addScalarTriangle(p, xyz, val, pre, 3*i, 3*i+1, 3*i+2); + addScalarTriangle(p, xyz, val, pre, 3 * i, 3 * i + 1, 3 * i + 2); } -static void addOutlineTetrahedron(PView *p, double **xyz, - unsigned int color, bool pre) +static void addOutlineTetrahedron(PView *p, double **xyz, unsigned int color, + bool pre) { const int it[4][3] = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2}, {3, 1, 2}}; for(int i = 0; i < 4; i++) addOutlineTriangle(p, xyz, color, pre, it[i][0], it[i][1], it[i][2]); } -static void addScalarTetrahedron(PView *p, double **xyz, - double **val, bool pre, int i0=0, - int i1=1, int i2=2, int i3=3) +static void addScalarTetrahedron(PView *p, double **xyz, double **val, bool pre, + int i0 = 0, int i1 = 1, int i2 = 2, int i3 = 3) { PViewOptions *opt = p->getOptions(); const int it[4][3] = {{i0, i2, i1}, {i0, i1, i3}, {i0, i3, i2}, {i3, i1, i2}}; - if(opt->boundary > 0 || - opt->intervalsType == PViewOptions::Continuous || - opt->intervalsType == PViewOptions::Discrete){ + if(opt->boundary > 0 || opt->intervalsType == PViewOptions::Continuous || + opt->intervalsType == PViewOptions::Discrete) { bool skin = (opt->boundary > 0) ? false : opt->drawSkinOnly; opt->boundary--; for(int i = 0; i < 4; i++) - addScalarTriangle(p, xyz, val, pre, it[i][0], it[i][1], it[i][2], true, skin); + addScalarTriangle(p, xyz, val, pre, it[i][0], it[i][1], it[i][2], true, + skin); opt->boundary++; return; } @@ -728,25 +724,29 @@ static void addScalarTetrahedron(PView *p, double **xyz, double z[4] = {xyz[i0][2], xyz[i1][2], xyz[i2][2], xyz[i3][2]}; double v[4] = {val[i0][0], val[i1][0], val[i2][0], val[i3][0]}; - if(opt->intervalsType == PViewOptions::Iso){ + if(opt->intervalsType == PViewOptions::Iso) { for(int k = 0; k < opt->nbIso; k++) { if(vmin == vmax) k = opt->nbIso / 2; double iso = opt->getScaleValue(k, opt->nbIso, vmin, vmax); double x2[6], y2[6], z2[6], nn[3]; int nb = IsoSimplex(x, y, z, v, iso, x2, y2, z2, nn); - if(nb >= 3){ + if(nb >= 3) { unsigned int color = opt->getColor(k, opt->nbIso); unsigned int col[3] = {color, color, color}; - for(int j = 2; j < nb; j++){ + for(int j = 2; j < nb; j++) { double x3[3] = {x2[0], x2[j - 1], x2[j]}; double y3[3] = {y2[0], y2[j - 1], y2[j]}; double z3[3] = {z2[0], z2[j - 1], z2[j]}; SVector3 n[3]; - for(int i = 0; i < 3; i++){ - n[i][0] = nn[0]; n[i][1] = nn[1]; n[i][2] = nn[2]; - if(opt->smoothNormals){ - if(pre) p->normals->add(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); - else p->normals->get(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); + for(int i = 0; i < 3; i++) { + n[i][0] = nn[0]; + n[i][1] = nn[1]; + n[i][2] = nn[2]; + if(opt->smoothNormals) { + if(pre) + p->normals->add(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); + else + p->normals->get(x3[i], y3[i], z3[i], n[i][0], n[i][1], n[i][2]); } } if(!pre) p->va_triangles->add(x3, y3, z3, n, col, 0, false, false); @@ -757,37 +757,38 @@ static void addScalarTetrahedron(PView *p, double **xyz, } } -static void addOutlineHexahedron(PView *p, double **xyz, - unsigned int color, bool pre) +static void addOutlineHexahedron(PView *p, double **xyz, unsigned int color, + bool pre) { const int iq[6][4] = {{0, 3, 2, 1}, {0, 1, 5, 4}, {0, 4, 7, 3}, {1, 2, 6, 5}, {2, 3, 7, 6}, {4, 5, 6, 7}}; for(int i = 0; i < 6; i++) - addOutlineQuadrangle(p, xyz, color, pre, iq[i][0], iq[i][1], - iq[i][2], iq[i][3]); + addOutlineQuadrangle(p, xyz, color, pre, iq[i][0], iq[i][1], iq[i][2], + iq[i][3]); } -static void addScalarHexahedron(PView *p, double **xyz, - double **val, bool pre) +static void addScalarHexahedron(PView *p, double **xyz, double **val, bool pre) { PViewOptions *opt = p->getOptions(); const int iq[6][4] = {{0, 3, 2, 1}, {0, 1, 5, 4}, {0, 4, 7, 3}, {1, 2, 6, 5}, {2, 3, 7, 6}, {4, 5, 6, 7}}; - const int is[6][4] = {{0,1,3,7}, {0,4,1,7}, {1,4,5,7}, - {1,2,3,7}, {1,6,2,7}, {1,5,6,7}}; + const int is[6][4] = {{0, 1, 3, 7}, {0, 4, 1, 7}, {1, 4, 5, 7}, + {1, 2, 3, 7}, {1, 6, 2, 7}, {1, 5, 6, 7}}; - if(opt->boundary > 0){ + if(opt->boundary > 0) { opt->boundary--; for(int i = 0; i < 6; i++) - addScalarQuadrangle(p, xyz, val, pre, iq[i][0], iq[i][1], iq[i][2], iq[i][3], true); + addScalarQuadrangle(p, xyz, val, pre, iq[i][0], iq[i][1], iq[i][2], + iq[i][3], true); opt->boundary++; return; } for(int i = 0; i < 6; i++) - addScalarTetrahedron(p, xyz, val, pre, is[i][0], is[i][1], is[i][2], is[i][3]); + addScalarTetrahedron(p, xyz, val, pre, is[i][0], is[i][1], is[i][2], + is[i][3]); } static void addOutlinePrism(PView *p, double **xyz, unsigned int color, @@ -797,7 +798,8 @@ static void addOutlinePrism(PView *p, double **xyz, unsigned int color, const int it[2][3] = {{0, 2, 1}, {3, 4, 5}}; for(int i = 0; i < 3; i++) - addOutlineQuadrangle(p, xyz, color, pre, iq[i][0], iq[i][1], iq[i][2], iq[i][3]); + addOutlineQuadrangle(p, xyz, color, pre, iq[i][0], iq[i][1], iq[i][2], + iq[i][3]); for(int i = 0; i < 2; i++) addOutlineTriangle(p, xyz, color, pre, it[i][0], it[i][1], it[i][2]); } @@ -809,10 +811,11 @@ static void addScalarPrism(PView *p, double **xyz, double **val, bool pre) const int it[2][3] = {{0, 2, 1}, {3, 4, 5}}; const int is[3][4] = {{0, 1, 2, 4}, {0, 4, 2, 5}, {0, 3, 4, 5}}; - if(opt->boundary > 0){ + if(opt->boundary > 0) { opt->boundary--; for(int i = 0; i < 3; i++) - addScalarQuadrangle(p, xyz, val, pre, iq[i][0], iq[i][1], iq[i][2], iq[i][3], true); + addScalarQuadrangle(p, xyz, val, pre, iq[i][0], iq[i][1], iq[i][2], + iq[i][3], true); for(int i = 0; i < 2; i++) addScalarTriangle(p, xyz, val, pre, it[i][0], it[i][1], it[i][2], true); opt->boundary++; @@ -820,11 +823,12 @@ static void addScalarPrism(PView *p, double **xyz, double **val, bool pre) } for(int i = 0; i < 3; i++) - addScalarTetrahedron(p, xyz, val, pre, is[i][0], is[i][1], is[i][2], is[i][3]); + addScalarTetrahedron(p, xyz, val, pre, is[i][0], is[i][1], is[i][2], + is[i][3]); } -static void addOutlinePyramid(PView *p, double **xyz, - unsigned int color, bool pre) +static void addOutlinePyramid(PView *p, double **xyz, unsigned int color, + bool pre) { const int it[4][3] = {{0, 1, 4}, {3, 0, 4}, {1, 2, 4}, {2, 3, 4}}; @@ -833,15 +837,14 @@ static void addOutlinePyramid(PView *p, double **xyz, addOutlineTriangle(p, xyz, color, pre, it[i][0], it[i][1], it[i][2]); } -static void addScalarPyramid(PView *p, double **xyz, - double **val, bool pre) +static void addScalarPyramid(PView *p, double **xyz, double **val, bool pre) { PViewOptions *opt = p->getOptions(); const int it[4][3] = {{0, 1, 4}, {3, 0, 4}, {1, 2, 4}, {2, 3, 4}}; const int is[2][4] = {{0, 1, 3, 4}, {1, 2, 3, 4}}; - if(opt->boundary > 0){ + if(opt->boundary > 0) { opt->boundary--; addScalarQuadrangle(p, xyz, val, pre, 0, 3, 2, 1, true); for(int i = 0; i < 4; i++) @@ -851,25 +854,25 @@ static void addScalarPyramid(PView *p, double **xyz, } for(int i = 0; i < 2; i++) - addScalarTetrahedron(p, xyz, val, pre, is[i][0], is[i][1], is[i][2], is[i][3]); + addScalarTetrahedron(p, xyz, val, pre, is[i][0], is[i][1], is[i][2], + is[i][3]); } -static void addOutlineTrihedron(PView *p, double **xyz, - unsigned int color, bool pre) +static void addOutlineTrihedron(PView *p, double **xyz, unsigned int color, + bool pre) { addOutlineQuadrangle(p, xyz, color, pre, 0, 1, 2, 3); } -static void addScalarTrihedron(PView *p, double **xyz, - double **val, bool pre, int i0=0, - int i1=1, int i2=2, int i3=3, bool unique=false) +static void addScalarTrihedron(PView *p, double **xyz, double **val, bool pre, + int i0 = 0, int i1 = 1, int i2 = 2, int i3 = 3, + bool unique = false) { addScalarQuadrangle(p, xyz, val, pre, i0, i1, i2, i3, unique); } - -static void addOutlinePolyhedron(PView *p, double **xyz, - unsigned int color, bool pre, int numNodes) +static void addOutlinePolyhedron(PView *p, double **xyz, unsigned int color, + bool pre, int numNodes) { // FIXME: this code is horribly slow const int it[4][3] = {{0, 2, 1}, {0, 1, 3}, {0, 3, 2}, {3, 1, 2}}; @@ -878,64 +881,77 @@ static void addOutlinePolyhedron(PView *p, double **xyz, verts.reserve(numNodes); for(int i = 0; i < numNodes; i++) verts.push_back(new MVertex(xyz[i][0], xyz[i][1], xyz[i][2])); - for(int i = 0; i < numNodes / 4; i++){ + for(int i = 0; i < numNodes / 4; i++) { for(int j = 0; j < 4; j++) { - MFace f(verts[4*i+it[j][0]], verts[4*i+it[j][1]], verts[4*i+it[j][2]]); + MFace f(verts[4 * i + it[j][0]], verts[4 * i + it[j][1]], + verts[4 * i + it[j][2]]); std::map<MFace, int, Less_Face>::iterator ite; for(ite = triFaces.begin(); ite != triFaces.end(); ite++) if((*ite).first == f) break; if(ite == triFaces.end()) - triFaces[f] = 100*i+j; - else triFaces.erase(ite); + triFaces[f] = 100 * i + j; + else + triFaces.erase(ite); } } for(std::map<MFace, int, Less_Face>::iterator ite = triFaces.begin(); - ite != triFaces.end(); ite++){ - int i = (int) (*ite).second / 100; + ite != triFaces.end(); ite++) { + int i = (int)(*ite).second / 100; int j = (*ite).second % 100; if(j < 4) - addOutlineTriangle(p, xyz, color, pre, 4*i+it[j][0], 4*i+it[j][1], 4*i+it[j][2]); + addOutlineTriangle(p, xyz, color, pre, 4 * i + it[j][0], 4 * i + it[j][1], + 4 * i + it[j][2]); } - for(int i = 0; i < numNodes; i++) - delete verts[i]; + for(int i = 0; i < numNodes; i++) delete verts[i]; } -static void addScalarPolyhedron(PView *p, double **xyz, - double **val, bool pre, int numNodes) +static void addScalarPolyhedron(PView *p, double **xyz, double **val, bool pre, + int numNodes) { PViewOptions *opt = p->getOptions(); - if(opt->boundary > 0){ + if(opt->boundary > 0) { return; } for(int i = 0; i < numNodes / 4; i++) - addScalarTetrahedron(p, xyz, val, pre, 4*i, 4*i + 1, 4*i + 2, 4*i + 3); + addScalarTetrahedron(p, xyz, val, pre, 4 * i, 4 * i + 1, 4 * i + 2, + 4 * i + 3); } -static void addOutlineElement(PView *p, int type, double **xyz, - bool pre, int numNodes) +static void addOutlineElement(PView *p, int type, double **xyz, bool pre, + int numNodes) { PViewOptions *opt = p->getOptions(); - switch(type){ + switch(type) { case TYPE_PNT: addOutlinePoint(p, xyz, opt->color.point, pre); break; case TYPE_LIN: addOutlineLine(p, xyz, opt->color.line, pre); break; case TYPE_TRI: addOutlineTriangle(p, xyz, opt->color.triangle, pre); break; - case TYPE_QUA: addOutlineQuadrangle(p, xyz, opt->color.quadrangle, pre); break; - case TYPE_POLYG: addOutlinePolygon(p, xyz, opt->color.quadrangle, pre, numNodes); break; - case TYPE_TET: addOutlineTetrahedron(p, xyz, opt->color.tetrahedron, pre); break; - case TYPE_HEX: addOutlineHexahedron(p, xyz, opt->color.hexahedron, pre); break; + case TYPE_QUA: + addOutlineQuadrangle(p, xyz, opt->color.quadrangle, pre); + break; + case TYPE_POLYG: + addOutlinePolygon(p, xyz, opt->color.quadrangle, pre, numNodes); + break; + case TYPE_TET: + addOutlineTetrahedron(p, xyz, opt->color.tetrahedron, pre); + break; + case TYPE_HEX: + addOutlineHexahedron(p, xyz, opt->color.hexahedron, pre); + break; case TYPE_PRI: addOutlinePrism(p, xyz, opt->color.prism, pre); break; case TYPE_PYR: addOutlinePyramid(p, xyz, opt->color.pyramid, pre); break; case TYPE_TRIH: addOutlineTrihedron(p, xyz, opt->color.pyramid, pre); break; - case TYPE_POLYH: addOutlinePolyhedron(p, xyz, opt->color.pyramid, pre, numNodes); break; + case TYPE_POLYH: + addOutlinePolyhedron(p, xyz, opt->color.pyramid, pre, numNodes); + break; } } -static void addScalarElement(PView *p, int type, double **xyz, - double **val, bool pre, int numNodes) +static void addScalarElement(PView *p, int type, double **xyz, double **val, + bool pre, int numNodes) { - switch(type){ + switch(type) { case TYPE_PNT: addScalarPoint(p, xyz, val, pre); break; case TYPE_LIN: addScalarLine(p, xyz, val, pre); break; case TYPE_TRI: addScalarTriangle(p, xyz, val, pre); break; @@ -951,21 +967,19 @@ static void addScalarElement(PView *p, int type, double **xyz, } static void addVectorElement(PView *p, int ient, int iele, int numNodes, - int type, double **xyz, - double **val, bool pre) + int type, double **xyz, double **val, bool pre) { // use adaptive data if available PViewData *data = p->getData(true); PViewOptions *opt = p->getOptions(); int numComp2; - double **val2 = new double*[numNodes]; - for(int i = 0; i < numNodes; i++) - val2[i] = new double[9]; - getExternalValues(p, opt->externalViewIndex, ient, iele, numNodes, - 3, val, numComp2, val2); + double **val2 = new double *[numNodes]; + for(int i = 0; i < numNodes; i++) val2[i] = new double[9]; + getExternalValues(p, opt->externalViewIndex, ient, iele, numNodes, 3, val, + numComp2, val2); - if(opt->vectorType == PViewOptions::Displacement){ + if(opt->vectorType == PViewOptions::Displacement) { for(int i = 0; i < numNodes; i++) val2[i][0] = ComputeScalarRep(numComp2, val2[i]); @@ -979,28 +993,27 @@ static void addVectorElement(PView *p, int ient, int iele, int numNodes, // add point trajectories // FIXME: this should be optional - if(!pre && numNodes == 1 && opt->timeStep > 0 && opt->lineWidth){ - for(int ts = 0; ts < opt->timeStep; ts++){ + if(!pre && numNodes == 1 && opt->timeStep > 0 && opt->lineWidth) { + for(int ts = 0; ts < opt->timeStep; ts++) { if(!data->hasTimeStep(ts)) continue; int numComp = data->getNumComponents(ts, ient, iele); double xyz0[3], dxyz[3][2] = {{0., 0.}, {0., 0.}, {0., 0.}}; data->getNode(ts, ient, iele, 0, xyz0[0], xyz0[1], xyz0[2]); - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { int comp = opt->forceNumComponents ? opt->componentMap[j] : j; - if(comp >= 0 && comp < numComp){ + if(comp >= 0 && comp < numComp) { data->getValue(ts, ient, iele, 0, comp, dxyz[j][0]); data->getValue(ts + 1, ient, iele, 0, comp, dxyz[j][1]); } } unsigned int col[2]; double norm[2]; - for(int i = 0; i < 2; i++){ - norm[i] = sqrt(dxyz[0][i] * dxyz[0][i] + - dxyz[1][i] * dxyz[1][i] + + for(int i = 0; i < 2; i++) { + norm[i] = sqrt(dxyz[0][i] * dxyz[0][i] + dxyz[1][i] * dxyz[1][i] + dxyz[2][i] * dxyz[2][i]); col[i] = opt->getColor(norm[i], opt->tmpMin, opt->tmpMax); } - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { dxyz[j][0] = xyz0[j] + dxyz[j][0] * opt->displacementFactor; dxyz[j][1] = xyz0[j] + dxyz[j][1] * opt->displacementFactor; } @@ -1009,31 +1022,30 @@ static void addVectorElement(PView *p, int ient, int iele, int numNodes, p->va_lines->add(dxyz[0], dxyz[1], dxyz[2], n, col, 0, false); } } - for(int i = 0; i < numNodes; i++) - delete [] val2[i]; - delete [] val2; + for(int i = 0; i < numNodes; i++) delete[] val2[i]; + delete[] val2; return; } - if(pre){ - for(int i = 0; i < numNodes; i++) - delete [] val2[i]; - delete [] val2; + if(pre) { + for(int i = 0; i < numNodes; i++) delete[] val2[i]; + delete[] val2; return; } - if(opt->glyphLocation == PViewOptions::Vertex){ - for(int i = 0; i < numNodes; i++){ + if(opt->glyphLocation == PViewOptions::Vertex) { + for(int i = 0; i < numNodes; i++) { double v2 = opt->saturateValues ? - saturateVector(val[i], numComp2, val2[i], opt->externalMin, opt->externalMax) : - ComputeScalarRep(numComp2, val2[i]); - if(v2 >= opt->externalMin && v2 <= opt->externalMax){ - unsigned int color = opt->getColor(v2, opt->externalMin, opt->externalMax, false, - (opt->intervalsType == PViewOptions::Discrete) ? - opt->nbIso : -1); + saturateVector(val[i], numComp2, val2[i], opt->externalMin, + opt->externalMax) : + ComputeScalarRep(numComp2, val2[i]); + if(v2 >= opt->externalMin && v2 <= opt->externalMax) { + unsigned int color = opt->getColor( + v2, opt->externalMin, opt->externalMax, false, + (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); unsigned int col[2] = {color, color}; double dxyz[3][2]; - for(int j = 0; j < 3; j++){ + for(int j = 0; j < 3; j++) { dxyz[j][0] = xyz[i][j]; dxyz[j][1] = val[i][j]; } @@ -1042,17 +1054,18 @@ static void addVectorElement(PView *p, int ient, int iele, int numNodes, } } - if(opt->glyphLocation == PViewOptions::COG){ + if(opt->glyphLocation == PViewOptions::COG) { // compute value by averaging the norm and averaging the directions (this // allows to preserve the min/max) SPoint3 pc(0., 0., 0.); double d[3] = {0., 0., 0.}; double v2 = 0.; - for(int i = 0; i < numNodes; i++){ + for(int i = 0; i < numNodes; i++) { pc += SPoint3(xyz[i][0], xyz[i][1], xyz[i][2]); v2 += opt->saturateValues ? - saturateVector(val[i], numComp2, val2[i], opt->externalMin, opt->externalMax) : - ComputeScalarRep(numComp2, val2[i]); + saturateVector(val[i], numComp2, val2[i], opt->externalMin, + opt->externalMax) : + ComputeScalarRep(numComp2, val2[i]); for(int j = 0; j < 3; j++) d[j] += val[i][j]; } pc /= (double)numNodes; @@ -1063,207 +1076,209 @@ static void addVectorElement(PView *p, int ient, int iele, int numNodes, // need tolerance since we compare computed results (the average) // instead of the raw data used to compute bounds if(v2 >= opt->externalMin * (1. - 1.e-15) && - v2 <= opt->externalMax * (1. + 1.e-15)){ - unsigned int color = opt->getColor(v2, opt->externalMin, opt->externalMax, false, - (opt->intervalsType == PViewOptions::Discrete) ? - opt->nbIso : -1); + v2 <= opt->externalMax * (1. + 1.e-15)) { + unsigned int color = opt->getColor( + v2, opt->externalMin, opt->externalMax, false, + (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); unsigned int col[2] = {color, color}; double dxyz[3][2]; - for(int i = 0; i < 3; i++){ + for(int i = 0; i < 3; i++) { dxyz[i][0] = pc[i]; dxyz[i][1] = d[i]; } p->va_vectors->add(dxyz[0], dxyz[1], dxyz[2], 0, col, 0, false); } } - for(int i = 0; i < numNodes; i++) - delete [] val2[i]; - delete [] val2; + for(int i = 0; i < numNodes; i++) delete[] val2[i]; + delete[] val2; } -static void addTriangle (PView *p, PViewOptions *opt, double *x0, double *x1, double *x2,SPoint3 &xx, double val){ - - unsigned int color = opt->getColor - (val, opt->tmpMin, opt->tmpMax, false, - (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); - - SVector3 a (x1[0]-x0[0],x1[1]-x0[1],x1[2]-x0[2]); - SVector3 b (x2[0]-x0[0],x2[1]-x0[1],x2[2]-x0[2]); - SVector3 c (xx.x()-x0[0],xx.y()-x0[1],xx.z()-x0[2]); - SVector3 N = crossprod (a,b); - unsigned int col[3] = {color, color, color}; +static void addTriangle(PView *p, PViewOptions *opt, double *x0, double *x1, + double *x2, SPoint3 &xx, double val) +{ + unsigned int color = opt->getColor( + val, opt->tmpMin, opt->tmpMax, false, + (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); + + SVector3 a(x1[0] - x0[0], x1[1] - x0[1], x1[2] - x0[2]); + SVector3 b(x2[0] - x0[0], x2[1] - x0[1], x2[2] - x0[2]); + SVector3 c(xx.x() - x0[0], xx.y() - x0[1], xx.z() - x0[2]); + SVector3 N = crossprod(a, b); + unsigned int col[3] = {color, color, color}; N.normalize(); - if (dot(c,N) > 0){ - double XX[3] = {x0[0],x1[0],x2[0]}; - double YY[3] = {x0[1],x1[1],x2[1]}; - double ZZ[3] = {x0[2],x1[2],x2[2]}; - SVector3 NN[3] = {N,N,N}; - p->va_triangles->add(XX,YY,ZZ, NN, col, 0, false); + if(dot(c, N) > 0) { + double XX[3] = {x0[0], x1[0], x2[0]}; + double YY[3] = {x0[1], x1[1], x2[1]}; + double ZZ[3] = {x0[2], x1[2], x2[2]}; + SVector3 NN[3] = {N, N, N}; + p->va_triangles->add(XX, YY, ZZ, NN, col, 0, false); } else { - double XX[3] = {x1[0],x0[0],x2[0]}; - double YY[3] = {x1[1],x0[1],x2[1]}; - double ZZ[3] = {x1[2],x0[2],x2[2]}; - SVector3 NN[3] = {-N,-N,-N}; - p->va_triangles->add(XX,YY,ZZ, NN, col, 0, false); + double XX[3] = {x1[0], x0[0], x2[0]}; + double YY[3] = {x1[1], x0[1], x2[1]}; + double ZZ[3] = {x1[2], x0[2], x2[2]}; + SVector3 NN[3] = {-N, -N, -N}; + p->va_triangles->add(XX, YY, ZZ, NN, col, 0, false); } } - -static void addTensorElement(PView *p, int iEnt, int iEle, int numNodes, int type, - double **xyz, double **val, - bool pre) +static void addTensorElement(PView *p, int iEnt, int iEle, int numNodes, + int type, double **xyz, double **val, bool pre) { PViewOptions *opt = p->getOptions(); - fullMatrix <double> tensor(3,3); - fullVector<double> S(3), imS (3); - fullMatrix<double> V(3,3); - fullMatrix <double> rightV(3,3); + fullMatrix<double> tensor(3, 3); + fullVector<double> S(3), imS(3); + fullMatrix<double> V(3, 3); + fullMatrix<double> rightV(3, 3); - if(opt->tensorType == PViewOptions::VonMises){ - for(int i = 0; i < numNodes; i++) - val[i][0] = ComputeVonMises(val[i]); + if(opt->tensorType == PViewOptions::VonMises) { + for(int i = 0; i < numNodes; i++) val[i][0] = ComputeVonMises(val[i]); addScalarElement(p, type, xyz, val, pre, numNodes); } - else if (opt->tensorType == PViewOptions::Frame) { - if(opt->glyphLocation == PViewOptions::Vertex){ - for(int i = 0; i < numNodes; i++){ - double d0[3],d1[3],d2[3]; - double nrm = sqrt (val [i][0]*val [i][0]+ - val [i][1]*val [i][1]+ - val [i][2]*val [i][2]); - - for (int j = 0; j < 3; j++) { - d0[j] = opt->displacementFactor* val [i][j+0*3]/nrm; - d1[j] = opt->displacementFactor* val [i][j+1*3]/nrm; - d2[j] = opt->displacementFactor* val [i][j+2*3]/nrm; - } - double x = xyz[i][0]; - double y = xyz[i][1]; - double z = xyz[i][2]; - - - SPoint3 xx (x,y,z); - - // printf("%g %g %g %g %g %g %g %g %g\n",n0.x(),n0.y(),n0.z(),n1.x(),n1.y(),n1.z(),n2.x(),n2.y(),n2.z()); - - double x0[3] = {x + d0[0] + d1[0] + d2[0] , y + d0[1] + d1[1] + d2[1] , z + d0[2] + d1[2] + d2[2] }; - double x1[3] = {x - d0[0] + d1[0] + d2[0] , y - d0[1] + d1[1] + d2[1] , z - d0[2] + d1[2] + d2[2] }; - double x2[3] = {x - d0[0] - d1[0] + d2[0] , y - d0[1] - d1[1] + d2[1] , z - d0[2] - d1[2] + d2[2] }; - double x3[3] = {x + d0[0] - d1[0] + d2[0] , y + d0[1] - d1[1] + d2[1] , z + d0[2] - d1[2] + d2[2] }; - - double x4[3] = {x + d0[0] + d1[0] - d2[0] , y + d0[1] + d1[1] - d2[1] , z + d0[2] + d1[2] - d2[2] }; - double x5[3] = {x - d0[0] + d1[0] - d2[0] , y - d0[1] + d1[1] - d2[1] , z - d0[2] + d1[2] - d2[2] }; - double x6[3] = {x - d0[0] - d1[0] - d2[0] , y - d0[1] - d1[1] - d2[1] , z - d0[2] - d1[2] - d2[2] }; - double x7[3] = {x + d0[0] - d1[0] - d2[0] , y + d0[1] - d1[1] - d2[1] , z + d0[2] - d1[2] - d2[2] }; - - if ((nrm > opt->tmpMin && opt->tmpMax) || opt->saturateValues){ - addTriangle (p, opt,x0,x1,x2,xx,nrm); - addTriangle (p, opt,x2,x3,x0,xx,nrm); - addTriangle (p, opt,x4,x7,x6,xx,nrm); - addTriangle (p, opt,x6,x5,x4,xx,nrm); - addTriangle (p, opt,x0,x3,x7,xx,nrm); - addTriangle (p, opt,x7,x4,x0,xx,nrm); - addTriangle (p, opt,x1,x5,x6,xx,nrm); - addTriangle (p, opt,x6,x2,x1,xx,nrm); - addTriangle (p, opt,x0,x4,x5,xx,nrm); - addTriangle (p, opt,x5,x1,x0,xx,nrm); - addTriangle (p, opt,x3,x2,x6,xx,nrm); - addTriangle (p, opt,x6,x7,x3,xx,nrm); - } + else if(opt->tensorType == PViewOptions::Frame) { + if(opt->glyphLocation == PViewOptions::Vertex) { + for(int i = 0; i < numNodes; i++) { + double d0[3], d1[3], d2[3]; + double nrm = sqrt(val[i][0] * val[i][0] + val[i][1] * val[i][1] + + val[i][2] * val[i][2]); + + for(int j = 0; j < 3; j++) { + d0[j] = opt->displacementFactor * val[i][j + 0 * 3] / nrm; + d1[j] = opt->displacementFactor * val[i][j + 1 * 3] / nrm; + d2[j] = opt->displacementFactor * val[i][j + 2 * 3] / nrm; + } + double x = xyz[i][0]; + double y = xyz[i][1]; + double z = xyz[i][2]; + + SPoint3 xx(x, y, z); + + // printf("%g %g %g %g %g %g %g %g + //%g\n",n0.x(),n0.y(),n0.z(),n1.x(),n1.y(),n1.z(),n2.x(),n2.y(),n2.z()); + + double x0[3] = {x + d0[0] + d1[0] + d2[0], y + d0[1] + d1[1] + d2[1], + z + d0[2] + d1[2] + d2[2]}; + double x1[3] = {x - d0[0] + d1[0] + d2[0], y - d0[1] + d1[1] + d2[1], + z - d0[2] + d1[2] + d2[2]}; + double x2[3] = {x - d0[0] - d1[0] + d2[0], y - d0[1] - d1[1] + d2[1], + z - d0[2] - d1[2] + d2[2]}; + double x3[3] = {x + d0[0] - d1[0] + d2[0], y + d0[1] - d1[1] + d2[1], + z + d0[2] - d1[2] + d2[2]}; + + double x4[3] = {x + d0[0] + d1[0] - d2[0], y + d0[1] + d1[1] - d2[1], + z + d0[2] + d1[2] - d2[2]}; + double x5[3] = {x - d0[0] + d1[0] - d2[0], y - d0[1] + d1[1] - d2[1], + z - d0[2] + d1[2] - d2[2]}; + double x6[3] = {x - d0[0] - d1[0] - d2[0], y - d0[1] - d1[1] - d2[1], + z - d0[2] - d1[2] - d2[2]}; + double x7[3] = {x + d0[0] - d1[0] - d2[0], y + d0[1] - d1[1] - d2[1], + z + d0[2] - d1[2] - d2[2]}; + + if((nrm > opt->tmpMin && opt->tmpMax) || opt->saturateValues) { + addTriangle(p, opt, x0, x1, x2, xx, nrm); + addTriangle(p, opt, x2, x3, x0, xx, nrm); + addTriangle(p, opt, x4, x7, x6, xx, nrm); + addTriangle(p, opt, x6, x5, x4, xx, nrm); + addTriangle(p, opt, x0, x3, x7, xx, nrm); + addTriangle(p, opt, x7, x4, x0, xx, nrm); + addTriangle(p, opt, x1, x5, x6, xx, nrm); + addTriangle(p, opt, x6, x2, x1, xx, nrm); + addTriangle(p, opt, x0, x4, x5, xx, nrm); + addTriangle(p, opt, x5, x1, x0, xx, nrm); + addTriangle(p, opt, x3, x2, x6, xx, nrm); + addTriangle(p, opt, x6, x7, x3, xx, nrm); + } } } } - else if (opt->tensorType == PViewOptions::Ellipse || - opt->tensorType == PViewOptions::Ellipsoid) { - if(opt->glyphLocation == PViewOptions::Vertex){ - double vval[3][4]= {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}}; - for(int i = 0; i < numNodes; i++){ - for (int j = 0; j < 3; j++) { - tensor(j,0) = val [i][0+j*3]; - tensor(j,1) = val [i][1+j*3]; - tensor(j,2) = val [i][2+j*3]; + else if(opt->tensorType == PViewOptions::Ellipse || + opt->tensorType == PViewOptions::Ellipsoid) { + if(opt->glyphLocation == PViewOptions::Vertex) { + double vval[3][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}; + for(int i = 0; i < numNodes; i++) { + for(int j = 0; j < 3; j++) { + tensor(j, 0) = val[i][0 + j * 3]; + tensor(j, 1) = val[i][1 + j * 3]; + tensor(j, 2) = val[i][2 + j * 3]; } tensor.eig(S, imS, V, rightV, false); - for (int k = 0; k < 3; k++) { + for(int k = 0; k < 3; k++) { vval[k][0] = xyz[i][k]; - for (int j = 0; j < 3; j++) { - vval[k][j+1] = V(k,j)*S(j); + for(int j = 0; j < 3; j++) { + vval[k][j + 1] = V(k, j) * S(j); } } double lmax = std::max(S(0), std::max(S(1), S(2))); - unsigned int color = opt->getColor - (lmax, opt->tmpMin, opt->tmpMax, false, - (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); + unsigned int color = opt->getColor( + lmax, opt->tmpMin, opt->tmpMax, false, + (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); unsigned int col[4] = {color, color, color, color}; p->va_ellipses->add(vval[0], vval[1], vval[2], 0, col, 0, false); } } - else if(opt->glyphLocation == PViewOptions::COG){ - double vval[3][4]= {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}}; + else if(opt->glyphLocation == PViewOptions::COG) { + double vval[3][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}; for(int i = 0; i < numNodes; i++) { - for (int j = 0; j < 3; j++) { - tensor(j,0) = val [i][0+j*3]; - tensor(j,1) = val [i][1+j*3]; - tensor(j,2) = val [i][2+j*3]; + for(int j = 0; j < 3; j++) { + tensor(j, 0) = val[i][0 + j * 3]; + tensor(j, 1) = val[i][1 + j * 3]; + tensor(j, 2) = val[i][2 + j * 3]; } tensor.eig(S, imS, V, rightV, false); - for (int j = 0; j < 3; j++) { - vval[0][j+1] += V(0,j)*S(j)/numNodes; - vval[1][j+1] += V(1,j)*S(j)/numNodes; - vval[2][j+1] += V(2,j)*S(j)/numNodes; + for(int j = 0; j < 3; j++) { + vval[0][j + 1] += V(0, j) * S(j) / numNodes; + vval[1][j + 1] += V(1, j) * S(j) / numNodes; + vval[2][j + 1] += V(2, j) * S(j) / numNodes; } - vval[0][0] += xyz[i][0]/numNodes; - vval[1][0] += xyz[i][1]/numNodes; - vval[2][0] += xyz[i][2]/numNodes; + vval[0][0] += xyz[i][0] / numNodes; + vval[1][0] += xyz[i][1] / numNodes; + vval[2][0] += xyz[i][2] / numNodes; } double lmax = std::max(S(0), std::max(S(1), S(2))); - unsigned int color = opt->getColor - (lmax, opt->tmpMin, opt->tmpMax, false, - (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); + unsigned int color = opt->getColor( + lmax, opt->tmpMin, opt->tmpMax, false, + (opt->intervalsType == PViewOptions::Discrete) ? opt->nbIso : -1); unsigned int col[4] = {color, color, color, color}; p->va_ellipses->add(vval[0], vval[1], vval[2], 0, col, 0, false); } } else { - double **vval[3] = {new double*[numNodes], - new double*[numNodes], - new double*[numNodes]}; + double **vval[3] = {new double *[numNodes], new double *[numNodes], + new double *[numNodes]}; for(int i = 0; i < 3; i++) - for(int j = 0; j < numNodes; j++) - vval[i][j] = new double[3]; + for(int j = 0; j < numNodes; j++) vval[i][j] = new double[3]; for(int i = 0; i < numNodes; i++) { - for (int j = 0; j < 3; j++) { - tensor(j,0) = val [i][0+j*3]; - tensor(j,1) = val [i][1+j*3]; - tensor(j,2) = val [i][2+j*3]; + for(int j = 0; j < 3; j++) { + tensor(j, 0) = val[i][0 + j * 3]; + tensor(j, 1) = val[i][1 + j * 3]; + tensor(j, 2) = val[i][2 + j * 3]; } - tensor.eig(S, imS, V, rightV, opt->tensorType != PViewOptions::EigenVectors); - if (PViewOptions::MinEigenValue == opt->tensorType) + tensor.eig(S, imS, V, rightV, + opt->tensorType != PViewOptions::EigenVectors); + if(PViewOptions::MinEigenValue == opt->tensorType) val[i][0] = S(0); - else if (PViewOptions::MaxEigenValue == opt->tensorType) + else if(PViewOptions::MaxEigenValue == opt->tensorType) val[i][0] = S(2); - else if (PViewOptions::EigenVectors == opt->tensorType) { - for (int j = 0; j < 3; j++) { - vval[0][i][j] = V(j,0)*S(0); - vval[1][i][j] = V(j,1)*S(1); - vval[2][i][j] = V(j,2)*S(2); + else if(PViewOptions::EigenVectors == opt->tensorType) { + for(int j = 0; j < 3; j++) { + vval[0][i][j] = V(j, 0) * S(0); + vval[1][i][j] = V(j, 1) * S(1); + vval[2][i][j] = V(j, 2) * S(2); } } } - if (PViewOptions::EigenVectors == opt->tensorType) { + if(PViewOptions::EigenVectors == opt->tensorType) { addVectorElement(p, iEnt, iEle, numNodes, type, xyz, vval[0], pre); addVectorElement(p, iEnt, iEle, numNodes, type, xyz, vval[1], pre); addVectorElement(p, iEnt, iEle, numNodes, type, xyz, vval[2], pre); } else addScalarElement(p, type, xyz, val, pre, numNodes); - for(int i = 0; i < 3; i++){ - for(int j = 0; j < numNodes; j++) - delete [] vval[i][j]; - delete [] vval[i]; + for(int i = 0; i < 3; i++) { + for(int j = 0; j < numNodes; j++) delete[] vval[i][j]; + delete[] vval[i]; } } } @@ -1279,61 +1294,68 @@ static void addElementsInArrays(PView *p, bool preprocessNormalsOnly) opt->tmpBBox.reset(); int NMAX = PVIEW_NMAX; - double **xyz = new double*[NMAX]; - double **val = new double*[NMAX]; - for(int i = 0; i < NMAX; i++){ + double **xyz = new double *[NMAX]; + double **val = new double *[NMAX]; + for(int i = 0; i < NMAX; i++) { xyz[i] = new double[3]; val[i] = new double[9]; } - for(int ent = 0; ent < data->getNumEntities(opt->timeStep); ent++){ + for(int ent = 0; ent < data->getNumEntities(opt->timeStep); ent++) { if(data->skipEntity(opt->timeStep, ent)) continue; - for(int i = 0; i < data->getNumElements(opt->timeStep, ent); i++){ - if(data->skipElement(opt->timeStep, ent, i, true, opt->sampling)) continue; + for(int i = 0; i < data->getNumElements(opt->timeStep, ent); i++) { + if(data->skipElement(opt->timeStep, ent, i, true, opt->sampling)) + continue; int type = data->getType(opt->timeStep, ent, i); if(opt->skipElement(type)) continue; int numComp = data->getNumComponents(opt->timeStep, ent, i); int numNodes = data->getNumNodes(opt->timeStep, ent, i); - if(numNodes > PVIEW_NMAX){ - if(type == TYPE_POLYG || type == TYPE_POLYH){ - if(numNodes > NMAX){ - for(int j = 0; j < NMAX; j++){ - delete [] xyz[j]; - delete [] val[j]; + if(numNodes > PVIEW_NMAX) { + if(type == TYPE_POLYG || type == TYPE_POLYH) { + if(numNodes > NMAX) { + for(int j = 0; j < NMAX; j++) { + delete[] xyz[j]; + delete[] val[j]; } - delete [] xyz; - delete [] val; + delete[] xyz; + delete[] val; NMAX = numNodes; - xyz = new double*[NMAX]; - val = new double*[NMAX]; - for(int j = 0; j < NMAX; j++){ + xyz = new double *[NMAX]; + val = new double *[NMAX]; + for(int j = 0; j < NMAX; j++) { xyz[j] = new double[3]; val[j] = new double[9]; } } } else { - if(numNodesError != numNodes){ + if(numNodesError != numNodes) { numNodesError = numNodes; - Msg::Warning("Fields with %d nodes per element cannot be displayed: " - "either force the field type or select 'Adapt visualization " - "grid' if the field is high-order", numNodes); + Msg::Warning( + "Fields with %d nodes per element cannot be displayed: " + "either force the field type or select 'Adapt visualization " + "grid' if the field is high-order", + numNodes); } continue; } } - if((numComp > 9 && !opt->forceNumComponents) || opt->forceNumComponents > 9){ + if((numComp > 9 && !opt->forceNumComponents) || + opt->forceNumComponents > 9) { if(numCompError != numComp) { numCompError = numComp; - Msg::Warning("Fields with %d components cannot be displayed: " - "either force the field type or select 'Adapt visualization " - "grid' if the field is high-order", numComp); + Msg::Warning( + "Fields with %d components cannot be displayed: " + "either force the field type or select 'Adapt visualization " + "grid' if the field is high-order", + numComp); } continue; } - for(int j = 0; j < numNodes; j++){ - data->getNode(opt->timeStep, ent, i, j, xyz[j][0], xyz[j][1], xyz[j][2]); - if(opt->forceNumComponents){ - for(int k = 0; k < opt->forceNumComponents; k++){ + for(int j = 0; j < numNodes; j++) { + data->getNode(opt->timeStep, ent, i, j, xyz[j][0], xyz[j][1], + xyz[j][2]); + if(opt->forceNumComponents) { + for(int k = 0; k < opt->forceNumComponents; k++) { int comp = opt->componentMap[k]; if(comp >= 0 && comp < numComp) data->getValue(opt->timeStep, ent, i, j, comp, val[j][k]); @@ -1357,56 +1379,61 @@ static void addElementsInArrays(PView *p, bool preprocessNormalsOnly) if(opt->showElement && !data->useGaussPoints()) addOutlineElement(p, type, xyz, preprocessNormalsOnly, numNodes); - if(opt->intervalsType != PViewOptions::Numeric){ - if(data->useGaussPoints()){ - for(int j = 0; j < numNodes; j++){ - double *x2 = new double[3]; double **xyz2 = &x2; - double *v2 = new double[9]; double **val2 = &v2; + if(opt->intervalsType != PViewOptions::Numeric) { + if(data->useGaussPoints()) { + for(int j = 0; j < numNodes; j++) { + double *x2 = new double[3]; + double **xyz2 = &x2; + double *v2 = new double[9]; + double **val2 = &v2; xyz2[0][0] = xyz[j][0]; xyz2[0][1] = xyz[j][1]; xyz2[0][2] = xyz[j][2]; - for(int k = 0; k < numComp; k++) - val2[0][k] = val[j][k]; + for(int k = 0; k < numComp; k++) val2[0][k] = val[j][k]; if(numComp == 1 && opt->drawScalars) - addScalarElement(p, TYPE_PNT, xyz2, val2, preprocessNormalsOnly, numNodes); + addScalarElement(p, TYPE_PNT, xyz2, val2, preprocessNormalsOnly, + numNodes); else if(numComp == 3 && opt->drawVectors) - addVectorElement(p, ent, i, 1, TYPE_PNT, xyz2, val2, preprocessNormalsOnly); + addVectorElement(p, ent, i, 1, TYPE_PNT, xyz2, val2, + preprocessNormalsOnly); else if(numComp == 9 && opt->drawTensors) - addTensorElement(p, ent, i, 1, TYPE_PNT, xyz2, val2, preprocessNormalsOnly); - delete [] x2; - delete [] v2; + addTensorElement(p, ent, i, 1, TYPE_PNT, xyz2, val2, + preprocessNormalsOnly); + delete[] x2; + delete[] v2; } } else if(numComp == 1 && opt->drawScalars) addScalarElement(p, type, xyz, val, preprocessNormalsOnly, numNodes); else if(numComp == 3 && opt->drawVectors) - addVectorElement(p, ent, i, numNodes, type, xyz, val, preprocessNormalsOnly); + addVectorElement(p, ent, i, numNodes, type, xyz, val, + preprocessNormalsOnly); else if(numComp == 9 && opt->drawTensors) - addTensorElement(p, ent, i, numNodes, type, xyz, val, preprocessNormalsOnly); + addTensorElement(p, ent, i, numNodes, type, xyz, val, + preprocessNormalsOnly); } } } - for(int j = 0; j < NMAX; j++){ - delete [] xyz[j]; - delete [] val[j]; + for(int j = 0; j < NMAX; j++) { + delete[] xyz[j]; + delete[] val[j]; } - delete [] xyz; - delete [] val; + delete[] xyz; + delete[] val; } class initPView { - private: +private: // we try to estimate how many primitives will end up in the vertex // arrays, since reallocating the arrays takes a huge amount of time // on Windows/Cygwin int _estimateIfClipped(PView *p, int num) { if(CTX::instance()->clipWholeElements && - CTX::instance()->clipOnlyDrawIntersectingVolume){ + CTX::instance()->clipOnlyDrawIntersectingVolume) { PViewOptions *opt = p->getOptions(); - for(int clip = 0; clip < 6; clip++){ - if(opt->clip & (1 << clip)) - return (int)sqrt((double)num); + for(int clip = 0; clip < 6; clip++) { + if(opt->clip & (1 << clip)) return (int)sqrt((double)num); } } return num; @@ -1442,11 +1469,12 @@ class initPView { if(opt->intervalsType == PViewOptions::Iso) heuristic = (tets + prisms + pyrs + hexas + polyhs) / 10; else if(opt->intervalsType == PViewOptions::Continuous) - heuristic = (tris + 2 * quads + 3 * polygs + 6 * tets + - 8 * prisms + 6 * pyrs + 2 * trihs + 12 * hexas + 10 * polyhs); + heuristic = (tris + 2 * quads + 3 * polygs + 6 * tets + 8 * prisms + + 6 * pyrs + 2 * trihs + 12 * hexas + 10 * polyhs); else if(opt->intervalsType == PViewOptions::Discrete) - heuristic = (tris + 2 * quads + 3 * polygs + 6 * tets + - 8 * prisms + 6 * pyrs + 2 * trihs + 12 * hexas + 10 * polyhs) * 2; + heuristic = (tris + 2 * quads + 3 * polygs + 6 * tets + 8 * prisms + + 6 * pyrs + 2 * trihs + 12 * hexas + 10 * polyhs) * + 2; heuristic = _estimateIfClipped(p, heuristic); return heuristic + 10000; } @@ -1466,8 +1494,9 @@ class initPView { heuristic = _estimateIfClipped(p, heuristic); return heuristic + 1000; } - public: - bool operator () (PView *p) + +public: + bool operator()(PView *p) { // use adaptive data if available PViewData *data = p->getData(true); @@ -1475,14 +1504,14 @@ class initPView { if(data->getDirty() || !data->getNumTimeSteps() || !p->getChanged()) return false; - if(!opt->visible || opt->type != PViewOptions::Plot3D) - return false; + if(!opt->visible || opt->type != PViewOptions::Plot3D) return false; p->deleteVertexArrays(); - if(data->isRemote()){ + if(data->isRemote()) { // FIXME: need to rewrite option code and add nice serialization - std::string fileName = CTX::instance()->homeDir + CTX::instance()->tmpFileName; + std::string fileName = + CTX::instance()->homeDir + CTX::instance()->tmpFileName; PrintOptions(0, GMSH_FULLRC, 0, 0, fileName.c_str()); std::string options = ConvertFileToString(fileName); data->fillRemoteVertexArrays(options); @@ -1491,15 +1520,15 @@ class initPView { if(opt->useGenRaise) opt->createGeneralRaise(); - if(opt->rangeType == PViewOptions::Custom){ + if(opt->rangeType == PViewOptions::Custom) { opt->tmpMin = opt->customMin; opt->tmpMax = opt->customMax; } - else if(opt->rangeType == PViewOptions::PerTimeStep){ + else if(opt->rangeType == PViewOptions::PerTimeStep) { opt->tmpMin = data->getMin(opt->timeStep); opt->tmpMax = data->getMax(opt->timeStep); } - else{ + else { // FIXME: this is not perfect for multi-step adaptive views, as // we don't have the correct min/max info for the other steps opt->tmpMin = data->getMin(); @@ -1525,12 +1554,14 @@ class initPView { p->va_vectors->finalize(); p->va_ellipses->finalize(); - Msg::Debug("%d vertices in vertex arrays (%g Mb)", p->va_points->getNumVertices() + - p->va_lines->getNumVertices() + p->va_triangles->getNumVertices() + - p->va_vectors->getNumVertices() + p->va_ellipses->getNumVertices(), - p->va_points->getMemoryInMb() + - p->va_lines->getMemoryInMb() + p->va_triangles->getMemoryInMb() + - p->va_vectors->getMemoryInMb() + p->va_ellipses->getMemoryInMb()); + Msg::Debug( + "%d vertices in vertex arrays (%g Mb)", + p->va_points->getNumVertices() + p->va_lines->getNumVertices() + + p->va_triangles->getNumVertices() + p->va_vectors->getNumVertices() + + p->va_ellipses->getNumVertices(), + p->va_points->getMemoryInMb() + p->va_lines->getMemoryInMb() + + p->va_triangles->getMemoryInMb() + p->va_vectors->getMemoryInMb() + + p->va_ellipses->getMemoryInMb()); p->setChanged(false); return true; @@ -1550,7 +1581,8 @@ void PView::fillVertexArray(onelab::localNetworkClient *remote, int length, int tag, type, numSteps; double min, max, time, xmin, ymin, zmin, xmax, ymax, zmax; if(!VertexArray::decodeHeader(length, bytes, swap, name, tag, type, min, max, - numSteps, time, xmin, ymin, zmin, xmax, ymax, zmax)) + numSteps, time, xmin, ymin, zmin, xmax, ymax, + zmax)) return; Msg::Debug("Filling vertex array (type %d) in view tag %d", type, tag); @@ -1558,16 +1590,17 @@ void PView::fillVertexArray(onelab::localNetworkClient *remote, int length, SBoundingBox3d bbox(xmin, ymin, zmin, xmax, ymax, zmax); PView *p = PView::getViewByTag(tag); - if(!p){ + if(!p) { Msg::Info("View tag %d does not exist: creating new view", tag); - PViewData *data = new PViewDataRemote(remote, min, max, numSteps, time, bbox); + PViewData *data = + new PViewDataRemote(remote, min, max, numSteps, time, bbox); data->setName(name + " (remote)"); p = new PView(data, tag); SetBoundingBox(); } - else{ - PViewDataRemote *data = dynamic_cast<PViewDataRemote*>(p->getData()); - if(data){ + else { + PViewDataRemote *data = dynamic_cast<PViewDataRemote *>(p->getData()); + if(data) { data->setMin(min); data->setMax(max); data->setTime(time); @@ -1577,7 +1610,7 @@ void PView::fillVertexArray(onelab::localNetworkClient *remote, int length, // not perfect (does not take transformations into account) p->getOptions()->tmpBBox = bbox; - switch(type){ + switch(type) { case 1: if(p->va_points) delete p->va_points; p->va_points = new VertexArray(1, 100); @@ -1603,9 +1636,7 @@ void PView::fillVertexArray(onelab::localNetworkClient *remote, int length, p->va_ellipses = new VertexArray(4, 100); p->va_ellipses->fromChar(length, bytes, swap); break; - default: - Msg::Error("Cannot fill vertex array of type %d", type); - return; + default: Msg::Error("Cannot fill vertex array of type %d", type); return; } p->setChanged(false); diff --git a/Post/PViewX3D.cpp b/Post/PViewX3D.cpp index 936918b7c541ab9f360fa91c3310494c2b59a9eb..9c3eaf9074194b41f2ac9868fb6be5633163dda5 100644 --- a/Post/PViewX3D.cpp +++ b/Post/PViewX3D.cpp @@ -30,73 +30,81 @@ using namespace std; static bool almostEqual(double x, double y) { - return std::abs(x-y) < CTX::instance()->print.x3dPrecision; + return std::abs(x - y) < CTX::instance()->print.x3dPrecision; } -bool compare_xmin_triangle(const TriangleToSort* first, const TriangleToSort* second) +bool compare_xmin_triangle(const TriangleToSort *first, + const TriangleToSort *second) { return (first->xmin < second->xmin); } -bool compare_ymin_triangle(const TriangleToSort* first, const TriangleToSort* second) +bool compare_ymin_triangle(const TriangleToSort *first, + const TriangleToSort *second) { return (first->ymin < second->ymin); } -bool compare_zmin_triangle(const TriangleToSort* first, const TriangleToSort* second) +bool compare_zmin_triangle(const TriangleToSort *first, + const TriangleToSort *second) { return (first->zmin < second->zmin); } -bool compare_xmax_triangle(const TriangleToSort* first, const TriangleToSort* second) +bool compare_xmax_triangle(const TriangleToSort *first, + const TriangleToSort *second) { - return (first->xmax < second->xmax ); + return (first->xmax < second->xmax); } -bool compare_ymax_triangle(const TriangleToSort* first, const TriangleToSort* second) +bool compare_ymax_triangle(const TriangleToSort *first, + const TriangleToSort *second) { - return (first->ymax < second->ymax ); + return (first->ymax < second->ymax); } -bool compare_zmax_triangle(const TriangleToSort* first, const TriangleToSort* second) +bool compare_zmax_triangle(const TriangleToSort *first, + const TriangleToSort *second) { - return (first->zmax < second->zmax ); + return (first->zmax < second->zmax); } -bool PView::writeX3D(const std::string &fileName ) +bool PView::writeX3D(const std::string &fileName) { // tags duplicated triangles - int _size=1; - if (!CTX::instance()->print.x3dRemoveInnerBorders) { - for(unsigned int i = 0; i < PView::list.size(); i++){ - VertexArray *va =PView::list[i]->va_triangles; - _size += va->getNumVertices()/3; + int _size = 1; + if(!CTX::instance()->print.x3dRemoveInnerBorders) { + for(unsigned int i = 0; i < PView::list.size(); i++) { + VertexArray *va = PView::list[i]->va_triangles; + _size += va->getNumVertices() / 3; } } - int _count=0; - std::vector<bool> visible(_size) ; - if (!CTX::instance()->print.x3dRemoveInnerBorders) { + int _count = 0; + std::vector<bool> visible(_size); + if(!CTX::instance()->print.x3dRemoveInnerBorders) { // evaluate bbox of each triangle - std::list< TriangleToSort* > tlist ; + std::list<TriangleToSort *> tlist; tlist.clear(); - for(unsigned int ivp = 0; ivp < PView::list.size(); ivp++){ - VertexArray *va =PView::list[ivp]->va_triangles; - for(int ipt = 0; ipt < va->getNumVertices(); ipt += 3){ - float *p0 = va->getVertexArray(3 * ipt ); - float *p1 = va->getVertexArray(3 * (ipt + 1)); - float *p2 = va->getVertexArray(3 * (ipt + 2)); - TriangleToSort *_current = new TriangleToSort ; - _current->_index = ipt; - _current->_globalIndex=_count; visible[_count]=true; _count++; - _current->_ppv = PView::list[ivp] ; - _current->xmin = min(p0[0], min(p1[0],p2[0]) ); - _current->ymin = min(p0[1], min(p1[1],p2[1]) ); - _current->zmin = min(p0[2], min(p1[2],p2[2]) ); - _current->xmax = max(p0[0], max(p1[0],p2[0]) ); - _current->ymax = max(p0[1], max(p1[1],p2[1]) ); - _current->zmax = max(p0[2], max(p1[2],p2[2]) ); - - tlist.push_back(_current); + for(unsigned int ivp = 0; ivp < PView::list.size(); ivp++) { + VertexArray *va = PView::list[ivp]->va_triangles; + for(int ipt = 0; ipt < va->getNumVertices(); ipt += 3) { + float *p0 = va->getVertexArray(3 * ipt); + float *p1 = va->getVertexArray(3 * (ipt + 1)); + float *p2 = va->getVertexArray(3 * (ipt + 2)); + TriangleToSort *_current = new TriangleToSort; + _current->_index = ipt; + _current->_globalIndex = _count; + visible[_count] = true; + _count++; + _current->_ppv = PView::list[ivp]; + _current->xmin = min(p0[0], min(p1[0], p2[0])); + _current->ymin = min(p0[1], min(p1[1], p2[1])); + _current->zmin = min(p0[2], min(p1[2], p2[2])); + _current->xmax = max(p0[0], max(p1[0], p2[0])); + _current->ymax = max(p0[1], max(p1[1], p2[1])); + _current->zmax = max(p0[2], max(p1[2], p2[2])); + + tlist.push_back(_current); } } // sort triangles upon the position of bbbox @@ -108,82 +116,98 @@ bool PView::writeX3D(const std::string &fileName ) tlist.sort(compare_xmin_triangle); // estimate and tags triangles which are identical - std::list< TriangleToSort* >::iterator pt,nt; - for ( pt=tlist.begin() ; pt != tlist.end() ; pt++ ) { - nt=pt; nt++; - bool found=false; - VertexArray *vap = ( (*pt)->_ppv)->va_triangles; - int ip = (*pt)->_index; - float *p0 = vap->getVertexArray( 3* ip ); - float *p1 = vap->getVertexArray( 3* (ip+1) ); - float *p2 = vap->getVertexArray( 3* (ip+2) ); - int gip=(*pt)->_globalIndex; - while ( nt != tlist.end() && !found ) { - int gin=(*nt)->_globalIndex; - if( ( ( ( abs( (*pt)->xmin - (*nt)->xmin ) < 1.e-9 ) && - ( abs( (*pt)->ymin - (*nt)->ymin ) < 1.e-9) ) && - ( abs( (*pt)->zmin - (*nt)->zmin ) < 1.e-9 ) ) - && ( ( ( abs( (*pt)->xmax - (*nt)->xmax ) < 1.e-9 ) && - ( abs( (*pt)->ymax - (*nt)->ymax ) < 1.e-9) ) && - ( abs( (*pt)->zmax - (*nt)->zmax ) < 1.e-9 ) ) ) { - VertexArray *van = ( (*nt)->_ppv)->va_triangles; - int in=(*nt)->_index; - float *n0 = van->getVertexArray( 3* in ); - float *n1 = van->getVertexArray( 3* (in+1) ); - float *n2 = van->getVertexArray( 3* (in+2) ); - - if ( almostEqual(p0[0],n0[0]) && almostEqual(p0[1],n0[1]) && almostEqual(p0[2],n0[2]) ){ - if ( almostEqual(p1[0],n1[0]) && almostEqual(p1[1],n1[1]) && almostEqual(p1[2],n1[2]) ){ - if ( almostEqual(p2[0],n2[0]) && almostEqual(p2[1],n2[1]) && almostEqual(p2[2],n2[2]) ){ - found=true; + std::list<TriangleToSort *>::iterator pt, nt; + for(pt = tlist.begin(); pt != tlist.end(); pt++) { + nt = pt; + nt++; + bool found = false; + VertexArray *vap = ((*pt)->_ppv)->va_triangles; + int ip = (*pt)->_index; + float *p0 = vap->getVertexArray(3 * ip); + float *p1 = vap->getVertexArray(3 * (ip + 1)); + float *p2 = vap->getVertexArray(3 * (ip + 2)); + int gip = (*pt)->_globalIndex; + while(nt != tlist.end() && !found) { + int gin = (*nt)->_globalIndex; + if((((abs((*pt)->xmin - (*nt)->xmin) < 1.e-9) && + (abs((*pt)->ymin - (*nt)->ymin) < 1.e-9)) && + (abs((*pt)->zmin - (*nt)->zmin) < 1.e-9)) && + (((abs((*pt)->xmax - (*nt)->xmax) < 1.e-9) && + (abs((*pt)->ymax - (*nt)->ymax) < 1.e-9)) && + (abs((*pt)->zmax - (*nt)->zmax) < 1.e-9))) { + VertexArray *van = ((*nt)->_ppv)->va_triangles; + int in = (*nt)->_index; + float *n0 = van->getVertexArray(3 * in); + float *n1 = van->getVertexArray(3 * (in + 1)); + float *n2 = van->getVertexArray(3 * (in + 2)); + + if(almostEqual(p0[0], n0[0]) && almostEqual(p0[1], n0[1]) && + almostEqual(p0[2], n0[2])) { + if(almostEqual(p1[0], n1[0]) && almostEqual(p1[1], n1[1]) && + almostEqual(p1[2], n1[2])) { + if(almostEqual(p2[0], n2[0]) && almostEqual(p2[1], n2[1]) && + almostEqual(p2[2], n2[2])) { + found = true; } } - else if ( almostEqual(p1[0],n2[0]) && almostEqual(p1[1],n2[1]) && almostEqual(p1[2],n2[2]) ) { - if ( almostEqual(p2[0],n1[0]) && almostEqual(p2[1],n1[1]) && almostEqual(p2[2],n1[2]) ) { - found=true; + else if(almostEqual(p1[0], n2[0]) && almostEqual(p1[1], n2[1]) && + almostEqual(p1[2], n2[2])) { + if(almostEqual(p2[0], n1[0]) && almostEqual(p2[1], n1[1]) && + almostEqual(p2[2], n1[2])) { + found = true; } } } - else if ( almostEqual(p0[0],n1[0]) && almostEqual(p0[1],n1[1]) && almostEqual(p0[2],n1[2]) ) { - if ( almostEqual(p1[0],n0[0]) && almostEqual(p1[1],n0[1]) && almostEqual(p1[2],n0[2]) ){ - if ( almostEqual(p2[0],n2[0]) && almostEqual(p2[1],n2[1]) && almostEqual(p2[2],n2[2]) ) { - found=true; + else if(almostEqual(p0[0], n1[0]) && almostEqual(p0[1], n1[1]) && + almostEqual(p0[2], n1[2])) { + if(almostEqual(p1[0], n0[0]) && almostEqual(p1[1], n0[1]) && + almostEqual(p1[2], n0[2])) { + if(almostEqual(p2[0], n2[0]) && almostEqual(p2[1], n2[1]) && + almostEqual(p2[2], n2[2])) { + found = true; } } - else if ( almostEqual(p1[0],n2[0]) && almostEqual(p1[1],n2[1]) && almostEqual(p1[2],n2[2]) ) { - if ( almostEqual(p2[0],n0[0]) && almostEqual(p2[1],n0[1]) && almostEqual(p2[2],n0[2]) ) { - found=true; + else if(almostEqual(p1[0], n2[0]) && almostEqual(p1[1], n2[1]) && + almostEqual(p1[2], n2[2])) { + if(almostEqual(p2[0], n0[0]) && almostEqual(p2[1], n0[1]) && + almostEqual(p2[2], n0[2])) { + found = true; } } } - else if ( almostEqual(p0[0],n2[0]) && almostEqual(p0[1],n2[1]) && almostEqual(p0[2],n2[2]) ) { - if ( almostEqual(p1[0],n0[0]) && almostEqual(p1[1],n0[1]) && almostEqual(p1[2],n0[2]) ){ - if ( almostEqual(p2[0],n1[0]) && almostEqual(p2[1],n1[1]) && almostEqual(p2[2],n1[2]) ) { - found=true; + else if(almostEqual(p0[0], n2[0]) && almostEqual(p0[1], n2[1]) && + almostEqual(p0[2], n2[2])) { + if(almostEqual(p1[0], n0[0]) && almostEqual(p1[1], n0[1]) && + almostEqual(p1[2], n0[2])) { + if(almostEqual(p2[0], n1[0]) && almostEqual(p2[1], n1[1]) && + almostEqual(p2[2], n1[2])) { + found = true; } } - else if ( almostEqual(p1[0],n1[0]) && almostEqual(p1[1],n1[1]) && almostEqual(p1[2],n1[2]) ) { - if ( almostEqual(p2[0],n0[0]) && almostEqual(p2[1],n0[1]) && almostEqual(p2[2],n0[2]) ) { - found=true; + else if(almostEqual(p1[0], n1[0]) && almostEqual(p1[1], n1[1]) && + almostEqual(p1[2], n1[2])) { + if(almostEqual(p2[0], n0[0]) && almostEqual(p2[1], n0[1]) && + almostEqual(p2[2], n0[2])) { + found = true; } } } - if (found){ - visible[gip]=false; - visible[gin]=false; - if ( pt != tlist.end() ) pt++; - } - else{ - nt++; - } - } - else { - nt = tlist.end(); - } + if(found) { + visible[gip] = false; + visible[gin] = false; + if(pt != tlist.end()) pt++; + } + else { + nt++; + } + } + else { + nt = tlist.end(); + } } } - for ( pt=tlist.begin() ; pt != tlist.end() ; pt++) { + for(pt = tlist.begin(); pt != tlist.end(); pt++) { // delete (*pt); } } @@ -191,184 +215,215 @@ bool PView::writeX3D(const std::string &fileName ) // beginning writing x3d file time_t rawtime; - struct tm * timeinfo; - time ( &rawtime ); - timeinfo = localtime ( &rawtime ); + struct tm *timeinfo; + time(&rawtime); + timeinfo = localtime(&rawtime); FILE *fp = Fopen(fileName.c_str(), "w"); - if(!fp){ + if(!fp) { Msg::Error("Unable to open file '%s'", fileName.c_str()); return false; } // x3 Header - fprintf(fp,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - fprintf(fp,"<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.3//EN\" " - "\"http://www.web3d.org/specifications/x3d-3.3.dtd\">\n"); - fprintf(fp,"<X3D profile='Interchange' version='3.3' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' >\n"); - fprintf(fp," <head>\n"); - fprintf(fp," <meta name='title' content='PView'/> \n"); - fprintf(fp," <meta name='description' content='%s'/>\n", fileName.c_str()); - fprintf(fp," <meta name='creator' content='gmsh'/> \n"); - fprintf(fp," <meta name='created' content=' %s '/>\n", asctime(timeinfo) ); - fprintf(fp," </head>\n"); + fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + fprintf(fp, "<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.3//EN\" " + "\"http://www.web3d.org/specifications/x3d-3.3.dtd\">\n"); + fprintf(fp, "<X3D profile='Interchange' version='3.3' " + "xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' >\n"); + fprintf(fp, " <head>\n"); + fprintf(fp, " <meta name='title' content='PView'/> \n"); + fprintf(fp, " <meta name='description' content='%s'/>\n", + fileName.c_str()); + fprintf(fp, " <meta name='creator' content='gmsh'/> \n"); + fprintf(fp, " <meta name='created' content=' %s '/>\n", + asctime(timeinfo)); + fprintf(fp, " </head>\n"); // Viewport - SBoundingBox3d bb(0.,0.,0.,0.,0.,0.); - for(std::vector<PView*>::iterator pvit=PView::list.begin() ; pvit < PView::list.end(); pvit++){ + SBoundingBox3d bb(0., 0., 0., 0., 0., 0.); + for(std::vector<PView *>::iterator pvit = PView::list.begin(); + pvit < PView::list.end(); pvit++) { PViewData *data = (*pvit)->getData(true); PViewOptions *opt = (*pvit)->getOptions(); - if( !data->getDirty() && opt->visible ) { - bb+= data->getBoundingBox(opt->timeStep); + if(!data->getDirty() && opt->visible) { + bb += data->getBoundingBox(opt->timeStep); } } SPoint3 _center = bb.center(); double _diagonal = bb.diag(); - fprintf(fp," <Scene>\n"); - fprintf(fp," <Viewpoint description='Book View' orientation='0 0. 1. 0.' position='%g %g %g'/> \n", - _center.x(), _center.y() , _center.z()+_diagonal*1.2 ); - fprintf(fp," <Background skyColor='.7 .7 1'/> \n"); + fprintf(fp, " <Scene>\n"); + fprintf(fp, + " <Viewpoint description='Book View' orientation='0 0. 1. 0.' " + "position='%g %g %g'/> \n", + _center.x(), _center.y(), _center.z() + _diagonal * 1.2); + fprintf(fp, " <Background skyColor='.7 .7 1'/> \n"); // HUD : Head Up Display - // here contour/scalebar legends in frame (-.45,-.28, 0.) and (.45, .28,0.) : viewport .9 x .56 - double viewportWidth =.9 ; - double viewportHeight =.56 ; - double font_size = 0.02; - if ( !CTX::instance()->print.x3dCompatibility ) { - std::vector<PView*> scales; - for(unsigned int i = 0; i < PView::list.size(); i++){ + // here contour/scalebar legends in frame (-.45,-.28, 0.) and (.45, .28,0.) : + // viewport .9 x .56 + double viewportWidth = .9; + double viewportHeight = .56; + double font_size = 0.02; + if(!CTX::instance()->print.x3dCompatibility) { + std::vector<PView *> scales; + for(unsigned int i = 0; i < PView::list.size(); i++) { PViewData *data = PView::list[i]->getData(); PViewOptions *opt = PView::list[i]->getOptions(); - if(!data->getDirty() - && opt->visible && opt->showScale - && opt->type == PViewOptions::Plot3D && data->getNumElements() - ) - scales.push_back(PView::list[i]); + if(!data->getDirty() && opt->visible && opt->showScale && + opt->type == PViewOptions::Plot3D && data->getNumElements()) + scales.push_back(PView::list[i]); } - - if ( !scales.empty() ){ - fprintf(fp," <ProtoDeclare appinfo='Heads-up display (HUD)' name='HeadsUpDisplay'> \n"); - fprintf(fp," <ProtoInterface> \n"); - fprintf(fp," <field accessType='inputOutput' appinfo='offset position for HUD' " - "name='screenOffset' type='SFVec3f' value='%g %g %g'/> \n", _center.x(), _center.y() , - 5*_center.z()+_diagonal*1.2 ); - fprintf(fp," <field accessType='inputOutput' appinfo='X3D content positioned at HUD offset' " - "name='children' type='MFNode'> \n"); - fprintf(fp," </field> \n"); - fprintf(fp," <field accessType='outputOnly' appinfo='HUD position update (in world " - "coordinates) relative to original location' name='position_changed' type='SFVec3f'/> \n"); - fprintf(fp," <field accessType='outputOnly' appinfo='HUD orientation update relative to " - "original location' name='orientation_changed' type='SFRotation'/> \n"); - fprintf(fp," </ProtoInterface> \n"); - fprintf(fp," <ProtoBody> \n"); - fprintf(fp," <Group bboxCenter=\"%g %g %g\"> \n", _center.x(), _center.y() , _center.z() ); - fprintf(fp," <Transform DEF='HudContainer'> \n"); - fprintf(fp," <Transform> \n"); - fprintf(fp," <IS> \n"); - fprintf(fp," <connect nodeField='translation' protoField='screenOffset'/> \n"); - fprintf(fp," </IS> \n"); - fprintf(fp," <Group> \n"); - fprintf(fp," <IS> \n"); - fprintf(fp," <connect nodeField='children' protoField='children'/> \n"); - fprintf(fp," </IS> \n"); - fprintf(fp," </Group> \n"); - fprintf(fp," </Transform> \n"); - fprintf(fp," </Transform> \n"); - fprintf(fp," <ProximitySensor DEF='HereIAm' size='10000000 10000000 10000000'> \n"); - fprintf(fp," <IS> \n"); - fprintf(fp," <connect nodeField='position_changed' protoField='position_changed'/> \n"); - fprintf(fp," <connect nodeField='orientation_changed' protoField='orientation_changed'/> \n"); - fprintf(fp," </IS> \n"); - fprintf(fp," </ProximitySensor> \n"); - fprintf(fp," <ROUTE fromField='orientation_changed' fromNode='HereIAm' toField='rotation' " - "toNode='HudContainer'/> \n"); - fprintf(fp," <ROUTE fromField='position_changed' fromNode='HereIAm' toField='translation' " - "toNode='HudContainer'/> \n"); - fprintf(fp," </Group> \n"); - fprintf(fp," </ProtoBody> \n"); - fprintf(fp," </ProtoDeclare> \n"); + if(!scales.empty()) { + fprintf(fp, " <ProtoDeclare appinfo='Heads-up display (HUD)' " + "name='HeadsUpDisplay'> \n"); + fprintf(fp, " <ProtoInterface> \n"); + fprintf(fp, + " <field accessType='inputOutput' appinfo='offset " + "position for HUD' " + "name='screenOffset' type='SFVec3f' value='%g %g %g'/> \n", + _center.x(), _center.y(), 5 * _center.z() + _diagonal * 1.2); + fprintf(fp, " <field accessType='inputOutput' appinfo='X3D " + "content positioned at HUD offset' " + "name='children' type='MFNode'> \n"); + fprintf(fp, " </field> \n"); + fprintf(fp, " <field accessType='outputOnly' appinfo='HUD " + "position update (in world " + "coordinates) relative to original location' " + "name='position_changed' type='SFVec3f'/> \n"); + fprintf( + fp, + " <field accessType='outputOnly' appinfo='HUD orientation " + "update relative to " + "original location' name='orientation_changed' type='SFRotation'/> \n"); + fprintf(fp, " </ProtoInterface> \n"); + fprintf(fp, " <ProtoBody> \n"); + fprintf(fp, " <Group bboxCenter=\"%g %g %g\"> \n", _center.x(), + _center.y(), _center.z()); + fprintf(fp, " <Transform DEF='HudContainer'> \n"); + fprintf(fp, " <Transform> \n"); + fprintf(fp, " <IS> \n"); + fprintf(fp, " <connect nodeField='translation' " + "protoField='screenOffset'/> \n"); + fprintf(fp, " </IS> \n"); + fprintf(fp, " <Group> \n"); + fprintf(fp, " <IS> \n"); + fprintf(fp, " <connect nodeField='children' " + "protoField='children'/> \n"); + fprintf(fp, " </IS> \n"); + fprintf(fp, " </Group> \n"); + fprintf(fp, " </Transform> \n"); + fprintf(fp, " </Transform> \n"); + fprintf(fp, " <ProximitySensor DEF='HereIAm' size='10000000 " + "10000000 10000000'> \n"); + fprintf(fp, " <IS> \n"); + fprintf(fp, " <connect nodeField='position_changed' " + "protoField='position_changed'/> \n"); + fprintf(fp, " <connect nodeField='orientation_changed' " + "protoField='orientation_changed'/> \n"); + fprintf(fp, " </IS> \n"); + fprintf(fp, " </ProximitySensor> \n"); + fprintf(fp, " <ROUTE fromField='orientation_changed' " + "fromNode='HereIAm' toField='rotation' " + "toNode='HudContainer'/> \n"); + fprintf(fp, " <ROUTE fromField='position_changed' " + "fromNode='HereIAm' toField='translation' " + "toNode='HudContainer'/> \n"); + fprintf(fp, " </Group> \n"); + fprintf(fp, " </ProtoBody> \n"); + fprintf(fp, " </ProtoDeclare> \n"); // fprintf(fp," <Background skyColor='.7 .7 1'/> \n"); - fprintf(fp," <Viewpoint description='Book View' orientation='0 0. 1. 0.' position='%g %g %g'/> \n", - _center.x(), _center.y() , _center.z()+_diagonal*1.2 ); - fprintf(fp," <!-- ProtoDeclare is the \"cookie cutter\" template, ProtoInstance creates an actual " - "occurrence --> \n"); - fprintf(fp," <ProtoInstance DEF='HeadsUpDisplay' name='HeadsUpDisplay'> \n"); - fprintf(fp," <!-- example: upper left-hand corner of screen (x=-2, y=1) and set back z=-5 from " - "user view --> \n"); - fprintf(fp," <fieldValue name='screenOffset' value='%g %g %g'/> \n", - _center.x(), _center.y() , _center.z()-.2*_diagonal ); - fprintf(fp," <fieldValue name='children'> \n"); + fprintf(fp, + " <Viewpoint description='Book View' orientation='0 0. 1. 0.' " + "position='%g %g %g'/> \n", + _center.x(), _center.y(), _center.z() + _diagonal * 1.2); + fprintf(fp, " <!-- ProtoDeclare is the \"cookie cutter\" template, " + "ProtoInstance creates an actual " + "occurrence --> \n"); + fprintf( + fp, + " <ProtoInstance DEF='HeadsUpDisplay' name='HeadsUpDisplay'> \n"); + fprintf(fp, " <!-- example: upper left-hand corner of screen (x=-2, " + "y=1) and set back z=-5 from " + "user view --> \n"); + fprintf(fp, " <fieldValue name='screenOffset' value='%g %g %g'/> \n", + _center.x(), _center.y(), _center.z() - .2 * _diagonal); + fprintf(fp, " <fieldValue name='children'> \n"); char label[1024]; - double maxw = 10.*font_size*3./4.; - const double tic = viewportWidth/100 ; - const double bar_size = tic*1.6 ; + double maxw = 10. * font_size * 3. / 4.; + const double tic = viewportWidth / 100; + const double bar_size = tic * 1.6; double width = 0., width_prev = 0., width_total = 0.; for(unsigned int i = 0; i < scales.size(); i++) { - PView *p = scales[i]; - PViewData *data = p->getData(); - PViewOptions *opt = p->getOptions(); - - if(!opt->autoPosition) { - double w= viewportWidth/3; - double h= viewportHeight/11; - double x=0.; - double y=-viewportHeight; - writeX3DScale(fp, p, x, y, w, h, tic, CTX::instance()->post.horizontalScales,font_size); - } - else if(CTX::instance()->post.horizontalScales){ - double ysep = viewportHeight/40; - double xc = 0.; - if(scales.size() == 1){ - double w = viewportWidth / 2., h = bar_size; - double x = xc - w / 2., y = -viewportHeight/2 + ysep; - writeX3DScale(fp, p, x, y, w, h, tic, 1,font_size); - } - else{ - double xsep = maxw / 4. + viewportWidth / 10.; - double w = ( viewportWidth - 4. * xsep) / 2.; - if(w < 30.*viewportWidth/1000) w =30.*viewportWidth/1000 ; - double h = bar_size; - double x = xc - (i % 2 ? -xsep / 1.5 : w + xsep / 1.5); - double y = -viewportHeight/2 + ysep + (i / 2) * (bar_size + tic +2 * font_size + ysep); - writeX3DScale(fp, p, x, y, w, h, tic, 1,font_size); - } - } - else{ - double xsep = viewportWidth / 50; - double dy = 2. * font_size ; - if(scales.size() == 1){ - double ysep = ( viewportHeight) / 6.; - double w = bar_size, h = viewportHeight - 2 * ysep - dy; - double x = -viewportWidth/2 + xsep, y = -viewportHeight/2 + ysep + dy; - writeX3DScale(fp, p, x, y, w, h, tic, 1,font_size); - - } - else{ - double ysep = viewportHeight / 30.; - double w = bar_size; - double h = ( viewportHeight - 3 * ysep - 2.5 * dy) / 2.; - double x = -viewportWidth/2 + xsep + width_total + (i / 2) * xsep; - double y = -viewportHeight/2 + ysep + dy + (1 - i % 2) * (h + 1.5 * dy + ysep); - writeX3DScale(fp, p, x, y, w, h, tic, 1, font_size); - } - // compute width - width_prev = width; - width =bar_size + tic + 10.* font_size *3/4; - if(opt->showTime){ - char tmp[256]; - sprintf(tmp, opt->format.c_str(), data->getTime(opt->timeStep)); - sprintf(label, "%s (%s)", data->getName().c_str(), tmp); - } - else{ - sprintf(label, "%s", data->getName().c_str()); - } - width =max(width, strlen(label)* font_size *3/4); - if(i % 2) width_total += std::max(bar_size + width, bar_size + width_prev); - } + PView *p = scales[i]; + PViewData *data = p->getData(); + PViewOptions *opt = p->getOptions(); + + if(!opt->autoPosition) { + double w = viewportWidth / 3; + double h = viewportHeight / 11; + double x = 0.; + double y = -viewportHeight; + writeX3DScale(fp, p, x, y, w, h, tic, + CTX::instance()->post.horizontalScales, font_size); + } + else if(CTX::instance()->post.horizontalScales) { + double ysep = viewportHeight / 40; + double xc = 0.; + if(scales.size() == 1) { + double w = viewportWidth / 2., h = bar_size; + double x = xc - w / 2., y = -viewportHeight / 2 + ysep; + writeX3DScale(fp, p, x, y, w, h, tic, 1, font_size); + } + else { + double xsep = maxw / 4. + viewportWidth / 10.; + double w = (viewportWidth - 4. * xsep) / 2.; + if(w < 30. * viewportWidth / 1000) w = 30. * viewportWidth / 1000; + double h = bar_size; + double x = xc - (i % 2 ? -xsep / 1.5 : w + xsep / 1.5); + double y = -viewportHeight / 2 + ysep + + (i / 2) * (bar_size + tic + 2 * font_size + ysep); + writeX3DScale(fp, p, x, y, w, h, tic, 1, font_size); + } + } + else { + double xsep = viewportWidth / 50; + double dy = 2. * font_size; + if(scales.size() == 1) { + double ysep = (viewportHeight) / 6.; + double w = bar_size, h = viewportHeight - 2 * ysep - dy; + double x = -viewportWidth / 2 + xsep, + y = -viewportHeight / 2 + ysep + dy; + writeX3DScale(fp, p, x, y, w, h, tic, 1, font_size); + } + else { + double ysep = viewportHeight / 30.; + double w = bar_size; + double h = (viewportHeight - 3 * ysep - 2.5 * dy) / 2.; + double x = -viewportWidth / 2 + xsep + width_total + (i / 2) * xsep; + double y = -viewportHeight / 2 + ysep + dy + + (1 - i % 2) * (h + 1.5 * dy + ysep); + writeX3DScale(fp, p, x, y, w, h, tic, 1, font_size); + } + // compute width + width_prev = width; + width = bar_size + tic + 10. * font_size * 3 / 4; + if(opt->showTime) { + char tmp[256]; + sprintf(tmp, opt->format.c_str(), data->getTime(opt->timeStep)); + sprintf(label, "%s (%s)", data->getName().c_str(), tmp); + } + else { + sprintf(label, "%s", data->getName().c_str()); + } + width = max(width, strlen(label) * font_size * 3 / 4); + if(i % 2) + width_total += std::max(bar_size + width, bar_size + width_prev); + } } - fprintf(fp," </fieldValue> \n"); - fprintf(fp," </ProtoInstance> \n"); + fprintf(fp, " </fieldValue> \n"); + fprintf(fp, " </ProtoInstance> \n"); } } @@ -385,20 +440,20 @@ bool PView::writeX3D(const std::string &fileName ) if( !data->getDirty() && opt->visible ) { va=PView::list[ipv]->va_points; for(int ipt = 0; ipt < va->getNumVertices(); ipt++){ - float *p = va->getVertexArray(3 * ipt); - double f = 1.; - if(opt->pointType > 1){ - char *n = va->getNormalArray(3 * ipt); - f = char2float(*n); - } - if(opt->pointType == 2){ - int s = (int)(opt->pointSize * f); - if(s){ - fprintf(fp,"points : %g %g %g\n", p[0], p[1], p[2]); - } - } - else - fprintf(fp,"sphere : %g %g %g \n", p[0], p[1], p[2] ); + float *p = va->getVertexArray(3 * ipt); + double f = 1.; + if(opt->pointType > 1){ + char *n = va->getNormalArray(3 * ipt); + f = char2float(*n); + } + if(opt->pointType == 2){ + int s = (int)(opt->pointSize * f); + if(s){ + fprintf(fp,"points : %g %g %g\n", p[0], p[1], p[2]); + } + } + else + fprintf(fp,"sphere : %g %g %g \n", p[0], p[1], p[2] ); } } // enf if dirty @@ -406,314 +461,327 @@ bool PView::writeX3D(const std::string &fileName ) */ // lines - int _ind=0; - fprintf(fp," <Shape> \n"); - fprintf(fp," <IndexedLineSet coordIndex=' "); - for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++){ + int _ind = 0; + fprintf(fp, " <Shape> \n"); + fprintf(fp, " <IndexedLineSet coordIndex=' "); + for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++) { PViewData *data = PView::list[ipv]->getData(true); PViewOptions *opt = PView::list[ipv]->getOptions(); - if( !data->getDirty() && opt->visible ) { - va=PView::list[ipv]->va_lines; - for(int ipt = 0; ipt < va->getNumVertices(); ipt += 2){ - if(opt->lineType != 2 && opt->lineType != 1) { - fprintf(fp,"%i %i %i ",_ind,_ind+1,-1); - } - _ind += 2; + if(!data->getDirty() && opt->visible) { + va = PView::list[ipv]->va_lines; + for(int ipt = 0; ipt < va->getNumVertices(); ipt += 2) { + if(opt->lineType != 2 && opt->lineType != 1) { + fprintf(fp, "%i %i %i ", _ind, _ind + 1, -1); + } + _ind += 2; } } // end if dirty - }// end for loop on PView::list - fprintf(fp,"'>\n"); - fprintf(fp," <Coordinate DEF='TurnPoints' point=' "); - for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++){ + } // end for loop on PView::list + fprintf(fp, "'>\n"); + fprintf(fp, " <Coordinate DEF='TurnPoints' point=' "); + for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++) { PViewData *data = PView::list[ipv]->getData(true); PViewOptions *opt = PView::list[ipv]->getOptions(); - if( !data->getDirty() && opt->visible ) { - va=PView::list[ipv]->va_lines; - for(int ipt = 0; ipt < va->getNumVertices(); ipt += 2){ - if(opt->lineType != 2 && opt->lineType != 1) { - float *p0 = va->getVertexArray(3 * ipt); - float *p1 = va->getVertexArray(3 * (ipt + 1)); - fprintf(fp,"%g %g %g %g %g %g ", p0[0], p0[1], p0[2], p1[0], p1[1], p1[2]); - } + if(!data->getDirty() && opt->visible) { + va = PView::list[ipv]->va_lines; + for(int ipt = 0; ipt < va->getNumVertices(); ipt += 2) { + if(opt->lineType != 2 && opt->lineType != 1) { + float *p0 = va->getVertexArray(3 * ipt); + float *p1 = va->getVertexArray(3 * (ipt + 1)); + fprintf(fp, "%g %g %g %g %g %g ", p0[0], p0[1], p0[2], p1[0], p1[1], + p1[2]); + } } // end for } // end if dirty - }// end for loop on PView::list - fprintf(fp,"'/> \n"); - fprintf(fp," </IndexedLineSet> \n"); - fprintf(fp," <Appearance> \n"); - fprintf(fp," <Material emissiveColor='0 0 0'/>\n"); - fprintf(fp," <LineProperties containerField='lineProperties'> \n"); - fprintf(fp," </LineProperties> \n"); - fprintf(fp," </Appearance> \n"); - fprintf(fp," </Shape>\n"); - - - - //vectors - colored arrow replaced by colored cones - for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++){ + } // end for loop on PView::list + fprintf(fp, "'/> \n"); + fprintf(fp, " </IndexedLineSet> \n"); + fprintf(fp, " <Appearance> \n"); + fprintf(fp, " <Material emissiveColor='0 0 0'/>\n"); + fprintf(fp, " <LineProperties containerField='lineProperties'> \n"); + fprintf(fp, " </LineProperties> \n"); + fprintf(fp, " </Appearance> \n"); + fprintf(fp, " </Shape>\n"); + + // vectors - colored arrow replaced by colored cones + for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++) { data = PView::list[ipv]->getData(true); - opt = PView::list[ipv]->getOptions(); - if( !data->getDirty() && opt->visible ) { - va=PView::list[ipv]->va_vectors; - for(int iv = 0; iv < va->getNumVertices(); iv += 2){ - float *s = va->getVertexArray(3 * iv); - float *v = va->getVertexArray(3 * (iv + 1)); - unsigned char *c = va->getColorArray(4 * iv); - double rgba[4]; - UnsignedChar2rgba(c,rgba) ; - double l = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - double lmax = opt->tmpMax; - if((l || opt->vectorType == 6) && lmax){ - double scale=.5/_diagonal; - double theta=acos(v[1]/l); - fprintf(fp," <Transform rotation='%g %g %g %g' translation='%e %e %e' >\n" - ,v[2],0.,-v[0],theta - ,s[0]+.5*scale*v[0],s[1]+.5*scale*v[1],s[2]+.5*scale*v[2]); - fprintf(fp," <Shape>\n"); - fprintf(fp," <Cone bottomRadius='%g' height='%g'/>\n", - .05*l*scale, - l*scale); - fprintf(fp," <Appearance>\n"); - fprintf(fp," <Material diffuseColor='%g %g %g'/>\n",rgba[0], rgba[1], rgba[2]); - fprintf(fp," </Appearance>\n"); - fprintf(fp," </Shape>\n"); - fprintf(fp," </Transform>\n"); - } // end if l + opt = PView::list[ipv]->getOptions(); + if(!data->getDirty() && opt->visible) { + va = PView::list[ipv]->va_vectors; + for(int iv = 0; iv < va->getNumVertices(); iv += 2) { + float *s = va->getVertexArray(3 * iv); + float *v = va->getVertexArray(3 * (iv + 1)); + unsigned char *c = va->getColorArray(4 * iv); + double rgba[4]; + UnsignedChar2rgba(c, rgba); + double l = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + double lmax = opt->tmpMax; + if((l || opt->vectorType == 6) && lmax) { + double scale = .5 / _diagonal; + double theta = acos(v[1] / l); + fprintf( + fp, + " <Transform rotation='%g %g %g %g' translation='%e %e %e' >\n", + v[2], 0., -v[0], theta, s[0] + .5 * scale * v[0], + s[1] + .5 * scale * v[1], s[2] + .5 * scale * v[2]); + fprintf(fp, " <Shape>\n"); + fprintf(fp, " <Cone bottomRadius='%g' height='%g'/>\n", + .05 * l * scale, l * scale); + fprintf(fp, " <Appearance>\n"); + fprintf(fp, " <Material diffuseColor='%g %g %g'/>\n", + rgba[0], rgba[1], rgba[2]); + fprintf(fp, " </Appearance>\n"); + fprintf(fp, " </Shape>\n"); + fprintf(fp, " </Transform>\n"); + } // end if l } // end for iv } // end if dirty - }// end for loop on PView::list - - - //triangles - colored triangles - //count all visible triangles of previous visited PView - _count=0; - _ind=0.; - fprintf(fp," <Transform> \n"); - fprintf(fp," <Shape> \n"); - fprintf(fp," <Appearance> \n"); - fprintf(fp," <Material transparency='%g' ", CTX::instance()->print.x3dTransparency ); - fprintf(fp," ambientIntensity='0.15' diffuseColor='.5 .5 .5' emissiveColor='0 0 0' "); - fprintf(fp," shininess='0.1' specularColor='.1 .1 .1' /> \n"); - fprintf(fp," </Appearance> \n"); - fprintf(fp," <IndexedTriangleSet solid='true' ccw='true' colorPerVertex='true' \n "); - fprintf(fp," normalPerVertex='true' containerField='geometry' index=' "); - for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++){ + } // end for loop on PView::list + + // triangles - colored triangles + // count all visible triangles of previous visited PView + _count = 0; + _ind = 0.; + fprintf(fp, " <Transform> \n"); + fprintf(fp, " <Shape> \n"); + fprintf(fp, " <Appearance> \n"); + fprintf(fp, " <Material transparency='%g' ", + CTX::instance()->print.x3dTransparency); + fprintf(fp, " ambientIntensity='0.15' diffuseColor='.5 .5 .5' " + "emissiveColor='0 0 0' "); + fprintf(fp, " shininess='0.1' specularColor='.1 .1 .1' /> \n"); + fprintf(fp, " </Appearance> \n"); + fprintf(fp, " <IndexedTriangleSet solid='true' ccw='true' " + "colorPerVertex='true' \n "); + fprintf( + fp, " normalPerVertex='true' containerField='geometry' index=' "); + for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++) { data = PView::list[ipv]->getData(true); - opt = PView::list[ipv]->getOptions(); - if( !data->getDirty() && opt->visible ) { - va=PView::list[ipv]->va_triangles; - for(int ipt = 0; ipt < va->getNumVertices(); ipt += 3){ - if ( (!CTX::instance()->print.x3dRemoveInnerBorders && visible[_count] ) || - CTX::instance()->print.x3dRemoveInnerBorders ) { - fprintf(fp,"%i %i %i ",_ind,_ind+1,_ind+2); - _ind += 3; - } - _count++; + opt = PView::list[ipv]->getOptions(); + if(!data->getDirty() && opt->visible) { + va = PView::list[ipv]->va_triangles; + for(int ipt = 0; ipt < va->getNumVertices(); ipt += 3) { + if((!CTX::instance()->print.x3dRemoveInnerBorders && visible[_count]) || + CTX::instance()->print.x3dRemoveInnerBorders) { + fprintf(fp, "%i %i %i ", _ind, _ind + 1, _ind + 2); + _ind += 3; + } + _count++; } } // enf if dirty - }// end loop on PView::list + } // end loop on PView::list - fprintf(fp," ' > \n"); - fprintf(fp," <Coordinate point='"); - _count=0; - for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++){ + fprintf(fp, " ' > \n"); + fprintf(fp, " <Coordinate point='"); + _count = 0; + for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++) { data = PView::list[ipv]->getData(true); - opt = PView::list[ipv]->getOptions(); - if( !data->getDirty() && opt->visible ) { - va=PView::list[ipv]->va_triangles; - for(int ipt = 0; ipt < va->getNumVertices(); ipt += 3){ - if ( ( !CTX::instance()->print.x3dRemoveInnerBorders && visible[_count] ) || - CTX::instance()->print.x3dRemoveInnerBorders) { - float *p0 = va->getVertexArray(3 * ipt); - float *p1 = va->getVertexArray(3 * (ipt + 1)); - float *p2 = va->getVertexArray(3 * (ipt + 2)); - - fprintf(fp,"%e %e %e %e %e %e %e %e %e " - , p0[0], p0[1], p0[2] - , p1[0], p1[1], p1[2] - , p2[0], p2[1], p2[2]); - } - _count++; + opt = PView::list[ipv]->getOptions(); + if(!data->getDirty() && opt->visible) { + va = PView::list[ipv]->va_triangles; + for(int ipt = 0; ipt < va->getNumVertices(); ipt += 3) { + if((!CTX::instance()->print.x3dRemoveInnerBorders && visible[_count]) || + CTX::instance()->print.x3dRemoveInnerBorders) { + float *p0 = va->getVertexArray(3 * ipt); + float *p1 = va->getVertexArray(3 * (ipt + 1)); + float *p2 = va->getVertexArray(3 * (ipt + 2)); + + fprintf(fp, "%e %e %e %e %e %e %e %e %e ", p0[0], p0[1], p0[2], p1[0], + p1[1], p1[2], p2[0], p2[1], p2[2]); + } + _count++; } } // enf if dirty - }// end loop on PView::list - fprintf(fp," '/> \n"); + } // end loop on PView::list + fprintf(fp, " '/> \n"); - fprintf(fp," <Color color='"); - _count=0; - for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++){ + fprintf(fp, " <Color color='"); + _count = 0; + for(unsigned int ipv = 0; ipv < PView::list.size(); ipv++) { data = PView::list[ipv]->getData(true); - opt = PView::list[ipv]->getOptions(); - if( !data->getDirty() && opt->visible ) { - va=PView::list[ipv]->va_triangles; - for(int ipt = 0; ipt < va->getNumVertices(); ipt += 3){ - if ( ( !CTX::instance()->print.x3dRemoveInnerBorders && visible[_count] ) || - CTX::instance()->print.x3dRemoveInnerBorders ) { - unsigned char *c0 = va->getColorArray(4 * ipt); - unsigned char *c1 = va->getColorArray(4 * (ipt+1)); - unsigned char *c2 = va->getColorArray(4 * (ipt+2)); - double rgba0[4] , rgba1[4] ,rgba2[4]; - UnsignedChar2rgba(c0,rgba0) ; - UnsignedChar2rgba(c1,rgba1) ; - UnsignedChar2rgba(c2,rgba2) ; - - fprintf(fp,"%g %g %g %g %g %g %g %g %g " - , rgba0[0],rgba0[1],rgba0[2] - , rgba1[0],rgba1[1],rgba1[2] - , rgba2[0],rgba2[1],rgba2[2]); - - } - _count++; + opt = PView::list[ipv]->getOptions(); + if(!data->getDirty() && opt->visible) { + va = PView::list[ipv]->va_triangles; + for(int ipt = 0; ipt < va->getNumVertices(); ipt += 3) { + if((!CTX::instance()->print.x3dRemoveInnerBorders && visible[_count]) || + CTX::instance()->print.x3dRemoveInnerBorders) { + unsigned char *c0 = va->getColorArray(4 * ipt); + unsigned char *c1 = va->getColorArray(4 * (ipt + 1)); + unsigned char *c2 = va->getColorArray(4 * (ipt + 2)); + double rgba0[4], rgba1[4], rgba2[4]; + UnsignedChar2rgba(c0, rgba0); + UnsignedChar2rgba(c1, rgba1); + UnsignedChar2rgba(c2, rgba2); + + fprintf(fp, "%g %g %g %g %g %g %g %g %g ", rgba0[0], rgba0[1], + rgba0[2], rgba1[0], rgba1[1], rgba1[2], rgba2[0], rgba2[1], + rgba2[2]); + } + _count++; } } // enf if dirty - }// end loop on PView::list - fprintf(fp," '/>\n"); - fprintf(fp," </IndexedTriangleSet> \n"); - fprintf(fp," </Shape> \n"); - fprintf(fp," </Transform> \n"); - - fprintf(fp," </Scene>\n"); - fprintf(fp,"</X3D>\n"); + } // end loop on PView::list + fprintf(fp, " '/>\n"); + fprintf(fp, " </IndexedTriangleSet> \n"); + fprintf(fp, " </Shape> \n"); + fprintf(fp, " </Transform> \n"); + + fprintf(fp, " </Scene>\n"); + fprintf(fp, "</X3D>\n"); fclose(fp); return true; } static void writeX3DScale(FILE *fp, PView *p, double xmin, double ymin, - double width, double height, double tic, - int horizontal,double font_size) + double width, double height, double tic, + int horizontal, double font_size) { // use adaptive data if available PViewData *data = p->getData(true); PViewOptions *opt = p->getOptions(); - if(opt->externalViewIndex >= 0){ + if(opt->externalViewIndex >= 0) { opt->tmpMin = opt->externalMin; opt->tmpMax = opt->externalMax; } - else if(opt->rangeType == PViewOptions::Custom){ + else if(opt->rangeType == PViewOptions::Custom) { opt->tmpMin = opt->customMin; opt->tmpMax = opt->customMax; } - else if(opt->rangeType == PViewOptions::PerTimeStep){ + else if(opt->rangeType == PViewOptions::PerTimeStep) { opt->tmpMin = data->getMin(opt->timeStep); opt->tmpMax = data->getMax(opt->timeStep); } - else{ + else { opt->tmpMin = data->getMin(); opt->tmpMax = data->getMax(); } writeX3DScaleBar(fp, p, xmin, ymin, width, height, tic, horizontal); - writeX3DScaleValues(fp, p, xmin, ymin, width, height, tic, horizontal,font_size); - writeX3DScaleLabel (fp, p, xmin, ymin, width, height, tic, horizontal,font_size); + writeX3DScaleValues(fp, p, xmin, ymin, width, height, tic, horizontal, + font_size); + writeX3DScaleLabel(fp, p, xmin, ymin, width, height, tic, horizontal, + font_size); } -static void writeX3DScaleBar(FILE *fp, PView *p, double xmin, double ymin, double width, - double height, double tic, int horizontal) +static void writeX3DScaleBar(FILE *fp, PView *p, double xmin, double ymin, + double width, double height, double tic, + int horizontal) { PViewOptions *opt = p->getOptions(); double box = (horizontal ? width : height) / (opt->nbIso ? opt->nbIso : 1); for(int i = 0; i < opt->nbIso; i++) { - if(opt->intervalsType == PViewOptions::Continuous - || opt->intervalsType == PViewOptions::Discrete - || opt->intervalsType == PViewOptions::Numeric){ - fprintf(fp," <Shape> \n"); - fprintf(fp," <IndexedFaceSet colorPerVertex='true' normalPerVertex='true' " - "coordIndex='0 1 2 3 -1' solid='false' ccw='true' > \n"); - fprintf(fp," <Coordinate point='"); - if(horizontal){ - fprintf(fp,"%e %e %e %e %e %e %e %e %e %e %e %e " - ,xmin + i * box , ymin, 0. - ,xmin + (i + 1) * box, ymin, 0. - ,xmin + (i + 1) * box, ymin + height, 0. - ,xmin + i * box , ymin + height, 0.); + if(opt->intervalsType == PViewOptions::Continuous || + opt->intervalsType == PViewOptions::Discrete || + opt->intervalsType == PViewOptions::Numeric) { + fprintf(fp, " <Shape> \n"); + fprintf( + fp, + " <IndexedFaceSet colorPerVertex='true' normalPerVertex='true' " + "coordIndex='0 1 2 3 -1' solid='false' ccw='true' > \n"); + fprintf(fp, " <Coordinate point='"); + if(horizontal) { + fprintf(fp, "%e %e %e %e %e %e %e %e %e %e %e %e ", xmin + i * box, + ymin, 0., xmin + (i + 1) * box, ymin, 0., xmin + (i + 1) * box, + ymin + height, 0., xmin + i * box, ymin + height, 0.); } - else{ - fprintf(fp,"%e %e %e %e %e %e %e %e %e %e %e %e " - ,xmin, ymin + i * box, 0. - ,xmin + width, ymin + i * box, 0. - ,xmin + width, ymin + (i + 1) * box, 0. - ,xmin, ymin + (i + 1) * box, 0.); + else { + fprintf(fp, "%e %e %e %e %e %e %e %e %e %e %e %e ", xmin, + ymin + i * box, 0., xmin + width, ymin + i * box, 0., + xmin + width, ymin + (i + 1) * box, 0., xmin, + ymin + (i + 1) * box, 0.); } - fprintf(fp," '/> \n"); - - if(opt->intervalsType == PViewOptions::Discrete - || opt->intervalsType == PViewOptions::Numeric){ - double rgba[4]= { .5,.5,.5,1. }; - unsigned int col = opt->getColor(i, opt->nbIso); - unsignedInt2RGBA(col,rgba[0],rgba[1],rgba[2],rgba[3]); - fprintf(fp," <Color color=' %g %g %g %g %g %g %g %g %g %g %g %g '/>\n", - rgba[0],rgba[1],rgba[2], rgba[0],rgba[1],rgba[2], - rgba[0],rgba[1],rgba[2], rgba[0],rgba[1],rgba[2] ); + fprintf(fp, " '/> \n"); + + if(opt->intervalsType == PViewOptions::Discrete || + opt->intervalsType == PViewOptions::Numeric) { + double rgba[4] = {.5, .5, .5, 1.}; + unsigned int col = opt->getColor(i, opt->nbIso); + unsignedInt2RGBA(col, rgba[0], rgba[1], rgba[2], rgba[3]); + fprintf(fp, + " <Color color=' %g %g %g %g %g %g %g %g %g %g %g " + "%g '/>\n", + rgba[0], rgba[1], rgba[2], rgba[0], rgba[1], rgba[2], rgba[0], + rgba[1], rgba[2], rgba[0], rgba[1], rgba[2]); } - else if(opt->intervalsType == PViewOptions::Continuous){ - double dv = (opt->tmpMax - opt->tmpMin) / (opt->nbIso ? opt->nbIso : 1); - double v1 = opt->tmpMin + i * dv; - double v2 = opt->tmpMin + (i + 1) * dv; - unsigned int col1 = opt->getColor(v1, opt->tmpMin, opt->tmpMax, true); - unsigned int col2 = opt->getColor(v2, opt->tmpMin, opt->tmpMax, true); - double rgba1[4]= { .5,.5,.5,1. }; - double rgba2[4]= { .5,.5,.5,1. }; - unsignedInt2RGBA(col1,rgba1[0],rgba1[1],rgba1[2],rgba1[3]); - unsignedInt2RGBA(col2,rgba2[0],rgba2[1],rgba2[2],rgba2[3]); - fprintf(fp," <Color color=' %g %g %g %g %g %g %g %g %g %g %g %g '/>\n", - rgba1[0],rgba1[1],rgba1[2], rgba2[0],rgba2[1],rgba2[2], rgba2[0], - rgba2[1],rgba2[2], rgba1[0],rgba1[1],rgba1[2] ); + else if(opt->intervalsType == PViewOptions::Continuous) { + double dv = (opt->tmpMax - opt->tmpMin) / (opt->nbIso ? opt->nbIso : 1); + double v1 = opt->tmpMin + i * dv; + double v2 = opt->tmpMin + (i + 1) * dv; + unsigned int col1 = opt->getColor(v1, opt->tmpMin, opt->tmpMax, true); + unsigned int col2 = opt->getColor(v2, opt->tmpMin, opt->tmpMax, true); + double rgba1[4] = {.5, .5, .5, 1.}; + double rgba2[4] = {.5, .5, .5, 1.}; + unsignedInt2RGBA(col1, rgba1[0], rgba1[1], rgba1[2], rgba1[3]); + unsignedInt2RGBA(col2, rgba2[0], rgba2[1], rgba2[2], rgba2[3]); + fprintf(fp, + " <Color color=' %g %g %g %g %g %g %g %g %g %g %g " + "%g '/>\n", + rgba1[0], rgba1[1], rgba1[2], rgba2[0], rgba2[1], rgba2[2], + rgba2[0], rgba2[1], rgba2[2], rgba1[0], rgba1[1], rgba1[2]); } - fprintf(fp," </IndexedFaceSet> \n"); + fprintf(fp, " </IndexedFaceSet> \n"); } - else{ - fprintf(fp," <Shape> \n"); - fprintf(fp," <IndexedLineSet colorPerVertex='true' coordIndex='0 1 -1' > \n"); - fprintf(fp," <Coordinate point='"); - if(horizontal){ - fprintf(fp,"%e %e %e %e %e %e ",xmin+box/2.+i*box , ymin , 0., - xmin+box/2.+i*box , ymin+height , 0.); + else { + fprintf(fp, " <Shape> \n"); + fprintf(fp, " <IndexedLineSet colorPerVertex='true' " + "coordIndex='0 1 -1' > \n"); + fprintf(fp, " <Coordinate point='"); + if(horizontal) { + fprintf(fp, "%e %e %e %e %e %e ", xmin + box / 2. + i * box, ymin, 0., + xmin + box / 2. + i * box, ymin + height, 0.); } - else{ - fprintf(fp,"%e %e %e %e %e %e ",xmin , ymin + box / 2. + i * box, 0., - xmin + width , ymin + box / 2. + i * box , 0.); + else { + fprintf(fp, "%e %e %e %e %e %e ", xmin, ymin + box / 2. + i * box, 0., + xmin + width, ymin + box / 2. + i * box, 0.); } - fprintf(fp," '/> \n"); - double rgba[4]= { .5,.5,.5,1. }; + fprintf(fp, " '/> \n"); + double rgba[4] = {.5, .5, .5, 1.}; unsigned int col = opt->getColor(i, opt->nbIso); - unsignedInt2RGBA(col,rgba[0],rgba[1],rgba[2],rgba[3]); - fprintf(fp," <Color color=' %g %g %g %g %g %g '/>\n", - rgba[0],rgba[1],rgba[2], rgba[0],rgba[1],rgba[2] ); - fprintf(fp," </IndexedLineSet> \n"); + unsignedInt2RGBA(col, rgba[0], rgba[1], rgba[2], rgba[3]); + fprintf(fp, " <Color color=' %g %g %g %g %g %g '/>\n", rgba[0], + rgba[1], rgba[2], rgba[0], rgba[1], rgba[2]); + fprintf(fp, " </IndexedLineSet> \n"); } - fprintf(fp," </Shape> \n"); + fprintf(fp, " </Shape> \n"); } } -static void writeX3DScaleValues(FILE *fp, PView *p, double xmin, double ymin, - double width, double height, double tic, - int horizontal,double font_size) +static void writeX3DScaleValues(FILE *fp, PView *p, double xmin, double ymin, + double width, double height, double tic, + int horizontal, double font_size) { PViewOptions *opt = p->getOptions(); if(!opt->nbIso) return; - double font_h = font_size ; // total font height - double font_a = font_size*3./4. ; // height above ref pt + double font_h = font_size; // total font height + double font_a = font_size * 3. / 4.; // height above ref pt char label[1024]; int nbv = opt->nbIso; - double maxw =0.; + double maxw = 0.; for(int i = 0; i < nbv + 1; i++) { double v = opt->getScaleValue(i, nbv + 1, opt->tmpMin, opt->tmpMax); sprintf(label, opt->format.c_str(), v); - maxw = max(maxw,strlen(label)*font_size*3./4.); + maxw = max(maxw, strlen(label) * font_size * 3. / 4.); } double f = (opt->intervalsType == PViewOptions::Discrete || opt->intervalsType == PViewOptions::Numeric || - opt->intervalsType == PViewOptions::Continuous) ? 2 : 2.5; - - if(horizontal && width < nbv * maxw){ - if(width < f * maxw) nbv = 1; - else nbv = 2; + opt->intervalsType == PViewOptions::Continuous) ? + 2 : + 2.5; + + if(horizontal && width < nbv * maxw) { + if(width < f * maxw) + nbv = 1; + else + nbv = 2; } - else if(!horizontal && height < nbv * font_h ){ - if(height < f * font_h) nbv = 1; - else nbv = 2; + else if(!horizontal && height < nbv * font_h) { + if(height < f * font_h) + nbv = 1; + else + nbv = 2; } double box = (horizontal ? width : height) / opt->nbIso; double vbox = (horizontal ? width : height) / nbv; @@ -722,86 +790,92 @@ static void writeX3DScaleValues(FILE *fp, PView *p, double xmin, double ymin, if(opt->intervalsType == PViewOptions::Discrete || opt->intervalsType == PViewOptions::Numeric || - opt->intervalsType == PViewOptions::Continuous){ + opt->intervalsType == PViewOptions::Continuous) { for(int i = 0; i < nbv + 1; i++) { double v = opt->getScaleValue(i, nbv + 1, opt->tmpMin, opt->tmpMax); sprintf(label, opt->format.c_str(), v); - if(horizontal){ + if(horizontal) { writeX3DStringCenter(fp, label, xmin + i * vbox, ymin + height + tic, 0., font_h); } - else{ + else { writeX3DStringCenter(fp, label, xmin + width + tic, ymin + i * vbox - font_a / 3., 0., font_h); } } } - else{ - if(opt->nbIso > 2 && (nbv == 1 || nbv == 2)){ + else { + if(opt->nbIso > 2 && (nbv == 1 || nbv == 2)) { vbox = (vbox * nbv - box) / nbv; nbv++; } for(int i = 0; i < nbv; i++) { double v = opt->getScaleValue(i, nbv, opt->tmpMin, opt->tmpMax); sprintf(label, opt->format.c_str(), v); - if(horizontal){ + if(horizontal) { writeX3DStringCenter(fp, label, xmin + box / 2. + i * vbox, ymin + height + tic, 0., font_h); } - else{ + else { writeX3DStringCenter(fp, label, xmin + width + tic, - ymin + box / 2. + i * vbox - font_a / 3., 0., font_h); + ymin + box / 2. + i * vbox - font_a / 3., 0., + font_h); } } } } -static void writeX3DScaleLabel(FILE *fp , PView *p, double xmin, double ymin, - double width, double height, double tic, int horizontal, - double font_size) +static void writeX3DScaleLabel(FILE *fp, PView *p, double xmin, double ymin, + double width, double height, double tic, + int horizontal, double font_size) { PViewOptions *opt = p->getOptions(); PViewData *data; // requested by Laurent: but is this really what we should be doing? - if(opt->externalViewIndex >= 0 && opt->externalViewIndex < (int)PView::list.size()) + if(opt->externalViewIndex >= 0 && + opt->externalViewIndex < (int)PView::list.size()) data = PView::list[opt->externalViewIndex]->getData(); else data = p->getData(); double font_h = font_size; - font_h *=1.2; + font_h *= 1.2; char label[1024]; int nt = data->getNumTimeSteps(); - if((opt->showTime == 1 && nt > 1) || opt->showTime == 2){ + if((opt->showTime == 1 && nt > 1) || opt->showTime == 2) { char tmp[256]; sprintf(tmp, opt->format.c_str(), data->getTime(opt->timeStep)); sprintf(label, "%s (%s)", data->getName().c_str(), tmp); } - else if((opt->showTime == 3 && nt > 1) || opt->showTime == 4){ - sprintf(label, "%s (%d/%d)", data->getName().c_str(), opt->timeStep,data->getNumTimeSteps() - 1); + else if((opt->showTime == 3 && nt > 1) || opt->showTime == 4) { + sprintf(label, "%s (%d/%d)", data->getName().c_str(), opt->timeStep, + data->getNumTimeSteps() - 1); } else sprintf(label, "%s", data->getName().c_str()); - if(horizontal){ - writeX3DStringCenter( fp,label, xmin + width / 2., ymin + height + tic + .9 * font_h, 0.,font_h ); + if(horizontal) { + writeX3DStringCenter(fp, label, xmin + width / 2., + ymin + height + tic + .9 * font_h, 0., font_h); } - else{ - writeX3DStringCenter( fp,label, xmin, ymin - 2 * font_h, 0.,font_h ); + else { + writeX3DStringCenter(fp, label, xmin, ymin - 2 * font_h, 0., font_h); } } -static void writeX3DStringCenter(FILE *fp, char *label,double x, double y, double z, - double font_size) +static void writeX3DStringCenter(FILE *fp, char *label, double x, double y, + double z, double font_size) { - fprintf(fp," <Transform translation='%g %g %g'> \n",x,y,0.); - fprintf(fp," <Shape> \n"); - fprintf(fp," <Text string='\"%s\"'>\n",label); - fprintf(fp," <FontStyle justify='\"MIDDLE\" \"MIDDLE\"' size=' %d '/> \n", - (int)font_size); - fprintf(fp," </Text>\n"); - fprintf(fp," <Appearance>\n"); - fprintf(fp," <Material diffuseColor='0. 0. 0. '/>\n"); - fprintf(fp," </Appearance>\n"); - fprintf(fp," </Shape>\n"); - fprintf(fp," </Transform> \n"); + fprintf(fp, " <Transform translation='%g %g %g'> \n", x, y, 0.); + fprintf(fp, " <Shape> \n"); + fprintf(fp, " <Text string='\"%s\"'>\n", label); + fprintf( + fp, + " <FontStyle justify='\"MIDDLE\" \"MIDDLE\"' size=' %d '/> \n", + (int)font_size); + fprintf(fp, " </Text>\n"); + fprintf(fp, " <Appearance>\n"); + fprintf(fp, " <Material diffuseColor='0. 0. 0. '/>\n"); + fprintf(fp, " </Appearance>\n"); + fprintf(fp, " </Shape>\n"); + fprintf(fp, " </Transform> \n"); } diff --git a/Post/PViewX3D.h b/Post/PViewX3D.h index 6b498a8764f5271b1fc0148c8e90d16cf9f744b0..1ca91681935e53a0d00a9188c6a8624cb2449e42 100644 --- a/Post/PViewX3D.h +++ b/Post/PViewX3D.h @@ -11,15 +11,16 @@ #ifndef _PVIEWX3D_H_ #define _PVIEWX3D_H_ -static inline void UnsignedChar2rgba(unsigned char *glc, double*rgba) +static inline void UnsignedChar2rgba(unsigned char *glc, double *rgba) { - rgba[0] = glc[0]/255.; - rgba[1] = glc[1]/255.; - rgba[2] = glc[2]/255.; - rgba[3] = glc[3]/255.; + rgba[0] = glc[0] / 255.; + rgba[1] = glc[1] / 255.; + rgba[2] = glc[2] / 255.; + rgba[3] = glc[3] / 255.; } -static inline void unsignedInt2RGBA(unsigned int &color, double &r, double &g, double &b, double &a) +static inline void unsignedInt2RGBA(unsigned int &color, double &r, double &g, + double &b, double &a) { r = color & 255; g = (color >> 8) & 255; @@ -31,23 +32,28 @@ static inline void unsignedInt2RGBA(unsigned int &color, double &r, double &g, d a = a / 255.; } -static void writeX3DScale(FILE *fp, PView *p, double xmin, double ymin, double width, double height, - double tic, int horizontal, double font_size); -static void writeX3DScaleBar(FILE *fp, PView *p, double xmin, double ymin, double width, double height, - double tic, int horizontal); -static void writeX3DScaleValues(FILE *fp, PView *p, double xmin, double ymin, double width, double height, - double tic, int horizontal, double font_size); -static void writeX3DScaleLabel(FILE *fp, PView *p, double xmin, double ymin, double width, double height, - double tic, int horizontal,double font_size); -static void writeX3DStringCenter(FILE *fp, char *label, double x, double y, double z, double font_size); +static void writeX3DScale(FILE *fp, PView *p, double xmin, double ymin, + double width, double height, double tic, + int horizontal, double font_size); +static void writeX3DScaleBar(FILE *fp, PView *p, double xmin, double ymin, + double width, double height, double tic, + int horizontal); +static void writeX3DScaleValues(FILE *fp, PView *p, double xmin, double ymin, + double width, double height, double tic, + int horizontal, double font_size); +static void writeX3DScaleLabel(FILE *fp, PView *p, double xmin, double ymin, + double width, double height, double tic, + int horizontal, double font_size); +static void writeX3DStringCenter(FILE *fp, char *label, double x, double y, + double z, double font_size); -class TriangleToSort{ - public: - PView* _ppv; +class TriangleToSort { +public: + PView *_ppv; int _index; int _globalIndex; - float xmin,ymin,zmin; - float xmax,ymax,zmax; + float xmin, ymin, zmin; + float xmax, ymax, zmax; }; #endif diff --git a/Post/adaptiveData.cpp b/Post/adaptiveData.cpp index 7e4f5437565ee2f0bb8d3fb94feacbd47890cc07..cedd57ed70cf72c92d65396685768874f9e35454 100644 --- a/Post/adaptiveData.cpp +++ b/Post/adaptiveData.cpp @@ -24,14 +24,14 @@ std::set<adaptiveVertex> adaptiveHexahedron::allVertices; std::set<adaptiveVertex> adaptivePrism::allVertices; std::set<adaptiveVertex> adaptivePyramid::allVertices; -std::list<adaptivePoint*> adaptivePoint::all; -std::list<adaptiveLine*> adaptiveLine::all; -std::list<adaptiveTriangle*> adaptiveTriangle::all; -std::list<adaptiveQuadrangle*> adaptiveQuadrangle::all; -std::list<adaptiveTetrahedron*> adaptiveTetrahedron::all; -std::list<adaptiveHexahedron*> adaptiveHexahedron::all; -std::list<adaptivePrism*> adaptivePrism::all; -std::list<adaptivePyramid*> adaptivePyramid::all; +std::list<adaptivePoint *> adaptivePoint::all; +std::list<adaptiveLine *> adaptiveLine::all; +std::list<adaptiveTriangle *> adaptiveTriangle::all; +std::list<adaptiveQuadrangle *> adaptiveQuadrangle::all; +std::list<adaptiveTetrahedron *> adaptiveTetrahedron::all; +std::list<adaptiveHexahedron *> adaptiveHexahedron::all; +std::list<adaptivePrism *> adaptivePrism::all; +std::list<adaptivePyramid *> adaptivePyramid::all; int adaptivePoint::numNodes = 1; int adaptiveLine::numNodes = 2; @@ -56,17 +56,18 @@ std::vector<int> globalVTKData::vtkGlobalCellType; std::vector<PCoords> globalVTKData::vtkGlobalCoords; std::vector<PValues> globalVTKData::vtkGlobalValues; -template <class T> -static void cleanElement() +template <class T> static void cleanElement() { - for(typename std::list<T*>::iterator it = T::all.begin(); it != T::all.end(); ++it) + for(typename std::list<T *>::iterator it = T::all.begin(); it != T::all.end(); + ++it) delete *it; T::all.clear(); T::allVertices.clear(); } -static void computeShapeFunctions(fullMatrix<double> *coeffs, fullMatrix<double> *eexps, - double u, double v, double w, fullVector<double> *sf, +static void computeShapeFunctions(fullMatrix<double> *coeffs, + fullMatrix<double> *eexps, double u, double v, + double w, fullVector<double> *sf, fullVector<double> *tmp) { for(int i = 0; i < eexps->size1(); i++) { @@ -82,48 +83,45 @@ static void computeShapeFunctions(fullMatrix<double> *coeffs, fullMatrix<double> \mathcal P_i \left(\frac{\xi }{1-\zeta}\right) \mathcal P_j \left(\frac{\eta}{1-\zeta}\right) \left(1-\zeta\right)^{max(i,j)} - \mathcal P^{2 max(i,j),0}_k \left(2 \zeta -1\right)~|~i,j \leq p, k \leq p - max(i,j) \f$ - and hence by the "monomials" - \f$ \mu_{ijk} = - \left(\frac{\xi }{\1-\zeta}\right)^i - \left(\frac{\eta}{\1-\zeta}\right)^j + \mathcal P^{2 max(i,j),0}_k \left(2 \zeta -1\right)~|~i,j \leq p, k \leq p - + max(i,j) \f$ and hence by the "monomials" \f$ \mu_{ijk} = \left(\frac{\xi + }{\1-\zeta}\right)^i \left(\frac{\eta}{\1-\zeta}\right)^j \left(1-\zeta\right)^{max(i,j)} \zeta^k~|~i,j \leq p~,~k \leq p-max(i,j) \f$ */ static void computeShapeFunctionsPyramid(fullMatrix<double> *coeffs, - fullMatrix<double> *eexps, - double u, double v, double w, + fullMatrix<double> *eexps, double u, + double v, double w, fullVector<double> *sf, fullVector<double> *tmp) { - - double oneMinW = (w==1) ? 1e-12:1-w; + double oneMinW = (w == 1) ? 1e-12 : 1 - w; for(int l = 0; l < eexps->size1(); l++) { - int i = (*eexps)(l,0); - int j = (*eexps)(l,1); - int k = (*eexps)(l,2); - int m = std::max(i,j); - (*tmp)(l) = pow(u,i); - (*tmp)(l) *= pow(v,j); - (*tmp)(l) *= pow(w,k); - (*tmp)(l) *= pow(oneMinW,m-i-j); + int i = (*eexps)(l, 0); + int j = (*eexps)(l, 1); + int k = (*eexps)(l, 2); + int m = std::max(i, j); + (*tmp)(l) = pow(u, i); + (*tmp)(l) *= pow(v, j); + (*tmp)(l) *= pow(w, k); + (*tmp)(l) *= pow(oneMinW, m - i - j); } coeffs->mult(*tmp, *sf); } adaptiveVertex *adaptiveVertex::add(double x, double y, double z, - std::set<adaptiveVertex> &allVertices) + std::set<adaptiveVertex> &allVertices) { adaptiveVertex p; p.x = x; p.y = y; p.z = z; std::set<adaptiveVertex>::iterator it = allVertices.find(p); - if(it == allVertices.end()){ + if(it == allVertices.end()) { allVertices.insert(p); it = allVertices.find(p); } - return (adaptiveVertex*)&(*it); + return (adaptiveVertex *)&(*it); } void adaptivePoint::create(int maxlevel) @@ -167,9 +165,9 @@ void adaptiveLine::recurCreate(adaptiveLine *e, int maxlevel, int level) // p1 p12 p2 adaptiveVertex *p1 = e->p[0]; adaptiveVertex *p2 = e->p[1]; - adaptiveVertex *p12 = adaptiveVertex::add - ((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, (p1->z + p2->z) * 0.5, - allVertices); + adaptiveVertex *p12 = + adaptiveVertex::add((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, + (p1->z + p2->z) * 0.5, allVertices); adaptiveLine *e1 = new adaptiveLine(p1, p12); recurCreate(e1, maxlevel, level); adaptiveLine *e2 = new adaptiveLine(p12, p2); @@ -195,7 +193,7 @@ void adaptiveLine::recurError(adaptiveLine *e, double AVG, double tol) double v2 = e->e[1]->V(); vr = (v1 + v2) / 2.; double v = e->V(); - if(fabs(v - vr) > AVG * tol){ + if(fabs(v - vr) > AVG * tol) { e->visible = false; recurError(e->e[0], AVG, tol); recurError(e->e[1], AVG, tol); @@ -245,15 +243,15 @@ void adaptiveTriangle::recurCreate(adaptiveTriangle *t, int maxlevel, int level) adaptiveVertex *p1 = t->p[0]; adaptiveVertex *p2 = t->p[1]; adaptiveVertex *p3 = t->p[2]; - adaptiveVertex *p12 = adaptiveVertex::add - ((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, (p1->z + p2->z) * 0.5, - allVertices); - adaptiveVertex *p13 = adaptiveVertex::add - ((p1->x + p3->x) * 0.5, (p1->y + p3->y) * 0.5, (p1->z + p3->z) * 0.5, - allVertices); - adaptiveVertex *p23 = adaptiveVertex::add - ((p3->x + p2->x) * 0.5, (p3->y + p2->y) * 0.5, (p3->z + p2->z) * 0.5, - allVertices); + adaptiveVertex *p12 = + adaptiveVertex::add((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, + (p1->z + p2->z) * 0.5, allVertices); + adaptiveVertex *p13 = + adaptiveVertex::add((p1->x + p3->x) * 0.5, (p1->y + p3->y) * 0.5, + (p1->z + p3->z) * 0.5, allVertices); + adaptiveVertex *p23 = + adaptiveVertex::add((p3->x + p2->x) * 0.5, (p3->y + p2->y) * 0.5, + (p3->z + p2->z) * 0.5, allVertices); adaptiveTriangle *t1 = new adaptiveTriangle(p1, p12, p13); recurCreate(t1, maxlevel, level); adaptiveTriangle *t2 = new adaptiveTriangle(p2, p23, p12); @@ -287,7 +285,7 @@ void adaptiveTriangle::recurError(adaptiveTriangle *t, double AVG, double tol) double v4 = t->e[3]->V(); vr = (2 * v1 + 2 * v2 + 2 * v3 + v4) / 7.; double v = t->V(); - if(fabs(v - vr) > AVG * tol){ + if(fabs(v - vr) > AVG * tol) { t->visible = false; recurError(t->e[0], AVG, tol); recurError(t->e[1], AVG, tol); @@ -323,7 +321,7 @@ void adaptiveTriangle::recurError(adaptiveTriangle *t, double AVG, double tol) fabs(t->e[1]->V() - vr2) > AVG * tol || fabs(t->e[2]->V() - vr3) > AVG * tol || fabs(t->e[3]->V() - vr4) > AVG * tol || - fabs(t->V() - vr) > AVG * tol){ + fabs(t->V() - vr) > AVG * tol) { t->visible = false; recurError(t->e[0], AVG, tol); recurError(t->e[1], AVG, tol); @@ -347,7 +345,8 @@ void adaptiveQuadrangle::create(int maxlevel) recurCreate(q, maxlevel, 0); } -void adaptiveQuadrangle::recurCreate(adaptiveQuadrangle *q, int maxlevel, int level) +void adaptiveQuadrangle::recurCreate(adaptiveQuadrangle *q, int maxlevel, + int level) { all.push_back(q); if(level++ >= maxlevel) return; @@ -359,21 +358,22 @@ void adaptiveQuadrangle::recurCreate(adaptiveQuadrangle *q, int maxlevel, int le adaptiveVertex *p2 = q->p[1]; adaptiveVertex *p3 = q->p[2]; adaptiveVertex *p4 = q->p[3]; - adaptiveVertex *p12 = adaptiveVertex::add - ((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, (p1->z + p2->z) * 0.5, - allVertices); - adaptiveVertex *p23 = adaptiveVertex::add - ((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, (p2->z + p3->z) * 0.5, - allVertices); - adaptiveVertex *p34 = adaptiveVertex::add - ((p3->x + p4->x) * 0.5, (p3->y + p4->y) * 0.5, (p3->z + p4->z) * 0.5, - allVertices); - adaptiveVertex *p14 = adaptiveVertex::add - ((p1->x + p4->x) * 0.5, (p1->y + p4->y) * 0.5, (p1->z + p4->z) * 0.5, - allVertices); - adaptiveVertex *pc = adaptiveVertex::add - ((p1->x + p2->x + p3->x + p4->x) * 0.25, (p1->y + p2->y + p3->y + p4->y) * 0.25, - (p1->z + p2->z + p3->z + p4->z) * 0.25, allVertices); + adaptiveVertex *p12 = + adaptiveVertex::add((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, + (p1->z + p2->z) * 0.5, allVertices); + adaptiveVertex *p23 = + adaptiveVertex::add((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, + (p2->z + p3->z) * 0.5, allVertices); + adaptiveVertex *p34 = + adaptiveVertex::add((p3->x + p4->x) * 0.5, (p3->y + p4->y) * 0.5, + (p3->z + p4->z) * 0.5, allVertices); + adaptiveVertex *p14 = + adaptiveVertex::add((p1->x + p4->x) * 0.5, (p1->y + p4->y) * 0.5, + (p1->z + p4->z) * 0.5, allVertices); + adaptiveVertex *pc = + adaptiveVertex::add((p1->x + p2->x + p3->x + p4->x) * 0.25, + (p1->y + p2->y + p3->y + p4->y) * 0.25, + (p1->z + p2->z + p3->z + p4->z) * 0.25, allVertices); adaptiveQuadrangle *q1 = new adaptiveQuadrangle(p1, p12, pc, p14); recurCreate(q1, maxlevel, level); adaptiveQuadrangle *q2 = new adaptiveQuadrangle(p2, p23, pc, p12); @@ -394,7 +394,8 @@ void adaptiveQuadrangle::error(double AVG, double tol) recurError(q, AVG, tol); } -void adaptiveQuadrangle::recurError(adaptiveQuadrangle *q, double AVG, double tol) +void adaptiveQuadrangle::recurError(adaptiveQuadrangle *q, double AVG, + double tol) { if(!q->e[0]) q->visible = true; @@ -408,8 +409,7 @@ void adaptiveQuadrangle::recurError(adaptiveQuadrangle *q, double AVG, double to double v4 = q->e[3]->V(); vr = (v1 + v2 + v3 + v4) / 4.; double v = q->V(); - if(fabs(v - vr) > AVG * tol || - fabs(vd - vr) > AVG * tol){ + if(fabs(v - vr) > AVG * tol || fabs(vd - vr) > AVG * tol) { q->visible = false; recurError(q->e[0], AVG, tol); recurError(q->e[1], AVG, tol); @@ -445,8 +445,7 @@ void adaptiveQuadrangle::recurError(adaptiveQuadrangle *q, double AVG, double to fabs(q->e[1]->V() - vr2) > AVG * tol || fabs(q->e[2]->V() - vr3) > AVG * tol || fabs(q->e[3]->V() - vr4) > AVG * tol || - fabs(q->V() - vr) > AVG * tol || - fabs(vd - vr) > AVG * tol){ + fabs(q->V() - vr) > AVG * tol || fabs(vd - vr) > AVG * tol) { q->visible = false; recurError(q->e[0], AVG, tol); recurError(q->e[1], AVG, tol); @@ -470,7 +469,8 @@ void adaptiveTetrahedron::create(int maxlevel) recurCreate(t, maxlevel, 0); } -void adaptiveTetrahedron::recurCreate(adaptiveTetrahedron *t, int maxlevel, int level) +void adaptiveTetrahedron::recurCreate(adaptiveTetrahedron *t, int maxlevel, + int level) { all.push_back(t); if(level++ >= maxlevel) return; @@ -479,24 +479,24 @@ void adaptiveTetrahedron::recurCreate(adaptiveTetrahedron *t, int maxlevel, int adaptiveVertex *p1 = t->p[1]; adaptiveVertex *p2 = t->p[2]; adaptiveVertex *p3 = t->p[3]; - adaptiveVertex *pe0 = adaptiveVertex::add - ((p0->x + p1->x) * 0.5, (p0->y + p1->y) * 0.5, (p0->z + p1->z) * 0.5, - allVertices); - adaptiveVertex *pe1 = adaptiveVertex::add - ((p0->x + p2->x) * 0.5, (p0->y + p2->y) * 0.5, (p0->z + p2->z) * 0.5, - allVertices); - adaptiveVertex *pe2 = adaptiveVertex::add - ((p0->x + p3->x) * 0.5, (p0->y + p3->y) * 0.5, (p0->z + p3->z) * 0.5, - allVertices); - adaptiveVertex *pe3 = adaptiveVertex::add - ((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, (p1->z + p2->z) * 0.5, - allVertices); - adaptiveVertex *pe4 = adaptiveVertex::add - ((p1->x + p3->x) * 0.5, (p1->y + p3->y) * 0.5, (p1->z + p3->z) * 0.5, - allVertices); - adaptiveVertex *pe5 = adaptiveVertex::add - ((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, (p2->z + p3->z) * 0.5, - allVertices); + adaptiveVertex *pe0 = + adaptiveVertex::add((p0->x + p1->x) * 0.5, (p0->y + p1->y) * 0.5, + (p0->z + p1->z) * 0.5, allVertices); + adaptiveVertex *pe1 = + adaptiveVertex::add((p0->x + p2->x) * 0.5, (p0->y + p2->y) * 0.5, + (p0->z + p2->z) * 0.5, allVertices); + adaptiveVertex *pe2 = + adaptiveVertex::add((p0->x + p3->x) * 0.5, (p0->y + p3->y) * 0.5, + (p0->z + p3->z) * 0.5, allVertices); + adaptiveVertex *pe3 = + adaptiveVertex::add((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, + (p1->z + p2->z) * 0.5, allVertices); + adaptiveVertex *pe4 = + adaptiveVertex::add((p1->x + p3->x) * 0.5, (p1->y + p3->y) * 0.5, + (p1->z + p3->z) * 0.5, allVertices); + adaptiveVertex *pe5 = + adaptiveVertex::add((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, + (p2->z + p3->z) * 0.5, allVertices); adaptiveTetrahedron *t1 = new adaptiveTetrahedron(p0, pe0, pe1, pe2); recurCreate(t1, maxlevel, level); adaptiveTetrahedron *t2 = new adaptiveTetrahedron(pe0, p1, pe3, pe4); @@ -529,7 +529,8 @@ void adaptiveTetrahedron::error(double AVG, double tol) recurError(t, AVG, tol); } -void adaptiveTetrahedron::recurError(adaptiveTetrahedron *t, double AVG, double tol) +void adaptiveTetrahedron::recurError(adaptiveTetrahedron *t, double AVG, + double tol) { if(!t->e[0]) t->visible = true; @@ -562,8 +563,7 @@ void adaptiveTetrahedron::recurError(adaptiveTetrahedron *t, double AVG, double else { double vi[8][8]; for(int k = 0; k < 8; k++) - for(int l = 0; l < 8; l++) - vi[k][l] = t->e[k]->e[l]->V(); + for(int l = 0; l < 8; l++) vi[k][l] = t->e[k]->e[l]->V(); double vri[8]; for(int k = 0; k < 8; k++) { vri[k] = 0.0; @@ -579,8 +579,7 @@ void adaptiveTetrahedron::recurError(adaptiveTetrahedron *t, double AVG, double fabs(t->e[4]->V() - vri[4]) > AVG * tol || fabs(t->e[5]->V() - vri[5]) > AVG * tol || fabs(t->e[6]->V() - vri[6]) > AVG * tol || - fabs(t->e[7]->V() - vri[7]) > AVG * tol || - fabs(v - vr) > AVG * tol) { + fabs(t->e[7]->V() - vri[7]) > AVG * tol || fabs(v - vr) > AVG * tol) { t->visible = false; recurError(t->e[0], AVG, tol); recurError(t->e[1], AVG, tol); @@ -608,11 +607,13 @@ void adaptiveHexahedron::create(int maxlevel) adaptiveVertex *p21 = adaptiveVertex::add(-1, 1, 1, allVertices); adaptiveVertex *p31 = adaptiveVertex::add(1, 1, 1, allVertices); adaptiveVertex *p41 = adaptiveVertex::add(1, -1, 1, allVertices); - adaptiveHexahedron *h = new adaptiveHexahedron(p1, p2, p3, p4, p11, p21, p31, p41); + adaptiveHexahedron *h = + new adaptiveHexahedron(p1, p2, p3, p4, p11, p21, p31, p41); recurCreate(h, maxlevel, 0); } -void adaptiveHexahedron::recurCreate(adaptiveHexahedron *h, int maxlevel, int level) +void adaptiveHexahedron::recurCreate(adaptiveHexahedron *h, int maxlevel, + int level) { all.push_back(h); if(level++ >= maxlevel) return; @@ -625,89 +626,89 @@ void adaptiveHexahedron::recurCreate(adaptiveHexahedron *h, int maxlevel, int le adaptiveVertex *p5 = h->p[5]; adaptiveVertex *p6 = h->p[6]; adaptiveVertex *p7 = h->p[7]; - adaptiveVertex *p01 = adaptiveVertex::add - ((p0->x + p1->x) * 0.5, (p0->y + p1->y) * 0.5, (p0->z + p1->z) * 0.5, - allVertices); - adaptiveVertex *p12 = adaptiveVertex::add - ((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, (p1->z + p2->z) * 0.5, - allVertices); - adaptiveVertex *p23 = adaptiveVertex::add - ((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, (p2->z + p3->z) * 0.5, - allVertices); - adaptiveVertex *p03 = adaptiveVertex::add - ((p3->x + p0->x) * 0.5, (p3->y + p0->y) * 0.5, (p3->z + p0->z) * 0.5, - allVertices); - adaptiveVertex *p45 = adaptiveVertex::add - ((p4->x + p5->x) * 0.5, (p4->y + p5->y) * 0.5, (p4->z + p5->z) * 0.5, - allVertices); - adaptiveVertex *p56 = adaptiveVertex::add - ((p5->x + p6->x) * 0.5, (p5->y + p6->y) * 0.5, (p5->z + p6->z) * 0.5, - allVertices); - adaptiveVertex *p67 = adaptiveVertex::add - ((p6->x + p7->x) * 0.5, (p6->y + p7->y) * 0.5, (p6->z + p7->z) * 0.5, - allVertices); - adaptiveVertex *p47 = adaptiveVertex::add - ((p7->x + p4->x) * 0.5, (p7->y + p4->y) * 0.5, (p7->z + p4->z) * 0.5, - allVertices); - adaptiveVertex *p04 = adaptiveVertex::add - ((p4->x + p0->x) * 0.5, (p4->y + p0->y) * 0.5, (p4->z + p0->z) * 0.5, - allVertices); - adaptiveVertex *p15 = adaptiveVertex::add - ((p5->x + p1->x) * 0.5, (p5->y + p1->y) * 0.5, (p5->z + p1->z) * 0.5, - allVertices); - adaptiveVertex *p26 = adaptiveVertex::add - ((p6->x + p2->x) * 0.5, (p6->y + p2->y) * 0.5, (p6->z + p2->z) * 0.5, - allVertices); - adaptiveVertex *p37 = adaptiveVertex::add - ((p7->x + p3->x) * 0.5, (p7->y + p3->y) * 0.5, (p7->z + p3->z) * 0.5, - allVertices); - adaptiveVertex *p0145 = adaptiveVertex::add - ((p45->x + p01->x) * 0.5, (p45->y + p01->y) * 0.5,(p45->z + p01->z) * 0.5, - allVertices); - adaptiveVertex *p1256 = adaptiveVertex::add - ((p12->x + p56->x) * 0.5, (p12->y + p56->y) * 0.5, (p12->z + p56->z) * 0.5, - allVertices); - adaptiveVertex *p2367 = adaptiveVertex::add - ((p23->x + p67->x) * 0.5, (p23->y + p67->y) * 0.5, (p23->z + p67->z) * 0.5, - allVertices); - adaptiveVertex *p0347 = adaptiveVertex::add - ((p03->x + p47->x) * 0.5, (p03->y + p47->y) * 0.5, (p03->z + p47->z) * 0.5, - allVertices); - adaptiveVertex *p4756 = adaptiveVertex::add - ((p47->x + p56->x) * 0.5, (p47->y + p56->y) * 0.5, (p47->z + p56->z) * 0.5, - allVertices); - adaptiveVertex *p0312 = adaptiveVertex::add - ((p03->x + p12->x) * 0.5, (p03->y + p12->y) * 0.5, (p03->z + p12->z) * 0.5, - allVertices); - adaptiveVertex *pc = adaptiveVertex::add - ((p0->x + p1->x + p2->x + p3->x + p4->x + p5->x + p6->x + p7->x) * 0.125, - (p0->y + p1->y + p2->y + p3->y + p4->y + p5->y + p6->y + p7->y) * 0.125, - (p0->z + p1->z + p2->z + p3->z + p4->z + p5->z + p6->z + p7->z) * 0.125, - allVertices); - - adaptiveHexahedron *h1 = new adaptiveHexahedron - (p0, p01, p0312, p03, p04, p0145, pc, p0347); // p0 + adaptiveVertex *p01 = + adaptiveVertex::add((p0->x + p1->x) * 0.5, (p0->y + p1->y) * 0.5, + (p0->z + p1->z) * 0.5, allVertices); + adaptiveVertex *p12 = + adaptiveVertex::add((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, + (p1->z + p2->z) * 0.5, allVertices); + adaptiveVertex *p23 = + adaptiveVertex::add((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, + (p2->z + p3->z) * 0.5, allVertices); + adaptiveVertex *p03 = + adaptiveVertex::add((p3->x + p0->x) * 0.5, (p3->y + p0->y) * 0.5, + (p3->z + p0->z) * 0.5, allVertices); + adaptiveVertex *p45 = + adaptiveVertex::add((p4->x + p5->x) * 0.5, (p4->y + p5->y) * 0.5, + (p4->z + p5->z) * 0.5, allVertices); + adaptiveVertex *p56 = + adaptiveVertex::add((p5->x + p6->x) * 0.5, (p5->y + p6->y) * 0.5, + (p5->z + p6->z) * 0.5, allVertices); + adaptiveVertex *p67 = + adaptiveVertex::add((p6->x + p7->x) * 0.5, (p6->y + p7->y) * 0.5, + (p6->z + p7->z) * 0.5, allVertices); + adaptiveVertex *p47 = + adaptiveVertex::add((p7->x + p4->x) * 0.5, (p7->y + p4->y) * 0.5, + (p7->z + p4->z) * 0.5, allVertices); + adaptiveVertex *p04 = + adaptiveVertex::add((p4->x + p0->x) * 0.5, (p4->y + p0->y) * 0.5, + (p4->z + p0->z) * 0.5, allVertices); + adaptiveVertex *p15 = + adaptiveVertex::add((p5->x + p1->x) * 0.5, (p5->y + p1->y) * 0.5, + (p5->z + p1->z) * 0.5, allVertices); + adaptiveVertex *p26 = + adaptiveVertex::add((p6->x + p2->x) * 0.5, (p6->y + p2->y) * 0.5, + (p6->z + p2->z) * 0.5, allVertices); + adaptiveVertex *p37 = + adaptiveVertex::add((p7->x + p3->x) * 0.5, (p7->y + p3->y) * 0.5, + (p7->z + p3->z) * 0.5, allVertices); + adaptiveVertex *p0145 = + adaptiveVertex::add((p45->x + p01->x) * 0.5, (p45->y + p01->y) * 0.5, + (p45->z + p01->z) * 0.5, allVertices); + adaptiveVertex *p1256 = + adaptiveVertex::add((p12->x + p56->x) * 0.5, (p12->y + p56->y) * 0.5, + (p12->z + p56->z) * 0.5, allVertices); + adaptiveVertex *p2367 = + adaptiveVertex::add((p23->x + p67->x) * 0.5, (p23->y + p67->y) * 0.5, + (p23->z + p67->z) * 0.5, allVertices); + adaptiveVertex *p0347 = + adaptiveVertex::add((p03->x + p47->x) * 0.5, (p03->y + p47->y) * 0.5, + (p03->z + p47->z) * 0.5, allVertices); + adaptiveVertex *p4756 = + adaptiveVertex::add((p47->x + p56->x) * 0.5, (p47->y + p56->y) * 0.5, + (p47->z + p56->z) * 0.5, allVertices); + adaptiveVertex *p0312 = + adaptiveVertex::add((p03->x + p12->x) * 0.5, (p03->y + p12->y) * 0.5, + (p03->z + p12->z) * 0.5, allVertices); + adaptiveVertex *pc = adaptiveVertex::add( + (p0->x + p1->x + p2->x + p3->x + p4->x + p5->x + p6->x + p7->x) * 0.125, + (p0->y + p1->y + p2->y + p3->y + p4->y + p5->y + p6->y + p7->y) * 0.125, + (p0->z + p1->z + p2->z + p3->z + p4->z + p5->z + p6->z + p7->z) * 0.125, + allVertices); + + adaptiveHexahedron *h1 = + new adaptiveHexahedron(p0, p01, p0312, p03, p04, p0145, pc, p0347); // p0 recurCreate(h1, maxlevel, level); - adaptiveHexahedron *h2 = new adaptiveHexahedron - (p01, p0145, p15, p1, p0312, pc, p1256, p12); // p1 + adaptiveHexahedron *h2 = + new adaptiveHexahedron(p01, p0145, p15, p1, p0312, pc, p1256, p12); // p1 recurCreate(h2, maxlevel, level); - adaptiveHexahedron *h3 = new adaptiveHexahedron - (p04, p4, p45, p0145, p0347, p47, p4756, pc); // p4 + adaptiveHexahedron *h3 = + new adaptiveHexahedron(p04, p4, p45, p0145, p0347, p47, p4756, pc); // p4 recurCreate(h3, maxlevel, level); - adaptiveHexahedron *h4 = new adaptiveHexahedron - (p0145, p45, p5, p15, pc, p4756, p56, p1256); // p5 + adaptiveHexahedron *h4 = + new adaptiveHexahedron(p0145, p45, p5, p15, pc, p4756, p56, p1256); // p5 recurCreate(h4, maxlevel, level); - adaptiveHexahedron *h5 = new adaptiveHexahedron - (p0347, p47, p4756, pc, p37, p7, p67, p2367); // p7 + adaptiveHexahedron *h5 = + new adaptiveHexahedron(p0347, p47, p4756, pc, p37, p7, p67, p2367); // p7 recurCreate(h5, maxlevel, level); - adaptiveHexahedron *h6 = new adaptiveHexahedron - (pc, p4756, p56, p1256, p2367, p67, p6, p26); // p6 + adaptiveHexahedron *h6 = + new adaptiveHexahedron(pc, p4756, p56, p1256, p2367, p67, p6, p26); // p6 recurCreate(h6, maxlevel, level); - adaptiveHexahedron *h7 = new adaptiveHexahedron - (p03, p0347, pc, p0312, p3, p37, p2367, p23); // p3 + adaptiveHexahedron *h7 = + new adaptiveHexahedron(p03, p0347, pc, p0312, p3, p37, p2367, p23); // p3 recurCreate(h7, maxlevel, level); - adaptiveHexahedron *h8 = new adaptiveHexahedron - (p0312, pc, p1256, p12, p23, p2367, p26, p2); // p2 + adaptiveHexahedron *h8 = + new adaptiveHexahedron(p0312, pc, p1256, p12, p23, p2367, p26, p2); // p2 recurCreate(h8, maxlevel, level); h->e[0] = h1; h->e[1] = h2; @@ -725,7 +726,8 @@ void adaptiveHexahedron::error(double AVG, double tol) recurError(h, AVG, tol); } -void adaptiveHexahedron::recurError(adaptiveHexahedron *h, double AVG, double tol) +void adaptiveHexahedron::recurError(adaptiveHexahedron *h, double AVG, + double tol) { if(!h->e[0]) h->visible = true; @@ -743,8 +745,7 @@ void adaptiveHexahedron::recurError(adaptiveHexahedron *h, double AVG, double to // we use diagonal 1-7 because it's the one used for drawing const double vd = (h->p[1]->val + h->p[7]->val) / 2.; if(!h->e[0]->e[0]) { - if(fabs(v - vr) > AVG * tol || - fabs(vd - vr) > AVG * tol) { + if(fabs(v - vr) > AVG * tol || fabs(vd - vr) > AVG * tol) { h->visible = false; recurError(h->e[0], AVG, tol); recurError(h->e[1], AVG, tol); @@ -761,8 +762,7 @@ void adaptiveHexahedron::recurError(adaptiveHexahedron *h, double AVG, double to else { double vii[8][8]; for(int i = 0; i < 8; i++) - for(int j = 0; j < 8; j++) - vii[i][j] = h->e[i]->e[j]->V(); + for(int j = 0; j < 8; j++) vii[i][j] = h->e[i]->e[j]->V(); double vri[8]; for(int k = 0; k < 8; k++) { vri[k] = 0.0; @@ -778,8 +778,7 @@ void adaptiveHexahedron::recurError(adaptiveHexahedron *h, double AVG, double to fabs(h->e[4]->V() - vri[4]) > AVG * tol || fabs(h->e[5]->V() - vri[5]) > AVG * tol || fabs(h->e[6]->V() - vri[6]) > AVG * tol || - fabs(h->e[7]->V() - vri[7]) > AVG * tol || - fabs(v - vr) > AVG * tol || + fabs(h->e[7]->V() - vri[7]) > AVG * tol || fabs(v - vr) > AVG * tol || fabs(vd - vr) > AVG * tol) { h->visible = false; recurError(h->e[0], AVG, tol); @@ -824,42 +823,42 @@ void adaptivePrism::recurCreate(adaptivePrism *p, int maxlevel, int level) adaptiveVertex *p4 = p->p[3]; adaptiveVertex *p5 = p->p[4]; adaptiveVertex *p6 = p->p[5]; - adaptiveVertex *p14 = adaptiveVertex::add - ((p1->x + p4->x) * 0.5, (p1->y + p4->y) * 0.5, (p1->z + p4->z) * 0.5, - allVertices); - adaptiveVertex *p25 = adaptiveVertex::add - ((p2->x + p5->x) * 0.5, (p2->y + p5->y) * 0.5, (p2->z + p5->z) * 0.5, - allVertices); - adaptiveVertex *p36 = adaptiveVertex::add - ((p3->x + p6->x) * 0.5, (p3->y + p6->y) * 0.5, (p3->z + p6->z) * 0.5, - allVertices); - adaptiveVertex *p12 = adaptiveVertex::add - ((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, (p1->z + p2->z) * 0.5, - allVertices); - adaptiveVertex *p23 = adaptiveVertex::add - ((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, (p2->z + p3->z) * 0.5, - allVertices); - adaptiveVertex *p31 = adaptiveVertex::add - ((p3->x + p1->x) * 0.5, (p3->y + p1->y) * 0.5, (p3->z + p1->z) * 0.5, - allVertices); - adaptiveVertex *p1425 = adaptiveVertex::add - ((p14->x + p25->x) * 0.5, (p14->y + p25->y) * 0.5, (p14->z + p25->z) * 0.5, - allVertices); - adaptiveVertex *p2536 = adaptiveVertex::add - ((p25->x + p36->x) * 0.5, (p25->y + p36->y) * 0.5, (p25->z + p36->z) * 0.5, - allVertices); - adaptiveVertex *p3614 = adaptiveVertex::add - ((p36->x + p14->x) * 0.5, (p36->y + p14->y) * 0.5, (p36->z + p14->z) * 0.5, - allVertices); - adaptiveVertex *p45 = adaptiveVertex::add - ((p4->x + p5->x) * 0.5, (p4->y + p5->y) * 0.5, (p4->z + p5->z) * 0.5, - allVertices); - adaptiveVertex *p56 = adaptiveVertex::add - ((p5->x + p6->x) * 0.5, (p5->y + p6->y) * 0.5, (p5->z + p6->z) * 0.5, - allVertices); - adaptiveVertex *p64 = adaptiveVertex::add - ((p6->x + p4->x) * 0.5, (p6->y + p4->y) * 0.5, (p6->z + p4->z) * 0.5, - allVertices); + adaptiveVertex *p14 = + adaptiveVertex::add((p1->x + p4->x) * 0.5, (p1->y + p4->y) * 0.5, + (p1->z + p4->z) * 0.5, allVertices); + adaptiveVertex *p25 = + adaptiveVertex::add((p2->x + p5->x) * 0.5, (p2->y + p5->y) * 0.5, + (p2->z + p5->z) * 0.5, allVertices); + adaptiveVertex *p36 = + adaptiveVertex::add((p3->x + p6->x) * 0.5, (p3->y + p6->y) * 0.5, + (p3->z + p6->z) * 0.5, allVertices); + adaptiveVertex *p12 = + adaptiveVertex::add((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, + (p1->z + p2->z) * 0.5, allVertices); + adaptiveVertex *p23 = + adaptiveVertex::add((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, + (p2->z + p3->z) * 0.5, allVertices); + adaptiveVertex *p31 = + adaptiveVertex::add((p3->x + p1->x) * 0.5, (p3->y + p1->y) * 0.5, + (p3->z + p1->z) * 0.5, allVertices); + adaptiveVertex *p1425 = + adaptiveVertex::add((p14->x + p25->x) * 0.5, (p14->y + p25->y) * 0.5, + (p14->z + p25->z) * 0.5, allVertices); + adaptiveVertex *p2536 = + adaptiveVertex::add((p25->x + p36->x) * 0.5, (p25->y + p36->y) * 0.5, + (p25->z + p36->z) * 0.5, allVertices); + adaptiveVertex *p3614 = + adaptiveVertex::add((p36->x + p14->x) * 0.5, (p36->y + p14->y) * 0.5, + (p36->z + p14->z) * 0.5, allVertices); + adaptiveVertex *p45 = + adaptiveVertex::add((p4->x + p5->x) * 0.5, (p4->y + p5->y) * 0.5, + (p4->z + p5->z) * 0.5, allVertices); + adaptiveVertex *p56 = + adaptiveVertex::add((p5->x + p6->x) * 0.5, (p5->y + p6->y) * 0.5, + (p5->z + p6->z) * 0.5, allVertices); + adaptiveVertex *p64 = + adaptiveVertex::add((p6->x + p4->x) * 0.5, (p6->y + p4->y) * 0.5, + (p6->z + p4->z) * 0.5, allVertices); p->e[0] = new adaptivePrism(p1, p12, p31, p14, p1425, p3614); recurCreate(p->e[0], maxlevel, level); p->e[1] = new adaptivePrism(p2, p23, p12, p25, p2536, p1425); @@ -890,12 +889,13 @@ void adaptivePrism::recurError(adaptivePrism *p, double AVG, double tol) p->visible = true; else { double vi[8]; - for(int i = 0; i < 8; i++) - vi[i] = p->e[i]->V(); - const double vr = (vi[0] + vi[1] + vi[2] + vi[3]/2 + vi[4] + vi[5] + vi[6] + vi[7]/2) / 7; + for(int i = 0; i < 8; i++) vi[i] = p->e[i]->V(); + const double vr = + (vi[0] + vi[1] + vi[2] + vi[3] / 2 + vi[4] + vi[5] + vi[6] + vi[7] / 2) / + 7; const double v = p->V(); if(!p->e[0]->e[0]) { - if(fabs(v - vr) > AVG * tol){ + if(fabs(v - vr) > AVG * tol) { p->visible = false; recurError(p->e[0], AVG, tol); recurError(p->e[1], AVG, tol); @@ -911,7 +911,7 @@ void adaptivePrism::recurError(adaptivePrism *p, double AVG, double tol) } else { bool err = false; - for(int i = 0; i < 8; i++){ + for(int i = 0; i < 8; i++) { double vi1 = p->e[i]->e[0]->V(); double vi2 = p->e[i]->e[1]->V(); double vi3 = p->e[i]->e[2]->V(); @@ -920,14 +920,14 @@ void adaptivePrism::recurError(adaptivePrism *p, double AVG, double tol) double vi6 = p->e[i]->e[5]->V(); double vi7 = p->e[i]->e[6]->V(); double vi8 = p->e[i]->e[7]->V(); - double vri = (vi1 + vi2 + vi3 + vi4/2 + vi5 + vi6 + vi7 + vi8/2) / 7; + double vri = + (vi1 + vi2 + vi3 + vi4 / 2 + vi5 + vi6 + vi7 + vi8 / 2) / 7; err |= (fabs((vi[i] - vri)) > AVG * tol); } err |= (fabs((v - vr)) > AVG * tol); if(err) { p->visible = false; - for(int i = 0; i < 8; i++) - recurError(p->e[i], AVG, tol); + for(int i = 0; i < 8; i++) recurError(p->e[i], AVG, tol); } else p->visible = true; @@ -963,54 +963,46 @@ void adaptivePyramid::recurCreate(adaptivePyramid *p, int maxlevel, int level) // center of the quad - adaptiveVertex *p1234 = adaptiveVertex::add - ((p1->x + p2->x + p3->x + p4->x)*0.25, - (p1->y + p2->y + p3->y + p4->y)*0.25, - (p1->z + p2->z + p3->z + p4->z)*0.25,allVertices); + adaptiveVertex *p1234 = + adaptiveVertex::add((p1->x + p2->x + p3->x + p4->x) * 0.25, + (p1->y + p2->y + p3->y + p4->y) * 0.25, + (p1->z + p2->z + p3->z + p4->z) * 0.25, allVertices); // quad edge points - adaptiveVertex *p12 = adaptiveVertex::add - ((p1->x + p2->x)*0.5, - (p1->y + p2->y)*0.5, - (p1->z + p2->z)*0.5,allVertices); + adaptiveVertex *p12 = + adaptiveVertex::add((p1->x + p2->x) * 0.5, (p1->y + p2->y) * 0.5, + (p1->z + p2->z) * 0.5, allVertices); - adaptiveVertex *p23 = adaptiveVertex::add - ((p2->x + p3->x)*0.5, - (p2->y + p3->y)*0.5, - (p2->z + p3->z)*0.5,allVertices); + adaptiveVertex *p23 = + adaptiveVertex::add((p2->x + p3->x) * 0.5, (p2->y + p3->y) * 0.5, + (p2->z + p3->z) * 0.5, allVertices); - adaptiveVertex *p34 = adaptiveVertex::add - ((p3->x + p4->x)*0.5, - (p3->y + p4->y)*0.5, - (p3->z + p4->z)*0.5,allVertices); + adaptiveVertex *p34 = + adaptiveVertex::add((p3->x + p4->x) * 0.5, (p3->y + p4->y) * 0.5, + (p3->z + p4->z) * 0.5, allVertices); - adaptiveVertex *p41 = adaptiveVertex::add - ((p4->x + p1->x)*0.5, - (p4->y + p1->y)*0.5, - (p4->z + p1->z)*0.5,allVertices); + adaptiveVertex *p41 = + adaptiveVertex::add((p4->x + p1->x) * 0.5, (p4->y + p1->y) * 0.5, + (p4->z + p1->z) * 0.5, allVertices); // quad vertex to apex edge points - adaptiveVertex *p15 = adaptiveVertex::add - ((p1->x + p5->x)*0.5, - (p1->y + p5->y)*0.5, - (p1->z + p5->z)*0.5,allVertices); + adaptiveVertex *p15 = + adaptiveVertex::add((p1->x + p5->x) * 0.5, (p1->y + p5->y) * 0.5, + (p1->z + p5->z) * 0.5, allVertices); - adaptiveVertex *p25 = adaptiveVertex::add - ((p2->x + p5->x)*0.5, - (p2->y + p5->y)*0.5, - (p2->z + p5->z)*0.5,allVertices); + adaptiveVertex *p25 = + adaptiveVertex::add((p2->x + p5->x) * 0.5, (p2->y + p5->y) * 0.5, + (p2->z + p5->z) * 0.5, allVertices); - adaptiveVertex *p35 = adaptiveVertex::add - ((p3->x + p5->x)*0.5, - (p3->y + p5->y)*0.5, - (p3->z + p5->z)*0.5,allVertices); + adaptiveVertex *p35 = + adaptiveVertex::add((p3->x + p5->x) * 0.5, (p3->y + p5->y) * 0.5, + (p3->z + p5->z) * 0.5, allVertices); - adaptiveVertex *p45 = adaptiveVertex::add - ((p4->x + p5->x)*0.5, - (p4->y + p5->y)*0.5, - (p4->z + p5->z)*0.5,allVertices); + adaptiveVertex *p45 = + adaptiveVertex::add((p4->x + p5->x) * 0.5, (p4->y + p5->y) * 0.5, + (p4->z + p5->z) * 0.5, allVertices); // four base pyramids on the quad base @@ -1025,21 +1017,21 @@ void adaptivePyramid::recurCreate(adaptivePyramid *p, int maxlevel, int level) // top pyramids - p->e[4] = new adaptivePyramid(p15,p25,p35,p45,p5); + p->e[4] = new adaptivePyramid(p15, p25, p35, p45, p5); recurCreate(p->e[4], maxlevel, level); - p->e[5] = new adaptivePyramid(p15,p45,p35,p25,p1234); + p->e[5] = new adaptivePyramid(p15, p45, p35, p25, p1234); recurCreate(p->e[5], maxlevel, level); // degenerated pyramids to replace the remaining tetrahedral holes // degenerated quad in the interior of the element, apices on the quad edges - p->e[6] = new adaptivePyramid(p1234,p25,p15,p1234,p12); + p->e[6] = new adaptivePyramid(p1234, p25, p15, p1234, p12); recurCreate(p->e[6], maxlevel, level); - p->e[7] = new adaptivePyramid(p1234,p35,p25,p1234,p23); + p->e[7] = new adaptivePyramid(p1234, p35, p25, p1234, p23); recurCreate(p->e[7], maxlevel, level); - p->e[8] = new adaptivePyramid(p1234,p45,p35,p1234,p34); + p->e[8] = new adaptivePyramid(p1234, p45, p35, p1234, p34); recurCreate(p->e[8], maxlevel, level); - p->e[9] = new adaptivePyramid(p1234,p15,p45,p1234,p41); + p->e[9] = new adaptivePyramid(p1234, p15, p45, p1234, p41); recurCreate(p->e[9], maxlevel, level); } @@ -1055,36 +1047,36 @@ void adaptivePyramid::recurError(adaptivePyramid *p, double AVG, double tol) p->visible = true; else { double vi[10]; - for (int i = 0; i < 10; i++) vi[i] = p->e[i]->V(); + for(int i = 0; i < 10; i++) vi[i] = p->e[i]->V(); double vr = 0; - for (int i = 0; i < 6 ; i++) vr += vi[i]; // pyramids have volume V/8 - for (int i = 6; i < 10; i++) vr += vi[i]*0.5; // tetrahedra have volume V/16 + for(int i = 0; i < 6; i++) vr += vi[i]; // pyramids have volume V/8 + for(int i = 6; i < 10; i++) + vr += vi[i] * 0.5; // tetrahedra have volume V/16 vr /= 8.; const double v = p->V(); if(!p->e[0]->e[0]) { - if(fabs(v - vr) > AVG * tol){ + if(fabs(v - vr) > AVG * tol) { p->visible = false; - for (int i = 0; i < 10; i++) recurError(p->e[i],AVG,tol); + for(int i = 0; i < 10; i++) recurError(p->e[i], AVG, tol); } else p->visible = true; } else { bool err = false; - for(int i = 0; i < 10; i++){ + for(int i = 0; i < 10; i++) { double vj[10]; - for (int j = 0; j < 10; j++) vj[j] = p->e[i]->e[j]->V(); + for(int j = 0; j < 10; j++) vj[j] = p->e[i]->e[j]->V(); double vri = 0; - for (int j = 0; j < 6 ; j++) vri += vj[j]; - for (int j = 6; j < 10; j++) vri += vj[j]*0.5; + for(int j = 0; j < 6; j++) vri += vj[j]; + for(int j = 6; j < 10; j++) vri += vj[j] * 0.5; vri /= 8.; err |= (fabs((vi[i] - vri)) > AVG * tol); } err |= (fabs((v - vr)) > AVG * tol); if(err) { p->visible = false; - for(int i = 0; i < 10; i++) - recurError(p->e[i], AVG, tol); + for(int i = 0; i < 10; i++) recurError(p->e[i], AVG, tol); } else p->visible = true; @@ -1093,30 +1085,28 @@ void adaptivePyramid::recurError(adaptivePyramid *p, double AVG, double tol) } template <class T> -adaptiveElements<T>::adaptiveElements(std::vector<fullMatrix<double>*> &p) - : _coeffsVal(0), _eexpsVal(0), _interpolVal(0), - _coeffsGeom(0), _eexpsGeom(0), _interpolGeom(0) +adaptiveElements<T>::adaptiveElements(std::vector<fullMatrix<double> *> &p) + : _coeffsVal(0), _eexpsVal(0), _interpolVal(0), _coeffsGeom(0), _eexpsGeom(0), + _interpolGeom(0) { - if(p.size() >= 2){ + if(p.size() >= 2) { _coeffsVal = p[0]; _eexpsVal = p[1]; } - if(p.size() == 4){ + if(p.size() == 4) { _coeffsGeom = p[2]; _eexpsGeom = p[3]; } } -template <class T> -adaptiveElements<T>::~adaptiveElements() +template <class T> adaptiveElements<T>::~adaptiveElements() { if(_interpolVal) delete _interpolVal; if(_interpolGeom) delete _interpolGeom; cleanElement<T>(); } -template <class T> -void adaptiveElements<T>::init(int level) +template <class T> void adaptiveElements<T>::init(int level) { #ifdef TIMER double t1 = GetTimeInSeconds(); @@ -1140,22 +1130,19 @@ void adaptiveElements<T>::init(int level) int i = 0; for(std::set<adaptiveVertex>::iterator it = T::allVertices.begin(); it != T::allVertices.end(); ++it) { - if(_coeffsVal && _eexpsVal) - computeShapeFunctions(_coeffsVal, _eexpsVal, - it->x, it->y, it->z, &sfv, tmpv); + computeShapeFunctions(_coeffsVal, _eexpsVal, it->x, it->y, it->z, &sfv, + tmpv); else T::GSF(it->x, it->y, it->z, sfv); - for(int j = 0; j < numVals; j++) - (*_interpolVal)(i, j) = sfv(j); + for(int j = 0; j < numVals; j++) (*_interpolVal)(i, j) = sfv(j); if(_coeffsGeom && _eexpsGeom) - computeShapeFunctions(_coeffsGeom, _eexpsGeom, - it->x, it->y, it->z, &sfg, tmpg); + computeShapeFunctions(_coeffsGeom, _eexpsGeom, it->x, it->y, it->z, &sfg, + tmpg); else T::GSF(it->x, it->y, it->z, sfg); - for(int j = 0; j < numNodes; j++) - (*_interpolGeom)(i, j) = sfg(j); + for(int j = 0; j < numNodes; j++) (*_interpolGeom)(i, j) = sfg(j); i++; } @@ -1169,22 +1156,23 @@ void adaptiveElements<T>::init(int level) #endif } -template <> -void adaptiveElements<adaptivePyramid>::init(int level) +template <> void adaptiveElements<adaptivePyramid>::init(int level) { #ifdef TIMER double t1 = GetTimeInSeconds(); #endif adaptivePyramid::create(level); - int numVals = _coeffsVal ? _coeffsVal->size1() : adaptivePyramid::numNodes; + int numVals = _coeffsVal ? _coeffsVal->size1() : adaptivePyramid::numNodes; int numNodes = _coeffsGeom ? _coeffsGeom->size1() : adaptivePyramid::numNodes; if(_interpolVal) delete _interpolVal; - _interpolVal = new fullMatrix<double>(adaptivePyramid::allVertices.size(), numVals); + _interpolVal = + new fullMatrix<double>(adaptivePyramid::allVertices.size(), numVals); if(_interpolGeom) delete _interpolGeom; - _interpolGeom = new fullMatrix<double>(adaptivePyramid::allVertices.size(), numNodes); + _interpolGeom = + new fullMatrix<double>(adaptivePyramid::allVertices.size(), numNodes); fullVector<double> sfv(numVals), *tmpv = 0; fullVector<double> sfg(numNodes), *tmpg = 0; @@ -1192,25 +1180,23 @@ void adaptiveElements<adaptivePyramid>::init(int level) if(_eexpsGeom) tmpg = new fullVector<double>(_eexpsGeom->size1()); int i = 0; - for(std::set<adaptiveVertex>::iterator it = adaptivePyramid::allVertices.begin(); + for(std::set<adaptiveVertex>::iterator it = + adaptivePyramid::allVertices.begin(); it != adaptivePyramid::allVertices.end(); ++it) { - if(_coeffsVal && _eexpsVal) - computeShapeFunctionsPyramid(_coeffsVal, _eexpsVal, - it->x, it->y, it->z, &sfv, tmpv); + computeShapeFunctionsPyramid(_coeffsVal, _eexpsVal, it->x, it->y, it->z, + &sfv, tmpv); else adaptivePyramid::GSF(it->x, it->y, it->z, sfv); - for(int j = 0; j < numVals; j++) - (*_interpolVal)(i, j) = sfv(j); + for(int j = 0; j < numVals; j++) (*_interpolVal)(i, j) = sfv(j); if(_coeffsGeom && _eexpsGeom) - computeShapeFunctionsPyramid(_coeffsGeom, _eexpsGeom, - it->x, it->y, it->z, &sfg, tmpg); + computeShapeFunctionsPyramid(_coeffsGeom, _eexpsGeom, it->x, it->y, it->z, + &sfg, tmpg); else adaptivePyramid::GSF(it->x, it->y, it->z, sfg); - for(int j = 0; j < numNodes; j++) - (*_interpolGeom)(i, j) = sfg(j); + for(int j = 0; j < numNodes; j++) (*_interpolGeom)(i, j) = sfg(j); i++; } @@ -1227,22 +1213,21 @@ void adaptiveElements<adaptivePyramid>::init(int level) template <class T> void adaptiveElements<T>::adapt(double tol, int numComp, std::vector<PCoords> &coords, - std::vector<PValues> &values, - double &minVal, double &maxVal, - GMSH_PostPlugin *plug, + std::vector<PValues> &values, double &minVal, + double &maxVal, GMSH_PostPlugin *plug, bool onlyComputeMinMax) { int numVertices = T::allVertices.size(); - if(!numVertices){ + if(!numVertices) { Msg::Error("No adapted vertices to interpolate"); return; } int numVals = _coeffsVal ? _coeffsVal->size1() : T::numNodes; - if(numVals != (int)values.size()){ - Msg::Error("Wrong number of values in adaptation %d != %i", - numVals, values.size()); + if(numVals != (int)values.size()) { + Msg::Error("Wrong number of values in adaptation %d != %i", numVals, + values.size()); return; } @@ -1251,60 +1236,58 @@ void adaptiveElements<T>::adapt(double tol, int numComp, #endif fullVector<double> val(numVals), res(numVertices); - switch (numComp) { - case 1: - { - for(int i = 0; i < numVals; i++) val(i) = values[i].v[0]; - break; - } + switch(numComp) { + case 1: { + for(int i = 0; i < numVals; i++) val(i) = values[i].v[0]; + break; + } case 3: - case 9: - { - for(int i = 0; i < numVals; i++) { - val(i) = 0; - for (int k=0; k < numComp; k++) val(i) += values[i].v[k] * values[i].v[k]; - } - break; - } - default: - { - Msg::Error("Can only adapt scalar, vector or tensor data"); - return; + case 9: { + for(int i = 0; i < numVals; i++) { + val(i) = 0; + for(int k = 0; k < numComp; k++) + val(i) += values[i].v[k] * values[i].v[k]; } + break; + } + default: { + Msg::Error("Can only adapt scalar, vector or tensor data"); + return; + } } _interpolVal->mult(val, res); - //minVal = VAL_INF; - //maxVal = -VAL_INF; - for(int i = 0; i < numVertices; i++){ + // minVal = VAL_INF; + // maxVal = -VAL_INF; + for(int i = 0; i < numVertices; i++) { minVal = std::min(minVal, res(i)); maxVal = std::max(maxVal, res(i)); } if(onlyComputeMinMax) return; fullMatrix<double> *resxyz = 0; - if(numComp == 3 || numComp == 9){ - fullMatrix<double> valxyz(numVals,numComp); - resxyz = new fullMatrix<double>(numVertices,numComp); - for(int i = 0; i < numVals; i++){ - for (int k=0;k<numComp;k++) { - valxyz(i,k) = values[i].v[k]; + if(numComp == 3 || numComp == 9) { + fullMatrix<double> valxyz(numVals, numComp); + resxyz = new fullMatrix<double>(numVertices, numComp); + for(int i = 0; i < numVals; i++) { + for(int k = 0; k < numComp; k++) { + valxyz(i, k) = values[i].v[k]; } } _interpolVal->mult(valxyz, *resxyz); } int numNodes = _coeffsGeom ? _coeffsGeom->size1() : T::numNodes; - if(numNodes != (int)coords.size()){ - Msg::Error("Wrong number of nodes in adaptation %d != %i", - numNodes, coords.size()); + if(numNodes != (int)coords.size()) { + Msg::Error("Wrong number of nodes in adaptation %d != %i", numNodes, + coords.size()); if(resxyz) delete resxyz; return; } fullMatrix<double> xyz(numNodes, 3), XYZ(numVertices, 3); - for(int i = 0; i < numNodes; i++){ + for(int i = 0; i < numNodes; i++) { xyz(i, 0) = coords[i].c[0]; xyz(i, 1) = coords[i].c[1]; xyz(i, 2) = coords[i].c[2]; @@ -1318,21 +1301,21 @@ void adaptiveElements<T>::adapt(double tol, int numComp, int i = 0; for(std::set<adaptiveVertex>::iterator it = T::allVertices.begin(); - it != T::allVertices.end(); ++it){ + it != T::allVertices.end(); ++it) { // ok because we know this will not change the set ordering - adaptiveVertex *p = (adaptiveVertex*)&(*it); + adaptiveVertex *p = (adaptiveVertex *)&(*it); p->val = res(i); - if(resxyz){ - p->val = (*resxyz)(i, 0); + if(resxyz) { + p->val = (*resxyz)(i, 0); p->valy = (*resxyz)(i, 1); p->valz = (*resxyz)(i, 2); - if (numComp == 9) { - p->valyx = (*resxyz)(i,3); - p->valyy = (*resxyz)(i,4); - p->valyz = (*resxyz)(i,5); - p->valzx = (*resxyz)(i,6); - p->valzy = (*resxyz)(i,7); - p->valzz = (*resxyz)(i,8); + if(numComp == 9) { + p->valyx = (*resxyz)(i, 3); + p->valyy = (*resxyz)(i, 4); + p->valyz = (*resxyz)(i, 5); + p->valzx = (*resxyz)(i, 6); + p->valzy = (*resxyz)(i, 7); + p->valzz = (*resxyz)(i, 8); } } p->X = XYZ(i, 0); @@ -1343,39 +1326,35 @@ void adaptiveElements<T>::adapt(double tol, int numComp, if(resxyz) delete resxyz; - for(typename std::list<T*>::iterator it = T::all.begin(); - it != T::all.end(); it++) + for(typename std::list<T *>::iterator it = T::all.begin(); it != T::all.end(); + it++) (*it)->visible = false; - if(!plug || tol != 0.){ + if(!plug || tol != 0.) { double avg = fabs(maxVal - minVal); if(tol < 0) avg = 1.; // force visibility to the smallest subdivision T::error(avg, tol); } - if(plug) - plug->assignSpecificVisibility(); + if(plug) plug->assignSpecificVisibility(); coords.clear(); values.clear(); - for(typename std::list<T*>::iterator it = T::all.begin(); - it != T::all.end(); it++){ - if((*it)->visible){ + for(typename std::list<T *>::iterator it = T::all.begin(); it != T::all.end(); + it++) { + if((*it)->visible) { adaptiveVertex **p = (*it)->p; for(int i = 0; i < T::numNodes; i++) { coords.push_back(PCoords(p[i]->X, p[i]->Y, p[i]->Z)); - switch (numComp) { - case 1: - values.push_back(PValues(p[i]->val)); - break; + switch(numComp) { + case 1: values.push_back(PValues(p[i]->val)); break; case 3: values.push_back(PValues(p[i]->val, p[i]->valy, p[i]->valz)); break; case 9: - values.push_back(PValues(p[i]->val, - p[i]->valy, p[i]->valz, - p[i]->valyx,p[i]->valyy,p[i]->valyz, - p[i]->valzx,p[i]->valzy,p[i]->valzz)); + values.push_back(PValues(p[i]->val, p[i]->valy, p[i]->valz, + p[i]->valyx, p[i]->valyy, p[i]->valyz, + p[i]->valzx, p[i]->valzy, p[i]->valzz)); break; } } @@ -1384,55 +1363,70 @@ void adaptiveElements<T>::adapt(double tol, int numComp, } template <class T> -void adaptiveElements<T>::addInView(double tol, int step, - PViewData *in, PViewDataList *out, - GMSH_PostPlugin *plug) +void adaptiveElements<T>::addInView(double tol, int step, PViewData *in, + PViewDataList *out, GMSH_PostPlugin *plug) { int numComp = in->getNumComponents(0, 0, 0); if(numComp != 1 && numComp != 3 && numComp != 9) return; int numEle = 0, *outNb = 0; std::vector<double> *outList = 0; - switch(T::numEdges){ + switch(T::numEdges) { case 0: numEle = in->getNumPoints(); - outNb = (numComp == 1) ? &out->NbSP : ((numComp == 3) ? &out->NbVP : &out->NbTP); - outList = (numComp == 1) ? &out->SP : ((numComp == 3) ? &out->VP : &out->TP); + outNb = + (numComp == 1) ? &out->NbSP : ((numComp == 3) ? &out->NbVP : &out->NbTP); + outList = + (numComp == 1) ? &out->SP : ((numComp == 3) ? &out->VP : &out->TP); break; case 1: numEle = in->getNumLines(); - outNb = (numComp == 1) ? &out->NbSL : ((numComp == 3) ? &out->NbVL : &out->NbTL); - outList = (numComp == 1) ? &out->SL : ((numComp == 3) ? &out->VL : &out->TL); + outNb = + (numComp == 1) ? &out->NbSL : ((numComp == 3) ? &out->NbVL : &out->NbTL); + outList = + (numComp == 1) ? &out->SL : ((numComp == 3) ? &out->VL : &out->TL); break; case 3: numEle = in->getNumTriangles(); - outNb = (numComp == 1) ? &out->NbST : ((numComp == 3) ? &out->NbVT : &out->NbTT); - outList = (numComp == 1) ? &out->ST : ((numComp == 3) ? &out->VT : &out->TT); + outNb = + (numComp == 1) ? &out->NbST : ((numComp == 3) ? &out->NbVT : &out->NbTT); + outList = + (numComp == 1) ? &out->ST : ((numComp == 3) ? &out->VT : &out->TT); break; case 4: numEle = in->getNumQuadrangles(); - outNb = (numComp == 1) ? &out->NbSQ : ((numComp == 3) ? &out->NbVQ : &out->NbTQ); - outList = (numComp == 1) ? &out->SQ : ((numComp == 3) ? &out->VQ : &out->TQ); + outNb = + (numComp == 1) ? &out->NbSQ : ((numComp == 3) ? &out->NbVQ : &out->NbTQ); + outList = + (numComp == 1) ? &out->SQ : ((numComp == 3) ? &out->VQ : &out->TQ); break; case 6: numEle = in->getNumTetrahedra(); - outNb = (numComp == 1) ? &out->NbSS : ((numComp == 3) ? &out->NbVS : &out->NbTS); - outList = (numComp == 1) ? &out->SS : ((numComp == 3) ? &out->VS : &out->TS); + outNb = + (numComp == 1) ? &out->NbSS : ((numComp == 3) ? &out->NbVS : &out->NbTS); + outList = + (numComp == 1) ? &out->SS : ((numComp == 3) ? &out->VS : &out->TS); break; case 9: numEle = in->getNumPrisms(); - outNb = (numComp == 1) ? &out->NbSI : ((numComp == 3) ? &out->NbVI : &out->NbTI); - outList = (numComp == 1) ? &out->SI : ((numComp == 3) ? &out->VI : &out->TI); + outNb = + (numComp == 1) ? &out->NbSI : ((numComp == 3) ? &out->NbVI : &out->NbTI); + outList = + (numComp == 1) ? &out->SI : ((numComp == 3) ? &out->VI : &out->TI); break; case 8: numEle = in->getNumPyramids(); - outNb = (numComp == 1) ? &out->NbSY : ((numComp == 3) ? &out->NbVY : &out->NbTY); - outList = (numComp == 1) ? &out->SY : ((numComp == 3) ? &out->VY : &out->TY); + outNb = + (numComp == 1) ? &out->NbSY : ((numComp == 3) ? &out->NbVY : &out->NbTY); + outList = + (numComp == 1) ? &out->SY : ((numComp == 3) ? &out->VY : &out->TY); break; case 12: numEle = in->getNumHexahedra(); - outNb = (numComp == 1) ? &out->NbSH : ((numComp == 3) ? &out->NbVH : &out->NbTH); - outList = (numComp == 1) ? &out->SH : ((numComp == 3) ? &out->VH : &out->TH); + outNb = + (numComp == 1) ? &out->NbSH : ((numComp == 3) ? &out->NbVH : &out->NbTH); + outList = + (numComp == 1) ? &out->SH : ((numComp == 3) ? &out->VH : &out->TH); break; } if(!numEle) return; @@ -1440,13 +1434,14 @@ void adaptiveElements<T>::addInView(double tol, int step, outList->clear(); *outNb = 0; - for(int ent = 0; ent < in->getNumEntities(step); ent++){ - for(int ele = 0; ele < in->getNumElements(step, ent); ele++){ + for(int ent = 0; ent < in->getNumEntities(step); ent++) { + for(int ele = 0; ele < in->getNumElements(step, ent); ele++) { if(in->skipElement(step, ent, ele) || - in->getNumEdges(step, ent, ele) != T::numEdges) continue; + in->getNumEdges(step, ent, ele) != T::numEdges) + continue; int numNodes = in->getNumNodes(step, ent, ele); std::vector<PCoords> coords; - for(int i = 0; i < numNodes; i++){ + for(int i = 0; i < numNodes; i++) { double x, y, z; in->getNode(step, ent, ele, i, x, y, z); coords.push_back(PCoords(x, y, z)); @@ -1454,48 +1449,45 @@ void adaptiveElements<T>::addInView(double tol, int step, int numVal = in->getNumValues(step, ent, ele); std::vector<PValues> values; - switch (numComp) { + switch(numComp) { case 1: - for(int i = 0; i < numVal; i++){ + for(int i = 0; i < numVal; i++) { double val; in->getValue(step, ent, ele, i, val); values.push_back(PValues(val)); } break; - case 3: - { - for(int i = 0; i < numVal / 3; i++){ - double vx, vy, vz; - in->getValue(step, ent, ele, 3 * i + 0, vx); - in->getValue(step, ent, ele, 3 * i + 1, vy); - in->getValue(step, ent, ele, 3 * i + 2, vz); - values.push_back(PValues(vx, vy, vz)); - } - break; + case 3: { + for(int i = 0; i < numVal / 3; i++) { + double vx, vy, vz; + in->getValue(step, ent, ele, 3 * i + 0, vx); + in->getValue(step, ent, ele, 3 * i + 1, vy); + in->getValue(step, ent, ele, 3 * i + 2, vz); + values.push_back(PValues(vx, vy, vz)); } - case 9: - { - for(int i = 0; i < numVal / 9; i++){ - double vxx, vxy, vxz,vyx, vyy, vyz,vzx, vzy, vzz ; - in->getValue(step, ent, ele, 9 * i + 0, vxx); - in->getValue(step, ent, ele, 9 * i + 1, vxy); - in->getValue(step, ent, ele, 9 * i + 2, vxz); - in->getValue(step, ent, ele, 9 * i + 3, vyx); - in->getValue(step, ent, ele, 9 * i + 4, vyy); - in->getValue(step, ent, ele, 9 * i + 5, vyz); - in->getValue(step, ent, ele, 9 * i + 6, vzx); - in->getValue(step, ent, ele, 9 * i + 7, vzy); - in->getValue(step, ent, ele, 9 * i + 8, vzz); - values.push_back(PValues(vxx,vxy,vxz, - vyx,vyy,vyz, - vzx,vzy,vzz)); - } - break; + break; + } + case 9: { + for(int i = 0; i < numVal / 9; i++) { + double vxx, vxy, vxz, vyx, vyy, vyz, vzx, vzy, vzz; + in->getValue(step, ent, ele, 9 * i + 0, vxx); + in->getValue(step, ent, ele, 9 * i + 1, vxy); + in->getValue(step, ent, ele, 9 * i + 2, vxz); + in->getValue(step, ent, ele, 9 * i + 3, vyx); + in->getValue(step, ent, ele, 9 * i + 4, vyy); + in->getValue(step, ent, ele, 9 * i + 5, vyz); + in->getValue(step, ent, ele, 9 * i + 6, vzx); + in->getValue(step, ent, ele, 9 * i + 7, vzy); + in->getValue(step, ent, ele, 9 * i + 8, vzz); + values.push_back( + PValues(vxx, vxy, vxz, vyx, vyy, vyz, vzx, vzy, vzz)); } + break; + } } adapt(tol, numComp, coords, values, out->Min, out->Max, plug); *outNb += coords.size() / T::numNodes; - for(unsigned int i = 0; i < coords.size() / T::numNodes; i++){ + for(unsigned int i = 0; i < coords.size() / T::numNodes; i++) { for(int k = 0; k < T::numNodes; ++k) outList->push_back(coords[T::numNodes * i + k].c[0]); for(int k = 0; k < T::numNodes; ++k) @@ -1511,52 +1503,54 @@ void adaptiveElements<T>::addInView(double tol, int step, } adaptiveData::adaptiveData(PViewData *data, bool outDataInit) - : _step(-1), _level(-1), _tol(-1.), _inData(data), - _points(0), _lines(0), _triangles(0), _quadrangles(0), - _tetrahedra(0), _hexahedra(0), _prisms(0),_pyramids(0) + : _step(-1), _level(-1), _tol(-1.), _inData(data), _points(0), _lines(0), + _triangles(0), _quadrangles(0), _tetrahedra(0), _hexahedra(0), _prisms(0), + _pyramids(0) { - if(outDataInit == true) { // For visualization of the adapted view in GMSH GUI only + if(outDataInit == + true) { // For visualization of the adapted view in GMSH GUI only _outData = new PViewDataList(true); _outData->setName(data->getName() + "_adapted"); } else { _outData = 0; // For external used } - std::vector<fullMatrix<double>*> p; - if(_inData->getNumPoints()){ + std::vector<fullMatrix<double> *> p; + if(_inData->getNumPoints()) { _inData->getInterpolationMatrices(TYPE_PNT, p); _points = new adaptiveElements<adaptivePoint>(p); } - if(_inData->getNumLines()){ + if(_inData->getNumLines()) { _inData->getInterpolationMatrices(TYPE_LIN, p); _lines = new adaptiveElements<adaptiveLine>(p); } - if(_inData->getNumTriangles()){ + if(_inData->getNumTriangles()) { _inData->getInterpolationMatrices(TYPE_TRI, p); _triangles = new adaptiveElements<adaptiveTriangle>(p); } - if(_inData->getNumQuadrangles()){ + if(_inData->getNumQuadrangles()) { _inData->getInterpolationMatrices(TYPE_QUA, p); _quadrangles = new adaptiveElements<adaptiveQuadrangle>(p); } - if(_inData->getNumTetrahedra()){ + if(_inData->getNumTetrahedra()) { _inData->getInterpolationMatrices(TYPE_TET, p); _tetrahedra = new adaptiveElements<adaptiveTetrahedron>(p); } - if(_inData->getNumPrisms()){ + if(_inData->getNumPrisms()) { _inData->getInterpolationMatrices(TYPE_PRI, p); _prisms = new adaptiveElements<adaptivePrism>(p); } - if(_inData->getNumHexahedra()){ + if(_inData->getNumHexahedra()) { _inData->getInterpolationMatrices(TYPE_HEX, p); _hexahedra = new adaptiveElements<adaptiveHexahedron>(p); } - if(_inData->getNumPyramids()){ + if(_inData->getNumPyramids()) { _inData->getInterpolationMatrices(TYPE_PYR, p); _pyramids = new adaptiveElements<adaptivePyramid>(p); } upWriteVTK(true); // By default, write VTK data if called... - upBuildStaticData(false); // ... and do not generated global static data structure (only useful for ParaView plugin). + upBuildStaticData(false); // ... and do not generated global static data + // structure (only useful for ParaView plugin). } adaptiveData::~adaptiveData() @@ -1580,7 +1574,7 @@ void adaptiveData::changeResolution(int step, int level, double tol, { timerInit = timerAdapt = 0.; - if(_level != level){ + if(_level != level) { if(_points) _points->init(level); if(_lines) _lines->init(level); if(_triangles) _triangles->init(level); @@ -1588,14 +1582,15 @@ void adaptiveData::changeResolution(int step, int level, double tol, if(_tetrahedra) _tetrahedra->init(level); if(_prisms) _prisms->init(level); if(_hexahedra) _hexahedra->init(level); - if(_pyramids) _pyramids->init(level); + if(_pyramids) _pyramids->init(level); } - if(plug || _step != step || _level != level || _tol != tol){ + if(plug || _step != step || _level != level || _tol != tol) { _outData->setDirty(true); if(_points) _points->addInView(tol, step, _inData, _outData, plug); if(_lines) _lines->addInView(tol, step, _inData, _outData, plug); if(_triangles) _triangles->addInView(tol, step, _inData, _outData, plug); - if(_quadrangles) _quadrangles->addInView(tol, step, _inData, _outData, plug); + if(_quadrangles) + _quadrangles->addInView(tol, step, _inData, _outData, plug); if(_tetrahedra) _tetrahedra->addInView(tol, step, _inData, _outData, plug); if(_prisms) _prisms->addInView(tol, step, _inData, _outData, plug); if(_hexahedra) _hexahedra->addInView(tol, step, _inData, _outData, plug); @@ -1621,15 +1616,15 @@ bool VTKData::isLittleEndian() return false; // Big Endian } -void VTKData::SwapArrayByteOrder( void* array, int nbytes, int nItems ) +void VTKData::SwapArrayByteOrder(void *array, int nbytes, int nItems) { // This swaps the byte order for the array of nItems each of size nbytes - int i,j; - unsigned char* ucDst = (unsigned char*)array; + int i, j; + unsigned char *ucDst = (unsigned char *)array; - for(i=0; i < nItems; i++) { - for(j=0; j < (nbytes/2); j++) - std::swap( ucDst[j] , ucDst[(nbytes - 1) - j] ); + for(i = 0; i < nItems; i++) { + for(j = 0; j < (nbytes / 2); j++) + std::swap(ucDst[j], ucDst[(nbytes - 1) - j]); ucDst += nbytes; } } @@ -1642,23 +1637,25 @@ void VTKData::writeVTKElmData() // Format choice if(vtkFormat == "vtu") { - - if(vtkCountTotElmLev0 <= numPartMinElm*minElmPerPart) { - if( (vtkCountTotElmLev0-1)%minElmPerPart == 0) { //new filename - vtkCountFile = (vtkCountTotElmLev0-1)/minElmPerPart; + if(vtkCountTotElmLev0 <= numPartMinElm * minElmPerPart) { + if((vtkCountTotElmLev0 - 1) % minElmPerPart == 0) { // new filename + vtkCountFile = (vtkCountTotElmLev0 - 1) / minElmPerPart; initVTKFile(); } } else { - if( (vtkCountTotElmLev0-1-numPartMinElm*minElmPerPart) % maxElmPerPart == 0) { - //new filename + if((vtkCountTotElmLev0 - 1 - numPartMinElm * minElmPerPart) % + maxElmPerPart == + 0) { + // new filename vtkCountFile = numPartMinElm + (vtkCountTotElmLev0 - 1 - - numPartMinElm*minElmPerPart) / maxElmPerPart; + numPartMinElm * minElmPerPart) / + maxElmPerPart; initVTKFile(); } } - if (vtkIsBinary == true) { // Use appended format for raw binary + if(vtkIsBinary == true) { // Use appended format for raw binary // Write raw binary data to separate files first. Text headers will be // added later, as wall as raw data size (needs to know the size before) @@ -1670,32 +1667,33 @@ void VTKData::writeVTKElmData() // Node value counter = 0; - darray= new double[vtkNumComp*vtkLocalValues.size()]; + darray = new double[vtkNumComp * vtkLocalValues.size()]; for(std::vector<PValues>::iterator it = vtkLocalValues.begin(); it != vtkLocalValues.end(); ++it) { - for(int i=0;i<vtkNumComp;i++) { - darray[counter+i] = it->v[i]; + for(int i = 0; i < vtkNumComp; i++) { + darray[counter + i] = it->v[i]; } - counter+=vtkNumComp; - vtkCountTotVal+=vtkNumComp; + counter += vtkNumComp; + vtkCountTotVal += vtkNumComp; } - assert(counter==vtkNumComp* (int) vtkLocalValues.size()); - fwrite(darray,sizeof(double),vtkNumComp*vtkLocalValues.size(),vtkFileNodVal); + assert(counter == vtkNumComp * (int)vtkLocalValues.size()); + fwrite(darray, sizeof(double), vtkNumComp * vtkLocalValues.size(), + vtkFileNodVal); delete[] darray; // Points - int sizeArray = (int) vtkLocalCoords.size(); - darray = new double[3*sizeArray]; + int sizeArray = (int)vtkLocalCoords.size(); + darray = new double[3 * sizeArray]; counter = 0; for(std::vector<PCoords>::iterator it = vtkLocalCoords.begin(); it != vtkLocalCoords.end(); ++it) { - for(int i=0;i<3;i++) { - darray[counter+i] = (*it).c[i]; + for(int i = 0; i < 3; i++) { + darray[counter + i] = (*it).c[i]; } - counter+=3; - vtkCountCoord+=3; + counter += 3; + vtkCountCoord += 3; } - fwrite(darray, sizeof(double),3*sizeArray,vtkFileCoord); + fwrite(darray, sizeof(double), 3 * sizeArray, vtkFileCoord); delete[] darray; // Cells @@ -1708,7 +1706,7 @@ void VTKData::writeVTKElmData() it != vtkLocalConnectivity.end(); ++it) { // Contrary to vtk format, no +1 required for the number of nodes in the // element - cellSizeData += (int) it->size(); + cellSizeData += (int)it->size(); } // Connectivity (and build offset at the same time) @@ -1726,11 +1724,12 @@ void VTKData::writeVTKElmData() cellOffset[cellcounter] = vtkCountTotNodConnect; // build the offset cellcounter++; } - fwrite(i64array,sizeof(uint64_t),cellSizeData,vtkFileConnect); + fwrite(i64array, sizeof(uint64_t), cellSizeData, vtkFileConnect); delete[] i64array; // Cell offset - fwrite(cellOffset,sizeof(uint64_t),vtkLocalConnectivity.size(),vtkFileCellOffset); + fwrite(cellOffset, sizeof(uint64_t), vtkLocalConnectivity.size(), + vtkFileCellOffset); delete[] cellOffset; // Cell type @@ -1741,28 +1740,28 @@ void VTKData::writeVTKElmData() i8array[counter] = *it; counter++; } - fwrite(i8array,sizeof(uint8_t),vtkLocalConnectivity.size(),vtkFileCellType); + fwrite(i8array, sizeof(uint8_t), vtkLocalConnectivity.size(), + vtkFileCellType); delete[] i8array; - } else { // ascii // Node values for(std::vector<PValues>::iterator it = vtkLocalValues.begin(); it != vtkLocalValues.end(); ++it) { - - for(int i=0;i<vtkNumComp;i++) { - fprintf(vtkFileNodVal,"%23.16e ",(*it).v[i]); + for(int i = 0; i < vtkNumComp; i++) { + fprintf(vtkFileNodVal, "%23.16e ", (*it).v[i]); vtkCountTotVal++; - if(vtkCountTotVal%6 == 0) fprintf(vtkFileNodVal,"\n"); + if(vtkCountTotVal % 6 == 0) fprintf(vtkFileNodVal, "\n"); } } for(std::vector<PCoords>::iterator it = vtkLocalCoords.begin(); it != vtkLocalCoords.end(); it++) { - fprintf(vtkFileCoord,"%23.16e %23.16e %23.16e ",(*it).c[0],(*it).c[1],(*it).c[2]); - vtkCountCoord+=3; - if(vtkCountCoord%6 == 0) fprintf(vtkFileCoord,"\n"); + fprintf(vtkFileCoord, "%23.16e %23.16e %23.16e ", (*it).c[0], + (*it).c[1], (*it).c[2]); + vtkCountCoord += 3; + if(vtkCountCoord % 6 == 0) fprintf(vtkFileCoord, "\n"); } // Cells @@ -1772,40 +1771,41 @@ void VTKData::writeVTKElmData() for(std::vector<vectInt>::iterator it = vtkLocalConnectivity.begin(); it != vtkLocalConnectivity.end(); ++it) { for(vectInt::iterator jt = it->begin(); jt != it->end(); ++jt) { - fprintf(vtkFileConnect,"%d ",*jt); + fprintf(vtkFileConnect, "%d ", *jt); vtkCountTotNodConnect++; - if(vtkCountTotNodConnect%6 == 0) fprintf(vtkFileConnect,"\n"); + if(vtkCountTotNodConnect % 6 == 0) fprintf(vtkFileConnect, "\n"); } cellOffset[cellcounter] = vtkCountTotNodConnect; // build the offset cellcounter++; } // Cell offset - for(uint64_t i = 0 ; i<vtkLocalConnectivity.size(); i++) { - fprintf(vtkFileCellOffset,"%d ",cellOffset[i]); + for(uint64_t i = 0; i < vtkLocalConnectivity.size(); i++) { + fprintf(vtkFileCellOffset, "%d ", cellOffset[i]); vtkCountCellOffset++; - if(vtkCountCellOffset%6 == 0) fprintf(vtkFileCellOffset,"\n"); + if(vtkCountCellOffset % 6 == 0) fprintf(vtkFileCellOffset, "\n"); } delete[] cellOffset; // Cell type for(std::vector<int>::iterator it = vtkLocalCellType.begin(); it != vtkLocalCellType.end(); it++) { - fprintf(vtkFileCellType,"%d ",*it); + fprintf(vtkFileCellType, "%d ", *it); vtkCountCellType++; - if(vtkCountCellType%6 == 0) fprintf(vtkFileCellType,"\n"); + if(vtkCountCellType % 6 == 0) fprintf(vtkFileCellType, "\n"); } - } //if ascii + } // if ascii - //finalize and close current vtu file - if(vtkCountTotElmLev0 <= numPartMinElm*minElmPerPart) { - if( vtkCountTotElmLev0%minElmPerPart == 0) { + // finalize and close current vtu file + if(vtkCountTotElmLev0 <= numPartMinElm * minElmPerPart) { + if(vtkCountTotElmLev0 % minElmPerPart == 0) { finalizeVTKFile(); } } else { - if( (vtkCountTotElmLev0-numPartMinElm*minElmPerPart)%maxElmPerPart == 0) { + if((vtkCountTotElmLev0 - numPartMinElm * minElmPerPart) % maxElmPerPart == + 0) { finalizeVTKFile(); } } @@ -1813,27 +1813,24 @@ void VTKData::writeVTKElmData() } // vtu format else Msg::Error("Unknown format"); - } void VTKData::initVTKFile() { // Temporary files - vtkFileCoord = fopen("vtkCoords.vtu","wb"); - vtkFileConnect = fopen("vtkConnectivity.vtu","wb"); - vtkFileCellOffset = fopen("vtkCellOffset.vtu","wb"); - vtkFileCellType = fopen("vtkCellType.vtu","wb"); - vtkFileNodVal = fopen("vtkNodeValue.vtu","wb"); + vtkFileCoord = fopen("vtkCoords.vtu", "wb"); + vtkFileConnect = fopen("vtkConnectivity.vtu", "wb"); + vtkFileCellOffset = fopen("vtkCellOffset.vtu", "wb"); + vtkFileCellType = fopen("vtkCellType.vtu", "wb"); + vtkFileNodVal = fopen("vtkNodeValue.vtu", "wb"); if(vtkCountFile == 0) { // write the pvtu file and create the corresponding directory for vtu files - if (vtkUseDefaultName == 1) { - vtkDirName = vtkFieldName - + "_step" + ToString<int>(vtkStep) - + "_level" + ToString<int>(vtkLevel) - + "_tol" + ToString<double>(vtkTol) - + "_npart" + ToString<int>(vtkNpart); + if(vtkUseDefaultName == 1) { + vtkDirName = vtkFieldName + "_step" + ToString<int>(vtkStep) + "_level" + + ToString<int>(vtkLevel) + "_tol" + ToString<double>(vtkTol) + + "_npart" + ToString<int>(vtkNpart); } else { // Remove existing extension here to avoid duplicate @@ -1845,38 +1842,49 @@ void VTKData::initVTKFile() CreateSingleDir(vtkDirName); - vtkFileName = vtkDirName + ".p" + vtkFormat; // add pvtu extension to file name - vtkFile = fopen(vtkFileName.c_str(),"w"); + vtkFileName = + vtkDirName + ".p" + vtkFormat; // add pvtu extension to file name + vtkFile = fopen(vtkFileName.c_str(), "w"); bool littleEndian = isLittleEndian(); // Determine endianess - if (littleEndian == true) - fprintf(vtkFile,"<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" byte_order=\"LittleEndian\">\n"); + if(littleEndian == true) + fprintf(vtkFile, "<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" " + "byte_order=\"LittleEndian\">\n"); else - fprintf(vtkFile,"<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" byte_order=\"BigEndian\">\n"); - - fprintf(vtkFile,"<PUnstructuredGrid GhostLevel=\"0\">\n"); - fprintf(vtkFile,"<PPoints>\n"); - fprintf(vtkFile,"<DataArray type=\"Float64\" Name=\"Points\" NumberOfComponents=\"3\"/>\n"); - fprintf(vtkFile,"</PPoints>\n"); - - fprintf(vtkFile,"<PCells>\n"); - fprintf(vtkFile,"<PDataArray type=\"Int64\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n"); - fprintf(vtkFile,"<PDataArray type=\"Int64\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n"); - fprintf(vtkFile,"<PDataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\"/>\n"); - fprintf(vtkFile,"</PCells>\n"); - - fprintf(vtkFile,"<PPointData>\n"); - fprintf(vtkFile,"<PDataArray type=\"Float64\" Name=\"%s\" NumberOfComponents=\"%d\"/>\n", - vtkFieldName.c_str(), vtkNumComp); - fprintf(vtkFile,"</PPointData>\n"); - - fprintf(vtkFile,"<PCellData>\n"); - fprintf(vtkFile,"</PCellData>\n"); + fprintf(vtkFile, "<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" " + "byte_order=\"BigEndian\">\n"); + + fprintf(vtkFile, "<PUnstructuredGrid GhostLevel=\"0\">\n"); + fprintf(vtkFile, "<PPoints>\n"); + fprintf(vtkFile, "<DataArray type=\"Float64\" Name=\"Points\" " + "NumberOfComponents=\"3\"/>\n"); + fprintf(vtkFile, "</PPoints>\n"); + + fprintf(vtkFile, "<PCells>\n"); + fprintf(vtkFile, "<PDataArray type=\"Int64\" Name=\"connectivity\" " + "NumberOfComponents=\"1\"/>\n"); + fprintf(vtkFile, "<PDataArray type=\"Int64\" Name=\"offsets\" " + "NumberOfComponents=\"1\"/>\n"); + fprintf( + vtkFile, + "<PDataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\"/>\n"); + fprintf(vtkFile, "</PCells>\n"); + + fprintf(vtkFile, "<PPointData>\n"); + fprintf( + vtkFile, + "<PDataArray type=\"Float64\" Name=\"%s\" NumberOfComponents=\"%d\"/>\n", + vtkFieldName.c_str(), vtkNumComp); + fprintf(vtkFile, "</PPointData>\n"); + + fprintf(vtkFile, "<PCellData>\n"); + fprintf(vtkFile, "</PCellData>\n"); for(int i = 0; i < vtkNpart; i++) - fprintf(vtkFile,"<Piece Source=\"%s/data%d.vtu\"/>\n", vtkDirName.c_str(),i); - fprintf(vtkFile,"</PUnstructuredGrid>\n"); - fprintf(vtkFile,"</VTKFile>\n"); + fprintf(vtkFile, "<Piece Source=\"%s/data%d.vtu\"/>\n", + vtkDirName.c_str(), i); + fprintf(vtkFile, "</PUnstructuredGrid>\n"); + fprintf(vtkFile, "</VTKFile>\n"); fclose(vtkFile); } } @@ -1901,17 +1909,20 @@ void VTKData::finalizeVTKFile() std::string filename; filename = vtkDirName + "/data" + ToString(vtkCountFile) + "." + vtkFormat; - Msg::StatusBar(true, "Writing VTK data in %s: fieldname = %s - numElm = %d - numNod = %d nodes\n", - filename.c_str(), vtkFieldName.c_str(), vtkCountTotElm, vtkCountTotNod); + Msg::StatusBar(true, + "Writing VTK data in %s: fieldname = %s - numElm = %d - " + "numNod = %d nodes\n", + filename.c_str(), vtkFieldName.c_str(), vtkCountTotElm, + vtkCountTotNod); - assert(vtkCountTotNod == vtkCountCoord/3); + assert(vtkCountTotNod == vtkCountCoord / 3); // Now concatenate headers with data files - if(vtkFormat == "vtu") { // Format choice + if(vtkFormat == "vtu") { // Format choice - if (vtkIsBinary == true) { // Binary or ascii + if(vtkIsBinary == true) { // Binary or ascii - vtkFile = fopen(filename.c_str(),"wb"); + vtkFile = fopen(filename.c_str(), "wb"); if(vtkFile == NULL) { printf("Could not open file %s\n", filename.c_str()); return; @@ -1921,221 +1932,272 @@ void VTKData::finalizeVTKFile() // Headers first - if (littleEndian == true) - fprintf(vtkFile,"<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" byte_order=\"LittleEndian\" header_type=\"UInt64\">\n"); + if(littleEndian == true) + fprintf(vtkFile, "<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" " + "byte_order=\"LittleEndian\" " + "header_type=\"UInt64\">\n"); else - fprintf(vtkFile,"<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" byte_order=\"BigEndian\" header_type=\"UInt64\">\n"); - fprintf(vtkFile,"<UnstructuredGrid>\n"); - fprintf(vtkFile,"<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n", - vtkCountTotNod,vtkCountTotElm); - + fprintf(vtkFile, "<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" " + "byte_order=\"BigEndian\" header_type=\"UInt64\">\n"); + fprintf(vtkFile, "<UnstructuredGrid>\n"); + fprintf(vtkFile, "<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n", + vtkCountTotNod, vtkCountTotElm); // Node value - fprintf(vtkFile,"<PointData>\n"); - fprintf(vtkFile,"<DataArray type=\"Float64\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"appended\" offset=\"%" PRIu64 "\"/>\n", vtkFieldName.c_str(), vtkNumComp,byteoffset); - fprintf(vtkFile,"</PointData>\n"); - byteoffset = byteoffset + (vtkCountTotNod*vtkNumComp+1)*sizeof(double); // +1 for datasize in bytes + fprintf(vtkFile, "<PointData>\n"); + fprintf(vtkFile, + "<DataArray type=\"Float64\" Name=\"%s\" " + "NumberOfComponents=\"%d\" format=\"appended\" offset=\"%" PRIu64 + "\"/>\n", + vtkFieldName.c_str(), vtkNumComp, byteoffset); + fprintf(vtkFile, "</PointData>\n"); + byteoffset = byteoffset + (vtkCountTotNod * vtkNumComp + 1) * + sizeof(double); // +1 for datasize in bytes // Cell values (none here but may change) - fprintf(vtkFile,"<CellData>\n"); - fprintf(vtkFile,"</CellData>\n"); // no offset here because empty cell data + fprintf(vtkFile, "<CellData>\n"); + fprintf(vtkFile, + "</CellData>\n"); // no offset here because empty cell data // Nodes - fprintf(vtkFile,"<Points>\n"); - fprintf(vtkFile,"<DataArray type=\"Float64\" Name=\"Points\" NumberOfComponents=\"3\" format=\"appended\" offset=\"%" PRIu64 "\"/>\n",byteoffset); - fprintf(vtkFile,"</Points>\n"); - byteoffset = byteoffset + (vtkCountCoord+1)*sizeof(double); // +1 for datasize in bytes + fprintf(vtkFile, "<Points>\n"); + fprintf(vtkFile, + "<DataArray type=\"Float64\" Name=\"Points\" " + "NumberOfComponents=\"3\" format=\"appended\" offset=\"%" PRIu64 + "\"/>\n", + byteoffset); + fprintf(vtkFile, "</Points>\n"); + byteoffset = byteoffset + (vtkCountCoord + 1) * + sizeof(double); // +1 for datasize in bytes // Cells - fprintf(vtkFile,"<Cells>\n"); - fprintf(vtkFile,"<DataArray type=\"Int64\" Name=\"connectivity\" format=\"appended\" offset=\"%" PRIu64 "\"/>\n",byteoffset); - byteoffset = byteoffset + (vtkCountTotNodConnect+1)*sizeof(uint64_t); - fprintf(vtkFile,"<DataArray type=\"Int64\" Name=\"offsets\" format=\"appended\" offset=\"%" PRIu64 "\"/>\n",byteoffset); - byteoffset = byteoffset + (vtkCountTotElm+1)*sizeof(uint64_t); - fprintf(vtkFile,"<DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"%" PRIu64 "\"/>\n",byteoffset); - byteoffset = byteoffset + (vtkCountTotElm+1)*sizeof(uint8_t); - fprintf(vtkFile,"</Cells>\n"); - - fprintf(vtkFile,"</Piece>\n"); - fprintf(vtkFile,"</UnstructuredGrid>\n"); - - fprintf(vtkFile,"<AppendedData encoding=\"raw\">\n"); - fprintf(vtkFile,"_"); + fprintf(vtkFile, "<Cells>\n"); + fprintf(vtkFile, + "<DataArray type=\"Int64\" Name=\"connectivity\" " + "format=\"appended\" offset=\"%" PRIu64 "\"/>\n", + byteoffset); + byteoffset = byteoffset + (vtkCountTotNodConnect + 1) * sizeof(uint64_t); + fprintf(vtkFile, + "<DataArray type=\"Int64\" Name=\"offsets\" format=\"appended\" " + "offset=\"%" PRIu64 "\"/>\n", + byteoffset); + byteoffset = byteoffset + (vtkCountTotElm + 1) * sizeof(uint64_t); + fprintf(vtkFile, + "<DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" " + "offset=\"%" PRIu64 "\"/>\n", + byteoffset); + byteoffset = byteoffset + (vtkCountTotElm + 1) * sizeof(uint8_t); + fprintf(vtkFile, "</Cells>\n"); + + fprintf(vtkFile, "</Piece>\n"); + fprintf(vtkFile, "</UnstructuredGrid>\n"); + + fprintf(vtkFile, "<AppendedData encoding=\"raw\">\n"); + fprintf(vtkFile, "_"); uint64_t datasize; // Node values - datasize = vtkNumComp*vtkCountTotNod*sizeof(double); - fwrite(&datasize,sizeof(uint64_t),1,vtkFile); + datasize = vtkNumComp * vtkCountTotNod * sizeof(double); + fwrite(&datasize, sizeof(uint64_t), 1, vtkFile); fclose(vtkFile); std::ifstream if_vtkNodeValue("vtkNodeValue.vtu", std::ios_base::binary); - std::ofstream of_vtkfile(filename.c_str(), std::ios_base::binary | std::ios_base::app); + std::ofstream of_vtkfile(filename.c_str(), + std::ios_base::binary | std::ios_base::app); of_vtkfile << if_vtkNodeValue.rdbuf(); if_vtkNodeValue.close(); of_vtkfile.close(); // Points - vtkFile = fopen(filename.c_str(),"ab"); - datasize = vtkCountTotNod*3*sizeof(double); - fwrite(&datasize,sizeof(uint64_t),1,vtkFile); + vtkFile = fopen(filename.c_str(), "ab"); + datasize = vtkCountTotNod * 3 * sizeof(double); + fwrite(&datasize, sizeof(uint64_t), 1, vtkFile); fclose(vtkFile); std::ifstream if_vtkCoords("vtkCoords.vtu", std::ios_base::binary); - of_vtkfile.open(filename.c_str(), std::ios_base::binary | std::ios_base::app); + of_vtkfile.open(filename.c_str(), + std::ios_base::binary | std::ios_base::app); of_vtkfile << if_vtkCoords.rdbuf(); if_vtkCoords.close(); of_vtkfile.close(); // Cells // Connectivity - vtkFile = fopen(filename.c_str(),"ab"); - datasize = vtkCountTotNodConnect*sizeof(uint64_t); - fwrite(&datasize,sizeof(uint64_t),1,vtkFile); + vtkFile = fopen(filename.c_str(), "ab"); + datasize = vtkCountTotNodConnect * sizeof(uint64_t); + fwrite(&datasize, sizeof(uint64_t), 1, vtkFile); fclose(vtkFile); - std::ifstream if_vtkConnectivity("vtkConnectivity.vtu", std::ios_base::binary); - of_vtkfile.open(filename.c_str(), std::ios_base::binary | std::ios_base::app); + std::ifstream if_vtkConnectivity("vtkConnectivity.vtu", + std::ios_base::binary); + of_vtkfile.open(filename.c_str(), + std::ios_base::binary | std::ios_base::app); of_vtkfile << if_vtkConnectivity.rdbuf(); if_vtkConnectivity.close(); of_vtkfile.close(); // Cell offset - vtkFile = fopen(filename.c_str(),"ab"); - datasize = vtkCountTotElm*sizeof(uint64_t); - fwrite(&datasize,sizeof(uint64_t),1,vtkFile); + vtkFile = fopen(filename.c_str(), "ab"); + datasize = vtkCountTotElm * sizeof(uint64_t); + fwrite(&datasize, sizeof(uint64_t), 1, vtkFile); fclose(vtkFile); - std::ifstream if_vtkCellOffset("vtkCellOffset.vtu", std::ios_base::binary); - of_vtkfile.open(filename.c_str(), std::ios_base::binary | std::ios_base::app); + std::ifstream if_vtkCellOffset("vtkCellOffset.vtu", + std::ios_base::binary); + of_vtkfile.open(filename.c_str(), + std::ios_base::binary | std::ios_base::app); of_vtkfile << if_vtkCellOffset.rdbuf(); if_vtkCellOffset.close(); of_vtkfile.close(); // Cell type - vtkFile = fopen(filename.c_str(),"ab"); - datasize = vtkCountTotElm*sizeof(uint8_t); - fwrite(&datasize,sizeof(uint64_t),1,vtkFile); + vtkFile = fopen(filename.c_str(), "ab"); + datasize = vtkCountTotElm * sizeof(uint8_t); + fwrite(&datasize, sizeof(uint64_t), 1, vtkFile); fclose(vtkFile); std::ifstream if_vtkCellType("vtkCellType.vtu", std::ios_base::binary); - of_vtkfile.open(filename.c_str(), std::ios_base::binary | std::ios_base::app); + of_vtkfile.open(filename.c_str(), + std::ios_base::binary | std::ios_base::app); of_vtkfile << if_vtkCellType.rdbuf(); if_vtkCellType.close(); of_vtkfile.close(); - vtkFile = fopen(filename.c_str(),"ab"); - fprintf(vtkFile,"\n"); - fprintf(vtkFile,"</AppendedData>\n"); - fprintf(vtkFile,"</VTKFile>\n"); // for both binary and ascii + vtkFile = fopen(filename.c_str(), "ab"); + fprintf(vtkFile, "\n"); + fprintf(vtkFile, "</AppendedData>\n"); + fprintf(vtkFile, "</VTKFile>\n"); // for both binary and ascii fclose(vtkFile); - } else { // ascii - vtkFile = fopen(filename.c_str(),"w"); + vtkFile = fopen(filename.c_str(), "w"); if(vtkFile == NULL) { printf("Could not open file %s\n", filename.c_str()); return; } - if (littleEndian == true) - fprintf(vtkFile,"<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" byte_order=\"LittleEndian\" header_type=\"UInt64\">\n"); + if(littleEndian == true) + fprintf(vtkFile, "<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" " + "byte_order=\"LittleEndian\" " + "header_type=\"UInt64\">\n"); else - fprintf(vtkFile,"<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" byte_order=\"BigEndian\" header_type=\"UInt64\">\n"); - fprintf(vtkFile,"<UnstructuredGrid>\n"); - fprintf(vtkFile,"<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n",vtkCountTotNod,vtkCountTotElm); + fprintf(vtkFile, "<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" " + "byte_order=\"BigEndian\" header_type=\"UInt64\">\n"); + fprintf(vtkFile, "<UnstructuredGrid>\n"); + fprintf(vtkFile, "<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n", + vtkCountTotNod, vtkCountTotElm); // Node values - fprintf(vtkFile,"<PointData>\n"); - fprintf(vtkFile,"<DataArray type=\"Float64\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"ascii\">\n",vtkFieldName.c_str(),vtkNumComp); - fclose(vtkFile); //close file for binary concatenation + fprintf(vtkFile, "<PointData>\n"); + fprintf(vtkFile, + "<DataArray type=\"Float64\" Name=\"%s\" " + "NumberOfComponents=\"%d\" format=\"ascii\">\n", + vtkFieldName.c_str(), vtkNumComp); + fclose(vtkFile); // close file for binary concatenation std::ifstream if_vtkNodeValue("vtkNodeValue.vtu", std::ios_base::binary); - std::ofstream of_vtkfile(filename.c_str(), std::ios_base::binary | std::ios_base::app); + std::ofstream of_vtkfile(filename.c_str(), + std::ios_base::binary | std::ios_base::app); of_vtkfile << if_vtkNodeValue.rdbuf(); if_vtkNodeValue.close(); of_vtkfile.close(); - vtkFile = fopen(filename.c_str(),"a"); - fprintf(vtkFile,"</DataArray>\n"); - fprintf(vtkFile,"</PointData>\n"); + vtkFile = fopen(filename.c_str(), "a"); + fprintf(vtkFile, "</DataArray>\n"); + fprintf(vtkFile, "</PointData>\n"); - //Cell values - fprintf(vtkFile,"<CellData>\n"); - fprintf(vtkFile,"</CellData>\n"); + // Cell values + fprintf(vtkFile, "<CellData>\n"); + fprintf(vtkFile, "</CellData>\n"); - //Nodes - fprintf(vtkFile,"<Points>\n"); - fprintf(vtkFile,"<DataArray type=\"Float64\" Name=\"Points\" NumberOfComponents=\"3\" format=\"ascii\">\n"); - fclose(vtkFile); //close file for binary concatenation + // Nodes + fprintf(vtkFile, "<Points>\n"); + fprintf(vtkFile, "<DataArray type=\"Float64\" Name=\"Points\" " + "NumberOfComponents=\"3\" format=\"ascii\">\n"); + fclose(vtkFile); // close file for binary concatenation - of_vtkfile.open(filename.c_str(), std::ios_base::binary | std::ios_base::app); + of_vtkfile.open(filename.c_str(), + std::ios_base::binary | std::ios_base::app); std::ifstream if_vtkCoords("vtkCoords.vtu", std::ios_base::binary); of_vtkfile << if_vtkCoords.rdbuf(); if_vtkCoords.close(); of_vtkfile.close(); - vtkFile = fopen(filename.c_str(),"a"); - fprintf(vtkFile,"</DataArray>\n"); - fprintf(vtkFile,"</Points>\n"); + vtkFile = fopen(filename.c_str(), "a"); + fprintf(vtkFile, "</DataArray>\n"); + fprintf(vtkFile, "</Points>\n"); // Cells - fprintf(vtkFile,"<Cells>\n"); - fprintf(vtkFile,"<DataArray type=\"Int64\" Name=\"connectivity\" format=\"ascii\">\n"); - fclose(vtkFile); //close file for binary concatenation + fprintf(vtkFile, "<Cells>\n"); + fprintf( + vtkFile, + "<DataArray type=\"Int64\" Name=\"connectivity\" format=\"ascii\">\n"); + fclose(vtkFile); // close file for binary concatenation // Connectivity - of_vtkfile.open(filename.c_str(), std::ios_base::binary | std::ios_base::app); - std::ifstream if_vtkConnectivity("vtkConnectivity.vtu", std::ios_base::binary); + of_vtkfile.open(filename.c_str(), + std::ios_base::binary | std::ios_base::app); + std::ifstream if_vtkConnectivity("vtkConnectivity.vtu", + std::ios_base::binary); of_vtkfile << if_vtkConnectivity.rdbuf(); if_vtkConnectivity.close(); of_vtkfile.close(); - vtkFile = fopen(filename.c_str(),"a"); - fprintf(vtkFile,"</DataArray>\n"); + vtkFile = fopen(filename.c_str(), "a"); + fprintf(vtkFile, "</DataArray>\n"); // Cell offset - fprintf(vtkFile,"<DataArray type=\"Int64\" Name=\"offsets\" format=\"ascii\">\n"); - fclose(vtkFile); //close file for binary concatenation - - of_vtkfile.open(filename.c_str(), std::ios_base::binary | std::ios_base::app); - std::ifstream if_vtkCellOffset("vtkCellOffset.vtu", std::ios_base::binary); + fprintf(vtkFile, + "<DataArray type=\"Int64\" Name=\"offsets\" format=\"ascii\">\n"); + fclose(vtkFile); // close file for binary concatenation + + of_vtkfile.open(filename.c_str(), + std::ios_base::binary | std::ios_base::app); + std::ifstream if_vtkCellOffset("vtkCellOffset.vtu", + std::ios_base::binary); of_vtkfile << if_vtkCellOffset.rdbuf(); if_vtkCellOffset.close(); of_vtkfile.close(); - vtkFile = fopen(filename.c_str(),"a"); - fprintf(vtkFile,"</DataArray>\n"); + vtkFile = fopen(filename.c_str(), "a"); + fprintf(vtkFile, "</DataArray>\n"); // Cell type - fprintf(vtkFile,"<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"); - fclose(vtkFile); //close file for binary concatenation + fprintf(vtkFile, + "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"); + fclose(vtkFile); // close file for binary concatenation - of_vtkfile.open(filename.c_str(), std::ios_base::binary | std::ios_base::app); + of_vtkfile.open(filename.c_str(), + std::ios_base::binary | std::ios_base::app); std::ifstream if_vtkCellType("vtkCellType.vtu", std::ios_base::binary); of_vtkfile << if_vtkCellType.rdbuf(); if_vtkCellType.close(); of_vtkfile.close(); - vtkFile = fopen(filename.c_str(),"a"); - fprintf(vtkFile,"</DataArray>\n"); - fprintf(vtkFile,"</Cells>\n"); - - fprintf(vtkFile,"</Piece>\n"); - fprintf(vtkFile,"</UnstructuredGrid>\n"); + vtkFile = fopen(filename.c_str(), "a"); + fprintf(vtkFile, "</DataArray>\n"); + fprintf(vtkFile, "</Cells>\n"); + fprintf(vtkFile, "</Piece>\n"); + fprintf(vtkFile, "</UnstructuredGrid>\n"); - fprintf(vtkFile,"</VTKFile>\n"); // for both binary and ascii + fprintf(vtkFile, "</VTKFile>\n"); // for both binary and ascii fclose(vtkFile); } // if binary/ascii // Remove temporary files now - if(remove("vtkCoords.vtu") !=0 ) printf("ERROR: Could not remove vtkCoords.vtu\n"); - if(remove("vtkConnectivity.vtu") !=0 ) printf("ERROR: Could not remove vtkConnectivity.vtu\n"); - if(remove("vtkCellOffset.vtu") !=0 ) printf("ERROR: Could not remove vtkCellOffset.vtu\n"); - if(remove("vtkCellType.vtu") !=0 ) printf("ERROR: Could not remove vtkCellType.vtu\n"); - if(remove("vtkNodeValue.vtu") !=0 ) printf("ERROR: Could not remove vtkNodeValue.vtu\n"); + if(remove("vtkCoords.vtu") != 0) + printf("ERROR: Could not remove vtkCoords.vtu\n"); + if(remove("vtkConnectivity.vtu") != 0) + printf("ERROR: Could not remove vtkConnectivity.vtu\n"); + if(remove("vtkCellOffset.vtu") != 0) + printf("ERROR: Could not remove vtkCellOffset.vtu\n"); + if(remove("vtkCellType.vtu") != 0) + printf("ERROR: Could not remove vtkCellType.vtu\n"); + if(remove("vtkNodeValue.vtu") != 0) + printf("ERROR: Could not remove vtkNodeValue.vtu\n"); // Reset counters for next file vtkCountTotNod = 0; @@ -2154,147 +2216,146 @@ void VTKData::finalizeVTKFile() int VTKData::getPVCellType(int numEdges) { int cellType; // Convention for cell types in ParaView - switch(numEdges){ - case 0: - printf("WARNING: Trying to write a node to the ParaView data base and file\n"); - cellType = -1; - break; - case 1: - printf("WARNING: Trying to write a node to the ParaView data base and file\n"); - cellType = -2; - break; - case 3: - cellType = 5; // 2D VTK triangle - break; - case 4: - cellType = 9; // 2D VTK quadrangle - break; - case 6: - cellType = 10; // 3D VTK tetrahedron - break; - case 9: - cellType = 13; // 3D VTK prism/wedge - break; - case 8: - cellType = 14; // 3D VTK pyramid - break; - case 12: - cellType = 12; // 3D VTK hexahedron - break; - default: - printf("ERROR: No cell type was detected\n"); - cellType = -1; - break; + switch(numEdges) { + case 0: + printf( + "WARNING: Trying to write a node to the ParaView data base and file\n"); + cellType = -1; + break; + case 1: + printf( + "WARNING: Trying to write a node to the ParaView data base and file\n"); + cellType = -2; + break; + case 3: + cellType = 5; // 2D VTK triangle + break; + case 4: + cellType = 9; // 2D VTK quadrangle + break; + case 6: + cellType = 10; // 3D VTK tetrahedron + break; + case 9: + cellType = 13; // 3D VTK prism/wedge + break; + case 8: + cellType = 14; // 3D VTK pyramid + break; + case 12: + cellType = 12; // 3D VTK hexahedron + break; + default: + printf("ERROR: No cell type was detected\n"); + cellType = -1; + break; } - return cellType; + return cellType; } template <class T> -void adaptiveElements<T>::adaptForVTK(double tol, - int numComp, +void adaptiveElements<T>::adaptForVTK(double tol, int numComp, std::vector<PCoords> &coords, std::vector<PValues> &values, double &minVal, double &maxVal) { int numVertices = T::allVertices.size(); - if(!numVertices){ + if(!numVertices) { Msg::Error("No adapted vertices to interpolate"); return; } int numVals = _coeffsVal ? _coeffsVal->size1() : T::numNodes; - if(numVals != (int)values.size()){ - Msg::Error("Wrong number of values in adaptation %d != %i", - numVals, values.size()); + if(numVals != (int)values.size()) { + Msg::Error("Wrong number of values in adaptation %d != %i", numVals, + values.size()); return; } - #ifdef TIMER +#ifdef TIMER double t1 = GetTimeInSeconds(); - #endif +#endif fullVector<double> val(numVals), res(numVertices); - switch (numComp) { - case 1: - { - for(int i = 0; i < numVals; i++) val(i) = values[i].v[0]; - break; - } - case 3: - case 9: - { - for(int i = 0; i < numVals; i++) { - val(i) = 0; - for (int k=0; k < numComp; k++) val(i) += values[i].v[k] * values[i].v[k]; - } - break; - } - default: - { - Msg::Error("Can only adapt scalar, vector or tensor data"); - return; + switch(numComp) { + case 1: { + for(int i = 0; i < numVals; i++) val(i) = values[i].v[0]; + break; + } + case 3: + case 9: { + for(int i = 0; i < numVals; i++) { + val(i) = 0; + for(int k = 0; k < numComp; k++) + val(i) += values[i].v[k] * values[i].v[k]; } + break; + } + default: { + Msg::Error("Can only adapt scalar, vector or tensor data"); + return; + } } _interpolVal->mult(val, res); - for(int i = 0; i < numVertices; i++){ + for(int i = 0; i < numVertices; i++) { minVal = std::min(minVal, res(i)); maxVal = std::max(maxVal, res(i)); } fullMatrix<double> *resxyz = 0; - if(numComp == 3 || numComp == 9){ + if(numComp == 3 || numComp == 9) { fullMatrix<double> valxyz(numVals, numComp); resxyz = new fullMatrix<double>(numVertices, numComp); - for(int i = 0; i < numVals; i++){ - for (int k = 0; k < numComp; k++) { - valxyz(i,k) = values[i].v[k]; + for(int i = 0; i < numVals; i++) { + for(int k = 0; k < numComp; k++) { + valxyz(i, k) = values[i].v[k]; } } _interpolVal->mult(valxyz, *resxyz); } int numNodes = _coeffsGeom ? _coeffsGeom->size1() : T::numNodes; - if(numNodes != (int)coords.size()){ - Msg::Error("Wrong number of nodes in adaptation %d != %i", - numNodes, coords.size()); + if(numNodes != (int)coords.size()) { + Msg::Error("Wrong number of nodes in adaptation %d != %i", numNodes, + coords.size()); if(resxyz) delete resxyz; return; } fullMatrix<double> xyz(numNodes, 3), XYZ(numVertices, 3); - for(int i = 0; i < numNodes; i++){ + for(int i = 0; i < numNodes; i++) { xyz(i, 0) = coords[i].c[0]; xyz(i, 1) = coords[i].c[1]; xyz(i, 2) = coords[i].c[2]; } _interpolGeom->mult(xyz, XYZ); - #ifdef TIMER +#ifdef TIMER adaptiveData::timerAdapt += GetTimeInSeconds() - t1; return; - #endif +#endif int i = 0; for(std::set<adaptiveVertex>::iterator it = T::allVertices.begin(); it != T::allVertices.end(); ++it) { // ok because we know this will not change the set ordering - adaptiveVertex *p = (adaptiveVertex*)&(*it); + adaptiveVertex *p = (adaptiveVertex *)&(*it); p->val = res(i); - if(resxyz){ - p->val = (*resxyz)(i, 0); + if(resxyz) { + p->val = (*resxyz)(i, 0); p->valy = (*resxyz)(i, 1); p->valz = (*resxyz)(i, 2); - if (numComp == 9) { - p->valyx = (*resxyz)(i,3); - p->valyy = (*resxyz)(i,4); - p->valyz = (*resxyz)(i,5); - p->valzx = (*resxyz)(i,6); - p->valzy = (*resxyz)(i,7); - p->valzz = (*resxyz)(i,8); + if(numComp == 9) { + p->valyx = (*resxyz)(i, 3); + p->valyy = (*resxyz)(i, 4); + p->valyz = (*resxyz)(i, 5); + p->valzx = (*resxyz)(i, 6); + p->valzy = (*resxyz)(i, 7); + p->valzz = (*resxyz)(i, 8); } } p->X = XYZ(i, 0); @@ -2305,10 +2366,11 @@ void adaptiveElements<T>::adaptForVTK(double tol, if(resxyz) delete resxyz; - for(typename std::list<T*>::iterator it = T::all.begin();it != T::all.end(); it++) + for(typename std::list<T *>::iterator it = T::all.begin(); it != T::all.end(); + it++) (*it)->visible = false; - if(tol != 0.){ + if(tol != 0.) { double avg = fabs(maxVal - minVal); if(tol < 0) avg = 1.; // force visibility to the smallest subdivision T::error(avg, tol); @@ -2316,71 +2378,71 @@ void adaptiveElements<T>::adaptForVTK(double tol, coords.clear(); values.clear(); - for(typename std::list<T*>::iterator it = T::all.begin();it != T::all.end(); it++){ - if((*it)->visible){ + for(typename std::list<T *>::iterator it = T::all.begin(); it != T::all.end(); + it++) { + if((*it)->visible) { adaptiveVertex **p = (*it)->p; for(int i = 0; i < T::numNodes; i++) { coords.push_back(PCoords(p[i]->X, p[i]->Y, p[i]->Z)); - switch (numComp) { - case 1: - values.push_back(PValues(p[i]->val)); - break; - case 3: - values.push_back(PValues(p[i]->val, p[i]->valy, p[i]->valz)); - break; - case 9: - values.push_back(PValues(p[i]->val, - p[i]->valy, p[i]->valz, - p[i]->valyx,p[i]->valyy,p[i]->valyz, - p[i]->valzx,p[i]->valzy,p[i]->valzz)); - break; + switch(numComp) { + case 1: values.push_back(PValues(p[i]->val)); break; + case 3: + values.push_back(PValues(p[i]->val, p[i]->valy, p[i]->valz)); + break; + case 9: + values.push_back(PValues(p[i]->val, p[i]->valy, p[i]->valz, + p[i]->valyx, p[i]->valyy, p[i]->valyz, + p[i]->valzx, p[i]->valzy, p[i]->valzz)); + break; } } } } } - template <class T> -void adaptiveElements<T>::buildMapping(nodMap<T> &myNodMap, double tol, int &numNodInsert) +void adaptiveElements<T>::buildMapping(nodMap<T> &myNodMap, double tol, + int &numNodInsert) { - - if (tol > 0.0 || myNodMap.getSize() == 0) { + if(tol > 0.0 || myNodMap.getSize() == 0) { // Either this is not a uniform refinement and we need to rebuild the whole // mapping for each canonical element, or this is the first time we try to // build the mapping - myNodMap.cleanMapping(); // Required if tol > 0 (local error based adaptation) + myNodMap + .cleanMapping(); // Required if tol > 0 (local error based adaptation) - for(typename std::list<T*>::iterator itleaf = T::all.begin(); + for(typename std::list<T *>::iterator itleaf = T::all.begin(); itleaf != T::all.end(); itleaf++) { // Visit all the leaves of the refined canonical element - if ((*itleaf)->visible == true) { + if((*itleaf)->visible == true) { // Find the leaves that are flagged for visibility - for(int i=0;i<T::numNodes;i++) { - // Visit each nodes of the leaf (3 for triangles, 4 for quadrangle, etc) + for(int i = 0; i < T::numNodes; i++) { + // Visit each nodes of the leaf (3 for triangles, 4 for quadrangle, + // etc) adaptiveVertex pquery; pquery.x = (*itleaf)->p[i]->x; pquery.y = (*itleaf)->p[i]->y; pquery.z = (*itleaf)->p[i]->z; std::set<adaptiveVertex>::iterator it = T::allVertices.find(pquery); - if(it == T::allVertices.end()){ - Msg::Error("Could not find adaptive Vertex in adaptiveElements<T>::buildMapping %f %f %f", - pquery.x,pquery.y,pquery.z); + if(it == T::allVertices.end()) { + Msg::Error("Could not find adaptive Vertex in " + "adaptiveElements<T>::buildMapping %f %f %f", + pquery.x, pquery.y, pquery.z); } - else{ + else { // Compute the distance in the list to get the mapping for // the canonical element (note std:distance returns long int - int dist = (int) std::distance(T::allVertices.begin(),it); + int dist = (int)std::distance(T::allVertices.begin(), it); myNodMap.mapping.push_back(dist); } // quit properly if vertex not found - Should not happen though assert(it != T::allVertices.end()); - } //for - } //if - }//for + } // for + } // if + } // for if(myNodMap.mapping.size() == 0) { Msg::Error("Node mapping in buildMapping has zero size"); @@ -2390,17 +2452,20 @@ void adaptiveElements<T>::buildMapping(nodMap<T> &myNodMap, double tol, int &num // Use an ordered set for efficiency // This set is also used in case of partiel refinement std::set<int> uniqueNod; - for(std::vector<int>::iterator it = myNodMap.mapping.begin(); it != myNodMap.mapping.end(); it++) { + for(std::vector<int>::iterator it = myNodMap.mapping.begin(); + it != myNodMap.mapping.end(); it++) { uniqueNod.insert(*it); } - numNodInsert = (int) uniqueNod.size(); + numNodInsert = (int)uniqueNod.size(); - // Renumber the elm in the mapping in case of partial refinement (when vis tolerance > 0) - // so that we have a continuous numbering starting from 0 with no missing node id in the connectivity - // This require a new local and temporary mapping, based on uniqueNod already generated above + // Renumber the elm in the mapping in case of partial refinement (when vis + // tolerance > 0) so that we have a continuous numbering starting from 0 + // with no missing node id in the connectivity This require a new local and + // temporary mapping, based on uniqueNod already generated above if(tol > 0.0) { std::set<int>::iterator jt; - for(std::vector<int>::iterator it = myNodMap.mapping.begin();it != myNodMap.mapping.end();++it) { + for(std::vector<int>::iterator it = myNodMap.mapping.begin(); + it != myNodMap.mapping.end(); ++it) { jt = uniqueNod.find(*it); *it = std::distance(uniqueNod.begin(), jt); } @@ -2409,61 +2474,44 @@ void adaptiveElements<T>::buildMapping(nodMap<T> &myNodMap, double tol, int &num } template <class T> -void adaptiveElements<T>::addInViewForVTK(int step, - PViewData *in, - VTKData &myVTKData, - bool writeVTK, +void adaptiveElements<T>::addInViewForVTK(int step, PViewData *in, + VTKData &myVTKData, bool writeVTK, bool buildStaticData) { int numComp = in->getNumComponents(0, 0, 0); if(numComp != 1 && numComp != 3 && numComp != 9) return; int numEle = 0; - switch(T::numEdges){ - case 0: - numEle = in->getNumPoints(); - break; - case 1: - numEle = in->getNumLines(); - break; - case 3: - numEle = in->getNumTriangles(); - break; - case 4: - numEle = in->getNumQuadrangles(); - break; - case 6: - numEle = in->getNumTetrahedra(); - break; - case 9: - numEle = in->getNumPrisms(); - break; - case 8: - numEle = in->getNumPyramids(); - break; - case 12: - numEle = in->getNumHexahedra(); - break; + switch(T::numEdges) { + case 0: numEle = in->getNumPoints(); break; + case 1: numEle = in->getNumLines(); break; + case 3: numEle = in->getNumTriangles(); break; + case 4: numEle = in->getNumQuadrangles(); break; + case 6: numEle = in->getNumTetrahedra(); break; + case 9: numEle = in->getNumPrisms(); break; + case 8: numEle = in->getNumPyramids(); break; + case 12: numEle = in->getNumHexahedra(); break; } if(!numEle) return; // New variables for high order visualiztion through vtk files int numNodInsert; nodMap<T> myNodMap; - + double minVal; double maxVal; - PViewDataGModel* tmpPViewDataGModel = dynamic_cast<PViewDataGModel*>(in); + PViewDataGModel *tmpPViewDataGModel = dynamic_cast<PViewDataGModel *>(in); minVal = tmpPViewDataGModel->getMin(step); maxVal = tmpPViewDataGModel->getMax(step); - - for(int ent = 0; ent < in->getNumEntities(step); ent++){ - for(int ele = 0; ele < in->getNumElements(step, ent); ele++){ + + for(int ent = 0; ent < in->getNumEntities(step); ent++) { + for(int ele = 0; ele < in->getNumElements(step, ent); ele++) { if(in->skipElement(step, ent, ele) || - in->getNumEdges(step, ent, ele) != T::numEdges) continue; + in->getNumEdges(step, ent, ele) != T::numEdges) + continue; int numNodes = in->getNumNodes(step, ent, ele); std::vector<PCoords> coords; - for(int i = 0; i < numNodes; i++){ + for(int i = 0; i < numNodes; i++) { double x, y, z; in->getNode(step, ent, ele, i, x, y, z); coords.push_back(PCoords(x, y, z)); @@ -2471,43 +2519,43 @@ void adaptiveElements<T>::addInViewForVTK(int step, int numVal = in->getNumValues(step, ent, ele); std::vector<PValues> values; - switch (numComp) { - case 1: - for(int i = 0; i < numVal; i++){ - double val; - in->getValue(step, ent, ele, i, val); - values.push_back(PValues(val)); - } - break; - case 3: - for(int i = 0; i < numVal / 3; i++){ - double vx, vy, vz; - in->getValue(step, ent, ele, 3 * i, vx); - in->getValue(step, ent, ele, 3 * i + 1, vy); - in->getValue(step, ent, ele, 3 * i + 2, vz); - values.push_back(PValues(vx, vy, vz)); - } - break; - case 9: - for(int i = 0; i < numVal / 9; i++){ - double vxx, vxy, vxz,vyx, vyy, vyz,vzx, vzy, vzz ; - in->getValue(step, ent, ele, 9 * i + 0, vxx); - in->getValue(step, ent, ele, 9 * i + 1, vxy); - in->getValue(step, ent, ele, 9 * i + 2, vxz); - in->getValue(step, ent, ele, 9 * i + 3, vyx); - in->getValue(step, ent, ele, 9 * i + 4, vyy); - in->getValue(step, ent, ele, 9 * i + 5, vyz); - in->getValue(step, ent, ele, 9 * i + 6, vzx); - in->getValue(step, ent, ele, 9 * i + 7, vzy); - in->getValue(step, ent, ele, 9 * i + 8, vzz); - values.push_back(PValues(vxx,vxy,vxz, - vyx,vyy,vyz, - vzx,vzy,vzz)); - } - break; + switch(numComp) { + case 1: + for(int i = 0; i < numVal; i++) { + double val; + in->getValue(step, ent, ele, i, val); + values.push_back(PValues(val)); + } + break; + case 3: + for(int i = 0; i < numVal / 3; i++) { + double vx, vy, vz; + in->getValue(step, ent, ele, 3 * i, vx); + in->getValue(step, ent, ele, 3 * i + 1, vy); + in->getValue(step, ent, ele, 3 * i + 2, vz); + values.push_back(PValues(vx, vy, vz)); + } + break; + case 9: + for(int i = 0; i < numVal / 9; i++) { + double vxx, vxy, vxz, vyx, vyy, vyz, vzx, vzy, vzz; + in->getValue(step, ent, ele, 9 * i + 0, vxx); + in->getValue(step, ent, ele, 9 * i + 1, vxy); + in->getValue(step, ent, ele, 9 * i + 2, vxz); + in->getValue(step, ent, ele, 9 * i + 3, vyx); + in->getValue(step, ent, ele, 9 * i + 4, vyy); + in->getValue(step, ent, ele, 9 * i + 5, vyz); + in->getValue(step, ent, ele, 9 * i + 6, vzx); + in->getValue(step, ent, ele, 9 * i + 7, vzy); + in->getValue(step, ent, ele, 9 * i + 8, vzz); + values.push_back( + PValues(vxx, vxy, vxz, vyx, vyy, vyz, vzx, vzy, vzz)); + } + break; } - adaptForVTK(myVTKData.vtkTol, numComp, coords, values, minVal, maxVal);// ,plug); + adaptForVTK(myVTKData.vtkTol, numComp, coords, values, minVal, + maxVal); // ,plug); // Inside initial element, after adapt() has been called @@ -2518,24 +2566,24 @@ void adaptiveElements<T>::addInViewForVTK(int step, // Pre-allocate some space for the local coordinates and connectivity // in order to write to any component of the vector later through vec[i] - myVTKData.vtkLocalCoords.resize(numNodInsert,PCoords(0.0,0.0,0.0)); - myVTKData.vtkLocalValues.resize(numNodInsert,PValues(numComp)); - - for(unsigned int i = 0; i < coords.size() / T::numNodes; i++){ + myVTKData.vtkLocalCoords.resize(numNodInsert, PCoords(0.0, 0.0, 0.0)); + myVTKData.vtkLocalValues.resize(numNodInsert, PValues(numComp)); + for(unsigned int i = 0; i < coords.size() / T::numNodes; i++) { // Loop over // - all refined elements if refinement level > 0 - // - single initial element when refinement box is checked for the first + // - single initial element when refinement box is checked for the + // first // time (ref level =0) // local connectivity for the considered sub triangle vectInt vtkElmConnectivity; for(int k = 0; k < T::numNodes; ++k) { - // Connectivity of the considered sub-element int countTotNodloc = T::numNodes * i + k; // Nodes are duplicate here - int vtkNodeId = myVTKData.vtkCountTotNod + myNodMap.mapping[countTotNodloc]; + int vtkNodeId = + myVTKData.vtkCountTotNod + myNodMap.mapping[countTotNodloc]; vtkElmConnectivity.push_back(vtkNodeId); // Coordinates of the nodes of the considered sub-element @@ -2543,12 +2591,13 @@ void adaptiveElements<T>::addInViewForVTK(int step, px = coords[T::numNodes * i + k].c[0]; py = coords[T::numNodes * i + k].c[1]; pz = coords[T::numNodes * i + k].c[2]; - PCoords tmpCoords = PCoords(px,py,pz); - myVTKData.vtkLocalCoords[myNodMap.mapping[countTotNodloc]] = tmpCoords; + PCoords tmpCoords = PCoords(px, py, pz); + myVTKData.vtkLocalCoords[myNodMap.mapping[countTotNodloc]] = + tmpCoords; // Value associated with each nodes of the sub-element - myVTKData.vtkLocalValues[myNodMap.mapping[countTotNodloc]] = values[T::numNodes * i + k]; - + myVTKData.vtkLocalValues[myNodMap.mapping[countTotNodloc]] = + values[T::numNodes * i + k]; } // Add elm connectivity to vector @@ -2558,13 +2607,14 @@ void adaptiveElements<T>::addInViewForVTK(int step, myVTKData.incrementTotElm(1); // Save element type - myVTKData.vtkLocalCellType.push_back(myVTKData.getPVCellType(T::numEdges)); - + myVTKData.vtkLocalCellType.push_back( + myVTKData.getPVCellType(T::numEdges)); // Global variables if(buildStaticData == true) { globalVTKData::vtkGlobalConnectivity.push_back(vtkElmConnectivity); - globalVTKData::vtkGlobalCellType.push_back(myVTKData.getPVCellType(T::numEdges)); + globalVTKData::vtkGlobalCellType.push_back( + myVTKData.getPVCellType(T::numEdges)); } // Clear existing structure (safer) @@ -2582,12 +2632,11 @@ void adaptiveElements<T>::addInViewForVTK(int step, } if(buildStaticData == true) { - - for(int i=0;i<numNodInsert; i++) { + for(int i = 0; i < numNodInsert; i++) { globalVTKData::vtkGlobalCoords.push_back(myVTKData.vtkLocalCoords[i]); } - for(int i=0;i<numNodInsert; i++) { + for(int i = 0; i < numNodInsert; i++) { globalVTKData::vtkGlobalValues.push_back(myVTKData.vtkLocalValues[i]); } } @@ -2596,17 +2645,17 @@ void adaptiveElements<T>::addInViewForVTK(int step, } // loop over mesh element } - } template <class T> int adaptiveElements<T>::countElmLev0(int step, PViewData *in) { int sum = 0; - for(int ent = 0; ent < in->getNumEntities(step); ent++){ - for(int ele = 0; ele < in->getNumElements(step, ent); ele++){ + for(int ent = 0; ent < in->getNumEntities(step); ent++) { + for(int ele = 0; ele < in->getNumElements(step, ent); ele++) { if(in->skipElement(step, ent, ele) || - in->getNumEdges(step, ent, ele) != T::numEdges) continue; + in->getNumEdges(step, ent, ele) != T::numEdges) + continue; else sum++; } @@ -2616,45 +2665,59 @@ int adaptiveElements<T>::countElmLev0(int step, PViewData *in) int adaptiveData::countTotElmLev0(int step, PViewData *in) { - int sumElm = 0; - if(_triangles) sumElm+=_triangles->countElmLev0(step, in); - if(_quadrangles) sumElm+=_quadrangles->countElmLev0(step, in); - if(_tetrahedra) sumElm+=_tetrahedra->countElmLev0(step, in); - if(_prisms) sumElm+=_prisms->countElmLev0(step, in); - if(_hexahedra) sumElm+=_hexahedra->countElmLev0(step, in); - if(_pyramids) sumElm+=_pyramids->countElmLev0(step, in); + if(_triangles) sumElm += _triangles->countElmLev0(step, in); + if(_quadrangles) sumElm += _quadrangles->countElmLev0(step, in); + if(_tetrahedra) sumElm += _tetrahedra->countElmLev0(step, in); + if(_prisms) sumElm += _prisms->countElmLev0(step, in); + if(_hexahedra) sumElm += _hexahedra->countElmLev0(step, in); + if(_pyramids) sumElm += _pyramids->countElmLev0(step, in); return sumElm; } - -void adaptiveData::changeResolutionForVTK(int step, int level, double tol, int npart, bool isBinary, - const std::string &guiFileName, int useDefaultName) +void adaptiveData::changeResolutionForVTK(int step, int level, double tol, + int npart, bool isBinary, + const std::string &guiFileName, + int useDefaultName) { - //clean global VTK data structure before (re)generating it + // clean global VTK data structure before (re)generating it if(buildStaticData == true) globalVTKData::clearGlobalData(); VTKData myVTKData(_inData->getName(), _inData->getNumComponents(0, 0, 0), - step, level, tol, guiFileName, useDefaultName, npart, isBinary); + step, level, tol, guiFileName, useDefaultName, npart, + isBinary); myVTKData.vtkTotNumElmLev0 = countTotElmLev0(step, _inData); myVTKData.setFileDistribution(); - // Views of 2D and 3D elements only supported for VTK. _points and _lines are currently ignored. + // Views of 2D and 3D elements only supported for VTK. _points and _lines are + // currently ignored. if(_triangles) _triangles->init(myVTKData.vtkLevel); if(_quadrangles) _quadrangles->init(myVTKData.vtkLevel); if(_tetrahedra) _tetrahedra->init(myVTKData.vtkLevel); if(_prisms) _prisms->init(myVTKData.vtkLevel); if(_hexahedra) _hexahedra->init(myVTKData.vtkLevel); - if(_pyramids) _pyramids->init(myVTKData.vtkLevel); - - if(_triangles) _triangles->addInViewForVTK(step, _inData, myVTKData, writeVTK, buildStaticData); - if(_quadrangles) _quadrangles->addInViewForVTK(step, _inData, myVTKData, writeVTK, buildStaticData); - if(_tetrahedra) _tetrahedra->addInViewForVTK(step, _inData, myVTKData, writeVTK, buildStaticData); - if(_prisms) _prisms->addInViewForVTK(step, _inData, myVTKData, writeVTK, buildStaticData); - if(_hexahedra) _hexahedra->addInViewForVTK(step, _inData, myVTKData, writeVTK, buildStaticData); - if(_pyramids) _pyramids->addInViewForVTK(step, _inData, myVTKData, writeVTK, buildStaticData); - - Msg::StatusBar(true,"Done writing VTK data"); + if(_pyramids) _pyramids->init(myVTKData.vtkLevel); + + if(_triangles) + _triangles->addInViewForVTK(step, _inData, myVTKData, writeVTK, + buildStaticData); + if(_quadrangles) + _quadrangles->addInViewForVTK(step, _inData, myVTKData, writeVTK, + buildStaticData); + if(_tetrahedra) + _tetrahedra->addInViewForVTK(step, _inData, myVTKData, writeVTK, + buildStaticData); + if(_prisms) + _prisms->addInViewForVTK(step, _inData, myVTKData, writeVTK, + buildStaticData); + if(_hexahedra) + _hexahedra->addInViewForVTK(step, _inData, myVTKData, writeVTK, + buildStaticData); + if(_pyramids) + _pyramids->addInViewForVTK(step, _inData, myVTKData, writeVTK, + buildStaticData); + + Msg::StatusBar(true, "Done writing VTK data"); } diff --git a/Post/adaptiveData.h b/Post/adaptiveData.h index 3ad3908fa4390e03aeb26cccbf71f6b28b597c2d..5ffddfe832a0b666c4b43c0ec6fde8cd77f191ea 100644 --- a/Post/adaptiveData.h +++ b/Post/adaptiveData.h @@ -20,13 +20,13 @@ #include "fullMatrix.h" #if defined(WIN32) - typedef unsigned __int8 uint8_t; // Valid for _MSC_VER >= 1300 - typedef unsigned __int64 uint64_t; - #define PRIu8 "u" - #define PRIu64 "I64u" +typedef unsigned __int8 uint8_t; // Valid for _MSC_VER >= 1300 +typedef unsigned __int64 uint64_t; +#define PRIu8 "u" +#define PRIu64 "I64u" #else - #define __STDC_FORMAT_MACROS - #include <inttypes.h> +#define __STDC_FORMAT_MACROS +#include <inttypes.h> #endif typedef std::vector<int> vectInt; @@ -36,8 +36,7 @@ class PViewDataList; class GMSH_PostPlugin; // For old compilers that do not support yet std::to_string() -template <class T> -std::string ToString(const T& val) +template <class T> std::string ToString(const T &val) { std::stringstream stream; stream << val; @@ -45,16 +44,17 @@ std::string ToString(const T& val) } class adaptiveVertex { - public: - float x, y, z; //!< parametric coordinates - double X, Y, Z; //!< cartesian coordinates - double val,valy,valz; //!< maximal three values - double valyx,valyy,valyz; - double valzx,valzy,valzz; - public: +public: + float x, y, z; //!< parametric coordinates + double X, Y, Z; //!< cartesian coordinates + double val, valy, valz; //!< maximal three values + double valyx, valyy, valyz; + double valzx, valzy, valzz; + +public: static adaptiveVertex *add(double x, double y, double z, std::set<adaptiveVertex> &allVertice); - bool operator < (const adaptiveVertex &other) const + bool operator<(const adaptiveVertex &other) const { if(other.x < x) return true; if(other.x > x) return false; @@ -65,42 +65,32 @@ class adaptiveVertex { } }; -template <class T> -class nodMap { +template <class T> class nodMap { public: std::vector<int> mapping; public: - void cleanMapping() - { - mapping.clear(); - } - ~nodMap() - { - cleanMapping(); - } - int getSize() {return (int) mapping.size();} + void cleanMapping() { mapping.clear(); } + ~nodMap() { cleanMapping(); } + int getSize() { return (int)mapping.size(); } }; class adaptivePoint { - public: +public: bool visible; adaptiveVertex *p[1]; adaptivePoint *e[1]; - static std::list<adaptivePoint*> all; + static std::list<adaptivePoint *> all; static std::set<adaptiveVertex> allVertices; static int numNodes, numEdges; - public: - adaptivePoint(adaptiveVertex *p1) - : visible(false) + +public: + adaptivePoint(adaptiveVertex *p1) : visible(false) { p[0] = p1; e[0] = 0; } - inline double V() const - { - return p[0]->val; - } + inline double V() const { return p[0]->val; } inline static void GSF(double u, double v, double w, fullVector<double> &sf) { sf(0) = 1; @@ -112,25 +102,22 @@ class adaptivePoint { }; class adaptiveLine { - public: +public: bool visible; adaptiveVertex *p[2]; adaptiveLine *e[2]; - static std::list<adaptiveLine*> all; + static std::list<adaptiveLine *> all; static std::set<adaptiveVertex> allVertices; static int numNodes, numEdges; - public: - adaptiveLine(adaptiveVertex *p1, adaptiveVertex *p2) - : visible(false) + +public: + adaptiveLine(adaptiveVertex *p1, adaptiveVertex *p2) : visible(false) { p[0] = p1; p[1] = p2; e[0] = e[1] = 0; } - inline double V() const - { - return (p[0]->val + p[1]->val) / 2.; - } + inline double V() const { return (p[0]->val + p[1]->val) / 2.; } inline static void GSF(double u, double v, double w, fullVector<double> &sf) { sf(0) = (1 - u) / 2.; @@ -143,14 +130,15 @@ class adaptiveLine { }; class adaptiveTriangle { - public: +public: bool visible; adaptiveVertex *p[3]; adaptiveTriangle *e[4]; - static std::list<adaptiveTriangle*> all; + static std::list<adaptiveTriangle *> all; static std::set<adaptiveVertex> allVertices; static int numNodes, numEdges; - public: + +public: adaptiveTriangle(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3) : visible(false) { @@ -159,10 +147,7 @@ class adaptiveTriangle { p[2] = p3; e[0] = e[1] = e[2] = e[3] = 0; } - inline double V() const - { - return (p[0]->val + p[1]->val + p[2]->val) / 3.; - } + inline double V() const { return (p[0]->val + p[1]->val + p[2]->val) / 3.; } inline static void GSF(double u, double v, double w, fullVector<double> &sf) { sf(0) = 1. - u - v; @@ -176,16 +161,17 @@ class adaptiveTriangle { }; class adaptiveQuadrangle { - public: +public: bool visible; adaptiveVertex *p[4]; adaptiveQuadrangle *e[4]; - static std::list<adaptiveQuadrangle*> all; + static std::list<adaptiveQuadrangle *> all; static std::set<adaptiveVertex> allVertices; static int numNodes, numEdges; - public: - adaptiveQuadrangle(adaptiveVertex *p1, adaptiveVertex *p2, - adaptiveVertex *p3, adaptiveVertex *p4) + +public: + adaptiveQuadrangle(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3, + adaptiveVertex *p4) : visible(false) { p[0] = p1; @@ -212,14 +198,15 @@ class adaptiveQuadrangle { }; class adaptivePrism { - public: +public: bool visible; adaptiveVertex *p[6]; adaptivePrism *e[8]; - static std::list<adaptivePrism*> all; + static std::list<adaptivePrism *> all; static std::set<adaptiveVertex> allVertices; static int numNodes, numEdges; - public: + +public: adaptivePrism(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3, adaptiveVertex *p4, adaptiveVertex *p5, adaptiveVertex *p6) : visible(false) @@ -230,21 +217,23 @@ class adaptivePrism { p[3] = p4; p[4] = p5; p[5] = p6; - e[0] = e[1] = e[2] = e[3] = NULL; - e[4] = e[5] = e[6] = e[7] = NULL; + e[0] = e[1] = e[2] = e[3] = NULL; + e[4] = e[5] = e[6] = e[7] = NULL; } inline double V() const { - return (p[0]->val + p[1]->val + p[2]->val + p[3]->val + p[4]->val + p[5]->val) / 6.; + return (p[0]->val + p[1]->val + p[2]->val + p[3]->val + p[4]->val + + p[5]->val) / + 6.; } inline static void GSF(double u, double v, double w, fullVector<double> &sf) { sf(0) = (1. - u - v) * (1 - w) / 2; - sf(1) = u * (1-w)/2; - sf(2) = v*(1-w)/2; - sf(3) = (1. - u - v)*(1+w)/2; - sf(4) = u*(1+w)/2; - sf(5) = v*(1+w)/2; + sf(1) = u * (1 - w) / 2; + sf(2) = v * (1 - w) / 2; + sf(3) = (1. - u - v) * (1 + w) / 2; + sf(4) = u * (1 + w) / 2; + sf(5) = v * (1 + w) / 2; } static void create(int maxlevel); static void recurCreate(adaptivePrism *p, int maxlevel, int level); @@ -253,14 +242,15 @@ class adaptivePrism { }; class adaptiveTetrahedron { - public: +public: bool visible; adaptiveVertex *p[4]; adaptiveTetrahedron *e[8]; - static std::list<adaptiveTetrahedron*> all; + static std::list<adaptiveTetrahedron *> all; static std::set<adaptiveVertex> allVertices; static int numNodes, numEdges; - public: + +public: adaptiveTetrahedron(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3, adaptiveVertex *p4) : visible(false) @@ -290,14 +280,15 @@ class adaptiveTetrahedron { }; class adaptiveHexahedron { - public: +public: bool visible; adaptiveVertex *p[8]; adaptiveHexahedron *e[8]; - static std::list<adaptiveHexahedron*> all; + static std::list<adaptiveHexahedron *> all; static std::set<adaptiveVertex> allVertices; static int numNodes, numEdges; - public: + +public: adaptiveHexahedron(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3, adaptiveVertex *p4, adaptiveVertex *p5, adaptiveVertex *p6, adaptiveVertex *p7, adaptiveVertex *p8) @@ -316,8 +307,9 @@ class adaptiveHexahedron { } inline double V() const { - return (p[0]->val + p[1]->val + p[2]->val+ p[3]->val + - p[4]->val + p[5]->val + p[6]->val+ p[7]->val) / 8.; + return (p[0]->val + p[1]->val + p[2]->val + p[3]->val + p[4]->val + + p[5]->val + p[6]->val + p[7]->val) / + 8.; } inline static void GSF(double u, double v, double w, fullVector<double> &sf) { @@ -339,19 +331,17 @@ class adaptiveHexahedron { // modif koen.hillewaert@cenaero.be, 31/07/2014 class adaptivePyramid { - public: +public: bool visible; adaptiveVertex *p[5]; adaptivePyramid *e[10]; - static std::list<adaptivePyramid*> all; + static std::list<adaptivePyramid *> all; static std::set<adaptiveVertex> allVertices; static int numNodes, numEdges; - public: - adaptivePyramid(adaptiveVertex *p1, - adaptiveVertex *p2, - adaptiveVertex *p3, - adaptiveVertex *p4, - adaptiveVertex *p5) + +public: + adaptivePyramid(adaptiveVertex *p1, adaptiveVertex *p2, adaptiveVertex *p3, + adaptiveVertex *p4, adaptiveVertex *p5) : visible(false) { p[0] = p1; @@ -359,7 +349,7 @@ class adaptivePyramid { p[2] = p3; p[3] = p4; p[4] = p5; - for (int i=0;i<10;i++) e[i] = NULL; + for(int i = 0; i < 10; i++) e[i] = NULL; } inline double V() const { @@ -368,7 +358,7 @@ class adaptivePyramid { // barycentric coordinates ? inline static void GSF(double u, double v, double w, fullVector<double> &sf) { - double ww = 0.25 / std::max(1e-14,1.-w); + double ww = 0.25 / std::max(1e-14, 1. - w); sf(0) = (1 - u - w) * (1 - v - w) * ww; sf(1) = (1 + u - w) * (1 - v - w) * ww; sf(2) = (1 + u - w) * (1 + v - w) * ww; @@ -382,23 +372,25 @@ class adaptivePyramid { }; class PCoords { - public: +public: double c[3]; PCoords(double x, double y, double z) { - c[0] = x; c[1] = y; c[2] = z; + c[0] = x; + c[1] = y; + c[2] = z; } }; -class PValues{ - public: - short int sizev; //acceptable values: 1 (scalar), 3 (vector), 9 (tensor) +class PValues { +public: + short int sizev; // acceptable values: 1 (scalar), 3 (vector), 9 (tensor) double *v; - PValues(const PValues& obj) + PValues(const PValues &obj) { sizev = obj.sizev; v = new double[sizev]; - for(int i=0;i<sizev;i++) { + for(int i = 0; i < sizev; i++) { v[i] = obj.v[i]; } } @@ -406,7 +398,7 @@ class PValues{ { sizev = size; v = new double[sizev]; - for(int i=0;i<sizev;i++) { + for(int i = 0; i < sizev; i++) { v[i] = 0.0; } } @@ -420,40 +412,47 @@ class PValues{ { sizev = 3; v = new double[sizev]; - v[0] = vx; v[1] = vy; v[2] = vz; + v[0] = vx; + v[1] = vy; + v[2] = vz; } - PValues(double vxx, double vxy, double vxz, - double vyx, double vyy, double vyz, - double vzx, double vzy, double vzz) + PValues(double vxx, double vxy, double vxz, double vyx, double vyy, + double vyz, double vzx, double vzy, double vzz) { sizev = 9; v = new double[sizev]; - v[0] = vxx; v[1] = vxy; v[2] = vxz; - v[3] = vyx; v[4] = vyy; v[5] = vyz; - v[6] = vzx; v[7] = vzy; v[8] = vzz; - } - ~PValues() - { - delete[] v; - } - void operator = (const PValues& obj) + v[0] = vxx; + v[1] = vxy; + v[2] = vxz; + v[3] = vyx; + v[4] = vyy; + v[5] = vyz; + v[6] = vzx; + v[7] = vzy; + v[8] = vzz; + } + ~PValues() { delete[] v; } + void operator=(const PValues &obj) { // Assume PValues object has already been generated // and v allocated when the operator = is called if(sizev != obj.sizev) - Msg::Error("In PValues overlodaing operator: size mistmatch %d %d",sizev); - for(int i=0;i<sizev;i++) { + Msg::Error("In PValues overlodaing operator: size mistmatch %d %d", + sizev); + for(int i = 0; i < sizev; i++) { v[i] = obj.v[i]; } } }; class globalVTKData { - public: - static std::vector<vectInt> vtkGlobalConnectivity; // conectivity (vector of vector) +public: + static std::vector<vectInt> + vtkGlobalConnectivity; // conectivity (vector of vector) static std::vector<int> vtkGlobalCellType; // topology static std::vector<PCoords> vtkGlobalCoords; // coordinates - static std::vector<PValues> vtkGlobalValues; // nodal values (either scalar or vector) + static std::vector<PValues> + vtkGlobalValues; // nodal values (either scalar or vector) globalVTKData(); static void clearGlobalConnectivity() { @@ -486,14 +485,11 @@ class globalVTKData { clearGlobalCoords(); clearGlobalValues(); } - ~globalVTKData() - { - clearGlobalData(); - } + ~globalVTKData() { clearGlobalData(); } }; class VTKData { - public: +public: // Data container to write output files readable for ParaView // vtk legacy and vtu for now std::string vtkFieldName; @@ -527,22 +523,22 @@ class VTKData { int vtkCountCoord; int vtkCountTotNodConnect; int vtkCountTotVal; - int vtkCountCellOffset; //used only for ascii output - int vtkCountCellType; //used only for ascii output + int vtkCountCellOffset; // used only for ascii output + int vtkCountCellType; // used only for ascii output std::vector<vectInt> vtkLocalConnectivity; // conectivity (vector of vector) std::vector<int> vtkLocalCellType; // topology std::vector<PCoords> vtkLocalCoords; // coordinates std::vector<PValues> vtkLocalValues; // nodal values (either scalar or vector) - public: - VTKData(std::string fieldName="unknown", int numComp = -1, int step = -1, - int level = -1, double tol=0.0, std::string filename="unknown", + VTKData(std::string fieldName = "unknown", int numComp = -1, int step = -1, + int level = -1, double tol = 0.0, std::string filename = "unknown", int useDefaultName = 1, int npart = -1, bool isBinary = true) { vtkIsBinary = isBinary; // choice: true, false - vtkFormat = std::string("vtu"); // choice: vtk (VTK legacy), vtu (XML appended) + vtkFormat = + std::string("vtu"); // choice: vtk (VTK legacy), vtu (XML appended) vtkFieldName = fieldName; vtkFileName = filename; @@ -561,7 +557,7 @@ public: vtkCountCoord = 0; vtkCountTotNodConnect = 0; vtkCountTotVal = 0; - vtkCountCellOffset = 0; //used only for ascii output + vtkCountCellOffset = 0; // used only for ascii output vtkCountCellType = 0; } void clearLocalData() @@ -575,15 +571,13 @@ public: vtkLocalCoords.clear(); vtkLocalValues.clear(); } - ~VTKData() - { - clearLocalData(); - } - void incrementTotNod(int increment) { vtkCountTotNod+=increment; } - void incrementTotElm(int increment) { vtkCountTotElm+=increment; } - void incrementTotElmLev0(int increment) { vtkCountTotElmLev0+=increment; } + ~VTKData() { clearLocalData(); } + void incrementTotNod(int increment) { vtkCountTotNod += increment; } + void incrementTotElm(int increment) { vtkCountTotElm += increment; } + void incrementTotElmLev0(int increment) { vtkCountTotElmLev0 += increment; } bool isLittleEndian(); - void SwapArrayByteOrder(void* array, int nbytes, int nItems); // used only for VTK + void SwapArrayByteOrder(void *array, int nbytes, + int nItems); // used only for VTK int getPVCellType(int numEdges); // void writeParaViewData(); void writeVTKElmData(); @@ -592,38 +586,40 @@ public: void setFileDistribution() { int tmpmod = vtkTotNumElmLev0 % vtkNpart; - minElmPerPart = (vtkTotNumElmLev0-tmpmod)/vtkNpart; + minElmPerPart = (vtkTotNumElmLev0 - tmpmod) / vtkNpart; numPartMinElm = vtkNpart - tmpmod; - if(tmpmod == 0 ) maxElmPerPart = minElmPerPart; - else maxElmPerPart = minElmPerPart+1; + if(tmpmod == 0) + maxElmPerPart = minElmPerPart; + else + maxElmPerPart = minElmPerPart + 1; numPartMaxElm = tmpmod; - assert(vtkTotNumElmLev0 == minElmPerPart*numPartMinElm+maxElmPerPart*numPartMaxElm); + assert(vtkTotNumElmLev0 == + minElmPerPart * numPartMinElm + maxElmPerPart * numPartMaxElm); } }; -template <class T> -class adaptiveElements { - private: +template <class T> class adaptiveElements { +private: fullMatrix<double> *_coeffsVal, *_eexpsVal, *_interpolVal; fullMatrix<double> *_coeffsGeom, *_eexpsGeom, *_interpolGeom; - public: - adaptiveElements(std::vector<fullMatrix<double>*> &interpolationMatrices); + +public: + adaptiveElements(std::vector<fullMatrix<double> *> &interpolationMatrices); ~adaptiveElements(); // create the _interpolVal and _interpolGeom matrices at the given // refinement level void init(int level); // process the element data in coords/values and return the refined // elements in coords/values - void adapt(double tol, int numComp, - std::vector<PCoords> &coords, std::vector<PValues> &values, - double &minVal, double &maxVal, GMSH_PostPlugin *plug=0, - bool onlyComputeMinMax=false); + void adapt(double tol, int numComp, std::vector<PCoords> &coords, + std::vector<PValues> &values, double &minVal, double &maxVal, + GMSH_PostPlugin *plug = 0, bool onlyComputeMinMax = false); // adapt all the T-type elements in the input view and add the // refined elements in the output view (we will remove this when we // switch to true on-the-fly local refinement in drawPost()) void addInView(double tol, int step, PViewData *in, PViewDataList *out, - GMSH_PostPlugin *plug=0); + GMSH_PostPlugin *plug = 0); // Routines for // - export of adapted views to pvtu file format for parallel visualization @@ -631,13 +627,13 @@ class adaptiveElements { // - and/or generation of VTK data structure for ParaView plugin. // Clone of adapt for VTK output files - void adaptForVTK(double tol, int numComp, - std::vector<PCoords> &coords, std::vector<PValues> &values, - double &minVal, double &maxVal); + void adaptForVTK(double tol, int numComp, std::vector<PCoords> &coords, + std::vector<PValues> &values, double &minVal, + double &maxVal); // Clone of addInView for VTK output files void addInViewForVTK(int step, PViewData *in, VTKData &myVTKData, - bool writeVtk=true, bool buildStaticData=false); + bool writeVtk = true, bool buildStaticData = false); int countElmLev0(int step, PViewData *in); @@ -648,7 +644,7 @@ class adaptiveElements { }; class adaptiveData { - private: +private: int _step, _level; double _tol; PViewData *_inData; @@ -677,12 +673,13 @@ class adaptiveData { // constructor. bool writeVTK; - public: +public: static double timerInit, timerAdapt; - adaptiveData(PViewData *data, bool outDataInit=true); + adaptiveData(PViewData *data, bool outDataInit = true); ~adaptiveData(); - PViewData *getData(){ return (PViewData*)_outData; } - void changeResolution(int step, int level, double tol, GMSH_PostPlugin *plug=0); + PViewData *getData() { return (PViewData *)_outData; } + void changeResolution(int step, int level, double tol, + GMSH_PostPlugin *plug = 0); int countTotElmLev0(int step, PViewData *in); void changeResolutionForVTK(int step, int level, double tol, int npart = 1, bool isBinary = true, diff --git a/Post/shapeFunctions.h b/Post/shapeFunctions.h index 30e46628c7ab7f08e9b41623bd7d053e4fedbf70..01e92d74f709095f181d2ad89577e7d163181c09 100644 --- a/Post/shapeFunctions.h +++ b/Post/shapeFunctions.h @@ -9,25 +9,27 @@ #include "Numeric.h" #include "GmshMessage.h" - -class element{ +class element { protected: bool _ownData; double *_x, *_y, *_z; static double TOL; + public: - element(double *x, double *y, double *z, int numNodes=0) + element(double *x, double *y, double *z, int numNodes = 0) { - if(!numNodes){ + if(!numNodes) { _ownData = false; - _x = x; _y = y; _z = z; + _x = x; + _y = y; + _z = z; } - else{ + else { _ownData = true; _x = new double[numNodes]; _y = new double[numNodes]; _z = new double[numNodes]; - for(int i = 0; i < numNodes; i++){ + for(int i = 0; i < numNodes; i++) { _x[i] = x[i]; _y[i] = y[i]; _z[i] = z[i]; @@ -36,10 +38,10 @@ public: } virtual ~element() { - if(_ownData){ - delete [] _x; - delete [] _y; - delete [] _z; + if(_ownData) { + delete[] _x; + delete[] _y; + delete[] _z; } } virtual void getXYZ(int num, double &x, double &y, double &z) @@ -49,47 +51,66 @@ public: y = _y[num]; z = _z[num]; } - static void setTolerance (const double tol){ TOL = tol; } - static double getTolerance () { return TOL; } + static void setTolerance(const double tol) { TOL = tol; } + static double getTolerance() { return TOL; } virtual int getDimension() = 0; virtual int getNumNodes() = 0; virtual void getNode(int num, double &u, double &v, double &w) = 0; virtual int getNumEdges() = 0; virtual void getEdge(int num, int &start, int &end) = 0; virtual int getNumGaussPoints() = 0; - virtual void getGaussPoint(int num, double &u, double &v, double &w, double &weight) = 0; - virtual void getShapeFunction(int num, double u, double v, double w, double &s) = 0; - virtual void getGradShapeFunction(int num, double u, double v, double w, double s[3]) = 0; + virtual void getGaussPoint(int num, double &u, double &v, double &w, + double &weight) = 0; + virtual void getShapeFunction(int num, double u, double v, double w, + double &s) = 0; + virtual void getGradShapeFunction(int num, double u, double v, double w, + double s[3]) = 0; double getJacobian(double u, double v, double w, double jac[3][3]) { jac[0][0] = jac[0][1] = jac[0][2] = 0.; jac[1][0] = jac[1][1] = jac[1][2] = 0.; jac[2][0] = jac[2][1] = jac[2][2] = 0.; double s[3]; - switch(getDimension()){ - case 3 : + switch(getDimension()) { + case 3: for(int i = 0; i < getNumNodes(); i++) { getGradShapeFunction(i, u, v, w, s); - jac[0][0] += _x[i] * s[0]; jac[0][1] += _y[i] * s[0]; jac[0][2] += _z[i] * s[0]; - jac[1][0] += _x[i] * s[1]; jac[1][1] += _y[i] * s[1]; jac[1][2] += _z[i] * s[1]; - jac[2][0] += _x[i] * s[2]; jac[2][1] += _y[i] * s[2]; jac[2][2] += _z[i] * s[2]; + jac[0][0] += _x[i] * s[0]; + jac[0][1] += _y[i] * s[0]; + jac[0][2] += _z[i] * s[0]; + jac[1][0] += _x[i] * s[1]; + jac[1][1] += _y[i] * s[1]; + jac[1][2] += _z[i] * s[1]; + jac[2][0] += _x[i] * s[2]; + jac[2][1] += _y[i] * s[2]; + jac[2][2] += _z[i] * s[2]; } return std::abs( jac[0][0] * jac[1][1] * jac[2][2] + jac[0][2] * jac[1][0] * jac[2][1] + jac[0][1] * jac[1][2] * jac[2][0] - jac[0][2] * jac[1][1] * jac[2][0] - jac[0][0] * jac[1][2] * jac[2][1] - jac[0][1] * jac[1][0] * jac[2][2]); - case 2 : + case 2: for(int i = 0; i < getNumNodes(); i++) { getGradShapeFunction(i, u, v, w, s); - jac[0][0] += _x[i] * s[0]; jac[0][1] += _y[i] * s[0]; jac[0][2] += _z[i] * s[0]; - jac[1][0] += _x[i] * s[1]; jac[1][1] += _y[i] * s[1]; jac[1][2] += _z[i] * s[1]; + jac[0][0] += _x[i] * s[0]; + jac[0][1] += _y[i] * s[0]; + jac[0][2] += _z[i] * s[0]; + jac[1][0] += _x[i] * s[1]; + jac[1][1] += _y[i] * s[1]; + jac[1][2] += _z[i] * s[1]; } { double a[3], b[3], c[3]; - a[0]= _x[1] - _x[0]; a[1]= _y[1] - _y[0]; a[2]= _z[1] - _z[0]; - b[0]= _x[2] - _x[0]; b[1]= _y[2] - _y[0]; b[2]= _z[2] - _z[0]; + a[0] = _x[1] - _x[0]; + a[1] = _y[1] - _y[0]; + a[2] = _z[1] - _z[0]; + b[0] = _x[2] - _x[0]; + b[1] = _y[2] - _y[0]; + b[2] = _z[2] - _z[0]; prodve(a, b, c); - jac[2][0] = c[0]; jac[2][1] = c[1]; jac[2][2] = c[2]; + jac[2][0] = c[0]; + jac[2][1] = c[1]; + jac[2][2] = c[2]; } return std::sqrt( std::pow(jac[0][0] * jac[1][1] - jac[0][1] * jac[1][0], 2) + @@ -98,33 +119,46 @@ public: case 1: for(int i = 0; i < getNumNodes(); i++) { getGradShapeFunction(i, u, v, w, s); - jac[0][0] += _x[i] * s[0]; jac[0][1] += _y[i] * s[0]; jac[0][2] += _z[i] * s[0]; + jac[0][0] += _x[i] * s[0]; + jac[0][1] += _y[i] * s[0]; + jac[0][2] += _z[i] * s[0]; } { double a[3], b[3], c[3]; - a[0]= _x[1] - _x[0]; a[1]= _y[1] - _y[0]; a[2]= _z[1] - _z[0]; - if((std::abs(a[0]) >= std::abs(a[1]) && std::abs(a[0]) >= std::abs(a[2])) || - (std::abs(a[1]) >= std::abs(a[0]) && std::abs(a[1]) >= std::abs(a[2]))) { - b[0] = a[1]; b[1] = -a[0]; b[2] = 0.; + a[0] = _x[1] - _x[0]; + a[1] = _y[1] - _y[0]; + a[2] = _z[1] - _z[0]; + if((std::abs(a[0]) >= std::abs(a[1]) && + std::abs(a[0]) >= std::abs(a[2])) || + (std::abs(a[1]) >= std::abs(a[0]) && + std::abs(a[1]) >= std::abs(a[2]))) { + b[0] = a[1]; + b[1] = -a[0]; + b[2] = 0.; } else { - b[0] = 0.; b[1] = a[2]; b[2] = -a[1]; + b[0] = 0.; + b[1] = a[2]; + b[2] = -a[1]; } prodve(a, b, c); - jac[1][0] = b[0]; jac[1][1] = b[1]; jac[1][2] = b[2]; - jac[2][0] = c[0]; jac[2][1] = c[1]; jac[2][2] = c[2]; + jac[1][0] = b[0]; + jac[1][1] = b[1]; + jac[1][2] = b[2]; + jac[2][0] = c[0]; + jac[2][1] = c[1]; + jac[2][2] = c[2]; } - return std::sqrt(std::pow(jac[0][0], 2)+std::pow(jac[0][1], 2)+std::pow(jac[0][2], 2)); - default: - jac[0][0] = jac[1][1] = jac[2][2] = 1.; - return 1.; + return std::sqrt(std::pow(jac[0][0], 2) + std::pow(jac[0][1], 2) + + std::pow(jac[0][2], 2)); + default: jac[0][0] = jac[1][1] = jac[2][2] = 1.; return 1.; } } - double interpolate(double val[], double u, double v, double w, int stride=1) + double interpolate(double val[], double u, double v, double w, int stride = 1) { double sum = 0; int j = 0; - for(int i = 0; i < getNumNodes(); i++){ + for(int i = 0; i < getNumNodes(); i++) { double s; getShapeFunction(i, u, v, w, s); sum += val[j] * s; @@ -132,12 +166,12 @@ public: } return sum; } - void interpolateGrad(double val[], double u, double v, double w, double f[3], int stride=1, - double invjac[3][3]=NULL) + void interpolateGrad(double val[], double u, double v, double w, double f[3], + int stride = 1, double invjac[3][3] = NULL) { double dfdu[3] = {0., 0., 0.}; int j = 0; - for(int i = 0; i < getNumNodes(); i++){ + for(int i = 0; i < getNumNodes(); i++) { double s[3]; getGradShapeFunction(i, u, v, w, s); dfdu[0] += val[j] * s[0]; @@ -145,17 +179,18 @@ public: dfdu[2] += val[j] * s[2]; j += stride; } - if(invjac){ + if(invjac) { matvec(invjac, dfdu, f); } - else{ + else { double jac[3][3], inv[3][3]; getJacobian(u, v, w, jac); inv3x3(jac, inv); matvec(inv, dfdu, f); } } - void interpolateCurl(double val[], double u, double v, double w, double f[3], int stride=3) + void interpolateCurl(double val[], double u, double v, double w, double f[3], + int stride = 3) { double fx[3], fy[3], fz[3], jac[3][3], inv[3][3]; getJacobian(u, v, w, jac); @@ -167,7 +202,8 @@ public: f[1] = -(fz[0] - fx[2]); f[2] = fy[0] - fx[1]; } - double interpolateDiv(double val[], double u, double v, double w, int stride=3) + double interpolateDiv(double val[], double u, double v, double w, + int stride = 3) { double fx[3], fy[3], fz[3], jac[3][3], inv[3][3]; getJacobian(u, v, w, jac); @@ -177,10 +213,10 @@ public: interpolateGrad(&val[2], u, v, w, fz, stride, inv); return fx[0] + fy[1] + fz[2]; } - double integrate(double val[], int stride=1) + double integrate(double val[], int stride = 1) { double sum = 0; - for(int i = 0; i < getNumGaussPoints(); i++){ + for(int i = 0; i < getNumGaussPoints(); i++) { double u, v, w, weight, jac[3][3]; getGaussPoint(i, u, v, w, weight); double det = getJacobian(u, v, w, jac); @@ -195,13 +231,12 @@ public: double ones[8] = {1., 1., 1., 1., 1., 1., 1., 1.}; double area = integrate(ones); double sum = 0, sumabs = 0.; - for(int i = 0; i < getNumNodes(); i++){ + for(int i = 0; i < getNumNodes(); i++) { sum += val[i]; sumabs += std::abs(val[i]); } double res = 0.; - if(sumabs) - res = area * (1 + sum/sumabs) * 0.5 ; + if(sumabs) res = area * (1 + sum / sumabs) * 0.5; return res; } virtual double integrateCirculation(double val[]) @@ -224,12 +259,12 @@ public: int iter = 1, maxiter = 20; double error = 1., tol = 1.e-6; - while (error > tol && iter < maxiter){ + while(error > tol && iter < maxiter) { double jac[3][3]; if(!getJacobian(uvw[0], uvw[1], uvw[2], jac)) break; double xn = 0., yn = 0., zn = 0.; - for (int i = 0; i < getNumNodes(); i++) { + for(int i = 0; i < getNumNodes(); i++) { double s; getShapeFunction(i, uvw[0], uvw[1], uvw[2], s); xn += _x[i] * s; @@ -239,50 +274,50 @@ public: double inv[3][3]; inv3x3(jac, inv); - double un = uvw[0] + - inv[0][0] * (xyz[0] - xn) + inv[1][0] * (xyz[1] - yn) + inv[2][0] * (xyz[2] - zn); - double vn = uvw[1] + - inv[0][1] * (xyz[0] - xn) + inv[1][1] * (xyz[1] - yn) + inv[2][1] * (xyz[2] - zn) ; - double wn = uvw[2] + - inv[0][2] * (xyz[0] - xn) + inv[1][2] * (xyz[1] - yn) + inv[2][2] * (xyz[2] - zn) ; + double un = uvw[0] + inv[0][0] * (xyz[0] - xn) + + inv[1][0] * (xyz[1] - yn) + inv[2][0] * (xyz[2] - zn); + double vn = uvw[1] + inv[0][1] * (xyz[0] - xn) + + inv[1][1] * (xyz[1] - yn) + inv[2][1] * (xyz[2] - zn); + double wn = uvw[2] + inv[0][2] * (xyz[0] - xn) + + inv[1][2] * (xyz[1] - yn) + inv[2][2] * (xyz[2] - zn); - error = std::sqrt(std::pow(un - uvw[0], 2) + std::pow(vn - uvw[1], 2) + std::pow(wn - uvw[2], 2)); + error = std::sqrt(std::pow(un - uvw[0], 2) + std::pow(vn - uvw[1], 2) + + std::pow(wn - uvw[2], 2)); uvw[0] = un; uvw[1] = vn; uvw[2] = wn; - iter++ ; + iter++; } - //if(error > tol) Msg::Warning("Newton did not converge in xyz2uvw") ; + // if(error > tol) Msg::Warning("Newton did not converge in xyz2uvw") ; } virtual int isInside(double u, double v, double w) = 0; double maxEdgeLength() { double max = 0.; - for(int i = 0; i < getNumEdges(); i++){ + for(int i = 0; i < getNumEdges(); i++) { int n1, n2; getEdge(i, n1, n2); - double d = std::sqrt(std::pow(_x[n1]-_x[n2], 2) + std::pow(_y[n1]-_y[n2], 2) + std::pow(_z[n1]-_z[n2], 2)); + double d = + std::sqrt(std::pow(_x[n1] - _x[n2], 2) + std::pow(_y[n1] - _y[n2], 2) + + std::pow(_z[n1] - _z[n2], 2)); if(d > max) max = d; } return max; } }; -class point : public element{ +class point : public element { public: - point(double *x, double *y, double *z, int numNodes=0) : element(x, y, z, numNodes) {} - inline int getDimension(){ return 0; } - inline int getNumNodes(){ return 1; } - void getNode(int num, double &u, double &v, double &w) + point(double *x, double *y, double *z, int numNodes = 0) + : element(x, y, z, numNodes) { - u = v = w = 0.; - } - inline int getNumEdges(){ return 0; } - void getEdge(int num, int &start, int &end) - { - start = end = 0; } - inline int getNumGaussPoints(){ return 1; } + inline int getDimension() { return 0; } + inline int getNumNodes() { return 1; } + void getNode(int num, double &u, double &v, double &w) { u = v = w = 0.; } + inline int getNumEdges() { return 0; } + void getEdge(int num, int &start, int &end) { start = end = 0; } + inline int getNumGaussPoints() { return 1; } void getGaussPoint(int num, double &u, double &v, double &w, double &weight) { u = v = w = 0.; @@ -291,46 +326,46 @@ public: void getShapeFunction(int num, double u, double v, double w, double &s) { switch(num) { - case 0 : s = 1.; break; - default : s = 0.; break; + case 0: s = 1.; break; + default: s = 0.; break; } } void getGradShapeFunction(int num, double u, double v, double w, double s[3]) { s[0] = s[1] = s[2] = 0.; } - void xyz2uvw(double xyz[3], double uvw[3]) - { - uvw[0] = uvw[1] = uvw[2] = 0.; - } + void xyz2uvw(double xyz[3], double uvw[3]) { uvw[0] = uvw[1] = uvw[2] = 0.; } int isInside(double u, double v, double w) { - if(std::abs(u) > TOL || std::abs(v) > TOL || std::abs(w) > TOL) - return 0; + if(std::abs(u) > TOL || std::abs(v) > TOL || std::abs(w) > TOL) return 0; return 1; } }; -class line : public element{ +class line : public element { public: - line(double *x, double *y, double *z, int numNodes=0) : element(x, y, z, numNodes) {} - inline int getDimension(){ return 1; } - inline int getNumNodes(){ return 2; } + line(double *x, double *y, double *z, int numNodes = 0) + : element(x, y, z, numNodes) + { + } + inline int getDimension() { return 1; } + inline int getNumNodes() { return 2; } void getNode(int num, double &u, double &v, double &w) { v = w = 0.; switch(num) { - case 0 : u = -1.; break; - case 1 : u = 1.; break; - default: u = 0.; break; + case 0: u = -1.; break; + case 1: u = 1.; break; + default: u = 0.; break; } } - inline int getNumEdges(){ return 1; } + inline int getNumEdges() { return 1; } void getEdge(int num, int &start, int &end) { - start = 0; end = 1; + start = 0; + end = 1; } - inline int getNumGaussPoints(){ return 1; } + inline int getNumGaussPoints() { return 1; } void getGaussPoint(int num, double &u, double &v, double &w, double &weight) { if(num < 0 || num > 0) return; @@ -340,106 +375,147 @@ public: void getShapeFunction(int num, double u, double v, double w, double &s) { switch(num) { - case 0 : s = 0.5 * (1.-u); break; - case 1 : s = 0.5 * (1.+u); break; - default : s = 0.; break; + case 0: s = 0.5 * (1. - u); break; + case 1: s = 0.5 * (1. + u); break; + default: s = 0.; break; } } void getGradShapeFunction(int num, double u, double v, double w, double s[3]) { switch(num) { - case 0 : s[0] = -0.5; s[1] = 0.; s[2] = 0.; break; - case 1 : s[0] = 0.5; s[1] = 0.; s[2] = 0.; break; - default : s[0] = s[1] = s[2] = 0.; break; + case 0: + s[0] = -0.5; + s[1] = 0.; + s[2] = 0.; + break; + case 1: + s[0] = 0.5; + s[1] = 0.; + s[2] = 0.; + break; + default: s[0] = s[1] = s[2] = 0.; break; } } double integrateCirculation(double val[]) { - double t[3] = {_x[1]-_x[0], _y[1]-_y[0], _z[1]-_z[0]}; + double t[3] = {_x[1] - _x[0], _y[1] - _y[0], _z[1] - _z[0]}; norme(t); double v[3]; - for(int i = 0; i < 3; i++) - v[i] = integrate(&val[i], 3); + for(int i = 0; i < 3; i++) v[i] = integrate(&val[i], 3); return prosca(t, v); } int isInside(double u, double v, double w) { - if(u < -(1. + TOL) || u > (1. + TOL) || std::abs(v) > TOL || std::abs(w) > TOL) + if(u < -(1. + TOL) || u > (1. + TOL) || std::abs(v) > TOL || + std::abs(w) > TOL) return 0; return 1; } }; -class triangle : public element{ +class triangle : public element { public: - triangle(double *x, double *y, double *z, int numNodes=0) : element(x, y, z, numNodes) {} - inline int getDimension(){ return 2; } - inline int getNumNodes(){ return 3; } + triangle(double *x, double *y, double *z, int numNodes = 0) + : element(x, y, z, numNodes) + { + } + inline int getDimension() { return 2; } + inline int getNumNodes() { return 3; } void getNode(int num, double &u, double &v, double &w) { w = 0.; switch(num) { - case 0 : u = 0.; v = 0.; break; - case 1 : u = 1.; v = 0.; break; - case 2 : u = 0.; v = 1.; break; - default: u = 0.; v = 0.; break; + case 0: + u = 0.; + v = 0.; + break; + case 1: + u = 1.; + v = 0.; + break; + case 2: + u = 0.; + v = 1.; + break; + default: + u = 0.; + v = 0.; + break; } } - inline int getNumEdges(){ return 3; } + inline int getNumEdges() { return 3; } void getEdge(int num, int &start, int &end) { switch(num) { - case 0 : start = 0; end = 1; break; - case 1 : start = 1; end = 2; break; - case 2 : start = 2; end = 0; break; + case 0: + start = 0; + end = 1; + break; + case 1: + start = 1; + end = 2; + break; + case 2: + start = 2; + end = 0; + break; default: start = end = 0; break; } } - inline int getNumGaussPoints(){ return /* 3 */ 1; } + inline int getNumGaussPoints() { return /* 3 */ 1; } void getGaussPoint(int num, double &u, double &v, double &w, double &weight) { /* - static double u3[3] = {0.16666666666666,0.66666666666666,0.16666666666666}; - static double v3[3] = {0.16666666666666,0.16666666666666,0.66666666666666}; - static double p3[3] = {0.16666666666666,0.16666666666666,0.16666666666666}; - if(num < 0 || num > 2) return; - u = u3[num]; - v = v3[num]; - w = 0.; - weight = p3[num]; + static double u3[3] = + {0.16666666666666,0.66666666666666,0.16666666666666}; static double v3[3] + = {0.16666666666666,0.16666666666666,0.66666666666666}; static double + p3[3] = {0.16666666666666,0.16666666666666,0.16666666666666}; if(num < 0 + || num > 2) return; u = u3[num]; v = v3[num]; w = 0.; weight = p3[num]; */ if(num < 0 || num > 0) return; - u = v = 0.333333333333333; w = 0.; + u = v = 0.333333333333333; + w = 0.; weight = 0.5; } void getShapeFunction(int num, double u, double v, double w, double &s) { - switch(num){ - case 0 : s = 1.-u-v; break; - case 1 : s = u ; break; - case 2 : s = v; break; - default : s = 0.; break; + switch(num) { + case 0: s = 1. - u - v; break; + case 1: s = u; break; + case 2: s = v; break; + default: s = 0.; break; } } void getGradShapeFunction(int num, double u, double v, double w, double s[3]) { switch(num) { - case 0 : s[0] = -1.; s[1] = -1.; s[2] = 0.; break; - case 1 : s[0] = 1.; s[1] = 0.; s[2] = 0.; break; - case 2 : s[0] = 0.; s[1] = 1.; s[2] = 0.; break; - default : s[0] = s[1] = s[2] = 0.; break; + case 0: + s[0] = -1.; + s[1] = -1.; + s[2] = 0.; + break; + case 1: + s[0] = 1.; + s[1] = 0.; + s[2] = 0.; + break; + case 2: + s[0] = 0.; + s[1] = 1.; + s[2] = 0.; + break; + default: s[0] = s[1] = s[2] = 0.; break; } } double integrateFlux(double val[]) { - double t1[3] = {_x[1]-_x[0], _y[1]-_y[0], _z[1]-_z[0]}; - double t2[3] = {_x[2]-_x[0], _y[2]-_y[0], _z[2]-_z[0]}; + double t1[3] = {_x[1] - _x[0], _y[1] - _y[0], _z[1] - _z[0]}; + double t2[3] = {_x[2] - _x[0], _y[2] - _y[0], _z[2] - _z[0]}; double n[3]; prodve(t1, t2, n); norme(n); double v[3]; - for(int i = 0; i < 3; i++) - v[i] = integrate(&val[i], 3); + for(int i = 0; i < 3; i++) v[i] = integrate(&val[i], 3); return prosca(n, v); } #if 0 // faster, but only valid for triangles in the z=0 plane @@ -464,39 +540,71 @@ public: } }; -class quadrangle : public element{ +class quadrangle : public element { public: - quadrangle(double *x, double *y, double *z, int numNodes=0) : element(x, y, z, numNodes) {} - inline int getDimension(){ return 2; } - inline int getNumNodes(){ return 4; } + quadrangle(double *x, double *y, double *z, int numNodes = 0) + : element(x, y, z, numNodes) + { + } + inline int getDimension() { return 2; } + inline int getNumNodes() { return 4; } void getNode(int num, double &u, double &v, double &w) { w = 0.; switch(num) { - case 0 : u = -1.; v = -1.; break; - case 1 : u = 1.; v = -1.; break; - case 2 : u = 1.; v = 1.; break; - case 3 : u = -1.; v = 1.; break; - default: u = 0.; v = 0.; break; + case 0: + u = -1.; + v = -1.; + break; + case 1: + u = 1.; + v = -1.; + break; + case 2: + u = 1.; + v = 1.; + break; + case 3: + u = -1.; + v = 1.; + break; + default: + u = 0.; + v = 0.; + break; } } - inline int getNumEdges(){ return 4; } + inline int getNumEdges() { return 4; } void getEdge(int num, int &start, int &end) { switch(num) { - case 0 : start = 0; end = 1; break; - case 1 : start = 1; end = 2; break; - case 2 : start = 2; end = 3; break; - case 3 : start = 3; end = 0; break; + case 0: + start = 0; + end = 1; + break; + case 1: + start = 1; + end = 2; + break; + case 2: + start = 2; + end = 3; + break; + case 3: + start = 3; + end = 0; + break; default: start = end = 0; break; } } - inline int getNumGaussPoints(){ return 4; } + inline int getNumGaussPoints() { return 4; } void getGaussPoint(int num, double &u, double &v, double &w, double &weight) { - static double u4[4] = {0.577350269189,-0.577350269189,0.577350269189,-0.577350269189}; - static double v4[4] = {0.577350269189,0.577350269189,-0.577350269189,-0.577350269189}; - static double p4[4] = {1.,1.,1.,1.}; + static double u4[4] = {0.577350269189, -0.577350269189, 0.577350269189, + -0.577350269189}; + static double v4[4] = {0.577350269189, 0.577350269189, -0.577350269189, + -0.577350269189}; + static double p4[4] = {1., 1., 1., 1.}; if(num < 0 || num > 3) return; u = u4[num]; v = v4[num]; @@ -506,33 +614,48 @@ public: void getShapeFunction(int num, double u, double v, double w, double &s) { switch(num) { - case 0 : s = 0.25 * (1.-u) * (1.-v); break; - case 1 : s = 0.25 * (1.+u) * (1.-v); break; - case 2 : s = 0.25 * (1.+u) * (1.+v); break; - case 3 : s = 0.25 * (1.-u) * (1.+v); break; - default : s = 0.; break; + case 0: s = 0.25 * (1. - u) * (1. - v); break; + case 1: s = 0.25 * (1. + u) * (1. - v); break; + case 2: s = 0.25 * (1. + u) * (1. + v); break; + case 3: s = 0.25 * (1. - u) * (1. + v); break; + default: s = 0.; break; } } void getGradShapeFunction(int num, double u, double v, double w, double s[3]) { switch(num) { - case 0 : s[0] = -0.25 * (1.-v); s[1] = -0.25 * (1.-u); s[2] = 0.; break; - case 1 : s[0] = 0.25 * (1.-v); s[1] = -0.25 * (1.+u); s[2] = 0.; break; - case 2 : s[0] = 0.25 * (1.+v); s[1] = 0.25 * (1.+u); s[2] = 0.; break; - case 3 : s[0] = -0.25 * (1.+v); s[1] = 0.25 * (1.-u); s[2] = 0.; break; - default : s[0] = s[1] = s[2] = 0.; break; + case 0: + s[0] = -0.25 * (1. - v); + s[1] = -0.25 * (1. - u); + s[2] = 0.; + break; + case 1: + s[0] = 0.25 * (1. - v); + s[1] = -0.25 * (1. + u); + s[2] = 0.; + break; + case 2: + s[0] = 0.25 * (1. + v); + s[1] = 0.25 * (1. + u); + s[2] = 0.; + break; + case 3: + s[0] = -0.25 * (1. + v); + s[1] = 0.25 * (1. - u); + s[2] = 0.; + break; + default: s[0] = s[1] = s[2] = 0.; break; } } double integrateFlux(double val[]) { - double t1[3] = {_x[1]-_x[0], _y[1]-_y[0], _z[1]-_z[0]}; - double t2[3] = {_x[2]-_x[0], _y[2]-_y[0], _z[2]-_z[0]}; + double t1[3] = {_x[1] - _x[0], _y[1] - _y[0], _z[1] - _z[0]}; + double t2[3] = {_x[2] - _x[0], _y[2] - _y[0], _z[2] - _z[0]}; double n[3]; prodve(t1, t2, n); norme(n); double v[3]; - for(int i = 0; i < 3; i++) - v[i] = integrate(&val[i], 3); + for(int i = 0; i < 3; i++) v[i] = integrate(&val[i], 3); return prosca(n, v); } int isInside(double u, double v, double w) @@ -544,41 +667,86 @@ public: } }; -class tetrahedron : public element{ +class tetrahedron : public element { public: - tetrahedron(double *x, double *y, double *z, int numNodes=0) : element(x, y, z, numNodes) {} - inline int getDimension(){ return 3; } - inline int getNumNodes(){ return 4; } + tetrahedron(double *x, double *y, double *z, int numNodes = 0) + : element(x, y, z, numNodes) + { + } + inline int getDimension() { return 3; } + inline int getNumNodes() { return 4; } void getNode(int num, double &u, double &v, double &w) { switch(num) { - case 0 : u = 0.; v = 0.; w = 0.; break; - case 1 : u = 1.; v = 0.; w = 0.; break; - case 2 : u = 0.; v = 1.; w = 0.; break; - case 3 : u = 0.; v = 0.; w = 1.; break; - default: u = 0.; v = 0.; w = 0.; break; + case 0: + u = 0.; + v = 0.; + w = 0.; + break; + case 1: + u = 1.; + v = 0.; + w = 0.; + break; + case 2: + u = 0.; + v = 1.; + w = 0.; + break; + case 3: + u = 0.; + v = 0.; + w = 1.; + break; + default: + u = 0.; + v = 0.; + w = 0.; + break; } } - inline int getNumEdges(){ return 6; } + inline int getNumEdges() { return 6; } void getEdge(int num, int &start, int &end) { switch(num) { - case 0 : start = 0; end = 1; break; - case 1 : start = 1; end = 2; break; - case 2 : start = 2; end = 0; break; - case 3 : start = 3; end = 0; break; - case 4 : start = 3; end = 2; break; - case 5 : start = 3; end = 1; break; + case 0: + start = 0; + end = 1; + break; + case 1: + start = 1; + end = 2; + break; + case 2: + start = 2; + end = 0; + break; + case 3: + start = 3; + end = 0; + break; + case 4: + start = 3; + end = 2; + break; + case 5: + start = 3; + end = 1; + break; default: start = end = 0; break; } } - inline int getNumGaussPoints(){ return 4; } + inline int getNumGaussPoints() { return 4; } void getGaussPoint(int num, double &u, double &v, double &w, double &weight) { - static double u4[4] = {0.138196601125,0.138196601125,0.138196601125,0.585410196625}; - static double v4[4] = {0.138196601125,0.138196601125,0.585410196625,0.138196601125}; - static double w4[4] = {0.138196601125,0.585410196625,0.138196601125,0.138196601125}; - static double p4[4] = {0.0416666666667,0.0416666666667,0.0416666666667,0.0416666666667}; + static double u4[4] = {0.138196601125, 0.138196601125, 0.138196601125, + 0.585410196625}; + static double v4[4] = {0.138196601125, 0.138196601125, 0.585410196625, + 0.138196601125}; + static double w4[4] = {0.138196601125, 0.585410196625, 0.138196601125, + 0.138196601125}; + static double p4[4] = {0.0416666666667, 0.0416666666667, 0.0416666666667, + 0.0416666666667}; if(num < 0 || num > 3) return; u = u4[num]; v = v4[num]; @@ -588,21 +756,37 @@ public: void getShapeFunction(int num, double u, double v, double w, double &s) { switch(num) { - case 0 : s = 1.-u-v-w; break; - case 1 : s = u ; break; - case 2 : s = v ; break; - case 3 : s = w; break; - default : s = 0.; break; + case 0: s = 1. - u - v - w; break; + case 1: s = u; break; + case 2: s = v; break; + case 3: s = w; break; + default: s = 0.; break; } } void getGradShapeFunction(int num, double u, double v, double w, double s[3]) { switch(num) { - case 0 : s[0] = -1.; s[1] = -1.; s[2] = -1.; break; - case 1 : s[0] = 1.; s[1] = 0.; s[2] = 0.; break; - case 2 : s[0] = 0.; s[1] = 1.; s[2] = 0.; break; - case 3 : s[0] = 0.; s[1] = 0.; s[2] = 1.; break; - default : s[0] = s[1] = s[2] = 0.; break; + case 0: + s[0] = -1.; + s[1] = -1.; + s[2] = -1.; + break; + case 1: + s[0] = 1.; + s[1] = 0.; + s[2] = 0.; + break; + case 2: + s[0] = 0.; + s[1] = 1.; + s[2] = 0.; + break; + case 3: + s[0] = 0.; + s[1] = 0.; + s[2] = 1.; + break; + default: s[0] = s[1] = s[2] = 0.; break; } } void xyz2uvw(double xyz[3], double uvw[3]) @@ -631,55 +815,130 @@ public: } }; -class hexahedron : public element{ +class hexahedron : public element { public: - hexahedron(double *x, double *y, double *z, int numNodes=0) : element(x, y, z, numNodes) {} - inline int getDimension(){ return 3; } - inline int getNumNodes(){ return 8; } + hexahedron(double *x, double *y, double *z, int numNodes = 0) + : element(x, y, z, numNodes) + { + } + inline int getDimension() { return 3; } + inline int getNumNodes() { return 8; } void getNode(int num, double &u, double &v, double &w) { switch(num) { - case 0 : u = -1.; v = -1.; w = -1.; break; - case 1 : u = 1.; v = -1.; w = -1.; break; - case 2 : u = 1.; v = 1.; w = -1.; break; - case 3 : u = -1.; v = 1.; w = -1.; break; - case 4 : u = -1.; v = -1.; w = 1.; break; - case 5 : u = 1.; v = -1.; w = 1.; break; - case 6 : u = 1.; v = 1.; w = 1.; break; - case 7 : u = -1.; v = 1.; w = 1.; break; - default: u = 0.; v = 0.; w = 0.; break; - } - } - inline int getNumEdges(){ return 12; } + case 0: + u = -1.; + v = -1.; + w = -1.; + break; + case 1: + u = 1.; + v = -1.; + w = -1.; + break; + case 2: + u = 1.; + v = 1.; + w = -1.; + break; + case 3: + u = -1.; + v = 1.; + w = -1.; + break; + case 4: + u = -1.; + v = -1.; + w = 1.; + break; + case 5: + u = 1.; + v = -1.; + w = 1.; + break; + case 6: + u = 1.; + v = 1.; + w = 1.; + break; + case 7: + u = -1.; + v = 1.; + w = 1.; + break; + default: + u = 0.; + v = 0.; + w = 0.; + break; + } + } + inline int getNumEdges() { return 12; } void getEdge(int num, int &start, int &end) { switch(num) { - case 0 : start = 0; end = 1; break; - case 1 : start = 0; end = 3; break; - case 2 : start = 0; end = 4; break; - case 3 : start = 1; end = 2; break; - case 4 : start = 1; end = 5; break; - case 5 : start = 2; end = 3; break; - case 6 : start = 2; end = 6; break; - case 7 : start = 3; end = 7; break; - case 8 : start = 4; end = 5; break; - case 9 : start = 4; end = 7; break; - case 10: start = 5; end = 6; break; - case 11: start = 6; end = 7; break; + case 0: + start = 0; + end = 1; + break; + case 1: + start = 0; + end = 3; + break; + case 2: + start = 0; + end = 4; + break; + case 3: + start = 1; + end = 2; + break; + case 4: + start = 1; + end = 5; + break; + case 5: + start = 2; + end = 3; + break; + case 6: + start = 2; + end = 6; + break; + case 7: + start = 3; + end = 7; + break; + case 8: + start = 4; + end = 5; + break; + case 9: + start = 4; + end = 7; + break; + case 10: + start = 5; + end = 6; + break; + case 11: + start = 6; + end = 7; + break; default: start = end = 0; break; } } - inline int getNumGaussPoints(){ return 6; } + inline int getNumGaussPoints() { return 6; } void getGaussPoint(int num, double &u, double &v, double &w, double &weight) { - static double u6[6] = { 0.40824826, 0.40824826, -0.40824826, - -0.40824826, -0.81649658, 0.81649658}; - static double v6[6] = { 0.70710678, -0.70710678, 0.70710678, - -0.70710678, 0., 0.}; - static double w6[6] = {-0.57735027, -0.57735027, 0.57735027, - 0.57735027, -0.57735027, 0.57735027}; - static double p6[6] = { 1.3333333333, 1.3333333333, 1.3333333333, - 1.3333333333, 1.3333333333, 1.3333333333}; + static double u6[6] = {0.40824826, 0.40824826, -0.40824826, + -0.40824826, -0.81649658, 0.81649658}; + static double v6[6] = {0.70710678, -0.70710678, 0.70710678, + -0.70710678, 0., 0.}; + static double w6[6] = {-0.57735027, -0.57735027, 0.57735027, + 0.57735027, -0.57735027, 0.57735027}; + static double p6[6] = {1.3333333333, 1.3333333333, 1.3333333333, + 1.3333333333, 1.3333333333, 1.3333333333}; if(num < 0 || num > 5) return; u = u6[num]; v = v6[num]; @@ -689,45 +948,61 @@ public: void getShapeFunction(int num, double u, double v, double w, double &s) { switch(num) { - case 0 : s = (1.-u) * (1.-v) * (1.-w) * 0.125; break; - case 1 : s = (1.+u) * (1.-v) * (1.-w) * 0.125; break; - case 2 : s = (1.+u) * (1.+v) * (1.-w) * 0.125; break; - case 3 : s = (1.-u) * (1.+v) * (1.-w) * 0.125; break; - case 4 : s = (1.-u) * (1.-v) * (1.+w) * 0.125; break; - case 5 : s = (1.+u) * (1.-v) * (1.+w) * 0.125; break; - case 6 : s = (1.+u) * (1.+v) * (1.+w) * 0.125; break; - case 7 : s = (1.-u) * (1.+v) * (1.+w) * 0.125; break; - default : s = 0.; break; + case 0: s = (1. - u) * (1. - v) * (1. - w) * 0.125; break; + case 1: s = (1. + u) * (1. - v) * (1. - w) * 0.125; break; + case 2: s = (1. + u) * (1. + v) * (1. - w) * 0.125; break; + case 3: s = (1. - u) * (1. + v) * (1. - w) * 0.125; break; + case 4: s = (1. - u) * (1. - v) * (1. + w) * 0.125; break; + case 5: s = (1. + u) * (1. - v) * (1. + w) * 0.125; break; + case 6: s = (1. + u) * (1. + v) * (1. + w) * 0.125; break; + case 7: s = (1. - u) * (1. + v) * (1. + w) * 0.125; break; + default: s = 0.; break; } } void getGradShapeFunction(int num, double u, double v, double w, double s[3]) { switch(num) { - case 0 : s[0] = -0.125 * (1.-v) * (1.-w); - s[1] = -0.125 * (1.-u) * (1.-w); - s[2] = -0.125 * (1.-u) * (1.-v); break; - case 1 : s[0] = 0.125 * (1.-v) * (1.-w); - s[1] = -0.125 * (1.+u) * (1.-w); - s[2] = -0.125 * (1.+u) * (1.-v); break; - case 2 : s[0] = 0.125 * (1.+v) * (1.-w); - s[1] = 0.125 * (1.+u) * (1.-w); - s[2] = -0.125 * (1.+u) * (1.+v); break; - case 3 : s[0] = -0.125 * (1.+v) * (1.-w); - s[1] = 0.125 * (1.-u) * (1.-w); - s[2] = -0.125 * (1.-u) * (1.+v); break; - case 4 : s[0] = -0.125 * (1.-v) * (1.+w); - s[1] = -0.125 * (1.-u) * (1.+w); - s[2] = 0.125 * (1.-u) * (1.-v); break; - case 5 : s[0] = 0.125 * (1.-v) * (1.+w); - s[1] = -0.125 * (1.+u) * (1.+w); - s[2] = 0.125 * (1.+u) * (1.-v); break; - case 6 : s[0] = 0.125 * (1.+v) * (1.+w); - s[1] = 0.125 * (1.+u) * (1.+w); - s[2] = 0.125 * (1.+u) * (1.+v); break; - case 7 : s[0] = -0.125 * (1.+v) * (1.+w); - s[1] = 0.125 * (1.-u) * (1.+w); - s[2] = 0.125 * (1.-u) * (1.+v); break; - default : s[0] = s[1] = s[2] = 0.; break; + case 0: + s[0] = -0.125 * (1. - v) * (1. - w); + s[1] = -0.125 * (1. - u) * (1. - w); + s[2] = -0.125 * (1. - u) * (1. - v); + break; + case 1: + s[0] = 0.125 * (1. - v) * (1. - w); + s[1] = -0.125 * (1. + u) * (1. - w); + s[2] = -0.125 * (1. + u) * (1. - v); + break; + case 2: + s[0] = 0.125 * (1. + v) * (1. - w); + s[1] = 0.125 * (1. + u) * (1. - w); + s[2] = -0.125 * (1. + u) * (1. + v); + break; + case 3: + s[0] = -0.125 * (1. + v) * (1. - w); + s[1] = 0.125 * (1. - u) * (1. - w); + s[2] = -0.125 * (1. - u) * (1. + v); + break; + case 4: + s[0] = -0.125 * (1. - v) * (1. + w); + s[1] = -0.125 * (1. - u) * (1. + w); + s[2] = 0.125 * (1. - u) * (1. - v); + break; + case 5: + s[0] = 0.125 * (1. - v) * (1. + w); + s[1] = -0.125 * (1. + u) * (1. + w); + s[2] = 0.125 * (1. + u) * (1. - v); + break; + case 6: + s[0] = 0.125 * (1. + v) * (1. + w); + s[1] = 0.125 * (1. + u) * (1. + w); + s[2] = 0.125 * (1. + u) * (1. + v); + break; + case 7: + s[0] = -0.125 * (1. + v) * (1. + w); + s[1] = 0.125 * (1. - u) * (1. + w); + s[2] = 0.125 * (1. - u) * (1. + v); + break; + default: s[0] = s[1] = s[2] = 0.; break; } } int isInside(double u, double v, double w) @@ -739,50 +1014,112 @@ public: } }; -class prism : public element{ +class prism : public element { public: - prism(double *x, double *y, double *z, int numNodes=0) : element(x, y, z, numNodes) {} - inline int getDimension(){ return 3; } - inline int getNumNodes(){ return 6; } + prism(double *x, double *y, double *z, int numNodes = 0) + : element(x, y, z, numNodes) + { + } + inline int getDimension() { return 3; } + inline int getNumNodes() { return 6; } void getNode(int num, double &u, double &v, double &w) { switch(num) { - case 0 : u = 0.; v = 0.; w = -1.; break; - case 1 : u = 1.; v = 0.; w = -1.; break; - case 2 : u = 0.; v = 1.; w = -1.; break; - case 3 : u = 0.; v = 0.; w = 1.; break; - case 4 : u = 1.; v = 0.; w = 1.; break; - case 5 : u = 0.; v = 1.; w = 1.; break; - default: u = 0.; v = 0.; w = 0.; break; + case 0: + u = 0.; + v = 0.; + w = -1.; + break; + case 1: + u = 1.; + v = 0.; + w = -1.; + break; + case 2: + u = 0.; + v = 1.; + w = -1.; + break; + case 3: + u = 0.; + v = 0.; + w = 1.; + break; + case 4: + u = 1.; + v = 0.; + w = 1.; + break; + case 5: + u = 0.; + v = 1.; + w = 1.; + break; + default: + u = 0.; + v = 0.; + w = 0.; + break; } } - inline int getNumEdges(){ return 9; } + inline int getNumEdges() { return 9; } void getEdge(int num, int &start, int &end) { switch(num) { - case 0 : start = 0; end = 1; break; - case 1 : start = 0; end = 2; break; - case 2 : start = 0; end = 3; break; - case 3 : start = 1; end = 2; break; - case 4 : start = 1; end = 4; break; - case 5 : start = 2; end = 5; break; - case 6 : start = 3; end = 4; break; - case 7 : start = 3; end = 5; break; - case 8 : start = 4; end = 5; break; + case 0: + start = 0; + end = 1; + break; + case 1: + start = 0; + end = 2; + break; + case 2: + start = 0; + end = 3; + break; + case 3: + start = 1; + end = 2; + break; + case 4: + start = 1; + end = 4; + break; + case 5: + start = 2; + end = 5; + break; + case 6: + start = 3; + end = 4; + break; + case 7: + start = 3; + end = 5; + break; + case 8: + start = 4; + end = 5; + break; default: start = end = 0; break; } } - inline int getNumGaussPoints(){ return 6; } + inline int getNumGaussPoints() { return 6; } void getGaussPoint(int num, double &u, double &v, double &w, double &weight) { - static double u6[6] = {0.166666666666666, 0.333333333333333, 0.166666666666666, - 0.166666666666666, 0.333333333333333, 0.166666666666666}; - static double v6[6] = {0.166666666666666, 0.166666666666666, 0.333333333333333, - 0.166666666666666, 0.166666666666666, 0.333333333333333}; + static double u6[6] = {0.166666666666666, 0.333333333333333, + 0.166666666666666, 0.166666666666666, + 0.333333333333333, 0.166666666666666}; + static double v6[6] = {0.166666666666666, 0.166666666666666, + 0.333333333333333, 0.166666666666666, + 0.166666666666666, 0.333333333333333}; static double w6[6] = {-0.577350269189, -0.577350269189, -0.577350269189, 0.577350269189, 0.577350269189, 0.577350269189}; - static double p6[6] = {0.166666666666666,0.166666666666666,0.166666666666666, - 0.166666666666666,0.166666666666666,0.166666666666666,}; + static double p6[6] = { + 0.166666666666666, 0.166666666666666, 0.166666666666666, + 0.166666666666666, 0.166666666666666, 0.166666666666666, + }; if(num < 0 || num > 5) return; u = u6[num]; v = v6[num]; @@ -792,97 +1129,161 @@ public: void getShapeFunction(int num, double u, double v, double w, double &s) { switch(num) { - case 0 : s = (1.-u-v) * (1.-w) * 0.5; break; - case 1 : s = u * (1.-w) * 0.5; break; - case 2 : s = v * (1.-w) * 0.5; break; - case 3 : s = (1.-u-v) * (1.+w) * 0.5; break; - case 4 : s = u * (1.+w) * 0.5; break; - case 5 : s = v * (1.+w) * 0.5; break; - default : s = 0.; break; + case 0: s = (1. - u - v) * (1. - w) * 0.5; break; + case 1: s = u * (1. - w) * 0.5; break; + case 2: s = v * (1. - w) * 0.5; break; + case 3: s = (1. - u - v) * (1. + w) * 0.5; break; + case 4: s = u * (1. + w) * 0.5; break; + case 5: s = v * (1. + w) * 0.5; break; + default: s = 0.; break; } } void getGradShapeFunction(int num, double u, double v, double w, double s[3]) { switch(num) { - case 0 : s[0] = -0.5 * (1.-w) ; - s[1] = -0.5 * (1.-w) ; - s[2] = -0.5 * (1.-u-v) ; break ; - case 1 : s[0] = 0.5 * (1.-w) ; - s[1] = 0. ; - s[2] = -0.5 * u ; break ; - case 2 : s[0] = 0. ; - s[1] = 0.5 * (1.-w) ; - s[2] = -0.5 * v ; break ; - case 3 : s[0] = -0.5 * (1.+w) ; - s[1] = -0.5 * (1.+w) ; - s[2] = 0.5 * (1.-u-v) ; break ; - case 4 : s[0] = 0.5 * (1.+w) ; - s[1] = 0. ; - s[2] = 0.5 * u ; break ; - case 5 : s[0] = 0. ; - s[1] = 0.5 * (1.+w) ; - s[2] = 0.5 * v ; break ; - default : s[0] = s[1] = s[2] = 0.; break; + case 0: + s[0] = -0.5 * (1. - w); + s[1] = -0.5 * (1. - w); + s[2] = -0.5 * (1. - u - v); + break; + case 1: + s[0] = 0.5 * (1. - w); + s[1] = 0.; + s[2] = -0.5 * u; + break; + case 2: + s[0] = 0.; + s[1] = 0.5 * (1. - w); + s[2] = -0.5 * v; + break; + case 3: + s[0] = -0.5 * (1. + w); + s[1] = -0.5 * (1. + w); + s[2] = 0.5 * (1. - u - v); + break; + case 4: + s[0] = 0.5 * (1. + w); + s[1] = 0.; + s[2] = 0.5 * u; + break; + case 5: + s[0] = 0.; + s[1] = 0.5 * (1. + w); + s[2] = 0.5 * v; + break; + default: s[0] = s[1] = s[2] = 0.; break; } } int isInside(double u, double v, double w) { - if(w > (1. + TOL) || w < -(1. + TOL) || u < (-TOL) || v < (-TOL) || u > ((1. + TOL) - v)) + if(w > (1. + TOL) || w < -(1. + TOL) || u < (-TOL) || v < (-TOL) || + u > ((1. + TOL) - v)) return 0; return 1; } }; -class pyramid : public element{ +class pyramid : public element { public: - pyramid(double *x, double *y, double *z, int numNodes=0) : element(x, y, z, numNodes) {} - inline int getDimension(){ return 3; } - inline int getNumNodes(){ return 5; } + pyramid(double *x, double *y, double *z, int numNodes = 0) + : element(x, y, z, numNodes) + { + } + inline int getDimension() { return 3; } + inline int getNumNodes() { return 5; } void getNode(int num, double &u, double &v, double &w) { switch(num) { - case 0 : u = -1.; v = -1.; w = 0.; break; - case 1 : u = 1.; v = -1.; w = 0.; break; - case 2 : u = 1.; v = 1.; w = 0.; break; - case 3 : u = -1.; v = 1.; w = 0.; break; - case 4 : u = 0.; v = 0.; w = 1.; break; - default: u = 0.; v = 0.; w = 0.; break; + case 0: + u = -1.; + v = -1.; + w = 0.; + break; + case 1: + u = 1.; + v = -1.; + w = 0.; + break; + case 2: + u = 1.; + v = 1.; + w = 0.; + break; + case 3: + u = -1.; + v = 1.; + w = 0.; + break; + case 4: + u = 0.; + v = 0.; + w = 1.; + break; + default: + u = 0.; + v = 0.; + w = 0.; + break; } } - inline int getNumEdges(){ return 8; } + inline int getNumEdges() { return 8; } void getEdge(int num, int &start, int &end) { switch(num) { - case 0 : start = 0; end = 1; break; - case 1 : start = 0; end = 3; break; - case 2 : start = 0; end = 4; break; - case 3 : start = 1; end = 2; break; - case 4 : start = 1; end = 4; break; - case 5 : start = 2; end = 3; break; - case 6 : start = 2; end = 4; break; - case 7 : start = 3; end = 4; break; + case 0: + start = 0; + end = 1; + break; + case 1: + start = 0; + end = 3; + break; + case 2: + start = 0; + end = 4; + break; + case 3: + start = 1; + end = 2; + break; + case 4: + start = 1; + end = 4; + break; + case 5: + start = 2; + end = 3; + break; + case 6: + start = 2; + end = 4; + break; + case 7: + start = 3; + end = 4; + break; default: start = end = 0; break; } } - inline int getNumGaussPoints(){ return 8; } + inline int getNumGaussPoints() { return 8; } void getGaussPoint(int num, double &u, double &v, double &w, double &weight) { - static double u8[8] = {0.2631840555694285,-0.2631840555694285, - 0.2631840555694285,-0.2631840555694285, - 0.5066163033492386,-0.5066163033492386, - 0.5066163033492386,-0.5066163033492386}; - static double v8[8] = {0.2631840555694285,0.2631840555694285, - -0.2631840555694285,-0.2631840555694285, - 0.5066163033492386,0.5066163033492386, - -0.5066163033492386,-0.5066163033492386}; - static double w8[8] = {0.544151844011225,0.544151844011225, - 0.544151844011225,0.544151844011225, - 0.122514822655441,0.122514822655441, - 0.122514822655441,0.122514822655441}; - static double p8[8] = {0.100785882079825,0.100785882079825, - 0.100785882079825,0.100785882079825, - 0.232547451253508,0.232547451253508, - 0.232547451253508,0.232547451253508}; + static double u8[8] = {0.2631840555694285, -0.2631840555694285, + 0.2631840555694285, -0.2631840555694285, + 0.5066163033492386, -0.5066163033492386, + 0.5066163033492386, -0.5066163033492386}; + static double v8[8] = {0.2631840555694285, 0.2631840555694285, + -0.2631840555694285, -0.2631840555694285, + 0.5066163033492386, 0.5066163033492386, + -0.5066163033492386, -0.5066163033492386}; + static double w8[8] = {0.544151844011225, 0.544151844011225, + 0.544151844011225, 0.544151844011225, + 0.122514822655441, 0.122514822655441, + 0.122514822655441, 0.122514822655441}; + static double p8[8] = {0.100785882079825, 0.100785882079825, + 0.100785882079825, 0.100785882079825, + 0.232547451253508, 0.232547451253508, + 0.232547451253508, 0.232547451253508}; if(num < 0 || num > 7) return; u = u8[num]; v = v8[num]; @@ -893,57 +1294,83 @@ public: { double r; - if(w != 1. && num != 4) r = u*v*w / (1.-w); - else r = 0.; + if(w != 1. && num != 4) + r = u * v * w / (1. - w); + else + r = 0.; switch(num) { - case 0 : s = 0.25 * ((1.-u) * (1.-v) - w + r); break; - case 1 : s = 0.25 * ((1.+u) * (1.-v) - w - r); break; - case 2 : s = 0.25 * ((1.+u) * (1.+v) - w + r); break; - case 3 : s = 0.25 * ((1.-u) * (1.+v) - w - r); break; - case 4 : s = w ; break; - default : s = 0. ; break; + case 0: s = 0.25 * ((1. - u) * (1. - v) - w + r); break; + case 1: s = 0.25 * ((1. + u) * (1. - v) - w - r); break; + case 2: s = 0.25 * ((1. + u) * (1. + v) - w + r); break; + case 3: s = 0.25 * ((1. - u) * (1. + v) - w - r); break; + case 4: s = w; break; + default: s = 0.; break; } } void getGradShapeFunction(int num, double u, double v, double w, double s[3]) { if(w == 1.) { switch(num) { - case 0 : s[0] = -0.25 ; - s[1] = -0.25 ; - s[2] = -0.25 ; break ; - case 1 : s[0] = 0.25 ; - s[1] = -0.25 ; - s[2] = -0.25 ; break ; - case 2 : s[0] = 0.25 ; - s[1] = 0.25 ; - s[2] = -0.25 ; break ; - case 3 : s[0] = -0.25 ; - s[1] = 0.25 ; - s[2] = -0.25 ; break ; - case 4 : s[0] = 0. ; - s[1] = 0. ; - s[2] = 1. ; break ; - default : s[0] = s[1] = s[2] = 0.; break; + case 0: + s[0] = -0.25; + s[1] = -0.25; + s[2] = -0.25; + break; + case 1: + s[0] = 0.25; + s[1] = -0.25; + s[2] = -0.25; + break; + case 2: + s[0] = 0.25; + s[1] = 0.25; + s[2] = -0.25; + break; + case 3: + s[0] = -0.25; + s[1] = 0.25; + s[2] = -0.25; + break; + case 4: + s[0] = 0.; + s[1] = 0.; + s[2] = 1.; + break; + default: s[0] = s[1] = s[2] = 0.; break; } } - else{ + else { switch(num) { - case 0 : s[0] = 0.25 * ( -(1.-v) + v*w/(1.-w) ) ; - s[1] = 0.25 * ( -(1.-u) + u*w/(1.-w) ) ; - s[2] = 0.25 * ( -1. + u*v/(1.-w) + u*v*w/std::pow(1.-w, 2) ) ; break ; - case 1 : s[0] = 0.25 * ( (1.-v) - v*w/(1.-w) ) ; - s[1] = 0.25 * ( -(1.+u) - u*w/(1.-w) ) ; - s[2] = 0.25 * ( -1. - u*v/(1.-w) - u*v*w/std::pow(1.-w, 2) ) ; break ; - case 2 : s[0] = 0.25 * ( (1.+v) + v*w/(1.-w) ) ; - s[1] = 0.25 * ( (1.+u) + u*w/(1.-w) ) ; - s[2] = 0.25 * ( -1. + u*v/(1.-w) + u*v*w/std::pow(1.-w, 2) ) ; break ; - case 3 : s[0] = 0.25 * ( -(1.+v) - v*w/(1.-w) ) ; - s[1] = 0.25 * ( (1.-u) - u*w/(1.-w) ) ; - s[2] = 0.25 * ( -1. - u*v/(1.-w) - u*v*w/std::pow(1.-w, 2) ) ; break ; - case 4 : s[0] = 0. ; - s[1] = 0. ; - s[2] = 1. ; break ; - default : s[0] = s[1] = s[2] = 0.; break; + case 0: + s[0] = 0.25 * (-(1. - v) + v * w / (1. - w)); + s[1] = 0.25 * (-(1. - u) + u * w / (1. - w)); + s[2] = + 0.25 * (-1. + u * v / (1. - w) + u * v * w / std::pow(1. - w, 2)); + break; + case 1: + s[0] = 0.25 * ((1. - v) - v * w / (1. - w)); + s[1] = 0.25 * (-(1. + u) - u * w / (1. - w)); + s[2] = + 0.25 * (-1. - u * v / (1. - w) - u * v * w / std::pow(1. - w, 2)); + break; + case 2: + s[0] = 0.25 * ((1. + v) + v * w / (1. - w)); + s[1] = 0.25 * ((1. + u) + u * w / (1. - w)); + s[2] = + 0.25 * (-1. + u * v / (1. - w) + u * v * w / std::pow(1. - w, 2)); + break; + case 3: + s[0] = 0.25 * (-(1. + v) - v * w / (1. - w)); + s[1] = 0.25 * ((1. - u) - u * w / (1. - w)); + s[2] = + 0.25 * (-1. - u * v / (1. - w) - u * v * w / std::pow(1. - w, 2)); + break; + case 4: + s[0] = 0.; + s[1] = 0.; + s[2] = 1.; + break; + default: s[0] = s[1] = s[2] = 0.; break; } } } @@ -956,25 +1383,29 @@ public: } }; -class elementFactory{ - public: - element* create(int numNodes, int dimension, double *x, double *y, double *z, - bool copy=false) +class elementFactory { +public: + element *create(int numNodes, int dimension, double *x, double *y, double *z, + bool copy = false) { - switch(dimension){ + switch(dimension) { case 0: return new point(x, y, z, copy ? numNodes : 0); case 1: return new line(x, y, z, copy ? numNodes : 0); case 2: - if(numNodes == 4) return new quadrangle(x, y, z, copy ? numNodes : 0); - else return new triangle(x, y, z, copy ? numNodes : 0); + if(numNodes == 4) + return new quadrangle(x, y, z, copy ? numNodes : 0); + else + return new triangle(x, y, z, copy ? numNodes : 0); case 3: - if(numNodes == 8) return new hexahedron(x, y, z, copy ? numNodes : 0); - else if(numNodes == 6) return new prism(x, y, z, copy ? numNodes : 0); - else if(numNodes == 5) return new pyramid(x, y, z, copy ? numNodes : 0); - else return new tetrahedron(x, y, z, copy ? numNodes : 0); - default: - Msg::Error("Unknown type of element in factory"); - return NULL; + if(numNodes == 8) + return new hexahedron(x, y, z, copy ? numNodes : 0); + else if(numNodes == 6) + return new prism(x, y, z, copy ? numNodes : 0); + else if(numNodes == 5) + return new pyramid(x, y, z, copy ? numNodes : 0); + else + return new tetrahedron(x, y, z, copy ? numNodes : 0); + default: Msg::Error("Unknown type of element in factory"); return NULL; } } }; diff --git a/Solver/FuncGradDisc.h b/Solver/FuncGradDisc.h index e9e44ceb63126c8e87fa4400238c168cbd0f2f9b..f31bdbbbfb7ca86a1b3610ec75103f41b04ff7e9 100644 --- a/Solver/FuncGradDisc.h +++ b/Solver/FuncGradDisc.h @@ -16,72 +16,68 @@ template <class scalar> class simpleFunction; - -class FuncGradDisc : public simpleFunctionOnElement<double> { - private : +class FuncGradDisc : public simpleFunctionOnElement<double> { +private: gLevelset *_ls; - GModel * _pModel; + GModel *_pModel; - public : - FuncGradDisc(gLevelset *ls, GModel *pModel){ +public: + FuncGradDisc(gLevelset *ls, GModel *pModel) + { _ls = ls; _pModel = pModel; } - double operator () (double x, double y, double z) const { - + double operator()(double x, double y, double z) const + { // --- F2 --- // MElement *e = getElement(); SPoint3 p(x, y, z); - if (e->getParent()) e = e->getParent(); + if(e->getParent()) e = e->getParent(); double xyz[3] = {x, y, z}; double uvw[3]; e->xyz2uvw(xyz, uvw); double val[30]; e->getShapeFunctions(uvw[0], uvw[1], uvw[2], val); double f = 0; - for (int i = 0; i < e->getNumShapeFunctions(); i++){ + for(int i = 0; i < e->getNumShapeFunctions(); i++) { MVertex *v = e->getShapeFunctionNode(i); - //std::cout<<"val[i] :" << val[i] << "\n"; - //std::cout<<"ls(i) :" << (*_ls)(v->x(),v->y(),v->z()) << "\n"; + // std::cout<<"val[i] :" << val[i] << "\n"; + // std::cout<<"ls(i) :" << (*_ls)(v->x(),v->y(),v->z()) << "\n"; f = f + std::abs((*_ls)(v->x(), v->y(), v->z())) * val[i]; } f = f - std::abs((*_ls)(x, y, z)); - //std::cout<<"val f :" << f << "\n"; + // std::cout<<"val f :" << f << "\n"; return f; // --- F1 --- // - -// SPoint3 p(x,y,z); -// if (e->getParent()) e = e->getParent(); -// double xyz[3] = {x,y,z}; -// double uvw[3]; -// e->xyz2uvw(xyz,uvw); -// double val[30]; -// e->getShapeFunctions(uvw[0], uvw[1], uvw[2], val); -// double f = 0; -// for (int i = 0; i < e->getNumShapeFunctions(); i++) -// { -// MVertex *v = e-<getShapeFunctionNode(i); -// f = f + (*_ls)(v->x(), v->y(), v->z()) * val[i]; -// } -// f = std::abs(f); -// return f; - + // SPoint3 p(x,y,z); + // if (e->getParent()) e = e->getParent(); + // double xyz[3] = {x,y,z}; + // double uvw[3]; + // e->xyz2uvw(xyz,uvw); + // double val[30]; + // e->getShapeFunctions(uvw[0], uvw[1], uvw[2], val); + // double f = 0; + // for (int i = 0; i < e->getNumShapeFunctions(); i++) + // { + // MVertex *v = e-<getShapeFunctionNode(i); + // f = f + (*_ls)(v->x(), v->y(), v->z()) * val[i]; + // } + // f = std::abs(f); + // return f; } - - - void gradient (double x, double y, double z, - double &dfdx, double &dfdy, double &dfdz) const { - + void gradient(double x, double y, double z, double &dfdx, double &dfdy, + double &dfdz) const + { // ---- F2 ---- // - MElement *e=getElement(); + MElement *e = getElement(); SPoint3 p(x, y, z); - if (e->getParent()) e = e->getParent(); + if(e->getParent()) e = e->getParent(); double xyz[3] = {x, y, z}; double uvw[3]; e->xyz2uvw(xyz, uvw); @@ -100,91 +96,101 @@ class FuncGradDisc : public simpleFunctionOnElement<double> { dfdy = 0; dfdz = 0; - if ((*_ls)(x, y, z) > 0) { - for (int i = 0; i < e->getNumShapeFunctions(); i++) { - dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; - dNdy = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + invjac[1][2] * gradsuvw[i][2]; - dNdz = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * gradsuvw[i][2]; + if((*_ls)(x, y, z) > 0) { + for(int i = 0; i < e->getNumShapeFunctions(); i++) { + dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + + invjac[0][2] * gradsuvw[i][2]; + dNdy = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + + invjac[1][2] * gradsuvw[i][2]; + dNdz = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + + invjac[2][2] * gradsuvw[i][2]; MVertex *v = e->getShapeFunctionNode(i); - dfdx = dfdx + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdx ; + dfdx = dfdx + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdx; dfdx = dfdx - (*_ls)(v->x(), v->y(), v->z()) * dNdx; - dfdy = dfdy + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdy ; + dfdy = dfdy + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdy; dfdy = dfdy - (*_ls)(v->x(), v->y(), v->z()) * dNdy; - dfdz = dfdz + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdz ; + dfdz = dfdz + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdz; dfdz = dfdz - (*_ls)(v->x(), v->y(), v->z()) * dNdz; } } - else{ - for (int i = 0; i < e->getNumShapeFunctions(); i++) { - dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; - dNdy = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + invjac[1][2] * gradsuvw[i][2]; - dNdz = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * gradsuvw[i][2]; + else { + for(int i = 0; i < e->getNumShapeFunctions(); i++) { + dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + + invjac[0][2] * gradsuvw[i][2]; + dNdy = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + + invjac[1][2] * gradsuvw[i][2]; + dNdz = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + + invjac[2][2] * gradsuvw[i][2]; MVertex *v = e->getShapeFunctionNode(i); - dfdx = dfdx + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdx ; + dfdx = dfdx + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdx; dfdx = dfdx + (*_ls)(v->x(), v->y(), v->z()) * dNdx; - dfdy = dfdy + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdy ; + dfdy = dfdy + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdy; dfdy = dfdy + (*_ls)(v->x(), v->y(), v->z()) * dNdy; - dfdz = dfdz + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdz ; + dfdz = dfdz + std::abs((*_ls)(v->x(), v->y(), v->z())) * dNdz; dfdz = dfdz + (*_ls)(v->x(), v->y(), v->z()) * dNdz; } } } - - // ---- F1 ------ // - -// -// SPoint3 p(x,y,z); -// if (e->getParent()) e = e->getParent(); -// double xyz[3] = {x,y,z}; -// double uvw[3]; -// e->xyz2uvw(xyz,uvw); -// double gradsuvw[256][3]; -// e->getGradShapeFunctions(uvw[0],uvw[1],uvw[2],gradsuvw); -// -// double jac[3][3]; -// double invjac[3][3]; -// double dNdx; -// double dNdy; -// double dNdz; -// const double detJ = e->getJacobian(uvw[0], uvw[1], uvw[2], jac); -// inv3x3(jac, invjac); -// -// dfdx = 0; -// dfdy = 0; -// dfdz = 0; -// -// if ((*_ls)(x,y,z)>0) -// { -// for (int i = 0; i < e->getNumShapeFunctions(); i++) -// { -// dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; -// dNdy = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + invjac[1][2] * gradsuvw[i][2]; -// dNdz = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * gradsuvw[i][2]; -// -// MVertex *v = e->getShapeFunctionNode(i); -// dfdx = dfdx + (*_ls)(v->x(), v->y(), v->z()) * dNdx; -// dfdy = dfdy + (*_ls)(v->x(), v->y(), v->z()) * dNdy; -// dfdz = dfdz + (*_ls)(v->x(), v->y(), v->z()) * dNdz; -// } -// }else -// { -// for (int i = 0; i < e->getNumShapeFunctions(); i++) -// { -// dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; -// dNdy = invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + invjac[1][2] * gradsuvw[i][2]; -// dNdz = invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * gradsuvw[i][2]; -// -// MVertex *v = e->getShapeFunctionNode(i); -// dfdx = dfdx - (*_ls)(v->x(), v->y(), v->z()) * dNdx; -// dfdy = dfdy - (*_ls)(v->x(), v->y(), v->z()) * dNdy; -// dfdz = dfdz - (*_ls)(v->x(), v->y(), v->z()) * dNdz; -// } -// } -// } - + // ---- F1 ------ // + + // + // SPoint3 p(x,y,z); + // if (e->getParent()) e = e->getParent(); + // double xyz[3] = {x,y,z}; + // double uvw[3]; + // e->xyz2uvw(xyz,uvw); + // double gradsuvw[256][3]; + // e->getGradShapeFunctions(uvw[0],uvw[1],uvw[2],gradsuvw); + // + // double jac[3][3]; + // double invjac[3][3]; + // double dNdx; + // double dNdy; + // double dNdz; + // const double detJ = e->getJacobian(uvw[0], uvw[1], uvw[2], jac); + // inv3x3(jac, invjac); + // + // dfdx = 0; + // dfdy = 0; + // dfdz = 0; + // + // if ((*_ls)(x,y,z)>0) + // { + // for (int i = 0; i < e->getNumShapeFunctions(); i++) + // { + // dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * + // gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; dNdy = + // invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + + // invjac[1][2] * gradsuvw[i][2]; dNdz = invjac[2][0] * + // gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * + // gradsuvw[i][2]; + // + // MVertex *v = e->getShapeFunctionNode(i); + // dfdx = dfdx + (*_ls)(v->x(), v->y(), v->z()) * dNdx; + // dfdy = dfdy + (*_ls)(v->x(), v->y(), v->z()) * dNdy; + // dfdz = dfdz + (*_ls)(v->x(), v->y(), v->z()) * dNdz; + // } + // }else + // { + // for (int i = 0; i < e->getNumShapeFunctions(); i++) + // { + // dNdx = invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * + // gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2]; dNdy = + // invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + + // invjac[1][2] * gradsuvw[i][2]; dNdz = invjac[2][0] * + // gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * + // gradsuvw[i][2]; + // + // MVertex *v = e->getShapeFunctionNode(i); + // dfdx = dfdx - (*_ls)(v->x(), v->y(), v->z()) * dNdx; + // dfdy = dfdy - (*_ls)(v->x(), v->y(), v->z()) * dNdy; + // dfdz = dfdz - (*_ls)(v->x(), v->y(), v->z()) * dNdz; + // } + // } + // } }; #endif diff --git a/Solver/FuncHeaviside.h b/Solver/FuncHeaviside.h index 4603b98c0cbcfde5c3cb7adf33f614e9878f9513..64a81b3430229485bc4d88f7df1cbe9d14c6422d 100644 --- a/Solver/FuncHeaviside.h +++ b/Solver/FuncHeaviside.h @@ -13,31 +13,36 @@ #include "simpleFunction.h" #include "gmshLevelset.h" -class FuncHeaviside : public simpleFunctionOnElement<double> { - private : +class FuncHeaviside : public simpleFunctionOnElement<double> { +private: + gLevelset *_ls; - gLevelset *_ls; - - public : - FuncHeaviside(gLevelset *ls) : _ls(ls) { } - virtual double operator() (double x, double y, double z) const { - if (_ls->isInsideDomain (x, y, z)) +public: + FuncHeaviside(gLevelset *ls) : _ls(ls) {} + virtual double operator()(double x, double y, double z) const + { + if(_ls->isInsideDomain(x, y, z)) return 1; else return -1; } - virtual double operator() (double x,double y,double z, MElement *e) const { - if (_ls->isInsideDomain (x, y, z)) + virtual double operator()(double x, double y, double z, MElement *e) const + { + if(_ls->isInsideDomain(x, y, z)) return 1; else return -1; } - virtual void gradient (double x, double y, double z, - double &dfdx, double &dfdy, double &dfdz) const - { dfdx = dfdy = dfdz = 0.0; } - virtual void gradient (double x, double y, double z, - double &dfdx, double &dfdy, double &dfdz, MElement *e) const - { dfdx = dfdy = dfdz = 0.0; } + virtual void gradient(double x, double y, double z, double &dfdx, + double &dfdy, double &dfdz) const + { + dfdx = dfdy = dfdz = 0.0; + } + virtual void gradient(double x, double y, double z, double &dfdx, + double &dfdy, double &dfdz, MElement *e) const + { + dfdx = dfdy = dfdz = 0.0; + } }; #endif diff --git a/Solver/SElement.cpp b/Solver/SElement.cpp index 54cc690db5ae1af297666b8b8fc7a07b99a57812..9e3c4b6ac7a58d8127c13824662acedc2b7c7f9a 100644 --- a/Solver/SElement.cpp +++ b/Solver/SElement.cpp @@ -22,25 +22,27 @@ etc. */ -simpleFunction<double> *SElement::_enrichement_s = 0, *SElement::_enrichement_t = 0; +simpleFunction<double> *SElement::_enrichement_s = 0, + *SElement::_enrichement_t = 0; -void SElement::gradNodalFunctions (double u, double v, double w, double invjac[3][3], double Grads[][3], - simpleFunction<double> *_enrichement) +void SElement::gradNodalFunctions(double u, double v, double w, + double invjac[3][3], double Grads[][3], + simpleFunction<double> *_enrichement) { double grads[256][3]; _e->getGradShapeFunctions(u, v, w, grads); int nbSF = getNumNodalShapeFunctions(); - for (int j = 0; j < nbSF; j++){ + for(int j = 0; j < nbSF; j++) { Grads[j][0] = invjac[0][0] * grads[j][0] + invjac[0][1] * grads[j][1] + - invjac[0][2] * grads[j][2]; + invjac[0][2] * grads[j][2]; Grads[j][1] = invjac[1][0] * grads[j][0] + invjac[1][1] * grads[j][1] + - invjac[1][2] * grads[j][2]; + invjac[1][2] * grads[j][2]; Grads[j][2] = invjac[2][0] * grads[j][0] + invjac[2][1] * grads[j][1] + - invjac[2][2] * grads[j][2]; + invjac[2][2] * grads[j][2]; } - if (_enrichement){ + if(_enrichement) { const int N = getNumNodalShapeFunctions(); SPoint3 p; double sf[256]; @@ -50,7 +52,7 @@ void SElement::gradNodalFunctions (double u, double v, double w, double invjac[3 double E = (*_enrichement)(p.x(), p.y(), p.z()); double dEdx, dEdy, dEdz; _enrichement_s->gradient(p.x(), p.y(), p.z(), dEdx, dEdy, dEdz); - for (int i = 0; i < N; i++){ + for(int i = 0; i < N; i++) { Grads[i][0] = Grads[i][0] * E + dEdx * sf[i]; Grads[i][1] = Grads[i][1] * E + dEdy * sf[i]; Grads[i][2] = Grads[i][2] * E + dEdz * sf[i]; @@ -58,51 +60,52 @@ void SElement::gradNodalFunctions (double u, double v, double w, double invjac[3 } } -void SElement::nodalFunctions (double u, double v, double w, double s[], - simpleFunction<double> *_enrichement) +void SElement::nodalFunctions(double u, double v, double w, double s[], + simpleFunction<double> *_enrichement) { _e->getShapeFunctions(u, v, w, s); - if (_enrichement){ - const int N = getNumNodalShapeFunctions(); + if(_enrichement) { + const int N = getNumNodalShapeFunctions(); SPoint3 p; // FIXME : re-use s for computing coordinates _e->pnt(u, v, w, p); double E = (*_enrichement)(p.x(), p.y(), p.z()); - for (int i = 0; i < N; i++){ + for(int i = 0; i < N; i++) { s[i] *= E; } } } - -void SElement::gradNodalShapeFunctions (double u, double v, double w, double invjac[3][3], - double grads[][3]) +void SElement::gradNodalShapeFunctions(double u, double v, double w, + double invjac[3][3], double grads[][3]) { - gradNodalFunctions (u, v, w, invjac, grads, _enrichement_s); + gradNodalFunctions(u, v, w, invjac, grads, _enrichement_s); } -void SElement::gradNodalTestFunctions (double u, double v, double w, double invjac[3][3], - double grads[][3]) +void SElement::gradNodalTestFunctions(double u, double v, double w, + double invjac[3][3], double grads[][3]) { - gradNodalFunctions (u, v, w, invjac, grads, _enrichement_t); + gradNodalFunctions(u, v, w, invjac, grads, _enrichement_t); } -void SElement::nodalShapeFunctions (double u, double v, double w, double s[]) +void SElement::nodalShapeFunctions(double u, double v, double w, double s[]) { - nodalFunctions (u, v, w, s, _enrichement_s); + nodalFunctions(u, v, w, s, _enrichement_s); } -void SElement::nodalTestFunctions (double u, double v, double w, double s[]) +void SElement::nodalTestFunctions(double u, double v, double w, double s[]) { - nodalFunctions (u, v, w, s, _enrichement_t); + nodalFunctions(u, v, w, s, _enrichement_t); } -int SElement::getNumNodalShapeFunctions () const { - if (_e->getParent()) return _e->getParent()->getNumVertices(); +int SElement::getNumNodalShapeFunctions() const +{ + if(_e->getParent()) return _e->getParent()->getNumVertices(); return _e->getNumVertices(); } -int SElement::getNumNodalTestFunctions () const { - if (_e->getParent()) return _e->getParent()->getNumVertices(); +int SElement::getNumNodalTestFunctions() const +{ + if(_e->getParent()) return _e->getParent()->getNumVertices(); return _e->getNumVertices(); } diff --git a/Solver/SElement.h b/Solver/SElement.h index 13529803dd60e0d101b1d40c86f38500b8e350ff..628effd4fd49422be32db0298a1f2273cd19cf34 100644 --- a/Solver/SElement.h +++ b/Solver/SElement.h @@ -15,36 +15,52 @@ // contain anything except the MElement). More advanced solvers will // derive and/or add containers for additional storage -class SElement -{ - private: +class SElement { +private: // the underlying mesh element MElement *_e; // store discrete function space and other data here // ... static simpleFunction<double> *_enrichement_s, *_enrichement_t; // gradient of functions (possibly enriched) - void nodalFunctions (double u, double v, double w, double s[], - simpleFunction<double> *_enrichement); - void gradNodalFunctions (double u, double v, double w, double invjac[3][3], - double grad[][3], simpleFunction<double> *_enrichment); - public: - SElement(MElement *e) : _e(e) {} - ~SElement(){} + void nodalFunctions(double u, double v, double w, double s[], + simpleFunction<double> *_enrichement); + void gradNodalFunctions(double u, double v, double w, double invjac[3][3], + double grad[][3], + simpleFunction<double> *_enrichment); + +public: + SElement(MElement *e) : _e(e) {} + ~SElement() {} MElement *getMeshElement() const { return _e; } - static void setShapeEnrichement(simpleFunction<double>*f) {_enrichement_s = f;} - static void setTestEnrichement(simpleFunction<double>*f) {_enrichement_t = f;} - static const simpleFunction<double>* getShapeEnrichement() {return _enrichement_s;} - static const simpleFunction<double>* getTestEnrichement() {return _enrichement_t;} + static void setShapeEnrichement(simpleFunction<double> *f) + { + _enrichement_s = f; + } + static void setTestEnrichement(simpleFunction<double> *f) + { + _enrichement_t = f; + } + static const simpleFunction<double> *getShapeEnrichement() + { + return _enrichement_s; + } + static const simpleFunction<double> *getTestEnrichement() + { + return _enrichement_t; + } int getNumNodalShapeFunctions() const; - inline MVertex *getVertex(int i) const {return _e->getParent() ? _e->getParent()->getVertex(i) : _e->getVertex(i);} + inline MVertex *getVertex(int i) const + { + return _e->getParent() ? _e->getParent()->getVertex(i) : _e->getVertex(i); + } int getNumNodalTestFunctions() const; - void nodalShapeFunctions (double u, double v, double w, double s[]); - void gradNodalShapeFunctions (double u, double v, double w, double invjac[3][3], - double grad[][3]); - void nodalTestFunctions (double u, double v, double w, double s[]); - void gradNodalTestFunctions (double u, double v, double w, double invjac[3][3], - double grad[][3]); + void nodalShapeFunctions(double u, double v, double w, double s[]); + void gradNodalShapeFunctions(double u, double v, double w, + double invjac[3][3], double grad[][3]); + void nodalTestFunctions(double u, double v, double w, double s[]); + void gradNodalTestFunctions(double u, double v, double w, double invjac[3][3], + double grad[][3]); }; #endif diff --git a/Solver/STensor33.cpp b/Solver/STensor33.cpp index d3853b0e3745d7608624cf7d41dd63ba75bdf997..fbe9bc794afa95fe9f976e53b9dc74158c58eb18 100644 --- a/Solver/STensor33.cpp +++ b/Solver/STensor33.cpp @@ -9,21 +9,18 @@ #include "STensor33.h" -void STensor33::print (const char *s) const +void STensor33::print(const char *s) const { char format[512]; - const char l[256]="%12.5E %12.5E %12.5E \n"; - sprintf (format, " tensor3 %s : \n %s %s %s \n %s %s %s \n %s %s %s \n", - s, l,l,l, l,l,l, l,l,l); - printf(format,s,_val[ 0],_val[ 1],_val[ 2], - _val[ 3],_val[ 4],_val[ 5], - _val[ 6],_val[ 7],_val[ 8], + const char l[256] = "%12.5E %12.5E %12.5E \n"; + sprintf(format, " tensor3 %s : \n %s %s %s \n %s %s %s \n %s %s %s \n", s, l, + l, l, l, l, l, l, l, l); + printf(format, s, _val[0], _val[1], _val[2], _val[3], _val[4], _val[5], + _val[6], _val[7], _val[8], - _val[ 9],_val[10],_val[11], - _val[12],_val[13],_val[14], - _val[15],_val[16],_val[17], + _val[9], _val[10], _val[11], _val[12], _val[13], _val[14], _val[15], + _val[16], _val[17], - _val[18],_val[19],_val[20], - _val[21],_val[22],_val[23], - _val[24],_val[25],_val[26]); + _val[18], _val[19], _val[20], _val[21], _val[22], _val[23], _val[24], + _val[25], _val[26]); } diff --git a/Solver/STensor33.h b/Solver/STensor33.h index 2842cab46a9ae90f1232e999dcd98480aee1ad26..be88affb6207d3bbf783257229bb9b58810ba201 100644 --- a/Solver/STensor33.h +++ b/Solver/STensor33.h @@ -17,28 +17,30 @@ // concrete class for general 3rd-order tensor in three-dimensional space class STensor33 { - protected: +protected: // 000 001 002 010 ... 211 212 220 221 222 double _val[27]; - public: + +public: inline int getIndex(int i, int j, int k) const { - static int _index[3][3][3] = {{{0,1,2},{3,4,5},{6,7,8}},{{9,10,11},{12,13,14},{15,16,17}},{{18,19,20},{21,22,23},{24,25,26}}}; + static int _index[3][3][3] = {{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}, + {{9, 10, 11}, {12, 13, 14}, {15, 16, 17}}, + {{18, 19, 20}, {21, 22, 23}, {24, 25, 26}}}; return _index[i][j][k]; } - STensor33(const STensor33& other) + STensor33(const STensor33 &other) { - for (int i = 0; i < 27; i++) _val[i] = other._val[i]; + for(int i = 0; i < 27; i++) _val[i] = other._val[i]; } // default constructor, null tensor STensor33(const double v = 0.0) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - _val[getIndex(i, j, k)]=v; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) _val[getIndex(i, j, k)] = v; } - inline double &operator()(int i, int j,int k) + inline double &operator()(int i, int j, int k) { return _val[getIndex(i, j, k)]; } @@ -46,95 +48,86 @@ class STensor33 { { return _val[getIndex(i, j, k)]; } - STensor33 operator + (const STensor33 &other) const + STensor33 operator+(const STensor33 &other) const { STensor33 res(*this); - for (int i = 0; i < 27; i++) res._val[i] += other._val[i]; + for(int i = 0; i < 27; i++) res._val[i] += other._val[i]; return res; } - STensor33& operator = (const STensor33 &other) + STensor33 &operator=(const STensor33 &other) { - for (int i = 0; i < 27; i++) _val[i] = other._val[i]; + for(int i = 0; i < 27; i++) _val[i] = other._val[i]; return *this; } - STensor33& operator += (const STensor33 &other) + STensor33 &operator+=(const STensor33 &other) { - for (int i = 0; i < 27; i++) _val[i] += other._val[i]; + for(int i = 0; i < 27; i++) _val[i] += other._val[i]; return *this; } - STensor33& operator -= (const STensor33 &other) + STensor33 &operator-=(const STensor33 &other) { - for (int i = 0; i < 27; i++) _val[i] -= other._val[i]; + for(int i = 0; i < 27; i++) _val[i] -= other._val[i]; return *this; } - STensor33& operator *= (const double &other) + STensor33 &operator*=(const double &other) { - for (int i = 0; i < 27; i++) _val[i] *= other; + for(int i = 0; i < 27; i++) _val[i] *= other; return *this; } - STensor33 transpose (int n, int m) const + STensor33 transpose(int n, int m) const { STensor33 ithis; - if ((n==0 && m==1) || (n==1 && m==0)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - ithis(i,j,k) = (*this)(j,i,k); + if((n == 0 && m == 1) || (n == 1 && m == 0)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) ithis(i, j, k) = (*this)(j, i, k); return ithis; } - if ((n==0 && m==2) || (n==2 && m==0)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - ithis(i,j,k) = (*this)(k,j,i); + if((n == 0 && m == 2) || (n == 2 && m == 0)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) ithis(i, j, k) = (*this)(k, j, i); return ithis; } - if ((n==1 && m==2) || (n==2 && m==1)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - ithis(i,j,k) = (*this)(i,k,j); + if((n == 1 && m == 2) || (n == 2 && m == 1)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) ithis(i, j, k) = (*this)(i, k, j); return ithis; } - return ithis+=(*this); + return ithis += (*this); } -/* STensor33& operator *= (const STensor33 &other) - { -// to be implemented - return *this; - }*/ + /* STensor33& operator *= (const STensor33 &other) + { + // to be implemented + return *this; + }*/ void print(const char *) const; - const double* data() const{return _val;} - double* data() {return _val;} + const double *data() const { return _val; } + double *data() { return _val; } }; // tensor product inline void tensprod(const SVector3 &a, const STensor3 &b, STensor33 &c) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - c(i,j,k)=a(i)*b(j,k); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) c(i, j, k) = a(i) * b(j, k); } inline void tensprod(const STensor3 &a, const SVector3 &b, STensor33 &c) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - c(i,j,k)=a(i,j)*b(k); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) c(i, j, k) = a(i, j) * b(k); } inline double dot(const STensor33 &a, const STensor33 &b) { - double prod=0; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - prod+=a(i,j,k)*b(i,j,k); + double prod = 0; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) prod += a(i, j, k) * b(i, j, k); return prod; } @@ -145,7 +138,7 @@ inline STensor33 operator*(const STensor33 &t, double m) val *= m; return val; } -inline STensor33 operator*(double m,const STensor33 &t) +inline STensor33 operator*(double m, const STensor33 &t) { STensor33 val(t); val *= m; @@ -155,48 +148,43 @@ inline STensor33 operator*(double m,const STensor33 &t) inline STensor3 operator*(const STensor33 &t, const SVector3 &m) { STensor3 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - val(i,j)+=t(i,j,k)*m(k); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) val(i, j) += t(i, j, k) * m(k); return val; } -inline STensor3 operator*( const SVector3 &m , const STensor33 &t) +inline STensor3 operator*(const SVector3 &m, const STensor33 &t) { STensor3 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - val(j,k)+=m(i)*t(i,j,k); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) val(j, k) += m(i) * t(i, j, k); return val; } inline SVector3 operator*(const STensor33 &t, const STensor3 &m) { SVector3 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - val(i)+=t(i,j,k)*m(k,j); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) val(i) += t(i, j, k) * m(k, j); return val; } -inline SVector3 operator*( const STensor3 &m , const STensor33 &t) +inline SVector3 operator*(const STensor3 &m, const STensor33 &t) { SVector3 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - val(k)+=m(j,i)*t(i,j,k); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) val(k) += m(j, i) * t(i, j, k); return val; } inline double operator*(const STensor33 &m, const STensor33 &t) { double val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - val+=m(i,j,k)*t(k,j,i); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) val += m(i, j, k) * t(k, j, i); return val; } diff --git a/Solver/STensor43.cpp b/Solver/STensor43.cpp index 34d29c1ca934f24cd1bba411dc7a9631cb94ca44..39737097c8596d3876683b3f21b7ff42e8769036 100644 --- a/Solver/STensor43.cpp +++ b/Solver/STensor43.cpp @@ -9,21 +9,25 @@ #include "STensor43.h" -void STensor43::print (const char *s) const +void STensor43::print(const char *s) const { char format[2048]; - const char l[256] = "%12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E \n"; - sprintf(format, " tensor4 %s : \n %s %s %s \n %s %s %s \n %s %s %s \n",s, l,l,l, l,l,l, l,l,l); - printf(format, s, - _val[ 0],_val[ 1],_val[ 2], _val[ 3],_val[ 4],_val[ 5], _val[ 6],_val[ 7],_val[ 8], - _val[ 9],_val[10],_val[11], _val[12],_val[13],_val[14], _val[15],_val[16],_val[17], - _val[18],_val[19],_val[20], _val[21],_val[22],_val[23], _val[24],_val[25],_val[26], + const char l[256] = + "%12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E \n"; + sprintf(format, " tensor4 %s : \n %s %s %s \n %s %s %s \n %s %s %s \n", s, l, + l, l, l, l, l, l, l, l); + printf(format, s, _val[0], _val[1], _val[2], _val[3], _val[4], _val[5], + _val[6], _val[7], _val[8], _val[9], _val[10], _val[11], _val[12], + _val[13], _val[14], _val[15], _val[16], _val[17], _val[18], _val[19], + _val[20], _val[21], _val[22], _val[23], _val[24], _val[25], _val[26], - _val[27],_val[28],_val[29], _val[30],_val[31],_val[32], _val[33],_val[34],_val[35], - _val[36],_val[37],_val[38], _val[39],_val[40],_val[41], _val[42],_val[43],_val[44], - _val[45],_val[46],_val[47], _val[48],_val[49],_val[50], _val[51],_val[52],_val[53], + _val[27], _val[28], _val[29], _val[30], _val[31], _val[32], _val[33], + _val[34], _val[35], _val[36], _val[37], _val[38], _val[39], _val[40], + _val[41], _val[42], _val[43], _val[44], _val[45], _val[46], _val[47], + _val[48], _val[49], _val[50], _val[51], _val[52], _val[53], - _val[54],_val[55],_val[56], _val[57],_val[58],_val[59], _val[60],_val[61],_val[62], - _val[63],_val[64],_val[65], _val[66],_val[67],_val[68], _val[69],_val[70],_val[71], - _val[72],_val[73],_val[74], _val[75],_val[76],_val[77], _val[78],_val[79],_val[80]); + _val[54], _val[55], _val[56], _val[57], _val[58], _val[59], _val[60], + _val[61], _val[62], _val[63], _val[64], _val[65], _val[66], _val[67], + _val[68], _val[69], _val[70], _val[71], _val[72], _val[73], _val[74], + _val[75], _val[76], _val[77], _val[78], _val[79], _val[80]); } diff --git a/Solver/STensor43.h b/Solver/STensor43.h index 532b9686feda9f8716323fb395754c1ba5ea2afc..de3da24b71945d078ea0750528fed004e8fdd3f4 100644 --- a/Solver/STensor43.h +++ b/Solver/STensor43.h @@ -17,191 +17,181 @@ // concrete class for general 3rd-order tensor in three-dimensional space class STensor43 { - protected: +protected: // 0000 0001 0002 0010 ... 2211 2212 2220 2221 2222 double _val[81]; - public: + +public: inline int getIndex(int i, int j, int k, int l) const { - static int _index[3][3][3][3] = {{{{0,1,2},{3,4,5},{6,7,8}},{{9,10,11},{12,13,14},{15,16,17}},{{18,19,20},{21,22,23},{24,25,26}}}, - {{{27,28,29},{30,31,32},{33,34,35}},{{36,37,38},{39,40,41},{42,43,44}},{{45,46,47},{48,49,50},{51,52,53}}}, - {{{54,55,56},{57,58,59},{60,61,62}},{{63,64,65},{66,67,68},{69,70,71}},{{72,73,74},{75,76,77},{78,79,80}}}}; + static int _index[3][3][3][3] = { + {{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}, + {{9, 10, 11}, {12, 13, 14}, {15, 16, 17}}, + {{18, 19, 20}, {21, 22, 23}, {24, 25, 26}}}, + {{{27, 28, 29}, {30, 31, 32}, {33, 34, 35}}, + {{36, 37, 38}, {39, 40, 41}, {42, 43, 44}}, + {{45, 46, 47}, {48, 49, 50}, {51, 52, 53}}}, + {{{54, 55, 56}, {57, 58, 59}, {60, 61, 62}}, + {{63, 64, 65}, {66, 67, 68}, {69, 70, 71}}, + {{72, 73, 74}, {75, 76, 77}, {78, 79, 80}}}}; return _index[i][j][k][l]; } - STensor43(const STensor43& other) + STensor43(const STensor43 &other) { - for (int i = 0; i < 81; i++) _val[i] = other._val[i]; + for(int i = 0; i < 81; i++) _val[i] = other._val[i]; } // default constructor, null tensor STensor43(const double v = 0.0) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - if ((i==k)&&(j==l)) - _val[getIndex(i, j, k, l)]=v; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + if((i == k) && (j == l)) + _val[getIndex(i, j, k, l)] = v; else - _val[getIndex(i, j, k, l)]=0.0; + _val[getIndex(i, j, k, l)] = 0.0; } // Symmetric identity tensor STensor43(const double vik, const double vil) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - { - _val[getIndex(i, j, k, l)]= 0.; - if ((i==k)&&(j==l)) - _val[getIndex(i, j, k, l)]+=0.5*vik; - if ((i==l)&&(j==k)) - _val[getIndex(i, j, k, l)]+=0.5*vil; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) { + _val[getIndex(i, j, k, l)] = 0.; + if((i == k) && (j == l)) _val[getIndex(i, j, k, l)] += 0.5 * vik; + if((i == l) && (j == k)) _val[getIndex(i, j, k, l)] += 0.5 * vil; } } - inline double &operator()(int i, int j,int k, int l) + inline double &operator()(int i, int j, int k, int l) { return _val[getIndex(i, j, k, l)]; } inline double operator()(int i, int j, int k, int l) const { - return _val[getIndex(i, j, k ,l)]; + return _val[getIndex(i, j, k, l)]; } - STensor43 operator + (const STensor43 &other) const + STensor43 operator+(const STensor43 &other) const { STensor43 res(*this); - for (int i = 0; i < 81; i++) res._val[i] += other._val[i]; + for(int i = 0; i < 81; i++) res._val[i] += other._val[i]; return res; } - STensor43& operator += (const STensor43 &other) + STensor43 &operator+=(const STensor43 &other) { - for (int i = 0; i < 81; i++) _val[i] += other._val[i]; + for(int i = 0; i < 81; i++) _val[i] += other._val[i]; return *this; } - STensor43& operator -= (const STensor43 &other) + STensor43 &operator-=(const STensor43 &other) { - for (int i = 0; i < 81; i++) _val[i] -= other._val[i]; + for(int i = 0; i < 81; i++) _val[i] -= other._val[i]; return *this; } - STensor43& operator = (const STensor43 &other) + STensor43 &operator=(const STensor43 &other) { - for (int i = 0; i < 81; i++) _val[i] = other._val[i]; + for(int i = 0; i < 81; i++) _val[i] = other._val[i]; return *this; } - STensor43& operator *= (const double &other) + STensor43 &operator*=(const double &other) { - for (int i = 0; i < 81; i++) _val[i] *= other; + for(int i = 0; i < 81; i++) _val[i] *= other; return *this; } - - STensor43 transpose (int n, int m) const + + STensor43 transpose(int n, int m) const { STensor43 ithis; - if ((n==0 && m==1) || (n==1 && m==0)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - ithis(i,j,k,l) = (*this)(j,i,k,l); + if((n == 0 && m == 1) || (n == 1 && m == 0)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) ithis(i, j, k, l) = (*this)(j, i, k, l); return ithis; } - if ((n==0 && m==2) || (n==2 && m==0)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - ithis(i,j,k,l) = (*this)(k,j,i,l); + if((n == 0 && m == 2) || (n == 2 && m == 0)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) ithis(i, j, k, l) = (*this)(k, j, i, l); return ithis; } - if ((n==0 && m==3) || (n==3 && m==0)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - ithis(i,j,k,l) = (*this)(l,j,k,i); + if((n == 0 && m == 3) || (n == 3 && m == 0)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) ithis(i, j, k, l) = (*this)(l, j, k, i); return ithis; } - if ((n==1 && m==2) || (n==2 && m==1)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - ithis(i,j,k,l) = (*this)(i,k,j,l); + if((n == 1 && m == 2) || (n == 2 && m == 1)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) ithis(i, j, k, l) = (*this)(i, k, j, l); return ithis; } - if ((n==1 && m==3) || (n==3 && m==1)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - ithis(i,j,k,l) = (*this)(i,l,k,j); + if((n == 1 && m == 3) || (n == 3 && m == 1)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) ithis(i, j, k, l) = (*this)(i, l, k, j); return ithis; } - if ((n==2 && m==3) || (n==3 && m==2)) - { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - ithis(i,j,k,l) = (*this)(i,j,l,k); + if((n == 2 && m == 3) || (n == 3 && m == 2)) { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) ithis(i, j, k, l) = (*this)(i, j, l, k); return ithis; } - return ithis+=(*this); + return ithis += (*this); } -/* STensor43& operator *= (const STensor43 &other) - { -// to be implemented - return *this; - }*/ + /* STensor43& operator *= (const STensor43 &other) + { + // to be implemented + return *this; + }*/ void print(const char *) const; - const double* data() const {return _val;} - double* data() {return _val;} + const double *data() const { return _val; } + double *data() { return _val; } - void axpy(const double a, const STensor43& other){ - for (int i = 0; i < 81; i++) _val[i] += a*other._val[i]; + void axpy(const double a, const STensor43 &other) + { + for(int i = 0; i < 81; i++) _val[i] += a * other._val[i]; } }; // tensor product inline void tensprod(const STensor3 &a, const STensor3 &b, STensor43 &c) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - c(i,j,k,l)=a(i,j)*b(k,l); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) c(i, j, k, l) = a(i, j) * b(k, l); } inline void tensprod(const SVector3 &a, const STensor33 &b, STensor43 &c) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - c(i,j,k,l)=a(i)*b(j,k,l); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) c(i, j, k, l) = a(i) * b(j, k, l); } inline void tensprod(const STensor33 &a, const SVector3 &b, STensor43 &c) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - c(i,j,k,l)=a(i,j,k)*b(l); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) c(i, j, k, l) = a(i, j, k) * b(l); } inline double dot(const STensor43 &a, const STensor43 &b) { - double prod=0; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - prod+=a(i,j,k,l)*b(i,j,k,l); + double prod = 0; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) prod += a(i, j, k, l) * b(i, j, k, l); return prod; } @@ -212,7 +202,7 @@ inline STensor43 operator*(const STensor43 &t, double m) val *= m; return val; } -inline STensor43 operator*(double m,const STensor43 &t) +inline STensor43 operator*(double m, const STensor43 &t) { STensor43 val(t); val *= m; @@ -222,74 +212,67 @@ inline STensor43 operator*(double m,const STensor43 &t) inline STensor33 operator*(const STensor43 &t, const SVector3 &m) { STensor33 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - val(i,j,k)+=t(i,j,k,l)*m(l); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) val(i, j, k) += t(i, j, k, l) * m(l); return val; } -inline STensor33 operator*( const SVector3 &m , const STensor43 &t) +inline STensor33 operator*(const SVector3 &m, const STensor43 &t) { STensor33 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - val(j,k,l)+=m(i)*t(i,j,k,l); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) val(j, k, l) += m(i) * t(i, j, k, l); return val; } inline STensor3 operator*(const STensor43 &t, const STensor3 &m) { STensor3 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - val(i,j)+=t(i,j,k,l)*m(l,k); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) val(i, j) += t(i, j, k, l) * m(l, k); return val; } -inline STensor3 operator*( const STensor3 &m , const STensor43 &t) +inline STensor3 operator*(const STensor3 &m, const STensor43 &t) { STensor3 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - val(k,l)+=m(j,i)*t(i,j,k,l); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) val(k, l) += m(j, i) * t(i, j, k, l); return val; } inline SVector3 operator*(const STensor43 &t, const STensor33 &m) { SVector3 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - val(i)+=t(i,j,k,l)*m(l,k,j); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) val(i) += t(i, j, k, l) * m(l, k, j); return val; } -inline SVector3 operator*( const STensor33 &m , const STensor43 &t) +inline SVector3 operator*(const STensor33 &m, const STensor43 &t) { SVector3 val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - val(l)+=m(k,j,i)*t(i,j,k,l); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) val(l) += m(k, j, i) * t(i, j, k, l); return val; } -inline double operator*( const STensor43 &m , const STensor43 &t) +inline double operator*(const STensor43 &m, const STensor43 &t) { double val(0.); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) - for (int l = 0; l < 3; l++) - val+=m(i,j,k,l)*t(l,k,j,i); + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) val += m(i, j, k, l) * t(l, k, j, i); return val; } diff --git a/Solver/STensor53.cpp b/Solver/STensor53.cpp index 3e821c6f12a3b08f1f102cb4ee04a13e30a582fd..c1c618e16269bdb5025232e646f1ee7c6873ab6b 100644 --- a/Solver/STensor53.cpp +++ b/Solver/STensor53.cpp @@ -5,22 +5,21 @@ #include "STensor53.h" -STensor53::STensor53(const double val){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - _val[i][j][k][l][m] = val; +STensor53::STensor53(const double val) +{ + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) _val[i][j][k][l][m] = val; }; - -STensor53::STensor53(const STensor53& src){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) +STensor53::STensor53(const STensor53 &src) +{ + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) _val[i][j][k][l][m] = src._val[i][j][k][l][m]; }; - diff --git a/Solver/STensor53.h b/Solver/STensor53.h index ebb4466896bd4a069e114c179adc3279391fea04..1cb1d48f147f39ef8c2fbb917451c128793a7e71 100644 --- a/Solver/STensor53.h +++ b/Solver/STensor53.h @@ -2,60 +2,63 @@ // // See the LICENSE.txt file for license information. Please report all // bugs and problems to the public mailing list <gmsh@onelab.info>. -#ifndef STENSOR53_H_ -#define STENSOR53_H_ +#ifndef STENSOR53_H_ +#define STENSOR53_H_ class STensor53 { - protected: - double _val[3][3][3][3][3]; +protected: + double _val[3][3][3][3][3]; - public: - STensor53(const double val = 0); - STensor53(const STensor53& src); - inline double &operator()(int i, int j,int k, int l, int m){ - return _val[i][j][k][l][m]; - }; - inline double operator()(int i, int j, int k, int l, int m) const{ - return _val[i][j][k][l][m]; - }; - STensor53& operator = (const STensor53 &other){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - _val[i][j][k][l][m] = other._val[i][j][k][l][m]; - return *this; - }; - STensor53& operator += (const STensor53 &other){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - _val[i][j][k][l][m] += other._val[i][j][k][l][m]; - return *this; - }; - STensor53& operator -= (const STensor53 &other){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - _val[i][j][k][l][m] -= other._val[i][j][k][l][m]; - return *this; - }; - STensor53& operator *= (const double &other){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - _val[i][j][k][l][m] *= other; - return *this; - }; +public: + STensor53(const double val = 0); + STensor53(const STensor53 &src); + inline double &operator()(int i, int j, int k, int l, int m) + { + return _val[i][j][k][l][m]; + }; + inline double operator()(int i, int j, int k, int l, int m) const + { + return _val[i][j][k][l][m]; + }; + STensor53 &operator=(const STensor53 &other) + { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + _val[i][j][k][l][m] = other._val[i][j][k][l][m]; + return *this; + }; + STensor53 &operator+=(const STensor53 &other) + { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + _val[i][j][k][l][m] += other._val[i][j][k][l][m]; + return *this; + }; + STensor53 &operator-=(const STensor53 &other) + { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + _val[i][j][k][l][m] -= other._val[i][j][k][l][m]; + return *this; + }; + STensor53 &operator*=(const double &other) + { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) _val[i][j][k][l][m] *= other; + return *this; + }; }; - - -#endif // STENSOR53_H_ +#endif // STENSOR53_H_ diff --git a/Solver/STensor63.cpp b/Solver/STensor63.cpp index 0a0c02b6f79e91dd74cdd16214133af1e235079b..70552c9fb80a6d071a981b67c6b588b5b3a79d22 100644 --- a/Solver/STensor63.cpp +++ b/Solver/STensor63.cpp @@ -5,22 +5,23 @@ #include "STensor63.h" -STensor63::STensor63(const double val){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - for (int n=0; n<3; n++) - _val[i][j][k][l][m][n] = val; +STensor63::STensor63(const double val) +{ + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + for(int n = 0; n < 3; n++) _val[i][j][k][l][m][n] = val; }; -STensor63::STensor63(const STensor63& src){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - for (int n=0; n<3; n++) +STensor63::STensor63(const STensor63 &src) +{ + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + for(int n = 0; n < 3; n++) _val[i][j][k][l][m][n] = src._val[i][j][k][l][m][n]; }; diff --git a/Solver/STensor63.h b/Solver/STensor63.h index c620c9794eb61fd4e8e6fafbc4c2c7836d016b43..df24ae0c3d4b22e9b79eb83a9fec15b9c730a14a 100644 --- a/Solver/STensor63.h +++ b/Solver/STensor63.h @@ -2,64 +2,67 @@ // // See the LICENSE.txt file for license information. Please report all // bugs and problems to the public mailing list <gmsh@onelab.info>. -#ifndef STENSOR63_H_ +#ifndef STENSOR63_H_ #define STENSOR63_H_ -class STensor63{ - protected: - double _val[3][3][3][3][3][3]; +class STensor63 { +protected: + double _val[3][3][3][3][3][3]; - public: - STensor63(const double val = 0); - STensor63(const STensor63& src); - inline double &operator()(int i, int j,int k, int l, int m, int n){ - return _val[i][j][k][l][m][n]; - }; - inline double operator()(int i, int j, int k, int l, int m, int n) const{ - return _val[i][j][k][l][m][n]; - }; - STensor63& operator = (const STensor63 &other){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - for (int n=0; n<3; n++) - _val[i][j][k][l][m][n] = other._val[i][j][k][l][m][n]; - return *this; - }; - STensor63& operator += (const STensor63 &other){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - for (int n=0; n<3; n++) - _val[i][j][k][l][m][n] += other._val[i][j][k][l][m][n]; - return *this; - }; - STensor63& operator -= (const STensor63 &other){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - for (int n=0; n<3; n++) - _val[i][j][k][l][m][n] -= other._val[i][j][k][l][m][n]; - return *this; - }; - STensor63& operator *= (const double &other){ - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - for (int k=0; k<3; k++) - for (int l=0; l<3; l++) - for (int m=0; m<3; m++) - for (int n=0; n<3; n++) - _val[i][j][k][l][m][n] *= other; - return *this; - }; -}; - - - -#endif // STENSOR63_H_ +public: + STensor63(const double val = 0); + STensor63(const STensor63 &src); + inline double &operator()(int i, int j, int k, int l, int m, int n) + { + return _val[i][j][k][l][m][n]; + }; + inline double operator()(int i, int j, int k, int l, int m, int n) const + { + return _val[i][j][k][l][m][n]; + }; + STensor63 &operator=(const STensor63 &other) + { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + for(int n = 0; n < 3; n++) + _val[i][j][k][l][m][n] = other._val[i][j][k][l][m][n]; + return *this; + }; + STensor63 &operator+=(const STensor63 &other) + { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + for(int n = 0; n < 3; n++) + _val[i][j][k][l][m][n] += other._val[i][j][k][l][m][n]; + return *this; + }; + STensor63 &operator-=(const STensor63 &other) + { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + for(int n = 0; n < 3; n++) + _val[i][j][k][l][m][n] -= other._val[i][j][k][l][m][n]; + return *this; + }; + STensor63 &operator*=(const double &other) + { + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) + for(int l = 0; l < 3; l++) + for(int m = 0; m < 3; m++) + for(int n = 0; n < 3; n++) _val[i][j][k][l][m][n] *= other; + return *this; + }; +}; + +#endif // STENSOR63_H_ diff --git a/Solver/convexCombinationTerm.h b/Solver/convexCombinationTerm.h index 04739b4ef050e4931ecbf1720c71ebfba065b5cc..637787a7d6e05b1ed7efca38dbc8ec9de942c798 100644 --- a/Solver/convexCombinationTerm.h +++ b/Solver/convexCombinationTerm.h @@ -16,12 +16,15 @@ #include "Numeric.h" class convexCombinationTerm : public femTerm<double> { - protected: +protected: const simpleFunction<double> *_k; const int _iField; - public: + +public: convexCombinationTerm(GModel *gm, int iField, simpleFunction<double> *k) - : femTerm<double>(gm), _k(k), _iField(iField) {} + : femTerm<double>(gm), _k(k), _iField(iField) + { + } virtual int sizeOfR(SElement *se) const { return se->getMeshElement()->getNumShapeFunctions(); @@ -37,37 +40,35 @@ class convexCombinationTerm : public femTerm<double> { } virtual void elementMatrix(SElement *se, fullMatrix<double> &m) const { - MElement *e = se->getMeshElement(); m.setAll(0.); const int nbSF = e->getNumShapeFunctions(); - for (int j = 0; j < nbSF; j++){ + for(int j = 0; j < nbSF; j++) { MVertex *vj = e->getShapeFunctionNode(j); double diag = 0.0; - for (int k = 0; k < nbSF; k++){ - MVertex *vk = e->getShapeFunctionNode(k); - MVertex *vl = NULL; - SVector3 a, b; - double tan = 0.0; - if ( k!=j && 3-j-k >= 0 && 3-j-k <=2) { - vl = e->getShapeFunctionNode(3-j-k); - a = SVector3(vk->x()-vj->x(),vk->y()-vj->y(),vk->z()-vj->z()); - b = SVector3(vl->x()-vj->x(),vl->y()-vj->y(),vl->z()-vj->z()); - double angle = myacos(dot(a,b)/(norm(a)*norm(b))); - tan = sin(angle*0.5)/cos(angle*0.5); - } - double length = vj->distance(vk); - m(j, k) = -tan/length; // mean value convex map - //m(j, k) = -1; //convex map of Tutte + for(int k = 0; k < nbSF; k++) { + MVertex *vk = e->getShapeFunctionNode(k); + MVertex *vl = NULL; + SVector3 a, b; + double tan = 0.0; + if(k != j && 3 - j - k >= 0 && 3 - j - k <= 2) { + vl = e->getShapeFunctionNode(3 - j - k); + a = SVector3(vk->x() - vj->x(), vk->y() - vj->y(), vk->z() - vj->z()); + b = SVector3(vl->x() - vj->x(), vl->y() - vj->y(), vl->z() - vj->z()); + double angle = myacos(dot(a, b) / (norm(a) * norm(b))); + tan = sin(angle * 0.5) / cos(angle * 0.5); + } + double length = vj->distance(vk); + m(j, k) = -tan / length; // mean value convex map + // m(j, k) = -1; //convex map of Tutte } - //m(j,j) = (nbSF - 1);// convex map of Tutte - for (int k = 0; k < nbSF; k++){ - if (k != j) diag += (-m(j,k)); + // m(j,j) = (nbSF - 1);// convex map of Tutte + for(int k = 0; k < nbSF; k++) { + if(k != j) diag += (-m(j, k)); } m(j, j) = diag; } } - }; #endif diff --git a/Solver/convexLaplaceTerm.h b/Solver/convexLaplaceTerm.h index 2d06bf5109c99bebae1425ddceb960a026af4320..fd23a468373caeae601af879f368347dae9ca7c5 100644 --- a/Solver/convexLaplaceTerm.h +++ b/Solver/convexLaplaceTerm.h @@ -9,43 +9,39 @@ #include "laplaceTerm.h" // \nabla \cdot k \nabla U -class convexLaplaceTerm : public laplaceTerm { - public: - convexLaplaceTerm(GModel *gm, int iField, simpleFunction<double> *k,std::map<MVertex*, SPoint3> *coord=NULL) - : laplaceTerm(gm,iField,k,coord) {} +class convexLaplaceTerm : public laplaceTerm { +public: + convexLaplaceTerm(GModel *gm, int iField, simpleFunction<double> *k, + std::map<MVertex *, SPoint3> *coord = NULL) + : laplaceTerm(gm, iField, k, coord) + { + } virtual void elementMatrix(SElement *se, fullMatrix<double> &m) const { - - laplaceTerm::elementMatrix(se,m); + laplaceTerm::elementMatrix(se, m); MElement *e = se->getMeshElement(); const int nbSF = e->getNumShapeFunctions(); double tr = 0.; - for (int j = 0; j<nbSF; j++) - tr += m(j,j); + for(int j = 0; j < nbSF; j++) tr += m(j, j); tr /= nbSF; - + // thredshold, alpha in (0;1) - double alpha = .1; - - for (int j = 0; j < nbSF; j++){ - for (int k = 0; k < j; k++){ - if( m(j,k) > -alpha*tr){ - double delta = m(j,k) + alpha*tr; - m(j,j) += delta; - m(k,k) += delta; - m(j,k) -= delta; - m(k,j) -= delta; - } + double alpha = .1; + + for(int j = 0; j < nbSF; j++) { + for(int k = 0; k < j; k++) { + if(m(j, k) > -alpha * tr) { + double delta = m(j, k) + alpha * tr; + m(j, j) += delta; + m(k, k) += delta; + m(j, k) -= delta; + m(k, j) -= delta; + } } } - } - }; - - - #endif diff --git a/Solver/crossConfTerm.h b/Solver/crossConfTerm.h index e2ab36aa383a5f3b5bc6e6c9fce3730b4808f5c8..7567bd6b9b26d0cca6e059f4956ad9d8e31e387e 100644 --- a/Solver/crossConfTerm.h +++ b/Solver/crossConfTerm.h @@ -15,17 +15,20 @@ #include "Numeric.h" class crossConfTerm : public femTerm<double> { - protected: +protected: const simpleFunction<double> *_diffusivity; const int _iFieldR; int _iFieldC; - std::map<MVertex*, SPoint3> *_coordView; - public: + std::map<MVertex *, SPoint3> *_coordView; + +public: crossConfTerm(GModel *gm, int iFieldR, int iFieldC, simpleFunction<double> *diffusivity, - std::map<MVertex*, SPoint3> *coord=NULL) + std::map<MVertex *, SPoint3> *coord = NULL) : femTerm<double>(gm), _diffusivity(diffusivity), _iFieldR(iFieldR), - _iFieldC(iFieldC), _coordView(coord) {} + _iFieldC(iFieldC), _coordView(coord) + { + } virtual int sizeOfR(SElement *se) const { @@ -37,7 +40,7 @@ class crossConfTerm : public femTerm<double> { } Dof getLocalDofR(SElement *se, int iRow) const { - return Dof(se->getMeshElement()->getShapeFunctionNode(iRow)->getNum(), + return Dof(se->getMeshElement()->getShapeFunctionNode(iRow)->getNum(), Dof::createTypeWithTwoInts(0, _iFieldR)); } Dof getLocalDofC(SElement *se, int iRow) const @@ -54,42 +57,44 @@ class crossConfTerm : public femTerm<double> { IntPt *GP; double jac[3][3]; double invjac[3][3]; - SVector3 Grads [256]; + SVector3 Grads[256]; double grads[256][3]; e->getIntegrationPoints(integrationOrder, &npts, &GP); m.setAll(0.); - for (int i = 0; i < npts; i++){ + for(int i = 0; i < npts; i++) { const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; const double weight = GP[i].weight; const double detJ = e->getJacobian(u, v, w, jac); - SPoint3 p; e->pnt(u, v, w, p); + SPoint3 p; + e->pnt(u, v, w, p); const double _diff = (*_diffusivity)(p.x(), p.y(), p.z()); inv3x3(jac, invjac); e->getGradShapeFunctions(u, v, w, grads); - for (int j = 0; j < nbSF; j++){ - Grads[j] = SVector3(invjac[0][0] * grads[j][0] + invjac[0][1] * grads[j][1] + - invjac[0][2] * grads[j][2], - invjac[1][0] * grads[j][0] + invjac[1][1] * grads[j][1] + - invjac[1][2] * grads[j][2], - invjac[2][0] * grads[j][0] + invjac[2][1] * grads[j][1] + - invjac[2][2] * grads[j][2]); + for(int j = 0; j < nbSF; j++) { + Grads[j] = + SVector3(invjac[0][0] * grads[j][0] + invjac[0][1] * grads[j][1] + + invjac[0][2] * grads[j][2], + invjac[1][0] * grads[j][0] + invjac[1][1] * grads[j][1] + + invjac[1][2] * grads[j][2], + invjac[2][0] * grads[j][0] + invjac[2][1] * grads[j][1] + + invjac[2][2] * grads[j][2]); } - SVector3 N (jac[2][0], jac[2][1], jac[2][2]); - for (int j = 0; j < nbSF; j++){ - for (int k = 0; k <= j; k++){ - m(j, k) += dot(crossprod(Grads[j], Grads[k]), N) * weight * detJ * _diff; + SVector3 N(jac[2][0], jac[2][1], jac[2][2]); + for(int j = 0; j < nbSF; j++) { + for(int k = 0; k <= j; k++) { + m(j, k) += + dot(crossprod(Grads[j], Grads[k]), N) * weight * detJ * _diff; } } } - for (int j = 0; j < nbSF; j++) - for (int k = 0; k < j; k++) - m(k, j) = -1.* m(j, k); + for(int j = 0; j < nbSF; j++) + for(int k = 0; k < j; k++) m(k, j) = -1. * m(j, k); } - void elementVector(SElement *se, fullVector<double> &m) const + void elementVector(SElement *se, fullVector<double> &m) const { MElement *e = se->getMeshElement(); int nbSF = e->getNumShapeFunctions(); @@ -100,18 +105,19 @@ class crossConfTerm : public femTerm<double> { fullVector<double> val(nbSF); val.scale(0.); - for (int i = 0; i < nbSF; i++){ - std::map<MVertex*, SPoint3>::iterator it = _coordView->find(e->getShapeFunctionNode(i)); + for(int i = 0; i < nbSF; i++) { + std::map<MVertex *, SPoint3>::iterator it = + _coordView->find(e->getShapeFunctionNode(i)); SPoint3 UV = it->second; - if (_iFieldC == 1) val(i) = UV.x(); - else if (_iFieldC == 2) val(i) = UV.y(); + if(_iFieldC == 1) + val(i) = UV.x(); + else if(_iFieldC == 2) + val(i) = UV.y(); } m.scale(0.); - for (int i = 0; i < nbSF; i++) - for (int j = 0; j < nbSF; j++) - m(i) += -(*mat)(i, j) * val(j); - + for(int i = 0; i < nbSF; i++) + for(int j = 0; j < nbSF; j++) m(i) += -(*mat)(i, j) * val(j); } }; diff --git a/Solver/diagBCTerm.h b/Solver/diagBCTerm.h index 53a146bf8940660817dd41463f83d2219757801a..2b7ca881b88a4e557970600d9a52f46d7154415f 100644 --- a/Solver/diagBCTerm.h +++ b/Solver/diagBCTerm.h @@ -16,12 +16,15 @@ #include "Numeric.h" class diagBCTerm : public femTerm<double> { - protected: +protected: const simpleFunction<double> *_k; const int _iField; - public: + +public: diagBCTerm(GModel *gm, int iField, simpleFunction<double> *k) - : femTerm<double>(gm), _k(k), _iField(iField) {} + : femTerm<double>(gm), _k(k), _iField(iField) + { + } virtual int sizeOfR(SElement *se) const { return se->getMeshElement()->getNumShapeFunctions(); @@ -41,14 +44,16 @@ class diagBCTerm : public femTerm<double> { MElement *e = se->getMeshElement(); m.setAll(0.); const int nbSF = e->getNumShapeFunctions(); - for (int j = 0; j < nbSF; j++){ - for (int k = 0; k < nbSF; k++) { + for(int j = 0; j < nbSF; j++) { + for(int k = 0; k < nbSF; k++) { m(j, k) = 0.0; m(k, j) = 0.0; } MVertex *v = e->getShapeFunctionNode(j); - if( v->onWhat()->dim() < 2 ) m(j, j) = 1.0; - else m(j, j) = 0.0; + if(v->onWhat()->dim() < 2) + m(j, j) = 1.0; + else + m(j, j) = 0.0; } } }; diff --git a/Solver/distanceTerm.h b/Solver/distanceTerm.h index 0261e9d6fdda9fa771961cb5d8106e9ab18b42e5..70952f594f57298036fe0f23acd934de8af5c185 100644 --- a/Solver/distanceTerm.h +++ b/Solver/distanceTerm.h @@ -9,10 +9,12 @@ #include "helmholtzTerm.h" class distanceTerm : public helmholtzTerm<double> { - public: +public: distanceTerm(GModel *gm, int iField, simpleFunction<double> *k, simpleFunction<double> *a) - : helmholtzTerm<double>(gm, iField, iField, k, a) {} + : helmholtzTerm<double>(gm, iField, iField, k, a) + { + } void elementVector(SElement *se, fullVector<double> &m) const { MElement *e = se->getMeshElement(); @@ -22,16 +24,16 @@ class distanceTerm : public helmholtzTerm<double> { double jac[3][3]; double ff[256]; e->getIntegrationPoints(integrationOrder, &npts, &GP); - m.scale(0.); - for (int i = 0; i < npts; i++){ + m.scale(0.); + for(int i = 0; i < npts; i++) { const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; const double weight = GP[i].weight; const double detJ = e->getJacobian(u, v, w, jac); e->getShapeFunctions(u, v, w, ff); - for (int j = 0; j < e->getNumShapeFunctions(); j++){ - m(j) += ff[j] * weight * detJ; + for(int j = 0; j < e->getNumShapeFunctions(); j++) { + m(j) += ff[j] * weight * detJ; } } } diff --git a/Solver/dofManager.cpp b/Solver/dofManager.cpp index 1fbec90b45105b8d9c195db872ce2699f88b5f35..7b6ec54767542031956cb3b771a97e9a8fcf0119 100644 --- a/Solver/dofManager.cpp +++ b/Solver/dofManager.cpp @@ -11,36 +11,40 @@ #include <dofManager.h> -template<> -void dofManager<double>::scatterSolution() +template <> void dofManager<double>::scatterSolution() { #ifdef HAVE_MPI - if (!_parallelFinalized) { + if(!_parallelFinalized) { _parallelFinalize(); } MPI_Status status; - std::vector<std::vector<double> > sendBuf(Msg::GetCommSize()), recvBuf(Msg::GetCommSize()); - std::vector<MPI_Request> reqRecv(Msg::GetCommSize()), reqSend(Msg::GetCommSize()); - for (int i = 0; i<Msg::GetCommSize(); i++) { + std::vector<std::vector<double> > sendBuf(Msg::GetCommSize()), + recvBuf(Msg::GetCommSize()); + std::vector<MPI_Request> reqRecv(Msg::GetCommSize()), + reqSend(Msg::GetCommSize()); + for(int i = 0; i < Msg::GetCommSize(); i++) { reqRecv[i] = reqSend[i] = MPI_REQUEST_NULL; - if (!ghostByProc[i].empty()) { + if(!ghostByProc[i].empty()) { recvBuf[i].resize(ghostByProc[i].size()); - MPI_Irecv (&recvBuf[i][0], recvBuf[i].size(), MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &reqRecv[i]); + MPI_Irecv(&recvBuf[i][0], recvBuf[i].size(), MPI_DOUBLE, i, 0, + MPI_COMM_WORLD, &reqRecv[i]); } - if (!parentByProc[i].empty()) { + if(!parentByProc[i].empty()) { getDofValue(parentByProc[i], sendBuf[i]); - MPI_Isend(&sendBuf[i][0], sendBuf[i].size(), MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &reqSend[i]); + MPI_Isend(&sendBuf[i][0], sendBuf[i].size(), MPI_DOUBLE, i, 0, + MPI_COMM_WORLD, &reqSend[i]); } } int index; - while (MPI_Waitany (Msg::GetCommSize(), &reqRecv[0], &index, &status) == 0 && index != MPI_UNDEFINED) { - if (status.MPI_TAG == 0) - for (unsigned int j = 0; j < recvBuf[index].size(); j++) { + while(MPI_Waitany(Msg::GetCommSize(), &reqRecv[0], &index, &status) == 0 && + index != MPI_UNDEFINED) { + if(status.MPI_TAG == 0) + for(unsigned int j = 0; j < recvBuf[index].size(); j++) { ghostValue[ghostByProc[index][j]] = recvBuf[index][j]; - //const Dof &dof = ghostByProc[index][j]; + // const Dof &dof = ghostByProc[index][j]; } } - MPI_Waitall (Msg::GetCommSize(), &reqSend[0], MPI_STATUS_IGNORE); + MPI_Waitall(Msg::GetCommSize(), &reqSend[0], MPI_STATUS_IGNORE); #endif } @@ -53,71 +57,76 @@ void dofManagerBase::_parallelFinalize() MPI_Status status; parentByProc.resize(Msg::GetCommSize()); ghostByProc.resize(Msg::GetCommSize()); - if (Msg::GetCommRank() == 0){ + if(Msg::GetCommRank() == 0) { numStart = 0; } else - MPI_Recv (&numStart, 1, MPI_INT, Msg::GetCommRank()-1, 0, MPI_COMM_WORLD, &status); + MPI_Recv(&numStart, 1, MPI_INT, Msg::GetCommRank() - 1, 0, MPI_COMM_WORLD, + &status); numTotal = numStart + _localSize; - if (Msg::GetCommRank() != Msg::GetCommSize()-1) - MPI_Send (&numTotal, 1, MPI_INT, Msg::GetCommRank()+1, 0, MPI_COMM_WORLD); - MPI_Bcast(&numTotal, 1, MPI_INT, Msg::GetCommSize()-1, MPI_COMM_WORLD); - for (std::map <Dof, int> ::iterator it = unknown.begin(); it!= unknown.end(); it++) + if(Msg::GetCommRank() != Msg::GetCommSize() - 1) + MPI_Send(&numTotal, 1, MPI_INT, Msg::GetCommRank() + 1, 0, MPI_COMM_WORLD); + MPI_Bcast(&numTotal, 1, MPI_INT, Msg::GetCommSize() - 1, MPI_COMM_WORLD); + for(std::map<Dof, int>::iterator it = unknown.begin(); it != unknown.end(); + it++) it->second += numStart; - std::vector<std::list<Dof> > ghostedByProc; + std::vector<std::list<Dof> > ghostedByProc; int *nRequest = new int[Msg::GetCommSize()]; int *nRequested = new int[Msg::GetCommSize()]; - for (int i = 0; i<Msg::GetCommSize(); i++) - nRequest[i] = 0; - for (std::map <Dof, std::pair<int, int> >::iterator it = ghostByDof.begin(); it != ghostByDof.end(); it++) { + for(int i = 0; i < Msg::GetCommSize(); i++) nRequest[i] = 0; + for(std::map<Dof, std::pair<int, int> >::iterator it = ghostByDof.begin(); + it != ghostByDof.end(); it++) { int procId = it->second.first; it->second.second = nRequest[procId]++; } MPI_Alltoall(nRequest, 1, MPI_INT, nRequested, 1, MPI_INT, MPI_COMM_WORLD); - long int **recv0 = new long int*[Msg::GetCommSize()]; - int **recv1 = new int*[Msg::GetCommSize()]; - long int **send0 = new long int*[Msg::GetCommSize()]; - int **send1 = new int*[Msg::GetCommSize()]; - MPI_Request *reqRecv0 = new MPI_Request[2*Msg::GetCommSize()]; + long int **recv0 = new long int *[Msg::GetCommSize()]; + int **recv1 = new int *[Msg::GetCommSize()]; + long int **send0 = new long int *[Msg::GetCommSize()]; + int **send1 = new int *[Msg::GetCommSize()]; + MPI_Request *reqRecv0 = new MPI_Request[2 * Msg::GetCommSize()]; MPI_Request *reqRecv1 = reqRecv0 + Msg::GetCommSize(); MPI_Request *reqSend0 = new MPI_Request[Msg::GetCommSize()]; MPI_Request *reqSend1 = new MPI_Request[Msg::GetCommSize()]; - for (int i = 0; i < Msg::GetCommSize(); i++) { - send0[i] = new long int[nRequest[i]*2]; - recv0[i] = new long int[nRequested[i]*2]; + for(int i = 0; i < Msg::GetCommSize(); i++) { + send0[i] = new long int[nRequest[i] * 2]; + recv0[i] = new long int[nRequested[i] * 2]; send1[i] = new int[nRequested[i]]; recv1[i] = new int[nRequest[i]]; reqSend0[i] = reqSend1[i] = reqRecv0[i] = reqRecv1[i] = MPI_REQUEST_NULL; - parentByProc[i].resize(nRequested[i], Dof(0,0)); - ghostByProc[i].resize(nRequest[i], Dof(0,0)); + parentByProc[i].resize(nRequested[i], Dof(0, 0)); + ghostByProc[i].resize(nRequest[i], Dof(0, 0)); } - for (int i = 0; i<Msg::GetCommSize(); i++) - nRequest [i] = 0; - for (std::map <Dof, std::pair<int, int> >::iterator it = ghostByDof.begin(); it != ghostByDof.end(); it++) { + for(int i = 0; i < Msg::GetCommSize(); i++) nRequest[i] = 0; + for(std::map<Dof, std::pair<int, int> >::iterator it = ghostByDof.begin(); + it != ghostByDof.end(); it++) { int proc = it->second.first; - send0 [proc] [nRequest[proc]*2] = it->first.getEntity(); - send0 [proc] [nRequest[proc]*2+1] = it->first.getType(); + send0[proc][nRequest[proc] * 2] = it->first.getEntity(); + send0[proc][nRequest[proc] * 2 + 1] = it->first.getType(); ghostByProc[proc][nRequest[proc]] = it->first; - nRequest [proc] ++; + nRequest[proc]++; } - for (int i = 0; i<Msg::GetCommSize(); i++) { - if (nRequested[i] > 0) { - MPI_Irecv (recv0[i], 2*nRequested[i], MPI_LONG, i, 0, MPI_COMM_WORLD, &reqRecv0[i]); + for(int i = 0; i < Msg::GetCommSize(); i++) { + if(nRequested[i] > 0) { + MPI_Irecv(recv0[i], 2 * nRequested[i], MPI_LONG, i, 0, MPI_COMM_WORLD, + &reqRecv0[i]); } - if (nRequest[i] > 0) { - MPI_Irecv (recv1[i], 2*nRequest[i], MPI_INT, i, 1, MPI_COMM_WORLD, &reqRecv1[i]); - MPI_Isend (send0[i], 2*nRequest[i], MPI_LONG, i, 0, MPI_COMM_WORLD, &reqSend0[i]); + if(nRequest[i] > 0) { + MPI_Irecv(recv1[i], 2 * nRequest[i], MPI_INT, i, 1, MPI_COMM_WORLD, + &reqRecv1[i]); + MPI_Isend(send0[i], 2 * nRequest[i], MPI_LONG, i, 0, MPI_COMM_WORLD, + &reqSend0[i]); } } int index; - while (MPI_Waitany (2*Msg::GetCommSize(), reqRecv0, &index, &status) == 0 && - index != MPI_UNDEFINED) { - if (status.MPI_TAG == 0) { - for (int j = 0; j < nRequested[index]; j++) { - Dof d(recv0[index][j*2], recv0[index][j*2+1]); + while(MPI_Waitany(2 * Msg::GetCommSize(), reqRecv0, &index, &status) == 0 && + index != MPI_UNDEFINED) { + if(status.MPI_TAG == 0) { + for(int j = 0; j < nRequested[index]; j++) { + Dof d(recv0[index][j * 2], recv0[index][j * 2 + 1]); std::map<Dof, int>::iterator it = unknown.find(d); - if (it == unknown.end ()) - Msg::Error ("ghost Dof does not exist on parent process"); + if(it == unknown.end()) + Msg::Error("ghost Dof does not exist on parent process"); send1[index][j] = it->second; parentByProc[index][j] = d; } @@ -125,30 +134,28 @@ void dofManagerBase::_parallelFinalize() MPI_COMM_WORLD, &reqSend1[index]); } } - for (int i = 0; i<Msg::GetCommSize(); i++) - for (int i = 0; i<Msg::GetCommSize(); i++) - nRequest[i] = 0; - for (std::map <Dof, std::pair<int, int> >::iterator it = ghostByDof.begin(); it != ghostByDof.end(); it++) { + for(int i = 0; i < Msg::GetCommSize(); i++) + for(int i = 0; i < Msg::GetCommSize(); i++) nRequest[i] = 0; + for(std::map<Dof, std::pair<int, int> >::iterator it = ghostByDof.begin(); + it != ghostByDof.end(); it++) { int proc = it->second.first; - unknown[it->first] = recv1 [proc][nRequest[proc] ++]; + unknown[it->first] = recv1[proc][nRequest[proc]++]; } - MPI_Waitall (Msg::GetCommSize(), reqSend0, MPI_STATUS_IGNORE); - MPI_Waitall (Msg::GetCommSize(), reqSend1, MPI_STATUS_IGNORE); - for (int i = 0; i < Msg::GetCommSize(); i++) { - delete [] send0[i]; - delete [] send1[i]; - delete [] recv0[i]; - delete [] recv1[i]; + MPI_Waitall(Msg::GetCommSize(), reqSend0, MPI_STATUS_IGNORE); + MPI_Waitall(Msg::GetCommSize(), reqSend1, MPI_STATUS_IGNORE); + for(int i = 0; i < Msg::GetCommSize(); i++) { + delete[] send0[i]; + delete[] send1[i]; + delete[] recv0[i]; + delete[] recv1[i]; } - delete [] send0; - delete [] send1; - delete [] recv0; - delete [] recv1; - delete [] reqSend0; - delete [] reqSend1; - delete [] reqRecv0; + delete[] send0; + delete[] send1; + delete[] recv0; + delete[] recv1; + delete[] reqSend0; + delete[] reqSend1; + delete[] reqRecv0; #endif _parallelFinalized = true; } - - diff --git a/Solver/dofManager.h b/Solver/dofManager.h index bdcc5fddbd55e6bcdf6408dab7ae977652ec516c..1592eff0ec7b78bf2424f8b81808a28b869a6d07 100644 --- a/Solver/dofManager.h +++ b/Solver/dofManager.h @@ -16,12 +16,12 @@ #include "linearSystem.h" #include "fullMatrix.h" -class Dof{ - protected: +class Dof { +protected: // v(x) = \sum_f \sum_i v_{fi} s^f_i(x) long int _entity; // "i": node, edge, group, etc. int _type; // "f": basis function type index, etc. - public: +public: Dof(long int entity, int type) : _entity(entity), _type(type) {} inline long int getEntity() const { return _entity; } inline int getType() const { return _type; } @@ -34,20 +34,20 @@ class Dof{ i1 = t % 10000; i2 = t / 10000; } - bool operator < (const Dof &other) const + bool operator<(const Dof &other) const { if(_entity < other._entity) return true; if(_entity > other._entity) return false; if(_type < other._type) return true; return false; } - bool operator == (const Dof &other) const{ + bool operator==(const Dof &other) const + { return (_entity == other._entity && _type == other._type); } }; -template<class T> struct dofTraits -{ +template <class T> struct dofTraits { typedef T VecType; typedef T MatType; inline static void gemm(VecType &r, const MatType &m, const VecType &v, @@ -57,14 +57,13 @@ template<class T> struct dofTraits } }; -template<class T> struct dofTraits<fullMatrix<T> > -{ +template <class T> struct dofTraits<fullMatrix<T> > { typedef fullMatrix<T> VecType; typedef fullMatrix<T> MatType; - inline static void gemm (VecType &r, const MatType &m, const VecType &v, - double alpha, double beta) + inline static void gemm(VecType &r, const MatType &m, const VecType &v, + double alpha, double beta) { - r.gemm(m, v, alpha,beta); + r.gemm(m, v, alpha, beta); } }; @@ -76,16 +75,16 @@ template<> struct dofTraits<fullVector<std::complex<double> > > }; */ -template<class T> -class DofAffineConstraint{ - public: +template <class T> class DofAffineConstraint { +public: std::vector<std::pair<Dof, typename dofTraits<T>::MatType> > linear; typename dofTraits<T>::VecType shift; }; -//non template part that can be implemented in the cxx file (and so avoid to include mpi.h in the .h file) -class dofManagerBase{ - protected: +// non template part that can be implemented in the cxx file (and so avoid to +// include mpi.h in the .h file) +class dofManagerBase { +protected: // numbering of unknown dof blocks std::map<Dof, int> unknown; @@ -93,15 +92,16 @@ class dofManagerBase{ std::map<Dof, Dof> associatedWith; // parallel section - // those dof are images of ghost located on another proc (id givent by the map). - // this is a first try, maybe not the final implementation - std::map<Dof, std::pair<int, int> > ghostByDof; // dof => procId, globalId + // those dof are images of ghost located on another proc (id givent by the + // map). this is a first try, maybe not the final implementation + std::map<Dof, std::pair<int, int> > ghostByDof; // dof => procId, globalId std::vector<std::vector<Dof> > ghostByProc, parentByProc; int _localSize; bool _parallelFinalized; bool _isParallel; void _parallelFinalize(); - dofManagerBase(bool isParallel) { + dofManagerBase(bool isParallel) + { _isParallel = isParallel; _parallelFinalized = false; } @@ -110,16 +110,16 @@ class dofManagerBase{ // A manager for degrees of freedoms, templated on the value of a dof // (what the functional returns): float, double, complex<double>, // fullVecor<double>, ... -template <class T> -class dofManager : public dofManagerBase{ - public: +template <class T> class dofManager : public dofManagerBase { +public: typedef typename dofTraits<T>::VecType dataVec; typedef typename dofTraits<T>::MatType dataMat; - protected: + +protected: // general affine constraint on sub-blocks, treated by adding // equations: // Dof = \sum_i dataMat_i x Dof_i + dataVec - std::map<Dof, DofAffineConstraint< dataVec > > constraints; + std::map<Dof, DofAffineConstraint<dataVec> > constraints; // fixations on full blocks, treated by eliminating equations: // DofVec = dataVec @@ -130,42 +130,42 @@ class dofManager : public dofManagerBase{ // linearSystems linearSystem<dataMat> *_current; - std::map<const std::string, linearSystem<dataMat>*> _linearSystems; + std::map<const std::string, linearSystem<dataMat> *> _linearSystems; std::map<Dof, T> ghostValue; - public: + +public: void scatterSolution(); - public: - dofManager(linearSystem<dataMat> *l, bool isParallel=false) - :dofManagerBase(isParallel), _current(l) +public: + dofManager(linearSystem<dataMat> *l, bool isParallel = false) + : dofManagerBase(isParallel), _current(l) { _linearSystems["A"] = l; } dofManager(linearSystem<dataMat> *l1, linearSystem<dataMat> *l2) - :dofManagerBase(false), _current(l1) + : dofManagerBase(false), _current(l1) { _linearSystems.insert(std::make_pair("A", l1)); _linearSystems.insert(std::make_pair("B", l2)); } - virtual ~dofManager(){} + virtual ~dofManager() {} virtual inline void fixDof(Dof key, const dataVec &value) { - if(unknown.find(key) != unknown.end()) - return; + if(unknown.find(key) != unknown.end()) return; fixed[key] = value; } inline void fixDof(long int ent, int type, const dataVec &value) { fixDof(Dof(ent, type), value); } - void fixVertex(MVertex const* v, int iComp, int iField, const dataVec &value) + void fixVertex(MVertex const *v, int iComp, int iField, const dataVec &value) { fixDof(v->getNum(), Dof::createTypeWithTwoInts(iComp, iField), value); } virtual inline bool isFixed(Dof key) const { - if(fixed.find(key) != fixed.end()){ + if(fixed.find(key) != fixed.end()) { return true; } return false; @@ -173,17 +173,15 @@ class dofManager : public dofManagerBase{ virtual inline bool isAnUnknown(Dof key) const { - if(ghostValue.find(key) == ghostValue.end()) - { - if(unknown.find(key) != unknown.end()) - return true; + if(ghostValue.find(key) == ghostValue.end()) { + if(unknown.find(key) != unknown.end()) return true; } return false; } virtual inline bool isConstrained(Dof key) const { - if(constraints.find(key) != constraints.end()){ + if(constraints.find(key) != constraints.end()) { return true; } return false; @@ -193,56 +191,52 @@ class dofManager : public dofManagerBase{ { return isFixed(Dof(ent, type)); } - inline bool isFixed(MVertex*v, int iComp, int iField) const + inline bool isFixed(MVertex *v, int iComp, int iField) const { return isFixed(v->getNum(), Dof::createTypeWithTwoInts(iComp, iField)); } - virtual inline void numberGhostDof (Dof key, int procId) { - if (fixed.find(key) != fixed.end()) return; - if (constraints.find(key) != constraints.end()) return; - if (ghostByDof.find(key) != ghostByDof.end()) return; + virtual inline void numberGhostDof(Dof key, int procId) + { + if(fixed.find(key) != fixed.end()) return; + if(constraints.find(key) != constraints.end()) return; + if(ghostByDof.find(key) != ghostByDof.end()) return; ghostByDof[key] = std::make_pair(procId, 0); } virtual inline void numberDof(Dof key) { - if (fixed.find(key) != fixed.end()) return; - if (constraints.find(key) != constraints.end()) return; - if (ghostByDof.find(key) != ghostByDof.end()) return; + if(fixed.find(key) != fixed.end()) return; + if(constraints.find(key) != constraints.end()) return; + if(ghostByDof.find(key) != ghostByDof.end()) return; - std::map<Dof, int> :: iterator it = unknown.find(key); - if (it == unknown.end()) { + std::map<Dof, int>::iterator it = unknown.find(key); + if(it == unknown.end()) { unsigned int size = unknown.size(); unknown[key] = size; } } virtual inline void numberDof(const std::vector<Dof> &R) { - for(unsigned int i=0;i<R.size();i++) - this->numberDof(R[i]); + for(unsigned int i = 0; i < R.size(); i++) this->numberDof(R[i]); } - inline void numberDof(long int ent, int type) - { - numberDof(Dof(ent, type)); - } - inline void numberVertex(MVertex*v, int iComp, int iField) + inline void numberDof(long int ent, int type) { numberDof(Dof(ent, type)); } + inline void numberVertex(MVertex *v, int iComp, int iField) { numberDof(v->getNum(), Dof::createTypeWithTwoInts(iComp, iField)); } - virtual inline void getDofValue(std::vector<Dof> &keys, std::vector<dataVec> &Vals) + virtual inline void getDofValue(std::vector<Dof> &keys, + std::vector<dataVec> &Vals) { int ndofs = keys.size(); size_t originalSize = Vals.size(); Vals.resize(originalSize + ndofs); - for (int i = 0; i < ndofs; ++i) getDofValue(keys[i], Vals[originalSize+i]); + for(int i = 0; i < ndofs; ++i) getDofValue(keys[i], Vals[originalSize + i]); } - virtual inline bool getAnUnknown(Dof key, dataVec &val) const + virtual inline bool getAnUnknown(Dof key, dataVec &val) const { - if(ghostValue.find(key) == ghostValue.end()) - { + if(ghostValue.find(key) == ghostValue.end()) { std::map<Dof, int>::const_iterator it = unknown.find(key); - if (it != unknown.end()) - { + if(it != unknown.end()) { _current->getFromSolution(it->second, val); return true; } @@ -250,55 +244,55 @@ class dofManager : public dofManagerBase{ return false; } - virtual inline void getFixedDofValue(Dof key, dataVec& val) const{ - typename std::map<Dof, dataVec>::const_iterator it = fixed.find(key); - if (it != fixed.end()) { - val = it->second; + virtual inline void getFixedDofValue(Dof key, dataVec &val) const + { + typename std::map<Dof, dataVec>::const_iterator it = fixed.find(key); + if(it != fixed.end()) { + val = it->second; + } + else { + Msg::Error("getFixedDof: Dof is not fixed"); + return; } - else{ - Msg::Error("getFixedDof: Dof is not fixed"); - return; - } - }; - virtual inline void getDofValue(Dof key, dataVec &val) const + virtual inline void getDofValue(Dof key, dataVec &val) const { { typename std::map<Dof, dataVec>::const_iterator it = ghostValue.find(key); - if (it != ghostValue.end()) { - val = it->second; + if(it != ghostValue.end()) { + val = it->second; return; } } { std::map<Dof, int>::const_iterator it = unknown.find(key); - if (it != unknown.end()) { + if(it != unknown.end()) { _current->getFromSolution(it->second, val); return; } } { typename std::map<Dof, dataVec>::const_iterator it = fixed.find(key); - if (it != fixed.end()) { - val = it->second; + if(it != fixed.end()) { + val = it->second; return; } } { - typename std::map<Dof, DofAffineConstraint< dataVec > >::const_iterator it = + typename std::map<Dof, DofAffineConstraint<dataVec> >::const_iterator it = constraints.find(key); - if (it != constraints.end()){ + if(it != constraints.end()) { dataVec tmp(val); val = it->second.shift; - for (unsigned i = 0; i < (it->second).linear.size(); i++){ + for(unsigned i = 0; i < (it->second).linear.size(); i++) { /* gcc: warning: variable ‘itu’ set but not used std::map<Dof, int>::const_iterator itu = unknown.find (((it->second).linear[i]).first);*/ getDofValue(((it->second).linear[i]).first, tmp); dofTraits<T>::gemm(val, ((it->second).linear[i]).second, tmp, 1, 1); } - return ; + return; } } } @@ -306,29 +300,32 @@ class dofManager : public dofManagerBase{ { getDofValue(Dof(ent, type), v); } - inline void getDofValue(MVertex *v, int iComp, int iField, dataVec &value) const + inline void getDofValue(MVertex *v, int iComp, int iField, + dataVec &value) const { getDofValue(v->getNum(), Dof::createTypeWithTwoInts(iComp, iField), value); } - virtual inline void insertInSparsityPatternLinConst(const Dof &R, const Dof &C) + virtual inline void insertInSparsityPatternLinConst(const Dof &R, + const Dof &C) { std::map<Dof, int>::iterator itR = unknown.find(R); - if (itR != unknown.end()) - { - typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator itConstraint; + if(itR != unknown.end()) { + typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator + itConstraint; itConstraint = constraints.find(C); - if (itConstraint != constraints.end()){ - for (unsigned i = 0; i < (itConstraint->second).linear.size(); i++){ + if(itConstraint != constraints.end()) { + for(unsigned i = 0; i < (itConstraint->second).linear.size(); i++) { insertInSparsityPattern(R, (itConstraint->second).linear[i].first); } } } - else{ // test function ; (no shift ?) - typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator itConstraint; + else { // test function ; (no shift ?) + typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator + itConstraint; itConstraint = constraints.find(R); - if (itConstraint != constraints.end()){ - for (unsigned i = 0; i < (itConstraint->second).linear.size(); i++){ + if(itConstraint != constraints.end()) { + for(unsigned i = 0; i < (itConstraint->second).linear.size(); i++) { insertInSparsityPattern((itConstraint->second).linear[i].first, C); } } @@ -337,193 +334,212 @@ class dofManager : public dofManagerBase{ virtual inline void insertInSparsityPattern(const Dof &R, const Dof &C) { - if (_isParallel && !_parallelFinalized) _parallelFinalize(); - if (!_current->isAllocated()) _current->allocate (sizeOfR()); + if(_isParallel && !_parallelFinalized) _parallelFinalize(); + if(!_current->isAllocated()) _current->allocate(sizeOfR()); std::map<Dof, int>::iterator itR = unknown.find(R); - if (itR != unknown.end()){ + if(itR != unknown.end()) { std::map<Dof, int>::iterator itC = unknown.find(C); - if (itC != unknown.end()){ + if(itC != unknown.end()) { _current->insertInSparsityPattern(itR->second, itC->second); } - else{ + else { typename std::map<Dof, dataVec>::iterator itFixed = fixed.find(C); - if (itFixed != fixed.end()) { + if(itFixed != fixed.end()) { } - else insertInSparsityPatternLinConst(R, C); + else + insertInSparsityPatternLinConst(R, C); } } - if (itR == unknown.end()) - { + if(itR == unknown.end()) { insertInSparsityPatternLinConst(R, C); } } - virtual inline void sparsityDof(const std::vector<Dof> &keys){ - for (unsigned int itR=0; itR< keys.size(); itR++){ - for (unsigned int itC=0; itC<keys.size(); itC++){ - insertInSparsityPattern(keys[itR],keys[itC]); + virtual inline void sparsityDof(const std::vector<Dof> &keys) + { + for(unsigned int itR = 0; itR < keys.size(); itR++) { + for(unsigned int itC = 0; itC < keys.size(); itC++) { + insertInSparsityPattern(keys[itR], keys[itC]); } } } virtual inline void assemble(const Dof &R, const Dof &C, const dataMat &value) { - if (_isParallel && !_parallelFinalized) _parallelFinalize(); - if (!_current->isAllocated()) _current->allocate (sizeOfR()); + if(_isParallel && !_parallelFinalized) _parallelFinalize(); + if(!_current->isAllocated()) _current->allocate(sizeOfR()); std::map<Dof, int>::iterator itR = unknown.find(R); - if (itR != unknown.end()){ + if(itR != unknown.end()) { std::map<Dof, int>::iterator itC = unknown.find(C); - if (itC != unknown.end()){ + if(itC != unknown.end()) { _current->addToMatrix(itR->second, itC->second, value); } - else{ + else { typename std::map<Dof, dataVec>::iterator itFixed = fixed.find(C); - if (itFixed != fixed.end()) { + if(itFixed != fixed.end()) { // tmp = -value * itFixed->second dataVec tmp(itFixed->second); dofTraits<T>::gemm(tmp, value, itFixed->second, -1, 0); _current->addToRightHandSide(itR->second, tmp); } - else assembleLinConst(R, C, value); + else + assembleLinConst(R, C, value); } } - if (itR == unknown.end()) - { + if(itR == unknown.end()) { assembleLinConst(R, C, value); } } virtual inline void assemble(std::vector<Dof> &R, std::vector<Dof> &C, - const fullMatrix<dataMat> &m) + const fullMatrix<dataMat> &m) { - if (_isParallel && !_parallelFinalized) _parallelFinalize(); - if (!_current->isAllocated()) _current->allocate(sizeOfR()); + if(_isParallel && !_parallelFinalized) _parallelFinalize(); + if(!_current->isAllocated()) _current->allocate(sizeOfR()); std::vector<int> NR(R.size()), NC(C.size()); - for (unsigned int i = 0; i < R.size(); i++){ + for(unsigned int i = 0; i < R.size(); i++) { std::map<Dof, int>::iterator itR = unknown.find(R[i]); - if (itR != unknown.end()) NR[i] = itR->second; - else NR[i] = -1; + if(itR != unknown.end()) + NR[i] = itR->second; + else + NR[i] = -1; } - for (unsigned int i = 0; i < C.size(); i++){ + for(unsigned int i = 0; i < C.size(); i++) { std::map<Dof, int>::iterator itC = unknown.find(C[i]); - if (itC != unknown.end()) NC[i] = itC->second; - else NC[i] = -1; - } - for (unsigned int i = 0; i < R.size(); i++){ - if (NR[i] != -1){ - for (unsigned int j = 0; j < C.size(); j++){ - if (NC[j] != -1){ + if(itC != unknown.end()) + NC[i] = itC->second; + else + NC[i] = -1; + } + for(unsigned int i = 0; i < R.size(); i++) { + if(NR[i] != -1) { + for(unsigned int j = 0; j < C.size(); j++) { + if(NC[j] != -1) { _current->addToMatrix(NR[i], NC[j], m(i, j)); } - else{ - typename std::map<Dof, dataVec>::iterator itFixed = fixed.find(C[j]); - if (itFixed != fixed.end()){ + else { + typename std::map<Dof, dataVec>::iterator itFixed = + fixed.find(C[j]); + if(itFixed != fixed.end()) { // tmp = -m(i,j) * itFixed->second dataVec tmp(itFixed->second); dofTraits<T>::gemm(tmp, m(i, j), itFixed->second, -1, 0); _current->addToRightHandSide(NR[i], tmp); } - else assembleLinConst(R[i], C[j], m(i, j)); + else + assembleLinConst(R[i], C[j], m(i, j)); } } } - else{ - for (unsigned int j = 0; j < C.size(); j++){ + else { + for(unsigned int j = 0; j < C.size(); j++) { assembleLinConst(R[i], C[j], m(i, j)); } } } } // for linear forms - virtual inline void assemble(std::vector<Dof> &R, const fullVector<dataMat> &m) + virtual inline void assemble(std::vector<Dof> &R, + const fullVector<dataMat> &m) { - if (_isParallel && !_parallelFinalized) _parallelFinalize(); - if (!_current->isAllocated()) _current->allocate(sizeOfR()); + if(_isParallel && !_parallelFinalized) _parallelFinalize(); + if(!_current->isAllocated()) _current->allocate(sizeOfR()); std::vector<int> NR(R.size()); - for (unsigned int i = 0; i < R.size(); i++){ + for(unsigned int i = 0; i < R.size(); i++) { std::map<Dof, int>::iterator itR = unknown.find(R[i]); - if (itR != unknown.end()) NR[i] = itR->second; - else NR[i] = -1; + if(itR != unknown.end()) + NR[i] = itR->second; + else + NR[i] = -1; } - for (unsigned int i = 0; i < R.size(); i++){ - if (NR[i] != -1){ + for(unsigned int i = 0; i < R.size(); i++) { + if(NR[i] != -1) { _current->addToRightHandSide(NR[i], m(i)); } - else{ - typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator itConstraint; + else { + typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator + itConstraint; itConstraint = constraints.find(R[i]); - if (itConstraint != constraints.end()){ - for (unsigned j = 0; j < (itConstraint->second).linear.size(); j++){ + if(itConstraint != constraints.end()) { + for(unsigned j = 0; j < (itConstraint->second).linear.size(); j++) { dataMat tmp; - dofTraits<T>::gemm(tmp, (itConstraint->second).linear[j].second, m(i), 1, 0); + dofTraits<T>::gemm(tmp, (itConstraint->second).linear[j].second, + m(i), 1, 0); assemble((itConstraint->second).linear[j].first, tmp); } } } } } - virtual inline void assemble(std::vector<Dof> &R, const fullMatrix<dataMat> &m) + virtual inline void assemble(std::vector<Dof> &R, + const fullMatrix<dataMat> &m) { - if (_isParallel && !_parallelFinalized) _parallelFinalize(); - if (!_current->isAllocated()) _current->allocate(sizeOfR()); + if(_isParallel && !_parallelFinalized) _parallelFinalize(); + if(!_current->isAllocated()) _current->allocate(sizeOfR()); std::vector<int> NR(R.size()); - for (unsigned int i = 0; i < R.size(); i++){ + for(unsigned int i = 0; i < R.size(); i++) { std::map<Dof, int>::iterator itR = unknown.find(R[i]); - if (itR != unknown.end()) NR[i] = itR->second; - else NR[i] = -1; - } - for (unsigned int i = 0; i < R.size(); i++){ - if (NR[i] != -1){ - for (unsigned int j = 0; j < R.size(); j++){ - if (NR[j] != -1){ + if(itR != unknown.end()) + NR[i] = itR->second; + else + NR[i] = -1; + } + for(unsigned int i = 0; i < R.size(); i++) { + if(NR[i] != -1) { + for(unsigned int j = 0; j < R.size(); j++) { + if(NR[j] != -1) { _current->addToMatrix(NR[i], NR[j], m(i, j)); } - else{ - typename std::map<Dof, dataVec>::iterator itFixed = fixed.find(R[j]); - if (itFixed != fixed.end()){ + else { + typename std::map<Dof, dataVec>::iterator itFixed = + fixed.find(R[j]); + if(itFixed != fixed.end()) { // tmp = -m(i,j) * itFixed->second dataVec tmp(itFixed->second); dofTraits<T>::gemm(tmp, m(i, j), itFixed->second, -1, 0); _current->addToRightHandSide(NR[i], tmp); - } else assembleLinConst(R[i], R[j], m(i, j)); + } + else + assembleLinConst(R[i], R[j], m(i, j)); } } } - else{ - for (unsigned int j = 0; j < R.size(); j++){ + else { + for(unsigned int j = 0; j < R.size(); j++) { assembleLinConst(R[i], R[j], m(i, j)); } } } } - inline void assemble(int entR, int typeR, int entC, int typeC, const dataMat &value) + inline void assemble(int entR, int typeR, int entC, int typeC, + const dataMat &value) { assemble(Dof(entR, typeR), Dof(entC, typeC), value); } - inline void assemble(MVertex *vR, int iCompR, int iFieldR, - MVertex *vC, int iCompC, int iFieldC, - const dataMat &value) + inline void assemble(MVertex *vR, int iCompR, int iFieldR, MVertex *vC, + int iCompC, int iFieldC, const dataMat &value) { assemble(vR->getNum(), Dof::createTypeWithTwoInts(iCompR, iFieldR), - vC->getNum(), Dof::createTypeWithTwoInts(iCompC, iFieldC), - value); + vC->getNum(), Dof::createTypeWithTwoInts(iCompC, iFieldC), value); } virtual inline void assemble(const Dof &R, const dataMat &value) { - if (_isParallel && !_parallelFinalized) _parallelFinalize(); + if(_isParallel && !_parallelFinalized) _parallelFinalize(); if(!_current->isAllocated()) _current->allocate(sizeOfR()); std::map<Dof, int>::iterator itR = unknown.find(R); - if(itR != unknown.end()){ + if(itR != unknown.end()) { _current->addToRightHandSide(itR->second, value); } - else{ - typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator itConstraint; + else { + typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator + itConstraint; itConstraint = constraints.find(R); - if (itConstraint != constraints.end()){ - for (unsigned j = 0; j < (itConstraint->second).linear.size(); j++){ + if(itConstraint != constraints.end()) { + for(unsigned j = 0; j < (itConstraint->second).linear.size(); j++) { dataMat tmp; - dofTraits<T>::gemm(tmp, (itConstraint->second).linear[j].second, value, 1, 0); + dofTraits<T>::gemm(tmp, (itConstraint->second).linear[j].second, + value, 1, 0); assemble((itConstraint->second).linear[j].first, tmp); } } @@ -534,13 +550,16 @@ class dofManager : public dofManagerBase{ assemble(Dof(entR, typeR), value); } inline void assemble(MVertex *vR, int iCompR, int iFieldR, - const dataMat &value) + const dataMat &value) { assemble(vR->getNum(), Dof::createTypeWithTwoInts(iCompR, iFieldR), value); } - virtual int sizeOfR() const { return _isParallel ? _localSize : unknown.size(); } + virtual int sizeOfR() const + { + return _isParallel ? _localSize : unknown.size(); + } virtual int sizeOfF() const { return fixed.size(); } - virtual void systemSolve(){ _current->systemSolve(); } + virtual void systemSolve() { _current->systemSolve(); } virtual void systemClear() { _current->zeroMatrix(); @@ -548,52 +567,56 @@ class dofManager : public dofManagerBase{ } virtual inline void setCurrentMatrix(std::string name) { - typename std::map<const std::string, linearSystem<dataMat>*>::iterator it = + typename std::map<const std::string, linearSystem<dataMat> *>::iterator it = _linearSystems.find(name); if(it != _linearSystems.end()) _current = it->second; - else{ + else { Msg::Error("Current matrix %s not found ", name.c_str()); throw; } } virtual linearSystem<dataMat> *getLinearSystem(std::string &name) { - typename std::map<const std::string, linearSystem<dataMat>*>::iterator it = + typename std::map<const std::string, linearSystem<dataMat> *>::iterator it = _linearSystems.find(name); if(it != _linearSystems.end()) return it->second; else return 0; } - virtual inline void setLinearConstraint (Dof key, DofAffineConstraint<dataVec> &affineconstraint) + virtual inline void + setLinearConstraint(Dof key, DofAffineConstraint<dataVec> &affineconstraint) { constraints[key] = affineconstraint; // constraints.insert(std::make_pair(key, affineconstraint)); } - virtual inline bool getLinearConstraint (Dof key, DofAffineConstraint<dataVec> &affineconstraint) + virtual inline bool + getLinearConstraint(Dof key, DofAffineConstraint<dataVec> &affineconstraint) { - typename std::map<Dof, DofAffineConstraint< dataVec > >::const_iterator it=constraints.find(key); - if (it!=constraints.end()) - { - affineconstraint=it->second; + typename std::map<Dof, DofAffineConstraint<dataVec> >::const_iterator it = + constraints.find(key); + if(it != constraints.end()) { + affineconstraint = it->second; return true; } return false; } - virtual inline void assembleLinConst(const Dof &R, const Dof &C, const dataMat &value) + virtual inline void assembleLinConst(const Dof &R, const Dof &C, + const dataMat &value) { std::map<Dof, int>::iterator itR = unknown.find(R); - if (itR != unknown.end()) - { - typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator itConstraint; + if(itR != unknown.end()) { + typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator + itConstraint; itConstraint = constraints.find(C); - if (itConstraint != constraints.end()){ + if(itConstraint != constraints.end()) { dataMat tmp(value); - for (unsigned i = 0; i < (itConstraint->second).linear.size(); i++){ - dofTraits<T>::gemm(tmp, (itConstraint->second).linear[i].second, value, 1, 0); + for(unsigned i = 0; i < (itConstraint->second).linear.size(); i++) { + dofTraits<T>::gemm(tmp, (itConstraint->second).linear[i].second, + value, 1, 0); assemble(R, (itConstraint->second).linear[i].first, tmp); } dataMat tmp2(value); @@ -601,13 +624,15 @@ class dofManager : public dofManagerBase{ _current->addToRightHandSide(itR->second, tmp2); } } - else{ // test function ; (no shift ?) - typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator itConstraint; + else { // test function ; (no shift ?) + typename std::map<Dof, DofAffineConstraint<dataVec> >::iterator + itConstraint; itConstraint = constraints.find(R); - if (itConstraint != constraints.end()){ + if(itConstraint != constraints.end()) { dataMat tmp(value); - for (unsigned i = 0; i < (itConstraint->second).linear.size(); i++){ - dofTraits<T>::gemm(tmp, itConstraint->second.linear[i].second, value, 1, 0); + for(unsigned i = 0; i < (itConstraint->second).linear.size(); i++) { + dofTraits<T>::gemm(tmp, itConstraint->second.linear[i].second, value, + 1, 0); assemble((itConstraint->second).linear[i].first, C, tmp); } } @@ -618,33 +643,33 @@ class dofManager : public dofManagerBase{ R.clear(); R.reserve(fixed.size()); typename std::map<Dof, dataVec>::iterator it; - for(it = fixed.begin(); it != fixed.end(); ++it){ + for(it = fixed.begin(); it != fixed.end(); ++it) { R.push_back(it->first); } } - virtual void getFixedDof(std::set<Dof>& R) - { - R.clear(); - typename std::map<Dof, dataVec>::iterator it; - for(it = fixed.begin(); it != fixed.end(); ++it){ + virtual void getFixedDof(std::set<Dof> &R) + { + R.clear(); + typename std::map<Dof, dataVec>::iterator it; + for(it = fixed.begin(); it != fixed.end(); ++it) { R.insert(it->first); } - } + } - virtual int getDofNumber(const Dof& key) + virtual int getDofNumber(const Dof &key) { - std::map<Dof,int>::iterator it = unknown.find(key); - if (it == unknown.end()){ + std::map<Dof, int>::iterator it = unknown.find(key); + if(it == unknown.end()) { return -1; } - else return it->second; + else + return it->second; } - virtual void clearAllLineConstraints() { - constraints.clear(); - } + virtual void clearAllLineConstraints() { constraints.clear(); } - std::map<Dof, DofAffineConstraint< dataVec > >& getAllLinearConstraints(){ + std::map<Dof, DofAffineConstraint<dataVec> > &getAllLinearConstraints() + { return constraints; }; }; diff --git a/Solver/eigenSolver.cpp b/Solver/eigenSolver.cpp index 266964983915dd1b5de1759ffbb7e4694c1f97c1..7a739c46c86ab5c1111b445ef9cf0334f12e3465 100644 --- a/Solver/eigenSolver.cpp +++ b/Solver/eigenSolver.cpp @@ -9,34 +9,36 @@ #if defined(HAVE_SLEPC) #include <slepceps.h> -#if SLEPC_VERSION_RELEASE != 0 && (SLEPC_VERSION_MAJOR < 3 || (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR < 2)) +#if SLEPC_VERSION_RELEASE != 0 && \ + (SLEPC_VERSION_MAJOR < 3 || \ + (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR < 2)) #define EPSDestroy(e) EPSDestroy(*(e)) #endif -void eigenSolver::_try(int ierr) const -{ - CHKERRABORT(PETSC_COMM_WORLD, ierr); -} +void eigenSolver::_try(int ierr) const { CHKERRABORT(PETSC_COMM_WORLD, ierr); } -eigenSolver::eigenSolver(dofManager<double> *manager, std::string A, std::string B, - bool hermitian) +eigenSolver::eigenSolver(dofManager<double> *manager, std::string A, + std::string B, bool hermitian) : _A(0), _B(0), _hermitian(hermitian) { - if (A.size()) { - _A = dynamic_cast<linearSystemPETSc<double>*>(manager->getLinearSystem(A)); + if(A.size()) { + _A = dynamic_cast<linearSystemPETSc<double> *>(manager->getLinearSystem(A)); if(!_A) Msg::Error("Could not find PETSc system '%s'", A.c_str()); } - if (B.size()) { - _B = dynamic_cast<linearSystemPETSc<double>*>(manager->getLinearSystem(B)); + if(B.size()) { + _B = dynamic_cast<linearSystemPETSc<double> *>(manager->getLinearSystem(B)); if(!_B) Msg::Error("Could not find PETSc system '%s'", B.c_str()); } } -eigenSolver::eigenSolver(linearSystemPETSc<double> *A, linearSystemPETSc<double> *B, - bool hermitian) : _A(A), _B(B), _hermitian(hermitian) {} +eigenSolver::eigenSolver(linearSystemPETSc<double> *A, + linearSystemPETSc<double> *B, bool hermitian) + : _A(A), _B(B), _hermitian(hermitian) +{ +} -bool eigenSolver::solve(int numEigenValues, std::string which, std::string method, - double tolVal, int iterMax) +bool eigenSolver::solve(int numEigenValues, std::string which, + std::string method, double tolVal, int iterMax) { if(!_A) return false; Mat A = _A->getMatrix(); @@ -48,7 +50,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho _try(MatGetSize(A, &N, &M)); PetscInt N2, M2; - if (_B) { + if(_B) { _try(MatAssemblyBegin(B, MAT_FINAL_ASSEMBLY)); _try(MatAssemblyEnd(B, MAT_FINAL_ASSEMBLY)); _try(MatGetSize(B, &N2, &M2)); @@ -66,13 +68,13 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho // set some default options _try(EPSSetDimensions(eps, numEigenValues, PETSC_DECIDE, PETSC_DECIDE)); _try(EPSSetTolerances(eps, tolVal, iterMax)); - if (method=="krylovschur") + if(method == "krylovschur") _try(EPSSetType(eps, EPSKRYLOVSCHUR)); - else if (method=="arnoldi") + else if(method == "arnoldi") _try(EPSSetType(eps, EPSARNOLDI)); - else if (method=="arpack") + else if(method == "arpack") _try(EPSSetType(eps, EPSARPACK)); - else if (method=="power") + else if(method == "power") _try(EPSSetType(eps, EPSPOWER)); else Msg::Fatal("eigenSolver: method '%s' not available", method.c_str()); @@ -81,17 +83,19 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho _try(EPSSetFromOptions(eps)); // force options specified directly as arguments - if (numEigenValues) + if(numEigenValues) _try(EPSSetDimensions(eps, numEigenValues, PETSC_DECIDE, PETSC_DECIDE)); - if (which=="smallest") + if(which == "smallest") _try(EPSSetWhichEigenpairs(eps, EPS_SMALLEST_MAGNITUDE)); - else if (which=="smallestReal") + else if(which == "smallestReal") _try(EPSSetWhichEigenpairs(eps, EPS_SMALLEST_REAL)); - else if (which=="largest") + else if(which == "largest") _try(EPSSetWhichEigenpairs(eps, EPS_LARGEST_MAGNITUDE)); - // print info -#if (SLEPC_VERSION_RELEASE == 0 || (SLEPC_VERSION_MAJOR > 3 || (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR >= 4))) + // print info +#if(SLEPC_VERSION_RELEASE == 0 || \ + (SLEPC_VERSION_MAJOR > 3 || \ + (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR >= 4))) EPSType type; #else const EPSType type; @@ -117,16 +121,17 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho _try(EPSGetIterationNumber(eps, &its)); EPSConvergedReason reason; _try(EPSGetConvergedReason(eps, &reason)); - if (reason==EPS_CONVERGED_TOL) { - double t2=Cpu(); - Msg::Debug("SLEPc converged in %d iterations (%g s)", its, t2-t1); + if(reason == EPS_CONVERGED_TOL) { + double t2 = Cpu(); + Msg::Debug("SLEPc converged in %d iterations (%g s)", its, t2 - t1); } - else if (reason==EPS_DIVERGED_ITS) + else if(reason == EPS_DIVERGED_ITS) Msg::Error("SLEPc diverged after %d iterations", its); - else if (reason==EPS_DIVERGED_BREAKDOWN) + else if(reason == EPS_DIVERGED_BREAKDOWN) Msg::Error("SLEPc generic breakdown in method"); -#if (SLEPC_VERSION_MAJOR < 3 || (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR < 2)) - else if (reason==EPS_DIVERGED_NONSYMMETRIC) +#if(SLEPC_VERSION_MAJOR < 3 || \ + (SLEPC_VERSION_MAJOR == 3 && SLEPC_VERSION_MINOR < 2)) + else if(reason == EPS_DIVERGED_NONSYMMETRIC) Msg::Error("The operator is nonsymmetric"); #endif @@ -136,24 +141,24 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho Msg::Debug("SLEPc number of converged eigenpairs: %d", nconv); // ignore additional eigenvalues if we get more than what we asked - if (nconv>nev) nconv = nev; + if(nconv > nev) nconv = nev; - if (nconv>0) { + if(nconv > 0) { Vec xr, xi; -#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR < 6) +#if(PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR < 6) _try(MatGetVecs(A, PETSC_NULL, &xr)); _try(MatGetVecs(A, PETSC_NULL, &xi)); #else - _try(MatCreateVecs(A, PETSC_NULL, &xr)); - _try(MatCreateVecs(A, PETSC_NULL, &xi)); + _try(MatCreateVecs(A, PETSC_NULL, &xr)); + _try(MatCreateVecs(A, PETSC_NULL, &xi)); #endif Msg::Debug(" Re[EigenValue] Im[EigenValue]" - " Relative error"); - for (int i=0; i<nconv; i++) { + " Relative error"); + for(int i = 0; i < nconv; i++) { PetscScalar kr, ki; _try(EPSGetEigenpair(eps, i, &kr, &ki, xr, xi)); PetscReal error; -#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR < 6) +#if(PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR < 6) _try(EPSComputeRelativeError(eps, i, &error)); #else _try(EPSComputeError(eps, i, EPS_ERROR_RELATIVE, &error)); @@ -165,8 +170,8 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho PetscReal re = kr; PetscReal im = ki; #endif - Msg::Debug("EIG %03d %s%.16e %s%.16e %3.6e", - i, (re<0) ? "" : " ", re, (im<0) ? "" : " ", im, error); + Msg::Debug("EIG %03d %s%.16e %s%.16e %3.6e", i, (re < 0) ? "" : " ", re, + (im < 0) ? "" : " ", im, error); // store eigenvalues and eigenvectors _eigenValues.push_back(std::complex<double>(re, im)); @@ -174,7 +179,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho _try(VecGetArray(xr, &tmpr)); _try(VecGetArray(xi, &tmpi)); std::vector<std::complex<double> > ev(N); - for (int i=0; i<N; i++) { + for(int i = 0; i < N; i++) { #if defined(PETSC_USE_COMPLEX) ev[i] = tmpr[i]; #else @@ -189,7 +194,7 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho _try(EPSDestroy(&eps)); - if (reason==EPS_CONVERGED_TOL) { + if(reason == EPS_CONVERGED_TOL) { Msg::Debug("SLEPc done"); return true; } @@ -197,27 +202,25 @@ bool eigenSolver::solve(int numEigenValues, std::string which, std::string metho Msg::Warning("SLEPc failed"); return false; } - } void eigenSolver::normalize_mode(std::vector<int> modeView, double scale) { Msg::Info("Normalize all eigenvectors"); - for (unsigned int imode=0; imode<modeView.size(); imode++) { + for(unsigned int imode = 0; imode < modeView.size(); imode++) { int i = modeView[imode]; double norm = 0.; - for (unsigned int j=0; j<_eigenVectors[i].size(); j++) { + for(unsigned int j = 0; j < _eigenVectors[i].size(); j++) { std::complex<double> val = _eigenVectors[i][j]; double normval = std::abs(val); - if (normval>norm) - norm = normval; + if(normval > norm) norm = normval; } - if (norm==0) { + if(norm == 0) { Msg::Error("zero eigenvector"); return; } - for (unsigned int j=0; j<_eigenVectors[i].size(); j++) { - _eigenVectors[i][j] *= (scale/norm); + for(unsigned int j = 0; j < _eigenVectors[i].size(); j++) { + _eigenVectors[i][j] *= (scale / norm); } } } diff --git a/Solver/eigenSolver.h b/Solver/eigenSolver.h index 547d2f35ee403acb7147fc51acd7ecb2963b5eff..a278390948d651f4f55a488691a7ad23ae638c2f 100644 --- a/Solver/eigenSolver.h +++ b/Solver/eigenSolver.h @@ -17,36 +17,39 @@ #include "linearSystemPETSc.h" class eigenSolver { - private: +private: linearSystemPETSc<double> *_A, *_B; bool _hermitian; std::vector<std::complex<double> > _eigenValues; std::vector<std::vector<std::complex<double> > > _eigenVectors; void _try(int ierr) const; - public: - eigenSolver(dofManager<double> *manager, std::string A, - std::string B="", bool hermitian=true); - eigenSolver(linearSystemPETSc<double> *A, linearSystemPETSc<double>* B = NULL, - bool hermitian=true); - bool solve(int numEigenValues=0, std::string which="", std::string method="krylovschur", - double tolVal=1.e-7, int iterMax=20); - - int getNumEigenValues() {return _eigenValues.size();} - int getNumberEigenvectors() {return _eigenVectors.size();} - - std::complex<double> getEigenValue(int num) { - return _eigenValues[num]; - } - std::complex<double> getEigenVectorComp(int num, int com) { + +public: + eigenSolver(dofManager<double> *manager, std::string A, std::string B = "", + bool hermitian = true); + eigenSolver(linearSystemPETSc<double> *A, linearSystemPETSc<double> *B = NULL, + bool hermitian = true); + bool solve(int numEigenValues = 0, std::string which = "", + std::string method = "krylovschur", double tolVal = 1.e-7, + int iterMax = 20); + + int getNumEigenValues() { return _eigenValues.size(); } + int getNumberEigenvectors() { return _eigenVectors.size(); } + + std::complex<double> getEigenValue(int num) { return _eigenValues[num]; } + std::complex<double> getEigenVectorComp(int num, int com) + { return _eigenVectors[num][com]; }; - std::vector<std::complex<double> > &getEigenVector(int num) { + std::vector<std::complex<double> > &getEigenVector(int num) + { return _eigenVectors[num]; } - void normalize_mode(std::vector<int> modeView, double scale=1.); + void normalize_mode(std::vector<int> modeView, double scale = 1.); - void clear() { + void clear() + { _eigenValues.clear(); _eigenVectors.clear(); }; @@ -57,23 +60,29 @@ class eigenSolver { #include "linearSystemPETSc.h" class eigenSolver { - private: +private: std::vector<std::complex<double> > _dummy; - public: - eigenSolver(dofManager<double> *manager, std::string A, - std::string B="", bool hermitian=false) {} - eigenSolver(linearSystemPETSc<double> *A, linearSystemPETSc<double>* B=NULL, - bool hermitian=false) {} - bool solve(int=0, std::string="", std::string="", double=0, int=0) { + +public: + eigenSolver(dofManager<double> *manager, std::string A, std::string B = "", + bool hermitian = false) + { + } + eigenSolver(linearSystemPETSc<double> *A, linearSystemPETSc<double> *B = NULL, + bool hermitian = false) + { + } + bool solve(int = 0, std::string = "", std::string = "", double = 0, int = 0) + { Msg::Error("Eigen solver requires SLEPc"); return false; } - int getNumEigenValues() {return 0;} - int getNumberEigenvectors() {return 0;} - std::complex<double> getEigenValue(int num) {return 0.;} - std::complex<double> getEigenVectorComp(int num, int com) {return 0.;} - std::vector<std::complex<double> > &getEigenVector(int num) {return _dummy;} - void normalize_mode(std::vector<int> modeView, double scale=1.) {} + int getNumEigenValues() { return 0; } + int getNumberEigenvectors() { return 0; } + std::complex<double> getEigenValue(int num) { return 0.; } + std::complex<double> getEigenVectorComp(int num, int com) { return 0.; } + std::vector<std::complex<double> > &getEigenVector(int num) { return _dummy; } + void normalize_mode(std::vector<int> modeView, double scale = 1.) {} void clear() {} }; diff --git a/Solver/elasticitySolver.cpp b/Solver/elasticitySolver.cpp index fd93a6c5b69ff5e10459ae38670fac6efb220d89..b2d28f5526d874c89ea1cda5dea0b91353cc908b 100644 --- a/Solver/elasticitySolver.cpp +++ b/Solver/elasticitySolver.cpp @@ -57,10 +57,11 @@ elasticitySolver::elasticitySolver(GModel *model, int tag) _dim = pModel->getNumRegions() ? 3 : 2; _tag = tag; pAssembler = NULL; - if (_dim==3) LagSpace=new VectorLagrangeFunctionSpace(_tag); - if (_dim==2) LagSpace=new VectorLagrangeFunctionSpace(_tag, - VectorLagrangeFunctionSpace::VECTOR_X, - VectorLagrangeFunctionSpace::VECTOR_Y); + if(_dim == 3) LagSpace = new VectorLagrangeFunctionSpace(_tag); + if(_dim == 2) + LagSpace = new VectorLagrangeFunctionSpace( + _tag, VectorLagrangeFunctionSpace::VECTOR_X, + VectorLagrangeFunctionSpace::VECTOR_Y); } void elasticitySolver::setMesh(const std::string &meshFileName, int dim) @@ -69,38 +70,40 @@ void elasticitySolver::setMesh(const std::string &meshFileName, int dim) pModel->readMSH(meshFileName.c_str()); _dim = pModel->getNumRegions() ? 3 : 2; - if (LagSpace) delete LagSpace; - if (dim == 3 || _dim==3) LagSpace = new VectorLagrangeFunctionSpace(_tag); - else if (dim == 2 || _dim==2) LagSpace = new VectorLagrangeFunctionSpace - (_tag,VectorLagrangeFunctionSpace::VECTOR_X, - VectorLagrangeFunctionSpace::VECTOR_Y); + if(LagSpace) delete LagSpace; + if(dim == 3 || _dim == 3) + LagSpace = new VectorLagrangeFunctionSpace(_tag); + else if(dim == 2 || _dim == 2) + LagSpace = new VectorLagrangeFunctionSpace( + _tag, VectorLagrangeFunctionSpace::VECTOR_X, + VectorLagrangeFunctionSpace::VECTOR_Y); - for (unsigned int i = 0; i < LagrangeMultiplierSpaces.size(); i++) - if (LagrangeMultiplierSpaces[i]) delete LagrangeMultiplierSpaces[i]; + for(unsigned int i = 0; i < LagrangeMultiplierSpaces.size(); i++) + if(LagrangeMultiplierSpaces[i]) delete LagrangeMultiplierSpaces[i]; LagrangeMultiplierSpaces.clear(); } void elasticitySolver::exportKb() { std::string sysname = "A"; - if(!pAssembler || - !pAssembler->getLinearSystem(sysname) || - !pAssembler->getLinearSystem(sysname)->isAllocated()) return; + if(!pAssembler || !pAssembler->getLinearSystem(sysname) || + !pAssembler->getLinearSystem(sysname)->isAllocated()) + return; double valeur; FILE *f = Fopen("K.txt", "w"); - if(f){ - for (int i = 0; i < pAssembler->sizeOfR(); i++){ - for (int j = 0; j < pAssembler->sizeOfR(); j++ ){ - pAssembler->getLinearSystem(sysname)->getFromMatrix (i, j, valeur); - fprintf (f, "%+e ", valeur) ; + if(f) { + for(int i = 0; i < pAssembler->sizeOfR(); i++) { + for(int j = 0; j < pAssembler->sizeOfR(); j++) { + pAssembler->getLinearSystem(sysname)->getFromMatrix(i, j, valeur); + fprintf(f, "%+e ", valeur); } - fprintf(f,"\n"); + fprintf(f, "\n"); } - fclose (f); + fclose(f); } f = Fopen("b.txt", "w"); - if(f){ - for (int i = 0; i < pAssembler->sizeOfR(); i++){ + if(f) { + for(int i = 0; i < pAssembler->sizeOfR(); i++) { pAssembler->getLinearSystem(sysname)->getFromRightHandSide(i, valeur); fprintf(f, "%+e\n", valeur); } @@ -124,234 +127,237 @@ void elasticitySolver::solve() #endif assemble(lsys); - //printLinearSystem(lsys,pAssembler->sizeOfR()); + // printLinearSystem(lsys,pAssembler->sizeOfR()); lsys->systemSolve(); printf("-- done solving!\n"); - double energ=0; + double energ = 0; GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); - for (unsigned int i = 0; i < elasticFields.size(); i++){ + for(unsigned int i = 0; i < elasticFields.size(); i++) { SolverField<SVector3> Field(pAssembler, LagSpace); - IsotropicElasticTerm Eterm(Field,elasticFields[i]._E,elasticFields[i]._nu); + IsotropicElasticTerm Eterm(Field, elasticFields[i]._E, + elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); - Assemble(Elastic_Energy_Term, elasticFields[i].g->begin(), elasticFields[i].g->end(), - Integ_Bulk,energ); + Assemble(Elastic_Energy_Term, elasticFields[i].g->begin(), + elasticFields[i].g->end(), Integ_Bulk, energ); } - printf("elastic energy=%f\n",energ); + printf("elastic energy=%f\n", energ); } void elasticitySolver::postSolve() { GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); - double energ=0; - for (unsigned int i = 0; i < elasticFields.size(); i++){ + double energ = 0; + for(unsigned int i = 0; i < elasticFields.size(); i++) { SolverField<SVector3> Field(pAssembler, LagSpace); - IsotropicElasticTerm Eterm(Field,elasticFields[i]._E,elasticFields[i]._nu); + IsotropicElasticTerm Eterm(Field, elasticFields[i]._E, + elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); Assemble(Elastic_Energy_Term, elasticFields[i].g->begin(), elasticFields[i].g->end(), Integ_Bulk, energ); } - printf("elastic energy=%f\n",energ); + printf("elastic energy=%f\n", energ); } void elasticitySolver::readInputFile(const std::string &fn) { FILE *f = Fopen(fn.c_str(), "r"); - if(!f){ + if(!f) { Msg::Error("Could not open file '%s'", fn.c_str()); return; } char what[256]; - while(!feof(f)){ - if(fscanf(f, "%s", what) != 1){ + while(!feof(f)) { + if(fscanf(f, "%s", what) != 1) { fclose(f); return; } - if(what[0]=='#'){ + if(what[0] == '#') { char buffer[1024]; if(fgets(buffer, sizeof(buffer), f) == NULL) Msg::Error("Cannot read line."); } - else if (!strcmp(what, "ElasticDomain")){ + else if(!strcmp(what, "ElasticDomain")) { elasticField field; int physical; - if(fscanf(f, "%d %lf %lf", &physical, &field._E, &field._nu) != 3){ + if(fscanf(f, "%d %lf %lf", &physical, &field._E, &field._nu) != 3) { fclose(f); return; } field._tag = _tag; - field.g = new groupOfElements (_dim, physical); + field.g = new groupOfElements(_dim, physical); elasticFields.push_back(field); } - else if (!strcmp(what, "LagrangeMultipliers")){ + else if(!strcmp(what, "LagrangeMultipliers")) { LagrangeMultiplierField field; int physical; double d1, d2, d3, val; - if(fscanf(f, "%d %lf %lf %lf %lf %lf %d", &physical, &field._tau, - &d1, &d2, &d3, &val, &field._tag) != 7){ + if(fscanf(f, "%d %lf %lf %lf %lf %lf %d", &physical, &field._tau, &d1, + &d2, &d3, &val, &field._tag) != 7) { fclose(f); return; } SVector3 sv(d1, d2, d3); field._d = sv.unit(); field._f = new simpleFunction<double>(val); - field.g = new groupOfElements (_dim - 1, physical); + field.g = new groupOfElements(_dim - 1, physical); LagrangeMultiplierFields.push_back(field); - LagrangeMultiplierSpaces.push_back(new ScalarLagrangeFunctionSpaceOfElement(field._tag)); + LagrangeMultiplierSpaces.push_back( + new ScalarLagrangeFunctionSpaceOfElement(field._tag)); } - else if (!strcmp(what, "Void")){ + else if(!strcmp(what, "Void")) { elasticField field; int physical; - if(fscanf(f, "%d", &physical) != 1){ + if(fscanf(f, "%d", &physical) != 1) { fclose(f); return; } field._E = field._nu = 0; - field.g = new groupOfElements (_dim, physical); + field.g = new groupOfElements(_dim, physical); field._tag = 0; elasticFields.push_back(field); } - else if (!strcmp(what, "NodeDisplacement")){ + else if(!strcmp(what, "NodeDisplacement")) { double val; int node, comp; - if(fscanf(f, "%d %d %lf", &node, &comp, &val) != 3){ + if(fscanf(f, "%d %d %lf", &node, &comp, &val) != 3) { fclose(f); return; } dirichletBC diri; - diri.g = new groupOfElements (0, node); - diri._f= new simpleFunction<double>(val); - diri._comp=comp; - diri._tag=node; - diri.onWhat=BoundaryCondition::ON_VERTEX; + diri.g = new groupOfElements(0, node); + diri._f = new simpleFunction<double>(val); + diri._comp = comp; + diri._tag = node; + diri.onWhat = BoundaryCondition::ON_VERTEX; allDirichlet.push_back(diri); } - else if (!strcmp(what, "EdgeDisplacement")){ + else if(!strcmp(what, "EdgeDisplacement")) { double val; int edge, comp; - if(fscanf(f, "%d %d %lf", &edge, &comp, &val) != 3){ + if(fscanf(f, "%d %d %lf", &edge, &comp, &val) != 3) { fclose(f); return; } dirichletBC diri; - diri.g = new groupOfElements (1, edge); - diri._f= new simpleFunction<double>(val); - diri._comp=comp; - diri._tag=edge; - diri.onWhat=BoundaryCondition::ON_EDGE; + diri.g = new groupOfElements(1, edge); + diri._f = new simpleFunction<double>(val); + diri._comp = comp; + diri._tag = edge; + diri.onWhat = BoundaryCondition::ON_EDGE; allDirichlet.push_back(diri); } - else if (!strcmp(what, "FaceDisplacement")){ + else if(!strcmp(what, "FaceDisplacement")) { double val; int face, comp; - if(fscanf(f, "%d %d %lf", &face, &comp, &val) != 3){ + if(fscanf(f, "%d %d %lf", &face, &comp, &val) != 3) { fclose(f); return; } dirichletBC diri; - diri.g = new groupOfElements (2, face); - diri._f= new simpleFunction<double>(val); - diri._comp=comp; - diri._tag=face; - diri.onWhat=BoundaryCondition::ON_FACE; + diri.g = new groupOfElements(2, face); + diri._f = new simpleFunction<double>(val); + diri._comp = comp; + diri._tag = face; + diri.onWhat = BoundaryCondition::ON_FACE; allDirichlet.push_back(diri); } - else if (!strcmp(what, "NodeForce")){ + else if(!strcmp(what, "NodeForce")) { double val1, val2, val3; int node; - if(fscanf(f, "%d %lf %lf %lf", &node, &val1, &val2, &val3) != 4){ + if(fscanf(f, "%d %lf %lf %lf", &node, &val1, &val2, &val3) != 4) { fclose(f); return; } neumannBC neu; - neu.g = new groupOfElements (0, node); - neu._f= new simpleFunction<SVector3>(SVector3(val1, val2, val3)); - neu._tag=node; - neu.onWhat=BoundaryCondition::ON_VERTEX; + neu.g = new groupOfElements(0, node); + neu._f = new simpleFunction<SVector3>(SVector3(val1, val2, val3)); + neu._tag = node; + neu.onWhat = BoundaryCondition::ON_VERTEX; allNeumann.push_back(neu); } - else if (!strcmp(what, "EdgeForce")){ + else if(!strcmp(what, "EdgeForce")) { double val1, val2, val3; int edge; - if(fscanf(f, "%d %lf %lf %lf", &edge, &val1, &val2, &val3) != 4){ + if(fscanf(f, "%d %lf %lf %lf", &edge, &val1, &val2, &val3) != 4) { fclose(f); return; } neumannBC neu; - neu.g = new groupOfElements (1, edge); - neu._f= new simpleFunction<SVector3>(SVector3(val1, val2, val3)); - neu._tag=edge; - neu.onWhat=BoundaryCondition::ON_EDGE; + neu.g = new groupOfElements(1, edge); + neu._f = new simpleFunction<SVector3>(SVector3(val1, val2, val3)); + neu._tag = edge; + neu.onWhat = BoundaryCondition::ON_EDGE; allNeumann.push_back(neu); } - else if (!strcmp(what, "FaceForce")){ + else if(!strcmp(what, "FaceForce")) { double val1, val2, val3; int face; - if(fscanf(f, "%d %lf %lf %lf", &face, &val1, &val2, &val3) != 4){ + if(fscanf(f, "%d %lf %lf %lf", &face, &val1, &val2, &val3) != 4) { fclose(f); return; } neumannBC neu; - neu.g = new groupOfElements (2, face); - neu._f= new simpleFunction<SVector3>(SVector3(val1, val2, val3)); - neu._tag=face; - neu.onWhat=BoundaryCondition::ON_FACE; + neu.g = new groupOfElements(2, face); + neu._f = new simpleFunction<SVector3>(SVector3(val1, val2, val3)); + neu._tag = face; + neu.onWhat = BoundaryCondition::ON_FACE; allNeumann.push_back(neu); } - else if (!strcmp(what, "VolumeForce")){ + else if(!strcmp(what, "VolumeForce")) { double val1, val2, val3; int volume; - if(fscanf(f, "%d %lf %lf %lf", &volume, &val1, &val2, &val3) != 4){ + if(fscanf(f, "%d %lf %lf %lf", &volume, &val1, &val2, &val3) != 4) { fclose(f); return; } neumannBC neu; - neu.g = new groupOfElements (3, volume); - neu._f= new simpleFunction<SVector3>(SVector3(val1, val2, val3)); - neu._tag=volume; - neu.onWhat=BoundaryCondition::ON_VOLUME; + neu.g = new groupOfElements(3, volume); + neu._f = new simpleFunction<SVector3>(SVector3(val1, val2, val3)); + neu._tag = volume; + neu.onWhat = BoundaryCondition::ON_VOLUME; allNeumann.push_back(neu); } - else if (!strcmp(what, "MeshFile")){ + else if(!strcmp(what, "MeshFile")) { char name[245]; - if(fscanf(f, "%s", name) != 1){ + if(fscanf(f, "%s", name) != 1) { fclose(f); return; } setMesh(name); } - else if (!strcmp(what, "CutMeshPlane")){ + else if(!strcmp(what, "CutMeshPlane")) { double a, b, c, d; - if(fscanf(f, "%lf %lf %lf %lf", &a, &b, &c, &d) != 4){ + if(fscanf(f, "%lf %lf %lf %lf", &a, &b, &c, &d) != 4) { fclose(f); return; } - int tag=1; - gLevelsetPlane ls(a,b,c,d,tag); + int tag = 1; + gLevelsetPlane ls(a, b, c, d, tag); pModel = pModel->buildCutGModel(&ls); pModel->writeMSH("cutMesh.msh"); } - else if (!strcmp(what, "CutMeshSphere")){ + else if(!strcmp(what, "CutMeshSphere")) { double x, y, z, r; - if(fscanf(f, "%lf %lf %lf %lf", &x, &y, &z, &r) != 4){ + if(fscanf(f, "%lf %lf %lf %lf", &x, &y, &z, &r) != 4) { fclose(f); return; } - int tag=1; - gLevelsetSphere ls(x,y,z,r,tag); + int tag = 1; + gLevelsetSphere ls(x, y, z, r, tag); pModel = pModel->buildCutGModel(&ls); pModel->writeMSH("cutMesh.msh"); } - else if (!strcmp(what, "CutMeshMathExpr")){ + else if(!strcmp(what, "CutMeshMathExpr")) { char expr[256]; - if(fscanf(f, "%s", expr) != 1){ + if(fscanf(f, "%s", expr) != 1) { fclose(f); return; } std::string exprS(expr); - int tag=1; - gLevelsetMathEval ls(exprS,tag); + int tag = 1; + gLevelsetMathEval ls(exprS, tag); pModel = pModel->buildCutGModel(&ls); pModel->writeMSH("cutMesh.msh"); } @@ -362,7 +368,6 @@ void elasticitySolver::readInputFile(const std::string &fn) fclose(f); } - void elasticitySolver::cutMesh(gLevelset *ls) { pModel = pModel->buildCutGModel(ls); @@ -375,37 +380,40 @@ void elasticitySolver::setElasticDomain(int phys, double E, double nu) field._E = E; field._nu = nu; field._tag = _tag; - field.g = new groupOfElements (_dim, phys); + field.g = new groupOfElements(_dim, phys); elasticFields.push_back(field); } void elasticitySolver::setLagrangeMultipliers(int phys, double tau, SVector3 d, - int tag, simpleFunction<double> *f) + int tag, + simpleFunction<double> *f) { LagrangeMultiplierField field; field._tau = tau; field._tag = tag; field._f = f; field._d = d.unit(); - field.g = new groupOfElements (_dim - 1, phys); // LM applied on entity of dimension = dim-1! + field.g = new groupOfElements( + _dim - 1, phys); // LM applied on entity of dimension = dim-1! LagrangeMultiplierFields.push_back(field); - LagrangeMultiplierSpaces.push_back(new ScalarLagrangeFunctionSpaceOfElement(tag)); + LagrangeMultiplierSpaces.push_back( + new ScalarLagrangeFunctionSpaceOfElement(tag)); } void elasticitySolver::changeLMTau(int tag, double tau) { - for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++){ - if(LagrangeMultiplierFields[i]._tag == tag){ + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++) { + if(LagrangeMultiplierFields[i]._tag == tag) { LagrangeMultiplierFields[i]._tau = tau; } } - } -void elasticitySolver::setEdgeDisp(int edge, int comp, simpleFunction<double> *f) +void elasticitySolver::setEdgeDisp(int edge, int comp, + simpleFunction<double> *f) { dirichletBC diri; - diri.g = new groupOfElements (1, edge); + diri.g = new groupOfElements(1, edge); diri._f = f; diri._comp = comp; diri._tag = edge; @@ -413,46 +421,49 @@ void elasticitySolver::setEdgeDisp(int edge, int comp, simpleFunction<double> *f allDirichlet.push_back(diri); } - -void elasticitySolver::addDirichletBC(int dim, int entityId, int component, double value) +void elasticitySolver::addDirichletBC(int dim, int entityId, int component, + double value) { dirichletBC diri; - diri.g = new groupOfElements (dim, entityId); - diri._f= new simpleFunction<double>(value); - diri._comp=component; - diri._tag=entityId; - switch (dim) { - case 0 : diri.onWhat=BoundaryCondition::ON_VERTEX; break; - case 1 : diri.onWhat=BoundaryCondition::ON_EDGE; break; - case 2 : diri.onWhat=BoundaryCondition::ON_FACE; break; - default : return; + diri.g = new groupOfElements(dim, entityId); + diri._f = new simpleFunction<double>(value); + diri._comp = component; + diri._tag = entityId; + switch(dim) { + case 0: diri.onWhat = BoundaryCondition::ON_VERTEX; break; + case 1: diri.onWhat = BoundaryCondition::ON_EDGE; break; + case 2: diri.onWhat = BoundaryCondition::ON_FACE; break; + default: return; } allDirichlet.push_back(diri); } -void elasticitySolver::addDirichletBC(int dim, std::string phys, int component, double value) +void elasticitySolver::addDirichletBC(int dim, std::string phys, int component, + double value) { int entityId = pModel->getPhysicalNumber(dim, phys); addDirichletBC(dim, entityId, component, value); } -void elasticitySolver::addNeumannBC(int dim, int entityId, const std::vector<double> value) +void elasticitySolver::addNeumannBC(int dim, int entityId, + const std::vector<double> value) { - if(value.size()!=3) return; + if(value.size() != 3) return; neumannBC neu; - neu.g = new groupOfElements (dim, entityId); - neu._f= new simpleFunction<SVector3>(SVector3(value[0], value[1], value[2])); - neu._tag=entityId; - switch (dim) { - case 0 : neu.onWhat=BoundaryCondition::ON_VERTEX; break; - case 1 : neu.onWhat=BoundaryCondition::ON_EDGE; break; - case 2 : neu.onWhat=BoundaryCondition::ON_FACE; break; - default : return; + neu.g = new groupOfElements(dim, entityId); + neu._f = new simpleFunction<SVector3>(SVector3(value[0], value[1], value[2])); + neu._tag = entityId; + switch(dim) { + case 0: neu.onWhat = BoundaryCondition::ON_VERTEX; break; + case 1: neu.onWhat = BoundaryCondition::ON_EDGE; break; + case 2: neu.onWhat = BoundaryCondition::ON_FACE; break; + default: return; } allNeumann.push_back(neu); } -void elasticitySolver::addNeumannBC(int dim, std::string phys, const std::vector<double> value) +void elasticitySolver::addNeumannBC(int dim, std::string phys, + const std::vector<double> value) { int entityId = pModel->getPhysicalNumber(dim, phys); addNeumannBC(dim, entityId, value); @@ -464,7 +475,7 @@ void elasticitySolver::addElasticDomain(int physical, double e, double nu) field._tag = _tag; field._E = e; field._nu = nu; - field.g = new groupOfElements (_dim, physical); + field.g = new groupOfElements(_dim, physical); elasticFields.push_back(field); } @@ -476,7 +487,7 @@ void elasticitySolver::addElasticDomain(std::string phys, double e, double nu) void elasticitySolver::assemble(linearSystem<double> *lsys) { - if (pAssembler) delete pAssembler; + if(pAssembler) delete pAssembler; pAssembler = new dofManager<double>(lsys); // we first do all fixations. the behavior of the dofManager is to @@ -484,88 +495,100 @@ void elasticitySolver::assemble(linearSystem<double> *lsys) // numbered afterwards // Dirichlet conditions - for (unsigned int i = 0; i < allDirichlet.size(); i++){ + for(unsigned int i = 0; i < allDirichlet.size(); i++) { FilterDofComponent filter(allDirichlet[i]._comp); - FixNodalDofs(*LagSpace, allDirichlet[i].g->begin(), allDirichlet[i].g->end(), - *pAssembler, *allDirichlet[i]._f, filter); + FixNodalDofs(*LagSpace, allDirichlet[i].g->begin(), + allDirichlet[i].g->end(), *pAssembler, *allDirichlet[i]._f, + filter); } // LagrangeMultipliers - for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i){ + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i) { unsigned int j = 0; - for ( ; j < LagrangeMultiplierSpaces.size(); j++) - if (LagrangeMultiplierSpaces[j]->getId() == LagrangeMultiplierFields[i]._tag) break; - NumberDofs(*(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i].g->begin(), + for(; j < LagrangeMultiplierSpaces.size(); j++) + if(LagrangeMultiplierSpaces[j]->getId() == + LagrangeMultiplierFields[i]._tag) + break; + NumberDofs(*(LagrangeMultiplierSpaces[j]), + LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), *pAssembler); } // Elastic Fields - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E != 0.) - NumberDofs(*LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), - *pAssembler); + NumberDofs(*LagSpace, elasticFields[i].g->begin(), + elasticFields[i].g->end(), *pAssembler); } // Voids - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E == 0.) - FixVoidNodalDofs(*LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), - *pAssembler); + FixVoidNodalDofs(*LagSpace, elasticFields[i].g->begin(), + elasticFields[i].g->end(), *pAssembler); } // Neumann conditions GaussQuadrature Integ_Boundary(GaussQuadrature::Val); - for (unsigned int i = 0; i < allNeumann.size(); i++){ + for(unsigned int i = 0; i < allNeumann.size(); i++) { LoadTerm<SVector3> Lterm(*LagSpace, allNeumann[i]._f); Assemble(Lterm, *LagSpace, allNeumann[i].g->begin(), allNeumann[i].g->end(), - Integ_Boundary,*pAssembler); + Integ_Boundary, *pAssembler); } // Assemble cross term, laplace term and rhs term for LM GaussQuadrature Integ_LagrangeMult(GaussQuadrature::ValVal); GaussQuadrature Integ_Laplace(GaussQuadrature::GradGrad); - for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++){ + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++) { unsigned int j = 0; - for ( ; j < LagrangeMultiplierSpaces.size(); j++) - if (LagrangeMultiplierSpaces[j]->getId() == LagrangeMultiplierFields[i]._tag) break; + for(; j < LagrangeMultiplierSpaces.size(); j++) + if(LagrangeMultiplierSpaces[j]->getId() == + LagrangeMultiplierFields[i]._tag) + break; printf("Lagrange Mult Lag\n"); - LagrangeMultiplierTerm<SVector3> LagTerm(*LagSpace, *(LagrangeMultiplierSpaces[j]), + LagrangeMultiplierTerm<SVector3> LagTerm(*LagSpace, + *(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i]._d); Assemble(LagTerm, *LagSpace, *(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i].g->begin(), - LagrangeMultiplierFields[i].g->end(), Integ_LagrangeMult, *pAssembler); + LagrangeMultiplierFields[i].g->end(), Integ_LagrangeMult, + *pAssembler); printf("Lagrange Mult Lap\n"); - LaplaceTerm<double,double> LapTerm(*(LagrangeMultiplierSpaces[j]), - -LagrangeMultiplierFields[i]._tau); - Assemble(LapTerm, *(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i].g->begin(), + LaplaceTerm<double, double> LapTerm(*(LagrangeMultiplierSpaces[j]), + -LagrangeMultiplierFields[i]._tau); + Assemble(LapTerm, *(LagrangeMultiplierSpaces[j]), + LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Laplace, *pAssembler); printf("Lagrange Mult Load\n"); - LoadTermOnBorder<double> Lterm(*(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i]._f); - Assemble(Lterm, *(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i].g->begin(), + LoadTermOnBorder<double> Lterm(*(LagrangeMultiplierSpaces[j]), + LagrangeMultiplierFields[i]._f); + Assemble(Lterm, *(LagrangeMultiplierSpaces[j]), + LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Boundary, *pAssembler); } // Assemble elastic term for GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); - for (unsigned int i = 0; i < elasticFields.size(); i++){ + for(unsigned int i = 0; i < elasticFields.size(); i++) { printf("Elastic\n"); - IsotropicElasticTerm Eterm(*LagSpace,elasticFields[i]._E,elasticFields[i]._nu); - Assemble(Eterm, *LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), - Integ_Bulk, *pAssembler); + IsotropicElasticTerm Eterm(*LagSpace, elasticFields[i]._E, + elasticFields[i]._nu); + Assemble(Eterm, *LagSpace, elasticFields[i].g->begin(), + elasticFields[i].g->end(), Integ_Bulk, *pAssembler); } - printf("nDofs=%d\n",pAssembler->sizeOfR()); - printf("nFixed=%d\n",pAssembler->sizeOfF()); - + printf("nDofs=%d\n", pAssembler->sizeOfR()); + printf("nFixed=%d\n", pAssembler->sizeOfF()); } void elasticitySolver::computeEffectiveStiffness(std::vector<double> stiff) { double st[6] = {0., 0., 0., 0., 0., 0.}; double volTot = 0.; - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { double E = elasticFields[i]._E; double nu = elasticFields[i]._nu; SolverField<SVector3> Field(pAssembler, LagSpace); - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); - it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; double vol = e->getVolume() * e->getVolumeSign(); int nbVertex = e->getNumVertices(); @@ -574,13 +597,13 @@ void elasticitySolver::computeEffectiveStiffness(std::vector<double> stiff) double valx[256]; double valy[256]; double valz[256]; - for (int k = 0; k < nbVertex; k++){ - MVertex *v = e->getVertex(k); - MPoint p(v); - Field.f(&p, 0, 0, 0, val[k]); - valx[k] = val[k](0); - valy[k] = val[k](1); - valz[k] = val[k](2); + for(int k = 0; k < nbVertex; k++) { + MVertex *v = e->getVertex(k); + MPoint p(v); + Field.f(&p, 0, 0, 0, val[k]); + valx[k] = val[k](0); + valy[k] = val[k](1); + valz[k] = val[k](2); } double gradux[3]; @@ -592,14 +615,16 @@ void elasticitySolver::computeEffectiveStiffness(std::vector<double> stiff) e->interpolateGrad(valy, u, v, w, graduy); e->interpolateGrad(valz, u, v, w, graduz); - double eps[6] = {gradux[0], graduy[1], graduz[2], - 0.5 * (gradux[1] + graduy[0]), - 0.5 * (gradux[2] + graduz[0]), - 0.5 * (graduy[2] + graduz[1])}; + double eps[6] = {gradux[0], + graduy[1], + graduz[2], + 0.5 * (gradux[1] + graduy[0]), + 0.5 * (gradux[2] + graduz[0]), + 0.5 * (graduy[2] + graduz[1])}; double A = E / (1. + nu); double B = A * (nu / (1. - 2 * nu)); - double trace = eps[0] + eps[1] + eps[2] ; + double trace = eps[0] + eps[1] + eps[2]; st[0] += (A * eps[0] + B * trace) * vol; st[1] += (A * eps[1] + B * trace) * vol; st[2] += (A * eps[2] + B * trace) * vol; @@ -609,18 +634,18 @@ void elasticitySolver::computeEffectiveStiffness(std::vector<double> stiff) volTot += vol; } } - for(int i = 0; i < 6;i++) - stiff[i] = st[i] / volTot; + for(int i = 0; i < 6; i++) stiff[i] = st[i] / volTot; } void elasticitySolver::computeEffectiveStrain(std::vector<double> strain) { double st[6] = {0., 0., 0., 0., 0., 0.}; double volTot = 0.; - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { SolverField<SVector3> Field(pAssembler, LagSpace); - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); - it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; double vol = e->getVolume() * e->getVolumeSign(); int nbVertex = e->getNumVertices(); @@ -629,13 +654,13 @@ void elasticitySolver::computeEffectiveStrain(std::vector<double> strain) double valx[256]; double valy[256]; double valz[256]; - for (int k = 0; k < nbVertex; k++){ - MVertex *v = e->getVertex(k); - MPoint p(v); - Field.f(&p, 0, 0, 0, val[k]); - valx[k] = val[k](0); - valy[k] = val[k](1); - valz[k] = val[k](2); + for(int k = 0; k < nbVertex; k++) { + MVertex *v = e->getVertex(k); + MPoint p(v); + Field.f(&p, 0, 0, 0, val[k]); + valx[k] = val[k](0); + valy[k] = val[k](1); + valz[k] = val[k](2); } double gradux[3]; @@ -656,44 +681,48 @@ void elasticitySolver::computeEffectiveStrain(std::vector<double> strain) volTot += vol; } } - for(int i = 0; i < 6;i++) - strain[i] = st[i] / volTot; + for(int i = 0; i < 6; i++) strain[i] = st[i] / volTot; } -double elasticitySolver::computeDisplacementError(simpleFunction<double> *f0, simpleFunction<double> *f1, - simpleFunction<double> *f2) { - std::cout << "compute displacement error"<< std::endl; +double elasticitySolver::computeDisplacementError(simpleFunction<double> *f0, + simpleFunction<double> *f1, + simpleFunction<double> *f2) +{ + std::cout << "compute displacement error" << std::endl; double err = 0.; - std::set<MVertex*> v; - std::map<MVertex*, MElement*> vCut; - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + std::set<MVertex *> v; + std::map<MVertex *, MElement *> vCut; + for(unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E == 0.) continue; - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); - it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; if(e->getParent()) { - for (std::size_t j = 0; j < e->getNumVertices(); ++j) { + for(std::size_t j = 0; j < e->getNumVertices(); ++j) { if(vCut.find(e->getVertex(j)) == vCut.end()) vCut[e->getVertex(j)] = e->getParent(); } } else { - for (std::size_t j = 0; j < e->getNumVertices(); ++j) + for(std::size_t j = 0; j < e->getNumVertices(); ++j) v.insert(e->getVertex(j)); } } } SolverField<SVector3> Field(pAssembler, LagSpace); - for (std::set<MVertex*>::iterator it = v.begin(); it != v.end(); ++it){ + for(std::set<MVertex *>::iterator it = v.begin(); it != v.end(); ++it) { SVector3 val; MPoint p(*it); Field.f(&p, 0, 0, 0, val); - SVector3 sol((*f0)((*it)->x(), (*it)->y(), (*it)->z()), (*f1)((*it)->x(), (*it)->y(), (*it)->z()), + SVector3 sol((*f0)((*it)->x(), (*it)->y(), (*it)->z()), + (*f1)((*it)->x(), (*it)->y(), (*it)->z()), (*f2)((*it)->x(), (*it)->y(), (*it)->z())); double diff = normSq(sol - val); err += diff; } - for (std::map<MVertex*,MElement*>::iterator it = vCut.begin(); it != vCut.end(); ++it){ + for(std::map<MVertex *, MElement *>::iterator it = vCut.begin(); + it != vCut.end(); ++it) { SVector3 val; double uvw[3]; double xyz[3] = {it->first->x(), it->first->y(), it->first->z()}; @@ -704,32 +733,36 @@ double elasticitySolver::computeDisplacementError(simpleFunction<double> *f0, si double diff = normSq(sol - val); err += diff; } -printf("Displacement Error = %g\n",sqrt(err)); + printf("Displacement Error = %g\n", sqrt(err)); return sqrt(err); } -double elasticitySolver::computeL2Norm(simpleFunction<double> *f0, simpleFunction<double> *f1, - simpleFunction<double> *f2) { +double elasticitySolver::computeL2Norm(simpleFunction<double> *f0, + simpleFunction<double> *f1, + simpleFunction<double> *f2) +{ double val = 0.0; SolverField<SVector3> solField(pAssembler, LagSpace); - for (unsigned int i = 0; i < elasticFields.size(); ++i){ - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); it != elasticFields[i].g->end(); ++it){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; int npts; IntPt *GP; double jac[3][3]; - int integrationOrder = 2 * (e->getPolynomialOrder()+5); + int integrationOrder = 2 * (e->getPolynomialOrder() + 5); e->getIntegrationPoints(integrationOrder, &npts, &GP); - for (int j = 0; j < npts; j++){ + for(int j = 0; j < npts; j++) { double u = GP[j].pt[0]; double v = GP[j].pt[1]; double w = GP[j].pt[2]; double weight = GP[j].weight; - double detJ = fabs(e->getJacobian (u, v, w, jac)); + double detJ = fabs(e->getJacobian(u, v, w, jac)); SPoint3 p; e->pnt(u, v, w, p); - SVector3 FEMVALUE; - solField.f(e, u, v, w, FEMVALUE); + SVector3 FEMVALUE; + solField.f(e, u, v, w, FEMVALUE); SVector3 sol((*f0)(p.x(), p.y(), p.z()), (*f1)(p.x(), p.y(), p.z()), (*f2)(p.x(), p.y(), p.z())); double diff = normSq(sol - FEMVALUE); @@ -737,42 +770,47 @@ double elasticitySolver::computeL2Norm(simpleFunction<double> *f0, simpleFunctio } } } -printf("L2Norm = %g\n",sqrt(val)); + printf("L2Norm = %g\n", sqrt(val)); return sqrt(val); } -double elasticitySolver::computeLagNorm(int tag, simpleFunction<double> *sol) { +double elasticitySolver::computeLagNorm(int tag, simpleFunction<double> *sol) +{ return 0; } #if defined(HAVE_POST) -PView *elasticitySolver::buildErrorView(const std::string postFileName, simpleFunction<double> *f0, - simpleFunction<double> *f1, simpleFunction<double> *f2) +PView *elasticitySolver::buildErrorView(const std::string postFileName, + simpleFunction<double> *f0, + simpleFunction<double> *f1, + simpleFunction<double> *f2) { - std::cout << "build Error View"<< std::endl; + std::cout << "build Error View" << std::endl; std::map<int, std::vector<double> > data; SolverField<SVector3> solField(pAssembler, LagSpace); - for (unsigned int i = 0; i < elasticFields.size(); ++i){ - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); it != elasticFields[i].g->end(); ++it){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; int npts; IntPt *GP; double jac[3][3]; - int integrationOrder = 2 * (e->getPolynomialOrder()+5); + int integrationOrder = 2 * (e->getPolynomialOrder() + 5); e->getIntegrationPoints(integrationOrder, &npts, &GP); double val = 0.0; - for (int j = 0; j < npts; j++){ + for(int j = 0; j < npts; j++) { double u = GP[j].pt[0]; double v = GP[j].pt[1]; double w = GP[j].pt[2]; double weight = GP[j].weight; - double detJ = fabs(e->getJacobian (u, v, w, jac)); + double detJ = fabs(e->getJacobian(u, v, w, jac)); SPoint3 p; e->pnt(u, v, w, p); - SVector3 FEMVALUE; - solField.f(e, u, v, w, FEMVALUE); + SVector3 FEMVALUE; + solField.f(e, u, v, w, FEMVALUE); SVector3 sol((*f0)(p.x(), p.y(), p.z()), (*f1)(p.x(), p.y(), p.z()), (*f2)(p.x(), p.y(), p.z())); double diff = normSq(sol - FEMVALUE); @@ -784,69 +822,76 @@ PView *elasticitySolver::buildErrorView(const std::string postFileName, simpleFu } } - PView *pv = new PView (postFileName, "ElementData", pModel, data, 0.0, 1); + PView *pv = new PView(postFileName, "ElementData", pModel, data, 0.0, 1); return pv; } -PView* elasticitySolver::buildDisplacementView (const std::string postFileName) +PView *elasticitySolver::buildDisplacementView(const std::string postFileName) { - std::cout << "build Displacement View"<< std::endl; - std::set<MVertex*> v; - std::map<MVertex*, MElement*> vCut; - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + std::cout << "build Displacement View" << std::endl; + std::set<MVertex *> v; + std::map<MVertex *, MElement *> vCut; + for(unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E == 0.) continue; - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); - it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; if(e->getParent()) { - for (std::size_t j = 0; j < e->getNumVertices(); ++j) { + for(std::size_t j = 0; j < e->getNumVertices(); ++j) { if(vCut.find(e->getVertex(j)) == vCut.end()) vCut[e->getVertex(j)] = e->getParent(); } } else { - for (std::size_t j = 0; j < e->getNumVertices(); ++j) + for(std::size_t j = 0; j < e->getNumVertices(); ++j) v.insert(e->getVertex(j)); } } } std::map<int, std::vector<double> > data; SolverField<SVector3> Field(pAssembler, LagSpace); - for (std::set<MVertex*>::iterator it = v.begin(); it != v.end(); ++it){ + for(std::set<MVertex *>::iterator it = v.begin(); it != v.end(); ++it) { SVector3 val; MPoint p(*it); Field.f(&p, 0, 0, 0, val); std::vector<double> vec(3); - vec[0] = val(0); vec[1] = val(1); vec[2] = val(2); + vec[0] = val(0); + vec[1] = val(1); + vec[2] = val(2); data[(*it)->getNum()] = vec; } - for (std::map<MVertex*,MElement*>::iterator it = vCut.begin(); it != vCut.end(); ++it){ + for(std::map<MVertex *, MElement *>::iterator it = vCut.begin(); + it != vCut.end(); ++it) { SVector3 val; double uvw[3]; double xyz[3] = {it->first->x(), it->first->y(), it->first->z()}; it->second->xyz2uvw(xyz, uvw); Field.f(it->second, uvw[0], uvw[1], uvw[2], val); std::vector<double> vec(3); - vec[0] = val(0); vec[1] = val(1); vec[2] = val(2); + vec[0] = val(0); + vec[1] = val(1); + vec[2] = val(2); data[it->first->getNum()] = vec; } - PView *pv = new PView (postFileName, "NodeData", pModel, data, 0.0); + PView *pv = new PView(postFileName, "NodeData", pModel, data, 0.0); return pv; } -PView* elasticitySolver::buildStressesView (const std::string postFileName) +PView *elasticitySolver::buildStressesView(const std::string postFileName) { double sti[6] = {0., 0., 0., 0., 0., 0.}; double str[6] = {0., 0., 0., 0., 0., 0.}; double volTot = 0.; - std::cout << "build stresses view"<< std::endl; + std::cout << "build stresses view" << std::endl; std::map<int, std::vector<double> > data; - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { double E = elasticFields[i]._E; double nu = elasticFields[i]._nu; SolverField<SVector3> Field(pAssembler, LagSpace); - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); - it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; double vol = e->getVolume() * e->getVolumeSign(); int nbVertex = e->getNumVertices(); @@ -855,13 +900,13 @@ PView* elasticitySolver::buildStressesView (const std::string postFileName) double valx[256]; double valy[256]; double valz[256]; - for (int k = 0; k < nbVertex; k++){ - MVertex *v = e->getVertex(k); - MPoint p(v); - Field.f(&p, 0, 0, 0, val[k]); - valx[k] = val[k](0); - valy[k] = val[k](1); - valz[k] = val[k](2); + for(int k = 0; k < nbVertex; k++) { + MVertex *v = e->getVertex(k); + MPoint p(v); + Field.f(&p, 0, 0, 0, val[k]); + valx[k] = val[k](0); + valy[k] = val[k](1); + valz[k] = val[k](2); } double gradux[3]; @@ -873,14 +918,16 @@ PView* elasticitySolver::buildStressesView (const std::string postFileName) e->interpolateGrad(valy, u, v, w, graduy); e->interpolateGrad(valz, u, v, w, graduz); - double eps[6] = {gradux[0], graduy[1], graduz[2], - 0.5 * (gradux[1] + graduy[0]), - 0.5 * (gradux[2] + graduz[0]), - 0.5 * (graduy[2] + graduz[1])}; + double eps[6] = {gradux[0], + graduy[1], + graduz[2], + 0.5 * (gradux[1] + graduy[0]), + 0.5 * (gradux[2] + graduz[0]), + 0.5 * (graduy[2] + graduz[1])}; double A = E / (1. + nu); double B = A * (nu / (1. - 2 * nu)); - double trace = eps[0] + eps[1] + eps[2] ; + double trace = eps[0] + eps[1] + eps[2]; double sxx = A * eps[0] + B * trace; double syy = A * eps[1] + B * trace; double szz = A * eps[2] + B * trace; @@ -889,14 +936,19 @@ PView* elasticitySolver::buildStressesView (const std::string postFileName) double syz = A * eps[5]; std::vector<double> vec(9); - vec[0] = sxx; vec[1] = sxy; vec[2] = sxz; - vec[3] = sxy; vec[4] = syy; vec[5] = syz; - vec[6] = sxz; vec[7] = syz; vec[8] = szz; + vec[0] = sxx; + vec[1] = sxy; + vec[2] = sxz; + vec[3] = sxy; + vec[4] = syy; + vec[5] = syz; + vec[6] = sxz; + vec[7] = syz; + vec[8] = szz; data[e->getNum()] = vec; - for(int k = 0; k < 6; k++) - str[k] += eps[k] * vol; + for(int k = 0; k < 6; k++) str[k] += eps[k] * vol; sti[0] += sxx * vol; sti[1] += syy * vol; sti[2] += szz * vol; @@ -906,25 +958,30 @@ PView* elasticitySolver::buildStressesView (const std::string postFileName) volTot += vol; } } - for(int i = 0; i < 6; i++){ + for(int i = 0; i < 6; i++) { str[i] = str[i] / volTot; sti[i] = sti[i] / volTot; } - printf("effective stiffn = ");for(int i = 0; i < 6; i++) printf("%g ",sti[i]);printf("\n"); - printf("effective strain = ");for(int i = 0; i < 6; i++) printf("%g ",str[i]);printf("\n"); + printf("effective stiffn = "); + for(int i = 0; i < 6; i++) printf("%g ", sti[i]); + printf("\n"); + printf("effective strain = "); + for(int i = 0; i < 6; i++) printf("%g ", str[i]); + printf("\n"); - PView *pv = new PView (postFileName, "ElementData", pModel, data, 0.0); + PView *pv = new PView(postFileName, "ElementData", pModel, data, 0.0); return pv; } -PView* elasticitySolver::buildStrainView (const std::string postFileName) +PView *elasticitySolver::buildStrainView(const std::string postFileName) { - std::cout << "build strain view"<< std::endl; + std::cout << "build strain view" << std::endl; std::map<int, std::vector<double> > data; - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { SolverField<SVector3> Field(pAssembler, LagSpace); - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); - it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; int nbVertex = e->getNumVertices(); std::vector<SVector3> val(nbVertex); @@ -932,13 +989,13 @@ PView* elasticitySolver::buildStrainView (const std::string postFileName) double valx[256]; double valy[256]; double valz[256]; - for (int k = 0; k < nbVertex; k++){ - MVertex *v = e->getVertex(k); - MPoint p(v); - Field.f(&p, 0, 0, 0, val[k]); - valx[k] = val[k](0); - valy[k] = val[k](1); - valz[k] = val[k](2); + for(int k = 0; k < nbVertex; k++) { + MVertex *v = e->getVertex(k); + MPoint p(v); + Field.f(&p, 0, 0, 0, val[k]); + valx[k] = val[k](0); + valy[k] = val[k](1); + valz[k] = val[k](2); } double gradux[3]; @@ -964,26 +1021,29 @@ PView* elasticitySolver::buildStrainView (const std::string postFileName) return pv; } -PView* elasticitySolver::buildLagrangeMultiplierView (const std::string postFileName, int tag) +PView * +elasticitySolver::buildLagrangeMultiplierView(const std::string postFileName, + int tag) { - std::cout << "build Lagrange Multiplier View"<< std::endl; + std::cout << "build Lagrange Multiplier View" << std::endl; unsigned int t = 0; if(tag != -1) - for ( ; t < LagrangeMultiplierSpaces.size(); t++) - if (LagrangeMultiplierSpaces[t]->getId() == tag) break; + for(; t < LagrangeMultiplierSpaces.size(); t++) + if(LagrangeMultiplierSpaces[t]->getId() == tag) break; if(t == LagrangeMultiplierSpaces.size()) return new PView(); - std::set<MVertex*> v; - for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i){ + std::set<MVertex *> v; + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i) { for(groupOfElements::elementContainer::const_iterator it = LagrangeMultiplierFields[i].g->begin(); - it != LagrangeMultiplierFields[i].g->end(); ++it){ + it != LagrangeMultiplierFields[i].g->end(); ++it) { MElement *e = *it; - for (std::size_t j = 0; j < e->getNumVertices(); ++j) v.insert(e->getVertex(j)); + for(std::size_t j = 0; j < e->getNumVertices(); ++j) + v.insert(e->getVertex(j)); } } std::map<int, std::vector<double> > data; SolverField<double> Field(pAssembler, LagrangeMultiplierSpaces[t]); - for(std::set<MVertex*>::iterator it = v.begin(); it != v.end(); ++it){ + for(std::set<MVertex *>::iterator it = v.begin(); it != v.end(); ++it) { double val; MPoint p(*it); Field.f(&p, 0, 0, 0, val); @@ -991,24 +1051,25 @@ PView* elasticitySolver::buildLagrangeMultiplierView (const std::string postFile vec.push_back(val); data[(*it)->getNum()] = vec; } - PView *pv = new PView (postFileName, "NodeData", pModel, data, 0.0); + PView *pv = new PView(postFileName, "NodeData", pModel, data, 0.0); return pv; } - PView *elasticitySolver::buildElasticEnergyView(const std::string postFileName) { - std::cout << "build Elastic Energy View"<< std::endl; + std::cout << "build Elastic Energy View" << std::endl; std::map<int, std::vector<double> > data; GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E == 0.) continue; SolverField<SVector3> Field(pAssembler, LagSpace); - IsotropicElasticTerm Eterm(Field, elasticFields[i]._E, elasticFields[i]._nu); + IsotropicElasticTerm Eterm(Field, elasticFields[i]._E, + elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); ScalarTermConstant<double> One(1.0); - for (groupOfElements::elementContainer::const_iterator it = - elasticFields[i].g->begin(); it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; double energ; double vol; @@ -1021,20 +1082,22 @@ PView *elasticitySolver::buildElasticEnergyView(const std::string postFileName) data[e->getNum()] = vec; } } - PView *pv = new PView (postFileName, "ElementData", pModel, data, 0.0); + PView *pv = new PView(postFileName, "ElementData", pModel, data, 0.0); return pv; } PView *elasticitySolver::buildVolumeView(const std::string postFileName) { - std::cout << "build Volume View"; + std::cout << "build Volume View"; std::map<int, std::vector<double> > data; - double voltot = 0; double length = 0; + double voltot = 0; + double length = 0; GaussQuadrature Integ_Vol(GaussQuadrature::Val); - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { ScalarTermConstant<double> One(1.0); - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); - it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; double vol; IntPt *GP; @@ -1046,10 +1109,11 @@ PView *elasticitySolver::buildVolumeView(const std::string postFileName) data[e->getNum()] = vec; } } - for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i){ + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i) { ScalarTermConstant<double> One(1.0); - for (groupOfElements::elementContainer::const_iterator it = LagrangeMultiplierFields[i].g->begin(); - it != LagrangeMultiplierFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + LagrangeMultiplierFields[i].g->begin(); + it != LagrangeMultiplierFields[i].g->end(); ++it) { MElement *e = *it; double l; IntPt *GP; @@ -1057,25 +1121,28 @@ PView *elasticitySolver::buildVolumeView(const std::string postFileName) One.get(e, npts, GP, l); length += l; } - std::cout << " : length " << LagrangeMultiplierFields[i]._tag << " = " << length; + std::cout << " : length " << LagrangeMultiplierFields[i]._tag << " = " + << length; length = 0; } - PView *pv = new PView (postFileName, "ElementData", pModel, data, 0.0, 1); + PView *pv = new PView(postFileName, "ElementData", pModel, data, 0.0, 1); std::cout << " / total vol = " << voltot << std::endl; return pv; } PView *elasticitySolver::buildVonMisesView(const std::string postFileName) { - std::cout << "build elastic view"<< std::endl; + std::cout << "build elastic view" << std::endl; std::map<int, std::vector<double> > data; GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); - for (unsigned int i = 0; i < elasticFields.size(); ++i){ + for(unsigned int i = 0; i < elasticFields.size(); ++i) { SolverField<SVector3> Field(pAssembler, LagSpace); - IsotropicElasticTerm Eterm(Field, elasticFields[i]._E, elasticFields[i]._nu); + IsotropicElasticTerm Eterm(Field, elasticFields[i]._E, + elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); - for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); - it != elasticFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + elasticFields[i].g->begin(); + it != elasticFields[i].g->end(); ++it) { MElement *e = *it; double energ; IntPt *GP; @@ -1086,50 +1153,51 @@ PView *elasticitySolver::buildVonMisesView(const std::string postFileName) data[(*it)->getNum()] = vec; } } - PView *pv = new PView (postFileName, "ElementData", pModel, data, 0.0); + PView *pv = new PView(postFileName, "ElementData", pModel, data, 0.0); return pv; } #else -PView* elasticitySolver::buildErrorView(int comp, simpleFunction<double> *sol, +PView *elasticitySolver::buildErrorView(int comp, simpleFunction<double> *sol, const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; } -PView* elasticitySolver::buildDisplacementView(const std::string postFileName) +PView *elasticitySolver::buildDisplacementView(const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; } -PView* elasticitySolver::buildStrainView(const std::string postFileName) +PView *elasticitySolver::buildStrainView(const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; } -PView* elasticitySolver::buildLagrangeMultiplierView (const std::string postFileName) +PView * +elasticitySolver::buildLagrangeMultiplierView(const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; } -PView* elasticitySolver::buildElasticEnergyView(const std::string postFileName) +PView *elasticitySolver::buildElasticEnergyView(const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; } -PView* elasticitySolver::buildVonMisesView(const std::string postFileName) +PView *elasticitySolver::buildVonMisesView(const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; } -PView* elasticitySolver::buildStressesView (const std::string postFileName) +PView *elasticitySolver::buildStressesView(const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; diff --git a/Solver/elasticitySolver.h b/Solver/elasticitySolver.h index f02abc4a719517ba1ac584e3cf353f93dcb69e66..3a8410c2ef9a181db50e1255252422800004a202 100644 --- a/Solver/elasticitySolver.h +++ b/Solver/elasticitySolver.h @@ -24,41 +24,37 @@ struct LagrangeMultiplierField { double _tau; SVector3 _d; simpleFunction<double> *_f; - LagrangeMultiplierField() : _tag(0), g(0){} + LagrangeMultiplierField() : _tag(0), g(0) {} }; struct elasticField { int _tag; // tag for the dofManager groupOfElements *g; // support for this field double _E, _nu; // specific elastic datas (should be somewhere else) - elasticField () : _tag(0), g(0){} + elasticField() : _tag(0), g(0) {} }; -struct BoundaryCondition -{ +struct BoundaryCondition { int _tag; // tag for the dofManager - enum location{UNDEF, ON_VERTEX, ON_EDGE, ON_FACE, ON_VOLUME}; + enum location { UNDEF, ON_VERTEX, ON_EDGE, ON_FACE, ON_VOLUME }; location onWhat; // on vertices or elements groupOfElements *g; // support for this BC BoundaryCondition() : _tag(0), onWhat(UNDEF), g(0) {} }; -struct dirichletBC : public BoundaryCondition -{ +struct dirichletBC : public BoundaryCondition { int _comp; // component simpleFunction<double> *_f; - dirichletBC ():BoundaryCondition(), _comp(0), _f(0){} + dirichletBC() : BoundaryCondition(), _comp(0), _f(0) {} }; -struct neumannBC : public BoundaryCondition -{ +struct neumannBC : public BoundaryCondition { simpleFunction<SVector3> *_f; - neumannBC () : BoundaryCondition(), _f(NULL){} + neumannBC() : BoundaryCondition(), _f(NULL) {} }; // an elastic solver ... -class elasticitySolver -{ - public: +class elasticitySolver { +public: GModel *pModel; int _dim, _tag; dofManager<double> *pAssembler; @@ -66,7 +62,7 @@ class elasticitySolver std::vector<FunctionSpace<double> *> LagrangeMultiplierSpaces; // young modulus and poisson coefficient per physical - std::vector<elasticField> elasticFields; + std::vector<elasticField> elasticFields; std::vector<LagrangeMultiplierField> LagrangeMultiplierFields; // neumann BC @@ -74,7 +70,7 @@ class elasticitySolver // dirichlet BC std::vector<dirichletBC> allDirichlet; - public: +public: elasticitySolver(int tag) : _tag(tag), pAssembler(0), LagSpace(0) {} elasticitySolver(GModel *model, int tag); @@ -88,19 +84,20 @@ class elasticitySolver virtual ~elasticitySolver() { - if (LagSpace) delete LagSpace; - for (unsigned int i = 0; i < LagrangeMultiplierSpaces.size(); i++) - if (LagrangeMultiplierSpaces[i]) delete LagrangeMultiplierSpaces[i]; + if(LagSpace) delete LagSpace; + for(unsigned int i = 0; i < LagrangeMultiplierSpaces.size(); i++) + if(LagrangeMultiplierSpaces[i]) delete LagrangeMultiplierSpaces[i]; LagrangeMultiplierSpaces.clear(); - if (pAssembler) delete pAssembler; + if(pAssembler) delete pAssembler; } - void assemble (linearSystem<double> *lsys); + void assemble(linearSystem<double> *lsys); void readInputFile(const std::string &meshFileName); - void read(const std::string s) {readInputFile(s.c_str());} + void read(const std::string s) { readInputFile(s.c_str()); } virtual void setMesh(const std::string &meshFileName, int dim = 0); void cutMesh(gLevelset *ls); void setElasticDomain(int phys, double E, double nu); - void setLagrangeMultipliers(int phys, double tau, SVector3 d, int tag, simpleFunction<double> *f); + void setLagrangeMultipliers(int phys, double tau, SVector3 d, int tag, + simpleFunction<double> *f); void changeLMTau(int tag, double tau); void setEdgeDisp(int edge, int comp, simpleFunction<double> *f); void solve(); @@ -111,20 +108,26 @@ class elasticitySolver virtual PView *buildDisplacementView(const std::string postFileName); virtual PView *buildStrainView(const std::string postFileName); virtual PView *buildStressesView(const std::string postFileName); - virtual PView *buildLagrangeMultiplierView(const std::string posFileName, int tag = -1); + virtual PView *buildLagrangeMultiplierView(const std::string posFileName, + int tag = -1); virtual PView *buildElasticEnergyView(const std::string postFileName); virtual PView *buildVonMisesView(const std::string postFileName); virtual PView *buildVolumeView(const std::string postFileName); - virtual PView *buildErrorView(const std::string postFileName, simpleFunction<double> *f0, - simpleFunction<double> *f1, simpleFunction<double> *f2); - double computeDisplacementError(simpleFunction<double> *f0, simpleFunction<double> *f1, + virtual PView *buildErrorView(const std::string postFileName, + simpleFunction<double> *f0, + simpleFunction<double> *f1, + simpleFunction<double> *f2); + double computeDisplacementError(simpleFunction<double> *f0, + simpleFunction<double> *f1, simpleFunction<double> *f2); - double computeL2Norm(simpleFunction<double> *f0, simpleFunction<double> *f1, simpleFunction<double> *f2); + double computeL2Norm(simpleFunction<double> *f0, simpleFunction<double> *f1, + simpleFunction<double> *f2); double computeLagNorm(int tag, simpleFunction<double> *f); // std::pair<PView *, PView*> buildErrorEstimateView // (const std::string &errorFileName, double, int); // std::pair<PView *, PView*> buildErrorEstimateView - // (const std::string &errorFileName, const elasticityData &ref, double, int); + // (const std::string &errorFileName, const elasticityData &ref, double, + // int); }; #endif diff --git a/Solver/elasticityTerm.cpp b/Solver/elasticityTerm.cpp index ebf18298a6ca3058a9c5b63c12d636771b74c81e..8ebca2324363bb581ac6352672f67c17c3301a14 100644 --- a/Solver/elasticityTerm.cpp +++ b/Solver/elasticityTerm.cpp @@ -11,25 +11,25 @@ void elasticityTerm::createData(MElement *e) const { - if (_data.find(e->getTypeForMSH()) != _data.end())return; + if(_data.find(e->getTypeForMSH()) != _data.end()) return; elasticityDataAtGaussPoint d; int nbSF = e->getNumShapeFunctions(); - int integrationOrder = 2 * (e->getPolynomialOrder() - 1) ; + int integrationOrder = 2 * (e->getPolynomialOrder() - 1); int npts; IntPt *GP; double gs[100][3]; e->getIntegrationPoints(integrationOrder, &npts, &GP); - for (int i=0;i<npts;i++){ - fullMatrix<double> a(nbSF,3); + for(int i = 0; i < npts; i++) { + fullMatrix<double> a(nbSF, 3); const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; const double weight = GP[i].weight; - e->getGradShapeFunctions(u,v,w,gs); - for (int j=0;j < nbSF;j++){ - a(j,0) = gs[j][0]; - a(j,1) = gs[j][1]; - a(j,2) = gs[j][2]; + e->getGradShapeFunctions(u, v, w, gs); + for(int j = 0; j < nbSF; j++) { + a(j, 0) = gs[j][0]; + a(j, 1) = gs[j][1]; + a(j, 2) = gs[j][2]; } d.gradSF.push_back(a); d.u.push_back(u); @@ -37,7 +37,8 @@ void elasticityTerm::createData(MElement *e) const d.w.push_back(w); d.weight.push_back(weight); } - // printf("coucou creation of a data for %d with %d points\n",e->getTypeForMSH(),npts); + // printf("coucou creation of a data for %d with %d + // points\n",e->getTypeForMSH(),npts); _data[e->getTypeForMSH()] = d; } @@ -55,47 +56,41 @@ void elasticityTerm::elementMatrix(SElement *se, fullMatrix<double> &m) const double C11 = FACT * (1 - _nu) / (1 - 2 * _nu); double C12 = FACT * _nu / (1 - 2 * _nu); double C44 = (C11 - C12) / 2; - const double C[6][6] = - { {C11, C12, C12, 0, 0, 0}, - {C12, C11, C12, 0, 0, 0}, - {C12, C12, C11, 0, 0, 0}, - { 0, 0, 0, C44, 0, 0}, - { 0, 0, 0, 0, C44, 0}, - { 0, 0, 0, 0, 0, C44} }; + const double C[6][6] = {{C11, C12, C12, 0, 0, 0}, {C12, C11, C12, 0, 0, 0}, + {C12, C12, C11, 0, 0, 0}, {0, 0, 0, C44, 0, 0}, + {0, 0, 0, 0, C44, 0}, {0, 0, 0, 0, 0, C44}}; fullMatrix<double> H(6, 6); fullMatrix<double> B(6, 3 * nbSF); fullMatrix<double> BTH(3 * nbSF, 6); fullMatrix<double> BT(3 * nbSF, 6); - for (int i = 0; i < 6; i++) - for (int j = 0; j < 6; j++) - H(i, j) = C[i][j]; + for(int i = 0; i < 6; i++) + for(int j = 0; j < 6; j++) H(i, j) = C[i][j]; - double jac[3][3],invjac[3][3],Grads[100][3]; - for (int i = 0; i < npts; i++){ + double jac[3][3], invjac[3][3], Grads[100][3]; + for(int i = 0; i < npts; i++) { const double weight = d.weight[i]; const fullMatrix<double> &grads = d.gradSF[i]; const double detJ = e->getJacobian(grads, jac); inv3x3(jac, invjac); - for (int j = 0; j < nbSF; j++){ - Grads[j][0] = invjac[0][0] * grads(j,0) + invjac[0][1] * grads(j,1) + - invjac[0][2] * grads(j,2); - Grads[j][1] = invjac[1][0] * grads(j,0) + invjac[1][1] * grads(j,1) + - invjac[1][2] * grads(j,2); - Grads[j][2] = invjac[2][0] * grads(j,0) + invjac[2][1] * grads(j,1) + - invjac[2][2] * grads(j,2); + for(int j = 0; j < nbSF; j++) { + Grads[j][0] = invjac[0][0] * grads(j, 0) + invjac[0][1] * grads(j, 1) + + invjac[0][2] * grads(j, 2); + Grads[j][1] = invjac[1][0] * grads(j, 0) + invjac[1][1] * grads(j, 1) + + invjac[1][2] * grads(j, 2); + Grads[j][2] = invjac[2][0] * grads(j, 0) + invjac[2][1] * grads(j, 1) + + invjac[2][2] * grads(j, 2); } - B.setAll(0.); BT.setAll(0.); - if (se->getShapeEnrichement() == se->getTestEnrichement()){ + if(se->getShapeEnrichement() == se->getTestEnrichement()) { // printf("coucou\n"); - for (int j = 0; j < nbSF; j++){ + for(int j = 0; j < nbSF; j++) { BT(j, 0) = B(0, j) = Grads[j][0]; - BT(j, 3) = B(3, j) = Grads[j][1]; + BT(j, 3) = B(3, j) = Grads[j][1]; BT(j, 5) = B(5, j) = Grads[j][2]; BT(j + nbSF, 1) = B(1, j + nbSF) = Grads[j][1]; @@ -107,7 +102,7 @@ void elasticityTerm::elementMatrix(SElement *se, fullMatrix<double> &m) const BT(j + 2 * nbSF, 5) = B(5, j + 2 * nbSF) = Grads[j][0]; } } - else{ + else { /* se->gradNodalTestFunctions (u, v, w, invjac,GradsT); for (int j = 0; j < nbSF; j++){ @@ -146,14 +141,14 @@ void elasticityTerm::elementVector(SElement *se, fullVector<double> &m) const m.scale(0.); - for (int i = 0; i < npts; i++){ + for(int i = 0; i < npts; i++) { const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; const double weight = GP[i].weight; const double detJ = e->getJacobian(u, v, w, jac); se->nodalTestFunctions(u, v, w, ff); - for (int j = 0; j < nbSF; j++){ + for(int j = 0; j < nbSF; j++) { m(j) += _volumeForce.x() * ff[j] * weight * detJ * .5; m(j + nbSF) += _volumeForce.y() * ff[j] * weight * detJ * .5; m(j + 2 * nbSF) += _volumeForce.z() * ff[j] * weight * detJ * .5; @@ -169,7 +164,8 @@ K_{uu} = \int_\Omega B^T_d H B_d dv */ -void elasticityMixedTerm::elementMatrix(SElement *se, fullMatrix<double> &m) const +void elasticityMixedTerm::elementMatrix(SElement *se, + fullMatrix<double> &m) const { setPolynomialBasis(se); MElement *e = se->getMeshElement(); @@ -183,78 +179,75 @@ void elasticityMixedTerm::elementMatrix(SElement *se, fullMatrix<double> &m) con e->getIntegrationPoints(integrationOrder, &npts, &GP); m.setAll(0.); - fullMatrix<double> KUU(3 * _sizeN,3 * _sizeN); - fullMatrix<double> KUP(3 * _sizeN,_sizeM); - fullMatrix<double> KUG(3 * _sizeN,_sizeM); - fullMatrix<double> KPG(_sizeM,_sizeM); - fullMatrix<double> KGG(_sizeM,_sizeM); - fullMatrix<double> KPP(_sizeM,_sizeM); // stabilization - - double FACT = _E / ((1 + _nu)*(1.-2*_nu)); - double C11 = FACT * (1 - _nu) ; - double C12 = FACT * _nu ; - double C44 = FACT* (1 - 2.*_nu)*.5; - //double _K = 3*_E / (1 - 2 * _nu); + fullMatrix<double> KUU(3 * _sizeN, 3 * _sizeN); + fullMatrix<double> KUP(3 * _sizeN, _sizeM); + fullMatrix<double> KUG(3 * _sizeN, _sizeM); + fullMatrix<double> KPG(_sizeM, _sizeM); + fullMatrix<double> KGG(_sizeM, _sizeM); + fullMatrix<double> KPP(_sizeM, _sizeM); // stabilization + + double FACT = _E / ((1 + _nu) * (1. - 2 * _nu)); + double C11 = FACT * (1 - _nu); + double C12 = FACT * _nu; + double C44 = FACT * (1 - 2. * _nu) * .5; + // double _K = 3*_E / (1 - 2 * _nu); // FIXME : PLANE STRESS !!! - // FACT = _E / (1-_nu*_nu); - // C11 = FACT; - // C12 = _nu * FACT; - // C44 = (1.-_nu)*.5*FACT; - - const double C[6][6] = - { {C11, C12, C12, 0, 0, 0}, - {C12, C11, C12, 0, 0, 0}, - {C12, C12, C11, 0, 0, 0}, - { 0, 0, 0, C44, 0, 0}, - { 0, 0, 0, 0, C44, 0}, - { 0, 0, 0, 0, 0, C44} }; - - fullMatrix<double> H (6, 6); - fullMatrix<double> B (6, 3 * _sizeN); - fullMatrix<double> BDEV (6, 3 * _sizeN); - fullMatrix<double> BDIL (1, 3 * _sizeN); - fullMatrix<double> BDILT (3 * _sizeN,1); + // FACT = _E / (1-_nu*_nu); + // C11 = FACT; + // C12 = _nu * FACT; + // C44 = (1.-_nu)*.5*FACT; + + const double C[6][6] = {{C11, C12, C12, 0, 0, 0}, {C12, C11, C12, 0, 0, 0}, + {C12, C12, C11, 0, 0, 0}, {0, 0, 0, C44, 0, 0}, + {0, 0, 0, 0, C44, 0}, {0, 0, 0, 0, 0, C44}}; + + fullMatrix<double> H(6, 6); + fullMatrix<double> B(6, 3 * _sizeN); + fullMatrix<double> BDEV(6, 3 * _sizeN); + fullMatrix<double> BDIL(1, 3 * _sizeN); + fullMatrix<double> BDILT(3 * _sizeN, 1); fullMatrix<double> BTH(3 * _sizeN, 6); fullMatrix<double> BT(3 * _sizeN, 6); fullMatrix<double> trBTH(3 * _sizeN, 1); fullMatrix<double> MT(_sizeM, 1); - fullMatrix<double> M(1,_sizeM); - for (int i = 0; i < 6; i++) - for (int j = 0; j < 6; j++) - H(i, j) = C[i][j]; + fullMatrix<double> M(1, _sizeM); + for(int i = 0; i < 6; i++) + for(int j = 0; j < 6; j++) H(i, j) = C[i][j]; double _dimension = 2.0; - for (int i = 0; i < npts; i++){ + for(int i = 0; i < npts; i++) { const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; const double weight = GP[i].weight; const double detJ = e->getJacobian(u, v, w, jac); inv3x3(jac, invjac); - se->gradNodalShapeFunctions(u, v, w, invjac,Grads); - e->getShapeFunctions (u,v,w,SF,_polyOrderM); + se->gradNodalShapeFunctions(u, v, w, invjac, Grads); + e->getShapeFunctions(u, v, w, SF, _polyOrderM); B.setAll(0.); BT.setAll(0.); - const double K = .0000002*weight * detJ * pow (detJ,2/_dimension); // the second detJ is for stabilization + const double K = + .0000002 * weight * detJ * + pow(detJ, 2 / _dimension); // the second detJ is for stabilization - for (int j = 0; j < _sizeM; j++){ - for (int k = 0; k < _sizeM; k++){ - KPP(j, k) += (Grads[j][0] * Grads[k][0] + - Grads[j][1] * Grads[k][1] + - Grads[j][2] * Grads[k][2])* K; + for(int j = 0; j < _sizeM; j++) { + for(int k = 0; k < _sizeM; k++) { + KPP(j, k) += (Grads[j][0] * Grads[k][0] + Grads[j][1] * Grads[k][1] + + Grads[j][2] * Grads[k][2]) * + K; } } const double K2 = weight * detJ; - for (int j = 0; j < _sizeN; j++){ - for (int k = 0; k < _sizeM; k++){ - KUP(j+0*_sizeN, k) += Grads[j][0] * SF[k] * K2; - KUP(j+1*_sizeN, k) += Grads[j][1] * SF[k] * K2; - KUP(j+2*_sizeN, k) += Grads[j][2] * SF[k] * K2; + for(int j = 0; j < _sizeN; j++) { + for(int k = 0; k < _sizeM; k++) { + KUP(j + 0 * _sizeN, k) += Grads[j][0] * SF[k] * K2; + KUP(j + 1 * _sizeN, k) += Grads[j][1] * SF[k] * K2; + KUP(j + 2 * _sizeN, k) += Grads[j][2] * SF[k] * K2; } } @@ -262,60 +255,63 @@ void elasticityMixedTerm::elementMatrix(SElement *se, fullMatrix<double> &m) con const double K3 = weight * detJ * _E/(2*(1+_nu)); for (int j = 0; j < _sizeN; j++){ for (int k = 0; k < _sizeN; k++){ - const double fa = (Grads[j][0] * Grads[k][0] + - Grads[j][1] * Grads[k][1] + - Grads[j][2] * Grads[k][2]) * K3; - KUU(j+0*_sizeN, k+0*_sizeN) += fa; - KUU(j+1*_sizeN, k+1*_sizeN) += fa; - KUU(j+2*_sizeN, k+2*_sizeN) += fa; + const double fa = (Grads[j][0] * Grads[k][0] + + Grads[j][1] * Grads[k][1] + + Grads[j][2] * Grads[k][2]) * K3; + KUU(j+0*_sizeN, k+0*_sizeN) += fa; + KUU(j+1*_sizeN, k+1*_sizeN) += fa; + KUU(j+2*_sizeN, k+2*_sizeN) += fa; } } */ - - for (int j = 0; j < _sizeN; j++){ - + for(int j = 0; j < _sizeN; j++) { // printf("%g %g %g\n",Grads[j][0],Grads[j][1],Grads[j][2]); - BDILT(j, 0) = BDIL(0, j) = Grads[j][0]/_dimension; + BDILT(j, 0) = BDIL(0, j) = Grads[j][0] / _dimension; - BT(j, 0) = B(0, j) = Grads[j][0];//-Grads[j][0]/_dimension; + BT(j, 0) = B(0, j) = Grads[j][0]; //-Grads[j][0]/_dimension; // BT(j, 1) = B(1, j) = -Grads[j][1]/_dimension; // BT(j, 2) = B(2, j) = -Grads[j][2]/_dimension; BT(j, 3) = B(3, j) = Grads[j][1]; BT(j, 4) = B(4, j) = Grads[j][2]; - BDILT(j + _sizeN, 0) = BDIL(0, j + _sizeN) = Grads[j][1]/_dimension; + BDILT(j + _sizeN, 0) = BDIL(0, j + _sizeN) = Grads[j][1] / _dimension; - // BT(j + _sizeN, 0) = B(0, j + _sizeN) = -Grads[j][0]/_dimension; - BT(j + _sizeN, 1) = B(1, j + _sizeN) = Grads[j][1];//-Grads[j][1]/_dimension; - // BT(j + _sizeN, 2) = B(2, j + _sizeN) = -Grads[j][2]/_dimension; + // BT(j + _sizeN, 0) = B(0, j + _sizeN) = -Grads[j][0]/_dimension; + BT(j + _sizeN, 1) = B(1, j + _sizeN) = + Grads[j][1]; //-Grads[j][1]/_dimension; + // BT(j + _sizeN, 2) = B(2, j + _sizeN) = -Grads[j][2]/_dimension; BT(j + _sizeN, 3) = B(3, j + _sizeN) = Grads[j][0]; BT(j + _sizeN, 5) = B(5, j + _sizeN) = Grads[j][2]; - BDILT(j + 2 * _sizeN, 0) = BDIL(0, j + 2 * _sizeN) = Grads[j][2]/_dimension; + BDILT(j + 2 * _sizeN, 0) = BDIL(0, j + 2 * _sizeN) = + Grads[j][2] / _dimension; - // BT(j + 2 * _sizeN, 0) = B(0, j + 2 * _sizeN) = -Grads[j][0]/_dimension; - // BT(j + 2 * _sizeN, 1) = B(1, j + 2 * _sizeN) = -Grads[j][1]/_dimension; - BT(j + 2 * _sizeN, 2) = B(2, j + 2 * _sizeN) = Grads[j][2];//-Grads[j][2]/_dimension; + // BT(j + 2 * _sizeN, 0) = B(0, j + 2 * _sizeN) = + // -Grads[j][0]/_dimension; BT(j + 2 * _sizeN, 1) = B(1, j + 2 * + // _sizeN) = -Grads[j][1]/_dimension; + BT(j + 2 * _sizeN, 2) = B(2, j + 2 * _sizeN) = + Grads[j][2]; //-Grads[j][2]/_dimension; BT(j + 2 * _sizeN, 4) = B(4, j + 2 * _sizeN) = Grads[j][1]; BT(j + 2 * _sizeN, 5) = B(5, j + 2 * _sizeN) = Grads[j][0]; } - for (int j = 0; j < _sizeM; j++){ - MT(j,0) = M(0,j) = SF[j]; + for(int j = 0; j < _sizeM; j++) { + MT(j, 0) = M(0, j) = SF[j]; } - // printf("BT (%d %d) x H (%d,%d) = BTH(%d,%d)\n",BT.size1(),BT.size2(), H.size1(),H.size2(),BTH.size1(),BTH.size2()); + // printf("BT (%d %d) x H (%d,%d) = BTH(%d,%d)\n",BT.size1(),BT.size2(), + // H.size1(),H.size2(),BTH.size1(),BTH.size2()); BTH.setAll(0.); BTH.gemm(BT, H); - for (int j = 0; j < 3*_sizeN; j++){ - trBTH(j,0) = BTH(j,0) + BTH(j,1) + BTH(j,2) ; + for(int j = 0; j < 3 * _sizeN; j++) { + trBTH(j, 0) = BTH(j, 0) + BTH(j, 1) + BTH(j, 2); } KUU.gemm(BTH, B, weight * detJ); @@ -323,44 +319,40 @@ void elasticityMixedTerm::elementMatrix(SElement *se, fullMatrix<double> &m) con // KPG.gemm(MT, M, -weight * detJ); // KUG.gemm(trBTH, M, weight * detJ/_dimension); // KGG.gemm(MT, M, weight * detJ * (_K)/(_dimension*_dimension)); - } - /* - 3*_sizeN _sizeM _sizeM + /* + 3*_sizeN _sizeM _sizeM - KUU KUP KUG - m = KUP^t KPP KPG - KUG^T KPG^t KGG + KUU KUP KUG + m = KUP^t KPP KPG + KUG^T KPG^t KGG - */ + */ - for (int i=0;i<3*_sizeN;i++){ - for (int j=0;j<3*_sizeN;j++) - m(i,j) = KUU(i,j); // assemble KUU + for(int i = 0; i < 3 * _sizeN; i++) { + for(int j = 0; j < 3 * _sizeN; j++) m(i, j) = KUU(i, j); // assemble KUU - for (int j=0;j<_sizeM;j++){ - m(i,j+3*_sizeN) = KUP(i,j); // assemble KUP - m(j+3*_sizeN,i) = KUP(i,j); // assemble KUP^T + for(int j = 0; j < _sizeM; j++) { + m(i, j + 3 * _sizeN) = KUP(i, j); // assemble KUP + m(j + 3 * _sizeN, i) = KUP(i, j); // assemble KUP^T } - for (int j=0;j<_sizeM;j++){ - m(i,j+3*_sizeN+_sizeM) = KUG(i,j); // assemble KUG - m(j+3*_sizeN+_sizeM,i) = KUG(i,j); // assemble KUG^t + for(int j = 0; j < _sizeM; j++) { + m(i, j + 3 * _sizeN + _sizeM) = KUG(i, j); // assemble KUG + m(j + 3 * _sizeN + _sizeM, i) = KUG(i, j); // assemble KUG^t } } - for (int i=0;i<_sizeM;i++){ - for (int j=0;j<_sizeM;j++){ - m(i+3*_sizeN,j+3*_sizeN+_sizeM) = KPG(i,j); // assemble KPG - m(j+3*_sizeN+_sizeM,i+3*_sizeN) = KPG(i,j); // assemble KPG^t + for(int i = 0; i < _sizeM; i++) { + for(int j = 0; j < _sizeM; j++) { + m(i + 3 * _sizeN, j + 3 * _sizeN + _sizeM) = KPG(i, j); // assemble KPG + m(j + 3 * _sizeN + _sizeM, i + 3 * _sizeN) = KPG(i, j); // assemble KPG^t - m(i+3*_sizeN+_sizeM,j+3*_sizeN+_sizeM) = KGG(i,j); // assemble KGG - - m(i+3*_sizeN,j+3*_sizeN) = KPP(i,j); // assemble KPP + m(i + 3 * _sizeN + _sizeM, j + 3 * _sizeN + _sizeM) = + KGG(i, j); // assemble KGG + m(i + 3 * _sizeN, j + 3 * _sizeN) = KPP(i, j); // assemble KPP } } // m.print("Mixed"); return; - } - diff --git a/Solver/elasticityTerm.h b/Solver/elasticityTerm.h index 3acc1b0e4d4bf891ecd64f5b8e8ad08fa7916c64..01ad524a8b33115a72f4de3fcea378b8800f6aa7 100644 --- a/Solver/elasticityTerm.h +++ b/Solver/elasticityTerm.h @@ -13,22 +13,22 @@ #include "SElement.h" #include "fullMatrix.h" -struct elasticityDataAtGaussPoint -{ - std::vector< fullMatrix<double> > gradSF; - std::vector<double> u,v,w,weight; +struct elasticityDataAtGaussPoint { + std::vector<fullMatrix<double> > gradSF; + std::vector<double> u, v, w, weight; }; class elasticityTerm : public femTerm<double> { - protected: +protected: double _E, _nu; int _iFieldR, _iFieldC; SVector3 _volumeForce; - mutable std::map<int,elasticityDataAtGaussPoint> _data; - void createData (MElement*) const; - public: - void setFieldC(int i){_iFieldC = i;} - void setFieldR(int i){_iFieldR = i;} + mutable std::map<int, elasticityDataAtGaussPoint> _data; + void createData(MElement *) const; + +public: + void setFieldC(int i) { _iFieldC = i; } + void setFieldR(int i) { _iFieldR = i; } // element matrix size : 3 dofs per vertex virtual int sizeOfR(SElement *se) const { @@ -56,11 +56,16 @@ class elasticityTerm : public femTerm<double> { return Dof(e->getShapeFunctionNode(ithLocalVertex)->getNum(), Dof::createTypeWithTwoInts(iCompC, _iFieldC)); } - public: - elasticityTerm(GModel *gm, double E, double nu, int fieldr, int fieldc) - : femTerm<double>(gm), _E(E), _nu(nu), _iFieldR(fieldr),_iFieldC(fieldc) {} - elasticityTerm(GModel *gm, double E, double nu, int fieldr) - : femTerm<double>(gm), _E(E), _nu(nu), _iFieldR(fieldr),_iFieldC(fieldr) {} + +public: + elasticityTerm(GModel *gm, double E, double nu, int fieldr, int fieldc) + : femTerm<double>(gm), _E(E), _nu(nu), _iFieldR(fieldr), _iFieldC(fieldc) + { + } + elasticityTerm(GModel *gm, double E, double nu, int fieldr) + : femTerm<double>(gm), _E(E), _nu(nu), _iFieldR(fieldr), _iFieldC(fieldr) + { + } void setVector(const SVector3 &f) { _volumeForce = f; } void elementMatrix(SElement *se, fullMatrix<double> &m) const; void elementVector(SElement *se, fullVector<double> &m) const; @@ -81,27 +86,28 @@ class elasticityMixedTerm : public femTerm<double> { protected: double _E, _nu; mutable int _iField, _polyOrderN, _polyOrderM, _sizeN, _sizeM; - mutable polynomialBasis *_pN,*_pM; - void setPolynomialBasis (SElement *se) const{ - _polyOrderN = se->getMeshElement()->getPolynomialOrder(); - _polyOrderM = se->getMeshElement()->getPolynomialOrder(); - _pN = (polynomialBasis*)se->getMeshElement()->getFunctionSpace(_polyOrderN); - _pM = (polynomialBasis*)se->getMeshElement()->getFunctionSpace(_polyOrderM); + mutable polynomialBasis *_pN, *_pM; + void setPolynomialBasis(SElement *se) const + { + _polyOrderN = se->getMeshElement()->getPolynomialOrder(); + _polyOrderM = se->getMeshElement()->getPolynomialOrder(); + _pN = + (polynomialBasis *)se->getMeshElement()->getFunctionSpace(_polyOrderN); + _pM = + (polynomialBasis *)se->getMeshElement()->getFunctionSpace(_polyOrderM); _sizeN = _pN->coefficients.size1(); _sizeM = _pM->coefficients.size1(); } + public: - void setField(int i){_iField = i;} + void setField(int i) { _iField = i; } // element matrix size : 3 dofs per vertex virtual int sizeOfR(SElement *se) const { setPolynomialBasis(se); return 3 * _sizeN + 2 * _sizeM; } - virtual int sizeOfC(SElement *se) const - { - return sizeOfR(se); - } + virtual int sizeOfC(SElement *se) const { return sizeOfR(se); } // order dofs in the local matrix : // dx1, dx2 ... dxn, dy1, ..., dyn, dz1, ... dzn , // p1,p2,...,pm, g1,g2,...,gm @@ -111,7 +117,7 @@ public: MElement *e = se->getMeshElement(); int iComp; int ithLocalVertex; - if (iRow < 3 * _sizeN){ + if(iRow < 3 * _sizeN) { iComp = iRow / _sizeN; ithLocalVertex = iRow % _sizeN; } @@ -125,15 +131,17 @@ public: } Dof getLocalDofC(SElement *se, int iCol) const { - return getLocalDofR(se,iCol); + return getLocalDofR(se, iCol); + } + +public: + elasticityMixedTerm(GModel *gm, double E, double nu, int field) + : femTerm<double>(gm), _E(E), _nu(nu), _iField(field) + { } - public: - elasticityMixedTerm(GModel *gm, double E, double nu, int field) - : femTerm<double>(gm), _E(E), _nu(nu), _iField(field) {} void elementMatrix(SElement *se, fullMatrix<double> &m) const; void elementVector(SElement *se, fullVector<double> &m) const {} - void setYoung (double E){_E = E;} + void setYoung(double E) { _E = E; } }; - #endif diff --git a/Solver/femTerm.h b/Solver/femTerm.h index f539f33184897b043725e9440b8f7e7690ec661d..cb3e8bd1b329e1e2b6409b6b1cd4123ff100d444 100644 --- a/Solver/femTerm.h +++ b/Solver/femTerm.h @@ -18,14 +18,15 @@ // a nodal finite element term : variables are always defined at nodes // of the mesh -template<class T> -class femTerm { - private: +template <class T> class femTerm { +private: typedef typename dofTraits<T>::VecType dataVec; typedef typename dofTraits<T>::MatType dataMat; - protected: + +protected: GModel *_gm; - public: + +public: femTerm(GModel *gm) : _gm(gm) {} virtual ~femTerm() {} // return the number of columns of the element matrix @@ -44,19 +45,18 @@ class femTerm { virtual void elementMatrix(SElement *se, fullMatrix<dataMat> &m) const = 0; virtual void elementVector(SElement *se, fullVector<dataVec> &m) const { - m.scale(0.0); + m.scale(0.0); } // add the contribution from all the elements in the intersection // of two element groups L and C - void addToMatrix(dofManager<dataVec> &dm, - groupOfElements &L, + void addToMatrix(dofManager<dataVec> &dm, groupOfElements &L, groupOfElements &C) const { groupOfElements::elementContainer::const_iterator it = L.begin(); - for ( ; it != L.end(); ++it){ + for(; it != L.end(); ++it) { MElement *eL = *it; - if (&C == &L || C.find(eL)){ + if(&C == &L || C.find(eL)) { SElement se(eL); addToMatrix(dm, &se); } @@ -72,36 +72,31 @@ class femTerm { elementMatrix(se, localMatrix); addToMatrix(dm, localMatrix, se); } - void addToMatrix(dofManager<dataVec> &dm, - fullMatrix<dataMat> &localMatrix, + void addToMatrix(dofManager<dataVec> &dm, fullMatrix<dataMat> &localMatrix, SElement *se) const { const int nbR = localMatrix.size1(); const int nbC = localMatrix.size2(); - std::vector<Dof> R, C; // better use default consdtructors and reserve the right amount of space to avoid reallocation + std::vector<Dof> R, C; // better use default consdtructors and reserve the + // right amount of space to avoid reallocation R.reserve(nbR); C.reserve(nbC); - bool sym=true; - if (nbR == nbC) - { - for (int j = 0; j < nbR; j++) - { + bool sym = true; + if(nbR == nbC) { + for(int j = 0; j < nbR; j++) { Dof r(getLocalDofR(se, j)); Dof c(getLocalDofC(se, j)); R.push_back(r); C.push_back(c); - if (!(r == c)) sym = false; + if(!(r == c)) sym = false; } } - else - { + else { sym = false; - for (int j = 0; j < nbR; j++) - R.push_back(getLocalDofR(se, j)); - for (int k = 0; k < nbC; k++) - C.push_back(getLocalDofC(se, k)); + for(int j = 0; j < nbR; j++) R.push_back(getLocalDofR(se, j)); + for(int k = 0; k < nbC; k++) C.push_back(getLocalDofC(se, k)); } - if (!sym) + if(!sym) dm.assemble(R, C, localMatrix); else dm.assemble(R, localMatrix); @@ -114,7 +109,7 @@ class femTerm { std::vector<MVertex *> v; GModel *m = _gm; m->getMeshVerticesForPhysicalGroup(dim, physical, v); - for (unsigned int i = 0; i < v.size(); i++) + for(unsigned int i = 0; i < v.size(); i++) dm.fixVertex(v[i], comp, field, e(v[i]->x(), v[i]->y(), v[i]->z())); } @@ -128,17 +123,19 @@ class femTerm { int npts; IntPt *GP; e->getIntegrationPoints(integrationOrder, &npts, &GP); - for (int ip = 0; ip < npts; ip++){ + for(int ip = 0; ip < npts; ip++) { const double u = GP[ip].pt[0]; const double v = GP[ip].pt[1]; const double w = GP[ip].pt[2]; const double weight = GP[ip].weight; const double detJ = e->getJacobian(u, v, w, jac); - SPoint3 p; e->pnt(u, v, w, p); + SPoint3 p; + e->pnt(u, v, w, p); e->getShapeFunctions(u, v, w, sf); const dataVec FCT = fct(p.x(), p.y(), p.z()); - for (int k = 0; k < e->getNumShapeFunctions(); k++){ - dm.assemble(e->getShapeFunctionNode(k), comp, field, detJ * weight * sf[k] * FCT); + for(int k = 0; k < e->getNumShapeFunctions(); k++) { + dm.assemble(e->getShapeFunctionNode(k), comp, field, + detJ * weight * sf[k] * FCT); } } } @@ -147,14 +144,15 @@ class femTerm { const simpleFunction<dataVec> &fct, dofManager<dataVec> &dm) { - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; GModel *m = _gm; m->getPhysicalGroups(groups); - std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].find(physical); - if (it == groups[dim].end()) return; - for (unsigned int i = 0; i < it->second.size(); ++i){ + std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].find(physical); + if(it == groups[dim].end()) return; + for(unsigned int i = 0; i < it->second.size(); ++i) { GEntity *ge = it->second[i]; - for (unsigned int j = 0; j < ge->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < ge->getNumMeshElements(); j++) { MElement *e = ge->getMeshElement(j); neumannNodalBC(e, comp, field, fct, dm); } @@ -164,16 +162,17 @@ class femTerm { const simpleFunction<dataVec> &fct, dofManager<dataVec> &dm) { - std::map<int, std::vector<GEntity*> > groups[4]; + std::map<int, std::vector<GEntity *> > groups[4]; GModel *m = _gm; m->getPhysicalGroups(groups); - std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].find(physical); - if (it == groups[dim].end()) return; - for (unsigned int i = 0; i < it->second.size(); ++i){ + std::map<int, std::vector<GEntity *> >::iterator it = + groups[dim].find(physical); + if(it == groups[dim].end()) return; + for(unsigned int i = 0; i < it->second.size(); ++i) { GEntity *ge = it->second[i]; - for (unsigned int j = 0; j < ge->getNumMeshElements(); j++){ + for(unsigned int j = 0; j < ge->getNumMeshElements(); j++) { MElement *e = ge->getMeshElement(j); - + neumannNodalBC(e, 0, field, fct, dm); neumannNodalBC(e, 1, field, fct, dm); neumannNodalBC(e, 2, field, fct, dm); @@ -184,38 +183,38 @@ class femTerm { void addToRightHandSide(dofManager<dataVec> &dm, groupOfElements &C) const { groupOfElements::elementContainer::const_iterator it = C.begin(); - for ( ; it != C.end(); ++it){ + for(; it != C.end(); ++it) { MElement *eL = *it; SElement se(eL); int nbR = sizeOfR(&se); fullVector<dataVec> V(nbR); elementVector(&se, V); // assembly - for (int j = 0; j < nbR; j++) dm.assemble(getLocalDofR(&se, j), V(j)); + for(int j = 0; j < nbR; j++) dm.assemble(getLocalDofR(&se, j), V(j)); } } }; - - -class DummyfemTerm : public femTerm<double> -{ - public: +class DummyfemTerm : public femTerm<double> { +public: typedef dofTraits<double>::VecType dataVec; typedef dofTraits<double>::MatType dataMat; DummyfemTerm(GModel *gm) : femTerm<double>(gm) {} virtual ~DummyfemTerm() {} - private : // i dont want to mess with this anymore - virtual int sizeOfC(SElement *se) const {return 0;} - virtual int sizeOfR(SElement *se) const {return 0;} - virtual Dof getLocalDofR(SElement *se, int iRow) const {return Dof(0, 0);} - virtual Dof getLocalDofC(SElement *se, int iCol) const {return Dof(0, 0);} - virtual void elementMatrix(SElement *se, fullMatrix<dataMat> &m) const {m.scale(0.);} - virtual void elementVector(SElement *se, fullVector<dataVec> &m) const {m.scale(0.);} -}; - - - +private: // i dont want to mess with this anymore + virtual int sizeOfC(SElement *se) const { return 0; } + virtual int sizeOfR(SElement *se) const { return 0; } + virtual Dof getLocalDofR(SElement *se, int iRow) const { return Dof(0, 0); } + virtual Dof getLocalDofC(SElement *se, int iCol) const { return Dof(0, 0); } + virtual void elementMatrix(SElement *se, fullMatrix<dataMat> &m) const + { + m.scale(0.); + } + virtual void elementVector(SElement *se, fullVector<dataVec> &m) const + { + m.scale(0.); + } +}; #endif diff --git a/Solver/filters.cpp b/Solver/filters.cpp index 3852497f11fca3e865b6ef6505609ac314fb2a30..75aae52070465ce7cfe966cdb7db6925a7a18be4 100644 --- a/Solver/filters.cpp +++ b/Solver/filters.cpp @@ -8,5 +8,3 @@ // #include "filters.h" - - diff --git a/Solver/filters.h b/Solver/filters.h index c0a2acc0a3883d65b278e2acae34ea1ae681248e..00f72c0447285b958364807b37d9e186b5829d0b 100644 --- a/Solver/filters.h +++ b/Solver/filters.h @@ -16,84 +16,95 @@ #include "gmshLevelset.h" template <class scalar> class simpleFunction; -class FilterNodeEnriched -{ - private : - std::set<int> *_TagEnrichedVertex; - std::set<int> * _EnrichComp; +class FilterNodeEnriched { +private: + std::set<int> *_TagEnrichedVertex; + std::set<int> *_EnrichComp; - public : - FilterNodeEnriched(std::set<int> *TagEnrichedVertex, std::set<int> *EnrichComp){ - _TagEnrichedVertex = TagEnrichedVertex; - _EnrichComp = EnrichComp; - } - virtual ~FilterNodeEnriched(){} +public: + FilterNodeEnriched(std::set<int> *TagEnrichedVertex, + std::set<int> *EnrichComp) + { + _TagEnrichedVertex = TagEnrichedVertex; + _EnrichComp = EnrichComp; + } + virtual ~FilterNodeEnriched() {} - virtual bool operator() (Dof &key) const{ - std::set<int>::iterator it1; - std::set<int>::iterator it2; - int i1, i2; - Dof::getTwoIntsFromType(key.getType(), i1, i2); - it2 = _EnrichComp->find(i1); - it1 = _TagEnrichedVertex->find(key.getEntity()); - if ((it1 != _TagEnrichedVertex->end()) && (it2 != _EnrichComp->end())) - return true; - else return false; - } - //std::vector<int> * getEnrichComp(){return _EnrichComp;} + virtual bool operator()(Dof &key) const + { + std::set<int>::iterator it1; + std::set<int>::iterator it2; + int i1, i2; + Dof::getTwoIntsFromType(key.getType(), i1, i2); + it2 = _EnrichComp->find(i1); + it1 = _TagEnrichedVertex->find(key.getEntity()); + if((it1 != _TagEnrichedVertex->end()) && (it2 != _EnrichComp->end())) + return true; + else + return false; + } + // std::vector<int> * getEnrichComp(){return _EnrichComp;} -// void SetEnrichedVertex(MElement *elep, std::vector<int> & EnrichedVertex,int &nbdofs) -// { -// EnrichedVertex.clear(); -// nbdofs = 0; -// for (int i=0 ;i<elep->getNumVertices();i++) -// { -// std::set<int>::iterator it; -// it = _TagEnrichedVertex->find(elep->getVertex(i)->getNum()); -// if (it!=_TagEnrichedVertex->end()) -// { -// EnrichedVertex.push_back(i); -// nbdofs = nbdofs + 1*_EnrichComp->size(); // enriched dof -// } -// } -// } + // void SetEnrichedVertex(MElement *elep, std::vector<int> & + // EnrichedVertex,int &nbdofs) + // { + // EnrichedVertex.clear(); + // nbdofs = 0; + // for (int i=0 ;i<elep->getNumVertices();i++) + // { + // std::set<int>::iterator it; + // it = _TagEnrichedVertex->find(elep->getVertex(i)->getNum()); + // if (it!=_TagEnrichedVertex->end()) + // { + // EnrichedVertex.push_back(i); + // nbdofs = nbdofs + 1*_EnrichComp->size(); // enriched dof + // } + // } + // } }; -class FilterElementsCutByLevelSet -{ - private : +class FilterElementsCutByLevelSet { +private: std::set<int> _TagEnrichedVertex; - std::pair<int,int> _LevelSetEntity; + std::pair<int, int> _LevelSetEntity; std::set<int> *_EnrichComp; - public : - FilterElementsCutByLevelSet(std::pair<int,int> LevelSetEntity , std::set<int> * EnrichComp){ + +public: + FilterElementsCutByLevelSet(std::pair<int, int> LevelSetEntity, + std::set<int> *EnrichComp) + { _EnrichComp = EnrichComp; _LevelSetEntity = LevelSetEntity; - // groupOfElements to get all the elements associate with the level set -- (work with *current GModel) - groupOfElements *LevelSetElements = new groupOfElements (_LevelSetEntity.first, _LevelSetEntity.second); + // groupOfElements to get all the elements associate with the level set -- + // (work with *current GModel) + groupOfElements *LevelSetElements = + new groupOfElements(_LevelSetEntity.first, _LevelSetEntity.second); // tag enriched vertex determination - std::set<MElement*>::const_iterator it = LevelSetElements->begin(); - for (; it != LevelSetElements->end(); it++) { + std::set<MElement *>::const_iterator it = LevelSetElements->begin(); + for(; it != LevelSetElements->end(); it++) { MElement *e = *it; - if (e->getParent()){ // if element got parents - for (std::size_t k = 0; k < e->getParent()->getNumVertices(); ++k){ // for all vertices in the element parent + if(e->getParent()) { // if element got parents + for(std::size_t k = 0; k < e->getParent()->getNumVertices(); + ++k) { // for all vertices in the element parent _TagEnrichedVertex.insert(e->getParent()->getVertex(k)->getNum()); } } } } - virtual ~FilterElementsCutByLevelSet(){} - virtual bool operator () (Dof & key) const{ + virtual ~FilterElementsCutByLevelSet() {} + virtual bool operator()(Dof &key) const + { std::set<int>::const_iterator it1; std::set<int>::const_iterator it2; int i1, i2; Dof::getTwoIntsFromType(key.getType(), i1, i2); it2 = _EnrichComp->find(i1); it1 = _TagEnrichedVertex.find(key.getEntity()); - if ((it1!=_TagEnrichedVertex.end()) && (it2 != _EnrichComp->end())){ + if((it1 != _TagEnrichedVertex.end()) && (it2 != _EnrichComp->end())) { return true; } - else return false; + else + return false; } }; diff --git a/Solver/frameSolver.cpp b/Solver/frameSolver.cpp index 283dc3a336f8dc0de5b0461c7da35cea87e9aebd..e801df0d2c6f5156caf2dd9b576b54008393fe56 100644 --- a/Solver/frameSolver.cpp +++ b/Solver/frameSolver.cpp @@ -12,69 +12,71 @@ #include "PViewData.h" #endif -frameSolver2d::frameSolver2d (GModel *gm) - : pAssembler(0),_myModel(gm) -{ -} +frameSolver2d::frameSolver2d(GModel *gm) : pAssembler(0), _myModel(gm) {} - -void frameSolver2d::addFixations (const std::vector<int> & dirs, const std::vector<int> &modelVertices, double value) +void frameSolver2d::addFixations(const std::vector<int> &dirs, + const std::vector<int> &modelVertices, + double value) { - for (unsigned int j=0;j<modelVertices.size();j++){ + for(unsigned int j = 0; j < modelVertices.size(); j++) { GVertex *gv = _myModel->getVertexByTag(modelVertices[j]); - if (gv){ - for (unsigned int i=0;i<dirs.size();i++){ - _fixations.push_back(gmshFixation(gv,dirs[i],value)); + if(gv) { + for(unsigned int i = 0; i < dirs.size(); i++) { + _fixations.push_back(gmshFixation(gv, dirs[i], value)); } } } } -void frameSolver2d::addNodalForces (const std::vector<int> &modelVertices, const std::vector<double> & force) +void frameSolver2d::addNodalForces(const std::vector<int> &modelVertices, + const std::vector<double> &force) { - for (unsigned int j=0;j<modelVertices.size();j++){ + for(unsigned int j = 0; j < modelVertices.size(); j++) { GVertex *gv = _myModel->getVertexByTag(modelVertices[j]); - if (gv){ - _nodalForces.push_back(std::make_pair(gv,force)); + if(gv) { + _nodalForces.push_back(std::make_pair(gv, force)); } } } -void frameSolver2d::addBeamsOrBars (const std::vector<int> &modelEdges, - double E, double I, double A, int r[2]){ - int r_middle[2] = {1,1} , r_left[2] = {r[0],1} , r_right[2] = {0,r[1]}; +void frameSolver2d::addBeamsOrBars(const std::vector<int> &modelEdges, double E, + double I, double A, int r[2]) +{ + int r_middle[2] = {1, 1}, r_left[2] = {r[0], 1}, r_right[2] = {0, r[1]}; // printf("adding %d beams\n",modelEdges.size()); - for (unsigned int i=0;i<modelEdges.size();i++){ + for(unsigned int i = 0; i < modelEdges.size(); i++) { GEdge *ge = _myModel->getEdgeByTag(modelEdges[i]); - if (ge){ + if(ge) { // printf("model edge %d found\n",ge->tag()); - for (unsigned int j=0; j < ge->lines.size(); ++j){ - MLine *l = ge->lines[j]; - if (j == 0 && j == ge->lines.size()-1) _beams.push_back(gmshBeam2d ( l , E , I , A , r)); - else if (j == 0) _beams.push_back(gmshBeam2d ( l , E , I , A , r_left)); - else if (j == ge->lines.size()-1) _beams.push_back(gmshBeam2d ( l , E , I , A , r_right)); - else _beams.push_back(gmshBeam2d ( l , E , I , A , r_middle)); + for(unsigned int j = 0; j < ge->lines.size(); ++j) { + MLine *l = ge->lines[j]; + if(j == 0 && j == ge->lines.size() - 1) + _beams.push_back(gmshBeam2d(l, E, I, A, r)); + else if(j == 0) + _beams.push_back(gmshBeam2d(l, E, I, A, r_left)); + else if(j == ge->lines.size() - 1) + _beams.push_back(gmshBeam2d(l, E, I, A, r_right)); + else + _beams.push_back(gmshBeam2d(l, E, I, A, r_middle)); } } } } -void frameSolver2d::addBeams (const std::vector<int> &modelEdges, - double E, double I, double A) +void frameSolver2d::addBeams(const std::vector<int> &modelEdges, double E, + double I, double A) { - int r[2] = {1,1}; - addBeamsOrBars(modelEdges,E,I,A,r); + int r[2] = {1, 1}; + addBeamsOrBars(modelEdges, E, I, A, r); } -void frameSolver2d::addBars (const std::vector<int> &modelEdges, - double E, double I, double A) +void frameSolver2d::addBars(const std::vector<int> &modelEdges, double E, + double I, double A) { - int r[2] = {0,0}; - addBeamsOrBars(modelEdges,E,I,A,r); + int r[2] = {0, 0}; + addBeamsOrBars(modelEdges, E, I, A, r); } - - // solve any time a parameter is modified /* @@ -84,76 +86,77 @@ void frameSolver2d::addBars (const std::vector<int> &modelEdges, We define 2 dofs per node */ -void frameSolver2d::createDofs () +void frameSolver2d::createDofs() { // printf("coucou %d fixations\n",_fixations.size()); - for (unsigned int i = 0; i<_fixations.size(); ++i){ - const gmshFixation &f = _fixations[i]; - // printf("f._vertex(%d) = %p %d %g\n",i,f._vertex,f._direction,f._value); + for(unsigned int i = 0; i < _fixations.size(); ++i) { + const gmshFixation &f = _fixations[i]; + // printf("f._vertex(%d) = %p %d + // %g\n",i,f._vertex,f._direction,f._value); MVertex *v = f._vertex->mesh_vertices[0]; - Dof DOF (v->getNum(),f._direction); + Dof DOF(v->getNum(), f._direction); pAssembler->fixDof(DOF, f._value); } // printf("coucou2\n"); - computeRotationTags (); + computeRotationTags(); // printf("coucou3\n"); - for (unsigned int i=0;i<_beams.size(); i++){ - // printf("beam[%d] rot %d %d\n",i,_beams[i]._rotationTags[0],_beams[i]._rotationTags[1]); - for (unsigned int j=0;j<2;j++){ + for(unsigned int i = 0; i < _beams.size(); i++) { + // printf("beam[%d] rot %d + // %d\n",i,_beams[i]._rotationTags[0],_beams[i]._rotationTags[1]); + for(unsigned int j = 0; j < 2; j++) { MVertex *v = _beams[i]._element->getVertex(j); - Dof theta (v->getNum(), - Dof::createTypeWithTwoInts (2,_beams[i]._rotationTags[j])); + Dof theta(v->getNum(), + Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[j])); pAssembler->numberDof(theta); - Dof U (v->getNum(),0); + Dof U(v->getNum(), 0); pAssembler->numberDof(U); - Dof V (v->getNum(),1); + Dof V(v->getNum(), 1); pAssembler->numberDof(V); } } // printf("%d dofs\n",pAssembler->sizeOfR()); } -void frameSolver2d::computeStiffnessMatrix (int iBeam, - fullMatrix<double> &K) +void frameSolver2d::computeStiffnessMatrix(int iBeam, fullMatrix<double> &K) { const gmshBeam2d &b = _beams[iBeam]; - const double BS = b._E * b._I / (b._L*b._L*b._L); + const double BS = b._E * b._I / (b._L * b._L * b._L); const double TS = b._E * b._A / b._L; const MVertex *v1 = b._element->getVertex(0); const MVertex *v2 = b._element->getVertex(1); - const double alpha = atan2 (v2->y() - v1->y(), - v2->x() - v1->x()); + const double alpha = atan2(v2->y() - v1->y(), v2->x() - v1->x()); const double C = cos(alpha); const double S = sin(alpha); - printf("beam %d %g %g %g\n",iBeam,alpha,C,S); + printf("beam %d %g %g %g\n", iBeam, alpha, C, S); - fullMatrix<double> R (6,6); - R(0,0) = R(1,1) = R (3,3) = R(4,4) = C; - R(0,1) = R (3,4) = S; - R(1,0) = R (4,3) = -S; - R(2,2) = R(5,5) = 1.0; + fullMatrix<double> R(6, 6); + R(0, 0) = R(1, 1) = R(3, 3) = R(4, 4) = C; + R(0, 1) = R(3, 4) = S; + R(1, 0) = R(4, 3) = -S; + R(2, 2) = R(5, 5) = 1.0; - fullMatrix<double> k (6,6); + fullMatrix<double> k(6, 6); // tensile stiffness - k(0,0) = k (3,3) = TS; - k(0,3) = k (3,0) = -TS; + k(0, 0) = k(3, 3) = TS; + k(0, 3) = k(3, 0) = -TS; // bending stiffness - k(1,1) = k(4,4) = 12 * BS; - k(2,2) = k(5,5) = 4. * BS * b._L * b._L; - k(1,2) = k(2,1) = k(1,5) = k(5,1) = 6 * BS * b._L; - k(4,2) = k(2,4) = k(4,5) = k(5,4) = -6 * BS * b._L; - k(4,1) = k(1,4) = -12 * BS ; - k(5,2) = k(2,5) = -2 * BS * b._L * b._L; + k(1, 1) = k(4, 4) = 12 * BS; + k(2, 2) = k(5, 5) = 4. * BS * b._L * b._L; + k(1, 2) = k(2, 1) = k(1, 5) = k(5, 1) = 6 * BS * b._L; + k(4, 2) = k(2, 4) = k(4, 5) = k(5, 4) = -6 * BS * b._L; + k(4, 1) = k(1, 4) = -12 * BS; + k(5, 2) = k(2, 5) = -2 * BS * b._L * b._L; - fullMatrix<double> Rt (R), temp(6,6); + fullMatrix<double> Rt(R), temp(6, 6); Rt.transposeInPlace(); - Rt.mult(k,temp);temp.mult(R,K); + Rt.mult(k, temp); + temp.mult(R, K); } -void frameSolver2d::solve () +void frameSolver2d::solve() { #if defined(HAVE_PETSC) linearSystemPETSc<double> *lsys = new linearSystemPETSc<double>; @@ -164,124 +167,128 @@ void frameSolver2d::solve () linearSystemFull<double> *lsys = new linearSystemFull<double>; #endif - if (pAssembler)delete pAssembler; + if(pAssembler) delete pAssembler; pAssembler = new dofManager<double>(lsys); // fix dofs and create free ones createDofs(); // force vector - std::vector<std::pair<GVertex*,std::vector<double> > >::iterator it = + std::vector<std::pair<GVertex *, std::vector<double> > >::iterator it = _nodalForces.begin(); - for (; it != _nodalForces.end(); ++it){ + for(; it != _nodalForces.end(); ++it) { MVertex *v = it->first->mesh_vertices[0]; - const std::vector<double> & F = it->second; - Dof DOFX (v->getNum(),0); - Dof DOFY (v->getNum(),1); + const std::vector<double> &F = it->second; + Dof DOFX(v->getNum(), 0); + Dof DOFY(v->getNum(), 1); pAssembler->assemble(DOFX, F[0]); pAssembler->assemble(DOFY, F[1]); } // stifness matrix - for (unsigned int i=0;i<_beams.size(); i++){ - fullMatrix<double> K(6,6); - computeStiffnessMatrix (i,K); + for(unsigned int i = 0; i < _beams.size(); i++) { + fullMatrix<double> K(6, 6); + computeStiffnessMatrix(i, K); _beams[i]._stiffness = K; MVertex *v0 = _beams[i]._element->getVertex(0); MVertex *v1 = _beams[i]._element->getVertex(1); - Dof theta0 (v0->getNum(), - Dof::createTypeWithTwoInts (2,_beams[i]._rotationTags[0])); - Dof theta1 (v1->getNum(), - Dof::createTypeWithTwoInts (2,_beams[i]._rotationTags[1])); - Dof U0 (v0->getNum(),0); - Dof U1 (v1->getNum(),0); - Dof V0 (v0->getNum(),1); - Dof V1 (v1->getNum(),1); - Dof DOFS[6] = {U0,V0,theta0,U1,V1,theta1}; - for (int j=0;j<6;j++){ - for (int k=0;k<6;k++){ - pAssembler->assemble(DOFS[j],DOFS[k],K(j,k)); + Dof theta0(v0->getNum(), + Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[0])); + Dof theta1(v1->getNum(), + Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[1])); + Dof U0(v0->getNum(), 0); + Dof U1(v1->getNum(), 0); + Dof V0(v0->getNum(), 1); + Dof V1(v1->getNum(), 1); + Dof DOFS[6] = {U0, V0, theta0, U1, V1, theta1}; + for(int j = 0; j < 6; j++) { + for(int k = 0; k < 6; k++) { + pAssembler->assemble(DOFS[j], DOFS[k], K(j, k)); } } } lsys->systemSolve(); // save the solution - for (unsigned int i=0;i<_beams.size(); i++){ + for(unsigned int i = 0; i < _beams.size(); i++) { MVertex *v0 = _beams[i]._element->getVertex(0); MVertex *v1 = _beams[i]._element->getVertex(1); - Dof theta0 (v0->getNum(), - Dof::createTypeWithTwoInts (2,_beams[i]._rotationTags[0])); - Dof theta1 (v1->getNum(), - Dof::createTypeWithTwoInts (2,_beams[i]._rotationTags[1])); - Dof U0 (v0->getNum(),0); - Dof U1 (v1->getNum(),0); - Dof V0 (v0->getNum(),1); - Dof V1 (v1->getNum(),1); - Dof DOFS[6] = {U0,V0,theta0,U1,V1,theta1}; - for (int j=0;j<6;j++){ - pAssembler->getDofValue(DOFS[j], _beams[i]._displacement[j]); + Dof theta0(v0->getNum(), + Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[0])); + Dof theta1(v1->getNum(), + Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[1])); + Dof U0(v0->getNum(), 0); + Dof U1(v1->getNum(), 0); + Dof V0(v0->getNum(), 1); + Dof V1(v1->getNum(), 1); + Dof DOFS[6] = {U0, V0, theta0, U1, V1, theta1}; + for(int j = 0; j < 6; j++) { + pAssembler->getDofValue(DOFS[j], _beams[i]._displacement[j]); } } delete lsys; delete pAssembler; } -void frameSolver2d::exportFrameData(const char * DISPL, const char * M) { +void frameSolver2d::exportFrameData(const char *DISPL, const char *M) +{ #if defined(HAVE_POST) { std::map<int, std::vector<double> > data; - for (unsigned int i=0;i<_beams.size(); i++){ + for(unsigned int i = 0; i < _beams.size(); i++) { std::vector<double> tmp; // tmp.push_back(_beams[i]._E); // tmp.push_back(_beams[i]._I); // tmp.push_back(_beams[i]._A); tmp.reserve(6); - for(int j = 0; j < 6; j++) { tmp.push_back(_beams[i]._displacement[j]); } + for(int j = 0; j < 6; j++) { + tmp.push_back(_beams[i]._displacement[j]); + } data[_beams[i]._element->getNum()] = tmp; } - PView *pv = new PView ("displacements", "Beam", _myModel, data, 0.0, 6); + PView *pv = new PView("displacements", "Beam", _myModel, data, 0.0, 6); pv->getData()->writeMSH(DISPL); delete pv; } { std::map<int, std::vector<double> > data; - for (unsigned int i=0;i<_beams.size(); i++){ + for(unsigned int i = 0; i < _beams.size(); i++) { std::vector<double> tmp; - fullVector<double> d (_beams[i]._displacement,6), F(6); - _beams[i]._stiffness.mult(d,F); + fullVector<double> d(_beams[i]._displacement, 6), F(6); + _beams[i]._stiffness.mult(d, F); tmp.push_back(-F(2)); tmp.push_back(F(5)); data[_beams[i]._element->getNum()] = tmp; } - PView *pv = new PView ("Momentum", "ElementNodeData", _myModel, data, 0.0, 1); + PView *pv = + new PView("Momentum", "ElementNodeData", _myModel, data, 0.0, 1); pv->getData()->writeMSH(M); delete pv; } #endif } -void frameSolver2d::computeRotationTags () +void frameSolver2d::computeRotationTags() { - std::multimap<MVertex*,gmshBeam2d*> v2b; - for (unsigned int i=0;i<_beams.size(); i++){ - v2b.insert(std::make_pair(_beams[i]._element->getVertex(0),&_beams[i])); - v2b.insert(std::make_pair(_beams[i]._element->getVertex(1),&_beams[i])); + std::multimap<MVertex *, gmshBeam2d *> v2b; + for(unsigned int i = 0; i < _beams.size(); i++) { + v2b.insert(std::make_pair(_beams[i]._element->getVertex(0), &_beams[i])); + v2b.insert(std::make_pair(_beams[i]._element->getVertex(1), &_beams[i])); } - std::multimap<MVertex*,gmshBeam2d*>::iterator s_it; - for (std::multimap<MVertex*,gmshBeam2d*>::iterator it = v2b.begin(); - it != v2b.end(); it = s_it){ + std::multimap<MVertex *, gmshBeam2d *>::iterator s_it; + for(std::multimap<MVertex *, gmshBeam2d *>::iterator it = v2b.begin(); + it != v2b.end(); it = s_it) { MVertex *theKey = it->first; - std::pair<std::multimap<MVertex*,gmshBeam2d*>::iterator, - std::multimap<MVertex*,gmshBeam2d*>::iterator> + std::pair<std::multimap<MVertex *, gmshBeam2d *>::iterator, + std::multimap<MVertex *, gmshBeam2d *>::iterator> keyRange = v2b.equal_range(theKey); int countRotules = 0; - for (s_it = keyRange.first; s_it != keyRange.second; ++s_it){ + for(s_it = keyRange.first; s_it != keyRange.second; ++s_it) { gmshBeam2d *b = s_it->second; - if (!b->isRigid(theKey)){ - b->setRotationTag(theKey,++countRotules); + if(!b->isRigid(theKey)) { + b->setRotationTag(theKey, ++countRotules); } } } diff --git a/Solver/frameSolver.h b/Solver/frameSolver.h index 07c6cd9d65647fd6c8eb39b54d4c26ad488a99a4..defea029eed45e1d6b8c4e5c3f0a12d93a1d03f4 100644 --- a/Solver/frameSolver.h +++ b/Solver/frameSolver.h @@ -15,61 +15,69 @@ class GVertex; #include "fullMatrix.h" #include "MLine.h" -struct gmshBeam2d -{ +struct gmshBeam2d { MLine *_element; - double _I, _A , _E, _L; - bool _rigidNodes [2]; + double _I, _A, _E, _L; + bool _rigidNodes[2]; double _forceVector[6]; double _displacement[6]; - int _rotationTags [2]; + int _rotationTags[2]; fullMatrix<double> _stiffness; - gmshBeam2d (MLine *l, double E , double I, double A, int r[2]) - : _element(l), _I(I), _A(A), _E(E){ - _L = distance(_element->getVertex(0),_element->getVertex(1)); + gmshBeam2d(MLine *l, double E, double I, double A, int r[2]) + : _element(l), _I(I), _A(A), _E(E) + { + _L = distance(_element->getVertex(0), _element->getVertex(1)); _rotationTags[0] = _rotationTags[1] = 0; - _rigidNodes[0] = r[0]; _rigidNodes[1] = r[1]; - for (int i = 0; i < 6; i++) _displacement[i] = 0.; - } - inline bool isRigid(MVertex*v)const{ + _rigidNodes[0] = r[0]; + _rigidNodes[1] = r[1]; + for(int i = 0; i < 6; i++) _displacement[i] = 0.; + } + inline bool isRigid(MVertex *v) const + { return _element->getVertex(0) == v ? _rigidNodes[0] : _rigidNodes[1]; } - inline void setRotationTag(MVertex * v, int tag){ - _element->getVertex(0) == v ? _rotationTags[0] = tag : _rotationTags[1] = tag; + inline void setRotationTag(MVertex *v, int tag) + { + _element->getVertex(0) == v ? _rotationTags[0] = tag : + _rotationTags[1] = tag; } }; -struct gmshFixation -{ +struct gmshFixation { GVertex *_vertex; int _direction; double _value; - gmshFixation (GVertex *v, int d, double val) : _vertex(v), _direction(d), _value(val) {} + gmshFixation(GVertex *v, int d, double val) + : _vertex(v), _direction(d), _value(val) + { + } }; // a solver that computes equilibriums of frames... -class frameSolver2d -{ - dofManager<double> *pAssembler; +class frameSolver2d { + dofManager<double> *pAssembler; std::vector<gmshBeam2d> _beams; - std::vector<std::pair<GVertex*,std::vector<double> > > _nodalForces; + std::vector<std::pair<GVertex *, std::vector<double> > > _nodalForces; std::vector<gmshFixation> _fixations; GModel *_myModel; - void computeStiffnessMatrix (int iBeam, fullMatrix<double> &K); - void createDofs () ; - void computeRotationTags () ; - void addBeamsOrBars (const std::vector<int> &modelEdges, - double E, double I, double A, int r[2]); - public: - frameSolver2d(GModel* myModel); - void addBeams(const std::vector<int> &modelEdges, - double E, double I, double A); - void addBars(const std::vector<int> &modelEdges, - double E, double I, double A); - void addNodalForces(const std::vector<int> &modelVertices, const std::vector<double> & force); - void addFixations(const std::vector<int> & dirs, const std::vector<int> &modelVertices, double value); - void exportFrameData(const char * displ, const char* M); - void solve () ; + void computeStiffnessMatrix(int iBeam, fullMatrix<double> &K); + void createDofs(); + void computeRotationTags(); + void addBeamsOrBars(const std::vector<int> &modelEdges, double E, double I, + double A, int r[2]); + +public: + frameSolver2d(GModel *myModel); + void addBeams(const std::vector<int> &modelEdges, double E, double I, + double A); + void addBars(const std::vector<int> &modelEdges, double E, double I, + double A); + void addNodalForces(const std::vector<int> &modelVertices, + const std::vector<double> &force); + void addFixations(const std::vector<int> &dirs, + const std::vector<int> &modelVertices, double value); + void exportFrameData(const char *displ, const char *M); + void solve(); }; #endif diff --git a/Solver/functionSpace.cpp b/Solver/functionSpace.cpp index 7494fcde1d8aaa9ec3e3de765b9b56dd0285be5a..cfc618983103b6b09f00c2650ee5be7e3089235d 100644 --- a/Solver/functionSpace.cpp +++ b/Solver/functionSpace.cpp @@ -9,7 +9,7 @@ #include "functionSpace.h" -const SVector3 VectorLagrangeFunctionSpaceOfElement::BasisVectors[3] = - {SVector3(1, 0, 0), SVector3(0, 1, 0), SVector3(0, 0, 1)}; -const SVector3 VectorLagrangeFunctionSpace::BasisVectors[3] = - {SVector3(1, 0, 0), SVector3(0, 1, 0), SVector3(0, 0, 1)}; +const SVector3 VectorLagrangeFunctionSpaceOfElement::BasisVectors[3] = { + SVector3(1, 0, 0), SVector3(0, 1, 0), SVector3(0, 0, 1)}; +const SVector3 VectorLagrangeFunctionSpace::BasisVectors[3] = { + SVector3(1, 0, 0), SVector3(0, 1, 0), SVector3(0, 0, 1)}; diff --git a/Solver/functionSpace.h b/Solver/functionSpace.h index b0d3ed95e003c3900b7e15154af15c028838c9fb..12f11ae19d042413a7d31e8f19edd3dad60a6436 100644 --- a/Solver/functionSpace.h +++ b/Solver/functionSpace.h @@ -18,108 +18,127 @@ #include "dofManager.h" #include "simpleFunction.h" -//class SVoid{}; -template<class T> struct TensorialTraits -{ +// class SVoid{}; +template <class T> struct TensorialTraits { typedef T ValType; typedef T GradType[3]; typedef T HessType[3][3]; typedef T ThirdDevType[3][3][3]; -/* typedef SVoid DivType; - typedef SVoid CurlType;*/ + /* typedef SVoid DivType; + typedef SVoid CurlType;*/ }; -template<> struct TensorialTraits<double> -{ +template <> struct TensorialTraits<double> { typedef double ValType; typedef SVector3 GradType; typedef STensor3 HessType; typedef double TensProdType; typedef STensor33 ThirdDevType; -/* typedef SVoid DivType; - typedef SVoid CurlType;*/ + /* typedef SVoid DivType; + typedef SVoid CurlType;*/ }; -template<> struct TensorialTraits<SVector3> -{ +template <> struct TensorialTraits<SVector3> { typedef SVector3 ValType; typedef STensor3 GradType; typedef STensor3 HessType; typedef STensor3 TensProdType; typedef STensor3 ThirdDevType; -// typedef double DivType; -// typedef SVector3 CurlType; + // typedef double DivType; + // typedef SVector3 CurlType; }; -template<> struct TensorialTraits<STensor3> -{ +template <> struct TensorialTraits<STensor3> { typedef STensor3 ValType; -// typedef STensor3 GradType; -// typedef STensor3 HessType; -// typedef STensor3 TensProdType; + // typedef STensor3 GradType; + // typedef STensor3 HessType; + // typedef STensor3 TensProdType; typedef STensor43 TensProdType; -// typedef double DivType; -// typedef SVector3 CurlType; + // typedef double DivType; + // typedef SVector3 CurlType; }; - -class FunctionSpaceBase -{ - public: - virtual ~FunctionSpaceBase(){} - virtual int getId(void) const =0; - virtual int getNumKeys(MElement *ele) const = 0; // if one needs the number of dofs +class FunctionSpaceBase { +public: + virtual ~FunctionSpaceBase() {} + virtual int getId(void) const = 0; + virtual int + getNumKeys(MElement *ele) const = 0; // if one needs the number of dofs virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const = 0; - virtual void getKeysOnVertex(MElement* ele, MVertex* v, const std::vector<int>& comp, std::vector<Dof>& keys) const{ - Msg::Warning("this function is defined to get Dofs of vertex %d on element %d",v->getNum(),ele->getNum()); + virtual void getKeysOnVertex(MElement *ele, MVertex *v, + const std::vector<int> &comp, + std::vector<Dof> &keys) const + { + Msg::Warning( + "this function is defined to get Dofs of vertex %d on element %d", + v->getNum(), ele->getNum()); } - virtual FunctionSpaceBase* clone(const int id) const {return NULL;}; // copy space with new Id + virtual FunctionSpaceBase *clone(const int id) const + { + return NULL; + }; // copy space with new Id }; -template<class T> -class FunctionSpace : public FunctionSpaceBase -{ - protected: +template <class T> class FunctionSpace : public FunctionSpaceBase { +protected: int _iField; // field number (used to build dof keys) - public: +public: typedef typename TensorialTraits<T>::ValType ValType; typedef typename TensorialTraits<T>::GradType GradType; typedef typename TensorialTraits<T>::HessType HessType; typedef typename TensorialTraits<T>::ThirdDevType ThirdDevType; - virtual int getId(void) const {return _iField;} - virtual void f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const = 0; - virtual void fuvw(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const {} // should return to pure virtual once all is done. - virtual void gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const = 0; - virtual void gradfuvw(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const {} // should return to pure virtual once all is done. - virtual void hessfuvw(MElement *ele, double u, double v, double w, std::vector<HessType> &hess) const = 0; - virtual void hessf(MElement *ele, double u, double v, double w,std::vector<HessType> &hess) const {} //need to high order fem - virtual void thirdDevfuvw(MElement *ele, double u, double v, double w,std::vector<ThirdDevType> &third) const {}; //need to high order fem - virtual void thirdDevf(MElement *ele, double u, double v, double w,std::vector<ThirdDevType> &third) const {}; //need to high order fem - - virtual int getNumKeys(MElement *ele) const = 0; // if one needs the number of dofs + virtual int getId(void) const { return _iField; } + virtual void f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const = 0; + virtual void fuvw(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const + { + } // should return to pure virtual once all is done. + virtual void gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const = 0; + virtual void gradfuvw(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const + { + } // should return to pure virtual once all is done. + virtual void hessfuvw(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const = 0; + virtual void hessf(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const + { + } // need to high order fem + virtual void thirdDevfuvw( + MElement *ele, double u, double v, double w, + std::vector<ThirdDevType> &third) const {}; // need to high order fem + virtual void thirdDevf( + MElement *ele, double u, double v, double w, + std::vector<ThirdDevType> &third) const {}; // need to high order fem + + virtual int + getNumKeys(MElement *ele) const = 0; // if one needs the number of dofs virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const = 0; }; -class ScalarLagrangeFunctionSpaceOfElement : public FunctionSpace<double> -{ - public: +class ScalarLagrangeFunctionSpaceOfElement : public FunctionSpace<double> { +public: typedef TensorialTraits<double>::ValType ValType; typedef TensorialTraits<double>::GradType GradType; typedef TensorialTraits<double>::HessType HessType; - private: +private: virtual void getKeys(MVertex *ver, std::vector<Dof> &keys) const { keys.push_back(Dof(ver->getNum(), _iField)); } - public: +public: ScalarLagrangeFunctionSpaceOfElement(int i = 0) { _iField = i; } - virtual void f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const + virtual void f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const { if(ele->getParent()) { - if(ele->getTypeForMSH() == MSH_LIN_B || ele->getTypeForMSH() == MSH_TRI_B || - ele->getTypeForMSH() == MSH_POLYG_B) { //FIXME MPolygonBorders... + if(ele->getTypeForMSH() == MSH_LIN_B || + ele->getTypeForMSH() == MSH_TRI_B || + ele->getTypeForMSH() == MSH_POLYG_B) { // FIXME MPolygonBorders... ele->movePointFromParentSpaceToElementSpace(u, v, w); } } @@ -129,11 +148,13 @@ class ScalarLagrangeFunctionSpaceOfElement : public FunctionSpace<double> ele->getShapeFunctions(u, v, w, &(vals[curpos])); } // Fonction renvoyant un vecteur contenant le grandient de chaque FF - virtual void gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const + virtual void gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { if(ele->getParent()) { - if(ele->getTypeForMSH() == MSH_LIN_B || ele->getTypeForMSH() == MSH_TRI_B || - ele->getTypeForMSH() == MSH_POLYG_B) { //FIXME MPolygonBorders... + if(ele->getTypeForMSH() == MSH_LIN_B || + ele->getTypeForMSH() == MSH_TRI_B || + ele->getTypeForMSH() == MSH_POLYG_B) { // FIXME MPolygonBorders... ele->movePointFromParentSpaceToElementSpace(u, v, w); } } @@ -143,40 +164,56 @@ class ScalarLagrangeFunctionSpaceOfElement : public FunctionSpace<double> ele->getGradShapeFunctions(u, v, w, gradsuvw); double jac[3][3]; double invjac[3][3]; - ele->getJacobian(u, v, w, jac); // redondant : on fait cet appel a l'exterieur + ele->getJacobian(u, v, w, + jac); // redondant : on fait cet appel a l'exterieur inv3x3(jac, invjac); for(int i = 0; i < ndofs; ++i) - grads.push_back(GradType( - invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2], - invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + invjac[1][2] * gradsuvw[i][2], - invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * gradsuvw[i][2])); - } - // Fonction renvoyant un vecteur contenant le hessien [][] de chaque FF dans l'espace ISOPARAMETRIQUE - virtual void hessfuvw(MElement *ele, double u, double v, double w, std::vector<HessType> &hess) const + grads.push_back( + GradType(invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + + invjac[0][2] * gradsuvw[i][2], + invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + + invjac[1][2] * gradsuvw[i][2], + invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + + invjac[2][2] * gradsuvw[i][2])); + } + // Fonction renvoyant un vecteur contenant le hessien [][] de chaque FF dans + // l'espace ISOPARAMETRIQUE + virtual void hessfuvw(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const { if(ele->getParent()) { - if(ele->getTypeForMSH() == MSH_LIN_B || ele->getTypeForMSH() == MSH_TRI_B || - ele->getTypeForMSH() == MSH_POLYG_B) { //FIXME MPolygonBorders... + if(ele->getTypeForMSH() == MSH_LIN_B || + ele->getTypeForMSH() == MSH_TRI_B || + ele->getTypeForMSH() == MSH_POLYG_B) { // FIXME MPolygonBorders... ele->movePointFromParentSpaceToElementSpace(u, v, w); } } int ndofs = ele->getNumShapeFunctions(); - hess.reserve(hess.size() + ndofs); // permet de mettre les composantes suivantes à la suite du vecteur + hess.reserve(hess.size() + ndofs); // permet de mettre les composantes + // suivantes à la suite du vecteur double hessuvw[256][3][3]; ele->getHessShapeFunctions(u, v, w, hessuvw); HessType hesst; - for(int i = 0; i < ndofs; ++i){ - hesst(0,0) = hessuvw[i][0][0]; hesst(0,1) = hessuvw[i][0][1]; hesst(0,2) = hessuvw[i][0][2]; - hesst(1,0) = hessuvw[i][1][0]; hesst(1,1) = hessuvw[i][1][1]; hesst(1,2) = hessuvw[i][1][2]; - hesst(2,0) = hessuvw[i][2][0]; hesst(2,1) = hessuvw[i][2][1]; hesst(2,2) = hessuvw[i][2][2]; + for(int i = 0; i < ndofs; ++i) { + hesst(0, 0) = hessuvw[i][0][0]; + hesst(0, 1) = hessuvw[i][0][1]; + hesst(0, 2) = hessuvw[i][0][2]; + hesst(1, 0) = hessuvw[i][1][0]; + hesst(1, 1) = hessuvw[i][1][1]; + hesst(1, 2) = hessuvw[i][1][2]; + hesst(2, 0) = hessuvw[i][2][0]; + hesst(2, 1) = hessuvw[i][2][1]; + hesst(2, 2) = hessuvw[i][2][2]; hess.push_back(hesst); } } - virtual void gradfuvw(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const + virtual void gradfuvw(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { if(ele->getParent()) { - if(ele->getTypeForMSH() == MSH_LIN_B || ele->getTypeForMSH() == MSH_TRI_B || - ele->getTypeForMSH() == MSH_POLYG_B) { //FIXME MPolygonBorders... + if(ele->getTypeForMSH() == MSH_LIN_B || + ele->getTypeForMSH() == MSH_TRI_B || + ele->getTypeForMSH() == MSH_POLYG_B) { // FIXME MPolygonBorders... ele->movePointFromParentSpaceToElementSpace(u, v, w); } } @@ -191,30 +228,31 @@ class ScalarLagrangeFunctionSpaceOfElement : public FunctionSpace<double> { return ele->getNumShapeFunctions(); } - virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const // appends ... + virtual void getKeys(MElement *ele, + std::vector<Dof> &keys) const // appends ... { int ndofs = ele->getNumShapeFunctions(); keys.reserve(keys.size() + ndofs); - for(int i = 0; i < ndofs; ++i) - getKeys(ele->getShapeFunctionNode(i), keys); + for(int i = 0; i < ndofs; ++i) getKeys(ele->getShapeFunctionNode(i), keys); } }; -class ScalarLagrangeFunctionSpace : public FunctionSpace<double> -{ - public: +class ScalarLagrangeFunctionSpace : public FunctionSpace<double> { +public: typedef TensorialTraits<double>::ValType ValType; typedef TensorialTraits<double>::GradType GradType; typedef TensorialTraits<double>::HessType HessType; - private: +private: virtual void getKeys(MVertex *ver, std::vector<Dof> &keys) const { keys.push_back(Dof(ver->getNum(), _iField)); } - public: + +public: ScalarLagrangeFunctionSpace(int i = 0) { _iField = i; } - virtual void f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const + virtual void f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const { if(ele->getParent()) ele = ele->getParent(); int ndofs = ele->getNumShapeFunctions(); @@ -223,7 +261,8 @@ class ScalarLagrangeFunctionSpace : public FunctionSpace<double> ele->getShapeFunctions(u, v, w, &(vals[curpos])); } // Fonction renvoyant un vecteur contenant le grandient de chaque FF - virtual void gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const + virtual void gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { if(ele->getParent()) ele = ele->getParent(); int ndofs = ele->getNumShapeFunctions(); @@ -232,31 +271,45 @@ class ScalarLagrangeFunctionSpace : public FunctionSpace<double> ele->getGradShapeFunctions(u, v, w, gradsuvw); double jac[3][3]; double invjac[3][3]; - ele->getJacobian(u, v, w, jac); // redondant : on fait cet appel a l'exterieur + ele->getJacobian(u, v, w, + jac); // redondant : on fait cet appel a l'exterieur inv3x3(jac, invjac); for(int i = 0; i < ndofs; ++i) - grads.push_back(GradType( - invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + invjac[0][2] * gradsuvw[i][2], - invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + invjac[1][2] * gradsuvw[i][2], - invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + invjac[2][2] * gradsuvw[i][2])); - } - // Fonction renvoyant un vecteur contenant le hessien [][] de chaque FF dans l'espace ISOPARAMETRIQUE - virtual void hessfuvw(MElement *ele, double u, double v, double w, std::vector<HessType> &hess) const + grads.push_back( + GradType(invjac[0][0] * gradsuvw[i][0] + invjac[0][1] * gradsuvw[i][1] + + invjac[0][2] * gradsuvw[i][2], + invjac[1][0] * gradsuvw[i][0] + invjac[1][1] * gradsuvw[i][1] + + invjac[1][2] * gradsuvw[i][2], + invjac[2][0] * gradsuvw[i][0] + invjac[2][1] * gradsuvw[i][1] + + invjac[2][2] * gradsuvw[i][2])); + } + // Fonction renvoyant un vecteur contenant le hessien [][] de chaque FF dans + // l'espace ISOPARAMETRIQUE + virtual void hessfuvw(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const { if(ele->getParent()) ele = ele->getParent(); int ndofs = ele->getNumShapeFunctions(); - hess.reserve(hess.size() + ndofs); // permet de mettre les composantes suivantes à la suite du vecteur + hess.reserve(hess.size() + ndofs); // permet de mettre les composantes + // suivantes à la suite du vecteur double hessuvw[256][3][3]; ele->getHessShapeFunctions(u, v, w, hessuvw); HessType hesst; - for(int i = 0; i < ndofs; ++i){ - hesst(0,0) = hessuvw[i][0][0]; hesst(0,1) = hessuvw[i][0][1]; hesst(0,2) = hessuvw[i][0][2]; - hesst(1,0) = hessuvw[i][1][0]; hesst(1,1) = hessuvw[i][1][1]; hesst(1,2) = hessuvw[i][1][2]; - hesst(2,0) = hessuvw[i][2][0]; hesst(2,1) = hessuvw[i][2][1]; hesst(2,2) = hessuvw[i][2][2]; + for(int i = 0; i < ndofs; ++i) { + hesst(0, 0) = hessuvw[i][0][0]; + hesst(0, 1) = hessuvw[i][0][1]; + hesst(0, 2) = hessuvw[i][0][2]; + hesst(1, 0) = hessuvw[i][1][0]; + hesst(1, 1) = hessuvw[i][1][1]; + hesst(1, 2) = hessuvw[i][1][2]; + hesst(2, 0) = hessuvw[i][2][0]; + hesst(2, 1) = hessuvw[i][2][1]; + hesst(2, 2) = hessuvw[i][2][2]; hess.push_back(hesst); } } - virtual void gradfuvw(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const + virtual void gradfuvw(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { if(ele->getParent()) ele = ele->getParent(); int ndofs = ele->getNumShapeFunctions(); @@ -266,64 +319,80 @@ class ScalarLagrangeFunctionSpace : public FunctionSpace<double> for(int i = 0; i < ndofs; ++i) grads.push_back(GradType(gradsuvw[i][0], gradsuvw[i][1], gradsuvw[i][2])); } - virtual void fuvw(MElement *ele, double u, double v, double w,std::vector<ValType> &vals) const + virtual void fuvw(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const { if(ele->getParent()) ele = ele->getParent(); - int ndofs= ele->getNumShapeFunctions(); - vals.reserve(vals.size()+ndofs); + int ndofs = ele->getNumShapeFunctions(); + vals.reserve(vals.size() + ndofs); double valsuvw[1256]; ele->getShapeFunctions(u, v, w, valsuvw); - for(int i = 0; i < ndofs; ++i) - vals.push_back(valsuvw[i]); + for(int i = 0; i < ndofs; ++i) vals.push_back(valsuvw[i]); } virtual int getNumKeys(MElement *ele) const { if(ele->getParent()) ele = ele->getParent(); return ele->getNumShapeFunctions(); } - virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const // appends ... + virtual void getKeys(MElement *ele, + std::vector<Dof> &keys) const // appends ... { if(ele->getParent()) ele = ele->getParent(); int ndofs = ele->getNumShapeFunctions(); keys.reserve(keys.size() + ndofs); - for(int i = 0; i < ndofs; ++i) - getKeys(ele->getShapeFunctionNode(i), keys); + for(int i = 0; i < ndofs; ++i) getKeys(ele->getShapeFunctionNode(i), keys); } }; -template <class T> class ScalarToAnyFunctionSpace : public FunctionSpace<T> -{ -public : +template <class T> class ScalarToAnyFunctionSpace : public FunctionSpace<T> { +public: typedef typename TensorialTraits<T>::ValType ValType; typedef typename TensorialTraits<T>::GradType GradType; typedef typename TensorialTraits<T>::HessType HessType; -protected : + +protected: std::vector<T> multipliers; std::vector<int> comp; FunctionSpace<double> *ScalarFS; -public : - template <class T2> ScalarToAnyFunctionSpace(const T2 &SFS, const T& mult, int comp_): ScalarFS(new T2(SFS)) + +public: + template <class T2> + ScalarToAnyFunctionSpace(const T2 &SFS, const T &mult, int comp_) + : ScalarFS(new T2(SFS)) { - multipliers.push_back(mult); comp.push_back(comp_); + multipliers.push_back(mult); + comp.push_back(comp_); } - template <class T2> ScalarToAnyFunctionSpace(const T2 &SFS, const T& mult1, int comp1_, - const T& mult2, int comp2_): ScalarFS(new T2(SFS)) + template <class T2> + ScalarToAnyFunctionSpace(const T2 &SFS, const T &mult1, int comp1_, + const T &mult2, int comp2_) + : ScalarFS(new T2(SFS)) { - multipliers.push_back(mult1); multipliers.push_back(mult2); - comp.push_back(comp1_); comp.push_back(comp2_); + multipliers.push_back(mult1); + multipliers.push_back(mult2); + comp.push_back(comp1_); + comp.push_back(comp2_); } - template <class T2> ScalarToAnyFunctionSpace(const T2 &SFS, const T& mult1, int comp1_, - const T& mult2, int comp2_, const T& mult3, int comp3_): ScalarFS(new T2(SFS)) + template <class T2> + ScalarToAnyFunctionSpace(const T2 &SFS, const T &mult1, int comp1_, + const T &mult2, int comp2_, const T &mult3, + int comp3_) + : ScalarFS(new T2(SFS)) { - multipliers.push_back(mult1); multipliers.push_back(mult2); multipliers.push_back(mult3); - comp.push_back(comp1_); comp.push_back(comp2_); comp.push_back(comp3_); + multipliers.push_back(mult1); + multipliers.push_back(mult2); + multipliers.push_back(mult3); + comp.push_back(comp1_); + comp.push_back(comp2_); + comp.push_back(comp3_); } - virtual ~ScalarToAnyFunctionSpace() {delete ScalarFS;} + virtual ~ScalarToAnyFunctionSpace() { delete ScalarFS; } - virtual void f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const + virtual void f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const { std::vector<double> valsd; ScalarFS->f(ele, u, v, w, valsd); @@ -331,13 +400,13 @@ public : int nbcomp = comp.size(); int curpos = vals.size(); vals.reserve(curpos + nbcomp * nbdofs); - for(int j = 0; j < nbcomp; ++j){ - for(int i = 0; i < nbdofs; ++i) - vals.push_back(multipliers[j] * valsd[i]); + for(int j = 0; j < nbcomp; ++j) { + for(int i = 0; i < nbdofs; ++i) vals.push_back(multipliers[j] * valsd[i]); } } - virtual void gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const + virtual void gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { std::vector<SVector3> gradsd; ScalarFS->gradf(ele, u, v, w, gradsd); @@ -346,18 +415,20 @@ public : int curpos = grads.size(); grads.reserve(curpos + nbcomp * nbdofs); GradType val; - for(int j = 0; j < nbcomp; ++j){ - for(int i = 0; i < nbdofs; ++i){ + for(int j = 0; j < nbcomp; ++j) { + for(int i = 0; i < nbdofs; ++i) { tensprod(multipliers[j], gradsd[i], val); grads.push_back(val); } } } - virtual void hessfuvw(MElement *ele, double u, double v, double w, std::vector<HessType> &hess) const + virtual void hessfuvw(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const { ScalarFS->hessfuvw(ele, u, v, w, hess); } - virtual void gradfuvw(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const + virtual void gradfuvw(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { std::vector<SVector3> gradsd; ScalarFS->gradfuvw(ele, u, v, w, gradsd); @@ -366,15 +437,18 @@ public : int curpos = grads.size(); grads.reserve(curpos + nbcomp * nbdofs); GradType val; - for(int j = 0; j < nbcomp; ++j){ - for(int i = 0; i < nbdofs; ++i){ + for(int j = 0; j < nbcomp; ++j) { + for(int i = 0; i < nbdofs; ++i) { tensprod(multipliers[j], gradsd[i], val); grads.push_back(val); } } } - virtual int getNumKeys(MElement *ele) const {return ScalarFS->getNumKeys(ele) * comp.size();} + virtual int getNumKeys(MElement *ele) const + { + return ScalarFS->getNumKeys(ele) * comp.size(); + } virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const { @@ -386,242 +460,291 @@ public : int nbcomp = comp.size(); int curpos = keys.size(); keys.reserve(curpos + nbcomp * nbdofs); - for(int j = 0; j < nbcomp; ++j){ - for(int i = 0; i < nk; ++i){ + for(int j = 0; j < nbcomp; ++j) { + for(int i = 0; i < nk; ++i) { int i1, i2; Dof::getTwoIntsFromType(bufk[i].getType(), i1, i2); - keys.push_back(Dof(bufk[i].getEntity(), Dof::createTypeWithTwoInts(comp[j], i1))); + keys.push_back( + Dof(bufk[i].getEntity(), Dof::createTypeWithTwoInts(comp[j], i1))); } } } }; -class VectorLagrangeFunctionSpaceOfElement : public ScalarToAnyFunctionSpace<SVector3> -{ - protected: +class VectorLagrangeFunctionSpaceOfElement + : public ScalarToAnyFunctionSpace<SVector3> { +protected: static const SVector3 BasisVectors[3]; - public: + +public: enum Along { VECTOR_X = 0, VECTOR_Y = 1, VECTOR_Z = 2 }; typedef TensorialTraits<SVector3>::ValType ValType; typedef TensorialTraits<SVector3>::GradType GradType; - VectorLagrangeFunctionSpaceOfElement(int id) : - ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace(ScalarLagrangeFunctionSpaceOfElement(id), - SVector3(1.,0.,0.), VECTOR_X, SVector3(0.,1.,0.), VECTOR_Y, SVector3(0.,0.,1.), VECTOR_Z) - {} - VectorLagrangeFunctionSpaceOfElement(int id, Along comp1) : - ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace(ScalarLagrangeFunctionSpaceOfElement(id), - BasisVectors[comp1], comp1) - {} - VectorLagrangeFunctionSpaceOfElement(int id, Along comp1, Along comp2) : - ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace(ScalarLagrangeFunctionSpaceOfElement(id), - BasisVectors[comp1], comp1, BasisVectors[comp2], comp2) - {} - VectorLagrangeFunctionSpaceOfElement(int id, Along comp1, Along comp2, Along comp3) : - ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace(ScalarLagrangeFunctionSpaceOfElement(id), - BasisVectors[comp1], comp1, BasisVectors[comp2], comp2, BasisVectors[comp3], comp3) - {} + VectorLagrangeFunctionSpaceOfElement(int id) + : ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace( + ScalarLagrangeFunctionSpaceOfElement(id), SVector3(1., 0., 0.), + VECTOR_X, SVector3(0., 1., 0.), VECTOR_Y, SVector3(0., 0., 1.), + VECTOR_Z) + { + } + VectorLagrangeFunctionSpaceOfElement(int id, Along comp1) + : ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace( + ScalarLagrangeFunctionSpaceOfElement(id), BasisVectors[comp1], comp1) + { + } + VectorLagrangeFunctionSpaceOfElement(int id, Along comp1, Along comp2) + : ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace( + ScalarLagrangeFunctionSpaceOfElement(id), BasisVectors[comp1], comp1, + BasisVectors[comp2], comp2) + { + } + VectorLagrangeFunctionSpaceOfElement(int id, Along comp1, Along comp2, + Along comp3) + : ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace( + ScalarLagrangeFunctionSpaceOfElement(id), BasisVectors[comp1], comp1, + BasisVectors[comp2], comp2, BasisVectors[comp3], comp3) + { + } }; -class VectorLagrangeFunctionSpace : public ScalarToAnyFunctionSpace<SVector3> -{ - protected: +class VectorLagrangeFunctionSpace : public ScalarToAnyFunctionSpace<SVector3> { +protected: static const SVector3 BasisVectors[3]; - public: + +public: enum Along { VECTOR_X = 0, VECTOR_Y = 1, VECTOR_Z = 2 }; typedef TensorialTraits<SVector3>::ValType ValType; typedef TensorialTraits<SVector3>::GradType GradType; - VectorLagrangeFunctionSpace(int id) : - ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace(ScalarLagrangeFunctionSpace(id), - SVector3(1.,0.,0.), VECTOR_X, SVector3(0.,1.,0.), VECTOR_Y, SVector3(0.,0.,1.), VECTOR_Z) - {} - VectorLagrangeFunctionSpace(int id, Along comp1) : - ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace(ScalarLagrangeFunctionSpace(id), - BasisVectors[comp1], comp1) - {} - VectorLagrangeFunctionSpace(int id, Along comp1, Along comp2) : - ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace(ScalarLagrangeFunctionSpace(id), - BasisVectors[comp1], comp1, BasisVectors[comp2], comp2) - {} - VectorLagrangeFunctionSpace(int id, Along comp1, Along comp2, Along comp3) : - ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace(ScalarLagrangeFunctionSpace(id), - BasisVectors[comp1], comp1, BasisVectors[comp2], comp2, BasisVectors[comp3], comp3) - {} + VectorLagrangeFunctionSpace(int id) + : ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace( + ScalarLagrangeFunctionSpace(id), SVector3(1., 0., 0.), VECTOR_X, + SVector3(0., 1., 0.), VECTOR_Y, SVector3(0., 0., 1.), VECTOR_Z) + { + } + VectorLagrangeFunctionSpace(int id, Along comp1) + : ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace( + ScalarLagrangeFunctionSpace(id), BasisVectors[comp1], comp1) + { + } + VectorLagrangeFunctionSpace(int id, Along comp1, Along comp2) + : ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace( + ScalarLagrangeFunctionSpace(id), BasisVectors[comp1], comp1, + BasisVectors[comp2], comp2) + { + } + VectorLagrangeFunctionSpace(int id, Along comp1, Along comp2, Along comp3) + : ScalarToAnyFunctionSpace<SVector3>::ScalarToAnyFunctionSpace( + ScalarLagrangeFunctionSpace(id), BasisVectors[comp1], comp1, + BasisVectors[comp2], comp2, BasisVectors[comp3], comp3) + { + } }; -template<class T> -class CompositeFunctionSpace : public FunctionSpace<T> -{ - public: +template <class T> class CompositeFunctionSpace : public FunctionSpace<T> { +public: typedef typename TensorialTraits<T>::ValType ValType; typedef typename TensorialTraits<T>::GradType GradType; typedef typename TensorialTraits<T>::HessType HessType; - typedef typename std::vector<FunctionSpace<T>* >::iterator iterFS; - protected: - - std::vector<FunctionSpace<T>* > _spaces; - public: - template <class T1> CompositeFunctionSpace(const T1& t) { _spaces.push_back(new T1(t));} - template <class T1, class T2> CompositeFunctionSpace(const T1& t1, const T2& t2) - { _spaces.push_back(new T1(t1)); - _spaces.push_back(new T2(t2)); } - template <class T1, class T2, class T3> CompositeFunctionSpace(const T1& t1, const T2& t2, const T3& t3) - { _spaces.push_back(new T1(t1)); + typedef typename std::vector<FunctionSpace<T> *>::iterator iterFS; + +protected: + std::vector<FunctionSpace<T> *> _spaces; + +public: + template <class T1> CompositeFunctionSpace(const T1 &t) + { + _spaces.push_back(new T1(t)); + } + template <class T1, class T2> + CompositeFunctionSpace(const T1 &t1, const T2 &t2) + { + _spaces.push_back(new T1(t1)); _spaces.push_back(new T2(t2)); - _spaces.push_back(new T3(t3)); } - template <class T1, class T2, class T3, class T4> CompositeFunctionSpace(const T1& t1, const T2& t2, const T3& t3, const T4& t4) - { _spaces.push_back(new T1(t1)); + } + template <class T1, class T2, class T3> + CompositeFunctionSpace(const T1 &t1, const T2 &t2, const T3 &t3) + { + _spaces.push_back(new T1(t1)); _spaces.push_back(new T2(t2)); _spaces.push_back(new T3(t3)); - _spaces.push_back(new T4(t4)); } - template <class T1> void insert(const T1& t) + } + template <class T1, class T2, class T3, class T4> + CompositeFunctionSpace(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) { - _spaces.push_back(new T(t)); + _spaces.push_back(new T1(t1)); + _spaces.push_back(new T2(t2)); + _spaces.push_back(new T3(t3)); + _spaces.push_back(new T4(t4)); } + template <class T1> void insert(const T1 &t) { _spaces.push_back(new T(t)); } ~CompositeFunctionSpace(void) { - for (iterFS it = _spaces.begin(); it != _spaces.end(); ++it) - delete (*it); + for(iterFS it = _spaces.begin(); it != _spaces.end(); ++it) delete(*it); } - virtual void f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const + virtual void f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const { - for (iterFS it = _spaces.begin(); it != _spaces.end(); ++it) + for(iterFS it = _spaces.begin(); it != _spaces.end(); ++it) (*it)->f(ele, u, v, w, vals); } - virtual void gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const + virtual void gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { - for (iterFS it = _spaces.begin(); it != _spaces.end(); ++it) + for(iterFS it = _spaces.begin(); it != _spaces.end(); ++it) (*it)->gradf(ele, u, v, w, grads); } - virtual void hessfuvw(MElement *ele, double u, double v, double w, std::vector<HessType> &hess) const + virtual void hessfuvw(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const { - for (iterFS it = _spaces.begin(); it != _spaces.end(); ++it) + for(iterFS it = _spaces.begin(); it != _spaces.end(); ++it) (*it)->hessfuvw(ele, u, v, w, hess); } virtual int getNumKeys(MElement *ele) const { int ndofs = 0; - for (iterFS it = _spaces.begin(); it != _spaces.end(); ++it) + for(iterFS it = _spaces.begin(); it != _spaces.end(); ++it) ndofs += (*it)->getNumKeys(ele); return ndofs; } virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const { - for (iterFS it = _spaces.begin(); it != _spaces.end(); ++it) + for(iterFS it = _spaces.begin(); it != _spaces.end(); ++it) (*it)->getKeys(ele, keys); } }; -template<class T> -class xFemFunctionSpace : public FunctionSpace<T> -{ - public: +template <class T> class xFemFunctionSpace : public FunctionSpace<T> { +public: typedef typename TensorialTraits<T>::ValType ValType; typedef typename TensorialTraits<T>::GradType GradType; typedef typename TensorialTraits<T>::HessType HessType; - protected: - FunctionSpace<T>* _spacebase; - simpleFunctionOnElement<double> *_funcEnrichment; - - public: - virtual void hessfuvw(MElement *ele, double u, double v, double w,std::vector<HessType> &hess) const {} - xFemFunctionSpace(FunctionSpace<T>* spacebase,simpleFunctionOnElement<double> *funcEnrichment) : - _spacebase(spacebase),_funcEnrichment(funcEnrichment){} - virtual void f(MElement *ele, double u, double v, double w,std::vector<ValType> &vals) const ; - virtual void gradf(MElement *ele, double u, double v, double w,std::vector<GradType> &grads) const; + +protected: + FunctionSpace<T> *_spacebase; + simpleFunctionOnElement<double> *_funcEnrichment; + +public: + virtual void hessfuvw(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const + { + } + xFemFunctionSpace(FunctionSpace<T> *spacebase, + simpleFunctionOnElement<double> *funcEnrichment) + : _spacebase(spacebase), _funcEnrichment(funcEnrichment) + { + } + virtual void f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const; + virtual void gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const; virtual int getNumKeys(MElement *ele) const; virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const; }; - -template<class T, class F> -class FilteredFunctionSpace : public FunctionSpace<T> -{ - public : +template <class T, class F> +class FilteredFunctionSpace : public FunctionSpace<T> { +public: typedef typename TensorialTraits<T>::ValType ValType; typedef typename TensorialTraits<T>::GradType GradType; typedef typename TensorialTraits<T>::HessType HessType; - protected: - FunctionSpace<T>* _spacebase; + +protected: + FunctionSpace<T> *_spacebase; F *_filter; - public: - virtual void hessfuvw(MElement *ele, double u, double v, double w, std::vector<HessType> &hess) const {} - FilteredFunctionSpace<T,F>(FunctionSpace<T>* spacebase,F * filter) : _spacebase(spacebase), _filter(filter){} - virtual void f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const; - virtual void gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const; + +public: + virtual void hessfuvw(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const + { + } + FilteredFunctionSpace<T, F>(FunctionSpace<T> *spacebase, F *filter) + : _spacebase(spacebase), _filter(filter) + { + } + virtual void f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const; + virtual void gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const; virtual int getNumKeys(MElement *ele) const; virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const; }; - -template <class T> void xFemFunctionSpace<T>::f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const +template <class T> +void xFemFunctionSpace<T>::f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const { - // We need parent parameters - MElement * elep; - if (ele->getParent()) elep = ele->getParent(); - else elep = ele; + // We need parent parameters + MElement *elep; + if(ele->getParent()) + elep = ele->getParent(); + else + elep = ele; - // Get the spacebase valsd + // Get the spacebase valsd std::vector<ValType> valsd; xFemFunctionSpace<T>::_spacebase->f(elep, u, v, w, valsd); int nbdofs = valsd.size(); - int curpos = vals.size(); // if in composite function space + int curpos = vals.size(); // if in composite function space vals.reserve(curpos + nbdofs); // then enriched dofs so the order is ex:(a2x,a2y,a3x,a3y) - if (nbdofs > 0){ // if enriched + if(nbdofs > 0) { // if enriched // Enrichment function calcul SPoint3 p; elep->pnt(u, v, w, p); // parametric to cartesian coordinates double func; _funcEnrichment->setElement(elep); func = (*_funcEnrichment)(p.x(), p.y(), p.z()); - for (int i = 0 ; i < nbdofs; i++){ + for(int i = 0; i < nbdofs; i++) { vals.push_back(valsd[i] * func); } } } -template <class T> void xFemFunctionSpace<T>::gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const +template <class T> +void xFemFunctionSpace<T>::gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { - - // We need parent parameters + // We need parent parameters MElement *elep; - if (ele->getParent()) elep = ele->getParent(); - else elep = ele; + if(ele->getParent()) + elep = ele->getParent(); + else + elep = ele; - // Get the spacebase gradsd + // Get the spacebase gradsd std::vector<GradType> gradsd; xFemFunctionSpace<T>::_spacebase->gradf(elep, u, v, w, gradsd); - int nbdofs=gradsd.size(); + int nbdofs = gradsd.size(); - // We need spacebase valsd to compute total gradient + // We need spacebase valsd to compute total gradient std::vector<ValType> valsd; xFemFunctionSpace<T>::_spacebase->f(elep, u, v, w, valsd); - int curpos = grads.size(); // if in composite function space + int curpos = grads.size(); // if in composite function space grads.reserve(curpos + nbdofs); - // then enriched dofs so the order is ex:(a2x,a2y,a3x,a3y) - if (nbdofs > 0){ // if enriched + // then enriched dofs so the order is ex:(a2x,a2y,a3x,a3y) + if(nbdofs > 0) { // if enriched double df[3]; SPoint3 p; elep->pnt(u, v, w, p); _funcEnrichment->setElement(elep); - _funcEnrichment->gradient (p.x(), p.y(), p.z(), df[0], df[1], df[2]); + _funcEnrichment->gradient(p.x(), p.y(), p.z(), df[0], df[1], df[2]); ValType gradfuncenrich(df[0], df[1], df[2]); - // Enrichment function calcul + // Enrichment function calcul double func; _funcEnrichment->setElement(elep); func = (*_funcEnrichment)(p.x(), p.y(), p.z()); - for (int i = 0 ; i < nbdofs; i++){ + for(int i = 0; i < nbdofs; i++) { GradType GradFunc; tensprod(valsd[i], gradfuncenrich, GradFunc); grads.push_back(gradsd[i] * func + GradFunc); @@ -632,17 +755,22 @@ template <class T> void xFemFunctionSpace<T>::gradf(MElement *ele, double u, dou template <class T> int xFemFunctionSpace<T>::getNumKeys(MElement *ele) const { MElement *elep; - if (ele->getParent()) elep = ele->getParent(); - else elep = ele; + if(ele->getParent()) + elep = ele->getParent(); + else + elep = ele; int nbdofs = xFemFunctionSpace<T>::_spacebase->getNumKeys(elep); return nbdofs; } -template <class T> void xFemFunctionSpace<T>::getKeys(MElement *ele, std::vector<Dof> &keys) const +template <class T> +void xFemFunctionSpace<T>::getKeys(MElement *ele, std::vector<Dof> &keys) const { MElement *elep; - if (ele->getParent()) elep = ele->getParent(); - else elep = ele; + if(ele->getParent()) + elep = ele->getParent(); + else + elep = ele; int normalk = xFemFunctionSpace<T>::_spacebase->getNumKeys(elep); @@ -655,25 +783,29 @@ template <class T> void xFemFunctionSpace<T>::getKeys(MElement *ele, std::vector int curpos = keys.size(); keys.reserve(curpos + nbdofs); - // get keys so the order is ex:(a2x,a2y,a3x,a3y) - // enriched dof tagged with ( i2 -> i2 + 1 ) - for (int i = 0 ;i < nbdofs; i++){ + // get keys so the order is ex:(a2x,a2y,a3x,a3y) + // enriched dof tagged with ( i2 -> i2 + 1 ) + for(int i = 0; i < nbdofs; i++) { int i1, i2; Dof::getTwoIntsFromType(bufk[i].getType(), i1, i2); - keys.push_back(Dof(bufk[i].getEntity(), Dof::createTypeWithTwoInts(i1, i2 + 1))); + keys.push_back( + Dof(bufk[i].getEntity(), Dof::createTypeWithTwoInts(i1, i2 + 1))); } } - // Filtered function space // -template <class T,class F> void FilteredFunctionSpace<T,F>::f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const +template <class T, class F> +void FilteredFunctionSpace<T, F>::f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const { - // We need parent parameters + // We need parent parameters MElement *elep; - if (ele->getParent()) elep = ele->getParent(); - else elep = ele; + if(ele->getParent()) + elep = ele->getParent(); + else + elep = ele; std::vector<ValType> valsd; @@ -684,41 +816,46 @@ template <class T,class F> void FilteredFunctionSpace<T,F>::f(MElement *ele, dou bufk.reserve(normalk); _spacebase->getKeys(elep, bufk); - for (int i = 0; i < bufk.size(); i++){ - if ((*_filter)(bufk[i])) - vals.push_back(valsd[i]); + for(int i = 0; i < bufk.size(); i++) { + if((*_filter)(bufk[i])) vals.push_back(valsd[i]); } } - -template <class T,class F> void FilteredFunctionSpace<T,F>::gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const +template <class T, class F> +void FilteredFunctionSpace<T, F>::gradf(MElement *ele, double u, double v, + double w, + std::vector<GradType> &grads) const { - // We need parent parameters + // We need parent parameters MElement *elep; - if (ele->getParent()) elep = ele->getParent(); - else elep = ele; + if(ele->getParent()) + elep = ele->getParent(); + else + elep = ele; - // Get space base gradsd + // Get space base gradsd std::vector<GradType> gradsd; _spacebase->gradf(elep, u, v, w, gradsd); - // Get numkeys + // Get numkeys int normalk = _spacebase->getNumKeys(elep); std::vector<Dof> bufk; bufk.reserve(normalk); _spacebase->getKeys(elep, bufk); - for (int i = 0; i < bufk.size(); i++){ - if ((*_filter)(bufk[i])) - grads.push_back(gradsd[i]); + for(int i = 0; i < bufk.size(); i++) { + if((*_filter)(bufk[i])) grads.push_back(gradsd[i]); } } -template <class T,class F> int FilteredFunctionSpace<T,F>::getNumKeys(MElement *ele) const +template <class T, class F> +int FilteredFunctionSpace<T, F>::getNumKeys(MElement *ele) const { MElement *elep; - if (ele->getParent()) elep = ele->getParent(); - else elep = ele; + if(ele->getParent()) + elep = ele->getParent(); + else + elep = ele; int nbdofs = 0; @@ -727,18 +864,21 @@ template <class T,class F> int FilteredFunctionSpace<T,F>::getNumKeys(MElement * bufk.reserve(normalk); _spacebase->getKeys(elep, bufk); - for (int i = 0; i < bufk.size(); i++){ - if ((*_filter)(bufk[i])) - nbdofs = nbdofs + 1; + for(int i = 0; i < bufk.size(); i++) { + if((*_filter)(bufk[i])) nbdofs = nbdofs + 1; } return nbdofs; } -template <class T, class F> void FilteredFunctionSpace<T, F>::getKeys(MElement *ele, std::vector<Dof> &keys) const +template <class T, class F> +void FilteredFunctionSpace<T, F>::getKeys(MElement *ele, + std::vector<Dof> &keys) const { MElement *elep; - if (ele->getParent()) elep = ele->getParent(); - else elep = ele; + if(ele->getParent()) + elep = ele->getParent(); + else + elep = ele; int normalk = _spacebase->getNumKeys(elep); @@ -746,11 +886,9 @@ template <class T, class F> void FilteredFunctionSpace<T, F>::getKeys(MElement * bufk.reserve(normalk); _spacebase->getKeys(elep, bufk); - for (int i = 0; i < bufk.size(); i++){ - if ((*_filter)(bufk[i])) - keys.push_back(bufk[i]); + for(int i = 0; i < bufk.size(); i++) { + if((*_filter)(bufk[i])) keys.push_back(bufk[i]); } } - #endif diff --git a/Solver/groupOfElements.cpp b/Solver/groupOfElements.cpp index 48e4fdc79b614041f8cf8835de4c6a44a4d1ad34..3051e7cfead6005b94cedfd2aed2c53324547885 100644 --- a/Solver/groupOfElements.cpp +++ b/Solver/groupOfElements.cpp @@ -7,46 +7,47 @@ #include "GModel.h" #include "GEntity.h" -groupOfElements::groupOfElements(GFace*gf) +groupOfElements::groupOfElements(GFace *gf) { elementFilterTrivial filter; addElementary(gf, filter); } -groupOfElements::groupOfElements(GRegion*gr) +groupOfElements::groupOfElements(GRegion *gr) { elementFilterTrivial filter; addElementary(gr, filter); } -groupOfElements::groupOfElements(std::vector<MElement*> &elems) +groupOfElements::groupOfElements(std::vector<MElement *> &elems) { elementFilterTrivial filter; - for (std::vector<MElement*>::iterator it = elems.begin(); it != elems.end(); it++){ + for(std::vector<MElement *>::iterator it = elems.begin(); it != elems.end(); + it++) { MElement *e = *it; - if (filter(e)){ + if(filter(e)) { insert(e); } } } - -void groupOfElements::addElementary(GEntity *ge, const elementFilter &filter){ - for (unsigned int j = 0; j < ge->getNumMeshElements(); j++){ +void groupOfElements::addElementary(GEntity *ge, const elementFilter &filter) +{ + for(unsigned int j = 0; j < ge->getNumMeshElements(); j++) { MElement *e = ge->getMeshElement(j); - if (filter(e)){ + if(filter(e)) { insert(e); } } } void groupOfElements::addPhysical(int dim, int physical, - const elementFilter &filter){ - std::map<int, std::vector<GEntity*> > groups[4]; + const elementFilter &filter) +{ + std::map<int, std::vector<GEntity *> > groups[4]; GModel::current()->getPhysicalGroups(groups); - std::vector<GEntity*> &ent = groups[dim][physical]; - for (unsigned int i = 0; i < ent.size(); i++){ + std::vector<GEntity *> &ent = groups[dim][physical]; + for(unsigned int i = 0; i < ent.size(); i++) { addElementary(ent[i], filter); } } - diff --git a/Solver/groupOfElements.h b/Solver/groupOfElements.h index 18733d0b2695a287d33d2fe86da8bc95d85c58ba..d0a9561a5ce41163d3a285fa394832681868c635 100644 --- a/Solver/groupOfElements.h +++ b/Solver/groupOfElements.h @@ -11,39 +11,39 @@ #include "MElement.h" class elementFilter { - public: - virtual ~elementFilter(){} - virtual bool operator() (MElement *) const = 0; +public: + virtual ~elementFilter() {} + virtual bool operator()(MElement *) const = 0; }; class elementFilterTrivial : public elementFilter { - public: - bool operator() (MElement *) const {return true;} +public: + bool operator()(MElement *) const { return true; } }; class groupOfElements { - public: - typedef std::set<MElement*> elementContainer; - typedef std::set<MVertex*> vertexContainer; +public: + typedef std::set<MElement *> elementContainer; + typedef std::set<MVertex *> vertexContainer; - protected: +protected: vertexContainer _vertices; elementContainer _elements; elementContainer _parents; - public: - groupOfElements(){} - groupOfElements (int dim, int physical) { addPhysical (dim, physical); } - groupOfElements (GFace*); - groupOfElements (GRegion*); - groupOfElements(std::vector<MElement*> &elems); +public: + groupOfElements() {} + groupOfElements(int dim, int physical) { addPhysical(dim, physical); } + groupOfElements(GFace *); + groupOfElements(GRegion *); + groupOfElements(std::vector<MElement *> &elems); - virtual ~groupOfElements(){} + virtual ~groupOfElements() {} virtual void addPhysical(int dim, int physical) { elementFilterTrivial filter; - addPhysical (dim, physical, filter); + addPhysical(dim, physical, filter); } virtual void addElementary(GEntity *ge, const elementFilter &f); @@ -59,30 +59,29 @@ class groupOfElements { size_t vsize() const { return _vertices.size(); } // FIXME : NOT VERY ELEGANT !!! - bool find (MElement *e) const // if same parent but different physicals return true ?! + bool find( + MElement *e) const // if same parent but different physicals return true ?! { - if (e->getParent() && _parents.find(e->getParent()) != _parents.end()) return true; + if(e->getParent() && _parents.find(e->getParent()) != _parents.end()) + return true; return (_elements.find(e) != _elements.end()); } - bool find (MVertex *v) const - { - return (_vertices.find(v) != _vertices.end()); - } + bool find(MVertex *v) const { return (_vertices.find(v) != _vertices.end()); } - inline void insert (MElement *e) + inline void insert(MElement *e) { _elements.insert(e); - if (e->getParent()){ + if(e->getParent()) { _parents.insert(e->getParent()); - for (std::size_t i = 0; i < e->getParent()->getNumVertices(); i++){ - _vertices.insert(e->getParent()->getVertex(i)); + for(std::size_t i = 0; i < e->getParent()->getNumVertices(); i++) { + _vertices.insert(e->getParent()->getVertex(i)); } } - else{ - for (std::size_t i = 0; i < e->getNumVertices(); i++){ - _vertices.insert(e->getVertex(i)); + else { + for(std::size_t i = 0; i < e->getNumVertices(); i++) { + _vertices.insert(e->getVertex(i)); } } } @@ -96,38 +95,41 @@ class groupOfElements { }; // child elements in pElem restricted to elements who have parent in sElem -class groupOfLagMultElements : public groupOfElements -{ - private : +class groupOfLagMultElements : public groupOfElements { +private: void fillElementContainer(groupOfElements &pElem, groupOfElements &sElem) { groupOfElements::elementContainer::const_iterator itp = pElem.begin(); - for (;itp!=pElem.end(); itp++) - { - if ((*itp)->getParent()) - { - if (sElem.find(*itp)) insert((*itp)) ; // warning : find method used to check if parent is in sElem + for(; itp != pElem.end(); itp++) { + if((*itp)->getParent()) { + if(sElem.find(*itp)) + insert(( + *itp)); // warning : find method used to check if parent is in sElem } - else std::cout << "groupOfLagMultElements : Warning, level set element has no parent ?! " << std::endl; + else + std::cout << "groupOfLagMultElements : Warning, level set element has " + "no parent ?! " + << std::endl; } } - public : - groupOfLagMultElements(int dim, int physical, groupOfElements &sElem) : groupOfElements() +public: + groupOfLagMultElements(int dim, int physical, groupOfElements &sElem) + : groupOfElements() { - groupOfElements pElem(dim , physical); - fillElementContainer(pElem,sElem); + groupOfElements pElem(dim, physical); + fillElementContainer(pElem, sElem); } - groupOfLagMultElements(int dim, int physical, std::vector < groupOfElements *> sElem) : groupOfElements() + groupOfLagMultElements(int dim, int physical, + std::vector<groupOfElements *> sElem) + : groupOfElements() { - groupOfElements pElem(dim , physical); - for (unsigned int i = 0 ;i < sElem.size() ; i ++) - { - fillElementContainer(pElem,(*sElem[i])); + groupOfElements pElem(dim, physical); + for(unsigned int i = 0; i < sElem.size(); i++) { + fillElementContainer(pElem, (*sElem[i])); } } - }; #endif diff --git a/Solver/helmholtzTerm.h b/Solver/helmholtzTerm.h index c2cc34f1e22ef246032adfea1b8512927398aa38..e9cdd0649c528748b87079084c6ab877e26d23a4 100644 --- a/Solver/helmholtzTerm.h +++ b/Solver/helmholtzTerm.h @@ -16,16 +16,18 @@ #include "Numeric.h" // \nabla \cdot k \nabla U - a U -template<class scalar> -class helmholtzTerm : public femTerm<scalar> { - protected: +template <class scalar> class helmholtzTerm : public femTerm<scalar> { +protected: const simpleFunction<scalar> *_k, *_a; const int _iFieldR; - int _iFieldC ; - public: + int _iFieldC; + +public: helmholtzTerm(GModel *gm, int iFieldR, int iFieldC, simpleFunction<scalar> *k, simpleFunction<scalar> *a) - : femTerm<scalar>(gm), _k(k), _a(a), _iFieldR(iFieldR), _iFieldC(iFieldC) {} + : femTerm<scalar>(gm), _k(k), _a(a), _iFieldR(iFieldR), _iFieldC(iFieldC) + { + } // one dof per vertex (nodal fem) virtual int sizeOfR(SElement *se) const { @@ -48,14 +50,15 @@ class helmholtzTerm : public femTerm<scalar> { virtual void elementMatrix(SElement *se, fullMatrix<scalar> &m) const { MElement *e = se->getMeshElement(); - if (_k)_k->setElement(e); - if (_a)_a->setElement(e); + if(_k) _k->setElement(e); + if(_a) _a->setElement(e); // compute integration rule // const int integrationOrder = (_a) ? 2 * e->getPolynomialOrder() : - //2 * (e->getPolynomialOrder() - 1); - const int integrationOrder = 2 * e->getPolynomialOrder() + 1; + // 2 * (e->getPolynomialOrder() - 1); + const int integrationOrder = 2 * e->getPolynomialOrder() + 1; - int npts; IntPt *GP; + int npts; + IntPt *GP; e->getIntegrationPoints(integrationOrder, &npts, &GP); // get the number of nodes const int nbSF = e->getNumShapeFunctions(); @@ -68,39 +71,40 @@ class helmholtzTerm : public femTerm<scalar> { // set the local matrix to 0 m.setAll(0.); // loop over integration points - for (int i = 0; i < npts; i++){ + for(int i = 0; i < npts; i++) { // compute stuff at this point const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; const double weightDetJ = GP[i].weight * e->getJacobian(u, v, w, jac); - SPoint3 p; e->pnt(u, v, w, p); + SPoint3 p; + e->pnt(u, v, w, p); const scalar K = _k ? (*_k)(p.x(), p.y(), p.z()) : 0.0; const scalar A = _a ? (*_a)(p.x(), p.y(), p.z()) : 0.0; - inv3x3(jac, invjac) ; + inv3x3(jac, invjac); e->getGradShapeFunctions(u, v, w, grads); - if (_a) e->getShapeFunctions(u, v, w, sf); - for (int j = 0; j < nbSF; j++){ + if(_a) e->getShapeFunctions(u, v, w, sf); + for(int j = 0; j < nbSF; j++) { Grads[j][0] = invjac[0][0] * grads[j][0] + invjac[0][1] * grads[j][1] + - invjac[0][2] * grads[j][2]; + invjac[0][2] * grads[j][2]; Grads[j][1] = invjac[1][0] * grads[j][0] + invjac[1][1] * grads[j][1] + - invjac[1][2] * grads[j][2]; + invjac[1][2] * grads[j][2]; Grads[j][2] = invjac[2][0] * grads[j][0] + invjac[2][1] * grads[j][1] + - invjac[2][2] * grads[j][2]; - if (!_a) sf[j] = 0; + invjac[2][2] * grads[j][2]; + if(!_a) sf[j] = 0; } - for (int j = 0; j < nbSF; j++){ - for (int k = 0; k <= j; k++){ - m(j, k) += (K * (Grads[j][0] * Grads[k][0] + - Grads[j][1] * Grads[k][1] + - Grads[j][2] * Grads[k][2]) + A * sf[j] * sf[k]) * weightDetJ; + for(int j = 0; j < nbSF; j++) { + for(int k = 0; k <= j; k++) { + m(j, k) += + (K * (Grads[j][0] * Grads[k][0] + Grads[j][1] * Grads[k][1] + + Grads[j][2] * Grads[k][2]) + + A * sf[j] * sf[k]) * + weightDetJ; } } } - for (int j = 0; j < nbSF; j++) - for (int k = 0; k < j; k++) - m(k, j) = m(j, k); - + for(int j = 0; j < nbSF; j++) + for(int k = 0; k < j; k++) m(k, j) = m(j, k); } }; diff --git a/Solver/laplaceTerm.h b/Solver/laplaceTerm.h index cc828c4e76b185a3a8a8cc9cf14b02ec38efff6f..99eed4ea9d8d6390065fc1afd9cb4b6d3c06de54 100644 --- a/Solver/laplaceTerm.h +++ b/Solver/laplaceTerm.h @@ -10,14 +10,18 @@ // \nabla \cdot k \nabla U class laplaceTerm : public helmholtzTerm<double> { - protected: +protected: const int _iField; - std::map<MVertex*, SPoint3> *_coordView; - public: - laplaceTerm(GModel *gm, int iField, simpleFunction<double> *k, - std::map<MVertex*, SPoint3> *coord=NULL) - : helmholtzTerm<double>(gm, iField, iField, k, 0), _iField(iField), _coordView(coord) {} - void elementVector(SElement *se, fullVector<double> &m) const + std::map<MVertex *, SPoint3> *_coordView; + +public: + laplaceTerm(GModel *gm, int iField, simpleFunction<double> *k, + std::map<MVertex *, SPoint3> *coord = NULL) + : helmholtzTerm<double>(gm, iField, iField, k, 0), _iField(iField), + _coordView(coord) + { + } + void elementVector(SElement *se, fullVector<double> &m) const { MElement *e = se->getMeshElement(); int nbSF = e->getNumShapeFunctions(); @@ -28,26 +32,29 @@ class laplaceTerm : public helmholtzTerm<double> { fullVector<double> val(nbSF); val.scale(0.); - for (int i = 0; i < nbSF; i++){ - std::map<MVertex*, SPoint3>::iterator it = _coordView->find(e->getShapeFunctionNode(i)); + for(int i = 0; i < nbSF; i++) { + std::map<MVertex *, SPoint3>::iterator it = + _coordView->find(e->getShapeFunctionNode(i)); SPoint3 UV = it->second; - if (_iField == 1) val(i) = UV.x(); - else if (_iField == 2) val(i) = UV.y(); + if(_iField == 1) + val(i) = UV.x(); + else if(_iField == 2) + val(i) = UV.y(); } m.scale(0.); - for (int i = 0; i < nbSF; i++) - for (int j = 0; j < nbSF; j++) - m(i) += -(*mat)(i, j) * val(j); + for(int i = 0; i < nbSF; i++) + for(int j = 0; j < nbSF; j++) m(i) += -(*mat)(i, j) * val(j); } }; // a \nabla U class massTerm : public helmholtzTerm<double> { - public: +public: massTerm(GModel *gm, int iField, simpleFunction<double> *a) - : helmholtzTerm<double>(gm, iField, iField, 0, a) {} + : helmholtzTerm<double>(gm, iField, iField, 0, a) + { + } }; - #endif diff --git a/Solver/linearSystem.cpp b/Solver/linearSystem.cpp index d6ff117b02dab5c14ac83513f409fd87ba9c17d2..34b0301f398d4d3477d1a288ac284f9c0bb13600 100644 --- a/Solver/linearSystem.cpp +++ b/Solver/linearSystem.cpp @@ -7,9 +7,9 @@ #include "linearSystemCSR.h" #include "linearSystemGMM.h" -void linearSystemBase::setParameter (std::string key, std::string value) +void linearSystemBase::setParameter(std::string key, std::string value) { - if (isAllocated()) + if(isAllocated()) Msg::Error("this system is already allocated, parameters cannot be set"); _parameters[key] = value; } @@ -18,6 +18,8 @@ std::string linearSystemBase::getParameter(std::string key) const { std::map<std::string, std::string>::const_iterator it; it = this->_parameters.find(key); - if(it == this->_parameters.end()) return ""; - else return it->second; + if(it == this->_parameters.end()) + return ""; + else + return it->second; } diff --git a/Solver/linearSystem.h b/Solver/linearSystem.h index 80f97b55d489dba90d419055f9e642ffc4f8967f..e12129733d8ce16f63899c6f3a48e45f9faadf26 100644 --- a/Solver/linearSystem.h +++ b/Solver/linearSystem.h @@ -12,10 +12,11 @@ // A class that encapsulates a linear system solver interface : // building a sparse matrix, solving a linear system class linearSystemBase { - protected: +protected: std::map<std::string, std::string> _parameters; - public : - virtual ~linearSystemBase(){} + +public: + virtual ~linearSystemBase() {} virtual bool isAllocated() const = 0; virtual void allocate(int nbRows) = 0; virtual void preAllocateEntries(){}; @@ -27,18 +28,17 @@ class linearSystemBase { // x = A*b virtual int matMult() { return 0; } - void setParameter (std::string key, std::string value); + void setParameter(std::string key, std::string value); std::string getParameter(std::string key) const; virtual void insertInSparsityPattern(int _row, int _col){}; virtual double normInfRightHandSide() const = 0; - virtual double normInfSolution() const {return 0;}; + virtual double normInfSolution() const { return 0; }; }; -template <class scalar> -class linearSystem : public linearSystemBase { - public : - linearSystem (){} - virtual ~linearSystem (){} +template <class scalar> class linearSystem : public linearSystemBase { +public: + linearSystem() {} + virtual ~linearSystem() {} virtual void addToMatrix(int _row, int _col, const scalar &val) = 0; virtual void getFromMatrix(int _row, int _col, scalar &val) const = 0; virtual void addToRightHandSide(int _row, const scalar &val, int ith = 0) = 0; diff --git a/Solver/linearSystemCSR.cpp b/Solver/linearSystemCSR.cpp index bcdd5feb2340901a0c875441c066aee818afee23..aeca90437cbf4a4516c22d5cff53e440fcc76250 100644 --- a/Solver/linearSystemCSR.cpp +++ b/Solver/linearSystemCSR.cpp @@ -12,32 +12,35 @@ #include "linearSystemCSR.h" #include "OS.h" -#define SWAP(a, b) temp = (a); (a) = (b); (b) = temp; -#define SWAPI(a, b) tempi = (a); (a) = (b); (b) = tempi; +#define SWAP(a, b) \ + temp = (a); \ + (a) = (b); \ + (b) = temp; +#define SWAPI(a, b) \ + tempi = (a); \ + (a) = (b); \ + (b) = tempi; static void *CSRMalloc(size_t size) { void *ptr; - if (!size) return(NULL); + if(!size) return (NULL); ptr = malloc(size); - return(ptr); + return (ptr); } -static void *CSRRealloc(void *ptr, size_t size) -{ - return realloc(ptr, size); -} +static void *CSRRealloc(void *ptr, size_t size) { return realloc(ptr, size); } static void CSRList_Realloc(CSRList_T *liste, int n) { char *temp; - if (n <= 0) return; - if (liste->array == NULL) { + if(n <= 0) return; + if(liste->array == NULL) { liste->nmax = ((n - 1) / liste->incr + 1) * liste->incr; liste->array = (char *)CSRMalloc(liste->nmax * liste->size); } else { - if (n > liste->nmax) { + if(n > liste->nmax) { liste->nmax = ((n - 1) / liste->incr + 1) * liste->incr; temp = (char *)CSRRealloc(liste->array, liste->nmax * liste->size); liste->array = temp; @@ -56,25 +59,25 @@ static CSRList_T *CSRList_Create(int n, int incr, int size) { CSRList_T *liste; - if (n <= 0) n = 1 ; - if (incr <= 0) incr = 1; + if(n <= 0) n = 1; + if(incr <= 0) incr = 1; liste = (CSRList_T *)CSRMalloc(sizeof(CSRList_T)); - liste->nmax = 0; - liste->incr = incr; - liste->size = size; - liste->n = 0; + liste->nmax = 0; + liste->incr = incr; + liste->size = size; + liste->n = 0; liste->isorder = 0; - liste->array = NULL; + liste->array = NULL; CSRList_Realloc(liste, n); - return(liste); + return (liste); } static void CSRList_Delete(CSRList_T *liste) { - if (liste != 0) { + if(liste != 0) { free(liste->array); free(liste); } @@ -88,40 +91,35 @@ void CSRList_Add(CSRList_T *liste, const void *data) memcpy(&liste->array[(liste->n - 1) * liste->size], data, liste->size); } -int CSRList_Nbr(CSRList_T *liste) -{ - return(liste->n); -} +int CSRList_Nbr(CSRList_T *liste) { return (liste->n); } -template<> -void linearSystemCSR<double>::preAllocateEntries () +template <> void linearSystemCSR<double>::preAllocateEntries() { - if (_entriesPreAllocated) return; - if (_sparsity.getNbRows() == 0) return; + if(_entriesPreAllocated) return; + if(_sparsity.getNbRows() == 0) return; INDEX_TYPE nnz = 0; int nbRows = _b->size(); - for (int i = 0; i < nbRows; i++){ + for(int i = 0; i < nbRows; i++) { int nInRow; - _sparsity.getRow (i, nInRow); + _sparsity.getRow(i, nInRow); nnz += nInRow; } - CSRList_Resize_strict (_ai, nnz); - CSRList_Resize_strict (_ptr, nnz); - INDEX_TYPE *jptr = (INDEX_TYPE*) _jptr->array; - INDEX_TYPE *ai = (INDEX_TYPE*) _ai->array; - INDEX_TYPE *ptr = (INDEX_TYPE*) _ptr->array; + CSRList_Resize_strict(_ai, nnz); + CSRList_Resize_strict(_ptr, nnz); + INDEX_TYPE *jptr = (INDEX_TYPE *)_jptr->array; + INDEX_TYPE *ai = (INDEX_TYPE *)_ai->array; + INDEX_TYPE *ptr = (INDEX_TYPE *)_ptr->array; jptr[0] = 0; nnz = 0; - for (int i = 0; i < nbRows; i++){ + for(int i = 0; i < nbRows; i++) { int nInRow; - const int *row = _sparsity.getRow (i, nInRow); - for (int j = 0; j < nInRow; j++) { + const int *row = _sparsity.getRow(i, nInRow); + for(int j = 0; j < nInRow; j++) { ai[nnz] = row[j]; - ptr[nnz] = nnz+1; - nnz ++; + ptr[nnz] = nnz + 1; + nnz++; } - if (nInRow != 0) - ptr[nnz - 1] = 0; + if(nInRow != 0) ptr[nnz - 1] = 0; jptr[i + 1] = nnz; something[i] = (nInRow == 0 ? 0 : 1); } @@ -129,42 +127,40 @@ void linearSystemCSR<double>::preAllocateEntries () sorted = true; _sparsity.clear(); // we do this after _sparsity.clear so that the peak memory usage is reduced - CSRList_Resize_strict (_a, nnz); - double *a = ( double * ) _a->array; - for (int i = 0; i < nnz; i++) { + CSRList_Resize_strict(_a, nnz); + double *a = (double *)_a->array; + for(int i = 0; i < nnz; i++) { a[i] = 0.; } } -template<> -void linearSystemCSR<std::complex<double> >::preAllocateEntries () +template <> void linearSystemCSR<std::complex<double> >::preAllocateEntries() { - if (_entriesPreAllocated) return; - if (_sparsity.getNbRows() == 0) return; + if(_entriesPreAllocated) return; + if(_sparsity.getNbRows() == 0) return; INDEX_TYPE nnz = 0; int nbRows = _b->size(); - for (int i = 0; i < nbRows; i++){ + for(int i = 0; i < nbRows; i++) { int nInRow; - _sparsity.getRow (i, nInRow); + _sparsity.getRow(i, nInRow); nnz += nInRow; } - CSRList_Resize_strict (_ai, nnz); - CSRList_Resize_strict (_ptr, nnz); - INDEX_TYPE *jptr = (INDEX_TYPE*) _jptr->array; - INDEX_TYPE *ai = (INDEX_TYPE*) _ai->array; - INDEX_TYPE *ptr = (INDEX_TYPE*) _ptr->array; + CSRList_Resize_strict(_ai, nnz); + CSRList_Resize_strict(_ptr, nnz); + INDEX_TYPE *jptr = (INDEX_TYPE *)_jptr->array; + INDEX_TYPE *ai = (INDEX_TYPE *)_ai->array; + INDEX_TYPE *ptr = (INDEX_TYPE *)_ptr->array; jptr[0] = 0; nnz = 0; - for (int i = 0; i < nbRows; i++){ + for(int i = 0; i < nbRows; i++) { int nInRow; - const int *row = _sparsity.getRow (i, nInRow); - for (int j = 0; j < nInRow; j++) { + const int *row = _sparsity.getRow(i, nInRow); + for(int j = 0; j < nInRow; j++) { ai[nnz] = row[j]; - ptr[nnz] = nnz+1; - nnz ++; + ptr[nnz] = nnz + 1; + nnz++; } - if (nInRow != 0) - ptr[nnz - 1] = 0; + if(nInRow != 0) ptr[nnz - 1] = 0; jptr[i + 1] = nnz; something[i] = (nInRow == 0 ? 0 : 1); } @@ -172,15 +168,14 @@ void linearSystemCSR<std::complex<double> >::preAllocateEntries () sorted = true; _sparsity.clear(); // we do this after _sparsity.clear so that the peak memory usage is reduced - CSRList_Resize_strict (_a, nnz); - std::complex<double> *a = ( std::complex<double> * ) _a->array; - for (int i = 0; i < nnz; i++) { + CSRList_Resize_strict(_a, nnz); + std::complex<double> *a = (std::complex<double> *)_a->array; + for(int i = 0; i < nnz; i++) { a[i] = std::complex<double>(); } } -template<> -void linearSystemCSR<double>::allocate(int nbRows) +template <> void linearSystemCSR<double>::allocate(int nbRows) { if(_a) { CSRList_Delete(_a); @@ -192,7 +187,7 @@ void linearSystemCSR<double>::allocate(int nbRows) delete[] something; } - if(nbRows == 0){ + if(nbRows == 0) { _a = 0; _ai = 0; _ptr = 0; @@ -204,21 +199,20 @@ void linearSystemCSR<double>::allocate(int nbRows) return; } - _a = CSRList_Create(nbRows, nbRows, sizeof(double)); - _ai = CSRList_Create(nbRows, nbRows, sizeof(INDEX_TYPE)); - _ptr = CSRList_Create(nbRows, nbRows, sizeof(INDEX_TYPE)); + _a = CSRList_Create(nbRows, nbRows, sizeof(double)); + _ai = CSRList_Create(nbRows, nbRows, sizeof(INDEX_TYPE)); + _ptr = CSRList_Create(nbRows, nbRows, sizeof(INDEX_TYPE)); _jptr = CSRList_Create(nbRows + 1, nbRows, sizeof(INDEX_TYPE)); something = new char[nbRows]; - for (int i = 0; i < nbRows; i++) something[i] = 0; + for(int i = 0; i < nbRows; i++) something[i] = 0; _b = new std::vector<double>(nbRows); _x = new std::vector<double>(nbRows); } -template<> -void linearSystemCSR<std::complex<double> >::allocate(int nbRows) +template <> void linearSystemCSR<std::complex<double> >::allocate(int nbRows) { if(_a) { CSRList_Delete(_a); @@ -230,7 +224,7 @@ void linearSystemCSR<std::complex<double> >::allocate(int nbRows) delete[] something; } - if(nbRows == 0){ + if(nbRows == 0) { _a = 0; _ai = 0; _ptr = 0; @@ -242,14 +236,14 @@ void linearSystemCSR<std::complex<double> >::allocate(int nbRows) return; } - _a = CSRList_Create(nbRows, nbRows, sizeof(std::complex<double>)); - _ai = CSRList_Create(nbRows, nbRows, sizeof(INDEX_TYPE)); - _ptr = CSRList_Create(nbRows, nbRows, sizeof(INDEX_TYPE)); + _a = CSRList_Create(nbRows, nbRows, sizeof(std::complex<double>)); + _ai = CSRList_Create(nbRows, nbRows, sizeof(INDEX_TYPE)); + _ptr = CSRList_Create(nbRows, nbRows, sizeof(INDEX_TYPE)); _jptr = CSRList_Create(nbRows + 1, nbRows, sizeof(INDEX_TYPE)); something = new char[nbRows]; - for (int i = 0; i < nbRows; i++) something[i] = 0; + for(int i = 0; i < nbRows; i++) something[i] = 0; _b = new std::vector<std::complex<double> >(nbRows); _x = new std::vector<std::complex<double> >(nbRows); @@ -261,15 +255,15 @@ const unsigned int M_sort2 = 7; static void free_ivector(int *v, long nl, long nh) { // free an int vector allocated with ivector() - free((char*)(v + nl - 1)); + free((char *)(v + nl - 1)); } static int *ivector(long nl, long nh) { // allocate an int vector with subscript range v[nl..nh] int *v; - v = (int *)malloc((size_t) ((nh - nl + 2) * sizeof(int))); - if (!v) fprintf(stderr, "allocation failure in ivector()\n"); + v = (int *)malloc((size_t)((nh - nl + 2) * sizeof(int))); + if(!v) fprintf(stderr, "allocation failure in ivector()\n"); return v - nl + 1; } @@ -283,7 +277,8 @@ static int cmpij(INDEX_TYPE ai, INDEX_TYPE aj, INDEX_TYPE bi, INDEX_TYPE bj) } template <class scalar> -static void _sort2_xkws(unsigned long n, scalar arr[], INDEX_TYPE ai[], INDEX_TYPE aj[]) +static void _sort2_xkws(unsigned long n, scalar arr[], INDEX_TYPE ai[], + INDEX_TYPE aj[]) { unsigned long i, ir = n, j, k, l = 1; int *istack, jstack = 0; @@ -292,14 +287,14 @@ static void _sort2_xkws(unsigned long n, scalar arr[], INDEX_TYPE ai[], INDEX_TY int b, c; istack = ivector(1, NSTACK); - for (;;) { - if (ir - l < M_sort2) { - for (j = l + 1; j <= ir; j++) { - a = arr[j -1]; - b = ai[j -1]; - c = aj[j -1]; - for (i = j - 1; i >= 1; i--) { - if (cmpij(ai[i - 1], aj[i - 1], b, c) <= 0) break; + for(;;) { + if(ir - l < M_sort2) { + for(j = l + 1; j <= ir; j++) { + a = arr[j - 1]; + b = ai[j - 1]; + c = aj[j - 1]; + for(i = j - 1; i >= 1; i--) { + if(cmpij(ai[i - 1], aj[i - 1], b, c) <= 0) break; arr[i + 1 - 1] = arr[i - 1]; ai[i + 1 - 1] = ai[i - 1]; aj[i + 1 - 1] = aj[i - 1]; @@ -308,7 +303,7 @@ static void _sort2_xkws(unsigned long n, scalar arr[], INDEX_TYPE ai[], INDEX_TY ai[i + 1 - 1] = b; aj[i + 1 - 1] = c; } - if (!jstack) { + if(!jstack) { free_ivector(istack, 1, NSTACK); return; } @@ -321,17 +316,17 @@ static void _sort2_xkws(unsigned long n, scalar arr[], INDEX_TYPE ai[], INDEX_TY SWAP(arr[k - 1], arr[l + 1 - 1]) SWAPI(ai[k - 1], ai[l + 1 - 1]) SWAPI(aj[k - 1], aj[l + 1 - 1]) - if (cmpij(ai[l + 1 - 1], aj[l + 1 - 1], ai[ir - 1], aj[ir - 1]) > 0){ + if(cmpij(ai[l + 1 - 1], aj[l + 1 - 1], ai[ir - 1], aj[ir - 1]) > 0) { SWAP(arr[l + 1 - 1], arr[ir - 1]) SWAPI(ai[l + 1 - 1], ai[ir - 1]) SWAPI(aj[l + 1 - 1], aj[ir - 1]) } - if (cmpij(ai[l - 1], aj[l - 1], ai[ir - 1], aj[ir - 1]) > 0){ + if(cmpij(ai[l - 1], aj[l - 1], ai[ir - 1], aj[ir - 1]) > 0) { SWAP(arr[l - 1], arr[ir - 1]) SWAPI(ai[l - 1], ai[ir - 1]) SWAPI(aj[l - 1], aj[ir - 1]) } - if (cmpij(ai[l + 1 - 1], aj[l + 1 - 1], ai[l - 1], aj[l - 1]) > 0){ + if(cmpij(ai[l + 1 - 1], aj[l + 1 - 1], ai[l - 1], aj[l - 1]) > 0) { SWAP(arr[l + 1 - 1], arr[l - 1]) SWAPI(ai[l + 1 - 1], ai[l - 1]) SWAPI(aj[l + 1 - 1], aj[l - 1]) @@ -341,10 +336,14 @@ static void _sort2_xkws(unsigned long n, scalar arr[], INDEX_TYPE ai[], INDEX_TY a = arr[l - 1]; b = ai[l - 1]; c = aj[l - 1]; - for (;;) { - do i++; while (cmpij(ai[i -1], aj[i -1], b, c) < 0); - do j--; while (cmpij(ai[j -1], aj[j -1], b, c) > 0); - if (j < i) break; + for(;;) { + do + i++; + while(cmpij(ai[i - 1], aj[i - 1], b, c) < 0); + do + j--; + while(cmpij(ai[j - 1], aj[j - 1], b, c) > 0); + if(j < i) break; SWAP(arr[i - 1], arr[j - 1]) SWAPI(ai[i - 1], ai[j - 1]) SWAPI(aj[i - 1], aj[j - 1]) @@ -356,11 +355,11 @@ static void _sort2_xkws(unsigned long n, scalar arr[], INDEX_TYPE ai[], INDEX_TY aj[l - 1] = aj[j - 1]; aj[j - 1] = c; jstack += 2; - if (jstack > NSTACK) { + if(jstack > NSTACK) { Msg::Fatal("NSTACK too small while sorting the columns of the matrix"); throw; } - if (ir - i + 1 >= j - l) { + if(ir - i + 1 >= j - l) { istack[jstack] = ir; istack[jstack - 1] = i; ir = j - 1; @@ -381,54 +380,56 @@ void sortColumns_(int NbLines, int nnz, INDEX_TYPE *ptr, INDEX_TYPE *jptr, // replace pointers by lines int *count = new int[NbLines]; - for(int i = 0; i < NbLines; i++){ + for(int i = 0; i < NbLines; i++) { count[i] = 0; INDEX_TYPE _position = jptr[i]; - while(1){ + while(1) { count[i]++; INDEX_TYPE _position_temp = _position; _position = ptr[_position]; ptr[_position_temp] = i; - if (_position == 0) break; + if(_position == 0) break; } } _sort2_xkws<scalar>(nnz, a, ptr, ai); jptr[0] = 0; - for(int i = 1; i <= NbLines; i++){ + for(int i = 1; i <= NbLines; i++) { jptr[i] = jptr[i - 1] + count[i - 1]; } - for(int i = 0; i < NbLines; i++){ - for (int j = jptr[i]; j < jptr[i + 1] - 1; j++){ + for(int i = 0; i < NbLines; i++) { + for(int j = jptr[i]; j < jptr[i + 1] - 1; j++) { ptr[j] = j + 1; } - if (jptr[i + 1] != jptr[i]) - ptr[jptr[i + 1] - 1] = 0; + if(jptr[i + 1] != jptr[i]) ptr[jptr[i + 1] - 1] = 0; } delete[] count; } -template<> -void linearSystemCSR<double>::getMatrix(INDEX_TYPE*& jptr,INDEX_TYPE*& ai,double*& a) +template <> +void linearSystemCSR<double>::getMatrix(INDEX_TYPE *&jptr, INDEX_TYPE *&ai, + double *&a) { - jptr = (INDEX_TYPE*) _jptr->array; - ai = (INDEX_TYPE*) _ai->array; - a = ( double * ) _a->array; - if (!sorted) - sortColumns_(_b->size(), CSRList_Nbr(_a), (INDEX_TYPE *) _ptr->array, jptr, + jptr = (INDEX_TYPE *)_jptr->array; + ai = (INDEX_TYPE *)_ai->array; + a = (double *)_a->array; + if(!sorted) + sortColumns_(_b->size(), CSRList_Nbr(_a), (INDEX_TYPE *)_ptr->array, jptr, ai, a); sorted = true; } -template<> -void linearSystemCSR<std::complex<double> >::getMatrix(INDEX_TYPE*& jptr,INDEX_TYPE*& ai,double *& a) +template <> +void linearSystemCSR<std::complex<double> >::getMatrix(INDEX_TYPE *&jptr, + INDEX_TYPE *&ai, + double *&a) { - jptr = (INDEX_TYPE*) _jptr->array; - ai = (INDEX_TYPE*) _ai->array; - a = ( double * ) _a->array; - if (!sorted) - sortColumns_(_b->size(), CSRList_Nbr(_a), (INDEX_TYPE *) _ptr->array, jptr, + jptr = (INDEX_TYPE *)_jptr->array; + ai = (INDEX_TYPE *)_ai->array; + a = (double *)_a->array; + if(!sorted) + sortColumns_(_b->size(), CSRList_Nbr(_a), (INDEX_TYPE *)_ptr->array, jptr, ai, (std::complex<double> *)a); sorted = true; } @@ -437,29 +438,27 @@ void linearSystemCSR<std::complex<double> >::getMatrix(INDEX_TYPE*& jptr,INDEX_T #include "gmm.h" -template<> -int linearSystemCSRGmm<double>::systemSolve() +template <> int linearSystemCSRGmm<double>::systemSolve() { - if (!sorted) - sortColumns_(_b->size(), - CSRList_Nbr(_a), - (INDEX_TYPE *) _ptr->array, - (INDEX_TYPE *) _jptr->array, - (INDEX_TYPE *) _ai->array, - (double*) _a->array); + if(!sorted) + sortColumns_(_b->size(), CSRList_Nbr(_a), (INDEX_TYPE *)_ptr->array, + (INDEX_TYPE *)_jptr->array, (INDEX_TYPE *)_ai->array, + (double *)_a->array); sorted = true; - gmm::csr_matrix_ref<double*, INDEX_TYPE *, INDEX_TYPE *, 0> - ref((double*)_a->array, (INDEX_TYPE *) _ai->array, - (INDEX_TYPE *)_jptr->array, _b->size(), _b->size()); + gmm::csr_matrix_ref<double *, INDEX_TYPE *, INDEX_TYPE *, 0> ref( + (double *)_a->array, (INDEX_TYPE *)_ai->array, (INDEX_TYPE *)_jptr->array, + _b->size(), _b->size()); gmm::csr_matrix<double, 0> M; M.init_with(ref); gmm::ildltt_precond<gmm::csr_matrix<double, 0> > P(M, 10, 1.e-10); gmm::iteration iter(_prec); iter.set_noisy(_noisy); - if(_gmres) gmm::gmres(M, *_x, *_b, P, 100, iter); - else gmm::cg(M, *_x, *_b, P, iter); + if(_gmres) + gmm::gmres(M, *_x, *_b, P, 100, iter); + else + gmm::cg(M, *_x, *_b, P, iter); return 1; } diff --git a/Solver/linearSystemCSR.h b/Solver/linearSystemCSR.h index b89dae72b2f028f958170861938e7ce2e38708ae..56970be0da04f465fe88f2737883b8ff37fe7edc 100644 --- a/Solver/linearSystemCSR.h +++ b/Solver/linearSystemCSR.h @@ -12,7 +12,7 @@ #include "linearSystem.h" #include "sparsityPattern.h" -typedef int INDEX_TYPE ; +typedef int INDEX_TYPE; typedef struct { int nmax; int size; @@ -23,77 +23,74 @@ typedef struct { } CSRList_T; void CSRList_Add(CSRList_T *liste, const void *data); -int CSRList_Nbr(CSRList_T *liste); +int CSRList_Nbr(CSRList_T *liste); -template <class scalar> -class linearSystemCSR : public linearSystem<scalar> { - protected: +template <class scalar> class linearSystemCSR : public linearSystem<scalar> { +protected: bool sorted; bool _entriesPreAllocated; char *something; CSRList_T *_a, *_ai, *_ptr, *_jptr; std::vector<scalar> *_b, *_x; - sparsityPattern _sparsity; // only used for pre-allocation, does not store the sparsity once allocated - public: - int getNNZ() {return CSRList_Nbr(linearSystemCSR<scalar>::_a);} - int getNbUnk() {return linearSystemCSR<scalar>::_b->size();} + sparsityPattern _sparsity; // only used for pre-allocation, does not store the + // sparsity once allocated +public: + int getNNZ() { return CSRList_Nbr(linearSystemCSR<scalar>::_a); } + int getNbUnk() { return linearSystemCSR<scalar>::_b->size(); } linearSystemCSR() - : sorted(false), _entriesPreAllocated(false), _a(0), _b(0), _x(0) {} - virtual bool isAllocated() const { return _a != 0; } - virtual void allocate(int) ; - virtual void clear() + : sorted(false), _entriesPreAllocated(false), _a(0), _b(0), _x(0) { - allocate(0); } - virtual ~linearSystemCSR() + virtual bool isAllocated() const { return _a != 0; } + virtual void allocate(int); + virtual void clear() { allocate(0); } + virtual ~linearSystemCSR() { allocate(0); } + virtual void insertInSparsityPattern(int i, int j) { - allocate(0); + _sparsity.insertEntry(i, j); } - virtual void insertInSparsityPattern (int i, int j) { - _sparsity.insertEntry (i,j); - } - virtual void preAllocateEntries (); + virtual void preAllocateEntries(); virtual void addToMatrix(int il, int ic, const scalar &val) { - if (!_entriesPreAllocated) - preAllocateEntries(); - INDEX_TYPE *jptr = (INDEX_TYPE*) _jptr->array; - INDEX_TYPE *ptr = (INDEX_TYPE*) _ptr->array; - INDEX_TYPE *ai = (INDEX_TYPE*) _ai->array; - scalar *a = ( scalar * ) _a->array; + if(!_entriesPreAllocated) preAllocateEntries(); + INDEX_TYPE *jptr = (INDEX_TYPE *)_jptr->array; + INDEX_TYPE *ptr = (INDEX_TYPE *)_ptr->array; + INDEX_TYPE *ai = (INDEX_TYPE *)_ai->array; + scalar *a = (scalar *)_a->array; - INDEX_TYPE position = jptr[il]; + INDEX_TYPE position = jptr[il]; - if (sorted) { // use bisection and direct adressing if sorted + if(sorted) { // use bisection and direct adressing if sorted int p0 = jptr[il]; - int p1 = jptr[il+1]; - while (p1-p0 > 20) { - position = ((p0+p1)/2); - if (ai[position] > ic) + int p1 = jptr[il + 1]; + while(p1 - p0 > 20) { + position = ((p0 + p1) / 2); + if(ai[position] > ic) p1 = position; - else if (ai[position] < ic) + else if(ai[position] < ic) p0 = position + 1; else { a[position] += val; return; } } - for (position = p0; position < p1; position++) { - if (ai[position] >= ic) { - if (ai[position] == ic){ + for(position = p0; position < p1; position++) { + if(ai[position] >= ic) { + if(ai[position] == ic) { a[position] += val; return; } break; } } - } else if(something[il]) { - while(1){ - if(ai[position] == ic){ + } + else if(something[il]) { + while(1) { + if(ai[position] == ic) { a[position] += val; return; } - if (ptr[position] == 0) break; + if(ptr[position] == 0) break; position = ptr[position]; } } @@ -105,9 +102,9 @@ class linearSystemCSR : public linearSystem<scalar> { // The pointers may have been modified if there has been a // reallocation in CSRList_Add - ptr = (INDEX_TYPE*) _ptr->array; - ai = (INDEX_TYPE*) _ai->array; - a = (scalar*) _a->array; + ptr = (INDEX_TYPE *)_ptr->array; + ai = (INDEX_TYPE *)_ai->array; + a = (scalar *)_a->array; INDEX_TYPE n = CSRList_Nbr(_a) - 1; @@ -115,57 +112,58 @@ class linearSystemCSR : public linearSystem<scalar> { jptr[il] = n; something[il] = 1; } - else ptr[position] = n; + else + ptr[position] = n; } - virtual void getMatrix(INDEX_TYPE*& jptr,INDEX_TYPE*& ai,double*& a); + virtual void getMatrix(INDEX_TYPE *&jptr, INDEX_TYPE *&ai, double *&a); - virtual void getFromMatrix (int row, int col, scalar &val) const + virtual void getFromMatrix(int row, int col, scalar &val) const { Msg::Error("getFromMatrix not implemented for CSR"); } virtual void addToRightHandSide(int row, const scalar &val, int ith = 0) { - if (!_b) return; + if(!_b) return; if(val != scalar()) (*_b)[row] += val; } virtual void addToSolution(int row, const scalar &val) { - if (!_x) return; + if(!_x) return; if(val != scalar()) (*_x)[row] += val; } virtual void getFromRightHandSide(int row, scalar &val) const { - if (!_b) return; + if(!_b) return; val = (*_b)[row]; } virtual void getFromSolution(int row, scalar &val) const { - if (!_x) return; + if(!_x) return; val = (*_x)[row]; } virtual void zeroMatrix() { - if (!_a) return; + if(!_a) return; int N = CSRList_Nbr(_a); - scalar *a = (scalar*) _a->array; - for (int i = 0; i < N; i++) a[i] = scalar(); + scalar *a = (scalar *)_a->array; + for(int i = 0; i < N; i++) a[i] = scalar(); } virtual void zeroRightHandSide() { - if (!_b) return; + if(!_b) return; for(unsigned int i = 0; i < _b->size(); i++) (*_b)[i] = scalar(); } virtual void zeroSolution() { - if (!_x) return; + if(!_x) return; for(unsigned int i = 0; i < _x->size(); i++) (*_x)[i] = scalar(); } virtual double normInfRightHandSide() const { - if (!_b) return 0.; + if(!_b) return 0.; double nor = 0.; double temp; - for(unsigned int i = 0; i < _b->size(); i++){ + for(unsigned int i = 0; i < _b->size(); i++) { temp = std::abs((*_b)[i]); if(nor < temp) nor = temp; } @@ -175,15 +173,16 @@ class linearSystemCSR : public linearSystem<scalar> { template <class scalar> class linearSystemCSRGmm : public linearSystemCSR<scalar> { - private: +private: double _prec; int _noisy, _gmres; - public: + +public: linearSystemCSRGmm() : _prec(1.e-8), _noisy(0), _gmres(0) {} - virtual ~linearSystemCSRGmm(){} - void setPrec(double p){ _prec = p; } - void setNoisy(int n){ _noisy = n; } - void setGmres(int n){ _gmres = n; } + virtual ~linearSystemCSRGmm() {} + void setPrec(double p) { _prec = p; } + void setNoisy(int n) { _noisy = n; } + void setGmres(int n) { _gmres = n; } virtual int systemSolve() #if !defined(HAVE_GMM) { diff --git a/Solver/linearSystemFull.h b/Solver/linearSystemFull.h index 974d24d2a5096008225f13056cb7f64fac67bd76..406fad19426d05831aeb63050ed4a9698bf6cffb 100644 --- a/Solver/linearSystemFull.h +++ b/Solver/linearSystemFull.h @@ -14,13 +14,13 @@ #include <stdlib.h> #include <set> -template <class scalar> -class linearSystemFull : public linearSystem<scalar> { - private: +template <class scalar> class linearSystemFull : public linearSystem<scalar> { +private: fullMatrix<scalar> *_a; fullVector<scalar> *_b, *_x; - public : - linearSystemFull() : _a(0), _b(0), _x(0){} + +public: + linearSystemFull() : _a(0), _b(0), _x(0) {} virtual bool isAllocated() const { return _a != 0; } virtual void allocate(int nbRows) { @@ -29,13 +29,10 @@ class linearSystemFull : public linearSystem<scalar> { _b = new fullVector<scalar>(nbRows); _x = new fullVector<scalar>(nbRows); } - virtual ~linearSystemFull() - { - clear(); - } + virtual ~linearSystemFull() { clear(); } virtual void clear() { - if(_a){ + if(_a) { delete _a; delete _b; delete _x; @@ -50,7 +47,7 @@ class linearSystemFull : public linearSystem<scalar> { { val = (*_a)(row, col); } - virtual void addToRightHandSide(int row, const scalar &val, int ith=0) + virtual void addToRightHandSide(int row, const scalar &val, int ith = 0) { if(val != 0.0) (*_b)(row) += val; } @@ -62,36 +59,24 @@ class linearSystemFull : public linearSystem<scalar> { { val = (*_b)(row); } - virtual void getFromSolution(int row, scalar &val) const - { - val = (*_x)(row); - } - virtual void zeroMatrix() + virtual void getFromSolution(int row, scalar &val) const { val = (*_x)(row); } + virtual void zeroMatrix() { _a->setAll(0.); } + virtual void zeroRightHandSide() { _b->setAll(0.); } + virtual void zeroSolution() { _x->setAll(0.); } + virtual double normInfRightHandSide() const { - _a->setAll(0.); - } - virtual void zeroRightHandSide() - { - _b->setAll(0.); - } - virtual void zeroSolution() - { - _x->setAll(0.); - } - virtual double normInfRightHandSide() const{ double nor = 0.; double temp; - for(int i=0;i<_b->size();i++){ + for(int i = 0; i < _b->size(); i++) { temp = (*_b)(i); - if(temp<0) temp = -temp; - if(nor<temp) nor=temp; + if(temp < 0) temp = -temp; + if(nor < temp) nor = temp; } return nor; } virtual int systemSolve() { - if (_b->size()) - _a->luSolve(*_b, *_x); + if(_b->size()) _a->luSolve(*_b, *_x); // _x->print("X in solve"); return 1; } diff --git a/Solver/linearSystemGMM.h b/Solver/linearSystemGMM.h index 6f7082a3418a019d61379c36b3f3ec528c223dcd..038753980322f5c9e67aab631e6092e4b6ebf771 100644 --- a/Solver/linearSystemGMM.h +++ b/Solver/linearSystemGMM.h @@ -15,33 +15,31 @@ #if defined(HAVE_GMM) #include <gmm.h> -template <class scalar> -class linearSystemGmm : public linearSystem<scalar> { - protected: - std::vector<scalar> *_x; // the nonLinearSystemGmm has to access to this vector +template <class scalar> class linearSystemGmm : public linearSystem<scalar> { +protected: + std::vector<scalar> + *_x; // the nonLinearSystemGmm has to access to this vector std::vector<scalar> *_b; // idem gmm::row_matrix<gmm::wsvector<scalar> > *_a; - private: + +private: double _prec; int _noisy, _gmres; - public: - linearSystemGmm() - : _x(0), _b(0), _a(0), _prec(1.e-8), _noisy(0), _gmres(0) {} + +public: + linearSystemGmm() : _x(0), _b(0), _a(0), _prec(1.e-8), _noisy(0), _gmres(0) {} virtual bool isAllocated() const { return _a != 0; } virtual void allocate(int nbRows) { clear(); - _a = new gmm::row_matrix< gmm::wsvector<scalar> >(nbRows, nbRows); + _a = new gmm::row_matrix<gmm::wsvector<scalar> >(nbRows, nbRows); _b = new std::vector<scalar>(nbRows); _x = new std::vector<scalar>(nbRows); } - virtual ~linearSystemGmm() - { - clear(); - } + virtual ~linearSystemGmm() { clear(); } virtual void clear() { - if (_a){ + if(_a) { delete _a; delete _b; delete _x; @@ -49,11 +47,11 @@ class linearSystemGmm : public linearSystem<scalar> { _a = 0; } - virtual void addToMatrix(int row, int col, const scalar &val) + virtual void addToMatrix(int row, int col, const scalar &val) { if(val != 0.0) (*_a)(row, col) += val; } - virtual void getFromMatrix (int row, int col, scalar &val) const + virtual void getFromMatrix(int row, int col, scalar &val) const { val = (*_a)(row, col); } @@ -73,14 +71,8 @@ class linearSystemGmm : public linearSystem<scalar> { if(val != 0.0) (*_x)[row] += val; } - virtual void getFromSolution(int row, scalar &val) const - { - val = (*_x)[row]; - } - virtual void zeroMatrix() - { - gmm::clear(*_a); - } + virtual void getFromSolution(int row, scalar &val) const { val = (*_x)[row]; } + virtual void zeroMatrix() { gmm::clear(*_a); } virtual void zeroRightHandSide() { for(unsigned int i = 0; i < _b->size(); i++) (*_b)[i] = 0.; @@ -90,31 +82,36 @@ class linearSystemGmm : public linearSystem<scalar> { for(unsigned int i = 0; i < _x->size(); i++) (*_x)[i] = 0.; } - virtual double normInfRightHandSide() const { + virtual double normInfRightHandSide() const + { double nor = 0.; double temp; - for(unsigned int i=0;i<_b->size();i++){ + for(unsigned int i = 0; i < _b->size(); i++) { temp = abs((*_b)[i]); // this is valid also for complex - //if(temp<0) temp = -temp; - if(nor<temp) nor=temp; + // if(temp<0) temp = -temp; + if(nor < temp) nor = temp; } return nor; } - void setPrec(double p){ _prec = p; } - void setNoisy(int n){ _noisy = n; } - void setGmres(int n){ _gmres = n; } + void setPrec(double p) { _prec = p; } + void setNoisy(int n) { _noisy = n; } + void setGmres(int n) { _gmres = n; } virtual int systemSolve() { #if defined(HAVE_MUMPS) gmm::MUMPS_solve(*_a, *_x, *_b); #else - //gmm::ilutp_precond<gmm::row_matrix<gmm::wsvector<scalar> > > P(*_a, 25, 0.); - gmm::ildltt_precond<gmm::row_matrix<gmm::wsvector<scalar> > > P(*_a, 30, 1.e-10); + // gmm::ilutp_precond<gmm::row_matrix<gmm::wsvector<scalar> > > P(*_a, 25, + // 0.); + gmm::ildltt_precond<gmm::row_matrix<gmm::wsvector<scalar> > > P(*_a, 30, + 1.e-10); gmm::iteration iter(_prec); iter.set_noisy(_noisy); - if(_gmres) gmm::gmres(*_a, *_x, *_b, P, 100, iter); - else gmm::cg(*_a, *_x, *_b, P, iter); + if(_gmres) + gmm::gmres(*_a, *_x, *_b, P, 100, iter); + else + gmm::cg(*_a, *_x, *_b, P, iter); #endif return 1; } @@ -122,9 +119,8 @@ class linearSystemGmm : public linearSystem<scalar> { #else -template <class scalar> -class linearSystemGmm : public linearSystem<scalar> { - public : +template <class scalar> class linearSystemGmm : public linearSystem<scalar> { +public: linearSystemGmm() { Msg::Error("Gmm++ is not available in this version of Gmsh"); @@ -142,10 +138,10 @@ class linearSystemGmm : public linearSystem<scalar> { virtual void zeroSolution() {} virtual int systemSolve() { return 0; } virtual double normInfRightHandSide() const { return 0.; } - void setPrec(double p){} - virtual void clear(){} - void setNoisy(int n){} - void setGmres(int n){} + void setPrec(double p) {} + virtual void clear() {} + void setNoisy(int n) {} + void setGmres(int n) {} }; #endif diff --git a/Solver/linearSystemMUMPS.cpp b/Solver/linearSystemMUMPS.cpp index 6116008ec103197f64e0aef1224614c8d5c3ec23..2a8dd13805dc105d8d6d7f015b3c49a313aa4fb9 100644 --- a/Solver/linearSystemMUMPS.cpp +++ b/Solver/linearSystemMUMPS.cpp @@ -3,7 +3,6 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to the public mailing list <gmsh@onelab.info>. - #include <stdio.h> #include <math.h> #include "linearSystemMUMPS.h" @@ -17,23 +16,14 @@ void mumpserror(int id, int subid) if(id < 0) { Msg::Error("MUMPS INFO(1) = %d, INFO(2) = %d", id, subid); - switch (id) { + switch(id) { case -6: - Msg::Error("Matrix is singular in structure, structural rank: %d", - subid); - break; - case -10: - Msg::Error("Matrix is numerically singular"); - break; - case -13 : - Msg::Error("Not enough memory"); - break; - case -40 : - Msg::Error("Matrix is not symmetric positive definite"); - break; - default: - Msg::Error("Check MUMPS user's guide"); + Msg::Error("Matrix is singular in structure, structural rank: %d", subid); break; + case -10: Msg::Error("Matrix is numerically singular"); break; + case -13: Msg::Error("Not enough memory"); break; + case -40: Msg::Error("Matrix is not symmetric positive definite"); break; + default: Msg::Error("Check MUMPS user's guide"); break; } } } @@ -46,8 +36,10 @@ linearSystemMUMPS<double>::linearSystemMUMPS() bool linearSystemMUMPS<double>::isAllocated() const { - if (_n > 0) return true; - else return false; + if(_n > 0) + return true; + else + return false; } void linearSystemMUMPS<double>::allocate(int nbRows) @@ -55,9 +47,9 @@ void linearSystemMUMPS<double>::allocate(int nbRows) _n = nbRows; _b.resize(_n); _x.resize(_n); - _a.reserve(10*_n); - _irn.reserve(10*_n); - _jcn.reserve(10*_n); + _a.reserve(10 * _n); + _irn.reserve(10 * _n); + _jcn.reserve(10 * _n); _ij.reserve(_n); } @@ -84,12 +76,12 @@ void linearSystemMUMPS<double>::zeroMatrix() void linearSystemMUMPS<double>::zeroRightHandSide() { - for(unsigned int i=0; i < _b.size(); i++) _b[i] = 0.; + for(unsigned int i = 0; i < _b.size(); i++) _b[i] = 0.; } void linearSystemMUMPS<double>::zeroSolution() { - for(unsigned int i=0; i < _x.size(); i++) _x[i] = 0.; + for(unsigned int i = 0; i < _x.size(); i++) _x[i] = 0.; } int linearSystemMUMPS<double>::systemSolve() @@ -101,34 +93,37 @@ int linearSystemMUMPS<double>::systemSolve() id.par = 1; const std::string sym = getParameter("symmetry"); - if(sym == "spd") id.sym = 1; - else if(sym == "symmetric") id.sym = 2; - else id.sym = 0; + if(sym == "spd") + id.sym = 1; + else if(sym == "symmetric") + id.sym = 2; + else + id.sym = 0; id.comm_fortran = USE_COMM_WORLD; Msg::Debug("MUMPS initialization"); - id.job=-1; + id.job = -1; dmumps_c(&id); mumpserror(id.info[0], id.info[1]); id.n = _n; id.nz = _nz; // Fortran indices start from 1 - for(unsigned int i=0; i < _irn.size(); i++) _irn[i]++; - for(unsigned int i=0; i < _jcn.size(); i++) _jcn[i]++; - id.irn= &*_irn.begin(); - id.jcn= &*_jcn.begin(); + for(unsigned int i = 0; i < _irn.size(); i++) _irn[i]++; + for(unsigned int i = 0; i < _jcn.size(); i++) _jcn[i]++; + id.irn = &*_irn.begin(); + id.jcn = &*_jcn.begin(); id.a = &*_a.begin(); id.rhs = &*_b.begin(); // Fortran indices start from 1 - id.icntl[1-1]=-1; - id.icntl[2-1]=-1; - id.icntl[3-1]=-1; - id.icntl[4-1]=0; - id.icntl[5-1]=0; - id.icntl[18-1]=0; + id.icntl[1 - 1] = -1; + id.icntl[2 - 1] = -1; + id.icntl[3 - 1] = -1; + id.icntl[4 - 1] = 0; + id.icntl[5 - 1] = 0; + id.icntl[18 - 1] = 0; Msg::Debug("MUMPS analysis, LU factorization, and back substitution"); id.job = 6; @@ -136,7 +131,7 @@ int linearSystemMUMPS<double>::systemSolve() mumpserror(id.info[0], id.info[1]); Msg::Debug("MUMPS destroy"); - id.job=-2; + id.job = -2; dmumps_c(&id); Msg::Debug("MUMPS end"); mumpserror(id.info[0], id.info[1]); @@ -144,21 +139,18 @@ int linearSystemMUMPS<double>::systemSolve() _x.clear(); _x = _b; _b = b; - for(unsigned int i=0; i < _irn.size(); i++) _irn[i]--; - for(unsigned int i=0; i < _jcn.size(); i++) _jcn[i]--; + for(unsigned int i = 0; i < _irn.size(); i++) _irn[i]--; + for(unsigned int i = 0; i < _jcn.size(); i++) _jcn[i]--; return 1; } -void linearSystemMUMPS<double>::insertInSparsityPattern(int row, int col) -{ - -} +void linearSystemMUMPS<double>::insertInSparsityPattern(int row, int col) {} double linearSystemMUMPS<double>::normInfRightHandSide() const { DMUMPS_REAL norm = 0.; - for(unsigned int i=0; i < _b.size(); i++) { + for(unsigned int i = 0; i < _b.size(); i++) { DMUMPS_REAL temp = fabs(_b[i]); if(temp > norm) norm = temp; } @@ -168,7 +160,7 @@ double linearSystemMUMPS<double>::normInfRightHandSide() const double linearSystemMUMPS<double>::normInfSolution() const { DMUMPS_REAL norm = 0.; - for(unsigned int i=0; i < _x.size(); i++) { + for(unsigned int i = 0; i < _x.size(); i++) { DMUMPS_REAL temp = fabs(_x[i]); if(temp > norm) norm = temp; } @@ -186,8 +178,8 @@ void linearSystemMUMPS<double>::addToMatrix(int row, int col, const double &val) _a.push_back(val); _irn.push_back(row); _jcn.push_back(col); - _ij.resize(row+1); - _ij[row][col] = _a.size()-1; + _ij.resize(row + 1); + _ij[row][col] = _a.size() - 1; _nz++; return; } @@ -196,7 +188,7 @@ void linearSystemMUMPS<double>::addToMatrix(int row, int col, const double &val) _a.push_back(val); _irn.push_back(row); _jcn.push_back(col); - _ij[row][col] = _a.size()-1; + _ij[row][col] = _a.size() - 1; _nz++; } else { @@ -204,23 +196,27 @@ void linearSystemMUMPS<double>::addToMatrix(int row, int col, const double &val) } } -void linearSystemMUMPS<double>::getFromMatrix(int row, int col, double &val) const +void linearSystemMUMPS<double>::getFromMatrix(int row, int col, + double &val) const { - //Msg::Error("getFromMatrix not implemented for linearSystemMUMPS"); + // Msg::Error("getFromMatrix not implemented for linearSystemMUMPS"); if((int)_ij.size() <= row) { val = 0.; return; } std::map<int, int>::const_iterator it = _ij[row].find(col); - if(it == _ij[row].end()) val = 0.; - else val = _a[it->second]; + if(it == _ij[row].end()) + val = 0.; + else + val = _a[it->second]; } -void linearSystemMUMPS<double>::addToRightHandSide(int row, const double &val, int ith) +void linearSystemMUMPS<double>::addToRightHandSide(int row, const double &val, + int ith) { // printf("adding %g to %d\n",val,row); if((int)_b.size() <= row) { - _b.resize(row+1); + _b.resize(row + 1); _b[row] = val; } else { @@ -237,14 +233,16 @@ void linearSystemMUMPS<double>::getFromRightHandSide(int row, double &val) const void linearSystemMUMPS<double>::getFromSolution(int row, double &val) const { // printf("x[%d] = %g\n",row,_x[row]); - if((int)_x.size() <= row) val = 0.; - else val = _x[row]; + if((int)_x.size() <= row) + val = 0.; + else + val = _x[row]; } void linearSystemMUMPS<double>::addToSolution(int row, const double &val) { if((int)_x.size() <= row) { - _x.resize(row+1); + _x.resize(row + 1); _x[row] = val; } else { diff --git a/Solver/linearSystemMUMPS.h b/Solver/linearSystemMUMPS.h index eec3534b358ea3217828ae137bd094a71b49c8b9..5f33d9299dbdf067a6ab5d661d3f29d6d63d60e1 100644 --- a/Solver/linearSystemMUMPS.h +++ b/Solver/linearSystemMUMPS.h @@ -16,25 +16,23 @@ #include "dmumps_c.h" #include "zmumps_c.h" -template <class scalar> -class linearSystemMUMPS : public linearSystem<scalar> { - - public: +template <class scalar> class linearSystemMUMPS : public linearSystem<scalar> { +public: linearSystemMUMPS() { Msg::Info("linearSystemMUMPS not implemented for this element type"); } - virtual bool isAllocated() const {return false;} + virtual bool isAllocated() const { return false; } virtual void allocate(int nbRows) {} virtual void clear() {} virtual void zeroMatrix() {} virtual void zeroRightHandSide() {} virtual void zeroSolution() {} - virtual int systemSolve() {return 1;} + virtual int systemSolve() { return 1; } virtual void insertInSparsityPattern(int row, int col) {} - virtual double normInfRightHandSide() const {return 0.;} - virtual double normInfSolution() const {return 0.;} + virtual double normInfRightHandSide() const { return 0.; } + virtual double normInfSolution() const { return 0.; } virtual void addToMatrix(int row, int col, const double &val) {} virtual void getFromMatrix(int row, int col, double &val) const {} @@ -42,13 +40,10 @@ class linearSystemMUMPS : public linearSystem<scalar> { virtual void getFromRightHandSide(int row, scalar &val) const {} virtual void getFromSolution(int row, scalar &val) const {} virtual void addToSolution(int row, const scalar &val) {} - }; -template <> -class linearSystemMUMPS<double> : public linearSystem<double> { - private: - +template <> class linearSystemMUMPS<double> : public linearSystem<double> { +private: int _n; int _nz; @@ -61,9 +56,9 @@ class linearSystemMUMPS<double> : public linearSystem<double> { // _ij[i][j] is the index of _a that is the (i, j) element of // the system matrix - std::vector<std::map<int,int> > _ij; + std::vector<std::map<int, int> > _ij; - public: +public: linearSystemMUMPS(); virtual bool isAllocated() const; @@ -84,7 +79,6 @@ class linearSystemMUMPS<double> : public linearSystem<double> { virtual void getFromRightHandSide(int row, double &val) const; virtual void getFromSolution(int row, double &val) const; virtual void addToSolution(int row, const double &val); - }; #endif diff --git a/Solver/linearSystemPETSc.cpp b/Solver/linearSystemPETSc.cpp index 0ed1c6d5d6984d9433422246301896a2bb8861f9..d4ec4db43719df692ac62ba4fd5b68c900f2e4ee 100644 --- a/Solver/linearSystemPETSc.cpp +++ b/Solver/linearSystemPETSc.cpp @@ -16,11 +16,11 @@ template class linearSystemPETSc<double>; - #ifdef PETSC_USE_COMPLEX template class linearSystemPETSc<std::complex<double> >; -// this specialization will cast to a double (take the real part) if "val" is a double wheras Petsc is built in complex mode. +// this specialization will cast to a double (take the real part) if "val" is a +// double wheras Petsc is built in complex mode. template <> void linearSystemPETSc<double>::getFromRightHandSide(int row, double &val) const { @@ -31,7 +31,8 @@ void linearSystemPETSc<double>::getFromRightHandSide(int row, double &val) const val = s.real(); } -// this specialization will cast to a double (take the real part) if "val" is a double wheras Petsc is built in complex mode. +// this specialization will cast to a double (take the real part) if "val" is a +// double wheras Petsc is built in complex mode. template <> void linearSystemPETSc<double>::getFromSolution(int row, double &val) const { @@ -43,97 +44,97 @@ void linearSystemPETSc<double>::getFromSolution(int row, double &val) const } #endif -template<> +template <> int linearSystemPETSc<fullMatrix<double> >::_getBlockSizeFromParameters() const { - if ( _parameters.find("blockSize") == _parameters.end()) - Msg::Error ("'blockSize' parameters must be set for linearSystemPETScBlock"); - int blockSize = strtol(_parameters.find("blockSize")->second.c_str(), NULL, 10); + if(_parameters.find("blockSize") == _parameters.end()) + Msg::Error("'blockSize' parameters must be set for linearSystemPETScBlock"); + int blockSize = + strtol(_parameters.find("blockSize")->second.c_str(), NULL, 10); return blockSize; } - -template<> -void linearSystemPETSc<fullMatrix<double> >::addToMatrix(int row, int col, - const fullMatrix<double> &val) +template <> +void linearSystemPETSc<fullMatrix<double> >::addToMatrix( + int row, int col, const fullMatrix<double> &val) { - if (!_entriesPreAllocated) - preAllocateEntries(); + if(!_entriesPreAllocated) preAllocateEntries(); PetscInt i = row, j = col; - #ifdef PETSC_USE_COMPLEX +#ifdef PETSC_USE_COMPLEX fullMatrix<std::complex<double> > modval(val.size1(), val.size2()); - for (int ii = 0; ii < val.size1(); ii++) { - for (int jj = 0; jj < val.size1(); jj++) { - modval(ii, jj) = val (ii, jj); + for(int ii = 0; ii < val.size1(); ii++) { + for(int jj = 0; jj < val.size1(); jj++) { + modval(ii, jj) = val(ii, jj); } } MatSetValuesBlocked(_a, 1, &i, 1, &j, modval.getDataPtr(), ADD_VALUES); - #else +#else MatSetValuesBlocked(_a, 1, &i, 1, &j, val.getDataPtr(), ADD_VALUES); - #endif +#endif _valuesNotAssembled = true; } -template<> -void linearSystemPETSc<fullMatrix<double> >::addToRightHandSide(int row, - const fullMatrix<double> &val, int ith) +template <> +void linearSystemPETSc<fullMatrix<double> >::addToRightHandSide( + int row, const fullMatrix<double> &val, int ith) { - if (!_entriesPreAllocated) - preAllocateEntries(); + if(!_entriesPreAllocated) preAllocateEntries(); int blockSize; _try(MatGetBlockSize(_a, &blockSize)); - for (int ii = 0; ii < blockSize; ii++) { + for(int ii = 0; ii < blockSize; ii++) { PetscInt i = row * blockSize + ii; PetscScalar v = val(ii, 0); VecSetValues(_b, 1, &i, &v, ADD_VALUES); } } -template<> -void linearSystemPETSc<fullMatrix<double > >::getFromRightHandSide(int row, - fullMatrix<double> &val) const +template <> +void linearSystemPETSc<fullMatrix<double> >::getFromRightHandSide( + int row, fullMatrix<double> &val) const { int blockSize; _try(MatGetBlockSize(_a, &blockSize)); - for (int i = 0; i < blockSize; i++) { - int ii = row*blockSize +i; - #ifdef PETSC_USE_COMPLEX + for(int i = 0; i < blockSize; i++) { + int ii = row * blockSize + i; +#ifdef PETSC_USE_COMPLEX PetscScalar s; - VecGetValues ( _b, 1, &ii, &s); - val(i,0) = s.real(); - #else - VecGetValues ( _b, 1, &ii, &val(i,0)); - #endif + VecGetValues(_b, 1, &ii, &s); + val(i, 0) = s.real(); +#else + VecGetValues(_b, 1, &ii, &val(i, 0)); +#endif } } -template<> -void linearSystemPETSc<fullMatrix<double> >::addToSolution(int row, const fullMatrix<double> &val) +template <> +void linearSystemPETSc<fullMatrix<double> >::addToSolution( + int row, const fullMatrix<double> &val) { int blockSize; _try(MatGetBlockSize(_a, &blockSize)); - for (int ii = 0; ii < blockSize; ii++) { + for(int ii = 0; ii < blockSize; ii++) { PetscInt i = row * blockSize + ii; PetscScalar v = val(ii, 0); VecSetValues(_x, 1, &i, &v, ADD_VALUES); } } -template<> -void linearSystemPETSc<fullMatrix<double> >::getFromSolution(int row, fullMatrix<double> &val) const +template <> +void linearSystemPETSc<fullMatrix<double> >::getFromSolution( + int row, fullMatrix<double> &val) const { int blockSize; _try(MatGetBlockSize(_a, &blockSize)); - for (int i = 0; i < blockSize; i++) { - int ii = row*blockSize +i; - #ifdef PETSC_USE_COMPLEX + for(int i = 0; i < blockSize; i++) { + int ii = row * blockSize + i; +#ifdef PETSC_USE_COMPLEX PetscScalar s; - VecGetValues ( _x, 1, &ii, &s); - val(i,0) = s.real(); - #else - VecGetValues ( _x, 1, &ii, &val(i,0)); - #endif + VecGetValues(_x, 1, &ii, &s); + val(i, 0) = s.real(); +#else + VecGetValues(_x, 1, &ii, &val(i, 0)); +#endif } } diff --git a/Solver/linearSystemPETSc.h b/Solver/linearSystemPETSc.h index b3fd996e3afcb4e679049ab57e3c89518582c0bc..3c638ef369adee87f1aab7642bfa28a483ef3508 100644 --- a/Solver/linearSystemPETSc.h +++ b/Solver/linearSystemPETSc.h @@ -48,13 +48,15 @@ #include "petsc.h" #include "petscksp.h" #else -typedef struct _p_Mat* Mat; -typedef struct _p_Vec* Vec; -typedef struct _p_KSP* KSP; +typedef struct _p_Mat *Mat; +typedef struct _p_Vec *Vec; +typedef struct _p_KSP *KSP; #endif -//support old PETSc version, try to avoid using PETSC_VERSION in other places -#if PETSC_VERSION_RELEASE != 0 && (PETSC_VERSION_MAJOR < 3 || (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR < 2)) +// support old PETSc version, try to avoid using PETSC_VERSION in other places +#if PETSC_VERSION_RELEASE != 0 && \ + (PETSC_VERSION_MAJOR < 3 || \ + (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR < 2)) #define KSPDestroy(k) KSPDestroy(*(k)) #define MatDestroy(m) MatDestroy(*(m)) #define VecDestroy(v) VecDestroy(*(v)) @@ -64,31 +66,41 @@ typedef struct _p_KSP* KSP; #endif // The petsc3.5 change log says: -// "KSPSetOperators() no longer has the MatStructure argument. The Mat objects now track that information themselves. -// Use KPS/PCSetReusePreconditioner() to prevent the recomputation of the preconditioner if the operator changed -// in the way that SAME_PRECONDITIONER did with KSPSetOperators()" -// So I guess this should be called with PETSC_TRUE as second argument only for SAME_PRECONDITIONER -// and false otherwise (i.e. for SAME_NONZERO_PATTERN, DIFFRENT_NONZERO_PATTERN) but it is a guess... -#if (PETSC_VERSION_MAJOR < 3 || (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR < 5)) -#define KSPSetOperators(_ksp, _a, _b, SAME_PRECONDITIONER) KSPSetOperators(_ksp, _a, _b, SAME_PRECONDITIONER) +// "KSPSetOperators() no longer has the MatStructure argument. The Mat objects +// now track that information themselves. Use KPS/PCSetReusePreconditioner() to +// prevent the recomputation of the preconditioner if the operator changed in +// the way that SAME_PRECONDITIONER did with KSPSetOperators()" So I guess this +// should be called with PETSC_TRUE as second argument only for +// SAME_PRECONDITIONER and false otherwise (i.e. for SAME_NONZERO_PATTERN, +// DIFFRENT_NONZERO_PATTERN) but it is a guess... +#if(PETSC_VERSION_MAJOR < 3 || \ + (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR < 5)) +#define KSPSetOperators(_ksp, _a, _b, SAME_PRECONDITIONER) \ + KSPSetOperators(_ksp, _a, _b, SAME_PRECONDITIONER) #else -# define SAME_PRECONDITIONER 999 -# define KSPSetOperators(_ksp, _a, _b, OPT_PRECON) (KSPSetOperators(_ksp, _a, _b), KSPSetReusePreconditioner(_ksp,PetscBool(OPT_PRECON == SAME_PRECONDITIONER))) +#define SAME_PRECONDITIONER 999 +#define KSPSetOperators(_ksp, _a, _b, OPT_PRECON) \ + (KSPSetOperators(_ksp, _a, _b), \ + KSPSetReusePreconditioner(_ksp, \ + PetscBool(OPT_PRECON == SAME_PRECONDITIONER))) #endif // Deprecated method PetscViewerSetFormat starts 3.7 the only instance we use -// can be replaced by PetscViewerPushFormat as we do not change the format of the same viewer -// in such a case PetscViewerPopFormat should be used and the following will not work -#if (PETSC_VERSION_MAJOR < 3 || (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR < 7)) -#define PetscViewerPushFormat(viewer , format) PetscViewerSetFormat(viewer , format) +// can be replaced by PetscViewerPushFormat as we do not change the format of +// the same viewer in such a case PetscViewerPopFormat should be used and the +// following will not work +#if(PETSC_VERSION_MAJOR < 3 || \ + (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR < 7)) +#define PetscViewerPushFormat(viewer, format) \ + PetscViewerSetFormat(viewer, format) #endif -template <class scalar> -class linearSystemPETSc : public linearSystem<scalar> { - protected: +template <class scalar> class linearSystemPETSc : public linearSystem<scalar> { +protected: bool _isAllocated, _kspAllocated, _entriesPreAllocated; bool _matrixChangedSinceLastSolve; - bool _valuesNotAssembled; //cannot use MatAssembled since MatAssembled return false for an empty matrix + bool _valuesNotAssembled; // cannot use MatAssembled since MatAssembled return + // false for an empty matrix Mat _a; Vec _b, _x; KSP _ksp; @@ -96,20 +108,21 @@ class linearSystemPETSc : public linearSystem<scalar> { sparsityPattern _sparsity; void _kspCreate(); void _assembleMatrixIfNeeded(); - #ifndef SWIG +#ifndef SWIG MPI_Comm _comm; - #endif +#endif int _getBlockSizeFromParameters() const; - public: + +public: ~linearSystemPETSc(); - void insertInSparsityPattern (int i, int j); + void insertInSparsityPattern(int i, int j); bool isAllocated() const { return _isAllocated; } void preAllocateEntries(); virtual void allocate(int nbRows); void print(); void clear(); void getFromMatrix(int row, int col, scalar &val) const; - void addToRightHandSide(int row, const scalar &val, int ith=0); + void addToRightHandSide(int row, const scalar &val, int ith = 0); void getFromRightHandSide(int row, scalar &val) const; double normInfRightHandSide() const; int getNumKspIteration() const; @@ -121,42 +134,41 @@ class linearSystemPETSc : public linearSystem<scalar> { void zeroSolution(); void printMatlab(const char *filename) const; virtual int systemSolve(); - Mat getMatrix(){ return _a; } + Mat getMatrix() { return _a; } virtual int matMult(); - //std::vector<scalar> getData(); - //std::vector<int> getRowPointers(); - //std::vector<int> getColumnsIndices(); - #ifndef SWIG +// std::vector<scalar> getData(); +// std::vector<int> getRowPointers(); +// std::vector<int> getColumnsIndices(); +#ifndef SWIG linearSystemPETSc(MPI_Comm com); - MPI_Comm getComm() const {return _comm;} - #endif + MPI_Comm getComm() const { return _comm; } +#endif linearSystemPETSc(); }; #else -template <class scalar> -class linearSystemPETSc : public linearSystem<scalar> { - public : +template <class scalar> class linearSystemPETSc : public linearSystem<scalar> { +public: linearSystemPETSc() { Msg::Error("PETSc is not available in this version of Gmsh"); } bool isAllocated() const { return false; } void allocate(int nbRows) {} - void clear(){} + void clear() {} void addToMatrix(int row, int col, const scalar &val) {} void getFromMatrix(int row, int col, scalar &val) const {} void addToRightHandSide(int row, const scalar &val, int ith = 0) {} void addToSolution(int row, const scalar &val) {} void getFromRightHandSide(int row, scalar &val) const {} void getFromSolution(int row, scalar &val) const {} - int getNumKspIteration() const {return 0;}; + int getNumKspIteration() const { return 0; }; void zeroMatrix() {} void zeroRightHandSide() {} void zeroSolution() {} - void printMatlab(const char *filename) const{}; + void printMatlab(const char *filename) const {}; virtual int systemSolve() { return 0; } - double normInfRightHandSide() const{return 0;} + double normInfRightHandSide() const { return 0; } virtual int matMult() { return 0; } }; #endif diff --git a/Solver/materialLaw.h b/Solver/materialLaw.h index acad9ac11a764ee1d1a18cf65326824ce08f631f..56c25564650d2b843f3f4cb3c09740446a881535 100644 --- a/Solver/materialLaw.h +++ b/Solver/materialLaw.h @@ -10,13 +10,9 @@ #ifndef _MATERIALLAW_H_ #define _MATERIALLAW_H_ -class Material -{ - public: +class Material { +public: virtual ~Material() {} - }; - - #endif //_MATERIALLAW_H_ diff --git a/Solver/orthogonalTerm.h b/Solver/orthogonalTerm.h index 5565cf193579c31d48b875fd220ede3e7396ed2a..30d5de5e0090763b5791cc4018fb596457f7587a 100644 --- a/Solver/orthogonalTerm.h +++ b/Solver/orthogonalTerm.h @@ -10,72 +10,82 @@ #include "dofManager.h" class orthogonalTerm : public helmholtzTerm<double> { - protected: +protected: PView *_pview; dofManager<double> *_dofView; bool withDof; - std::map<MVertex*, double > *_distance_map; - public: + std::map<MVertex *, double> *_distance_map; + +public: orthogonalTerm(GModel *gm, int iField, simpleFunction<double> *k, - std::map<MVertex*, double > *distance_map) + std::map<MVertex *, double> *distance_map) : helmholtzTerm<double>(gm, iField, iField, k, 0), _pview(0), _dofView(0), - withDof(false), _distance_map(distance_map) {} - orthogonalTerm(GModel *gm, int iField, simpleFunction<double> *k, PView *pview) - : helmholtzTerm<double>(gm, iField, iField, k, 0), _pview(pview), _dofView(0), - withDof(false) {} + withDof(false), _distance_map(distance_map) + { + } + orthogonalTerm(GModel *gm, int iField, simpleFunction<double> *k, + PView *pview) + : helmholtzTerm<double>(gm, iField, iField, k, 0), _pview(pview), + _dofView(0), withDof(false) + { + } orthogonalTerm(GModel *gm, int iField, simpleFunction<double> *k, dofManager<double> *dofView) - : helmholtzTerm<double>(gm, iField, iField, k, 0), _pview(0), _dofView(dofView), - withDof(true) {} + : helmholtzTerm<double>(gm, iField, iField, k, 0), _pview(0), + _dofView(dofView), withDof(true) + { + } void elementVector(SElement *se, fullVector<double> &m) const { MElement *e = se->getMeshElement(); int nbSF = e->getNumShapeFunctions(); - //fill elementary matrix mat(i,j) + // fill elementary matrix mat(i,j) int integrationOrder = 2 * (e->getPolynomialOrder() - 1); int npts; IntPt *GP; double jac[3][3]; double invjac[3][3]; - SVector3 Grads [256]; + SVector3 Grads[256]; double grads[256][3]; e->getIntegrationPoints(integrationOrder, &npts, &GP); fullMatrix<double> mat(nbSF, nbSF); mat.setAll(0.); - for(int i = 0; i < npts; i++){ + for(int i = 0; i < npts; i++) { const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; const double weight = GP[i].weight; const double detJ = e->getJacobian(u, v, w, jac); - SPoint3 p; e->pnt(u, v, w, p); + SPoint3 p; + e->pnt(u, v, w, p); inv3x3(jac, invjac); e->getGradShapeFunctions(u, v, w, grads); - for(int j = 0; j < nbSF; j++){ - Grads[j] = SVector3(invjac[0][0] * grads[j][0] + invjac[0][1] * grads[j][1] + - invjac[0][2] * grads[j][2], - invjac[1][0] * grads[j][0] + invjac[1][1] * grads[j][1] + - invjac[1][2] * grads[j][2], - invjac[2][0] * grads[j][0] + invjac[2][1] * grads[j][1] + - invjac[2][2] * grads[j][2]); + for(int j = 0; j < nbSF; j++) { + Grads[j] = + SVector3(invjac[0][0] * grads[j][0] + invjac[0][1] * grads[j][1] + + invjac[0][2] * grads[j][2], + invjac[1][0] * grads[j][0] + invjac[1][1] * grads[j][1] + + invjac[1][2] * grads[j][2], + invjac[2][0] * grads[j][0] + invjac[2][1] * grads[j][1] + + invjac[2][2] * grads[j][2]); } - SVector3 N (jac[2][0], jac[2][1], jac[2][2]); + SVector3 N(jac[2][0], jac[2][1], jac[2][2]); for(int j = 0; j < nbSF; j++) for(int k = 0; k <= j; k++) mat(j, k) += dot(crossprod(Grads[j], Grads[k]), N) * weight * detJ; } for(int j = 0; j < nbSF; j++) - for(int k = 0; k < j; k++) - mat(k, j) = -1.* mat(j, k); + for(int k = 0; k < j; k++) mat(k, j) = -1. * mat(j, k); - //2) compute vector m(i) = mat(i,j)*val(j) + // 2) compute vector m(i) = mat(i,j)*val(j) fullVector<double> val(nbSF); val.scale(0.); - for(int i = 0; i < nbSF; i++){ - std::map<MVertex*, double>::iterator it = _distance_map->find(e->getShapeFunctionNode(i)); + for(int i = 0; i < nbSF; i++) { + std::map<MVertex *, double>::iterator it = + _distance_map->find(e->getShapeFunctionNode(i)); val(i) = it->second; } @@ -90,14 +100,14 @@ class orthogonalTerm : public helmholtzTerm<double> { /* exit(1); */ /* /\* PViewData *data = view->getData(); *\/ */ /* /\* for (int i = 0; i < nbSF; i++){ *\/ */ - /* /\* data->getValue(0, e->, e->getNum(), e->getShapeFunctionNode(i)->getNum(), nod, 0, val(i)); *\/ */ + /* /\* data->getValue(0, e->, e->getNum(), + * e->getShapeFunctionNode(i)->getNum(), nod, 0, val(i)); *\/ */ /* /\* } *\/ */ /* } */ m.scale(0.); for(int i = 0; i < nbSF; i++) - for(int j = 0; j < nbSF; j++) - m(i) += -mat(i, j) * val(j); + for(int j = 0; j < nbSF; j++) m(i) += -mat(i, j) * val(j); } }; diff --git a/Solver/quadratureRules.h b/Solver/quadratureRules.h index d97390b7c2d28d29b817389858b561e056d481d4..301c9c5c790994a7f574bdf02ddcb239b2b711fa 100644 --- a/Solver/quadratureRules.h +++ b/Solver/quadratureRules.h @@ -13,64 +13,59 @@ #include "GaussIntegration.h" #include "MElement.h" -class QuadratureBase -{ - public : - virtual ~QuadratureBase(){} - virtual int getIntPoints(MElement *e, IntPt **GP) =0; +class QuadratureBase { +public: + virtual ~QuadratureBase() {} + virtual int getIntPoints(MElement *e, IntPt **GP) = 0; }; // For rigid contact no need of Gauss'integration // but to use clasical get function in term npts and IntPt are needed // so use a empty gaussQuadrature rule -class QuadratureVoid : public QuadratureBase -{ - public: - QuadratureVoid() : QuadratureBase(){} - ~QuadratureVoid(){} - int getIntPoints(MElement *e, IntPt **GP){GP=NULL; return 0;} -} ; +class QuadratureVoid : public QuadratureBase { +public: + QuadratureVoid() : QuadratureBase() {} + ~QuadratureVoid() {} + int getIntPoints(MElement *e, IntPt **GP) + { + GP = NULL; + return 0; + } +}; + +class GaussQuadrature : public QuadratureBase { +public: + enum IntegCases { Other, Val, Grad, ValVal, GradGrad }; -class GaussQuadrature : public QuadratureBase -{ - public : - enum IntegCases {Other, Val, Grad, ValVal, GradGrad}; - private : +private: int order; IntegCases info; - public : + +public: GaussQuadrature(int order_ = 0) : order(order_), info(Other) {} GaussQuadrature(IntegCases info_) : order(0), info(info_) {} - virtual ~GaussQuadrature(){} + virtual ~GaussQuadrature() {} virtual int getIntPoints(MElement *e, IntPt **GP) { int integrationOrder; int npts; int geoorder = e->getPolynomialOrder(); - switch(info) - { - case Other : - integrationOrder = order; - break; - case Val : - integrationOrder = geoorder + 1; - break; - case Grad : - integrationOrder = geoorder; - break; - case ValVal : - integrationOrder = 2 * geoorder; - break; - case GradGrad : - integrationOrder = 3 * (geoorder - 1) + 1; - break; - default : integrationOrder = 1; + switch(info) { + case Other: integrationOrder = order; break; + case Val: integrationOrder = geoorder + 1; break; + case Grad: integrationOrder = geoorder; break; + case ValVal: integrationOrder = 2 * geoorder; break; + case GradGrad: integrationOrder = 3 * (geoorder - 1) + 1; break; + default: integrationOrder = 1; } e->getIntegrationPoints(integrationOrder, &npts, GP); return npts; } // copy constructor - GaussQuadrature(const GaussQuadrature &other) : order(other.order), info(other.info){} + GaussQuadrature(const GaussQuadrature &other) + : order(other.order), info(other.info) + { + } }; #endif //_QUADRATURERULES_H_ diff --git a/Solver/solverAlgorithms.h b/Solver/solverAlgorithms.h index 2ae89c1865d9b262de246df194cca15ff0d4c9e8..1ba460c3daf9989f50e9f48830d26143530d1cd1 100644 --- a/Solver/solverAlgorithms.h +++ b/Solver/solverAlgorithms.h @@ -10,55 +10,54 @@ #ifndef _SOLVERALGORITHMS_H_ #define _SOLVERALGORITHMS_H_ - #include "dofManager.h" #include "terms.h" #include "quadratureRules.h" #include "MVertex.h" - - -template<class Iterator, class Assembler> void Assemble(BilinearTermBase &term, FunctionSpaceBase &space, - Iterator itbegin, Iterator itend, - QuadratureBase &integrator, Assembler &assembler) - // symmetric +template <class Iterator, class Assembler> +void Assemble(BilinearTermBase &term, FunctionSpaceBase &space, + Iterator itbegin, Iterator itend, QuadratureBase &integrator, + Assembler &assembler) +// symmetric { fullMatrix<typename Assembler::dataMat> localMatrix; std::vector<Dof> R; - for (Iterator it = itbegin; it != itend; ++it){ + for(Iterator it = itbegin; it != itend; ++it) { MElement *e = *it; R.clear(); IntPt *GP; int npts = integrator.getIntPoints(e, &GP); - term.get(e, npts, GP, localMatrix); //localMatrix.print(); + term.get(e, npts, GP, localMatrix); // localMatrix.print(); space.getKeys(e, R); assembler.assemble(R, localMatrix); } } -template<class Iterator, class Assembler> void Assemble(BilinearTermBase &term, FunctionSpaceBase &space, - Iterator itbegin, Iterator itend, - QuadratureBase &integrator, Assembler &assembler, - elementFilter& efilter) - // symmetric +template <class Iterator, class Assembler> +void Assemble(BilinearTermBase &term, FunctionSpaceBase &space, + Iterator itbegin, Iterator itend, QuadratureBase &integrator, + Assembler &assembler, elementFilter &efilter) +// symmetric { fullMatrix<typename Assembler::dataMat> localMatrix; std::vector<Dof> R; - for (Iterator it = itbegin; it != itend; ++it){ + for(Iterator it = itbegin; it != itend; ++it) { MElement *e = *it; - if (efilter(e)){ - R.clear(); - IntPt *GP; - int npts = integrator.getIntPoints(e, &GP); - term.get(e, npts, GP, localMatrix); //localMatrix.print(); - space.getKeys(e, R); - assembler.assemble(R, localMatrix); - } + if(efilter(e)) { + R.clear(); + IntPt *GP; + int npts = integrator.getIntPoints(e, &GP); + term.get(e, npts, GP, localMatrix); // localMatrix.print(); + space.getKeys(e, R); + assembler.assemble(R, localMatrix); + } } } -template<class Assembler> void Assemble(BilinearTermBase &term, FunctionSpaceBase &space, MElement *e, - QuadratureBase &integrator, Assembler &assembler) // symmetric +template <class Assembler> +void Assemble(BilinearTermBase &term, FunctionSpaceBase &space, MElement *e, + QuadratureBase &integrator, Assembler &assembler) // symmetric { fullMatrix<typename Assembler::dataMat> localMatrix; std::vector<Dof> R; @@ -69,90 +68,94 @@ template<class Assembler> void Assemble(BilinearTermBase &term, FunctionSpaceBas assembler.assemble(R, localMatrix); } -template<class Iterator, class Assembler> void Assemble(BilinearTermBase &term, - FunctionSpaceBase &shapeFcts, - FunctionSpaceBase &testFcts, - Iterator itbegin, Iterator itend, - QuadratureBase &integrator, - Assembler &assembler) // non symmetric +template <class Iterator, class Assembler> +void Assemble(BilinearTermBase &term, FunctionSpaceBase &shapeFcts, + FunctionSpaceBase &testFcts, Iterator itbegin, Iterator itend, + QuadratureBase &integrator, + Assembler &assembler) // non symmetric { fullMatrix<typename Assembler::dataMat> localMatrix; std::vector<Dof> R; std::vector<Dof> C; - for (Iterator it = itbegin; it != itend; ++it){ + for(Iterator it = itbegin; it != itend; ++it) { MElement *e = *it; R.clear(); C.clear(); IntPt *GP; int npts = integrator.getIntPoints(e, &GP); - term.get(e, npts, GP, localMatrix); //localMatrix.print(); - //printf("local matrix size = %d %d\n", localMatrix.size1(), localMatrix.size2()); + term.get(e, npts, GP, localMatrix); // localMatrix.print(); + // printf("local matrix size = %d %d\n", localMatrix.size1(), + // localMatrix.size2()); shapeFcts.getKeys(e, R); testFcts.getKeys(e, C); -// std::cout << "assembling normal test function ; lagrange trial function : " << std::endl; -// for (int i = 0 ; i < R.size() ; i++) -// { -// std::cout << "tests : " << R[i].getEntity() << ":" << R[i].getType() << std::endl ; -// } -// for (int i = 0 ; i < R.size() ; i++) -// { -// std::cout << "trial : " << C[i].getEntity() << ":" << C[i].getType() << std::endl ; -// } + // std::cout << "assembling normal test function ; lagrange trial + // function : " << std::endl; for (int i = 0 ; i < R.size() ; i++) + // { + // std::cout << "tests : " << R[i].getEntity() << ":" << R[i].getType() + // << std::endl ; + // } + // for (int i = 0 ; i < R.size() ; i++) + // { + // std::cout << "trial : " << C[i].getEntity() << ":" << C[i].getType() + // << std::endl ; + // } assembler.assemble(R, C, localMatrix); -// std::cout << "assembling lagrange test function ; normal trial function : " << std::endl; -// for (int i = 0 ; i < R.size() ; i++) -// { -// std::cout << "tests : " << C[i].getEntity() << ":" << C[i].getType() << std::endl ; -// } -// for (int i = 0 ; i < R.size() ; i++) -// { -// std::cout << "trial : " << R[i].getEntity() << ":" << R[i].getType() << std::endl ; -// } + // std::cout << "assembling lagrange test function ; normal trial + // function : " << std::endl; for (int i = 0 ; i < R.size() ; i++) + // { + // std::cout << "tests : " << C[i].getEntity() << ":" << C[i].getType() + // << std::endl ; + // } + // for (int i = 0 ; i < R.size() ; i++) + // { + // std::cout << "trial : " << R[i].getEntity() << ":" << R[i].getType() + // << std::endl ; + // } assembler.assemble(C, R, localMatrix.transpose()); } } - - -template<class Iterator, class Assembler> void Assemble(LinearTermBase<double> &term, FunctionSpaceBase &space, - Iterator itbegin, Iterator itend, - QuadratureBase &integrator, Assembler &assembler) +template <class Iterator, class Assembler> +void Assemble(LinearTermBase<double> &term, FunctionSpaceBase &space, + Iterator itbegin, Iterator itend, QuadratureBase &integrator, + Assembler &assembler) { fullVector<typename Assembler::dataMat> localVector; std::vector<Dof> R; - for (Iterator it = itbegin; it != itend; ++it){ + for(Iterator it = itbegin; it != itend; ++it) { MElement *e = *it; R.clear(); IntPt *GP; int npts = integrator.getIntPoints(e, &GP); - term.get(e, npts, GP, localVector); //localVector.print(); + term.get(e, npts, GP, localVector); // localVector.print(); space.getKeys(e, R); assembler.assemble(R, localVector); } } -template<class Iterator, class Assembler> void Assemble(LinearTermBase<double> &term, FunctionSpaceBase &space, - Iterator itbegin, Iterator itend, - QuadratureBase &integrator, Assembler &assembler, - elementFilter& efilter) +template <class Iterator, class Assembler> +void Assemble(LinearTermBase<double> &term, FunctionSpaceBase &space, + Iterator itbegin, Iterator itend, QuadratureBase &integrator, + Assembler &assembler, elementFilter &efilter) { fullVector<typename Assembler::dataMat> localVector; std::vector<Dof> R; - for (Iterator it = itbegin; it != itend; ++it){ + for(Iterator it = itbegin; it != itend; ++it) { MElement *e = *it; - if (efilter(e)){ - R.clear(); - IntPt *GP; - int npts = integrator.getIntPoints(e, &GP); - term.get(e, npts, GP, localVector); //localVector.print(); - space.getKeys(e, R); - assembler.assemble(R, localVector); - } + if(efilter(e)) { + R.clear(); + IntPt *GP; + int npts = integrator.getIntPoints(e, &GP); + term.get(e, npts, GP, localVector); // localVector.print(); + space.getKeys(e, R); + assembler.assemble(R, localVector); + } } } -template<class Assembler> void Assemble(LinearTermBase<double> &term, FunctionSpaceBase &space, MElement *e, - QuadratureBase &integrator, Assembler &assembler) +template <class Assembler> +void Assemble(LinearTermBase<double> &term, FunctionSpaceBase &space, + MElement *e, QuadratureBase &integrator, Assembler &assembler) { fullVector<typename Assembler::dataMat> localVector; std::vector<Dof> R; @@ -163,12 +166,12 @@ template<class Assembler> void Assemble(LinearTermBase<double> &term, FunctionSp assembler.assemble(R, localVector); } -template<class Iterator, class dataMat> void Assemble(ScalarTermBase<double> &term, - Iterator itbegin, Iterator itend, - QuadratureBase &integrator, dataMat & val) +template <class Iterator, class dataMat> +void Assemble(ScalarTermBase<double> &term, Iterator itbegin, Iterator itend, + QuadratureBase &integrator, dataMat &val) { dataMat localval; - for (Iterator it = itbegin; it != itend; ++it){ + for(Iterator it = itbegin; it != itend; ++it) { MElement *e = *it; IntPt *GP; int npts = integrator.getIntPoints(e, &GP); @@ -177,25 +180,25 @@ template<class Iterator, class dataMat> void Assemble(ScalarTermBase<double> &te } } -template<class Iterator, class dataMat> void Assemble(ScalarTermBase<double> &term, - Iterator itbegin, Iterator itend, - QuadratureBase &integrator, dataMat & val, - elementFilter& efilter) +template <class Iterator, class dataMat> +void Assemble(ScalarTermBase<double> &term, Iterator itbegin, Iterator itend, + QuadratureBase &integrator, dataMat &val, elementFilter &efilter) { dataMat localval; - for (Iterator it = itbegin; it != itend; ++it){ + for(Iterator it = itbegin; it != itend; ++it) { MElement *e = *it; - if (efilter(e)){ - IntPt *GP; - int npts = integrator.getIntPoints(e, &GP); - term.get(e, npts, GP, localval); - val += localval; - } + if(efilter(e)) { + IntPt *GP; + int npts = integrator.getIntPoints(e, &GP); + term.get(e, npts, GP, localval); + val += localval; + } } } -template<class Iterator, class dataMat> void Assemble(ScalarTermBase<double> &term, MElement *e, - QuadratureBase &integrator, dataMat & val) +template <class Iterator, class dataMat> +void Assemble(ScalarTermBase<double> &term, MElement *e, + QuadratureBase &integrator, dataMat &val) { dataMat localval; IntPt *GP; @@ -204,88 +207,82 @@ template<class Iterator, class dataMat> void Assemble(ScalarTermBase<double> &te val += localval; } - -template<class Assembler> void FixDofs(Assembler &assembler, std::vector<Dof> &dofs, - std::vector<typename Assembler::dataVec> &vals) +template <class Assembler> +void FixDofs(Assembler &assembler, std::vector<Dof> &dofs, + std::vector<typename Assembler::dataVec> &vals) { int nbff = dofs.size(); - for (int i = 0; i < nbff; ++i){ + for(int i = 0; i < nbff; ++i) { assembler.fixDof(dofs[i], vals[i]); } } -class FilterDof -{ - public: - virtual ~FilterDof(){} +class FilterDof { +public: + virtual ~FilterDof() {} virtual bool operator()(Dof key) = 0; }; -class FilterDofTrivial : public FilterDof -{ - public: - virtual bool operator()(Dof key) {return true;} +class FilterDofTrivial : public FilterDof { +public: + virtual bool operator()(Dof key) { return true; } }; -class FilterDofComponent : public FilterDof -{ +class FilterDofComponent : public FilterDof { int comp; - public : + +public: FilterDofComponent(int comp_) : comp(comp_) {} virtual bool operator()(Dof key) { int type = key.getType(); int icomp, iphys; Dof::getTwoIntsFromType(type, icomp, iphys); - if (icomp == comp) return true; + if(icomp == comp) return true; return false; } }; // return true if the Dof is in a filled set -class FilterDofSet : public FilterDof -{ - protected: +class FilterDofSet : public FilterDof { +protected: std::set<Dof> _dofset; - public: - FilterDofSet() : FilterDof(){} - virtual ~FilterDofSet(){} + +public: + FilterDofSet() : FilterDof() {} + virtual ~FilterDofSet() {} virtual bool operator()(Dof key) { std::set<Dof>::iterator itR = _dofset.find(key); - if(itR == _dofset.end()){ + if(itR == _dofset.end()) { return false; } return true; } - virtual void addDof(Dof key) - { - _dofset.insert(key); - } + virtual void addDof(Dof key) { _dofset.insert(key); } virtual void addDof(std::vector<Dof> &R) { - for(unsigned int i=0;i<R.size();i++) - this->addDof(R[i]); + for(unsigned int i = 0; i < R.size(); i++) this->addDof(R[i]); } }; -template<class Assembler> void FixNodalDofs(FunctionSpaceBase &space, MElement *e, Assembler &assembler, - simpleFunction<typename Assembler::dataVec> &fct, - FilterDof &filter) +template <class Assembler> +void FixNodalDofs(FunctionSpaceBase &space, MElement *e, Assembler &assembler, + simpleFunction<typename Assembler::dataVec> &fct, + FilterDof &filter) { - std::vector<MVertex*> tabV; + std::vector<MVertex *> tabV; int nv = e->getNumVertices(); std::vector<Dof> R; space.getKeys(e, R); tabV.reserve(nv); - for (int i = 0; i < nv; ++i) - tabV.push_back(e->getVertex(i)); + for(int i = 0; i < nv; ++i) tabV.push_back(e->getVertex(i)); - for (std::vector<Dof>::iterator itd = R.begin(); itd != R.end(); ++itd){ + for(std::vector<Dof>::iterator itd = R.begin(); itd != R.end(); ++itd) { Dof key = *itd; - if (filter(key)){ - for (int i = 0;i < nv; ++i){ - if (tabV[i]->getNum() == key.getEntity()){ + if(filter(key)) { + for(int i = 0; i < nv; ++i) { + if(tabV[i]->getNum() == key.getEntity()) { assembler.fixDof(key, fct(tabV[i]->x(), tabV[i]->y(), tabV[i]->z())); break; } @@ -294,59 +291,64 @@ template<class Assembler> void FixNodalDofs(FunctionSpaceBase &space, MElement * } } -template<class Iterator, class Assembler> void FixNodalDofs(FunctionSpaceBase &space, Iterator itbegin, - Iterator itend, Assembler &assembler, - simpleFunction<typename Assembler::dataVec> &fct, - FilterDof &filter) +template <class Iterator, class Assembler> +void FixNodalDofs(FunctionSpaceBase &space, Iterator itbegin, Iterator itend, + Assembler &assembler, + simpleFunction<typename Assembler::dataVec> &fct, + FilterDof &filter) { - for (Iterator it = itbegin; it != itend; ++it) + for(Iterator it = itbegin; it != itend; ++it) FixNodalDofs(space, *it, assembler, fct, filter); } -template<class Iterator, class Assembler> void FixVoidNodalDofs(FunctionSpaceBase &space, Iterator itbegin, - Iterator itend, Assembler &assembler) +template <class Iterator, class Assembler> +void FixVoidNodalDofs(FunctionSpaceBase &space, Iterator itbegin, + Iterator itend, Assembler &assembler) { FilterDofTrivial filter; simpleFunction<typename Assembler::dataVec> fct(0.); FixNodalDofs(space, itbegin, itend, assembler, fct, filter); } -template<class Iterator, class Assembler> void NumberDofs(FunctionSpaceBase &space, Iterator itbegin, - Iterator itend, Assembler &assembler) +template <class Iterator, class Assembler> +void NumberDofs(FunctionSpaceBase &space, Iterator itbegin, Iterator itend, + Assembler &assembler) { - for (Iterator it = itbegin; it != itend; ++it){ + for(Iterator it = itbegin; it != itend; ++it) { MElement *e = *it; std::vector<Dof> R; space.getKeys(e, R); int nbdofs = R.size(); - for (int i = 0; i < nbdofs; ++i) assembler.numberDof(R[i]); + for(int i = 0; i < nbdofs; ++i) assembler.numberDof(R[i]); } } -//// Mean HangingNodes -//template <class Assembler> void FillHangingNodes(FunctionSpaceBase &space, std::map<int,std::vector <int> > &HangingNodes, Assembler &assembler, int &field, int &dim) -//{ -// std::map<int, std::vector <int> >::iterator ith; -// ith = HangingNodes.begin(); -// int compt = 1; -// while (ith != HangingNodes.end()){ -// float fac; -// fac = 1.0 / (ith->second).size(); -// for (int j = 0; j < dim; j++){ -// DofAffineConstraint<double> constraint; -// int type = Dof::createTypeWithTwoInts(j, field); -// Dof hgnd(ith->first, type); -// for (int i = 0; i < (ith->second).size(); i++){ -// Dof key((ith->second)[i], type); -// std::pair<Dof, double > linDof(key, fac); -// constraint.linear.push_back(linDof); -// } -// constraint.shift = 0; -// assembler.setLinearConstraint (hgnd, constraint); -// } -// ith++; -// compt++; -// } -//} + //// Mean HangingNodes + // template <class Assembler> void FillHangingNodes(FunctionSpaceBase &space, + // std::map<int,std::vector <int> > &HangingNodes, Assembler &assembler, int + // &field, int &dim) + //{ + // std::map<int, std::vector <int> >::iterator ith; + // ith = HangingNodes.begin(); + // int compt = 1; + // while (ith != HangingNodes.end()){ + // float fac; + // fac = 1.0 / (ith->second).size(); + // for (int j = 0; j < dim; j++){ + // DofAffineConstraint<double> constraint; + // int type = Dof::createTypeWithTwoInts(j, field); + // Dof hgnd(ith->first, type); + // for (int i = 0; i < (ith->second).size(); i++){ + // Dof key((ith->second)[i], type); + // std::pair<Dof, double > linDof(key, fac); + // constraint.linear.push_back(linDof); + // } + // constraint.shift = 0; + // assembler.setLinearConstraint (hgnd, constraint); + // } + // ith++; + // compt++; + // } + //} -#endif// _SOLVERALGORITHMS_H_ +#endif // _SOLVERALGORITHMS_H_ diff --git a/Solver/solverField.h b/Solver/solverField.h index f1435cf37ac584271e3a9210b302a6b582b6d65e..d99b4d6582734351d5bce5e8fb6d67ada7659aea 100644 --- a/Solver/solverField.h +++ b/Solver/solverField.h @@ -16,26 +16,42 @@ #include "dofManager.h" #include "functionSpace.h" -template<class T> -class SolverField : public FunctionSpace<T> // being able to use it instead of a real function space is interesting (nbkeys=1, explicit keys/dofs undefined (or could be defined element-wise ) +template <class T> +class SolverField + : public FunctionSpace<T> // being able to use it instead of a real function + // space is interesting (nbkeys=1, explicit + // keys/dofs undefined (or could be defined + // element-wise ) { - public: +public: typedef typename TensorialTraits<T>::ValType ValType; typedef typename TensorialTraits<T>::GradType GradType; typedef typename TensorialTraits<T>::HessType HessType; - private: + +private: dofManager<double> *dm; FunctionSpace<T> *fs; - public: - SolverField(dofManager<double> *dm_, FunctionSpace<T> *fs_) : dm(dm_), fs(fs_) {} - virtual int getNumKeys(MVertex *ver) const { return 1;} - virtual int getNumKeys(MElement *ele) const { return 1;} - private: - virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const { Msg::Error("getKeys for SolverField shouldn't be called");} - virtual void getKeys(MVertex *ver, std::vector<Dof> &keys) const {Msg::Error("getKeys for SolverField shouldn't be called");} - public: - - virtual void f(MElement *ele, double u, double v, double w, ValType &val) const + +public: + SolverField(dofManager<double> *dm_, FunctionSpace<T> *fs_) : dm(dm_), fs(fs_) + { + } + virtual int getNumKeys(MVertex *ver) const { return 1; } + virtual int getNumKeys(MElement *ele) const { return 1; } + +private: + virtual void getKeys(MElement *ele, std::vector<Dof> &keys) const + { + Msg::Error("getKeys for SolverField shouldn't be called"); + } + virtual void getKeys(MVertex *ver, std::vector<Dof> &keys) const + { + Msg::Error("getKeys for SolverField shouldn't be called"); + } + +public: + virtual void f(MElement *ele, double u, double v, double w, + ValType &val) const { std::vector<Dof> D; std::vector<ValType> SFVals; @@ -44,18 +60,19 @@ class SolverField : public FunctionSpace<T> // being able to use it instead of a dm->getDofValue(D, DMVals); fs->f(ele, u, v, w, SFVals); val = ValType(); - for (unsigned int i = 0; i < D.size(); ++i) - val += SFVals[i] * DMVals[i]; + for(unsigned int i = 0; i < D.size(); ++i) val += SFVals[i] * DMVals[i]; } - virtual void f(MElement *ele, double u, double v, double w, std::vector<ValType> &vals) const + virtual void f(MElement *ele, double u, double v, double w, + std::vector<ValType> &vals) const { ValType val; f(ele, u, v, w, val); vals.push_back(val); } - virtual void gradf(MElement *ele, double u, double v, double w, GradType &grad) const + virtual void gradf(MElement *ele, double u, double v, double w, + GradType &grad) const { std::vector<Dof> D; std::vector<GradType> SFGrads; @@ -64,35 +81,37 @@ class SolverField : public FunctionSpace<T> // being able to use it instead of a dm->getDofValue(D, DMVals); fs->gradf(ele, u, v, w, SFGrads); grad = GradType(); - for (unsigned int i = 0; i < D.size(); ++i) - grad += SFGrads[i] * DMVals[i]; + for(unsigned int i = 0; i < D.size(); ++i) grad += SFGrads[i] * DMVals[i]; } // A quoi sert cette fonction ?? (Evalue le hessien au noeuds -/* virtual void hessf(MElement *ele, double u, double v, double w, HessType &hess) - { - // Pas besoin des dof etc -// std::vector<Dof> D; - std::vector<HessType> SFHess; -// std::vector<double> DMVals; -// fs->getKeys(ele, D); -// dm->getDofValue(D, DMVals); - fs->hessf(ele, u, v, w, SFHess); - -// hess = HessType; -// for (int i = 0; i < D.size(); ++i) -// hess += SFHess[i] * DMVals[i]; - }*/ - - virtual void gradf(MElement *ele, double u, double v, double w, std::vector<GradType> &grads) const + /* virtual void hessf(MElement *ele, double u, double v, double w, HessType + &hess) + { + // Pas besoin des dof etc + // std::vector<Dof> D; + std::vector<HessType> SFHess; + // std::vector<double> DMVals; + // fs->getKeys(ele, D); + // dm->getDofValue(D, DMVals); + fs->hessf(ele, u, v, w, SFHess); + + // hess = HessType; + // for (int i = 0; i < D.size(); ++i) + // hess += SFHess[i] * DMVals[i]; + }*/ + + virtual void gradf(MElement *ele, double u, double v, double w, + std::vector<GradType> &grads) const { GradType grad; gradf(ele, u, v, w, grad); grads.push_back(grad); } - virtual void hessfuvw(MElement *ele, double u, double v, double w, std::vector<HessType> &hess) const + virtual void hessfuvw(MElement *ele, double u, double v, double w, + std::vector<HessType> &hess) const { - //HessType hes; + // HessType hes; fs->hessfuvw(ele, u, v, w, hess); } }; diff --git a/Solver/sparsityPattern.cpp b/Solver/sparsityPattern.cpp index c87e1a88947b93954e3921b894b01a2ff44a1fad..b79e95e9a110178ea77eacec1e75b9f081419b6c 100644 --- a/Solver/sparsityPattern.cpp +++ b/Solver/sparsityPattern.cpp @@ -9,26 +9,23 @@ #include "sparsityPattern.h" -#include<stdlib.h> -#include<string.h> +#include <stdlib.h> +#include <string.h> // this class has been optimized, please before changing anything, check twice : // the impact on the performance to assemble typical High Order FE problems // and the impact on the memory usage for this operation -sparsityPattern::~sparsityPattern() -{ - clear(); -} +sparsityPattern::~sparsityPattern() { clear(); } -void sparsityPattern::clear() +void sparsityPattern::clear() { - for(int i = 0; i <_nRows; i++) { - if (_rowsj[i]) free(_rowsj[i]); + for(int i = 0; i < _nRows; i++) { + if(_rowsj[i]) free(_rowsj[i]); } - if (_nByRow) free(_nByRow); - if (_nAllocByRow) free(_nAllocByRow); - if (_rowsj) free(_rowsj); + if(_nByRow) free(_nByRow); + if(_nAllocByRow) free(_nAllocByRow); + if(_rowsj) free(_rowsj); _nByRow = NULL; _rowsj = NULL; _nAllocByRow = NULL; @@ -36,62 +33,64 @@ void sparsityPattern::clear() _nRowsAlloc = 0; } -void sparsityPattern::insertEntry (int i, int j) +void sparsityPattern::insertEntry(int i, int j) { - if (i >= _nRows) { - if (i >= _nRowsAlloc) { - _nRowsAlloc = (i+1)*3/2; - _rowsj = (int**)realloc (_rowsj, sizeof(int*)*_nRowsAlloc); - _nByRow = (int*)realloc (_nByRow, sizeof(int)*_nRowsAlloc); - _nAllocByRow = (int*)realloc(_nAllocByRow, sizeof(int)*_nRowsAlloc); + if(i >= _nRows) { + if(i >= _nRowsAlloc) { + _nRowsAlloc = (i + 1) * 3 / 2; + _rowsj = (int **)realloc(_rowsj, sizeof(int *) * _nRowsAlloc); + _nByRow = (int *)realloc(_nByRow, sizeof(int) * _nRowsAlloc); + _nAllocByRow = (int *)realloc(_nAllocByRow, sizeof(int) * _nRowsAlloc); } - for (int k = _nRows; k <= i; k++) { + for(int k = _nRows; k <= i; k++) { _nByRow[k] = 0; _nAllocByRow[k] = 0; _rowsj[k] = NULL; } - _nRows = i+1; + _nRows = i + 1; } int n = _nByRow[i]; int *rowj = _rowsj[i]; int k = 0; int k0 = 0, k1 = n; - if (n>20) { - while (k1-k0 > 20) { - int k2 = ((k0+k1)/2); - if (rowj[k2] > j) + if(n > 20) { + while(k1 - k0 > 20) { + int k2 = ((k0 + k1) / 2); + if(rowj[k2] > j) k1 = k2; - else if (rowj[k2] < j) - k0 = k2+1; + else if(rowj[k2] < j) + k0 = k2 + 1; else return; } - for (k = k0; k < k1; k++) { - if (rowj[k] >= j) { - if (rowj[k] == j) return; + for(k = k0; k < k1; k++) { + if(rowj[k] >= j) { + if(rowj[k] == j) return; break; } } - } else { // this "if() else" is not strictly necessary but with it, gcc unroll the for(k) loop - for (k = 0; k < n; k++) { - if (rowj[k] >= j) { - if (rowj[k] == j) return; + } + else { // this "if() else" is not strictly necessary but with it, gcc unroll + // the for(k) loop + for(k = 0; k < n; k++) { + if(rowj[k] >= j) { + if(rowj[k] == j) return; break; } } } - _nByRow[i] = n+1; - if (_nByRow[i]> _nAllocByRow[i]) { - int na = (n+1)*3/2; - _rowsj[i] = (int*)realloc(_rowsj[i], (na*sizeof(int))); + _nByRow[i] = n + 1; + if(_nByRow[i] > _nAllocByRow[i]) { + int na = (n + 1) * 3 / 2; + _rowsj[i] = (int *)realloc(_rowsj[i], (na * sizeof(int))); _nAllocByRow[i] = na; } - memmove(&_rowsj[i][k+1], &_rowsj[i][k], (n-k)*sizeof (int)); + memmove(&_rowsj[i][k + 1], &_rowsj[i][k], (n - k) * sizeof(int)); _rowsj[i][k] = j; } -sparsityPattern::sparsityPattern () +sparsityPattern::sparsityPattern() { _nRows = 0; _nRowsAlloc = 0; @@ -100,9 +99,9 @@ sparsityPattern::sparsityPattern () _nAllocByRow = NULL; } -const int *sparsityPattern::getRow (int i, int &size) const +const int *sparsityPattern::getRow(int i, int &size) const { - if (i >= _nRows){ + if(i >= _nRows) { size = 0; return NULL; } diff --git a/Solver/sparsityPattern.h b/Solver/sparsityPattern.h index c2839ed6d24271442bfe96f44359c5f48aeac847..7b6febe66e4dd8017d80167d666351fe58ee67e4 100644 --- a/Solver/sparsityPattern.h +++ b/Solver/sparsityPattern.h @@ -15,13 +15,13 @@ class sparsityPattern { int **_rowsj; int _nRows, _nRowsAlloc; - public : - void insertEntry (int i, int j); - const int* getRow (int line, int &size) const; +public: + void insertEntry(int i, int j); + const int *getRow(int line, int &size) const; void clear(); - sparsityPattern (); + sparsityPattern(); ~sparsityPattern(); - inline int getNbRows() {return _nRows;} + inline int getNbRows() { return _nRows; } }; #endif diff --git a/Solver/terms.cpp b/Solver/terms.cpp index b34cc17861f2402269dcf139e86522a838b7b104..9fb4f9fd8dc92d55a177a149410f9dbf98fef815 100644 --- a/Solver/terms.cpp +++ b/Solver/terms.cpp @@ -9,66 +9,77 @@ #include "terms.h" - -void BilinearTermToScalarTerm::get(MElement *ele, int npts, IntPt *GP, double &val) const +void BilinearTermToScalarTerm::get(MElement *ele, int npts, IntPt *GP, + double &val) const { fullMatrix<double> localMatrix; bilterm.get(ele, npts, GP, localMatrix); val = localMatrix(0, 0); } -void BilinearTermBase::get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const +void BilinearTermBase::get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const { std::vector<fullMatrix<double> > mv(npts); - get(ele,npts,GP,mv); + get(ele, npts, GP, mv); m.resize(mv[0].size1(), mv[0].size2()); m.setAll(0.); double jac[3][3]; - for (int k=0;k<npts;k++) - { - const double u = GP[k].pt[0]; const double v = GP[k].pt[1]; const double w = GP[k].pt[2]; - const double weight = GP[k].weight; const double detJ = ele->getJacobian(u, v, w, jac); - const double coeff=weight*detJ; - for (int i=0;i<mv[k].size1();++i) - for (int j=0;j<mv[k].size2();++j) - m(i,j)+=mv[k](i,j)*coeff; + for(int k = 0; k < npts; k++) { + const double u = GP[k].pt[0]; + const double v = GP[k].pt[1]; + const double w = GP[k].pt[2]; + const double weight = GP[k].weight; + const double detJ = ele->getJacobian(u, v, w, jac); + const double coeff = weight * detJ; + for(int i = 0; i < mv[k].size1(); ++i) + for(int j = 0; j < mv[k].size2(); ++j) m(i, j) += mv[k](i, j) * coeff; } } -IsotropicElasticTerm::IsotropicElasticTerm(FunctionSpace<SVector3>& space1_, FunctionSpace<SVector3>& space2_, double E_, double nu_) : - BilinearTerm<SVector3, SVector3>(space1_, space2_), E(E_), nu(nu_), H(6, 6) +IsotropicElasticTerm::IsotropicElasticTerm(FunctionSpace<SVector3> &space1_, + FunctionSpace<SVector3> &space2_, + double E_, double nu_) + : BilinearTerm<SVector3, SVector3>(space1_, space2_), E(E_), nu(nu_), H(6, 6) { double FACT = E / (1 + nu); double C11 = FACT * (1 - nu) / (1 - 2 * nu); double C12 = FACT * nu / (1 - 2 * nu); double C44 = (C11 - C12) / 2; H.scale(0.); - for(int i = 0; i < 3; ++i) { H(i, i) = C11; H(i + 3, i + 3) = C44; } + for(int i = 0; i < 3; ++i) { + H(i, i) = C11; + H(i + 3, i + 3) = C44; + } H(1, 0) = H(0, 1) = H(2, 0) = H(0, 2) = H(1, 2) = H(2, 1) = C12; sym = (&space1_ == &space2_); } -IsotropicElasticTerm::IsotropicElasticTerm(FunctionSpace<SVector3>& space1_, double E_, double nu_) : - BilinearTerm<SVector3, SVector3>(space1_, space1_), E(E_), nu(nu_), H(6, 6) +IsotropicElasticTerm::IsotropicElasticTerm(FunctionSpace<SVector3> &space1_, + double E_, double nu_) + : BilinearTerm<SVector3, SVector3>(space1_, space1_), E(E_), nu(nu_), H(6, 6) { double FACT = E / (1 + nu); double C11 = FACT * (1 - nu) / (1 - 2 * nu); double C12 = FACT * nu / (1 - 2 * nu); double C44 = (C11 - C12) / 2; -/* FACT = E / (1 - nu * nu); // plane stress (plates) - C11 = FACT; - C12 = nu * FACT; - C44 = (1. - nu) * .5 * FACT;*/ + /* FACT = E / (1 - nu * nu); // plane stress (plates) + C11 = FACT; + C12 = nu * FACT; + C44 = (1. - nu) * .5 * FACT;*/ H.scale(0.); - for(int i = 0; i < 3; ++i) { H(i, i) = C11; H(i + 3, i + 3) = C44; } + for(int i = 0; i < 3; ++i) { + H(i, i) = C11; + H(i + 3, i + 3) = C44; + } H(1, 0) = H(0, 1) = H(2, 0) = H(0, 2) = H(1, 2) = H(2, 1) = C12; sym = true; } -void IsotropicElasticTerm::get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const +void IsotropicElasticTerm::get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const { if(ele->getParent()) ele = ele->getParent(); - if(sym) - { + if(sym) { int nbFF = BilinearTerm<SVector3, SVector3>::space1.getNumKeys(ele); double jac[3][3]; fullMatrix<double> B(6, nbFF); @@ -76,15 +87,17 @@ void IsotropicElasticTerm::get(MElement *ele, int npts, IntPt *GP, fullMatrix<do fullMatrix<double> BT(nbFF, 6); m.resize(nbFF, nbFF); m.setAll(0.); - //std::cout << m.size1() << " " << m.size2() << std::endl; - for(int i = 0; i < npts; i++) - { - const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; - const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac); + // std::cout << m.size1() << " " << m.size2() << std::endl; + for(int i = 0; i < npts; i++) { + const double u = GP[i].pt[0]; + const double v = GP[i].pt[1]; + const double w = GP[i].pt[2]; + const double weight = GP[i].weight; + const double detJ = ele->getJacobian(u, v, w, jac); std::vector<TensorialTraits<SVector3>::GradType> Grads; - BilinearTerm<SVector3, SVector3>::space1.gradf(ele, u, v, w, Grads); // a optimiser ?? - for(int j = 0; j < nbFF; j++) - { + BilinearTerm<SVector3, SVector3>::space1.gradf(ele, u, v, w, + Grads); // a optimiser ?? + for(int j = 0; j < nbFF; j++) { BT(j, 0) = B(0, j) = Grads[j](0, 0); BT(j, 1) = B(1, j) = Grads[j](1, 1); BT(j, 2) = B(2, j) = Grads[j](2, 2); @@ -94,11 +107,10 @@ void IsotropicElasticTerm::get(MElement *ele, int npts, IntPt *GP, fullMatrix<do } BTH.setAll(0.); BTH.gemm(BT, H); - m.gemm(BTH, B, weight * detJ, 1.); //m = m + w*detJ*BT*H*B + m.gemm(BTH, B, weight * detJ, 1.); // m = m + w*detJ*BT*H*B } } - else - { + else { int nbFF1 = BilinearTerm<SVector3, SVector3>::space1.getNumKeys(ele); int nbFF2 = BilinearTerm<SVector3, SVector3>::space2.getNumKeys(ele); double jac[3][3]; @@ -108,16 +120,19 @@ void IsotropicElasticTerm::get(MElement *ele, int npts, IntPt *GP, fullMatrix<do m.resize(nbFF1, nbFF2); m.setAll(0.); // Sum on Gauss Points i - for(int i = 0; i < npts; i++) - { - const double u = GP[i].pt[0]; const double v = GP[i].pt[1]; const double w = GP[i].pt[2]; - const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac); - std::vector<TensorialTraits<SVector3>::GradType> Grads;// tableau de matrices... - std::vector<TensorialTraits<SVector3>::GradType> GradsT;// tableau de matrices... + for(int i = 0; i < npts; i++) { + const double u = GP[i].pt[0]; + const double v = GP[i].pt[1]; + const double w = GP[i].pt[2]; + const double weight = GP[i].weight; + const double detJ = ele->getJacobian(u, v, w, jac); + std::vector<TensorialTraits<SVector3>::GradType> + Grads; // tableau de matrices... + std::vector<TensorialTraits<SVector3>::GradType> + GradsT; // tableau de matrices... BilinearTerm<SVector3, SVector3>::space1.gradf(ele, u, v, w, Grads); BilinearTerm<SVector3, SVector3>::space2.gradf(ele, u, v, w, GradsT); - for(int j = 0; j < nbFF1; j++) - { + for(int j = 0; j < nbFF1; j++) { BT(j, 0) = Grads[j](0, 0); BT(j, 1) = Grads[j](1, 1); BT(j, 2) = Grads[j](2, 2); @@ -125,8 +140,7 @@ void IsotropicElasticTerm::get(MElement *ele, int npts, IntPt *GP, fullMatrix<do BT(j, 4) = Grads[j](1, 2) + Grads[j](2, 1); BT(j, 5) = Grads[j](0, 2) + Grads[j](2, 0); } - for(int j = 0; j < nbFF2; j++) - { + for(int j = 0; j < nbFF2; j++) { B(0, j) = GradsT[j](0, 0); B(1, j) = GradsT[j](1, 1); B(2, j) = GradsT[j](2, 2); @@ -142,29 +156,30 @@ void IsotropicElasticTerm::get(MElement *ele, int npts, IntPt *GP, fullMatrix<do } } -void LagMultTerm::get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const +void LagMultTerm::get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const { - int nbFF1 = BilinearTerm<SVector3, SVector3>::space1.getNumKeys(ele); //nbVertices*nbcomp of parent - int nbFF2 = BilinearTerm<SVector3, SVector3>::space2.getNumKeys(ele); //nbVertices of boundary + int nbFF1 = BilinearTerm<SVector3, SVector3>::space1.getNumKeys( + ele); // nbVertices*nbcomp of parent + int nbFF2 = BilinearTerm<SVector3, SVector3>::space2.getNumKeys( + ele); // nbVertices of boundary double jac[3][3]; m.resize(nbFF1, nbFF2); m.setAll(0.); - for(int i = 0; i < npts; i++) - { - double u = GP[i].pt[0]; double v = GP[i].pt[1]; double w = GP[i].pt[2]; - const double weight = GP[i].weight; const double detJ = ele->getJacobian(u, v, w, jac); + for(int i = 0; i < npts; i++) { + double u = GP[i].pt[0]; + double v = GP[i].pt[1]; + double w = GP[i].pt[2]; + const double weight = GP[i].weight; + const double detJ = ele->getJacobian(u, v, w, jac); std::vector<TensorialTraits<SVector3>::ValType> Vals; std::vector<TensorialTraits<SVector3>::ValType> ValsT; - BilinearTerm<SVector3,SVector3>::space1.f(ele, u, v, w, Vals); - BilinearTerm<SVector3,SVector3>::space2.f(ele, u, v, w, ValsT); - for(int j = 0; j < nbFF1; j++) - { - for(int k = 0; k < nbFF2; k++) - { + BilinearTerm<SVector3, SVector3>::space1.f(ele, u, v, w, Vals); + BilinearTerm<SVector3, SVector3>::space2.f(ele, u, v, w, ValsT); + for(int j = 0; j < nbFF1; j++) { + for(int k = 0; k < nbFF2; k++) { m(j, k) += _eqfac * dot(Vals[j], ValsT[k]) * weight * detJ; } } } } - - diff --git a/Solver/terms.h b/Solver/terms.h index df7cf2d0aa4d957bc81269abab7f2134dac11fec..ff08ba6e47415ee1bbcf37702650cf5df3878a26 100644 --- a/Solver/terms.h +++ b/Solver/terms.h @@ -20,178 +20,235 @@ #include <vector> #include <iterator> -template<class T2> class ScalarTermBase; +template <class T2> class ScalarTermBase; -template<class T2> class LinearTermBase; -template<class T2> class PlusTerm; +template <class T2> class LinearTermBase; +template <class T2> class PlusTerm; -class BilinearTermBase; +class BilinearTermBase; -inline double dot(const double &a, const double &b) -{ - return a * b; -} +inline double dot(const double &a, const double &b) { return a * b; } -inline int delta(int i,int j) {if (i==j) return 1; else return 0;} - -inline void setDirection(double &a, const double &b) +inline int delta(int i, int j) { - a = b; + if(i == j) + return 1; + else + return 0; } + +inline void setDirection(double &a, const double &b) { a = b; } inline void setDirection(SVector3 &a, const SVector3 &b) { for(int i = 0; i < 3; i++) a(i) = b(i); } -template<class T2=double> class ScalarTermBase -{ -public : +template <class T2 = double> class ScalarTermBase { +public: virtual ~ScalarTermBase() {} - virtual void get(MElement *ele, int npts, IntPt *GP, T2 &val) const = 0 ; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<T2> &vval) const = 0 ; - virtual ScalarTermBase<T2>* clone () const =0; + virtual void get(MElement *ele, int npts, IntPt *GP, T2 &val) const = 0; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<T2> &vval) const = 0; + virtual ScalarTermBase<T2> *clone() const = 0; }; -template<class T2=double> class ScalarTerm : public ScalarTermBase<T2> -{ -public : +template <class T2 = double> class ScalarTerm : public ScalarTermBase<T2> { +public: virtual ~ScalarTerm() {} }; - -template<class T2=double> class ScalarTermConstant : public ScalarTerm<T2> -{ +template <class T2 = double> class ScalarTermConstant : public ScalarTerm<T2> { protected: T2 cst; -public : + +public: ScalarTermConstant(T2 val_ = T2()) : cst(val_) {} virtual ~ScalarTermConstant() {} virtual void get(MElement *ele, int npts, IntPt *GP, T2 &val) const; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<T2> &vval) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<T2> &vval) const; virtual void get(MVertex *ver, T2 &val) const; - virtual ScalarTermBase<T2>* clone () const {return new ScalarTermConstant<T2>(cst);} + virtual ScalarTermBase<T2> *clone() const + { + return new ScalarTermConstant<T2>(cst); + } }; -class BilinearTermToScalarTerm : public ScalarTerm<double> -{ +class BilinearTermToScalarTerm : public ScalarTerm<double> { protected: BilinearTermBase &bilterm; -public : - BilinearTermToScalarTerm(BilinearTermBase &bilterm_): bilterm(bilterm_){} + +public: + BilinearTermToScalarTerm(BilinearTermBase &bilterm_) : bilterm(bilterm_) {} virtual ~BilinearTermToScalarTerm() {} virtual void get(MElement *ele, int npts, IntPt *GP, double &val) const; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<double> &vval) const {}; - virtual ScalarTermBase<double>* clone () const {return new BilinearTermToScalarTerm(bilterm);} + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<double> &vval) const {}; + virtual ScalarTermBase<double> *clone() const + { + return new BilinearTermToScalarTerm(bilterm); + } }; - - -class BilinearTermBase -{ -public : +class BilinearTermBase { +public: virtual ~BilinearTermBase() {} - virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const ; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<fullMatrix<double> > &mv) const = 0 ; - virtual BilinearTermBase* clone () const =0; + virtual void get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullMatrix<double> > &mv) const = 0; + virtual BilinearTermBase *clone() const = 0; }; - -template<class T2> class BilinearTermContract : public BilinearTermBase -{ +template <class T2> class BilinearTermContract : public BilinearTermBase { protected: const LinearTermBase<T2> *a; const LinearTermBase<T2> *b; + public: - BilinearTermContract(const LinearTermBase<T2> &a_,const LinearTermBase<T2> &b_) : a(a_.clone()),b(b_.clone()) {} - virtual ~BilinearTermContract() {delete a;delete b;} - virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const ; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<fullMatrix<double> > &mv) const {}; - virtual BilinearTermBase* clone () const {return new BilinearTermContract<T2>(*a,*b);} + BilinearTermContract(const LinearTermBase<T2> &a_, + const LinearTermBase<T2> &b_) + : a(a_.clone()), b(b_.clone()) + { + } + virtual ~BilinearTermContract() + { + delete a; + delete b; + } + virtual void get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullMatrix<double> > &mv) const {}; + virtual BilinearTermBase *clone() const + { + return new BilinearTermContract<T2>(*a, *b); + } }; -template<class T2> class BilinearTermContractWithLaw : public BilinearTermContract<T2> -{ +template <class T2> +class BilinearTermContractWithLaw : public BilinearTermContract<T2> { public: protected: - const ScalarTermBase< typename TensorialTraits<T2>::TensProdType > *c; + const ScalarTermBase<typename TensorialTraits<T2>::TensProdType> *c; + public: - BilinearTermContractWithLaw(const LinearTermBase<T2> &a_,const ScalarTermBase<typename TensorialTraits<T2>::TensProdType> &c_, const LinearTermBase<T2> &b_) : BilinearTermContract<T2>(a_,b_), c(c_.clone()) {} - virtual ~BilinearTermContractWithLaw() {delete c;} - virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const ; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<fullMatrix<double> > &mv) const ; - virtual BilinearTermBase* clone () const {return new BilinearTermContractWithLaw<T2>(*BilinearTermContract<T2>::a,*c,*BilinearTermContract<T2>::b);} + BilinearTermContractWithLaw( + const LinearTermBase<T2> &a_, + const ScalarTermBase<typename TensorialTraits<T2>::TensProdType> &c_, + const LinearTermBase<T2> &b_) + : BilinearTermContract<T2>(a_, b_), c(c_.clone()) + { + } + virtual ~BilinearTermContractWithLaw() { delete c; } + virtual void get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullMatrix<double> > &mv) const; + virtual BilinearTermBase *clone() const + { + return new BilinearTermContractWithLaw<T2>(*BilinearTermContract<T2>::a, *c, + *BilinearTermContract<T2>::b); + } }; -template<class T2> BilinearTermContract<T2> operator |(const LinearTermBase<T2>& L1,const LinearTermBase<T2>& L2); +template <class T2> +BilinearTermContract<T2> operator|(const LinearTermBase<T2> &L1, + const LinearTermBase<T2> &L2); +template <class T1, class T2> class BilinearTerm : public BilinearTermBase { +protected: + FunctionSpace<T1> &space1; + FunctionSpace<T2> &space2; -template<class T1,class T2> class BilinearTerm : public BilinearTermBase -{ -protected : - FunctionSpace<T1>& space1; - FunctionSpace<T2>& space2; -public : - BilinearTerm(FunctionSpace<T1>& space1_, FunctionSpace<T2>& space2_) : space1(space1_), space2(space2_) {} +public: + BilinearTerm(FunctionSpace<T1> &space1_, FunctionSpace<T2> &space2_) + : space1(space1_), space2(space2_) + { + } virtual ~BilinearTerm() {} }; -template<class T2=double> class LinearTermBase -{ +template <class T2 = double> class LinearTermBase { public: virtual ~LinearTermBase() {} - virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &v) const ; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<fullVector<T2> > &vv) const =0; - virtual LinearTermBase<T2>* clone () const = 0; - PlusTerm<T2> operator +(const LinearTermBase<T2>& other); + virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &v) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullVector<T2> > &vv) const = 0; + virtual LinearTermBase<T2> *clone() const = 0; + PlusTerm<T2> operator+(const LinearTermBase<T2> &other); }; - -template<class T2> class PlusTerm:public LinearTermBase<T2> -{ +template <class T2> class PlusTerm : public LinearTermBase<T2> { const LinearTermBase<T2> *a; const LinearTermBase<T2> *b; + public: - PlusTerm(const LinearTermBase<T2> &a_,const LinearTermBase<T2> &b_) : a(a_.clone()),b(b_.clone()) {} - virtual ~PlusTerm() {delete a;delete b;} - virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &v) const ; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<fullVector<T2> > &vv) const {}; - virtual LinearTermBase<T2>* clone () const { return new PlusTerm<T2>(*a,*b);} + PlusTerm(const LinearTermBase<T2> &a_, const LinearTermBase<T2> &b_) + : a(a_.clone()), b(b_.clone()) + { + } + virtual ~PlusTerm() + { + delete a; + delete b; + } + virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<T2> &v) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullVector<T2> > &vv) const {}; + virtual LinearTermBase<T2> *clone() const { return new PlusTerm<T2>(*a, *b); } }; +template <class T1, class T2 = double> +class LinearTerm : public LinearTermBase<T2> { +protected: + FunctionSpace<T1> &space1; -template<class T1, class T2=double> class LinearTerm : public LinearTermBase<T2> -{ -protected : - FunctionSpace<T1>& space1; -public : - LinearTerm(FunctionSpace<T1>& space1_) : space1(space1_) {} +public: + LinearTerm(FunctionSpace<T1> &space1_) : space1(space1_) {} virtual ~LinearTerm() {} }; - - -template<class T1> class GradTerm : public LinearTerm<T1, typename TensorialTraits<T1>::GradType > -{ -public : - GradTerm(FunctionSpace<T1>& space1_) : LinearTerm<T1,typename TensorialTraits<T1>::GradType >(space1_) {} - virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<typename TensorialTraits<T1>::GradType > &vec) const {LinearTermBase<typename TensorialTraits<T1>::GradType>::get(ele,npts,GP,vec);} - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<fullVector<typename TensorialTraits<T1>::GradType > > &vvec) const; - virtual LinearTermBase<typename TensorialTraits<T1>::GradType>* clone () const { return new GradTerm<T1>(LinearTerm<T1,typename TensorialTraits<T1>::GradType>::space1);} +template <class T1> +class GradTerm : public LinearTerm<T1, typename TensorialTraits<T1>::GradType> { +public: + GradTerm(FunctionSpace<T1> &space1_) + : LinearTerm<T1, typename TensorialTraits<T1>::GradType>(space1_) + { + } + virtual void + get(MElement *ele, int npts, IntPt *GP, + fullVector<typename TensorialTraits<T1>::GradType> &vec) const + { + LinearTermBase<typename TensorialTraits<T1>::GradType>::get(ele, npts, GP, + vec); + } + virtual void + get(MElement *ele, int npts, IntPt *GP, + std::vector<fullVector<typename TensorialTraits<T1>::GradType> > &vvec) + const; + virtual LinearTermBase<typename TensorialTraits<T1>::GradType> *clone() const + { + return new GradTerm<T1>( + LinearTerm<T1, typename TensorialTraits<T1>::GradType>::space1); + } virtual ~GradTerm() {} }; - -template<class T1, class T2> class LaplaceTerm : public BilinearTerm<T1, T2> -{ -public : - LaplaceTerm(FunctionSpace<T1>& space1_, FunctionSpace<T2>& space2_) : BilinearTerm<T1, T2>(space1_, space2_) - {} +template <class T1, class T2> class LaplaceTerm : public BilinearTerm<T1, T2> { +public: + LaplaceTerm(FunctionSpace<T1> &space1_, FunctionSpace<T2> &space2_) + : BilinearTerm<T1, T2>(space1_, space2_) + { + } virtual ~LaplaceTerm() {} - virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const + virtual void get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const { Msg::Error("LaplaceTerm<S1, S2> w/ S1 != S2 not implemented"); } - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector< fullMatrix<double> > &vm) const + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullMatrix<double> > &vm) const { Msg::Error("LaplaceTerm<S1, S2> w/ S1 != S2 not implemented"); } @@ -199,99 +256,153 @@ public : { Msg::Error("LaplaceTerm<S1, S2> w/ S1 != S2 not implemented"); } - virtual BilinearTermBase* clone () const {return new LaplaceTerm< T1, T2 >(BilinearTerm<T1, T2>::space1,BilinearTerm<T1, T2>::space2);} + virtual BilinearTermBase *clone() const + { + return new LaplaceTerm<T1, T2>(BilinearTerm<T1, T2>::space1, + BilinearTerm<T1, T2>::space2); + } }; // class -template<class T1> class LaplaceTerm<T1, T1> : public BilinearTerm<T1, T1> // symmetric +template <class T1> +class LaplaceTerm<T1, T1> + : public BilinearTerm<T1, T1> // symmetric { protected: double diffusivity; -public : - LaplaceTerm(FunctionSpace<T1>& space1_, double diff = 1) : - BilinearTerm<T1, T1>(space1_, space1_), diffusivity(diff) {} + +public: + LaplaceTerm(FunctionSpace<T1> &space1_, double diff = 1) + : BilinearTerm<T1, T1>(space1_, space1_), diffusivity(diff) + { + } virtual ~LaplaceTerm() {} - virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector< fullMatrix<double> > &vm) const{}; - virtual BilinearTermBase* clone () const {return new LaplaceTerm< T1, T1 >(BilinearTerm<T1, T1>::space1,diffusivity);} + virtual void get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullMatrix<double> > &vm) const {}; + virtual BilinearTermBase *clone() const + { + return new LaplaceTerm<T1, T1>(BilinearTerm<T1, T1>::space1, diffusivity); + } }; // class -class IsotropicElasticTerm : public BilinearTerm<SVector3,SVector3> -{ -protected : +class IsotropicElasticTerm : public BilinearTerm<SVector3, SVector3> { +protected: double E, nu; bool sym; - fullMatrix<double> H;/* = - { {C11, C12, C12, 0, 0, 0}, - {C12, C11, C12, 0, 0, 0}, - {C12, C12, C11, 0, 0, 0}, - { 0, 0, 0, C44, 0, 0}, - { 0, 0, 0, 0, C44, 0}, - { 0, 0, 0, 0, 0, C44} };*/ -public : - IsotropicElasticTerm(FunctionSpace<SVector3>& space1_, FunctionSpace<SVector3>& space2_, double E_, double nu_); - IsotropicElasticTerm(FunctionSpace<SVector3>& space1_, double E_, double nu_); + fullMatrix<double> H; /* = + { {C11, C12, C12, 0, 0, 0}, + {C12, C11, C12, 0, 0, 0}, + {C12, C12, C11, 0, 0, 0}, + { 0, 0, 0, C44, 0, 0}, + { 0, 0, 0, 0, C44, 0}, + { 0, 0, 0, 0, 0, C44} };*/ +public: + IsotropicElasticTerm(FunctionSpace<SVector3> &space1_, + FunctionSpace<SVector3> &space2_, double E_, double nu_); + IsotropicElasticTerm(FunctionSpace<SVector3> &space1_, double E_, double nu_); virtual ~IsotropicElasticTerm() {} - virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector< fullMatrix<double> > &vm) const{}; - virtual BilinearTermBase* clone () const {return new IsotropicElasticTerm(BilinearTerm<SVector3, SVector3>::space1,BilinearTerm<SVector3, SVector3>::space2,E,nu);} + virtual void get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullMatrix<double> > &vm) const {}; + virtual BilinearTermBase *clone() const + { + return new IsotropicElasticTerm(BilinearTerm<SVector3, SVector3>::space1, + BilinearTerm<SVector3, SVector3>::space2, E, + nu); + } }; // class - -template<class T1> class LoadTerm : public LinearTerm<T1> -{ +template <class T1> class LoadTerm : public LinearTerm<T1> { protected: simpleFunction<typename TensorialTraits<T1>::ValType> *Load; -public : - LoadTerm(FunctionSpace<T1>& space1_, simpleFunction<typename TensorialTraits<T1>::ValType> *Load_) : - LinearTerm<T1>(space1_), Load(Load_) {} + +public: + LoadTerm(FunctionSpace<T1> &space1_, + simpleFunction<typename TensorialTraits<T1>::ValType> *Load_) + : LinearTerm<T1>(space1_), Load(Load_) + { + } virtual ~LoadTerm() {} - virtual LinearTermBase<double>* clone () const { return new LoadTerm<T1>(LinearTerm<T1>::space1,Load);} - virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<double> &m) const ; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<fullVector<double> > &vv) const {}; + virtual LinearTermBase<double> *clone() const + { + return new LoadTerm<T1>(LinearTerm<T1>::space1, Load); + } + virtual void get(MElement *ele, int npts, IntPt *GP, + fullVector<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullVector<double> > &vv) const {}; }; -template<class T1> class LagrangeMultiplierTerm : public BilinearTerm<T1, double> -{ +template <class T1> +class LagrangeMultiplierTerm : public BilinearTerm<T1, double> { T1 _d; -public : - LagrangeMultiplierTerm(FunctionSpace<T1>& space1_, FunctionSpace<double>& space2_, const T1 &d) : - BilinearTerm<T1, double>(space1_, space2_) + +public: + LagrangeMultiplierTerm(FunctionSpace<T1> &space1_, + FunctionSpace<double> &space2_, const T1 &d) + : BilinearTerm<T1, double>(space1_, space2_) { setDirection(_d, d); } virtual ~LagrangeMultiplierTerm() {} - virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector< fullMatrix<double> > &vm) const{}; - virtual BilinearTermBase* clone () const {return new LagrangeMultiplierTerm(BilinearTerm<T1, double>::space1, BilinearTerm<T1, double>::space2, _d);} + virtual void get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullMatrix<double> > &vm) const {}; + virtual BilinearTermBase *clone() const + { + return new LagrangeMultiplierTerm(BilinearTerm<T1, double>::space1, + BilinearTerm<T1, double>::space2, _d); + } }; -class LagMultTerm : public BilinearTerm<SVector3, SVector3> -{ -private : +class LagMultTerm : public BilinearTerm<SVector3, SVector3> { +private: double _eqfac; -public : - LagMultTerm(FunctionSpace<SVector3>& space1_, FunctionSpace<SVector3>& space2_, double eqfac = 1.0) : - BilinearTerm<SVector3, SVector3>(space1_, space2_), _eqfac(eqfac) {} + +public: + LagMultTerm(FunctionSpace<SVector3> &space1_, + FunctionSpace<SVector3> &space2_, double eqfac = 1.0) + : BilinearTerm<SVector3, SVector3>(space1_, space2_), _eqfac(eqfac) + { + } virtual ~LagMultTerm() {} - virtual void get(MElement *ele, int npts, IntPt *GP, fullMatrix<double> &m) const; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector< fullMatrix<double> > &vm) const{}; - virtual BilinearTermBase* clone () const {return new LagMultTerm(BilinearTerm<SVector3, SVector3>::space1,BilinearTerm<SVector3, SVector3>::space2,_eqfac);} + virtual void get(MElement *ele, int npts, IntPt *GP, + fullMatrix<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullMatrix<double> > &vm) const {}; + virtual BilinearTermBase *clone() const + { + return new LagMultTerm(BilinearTerm<SVector3, SVector3>::space1, + BilinearTerm<SVector3, SVector3>::space2, _eqfac); + } }; -template<class T1> class LoadTermOnBorder : public LinearTerm<T1> -{ -private : +template <class T1> class LoadTermOnBorder : public LinearTerm<T1> { +private: double _eqfac; simpleFunction<typename TensorialTraits<T1>::ValType> *Load; -public : - LoadTermOnBorder(FunctionSpace<T1>& space1_, simpleFunction<typename TensorialTraits<T1>::ValType> *Load_, double eqfac = 1.0) : - LinearTerm<T1>(space1_), _eqfac(eqfac), Load(Load_) {} + +public: + LoadTermOnBorder(FunctionSpace<T1> &space1_, + simpleFunction<typename TensorialTraits<T1>::ValType> *Load_, + double eqfac = 1.0) + : LinearTerm<T1>(space1_), _eqfac(eqfac), Load(Load_) + { + } virtual ~LoadTermOnBorder() {} - virtual LinearTermBase<double>* clone () const { return new LoadTermOnBorder<T1>(LinearTerm<T1>::space1,Load,_eqfac);} - virtual void get(MElement *ele, int npts, IntPt *GP, fullVector<double> &m) const ; - virtual void get(MElement *ele, int npts, IntPt *GP, std::vector<fullVector<double> > &vv) const {}; + virtual LinearTermBase<double> *clone() const + { + return new LoadTermOnBorder<T1>(LinearTerm<T1>::space1, Load, _eqfac); + } + virtual void get(MElement *ele, int npts, IntPt *GP, + fullVector<double> &m) const; + virtual void get(MElement *ele, int npts, IntPt *GP, + std::vector<fullVector<double> > &vv) const {}; }; #include "terms.hpp" -#endif// _TERMS_H_ +#endif // _TERMS_H_ diff --git a/Solver/thermicSolver.cpp b/Solver/thermicSolver.cpp index b7b135bd07545ec5012096d2084fc73bdf9abee6..931f640bcbbea83ea7bdc60809e667685fb593cc 100644 --- a/Solver/thermicSolver.cpp +++ b/Solver/thermicSolver.cpp @@ -30,10 +30,10 @@ void thermicSolver::setMesh(const std::string &meshFileName) pModel->readMSH(meshFileName.c_str()); _dim = pModel->getNumRegions() ? 3 : 2; - if (LagSpace) delete LagSpace; + if(LagSpace) delete LagSpace; LagSpace = new ScalarLagrangeFunctionSpace(_tag); - if (LagrangeMultiplierSpace) delete LagrangeMultiplierSpace; + if(LagrangeMultiplierSpace) delete LagrangeMultiplierSpace; LagrangeMultiplierSpace = new ScalarLagrangeFunctionSpaceOfElement(_tag + 1); } @@ -63,33 +63,34 @@ void thermicSolver::setThermicDomain(int phys, double k) thermicField field; field._k = k; field._tag = _tag; - field.g = new groupOfElements (_dim, phys); + field.g = new groupOfElements(_dim, phys); thermicFields.push_back(field); } void thermicSolver::changeLMTau(int tag, double tau) { - for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++){ - if(LagrangeMultiplierFields[i]._tag == tag){ + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++) { + if(LagrangeMultiplierFields[i]._tag == tag) { LagrangeMultiplierFields[i]._tau = tau; } } } -void thermicSolver::setLagrangeMultipliers(int phys, double tau, int tag, simpleFunction<double> *f) +void thermicSolver::setLagrangeMultipliers(int phys, double tau, int tag, + simpleFunction<double> *f) { LagrangeMultiplierFieldT field; field._tau = tau; field._tag = tag; field._f = f; - field.g = new groupOfElements (_dim - 1, phys); + field.g = new groupOfElements(_dim - 1, phys); LagrangeMultiplierFields.push_back(field); } void thermicSolver::setEdgeTemp(int edge, simpleFunction<double> *f) { dirichletBCT diri; - diri.g = new groupOfElements (1, edge); + diri.g = new groupOfElements(1, edge); diri._f = f; diri._tag = edge; diri.onWhat = BoundaryConditionT::ON_EDGE; @@ -99,7 +100,7 @@ void thermicSolver::setEdgeTemp(int edge, simpleFunction<double> *f) void thermicSolver::setFaceTemp(int face, simpleFunction<double> *f) { dirichletBCT diri; - diri.g = new groupOfElements (2, face); + diri.g = new groupOfElements(2, face); diri._f = f; diri._tag = face; diri.onWhat = BoundaryConditionT::ON_FACE; @@ -108,7 +109,7 @@ void thermicSolver::setFaceTemp(int face, simpleFunction<double> *f) void thermicSolver::assemble(linearSystem<double> *lsys) { - if (pAssembler) delete pAssembler; + if(pAssembler) delete pAssembler; pAssembler = new dofManager<double>(lsys); // we first do all fixations. the behavior of the dofManager is to @@ -116,24 +117,26 @@ void thermicSolver::assemble(linearSystem<double> *lsys) // numbered afterwards // Dirichlet conditions - for (unsigned int i = 0; i < allDirichlet.size(); i++){ + for(unsigned int i = 0; i < allDirichlet.size(); i++) { FilterDofTrivial filter; - FixNodalDofs(*LagSpace, allDirichlet[i].g->begin(), allDirichlet[i].g->end(), - *pAssembler, *allDirichlet[i]._f, filter); + FixNodalDofs(*LagSpace, allDirichlet[i].g->begin(), + allDirichlet[i].g->end(), *pAssembler, *allDirichlet[i]._f, + filter); } // LagrangeMultipliers - for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i){ + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i) { NumberDofs(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), *pAssembler); } // Thermic Fields - for (unsigned int i = 0; i < thermicFields.size(); ++i){ - NumberDofs(*LagSpace, thermicFields[i].g->begin(), thermicFields[i].g->end(), *pAssembler); + for(unsigned int i = 0; i < thermicFields.size(); ++i) { + NumberDofs(*LagSpace, thermicFields[i].g->begin(), + thermicFields[i].g->end(), *pAssembler); } // Neumann conditions GaussQuadrature Integ_Boundary(GaussQuadrature::Val); - for (unsigned int i = 0; i < allNeumann.size(); i++){ - std::cout << "Neumann BC" << std::endl; + for(unsigned int i = 0; i < allNeumann.size(); i++) { + std::cout << "Neumann BC" << std::endl; LoadTerm<double> Lterm(*LagSpace, allNeumann[i]._f); Assemble(Lterm, *LagSpace, allNeumann[i].g->begin(), allNeumann[i].g->end(), Integ_Boundary, *pAssembler); @@ -141,29 +144,34 @@ void thermicSolver::assemble(linearSystem<double> *lsys) // Assemble cross term, laplace term and rhs term for LM GaussQuadrature Integ_LagrangeMult(GaussQuadrature::ValVal); GaussQuadrature Integ_Laplace(GaussQuadrature::GradGrad); - for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++){ + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++) { printf("Lagrange Mult Lag\n"); - LagrangeMultiplierTerm<double> LagTerm(*LagSpace, *LagrangeMultiplierSpace, 1.); + LagrangeMultiplierTerm<double> LagTerm(*LagSpace, *LagrangeMultiplierSpace, + 1.); Assemble(LagTerm, *LagSpace, *LagrangeMultiplierSpace, - LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), - Integ_LagrangeMult, *pAssembler); + LagrangeMultiplierFields[i].g->begin(), + LagrangeMultiplierFields[i].g->end(), Integ_LagrangeMult, + *pAssembler); printf("Lagrange Mult Lap\n"); LaplaceTerm<double, double> LapTerm(*LagrangeMultiplierSpace, -LagrangeMultiplierFields[i]._tau); - Assemble(LapTerm, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), + Assemble(LapTerm, *LagrangeMultiplierSpace, + LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Laplace, *pAssembler); printf("Lagrange Mult Load\n"); - LoadTermOnBorder<double> Lterm(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i]._f); - Assemble(Lterm, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), + LoadTermOnBorder<double> Lterm(*LagrangeMultiplierSpace, + LagrangeMultiplierFields[i]._f); + Assemble(Lterm, *LagrangeMultiplierSpace, + LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Boundary, *pAssembler); } // Assemble thermic term GaussQuadrature Integ_Bulk(GaussQuadrature::ValVal); - for (unsigned int i = 0; i < thermicFields.size(); i++){ + for(unsigned int i = 0; i < thermicFields.size(); i++) { printf("Thermic Term\n"); LaplaceTerm<double, double> Tterm(*LagSpace, thermicFields[i]._k); - Assemble(Tterm, *LagSpace, thermicFields[i].g->begin(), thermicFields[i].g->end(), - Integ_Bulk, *pAssembler); + Assemble(Tterm, *LagSpace, thermicFields[i].g->begin(), + thermicFields[i].g->end(), Integ_Bulk, *pAssembler); } /*for (int i = 0;i<pAssembler->sizeOfR();i++){ @@ -179,132 +187,153 @@ void thermicSolver::assemble(linearSystem<double> *lsys) printf("nFixed=%d\n", pAssembler->sizeOfF()); } -double thermicSolver::computeL2Norm(simpleFunction<double> *sol) { +double thermicSolver::computeL2Norm(simpleFunction<double> *sol) +{ double val = 0.0; SolverField<double> solField(pAssembler, LagSpace); - for (unsigned int i = 0; i < thermicFields.size(); ++i){ - for (groupOfElements::elementContainer::const_iterator it = thermicFields[i].g->begin(); it != thermicFields[i].g->end(); ++it){ + for(unsigned int i = 0; i < thermicFields.size(); ++i) { + for(groupOfElements::elementContainer::const_iterator it = + thermicFields[i].g->begin(); + it != thermicFields[i].g->end(); ++it) { MElement *e = *it; -//printf("element (%g,%g) (%g,%g) (%g,%g)\n",e->getVertex(0)->x(),e->getVertex(0)->y(),e->getVertex(1)->x(),e->getVertex(1)->y(),e->getVertex(2)->x(),e->getVertex(2)->y()); + // printf("element (%g,%g) (%g,%g) + // (%g,%g)\n",e->getVertex(0)->x(),e->getVertex(0)->y(),e->getVertex(1)->x(),e->getVertex(1)->y(),e->getVertex(2)->x(),e->getVertex(2)->y()); int npts; IntPt *GP; double jac[3][3]; - int integrationOrder = 2 * (e->getPolynomialOrder()+5); + int integrationOrder = 2 * (e->getPolynomialOrder() + 5); e->getIntegrationPoints(integrationOrder, &npts, &GP); - for (int j = 0; j < npts; j++){ + for(int j = 0; j < npts; j++) { double u = GP[j].pt[0]; double v = GP[j].pt[1]; double w = GP[j].pt[2]; double weight = GP[j].weight; - double detJ = fabs(e->getJacobian (u, v, w, jac)); + double detJ = fabs(e->getJacobian(u, v, w, jac)); SPoint3 p; e->pnt(u, v, w, p); - double FEMVALUE; - solField.f(e, u, v, w, FEMVALUE); + double FEMVALUE; + solField.f(e, u, v, w, FEMVALUE); double diff = (*sol)(p.x(), p.y(), p.z()) - FEMVALUE; val += diff * diff * detJ * weight; -//printf("(%g %g) : detJ=%g we=%g FV=%g sol=%g diff=%g\n",p.x(),p.y(),detJ,weight,FEMVALUE,(*sol)(p.x(), p.y(), p.z()),diff); + // printf("(%g %g) : detJ=%g we=%g FV=%g sol=%g + // diff=%g\n",p.x(),p.y(),detJ,weight,FEMVALUE,(*sol)(p.x(), p.y(), + // p.z()),diff); } } } -printf("L2Norm = %g\n",sqrt(val)); + printf("L2Norm = %g\n", sqrt(val)); return sqrt(val); } -double thermicSolver::computeLagNorm(int tag, simpleFunction<double> *sol) { +double thermicSolver::computeLagNorm(int tag, simpleFunction<double> *sol) +{ double val = 0.0, val2 = 0.0; SolverField<double> solField(pAssembler, LagrangeMultiplierSpace); - for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i){ + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i) { if(tag != LagrangeMultiplierFields[i]._tag) continue; - for(groupOfElements::elementContainer::const_iterator it = LagrangeMultiplierFields[i].g->begin(); - it != LagrangeMultiplierFields[i].g->end(); ++it){ + for(groupOfElements::elementContainer::const_iterator it = + LagrangeMultiplierFields[i].g->begin(); + it != LagrangeMultiplierFields[i].g->end(); ++it) { MElement *e = *it; -//printf("element (%g,%g) (%g,%g)\n",e->getVertex(0)->x(),e->getVertex(0)->y(),e->getVertex(1)->x(),e->getVertex(1)->y()); + // printf("element (%g,%g) + // (%g,%g)\n",e->getVertex(0)->x(),e->getVertex(0)->y(),e->getVertex(1)->x(),e->getVertex(1)->y()); int npts; IntPt *GP; double jac[3][3]; - int integrationOrder = 2 * (e->getPolynomialOrder()+1); + int integrationOrder = 2 * (e->getPolynomialOrder() + 1); e->getIntegrationPoints(integrationOrder, &npts, &GP); - for (int j = 0; j < npts; j++){ + for(int j = 0; j < npts; j++) { double u = GP[j].pt[0]; double v = GP[j].pt[1]; double w = GP[j].pt[2]; double weight = GP[j].weight; - double detJ = fabs(e->getJacobian (u, v, w, jac)); + double detJ = fabs(e->getJacobian(u, v, w, jac)); SPoint3 p; e->getParent()->pnt(u, v, w, p); - double FEMVALUE; - solField.f(e, u, v, w, FEMVALUE); + double FEMVALUE; + solField.f(e, u, v, w, FEMVALUE); double diff = (*sol)(p.x(), p.y(), p.z()) - FEMVALUE; val += diff * diff * detJ * weight; - val2 += (*sol)(p.x(), p.y(), p.z()) * (*sol)(p.x(), p.y(), p.z()) * detJ * weight; -//printf("(%g %g) : u,v=(%g,%g) detJ=%g we=%g FV=%g sol=%g diff=%g\n",p.x(),p.y(),u,v,detJ,weight,FEMVALUE,(*sol)(p.x(), p.y(), p.z()),diff); + val2 += (*sol)(p.x(), p.y(), p.z()) * (*sol)(p.x(), p.y(), p.z()) * + detJ * weight; + // printf("(%g %g) : u,v=(%g,%g) detJ=%g we=%g FV=%g sol=%g + // diff=%g\n",p.x(),p.y(),u,v,detJ,weight,FEMVALUE,(*sol)(p.x(), p.y(), + // p.z()),diff); } } } -printf("LagNorm = %g\n",sqrt(val/val2)); - return sqrt(val/val2); + printf("LagNorm = %g\n", sqrt(val / val2)); + return sqrt(val / val2); } #if defined(HAVE_POST) -PView* thermicSolver::buildTemperatureView (const std::string postFileName) +PView *thermicSolver::buildTemperatureView(const std::string postFileName) { - std::cout << "build Temperature View"<< std::endl; - std::set<MVertex*> v; - std::map<MVertex*, MElement*> vCut; - for (unsigned int i = 0; i < thermicFields.size(); ++i){ - for (groupOfElements::elementContainer::const_iterator it = thermicFields[i].g->begin(); it != thermicFields[i].g->end(); ++it){ + std::cout << "build Temperature View" << std::endl; + std::set<MVertex *> v; + std::map<MVertex *, MElement *> vCut; + for(unsigned int i = 0; i < thermicFields.size(); ++i) { + for(groupOfElements::elementContainer::const_iterator it = + thermicFields[i].g->begin(); + it != thermicFields[i].g->end(); ++it) { MElement *e = *it; if(e->getParent()) { - for (std::size_t j = 0; j < e->getNumVertices(); ++j) { + for(std::size_t j = 0; j < e->getNumVertices(); ++j) { if(vCut.find(e->getVertex(j)) == vCut.end()) vCut[e->getVertex(j)] = e->getParent(); } } else { - for (std::size_t j = 0; j < e->getNumVertices(); ++j) + for(std::size_t j = 0; j < e->getNumVertices(); ++j) v.insert(e->getVertex(j)); } } } std::map<int, std::vector<double> > data; SolverField<double> Field(pAssembler, LagSpace); - for (std::set<MVertex*>::iterator it = v.begin(); it != v.end(); ++it){ + for(std::set<MVertex *>::iterator it = v.begin(); it != v.end(); ++it) { double val; MPoint p(*it); - Field.f(&p, 0, 0, 0, val); //printf("valv=%g\n",val); - std::vector<double> vec; vec.push_back(val); + Field.f(&p, 0, 0, 0, val); // printf("valv=%g\n",val); + std::vector<double> vec; + vec.push_back(val); data[(*it)->getNum()] = vec; } - for (std::map<MVertex*, MElement*>::iterator it = vCut.begin(); it != vCut.end(); ++it){ + for(std::map<MVertex *, MElement *>::iterator it = vCut.begin(); + it != vCut.end(); ++it) { double val; double uvw[3]; double xyz[3] = {it->first->x(), it->first->y(), it->first->z()}; it->second->xyz2uvw(xyz, uvw); - Field.f(it->second, uvw[0], uvw[1], uvw[2], val); //printf("valvc=%g\n",val); - std::vector<double> vec; vec.push_back(val); + Field.f(it->second, uvw[0], uvw[1], uvw[2], + val); // printf("valvc=%g\n",val); + std::vector<double> vec; + vec.push_back(val); data[it->first->getNum()] = vec; } - PView *pv = new PView (postFileName, "NodeData", pModel, data, 0.0, 1); + PView *pv = new PView(postFileName, "NodeData", pModel, data, 0.0, 1); return pv; } -PView* thermicSolver::buildLagrangeMultiplierView (const std::string postFileName) +PView * +thermicSolver::buildLagrangeMultiplierView(const std::string postFileName) { - std::cout << "build Lagrange Multiplier View"<< std::endl; + std::cout << "build Lagrange Multiplier View" << std::endl; if(!LagrangeMultiplierSpace) return new PView(); - std::set<MVertex*> v; - for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i){ - for(groupOfElements::elementContainer::const_iterator it = LagrangeMultiplierFields[i].g->begin(); - it != LagrangeMultiplierFields[i].g->end(); ++it){ + std::set<MVertex *> v; + for(unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i) { + for(groupOfElements::elementContainer::const_iterator it = + LagrangeMultiplierFields[i].g->begin(); + it != LagrangeMultiplierFields[i].g->end(); ++it) { MElement *e = *it; - for (std::size_t j = 0; j < e->getNumVertices(); ++j) v.insert(e->getVertex(j)); + for(std::size_t j = 0; j < e->getNumVertices(); ++j) + v.insert(e->getVertex(j)); } } std::map<int, std::vector<double> > data; SolverField<double> Field(pAssembler, LagrangeMultiplierSpace); - for(std::set<MVertex*>::iterator it = v.begin(); it != v.end(); ++it){ + for(std::set<MVertex *>::iterator it = v.begin(); it != v.end(); ++it) { double val; MPoint p(*it); Field.f(&p, 0, 0, 0, val); @@ -312,37 +341,38 @@ PView* thermicSolver::buildLagrangeMultiplierView (const std::string postFileNam vec.push_back(val); data[(*it)->getNum()] = vec; } - PView *pv = new PView (postFileName, "NodeData", pModel, data, 0.0, 1); + PView *pv = new PView(postFileName, "NodeData", pModel, data, 0.0, 1); return pv; } -PView* thermicSolver::buildErrorEstimateView(const std::string errorFileName, +PView *thermicSolver::buildErrorEstimateView(const std::string errorFileName, simpleFunction<double> *sol) { - std::cout << "build Error View"<< std::endl; + std::cout << "build Error View" << std::endl; std::map<int, std::vector<double> > data; SolverField<double> solField(pAssembler, LagSpace); - for (unsigned int i = 0; i < thermicFields.size(); ++i){ - for (groupOfElements::elementContainer::const_iterator it = - thermicFields[i].g->begin(); it != thermicFields[i].g->end(); ++it){ + for(unsigned int i = 0; i < thermicFields.size(); ++i) { + for(groupOfElements::elementContainer::const_iterator it = + thermicFields[i].g->begin(); + it != thermicFields[i].g->end(); ++it) { MElement *e = *it; int npts; IntPt *GP; double jac[3][3]; - int integrationOrder = 2 * (e->getPolynomialOrder()+5); + int integrationOrder = 2 * (e->getPolynomialOrder() + 5); e->getIntegrationPoints(integrationOrder, &npts, &GP); double val = 0.0; - for (int j = 0; j < npts; j++){ + for(int j = 0; j < npts; j++) { double u = GP[j].pt[0]; double v = GP[j].pt[1]; double w = GP[j].pt[2]; double weight = GP[j].weight; - double detJ = fabs(e->getJacobian (u, v, w, jac)); + double detJ = fabs(e->getJacobian(u, v, w, jac)); SPoint3 p; e->pnt(u, v, w, p); - double FEMVALUE; - solField.f(e, u, v, w, FEMVALUE); + double FEMVALUE; + solField.f(e, u, v, w, FEMVALUE); double diff = (*sol)(p.x(), p.y(), p.z()) - FEMVALUE; val += diff * diff * detJ * weight; } @@ -352,24 +382,25 @@ PView* thermicSolver::buildErrorEstimateView(const std::string errorFileName, } } - PView *pv = new PView (errorFileName, "ElementData", pModel, data, 0.0, 1); + PView *pv = new PView(errorFileName, "ElementData", pModel, data, 0.0, 1); return pv; } #else -PView* thermicSolver::buildTemperatureView(const std::string postFileName) +PView *thermicSolver::buildTemperatureView(const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; } -PView* thermicSolver::buildLagrangeMultiplierView (const std::string postFileName) +PView * +thermicSolver::buildLagrangeMultiplierView(const std::string postFileName) { Msg::Error("Post-pro module not available"); return 0; } -PView* thermicSolver::buildErrorEstimateView(const std::string errorFileName, +PView *thermicSolver::buildErrorEstimateView(const std::string errorFileName, simpleFunction<double> *sol) { Msg::Error("Post-pro module not available"); diff --git a/Solver/thermicSolver.h b/Solver/thermicSolver.h index d884c6f5140334f01db0a316c583eb1070403776..0b111ae5a9d2656545bf389c82daa13162af4078 100644 --- a/Solver/thermicSolver.h +++ b/Solver/thermicSolver.h @@ -23,40 +23,36 @@ struct LagrangeMultiplierFieldT { groupOfElements *g; double _tau; simpleFunction<double> *_f; - LagrangeMultiplierFieldT() : _tag(0), g(0){} + LagrangeMultiplierFieldT() : _tag(0), g(0) {} }; struct thermicField { int _tag; // tag for the dofManager groupOfElements *g; // support for this field double _k; // diffusivity - thermicField () : _tag(0), g(0){} + thermicField() : _tag(0), g(0) {} }; -struct BoundaryConditionT -{ +struct BoundaryConditionT { int _tag; // tag for the dofManager - enum location{UNDEF, ON_VERTEX, ON_EDGE, ON_FACE, ON_VOLUME}; + enum location { UNDEF, ON_VERTEX, ON_EDGE, ON_FACE, ON_VOLUME }; location onWhat; // on vertices or elements groupOfElements *g; // support for this BC BoundaryConditionT() : _tag(0), onWhat(UNDEF), g(0) {} }; -struct dirichletBCT : public BoundaryConditionT -{ +struct dirichletBCT : public BoundaryConditionT { simpleFunction<double> *_f; - dirichletBCT ():BoundaryConditionT(), _f(0){} + dirichletBCT() : BoundaryConditionT(), _f(0) {} }; -struct neumannBCT : public BoundaryConditionT -{ +struct neumannBCT : public BoundaryConditionT { simpleFunction<double> *_f; - neumannBCT () : BoundaryConditionT(), _f(0){} + neumannBCT() : BoundaryConditionT(), _f(0) {} }; // a thermic solver ... -class thermicSolver -{ - protected: +class thermicSolver { +protected: GModel *pModel; int _dim, _tag; dofManager<double> *pAssembler; @@ -71,20 +67,24 @@ class thermicSolver // dirichlet BC std::vector<dirichletBCT> allDirichlet; - public: - thermicSolver(int tag) : _tag(tag), pAssembler(0), LagSpace(0), LagrangeMultiplierSpace(0) {} +public: + thermicSolver(int tag) + : _tag(tag), pAssembler(0), LagSpace(0), LagrangeMultiplierSpace(0) + { + } virtual ~thermicSolver() { - if (LagSpace) delete LagSpace; - if (LagrangeMultiplierSpace) delete LagrangeMultiplierSpace; - if (pAssembler) delete pAssembler; + if(LagSpace) delete LagSpace; + if(LagrangeMultiplierSpace) delete LagrangeMultiplierSpace; + if(pAssembler) delete pAssembler; } - void assemble (linearSystem<double> *lsys); + void assemble(linearSystem<double> *lsys); virtual void setMesh(const std::string &meshFileName); void cutMesh(gLevelset *ls); void setThermicDomain(int phys, double k); - void setLagrangeMultipliers(int phys, double tau, int tag, simpleFunction<double> *f); + void setLagrangeMultipliers(int phys, double tau, int tag, + simpleFunction<double> *f); void changeLMTau(int tag, double tau); void setEdgeTemp(int edge, simpleFunction<double> *f); void setFaceTemp(int face, simpleFunction<double> *f); @@ -93,10 +93,11 @@ class thermicSolver virtual PView *buildLagrangeMultiplierView(const std::string postFileName); double computeL2Norm(simpleFunction<double> *f); double computeLagNorm(int tag, simpleFunction<double> *f); - PView* buildErrorEstimateView(const std::string errorFileName, + PView *buildErrorEstimateView(const std::string errorFileName, simpleFunction<double> *sol); // std::pair<PView *, PView*> buildErrorEstimateView - // (const std::string &errorFileName, const elasticityData &ref, double, int); + // (const std::string &errorFileName, const elasticityData &ref, double, + // int); }; #endif diff --git a/utils/solvers/c++/GmshSocket.h b/utils/solvers/c++/GmshSocket.h index a73ce324a4e25610aed691c0496a9862c901e99f..4f6129ff8ceac515033b6df462ddb48665a4b8e2 100644 --- a/utils/solvers/c++/GmshSocket.h +++ b/utils/solvers/c++/GmshSocket.h @@ -104,10 +104,10 @@ class GmshSocket{ int _SendData(const void *buffer, int bytes) { const char *buf = (const char *)buffer; - int sofar = 0; - int remaining = bytes; + long int sofar = 0; + long int remaining = bytes; do { - int len = send(_sock, buf + sofar, remaining, 0); + long int len = send(_sock, buf + sofar, remaining, 0); if(len < 0) return -1; // error sofar += len; remaining -= len; @@ -119,10 +119,10 @@ class GmshSocket{ int _ReceiveData(void *buffer, int bytes) { char *buf = (char *)buffer; - int sofar = 0; - int remaining = bytes; + long int sofar = 0; + long int remaining = bytes; do { - int len = recv(_sock, buf + sofar, remaining, 0); + long int len = recv(_sock, buf + sofar, remaining, 0); if(len == 0) break; // we're done! if(len < 0) return -1; // error sofar += len; diff --git a/utils/solvers/c++/onelab.h b/utils/solvers/c++/onelab.h index 422e65bb3e9dba9a1aabb8dcaafdfe108a5b81bb..5110640338410699272dfe4b5607cd85e2737556 100644 --- a/utils/solvers/c++/onelab.h +++ b/utils/solvers/c++/onelab.h @@ -44,7 +44,7 @@ #include "picojson.h" #endif -namespace onelab{ +namespace onelab { // The base parameter class. class parameter { @@ -74,40 +74,42 @@ namespace onelab{ bool _visible; // sould the paramete be "read-only" (not settable by the user) bool _readOnly; + protected: // optional additional attributes std::map<std::string, std::string> _attributes; + public: - parameter(const std::string &name="", const std::string &label="", - const std::string &help="") + parameter(const std::string &name = "", const std::string &label = "", + const std::string &help = "") : _name(name), _label(label), _help(help), _visible(true), _readOnly(false) { _changedValue = defaultChangedValue(); } - virtual ~parameter(){} - void setName(const std::string &name){ _name = name; } - void setLabel(const std::string &label){ _label = label; } - void setHelp(const std::string &help){ _help = help; } - void setChanged(int changed, const std::string &client="") + virtual ~parameter() {} + void setName(const std::string &name) { _name = name; } + void setLabel(const std::string &label) { _label = label; } + void setHelp(const std::string &help) { _help = help; } + void setChanged(int changed, const std::string &client = "") { - if(client.size()){ + if(client.size()) { std::map<std::string, int>::iterator it = _clients.find(client); if(it != _clients.end()) it->second = changed; } - else{ + else { for(std::map<std::string, int>::iterator it = _clients.begin(); it != _clients.end(); it++) it->second = changed; } } - void setChangedValue(int value){ _changedValue = value; } + void setChangedValue(int value) { _changedValue = value; } void setNeverChanged(bool never) { _changedValue = never ? 0 : defaultChangedValue(); } - void setVisible(bool visible){ _visible = visible; } - void setReadOnly(bool readOnly){ _readOnly = readOnly; } + void setVisible(bool visible) { _visible = visible; } + void setReadOnly(bool readOnly) { _readOnly = readOnly; } void setAttribute(const std::string &key, const std::string &value) { _attributes[key] = value; @@ -116,11 +118,13 @@ namespace onelab{ { _attributes = attributes; } - void setClients(const std::map<std::string, int> &clients){ _clients = clients; } + void setClients(const std::map<std::string, int> &clients) + { + _clients = clients; + } void addClient(const std::string &client, int changed) { - if(_clients.find(client) == _clients.end()) - _clients[client] = changed; + if(_clients.find(client) == _clients.end()) _clients[client] = changed; } void addClients(const std::map<std::string, int> &clients) { @@ -143,7 +147,7 @@ namespace onelab{ std::string getShortName() const { std::string units = getAttribute("Units"); - if(_label.size()){ + if(_label.size()) { if(units.empty()) return _label; else @@ -152,35 +156,33 @@ namespace onelab{ std::string s = _name; // remove path std::string::size_type last = _name.find_last_of('/'); - if(last != std::string::npos) - s = _name.substr(last + 1); + if(last != std::string::npos) s = _name.substr(last + 1); // remove starting white space - while(s.size() && s[0] == ' ') - s = s.substr(1); + while(s.size() && s[0] == ' ') s = s.substr(1); // remove starting braces: can be used to order parameters 'from the end', // as the ASCII code is after numbers and letters - while(s.size() && (s[0] == '}' || s[0] == '{')) - s = s.substr(1); + while(s.size() && (s[0] == '}' || s[0] == '{')) s = s.substr(1); // remove starting numbers: can be used to order parameters 'from the // start' - while(s.size() && s[0] >= '0' && s[0] <= '9') - s = s.substr(1); + while(s.size() && s[0] >= '0' && s[0] <= '9') s = s.substr(1); if(units.empty()) return s; else return s + " [" + units + "]"; } - int getChanged(const std::string &client="") const + int getChanged(const std::string &client = "") const { - if(client.size()){ + if(client.size()) { std::map<std::string, int>::const_iterator it = _clients.find(client); - if(it != _clients.end()) return it->second; - else return 0; + if(it != _clients.end()) + return it->second; + else + return 0; } - else{ + else { int changed = 0; for(std::map<std::string, int>::const_iterator it = _clients.begin(); - it != _clients.end(); it++){ + it != _clients.end(); it++) { changed = std::max(changed, it->second); } return changed; @@ -192,7 +194,8 @@ namespace onelab{ bool getReadOnly() const { return _readOnly; } std::string getAttribute(const std::string &key) const { - std::map<std::string, std::string>::const_iterator it = _attributes.find(key); + std::map<std::string, std::string>::const_iterator it = + _attributes.find(key); if(it != _attributes.end()) return it->second; return ""; } @@ -207,27 +210,27 @@ namespace onelab{ static int defaultChangedValue() { return 31; } static std::string getNextToken(const std::string &msg, std::string::size_type &first, - char separator=charSep()) + char separator = charSep()) { if(first == std::string::npos) return ""; std::string::size_type last = msg.find_first_of(separator, first); std::string next(""); - if(last == std::string::npos){ + if(last == std::string::npos) { next = msg.substr(first); first = last; } - else if(first == last){ + else if(first == last) { next = ""; first = last + 1; } - else{ + else { next = msg.substr(first, last - first); first = last + 1; } return next; } static std::vector<std::string> split(const std::string &msg, - char separator=charSep()) + char separator = charSep()) { std::vector<std::string> out; std::string::size_type first = 0; @@ -239,8 +242,7 @@ namespace onelab{ const std::string &whitespace = " \t\n") { std::string::size_type strBegin = str.find_first_not_of(whitespace); - if(strBegin == std::string::npos) - return ""; // no content + if(strBegin == std::string::npos) return ""; // no content std::string::size_type strEnd = str.find_last_not_of(whitespace); std::string::size_type strRange = strEnd - strBegin + 1; return str.substr(strBegin, strRange); @@ -256,22 +258,21 @@ namespace onelab{ { std::ostringstream sstream; sstream << version() << charSep() << getType() << charSep() - << sanitize(getName()) << charSep() - << sanitize(getLabel()) << charSep() - << sanitize(getHelp()) << charSep() - << getChangedValue() << charSep() - << (getVisible() ? 1 : 0) << charSep() - << (getReadOnly() ? 1 : 0) << charSep() + << sanitize(getName()) << charSep() << sanitize(getLabel()) + << charSep() << sanitize(getHelp()) << charSep() + << getChangedValue() << charSep() << (getVisible() ? 1 : 0) + << charSep() << (getReadOnly() ? 1 : 0) << charSep() << _attributes.size() << charSep(); - for(std::map<std::string, std::string>::const_iterator it = _attributes.begin(); + for(std::map<std::string, std::string>::const_iterator it = + _attributes.begin(); it != _attributes.end(); it++) - sstream << sanitize(it->first) << charSep() - << sanitize(it->second) << charSep(); + sstream << sanitize(it->first) << charSep() << sanitize(it->second) + << charSep(); sstream << getClients().size() << charSep(); for(std::map<std::string, int>::const_iterator it = getClients().begin(); it != getClients().end(); it++) - sstream << sanitize(it->first) << charSep() - << (it->second ? 1 : 0) << charSep(); + sstream << sanitize(it->first) << charSep() << (it->second ? 1 : 0) + << charSep(); return sstream.str(); } virtual std::string::size_type fromChar(const std::string &msg) @@ -286,12 +287,12 @@ namespace onelab{ setVisible(atoi(getNextToken(msg, pos).c_str())); setReadOnly(atoi(getNextToken(msg, pos).c_str())); int numAttributes = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < numAttributes; i++){ + for(int i = 0; i < numAttributes; i++) { std::string key(getNextToken(msg, pos)); setAttribute(key, getNextToken(msg, pos)); } int numClients = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < numClients; i++){ + for(int i = 0; i < numClients; i++) { std::string client(getNextToken(msg, pos)); int changed = atoi(getNextToken(msg, pos).c_str()); addClient(client, changed); @@ -311,13 +312,12 @@ namespace onelab{ msg.clear(); char tmp[1000]; if(!fgets(tmp, sizeof(tmp), fp)) return false; // first line is comment - while(!feof(fp)){ + while(!feof(fp)) { int numc = 0; if(!fscanf(fp, "%d ", &numc)) break; // space is important if(!numc) break; msg.push_back(""); - for(int i = 0; i < numc; i++) - msg.back() += fgetc(fp); + for(int i = 0; i < numc; i++) msg.back() += fgetc(fp); if(!fgets(tmp, sizeof(tmp), fp)) break; // end of line } return true; @@ -327,12 +327,11 @@ namespace onelab{ { time_t now; time(&now); - fprintf(fp, "ONELAB database created by %s on %s", - creator.c_str(), ctime(&now)); - for(unsigned int i = 0; i < msg.size(); i++){ + fprintf(fp, "ONELAB database created by %s on %s", creator.c_str(), + ctime(&now)); + for(unsigned int i = 0; i < msg.size(); i++) { fprintf(fp, "%d ", (int)msg[i].size()); - for(unsigned int j = 0; j < msg[i].size(); j++) - fputc(msg[i][j], fp); + for(unsigned int j = 0; j < msg[i].size(); j++) fputc(msg[i][j], fp); fputc('\n', fp); } return true; @@ -354,69 +353,75 @@ namespace onelab{ sstream << ", \"changedValue\":" << getChangedValue() << ", \"visible\":" << (getVisible() ? "true" : "false") << ", \"readOnly\":" << (getReadOnly() ? "true" : "false"); - if(_attributes.size()){ + if(_attributes.size()) { sstream << ", \"attributes\":{ "; - for(std::map<std::string, std::string>::const_iterator it = _attributes.begin(); - it != _attributes.end(); it++){ + for(std::map<std::string, std::string>::const_iterator it = + _attributes.begin(); + it != _attributes.end(); it++) { if(it != _attributes.begin()) sstream << ", "; sstream << "\"" << sanitizeJSON(it->first) << "\":\"" << sanitizeJSON(it->second) << "\""; } sstream << " }"; } - if(getClients().size()){ + if(getClients().size()) { sstream << ", \"clients\":{ "; - for(std::map<std::string, int>::const_iterator it = getClients().begin(); - it != getClients().end(); it++){ + for(std::map<std::string, int>::const_iterator it = + getClients().begin(); + it != getClients().end(); it++) { if(it != getClients().begin()) sstream << ", "; - sstream << "\"" << sanitizeJSON(it->first) << "\":" - << it->second; + sstream << "\"" << sanitizeJSON(it->first) << "\":" << it->second; } sstream << " }"; } return sstream.str(); } #if defined(HAVE_PICOJSON) - virtual bool fromJSON(const picojson::value::object& par) + virtual bool fromJSON(const picojson::value::object &par) { - for(picojson::value::object::const_iterator it = par.begin(); it != par.end(); ++it){ - if(it->first == "name"){ + for(picojson::value::object::const_iterator it = par.begin(); + it != par.end(); ++it) { + if(it->first == "name") { if(!it->second.is<std::string>()) return false; setName(it->second.get<std::string>()); } - else if(it->first == "label"){ + else if(it->first == "label") { if(!it->second.is<std::string>()) return false; setLabel(it->second.get<std::string>()); } - else if(it->first == "help"){ + else if(it->first == "help") { if(!it->second.is<std::string>()) return false; setHelp(it->second.get<std::string>()); } - else if(it->first == "changedValue"){ + else if(it->first == "changedValue") { if(!it->second.is<double>()) return false; setChangedValue((int)it->second.get<double>()); } - else if(it->first == "visible"){ + else if(it->first == "visible") { if(!it->second.is<bool>()) return false; setVisible(it->second.get<bool>()); } - else if(it->first == "readOnly"){ + else if(it->first == "readOnly") { if(!it->second.is<bool>()) return false; setReadOnly(it->second.get<bool>()); } - else if(it->first == "attributes"){ + else if(it->first == "attributes") { if(!it->second.is<picojson::object>()) return false; - const picojson::value::object &obj = it->second.get<picojson::object>(); - for (picojson::value::object::const_iterator i = obj.begin(); i != obj.end(); ++i) { + const picojson::value::object &obj = + it->second.get<picojson::object>(); + for(picojson::value::object::const_iterator i = obj.begin(); + i != obj.end(); ++i) { std::string key(i->first); if(!i->second.is<std::string>()) return false; setAttribute(key, i->second.get<std::string>()); } } - else if(it->first == "clients"){ + else if(it->first == "clients") { if(!it->second.is<picojson::object>()) return false; - const picojson::value::object &obj = it->second.get<picojson::object>(); - for (picojson::value::object::const_iterator i = obj.begin(); i != obj.end(); ++i) { + const picojson::value::object &obj = + it->second.get<picojson::object>(); + for(picojson::value::object::const_iterator i = obj.begin(); + i != obj.end(); ++i) { std::string client(i->first); if(!i->second.is<double>()) return false; addClient(client, (int)i->second.get<double>()); @@ -428,7 +433,7 @@ namespace onelab{ #endif }; - class parameterLessThan{ + class parameterLessThan { public: bool operator()(const parameter *p1, const parameter *p2) const { @@ -438,7 +443,7 @@ namespace onelab{ // The number class. Numbers are stored internally as double precision real // numbers. - class number : public parameter{ + class number : public parameter { private: std::vector<double> _values, _choices; double _min, _max, _step; @@ -446,22 +451,31 @@ namespace onelab{ // when not in a loop int _index; std::map<double, std::string> _valueLabels; + public: - number(const std::string &name="", double value=0., - const std::string &label="", const std::string &help="") + number(const std::string &name = "", double value = 0., + const std::string &label = "", const std::string &help = "") : parameter(name, label, help), _values(std::vector<double>(1, value)), - _min(-maxNumber()), _max(maxNumber()), _step(0.), _index(-1){} + _min(-maxNumber()), _max(maxNumber()), _step(0.), _index(-1) + { + } number(const std::string &name, const std::vector<double> &values, - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _values(values), - _min(-maxNumber()), _max(maxNumber()), _step(0.), _index(-1){} - void setValue(double value){ _values.resize(1); _values[0] = value; } - void setValues(const std::vector<double> &values){ _values = values; } - void setMin(double min){ _min = min; } - void setMax(double max){ _max = max; } - void setStep(double step){ _step = step; } - void setIndex(int index){ _index = index; } - void setChoices(const std::vector<double> &choices){ _choices = choices; } + const std::string &label = "", const std::string &help = "") + : parameter(name, label, help), _values(values), _min(-maxNumber()), + _max(maxNumber()), _step(0.), _index(-1) + { + } + void setValue(double value) + { + _values.resize(1); + _values[0] = value; + } + void setValues(const std::vector<double> &values) { _values = values; } + void setMin(double min) { _min = min; } + void setMax(double max) { _max = max; } + void setStep(double step) { _step = step; } + void setIndex(int index) { _index = index; } + void setChoices(const std::vector<double> &choices) { _choices = choices; } void setChoiceLabels(const std::vector<std::string> &labels) { if(labels.size() != _choices.size()) return; @@ -478,7 +492,11 @@ namespace onelab{ _valueLabels[value] = label; } std::string getType() const { return "number"; } - double getValue() const { if(_values.empty()) return 0.; return _values[0]; } + double getValue() const + { + if(_values.empty()) return 0.; + return _values[0]; + } const std::vector<double> &getValues() const { return _values; } unsigned int getNumValues() const { return _values.size(); } double getMin() const { return _min; } @@ -492,7 +510,8 @@ namespace onelab{ } std::string getValueLabel(double value) const { - std::map<double, std::string>::const_iterator it = _valueLabels.find(value); + std::map<double, std::string>::const_iterator it = + _valueLabels.find(value); if(it != _valueLabels.end()) return it->second; return ""; } @@ -505,13 +524,13 @@ namespace onelab{ setReadOnly(p.getReadOnly()); setAttributes(p.getAttributes()); bool changed = false; - for(unsigned int i = 0; i < p.getValues().size(); i++){ - if(p.getValues()[i] != getValues()[i]){ + for(unsigned int i = 0; i < p.getValues().size(); i++) { + if(p.getValues()[i] != getValues()[i]) { changed = true; break; } } - if(changed){ + if(changed) { setValues(p.getValues()); setChanged(getChangedValue()); } @@ -527,22 +546,18 @@ namespace onelab{ { std::ostringstream sstream; sstream.precision(16); - sstream << parameter::toChar() - << _values.size() << charSep(); + sstream << parameter::toChar() << _values.size() << charSep(); for(unsigned int i = 0; i < _values.size(); i++) sstream << _values[i] << charSep(); - sstream << _min << charSep() - << _max << charSep() - << _step << charSep() - << _index << charSep() - << _choices.size() << charSep(); + sstream << _min << charSep() << _max << charSep() << _step << charSep() + << _index << charSep() << _choices.size() << charSep(); for(unsigned int i = 0; i < _choices.size(); i++) sstream << _choices[i] << charSep(); sstream << _valueLabels.size() << charSep(); - for(std::map<double, std::string>::const_iterator it = _valueLabels.begin(); - it != _valueLabels.end(); it++){ - sstream << it->first << charSep() - << sanitize(it->second) << charSep(); + for(std::map<double, std::string>::const_iterator it = + _valueLabels.begin(); + it != _valueLabels.end(); it++) { + sstream << it->first << charSep() << sanitize(it->second) << charSep(); } return sstream.str(); } @@ -561,7 +576,7 @@ namespace onelab{ for(unsigned int i = 0; i < _choices.size(); i++) _choices[i] = atof(getNextToken(msg, pos).c_str()); int numValueLabels = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < numValueLabels; i++){ + for(int i = 0; i < numValueLabels; i++) { double value = atof(getNextToken(msg, pos).c_str()); _valueLabels[value] = getNextToken(msg, pos); } @@ -571,29 +586,27 @@ namespace onelab{ { std::ostringstream sstream; sstream.precision(16); - sstream << "{ " << parameter::toJSON() - << ", \"values\":[ "; - for(unsigned int i = 0; i < _values.size(); i++){ + sstream << "{ " << parameter::toJSON() << ", \"values\":[ "; + for(unsigned int i = 0; i < _values.size(); i++) { if(i) sstream << ", "; sstream << _values[i]; } sstream << " ]" - << ", \"min\":" << _min - << ", \"max\":" << _max - << ", \"step\":" << _step - << ", \"index\":" << _index; - if(_choices.size()){ + << ", \"min\":" << _min << ", \"max\":" << _max + << ", \"step\":" << _step << ", \"index\":" << _index; + if(_choices.size()) { sstream << ", \"choices\":[ "; - for(unsigned int i = 0; i < _choices.size(); i++){ + for(unsigned int i = 0; i < _choices.size(); i++) { if(i) sstream << ", "; sstream << _choices[i]; } sstream << " ]"; } - if(_valueLabels.size()){ + if(_valueLabels.size()) { sstream << ", \"valueLabels\":{ "; - for(std::map<double, std::string>::const_iterator it = _valueLabels.begin(); - it != _valueLabels.end(); it++){ + for(std::map<double, std::string>::const_iterator it = + _valueLabels.begin(); + it != _valueLabels.end(); it++) { if(it != _valueLabels.begin()) sstream << ", "; sstream << "\"" << sanitizeJSON(it->second) << "\":" << it->first; } @@ -603,48 +616,51 @@ namespace onelab{ return sstream.str(); } #if defined(HAVE_PICOJSON) - bool fromJSON(const picojson::value::object& par) + bool fromJSON(const picojson::value::object &par) { if(!parameter::fromJSON(par)) return false; - for(picojson::value::object::const_iterator it = par.begin(); it != par.end(); ++it){ - if(it->first == "values"){ + for(picojson::value::object::const_iterator it = par.begin(); + it != par.end(); ++it) { + if(it->first == "values") { if(!it->second.is<picojson::array>()) return false; const picojson::value::array &arr = it->second.get<picojson::array>(); _values.resize(arr.size()); - for(unsigned int i = 0; i < arr.size(); i++){ + for(unsigned int i = 0; i < arr.size(); i++) { if(!arr[i].is<double>()) return false; _values[i] = arr[i].get<double>(); } } - else if(it->first == "min"){ + else if(it->first == "min") { if(!it->second.is<double>()) return false; setMin(it->second.get<double>()); } - else if(it->first == "max"){ + else if(it->first == "max") { if(!it->second.is<double>()) return false; setMax(it->second.get<double>()); } - else if(it->first == "step"){ + else if(it->first == "step") { if(!it->second.is<double>()) return false; setStep(it->second.get<double>()); } - else if(it->first == "index"){ + else if(it->first == "index") { if(!it->second.is<double>()) return false; setIndex((int)it->second.get<double>()); } - else if(it->first == "choices"){ + else if(it->first == "choices") { if(!it->second.is<picojson::array>()) return false; const picojson::value::array &arr = it->second.get<picojson::array>(); _choices.resize(arr.size()); - for(unsigned int i = 0; i < arr.size(); i++){ + for(unsigned int i = 0; i < arr.size(); i++) { if(!arr[i].is<double>()) return false; _choices[i] = arr[i].get<double>(); } } - else if(it->first == "valueLabels"){ + else if(it->first == "valueLabels") { if(!it->second.is<picojson::object>()) return false; - const picojson::value::object &obj = it->second.get<picojson::object>(); - for (picojson::value::object::const_iterator i = obj.begin(); i != obj.end(); ++i) { + const picojson::value::object &obj = + it->second.get<picojson::object>(); + for(picojson::value::object::const_iterator i = obj.begin(); + i != obj.end(); ++i) { if(!i->second.is<double>()) return false; _valueLabels[i->second.get<double>()] = i->first; } @@ -657,28 +673,40 @@ namespace onelab{ // The string class. A string has a mutable "kind", that can be changed at // runtime. Kinds leading to specific behavior in Gmsh are: "file". - class string : public parameter{ + class string : public parameter { private: std::vector<std::string> _values, _choices; std::string _kind; + public: - string(const std::string &name="", const std::string &value="", - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _values(std::vector<std::string>(1, value)), - _kind("generic") {} + string(const std::string &name = "", const std::string &value = "", + const std::string &label = "", const std::string &help = "") + : parameter(name, label, help), + _values(std::vector<std::string>(1, value)), _kind("generic") + { + } string(const std::string &name, const std::vector<std::string> &values, - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _values(values), - _kind("generic") {} - void setValue(const std::string &value){ _values.resize(1); _values[0] = value; } - void setValues(const std::vector<std::string> &values){ _values = values; } - void setKind(const std::string &kind){ _kind = kind; } - void setChoices(const std::vector<std::string> &choices){ _choices = choices; } + const std::string &label = "", const std::string &help = "") + : parameter(name, label, help), _values(values), _kind("generic") + { + } + void setValue(const std::string &value) + { + _values.resize(1); + _values[0] = value; + } + void setValues(const std::vector<std::string> &values) { _values = values; } + void setKind(const std::string &kind) { _kind = kind; } + void setChoices(const std::vector<std::string> &choices) + { + _choices = choices; + } std::string getType() const { return "string"; } const std::string &getValue() const { static std::string n(""); - if(_values.empty()) return n; return _values[0]; + if(_values.empty()) return n; + return _values[0]; } const std::vector<std::string> &getValues() const { return _values; } unsigned int getNumValues() const { return _values.size(); } @@ -693,17 +721,17 @@ namespace onelab{ setReadOnly(p.getReadOnly()); setAttributes(p.getAttributes()); bool changed = false; - for(unsigned int i = 0; i < p.getValues().size(); i++){ - if(p.getValues()[i] != getValues()[i]){ + for(unsigned int i = 0; i < p.getValues().size(); i++) { + if(p.getValues()[i] != getValues()[i]) { changed = true; break; } } - if(changed){ + if(changed) { setValues(p.getValues()); setChanged(getChangedValue()); } - if(p.getKind() != getKind()){ + if(p.getKind() != getKind()) { setKind(p.getKind()); setChanged(getChangedValue()); } @@ -713,12 +741,10 @@ namespace onelab{ std::string toChar() const { std::ostringstream sstream; - sstream << parameter::toChar() - << _values.size() << charSep(); + sstream << parameter::toChar() << _values.size() << charSep(); for(unsigned int i = 0; i < _values.size(); i++) sstream << sanitize(_values[i]) << charSep(); - sstream << sanitize(_kind) << charSep() - << _choices.size() << charSep(); + sstream << sanitize(_kind) << charSep() << _choices.size() << charSep(); for(unsigned int i = 0; i < _choices.size(); i++) sstream << sanitize(_choices[i]) << charSep(); return sstream.str(); @@ -739,18 +765,17 @@ namespace onelab{ std::string toJSON() const { std::ostringstream sstream; - sstream << "{ " << parameter::toJSON() - << ", \"values\":[ " ; - for(unsigned int i = 0; i < _values.size(); i++){ + sstream << "{ " << parameter::toJSON() << ", \"values\":[ "; + for(unsigned int i = 0; i < _values.size(); i++) { if(i) sstream << ", "; sstream << "\"" << sanitizeJSON(_values[i]) << "\""; } sstream << " ] "; if(_kind.size()) - sstream << ", \"kind\":\"" << sanitizeJSON(_kind) << "\""; - if(_choices.size()){ + sstream << ", \"kind\":\"" << sanitizeJSON(_kind) << "\""; + if(_choices.size()) { sstream << ", \"choices\":[ "; - for(unsigned int i = 0; i < _choices.size(); i++){ + for(unsigned int i = 0; i < _choices.size(); i++) { if(i) sstream << ", "; sstream << "\"" << sanitizeJSON(_choices[i]) << "\""; } @@ -760,28 +785,29 @@ namespace onelab{ return sstream.str(); } #if defined(HAVE_PICOJSON) - bool fromJSON(const picojson::value::object& par) + bool fromJSON(const picojson::value::object &par) { if(!parameter::fromJSON(par)) return false; - for(picojson::value::object::const_iterator it = par.begin(); it != par.end(); ++it){ - if(it->first == "values"){ + for(picojson::value::object::const_iterator it = par.begin(); + it != par.end(); ++it) { + if(it->first == "values") { if(!it->second.is<picojson::array>()) return false; const picojson::value::array &arr = it->second.get<picojson::array>(); _values.resize(arr.size()); - for(unsigned int i = 0; i < arr.size(); i++){ + for(unsigned int i = 0; i < arr.size(); i++) { if(!arr[i].is<std::string>()) return false; _values[i] = arr[i].get<std::string>(); } } - else if(it->first == "kind"){ + else if(it->first == "kind") { if(!it->second.is<std::string>()) return false; setKind(it->second.get<std::string>()); } - else if(it->first == "choices"){ + else if(it->first == "choices") { if(!it->second.is<picojson::array>()) return false; const picojson::value::array &arr = it->second.get<picojson::array>(); _choices.resize(arr.size()); - for(unsigned int i = 0; i < arr.size(); i++){ + for(unsigned int i = 0; i < arr.size(); i++) { if(!arr[i].is<std::string>()) return false; _choices[i] = arr[i].get<std::string>(); } @@ -794,35 +820,35 @@ namespace onelab{ // The parameter space, i.e., the set of parameters stored and handled by the // onelab server. - class parameterSpace{ + class parameterSpace { private: - std::set<number*, parameterLessThan> _numbers; - std::set<string*, parameterLessThan> _strings; + std::set<number *, parameterLessThan> _numbers; + std::set<string *, parameterLessThan> _strings; // delete a parameter from the parameter space - template <class T> bool _clear(const std::string &name, - const std::string &client, - std::set<T*, parameterLessThan> &ps) - { - if(name.empty() && client.size()){ - std::vector<T*> toDelete; - for(typename std::set<T*, parameterLessThan>::iterator it = ps.begin(); - it != ps.end(); ){ + template <class T> + bool _clear(const std::string &name, const std::string &client, + std::set<T *, parameterLessThan> &ps) + { + if(name.empty() && client.size()) { + std::vector<T *> toDelete; + for(typename std::set<T *, parameterLessThan>::iterator it = ps.begin(); + it != ps.end();) { T *p = *it; - if(p->hasClient(client)){ + if(p->hasClient(client)) { ps.erase(it++); // to avoid invalid iterator delete p; } - else{ + else { it++; } } } - else{ + else { T tmp(name); - typename std::set<T*, parameterLessThan>::iterator it = ps.find(&tmp); - if(it != ps.end()){ + typename std::set<T *, parameterLessThan>::iterator it = ps.find(&tmp); + if(it != ps.end()) { T *p = *it; - if(client.empty() || p->hasClient(client)){ + if(client.empty() || p->hasClient(client)) { ps.erase(it); delete p; return true; @@ -835,17 +861,20 @@ namespace onelab{ // (adding new clients if necessary). This would need to be locked to avoid // race conditions when several clients try to set a parameter at the same // time. - template <class T> bool _set(const T &p, const std::string &client, - std::set<T*, parameterLessThan> &ps) + template <class T> + bool _set(const T &p, const std::string &client, + std::set<T *, parameterLessThan> &ps) { - typename std::set<T*, parameterLessThan>::iterator it = ps.find((T*)&p); - if(it != ps.end()){ + typename std::set<T *, parameterLessThan>::iterator it = ps.find((T *)&p); + if(it != ps.end()) { (*it)->update(p); - if(client.size()) (*it)->addClient(client, parameter::defaultChangedValue()); + if(client.size()) + (*it)->addClient(client, parameter::defaultChangedValue()); } - else{ - T* newp = new T(p); - if(client.size()) newp->addClient(client, parameter::defaultChangedValue()); + else { + T *newp = new T(p); + if(client.size()) + newp->addClient(client, parameter::defaultChangedValue()); ps.insert(newp); } return true; @@ -854,71 +883,75 @@ namespace onelab{ // category if no name is given. If we find a given parameter by name, we // add the client requesting the parameter to the list of clients for this // parameter. This would also need to be locked. - template <class T> bool _get(std::vector<T> &p, const std::string &name, - const std::string &client, - std::set<T*, parameterLessThan> &ps) + template <class T> + bool _get(std::vector<T> &p, const std::string &name, + const std::string &client, std::set<T *, parameterLessThan> &ps) { p.clear(); - if(name.empty()){ - for(typename std::set<T*, parameterLessThan>::iterator it = ps.begin(); + if(name.empty()) { + for(typename std::set<T *, parameterLessThan>::iterator it = ps.begin(); it != ps.end(); it++) p.push_back(**it); } - else{ + else { T tmp(name); - typename std::set<T*, parameterLessThan>::iterator it = ps.find(&tmp); - if(it != ps.end()){ - if(client.size()) (*it)->addClient(client, parameter::defaultChangedValue()); + typename std::set<T *, parameterLessThan>::iterator it = ps.find(&tmp); + if(it != ps.end()) { + if(client.size()) + (*it)->addClient(client, parameter::defaultChangedValue()); p.push_back(**it); } } return true; } - template <class T> T* _getPtr(std::string name, const std::string client, - std::set<T*, parameterLessThan> ps) + template <class T> + T *_getPtr(std::string name, const std::string client, + std::set<T *, parameterLessThan> ps) { T tmp(name); - typename std::set<T*, parameterLessThan>::iterator it = ps.find(&tmp); - if(it != ps.end()){ - if(client.size()) (*it)->addClient(client, parameter::defaultChangedValue()); + typename std::set<T *, parameterLessThan>::iterator it = ps.find(&tmp); + if(it != ps.end()) { + if(client.size()) + (*it)->addClient(client, parameter::defaultChangedValue()); return *it; } return NULL; } + public: - parameterSpace(){} - ~parameterSpace(){ clear(); } - void clear(const std::string &name="", const std::string &client="") + parameterSpace() {} + ~parameterSpace() { clear(); } + void clear(const std::string &name = "", const std::string &client = "") { - if(name.empty() && client.empty()){ - std::set<parameter*, parameterLessThan> ps; + if(name.empty() && client.empty()) { + std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(std::set<parameter*, parameterLessThan>::iterator it = ps.begin(); + for(std::set<parameter *, parameterLessThan>::iterator it = ps.begin(); it != ps.end(); it++) delete *it; _numbers.clear(); _strings.clear(); } - else{ + else { bool done = _clear(name, client, _numbers); if(!done) done = _clear(name, client, _strings); } } - bool set(const number &p, const std::string &client="") + bool set(const number &p, const std::string &client = "") { return _set(p, client, _numbers); } - bool set(const string &p, const std::string &client="") + bool set(const string &p, const std::string &client = "") { return _set(p, client, _strings); } - bool get(std::vector<number> &ps, const std::string &name="", - const std::string &client="") + bool get(std::vector<number> &ps, const std::string &name = "", + const std::string &client = "") { return _get(ps, name, client, _numbers); } - bool get(std::vector<string> &ps, const std::string &name="", - const std::string &client="") + bool get(std::vector<string> &ps, const std::string &name = "", + const std::string &client = "") { return _get(ps, name, client, _strings); } @@ -932,7 +965,7 @@ namespace onelab{ { *ptr = _getPtr(name, client, _strings); } - void getAllParameters(std::set<parameter*, parameterLessThan> &ps) const + void getAllParameters(std::set<parameter *, parameterLessThan> &ps) const { ps.insert(_numbers.begin(), _numbers.end()); ps.insert(_strings.begin(), _strings.end()); @@ -944,82 +977,87 @@ namespace onelab{ // check if at least one parameter depends on the given client bool hasClient(const std::string &client) const { - std::set<parameter*, parameterLessThan> ps; + std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(std::set<parameter*, parameterLessThan>::iterator it = ps.begin(); + for(std::set<parameter *, parameterLessThan>::iterator it = ps.begin(); it != ps.end(); it++) if((*it)->hasClient(client)) return true; return false; } // check if some parameters have changed (optionnally only check the // parameters that depend on a given client) - int getChanged(const std::string &client="") const + int getChanged(const std::string &client = "") const { - std::set<parameter*, parameterLessThan> ps; + std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); int changed = 0; - for(std::set<parameter*, parameterLessThan>::iterator it = ps.begin(); - it != ps.end(); it++){ + for(std::set<parameter *, parameterLessThan>::iterator it = ps.begin(); + it != ps.end(); it++) { changed = std::max(changed, (*it)->getChanged(client)); } return changed; } // set the changed flag for all the parameters that depend on the given // client (or for all parameters if no client name is provided) - void setChanged(int changed, const std::string &client="") + void setChanged(int changed, const std::string &client = "") { - std::set<parameter*, parameterLessThan> ps; + std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(std::set<parameter*, parameterLessThan>::iterator it = ps.begin(); + for(std::set<parameter *, parameterLessThan>::iterator it = ps.begin(); it != ps.end(); it++) (*it)->setChanged(changed, client); } - void thresholdChanged(int threshold, const std::string &client="") + void thresholdChanged(int threshold, const std::string &client = "") { - std::set<parameter*, parameterLessThan> ps; + std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(std::set<parameter*, parameterLessThan>::iterator it = ps.begin(); - it != ps.end(); it++){ + for(std::set<parameter *, parameterLessThan>::iterator it = ps.begin(); + it != ps.end(); it++) { int changed = (*it)->getChanged(client); - if(changed > threshold) - (*it)->setChanged(threshold, client); + if(changed > threshold) (*it)->setChanged(threshold, client); } } // serialize the parameter space (optionally only serialize those parameters // that depend on the given client) - std::vector<std::string> toChar(const std::string &client="") const + std::vector<std::string> toChar(const std::string &client = "") const { std::vector<std::string> s; - std::set<parameter*, parameterLessThan> ps; + std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(std::set<parameter*, parameterLessThan>::const_iterator it = ps.begin(); + for(std::set<parameter *, parameterLessThan>::const_iterator it = + ps.begin(); it != ps.end(); it++) - if(client.empty() || (*it)->hasClient(client)){ - if((*it)->getAttribute("NotInDb") != "True") - s.push_back((*it)->toChar()); - } + if(client.empty() || (*it)->hasClient(client)) { + if((*it)->getAttribute("NotInDb") != "True") + s.push_back((*it)->toChar()); + } return s; } // unserialize the parameter space - bool fromChar(const std::vector<std::string> &msg, const std::string &client="") + bool fromChar(const std::vector<std::string> &msg, + const std::string &client = "") { - for(unsigned int i = 0; i < msg.size(); i++){ + for(unsigned int i = 0; i < msg.size(); i++) { std::string version, type, name; onelab::parameter::getInfoFromChar(msg[i], version, type, name); if(onelab::parameter::version() != version) return false; - if(type == "number"){ - number p; p.fromChar(msg[i]); set(p, client); + if(type == "number") { + number p; + p.fromChar(msg[i]); + set(p, client); } - else if(type == "string"){ - string p; p.fromChar(msg[i]); set(p, client); + else if(type == "string") { + string p; + p.fromChar(msg[i]); + set(p, client); } else return false; } return true; } - bool toJSON(std::string &json, const std::string &creator="", - const std::string &client="") const + bool toJSON(std::string &json, const std::string &creator = "", + const std::string &client = "") const { time_t now; time(&now); @@ -1031,21 +1069,22 @@ namespace onelab{ json += " \"date\":\"" + t + "\",\n"; json += " \"version\":\"" + parameter::version() + "\",\n"; json += " \"parameters\":[\n"; - std::set<parameter*, parameterLessThan> ps; + std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(std::set<parameter*, parameterLessThan>::const_iterator it = ps.begin(); - it != ps.end(); it++){ + for(std::set<parameter *, parameterLessThan>::const_iterator it = + ps.begin(); + it != ps.end(); it++) { if(it != ps.begin()) json += ",\n"; - if(client.empty() || (*it)->hasClient(client)){ - if((*it)->getAttribute("NotInDb") != "True"){ - json += " " + (*it)->toJSON(); + if(client.empty() || (*it)->hasClient(client)) { + if((*it)->getAttribute("NotInDb") != "True") { + json += " " + (*it)->toJSON(); } - } + } } json += "\n ] }\n}\n"; return true; } - bool fromJSON(const std::string &json, const std::string &client="") + bool fromJSON(const std::string &json, const std::string &client = "") { #if defined(HAVE_PICOJSON) picojson::value v; @@ -1053,28 +1092,37 @@ namespace onelab{ if(err.size()) return false; if(!v.is<picojson::object>()) return false; const picojson::value::object &obj = v.get<picojson::object>(); - for (picojson::value::object::const_iterator i = obj.begin(); i != obj.end(); ++i) { - if(i->first == "onelab"){ // onelab database + for(picojson::value::object::const_iterator i = obj.begin(); + i != obj.end(); ++i) { + if(i->first == "onelab") { // onelab database if(!i->second.is<picojson::object>()) return false; const picojson::value::object &db = i->second.get<picojson::object>(); - for (picojson::value::object::const_iterator j = db.begin(); j != db.end(); ++j) { - if(j->first == "version"){ + for(picojson::value::object::const_iterator j = db.begin(); + j != db.end(); ++j) { + if(j->first == "version") { if(!j->second.is<std::string>()) return false; - if(j->second.get<std::string>() != parameter::version()) return false; + if(j->second.get<std::string>() != parameter::version()) + return false; } - else if(j->first == "parameters"){ + else if(j->first == "parameters") { if(!j->second.is<picojson::array>()) return false; - const picojson::value::array &arr = j->second.get<picojson::array>(); - for(unsigned int k = 0; k < arr.size(); k++){ + const picojson::value::array &arr = + j->second.get<picojson::array>(); + for(unsigned int k = 0; k < arr.size(); k++) { if(!arr[k].is<picojson::object>()) return false; - const picojson::value::object &par = arr[k].get<picojson::object>(); + const picojson::value::object &par = + arr[k].get<picojson::object>(); picojson::value::object::const_iterator it = par.find("type"); if(it == par.end()) return false; - if(it->second.to_str() == "number"){ - number p; p.fromJSON(par); set(p, client); + if(it->second.to_str() == "number") { + number p; + p.fromJSON(par); + set(p, client); } - else if(it->second.to_str() == "string"){ - string p; p.fromJSON(par); set(p, client); + else if(it->second.to_str() == "string") { + string p; + p.fromJSON(par); + set(p, client); } } } @@ -1091,7 +1139,7 @@ namespace onelab{ // The onelab client: a class that communicates with the onelab server. Each // client should be derived from this one. A client can be understood as "one // simulation step in a complex computation". - class client{ + class client { protected: // the name of the client std::string _name; @@ -1099,64 +1147,82 @@ namespace onelab{ int _id; // the index of the client in an external client list (if any) int _index; + public: - client(const std::string &name) : _name(name), _id(0), _index(-1){} - virtual ~client(){} - std::string getName(){ return _name; } - void setId(int id){ _id = id; } - int getId(){ return _id; } - void setIndex(int index){ _index = index; } - int getIndex(){ return _index; } - virtual bool run(){ return false; } - virtual bool isNetworkClient(){ return false; } - virtual bool kill(){ return false; } - virtual void sendInfo(const std::string &msg){ std::cout << msg << std::endl; } - virtual void sendWarning(const std::string &msg){ std::cerr << msg << std::endl; } - virtual void sendError(const std::string &msg){ std::cerr << msg << std::endl; } - virtual void sendProgress(const std::string &msg){ std::cout << msg << std::endl; } - virtual void sendMergeFileRequest(const std::string &msg){} - virtual void sendOpenProjectRequest(const std::string &msg){} - virtual void sendParseStringRequest(const std::string &msg){} - virtual void sendVertexArray(const std::string &msg){} + client(const std::string &name) : _name(name), _id(0), _index(-1) {} + virtual ~client() {} + std::string getName() { return _name; } + void setId(int id) { _id = id; } + int getId() { return _id; } + void setIndex(int index) { _index = index; } + int getIndex() { return _index; } + virtual bool run() { return false; } + virtual bool isNetworkClient() { return false; } + virtual bool kill() { return false; } + virtual void sendInfo(const std::string &msg) + { + std::cout << msg << std::endl; + } + virtual void sendWarning(const std::string &msg) + { + std::cerr << msg << std::endl; + } + virtual void sendError(const std::string &msg) + { + std::cerr << msg << std::endl; + } + virtual void sendProgress(const std::string &msg) + { + std::cout << msg << std::endl; + } + virtual void sendMergeFileRequest(const std::string &msg) {} + virtual void sendOpenProjectRequest(const std::string &msg) {} + virtual void sendParseStringRequest(const std::string &msg) {} + virtual void sendVertexArray(const std::string &msg) {} virtual bool clear(const std::string &name) = 0; virtual bool set(const number &p) = 0; virtual bool set(const string &p) = 0; - virtual bool get(std::vector<number> &ps, const std::string &name="") = 0; - virtual bool get(std::vector<string> &ps, const std::string &name="") = 0; + virtual bool get(std::vector<number> &ps, const std::string &name = "") = 0; + virtual bool get(std::vector<string> &ps, const std::string &name = "") = 0; virtual bool setAndAppendChoices(const number &p) = 0; virtual bool setAndAppendChoices(const string &p) = 0; - virtual bool getWithoutChoices(std::vector<number> &ps, const std::string &name="") = 0; - virtual bool getWithoutChoices(std::vector<string> &ps, const std::string &name="") = 0; + virtual bool getWithoutChoices(std::vector<number> &ps, + const std::string &name = "") = 0; + virtual bool getWithoutChoices(std::vector<string> &ps, + const std::string &name = "") = 0; std::vector<std::string> toChar() { std::vector<std::string> out; - std::vector<number> n; get(n); + std::vector<number> n; + get(n); for(unsigned int i = 0; i < n.size(); i++) out.push_back(n[i].toChar()); - std::vector<string> s; get(s); + std::vector<string> s; + get(s); for(unsigned int i = 0; i < s.size(); i++) out.push_back(s[i].toChar()); return out; } bool fromChar(const std::vector<std::string> &msg) { - for(unsigned int i = 0; i < msg.size(); i++){ + for(unsigned int i = 0; i < msg.size(); i++) { std::string version, type, name; onelab::parameter::getInfoFromChar(msg[i], version, type, name); if(onelab::parameter::version() != version) return false; - if(type == "number"){ - number p; p.fromChar(msg[i]); set(p); + if(type == "number") { + number p; + p.fromChar(msg[i]); + set(p); } - else if(type == "string"){ - string p; p.fromChar(msg[i]); set(p); + else if(type == "string") { + string p; + p.fromChar(msg[i]); + set(p); } else return false; } return true; } - bool toFile(FILE *fp) - { - return parameter::toFile(toChar(), fp, getName()); - } + bool toFile(FILE *fp) { return parameter::toFile(toChar(), fp, getName()); } bool fromFile(FILE *fp) { std::vector<std::string> msg; @@ -1167,41 +1233,43 @@ namespace onelab{ // The onelab server: a singleton that stores the parameter space and // interacts with onelab clients. - class server{ + class server { private: // the unique server (singleton behaviour due to the "static" specifier) static server *_server; // the address of the server std::string _address; // the connected clients - std::set<client*> _clients; + std::set<client *> _clients; // the parameter space parameterSpace _parameterSpace; + public: - server(const std::string &address="") : _address(address) {} - ~server(){} - static server *instance(const std::string &address="") + server(const std::string &address = "") : _address(address) {} + ~server() {} + static server *instance(const std::string &address = "") { if(!_server) _server = new server(address); return _server; } static void setInstance(server *s) { _server = s; } - void clear(const std::string &name="", const std::string &client="") + void clear(const std::string &name = "", const std::string &client = "") { _parameterSpace.clear(name, client); } - template <class T> bool set(const T &p, const std::string &client="") + template <class T> bool set(const T &p, const std::string &client = "") { return _parameterSpace.set(p, client); } - template <class T> bool get(std::vector<T> &ps, const std::string &name="", - const std::string &client="") + template <class T> + bool get(std::vector<T> &ps, const std::string &name = "", + const std::string &client = "") { return _parameterSpace.get(ps, name, client); } - typedef std::set<client*>::iterator citer; - citer firstClient(){ return _clients.begin(); } - citer lastClient(){ return _clients.end(); } + typedef std::set<client *>::iterator citer; + citer firstClient() { return _clients.begin(); } + citer lastClient() { return _clients.end(); } int getNumClients() { return (int)_clients.size(); }; citer findClient(const std::string &name) { @@ -1214,89 +1282,96 @@ namespace onelab{ _clients.insert(c); c->setId(_clients.size()); } - void unregisterClient(client *c){ _clients.erase(c); } - void setChanged(int changed, const std::string &client="") + void unregisterClient(client *c) { _clients.erase(c); } + void setChanged(int changed, const std::string &client = "") { _parameterSpace.setChanged(changed, client); } - int getChanged(const std::string &client="") + int getChanged(const std::string &client = "") { return _parameterSpace.getChanged(client); } - void thresholdChanged(int value, const std::string &client="") + void thresholdChanged(int value, const std::string &client = "") { _parameterSpace.thresholdChanged(value, client); } - unsigned int getNumParameters(){ return _parameterSpace.getNumParameters(); } - std::vector<std::string> toChar(const std::string &client="") + unsigned int getNumParameters() + { + return _parameterSpace.getNumParameters(); + } + std::vector<std::string> toChar(const std::string &client = "") { return _parameterSpace.toChar(client); } - bool fromChar(const std::vector<std::string> &msg, const std::string &client="") + bool fromChar(const std::vector<std::string> &msg, + const std::string &client = "") { return _parameterSpace.fromChar(msg, client); } - bool toFile(FILE *fp, const std::string &client="") + bool toFile(FILE *fp, const std::string &client = "") { return parameter::toFile(toChar(client), fp, "onelab server"); } - bool fromFile(FILE *fp, const std::string &client="") + bool fromFile(FILE *fp, const std::string &client = "") { std::vector<std::string> msg; if(parameter::fromFile(msg, fp)) return fromChar(msg, client); return false; } - bool toJSON(std::string &json, const std::string &client="") + bool toJSON(std::string &json, const std::string &client = "") { return _parameterSpace.toJSON(json, client); } - bool fromJSON(const std::string &json, const std::string &client="") + bool fromJSON(const std::string &json, const std::string &client = "") { return _parameterSpace.fromJSON(json, client); } }; // A local client, which lives in the same memory space as the server. - class localClient : public client{ + class localClient : public client { private: template <class T> bool _set(const T &p) { server::instance()->set(p, _name); return true; } - template <class T> bool _get(std::vector<T> &ps, - const std::string &name="") + template <class T> + bool _get(std::vector<T> &ps, const std::string &name = "") { server::instance()->get(ps, name, _name); return true; } + public: localClient(const std::string &name) : client(name) { server::instance()->registerClient(this); } - virtual ~localClient() - { - server::instance()->unregisterClient(this); - } - virtual bool clear(const std::string &name="") + virtual ~localClient() { server::instance()->unregisterClient(this); } + virtual bool clear(const std::string &name = "") { server::instance()->clear(name); return true; } - virtual bool set(const number &p){ return _set(p); } - virtual bool set(const string &p){ return _set(p); } - virtual bool get(std::vector<number> &ps, - const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<string> &ps, - const std::string &name=""){ return _get(ps, name); } + virtual bool set(const number &p) { return _set(p); } + virtual bool set(const string &p) { return _set(p); } + virtual bool get(std::vector<number> &ps, const std::string &name = "") + { + return _get(ps, name); + } + virtual bool get(std::vector<string> &ps, const std::string &name = "") + { + return _get(ps, name); + } virtual bool setAndAppendChoices(const number &p) { std::vector<number> ps; _get(ps, _name); std::vector<double> choices; if(ps.size()) choices = ps[0].getChoices(); - choices.insert(choices.end(), p.getChoices().begin(), p.getChoices().end()); + choices.insert(choices.end(), p.getChoices().begin(), + p.getChoices().end()); number p2(p); p2.setChoices(choices); return _set(p2); @@ -1307,13 +1382,14 @@ namespace onelab{ _get(ps, _name); std::vector<std::string> choices; if(ps.size()) choices = ps[0].getChoices(); - choices.insert(choices.end(), p.getChoices().begin(), p.getChoices().end()); + choices.insert(choices.end(), p.getChoices().begin(), + p.getChoices().end()); string p2(p); p2.setChoices(choices); return _set(p2); } virtual bool getWithoutChoices(std::vector<number> &ps, - const std::string &name="") + const std::string &name = "") { bool ret = _get(ps, name); for(unsigned int i = 0; i < ps.size(); i++) @@ -1321,7 +1397,7 @@ namespace onelab{ return ret; } virtual bool getWithoutChoices(std::vector<string> &ps, - const std::string &name="") + const std::string &name = "") { bool ret = _get(ps, name); for(unsigned int i = 0; i < ps.size(); i++) @@ -1331,7 +1407,7 @@ namespace onelab{ }; // The local part of a network client. - class localNetworkClient : public localClient{ + class localNetworkClient : public localClient { private: // executable of the client (including filesystem path, if necessary) std::string _executable; @@ -1347,36 +1423,39 @@ namespace onelab{ int _pid; // underlying GmshServer GmshServer *_gmshServer; + public: localNetworkClient(const std::string &name, const std::string &executable, - const std::string &remoteLogin="", - bool treatExecutableAsFullCommandLine=false) + const std::string &remoteLogin = "", + bool treatExecutableAsFullCommandLine = false) : localClient(name), _executable(executable), _treatExecutableAsFullCommandLine(treatExecutableAsFullCommandLine), _remoteLogin(remoteLogin), _socketSwitch("-onelab"), _pid(-1), - _gmshServer(0) {} - virtual ~localNetworkClient(){} - virtual bool isNetworkClient(){ return true; } - const std::string &getExecutable(){ return _executable; } - void setExecutable(const std::string &s){ _executable = s; } - const std::string &getRemoteLogin(){ return _remoteLogin; } + _gmshServer(0) + { + } + virtual ~localNetworkClient() {} + virtual bool isNetworkClient() { return true; } + const std::string &getExecutable() { return _executable; } + void setExecutable(const std::string &s) { _executable = s; } + const std::string &getRemoteLogin() { return _remoteLogin; } bool treatExecutableAsFullCommandLine() const { return _treatExecutableAsFullCommandLine; } - void setRemoteLogin(const std::string &s){ _remoteLogin = s; } - const std::string &getSocketSwitch(){ return _socketSwitch; } - void setSocketSwitch(const std::string &s){ _socketSwitch = s; } - int getPid(){ return _pid; } - void setPid(int pid){ _pid = pid; } - GmshServer *getGmshServer(){ return _gmshServer; } - void setGmshServer(GmshServer *server){ _gmshServer = server; } + void setRemoteLogin(const std::string &s) { _remoteLogin = s; } + const std::string &getSocketSwitch() { return _socketSwitch; } + void setSocketSwitch(const std::string &s) { _socketSwitch = s; } + int getPid() { return _pid; } + void setPid(int pid) { _pid = pid; } + GmshServer *getGmshServer() { return _gmshServer; } + void setGmshServer(GmshServer *server) { _gmshServer = server; } virtual bool run() = 0; virtual bool kill() = 0; }; // The remote part of a network client. - class remoteNetworkClient : public client{ + class remoteNetworkClient : public client { private: // address (inet:port or unix socket) of the server std::string _serverAddress; @@ -1384,124 +1463,134 @@ namespace onelab{ GmshClient *_gmshClient; // number of subclients int _numSubClients; - template <class T> bool _set(const T &p, bool withChoices=true) + template <class T> bool _set(const T &p, bool withChoices = true) { if(!_gmshClient) return false; std::string msg = p.toChar(); - _gmshClient->SendMessage(withChoices ? GmshSocket::GMSH_PARAMETER : - GmshSocket::GMSH_PARAMETER_WITHOUT_CHOICES, + _gmshClient->SendMessage(withChoices ? + GmshSocket::GMSH_PARAMETER : + GmshSocket::GMSH_PARAMETER_WITHOUT_CHOICES, msg.size(), &msg[0]); return true; } - template <class T> bool _get(std::vector<T> &ps, const std::string &name="", - bool withChoices=true) + template <class T> + bool _get(std::vector<T> &ps, const std::string &name = "", + bool withChoices = true) { ps.clear(); if(!_gmshClient) return false; T p(name); std::string msg = p.toChar(); if(name.size()) - _gmshClient->SendMessage(withChoices ? GmshSocket::GMSH_PARAMETER_QUERY : - GmshSocket::GMSH_PARAMETER_QUERY_WITHOUT_CHOICES, - msg.size(), &msg[0]); + _gmshClient->SendMessage( + withChoices ? GmshSocket::GMSH_PARAMETER_QUERY : + GmshSocket::GMSH_PARAMETER_QUERY_WITHOUT_CHOICES, + msg.size(), &msg[0]); else // get all parameters - _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY_ALL, msg.size(), &msg[0]); + _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY_ALL, + msg.size(), &msg[0]); - while(1){ + while(1) { // stop if we have no communications for 5 minutes int ret = _gmshClient->Select(500, 0); - if(!ret){ + if(!ret) { _gmshClient->Info("Timeout: aborting remote get"); return false; } - else if(ret < 0){ + else if(ret < 0) { _gmshClient->Error("Error on select: aborting remote get"); return false; } int type, length, swap; - if(!_gmshClient->ReceiveHeader(&type, &length, &swap)){ - _gmshClient->Error("Did not receive message header: aborting remote get"); + if(!_gmshClient->ReceiveHeader(&type, &length, &swap)) { + _gmshClient->Error( + "Did not receive message header: aborting remote get"); return false; } std::string msg(length, ' '); - if(!_gmshClient->ReceiveMessage(length, &msg[0])){ - _gmshClient->Error("Did not receive message body: aborting remote get"); + if(!_gmshClient->ReceiveMessage(length, &msg[0])) { + _gmshClient->Error( + "Did not receive message body: aborting remote get"); return false; } - if(type == GmshSocket::GMSH_PARAMETER){ + if(type == GmshSocket::GMSH_PARAMETER) { T p; p.fromChar(msg); ps.push_back(p); return true; } - if(type == GmshSocket::GMSH_PARAMETER_QUERY_ALL){ + if(type == GmshSocket::GMSH_PARAMETER_QUERY_ALL) { T p; p.fromChar(msg); ps.push_back(p); // do NOT return until all parameters have been downloaded } - else if(type == GmshSocket::GMSH_PARAMETER_QUERY_END){ - // all parameters have been sent + else if(type == GmshSocket::GMSH_PARAMETER_QUERY_END) { + // all parameters have been sent return true; } - else if(type == GmshSocket::GMSH_PARAMETER_NOT_FOUND){ + else if(type == GmshSocket::GMSH_PARAMETER_NOT_FOUND) { // parameter not found return true; } - else if(type == GmshSocket::GMSH_INFO){ + else if(type == GmshSocket::GMSH_INFO) { return true; } - else{ + else { _gmshClient->Error("Unknown message type: aborting remote get"); return false; } } return true; } + public: void waitOnSubClients() { if(!_gmshClient) return; - while(_numSubClients > 0){ + while(_numSubClients > 0) { int ret = _gmshClient->Select(500, 0); - if(!ret){ + if(!ret) { _gmshClient->Info("Timeout: aborting wait on subclients"); return; } - else if(ret < 0){ + else if(ret < 0) { _gmshClient->Error("Error on select: aborting wait on subclients"); return; } int type, length, swap; - if(!_gmshClient->ReceiveHeader(&type, &length, &swap)){ - _gmshClient->Error("Did not receive message header: aborting wait on subclients"); + if(!_gmshClient->ReceiveHeader(&type, &length, &swap)) { + _gmshClient->Error( + "Did not receive message header: aborting wait on subclients"); return; } std::string msg(length, ' '); - if(!_gmshClient->ReceiveMessage(length, &msg[0])){ - _gmshClient->Error("Did not receive message body: aborting wait on subclients"); + if(!_gmshClient->ReceiveMessage(length, &msg[0])) { + _gmshClient->Error( + "Did not receive message body: aborting wait on subclients"); return; } - if(type == GmshSocket::GMSH_STOP) - _numSubClients -= 1; + if(type == GmshSocket::GMSH_STOP) _numSubClients -= 1; } } + public: - remoteNetworkClient(const std::string &name, const std::string &serverAddress) + remoteNetworkClient(const std::string &name, + const std::string &serverAddress) : client(name), _serverAddress(serverAddress), _numSubClients(0) { _gmshClient = new GmshClient(); - if(_gmshClient->Connect(_serverAddress.c_str()) < 0){ + if(_gmshClient->Connect(_serverAddress.c_str()) < 0) { delete _gmshClient; _gmshClient = 0; } - else{ + else { _gmshClient->Start(); } } virtual ~remoteNetworkClient() { - if(_gmshClient){ + if(_gmshClient) { waitOnSubClients(); _gmshClient->Stop(); _gmshClient->Disconnect(); @@ -1509,33 +1598,36 @@ namespace onelab{ _gmshClient = 0; } } - GmshClient *getGmshClient(){ return _gmshClient; } - virtual bool isNetworkClient(){ return true; } - virtual bool clear(const std::string &name="") + GmshClient *getGmshClient() { return _gmshClient; } + virtual bool isNetworkClient() { return true; } + virtual bool clear(const std::string &name = "") { if(!_gmshClient) return false; std::string msg = name; if(msg.empty()) msg = "*"; - _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_CLEAR, msg.size(), &msg[0]); + _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_CLEAR, msg.size(), + &msg[0]); return true; } - virtual bool set(const number &p){ return _set(p); } - virtual bool set(const string &p){ return _set(p); } - virtual bool get(std::vector<number> &ps, const std::string &name="") + virtual bool set(const number &p) { return _set(p); } + virtual bool set(const string &p) { return _set(p); } + virtual bool get(std::vector<number> &ps, const std::string &name = "") { return _get(ps, name); } - virtual bool get(std::vector<string> &ps, const std::string &name="") + virtual bool get(std::vector<string> &ps, const std::string &name = "") { return _get(ps, name); } - virtual bool setAndAppendChoices(const number &p){ return _set(p, false); } - virtual bool setAndAppendChoices(const string &p){ return _set(p, false); } - virtual bool getWithoutChoices(std::vector<number> &ps, const std::string &name="") + virtual bool setAndAppendChoices(const number &p) { return _set(p, false); } + virtual bool setAndAppendChoices(const string &p) { return _set(p, false); } + virtual bool getWithoutChoices(std::vector<number> &ps, + const std::string &name = "") { return _get(ps, name, false); } - virtual bool getWithoutChoices(std::vector<string> &ps, const std::string &name="") + virtual bool getWithoutChoices(std::vector<string> &ps, + const std::string &name = "") { return _get(ps, name, false); } @@ -1567,12 +1659,13 @@ namespace onelab{ { if(_gmshClient) _gmshClient->ParseString(msg.c_str()); } - void runNonBlockingSubClient(const std::string &name, const std::string &command) + void runNonBlockingSubClient(const std::string &name, + const std::string &command) { #if !defined(BUILD_IOS) - if(!_gmshClient){ + if(!_gmshClient) { int res = system(command.c_str()); - if(res){ + if(res) { // report error } return; @@ -1589,6 +1682,6 @@ namespace onelab{ } }; -} +} // namespace onelab #endif