Commit cd40b148 authored by Dmitry Bagaev's avatar Dmitry Bagaev

Merge branch 'INMOST-DEV/master' into fixfc2

parent 1c2af4d6
......@@ -8,6 +8,7 @@
#include <iostream>
#define LOG(level,msg) { if (log_level >= level) cout << msg << endl; }
#define BARRIER MPI_Barrier(MPI_COMM_WORLD);
using namespace std;
......@@ -167,6 +168,24 @@ void motion(int nmx, int nmy) // Mouse
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.
void mpi_draw()
{
......@@ -204,19 +223,7 @@ void mpi_draw()
for (int i = 1; i < size; i++)
{
if (current_proc_draw != -1 && current_proc_draw != i) continue;
switch (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;
}
set_color(i);
if (i > 10 && i < 13)
{
......@@ -249,6 +256,8 @@ void mpi_draw()
// Draw our edges
glColor3f(0.0f,0.0f,0.0f);
if (current_proc_draw == -1 || current_proc_draw == 0)
{
glBegin(GL_LINES);
for (Mesh::iteratorEdge f = thegrid.mesh->BeginEdge(); f != thegrid.mesh->EndEdge(); f++)
{
......@@ -257,12 +266,13 @@ void mpi_draw()
glVertex3dv(&nodes[1].RealArray(thegrid.mesh->CoordsTag())[0]);
}
glEnd();
}
// Draw other edges
glLineWidth(2);
glBegin(GL_LINES);
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)
{
glVertex3dv(&(sub_edges_nodes[i][j]));
......@@ -416,7 +426,7 @@ void prepare_to_correct_brothers()
thegrid.mesh->AssignGlobalID(CELL | EDGE | FACE | NODE);
}
/// Redistribute grid by using partitioner
/// Redistribute grid by partitioner
void redistribute(int type)
{
LOG(2,"Process " << ::rank << ": redistribute. Cells: " << thegrid.mesh->NumberOfCells())
......@@ -427,13 +437,26 @@ void redistribute(int type)
if (type == 1) part->SetMethod(Partitioner::Parmetis, Partitioner::Repartition);
if (type == 2) part->SetMethod(Partitioner::Parmetis, Partitioner::Refine);
// Compute the partitioner and store new processor ID in the mesh
try
{
part->Evaluate();
}
catch (INMOST::ErrorType er)
{
cout << "Exception: " << er << endl;
}
delete part;
correct_brothers(&thegrid,size,::rank, 2);
thegrid.mesh->RemoveGhost();
try
{
thegrid.mesh->Redistribute();
}
catch (INMOST::ErrorType er)
{
cout << "Exception: " << er << endl;
}
thegrid.mesh->RemoveGhost();
thegrid.mesh->ReorderEmpty(CELL|FACE|EDGE|NODE);
thegrid.mesh->AssignGlobalID(CELL | EDGE | FACE | NODE);
LOG(2,"Process " << ::rank << ": redistribute completed")
......@@ -544,6 +567,10 @@ void keyboard(unsigned char key, int x, int y)
{
draw_edges = !draw_edges;
}
if( key == 't' || key == 'T' )
{
draw_faces = !draw_faces;
}
if( key == 'i' || key == 'I' )
{
draw_in_motion = !draw_in_motion ;
......@@ -647,7 +674,7 @@ void NotMainProcess()
int main(int argc, char ** argv)
{
int i;
int n[3] = {10,10,1};
int n[3] = {2,2,1};
thegrid.transformation = transformation;
thegrid.rev_transformation = rev_transformation;
......
......@@ -351,7 +351,7 @@ void gridInit(struct grid * g, int n[3])
}
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
......@@ -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)
{
Tag tag_owner = g->mesh->RedistributeTag();
......@@ -1193,7 +1246,7 @@ void correct_brothers(struct grid* g, int size, int rank, int type)
ElementArray<Cell> children;
ElementArray<Element> adjs = center_node.getAdjElements(CELL);
if (adjs.size() != 8) TSNH
//if (adjs.size() != 8) TSNH
int my = 0;
int new_owner = 0;
......@@ -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++)
{
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)
if (action == 0 || action == 1)
gridCoarse(g);
g->mesh->ReorderEmpty(CELL | FACE | EDGE | NODE);
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
//g->mesh->ReorderEmpty(CELL | FACE | EDGE | NODE);
//g->mesh->ResolveShared(); // Resolve duplicate nodes
if (action == 0 || action == 2)
gridRefine(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->ExchangeGhost(2,NODE); // Construct Ghost cells in 2 layers connected via nodes
}
......@@ -62,10 +62,13 @@ struct grid
/// Often after redistribution brother cells splits to different 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 pre_eval(struct grid* g, int size, int rank);
/// Debug. Print information about all cells
void print_all_about_cells(struct grid * g);
void print_redist_tag(struct grid* g, int rank);
/// Initialize grid. Create tags and other data
void gridInit(struct grid * g, int n[3]);
/// 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