Changeset 26492 for issm/trunk-jpl/src/jl/issm.jl
- Timestamp:
- 10/20/21 10:01:31 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/jl/issm.jl
r26472 r26492 12 12 function Mesh2dTriangle() #{{{ 13 13 return Mesh2dTriangle( 0, 0, Vector{Float64}(undef,0), Vector{Float64}(undef, 0), Matrix{Int32}(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 else 24 println(io,"empty") 25 end 26 end 14 27 end# }}} 15 28 mutable struct Mesh3dPrism{T} <: AbstractMesh … … 41 54 return Mask( Vector{Float64}(undef,0), Vector{Float64}(undef,0)) 42 55 end# }}} 56 mutable struct Initialization 57 vx::Vector{Float64} 58 vy::Vector{Float64} 59 end 60 function Initialization() #{{{ 61 return Initialization( Vector{Float64}(undef,0), Vector{Float64}(undef,0)) 62 end# }}} 63 mutable 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 80 end 81 function 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") 83 end# }}} 43 84 44 85 mutable struct model … … 46 87 geometry::Geometry 47 88 mask::Mask 89 materials::Materials 90 initialization::Initialization 48 91 end 49 92 function model() #{{{ 50 return model( Mesh2dTriangle(), Geometry(), Mask() )93 return model( Mesh2dTriangle(), Geometry(), Mask(), Materials(), Initialization()) 51 94 end#}}} 52 95 function Base.show(io::IO, md::model)# {{{ … … 58 101 @printf "%19s: %-22s -- %s\n" "geometry" typeof(md.geometry) "surface elevation, bedrock topography, ice thickness,..." 59 102 @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" 60 105 61 106 end# }}} 62 107 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 109 function 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 117 end#}}} 118 function 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 157 end# }}}
Note:
See TracChangeset
for help on using the changeset viewer.