~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to sandbox/graph/main.cpp

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <dolfin.h>
 
2
#include <iostream>
 
3
 
 
4
using namespace dolfin;
 
5
 
 
6
void testGraphEditor()
 
7
{
 
8
  /// Testing GraphEditor
 
9
  std::cout << "Testing GraphEditor" << std::endl;
 
10
  GraphEditor ge;
 
11
  Graph graph;
 
12
  ge.open(graph, Graph::undirected);
 
13
  ge.initVertices(4);
 
14
  ge.addVertex(0, 2);
 
15
  ge.addVertex(1, 3);
 
16
  ge.addVertex(2, 2);
 
17
  ge.addVertex(3, 3);
 
18
 
 
19
  ge.initEdges(5);
 
20
  ge.addEdge(0, 1);
 
21
  ge.addEdge(1, 2);
 
22
  ge.addEdge(2, 3);
 
23
  ge.addEdge(1, 3);
 
24
  ge.addEdge(0, 3);
 
25
 
 
26
  ge.close();
 
27
 
 
28
  graph.disp();
 
29
}
 
30
void testMeshToGraph()
 
31
{
 
32
  std::cout << "Testing Mesh to graph convertion" << std::endl;
 
33
  UnitSquare mesh(2, 2);
 
34
 
 
35
  Graph graph(mesh, "nodal");
 
36
 
 
37
}
 
38
void testInputOutput()
 
39
{
 
40
  std::cout << "Testing InputOutput" << std::endl;
 
41
  Graph graph;
 
42
  GraphEditor editor;
 
43
  editor.open(graph, Graph::undirected);
 
44
  editor.initVertices(3);
 
45
  editor.addVertex(0, 2);
 
46
  editor.addVertex(1, 2);
 
47
  editor.addVertex(2, 2);
 
48
  editor.initEdges(3);
 
49
  editor.addEdge(0, 1);
 
50
  editor.addEdge(0, 2);
 
51
  editor.addEdge(1, 2);
 
52
  editor.close();
 
53
  graph.disp();
 
54
 
 
55
  File file("graph_test.xml");
 
56
  file << graph;
 
57
 
 
58
  Graph graph2;
 
59
  file >> graph2;
 
60
  graph2.disp();
 
61
}
 
62
 
 
63
void testCloseError()
 
64
{
 
65
  std::cout << "Testing editor closing" << std::endl;
 
66
  Graph graph;
 
67
  GraphEditor editor;
 
68
  editor.open(graph, Graph::undirected);
 
69
  editor.initVertices(3);
 
70
  editor.addVertex(0, 2);
 
71
  editor.addVertex(1, 2);
 
72
  editor.addVertex(2, 2);
 
73
  editor.initEdges(3);
 
74
  editor.addEdge(0, 1);
 
75
  editor.addEdge(0, 2);
 
76
  editor.close();
 
77
}
 
78
 
 
79
void testOutOfOrderError()
 
80
{
 
81
  std::cout << "Testing adding vertices out of order" << std::endl;
 
82
  Graph graph;
 
83
  GraphEditor editor;
 
84
  editor.open(graph, Graph::undirected);
 
85
  editor.initVertices(3);
 
86
  editor.addVertex(0, 2);
 
87
  editor.addVertex(2, 2);
 
88
  editor.addVertex(1, 2);
 
89
  editor.initEdges(3);
 
90
  editor.addEdge(0, 1);
 
91
  editor.addEdge(0, 2);
 
92
  editor.addEdge(1, 2);
 
93
  editor.close();
 
94
}
 
95
 
 
96
void testTooManyVerticesError()
 
97
{
 
98
  std::cout << "Testing adding too many vertices" << std::endl;
 
99
  Graph graph;
 
100
  GraphEditor editor;
 
101
  editor.open(graph, Graph::undirected);
 
102
  editor.initVertices(3);
 
103
  editor.addVertex(0, 2);
 
104
  editor.addVertex(1, 2);
 
105
  editor.addVertex(2, 2);
 
106
  editor.addVertex(3, 2);
 
107
  editor.initEdges(3);
 
108
  editor.addEdge(0, 1);
 
109
  editor.addEdge(0, 2);
 
110
  editor.addEdge(1, 2);
 
111
  editor.close();
 
112
}
 
113
 
 
114
void testInitEdgesError1()
 
115
{
 
116
  std::cout << "Testing inititializing too few edges" << std::endl;
 
117
  Graph graph;
 
118
  GraphEditor editor;
 
119
  editor.open(graph, Graph::undirected);
 
120
  editor.initVertices(4);
 
121
  editor.addVertex(0, 2);
 
122
  editor.addVertex(1, 3);
 
123
  editor.addVertex(2, 2);
 
124
  editor.addVertex(3, 2);
 
125
  editor.initEdges(3);
 
126
  editor.close();
 
127
}
 
128
 
 
129
void testInitEdgesError2()
 
130
{
 
131
  std::cout << "Testing inititializing too many edges" << std::endl;
 
132
  Graph graph;
 
133
  GraphEditor editor;
 
134
  editor.open(graph, Graph::undirected);
 
135
  editor.initVertices(4);
 
136
  editor.addVertex(0, 2);
 
137
  editor.addVertex(1, 3);
 
138
  editor.addVertex(2, 2);
 
139
  editor.addVertex(3, 2);
 
140
  editor.initEdges(5);
 
141
  editor.close();
 
142
}
 
143
 
 
144
void testIteration()
 
145
{
 
146
  /* 2---3
 
147
   * |\1 |\
 
148
   * | \ | \
 
149
   * |0 \|2 \
 
150
   * 0---1---4
 
151
   *
 
152
   *
 
153
   *
 
154
   */
 
155
  
 
156
  Mesh mesh;
 
157
  MeshEditor editor;
 
158
  editor.open(mesh, "triangle", 2, 2);
 
159
  editor.initVertices(5);
 
160
  editor.addVertex(0, 0.4, 0.4);
 
161
  editor.addVertex(1, 0.7, 0.4);
 
162
  editor.addVertex(2, 0.4, 0.7);
 
163
  editor.addVertex(3, 0.7, 0.7);
 
164
  editor.addVertex(4, 1.0, 0.4);
 
165
  editor.initCells(3);
 
166
  editor.addCell(0, 0, 1, 2);
 
167
  editor.addCell(1, 2, 1, 3);
 
168
  editor.addCell(2, 3, 1, 4);
 
169
  editor.close();
 
170
 
 
171
  mesh.init(2, 2);
 
172
  mesh.disp();
 
173
 
 
174
  for (CellIterator c0(mesh); !c0.end(); ++c0)
 
175
  {
 
176
    cout << *c0 << endl;
 
177
    for (CellIterator c1(*c0); !c1.end(); ++c1)
 
178
      cout << "  " << *c1 << endl;
 
179
  }
 
180
}
 
181
 
 
182
int main(int argc, char* argv[])
 
183
{
 
184
  //testMeshToGraph();
 
185
  //testGraphEditor();
 
186
  //testInputOutput(); 
 
187
  //testCloseError();
 
188
  //testTooManyVerticesError();
 
189
  //testInitEdgesError1();
 
190
  //testInitEdgesError2();
 
191
 
 
192
  testIteration();
 
193
}