Skip to content

Commit

Permalink
Fix up some compilation errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
tupek2 committed Dec 11, 2024
1 parent 42c532f commit 92e28a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
34 changes: 10 additions & 24 deletions src/serac/numerics/tests/test_trust_region_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct MeshFixture : public testing::Test {
mfem::ParMesh* mesh;
};

std::vector<mfem::Vector> applyLinearOperator(const Mat& A, const std::vector<mfem::Vector*>& states)
std::vector<mfem::Vector> applyLinearOperator(const Mat& A, const std::vector<const mfem::Vector*>& states)
{
std::vector<mfem::Vector> Astates;
for (auto s : states) {
Expand Down Expand Up @@ -133,37 +133,23 @@ TEST_F(MeshFixture, QR)
a[i] = 2 * i + 0.01 * i * i + 1.25;
b[i] = -i + 0.02 * i * i + 0.1;
}
std::vector<mfem::Vector*> states = {&u1, &u2, &u3}; //,u4};

/*
for (int s=0; s < states.size(); ++s) {
for (int i=0; i < u1.Size(); ++i) {
std::cout << states[s][i] << " ";
}
printf("\n");
}
for (int i=0; i < u1.Size(); ++i) {
std::cout << a[i] << " ";
}
printf("\n");
for (int i=0; i < u1.Size(); ++i) {
std::cout << b[i] << " ";
}
printf("\n");
*/
std::vector<const mfem::Vector*> states = {&u1, &u2, &u3}; //,u4};

auto A_parallel = createDiagonalTestMatrix(a);
std::vector<mfem::Vector> Astates = applyLinearOperator(A_parallel, states);

std::vector<mfem::Vector*> AstatePtrs;
std::vector<const mfem::Vector*> AstatePtrs;
for (size_t i = 0; i < Astates.size(); ++i) {
AstatePtrs.push_back(&Astates[i]);
}

double delta = 3.4; // 0.001;
auto [sol, leftvecs, leftvals] = serac::solveSubspaceProblem(states, AstatePtrs, b, delta, 1);
double delta = 0.001;
auto [sol, leftvecs, leftvals, energy] = serac::solveSubspaceProblem(states, AstatePtrs, b, delta, 1);

serac::FiniteElementState serac_sol(b);
serac_sol = sol;

ASSERT_NEAR( std::sqrt(serac::innerProduct(serac_sol, serac_sol)), delta, 1e-12 );

MatDestroy(&A_parallel);
}
Expand Down
18 changes: 9 additions & 9 deletions src/serac/numerics/trust_region_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct BasisVectors {
PetscInt iStart, iEnd;
VecGetOwnershipRange(v, &iStart, &iEnd);

col_indices.reserve(static_cast<size_t>(local_rows));
col_indices.reserve(size_t(local_rows));
for (int i = iStart; i < iEnd; ++i) {
col_indices.push_back(i);
}
Expand Down Expand Up @@ -260,8 +260,8 @@ auto exactTrustRegionSolve(DenseMat A, const DenseVec& b, double delta, int num_
auto [sigs, V] = eigh(A);
std::vector<DenseVec> leftmosts;
std::vector<double> minsigs;
int num_leftmost_possible = std::min(num_leftmost, int(isize));
for (int i = 0; i < num_leftmost_possible; ++i) {
size_t num_leftmost_possible(size_t(std::min(num_leftmost, isize)));
for (size_t i = 0; i < num_leftmost_possible; ++i) {
leftmosts.emplace_back(V[i]);
minsigs.emplace_back(sigs[i]);
}
Expand Down Expand Up @@ -299,7 +299,7 @@ auto exactTrustRegionSolve(DenseMat A, const DenseVec& b, double delta, int num_
DenseVec p(isize);
p = 0.0;
for (int i = 0; i < isize; ++i) {
p.add(bv[i], V[i]);
p.add(bv[i], V[size_t(i)]);
}

const auto& z = leftMost;
Expand Down Expand Up @@ -351,7 +351,7 @@ auto exactTrustRegionSolve(DenseMat A, const DenseVec& b, double delta, int num_
DenseVec x(isize);
x = 0.0;
for (int i = 0; i < isize; ++i) {
x.add(bvOverSigs[i], V[i]);
x.add(bvOverSigs[i], V[size_t(i)]);
}

double e1 = quadraticEnergy(A, b, x);
Expand Down Expand Up @@ -400,8 +400,8 @@ std::tuple<mfem::Vector, std::vector<std::shared_ptr<mfem::Vector>>, std::vector
for (int i = 0; i < rows; ++i) {
if (R(i, i) < 1e-9 * trace_mag) {
// printf("removing after QR state number %d\n", i);
auto statesNew = remove_at(states, i);
auto AstatesNew = remove_at(Astates, i);
auto statesNew = remove_at(states, size_t(i));
auto AstatesNew = remove_at(Astates, size_t(i));
return solveSubspaceProblem(statesNew, AstatesNew, b, delta, num_leftmost);
}
}
Expand Down Expand Up @@ -451,12 +451,12 @@ std::pair<std::vector<const mfem::Vector*>, std::vector<const mfem::Vector*>> re
norms.push_back(std::sqrt(mfem::InnerProduct(PETSC_COMM_WORLD, *directions[i], *directions[i])));
}

std::vector<std::pair<const mfem::Vector*, int>> kepts;
std::vector<std::pair<const mfem::Vector*, size_t>> kepts;
for (size_t i = 0; i < num_dirs; ++i) {
bool keepi = true;
if (norms[i] == 0) keepi = false;
for (auto&& kept_and_j : kepts) {
int j = kept_and_j.second;
size_t j = kept_and_j.second;
double dot_ij = mfem::InnerProduct(PETSC_COMM_WORLD, *directions[i], *kept_and_j.first);
if (dot_ij > 0.999 * norms[i] * norms[j]) {
keepi = false;
Expand Down

0 comments on commit 92e28a2

Please sign in to comment.