diff --git a/NonLinearSolver/modelReduction/Tree.cpp b/NonLinearSolver/modelReduction/Tree.cpp index 1c7cf9c7ad1eed50472b27ccd397ffd48537c8d4..e00abd926827ab13449157c16b9af3d2b7b99711 100644 --- a/NonLinearSolver/modelReduction/Tree.cpp +++ b/NonLinearSolver/modelReduction/Tree.cpp @@ -2130,7 +2130,7 @@ void Tree::clear() _root = NULL; }; -void Tree::initialize(bool rand) +void Tree::initialize(bool rand, bool normalizedWeight) { // random weight for leaves unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); @@ -2155,23 +2155,28 @@ void Tree::initialize(bool rand) for (int i=0; i< allLeaves.size(); i++) { TreeNode* n = allLeaves[i]; - n->weight = getVal(minWeight,maxWeight); + double randVal = getVal(minWeight,maxWeight); + n->weight = n->af->getReciprocalVal(randVal); toltalWeightLeaves += n->af->getVal(n->weight); } + for (int i=0; i< allLeaves.size(); i++) { TreeNode* n = allLeaves[i]; - double vv = (n->af->getVal(n->weight))/toltalWeightLeaves; - n->weight *= n->af->getReciprocalVal(vv); + if (normalizedWeight) + { + double vv = (n->af->getVal(n->weight))/toltalWeightLeaves; + n->weight = n->af->getReciprocalVal(vv); + } // propagate data double w = n->weight; - while (n->parent != NULL) + TreeNode* parent = n->parent; + while (parent != NULL) { - n->parent->weight += n->af->getVal(w); - n = n->parent; + parent->weight += n->af->getVal(w); + parent = parent->parent; }; }; - //printf("pi = %e\n",pi); double minAlpha = 0.; double maxAlpha = 1; diff --git a/NonLinearSolver/modelReduction/Tree.h b/NonLinearSolver/modelReduction/Tree.h index 20610abe277fb260a7af7bda56618a14c1ab5866..add67981d86b8e878528388aa0e10e3defa2193c 100644 --- a/NonLinearSolver/modelReduction/Tree.h +++ b/NonLinearSolver/modelReduction/Tree.h @@ -59,7 +59,7 @@ class Tree void printTree() const; void printTreeInteraction(const std::string fname="treeInteraction.txt", bool colorMat = true, int dir=1) const; void clear(); - void initialize(bool rand=true); + void initialize(bool rand=true, bool normalizedWeight=false); const TreeNode* getRootNode() const {return _root;}; void assignMaterialLaws(int numPhases);