Changeset 26572


Ignore:
Timestamp:
11/09/21 07:04:19 (3 years ago)
Author:
bdef
Message:

NEW:dealing with export on sparse stepping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/contrib/defleurian/paraview/exportVTK.py

    r25483 r26572  
    6767        for solution in solnames:
    6868            #looking for multiple time steps
    69             if (np.size(res_struct.__dict__[solution]) > num_of_timesteps):
    70                 num_of_timesteps = np.size(res_struct.__dict__[solution])
    71                 num_of_timesteps = int(num_of_timesteps)
    72                 if 'Surface' in dict.keys(res_struct.__dict__[solution][0].__dict__):
    73                     moving_mesh = True
     69            try:
     70                if len(res_struct.__dict__[solution]) > num_of_timesteps:
     71                    num_of_timesteps = len(res_struct.__dict__[solution])
     72                    num_of_timesteps = int(num_of_timesteps)
     73                    if 'Surface' in dict.keys(res_struct.__dict__[solution][0].__dict__):
     74                        moving_mesh = True
     75            except TypeError:
     76                continue
    7477    else:
    7578        num_of_timesteps = 1
     
    9295        raise BadDimension('exportVTK does not support your element type')
    9396
     97    #only keep the envelope and not the bulk of the results.
    9498    if enveloppe:
    9599        if dim == 3:
     
    252256            for sol in solnames:
    253257                treated_res = []
    254     #dealing with results on different timesteps
    255                 if(np.size(res_struct.__dict__[sol]) > timestep):
    256                     timestep = step
    257                 else:
    258                     timestep = np.size(res_struct.__dict__[sol])
    259 
    260     #getting the  fields in the solution
    261                 if(type(res_struct.__dict__[sol]) == list):
     258                #dealing with results on different timesteps
     259                try:
     260                    if(len(res_struct.__dict__[sol]) > timestep):
     261                        timestep = step
     262                    else:
     263                        timestep = np.size(res_struct.__dict__[sol])
     264                except TypeError:
     265                    #result as no len() so no timesteps
     266                    timestep = 1
     267
     268                #getting the  fields in the solution
     269                if(type(res_struct.__dict__[sol]).__name__ == 'solution'):
    262270                    spe_res_struct = res_struct.__dict__[sol].__getitem__(timestep)
    263271                    fieldnames = dict.keys(spe_res_struct.__dict__)
    264                 else:
     272                elif(type(res_struct.__dict__[sol]).__name__ == 'solutionstep'):
    265273                    spe_res_struct = res_struct.__dict__[sol]
    266274                    fieldnames = dict.keys(spe_res_struct.__dict__)
    267 
    268     #Sorting scalars, vectors and tensors
     275                elif(type(res_struct.__dict__[sol]).__name__ == 'results'):  #this is a result without steps
     276                    spe_res_struct = res_struct.__dict__[sol]
     277                    fieldnames = dict.keys(spe_res_struct.__dict__)
     278                else:
     279                    print("WARNING, solution type '{}' is not recognise, exported results might be wrong".format(type(res_struct.__dict__[sol])))
     280                    spe_res_struct = res_struct.__dict__[sol]
     281                    fieldnames = dict.keys(spe_res_struct.__dict__)
     282
     283                #Sorting scalars, vectors and tensors
    269284                tensors = [field for field in fieldnames if field[-2:] in ['xx', 'yy', 'xy', 'zz', 'xz', 'yz']]
    270285                non_tensor = [field for field in fieldnames if field not in tensors]
    271286                vectors = [field for field in non_tensor if field[-1] in ['x', 'y', 'z'] and field[-4:] not in ['Flux']]
    272287
    273     #check which field is a real result and print
     288                #check which field is a real result and print
    274289                for field in fieldnames:
     290                    print("Treating {}".format(field))
    275291                    if field in treated_res:
     292                        print("{} is already done".format(field))
    276293                        continue
    277294                    elif field in vectors:
     295                        print("{} is a vector".format(field))
    278296                        try:
    279297                            Vxstruct = np.squeeze(spe_res_struct.__dict__[field[:-1] + 'x'])
     
    299317
    300318                    elif field in tensors:
     319                        print("{} is a tensor".format(field))
    301320                        try:
    302321                            Txxstruct = np.squeeze(spe_res_struct.__dict__[field[:-2] + 'xx'])
     
    346365                        else:
    347366                            print("format for field {}.{} is not suported, field is skipped".format(sol, field))
    348                             continue
    349367    # }}}
    350368    # loop on arguments, if something other than result is asked, do it now {{{
Note: See TracChangeset for help on using the changeset viewer.