//=============================================================================
// File : GHS3DPlugin_GHS3D.cxx
// Created :
-// Author : Edward AGAPOV
+// Author : Edward AGAPOV, modified by Lioka RAZAFINDRAZAKA (CEA) 09/02/2007
// Project : SALOME
// Copyright : CEA 2003
// $Header$
#include <sys/sysinfo.h>
#endif
+//#include <Standard_Stream.hxx>
+
+#include <BRepGProp.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepClass_FaceClassifier.hxx>
+#include <BRepClass3d_SolidClassifier.hxx>
+#include <TopAbs.hxx>
+#include <Bnd_Box.hxx>
+#include <GProp_GProps.hxx>
+#include <Precision.hxx>
#ifdef _DEBUG_
#define DUMP(txt) \
#define DUMP(txt)
#endif
+// include for mmap
+#include "HDFconvert.hxx"
+
//=============================================================================
/*!
*
MESSAGE("GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D");
_name = "GHS3D_3D";
_shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
+ _iShape=0;
+ _nbShape=0;
}
//=============================================================================
*/
//=============================================================================
-bool GHS3DPlugin_GHS3D::CheckHypothesis
- (SMESH_Mesh& aMesh,
- const TopoDS_Shape& aShape,
- SMESH_Hypothesis::Hypothesis_Status& aStatus)
+bool GHS3DPlugin_GHS3D::CheckHypothesis ( SMESH_Mesh& aMesh,
+ const TopoDS_Shape& aShape,
+ SMESH_Hypothesis::Hypothesis_Status& aStatus )
{
// MESSAGE("GHS3DPlugin_GHS3D::CheckHypothesis");
aStatus = SMESH_Hypothesis::HYP_OK;
static bool writeFaces (ofstream & theFile,
SMESHDS_Mesh * theMesh,
- const TopoDS_Shape& theShape,
const map <int,int> & theSmdsToGhs3dIdMap)
{
// record structure:
//
// NB_ELEMS DUMMY_INT
// Loop from 1 to NB_ELEMS
- // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
+ // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT
// get all faces bound to theShape
+
int nbFaces = 0;
+ TopoDS_Shape theShape = theMesh->ShapeToMesh();
list< const SMDS_MeshElement* > faces;
TopExp_Explorer fExp( theShape, TopAbs_FACE );
+ SMESHDS_SubMesh* sm;
+ SMDS_ElemIteratorPtr eIt;
+
+ const char* space = " ";
+ const int dummyint = 0;
+
+ list< const SMDS_MeshElement* >::iterator f;
+ map<int,int>::const_iterator it;
+ SMDS_ElemIteratorPtr nodeIt;
+ const SMDS_MeshElement* elem;
+ int nbNodes;
+ int aSmdsID;
+
for ( ; fExp.More(); fExp.Next() ) {
- SMESHDS_SubMesh* sm = theMesh->MeshElements( fExp.Current() );
+ sm = theMesh->MeshElements( fExp.Current() );
if ( sm ) {
- SMDS_ElemIteratorPtr eIt = sm->GetElements();
+ eIt = sm->GetElements();
while ( eIt->more() ) {
faces.push_back( eIt->next() );
nbFaces++;
if ( nbFaces == 0 )
return false;
- const char* space = " ";
- const int dummyint = 0;
+ cout << " " << nbFaces << " triangles" << endl;
+ cout << endl;
// NB_ELEMS DUMMY_INT
theFile << space << nbFaces << space << dummyint << endl;
// Loop from 1 to NB_ELEMS
- list< const SMDS_MeshElement* >::iterator f = faces.begin();
+
+ f = faces.begin();
for ( ; f != faces.end(); ++f )
{
- // NB_NODES
- const SMDS_MeshElement* elem = *f;
- const int nbNodes = elem->NbNodes();
+ // NB_NODES PER FACE
+ elem = *f;
+ nbNodes = elem->NbNodes();
theFile << space << nbNodes;
// NODE_NB_1 NODE_NB_2 ...
- SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
+ nodeIt = elem->nodesIterator();
while ( nodeIt->more() )
{
// find GHS3D ID
- int aSmdsID = nodeIt->next()->GetID();
- map<int,int>::const_iterator it = theSmdsToGhs3dIdMap.find( aSmdsID );
+ aSmdsID = nodeIt->next()->GetID();
+ it = theSmdsToGhs3dIdMap.find( aSmdsID );
ASSERT( it != theSmdsToGhs3dIdMap.end() );
theFile << space << (*it).second;
}
const char* space = " ";
const int dummyint = 0;
+ int aGhs3dID = 1;
+ SMDS_NodeIteratorPtr it = theMesh->nodesIterator();
+ const SMDS_MeshNode* node;
+
// NB_NODES
theFile << space << nbNodes << endl;
+ cout << "The 2D mesh contains :" << endl;
+ cout << " " << nbNodes << " nodes" << endl;
// Loop from 1 to NB_NODES
- int aGhs3dID = 1;
- SMDS_NodeIteratorPtr it = theMesh->nodesIterator();
+
while ( it->more() )
{
- const SMDS_MeshNode* node = it->next();
+ node = it->next();
theSmdsToGhs3dIdMap.insert( map <int,int>::value_type( node->GetID(), aGhs3dID ));
theGhs3dIdToNodeMap.insert (map <int,const SMDS_MeshNode*>::value_type( aGhs3dID, node ));
aGhs3dID++;
}
//=======================================================================
-//function : getInt
+//function : findSolid
//purpose :
//=======================================================================
-static bool getInt( int & theValue, char * & theLine )
-{
- char *ptr;
- theValue = strtol( theLine, &ptr, 10 );
- if ( ptr == theLine ||
- // there must not be neither '.' nor ',' nor 'E' ...
- (*ptr != ' ' && *ptr != '\n' && *ptr != '\0'))
- return false;
-
- DUMP( " " << theValue );
- theLine = ptr;
- return true;
+static TopoDS_Shape findSolid(const SMDS_MeshNode *aNode[],
+ TopoDS_Shape aSolid,
+ const TopoDS_Shape shape[],
+ const double box[][6],
+ const int nShape) {
+
+ Standard_Real PX, PY, PZ;
+ int iShape;
+
+ PX = ( aNode[0]->X() + aNode[1]->X() + aNode[2]->X() + aNode[3]->X() ) / 4.0;
+ PY = ( aNode[0]->Y() + aNode[1]->Y() + aNode[2]->Y() + aNode[3]->Y() ) / 4.0;
+ PZ = ( aNode[0]->Z() + aNode[1]->Z() + aNode[2]->Z() + aNode[3]->Z() ) / 4.0;
+ gp_Pnt aPnt(PX, PY, PZ);
+
+ BRepClass3d_SolidClassifier SC (aSolid, aPnt, Precision::Confusion());
+ if ( not(SC.State() == TopAbs_IN) ) {
+ for (iShape = 0; iShape < nShape; iShape++) {
+ aSolid = shape[iShape];
+ if ( not( PX < box[iShape][0] || box[iShape][1] < PX ||
+ PY < box[iShape][2] || box[iShape][3] < PY ||
+ PZ < box[iShape][4] || box[iShape][5] < PZ) ) {
+ BRepClass3d_SolidClassifier SC (aSolid, aPnt, Precision::Confusion());
+ if (SC.State() == TopAbs_IN)
+ break;
+ }
+ }
+ }
+ return aSolid;
}
//=======================================================================
-//function : getDouble
+//function : readMapIntLine
//purpose :
//=======================================================================
-static bool getDouble( double & theValue, char * & theLine )
-{
- char *ptr;
- theValue = strtod( theLine, &ptr );
- if ( ptr == theLine )
- return false;
-
- DUMP( " " << theValue );
- theLine = ptr;
- return true;
+static char* readMapIntLine(char* ptr, int tab[]) {
+ char* ptrRet = "\n";
+ long int intVal;
+ int i = 1;
+ cout << endl;
+
+ while ( *ptr != *ptrRet ) {
+ intVal = strtol(ptr, &ptr, 10);
+ if ( i < 4 )
+ tab[i-1] = intVal;
+ i++;
+ }
+ return ptr;
}
-
-//=======================================================================
-//function : readLine
-//purpose :
-//=======================================================================
-
-#define GHS3DPlugin_BUFLENGTH 256
-#define GHS3DPlugin_ReadLine(aPtr,aBuf,aFile,aLineNb) \
-{ aPtr = fgets( aBuf, GHS3DPlugin_BUFLENGTH - 2, aFile ); aLineNb++; DUMP(endl); }
//=======================================================================
-//function : readResult
+//function : readResultFile
//purpose :
//=======================================================================
-static bool readResult(FILE * theFile,
- SMESHDS_Mesh * theMesh,
- const TopoDS_Shape& theShape,
- map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap)
-{
- // structure:
-
- // record 1:
- // NB_ELEMENTS NB_NODES NB_INPUT_NODES (14 DUMMY_INT)
- // record 2:
- // (NB_ELEMENTS * 4) node nbs
- // record 3:
- // (NB_NODES) node XYZ
-
- char aBuffer[ GHS3DPlugin_BUFLENGTH ];
- char * aPtr;
- int aLineNb = 0;
- int shapeID = theMesh->ShapeToIndex( theShape );
-
- // ----------------------------------------
- // record 1:
- // read nb of generated elements and nodes
- // ----------------------------------------
- int nbElems = 0 , nbNodes = 0, nbInputNodes = 0;
- GHS3DPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb );
- if (!aPtr ||
- !getInt( nbElems, aPtr ) ||
- !getInt( nbNodes, aPtr ) ||
- !getInt( nbInputNodes, aPtr))
- return false;
+static bool readResultFile(const int fileOpen,
+ SMESHDS_Mesh* theMeshDS,
+ TopoDS_Shape tabShape[],
+ double tabBox[][6],
+ const int nShape,
+ map <int,const SMDS_MeshNode*>& theGhs3dIdToNodeMap) {
- // -------------------------------------------
- // record 2:
- // read element nodes and create tetrahedrons
- // -------------------------------------------
- GHS3DPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb );
- for (int iElem = 0; iElem < nbElems; iElem++)
- {
- // read 4 nodes
- const SMDS_MeshNode * node[4];
- for (int iNode = 0; iNode < 4; iNode++)
- {
- // read Ghs3d node ID
- int ID = 0;
- if (!aPtr || ! getInt ( ID, aPtr ))
- {
- GHS3DPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb );
- if (!aPtr || ! getInt ( ID, aPtr ))
- {
- MESSAGE( "Cant read " << (iNode+1) << "-th node on line " << aLineNb );
- return false;
- }
- }
- // find/create a node with ID
- map <int,const SMDS_MeshNode*>::iterator IdNode = theGhs3dIdToNodeMap.find( ID );
- if ( IdNode == theGhs3dIdToNodeMap.end())
- {
- // ID is not yet in theGhs3dIdToNodeMap
- ASSERT ( ID > nbInputNodes ); // it should be a new one
- SMDS_MeshNode * aNewNode = theMesh->AddNode( 0.,0.,0. ); // read XYZ later
- theMesh->SetNodeInVolume( aNewNode, shapeID );
- theGhs3dIdToNodeMap.insert ( make_pair( ID, aNewNode ));
- node[ iNode ] = aNewNode;
- }
- else
- {
- node[ iNode ] = IdNode->second;
- }
+ struct stat status;
+ size_t length;
+
+ char *ptr;
+ char *tetraPtr;
+ char *shapePtr;
+
+ int fileStat, fileClose;
+ int nbElems, nbNodes, nbInputNodes;
+ int nodeId, triangleId;
+ int tab[3], tabID[nShape];
+ int nbTriangle;
+ int ID, shapeID, ghs3dShapeID;
+
+ double coord [3];
+
+ TopoDS_Shape aSolid;
+ SMDS_MeshNode * aNewNode;
+ const SMDS_MeshNode * node[4];
+ map <int,const SMDS_MeshNode*>::iterator IdNode;
+ SMDS_MeshElement* aTet;
+
+ for (int i=0; i<nShape; i++)
+ tabID[i] = 0;
+
+ // Read the file state
+ fileStat = fstat(fileOpen, &status);
+ length = status.st_size;
+
+ // Mapping the result file into memory
+ ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
+ fileClose = close(fileOpen);
+
+ ptr = readMapIntLine(ptr, tab);
+ tetraPtr = ptr;
+
+ nbElems = tab[0];
+ nbNodes = tab[1];
+ nbInputNodes = tab[2];
+
+ // Reading the nodeId
+ for (int i=0; i < 4*nbElems; i++)
+ nodeId = strtol(ptr, &ptr, 10);
+
+ // Reading the nodeCoor and update the nodeMap
+ for (int iNode=0; iNode < nbNodes; iNode++) {
+ for (int iCoor=0; iCoor < 3; iCoor++)
+ coord[ iCoor ] = strtod(ptr, &ptr);
+ if ((iNode+1) > nbInputNodes) {
+ aNewNode = theMeshDS->AddNode( coord[0],coord[1],coord[2] );
+ theGhs3dIdToNodeMap.insert(make_pair( (iNode+1), aNewNode ));
}
- // create a tetrahedron with orientation as for MED
- SMDS_MeshElement* aTet = theMesh->AddVolume( node[1], node[0], node[2], node[3] );
- theMesh->SetMeshElementOnShape( aTet, shapeID );
}
- // ------------------------
- // record 3:
- // read and set nodes' XYZ
- // ------------------------
- GHS3DPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb );
- for (int iNode = 0; iNode < nbNodes; iNode++)
- {
- // read 3 coordinates
- double coord [3];
- for (int iCoord = 0; iCoord < 3; iCoord++)
- {
- if (!aPtr || ! getDouble ( coord[ iCoord ], aPtr ))
- {
- GHS3DPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb );
- if (!aPtr || ! getDouble ( coord[ iCoord ], aPtr ))
- {
- MESSAGE( "Cant read " << (iCoord+1) << "-th node coord on line " << aLineNb );
- return false;
- }
- }
+ // Reading the triangles
+ nbTriangle = strtol(ptr, &ptr, 10);
+
+ for (int i=0; i < 3*nbTriangle; i++)
+ triangleId = strtol(ptr, &ptr, 10);
+
+ shapePtr = ptr;
+
+ // Associating the tetrahedrons with the shapes
+ for (int iElem = 0; iElem < nbElems; iElem++) {
+ for (int iNode = 0; iNode < 4; iNode++) {
+ ID = strtol(tetraPtr, &tetraPtr, 10);
+ IdNode = theGhs3dIdToNodeMap.find(ID);
+ node[ iNode ] = IdNode->second;
}
- // do not move old nodes
- int ID = iNode + 1;
- if (ID <= nbInputNodes)
- continue;
- // find a node
- map <int,const SMDS_MeshNode*>::iterator IdNode = theGhs3dIdToNodeMap.find( ID );
- ASSERT ( IdNode != theGhs3dIdToNodeMap.end());
- SMDS_MeshNode* node = const_cast<SMDS_MeshNode*> ( (*IdNode).second );
-
- // set XYZ
- theMesh->MoveNode( node, coord[0], coord[1], coord[2] );
+ aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
+ ghs3dShapeID = strtol(shapePtr, &shapePtr, 10);
+ if ( tabID[ ghs3dShapeID - 1 ] == 0 ) {
+ if (iElem == 0)
+ aSolid = tabShape[0];
+ aSolid = findSolid(node, aSolid, tabShape, tabBox, nbTriangle);
+ shapeID = theMeshDS->ShapeToIndex( aSolid );
+ tabID[ ghs3dShapeID - 1] = shapeID;
+ }
+ else
+ shapeID = tabID[ ghs3dShapeID - 1];
+ theMeshDS->SetMeshElementOnShape( aTet, shapeID );
}
-
- return nbElems;
+ return true;
}
//=======================================================================
return aTmpDir;
}
-//================================================================================
+//=============================================================================
/*!
- * \brief Decrease amount of memory GHS3D may use until it can allocate it
- * \param nbMB - memory size to adjust
- * \param aLogFileName - file for GHS3D output
- * \retval bool - false if GHS3D can not run for any reason
+ *Here we are going to use the GHS3D mesher
*/
-//================================================================================
+//=============================================================================
-static bool adjustMemory(int & nbMB, const TCollection_AsciiString & aLogFileName)
+bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
+ const TopoDS_Shape& theShape)
{
- TCollection_AsciiString cmd( "ghs3d -m " );
- cmd += nbMB;
- cmd += " 1>";
- cmd += aLogFileName;
+ bool Ok;
+ SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
- system( cmd.ToCString() ); // run
+ if (_iShape == 0 && _nbShape == 0) {
+ cout << endl;
+ cout << "Ghs3d execution..." << endl;
+ cout << endl;
- // analyse log file
+ TopExp_Explorer exp (meshDS->ShapeToMesh(), TopAbs_SOLID);
+ for (; exp.More(); exp.Next())
+ _nbShape++;
+ }
- FILE * aLogFile = fopen( aLogFileName.ToCString(), "r" );
- if ( aLogFile )
- {
- bool memoryOK = true;
- char * aPtr;
- char aBuffer[ GHS3DPlugin_BUFLENGTH ];
- int aLineNb = 0;
- do {
- GHS3DPlugin_ReadLine( aPtr, aBuffer, aLogFile, aLineNb );
- if ( aPtr ) {
- TCollection_AsciiString line( aPtr );
- if ( line.Search( "UNABLE TO ALLOCATE MEMORY" ) > 0 )
- memoryOK = false;
- }
- } while ( aPtr && memoryOK );
+ _iShape++;
- fclose( aLogFile );
+ if ( _iShape == _nbShape ) {
- if ( !memoryOK ) {
- nbMB *= 0.75;
- return adjustMemory( nbMB, aLogFileName );
- }
- return true;
- }
- return false;
-}
+ // create bounding box for every shape
-//=============================================================================
-/*!
- *Here we are going to use the GHS3D mesher
- */
-//=============================================================================
+ int iShape = 0;
+ TopoDS_Shape tabShape[_nbShape];
+ double tabBox[_nbShape][6];
+ Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
-bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
- const TopoDS_Shape& theShape)
-{
- MESSAGE("GHS3DPlugin_GHS3D::Compute");
-
- SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
+ TopExp_Explorer expBox (meshDS->ShapeToMesh(), TopAbs_SOLID);
+ for (; expBox.More(); expBox.Next()) {
+ tabShape[iShape] = expBox.Current();
+ Bnd_Box BoundingBox;
+ BRepBndLib::Add(expBox.Current(), BoundingBox);
+ BoundingBox.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
+ tabBox[iShape][0] = Xmin; tabBox[iShape][1] = Xmax;
+ tabBox[iShape][2] = Ymin; tabBox[iShape][3] = Ymax;
+ tabBox[iShape][4] = Zmin; tabBox[iShape][5] = Zmax;
+ iShape++;
+ }
- // make a unique working file name
- // to avoid access to the same files by eg different users
+ // make a unique working file name
+ // to avoid access to the same files by eg different users
- TCollection_AsciiString aGenericName, aTmpDir = getTmpDir();
- aGenericName = aTmpDir + "GHS3D_";
+ TCollection_AsciiString aGenericName, aTmpDir = getTmpDir();
+ aGenericName = aTmpDir + "GHS3D_";
#ifdef WIN32
- aGenericName += GetCurrentProcessId();
+ aGenericName += GetCurrentProcessId();
#else
- aGenericName += getpid();
+ aGenericName += getpid();
#endif
- aGenericName += "_";
- aGenericName += meshDS->ShapeToIndex( theShape );
-
- TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName;
- TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName;
- aFacesFileName = aGenericName + ".faces"; // in faces
- aPointsFileName = aGenericName + ".points"; // in points
- aResultFileName = aGenericName + ".noboite";// out points and volumes
- aBadResFileName = aGenericName + ".boite"; // out bad result
- aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
- aLogFileName = aGenericName + ".log"; // log
-
- // -----------------
- // make input files
- // -----------------
-
- ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
- ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
- bool Ok =
+ aGenericName += "_";
+ aGenericName += meshDS->ShapeToIndex( theShape );
+
+ TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName;
+ TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName;
+ aFacesFileName = aGenericName + ".faces"; // in faces
+ aPointsFileName = aGenericName + ".points"; // in points
+ aResultFileName = aGenericName + ".noboite";// out points and volumes
+ aBadResFileName = aGenericName + ".boite"; // out bad result
+ aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
+ aLogFileName = aGenericName + ".log"; // log
+
+ // -----------------
+ // make input files
+ // -----------------
+
+ ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
+ ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
+ // bool Ok =
+ Ok =
#ifdef WIN32
- aFacesFile->is_open() && aPointsFile->is_open();
+ aFacesFile->is_open() && aPointsFile->is_open();
#else
- aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
+ aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
#endif
- if (!Ok)
- {
- INFOS( "Can't write into " << aTmpDir.ToCString());
- return false;
- }
- map <int,int> aSmdsToGhs3dIdMap;
- map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
+ if (!Ok) {
+ INFOS( "Can't write into " << aTmpDir.ToCString());
+ return false;
+ }
+ map <int,int> aSmdsToGhs3dIdMap;
+ map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
- Ok =
- (writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap ) &&
- writeFaces ( aFacesFile, meshDS, theShape, aSmdsToGhs3dIdMap ));
+ Ok = writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap ) &&
+ writeFaces ( aFacesFile, meshDS, aSmdsToGhs3dIdMap );
- aFacesFile.close();
- aPointsFile.close();
+ aFacesFile.close();
+ aPointsFile.close();
- if ( ! Ok ) {
- if ( !getenv("GHS3D_KEEP_FILES") ) {
- OSD_File( aFacesFileName ).Remove();
- OSD_File( aPointsFileName ).Remove();
+ if ( ! Ok ) {
+ if ( !getenv("GHS3D_KEEP_FILES") ) {
+ OSD_File( aFacesFileName ).Remove();
+ OSD_File( aPointsFileName ).Remove();
+ }
+ return false;
}
- return false;
- }
- // -----------------
- // run ghs3d mesher WIN32???
- // -----------------
+ // -----------------
+ // run ghs3d mesher WIN32???
+ // -----------------
+
+ // ghs3d need to know amount of memory it may use (MB).
+ // Default memory is defined at ghs3d installation but it may be not enough,
+ // so allow to use about all available memory
- // ghs3d need to know amount of memory it may use (MB).
- // Default memory is defined at ghs3d installation but it may be not enough,
- // so allow to use about all available memory
- TCollection_AsciiString memory;
+ TCollection_AsciiString memory;
#ifndef WIN32
- struct sysinfo si;
- int err = sysinfo( &si );
- if ( err == 0 ) {
- int MB = 0.9 * ( si.freeram + si.freeswap ) * si.mem_unit / 1024 / 1024;
- adjustMemory( MB, aLogFileName );
- memory = "-m ";
- memory += MB;
- }
+ struct sysinfo si;
+ int err = sysinfo( &si );
+ if ( err == 0 ) {
+ int freeMem = si.totalram * si.mem_unit / 1024 / 1024;
+ memory = "-m ";
+ memory += int( 0.7 * freeMem );
+ }
#endif
- TCollection_AsciiString cmd( "ghs3d " ); // command to run
- cmd +=
- memory + // memory
- " -f " + aGenericName + // file to read
- " 1>" + aLogFileName; // dump into file
+ MESSAGE("GHS3DPlugin_GHS3D::Compute");
+ TCollection_AsciiString cmd( "ghs3d " ); // command to run
+ cmd +=
+ memory + // memory
+ " -c0 -f " + aGenericName + // file to read
+ " 1>" + aLogFileName; // dump into file
- system( cmd.ToCString() ); // run
+ system( cmd.ToCString() ); // run
- // --------------
- // read a result
- // --------------
+ cout << endl;
+ cout << "End of Ghs3d execution !" << endl;
- FILE * aResultFile = fopen( aResultFileName.ToCString(), "r" );
- if (aResultFile)
- {
- Ok = readResult( aResultFile, meshDS, theShape, aGhs3dIdToNodeMap );
- fclose(aResultFile);
- }
- else
- Ok = false;
+ // --------------
+ // read a result
+ // --------------
- // ---------------------
- // remove working files
- // ---------------------
+ // Mapping the result file
- if ( Ok ) {
- OSD_File( aLogFileName ).Remove();
- }
- else if ( OSD_File( aLogFileName ).Size() > 0 ) {
- INFOS( "GHS3D Error: see " << aLogFileName.ToCString() );
- }
- else {
- OSD_File( aLogFileName ).Remove();
- INFOS( "GHS3D Error: command '" << cmd.ToCString() << "' failed" );
- }
+ int fileOpen;
+ fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
+ if ( fileOpen < 0 ) {
+ cout << endl;
+ cout << "Error when opening the " << aResultFileName.ToCString() << " file" << endl;
+ cout << endl;
+ Ok = false;
+ }
+ else
+ Ok = readResultFile( fileOpen, meshDS, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap );
- if ( !getenv("GHS3D_KEEP_FILES") )
- {
- OSD_File( aFacesFileName ).Remove();
- OSD_File( aPointsFileName ).Remove();
- OSD_File( aResultFileName ).Remove();
- OSD_File( aBadResFileName ).Remove();
- OSD_File( aBbResFileName ).Remove();
+ // ---------------------
+ // remove working files
+ // ---------------------
+
+ if ( Ok ) {
+ OSD_File( aLogFileName ).Remove();
+ }
+ else if ( OSD_File( aLogFileName ).Size() > 0 ) {
+ INFOS( "GHS3D Error: see " << aLogFileName.ToCString() );
+ }
+ else {
+ OSD_File( aLogFileName ).Remove();
+ INFOS( "GHS3D Error: command '" << cmd.ToCString() << "' failed" );
+ }
+
+ if ( !getenv("GHS3D_KEEP_FILES") ) {
+ OSD_File( aFacesFileName ).Remove();
+ OSD_File( aPointsFileName ).Remove();
+ OSD_File( aResultFileName ).Remove();
+ OSD_File( aBadResFileName ).Remove();
+ OSD_File( aBbResFileName ).Remove();
+ }
+ if ( _iShape == _nbShape ) {
+ cout << "Output file " << aResultFileName.ToCString();
+ if ( !Ok )
+ cout << " not treated !" << endl;
+ else
+ cout << " treated !" << endl;
+ cout << endl;
+ }
}
-
return Ok;
}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+ostream & GHS3DPlugin_GHS3D::SaveTo(ostream & save)
+{
+ return save;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+istream & GHS3DPlugin_GHS3D::LoadFrom(istream & load)
+{
+ return load;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+ostream & operator << (ostream & save, GHS3DPlugin_GHS3D & hyp)
+{
+ return hyp.SaveTo( save );
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+istream & operator >> (istream & load, GHS3DPlugin_GHS3D & hyp)
+{
+ return hyp.LoadFrom( load );
+}