Skip to content
Snippets Groups Projects
Select Git revision
  • a3711e5e8f73221b8d04be8506cc8c91946cd0b1
  • master default protected
  • alphashapes
  • quadMeshingTools
  • cygwin_conv_path
  • macos_arm64
  • add-transfiniteautomatic-to-geo
  • patch_releases_4_10
  • HierarchicalHDiv
  • isuruf-master-patch-63355
  • hyperbolic
  • hexdom
  • hxt_update
  • jf
  • 1618-pythonocc-and-gmsh-api-integration
  • octreeSizeField
  • hexbl
  • alignIrregularVertices
  • getEdges
  • patch_releases_4_8
  • isuruf-master-patch-51992
  • gmsh_4_11_0
  • gmsh_4_10_5
  • gmsh_4_10_4
  • gmsh_4_10_3
  • gmsh_4_10_2
  • gmsh_4_10_1
  • gmsh_4_10_0
  • gmsh_4_9_5
  • gmsh_4_9_4
  • gmsh_4_9_3
  • gmsh_4_9_2
  • gmsh_4_9_1
  • gmsh_4_9_0
  • gmsh_4_8_4
  • gmsh_4_8_3
  • gmsh_4_8_2
  • gmsh_4_8_1
  • gmsh_4_8_0
  • gmsh_4_7_1
  • gmsh_4_7_0
41 results

BackgroundMesh.cpp

Blame
  • Forked from gmsh / gmsh
    Source project has a limited visibility.
    Tree.h 4.34 KiB
    //
    // C++ Interface:  tree
    //
    //
    // Author:  <V.-D. Nguyen>, (C) 2020
    //
    // Copyright: See COPYING file that comes with this distribution
    //
    //
    #ifndef _TREE_H_
    #define _TREE_H_ 
    
    #ifndef SWIG
    #include "ANNUtils.h"
    #include <vector>
    #include "SVector3.h"
    #endif //SWIG
    
    class TreeNode
    {
      public:
        #ifndef SWIG
        activationFunction* af; // to make sure weight is posible when upscale 
        std::vector<double> direction; // direction data = (nuChilds-1) in 2D and (nuChilds-1)*2 in 3D 
        double weight; 
        int depth; // in layer 0 - root, 
        int location; // location in vector of childs of parent node
        int childOrder; // order in childlist of paraent
        TreeNode* parent; // parent node (NULL for root node)
        std::vector<TreeNode*> childs; // child nodes (NULL for last nodes)
        int matIndex; // specify material number -1 by default
        #endif //SWIG
        TreeNode();
        TreeNode(int k, int c, TreeNode* p, int o, const std::string affunc="relu");
        virtual ~TreeNode();
        int getNodeId() const{return location*1000+depth;};
        void printData() const;
        #ifndef SWIG
        void saveToFile(FILE* file) const;
        void getNormal(std::vector<SVector3>& vec, bool stiff=false, std::vector<std::vector<SVector3> >* DnormalDunknown=NULL) const;
        #endif //SWIG
    };
    
    class Tree
    {
      public:
        typedef std::vector<const TreeNode*> nodeContainer;
      
      public:
        Tree();  
        ~Tree();
        void createPerfectTree(int maxDepth, int numChild, int numDirVars, const std::string affunc="relu");
        void createPerfectTree(int maxDepth, int numChildRegular, int numChildLeaf, int numDirVars, const std::string affunc="relu", int lastRepeat=1);
        void createMixedTree(int maxDepth, int numChildMax, int leafPerNode, int numDirVars,const std::string affunc="relu");
        void createRandomTree(int nbLeaves, int numChildMax, int leafPerNode, int numDirVars,const std::string affunc="relu", bool randomSubdivion=true, bool randomChild=true, bool sameNbChildLayer=true);
        void createRandomTreeSameDepthForNodes(int nbLeaves, int numChildMax, int leafPerNode, int numDirVars,const std::string affunc="relu", bool randomChild=true, bool randomMat=true);
        void createSpecialBinaryTree(int numNodes, int numDirVars,const std::string affunc="relu");
        void createSpecialTripleTree(int numNodes, int numDirVars,const std::string affunc="relu");
        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, bool normalizedWeight=true, bool type = true);
        const TreeNode* getRootNode() const {return _root;};
        
        void assignMaterialLaws(int numPhases);
        
        void printAllRegularNodes() const;
        
        void printAssociatedLeavesForNode(const TreeNode* node) const;
        void printBackTrackingPath(const TreeNode* node) const;
        
        void saveDataToFile(std::string filename) const;
        void loadDataFromFile(std::string filename);
        int getNumberOfNodes() const;
        bool checkDuplicate() const;
        double getPhaseFraction(int i) const;
        void printPhaseFraction() const;
        void printLeafFraction() const;
        void printNodeFraction() const;
        
        bool removeLeavesWithZeroContribution(double tol=1e-6);
        bool removeZeroBranches(double tol);
        bool removeZeroLeaves(double tol, bool iteration=true);
        bool treeMerging();
        
        #ifndef SWIG
        void getAllRegularNodes(nodeContainer& allRegNodes) const;
        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);
        void getBackTrackingPath(const TreeNode* node, nodeContainer& path) const;
        double getNonNegativeWeight(const TreeNode* node) const;
        void getRefToAllLeaves(std::vector<TreeNode*>& allLeaves);
        void getRefToAllNodes(std::vector<TreeNode*>& allNodes);  
        void getRefToAssociatedNodes(TreeNode* node, std::vector<TreeNode*>& allNodes);
        #endif //SWIG
      
      protected:
        #ifndef SWIG
        TreeNode* _root;
        #endif //SWIG
    };
    #endif //_TREE_H_