source: issm/oecreview/Archive/25834-26739/ISSM-26491-26492.diff

Last change on this file was 26740, checked in by Mathieu Morlighem, 3 years ago

CHG: added 25834-26739

File size: 4.5 KB
  • ../trunk-jpl/src/jl/plotmodel.jl

     
    2727                        fig, ax, h = Makie.mesh( [md.mesh.x md.mesh.y], md.mesh.elements, shading = false, color = data, colormap = jet)
    2828
    2929                        #Add colorbar
    30                         Colorbar(fig[1, 2], h, width=25)
     30                        #Colorbar(fig[1, 2], h, width=25)
    3131                else
    3232                        error("data of size "*string(length(data))*" not supported yet!")
    3333                end
  • ../trunk-jpl/src/jl/issm.jl

     
    1212function Mesh2dTriangle() #{{{
    1313        return Mesh2dTriangle( 0, 0, Vector{Float64}(undef,0), Vector{Float64}(undef, 0), Matrix{Int32}(undef, 0, 0))
    1414end# }}}
     15function 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                else
     24                        println(io,"empty")
     25                end
     26        end
     27end# }}}
    1528mutable struct Mesh3dPrism{T} <: AbstractMesh
    1629        numberofvertices::Int32
    1730        numberofelements::Int32
     
    4053function Mask() #{{{
    4154        return Mask( Vector{Float64}(undef,0), Vector{Float64}(undef,0))
    4255end# }}}
     56mutable struct Initialization
     57        vx::Vector{Float64}
     58        vy::Vector{Float64}
     59end
     60function Initialization() #{{{
     61        return Initialization( Vector{Float64}(undef,0), Vector{Float64}(undef,0))
     62end# }}}
     63mutable struct Materials
     64        rho_ice::Float64
     65        rho_water::Float64
     66        rho_freshwater::Float64
     67        mu_water::Float64
     68        heatcapacity::Float64
     69        latentheat::Float64
     70        thermalconductivity::Float64
     71        temperateiceconductivity::Float64
     72        effectiveconductivity_averaging::Int32
     73        meltingpoint::Float64
     74        beta::Float64
     75        mixed_layer_capacity::Float64
     76        thermal_exchange_velocity::Float64
     77        rheology_B::Vector{Float64}
     78        rheology_n::Vector{Float64}
     79        rheology_law::String
     80end
     81function Materials() #{{{
     82        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")
     83end# }}}
    4384
    4485mutable struct model
    4586        mesh::AbstractMesh
    4687        geometry::Geometry
    4788        mask::Mask
     89        materials::Materials
     90        initialization::Initialization
    4891end
    4992function model() #{{{
    50         return model( Mesh2dTriangle(), Geometry(), Mask())
     93        return model( Mesh2dTriangle(), Geometry(), Mask(), Materials(), Initialization())
    5194end#}}}
    5295function Base.show(io::IO, md::model)# {{{
    5396
     
    57100        @printf "%19s: %-22s -- %s\n" "mesh" typeof(md.mesh) "mesh properties"
    58101        @printf "%19s: %-22s -- %s\n" "geometry" typeof(md.geometry) "surface elevation, bedrock topography, ice thickness,..."
    59102        @printf "%19s: %-22s -- %s\n" "mask" typeof(md.mask) "defines grounded and floating regions"
     103        @printf "%19s: %-22s -- %s\n" "materials" typeof(md.materials) "material properties"
     104        @printf "%19s: %-22s -- %s\n" "initialization" typeof(md.initialization) "initial state"
    60105
    61106end# }}}
    62107
    63 # Probably actually want something more like:
    64 # function solve(mesh::AbstractMesh, data::AbstractDataset)
    65 #     do_something_with_mesh(mesh) # This will dispatch
    66 #     do_something_with_data(data) # This will dispatch
    67 #     # do something
    68 # end
     108#utils
     109function issmdir() #{{{
     110        issmdir = ENV["ISSM_DIR"]
     111
     112        if isempty(issmdir)
     113                error("Could not determine the location of ISSM")
     114        else
     115                return issmdir
     116        end
     117end#}}}
     118function archread(filename::String,variablename::String) #{{{
     119
     120        #initialize variables
     121        found = false
     122
     123        #open file
     124        output = open(filename, "r") do f
     125
     126                while !eof(f)
     127                        reclen  = bswap(read(f, Int32))
     128                        rectype = bswap(read(f, Int32))
     129                        if rectype!=1
     130                                error("Expected variable of type string")
     131                        else
     132                                fieldname_length = bswap(read(f, Int32))
     133                                field_name = String(read(f, fieldname_length))
     134                        end
     135                        rec_length = bswap(read(f, Int32))
     136                        field_type = bswap(read(f, Int32))
     137                        if field_type==2
     138                                data = bswap(read(f, Float64))
     139                        elseif field_type==3
     140                                rows = bswap(read(f, Int32))
     141                                cols = bswap(read(f, Int32))
     142                                data = reinterpret(Float64, read(f, sizeof(Float64)*rows*cols))
     143                                data .= ntoh.(data)
     144                                data = reshape(data, (rows,cols))
     145                        else
     146                                error("Error: Encountered invalid field type when reading data.")
     147                        end
     148
     149                        if field_name == variablename
     150                                found = true
     151                                return data
     152                        end
     153                end
     154        end
     155
     156        return output
     157end# }}}
Note: See TracBrowser for help on using the repository browser.