Commit 9924abdb authored by SilverLife's avatar SilverLife
Browse files

Added adaptive_mesh_test for sets.

parent e52e4aa8
......@@ -5,20 +5,24 @@ add_library(AdaptiveMeshLib amesh.cpp amesh.h)
add_executable(AdaptiveMesh main.cpp)
add_executable(AdaptiveMeshCube main_cube.cpp)
add_executable(AdaptiveMeshSphere main_sphere.cpp)
add_executable(AdaptiveMeshTestSet test_set.cpp)
target_link_libraries(AdaptiveMesh inmost AdaptiveMeshLib)
target_link_libraries(AdaptiveMeshCube inmost AdaptiveMeshLib)
target_link_libraries(AdaptiveMeshSphere inmost AdaptiveMeshLib)
target_link_libraries(AdaptiveMeshTestSet inmost AdaptiveMeshLib)
if(USE_MPI)
message("linking AdaptiveMesh with MPI")
target_link_libraries(AdaptiveMesh ${MPI_LIBRARIES})
target_link_libraries(AdaptiveMeshCube ${MPI_LIBRARIES})
target_link_libraries(AdaptiveMeshSphere ${MPI_LIBRARIES})
target_link_libraries(AdaptiveMeshTestSet ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(AdaptiveMesh PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
set_target_properties(AdaptiveMeshCube PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
set_target_properties(AdaptiveMeshSphere PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
set_target_properties(AdaptiveMeshTestSet PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
......@@ -30,4 +34,5 @@ install(TARGETS AdaptiveMeshLib EXPORT inmost-targets
PUBLIC_HEADER DESTINATION include)
install(TARGETS AdaptiveMesh EXPORT inmost-targets RUNTIME DESTINATION bin)
install(TARGETS AdaptiveMeshCube EXPORT inmost-targets RUNTIME DESTINATION bin)
install(TARGETS AdaptiveMeshSphere EXPORT inmost-targets RUNTIME DESTINATION bin)
\ No newline at end of file
install(TARGETS AdaptiveMeshSphere EXPORT inmost-targets RUNTIME DESTINATION bin)
install(TARGETS AdaptiveMeshTestSet EXPORT inmost-targets RUNTIME DESTINATION bin)
......@@ -70,7 +70,7 @@ namespace INMOST
if (p->GetElementType() == FACE) type = "face";
if (p->GetElementType() == EDGE) type = "edge";
if (p->GetElementType() == NODE) type = "node";
ss << type << "-" << p->GlobalID() << " ";
ss << type << "-" << setw(2) << p->GlobalID() << " ";
p++;
}
ss << endl;
......@@ -93,6 +93,24 @@ namespace INMOST
cout << ss.str() << endl;
}
void PrintRefs(ostream& os, Storage::reference_array refs)
{
for(Storage::reference_array::size_type i = 0; i < refs.size(); ++i)
{
string type = "unknw";
if (refs[i].GetElementType() == CELL) type = "cell";
if (refs[i].GetElementType() == FACE) type = "face";
if (refs[i].GetElementType() == EDGE) type = "edge";
if (refs[i].GetElementType() == NODE) type = "node";
os << "(" << type << "," << refs[i]->GlobalID() << ") ";
Storage::real xyz[3] = {0,0,0};
refs[i]->Centroid(xyz);
os << "(" << xyz[0] << "," << xyz[1] << "," << xyz[2] <<")" << endl;
}
}
void AdaptiveMesh::PrintMesh(ostream& os, int cell, int face, int edge, int node)
{
if (cell + face + edge + node == 0) return;
......@@ -103,24 +121,32 @@ namespace INMOST
ss << "Cells: " << NumberOfCells() << endl;
for(Mesh::iteratorCell it = BeginCell(); it != EndCell(); ++it)
{
ss << rank << ": " << it->GlobalID() << " - " ;
ss << rank << ": " << it->GlobalID() << " - " << it->LocalID() << " - ";
if (it->GetStatus() == Element::Shared) ss << "shared";
else if (it->GetStatus() == Element::Ghost) ss << "ghost";
else ss << "none";
Storage::reference_array refs = ref_tag[it->self()];
if (refs.size() > 0) ss << ". Ref: ";
for(Storage::reference_array::size_type i = 0; i < refs.size(); ++i)
/*
ss << " (";
Storage::integer_array arr = it->IntegerArrayDV(tag_processors);
for (int i = 0; i < arr.size(); i++) ss << arr[i] << " ";
ss << ") ";
*/
/*
Storage::reference_array refs = hanging_nodes[it->self()];
if (refs.size() > 0)
{
string type = "unknw";
if (refs[i].GetElementType() == CELL) type = "cell";
if (refs[i].GetElementType() == FACE) type = "face";
if (refs[i].GetElementType() == EDGE) type = "edge";
if (refs[i].GetElementType() == NODE) type = "node";
ss << "(" << type << "," << refs[i]->GlobalID() << ") ";
ss << endl << " Hanging nodes: ";
PrintRefs(ss,refs);
}
ss << endl;
ss << " ParentSet: " << ElementSet(this,parent_set[*it]).GetName();
*/
/*
orage::reference_array refs = ref_tag[it->self()];
PrintRefs(refs);
*/
ss << endl;
}
}
......@@ -147,6 +173,16 @@ namespace INMOST
}
ss << endl;
{
Storage::reference_array refs = hanging_nodes[it->self()];
if (refs.size() > 0)
{
ss << endl << " Hanging nodes: ";
PrintRefs(ss,refs);
}
ss << endl;
}
}
}
......@@ -256,6 +292,19 @@ namespace INMOST
}
void AdaptiveMesh::SynchronizeSet(ElementSet set)
{
#ifdef USE_MPI
int size = GetProcessorsNumber();
int rank = GetProcessorRank();
for (int i = 0; i < size; i++)
{
set.IntegerArray(tag_sendto).push_back(i);
ExchangeMarked();
}
#endif
}
void AdaptiveMesh::Test()
{
std::cout << rank << ": ================" << endl;
......@@ -595,7 +644,7 @@ namespace INMOST
//11. Restore parallel connectivity, global ids
ResolveShared(true);
//if (call_counter == 0)
// ResolveModification(false,1);
ResolveModification(false,1);
//12. Let the user update their data
//todo: call back function for New() cells
//13. Delete old elements of the mesh
......@@ -684,6 +733,7 @@ namespace INMOST
for(Storage::integer it = 0; it < CellLastLocalID(); ++it) if( isValidCell(it) )
{
Cell c = CellByLocalID(it);
if (!isValidElement(c.GetHandle())) continue;
if( indicator[c] )
{
ElementSet parent(this,parent_set[c]);
......@@ -922,7 +972,7 @@ namespace INMOST
DeleteTag(indicator,FACE|EDGE);
//todo:
ResolveShared(true);
//ResolveModification(false,1);
ResolveModification(false,1);
//todo:
//let the user update their data
ApplyModification();
......
......@@ -9,8 +9,6 @@ namespace INMOST
ElementSet root; //< Root set that links all the other sets for coarsements
TagInteger tag_status;
TagInteger tag_an;
TagReference parent_set; //<Link to the set that contains an element.
TagReferenceArray hanging_nodes; //< Link to current hanging nodes of the cell.
int rank;
int size;
/// Prepare sets for coarsements.
......@@ -18,9 +16,12 @@ namespace INMOST
void PrepareSet();
void PrintSetLocal(std::string offset, ElementSet it, std::stringstream& ss);
public:
TagReference parent_set; //<Link to the set that contains an element.
TagReferenceArray hanging_nodes; //< Link to current hanging nodes of the cell.
TagInteger level; //< Refinement level of the cell
TagReferenceArray ref_tag; //<Link to the set that contains an element.
Storage::integer GetLevel(const Storage & e) {return level[e];}
void SynchronizeSet(ElementSet set);
AdaptiveMesh();
~AdaptiveMesh();
/// Indicator must be 1 on cells to be refined
......
#include "amesh.h"
#include <fstream>
#include <iomanip>
#include <sstream>
using namespace std;
using namespace INMOST;
int rank;
int size;
void add_elem_to_set(AdaptiveMesh& m, ElementSet& set, Element& elem)
{
set.PutElement(elem);
m.parent_set[elem] = set.GetHandle();
}
int main(int argc, char ** argv)
{
Mesh::Initialize(&argc,&argv);
AdaptiveMesh m;
m.Load("grid_for_set.pvtk");
size = m.GetProcessorsNumber();
rank = m.GetProcessorRank();
m.SetCommunicator(MPI_COMM_WORLD);
m.ResolveShared();
m.UpdateStatus();
m.Save("test_sets_begin.pvtk");
m.ResolveModification(false,1);
m.UpdateStatus();
m.Save("test_sets_resolve.pvtk");
ElementSet base;
ElementSet C1;
ElementSet C2;
// Create sets.
base = m.CreateSetUnique("BASE").first;
C1 = m.CreateSetUnique("C1").first;
C2 = m.CreateSetUnique("C2").first;
// Set relations for sets
base.AddChild(C1);
base.AddChild(C2);
// Syncronize status of sets
m.ResolveSets();
// Fill sets
for(Mesh::iteratorCell it = m.BeginCell(); it != m.EndCell(); ++it)
{
int gl = it->GlobalID();
if (rank == 0 && gl == 0 ) add_elem_to_set(m,base,it->self());
if (rank == 1 && gl == 16) add_elem_to_set(m,base,it->self());
if (gl >= 1 && gl <= 8 ) add_elem_to_set(m,C1,it->self());
if (gl >= 9 && gl <= 17 && gl != 16) add_elem_to_set(m,C2,it->self());
}
// PrintSets
m.PrintSet();
// Print Mesh cells to beforeSync_rank file
{
stringstream ss;
ss << "beforeSync_" << rank;
ofstream ofs(ss.str().c_str());
m.PrintMesh(ofs,1,0,0,0);
}
// Synchronize sets.
m.SynchronizeSet(C1); // C1 = C1 (on 0 rank) union C1 (on 1 rank)
m.SynchronizeSet(C2);
// Print Mesh cells to afterSync_rank file
{
stringstream ss;
ss << "afterSync_" << rank;
ofstream ofs(ss.str().c_str());
m.PrintMesh(ofs,1,0,0,0);
}
// PrintSets
m.PrintSet();
m.UpdateStatus();
m.Save("after_set_sync.pvtk");
Mesh::Finalize();
return 0;
}
......@@ -1653,7 +1653,6 @@ namespace INMOST
while (!cells_queue.empty())
{
cout << "Queue size: " << cells_queue.size() << endl;
Cell c = cells_queue.front();
cells_queue.pop();
......
......@@ -2421,6 +2421,7 @@ namespace INMOST
}
else
{
int rank = GetProcessorRank();
for(eit = elements[i].begin(); eit != elements[i].end(); eit++) if( !select || GetMarker(*eit,select) )
{
// REPORT_STR("element type " << ElementTypeName(*eit) << " global id " << Integer(*eit,GlobalIDTag()));
......@@ -2439,13 +2440,16 @@ namespace INMOST
array_data_send.resize(had_s+GetDataCapacity(*eit,tag));
if (tag.GetDataType() == DATA_REFERENCE)
{
//cout << "Element: " << Element(this,*eit).GlobalID() << endl;
reference_array refs = ReferenceArray(*eit, tag);
cout << "Size: " << refs.size() << endl;
int bytes = tag.GetBytesSize();
for(Storage::reference_array::size_type i = 0; i < refs.size(); ++i)
{
if (refs[i] == InvalidElement()) continue;
HandleType data = ComposeHandle(refs[i]->GetElementType(), refs[i]->GlobalID());
memcpy(&array_data_send[had_s+i*bytes],&data,sizeof(HandleType));
cout << ro() << rank << ": Pack elem " << refs[i]->GlobalID() << endl;
}
}
else
......@@ -2765,12 +2769,15 @@ namespace INMOST
{
for(p = procs.begin(); p != procs.end(); p++ )
{
if (from.find(*p) == from.end()) continue;
const elements_by_type& elements = from.find(*p)->second;
for(int i = ElementNum(NODE); i <= ElementNum(ESET); i++) if( (mask & ElementTypeFromDim(i)) && tags[k].isDefinedByDim(i) )
{
for (int j = 0; j < elements[i].size(); j++)
{
if (!isValidHandleRange(elements[i][j])) continue;
//if (!isValidElement(ElementTypeFromDim(i),elements[i][j])) continue;
//cout << GlobalID(elements[i][j]) << " <-=-" << endl;
reference_array refs = ReferenceArray(elements[i][j], tags[k]);
if (refs.size() == 0) continue;
if (tags[k] == HighConnTag())
......@@ -3109,6 +3116,7 @@ namespace INMOST
MarkerType busy = CreateMarker();
// Recursevely looking for all high connections for ESETs
// At now parent set are't include !!
for(element_set::iterator it = selems[4].begin(); it != selems[4].end(); ++it) SetMarker(*it,busy);
int ind = 0;
while (ind < selems[4].size())
......@@ -3117,6 +3125,7 @@ namespace INMOST
// looking to child, sibling and parent
for (int i = 0; i <= 2; i++)
{
if (i == 2) continue;
ElementSet _set;
switch (i)
{
......@@ -3490,10 +3499,12 @@ namespace INMOST
/////////////////////////////////////////
// pack esets
// For now parent set are't pack.
//if( false )
{
std::vector<INMOST_DATA_ENUM_TYPE> low_conn_size(selems[4].size());
std::vector<INMOST_DATA_ENUM_TYPE> high_conn_size(selems[4].size()); // TODO - 3
cout << "@@@ size" << selems[4].size() << endl;
std::vector<Storage::integer> low_conn_nums; // array composed elements : ElementType and position in array
std::vector<int> high_conn_nums(selems[4].size() * 3); // array of indexes of children, sibling, parent. -1 if has't
INMOST_DATA_ENUM_TYPE num_high = 0;
......@@ -3543,7 +3554,9 @@ namespace INMOST
if (set.HaveChild()) high_conn_nums[k*3+0] = Integer(selems[4][Integer(set.GetChild().GetHandle(), arr_position)],arr_position); else high_conn_nums[k*3 + 0] = -1;
if (set.HaveSibling()) high_conn_nums[k*3+1] = Integer(selems[4][Integer(set.GetSibling().GetHandle(),arr_position)],arr_position); else high_conn_nums[k*3 + 1] = -1;
if (set.HaveParent()) high_conn_nums[k*3+2] = Integer(selems[4][Integer(set.GetParent().GetHandle(), arr_position)],arr_position); else high_conn_nums[k*3 + 2] = -1;
// Parent set are't pack now.!!
if (0 && set.HaveParent()) high_conn_nums[k*3+2] = Integer(selems[4][Integer(set.GetParent().GetHandle(), arr_position)],arr_position); else high_conn_nums[k*3 + 2] = -1;
stringstream ss5;
ss5 << ro() << mpirank << ": high_conn_nums for set " << set.GetName() << ": ";
......@@ -4168,7 +4181,7 @@ namespace INMOST
ss1 << "(" << type << "," << array_pos << ") ";
ElementSet set(this, selems[4][i]);
set.PutElement(elem);
set.AddElement(elem);
ind++;
}
......@@ -4191,8 +4204,25 @@ namespace INMOST
}
//cout << ss6.str() << endl;
for (int i = 0; i < num; i++) if (high_conn_nums[i*3+0] != -1) ElementSet(this,selems[4][i]).AddChild(ElementSet(this,selems[4][high_conn_nums[i*3+0]]));
for (int i = 0; i < num; i++) if (high_conn_nums[i*3+1] != -1) ElementSet(this,selems[4][i]).AddSibling(ElementSet(this,selems[4][high_conn_nums[i*3+1]]));
for (int i = 0; i < num; i++) if (high_conn_nums[i*3+0] != -1)
{
ElementSet par_set = ElementSet(this,selems[4][i]);
ElementSet chd_set = ElementSet(this,selems[4][high_conn_nums[i*3+0]]);
bool chld_exist = false;
for(ElementSet it = par_set->GetChild(); it->isValid(); it = it->GetSibling())
{
if (chd_set == it->getAsSet()) { chld_exist = true; break; }
}
if (!chld_exist) par_set.AddChild(chd_set);
}
for (int i = 0; i < num; i++) if (high_conn_nums[i*3+1] != -1)
{
ElementSet set = ElementSet(this,selems[4][i]);
if (!set->HaveSibling()) set.AddSibling(ElementSet(this,selems[4][high_conn_nums[i*3+1]]));
}
}
}
/////////////////////////////////////////////////////////////
......
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