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

Make constraint handling tools available for users #1158

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

KnutAM
Copy link
Member

@KnutAM KnutAM commented Feb 23, 2025

Supersedes #1152

Currently, there is a lot of nice functionality for working with dofs and constraints that are not available for users, without relying in clearly internal functions, such as _local_facet_dofs_for_bc (ref. e.g. if one should make a how-to from #1119).

The aim of this PR is to make some of this available to users, in particular, the local dofs belonging to an entity are made available via an updated BCValues struct. Secondly, the logic for getting periodic dofs are included in a new PeriodicDofLocations struct.

Finally, the concept of a DofLocation is included more formally (we use this already, but this PR adds a separate type of this). For a nodal interpolation a DofLocation has an actual coordinate (but abstractly doesn't have to). For vectorized interpolations, we can have multiple dofs associated with a single DofLocation.

With the tools introduced, we have the following possibilities,

bcv = BCValues(func_interpolation, geom_interpolation, boundary_type::Type{<:BoundaryIndex}, field_offset)
get_dof_locations(bcv::BCValues, entitynr::Int) # Iterate over the `DofLocation`s for the given entity
x = spatial_coordinate(bcv::BCValues, loc::DofLocation, cell_coords) # No need to update entity index in `bcv` to get global coord of a dof location 
local_dof = get_local_dof(bcv::BCValues, loc, component) # celldofs[local_dof] gives global dof for the local dof at location `loc` at component `component`. 

pdl = PeriodicDofLocations(function_interpolation)
component = 1
for image_dof_location in get_dof_locations(bcv, image_facet)
    # Using fp::PeriodicFacetPair from `collect_periodic_facets`
    mirror_dof_location = get_mirror_dof_location(pdl, fp, image_dof_location)
    local_image_dof = get_local_dof(bcv, image_dof_location, component)
    local_mirror_dof = get_local_dof(bcv, mirror_dof_location, component)
    ...
end

Currently, I haven't added exports or much documentation. Would be grateful for some feedback. My goal is allowing users build their own custom constraints more easily.

Brief summary of the internal changes in the code as a result of this

  • Removed the local_facet_dofs and local_facet_dofs_offset fields from Dirichlet. (These were also used for nodal BCs, so same fields are there but renamed to describe what they do)
  • The local_facet_dofs logic is now only for the first dof, and only when calling get_local_dof the vector component for vectorized interpolations are used.
  • For PeriodicDirichlet, everything now works by identifying dofs with the first component, all components are only added in the end. We also don't use a separate iterator when the rotation matrix is given, as we use the same strategy there.

I moved the PeriodicDofLocations functionality into periodicity_utils.jl, this can of course be included in ConstraintHandler.jl, however, I believe it would be easier to navigate if we could move all logic related to periodicity into a separate file as it is quite hard to navigate the ConstraintHandler.jl file.

Copy link

codecov bot commented Feb 23, 2025

Codecov Report

Attention: Patch coverage is 97.36842% with 4 lines in your changes missing coverage. Please review.

Project coverage is 93.70%. Comparing base (5f20e7b) to head (3306eb0).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
src/Dofs/ConstraintHandler.jl 96.07% 2 Missing ⚠️
src/Dofs/periodicity_utils.jl 97.14% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1158      +/-   ##
==========================================
+ Coverage   93.69%   93.70%   +0.01%     
==========================================
  Files          39       40       +1     
  Lines        6237     6232       -5     
==========================================
- Hits         5844     5840       -4     
+ Misses        393      392       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

1 participant