File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -432,3 +432,29 @@ def copy_from_nx_graph(G_nx):
432432
433433
434434 return G
435+
436+
437+ def nxgraph_attribute_to_dolfin (G , attr ):
438+ '''
439+ Make a dolfin function representing edge attributes of a networkx graph
440+
441+ Args:
442+ G (nx.Graph): graph representing the network
443+ attr (str): attribute to be represented
444+
445+ Returns:
446+ func (dolfin.Function): a DG function representing the attribute
447+ '''
448+
449+ mesh0 , foo = G .get_mesh (0 )
450+ DG_coarse = FunctionSpace (mesh0 , 'DG' , 0 ) # trick: Interpolate the radius from the coarse mesh to the fine mesh
451+
452+ attr_dict = nx .get_edge_attributes (G , attr )
453+ func = Function (DG_coarse )
454+ func .vector ()[:] = np .asarray (list (attr_dict .values ()))
455+ func .set_allow_extrapolation (True )
456+
457+ DG = FunctionSpace (G .mesh , 'DG' , 1 )
458+ func = interpolate (func , DG )
459+
460+ return func
You can’t perform that action at this time.
0 commit comments