From 73f585ed8b130072361478b6059f763992171523 Mon Sep 17 00:00:00 2001 From: JGonzalez Date: Wed, 8 Apr 2026 15:47:36 +0200 Subject: [PATCH] Inout working --- src/modules/init/moduleInput.f90 | 1 + src/modules/mesh/moduleMesh.f90 | 9 +-- src/modules/mesh/moduleMesh@boundaryEM.f90 | 66 +++++++++++++++++++--- src/modules/output/moduleOutput.f90 | 1 + src/modules/solver/moduleSolver.f90 | 1 + 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/modules/init/moduleInput.f90 b/src/modules/init/moduleInput.f90 index 575b372..19a4369 100644 --- a/src/modules/init/moduleInput.f90 +++ b/src/modules/init/moduleInput.f90 @@ -493,6 +493,7 @@ MODULE moduleInput CALL config%get(object // '.numColl', collOutput, found) CALL config%get(object // '.EMField', emOutput, found) call config%get(object // '.boundariesParticle', boundaryParticleOutput, found) + call config%get(object // '.boundariesEM', boundaryEMOutput, found) call config%get(object // '.injects', injectOutput, found) CALL config%get(object // '.triggerCPUTime', triggerCPUTime, found) diff --git a/src/modules/mesh/moduleMesh.f90 b/src/modules/mesh/moduleMesh.f90 index aa20a2b..e257cf2 100644 --- a/src/modules/mesh/moduleMesh.f90 +++ b/src/modules/mesh/moduleMesh.f90 @@ -963,8 +963,8 @@ MODULE moduleMesh integer:: nNodes type(meshNodePointer), allocatable:: nodes(:) - procedure(updateEM_interface), pointer, pass:: update => null() - procedure(printEM_interface), pointer, pass:: print => null() + procedure(updateEM_interface), pointer, pass:: update => null() + procedure(printEMboundary_interface), pointer, pass:: print => null() contains procedure(applyEM_interface), deferred, pass:: apply @@ -989,13 +989,13 @@ MODULE moduleMesh end subroutine updateEM_interface ! Write the values of the particle boundary model - subroutine printEM_interface(self, fileID) + subroutine printEMboundary_interface(self, fileID) import boundaryEMGeneric class(boundaryEMGeneric), intent(inout):: self integer, intent(in):: fileID - end subroutine printEM_interface + end subroutine printEMboundary_interface end interface @@ -1060,6 +1060,7 @@ MODULE moduleMesh type, extends(boundaryEMGeneric):: boundaryEMFloating real(8):: potential real(8):: invC ! Inverse of the capacitance of the surface + real(8):: charge ! Charge accumulated on surface type(meshEdgePointer), allocatable:: edges(:) !Array with edges contains ! boundaryEMGeneric DEFERRED PROCEDURES diff --git a/src/modules/mesh/moduleMesh@boundaryEM.f90 b/src/modules/mesh/moduleMesh@boundaryEM.f90 index e45f996..43202b4 100644 --- a/src/modules/mesh/moduleMesh@boundaryEM.f90 +++ b/src/modules/mesh/moduleMesh@boundaryEM.f90 @@ -159,8 +159,12 @@ submodule(moduleMesh) boundaryEM ! Inverse of non-dimensional capacitance self%invC = 1.0d0 / (capacitance / (eps_0 * L_ref)) + self%charge = 0.0d0 + self%update => updateFloating + self%print => writeFloating + allocate(self%edges(0)) end select @@ -196,9 +200,8 @@ submodule(moduleMesh) boundaryEM class(meshEdge), pointer:: edge real(8), allocatable:: mom_nodes(:) class(meshNode), pointer:: node - real(8):: mom_center, edgeDensityCurrent, totalCurrent + real(8):: mom_center, edgeDensityCurrent - totalCurrent = 0.0d0 select type(self) type is(boundaryEMFloating) do e = 1, size(self%edges) @@ -224,20 +227,34 @@ submodule(moduleMesh) boundaryEM end do - totalCurrent = totalCurrent + edgeDensityCurrent * edge%surface + ! Accumulate charge of speceis on surface + self%charge = self%charge + edgeDensityCurrent * edge%surface * tauMin end do - self%potential = self%potential + self%invC * totalCurrent * tauMin - - ! print *, totalCurrent, self%potential + self%potential = self%charge * self%invC end select end subroutine updateFloating ! Write - subroutine writeFloating() + subroutine writeFloating(self, fileID) + use moduleOutput, only: fmtColReal + use moduleConstParam, only: qe + use moduleRefParam, only: Volt_ref + implicit none + + class(boundaryEMGeneric), intent(inout):: self + integer, intent(in):: fileID + + write(fileID, '(A)') self%name + select type(self) + type is(boundaryEMFloating) + write(fileID, '(A,",",A)') 'Total charge', 'Potential (V)' + write(fileID, '('//fmtColReal//','//fmtColReal//')') self%charge * qe, self%potential * Volt_ref + + end select end subroutine writeFloating @@ -274,7 +291,7 @@ submodule(moduleMesh) boundaryEM do b = 1, nBoundariesEM if (associated(boundariesEM(b)%obj%update)) then - call boundariesEM(b)%obj%update + call boundariesEM(b)%obj%update() end if @@ -282,4 +299,37 @@ submodule(moduleMesh) boundaryEM end subroutine boundariesEM_update + ! Write all EM boundaries + module subroutine boundariesEM_write() + use moduleCaseparam, only: timeStep + use moduleOutput, only: fileID_boundaryEM, & + formatFileName, & + informFileCreation,& + boundaryEMOutput,& + generateFilePath, & + prefix + implicit none + + integer:: b + character(:), allocatable:: fileName + + if (boundaryEMOutput) then + fileName = formatFileName(prefix, 'boundariesEM', 'csv', timeStep) + call informFileCreation(fileName) + open(fileID_boundaryEM, file = generateFilePath(fileName)) + + do b = 1, nBoundariesEM + if (associated(boundariesEM(b)%obj%update)) then + call boundariesEM(b)%obj%print(fileID_boundaryEM) + + end if + + end do + + close(fileID_boundaryEM) + + end if + + end subroutine boundariesEM_write + end submodule boundaryEM diff --git a/src/modules/output/moduleOutput.f90 b/src/modules/output/moduleOutput.f90 index d9fb91f..bf75c27 100644 --- a/src/modules/output/moduleOutput.f90 +++ b/src/modules/output/moduleOutput.f90 @@ -14,6 +14,7 @@ MODULE moduleOutput LOGICAL:: collOutput = .FALSE. LOGICAL:: emOutput = .FALSE. logical:: boundaryParticleOutput = .false. + logical:: boundaryEMOutput = .false. logical:: injectOutput = .false. ! Prefix for iteration files diff --git a/src/modules/solver/moduleSolver.f90 b/src/modules/solver/moduleSolver.f90 index 635c9eb..33e3408 100644 --- a/src/modules/solver/moduleSolver.f90 +++ b/src/modules/solver/moduleSolver.f90 @@ -548,6 +548,7 @@ MODULE moduleSolver ! Output of boundaries call boundariesParticle_write() + call boundariesEM_write() ! Output of inejcts call writeInjects()