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

Wrote additional high level API assembly functions #652

Merged
merged 6 commits into from
Sep 6, 2021

Conversation

amartinhuertas
Copy link
Member

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Sep 5, 2021

Codecov Report

Merging #652 (1cc0816) into master (87ff667) will increase coverage by 0.33%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #652      +/-   ##
==========================================
+ Coverage   87.70%   88.03%   +0.33%     
==========================================
  Files         134      134              
  Lines       14315    14679     +364     
==========================================
+ Hits        12555    12923     +368     
+ Misses       1760     1756       -4     
Impacted Files Coverage Δ
src/FESpaces/Assemblers.jl 78.98% <100.00%> (+2.09%) ⬆️
src/FESpaces/DivConformingFESpaces.jl 97.79% <0.00%> (+1.36%) ⬆️
src/Fields/ArrayBlocks.jl 90.90% <0.00%> (+2.49%) ⬆️
src/ReferenceFEs/RaviartThomasRefFEs.jl 96.96% <0.00%> (+3.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87ff667...1cc0816. Read the comment docs.

Copy link
Member

@fverdugo fverdugo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @amartinhuertas thanks for the PR!

See my minor comments below.

@@ -270,44 +270,88 @@ function assemble_matrix(f::Function,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix(a,collect_cell_matrix(U,V,f(u,v)))
end

function assemble_matrix!(A,f::Function,a::Assembler,U::FESpace,V::FESpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start the argument list with ::Function objects so that we can use do-block syntax. Also type-annotate the new array arguments, I.e.

assemble_matrix!(f::Function,A::AbstractMatrix,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix_and_vector!(f::Function,b::Function,M::AbstractMatrix,r::AbstractVector,a::Assembler,U::FESpace,V::FESpace)

Apply this minor changes to all new introduced assembly functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start the argument list with ::Function objects so that we can use do-block syntax

I though that the parameters that are modified in a !-like function should appear first in the list of parameters by convention. From your comment, I guess this is not strictly necessary, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, see e.g. broadcast

* Started the argument list with ::Function objects so that we can use do-block syntax.
function assemble_matrix(f,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix(a,collect_cell_matrix(U,V,f))
end

function assemble_matrix!(A::AbstractMatrix,f,a::Assembler,U::FESpace,V::FESpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function argument first here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f is not a function, isnt?

function assemble_vector(f,a::Assembler,V::FESpace)
assemble_vector(a,collect_cell_vector(V,f))
end

function assemble_vector!(b::AbstractVector,f,a::Assembler,V::FESpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f is not a function, isnt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f is a callable object, usually a Function.

to be consistent we have 2 main options:

  • add missing ::Function everywhere in this file, where we accept a function
  • remove all ::Function anotations to allow generic callable objects

2 is more general, but 1 is less disruptive wrt what we have now and also works since the weak form is always defined via functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still dont understand why f it is function/callable object in this particular function. See, e.g.,

function collect_cell_vector(test::FESpace,a::DomainContribution)
  w = []
  r = []
  for trian in get_domains(a)
    cell_vec = get_contribution(a,trian)
    @assert ndims(eltype(cell_vec)) == 1
    cell_vec_r = attach_constraints_rows(test,cell_vec,trian)
    rows = get_cell_dof_ids(test,trian)
    push!(w,compress_contributions(cell_vec_r,trian))
    push!(r,compress_ids(rows,trian))
  end
  (w,r)
end

a is a callable object?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It is not a function. it is an object for which collect_cell_vector and related functions are defined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, in any case I had to put the f and b args first in all function signatures to let all tests pass ...

function assemble_matrix_and_vector(f,b,a::Assembler,U::FESpace,V::FESpace)
assemble_matrix_and_vector(a,collect_cell_matrix_and_vector(U,V,f,b))
end

function assemble_matrix_and_vector!(M,r,f,b,a::Assembler,U::FESpace,V::FESpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here (and type-annotate array inputs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops ... I forgot this one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f is not a function, isnt?

function assemble_matrix(f,U::FESpace,V::FESpace)
a = SparseMatrixAssembler(U,V)
assemble_matrix(f,a,U,V)
end

function assemble_matrix!(A,f,U::FESpace,V::FESpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

function assemble_vector(f,V::FESpace)
a = SparseMatrixAssembler(V,V)
assemble_vector(f,a,V)
end

function assemble_vector!(b,f,V::FESpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

function assemble_matrix_and_vector(f,b,U::FESpace,V::FESpace)
a = SparseMatrixAssembler(U,V)
assemble_matrix_and_vector(f,b,a,U,V)
end

function assemble_matrix_and_vector!(M,r,f,b,U::FESpace,V::FESpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@amartinhuertas
Copy link
Member Author

Hi @fverdugo ... I already addressed all your comments. Anyway there is still something I do not understand. Some times we pass arguments to the f and b parameters which are not actually functions/callable objects ... I dont know perphaps I am confused. In any case, I think the PR is ready to be merged (if the tests pass).

@fverdugo
Copy link
Member

fverdugo commented Sep 6, 2021

You are right. It is not a function. it is an object for which collect_cell_vector and related functions are defined. E.g. a DomainContribution

@fverdugo fverdugo merged commit a502b1a into master Sep 6, 2021
@fverdugo fverdugo deleted the developed_additional_highlevel_assembly_functions branch September 6, 2021 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants