From ec804c5a940e7f977dc10d688eb179439698f250 Mon Sep 17 00:00:00 2001 From: kimauth Date: Mon, 27 Mar 2023 11:06:34 +0200 Subject: [PATCH 1/3] remove usage of getfieldinterpolations/getfielddims/getfieldnames(fh) --- src/Dofs/ConstraintHandler.jl | 6 +++--- src/Dofs/MixedDofHandler.jl | 36 +++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Dofs/ConstraintHandler.jl b/src/Dofs/ConstraintHandler.jl index 635e24e7ca..3b73230bef 100644 --- a/src/Dofs/ConstraintHandler.jl +++ b/src/Dofs/ConstraintHandler.jl @@ -914,7 +914,7 @@ end function add!(ch::ConstraintHandler{<:MixedDofHandler}, dbc::Dirichlet) dbc_added = false for fh in ch.dh.fieldhandlers - if dbc.field_name in getfieldnames(fh) && _in_cellset(ch.dh.grid, fh.cellset, dbc.faces; all=false) + if !isnothing(_find_field(fh, dbc.field_name)) && _in_cellset(ch.dh.grid, fh.cellset, dbc.faces; all=false) # Dofs in `dbc` not in `fh` will be removed, hence `dbc.faces` must be copied. # Recreating the `dbc` will create a copy of `dbc.faces`. # In this case, add! will warn, unless `warn_not_in_cellset=false` @@ -938,8 +938,8 @@ function add!(ch::ConstraintHandler, fh::FieldHandler, dbc::Dirichlet; warn_not_ # Extract stuff for the field field_idx = find_field(fh, dbc.field_name) - interpolation = getfieldinterpolations(fh)[field_idx] - field_dim = getfielddims(fh)[field_idx] + interpolation = getfieldinterpolation(fh, field_idx) + field_dim = getfielddim(fh, field_idx) if !all(c -> 0 < c <= field_dim, dbc.components) error("components $(dbc.components) not within range of field :$(dbc.field_name) ($(field_dim) dimension(s))") diff --git a/src/Dofs/MixedDofHandler.jl b/src/Dofs/MixedDofHandler.jl index 79155677b0..433bce2ad4 100644 --- a/src/Dofs/MixedDofHandler.jl +++ b/src/Dofs/MixedDofHandler.jl @@ -164,11 +164,11 @@ function add!(dh::MixedDofHandler, fh::FieldHandler) _check_same_celltype(dh.grid, collect(fh.cellset)) _check_cellset_intersections(dh, fh) # the field interpolations should have the same refshape as the cells they are applied to - refshapes_fh = getrefshape.(getfieldinterpolations(fh)) # extract the celltype from the first cell as the celltypes are all equal cell_type = typeof(dh.grid.cells[first(fh.cellset)]) refshape_cellset = getrefshape(default_interpolation(cell_type)) - for refshape in refshapes_fh + for field_idx in eachindex(fh.fields) + refshape = getrefshape(getfieldinterpolation(fh, field_idx)) refshape_cellset == refshape || error("The RefShapes of the fieldhandlers interpolations must correspond to the RefShape of the cells it is applied to.") end @@ -265,9 +265,7 @@ function __close!(dh::MixedDofHandler{dim}) where {dim} dh, cellnumbers, dh.field_names, - getfieldnames(fh), - getfielddims(fh), - getfieldinterpolations(fh), + fh.fields, nextdof, vertexdicts, edgedicts, @@ -281,9 +279,10 @@ function __close!(dh::MixedDofHandler{dim}) where {dim} end -function _close!(dh::MixedDofHandler{dim}, cellnumbers, global_field_names, field_names, field_dims, field_interpolations, nextdof, vertexdicts, edgedicts, facedicts) where {dim} +function _close!(dh::MixedDofHandler{dim}, cellnumbers, global_field_names, fields, nextdof, vertexdicts, edgedicts, facedicts) where {dim} ip_infos = InterpolationInfo[] - for interpolation in field_interpolations + for field in fields + interpolation = field.interpolation ip_info = InterpolationInfo(interpolation) push!(ip_infos, ip_info) # TODO: More than one face dof per face in 3D are not implemented yet. This requires @@ -300,14 +299,15 @@ function _close!(dh::MixedDofHandler{dim}, cellnumbers, global_field_names, fiel len_cell_dofs = length(dh.cell_dofs) dh.cell_dofs_offset[ci] = len_cell_dofs + 1 - for (local_num, field_name) in enumerate(field_names) - fi = findfirst(i->i == field_name, global_field_names) - @debug "\tfield: $(field_name)" + for (local_num, field) in pairs(fields) + # for (local_num, field_name) in enumerate(field_names) + fi = findfirst(i->i == field.name, global_field_names) + @debug "\tfield: $(field.name)" ip_info = ip_infos[local_num] # Distribute dofs for vertices nextdof = add_vertex_dofs( - dh.cell_dofs, cell, vertexdicts[fi], field_dims[local_num], + dh.cell_dofs, cell, vertexdicts[fi], field.dim, ip_info.nvertexdofs, nextdof ) @@ -316,7 +316,7 @@ function _close!(dh::MixedDofHandler{dim}, cellnumbers, global_field_names, fiel # Regular 3D element or 2D interpolation embedded in 3D space nentitydofs = ip_info.dim == 3 ? ip_info.nedgedofs : ip_info.nfacedofs nextdof = add_edge_dofs( - dh.cell_dofs, cell, edgedicts[fi], field_dims[local_num], + dh.cell_dofs, cell, edgedicts[fi], field.dim, nentitydofs, nextdof ) end @@ -325,14 +325,14 @@ function _close!(dh::MixedDofHandler{dim}, cellnumbers, global_field_names, fiel # they are added above as edge dofs. if ip_info.dim == dim nextdof = add_face_dofs( - dh.cell_dofs, cell, facedicts[fi], field_dims[local_num], + dh.cell_dofs, cell, facedicts[fi], field.dim, ip_info.nfacedofs, nextdof ) end # Distribute internal dofs for cells nextdof = add_cell_dofs( - dh.cell_dofs, field_dims[local_num], ip_info.ncelldofs, nextdof + dh.cell_dofs, field.dim, ip_info.ncelldofs, nextdof ) end @@ -460,7 +460,7 @@ See also: [`find_field(dh::MixedDofHandler, field_name::Symbol)`](@ref), [`_find function find_field(fh::FieldHandler, field_name::Symbol) field_idx = _find_field(fh, field_name) if field_idx === nothing - error("Did not find field :$field_name in FieldHandler (existing fields: $(getfieldnames(fh)))") + error("Did not find field :$field_name in FieldHandler (existing fields: $([field.name for field in fh.fields]))") end return field_idx end @@ -580,9 +580,9 @@ function reshape_to_nodes(dh::MixedDofHandler, u::Vector{T}, fieldname::Symbol) for fh in dh.fieldhandlers # check if this fh contains this field, otherwise continue to the next - field_pos = findfirst(i->i == fieldname, getfieldnames(fh)) - field_pos === nothing && continue - offset = field_offset(fh, fieldname) + field_idx = _find_field(fh, fieldname) + field_idx === nothing && continue + offset = field_offset(fh, field_idx) reshape_field_data!(data, dh, u, offset, field_dim, fh.cellset) end From deb1d4d16b05ca2eb34e9b4e83db3c1d15722e4f Mon Sep 17 00:00:00 2001 From: kimauth Date: Mon, 27 Mar 2023 11:20:35 +0200 Subject: [PATCH 2/3] remove more usage of getfieldnames(fh) --- src/Dofs/apply_analytical.jl | 2 +- src/PointEval/PointEvalHandler.jl | 2 +- test/test_apply_analytical.jl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Dofs/apply_analytical.jl b/src/Dofs/apply_analytical.jl index 64099fd83d..5e488657eb 100644 --- a/src/Dofs/apply_analytical.jl +++ b/src/Dofs/apply_analytical.jl @@ -51,7 +51,7 @@ function apply_analytical!( ip_geos = _default_interpolations(dh) for (fh, ip_geo) in zip(dh.fieldhandlers, ip_geos) - fieldname ∈ getfieldnames(fh) || continue + isnothing(_find_field(fh, fieldname)) && continue field_idx = find_field(fh, fieldname) ip_fun = getfieldinterpolation(fh, field_idx) field_dim = getfielddim(fh, field_idx) diff --git a/src/PointEval/PointEvalHandler.jl b/src/PointEval/PointEvalHandler.jl index 59b5f8f1db..f7e0d54874 100644 --- a/src/PointEval/PointEvalHandler.jl +++ b/src/PointEval/PointEvalHandler.jl @@ -296,7 +296,7 @@ get_func_interpolations(dh::DH, fieldname) where DH<:DofHandler = [getfieldinter function get_func_interpolations(dh::DH, fieldname) where DH<:MixedDofHandler func_interpolations = Union{Interpolation,Nothing}[] for fh in dh.fieldhandlers - j = findfirst(i -> i === fieldname, getfieldnames(fh)) + j = _find_field(fh, fieldname) if j === nothing push!(func_interpolations, missing) else diff --git a/test/test_apply_analytical.jl b/test/test_apply_analytical.jl index 395c562893..3618e2d144 100644 --- a/test/test_apply_analytical.jl +++ b/test/test_apply_analytical.jl @@ -68,7 +68,7 @@ function _global_dof_range(dh::MixedDofHandler, field_name::Symbol) dofs = Set{Int}() for fh in dh.fieldhandlers - if field_name ∈ Ferrite.getfieldnames(fh) + if !isnothing(Ferrite._find_field(fh, field_name)) _global_dof_range!(dofs, dh, fh, field_name, fh.cellset) end end From c393a45262695ab4f66a1d5995c0a807fada2656 Mon Sep 17 00:00:00 2001 From: kimauth Date: Mon, 27 Mar 2023 11:21:45 +0200 Subject: [PATCH 3/3] remove getfielddims(fh)/getfieldinterpolations(f)/getfieldnames(fh) --- src/Dofs/MixedDofHandler.jl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Dofs/MixedDofHandler.jl b/src/Dofs/MixedDofHandler.jl index 433bce2ad4..f5e2c5fb8a 100644 --- a/src/Dofs/MixedDofHandler.jl +++ b/src/Dofs/MixedDofHandler.jl @@ -70,10 +70,6 @@ function Base.show(io::IO, ::MIME"text/plain", dh::MixedDofHandler) end end -getfieldnames(fh::FieldHandler) = [field.name for field in fh.fields] -getfielddims(fh::FieldHandler) = [field.dim for field in fh.fields] -getfieldinterpolations(fh::FieldHandler) = [field.interpolation for field in fh.fields] - """ ndofs_per_cell(dh::AbstractDofHandler[, cell::Int=1]) @@ -120,7 +116,6 @@ end """ getfieldnames(dh::MixedDofHandler) - getfieldnames(fh::FieldHandler) Return a vector with the names of all fields. Can be used as an iterable over all the fields in the problem.