How to use the discretize.TreeMesh.TreeMesh function in discretize

To help you get started, we’ve selected a few discretize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simpeg / simpeg / SimPEG / Tests.py View on Github external
return 1./nc

        elif 'Tree' in self._meshType:
            nc *= 2
            if 'uniform' in self._meshType or 'notatree' in self._meshType:
                h = [nc, nc, nc]
            elif 'random' in self._meshType:
                h1 = np.random.rand(nc)*nc*0.5 + nc*0.5
                h2 = np.random.rand(nc)*nc*0.5 + nc*0.5
                h3 = np.random.rand(nc)*nc*0.5 + nc*0.5
                h = [hi/np.sum(hi) for hi in [h1, h2, h3]]  # normalize
            else:
                raise Exception('Unexpected meshType')

            levels = int(np.log(nc)/np.log(2))
            self.M = Tree(h[:self.meshDimension], levels=levels)
            def function(cell):
                if 'notatree' in self._meshType:
                    return levels - 1
                r = cell.center - np.array([0.5]*len(cell.center))
                dist = np.sqrt(r.dot(r))
                if dist < 0.2:
                    return levels
                return levels - 1
            self.M.refine(function,balance=False)
            self.M.number(balance=False)
            # self.M.plotGrid(showIt=True)
            max_h = max([np.max(hi) for hi in self.M.h])
            return max_h