Skip to content

Commit

Permalink
DivMomentumTri
Browse files Browse the repository at this point in the history
  • Loading branch information
OsKnoth committed Dec 6, 2024
1 parent 4453dbd commit e0c2a08
Show file tree
Hide file tree
Showing 16 changed files with 1,154 additions and 36 deletions.
File renamed without changes.
53 changes: 38 additions & 15 deletions Examples/testFEMSeiConsShallow.jl → Examples/ConsNonLinShallow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ LatB = 0.0

#Quad
GridType = "CubedSphere"
nPanel = 40
nPanel = 80
#GridType = "HealPix"
ns = 57

#Grid construction
RadEarth = Phys.RadEarth
Grid, Exchange = Grids.InitGridSphere(backend,FTB,OrdPoly,nz,nPanel,RefineLevel,ns,
nLat,nLon,LatB,GridType,Decomp,RadEarth,Model,ParallelCom)

print("Which Problem do you want so solve? \n")
print("1 - GalewskiSphere\n\
2 - HaurwitzSphere\n")
Expand All @@ -165,38 +170,45 @@ a = parse(Int,text)
if a == 1
Problem = "GalewskiSphere"
Param = Examples.Parameters(FTB,Problem)
RadEarth = Phys.RadEarth
GridLength = Grids.GridLength(Grid)
GridLengthMin,GridLengthMax = Grids.GridLength(Grid)
cS = sqrt(Phys.Grav * Param.H0G)
dtau = GridLength / cS * 0.1
dtau = GridLengthMin / cS / sqrt(2) * .5
EndTime = 24 * 3600 # One day
PrintTime = 3600
nAdveVel = round(EndTime / dtau)
dtau = EndTime / nAdveVel
nprint = ceil(nAdveVel/50)
nprint = ceil(PrintTime/dtau)
GridTypeOut = GridType*"NonLinShallowGal"
@show GridLengthMin,GridLengthMax
@show nAdveVel
@show dtau
@show nprint
elseif a == 2
Problem = "HaurwitzSphere"
Param = Examples.Parameters(FTB,Problem)
RadEarth = Phys.RadEarth
dtau = 30 #g=9.81, H=8000
nAdveVel = ceil(Int,6*24*3600/dtau)
GridLengthMin,GridLengthMax = Grids.GridLength(Grid)
cS = sqrt(Phys.Grav * Param.h0)
dtau = GridLengthMin / cS / sqrt(2) * .3
EndTime = 24 * 3600 # One day
PrintTime = 3600
nAdveVel = round(EndTime / dtau)
dtau = EndTime / nAdveVel
nprint = ceil(PrintTime/dtau)
GridTypeOut = GridType*"NonLinShallowHaurwitz"
@show GridLengthMin,GridLengthMax
@show nAdveVel
@show dtau
@show nprint
else
print("Error")
end
println("The chosen Problem is ")
Examples.InitialProfile!(Model,Problem,Param,Phys)

#Grid construction
Grid, Exchange = Grids.InitGridSphere(backend,FTB,OrdPoly,nz,nPanel,RefineLevel,ns,nLat,nLon,LatB,GridType,Decomp,RadEarth,
Model,ParallelCom)
#Output
vtkSkeletonMesh = Outputs.vtkStruct{Float64}(backend,Grid,Grid.NumFaces,Flat)

#finite elements
#Finite elements
DG = FEMSei.DG0Struct{FTB}(Grids.Quad(),backend,Grid)
VecDG = FEMSei.VecDG0Struct{FTB}(Grids.Quad(),backend,Grid)
RT = FEMSei.RT0Struct{FTB}(Grids.Quad(),backend,Grid)
Expand Down Expand Up @@ -235,9 +247,8 @@ FEMSei.Project!(backend,FTB,Uh,DG,Grid,nQuad,FEMSei.Jacobi!,Model.InitialProfile
FileNumber=0
VelSp = zeros(Grid.NumFaces,2)
FEMSei.ConvertScalarVelocitySp!(backend,FTB,VelSp,Uhu,RT,Uh,DG,Grid,FEMSei.Jacobi!)
Outputs.vtkSkeleton!(vtkSkeletonMesh, "ConsShallow", Proc, ProcNumber, [Uh VelSp] ,FileNumber)
Outputs.vtkSkeleton!(vtkSkeletonMesh, GridTypeOut, Proc, ProcNumber, [Uh VelSp] ,FileNumber)

nprint = 10
for i = 1 : nAdveVel
@show i,(i-1)*dtau/3600
@. F = 0
Expand All @@ -251,6 +262,18 @@ for i = 1 : nAdveVel
FEMSei.CrossRhs!(backend,FTB,Fhu,RT,Uhu,RT,Grid,Grids.Quad(),nQuad,FEMSei.Jacobi!)
FEMSei.GradHeightSquared!(backend,FTB,Fhu,RT,Uh,DG,Grid,Grids.Quad(),nQuad,FEMSei.Jacobi!)
ldiv!(RT.LUM,Fhu)
@. UNew = U + 1 / 3 * dtau * F
@. F = 0
# Tendency h
FEMSei.DivRhs!(backend,FTB,Fh,DG,UNewhu,RT,Grid,Grids.Quad(),nQuad,FEMSei.Jacobi!)
ldiv!(DG.LUM,Fh)
# Tendency hu
FEMSei.ProjectScalarHDivVecDG1!(backend,FTB,uRec,VecDG,UNewh,DG,UNewhu,RT,Grid,
Grids.Quad(),nQuad,FEMSei.Jacobi!)
FEMSei.DivMomentumVector!(backend,FTB,Fhu,RT,UNewhu,RT,uRec,VecDG,Grid,Grids.Quad(),nQuad,FEMSei.Jacobi!)
FEMSei.CrossRhs!(backend,FTB,Fhu,RT,UNewhu,RT,Grid,Grids.Quad(),nQuad,FEMSei.Jacobi!)
FEMSei.GradHeightSquared!(backend,FTB,Fhu,RT,UNewh,DG,Grid,Grids.Quad(),nQuad,FEMSei.Jacobi!)
ldiv!(RT.LUM,Fhu)
@. UNew = U + 0.5 * dtau * F
@. F = 0
# Tendency h
Expand All @@ -268,7 +291,7 @@ for i = 1 : nAdveVel
if mod(i,nprint) == 0
global FileNumber += 1
FEMSei.ConvertScalarVelocitySp!(backend,FTB,VelSp,Uhu,RT,Uh,DG,Grid,FEMSei.Jacobi!)
Outputs.vtkSkeleton!(vtkSkeletonMesh, "ConsShallow", Proc, ProcNumber, [Uh VelSp] ,FileNumber)
Outputs.vtkSkeleton!(vtkSkeletonMesh, GridTypeOut, Proc, ProcNumber, [Uh VelSp] ,FileNumber)
end
end
@show "finished"
280 changes: 280 additions & 0 deletions Examples/testFEMSeiProjectionVectorTri.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
import CGDycore:
Examples, Parallels, Models, Grids, Outputs, Integration, GPU, DyCore, FEMSei, FiniteVolumes
using MPI
using Base
using CUDA
using AMDGPU
using Metal
using KernelAbstractions
using StaticArrays
using ArgParse
using LinearAlgebra

# Model
parsed_args = DyCore.parse_commandline()
Problem = parsed_args["Problem"]
ProfRho = parsed_args["ProfRho"]
ProfTheta = parsed_args["ProfTheta"]
PertTh = parsed_args["PertTh"]
ProfVel = parsed_args["ProfVel"]
ProfVelGeo = parsed_args["ProfVelGeo"]
RhoVPos = parsed_args["RhoVPos"]
RhoCPos = parsed_args["RhoCPos"]
RhoIPos = parsed_args["RhoIPos"]
RhoRPos = parsed_args["RhoRPos"]
HorLimit = parsed_args["HorLimit"]
Upwind = parsed_args["Upwind"]
Damping = parsed_args["Damping"]
Relax = parsed_args["Relax"]
StrideDamp = parsed_args["StrideDamp"]
Geos = parsed_args["Geos"]
Coriolis = parsed_args["Coriolis"]
CoriolisType = parsed_args["CoriolisType"]
Buoyancy = parsed_args["Buoyancy"]
Equation = parsed_args["Equation"]
RefProfile = parsed_args["RefProfile"]
ProfpBGrd = parsed_args["ProfpBGrd"]
ProfRhoBGrd = parsed_args["ProfRhoBGrd"]
Microphysics = parsed_args["Microphysics"]
TypeMicrophysics = parsed_args["TypeMicrophysics"]
RelCloud = parsed_args["RelCloud"]
Rain = parsed_args["Rain"]
Source = parsed_args["Source"]
Forcing = parsed_args["Forcing"]
VerticalDiffusion = parsed_args["VerticalDiffusion"]
JacVerticalDiffusion = parsed_args["JacVerticalDiffusion"]
JacVerticalAdvection = parsed_args["JacVerticalAdvection"]
SurfaceFlux = parsed_args["SurfaceFlux"]
SurfaceFluxMom = parsed_args["SurfaceFluxMom"]
NumV = parsed_args["NumV"]
NumTr = parsed_args["NumTr"]
Curl = parsed_args["Curl"]
ModelType = parsed_args["ModelType"]
Thermo = parsed_args["Thermo"]
# Parallel
Decomp = parsed_args["Decomp"]
# Time integration
SimDays = parsed_args["SimDays"]
SimHours = parsed_args["SimHours"]
SimMinutes = parsed_args["SimMinutes"]
SimSeconds = parsed_args["SimSeconds"]
StartAverageDays = parsed_args["StartAverageDays"]
dtau = parsed_args["dtau"]
IntMethod = parsed_args["IntMethod"]
Table = parsed_args["Table"]
# Grid
nz = parsed_args["nz"]
nPanel = parsed_args["nPanel"]
H = parsed_args["H"]
Stretch = parsed_args["Stretch"]
StretchType = parsed_args["StretchType"]
TopoS = parsed_args["TopoS"]
GridType = parsed_args["GridType"]
RadEarth = parsed_args["RadEarth"]
# CG Element
OrdPoly = parsed_args["OrdPoly"]
# Viscosity
HyperVisc = parsed_args["HyperVisc"]
HyperDCurl = parsed_args["HyperDCurl"]
HyperDGrad = parsed_args["HyperDGrad"]
HyperDRhoDiv = parsed_args["HyperDRhoDiv"]
HyperDDiv = parsed_args["HyperDDiv"]
HyperDDivW = parsed_args["HyperDDivW"]
# Output
PrintDays = parsed_args["PrintDays"]
PrintHours = parsed_args["PrintHours"]
PrintMinutes = parsed_args["PrintMinutes"]
PrintSeconds = parsed_args["PrintSeconds"]
PrintStartTime = parsed_args["PrintStartTime"]
Flat = parsed_args["Flat"]

# Device
Device = parsed_args["Device"]
GPUType = parsed_args["GPUType"]
FloatTypeBackend = parsed_args["FloatTypeBackend"]
NumberThreadGPU = parsed_args["NumberThreadGPU"]

MPI.Init()
Flat = false #testen
Device = "CPU"
FloatTypeBackend = "Float64"

if Device == "CPU"
backend = CPU()
elseif Device == "GPU"
if GPUType == "CUDA"
backend = CUDABackend()
CUDA.allowscalar(true)
# CUDA.device!(MPI.Comm_rank(MPI.COMM_WORLD))
elseif GPUType == "AMD"
backend = ROCBackend()
AMDGPU.allowscalar(false)
elseif GPUType == "Metal"
backend = MetalBackend()
Metal.allowscalar(true)
end
else
backend = CPU()
end

if FloatTypeBackend == "Float64"
FTB = Float64
elseif FloatTypeBackend == "Float32"
FTB = Float32
else
@show "False FloatTypeBackend"
stop
end

MPI.Init()
comm = MPI.COMM_WORLD
Proc = MPI.Comm_rank(comm) + 1
ProcNumber = MPI.Comm_size(comm)
ParallelCom = DyCore.ParallelComStruct()
ParallelCom.Proc = Proc
ParallelCom.ProcNumber = ProcNumber

# Physical parameters
Phys = DyCore.PhysParameters{FTB}()

#ModelParameters
Model = DyCore.ModelStruct{FTB}()

RefineLevel = 6
nz = 1
nQuad = 3
nQuadM = 3 #2
nQuadS = 3 #3
Decomp = "EqualArea"
nLat = 0
nLon = 0
LatB = 0.0

#Quad
GridType = "TriangularSphere"
nPanel = 80
#GridType = "HealPix"
ns = 57

print("Which Problem do you want so solve? \n")
print("1 - GalewskiSphere\n\
2 - HaurwitzSphere\n\
3 - LinearBlob\n\
4 - AdvectionSpherical\n")
text = readline()
a = parse(Int,text)
if a == 1
Problem = "GalewskiSphere"
Param = Examples.Parameters(FTB,Problem)
RadEarth = Phys.RadEarth
dtau = 30
nAdveVel = 100 #ceil(Int,6*24*3600/dtau)
GridTypeOut = GridType*"NonLinShallowGal"
@show nAdveVel
elseif a == 2
Problem = "HaurwitzSphere"
Param = Examples.Parameters(FTB,Problem)
RadEarth = Phys.RadEarth
dtau = 30 #g=9.81, H=8000
nAdveVel = ceil(Int,6*24*3600/dtau)
GridTypeOut = GridType*"NonLinShallowHaurwitz"
@show nAdveVel
elseif a == 3
Problem = "LinearBlob"
Param = Examples.Parameters(FTB,Problem)
RadEarth = 1.0
dtau = 0.00025
nAdveVel = 100
GridTypeOut = GridType*"NonLinShallowBlob"
@show nAdveVel
elseif a == 4
Problem = "AdvectionSphereSpherical"
Param = Examples.Parameters(FTB,Problem)
RadEarth = 1.0
dtau = 2*pi*RadEarth/4/nPanel/Param.uMax*0.1
@show dtau # 0.0004581489286485114 #in s = 2*pi*Rad / 4*nPanel / param.uMax * cFL (ca. 0.7) bei RK2 (RK3 1.7)
nAdveVel = 100
nprint = 10
GridTypeOut = GridType*"Advec"
@show nAdveVel
else
print("Error")
end
println("The chosen Problem is ")
Examples.InitialProfile!(Model,Problem,Param,Phys)
ProfileUTR = Examples.AdvectionVelocity()(Param,Phys)

#Grid construction
Grid, Exchange = Grids.InitGridSphere(backend,FTB,OrdPoly,nz,nPanel,RefineLevel,ns,nLat,nLon,LatB,GridType,Decomp,RadEarth,
Model,ParallelCom)
for iE = 1 : Grid.NumEdges
Grids.PosEdgeInFace!(Grid.Edges[iE],Grid.Edges,Grid.Faces)
end
vtkSkeletonMesh = Outputs.vtkStruct{Float64}(backend,Grid,Grid.NumFaces,Flat)

#finite elements
VecDG = FEMSei.VecDG0Struct{FTB}(Grids.Tri(),backend,Grid)
RTTR = FEMSei.RT0Struct{FTB}(Grids.Tri(),backend,Grid)
RT = FEMSei.RT0Struct{FTB}(Grids.Tri(),backend,Grid)

#massmatrix und LU-decomposition
VecDG.M = FEMSei.MassMatrix(backend,FTB,VecDG,Grid,nQuadM,FEMSei.Jacobi!)
VecDG.LUM = lu(VecDG.M)
RTTR.M = FEMSei.MassMatrix(backend,FTB,RTTR,Grid,nQuadM,FEMSei.Jacobi!)
RTTR.LUM = lu(RTTR.M)
RT.M = FEMSei.MassMatrix(backend,FTB,RT,Grid,nQuadM,FEMSei.Jacobi!)
RT.LUM = lu(RT.M)

#stiffmatrix
cVecDG = zeros(FTB,VecDG.NumG)
cRT = zeros(FTB,RTTR.NumG)

QuadOrd=3

FEMSei.Interpolate1!(backend,FTB,cRT,RTTR,Grid.Type,Grid,nQuad,FEMSei.Jacobi!,ProfileUTR)
#projection from
FEMSei.ProjectHDivVecDG!(backend,FTB,cVecDG,VecDG,cRT,RTTR,Grid,Grids.Quad(),nQuad,FEMSei.Jacobi!)

u = zeros(FTB,RT.NumG)
VelSp = zeros(Grid.NumFaces,2)

#Fortin-Interpolation
FEMSei.Interpolate1!(backend,FTB,u,RT,Grid.Type,Grid,QuadOrd,FEMSei.Jacobi!,Model.InitialProfile)

FEMSei.ConvertVelocitySp!(backend,FTB,VelSp,cRT,RTTR,Grid,FEMSei.Jacobi!)

FileNumber=0
Outputs.vtkSkeleton!(vtkSkeletonMesh, "Proj_Recov_Tri", Proc, ProcNumber, VelSp, FileNumber)

#runge-kutta steps
time = 0.0
cRTNew = similar(cRT)
Rhs = zeros(FTB,RT.NumG)

for i = 1 : nAdveVel
@show i
@. Rhs = 0
FEMSei.ProjectHDivVecDG!(backend,FTB,cVecDG,VecDG,cRT,RTTR,Grid,Grids.Tri(),nQuad,FEMSei.Jacobi!)
#FEMSei.DivMomentumVector!(backend,FTB,Rhs,u,RT,cVecDG,VecDG,RT,Grid,Grids.Tri(),nQuad,FEMSei.Jacobi!)
FEMSei.DivMomentumVector!(backend,FTB,Rhs,RT,u,RT,cVecDG,VecDG,Grid,Grids.Tri(),nQuad,FEMSei.Jacobi!)
ldiv!(RTTR.LUM,Rhs)
################TEST
# FEMSei.ConvertVelocitySp!(backend,FTB,VelSp,Rhs,RTTR,Grid,FEMSei.Jacobi!)
# FileNumber=4000
# Outputs.vtkSkeleton!(vtkSkeletonMesh, "Rhs", Proc, ProcNumber, VelSp, FileNumber)
################
@. cRTNew = cRT + 0.5 * dtau * Rhs
@. Rhs = 0
#CG nach vorn nach RHs sezten
FEMSei.ProjectHDivVecDG!(backend,FTB,cVecDG,VecDG,cRTNew,RTTR,Grid,Grids.Tri(),nQuad,FEMSei.Jacobi!)
#FEMSei.DivMomentumVector!(backend,FTB,Rhs,u,RT,cVecDG,VecDG,RT,Grid,Grids.Tri(),nQuad,FEMSei.Jacobi!)
FEMSei.DivMomentumVector!(backend,FTB,Rhs,RT,u,RT,cVecDG,VecDG,Grid,Grids.Tri(),nQuad,FEMSei.Jacobi!)
ldiv!(RTTR.LUM,Rhs)
@. cRT = cRT + dtau * Rhs
if mod(i,nprint) == 0
FEMSei.ConvertVelocitySp!(backend,FTB,VelSp,cRT,RTTR,Grid,FEMSei.Jacobi!)
global FileNumber += 1
Outputs.vtkSkeleton!(vtkSkeletonMesh, "Proj_Recov_Tri", Proc, ProcNumber,VelSp, FileNumber)
end
end
@show "finished"
Loading

0 comments on commit e0c2a08

Please sign in to comment.