mathcomp.gridgeom
Class Grid

java.lang.Object
  extended by mathcomp.gridgeom.Grid

public class Grid
extends java.lang.Object

A Grid knows its nodes, edges, and elements. The information on the neighbors is stored in the edges.

Author:
pht

Constructor Summary
Grid(java.util.Set nodes, java.util.Set edges, java.util.Set elements)
          Creates a new Grid from the given sets of nodes, edges and elements.
 
Method Summary
 Triangle addNewTriangle(Node[] nodes)
          Adds a new Triangle based on nodes.
 java.util.Map calcBoundary()
          Calculates boundary nodes of this grid.
 java.util.Map calcBoundaryEdges()
          Calculates boundary edges of this grid.
static int co(int i, int j)
          Calculate the only number in {0,1,2} \ {i,j}.
 Grid createCopy()
          Creates a new (essentially) deep copy of this.
static Grid createFromFile(java.lang.String filename)
          Creates a new Grid from the given filename.
static Grid createFromReader(java.io.BufferedReader in)
          Creates a new Grid from in.
static Grid createFromReader(java.io.BufferedReader in, boolean shiftDownIndices)
           
static Grid createFromReader2(java.io.BufferedReader in)
          Creates a new Grid from in.
static Grid createFromResource(java.lang.String res)
          Creates a new Grid from the given res.
static Grid createFromUrl(java.net.URL url)
          Creates a new Grid from the given url.
 void createParentElements()
           
 java.awt.geom.Rectangle2D getBounds()
           
 double getC_G()
           
 double getC_h()
           
 Node getCenterNode()
           
 java.util.Set getEdges()
          Returns the edges.
 java.util.Set getElements()
          Returns the elements.
 double getH()
           
 int getIndex(Triangle t, Triangle neighbour)
          Returns the index of the edge of t which is common.
 java.util.Set getInflowEdges()
           
 java.util.Map getInfo()
           
 java.lang.String getInfo(Edge e)
          Each edge has a possible info associated with it.
 java.lang.String getInfo(Node n)
           
 Node getMiddleNode(Node a, Node b)
          Calculates average of a and b.
 Node getMiddleNodeForEdge(Triangle t, int index)
           
 Triangle getNeighbour(Triangle t, int i)
          Returns the Triangle adjacent to t on side i.
 java.util.Set getNodes()
          Returns the nodes.
 java.util.Map getParentElements()
           
 Grid getParentGrid()
           
 Node getSchwerpunkt(Triangle t)
          Calculates the average of the nodes of t.
 java.util.Map getTriangleInfo()
           
 double getTriangleInfo(Triangle t)
          Each triangle has a possible info associated with it.
 boolean isMarkedGreen(Triangle t)
           
static java.lang.String nextLine(java.io.BufferedReader in)
           
 void putMarkedGreen(Triangle t)
           
 void removeMarkedGreen(Triangle t)
           
 void setBounds(java.awt.geom.Rectangle2D bounds)
           
 void setCenterNode(Node centerNode)
           
 void setEdges(java.util.Set edges)
          Sets the edges.
 void setElements(java.util.Set elements)
          Sets the elements.
 void setInfo(Edge e, java.lang.String s)
           
 void setInfo(java.util.Map map)
           
 void setNodes(java.util.Set nodes)
          Sets the nodes.
 void setParentElements(java.util.Map parentElements)
           
 void setParentGrid(Grid parentGrid)
           
 void setTriangleInfo(Triangle t, double d)
           
 void writeToFile(java.io.File file)
           
 void writeToFile(java.io.File file, boolean matlab)
          Writes this grid to file.
 void writeToFile(java.lang.String filename)
          Writes this grid to filename.
 void writeToWriter(java.io.PrintWriter out)
          Writes this grid to out.
 void writeToWriter(java.io.PrintWriter out, boolean matlab)
          Writes this grid to out, with an Matlab compatible format, if matlab is true.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grid

public Grid(java.util.Set nodes,
            java.util.Set edges,
            java.util.Set elements)
Creates a new Grid from the given sets of nodes, edges and elements.

Parameters:
nodes -
edges -
elements -
Method Detail

getNeighbour

public Triangle getNeighbour(Triangle t,
                             int i)
Returns the Triangle adjacent to t on side i. It get's the Information from t.getEdge(i).

Parameters:
t - triangle of which we want to have the neighbour
i - number of the side of t
Returns:
triangle adjacent to edge i of t
See Also:
Edge.getOtherTriangle(Triangle)

getIndex

public int getIndex(Triangle t,
                    Triangle neighbour)
Returns the index of the edge of t which is common.

Parameters:
t -
neighbour -
Returns:
index of commen edge, or -1 if not adjacent

createCopy

public Grid createCopy()
Creates a new (essentially) deep copy of this. Immutable Objects are not cloned.

Returns:
deep copy

createFromFile

public static Grid createFromFile(java.lang.String filename)
Creates a new Grid from the given filename.

Parameters:
filename -
Returns:
new Grid from filename

createFromResource

public static Grid createFromResource(java.lang.String res)
                               throws java.io.FileNotFoundException
Creates a new Grid from the given res.

Parameters:
res -
Returns:
new Grid from res
Throws:
java.io.FileNotFoundException
See Also:
createFromStream(InputStream, String)

createFromUrl

public static Grid createFromUrl(java.net.URL url)
                          throws java.io.IOException
Creates a new Grid from the given url.

Parameters:
url -
Returns:
new Grid from url
Throws:
java.io.IOException
See Also:
createFromStream(InputStream, String)

createFromReader

public static Grid createFromReader(java.io.BufferedReader in)
                             throws java.io.IOException
Creates a new Grid from in.

Parameters:
in -
Returns:
new Grid from in
Throws:
java.io.IOException

createFromReader

public static Grid createFromReader(java.io.BufferedReader in,
                                    boolean shiftDownIndices)
                             throws java.io.IOException
Throws:
java.io.IOException

createFromReader2

public static Grid createFromReader2(java.io.BufferedReader in)
                              throws java.io.IOException
Creates a new Grid from in.

Parameters:
in -
Returns:
new Grid from in
Throws:
java.io.IOException

nextLine

public static java.lang.String nextLine(java.io.BufferedReader in)
                                 throws java.io.IOException
Throws:
java.io.IOException

writeToFile

public void writeToFile(java.lang.String filename)
Writes this grid to filename.

Parameters:
filename -
See Also:
writeToFile(File)

writeToFile

public void writeToFile(java.io.File file,
                        boolean matlab)
Writes this grid to file.

Parameters:
file -
See Also:
writeToWriter(PrintWriter)

writeToFile

public void writeToFile(java.io.File file)

writeToWriter

public void writeToWriter(java.io.PrintWriter out)
                   throws java.io.IOException
Writes this grid to out. Matlab-Export is true.

Parameters:
out -
Throws:
java.io.IOException
See Also:
writeToWriter(PrintWriter, boolean)

writeToWriter

public void writeToWriter(java.io.PrintWriter out,
                          boolean matlab)
                   throws java.io.IOException
Writes this grid to out, with an Matlab compatible format, if matlab is true.

Parameters:
out -
matlab - matlab compatible output
Throws:
java.io.IOException

getMiddleNode

public Node getMiddleNode(Node a,
                          Node b)
Calculates average of a and b.

Parameters:
a -
b -
Returns:
average of a and b

getMiddleNodeForEdge

public Node getMiddleNodeForEdge(Triangle t,
                                 int index)

getSchwerpunkt

public Node getSchwerpunkt(Triangle t)
Calculates the average of the nodes of t.

Parameters:
t -
Returns:
average of nodes of t

calcBoundary

public java.util.Map calcBoundary()
Calculates boundary nodes of this grid. An edge is considered as boundary if it has only one adjacent triangle. The value of an node is the info of its edge.

Returns:
boundary nodes with respective edge info
See Also:
getNeighbour(Triangle, int), getInfo(Edge)

calcBoundaryEdges

public java.util.Map calcBoundaryEdges()
Calculates boundary edges of this grid. An edge is considered as boundary if it has only one adjacent triangle. The value of an edge is its info.

Returns:
boundary edges with respective info
See Also:
getNeighbour(Triangle, int), TODO badly impl cause same double iteration as above

getInflowEdges

public java.util.Set getInflowEdges()

getInfo

public java.lang.String getInfo(Edge e)
Each edge has a possible info associated with it.

Parameters:
e -
Returns:
info for edge e.

getInfo

public java.lang.String getInfo(Node n)

addNewTriangle

public Triangle addNewTriangle(Node[] nodes)
Adds a new Triangle based on nodes.

Parameters:
nodes -
Returns:
new Triangle based on nodes
See Also:
Triangle.Triangle(Node[])

getEdges

public java.util.Set getEdges()
Returns the edges.

Returns:
Set

getElements

public java.util.Set getElements()
Returns the elements.

Returns:
Set

getNodes

public java.util.Set getNodes()
Returns the nodes.

Returns:
Set

setEdges

public void setEdges(java.util.Set edges)
Sets the edges.

Parameters:
edges - The edges to set

setElements

public void setElements(java.util.Set elements)
Sets the elements.

Parameters:
elements - The elements to set

setNodes

public void setNodes(java.util.Set nodes)
Sets the nodes.

Parameters:
nodes - The nodes to set

co

public static int co(int i,
                     int j)
Calculate the only number in {0,1,2} \ {i,j}.

Parameters:
i -
j -
Returns:
the only number in {0,1,2} \ {i,j}.

getH

public double getH()

getC_h

public double getC_h()

getC_G

public double getC_G()

getCenterNode

public Node getCenterNode()

setCenterNode

public void setCenterNode(Node centerNode)

getBounds

public java.awt.geom.Rectangle2D getBounds()

setBounds

public void setBounds(java.awt.geom.Rectangle2D bounds)

isMarkedGreen

public boolean isMarkedGreen(Triangle t)

putMarkedGreen

public void putMarkedGreen(Triangle t)

removeMarkedGreen

public void removeMarkedGreen(Triangle t)

getInfo

public java.util.Map getInfo()

setInfo

public void setInfo(java.util.Map map)

getParentElements

public java.util.Map getParentElements()

setParentElements

public void setParentElements(java.util.Map parentElements)

createParentElements

public void createParentElements()

getParentGrid

public Grid getParentGrid()

setParentGrid

public void setParentGrid(Grid parentGrid)

getTriangleInfo

public double getTriangleInfo(Triangle t)
Each triangle has a possible info associated with it.

Parameters:
t -
Returns:
info for t.

setTriangleInfo

public void setTriangleInfo(Triangle t,
                            double d)

getTriangleInfo

public java.util.Map getTriangleInfo()

setInfo

public void setInfo(Edge e,
                    java.lang.String s)