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 _enfVertexList(DefaultGHS3DEnforcedVertexList()),
56 _enfVertexCoordsSizeList(DefaultGHS3DEnforcedVertexCoordsValues()),
57 _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()),
58 _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()),
59 _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()),
60 _enfMeshList(DefaultGHS3DEnforcedMeshList()),
61 _entryEnfMeshMap(DefaultEntryGHS3DEnforcedMeshListMap()),
62 _enfNodes(TIDSortedNodeGroupMap()),
63 _enfEdges(TIDSortedElemGroupMap()),
64 _enfTriangles(TIDSortedElemGroupMap()),
65 _nodeIDToSizeMap(DefaultID2SizeMap()),
66 _elementIDToSizeMap(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 : SetEnforcedVertex
334 //=======================================================================
336 bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
337 double size, double x, double y, double z, bool isCompound)
339 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", "
340 << size << ", " << x << ", " << y << ", " << z << ", "<< isCompound << ")");
342 bool toNotify = false;
343 bool toCreate = true;
345 TGHS3DEnforcedVertex *oldEnVertex;
346 TGHS3DEnforcedVertex *newEnfVertex = new TGHS3DEnforcedVertex();
347 newEnfVertex->name = theName;
348 newEnfVertex->geomEntry = theEntry;
349 newEnfVertex->coords.clear();
351 newEnfVertex->coords.push_back(x);
352 newEnfVertex->coords.push_back(y);
353 newEnfVertex->coords.push_back(z);
355 newEnfVertex->groupName = theGroupName;
356 newEnfVertex->size = size;
357 newEnfVertex->isCompound = isCompound;
360 // update _enfVertexList
361 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex);
362 if (it != _enfVertexList.end()) {
365 MESSAGE("Enforced Vertex was found => Update");
366 if (oldEnVertex->name != theName) {
367 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theName << "\"");
368 oldEnVertex->name = theName;
371 if (oldEnVertex->groupName != theGroupName) {
372 MESSAGE("Update group name from \"" << oldEnVertex->groupName << "\" to \"" << theGroupName << "\"");
373 oldEnVertex->groupName = theGroupName;
376 if (oldEnVertex->size != size) {
377 MESSAGE("Update size from \"" << oldEnVertex->size << "\" to \"" << size << "\"");
378 oldEnVertex->size = size;
382 // update map coords / enf vertex if needed
383 if (oldEnVertex->coords.size()) {
384 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
385 _enfVertexCoordsSizeList[oldEnVertex->coords] = size;
388 // update map geom entry / enf vertex if needed
389 if (oldEnVertex->geomEntry != "") {
390 _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
391 _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size;
396 // //////// CREATE ////////////
399 MESSAGE("Creating new enforced vertex");
400 _enfVertexList.insert(newEnfVertex);
401 if (theEntry == "") {
402 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
403 _enfVertexCoordsSizeList[newEnfVertex->coords] = size;
406 _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
407 _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size;
412 NotifySubMeshesHypothesisModification();
414 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex END");
419 //=======================================================================
420 //function : SetEnforcedMesh
421 //=======================================================================
422 bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, double size, std::string groupName)
424 TIDSortedElemSet theElemSet;
425 SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType));
426 while ( eIt->more() )
427 theElemSet.insert( eIt->next() );
428 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source mesh");
429 bool added = SetEnforcedElements( theElemSet, elementType, size, groupName);
431 TGHS3DEnforcedMesh* newEnfMesh = new TGHS3DEnforcedMesh();
432 newEnfMesh->name = name;
433 newEnfMesh->entry = entry;
434 newEnfMesh->elementType = elementType;
435 newEnfMesh->size = size;
436 newEnfMesh->groupName = groupName;
438 TGHS3DEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
439 if (it == _enfMeshList.end()) {
440 _entryEnfMeshMap[entry].insert(newEnfMesh);
441 _enfMeshList.insert(newEnfMesh);
447 //=======================================================================
448 //function : SetEnforcedGroup
449 //=======================================================================
450 bool GHS3DPlugin_Hypothesis::SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, double size, std::string groupName)
452 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedGroup");
453 TIDSortedElemSet theElemSet;
454 if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
455 for (int i=0; i < theIDs->length(); i++) {
456 CORBA::Long ind = theIDs[i];
457 if (elementType == SMESH::NODE)
459 const SMDS_MeshNode * node = theMeshDS->FindNode(ind);
461 theElemSet.insert( node );
465 const SMDS_MeshElement * elem = theMeshDS->FindElement(ind);
467 theElemSet.insert( elem );
471 // SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements();
472 // while ( it->more() )
473 // theElemSet.insert( it->next() );
475 MESSAGE("Add "<<theElemSet.size()<<" types["<<elementType<<"] from source group ");
476 bool added = SetEnforcedElements( theElemSet, elementType, size, groupName);
478 TGHS3DEnforcedMesh* newEnfMesh = new TGHS3DEnforcedMesh();
479 newEnfMesh->name = name;
480 newEnfMesh->entry = entry;
481 newEnfMesh->elementType = elementType;
482 newEnfMesh->size = size;
483 newEnfMesh->groupName = groupName;
485 TGHS3DEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh);
486 if (it == _enfMeshList.end()) {
487 _entryEnfMeshMap[entry].insert(newEnfMesh);
488 _enfMeshList.insert(newEnfMesh);
494 //=======================================================================
495 //function : SetEnforcedElements
496 //=======================================================================
497 bool GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, double size, std::string groupName)
499 MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedElements");
500 TIDSortedElemSet::const_iterator it = theElemSet.begin();
501 const SMDS_MeshElement* elem;
502 const SMDS_MeshNode* node;
504 for (;it != theElemSet.end();++it)
507 switch (elementType) {
509 node = dynamic_cast<const SMDS_MeshNode*>(elem);
511 _enfNodes.insert(make_pair(node,groupName));
512 _nodeIDToSizeMap.insert(make_pair(node->GetID(), size));
516 SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator();
517 for (;nodeIt->more();) {
518 node = dynamic_cast<const SMDS_MeshNode*>(nodeIt->next());
519 _enfNodes.insert(make_pair(node,groupName));
520 _nodeIDToSizeMap.insert(make_pair(node->GetID(), size));
526 if (elem->GetType() == SMDSAbs_Edge) {
527 _enfEdges.insert(make_pair(elem,groupName));
528 _elementIDToSizeMap.insert(make_pair(elem->GetID(), size));
531 else if (elem->GetType() > SMDSAbs_Edge) {
532 SMDS_ElemIteratorPtr it = elem->edgesIterator();
534 const SMDS_MeshElement* anEdge = it->next();
535 _enfEdges.insert(make_pair(anEdge,groupName));
536 _elementIDToSizeMap.insert(make_pair(anEdge->GetID(), size));
542 if (elem->GetType() == SMDSAbs_Face)
544 if (elem->NbCornerNodes() == 3) {
545 _enfTriangles.insert(make_pair(elem,groupName));
546 _elementIDToSizeMap.insert(make_pair(elem->GetID(), size));
550 else if (elem->GetType() > SMDSAbs_Face) { // Group of faces
551 SMDS_ElemIteratorPtr it = elem->facesIterator();
553 const SMDS_MeshElement* aFace = it->next();
554 if (aFace->NbCornerNodes() == 3) {
555 _enfTriangles.insert(make_pair(aFace,groupName));
556 _elementIDToSizeMap.insert(make_pair(aFace->GetID(), size));
567 NotifySubMeshesHypothesisModification();
572 //=======================================================================
573 //function : GetEnforcedVertex
574 //=======================================================================
576 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z)
577 throw (std::invalid_argument)
579 std::vector<double> coord(3);
583 if (_coordsEnfVertexMap.count(coord)>0)
584 return _coordsEnfVertexMap[coord];
585 std::ostringstream msg ;
586 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
587 throw std::invalid_argument(msg.str());
590 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry)
591 throw (std::invalid_argument)
593 if (_geomEntryEnfVertexMap.count(theEntry)>0)
594 return _geomEntryEnfVertexMap[theEntry];
596 std::ostringstream msg ;
597 msg << "No enforced vertex with entry " << theEntry;
598 throw std::invalid_argument(msg.str());
601 //=======================================================================
602 //function : RemoveEnforcedVertex
603 //=======================================================================
605 bool GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry)
606 throw (std::invalid_argument)
608 bool toNotify = false;
609 std::ostringstream msg;
610 TGHS3DEnforcedVertex *oldEnfVertex;
611 std::vector<double> coords(3);
616 // check that enf vertex with given enf vertex entry exists
617 TGeomEntryGHS3DEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry);
618 if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) {
620 MESSAGE("Found enforced vertex with geom entry " << theEntry);
621 oldEnfVertex = it_enfVertexEntry->second;
622 _geomEntryEnfVertexMap.erase(it_enfVertexEntry);
625 MESSAGE("Enforced vertex with geom entry " << theEntry << " not found");
626 // check that enf vertex with given coords exists
627 TCoordsGHS3DEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
628 if (it_coords_enf != _coordsEnfVertexMap.end()) {
630 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
631 oldEnfVertex = it_coords_enf->second;
632 _coordsEnfVertexMap.erase(it_coords_enf);
633 _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords));
636 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
637 throw std::invalid_argument(msg.str());
641 MESSAGE("Remove enf vertex from _enfVertexList");
643 // update _enfVertexList
644 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
645 if (it != _enfVertexList.end()) {
646 if ((*it)->groupName != "")
647 _groupsToRemove.insert((*it)->groupName);
648 _enfVertexList.erase(it);
654 NotifySubMeshesHypothesisModification();
659 //=======================================================================
660 //function : ClearEnforcedVertices
661 //=======================================================================
662 void GHS3DPlugin_Hypothesis::ClearEnforcedVertices()
664 TGHS3DEnforcedVertexList::const_iterator it = _enfVertexList.begin();
665 for(;it != _enfVertexList.end();++it) {
666 if ((*it)->groupName != "")
667 _groupsToRemove.insert((*it)->groupName);
669 _enfVertexList.clear();
670 _coordsEnfVertexMap.clear();
671 _geomEntryEnfVertexMap.clear();
672 _enfVertexCoordsSizeList.clear();
673 _enfVertexEntrySizeList.clear();
674 NotifySubMeshesHypothesisModification();
677 //=======================================================================
678 //function : ClearEnforcedMeshes
679 //=======================================================================
680 void GHS3DPlugin_Hypothesis::ClearEnforcedMeshes()
682 TGHS3DEnforcedMeshList::const_iterator it = _enfMeshList.begin();
683 for(;it != _enfMeshList.end();++it) {
684 if ((*it)->groupName != "")
685 _groupsToRemove.insert((*it)->groupName);
689 _enfTriangles.clear();
690 _nodeIDToSizeMap.clear();
691 _elementIDToSizeMap.clear();
692 _enfMeshList.clear();
693 _entryEnfMeshMap.clear();
694 NotifySubMeshesHypothesisModification();
698 //=======================================================================
699 //function : SetGroupsToRemove
700 //=======================================================================
702 void GHS3DPlugin_Hypothesis::ClearGroupsToRemove()
704 _groupsToRemove.clear();
708 //=======================================================================
709 //function : DefaultMeshHoles
710 //=======================================================================
712 bool GHS3DPlugin_Hypothesis::DefaultMeshHoles()
714 return false; // PAL19680
717 //=======================================================================
718 //function : DefaultMaximumMemory
719 //=======================================================================
722 #include <sys/sysinfo.h>
727 short GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
731 int err = sysinfo( &si );
733 int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
734 return (int) ( 0.7 * ramMB );
737 // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
738 MEMORYSTATUSEX statex;
739 statex.dwLength = sizeof (statex);
740 int err = GlobalMemoryStatusEx (&statex);
743 statex.ullTotalPhys / 1024 / 1024 +
744 statex.ullTotalPageFile / 1024 / 1024 +
745 statex.ullTotalVirtual / 1024 / 1024;
746 return (int) ( 0.7 * totMB );
752 //=======================================================================
753 //function : DefaultInitialMemory
754 //=======================================================================
756 short GHS3DPlugin_Hypothesis::DefaultInitialMemory()
758 return DefaultMaximumMemory();
761 //=======================================================================
762 //function : DefaultOptimizationLevel
763 //=======================================================================
765 short GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
770 //=======================================================================
771 //function : DefaultWorkingDirectory
772 //=======================================================================
774 std::string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory()
776 TCollection_AsciiString aTmpDir;
778 char *Tmp_dir = getenv("SALOME_TMP_DIR");
779 if(Tmp_dir != NULL) {
784 aTmpDir = TCollection_AsciiString("C:\\");
786 aTmpDir = TCollection_AsciiString("/tmp/");
789 return aTmpDir.ToCString();
792 //=======================================================================
793 //function : DefaultKeepFiles
794 //=======================================================================
796 bool GHS3DPlugin_Hypothesis::DefaultKeepFiles()
801 //=======================================================================
802 //function : DefaultVerboseLevel
803 //=======================================================================
805 short GHS3DPlugin_Hypothesis::DefaultVerboseLevel()
810 //=======================================================================
811 //function : DefaultToCreateNewNodes
812 //=======================================================================
814 bool GHS3DPlugin_Hypothesis::DefaultToCreateNewNodes()
819 //=======================================================================
820 //function : DefaultToUseBoundaryRecoveryVersion
821 //=======================================================================
823 bool GHS3DPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion()
828 //=======================================================================
829 //function : DefaultToUseFEMCorrection
830 //=======================================================================
832 bool GHS3DPlugin_Hypothesis::DefaultToUseFEMCorrection()
837 //=======================================================================
838 //function : DefaultToRemoveCentralPoint
839 //=======================================================================
841 bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint()
846 // //=======================================================================
847 // //function : DefaultID2SizeMap
848 // //=======================================================================
850 // GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::DefaultID2SizeMap()
852 // return GHS3DPlugin_Hypothesis::TID2SizeMap();
856 //=======================================================================
858 //=======================================================================
860 std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
862 save << (int) myToMeshHoles << " ";
863 save << myMaximumMemory << " ";
864 save << myInitialMemory << " ";
865 save << myOptimizationLevel << " ";
866 save << myWorkingDirectory << " ";
867 save << (int)myKeepFiles << " ";
868 save << myVerboseLevel << " ";
869 save << (int)myToCreateNewNodes << " ";
870 save << (int)myToUseBoundaryRecoveryVersion << " ";
871 save << (int)myToUseFemCorrection << " ";
872 save << (int)myToRemoveCentralPoint << " ";
873 if (!myTextOption.empty()) {
874 save << "__OPTIONS_BEGIN__ ";
875 save << myTextOption << " ";
876 save << "__OPTIONS_END__ ";
880 TGHS3DEnforcedVertexList::iterator it = _enfVertexList.begin();
881 if (it != _enfVertexList.end()) {
882 save << "__ENFORCED_VERTICES_BEGIN__ ";
883 for ( ; it != _enfVertexList.end(); ++it ) {
884 TGHS3DEnforcedVertex *enfVertex = (*it);
885 save << " " << "__BEGIN_VERTEX__";
886 if (!enfVertex->name.empty()) {
887 save << " " << "__BEGIN_NAME__";
888 save << " " << enfVertex->name;
889 save << " " << "__END_NAME__";
891 if (!enfVertex->geomEntry.empty()) {
892 save << " " << "__BEGIN_ENTRY__";
893 save << " " << enfVertex->geomEntry;
894 save << " " << enfVertex->isCompound;
895 save << " " << "__END_ENTRY__";
897 if (!enfVertex->groupName.empty()) {
898 save << " " << "__BEGIN_GROUP__";
899 save << " " << enfVertex->groupName;
900 save << " " << "__END_GROUP__";
902 if (enfVertex->coords.size()) {
903 save << " " << "__BEGIN_COORDS__";
904 for (int i=0;i<enfVertex->coords.size();i++)
905 save << " " << enfVertex->coords[i];
906 save << " " << "__END_COORDS__";
908 save << " " << "__BEGIN_SIZE__";
909 save << " " << enfVertex->size;
910 save << " " << "__END_SIZE__";
911 save << " " << "__END_VERTEX__";
913 save << "__ENFORCED_VERTICES_END__ ";
919 //=======================================================================
920 //function : LoadFrom
921 //=======================================================================
923 std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
932 load.clear(ios::badbit | load.rdstate());
938 load.clear(ios::badbit | load.rdstate());
944 load.clear(ios::badbit | load.rdstate());
948 myOptimizationLevel = i;
950 load.clear(ios::badbit | load.rdstate());
952 isOK = (load >> myWorkingDirectory);
954 if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
956 myWorkingDirectory.clear();
958 else if ( myWorkingDirectory == "1" ) {
960 myWorkingDirectory.clear();
964 load.clear(ios::badbit | load.rdstate());
966 if ( !myWorkingDirectory.empty() ) {
971 load.clear(ios::badbit | load.rdstate());
976 myVerboseLevel = (short) i;
978 load.clear(ios::badbit | load.rdstate());
982 myToCreateNewNodes = (bool) i;
984 load.clear(ios::badbit | load.rdstate());
988 myToUseBoundaryRecoveryVersion = (bool) i;
990 load.clear(ios::badbit | load.rdstate());
994 myToUseFemCorrection = (bool) i;
996 load.clear(ios::badbit | load.rdstate());
1000 myToRemoveCentralPoint = (bool) i;
1002 load.clear(ios::badbit | load.rdstate());
1004 std::string separator;
1005 bool hasOptions = false;
1006 bool hasEnforcedVertices = false;
1007 isOK = (load >> separator);
1010 if (separator == "__OPTIONS_BEGIN__")
1012 else if (separator == "__ENFORCED_VERTICES_BEGIN__")
1013 hasEnforcedVertices = true;
1019 isOK = (load >> txt);
1021 if (txt == "__OPTIONS_END__") {
1022 if (!myTextOption.empty()) {
1023 // Remove last space
1024 myTextOption.erase(myTextOption.end()-1);
1029 myTextOption += txt;
1030 myTextOption += " ";
1036 isOK = (load >> separator);
1037 if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
1038 hasEnforcedVertices = true;
1041 if (hasEnforcedVertices) {
1042 std::string txt, name, entry, groupName;
1043 double size, coords[3];
1045 bool hasCoords = false;
1047 isOK = (load >> txt); // __BEGIN_VERTEX__
1049 if (txt == "__ENFORCED_VERTICES_END__")
1052 TGHS3DEnforcedVertex *enfVertex = new TGHS3DEnforcedVertex();
1054 isOK = (load >> txt);
1055 if (txt == "__END_VERTEX__") {
1056 enfVertex->name = name;
1057 enfVertex->geomEntry = entry;
1058 enfVertex->isCompound = isCompound;
1059 enfVertex->groupName = groupName;
1060 enfVertex->coords.clear();
1062 enfVertex->coords.assign(coords,coords+3);
1064 _enfVertexList.insert(enfVertex);
1066 if (enfVertex->coords.size())
1067 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1068 if (!enfVertex->geomEntry.empty())
1069 _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1078 if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__
1079 while (isOK && (txt != "__END_NAME__")) {
1080 isOK = (load >> txt);
1081 if (txt != "__END_NAME__") {
1087 MESSAGE("name: " <<name);
1090 if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1091 isOK = (load >> entry);
1092 isOK = (load >> isCompound);
1093 isOK = (load >> txt); // __END_ENTRY__
1094 if (txt != "__END_ENTRY__")
1095 throw std::exception();
1096 MESSAGE("entry: " << entry);
1099 if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1100 while (isOK && (txt != "__END_GROUP__")) {
1101 isOK = (load >> txt);
1102 if (txt != "__END_GROUP__") {
1103 if (!groupName.empty())
1108 MESSAGE("groupName: " << groupName);
1111 if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1113 isOK = (load >> coords[0] >> coords[1] >> coords[2]);
1114 isOK = (load >> txt); // __END_COORDS__
1115 if (txt != "__END_COORDS__")
1116 throw std::exception();
1117 MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]);
1120 if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__
1121 isOK = (load >> size);
1122 isOK = (load >> txt); // __END_ENTRY__
1123 if (txt != "__END_SIZE__") {
1124 throw std::exception();
1126 MESSAGE("size: " << size);
1136 //=======================================================================
1137 //function : SetParametersByMesh
1138 //=======================================================================
1140 bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&)
1146 //================================================================================
1148 * \brief Return false
1150 //================================================================================
1152 bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
1153 const SMESH_Mesh* /*theMesh*/)
1158 //================================================================================
1160 * \brief Return command to run ghs3d mesher excluding file prefix (-f)
1162 //================================================================================
1164 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
1165 const bool hasShapeToMesh)
1167 TCollection_AsciiString cmd;
1169 cmd = "ghs3d-41"; // to use old mesh2 format
1171 cmd = "ghs3d"; // to use new mesh format
1172 // check if any option is overridden by hyp->myTextOption
1173 bool m = hyp ? ( hyp->myTextOption.find("-m") == std::string::npos ) : true;
1174 bool M = hyp ? ( hyp->myTextOption.find("-M") == std::string::npos ) : true;
1175 bool c = hyp ? ( hyp->myTextOption.find("-c") == std::string::npos ) : true;
1176 bool o = hyp ? ( hyp->myTextOption.find("-o") == std::string::npos ) : true;
1177 bool p0 = hyp ? ( hyp->myTextOption.find("-p0") == std::string::npos ) : true;
1178 bool C = hyp ? ( hyp->myTextOption.find("-C") == std::string::npos ) : true;
1179 bool v = hyp ? ( hyp->myTextOption.find("-v") == std::string::npos ) : true;
1180 bool fem = hyp ? ( hyp->myTextOption.find("-FEM")== std::string::npos ) : true;
1181 bool rem = hyp ? ( hyp->myTextOption.find("-no_initial_central_point")== std::string::npos ) : true;
1183 // if use boundary recovery version, few options are allowed
1184 bool useBndRecovery = !C;
1185 if ( !useBndRecovery && hyp )
1186 useBndRecovery = hyp->myToUseBoundaryRecoveryVersion;
1188 // ghs3d needs to know amount of memory it may use (MB).
1189 // Default memory is defined at ghs3d installation but it may be not enough,
1190 // so allow to use about all available memory
1192 short aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
1194 if ( aMaximumMemory < 0 )
1195 cmd += DefaultMaximumMemory();
1197 cmd += aMaximumMemory;
1199 if ( M && !useBndRecovery ) {
1200 short aInitialMemory = hyp ? hyp->myInitialMemory : -1;
1202 if ( aInitialMemory > 0 )
1203 cmd += aInitialMemory;
1207 // component to mesh
1208 // 0 , all components to be meshed
1209 // 1 , only the main ( outermost ) component to be meshed
1210 if ( c && !useBndRecovery ) {
1211 // We always run GHS3D with "to mesh holes'==TRUE (see PAL19680)
1212 if ( hasShapeToMesh )
1215 bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
1223 // optimization level
1224 if ( o && hyp && !useBndRecovery ) {
1225 if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
1226 const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
1228 cmd += level[ hyp->myOptimizationLevel ];
1232 // to create internal nodes
1233 if ( p0 && hyp && !hyp->myToCreateNewNodes ) {
1240 cmd += hyp->myVerboseLevel;
1243 // boundary recovery version
1244 if ( useBndRecovery ) {
1248 // to use FEM correction
1249 if ( fem && hyp && hyp->myToUseFemCorrection) {
1253 // to remove initial central point.
1254 if ( rem && hyp && hyp->myToRemoveCentralPoint) {
1255 cmd += " -no_initial_central_point";
1259 if ( hyp && !hyp->myTextOption.empty() ) {
1261 cmd += (char*) hyp->myTextOption.c_str();
1268 return cmd.ToCString();
1271 //================================================================================
1273 * \brief Return a unique file name
1275 //================================================================================
1277 std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp)
1279 std::string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory();
1280 const char lastChar = *aTmpDir.rbegin();
1282 if(lastChar != '\\') aTmpDir+='\\';
1284 if(lastChar != '/') aTmpDir+='/';
1287 TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
1288 aGenericName += "GHS3D_";
1289 aGenericName += getpid();
1290 aGenericName += "_";
1291 aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
1293 return aGenericName.ToCString();
1297 //================================================================================
1299 * \brief Return the enforced vertices
1301 //================================================================================
1303 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp)
1305 return hyp ? hyp->_GetEnforcedVertices():DefaultGHS3DEnforcedVertexList();
1308 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const GHS3DPlugin_Hypothesis* hyp)
1310 return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultGHS3DEnforcedVertexCoordsValues();
1313 GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexEntryValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const GHS3DPlugin_Hypothesis* hyp)
1315 return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultGHS3DEnforcedVertexEntryValues();
1318 GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByCoords (const GHS3DPlugin_Hypothesis* hyp)
1320 return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsGHS3DEnforcedVertexMap();
1323 GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByEntry (const GHS3DPlugin_Hypothesis* hyp)
1325 return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryGHS3DEnforcedVertexMap();
1328 GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap GHS3DPlugin_Hypothesis::GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp)
1330 return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap();
1333 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp)
1335 return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap();
1338 GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp)
1340 return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap();
1343 GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp)
1345 return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap();
1348 GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::GetElementIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp)
1350 return hyp ? hyp->_GetElementIDToSizeMap(): DefaultID2SizeMap();
1353 GHS3DPlugin_Hypothesis::TSetStrings GHS3DPlugin_Hypothesis::GetGroupsToRemove(const GHS3DPlugin_Hypothesis* hyp)
1355 return hyp ? hyp->_GetGroupsToRemove(): DefaultGroupsToRemove();