Subroutine for reading mesh

It is now complete and working. I also added some minor improvements to moduleMesh.f90 using 'associate' to practice.

I noticed there are a lot of things (allocating K, for example) that are common for all meshes and should be moved to a general module.
This commit is contained in:
Jorge Gonzalez 2026-01-22 14:06:20 +01:00
commit 3083e20ff7
2 changed files with 46 additions and 14 deletions

View file

@ -80,8 +80,18 @@ module moduleMeshInputText
end if
self%numNodes = nNodes
self%numCells = nNodes - 1
allocate(self%nodes(1:self%numNodes))
SELECT TYPE(self)
TYPE IS(meshParticles)
ALLOCATE(self%K(1:self%numNodes, 1:self%numNodes))
ALLOCATE(self%IPIV(1:self%numNodes, 1:self%numNodes))
self%K = 0.D0
self%IPIV = 0
END SELECT
self%numCells = nNodes - 1
allocate(self%cells(1:self%numCells))
select type(self)
@ -142,12 +152,33 @@ module moduleMeshInputText
end do
!Allocate cells
n = 1
allocate(p(1:2))
do c = 1, self%numCells
p(1) = n
n = n + 1
p(2) = n
select case(self%geometry)
case("Cart")
allocate(meshCell1DCartSegm:: self%cells(c)%obj)
case("Rad")
allocate(meshCell1DRadSegm:: self%cells(c)%obj)
end select
call self%cells(c)%obj%init(c, p, self%nodes)
end do
deallocate(p)
close(fileID)
!Call mesh connectivity
CALL self%connectMesh
end subroutine readText
subroutine readInitialText(filename, density, velocity, temperature)

View file

@ -499,28 +499,29 @@ MODULE moduleMesh
IMPLICIT NONE
CLASS(meshParticles), INTENT(inout):: self
INTEGER:: e
INTEGER:: nNodes
INTEGER:: c
INTEGER, ALLOCATABLE:: n(:)
REAL(8), ALLOCATABLE:: localK(:,:)
INTEGER:: i, j
DO e = 1, self%numCells
nNodes = self%cells(e)%obj%nNodes
ALLOCATE(n(1:nNodes))
ALLOCATE(localK(1:nNodes, 1:nNodes))
n = self%cells(e)%obj%getNodes(nNodes)
localK = self%cells(e)%obj%elemK(nNodes)
DO c = 1, self%numCells
associate(nNodes => self%cells(c)%obj%nNodes)
ALLOCATE(n(1:nNodes))
ALLOCATE(localK(1:nNodes, 1:nNodes))
n = self%cells(c)%obj%getNodes(nNodes)
localK = self%cells(c)%obj%elemK(nNodes)
DO i = 1, nNodes
DO j = 1, nNodes
self%K(n(i), n(j)) = self%K(n(i), n(j)) + localK(i, j)
DO i = 1, nNodes
DO j = 1, nNodes
self%K(n(i), n(j)) = self%K(n(i), n(j)) + localK(i, j)
END DO
END DO
END DO
DEALLOCATE(n, localK)
DEALLOCATE(n, localK)
end associate
END DO