diff --git a/Mesh/meshGFaceRecombine.cpp b/Mesh/meshGFaceRecombine.cpp index 2fef7100fe4951bc4970de396d7255115dbae9c7..6478be3e17dd717a001619b75c40f75cabe29021 100644 --- a/Mesh/meshGFaceRecombine.cpp +++ b/Mesh/meshGFaceRecombine.cpp @@ -198,8 +198,7 @@ Recombine2D::Recombine2D(GFace *gf) : _gf(gf), _strategy(0), _numChange(0) } } - static int rea = -1; - if (++rea < 1) _data->printState(); + _data->printState(); } Recombine2D::~Recombine2D() @@ -257,10 +256,16 @@ bool Recombine2D::recombine() return 1; } -bool Recombine2D::recombine(int depth) +double Recombine2D::recombine(int depth) { - Rec2DData::clearChanges(); + Rec2DData::clearChanges(); double bestGlobalQuality; + _data->printActions(); + Rec2DNode *root1 = new Rec2DNode(NULL, NULL, bestGlobalQuality, depth); + _data->printActions(); + Rec2DNode *root2 = new Rec2DNode(NULL, NULL, bestGlobalQuality, depth); + _data->printActions(); + _data->printState(); Rec2DNode *root = new Rec2DNode(NULL, NULL, bestGlobalQuality, depth); Rec2DNode *currentNode = root->selectBestNode(); @@ -269,7 +274,7 @@ bool Recombine2D::recombine(int depth) currentNode = currentNode->selectBestNode(); } - Msg::Info("==> %g", Rec2DData::getGlobalQuality()); + return Rec2DData::getGlobalQuality(); //_data->printState(); } @@ -325,6 +330,11 @@ void Recombine2D::drawState(double shiftx, double shifty) drawContext::global()->draw(); } +void Recombine2D::printState() +{ + _data->printState(); +} + double Recombine2D::_geomAngle(MVertex *v, std::vector<GEdge*> &gEdge, std::vector<MElement*> &elem) //* @@ -644,6 +654,7 @@ void Rec2DData::remove(Rec2DAction *ra) void Rec2DData::printState() { + Msg::Info(" "); Msg::Info("State"); Msg::Info("-----"); Msg::Info("numEdge %d (%d), valEdge %g => %g", _numEdge, _edges.size(), (double)_valEdge, (double)_valEdge/_numEdge); @@ -659,7 +670,7 @@ void Rec2DData::printState() iter_re ite; long double valEdge = .0; for (ite = firstEdge(); ite != lastEdge(); ++ite) { - valEdge += (long double)(*ite)->getVal(); + valEdge += (long double)(*ite)->getWeightedQual(); } Msg::Info("valEdge : %g >< %g", (double)valEdge, (double)_valEdge); iter_rv itv; @@ -672,6 +683,17 @@ void Rec2DData::printState() Msg::Info("valVert : %g >< %g", (double)valVert, (double)_valVert); } +void Rec2DData::printActions() +{ + Recombine2D::incNumChange(); + _actions.sort(lessRec2DAction()); + std::list<Rec2DAction*>::iterator it = _actions.begin(); + for (; it != _actions.end(); ++it) { + Msg::Info("action %d -> reward %g", *it, (*it)->getReward()); + } + Msg::Info(" "); +} + int Rec2DData::getNewParity() { if (_current->_parities.empty()) @@ -1038,13 +1060,42 @@ Rec2DAction::Rec2DAction() bool Rec2DAction::operator<(Rec2DAction &other) { - return getReward() < other.getReward(); + //return doub < other.getReward(); + return getReward() < other.getReward(); } double Rec2DAction::getReward() { if (_lastUpdate < Recombine2D::getNumChange()) _computeGlobQual(); + + static const Rec2DAction *ra = this; + double doub = _globQualIfExecuted; + static double a = .0; + static const double b = doub; + static int k = -1; + static int num = -3; + if (k == -1) { + ++k; + Msg::Error("========== Im %d =========", this); + } + if (ra == this) { + if (a == doub) { + ++k; + Msg::Warning("same reward :) num %d", k); + } + else { + Msg::Warning("reward changed %g -> %g (first %g)", a, doub, b); + a = doub; + printCoord(); + _computeGlobQual2(); + } + if (_lastUpdate != num) { + Msg::Info("__ %d __ %d __", _lastUpdate, Recombine2D::getNumChange()); + num = _lastUpdate; + } + } + return _globQualIfExecuted/* - Rec2DData::getGlobalQuality()*/; } @@ -1113,6 +1164,16 @@ void Rec2DTwoTri2Quad::reveal() void Rec2DTwoTri2Quad::_computeGlobQual() { + /*static const Rec2DAction *ra = this; + double doub = _globQualIfExecuted; + static double a = .0; + static const double b = doub; + static int k = -1; + static int num = -3; + if (k == -1) { + ++k; + Msg::Error("========== And me %d =========", this); + }*/ double valEdge = -REC2D_EDGE_BASE * _edges[4]->getQual(); for (int i = 0; i < 4; ++i) valEdge += REC2D_EDGE_QUAD * _edges[i]->getQual(); @@ -1123,8 +1184,33 @@ void Rec2DTwoTri2Quad::_computeGlobQual() _globQualIfExecuted = Rec2DData::getGlobalQuality(4*REC2D_EDGE_QUAD - REC2D_EDGE_BASE, - valEdge, 0, valVert ); + valEdge, 0, valVert ); _lastUpdate = Recombine2D::getNumChange(); + + /*if (ra == this) { + Msg::Info(" %d %g %g", 4*REC2D_EDGE_QUAD - REC2D_EDGE_BASE, valEdge, valVert); + }*/ +} + +void Rec2DTwoTri2Quad::_computeGlobQual2() +{ + Msg::Info("%g %g %g %g %g %g %g", -REC2D_EDGE_BASE * _edges[4]->getQual(), + REC2D_EDGE_QUAD * _edges[0]->getQual(), + REC2D_EDGE_QUAD * _edges[1]->getQual(), + REC2D_EDGE_QUAD * _edges[2]->getQual(), + REC2D_EDGE_QUAD * _edges[3]->getQual(), + _vertices[0]->getGainMerge(_triangles[0], _triangles[1]), + _vertices[1]->getGainMerge(_triangles[0], _triangles[1]) ); + double valEdge = -REC2D_EDGE_BASE * _edges[4]->getQual(); + for (int i = 0; i < 4; ++i) + valEdge += REC2D_EDGE_QUAD * _edges[i]->getQual(); + + double valVert; + valVert += _vertices[0]->getGainMerge(_triangles[0], _triangles[1]); + valVert += _vertices[1]->getGainMerge(_triangles[0], _triangles[1]); + Msg::Info("%d %g %g", 4*REC2D_EDGE_QUAD - REC2D_EDGE_BASE, valEdge, valVert); + Msg::Info("%g", Rec2DData::getGlobalQuality(4*REC2D_EDGE_QUAD - REC2D_EDGE_BASE, + valEdge, 0, valVert )); } void Rec2DTwoTri2Quad::color(int a, int b, int c) @@ -1332,8 +1418,23 @@ int Rec2DTwoTri2Quad::getNum(double shiftx, double shifty) return quad->getNum(); } +void Rec2DTwoTri2Quad::printCoord() +{ + Msg::Info("(%g %g) (%g %g) (%g %g) (%g %g) %d %d", _vertices[0]->u(), + _vertices[0]->v(), + _vertices[1]->u(), + _vertices[1]->v(), + _vertices[2]->u(), + _vertices[2]->v(), + _vertices[3]->u(), + _vertices[3]->v(), + _vertices[0]->getNumElements(), + _vertices[1]->getNumElements() ); +} + Rec2DElement* Rec2DTwoTri2Quad::getRandomElement() { + return _triangles[0]; return _triangles[rand() % 2]; } @@ -1352,7 +1453,7 @@ void Rec2DEdge::hide() _rv0->rmv(this); _rv1->rmv(this); Rec2DData::remove(this); - Rec2DData::addEdge(-_weight, -getVal()); + Rec2DData::addEdge(-_weight, -getWeightedQual()); } void Rec2DEdge::reveal() @@ -1360,7 +1461,7 @@ void Rec2DEdge::reveal() _rv0->add(this); _rv1->add(this); Rec2DData::add(this); - Rec2DData::addEdge(_weight, getVal()); + Rec2DData::addEdge(_weight, getWeightedQual()); } void Rec2DEdge::_computeQual() //* @@ -1375,15 +1476,15 @@ void Rec2DEdge::_computeQual() //* double Rec2DEdge::getQual() { - if (_lastUpdate < Recombine2D::getNumChange() && - (_rv0->getLastMove() > _lastUpdate || - _rv1->getLastMove() > _lastUpdate ) ) { - _computeQual(); + if (_rv0->getLastMove() > _lastUpdate || + _rv1->getLastMove() > _lastUpdate ) { + _computeQual(); + Msg::Warning("Imhere"); } return _qual; } -double Rec2DEdge::getVal() +double Rec2DEdge::getWeightedQual() { if (_weight != .0 && _lastUpdate < Recombine2D::getNumChange() && diff --git a/Mesh/meshGFaceRecombine.h b/Mesh/meshGFaceRecombine.h index 46f5eb8102eae532944b176bf77cd262e13dc393..adb7cb8554d27bea24e0ed77351b0feb49394449 100644 --- a/Mesh/meshGFaceRecombine.h +++ b/Mesh/meshGFaceRecombine.h @@ -61,13 +61,14 @@ class Recombine2D { ~Recombine2D(); bool recombine(); - bool recombine(int depth); + double recombine(int depth); bool developTree(); static void nextTreeActions(std::vector<Rec2DAction*>&, std::vector<Rec2DElement*> &neighbours); inline void setStrategy(int s) {_strategy = s;} void drawState(double shiftx, double shifty); + void printState(); static inline GFace* getGFace() {return _current->_gf;} static inline int getNumChange() {return _current->_numChange;} @@ -107,6 +108,7 @@ class Rec2DData { ~Rec2DData(); void printState(); + void printActions(); void drawTriangles(double shiftx, double shifty); void drawChanges(double shiftx, double shifty); #ifdef REC2D_DRAW @@ -226,7 +228,7 @@ class Rec2DAction { virtual void reveal() = 0; bool operator<(Rec2DAction&); - virtual double getReward(); + double getReward(); virtual void color(int, int, int) = 0; virtual void apply(std::vector<Rec2DVertex*> &newPar) = 0; virtual void apply(Rec2DDataChange*) = 0; @@ -240,9 +242,11 @@ class Rec2DAction { virtual void getNeighbourElements(std::vector<Rec2DElement*>&) = 0; virtual int getNum(double shiftx, double shifty) = 0; virtual Rec2DElement* getRandomElement() = 0; + virtual void printCoord() = 0; private : virtual void _computeGlobQual() = 0; + virtual void _computeGlobQual2() = 0; }; class Rec2DTwoTri2Quad : public Rec2DAction { @@ -260,11 +264,13 @@ class Rec2DTwoTri2Quad : public Rec2DAction { virtual void color(int, int, int); virtual void apply(std::vector<Rec2DVertex*> &newPar); virtual void apply(Rec2DDataChange*); + virtual bool isObsolete(); virtual bool isAssumedObsolete(); static bool isObsolete(int*); virtual void getAssumedParities(int*); virtual bool whatWouldYouDo(std::map<Rec2DVertex*, std::vector<int> >&); + virtual inline Rec2DVertex* getVertex(int i) {return _vertices[i];} //- virtual inline int getNumElement() {return 2;} virtual void getElements(std::vector<Rec2DElement*>&); @@ -272,8 +278,11 @@ class Rec2DTwoTri2Quad : public Rec2DAction { virtual int getNum(double shiftx, double shifty); virtual Rec2DElement* getRandomElement(); + virtual void printCoord(); + private : virtual void _computeGlobQual(); + virtual void _computeGlobQual2(); }; class Rec2DEdge { @@ -290,7 +299,7 @@ class Rec2DEdge { void reveal(); double getQual(); - double getVal(); + double getWeightedQual(); inline double addHasTri() {_addWeight(-REC2D_EDGE_QUAD); ++_boundary;} inline double remHasTri() {_addWeight(REC2D_EDGE_QUAD); --_boundary;} @@ -400,7 +409,7 @@ class Rec2DElement { public : Rec2DElement(MTriangle*, Rec2DEdge**, Rec2DVertex **rv = NULL); Rec2DElement(MQuadrangle*, Rec2DEdge**, Rec2DVertex **rv = NULL); - ~Rec2DElement() { hide();} + ~Rec2DElement() {hide();} void hide(); void reveal();