parameters: (self, original_field_names)
return_statement: return self._replace_name_case(field_names, original_field_names)
docstring: Return field names sorted in a SIERRA-friendly manner.
  
          In order for SIERRA to recognize vectors, tensors, and element fields
          with multiple integration points, fields must be sorted in a specific
          order.  This function provides that sort order.
  
          As fields within exomerge are stored in a set, exomerge has no internal
          or natural field order.  This routine is only necessary for writing to
          ExodusII files.
docstring_summary: Return field names sorted in a SIERRA-friendly manner.
docstring_tokens: Return field names sorted in a SIERRA - friendly manner .
function: def _sort_field_names(self, original_field_names):
          """
          Return field names sorted in a SIERRA-friendly manner.
  
          In order for SIERRA to recognize vectors, tensors, and element fields
          with multiple integration points, fields must be sorted in a specific
          order.  This function provides that sort order.
  
          As fields within exomerge are stored in a set, exomerge has no internal
          or natural field order.  This routine is only necessary for writing to
          ExodusII files.
  
          """
          field_names = [x.lower() for x in original_field_names]
          # Look through all fields to find multi-component fields and store
          # these as tuples of the following form:
          # ('base_name', 'component', integration_points)
          multicomponent_fields = set()
          for name in field_names:
              # see if it has an integration point
              if re.match('.*_[0-9]+$', name):
                  (name, integration_point) = name.rsplit('_', 1)
                  integration_point = int(integration_point)
              else:
                  integration_point = None
              # see if it possibly has a component
              if re.match('.*_.+$', name):
                  component = name.rsplit('_', 1)[1]
                  if component in self.ALL_MULTI_COMPONENT_FIELD_SUBSCRIPTS:
                      name = name.rsplit('_', 1)[0]
                      multicomponent_fields.add(
                          (name, component, integration_point))
          # now sort multi-component fields
          base_names = set(x for x, _, _ in multicomponent_fields)
          sorted_field_names = dict()
          field_names = set(field_names)
          for base_name in base_names:
              # find all components of this form
              components = set(x for name, x, _ in multicomponent_fields
                               if name == base_name)
              # find max integration point value
              integration_points = set(x for name, _, x in multicomponent_fields
                                       if name == base_name and x is not None)
              if integration_points:
                  integration_point_count = max(
                      x for name, _, x in multicomponent_fields
                      if name == base_name and x is not None)
              else:
                  integration_point_count = None
  
              # see if the components match the form of something
              matching_form = None
              for form, included_components in (list(
                      self.MULTI_COMPONENT_FIELD_SUBSCRIPTS.items())):
                  if set(included_components) == components:
                      matching_form = form
              if not matching_form:
                  continue
              # see if all components and integration points are present
              mid = [
                  '_' + x
                  for x in self.MULTI_COMPONENT_FIELD_SUBSCRIPTS[matching_form]
              ]
              if integration_point_count is None:
                  last = ['']
              else:
                  last = [
                      '_' + str(x + 1) for x in range(integration_point_count)
                  ]
              all_names = [base_name + m + l for l in last for m in mid]
              if set(all_names).issubset(field_names):
                  sorted_field_names[all_names[0]] = all_names
                  field_names = field_names - set(all_names)
          # sort field names which are not part of multicomponent fields
          field_names = sorted(field_names)
          # for each list of field names, find place to splice into list
          place_to_insert = dict()
          for name in list(sorted_field_names.keys()):
              place = bisect.bisect_left(field_names, name)
              if place not in place_to_insert:
                  place_to_insert[place] = [name]
              else:
                  place_to_insert[place].append(name)
          # splice them in
          for place in sorted(list(place_to_insert.keys()), reverse=True):
              for name in place_to_insert[place]:
                  field_names[place:place] = sorted_field_names[name]
          return self._replace_name_case(field_names, original_field_names)
function_tokens: def _sort_field_names ( self , original_field_names ) : field_names = [ x . lower ( ) for x in original_field_names ] # Look through all fields to find multi-component fields and store # these as tuples of the following form: # ('base_name', 'component', integration_points) multicomponent_fields = set ( ) for name in field_names : # see if it has an integration point if re . match ( '.*_[0-9]+$' , name ) : ( name , integration_point ) = name . rsplit ( '_' , 1 ) integration_point = int ( integration_point ) else : integration_point = None # see if it possibly has a component if re . match ( '.*_.+$' , name ) : component = name . rsplit ( '_' , 1 ) [ 1 ] if component in self . ALL_MULTI_COMPONENT_FIELD_SUBSCRIPTS : name = name . rsplit ( '_' , 1 ) [ 0 ] multicomponent_fields . add ( ( name , component , integration_point ) ) # now sort multi-component fields base_names = set ( x for x , _ , _ in multicomponent_fields ) sorted_field_names = dict ( ) field_names = set ( field_names ) for base_name in base_names : # find all components of this form components = set ( x for name , x , _ in multicomponent_fields if name == base_name ) # find max integration point value integration_points = set ( x for name , _ , x in multicomponent_fields if name == base_name and x is not None ) if integration_points : integration_point_count = max ( x for name , _ , x in multicomponent_fields if name == base_name and x is not None ) else : integration_point_count = None # see if the components match the form of something matching_form = None for form , included_components in ( list ( self . MULTI_COMPONENT_FIELD_SUBSCRIPTS . items ( ) ) ) : if set ( included_components ) == components : matching_form = form if not matching_form : continue # see if all components and integration points are present mid = [ '_' + x for x in self . MULTI_COMPONENT_FIELD_SUBSCRIPTS [ matching_form ] ] if integration_point_count is None : last = [ '' ] else : last = [ '_' + str ( x + 1 ) for x in range ( integration_point_count ) ] all_names = [ base_name + m + l for l in last for m in mid ] if set ( all_names ) . issubset ( field_names ) : sorted_field_names [ all_names [ 0 ] ] = all_names field_names = field_names - set ( all_names ) # sort field names which are not part of multicomponent fields field_names = sorted ( field_names ) # for each list of field names, find place to splice into list place_to_insert = dict ( ) for name in list ( sorted_field_names . keys ( ) ) : place = bisect . bisect_left ( field_names , name ) if place not in place_to_insert : place_to_insert [ place ] = [ name ] else : place_to_insert [ place ] . append ( name ) # splice them in for place in sorted ( list ( place_to_insert . keys ( ) ) , reverse = True ) : for name in place_to_insert [ place ] : field_names [ place : place ] = sorted_field_names [ name ] return self . _replace_name_case ( field_names , original_field_names )