diff --git a/src/modules/mesh/0D/makefile b/src/modules/mesh/0D/makefile new file mode 100644 index 0000000..9dcba7e --- /dev/null +++ b/src/modules/mesh/0D/makefile @@ -0,0 +1,5 @@ +all: moduleMesh0D.o + +moduleMesh0D.o: moduleMesh0D.f90 + $(FC) $(FCFLAGS) -c $(subst .o,.f90,$@) -o $(OBJDIR)/$@ + diff --git a/src/modules/mesh/0D/moduleMesh0D.f90 b/src/modules/mesh/0D/moduleMesh0D.f90 new file mode 100644 index 0000000..3b84448 --- /dev/null +++ b/src/modules/mesh/0D/moduleMesh0D.f90 @@ -0,0 +1,181 @@ +!moduleMesh1D: 0D mesh. No coordinates are relevant. No edges are used +MODULE moduleMesh0D + USE moduleMesh + IMPLICIT NONE + + TYPE, PUBLIC, EXTENDS(meshNode):: meshNode0D + INTEGER:: n1 + CONTAINS + PROCEDURE, PASS:: init => initNode0D + PROCEDURE, PASS:: getCoordinates => getCoord0D + + END TYPE meshNode0D + + TYPE, PUBLIC, EXTENDS(meshVol):: meshVol0D + CLASS(meshNode), POINTER:: n1 + CONTAINS + PROCEDURE, PASS:: init => initVol0D + PROCEDURE, PASS:: getNodes => getNodes0D + PROCEDURE, PASS:: randPos => randPos0D + PROCEDURE, PASS:: scatter => scatter0D + PROCEDURE, PASS:: gatherEF => gatherEF0D + PROCEDURE, PASS:: elemK => elemK0D + PROCEDURE, PASS:: elemF => elemF0D + PROCEDURE, PASS:: phy2log => phy2log0D + PROCEDURE, NOPASS:: inside => inside0D + PROCEDURE, PASS:: nextElement => nextElement0D + + END TYPE meshVol0D + + CONTAINS + !NODE FUNCTIONS + !Init node + SUBROUTINE initNode0D(self, n, r) + IMPLICIT NONE + + CLASS(meshNode0D), INTENT(out):: self + INTEGER, INTENT(in):: n + REAL(8), INTENT(in):: r(1:3) !Unused variable + + self%n = n + + END SUBROUTINE initNode0D + + !Get node coordinates + PURE FUNCTION getCoord0D(self) RESULT(r) + IMPLICIT NONE + + CLASS(meshNode0D), INTENT(in):: self + REAL(8):: r(1:3) + + r = 0.D0 + + END FUNCTION + + !VOLUME FUNCTIONS + !Inits dummy 0D volume + SUBROUTINE initVol0D(self, n, p, nodes) + USE moduleRefParam + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(out):: self + INTEGER, INTENT(in):: n + INTEGER, INTENT(in):: p(:) + TYPE(meshNodeCont), INTENT(in), TARGET:: nodes(:) + + self%n = n + + self%n1 => nodes(p(1))%obj + self%volume = 1.D0 + self%n1%v = 1.D0 + + self%sigmaVrelMax = sigma_ref/L_ref**2 + + CALL OMP_INIT_LOCK(self%lock) + + END SUBROUTINE initVol0D + + PURE FUNCTION getNodes0D(self) RESULT(n) + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(in):: self + INTEGER, ALLOCATABLE:: n(:) + + END FUNCTION getNodes0D + + FUNCTION randPos0D(self) RESULT(r) + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(in):: self + REAL(8):: r(1:3) + + r = 0.D0 + + END FUNCTION randPos0D + + SUBROUTINE scatter0D(self, part) + USE moduleMath + USE moduleSpecies + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(in):: self + CLASS(particle), INTENT(in):: part + REAL(8):: tensorS(1:3,1:3) + TYPE(outputNode), POINTER:: vertex + + tensorS = outerProduct(part%v, part%v) + + vertex => self%n1%output(part%species%n) + vertex%den = vertex%den + part%weight + vertex%mom(:) = vertex%mom(:) + part%weight*part%v(:) + vertex%tensorS(:,:) = vertex%tensorS(:,:) + part%weight*tensorS + + END SUBROUTINE scatter0D + + PURE FUNCTION gatherEF0D(self, xi) RESULT(EF) + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(in):: self + REAL(8), INTENT(in):: xi(1:3) + REAL(8):: EF(1:3) + + EF = 0.D0 + + END FUNCTION gatherEF0D + + PURE FUNCTION elemK0D(self) RESULT(localK) + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(in):: self + REAL(8), ALLOCATABLE:: localK(:,:) + + ALLOCATE(localK(1:1, 1:1)) + localK = 0.D0 + + END FUNCTION elemK0D + + PURE FUNCTION elemF0D(self, source) RESULT(localF) + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(in):: self + REAL(8), INTENT(in):: source(1:) + REAL(8), ALLOCATABLE:: localF(:) + + ALLOCATE(localF(1:1)) + localF = 0.D0 + + END FUNCTION elemF0D + + PURE FUNCTION phy2log0D(self,r) RESULT(xN) + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(in):: self + REAL(8), INTENT(in):: r(1:3) + REAL(8):: xN(1:3) + + xN = 0.D0 + + END FUNCTION phy2log0D + + PURE FUNCTION inside0D(xi) RESULT(ins) + IMPLICIT NONE + + REAL(8), INTENT(in):: xi(1:3) + LOGICAL:: ins + + ins = .TRUE. + + END FUNCTION inside0D + + SUBROUTINE nextElement0D(self, xi, nextElement) + IMPLICIT NONE + + CLASS(meshVol0D), INTENT(in):: self + REAL(8), INTENT(in):: xi(1:3) + CLASS(meshElement), POINTER, INTENT(out):: nextElement + + nextElement => NULL() + + END SUBROUTINE nextElement0D + +END MODULE moduleMesh0D diff --git a/src/modules/mesh/inout/0D/makefile b/src/modules/mesh/inout/0D/makefile new file mode 100644 index 0000000..4bf91b7 --- /dev/null +++ b/src/modules/mesh/inout/0D/makefile @@ -0,0 +1,7 @@ +all: moduleMeshInput0D.o moduleMeshOutput0D.o + +moduleMeshInput0D.o: moduleMeshOutput0D.o moduleMeshInput0D.f90 + $(FC) $(FCFLAGS) -c $(subst .o,.f90,$@) -o $(OBJDIR)/$@ + +%.o: %.f90 + $(FC) $(FCFLAGS) -c $< -o $(OBJDIR)/$@ diff --git a/src/modules/mesh/inout/0D/moduleMeshInput0D.f90 b/src/modules/mesh/inout/0D/moduleMeshInput0D.f90 new file mode 100644 index 0000000..678671a --- /dev/null +++ b/src/modules/mesh/inout/0D/moduleMeshInput0D.f90 @@ -0,0 +1,66 @@ +MODULE moduleMeshInput0D + !Creates a 0D mesh. mostly used for testing collisional processes. + !This mesh consists on 1 node and 1 volume in which all particles are located. + !No boundary conditions and no pusher should be applied to this geometry. + !Output should go to a single file (per species) in which each row represents an iteration. + !In principle, no EM field is applied. + + CONTAINS + !Inits the 0D mesh + SUBROUTINE init0D(self) + USE moduleMesh + USE moduleMeshOutput0D + IMPLICIT NONE + + CLASS(meshGeneric), INTENT(inout), TARGET:: self + + IF (ASSOCIATED(meshForMCC, self)) self%printColl => printColl0D + SELECT TYPE(self) + TYPE IS(meshParticles) + self%printOutput => printOutput0D + self%printEM => printEM0D + + END SELECT + self%readMesh => read0D + + END SUBROUTINE init0D + + !Reads a 0D mesh file. + !No reading is actually done as the 0D mesh is a fixed one + SUBROUTINE read0D(self, filename) + USE moduleMesh + USE moduleMesh0D + IMPLICIT NONE + + CLASS(meshGeneric), INTENT(inout):: self + CHARACTER(:), ALLOCATABLE, INTENT(in):: filename !Dummy file, not used + REAL(8):: r(1:3) + + !Allocates one node + self%numNodes = 1 + ALLOCATE(self%nodes(1:1)) + !Allocates one volume + self%numVols = 1 + ALLOCATE(self%vols(1:1)) + !Allocates matrix K + SELECT TYPE(self) + TYPE IS(meshParticles) + ALLOCATE(self%K(1:1, 1:1)) + ALLOCATE(self%IPIV(1:1, 1:1)) + self%K = 0.D0 + self%IPIV = 0.D0 + + END SELECT + + !Creates the node + ALLOCATE(meshNode0D:: self%nodes(1)%obj) + r = 0.D0 + CALL self%nodes(1)%obj%init(1, r) + + !Creates the volume + ALLOCATE(meshVol0D:: self%vols(1)%obj) + CALL self%vols(1)%obj%init(1, (/ 1/), self%nodes) + + END SUBROUTINE read0D + +END MODULE moduleMeshInput0D diff --git a/src/modules/mesh/inout/0D/moduleMeshOutput0D.f90 b/src/modules/mesh/inout/0D/moduleMeshOutput0D.f90 new file mode 100644 index 0000000..6e490b4 --- /dev/null +++ b/src/modules/mesh/inout/0D/moduleMeshOutput0D.f90 @@ -0,0 +1,61 @@ +MODULE moduleMeshOutput0D + + CONTAINS + SUBROUTINE printOutput0D(self, t) + USE moduleMesh + USE moduleRefParam + USE moduleSpecies + USE moduleOutput + IMPLICIT NONE + + CLASS(meshParticles), INTENT(in):: self + INTEGER, INTENT(in):: t + INTEGER:: i + TYPE(outputFormat):: output + CHARACTER(:), ALLOCATABLE:: fileName + + DO i = 1, nSpecies + fileName='OUTPUT_' // species(i)%obj%name // '.dat' + IF (t == 0) THEN + OPEN(20, file = path // folder // '/' // fileName, action = 'write') + WRITE(20, "(A1, 8X, A1, 6(A20))") "#","t","density", "velocity", "pressure", "temperature" + WRITE(*, "(6X,A15,A)") "Creating file: ", fileName + CLOSE(20) + + END IF + + OPEN(20, file = path // folder // '/' // fileName, position = 'append', action = 'write') + CALL calculateOutput(self%nodes(1)%obj%output(i), output, self%nodes(1)%obj%v, species(i)%obj) + WRITE(20, "(I10, 6(ES20.6E3))") t, output%density, output%velocity, output%pressure, output%temperature + CLOSE(20) + + END DO + + END SUBROUTINE printOutput0D + + SUBROUTINE printColl0D(self, t) + USE moduleMesh + USE moduleRefParam + USE moduleCaseParam + USE moduleCollisions + USE moduleOutput + IMPLICIT NONE + + CLASS(meshGeneric), INTENT(in):: self + INTEGER, INTENT(in):: t + + END SUBROUTINE printColl0D + + SUBROUTINE printEM0D(self, t) + USE moduleMesh + USE moduleRefParam + USE moduleCaseParam + USE moduleOutput + IMPLICIT NONE + + CLASS(meshParticles), INTENT(in):: self + INTEGER, INTENT(in):: t + + END SUBROUTINE printEM0D + +END MODULE moduleMeshOutput0D diff --git a/src/modules/mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 b/src/modules/mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 index 59d7064..629a6f2 100644 --- a/src/modules/mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 +++ b/src/modules/mesh/inout/gmsh2/moduleMeshInputGmsh2.f90 @@ -1,4 +1,5 @@ MODULE moduleMeshInputGmsh2 + !Reads a mesh in the Gmsh v2.0 format CONTAINS !Inits a mesh to use Gmsh2 format diff --git a/src/modules/mesh/inout/gmsh2/moduleMeshOutputGmsh2.f90 b/src/modules/mesh/inout/gmsh2/moduleMeshOutputGmsh2.f90 index bec5449..43b1ef8 100644 --- a/src/modules/mesh/inout/gmsh2/moduleMeshOutputGmsh2.f90 +++ b/src/modules/mesh/inout/gmsh2/moduleMeshOutputGmsh2.f90 @@ -96,8 +96,8 @@ MODULE moduleMeshOutputGmsh2 IMPLICIT NONE CLASS(meshGeneric), INTENT(in):: self - INTEGER:: numEdges INTEGER, INTENT(in):: t + INTEGER:: numEdges INTEGER:: n REAL(8):: time CHARACTER(:), ALLOCATABLE:: fileName diff --git a/src/modules/mesh/inout/makefile b/src/modules/mesh/inout/makefile index 7817608..2f73e73 100644 --- a/src/modules/mesh/inout/makefile +++ b/src/modules/mesh/inout/makefile @@ -1,4 +1,7 @@ -all: gmsh2.o +all: gmsh2.o 0D.o gmsh2.o: $(MAKE) -C gmsh2 all + +0D.o: + $(MAKE) -C 0D all diff --git a/src/modules/mesh/makefile b/src/modules/mesh/makefile index 0adc8f6..a013878 100644 --- a/src/modules/mesh/makefile +++ b/src/modules/mesh/makefile @@ -1,4 +1,4 @@ -all: moduleMesh.o moduleMeshBoundary.o inout.o 3DCart.o 2DCyl.o 2DCart.o 1DRad.o 1DCart.o +all: moduleMesh.o moduleMeshBoundary.o inout.o 3DCart.o 2DCyl.o 2DCart.o 1DRad.o 1DCart.o 0D.o 3DCart.o: moduleMesh.o $(MAKE) -C 3DCart all @@ -15,11 +15,14 @@ all: moduleMesh.o moduleMeshBoundary.o inout.o 3DCart.o 2DCyl.o 2DCart.o 1DRad.o 1DRad.o: moduleMesh.o $(MAKE) -C 1DRad all +0D.o: moduleMesh.o + $(MAKE) -C 0D all + moduleMesh.o: moduleMesh.f90 $(FC) $(FCFLAGS) -c $(subst .o,.f90,$@) -o $(OBJDIR)/$@ moduleMeshBoundary.o: moduleMesh.o moduleMeshBoundary.f90 $(FC) $(FCFLAGS) -c $(subst .o,.f90,$@) -o $(OBJDIR)/$@ -inout.o: 3DCart.o 2DCyl.o 2DCart.o 1DRad.o 1DCart.o +inout.o: 3DCart.o 2DCyl.o 2DCart.o 1DRad.o 1DCart.o 0D.o $(MAKE) -C inout all diff --git a/src/modules/mesh/moduleMesh.f90 b/src/modules/mesh/moduleMesh.f90 index 8ddee60..53fa341 100644 --- a/src/modules/mesh/moduleMesh.f90 +++ b/src/modules/mesh/moduleMesh.f90 @@ -193,7 +193,6 @@ MODULE moduleMesh END SUBROUTINE scatter_interface PURE FUNCTION gatherEF_interface(self, xi) RESULT(EF) - IMPORT:: meshVol CLASS(meshVol), INTENT(in):: self REAL(8), INTENT(in):: xi(1:3) @@ -655,7 +654,7 @@ MODULE moduleMesh END SUBROUTINE doCollisions SUBROUTINE doCoulomb(self) - IMPORT meshParticles + IMPLICIT NONE CLASS(meshParticles), INTENT(inout):: self diff --git a/src/modules/moduleInput.f90 b/src/modules/moduleInput.f90 index 9d9de19..46c4421 100644 --- a/src/modules/moduleInput.f90 +++ b/src/modules/moduleInput.f90 @@ -779,8 +779,11 @@ MODULE moduleInput CASE("1DCart") mesh%connectMesh => connectMesh1DCart + CASE("0D") + mesh%connectMesh => NULL() + END SELECT - CALL mesh%connectMesh + IF (ASSOCIATED(mesh%connectMesh)) CALL mesh%connectMesh IF (doubleMesh) THEN meshColl%connectMesh => mesh%connectMesh diff --git a/src/modules/moduleOutput.f90 b/src/modules/moduleOutput.f90 index a9efdc4..89df330 100644 --- a/src/modules/moduleOutput.f90 +++ b/src/modules/moduleOutput.f90 @@ -98,17 +98,14 @@ MODULE moduleOutput OPEN(20, file = path // folder // '/' // fileName, action = 'write') WRITE(20, "(A1, 8X, A1, 9X, A1, 6(A20))") "#","t","n","total","push","reset","collision","weighting","EMField" WRITE(*, "(6X,A15,A)") "Creating file: ", fileName - - ELSE + CLOSE(20) END IF - OPEN(20, file = path // folder // '/' // fileName, position = 'append', action = 'write') - - ELSE - OPEN(20, file = path // folder // '/' // fileName, position = 'append', action = 'write') END IF + OPEN(20, file = path // folder // '/' // fileName, position = 'append', action = 'write') + WRITE (20, "(I10, I10, 7(ES20.6E3))") t, nPartOld, tStep, tPush, tReset, tColl, tCoul, tWeight, tEMField CLOSE(20)