-
Notifications
You must be signed in to change notification settings - Fork 89
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
(Performance) improvements on gathering field information from MixedDofHandler
#621
Conversation
Allows to avoid recomputing the field_idx if several functions are called for the same field
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #621 +/- ##
==========================================
- Coverage 92.65% 92.44% -0.22%
==========================================
Files 29 29
Lines 4441 4463 +22
==========================================
+ Hits 4115 4126 +11
- Misses 326 337 +11
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Thanks for taking the time Kim! Note that using Ferrite
function get_2d_grid()
# GIVEN: two cells, a quad and a triangle sharing one face
cells = [
Quadrilateral((1, 2, 3, 4)),
Triangle((3, 2, 5))
]
coords = zeros(Vec{2,Float64}, 5)
nodes = [Node(coord) for coord in zeros(Vec{2,Float64}, 5)]
return Grid(cells,nodes)
end
function create_field(;name, field_dim, order, spatial_dim, cellshape)
interpolation = Lagrange{spatial_dim, cellshape, order}()
return Field(name, interpolation, field_dim)
end
grid = get_2d_grid()
# WHEN: adding a scalar field for each cell and generating dofs
field1 = create_field(name=:u, spatial_dim=2, field_dim=1, order=1, cellshape=RefCube)
field2 = create_field(name=:u, spatial_dim=2, field_dim=1, order=1, cellshape=RefTetrahedron)
dh = MixedDofHandler(grid);
add!(dh, FieldHandler([field1], Set(1)));
add!(dh, FieldHandler([field2], Set(2)));
close!(dh)
Ferrite.find_field(dh, :u) returns only (1,1). |
It's not broken, that is the intended behaviour. (It's described in the docstring like that.) However, after some discussion with @fredrikekre, I'll add error messages to some of the functions for the case that a |
Okay. Then I have a suggestion for the dof handler merge. Do you think it makes sense to have different FieldHandlers? One for fields covering the full domain (i.e. the functionality of the current dof handler) and one for fields on subdomains (which is the selling point of the mixed dof handler)? cc @fredrikekre |
That is what Kim and I discussed. We rename |
How should I know then externally if a field is defined on all types of cells as e.g. |
This PR tackles the functionality that requests field information from the
MixedDofHandler
, in particularfind_field
getfielddim
getfieldinterpolation
field_offset
dof_range
Performance improvements
Finding fields based on the field name was a bit suboptimal. From the side of the user API, in particular
dof_range
profits, but most improvements are based on a betterfind_field
:@btime dof_range($fh, $(:f3))
@btime Ferrite.find_field($mixed_dh, $(:f3))
@btime Ferrite.find_field($fh, $(:f3))
Benchmark code
Breaking change to
find_field(mixed_dh, fieldname)
find_field
now searches for the first occurence of the given field and returns a tuple with the index of the fieldhandler it was found in and the index of the field in the fieldhandler (before it only searched in the first fieldhandler).API
It is most efficient to call
getfielddim
,getfieldinterpolation
,field_offset
anddof_range
withfield_idxs
instead offieldname
as argument. However, in order to have the exact same syntax forMixedDofHandler
andDofHandler
(working towards merging them), I suggest to have both options for all functions, i.e. possible ways to call e.g.dof_range
are:dof_range(mixed_dh, field_idxs)
dof_range(mixed_dh, fieldname)
dof_range(fh, field_idxs)
dof_range(fh, fieldname)