1 | import os
|
---|
2 | import numpy
|
---|
3 |
|
---|
4 | def SetIceShelfBC(md,icefrontfile=''):
|
---|
5 | """
|
---|
6 | SETICESHELFBC - Create the boundary conditions for diagnostic and thermal models for a Ice Shelf with Ice Front
|
---|
7 |
|
---|
8 | Neumann BC are used on the ice front (an ANRGUS contour around the ice front
|
---|
9 | must be given in input)
|
---|
10 | Dirichlet BC are used elsewhere for diagnostic
|
---|
11 |
|
---|
12 | Usage:
|
---|
13 | md=SetIceShelfBC(md,varargin)
|
---|
14 |
|
---|
15 | Example:
|
---|
16 | md=SetIceShelfBC(md);
|
---|
17 | md=SetIceShelfBC(md,'Front.exp');
|
---|
18 |
|
---|
19 | See also: SETICESHEETBC, SETMARINEICESHEETBC
|
---|
20 | """
|
---|
21 |
|
---|
22 | #node on Dirichlet (boundary and ~icefront)
|
---|
23 | if icefrontfile:
|
---|
24 | if not os.path.exists(icefrontfile):
|
---|
25 | raise IOError("SetIceShelfBC error message: ice front file '%s' not found." % icefrontfile)
|
---|
26 | nodeinsideicefront=ContourToMesh(md.mesh.elements,md.mesh.x,md.mesh.y,icefrontfile,'node',2)
|
---|
27 | nodeonicefront=double(md.mesh.vertexonboundary and nodeinsideicefront)
|
---|
28 | else:
|
---|
29 | nodeonicefront=numpy.zeros(md.mesh.numberofvertices)
|
---|
30 |
|
---|
31 | # pos=find(md.mesh.vertexonboundary & ~nodeonicefront);
|
---|
32 | pos=[i for i,(vob,noif) in enumerate(zip(md.mesh.vertexonboundary,nodeonicefront)) if vob and not noif]
|
---|
33 | md.diagnostic.spcvx=float('NaN')*numpy.ones(md.mesh.numberofvertices)
|
---|
34 | md.diagnostic.spcvy=float('NaN')*numpy.ones(md.mesh.numberofvertices)
|
---|
35 | md.diagnostic.spcvz=float('NaN')*numpy.ones(md.mesh.numberofvertices)
|
---|
36 | md.diagnostic.spcvx[pos]=0
|
---|
37 | md.diagnostic.spcvy[pos]=0
|
---|
38 | md.diagnostic.spcvz[pos]=0
|
---|
39 | md.diagnostic.referential=float('NaN')*numpy.ones((md.mesh.numberofvertices,6))
|
---|
40 |
|
---|
41 | #Dirichlet Values
|
---|
42 | if numpy.size(md.inversion.vx_obs)==md.mesh.numberofvertices and numpy.size(md.inversion.vy_obs)==md.mesh.numberofvertices:
|
---|
43 | print ' boundary conditions for diagnostic model: spc set as observed velocities'
|
---|
44 | md.diagnostic.spcvx[pos]=md.inversion.vx_obs[pos]
|
---|
45 | md.diagnostic.spcvy[pos]=md.inversion.vy_obs[pos]
|
---|
46 | else:
|
---|
47 | print ' boundary conditions for diagnostic model: spc set as zero'
|
---|
48 |
|
---|
49 | #segment on Ice Front
|
---|
50 | #segment on Neumann (Ice Front)
|
---|
51 | # pos=find(nodeonicefront(md.mesh.segments(:,1)) | nodeonicefront(md.mesh.segments(:,2)));
|
---|
52 | pos=[i for i,(noif1,noif2) in enumerate(zip(nodeonicefront[md.mesh.segments[:,0].astype('int')-1],nodeonicefront[md.mesh.segments[:,1].astype('int')-1])) if noif1 or noif2]
|
---|
53 | if md.mesh.dimension==2:
|
---|
54 | pressureload=md.mesh.segments[pos,:]
|
---|
55 | elif md.mesh.dimension==3:
|
---|
56 | # pressureload_layer1=[md.mesh.segments(pos,1:2) md.mesh.segments(pos,2)+md.mesh.numberofvertices2d md.mesh.segments(pos,1)+md.mesh.numberofvertices2d md.mesh.segments(pos,3)];
|
---|
57 | pressureload_layer1=numpy.concatenate((md.mesh.segments[pos,0:2],md.mesh.segments[pos,1]+md.mesh.numberofvertices2d,md.mesh.segments[pos,0]+md.mesh.numberofvertices2d,md.mesh.segments[pos,2]),axis=1)
|
---|
58 | pressureload=numpy.zeros((0,5))
|
---|
59 | for i in xrange(1,md.mesh.numberoflayers):
|
---|
60 | # pressureload=[pressureload ;pressureload_layer1(:,1:4)+(i-1)*md.mesh.numberofvertices2d pressureload_layer1(:,5)+(i-1)*md.mesh.numberofelements2d ];
|
---|
61 | pressureload=numpy.concatenate((pressureload,numpy.concatenate((pressureload_layer1[:,0:3]+(i-1)*md.mesh.numberofvertices2d,pressureload_layer1[:,4]+(i-1)*md.mesh.numberofelements2d),axis=1)),axis=0)
|
---|
62 |
|
---|
63 | #Add water or air enum depending on the element
|
---|
64 | # pressureload=[pressureload 1*md.mask.elementonfloatingice(pressureload(:,end))];
|
---|
65 | pressureload=numpy.concatenate((pressureload,1*md.mask.elementonfloatingice[pressureload[:,-1].astype('int')-1].reshape((-1,1))),axis=1)
|
---|
66 |
|
---|
67 | #plug onto model
|
---|
68 | md.diagnostic.icefront=pressureload
|
---|
69 |
|
---|
70 | #Create zeros basalforcings and surfaceforcings
|
---|
71 | if numpy.isnan(md.surfaceforcings.precipitation).all():
|
---|
72 | md.surfaceforcings.precipitation=numpy.zeros(md.mesh.numberofvertices)
|
---|
73 | print ' no surfaceforcings.precipitation specified: values set as zero'
|
---|
74 | if numpy.isnan(md.surfaceforcings.mass_balance).all():
|
---|
75 | md.surfaceforcings.mass_balance=numpy.zeros(md.mesh.numberofvertices)
|
---|
76 | print ' no surfaceforcings.mass_balance specified: values set as zero'
|
---|
77 | if numpy.isnan(md.basalforcings.melting_rate).all():
|
---|
78 | md.basalforcings.melting_rate=numpy.zeros(md.mesh.numberofvertices)
|
---|
79 | print ' no basalforcings.melting_rate specified: values set as zero'
|
---|
80 | if numpy.isnan(md.balancethickness.thickening_rate).all():
|
---|
81 | md.balancethickness.thickening_rate=numpy.zeros(md.mesh.numberofvertices)
|
---|
82 | print ' no balancethickness.thickening_rate specified: values set as zero'
|
---|
83 |
|
---|
84 | md.prognostic.spcthickness=float('NaN')*numpy.ones(md.mesh.numberofvertices)
|
---|
85 | md.balancethickness.spcthickness=float('NaN')*numpy.ones(md.mesh.numberofvertices)
|
---|
86 |
|
---|
87 | if numpy.size(md.initialization.temperature)==md.mesh.numberofvertices:
|
---|
88 | md.thermal.spctemperature=float('NaN')*numpy.ones(md.mesh.numberofvertices)
|
---|
89 | # pos=find(md.mesh.vertexonsurface); md.thermal.spctemperature(pos)=md.initialization.temperature(pos); %impose observed temperature on surface
|
---|
90 | pos=[i for i,vos in enumerate(md.mesh.vertexonsurface) if vos]
|
---|
91 | md.thermal.spctemperature[pos]=md.initialization.temperature[pos] # impose observed temperature on surface
|
---|
92 | if not numpy.size(md.basalforcings.geothermalflux)==md.mesh.numberofvertices:
|
---|
93 | md.basalforcings.geothermalflux=numpy.zeros(md.mesh.numberofvertices)
|
---|
94 | else:
|
---|
95 | print ' no thermal boundary conditions created: no observed temperature found'
|
---|
96 |
|
---|
97 | return md
|
---|
98 |
|
---|