Skip to content
Snippets Groups Projects
Commit 1da210da authored by Van Dung NGUYEN's avatar Van Dung NGUYEN
Browse files

add new function

parent 62b643d5
No related branches found
No related tags found
1 merge request!309Master
...@@ -2544,6 +2544,12 @@ DeepMaterialNetwork::DeepMaterialNetwork(const Tree& T): _T(&T), _isInitialized( ...@@ -2544,6 +2544,12 @@ DeepMaterialNetwork::DeepMaterialNetwork(const Tree& T): _T(&T), _isInitialized(
#if defined(HAVE_PETSC) || defined(HAVE_GMM) #if defined(HAVE_PETSC) || defined(HAVE_GMM)
_sys = NULL; _sys = NULL;
#endif // #endif //
if (_T->checkDuplicate())
{
Msg::Error("Duplicating node exists, the computation cannot continue !!!");
Msg::Exit(0);
}
}; };
......
...@@ -958,6 +958,34 @@ int Tree::getNumberOfNodes() const ...@@ -958,6 +958,34 @@ int Tree::getNumberOfNodes() const
return allNodes.size(); return allNodes.size();
}; };
bool Tree::checkDuplicate() const
{
bool ok = false;
nodeContainer allNodes;
getAllNodes(allNodes);
std::set<int> nodeId;
for (int i=0; i< allNodes.size(); i++)
{
const TreeNode* node = allNodes[i];
std::set<int>::const_iterator itF = nodeId.find(node->getNodeId());
if (itF == nodeId.end())
{
nodeId.insert(node->getNodeId());
}
else
{
Msg::Error("node duplicating:");
node->printData();
ok = true;
}
}
if (!ok)
{
Msg::Info("no duplicatint node is found !!!");
}
return ok;
}
bool Tree::removeZeroLeaves(double tol, bool iteration) bool Tree::removeZeroLeaves(double tol, bool iteration)
{ {
bool ok = false; bool ok = false;
...@@ -1020,88 +1048,49 @@ bool Tree::removeZeroLeaves(double tol, bool iteration) ...@@ -1020,88 +1048,49 @@ bool Tree::removeZeroLeaves(double tol, bool iteration)
{ {
Msg::Info("----------------------------------"); Msg::Info("----------------------------------");
parent->printData(); parent->printData();
for (int i=0; i< parent->childs.size(); i++)
{
parent->childs[i]->printData();
}
std::vector<TreeNode*> newChilds;
bool found = false;
int removePos = -1;
for (int i=0; i< parent->childs.size(); i++)
{
if (parent->childs[i] == leaf)
{
found = true;
removePos = i;
}
if (!found)
{
newChilds.push_back(parent->childs[i]);
}
else
{
for (int j=i+1; j<parent->childs.size(); j++)
{
TreeNode* n = parent->childs[j];
n->childOrder = j-1;
newChilds.push_back(n);
};
break;
}
};
// //
std::vector<TreeNode*> newChilds;
std::vector<double> newDirection; std::vector<double> newDirection;
if (removePos > -1) //
{
int numberNormal = parent->childs.size()-1; int numberNormal = parent->childs.size()-1;
int totalNumberDirVars = parent->direction.size(); int totalNumberDirVars = parent->direction.size();
int numberVarsPerNormal = totalNumberDirVars/numberNormal; int numberVarsPerNormal = totalNumberDirVars/numberNormal;
//
if (removePos == 0) for (int j=0; j< parent->childs.size(); j++)
{ {
for (int j=numberVarsPerNormal; j< parent->direction.size(); j++) if (parent->childs[j]->location != leaf->location)
{ {
newDirection.push_back(parent->direction[j]); newChilds.push_back(parent->childs[j]);
} if (newChilds.size() > 1)
}
else if (removePos == parent->childs.size()-1)
{ {
for (int j=0; j< parent->direction.size()-numberVarsPerNormal; j++) if (numberVarsPerNormal == 1)
{ {
newDirection.push_back(parent->direction[j]); newDirection.push_back(parent->direction[j-1]);
} }
else if (numberVarsPerNormal == 2)
{
newDirection.push_back(parent->direction[(j-1)*numberVarsPerNormal]);
newDirection.push_back(parent->direction[(j-1)*numberVarsPerNormal+1]);
} }
else else
{ {
for (int j=0; j< (removePos-1)*numberVarsPerNormal; j++) Msg::Error("numberVarsPerNormal = %d is not correct !!!",numberVarsPerNormal);
{ Msg::Exit(0);
newDirection.push_back(parent->direction[j]);
} }
for (int j=(removePos)*numberVarsPerNormal; j< parent->direction.size(); j++)
{
newDirection.push_back(parent->direction[j]);
} }
} }
Msg::Info("old size = %d, new size = %d",parent->direction.size(),newDirection.size());
} }
else Msg::Info("\nSTART removing ");
{
Msg::Error("leaf is not removed correctly");
Msg::Exit(0);
};
parent->childs = newChilds;
parent->direction = newDirection;
Msg::Info("after removing");
parent->printData(); parent->printData();
for (int i=0; i< parent->childs.size(); i++) parent->childs = newChilds;
for (int j=0; j <parent->childs.size(); j++)
{ {
parent->childs[i]->printData(); parent->childs[j]->childOrder = j;
} }
Msg::Info("----------------------------------"); parent->direction = newDirection;
Msg::Info("------------------");
parent->printData();
Msg::Info("DONE removing\n");
} }
else else
{ {
......
...@@ -72,6 +72,7 @@ class Tree ...@@ -72,6 +72,7 @@ class Tree
void saveDataToFile(std::string filename) const; void saveDataToFile(std::string filename) const;
void loadDataFromFile(std::string filename); void loadDataFromFile(std::string filename);
int getNumberOfNodes() const; int getNumberOfNodes() const;
bool checkDuplicate() const;
double getPhaseFraction(int i) const; double getPhaseFraction(int i) const;
void printPhaseFraction() const; void printPhaseFraction() const;
void printLeafFraction() const; void printLeafFraction() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment