Changeset 12191


Ignore:
Timestamp:
05/03/12 12:43:52 (13 years ago)
Author:
Eric.Larour
Message:

Further translation of SetIceShelfBC.m to python

File:
1 edited

Legend:

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

    r12127 r12191  
    1 def SetIceShelfBC(md,icefrontfile='')
     1from numpy import *
     2def SetIceShelfBC(md,icefrontfile=''):
    23        #SETICESHELFBC - Create the boundary conditions for diagnostic and thermal models for a  Ice Shelf with Ice Front
    34        #
     
    2223                        print 'SetIceShelfBC error message: ice front file '+icefrontfile+ ' not found'
    2324                        return []
    24                 nodeinsideicefront=ContourToMesh(md.mesh.elements,md.mesh.x,md.mesh.y,icefrontfile,'node',2);
    25                 nodeonicefront=double(md.mesh.vertexonboundary & nodeinsideicefront);
     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))
    2627       
    27         pos=find(md.mesh.vertexonboundary & ~nodeonicefront);
    28         md.diagnostic.spcvx=NaN*ones(md.mesh.numberofvertices,1);
    29         md.diagnostic.spcvy=NaN*ones(md.mesh.numberofvertices,1);
    30         md.diagnostic.spcvz=NaN*ones(md.mesh.numberofvertices,1);
    31         md.diagnostic.spcvx(pos)=0;
    32         md.diagnostic.spcvy(pos)=0;
    33         md.diagnostic.spcvz(pos)=0;
    34         md.diagnostic.referential=NaN*ones(md.mesh.numberofvertices,6);
     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);
    3536
    3637        #Dirichlet Values
    37         if (length(md.inversion.vx_obs)==md.mesh.numberofvertices & length(md.inversion.vy_obs)==md.mesh.numberofvertices)
    38                 disp('      boundary conditions for diagnostic model: spc set as observed velocities');
    39                 md.diagnostic.spcvx(pos)=md.inversion.vx_obs(pos);
    40                 md.diagnostic.spcvy(pos)=md.inversion.vy_obs(pos);
    41         else
    42                 disp('      boundary conditions for diagnostic model: spc set as zero');
    43         end
     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]
     43        else:
     44                print '      boundary conditions for diagnostic model: spc set as zero'
    4445
    4546        #segment on Ice Front
    4647        #segment on Neumann (Ice Front)
    47         pos=find(nodeonicefront(md.mesh.segments(:,1)) | nodeonicefront(md.mesh.segments(:,2)));
    48         if (md.mesh.dimension==2)
    49                 pressureload=md.mesh.segments(pos,:);
    50         elseif md.mesh.dimension==3
    51                 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)];
     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,:];
     54        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]];
    5256                pressureload=[];
    53                 for i=1:md.mesh.numberoflayers-1,
    54                         pressureload=[pressureload ;pressureload_layer1(:,1:4)+(i-1)*md.mesh.numberofvertices2d pressureload_layer1(:,5)+(i-1)*md.mesh.numberofelements2d ];
    55                 end
    56         end
     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 ];
    5759
    5860        #Add water or air enum depending on the element
    59         pressureload=[pressureload 1*md.mask.elementonfloatingice(pressureload(:,end))];
     61        pressureload=[pressureload, 1*md.mask.elementonfloatingice(pressureload[:,end])];
    6062
    6163        #plug onto model
     
    6365
    6466        #Create zeros basalforcings and surfaceforcings
    65         if isnan(md.surfaceforcings.precipitation),
    66                 md.surfaceforcings.precipitation=zeros(md.mesh.numberofvertices,1);
    67                 disp('      no surfaceforcings.precipitation specified: values set as zero');
    68         end
    69         if isnan(md.surfaceforcings.mass_balance),
    70                 md.surfaceforcings.mass_balance=zeros(md.mesh.numberofvertices,1);
    71                 disp('      no surfaceforcings.mass_balance specified: values set as zero');
    72         end
    73         if isnan(md.basalforcings.melting_rate),
    74                 md.basalforcings.melting_rate=zeros(md.mesh.numberofvertices,1);
    75                 disp('      no basalforcings.melting_rate specified: values set as zero');
    76         end
    77         if isnan(md.balancethickness.thickening_rate),
    78                 md.balancethickness.thickening_rate=zeros(md.mesh.numberofvertices,1);
    79                 disp('      no balancethickness.thickening_rate specified: values set as zero');
    80         end
     67        if isnan(md.surfaceforcings.precipitation):
     68                md.surfaceforcings.precipitation=zeros(md.mesh.numberofvertices);
     69                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);
     72                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)
     75                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);
     78                print '      no balancethickness.thickening_rate specified: values set as zero'
    8179
    82         md.prognostic.spcthickness=NaN*ones(md.mesh.numberofvertices,1);
    83         md.balancethickness.spcthickness=NaN*ones(md.mesh.numberofvertices,1);
     80        md.prognostic.spcthickness=NaN*ones(md.mesh.numberofvertices);
     81        md.balancethickness.spcthickness=NaN*ones(md.mesh.numberofvertices);
    8482
    85         if (length(md.initialization.temperature)==md.mesh.numberofvertices),
    86                 md.thermal.spctemperature=NaN*ones(md.mesh.numberofvertices,1);
    87                 pos=find(md.mesh.vertexonsurface); md.thermal.spctemperature(pos)=md.initialization.temperature(pos); #impose observed temperature on surface
    88                 if (length(md.basalforcings.geothermalflux)~=md.mesh.numberofvertices),
    89                         md.basalforcings.geothermalflux=zeros(md.mesh.numberofvertices,1);
    90                 end
    91         else
    92                 disp('      no thermal boundary conditions created: no observed temperature found');
    93         end
     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);
     88        else:
     89                print '      no thermal boundary conditions created: no observed temperature found'
     90
     91        return md
Note: See TracChangeset for help on using the changeset viewer.