Changeset 12854


Ignore:
Timestamp:
08/01/12 15:29:34 (13 years ago)
Author:
jschierm
Message:

Revised python version of SetIceShelfBC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/utils/BC/SetIceShelfBC.py

    r12191 r12854  
    1 from numpy import *
     1import os
     2import numpy
     3
    24def SetIceShelfBC(md,icefrontfile=''):
    3         #SETICESHELFBC - Create the boundary conditions for diagnostic and thermal models for a  Ice Shelf with Ice Front
    4         #
    5         #   Neumann BC are used on the ice front (an ANRGUS contour around the ice front
    6         #   must be given in input)
    7         #   Dirichlet BC are used elsewhere for diagnostic
    8         #
    9         #   Usage:
    10         #      md=SetIceShelfBC(md,varargin)
    11         #
    12         #   Example:
    13         #      md=SetIceShelfBC(md);
    14         #      md=SetIceShelfBC(md,'Front.exp');
    15         #
    16         #   See also: SETICESHEETBC, SETMARINEICESHEETBC
     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        """
    1721
    1822        #node on Dirichlet (boundary and ~icefront)
    19         if not icefrontfile:
    20                 nodeonicefront=zeros(md.mesh.numberofvertices)
     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)
    2128        else:
    22                 if not os.path.isfile(icefrontfile):
    23                         print 'SetIceShelfBC error message: ice front file '+icefrontfile+ ' not found'
    24                         return []
    25                 nodeinsideicefront=ContourToMesh(md.mesh.elements,md.mesh.x,md.mesh.y,icefrontfile,'node',2)
    26                 nodeonicefront=double(md.mesh.vertexonboundary.astype(bool) and nodeinsideicefront.astype(bool))
    27        
    28         pos=argwhere(logical_and(md.mesh.vertexonboundary.astype(bool),~nodeonicefront.astype(bool)))
    29         md.diagnostic.spcvx=NaN*ones(md.mesh.numberofvertices);
    30         md.diagnostic.spcvy=NaN*ones(md.mesh.numberofvertices);
    31         md.diagnostic.spcvz=NaN*ones(md.mesh.numberofvertices);
    32         md.diagnostic.spcvx[pos]=0;
    33         md.diagnostic.spcvy[pos]=0;
    34         md.diagnostic.spcvz[pos]=0;
    35         md.diagnostic.referential=float('NaN')*ones((md.mesh.numberofvertices,6),float);
     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))
    3640
    3741        #Dirichlet Values
    38         if ~isnan(md.inversion.vx_obs) and ~isnan(md.inversion.vy_obs):
    39                 if (len(md.inversion.vx_obs)==md.mesh.numberofvertices) and (len(md.inversion.vy_obs)==md.mesh.numberofvertices):
    40                         print '      boundary conditions for diagnostic model: spc set as observed velocities'
    41                         md.diagnostic.spcvx[pos]=md.inversion.vx_obs[pos]
    42                         md.diagnostic.spcvy[pos]=md.inversion.vy_obs[pos]
     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]
    4346        else:
    4447                print '      boundary conditions for diagnostic model: spc set as zero'
     
    4649        #segment on Ice Front
    4750        #segment on Neumann (Ice Front)
    48         segs1=md.mesh.segments[:,0].astype(int)-1
    49         segs2=md.mesh.segments[:,1].astype(int)-1
    50 
    51         pos=argwhere(logical_and(nodeonicefront[segs1].astype(bool),nodeonicefront[segs2].astype(bool)))
    52         if (md.mesh.dimension==2):
    53                 pressureload=md.mesh.segments[pos,:];
     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,:]
    5455        elif md.mesh.dimension==3:
    55                 pressureload_layer=[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]];
    56                 pressureload=[];
    57                 for i in range(1,md.mesh.numberoflayers-1):
    58                         pressureload=[pressureload ,pressureload_layer1[:,1:4]+(i-1)*md.mesh.numberofvertices2d, pressureload_layer1[:,5]+(i-1)*md.mesh.numberofelements2d ];
     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)
    5962
    6063        #Add water or air enum depending on the element
    61         pressureload=[pressureload, 1*md.mask.elementonfloatingice(pressureload[:,end])];
     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)
    6266
    6367        #plug onto model
    64         md.diagnostic.icefront=pressureload;
     68        md.diagnostic.icefront=pressureload
    6569
    6670        #Create zeros basalforcings and surfaceforcings
    67         if isnan(md.surfaceforcings.precipitation):
    68                 md.surfaceforcings.precipitation=zeros(md.mesh.numberofvertices);
     71        if numpy.isnan(md.surfaceforcings.precipitation).all():
     72                md.surfaceforcings.precipitation=numpy.zeros(md.mesh.numberofvertices)
    6973                print '      no surfaceforcings.precipitation specified: values set as zero'
    70         if isnan(md.surfaceforcings.mass_balance):
    71                 md.surfaceforcings.mass_balance=zeros(md.mesh.numberofvertices);
     74        if numpy.isnan(md.surfaceforcings.mass_balance).all():
     75                md.surfaceforcings.mass_balance=numpy.zeros(md.mesh.numberofvertices)
    7276                print '      no surfaceforcings.mass_balance specified: values set as zero'
    73         if isnan(md.basalforcings.melting_rate):
    74                 md.basalforcings.melting_rate=zeros(md.mesh.numberofvertices)
     77        if numpy.isnan(md.basalforcings.melting_rate).all():
     78                md.basalforcings.melting_rate=numpy.zeros(md.mesh.numberofvertices)
    7579                print '      no basalforcings.melting_rate specified: values set as zero'
    76         if isnan(md.balancethickness.thickening_rate):
    77                 md.balancethickness.thickening_rate=zeros(md.mesh.numberofvertices);
     80        if numpy.isnan(md.balancethickness.thickening_rate).all():
     81                md.balancethickness.thickening_rate=numpy.zeros(md.mesh.numberofvertices)
    7882                print '      no balancethickness.thickening_rate specified: values set as zero'
    7983
    80         md.prognostic.spcthickness=NaN*ones(md.mesh.numberofvertices);
    81         md.balancethickness.spcthickness=NaN*ones(md.mesh.numberofvertices);
     84        md.prognostic.spcthickness=float('NaN')*numpy.ones(md.mesh.numberofvertices)
     85        md.balancethickness.spcthickness=float('NaN')*numpy.ones(md.mesh.numberofvertices)
    8286
    83         if (len(md.initialization.temperature)==md.mesh.numberofvertices):
    84                 md.thermal.spctemperature=NaN*ones(md.mesh.numberofvertices);
    85                 pos=argwhere(md.mesh.vertexonsurface); md.thermal.spctemperature[pos]=md.initialization.temperature[pos]; #impose observed temperature on surface
    86                 if (len(md.basalforcings.geothermalflux) !=md.mesh.numberofvertices):
    87                         md.basalforcings.geothermalflux=zeros(md.mesh.numberofvertices);
     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)
    8894        else:
    8995                print '      no thermal boundary conditions created: no observed temperature found'
    9096
    9197        return md
     98
Note: See TracChangeset for help on using the changeset viewer.