Skeleton of functions

This commit is contained in:
Jorge Gonzalez 2026-04-06 18:01:48 +02:00
commit 1b864d6bed
2 changed files with 137 additions and 45 deletions

View file

@ -990,6 +990,7 @@ MODULE moduleMesh
end interface end interface
! Extended types ! Extended types
! Dirichlet: Constant potential value
TYPE, EXTENDS(boundaryEMGeneric):: boundaryEMDirichlet TYPE, EXTENDS(boundaryEMGeneric):: boundaryEMDirichlet
REAL(8):: potential REAL(8):: potential
CONTAINS CONTAINS
@ -1016,6 +1017,7 @@ MODULE moduleMesh
end interface end interface
! Dirichlet time: time-dependent potential value
TYPE, EXTENDS(boundaryEMGeneric):: boundaryEMDirichletTime TYPE, EXTENDS(boundaryEMGeneric):: boundaryEMDirichletTime
real(8):: potential real(8):: potential
real(8):: timeFactor real(8):: timeFactor
@ -1044,6 +1046,33 @@ MODULE moduleMesh
end interface end interface
! Floating: Floating surface, ie, zero net current
type, extends(boundaryEMGeneric):: boundaryEMFloating
real(8):: potential
contains
! boundaryEMGeneric DEFERRED PROCEDURES
procedure, pass:: apply => applyFloating
end type boundaryEMFloating
interface
module subroutine initFloating(self, config, object)
use json_module
class(boundaryEMGeneric), allocatable, intent(inout):: self
type(json_file), intent(inout):: config
character(:), allocatable, intent(in):: object
end subroutine initFloating
module subroutine applyFloating(self, vectorF)
class(boundaryEMFloating), intent(in):: self
real(8), intent(inout):: vectorF(:)
end subroutine applyFloating
end interface
! Container for boundary conditions ! Container for boundary conditions
TYPE:: boundaryEMCont TYPE:: boundaryEMCont
CLASS(boundaryEMGeneric), ALLOCATABLE:: obj CLASS(boundaryEMGeneric), ALLOCATABLE:: obj

View file

@ -1,30 +1,7 @@
submodule(moduleMesh) boundaryEM submodule(moduleMesh) boundaryEM
CONTAINS CONTAINS
module function boundaryEMName_to_Index(boundaryName) result(bp) ! Dirichlet boundary condition
use moduleErrors ! Init
implicit none
character(:), allocatable:: boundaryName
integer:: bp
integer:: b
bp = 0
do b = 1, nBoundariesEM
if (boundaryName == boundariesEM(b)%obj%name) then
bp = boundariesEM(b)%obj%n
end if
end do
if (bp == 0) then
call criticalError('Boundary ' // boundaryName // ' not found', 'boundaryEMName_to_Index')
end if
end function boundaryEMName_to_Index
! Initialize Dirichlet boundary condition
module SUBROUTINE initDirichlet(self, config, object) module SUBROUTINE initDirichlet(self, config, object)
use json_module use json_module
USE moduleRefParam, ONLY: Volt_ref USE moduleRefParam, ONLY: Volt_ref
@ -51,7 +28,25 @@ submodule(moduleMesh) boundaryEM
end subroutine initDirichlet end subroutine initDirichlet
! Initialize Dirichlet boundary condition ! Apply
module SUBROUTINE applyDirichlet(self, vectorF)
USE moduleMesh
IMPLICIT NONE
CLASS(boundaryEMDirichlet), INTENT(in):: self
REAL(8), INTENT(inout):: vectorF(:)
integer:: n
DO n = 1, self%nNodes
self%nodes(n)%obj%emData%phi = self%potential
vectorF(self%nodes(n)%obj%n) = self%nodes(n)%obj%emData%phi
END DO
END SUBROUTINE applyDirichlet
! Dirichlet time-dependent boundary condition
! Init
module subroutine initDirichletTime(self, config, object) module subroutine initDirichletTime(self, config, object)
use json_module use json_module
use moduleRefParam, ONLY: Volt_ref, ti_ref use moduleRefParam, ONLY: Volt_ref, ti_ref
@ -96,24 +91,7 @@ submodule(moduleMesh) boundaryEM
END SUBROUTINE initDirichletTime END SUBROUTINE initDirichletTime
!Apply Dirichlet boundary condition to the poisson equation ! Apply
module SUBROUTINE applyDirichlet(self, vectorF)
USE moduleMesh
IMPLICIT NONE
CLASS(boundaryEMDirichlet), INTENT(in):: self
REAL(8), INTENT(inout):: vectorF(:)
integer:: n
DO n = 1, self%nNodes
self%nodes(n)%obj%emData%phi = self%potential
vectorF(self%nodes(n)%obj%n) = self%nodes(n)%obj%emData%phi
END DO
END SUBROUTINE applyDirichlet
!Apply Dirichlet boundary condition with time temporal profile
module SUBROUTINE applyDirichletTime(self, vectorF) module SUBROUTINE applyDirichletTime(self, vectorF)
USE moduleMesh USE moduleMesh
USE moduleCaseParam, ONLY: timeStep, tauMin USE moduleCaseParam, ONLY: timeStep, tauMin
@ -131,7 +109,8 @@ submodule(moduleMesh) boundaryEM
END SUBROUTINE applyDirichletTime END SUBROUTINE applyDirichletTime
module subroutine updateDirichletTime(self) ! Update
subroutine updateDirichletTime(self)
implicit none implicit none
class(boundaryEMGeneric), intent(inout):: self class(boundaryEMGeneric), intent(inout):: self
@ -144,6 +123,90 @@ submodule(moduleMesh) boundaryEM
end subroutine updateDirichletTime end subroutine updateDirichletTime
! Floating surface
! Init
module subroutine initFloating(self, config, object)
use json_module
use moduleRefParam, only: Volt_ref
use moduleErrors
implicit none
class(boundaryEMGeneric), allocatable, intent(inout):: self
type(json_file), intent(inout):: config
character(:), allocatable, intent(in):: object
real(8):: potential
logical:: found
select type(self)
type is(boundaryEMFloating)
call config%get(object // '.potential', potential, found)
if (.not. found) then
call criticalError('Required parameter "potential" for Floating boundary condition not found', &
'readBoundaryEM')
end if
self%potential = potential / Volt_ref
self%update => updateFloating
end select
end subroutine initFloating
! Apply
module subroutine applyFloating(self, vectorF)
use moduleMesh
implicit none
class(boundaryEMFloating), intent(in):: self
real(8), intent(inout):: vectorF(:)
integer:: n
do n = 1, self%nNodes
self%nodes(n)%obj%emData%phi = self%potential
vectorF(self%nodes(n)%obj%n) = self%nodes(n)%obj%emData%phi
end do
end subroutine applyFloating
! Update
subroutine updateFloating(self)
class(boundaryEMGeneric), intent(inout):: self
select type(self)
type is(boundaryEMFloating)
end select
end subroutine updateFloating
! Get the index of the boundary based on the name
module function boundaryEMName_to_Index(boundaryName) result(bp)
use moduleErrors
implicit none
character(:), allocatable:: boundaryName
integer:: bp
integer:: b
bp = 0
do b = 1, nBoundariesEM
if (boundaryName == boundariesEM(b)%obj%name) then
bp = boundariesEM(b)%obj%n
end if
end do
if (bp == 0) then
call criticalError('Boundary ' // boundaryName // ' not found', 'boundaryEMName_to_Index')
end if
end function boundaryEMName_to_Index
! Update all EM boundaries
module subroutine boundariesEM_update() module subroutine boundariesEM_update()
implicit none implicit none