-// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMDS : implementation of Salome mesh data structure
#endif
// number of added entities to check memory after
-#define CHECKMEMORY_INTERVAL 1000
+#define CHECKMEMORY_INTERVAL 100000
vector<SMDS_Mesh*> SMDS_Mesh::_meshList = vector<SMDS_Mesh*>();
int SMDS_Mesh::chunkSize = 1024;
if ( err )
return -1;
+ const unsigned long Mbyte = 1024 * 1024;
+
static int limit = -1;
if ( limit < 0 ) {
int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM
if (status >= 0 ) {
limit = WEXITSTATUS(status);
}
+ else {
+ double factor = ( si.totalswap == 0 ) ? 0.1 : 0.2;
+ limit = int(( factor * si.totalram * si.mem_unit ) / Mbyte );
+ }
if ( limit < 20 )
limit = 20;
else
- limit = int( limit * 1.5 );
-#ifdef _DEBUG_
+ limit = int ( limit * 1.5 );
MESSAGE ( "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" );
-#endif
}
- const unsigned long Mbyte = 1024 * 1024;
// compute separately to avoid overflow
int freeMb =
( si.freeram * si.mem_unit ) / Mbyte +
( si.freeswap * si.mem_unit ) / Mbyte;
+ //cout << "freeMb = " << freeMb << " limit = " << limit << endl;
if ( freeMb > limit )
return freeMb - limit;
if ( doNotRaise )
return 0;
-#ifdef _DEBUG_
+
MESSAGE ("SMDS_Mesh::CheckMemory() throws as free memory too low: " << freeMb <<" MB" );
-#endif
throw std::bad_alloc();
#else
return -1;
// find the MeshNode corresponding to ID
const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
if(!node){
- // TODO ID < 1
- if (ID <= 0)
+ if (ID < 1)
{
MESSAGE("=============> Bad Node Id: " << ID);
ID = myNodeIDFactory->GetFreeID();
SMDS_MeshNode * node = myNodePool->getNew();
node->init(ID, myMeshId, 0, x, y, z);
- //rnv: Set SMDS_SpacePosition for node if need
- if( node->GetPosition()->GetTypeOfPosition() != SMDS_TOP_3DSPACE)
- node->SetPosition(SMDS_SpacePosition::originSpacePosition());
-
if (ID >= myNodes.size())
{
myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
- MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
+// MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
}
myNodes[ID] = node;
myNodeIDFactory->BindID(ID,node);
{
if (!n) return 0;
- //if (my0DElements.Extent() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
+ if (Nb0DElements() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
//MESSAGE("Add0DElementWithID" << ID)
SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
if (myElementIDFactory->BindID(ID, el0d)) {
return NULL;
if ( !e1 || !e2 || !e3 ) return 0;
- //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
MESSAGE("AddFaceWithID" << ID);
SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
return NULL;
MESSAGE("AddFaceWithID" << ID);
if ( !e1 || !e2 || !e3 || !e4 ) return 0;
- //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
adjustmyCellsCapacity(ID);
myCells[ID] = face;
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume* volume = 0;
if ( !n1 || !n2 || !n3 || !n4) return volume;
- //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionFaces()) {
SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume* volume = 0;
if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
- //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionFaces()) {
SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume* volume = 0;
if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
- //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionFaces()) {
SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume* volume = 0;
if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6 || !n7 || !n8) return volume;
- //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionFaces()) {
SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
SMDS_MeshFace * f2=FindFaceOrCreate(n5,n6,n7,n8);
if (!hasConstructionFaces())
return NULL;
if ( !f1 || !f2 || !f3 || !f4) return 0;
- //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4);
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
if (!hasConstructionFaces())
return NULL;
if ( !f1 || !f2 || !f3 || !f4 || !f5) return 0;
- //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
if (!hasConstructionFaces())
return NULL;
if ( !f1 || !f2 || !f3 || !f4 || !f5 || !f6) return 0;
- //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
SMDS_MeshVolume * volume = new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5,f6);
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
{
SMDS_MeshFace * face;
- //if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if (hasConstructionEdges())
{
MESSAGE("Error : Not implemented");
const int ID)
{
SMDS_MeshVolume* volume;
- //if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if (hasConstructionFaces())
{
MESSAGE("Error : Not implemented");
if (vtkId >= myCellIdVtkToSmds.size()) // --- resize local vector
{
- MESSAGE(" --------------------- resize myCellIdVtkToSmds " << vtkId << " --> " << vtkId + SMDS_Mesh::chunkSize);
+// MESSAGE(" --------------------- resize myCellIdVtkToSmds " << vtkId << " --> " << vtkId + SMDS_Mesh::chunkSize);
myCellIdVtkToSmds.resize(vtkId + SMDS_Mesh::chunkSize, -1);
}
myCellIdVtkToSmds[vtkId] = ID;
{
if (ID < 1 || ID >= myNodes.size())
{
- MESSAGE("------------------------------------------------------------------------- ");
- MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size());
- MESSAGE("------------------------------------------------------------------------- ");
+// MESSAGE("------------------------------------------------------------------------- ");
+// MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size());
+// MESSAGE("------------------------------------------------------------------------- ");
return 0;
}
return (const SMDS_MeshNode *)myNodes[ID];
int ID)
{
if ( !node1 || !node2 || !node3) return 0;
-// if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionEdges())
{
SMDS_MeshEdge *edge1, *edge2, *edge3;
int ID)
{
if ( !node1 || !node2 || !node3 || !node4 ) return 0;
-// if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionEdges())
{
//MESSAGE("createQuadrangle hasConstructionEdges "<< ID);
SMDS_MeshEdge * toReturn=NULL;
toReturn=const_cast<SMDS_MeshEdge*>(FindEdge(node1,node2));
if(toReturn==NULL) {
- //if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
+ if ( NbEdges() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
adjustmyCellsCapacity(ID);
vector<vtkIdType> nodeIds;
///////////////////////////////////////////////////////////////////////////////
int SMDS_Mesh::NbNodes() const
{
- //MESSAGE(myGrid->GetNumberOfPoints());
- //MESSAGE(myInfo.NbNodes());
- //MESSAGE(myNodeMax);
+ //MESSAGE(myGrid->GetNumberOfPoints());
+ //MESSAGE(myInfo.NbNodes());
+ //MESSAGE(myNodeMax);
return myInfo.NbNodes();
}
while (itn->more())
{
const SMDS_MeshNode *node = itn->next();
+ ((SMDS_MeshNode*)node)->SetPosition(SMDS_SpacePosition::originSpacePosition());
myNodeIDFactory->ReleaseID(node->GetID(), node->getVtkId());
}
}
while (itn->more())
{
SMDS_MeshNode *node = (SMDS_MeshNode*)(itn->next());
+ node->SetPosition(SMDS_SpacePosition::originSpacePosition());
myNodePool->destroy(node);
}
myNodes.clear();
// rnv: to fix bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
// using double type for storing coordinates of nodes instead float.
points->SetDataType(VTK_DOUBLE);
- points->SetNumberOfPoints(SMDS_Mesh::chunkSize);
+ points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
myGrid->SetPoints( points );
points->Delete();
myGrid->BuildLinks();
i++;
}
set<const SMDS_MeshElement*> *retSet=intersectionOfSets(initSet, numberOfSets);
- MESSAGE("nb elems " << i << " intersection " << retSet->size());
+// MESSAGE("nb elems " << i << " intersection " << retSet->size());
delete [] initSet;
return retSet;
}
myNodeIDFactory->ReleaseID((*it)->GetID(), (*it)->getVtkId());
removedNodes.push_back((*it));
if (const SMDS_MeshNode* vtkElem = dynamic_cast<const SMDS_MeshNode*>(*it))
+ {
+ ((SMDS_MeshNode*)vtkElem)->SetPosition(SMDS_SpacePosition::originSpacePosition());
myNodePool->destroy((SMDS_MeshNode*) vtkElem);
+ }
else
delete (*it);
it++;
if (!itFe->more()) { // free node
myNodes[elemId] = 0;
myInfo.myNbNodes--;
+ ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition());
myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
myNodeIDFactory->ReleaseID(elemId, vtkId);
}
myInfo.myNbQuadEdges++;
// if (!registerElement(ID, edge)) {
-// RemoveElement(edge, false);
-// edge = NULL;
+// RemoveElement(edge, false);
+// edge = NULL;
// }
return edge;
if ( !n1 || !n2 || !n3 || !n4 || !n12 || !n23 || !n34 || !n41) return 0;
if(hasConstructionEdges()) {
// creation quadratic edges - not implemented
- return 0;
+ return 0;
}
else
{
myNodeMin = 0;
if (myNodes.size() == 0)
{
- myNodeMax=0;
- return;
+ myNodeMax=0;
+ return;
}
while (!myNodes[myNodeMin] && (myNodeMin<myNodes.size()))
myNodeMin++;
void SMDS_Mesh::dumpGrid(string ficdump)
{
- MESSAGE("SMDS_Mesh::dumpGrid " << ficdump);
+ MESSAGE("SMDS_Mesh::dumpGrid " << ficdump);
// vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
// aWriter->SetFileName(ficdump.c_str());
// aWriter->SetInput(myGrid);
ficcon << "-------------------------------- points " << nbPoints << endl;
for (int i=0; i<nbPoints; i++)
{
- ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
+ ficcon << i << " " << *(myGrid->GetPoint(i)) << " " << *(myGrid->GetPoint(i)+1) << " " << " " << *(myGrid->GetPoint(i)+2) << endl;
}
int nbCells = myGrid->GetNumberOfCells();
ficcon << "-------------------------------- cells " << nbCells << endl;
for (int i=0; i<nbCells; i++)
{
-// MESSAGE(i << " " << myGrid->GetCell(i));
-// MESSAGE(" " << myGrid->GetCell(i)->GetCellType());
- ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
- int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
- vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
- for (int j=0; j<nbptcell; j++)
- {
- ficcon << " " << listid->GetId(j);
- }
- ficcon << endl;
+// MESSAGE(i << " " << myGrid->GetCell(i));
+// MESSAGE(" " << myGrid->GetCell(i)->GetCellType());
+ ficcon << i << " - " << myGrid->GetCell(i)->GetCellType() << " -";
+ int nbptcell = myGrid->GetCell(i)->GetNumberOfPoints();
+ vtkIdList *listid = myGrid->GetCell(i)->GetPointIds();
+ for (int j=0; j<nbptcell; j++)
+ {
+ ficcon << " " << listid->GetId(j);
+ }
+ ficcon << endl;
}
ficcon << "-------------------------------- connectivity " << nbPoints << endl;
- vtkCellLinks *links = myGrid->GetCellLinks();
+ vtkCellLinks *links = myGrid->GetCellLinks();
for (int i=0; i<nbPoints; i++)
{
- int ncells = links->GetNcells(i);
- vtkIdType *cells = links->GetCells(i);
- ficcon << i << " - " << ncells << " -";
- for (int j=0; j<ncells; j++)
- {
- ficcon << " " << cells[j];
- }
- ficcon << endl;
+ int ncells = links->GetNcells(i);
+ vtkIdType *cells = links->GetCells(i);
+ ficcon << i << " - " << ncells << " -";
+ for (int j=0; j<ncells; j++)
+ {
+ ficcon << " " << cells[j];
+ }
+ ficcon << endl;
}
ficcon.close();
}
//! get last modification timeStamp
-unsigned long SMDS_Mesh::GetMTime()
+unsigned long SMDS_Mesh::GetMTime() const
{
return this->myModifTime;
}