Skip to content

Commit

Permalink
Move from utils to fem, CwiseSqrt, and more debris
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcars committed Oct 6, 2023
1 parent 78f0946 commit f536eec
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion palace/drivers/basesolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <complex>
#include <mfem.hpp>
#include <nlohmann/json.hpp>
#include "fem/errorindicators.hpp"
#include "linalg/ksp.hpp"
#include "models/domainpostoperator.hpp"
#include "models/postoperator.hpp"
#include "models/surfacepostoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/filesystem.hpp"
#include "utils/iodata.hpp"
#include "utils/timer.hpp"
Expand Down
2 changes: 1 addition & 1 deletion palace/drivers/drivensolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <complex>
#include <mfem.hpp>
#include "fem/errorindicators.hpp"
#include "linalg/errorestimator.hpp"
#include "linalg/ksp.hpp"
#include "linalg/operator.hpp"
Expand All @@ -16,7 +17,6 @@
#include "models/surfacecurrentoperator.hpp"
#include "models/waveportoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/iodata.hpp"
#include "utils/prettyprint.hpp"
#include "utils/timer.hpp"
Expand Down
2 changes: 1 addition & 1 deletion palace/drivers/eigensolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "eigensolver.hpp"

#include <mfem.hpp>
#include "fem/errorindicators.hpp"
#include "linalg/arpack.hpp"
#include "linalg/divfree.hpp"
#include "linalg/errorestimator.hpp"
Expand All @@ -15,7 +16,6 @@
#include "models/postoperator.hpp"
#include "models/spaceoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/iodata.hpp"
#include "utils/timer.hpp"

Expand Down
2 changes: 1 addition & 1 deletion palace/drivers/electrostaticsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "electrostaticsolver.hpp"

#include <mfem.hpp>
#include "fem/errorindicators.hpp"
#include "linalg/errorestimator.hpp"
#include "linalg/ksp.hpp"
#include "linalg/operator.hpp"
#include "linalg/vector.hpp"
#include "models/laplaceoperator.hpp"
#include "models/postoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/iodata.hpp"
#include "utils/timer.hpp"

Expand Down
2 changes: 1 addition & 1 deletion palace/drivers/magnetostaticsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "magnetostaticsolver.hpp"

#include <mfem.hpp>
#include "fem/errorindicators.hpp"
#include "linalg/errorestimator.hpp"
#include "linalg/ksp.hpp"
#include "linalg/operator.hpp"
#include "models/curlcurloperator.hpp"
#include "models/postoperator.hpp"
#include "models/surfacecurrentoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/iodata.hpp"
#include "utils/timer.hpp"

Expand Down
2 changes: 1 addition & 1 deletion palace/drivers/transientsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "transientsolver.hpp"

#include <mfem.hpp>
#include "fem/errorindicators.hpp"
#include "linalg/errorestimator.hpp"
#include "linalg/vector.hpp"
#include "models/lumpedportoperator.hpp"
Expand All @@ -12,7 +13,6 @@
#include "models/surfacecurrentoperator.hpp"
#include "models/timeoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/excitations.hpp"
#include "utils/iodata.hpp"
#include "utils/timer.hpp"
Expand Down
7 changes: 4 additions & 3 deletions palace/fem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Add source files and subdirectories.
#

# target_sources(${TARGET_NAME}
# PRIVATE
# )
target_sources(${TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/errorindicators.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "errorindicators.hpp"

#include <fmt/os.h>
#include "utils/communication.hpp"

namespace palace
Expand Down Expand Up @@ -48,5 +48,4 @@ void ErrorIndicators::AddIndicators(const ErrorIndicators &error_indicators)
(*this) = error_indicators;
}
}

} // namespace palace
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#ifndef PALACE_UTILS_ERROR_INDICATORS_HPP
#define PALACE_UTILS_ERROR_INDICATORS_HPP
#ifndef PALACE_FEM_ERROR_INDICATORS_HPP
#define PALACE_FEM_ERROR_INDICATORS_HPP

#include "linalg/vector.hpp"
#include "utils/communication.hpp"
Expand Down Expand Up @@ -81,4 +81,4 @@ class ErrorIndicators

} // namespace palace

#endif // PALACE_UTILS_ERROR_INDICATORS_HPP
#endif // PALACE_FEM_ERROR_INDICATORS_HPP
12 changes: 3 additions & 9 deletions palace/linalg/errorestimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "errorestimator.hpp"
#include <limits>
#include "fem/coefficient.hpp"
#include "fem/errorindicators.hpp"
#include "fem/integrator.hpp"
#include "fem/multigrid.hpp"
#include "linalg/amg.hpp"
Expand All @@ -12,7 +13,6 @@
#include "linalg/rap.hpp"
#include "models/materialoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/iodata.hpp"
#include "utils/timer.hpp"

Expand Down Expand Up @@ -162,10 +162,7 @@ ErrorIndicators CurlFluxErrorEstimator::ComputeIndicators(const ComplexVector &v
}
}
}
for (auto &e : estimates)
{
e = std::sqrt(e);
}
linalg::CwiseSqrt(estimates);

Mpi::GlobalSum(1, &normalization, nd_fespace.GetComm());
normalization = std::sqrt(normalization);
Expand Down Expand Up @@ -306,10 +303,7 @@ ErrorIndicators GradFluxErrorEstimator::ComputeIndicators(const Vector &v) const
paraview.Save();
}
}
for (auto &e : estimates)
{
e = std::sqrt(e);
}
linalg::CwiseSqrt(estimates);

Mpi::GlobalSum(1, &normalization, h1_fespace.GetComm());
normalization = std::sqrt(normalization);
Expand Down
2 changes: 1 addition & 1 deletion palace/linalg/errorestimator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#include <memory>
#include <mfem.hpp>
#include "fem/errorindicators.hpp"
#include "linalg/ksp.hpp"
#include "linalg/operator.hpp"
#include "linalg/vector.hpp"
#include "utils/errorindicators.hpp"

namespace palace
{
Expand Down
7 changes: 7 additions & 0 deletions palace/linalg/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ void SetRandomSign(MPI_Comm comm, ComplexVector &x, int seed)
{ XI[i] = (XI[i] > 0.0) ? 1.0 : ((XI[i] < 0.0) ? -1.0 : 0.0); });
}

void CwiseSqrt(Vector &x)
{
const int N = x.Size();
auto *X = x.ReadWrite();
mfem::forall(N, [=] MFEM_HOST_DEVICE(int i) { X[i] = std::sqrt(X[i]); });
}

template <>
void SetSubVector(Vector &x, const mfem::Array<int> &rows, double s)
{
Expand Down
3 changes: 3 additions & 0 deletions palace/linalg/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ void SetRandomReal(MPI_Comm comm, VecType &x, int seed = 0);
template <typename VecType>
void SetRandomSign(MPI_Comm comm, VecType &x, int seed = 0);

// Component-wise square root.
void CwiseSqrt(Vector &x);

// Calculate the inner product yᴴ x or yᵀ x.
template <typename VecType>
inline auto Dot(MPI_Comm comm, const VecType &x, const VecType &y)
Expand Down
2 changes: 1 addition & 1 deletion palace/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "drivers/electrostaticsolver.hpp"
#include "drivers/magnetostaticsolver.hpp"
#include "drivers/transientsolver.hpp"
#include "fem/errorindicators.hpp"
#include "linalg/slepc.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/geodata.hpp"
#include "utils/iodata.hpp"
#include "utils/timer.hpp"
Expand Down
2 changes: 1 addition & 1 deletion palace/models/postoperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "postoperator.hpp"

#include "fem/coefficient.hpp"
#include "fem/errorindicators.hpp"
#include "models/curlcurloperator.hpp"
#include "models/laplaceoperator.hpp"
#include "models/lumpedportoperator.hpp"
Expand All @@ -12,7 +13,6 @@
#include "models/surfacecurrentoperator.hpp"
#include "models/waveportoperator.hpp"
#include "utils/communication.hpp"
#include "utils/errorindicators.hpp"
#include "utils/geodata.hpp"
#include "utils/iodata.hpp"

Expand Down
1 change: 0 additions & 1 deletion palace/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
target_sources(${TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/configfile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/errorindicators.cpp
${CMAKE_CURRENT_SOURCE_DIR}/geodata.cpp
${CMAKE_CURRENT_SOURCE_DIR}/iodata.cpp
${CMAKE_CURRENT_SOURCE_DIR}/meshio.cpp
Expand Down

0 comments on commit f536eec

Please sign in to comment.