modernize C++: use emplace

This commit is contained in:
wmayer
2023-08-07 01:01:53 +02:00
committed by Chris Hennes
parent 89d529ab7b
commit 4f10fc4fa0
4 changed files with 33 additions and 32 deletions

View File

@@ -44,16 +44,16 @@ DlgSettingsFemGeneralImp::DlgSettingsFemGeneralImp(QWidget* parent)
std::vector<std::string> 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) {

View File

@@ -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

View File

@@ -200,8 +200,9 @@ void add_triplets(Eigen::VectorXd values, double row, std::vector<trip> &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)));
}
}
}

View File

@@ -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;