From ce6b6a41a60fd69956d0f7147c0061dd5383b920 Mon Sep 17 00:00:00 2001 From: JGonzalez Date: Fri, 20 Feb 2026 09:50:42 +0100 Subject: [PATCH] New physical surfaces implemented --- src/modules/mesh/1DCart/moduleMesh1DCart.f90 | 20 +++--- src/modules/mesh/1DRad/moduleMesh1DRad.f90 | 20 +++--- src/modules/mesh/2DCart/moduleMesh2DCart.f90 | 21 +++--- src/modules/mesh/2DCyl/moduleMesh2DCyl.f90 | 21 +++--- src/modules/mesh/3DCart/moduleMesh3DCart.f90 | 8 ++- .../mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 | 6 +- .../mesh/inout/text/moduleMeshInputText.f90 | 7 +- .../mesh/inout/vtu/moduleMeshInputVTU.f90 | 1 - src/modules/mesh/moduleMesh.f90 | 26 ++++++- src/modules/mesh/moduleMesh@elements.f90 | 21 ++++++ src/modules/mesh/moduleMesh@surfaces.f90 | 70 +++++++++---------- 11 files changed, 122 insertions(+), 99 deletions(-) diff --git a/src/modules/mesh/1DCart/moduleMesh1DCart.f90 b/src/modules/mesh/1DCart/moduleMesh1DCart.f90 index e4ac1d7..ffc47da 100644 --- a/src/modules/mesh/1DCart/moduleMesh1DCart.f90 +++ b/src/modules/mesh/1DCart/moduleMesh1DCart.f90 @@ -98,7 +98,7 @@ MODULE moduleMesh1DCart !EDGE FUNCTIONS !Init edge element - SUBROUTINE initEdge1DCart(self, n, p, btPart, btEM) + SUBROUTINE initEdge1DCart(self, n, p, ps) USE moduleSpecies, only: nSpecies USE moduleErrors IMPLICIT NONE @@ -106,8 +106,8 @@ MODULE moduleMesh1DCart CLASS(meshEdge1DCart), INTENT(out):: self INTEGER, INTENT(in):: n INTEGER, INTENT(in):: p(:) - INTEGER, INTENT(in):: btPart(1:nSpecies) - integer, intent(in):: btEM + INTEGER, INTENT(in):: ps + integer:: ps_index REAL(8), DIMENSION(1:3):: r1 INTEGER:: s @@ -123,16 +123,12 @@ MODULE moduleMesh1DCart self%normal = (/ 1.D0, 0.D0, 0.D0 /) - !Boundary particle linking - allocate(self%boundariesParticle(1:nSpecies)) - !Assign functions to boundary - do s = 1, nSpecies - self%boundariesParticle(s)%obj => boundariesParticle(btPart(s))%obj + ! Get Physical Surface index based on input numering + ps_index = physicalSurface_to_index(ps) - end do - - ! Add nodes to EM boundary - call boundariesEMLinking(btEM)%model%addNodes(self%getNodes(self%nNodes)) + ! Add elements to physical surface + call physicalSurfaces(ps_index)%addEdge(self%n) + call physicalSurfaces(ps_index)%addNode(self%n1%n) end subroutine initEdge1DCart diff --git a/src/modules/mesh/1DRad/moduleMesh1DRad.f90 b/src/modules/mesh/1DRad/moduleMesh1DRad.f90 index edfece5..344925d 100644 --- a/src/modules/mesh/1DRad/moduleMesh1DRad.f90 +++ b/src/modules/mesh/1DRad/moduleMesh1DRad.f90 @@ -98,7 +98,7 @@ MODULE moduleMesh1DRad !EDGE FUNCTIONS !Init edge element - SUBROUTINE initEdge1DRad(self, n, p, btPart, btEM) + SUBROUTINE initEdge1DRad(self, n, p, ps) USE moduleSpecies, only:nSpecies USE moduleErrors IMPLICIT NONE @@ -106,8 +106,8 @@ MODULE moduleMesh1DRad CLASS(meshEdge1DRad), INTENT(out):: self INTEGER, INTENT(in):: n INTEGER, INTENT(in):: p(:) - INTEGER, INTENT(in):: btPart(1:nSpecies) - integer, intent(in):: btEM + INTEGER, INTENT(in):: ps + integer:: ps_index REAL(8), DIMENSION(1:3):: r1 INTEGER:: s @@ -123,16 +123,12 @@ MODULE moduleMesh1DRad self%normal = (/ 1.D0, 0.D0, 0.D0 /) - !Boundary particle linking - allocate(self%boundariesParticle(1:nSpecies)) - !Assign functions to boundary - do s = 1, nSpecies - self%boundariesParticle(s)%obj => boundariesParticle(btPart(s))%obj + ! Get Physical Surface index based on input numering + ps_index = physicalSurface_to_index(ps) - end do - - ! Add nodes to EM boundary - call boundariesEMLinking(btEM)%model%addNodes(self%getNodes(self%nNodes)) + ! Add elements to physical surface + call physicalSurfaces(ps_index)%addEdge(self%n) + call physicalSurfaces(ps_index)%addNode(self%n1%n) end subroutine initEdge1DRad diff --git a/src/modules/mesh/2DCart/moduleMesh2DCart.f90 b/src/modules/mesh/2DCart/moduleMesh2DCart.f90 index f928f7f..50a0543 100644 --- a/src/modules/mesh/2DCart/moduleMesh2DCart.f90 +++ b/src/modules/mesh/2DCart/moduleMesh2DCart.f90 @@ -133,7 +133,7 @@ MODULE moduleMesh2DCart !EDGE FUNCTIONS !Init edge element - SUBROUTINE initEdge2DCart(self, n, p, btPart, btEm) + SUBROUTINE initEdge2DCart(self, n, p, ps) USE moduleSpecies, only:nSpecies USE moduleErrors IMPLICIT NONE @@ -141,8 +141,8 @@ MODULE moduleMesh2DCart CLASS(meshEdge2DCart), INTENT(out):: self INTEGER, INTENT(in):: n INTEGER, INTENT(in):: p(:) - INTEGER, INTENT(in):: btPart(1:nSpecies) - integer, intent(in):: btEM + INTEGER, INTENT(in):: ps + integer:: ps_index REAL(8), DIMENSION(1:3):: r1, r2 INTEGER:: s @@ -162,16 +162,13 @@ MODULE moduleMesh2DCart 0.D0 /) self%normal = self%normal/NORM2(self%normal) - !Boundary particle linking - allocate(self%boundariesParticle(1:nSpecies)) - !Assign functions to boundary - do s = 1, nSpecies - self%boundariesParticle(s)%obj => boundariesParticle(btPart(s))%obj + ! Get Physical Surface index based on input numering + ps_index = physicalSurface_to_index(ps) - end do - - ! Add nodes to EM boundary - call boundariesEMLinking(btEM)%model%addNodes(self%getNodes(self%nNodes)) + ! Add elements to physical surface + call physicalSurfaces(ps_index)%addEdge(self%n) + call physicalSurfaces(ps_index)%addNode(self%n1%n) + call physicalSurfaces(ps_index)%addNode(self%n2%n) END SUBROUTINE initEdge2DCart diff --git a/src/modules/mesh/2DCyl/moduleMesh2DCyl.f90 b/src/modules/mesh/2DCyl/moduleMesh2DCyl.f90 index 137fd68..10f1790 100644 --- a/src/modules/mesh/2DCyl/moduleMesh2DCyl.f90 +++ b/src/modules/mesh/2DCyl/moduleMesh2DCyl.f90 @@ -133,7 +133,7 @@ MODULE moduleMesh2DCyl !EDGE FUNCTIONS !Init edge element - SUBROUTINE initEdge2DCyl(self, n, p, btPart, btEM) + SUBROUTINE initEdge2DCyl(self, n, p, ps) USE moduleSpecies USE moduleErrors USE moduleConstParam, ONLY: PI @@ -142,8 +142,8 @@ MODULE moduleMesh2DCyl CLASS(meshEdge2DCyl), INTENT(out):: self INTEGER, INTENT(in):: n INTEGER, INTENT(in):: p(:) - INTEGER, INTENT(in):: btPart(1:nsPecies) - integer, intent(in):: btEM + INTEGER, INTENT(in):: ps + integer:: ps_index REAL(8), DIMENSION(1:3):: r1, r2 INTEGER:: s @@ -171,16 +171,13 @@ MODULE moduleMesh2DCyl 0.D0 /) self%normal = self%normal/NORM2(self%normal) - !Boundary particle linking - allocate(self%boundariesParticle(1:nSpecies)) - !Assign functions to boundary - do s = 1, nSpecies - self%boundariesParticle(s)%obj => boundariesParticle(btPart(s))%obj + ! Get Physical Surface index based on input numering + ps_index = physicalSurface_to_index(ps) - end do - - ! Add nodes to EM boundary - call boundariesEMLinking(btEM)%model%addNodes(self%getNodes(self%nNodes)) + ! Add elements to physical surface + call physicalSurfaces(ps_index)%addEdge(self%n) + call physicalSurfaces(ps_index)%addNode(self%n1%n) + call physicalSurfaces(ps_index)%addNode(self%n2%n) END SUBROUTINE initEdge2DCyl diff --git a/src/modules/mesh/3DCart/moduleMesh3DCart.f90 b/src/modules/mesh/3DCart/moduleMesh3DCart.f90 index d891ec7..b50712a 100644 --- a/src/modules/mesh/3DCart/moduleMesh3DCart.f90 +++ b/src/modules/mesh/3DCart/moduleMesh3DCart.f90 @@ -144,8 +144,14 @@ MODULE moduleMesh3DCart self%surface = 1.D0/L_ref**2 !TODO: FIX THIS WHEN MOVING TO 3D + ! Get Physical Surface index based on input numering ps_index = physicalSurface_to_index(ps) - + + ! Add elements to physical surface + call physicalSurfaces(ps_index)%addEdge(self%n) + call physicalSurfaces(ps_index)%addNode(self%n1%n) + call physicalSurfaces(ps_index)%addNode(self%n2%n) + call physicalSurfaces(ps_index)%addNode(self%n3%n) END SUBROUTINE initEdge3DCartTria diff --git a/src/modules/mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 b/src/modules/mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 index cbf1dd7..c3e2d83 100644 --- a/src/modules/mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 +++ b/src/modules/mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 @@ -37,7 +37,6 @@ MODULE moduleMeshInputGmsh2 REAL(8):: r(1:3) !3 generic coordinates INTEGER, ALLOCATABLE:: p(:) !Array for nodes INTEGER:: e = 0, n = 0, eTemp = 0, elemType = 0 - integer:: btPart = 0, btEM = 0 INTEGER:: totalNumElem INTEGER:: numEdges INTEGER:: boundaryType @@ -199,11 +198,8 @@ MODULE moduleMeshInputGmsh2 END SELECT - !Associate boundary condition procedure. - btPart = physicalSurface_to_id(boundariesParticleLinking,boundaryType) - btEM = physicalSurface_to_id(boundariesEMLinking, boundaryType) + CALL self%edges(e)%obj%init(n, p, boundaryType) - CALL self%edges(e)%obj%init(n, p, boundariesParticleLinking(btPart)%speciesIndex, btEM) DEALLOCATE(p) END DO diff --git a/src/modules/mesh/inout/text/moduleMeshInputText.f90 b/src/modules/mesh/inout/text/moduleMeshInputText.f90 index 2f685ea..9946bba 100644 --- a/src/modules/mesh/inout/text/moduleMeshInputText.f90 +++ b/src/modules/mesh/inout/text/moduleMeshInputText.f90 @@ -47,7 +47,6 @@ module moduleMeshInputText integer:: physicalID integer:: n, c integer, allocatable:: p(:) - integer:: btPart, btEM fileID = 10 @@ -141,10 +140,8 @@ module moduleMeshInputText allocate(p(1)) p(1) = n - !Associate boundary condition procedure. - btPart = physicalSurface_to_id(boundariesParticleLinking, physicalID) - btEM = physicalSurface_to_id(boundariesEMLinking, physicalID) - call self%edges(physicalID)%obj%init(physicalID, p, boundariesParticleLinking(btPart)%speciesIndex, btEM) + + call self%edges(physicalID)%obj%init(physicalID, p, physicalID) deallocate(p) diff --git a/src/modules/mesh/inout/vtu/moduleMeshInputVTU.f90 b/src/modules/mesh/inout/vtu/moduleMeshInputVTU.f90 index 508f453..e60e4b1 100644 --- a/src/modules/mesh/inout/vtu/moduleMeshInputVTU.f90 +++ b/src/modules/mesh/inout/vtu/moduleMeshInputVTU.f90 @@ -173,7 +173,6 @@ MODULE moduleMeshInputVTU REAL(8), ALLOCATABLE, DIMENSION(:):: coordinates INTEGER:: n, e, c INTEGER, ALLOCATABLE:: p(:) - INTEGER:: btPart, btEM fileID = 10 diff --git a/src/modules/mesh/moduleMesh.f90 b/src/modules/mesh/moduleMesh.f90 index 9132f39..2514f35 100644 --- a/src/modules/mesh/moduleMesh.f90 +++ b/src/modules/mesh/moduleMesh.f90 @@ -71,7 +71,7 @@ MODULE moduleMesh ! Array of pointers to nodes. TYPE:: meshNodePointer CLASS(meshNode), POINTER:: obj - CONTAINS + contains procedure, pass:: meshNodePointer_equal_type_type procedure, pass:: meshNodePointer_equal_type_int generic:: operator(==) => meshNodePointer_equal_type_type, meshNodePointer_equal_type_int @@ -136,14 +136,14 @@ MODULE moduleMesh ABSTRACT INTERFACE !Inits the edge parameters - subroutine initEdge_interface(self, n, p, physicalSurface) + subroutine initEdge_interface(self, n, p, ps) use moduleSpecies, only:nSpecies import:: meshEdge class(meshEdge), intent(out):: self integer, intent(in):: n integer, intent(in):: p(:) - integer, intent(in):: physicalSurface + integer, intent(in):: ps end subroutine initEdge_interface @@ -184,9 +184,29 @@ MODULE moduleMesh ! Array of pointers to edges. type:: meshEdgePointer class(meshEdge), pointer:: obj + contains + procedure, pass:: meshEdgePointer_equal_type_type + procedure, pass:: meshEdgePointer_equal_type_int + generic:: operator(==) => meshEdgePointer_equal_type_type, meshEdgePointer_equal_type_int end type meshEdgePointer + interface + module function meshEdgePointer_equal_type_type(self, other) result(isEqual) + class(meshEdgePointer), intent(in):: self, other + logical:: isEqual + + end function meshEdgePointer_equal_type_type + + module function meshEdgePointer_equal_type_int(self, other) result(isEqual) + class(meshEdgePointer), intent(in):: self + integer, intent(in):: other + logical:: isEqual + + end function meshEdgePointer_equal_type_int + + end interface + !Parent of cell element TYPE, PUBLIC, ABSTRACT, EXTENDS(meshElement):: meshCell !Number of nodes in the cell diff --git a/src/modules/mesh/moduleMesh@elements.f90 b/src/modules/mesh/moduleMesh@elements.f90 index 81c03e3..211a668 100644 --- a/src/modules/mesh/moduleMesh@elements.f90 +++ b/src/modules/mesh/moduleMesh@elements.f90 @@ -39,6 +39,27 @@ submodule(moduleMesh) elements end function meshNodePointer_equal_type_int + function meshEdgePointer_equal_type_type(self, other) result(isEqual) + implicit none + + class(meshEdgePointer), intent(in):: self, other + logical:: isEqual + + isEqual = self%obj%n == other%obj%n + + end function meshEdgePointer_equal_type_type + + function meshEdgePointer_equal_type_int(self, other) result(isEqual) + implicit none + + class(meshEdgePointer), intent(in):: self + integer, intent(in):: other + logical:: isEqual + + isEqual = self%obj%n == other + + end function meshEdgePointer_equal_type_int + !Constructs the global K matrix SUBROUTINE constructGlobalK(self) IMPLICIT NONE diff --git a/src/modules/mesh/moduleMesh@surfaces.f90 b/src/modules/mesh/moduleMesh@surfaces.f90 index e3d95dc..e7b13c7 100644 --- a/src/modules/mesh/moduleMesh@surfaces.f90 +++ b/src/modules/mesh/moduleMesh@surfaces.f90 @@ -24,30 +24,29 @@ submodule(moduleMesh) surfaces class(physicalSurface), intent(inout):: self integer, intent(in):: node - integer:: n, nn + integer:: nn logical:: inArray + type(meshNodePointer):: nodeToAdd - associate(nodeToAdd => mesh%nodes(node)%obj) - inArray = .false. - ! I cannot use the procedure 'any' for this - do nn = 1 , size(self%nodes) - IF (self%nodes(nn)%obj == nodeToAdd) THEN - ! Node already in array - inArray = .true. - exit - - end if - - end do - - if (.not. inArray) then - ! If not, add element to array of nodes - self%nodes = [self%nodes, nodeToAdd] + nodeToAdd%obj => mesh%nodes(node)%obj + inArray = .false. + ! I cannot use the procedure 'any' for this + do nn = 1 , size(self%nodes) + IF (self%nodes(nn) == nodeToAdd) THEN + ! Node already in array + inArray = .true. + exit end if - end associate + end do + + if (.not. inArray) then + ! If not, add element to array of nodes + self%nodes = [self%nodes, nodeToAdd] + + end if end subroutine addNode @@ -56,30 +55,29 @@ submodule(moduleMesh) surfaces class(physicalSurface), intent(inout):: self integer, intent(in):: edge - integer:: n, nn + integer:: nn logical:: inArray + type(meshEdgePointer):: edgeToAdd - associate(edgeToAdd => mesh%edges(edge)%obj) - inArray = .false. - ! I cannot use the procedure 'any' for this - do nn = 1 , size(self%edges) - IF (self%edges(nn) == edgeToAdd) THEN - ! Node already in array - inArray = .true. - exit - - end if - - end do - - if (.not. inArray) then - ! If not, add element to array of nodes - self%edges = [self%edges, edgeToAdd] + edgeToAdd %obj => mesh%edges(edge)%obj + inArray = .false. + ! I cannot use the procedure 'any' for this + do nn = 1 , size(self%edges) + IF (self%edges(nn) == edgeToAdd) THEN + ! Node already in array + inArray = .true. + exit end if - end associate + end do + + if (.not. inArray) then + ! If not, add element to array of nodes + self%edges = [self%edges, edgeToAdd] + + end if end subroutine addEdge