Changeset 25502


Ignore:
Timestamp:
08/31/20 19:41:23 (5 years ago)
Author:
jdquinn
Message:

BUG: Corrected frictionshakti failure (constructor works more like MATLAB now; added structtobj.py); prefer function 'fieldnames' to 'fields' in MATLAB

Location:
issm/trunk-jpl
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/frictionshakti.m

    r25499 r25502  
    99        end
    1010        methods
    11                 function self = extrude(self,md) % {{{
    12                         self.coefficient=project3d(md,'vector',self.coefficient,'type','node','layer',1);
    13                 end % }}}
    1411                function self = frictionshakti(varargin) % {{{
    1512                        switch nargin
     
    2421                function self = setdefaultparameters(self) % {{{
    2522
     23                end % }}}
     24                function self = extrude(self,md) % {{{
     25                        self.coefficient=project3d(md,'vector',self.coefficient,'type','node','layer',1);
    2626                end % }}}
    2727                function md = checkconsistency(self,md,solution,analyses) % {{{
  • issm/trunk-jpl/src/m/classes/frictionshakti.py

    r25499 r25502  
    44from fielddisplay import fielddisplay
    55from project3d import project3d
     6from structtoobj import structtoobj
    67from WriteData import WriteData
    78
     
    1415    """
    1516
    16     def __init__(self, md):  # {{{
     17    def __init__(self, *args):  # {{{
    1718        self.coefficient = np.nan
    18         #set defaults
    19         self.setdefaultparameters()
     19       
     20        nargs = len(args)
     21        if nargs == 0:
     22            self.setdefaultparameters()
     23        elif nargs == 1:
     24            self = structtoobj(self, args[0])
    2025    #}}}
    2126
     
    4247
    4348        md = checkfield(md, 'fieldname', 'friction.coefficient', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
     49
    4450        return md
    4551    # }}}
  • issm/trunk-jpl/src/m/classes/model.m

    r25499 r25502  
    424424                                if isobject(md.outputdefinition.definitions{i})
    425425                                        %get subfields
    426                                         solutionsubfields=fields(md.outputdefinition.definitions{i});
     426                                        solutionsubfields=fieldnames(md.outputdefinition.definitions{i});
    427427                                        for j=1:length(solutionsubfields),
    428428                                                field=md.outputdefinition.definitions{i}.(solutionsubfields{j});
     
    548548
    549549                        %loop over model fields
    550                         model_fields=fields(md1);
     550                        model_fields=fieldnames(md1);
    551551                        for i=1:length(model_fields),
    552552                                %get field
     
    554554                                fieldsize=size(field);
    555555                                if isobject(field), %recursive call
    556                                         object_fields=fields(md1.(model_fields{i}));
     556                                        object_fields=fieldnames(md1.(model_fields{i}));
    557557                                        for j=1:length(object_fields),
    558558                                                %get field
     
    721721                        if isstruct(md1.results),
    722722                                md2.results=struct();
    723                                 solutionfields=fields(md1.results);
     723                                solutionfields=fieldnames(md1.results);
    724724                                for i=1:length(solutionfields),
    725725                                        if isstruct(md1.results.(solutionfields{i}))
     
    728728                                                for p=1:length(md1.results.(solutionfields{i}))
    729729                                                    current = md1.results.(solutionfields{i})(p);
    730                                                     solutionsubfields=fields(current);
     730                                                    solutionsubfields=fieldnames(current);
    731731                                                    for j=1:length(solutionsubfields),
    732732                                                        field=md1.results.(solutionfields{i})(p).(solutionsubfields{j});
     
    757757                                if isobject(md1.outputdefinition.definitions{i})
    758758                                        %get subfields
    759                                         solutionsubfields=fields(md1.outputdefinition.definitions{i});
     759                                        solutionsubfields=fieldnames(md1.outputdefinition.definitions{i});
    760760                                        for j=1:length(solutionsubfields),
    761761                                                field=md1.outputdefinition.definitions{i}.(solutionsubfields{j});
  • issm/trunk-jpl/src/m/classes/sealevelmodel.m

    r25499 r25502  
    106106                end % }}}
    107107                function self=mergeresults(self) % {{{
    108                         champs=fields(self.icecaps{1}.results.TransientSolution);
     108                        champs=fieldnames(self.icecaps{1}.results.TransientSolution);
    109109                        for i=1:length(self.mergedcaps)/2,
    110110                                md=self.mergedcaps{2*(i-1)+1}; trans=self.mergedcaps{2*(i-1)+2};
  • issm/trunk-jpl/src/m/consistency/comparemodels.m

    r20964 r25502  
    22
    33        %loop over model fields
    4         model_fields=fields(md1);
     4        model_fields=fieldnames(md1);
    55        for i=1:length(model_fields),
    66                field1=md1.(model_fields{i});
     
    1111                                continue;
    1212                        end
    13                         object_fields=fields(md1.(model_fields{i}));
     13                        object_fields=fieldnames(md1.(model_fields{i}));
    1414                        for j=1:length(object_fields),
    1515                                field1=md1.(model_fields{i}).(object_fields{j});
  • issm/trunk-jpl/src/m/contrib/defleurian/netCDF/export_netCDF.m

    r25458 r25502  
    5454                groupID=netcdf.defGrp(ncid,groups{i});
    5555                %In each group gather the fields of the class
    56                 groupfields=fields(md.(groups{i}));
     56                groupfields=fieldnames(md.(groups{i}));
    5757                for j=1:length(groupfields),
    5858                        Var=md.(groups{i}).(groupfields{j});
     
    8787                                                listgroupID=netcdf.defGrp(subgroupID,lname);
    8888                                                netcdf.putAtt(listgroupID,netcdf.getConstant('NC_GLOBAL'),'classtype',class(Var{l}));
    89                                                 subfields=fields(Var{l});
     89                                                subfields=fieldnames(Var{l});
    9090                                                for m=1:length(subfields)
    9191                                                        if ~strcmp(subfields{m},'outlog')
     
    121121                                                listgroupID=netcdf.defGrp(subgroupID,lname);
    122122                                                netcdf.putAtt(listgroupID,netcdf.getConstant('NC_GLOBAL'),'classtype',classtype);
    123                                                 subfields=fields(Var(l));
     123                                                subfields=fieldnames(Var(l));
    124124                                                for m=1:length(subfields)
    125125                                                        if ~strcmp(subfields{m},'outlog')
     
    135135                                        end
    136136                                        netcdf.putAtt(subgroupID,netcdf.getConstant('NC_GLOBAL'),'classtype',classtype);
    137                                         subfields=fields(Var);
     137                                        subfields=fieldnames(Var);
    138138                                        for m=1:length(subfields)
    139139                                                if ~strcmp(subfields{m},'outlog')
     
    197197        elseif isa(Var,'struct'),
    198198                %Start by getting the structure fields and size
    199                 locfields=fields(Var);
     199                locfields=fieldnames(Var);
    200200                [dims,DimSize,DimValue]=GetDims(ncid,Var,DimSize,DimValue);
    201201                varid = netcdf.defVar(groupID,field,'NC_CHAR',dims);
     
    244244                varsize=size(Var');
    245245        elseif isa(Var,'struct')
    246                 varsize=length(fields(Var));
     246                varsize=length(fieldnames(Var));
    247247        else
    248248                varsize=size(Var);
  • issm/trunk-jpl/src/m/contrib/larour/mdanalysis.m

    r24880 r25502  
    531531        mv=md.mask;
    532532end
    533 strings=fields(mv);
     533strings=fieldnames(mv);
    534534strings={'all',strings{:}};
    535535set(hObject,'String',strings);
     
    693693if issealevel,
    694694        if isearth,
    695                 resultfields=fields(md.earth.results);
     695                resultfields=fieldnames(md.earth.results);
    696696        else
    697                 resultfields=fields(md.icecaps{1}.results);
     697                resultfields=fieldnames(md.icecaps{1}.results);
    698698        end
    699699else
    700         resultfields=fields(md.results);
     700        resultfields=fieldnames(md.results);
    701701end
    702702if isempty(resultfields),
     
    854854end
    855855fieldHandle=findobj('Tag', 'Masque');
    856 strings=fields(mv);
     856strings=fieldnames(mv);
    857857strings={'all',strings{:}};
    858858set(fieldHandle,'String',strings);
  • issm/trunk-jpl/src/m/miscellaneous/fielddisplay.m

    r21989 r25502  
    7575function struct_display(offset,name,field,comment) % {{{
    7676
    77         if ~isempty(fields(field))
     77        if ~isempty(fieldnames(field))
    7878                displayunit(offset,name,'(structure)',comment),
    7979                offset=[offset '   '];
    8080
    81                 structure_fields=fields(field);
     81                structure_fields=fieldnames(field);
    8282
    8383                for i=1:length(structure_fields),
  • issm/trunk-jpl/src/m/miscellaneous/structtoobj.m

    r8952 r25502  
    33
    44        %Get object and structure fields
    5         structfields=fields(S);
     5        structfields=fieldnames(S);
    66        objprops    =properties(class(obj));
    77
    88        %recover object properties
    99        for i=1:length(structfields),
    10                 fieldname =structfields{i};
     10                fieldname=structfields{i};
    1111                if ismember(fieldname,objprops),
    1212                        fieldvalue=getfield(S,fieldname);
  • issm/trunk-jpl/src/m/plot/plot_transient_movie.m

    r25193 r25502  
    1414        else
    1515                disp('List of available fields:');
    16                 F=fields(md.results.TransientSolution(1));
     16                F=fieldnames(md.results.TransientSolution(1));
    1717                num = [];
    1818                for i=1:numel(F),
  • issm/trunk-jpl/src/m/plot/processdata.m

    r23912 r25502  
    2020if isstruct(data),
    2121        disp('data provided is a struct with the following fields:');
    22         F=fields(data);
     22        F=fieldnames(data);
    2323        for i=1:numel(F),
    2424                disp(['   ' num2str(i) ': ' F{i} ]);
  • issm/trunk-jpl/src/m/regional/regionaltransient2d.m

    r16470 r25502  
    4343
    4444        %loop over model fields
    45         model_fields=fields(md1);
     45        model_fields=fieldnames(md1);
    4646        for i=1:length(model_fields),
    4747
     
    5252                %copy field, interpolated to new mesh
    5353                if isobject(field), %recursive call
    54                         object_fields=fields(md1.(model_fields{i}));
     54                        object_fields=fieldnames(md1.(model_fields{i}));
    5555                        fname=['(model_fields{i}).(object_fields{j})'];
    5656                else
  • issm/trunk-jpl/src/m/solve/convert2str.m

    r17721 r25502  
    109109function str = struct_display(field) % {{{
    110110
    111         if ~isempty(fields(field))
     111        if ~isempty(fieldnames(field))
    112112                displayunit('(structure)'),
    113113
    114                 structure_fields=fields(field);
     114                structure_fields=fieldnames(field);
    115115
    116116                for i=1:length(structure_fields),
  • issm/trunk-jpl/test/NightlyRun/test350.m

    r23024 r25502  
    1010md.cluster=generic('name',oshostname(),'np',2);
    1111
    12 %Use hydroogy coupled friciton law
     12%Use hydrology coupled friction law
    1313md.friction=frictionshakti(md.friction);
    1414
  • issm/trunk-jpl/test/NightlyRun/test350.py

    r25023 r25502  
    2222md.cluster = generic('name', gethostname(), 'np', 2)
    2323
    24 #Use hydroogy coupled friciton law
    25 md.friction = frictionshakti(md)
     24#Use hydrology coupled friction law
     25md.friction = frictionshakti(md.friction)
    2626
    2727#Change hydrology class to Shakti' model
Note: See TracChangeset for help on using the changeset viewer.