diff --git a/libsrc/core/array.hpp b/libsrc/core/array.hpp index 462f56b2c..e5afa3a5b 100644 --- a/libsrc/core/array.hpp +++ b/libsrc/core/array.hpp @@ -842,6 +842,9 @@ namespace ngcore NETGEN_INLINE void NothingToDelete () { mem_to_delete = nullptr; + + // this memory is not managed by the Array anymore, so set the memory usage to 0 + mt.Free(sizeof(T)*allocsize); } /// Change logical size. If necessary, do reallocation. Keeps contents. diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index 2d5dcfef7..dcc6c666a 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -1211,7 +1211,7 @@ namespace netgen PrintMessage (2, "Object ", i, " has ", tams->GetNT(), " triangles"); } } - catch (exception) + catch (const std::exception &) { cerr << "*************************************************************" << endl << "**** out of memory problem in CSG visualization ****" << endl diff --git a/libsrc/general/table.cpp b/libsrc/general/table.cpp index 18d9cf7e4..dad727ac0 100644 --- a/libsrc/general/table.cpp +++ b/libsrc/general/table.cpp @@ -109,7 +109,7 @@ namespace netgen { void * p = new char [(line.maxsize+5) * elsize]; - if (line.maxsize*elsize) + if (line.maxsize && elsize) memcpy (p, line.col, line.maxsize * elsize); delete [] (char*)line.col; diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index 970070b69..a6fb2c0af 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -1041,7 +1041,7 @@ namespace netgen build_searchtree); return ind - 1; } - catch(NgException e) // quads not implemented curved yet + catch(const NgException & e) // quads not implemented curved yet { for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++) { diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index 3ad4a33df..f74f55a45 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -301,7 +301,7 @@ namespace netgen in >> name; cout << IM(3) << len << " element are in group " << name << endl; int hi, index; - int fdnr, ednr; + int fdnr=-1, ednr=-1; in >> hi >> index >> hi >> hi; int codim = get<1>(element_map[index]); @@ -712,7 +712,7 @@ namespace netgen if(!UserFormatRegister::HaveFormat(format)) throw Exception("Unknown format: " + format); - const auto & entry = UserFormatRegister::Get(format); + const auto entry = UserFormatRegister::Get(format); if(!entry.read) throw Exception("Reading format " + format + " is not implemented"); diff --git a/libsrc/interface/rw_medit.cpp b/libsrc/interface/rw_medit.cpp index e2d638542..d952d344c 100644 --- a/libsrc/interface/rw_medit.cpp +++ b/libsrc/interface/rw_medit.cpp @@ -53,8 +53,8 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map> p[i]; - fin >> index; - mesh.AddPoint(p); + fin >> index; + mesh.AddPoint(p); } } else if(token == "Edges") { @@ -64,10 +64,10 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map> seg[i]; - fin >> seg.edgenr; - seg.edgenr = getIndex(1, seg.edgenr); - seg.si = seg.edgenr; - mesh.AddSegment(seg); + fin >> seg.edgenr; + seg.edgenr = getIndex(1, seg.edgenr); + seg.si = seg.edgenr; + mesh.AddSegment(seg); } } else if(token == "Triangles") { @@ -77,9 +77,9 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map> sel[i]; - fin >> index; - sel.SetIndex(getIndex(2, index)); - mesh.AddSurfaceElement(sel); + fin >> index; + sel.SetIndex(getIndex(2, index)); + mesh.AddSurfaceElement(sel); } } else if(token == "Tetrahedra") { @@ -89,10 +89,10 @@ void ReadMeditFormat (Mesh & mesh, const filesystem::path & filename, map> el[i]; - fin >> index; - el.SetIndex(getIndex(3, index)); - el.Invert(); - mesh.AddVolumeElement(el); + fin >> index; + el.SetIndex(getIndex(3, index)); + el.Invert(); + mesh.AddVolumeElement(el); } } else if(token == "Corners") { diff --git a/libsrc/interface/writeuser.cpp b/libsrc/interface/writeuser.cpp index 04f3780f4..bfab7fbbf 100644 --- a/libsrc/interface/writeuser.cpp +++ b/libsrc/interface/writeuser.cpp @@ -39,7 +39,7 @@ bool WriteUserFormat (const string & format, if(!UserFormatRegister::HaveFormat(format)) return true; - const auto & entry = UserFormatRegister::Get(format); + const auto entry = UserFormatRegister::Get(format); if(!entry.write) return true; diff --git a/libsrc/linalg/densemat.cpp b/libsrc/linalg/densemat.cpp index 06b8c2575..4dd316e0d 100644 --- a/libsrc/linalg/densemat.cpp +++ b/libsrc/linalg/densemat.cpp @@ -49,7 +49,7 @@ namespace netgen { data = NULL; height = width = 0; SetSize (m2.Height(), m2.Width()); - if (Height()*Width()) + if (Height() && Width()) memcpy (data, m2.data, sizeof(double) * (Height() * Width())); } @@ -70,7 +70,7 @@ namespace netgen delete[] data; - if (h*w) + if (h && w) data = new double[h*w]; else data = NULL; diff --git a/libsrc/meshing/boundarylayer.cpp b/libsrc/meshing/boundarylayer.cpp index dcadf9c94..b8f442bed 100644 --- a/libsrc/meshing/boundarylayer.cpp +++ b/libsrc/meshing/boundarylayer.cpp @@ -788,9 +788,9 @@ namespace netgen if(fabs(mat.Det()) > 1e-6) break; } - int maxpos1; - int maxpos2; - double val = 0; + int maxpos1 = 0; + int maxpos2 = 1; + double val = ns[0] * ns[1]; for (auto i : Range(ns)) { for (auto j : Range(i + 1, ns.Size())) diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 7e323dfd9..f0f566ef0 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -1066,7 +1066,8 @@ double MeshOptimize3d :: SwapImproveEdge ( bad3 += GetLegalPenalty(); } - bool swap2, swap3; + bool swap2=false; + bool swap3=false; if (goal == OPT_CONFORM) { @@ -2608,7 +2609,7 @@ double MeshOptimize3d :: SplitImprove2Element ( // search for very flat tets, with two disjoint edges nearly crossing, like a rectangle with diagonals int minedge = -1; double mindist = 1e99; - double minlam0, minlam1; + double minlam0=0, minlam1=0; for (int i : Range(3)) { diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 7fa8bfb13..798d737a4 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -196,8 +196,8 @@ namespace netgen auto& el = mesh.SurfaceElement(velement); if(el.GetType() == TRIG) { - double seg_lam; - double lam; + double seg_lam=-1; + double lam=-1; auto seg = mesh.LineSegment(segs[i]); for(auto k : Range(3)) { diff --git a/libsrc/meshing/meshfunc.cpp b/libsrc/meshing/meshfunc.cpp index 097dc56e3..9a1cf0285 100644 --- a/libsrc/meshing/meshfunc.cpp +++ b/libsrc/meshing/meshfunc.cpp @@ -396,8 +396,8 @@ namespace netgen for (int i = 1; i <= mesh.GetNOpenElements(); i++) md.meshing->AddBoundaryElement (mesh.OpenElement(i)); - if (mp.delaunay && mesh.GetNOpenElements()) - { + if (mp.delaunay && mesh.GetNOpenElements()) + { int oldne = mesh.GetNE(); md.meshing->Delaunay (mesh, domain, mp); @@ -408,22 +408,22 @@ namespace netgen PrintMessage (3, mesh.GetNP(), " points, ", mesh.GetNE(), " elements"); mesh.FindOpenElements(domain); - } + } - Box<3> domain_bbox( Box<3>::EMPTY_BOX ); + Box<3> domain_bbox( Box<3>::EMPTY_BOX ); - for (auto & sel : mesh.SurfaceElements()) + for (auto & sel : mesh.SurfaceElements()) { if (sel.IsDeleted() ) continue; for (auto pi : sel.PNums()) domain_bbox.Add (mesh[pi]); } - domain_bbox.Increase (0.01 * domain_bbox.Diam()); + domain_bbox.Increase (0.01 * domain_bbox.Diam()); - int cntsteps = 0; - int meshed; - if (mesh.GetNOpenElements()) + int cntsteps = 0; + int meshed; + if (mesh.GetNOpenElements()) do { if (multithread.terminate) @@ -515,24 +515,22 @@ namespace netgen PrintMessage (1, "Success !"); } } - while (!meshed); - - { - PrintMessage (3, "Check subdomain ", domain, " / ", mesh.GetNDomains()); + while (!meshed); - mesh.FindOpenElements(domain); + PrintMessage (3, "Check subdomain ", domain, " / ", mesh.GetNDomains()); - bool res = (mesh.CheckConsistentBoundary() != 0); - if (res) - { - if(debugparam.write_mesh_on_error) - md.mesh->Save("inconsistent_surface_domain_"+ToString(md.domain)+".vol.gz"); - PrintError ("Surface mesh not consistent"); - throw NgException ("Stop meshing since surface mesh not consistent"); - } - } - RemoveIllegalElements (mesh, domain); - ConformToFreeSegments (mesh, domain); + mesh.FindOpenElements(domain); + + bool res = (mesh.CheckConsistentBoundary() != 0); + if (res) + { + if(debugparam.write_mesh_on_error) + md.mesh->Save("inconsistent_surface_domain_"+ToString(md.domain)+".vol.gz"); + PrintError ("Surface mesh not consistent"); + throw NgException ("Stop meshing since surface mesh not consistent"); + } + RemoveIllegalElements (mesh, domain); + ConformToFreeSegments (mesh, domain); } void MergeMeshes( Mesh & mesh, Array & md ) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index c874e6fbc..bb09d193a 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -175,7 +175,8 @@ namespace netgen } constexpr PointIndex (t_invalid inv) : i(PointIndex::BASE-1) { ; } // PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; } - constexpr operator int () const { return i; } + constexpr operator const int& () const { return i; } + explicit constexpr operator int& () { return i; } PointIndex operator++ (int) { PointIndex hi(*this); i++; return hi; } PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; } PointIndex & operator++ () { i++; return *this; } diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 0500ac5cf..a771ba187 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -267,7 +267,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def(py::init()) .def("__repr__", &ToString) .def("__str__", &ToString) - .def_property_readonly("nr", &PointIndex::operator int) + .def_property_readonly("nr", &PointIndex::operator const int&) .def("__eq__" , FunctionPointer( [](PointIndex &self, PointIndex &other) { return static_cast(self)==static_cast(other); }) ) .def("__hash__" , FunctionPointer( [](PointIndex &self ) { return static_cast(self); }) ) diff --git a/libsrc/stlgeom/python_stl.cpp b/libsrc/stlgeom/python_stl.cpp index f25d347c9..a56c0eede 100644 --- a/libsrc/stlgeom/python_stl.cpp +++ b/libsrc/stlgeom/python_stl.cpp @@ -224,7 +224,7 @@ NGCORE_API_EXPORT void ExportSTL(py::module & m) .def("GetVicinity", [] (shared_ptr self, int node, int size, string type) { NgArray vic; - int trig; + int trig=-1; if(type == "trig") trig = node; diff --git a/libsrc/visualization/vsmesh.cpp b/libsrc/visualization/vsmesh.cpp index 17139387b..ab9f64a97 100644 --- a/libsrc/visualization/vsmesh.cpp +++ b/libsrc/visualization/vsmesh.cpp @@ -266,7 +266,7 @@ namespace netgen } - catch (bad_weak_ptr e) + catch (const bad_weak_ptr & e) { // cout << "don't have a mesh to visualize" << endl; VisualScene::DrawScene(); @@ -895,7 +895,7 @@ namespace netgen vstimestamp = meshtimestamp; } - catch (bad_weak_ptr e) + catch (const bad_weak_ptr & e) { PrintMessage (3, "vsmesh::buildscene: don't have a mesh to visualize"); VisualScene::BuildScene (zoomall); diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index 16dd17d01..fadf1ecad 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -641,7 +641,7 @@ namespace netgen // delete lock; // mem_lock.UnLock(); } - catch (bad_weak_ptr e) + catch (const bad_weak_ptr & e) { // cout << "don't have a mesh to visualize" << endl; VisualScene::DrawScene(); @@ -1120,7 +1120,7 @@ namespace netgen clipplanetimestamp = max2 (vispar.clipping.timestamp, solutiontimestamp); } - catch (bad_weak_ptr e) + catch (const bad_weak_ptr & e) { PrintMessage (3, "vssolution::buildscene: don't have a mesh to visualize"); VisualScene::BuildScene (zoomall); diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index 8b6a245b7..139685c5a 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -194,7 +194,7 @@ namespace netgen if(mesh->GetGeometry()) ng_geometry = mesh->GetGeometry(); } - catch (NgException e) + catch (const NgException & e) { PrintMessage (3, e.What()); return TCL_ERROR; @@ -269,7 +269,7 @@ namespace netgen geometry -> LoadSurfaces(infile); } } - catch (NgException e) + catch (const NgException & e) { PrintMessage (3, e.What()); return TCL_ERROR; @@ -551,7 +551,7 @@ namespace netgen } } - catch (NgException e) + catch (const NgException & e) { Tcl_SetResult (interp, const_cast (e.What().c_str()), TCL_VOLATILE); return TCL_ERROR; @@ -582,7 +582,7 @@ namespace netgen { ng_geometry -> Save (string (cfilename)); } - catch (NgException e) + catch (const NgException & e) { Tcl_SetResult (interp, const_cast (e.What().c_str()), TCL_VOLATILE); return TCL_ERROR; @@ -1440,7 +1440,7 @@ namespace netgen PrintMessage (1, "Meshing done, time = ", GetTime(), " sec"); } - catch (NgException e) + catch (const NgException & e) { cout << e.What() << endl; }