From 0109dc2f067a0d7285e5b8c770cc3060048a8a81 Mon Sep 17 00:00:00 2001 From: JGonzalez Date: Wed, 11 Mar 2026 19:15:58 +0100 Subject: [PATCH] Trying to organise output better --- src/makefile | 1 - .../mesh/inout/0D/moduleMeshOutput0D.f90 | 30 +++--- .../inout/gmsh2/moduleMeshOutputGmsh2.f90 | 80 ++++++++-------- src/modules/mesh/inout/makefile | 2 +- .../mesh/inout/moduleMeshInoutCommon.f90 | 74 --------------- .../mesh/inout/text/moduleMeshOutputText.f90 | 14 +-- .../mesh/inout/vtu/moduleMeshOutputVTU.f90 | 91 +++++++++---------- src/modules/mesh/moduleMesh.f90 | 6 +- .../mesh/moduleMesh@boundaryParticle.f90 | 28 +++++- src/modules/output/moduleOutput.f90 | 59 +++++++++++- src/modules/solver/moduleSolver.f90 | 3 +- 11 files changed, 196 insertions(+), 192 deletions(-) delete mode 100644 src/modules/mesh/inout/moduleMeshInoutCommon.f90 diff --git a/src/makefile b/src/makefile index e422355..50fb18a 100644 --- a/src/makefile +++ b/src/makefile @@ -6,7 +6,6 @@ OBJECTS = $(OBJDIR)/moduleMesh.o $(OBJDIR)/moduleMeshCommon.o $(OBJDIR)/moduleCo $(OBJDIR)/moduleCollisions.o $(OBJDIR)/moduleTable.o $(OBJDIR)/moduleParallel.o \ $(OBJDIR)/moduleEM.o $(OBJDIR)/moduleRandom.o $(OBJDIR)/moduleMath.o \ $(OBJDIR)/moduleProbe.o $(OBJDIR)/moduleAverage.o $(OBJDIR)/moduleCoulomb.o \ - $(OBJDIR)/moduleMeshInoutCommon.o \ $(OBJDIR)/moduleMeshInputVTU.o $(OBJDIR)/moduleMeshOutputVTU.o \ $(OBJDIR)/moduleMeshInputGmsh2.o $(OBJDIR)/moduleMeshOutputGmsh2.o \ $(OBJDIR)/moduleMeshInput0D.o $(OBJDIR)/moduleMeshOutput0D.o \ diff --git a/src/modules/mesh/inout/0D/moduleMeshOutput0D.f90 b/src/modules/mesh/inout/0D/moduleMeshOutput0D.f90 index c0dcfbb..f0ca6b6 100644 --- a/src/modules/mesh/inout/0D/moduleMeshOutput0D.f90 +++ b/src/modules/mesh/inout/0D/moduleMeshOutput0D.f90 @@ -15,22 +15,24 @@ MODULE moduleMeshOutput0D CHARACTER(:), ALLOCATABLE:: fileName DO i = 1, nSpecies - fileName='OUTPUT_' // species(i)%obj%name // '.dat' + fileName = formatFileName('Output', species(i)%obj%name, 'csv') IF (timeStep == 0) THEN - OPEN(20, file = path // folder // '/' // fileName, action = 'write') - WRITE(20, "(A1, 14X, A5, A20, 40X, A20, 2(A20))") "#","t (s)","density (m^-3)", "velocity (m/s)", & - "pressure (Pa)", "temperature (K)" - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName + OPEN(20, file = generateFilePath(fileName), action = 'write') + WRITE(20, "(*("//fmtColStr//"))")'"t (s)"','"density (m^-3)"', & + '"velocity (m/s):0"', '"velocity (m/s):1"', '"velocity (m/s):2"', & + '"pressure (Pa)"', & + '"temperature (K)"' + call informFileCreation(fileName) CLOSE(20) END IF - OPEN(20, file = path // folder // '/' // fileName, position = 'append', action = 'write') + OPEN(20, file = generateFilePath(fileName), position = 'append', action = 'write') CALL calculateOutput(self%nodes(1)%obj%output(i), output, self%nodes(1)%obj%v, species(i)%obj) - WRITE(20, "(7(ES20.6E3))") REAL(timeStep)*tauMin*ti_ref, output%density, & - output%velocity, & - output%pressure, & - output%temperature + WRITE(20, "(*("//fmtColReal//"))") REAL(timeStep)*tauMin*ti_ref, output%density, & + output%velocity, & + output%pressure, & + output%temperature CLOSE(20) END DO @@ -51,15 +53,15 @@ MODULE moduleMeshOutput0D fileName='OUTPUT_Collisions.dat' IF (timeStep == tInitial) THEN - OPEN(20, file = path // folder // '/' // fileName, action = 'write') + OPEN(20, file = generateFilePath(fileName), action = 'write') WRITE(20, "(A1, 14X, A5, A20)") "#","t (s)","collisions" - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName + call informFileCreation(fileName) CLOSE(20) END IF - OPEN(20, file = path // folder // '/' // fileName, position = 'append', action = 'write') - WRITE(20, "(ES20.6E3, 10I20)") REAL(timeStep)*tauMin*ti_ref, (self%cells(1)%obj%tallyColl(k)%tally, k=1,nCollPairs) + OPEN(20, file = generateFilePath(fileName), position = 'append', action = 'write') + WRITE(20, "("//fmtReal//", 10I20)") REAL(timeStep)*tauMin*ti_ref, (self%cells(1)%obj%tallyColl(k)%tally, k=1,nCollPairs) CLOSE(20) END SUBROUTINE printColl0D diff --git a/src/modules/mesh/inout/gmsh2/moduleMeshOutputGmsh2.f90 b/src/modules/mesh/inout/gmsh2/moduleMeshOutputGmsh2.f90 index 8176bb5..0ca61ad 100644 --- a/src/modules/mesh/inout/gmsh2/moduleMeshOutputGmsh2.f90 +++ b/src/modules/mesh/inout/gmsh2/moduleMeshOutputGmsh2.f90 @@ -16,6 +16,7 @@ MODULE moduleMeshOutputGmsh2 !Node data subroutines !Header SUBROUTINE writeGmsh2HeaderNodeData(fileID, title, iteration, time, dimensions, nNodes) + use moduleOutput IMPLICIT NONE INTEGER, INTENT(in):: fileID @@ -25,14 +26,14 @@ MODULE moduleMeshOutputGmsh2 WRITE(fileID, "(A)") '$NodeData' - WRITE(fileID, "(I10)") 1 + WRITE(fileID, "("//fmtInt//")") 1 WRITE(fileID, "(A1, A, A1)") '"' , title , '"' - WRITE(fileID, "(I10)") 1 - WRITE(fileID, "(ES20.6E3)") time - WRITE(fileID, "(I10)") 3 - WRITE(fileID, "(I10)") iteration - WRITE(fileID, "(I10)") dimensions - WRITE(fileID, "(I10)") nNodes + WRITE(fileID, "("//fmtInt//")") 1 + WRITE(fileID, "("//fmtReal//")") time + WRITE(fileID, "("//fmtInt//")") 3 + WRITE(fileID, "("//fmtInt//")") iteration + WRITE(fileID, "("//fmtInt//")") dimensions + WRITE(fileID, "("//fmtInt//")") nNodes END SUBROUTINE writeGmsh2HeaderNodeData @@ -49,6 +50,7 @@ MODULE moduleMeshOutputGmsh2 !Element data subroutines !Header SUBROUTINE writeGmsh2HeaderElementData(fileID, title, iteration, time, dimensions, nVols) + use moduleOutput IMPLICIT NONE INTEGER, INTENT(in):: fileID @@ -58,14 +60,14 @@ MODULE moduleMeshOutputGmsh2 WRITE(fileID, "(A)") '$ElementData' - WRITE(fileID, "(I10)") 1 + WRITE(fileID, "("//fmtInt//")") 1 WRITE(fileID, "(A1, A, A1)") '"' , title , '"' - WRITE(fileID, "(I10)") 1 - WRITE(fileID, "(ES20.6E3)") time - WRITE(fileID, "(I10)") 3 - WRITE(fileID, "(I10)") iteration - WRITE(fileID, "(I10)") dimensions - WRITE(fileID, "(I10)") nVols + WRITE(fileID, "("//fmtInt//")") 1 + WRITE(fileID, "("//fmtReal//")") time + WRITE(fileID, "("//fmtInt//")") 3 + WRITE(fileID, "("//fmtInt//")") iteration + WRITE(fileID, "("//fmtInt//")") dimensions + WRITE(fileID, "("//fmtInt//")") nVols END SUBROUTINE writeGmsh2HeaderElementData @@ -85,7 +87,6 @@ MODULE moduleMeshOutputGmsh2 USE moduleRefParam USE moduleSpecies USE moduleOutput - USE moduleMeshInoutCommon USE moduleCaseParam, ONLY: timeStep IMPLICIT NONE @@ -99,33 +100,33 @@ MODULE moduleMeshOutputGmsh2 DO i = 1, nSpecies fileName = formatFileName(prefix, species(i)%obj%name, 'msh', timeStep) - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - OPEN (60, file = path // folder // '/' // fileName) + call informFileCreation(fileName) + OPEN (60, file = generateFilePath(fileName)) CALL writeGmsh2HeaderMesh(60) CALL writeGmsh2HeaderNodeData(60, species(i)%obj%name // ' density (m^-3)', timeStep, time, 1, self%numNodes) DO n=1, self%numNodes CALL calculateOutput(self%nodes(n)%obj%output(i), output(n), self%nodes(n)%obj%v, species(i)%obj) - WRITE(60, "(I6,ES20.6E3)") n, output(n)%density + WRITE(60, "(I6,"//fmtReal//")") n, output(n)%density END DO CALL writeGmsh2FooterNodeData(60) CALL writeGmsh2HeaderNodeData(60, species(i)%obj%name // ' velocity (m s^-1)', timeStep, time, 3, self%numNodes) DO n=1, self%numNodes - WRITE(60, "(I6,3(ES20.6E3))") n, output(n)%velocity + WRITE(60, "(I6,3("//fmtReal//"))") n, output(n)%velocity END DO CALL writeGmsh2FooterNodeData(60) CALL writeGmsh2HeaderNodeData(60, species(i)%obj%name // ' Pressure (Pa)', timeStep, time, 1, self%numNodes) DO n=1, self%numNodes - WRITE(60, "(I6,3(ES20.6E3))") n, output(n)%pressure + WRITE(60, "(I6,3("//fmtReal//"))") n, output(n)%pressure END DO CALL writeGmsh2FooterNodeData(60) CALL writeGmsh2HeaderNodeData(60, species(i)%obj%name // ' Temperature (K)', timeStep, time, 1, self%numNodes) DO n=1, self%numNodes - WRITE(60, "(I6,3(ES20.6E3))") n, output(n)%temperature + WRITE(60, "(I6,3("//fmtReal//"))") n, output(n)%temperature END DO CALL writeGmsh2FooterNodeData(60) CLOSE (60) @@ -141,7 +142,6 @@ MODULE moduleMeshOutputGmsh2 USE moduleCaseParam USE moduleCollisions USE moduleOutput - USE moduleMeshInoutCommon IMPLICIT NONE CLASS(meshGeneric), INTENT(in):: self @@ -169,8 +169,8 @@ MODULE moduleMeshOutputGmsh2 time = DBLE(timeStep)*tauMin*ti_ref fileName = formatFileName(prefix, 'Collisions', 'msh', timeStep) - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - OPEN (60, file = path // folder // '/' // fileName) + call informFileCreation(fileName) + OPEN (60, file = generateFilePath(fileName)) CALL writeGmsh2HeaderMesh(60) @@ -180,7 +180,7 @@ MODULE moduleMeshOutputGmsh2 title = '"Pair ' // interactionMatrix(k)%sp_i%name // '-' // interactionMatrix(k)%sp_j%name // ' collision ' // cString CALL writeGmsh2HeaderElementData(60, title, timeStep, time, 1, self%numCells) DO n=1, self%numCells - WRITE(60, "(I6,I10)") n + numEdges, self%cells(n)%obj%tallyColl(k)%tally(c) + WRITE(60, "(I6,"//fmtInt//")") n + numEdges, self%cells(n)%obj%tallyColl(k)%tally(c) END DO CALL writeGmsh2FooterElementData(60) @@ -200,7 +200,6 @@ MODULE moduleMeshOutputGmsh2 USE moduleRefParam USE moduleCaseParam USE moduleOutput - USE moduleMeshInoutCommon IMPLICIT NONE CLASS(meshParticles), INTENT(in):: self @@ -215,8 +214,8 @@ MODULE moduleMeshOutputGmsh2 time = DBLE(timeStep)*tauMin*ti_ref fileName = formatFileName(prefix, 'EMField', 'msh', timeStep) - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - OPEN (20, file = path // folder // '/' // fileName) + call informFileCreation(fileName) + OPEN (20, file = generateFilePath(fileName)) CALL writeGmsh2HeaderMesh(20) @@ -251,7 +250,6 @@ MODULE moduleMeshOutputGmsh2 USE moduleSpecies USE moduleOutput USE moduleAverage - USE moduleMeshInoutCommon IMPLICIT NONE CLASS(meshParticles), INTENT(in):: self @@ -262,12 +260,12 @@ MODULE moduleMeshOutputGmsh2 DO i = 1, nSpecies fileName = formatFileName('Average_mean', species(i)%obj%name, 'msh') - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - OPEN (fileMean, file = path // folder // '/' // fileName) + call informFileCreation(fileName) + OPEN (fileMean, file = generateFilePath(fileName)) fileName = formatFileName('Average_deviation', species(i)%obj%name, 'msh') - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - OPEN (filedeviation, file = path // folder // '/' // fileName) + call informFileCreation(fileName) + OPEN (filedeviation, file = generateFilePath(fileName)) CALL writeGmsh2HeaderMesh(fileMean) CALL writeGmsh2HeaderMesh(fileDeviation) @@ -276,9 +274,9 @@ MODULE moduleMeshOutputGmsh2 CALL writeGmsh2HeaderNodeData(fileDeviation, species(i)%obj%name // ' density, sd (m^-3)', 0, 0.D0, 1, self%numNodes) DO n=1, self%numNodes CALL calculateOutput(averageScheme(n)%mean%output(i), outputMean(n), self%nodes(n)%obj%v, species(i)%obj) - WRITE(fileMean, "(I6,ES20.6E3)") n, outputMean(n)%density + WRITE(fileMean, "(I6,"//fmtReal//")") n, outputMean(n)%density CALL calculateOutput(averageScheme(n)%deviation%output(i), outputDeviation(n), self%nodes(n)%obj%v, species(i)%obj) - WRITE(fileDeviation, "(I6,ES20.6E3)") n, outputDeviation(n)%density + WRITE(fileDeviation, "(I6,"//fmtReal//")") n, outputDeviation(n)%density END DO CALL writeGmsh2FooterNodeData(fileMean) CALL writeGmsh2FooterNodeData(fileDeviation) @@ -286,8 +284,8 @@ MODULE moduleMeshOutputGmsh2 CALL writeGmsh2HeaderNodeData(fileMean, species(i)%obj%name // ' velocity, mean (m s^-1)', 0, 0.D0, 3, self%numNodes) CALL writeGmsh2HeaderNodeData(fileDeviation, species(i)%obj%name // ' velocity, sd (m s^-1)', 0, 0.D0, 3, self%numNodes) DO n=1, self%numNodes - WRITE(fileMean, "(I6,3(ES20.6E3))") n, outputMean(n)%velocity - WRITE(fileDeviation, "(I6,3(ES20.6E3))") n, outputDeviation(n)%velocity + WRITE(fileMean, "(I6,3("//fmtReal//"))") n, outputMean(n)%velocity + WRITE(fileDeviation, "(I6,3("//fmtReal//"))") n, outputDeviation(n)%velocity END DO CALL writeGmsh2FooterNodeData(fileMean) CALL writeGmsh2FooterNodeData(fileDeviation) @@ -295,8 +293,8 @@ MODULE moduleMeshOutputGmsh2 CALL writeGmsh2HeaderNodeData(fileMean, species(i)%obj%name // ' Pressure, mean (Pa)', 0, 0.D0, 1, self%numNodes) CALL writeGmsh2HeaderNodeData(fileDeviation, species(i)%obj%name // ' Pressure, sd (Pa)', 0, 0.D0, 1, self%numNodes) DO n=1, self%numNodes - WRITE(fileMean, "(I6,3(ES20.6E3))") n, outputMean(n)%pressure - WRITE(fileDeviation, "(I6,3(ES20.6E3))") n, outputDeviation(n)%pressure + WRITE(fileMean, "(I6,3("//fmtReal//"))") n, outputMean(n)%pressure + WRITE(fileDeviation, "(I6,3("//fmtReal//"))") n, outputDeviation(n)%pressure END DO CALL writeGmsh2FooterNodeData(fileMean) CALL writeGmsh2FooterNodeData(fileDeviation) @@ -304,8 +302,8 @@ MODULE moduleMeshOutputGmsh2 CALL writeGmsh2HeaderNodeData(fileMean, species(i)%obj%name // ' Temperature, mean (K)', 0, 0.D0, 1, self%numNodes) CALL writeGmsh2HeaderNodeData(fileDeviation, species(i)%obj%name // ' Temperature, sd (K)', 0, 0.D0, 1, self%numNodes) DO n=1, self%numNodes - WRITE(fileMean, "(I6,3(ES20.6E3))") n, outputMean(n)%temperature - WRITE(fileDeviation, "(I6,3(ES20.6E3))") n, outputDeviation(n)%temperature + WRITE(fileMean, "(I6,3("//fmtReal//"))") n, outputMean(n)%temperature + WRITE(fileDeviation, "(I6,3("//fmtReal//"))") n, outputDeviation(n)%temperature END DO CALL writeGmsh2FooterNodeData(fileMean) CALL writeGmsh2FooterNodeData(fileDeviation) diff --git a/src/modules/mesh/inout/makefile b/src/modules/mesh/inout/makefile index 1b8883d..37d2c95 100644 --- a/src/modules/mesh/inout/makefile +++ b/src/modules/mesh/inout/makefile @@ -1,6 +1,6 @@ all: vtu.o gmsh2.o 0D.o text.o -vtu.o: moduleMeshInoutCommon.o +vtu.o: $(MAKE) -C vtu all gmsh2.o: diff --git a/src/modules/mesh/inout/moduleMeshInoutCommon.f90 b/src/modules/mesh/inout/moduleMeshInoutCommon.f90 deleted file mode 100644 index 8956423..0000000 --- a/src/modules/mesh/inout/moduleMeshInoutCommon.f90 +++ /dev/null @@ -1,74 +0,0 @@ -MODULE moduleMeshInoutCommon - - CHARACTER(LEN=4):: prefix = 'Step' - - integer, parameter, private:: fileID_boundaryParticle = 30 - integer, parameter, private:: fileID_boundaryEM = 31 - - CONTAINS - PURE FUNCTION formatFileName(pref, suff, extension, timeStep) RESULT(fileName) - USE moduleOutput - IMPLICIT NONE - - CHARACTER(*), INTENT(in):: pref, suff, extension - INTEGER, INTENT(in), OPTIONAL:: timeStep - CHARACTER (LEN=iterationDigits):: tString - CHARACTER(:), ALLOCATABLE:: fileName - - IF (PRESENT(timeStep)) THEN - WRITE(tString, iterationFormat) timeStep - fileName = pref // '_' // tString // '_' // suff // '.' // extension - - ELSE - fileName = pref // '_' // suff // '.' // extension - - END IF - - END FUNCTION formatFileName - - pure function returnFilePath(filename) result(completePath) - use moduleOutput, only: path, folder - implicit none - - character(:), allocatable, intent(in):: fileName - character(:), allocatable:: completePath - - completePath = path // folder // '/' // fileName - - end function returnFilePath - - subroutine informFileCreation(filename) - implicit none - - character(:), allocatable, intent(in):: fileName - - write(*, "(6X,A15,A)") "Creating file: ", fileName - - end subroutine informFileCreation - - module subroutine boundariesParticle_print() - use moduleCaseparam, only: timeStep - use moduleOutput, only: path, folder - use moduleMesh, only: nBoundariesParticle, boundariesParticle - implicit none - - integer:: b - character(:), allocatable:: fileName - - fileName = formatFileName(prefix, 'boundariesParticle', 'csv', timeStep) - call informFileCreation(fileName) - open(fileID_boundaryParticle, file = path // folder // '/' // fileName) - - do b = 1, nBoundariesParticle - if (associated(boundariesParticle(b)%obj%print)) then - call boundariesParticle(b)%obj%print(fileID_boundaryParticle) - - end if - - end do - - close(fileID_boundaryParticle) - - end subroutine boundariesParticle_print - -END MODULE moduleMeshInoutCommon diff --git a/src/modules/mesh/inout/text/moduleMeshOutputText.f90 b/src/modules/mesh/inout/text/moduleMeshOutputText.f90 index 0cd539b..cd8f04c 100644 --- a/src/modules/mesh/inout/text/moduleMeshOutputText.f90 +++ b/src/modules/mesh/inout/text/moduleMeshOutputText.f90 @@ -121,7 +121,6 @@ module moduleMeshOutputText subroutine printOutputText(self) use moduleMesh use moduleSpecies - use moduleMeshInoutCommon use moduleCaseParam, ONLY: timeStep implicit none @@ -134,7 +133,7 @@ module moduleMeshOutputText do s = 1, nSpecies fileName = formatFileName(prefix, species(s)%obj%name, 'csv', timeStep) - write(*, "(6X,A15,A)") "Creating file: ", fileName + call informFileCreation(fileName) open (fileID, file = path // folder // '/' // fileName) write(fileID, '(5(A,","),A)') '"Position (m)"', & @@ -153,7 +152,6 @@ module moduleMeshOutputText subroutine printCollText(self) use moduleMesh use moduleOutput - use moduleMeshInoutCommon use moduleCaseParam, only: timeStep implicit none @@ -167,7 +165,7 @@ module moduleMeshOutputText if (collOutput) then fileName = formatFileName(prefix, 'Collisions', 'csv', timeStep) - write(*, "(6X,A15,A)") "Creating file: ", fileName + call informFileCreation(fileName) open (fileID, file = path // folder // '/' // fileName) write(fileID, '(A)', advance='no') "Cell" @@ -191,7 +189,6 @@ module moduleMeshOutputText subroutine printEMText(self) use moduleMesh - use moduleMeshInoutCommon use moduleCaseParam, only: timeStep implicit none @@ -203,7 +200,7 @@ module moduleMeshOutputText if (emOutput) then fileName = formatFileName(prefix, 'EMField', 'csv', timeStep) - write(*, "(6X,A15,A)") "Creating file: ", fileName + call informFileCreation(fileName) open (fileID, file = path // folder // '/' // fileName) write(fileID, '(8(A,","),A)') '"Position (m)"', & @@ -222,7 +219,6 @@ module moduleMeshOutputText subroutine printAverageText(self) use moduleMesh use moduleSpecies - use moduleMeshInoutCommon implicit none class(meshParticles), intent(in):: self @@ -235,7 +231,7 @@ module moduleMeshOutputText do s = 1, nSpecies fileNameMean = formatFileName('Average_mean', species(s)%obj%name, 'csv') - write(*, "(6X,A15,A)") "Creating file: ", fileNameMean + call informFileCreation(fileNameMean) open (fileIDMean, file = path // folder // '/' // fileNameMean) write(fileIDMean, '(5(A,","),A)') '"Position (m)"', & @@ -244,7 +240,7 @@ module moduleMeshOutputText '"Temperature, mean (K)"' fileNameDeviation = formatFileName('Average_deviation', species(s)%obj%name, 'csv') - write(*, "(6X,A15,A)") "Creating file: ", fileNameDeviation + call informFileCreation(fileNameDeviation) open (fileIDDeviation, file = path // folder // '/' // fileNameDeviation) write(fileIDDeviation, '(5(A,","),A)') '"Position (m)"', & diff --git a/src/modules/mesh/inout/vtu/moduleMeshOutputVTU.f90 b/src/modules/mesh/inout/vtu/moduleMeshOutputVTU.f90 index 8e8f91a..4f986c5 100644 --- a/src/modules/mesh/inout/vtu/moduleMeshOutputVTU.f90 +++ b/src/modules/mesh/inout/vtu/moduleMeshOutputVTU.f90 @@ -12,7 +12,7 @@ MODULE moduleMeshOutputVTU WRITE(fileID,"(A)") '' WRITE(fileID,"(2X, A)") '' WRITE(fileID,"(4X, A)") '' - WRITE(fileID,"(6X, A, I10, A, I10, A)") '' + WRITE(fileID,"(6X, A, "//fmtInt//", A, "//fmtInt//", A)") '' END SUBROUTINE writeHeader @@ -87,14 +87,14 @@ MODULE moduleMeshOutputVTU !Write nodes coordinates WRITE(fileID, "(8X, A)") '' WRITE(fileID, "(10X,A)") '' - WRITE(fileID, "(6(ES20.6E3))") (self%nodes(e)%obj%getCoordinates()*L_ref, e = 1, self%numNodes) + WRITE(fileID, "(6("//fmtReal//"))") (self%nodes(e)%obj%getCoordinates()*L_ref, e = 1, self%numNodes) WRITE(fileID, "(10X, A)") '' WRITE(fileID, "(8X, A)") '' WRITE(fileID, "(8X, A)") '' !Write nodes connectivity of each cell WRITE(fileID, "(10X,A)") '' - WRITE(fileID, "(6(I10))") (self%cells(e)%obj%getNodes(self%cells(e)%obj%nNodes) - 1, e = 1, self%numCells) !Array starts on 0 + WRITE(fileID, "(6("//fmtInt//"))") (self%cells(e)%obj%getNodes(self%cells(e)%obj%nNodes) - 1, e = 1, self%numCells) !Array starts on 0 WRITE(fileID, "(10X, A)") '' !Write offset of each cell offset(1) = self%cells(1)%obj%nNodes @@ -103,7 +103,7 @@ MODULE moduleMeshOutputVTU offset(e) = offset(e - 1) + self%cells(e)%obj%nNodes END DO - WRITE(fileID, "(6(I10))") offset + WRITE(fileID, "(6("//fmtInt//"))") offset WRITE(fileID, "(10X, A)") '' !Write type of each cell WRITE(fileID, "(10X,A)") '' @@ -111,7 +111,7 @@ MODULE moduleMeshOutputVTU types(e) = getCellType(self%cells(e)%obj) END DO - WRITE(fileID, "(6(I10))") types + WRITE(fileID, "(6("//fmtInt//"))") types WRITE(fileID, "(10X, A)") '' WRITE(fileID, "(8X, A)") '' @@ -137,19 +137,19 @@ MODULE moduleMeshOutputVTU WRITE(fileID,"(8X,A)") '' !Write density WRITE(fileID,"(10X,A)") '' - WRITE(fileID,"(6(ES20.6E3))") (output(n)%density, n = 1, self%numNodes) + WRITE(fileID,"(6("//fmtReal//"))") (output(n)%density, n = 1, self%numNodes) WRITE(fileID,"(10X,A)") '' !Write velocity WRITE(fileID,"(10X,A)") '' - WRITE(fileID,"(6(ES20.6E3))") (output(n)%velocity, n = 1, self%numNodes) + WRITE(fileID,"(6("//fmtReal//"))") (output(n)%velocity, n = 1, self%numNodes) WRITE(fileID,"(10X,A)") '' !Write pressure WRITE(fileID,"(10X,A)") '' - WRITE(fileID,"(6(ES20.6E3))") (output(n)%pressure, n = 1, self%numNodes) + WRITE(fileID,"(6("//fmtReal//"))") (output(n)%pressure, n = 1, self%numNodes) WRITE(fileID,"(10X,A)") '' !Write temperature WRITE(fileID,"(10X,A)") '' - WRITE(fileID,"(6(ES20.6E3))") (output(n)%temperature, n = 1, self%numNodes) + WRITE(fileID,"(6("//fmtReal//"))") (output(n)%temperature, n = 1, self%numNodes) WRITE(fileID,"(10X,A)") '' !End node data WRITE(fileID,"(8X,A)") '' @@ -173,7 +173,7 @@ MODULE moduleMeshOutputVTU WRITE(cString, "(I2)") c title = 'Pair ' // interactionMatrix(k)%sp_i%name // '-' // interactionMatrix(k)%sp_j%name // ' collision ' // cString WRITE(fileID,"(10X,A, A, A)") '' - WRITE(fileID, "(6(I10))") (self%cells(n)%obj%tallyColl(k)%tally(c), n = 1, self%numCells) + WRITE(fileID, "(6("//fmtInt//"))") (self%cells(n)%obj%tallyColl(k)%tally(c), n = 1, self%numCells) WRITE(fileID, "(10X, A)") '' END DO @@ -196,11 +196,11 @@ MODULE moduleMeshOutputVTU WRITE(fileID,"(8X,A)") '' !Electric potential WRITE(fileID,"(10X,A)") '' - WRITE(fileID,"(6(ES20.6E3))") (self%nodes(n)%obj%emData%phi*Volt_ref, n = 1, self%numNodes) + WRITE(fileID,"(6("//fmtReal//"))") (self%nodes(n)%obj%emData%phi*Volt_ref, n = 1, self%numNodes) WRITE(fileID,"(10X,A)") '' !Magnetic Field WRITE(fileID,"(10X,A)") '' - WRITE(fileID,"(6(ES20.6E3))") (self%nodes(n)%obj%emData%B*B_ref, n = 1, self%numNodes) + WRITE(fileID,"(6("//fmtReal//"))") (self%nodes(n)%obj%emData%B*B_ref, n = 1, self%numNodes) WRITE(fileID,"(10X,A)") '' WRITE(fileID,"(8X,A)") '' @@ -209,7 +209,7 @@ MODULE moduleMeshOutputVTU WRITE(fileID,"(8X,A)") '' !Electric field WRITE(fileID,"(10X,A, A, A)") '' - WRITE(fileID,"(6(ES20.6E3))") (self%cells(n)%obj%gatherElectricField(Xi)*EF_ref, n = 1, self%numCells) + WRITE(fileID,"(6("//fmtReal//"))") (self%cells(n)%obj%gatherElectricField(Xi)*EF_ref, n = 1, self%numCells) WRITE(fileID,"(10X,A)") '' WRITE(fileID,"(8X,A)") '' @@ -221,30 +221,32 @@ MODULE moduleMeshOutputVTU USE moduleRefParam IMPLICIT NONE - INTEGER:: fileID - CHARACTER(*):: fileNameStep, fileNameCollection + INTEGER, intent(in):: fileID + CHARACTER(*), intent(in):: fileNameStep, fileNameCollection IF (timeStep == tInitial) THEN !Create collection file - WRITE(*, "(6X,A15,A)") "Creating file: ", fileNameCollection - OPEN (fileID + 1, file = path // folder // '/' // fileNameCollection) + call informFileCreation(fileNameCollection) + OPEN (fileID + 1, file = generateFilePath(fileNameCollection)) WRITE (fileID + 1, "(A)") '' WRITE (fileID + 1, "(2X, A)") '' CLOSE(fileID + 1) + else + ! Append removing the last two lines that close the + rewind(fileID) + rewind(fileID) + END IF !Write iteration file in collection - OPEN (fileID + 1, file = path // folder // '/' // fileNameCollection, ACCESS='APPEND') - WRITE(fileID + 1, "(4X, A, ES20.6E3, A, A, A)") & + OPEN (fileID + 1, file = generateFilePath(fileNameCollection), ACCESS='APPEND') + WRITE(fileID + 1, "(4X, A, "//fmtReal//", A, A, A)") & '' - !Close collection file - IF (timeStep == tFinal) THEN - WRITE (fileID + 1, "(2X, A)") '' - WRITE (fileID + 1, "(A)") '' + WRITE (fileID + 1, "(2X, A)") '' + WRITE (fileID + 1, "(A)") '' - END IF CLOSE(fileID + 1) END SUBROUTINE writeCollection @@ -276,29 +278,29 @@ MODULE moduleMeshOutputVTU !Write density WRITE(fileIDMean, "(10X,A)") '' WRITE(fileIDDeviation,"(10X,A)") '' - WRITE(fileIDMean, "(6(ES20.6E3))") (outputMean(n)%density, n = 1, self%numNodes) - WRITE(fileIDDeviation,"(6(ES20.6E3))") (outputDeviation(n)%density, n = 1, self%numNodes) + WRITE(fileIDMean, "(6("//fmtReal//"))") (outputMean(n)%density, n = 1, self%numNodes) + WRITE(fileIDDeviation,"(6("//fmtReal//"))") (outputDeviation(n)%density, n = 1, self%numNodes) WRITE(fileIDMean,"(10X,A)") '' WRITE(fileIDDeviation,"(10X,A)") '' !Write velocity WRITE(fileIDMean, "(10X,A)") '' WRITE(fileIDDeviation,"(10X,A)") '' - WRITE(fileIDMean, "(6(ES20.6E3))") (outputMean(n)%velocity, n = 1, self%numNodes) - WRITE(fileIDDeviation,"(6(ES20.6E3))") (outputDeviation(n)%velocity, n = 1, self%numNodes) + WRITE(fileIDMean, "(6("//fmtReal//"))") (outputMean(n)%velocity, n = 1, self%numNodes) + WRITE(fileIDDeviation,"(6("//fmtReal//"))") (outputDeviation(n)%velocity, n = 1, self%numNodes) WRITE(fileIDMean, "(10X,A)") '' WRITE(fileIDDeviation,"(10X,A)") '' !Write pressure WRITE(fileIDMean, "(10X,A)") '' WRITE(fileIDDeviation,"(10X,A)") '' - WRITE(fileIDMean, "(6(ES20.6E3))") (outputMean(n)%pressure, n = 1, self%numNodes) - WRITE(fileIDDeviation,"(6(ES20.6E3))") (outputDeviation(n)%pressure, n = 1, self%numNodes) + WRITE(fileIDMean, "(6("//fmtReal//"))") (outputMean(n)%pressure, n = 1, self%numNodes) + WRITE(fileIDDeviation,"(6("//fmtReal//"))") (outputDeviation(n)%pressure, n = 1, self%numNodes) WRITE(fileIDMean, "(10X,A)") '' WRITE(fileIDDeviation,"(10X,A)") '' !Write temperature WRITE(fileIDMean, "(10X,A)") '' WRITE(fileIDDeviation,"(10X,A)") '' - WRITE(fileIDMean, "(6(ES20.6E3))") (outputMean(n)%temperature, n = 1, self%numNodes) - WRITE(fileIDDeviation,"(6(ES20.6E3))") (outputDeviation(n)%temperature, n = 1, self%numNodes) + WRITE(fileIDMean, "(6("//fmtReal//"))") (outputMean(n)%temperature, n = 1, self%numNodes) + WRITE(fileIDDeviation,"(6("//fmtReal//"))") (outputDeviation(n)%temperature, n = 1, self%numNodes) WRITE(fileIDMean, "(10X,A)") '' WRITE(fileIDDeviation,"(10X,A)") '' !End node data @@ -310,7 +312,6 @@ MODULE moduleMeshOutputVTU SUBROUTINE printOutputVTU(self) USE moduleMesh USE moduleSpecies - USE moduleMeshInoutCommon USE moduleCaseParam, ONLY: timeStep IMPLICIT NONE @@ -322,8 +323,8 @@ MODULE moduleMeshOutputVTU DO i = 1, nSpecies fileName = formatFileName(prefix, species(i)%obj%name, 'vtu', timeStep) - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - OPEN (fileID, file = path // folder // '/' // fileName) + call informFileCreation(fileName) + OPEN (fileID, file = generateFilePath(fileName)) CALL writeHeader(self%numNodes, self%numCells, fileID) @@ -346,7 +347,6 @@ MODULE moduleMeshOutputVTU SUBROUTINE printCollVTU(self) USE moduleMesh USE moduleOutput - USE moduleMeshInoutCommon USE moduleCaseParam, ONLY: timeStep IMPLICIT NONE @@ -358,8 +358,8 @@ MODULE moduleMeshOutputVTU IF (collOutput) THEN fileName = formatFileName(prefix, 'Collisions', 'vtu', timeStep) - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - OPEN (fileID, file = path // folder // '/' // fileName) + call informFileCreation(fileName) + OPEN (fileID, file = generateFilePath(fileName)) CALL writeHeader(self%numNodes, self%numCells, fileID) @@ -381,7 +381,6 @@ MODULE moduleMeshOutputVTU SUBROUTINE printEMVTU(self) USE moduleMesh - USE moduleMeshInoutCommon USE moduleCaseParam, ONLY: timeStep IMPLICIT NONE @@ -393,8 +392,8 @@ MODULE moduleMeshOutputVTU IF (emOutput) THEN fileName = formatFileName(prefix, 'EMField', 'vtu', timeStep) - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - OPEN (fileID, file = path // folder // '/' // fileName) + call informFileCreation(fileName) + OPEN (fileID, file = generateFilePath(fileName)) CALL writeHeader(self%numNodes, self%numCells, fileID) @@ -416,8 +415,8 @@ MODULE moduleMeshOutputVTU SUBROUTINE printAverageVTU(self) USE moduleMesh + use moduleOutput USE moduleSpecies - USE moduleMeshInoutCommon IMPLICIT NONE CLASS(meshParticles), INTENT(in):: self @@ -429,12 +428,12 @@ MODULE moduleMeshOutputVTU DO i = 1, nSpecies fileNameMean = formatFileName('Average_mean', species(i)%obj%name, 'vtu') - WRITE(*, "(6X,A15,A)") "Creating file: ", fileNameMean - OPEN (fileIDMean, file = path // folder // '/' // fileNameMean) + call informFileCreation(fileNameMean) + OPEN (fileIDMean, file = generateFilePath(fileNameMean)) fileNameDeviation = formatFileName('Average_deviation', species(i)%obj%name, 'vtu') - WRITE(*, "(6X,A15,A)") "Creating file: ", fileNameDeviation - OPEN (fileIDDeviation, file = path // folder // '/' // fileNameDeviation) + call informFileCreation(fileNameDeviation) + OPEN (fileIDDeviation, file = generateFilePath(fileNameDeviation)) CALL writeHeader(self%numNodes, self%numCells, fileIDMean) CALL writeHeader(self%numNodes, self%numCells, fileIDDeviation) diff --git a/src/modules/mesh/moduleMesh.f90 b/src/modules/mesh/moduleMesh.f90 index 4578652..2e587a1 100644 --- a/src/modules/mesh/moduleMesh.f90 +++ b/src/modules/mesh/moduleMesh.f90 @@ -887,12 +887,16 @@ MODULE moduleMesh !Array for boundaries type(boundaryParticleCont), allocatable, target:: boundariesParticle(:) - ! Update the particle boundary models interface + ! Update the particle boundary models module subroutine boundariesParticle_update() end subroutine boundariesParticle_update + ! Write data about particle boundaries + module subroutine boundariesParticle_write() + + end subroutine boundariesParticle_write end interface ! BOUNDARY ELECTROMAGNETIC DEFINITIONS diff --git a/src/modules/mesh/moduleMesh@boundaryParticle.f90 b/src/modules/mesh/moduleMesh@boundaryParticle.f90 index 7073806..ca619d8 100644 --- a/src/modules/mesh/moduleMesh@boundaryParticle.f90 +++ b/src/modules/mesh/moduleMesh@boundaryParticle.f90 @@ -414,9 +414,9 @@ submodule(moduleMesh) boundaryParticle write(fileID, '(A)') self%name select type(self) type is(boundaryQuasiNeutrality) - write(fileID, '(A,",",A)'), '"Edge id"', '"alpha"' + write(fileID, '(A,",",A)') '"Edge id"', '"alpha"' do e = 1, size(self%edges) - write(fileID, '(I0,",",ES0.6E3)'), self%edges(e)%obj%n, self%alpha(self%edges(e)%obj%n) + write(fileID, '(I0,",",ES0.6E3)') self%edges(e)%obj%n, self%alpha(self%edges(e)%obj%n) end do @@ -477,4 +477,28 @@ submodule(moduleMesh) boundaryParticle end subroutine boundariesParticle_update + module subroutine boundariesParticle_write() + use moduleCaseparam, only: timeStep + use moduleOutput, only:fileID_boundaryParticle, formatFileName, informFileCreation + implicit none + + integer:: b + character(:), allocatable:: fileName + + fileName = formatFileName(prefix, 'boundariesParticle', 'csv', timeStep) + call informFileCreation(fileName) + open(fileID_boundaryParticle, file = path // folder // '/' // fileName) + + do b = 1, nBoundariesParticle + if (associated(boundariesParticle(b)%obj%print)) then + call boundariesParticle(b)%obj%print(fileID_boundaryParticle) + + end if + + end do + + close(fileID_boundaryParticle) + + end subroutine boundariesParticle_write + end submodule boundaryParticle diff --git a/src/modules/output/moduleOutput.f90 b/src/modules/output/moduleOutput.f90 index 2af3c70..04e2913 100644 --- a/src/modules/output/moduleOutput.f90 +++ b/src/modules/output/moduleOutput.f90 @@ -43,6 +43,25 @@ MODULE moduleOutput LOGICAL:: collOutput = .FALSE. LOGICAL:: emOutput = .FALSE. + ! Prefix for iteration files + character(len=*), parameter:: prefix = 'Step' + + ! Column separator + character(len=*), parameter:: colSep = '","' + + ! General format for file outputs + character(len=*), parameter:: fmtColReal = 'ES0.6E3,:,'//colSep ! Column with real + character(len=*), parameter:: fmtColInt = 'I0,:,'//colSep ! Column with integer + character(len=*), parameter:: fmtColStr = 'A,:,'//colSep ! Column with text + character(len=*), parameter:: fmtReal = 'ES14.6E3' ! Fixed size real + character(len=*), parameter:: fmtInt = 'I14' ! Fixed size real + + ! File IDs for different input/output + integer, parameter:: fileID_mesh = 10 ! Base id for mesh files + integer, parameter:: fileID_output = 20 ! Base id for species/collisions/EM output + integer, parameter:: fileID_boundaryParticle = 30 ! Particle boundaries + integer, parameter:: fileID_boundaryEM = 31 ! EM boundaries + CONTAINS PURE SUBROUTINE outputNode_equal_outputNode(self, from) IMPLICIT NONE @@ -177,7 +196,7 @@ MODULE moduleOutput WRITE(20, "(A1, 8X, A1, 9X, A1, 7(A20))") "#","t","n","total (s)","push (s)","reset (s)", & "collision (s)","coulomb (s)", & "weighting (s)","EMField (s)" - WRITE(*, "(6X,A15,A)") "Creating file: ", fileName + call informFileCreation(fileName) CLOSE(20) END IF @@ -194,5 +213,43 @@ MODULE moduleOutput END SUBROUTINE printTime + PURE FUNCTION formatFileName(pref, suff, extension, timeStep) RESULT(fileName) + IMPLICIT NONE + + CHARACTER(*), INTENT(in):: pref, suff, extension + INTEGER, INTENT(in), OPTIONAL:: timeStep + CHARACTER (LEN=iterationDigits):: tString + CHARACTER(:), ALLOCATABLE:: fileName + + IF (PRESENT(timeStep)) THEN + WRITE(tString, iterationFormat) timeStep + fileName = pref // '_' // tString // '_' // suff // '.' // extension + + ELSE + fileName = pref // '_' // suff // '.' // extension + + END IF + + END FUNCTION formatFileName + + pure function generateFilePath(filename) result(completePath) + implicit none + + character(*), intent(in):: fileName + character(:), allocatable:: completePath + + completePath = path // folder // '/' // fileName + + end function generateFilePath + + subroutine informFileCreation(filename) + implicit none + + character(*), intent(in):: fileName + + write(*, "(6X,A15,A)") "Creating file: ", fileName + + end subroutine informFileCreation + END MODULE moduleOutput diff --git a/src/modules/solver/moduleSolver.f90 b/src/modules/solver/moduleSolver.f90 index 0748fb9..1fb48f9 100644 --- a/src/modules/solver/moduleSolver.f90 +++ b/src/modules/solver/moduleSolver.f90 @@ -521,7 +521,6 @@ MODULE moduleSolver USE moduleCompTime USE moduleProbe USE moduleCaseParam, ONLY: timeStep - use moduleMeshInoutCommon, only: boundariesParticle_print IMPLICIT NONE CALL outputProbes() @@ -538,7 +537,7 @@ MODULE moduleSolver CALL mesh%printEM() ! Output of boundaries. TODO: Add an if - call boundariesParticle_print() + call boundariesParticle_write() WRITE(*, "(5X,A21,I10,A1,I10)") "t/tFinal: ", timeStep, "/", tFinal WRITE(*, "(5X,A21,I10)") "Particles: ", nPartOld