← Back to team overview

ufl team mailing list archive

Re: [Branch ~ufl-core/ufl/main] Rev 892: Add function sort_elements for sorting elements backwards with nested sub

 

On Monday 25 January 2010 07:13:14 Anders Logg wrote:
> On Mon, Jan 25, 2010 at 03:09:06PM +0000, Garth N. Wells wrote:
> > Anders Logg wrote:
> > > On Mon, Jan 25, 2010 at 03:19:36PM +0100, Marie Rognes wrote:
> > >> noreply@xxxxxxxxxxxxx wrote:
> > >>> ------------------------------------------------------------
> > >>> revno: 892
> > >>> committer: Anders Logg <logg@xxxxxxxxx>
> > >>> branch nick: ufl-main
> > >>> timestamp: Mon 2010-01-25 13:26:37 +0100
> > >>> message:
> > >>>  Add function sort_elements for sorting elements backwards with
> > >>> nested sub elements first. Using pygraph library for sorting directed
> > >>> acyclic graph. modified:
> > >>>  ufl/algorithms/__init__.py
> > >>>  ufl/algorithms/analysis.py
> > >>
> > >> Is pygraph super-standard?
> > >
> > > I don't know but it's in Ubuntu... :-)
> > >
> > > It was the simplest way I could find to store a list of elements based
> > > on their dependencies to sub elements.
> > >
> > > If it's a problem, we could implement the sorting ourselves.
> >
> > If it's simple, I would suggest implementing it ourselves to avoid a
> > dependency since UFL didn't have any dependencies beyond the standard
> > Python modules. It can wait until until the UFL/FFC change are complete
> > though.
> 
> You mean like tomorrow?
> 
> If anyone has a simple piece of code to do the following, let me know:
> 
>   # Create directed graph
>   g = digraph()
> 
>   # Add nodes (elements)
>   for element in elements:
>       g.add_node(element)
> 
>   # Add edges (dependencies)
>   for element in elements:
>       for sub_element in element.sub_elements():
>           g.add_edge(element, sub_element)
> 
>   # Sort graph
>   sorted_elements = topological_sorting(g)

I am not sure what you want to accomplish but I suppose:

   collection = []

   for element in elements:
       for sub_element in element.sub_elements():
           collection.append((element, sub_element))

   collection.sort()

would not do it? Then you would get a list with the "lowest" elements first 
followed with the lowest sub_elements.

Johan

> --
> Anders
> 



References