j-fu / VoronoiFVM.jl

Solution of nonlinear multiphysics partial differential equation systems using the Voronoi finite volume method
MIT License
183 stars 33 forks source link

Provide function which returns solution on boundary region #36

Closed Da-Be-Ru closed 2 years ago

Da-Be-Ru commented 2 years ago

For some post processing purposes, it could be beneficial to provide a function which returns the nodal values $u_k$ at designated boundary face regions.

My suggestion would be to provide something like a bvals function in vfvm_system.jl.

A quick and dirty draft could look like this:

function bvalinds(system::VoronoiFVM.AbstractSystem{Tv,Ti}, regions::AbstractVector) where {Tv,Ti}
   TA=Array{Ti}
   bvals=Array{TA}(undef,length(regions))
   grid=system.grid

   for (i,ireg) in enumerate(regions)
      catBFaces=findall(grid[BFaceRegions].==ireg)
      catBFaceLeftNodes=grid[BFaceNodes][1,catBFaces]
      catBFaceRightNodes=grid[BFaceNodes][2,catBFaces]
      BNodes=union(catBFaceLeftNodes,catBFaceRightNodes)
      bvals[i]=BNodes
   end

   return bvals
end

The user could then simply call a solution vector as indexed by the boundary face regions, e.g. if we want to extract the boundary values of a solution U associated with a system system on regions [1,3], we would simply execute

>bvals=bvalinds(system,[1,3]);
>U[1,bvals[1]] #boundary values for face region 1
>U[1,bvals[2]] #boundary values for face region 3

On the spot, I am not quite sure yet how we would extend that for arbitrary species and boundary species though and it might be worth thinking about if we should preserve some kind of ordering or orientation of the boundary nodes.

j-fu commented 2 years ago

BTW what are the "postprocessing purposes" ? We already have subgrid functionality (hadn't this in my head yesterday...): in ExtendableGrids and VoronoiFVM Examples.

May be this is already sufficient (or was intended anyway ?)

(BTW one missing thing here is point sorting for the extraction of 1D boundaries from 2D).

Da-Be-Ru commented 2 years ago

I believe the basic use case is to obtain nodal values on the boundary in order to determine the value of some external boundary reaction functions.

But yes, I forgot about the subgrid functionality, too. The example and the ExtendableGrids documentation demonstrate exactly the kind of functionality that has been suggested.

Given what has been described to me, I would consider the issue resolved, frankly.