Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Refactor PDE operator for multigrid #401

Draft
wants to merge 24 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Checks: >
cppcoreguidelines-*,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-avoid-magic-numbers,
hicpp-*,
misc-*,
-misc-non-private-member-variables-in-classes,
Expand All @@ -19,5 +20,6 @@ Checks: >
readability-*,
-readability-else-after-return,
-readability-identifier-length,
-readability-magic-numbers,

WarningsAsErrors: '*'
1 change: 0 additions & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
pull_request:
branches:
- master
- devel
types:
- opened
- reopened
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
pull_request:
branches:
- master
- devel
types:
- opened
- reopened
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ main
#Output files
applications/*/*.vtk
*.vtu
*.pvtu
*.vts
*.frt
integratedFields.txt
Expand Down
4 changes: 2 additions & 2 deletions applications/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "core/variableAttributes.h"
#include "equations.cc"

#include <core/ParseCommandLineOpts.h>
#include <core/inputFileReader.h>
#include <core/parse_cmd_options.h>
#include <core/variableAttributeLoader.h>

// Header file for postprocessing that may or may not exist
Expand Down Expand Up @@ -38,7 +38,7 @@ main(int argc, char **argv)
std::string parameters_filename;
try
{
ParseCommandLineOpts cli_options(argc, argv);
parseCMDOptions cli_options(argc, argv);
parameters_filename = cli_options.getParametersFilename();
}
catch (const char *msg)
Expand Down
157 changes: 157 additions & 0 deletions applications/multigrid_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
##
# CMake script for the PRISMS-PF applications
# Adapted from the ASPECT CMake file
##

cmake_minimum_required(VERSION 3.3.0)

project(myapp)

message(STATUS "")
message(STATUS "=========================================================")
message(STATUS "Configuring PRISMS-PF application")
message(STATUS "=========================================================")
message(STATUS "")

# Setup the build type (debug, release, debugrelease)
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "DebugRelease"
CACHE STRING
"Choose the type of build, options are: Debug, Release and DebugRelease."
FORCE)
endif()

# Convert build type into the debug and release builds, which may or may
# not be built.
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease" )
message(STATUS "Setting up PRISMS-PF application for ${CMAKE_BUILD_TYPE} mode.")
else()
message(FATAL_ERROR
"CMAKE_BUILD_TYPE must either be 'Release', 'Debug', or 'DebugRelease', but is set to '${CMAKE_BUILD_TYPE}'.")
endif()

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease")
set(PRISMS_PF_BUILD_DEBUG "ON")
else()
set(PRISMS_PF_BUILD_DEBUG "OFF")
endif()

if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease")
set(PRISMS_PF_BUILD_RELEASE "ON")
else()
set(PRISMS_PF_BUILD_RELEASE "OFF")
endif()

# Find deal.II installation
find_package(deal.II 9.6.0 QUIET
HINTS ${DEAL_II_DIR} $ENV{DEAL_II_DIR}
)
if(NOT ${deal.II_FOUND})
message(FATAL_ERROR "\n*** Could not find a recent version of deal.II. ***\n"
"You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake "
"or set an environment variable \"DEAL_II_DIR\" that contains a path to a "
"recent version of deal.II."
)
endif()

message(STATUS "Found deal.II version ${DEAL_II_PACKAGE_VERSION} at '${deal.II_DIR}'")

set(DEALII_INSTALL_VALID ON)

if(NOT DEAL_II_WITH_P4EST)
message(SEND_ERROR
"\n**deal.II was built without support for p4est!\n"
)
set(DEALII_INSTALL_VALID OFF)
endif()

if(NOT DEALII_INSTALL_VALID)
message(FATAL_ERROR
"\nPRISMS-PF requires a deal.II installation with certain features enabled!\n"
)
endif()

deal_ii_initialize_cached_variables()

# Make and ninja build options
if(CMAKE_GENERATOR MATCHES "Ninja")
set(_make_command "$ ninja")
else()
set(_make_command " $ make")
endif()

# Debug and release targets
if(${DEAL_II_BUILD_TYPE} MATCHES "DebugRelease")
add_custom_target(release
COMMAND ${CMAKE_COMMAND} -D CMAKE_BUILD_TYPE=Release .
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMAND ${CMAKE_COMMAND} -E echo "*** Switched to Release mode. Now recompile with: ${_make_command}"
COMMAND ${CMAKE_COMMAND} -E echo "***"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
COMMENT "switching to RELEASE mode..."
)

add_custom_target(debug
COMMAND ${CMAKE_COMMAND} -D CMAKE_BUILD_TYPE=Debug .
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMAND ${CMAKE_COMMAND} -E echo "*** Switched to Debug mode. Now recompile with: ${_make_command}"
COMMAND ${CMAKE_COMMAND} -E echo "***"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
COMMENT "switching to DEBUG mode..."
)

add_custom_target(debugrelease
COMMAND ${CMAKE_COMMAND} -D CMAKE_BUILD_TYPE=DebugRelease .
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMAND ${CMAKE_COMMAND} -E echo "*** Switched to Debug and Release mode. Now recompile with: ${_make_command}"
COMMAND ${CMAKE_COMMAND} -E echo "***"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
COMMENT "switching to DEBUG/RELEASE mode..."
)
endif()

# Add distclean target to clean build
add_custom_target(distclean
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target clean
COMMAND ${CMAKE_COMMAND} -E remove_directory CMakeFiles
COMMAND ${CMAKE_COMMAND} -E remove
CMakeCache.txt cmake_install.cmake Makefile
build.ninja rules.ninja .ninja_deps .ninja_log
COMMENT "distclean invoked"
)

# Set location of files
include_directories(${CMAKE_SOURCE_DIR}/../../include)
include_directories(${CMAKE_SOURCE_DIR}/../../src)
include_directories(${CMAKE_SOURCE_DIR})

# Set the location of the main.cc file
set(TARGET_SRC "${CMAKE_SOURCE_DIR}/main.cc" "${CMAKE_SOURCE_DIR}/equations.cc")

# Check if there has been updates to main library
set(dir ${PROJECT_SOURCE_DIR}/../..)
EXECUTE_PROCESS(COMMAND "rm" "CMakeCache.txt" WORKING_DIRECTORY ${dir})
EXECUTE_PROCESS(COMMAND "cmake" "CMakeLists.txt" WORKING_DIRECTORY ${dir})
EXECUTE_PROCESS(COMMAND "make" WORKING_DIRECTORY ${dir})

# Set targets & link libraries for the build type
if(${PRISMS_PF_BUILD_DEBUG} STREQUAL "ON")
add_executable(main_debug ${TARGET_SRC})
set_property(TARGET main_debug PROPERTY OUTPUT_NAME main-debug)
deal_ii_setup_target(main_debug DEBUG)
target_link_libraries(main_debug ${CMAKE_SOURCE_DIR}/../../libprisms-pf-debug.a)
endif()

if(${PRISMS_PF_BUILD_RELEASE} STREQUAL "ON")
add_executable(main_release ${TARGET_SRC})
set_property(TARGET main_release PROPERTY OUTPUT_NAME main)
deal_ii_setup_target(main_release RELEASE)
target_link_libraries(main_release ${CMAKE_SOURCE_DIR}/../../libprisms-pf-release.a)
endif()
57 changes: 57 additions & 0 deletions applications/multigrid_test/custom_pde.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef CUSTOM_PDE_H_
#define CUSTOM_PDE_H_

#include <core/matrix_free_operator.h>

using namespace dealii;

/**
* \brief This is a derived class of `matrixFreeOperator` where the user implements their
* PDEs.
*
* \tparam dim The number of dimensions in the problem.
* \tparam degree The polynomial degree of the shape functions.
* \tparam number Datatype to use. Either double or float.
*/
template <int dim, int degree, typename number>
class customPDE : public matrixFreeOperator<dim, degree, number>
{
public:
using scalarValue = VectorizedArray<number>;
using scalarGrad = Tensor<1, dim, VectorizedArray<number>>;
using scalarHess = Tensor<2, dim, VectorizedArray<number>>;
using vectorValue = Tensor<1, dim, VectorizedArray<number>>;
using vectorGrad = Tensor<2, dim, VectorizedArray<number>>;
using vectorHess = Tensor<3, dim, VectorizedArray<number>>;

/**
* \brief Constructor.
*/
customPDE() = default;

/**
* \brief User-implemented class for the RHS of explicit equations.
*/
void
compute_explicit_RHS(variableContainer<dim, degree, number> &variable_list,
const dealii::Point<dim, dealii::VectorizedArray<number>>
&q_point_loc) const override;

/**
* \brief User-implemented class for the RHS of nonexplicit equations.
*/
void
compute_nonexplicit_RHS(variableContainer<dim, degree, number> &variable_list,
const dealii::Point<dim, dealii::VectorizedArray<number>>
&q_point_loc) const override;

/**
* \brief User-implemented class for the LHS of nonexplicit equations.
*/
void
compute_nonexplicit_LHS(variableContainer<dim, degree, number> &variable_list,
const dealii::Point<dim, dealii::VectorizedArray<number>>
&q_point_loc) const override;
};

#endif
48 changes: 48 additions & 0 deletions applications/multigrid_test/equations.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "custom_pde.h"

#include <config.h>
#include <core/variableAttributeLoader.h>

void
customAttributeLoader::loadVariableAttributes()
{
set_variable_name(0, "phi");
set_variable_type(0, SCALAR);
set_variable_equation_type(0, EXPLICIT_TIME_DEPENDENT);

set_dependencies_value_term_RHS(0, "");
set_dependencies_gradient_term_RHS(0, "");
}

void
customAttributeLoader::loadPostProcessorVariableAttributes()
{}

template <int dim, int degree, typename number>
void
customPDE<dim, degree, number>::compute_explicit_RHS(
variableContainer<dim, degree, number> &variable_list,
const Point<dim, VectorizedArray<number>> &q_point_loc) const
{}

template <int dim, int degree, typename number>
void
customPDE<dim, degree, number>::compute_nonexplicit_RHS(
variableContainer<dim, degree, number> &variable_list,
const Point<dim, VectorizedArray<number>> &q_point_loc) const
{
scalarGrad phi = variable_list.get_scalar_gradient(0);

scalarValue coefficient = 1.0 / (0.05 + 2.0 * q_point_loc.square());

variable_list.set_scalar_gradient_term(0, phi * coefficient);
}

template <int dim, int degree, typename number>
void
customPDE<dim, degree, number>::compute_nonexplicit_LHS(
variableContainer<dim, degree, number> &variable_list,
const Point<dim, VectorizedArray<number>> &q_point_loc) const
{}

INSTANTIATE_TRI_TEMPLATE(customPDE)
38 changes: 38 additions & 0 deletions applications/multigrid_test/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "custom_pde.h"

#include <core/temp_test.h>

int
main(int argc, char *argv[])
{
try
{
Utilities::MPI::MPI_InitFinalize mpi_init(argc, argv, 1);

LaplaceProblem<dimension> laplace_problem;
laplace_problem.run();
}
catch (std::exception &exc)
{
std::cerr << '\n'
<< '\n'
<< "----------------------------------------------------" << '\n';
std::cerr << "Exception on processing: " << '\n'
<< exc.what() << '\n'
<< "Aborting!" << '\n'
<< "----------------------------------------------------" << '\n';
return 1;
}
catch (...)
{
std::cerr << '\n'
<< '\n'
<< "----------------------------------------------------" << '\n';
std::cerr << "Unknown exception!" << '\n'
<< "Aborting!" << '\n'
<< "----------------------------------------------------" << '\n';
return 1;
}

return 0;
}
4 changes: 2 additions & 2 deletions automatic_tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "core/variableAttributes.h"
#include "equations.cc"

#include <core/ParseCommandLineOpts.h>
#include <core/inputFileReader.h>
#include <core/parse_cmd_options.h>
#include <core/variableAttributeLoader.h>

// Header file for postprocessing that may or may not exist
Expand Down Expand Up @@ -38,7 +38,7 @@ main(int argc, char **argv)
std::string parameters_filename;
try
{
ParseCommandLineOpts cli_options(argc, argv);
parseCMDOptions cli_options(argc, argv);
parameters_filename = cli_options.getParametersFilename();
}
catch (const char *msg)
Expand Down
Loading
Loading