Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/ComputationalModels/BoundaryConditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ end

getindex(bc::MultiFieldBC, i) = bc.BoundaryCondition[i]

include("EvolutionFunctions.jl")
include("CartesianTags.jl")
include("FaceLabeling.jl")


struct MultiFieldTC{A} <: TimedependentCondition
vh::A # could be a multifield or single field
Expand Down
5 changes: 5 additions & 0 deletions src/ComputationalModels/ComputationalModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ using GridapGmsh: GmshDiscreteModel

import Base.getindex

# Deprecation exports
using HyperFEM.DiscreteModeling
Base.@deprecate_binding CartesianTags DiscreteModeling.CartesianTags
Base.@deprecate_binding EvolutionFunctions DiscreteModeling.EvolutionFunctions

include("BoundaryConditions.jl")
export DirichletBC
export NeumannBC
Expand Down
14 changes: 0 additions & 14 deletions src/ComputationalModels/FaceLabeling.jl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
"Shortcuts for the tags of cartesian discrete models."
module CartesianTags

export face0YZ, face1YZ, faceX0Z, faceX1Z, faceXY0, faceXY1

export edgeX00, edgeX10, edgeX01, edgeX11
export edge0Y0, edge1Y0, edge0Y1, edge1Y1
export edge00Z, edge10Z, edge01Z, edge11Z

export corner000, corner100, corner010, corner110
export corner001, corner101, corner011, corner111

export edgeX00⁺, edgeX10⁺, edgeX01⁺, edgeX11⁺
export edge0Y0⁺, edge1Y0⁺, edge0Y1⁺, edge1Y1⁺
export edge00Z⁺, edge10Z⁺, edge01Z⁺, edge11Z⁺

export face0YZ⁺, face1YZ⁺, faceX0Z⁺, faceX1Z⁺, faceXY0⁺, faceXY1⁺

# Deprecated tags
export faceX0, faceX1, faceY0, faceY1, faceZ0, faceZ1

# --- Face tags ---

"Tags indicating the face at plane X0."
Expand Down
20 changes: 20 additions & 0 deletions src/DiscreteModeling/DiscreteModeling.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

"""
A bundle of helper tools to work with discrete models in space/time.
"""
module DiscreteModeling

using Gridap

export CartesianTags
export EvolutionFunctions
export add_tag_from_vertex_filter!
export aspect_ratio
export element_size

include("CartesianTags.jl")
include("EvolutionFunctions.jl")
include("FaceLabeling.jl")
include("MeshDescriptor.jl")

end
28 changes: 28 additions & 0 deletions src/DiscreteModeling/FaceLabeling.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

"""
Create a new tag from a geometry and a coordinate-based filter function.
The filter function takes in vertex coordinates and returns a boolean values. A geometrical
entity is tagged if all its vertices pass the filter.

# See also
- `Gridap.Geometry.face_labeling_from_vertex_filter`
- `Gridap.Geometry.merge!`
"""
function add_tag_from_vertex_filter!(
labels::Gridap.Geometry.FaceLabeling,
tag::String,
geometry::Gridap.Geometry.DiscreteModel,
filter::Function)
new_labels = Gridap.Geometry.face_labeling_from_vertex_filter(geometry.grid_topology, tag, filter)
merge!(labels, new_labels)
end


function add_tag_from_vertex_filter!(
labels::Gridap.Geometry.FaceLabeling,
geometry::Gridap.Geometry.DiscreteModel,
tag::String,
filter::Function)
@warn "This method is deprecated. Call the function with: (labels, tag, geometry, filter)"
add_tag_from_vertex_filter!(labels, tag, geometry, filter)
end
88 changes: 88 additions & 0 deletions src/DiscreteModeling/MeshDescriptor.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

"""
Return the aspect ratio of the underlying cartesian elements as a string.
This function is only available for an underlying `CartesianGrid`.

# Example
aspect_ratio(Ω) # "51:51:5"
aspect_ratio(Ω, tol=0.05) # "10:10:1"
aspect_ratio(uh⁺, tol=0.1) # "10:10:1"
"""
function aspect_ratio(grid::CartesianGrid; tol=1e-6)
descriptor = Gridap.Geometry.get_cartesian_descriptor(grid)
sizes = descriptor.sizes

rel = sizes ./ minimum(sizes)
best = nothing
best_error = Inf
best_complexity = Inf

for d in 0:20
candidate = round.(Int, rel .* d)
any(candidate .== 0) && continue
approx = candidate ./ d
err = maximum(abs.(approx .- rel) ./ rel)
if err < best_error
complexity = max(candidate...)
if complexity < best_complexity
best = candidate
best_error = err
best_complexity = complexity
end
end
end

if best_error > tol # exact fallback
denominators = denominator.(rationalize.(sizes))
least_mult = lcm(denominators...)
best = round.(Int, sizes .* least_mult)
end

join(best, ":")
end

function aspect_ratio(model::CartesianDiscreteModel; kwargs...)
aspect_ratio(get_grid(model); kwargs...)
end

function aspect_ratio(triangulation::Triangulation; kwargs...)
aspect_ratio(get_background_model(triangulation); kwargs...)
end

function aspect_ratio(f::CellField; kwargs...)
aspect_ratio(get_triangulation(f); kwargs...)
end


"""
Return the element size for a cartesian mesh.
This function is only available for an underlying `CartesianGrid`.

# Example
element_size(model) # Compute the diagonal
element_size(uh, :x) # Get the x-size of the underlying grid
"""
function element_size(grid::CartesianGrid)
descriptor = Gridap.Geometry.get_cartesian_descriptor(grid)
sizes = descriptor.sizes
sqrt(sum(abs2, sizes))
end

function element_size(grid::CartesianGrid, direction)
descriptor = Gridap.Geometry.get_cartesian_descriptor(grid)
direction_indices = Dict(:x => 1, :y => 2, :z => 3)
index = direction_indices[direction]
descriptor.sizes[index]
end

function element_size(model::CartesianDiscreteModel, args...)
element_size(get_grid(model), args...)
end

function element_size(triangulation::Triangulation, args...)
element_size(get_background_model(triangulation), args...)
end

function element_size(f::CellField, args...)
element_size(get_triangulation(f), args...)
end
7 changes: 5 additions & 2 deletions src/Exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ end
@publish ComputationalModels TrialFESpace! # Exporting internal function of Gridap
@publish ComputationalModels L2_Projection

# Note: the files FaceLabeling, CartesianTags and Evolution functions should be moved to a module different than ComputationalModels
@publish ComputationalModels add_tag_from_vertex_filter!
@publish DiscreteModeling CartesianTags
@publish DiscreteModeling EvolutionFunctions
@publish DiscreteModeling add_tag_from_vertex_filter!
@publish DiscreteModeling aspect_ratio
@publish DiscreteModeling element_size

@publish Solvers IterativeSolver
@publish Solvers Newton_RaphsonSolver
Expand Down
2 changes: 1 addition & 1 deletion src/HyperFEM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ include("TensorAlgebra/TensorAlgebra.jl")
include("PhysicalModels/PhysicalModels.jl")
include("WeakForms/WeakForms.jl")
include("Solvers/Solvers.jl")
include("DiscreteModeling/DiscreteModeling.jl")
include("ComputationalModels/ComputationalModels.jl")

include("Io.jl")
include("Exports.jl")

Expand Down
Loading