-
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
Add apply_analytical! function #532
Merged
Merged
Changes from 36 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
0b22bcc
Add initial_conditions!
KnutAM 8ef8b48
Add tests and fix minor bug
KnutAM 3320f89
Clean code and move overloads
KnutAM 161a357
Make code more clear
KnutAM b72ff7b
Remove Returns to support 1.6
KnutAM 027eb41
Rename initial_conditions->apply_analytical!
KnutAM 5d5b93f
Update transient heat flow example
KnutAM c96b88b
Improve Exception handling and add tests
KnutAM 269d867
Fix tests for julia 1.6
KnutAM e327d75
Add colorbar
KnutAM 106f049
Merge branch 'master' into kam/initial_conditions
KnutAM 2887dc5
Update docs and make internal internal
KnutAM 15d12d8
Reduce gif size
KnutAM 3957086
Use gifsky and support svg images in examples
KnutAM 9203026
Fix typos in example
KnutAM 129e8c3
Add documentation
KnutAM faffed0
Use apply_analytical! in homogenization example
KnutAM e95ac23
Add semicolon to prevent output in example
KnutAM 7714b89
Clarify DAE definition
KnutAM 3d3165b
Rename to transfer_solution!
KnutAM 9b7d775
Use u instead of x for unknown dof values in initial condition docs
KnutAM 8e1baf0
Reorder args and make fieldname optional
KnutAM ebca08b
Update docs with new argument order and defaults
KnutAM a599d05
Revert back to apply_analytical!
KnutAM 28863d8
Add warning about non-nodal interpolations
KnutAM 1170e4f
Update filenames in tests
KnutAM 0ea6420
Improve note-text
KnutAM cecbdfb
Merge branch 'master' into kam/initial_conditions
KnutAM b49bf62
fix example text mistake
KnutAM 976e5ba
Move gif and svg to gh-pages/assets
KnutAM 51d3f7e
Apply suggestions from code review
KnutAM c574a06
Julia formatting
KnutAM 7f7b929
Require fieldname also for single-field problems
KnutAM 450e9c5
Put apply_analytical tests last, before examples
KnutAM cacce2f
Add changelog [no ci]
KnutAM 211c8ac
Merge branch 'master' into kam/initial_conditions
KnutAM 494a2e1
Change argument order in apply_analytical
KnutAM 10a7922
Introduce CellDofValues
KnutAM f95c6df
Revert bad autoformatting
KnutAM 2166d14
Manual tuning back autoformatting
KnutAM a9bef3d
Fix more autoformat issues
KnutAM 1bd56ae
Set whitespace_in_kwargs=false
KnutAM 6e64ff8
fixes more autoformat
KnutAM cc92f33
Add simplified constructor for QuadratureRule
KnutAM da7e532
Use CellScalarValues instead of custom type
KnutAM 60e3cb4
Reset cell_values.jl formatting
KnutAM 4f85093
Final formatting
KnutAM 3387146
Update src/Quadrature/quadrature.jl
KnutAM b736685
Reflect required dim in QuadratureRule
KnutAM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,9 @@ get_rhs_data | |
apply_rhs! | ||
Ferrite.RHSData | ||
``` | ||
|
||
# Initial conditions | ||
|
||
```@docs | ||
apply_analytical! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
|
||
function _default_interpolations(dh::MixedDofHandler) | ||
fhs = dh.fieldhandlers | ||
getcelltype(i) = typeof(getcells(dh.grid, first(fhs[i].cellset))) | ||
ntuple(i -> default_interpolation(getcelltype(i)), length(fhs)) | ||
end | ||
|
||
function _default_interpolation(dh::DofHandler) | ||
return default_interpolation(typeof(getcells(dh.grid, 1))) | ||
end | ||
|
||
""" | ||
apply_analytical!( | ||
a::AbstractVector, dh::AbstractDofHandler, f::Function, | ||
fieldname::Symbol, cellset=1:getncells(dh.grid)) | ||
KnutAM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Apply a solution `f(x)` by modifying the values in the degree of freedom vector `a` | ||
pertaining to the field `fieldname` for all cells in `cellset`. | ||
The function `f(x)` are given the spatial coordinate | ||
of the degree of freedom. For scalar fields, `f(x)::Number`, | ||
and for vector fields with dimension `dim`, `f(x)::Vec{dim}`. | ||
|
||
This function can be used to apply initial conditions for time dependent problems. | ||
|
||
!!! note | ||
This function only works for standard nodal finite element interpolations | ||
when the function value at the (algebraic) node is equal to the corresponding | ||
degree of freedom value. | ||
This holds for e.g. Lagrange and Serendipity interpolations, including | ||
sub- and superparametric elements. | ||
|
||
""" | ||
function apply_analytical!( | ||
a::AbstractVector, dh::DofHandler, f::Function, fieldname::Symbol, | ||
cellset=1:getncells(dh.grid) | ||
) | ||
fieldname ∉ getfieldnames(dh) && error("The fieldname $fieldname was not found in the dof handler") | ||
ip_geo = _default_interpolation(dh) | ||
field_idx = find_field(dh, fieldname) | ||
ip_fun = getfieldinterpolation(dh, field_idx) | ||
celldofinds = dof_range(dh, fieldname) | ||
field_dim = getfielddim(dh, field_idx) | ||
_apply_analytical!(a, dh, celldofinds, field_dim, ip_fun, ip_geo, f, cellset) | ||
end | ||
|
||
function apply_analytical!( | ||
a::AbstractVector, dh::MixedDofHandler, f::Function, fieldname::Symbol, | ||
cellset=1:getncells(dh.grid), | ||
) | ||
fieldname ∉ getfieldnames(dh) && error("The fieldname $fieldname was not found in the dof handler") | ||
ip_geos = _default_interpolations(dh) | ||
|
||
for (fh, ip_geo) in zip(dh.fieldhandlers, ip_geos) | ||
fieldname ∈ getfieldnames(fh) || continue | ||
field_idx = find_field(fh, fieldname) | ||
ip_fun = getfieldinterpolation(fh, field_idx) | ||
field_dim = getfielddim(fh, field_idx) | ||
celldofinds = dof_range(fh, fieldname) | ||
_apply_analytical!(a, dh, celldofinds, field_dim, ip_fun, ip_geo, f, intersect(fh.cellset, cellset)) | ||
end | ||
return a | ||
end | ||
|
||
function _apply_analytical!( | ||
a::Vector, dh::AbstractDofHandler, celldofinds, field_dim, | ||
ip_fun::Interpolation, ip_geo::Interpolation, f::Function, cellset) | ||
|
||
coords = getcoordinates(dh.grid, first(cellset)) | ||
c_dofs = celldofs(dh, first(cellset)) | ||
f_dofs = zeros(Int, length(celldofinds)) | ||
|
||
# Check f before looping | ||
length(f(first(coords))) == field_dim || error("length(f(x)) must be equal to dimension of the field ($field_dim)") | ||
|
||
for cellnr in cellset | ||
cellcoords!(coords, dh, cellnr) | ||
celldofs!(c_dofs, dh, cellnr) | ||
for (i, celldofind) in enumerate(celldofinds) | ||
f_dofs[i] = c_dofs[celldofind] | ||
end | ||
_apply_analytical!(a, f_dofs, coords, field_dim, ip_fun, ip_geo, f) | ||
end | ||
return a | ||
end | ||
|
||
function _apply_analytical!(a::Vector, dofs::Vector{Int}, coords::Vector{XT}, field_dim, ip_fun, ip_geo, f) where {XT<:Vec} | ||
|
||
getnbasefunctions(ip_geo) == length(coords) || error("coords=$coords not compatible with ip_ge=$ip_geo") | ||
ref_coords = reference_coordinates(ip_fun) | ||
length(ref_coords) * field_dim == length(dofs) || error("$ip_fun must have length(dofs)=$(length(dofs)) reference coords") | ||
|
||
for (i_dof, refpoint) in enumerate(ref_coords) | ||
x_dof = zero(XT) | ||
for (i, x_node) in enumerate(coords) | ||
x_dof += value(ip_geo, i, refpoint) * x_node | ||
end | ||
for (idim, icval) in enumerate(f(x_dof)) | ||
a[dofs[field_dim*(i_dof-1)+idim]] = icval | ||
end | ||
end | ||
return a | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ export | |
FieldHandler, | ||
Field, | ||
reshape_to_nodes, | ||
apply_analytical!, | ||
|
||
# Constraints | ||
ConstraintHandler, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think other examples use https://github.com/jipolanco/WriteVTK.jl/blob/6e528bd6a016efb84f5cb50f2dc43bcdc59ab8d4/src/gridtypes/ParaviewCollection.jl#L59 but since I don't see that in the WriteVTK documentation maybe it is deprecated or discouraged? Edit: I see that this approach was also used later in this file, so let's at least have it consistent (if you change here, also change below).
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 haven't seen
collection_add_timestep
before. What example did you think of?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.
My research code I guess :D I thought we had some other time dependent problems. It used to be the only advertised way before, but maybe that has changed.
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.
JuliaVTK/WriteVTK.jl#113