def WriteHalos(halos, filename):
  """
  Write a Fluidity .halo file
  """
    
  xmlfile = xml.dom.minidom.Document()
  
  halosRootEle = xmlfile.createElement("halos")
  halosRootEle.setAttribute("process", str(halos.GetProcess()))
  halosRootEle.setAttribute("nprocs", str(halos.GetNProcesses()))
  xmlfile.appendChild(halosRootEle)
  
  halos = halos.LevelHaloDict()
  for level in halos.keys():
    halo = halos[level]
  
    haloEle = xmlfile.createElement("halo")
    haloEle.setAttribute("level", str(level))
    haloEle.setAttribute("n_private_nodes", str(halo.GetNOwnedNodes()))
    halosRootEle.appendChild(haloEle)
    
    for i, process in enumerate(range(halo.GetNProcesses())):
      haloDataEle = xmlfile.createElement("halo_data")
      haloDataEle.setAttribute("process", str(i))
      haloEle.appendChild(haloDataEle)
      
      sendEle = xmlfile.createElement("send")
      haloDataEle.appendChild(sendEle)
      
      if level > 0:
        sendText = xmlfile.createTextNode(utils.FormLine(utils.OffsetList(utils.ExpandList(halo.GetSends(process = i)), 1), delimiter = " ", newline = False))
      else:
        sendText = xmlfile.createTextNode(utils.FormLine(utils.ExpandList(halo.GetSends(process = i)), delimiter = " ", newline = False))
      sendEle.appendChild(sendText)
      
      receiveEle = xmlfile.createElement("receive")
      haloDataEle.appendChild(receiveEle)
      
      if level > 0:
        receiveText = xmlfile.createTextNode(utils.FormLine(utils.OffsetList(utils.ExpandList(halo.GetReceives(process = i)), 1), delimiter = " ", newline = False))
      else:
        receiveText = xmlfile.createTextNode(utils.FormLine(utils.ExpandList(halo.GetReceives(process = i)), delimiter = " ", newline = False))
      receiveEle.appendChild(receiveText)
  
  handle = open(filename, "w")
  if XmlExtSupport():
    xml.dom.ext.PrettyPrint(xmlfile, handle)
  else:
    xmlfile.writexml(handle)
  handle.flush()
  handle.close()
  
  return
 def TrailingReceivesOrdered(self):
   """
   Return whether this halo is trailing receive ordered
   """
   
   # If we do not have a number of owned nodes, we can't be usefully trailing
   # receive ordered
   if not self.HasNOwnedNodes():
     return False
     
   nOwnedNodes = self.GetNOwnedNodes()
   
   # All sends must be owned
   for sends in self._sends:
     if len(sends) > 0 and max(sends) >= nOwnedNodes:
       return False
   # All receives must be non-owned
   for receives in self._receives:
     if len(receives) > 0 and min(receives) < nOwnedNodes:
       return False
   # All receives must be unique and consecutive
   allReceives = utils.ExpandList(self._receives)
   allReceives.sort()
   if not allReceives == range(nOwnedNodes, nOwnedNodes + len(allReceives)):
     return False
   
   return True
Exemple #3
0
def XyPhiToVtu(x, y, phi, fieldName="Scalar"):
    """
  Generate a 2D vtu containing the supplied structured field
  """

    result = XyToVtu(x, y)

    lphi = numpy.array(utils.ExpandList(utils.TransposeListList(phi)))
    lphi.shape = (len(x) * len(y), 1)
    result.AddScalarField(fieldName, lphi)

    return result
 def GetData(self):
   return utils.ExpandList(self._data)