-
-
Notifications
You must be signed in to change notification settings - Fork 74
Nonlinear Laplacian Handling in MOLFiniteDifference (issue #354) #371
Conversation
…es involving Differentials in SymbolicUtils.jl.
Is there a reason why this is commented? |
I am working with some test files in my computer that isolate the portion of code that performs this particular parsing. This code is not integrated to MOL_discretization.jl yet, first I need to solve some issues with the automatic generation of rules involving Differentials. Because I wanted to upload some progress, I added the portion of code of interest at about the place where it should be integrated, but as a comment. |
…y term of the rhs.
… + u(t,x)^2) * Dx(u(t,x))). Case 2: Dx(u(t,x) * u(t,x) * Dx(u(t,x))).
updating my fork
I added code to handle cases like the following:
To do this I partially used the SymbolicUtils Also, I added new test cases for all the examples above. The function |
@ChrisRackauckas if you agree, you can merge this PR. |
It's WIP and has merge conflicts? |
nonlinlap_rules = [] | ||
for t in vcat(lhs_arg,rhs_arg) | ||
for r in rules | ||
if r(t) != nothing | ||
push!(nonlinlap_rules, t => r(t)) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I did not find a way to fully use SymbolicUtils to solve this issue. So I solved a part of it manually. An explanation of my issue can be found in the following document.: https://docs.google.com/document/d/1qbWokDYXuO5GV3ilI8R4fWWnvkBkrpQd3H6d7l9DrC4/edit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YingboMa can you double check this?
I update my fork from time to time, I estimate that the conflicts were generated because of that. Unfortunately I do not see an option in github that allows me to resolve them. If there is such an option, and you could point me to it, I would be happy to resolve them. |
I think you need write access to resolve conflicts on github, but if you merge master into your local branch you will see them and be able to resolve them |
Thanks for the advice. In summary this is what I did:
|
@ChrisRackauckas @tinosulzer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok merging this as something that works for now so we can move forward. But I am not sure this is the most accurate approach: currently we do D(u_i+1/2, x_i+1/2) (i.e. function of the average) but usually I have seen D_i+1/2 (i.e. average of the function). These can be quite different if D is nonlinear. Would need to dig more into the numerical analysis to be sure which is best
Currently a basic approximation is implemented. I would like to solve this in another PR. In the first page of this draft you can find the definition of g based on a degree 2 polynomial in a 3D case. If this is the correct definition, I would need to know which stencil nodes should I use. The "cross" gives me 7, but I need 10 to fit the coefficients, I think that the crossed derivatives could be avoided to use just 7 nodes. |
You split it to the 3 terms Del u = u_xx + u_yy + u_zz and then you have 2 unique coefficients per, + 1 for the middle. Otherwise you have to have the corner terms, which you could discretize to include the corners. |
# TODO: check central_neighbor_idxs. It does not work like the old implementation. | ||
#I1 = oneunit(first(indices)) | ||
#Imin = first(indices) + I1 * (order÷2) | ||
#Imax = last(indices) - I1 * (order÷2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below
# Use max and min to apply buffers | ||
central_neighbor_idxs(II,j) = stencil(j) .+ max(Imin,min(II,Imax)) | ||
# central_neighbor_idxs(II,j) = stencil(j) .+ max(Imin,min(II,Imax)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? just remove if there's a new definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's back to the old definition which ignores the discretization order (I think) i.e. breaks #365 but not enough to cause tests to fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you looking into this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can take a look tomorrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing that is broken with the stencil
approach is "Test 00: Dt(u(t,x,y)) ~ Dxx(u(t,x,y)) + Dyy(u(t,x,y))" in the MOL_2D_Diffusion.jl
test with orders 4 and 6. The test breaks because the solution is not accurate enough, not a syntax error. The reason it works with the old syntax is that it just ignores discretization.centered_order
and pretends you're always asking for order 2. @emmanuellujan if you only test for order 2 in that test then you can use the syntax you commented out, and we should open an issue for the order 4 and 6 in 2D.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that it is better not to remove those comments for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I'll just open a PR to your fork
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we posted almost at the same time, I did not see your comment when I posted mine. I will check what you mention. Thank you :)
That would make the approximation O(dx) instead of O(dx^2), but that can be improved in a subsequent PR. Let's get an issue open for this. |
I know, but if you want to fit a degree 2 polynomial in 3D you need 10 coefficients, ergo 10 nodes. If you use a typical stencil (without the corners), you have 7 nodes, ergo you need to neglect some terms of the polynomial. I think the cross derivative terms could be removed to this end. Another option is to use the corners. In this case, you have 15 nodes available, but you only need 10, so you need to chose which corners to use. Probably any choice in which the nodes are sufficiently distributed is enough. |
Okay, we need to wait until this PR is merged to post the new issue. Note: currently issue #371 contains this "sub-issue". |
Yes, that is what I'm saying. The typical stencil is not a 2nd order 2D polynomial: it's the cross product of 2 1D polynomials. That's the derivation we should probably use. Though the 9 coefficient 2D polynomial is used though. See the examples here: https://en.wikipedia.org/wiki/Discrete_Laplace_operator#Implementation_via_operator_discretization Generating the higher precision stencils wouldn't be a bad idea, given that it's easy (and doesn't impact the cache efficiency) |
remove orders [4,6] test
Fix issue 354
Fixes part of #354