Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jigyasa Watwani
/
growth-pattern-control
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
231643ef
authored
Sep 18, 2022
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
laplace eqn errors for different dx
parent
a4339727
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
fem_errors/fem_errors.py
fem_errors/fem_errors.py
0 → 100644
View file @
231643ef
import
dolfin
as
df
import
matplotlib.pyplot
as
plt
import
numpy
as
np
df
.
set_log_level
(
df
.
LogLevel
.
ERROR
)
df
.
parameters
[
'form_compiler'
][
'optimize'
]
=
True
def
laplace
(
Nx
,
L
,
cL
,
cR
):
# mesh, function space, function, test function
mesh
=
df
.
IntervalMesh
(
Nx
,
0
,
L
)
x
=
mesh
.
coordinates
()[:,
0
]
function_space
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
c
,
tc
=
df
.
Function
(
function_space
),
df
.
TestFunction
(
function_space
)
# Dirichlet boundary
dbc
=
df
.
DirichletBC
(
function_space
,
df
.
Constant
(
0
),
'on_boundary'
)
def
left
(
x
,
on_boundary
):
# inhomogeneous dirichlet boundary
return
df
.
near
(
x
[
0
],
0.0
)
and
on_boundary
def
right
(
x
,
on_boundary
):
return
df
.
near
(
x
[
0
],
L
)
and
on_boundary
dbc_left
=
df
.
DirichletBC
(
function_space
,
df
.
Constant
(
cL
),
left
)
dbc_right
=
df
.
DirichletBC
(
function_space
,
df
.
Constant
(
cR
),
right
)
dbc
=
[
dbc_left
,
dbc_right
]
# form
form
=
df
.
inner
(
c
.
dx
(
0
),
tc
.
dx
(
0
))
*
df
.
dx
(
mesh
)
# solve
df
.
solve
(
form
==
0
,
c
,
dbc
)
c_numerical
=
c
.
compute_vertex_values
(
mesh
)
# exact solution
c_exact
=
((
cR
-
cL
)
/
L
)
*
x
+
cL
# plot
# plt.plot(x, c_numerical, 'bo', label='Numerical solution')
# plt.plot(x, c_exact, label='Exact solution')
# plt.xlabel('x')
# plt.ylabel('$c(x)$')
# plt.legend()
# plt.show()
error
=
np
.
max
(
np
.
abs
(
c_numerical
-
c_exact
))
return
(
error
)
# parameters
L
,
cL
,
cR
=
2
*
np
.
pi
,
1
,
-
1
Nx_array
=
np
.
array
([
5
,
10
,
20
,
40
,
80
,
100
,
200
,
400
,
800
,
1600
])
dx_array
=
L
/
Nx_array
error_array
=
np
.
zeros
(
len
(
dx_array
))
for
i
in
range
(
0
,
len
(
dx_array
)):
error_array
[
i
]
=
laplace
(
Nx_array
[
i
],
L
,
cL
,
cR
)
plt
.
plot
(
dx_array
,
error_array
,
'bo'
)
plt
.
show
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment