Skip to content

Commit 8ad7587

Browse files
authored
Merge pull request #1982 from Hukai0/draft/kyle
WIP(cgraph):add linear_elasticity_eigen_3d_example
2 parents 41ea5ed + 760a4b8 commit 8ad7587

File tree

245 files changed

+18527
-2163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+18527
-2163
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ tags
7575
.DS_Store
7676
*env
7777
tmp
78+
*.msh

docs/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ GEM
8585
rb-fsevent (0.11.0)
8686
rb-inotify (0.10.1)
8787
ffi (~> 1.0)
88-
rexml (3.3.9)
88+
rexml (3.4.2)
8989
rouge (3.26.0)
9090
safe_yaml (1.0.5)
9191
sassc (2.4.0)

example/cfd/bam_break.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from fealpy.backend import backend_manager as bm
2+
import matplotlib.pyplot as plt
3+
bm.set_backend("numpy")
4+
from fealpy.mesh.node_mesh import BamBreak
5+
from fealpy.cfd.simulation.sph.particle_solver_new import ParticleSystem, BamBreakSolver, Visualizer
6+
7+
dx = 0.03
8+
dy = 0.03
9+
maxstep = 2000
10+
11+
# 创建网格
12+
mesh = BamBreak.from_bam_break_domain(dx, dy)
13+
14+
# 创建粒子系统
15+
particle_system = ParticleSystem(dx, dy)
16+
particle_system.initialize_particles(mesh.node, mesh.nodedata)
17+
18+
# 创建SPH求解器
19+
sph_solver = BamBreakSolver(particle_system)
20+
21+
# 初始可视化
22+
color = bm.where(particle_system.particles["tag"], "red", "blue")
23+
plt.scatter(particle_system.particles["position"][:, 0],
24+
particle_system.particles["position"][:, 1],
25+
c=color, s=5)
26+
plt.grid(True)
27+
plt.show()
28+
29+
# 运行模拟
30+
sph_solver.run_simulation(maxstep, draw_interval=10, reinitalize_interval=30)
31+
32+
# 最终结果可视化
33+
visualizer = Visualizer(particle_system)
34+
visualizer.final_plot()
35+
36+
37+

example/cfd/test/stationary_stokes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
help = "Type of refinement strategy, default is uniform_refine")
5353

5454
parser.add_argument('--maxit',
55-
default = 5, type = int,
55+
default = 3, type = int,
5656
help = "Maximum number of iterations for the solver, default is 5")
5757

5858
parser.add_argument('--maxstep',

example/cgraph/dipole_example.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
import json
3+
import fealpy.cgraph as cgraph
4+
5+
WORLD_GRAPH = cgraph.WORLD_GRAPH
6+
7+
pde = cgraph.create("DipoleAntenna3D")
8+
mesher = cgraph.create("Dipole3d")
9+
spacer = cgraph.create("FunctionSpace")
10+
uher = cgraph.create("FEFunction")
11+
dipole_antenna_eq = cgraph.create("DipoleAntennaEquation")
12+
dbc = cgraph.create("DirichletBC")
13+
solver = cgraph.create("IterativeSolver")
14+
15+
16+
# 连接节点
17+
mesher(cr = 0.05, sr0 = 1.9, sr1 = 2.4, L = 2.01, G = 0.01)
18+
spacer(type = "first_nedelec", mesh=mesher().mesh, p=1)
19+
dipole_antenna_eq(
20+
space=spacer(),
21+
q=3,
22+
diffusion = pde().diffusion,
23+
reaction = pde().reaction,
24+
source = pde().source,
25+
Y = pde().Y,
26+
ID = mesher().ID1
27+
)
28+
29+
dbc(
30+
gd=pde().dirichlet,
31+
isDDof=mesher().ID2,
32+
form=dipole_antenna_eq().operator,
33+
F=dipole_antenna_eq().source
34+
)
35+
36+
solver(
37+
A=dbc().A,
38+
b=dbc().F,
39+
solver = "minres"
40+
)
41+
42+
43+
# 最终连接到图输出节点上
44+
WORLD_GRAPH.output(mesh=mesher().mesh, uh=solver())
45+
46+
WORLD_GRAPH.register_error_hook(print)
47+
WORLD_GRAPH.execute()
48+
print(WORLD_GRAPH.get())
49+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import json
2+
import fealpy.cgraph as cgraph
3+
4+
5+
WORLD_GRAPH = cgraph.WORLD_GRAPH
6+
7+
pde = cgraph.create("DLDMicrofluidicChip2D")
8+
mesher = cgraph.create("DLDMicrofluidicChipMesh2d")
9+
uspacer = cgraph.create("TensorFunctionSpace")
10+
pspacer = cgraph.create("FunctionSpace")
11+
dld_eq = cgraph.create("StokesEquation")
12+
solver = cgraph.create("CGSolver")
13+
postprocess = cgraph.create("VPDecoupling")
14+
15+
mesher(lc = 0.02)
16+
uspacer(mesh = mesher(), p=2, gd = 2)
17+
pspacer(mesh = mesher(), p=1)
18+
pde(radius = mesher().radius,
19+
centers = mesher().centers,
20+
inlet_boundary = mesher().inlet_boundary,
21+
outlet_boundary = mesher().outlet_boundary,
22+
wall_boundary = mesher().wall_boundary)
23+
dld_eq(uspace = uspacer(),
24+
pspace = pspacer(),
25+
velocity_dirichlet = pde().velocity_dirichlet,
26+
pressure_dirichlet = pde().pressure_dirichlet,
27+
is_velocity_boundary = pde().is_velocity_boundary,
28+
is_pressure_boundary = pde().is_pressure_boundary)
29+
solver(A = dld_eq().bform,
30+
b = dld_eq().lform)
31+
postprocess(out = solver().out,
32+
uspace = uspacer(),
33+
mesh = mesher())
34+
35+
# 最终连接到图输出节点上
36+
WORLD_GRAPH.output(uh = postprocess().uh,u_x = postprocess().u_x, u_y = postprocess().u_y, ph = postprocess().ph)
37+
WORLD_GRAPH.error_listeners.append(print)
38+
WORLD_GRAPH.execute()
39+
print(WORLD_GRAPH.get())
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import json
2+
import fealpy.cgraph as cgraph
3+
4+
5+
WORLD_GRAPH = cgraph.WORLD_GRAPH
6+
7+
pde = cgraph.create("DLDMicrofluidicChip3D")
8+
mesher = cgraph.create("DLDMicrofluidicChipMesh3d")
9+
uspacer = cgraph.create("TensorFunctionSpace")
10+
pspacer = cgraph.create("FunctionSpace")
11+
dld_eq = cgraph.create("StokesEquation")
12+
solver = cgraph.create("CGSolver")
13+
postprocess = cgraph.create("VPDecoupling")
14+
15+
mesher(lc = 0.04)
16+
uspacer(mesh = mesher(), p=2, gd = 3)
17+
pspacer(mesh = mesher(), p=1)
18+
pde(thickness = mesher().thickness,
19+
radius = mesher().radius,
20+
centers = mesher().centers,
21+
inlet_boundary = mesher().inlet_boundary,
22+
outlet_boundary = mesher().outlet_boundary,
23+
wall_boundary = mesher().wall_boundary)
24+
dld_eq(uspace = uspacer(),
25+
pspace = pspacer(),
26+
velocity_dirichlet = pde().velocity_dirichlet,
27+
pressure_dirichlet = pde().pressure_dirichlet,
28+
is_velocity_boundary = pde().is_velocity_boundary,
29+
is_pressure_boundary = pde().is_pressure_boundary)
30+
solver(A = dld_eq().bform,
31+
b = dld_eq().lform)
32+
postprocess(out = solver().out,
33+
uspace = uspacer(),
34+
mesh = mesher())
35+
36+
# 最终连接到图输出节点上
37+
WORLD_GRAPH.output(uh = postprocess().uh)
38+
WORLD_GRAPH.error_listeners.append(print)
39+
WORLD_GRAPH.execute()
40+
print(WORLD_GRAPH.get())
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import fealpy.cgraph as cgraph
2+
from fealpy.backend import backend_manager as bm
3+
4+
WORLD_GRAPH = cgraph.WORLD_GRAPH
5+
6+
model = cgraph.create("Beam2d")
7+
mesher = cgraph.create("CreateMesh")
8+
beam_materialer = cgraph.create("BeamMaterial")
9+
spacer = cgraph.create("FunctionSpace")
10+
beam_model = cgraph.create("Beam")
11+
dbc = cgraph.create("StructuralDirichletBC")
12+
solver = cgraph.create("DirectSolver")
13+
postprocess = cgraph.create("UDecoupling")
14+
15+
# 连接节点
16+
node = bm.array([[0], [5],[7.5]], dtype=bm.float64)
17+
cell = bm.array([[0, 1],[1,2]] , dtype=bm.int32)
18+
19+
mesher(node = node, cell = cell)
20+
spacer(type="lagrange", mesh=mesher(), p=1)
21+
22+
beam_materialer(property="Steel", beam_type="Euler-Bernoulli beam", beam_E=200e9, beam_nu=0.3, I=118.6e-6)
23+
24+
beam_model(
25+
space = spacer(),
26+
beam_E = beam_materialer().E,
27+
beam_nu = beam_materialer().nu,
28+
I = beam_materialer().I,
29+
distributed_load = model().f,
30+
beam_type = "euler_bernoulli_2d",
31+
)
32+
33+
dbc(
34+
gd=model().dirichlet,
35+
isDDof=model().dirichlet_dof_index,
36+
K = beam_model().K,
37+
F=beam_model().F,
38+
space=spacer()
39+
)
40+
41+
solver(A = dbc().K,
42+
b = dbc().F)
43+
44+
45+
# 最终连接到图输出节点上
46+
WORLD_GRAPH.output(mesh=mesher(), u=solver())
47+
WORLD_GRAPH.register_error_hook(print)
48+
WORLD_GRAPH.execute()
49+
print(WORLD_GRAPH.get())

example/cgraph/helmholtz_2d_example.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
helmholtz_eq = cgraph.create("HelmholtzEquation")
1313
dbc = cgraph.create("DirichletBC")
1414
solver = cgraph.create("CGSolver")
15+
mesh2d3d = cgraph.create("MeshDimensionUpgrading")
1516

1617

1718
# 连接节点
@@ -35,7 +36,19 @@
3536
x0=dbc().uh
3637
)
3738
# 最终连接到图输出节点上
38-
WORLD_GRAPH.output(mesh=mesher(), uh=solver())
39+
WORLD_GRAPH.output(
40+
mesh=mesh2d3d(mesh=mesher(), z=solver()),
41+
uh=solver()
42+
)
3943

4044
WORLD_GRAPH.execute()
41-
print(WORLD_GRAPH.get())
45+
result = WORLD_GRAPH.get()
46+
mesh = result["mesh"]
47+
48+
from matplotlib import pyplot as plt
49+
50+
fig = plt.figure()
51+
axes = fig.add_subplot(projection="3d")
52+
mesh.add_plot(axes)
53+
54+
plt.show()
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import json
2+
import fealpy.cgraph as cgraph
3+
4+
5+
WORLD_GRAPH = cgraph.WORLD_GRAPH
6+
7+
pde = cgraph.create("IncompressibleCylinder2d")
8+
uspacer = cgraph.create("TensorFunctionSpace")
9+
pspacer = cgraph.create("FunctionSpace")
10+
dbc_u = cgraph.create("ProjectDBC")
11+
dbc_p = cgraph.create("ProjectDBC")
12+
simulation = cgraph.create("IncompressibleNSIPCS")
13+
timeline = cgraph.create("CFDTimeline")
14+
IncompressibleNSRun = cgraph.create("IncompressibleNSIPCSRun")
15+
16+
pde(
17+
mu = 0.001,
18+
rho = 1.0,
19+
cx = 0.5,
20+
cy = 0.2,
21+
radius = 0.07,
22+
n_circle = 100,
23+
h = 0.06)
24+
uspacer(mesh = pde().mesh, p=2, gd = 2)
25+
pspacer(mesh = pde().mesh, p=1)
26+
dbc_u(
27+
space = uspacer(),
28+
dirichlet = pde().velocity_dirichlet,
29+
is_boundary = pde().is_velocity_boundary
30+
)
31+
dbc_p(
32+
space = pspacer(),
33+
dirichlet = pde().pressure_dirichlet,
34+
is_boundary = pde().is_pressure_boundary
35+
)
36+
simulation(
37+
constitutive = 1,
38+
mu = pde().mu,
39+
rho = pde().rho,
40+
source = pde().source,
41+
uspace = uspacer(),
42+
pspace = pspacer(),
43+
is_pressure_boundary = pde().is_pressure_boundary,
44+
apply_bcu = dbc_u().apply_bc,
45+
apply_bcp = dbc_p().apply_bc,
46+
q = 2
47+
)
48+
timeline(
49+
T0 = 0.0,
50+
T1 = 1.0,
51+
NT = 1000
52+
)
53+
IncompressibleNSRun(
54+
T0=timeline().T0,
55+
T1=timeline().T1,
56+
NL=timeline().NL,
57+
uspace = uspacer(),
58+
pspace = pspacer(),
59+
velocity_0 = pde().velocity_0,
60+
pressure_0 = pde().pressure_0,
61+
is_pressure_boundary = pde().is_pressure_boundary,
62+
predict_velocity = simulation().predict_velocity,
63+
correct_pressure = simulation().correct_pressure,
64+
correct_velocity = simulation().correct_velocity,
65+
mesh = pde().mesh,
66+
output_dir = "/home/libz/cylinder"
67+
)
68+
69+
WORLD_GRAPH.output(uh_x = IncompressibleNSRun().uh_x)
70+
WORLD_GRAPH.error_listeners.append(print)
71+
WORLD_GRAPH.execute()
72+
print(WORLD_GRAPH.get())
73+

0 commit comments

Comments
 (0)