Changeset 26471
- Timestamp:
- 10/05/21 06:30:28 (3 years ago)
- Location:
- issm/trunk-jpl/src/jl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/jl/issm.jl
r26467 r26471 1 using Printf 2 3 #Define classes used by model struct 1 4 abstract type AbstractMesh end 2 3 struct Mesh2dTriangle <: AbstractMesh 5 mutable struct Mesh2dTriangle <: AbstractMesh 4 6 numberofvertices::Int32 5 7 numberofelements::Int32 … … 8 10 elements::Matrix{Int32} 9 11 end 10 11 struct Mesh3dPrism{T} <: AbstractMesh 12 function Mesh2dTriangle() #{{{ 13 return Mesh2dTriangle( 0, 0, Vector{Float64}(undef,0), Vector{Float64}(undef, 0), Matrix{Int32}(undef, 0, 0)) 14 end# }}} 15 mutable struct Mesh3dPrism{T} <: AbstractMesh 12 16 numberofvertices::Int32 13 17 numberofelements::Int32 … … 18 22 elements::Matrix{Int32} 19 23 end 20 21 struct Geometry 24 function Mesh3dPrism() #{{{ 25 return Mesh3dPrism( 0, 0, 0, Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0), Matrix{Int32}(undef, 0, 0)) 26 end# }}} 27 mutable struct Geometry 22 28 surface::Vector{Float64} 23 29 base::Vector{Float64} … … 25 31 bed::Vector{Float64} 26 32 end 33 function Geometry() #{{{ 34 return Geometry( Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0)) 35 end# }}} 27 36 28 function configure(; 29 MeshType = Mesh2dTriangle, 30 meshnbv = 0, 31 meshnbe = 0, 32 meshx = [NaN], 33 meshy = [NaN], 34 meshel = [0], 35 GeometryType = Geometry, 36 geos = [NaN], 37 geob1 = [NaN], 38 geoh = [NaN], 39 geob2 = [NaN], 40 ) 37 mutable struct model 38 mesh::AbstractMesh 39 geometry::Geometry 40 end 41 function model() #{{{ 42 return model(Mesh2dTriangle(),Geometry()) 43 end#}}} 44 function Base.show(io::IO, md::model)# {{{ 41 45 42 mesh = MeshType(meshnbv,meshnbe,meshx,meshy,meshel) 43 geometry = Geometry(geos,geob1,geoh,geob2) 46 compact = get(io, :compact, false) 44 47 45 return (mesh = mesh, geometry = geometry) 46 end 48 println(io,"Model:") 49 @printf "%19s: %-22s -- %s\n" "mesh" typeof(md.mesh) "mesh properties" 50 @printf "%19s: %-22s -- %s\n" "geometry" typeof(md.geometry) "surface elevation, bedrock topography, ice thickness,..." 47 51 48 solve(model::NamedTuple) = solve(model.mesh, model.geometry) 49 50 function solve(mesh::Mesh2dTriangle, geometry::Geometry) 51 println("Solving with triangular mesh, ... data, ...") 52 # do something 53 end 54 function solve(mesh::Mesh3dPrism, geometry::Geometry) 55 println("Solving with rectangular mesh, ... data, ...") 56 # do something 57 end 52 end# }}} 58 53 59 54 # Probably actually want something more like: … … 63 58 # # do something 64 59 # end 65 66 function remake(model::NamedTuple;67 MeshType = typeof(model.mesh),68 meshnbv = model.mesh.nbv,69 meshnbe = model.mesh.nbe,70 meshx = model.mesh.x,71 meshy = model.mesh.y,72 meshel = model.mesh.elements,73 surface = model.geometry.surface,74 base = model.geometry.base,75 thickness = model.geometry.thickness,76 bed = model.geometry.bed,77 )78 79 mesh = MeshType(meshnbv, meshnbe, meshx, meshy, meshel)80 geometry = geometry(surface, base, thickness, bed)81 82 return (mesh = mesh, geometry = geometry)83 end84 85 function remesh(model::NamedTuple;86 MeshType = Mesh2dTriangle,87 meshx = rand(1000),88 meshy = rand(1000)89 )90 91 new_mesh = MeshType(meshx, meshy)92 return (mesh = new_mesh, data = model.data)93 end94 95 ## --- Try it out96 97 # Just use default parameters98 model = configure()99 solve(model)100 ## --- Try it out101 102 # Actually specify some relevant parameters103 model = configure(104 MeshType = Mesh3dPrism,105 foo = rand(10000),106 bar = rand(1000,1000),107 baz = randn(1000,1000)108 )109 solve(model) -
issm/trunk-jpl/src/jl/triangle.jl
r26467 r26471 1 1 #see https://github.com/JuliaGeometry/Triangulate.jl/blob/master/src/plot.jl 2 #see https://github.com/JuliaGeometry/MeshViz.jl/blob/master/src/simplemesh.jl 2 3 3 4 #Class Triangle's triangulateio … … 52 53 53 54 using Printf, PyPlot 55 using GLMakie 54 56 """ 55 57 TRIANGLE - create model mesh using the triangle package … … 166 168 #plot 167 169 clf() 168 fig = matplotlib[:pyplot][:figure]("2D Mesh Plot", figsize = (10,10)) 169 ax = matplotlib[:pyplot][:axes]() 170 ax[:set_aspect]("equal") 171 tri = ax[:triplot](points[:,1], points[:,2], elements.-1) 172 setp(tri, linestyle = "-", linewidth = 1.5, marker = "None", markersize = 5., color = "blue") 173 174 fig[:canvas][:draw]() 170 if false 171 poly(points, elements, strokewidth=1, shading=false,transparency=true) 172 else 173 fig = matplotlib[:pyplot][:figure]("2D Mesh Plot", figsize = (10,10)) 174 ax = matplotlib[:pyplot][:axes]() 175 ax[:set_aspect]("equal") 176 tri = ax[:triplot](points[:,1], points[:,2], elements.-1) 177 setp(tri, linestyle = "-", linewidth = 1.5, marker = "None", markersize = 5., color = "blue") 178 fig[:canvas][:draw]() 179 end 175 180 176 181 end#}}}
Note:
See TracChangeset
for help on using the changeset viewer.