From 58f3f9873eee1382728913ceb2fb61bdfcb51c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesus=20Mart=C3=ADnez?= Date: Wed, 28 Jan 2026 07:53:17 +0100 Subject: [PATCH] Adds constructor for DirichletBC Adds a constructor for the `DirichletBC` struct that accepts boundary condition tags and values, automatically generating timestep functions and setting up the boundary condition. Additionally, corrects a reshaping operation and comments out line search output in nonlinear solvers to reduce verbosity. --- src/ComputationalModels/BoundaryConditions.jl | 15 ++++++++++++--- src/Solvers/NonlinearSolvers.jl | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ComputationalModels/BoundaryConditions.jl b/src/ComputationalModels/BoundaryConditions.jl index a031070..78de4df 100644 --- a/src/ComputationalModels/BoundaryConditions.jl +++ b/src/ComputationalModels/BoundaryConditions.jl @@ -67,7 +67,7 @@ function _get_bc_func(tags_::Vector{String}, values_, bc_timesteps) @inbounds for i in eachindex(tags_) if values_[i] === DirichletCoupling || typeof(values_[i]) <: DirichletCoupling - bc_func_[i] = (Λ) -> (x) -> x + bc_func_[i] = (Λ) -> (x) -> x else if isnothing(bc_timesteps[i]) bc_func_[i] = values_[i] @@ -97,6 +97,16 @@ struct DirichletBC{A} <: BoundaryCondition caches = (bc_values) new{typeof(caches)}(tags_, funcs_, bc_timesteps, caches) end + + + function DirichletBC(bc_tags::Vector{String}, bc_values) + @assert(length(bc_tags) == length(bc_values)) + bc_timesteps = [Λ -> 1.0 for _ in 1:length(bc_tags)] + tags_, funcs_ = _get_bc_func(bc_tags, bc_values, bc_timesteps) + caches = (bc_values) + new{typeof(caches)}(tags_, funcs_, bc_timesteps, caches) + end + end function updateBC!(m::DirichletBC, bc_values, bc_timesteps) @@ -206,7 +216,7 @@ struct InterpolableBC{A,B,C} <: DirichletCoupling dim = length(U.space.fe_dof_basis.trian.model.grid.node_coordinates[1]) mask = U.space.dirichlet_dof_tag .== dcmask[1] vals = U.dirichlet_values[mask] - Interface_coords_ = reshape(vals, dim,:)' + Interface_coords_ = reshape(vals, dim, :)' coords = VectorValue.(eachrow(Interface_coords_)) v = evaluate(Interpolable(1.0), coords) bc_values = reduce(vcat, map(x -> get_array(x), v)) @@ -228,4 +238,3 @@ function InterpolableBC!(U::TrialFESpace, bc::DirichletBC, interface_tags::Strin return obj end - \ No newline at end of file diff --git a/src/Solvers/NonlinearSolvers.jl b/src/Solvers/NonlinearSolvers.jl index 1ed8f66..d7cf903 100644 --- a/src/Solvers/NonlinearSolvers.jl +++ b/src/Solvers/NonlinearSolvers.jl @@ -71,9 +71,9 @@ function _solve_nr!(x, A, b, dx, ns, nls, op) α = linesearch(x, dx, b, op) x .+= α * dx - if α < 1.0 && Int(log.verbose)>0 - println("Activated line-search: $α") - end + # if α < 1.0 && Int(log.verbose)>0 + # println("Activated line-search: $α") + # end # Check convergence for the current residual # residual!(b, op, x) res = norm(b)