Commit 81ff6d4b authored by SilverLife's avatar SilverLife
Browse files

Add SynchronizeIndicated function to AdaptiveMesh example.

parent fb1b5fda
...@@ -156,11 +156,26 @@ namespace INMOST ...@@ -156,11 +156,26 @@ namespace INMOST
ss << "Faces: " << NumberOfFaces() << endl; ss << "Faces: " << NumberOfFaces() << endl;
for(Mesh::iteratorFace it = BeginFace(); it != EndFace(); ++it) for(Mesh::iteratorFace it = BeginFace(); it != EndFace(); ++it)
{ {
ss << rank << ": " << it->GlobalID() << " - " ; ss << rank << ": " << setw(2) << it->LocalID() << " " << setw(2) << it->GlobalID() << " - " ;
ss << setw(6);
if (it->GetStatus() == Element::Shared) ss << "shared"; if (it->GetStatus() == Element::Shared) ss << "shared";
else if (it->GetStatus() == Element::Ghost) ss << "ghost"; else if (it->GetStatus() == Element::Ghost) ss << "ghost";
else ss << "none"; else ss << "none";
double xyz[3];
it->Centroid(xyz);
ss << " (" << setw(5) << xyz[0] << " " << setw(5) << xyz[1] << " " << setw(5) << xyz[2] << ")";
ss << " " << GetMarker(*it,NewMarker());
ss << " nc(" << it->getNodes().size() << ": ";
ElementArray<Node> nodes = it->getNodes();
for (ElementArray<Node>::iterator node = nodes.begin(); node != nodes.end(); node++)
ss << setw(2) << node->GlobalID() << " ";
ss << ")";
/*
Storage::reference_array refs = ref_tag[it->self()]; Storage::reference_array refs = ref_tag[it->self()];
if (refs.size() > 0) ss << ". Ref: "; if (refs.size() > 0) ss << ". Ref: ";
for(Storage::reference_array::size_type i = 0; i < refs.size(); ++i) for(Storage::reference_array::size_type i = 0; i < refs.size(); ++i)
...@@ -184,6 +199,8 @@ namespace INMOST ...@@ -184,6 +199,8 @@ namespace INMOST
} }
ss << endl; ss << endl;
} }
*/
ss << endl;
} }
} }
...@@ -218,7 +235,8 @@ namespace INMOST ...@@ -218,7 +235,8 @@ namespace INMOST
ss << "Nodes:" << endl; ss << "Nodes:" << endl;
for(Mesh::iteratorNode it = BeginNode(); it != EndNode(); ++it) for(Mesh::iteratorNode it = BeginNode(); it != EndNode(); ++it)
{ {
ss << rank << ": " << it->GlobalID() << " - " ; ss << rank << ": " << setw(2) << it->GlobalID() << " - " ;
ss << setw(6);
if (it->GetStatus() == Element::Shared) ss << "shared"; if (it->GetStatus() == Element::Shared) ss << "shared";
else if (it->GetStatus() == Element::Ghost) ss << "ghost"; else if (it->GetStatus() == Element::Ghost) ss << "ghost";
else ss << "none"; else ss << "none";
...@@ -236,6 +254,14 @@ namespace INMOST ...@@ -236,6 +254,14 @@ namespace INMOST
ss << "(" << type << "," << refs[i]->GlobalID() << ") "; ss << "(" << type << "," << refs[i]->GlobalID() << ") ";
} }
ss << " " << GetMarker(*it,NewMarker());
ss << "(" <<
setw(3) << it->RealArray(CoordsTag())[0] << " " <<
setw(3) << it->RealArray(CoordsTag())[1] << " " <<
setw(3) << it->RealArray(CoordsTag())[2] << ")";
} }
ss << endl; ss << endl;
} }
...@@ -652,6 +678,7 @@ namespace INMOST ...@@ -652,6 +678,7 @@ namespace INMOST
ResolveShared(true); ResolveShared(true);
//if (call_counter == 0) //if (call_counter == 0)
ResolveModification(false,1); ResolveModification(false,1);
//ExchangeGhost(3,NODE); // Construct Ghost cells in 2 layers connected via nodes
//12. Let the user update their data //12. Let the user update their data
//todo: call back function for New() cells //todo: call back function for New() cells
//13. Delete old elements of the mesh //13. Delete old elements of the mesh
...@@ -659,11 +686,17 @@ namespace INMOST ...@@ -659,11 +686,17 @@ namespace INMOST
//14. Done //14. Done
//cout << rank << ": Before end " << endl; //cout << rank << ": Before end " << endl;
EndModification(); EndModification();
ResolveSets();
CheckCentroids(); CheckCentroids();
//RemoveGhost(&marker_new);
//ExchangeGhost(1,FACE,&marker_new); // Construct Ghost cells in 2 layers connected via nodes BeginModification();
//ReleaseMarker(marker_new); ExchangeGhost(1,NODE,&marker_new); // Construct Ghost cells in 2 layers connected via nodes
//ExchangeData(hanging_nodes,CELL | FACE,0); ReleaseMarker(marker_new);
ApplyModification();
EndModification();
//ExchangeData(hanging_nodes,CELL | FACE,0);
//cout << rank << ": After end " << endl; //cout << rank << ": After end " << endl;
//reorder element's data to free up space //reorder element's data to free up space
ReorderEmpty(CELL|FACE|EDGE|NODE); ReorderEmpty(CELL|FACE|EDGE|NODE);
...@@ -672,9 +705,73 @@ namespace INMOST ...@@ -672,9 +705,73 @@ namespace INMOST
cout << ro() << rank << ": END REFINE " << (ret != 0) << endl; cout << ro() << rank << ": END REFINE " << (ret != 0) << endl;
return ret != 0; return ret != 0;
} }
void OperationMin(const Tag & tag, const Element & element, const INMOST_DATA_BULK_TYPE * data, INMOST_DATA_ENUM_TYPE size)
{
int value = (int)*((int*)data);
if (value < element->Integer(tag))
{
element->Integer(tag) = value;
}
(void)size;
}
void AdaptiveMesh::SynchronizeIndicated(TagInteger& indicator)
{
if (GetProcessorsNumber() == 1) return;
int rank = GetProcessorRank();
// Check all sets. All elements in sets must be indicated. At first we check indicator in local processor, and second integrate data
TagInteger tag_indicated = CreateTag("INDICATED",DATA_INTEGER,ESET,NONE,1);
for(Mesh::iteratorSet it = BeginSet(); it != EndSet(); ++it)
{
ElementSet set = ElementSet(this,*it);
set.Integer(tag_indicated) = 1;
ElementSet::iterator p = set.Begin();
while(p != set.End())
{
if (indicator[*p] == 0)
{
tag_indicated[set] = 0;
//cout << ro() << rank << ": Set " << set.GetName() << " not all indicated" << endl;
break;
}
p++;
}
}
ReduceData(tag_indicated,ESET,0,OperationMin);
ExchangeData(tag_indicated,ESET,0);
for(Mesh::iteratorSet it = BeginSet(); it != EndSet(); ++it)
if (it->Integer(tag_indicated) == 0)
{
ElementSet::iterator p = it->Begin();
while(p != it->End())
{
p->Integer(indicator) = 0;
p++;
}
}
/*
stringstream ss;
for(Mesh::iteratorSet it = BeginSet(); it != EndSet(); ++it)
{
ss << it->GetName() << " - " << it->Integer(tag_indicated) << endl;;
}
cout << ro() << rank << " Sets: \n" << ss.str() << endl;
*/
}
bool AdaptiveMesh::Coarse(TagInteger & indicator) bool AdaptiveMesh::Coarse(TagInteger & indicator)
{ {
cout << ro() << rank << ": BEGIN COARSE\n";
SynchronizeIndicated(indicator);
return false;
static int call_counter = 0; static int call_counter = 0;
//return number of coarsened cells //return number of coarsened cells
int ret = 0; int ret = 0;
...@@ -983,12 +1080,13 @@ namespace INMOST ...@@ -983,12 +1080,13 @@ namespace INMOST
//todo: //todo:
ResolveShared(true); ResolveShared(true);
ResolveModification(false,1); ResolveModification(false,1);
CheckCentroids();
//todo: //todo:
//let the user update their data //let the user update their data
ApplyModification(); ApplyModification();
//done //done
EndModification(); EndModification();
CheckCentroids(); //CheckCentroids();
//ExchangeData(hanging_nodes,CELL | FACE,0); //ExchangeData(hanging_nodes,CELL | FACE,0);
//cleanup null links to hanging nodes //cleanup null links to hanging nodes
for(ElementType etype = FACE; etype <= CELL; etype = NextElementType(etype)) for(ElementType etype = FACE; etype <= CELL; etype = NextElementType(etype))
...@@ -1008,6 +1106,7 @@ namespace INMOST ...@@ -1008,6 +1106,7 @@ namespace INMOST
ReorderEmpty(CELL|FACE|EDGE|NODE|ESET); ReorderEmpty(CELL|FACE|EDGE|NODE|ESET);
call_counter++; call_counter++;
cout << ro() << rank << ": END COARSE\n";
return ret != 0; return ret != 0;
} }
} }
...@@ -15,6 +15,7 @@ namespace INMOST ...@@ -15,6 +15,7 @@ namespace INMOST
/// Do not do this in constructor, since mesh may contain no cells. /// Do not do this in constructor, since mesh may contain no cells.
void PrepareSet(); void PrepareSet();
void PrintSetLocal(std::string offset, ElementSet it, std::stringstream& ss); void PrintSetLocal(std::string offset, ElementSet it, std::stringstream& ss);
void SynchronizeIndicated(TagInteger& indicator);
public: public:
TagReference parent_set; //<Link to the set that contains an element. TagReference parent_set; //<Link to the set that contains an element.
TagReferenceArray hanging_nodes; //< Link to current hanging nodes of the cell. TagReferenceArray hanging_nodes; //< Link to current hanging nodes of the cell.
......
...@@ -1819,7 +1819,8 @@ namespace INMOST ...@@ -1819,7 +1819,8 @@ namespace INMOST
del_shared.clear(); del_shared.clear();
#endif //USE_PARALLEL_STORAGE #endif //USE_PARALLEL_STORAGE
for(element_set::iterator it = delete_elements.begin(); it != delete_elements.end(); it++) Destroy(*it); //for(element_set::iterator it = delete_elements.begin(); it != delete_elements.end(); it++) Destroy(*it);
for(element_set::iterator it = delete_elements.begin(); it != delete_elements.end(); it++) Delete(*it);
delete_elements.clear(); delete_elements.clear();
for(ElementType mask = FACE; mask >= NODE; mask = PrevElementType(mask)) for(ElementType mask = FACE; mask >= NODE; mask = PrevElementType(mask))
...@@ -2024,7 +2025,8 @@ namespace INMOST ...@@ -2024,7 +2025,8 @@ namespace INMOST
} }
del_shared.clear(); del_shared.clear();
#endif //USE_PARALLEL_STORAGE #endif //USE_PARALLEL_STORAGE
for(element_set::iterator it = delete_elements.begin(); it != delete_elements.end(); it++) Destroy(*it); //for(element_set::iterator it = delete_elements.begin(); it != delete_elements.end(); it++) Destroy(*it);
for(element_set::iterator it = delete_elements.begin(); it != delete_elements.end(); it++) Delete(*it);
delete_elements.clear(); delete_elements.clear();
} }
DeleteTag(tag_delete); DeleteTag(tag_delete);
...@@ -5081,8 +5083,10 @@ namespace INMOST ...@@ -5081,8 +5083,10 @@ namespace INMOST
int mpirank = GetProcessorRank(); int mpirank = GetProcessorRank();
bool delete_ghost = false; bool delete_ghost = false;
//if( layers == Integer(tag_layers) && bridge == Integer(tag_bridge) ) return; //if( layers == Integer(tag_layers) && bridge == Integer(tag_bridge) ) return;
cout << "Check " << layers << " " << Integer(GetHandle(),tag_layers) << endl;
if( layers < Integer(GetHandle(),tag_layers) ) delete_ghost = true; if( layers < Integer(GetHandle(),tag_layers) ) delete_ghost = true;
else if( layers == Integer(GetHandle(),tag_layers) && bridge < Integer(GetHandle(),tag_bridge) ) delete_ghost = true; else if( layers == Integer(GetHandle(),tag_layers) && bridge < Integer(GetHandle(),tag_bridge) ) delete_ghost = true;
if (marker != NULL) delete_ghost = true;
int test_bridge = 0; int test_bridge = 0;
if( (bridge & MESH) || (bridge & ESET) || (bridge & CELL) ) throw Impossible; if( (bridge & MESH) || (bridge & ESET) || (bridge & CELL) ) throw Impossible;
...@@ -5091,7 +5095,7 @@ namespace INMOST ...@@ -5091,7 +5095,7 @@ namespace INMOST
if( test_bridge == 0 || test_bridge > 1 ) throw Impossible; if( test_bridge == 0 || test_bridge > 1 ) throw Impossible;
double time; double time;
//RemoveGhost(); //RemoveGhost();
Tag layers_marker = CreateTag("TEMPORARY_LAYERS_MARKER",DATA_INTEGER,CELL,CELL); Tag layers_marker = CreateTag("TEMPORARY_LAYERS_MARKER",DATA_INTEGER,CELL|bridge,CELL|bridge);
Integer(GetHandle(),tag_layers) = layers; Integer(GetHandle(),tag_layers) = layers;
Integer(GetHandle(),tag_bridge) = bridge; Integer(GetHandle(),tag_bridge) = bridge;
Storage::integer_array procs = IntegerArrayDV(GetHandle(),tag_processors); Storage::integer_array procs = IntegerArrayDV(GetHandle(),tag_processors);
......
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