Skip to content

Commit

Permalink
Merge branch 'develop' into mish2/stress_extrapolation
Browse files Browse the repository at this point in the history
  • Loading branch information
white238 authored Aug 8, 2024
2 parents 61ae643 + fb6fab7 commit 67fa85f
Show file tree
Hide file tree
Showing 24 changed files with 194 additions and 94 deletions.
2 changes: 2 additions & 0 deletions cmake/SeracBasics.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ else()
endif()
option(SERAC_ENABLE_CODE_CHECKS "Enable Serac's code checks" ${_enable_serac_code_checks})

cmake_dependent_option(SERAC_ENABLE_TESTS "Enables Serac Tests" ON "ENABLE_TESTS" OFF)

#------------------------------------------------------------------------------
# Profiling options
#------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ if (ENABLE_DOCS)
add_subdirectory(docs)
endif()

if(ENABLE_TESTS)
if(SERAC_ENABLE_TESTS)
add_subdirectory(tests)
endif()
3 changes: 2 additions & 1 deletion src/docs/sphinx/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ one of the following commands:
If you built the dependencies using Spack/uberenv, the host-config file is output at the
project root. To use the pre-built dependencies on LC, you must be in the appropriate
LC group. Contact `Jamie Bramwell <bramwell1@llnl.gov>`_ for access.
LC group. Contact `Brandon Talamini <talamini1@llnl.gov>`_ for access.

Some build options frequently used by Serac include:

* ``CMAKE_BUILD_TYPE``: Specifies the build type, see the `CMake docs <https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html>`_
* ``ENABLE_BENCHMARKS``: Enables Google Benchmark performance tests, defaults to ``OFF``
* ``ENABLE_WARNINGS_AS_ERRORS``: Turns compiler warnings into errors, defaults to ``ON``
* ``ENABLE_ASAN``: Enables the Address Sanitizer for memory safety inspections, defaults to ``OFF``
* ``SERAC_ENABLE_TESTS``: Enables Serac unit tests, defaults to ``ON``
* ``SERAC_ENABLE_CODEVELOP``: Enables local development build of MFEM/Axom, see :ref:`codevelop-label`, defaults to ``OFF``
* ``SERAC_USE_VDIM_ORDERING``: Sets the vector ordering to be ``byVDIM``, which is significantly faster for algebraic multigrid,
but may conflict with other packages if Serac is being used as a dependency, defaults to ``OFF``.
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ blt_add_executable( NAME serac_driver
OUTPUT_NAME serac
)

if (ENABLE_TESTS)
if (SERAC_ENABLE_TESTS)
set(input_files_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../data/input_files)

# Make sure running serac driver doesn't completely fail
Expand Down
8 changes: 4 additions & 4 deletions src/serac/infrastructure/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#
# SPDX-License-Identifier: (BSD-3-Clause)

if(ENABLE_TESTS)
add_subdirectory(tests)
endif()

# This file contains metadata that often changes (ie. git sha).
# Hide these changes in the source file so we do not force
# a full rebuild.
Expand Down Expand Up @@ -73,3 +69,7 @@ install(TARGETS serac_infrastructure
EXPORT serac-targets
DESTINATION lib
)

if(SERAC_ENABLE_TESTS)
add_subdirectory(tests)
endif()
6 changes: 6 additions & 0 deletions src/serac/infrastructure/initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ std::pair<int, int> initialize(int argc, char* argv[], MPI_Comm comm)
#endif

#ifdef SERAC_USE_PETSC

#ifdef SERAC_USE_SLEPC
mfem::MFEMInitializeSlepc(&argc, &argv);
#else
mfem::MFEMInitializePetsc(&argc, &argv);
#endif

#endif
// Initialize GPU (no-op if not enabled/available)
// TODO for some reason this causes errors on Lassen. We need to look into this ASAP.
Expand Down
7 changes: 6 additions & 1 deletion src/serac/infrastructure/terminator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ void exitGracefully(bool error)
}

#ifdef SERAC_USE_PETSC
#ifdef SERAC_USE_SLEPC
mfem::MFEMFinalizeSlepc();
#else
mfem::MFEMFinalizePetsc();
#endif
#endif

profiling::finalize();

int mpi_initialized = 0;
MPI_Initialized(&mpi_initialized);
Expand All @@ -61,7 +67,6 @@ void exitGracefully(bool error)
if (mpi_initialized && !mpi_finalized) {
MPI_Finalize();
}
profiling::finalize();

accelerator::terminateDevice();

Expand Down
8 changes: 4 additions & 4 deletions src/serac/infrastructure/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#
# SPDX-License-Identifier: (BSD-3-Clause)

set(test_dependencies gtest serac_physics serac_mesh)
set(infrastructure_test_depends serac_physics serac_mesh gtest)

set(infrastructure_tests
set(infrastructure_test_sources
error_handling.cpp
input.cpp
profiling.cpp)

serac_add_tests( SOURCES ${infrastructure_tests}
DEPENDS_ON ${test_dependencies})
serac_add_tests( SOURCES ${infrastructure_test_sources}
DEPENDS_ON ${infrastructure_test_depends})
8 changes: 4 additions & 4 deletions src/serac/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#
# SPDX-License-Identifier: (BSD-3-Clause)

if(ENABLE_TESTS)
add_subdirectory(tests)
endif()

set(mesh_headers
mesh_utils.hpp
mesh_utils_base.hpp
Expand All @@ -32,3 +28,7 @@ install(TARGETS serac_mesh
EXPORT serac-targets
DESTINATION lib
)

if(SERAC_ENABLE_TESTS)
add_subdirectory(tests)
endif()
14 changes: 7 additions & 7 deletions src/serac/mesh/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
#
# SPDX-License-Identifier: (BSD-3-Clause)

set(test_dependencies gtest serac_numerics serac_mesh serac_boundary_conditions)
set(mesh_test_depends serac_numerics serac_mesh serac_boundary_conditions gtest)

set(mesh_parallel_tests
set(mesh_parallel_test_sources
mesh_test.cpp
)

serac_add_tests( SOURCES ${mesh_parallel_tests}
DEPENDS_ON ${test_dependencies}
serac_add_tests( SOURCES ${mesh_parallel_test_sources}
DEPENDS_ON ${mesh_test_depends}
NUM_MPI_TASKS 2)

set(mesh_serial_tests
set(mesh_serial_test_sources
mesh_generation.cpp
)

serac_add_tests( SOURCES ${mesh_serial_tests}
DEPENDS_ON ${test_dependencies}
serac_add_tests( SOURCES ${mesh_serial_test_sources}
DEPENDS_ON ${mesh_test_depends}
NUM_MPI_TASKS 1)
8 changes: 4 additions & 4 deletions src/serac/numerics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

add_subdirectory(functional)

if(ENABLE_TESTS)
add_subdirectory(tests)
endif()

set(numerics_headers
equation_solver.hpp
odes.hpp
Expand Down Expand Up @@ -39,3 +35,7 @@ install(TARGETS serac_numerics
EXPORT serac-targets
DESTINATION lib
)

if(SERAC_ENABLE_TESTS)
add_subdirectory(tests)
endif()
2 changes: 1 addition & 1 deletion src/serac/numerics/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ install(TARGETS serac_functional
DESTINATION lib
)

if(ENABLE_TESTS)
if(SERAC_ENABLE_TESTS)
add_subdirectory(tests)
endif()
26 changes: 14 additions & 12 deletions src/serac/numerics/functional/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
#
# SPDX-License-Identifier: (BSD-3-Clause)

set(functional_test_depends gtest serac_functional ${functional_depends})

# This test is all constexpr-evaluated, so it doesn't
# actually need to run, if it compiles without error, the tests have passed
blt_add_executable(NAME tensor_unit_tests
SOURCES tensor_unit_tests.cpp
OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY}
DEPENDS_ON gtest serac_functional ${functional_depends}
DEPENDS_ON ${functional_test_depends}
FOLDER serac/tests)

# Then add the examples/tests
set(functional_tests_serial
set(functional_serial_test_sources
functional_shape_derivatives.cpp
simplex_basis_function_unit_tests.cpp
bug_boundary_qoi.cpp
Expand All @@ -25,13 +27,13 @@ set(functional_tests_serial
tuple_arithmetic_unit_tests.cpp
test_newton.cpp)

serac_add_tests( SOURCES ${functional_tests_serial}
DEPENDS_ON gtest serac_functional ${functional_depends})
serac_add_tests(SOURCES ${functional_serial_test_sources}
DEPENDS_ON ${functional_test_depends})

set_source_files_properties(functional_tet_quality PROPERTIES LANGUAGE CXX)

# Then add the examples/tests
set(functional_tests_mpi
set(functional_parallel_test_sources
#functional_basic_hcurl.cpp
functional_with_domain.cpp
functional_basic_h1_scalar.cpp
Expand All @@ -44,27 +46,27 @@ set(functional_tests_mpi
functional_comparison_L2.cpp
)

serac_add_tests( SOURCES ${functional_tests_mpi}
DEPENDS_ON gtest serac_functional serac_state ${functional_depends}
NUM_MPI_TASKS 4 )
serac_add_tests(SOURCES ${functional_parallel_test_sources}
DEPENDS_ON ${functional_test_depends}
NUM_MPI_TASKS 4 )

foreach(filename ${functional_tests_mpi})
foreach(filename ${functional_parallel_test_sources})
set_source_files_properties(${filename} PROPERTIES LANGUAGE CXX)
endforeach()

target_link_libraries(bug_boundary_qoi PUBLIC serac_physics)

if(ENABLE_CUDA)

set(functional_tests_cuda
set(functional_cuda_test_sources
tensor_unit_tests_cuda.cu
# some of the GPU functionality is temporarily disabled to
# help incrementally roll-out the variadic implementation of Functional
# TODO: re-enable GPU kernels in a follow-up PR
# functional_comparisons_cuda.cu
)

serac_add_tests( SOURCES ${functional_tests_cuda}
DEPENDS_ON gtest serac_functional serac_state ${functional_depends})
serac_add_tests( SOURCES ${functional_cuda_test_sources}
DEPENDS_ON ${functional_test_depends})

endif()
26 changes: 20 additions & 6 deletions src/serac/numerics/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@
#
# SPDX-License-Identifier: (BSD-3-Clause)

set(test_dependencies gtest serac_numerics serac_boundary_conditions)
set(numerics_test_dependencies serac_numerics serac_boundary_conditions gtest)

set(numerics_serial_tests
set(numerics_serial_test_sources
equationsolver.cpp
operator.cpp
odes.cpp
)

serac_add_tests( SOURCES ${numerics_serial_tests}
DEPENDS_ON ${test_dependencies}
serac_add_tests( SOURCES ${numerics_serial_test_sources}
DEPENDS_ON ${numerics_test_dependencies}
NUM_MPI_TASKS 1)

if(PETSC_FOUND)
serac_add_tests(SOURCES equationsolver_petsc.cpp
DEPENDS_ON ${test_dependencies}
set(petsc_solver_tests
equationsolver_petsc.cpp
)
serac_add_tests(SOURCES ${petsc_solver_tests}
DEPENDS_ON ${numerics_test_dependencies}
NUM_MPI_TASKS 1)

if(SLEPC_FOUND)
set(slepc_solver_tests
eigensolver.cpp
)
serac_add_tests(SOURCES ${slepc_solver_tests}
DEPENDS_ON ${numerics_test_dependencies}
NUM_MPI_TASKS 2)
endif()

endif()

71 changes: 71 additions & 0 deletions src/serac/numerics/tests/eigensolver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
// other Serac Project Developers. See the top-level LICENSE file for
// details.
//
// SPDX-License-Identifier: (BSD-3-Clause)

#include <gtest/gtest.h>
#include "mfem.hpp"
#include "serac/infrastructure/initialize.hpp"
#include "serac/infrastructure/terminator.hpp"
#include "petsc.h"

#ifndef MFEM_USE_SLEPC
#error This examples requires that MFEM is build with MFEM_USE_SLEPC=YES
#endif

TEST(PETSC_AND_SLEPC, CanComputeSmallestEigenvalueAndEigenvectors)
{
int world_rank;
MPI_Comm comm;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_split(MPI_COMM_WORLD, (0 != world_rank) ? MPI_UNDEFINED : 0, 0, &comm);
if (world_rank != 0) return;

Mat A; /* problem matrix */
int N = 6;
unsigned int M = 3;
MatCreate(comm, &A);
MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, N, N);
MatSetFromOptions(A);

int Istart, Iend;
MatGetOwnershipRange(A, &Istart, &Iend);
for (int i = Istart; i < Iend; i++) {
MatSetValue(A, i, i, i - 2, INSERT_VALUES);
}

MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);

mfem::Vector v, w;
v.SetSize(N);
w.SetSize(N);

mfem::SlepcEigenSolver eig(comm);
eig.SetNumModes(static_cast<int>(M));
eig.SetWhichEigenpairs(mfem::SlepcEigenSolver::SMALLEST_REAL);
// eig.SetWhichEigenpairs(mfem::SlepcEigenSolver::LARGEST_MAGNITUDE);
eig.SetOperator(A);
eig.Solve();

EXPECT_GE(eig.GetNumConverged(), M);

for (unsigned int i = 0; i < M; ++i) {
eig.GetEigenvector(i, v);
double eval;
eig.GetEigenvalue(i, eval);
EXPECT_NEAR(eval, static_cast<double>(i) - 2.0, 1e-14);
}
}

int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
serac::initialize(argc, argv);

int result = RUN_ALL_TESTS();

serac::exitGracefully();
return result;
}
Loading

0 comments on commit 67fa85f

Please sign in to comment.