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
/// 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;
/// 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.
/// Call Mesh::ExchangeMarked to perform the exchange.
void SendTo (std::set<Storage::integer> & procs) const;
......@@ -3292,7 +3292,7 @@ namespace INMOST
void MarkNormalOrientation(MarkerType mrk);
//implemented in modify.cpp
private:
MarkerType hide_element, new_element, temp_hide_element;
MarkerType hide_element, new_element, update_geometry, temp_hide_element;
public:
/// Check whether code runs between Mesh::BeginModification, Mesh::EndModification scope.
/// In case mesh is modified, on element construction Mesh::TieElements will always place elements
......@@ -3301,6 +3301,7 @@ namespace INMOST
bool isMeshModified () const {return new_element != 0;}
MarkerType HideMarker () const {return hide_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 BeginModification (); //allow elements to be hidden
/// After this function any link to deleted element will be replaced by InvalidHandle().
......
......@@ -605,6 +605,8 @@ namespace INMOST
void Mesh::RecomputeGeometricData(HandleType e)
{
if (GetMarker(e, UpdateGeometryMarker())) //prevent recursive entry
RemMarker(e, UpdateGeometryMarker());
//static std::map<Element *, int> numfixes;
GeometricData d ;
for(d = CENTROID; d <= NORMAL; d++) // first compute centroids and normals
......@@ -1113,6 +1115,7 @@ namespace INMOST
case MEASURE:
if( HaveGeometricData(MEASURE,etype) )
{
if (UpdateGeometryMarker() && GetMarker(e, UpdateGeometryMarker())) RecomputeGeometricData(e);
*ret = static_cast<Storage::real *>(MGetDenseLink(e,measure_tag))[0];
//~ if( isnan(*ret) || fabs(*ret) < 1e-15 ) throw -1;
}
......@@ -1257,6 +1260,7 @@ namespace INMOST
faces.RemPrivateMarker(rev);
ReleasePrivateMarker(rev);
}
assert(vol > 0);
*ret = vol;
break;
}
......@@ -1269,6 +1273,7 @@ namespace INMOST
memcpy(ret,MGetDenseLink(e,CoordsTag()),sizeof(real)*mdim);
else if(HaveGeometricData(CENTROID,etype))
{
if (UpdateGeometryMarker() && GetMarker(e, UpdateGeometryMarker())) RecomputeGeometricData(e);
memcpy(ret,MGetDenseLink(e,centroid_tag),sizeof(real)*mdim);
}
else
......@@ -1289,6 +1294,7 @@ namespace INMOST
memcpy(ret,MGetDenseLink(e,CoordsTag()),sizeof(real)*mdim);
else if(HaveGeometricData(BARYCENTER,etype))
{
if (UpdateGeometryMarker() && GetMarker(e, UpdateGeometryMarker())) RecomputeGeometricData(e);
memcpy(ret,MGetDenseLink(e,barycenter_tag),sizeof(real)*mdim);
}
else
......@@ -1452,6 +1458,7 @@ namespace INMOST
{
if( HaveGeometricData(NORMAL,etype) )
{
if (UpdateGeometryMarker() && GetMarker(e, UpdateGeometryMarker())) RecomputeGeometricData(e);
memcpy(ret,MGetDenseLink(e,normal_tag),sizeof(real)*mdim);
}
else
......
......@@ -176,7 +176,7 @@ namespace INMOST
Storage::real compute_measure(ElementArray<T> & data)
{
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);
measure += tmp;
......
......@@ -194,7 +194,7 @@ namespace INMOST
//have_global_id = NONE;
checkset = DEFAULT_CHECK;
errorset = 0;
new_element = hide_element = 0;
new_element = hide_element = update_geometry = 0;
memset(hidden_count,0,sizeof(integer)*6);
memset(hidden_count_zero,0,sizeof(integer)*6);
......@@ -453,6 +453,7 @@ namespace INMOST
errorset = other.errorset;
new_element = other.new_element;
hide_element = other.hide_element;
update_geometry = other.update_geometry;
epsilon = other.epsilon;
//have_global_id = other.have_global_id;
// copy communicator
......@@ -582,6 +583,7 @@ namespace INMOST
errorset = other.errorset;
new_element = other.new_element;
hide_element = other.hide_element;
update_geometry = other.update_geometry;
epsilon = other.epsilon;
//have_global_id = other.have_global_id;
// copy communicator
......@@ -1283,7 +1285,9 @@ namespace INMOST
//DEBUG END
ComputeGeometricType(he);
SetMarker(he,NewMarker());
RecomputeGeometricData(he);
if (UpdateGeometryMarker())
SetMarker(he, UpdateGeometryMarker());
else RecomputeGeometricData(he);
EndTopologyCheck(he,chk);
/*
chk |= EndTopologyCheck(he);
......@@ -1382,7 +1386,9 @@ namespace INMOST
//DEBUG END
ComputeGeometricType(he);
SetMarker(he,NewMarker());
RecomputeGeometricData(he);
if (UpdateGeometryMarker())
SetMarker(he, UpdateGeometryMarker());
else RecomputeGeometricData(he);
EndTopologyCheck(he,chk);
/*
chk |= EndTopologyCheck(he);
......@@ -1827,7 +1833,9 @@ namespace INMOST
lc.insert(lc.begin(),c_faces.begin(),c_faces.end());
ComputeGeometricType(he);
SetMarker(he,NewMarker());
RecomputeGeometricData(he);
if (UpdateGeometryMarker())
SetMarker(he, UpdateGeometryMarker());
else RecomputeGeometricData(he);
EndTopologyCheck(he,chk);
}
return std::make_pair(Cell(this,he),true);
......
......@@ -598,7 +598,9 @@ namespace INMOST
m->ComputeGeometricType(cells[it]);
assert(m->GetGeometricType(cells[it]) != MultiPolygon);
//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);
}
......@@ -859,7 +861,9 @@ namespace INMOST
lc.insert(lc.begin()+insert_pos[k],e->GetHandle());
ehc.push_back(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);
}
......@@ -867,7 +871,9 @@ namespace INMOST
{
m->ComputeGeometricType(cells[it]);
//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);
}
return e;
......@@ -1221,7 +1227,9 @@ namespace INMOST
else
lc.insert(lc.begin()+insert_pos[it],ret.rbegin(),ret.rend());
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);
//Face(m,faces[it]).FixEdgeOrder();
}
......@@ -1235,7 +1243,9 @@ namespace INMOST
for(size_t it = 0; it < cells.size(); ++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);
}
return ret;
......@@ -1420,7 +1430,9 @@ namespace INMOST
adj_type & lc = m->LowConn(cells[it]); //cell faces
lc.insert(lc.end(),ret.begin(),ret.end());
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);
}
......@@ -1514,6 +1526,7 @@ namespace INMOST
ENTER_FUNC();
hide_element = CreateMarker();
new_element = CreateMarker();
update_geometry = 0;// CreateMarker();
EXIT_FUNC();
}
......@@ -1529,14 +1542,14 @@ namespace INMOST
memcpy(hidden_count,hidden_count_zero,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(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(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);
RecomputeGeometricData(h);
......@@ -1658,6 +1671,30 @@ namespace INMOST
it->second[i].resize(k);
}
#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();
//Destroy(erase);//old approach
EXIT_FUNC();
......@@ -1926,10 +1963,10 @@ namespace INMOST
return ret;
}
void Element::UpdateGeometricData() const
{
GetMeshLink()->RecomputeGeometricData(GetHandle());
}
//void Element::UpdateGeometricData() const
//{
// GetMeshLink()->RecomputeGeometricData(GetHandle());
//}
void Cell::SwapBackCell() const
{
......@@ -1953,8 +1990,13 @@ namespace INMOST
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.resize(1); //just remove element, we will do this anyway later
if( m->HaveGeometricData(ORIENTATION,FACE) )
Face(m,lc[it])->FixNormalOrientation(false); //restore orientation
if (m->HaveGeometricData(ORIENTATION, FACE))
{
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() )
......@@ -2089,7 +2131,9 @@ namespace INMOST
}
}
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);
}
}
......@@ -2141,7 +2185,9 @@ namespace INMOST
}
}
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
//should be also modified, start from lowest elements in ierarchy and go up
for (ElementType etype = NODE; etype <= CELL; etype = NextElementType(etype))
......@@ -2164,7 +2210,9 @@ namespace INMOST
}
}
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);
}
}
......
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