Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapMP #12

Open
wants to merge 179 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
77f60c2
added routine to check if 2 KnotVectors are refined of each other. ad…
May 30, 2022
17da154
added flip option for Boundary functions to evaluate on flipped grids…
May 30, 2022
06dcd9a
added grid evaluation for (not yet outer) normal vector for BsplineFu…
May 31, 2022
d82c54a
update
May 31, 2022
64c793f
update
Jun 3, 2022
fbf4613
update
Jun 13, 2022
8a54c42
added convenience functions
Jun 20, 2022
6991537
added flip for boundary
Jun 20, 2022
e861fd3
Merge branch 'adapMP' of github.com:Stefan714/pyiga into adapMP
Jun 20, 2022
9499b3f
added NewMultipatch
Jun 20, 2022
009d0c5
added patchmesh
Jun 20, 2022
0bf2105
added option for multiplicity + refinement for it.
Jun 26, 2022
310c0fb
added refinenment option for uniform refinement with higher
Jun 26, 2022
5f71d7b
added prolongation routine for Tensor product splines
Jul 7, 2022
35390a5
update for split_patches to return ALL the new patches emerging from …
Jul 7, 2022
67c49cd
update
Jul 7, 2022
52b5482
update
Jul 15, 2022
df11828
changed input format for split_patches
Jul 15, 2022
6ef7699
changed corner_dof to corner_dofs for multiple dofs belonging to a sp…
Jul 15, 2022
b1ab5ec
update
Jul 22, 2022
70123d3
moved split_dirichlet_data to Multipatch class
Jul 22, 2022
1dcd665
auxiliary binary tree class to characterize segments of a 2D boundary
Aug 23, 2022
651b604
patchmesh class for 3D
Aug 23, 2022
6a00392
added rotate_3d function to rotate geometry around a line generted by…
Sep 5, 2022
7b4ee71
added rotate_3d function for BSplineFunc
Sep 6, 2022
476f350
added routine to visualize 3D geometries and some minor updates to al…
Sep 12, 2022
6ffcba8
updated corners function
Sep 16, 2022
dcab660
updated corners function and added a function to return local edges o…
Sep 16, 2022
063f56b
update
Sep 28, 2022
4b4e661
update
Sep 28, 2022
787f9f4
dded rotation routine
Sep 28, 2022
907c4f1
update
Sep 28, 2022
fef5d47
update
Sep 28, 2022
195b340
update
Sep 28, 2022
4d121a0
added Neumann and Robin assembler routines to Multipatch.assemble_system
Nov 8, 2022
dd1e884
slightly changed to work with the changes made to the Multipatch class.
Nov 8, 2022
213f4d8
added new boundary format to functions
Nov 18, 2022
35c7642
added new boundary format to functions
Nov 18, 2022
4b2852e
added new boundary format to functions
Nov 18, 2022
e69ed61
added new boundary format and corner info to class
Nov 18, 2022
ac1f21d
added new boundary format and corner/edge info to class
Nov 18, 2022
bee1b90
update
Jan 3, 2023
c9e8feb
update
Jan 3, 2023
acd0b66
added Test
Jan 3, 2023
e28933d
added
Jan 3, 2023
aeb73a9
update
Jan 3, 2023
1e9a27b
update
Jan 3, 2023
885c7b3
function to get (nice?) basis for nullspace of matrix
stefantakacs Jan 4, 2023
e0c09b6
Merge branch 'adapMP' of https://github.com/Stefan714/pyiga into adapMP
stefantakacs Jan 4, 2023
92d3e57
new
Jan 13, 2023
b079ec2
Merge branch 'c-f-h:master' into adapMP
Stefan714 Jan 13, 2023
1e534c0
added example
Jan 20, 2023
4cf00e6
added vforms for boundary integrals in order to assemble Robin/Neumann
Feb 2, 2023
87463a6
minor changes
Feb 2, 2023
0f2a9eb
minor changes
Feb 2, 2023
82d8687
update
Feb 2, 2023
af2430f
update boundary vforms
Feb 3, 2023
742a83a
added PatchMesh to file
Feb 3, 2023
14e0499
changed Multipatch class to work with PatchMesh
Feb 3, 2023
04a60bd
update
Feb 3, 2023
d8431f7
changed in order to work with PatchMesh
Feb 3, 2023
e3889e8
example notebook for testing algebraic approach.
Feb 9, 2023
3bd5323
update
Feb 14, 2023
ac58a87
update
Feb 14, 2023
3c6caff
update
Feb 15, 2023
d913f6a
test for basis construction
stefantakacs Feb 15, 2023
de457e1
Merge branch 'adapMP' of https://github.com/Stefan714/pyiga into adapMP
stefantakacs Feb 15, 2023
4e443fb
also 3D
stefantakacs Feb 15, 2023
f91cead
update
Feb 21, 2023
bd69342
update
Mar 3, 2023
760cd18
update
Mar 3, 2023
119665d
modified pruning parameter
Mar 3, 2023
18b06b3
update
Mar 3, 2023
c8b66e3
update
Mar 3, 2023
7d5992f
update
Mar 6, 2023
de90a59
update
Mar 6, 2023
9e4c9f2
update
Mar 10, 2023
d7ad5b7
update
Mar 10, 2023
c4d0413
update
Mar 13, 2023
176d2ca
aenderungen
stefantakacs Mar 13, 2023
50fd4d9
update
Apr 6, 2023
577a5b7
update
Apr 6, 2023
21a8646
update
Apr 6, 2023
ef3065a
update
Apr 6, 2023
274c917
update
Apr 6, 2023
45977c4
update
Apr 6, 2023
b6c6929
update
Apr 17, 2023
0c7a2c2
added Test file
May 1, 2023
5649829
Merge branch 'adapMP' of github.com:Stefan714/pyiga into adapMP
May 1, 2023
77cd24d
update
May 1, 2023
a09f176
update
May 2, 2023
27f939c
update
May 2, 2023
39ef747
fix Test.ipynb
stefantakacs May 2, 2023
44e7ac8
update
May 25, 2023
0600f44
update
May 25, 2023
11a3481
update
May 25, 2023
51cbd5e
update
May 25, 2023
5df8564
update
May 25, 2023
881cdd0
update
May 25, 2023
db4159d
update
May 25, 2023
cb10d78
update
May 26, 2023
22e5f21
update
May 26, 2023
59da30f
update
Jun 16, 2023
b62f630
update
Oct 4, 2023
34be5af
update
Oct 4, 2023
84abf75
update
Oct 4, 2023
adcffb2
update
Oct 4, 2023
e80db41
update
Oct 4, 2023
f33402f
update
Oct 4, 2023
419dc9f
update
Oct 6, 2023
80d683a
update
Jan 16, 2024
2915296
update
Jan 16, 2024
d0161cc
update
Jan 16, 2024
02796a4
update
Jan 25, 2024
980f280
update
Jan 26, 2024
6b33dc2
update
Jan 29, 2024
22b5e45
update
Feb 6, 2024
687ab9c
update
Feb 9, 2024
691d165
update
Feb 14, 2024
f22a271
update
Feb 15, 2024
86585aa
update
Feb 16, 2024
732d4b5
update
Feb 23, 2024
a2d815d
update
Feb 28, 2024
bc75877
update
Mar 6, 2024
5c10c01
update
Mar 6, 2024
3cd2c11
update
Mar 14, 2024
2bee9ae
update
Mar 18, 2024
fd868b0
update
Mar 20, 2024
a2baae2
update
Mar 22, 2024
262bc83
update
Mar 25, 2024
91420e8
update
Mar 26, 2024
c887a6d
update
Mar 26, 2024
cba66e0
update
Mar 28, 2024
1a2dc6a
update
Apr 2, 2024
9058ccf
update
Apr 3, 2024
e6eb7c0
update
Apr 5, 2024
cb1fe51
update
Apr 8, 2024
1da1385
update
Apr 10, 2024
317a985
update
Apr 11, 2024
a50fed6
update
Apr 12, 2024
ae865f1
update
Apr 14, 2024
e841aa3
update
Apr 17, 2024
c755e83
update
Apr 19, 2024
c5099d2
update
Apr 22, 2024
d2dfa41
update
Apr 23, 2024
d58a5dd
update
Apr 25, 2024
a9952ac
update
Apr 26, 2024
e773f3f
update
May 3, 2024
9664dc6
update
May 5, 2024
671ba57
update
May 24, 2024
d8a0501
update
May 25, 2024
18b0a19
update
May 27, 2024
ef1e5ac
update
May 28, 2024
b8b8d97
added class for realizing Lanczos matrices in order to estimate the c…
Jun 18, 2024
7c5ac18
update
Jun 25, 2024
7100c5c
added cythonized version for the basis algorithm
Jul 4, 2024
a573680
update
Jul 4, 2024
9aad28d
update
Jul 13, 2024
5d974ee
update
Stefan714 Jul 13, 2024
191daa4
update
Jul 17, 2024
a336a76
update
Jul 22, 2024
fd0c23c
update
Jul 24, 2024
905e023
update
Jul 25, 2024
167cd02
update
Jul 26, 2024
27eee83
update
Jul 29, 2024
b1ef8f2
update
Aug 1, 2024
54da64e
update
Aug 7, 2024
0bd092c
update
Oct 15, 2024
998f5fb
Merge branch 'master' into adapMP
Oct 15, 2024
ae028cf
xRevert "Merge branch 'master' into adapMP"
Oct 16, 2024
5ff9fc1
update working
Oct 22, 2024
7466c30
added Reduced Basis example, added routine to compute maximal points …
Oct 23, 2024
2cbec9b
update
Oct 24, 2024
d3d519b
update
Oct 24, 2024
3a5f42c
update
Oct 24, 2024
6699d27
update
Oct 24, 2024
a3a0404
update
Oct 28, 2024
ea01978
update
Nov 22, 2024
2ed2c96
update
Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
337 changes: 337 additions & 0 deletions notebooks/2D_curl.ipynb

Large diffs are not rendered by default.

610 changes: 610 additions & 0 deletions notebooks/3D_Inductance.ipynb

Large diffs are not rendered by default.

2,539 changes: 2,539 additions & 0 deletions notebooks/IETI.ipynb

Large diffs are not rendered by default.

340 changes: 340 additions & 0 deletions notebooks/IGA_FEM.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,340 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8ba4e535-7510-4e12-bf36-f9d5e9ee2ed9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"%pylab inline\n",
"import numpy as np\n",
"import scipy\n",
"import math\n",
"import time\n",
"from scipy.sparse.linalg import onenormest, splu, LinearOperator\n",
"from scipy.sparse import coo_matrix, block_diag, identity, hstack\n",
"import matplotlib.pyplot as plt\n",
"from pyiga import assemble, bspline, vform, geometry, vis, solvers, utils, topology\n",
"#from patchmesh import *\n",
"#from sksparse.cholmod import cholesky\n",
"#from patchmesh3D import *\n",
"#from multipatch import *\n",
"\n",
"np.set_printoptions(linewidth=100000)\n",
"np.set_printoptions(precision=2)\n",
"np.set_printoptions(formatter={'float': lambda x: \"{0: 0.3f}\".format(x) if x>=0 else \"{0:0.3f}\".format(x)})"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "4c225d79-ee4e-4581-80b1-0927872fc136",
"metadata": {},
"outputs": [],
"source": [
"def condest(A):\n",
" luA = splu(A)\n",
" iA = LinearOperator(luA.shape, matvec = lambda x : luA.solve(x), rmatvec = lambda x : luA.solve(x))\n",
" return onenormest(iA)*onenormest(A)\n",
"\n",
"def pcg(Afuns, f, tol = 1e-5, maxit = 100, pfuns = 1, output = False): \n",
" maxit = int(maxit)\n",
" if not callable(pfuns):\n",
" pfun = lambda x : x\n",
" # splu_pfun = sp.linalg.splu(pfuns,permc_spec='COLAMD')\n",
" # pfun = lambda x : splu_pfun.solve(x)\n",
" else:\n",
" pfun = pfuns\n",
" if not callable(Afuns):\n",
" Afun = lambda x : Afuns@x\n",
" else:\n",
" Afun = Afuns\n",
" if not isinstance(f,np.ndarray):\n",
" d = f.A.ravel()\n",
" else:\n",
" d = f.ravel() \n",
" # print('Cond about',condest(pfuns@Afuns))\n",
" w = pfun(d)\n",
" rho = w@d\n",
" err0 = np.sqrt(rho)\n",
" s = w\n",
" u = 0*d.copy()\n",
" for it in range(maxit):\n",
" As = Afun(s)\n",
" alpha = rho/(As@s)\n",
" u = u + alpha*s\n",
" d = d - alpha*As\n",
" w = pfun(d)\n",
" rho1 = rho\n",
" rho = w@d\n",
" err = np.sqrt(rho)\n",
" if err < tol*err0:\n",
" break\n",
" beta = rho/rho1\n",
" s = w + beta*s\n",
" if output:\n",
" print('pcg stopped after ' + str(it) + ' iterations with relres ' + str(err/err0))\n",
" return u,it,d"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "bc18c467-f277-4911-83bb-b72191d569e0",
"metadata": {},
"outputs": [],
"source": [
"def refine(kvs, mult=1):\n",
" return tuple(kv.h_refine(mult=mult) for kv in kvs)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "5818aac7-8be0-4c6c-a359-01f4c9085b08",
"metadata": {},
"outputs": [],
"source": [
"u = lambda x,y: exp(x**2+y**2)\n",
"f = lambda x,y: -4*(x**2+y**2+1)*exp(x**2+y**2)\n",
"geo=geometry.unit_square()\n",
"maxiter=8\n",
"degree = (1,2,3,4)\n",
"numdofs, assembly_t, nnz, nnzq, nnzL, nnzLq, cond, cg_it = np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter)\n",
"\n",
"for p in degree:\n",
" kvs = 2*(bspline.make_knots(p,0.0,1.0,2),)\n",
" for i in range(maxiter):\n",
" numdofs[(p-1)*maxiter+i]=np.prod([kv.numdofs for kv in kvs])\n",
" t=time.time()\n",
" Ah = assemble.stiffness(kvs, geo)\n",
" Fh = assemble.inner_products(kvs, f, f_physical=True, geo=geo).ravel()\n",
" assembly_t[(p-1)*maxiter+i]=time.time()-t\n",
" nnz[(p-1)*maxiter+i]=Ah.nnz#/np.prod(Ah.shape)\n",
" nnzq[(p-1)*maxiter+i]=100*Ah.nnz/np.prod(Ah.shape)\n",
" \n",
" bcs = assemble.compute_dirichlet_bcs(kvs, geo, [('bottom', u), ('top', u), ('left', u), ('right', u)])\n",
" LS = assemble.RestrictedLinearSystem(Ah, Fh, bcs)\n",
" solver = scipy.sparse.linalg.splu(LS.A)\n",
" nnzL[(p-1)*maxiter+i] = solver.L.nnz#/np.prod(solver.L.shape)\n",
" nnzLq[(p-1)*maxiter+i] = 100*solver.L.nnz/np.prod(solver.L.shape)\n",
" cond[(p-1)*maxiter+i] = condest(LS.A)\n",
" _, it, _ = pcg(LS.A,LS.b,maxit=1000)\n",
" cg_it[(p-1)*maxiter+i] = it\n",
" #bcs = assemble.compute_dirichlet_bcs(kvs, geo, [('bottom',0),('right',0),('left', 0), ('top', 0)])\n",
" if i!=maxiter-1:\n",
" kvs = refine(kvs)\n",
"np.savetxt('Iga.txt',np.c_[numdofs, assembly_t, nnz, nnzq, nnzL, nnzLq, cond, cg_it], fmt=('%d', '%1.3f','%d','%1.3f','%d','%1.3f', '%1.3e','%d'), delimiter = \" & \")"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "8366adbe-4051-4c5a-8ff4-2ac92a71fbcc",
"metadata": {},
"outputs": [],
"source": [
"numdofs, assembly_t, nnz, nnzL, cond, cg_it = np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter), np.zeros(len(degree)*maxiter)\n",
"\n",
"for p in degree:\n",
" kvs = 2*(bspline.make_knots(p,0.0,1.0,2,mult=p),)\n",
" for i in range(maxiter):\n",
" numdofs[(p-1)*maxiter+i]=np.prod([kv.numdofs for kv in kvs])\n",
" t=time.time()\n",
" Ah = assemble.stiffness(kvs, geo)\n",
" Fh = assemble.inner_products(kvs, f, f_physical=True, geo=geo).ravel()\n",
" assembly_t[(p-1)*maxiter+i]=time.time()-t\n",
" nnz[(p-1)*maxiter+i]=Ah.nnz#/np.prod(Ah.shape)\n",
" nnzq[(p-1)*maxiter+i]=100*Ah.nnz/np.prod(Ah.shape)\n",
" \n",
" bcs = assemble.compute_dirichlet_bcs(kvs, geo, [('bottom', u), ('top', u), ('left', u), ('right', u)])\n",
" LS = assemble.RestrictedLinearSystem(Ah, Fh, bcs)\n",
" solver = scipy.sparse.linalg.splu(LS.A)\n",
" nnzL[(p-1)*maxiter+i] = solver.L.nnz#/np.prod(solver.L.shape)\n",
" nnzLq[(p-1)*maxiter+i] = 100*solver.L.nnz/np.prod(solver.L.shape)\n",
" cond[(p-1)*maxiter+i] = condest(LS.A)\n",
" _, it, _ = pcg(LS.A,LS.b,maxit=1000)\n",
" cg_it[(p-1)*maxiter+i] = it\n",
" #bcs = assemble.compute_dirichlet_bcs(kvs, geo, [('bottom',0),('right',0),('left', 0), ('top', 0)])\n",
" if i!=maxiter-1:\n",
" kvs = refine(kvs,mult=p)\n",
"np.savetxt('FEM.txt',np.c_[numdofs, assembly_t, nnz, nnzq, nnzL, nnzLq, cond, cg_it], fmt=('%d', '%1.3f','%d','%1.3f','%d','%1.3f', '%1.3e','%d'), delimiter = \" & \")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8202037e-21ed-454b-af0d-bd3865d2c8eb",
"metadata": {},
"outputs": [],
"source": [
"Ah = assemble.stiffness(2*(bspline.make_knots(4,0.0,1.0,10,mult=1),), geo=geometry.unit_cube(2))"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "0a2037db-d24b-43ba-a344-d5bb80bfc058",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3e+00\n"
]
}
],
"source": [
"print(\"%1.0e\" % 300.0)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "cdad44ce-b26d-4212-92a5-061907ffdd81",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1191016\n",
"0.15817920254315804\n"
]
}
],
"source": [
"print(Ah.nnz)\n",
"print(Ah.nnz/(np.prod(Ah.shape)))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7fcfe66e-b2b6-411d-b316-87d16d7033a4",
"metadata": {},
"outputs": [],
"source": [
"Ah = assemble.stiffness(3*(bspline.make_knots(4,0.0,1.0,10,mult=4),), geo=geometry.unit_cube(3))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "bda47b3d-6cc3-4a32-a7b1-431e45a74fe1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"13997521\n",
"0.0029467818577920764\n"
]
}
],
"source": [
"print(Ah.nnz)\n",
"print(Ah.nnz/(np.prod(Ah.shape)))"
]
},
{
"cell_type": "code",
"execution_count": 181,
"id": "22410362-ccc5-42cf-9a13-0678d36bf407",
"metadata": {},
"outputs": [],
"source": [
"kvs = 2*(bspline.make_knots(2,0.0,1.0,3,mult=2),)"
]
},
{
"cell_type": "code",
"execution_count": 182,
"id": "ed4e1009-6731-406e-97e8-82eb5e0674ab",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 182,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"kvs[0].first_active_at(0.75)"
]
},
{
"cell_type": "code",
"execution_count": 184,
"id": "837f8a5d-12c2-4ca7-9e8f-a51f51f88e1a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 184,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"kvs[0].numdofs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "64e003d0-e5a1-4083-8fc8-c85b6564219c",
"metadata": {},
"outputs": [],
"source": [
"from scipy.sparse.linalg import onenormest, splu, LinearOperator\n",
"\n",
"def condest(A):\n",
" luA = splu(A)\n",
" iA = LinearOperator(luA.shape, matvec = lambda x : luA.solve(x), rmatvec = lambda x : luA.solve(x))\n",
" return onenormest(iA)*onenormest(A)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading