diff --git a/NonLinearSolver/modelReduction/Tree.cpp b/NonLinearSolver/modelReduction/Tree.cpp index 3d545a74ef9b2f32f81f9cb069df94f25ef0f5be..3858f487aaaed0cc52d0b58fbab1fe51096f678a 100644 --- a/NonLinearSolver/modelReduction/Tree.cpp +++ b/NonLinearSolver/modelReduction/Tree.cpp @@ -1188,6 +1188,18 @@ bool Tree::treeMerging() node->parent = parent->parent; node->childOrder = parent->childOrder; grandParent->childs[parent->childOrder] = node; + + // + // decrease all associated nodes by 1 + std::vector<TreeNode*> allAssociatedNodesToChild; + getRefToAssociatedNodes(node,allAssociatedNodesToChild); + for (int j=0; j< allAssociatedNodesToChild.size(); j++) + { + std::vector<int> loc; + getMaxLocationByDepth(loc); + allAssociatedNodesToChild[j]->depth--; + allAssociatedNodesToChild[j]->location=loc[allAssociatedNodesToChild[j]->depth]+1; + }; }; for (std::set<TreeNode*>::iterator itp = allParents.begin(); itp != allParents.end(); itp++) @@ -1367,7 +1379,10 @@ bool Tree::removeZeroBranches(double tol) getRefToAssociatedNodes(child,allAssociatedNodesToChild); for (int j=0; j< allAssociatedNodesToChild.size(); j++) { + std::vector<int> loc; + getMaxLocationByDepth(loc); allAssociatedNodesToChild[j]->depth--; + allAssociatedNodesToChild[j]->location=loc[allAssociatedNodesToChild[j]->depth]+1; }; Msg::Info("------------------"); @@ -1729,6 +1744,25 @@ void Tree::getAllNodesByDepth(std::map<int,std::vector<TreeNode*> >& allNodes) }; }; +void Tree::getMaxLocationByDepth(std::vector<int>& loc) const +{ + std::map<int,nodeContainer > allNodes; + getAllNodesByDepth(allNodes); + loc.resize(allNodes.size(),0); + for (std::map<int,nodeContainer >::const_iterator it = allNodes.begin(); it != allNodes.end(); it++) + { + const nodeContainer& depthNode = it->second; + for (int j=0; j< depthNode.size(); j++) + { + const TreeNode* node = depthNode[j]; + if (node->location >loc[it->first]) + { + loc[it->first]= node->location; + } + } + } +}; + void Tree::getAllNodesByDepth(std::map<int,nodeContainer >& allNodes) const { allNodes.clear(); diff --git a/NonLinearSolver/modelReduction/Tree.h b/NonLinearSolver/modelReduction/Tree.h index 7a5c631b980d7654f5ae67b0e274326e9bcc0264..dfaff94d743e2c810b69e96968dc6c43957465ab 100644 --- a/NonLinearSolver/modelReduction/Tree.h +++ b/NonLinearSolver/modelReduction/Tree.h @@ -86,6 +86,7 @@ class Tree void getAllLeaves(nodeContainer& allLeaves) const; void getAllNodes(nodeContainer& allNodes) const; void getAllNodesByDepth(std::map<int,nodeContainer>& allNodes) const; + void getMaxLocationByDepth(std::vector<int>& loc) const; void getAllNodesByDepth(std::map<int,std::vector<TreeNode*> >& allNodes); void getAssociatedLeavesForNode(const TreeNode* node, nodeContainer& allLeaves) const; void getAssociatedLeavesForNode(TreeNode* node, std::vector<TreeNode*>& allLeaves);