Skip to content

Commit 760a4b8

Browse files
committed
WIP(cgraph):add linear_elasticity_eigen_3d_example
1 parent 8f8562b commit 760a4b8

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

example/cgraph/linear_elasticity_eigen_3d_example.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@
44
WORLD_GRAPH = cgraph.WORLD_GRAPH
55

66
pde = cgraph.create("LinearElasticityEigen3d") # PDE 数据(示例)
7-
mesher = cgraph.create("uniform_tet") # 网格生成
8-
spacer = cgraph.create("FunctionSpace") # 函数空间节点
7+
mesher = cgraph.create("Box3d") # 网格生成
8+
spacer = cgraph.create("TensorFunctionSpace") # 函数空间节点
99
isDDof = cgraph.create("BoundaryDof")
1010
eig_eq = cgraph.create("LinearElasticityEigenEquation")
1111
eigensolver = cgraph.create("EigenSolver")
1212
dbc = cgraph.create("DirichletBC")
1313

14-
spacer(mesh=mesher(), p=1)
14+
spacer(mesh=mesher(), p=1,gd=3)
1515

1616
eig_eq(space=spacer(), q=3, material = pde().material, displacement_bc = pde().displacement_bc, is_displacement_boundary = pde().is_displacement_boundary)
1717

1818
eigensolver(
19-
S=eig_eq().S,
20-
M=eig_eq().M,
21-
space=spacer(),
22-
19+
S=eig_eq().stiffness,
20+
M=eig_eq().mass,
2321
neigen=6,
2422
which='SM'
2523
)
2624

27-
# 输出:把网格和第一个模态输出到 WORLD_GRAPH
28-
WORLD_GRAPH.output(mesh=mesher(), uh=eigensolver().modes[0])
29-
WORLD_GRAPH.register_error_hook(print)
25+
WORLD_GRAPH.output(eig_eq=eigensolver().val, uh=eigensolver().vec)
26+
WORLD_GRAPH.error_listeners.append(print)
3027
WORLD_GRAPH.execute()
31-
print(WORLD_GRAPH.get())
28+
print(WORLD_GRAPH.get())

fealpy/cgraph/fem/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
from .timoaxle import *
99
from .truss import *
1010
from .beam import *
11+
from .linear_elasticity_eigen import *

fealpy/cgraph/fem/linear_elasticity_eigen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LinearElasticityEigenEquation(CNodeType):
99
INPUT_SLOTS = [
1010
PortConf("space", DataType.SPACE, "函数空间"),
1111
PortConf("q", DataType.INT, title="积分公式", default=3, min_val=1, max_val=17),
12-
PortConf("material", DataType.OBJECT, title="材料属性"),
12+
PortConf("material", DataType.MENU, title="材料属性"),
1313
PortConf("displacement_bc", DataType.FUNCTION, title="位移边界条件函数"),
1414
PortConf("is_displacement_boundary", DataType.FUNCTION, title="位移边界标识函数"),
1515
]
@@ -25,7 +25,7 @@ def run(space, q: int, material, displacement_bc, is_displacement_boundary):
2525
from ...fem import LinearElasticityIntegrator
2626
from ...fem import ScalarMassIntegrator as MassIntegrator
2727
from ...fem import DirichletBC
28-
from ...backend import backend as bm
28+
from ...backend import backend_manager as bm
2929

3030

3131
bform_S = BilinearForm(space)

fealpy/cgraph/model/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
from .incompressible_navier_stokes2d import IncompressibleCylinder2d
1010
from .dipole_antenna3d import DipoleAntenna3D
1111
from .beam2d import Beam2d
12+
from .linear_elasticity_eigen3d import LinearElasticityEigen3d

fealpy/cgraph/model/linear_elasticity_eigen3d.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ class LinearElasticityEigen3d(CNodeType):
77
OUTPUT_SLOTS = [
88
PortConf("domain", DataType.NONE),
99
PortConf("material", DataType.NONE),
10-
PortConf("displacement", DataType.FUNCTION),
11-
PortConf("body_force", DataType.FUNCTION),
1210
PortConf("displacement_bc", DataType.FUNCTION),
1311
PortConf("is_displacement_boundary", DataType.FUNCTION),
1412
]
@@ -20,7 +18,7 @@ def run():
2018
model = CSMModelManager("linear_elasticity").get_example(1)
2119
return (domain, model.material)+ tuple(
2220
getattr(model, name)
23-
for name in ["displacement", "displacement_bc"]
21+
for name in [ "displacement_bc", "is_displacement_boundary"]
2422
)
2523

2624

fealpy/cgraph/solver.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,31 @@ def run(*args, **kwargs):
9090
mgr.set_matrix(A)
9191
mgr.set_tolerances(rtol=rtol, atol=atol, maxit=maxit)
9292
x = mgr.solve(b)
93-
return x
93+
return x
94+
95+
from .nodetype import CNodeType, PortConf, DataType
96+
97+
__all__ = ["EigenSolver"]
98+
99+
class EigenSolver(CNodeType):
100+
TITLE: str = "特征值求解器"
101+
PATH: str = "解法器.特征值"
102+
INPUT_SLOTS = [
103+
PortConf("S", DataType.TENSOR, title="刚度矩阵 S"),
104+
PortConf("M", DataType.TENSOR, title="质量矩阵 M"),
105+
PortConf("neigen", DataType.INT, title="求取的特征值个数", default=6, min_val=1),
106+
PortConf("which", DataType.STRING, title="eigsh which", default='SM'),
107+
]
108+
OUTPUT_SLOTS = [
109+
PortConf("val", DataType.TENSOR, title="特征值"),
110+
PortConf("vec", DataType.TENSOR, title="特征向量"),
111+
]
112+
113+
@staticmethod
114+
def run(*args, **kwargs):
115+
from scipy.sparse.linalg import eigsh
116+
S = kwargs.get('S')
117+
M = kwargs.get('M')
118+
neigen = kwargs.get('neigen')
119+
val, vec = eigsh(S, k=neigen, M=M, which=kwargs.get('which', 'SM'), tol=1e-6, maxiter=1000)
120+
return val, vec

0 commit comments

Comments
 (0)