Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66282033
mixed_poisson.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jun 9, 12:44
Size
820 B
Mime Type
text/x-python
Expires
Tue, Jun 11, 12:44 (2 d)
Engine
blob
Format
Raw Data
Handle
18197276
Attached To
R6746 RationalROMPy
mixed_poisson.py
View Options
from
matplotlib
import
pyplot
as
plt
plt
.
jet
()
import
fenics
as
fen
# Create mesh and define function space
mesh
=
fen
.
UnitSquareMesh
(
10
,
10
)
CG1
=
fen
.
FiniteElement
(
"P"
,
fen
.
triangle
,
1
)
R0
=
fen
.
FiniteElement
(
"R"
,
fen
.
triangle
,
0
)
element
=
fen
.
MixedElement
([
CG1
,
R0
])
W
=
fen
.
FunctionSpace
(
mesh
,
element
)
# Define variational problem
(
u
,
c
)
=
fen
.
TrialFunction
(
W
)
(
v
,
d
)
=
fen
.
TestFunctions
(
W
)
f
=
fen
.
Expression
(
"10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)"
,
element
=
CG1
)
g
=
fen
.
Expression
(
"-sin(5*x[0])"
,
element
=
CG1
)
a
=
(
fen
.
inner
(
fen
.
grad
(
u
),
fen
.
grad
(
v
))
+
c
*
v
+
u
*
d
)
*
fen
.
dx
L
=
f
*
v
*
fen
.
dx
+
g
*
v
*
fen
.
ds
# Compute solution
w
=
fen
.
Function
(
W
)
fen
.
solve
(
a
==
L
,
w
)
(
u
,
c
)
=
w
.
split
()
# Plot solution
plt
.
figure
()
p
=
fen
.
plot
(
u
)
plt
.
colorbar
(
p
)
plt
.
show
(),
plt
.
close
()
Event Timeline
Log In to Comment