Commit c9250c29 authored by Kirill Terekhov's avatar Kirill Terekhov
Browse files

sync AdaptiveMesh

different approach to give unique names to sets
parent 03cff674
......@@ -6,6 +6,7 @@
//from inmost
//std::string base64_encode(unsigned char const* buf, unsigned int bufLen);
/*
std::string base64_encode_(unsigned char const* buf, unsigned int bufLen)
{
static const std::string base64_chars =
......@@ -52,6 +53,7 @@
return ret;
}
*/
/// todo:
/// 1. coarsment
/// 2. strategy for faces/edges with faults
......@@ -385,6 +387,7 @@ namespace INMOST
void AdaptiveMesh::ClearData()
{
set_id = m->DeleteTag(set_id);
level = m->DeleteTag(level);
hanging_nodes = m->DeleteTag(hanging_nodes);
parent_set = m->DeleteTag(parent_set);
......@@ -407,6 +410,7 @@ namespace INMOST
root.PutElement(it->self());
parent_set[it->self()] = root.GetHandle();
}
m->Enumerate(CELL,set_id);
}
}
if( !m->HaveGlobalID(CELL) ) m->AssignGlobalID(CELL); //for unique set names
......@@ -419,6 +423,7 @@ namespace INMOST
//create a tag that stores maximal refinement level of each element
level = m->CreateTag("REFINEMENT_LEVEL",DATA_INTEGER,CELL|FACE|EDGE|NODE|ESET,NONE,1);
tag_status = m->CreateTag("TAG_STATUS",DATA_INTEGER,CELL|FACE|EDGE|NODE,NONE,1);
set_id = m->CreateTag("SET_ID",DATA_INTEGER,CELL,NONE,1);
//tag_an = m->CreateTag("TAG_AN",DATA_INTEGER,CELL|FACE|EDGE|NODE,NONE,1);
//ref_tag = m->CreateTag("REF",DATA_REFERENCE,CELL|FACE|EDGE|NODE,NONE);
//create a tag that stores links to all the hanging nodes of the cell
......@@ -470,6 +475,17 @@ namespace INMOST
//initialize tree structure
m->CheckCentroids(__FILE__,__LINE__);
PrepareSet();
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(parent_set,CELL,0);
m->CheckCentroids(__FILE__,__LINE__);
m->ResolveSets();
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(parent_set,CELL,0);
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(hanging_nodes,CELL | FACE,0);
m->CheckCentroids(__FILE__,__LINE__);
CheckParentSet();
int schedule_counter = 1; //indicates order in which refinement will be scheduled
int scheduled = 1; //indicates that at least one element was scheduled on current sweep
......@@ -708,8 +724,12 @@ namespace INMOST
c.Centroid(cnt);
std::stringstream set_name;
//set_name << parent.GetName() << "_C" << c.GlobalID(); //rand may be unsafe
if( parent == root )
set_name << "r" << set_id[c];
else
set_name << parent.GetName() << "c" << set_id[c];
set_name << base64_encode_((unsigned char *)cnt,3*sizeof(double)/sizeof(unsigned char));
/*
ElementSet check_set = m->GetSet(set_name.str());
if( check_set.isValid() )
{
......@@ -720,14 +740,16 @@ namespace INMOST
for(ElementSet::iterator it = check_set.Begin(); it != check_set.End(); ++it)
std::cout << ElementTypeName(it->GetElementType()) << ":" << it->LocalID() << "," << it->GlobalID() << "," << Element::StatusName(c.GetStatus()) << "," << level[*it] << " ";
std::cout << std::endl;
exit(-1);
}
*/
ElementSet cell_set = m->CreateSetUnique(set_name.str()).first;
cell_set->SetExchange(ElementSet::SYNC_ELEMENTS_ALL);
level[cell_set] = level[c]+1;
//set up increased level for the new cells
for(ElementArray<Cell>::size_type kt = 0; kt < new_cells.size(); ++kt)
{
set_id[new_cells[kt]] = kt;
level[new_cells[kt]] = level[c]+1;
cell_set.PutElement(new_cells[kt]);
parent_set[new_cells[kt]] = cell_set.GetHandle();
......@@ -788,6 +810,7 @@ namespace INMOST
//11. Restore parallel connectivity, global ids
/*
{
std::fstream fout;
fout.open("out"+std::to_string(m->GetProcessorRank())+".txt",std::ios::out);
......@@ -807,6 +830,7 @@ namespace INMOST
fout.close();
}
*/
//if (call_counter == 0)
m->ResolveModification();
//m->SynchronizeMarker(m->NewMarker(),CELL|FACE|EDGE|NODE,SYNC_BIT_OR);
......@@ -822,6 +846,10 @@ namespace INMOST
//cout << rank << ": Before end " << std::endl;
m->EndModification();
static int fi = 0;
m->Save("refine"+std::to_string(fi)+".pvtk");
std::cout << "Save refine"+std::to_string(fi)+".pvtk" << std::endl;
fi++;
//ExchangeData(hanging_nodes,CELL | FACE,0);
//m->ResolveSets();
......@@ -833,15 +861,7 @@ namespace INMOST
//m->EndModification();
//PrintSet();
//m->ResolveSets();
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(parent_set,CELL,0);
m->CheckCentroids(__FILE__,__LINE__);
m->ResolveSets();
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(parent_set,CELL,0);
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(hanging_nodes,CELL | FACE,0);
m->CheckCentroids(__FILE__,__LINE__);
//restore face orientation
//BUG: bad orientation not fixed automatically
int nfixed = 0;
......@@ -862,8 +882,8 @@ namespace INMOST
std::cout << m->GetProcessorRank() << " parent set is something else " << ElementTypeName(GetHandleElementType(parent_set[*it])) << ":" << GetHandleID(parent_set[*it]) << " on CELL:" << it->LocalID() << " " << Element::StatusName(it->GetStatus()) << std::endl;
}
*/
std::cout << rank << " check parent_set at end" << std::endl;
CheckParentSet();
//std::cout << rank << " check parent_set at end" << std::endl;
//CheckParentSet();
//ExchangeData(hanging_nodes,CELL | FACE,0);
//cout << rank << ": After end " << std::endl;
......@@ -947,6 +967,17 @@ namespace INMOST
int ret = 0;
//initialize tree structure
PrepareSet();
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(parent_set,CELL,0);
m->CheckCentroids(__FILE__,__LINE__);
m->ResolveSets();
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(parent_set,CELL,0);
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(hanging_nodes,CELL | FACE,0);
m->CheckCentroids(__FILE__,__LINE__);
SynchronizeIndicated(indicator);
CheckParentSet();
int schedule_counter = 1; //indicates order in which refinement will be scheduled
......@@ -1257,6 +1288,11 @@ namespace INMOST
m->ApplyModification();
//done
m->EndModification();
static int fi = 0;
m->Save("coarse"+std::to_string(fi)+".pvtk");
std::cout << "Save coarse"+std::to_string(fi)+".pvtk" << std::endl;
fi++;
//exit(-1);
m->CheckCentroids(__FILE__,__LINE__);
//CheckCentroids();
......@@ -1273,19 +1309,11 @@ namespace INMOST
}
}
//m->ResolveSets();
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(parent_set,CELL,0);
m->CheckCentroids(__FILE__,__LINE__);
m->ResolveSets();
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(parent_set,CELL,0);
m->CheckCentroids(__FILE__,__LINE__);
m->ExchangeData(hanging_nodes,CELL | FACE,0);
m->CheckCentroids(__FILE__,__LINE__);
//cleanup null links in sets
CleanupSets(root);
CheckParentSet();
//CheckParentSet();
//restore face orientation
......
......@@ -9,7 +9,8 @@ namespace INMOST
Mesh * m;
Model * model;
ElementSet root; //< Root set that links all the other sets for coarsements
TagInteger tag_status;
TagInteger tag_status;
TagInteger set_id;
//TagInteger tag_an;
int rank;
int size;
......
......@@ -159,7 +159,7 @@ int main(int argc, char ** argv)
}
while(numref);
if( false )
if( true )
{
TagInteger tag_owner = m.CreateTag("OWN",DATA_INTEGER,CELL,NONE,1);
TagInteger tag_owner0 = m.GetTag("OWNER_PROCESSOR");
......
......@@ -2052,7 +2052,7 @@ namespace INMOST
{
if( GetProcessorsNumber() == 1 ) return;
ResolveShared(true);
//ExchangeGhost(1,NODE,NewMarker()); //TODO!!!!
// ExchangeGhost(Integer(GetHandle(),tag_layers),Integer(GetHandle(),tag_bridge),NewMarker()); //TODO!!!!
ResolveSets();
}
......@@ -2091,7 +2091,8 @@ namespace INMOST
}
}
*/
RecomputeParallelStorage(ESET|CELL|FACE|EDGE|NODE);
//RecomputeParallelStorage(ESET|CELL|FACE|EDGE|NODE);
//ExchangeGhost(Integer(GetHandle(),tag_layers),Integer(GetHandle(),tag_bridge),NewMarker()); //TODO!!!!
memset(hidden_count,0,sizeof(integer)*6);
memset(hidden_count_zero,0,sizeof(integer)*6);
ReleaseMarker(hide_element);
......@@ -2167,7 +2168,7 @@ namespace INMOST
bool Mesh::Delete(HandleType h)
{
if(!New(h) && Hide(h))
if(/*!New(h) &&*/ Hide(h))
{
//mark all elements that rely on this that they should be deleted
if( GetHandleElementType(h) < CELL )
......
......@@ -231,7 +231,7 @@ namespace INMOST
for(int k = 0; k < CellLastLocalID(); k++) if( isValidCell(k) )
{
Cell c = CellByLocalID(k);
if (c.GetStatus() != Element::Owned)
if (!c.Hidden() && c.GetStatus() != Element::Owned)
{
tag[c][1] = INT_MAX;
ElementArray<Cell> cells = c.NeighbouringCells();
......@@ -264,16 +264,50 @@ namespace INMOST
}
ReduceData(tag, CELL, 0, OperationMinDistance);
ExchangeData(tag, CELL, 0);
for(Mesh::iteratorCell it = BeginCell(); it != EndCell(); it++) if( it->GetStatus() != Element::Owned )
for(int k = 0; k < CellLastLocalID(); k++) if( isValidCell(k) )
{
//if ( !only_new || it->nbAdjElements(NODE | EDGE | FACE | CELL, NewMarker()) != 0)
Cell c = CellByLocalID(k);
if( !c.Hidden() && c.GetStatus() != Element::Owned )
{
int new_owner = tag[*it][0];
it->IntegerDF(tag_owner) = new_owner;
if (GetProcessorRank() == new_owner)
it->SetStatus(Element::Shared);
else
it->SetStatus(Element::Ghost);
//if ( !only_new || it->nbAdjElements(NODE | EDGE | FACE | CELL, NewMarker()) != 0)
if( !only_new || c.nbAdjElements(NODE | EDGE | FACE | CELL, NewMarker()) )
{
int new_owner = tag[c][0];
c.IntegerDF(tag_owner) = new_owner;
if (GetProcessorRank() == new_owner)
c.SetStatus(Element::Shared);
else
c.SetStatus(Element::Ghost);
}
}
}
for(ElementType etype = FACE; etype >= NODE; etype = PrevElementType(etype))
{
for(int k = 0; k < LastLocalID(etype); k++) if( isValidElement(etype,k) )
{
Element e = ElementByLocalID(etype,k);
if( !e.Hidden() && e.GetStatus() != Element::Owned )
{
if( !only_new || e.nbAdjElements(NODE | EDGE | FACE | CELL,NewMarker()) )
{
Element::adj_type & hc = HighConn(e.GetHandle());
int new_owner = INT_MAX;
for(int l = 0; l < hc.size(); ++l)
{
if( !GetMarker(hc[l],HideMarker()) )
new_owner = std::min(new_owner,Integer(hc[l],tag_owner));
}
if( new_owner != INT_MAX &&
e.IntegerDF(tag_owner) != new_owner )
{
e.IntegerDF(tag_owner) = new_owner;
if (GetProcessorRank() == new_owner)
e.SetStatus(Element::Shared);
else
e.SetStatus(Element::Ghost);
}
}
}
}
}
#endif
......@@ -1953,7 +1987,8 @@ namespace INMOST
}
del_shared.clear();
#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();
}
DeleteTag(tag_delete);
......@@ -5040,8 +5075,9 @@ namespace INMOST
for(int j = ElementNum(CELL); j >= ElementNum(NODE); j--)
{
//this is not really needed because we destroy those elements
//for(element_set::iterator kt = delete_elements[j].begin(); kt != delete_elements[j].end(); ++kt) RemMarker(*kt,delete_marker);
for(element_set::iterator kt = delete_elements[j].begin(); kt != delete_elements[j].end(); ++kt) Destroy(*kt);
for(element_set::iterator kt = delete_elements[j].begin(); kt != delete_elements[j].end(); ++kt) RemMarker(*kt,delete_marker);
//for(element_set::iterator kt = delete_elements[j].begin(); kt != delete_elements[j].end(); ++kt) Destroy(*kt);
for(element_set::iterator kt = delete_elements[j].begin(); kt != delete_elements[j].end(); ++kt) Delete(*kt);
}
ReleaseMarker(delete_marker);
}
......@@ -5054,7 +5090,8 @@ namespace INMOST
Storage::integer_array procs = it->IntegerArray(tag_new_processors);
if( !std::binary_search(procs.begin(),procs.end(),mpirank) )
{
Destroy(*it);
//Destroy(*it);
Delete(*it);
++count;
}
}
......@@ -5298,7 +5335,8 @@ namespace INMOST
//cout << "Check " << layers << " " << Integer(GetHandle(),tag_layers) << endl;
if( layers < Integer(GetHandle(),tag_layers) ) delete_ghost = true;
else if( layers == Integer(GetHandle(),tag_layers) && bridge < Integer(GetHandle(),tag_bridge) ) delete_ghost = true;
if (marker != 0) delete_ghost = true;
if (marker != 0)
delete_ghost = true;
int test_bridge = 0;
if( (bridge & MESH) || (bridge & ESET) || (bridge & CELL) ) throw Impossible;
......
......@@ -41,10 +41,11 @@ mpiexec -np 2 lldb -s lldb.in ./AdaptiveMesh grid.vtk
9) PackElementsData / UnpackElementsData - don't pack elements that are already present on remote processor
10) EquilibrateGhost - mark and synchronize marker with only_new
10.1) Do we need the same in ResolveShared?
11) add cell_set_id to create new sets with same short name instead of base64_encode
11) (ok) add cell_set_id to create new sets with same short name instead of base64_encode
12) check MFD-F scalability on cluster
13) ResolveShared same_boxes - add whole mesh centroid comparison!
14) AdaptiveMesh - second parent_set update in Coarse
15) ResolveModification - ExchangeGhost - use marker for deleted new elements
Изменение сетки:
0) (готово) избавиться от получения ссылок на первый элемент массивов, заменить на data()
......
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