Changeset 26471


Ignore:
Timestamp:
10/05/21 06:30:28 (3 years ago)
Author:
Mathieu Morlighem
Message:

CHG: slow progress...

Location:
issm/trunk-jpl/src/jl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/jl/issm.jl

    r26467 r26471  
     1using Printf
     2
     3#Define classes used by model struct
    14abstract type AbstractMesh end
    2 
    3 struct Mesh2dTriangle <: AbstractMesh
     5mutable struct Mesh2dTriangle <: AbstractMesh
    46        numberofvertices::Int32
    57        numberofelements::Int32
     
    810        elements::Matrix{Int32}
    911end
    10 
    11 struct Mesh3dPrism{T} <: AbstractMesh
     12function Mesh2dTriangle() #{{{
     13        return Mesh2dTriangle( 0, 0, Vector{Float64}(undef,0), Vector{Float64}(undef, 0), Matrix{Int32}(undef, 0, 0))
     14end# }}}
     15mutable struct Mesh3dPrism{T} <: AbstractMesh
    1216        numberofvertices::Int32
    1317        numberofelements::Int32
     
    1822        elements::Matrix{Int32}
    1923end
    20 
    21 struct Geometry
     24function Mesh3dPrism() #{{{
     25        return Mesh3dPrism( 0, 0, 0, Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0), Matrix{Int32}(undef, 0, 0))
     26end# }}}
     27mutable struct Geometry
    2228        surface::Vector{Float64}
    2329        base::Vector{Float64}
     
    2531        bed::Vector{Float64}
    2632end
     33function Geometry() #{{{
     34        return Geometry( Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0), Vector{Float64}(undef,0))
     35end# }}}
    2736
    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     )
     37mutable struct model
     38        mesh::AbstractMesh
     39        geometry::Geometry
     40end
     41function model() #{{{
     42        return model(Mesh2dTriangle(),Geometry())
     43end#}}}
     44function Base.show(io::IO, md::model)# {{{
    4145
    42         mesh = MeshType(meshnbv,meshnbe,meshx,meshy,meshel)
    43         geometry = Geometry(geos,geob1,geoh,geob2)
     46        compact = get(io, :compact, false)
    4447
    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,..."
    4751
    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
     52end# }}}
    5853
    5954# Probably actually want something more like:
     
    6358#     # do something
    6459# 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 end
    84 
    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 end
    94 
    95 ## --- Try it out
    96 
    97 # Just use default parameters
    98 model = configure()
    99 solve(model)
    100 ## --- Try it out
    101 
    102 # Actually specify some relevant parameters
    103 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  
    11#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
    23
    34#Class Triangle's triangulateio
     
    5253
    5354using Printf, PyPlot
     55using GLMakie
    5456"""
    5557TRIANGLE - create model mesh using the triangle package
     
    166168        #plot
    167169        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
    175180       
    176181end#}}}
Note: See TracChangeset for help on using the changeset viewer.