Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbolic computation of differential ops on Functions #231

Closed
santiagobadia opened this issue Apr 19, 2020 · 3 comments
Closed

Symbolic computation of differential ops on Functions #231

santiagobadia opened this issue Apr 19, 2020 · 3 comments

Comments

@santiagobadia
Copy link
Member

I would like to start using automatic diff for computing differential operators over analytical functions. We should think how to implement this within Gridap. I would use ForwardDiff, which provides what we need. The following example goes beyond Gridap, since it also includes transient problems. The transient part will go to GridapODEs.

using ForwardDiff

u(t::Real) = x -> u(x,t)

∇u(x,t) = VectorValue(ForwardDiff.gradient(u(t),x)...)
∇u(x::Gridap.TensorValues.MultiValue,t) = ∇u(x.array,t)
∇u(t::Real) = x -> ∇u(x,t)

_∇u(x,t) = ForwardDiff.gradient(u(t),x)
_∇u(t::Real) = x -> ForwardDiff.gradient(u(t),x)
Δu(x,t) = tr(ForwardDiff.jacobian(_∇u(t),x))
Δu(x::Gridap.TensorValues.MultiValue,t) = Δu(x.array,t)
Δu(t::Real) = x -> Δu(x,t)

v(x) = t -> u(x,t)
∂tu(t) = x -> ForwardDiff.derivative(v(x),t)
∂tu(x,t) = ∂tu(t)(x)

∂t(::typeof(u)) = ∂tu
(::typeof(u)) = ∇u
@fverdugo
Copy link
Member

@santiagobadia Could you write the wanted API for a stady-state problem?

I have the feeling (just an intuition) that it will be easier to use ForwardDiff to compute time derivatives than to compute spatial gradients or jacobians of residuals

@santiagobadia
Copy link
Member Author

@fverdugo not sure I understand, I am already doing the space diff in the example above. The space-only case is a simplification of the one above. I am not sure about performance, but I can easily check... In any case, for the moment, I am just considering to use it for analytical functions, relieving the user from computing them manually for code validation in manufactured solutions, which is very prompt to error. Not for the residual, jacobian, yet.

@fverdugo
Copy link
Member

Done in PR #236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants