├── .gitignore ├── Aux_tools ├── FDM2CoupleBiharmonic │ ├── ABS2FDM_Mesh6.eps │ ├── ABS2FDM_Mesh6.png │ ├── ABS2FDM_Mesh7.eps │ ├── ABS2FDM_Mesh7.png │ ├── ABS2FDM_Mesh8.eps │ ├── ABS2FDM_Mesh8.png │ ├── ABS2FDM_Mesh9.eps │ ├── ABS2FDM_Mesh9.png │ ├── FDM2Biharmonic_Couple2Dirichlet_Zero.m │ ├── FDM2Biharmonic_CoupleScheme.m │ ├── FDM2Possion.m │ ├── FDM2Possion_Dirchlet_Zero.m │ ├── Poisson_matrix.m │ ├── result2fdm.txt │ ├── result2fdm_mesh6.txt │ ├── result2fdm_mesh7.txt │ ├── result2fdm_mesh8.txt │ └── result2fdm_mesh9.txt ├── gene_mesh01 │ ├── assemble_fmesh.m │ ├── generate_mesh.m │ ├── meshXY6.mat │ ├── meshXY7.mat │ └── quadtreeind.m ├── plot_scatter │ └── plot_solu_perr.m └── tools2matlab │ ├── assemble_fmesh.m │ ├── generate_mesh.m │ ├── plot_fun.m │ ├── plot_fun2in.m │ ├── plot_pointError.m │ ├── plot_solu_perr.m │ └── quadtreeind.m ├── Experiments ├── BiCELM_Navier │ ├── Bi_CELM_2DNavier.py │ └── Bi_CELM_3DNavier.py ├── Possion │ ├── Possion1D.py │ ├── Possion2D.py │ └── Possion3D.py ├── data2Biharmonic3D │ ├── TestXYZ.mat │ ├── TrainXYZ.mat │ ├── TrainXYZbd1.mat │ └── TrainXYZbd2.mat ├── data2points │ ├── Irregular_domain01 │ │ ├── liujiaoxing_domain2D.asv │ │ ├── liujiaoxing_domain2D.m │ │ ├── testXY.mat │ │ └── test_point.m │ ├── Irregular_domain11 │ │ ├── liujiaoxing_domain2D.asv │ │ ├── liujiaoxing_domain2D.m │ │ ├── testXY.mat │ │ └── test_point.m │ ├── create_mesh │ │ ├── create3D_data.m │ │ ├── create4D_data.m │ │ ├── create5D_data.m │ │ ├── create_2Dmesh.m │ │ ├── load_recover_solu.m │ │ ├── recover_index.m │ │ ├── recover_solu.m │ │ ├── reorder_index.m │ │ ├── testXY.mat │ │ ├── testXYZ.mat │ │ ├── testXYZS.mat │ │ └── testXYZST.mat │ ├── gene_mesh01 │ │ ├── assemble_fmesh.m │ │ ├── generate_mesh.m │ │ ├── meshXY6.mat │ │ ├── meshXY7.mat │ │ └── quadtreeind.m │ └── gene_mesh11 │ │ ├── assemble_fmesh.m │ │ ├── generate_mesh.m │ │ ├── meshXY6.mat │ │ ├── meshXY7.mat │ │ └── quadtreeind.m └── dataMat_highDim │ ├── ThreeD2Fixed_X │ ├── assemble_fmesh.m │ ├── generate_mesh.m │ ├── plot_fun.m │ ├── plot_fun2in.m │ ├── plot_pointError.m │ ├── plot_solu_perr.m │ ├── quadtreeind.m │ └── testXYZ7.mat │ ├── ThreeD2Fixed_Y │ ├── assemble_fmesh.m │ ├── generate_mesh.m │ ├── plot_fun.m │ ├── plot_fun2in.m │ ├── plot_pointError.m │ ├── plot_solu_perr.m │ ├── quadtreeind.m │ └── testXYZ.mat │ ├── ThreeD2Fixed_Z │ ├── assemble_fmesh.m │ ├── generate_mesh.m │ ├── plot_fun.m │ ├── plot_fun2in.m │ ├── plot_pointError.m │ ├── plot_solu_perr.m │ ├── quadtreeind.m │ └── testXYZ7.mat │ ├── Untitled.m │ ├── generate_data.m │ ├── testXY.mat │ ├── testXYZ.mat │ ├── testXYZRSTVW.mat │ ├── testXYZS.mat │ └── testXYZST.mat ├── LICENSE ├── Networks ├── ELM_Base.py └── __pycache__ │ └── ELM_Base.cpython-39.pyc ├── Problems ├── Biharmonic_eqs.py ├── General_Laplace.py └── __pycache__ │ └── General_Laplace.cpython-39.pyc ├── README.md ├── Results └── Laplace1D │ ├── 10m_23d_21h_48m_30s │ ├── Possion1D.py │ └── log.txt │ ├── 10m_23d_21h_51m_33s │ ├── Possion1D.py │ └── log.txt │ └── 10m_23d_21h_52m_5s │ ├── Possion1D.py │ └── log.txt └── utilizers ├── DNN_tools.py ├── Load_data2Mat.py ├── RFN_Log_Print.py ├── __pycache__ ├── DNN_tools.cpython-39.pyc ├── Load_data2Mat.cpython-39.pyc ├── RFN_Log_Print.cpython-39.pyc ├── dataUtilizer2numpy.cpython-39.pyc ├── plot_data.cpython-39.pyc └── saveData.cpython-39.pyc ├── dataUtilizer2numpy.py ├── plot_data.py └── saveData.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/ABS2FDM_Mesh6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/ABS2FDM_Mesh6.png -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/ABS2FDM_Mesh7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/ABS2FDM_Mesh7.png -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/ABS2FDM_Mesh8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/ABS2FDM_Mesh8.png -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/ABS2FDM_Mesh9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/ABS2FDM_Mesh9.png -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/FDM2Biharmonic_Couple2Dirichlet_Zero.m: -------------------------------------------------------------------------------- 1 | function Uapp = FDM2Biharmonic_Couple2Dirichlet_Zero(Nx, Ny, xleft, xright, ybottom, ytop, fside) 2 | format long; 3 | 4 | % Define the step sizes and create the grid without boundary points 5 | hx = (xright-xleft)/Nx; 6 | x = zeros(Nx-1,1); 7 | for ix=1:Nx-1 8 | x(ix) = xleft+ix*hx; 9 | end 10 | 11 | hy = (ytop-ybottom)/Ny; 12 | y=zeros(Ny-1,1); 13 | for iy=1:Ny-1 14 | y(iy) = ybottom+iy*hy; 15 | end 16 | 17 | % Define the source term 18 | source_term = fside; 19 | 20 | % Initialize the coefficient matrix A and the right-hand side vector F 21 | N = (Ny-1)*(Nx-1); 22 | A = sparse(N,N); 23 | FV = zeros(N,1); 24 | 25 | % Loop through each inner grid point, Apply finite difference scheme (central differences) 26 | hx1 = hx*hx; 27 | hy1 = hy*hy; 28 | for jv = 1:Ny-1 29 | for iv=1:Nx-1 30 | kv = iv + (jv-1)*(Nx-1); 31 | FV(kv) = fside(x(iv),y(jv)); 32 | A(kv,kv) = -2/hx1 -2/hy1; 33 | 34 | %-- x direction -------------- 35 | if iv == 1 36 | A(kv,kv+1) = 1/hx1; 37 | else 38 | if iv==Nx-1 39 | A(kv,kv-1) = 1/hx1; 40 | else 41 | A(kv,kv-1) = 1/hx1; 42 | A(kv,kv+1) = 1/hx1; 43 | end 44 | end 45 | %-- y direction -------------- 46 | if jv == 1 47 | A(kv,kv+Nx-1) = 1/hy1; 48 | else 49 | if jv==Ny-1 50 | A(kv,kv-(Nx-1)) = 1/hy1; 51 | else 52 | A(kv,kv-(Nx-1)) = 1/hy1; 53 | A(kv,kv+Nx-1) = 1/hy1; 54 | end 55 | end 56 | end 57 | end 58 | V = A\FV; 59 | 60 | B = sparse(N,N); 61 | FU = zeros(N,1); 62 | 63 | % Loop through each inner grid point, Apply finite difference scheme (central differences) 64 | for ju = 1:Ny-1 65 | for iu=1:Nx-1 66 | ku = iu + (ju-1)*(Nx-1); 67 | FV(ku) = V(ku); 68 | B(ku,ku) = -2/hx1 -2/hy1; 69 | 70 | %-- x direction -------------- 71 | if iu == 1 72 | B(ku,ku+1) = 1/hx1; 73 | else 74 | if iu==Nx-1 75 | B(ku,ku-1) = 1/hx1; 76 | else 77 | B(ku,ku-1) = 1/hx1; 78 | B(ku,ku+1) = 1/hx1; 79 | end 80 | end 81 | %-- y direction -------------- 82 | if ju == 1 83 | B(ku,ku+Nx-1) = 1/hy1; 84 | else 85 | if ju==Ny-1 86 | B(ku,ku-(Nx-1)) = 1/hy1; 87 | else 88 | B(ku,ku-(Nx-1)) = 1/hy1; 89 | B(ku,ku+Nx-1) = 1/hy1; 90 | end 91 | end 92 | end 93 | end 94 | 95 | U = B\FV; 96 | %--- Transform back to (i,j) form to plot the solution --- 97 | j = 1; 98 | for k=1:N 99 | i = k - (j-1)*(Nx-1) ; 100 | Uapp(i,j) = U(k); 101 | j = fix(k/(Nx-1)) + 1; 102 | end 103 | end -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/FDM2Biharmonic_CoupleScheme.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/FDM2Biharmonic_CoupleScheme.m -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/FDM2Possion.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/FDM2Possion.m -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/FDM2Possion_Dirchlet_Zero.m: -------------------------------------------------------------------------------- 1 | function Uapp = FDM2Possion_Dirchlet_Zero(Nx, Ny, xleft, xright, ybottom, ytop, fside) 2 | format long; 3 | 4 | % Define the step sizes and create the grid without boundary points 5 | hx = (xright-xleft)/Nx; 6 | x = zeros(Nx-1,1); 7 | for i=1:Nx-1 8 | x(i) = xleft+i*hx; 9 | end 10 | 11 | hy = (ytop-ybottom)/Ny; 12 | y=zeros(Ny-1,1); 13 | for i=1:Ny-1 14 | y(i) = ybottom+i*hy; 15 | end 16 | 17 | % Define the source term 18 | source_term = fside; 19 | 20 | % Initialize the coefficient matrix A and the right-hand side vector F 21 | N = (Ny-1)*(Nx-1); 22 | A = sparse(N,N); 23 | F = zeros(N,1); 24 | 25 | % Loop through each inner grid point, Apply finite difference scheme (central differences) 26 | hx1 = hx*hx; 27 | hy1 = hy*hy; 28 | for j = 1:Ny-1 29 | for i=1:Nx-1 30 | k = i + (j-1)*(Nx-1); 31 | F(k) = fside(x(i),y(j)); 32 | A(k,k) = -2/hx1 -2/hy1; 33 | 34 | %-- x direction -------------- 35 | if i == 1 36 | A(k,k+1) = 1/hx1; 37 | else 38 | if i==Nx-1 39 | A(k,k-1) = 1/hx1; 40 | else 41 | A(k,k-1) = 1/hx1; 42 | A(k,k+1) = 1/hx1; 43 | end 44 | end 45 | %-- y direction -------------- 46 | if j == 1 47 | A(k,k+Nx-1) = 1/hy1; 48 | else 49 | if j==Ny-1 50 | A(k,k-(Nx-1)) = 1/hy1; 51 | else 52 | A(k,k-(Nx-1)) = 1/hy1; 53 | A(k,k+Nx-1) = 1/hy1; 54 | end 55 | end 56 | end 57 | end 58 | 59 | U = A\F; 60 | 61 | %--- Transform back to (i,j) form to plot the solution --- 62 | j = 1; 63 | for k=1:N 64 | i = k - (j-1)*(Nx-1) ; 65 | Uapp(i,j) = U(k); 66 | j = fix(k/(Nx-1)) + 1; 67 | end 68 | end -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/Poisson_matrix.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %%%% Matrix method for Poisson Equation %%%% 3 | %%% u_{xx} + u_{yy} = f(x, y), 0 < x < 1, 0 < y < 1 %%%% 4 | %%% u(x, y) = 0 on boundary, %%%% 5 | %%% Exact soln: u(x, y) = sin(pi*x)*sin(pi*y) %%%% 6 | %%% Here f(x, y) = -2*pi^2*sin(pi*x)*sin(pi*y); %%%% 7 | %%% Course: MATH F422, Dr. P. Dhanumjaya %%%% 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | 10 | clc; 11 | clear all; 12 | close all; 13 | 14 | fpoisson = @(x, y) -2*pi^2*sin(pi*x).*sin(pi*y); 15 | uexact = @(x, y) sin(pi*x).*sin(pi*y); 16 | 17 | xleft = 0; 18 | xright = 1; 19 | ybottom = 0; 20 | ytop = 1; 21 | 22 | Nx = 100; 23 | Ny = 100; 24 | 25 | format long; 26 | 27 | hx = (xright-xleft)/Nx; 28 | x = zeros(Nx-1,1); 29 | for i=1:Nx-1 30 | x(i) = xleft+i*hx; 31 | end 32 | 33 | hy = (ytop-ybottom)/Ny; 34 | y=zeros(Ny-1,1); 35 | for i=1:Ny-1 36 | y(i) = ybottom+i*hy; 37 | end 38 | 39 | 40 | N = (Ny-1)*(Nx-1); 41 | A = sparse(N,N); 42 | F = zeros(N,1); 43 | 44 | hx1 = hx*hx; 45 | hy1 = hy*hy; 46 | for j = 1:Ny-1 47 | for i=1:Nx-1 48 | k = i + (j-1)*(Nx-1); 49 | F(k) = fpoisson(x(i),y(j)); 50 | A(k,k) = -2/hx1 -2/hy1; 51 | if i == 1 52 | A(k,k+1) = 1/hx1; 53 | else 54 | if i==Nx-1 55 | A(k,k-1) = 1/hx1; 56 | else 57 | A(k,k-1) = 1/hx1; 58 | A(k,k+1) = 1/hx1; 59 | end 60 | end 61 | %-- y direction -------------- 62 | if j == 1 63 | A(k,k+Nx-1) = 1/hy1; 64 | else 65 | if j==Ny-1 66 | A(k,k-(Nx-1)) = 1/hy1; 67 | else 68 | A(k,k-(Nx-1)) = 1/hy1; 69 | A(k,k+Nx-1) = 1/hy1; 70 | end 71 | end 72 | end 73 | end 74 | 75 | U = A\F; 76 | 77 | %--- Transform back to (i,j) form to plot the solution --- 78 | j = 1; 79 | for k=1:N 80 | i = k - (j-1)*(Nx-1) ; 81 | Uapp(i,j) = U(k); 82 | Uex(i,j) = uexact(x(i),y(j)); 83 | j = fix(k/(Nx-1)) + 1; 84 | end 85 | 86 | % Analyze abd Visualize the result. 87 | 88 | e = max( max( abs(Uapp-Uex))) % The maximum error 89 | 90 | surf(x,y,Uapp); 91 | title('The Approximate solution plot'); 92 | xlabel('x'); 93 | ylabel('y'); 94 | 95 | figure(2); 96 | surf(x,y,Uex); 97 | title('The Exact solution plot'); 98 | xlabel('x'); 99 | ylabel('y'); 100 | -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/result2fdm.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/result2fdm.txt -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/result2fdm_mesh6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/result2fdm_mesh6.txt -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/result2fdm_mesh7.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/result2fdm_mesh7.txt -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/result2fdm_mesh8.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/result2fdm_mesh8.txt -------------------------------------------------------------------------------- /Aux_tools/FDM2CoupleBiharmonic/result2fdm_mesh9.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/FDM2CoupleBiharmonic/result2fdm_mesh9.txt -------------------------------------------------------------------------------- /Aux_tools/gene_mesh01/assemble_fmesh.m: -------------------------------------------------------------------------------- 1 | function geom = assemble_fmesh(geom) 2 | %ASSEMBLE_FMESH generate fine mesh for [-1, 1] x [-1, 1] 3 | % this requires the side length geom.L = (geom.N1+1)*geom.h 4 | 5 | if nargin == 0 6 | test_assemble_fmesh; 7 | return 8 | end 9 | 10 | hx = (geom.xend - geom.xstart)/(geom.N1+1); 11 | hy = (geom.yend - geom.ystart)/(geom.N1+1); 12 | xline = geom.xstart:hx: geom.xend; 13 | yline = geom.ystart:hy:geom.yend; 14 | [x, y] = meshgrid(geom.xstart:hx:geom.xend, geom.ystart:hy:geom.yend); 15 | geom.X = x; 16 | geom.Y = y; 17 | 18 | x = x'; x = x(:)'; 19 | y = y'; y = y(:)'; 20 | 21 | p = [x; y]; 22 | 23 | % create the element matrix t for square elements 24 | N = geom.N1 + 1; 25 | t = zeros(4, N^2); 26 | nb = speye(N^2, N^2); 27 | for i = 1:N 28 | for j = 1:N 29 | ind = i + N*(j-1); 30 | t(:, ind) = [ 31 | (j-1)*(N+1)+i; 32 | (j-1)*(N+1)+i+1; 33 | j*(N+1)+i; 34 | j*(N+1)+i+1; 35 | ]; 36 | % pt is the center of elements t 37 | pt(:, ind) = sum(p(:, t(:, ind)), 2)/4; 38 | end 39 | end 40 | 41 | % identify interior dofs and boundary dofs 42 | ib = abs(x)==geom.xstart | abs(x)==geom.xend | abs(y)==geom.ystart | abs(y)==geom.yend; 43 | in = not(ib); 44 | pin = p(:, in); 45 | 46 | % [ind, ~, ~, adjmatrix, ~, ~] = quadtree(pin(1, :), pin(2, :), [], 1); 47 | % ind is the index of regions 48 | % bx, by denotes the order in x and y direction respectively 49 | % nb is the adjacency matrix of regions 50 | ind = quadtreeind(geom.q); 51 | 52 | % now reorder the dofs by the regions, this create a natural order 53 | % multiresolution operations by using the base 4 representation of indices 54 | % r1 = pin(1, ind) 55 | % r2 = pin(2, ind) 56 | pin(:, ind) = pin; 57 | nb = sparse(nb); 58 | 59 | geom.p = p; 60 | geom.t = t; 61 | geom.pt = pt; 62 | geom.ib = ib; 63 | geom.in = in; 64 | geom.ind = ind; 65 | geom.pin = pin; 66 | % geom.adjmatrix = adjmatrix; 67 | end 68 | 69 | function test_assemble_fmesh 70 | q = 3; 71 | nl = 2; 72 | T = []; 73 | J = []; 74 | 75 | % geom: (only square geometry available now) 76 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 77 | geom.q = q; 78 | geom.nl = nl; 79 | geom.L = 2; % side length 80 | geom.dim = 2; % dimension of the problem 81 | geom.m = 2^geom.dim; % 82 | geom.N1 = 2^q; % dofs in one dimension 83 | geom.N = (geom.m)^geom.q; % dofs in the domain 84 | geom.h = geom.L/(geom.N1+1); % grid size 85 | 86 | geom = assemble_fmesh(geom); 87 | 88 | meshin = geom.pin; 89 | 90 | end -------------------------------------------------------------------------------- /Aux_tools/gene_mesh01/generate_mesh.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | q = 6; 5 | % q = 7; 6 | nl = 2; 7 | T = []; 8 | J = []; 9 | 10 | % geom: (only square geometry available now) 11 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 12 | geom.q = q; 13 | geom.nl = nl; 14 | geom.dim = 2; % dimension of the problem 15 | geom.m = 2^geom.dim; % 16 | geom.N1 = 2^q; % dofs in one dimension, uniformly sampling 2^q points in range (a, b), not including edges 17 | geom.N = (geom.m)^geom.q; % dofs in the domain 18 | geom.xstart = 0; 19 | geom.xend = 1; 20 | geom.ystart = 0; 21 | geom.yend = 1; 22 | 23 | 24 | geom = assemble_fmesh(geom); 25 | 26 | meshXY = geom.pin; % the point pair for interior of square of [a,b]X[c,d], not including edges 27 | 28 | if q == 3 29 | save('meshXY3.mat', 'meshXY') 30 | elseif q == 4 31 | save('meshXY4.mat', 'meshXY') 32 | elseif q == 5 33 | save('meshXY5.mat', 'meshXY') 34 | elseif q == 6 35 | save('meshXY6.mat', 'meshXY') 36 | elseif q == 7 37 | save('meshXY7.mat', 'meshXY') 38 | end -------------------------------------------------------------------------------- /Aux_tools/gene_mesh01/meshXY6.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/gene_mesh01/meshXY6.mat -------------------------------------------------------------------------------- /Aux_tools/gene_mesh01/meshXY7.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Aux_tools/gene_mesh01/meshXY7.mat -------------------------------------------------------------------------------- /Aux_tools/gene_mesh01/quadtreeind.m: -------------------------------------------------------------------------------- 1 | function ind = quadtreeind(q) 2 | % construct quadtree index 3 | m = 4; 4 | 5 | M = [1 2; 3 4]; 6 | 7 | for k = 2:q 8 | M = [M M+m^(k-1); M+2*m^(k-1) M+3*m^(k-1)]; 9 | end 10 | 11 | ind = M(:)'; 12 | 13 | end -------------------------------------------------------------------------------- /Aux_tools/plot_scatter/plot_solu_perr.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all 3 | close all 4 | ftsz = 15; 5 | 6 | testPoint = load('testData2XY.mat'); 7 | XY = (testPoint.Points2XY)'; 8 | X = XY(1,:); 9 | Y = XY(2, :); 10 | 11 | solu2exact = load('Utrue'); 12 | solu2numerical = load('Unumeri'); 13 | Solu_UTrue = solu2exact.UTRUE; 14 | Solu_UDNN = solu2numerical.UNUMERI; 15 | 16 | figure('name','Exact_Solu') 17 | ct = Solu_UTrue; 18 | scatter_solu2u = scatter3(X, Y, Solu_UTrue,50, ct, '.'); 19 | shading interp 20 | hold on 21 | colorbar; 22 | caxis([0 1]) 23 | hold on 24 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 25 | set(gcf, 'Renderer', 'zbuffer'); 26 | hold on 27 | 28 | figure('name','DNN_Solu') 29 | cn = Solu_UDNN; 30 | mesh_solu_unn =scatter3(X, Y, Solu_UDNN, 50, cn, '.'); 31 | shading interp 32 | hold on 33 | colorbar; 34 | caxis([0 1]) 35 | hold on 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | hold on 39 | 40 | err2solu = abs(Solu_UTrue-Solu_UDNN); 41 | figure('name','Err2solu') 42 | cp = err2solu; 43 | mesh_solu_err2u = scatter3(X, Y, err2solu, 50, cp, '.'); 44 | shading interp 45 | title('Absolute Error') 46 | hold on 47 | colorbar; 48 | caxis([0 1e-8]) 49 | hold on 50 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 51 | set(gcf, 'Renderer', 'zbuffer'); 52 | hold on 53 | 54 | 55 | -------------------------------------------------------------------------------- /Aux_tools/tools2matlab/assemble_fmesh.m: -------------------------------------------------------------------------------- 1 | function geom = assemble_fmesh(geom) 2 | %ASSEMBLE_FMESH generate fine mesh for [-1, 1] x [-1, 1] 3 | % this requires the side length geom.L = (geom.N1+1)*geom.h 4 | 5 | if nargin == 0 6 | test_assemble_fmesh; 7 | return 8 | end 9 | 10 | hx = (geom.xend - geom.xstart)/(geom.N1+1); 11 | hy = (geom.yend - geom.ystart)/(geom.N1+1); 12 | xline = geom.xstart:hx: geom.xend; 13 | yline = geom.ystart:hy:geom.yend; 14 | [x, y] = meshgrid(geom.xstart:hx:geom.xend, geom.ystart:hy:geom.yend); 15 | geom.X = x; 16 | geom.Y = y; 17 | 18 | x = x'; x = x(:)'; 19 | y = y'; y = y(:)'; 20 | 21 | p = [x; y]; 22 | 23 | % create the element matrix t for square elements 24 | N = geom.N1 + 1; 25 | t = zeros(4, N^2); 26 | nb = speye(N^2, N^2); 27 | for i = 1:N 28 | for j = 1:N 29 | ind = i + N*(j-1); 30 | t(:, ind) = [ 31 | (j-1)*(N+1)+i; 32 | (j-1)*(N+1)+i+1; 33 | j*(N+1)+i; 34 | j*(N+1)+i+1; 35 | ]; 36 | % pt is the center of elements t 37 | pt(:, ind) = sum(p(:, t(:, ind)), 2)/4; 38 | end 39 | end 40 | 41 | % identify interior dofs and boundary dofs 42 | ib = abs(x)==geom.xstart | abs(x)==geom.xend | abs(y)==geom.ystart | abs(y)==geom.yend; 43 | in = not(ib); 44 | pin = p(:, in); 45 | 46 | % [ind, ~, ~, adjmatrix, ~, ~] = quadtree(pin(1, :), pin(2, :), [], 1); 47 | % ind is the index of regions 48 | % bx, by denotes the order in x and y direction respectively 49 | % nb is the adjacency matrix of regions 50 | ind = quadtreeind(geom.q); 51 | 52 | % now reorder the dofs by the regions, this create a natural order 53 | % multiresolution operations by using the base 4 representation of indices 54 | % r1 = pin(1, ind) 55 | % r2 = pin(2, ind) 56 | pin(:, ind) = pin; 57 | nb = sparse(nb); 58 | 59 | geom.p = p; 60 | geom.t = t; 61 | geom.pt = pt; 62 | geom.ib = ib; 63 | geom.in = in; 64 | geom.ind = ind; 65 | geom.pin = pin; 66 | % geom.adjmatrix = adjmatrix; 67 | end 68 | 69 | function test_assemble_fmesh 70 | q = 3; 71 | nl = 2; 72 | T = []; 73 | J = []; 74 | 75 | % geom: (only square geometry available now) 76 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 77 | geom.q = q; 78 | geom.nl = nl; 79 | geom.L = 2; % side length 80 | geom.dim = 2; % dimension of the problem 81 | geom.m = 2^geom.dim; % 82 | geom.N1 = 2^q; % dofs in one dimension 83 | geom.N = (geom.m)^geom.q; % dofs in the domain 84 | geom.h = geom.L/(geom.N1+1); % grid size 85 | 86 | geom = assemble_fmesh(geom); 87 | 88 | meshin = geom.pin; 89 | 90 | end -------------------------------------------------------------------------------- /Aux_tools/tools2matlab/generate_mesh.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | q = 8; 5 | nl = 2; 6 | T = []; 7 | J = []; 8 | 9 | % geom: (only square geometry available now) 10 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 11 | geom.q = q; 12 | geom.nl = nl; 13 | geom.dim = 2; % dimension of the problem 14 | geom.m = 2^geom.dim; % 15 | geom.N1 = 2^q; % dofs in one dimension, uniformly sampling 2^q points in range (a, b), not including edges 16 | geom.N = (geom.m)^geom.q; % dofs in the domain 17 | geom.xstart = 0; 18 | geom.xend = 1; 19 | geom.ystart = 0; 20 | geom.yend = 1; 21 | 22 | 23 | geom = assemble_fmesh(geom); 24 | 25 | meshXY = geom.pin; % the point pair for interior of square of [a,b]X[c,d], not including edges 26 | 27 | if q == 3 28 | save('meshXY3', 'meshXY'); 29 | elseif q == 4 30 | save('meshXY4', 'meshXY'); 31 | elseif q == 5 32 | save('meshXY5', 'meshXY'); 33 | elseif q == 6 34 | save('meshXY6', 'meshXY'); 35 | elseif q == 7 36 | save('meshXY7', 'meshXY'); 37 | elseif q == 8 38 | save('meshXY8', 'meshXY'); 39 | elseif num2interior_mesh == 9 40 | save('meshXY9', 'meshXY'); 41 | end -------------------------------------------------------------------------------- /Aux_tools/tools2matlab/plot_fun.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_fun(geom, u) 9 | ftsz = 14; 10 | % require u to be a row vector 11 | if size(u, 2) == 1 12 | u=u'; 13 | end 14 | 15 | if length(u)==length(geom.p) % if u defined also on boundary 16 | 17 | elseif length(u)==sum(geom.in) % if u only defined on interior dofs 18 | u = u(geom.ind); 19 | u0 = zeros(length(geom.p), 1); 20 | u0(geom.in) = u; 21 | u = reshape(u0, size(geom.X))'; 22 | else 23 | error('dof of u does not match dof of mesh') 24 | return 25 | end 26 | 27 | mesh_u = u; 28 | 29 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 30 | axis tight; 31 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 32 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 33 | h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 34 | % colorbar; 35 | % caxis([0 0.5]) 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | end -------------------------------------------------------------------------------- /Aux_tools/tools2matlab/plot_fun2in.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_fun2in(geom, u) 9 | meshX = geom.X; 10 | meshY = geom.Y; 11 | 12 | meshX_in = meshX(2:end-1, 2:end-1); 13 | meshY_in = meshY(2:end-1, 2:end-1); 14 | 15 | ftsz = 14; 16 | % require u to be a row vector 17 | if size(u, 2) == 1 18 | u=u'; 19 | end 20 | 21 | if length(u)==sum(geom.in) % if u only defined on interior dofs 22 | u0 = u(geom.ind); 23 | u = reshape(u0, size(meshX_in))'; 24 | else 25 | error('dof of u does not match dof of mesh') 26 | return 27 | end 28 | 29 | mesh_u = u; 30 | 31 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 32 | axis tight; 33 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 34 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 35 | 36 | h = surf(meshX_in, meshY_in, u,'Edgecolor', 'none'); 37 | % colorbar; 38 | % caxis([0 0.5]) 39 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 40 | set(gcf, 'Renderer', 'zbuffer'); 41 | end -------------------------------------------------------------------------------- /Aux_tools/tools2matlab/plot_pointError.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_pointError(geom, u) 9 | ftsz = 14; 10 | % require u to be a row vector 11 | if size(u, 2) == 1 12 | u=u'; 13 | end 14 | 15 | if length(u)==length(geom.p) % if u defined also on boundary 16 | 17 | elseif length(u)==sum(geom.in) % if u only defined on interior dofs 18 | u = u(geom.ind); 19 | u0 = zeros(length(geom.p), 1); 20 | u0(geom.in) = u; 21 | u = reshape(u0, size(geom.X))'; 22 | else 23 | error('dof of u does not match dof of mesh') 24 | return 25 | end 26 | 27 | mesh_u = u; 28 | 29 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 30 | axis tight; 31 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 32 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 33 | h = surf(geom.X, geom.Y, u); 34 | colorbar; 35 | caxis([0 5e-3]) 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | end -------------------------------------------------------------------------------- /Aux_tools/tools2matlab/plot_solu_perr.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all 3 | close all 4 | 5 | q = 7; 6 | nl = 2; 7 | T = []; 8 | J = []; 9 | 10 | % geom: (only square geometry available now) 11 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 12 | geom.q = q; 13 | geom.nl = nl; 14 | geom.L = 2; % side length 15 | geom.dim = 2; % dimension of the problem 16 | geom.m = 2^geom.dim; % 17 | geom.N1 = 2^q; % dofs in one dimension 18 | geom.N = (geom.m)^geom.q; % dofs in the domain 19 | geom.h = geom.L/(geom.N1+1); % grid size 20 | geom.xstart = 0; 21 | geom.xend = 1; 22 | geom.ystart = 0; 23 | geom.yend = 1; 24 | 25 | geom = assemble_fmesh(geom); 26 | 27 | 28 | solu2exact = load('Utrue'); 29 | solu2numerical = load('Unumeri'); 30 | Solu_UTrue = solu2exact.UTRUE; 31 | Solu_UDNN = solu2numerical.UNUMERI; 32 | figure('name','Exact_Solu') 33 | mesh_solu2u = plot_fun2in(geom,Solu_UTrue); 34 | hold on 35 | 36 | figure('name','DNN_Solu') 37 | mesh_solu_unn = plot_fun2in(geom,Solu_UDNN); 38 | hold on 39 | 40 | err2solu = abs(Solu_UTrue-Solu_UDNN); 41 | figure('name','Err2solu') 42 | mesh_solu_err2u = plot_fun2in(geom,err2solu); 43 | title('Absolute Error') 44 | hold on 45 | colorbar; 46 | caxis([0 1e-13]) 47 | hold on 48 | 49 | 50 | -------------------------------------------------------------------------------- /Aux_tools/tools2matlab/quadtreeind.m: -------------------------------------------------------------------------------- 1 | function ind = quadtreeind(q) 2 | % construct quadtree index 3 | m = 4; 4 | 5 | M = [1 2; 3 4]; 6 | 7 | for k = 2:q 8 | M = [M M+m^(k-1); M+2*m^(k-1) M+3*m^(k-1)]; 9 | end 10 | 11 | ind = M(:)'; 12 | 13 | end -------------------------------------------------------------------------------- /Experiments/BiCELM_Navier/Bi_CELM_2DNavier.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import platform 4 | import shutil 5 | 6 | import torch 7 | import numpy as np 8 | torch.set_default_dtype(torch.float64) 9 | import time 10 | import datetime 11 | from scipy.linalg import lstsq 12 | import matplotlib.pyplot as plt 13 | from Networks import ELM_Base 14 | from utilizers import DNN_tools 15 | from utilizers import plot_data 16 | from utilizers import saveData 17 | from utilizers import dataUtilizer2numpy 18 | from utilizers import Load_data2Mat 19 | from utilizers import RFN_Log_Print 20 | from Problems import General_Laplace 21 | from Problems import Biharmonic_eqs 22 | 23 | 24 | # Global random feature network 25 | class GELM(object): 26 | def __init__(self, indim=1, outdim=1, num2hidden=None, name2Model='PIELM', actName2hidden='tanh', actName2Deri='tanh', 27 | actName2DDeri='tanh', type2float='float32', opt2init_W='xavier_normal', opt2init_B='xavier_uniform', 28 | W_sigma=1.0, B_sigma=1.0): 29 | super(GELM, self).__init__() 30 | 31 | self.indim = indim 32 | self.outdim = outdim 33 | self.num2hidden = num2hidden 34 | self.name2Model = name2Model 35 | self.actName2hidden = actName2hidden 36 | self.actName2derivative = actName2Deri 37 | self.actName2DDeri = actName2DDeri 38 | 39 | if type2float == 'float32': 40 | self.float_type = np.float32 41 | elif type2float == 'float64': 42 | self.float_type = np.float64 43 | elif type2float == 'float16': 44 | self.float_type = np.float16 45 | 46 | # The ELM solver for solving PDEs 47 | if str.upper(name2Model) == 'PIELM': 48 | self.ELM2U = ELM_Base.PIELM( 49 | dim2in=indim, dim2out=1, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 50 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 51 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 52 | self.ELM2V = ELM_Base.PIELM( 53 | dim2in=indim, dim2out=1, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 54 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 55 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 56 | else: 57 | self.ELM2U = ELM_Base.FourierFeaturePIELM( 58 | dim2in=indim, dim2out=1, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 59 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 60 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 61 | self.ELM2V = ELM_Base.FourierFeaturePIELM( 62 | dim2in=indim, dim2out=1, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 63 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 64 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 65 | 66 | def load_meshData(self, path2file=None, mesh_number=2, to_float=True, shuffle_data=True): 67 | test_meshXY_file = path2file + str('meshXY') + str(mesh_number) + str('.mat') 68 | mesh_points = Load_data2Mat.load_Matlab_data(test_meshXY_file) 69 | XY_points = mesh_points['meshXY'] 70 | shape2XY = np.shape(XY_points) 71 | assert (len(shape2XY) == 2) 72 | if shape2XY[0] == 2: 73 | xy_data = np.transpose(XY_points, (1, 0)) 74 | else: 75 | xy_data = XY_points 76 | 77 | if to_float: 78 | xy_data = xy_data.astype(dtype=self.float_type) 79 | if shuffle_data: 80 | np.random.shuffle(xy_data) 81 | return xy_data 82 | 83 | def load_RandPointsData(self, path2file=None, to_float=True, shuffle_data=True): 84 | test_meshXY_file = path2file + str('testXY') + str('.mat') 85 | mesh_points = Load_data2Mat.load_Matlab_data(test_meshXY_file) 86 | XY_points = mesh_points['XY'] 87 | shape2XY = np.shape(XY_points) 88 | assert (len(shape2XY) == 2) 89 | if shape2XY[0] == 2: 90 | xy_data = np.transpose(XY_points, (1, 0)) 91 | else: 92 | xy_data = XY_points 93 | 94 | if to_float: 95 | xy_data = xy_data.astype(dtype=self.float_type) 96 | if shuffle_data: 97 | np.random.shuffle(xy_data) 98 | return xy_data 99 | 100 | # Assembling the matrix A,f in inner domain 101 | def assemble_matrix2inner(self, XY_inner=None, fside=None, if_lambda2fside=True): 102 | shape2XY = XY_inner.shape 103 | lenght2XY_shape = len(shape2XY) 104 | assert (lenght2XY_shape == 2) 105 | assert (shape2XY[-1] == 2) 106 | 107 | A12 = self.ELM2V.assemble_matrix2Laplace_2D(XY_input=XY_inner) 108 | 109 | A21 = self.ELM2U.assemble_matrix2Laplace_2D(XY_input=XY_inner) 110 | 111 | A22 = -1.0 * self.ELM2V.assemble_matrix2interior_2D(XY_input=XY_inner) 112 | 113 | X = np.reshape(XY_inner[:, 0], newshape=[-1, 1]) 114 | Y = np.reshape(XY_inner[:, 1], newshape=[-1, 1]) 115 | 116 | if if_lambda2fside: 117 | f = fside(X, Y) 118 | else: 119 | f = fside 120 | 121 | return (A12, A21, A22, f) 122 | 123 | # Assembling the matrix B,g in boundary domain 124 | def assemble_matrix2boundary(self, XY_bd=None, gside=None, if_lambda2gside=True): 125 | shape2XY = XY_bd.shape 126 | lenght2XY_shape = len(shape2XY) 127 | assert (lenght2XY_shape == 2) 128 | assert (shape2XY[-1] == 2) 129 | 130 | B = self.ELM2U.assemble_matrix2interior_2D(XY_input=XY_bd) 131 | 132 | X = np.reshape(XY_bd[:, 0], newshape=[-1, 1]) 133 | Y = np.reshape(XY_bd[:, 1], newshape=[-1, 1]) 134 | 135 | if if_lambda2gside: 136 | g = gside(X, Y) 137 | else: 138 | g = gside 139 | 140 | return (B, g) 141 | 142 | # Assembling the matrix B,g in boundary domain 143 | def assemble_matrix2_2ndDeriBD(self, XY_bd=None, hside=None, if_lambda2hside=True): 144 | shape2XY = XY_bd.shape 145 | lenght2XY_shape = len(shape2XY) 146 | assert (lenght2XY_shape == 2) 147 | assert (shape2XY[-1] == 2) 148 | 149 | B = self.ELM2V.assemble_matrix2interior_2D(XY_input=XY_bd) 150 | 151 | X = np.reshape(XY_bd[:, 0], newshape=[-1, 1]) 152 | Y = np.reshape(XY_bd[:, 1], newshape=[-1, 1]) 153 | 154 | if if_lambda2hside: 155 | h = hside(X, Y) 156 | else: 157 | h= hside 158 | 159 | return (B, h) 160 | 161 | def test_rfn(self, points=None): 162 | rfn_basis = self.ELM2U.assemble_matrix2interior_2D(XY_input=points) 163 | return rfn_basis 164 | 165 | 166 | def solve_biharmonic(Rdic=None): 167 | log_out_path = Rdic['FolderName'] # 将路径从字典 R 中提取出来 168 | if not os.path.exists(log_out_path): # 判断路径是否已经存在 169 | os.mkdir(log_out_path) # 无 log_out_path 路径,创建一个 log_out_path 路径 170 | logfile_name = '%s%s.txt' % ('log2', Rdic['act_name']) 171 | log_fileout = open(os.path.join(log_out_path, logfile_name), 'w') # 在这个路径下创建并打开一个可写的 log_train.txt文件 172 | RFN_Log_Print.dictionary_out2file(Rdic, log_fileout) 173 | 174 | time_begin = time.time() 175 | 176 | model = GELM(indim=Rdic['input_dim'], outdim=Rdic['out_dim'], num2hidden=Rdic['rfn_hidden'], 177 | name2Model=Rdic['name2model'], actName2hidden=Rdic['act_name'], actName2Deri=Rdic['act_name'], 178 | actName2DDeri=Rdic['act_name'], type2float='float64', opt2init_W=Rdic['opt2initW'], 179 | opt2init_B=Rdic['opt2initB'], W_sigma=Rdic['sigma'], B_sigma=Rdic['sigma']) 180 | 181 | left = 0.0 182 | right = 1.0 183 | if Rdic['Equa_name'] == 'PDE4': 184 | left = -1.0 185 | right = 1.0 186 | # file_path2points = '../data2points/gene_mesh01/' 187 | file_path2points = '../data2points/gene_mesh11/' 188 | points = model.load_meshData(path2file=file_path2points, mesh_number=7, to_float=True, shuffle_data=False) 189 | else: 190 | left = 0.0 191 | right = 1.0 192 | file_path2points = '../data2points/Irregular_domain01/' 193 | # file_path2points = '../data2points/Irregular_domain11/' 194 | points = model.load_RandPointsData(path2file=file_path2points, to_float=True, shuffle_data=True) 195 | shape2points = np.shape(points) 196 | Rdic['point_num2inner'] = shape2points[0] 197 | saveData.save_testData_or_solus2mat(points, dataName='testXY', outPath=FolderName) 198 | 199 | left_bd, right_bd, bottom_bd, top_bd = dataUtilizer2numpy.gene_2Drand_points2bd( 200 | num2point=Rdic['point_num2boundary'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 201 | region_b=left, region_t=right, to_float=True, float_type=np.float64, eps=0.001, opt2rand='random', 202 | shuffle_uniform=True) 203 | 204 | f_side, u_true, u_left, u_right, u_bottom, u_top, ux_left, ux_right, uy_bottom, uy_top, lapU_left, lapU_right, \ 205 | lapU_bottom, lapU_top = Biharmonic_eqs.get_biharmonic_Navier_2D(equa_name=Rdic['Equa_name']) 206 | 207 | A12, A21, A22, f_i = model.assemble_matrix2inner(XY_inner=points, fside=f_side) 208 | 209 | B_l, gl = model.assemble_matrix2boundary(XY_bd=left_bd, gside=u_left) 210 | 211 | B_r, gr = model.assemble_matrix2boundary(XY_bd=right_bd, gside=u_right) 212 | 213 | B_b, gb = model.assemble_matrix2boundary(XY_bd=bottom_bd, gside=u_bottom) 214 | 215 | B_t, gt = model.assemble_matrix2boundary(XY_bd=top_bd, gside=u_top) 216 | 217 | N_l, hl = model.assemble_matrix2_2ndDeriBD(XY_bd=left_bd, hside=lapU_left) 218 | 219 | N_r, hr = model.assemble_matrix2_2ndDeriBD(XY_bd=right_bd, hside=lapU_right) 220 | 221 | N_b, hb = model.assemble_matrix2_2ndDeriBD(XY_bd=bottom_bd, hside=lapU_bottom) 222 | 223 | N_t, ht = model.assemble_matrix2_2ndDeriBD(XY_bd=top_bd, hside=lapU_top) 224 | 225 | num2inner = Rdic['point_num2inner'] 226 | num2boundary = Rdic['point_num2boundary'] 227 | rfn_hidden = Rdic['rfn_hidden'] 228 | 229 | A = np.zeros([2*num2inner + 8 * num2boundary, 2*rfn_hidden]) 230 | F = np.zeros([2*num2inner + 8 * num2boundary, 1]) 231 | 232 | A[0:num2inner, rfn_hidden: 2*rfn_hidden] = A12 233 | A[num2inner: 2*num2inner, 0: rfn_hidden] = A21 234 | A[num2inner: 2 * num2inner, rfn_hidden: 2*rfn_hidden] = A22 235 | 236 | A[2*num2inner:2*num2inner+num2boundary, 0: rfn_hidden] = B_l 237 | A[2*num2inner + num2boundary:2*num2inner+2*num2boundary, 0: rfn_hidden] = B_r 238 | A[2*num2inner + 2*num2boundary:2*num2inner+3*num2boundary, 0: rfn_hidden] = B_b 239 | A[2*num2inner + 3*num2boundary:2*num2inner+4*num2boundary, 0: rfn_hidden] = B_t 240 | 241 | A[2*num2inner + 4 * num2boundary:2*num2inner + 5 * num2boundary, rfn_hidden: 2*rfn_hidden] = N_l 242 | A[2*num2inner + 5 * num2boundary:2*num2inner + 6 * num2boundary, rfn_hidden: 2*rfn_hidden] = N_r 243 | A[2*num2inner + 6 * num2boundary:2*num2inner + 7 * num2boundary, rfn_hidden: 2*rfn_hidden] = N_b 244 | A[2*num2inner + 7 * num2boundary:2*num2inner + 8 * num2boundary, rfn_hidden: 2*rfn_hidden] = N_t 245 | 246 | F[0:num2inner, :] = f_i 247 | 248 | F[2*num2inner:2*num2inner + num2boundary, :] = gl 249 | F[2*num2inner + num2boundary:2*num2inner + 2 * num2boundary, :] = gr 250 | F[2*num2inner + 2 * num2boundary:2*num2inner + 3 * num2boundary, :] = gb 251 | F[2*num2inner + 3 * num2boundary:2*num2inner + 4 * num2boundary, :] = gt 252 | 253 | F[2*num2inner + 4 * num2boundary:2*num2inner + 5 * num2boundary, :] = hl 254 | F[2*num2inner + 5 * num2boundary:2*num2inner + 6 * num2boundary, :] = hr 255 | F[2*num2inner + 6 * num2boundary:2*num2inner + 7 * num2boundary, :] = hb 256 | F[2*num2inner + 7 * num2boundary:2*num2inner + 8 * num2boundary, :] = ht 257 | 258 | # # rescaling 259 | c = 100.0 260 | 261 | for i in range(len(A)): 262 | ratio = c / A[i, :].max() 263 | A[i, :] = A[i, :] * ratio 264 | F[i] = F[i] * ratio 265 | # solve 266 | w = lstsq(A, F)[0] 267 | 268 | temp = model.test_rfn(points=points) 269 | numeri_solu = np.matmul(temp, np.reshape(w[0: rfn_hidden, :], newshape=[-1, 1])) 270 | 271 | time_end = time.time() 272 | run_time = time_end - time_begin 273 | 274 | exact_solu = u_true(np.reshape(points[:, 0], newshape=[-1, 1]), np.reshape(points[:, 1], newshape=[-1, 1])) 275 | 276 | abs_diff = np.abs(exact_solu - numeri_solu) 277 | 278 | max_diff = np.max(abs_diff) 279 | 280 | print('max_diff:', max_diff) 281 | 282 | rel_err = np.sqrt(np.sum(np.square(exact_solu - numeri_solu), axis=0)/np.sum(np.square(exact_solu), axis=0)) 283 | 284 | print('relative error:', rel_err[0]) 285 | 286 | print('running time:', run_time) 287 | 288 | DNN_tools.log_string('The max absolute error: %.18f\n' % max_diff, log_fileout) 289 | DNN_tools.log_string('The relative error: %.18f\n' % rel_err[0], log_fileout) 290 | DNN_tools.log_string('The running time: %.18f s\n' % run_time, log_fileout) 291 | 292 | plot_data.plot_scatter_solu(abs_diff, points, color='m', actName='diff', outPath=FolderName) 293 | plot_data.plot_scatter_solu(exact_solu, points, color='r', actName='exact', outPath=FolderName) 294 | plot_data.plot_scatter_solu(numeri_solu, points, color='b', actName='numerical', outPath=FolderName) 295 | 296 | saveData.save_testData_or_solus2mat(exact_solu, dataName='true', outPath=FolderName) 297 | saveData.save_testData_or_solus2mat(numeri_solu, dataName='numeri', outPath=FolderName) 298 | saveData.save_testData_or_solus2mat(abs_diff, dataName='perr', outPath=FolderName) 299 | 300 | saveData.save_run_time2mat(run_time=run_time, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 301 | saveData.save_max_rel2mat(max_err=max_diff, rel_err=rel_err, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 302 | 303 | 304 | if __name__ == "__main__": 305 | R = {} 306 | # 文件保存路径设置 307 | file2results = 'Results' 308 | store_file = 'Bi2Navier2D_CRFN' 309 | BASE_DIR2FILE = os.path.dirname(os.path.abspath(__file__)) 310 | split_BASE_DIR2FILE = os.path.split(BASE_DIR2FILE) 311 | split_BASE_DIR2FILE = os.path.split(split_BASE_DIR2FILE[0]) 312 | BASE_DIR = split_BASE_DIR2FILE[0] 313 | sys.path.append(BASE_DIR) 314 | OUT_DIR_BASE = os.path.join(BASE_DIR, file2results) 315 | OUT_DIR = os.path.join(OUT_DIR_BASE, store_file) 316 | sys.path.append(OUT_DIR) 317 | if not os.path.exists(OUT_DIR): 318 | print('---------------------- OUT_DIR ---------------------:', OUT_DIR) 319 | os.mkdir(OUT_DIR) 320 | 321 | current_day_time = datetime.datetime.now() # 获取当前时间 322 | date_time_dir = str(current_day_time.month) + str('m_') + \ 323 | str(current_day_time.day) + str('d_') + str(current_day_time.hour) + str('h_') + \ 324 | str(current_day_time.minute) + str('m_') + str(current_day_time.second) + str('s') 325 | FolderName = os.path.join(OUT_DIR, date_time_dir) # 路径连接 326 | if not os.path.exists(FolderName): 327 | print('--------------------- FolderName -----------------:', FolderName) 328 | os.mkdir(FolderName) 329 | 330 | R['FolderName'] = FolderName 331 | 332 | # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 复制并保存当前文件 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 333 | if platform.system() == 'Windows': 334 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 335 | else: 336 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 337 | 338 | R['PDE_type'] = 'Biharmonic_ELM' 339 | R['Equa_name'] = 'PDE4' 340 | # R['Equa_name'] = 'PDE5' 341 | 342 | # R['point_num2inner'] = 20000 343 | R['point_num2inner'] = 16384 344 | R['point_num2boundary'] = 2000 345 | 346 | R['name2model'] = 'PIELM' 347 | # R['name2model'] = 'FF_PIELM' 348 | 349 | # R['rfn_hidden'] = 50 350 | # R['rfn_hidden'] = 100 351 | # R['rfn_hidden'] = 250 352 | # R['rfn_hidden'] = 500 353 | # R['rfn_hidden'] = 750 354 | R['rfn_hidden'] = 1000 355 | # R['rfn_hidden'] = 1250 356 | # R['rfn_hidden'] = 1500 357 | # R['rfn_hidden'] = 1750 358 | # R['rfn_hidden'] = 2000 359 | # R['rfn_hidden'] = 2250 360 | # R['rfn_hidden'] = 2500 361 | 362 | R['input_dim'] = 2 363 | R['out_dim'] = 1 364 | 365 | # R['sigma'] = 0.5 366 | # R['sigma'] = 1.0 367 | # R['sigma'] = 2.0 368 | # R['sigma'] = 4.0 369 | # R['sigma'] = 6.0 370 | R['sigma'] = 8.0 371 | # R['sigma'] = 10.0 372 | # R['sigma'] = 12.0 373 | # R['sigma'] = 14.0 374 | # R['sigma'] = 16.0 375 | # R['sigma'] = 18.0 376 | # R['sigma'] = 20.0 377 | 378 | if R['name2model'] == 'FF_PIELM': 379 | R['act_name'] = 'fourier' 380 | else: 381 | # R['act_name'] = 'tanh' 382 | # R['act_name'] = 'enh_tanh' 383 | R['act_name'] = 'sin' 384 | # R['act_name'] = 'gauss' 385 | # R['act_name'] = 'sinAddcos' 386 | 387 | # R['opt2initW'] = 'normal' 388 | # R['opt2initW'] = 'uniform11' 389 | R['opt2initW'] = 'scale_uniform11' 390 | 391 | # R['opt2initB'] = 'normal' 392 | # R['opt2initB'] = 'uniform11' 393 | R['opt2initB'] = 'scale_uniform11' 394 | 395 | solve_biharmonic(Rdic=R) -------------------------------------------------------------------------------- /Experiments/Possion/Possion1D.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import platform 4 | import shutil 5 | 6 | import torch 7 | import numpy as np 8 | torch.set_default_dtype(torch.float64) 9 | import time 10 | import datetime 11 | from scipy.linalg import lstsq 12 | import matplotlib.pyplot as plt 13 | from Networks import ELM_Base 14 | from utilizers import DNN_tools 15 | from utilizers import plot_data 16 | from utilizers import saveData 17 | from utilizers import RFN_Log_Print 18 | from Problems import General_Laplace 19 | from utilizers import dataUtilizer2numpy 20 | 21 | 22 | # Global random feature network 23 | class GELM2Possion(object): 24 | def __init__(self, indim=1, outdim=1, num2hidden=None, name2Model='DNN', actName2hidden='tanh', actName2Deri='tanh', 25 | actName2DDeri='tanh', type2float='float32', opt2init_W='xavier_normal', opt2init_B='xavier_uniform', 26 | W_sigma=1.0, B_sigma=1.0, freq=None, repeatHighFreq=False): 27 | super(GELM2Possion, self).__init__() 28 | 29 | self.indim = indim 30 | self.outdim = outdim 31 | self.num2hidden = num2hidden 32 | self.name2Model = name2Model 33 | self.actName2hidden = actName2hidden 34 | self.actName2derivative = actName2Deri 35 | self.actName2DDeri = actName2DDeri 36 | self.act_func2hidden = ELM_Base.my_actFunc(actName=actName2hidden) 37 | self.act_func2Deri = ELM_Base.ActFunc2Derivate(actName=actName2Deri) 38 | self.act_func2DDeri = ELM_Base.ActFunc2DDerivate(actName=actName2DDeri) 39 | 40 | if str.upper(name2Model) == 'PIELM': 41 | self.ELM_Bases = ELM_Base.PIELM( 42 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 43 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 44 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 45 | elif str.upper(name2Model) == 'MULTI_SCALE_FOURIER_ELM': 46 | self.ELM_Bases = ELM_Base.MultiscaleFourierPIELM( 47 | dim2in=indim, dim2out=1, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 48 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, scale=freq, 49 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma, 50 | repeat_Highfreq=repeatHighFreq) 51 | elif str.upper(name2Model) == 'MULTI_4FF_ELM': 52 | self.ELM_Bases = ELM_Base.Multi4FF_PIELM( 53 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 54 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 55 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma_W1=1.0, sigma_W2=5.0, sigma_W3=10.0, 56 | sigma_W4=15.0, sigma_B1=1.0, sigma_B2=5.0, sigma_B3=10.0, sigma_B4=15.0) 57 | else: 58 | self.ELM_Bases = ELM_Base.FourierFeaturePIELM( 59 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 60 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 61 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 62 | 63 | if type2float == 'float32': 64 | self.float_type = np.float32 65 | elif type2float == 'float64': 66 | self.float_type = np.float64 67 | elif type2float == 'float16': 68 | self.float_type = np.float16 69 | 70 | # Assembling the matrix A,f in inner domain 71 | def assemble_matrix2inner(self, X_inner=None, fside=None, if_lambda2fside=True): 72 | A = self.ELM_Bases.assemble_matrix2Laplace_1D(X_input=X_inner) 73 | 74 | shape2XY = X_inner.shape 75 | lenght2XY_shape = len(shape2XY) 76 | assert (lenght2XY_shape == 2) 77 | assert (shape2XY[-1] == 1) 78 | 79 | if if_lambda2fside: 80 | f = fside(X_inner) 81 | else: 82 | f = fside 83 | 84 | return (A, f) 85 | 86 | # Assembling the matrix B,g in boundary domain 87 | def assemble_matrix2boundary(self, X_bd=None, gside=None, if_lambda2gside=True): 88 | B = self.ELM_Bases.assemble_matrix2boundary_1D(X_input=X_bd) 89 | shape2XY = X_bd.shape 90 | lenght2XY_shape = len(shape2XY) 91 | assert (lenght2XY_shape == 2) 92 | assert (shape2XY[-1] == 1) 93 | 94 | if if_lambda2gside: 95 | g = gside(X_bd) 96 | else: 97 | g = gside 98 | 99 | return (B, g) 100 | 101 | def test_rfn(self, points=None): 102 | ELM_Bases = self.ELM_Bases.assemble_matrix2interior_1D(X_input=points) 103 | return ELM_Bases 104 | 105 | 106 | def solve_possion(Rdic=None): 107 | log_out_path = Rdic['FolderName'] # 将路径从字典 R 中提取出来 108 | if not os.path.exists(log_out_path): # 判断路径是否已经存在 109 | os.mkdir(log_out_path) # 无 log_out_path 路径,创建一个 log_out_path 路径 110 | logfile_name = '%s.txt' % ('log') 111 | log_fileout = open(os.path.join(log_out_path, logfile_name), 'w') # 在这个路径下创建并打开一个可写的 log_train.txt文件 112 | RFN_Log_Print.dictionary_out2file(Rdic, log_fileout) 113 | 114 | time_begin = time.time() 115 | 116 | left = 0.0 117 | right = 1.0 118 | 119 | Model = GELM2Possion(indim=Rdic['input_dim'], outdim=Rdic['out_dim'], num2hidden=Rdic['rfn_hidden'], 120 | name2Model=Rdic['name2model'], actName2hidden=Rdic['act_name'], actName2Deri=Rdic['act_name'], 121 | actName2DDeri=Rdic['act_name'], type2float='float64', opt2init_W=Rdic['opt2initW'], 122 | opt2init_B=Rdic['opt2initB'], W_sigma=Rdic['sigma'], B_sigma=Rdic['sigma'], freq=Rdic['freq'], 123 | repeatHighFreq=True) 124 | 125 | type2float = np.float64 126 | # points = dataUtilizer2numpy.gene_1Drand_points2inner(num2point=Rdic['point_num2inner'], 127 | # variable_dim=Rdic['input_dim'], 128 | # region_l=left, region_r=right, to_float=True, 129 | # float_type=type2float, opt2rand='random') 130 | 131 | points = dataUtilizer2numpy.gene_1Dmesh_points2inner(num2point=Rdic['point_num2inner'], 132 | variable_dim=Rdic['input_dim'], 133 | region_l=left, region_r=right, to_float=True, 134 | float_type=type2float) 135 | 136 | left_bd, right_bd = dataUtilizer2numpy.gene_1Dinterval2bd( 137 | num2point=Rdic['point_num2boundary'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 138 | to_float=True, float_type=type2float) 139 | 140 | f_side, u_true, ux_left, ux_right = General_Laplace.get_infos2Laplace_1D(equa_name=Rdic['Equa_name']) 141 | 142 | A_I, f_i = Model.assemble_matrix2inner(X_inner=points, fside=f_side) 143 | 144 | B_l, gl = Model.assemble_matrix2boundary(X_bd=left_bd, gside=ux_left) 145 | 146 | B_r, gr = Model.assemble_matrix2boundary(X_bd=right_bd, gside=ux_right) 147 | 148 | num2inner = Rdic['point_num2inner'] 149 | num2boundary = Rdic['point_num2boundary'] 150 | rfn_hidden = Rdic['rfn_hidden'] 151 | 152 | if str.upper(Rdic['name2model']) == 'MULTI_4FF_ELM': 153 | A = np.zeros([num2inner + 2 * num2boundary, 4*rfn_hidden]) 154 | else: 155 | A = np.zeros([num2inner + 2 * num2boundary, rfn_hidden]) 156 | F = np.zeros([num2inner + 2 * num2boundary, 1]) 157 | 158 | A[0:num2inner, :] = A_I 159 | 160 | A[num2inner:num2inner+num2boundary, :] = B_l 161 | A[num2inner+num2boundary:num2inner + 2 * num2boundary, :] = B_r 162 | 163 | F[0:num2inner, :] = f_i 164 | 165 | F[num2inner:num2inner + num2boundary, :] = gl 166 | F[num2inner + num2boundary:num2inner + 2 * num2boundary, :] = gr 167 | 168 | # # rescaling 169 | c = 100.0 170 | 171 | for i in range(len(A)): 172 | ratio = c / A[i, :].max() 173 | A[i, :] = A[i, :] * ratio 174 | F[i] = F[i] * ratio 175 | # solve 176 | w = lstsq(A, F)[0] 177 | 178 | temp = Model.test_rfn(points=points) 179 | numeri_solu = np.matmul(temp, w) 180 | 181 | time_end = time.time() 182 | run_time = time_end - time_begin 183 | 184 | exact_solu = u_true(points) 185 | 186 | abs_diff = np.abs(exact_solu - numeri_solu) 187 | 188 | max_diff = np.max(abs_diff) 189 | 190 | print('max_diff:', max_diff) 191 | 192 | rel_err = np.sqrt(np.sum(np.square(exact_solu - numeri_solu), axis=0) / np.sum(np.square(exact_solu), axis=0)) 193 | 194 | print('relative error:', rel_err[0]) 195 | 196 | print('running time:', run_time) 197 | 198 | DNN_tools.log_string('The max absolute error: %.18f\n' % max_diff, log_fileout) 199 | DNN_tools.log_string('The relative error: %.18f\n' % rel_err[0], log_fileout) 200 | DNN_tools.log_string('The running time: %.18f s\n' % run_time, log_fileout) 201 | 202 | plot_data.plot_solu_1D(solu=abs_diff, coords=points, color='m', actName='diff', outPath=FolderName) 203 | plot_data.plot_solu_1D(solu=exact_solu, coords=points, color='r', actName='exact', outPath=FolderName) 204 | plot_data.plot_solu_1D(solu=numeri_solu, coords=points, color='b', actName='numerical', outPath=FolderName) 205 | 206 | saveData.save_testData_or_solus2mat(exact_solu, dataName='true', outPath=FolderName) 207 | saveData.save_testData_or_solus2mat(numeri_solu, dataName='numeri', outPath=FolderName) 208 | saveData.save_testData_or_solus2mat(abs_diff, dataName='perr', outPath=FolderName) 209 | 210 | saveData.save_run_time2mat(run_time=run_time, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 211 | saveData.save_max_rel2mat(max_err=max_diff, rel_err=rel_err, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 212 | 213 | 214 | if __name__ == "__main__": 215 | R = {} 216 | # 文件保存路径设置 217 | file2results = 'Results' 218 | store_file = 'Laplace1D' 219 | BASE_DIR2FILE = os.path.dirname(os.path.abspath(__file__)) 220 | split_BASE_DIR2FILE = os.path.split(BASE_DIR2FILE) 221 | split_BASE_DIR2FILE = os.path.split(split_BASE_DIR2FILE[0]) 222 | BASE_DIR = split_BASE_DIR2FILE[0] 223 | sys.path.append(BASE_DIR) 224 | OUT_DIR_BASE = os.path.join(BASE_DIR, file2results) 225 | OUT_DIR = os.path.join(OUT_DIR_BASE, store_file) 226 | sys.path.append(OUT_DIR) 227 | if not os.path.exists(OUT_DIR): 228 | print('---------------------- OUT_DIR ---------------------:', OUT_DIR) 229 | os.mkdir(OUT_DIR) 230 | 231 | current_day_time = datetime.datetime.now() # 获取当前时间 232 | date_time_dir = str(current_day_time.month) + str('m_') + \ 233 | str(current_day_time.day) + str('d_') + str(current_day_time.hour) + str('h_') + \ 234 | str(current_day_time.minute) + str('m_') + str(current_day_time.second) + str('s') 235 | FolderName = os.path.join(OUT_DIR, date_time_dir) # 路径连接 236 | if not os.path.exists(FolderName): 237 | print('--------------------- FolderName -----------------:', FolderName) 238 | os.mkdir(FolderName) 239 | 240 | R['FolderName'] = FolderName 241 | 242 | # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 复制并保存当前文件 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 243 | if platform.system() == 'Windows': 244 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 245 | else: 246 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 247 | 248 | R['PDE_type'] = 'Laplace' 249 | # R['Equa_name'] = 'PDE1' 250 | # R['Equa_name'] = 'PDE2' 251 | R['Equa_name'] = 'PDE3' 252 | 253 | R['point_num2inner'] = 2000 254 | R['point_num2boundary'] = 5 255 | R['rfn_hidden'] = 200 256 | R['input_dim'] = 1 257 | R['out_dim'] = 1 258 | 259 | # R['name2model'] = 'PIELM' 260 | # R['name2model'] = 'FF_PIELM' 261 | # R['name2model'] = 'Multi_4FF_ELM' 262 | R['name2model'] = 'MULTI_SCALE_FOURIER_ELM' 263 | 264 | if R['name2model'] == 'Multi_4FF_ELM': 265 | R['rfn_hidden'] = 100 266 | # R['rfn_hidden'] = 250 267 | # R['rfn_hidden'] = 300 268 | # R['rfn_hidden'] = 500 269 | 270 | # R['sigma'] = 6 271 | # R['sigma'] = 8 272 | # R['sigma'] = 10 273 | # R['sigma'] = 20 274 | # R['sigma'] = 30 275 | # R['sigma'] = 40 276 | # R['sigma'] = 50 277 | # R['sigma'] = 60 278 | R['sigma'] = 70 279 | 280 | R['freq'] = np.concatenate(([1], np.arange(1, 50 - 1)), axis=0) 281 | 282 | if R['name2model'] == 'Multi_4FF_ELM' or R['name2model'] == 'FF_PIELM': 283 | R['act_name'] = 'fourier' 284 | elif R['name2model'] == 'MULTI_SCALE_FOURIER_ELM': 285 | R['act_name'] = 'fourier' 286 | 287 | R['opt2initW'] = 'uniform11' 288 | # R['opt2initW'] = 'xavier_normal' 289 | 290 | R['opt2initB'] = 'uniform11' 291 | else: 292 | # R['act_name'] = 'tanh' 293 | R['act_name'] = 'sin' 294 | # R['act_name'] = 'gauss' 295 | # R['act_name'] = 'sinAddcos' 296 | 297 | # R['opt2initW'] = 'normal' 298 | # R['opt2initW'] = 'uniform11' 299 | R['opt2initW'] = 'scale_uniform11' 300 | 301 | # R['opt2initB'] = 'normal' 302 | # R['opt2initB'] = 'uniform11' 303 | R['opt2initB'] = 'scale_uniform11' 304 | solve_possion(Rdic=R) -------------------------------------------------------------------------------- /Experiments/Possion/Possion2D.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import platform 4 | import shutil 5 | 6 | import torch 7 | import numpy as np 8 | 9 | torch.set_default_dtype(torch.float64) 10 | import time 11 | import datetime 12 | from scipy.linalg import lstsq 13 | import matplotlib.pyplot as plt 14 | from Networks import ELM_Base 15 | from utilizers import DNN_tools 16 | from utilizers import plot_data 17 | from utilizers import saveData 18 | from utilizers import RFN_Log_Print 19 | from utilizers import dataUtilizer2numpy 20 | from Problems import General_Laplace 21 | 22 | 23 | # Global random feature network 24 | class GELM2Poisson(object): 25 | def __init__(self, indim=1, outdim=1, num2hidden=None, name2Model='DNN', actName2hidden='tanh', actName2Deri='tanh', 26 | actName2DDeri='tanh', type2float='float32', opt2init_W='xavier_normal', opt2init_B='xavier_uniform', 27 | W_sigma=1.0, B_sigma=1.0, freq=None, repeatHighFreq=False): 28 | super(GELM2Poisson, self).__init__() 29 | 30 | self.indim = indim 31 | self.outdim = outdim 32 | self.num2hidden = num2hidden 33 | self.name2Model = name2Model 34 | self.actName2hidden = actName2hidden 35 | self.actName2derivative = actName2Deri 36 | self.actName2DDeri = actName2DDeri 37 | 38 | # The ELM solver for solving PDEs 39 | if str.upper(name2Model) == 'PIELM': 40 | self.ELM_Bases = ELM_Base.PIELM( 41 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 42 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 43 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 44 | elif str.upper(name2Model) == 'MULTI_SCALE_FOURIER_ELM': 45 | self.ELM_Bases = ELM_Base.MultiscaleFourierPIELM( 46 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 47 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, scale=freq, 48 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma, 49 | repeat_Highfreq=repeatHighFreq) 50 | elif str.upper(name2Model) == 'MULTI_4FF_ELM': 51 | self.ELM_Bases = ELM_Base.Multi4FF_PIELM( 52 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 53 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 54 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma_W1=1.0, sigma_W2=5.0, sigma_W3=10.0, 55 | sigma_W4=15.0, sigma_B1=1.0, sigma_B2=5.0, sigma_B3=10.0, sigma_B4=15.0) 56 | else: 57 | self.ELM_Bases = ELM_Base.FourierFeaturePIELM( 58 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 59 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 60 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 61 | 62 | if type2float == 'float32': 63 | self.float_type = np.float32 64 | elif type2float == 'float64': 65 | self.float_type = np.float64 66 | elif type2float == 'float16': 67 | self.float_type = np.float16 68 | 69 | # Assembling the matrix A,f in inner domain 70 | def assemble_matrix2inner(self, XY_inner=None, fside=None, if_lambda2fside=True): 71 | shape2XY = XY_inner.shape 72 | lenght2XY_shape = len(shape2XY) 73 | assert (lenght2XY_shape == 2) 74 | assert (shape2XY[-1] == 2) 75 | 76 | A = self.ELM_Bases.assemble_matrix2Laplace_2D(XY_input=XY_inner) 77 | 78 | X = np.reshape(XY_inner[:, 0], newshape=[-1, 1]) 79 | Y = np.reshape(XY_inner[:, 1], newshape=[-1, 1]) 80 | 81 | if if_lambda2fside: 82 | f = fside(X, Y) 83 | else: 84 | f = fside 85 | 86 | return (A, f) 87 | 88 | # Assembling the matrix B,g in boundary domain 89 | def assemble_matrix2boundary(self, XY_boundary=None, gside=None, if_lambda2gside=True): 90 | shape2XY = XY_boundary.shape 91 | lenght2XY_shape = len(shape2XY) 92 | assert (lenght2XY_shape == 2) 93 | assert (shape2XY[-1] == 2) 94 | 95 | B = self.ELM_Bases.assemble_matrix2boundary_2D(XY_input=XY_boundary) 96 | 97 | X = np.reshape(XY_boundary[:, 0], newshape=[-1, 1]) 98 | Y = np.reshape(XY_boundary[:, 1], newshape=[-1, 1]) 99 | 100 | if if_lambda2gside: 101 | g = gside(X, Y) 102 | else: 103 | g = gside 104 | 105 | return (B, g) 106 | 107 | def test_model(self, points=None): 108 | ELM_Bases = self.ELM_Bases.assemble_matrix2interior_2D(XY_input=points) 109 | return ELM_Bases 110 | 111 | 112 | def solve_possion(Rdic=None): 113 | log_out_path = Rdic['FolderName'] # 将路径从字典 R 中提取出来 114 | if not os.path.exists(log_out_path): # 判断路径是否已经存在 115 | os.mkdir(log_out_path) # 无 log_out_path 路径,创建一个 log_out_path 路径 116 | logfile_name = '%s.txt' % ('log') 117 | log_fileout = open(os.path.join(log_out_path, logfile_name), 'w') # 在这个路径下创建并打开一个可写的 log_train.txt文件 118 | RFN_Log_Print.dictionary_out2file(Rdic, log_fileout) 119 | 120 | time_begin = time.time() 121 | 122 | left = 0.0 123 | right = 1.0 124 | 125 | if Rdic['Equa_name'] == 'PDE2': 126 | right = 1.0 127 | elif Rdic['Equa_name'] == 'PDE3': 128 | right = 1.0 129 | elif Rdic['Equa_name'] == 'PDE4': 130 | right = 1.0 131 | Model = GELM2Poisson( 132 | indim=Rdic['input_dim'], outdim=Rdic['out_dim'], num2hidden=Rdic['rfn_hidden'], name2Model=Rdic['name2model'], 133 | actName2hidden=Rdic['act_name'], actName2Deri=Rdic['act_name'], actName2DDeri=Rdic['act_name'], 134 | type2float='float64', opt2init_W=Rdic['opt2initW'], opt2init_B=Rdic['opt2initB'], W_sigma=Rdic['sigma'], 135 | B_sigma=Rdic['sigma']) 136 | 137 | type2float = np.float64 138 | # points = dataUtilizer2numpy.gene_2Drand_points2inner( 139 | # num2point=Rdic['point_num2inner'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 140 | # region_b=left, region_t=right, to_float=True, float_type=type2float, opt2rand='uniform', shuffle_point=True) 141 | 142 | if Rdic['model2generate_data'] == 'load_porous_data': 143 | points = dataUtilizer2numpy.load_data2porous_domain( 144 | region_left=left, region_right=right, region_bottom=left, region_top=right, float_type=type2float) 145 | saveData.save_testData_or_solus2mat(points, 'testxy', Rdic['FolderName']) 146 | else: 147 | points, mesh = dataUtilizer2numpy.gene_mesh_gene_rand_2Dinner( 148 | num2mesh=50, num2point=Rdic['point_num2inner'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 149 | region_b=left, region_t=right, to_float=True, float_type=type2float, opt2rand='uniform', shuffle_point=True) 150 | saveData.save_testData_or_solus2mat(mesh, 'testxy', Rdic['FolderName']) 151 | 152 | left_bd, right_bd, bottom_bd, top_bd = dataUtilizer2numpy.gene_2Drand_points2bd( 153 | num2point=Rdic['point_num2boundary'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 154 | region_b=left, region_t=right, to_float=True, float_type=type2float, opt2rand='random', shuffle_uniform=True) 155 | 156 | f_side, u_true, ux_left, ux_right, uy_bottom, uy_top = General_Laplace.get_Laplace2D_infos(equa_name=Rdic['Equa_name']) 157 | 158 | A_I, f_i = Model.assemble_matrix2inner(XY_inner=points, fside=f_side, if_lambda2fside=True) 159 | 160 | B_l, gl = Model.assemble_matrix2boundary(XY_boundary=left_bd, gside=ux_left) 161 | 162 | B_r, gr = Model.assemble_matrix2boundary(XY_boundary=right_bd, gside=ux_right) 163 | 164 | B_b, gb = Model.assemble_matrix2boundary(XY_boundary=bottom_bd, gside=uy_bottom) 165 | 166 | B_t, gt = Model.assemble_matrix2boundary(XY_boundary=top_bd, gside=uy_top) 167 | 168 | # num2inner = Rdic['point_num2inner'] 169 | num2inner = points.shape[0] 170 | num2boundary = Rdic['point_num2boundary'] 171 | rfn_hidden = Rdic['rfn_hidden'] 172 | 173 | if str.upper(Rdic['name2model']) == 'MULTI_4FF_ELM': 174 | A = np.zeros([num2inner + 4 * num2boundary, 4 * rfn_hidden]) 175 | else: 176 | A = np.zeros([num2inner + 4 * num2boundary, rfn_hidden]) 177 | 178 | F = np.zeros([num2inner + 4 * num2boundary, 1]) 179 | 180 | A[0:num2inner, :] = A_I 181 | 182 | A[num2inner:num2inner + num2boundary, :] = B_l 183 | A[num2inner + num2boundary:num2inner + 2 * num2boundary, :] = B_r 184 | A[num2inner + 2 * num2boundary:num2inner + 3 * num2boundary, :] = B_b 185 | A[num2inner + 3 * num2boundary:num2inner + 4 * num2boundary, :] = B_t 186 | 187 | F[0:num2inner, :] = f_i 188 | 189 | F[num2inner:num2inner + num2boundary, :] = gl 190 | F[num2inner + num2boundary:num2inner + 2 * num2boundary, :] = gr 191 | F[num2inner + 2 * num2boundary:num2inner + 3 * num2boundary, :] = gb 192 | F[num2inner + 3 * num2boundary:num2inner + 4 * num2boundary, :] = gt 193 | 194 | # # rescaling 195 | c = 100.0 196 | 197 | for i in range(len(A)): 198 | ratio = c / A[i, :].max() 199 | A[i, :] = A[i, :] * ratio 200 | F[i] = F[i] * ratio 201 | # solve 202 | w = lstsq(A, F)[0] 203 | 204 | if Rdic['model2generate_data'] == 'load_porous_data': 205 | temp = Model.test_model(points=points) 206 | else: 207 | temp = Model.test_model(points=mesh) 208 | numeri_solu = np.matmul(temp, w) 209 | 210 | time_end = time.time() 211 | run_time = time_end - time_begin 212 | 213 | if Rdic['model2generate_data'] == 'load_porous_data': 214 | exact_solu = u_true(np.reshape(points[:, 0], newshape=[-1, 1]), np.reshape(points[:, 1], newshape=[-1, 1])) 215 | else: 216 | exact_solu = u_true(np.reshape(mesh[:, 0], newshape=[-1, 1]), np.reshape(mesh[:, 1], newshape=[-1, 1])) 217 | 218 | abs_diff = np.abs(exact_solu - numeri_solu) 219 | 220 | max_diff = np.max(abs_diff) 221 | 222 | print('max_diff:', max_diff) 223 | 224 | rel_err = np.sqrt(np.sum(np.square(exact_solu - numeri_solu), axis=0) / np.sum(np.square(exact_solu), axis=0)) 225 | 226 | print('relative error:', rel_err[0]) 227 | 228 | print('running time:', run_time) 229 | 230 | DNN_tools.log_string('The max absolute error: %.18f\n' % max_diff, log_fileout) 231 | DNN_tools.log_string('The relative error: %.18f\n' % rel_err[0], log_fileout) 232 | DNN_tools.log_string('The running time: %.18f s\n' % run_time, log_fileout) 233 | 234 | if Rdic['model2generate_data'] == 'load_porous_data': 235 | plot_data.plot_scatter_solu(abs_diff, points, color='m', actName='diff', outPath=FolderName) 236 | plot_data.plot_scatter_solu(exact_solu, points, color='r', actName='exact', outPath=FolderName) 237 | plot_data.plot_scatter_solu(numeri_solu, points, color='b', actName='numerical', outPath=FolderName) 238 | else: 239 | plot_data.plot_scatter_solu(abs_diff, mesh, color='m', actName='diff', outPath=FolderName) 240 | plot_data.plot_scatter_solu(exact_solu, mesh, color='r', actName='exact', outPath=FolderName) 241 | plot_data.plot_scatter_solu(numeri_solu, mesh, color='b', actName='numerical', outPath=FolderName) 242 | 243 | saveData.save_testData_or_solus2mat(exact_solu, dataName='true', outPath=FolderName) 244 | saveData.save_testData_or_solus2mat(numeri_solu, dataName='numeri', outPath=FolderName) 245 | saveData.save_testData_or_solus2mat(abs_diff, dataName='perr', outPath=FolderName) 246 | 247 | saveData.save_run_time2mat(run_time=run_time, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 248 | saveData.save_max_rel2mat(max_err=max_diff, rel_err=rel_err, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 249 | 250 | 251 | if __name__ == "__main__": 252 | R = {} 253 | # 文件保存路径设置 254 | file2results = 'Results' 255 | store_file = 'Laplace2D' 256 | BASE_DIR2FILE = os.path.dirname(os.path.abspath(__file__)) 257 | split_BASE_DIR2FILE = os.path.split(BASE_DIR2FILE) 258 | split_BASE_DIR2FILE = os.path.split(split_BASE_DIR2FILE[0]) 259 | BASE_DIR = split_BASE_DIR2FILE[0] 260 | sys.path.append(BASE_DIR) 261 | OUT_DIR_BASE = os.path.join(BASE_DIR, file2results) 262 | OUT_DIR = os.path.join(OUT_DIR_BASE, store_file) 263 | sys.path.append(OUT_DIR) 264 | if not os.path.exists(OUT_DIR): 265 | print('---------------------- OUT_DIR ---------------------:', OUT_DIR) 266 | os.mkdir(OUT_DIR) 267 | 268 | current_day_time = datetime.datetime.now() # 获取当前时间 269 | date_time_dir = str(current_day_time.month) + str('m_') + \ 270 | str(current_day_time.day) + str('d_') + str(current_day_time.hour) + str('h_') + \ 271 | str(current_day_time.minute) + str('m_') + str(current_day_time.second) + str('s') 272 | FolderName = os.path.join(OUT_DIR, date_time_dir) # 路径连接 273 | if not os.path.exists(FolderName): 274 | print('--------------------- FolderName -----------------:', FolderName) 275 | os.mkdir(FolderName) 276 | 277 | R['FolderName'] = FolderName 278 | 279 | # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 复制并保存当前文件 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 280 | if platform.system() == 'Windows': 281 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 282 | else: 283 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 284 | 285 | R['model2generate_data'] = 'load_porous_data' 286 | # R['model2generate_data'] = 'generate_mesh_data' 287 | 288 | R['PDE_type'] = 'Laplace' 289 | # R['Equa_name'] = 'PDE1' 290 | R['Equa_name'] = 'PDE2' 291 | # R['Equa_name'] = 'PDE3' 292 | # R['Equa_name'] = 'PDE4' 293 | 294 | R['point_num2inner'] = 5000 295 | R['point_num2boundary'] = 15 296 | R['rfn_hidden'] = 1000 297 | R['input_dim'] = 2 298 | R['out_dim'] = 1 299 | 300 | # R['name2model'] = 'PIELM' 301 | R['name2model'] = 'FF_PIELM' 302 | # R['name2model'] = 'Multi_4FF_ELM' 303 | 304 | if R['name2model'] == 'Multi_4FF_ELM': 305 | # R['rfn_hidden'] = 200 306 | R['rfn_hidden'] = 250 307 | # R['rfn_hidden'] = 300 308 | # R['rfn_hidden'] = 500 309 | 310 | # R['sigma'] = 0.25 311 | # R['sigma'] = 0.5 312 | # R['sigma'] = 0.75 313 | # R['sigma'] = 1.0 314 | # R['sigma'] = 1.5 315 | # R['sigma'] = 2.0 316 | # R['sigma'] = 2.5 317 | # R['sigma'] = 3.0 318 | # R['sigma'] = 6 319 | # R['sigma'] = 8 320 | # R['sigma'] = 10 321 | # R['sigma'] = 15 322 | # R['sigma'] = 20 323 | # R['sigma'] = 25 324 | # R['sigma'] = 30 325 | R['sigma'] = 35 326 | 327 | if R['name2model'] == 'Multi_4FF_ELM' or R['name2model'] == 'FF_PIELM': 328 | R['act_name'] = 'fourier' 329 | else: 330 | # R['act_name'] = 'tanh' 331 | R['act_name'] = 'sin' 332 | # R['act_name'] = 'gauss' 333 | # R['act_name'] = 'sinAddcos' 334 | 335 | # R['opt2initW'] = 'normal' 336 | R['opt2initW'] = 'scale_uniform11' 337 | 338 | # R['opt2initB'] = 'normal' 339 | # R['opt2initB'] = 'uniform11' 340 | R['opt2initB'] = 'scale_uniform11' 341 | solve_possion(Rdic=R) 342 | -------------------------------------------------------------------------------- /Experiments/Possion/Possion3D.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import platform 4 | import shutil 5 | 6 | import torch 7 | import numpy as np 8 | 9 | torch.set_default_dtype(torch.float64) 10 | import time 11 | import datetime 12 | from scipy.linalg import lstsq 13 | import matplotlib.pyplot as plt 14 | from Networks import ELM_Base 15 | from utilizers import DNN_tools 16 | from utilizers import plot_data 17 | from utilizers import saveData 18 | from utilizers import RFN_Log_Print 19 | from utilizers import dataUtilizer2numpy 20 | from Problems import General_Laplace 21 | 22 | 23 | # Global random feature network 24 | class GELM(object): 25 | def __init__(self, indim=1, outdim=1, num2hidden=None, name2Model='DNN', actName2hidden='tanh', actName2Deri='tanh', 26 | actName2DDeri='tanh', type2float='float32', opt2init_W='xavier_normal', opt2init_B='xavier_uniform', 27 | W_sigma=1.0, B_sigma=1.0, freq=None, repeatHighFreq=False): 28 | super(GELM, self).__init__() 29 | 30 | self.indim = indim 31 | self.outdim = outdim 32 | self.num2hidden = num2hidden 33 | self.name2Model = name2Model 34 | self.actName2hidden = actName2hidden 35 | self.actName2derivative = actName2Deri 36 | self.actName2DDeri = actName2DDeri 37 | 38 | # The ELM solver for solving PDEs 39 | if str.upper(name2Model) == 'PIELM': 40 | self.ELM_Bases = ELM_Base.PIELM( 41 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 42 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 43 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 44 | elif str.upper(name2Model) == 'MULTI_SCALE_FOURIER_ELM': 45 | self.ELM_Bases = ELM_Base.MultiscaleFourierPIELM( 46 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 47 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, scale=freq, 48 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma, 49 | repeat_Highfreq=repeatHighFreq) 50 | elif str.upper(name2Model) == 'MULTI_4FF_ELM': 51 | self.ELM_Bases = ELM_Base.Multi4FF_PIELM( 52 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 53 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 54 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma_W1=1.0, sigma_W2=5.0, sigma_W3=10.0, 55 | sigma_W4=15.0, sigma_B1=1.0, sigma_B2=5.0, sigma_B3=10.0, sigma_B4=15.0) 56 | else: 57 | self.ELM_Bases = ELM_Base.FourierFeaturePIELM( 58 | dim2in=indim, dim2out=outdim, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 59 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, 60 | opt2init_hiddenW=opt2init_W, opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 61 | 62 | if type2float == 'float32': 63 | self.float_type = np.float32 64 | elif type2float == 'float64': 65 | self.float_type = np.float64 66 | elif type2float == 'float16': 67 | self.float_type = np.float16 68 | 69 | # Assembling the matrix A,f in inner domain 70 | def assemble_matrix2inner(self, XY_inner=None, fside=None, if_lambda2fside=True): 71 | shape2XY = XY_inner.shape 72 | lenght2XY_shape = len(shape2XY) 73 | assert (lenght2XY_shape == 2) 74 | assert (shape2XY[-1] == 2) 75 | 76 | A = self.ELM_Bases.assemble_matrix2Laplace_3D(XYZ_input=XY_inner) 77 | 78 | X = np.reshape(XY_inner[:, 0], newshape=[-1, 1]) 79 | Y = np.reshape(XY_inner[:, 1], newshape=[-1, 1]) 80 | 81 | if if_lambda2fside: 82 | f = fside(X, Y) 83 | else: 84 | f = fside 85 | 86 | return (A, f) 87 | 88 | # Assembling the matrix B,g in boundary domain 89 | def assemble_matrix2boundary(self, XY_boundary=None, gside=None, if_lambda2gside=True): 90 | shape2XY = XY_boundary.shape 91 | lenght2XY_shape = len(shape2XY) 92 | assert (lenght2XY_shape == 2) 93 | assert (shape2XY[-1] == 2) 94 | 95 | B = self.ELM_Bases.assemble_matrix2boundary_2D(XY_input=XY_boundary) 96 | 97 | X = np.reshape(XY_boundary[:, 0], newshape=[-1, 1]) 98 | Y = np.reshape(XY_boundary[:, 1], newshape=[-1, 1]) 99 | Z = np.reshape(XY_boundary[:, 2], newshape=[-1, 1]) 100 | 101 | if if_lambda2gside: 102 | g = gside(X, Y, Z) 103 | else: 104 | g = gside 105 | 106 | return (B, g) 107 | 108 | def test_model(self, points=None): 109 | ELM_Bases = self.ELM_Bases.assemble_matrix2interior_3D(XYZ_input=points) 110 | return ELM_Bases 111 | 112 | 113 | def solve_possion(Rdic=None): 114 | log_out_path = Rdic['FolderName'] # 将路径从字典 R 中提取出来 115 | if not os.path.exists(log_out_path): # 判断路径是否已经存在 116 | os.mkdir(log_out_path) # 无 log_out_path 路径,创建一个 log_out_path 路径 117 | logfile_name = '%s.txt' % ('log') 118 | log_fileout = open(os.path.join(log_out_path, logfile_name), 'w') # 在这个路径下创建并打开一个可写的 log_train.txt文件 119 | RFN_Log_Print.dictionary_out2file(Rdic, log_fileout) 120 | 121 | time_begin = time.time() 122 | 123 | left = 0.0 124 | right = 2.0 125 | 126 | if R['Equa_name'] == 'PDE2': 127 | right = 5.0 128 | elif R['Equa_name'] == 'PDE3': 129 | right = 1.0 130 | elif R['Equa_name'] == 'PDE4': 131 | right = 1.0 132 | Model = GELM(indim=Rdic['input_dim'], outdim=Rdic['out_dim'], num2hidden=Rdic['rfn_hidden'], name2Model='DNN', 133 | actName2hidden=Rdic['act_name'], actName2Deri=Rdic['act_name'], actName2DDeri=Rdic['act_name'], 134 | type2float='float64', opt2init_W=Rdic['opt2initW'], opt2init_B=Rdic['opt2initB'], 135 | W_sigma=Rdic['sigma'], B_sigma=Rdic['sigma']) 136 | 137 | type2float = np.float64 138 | # points = dataUtilizer2numpy.gene_2Drand_points2inner( 139 | # num2point=Rdic['point_num2inner'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 140 | # region_b=left, region_t=right, to_float=True, float_type=type2float, opt2rand='uniform', shuffle_point=True) 141 | 142 | points, mesh = dataUtilizer2numpy.gene_mesh_gene_rand_2Dinner( 143 | num2mesh=50, num2point=Rdic['point_num2inner'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 144 | region_b=left, region_t=right, to_float=True, float_type=type2float, opt2rand='uniform', shuffle_point=True) 145 | 146 | left_bd, right_bd, bottom_bd, top_bd = dataUtilizer2numpy.gene_2Drand_points2bd( 147 | num2point=Rdic['point_num2boundary'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 148 | region_b=left, region_t=right, to_float=True, float_type=type2float, opt2rand='random', shuffle_uniform=True) 149 | 150 | f_side, u_true, ux_left, ux_right, uy_bottom, uy_top = General_Laplace.get_Laplace2D_infos(equa_name=Rdic['Equa_name']) 151 | 152 | A_I, f_i = Model.assemble_matrix2inner(XY_inner=points, fside=f_side, if_lambda2fside=True) 153 | 154 | B_l, gl = Model.assemble_matrix2boundary(XY_boundary=left_bd, gside=ux_left) 155 | 156 | B_r, gr = Model.assemble_matrix2boundary(XY_boundary=right_bd, gside=ux_right) 157 | 158 | B_b, gb = Model.assemble_matrix2boundary(XY_boundary=bottom_bd, gside=uy_bottom) 159 | 160 | B_t, gt = Model.assemble_matrix2boundary(XY_boundary=top_bd, gside=uy_top) 161 | 162 | # num2inner = Rdic['point_num2inner'] 163 | num2inner = points.shape[0] 164 | num2boundary = Rdic['point_num2boundary'] 165 | rfn_hidden = Rdic['rfn_hidden'] 166 | 167 | A = np.zeros([num2inner + 4 * num2boundary, rfn_hidden]) 168 | F = np.zeros([num2inner + 4 * num2boundary, 1]) 169 | 170 | A[0:num2inner, :] = A_I 171 | 172 | A[num2inner:num2inner + num2boundary, :] = B_l 173 | A[num2inner + num2boundary:num2inner + 2 * num2boundary, :] = B_r 174 | A[num2inner + 2 * num2boundary:num2inner + 3 * num2boundary, :] = B_b 175 | A[num2inner + 3 * num2boundary:num2inner + 4 * num2boundary, :] = B_t 176 | 177 | F[0:num2inner, :] = f_i 178 | 179 | F[num2inner:num2inner + num2boundary, :] = gl 180 | F[num2inner + num2boundary:num2inner + 2 * num2boundary, :] = gr 181 | F[num2inner + 2 * num2boundary:num2inner + 3 * num2boundary, :] = gb 182 | F[num2inner + 3 * num2boundary:num2inner + 4 * num2boundary, :] = gt 183 | 184 | # # rescaling 185 | c = 100.0 186 | 187 | for i in range(len(A)): 188 | ratio = c / A[i, :].max() 189 | A[i, :] = A[i, :] * ratio 190 | F[i] = F[i] * ratio 191 | # solve 192 | w = lstsq(A, F)[0] 193 | 194 | temp = Model.test_model(points=mesh) 195 | numeri_solu = np.matmul(temp, w) 196 | 197 | time_end = time.time() 198 | run_time = time_end - time_begin 199 | 200 | exact_solu = u_true(np.reshape(mesh[:, 0], newshape=[-1, 1]), np.reshape(mesh[:, 1], newshape=[-1, 1])) 201 | 202 | abs_diff = np.abs(exact_solu - numeri_solu) 203 | 204 | max_diff = np.max(abs_diff) 205 | 206 | print('max_diff:', max_diff) 207 | 208 | rel_err = np.sqrt(np.sum(np.square(exact_solu - numeri_solu), axis=0) / np.sum(np.square(exact_solu), axis=0)) 209 | 210 | print('relative error:', rel_err[0]) 211 | 212 | print('running time:', run_time) 213 | 214 | DNN_tools.log_string('The max absolute error: %.18f\n' % max_diff, log_fileout) 215 | DNN_tools.log_string('The relative error: %.18f\n' % rel_err[0], log_fileout) 216 | DNN_tools.log_string('The running time: %.18f s\n' % run_time, log_fileout) 217 | 218 | plot_data.plot_scatter_solu(abs_diff, mesh, color='m', actName='diff', outPath=FolderName) 219 | plot_data.plot_scatter_solu(exact_solu, mesh, color='r', actName='exact', outPath=FolderName) 220 | plot_data.plot_scatter_solu(numeri_solu, mesh, color='b', actName='numerical', outPath=FolderName) 221 | 222 | saveData.save_testData_or_solus2mat(exact_solu, dataName='true', outPath=FolderName) 223 | saveData.save_testData_or_solus2mat(numeri_solu, dataName='numeri', outPath=FolderName) 224 | saveData.save_testData_or_solus2mat(abs_diff, dataName='perr', outPath=FolderName) 225 | 226 | saveData.save_run_time2mat(run_time=run_time, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 227 | saveData.save_max_rel2mat(max_err=max_diff, rel_err=rel_err, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 228 | 229 | 230 | if __name__ == "__main__": 231 | R = {} 232 | # 文件保存路径设置 233 | file2results = 'Results' 234 | store_file = 'Laplace2D' 235 | BASE_DIR2FILE = os.path.dirname(os.path.abspath(__file__)) 236 | split_BASE_DIR2FILE = os.path.split(BASE_DIR2FILE) 237 | split_BASE_DIR2FILE = os.path.split(split_BASE_DIR2FILE[0]) 238 | BASE_DIR = split_BASE_DIR2FILE[0] 239 | sys.path.append(BASE_DIR) 240 | OUT_DIR_BASE = os.path.join(BASE_DIR, file2results) 241 | OUT_DIR = os.path.join(OUT_DIR_BASE, store_file) 242 | sys.path.append(OUT_DIR) 243 | if not os.path.exists(OUT_DIR): 244 | print('---------------------- OUT_DIR ---------------------:', OUT_DIR) 245 | os.mkdir(OUT_DIR) 246 | 247 | current_day_time = datetime.datetime.now() # 获取当前时间 248 | date_time_dir = str(current_day_time.month) + str('m_') + \ 249 | str(current_day_time.day) + str('d_') + str(current_day_time.hour) + str('h_') + \ 250 | str(current_day_time.minute) + str('m_') + str(current_day_time.second) + str('s') 251 | FolderName = os.path.join(OUT_DIR, date_time_dir) # 路径连接 252 | if not os.path.exists(FolderName): 253 | print('--------------------- FolderName -----------------:', FolderName) 254 | os.mkdir(FolderName) 255 | 256 | R['FolderName'] = FolderName 257 | 258 | # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 复制并保存当前文件 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 259 | if platform.system() == 'Windows': 260 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 261 | else: 262 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 263 | 264 | R['PDE_type'] = 'Laplace' 265 | R['Equa_name'] = 'PDE1' 266 | # R['Equa_name'] = 'PDE2' 267 | # R['Equa_name'] = 'PDE3' 268 | # R['Equa_name'] = 'PDE4' 269 | 270 | R['point_num2inner'] = 10000 271 | R['point_num2boundary'] = 1000 272 | R['rfn_hidden'] = 1000 273 | R['input_dim'] = 2 274 | R['out_dim'] = 1 275 | 276 | R['sigma'] = 20 277 | 278 | # R['act_name'] = 'tanh' 279 | # R['act_name'] = 'sin' 280 | # R['act_name'] = 'gauss' 281 | # R['act_name'] = 'sinAddcos' 282 | 283 | R['act_name'] = 'fourier' 284 | 285 | # R['opt2initW'] = 'normal' 286 | R['opt2initW'] = 'scale_uniform11' 287 | 288 | # R['opt2initB'] = 'normal' 289 | # R['opt2initB'] = 'uniform11' 290 | R['opt2initB'] = 'scale_uniform11' 291 | solve_possion(Rdic=R) -------------------------------------------------------------------------------- /Experiments/data2Biharmonic3D/TestXYZ.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2Biharmonic3D/TestXYZ.mat -------------------------------------------------------------------------------- /Experiments/data2Biharmonic3D/TrainXYZ.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2Biharmonic3D/TrainXYZ.mat -------------------------------------------------------------------------------- /Experiments/data2Biharmonic3D/TrainXYZbd1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2Biharmonic3D/TrainXYZbd1.mat -------------------------------------------------------------------------------- /Experiments/data2Biharmonic3D/TrainXYZbd2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2Biharmonic3D/TrainXYZbd2.mat -------------------------------------------------------------------------------- /Experiments/data2points/Irregular_domain01/liujiaoxing_domain2D.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/Irregular_domain01/liujiaoxing_domain2D.asv -------------------------------------------------------------------------------- /Experiments/data2points/Irregular_domain01/liujiaoxing_domain2D.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/Irregular_domain01/liujiaoxing_domain2D.m -------------------------------------------------------------------------------- /Experiments/data2points/Irregular_domain01/testXY.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/Irregular_domain01/testXY.mat -------------------------------------------------------------------------------- /Experiments/data2points/Irregular_domain01/test_point.m: -------------------------------------------------------------------------------- 1 | clear all 2 | clc 3 | close all 4 | 5 | point = load('testXY.mat'); 6 | 7 | XY = point.XY; 8 | X = XY(1,:); 9 | Y = XY(2,:); 10 | Z = sin(pi*X).*sin(pi*Y); 11 | plot3(X,Y,Z,'b.') -------------------------------------------------------------------------------- /Experiments/data2points/Irregular_domain11/liujiaoxing_domain2D.asv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/Irregular_domain11/liujiaoxing_domain2D.asv -------------------------------------------------------------------------------- /Experiments/data2points/Irregular_domain11/liujiaoxing_domain2D.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/Irregular_domain11/liujiaoxing_domain2D.m -------------------------------------------------------------------------------- /Experiments/data2points/Irregular_domain11/testXY.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/Irregular_domain11/testXY.mat -------------------------------------------------------------------------------- /Experiments/data2points/Irregular_domain11/test_point.m: -------------------------------------------------------------------------------- 1 | clear all 2 | clc 3 | close all 4 | 5 | point = load('testXY.mat'); 6 | 7 | XY = point.XY; 8 | X = XY(1,:); 9 | Y = XY(2,:); 10 | Z = sin(pi*X).*sin(pi*Y); 11 | plot3(X,Y,Z,'b.') -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/create3D_data.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/create3D_data.m -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/create4D_data.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/create4D_data.m -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/create5D_data.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/create5D_data.m -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/create_2Dmesh.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/create_2Dmesh.m -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/load_recover_solu.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | q = 6; 5 | N = 2^q+1; 6 | if q==4 7 | data2mesh = load('meshXY4'); 8 | data2solu = load('utrue4'); 9 | elseif q==5 10 | data2mesh = load('meshXY5'); 11 | data2solu = load('utrue5'); 12 | elseif q==6 13 | data2mesh = load('meshXY6'); 14 | data2solu = load('utrue6'); 15 | elseif q==7 16 | data2mesh = load('meshXY7'); 17 | data2solu = load('utrue7'); 18 | end 19 | 20 | xpoints = -1:2/N:1; 21 | ypoints = -1:2/N:1; 22 | [meshX, meshY] = meshgrid(xpoints, ypoints); 23 | solu1 = data2solu.utrue; 24 | 25 | scatter_u = reshape(solu1, [N+1, N+1]); 26 | figure('name', 'scatter_solu') 27 | surf(meshX, meshY, scatter_u) 28 | hold on 29 | 30 | 31 | solu = recover_solu(solu1, N+1); 32 | u = reshape(solu, [N+1, N+1]); 33 | figure('name', 'recover_solu') 34 | surf(meshX, meshY, u) 35 | hold on 36 | -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/recover_index.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/recover_index.m -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/recover_solu.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/recover_solu.m -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/reorder_index.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/reorder_index.m -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/testXY.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/testXY.mat -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/testXYZ.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/testXYZ.mat -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/testXYZS.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/testXYZS.mat -------------------------------------------------------------------------------- /Experiments/data2points/create_mesh/testXYZST.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/create_mesh/testXYZST.mat -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh01/assemble_fmesh.m: -------------------------------------------------------------------------------- 1 | function geom = assemble_fmesh(geom) 2 | %ASSEMBLE_FMESH generate fine mesh for [-1, 1] x [-1, 1] 3 | % this requires the side length geom.L = (geom.N1+1)*geom.h 4 | 5 | if nargin == 0 6 | test_assemble_fmesh; 7 | return 8 | end 9 | 10 | hx = (geom.xend - geom.xstart)/(geom.N1+1); 11 | hy = (geom.yend - geom.ystart)/(geom.N1+1); 12 | xline = geom.xstart:hx: geom.xend; 13 | yline = geom.ystart:hy:geom.yend; 14 | [x, y] = meshgrid(geom.xstart:hx:geom.xend, geom.ystart:hy:geom.yend); 15 | geom.X = x; 16 | geom.Y = y; 17 | 18 | x = x'; x = x(:)'; 19 | y = y'; y = y(:)'; 20 | 21 | p = [x; y]; 22 | 23 | % create the element matrix t for square elements 24 | N = geom.N1 + 1; 25 | t = zeros(4, N^2); 26 | nb = speye(N^2, N^2); 27 | for i = 1:N 28 | for j = 1:N 29 | ind = i + N*(j-1); 30 | t(:, ind) = [ 31 | (j-1)*(N+1)+i; 32 | (j-1)*(N+1)+i+1; 33 | j*(N+1)+i; 34 | j*(N+1)+i+1; 35 | ]; 36 | % pt is the center of elements t 37 | pt(:, ind) = sum(p(:, t(:, ind)), 2)/4; 38 | end 39 | end 40 | 41 | % identify interior dofs and boundary dofs 42 | ib = abs(x)==geom.xstart | abs(x)==geom.xend | abs(y)==geom.ystart | abs(y)==geom.yend; 43 | in = not(ib); 44 | pin = p(:, in); 45 | 46 | % [ind, ~, ~, adjmatrix, ~, ~] = quadtree(pin(1, :), pin(2, :), [], 1); 47 | % ind is the index of regions 48 | % bx, by denotes the order in x and y direction respectively 49 | % nb is the adjacency matrix of regions 50 | ind = quadtreeind(geom.q); 51 | 52 | % now reorder the dofs by the regions, this create a natural order 53 | % multiresolution operations by using the base 4 representation of indices 54 | % r1 = pin(1, ind) 55 | % r2 = pin(2, ind) 56 | pin(:, ind) = pin; 57 | nb = sparse(nb); 58 | 59 | geom.p = p; 60 | geom.t = t; 61 | geom.pt = pt; 62 | geom.ib = ib; 63 | geom.in = in; 64 | geom.ind = ind; 65 | geom.pin = pin; 66 | % geom.adjmatrix = adjmatrix; 67 | end 68 | 69 | function test_assemble_fmesh 70 | q = 3; 71 | nl = 2; 72 | T = []; 73 | J = []; 74 | 75 | % geom: (only square geometry available now) 76 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 77 | geom.q = q; 78 | geom.nl = nl; 79 | geom.L = 2; % side length 80 | geom.dim = 2; % dimension of the problem 81 | geom.m = 2^geom.dim; % 82 | geom.N1 = 2^q; % dofs in one dimension 83 | geom.N = (geom.m)^geom.q; % dofs in the domain 84 | geom.h = geom.L/(geom.N1+1); % grid size 85 | 86 | geom = assemble_fmesh(geom); 87 | 88 | meshin = geom.pin; 89 | 90 | end -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh01/generate_mesh.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | q = 6; 5 | % q = 7; 6 | nl = 2; 7 | T = []; 8 | J = []; 9 | 10 | % geom: (only square geometry available now) 11 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 12 | geom.q = q; 13 | geom.nl = nl; 14 | geom.dim = 2; % dimension of the problem 15 | geom.m = 2^geom.dim; % 16 | geom.N1 = 2^q; % dofs in one dimension, uniformly sampling 2^q points in range (a, b), not including edges 17 | geom.N = (geom.m)^geom.q; % dofs in the domain 18 | geom.xstart = 0; 19 | geom.xend = 1; 20 | geom.ystart = 0; 21 | geom.yend = 1; 22 | 23 | 24 | geom = assemble_fmesh(geom); 25 | 26 | meshXY = geom.pin; % the point pair for interior of square of [a,b]X[c,d], not including edges 27 | 28 | if q == 3 29 | save('meshXY3.mat', 'meshXY') 30 | elseif q == 4 31 | save('meshXY4.mat', 'meshXY') 32 | elseif q == 5 33 | save('meshXY5.mat', 'meshXY') 34 | elseif q == 6 35 | save('meshXY6.mat', 'meshXY') 36 | elseif q == 7 37 | save('meshXY7.mat', 'meshXY') 38 | end -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh01/meshXY6.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/gene_mesh01/meshXY6.mat -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh01/meshXY7.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/gene_mesh01/meshXY7.mat -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh01/quadtreeind.m: -------------------------------------------------------------------------------- 1 | function ind = quadtreeind(q) 2 | % construct quadtree index 3 | m = 4; 4 | 5 | M = [1 2; 3 4]; 6 | 7 | for k = 2:q 8 | M = [M M+m^(k-1); M+2*m^(k-1) M+3*m^(k-1)]; 9 | end 10 | 11 | ind = M(:)'; 12 | 13 | end -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh11/assemble_fmesh.m: -------------------------------------------------------------------------------- 1 | function geom = assemble_fmesh(geom) 2 | %ASSEMBLE_FMESH generate fine mesh for [-1, 1] x [-1, 1] 3 | % this requires the side length geom.L = (geom.N1+1)*geom.h 4 | 5 | if nargin == 0 6 | test_assemble_fmesh; 7 | return 8 | end 9 | 10 | hx = (geom.xend - geom.xstart)/(geom.N1+1); 11 | hy = (geom.yend - geom.ystart)/(geom.N1+1); 12 | xline = geom.xstart:hx: geom.xend; 13 | yline = geom.ystart:hy:geom.yend; 14 | [x, y] = meshgrid(geom.xstart:hx:geom.xend, geom.ystart:hy:geom.yend); 15 | geom.X = x; 16 | geom.Y = y; 17 | 18 | x = x'; x = x(:)'; 19 | y = y'; y = y(:)'; 20 | 21 | p = [x; y]; 22 | 23 | % create the element matrix t for square elements 24 | N = geom.N1 + 1; 25 | t = zeros(4, N^2); 26 | nb = speye(N^2, N^2); 27 | for i = 1:N 28 | for j = 1:N 29 | ind = i + N*(j-1); 30 | t(:, ind) = [ 31 | (j-1)*(N+1)+i; 32 | (j-1)*(N+1)+i+1; 33 | j*(N+1)+i; 34 | j*(N+1)+i+1; 35 | ]; 36 | % pt is the center of elements t 37 | pt(:, ind) = sum(p(:, t(:, ind)), 2)/4; 38 | end 39 | end 40 | 41 | % identify interior dofs and boundary dofs 42 | ib = abs(x)==geom.xstart | abs(x)==geom.xend | abs(y)==geom.ystart | abs(y)==geom.yend; 43 | in = not(ib); 44 | pin = p(:, in); 45 | 46 | % [ind, ~, ~, adjmatrix, ~, ~] = quadtree(pin(1, :), pin(2, :), [], 1); 47 | % ind is the index of regions 48 | % bx, by denotes the order in x and y direction respectively 49 | % nb is the adjacency matrix of regions 50 | ind = quadtreeind(geom.q); 51 | 52 | % now reorder the dofs by the regions, this create a natural order 53 | % multiresolution operations by using the base 4 representation of indices 54 | % r1 = pin(1, ind) 55 | % r2 = pin(2, ind) 56 | pin(:, ind) = pin; 57 | nb = sparse(nb); 58 | 59 | geom.p = p; 60 | geom.t = t; 61 | geom.pt = pt; 62 | geom.ib = ib; 63 | geom.in = in; 64 | geom.ind = ind; 65 | geom.pin = pin; 66 | % geom.adjmatrix = adjmatrix; 67 | end 68 | 69 | function test_assemble_fmesh 70 | q = 3; 71 | nl = 2; 72 | T = []; 73 | J = []; 74 | 75 | % geom: (only square geometry available now) 76 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 77 | geom.q = q; 78 | geom.nl = nl; 79 | geom.L = 2; % side length 80 | geom.dim = 2; % dimension of the problem 81 | geom.m = 2^geom.dim; % 82 | geom.N1 = 2^q; % dofs in one dimension 83 | geom.N = (geom.m)^geom.q; % dofs in the domain 84 | geom.h = geom.L/(geom.N1+1); % grid size 85 | 86 | geom = assemble_fmesh(geom); 87 | 88 | meshin = geom.pin; 89 | 90 | end -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh11/generate_mesh.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | % q = 6; 5 | q = 7; 6 | nl = 2; 7 | T = []; 8 | J = []; 9 | 10 | % geom: (only square geometry available now) 11 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 12 | geom.q = q; 13 | geom.nl = nl; 14 | geom.dim = 2; % dimension of the problem 15 | geom.m = 2^geom.dim; % 16 | geom.N1 = 2^q; % dofs in one dimension, uniformly sampling 2^q points in range (a, b), not including edges 17 | geom.N = (geom.m)^geom.q; % dofs in the domain 18 | geom.xstart = -1; 19 | geom.xend = 1; 20 | geom.ystart = -1; 21 | geom.yend = 1; 22 | 23 | 24 | geom = assemble_fmesh(geom); 25 | 26 | meshXY = geom.pin; % the point pair for interior of square of [a,b]X[c,d], not including edges 27 | 28 | if q == 3 29 | save('meshXY3.mat', 'meshXY') 30 | elseif q == 4 31 | save('meshXY4.mat', 'meshXY') 32 | elseif q == 5 33 | save('meshXY5.mat', 'meshXY') 34 | elseif q == 6 35 | save('meshXY6.mat', 'meshXY') 36 | elseif q == 7 37 | save('meshXY7.mat', 'meshXY') 38 | end -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh11/meshXY6.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/gene_mesh11/meshXY6.mat -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh11/meshXY7.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/data2points/gene_mesh11/meshXY7.mat -------------------------------------------------------------------------------- /Experiments/data2points/gene_mesh11/quadtreeind.m: -------------------------------------------------------------------------------- 1 | function ind = quadtreeind(q) 2 | % construct quadtree index 3 | m = 4; 4 | 5 | M = [1 2; 3 4]; 6 | 7 | for k = 2:q 8 | M = [M M+m^(k-1); M+2*m^(k-1) M+3*m^(k-1)]; 9 | end 10 | 11 | ind = M(:)'; 12 | 13 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_X/assemble_fmesh.m: -------------------------------------------------------------------------------- 1 | function geom = assemble_fmesh(geom) 2 | %ASSEMBLE_FMESH generate fine mesh for [-1, 1] x [-1, 1] 3 | % this requires the side length geom.L = (geom.N1+1)*geom.h 4 | 5 | if nargin == 0 6 | test_assemble_fmesh; 7 | return 8 | end 9 | 10 | hx = (geom.xend - geom.xstart)/(geom.N1+1); 11 | hy = (geom.yend - geom.ystart)/(geom.N1+1); 12 | xline = geom.xstart:hx: geom.xend; 13 | yline = geom.ystart:hy:geom.yend; 14 | [x, y] = meshgrid(geom.xstart:hx:geom.xend, geom.ystart:hy:geom.yend); 15 | geom.X = x; 16 | geom.Y = y; 17 | 18 | x = x'; x = x(:)'; 19 | y = y'; y = y(:)'; 20 | 21 | p = [x; y]; 22 | 23 | % create the element matrix t for square elements 24 | N = geom.N1 + 1; 25 | t = zeros(4, N^2); 26 | nb = speye(N^2, N^2); 27 | for i = 1:N 28 | for j = 1:N 29 | ind = i + N*(j-1); 30 | t(:, ind) = [ 31 | (j-1)*(N+1)+i; 32 | (j-1)*(N+1)+i+1; 33 | j*(N+1)+i; 34 | j*(N+1)+i+1; 35 | ]; 36 | % pt is the center of elements t 37 | pt(:, ind) = sum(p(:, t(:, ind)), 2)/4; 38 | end 39 | end 40 | 41 | % identify interior dofs and boundary dofs 42 | ib = abs(x)==geom.xstart | abs(x)==geom.xend | abs(y)==geom.ystart | abs(y)==geom.yend; 43 | in = not(ib); 44 | pin = p(:, in); 45 | 46 | % [ind, ~, ~, adjmatrix, ~, ~] = quadtree(pin(1, :), pin(2, :), [], 1); 47 | % ind is the index of regions 48 | % bx, by denotes the order in x and y direction respectively 49 | % nb is the adjacency matrix of regions 50 | ind = quadtreeind(geom.q); 51 | 52 | % now reorder the dofs by the regions, this create a natural order 53 | % multiresolution operations by using the base 4 representation of indices 54 | % r1 = pin(1, ind) 55 | % r2 = pin(2, ind) 56 | pin(:, ind) = pin; 57 | nb = sparse(nb); 58 | 59 | geom.p = p; 60 | geom.t = t; 61 | geom.pt = pt; 62 | geom.ib = ib; 63 | geom.in = in; 64 | geom.ind = ind; 65 | geom.pin = pin; 66 | % geom.adjmatrix = adjmatrix; 67 | end 68 | 69 | function test_assemble_fmesh 70 | q = 3; 71 | nl = 2; 72 | T = []; 73 | J = []; 74 | 75 | % geom: (only square geometry available now) 76 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 77 | geom.q = q; 78 | geom.nl = nl; 79 | geom.L = 2; % side length 80 | geom.dim = 2; % dimension of the problem 81 | geom.m = 2^geom.dim; % 82 | geom.N1 = 2^q; % dofs in one dimension 83 | geom.N = (geom.m)^geom.q; % dofs in the domain 84 | geom.h = geom.L/(geom.N1+1); % grid size 85 | 86 | geom = assemble_fmesh(geom); 87 | 88 | meshin = geom.pin; 89 | 90 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_X/generate_mesh.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | q = 7; 5 | nl = 2; 6 | T = []; 7 | J = []; 8 | 9 | % geom: (only square geometry available now) 10 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 11 | geom.q = q; 12 | geom.nl = nl; 13 | geom.dim = 2; % dimension of the problem 14 | geom.m = 2^geom.dim; % 15 | geom.N1 = 2^q; % dofs in one dimension, uniformly sampling 2^q points in range (a, b), not including edges 16 | geom.N = (geom.m)^geom.q; % dofs in the domain 17 | geom.xstart = 0; 18 | geom.xend = 1; 19 | geom.ystart = 0; 20 | geom.yend = 1; 21 | 22 | 23 | geom = assemble_fmesh(geom); 24 | 25 | meshXY = geom.pin; % the point pair for interior of square of [a,b]X[c,d], not including edges 26 | X_coords = 0.5*ones(1, geom.N); 27 | % X_coords = 0.25*ones(1, geom.N); 28 | 29 | XYZ = [X_coords; meshXY]; 30 | if q == 7 31 | save('testXYZ7.mat','XYZ') 32 | elseif q == 6 33 | save('testXYZ6.mat','XYZ') 34 | elseif q == 5 35 | save('testXYZ5.mat','XYZ') 36 | end 37 | -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_X/plot_fun.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_fun(geom, u) 9 | ftsz = 14; 10 | % require u to be a row vector 11 | if size(u, 2) == 1 12 | u=u'; 13 | end 14 | 15 | if length(u)==length(geom.p) % if u defined also on boundary 16 | 17 | elseif length(u)==sum(geom.in) % if u only defined on interior dofs 18 | u = u(geom.ind); 19 | u0 = zeros(length(geom.p), 1); 20 | u0(geom.in) = u; 21 | u = reshape(u0, size(geom.X))'; 22 | else 23 | error('dof of u does not match dof of mesh') 24 | return 25 | end 26 | 27 | mesh_u = u; 28 | 29 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 30 | axis tight; 31 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 32 | h = surf(geom.X, geom.Y, u); 33 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 34 | % colorbar; 35 | % caxis([0 0.5]) 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_X/plot_fun2in.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_fun2in(geom, u) 9 | meshX = geom.X; 10 | meshY = geom.Y; 11 | 12 | meshX_in = meshX(2:end-1, 2:end-1); 13 | meshY_in = meshY(2:end-1, 2:end-1); 14 | 15 | ftsz = 14; 16 | % require u to be a row vector 17 | if size(u, 2) == 1 18 | u=u'; 19 | end 20 | 21 | if length(u)==sum(geom.in) % if u only defined on interior dofs 22 | u0 = u(geom.ind); 23 | u = reshape(u0, size(meshX_in))'; 24 | else 25 | error('dof of u does not match dof of mesh') 26 | return 27 | end 28 | 29 | mesh_u = u; 30 | 31 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 32 | axis tight; 33 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 34 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 35 | 36 | h = surf(meshX_in, meshY_in, u,'Edgecolor', 'none'); 37 | % colorbar; 38 | % caxis([0 0.5]) 39 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 40 | set(gcf, 'Renderer', 'zbuffer'); 41 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_X/plot_pointError.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_pointError(geom, u) 9 | ftsz = 14; 10 | % require u to be a row vector 11 | if size(u, 2) == 1 12 | u=u'; 13 | end 14 | 15 | if length(u)==length(geom.p) % if u defined also on boundary 16 | 17 | elseif length(u)==sum(geom.in) % if u only defined on interior dofs 18 | u = u(geom.ind); 19 | u0 = zeros(length(geom.p), 1); 20 | u0(geom.in) = u; 21 | u = reshape(u0, size(geom.X))'; 22 | else 23 | error('dof of u does not match dof of mesh') 24 | return 25 | end 26 | 27 | mesh_u = u; 28 | 29 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 30 | axis tight; 31 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 32 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 33 | h = surf(geom.X, geom.Y, u); 34 | colorbar; 35 | caxis([0 5e-3]) 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_X/plot_solu_perr.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all 3 | close all 4 | meshData = load('meshXY7.mat'); 5 | meshXY = meshData.UMESHXY; 6 | 7 | q = 7; 8 | nl = 2; 9 | T = []; 10 | J = []; 11 | 12 | % geom: (only square geometry available now) 13 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 14 | geom.q = q; 15 | geom.nl = nl; 16 | geom.L = 2; % side length 17 | geom.dim = 2; % dimension of the problem 18 | geom.m = 2^geom.dim; % 19 | geom.N1 = 2^q; % dofs in one dimension 20 | geom.N = (geom.m)^geom.q; % dofs in the domain 21 | geom.h = geom.L/(geom.N1+1); % grid size 22 | geom.xstart = -1; 23 | geom.xend = 1; 24 | geom.ystart = -1; 25 | geom.yend = 1; 26 | 27 | geom = assemble_fmesh(geom); 28 | 29 | 30 | data2solution = load('test_solus.mat'); 31 | Solu_True = data2solution.Utrue; 32 | Solu_DNN = data2solution.Us2relu; 33 | figure('name','Exact_Solu') 34 | mesh_solu_true = plot_fun(geom,Solu_True); 35 | hold on 36 | 37 | figure('name','DNN_Solu') 38 | mesh_solu_dnn = plot_fun(geom,Solu_DNN); 39 | hold on 40 | 41 | err2solu = abs(Solu_True-Solu_DNN); 42 | figure('name','Err2solu') 43 | mesh_solu_err = plot_fun2in(geom,err2solu); 44 | title('Absolute Error') 45 | hold on 46 | colorbar; 47 | caxis([0 0.025]) 48 | hold on 49 | -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_X/quadtreeind.m: -------------------------------------------------------------------------------- 1 | function ind = quadtreeind(q) 2 | % construct quadtree index 3 | m = 4; 4 | 5 | M = [1 2; 3 4]; 6 | 7 | for k = 2:q 8 | M = [M M+m^(k-1); M+2*m^(k-1) M+3*m^(k-1)]; 9 | end 10 | 11 | ind = M(:)'; 12 | 13 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_X/testXYZ7.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/dataMat_highDim/ThreeD2Fixed_X/testXYZ7.mat -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Y/assemble_fmesh.m: -------------------------------------------------------------------------------- 1 | function geom = assemble_fmesh(geom) 2 | %ASSEMBLE_FMESH generate fine mesh for [-1, 1] x [-1, 1] 3 | % this requires the side length geom.L = (geom.N1+1)*geom.h 4 | 5 | if nargin == 0 6 | test_assemble_fmesh; 7 | return 8 | end 9 | 10 | hx = (geom.xend - geom.xstart)/(geom.N1+1); 11 | hy = (geom.yend - geom.ystart)/(geom.N1+1); 12 | xline = geom.xstart:hx: geom.xend; 13 | yline = geom.ystart:hy:geom.yend; 14 | [x, y] = meshgrid(geom.xstart:hx:geom.xend, geom.ystart:hy:geom.yend); 15 | geom.X = x; 16 | geom.Y = y; 17 | 18 | x = x'; x = x(:)'; 19 | y = y'; y = y(:)'; 20 | 21 | p = [x; y]; 22 | 23 | % create the element matrix t for square elements 24 | N = geom.N1 + 1; 25 | t = zeros(4, N^2); 26 | nb = speye(N^2, N^2); 27 | for i = 1:N 28 | for j = 1:N 29 | ind = i + N*(j-1); 30 | t(:, ind) = [ 31 | (j-1)*(N+1)+i; 32 | (j-1)*(N+1)+i+1; 33 | j*(N+1)+i; 34 | j*(N+1)+i+1; 35 | ]; 36 | % pt is the center of elements t 37 | pt(:, ind) = sum(p(:, t(:, ind)), 2)/4; 38 | end 39 | end 40 | 41 | % identify interior dofs and boundary dofs 42 | ib = abs(x)==geom.xstart | abs(x)==geom.xend | abs(y)==geom.ystart | abs(y)==geom.yend; 43 | in = not(ib); 44 | pin = p(:, in); 45 | 46 | % [ind, ~, ~, adjmatrix, ~, ~] = quadtree(pin(1, :), pin(2, :), [], 1); 47 | % ind is the index of regions 48 | % bx, by denotes the order in x and y direction respectively 49 | % nb is the adjacency matrix of regions 50 | ind = quadtreeind(geom.q); 51 | 52 | % now reorder the dofs by the regions, this create a natural order 53 | % multiresolution operations by using the base 4 representation of indices 54 | % r1 = pin(1, ind) 55 | % r2 = pin(2, ind) 56 | pin(:, ind) = pin; 57 | nb = sparse(nb); 58 | 59 | geom.p = p; 60 | geom.t = t; 61 | geom.pt = pt; 62 | geom.ib = ib; 63 | geom.in = in; 64 | geom.ind = ind; 65 | geom.pin = pin; 66 | % geom.adjmatrix = adjmatrix; 67 | end 68 | 69 | function test_assemble_fmesh 70 | q = 3; 71 | nl = 2; 72 | T = []; 73 | J = []; 74 | 75 | % geom: (only square geometry available now) 76 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 77 | geom.q = q; 78 | geom.nl = nl; 79 | geom.L = 2; % side length 80 | geom.dim = 2; % dimension of the problem 81 | geom.m = 2^geom.dim; % 82 | geom.N1 = 2^q; % dofs in one dimension 83 | geom.N = (geom.m)^geom.q; % dofs in the domain 84 | geom.h = geom.L/(geom.N1+1); % grid size 85 | 86 | geom = assemble_fmesh(geom); 87 | 88 | meshin = geom.pin; 89 | 90 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Y/generate_mesh.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | q = 7; 5 | nl = 2; 6 | T = []; 7 | J = []; 8 | 9 | % geom: (only square geometry available now) 10 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 11 | geom.q = q; 12 | geom.nl = nl; 13 | geom.dim = 2; % dimension of the problem 14 | geom.m = 2^geom.dim; % 15 | geom.N1 = 2^q; % dofs in one dimension, uniformly sampling 2^q points in range (a, b), not including edges 16 | geom.N = (geom.m)^geom.q; % dofs in the domain 17 | geom.xstart = 0; 18 | geom.xend = 1; 19 | geom.ystart = 0; 20 | geom.yend = 1; 21 | 22 | 23 | geom = assemble_fmesh(geom); 24 | 25 | meshXY = geom.pin; % the point pair for interior of square of [a,b]X[c,d], not including edges 26 | Y_coords = 0.5*ones(1, geom.N); 27 | 28 | XYZ = [meshXY(1,:);Y_coords; meshXY(2,:)]; 29 | save('testXYZ.mat','XYZ') -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Y/plot_fun.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_fun(geom, u) 9 | ftsz = 14; 10 | % require u to be a row vector 11 | if size(u, 2) == 1 12 | u=u'; 13 | end 14 | 15 | if length(u)==length(geom.p) % if u defined also on boundary 16 | 17 | elseif length(u)==sum(geom.in) % if u only defined on interior dofs 18 | u = u(geom.ind); 19 | u0 = zeros(length(geom.p), 1); 20 | u0(geom.in) = u; 21 | u = reshape(u0, size(geom.X))'; 22 | else 23 | error('dof of u does not match dof of mesh') 24 | return 25 | end 26 | 27 | mesh_u = u; 28 | 29 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 30 | axis tight; 31 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 32 | h = surf(geom.X, geom.Y, u); 33 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 34 | % colorbar; 35 | % caxis([0 0.5]) 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Y/plot_fun2in.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_fun2in(geom, u) 9 | meshX = geom.X; 10 | meshY = geom.Y; 11 | 12 | meshX_in = meshX(2:end-1, 2:end-1); 13 | meshY_in = meshY(2:end-1, 2:end-1); 14 | 15 | ftsz = 14; 16 | % require u to be a row vector 17 | if size(u, 2) == 1 18 | u=u'; 19 | end 20 | 21 | if length(u)==sum(geom.in) % if u only defined on interior dofs 22 | u0 = u(geom.ind); 23 | u = reshape(u0, size(meshX_in))'; 24 | else 25 | error('dof of u does not match dof of mesh') 26 | return 27 | end 28 | 29 | mesh_u = u; 30 | 31 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 32 | axis tight; 33 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 34 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 35 | 36 | h = surf(meshX_in, meshY_in, u,'Edgecolor', 'none'); 37 | % colorbar; 38 | % caxis([0 0.5]) 39 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 40 | set(gcf, 'Renderer', 'zbuffer'); 41 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Y/plot_pointError.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_pointError(geom, u) 9 | ftsz = 14; 10 | % require u to be a row vector 11 | if size(u, 2) == 1 12 | u=u'; 13 | end 14 | 15 | if length(u)==length(geom.p) % if u defined also on boundary 16 | 17 | elseif length(u)==sum(geom.in) % if u only defined on interior dofs 18 | u = u(geom.ind); 19 | u0 = zeros(length(geom.p), 1); 20 | u0(geom.in) = u; 21 | u = reshape(u0, size(geom.X))'; 22 | else 23 | error('dof of u does not match dof of mesh') 24 | return 25 | end 26 | 27 | mesh_u = u; 28 | 29 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 30 | axis tight; 31 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 32 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 33 | h = surf(geom.X, geom.Y, u); 34 | colorbar; 35 | caxis([0 5e-3]) 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Y/plot_solu_perr.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all 3 | close all 4 | meshData = load('meshXY7.mat'); 5 | meshXY = meshData.UMESHXY; 6 | 7 | q = 7; 8 | nl = 2; 9 | T = []; 10 | J = []; 11 | 12 | % geom: (only square geometry available now) 13 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 14 | geom.q = q; 15 | geom.nl = nl; 16 | geom.L = 2; % side length 17 | geom.dim = 2; % dimension of the problem 18 | geom.m = 2^geom.dim; % 19 | geom.N1 = 2^q; % dofs in one dimension 20 | geom.N = (geom.m)^geom.q; % dofs in the domain 21 | geom.h = geom.L/(geom.N1+1); % grid size 22 | geom.xstart = -1; 23 | geom.xend = 1; 24 | geom.ystart = -1; 25 | geom.yend = 1; 26 | 27 | geom = assemble_fmesh(geom); 28 | 29 | 30 | data2solution = load('test_solus.mat'); 31 | Solu_True = data2solution.Utrue; 32 | Solu_DNN = data2solution.Us2relu; 33 | figure('name','Exact_Solu') 34 | mesh_solu_true = plot_fun(geom,Solu_True); 35 | hold on 36 | 37 | figure('name','DNN_Solu') 38 | mesh_solu_dnn = plot_fun(geom,Solu_DNN); 39 | hold on 40 | 41 | err2solu = abs(Solu_True-Solu_DNN); 42 | figure('name','Err2solu') 43 | mesh_solu_err = plot_fun2in(geom,err2solu); 44 | title('Absolute Error') 45 | hold on 46 | colorbar; 47 | caxis([0 0.025]) 48 | hold on 49 | -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Y/quadtreeind.m: -------------------------------------------------------------------------------- 1 | function ind = quadtreeind(q) 2 | % construct quadtree index 3 | m = 4; 4 | 5 | M = [1 2; 3 4]; 6 | 7 | for k = 2:q 8 | M = [M M+m^(k-1); M+2*m^(k-1) M+3*m^(k-1)]; 9 | end 10 | 11 | ind = M(:)'; 12 | 13 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Y/testXYZ.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/dataMat_highDim/ThreeD2Fixed_Y/testXYZ.mat -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Z/assemble_fmesh.m: -------------------------------------------------------------------------------- 1 | function geom = assemble_fmesh(geom) 2 | %ASSEMBLE_FMESH generate fine mesh for [-1, 1] x [-1, 1] 3 | % this requires the side length geom.L = (geom.N1+1)*geom.h 4 | 5 | if nargin == 0 6 | test_assemble_fmesh; 7 | return 8 | end 9 | 10 | hx = (geom.xend - geom.xstart)/(geom.N1+1); 11 | hy = (geom.yend - geom.ystart)/(geom.N1+1); 12 | xline = geom.xstart:hx: geom.xend; 13 | yline = geom.ystart:hy:geom.yend; 14 | [x, y] = meshgrid(geom.xstart:hx:geom.xend, geom.ystart:hy:geom.yend); 15 | geom.X = x; 16 | geom.Y = y; 17 | 18 | x = x'; x = x(:)'; 19 | y = y'; y = y(:)'; 20 | 21 | p = [x; y]; 22 | 23 | % create the element matrix t for square elements 24 | N = geom.N1 + 1; 25 | t = zeros(4, N^2); 26 | nb = speye(N^2, N^2); 27 | for i = 1:N 28 | for j = 1:N 29 | ind = i + N*(j-1); 30 | t(:, ind) = [ 31 | (j-1)*(N+1)+i; 32 | (j-1)*(N+1)+i+1; 33 | j*(N+1)+i; 34 | j*(N+1)+i+1; 35 | ]; 36 | % pt is the center of elements t 37 | pt(:, ind) = sum(p(:, t(:, ind)), 2)/4; 38 | end 39 | end 40 | 41 | % identify interior dofs and boundary dofs 42 | ib = abs(x)==geom.xstart | abs(x)==geom.xend | abs(y)==geom.ystart | abs(y)==geom.yend; 43 | in = not(ib); 44 | pin = p(:, in); 45 | 46 | % [ind, ~, ~, adjmatrix, ~, ~] = quadtree(pin(1, :), pin(2, :), [], 1); 47 | % ind is the index of regions 48 | % bx, by denotes the order in x and y direction respectively 49 | % nb is the adjacency matrix of regions 50 | ind = quadtreeind(geom.q); 51 | 52 | % now reorder the dofs by the regions, this create a natural order 53 | % multiresolution operations by using the base 4 representation of indices 54 | % r1 = pin(1, ind) 55 | % r2 = pin(2, ind) 56 | pin(:, ind) = pin; 57 | nb = sparse(nb); 58 | 59 | geom.p = p; 60 | geom.t = t; 61 | geom.pt = pt; 62 | geom.ib = ib; 63 | geom.in = in; 64 | geom.ind = ind; 65 | geom.pin = pin; 66 | % geom.adjmatrix = adjmatrix; 67 | end 68 | 69 | function test_assemble_fmesh 70 | q = 3; 71 | nl = 2; 72 | T = []; 73 | J = []; 74 | 75 | % geom: (only square geometry available now) 76 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 77 | geom.q = q; 78 | geom.nl = nl; 79 | geom.L = 2; % side length 80 | geom.dim = 2; % dimension of the problem 81 | geom.m = 2^geom.dim; % 82 | geom.N1 = 2^q; % dofs in one dimension 83 | geom.N = (geom.m)^geom.q; % dofs in the domain 84 | geom.h = geom.L/(geom.N1+1); % grid size 85 | 86 | geom = assemble_fmesh(geom); 87 | 88 | meshin = geom.pin; 89 | 90 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Z/generate_mesh.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | q = 7; 5 | nl = 2; 6 | T = []; 7 | J = []; 8 | 9 | % geom: (only square geometry available now) 10 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 11 | geom.q = q; 12 | geom.nl = nl; 13 | geom.dim = 2; % dimension of the problem 14 | geom.m = 2^geom.dim; % 15 | geom.N1 = 2^q; % dofs in one dimension, uniformly sampling 2^q points in range (a, b), not including edges 16 | geom.N = (geom.m)^geom.q; % dofs in the domain 17 | geom.xstart = 0; 18 | geom.xend = 1; 19 | geom.ystart = 0; 20 | geom.yend = 1; 21 | 22 | 23 | geom = assemble_fmesh(geom); 24 | 25 | meshXY = geom.pin; % the point pair for interior of square of [a,b]X[c,d], not including edges 26 | Z_coords = 0.5*ones(1, geom.N); 27 | 28 | XYZ = [meshXY;Z_coords]; 29 | if q == 7 30 | save('testXYZ7.mat','XYZ') 31 | elseif q == 6 32 | save('testXYZ6.mat','XYZ') 33 | elseif q == 5 34 | save('testXYZ5.mat','XYZ') 35 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Z/plot_fun.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_fun(geom, u) 9 | ftsz = 14; 10 | % require u to be a row vector 11 | if size(u, 2) == 1 12 | u=u'; 13 | end 14 | 15 | if length(u)==length(geom.p) % if u defined also on boundary 16 | 17 | elseif length(u)==sum(geom.in) % if u only defined on interior dofs 18 | u = u(geom.ind); 19 | u0 = zeros(length(geom.p), 1); 20 | u0(geom.in) = u; 21 | u = reshape(u0, size(geom.X))'; 22 | else 23 | error('dof of u does not match dof of mesh') 24 | return 25 | end 26 | 27 | mesh_u = u; 28 | 29 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 30 | axis tight; 31 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 32 | h = surf(geom.X, geom.Y, u); 33 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 34 | % colorbar; 35 | % caxis([0 0.5]) 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Z/plot_fun2in.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_fun2in(geom, u) 9 | meshX = geom.X; 10 | meshY = geom.Y; 11 | 12 | meshX_in = meshX(2:end-1, 2:end-1); 13 | meshY_in = meshY(2:end-1, 2:end-1); 14 | 15 | ftsz = 14; 16 | % require u to be a row vector 17 | if size(u, 2) == 1 18 | u=u'; 19 | end 20 | 21 | if length(u)==sum(geom.in) % if u only defined on interior dofs 22 | u0 = u(geom.ind); 23 | u = reshape(u0, size(meshX_in))'; 24 | else 25 | error('dof of u does not match dof of mesh') 26 | return 27 | end 28 | 29 | mesh_u = u; 30 | 31 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 32 | axis tight; 33 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 34 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 35 | 36 | h = surf(meshX_in, meshY_in, u,'Edgecolor', 'none'); 37 | % colorbar; 38 | % caxis([0 0.5]) 39 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 40 | set(gcf, 'Renderer', 'zbuffer'); 41 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Z/plot_pointError.m: -------------------------------------------------------------------------------- 1 | % plot function which is defined on the iterior dofs 2 | % function plot_fun(p, e, t, in, ind, u) % with triangular mesh 3 | % u1 = zeros(size(p,2), 1); 4 | % u1(in) = u(ind); 5 | % pdeplot(p,e,t,'xydata',u1,'zdata',u1); 6 | % end 7 | 8 | function mesh_u=plot_pointError(geom, u) 9 | ftsz = 14; 10 | % require u to be a row vector 11 | if size(u, 2) == 1 12 | u=u'; 13 | end 14 | 15 | if length(u)==length(geom.p) % if u defined also on boundary 16 | 17 | elseif length(u)==sum(geom.in) % if u only defined on interior dofs 18 | u = u(geom.ind); 19 | u0 = zeros(length(geom.p), 1); 20 | u0(geom.in) = u; 21 | u = reshape(u0, size(geom.X))'; 22 | else 23 | error('dof of u does not match dof of mesh') 24 | return 25 | end 26 | 27 | mesh_u = u; 28 | 29 | % surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'none', 'FaceAlpha', 0.9); 30 | axis tight; 31 | % surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 32 | % h = surf(geom.X, geom.Y, u, 'Edgecolor', 'none'); 33 | h = surf(geom.X, geom.Y, u); 34 | colorbar; 35 | caxis([0 5e-3]) 36 | set(gca, 'XMinortick', 'off', 'YMinorTick', 'off', 'Fontsize', ftsz); 37 | set(gcf, 'Renderer', 'zbuffer'); 38 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Z/plot_solu_perr.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all 3 | close all 4 | meshData = load('meshXY7.mat'); 5 | meshXY = meshData.UMESHXY; 6 | 7 | q = 7; 8 | nl = 2; 9 | T = []; 10 | J = []; 11 | 12 | % geom: (only square geometry available now) 13 | % generating 2d square mesh for the region [-1, 1] x [-1 1] 14 | geom.q = q; 15 | geom.nl = nl; 16 | geom.L = 2; % side length 17 | geom.dim = 2; % dimension of the problem 18 | geom.m = 2^geom.dim; % 19 | geom.N1 = 2^q; % dofs in one dimension 20 | geom.N = (geom.m)^geom.q; % dofs in the domain 21 | geom.h = geom.L/(geom.N1+1); % grid size 22 | geom.xstart = -1; 23 | geom.xend = 1; 24 | geom.ystart = -1; 25 | geom.yend = 1; 26 | 27 | geom = assemble_fmesh(geom); 28 | 29 | 30 | data2solution = load('test_solus.mat'); 31 | Solu_True = data2solution.Utrue; 32 | Solu_DNN = data2solution.Us2relu; 33 | figure('name','Exact_Solu') 34 | mesh_solu_true = plot_fun(geom,Solu_True); 35 | hold on 36 | 37 | figure('name','DNN_Solu') 38 | mesh_solu_dnn = plot_fun(geom,Solu_DNN); 39 | hold on 40 | 41 | err2solu = abs(Solu_True-Solu_DNN); 42 | figure('name','Err2solu') 43 | mesh_solu_err = plot_fun2in(geom,err2solu); 44 | title('Absolute Error') 45 | hold on 46 | colorbar; 47 | caxis([0 0.025]) 48 | hold on 49 | -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Z/quadtreeind.m: -------------------------------------------------------------------------------- 1 | function ind = quadtreeind(q) 2 | % construct quadtree index 3 | m = 4; 4 | 5 | M = [1 2; 3 4]; 6 | 7 | for k = 2:q 8 | M = [M M+m^(k-1); M+2*m^(k-1) M+3*m^(k-1)]; 9 | end 10 | 11 | ind = M(:)'; 12 | 13 | end -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/ThreeD2Fixed_Z/testXYZ7.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/dataMat_highDim/ThreeD2Fixed_Z/testXYZ7.mat -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/Untitled.m: -------------------------------------------------------------------------------- 1 | clear all 2 | clc 3 | close all 4 | data2xyz=load('testXYZ.mat'); 5 | xyz = data2xyz.XYZ; 6 | min(xyz) 7 | max(xyz) -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/generate_data.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear all 3 | close all 4 | % dim = input('please input a integral number:'); 5 | dim = 8; 6 | batch_size = 1600; 7 | XYZRSTVW = rand(batch_size, dim); 8 | save('testXYZRSTVW.mat', 'XYZRSTVW') 9 | 10 | -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/testXY.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/dataMat_highDim/testXY.mat -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/testXYZ.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/dataMat_highDim/testXYZ.mat -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/testXYZRSTVW.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/dataMat_highDim/testXYZRSTVW.mat -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/testXYZS.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/dataMat_highDim/testXYZS.mat -------------------------------------------------------------------------------- /Experiments/dataMat_highDim/testXYZST.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Experiments/dataMat_highDim/testXYZST.mat -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Blue-Giant 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Networks/__pycache__/ELM_Base.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Networks/__pycache__/ELM_Base.cpython-39.pyc -------------------------------------------------------------------------------- /Problems/General_Laplace.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import torch 3 | 4 | 5 | def get_infos2Laplace_1D(input_dim=1, out_dim=1, intervalL=0.0, intervalR=1.0, equa_name=None): 6 | # uxx = f 7 | if equa_name == 'PDE1': 8 | # u=sin(pi*x), f=-pi*pi*sin(pi*x) 9 | fside = lambda x: -(np.pi)*(np.pi)*np.sin(np.pi*x) 10 | utrue = lambda x: np.sin(np.pi*x) 11 | uleft = lambda x: np.sin(np.pi*x) 12 | uright = lambda x: np.sin(np.pi*x) 13 | return fside, utrue, uleft, uright 14 | 15 | 16 | # 偏微分方程的一些信息:边界条件,初始条件,真解,右端项函数 17 | def get_Laplace2D_infos(equa_name=None): 18 | if equa_name == 'PDE1': 19 | f_side = lambda x, y: 2.0 * np.exp(x) * np.exp(y) 20 | 21 | u_true = lambda x, y: np.exp(x) * np.exp(y) 22 | 23 | ux_left = lambda x, y: np.exp(x) * np.exp(y) 24 | ux_right = lambda x, y: np.exp(x) * np.exp(y) 25 | uy_bottom = lambda x, y: np.exp(x) * np.exp(y) 26 | uy_top = lambda x, y: np.exp(x) * np.exp(y) 27 | elif equa_name == 'PDE2': 28 | f_side = lambda x, y: -2.0 * np.pi * np.pi * np.sin(np.pi*x) * np.sin(np.pi*y) 29 | 30 | u_true = lambda x, y: np.sin(np.pi*x) * np.sin(np.pi*y) 31 | 32 | ux_left = lambda x, y: np.sin(np.pi*x) * np.sin(np.pi*y) 33 | ux_right = lambda x, y: np.sin(np.pi*x) * np.sin(np.pi*y) 34 | uy_bottom = lambda x, y: np.sin(np.pi*x) * np.sin(np.pi*y) 35 | uy_top = lambda x, y: np.sin(np.pi*x) * np.sin(np.pi*y) 36 | elif equa_name == 'PDE3': 37 | f_side = lambda x, y: -25.0 * np.pi * np.pi * np.sin(3*np.pi*x) * np.sin(4*np.pi*y) 38 | 39 | u_true = lambda x, y: np.sin(3*np.pi*x) * np.sin(4*np.pi*y) 40 | 41 | ux_left = lambda x, y: np.sin(3*np.pi*x) * np.sin(4*np.pi*y) 42 | ux_right = lambda x, y: np.sin(3*np.pi*x) * np.sin(4*np.pi*y) 43 | uy_bottom = lambda x, y: np.sin(3*np.pi*x) * np.sin(4*np.pi*y) 44 | uy_top = lambda x, y: np.sin(3*np.pi*x) * np.sin(4*np.pi*y) 45 | elif equa_name == 'PDE4': 46 | f_side = lambda x, y: -2.0 * np.pi * np.pi * np.sin(np.pi*x) * np.sin(np.pi*y) - 10.0 * np.pi * np.pi * np.sin(8*np.pi*x) * np.sin(6*np.pi*y) 47 | 48 | u_true = lambda x, y: np.sin(np.pi*x) * np.sin(np.pi*y) + 0.1*np.sin(8*np.pi*x) * np.sin(6*np.pi*y) 49 | 50 | ux_left = lambda x, y: np.sin(1.0*np.pi*x) * np.sin(1.0*np.pi*y) + 0.1*np.sin(8*np.pi*x) * np.sin(6*np.pi*y) 51 | ux_right = lambda x, y: np.sin(1.0*np.pi*x) * np.sin(1.0*np.pi*y) + 0.1*np.sin(8*np.pi*x) * np.sin(6*np.pi*y) 52 | uy_bottom = lambda x, y: np.sin(1.0*np.pi*x) * np.sin(1.0*np.pi*y) + 0.1*np.sin(8*np.pi*x) * np.sin(6*np.pi*y) 53 | uy_top = lambda x, y: np.sin(1.0*np.pi*x) * np.sin(1.0*np.pi*y) + 0.1*np.sin(8*np.pi*x) * np.sin(6*np.pi*y) 54 | return f_side, u_true, ux_left, ux_right, uy_bottom, uy_top 55 | 56 | 57 | # 偏微分方程的一些信息:边界条件,初始条件,真解,右端项函数 58 | def get_infos2Laplace_2D(input_dim=1, out_dim=1, left_bottom=0.0, right_top=1.0, equa_name=None): 59 | if equa_name == 'PDE1': 60 | # u=exp(-x)(y^3), f = -exp(-x)(x-2+y^3+6y) 61 | f_side = lambda x, y: -(torch.exp(-1.0*x)) * (x - 2 + torch.pow(y, 3) + 6 * y) 62 | 63 | u_true = lambda x, y: (torch.exp(-1.0*x))*(x + torch.pow(y, 3)) 64 | 65 | ux_left = lambda x, y: (torch.exp(-1.0*x))*(x + torch.pow(y, 3)) 66 | ux_right = lambda x, y: (torch.exp(-1.0*x))*(x + torch.pow(y, 3)) 67 | uy_bottom = lambda x, y: (torch.exp(-1.0*x))*(x + torch.pow(y, 3)) 68 | uy_top = lambda x, y: (torch.exp(-1.0*x))*(x + torch.pow(y, 3)) 69 | return f_side, u_true, ux_left, ux_right, uy_bottom, uy_top 70 | elif equa_name == 'PDE2': 71 | f_side = lambda x, y: (-1.0)*torch.sin(torch.pi*x) * (2 - torch.square(torch.pi)*torch.square(y)) 72 | 73 | u_true = lambda x, y: torch.square(y)*torch.sin(torch.pi*x) 74 | 75 | ux_left = lambda x, y: torch.square(y)*torch.sin(torch.pi*x) 76 | ux_right = lambda x, y: torch.square(y)*torch.sin(torch.pi*x) 77 | uy_bottom = lambda x, y: torch.square(y)*torch.sin(torch.pi*x) 78 | uy_top = lambda x, y: torch.square(y)*torch.sin(torch.pi*x) 79 | return f_side, u_true, ux_left, ux_right, uy_bottom, uy_top 80 | elif equa_name == 'PDE3': 81 | # u=exp(x+y), f = -2*exp(x+y) 82 | f_side = lambda x, y: -2.0*(torch.exp(x)*torch.exp(y)) 83 | u_true = lambda x, y: torch.exp(x)*torch.exp(y) 84 | ux_left = lambda x, y: torch.multiply(torch.exp(y), torch.exp(left_bottom)) 85 | ux_right = lambda x, y: torch.multiply(torch.exp(y), torch.exp(right_top)) 86 | uy_bottom = lambda x, y: torch.multiply(torch.exp(x), torch.exp(left_bottom)) 87 | uy_top = lambda x, y: torch.multiply(torch.exp(x), torch.exp(right_top)) 88 | return f_side, u_true, ux_left, ux_right, uy_bottom, uy_top 89 | elif equa_name == 'PDE4': 90 | # u=(1/4)*(x^2+y^2), f = -1 91 | f_side = lambda x, y: -1.0*torch.ones_like(x) 92 | u_true = lambda x, y: 0.25*(torch.pow(x, 2)+torch.pow(y, 2)) 93 | ux_left = lambda x, y: 0.25 * torch.pow(y, 2) + 0.25 * torch.pow(left_bottom, 2) 94 | ux_right = lambda x, y: 0.25 * torch.pow(y, 2) + 0.25 * torch.pow(right_top, 2) 95 | uy_bottom = lambda x, y: 0.25 * torch.pow(x, 2) + 0.25 * torch.pow(left_bottom, 2) 96 | uy_top = lambda x, y: 0.25 * torch.pow(x, 2) + 0.25 * torch.pow(right_top, 2) 97 | return f_side, u_true, ux_left, ux_right, uy_bottom, uy_top 98 | elif equa_name == 'PDE5': 99 | # u=(1/4)*(x^2+y^2)+x+y, f = -1 100 | f_side = lambda x, y: -1.0*torch.ones_like(x) 101 | 102 | u_true = lambda x, y: 0.25*(torch.pow(x, 2)+torch.pow(y, 2)) + x + y 103 | 104 | ux_left = lambda x, y: 0.25 * torch.pow(y, 2) + 0.25 * torch.pow(left_bottom, 2) + left_bottom + y 105 | ux_right = lambda x, y: 0.25 * torch.pow(y, 2) + 0.25 * torch.pow(right_top, 2) + right_top + y 106 | uy_bottom = lambda x, y: 0.25 * torch.pow(x, 2) + torch.pow(left_bottom, 2) + left_bottom + x 107 | uy_top = lambda x, y: 0.25 * torch.pow(x, 2) + 0.25 * torch.pow(right_top, 2) + right_top + x 108 | return f_side, u_true, ux_left, ux_right, uy_bottom, uy_top 109 | elif equa_name == 'PDE6': 110 | # u=(1/2)*(x^2)*(y^2), f = -(x^2+y^2) 111 | f_side = lambda x, y: -1.0*(torch.pow(x, 2)+torch.pow(y, 2)) 112 | 113 | u_true = lambda x, y: 0.5 * (torch.pow(x, 2) * torch.pow(y, 2)) 114 | 115 | ux_left = lambda x, y: 0.5 * (torch.pow(left_bottom, 2) * torch.pow(y, 2)) 116 | ux_right = lambda x, y: 0.5 * (torch.pow(right_top, 2) * torch.pow(y, 2)) 117 | uy_bottom = lambda x, y: 0.5 * (torch.pow(x, 2) * torch.pow(left_bottom, 2)) 118 | uy_top = lambda x, y: 0.5 * (torch.pow(x, 2) * torch.pow(right_top, 2)) 119 | return f_side, u_true, ux_left, ux_right, uy_bottom, uy_top 120 | elif equa_name == 'PDE7': 121 | # u=(1/2)*(x^2)*(y^2)+x+y, f = -(x^2+y^2) 122 | f_side = lambda x, y: -1.0*(torch.pow(x, 2)+torch.pow(y, 2)) 123 | 124 | u_true = lambda x, y: 0.5*(torch.pow(x, 2)*torch.pow(y, 2)) + x*torch.ones_like(x) + y*torch.ones_like(y) 125 | 126 | ux_left = lambda x, y: 0.5 * torch.multiply(torch.pow(left_bottom, 2), torch.pow(y, 2)) + left_bottom + y 127 | ux_right = lambda x, y: 0.5 * torch.multiply(torch.pow(right_top, 2), torch.pow(y, 2)) + right_top + y 128 | uy_bottom = lambda x, y: 0.5 * torch.multiply(torch.pow(x, 2), torch.pow(left_bottom, 2)) + x + left_bottom 129 | uy_top = lambda x, y: 0.5 * torch.multiply(torch.pow(x, 2), torch.pow(right_top, 2)) + x + right_top 130 | return f_side, u_true, ux_left, ux_right, uy_bottom, uy_top 131 | 132 | 133 | # 偏微分方程的一些信息:边界条件,初始条件,真解,右端项函数 134 | def get_infos2Laplace_3D(input_dim=1, out_dim=1, intervalL=0.0, intervalR=1.0, equa_name=None): 135 | if equa_name == 'PDE1': 136 | # Laplace U = f 137 | # u=sin(pi*x)*sin(pi*y)*sin(pi*z), f=pi*pi*sin(pi*x)*sin(pi*y)*sin(pi*z) 138 | fside = lambda x, y, z: -(np.pi)*(np.pi)*np.sin(np.pi*x)*np.sin(np.pi*y)*np.sin(np.pi*z) 139 | utrue = lambda x, y, z: np.sin(np.pi*x)*np.sin(np.pi*y)*np.sin(np.pi*z) 140 | u_00 = lambda x, y, z: np.sin(np.pi*x)*np.sin(np.pi*y)*np.sin(np.pi*z) 141 | u_01 = lambda x, y, z: np.sin(np.pi*x)*np.sin(np.pi*y)*np.sin(np.pi*z) 142 | u_10 = lambda x, y, z: np.sin(np.pi*x)*np.sin(np.pi*y)*np.sin(np.pi*z) 143 | u_11 = lambda x, y, z: np.sin(np.pi*x)*np.sin(np.pi*y)*np.sin(np.pi*z) 144 | u_20 = lambda x, y, z: np.sin(np.pi*x)*np.sin(np.pi*y)*np.sin(np.pi*z) 145 | u_21 = lambda x, y, z: np.sin(np.pi*x)*np.sin(np.pi*y)*np.sin(np.pi*z) 146 | return fside, utrue, u_00, u_01, u_10, u_11, u_20, u_21 147 | 148 | 149 | # 偏微分方程的一些信息:边界条件,初始条件,真解,右端项函数 150 | def get_infos2Laplace_5D(input_dim=1, out_dim=1, intervalL=0.0, intervalR=1.0, equa_name=None): 151 | if equa_name == 'PDE1': 152 | # u=sin(pi*x), f=-pi*pi*sin(pi*x) 153 | fside = lambda x, y, z, s, t: -(torch.pi)*(torch.pi)*torch.sin(torch.pi*x) 154 | utrue = lambda x, y, z, s, t: torch.sin(torch.pi*x)*torch.sin(torch.pi*y)*torch.sin(torch.pi*z)*torch.sin(torch.pi*s)*torch.sin(torch.pi*t) 155 | u_00 = lambda x, y, z, s, t: torch.sin(torch.pi*intervalL)*torch.sin(torch.pi*y)*torch.sin(torch.pi*z)*torch.sin(torch.pi*s)*torch.sin(torch.pi*t) 156 | u_01 = lambda x, y, z, s, t: torch.sin(torch.pi*intervalR)*torch.sin(torch.pi*y)*torch.sin(torch.pi*z)*torch.sin(torch.pi*s)*torch.sin(torch.pi*t) 157 | u_10 = lambda x, y, z, s, t: torch.sin(torch.pi * x) * torch.sin(torch.pi * intervalL) * torch.sin(torch.pi * z) * torch.sin(torch.pi * s) * torch.sin(torch.pi * t) 158 | u_11 = lambda x, y, z, s, t: torch.sin(torch.pi * x) * torch.sin(torch.pi * intervalR) * torch.sin(torch.pi * z) * torch.sin(torch.pi * s) * torch.sin(torch.pi * t) 159 | u_20 = lambda x, y, z, s, t: torch.sin(torch.pi * x) * torch.sin(torch.pi * y) * torch.sin(torch.pi * intervalL) * torch.sin(torch.pi * s) * torch.sin(torch.pi * t) 160 | u_21 = lambda x, y, z, s, t: torch.sin(torch.pi * x) * torch.sin(torch.pi * y) * torch.sin(torch.pi * intervalR) * torch.sin(torch.pi * s) * torch.sin(torch.pi * t) 161 | u_30 = lambda x, y, z, s, t: torch.sin(torch.pi * x) * torch.sin(torch.pi * y) * torch.sin(torch.pi * z) * torch.sin(torch.pi * intervalL) * torch.sin(torch.pi * t) 162 | u_31 = lambda x, y, z, s, t: torch.sin(torch.pi * x) * torch.sin(torch.pi * y) * torch.sin(torch.pi * z) * torch.sin(torch.pi * intervalR) * torch.sin(torch.pi * t) 163 | u_40 = lambda x, y, z, s, t: torch.sin(torch.pi * x) * torch.sin(torch.pi * y) * torch.sin(torch.pi * z) * torch.sin(torch.pi * s) * torch.sin(torch.pi * intervalL) 164 | u_41 = lambda x, y, z, s, t: torch.sin(torch.pi * x) * torch.sin(torch.pi * y) * torch.sin(torch.pi * z) * torch.sin(torch.pi * s) * torch.sin(torch.pi * intervalR) 165 | return fside, utrue, u_00, u_01, u_10, u_11, u_20, u_21, u_30, u_31, u_40, u_41 -------------------------------------------------------------------------------- /Problems/__pycache__/General_Laplace.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/Problems/__pycache__/General_Laplace.cpython-39.pyc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PIELM_Numpy 2 | 3 | Physcial Informed Extreme Learning Machine(PIELM) method to solve PDEs, such as Possion problem and Biharmonic problem 4 | 5 | # Corresponding Papers 6 | 7 | ## Augmented physics informed extreme learning machine to solve thebiharmonic equations via Fourier expansions 8 | created by Xi’an Li, Jinran Wu, Yujia Huang, Zhe Ding, You-Gan Wang, Xin Tai, Liang Liu 9 | 10 | [[Paper]](https://arxiv.org/pdf/2310.13947.pdf) 11 | 12 | ### Ideas 13 | By carefully calculating the differential and boundary operators of the biharmonicequation on discretized collections, the solution for this high-order equation is reformulated as a linearleast squares minimization problem. 14 | 15 | ### Abstract: 16 | To address the sensitivity of parameters and limited precision for physics-informed extreme learning machines(PIELM) with common activation functions, such as sigmoid, tangent, and Gaussian, in solving highorder partial differential equations (PDEs) relevant to scientific computation and engineering applications, this work develops a Fourier-induced PIELM (FPIELM) method. This approach aims to approximatesolutions for a class of fourth-order biharmonic equations with two boundary conditions on both unitized and non-unitized domains. By carefully calculating the differential and boundary operators of the biharmonicequation on discretized collections, the solution for this high-order equation is reformulated as a linearleast squares minimization problem. We further evaluate the FPIELM with varying hidden nodes andscaling factors for uniform distribution initialization, and then determine the optimal range for these twohyperparameters. Numerical experiments and comparative analyses demonstrate that the proposed FPIELMmethod is more stable, robust, precise, and efficient than other PIELM approaches in solving biharmonicequations across both regular and irregular domains. 17 | -------------------------------------------------------------------------------- /Results/Laplace1D/10m_23d_21h_48m_30s/Possion1D.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import platform 4 | import shutil 5 | 6 | import torch 7 | import numpy as np 8 | torch.set_default_dtype(torch.float64) 9 | import time 10 | import datetime 11 | from scipy.linalg import lstsq 12 | import matplotlib.pyplot as plt 13 | from Networks import ELM_Base 14 | from utilizers import DNN_tools 15 | from utilizers import plot_data 16 | from utilizers import saveData 17 | from utilizers import RFN_Log_Print 18 | from Problems import General_Laplace 19 | from utilizers import dataUtilizer2numpy 20 | 21 | 22 | # Global random feature network 23 | class GELM2Possion(object): 24 | def __init__(self, indim=1, outdim=1, num2hidden=None, name2Model='DNN', actName2hidden='tanh', actName2Deri='tanh', 25 | actName2DDeri='tanh', type2float='float32', opt2init_W='xavier_normal', opt2init_B='xavier_uniform', 26 | W_sigma=1.0, B_sigma=1.0): 27 | super(GELM2Possion, self).__init__() 28 | 29 | self.indim = indim 30 | self.outdim = outdim 31 | self.num2hidden = num2hidden 32 | self.name2Model = name2Model 33 | self.actName2hidden = actName2hidden 34 | self.actName2derivative = actName2Deri 35 | self.actName2DDeri = actName2DDeri 36 | self.act_func2hidden = RFN_Base.my_actFunc(actName=actName2hidden) 37 | self.act_func2Deri = RFN_Base.ActFunc2Derivate(actName=actName2Deri) 38 | self.act_func2DDeri = RFN_Base.ActFunc2DDerivate(actName=actName2DDeri) 39 | 40 | self.ELM_Bases = RFN_Base.PIELM( 41 | dim2in=indim, dim2out=1, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 42 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, opt2init_hiddenW=opt2init_W, 43 | opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 44 | 45 | if type2float == 'float32': 46 | self.float_type = np.float32 47 | elif type2float == 'float64': 48 | self.float_type = np.float64 49 | elif type2float == 'float16': 50 | self.float_type = np.float16 51 | 52 | # Assembling the matrix A,f in inner domain 53 | def assemble_matrix2inner(self, X_inner=None, fside=None, if_lambda2fside=True): 54 | A = self.ELM_Bases.assemble_matrix2DDerivative_1D(X_input=X_inner) 55 | 56 | shape2XY = X_inner.shape 57 | lenght2XY_shape = len(shape2XY) 58 | assert (lenght2XY_shape == 2) 59 | assert (shape2XY[-1] == 1) 60 | 61 | if if_lambda2fside: 62 | f = fside(X_inner) 63 | else: 64 | f = fside 65 | 66 | return (A, f) 67 | 68 | # Assembling the matrix B,g in boundary domain 69 | def assemble_matrix2boundary(self, X_bd=None, gside=None, if_lambda2gside=True): 70 | B = self.ELM_Bases.assemble_matrix2boundary_1D(X_input=X_bd) 71 | shape2XY = X_bd.shape 72 | lenght2XY_shape = len(shape2XY) 73 | assert (lenght2XY_shape == 2) 74 | assert (shape2XY[-1] == 1) 75 | 76 | if if_lambda2gside: 77 | g = gside(X_bd) 78 | else: 79 | g = gside 80 | 81 | return (B, g) 82 | 83 | def test_rfn(self, points=None): 84 | ELM_Bases = self.ELM_Bases.get_out2Hidden(input_data=points) 85 | return ELM_Bases 86 | 87 | 88 | def solve_possion(Rdic=None): 89 | log_out_path = Rdic['FolderName'] # 将路径从字典 R 中提取出来 90 | if not os.path.exists(log_out_path): # 判断路径是否已经存在 91 | os.mkdir(log_out_path) # 无 log_out_path 路径,创建一个 log_out_path 路径 92 | logfile_name = '%s.txt' % ('log') 93 | log_fileout = open(os.path.join(log_out_path, logfile_name), 'w') # 在这个路径下创建并打开一个可写的 log_train.txt文件 94 | RFN_Log_Print.dictionary_out2file(Rdic, log_fileout) 95 | 96 | time_begin = time.time() 97 | 98 | left = 0.0 99 | right = 1.0 100 | 101 | Model = GELM2Possion(indim=Rdic['input_dim'], outdim=Rdic['out_dim'], num2hidden=Rdic['rfn_hidden'], 102 | name2Model='DNN', actName2hidden=Rdic['act_name'], type2float='float64', opt2init_W='normal', 103 | opt2init_B='uniform', W_sigma=1.0, B_sigma=1.0) 104 | 105 | type2float = np.float64 106 | # points = dataUtilizer2numpy.gene_1Drand_points2inner(num2point=Rdic['point_num2inner'], 107 | # variable_dim=Rdic['input_dim'], 108 | # region_l=left, region_r=right, to_float=True, 109 | # float_type=type2float, opt2rand='random') 110 | 111 | points = dataUtilizer2numpy.gene_1Dmesh_points2inner(num2point=Rdic['point_num2inner'], 112 | variable_dim=Rdic['input_dim'], 113 | region_l=left, region_r=right, to_float=True, 114 | float_type=type2float) 115 | 116 | left_bd, right_bd = dataUtilizer2numpy.gene_1Dinterval2bd( 117 | num2point=Rdic['point_num2boundary'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 118 | to_float=True, float_type=type2float) 119 | 120 | f_side, u_true, ux_left, ux_right = General_Laplace.get_infos2Laplace_1D(equa_name=Rdic['Equa_name']) 121 | 122 | A_I, f_i = Model.assemble_matrix2inner(X_inner=points, fside=f_side) 123 | 124 | B_l, gl = Model.assemble_matrix2boundary(X_bd=left_bd, gside=ux_left) 125 | 126 | B_r, gr = Model.assemble_matrix2boundary(X_bd=right_bd, gside=ux_right) 127 | 128 | num2inner = Rdic['point_num2inner'] 129 | num2boundary = Rdic['point_num2boundary'] 130 | rfn_hidden = Rdic['rfn_hidden'] 131 | 132 | A = np.zeros([num2inner + 2 * num2boundary, rfn_hidden]) 133 | F = np.zeros([num2inner + 2 * num2boundary, 1]) 134 | 135 | A[0:num2inner, :] = A_I 136 | 137 | A[num2inner:num2inner+num2boundary, :] = B_l 138 | A[num2inner+num2boundary:num2inner + 2 * num2boundary, :] = B_r 139 | 140 | F[0:num2inner, :] = f_i 141 | 142 | F[num2inner:num2inner + num2boundary, :] = gl 143 | F[num2inner + num2boundary:num2inner + 2 * num2boundary, :] = gr 144 | 145 | # # rescaling 146 | c = 100.0 147 | 148 | for i in range(len(A)): 149 | ratio = c / A[i, :].max() 150 | A[i, :] = A[i, :] * ratio 151 | F[i] = F[i] * ratio 152 | # solve 153 | w = lstsq(A, F)[0] 154 | 155 | temp = Model.test_rfn(points=points) 156 | numeri_solu = np.matmul(temp, w) 157 | 158 | time_end = time.time() 159 | run_time = time_end - time_begin 160 | 161 | exact_solu = u_true(points) 162 | 163 | abs_diff = np.abs(exact_solu - numeri_solu) 164 | 165 | max_diff = np.max(abs_diff) 166 | 167 | print('max_diff:', max_diff) 168 | 169 | rel_err = np.sqrt(np.sum(np.square(exact_solu - numeri_solu), axis=0) / np.sum(np.square(exact_solu), axis=0)) 170 | 171 | print('relative error:', rel_err[0]) 172 | 173 | print('running time:', run_time) 174 | 175 | DNN_tools.log_string('The max absolute error: %.18f\n' % max_diff, log_fileout) 176 | DNN_tools.log_string('The relative error: %.18f\n' % rel_err[0], log_fileout) 177 | DNN_tools.log_string('The running time: %.18f s\n' % run_time, log_fileout) 178 | 179 | plot_data.plot_solu_1D(solu=abs_diff, coords=points, color='m', actName='diff', outPath=FolderName) 180 | plot_data.plot_solu_1D(solu=exact_solu, coords=points, color='r', actName='exact', outPath=FolderName) 181 | plot_data.plot_solu_1D(solu=numeri_solu, coords=points, color='b', actName='numerical', outPath=FolderName) 182 | 183 | saveData.save_testData_or_solus2mat(exact_solu, dataName='true', outPath=FolderName) 184 | saveData.save_testData_or_solus2mat(numeri_solu, dataName='numeri', outPath=FolderName) 185 | saveData.save_testData_or_solus2mat(abs_diff, dataName='perr', outPath=FolderName) 186 | 187 | saveData.save_run_time2mat(run_time=run_time, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 188 | saveData.save_max_rel2mat(max_err=max_diff, rel_err=rel_err, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 189 | 190 | 191 | if __name__ == "__main__": 192 | R = {} 193 | # 文件保存路径设置 194 | file2results = 'Results' 195 | store_file = 'Laplace1D' 196 | BASE_DIR2FILE = os.path.dirname(os.path.abspath(__file__)) 197 | split_BASE_DIR2FILE = os.path.split(BASE_DIR2FILE) 198 | split_BASE_DIR2FILE = os.path.split(split_BASE_DIR2FILE[0]) 199 | BASE_DIR = split_BASE_DIR2FILE[0] 200 | sys.path.append(BASE_DIR) 201 | OUT_DIR_BASE = os.path.join(BASE_DIR, file2results) 202 | OUT_DIR = os.path.join(OUT_DIR_BASE, store_file) 203 | sys.path.append(OUT_DIR) 204 | if not os.path.exists(OUT_DIR): 205 | print('---------------------- OUT_DIR ---------------------:', OUT_DIR) 206 | os.mkdir(OUT_DIR) 207 | 208 | current_day_time = datetime.datetime.now() # 获取当前时间 209 | date_time_dir = str(current_day_time.month) + str('m_') + \ 210 | str(current_day_time.day) + str('d_') + str(current_day_time.hour) + str('h_') + \ 211 | str(current_day_time.minute) + str('m_') + str(current_day_time.second) + str('s') 212 | FolderName = os.path.join(OUT_DIR, date_time_dir) # 路径连接 213 | if not os.path.exists(FolderName): 214 | print('--------------------- FolderName -----------------:', FolderName) 215 | os.mkdir(FolderName) 216 | 217 | R['FolderName'] = FolderName 218 | 219 | # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 复制并保存当前文件 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 220 | if platform.system() == 'Windows': 221 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 222 | else: 223 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 224 | 225 | R['PDE_type'] = 'Laplace' 226 | R['Equa_name'] = 'PDE1' 227 | # R['Equa_name'] = 'PDE2' 228 | 229 | R['point_num2inner'] = 2000 230 | R['point_num2boundary'] = 5 231 | R['rfn_hidden'] = 200 232 | R['input_dim'] = 1 233 | R['out_dim'] = 1 234 | 235 | R['sigma'] = 2 236 | 237 | R['act_name'] = 'tanh' 238 | # R['act_name'] = 'sin' 239 | # R['act_name'] = 'gauss' 240 | # R['act_name'] = 'sinAddcos' 241 | 242 | # R['act_name'] = 'fourier' 243 | 244 | # R['opt2initW'] = 'normal' 245 | # R['opt2initW'] = 'uniform' 246 | R['opt2initW'] = 'scale_uniform' 247 | 248 | # R['opt2initB'] = 'normal' 249 | # R['opt2initB'] = 'uniform' 250 | R['opt2initB'] = 'scale_uniform' 251 | solve_possion(Rdic=R) -------------------------------------------------------------------------------- /Results/Laplace1D/10m_23d_21h_48m_30s/log.txt: -------------------------------------------------------------------------------- 1 | PDE type for problem: Laplace 2 | 3 | Equation name for problem: PDE1 4 | 5 | num to the unit of rfn basis:200 6 | 7 | Activate function for RFN basis: tanh 8 | 9 | Option for initializing the weights of RFN basis: scale_uniform 10 | 11 | Option for initializing the weights of RFN basis: scale_uniform 12 | 13 | Batch-size 2 interior: 2000 14 | 15 | Batch-size 2 boundary: 5 16 | 17 | -------------------------------------------------------------------------------- /Results/Laplace1D/10m_23d_21h_51m_33s/Possion1D.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import platform 4 | import shutil 5 | 6 | import torch 7 | import numpy as np 8 | torch.set_default_dtype(torch.float64) 9 | import time 10 | import datetime 11 | from scipy.linalg import lstsq 12 | import matplotlib.pyplot as plt 13 | from Networks import ELM_Base 14 | from utilizers import DNN_tools 15 | from utilizers import plot_data 16 | from utilizers import saveData 17 | from utilizers import RFN_Log_Print 18 | from Problems import General_Laplace 19 | from utilizers import dataUtilizer2numpy 20 | 21 | 22 | # Global random feature network 23 | class GELM2Possion(object): 24 | def __init__(self, indim=1, outdim=1, num2hidden=None, name2Model='DNN', actName2hidden='tanh', actName2Deri='tanh', 25 | actName2DDeri='tanh', type2float='float32', opt2init_W='xavier_normal', opt2init_B='xavier_uniform', 26 | W_sigma=1.0, B_sigma=1.0): 27 | super(GELM2Possion, self).__init__() 28 | 29 | self.indim = indim 30 | self.outdim = outdim 31 | self.num2hidden = num2hidden 32 | self.name2Model = name2Model 33 | self.actName2hidden = actName2hidden 34 | self.actName2derivative = actName2Deri 35 | self.actName2DDeri = actName2DDeri 36 | self.act_func2hidden = RFN_Base.my_actFunc(actName=actName2hidden) 37 | self.act_func2Deri = RFN_Base.ActFunc2Derivate(actName=actName2Deri) 38 | self.act_func2DDeri = RFN_Base.ActFunc2DDerivate(actName=actName2DDeri) 39 | 40 | self.ELM_Bases = RFN_Base.PIELM( 41 | dim2in=indim, dim2out=1, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 42 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, opt2init_hiddenW=opt2init_W, 43 | opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 44 | 45 | if type2float == 'float32': 46 | self.float_type = np.float32 47 | elif type2float == 'float64': 48 | self.float_type = np.float64 49 | elif type2float == 'float16': 50 | self.float_type = np.float16 51 | 52 | # Assembling the matrix A,f in inner domain 53 | def assemble_matrix2inner(self, X_inner=None, fside=None, if_lambda2fside=True): 54 | A = self.ELM_Bases.assemble_matrix2DDerivative_1D(X_input=X_inner) 55 | 56 | shape2XY = X_inner.shape 57 | lenght2XY_shape = len(shape2XY) 58 | assert (lenght2XY_shape == 2) 59 | assert (shape2XY[-1] == 1) 60 | 61 | if if_lambda2fside: 62 | f = fside(X_inner) 63 | else: 64 | f = fside 65 | 66 | return (A, f) 67 | 68 | # Assembling the matrix B,g in boundary domain 69 | def assemble_matrix2boundary(self, X_bd=None, gside=None, if_lambda2gside=True): 70 | B = self.ELM_Bases.assemble_matrix2boundary_1D(X_input=X_bd) 71 | shape2XY = X_bd.shape 72 | lenght2XY_shape = len(shape2XY) 73 | assert (lenght2XY_shape == 2) 74 | assert (shape2XY[-1] == 1) 75 | 76 | if if_lambda2gside: 77 | g = gside(X_bd) 78 | else: 79 | g = gside 80 | 81 | return (B, g) 82 | 83 | def test_rfn(self, points=None): 84 | ELM_Bases = self.ELM_Bases.get_out2Hidden(input_data=points) 85 | return ELM_Bases 86 | 87 | 88 | def solve_possion(Rdic=None): 89 | log_out_path = Rdic['FolderName'] # 将路径从字典 R 中提取出来 90 | if not os.path.exists(log_out_path): # 判断路径是否已经存在 91 | os.mkdir(log_out_path) # 无 log_out_path 路径,创建一个 log_out_path 路径 92 | logfile_name = '%s.txt' % ('log') 93 | log_fileout = open(os.path.join(log_out_path, logfile_name), 'w') # 在这个路径下创建并打开一个可写的 log_train.txt文件 94 | RFN_Log_Print.dictionary_out2file(Rdic, log_fileout) 95 | 96 | time_begin = time.time() 97 | 98 | left = 0.0 99 | right = 1.0 100 | 101 | Model = GELM2Possion(indim=Rdic['input_dim'], outdim=Rdic['out_dim'], num2hidden=Rdic['rfn_hidden'], 102 | name2Model='DNN', actName2hidden=Rdic['act_name'], type2float='float64', opt2init_W='normal', 103 | opt2init_B='uniform', W_sigma=1.0, B_sigma=1.0) 104 | 105 | type2float = np.float64 106 | # points = dataUtilizer2numpy.gene_1Drand_points2inner(num2point=Rdic['point_num2inner'], 107 | # variable_dim=Rdic['input_dim'], 108 | # region_l=left, region_r=right, to_float=True, 109 | # float_type=type2float, opt2rand='random') 110 | 111 | points = dataUtilizer2numpy.gene_1Dmesh_points2inner(num2point=Rdic['point_num2inner'], 112 | variable_dim=Rdic['input_dim'], 113 | region_l=left, region_r=right, to_float=True, 114 | float_type=type2float) 115 | 116 | left_bd, right_bd = dataUtilizer2numpy.gene_1Dinterval2bd( 117 | num2point=Rdic['point_num2boundary'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 118 | to_float=True, float_type=type2float) 119 | 120 | f_side, u_true, ux_left, ux_right = General_Laplace.get_infos2Laplace_1D(equa_name=Rdic['Equa_name']) 121 | 122 | A_I, f_i = Model.assemble_matrix2inner(X_inner=points, fside=f_side) 123 | 124 | B_l, gl = Model.assemble_matrix2boundary(X_bd=left_bd, gside=ux_left) 125 | 126 | B_r, gr = Model.assemble_matrix2boundary(X_bd=right_bd, gside=ux_right) 127 | 128 | num2inner = Rdic['point_num2inner'] 129 | num2boundary = Rdic['point_num2boundary'] 130 | rfn_hidden = Rdic['rfn_hidden'] 131 | 132 | A = np.zeros([num2inner + 2 * num2boundary, rfn_hidden]) 133 | F = np.zeros([num2inner + 2 * num2boundary, 1]) 134 | 135 | A[0:num2inner, :] = A_I 136 | 137 | A[num2inner:num2inner+num2boundary, :] = B_l 138 | A[num2inner+num2boundary:num2inner + 2 * num2boundary, :] = B_r 139 | 140 | F[0:num2inner, :] = f_i 141 | 142 | F[num2inner:num2inner + num2boundary, :] = gl 143 | F[num2inner + num2boundary:num2inner + 2 * num2boundary, :] = gr 144 | 145 | # # rescaling 146 | c = 100.0 147 | 148 | for i in range(len(A)): 149 | ratio = c / A[i, :].max() 150 | A[i, :] = A[i, :] * ratio 151 | F[i] = F[i] * ratio 152 | # solve 153 | w = lstsq(A, F)[0] 154 | 155 | temp = Model.test_rfn(points=points) 156 | numeri_solu = np.matmul(temp, w) 157 | 158 | time_end = time.time() 159 | run_time = time_end - time_begin 160 | 161 | exact_solu = u_true(points) 162 | 163 | abs_diff = np.abs(exact_solu - numeri_solu) 164 | 165 | max_diff = np.max(abs_diff) 166 | 167 | print('max_diff:', max_diff) 168 | 169 | rel_err = np.sqrt(np.sum(np.square(exact_solu - numeri_solu), axis=0) / np.sum(np.square(exact_solu), axis=0)) 170 | 171 | print('relative error:', rel_err[0]) 172 | 173 | print('running time:', run_time) 174 | 175 | DNN_tools.log_string('The max absolute error: %.18f\n' % max_diff, log_fileout) 176 | DNN_tools.log_string('The relative error: %.18f\n' % rel_err[0], log_fileout) 177 | DNN_tools.log_string('The running time: %.18f s\n' % run_time, log_fileout) 178 | 179 | plot_data.plot_solu_1D(solu=abs_diff, coords=points, color='m', actName='diff', outPath=FolderName) 180 | plot_data.plot_solu_1D(solu=exact_solu, coords=points, color='r', actName='exact', outPath=FolderName) 181 | plot_data.plot_solu_1D(solu=numeri_solu, coords=points, color='b', actName='numerical', outPath=FolderName) 182 | 183 | saveData.save_testData_or_solus2mat(exact_solu, dataName='true', outPath=FolderName) 184 | saveData.save_testData_or_solus2mat(numeri_solu, dataName='numeri', outPath=FolderName) 185 | saveData.save_testData_or_solus2mat(abs_diff, dataName='perr', outPath=FolderName) 186 | 187 | saveData.save_run_time2mat(run_time=run_time, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 188 | saveData.save_max_rel2mat(max_err=max_diff, rel_err=rel_err, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 189 | 190 | 191 | if __name__ == "__main__": 192 | R = {} 193 | # 文件保存路径设置 194 | file2results = 'Results' 195 | store_file = 'Laplace1D' 196 | BASE_DIR2FILE = os.path.dirname(os.path.abspath(__file__)) 197 | split_BASE_DIR2FILE = os.path.split(BASE_DIR2FILE) 198 | split_BASE_DIR2FILE = os.path.split(split_BASE_DIR2FILE[0]) 199 | BASE_DIR = split_BASE_DIR2FILE[0] 200 | sys.path.append(BASE_DIR) 201 | OUT_DIR_BASE = os.path.join(BASE_DIR, file2results) 202 | OUT_DIR = os.path.join(OUT_DIR_BASE, store_file) 203 | sys.path.append(OUT_DIR) 204 | if not os.path.exists(OUT_DIR): 205 | print('---------------------- OUT_DIR ---------------------:', OUT_DIR) 206 | os.mkdir(OUT_DIR) 207 | 208 | current_day_time = datetime.datetime.now() # 获取当前时间 209 | date_time_dir = str(current_day_time.month) + str('m_') + \ 210 | str(current_day_time.day) + str('d_') + str(current_day_time.hour) + str('h_') + \ 211 | str(current_day_time.minute) + str('m_') + str(current_day_time.second) + str('s') 212 | FolderName = os.path.join(OUT_DIR, date_time_dir) # 路径连接 213 | if not os.path.exists(FolderName): 214 | print('--------------------- FolderName -----------------:', FolderName) 215 | os.mkdir(FolderName) 216 | 217 | R['FolderName'] = FolderName 218 | 219 | # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 复制并保存当前文件 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 220 | if platform.system() == 'Windows': 221 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 222 | else: 223 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 224 | 225 | R['PDE_type'] = 'Laplace' 226 | R['Equa_name'] = 'PDE1' 227 | # R['Equa_name'] = 'PDE2' 228 | 229 | R['point_num2inner'] = 2000 230 | R['point_num2boundary'] = 5 231 | R['rfn_hidden'] = 200 232 | R['input_dim'] = 1 233 | R['out_dim'] = 1 234 | 235 | R['sigma'] = 2 236 | 237 | R['act_name'] = 'tanh' 238 | # R['act_name'] = 'sin' 239 | # R['act_name'] = 'gauss' 240 | # R['act_name'] = 'sinAddcos' 241 | 242 | # R['act_name'] = 'fourier' 243 | 244 | # R['opt2initW'] = 'normal' 245 | # R['opt2initW'] = 'uniform' 246 | R['opt2initW'] = 'scale_uniform' 247 | 248 | # R['opt2initB'] = 'normal' 249 | # R['opt2initB'] = 'uniform' 250 | R['opt2initB'] = 'scale_uniform' 251 | solve_possion(Rdic=R) -------------------------------------------------------------------------------- /Results/Laplace1D/10m_23d_21h_51m_33s/log.txt: -------------------------------------------------------------------------------- 1 | PDE type for problem: Laplace 2 | 3 | Equation name for problem: PDE1 4 | 5 | num to the unit of rfn basis:200 6 | 7 | Activate function for RFN basis: tanh 8 | 9 | Option for initializing the weights of RFN basis: scale_uniform 10 | 11 | Option for initializing the weights of RFN basis: scale_uniform 12 | 13 | Batch-size 2 interior: 2000 14 | 15 | Batch-size 2 boundary: 5 16 | 17 | -------------------------------------------------------------------------------- /Results/Laplace1D/10m_23d_21h_52m_5s/Possion1D.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import platform 4 | import shutil 5 | 6 | import torch 7 | import numpy as np 8 | torch.set_default_dtype(torch.float64) 9 | import time 10 | import datetime 11 | from scipy.linalg import lstsq 12 | import matplotlib.pyplot as plt 13 | from Networks import ELM_Base 14 | from utilizers import DNN_tools 15 | from utilizers import plot_data 16 | from utilizers import saveData 17 | from utilizers import RFN_Log_Print 18 | from Problems import General_Laplace 19 | from utilizers import dataUtilizer2numpy 20 | 21 | 22 | # Global random feature network 23 | class GELM2Possion(object): 24 | def __init__(self, indim=1, outdim=1, num2hidden=None, name2Model='DNN', actName2hidden='tanh', actName2Deri='tanh', 25 | actName2DDeri='tanh', type2float='float32', opt2init_W='xavier_normal', opt2init_B='xavier_uniform', 26 | W_sigma=1.0, B_sigma=1.0): 27 | super(GELM2Possion, self).__init__() 28 | 29 | self.indim = indim 30 | self.outdim = outdim 31 | self.num2hidden = num2hidden 32 | self.name2Model = name2Model 33 | self.actName2hidden = actName2hidden 34 | self.actName2derivative = actName2Deri 35 | self.actName2DDeri = actName2DDeri 36 | self.act_func2hidden = RFN_Base.my_actFunc(actName=actName2hidden) 37 | self.act_func2Deri = RFN_Base.ActFunc2Derivate(actName=actName2Deri) 38 | self.act_func2DDeri = RFN_Base.ActFunc2DDerivate(actName=actName2DDeri) 39 | 40 | self.ELM_Bases = RFN_Base.PIELM( 41 | dim2in=indim, dim2out=1, num2hidden_units=num2hidden, name2Model='DNN', actName2hidden=actName2hidden, 42 | actName2Deri=actName2Deri, actName2DDeri=actName2DDeri, type2float=type2float, opt2init_hiddenW=opt2init_W, 43 | opt2init_hiddenB=opt2init_B, sigma2W=W_sigma, sigma2B=B_sigma) 44 | 45 | if type2float == 'float32': 46 | self.float_type = np.float32 47 | elif type2float == 'float64': 48 | self.float_type = np.float64 49 | elif type2float == 'float16': 50 | self.float_type = np.float16 51 | 52 | # Assembling the matrix A,f in inner domain 53 | def assemble_matrix2inner(self, X_inner=None, fside=None, if_lambda2fside=True): 54 | A = self.ELM_Bases.assemble_matrix2DDerivative_1D(X_input=X_inner) 55 | 56 | shape2XY = X_inner.shape 57 | lenght2XY_shape = len(shape2XY) 58 | assert (lenght2XY_shape == 2) 59 | assert (shape2XY[-1] == 1) 60 | 61 | if if_lambda2fside: 62 | f = fside(X_inner) 63 | else: 64 | f = fside 65 | 66 | return (A, f) 67 | 68 | # Assembling the matrix B,g in boundary domain 69 | def assemble_matrix2boundary(self, X_bd=None, gside=None, if_lambda2gside=True): 70 | B = self.ELM_Bases.assemble_matrix2boundary_1D(X_input=X_bd) 71 | shape2XY = X_bd.shape 72 | lenght2XY_shape = len(shape2XY) 73 | assert (lenght2XY_shape == 2) 74 | assert (shape2XY[-1] == 1) 75 | 76 | if if_lambda2gside: 77 | g = gside(X_bd) 78 | else: 79 | g = gside 80 | 81 | return (B, g) 82 | 83 | def test_rfn(self, points=None): 84 | ELM_Bases = self.ELM_Bases.get_out2Hidden(input_data=points) 85 | return ELM_Bases 86 | 87 | 88 | def solve_possion(Rdic=None): 89 | log_out_path = Rdic['FolderName'] # 将路径从字典 R 中提取出来 90 | if not os.path.exists(log_out_path): # 判断路径是否已经存在 91 | os.mkdir(log_out_path) # 无 log_out_path 路径,创建一个 log_out_path 路径 92 | logfile_name = '%s.txt' % ('log') 93 | log_fileout = open(os.path.join(log_out_path, logfile_name), 'w') # 在这个路径下创建并打开一个可写的 log_train.txt文件 94 | RFN_Log_Print.dictionary_out2file(Rdic, log_fileout) 95 | 96 | time_begin = time.time() 97 | 98 | left = 0.0 99 | right = 1.0 100 | 101 | Model = GELM2Possion(indim=Rdic['input_dim'], outdim=Rdic['out_dim'], num2hidden=Rdic['rfn_hidden'], 102 | name2Model='DNN', actName2hidden=Rdic['act_name'], type2float='float64', opt2init_W='normal', 103 | opt2init_B='uniform', W_sigma=1.0, B_sigma=1.0) 104 | 105 | type2float = np.float64 106 | # points = dataUtilizer2numpy.gene_1Drand_points2inner(num2point=Rdic['point_num2inner'], 107 | # variable_dim=Rdic['input_dim'], 108 | # region_l=left, region_r=right, to_float=True, 109 | # float_type=type2float, opt2rand='random') 110 | 111 | points = dataUtilizer2numpy.gene_1Dmesh_points2inner(num2point=Rdic['point_num2inner'], 112 | variable_dim=Rdic['input_dim'], 113 | region_l=left, region_r=right, to_float=True, 114 | float_type=type2float) 115 | 116 | left_bd, right_bd = dataUtilizer2numpy.gene_1Dinterval2bd( 117 | num2point=Rdic['point_num2boundary'], variable_dim=Rdic['input_dim'], region_l=left, region_r=right, 118 | to_float=True, float_type=type2float) 119 | 120 | f_side, u_true, ux_left, ux_right = General_Laplace.get_infos2Laplace_1D(equa_name=Rdic['Equa_name']) 121 | 122 | A_I, f_i = Model.assemble_matrix2inner(X_inner=points, fside=f_side) 123 | 124 | B_l, gl = Model.assemble_matrix2boundary(X_bd=left_bd, gside=ux_left) 125 | 126 | B_r, gr = Model.assemble_matrix2boundary(X_bd=right_bd, gside=ux_right) 127 | 128 | num2inner = Rdic['point_num2inner'] 129 | num2boundary = Rdic['point_num2boundary'] 130 | rfn_hidden = Rdic['rfn_hidden'] 131 | 132 | A = np.zeros([num2inner + 2 * num2boundary, rfn_hidden]) 133 | F = np.zeros([num2inner + 2 * num2boundary, 1]) 134 | 135 | A[0:num2inner, :] = A_I 136 | 137 | A[num2inner:num2inner+num2boundary, :] = B_l 138 | A[num2inner+num2boundary:num2inner + 2 * num2boundary, :] = B_r 139 | 140 | F[0:num2inner, :] = f_i 141 | 142 | F[num2inner:num2inner + num2boundary, :] = gl 143 | F[num2inner + num2boundary:num2inner + 2 * num2boundary, :] = gr 144 | 145 | # # rescaling 146 | c = 100.0 147 | 148 | for i in range(len(A)): 149 | ratio = c / A[i, :].max() 150 | A[i, :] = A[i, :] * ratio 151 | F[i] = F[i] * ratio 152 | # solve 153 | w = lstsq(A, F)[0] 154 | 155 | temp = Model.test_rfn(points=points) 156 | numeri_solu = np.matmul(temp, w) 157 | 158 | time_end = time.time() 159 | run_time = time_end - time_begin 160 | 161 | exact_solu = u_true(points) 162 | 163 | abs_diff = np.abs(exact_solu - numeri_solu) 164 | 165 | max_diff = np.max(abs_diff) 166 | 167 | print('max_diff:', max_diff) 168 | 169 | rel_err = np.sqrt(np.sum(np.square(exact_solu - numeri_solu), axis=0) / np.sum(np.square(exact_solu), axis=0)) 170 | 171 | print('relative error:', rel_err[0]) 172 | 173 | print('running time:', run_time) 174 | 175 | DNN_tools.log_string('The max absolute error: %.18f\n' % max_diff, log_fileout) 176 | DNN_tools.log_string('The relative error: %.18f\n' % rel_err[0], log_fileout) 177 | DNN_tools.log_string('The running time: %.18f s\n' % run_time, log_fileout) 178 | 179 | plot_data.plot_solu_1D(solu=abs_diff, coords=points, color='m', actName='diff', outPath=FolderName) 180 | plot_data.plot_solu_1D(solu=exact_solu, coords=points, color='r', actName='exact', outPath=FolderName) 181 | plot_data.plot_solu_1D(solu=numeri_solu, coords=points, color='b', actName='numerical', outPath=FolderName) 182 | 183 | saveData.save_testData_or_solus2mat(exact_solu, dataName='true', outPath=FolderName) 184 | saveData.save_testData_or_solus2mat(numeri_solu, dataName='numeri', outPath=FolderName) 185 | saveData.save_testData_or_solus2mat(abs_diff, dataName='perr', outPath=FolderName) 186 | 187 | saveData.save_run_time2mat(run_time=run_time, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 188 | saveData.save_max_rel2mat(max_err=max_diff, rel_err=rel_err, num2hidden=Rdic['rfn_hidden'], outPath=FolderName) 189 | 190 | 191 | if __name__ == "__main__": 192 | R = {} 193 | # 文件保存路径设置 194 | file2results = 'Results' 195 | store_file = 'Laplace1D' 196 | BASE_DIR2FILE = os.path.dirname(os.path.abspath(__file__)) 197 | split_BASE_DIR2FILE = os.path.split(BASE_DIR2FILE) 198 | split_BASE_DIR2FILE = os.path.split(split_BASE_DIR2FILE[0]) 199 | BASE_DIR = split_BASE_DIR2FILE[0] 200 | sys.path.append(BASE_DIR) 201 | OUT_DIR_BASE = os.path.join(BASE_DIR, file2results) 202 | OUT_DIR = os.path.join(OUT_DIR_BASE, store_file) 203 | sys.path.append(OUT_DIR) 204 | if not os.path.exists(OUT_DIR): 205 | print('---------------------- OUT_DIR ---------------------:', OUT_DIR) 206 | os.mkdir(OUT_DIR) 207 | 208 | current_day_time = datetime.datetime.now() # 获取当前时间 209 | date_time_dir = str(current_day_time.month) + str('m_') + \ 210 | str(current_day_time.day) + str('d_') + str(current_day_time.hour) + str('h_') + \ 211 | str(current_day_time.minute) + str('m_') + str(current_day_time.second) + str('s') 212 | FolderName = os.path.join(OUT_DIR, date_time_dir) # 路径连接 213 | if not os.path.exists(FolderName): 214 | print('--------------------- FolderName -----------------:', FolderName) 215 | os.mkdir(FolderName) 216 | 217 | R['FolderName'] = FolderName 218 | 219 | # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 复制并保存当前文件 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 220 | if platform.system() == 'Windows': 221 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 222 | else: 223 | shutil.copy(__file__, '%s/%s' % (FolderName, os.path.basename(__file__))) 224 | 225 | R['PDE_type'] = 'Laplace' 226 | R['Equa_name'] = 'PDE1' 227 | # R['Equa_name'] = 'PDE2' 228 | 229 | R['point_num2inner'] = 2000 230 | R['point_num2boundary'] = 5 231 | R['rfn_hidden'] = 200 232 | R['input_dim'] = 1 233 | R['out_dim'] = 1 234 | 235 | R['sigma'] = 2 236 | 237 | R['act_name'] = 'tanh' 238 | # R['act_name'] = 'sin' 239 | # R['act_name'] = 'gauss' 240 | # R['act_name'] = 'sinAddcos' 241 | 242 | # R['act_name'] = 'fourier' 243 | 244 | # R['opt2initW'] = 'normal' 245 | # R['opt2initW'] = 'uniform' 246 | R['opt2initW'] = 'scale_uniform' 247 | 248 | # R['opt2initB'] = 'normal' 249 | # R['opt2initB'] = 'uniform' 250 | R['opt2initB'] = 'scale_uniform' 251 | solve_possion(Rdic=R) -------------------------------------------------------------------------------- /Results/Laplace1D/10m_23d_21h_52m_5s/log.txt: -------------------------------------------------------------------------------- 1 | PDE type for problem: Laplace 2 | 3 | Equation name for problem: PDE1 4 | 5 | num to the unit of rfn basis:200 6 | 7 | Activate function for RFN basis: tanh 8 | 9 | Option for initializing the weights of RFN basis: scale_uniform 10 | 11 | Option for initializing the weights of RFN basis: scale_uniform 12 | 13 | Batch-size 2 interior: 2000 14 | 15 | Batch-size 2 boundary: 5 16 | 17 | -------------------------------------------------------------------------------- /utilizers/DNN_tools.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import numpy as np 4 | import matplotlib.pyplot as plt 5 | import time 6 | 7 | # 保存图片的一些设置 8 | isShowPic = 1 9 | Leftp = 0.18 10 | Bottomp = 0.18 11 | Widthp = 0.88-Leftp 12 | Heightp = 0.9-Bottomp 13 | pos = [Leftp, Bottomp, Widthp, Heightp] 14 | 15 | 16 | # 图片保存函数 17 | def mySaveFig(pltm, fntmp, fp=0, ax=0, isax=0, iseps=0, isShowPic=0): 18 | if isax == 1: 19 | pltm.rc('xtick', labelsize=18) 20 | pltm.rc('ytick', labelsize=18) 21 | ax.set_position(pos, which='both') 22 | fnm = '%s.png'%(fntmp) 23 | pltm.savefig(fnm) 24 | if iseps: 25 | fnm = '%s.eps'%(fntmp) 26 | pltm.savefig(fnm, format='eps', dpi=600) 27 | if fp != 0: 28 | fp.savefig("%s.pdf"%(fntmp), bbox_inches='tight') 29 | if isShowPic == 1: 30 | pltm.show() 31 | elif isShowPic == -1: 32 | return 33 | else: 34 | pltm.close() 35 | 36 | 37 | # 日志记数 38 | def log_string(out_str, log_out): 39 | log_out.write(out_str + '\n') # 将字符串写到文件log_fileout中去,末尾加换行 40 | log_out.flush() # 清空缓存区 41 | # flush() 方法是用来刷新缓冲区的,即将缓冲区中的数据立刻写入文件,同时清空缓冲区,不需要是被动的等待输出缓冲区写入。 42 | # 一般情况下,文件关闭后会自动刷新缓冲区,但有时你需要在关闭前刷新它,这时就可以使用 flush() 方法。 43 | 44 | 45 | def print_and_log_train_one_epoch(i_epoch, run_time, tmp_lr, temp_penalty_bd, pwb, loss_it_tmp, 46 | loss_bd_tmp, loss_tmp, train_mse_tmp, train_res_tmp, log_out=None): 47 | # 将运行结果打印出来 48 | print('train epoch: %d, time: %.3f' % (i_epoch, run_time)) 49 | print('learning rate: %.10f' % tmp_lr) 50 | print('boundary penalty: %f' % temp_penalty_bd) 51 | print('weights and biases with penalty: %f' % pwb) 52 | print('loss_it for training: %.10f' % loss_it_tmp) 53 | print('loss_bd for training: %.10f' % loss_bd_tmp) 54 | print('loss for training: %.10f' % loss_tmp) 55 | print('solution mean square error for training: %.10f' % train_mse_tmp) 56 | print('solution residual error for training: %.10f\n' % train_res_tmp) 57 | 58 | log_string('train epoch: %d,time: %.3f' % (i_epoch, run_time), log_out) 59 | log_string('learning rate: %.10f' % tmp_lr, log_out) 60 | log_string('boundary penalty: %f' % temp_penalty_bd, log_out) 61 | log_string('weights and biases with penalty: %f' % pwb, log_out) 62 | log_string('loss_it for training: %.10f' % loss_it_tmp, log_out) 63 | log_string('loss_bd for training: %.10f' % loss_bd_tmp, log_out) 64 | log_string('loss for training: %.10f' % loss_tmp, log_out) 65 | log_string('solution mean square error for training: %.10f' % train_mse_tmp, log_out) 66 | log_string('solution residual error for training: %.10f\n' % train_res_tmp, log_out) 67 | 68 | 69 | def print_and_log_test_one_epoch(mse2test, res2test, log_out=None): 70 | # 将运行结果打印出来 71 | print('mean square error of predict and real for testing: %.10f' % mse2test) 72 | print('residual error of predict and real for testing: %.10f\n' % res2test) 73 | 74 | log_string('mean square error of predict and real for testing: %.10f' % mse2test, log_out) 75 | log_string('residual error of predict and real for testing: %.10f\n\n' % res2test, log_out) -------------------------------------------------------------------------------- /utilizers/Load_data2Mat.py: -------------------------------------------------------------------------------- 1 | # !python3 2 | # -*- coding: utf-8 -*- 3 | # author: flag 4 | 5 | import numpy as np 6 | import scipy.io 7 | import torch 8 | 9 | 10 | # load the data from matlab of .mat 11 | def load_Matlab_data(filename=None): 12 | data = scipy.io.loadmat(filename, mat_dtype=True, struct_as_record=True) # variable_names='CATC' 13 | return data 14 | 15 | 16 | def get_randomData2mat(dim=2, data_path=None, to_torch=False, to_float=True, float_type='float64', to_cuda=False, gpu_no=0, use_grad2x=False): 17 | if dim == 2: 18 | file_name2data = str(data_path) + '/' + str('testXY') + str('.mat') 19 | data2matlab = load_Matlab_data(filename=file_name2data) 20 | data2points = data2matlab['XY'] 21 | elif dim == 3: 22 | file_name2data = str(data_path) + '/' + str('testXYZ') + str('.mat') 23 | data2matlab = load_Matlab_data(filename=file_name2data) 24 | data2points = data2matlab['XYZ'] 25 | elif dim == 4: 26 | file_name2data = str(data_path) + '/' + str('testXYZS') + str('.mat') 27 | data2matlab = load_Matlab_data(filename=file_name2data) 28 | data2points = data2matlab['XYZS'] 29 | elif dim == 5: 30 | file_name2data = str(data_path) + '/' + str('testXYZST') + str('.mat') 31 | data2matlab = load_Matlab_data(filename=file_name2data) 32 | data2points = data2matlab['XYZST'] 33 | elif dim == 8: 34 | file_name2data = str(data_path) + '/' + str('testXYZRSTVW') + str('.mat') 35 | data2matlab = load_Matlab_data(filename=file_name2data) 36 | data2points = data2matlab['XYZRSTVW'] 37 | if to_float: 38 | data2points = data2points.astype(np.float32) 39 | 40 | shape2data = np.shape(data2points) 41 | assert (len(shape2data) == 2) 42 | if shape2data[0] == 3 or shape2data[0] == 4 or shape2data[0] == 4 or shape2data[0] == 5 or shape2data[0] == 8: 43 | data2points = np.transpose(data2points, (1, 0)) 44 | 45 | if to_torch: 46 | torch_data = torch.from_numpy(data2points) 47 | 48 | if to_cuda: 49 | torch_data = torch_data.cuda(device='cuda:' + str(gpu_no)) 50 | 51 | torch_data.requires_grad = use_grad2x 52 | return torch_data 53 | 54 | 55 | def get_meshData2Laplace(equation_name=None, mesh_number=2, to_torch=False, to_float=True, to_cuda=False, gpu_no=0, 56 | use_grad2x=False): 57 | if equation_name == 'multi_scale2D_1': 58 | test_meshXY_file = '../dataMat2pLaplace/E1/' + str('meshXY') + str(mesh_number) + str('.mat') 59 | elif equation_name == 'multi_scale2D_2': 60 | test_meshXY_file = '../dataMat2pLaplace/E2/' + str('meshXY') + str(mesh_number) + str('.mat') 61 | elif equation_name == 'multi_scale2D_3': 62 | test_meshXY_file = '../dataMat2pLaplace/E3/' + str('meshXY') + str(mesh_number) + str('.mat') 63 | elif equation_name == 'multi_scale2D_4': 64 | test_meshXY_file = '../dataMat2pLaplace/E4/' + str('meshXY') + str(mesh_number) + str('.mat') 65 | elif equation_name == 'multi_scale2D_5': 66 | test_meshXY_file = '../dataMat2pLaplace/E5/' + str('meshXY') + str(mesh_number) + str('.mat') 67 | elif equation_name == 'multi_scale2D_6': 68 | assert (mesh_number == 6) 69 | test_meshXY_file = '../dataMat2pLaplace/E6/' + str('meshXY') + str(mesh_number) + str('.mat') 70 | elif equation_name == 'multi_scale2D_7': 71 | assert(mesh_number == 6) 72 | test_meshXY_file = '../dataMat2pLaplace/E7/' + str('meshXY') + str(mesh_number) + str('.mat') 73 | mesh_points = load_Matlab_data(test_meshXY_file) 74 | XY_points = mesh_points['meshXY'] 75 | shape2XY = np.shape(XY_points) 76 | assert(len(shape2XY) == 2) 77 | if shape2XY[0] == 2: 78 | xy_data = np.transpose(XY_points, (1, 0)) 79 | else: 80 | xy_data = XY_points 81 | 82 | if to_float: 83 | xy_data = xy_data.astype(np.float32) 84 | 85 | if to_torch: 86 | xy_data = torch.from_numpy(xy_data) 87 | 88 | if to_cuda: 89 | xy_data = xy_data.cuda(device='cuda:' + str(gpu_no)) 90 | 91 | xy_data.requires_grad = use_grad2x 92 | return xy_data 93 | 94 | 95 | def get_data2pLaplace(equation_name=None, mesh_number=2, to_torch=False, to_float=True, to_cuda=False, gpu_no=0, 96 | use_grad2x=False): 97 | if equation_name == 'multi_scale2D_1': 98 | test_meshXY_file = '../dataMat2pLaplace/E1/' + str('meshXY') + str(mesh_number) + str('.mat') 99 | elif equation_name == 'multi_scale2D_2': 100 | test_meshXY_file = '../dataMat2pLaplace/E2/' + str('meshXY') + str(mesh_number) + str('.mat') 101 | elif equation_name == 'multi_scale2D_3': 102 | test_meshXY_file = '../dataMat2pLaplace/E3/' + str('meshXY') + str(mesh_number) + str('.mat') 103 | elif equation_name == 'multi_scale2D_4': 104 | test_meshXY_file = '../dataMat2pLaplace/E4/' + str('meshXY') + str(mesh_number) + str('.mat') 105 | elif equation_name == 'multi_scale2D_5': 106 | test_meshXY_file = '../dataMat2pLaplace/E5/' + str('meshXY') + str(mesh_number) + str('.mat') 107 | elif equation_name == 'multi_scale2D_6': 108 | test_meshXY_file = '../dataMat2pLaplace/E6/' + str('meshXY') + str(mesh_number) + str('.mat') 109 | elif equation_name == 'multi_scale2D_9': 110 | test_meshXY_file = '../dataMat2pLaplace/E9/' + str('meshXY') + str(mesh_number) + str('.mat') 111 | elif equation_name == 'multi_scale2D_10': 112 | test_meshXY_file = '../dataMat2pLaplace/E10/' + str('meshXY') + str(mesh_number) + str('.mat') 113 | elif equation_name == 'multi_scale2D_7': 114 | assert(mesh_number == 6) 115 | test_meshXY_file = '../dataMat2pLaplace/E7/' + str('meshXY') + str(mesh_number) + str('.mat') 116 | mesh_XY = load_Matlab_data(test_meshXY_file) 117 | XY_points = mesh_XY['meshXY'] 118 | shape2XY = np.shape(XY_points) 119 | assert (len(shape2XY) == 2) 120 | if shape2XY[0] == 2: 121 | test_xy_data = np.transpose(XY_points, (1, 0)) 122 | else: 123 | test_xy_data = XY_points 124 | 125 | if to_float: 126 | test_xy_data = test_xy_data.astype(np.float32) 127 | 128 | if to_torch: 129 | test_xy_data = torch.from_numpy(test_xy_data) 130 | 131 | if to_cuda: 132 | test_xy_data = test_xy_data.cuda(device='cuda:' + str(gpu_no)) 133 | 134 | test_xy_data.requires_grad = use_grad2x 135 | return test_xy_data 136 | 137 | 138 | def get_meshData2Boltzmann(equation_name=None, domain_lr='01', mesh_number=2, to_torch=False, to_float=True, 139 | to_cuda=False, gpu_no=0, use_grad2x=False): 140 | if domain_lr == '01': 141 | meshXY_file = '../dataMat2Boltz/meshData_01/' + str('meshXY') + str(mesh_number) + str('.mat') 142 | elif domain_lr == '11': 143 | meshXY_file = '../dataMat2Boltz/meshData_11/' + str('meshXY') + str(mesh_number) + str('.mat') 144 | mesh_points = load_Matlab_data(meshXY_file) 145 | XY_points = mesh_points['meshXY'] 146 | shape2XY = np.shape(XY_points) 147 | assert (len(shape2XY) == 2) 148 | if shape2XY[0] == 2: 149 | xy_data = np.transpose(XY_points, (1, 0)) 150 | else: 151 | xy_data = XY_points 152 | 153 | if to_float: 154 | xy_data = xy_data.astype(np.float32) 155 | 156 | if to_torch: 157 | xy_data = torch.from_numpy(xy_data) 158 | 159 | if to_cuda: 160 | xy_data = xy_data.cuda(device='cuda:' + str(gpu_no)) 161 | 162 | xy_data.requires_grad = use_grad2x 163 | return xy_data 164 | 165 | 166 | def get_meshdata2Convection(equation_name=None, mesh_number=2, to_torch=False, to_float=True, to_cuda=False, 167 | gpu_no=0, use_grad2x=False): 168 | if equation_name == 'multi_scale2D_1': 169 | meshXY_file = '../dataMat2pLaplace/E1/' + str('meshXY') + str(mesh_number) + str('.mat') 170 | elif equation_name == 'multi_scale2D_2': 171 | meshXY_file = '../dataMat2pLaplace/E2/' + str('meshXY') + str(mesh_number) + str('.mat') 172 | elif equation_name == 'multi_scale2D_3': 173 | meshXY_file = '../dataMat2pLaplace/E3/' + str('meshXY') + str(mesh_number) + str('.mat') 174 | elif equation_name == 'multi_scale2D_4': 175 | meshXY_file = '../dataMat2pLaplace/E4/' + str('meshXY') + str(mesh_number) + str('.mat') 176 | elif equation_name == 'multi_scale2D_5': 177 | meshXY_file = '../dataMat2pLaplace/E5/' + str('meshXY') + str(mesh_number) + str('.mat') 178 | elif equation_name == 'multi_scale2D_6': 179 | meshXY_file = '../dataMat2pLaplace/E6/' + str('meshXY') + str(mesh_number) + str('.mat') 180 | mesh_points = load_Matlab_data(meshXY_file) 181 | XY_points = mesh_points['meshXY'] 182 | shape2XY = np.shape(XY_points) 183 | assert (len(shape2XY) == 2) 184 | if shape2XY[0] == 2: 185 | xy_data = np.transpose(XY_points, (1, 0)) 186 | else: 187 | xy_data = XY_points 188 | 189 | if to_float: 190 | xy_data = xy_data.astype(np.float32) 191 | 192 | if to_torch: 193 | xy_data = torch.from_numpy(xy_data) 194 | 195 | if to_cuda: 196 | xy_data = xy_data.cuda(device='cuda:' + str(gpu_no)) 197 | 198 | xy_data.requires_grad = use_grad2x 199 | return xy_data 200 | 201 | 202 | if __name__ == '__main__': 203 | mat_data_path = '../dataMat_highDim' 204 | mat_data = get_randomData2mat(dim=2, data_path=mat_data_path) 205 | print('end!!!!') -------------------------------------------------------------------------------- /utilizers/RFN_Log_Print.py: -------------------------------------------------------------------------------- 1 | from utilizers import DNN_tools 2 | 3 | 4 | def dictionary_out2file(R_dic, log_fileout): 5 | # ----------------------------------------------------------------------------------------------------------------- 6 | DNN_tools.log_string('PDE type for problem: %s\n' % (R_dic['PDE_type']), log_fileout) 7 | DNN_tools.log_string('Equation name for problem: %s\n' % (R_dic['Equa_name']), log_fileout) 8 | 9 | # ----------------------------------------------------------------------------------------------------------------- 10 | DNN_tools.log_string('The model:%s\n' % str(R_dic['name2model']), log_fileout) 11 | DNN_tools.log_string('num to the unit of rfn basis:%s\n' % str(R_dic['rfn_hidden']), log_fileout) 12 | DNN_tools.log_string('Activate function for RFN basis: %s\n' % str(R_dic['act_name']), log_fileout) 13 | 14 | DNN_tools.log_string('Option for initializing the weights of RFN basis: %s\n' % str(R_dic['opt2initW']), log_fileout) 15 | DNN_tools.log_string('Option for initializing the weights of RFN basis: %s\n' % str(R_dic['opt2initB']), log_fileout) 16 | 17 | # ----------------------------------------------------------------------------------------------------------------- 18 | DNN_tools.log_string('Batch-size 2 interior: %s\n' % str(R_dic['point_num2inner']), log_fileout) 19 | DNN_tools.log_string('Batch-size 2 boundary: %s\n' % str(R_dic['point_num2boundary']), log_fileout) -------------------------------------------------------------------------------- /utilizers/__pycache__/DNN_tools.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/utilizers/__pycache__/DNN_tools.cpython-39.pyc -------------------------------------------------------------------------------- /utilizers/__pycache__/Load_data2Mat.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/utilizers/__pycache__/Load_data2Mat.cpython-39.pyc -------------------------------------------------------------------------------- /utilizers/__pycache__/RFN_Log_Print.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/utilizers/__pycache__/RFN_Log_Print.cpython-39.pyc -------------------------------------------------------------------------------- /utilizers/__pycache__/dataUtilizer2numpy.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/utilizers/__pycache__/dataUtilizer2numpy.cpython-39.pyc -------------------------------------------------------------------------------- /utilizers/__pycache__/plot_data.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/utilizers/__pycache__/plot_data.cpython-39.pyc -------------------------------------------------------------------------------- /utilizers/__pycache__/saveData.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blue-Giant/PIELM_Numpy/d4c5322d4a239817417467c09122366bc9308e44/utilizers/__pycache__/saveData.cpython-39.pyc -------------------------------------------------------------------------------- /utilizers/plot_data.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | from mpl_toolkits.axes_grid1.inset_locator import mark_inset 3 | from mpl_toolkits.axes_grid1.inset_locator import inset_axes 4 | from matplotlib.patches import ConnectionPatch 5 | import matplotlib.cm as cm 6 | from mpl_toolkits.mplot3d import Axes3D 7 | import numpy as np 8 | from utilizers import DNN_tools 9 | 10 | 11 | def plot_solu_1D(solu=None, coords=None, color='m', actName='diff', outPath=None): 12 | fig11 = plt.figure(figsize=(9, 6.5)) 13 | ax = plt.gca() 14 | ax.plot(coords, solu, color=color, linestyle='dotted', label=actName) 15 | # box = ax.get_position() 16 | # ax.set_position([box.x0, box.y0, box.width, box.height * 0.8]) 17 | ax.legend(loc='right', bbox_to_anchor=(0.9, 1.05), ncol=4, fontsize=12) 18 | ax.set_xlabel('x', fontsize=14) 19 | ax.set_ylabel('u', fontsize=14) 20 | fntmp = '%s/solus2%s' % (outPath, actName) 21 | DNN_tools.mySaveFig(plt, fntmp, ax=ax, isax=1, iseps=0) 22 | 23 | 24 | def plot_2solus_1D(exact_solu=None, nn_solu=None, coords=None, batch_size=1000, outPath=None, subfig_type=1): 25 | if subfig_type == 1: 26 | plt.figure(figsize=(16, 10), dpi=98) 27 | fig, ax = plt.subplots(1, 1) # fig, ax = plt.subplots(a,b)用来控制子图个数:a为行数,b为列数。 28 | ax.plot(coords, exact_solu, 'b-.', label='exact') 29 | ax.plot(coords, nn_solu, 'g:', label='nn') 30 | ax.legend(fontsize=10) 31 | ax.set_xlabel('x', fontsize=18) 32 | 33 | axins = inset_axes(ax, width="50%", height="40%", loc=8, bbox_to_anchor=(0.2, 0.4, 0.5, 0.5), 34 | bbox_transform=ax.transAxes) 35 | 36 | # 在子坐标系中绘制原始数据 37 | axins.plot(coords, exact_solu, color='b', linestyle='-.') 38 | 39 | axins.plot(coords, nn_solu, color='g', linestyle=':') 40 | 41 | axins.set_xticks([]) 42 | axins.set_yticks([]) 43 | 44 | # 设置放大区间 45 | zone_left = int(0.4 * batch_size) 46 | zone_right = int(0.4 * batch_size) + 100 47 | 48 | # 坐标轴的扩展比例(根据实际数据调整) 49 | x_ratio = 0.0 # x轴显示范围的扩展比例 50 | y_ratio = 0.075 # y轴显示范围的扩展比例 51 | 52 | # X轴的显示范围 53 | xlim0 = coords[zone_left] - (coords[zone_right] - coords[zone_left]) * x_ratio 54 | xlim1 = coords[zone_right] + (coords[zone_right] - coords[zone_left]) * x_ratio 55 | 56 | # Y轴的显示范围 57 | y = np.hstack((exact_solu[zone_left:zone_right], nn_solu[zone_left:zone_right])) 58 | ylim0 = np.min(y) - (np.max(y) - np.min(y)) * y_ratio 59 | ylim1 = np.max(y) + (np.max(y) - np.min(y)) * y_ratio 60 | 61 | # 调整子坐标系的显示范围 62 | axins.set_xlim(xlim0, xlim1) 63 | axins.set_ylim(ylim0, ylim1) 64 | 65 | # 建立父坐标系与子坐标系的连接线 66 | # loc1 loc2: 坐标系的四个角 67 | # 1 (右上) 2 (左上) 3(左下) 4(右下) 68 | mark_inset(ax, axins, loc1=3, loc2=1, fc="none", ec='k', lw=1) 69 | 70 | fntmp = '%s/solus2test' % (outPath) 71 | DNN_tools.mySaveFig(plt, fntmp, ax=ax, isax=1, iseps=0) 72 | elif subfig_type == 2: 73 | plt.figure(figsize=(16, 10), dpi=98) 74 | ax = plt.gca() 75 | p1 = plt.subplot(121) # 1行2列,第一个图 76 | p2 = plt.subplot(122) # 1行2列,第二个图 77 | 78 | p1.plot(coords, exact_solu, color='b', linestyle='-.', label='exact') 79 | p1.plot(coords, nn_solu, color='g', linestyle=':', label='nn') 80 | ax.legend(fontsize=10) 81 | 82 | p2.plot(coords, exact_solu, color='b', linestyle='-.', label='exact') 83 | p2.plot(coords, nn_solu, color='g', linestyle=':', label='nn') 84 | p2.axis([0.35, 0.65, 0.2, 0.27]) 85 | 86 | # plot the box of 87 | tx0 = 0.35 88 | tx1 = 0.65 89 | ty0 = 0.2 90 | ty1 = 0.27 91 | sx = [tx0, tx1, tx1, tx0, tx0] 92 | sy = [ty0, ty0, ty1, ty1, ty0] 93 | p1.plot(sx, sy, "purple") 94 | 95 | # plot patch lines 96 | xy = (0.64, 0.265) 97 | xy2 = (0.36, 0.265) 98 | con = ConnectionPatch(xyA=xy2, xyB=xy, coordsA="data", coordsB="data", axesA=p2, axesB=p1) 99 | p2.add_artist(con) 100 | 101 | xy = (0.64, 0.21) 102 | xy2 = (0.36, 0.205) 103 | con = ConnectionPatch(xyA=xy2, xyB=xy, coordsA="data", coordsB="data", 104 | axesA=p2, axesB=p1) 105 | p2.add_artist(con) 106 | 107 | fntmp = '%s/solus2test' % (outPath) 108 | DNN_tools.mySaveFig(plt, fntmp, ax=ax, isax=1, iseps=0) 109 | else: 110 | fig11 = plt.figure(figsize=(9, 6.5)) 111 | ax = plt.gca() 112 | ax.plot(coords, exact_solu, 'b-.', label='exact') 113 | ax.plot(coords, nn_solu, 'r:', label='nn') 114 | # box = ax.get_position() 115 | # ax.set_position([box.x0, box.y0, box.width, box.height * 0.8]) 116 | ax.legend(loc='right', bbox_to_anchor=(0.9, 1.05), ncol=4, fontsize=12) 117 | ax.set_xlabel('x', fontsize=14) 118 | ax.set_ylabel('u', fontsize=14) 119 | fntmp = '%s/solus2test' % (outPath) 120 | DNN_tools.mySaveFig(plt, fntmp, ax=ax, isax=1, iseps=0) 121 | 122 | 123 | def plot_scatter_solu(solu, test_batch, color='b', actName=None, outPath=None): 124 | test_x_bach = np.reshape(test_batch[:, 0], newshape=[-1, 1]) 125 | test_y_bach = np.reshape(test_batch[:, 1], newshape=[-1, 1]) 126 | 127 | # 绘制解的3D散点图 128 | fig = plt.figure(figsize=(6.5, 6.5)) 129 | ax = Axes3D(fig) 130 | ax.scatter(test_x_bach, test_y_bach, solu, c=color, label=actName) 131 | 132 | # 刻度值字体大小设置(x轴和y轴同时设置) 133 | plt.tick_params(labelsize=18) 134 | # 绘制图例 135 | ax.legend(loc='best', fontsize=16) 136 | # 添加坐标轴(顺序是X,Y, Z) 137 | ax.set_xlabel('X', fontdict={'size': 16, 'color': 'red'}) 138 | ax.set_ylabel('Y', fontdict={'size': 16, 'color': 'red'}) 139 | ax.set_zlabel('u', fontdict={'size': 16, 'color': 'red'}) 140 | 141 | # plt.title('solution', fontsize=15) 142 | fntmp = '%s/solus2%s' % (outPath, actName) 143 | DNN_tools.mySaveFig(plt, fntmp, ax=ax, isax=1, iseps=0) 144 | 145 | 146 | def plot_scatter_solus(solu1, solu2, test_batch, actName1=None, actName2=None, outPath=None): 147 | test_x_bach = np.reshape(test_batch[:, 0], newshape=[-1, 1]) 148 | test_y_bach = np.reshape(test_batch[:, 1], newshape=[-1, 1]) 149 | 150 | # 绘制解的3D散点图(真解和预测解) 151 | fig = plt.figure(figsize=(6.5, 6.5)) 152 | ax = Axes3D(fig) 153 | ax.scatter(test_x_bach, test_y_bach, solu1, c='b', label=actName1) 154 | ax.scatter(test_x_bach, test_y_bach, solu2, c='r', label=actName2) 155 | 156 | # 刻度值字体大小设置(x轴和y轴同时设置) 157 | plt.tick_params(labelsize=18) 158 | # 绘制图例 159 | ax.legend(loc='best', fontsize=16) 160 | # 添加坐标轴(顺序是X,Y, Z) 161 | ax.set_xlabel('X', fontdict={'size': 16, 'color': 'red'}) 162 | ax.set_ylabel('Y', fontdict={'size': 16, 'color': 'red'}) 163 | ax.set_zlabel('u', fontdict={'size': 16, 'color': 'red'}) 164 | 165 | # plt.title('solution', fontsize=15) 166 | fntmp = '%s/solus2%s' % (outPath, actName2) 167 | DNN_tools.mySaveFig(plt, fntmp, ax=ax, isax=1, iseps=0) 168 | -------------------------------------------------------------------------------- /utilizers/saveData.py: -------------------------------------------------------------------------------- 1 | """ 2 | @author: LXA 3 | Date: 2020 年 5 月 31 日 4 | """ 5 | import scipy.io as scio 6 | 7 | 8 | def save_trainLoss2mat_1actFunc(loss_it, loss_bd, loss, actName=None, outPath=None): 9 | # if actName == 's2ReLU': 10 | # outFile2data = '%s/Loss2s2ReLU.mat' % (outPath) 11 | # if actName == 'sReLU': 12 | # outFile2data = '%s/Loss2sReLU.mat' % (outPath) 13 | # if actName == 'ReLU': 14 | # outFile2data = '%s/Loss2ReLU.mat' % (outPath) 15 | outFile2data = '%s/Loss2%s.mat' % (outPath, actName) 16 | key2mat_1 = 'loss_it' 17 | key2mat_2 = 'loss_bd' 18 | key2mat_3 = 'loss' 19 | scio.savemat(outFile2data, {key2mat_1: loss_it, key2mat_2: loss_bd, key2mat_3: loss}) 20 | 21 | 22 | def save_trainLoss2mat_1act_Func(loss_it, loss_bd, loss_bdd, loss, actName=None, outPath=None): 23 | # if actName == 's2ReLU': 24 | # outFile2data = '%s/Loss2s2ReLU.mat' % (outPath) 25 | # if actName == 'sReLU': 26 | # outFile2data = '%s/Loss2sReLU.mat' % (outPath) 27 | # if actName == 'ReLU': 28 | # outFile2data = '%s/Loss2ReLU.mat' % (outPath) 29 | outFile2data = '%s/Loss2%s.mat' % (outPath, actName) 30 | key2mat_1 = 'loss_it' 31 | key2mat_2 = 'loss_bd' 32 | key2mat_3 = 'loss_bdd' 33 | key2mat_4 = 'loss' 34 | scio.savemat(outFile2data, {key2mat_1: loss_it, key2mat_2: loss_bd, key2mat_3: loss_bdd, key2mat_4: loss}) 35 | 36 | 37 | def save_trainLoss2mat_1actFunc_Dirichlet(loss_it, loss_bd, loss_bd2, loss_all, actName=None, outPath=None): 38 | # if actName == 's2ReLU': 39 | # outFile2data = '%s/Loss2s2ReLU.mat' % (outPath) 40 | # if actName == 'sReLU': 41 | # outFile2data = '%s/Loss2sReLU.mat' % (outPath) 42 | # if actName == 'ReLU': 43 | # outFile2data = '%s/Loss2ReLU.mat' % (outPath) 44 | outFile2data = '%s/Loss2%s.mat' % (outPath, actName) 45 | key2mat_1 = 'loss_it' 46 | key2mat_2 = 'loss_bd0' 47 | key2mat_4 = 'loss_bd2' 48 | key2mat_5 = 'loss' 49 | scio.savemat(outFile2data, {key2mat_1: loss_it, key2mat_2: loss_bd, key2mat_4: loss_bd2, key2mat_5: loss_all}) 50 | 51 | 52 | def save_trainLoss2mat_1actFunc_Navier(loss_U, loss_bd, loss_Psi, loss_bdd, loss, actName=None, outPath=None): 53 | # print('actName:', actName) 54 | # print('id of loss_it:', id(loss_U)) 55 | # print('values of loss_it:', loss_U) 56 | if str.lower(actName) == 's2relu': 57 | outFile2data = '%s/Loss_s2ReLU.mat' % (outPath) 58 | elif str.lower(actName) == 'srelu': 59 | outFile2data = '%s/Loss_sReLU.mat' % (outPath) 60 | elif str.lower(actName) == 'relu': 61 | outFile2data = '%s/Loss_ReLU.mat' % (outPath) 62 | else: 63 | outFile2data = '%s/Loss_%s.mat' % (outPath, str(actName)) 64 | 65 | # print('outFile2data:', outFile2data) 66 | 67 | key2mat_0 = 'lossU_%s' % (str(actName)) 68 | key2mat_1 = 'lossBD_%s' % (str(actName)) 69 | key2mat_2 = 'lossPsi_%s' % (str(actName)) 70 | key2mat_3 = 'lossBDD_%s' % (str(actName)) 71 | key2mat_4 = 'loss_%s' % (str(actName)) 72 | scio.savemat(outFile2data, {key2mat_0: loss_U, key2mat_1: loss_bd, key2mat_2: loss_Psi, key2mat_3: loss_bdd, key2mat_4: loss}) 73 | 74 | 75 | def save_train_MSE_REL2mat(Mse_data, Rel_data, actName=None, outPath=None): 76 | # if actName == 's2ReLU': 77 | # outFile2data = '%s/train_Err2s2ReLU.mat' % (outPath) 78 | # if actName == 'sReLU': 79 | # outFile2data = '%s/train_Err2sReLU.mat' % (outPath) 80 | # if actName == 'ReLU': 81 | # outFile2data = '%s/train_Err2ReLU.mat' % (outPath) 82 | outFile2data = '%s/Loss2%s.mat' % (outPath, actName) 83 | key2mat_1 = 'mse' 84 | key2mat_2 = 'rel' 85 | scio.savemat(outFile2data, {key2mat_1: Mse_data, key2mat_2: Rel_data}) 86 | 87 | 88 | def save_meshData2mat(data, dataName=None, mesh_number=4, outPath=None): 89 | outFile2data = '%s/%s%s.mat' % (outPath, dataName, mesh_number) 90 | key2mat = 'U%s' % (str.upper(dataName)) 91 | scio.savemat(outFile2data, {key2mat: data}) 92 | 93 | 94 | # 一个mat文件保存一种数据 95 | def save_testData_or_solus2mat(data, dataName=None, outPath=None): 96 | if str.lower(dataName) == 'testxy': 97 | outFile2data = '%s/testData2XY.mat' % (outPath) 98 | key2mat = 'Points2XY' 99 | elif str.lower(dataName) == 'testxyz': 100 | outFile2data = '%s/testData2XYZ.mat' % (outPath) 101 | key2mat = 'Points2XYZ' 102 | elif str.lower(dataName) == 'testxyzs': 103 | outFile2data = '%s/testData2XYZS.mat' % (outPath) 104 | key2mat = 'Points2XYZS' 105 | elif str.lower(dataName) == 'testxyzst': 106 | outFile2data = '%s/testData2XYZST.mat' % (outPath) 107 | key2mat = 'Points2XYZST' 108 | elif str.lower(dataName) == 'utrue': 109 | outFile2data = '%s/Utrue.mat' % (outPath) 110 | key2mat = 'Utrue' 111 | else: 112 | outFile2data = '%s/U%s.mat' % (outPath, dataName) 113 | key2mat = 'U%s' % (str.upper(dataName)) 114 | 115 | scio.savemat(outFile2data, {key2mat: data}) 116 | 117 | 118 | # 合并保存数据 119 | def save_2testSolus2mat(exact_solution, dnn_solution, actName=None, actName1=None, outPath=None): 120 | outFile2data = '%s/test_solus.mat' % (outPath) 121 | if str.lower(actName) == 'utrue': 122 | key2mat_1 = 'Utrue' 123 | key2mat_2 = 'U%s' % (actName1) 124 | scio.savemat(outFile2data, {key2mat_1: exact_solution, key2mat_2: dnn_solution}) 125 | 126 | 127 | # 合并保存数据 128 | def save_3testSolus2mat(exact_solution, solution2act1, solution2act2, actName='Utrue', actName1=None, actName2=None, 129 | outPath=None): 130 | outFile2data = '%s/solutions.mat' % (outPath) 131 | if str.lower(actName) == 'utrue': 132 | key2mat_1 = 'Utrue' 133 | key2mat_3 = 'U%s' % (actName1) 134 | key2mat_4 = 'U%s' % (actName2) 135 | scio.savemat(outFile2data, {key2mat_1: exact_solution, key2mat_3: solution2act1, key2mat_4: solution2act2}) 136 | 137 | 138 | # 合并保存数据 139 | def save_4testSolus2mat(exact_solution, solution2act1, solution2act2, solution2act3, actName='Utrue', actName1=None, 140 | actName2=None, actName3=None, outPath=None): 141 | outFile2data = '%s/solutions.mat' % (outPath) 142 | if str.lower(actName) == 'utrue': 143 | key2mat_1 = 'Utrue' 144 | key2mat_2 = 'U%s' % (actName1) 145 | key2mat_3 = 'U%s' % (actName2) 146 | key2mat_4 = 'U%s' % (actName3) 147 | scio.savemat(outFile2data, {key2mat_1: exact_solution, key2mat_2: solution2act1, key2mat_3: solution2act2, 148 | key2mat_4: solution2act3}) 149 | 150 | 151 | def save_testLoss2mat_1act_Func(loss_it, loss_bd, loss_bd2, loss, actName=None, outPath=None): 152 | # if actName == 's2ReLU': 153 | # outFile2data = '%s/Loss2s2ReLU.mat' % (outPath) 154 | # if actName == 'sReLU': 155 | # outFile2data = '%s/Loss2sReLU.mat' % (outPath) 156 | # if actName == 'ReLU': 157 | # outFile2data = '%s/Loss2ReLU.mat' % (outPath) 158 | outFile2data = '%s/Loss2%s.mat' % (outPath, actName) 159 | key2mat_1 = 'loss_it' 160 | key2mat_2 = 'loss_bd0' 161 | key2mat_3 = 'loss_bd2' 162 | key2mat_4 = 'loss' 163 | scio.savemat(outFile2data, {key2mat_1: loss_it, key2mat_2: loss_bd, key2mat_3: loss_bd2, key2mat_4: loss}) 164 | 165 | 166 | def save_testMSE_REL2mat(Mse_data, Rel_data, actName=None, outPath=None): 167 | # if actName == 's2ReLU': 168 | # outFile2data = '%s/test_Err2s2ReLU.mat' % (outPath) 169 | # if actName == 'sReLU': 170 | # outFile2data = '%s/test_Err2sReLU.mat' % (outPath) 171 | # if actName == 'ReLU': 172 | # outFile2data = '%s/test_Err2ReLU.mat' % (outPath) 173 | outFile2data = '%s/test_Err2%s.mat' % (outPath, actName) 174 | key2mat_1 = 'mse' 175 | key2mat_2 = 'rel' 176 | scio.savemat(outFile2data, {key2mat_1: Mse_data, key2mat_2: Rel_data}) 177 | 178 | 179 | # 按误差类别保存,MSE和REL 180 | def save_testErrors2mat(err_sReLU, err_s2ReLU, errName=None, outPath=None): 181 | if str.upper(errName) == 'MSE': 182 | outFile2data = '%s/MSE.mat' % (outPath) 183 | key2mat_1 = 'mse2sReLU' 184 | key2mat_2 = 'mse2s2ReLU' 185 | scio.savemat(outFile2data, {key2mat_1: err_sReLU, key2mat_2: err_s2ReLU}) 186 | elif str.upper(errName) == 'REL': 187 | outFile2data = '%s/REL.mat' % (outPath) 188 | key2mat_1 = 'rel2sReLU' 189 | key2mat_2 = 'rel2s2ReLU' 190 | scio.savemat(outFile2data, {key2mat_1: err_sReLU, key2mat_2: err_s2ReLU}) 191 | 192 | 193 | def save_test_point_wise_err2mat(data2point_wise_err, actName=None, outPath=None): 194 | if str.lower(actName) == 'srelu': 195 | outFile2data = '%s/pERR2sReLU.mat' % (outPath) 196 | key2mat = 'pERR2sReLU' 197 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 198 | elif str.lower(actName) == 's2relu': 199 | outFile2data = '%s/pERR2s2ReLU.mat' % (outPath) 200 | key2mat = 'pERR2s2ReLU' 201 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 202 | elif str.lower(actName) == 's3relu': 203 | outFile2data = '%s/pERR2s3ReLU.mat' % (outPath) 204 | key2mat = 'pERR2smReLU' 205 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 206 | elif str.lower(actName) == 'csrelu': 207 | outFile2data = '%s/pERR2CsReLU.mat' % (outPath) 208 | key2mat = 'pERR2CsReLU' 209 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 210 | elif str.lower(actName) == 'relu': 211 | outFile2data = '%s/pERR2ReLU.mat' % (outPath) 212 | key2mat = 'pERR2ReLU' 213 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 214 | elif str.lower(actName) == 'sin': 215 | outFile2data = '%s/pERR2Sin.mat' % (outPath) 216 | key2mat = 'pERR2Sin' 217 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 218 | elif str.lower(actName) == 'powsin_srelu': 219 | outFile2data = '%s/pERR2p2SinSrelu.mat' % (outPath) 220 | key2mat = 'pERR2p2SinSrelu' 221 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 222 | elif str.lower(actName) == 'tanh': 223 | outFile2data = '%s/pERR2tanh.mat' % (outPath) 224 | key2mat = 'pERR2tanh' 225 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 226 | elif str.lower(actName) == 'elu': 227 | outFile2data = '%s/pERR2elu.mat' % (outPath) 228 | key2mat = 'pERR2elu' 229 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 230 | elif str.lower(actName) == 'singauss': 231 | outFile2data = '%s/pERR2sgauss.mat' % (outPath) 232 | key2mat = 'pERR2sgauss' 233 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 234 | elif str.lower(actName) == 'modify_mexican': 235 | outFile2data = '%s/pERR2mmexican.mat' % (outPath) 236 | key2mat = 'pERR2sgauss' 237 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 238 | elif str.lower(actName) == 'sin_modify_mexican': 239 | outFile2data = '%s/pERR2sm-mexican.mat' % (outPath) 240 | key2mat = 'pERR2sgauss' 241 | scio.savemat(outFile2data, {key2mat: data2point_wise_err}) 242 | 243 | 244 | def save_run_time2mat(run_time=0.01, num2hidden=1000, outPath=None): 245 | outFile2data = '%s/runTime_%s.mat' % (outPath, str(num2hidden)) 246 | key2mat = 'time' 247 | key_hidden = 'basis' 248 | scio.savemat(outFile2data, {key2mat: run_time, key_hidden: num2hidden}) 249 | 250 | 251 | def save_max_rel2mat(max_err=0.01, rel_err=0.01, num2hidden=1000, outPath=None): 252 | outFile2data = '%s/Errors_%s.mat' % (outPath, str(num2hidden)) 253 | key2max = 'max' 254 | key2rel = 'rel' 255 | key2hidden = 'basis' 256 | scio.savemat(outFile2data, {key2max: max_err, key2rel: rel_err, key2hidden: num2hidden}) --------------------------------------------------------------------------------