From 7d4f4b98c37f86a8744fabc699bbba4253bc37e8 Mon Sep 17 00:00:00 2001 From: JGonzalez Date: Mon, 19 Jan 2026 15:37:31 +0100 Subject: [PATCH] Implementing input subroutines --- .../mesh/inout/text/moduleMeshInputText.f90 | 90 +++++++++++++++++-- src/modules/mesh/moduleMesh.f90 | 8 +- 2 files changed, 88 insertions(+), 10 deletions(-) diff --git a/src/modules/mesh/inout/text/moduleMeshInputText.f90 b/src/modules/mesh/inout/text/moduleMeshInputText.f90 index 4e29d03..f28de9c 100644 --- a/src/modules/mesh/inout/text/moduleMeshInputText.f90 +++ b/src/modules/mesh/inout/text/moduleMeshInputText.f90 @@ -41,19 +41,25 @@ module moduleMeshInputText class(meshGeneric), intent(inout):: self character(:), allocatable, intent(in):: filename !Dummy file, not used integer:: fileID, reason - CHARACTER(LEN=256):: line - real(8):: r !dummy 1D coordinate + character(len=256):: line + integer:: nNodes + real(8):: r(1:3) !dummy 3D coordinate integer:: physicalID + integer:: n, c + integer, allocatable:: p(:) + integer:: bt fileID = 10 open(fileID, file=trim(filename)) !Skip header - read(fileID) + read(fileID, *) + !Get number of nodes + nNodes = 0 do - read(fileID, *, iostat=reason) r, physicalID + read(fileID, *, iostat=reason) line if (reason > 0) then call criticalError('Error reading mesh file', 'readText') @@ -61,10 +67,82 @@ module moduleMeshInputText else if (reason < 0) then exit + else if (len(line) > 0) then + nNodes = nNodes + 1 + end if - write(*, *) r, physicalID - + end do + + if (nNodes == 0) then + call criticalError('No nodes read in mesh file', 'readText') + + end if + + self%numNodes = nNodes + self%numCells = nNodes - 1 + allocate(self%nodes(1:self%numNodes)) + allocate(self%cells(1:self%numCells)) + + select type(self) + type is (meshParticles) + self%numEdges = 2 + + allocate(self%edges(1:self%numEdges)) + + end select + + !Read the mesh now + rewind(fileID) + + !Skip header + read(fileID, *) + + !Allocate nodes and edges + do n = 1, self%numNodes + r = 0.D0 + + read(fileID, *) r(1), physicalID + + select case(self%geometry) + case("Cart") + allocate(meshNode1DCart:: self%nodes(n)%obj) + + case("Rad") + allocate(meshNode1DRad:: self%nodes(n)%obj) + + end select + + !Init nodes + call self%nodes(n)%obj%init(n, r) + + !Allocate edges if required) + select type(self) + type is (meshParticles) + if ((physicalID == 1) .or. (physicalID == 2)) then + select case(self%geometry) + case("Cart") + allocate(meshEdge1DCart:: self%edges(physicalID)%obj) + + case("Rad") + allocate(meshEdge1DRad:: self%edges(physicalID)%obj) + + end select + + allocate(p(1)) + p(1) = n + bt = getBoundaryId(physicalID) + call self%edges(physicalID)%obj%init(physicalID, p, physicalID, physicalID) + deallocate(p) + + end if + + end select + + end do + + !Allocate cells + do c = 1, self%numCells end do diff --git a/src/modules/mesh/moduleMesh.f90 b/src/modules/mesh/moduleMesh.f90 index 7ab3914..78cc772 100644 --- a/src/modules/mesh/moduleMesh.f90 +++ b/src/modules/mesh/moduleMesh.f90 @@ -344,10 +344,10 @@ MODULE moduleMesh !Array of cell elements TYPE(meshCellCont), ALLOCATABLE:: cells(:) !PROCEDURES SPECIFIC OF FILE TYPE - PROCEDURE(readMesh_interface), POINTER, PASS:: readMesh => NULL() - PROCEDURE(readInitial_interface), POINTER, NOPASS:: readInitial => NULL() - PROCEDURE(connectMesh_interface), POINTER, PASS:: connectMesh => NULL() - PROCEDURE(printColl_interface), POINTER, PASS:: printColl => NULL() + PROCEDURE(readMesh_interface), POINTER, PASS:: readMesh => NULL() + PROCEDURE(readInitial_interface), POINTER, NOPASS:: readInitial => NULL() + PROCEDURE(connectMesh_interface), POINTER, PASS:: connectMesh => NULL() + PROCEDURE(printColl_interface), POINTER, PASS:: printColl => NULL() CONTAINS !GENERIC PROCEDURES PROCEDURE, PASS:: doCollisions