Changeset 26522
- Timestamp:
- 10/29/21 08:05:53 (3 years ago)
- Location:
- issm/trunk-jpl/src/jl
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/jl/issm.jl
r26518 r26522 1 using Printf 1 # Julia version of the Ice-sheet and Sea-level System Model 2 # 3 # Author: Mathieu Morlighem 4 # email: mathieu.morlighem@dartmouth.edu 2 5 3 #Define classes used by model struct 4 abstract type AbstractMesh end 5 mutable struct Mesh2dTriangle <: AbstractMesh 6 numberofvertices::Int64 7 numberofelements::Int64 8 x::Vector{Float64} 9 y::Vector{Float64} 10 elements::Matrix{Int64} 6 module ISSM 7 8 include("classes.jl") 9 include("utils.jl") 10 include("triangle.jl") 11 include("parameterization.jl") 12 include("solve.jl") 13 #include("plotmodel.jl") 14 11 15 end 12 function Mesh2dTriangle() #{{{13 return Mesh2dTriangle( 0, 0, Vector{Float64}(undef,0), Vector{Float64}(undef, 0), Matrix{Int64}(undef, 0, 0))14 end# }}}15 function Base.show(io::IO, this::Mesh2dTriangle)# {{{16 17 println(io,typeof(this),":")18 for name in fieldnames(typeof(this))19 a=getfield(this,name)20 print(io," $(name) = ")21 if !isempty(a)22 println(io, typeof(a), " of size ", size(a))23 else24 println(io,"empty")25 end26 end27 end# }}}28 mutable struct Mesh3dPrism{T} <: AbstractMesh29 numberofvertices::Int6430 numberofelements::Int6431 numberoflayers::Int6432 x::Vector{Float64}33 y::Vector{Float64}34 z::Vector{Float64}35 elements::Matrix{Int64}36 end37 function Mesh3dPrism() #{{{38 return Mesh3dPrism( 0, 0, 0, Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0), Matrix{Int64}(undef, 0, 0))39 end# }}}40 mutable struct Geometry41 surface::Vector{Float64}42 base::Vector{Float64}43 thickness::Vector{Float64}44 bed::Vector{Float64}45 end46 function Geometry() #{{{47 return Geometry( Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0))48 end# }}}49 mutable struct Mask50 ocean_levelset::Vector{Float64}51 ice_levelset::Vector{Float64}52 end53 function Mask() #{{{54 return Mask( Vector{Float64}(undef,0), Vector{Float64}(undef,0))55 end# }}}56 mutable struct Initialization57 vx::Vector{Float64}58 vy::Vector{Float64}59 end60 function Initialization() #{{{61 return Initialization( Vector{Float64}(undef,0), Vector{Float64}(undef,0))62 end# }}}63 mutable struct Stressbalance64 spcvx::Vector{Float64}65 spcvy::Vector{Float64}66 restol::Float6467 reltol::Float6468 abstol::Float6469 maxiter::Int6470 end71 function Stressbalance() #{{{72 return Stressbalance( Vector{Float64}(undef,0), Vector{Float64}(undef,0), 0., 0., 0., 0)73 end# }}}74 mutable struct Constants75 g::Float6476 yts::Float6477 end78 function Constants() #{{{79 return Constants( 9.81, 365*24*3600.)80 end# }}}81 mutable struct Materials82 rho_ice::Float6483 rho_water::Float6484 rho_freshwater::Float6485 mu_water::Float6486 heatcapacity::Float6487 latentheat::Float6488 thermalconductivity::Float6489 temperateiceconductivity::Float6490 effectiveconductivity_averaging::Int6491 meltingpoint::Float6492 beta::Float6493 mixed_layer_capacity::Float6494 thermal_exchange_velocity::Float6495 rheology_B::Vector{Float64}96 rheology_n::Vector{Float64}97 rheology_law::String98 end99 function Materials() #{{{100 return Materials(917., 1023., 1000., 0.001787, 2093., 3.34*10^5, 2.4, .24, 1, 273.15, 9.8*10^-8, 3974., 1.00*10^-4, Vector{Float64}(undef,0), Vector{Float64}(undef,0), "Cuffey")101 end# }}}102 103 mutable struct model104 mesh::AbstractMesh105 geometry::Geometry106 mask::Mask107 materials::Materials108 initialization::Initialization109 stressbalance::Stressbalance110 constants::Constants111 end112 function model() #{{{113 return model( Mesh2dTriangle(), Geometry(), Mask(), Materials(), Initialization(),Stressbalance(), Constants())114 end#}}}115 function Base.show(io::IO, md::model)# {{{116 117 compact = get(io, :compact, false)118 119 println(io,"Model:")120 @printf "%19s: %-22s -- %s\n" "mesh" typeof(md.mesh) "mesh properties"121 @printf "%19s: %-22s -- %s\n" "geometry" typeof(md.geometry) "surface elevation, bedrock topography, ice thickness,..."122 @printf "%19s: %-22s -- %s\n" "mask" typeof(md.mask) "defines grounded and floating regions"123 @printf "%19s: %-22s -- %s\n" "materials" typeof(md.materials) "material properties"124 @printf "%19s: %-22s -- %s\n" "initialization" typeof(md.initialization) "initial state"125 @printf "%19s: %-22s -- %s\n" "stressbalance" typeof(md.stressbalance) "stress balance parameters"126 @printf "%19s: %-22s -- %s\n" "constants" typeof(md.constants) "physical constants"127 128 end# }}}129 130 #utils131 function issmdir() #{{{132 issmdir = ENV["ISSM_DIR"]133 134 if isempty(issmdir)135 error("Could not determine the location of ISSM")136 else137 return issmdir138 end139 end#}}}140 function archread(filename::String,variablename::String) #{{{141 142 #initialize variables143 found = false144 145 #open file146 output = open(filename, "r") do f147 148 while !eof(f)149 reclen = bswap(read(f, Int32))150 rectype = bswap(read(f, Int32))151 if rectype!=1152 error("Expected variable of type string")153 else154 fieldname_length = bswap(read(f, Int32))155 field_name = String(read(f, fieldname_length))156 end157 rec_length = bswap(read(f, Int32))158 field_type = bswap(read(f, Int32))159 if field_type==2160 data = bswap(read(f, Float64))161 elseif field_type==3162 rows = bswap(read(f, Int32))163 cols = bswap(read(f, Int32))164 data = reinterpret(Float64, read(f, sizeof(Float64)*rows*cols))165 data .= ntoh.(data)166 data = reshape(data, (rows,cols))167 data = collect(data)168 if cols == 1169 data = vec(data)170 end171 else172 error("Error: Encountered invalid field type when reading data.")173 end174 175 if field_name == variablename176 found = true177 return data178 end179 end180 end181 182 return output183 end# }}}184 function InterpFromMeshToMesh2d(index::Array,x::Vector,y::Vector,data::Vector,xout::Vector,yout::Vector) #{{{185 #prepare input arrays186 nods = Cint(length(x))187 nels = Cint(size(index,1))188 nods_interp = Cint(length(xout))189 Cindex=Array{Cint,1}(undef,length(index))190 for i in 1:size(index,1)191 for j in 1:3192 Cindex[(i-1)*3+j] = Int32(index[i,j])193 end194 end195 Cx = Array{Cdouble,1}(undef,nods)196 Cy = Array{Cdouble,1}(undef,nods)197 Cdata = Array{Cdouble,1}(undef,nods)198 for i in 1:nods199 Cx[i] = x[i]200 Cy[i] = y[i]201 Cdata[i] = data[i]202 end203 Cxout = Array{Cdouble,1}(undef,nods_interp)204 Cyout = Array{Cdouble,1}(undef,nods_interp)205 for i in 1:nods_interp206 Cxout[i] = xout[i]207 Cyout[i] = yout[i]208 end209 210 Cdataout = Vector{Float64}(undef,nods_interp)211 212 #This is not working....213 rc=ccall( (:InterpFromMeshToMesh2dx,"libISSMCore"),214 Cint, (Ptr{Ptr{Cdouble}},Ptr{Cint}, Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cint, Ptr{Cdouble}, Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Cint),215 Ref(Ref(Cdataout)), Ref(Cindex), Ref(Cx), Ref(Cy), nods, nels,216 Ref(Cdata), nods, 1, Ref(Cxout), Ref(Cyout), nods_interp)217 218 #Process output219 dataout = Vector{Float64}(undef,nods_interp)220 for i in 1:nods_interp221 dataout[i] = Cdataout[i]222 end223 224 return dataout225 end #}}}226 function solve(md::model,solution::String) #{{{227 228 if solution=="sb" || solution=="Stressbalance"229 solutionstring = "StressbalanceSolution"230 else231 error("solutionstring "*solution*" not supported!");232 end233 234 IssmCore(md)235 236 return md237 end #}}} -
issm/trunk-jpl/src/jl/parameterization.jl
r26500 r26522 1 include(" issm.jl")1 include("classes.jl") 2 2 include("exp.jl") 3 3 -
issm/trunk-jpl/src/jl/plotmodel.jl
r26492 r26522 2 2 3 3 using GLMakie 4 include("classes.jl") 5 using .ISSM 4 6 5 function plotmodel(md:: model,data)7 function plotmodel(md::ISSM.model,data::Vector) 6 8 7 9 vertexcolor = :black -
issm/trunk-jpl/src/jl/solve.jl
r26518 r26522 1 include(" issm.jl")1 include("classes.jl") 2 2 include("issmenums.jl") 3 3 … … 209 209 210 210 #Solve 211 error("not there yet")212 211 Stressbalance(femmodel) 213 212 … … 317 316 end#}}} 318 317 function CreateConstraints(analysis::StressbalanceAnalysis,constraints::Vector{Constraint},md::model) #{{{ 319 error("stop") 320 end#}}} 318 319 #load constraints from model 320 spcvx = md.stressbalance.spcvx 321 spcvy = md.stressbalance.spcvy 322 323 count = 1 324 for i in 1:md.mesh.numberofvertices 325 if ~isnan(spcvx[i]) 326 push!(constraints,Constraint(count,i,1,spcvx[i])) 327 count+=1 328 end 329 if ~isnan(spcvy[i]) 330 push!(constraints,Constraint(count,i,2,spcvy[i])) 331 count+=1 332 end 333 end 334 335 end#}}} 336 function Stressbalance(femmodel::FemModel) 337 error("STOP") 338 end 321 339 322 340 #Element functions -
issm/trunk-jpl/src/jl/test101.jl
r26500 r26522 1 1 #!/Applications/Julia-1.6.app/Contents/Resources/julia/bin/julia 2 include("triangle.jl") 3 include("parameterization.jl") 4 include("solve.jl") 2 include("issm.jl") 3 using .ISSM 5 4 6 md = model()7 md = triangle(md,"../../test/Exp/Square.exp",180000.)8 md = setmask(md,"all","")5 md = ISSM.model() 6 md = ISSM.triangle(md,"../../test/Exp/Square.exp",180000.) 7 md = ISSM.setmask(md,"all","") 9 8 10 9 #Geometry … … 21 20 22 21 #Initial velocity 23 x = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","x")24 y = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","y")25 vx = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","vx")26 vy = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","vy")27 index = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","index")22 x = ISSM.archread(ISSM.issmdir()*"/test/Data/SquareShelfConstrained.arch","x") 23 y = ISSM.archread(ISSM.issmdir()*"/test/Data/SquareShelfConstrained.arch","y") 24 vx = ISSM.archread(ISSM.issmdir()*"/test/Data/SquareShelfConstrained.arch","vx") 25 vy = ISSM.archread(ISSM.issmdir()*"/test/Data/SquareShelfConstrained.arch","vy") 26 index = ISSM.archread(ISSM.issmdir()*"/test/Data/SquareShelfConstrained.arch","index") 28 27 md.initialization.vx=zeros(md.mesh.numberofvertices)#InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y) 29 28 md.initialization.vy=zeros(md.mesh.numberofvertices)#InterpFromMeshToMesh2d(index,x,y,vy,md.mesh.x,md.mesh.y) … … 36 35 md.stressbalance.abstol=NaN 37 36 38 md=solve(md,"Stressbalance") 37 #Boundary conditions 38 md.stressbalance.spcvx = NaN*ones(md.mesh.numberofvertices) 39 md.stressbalance.spcvy = NaN*ones(md.mesh.numberofvertices) 40 pos = findall(md.mesh.vertexonboundary) 41 md.stressbalance.spcvx[pos] .= 0.0 42 md.stressbalance.spcvy[pos] .= 0.0 43 44 md=ISSM.solve(md,"Stressbalance") -
issm/trunk-jpl/src/jl/triangle.jl
r26500 r26522 51 51 52 52 using Printf #needed for sprintf 53 include(" issm.jl")53 include("classes.jl") 54 54 include("exp.jl") 55 55 … … 162 162 points = convert(Array{Cdouble,2}, Base.unsafe_wrap(Array, ctio_out.pointlist, (2,Int(ctio_out.numberofpoints)), own=true))' 163 163 triangles = convert(Array{Cint,2}, Base.unsafe_wrap(Array, ctio_out.trianglelist, (3,Int(ctio_out.numberoftriangles)), own=true))' .+1 164 segments = convert(Array{Cint,2}, Base.unsafe_wrap(Array, ctio_out.segmentlist, (2,Int(ctio_out.numberofsegments)), own=true))' .+1 165 166 #assign output 164 167 md.mesh = Mesh2dTriangle() 165 168 md.mesh.numberofvertices = ctio_out.numberofpoints … … 168 171 md.mesh.y = points[:,2] 169 172 md.mesh.elements = triangles 173 md.mesh.segments = segments 174 175 #post processing 176 md.mesh.vertexonboundary = zeros(Bool,md.mesh.numberofvertices) 177 md.mesh.vertexonboundary[md.mesh.segments] .= true 170 178 171 179 return md
Note:
See TracChangeset
for help on using the changeset viewer.