-
Notifications
You must be signed in to change notification settings - Fork 97
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
Shape derivative #653
Shape derivative #653
Conversation
Revert "change to FLoat 32 + cellpoint struct orig" This reverts commit f4b09ee. reverting working for autodiff - needs ironing(checksdeleted more for allowing piping duals (dont need the SMA) get rid of show compat w/ reversediff get rid assmebler generaliser type stability fixing monomial basis to pass tests get rid comments
Hi @ConnorMallon. Test are not passing. Try to pull the latest version in master and push again to this branch. |
Tests are now passing. Please have a look and let me know what I can do to fix anything or make it a bit more clean. |
Hey @fverdugo, What is purpose of doing a |
I have smuggled in some more changes here. These are for something slightly different but still related. I noticed an issue when trying to use Gridaps built in Autodiff on a bimaterial problem. Here we have a problem where a
|
Also added some support for multifield but the following MWE does not work:
|
Reverted changes related to Gridaps Autodiff (derivative w.r.t a FEfunction) . This PR is now only for making the shape derivative possible (derivative w.r.t the goemetry) |
Yes, AppendedArray is general enough to handle cases with different eltypes. But, even in this situation, it is preferable to feed it with two arrays with the same eltype. You can evaluate with a profiler if this is a hotspot or not and then decide. For me, the only important request in this PR is to not introduce type instabilities in the code that was already working. If you end up with changes that introduce type instabilities for your new use case, but you do not introduce type instabilities for the previous use cases, then it is rather acceptable. |
Ok, thanks for your answer. We are on the same page. The question that I have now is why @ConnorMallon used |
Because when So in essence, I was trying to avoid the abstract types given by |
Ok. Thus, it was not actually something that you needed to avoid a code crash or something like that, right? In such a case, let use live with the current solution. It does not introduce type instability for the most common case in which both arrays are of the same eltype. |
no it was actually causing an error down the line somewhere |
Ok!!!!!!! At last!!!! :-) Everything starts making sense to me now. I was wondering how you realized of this very subtle detail without an error. |
Yes it would of probably been more helpful if I provided a bit more explanation on each of the commits explaining why exactly the changes were made including the errors in which they were made to get around. |
Hey @amartinhuertas, I have made the changes as requested in the last commit. |
Ok. Thanks for your work. We have resolved one of the two main issues in this PR (frequent dynamic memory allocation of small arrays). There is still the other that has to be solved. I will wait for your reproducer. |
Here is the error: ERROR: LoadError: MethodError: no method matching Gridap.CellData.CellPoint(::Gridap.Arrays.AppendedArray{Vector{Gridap.TensorValues.VectorValue{2, Float64}}, Gridap.Arrays.CompressedArray{Vector{Gridap.TensorValues.VectorValue{2, Float64}}, 1, Vector{Vector{Gridap.TensorValues.VectorValue{2, Float64}}}, Vector{Int8}}, FillArrays.Fill{Vector{Gridap.TensorValues.VectorValue{2, Float64}}, 1, Tuple{Base.OneTo{Int64}}}}, ::Gridap.Arrays.AppendedArray{Vector,Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Arrays.Broadcasting{Gridap.Arrays.Reindex{Vector{Gridap.TensorValues.VectorValue{2, ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.TrackedArray{Float64, Float64, 2, Matrix{Float64}, Matrix{Float64}}}}}}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Gridap.TensorValues.VectorValue{2, ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.TrackedArray{Float64, Float64, 2, Matrix{Float64}, Matrix{Float64}}}}}, 1, Tuple{Gridap.Arrays.Table{Int32, Vector{Int32}, Vector{Int32}}}}, Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Arrays.Broadcasting{Gridap.Arrays.Reindex{Gridap.Geometry.CartesianCoordinates{2, Float64, typeof(identity)}}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Gridap.TensorValues.VectorValue{2, Float64}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Arrays.Reindex{Gridap.Geometry.CartesianCellNodes{2}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Int32}, 1, Tuple{Vector{Int32}}}}}}, ::Gridap.Geometry.AppendedTriangulation{2, 2, GridapEmbedded.Interfaces.SubCellTriangulation{2, 2, ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.TrackedArray{Float64, Float64, 2, Matrix{Float64}, Matrix{Float64}}}, Gridap.Geometry.CartesianDiscreteModel{2, Float64, typeof(identity)}}, Gridap.Geometry.BodyFittedTriangulation{2, 2, Gridap.Geometry.CartesianDiscreteModel{2, Float64, typeof(identity)}, Gridap.Geometry.GridPortion{2, 2, Gridap.Geometry.CartesianGrid{2, Float64, typeof(identity)}}, Vector{Int32}}}, ::Gridap.CellData.ReferenceDomain)
Closest candidates are:
Gridap.CellData.CellPoint(::AbstractArray{<:Union{AbstractArray{<:Gridap.TensorValues.VectorValue}, Gridap.TensorValues.VectorValue}}, ::AbstractArray{<:Union{AbstractArray{<:Gridap.TensorValues.VectorValue}, Gridap.TensorValues.VectorValue}}, ::Gridap.Geometry.Triangulation, ::DS) where DS at ~/.julia/dev/Gridap/src/CellData/CellFields.jl:6
Gridap.CellData.CellPoint(::AbstractArray{<:Union{AbstractArray{<:Gridap.TensorValues.VectorValue}, Gridap.TensorValues.VectorValue}}, ::Gridap.Geometry.Triangulation, ::Gridap.CellData.PhysicalDomain) at ~/.julia/dev/Gridap/src/CellData/CellFields.jl:22
Gridap.CellData.CellPoint(::AbstractArray{<:Union{AbstractArray{<:Gridap.TensorValues.VectorValue}, Gridap.TensorValues.VectorValue}}, ::Gridap.Geometry.Triangulation, ::Gridap.CellData.ReferenceDomain) at ~/.julia/dev/Gridap/src/CellData/CellFields.jl:12 Note the ::Gridap.Arrays.AppendedArray{
- Vector,
Gridap.Arr............................} buried in there (the second argument we are trying to give to the function). It is a vector without any eltype defined which results from trying to do |
For clarity in the discussion, let me separate the 4 arguments to the 1st argument
2nd argument
3rd argument
4th argument
These 4th arguments must match the type annotations of the member variables in the type definition statement
|
Now that the problem and its cause are clear, we can start talking about possible solutions. @fverdugo ... can we remove the constraint from the CellPoint member variables? This is one possible solution. |
@ConnorMallon ... if you remove the constraint from the CellPoint member variables, does your code run smoothly, or there are other issues to be solved? |
It does run smoothly. However,I am going to guess that this change is going to break stability for regular Gridap functions that were type stable. I have tried to avoid this approach after being warned about this by francesc here |
Ok, I was probably loose when using the expression remove the constraint. By this I mean to annotate cell_ref and cell_phys member variables with Tr, and Tp types that become type parameters right after dc in the type declaration. I don't see why this introdces type instability. Indeed the current member variables are polymorphic abstractarray |
HI @ConnorMallon ! I have implemented this here ConnorMallon@56dd373 Can you please double check that your code runs with this mod? If affirmative, and the tests pass, I will accept this PR. |
@ConnorMallon tests are passing, good news. Once you confirm that your code runs succesfully, I will accept the PR. |
code runs successfully. thanks Alberto |
Modifications to allow propogation of duals for autodiff ( to resolve gridap/GridapEmbedded.jl#51 ).
The main problem I had here was with the appended triangulation object. When using a cut triangulation, some of the points come from the background triangulation and some from the cut section of the triangulation. With a pertubation of the geometry, dual numbers appear in the points around the cut areas but the unaffected points are still built on primitive types. Since these points get " apppended " we end up with a mixed type array. I have got around this but it is probably not the cleanest way. Let me know what I can do to make this better. Note that I made the concrete type check look 1 layer deeper to cater for the appended array.