Skip to content

Commit

Permalink
Update function docs and fix abs error
Browse files Browse the repository at this point in the history
  • Loading branch information
ckendrick committed Apr 2, 2024
1 parent 92c3c45 commit b8caa16
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/prom/elliptic_eigenproblem_global_rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ double Potential(const Vector &x)
// min_d is the lower bound of the atom distance over time

// verify t is within inner 20% of domain (centered around mesh origin)
CAROM::check_within_portion(bb_min, bb_max, center, 0.2);
CAROM::verify_within_portion(bb_min, bb_max, center, 0.2);

return -D * (std::exp(-X.DistanceSquaredTo(center) / std::pow(c * min_d,
2)) + std::exp(
Expand Down Expand Up @@ -929,7 +929,7 @@ double Potential(const Vector &x)
}

// verify t is within inner 20% of domain (centered around mesh origin)
CAROM::check_within_portion(bb_min, bb_max, center, 0.2);
CAROM::verify_within_portion(bb_min, bb_max, center, 0.2);

return -D * (std::exp(-X.DistanceSquaredTo(center) / std::pow(c * min_d,
2)) + std::exp(
Expand Down
12 changes: 8 additions & 4 deletions lib/mfem/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,21 @@ void ComputeCtAB_vec(const HypreParMatrix& A,
C.transposeMult(AB_carom, CtAB_vec);
}

void check_within_portion(const mfem::Vector &bb_min,
const mfem::Vector &bb_max, const mfem::Vector &t, const double limit)
void verify_within_portion(const mfem::Vector &bb_min,
const mfem::Vector &bb_max,
const mfem::Vector &t, const double limit)
{
// helper function to check if t is within limit percentage relative to the center of the mesh
// helper function to check if t is within limit percentage relative
// to the center of the mesh
CAROM_VERIFY(t.Size() == bb_min.Size() && bb_min.Size() == bb_max.Size());
CAROM_VERIFY(limit >= 0.0 && limit <= 1.0);
for (int i = 0; i < t.Size(); i++)
{
double domain_limit = limit * (bb_max[i] - bb_min[i]);
double mesh_center = 0.5 * (bb_max[i] + bb_min[i]);

// check that t is within the limit relative to the center of the mesh
if ((t(i) - mesh_center) - (0.5 * domain_limit) > 1.0e-14)
if (std::abs((t(i) - mesh_center)) - (0.5 * domain_limit) > 1.0e-14)
{
std::cerr << "Error: value of t exceeds domain limit: t = " << t(
i) << ", limit = " << 0.5 * domain_limit << "\n";
Expand Down
26 changes: 18 additions & 8 deletions lib/mfem/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,27 @@ void ComputeCtAB_vec(const HypreParMatrix& A,
CAROM::Vector& CtAB_vec);

/**
* @brief Helper function to ensure that @p t is within a given percentage of the domain relative to the center of the mesh
* @brief Helper function to ensure that @p t is within a given percentage of
* the domain relative to the center of the mesh. Performs the check for each
* dimension of the mesh (works if mesh is 2D or 3D).
*
* @param bb_min Minimum corner of mesh bounding box. See mfem::Mesh::GetBoundingBox().
* @param bb_min Minimum corner of mesh bounding box.
* See mfem::Mesh::GetBoundingBox().
*
* @param bb_max Maximum corner of mesh bounding box. See mfem::Mesh::GetBoundingBox().
* @param bb_max Maximum corner of mesh bounding box.
* See mfem::Mesh::GetBoundingBox().
*
* @param t Point to check if within given @p limit percentage of mesh domain relative to mesh center.
* @param t Point to check if within given @p limit percentage of mesh domain
* relative to mesh center.
*
* @param limit Fractional percentage (from [0, 1]) of mesh domain to check bounds of @p t.
* @param limit Fractional percentage (from [0, 1]) of mesh domain to check
* bounds of @p t.
*
* @note This will throw an error and exit if the check fails.
*/
void check_within_portion(const mfem::Vector &bb_min,
const mfem::Vector &bb_max, const mfem::Vector &t, const double limit);
void verify_within_portion(const mfem::Vector &bb_min,
const mfem::Vector &bb_max,
const mfem::Vector &t, const double limit);

/**
* @brief Maps a value from [-1, 1] to the corresponding mesh domain [bb_min, bb_max]
Expand All @@ -85,7 +94,8 @@ double map_to_ref_mesh(const double &bb_min, const double &bb_max,
const double &fraction);

/**
* @brief Maps a value within mesh domain [bb_min, bb_max] to the corresponding value between [-1, 1]
* @brief Maps a value within mesh domain [bb_min, bb_max] to the corresponding
* value between [-1, 1]
*
* @param bb_min Minimum value of domain
*
Expand Down

0 comments on commit b8caa16

Please sign in to comment.