Exemple #1
0
from varglas.data.data_factory    import DataFactory
from varglas.mesh.mesh_factory    import MeshFactory
from varglas.io                   import DataInput, DataOutput
from varglas.helper               import default_config
from fenics                       import *
from scipy.io                     import loadmat

# get the input args :
out_dir = 'dump/bed/09/bv_smb/'
in_dir  = 'dump/bed/09/'

mesh   = Mesh(in_dir + 'submesh.xdmf')
Q      = FunctionSpace(mesh, 'CG', 1)

bamber = DataFactory.get_bamber()
dbm    = DataInput(bamber,  mesh=mesh)

S      = Function(Q)
B      = Function(Q)

File(in_dir + 'S_s.xml') >> S
File(in_dir + 'B_s.xml') >> B

adot_v = loadmat(in_dir + 'smb/smb.mat')
dbm.data['smb'] = adot_v['map_data']

adot = dbm.get_expression('smb', near=True)

config = default_config()
config['output_path']               = out_dir
config['balance_velocity']['kappa'] = 5.0
# set the output directory :
out_dir = dir_b + str(i) + '/'
in_dir = 'vars/'

set_log_active(True)

thklim = 1.0

measures = DataFactory.get_ant_measures(res=450)
bedmap1 = DataFactory.get_bedmap1(thklim=thklim)
bedmap2 = DataFactory.get_bedmap2(thklim=thklim)

mesh = MeshFactory.get_ronne_3D_50H()

dm = DataInput(measures, mesh=mesh)
db1 = DataInput(bedmap1, mesh=mesh)
db2 = DataInput(bedmap2, mesh=mesh)

db2.data['B'] = db2.data['S'] - db2.data['H']
db2.set_data_val('H', 32767, thklim)
db2.data['S'] = db2.data['B'] + db2.data['H']

H = db2.get_nearest_expression("H")
S = db2.get_nearest_expression("S")
B = db2.get_nearest_expression("B")
M = db2.get_nearest_expression("mask")
T_s = db1.get_nearest_expression("srfTemp")
q_geo = db1.get_nearest_expression("q_geo")
adot = db1.get_nearest_expression("adot")
U_ob = dm.get_projection("U_ob", near=True)
Exemple #3
0
from varglas.data.data_factory import DataFactory
from pylab import *
from scipy.interpolate import interp2d

#===============================================================================
# data preparation :
out_dir = 'dump/meshes/'

# collect the raw data :
bamber = DataFactory.get_bamber()
rignot = DataFactory.get_rignot()
searise = DataFactory.get_searise()
gimp = DataFactory.get_gimp()

# create data objects to use with varglas :
dbm = DataInput(bamber, gen_space=False)
drg = DataInput(rignot, gen_space=False)
dsr = DataInput(searise, gen_space=False)
dgm = DataInput(gimp, gen_space=False)

drg.set_data_max('U_ob', boundary=1000.0, val=1000.0)
drg.set_data_min('U_ob', boundary=0.0, val=0.0)

#===============================================================================
# form field from which to refine :
## antarctica :: Info : 4449632 vertices 25902918 elements
#drg.data['ref'] = (0.02 + 1/(1 + drg.data['U_ob'])) * 50000
dbm.data['ref'] = 5 * dbm.data['H'].copy()
dbm.data['ref'][dbm.data['ref'] < 5000.0] = 5000.0

## plot to check :
valid  = intersect1d(valid, where(U_ob_v > 1e-9)[0])
valid  = intersect1d(valid, where(abs(Mb_v) < 200)[0])
valid  = intersect1d(valid, where(S_v > -100)[0])
valid  = intersect1d(valid, where(Ts_v > 100)[0])
valid  = intersect1d(valid, where(h_v > 0)[0])
valid  = intersect1d(valid, where(S_v - B_v > 60)[0])
valid  = intersect1d(valid, where(adot_v > -100)[0])

valid_f          = Function(Q)
valid_f_v        = valid_f.vector().array()
valid_f_v[valid] = 1.0
valid_f.vector().set_local(valid_f_v)
valid_f.vector().apply('insert')

rignot   = DataFactory.get_gre_rignot()
drg      = DataInput(rignot, gen_space=False)

betaMax = 200.0

ini_f = Function(Q)
ini_f.vector()[:] = ini
plotIce(drg, ini_f, name='ini', direc='images/stats/' + file_n,
        cmap='gist_yarg', scale='log', numLvls=12, tp=False,
        tpAlpha=0.5, show=False, umin=1.0, umax=betaMax)

Ubar_avg_f = Function(Q)
Ubar_avg_f.vector()[:] = Ubar_avg
plotIce(drg, Ubar_avg_f, name='Ubar_avg', direc='images/stats/' + file_n,
        title=r'$\Vert \mathbf{\bar{u}}_{\bar{bv}} \Vert$', cmap='gist_yarg', 
        scale='log', numLvls=12, tp=False,
        tpAlpha=0.5, show=False, umin=1.0, umax=4000.0)
Exemple #5
0
valid = intersect1d(valid, where(U_ob_v > 1e-10)[0])
valid = intersect1d(valid, where(abs(Mb_v) < 200)[0])
valid = intersect1d(valid, where(S_v > -100)[0])
valid = intersect1d(valid, where(Ts_v > 100)[0])
valid = intersect1d(valid, where(h_v > 0)[0])
valid = intersect1d(valid, where(S_v - B_v > 60)[0])
valid = intersect1d(valid, where(adot_v > -100)[0])

valid_f = Function(Q)
valid_f_v = valid_f.vector().array()
valid_f_v[valid] = 1.0
valid_f.vector().set_local(valid_f_v)
valid_f.vector().apply('insert')

measures = DataFactory.get_ant_measures(res=900)
dm = DataInput(measures, gen_space=False)

betaMax = 200.0

#ini_f = Function(Q)
#ini_f.vector()[:] = ini
#plotIce(dm, ini_f, name='ini', direc='images/stats/' + file_n,
#        cmap='gist_yarg', scale='log', numLvls=12, tp=False,
#        tpAlpha=0.5, show=False, umin=1.0, umax=betaMax)
#
#Ubar_avg_f = Function(Q)
#Ubar_avg_f.vector()[:] = Ubar_avg
#plotIce(dm, Ubar_avg_f, name='Ubar_avg', direc='images/stats/' + file_n,
#        title=r'$\Vert \mathbf{\bar{u}}_{\bar{bv}} \Vert$', cmap='gist_yarg',
#        scale='log', numLvls=12, tp=False,
#        tpAlpha=0.5, show=False, umin=1.0, umax=4000.0)
Exemple #6
0
config['mode'] = 'transient'
config['model_order'] = 'L1L2'
config['output_path'] = out_dir
config['t_start'] = 0.0
config['t_end'] = 35000.0
config['time_step'] = 10.0
config['periodic_boundary_conditions'] = False
config['velocity']['poly_degree'] = 2
config['enthalpy']['on'] = True
config['enthalpy']['N_T'] = 8
config['free_surface']['on'] = True
config['free_surface']['thklim'] = thklim
config['velocity']['transient_beta'] = 'stats'

bedmap2 = DataFactory.get_bedmap2()
db2 = DataInput(bedmap2, mesh=mesh)

db2.data['Sn'] = db2.data['S'] + thklim

B = db2.get_expression("B", near=True)
S = db2.get_expression("Sn", near=True)

model = Model(config)
model.set_mesh(mesh)


class Adot(Expression):
    Rel = 450000
    s = 1e-5

    def eval(self, values, x):
Exemple #7
0
# -*- coding: utf-8 -*-
"""
Create a rectangular test mesh.
"""

from varglas.meshing           import MeshGenerator
from varglas.io                import DataInput
from varglas.data.data_factory import DataFactory
import numpy as np


b = DataFactory.get_bamber()
db = DataInput(b, gen_space = False) 
m = MeshGenerator(db, 'mesh_250', '')

xs = [0.0, 100e3, 100e3, 0.0]
ys = [0.0, 0.0, 20e3, 20e3] 

domain_coordinates = np.transpose([xs, ys])

m.set_contour(domain_coordinates)
m.write_gmsh_contour(250)
m.close_file()
Exemple #8
0
g_conv = arange(len(a_valid), len(g_valid) + len(a_valid))

a_valid_f = Function(a_Q)
a_valid_f_v = a_valid_f.vector().array()
a_valid_f_v[a_valid] = 1.0
a_valid_f.vector().set_local(a_valid_f_v)
a_valid_f.vector().apply('insert')

g_valid_f = Function(g_Q)
g_valid_f_v = g_valid_f.vector().array()
g_valid_f_v[g_valid] = 1.0
g_valid_f.vector().set_local(g_valid_f_v)
g_valid_f.vector().apply('insert')

measures = DataFactory.get_ant_measures(res=900)
dm = DataInput(measures, gen_space=False)

rignot = DataFactory.get_gre_rignot()
drg = DataInput(rignot, gen_space=False)

betaMax = 200.0

#===============================================================================

#plotIce(dm, a_valid_f, name='valid', direc=a_fn,
#        cmap='gist_yarg', scale='bool', numLvls=12, tp=False,
#        tpAlpha=0.5, show=False)
#
#plotIce(drg, g_valid_f, name='valid', direc=g_fn,
#        cmap='gist_yarg', scale='bool', numLvls=12, tp=False,
#        tpAlpha=0.5, show=False)
Exemple #9
0
from varglas.helper            import default_config
from varglas.model             import Model

set_log_active(False)

thklim = 1.0

# collect the raw data :
searise = DataFactory.get_searise(thklim = thklim)
bamber  = DataFactory.get_bamber(thklim = thklim)

# load a mesh :
mesh  = MeshFactory.get_greenland_2D_5H()

# create data objects to use with varglas :
dsr   = DataInput(searise, mesh=mesh)
dbm   = DataInput(bamber,  mesh=mesh)

dbm.data['S'] = dbm.data['B'] + thklim

B     = dbm.get_expression('B',    near=True)
S     = dbm.get_expression('S',    near=True)
adot  = dsr.get_expression('adot', near=True)
T_s   = dsr.get_interpolation('T', near=True)

out_dir = 'dump/transient_H/'

parameters['form_compiler']['quadrature_degree'] = 2
parameters['form_compiler']['precision']         = 30
#parameters['form_compiler']['optimize']          = True
parameters['form_compiler']['cpp_optimize']      = True
Exemple #10
0
from fenics                       import *

out_dir  = 'dump/vars_ant_spacing/'
thklim   = 1.0

# collect the raw data :
searise  = DataFactory.get_searise(thklim = thklim)
bamber   = DataFactory.get_bamber(thklim = thklim)
fm_qgeo  = DataFactory.get_gre_qgeo_fox_maule()
rignot   = DataFactory.get_gre_rignot()

# define the mesh :
mesh = Mesh('dump/meshes/gre_mesh_ant_spacing.xml')

# create data objects to use with varglas :
dsr     = DataInput(searise,  mesh=mesh)
dbm     = DataInput(bamber,   mesh=mesh)
dfm     = DataInput(fm_qgeo,  mesh=mesh)
drg     = DataInput(rignot,   mesh=mesh)
    
# change the projection of all data to Rignot projection :
dsr.change_projection(drg)
dbm.change_projection(drg)
dfm.change_projection(drg)

# get the expressions used by varglas :
S     = dbm.get_expression('S',        near=True)
B     = dbm.get_expression('B',        near=True)
M     = dbm.get_expression('mask',     near=True)
adot  = dsr.get_expression('adot',     near=True)
T_s   = dsr.get_interpolation('T',     near=True)
Exemple #11
0
from varglas.meshing import MeshGenerator, MeshRefiner
from varglas.data.data_factory import DataFactory
from varglas.io import DataInput, print_min_max
from pylab import *
from scipy.interpolate import interp2d

#===============================================================================
# data preparation :
out_dir = 'dump/meshes/'

# get the data :
measure = DataFactory.get_ant_measures()
bedmap2 = DataFactory.get_bedmap2()

# process the data :
dbm = DataInput(measure, gen_space=False)
db2 = DataInput(bedmap2, gen_space=False)

dbm.set_data_min('U_ob', boundary=0.0, val=0.0)
db2.set_data_val("H", 32767, 0.0)
db2.set_data_val('S', 32767, 0.0)

# calculate surface gradient :
gradS = gradient(db2.data['S'])
gS_n = sqrt(gradS[0]**2 + gradS[1]**2 + 1e-16)

# create interpolation object to convert measures to bedmap2 coordinates :
interp = interp2d(db2.x, db2.y, gS_n)
gS_n = interp(dbm.x, dbm.y)
interp = interp2d(db2.x, db2.y, db2.data['mask'])
mask = interp(dbm.x, dbm.y)
Exemple #12
0
from varglas.io                import DataInput, MeshGenerator, MeshRefiner
from varglas.data.data_factory import DataFactory
from pylab                     import *


#===============================================================================
# data preparation :
thklim = 0.0

# create meshgrid for contour :
bedmap2 = DataFactory.get_bedmap2()

# process the data :
db2 = DataInput(bedmap2, gen_space=False)
#db2.set_data_val("H", 32767, thklim)
#db2.set_data_val('S', 32767, 0.0)
#
#db2.data['B'] = db2.data['S'] - db2.data['H']
#
#gradS = gradient(db2.data['S'])
#gS_n  = sqrt(gradS[0]**2 + gradS[1]**2) + 1
#
#db2.data['ref'] = db2.data['H'] / gS_n

db2.data['mask'][db2.data['mask'] == 1]   = 100
db2.data['mask'][db2.data['mask'] == 127] = 0
db2.data['mask'][db2.data['mask'] == 1]   = 0

# plot to check :
imshow(db2.data['mask'][::-1,:])
colorbar()
Exemple #13
0
File(ant_in_dir + 'adot_s.xml') >> a_adot
File(ant_in_dir + 'qgeo_s.xml') >> a_qgeo
File(ant_in_dir + 'beta_s.xml') >> a_beta
File(ant_in_dir + 'Mb_s.xml')   >> a_Mb
File(ant_in_dir + 'Tb_s.xml')   >> a_Tb
File(ant_in_dir + 'Ts_s.xml')   >> a_Ts
File(ant_in_dir + 'u_s.xml')    >> a_u
File(ant_in_dir + 'v_s.xml')    >> a_v
File(ant_in_dir + 'w_s.xml')    >> a_w
File('antarctica/dump/bed/balance_velocity/Ubar_s.xml') >> a_Ubar
File('antarctica/dump/bed/balance_water/q.xml')         >> a_qbar

#===============================================================================
# plotting :
bedmap1  = DataFactory.get_bedmap1(thklim=1.0)
d1       = DataInput(bedmap1, mesh=a_mesh)
  
cmap = 'gist_earth'
cmap = 'RdYlGn'
cmap = 'RdGy'
cmap = 'gist_gray'
cmap = 'Purples'
cmap = 'Reds'
cmap = 'Oranges'

plotIce(d1, 'B', '.', 'gist_yarg', scale='lin', name=r'$B$', 
        numLvls=12, tp=False, tpAlpha=0.5)

#===============================================================================

a_dSdx   = project(a_S.dx(0), a_Q)
S = Function(Q)
B = Function(Q)

File(in_dir + 'S_s.xml') >> S
File(in_dir + 'B_s.xml') >> B

config = default_config()
config['output_path'] = out_dir
config['balance_velocity']['kappa'] = 5.0
config['model_order'] = 'SSA'

model = model.Model(config)
model.set_mesh(mesh)
model.set_surface_and_bed(S, B)
model.initialize_variables()

model.init_adot(in_dir + 'adot_s.xml')

F = solvers.BalanceVelocitySolver(model, config)

F.solve()

model.save_xml(model.Ubar, 'Ubar_5')

bedmap = DataFactory.get_bedmap1()
bm = DataInput(bedmap, gen_space=False)

do = DataOutput(out_dir)
do.write_matlab(bm, model.Ubar, 'Ubar_5', val=0.0)
Exemple #15
0
from scipy.interpolate import RectBivariateSpline

kappa = 5.0  # ice thickness to refine

#===============================================================================
# data preparation :
out_dir = 'dump/meshes/'
mesh_name = 'jakobshavn_3D_%iH_mesh_block' % int(kappa)

# get the data :
bamber = DataFactory.get_bamber()
#rignot   = DataFactory.get_rignot()
#searise  = DataFactory.get_searise()

# process the data :
dbm = DataInput(bamber, gen_space=False)
#drg      = DataInput(rignot,  gen_space=False)
#dsr      = DataInput(searise, gen_space=False)

#drg.change_projection(dbm)
#dbm.change_projection(drg)

## calculate surface gradient :
#U_ob   = sqrt(drg.data['vx']**2 + drg.data['vy']**2 + 1e-16)
#
#U_ob[U_ob < 1e-15]  = 1e-15
#U_ob[U_ob > 1000.0] = 1000.0
#
#drg.data['U_ob'] = U_ob

## plot to check :