From 4f10fc4fa0bb967c9e16d112b982ab79b3c0a148 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 7 Aug 2023 01:01:53 +0200 Subject: [PATCH] modernize C++: use emplace --- src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp | 10 ++-- .../MeshPart/App/MeshFlatteningLscmRelax.cpp | 48 +++++++++---------- src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp | 5 +- src/Mod/Part/App/PropertyTopoShapeList.cpp | 2 +- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp b/src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp index adf05bc409..4c647f772b 100644 --- a/src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp +++ b/src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp @@ -44,16 +44,16 @@ DlgSettingsFemGeneralImp::DlgSettingsFemGeneralImp(QWidget* parent) std::vector Solvers = {"None"}; if (!Fem::Tools::checkIfBinaryExists("CCX", "ccx", "ccx").empty()) - Solvers.push_back("CalculiX"); + Solvers.emplace_back("CalculiX"); if (!Fem::Tools::checkIfBinaryExists("Elmer", "elmer", "ElmerSolver").empty()) - Solvers.push_back("Elmer"); + Solvers.emplace_back("Elmer"); // also check the multi-CPU Elmer build else if (!Fem::Tools::checkIfBinaryExists("Elmer", "elmer", "ElmerSolver_mpi").empty()) - Solvers.push_back("Elmer"); + Solvers.emplace_back("Elmer"); if (!Fem::Tools::checkIfBinaryExists("Mystran", "mystran", "mystran").empty()) - Solvers.push_back("Mystran"); + Solvers.emplace_back("Mystran"); if (!Fem::Tools::checkIfBinaryExists("Z88", "z88", "z88r").empty()) - Solvers.push_back("Z88"); + Solvers.emplace_back("Z88"); QStringList solversList; for (auto item : Solvers) { diff --git a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp index 627145f3de..e462d76e9a 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp @@ -198,10 +198,10 @@ void LscmRelax::relax(double weight) for (int k=0; k < 3; k++) { col_pos = this->triangles(k, i); - K_g_triplets.push_back(trip(row_pos * 2, col_pos * 2, K_m(j * 2, k * 2))); - K_g_triplets.push_back(trip(row_pos * 2 + 1, col_pos * 2, K_m(j * 2 + 1, k * 2))); - K_g_triplets.push_back(trip(row_pos * 2 + 1, col_pos * 2 + 1, K_m(j * 2 + 1, k * 2 + 1))); - K_g_triplets.push_back(trip(row_pos * 2, col_pos * 2 + 1, K_m(j * 2, k * 2 + 1))); + K_g_triplets.emplace_back(trip(row_pos * 2, col_pos * 2, K_m(j * 2, k * 2))); + K_g_triplets.emplace_back(trip(row_pos * 2 + 1, col_pos * 2, K_m(j * 2 + 1, k * 2))); + K_g_triplets.emplace_back(trip(row_pos * 2 + 1, col_pos * 2 + 1, K_m(j * 2 + 1, k * 2 + 1))); + K_g_triplets.emplace_back(trip(row_pos * 2, col_pos * 2 + 1, K_m(j * 2, k * 2 + 1))); // we don't have to fill all because the matrix is symmetric. } } @@ -253,16 +253,16 @@ void LscmRelax::relax(double weight) for (long i=0; i < this->flat_vertices.cols() ; i++) { // fixing total ux - K_g_triplets.push_back(trip(i * 2, this->flat_vertices.cols() * 2, 1)); - K_g_triplets.push_back(trip(this->flat_vertices.cols() * 2, i * 2, 1)); + K_g_triplets.emplace_back(trip(i * 2, this->flat_vertices.cols() * 2, 1)); + K_g_triplets.emplace_back(trip(this->flat_vertices.cols() * 2, i * 2, 1)); // fixing total uy - K_g_triplets.push_back(trip(i * 2 + 1, this->flat_vertices.cols() * 2 + 1, 1)); - K_g_triplets.push_back(trip(this->flat_vertices.cols() * 2 + 1, i * 2 + 1, 1)); + K_g_triplets.emplace_back(trip(i * 2 + 1, this->flat_vertices.cols() * 2 + 1, 1)); + K_g_triplets.emplace_back(trip(this->flat_vertices.cols() * 2 + 1, i * 2 + 1, 1)); // fixing ux*y-uy*x - K_g_triplets.push_back(trip(i * 2, this->flat_vertices.cols() * 2 + 2, - this->flat_vertices(1, i))); - K_g_triplets.push_back(trip(this->flat_vertices.cols() * 2 + 2, i * 2, - this->flat_vertices(1, i))); - K_g_triplets.push_back(trip(i * 2 + 1, this->flat_vertices.cols() * 2 + 2, this->flat_vertices(0, i))); - K_g_triplets.push_back(trip(this->flat_vertices.cols() * 2 + 2, i * 2 + 1, this->flat_vertices(0, i))); + K_g_triplets.emplace_back(trip(i * 2, this->flat_vertices.cols() * 2 + 2, - this->flat_vertices(1, i))); + K_g_triplets.emplace_back(trip(this->flat_vertices.cols() * 2 + 2, i * 2, - this->flat_vertices(1, i))); + K_g_triplets.emplace_back(trip(i * 2 + 1, this->flat_vertices.cols() * 2 + 2, this->flat_vertices(0, i))); + K_g_triplets.emplace_back(trip(this->flat_vertices.cols() * 2 + 2, i * 2 + 1, this->flat_vertices(0, i))); } // project out the nullspace solution: @@ -334,7 +334,7 @@ void LscmRelax::area_relax(double weight) for(auto col: range_6) { - K_g_triplets.push_back(trip(i, indices[col], (double) B[col])); + K_g_triplets.emplace_back(trip(i, indices[col], (double) B[col])); } } K_g_lsq.setFromTriplets(K_g_triplets.begin(), K_g_triplets.end()); @@ -403,7 +403,7 @@ void LscmRelax::edge_relax(double weight) { for (auto col: range_4) { - K_g_triplets.push_back(trip(indices[row], indices[col], (double) K(row, col))); + K_g_triplets.emplace_back(trip(indices[row], indices[col], (double) K(row, col))); } rhs(indices[row]) += rhs_m[row]; } @@ -436,17 +436,17 @@ void LscmRelax::lscm() y31 = this->q_l_g(i, 2); x32 = x31 - x21; - triple_list.push_back(trip(2 * i, this->new_order[this->triangles(0, i)] * 2, x32)); - triple_list.push_back(trip(2 * i, this->new_order[this->triangles(0, i)] * 2 + 1, -y31)); - triple_list.push_back(trip(2 * i, this->new_order[this->triangles(1, i)] * 2, -x31)); - triple_list.push_back(trip(2 * i, this->new_order[this->triangles(1, i)] * 2 + 1, y31)); - triple_list.push_back(trip(2 * i, this->new_order[this->triangles(2, i)] * 2, x21)); + triple_list.emplace_back(trip(2 * i, this->new_order[this->triangles(0, i)] * 2, x32)); + triple_list.emplace_back(trip(2 * i, this->new_order[this->triangles(0, i)] * 2 + 1, -y31)); + triple_list.emplace_back(trip(2 * i, this->new_order[this->triangles(1, i)] * 2, -x31)); + triple_list.emplace_back(trip(2 * i, this->new_order[this->triangles(1, i)] * 2 + 1, y31)); + triple_list.emplace_back(trip(2 * i, this->new_order[this->triangles(2, i)] * 2, x21)); - triple_list.push_back(trip(2 * i + 1, this->new_order[this->triangles(0, i)] * 2, y31)); - triple_list.push_back(trip(2 * i + 1, this->new_order[this->triangles(0, i)] * 2 + 1, x32)); - triple_list.push_back(trip(2 * i + 1, this->new_order[this->triangles(1, i)] * 2, -y31)); - triple_list.push_back(trip(2 * i + 1, this->new_order[this->triangles(1, i)] * 2 + 1, -x31)); - triple_list.push_back(trip(2 * i + 1, this->new_order[this->triangles(2, i)] * 2 + 1, x21)); + triple_list.emplace_back(trip(2 * i + 1, this->new_order[this->triangles(0, i)] * 2, y31)); + triple_list.emplace_back(trip(2 * i + 1, this->new_order[this->triangles(0, i)] * 2 + 1, x32)); + triple_list.emplace_back(trip(2 * i + 1, this->new_order[this->triangles(1, i)] * 2, -y31)); + triple_list.emplace_back(trip(2 * i + 1, this->new_order[this->triangles(1, i)] * 2 + 1, -x31)); + triple_list.emplace_back(trip(2 * i + 1, this->new_order[this->triangles(2, i)] * 2 + 1, x21)); } // 2. divide the triplets in matrix(unknown part) and rhs(known part) and reset the position diff --git a/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp b/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp index 602837af1b..db35df9087 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp @@ -200,8 +200,9 @@ void add_triplets(Eigen::VectorXd values, double row, std::vector &triplet { for (unsigned int i=0; i < values.size(); i++) { - if (values(i) != 0.) - triplets.push_back(trip(row, i, values(i))); + if (values(i) != 0.) { + triplets.emplace_back(trip(row, i, values(i))); + } } } diff --git a/src/Mod/Part/App/PropertyTopoShapeList.cpp b/src/Mod/Part/App/PropertyTopoShapeList.cpp index eb7bf6adb8..e12a62a4eb 100644 --- a/src/Mod/Part/App/PropertyTopoShapeList.cpp +++ b/src/Mod/Part/App/PropertyTopoShapeList.cpp @@ -189,7 +189,7 @@ App::Property *PropertyTopoShapeList::Copy() const for (auto& shape : _lValueList) { BRepBuilderAPI_Copy copy(shape.getShape()); TopoDS_Shape* newShape = new TopoDS_Shape(copy.Shape()); - copiedShapes.push_back(*newShape); + copiedShapes.emplace_back(*newShape); } p->setValues(copiedShapes); return p;