Skip to content

Commit

Permalink
added bfacevelocities for fem coupling and adjusted test environment …
Browse files Browse the repository at this point in the history
…to run tests for fem coupling
  • Loading branch information
pjaap committed Oct 10, 2024
1 parent 1358289 commit 3085a9d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
45 changes: 34 additions & 11 deletions ext/VoronoiFVMExtendableFEMBaseExt.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
module VoronoiFVMExtendableFEMBaseExt

using VoronoiFVM
using ExtendableFEMBase
using ExtendableGrids
using ExtendableFEMBase: CellFinder, evaluate_bary!,
FEVectorBlock, initialize!, Identity,
PointEvaluator, SegmentIntegrator

using ExtendableGrids: Cartesian2D, CoordinateSystem, Cylindrical2D,
Edge1D, eval_trafo!, gFindLocal!,
mapderiv!, postprocess_xreftest!, update_trafo!

using LinearAlgebra: dot, norm

using Base: fill!

id(u) = (u, Identity)

function iscloser(pint,p1,p2,eps)
return norm(pint-p2)<norm(p2-p1)-eps
function iscloser(pint, p1, p2, eps)
return norm(pint - p2) < norm(p2 - p1) - eps
end

"""
Expand Down Expand Up @@ -61,7 +70,21 @@ function VoronoiFVM.edgevelocities(grid, vel::FEVectorBlock; kwargs...)
axisymmetric = grid[CoordinateSystem] <: Cylindrical2D ? true : false
seg_integrator, point_evaluator, cf, flowgrid = prepare_segment_integration(vel; axisymmetric, kwargs...)
aug_fevec_block = AugmentedFEVectorBlock(vel, seg_integrator, point_evaluator, cf, flowgrid)
velovec = VoronoiFVM.edgevelocities(grid, aug_fevec_block; axisymmetric,kwargs...)
velovec = VoronoiFVM.edgevelocities(grid, aug_fevec_block; axisymmetric, kwargs...)

if axisymmetric
circular_symmetric!(flowgrid)
end

return velovec
end

function VoronoiFVM.bfacevelocities(grid, vel::FEVectorBlock; kwargs...)
axisymmetric = grid[CoordinateSystem] <: Cylindrical2D ? true : false
seg_integrator, point_evaluator, cf, flowgrid = prepare_segment_integration(vel; axisymmetric, kwargs...)
aug_fevec_block = AugmentedFEVectorBlock(vel, seg_integrator, point_evaluator, cf, flowgrid)

velovec = VoronoiFVM.bfacevelocities(grid, aug_fevec_block; axisymmetric, kwargs...)

if axisymmetric
circular_symmetric!(flowgrid)
Expand All @@ -78,18 +101,18 @@ function VoronoiFVM.integrate(::Type{<:Cylindrical2D}, p1, p2, hnormal, aug_vec_
_integrate_along_segments(p1, p2, hnormal, aug_vec_block; kwargs...)
end

function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVectorBlock; interpolate_eps=1.0e-12, axisymmetric = false, kwargs...)
function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVectorBlock; interpolate_eps=1.0e-12, axisymmetric=false, kwargs...)

edge_length = norm(p1 - p2, 2)
avg_r = (p1[1]+p2[1])/2
avg_r = (p1[1] + p2[1]) / 2
bp1 = zeros(3)
CF = aug_vec_block.cellfinder
icell::Int = gFindLocal!(bp1, CF, p1; eps=interpolate_eps)
if edge_length interpolate_eps
point_evaluator = aug_vec_block.point_evaluator
evaluate_bary!(p2, point_evaluator, bp1, icell)
if axisymmetric
return dot(p2, hnormal)/(avg_r)
return dot(p2, hnormal) / (avg_r)
else
return dot(p2, hnormal)
end
Expand Down Expand Up @@ -127,7 +150,7 @@ function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVe
for j = 1:2, k = 1:2
bp[k] += invA[j, k] * cx[j]
end
ExtendableGrids.postprocess_xreftest!(bp, CF.xCellGeometries[icell])
postprocess_xreftest!(bp, CF.xCellGeometries[icell])
end

i = 1
Expand Down Expand Up @@ -247,9 +270,9 @@ function _integrate_along_segments(p1, p2, hnormal, aug_vec_block::AugmentedFEVe
end

if axisymmetric
return dot(result,hnormal)/(avg_r*edge_length)
return dot(result, hnormal) / (avg_r * edge_length)
else
return dot(result,hnormal)/edge_length
return dot(result, hnormal) / edge_length
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/vfvm_formfactors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ $(SIGNATURES)
Project velocity onto boundary face normals
"""
function bfacevelocities(grid, velofunc)
function bfacevelocities(grid, velofunc; kwargs...)
@assert dim_space(grid) < 3
bfacenodes = grid[BFaceNodes]
coord = grid[Coordinates]
Expand All @@ -434,8 +434,8 @@ function bfacevelocities(grid, velofunc)
p1 = coord[:, bfacenodes[1, ibface]]
p2 = coord[:, bfacenodes[2, ibface]]
pm = 0.5 * (p1 + p2)
velovec[1, ibface] = integrate(coord_system, p1, pm, bfacenormals[:, ibface], velofunc)
velovec[2, ibface] = integrate(coord_system, pm, p2, bfacenormals[:, ibface], velofunc)
velovec[1, ibface] = integrate(coord_system, p1, pm, bfacenormals[:, ibface], velofunc; kwargs...)
velovec[2, ibface] = integrate(coord_system, pm, p2, bfacenormals[:, ibface], velofunc; kwargs...)
end
end
return velovec
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
ExampleJuggler = "3bbe58f8-ed81-4c4e-a134-03e85fcf4a1a"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
ExtendableFEMBase = "12fb9182-3d4c-4424-8fd1-727a0899810c"
ExtendableGrids = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
ExtendableSparse = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down

0 comments on commit 3085a9d

Please sign in to comment.