Changeset 23431


Ignore:
Timestamp:
10/17/18 03:28:24 (6 years ago)
Author:
bdef
Message:

BUG: fix for model colapse

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/classes/model.py

    r23095 r23431  
    1616from basalforcings import basalforcings
    1717from matice import matice
    18 from levelset import levelset 
     18from levelset import levelset
    1919from calving import calving
    2020from fourierlove import fourierlove
     
    7575
    7676                # classtype=model.properties
    77                                
     77
    7878                # for classe in dict.keys(classtype):
    7979                #       print classe
     
    225225                   This routine extracts a submodel from a bigger model with respect to a given contour
    226226                   md must be followed by the corresponding exp file or flags list
    227                    It can either be a domain file (argus type, .exp extension), or an array of element flags. 
    228                    If user wants every element outside the domain to be 
     227                   It can either be a domain file (argus type, .exp extension), or an array of element flags.
     228                   If user wants every element outside the domain to be
    229229                   extract2d, add '~' to the name of the domain file (ex: '~HO.exp')
    230230                   an empty string '' will be considered as an empty domain
     
    349349                        md2.mesh.lowerelements[pos]=Pelem[md2.mesh.lowerelements[pos].astype(int)-1]
    350350
    351                 #Initial 2d mesh 
     351                #Initial 2d mesh
    352352                if md1.mesh.__class__.__name__=='mesh3dprisms':
    353353                        flag_elem_2d=flag_elem[np.arange(0,md1.mesh.numberofelements2d)]
     
    431431                if np.size(md1.stressbalance.spcvx)>1 and np.size(md1.stressbalance.spcvy)>2 and np.size(md1.stressbalance.spcvz)>2:
    432432                        if np.size(md1.inversion.vx_obs)>1 and np.size(md1.inversion.vy_obs)>1:
    433                                 md2.stressbalance.spcvx[nodestoflag2]=md2.inversion.vx_obs[nodestoflag2] 
     433                                md2.stressbalance.spcvx[nodestoflag2]=md2.inversion.vx_obs[nodestoflag2]
    434434                                md2.stressbalance.spcvy[nodestoflag2]=md2.inversion.vy_obs[nodestoflag2]
    435435                        else:
     
    508508                    - follow two polynomial laws, one for the lower part and one for the upper part of the mesh
    509509                    - be discribed by a list of coefficients (between 0 and 1)
    510  
     510
    511511
    512512                   Usage:
     
    596596                number_nodes3d=np.size(x3d)    #number of 3d nodes for the non extruded part of the mesh
    597597
    598                 #Extrude elements 
     598                #Extrude elements
    599599                elements3d=np.empty((0,6),int)
    600600                for i in xrange(numlayers-1):
     
    618618                md.mesh.upperelements=upperelements
    619619
    620                 #Save old mesh 
     620                #Save old mesh
    621621                md.mesh.x2d=md.mesh.x
    622622                md.mesh.y2d=md.mesh.y
     
    625625                md.mesh.numberofvertices2d=md.mesh.numberofvertices
    626626
    627                 #Build global 3d mesh 
     627                #Build global 3d mesh
    628628                md.mesh.elements=elements3d
    629629                md.mesh.x=x3d
     
    672672
    673673                md.materials.extrude(md)
    674                 md.damage.extrude(md)
     674                if md.damage.isdamage==1:
     675                        md.damage.extrude(md)
    675676                md.gia.extrude(md)
    676677                md.mask.extrude(md)
     
    688689                '''
    689690                collapses a 3d mesh into a 2d mesh
    690                        
     691
    691692                This routine collapses a 3d model into a 2d model and collapses all
    692693                the fileds of the 3d model by taking their depth-averaged values
    693                        
     694
    694695                Usage:
    695696                        md=collapse(md)
    696                 '''     
     697                '''
    697698
    698699                #Check that the model is really a 3d model
    699700                if md.mesh.domaintype().lower() != '3d':
    700701                        raise StandardError("only a 3D model can be collapsed")
    701                
     702
    702703                #dealing with the friction law
    703704                #drag is limited to nodes that are on the bedrock.
    704                 if hasattr(md.friction,'coefficient'): 
     705                if hasattr(md.friction,'coefficient'):
    705706                        md.friction.coefficient=project2d(md,md.friction.coefficient,1)
    706707
    707708                #p and q (same deal, except for element that are on the bedrock: )
    708                 if hasattr(md.friction,'p'): 
     709                if hasattr(md.friction,'p'):
    709710                        md.friction.p=project2d(md,md.friction.p,1)
    710                 if hasattr(md.friction,'q'): 
     711                if hasattr(md.friction,'q'):
    711712                        md.friction.q=project2d(md,md.friction.q,1)
    712                
    713                 if hasattr(md.friction,'coefficientcoulomb'): 
     713
     714                if hasattr(md.friction,'coefficientcoulomb'):
    714715                        md.friction.coefficientcoulomb=project2d(md,md.friction.coefficientcoulomb,1)
    715                 if hasattr(md.friction,'C'): 
     716                if hasattr(md.friction,'C'):
    716717                        md.friction.C=project2d(md,md.friction.C,1)
    717                 if hasattr(md.friction,'As'): 
     718                if hasattr(md.friction,'As'):
    718719                        md.friction.As=project2d(md,md.friction.As,1)
    719720                if hasattr(md.friction,'effective_pressure') and not np.isnan(md.friction.effective_pressure).all():
    720721                        md.friction.effective_pressure=project2d(md,md.friction.effective_pressure,1)
    721                 if hasattr(md.friction,'water_layer'): 
     722                if hasattr(md.friction,'water_layer'):
    722723                        md.friction.water_layer=project2d(md,md.friction.water_layer,1)
    723                 if hasattr(md.friction,'m'): 
     724                if hasattr(md.friction,'m'):
    724725                        md.friction.m=project2d(md,md.friction.m,1)
    725726
    726727                #observations
    727                 if not np.isnan(md.inversion.vx_obs).all(): 
    728                         md.inversion.vx_obs=project2d(md,md.inversion.vx_obs,md.mesh.numberoflayers) 
    729                 if not np.isnan(md.inversion.vy_obs).all(): 
    730                         md.inversion.vy_obs=project2d(md,md.inversion.vy_obs,md.mesh.numberoflayers) 
    731                 if not np.isnan(md.inversion.vel_obs).all(): 
    732                         md.inversion.vel_obs=project2d(md,md.inversion.vel_obs,md.mesh.numberoflayers) 
    733                 if not np.isnan(md.inversion.cost_functions_coefficients).all(): 
    734                         md.inversion.cost_functions_coefficients=project2d(md,md.inversion.cost_functions_coefficients,md.mesh.numberoflayers) 
     728                if not np.isnan(md.inversion.vx_obs).all():
     729                        md.inversion.vx_obs=project2d(md,md.inversion.vx_obs,md.mesh.numberoflayers)
     730                if not np.isnan(md.inversion.vy_obs).all():
     731                        md.inversion.vy_obs=project2d(md,md.inversion.vy_obs,md.mesh.numberoflayers)
     732                if not np.isnan(md.inversion.vel_obs).all():
     733                        md.inversion.vel_obs=project2d(md,md.inversion.vel_obs,md.mesh.numberoflayers)
     734                if not np.isnan(md.inversion.cost_functions_coefficients).all():
     735                        md.inversion.cost_functions_coefficients=project2d(md,md.inversion.cost_functions_coefficients,md.mesh.numberoflayers)
    735736                if isinstance(md.inversion.min_parameters,np.ndarray):
    736                         if md.inversion.min_parameters.size>1: 
    737                                 md.inversion.min_parameters=project2d(md,md.inversion.min_parameters,md.mesh.numberoflayers) 
     737                        if md.inversion.min_parameters.size>1:
     738                                md.inversion.min_parameters=project2d(md,md.inversion.min_parameters,md.mesh.numberoflayers)
    738739                if isinstance(md.inversion.max_parameters,np.ndarray):
    739                         if md.inversion.max_parameters.size>1: 
    740                                 md.inversion.max_parameters=project2d(md,md.inversion.max_parameters,md.mesh.numberoflayers) 
     740                        if md.inversion.max_parameters.size>1:
     741                                md.inversion.max_parameters=project2d(md,md.inversion.max_parameters,md.mesh.numberoflayers)
    741742                if not np.isnan(md.smb.mass_balance).all():
    742                         md.smb.mass_balance=project2d(md,md.smb.mass_balance,md.mesh.numberoflayers) 
    743                
     743                        md.smb.mass_balance=project2d(md,md.smb.mass_balance,md.mesh.numberoflayers)
     744
    744745                #results
    745                 if not np.isnan(md.initialization.vx).all(): 
     746                if not np.isnan(md.initialization.vx).all():
    746747                        md.initialization.vx=DepthAverage(md,md.initialization.vx)
    747                 if not np.isnan(md.initialization.vy).all(): 
     748                if not np.isnan(md.initialization.vy).all():
    748749                        md.initialization.vy=DepthAverage(md,md.initialization.vy)
    749                 if not np.isnan(md.initialization.vz).all(): 
     750                if not np.isnan(md.initialization.vz).all():
    750751                        md.initialization.vz=DepthAverage(md,md.initialization.vz)
    751                 if not np.isnan(md.initialization.vel).all(): 
     752                if not np.isnan(md.initialization.vel).all():
    752753                        md.initialization.vel=DepthAverage(md,md.initialization.vel)
    753                 if not np.isnan(md.initialization.temperature).all(): 
     754                if not np.isnan(md.initialization.temperature).all():
    754755                        md.initialization.temperature=DepthAverage(md,md.initialization.temperature)
    755                 if not np.isnan(md.initialization.pressure).all(): 
     756                if not np.isnan(md.initialization.pressure).all():
    756757                        md.initialization.pressure=project2d(md,md.initialization.pressure,1)
    757                 if not np.isnan(md.initialization.sediment_head).all(): 
     758                if not np.isnan(md.initialization.sediment_head).all():
    758759                        md.initialization.sediment_head=project2d(md,md.initialization.sediment_head,1)
    759                 if not np.isnan(md.initialization.epl_head).all(): 
     760                if not np.isnan(md.initialization.epl_head).all():
    760761                        md.initialization.epl_head=project2d(md,md.initialization.epl_head,1)
    761                 if not np.isnan(md.initialization.epl_thickness).all(): 
     762                if not np.isnan(md.initialization.epl_thickness).all():
    762763                        md.initialization.epl_thickness=project2d(md,md.initialization.epl_thickness,1)
    763764
    764765                #giaivins
    765                 if not np.isnan(md.gia.mantle_viscosity).all(): 
    766                         md.gia.mantle_viscosity=project2d(md,md.gia.mantle_viscosity,1) 
    767                 if not np.isnan(md.gia.lithosphere_thickness).all(): 
    768                         md.gia.lithosphere_thickness=project2d(md,md.gia.lithosphere_thickness,1) 
     766                if not np.isnan(md.gia.mantle_viscosity).all():
     767                        md.gia.mantle_viscosity=project2d(md,md.gia.mantle_viscosity,1)
     768                if not np.isnan(md.gia.lithosphere_thickness).all():
     769                        md.gia.lithosphere_thickness=project2d(md,md.gia.lithosphere_thickness,1)
    769770
    770771                #elementstype
     
    777778
    778779                # Hydrologydc variables
    779                 if hasattr(md.hydrology,'hydrologydc'):
     780                if type(md.hydrology is 'hydrologydc'):
    780781                        md.hydrology.spcsediment_head=project2d(md,md.hydrology.spcsediment_head,1)
    781                         md.hydrology.mask_eplactive_node=project2d(md,md.hydrology.mask_eplactive_node,1)
    782782                        md.hydrology.sediment_transmitivity=project2d(md,md.hydrology.sediment_transmitivity,1)
    783783                        md.hydrology.basal_moulin_input=project2d(md,md.hydrology.basal_moulin_input,1)
     784                        md.hydrology.mask_thawed_node=project2d(md,md.hydrology.mask_thawed_node,1)
    784785                        if md.hydrology.isefficientlayer == 1:
     786                                md.hydrology.mask_eplactive_node=project2d(md,md.hydrology.mask_eplactive_node,1)
    785787                                md.hydrology.spcepl_head=project2d(md,md.hydrology.spcepl_head,1)
    786788
     
    793795                md.masstransport.spcthickness=project2d(md,md.masstransport.spcthickness,md.mesh.numberoflayers)
    794796                md.thermal.spctemperature=project2d(md,md.thermal.spctemperature,md.mesh.numberoflayers-1)
    795                 if not np.isnan(md.damage.spcdamage).all(): 
     797                if not np.isnan(md.damage.spcdamage).all():
    796798                        md.damage.spcdamage=project2d(md,md.damage.spcdamage,md.mesh.numberoflayers-1)
    797799
     
    799801                md.materials.rheology_B=DepthAverage(md,md.materials.rheology_B)
    800802                md.materials.rheology_n=project2d(md,md.materials.rheology_n,1)
    801                
    802                 #damage: 
     803
     804                #damage:
    803805                if md.damage.isdamage:
    804806                        md.damage.D=DepthAverage(md,md.damage.D)
    805807
    806808                #special for thermal modeling:
    807                 md.basalforcings.groundedice_melting_rate=project2d(md,md.basalforcings.groundedice_melting_rate,1) 
    808                 md.basalforcings.floatingice_melting_rate=project2d(md,md.basalforcings.floatingice_melting_rate,1) 
     809                md.basalforcings.groundedice_melting_rate=project2d(md,md.basalforcings.groundedice_melting_rate,1)
     810                md.basalforcings.floatingice_melting_rate=project2d(md,md.basalforcings.floatingice_melting_rate,1)
    809811                md.basalforcings.geothermalflux=project2d(md,md.basalforcings.geothermalflux,1) #bedrock only gets geothermal flux
    810812
     
    848850                mesh.numberofelements=md.mesh.numberofelements2d
    849851                mesh.elements=md.mesh.elements2d
    850                 if not np.isnan(md.mesh.vertexonboundary).all(): 
     852                if not np.isnan(md.mesh.vertexonboundary).all():
    851853                        mesh.vertexonboundary=project2d(md,md.mesh.vertexonboundary,1)
    852                 if not np.isnan(md.mesh.elementconnectivity).all(): 
     854                if not np.isnan(md.mesh.elementconnectivity).all():
    853855                        mesh.elementconnectivity=project2d(md,md.mesh.elementconnectivity,1)
    854856                if isinstance(md.mesh.lat,np.ndarray):
    855                         if md.mesh.lat.size==md.mesh.numberofvertices: 
    856                                 mesh.lat=project2d(md,md.mesh.lat,1) 
     857                        if md.mesh.lat.size==md.mesh.numberofvertices:
     858                                mesh.lat=project2d(md,md.mesh.lat,1)
    857859                if isinstance(md.mesh.long,np.ndarray):
    858                         if md.mesh.long.size==md.mesh.numberofvertices: 
    859                                 md.mesh.long=project2d(md,md.mesh.long,1) 
     860                        if md.mesh.long.size==md.mesh.numberofvertices:
     861                                md.mesh.long=project2d(md,md.mesh.long,1)
    860862                mesh.epsg=md.mesh.epsg
    861863                if isinstance(md.mesh.scale_factor,np.ndarray):
    862                         if md.mesh.scale_factor.size==md.mesh.numberofvertices: 
    863                                 md.mesh.scale_factor=project2d(md,md.mesh.scale_factor,1) 
     864                        if md.mesh.scale_factor.size==md.mesh.numberofvertices:
     865                                md.mesh.scale_factor=project2d(md,md.mesh.scale_factor,1)
    864866                md.mesh=mesh
    865867                md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices)[0]
Note: See TracChangeset for help on using the changeset viewer.