Skip to content

Commit e37bf0f

Browse files
committed
Add Diffusion Problem to pygadjoints and forward simulation
1 parent b26f376 commit e37bf0f

File tree

11 files changed

+570
-246
lines changed

11 files changed

+570
-246
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import numpy as np
2+
import splinepy as spp
3+
4+
import pygadjoints as pyg
5+
6+
7+
"""
8+
This example solves a thermal diffusion problem in the form
9+
10+
.. math:
11+
\lambda \Delta \theta + \bar{f} = 0
12+
13+
We construct the manufactured solution with two variables in the form of
14+
15+
.. math:
16+
\theta = \alpha \text{sin} (2x) + \beta x y^2
17+
18+
which can be obtained, iff :math:`\bar{f}` is given as
19+
20+
.. math:
21+
\bar{f} = \lambda (4 \text{sin} (2x) + 2\beta x)
22+
23+
"""
24+
25+
# Define boundary conditions
26+
lambda_ = 1.172e-5
27+
print(f"Thermal Diffusivity : {lambda_}")
28+
29+
# Define function parameters
30+
alpha_ = 2
31+
beta_ = 3.1
32+
33+
boundary_conditions_options = [
34+
{
35+
# F - function (source)
36+
"tag": "Function",
37+
"attributes": {"type": "FunctionExpr", "id": "1", "dim": "3"},
38+
"text":
39+
f"4 * sin(2 * x) * {alpha_} * {lambda_} -"
40+
f" 2 * {beta_} * x * {lambda_}",
41+
},
42+
{
43+
"tag": "boundaryConditions",
44+
"attributes": {"multipatch": "0", "id": "2"},
45+
"children": [
46+
{
47+
"tag": "Function",
48+
"attributes": {
49+
"type": "FunctionExpr",
50+
"dim": "3",
51+
"index": "0",
52+
},
53+
"text":
54+
f"sin(2 * x) * {alpha_} "
55+
f" + {beta_} * x * y * y",
56+
},
57+
],
58+
},
59+
{
60+
"tag": "Function",
61+
"attributes": {
62+
"type": "FunctionExpr",
63+
"dim": "3",
64+
"id": "3",
65+
},
66+
"text":
67+
f"sin(2 * x) * {alpha_} "
68+
f"+ {beta_} * x * y * y",
69+
},
70+
]
71+
72+
# Set boundary conditions on all boundary elements of the multipatch (-1)
73+
74+
boundary_conditions_options[1]["children"].append(
75+
{
76+
"tag": "bc",
77+
"attributes": {
78+
"type": "Dirichlet",
79+
"function": str(0),
80+
"unknown": str(0),
81+
"name": f"BID{1}",
82+
},
83+
}
84+
)
85+
86+
# Create a simple geometry
87+
np.random.seed(9234865)
88+
n_refine = 2
89+
n_elevate = 1
90+
91+
microtile_patches = spp.helpme.create.box(3, 4, 3.5).bspline
92+
for _ in range(n_elevate):
93+
microtile_patches.elevate_degrees([0, 1, 2])
94+
microtile_patches.cps += 1 * np.random.random(microtile_patches.cps.shape)
95+
microtile_patches.insert_knots(0, np.linspace(0, 1, n_refine ** 2))
96+
microtile_patches.insert_knots(1, np.linspace(0, 1, n_refine ** 2))
97+
microtile_patches.insert_knots(2, np.linspace(0, 1, n_refine ** 2))
98+
# microtile_patches.show()
99+
microtile = spp.Multipatch([microtile_patches])
100+
microtile.determine_interfaces()
101+
# microtile.boundaries_from_continuity()
102+
spp.io.gismo.export(
103+
"mini_example.xml",
104+
microtile,
105+
options=boundary_conditions_options,
106+
as_base64=False,
107+
labeled_boundaries=True,
108+
)
109+
print("Test 1")
110+
111+
diffusion_solver = pyg.DiffusionProblem()
112+
diffusion_solver.init("mini_example.xml", 0, True)
113+
diffusion_solver.set_material_constants(lambda_)
114+
diffusion_solver.assemble()
115+
diffusion_solver.solve_linear_system()
116+
diffusion_solver.export_paraview("solution", False, 80**3, True)
117+
diffusion_solver.export_xml("solution_2")
118+
print("Export successfull")

0 commit comments

Comments
 (0)