From b4b0029ebf33052d28c8ae875c63d737b5203b84 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Wed, 13 Aug 2008 15:20:19 +0000 Subject: [PATCH] use ostringstream instead of sprintf --- Geo/GEdge.cpp | 8 ++-- Geo/GEntity.cpp | 24 ++++------ Geo/GFace.cpp | 27 +++++------- Geo/GRegion.cpp | 29 +++++------- Geo/GVertex.cpp | 14 +++--- benchmarks/extrude/tycoelectronics.geo | 48 ++++++++++++++++++++ tutorial/view5.msh | 61 ++++++++++++++++++++++++++ 7 files changed, 150 insertions(+), 61 deletions(-) create mode 100644 benchmarks/extrude/tycoelectronics.geo create mode 100644 tutorial/view5.msh diff --git a/Geo/GEdge.cpp b/Geo/GEdge.cpp index 1d18a5b081..1d3bcc087f 100644 --- a/Geo/GEdge.cpp +++ b/Geo/GEdge.cpp @@ -3,6 +3,7 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to <gmsh@geuz.org>. +#include <sstream> #include <algorithm> #include "GModel.h" #include "GEdge.h" @@ -110,10 +111,9 @@ void GEdge::setVisibility(char val, bool recursive) std::string GEdge::getAdditionalInfoString() { - if(!v0 || !v1) return std::string(""); - char tmp[256]; - sprintf(tmp, "{%d,%d}", v0->tag(), v1->tag()); - return std::string(tmp); + std::ostringstream sstream; + if(v0 && v1) sstream << "{" << v0->tag() << "," << v1->tag() << "}"; + return sstream.str(); } GPoint GEdge::closestPoint(const SPoint3 & queryPoint) const diff --git a/Geo/GEntity.cpp b/Geo/GEntity.cpp index 083d6d1afe..e98253798a 100644 --- a/Geo/GEntity.cpp +++ b/Geo/GEntity.cpp @@ -3,7 +3,7 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to <gmsh@geuz.org>. -#include <stdio.h> +#include <sstream> #include "GModel.h" #include "GEntity.h" #include "MElement.h" @@ -56,24 +56,18 @@ bool GEntity::useColor() std::string GEntity::getInfoString() { - char tmp[256]; - sprintf(tmp, " %d", tag()); - - std::string out = getTypeString() + tmp; + std::ostringstream sstream; + sstream << getTypeString() << " " << tag(); std::string info = getAdditionalInfoString(); - if(info.size()) - out += " " + info; + if(info.size()) sstream << " " << info; if(physicals.size()){ - out += " (Physical: "; - for(unsigned int i = 0; i < physicals.size(); i++){ - if(i) out += " "; - sprintf(tmp, "%d", physicals[i]); - out += tmp; - } - out += ")"; + sstream << " (Physical:"; + for(unsigned int i = 0; i < physicals.size(); i++) + sstream << " " << physicals[i]; + sstream << ")"; } - return out; + return sstream.str(); } diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp index 0f28352192..85613f7800 100644 --- a/Geo/GFace.cpp +++ b/Geo/GFace.cpp @@ -3,6 +3,7 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to <gmsh@geuz.org>. +#include <sstream> #include "GModel.h" #include "GFace.h" #include "GEdge.h" @@ -153,25 +154,19 @@ void GFace::setVisibility(char val, bool recursive) std::string GFace::getAdditionalInfoString() { - if(l_edges.empty()) return std::string(""); - - std::string str("{"); - if(l_edges.size() > 10){ - char tmp[256]; - sprintf(tmp, "%d, ..., %d", l_edges.front()->tag(), l_edges.back()->tag()); - str += tmp; + std::ostringstream sstream; + if(l_edges.size() > 20){ + sstream << "{" << l_edges.front()->tag() << ",...," << l_edges.back()->tag() << "}"; } - else{ - std::list<GEdge*>::const_iterator it = l_edges.begin(); - for(; it != l_edges.end(); it++){ - if(it != l_edges.begin()) str += ","; - char tmp[256]; - sprintf(tmp, "%d", (*it)->tag()); - str += tmp; + else if(l_edges.size()){ + sstream << "{"; + for(std::list<GEdge*>::iterator it = l_edges.begin(); it != l_edges.end(); ++it){ + if(it != l_edges.begin()) sstream << ","; + sstream << (*it)->tag(); } + sstream << "}"; } - str += "}"; - return str; + return sstream.str(); } void GFace::computeMeanPlane() diff --git a/Geo/GRegion.cpp b/Geo/GRegion.cpp index b4d6dd4061..2c5e812c9a 100644 --- a/Geo/GRegion.cpp +++ b/Geo/GRegion.cpp @@ -3,6 +3,7 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to <gmsh@geuz.org>. +#include <sstream> #include "GModel.h" #include "GRegion.h" #include "GFace.h" @@ -119,25 +120,19 @@ void GRegion::setVisibility(char val, bool recursive) std::string GRegion::getAdditionalInfoString() { - if(l_faces.empty()) return std::string(""); - - std::string str("{"); - if(l_faces.size() > 10){ - char tmp[256]; - sprintf(tmp, "%d, ..., %d", l_faces.front()->tag(), l_faces.back()->tag()); - str += tmp; + std::ostringstream sstream; + if(l_faces.size() > 20){ + sstream << "{" << l_faces.front()->tag() << ",...," << l_faces.back()->tag() << "}"; } - else{ - std::list<GFace*>::const_iterator it = l_faces.begin(); - for(; it != l_faces.end(); it++){ - if(it != l_faces.begin()) str += ","; - char tmp[256]; - sprintf(tmp, "%d", (*it)->tag()); - str += tmp; + else if(l_faces.size()){ + sstream << "{"; + for(std::list<GFace*>::iterator it = l_faces.begin(); it != l_faces.end(); ++it){ + if(it != l_faces.begin()) sstream << ","; + sstream << (*it)->tag(); } + sstream << "}"; } - str += "}"; - return str; + return sstream.str(); } std::list<GEdge*> GRegion::edges() const @@ -149,7 +144,7 @@ std::list<GEdge*> GRegion::edges() const e2 = (*it)->edges(); std::list<GEdge*>::const_iterator it2 = e2.begin(); while (it2 != e2.end()){ - if (std::find(e.begin(), e.end(), *it2) == e.end()) + if(std::find(e.begin(), e.end(), *it2) == e.end()) e.push_back(*it2); ++it2; } diff --git a/Geo/GVertex.cpp b/Geo/GVertex.cpp index f1b52a26ef..9d9efb8a3b 100644 --- a/Geo/GVertex.cpp +++ b/Geo/GVertex.cpp @@ -3,7 +3,7 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to <gmsh@geuz.org>. -#include <string.h> +#include <sstream> #include <algorithm> #include "GVertex.h" #include "GFace.h" @@ -50,15 +50,11 @@ SPoint2 GVertex::reparamOnFace(GFace *gf, int) const std::string GVertex::getAdditionalInfoString() { - char str[256]; - sprintf(str, "{%g,%g,%g}", x(), y(), z()); + std::ostringstream sstream; + sstream << "{" << x() << "," << y() << "," << z() << "}"; double lc = prescribedMeshSizeAtVertex(); - if(lc < 1.e22){ - char str2[256]; - sprintf(str2, " (cl: %g)", lc); - strcat(str, str2); - } - return std::string(str); + if(lc < 1.e22) sstream << " (cl: " << lc << ")"; + return sstream.str(); } unsigned int GVertex::getNumMeshElements() diff --git a/benchmarks/extrude/tycoelectronics.geo b/benchmarks/extrude/tycoelectronics.geo new file mode 100644 index 0000000000..1d2688d005 --- /dev/null +++ b/benchmarks/extrude/tycoelectronics.geo @@ -0,0 +1,48 @@ +Point (1) = {0, 0, 0, 50}; +Point (2) = {0, 339.5, 0, 50}; +Point (3) = {0, 393, 0, 50}; +Point (4) = {0, 393, 434, 50}; +Point (5) = {0, 385, 434, 50}; +Point (6) = {0, 354.5, 434, 50}; +Point (7) = {0, 0, 434, 50}; +Point (8) = {0, 100, 1009, 50}; +Point (9) = {0, 0, 1009, 50}; +Point (10) = {0, 0, 1309, 50}; +Point (11) = {0, 50, 1309, 50}; +Point (12) = {0, 50, 1409, 50}; +Point (13) = {0, 0, 1409, 50}; +Point (14) = {0, 40, 1409, 50}; +Point (16) = {0, 40, 721.5, 50}; +Point (17) = {0, 0, 721.5, 50}; +Line (1) = {3, 4}; +Line (2) = {5, 4}; +Line (3) = {2, 6}; +Line (4) = {5, 8}; +Line (5) = {8, 11}; +Line (6) = {11, 12}; +Line (7) = {6, 16}; +Line (8) = {16, 14}; +Line (9) = {3, 2}; +Line (10) = {12, 14}; + +//surface to be rotated +Line Loop(11) = {9,3,7,8,-10,-6,-5,-4,2,-1}; +Plane Surface(12) = {11}; + +//rotate surface +Extrude { { 0, 0, 1 }, { 0, 0, 0 }, 2*Pi/3 } { Surface { 12 }; Layers { 6 }; } +Extrude { { 0, 0, 1 }, { 0, 0, 0 }, 2*Pi/3 } { Surface { 64 }; Layers { 6 }; } +Extrude { { 0, 0, 1 }, { 0, 0, 0 }, 2*Pi/3 } { Surface { 116 }; Layers { 6 }; } + +// REMOVED THIS +//Surface Loop(168) = {167,131,135,139,143,147,151,155,159,163,63,27,31,35,39,43,47,51,55,59,83,87,91,95,99,103,107,111,115,79}; +//Volume(169) = {168}; + +//inlet +Physical Surface(170) = {131,27,79}; +//outlet +Physical Surface(171) = {43,147,95}; +//walls +Physical Surface(172) = {143,39,155,103,51,47,151,91,99,159,107,55,139,35,87,59,163,111,167,135,83,115,31,63}; + +Physical Volume(172) = {169}; diff --git a/tutorial/view5.msh b/tutorial/view5.msh new file mode 100644 index 0000000000..fa1c902976 --- /dev/null +++ b/tutorial/view5.msh @@ -0,0 +1,61 @@ +$MeshFormat +2.0 0 8 +$EndMeshFormat +$Nodes +6 +1 0 0 0 +2 1 0 0 +3 1 1 0 +4 0 1 0 +5 2 0 0 +6 2 1 0 +$EndNodes +$Elements +2 +1 3 0 1 2 3 4 +2 3 0 2 5 6 3 +$EndElements +$NodeData +1 +"A scalar view" +1 +0.0 +3 +0 +1 +6 +1 0.0 +2 0.1 +3 0.2 +4 0.0 +5 0.2 +6 0.4 +$EndNodeData +$NodeData +1 +"A multi-step vector view on element 1" +1 +0.0001 +3 +0 +3 +4 +1 0.4 0.0 0.0 +2 0.5 0.2 0.0 +3 0.7 0.5 0.0 +4 0.8 0.8 0.0 +$EndNodeData +$NodeData +1 +"A multi-step vector view on element 1" +1 +0.0002 +3 +1 +3 +4 +1 -0.4 0.0 0.0 +2 -0.5 0.2 0.0 +3 -0.7 0.5 0.0 +4 -0.8 0.8 0.0 +$EndNodeData -- GitLab