1 // Copyright (C) 2004-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //=============================================================================
21 // File : GHS3DPlugin_Hypothesis.cxx
22 // Created : Wed Apr 2 12:36:29 2008
23 // Author : Edward AGAPOV (eap)
24 //=============================================================================
26 #include "GHS3DPlugin_Hypothesis.hxx"
27 #include <SMESH_ProxyMesh.hxx>
28 #include <SMESH_Group.hxx>
29 #include <StdMeshers_QuadToTriaAdaptor.hxx>
31 #include <TCollection_AsciiString.hxx>
35 #define getpid _getpid
38 //=======================================================================
39 //function : GHS3DPlugin_Hypothesis
40 //=======================================================================
42 GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen)
43 : SMESH_Hypothesis(hypId, studyId, gen),
44 myToMeshHoles(DefaultMeshHoles()),
47 myOptimizationLevel(DefaultOptimizationLevel()),
48 myWorkingDirectory(DefaultWorkingDirectory()),
49 myKeepFiles(DefaultKeepFiles()),
50 myVerboseLevel(DefaultVerboseLevel()),
51 myToCreateNewNodes(DefaultToCreateNewNodes()),
52 myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
53 myToUseFemCorrection(DefaultToUseFEMCorrection()),
54 myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
55 myGradation(DefaultGradation()),
56 _enfVertexList(DefaultGHS3DEnforcedVertexList()),
57 _enfVertexCoordsSizeList(DefaultGHS3DEnforcedVertexCoordsValues()),
58 _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()),
59 _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()),
60 _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()),
61 _enfMeshList(DefaultGHS3DEnforcedMeshList()),
62 _entryEnfMeshMap(DefaultEntryGHS3DEnforcedMeshListMap()),
63 _enfNodes(TIDSortedNodeGroupMap()),
64 _enfEdges(TIDSortedElemGroupMap()),
65 _enfTriangles(TIDSortedElemGroupMap()),
66 _nodeIDToSizeMap(DefaultID2SizeMap()),
67 _groupsToRemove(DefaultGroupsToRemove())
69 _name = "GHS3D_Parameters";
73 //=======================================================================
74 //function : SetToMeshHoles
75 //=======================================================================
77 void GHS3DPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
79 if ( myToMeshHoles != toMesh ) {
80 myToMeshHoles = toMesh;
81 NotifySubMeshesHypothesisModification();
85 //=======================================================================
86 //function : GetToMeshHoles
87 //=======================================================================
89 bool GHS3DPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
91 if (checkFreeOption && !myTextOption.empty()) {
92 if ( myTextOption.find("-c 0"))
94 if ( myTextOption.find("-c 1"))
100 //=======================================================================
101 //function : SetMaximumMemory
102 //=======================================================================
104 void GHS3DPlugin_Hypothesis::SetMaximumMemory(short MB)
106 if ( myMaximumMemory != MB ) {
107 myMaximumMemory = MB;
108 NotifySubMeshesHypothesisModification();
112 //=======================================================================
113 //function : GetMaximumMemory
114 // * automatic memory adjustment mode. Default is zero
115 //=======================================================================
117 short GHS3DPlugin_Hypothesis::GetMaximumMemory() const
119 return myMaximumMemory;
122 //=======================================================================
123 //function : SetInitialMemory
124 //=======================================================================
126 void GHS3DPlugin_Hypothesis::SetInitialMemory(short MB)
128 if ( myInitialMemory != MB ) {
129 myInitialMemory = MB;
130 NotifySubMeshesHypothesisModification();
134 //=======================================================================
135 //function : GetInitialMemory
136 //=======================================================================
138 short GHS3DPlugin_Hypothesis::GetInitialMemory() const
140 return myInitialMemory;
143 //=======================================================================
144 //function : SetOptimizationLevel
145 //=======================================================================
147 void GHS3DPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level)
149 if ( myOptimizationLevel != level ) {
150 myOptimizationLevel = level;
151 NotifySubMeshesHypothesisModification();
155 //=======================================================================
156 //function : GetOptimizationLevel
157 //=======================================================================
159 GHS3DPlugin_Hypothesis::OptimizationLevel GHS3DPlugin_Hypothesis::GetOptimizationLevel() const
161 return (OptimizationLevel) myOptimizationLevel;
164 //=======================================================================
165 //function : SetWorkingDirectory
166 //=======================================================================
168 void GHS3DPlugin_Hypothesis::SetWorkingDirectory(const std::string& path)
170 if ( myWorkingDirectory != path ) {
171 myWorkingDirectory = path;
172 NotifySubMeshesHypothesisModification();
176 //=======================================================================
177 //function : GetWorkingDirectory
178 //=======================================================================
180 std::string GHS3DPlugin_Hypothesis::GetWorkingDirectory() const
182 return myWorkingDirectory;
185 //=======================================================================
186 //function : SetKeepFiles
187 //=======================================================================
189 void GHS3DPlugin_Hypothesis::SetKeepFiles(bool toKeep)
191 if ( myKeepFiles != toKeep ) {
192 myKeepFiles = toKeep;
193 NotifySubMeshesHypothesisModification();
197 //=======================================================================
198 //function : GetKeepFiles
199 //=======================================================================
201 bool GHS3DPlugin_Hypothesis::GetKeepFiles() const
206 //=======================================================================
207 //function : SetVerboseLevel
208 //=======================================================================
210 void GHS3DPlugin_Hypothesis::SetVerboseLevel(short level)
212 if ( myVerboseLevel != level ) {
213 myVerboseLevel = level;
214 NotifySubMeshesHypothesisModification();
218 //=======================================================================
219 //function : GetVerboseLevel
220 //=======================================================================
222 short GHS3DPlugin_Hypothesis::GetVerboseLevel() const
224 return myVerboseLevel;
227 //=======================================================================
228 //function : SetToCreateNewNodes
229 //=======================================================================
231 void GHS3DPlugin_Hypothesis::SetToCreateNewNodes(bool toCreate)
233 if ( myToCreateNewNodes != toCreate ) {
234 myToCreateNewNodes = toCreate;
235 NotifySubMeshesHypothesisModification();
239 //=======================================================================
240 //function : GetToCreateNewNodes
241 //=======================================================================
243 bool GHS3DPlugin_Hypothesis::GetToCreateNewNodes() const
245 return myToCreateNewNodes;
248 //=======================================================================
249 //function : SetToUseBoundaryRecoveryVersion
250 //=======================================================================
252 void GHS3DPlugin_Hypothesis::SetToUseBoundaryRecoveryVersion(bool toUse)
254 if ( myToUseBoundaryRecoveryVersion != toUse ) {
255 myToUseBoundaryRecoveryVersion = toUse;
256 NotifySubMeshesHypothesisModification();
260 //=======================================================================
261 //function : GetToUseBoundaryRecoveryVersion
262 //=======================================================================
264 bool GHS3DPlugin_Hypothesis::GetToUseBoundaryRecoveryVersion() const
266 return myToUseBoundaryRecoveryVersion;
269 //=======================================================================
270 //function : SetFEMCorrection
271 //=======================================================================
273 void GHS3DPlugin_Hypothesis::SetFEMCorrection(bool toUseFem)
275 if ( myToUseFemCorrection != toUseFem ) {
276 myToUseFemCorrection = toUseFem;
277 NotifySubMeshesHypothesisModification();
281 //=======================================================================
282 //function : GetFEMCorrection
283 //=======================================================================
285 bool GHS3DPlugin_Hypothesis::GetFEMCorrection() const
287 return myToUseFemCorrection;
290 //=======================================================================
291 //function : SetToRemoveCentralPoint
292 //=======================================================================
294 void GHS3DPlugin_Hypothesis::SetToRemoveCentralPoint(bool toRemove)
296 if ( myToRemoveCentralPoint != toRemove ) {
297 myToRemoveCentralPoint = toRemove;
298 NotifySubMeshesHypothesisModification();
302 //=======================================================================
303 //function : GetToRemoveCentralPoint
304 //=======================================================================
306 bool GHS3DPlugin_Hypothesis::GetToRemoveCentralPoint() const
308 return myToRemoveCentralPoint;
311 //=======================================================================
312 //function : SetTextOption
313 //=======================================================================
315 void GHS3DPlugin_Hypothesis::SetTextOption(const std::string& option)
317 if ( myTextOption != option ) {
318 myTextOption = option;
319 NotifySubMeshesHypothesisModification();
323 //=======================================================================
324 //function : GetTextOption
325 //=======================================================================
327 std::string GHS3DPlugin_Hypothesis::GetTextOption() const
332 //=======================================================================
333 //function : SetGradation
334 //=======================================================================
336 void GHS3DPlugin_Hypothesis::SetGradation(double gradation)
338 if ( myGradation != gradation ) {
339 myGradation = gradation;
340 NotifySubMeshesHypothesisModification();
344 //=======================================================================
345 //function : GetGradation
346 //=======================================================================
348 double GHS3DPlugin_Hypothesis::GetGradation() const
353 //=======================================================================
354 //function : SetEnforcedVertex
355 //=======================================================================
357 bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
358 double size, double x, double y, double z, bool isCompound)
360 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", "
361 << size << ", " << x << ", " << y << ", " << z << ", "<< isCompound << ")");
363 bool toNotify = false;
364 bool toCreate = true;
366 TGHS3DEnforcedVertex *oldEnVertex;
367 TGHS3DEnforcedVertex *newEnfVertex = new TGHS3DEnforcedVertex();
368 newEnfVertex->name = theName;
369 newEnfVertex->geomEntry = theEntry;
370 newEnfVertex->coords.clear();
372 newEnfVertex->coords.push_back(x);
373 newEnfVertex->coords.push_back(y);
374 newEnfVertex->coords.push_back(z);
376 newEnfVertex->groupName = theGroupName;
377 newEnfVertex->size = size;
378 newEnfVertex->isCompound = isCompound;
381 // update _enfVertexList
382 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
383 if (it != _enfVertexList.end()) {
386 MESSAGE("Enforced Vertex was found => Update");
387 if (oldEnVertex->name != theName) {
388 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theName << "\"");
389 oldEnVertex->name = theName;
392 if (oldEnVertex->groupName != theGroupName) {
393 MESSAGE("Update group name from \"" << oldEnVertex->groupName << "\" to \"" << theGroupName << "\"");
394 oldEnVertex->groupName = theGroupName;
397 if (oldEnVertex->size != size) {
398 MESSAGE("Update size from \"" << oldEnVertex->size << "\" to \"" << size << "\"");
399 oldEnVertex->size = size;
403 // update map coords / enf vertex if needed
404 if (oldEnVertex->coords.size()) {
405 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
406 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
409 // update map geom entry / enf vertex if needed
410 if (oldEnVertex->geomEntry != "") {
411 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
412 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
417 // //////// CREATE ////////////
420 MESSAGE("Creating new enforced vertex");
421 _enfVertexList.insert(newEnfVertex);
422 if (theEntry == "") {
423 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
424 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
427 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
428 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
433 NotifySubMeshesHypothesisModification();
435 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex END");
440 //=======================================================================
441 //function : SetEnforcedMesh
442 //=======================================================================
443 bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
445 TIDSortedElemSet theElemSet;
446 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
447 while ( eIt->more() )
448 theElemSet.insert( eIt->next() );
449 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source mesh");
450 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
452 TGHS3DEnforcedMesh* newEnfMesh = new TGHS3DEnforcedMesh();
453 newEnfMesh->name = name;
454 newEnfMesh->entry = entry;
455 newEnfMesh->elementType = elementType;
456 newEnfMesh->groupName = groupName;
458 TGHS3DEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
459 if (it == _enfMeshList.end()) {
460 _entryEnfMeshMap[entry].insert(newEnfMesh);
461 _enfMeshList.insert(newEnfMesh);
467 //=======================================================================
468 //function : SetEnforcedGroup
469 //=======================================================================
470 bool GHS3DPlugin_Hypothesis::SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName)
472 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedGroup");
473 TIDSortedElemSet theElemSet;
474 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
475 for (int i=0; i < theIDs->length(); i++) {
476 CORBA::Long ind = theIDs[i];
477 if (elementType == SMESH::NODE)
479 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
481 theElemSet.insert( node );
485 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
487 theElemSet.insert( elem );
491 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
492 // while ( it->more() )
493 // theElemSet.insert( it->next() );
495 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source group ");
496 bool added = SetEnforcedElements( theElemSet, elementType, groupName);
498 TGHS3DEnforcedMesh* newEnfMesh = new TGHS3DEnforcedMesh();
499 newEnfMesh->name = name;
500 newEnfMesh->entry = entry;
501 newEnfMesh->elementType = elementType;
502 newEnfMesh->groupName = groupName;
504 TGHS3DEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
505 if (it == _enfMeshList.end()) {
506 _entryEnfMeshMap[entry].insert(newEnfMesh);
507 _enfMeshList.insert(newEnfMesh);
513 //=======================================================================
514 //function : SetEnforcedElements
515 //=======================================================================
516 bool GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName)
518 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedElements");
519 TIDSortedElemSet::const_iterator it = theElemSet.begin();
520 const SMDS_MeshElement* elem;
521 const SMDS_MeshNode* node;
523 pair<TIDSortedNodeGroupMap::iterator,bool> nodeRet;
524 pair<TIDSortedElemGroupMap::iterator,bool> elemRet;
526 for (;it != theElemSet.end();++it)
529 switch (elementType) {
531 node = dynamic_cast<const SMDS_MeshNode*>(elem);
533 nodeRet = _enfNodes.insert(make_pair(node,groupName));
534 added = added && nodeRet.second;
535 string msg = added ? "yes":"no";
536 MESSAGE( "Node (" <<node->X()<<","<<node->Y()<<","<<node->Z()<< ") with ID " << node->GetID() <<" added ? " << msg);
539 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
540 for (;nodeIt->more();) {
541 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
542 nodeRet = _enfNodes.insert(make_pair(node,groupName));
543 added = added && nodeRet.second;
549 if (elem->GetType() == SMDSAbs_Edge) {
550 elemRet = _enfEdges.insert(make_pair(elem,groupName));
551 added = added && elemRet.second;
553 else if (elem->GetType() > SMDSAbs_Edge) {
554 SMDS_ElemIteratorPtr it = elem->edgesIterator();
556 const SMDS_MeshElement* anEdge = it->next();
557 elemRet = _enfEdges.insert(make_pair(anEdge,groupName));
558 added = added && elemRet.second;
563 if (elem->GetType() == SMDSAbs_Face)
565 if (elem->NbCornerNodes() == 3) {
566 elemRet = _enfTriangles.insert(make_pair(elem,groupName));
567 added = added && elemRet.second;
570 else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
571 SMDS_ElemIteratorPtr it = elem->facesIterator();
573 const SMDS_MeshElement* aFace = it->next();
574 if (aFace->NbCornerNodes() == 3) {
575 elemRet = _enfTriangles.insert(make_pair(aFace,groupName));
576 added = added && elemRet.second;
586 NotifySubMeshesHypothesisModification();
591 //=======================================================================
592 //function : GetEnforcedVertex
593 //=======================================================================
595 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
596 throw (std::invalid_argument)
598 std::vector<double> coord(3);
602 if (_coordsEnfVertexMap.count(coord)>0)
603 return _coordsEnfVertexMap[coord];
604 std::ostringstream msg ;
605 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
606 throw std::invalid_argument(msg.str());
609 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
610 throw (std::invalid_argument)
612 if (_geomEntryEnfVertexMap.count(theEntry)>0)
613 return _geomEntryEnfVertexMap[theEntry];
615 std::ostringstream msg ;
616 msg << "No enforced vertex with entry " << theEntry;
617 throw std::invalid_argument(msg.str());
620 //=======================================================================
621 //function : RemoveEnforcedVertex
622 //=======================================================================
624 bool GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
625 throw (std::invalid_argument)
627 bool toNotify = false;
628 std::ostringstream msg;
629 TGHS3DEnforcedVertex *oldEnfVertex;
630 std::vector<double> coords(3);
635 // check that enf vertex with given enf vertex entry exists
636 TGeomEntryGHS3DEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
637 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
639 MESSAGE("Found enforced vertex with geom entry " << theEntry);
640 oldEnfVertex = it_enfVertexEntry->second;
641 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
644 MESSAGE("Enforced vertex with geom entry " << theEntry << " not found");
645 // check that enf vertex with given coords exists
646 TCoordsGHS3DEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
647 if (it_coords_enf != _coordsEnfVertexMap.end()) {
649 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
650 oldEnfVertex = it_coords_enf->second;
651 _coordsEnfVertexMap.erase(it_coords_enf);
652 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
655 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
656 throw std::invalid_argument(msg.str());
660 MESSAGE("Remove enf vertex from _enfVertexList");
662 // update _enfVertexList
663 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
664 if (it != _enfVertexList.end()) {
665 if ((*it)->groupName != "")
666 _groupsToRemove.insert((*it)->groupName);
667 _enfVertexList.erase(it);
673 NotifySubMeshesHypothesisModification();
678 //=======================================================================
679 //function : ClearEnforcedVertices
680 //=======================================================================
681 void GHS3DPlugin_Hypothesis::ClearEnforcedVertices()
683 TGHS3DEnforcedVertexList::const_iterator it = _enfVertexList.begin();
684 for(;it != _enfVertexList.end();++it) {
685 if ((*it)->groupName != "")
686 _groupsToRemove.insert((*it)->groupName);
688 _enfVertexList.clear();
689 _coordsEnfVertexMap.clear();
690 _geomEntryEnfVertexMap.clear();
691 _enfVertexCoordsSizeList.clear();
692 _enfVertexEntrySizeList.clear();
693 NotifySubMeshesHypothesisModification();
696 //=======================================================================
697 //function : ClearEnforcedMeshes
698 //=======================================================================
699 void GHS3DPlugin_Hypothesis::ClearEnforcedMeshes()
701 TGHS3DEnforcedMeshList::const_iterator it = _enfMeshList.begin();
702 for(;it != _enfMeshList.end();++it) {
703 if ((*it)->groupName != "")
704 _groupsToRemove.insert((*it)->groupName);
708 _enfTriangles.clear();
709 _nodeIDToSizeMap.clear();
710 _enfMeshList.clear();
711 _entryEnfMeshMap.clear();
712 NotifySubMeshesHypothesisModification();
716 //=======================================================================
717 //function : SetGroupsToRemove
718 //=======================================================================
720 void GHS3DPlugin_Hypothesis::ClearGroupsToRemove()
722 _groupsToRemove.clear();
726 //=======================================================================
727 //function : DefaultMeshHoles
728 //=======================================================================
730 bool GHS3DPlugin_Hypothesis::DefaultMeshHoles()
732 return false; // PAL19680
735 //=======================================================================
736 //function : DefaultMaximumMemory
737 //=======================================================================
740 #include <sys/sysinfo.h>
745 short GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
749 int err = sysinfo( &si );
751 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
752 return (int) ( 0.7 * ramMB );
755 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
756 MEMORYSTATUSEX statex;
757 statex.dwLength = sizeof (statex);
758 int err = GlobalMemoryStatusEx (&statex);
761 statex.ullTotalPhys / 1024 / 1024 +
762 statex.ullTotalPageFile / 1024 / 1024 +
763 statex.ullTotalVirtual / 1024 / 1024;
764 return (int) ( 0.7 * totMB );
770 //=======================================================================
771 //function : DefaultInitialMemory
772 //=======================================================================
774 short GHS3DPlugin_Hypothesis::DefaultInitialMemory()
776 return DefaultMaximumMemory();
779 //=======================================================================
780 //function : DefaultOptimizationLevel
781 //=======================================================================
783 short GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
788 //=======================================================================
789 //function : DefaultWorkingDirectory
790 //=======================================================================
792 std::string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory()
794 TCollection_AsciiString aTmpDir;
796 char *Tmp_dir = getenv("SALOME_TMP_DIR");
797 if(Tmp_dir != NULL) {
802 aTmpDir = TCollection_AsciiString("C:\\");
804 aTmpDir = TCollection_AsciiString("/tmp/");
807 return aTmpDir.ToCString();
810 //=======================================================================
811 //function : DefaultKeepFiles
812 //=======================================================================
814 bool GHS3DPlugin_Hypothesis::DefaultKeepFiles()
819 //=======================================================================
820 //function : DefaultVerboseLevel
821 //=======================================================================
823 short GHS3DPlugin_Hypothesis::DefaultVerboseLevel()
828 //=======================================================================
829 //function : DefaultToCreateNewNodes
830 //=======================================================================
832 bool GHS3DPlugin_Hypothesis::DefaultToCreateNewNodes()
837 //=======================================================================
838 //function : DefaultToUseBoundaryRecoveryVersion
839 //=======================================================================
841 bool GHS3DPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
846 //=======================================================================
847 //function : DefaultToUseFEMCorrection
848 //=======================================================================
850 bool GHS3DPlugin_Hypothesis::DefaultToUseFEMCorrection()
855 //=======================================================================
856 //function : DefaultToRemoveCentralPoint
857 //=======================================================================
859 bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint()
864 //=======================================================================
865 //function : DefaultGradation
866 //=======================================================================
868 double GHS3DPlugin_Hypothesis::DefaultGradation()
873 // //=======================================================================
874 // //function : DefaultID2SizeMap
875 // //=======================================================================
877 // GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::DefaultID2SizeMap()
879 // return GHS3DPlugin_Hypothesis::TID2SizeMap();
883 //=======================================================================
885 //=======================================================================
887 std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
889 save << (int) myToMeshHoles << " ";
890 save << myMaximumMemory << " ";
891 save << myInitialMemory << " ";
892 save << myOptimizationLevel << " ";
893 save << myWorkingDirectory << " ";
894 save << (int)myKeepFiles << " ";
895 save << myVerboseLevel << " ";
896 save << (int)myToCreateNewNodes << " ";
897 save << (int)myToUseBoundaryRecoveryVersion << " ";
898 save << (int)myToUseFemCorrection << " ";
899 save << (int)myToRemoveCentralPoint << " ";
900 save << myGradation << " ";
901 if (!myTextOption.empty()) {
902 save << "__OPTIONS_BEGIN__ ";
903 save << myTextOption << " ";
904 save << "__OPTIONS_END__ ";
908 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.begin();
909 if (it != _enfVertexList.end()) {
910 save << " " << "__ENFORCED_VERTICES_BEGIN__ ";
911 for ( ; it != _enfVertexList.end(); ++it ) {
912 TGHS3DEnforcedVertex *enfVertex = (*it);
913 save << " " << "__BEGIN_VERTEX__";
914 if (!enfVertex->name.empty()) {
915 save << " " << "__BEGIN_NAME__";
916 save << " " << enfVertex->name;
917 save << " " << "__END_NAME__";
919 if (!enfVertex->geomEntry.empty()) {
920 save << " " << "__BEGIN_ENTRY__";
921 save << " " << enfVertex->geomEntry;
922 save << " " << enfVertex->isCompound;
923 save << " " << "__END_ENTRY__";
925 if (!enfVertex->groupName.empty()) {
926 save << " " << "__BEGIN_GROUP__";
927 save << " " << enfVertex->groupName;
928 save << " " << "__END_GROUP__";
930 if (enfVertex->coords.size()) {
931 save << " " << "__BEGIN_COORDS__";
932 for (int i=0;i<enfVertex->coords.size();i++)
933 save << " " << enfVertex->coords[i];
934 save << " " << "__END_COORDS__";
936 save << " " << "__BEGIN_SIZE__";
937 save << " " << enfVertex->size;
938 save << " " << "__END_SIZE__";
939 save << " " << "__END_VERTEX__";
941 save << " " << "__ENFORCED_VERTICES_END__ ";
944 TGHS3DEnforcedMeshList::iterator it_mesh = _enfMeshList.begin();
945 if (it_mesh != _enfMeshList.end()) {
946 save << " " << "__ENFORCED_MESHES_BEGIN__ ";
947 for ( ; it_mesh != _enfMeshList.end(); ++it_mesh ) {
948 TGHS3DEnforcedMesh *enfMesh = (*it_mesh);
949 save << " " << "__BEGIN_ENF_MESH__";
951 save << " " << "__BEGIN_NAME__";
952 save << " " << enfMesh->name;
953 save << " " << "__END_NAME__";
955 save << " " << "__BEGIN_ENTRY__";
956 save << " " << enfMesh->entry;
957 save << " " << "__END_ENTRY__";
959 save << " " << "__BEGIN_ELEM_TYPE__";
960 save << " " << (int)enfMesh->elementType;
961 save << " " << "__END_ELEM_TYPE__";
963 if (!enfMesh->groupName.empty()) {
964 save << " " << "__BEGIN_GROUP__";
965 save << " " << enfMesh->groupName;
966 save << " " << "__END_GROUP__";
968 save << " " << "__END_ENF_MESH__";
969 std::cout << "Saving of enforced mesh " << enfMesh->name.c_str() << " done" << std::endl;
971 save << " " << "__ENFORCED_MESHES_END__ ";
976 //=======================================================================
977 //function : LoadFrom
978 //=======================================================================
980 std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
990 load.clear(ios::badbit | load.rdstate());
996 load.clear(ios::badbit | load.rdstate());
1000 myInitialMemory = i;
1002 load.clear(ios::badbit | load.rdstate());
1006 myOptimizationLevel = i;
1008 load.clear(ios::badbit | load.rdstate());
1010 isOK = (load >> myWorkingDirectory);
1012 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
1013 myKeepFiles = false;
1014 myWorkingDirectory.clear();
1016 else if ( myWorkingDirectory == "1" ) {
1018 myWorkingDirectory.clear();
1022 load.clear(ios::badbit | load.rdstate());
1024 if ( !myWorkingDirectory.empty() ) {
1029 load.clear(ios::badbit | load.rdstate());
1034 myVerboseLevel = (short) i;
1036 load.clear(ios::badbit | load.rdstate());
1040 myToCreateNewNodes = (bool) i;
1042 load.clear(ios::badbit | load.rdstate());
1046 myToUseBoundaryRecoveryVersion = (bool) i;
1048 load.clear(ios::badbit | load.rdstate());
1052 myToUseFemCorrection = (bool) i;
1054 load.clear(ios::badbit | load.rdstate());
1058 myToRemoveCentralPoint = (bool) i;
1060 load.clear(ios::badbit | load.rdstate());
1066 load.clear(ios::badbit | load.rdstate());
1068 std::string separator;
1069 bool hasOptions = false;
1070 bool hasEnforcedVertices = false;
1071 bool hasEnforcedMeshes = false;
1072 isOK = (load >> separator);
1075 if (separator == "__OPTIONS_BEGIN__")
1077 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1078 hasEnforcedVertices = true;
1079 else if (separator == "__ENFORCED_MESHES_BEGIN__")
1080 hasEnforcedMeshes = true;
1086 isOK = (load >> txt);
1088 if (txt == "__OPTIONS_END__") {
1089 if (!myTextOption.empty()) {
1090 // Remove last space
1091 myTextOption.erase(myTextOption.end()-1);
1096 myTextOption += txt;
1097 myTextOption += " ";
1103 isOK = (load >> separator);
1104 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1105 hasEnforcedVertices = true;
1106 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1107 hasEnforcedMeshes = true;
1110 if (hasEnforcedVertices) {
1111 std::string txt, name, entry, groupName;
1112 double size, coords[3];
1114 bool hasCoords = false;
1115 isOK = (load >> txt); // __BEGIN_VERTEX__
1117 if (txt == "__ENFORCED_VERTICES_END__")
1120 TGHS3DEnforcedVertex *enfVertex = new TGHS3DEnforcedVertex();
1122 isOK = (load >> txt);
1123 if (txt == "__END_VERTEX__") {
1124 enfVertex->name = name;
1125 enfVertex->geomEntry = entry;
1126 enfVertex->isCompound = isCompound;
1127 enfVertex->groupName = groupName;
1128 enfVertex->coords.clear();
1130 enfVertex->coords.assign(coords,coords+3);
1132 _enfVertexList.insert(enfVertex);
1134 if (enfVertex->coords.size())
1135 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1136 if (!enfVertex->geomEntry.empty())
1137 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1146 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1147 while (isOK && (txt != "__END_NAME__")) {
1148 isOK = (load >> txt);
1149 if (txt != "__END_NAME__") {
1155 MESSAGE("name: " <<name);
1158 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1159 isOK = (load >> entry);
1160 isOK = (load >> isCompound);
1161 isOK = (load >> txt); // __END_ENTRY__
1162 if (txt != "__END_ENTRY__")
1163 throw std::exception();
1164 MESSAGE("entry: " << entry);
1167 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1168 while (isOK && (txt != "__END_GROUP__")) {
1169 isOK = (load >> txt);
1170 if (txt != "__END_GROUP__") {
1171 if (!groupName.empty())
1176 MESSAGE("groupName: " << groupName);
1179 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1181 isOK = (load >> coords[0] >> coords[1] >> coords[2]);
1182 isOK = (load >> txt); // __END_COORDS__
1183 if (txt != "__END_COORDS__")
1184 throw std::exception();
1185 MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]);
1188 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1189 isOK = (load >> size);
1190 isOK = (load >> txt); // __END_ENTRY__
1191 if (txt != "__END_SIZE__") {
1192 throw std::exception();
1194 MESSAGE("size: " << size);
1197 isOK = (load >> txt); // __BEGIN_VERTEX__
1201 if (hasEnforcedVertices) {
1202 isOK = (load >> separator);
1203 if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
1204 hasEnforcedMeshes = true;
1207 if (hasEnforcedMeshes) {
1208 std::string txt, name, entry, groupName;
1209 int elementType = -1;
1210 isOK = (load >> txt); // __BEGIN_ENF_MESH__
1213 if (txt == "__ENFORCED_MESHES_END__")
1216 TGHS3DEnforcedMesh *enfMesh = new TGHS3DEnforcedMesh();
1218 isOK = (load >> txt);
1219 if (txt == "__END_ENF_MESH__") {
1220 enfMesh->name = name;
1221 enfMesh->entry = entry;
1222 enfMesh->elementType = (SMESH::ElementType)elementType;
1223 enfMesh->groupName = groupName;
1225 _enfMeshList.insert(enfMesh);
1226 std::cout << "Restoring of enforced mesh " <<name << " done" << std::endl;
1235 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1236 while (isOK && (txt != "__END_NAME__")) {
1237 isOK = (load >> txt);
1238 if (txt != "__END_NAME__") {
1244 MESSAGE("name: " <<name);
1247 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1248 isOK = (load >> entry);
1249 isOK = (load >> txt); // __END_ENTRY__
1250 if (txt != "__END_ENTRY__")
1251 throw std::exception();
1252 MESSAGE("entry: " << entry);
1255 if (txt == "__BEGIN_ELEM_TYPE__") { // __BEGIN_ELEM_TYPE__
1256 isOK = (load >> elementType);
1257 isOK = (load >> txt); // __END_ELEM_TYPE__
1258 if (txt != "__END_ELEM_TYPE__")
1259 throw std::exception();
1260 MESSAGE("elementType: " << elementType);
1263 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1264 while (isOK && (txt != "__END_GROUP__")) {
1265 isOK = (load >> txt);
1266 if (txt != "__END_GROUP__") {
1267 if (!groupName.empty())
1272 MESSAGE("groupName: " << groupName);
1274 std::cout << "isOK: " << isOK << std::endl;
1277 isOK = (load >> txt); // __BEGIN_ENF_MESH__
1284 //=======================================================================
1285 //function : SetParametersByMesh
1286 //=======================================================================
1288 bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1294 //================================================================================
1296 * \brief Return false
1298 //================================================================================
1300 bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
1301 const SMESH_Mesh* /*theMesh*/)
1306 //================================================================================
1308 * \brief Return command to run ghs3d mesher excluding file prefix (-f)
1310 //================================================================================
1312 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
1313 const bool hasShapeToMesh)
1315 TCollection_AsciiString cmd;
1317 cmd = "ghs3d-41"; // to use old mesh2 format
1319 cmd = "ghs3d"; // to use new mesh format
1320 // check if any option is overridden by hyp->myTextOption
1321 bool m = hyp ? ( hyp->myTextOption.find("-m") == std::string::npos ) : true;
1322 bool M = hyp ? ( hyp->myTextOption.find("-M") == std::string::npos ) : true;
1323 bool c = hyp ? ( hyp->myTextOption.find("-c") == std::string::npos ) : true;
1324 bool o = hyp ? ( hyp->myTextOption.find("-o") == std::string::npos ) : true;
1325 bool p0 = hyp ? ( hyp->myTextOption.find("-p0") == std::string::npos ) : true;
1326 bool C = hyp ? ( hyp->myTextOption.find("-C") == std::string::npos ) : true;
1327 bool v = hyp ? ( hyp->myTextOption.find("-v") == std::string::npos ) : true;
1328 bool fem = hyp ? ( hyp->myTextOption.find("-FEM")== std::string::npos ) : true;
1329 bool rem = hyp ? ( hyp->myTextOption.find("-no_initial_central_point")== std::string::npos ) : true;
1330 bool gra = hyp ? ( hyp->myTextOption.find("-Dcpropa")== std::string::npos ) : true;
1332 // if use boundary recovery version, few options are allowed
1333 bool useBndRecovery = !C;
1334 if ( !useBndRecovery && hyp )
1335 useBndRecovery = hyp->myToUseBoundaryRecoveryVersion;
1337 // ghs3d needs to know amount of memory it may use (MB).
1338 // Default memory is defined at ghs3d installation but it may be not enough,
1339 // so allow to use about all available memory
1341 short aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
1343 if ( aMaximumMemory < 0 )
1344 cmd += DefaultMaximumMemory();
1346 cmd += aMaximumMemory;
1348 if ( M && !useBndRecovery ) {
1349 short aInitialMemory = hyp ? hyp->myInitialMemory : -1;
1351 if ( aInitialMemory > 0 )
1352 cmd += aInitialMemory;
1356 // component to mesh
1357 // 0 , all components to be meshed
1358 // 1 , only the main ( outermost ) component to be meshed
1359 if ( c && !useBndRecovery ) {
1360 // We always run GHS3D with "to mesh holes'==TRUE (see PAL19680)
1361 if ( hasShapeToMesh )
1364 bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
1372 // optimization level
1373 if ( o && hyp && !useBndRecovery ) {
1374 if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
1375 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
1377 cmd += level[ hyp->myOptimizationLevel ];
1381 // to create internal nodes
1382 if ( p0 && hyp && !hyp->myToCreateNewNodes ) {
1389 cmd += hyp->myVerboseLevel;
1392 // boundary recovery version
1393 if ( useBndRecovery ) {
1397 // to use FEM correction
1398 if ( fem && hyp && hyp->myToUseFemCorrection) {
1402 // to remove initial central point.
1403 if ( rem && hyp && hyp->myToRemoveCentralPoint) {
1404 cmd += " -no_initial_central_point";
1408 if ( hyp && !hyp->myTextOption.empty() ) {
1410 cmd += (char*) hyp->myTextOption.c_str();
1413 // to define volumic gradation.
1415 cmd += " -Dcpropa=";
1416 cmd += hyp->myGradation;
1423 return cmd.ToCString();
1426 //================================================================================
1428 * \brief Return a unique file name
1430 //================================================================================
1432 std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
1434 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1435 const char lastChar = *aTmpDir.rbegin();
1437 if(lastChar != '\\') aTmpDir+='\\';
1439 if(lastChar != '/') aTmpDir+='/';
1442 TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
1443 aGenericName += "GHS3D_";
1444 aGenericName += getpid();
1445 aGenericName += "_";
1446 aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
1448 return aGenericName.ToCString();
1452 //================================================================================
1454 * \brief Return the enforced vertices
1456 //================================================================================
1458 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp)
1460 return hyp ? hyp->_GetEnforcedVertices():DefaultGHS3DEnforcedVertexList();
1463 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const GHS3DPlugin_Hypothesis* hyp)
1465 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultGHS3DEnforcedVertexCoordsValues();
1468 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexEntryValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const GHS3DPlugin_Hypothesis* hyp)
1470 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultGHS3DEnforcedVertexEntryValues();
1473 GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByCoords (const GHS3DPlugin_Hypothesis* hyp)
1475 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsGHS3DEnforcedVertexMap();
1478 GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByEntry (const GHS3DPlugin_Hypothesis* hyp)
1480 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryGHS3DEnforcedVertexMap();
1483 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap GHS3DPlugin_Hypothesis::GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp)
1485 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
1488 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp)
1490 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
1493 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp)
1495 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
1498 GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp)
1500 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
1503 GHS3DPlugin_Hypothesis::TSetStrings GHS3DPlugin_Hypothesis::GetGroupsToRemove(const GHS3DPlugin_Hypothesis* hyp)
1505 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();