Commit 3231377a authored by Kirill Terekhov's avatar Kirill Terekhov

Delay geometric data recalculation during modification (currently disabled)

parent a3db81b4
...@@ -486,7 +486,7 @@ namespace INMOST ...@@ -486,7 +486,7 @@ namespace INMOST
/// 3. Should correctly account for order of edges (may be implemented through CheckEdgeOrder, FixEdgeOrder). /// 3. Should correctly account for order of edges (may be implemented through CheckEdgeOrder, FixEdgeOrder).
void Connect (const HandleType * adjacent, INMOST_DATA_ENUM_TYPE num) const; void Connect (const HandleType * adjacent, INMOST_DATA_ENUM_TYPE num) const;
/// Update geometric data for element, calls RecomputeGeometricData from Mesh. /// Update geometric data for element, calls RecomputeGeometricData from Mesh.
void UpdateGeometricData () const; //void UpdateGeometricData () const;
/// Marks element to be sent to remote processors that current processor don't belong to. /// Marks element to be sent to remote processors that current processor don't belong to.
/// Call Mesh::ExchangeMarked to perform the exchange. /// Call Mesh::ExchangeMarked to perform the exchange.
void SendTo (std::set<Storage::integer> & procs) const; void SendTo (std::set<Storage::integer> & procs) const;
...@@ -3292,7 +3292,7 @@ namespace INMOST ...@@ -3292,7 +3292,7 @@ namespace INMOST
void MarkNormalOrientation(MarkerType mrk); void MarkNormalOrientation(MarkerType mrk);
//implemented in modify.cpp //implemented in modify.cpp
private: private:
MarkerType hide_element, new_element, temp_hide_element; MarkerType hide_element, new_element, update_geometry, temp_hide_element;
public: public:
/// Check whether code runs between Mesh::BeginModification, Mesh::EndModification scope. /// Check whether code runs between Mesh::BeginModification, Mesh::EndModification scope.
/// In case mesh is modified, on element construction Mesh::TieElements will always place elements /// In case mesh is modified, on element construction Mesh::TieElements will always place elements
...@@ -3301,6 +3301,7 @@ namespace INMOST ...@@ -3301,6 +3301,7 @@ namespace INMOST
bool isMeshModified () const {return new_element != 0;} bool isMeshModified () const {return new_element != 0;}
MarkerType HideMarker () const {return hide_element;} MarkerType HideMarker () const {return hide_element;}
MarkerType NewMarker () const {return new_element;} MarkerType NewMarker () const {return new_element;}
MarkerType UpdateGeometryMarker() const {return update_geometry;}
void SwapModification (bool recompute_geometry); // swap hidden and new elements, so that old mesh is recovered void SwapModification (bool recompute_geometry); // swap hidden and new elements, so that old mesh is recovered
void BeginModification (); //allow elements to be hidden void BeginModification (); //allow elements to be hidden
/// After this function any link to deleted element will be replaced by InvalidHandle(). /// After this function any link to deleted element will be replaced by InvalidHandle().
......
...@@ -605,6 +605,8 @@ namespace INMOST ...@@ -605,6 +605,8 @@ namespace INMOST
void Mesh::RecomputeGeometricData(HandleType e) void Mesh::RecomputeGeometricData(HandleType e)
{ {
if (GetMarker(e, UpdateGeometryMarker())) //prevent recursive entry
RemMarker(e, UpdateGeometryMarker());
//static std::map<Element *, int> numfixes; //static std::map<Element *, int> numfixes;
GeometricData d ; GeometricData d ;
for(d = CENTROID; d <= NORMAL; d++) // first compute centroids and normals for(d = CENTROID; d <= NORMAL; d++) // first compute centroids and normals
...@@ -1113,6 +1115,7 @@ namespace INMOST ...@@ -1113,6 +1115,7 @@ namespace INMOST
case MEASURE: case MEASURE:
if( HaveGeometricData(MEASURE,etype) ) if( HaveGeometricData(MEASURE,etype) )
{ {
if (UpdateGeometryMarker() && GetMarker(e, UpdateGeometryMarker())) RecomputeGeometricData(e);
*ret = static_cast<Storage::real *>(MGetDenseLink(e,measure_tag))[0]; *ret = static_cast<Storage::real *>(MGetDenseLink(e,measure_tag))[0];
//~ if( isnan(*ret) || fabs(*ret) < 1e-15 ) throw -1; //~ if( isnan(*ret) || fabs(*ret) < 1e-15 ) throw -1;
} }
...@@ -1257,6 +1260,7 @@ namespace INMOST ...@@ -1257,6 +1260,7 @@ namespace INMOST
faces.RemPrivateMarker(rev); faces.RemPrivateMarker(rev);
ReleasePrivateMarker(rev); ReleasePrivateMarker(rev);
} }
assert(vol > 0);
*ret = vol; *ret = vol;
break; break;
} }
...@@ -1269,6 +1273,7 @@ namespace INMOST ...@@ -1269,6 +1273,7 @@ namespace INMOST
memcpy(ret,MGetDenseLink(e,CoordsTag()),sizeof(real)*mdim); memcpy(ret,MGetDenseLink(e,CoordsTag()),sizeof(real)*mdim);
else if(HaveGeometricData(CENTROID,etype)) else if(HaveGeometricData(CENTROID,etype))
{ {
if (UpdateGeometryMarker() && GetMarker(e, UpdateGeometryMarker())) RecomputeGeometricData(e);
memcpy(ret,MGetDenseLink(e,centroid_tag),sizeof(real)*mdim); memcpy(ret,MGetDenseLink(e,centroid_tag),sizeof(real)*mdim);
} }
else else
...@@ -1289,6 +1294,7 @@ namespace INMOST ...@@ -1289,6 +1294,7 @@ namespace INMOST
memcpy(ret,MGetDenseLink(e,CoordsTag()),sizeof(real)*mdim); memcpy(ret,MGetDenseLink(e,CoordsTag()),sizeof(real)*mdim);
else if(HaveGeometricData(BARYCENTER,etype)) else if(HaveGeometricData(BARYCENTER,etype))
{ {
if (UpdateGeometryMarker() && GetMarker(e, UpdateGeometryMarker())) RecomputeGeometricData(e);
memcpy(ret,MGetDenseLink(e,barycenter_tag),sizeof(real)*mdim); memcpy(ret,MGetDenseLink(e,barycenter_tag),sizeof(real)*mdim);
} }
else else
...@@ -1452,6 +1458,7 @@ namespace INMOST ...@@ -1452,6 +1458,7 @@ namespace INMOST
{ {
if( HaveGeometricData(NORMAL,etype) ) if( HaveGeometricData(NORMAL,etype) )
{ {
if (UpdateGeometryMarker() && GetMarker(e, UpdateGeometryMarker())) RecomputeGeometricData(e);
memcpy(ret,MGetDenseLink(e,normal_tag),sizeof(real)*mdim); memcpy(ret,MGetDenseLink(e,normal_tag),sizeof(real)*mdim);
} }
else else
......
...@@ -176,7 +176,7 @@ namespace INMOST ...@@ -176,7 +176,7 @@ namespace INMOST
Storage::real compute_measure(ElementArray<T> & data) Storage::real compute_measure(ElementArray<T> & data)
{ {
Storage::real measure = 0, tmp; Storage::real measure = 0, tmp;
for(typename ElementArray<T>::size_type k = 1; k < data.size(); ++k) for(typename ElementArray<T>::size_type k = 0; k < data.size(); ++k)
{ {
mesh->GetGeometricData(data[k].GetHandle(),MEASURE,&tmp); mesh->GetGeometricData(data[k].GetHandle(),MEASURE,&tmp);
measure += tmp; measure += tmp;
......
...@@ -194,7 +194,7 @@ namespace INMOST ...@@ -194,7 +194,7 @@ namespace INMOST
//have_global_id = NONE; //have_global_id = NONE;
checkset = DEFAULT_CHECK; checkset = DEFAULT_CHECK;
errorset = 0; errorset = 0;
new_element = hide_element = 0; new_element = hide_element = update_geometry = 0;
memset(hidden_count,0,sizeof(integer)*6); memset(hidden_count,0,sizeof(integer)*6);
memset(hidden_count_zero,0,sizeof(integer)*6); memset(hidden_count_zero,0,sizeof(integer)*6);
...@@ -453,6 +453,7 @@ namespace INMOST ...@@ -453,6 +453,7 @@ namespace INMOST
errorset = other.errorset; errorset = other.errorset;
new_element = other.new_element; new_element = other.new_element;
hide_element = other.hide_element; hide_element = other.hide_element;
update_geometry = other.update_geometry;
epsilon = other.epsilon; epsilon = other.epsilon;
//have_global_id = other.have_global_id; //have_global_id = other.have_global_id;
// copy communicator // copy communicator
...@@ -582,6 +583,7 @@ namespace INMOST ...@@ -582,6 +583,7 @@ namespace INMOST
errorset = other.errorset; errorset = other.errorset;
new_element = other.new_element; new_element = other.new_element;
hide_element = other.hide_element; hide_element = other.hide_element;
update_geometry = other.update_geometry;
epsilon = other.epsilon; epsilon = other.epsilon;
//have_global_id = other.have_global_id; //have_global_id = other.have_global_id;
// copy communicator // copy communicator
...@@ -1283,7 +1285,9 @@ namespace INMOST ...@@ -1283,7 +1285,9 @@ namespace INMOST
//DEBUG END //DEBUG END
ComputeGeometricType(he); ComputeGeometricType(he);
SetMarker(he,NewMarker()); SetMarker(he,NewMarker());
RecomputeGeometricData(he); if (UpdateGeometryMarker())
SetMarker(he, UpdateGeometryMarker());
else RecomputeGeometricData(he);
EndTopologyCheck(he,chk); EndTopologyCheck(he,chk);
/* /*
chk |= EndTopologyCheck(he); chk |= EndTopologyCheck(he);
...@@ -1382,7 +1386,9 @@ namespace INMOST ...@@ -1382,7 +1386,9 @@ namespace INMOST
//DEBUG END //DEBUG END
ComputeGeometricType(he); ComputeGeometricType(he);
SetMarker(he,NewMarker()); SetMarker(he,NewMarker());
RecomputeGeometricData(he); if (UpdateGeometryMarker())
SetMarker(he, UpdateGeometryMarker());
else RecomputeGeometricData(he);
EndTopologyCheck(he,chk); EndTopologyCheck(he,chk);
/* /*
chk |= EndTopologyCheck(he); chk |= EndTopologyCheck(he);
...@@ -1827,7 +1833,9 @@ namespace INMOST ...@@ -1827,7 +1833,9 @@ namespace INMOST
lc.insert(lc.begin(),c_faces.begin(),c_faces.end()); lc.insert(lc.begin(),c_faces.begin(),c_faces.end());
ComputeGeometricType(he); ComputeGeometricType(he);
SetMarker(he,NewMarker()); SetMarker(he,NewMarker());
RecomputeGeometricData(he); if (UpdateGeometryMarker())
SetMarker(he, UpdateGeometryMarker());
else RecomputeGeometricData(he);
EndTopologyCheck(he,chk); EndTopologyCheck(he,chk);
} }
return std::make_pair(Cell(this,he),true); return std::make_pair(Cell(this,he),true);
......
...@@ -598,7 +598,9 @@ namespace INMOST ...@@ -598,7 +598,9 @@ namespace INMOST
m->ComputeGeometricType(cells[it]); m->ComputeGeometricType(cells[it]);
assert(m->GetGeometricType(cells[it]) != MultiPolygon); assert(m->GetGeometricType(cells[it]) != MultiPolygon);
//recompute geometric data //recompute geometric data
m->RecomputeGeometricData(cells[it]); if (m->UpdateGeometryMarker())
m->SetMarker(cells[it],m->UpdateGeometryMarker());
else m->RecomputeGeometricData(cells[it]);
m->EndTopologyCheck(cells[it],0); m->EndTopologyCheck(cells[it],0);
} }
...@@ -859,7 +861,9 @@ namespace INMOST ...@@ -859,7 +861,9 @@ namespace INMOST
lc.insert(lc.begin()+insert_pos[k],e->GetHandle()); lc.insert(lc.begin()+insert_pos[k],e->GetHandle());
ehc.push_back(faces[k]); ehc.push_back(faces[k]);
m->ComputeGeometricType(faces[k]); m->ComputeGeometricType(faces[k]);
m->RecomputeGeometricData(faces[k]); if (m->UpdateGeometryMarker())
m->SetMarker(faces[k],m->UpdateGeometryMarker());
else m->RecomputeGeometricData(faces[k]);
m->EndTopologyCheck(faces[k],0); m->EndTopologyCheck(faces[k],0);
} }
...@@ -867,7 +871,9 @@ namespace INMOST ...@@ -867,7 +871,9 @@ namespace INMOST
{ {
m->ComputeGeometricType(cells[it]); m->ComputeGeometricType(cells[it]);
//update centroid, volume, orientation, etc //update centroid, volume, orientation, etc
m->RecomputeGeometricData(cells[it]); if (m->UpdateGeometryMarker())
m->SetMarker(cells[it],m->UpdateGeometryMarker());
else m->RecomputeGeometricData(cells[it]);
m->EndTopologyCheck(cells[it],0); m->EndTopologyCheck(cells[it],0);
} }
return e; return e;
...@@ -1221,7 +1227,9 @@ namespace INMOST ...@@ -1221,7 +1227,9 @@ namespace INMOST
else else
lc.insert(lc.begin()+insert_pos[it],ret.rbegin(),ret.rend()); lc.insert(lc.begin()+insert_pos[it],ret.rbegin(),ret.rend());
m->ComputeGeometricType(faces[it]); m->ComputeGeometricType(faces[it]);
m->RecomputeGeometricData(faces[it]); if (m->UpdateGeometryMarker())
m->SetMarker(faces[it], m->UpdateGeometryMarker());
else m->RecomputeGeometricData(faces[it]);
m->EndTopologyCheck(faces[it],0); m->EndTopologyCheck(faces[it],0);
//Face(m,faces[it]).FixEdgeOrder(); //Face(m,faces[it]).FixEdgeOrder();
} }
...@@ -1235,7 +1243,9 @@ namespace INMOST ...@@ -1235,7 +1243,9 @@ namespace INMOST
for(size_t it = 0; it < cells.size(); ++it) for(size_t it = 0; it < cells.size(); ++it)
{ {
m->ComputeGeometricType(cells[it]); m->ComputeGeometricType(cells[it]);
m->RecomputeGeometricData(cells[it]); if (m->UpdateGeometryMarker())
m->SetMarker(cells[it], m->UpdateGeometryMarker());
else m->RecomputeGeometricData(cells[it]);
m->EndTopologyCheck(cells[it],0); m->EndTopologyCheck(cells[it],0);
} }
return ret; return ret;
...@@ -1420,7 +1430,9 @@ namespace INMOST ...@@ -1420,7 +1430,9 @@ namespace INMOST
adj_type & lc = m->LowConn(cells[it]); //cell faces adj_type & lc = m->LowConn(cells[it]); //cell faces
lc.insert(lc.end(),ret.begin(),ret.end()); lc.insert(lc.end(),ret.begin(),ret.end());
m->ComputeGeometricType(cells[it]); m->ComputeGeometricType(cells[it]);
m->RecomputeGeometricData(cells[it]); if (m->UpdateGeometryMarker())
m->SetMarker(cells[it], m->UpdateGeometryMarker());
else m->RecomputeGeometricData(cells[it]);
m->EndTopologyCheck(cells[it],0); m->EndTopologyCheck(cells[it],0);
} }
...@@ -1514,6 +1526,7 @@ namespace INMOST ...@@ -1514,6 +1526,7 @@ namespace INMOST
ENTER_FUNC(); ENTER_FUNC();
hide_element = CreateMarker(); hide_element = CreateMarker();
new_element = CreateMarker(); new_element = CreateMarker();
update_geometry = 0;// CreateMarker();
EXIT_FUNC(); EXIT_FUNC();
} }
...@@ -1529,14 +1542,14 @@ namespace INMOST ...@@ -1529,14 +1542,14 @@ namespace INMOST
memcpy(hidden_count,hidden_count_zero,sizeof(integer)*6); memcpy(hidden_count,hidden_count_zero,sizeof(integer)*6);
memcpy(hidden_count_zero,tmp,sizeof(integer)*6); memcpy(hidden_count_zero,tmp,sizeof(integer)*6);
if( recompute_geometry ) if( recompute_geometry ) //TODO ????????
{ {
for(ElementType etype = EDGE; etype <= CELL; etype = etype << 1) for(ElementType etype = EDGE; etype <= CELL; etype = etype << 1)
{ {
for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) ) for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) )
{ {
HandleType h = ComposeHandle(etype,it); HandleType h = ComposeHandle(etype,it);
if( GetMarker(h,new_element) ) if( GetMarker(h,NewMarker()) && !GetMarker(h,UpdateGeometryMarker()) ) //element is new and geometry was already recomputed
{ {
ComputeGeometricType(h); ComputeGeometricType(h);
RecomputeGeometricData(h); RecomputeGeometricData(h);
...@@ -1658,6 +1671,30 @@ namespace INMOST ...@@ -1658,6 +1671,30 @@ namespace INMOST
it->second[i].resize(k); it->second[i].resize(k);
} }
#endif #endif
EXIT_BLOCK();
ENTER_BLOCK();
if (UpdateGeometryMarker())
{
for (ElementType etype = EDGE; etype <= CELL; etype = NextElementType(etype))
{
int updated = 0;
#if defined(USE_OMP)
#pragma omp parallel for reduction(+:updated)
#endif
for (integer it = 0; it < LastLocalID(etype); ++it) if (isValidElement(etype, it))
{
Element e = ElementByLocalID(etype, it);
if (e.GetMarker(UpdateGeometryMarker()))
{
updated++;
RecomputeGeometricData(e.GetHandle());
}
}
std::cout << "Geometry updated for " << updated << " element type " << ElementTypeName(etype) << std::endl;
}
ReleaseMarker(UpdateGeometryMarker());
update_geometry = 0;
}
EXIT_BLOCK(); EXIT_BLOCK();
//Destroy(erase);//old approach //Destroy(erase);//old approach
EXIT_FUNC(); EXIT_FUNC();
...@@ -1926,10 +1963,10 @@ namespace INMOST ...@@ -1926,10 +1963,10 @@ namespace INMOST
return ret; return ret;
} }
void Element::UpdateGeometricData() const //void Element::UpdateGeometricData() const
{ //{
GetMeshLink()->RecomputeGeometricData(GetHandle()); // GetMeshLink()->RecomputeGeometricData(GetHandle());
} //}
void Cell::SwapBackCell() const void Cell::SwapBackCell() const
{ {
...@@ -1953,8 +1990,13 @@ namespace INMOST ...@@ -1953,8 +1990,13 @@ namespace INMOST
std::swap(hc[k1],hc[k2]); std::swap(hc[k1],hc[k2]);
//hc[k2] = GetHandle(); //cannot use the cell because virtualization table is already destroyed and FixNormalOrientation will do bad things //hc[k2] = GetHandle(); //cannot use the cell because virtualization table is already destroyed and FixNormalOrientation will do bad things
//hc.resize(1); //just remove element, we will do this anyway later //hc.resize(1); //just remove element, we will do this anyway later
if( m->HaveGeometricData(ORIENTATION,FACE) ) if (m->HaveGeometricData(ORIENTATION, FACE))
Face(m,lc[it])->FixNormalOrientation(false); //restore orientation {
if (!m->UpdateGeometryMarker())
Face(m, lc[it])->FixNormalOrientation(false); //restore orientation
else
m->SetMarker(lc[it], m->UpdateGeometryMarker()); //delay
}
} }
} }
//~ if( !Face(m,lc[it])->CheckNormalOrientation() ) //~ if( !Face(m,lc[it])->CheckNormalOrientation() )
...@@ -2089,7 +2131,9 @@ namespace INMOST ...@@ -2089,7 +2131,9 @@ namespace INMOST
} }
} }
m->ComputeGeometricType(arr[el_num][it]); m->ComputeGeometricType(arr[el_num][it]);
m->RecomputeGeometricData(arr[el_num][it]); if (m->UpdateGeometryMarker())
m->SetMarker(arr[el_num][it],m->UpdateGeometryMarker());
else m->RecomputeGeometricData(arr[el_num][it]);
m->RemMarker(arr[el_num][it],mod); m->RemMarker(arr[el_num][it],mod);
} }
} }
...@@ -2141,7 +2185,9 @@ namespace INMOST ...@@ -2141,7 +2185,9 @@ namespace INMOST
} }
} }
ComputeGeometricType(); ComputeGeometricType();
UpdateGeometricData(); if (m->UpdateGeometryMarker())
m->SetMarker(GetHandle(),m->UpdateGeometryMarker());
else m->RecomputeGeometricData(GetHandle());
//if element placed below on ierarhy was modified, then all upper elements //if element placed below on ierarhy was modified, then all upper elements
//should be also modified, start from lowest elements in ierarchy and go up //should be also modified, start from lowest elements in ierarchy and go up
for (ElementType etype = NODE; etype <= CELL; etype = NextElementType(etype)) for (ElementType etype = NODE; etype <= CELL; etype = NextElementType(etype))
...@@ -2164,7 +2210,9 @@ namespace INMOST ...@@ -2164,7 +2210,9 @@ namespace INMOST
} }
} }
m->ComputeGeometricType(arr[el_num][it]); m->ComputeGeometricType(arr[el_num][it]);
m->RecomputeGeometricData(arr[el_num][it]); if (m->UpdateGeometryMarker())
m->SetMarker(arr[el_num][it],m->UpdateGeometryMarker());
else m->RecomputeGeometricData(arr[el_num][it]);
m->RemMarker(arr[el_num][it], mod); m->RemMarker(arr[el_num][it], mod);
} }
} }
......
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