How to use sympy in firedrake #3187
Unanswered
zhyxue0
asked this question in
Firedrake support
Replies: 3 comments 3 replies
-
What would you like to do with the expression? It may be that you can get away with using UFL for your symbolics (and the things will be easier). |
Beta Was this translation helpful? Give feedback.
2 replies
-
This is also done several places in Irksome for time-dependent problems.
For example, check the demo:
https://github.com/firedrakeproject/Irksome/blob/master/demos/heat/demo_heat.py.rst
There are other demos and tests in similar vein.
…On Thu, Oct 26, 2023 at 12:09 PM Lawrence Mitchell ***@***.***> wrote:
OK, so you want to symbolically differentiate to find f = u_t - a(u_xx +
u_yy). You can do this with ufl if you use UFL objects and variable and
diff (see
https://fenics.readthedocs.io/projects/ufl/en/latest/manual/form_language.html#variable-derivatives
)
So, suppose you have x y and z as being spatial coordinates:
x, y = SpatialCoordinate(mesh)t = Constant(...) # current time
# define objects that we can differentiate with respect toxv = variable(x)yv = variable(y)tv = variable(t)
u = 3*xv*yv + xv**2 + 2*yv**2 + tv**3# a is defined previous as a normal python functionf = diff(u, tv) - a(diff(diff(u, xv), xv) + diff(diff(u, yv), yv))
# Now you can just use `f` as a normal UFL expression
—
Reply to this email directly, view it on GitHub
<#3187 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA4XULY54YZDFE3S7OZMV4TYBKKMZAVCNFSM6AAAAAA6RNWGRSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TGOJVGM3DK>
.
You are receiving this because you are subscribed to this thread.Message
ID: <firedrakeproject/firedrake/repo-discussions/3187/comments/7395365@
github.com>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
It should respect the rules of vector algebra/calculus. You can stick UFL
expressions into arrays by `as_vector` (it takes a list?) and then you need
to compute the vector Laplacian that's right for you. You should try it
out and post specific questions when something breaks.
…On Thu, Oct 26, 2023 at 9:41 PM Sean ***@***.***> wrote:
Thanks a lot. But I have some questions. I note
uexact = B * atan(t)*(pi / 2.0 - atan(S * (R - t)))rhs = expand_derivatives(diff(uexact, t)) - div(grad(uexact))
f I want to solve for f by this equation, $u=(u_0, u_1)$ is a vector,a
vector, therefore f is also a vector,
Does expand_derivatives(diff(uexact, t)) - div(grad(uexact)) also work in
vector form?
And this equation is
$f = u_{t} - \Delta u - |u|^{p} u$, where $|u| =(u_0^2 + u_1^2)^p$.
How to express f if I code
def u_exact(x, y, t):
u = as_vector(sin(x)*t, sin(y)*t)return u
# How to code it?def f(u):
—
Reply to this email directly, view it on GitHub
<#3187 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA4XULZBI34JKPOUL57LT6DYBMNMVAVCNFSM6AAAAAA6RNWGRSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TGOJYHEZDC>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, everyone! I am trying to use
sympy
in firerake to make expressions general.Here is my idea, but it seems does not work.
Do you have any good suggestions?
Beta Was this translation helpful? Give feedback.
All reactions