Commit cd40b148 authored by Dmitry Bagaev's avatar Dmitry Bagaev

Merge branch 'INMOST-DEV/master' into fixfc2

parent 1c2af4d6
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <iostream> #include <iostream>
#define LOG(level,msg) { if (log_level >= level) cout << msg << endl; } #define LOG(level,msg) { if (log_level >= level) cout << msg << endl; }
#define BARRIER MPI_Barrier(MPI_COMM_WORLD);
using namespace std; using namespace std;
...@@ -167,6 +168,24 @@ void motion(int nmx, int nmy) // Mouse ...@@ -167,6 +168,24 @@ void motion(int nmx, int nmy) // Mouse
glutPostRedisplay(); glutPostRedisplay();
} }
void set_color(int i)
{
switch (i)
{
case 0: glColor3f(0.0, 0.0, 1.0); break;
case 1: glColor3f(0.0, 1.0, 0.0); break;
case 2: glColor3f(1.0, 0.0, 0.0); break;
case 3: glColor3f(0.0, 1.0, 1.0); break;
case 4: glColor3f(1.0, 0.0, 1.0); break;
case 5: glColor3f(0.0, 0.5, 0.5); break;
case 6: glColor3f(1.0, 1.0, 0.0); break;
case 7: glColor3f(0.3, 0.8, 0.5); break;
case 8: glColor3f(0.5, 0.0, 0.5); break;
case 9: glColor3f(0.5, 0.5, 0.0); break;
case 10: glColor3f(1.0, 1.0, 1.0); break;
}
}
/// Main drawing function. MPI version draws cells of each processor with unique color. /// Main drawing function. MPI version draws cells of each processor with unique color.
void mpi_draw() void mpi_draw()
{ {
...@@ -204,19 +223,7 @@ void mpi_draw() ...@@ -204,19 +223,7 @@ void mpi_draw()
for (int i = 1; i < size; i++) for (int i = 1; i < size; i++)
{ {
if (current_proc_draw != -1 && current_proc_draw != i) continue; if (current_proc_draw != -1 && current_proc_draw != i) continue;
switch (i) set_color(i);
{
case 1: glColor3f(0.0, 1.0, 0.0); break;
case 2: glColor3f(1.0, 0.0, 0.0); break;
case 3: glColor3f(0.0, 1.0, 1.0); break;
case 4: glColor3f(1.0, 0.0, 1.0); break;
case 5: glColor3f(0.0, 0.5, 0.5); break;
case 6: glColor3f(1.0, 1.0, 0.0); break;
case 7: glColor3f(0.3, 0.8, 0.5); break;
case 8: glColor3f(0.5, 0.0, 0.5); break;
case 9: glColor3f(0.5, 0.5, 0.0); break;
case 10: glColor3f(1.0, 1.0, 1.0); break;
}
if (i > 10 && i < 13) if (i > 10 && i < 13)
{ {
...@@ -249,20 +256,23 @@ void mpi_draw() ...@@ -249,20 +256,23 @@ void mpi_draw()
// Draw our edges // Draw our edges
glColor3f(0.0f,0.0f,0.0f); glColor3f(0.0f,0.0f,0.0f);
glBegin(GL_LINES); if (current_proc_draw == -1 || current_proc_draw == 0)
for (Mesh::iteratorEdge f = thegrid.mesh->BeginEdge(); f != thegrid.mesh->EndEdge(); f++)
{ {
ElementArray<Node> nodes = f->getNodes(); glBegin(GL_LINES);
glVertex3dv(&nodes[0].RealArray(thegrid.mesh->CoordsTag())[0]); for (Mesh::iteratorEdge f = thegrid.mesh->BeginEdge(); f != thegrid.mesh->EndEdge(); f++)
glVertex3dv(&nodes[1].RealArray(thegrid.mesh->CoordsTag())[0]); {
ElementArray<Node> nodes = f->getNodes();
glVertex3dv(&nodes[0].RealArray(thegrid.mesh->CoordsTag())[0]);
glVertex3dv(&nodes[1].RealArray(thegrid.mesh->CoordsTag())[0]);
}
glEnd();
} }
glEnd();
// Draw other edges // Draw other edges
glLineWidth(2); glLineWidth(2);
glBegin(GL_LINES); glBegin(GL_LINES);
for (int i = 1; i < size; i++) for (int i = 1; i < size; i++)
{ {
if (current_proc_draw != -1 && current_proc_draw != i) continue;
for (int j = 0; j < sub_edges_nodes_n[i]; j+=6) for (int j = 0; j < sub_edges_nodes_n[i]; j+=6)
{ {
glVertex3dv(&(sub_edges_nodes[i][j])); glVertex3dv(&(sub_edges_nodes[i][j]));
...@@ -416,7 +426,7 @@ void prepare_to_correct_brothers() ...@@ -416,7 +426,7 @@ void prepare_to_correct_brothers()
thegrid.mesh->AssignGlobalID(CELL | EDGE | FACE | NODE); thegrid.mesh->AssignGlobalID(CELL | EDGE | FACE | NODE);
} }
/// Redistribute grid by using partitioner /// Redistribute grid by partitioner
void redistribute(int type) void redistribute(int type)
{ {
LOG(2,"Process " << ::rank << ": redistribute. Cells: " << thegrid.mesh->NumberOfCells()) LOG(2,"Process " << ::rank << ": redistribute. Cells: " << thegrid.mesh->NumberOfCells())
...@@ -426,14 +436,27 @@ void redistribute(int type) ...@@ -426,14 +436,27 @@ void redistribute(int type)
if (type == 0) part->SetMethod(Partitioner::Parmetis, Partitioner::Partition); if (type == 0) part->SetMethod(Partitioner::Parmetis, Partitioner::Partition);
if (type == 1) part->SetMethod(Partitioner::Parmetis, Partitioner::Repartition); if (type == 1) part->SetMethod(Partitioner::Parmetis, Partitioner::Repartition);
if (type == 2) part->SetMethod(Partitioner::Parmetis, Partitioner::Refine); if (type == 2) part->SetMethod(Partitioner::Parmetis, Partitioner::Refine);
// Compute the partitioner and store new processor ID in the mesh try
part->Evaluate(); {
part->Evaluate();
}
catch (INMOST::ErrorType er)
{
cout << "Exception: " << er << endl;
}
delete part; delete part;
correct_brothers(&thegrid,size,::rank, 2); correct_brothers(&thegrid,size,::rank, 2);
try
{
thegrid.mesh->Redistribute();
}
catch (INMOST::ErrorType er)
{
cout << "Exception: " << er << endl;
}
thegrid.mesh->RemoveGhost(); thegrid.mesh->RemoveGhost();
thegrid.mesh->Redistribute();
thegrid.mesh->ReorderEmpty(CELL|FACE|EDGE|NODE); thegrid.mesh->ReorderEmpty(CELL|FACE|EDGE|NODE);
thegrid.mesh->AssignGlobalID(CELL | EDGE | FACE | NODE); thegrid.mesh->AssignGlobalID(CELL | EDGE | FACE | NODE);
LOG(2,"Process " << ::rank << ": redistribute completed") LOG(2,"Process " << ::rank << ": redistribute completed")
...@@ -544,6 +567,10 @@ void keyboard(unsigned char key, int x, int y) ...@@ -544,6 +567,10 @@ void keyboard(unsigned char key, int x, int y)
{ {
draw_edges = !draw_edges; draw_edges = !draw_edges;
} }
if( key == 't' || key == 'T' )
{
draw_faces = !draw_faces;
}
if( key == 'i' || key == 'I' ) if( key == 'i' || key == 'I' )
{ {
draw_in_motion = !draw_in_motion ; draw_in_motion = !draw_in_motion ;
...@@ -647,7 +674,7 @@ void NotMainProcess() ...@@ -647,7 +674,7 @@ void NotMainProcess()
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
int i; int i;
int n[3] = {10,10,1}; int n[3] = {2,2,1};
thegrid.transformation = transformation; thegrid.transformation = transformation;
thegrid.rev_transformation = rev_transformation; thegrid.rev_transformation = rev_transformation;
......
...@@ -351,7 +351,7 @@ void gridInit(struct grid * g, int n[3]) ...@@ -351,7 +351,7 @@ void gridInit(struct grid * g, int n[3])
} }
g->mesh->ResolveShared(); // Resolve duplicate nodes g->mesh->ResolveShared(); // Resolve duplicate nodes
g->mesh->ExchangeGhost(2,NODE); // Construct Ghost cells in 2 layers connected via nodes //g->mesh->ExchangeGhost(1,NODE); // Construct Ghost cells in 2 layers connected via nodes
} }
/// Return adjacent cell with number cell_num /// Return adjacent cell with number cell_num
...@@ -1177,6 +1177,59 @@ void gridCoarse(struct grid * g) ...@@ -1177,6 +1177,59 @@ void gridCoarse(struct grid * g)
} }
} }
void print_redist_tag(struct grid* g, int rank)
{
Tag tag_owner = g->mesh->RedistributeTag();
for(Mesh::iteratorCell it = g->mesh->BeginCell(); it != g->mesh->EndCell(); it++)
{
cout << rank << " : " << it->getAsCell().Integer(tag_owner) << " : ";
print_cell_center(g, it->getAsCell());
}
}
void pre_eval(struct grid* g, int size, int rank)
{
int c_all = g->mesh->TotalNumberOf(CELL);
int c_average = c_all / size;
int c_my = g->mesh->NumberOfCells();
Tag tag_owner = g->mesh->RedistributeTag();
for(Mesh::iteratorCell it = g->mesh->BeginCell(); it != g->mesh->EndCell(); it++)
{
it->getAsCell().Integer(tag_owner) = rank;
if( it->getAsCell().GetStatus() == Element::Ghost ) continue;
if (c_my > c_average)
{
int adj_count = 0;
bool has_adj = false;
ElementArray<Face> faces = it->getAsCell().getFaces();
for (ElementArray<Face>::iterator face = faces.begin(); face != faces.end(); face++)
{
ElementArray<Element> adjs = face->getAsFace().getAdjElements(CELL);
if (adjs.size() > 1) adj_count++;
if (adjs.size() > 1)
{
for (ElementArray<Element>::iterator p = adjs.begin(); p != adjs.end(); p++)
if (p->getAsCell().GetStatus() == Element::Ghost)
{
has_adj = true;
break;
}
if (has_adj) break;
}
}
if (has_adj)
{
c_my--;
it->getAsCell().Integer(tag_owner) = (rank + 1) % size;
}
}
};
}
void correct_brothers(struct grid* g, int size, int rank, int type) void correct_brothers(struct grid* g, int size, int rank, int type)
{ {
Tag tag_owner = g->mesh->RedistributeTag(); Tag tag_owner = g->mesh->RedistributeTag();
...@@ -1193,7 +1246,7 @@ void correct_brothers(struct grid* g, int size, int rank, int type) ...@@ -1193,7 +1246,7 @@ void correct_brothers(struct grid* g, int size, int rank, int type)
ElementArray<Cell> children; ElementArray<Cell> children;
ElementArray<Element> adjs = center_node.getAdjElements(CELL); ElementArray<Element> adjs = center_node.getAdjElements(CELL);
if (adjs.size() != 8) TSNH //if (adjs.size() != 8) TSNH
int my = 0; int my = 0;
int new_owner = 0; int new_owner = 0;
...@@ -1210,7 +1263,7 @@ void correct_brothers(struct grid* g, int size, int rank, int type) ...@@ -1210,7 +1263,7 @@ void correct_brothers(struct grid* g, int size, int rank, int type)
for (ElementArray<Element>::iterator p = adjs.begin(); p != adjs.end(); p++) for (ElementArray<Element>::iterator p = adjs.begin(); p != adjs.end(); p++)
{ {
if (p->getAsCell().Integer(g->c_tags.level) == 0) continue; if (p->getAsCell().Integer(g->c_tags.level) == 0) continue;
if (type == 2) p->getAsCell().Integer(tag_owner) = rank == 0? 1 : 0; p->getAsCell().Integer(tag_owner) = new_owner;
} }
} }
} }
...@@ -1221,14 +1274,14 @@ void gridAMR(struct grid * g, int action) ...@@ -1221,14 +1274,14 @@ void gridAMR(struct grid * g, int action)
if (action == 0 || action == 1) if (action == 0 || action == 1)
gridCoarse(g); gridCoarse(g);
g->mesh->ReorderEmpty(CELL | FACE | EDGE | NODE); //g->mesh->ExchangeGhost(1,NODE); // Construct Ghost cells in 2 layers connected via nodes
g->mesh->ResolveShared(); // Resolve duplicate nodes //g->mesh->ReorderEmpty(CELL | FACE | EDGE | NODE);
g->mesh->ExchangeGhost(2,NODE); // Construct Ghost cells in 2 layers connected via nodes //g->mesh->ResolveShared(); // Resolve duplicate nodes
if (action == 0 || action == 2) if (action == 0 || action == 2)
gridRefine(g); gridRefine(g);
g->mesh->ReorderEmpty(CELL | FACE | EDGE | NODE); g->mesh->ReorderEmpty(CELL | FACE | EDGE | NODE);
// g->mesh->ExchangeGhost(1,NODE); // Construct Ghost cells in 2 layers connected via nodes
g->mesh->ResolveShared(); // Resolve duplicate nodes g->mesh->ResolveShared(); // Resolve duplicate nodes
g->mesh->ExchangeGhost(2,NODE); // Construct Ghost cells in 2 layers connected via nodes
} }
...@@ -62,10 +62,13 @@ struct grid ...@@ -62,10 +62,13 @@ struct grid
/// Often after redistribution brother cells splits to different processor /// Often after redistribution brother cells splits to different processor
/// This function corrects this division. Puts all children to one processor /// This function corrects this division. Puts all children to one processor
void correct_brothers(struct grid* g, int size, int rank, int type); void correct_brothers(struct grid* g, int size, int rank, int type);
void pre_eval(struct grid* g, int size, int rank);
/// Debug. Print information about all cells /// Debug. Print information about all cells
void print_all_about_cells(struct grid * g); void print_all_about_cells(struct grid * g);
void print_redist_tag(struct grid* g, int rank);
/// Initialize grid. Create tags and other data /// Initialize grid. Create tags and other data
void gridInit(struct grid * g, int n[3]); void gridInit(struct grid * g, int n[3]);
/// Split cells using "cell_should_split" rule /// Split cells using "cell_should_split" rule
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment