Skip to content

Commit

Permalink
mulgrids.py: added nodes_in_columns() and column_boundary_nodes() met…
Browse files Browse the repository at this point in the history
…hods
  • Loading branch information
acroucher committed Mar 29, 2012
1 parent 1a5b78f commit da62709
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
22 changes: 22 additions & 0 deletions doc/mulgrids.tex
Expand Up @@ -118,6 +118,7 @@ \subsection{Methods}
\texttt{block\_name} & string & name of block at given layer and column\\
\texttt{block\_name\_containing\_point} & string & name of block containing specified point\\
\texttt{check} & Boolean & checks grid for errors (and optionally fixes them)\\
\texttt{column\_boundary\_nodes} & list & nodes around the outer boundary of a group of columns\\
\texttt{column\_containing\_point} & column & column containing specified horizontal point\\
\texttt{column\_mapping} & dictionary & mapping from the columns of another \texttt{mulgrid} object\\
\texttt{column\_name} & string & column name of a block name\\
Expand All @@ -139,6 +140,7 @@ \subsection{Methods}
\texttt{layer\_plot} & -- & plots a variable over a layer of the grid\\
\texttt{line\_values} & tuple & values of a variable along an arbitrary line through the grid\\
\texttt{line\_plot} & -- & plots a variable along an arbitrary line through the grid\\
\texttt{nodes\_in\_columns} & list & nodes in a specified list of columns\\
\texttt{nodes\_in\_polygon} & list & nodes inside a specified polygon (or rectangle)\\
\texttt{node\_nearest\_to} & \texttt{node} & node nearest to a specified point\\
\texttt{optimize} & -- & adjusts node positions to optimize grid quality\\
Expand Down Expand Up @@ -237,6 +239,16 @@ \subsubsection{\texttt{check(\emph{fix}=False,\emph{silent}=False)}}
Whether to print out feedback or not.
\end{itemize}

\subsubsection{\texttt{column\_boundary\_nodes(\emph{columns})}}

Returns the nodes around the outer boundary of a list of columns. The list is ordered, in a counter-clockwise direction.

\textbf{Parameters:}
\begin{itemize}
\item \textbf{columns}: list\\
The list of columns for which the boundary is required.
\end{itemize}

\subsubsection{\texttt{column\_containing\_point(\emph{pos}, \emph{columns}=None, \emph{guess}=None, \emph{bounds}=None,\\
\emph{qtree}=None)}}

Expand Down Expand Up @@ -541,6 +553,16 @@ \subsubsection{\texttt{line\_plot(\emph{start}=None, \emph{end}=None, \emph{vari

plots the variable \texttt{t} along a line from (0,0,500) to (1000,0,500) through the grid, with the values as Temperature ($^{\circ}$C).

\subsubsection{\texttt{nodes\_in\_columns(\emph{columns})}}

Returns a list of all nodes in a specified list of columns.

\textbf{Parameters:}
\begin{itemize}
\item \textbf{columns}: list (of \texttt{column})\\
List of columns in which to find nodes.
\end{itemize}

\subsubsection{\texttt{nodes\_in\_polygon(\emph{polygon})}}

Returns a list of all nodes inside the specified polygon or rectangle.
Expand Down
26 changes: 17 additions & 9 deletions mulgrids.py
Expand Up @@ -1769,20 +1769,29 @@ def connection_with_nodes(self,nodes):
if all([node in con.node for node in nodes]): return con
return None

def get_boundary_nodes(self):
"""Returns an ordered list of the nodes on the outer boundary of the grid."""
def nodes_in_columns(self,columns):
"""Returns a list of all nodes in the specified columns."""
nodes=set([])
for col in columns: nodes=nodes | set(col.node)
return list(nodes)

def column_boundary_nodes(self,columns):
"""Returns an ordered list of the nodes on the outer boundary of the group of specified columns."""
nodes=self.nodes_in_columns(columns)
def next_bdy_node(n):
for col in n.column:
for col in [c for c in n.column if c in columns]:
i=col.node.index(n)
n2=col.node[(i+1)%col.num_nodes]
con=self.connection_with_nodes([n,n2])
if not con: return n2
else:
if not all([(c in columns) for c in con.column]): return n2
return None
# look for a starting node along the left-hand edge of the grid (this avoids
# look for a starting node along the left-hand edge of the selection (this avoids
# picking up any interior boundaries):
startnode=None
xmin=self.bounds[0][0]
leftnodes=[node for node in self.nodelist if node.pos[0]==xmin]
xmin=bounds_of_points([node.pos for node in nodes])[0][0]
leftnodes=[node for node in nodes if node.pos[0]==xmin]
for node in leftnodes:
nextnode=next_bdy_node(node)
if nextnode:
Expand All @@ -1798,6 +1807,7 @@ def next_bdy_node(n):
back=node.name==startnode.name
return bdynodes
else: return []
def get_boundary_nodes(self): return self.column_boundary_nodes(self.columnlist)
boundary_nodes=property(get_boundary_nodes)

def get_boundary_polygon(self):
Expand Down Expand Up @@ -2027,9 +2037,7 @@ def fit_surface(self,data,alpha=0.1,beta=0.1,columns=[],min_columns=[],grid_boun
if min_columns<>[]:
if not isinstance(min_columns[0],str): min_columns=[col.name for col in min_columns]
if all([col.num_nodes in [3,4] for col in columns]):
nodes=set([])
for col in columns: nodes=nodes | set(col.node)
nodes=list(nodes)
nodes=self.nodes_in_columns(columns)
node_index=dict([(node.name,i) for i,node in enumerate(nodes)])
num_nodes=len(nodes)
bbox=bounds_of_points([node.pos for node in nodes])
Expand Down

0 comments on commit da62709

Please sign in to comment.