コード例 #1
0
ファイル: HalfEdgeAVEMTest.py プロジェクト: ymjyxw/fealpy
    def uni_run(self):
        problem = self.problem
        options = self.optoptions
        model = problem['objective']
        mesh = problem['mesh']

        optalg = SteepestDescentAlg(problem, options)
        optalg.run()
コード例 #2
0
    def run(self, estimator='mix'):
        problem = self.problem
        options = self.optoptions
        model = problem['objective']
        mesh = problem['mesh']
        mesh = HalfEdgeMesh2d.from_mesh(mesh)

        #fig = plt.figure()
        #axes = fig.gca()
        #mesh.add_plot(axes)
        #mesh.find_node(axes, showindex=True)
        #mesh.find_cell(axes, showindex=True)
        #plt.show()

        aopts = mesh.adaptive_options(maxcoarsen=3, HB=True)
        while True:
            while True:
                print('NN', mesh.number_of_nodes())
                NC = mesh.number_of_cells()

                mu = problem['x0']
                if estimator == 'mix':
                    eta = model.mix_estimate(mu, w=1)
                if estimator == 'grad':
                    eta = model.estimate(q)

                aopts['data'] = {'mu': mu}
                S0 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,
                                                                           0])
                S1 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,
                                                                           1])

                mesh.adaptive(eta, aopts)

                model.reinit(mesh)
                aopts['data']['mu'] = np.zeros((model.gdof, 2))
                aopts['data']['mu'][:, 0] = model.vemspace.interpolation(
                    S0, aopts['HB'])
                aopts['data']['mu'][:, 1] = model.vemspace.interpolation(
                    S1, aopts['HB'])
                problem['x0'] = aopts['data']['mu']

                optalg = SteepestDescentAlg(problem, options)
                x, f, g, diff = optalg.run()
                problem['mesh'] = mesh
                problem['x0'] = x
                problem['rho'] = model.rho
                self.problem = problem

                if diff < options['FunValDiff']:
                    if (np.max(problem['rho'][:, 0]) < 1) and (np.min(
                            problem['rho'][:, 0]) > 0):
                        break
                pass
コード例 #3
0
ファイル: HalfEdgeAVEMTest.py プロジェクト: wphu/fealpy
    def run(self, estimator='mix'):
        problem = self.problem
        options = self.optoptions
        model = problem['objective']


        optalg = SteepestDescentAlg(problem, options)
        x, f, g, diff = optalg.run(maxit=500)
        while True:
            while True:
                mesh = problem['mesh']
                aopts = mesh.adaptive_options(method='mean', maxcoarsen=3, HB=True)
                print('NN', mesh.number_of_nodes())
                mu = problem['x0']
                if estimator == 'mix':
                    eta = model.mix_estimate(mu, w=1)
                if estimator == 'grad':
                    eta = model.estimate(q)

                aopts['data'] = {'mu':mu}
                S0 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,0])
                S1 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,1])


                mesh.adaptive(eta, aopts)

                model.reinit(mesh)
                aopts['data']['mu'] = np.zeros((model.gdof,2))
                aopts['data']['mu'][:,0] = model.vemspace.interpolation(S0, aopts['HB'])
                aopts['data']['mu'][:,1] = model.vemspace.interpolation(S1, aopts['HB'])
                problem['x0'] = aopts['data']['mu']

                optalg = SteepestDescentAlg(problem, options)
                x, f, g, diff = optalg.run(maxit=100)
                problem['mesh'] = mesh
                problem['x0'] = x
                problem['rho'] = model.rho
                self.problem = problem

                if diff < options['FunValDiff']:
                   if (np.max(problem['rho'][:,0]) < 1) and (np.min(problem['rho'][:,0]) >0):
                       break
                pass
コード例 #4
0
ファイル: test_avem_strong.py プロジェクト: ymjyxw/fealpy
    def run(self, estimator='mix'):
        problem = self.problem
        options = self.optoptions
        moptions = self.moptions
        model = problem['objective']

        optalg = SteepestDescentAlg(problem, options)
        x, f, g, diff = optalg.run(maxit=10)

        q = np.zeros(model.rho.shape)
        q[:, 0] = model.q0[:, -1]
        q[:, 1] = model.q1[:, -1]
        problem['x0'] = x
        while True:
            print('chiN', moptions['chiN'])
            while True:
                mesh = problem['mesh']  ##多边形网格
                hmesh = HalfEdgeMesh2d.from_mesh(mesh)  ##半边网格
                aopts = hmesh.adaptive_options(method='mean',
                                               maxcoarsen=3,
                                               HB=True)
                print('NN', mesh.number_of_nodes())

                mu = problem['x0']
                if estimator == 'mix':
                    eta = model.mix_estimate(q, w=1)
                if estimator == 'grad':
                    eta = model.estimate(q)

                aopts['data'] = {'mu': mu}
                S0 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,
                                                                           0])
                S1 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,
                                                                           1])

                hmesh.adaptive(eta, aopts)  ###半边网格做自适应
                mesh = PolygonMesh.from_halfedgemesh(hmesh)  ###多边形网格

                model.reinit(mesh)  ###多边形网格给进空间
                aopts['data']['mu'] = np.zeros((model.gdof, 2))
                aopts['data']['mu'][:, 0] = model.vemspace.interpolation(
                    S0, aopts['HB'])
                aopts['data']['mu'][:, 1] = model.vemspace.interpolation(
                    S1, aopts['HB'])
                problem['x0'] = aopts['data']['mu']

                optalg = SteepestDescentAlg(problem, options)
                x, f, g, diff = optalg.run(maxit=200)
                problem['mesh'] = mesh  ###多边形网格
                problem['x0'] = x
                problem['rho'] = model.rho
                self.problem = problem
                q = np.zeros(model.rho.shape)

                q[:, 0] = model.q0[:, -1]
                q[:, 1] = model.q1[:, -1]

                if diff < options['FunValDiff']:
                    if (np.max(problem['rho'][:, 0]) < 1) and (np.min(
                            problem['rho'][:, 0]) > 0):
                        break

            myfile = open(
                moptions['rdir'] + '/' + str(int(moptions['chiN'])) +
                'mesh.bin', 'wb')
            import pickle
            pickle.dump(problem['mesh'], myfile)
            myfile.close()
            model.save_data(moptions['rdir'] + '/' +
                            str(int(moptions['chiN'])) + '.mat')

            moptions['chiN'] += 5
            if moptions['chiN'] > 60:
                break
コード例 #5
0
    def run(self, estimator='grad'):
        problem = self.problem
        options = self.optoptions
        moptions = self.moptions
        model = problem['objective']
        mesh = problem['mesh']
        fig = plt.figure()
        axes = fig.gca()
        mesh.add_plot(axes, cellcolor='w')
        plt.show()
        #plt.savefig('flower15.png')
        #plt.savefig('flower15.pdf')
        #plt.close()

        optalg = SteepestDescentAlg(problem, options)
        x, f, g, diff = optalg.run(maxit=500)

        q = np.zeros(model.rho.shape)
        while True:
            print('chiN', moptions['chiN'])
            if moptions['chiN'] > 15:
                optalg = SteepestDescentAlg(problem, options)
                x, f, g, diff = optalg.run(maxit=10, eta_ref='etamaxmin')
            q = np.zeros(model.rho.shape)
            q[:, 0] = model.q0[:, -1]
            q[:, 1] = model.q1[:, -1]
            problem['x0'] = x
            while True:
                mesh = problem['mesh']
                hmesh = HalfEdgeMesh2d.from_mesh(mesh)
                aopts = hmesh.adaptive_options(method='mean',
                                               maxcoarsen=3,
                                               HB=True)
                print('NN', mesh.number_of_nodes())

                mu = problem['x0']
                if estimator == 'mix':
                    eta = model.mix_estimate(q, w=1)
                if estimator == 'grad':
                    eta = model.estimate(q)

                aopts['data'] = {'mu': mu}
                S0 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,
                                                                           0])
                S1 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,
                                                                           1])

                hmesh.adaptive(eta, aopts)
                mesh = PolygonMesh.from_halfedgemesh(hmesh)

                model.reinit(mesh)
                aopts['data']['mu'] = np.zeros((model.gdof, 2))
                aopts['data']['mu'][:, 0] = model.vemspace.interpolation(
                    S0, aopts['HB'])
                aopts['data']['mu'][:, 1] = model.vemspace.interpolation(
                    S1, aopts['HB'])
                problem['x0'] = aopts['data']['mu']

                optalg = SteepestDescentAlg(problem, options)
                x, f, g, diff = optalg.run(maxit=100)
                problem['mesh'] = mesh
                problem['x0'] = x
                problem['rho'] = model.rho
                q = np.zeros(model.rho.shape)

                q[:, 0] = model.q0[:, -1]
                q[:, 1] = model.q1[:, -1]

                if diff < options['FunValDiff']:
                    if (np.max(problem['rho'][:, 0]) < 1) and (np.min(
                            problem['rho'][:, 0]) > 0):
                        break
                myfile = open(
                    moptions['rdir'] + '/' + str(int(moptions['chiN'])) +
                    'mesh.bin', 'wb')
                import pickle
                pickle.dump(problem['mesh'], myfile)
                myfile.close()
                model.save_data(moptions['rdir'] + '/' +
                                str(int(moptions['chiN'])) + '.mat')

            moptions['chiN'] += 1
            if moptions['chiN'] > 60:
                break
コード例 #6
0
    def run(self, estimator='mix'):
        model = problem['objective']
        mesh = problem['mesh']
        mesh = HalfEdgeMesh.from_mesh(mesh)

        fig = plt.figure()
        axes = fig.gca()
        mesh.add_plot(axes)
        mesh.find_node(axes, showindex=True)
        mesh.find_cell(axes, showindex=True)

        aopts = mesh.adaptive_options(method='numrefine',
                                      maxcoarsen=3,
                                      HB=True)
        while True:
            while True:
                print('NN', mesh.number_of_nodes())
                NC = mesh.number_of_cells()

                mu = problem['x0']
                w = np.zeros(mu.shape)
                w[:, 0] = mu[:, 0] - mu[:, 1]
                w[:, 1] = mu[:, 0] + mu[:, 1]

                if estimator == 'mix':
                    #eta = model.mix_estimate(q,w=1)
                    eta = np.ones(NC, dtype=int)
                if estimator == 'grad':
                    eta = model.estimate(q)

                aopts['data'] = {'mu': mu}
                S0 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,
                                                                           0])
                S1 = model.vemspace.project_to_smspace(aopts['data']['mu'][:,
                                                                           1])

                mesh.adaptive(eta, aopts)

                fig = plt.figure()
                axes = fig.gca()
                mesh.add_plot(axes)
                mesh.find_node(axes, showindex=True)
                mesh.find_cell(axes, showindex=True)

                model.reinit(mesh)
                aopts['data']['mu'] = np.zeros((model.gdof, 2))
                aopts['data']['mu'][:, 0] = model.vemspace.interpolation(
                    S0, aopts['HB'])
                aopts['data']['mu'][:, 1] = model.vemspace.interpolation(
                    S1, aopts['HB'])
                problem['x0'] = aopts['data']['mu']

                optalg = SteepestDescentAlg(problem, options)
                x, f, g, diff = optalg.run()
                problem['mesh'] = mesh
                problem['x0'] = x
                q = model.rho.copy()
                q[:, 0] = model.q0[:, -1]
                q[:, 1] = model.q1[:, -1]

                if diff < options['FunValDiff']:
                    if (np.max(problem['rho'][:, 0]) < 1) and (np.min(
                            problem['rho'][:, 0]) > 0):
                        break
                pass
コード例 #7
0
from fealpy.opt.saddleoptalg import SteepestDescentAlg
from fealpy.quadrature import TriangleQuadrature

order = int(sys.argv[1])
n = int(sys.argv[2])

moptions = scftmodel_options(nspecies=2,
                             nblend=1,
                             nblock=2,
                             ndeg=100,
                             fA=0.2,
                             chiAB=0.25,
                             dim=2,
                             T0=20,
                             T1=80,
                             nupdate=0,
                             order=order)

mesh = complex_mesh(r=20, filename=sys.argv[2])
options = {
    'MaxIters': 500000,
    'MaxFunEvals': 500000,
    'NormGradTol': 1e-6,
    'FunValDiff': 1e-6,
    'StepLength': 2,
    'StepTol': 1e-14,
    'Output': True
}
optalg = SteepestDescentAlg(problem, options)
optalg.run(maxit=1)
コード例 #8
0
ファイル: QuadtreeAVEMTest.py プロジェクト: zweien/fealpy
        aopts['data'] = {'mu': mu}
        S0 = model.vemspace.project_to_smspace(aopts['data']['mu'][:, 0])
        S1 = model.vemspace.project_to_smspace(aopts['data']['mu'][:, 1])
        quadtree.adaptive(eta, aopts)
        print('NN', quadtree.number_of_nodes())
        mesh = quadtree.to_pmesh()
        model.reinit(mesh)
        aopts['data']['mu'] = np.zeros((model.gdof, 2))
        aopts['data']['mu'][:,
                            0] = model.vemspace.interpolation(S0, aopts['HB'])
        aopts['data']['mu'][:,
                            1] = model.vemspace.interpolation(S1, aopts['HB'])
        problem['x0'] = aopts['data']['mu']

        optalg = SteepestDescentAlg(problem, options)
        x, f, g, diff = optalg.run()
        problem['rho'] = model.rho
        problem['quadtree'] = quadtree
        problem['x0'] = x
        q = model.rho.copy()
        q[:, 0] = model.q0[:, -1]
        q[:, 1] = model.q1[:, -1]

        if diff < options['FunValDiff']:
            if (np.max(problem['rho'][:, 0]) < 1) and (np.min(
                    problem['rho'][:, 0]) > 0):
                break

    myfile = open(str(int(moptions['chiN'])) + 'quadtree.bin', 'wb')
    import pickle