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

Installation system needs another small overhaul #6

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion DiFfRG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ clang_format(format ${headers} ${sources} ${cuda_sources})
file(GLOB_RECURSE CMAKE_FILES CMakeLists.txt)

cmake_format(cmake-format ${CMAKE_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup_build_system.cmake)
${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup_build_system.cmake)
25 changes: 15 additions & 10 deletions DiFfRG/cmake/setup_build_system.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,21 @@ if(USE_CUDA)

endif()

cpmaddpackage(
NAME
spdlog
GITHUB_REPOSITORY
gabime/spdlog
VERSION
1.14.1
OPTIONS
"CMAKE_BUILD_TYPE Release"
"CMAKE_CXX_FLAGS \"-O3 -DNDEBUG\"")
if(NOT spdlog_ADDED)
cpmaddpackage(
NAME
spdlog
GITHUB_REPOSITORY
gabime/spdlog
VERSION
1.14.1
OPTIONS
"CMAKE_BUILD_TYPE Release")
if(spdlog_ADDED)
install(TARGETS spdlog
EXPORT DiFfRGTargets)
endif()
endif()

# ##############################################################################
# Helper functions
Expand Down
621 changes: 621 additions & 0 deletions DiFfRG/include/DiFfRG/discretization/FV/assembler/KurganovTadmor.hh

Large diffs are not rendered by default.

84 changes: 78 additions & 6 deletions DiFfRG/include/DiFfRG/discretization/FV/discretization.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_renumbering.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/fe/fe_q.h>
#include <deal.II/fe/fe_dgq.h>
#include <deal.II/fe/fe_system.h>
#include <deal.II/fe/mapping_q1.h>
#include <deal.II/lac/affine_constraints.h>
#include <spdlog/spdlog.h>

// DiFfRG
#include <DiFfRG/common/utils.hh>
#include <DiFfRG/discretization/FV/assembler/KurganovTadmor.hh>

namespace DiFfRG
{
Expand All @@ -22,7 +22,7 @@ namespace DiFfRG

/**
* @brief Class to manage the system on which we solve, i.e. fe spaces, grids, etc.
* This class is a System for CG systems.
* This class is a System for FV systems.
*
* @tparam Model_ The Model class used for the Simulation
*/
Expand All @@ -36,21 +36,93 @@ namespace DiFfRG
using Mesh = Mesh_;
static constexpr uint dim = Mesh::dim;

Discretization(Mesh &mesh, const JSONValue &json) : mesh(mesh), json(json) {};
Discretization(Mesh &mesh, const JSONValue &json)
: mesh(mesh), json(json),
fe(std::make_shared<FESystem<dim>>(FE_DGQ<dim>(0), Components::count_fe_functions(0))),
dof_handler(mesh.get_triangulation())
{
setup_dofs();
}

const auto &get_constraints(const uint i = 0) const
{
(void)i;
return constraints;
}
auto &get_constraints(const uint i = 0)
{
(void)i;
return constraints;
}
const auto &get_dof_handler(const uint i = 0) const
{
(void)i;
return dof_handler;
}
auto &get_dof_handler(const uint i = 0)
{
(void)i;
return dof_handler;
}
const auto &get_fe(uint i = 0) const
{
if (i != 0) throw std::runtime_error("Wrong FE index");
return *fe;
}
const auto &get_mapping() const { return mapping; }
const auto &get_triangulation() const { return mesh.get_triangulation(); }
auto &get_triangulation() { return mesh.get_triangulation(); }
const Point<dim> &get_support_point(const uint &dof) const { return support_points[dof]; }
const auto &get_support_points() const { return support_points; }
const auto &get_json() const { return json; }

void reinit() {}
void reinit() { setup_dofs(); }

uint get_closest_dof(const Point<dim> &p) const
{
uint dof = 0;
double min_dist = std::numeric_limits<double>::max();
for (uint i = 0; i < support_points.size(); ++i) {
const auto dist = p.distance(support_points[i]);
if (dist < min_dist) {
min_dist = dist;
dof = i;
}
}
return dof;
}

std::vector<uint> get_block_structure() const
{
std::vector<uint> block_structure{dof_handler.n_dofs()};
if (Components::count_variables() > 0) block_structure.push_back(Components::count_variables());
return block_structure;
}

protected:
void setup_dofs()
{
dof_handler.distribute_dofs(*fe);

spdlog::get("log")->info("FV: Number of active cells: {}", mesh.get_triangulation().n_active_cells());
spdlog::get("log")->info("FV: Number of degrees of freedom: {}", dof_handler.n_dofs());

constraints.clear();
DoFTools::make_hanging_node_constraints(dof_handler, constraints);
constraints.close();

support_points.resize(dof_handler.n_dofs());
DoFTools::map_dofs_to_support_points(mapping, dof_handler, support_points);
}

Mesh &mesh;
JSONValue json;

std::shared_ptr<FESystem<dim>> fe;
DoFHandler<dim> dof_handler;
AffineConstraints<NumberType> constraints;
MappingQ1<dim> mapping;
std::vector<Point<dim>> support_points;
};
} // namespace FV
} // namespace DiFfRG
} // namespace DiFfRG
7 changes: 7 additions & 0 deletions DiFfRG/include/DiFfRG/discretization/common/types.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace DiFfRG
{
template <typename T>
concept MeshIsRectangular = requires(T x) { T::is_rectangular; } && T::is_rectangular;
} // namespace DiFfRG
67 changes: 1 addition & 66 deletions DiFfRG/include/DiFfRG/discretization/data/data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -168,73 +168,8 @@ namespace DiFfRG

namespace FV
{
/**
* @brief A class to set up initial data for whatever discretization we have chosen.
* Also used to switch/manage memory, vectors, matrices over interfaces between spatial discretization and
* separate variables.
*
* @tparam Discretization Spatial Discretization used in the system
*/
template <typename Discretization>
class FlowingVariables : public AbstractFlowingVariables<typename Discretization::NumberType>
{
public:
using NumberType = typename Discretization::NumberType;
using Components = typename Discretization::Components;
static constexpr uint dim = Discretization::dim;

/**
* @brief Construct a new Flowing Variables object
*
* @param discretization The spatial discretization to use
*/
FlowingVariables(const Discretization &discretization) : discretization(discretization) {}

/**
* @brief Interpolates the initial condition from a numerical model.
*
* @param model The model to interpolate from. Must provide a method initial_condition(const Point<dim> &,
* Vector<NumberType> &)
*/
template <typename Model> void interpolate(const Model &model)
{
auto block_structure = discretization.get_block_structure();
m_data = (block_structure);

if constexpr (Model::Components::count_fe_functions() > 0) {
// TODO
}
if (m_data.n_blocks() > 1) model.initial_condition_variables(m_data.block(1));
}

/**
* @brief Obtain the data vector holding both spatial (block 0) and variable (block 1) data.
*
* @return BlockVector<NumberType>& The data vector.
*/
virtual BlockVector<NumberType> &data() override { return m_data; }
virtual const BlockVector<NumberType> &data() const override { return m_data; }

/**
* @brief Obtain the spatial data vector.
*
* @return Vector<NumberType>& The spatial data vector.
*/
virtual Vector<NumberType> &spatial_data() override { return m_data.block(0); }
virtual const Vector<NumberType> &spatial_data() const override { return m_data.block(0); }

/**
* @brief Obtain the variable data vector.
*
* @return Vector<NumberType>& The variable data vector.
*/
virtual Vector<NumberType> &variable_data() override { return m_data.block(1); }
virtual const Vector<NumberType> &variable_data() const override { return m_data.block(1); }

private:
const Discretization &discretization;
BlockVector<NumberType> m_data;
};
using FlowingVariables = DiFfRG::FE::FlowingVariables<Discretization>;
} // namespace FV

} // namespace DiFfRG
2 changes: 2 additions & 0 deletions DiFfRG/include/DiFfRG/discretization/discretization.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <DiFfRG/discretization/FV/discretization.hh>

#include <DiFfRG/discretization/FEM/cg.hh>
#include <DiFfRG/discretization/FEM/dg.hh>
#include <DiFfRG/discretization/FEM/ldg.hh>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace DiFfRG
{
public:
static constexpr uint dim = dim_;
static constexpr bool is_rectangular = true;

/**
* @brief Construct a new RectangularMesh object.
Expand Down
13 changes: 5 additions & 8 deletions DiFfRG/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# add_compile_definitions(CUDA_API_PER_THREAD_DEFAULT_STREAM)
add_library(
DiFfRG STATIC
set(DiFfRG_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/common/boost_json.cc
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/common/configuration_helper.cc
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/common/csv_reader.cc
Expand Down Expand Up @@ -30,9 +29,7 @@ add_library(
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/timestepping/trbdf2.cc
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/physics/flow_equations.cc)
if(USE_CUDA)
target_sources(
DiFfRG
PRIVATE
list(APPEND DiFfRG_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/common/cuda_prefix.cu
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/physics/integration/quadrature_provider.cu
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/physics/interpolation/linear_interpolation_1D.cu
Expand All @@ -43,9 +40,7 @@ if(USE_CUDA)
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/physics/interpolation/tex_linear_interpolation_1D_stack.cu
)
else()
target_sources(
DiFfRG
PRIVATE
list(APPEND DiFfRG_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/physics/integration/quadrature_provider.cc
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/physics/interpolation/linear_interpolation_1D.cc
${CMAKE_CURRENT_SOURCE_DIR}/DiFfRG/physics/interpolation/linear_interpolation_2D.cc
Expand All @@ -56,6 +51,8 @@ else()
)
endif()

add_library(DiFfRG STATIC ${DiFfRG_SOURCES})

setup_target(DiFfRG)

target_include_directories(
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ if [[ ${install_dir} != "n" ]] && [[ ${install_dir} != "N" ]]; then

# Make sure the install directory is absolute
idir=$(expandPath ${install_dir}/)
idir=$(readlink --canonicalize ${idir})
#idir=$(readlink --canonicalize ${idir})
echo "DiFfRG library will be installed in ${idir}"

# Check if the install directory is writable
Expand Down
4 changes: 2 additions & 2 deletions external/build_boost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fi
echo $COMPILER
cd $SOURCE_PATH

./bootstrap.sh --prefix=${INSTALL_PATH}
./b2 --build-dir=${BUILD_PATH} \
$SuperUser ./bootstrap.sh --prefix=${INSTALL_PATH}
$SuperUser ./b2 --build-dir=${BUILD_PATH} \
--prefix=${INSTALL_PATH} \
--with-headers \
--with-iostreams \
Expand Down
2 changes: 1 addition & 1 deletion external/build_dealii.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ cmake -DCMAKE_BUILD_TYPE=DebugRelease \
2>&1 | tee $CMAKE_LOG_FILE

make -j $THREADS 2>&1 | tee $MAKE_LOG_FILE
make -j $THREADS install
$SuperUser make -j $THREADS install
18 changes: 9 additions & 9 deletions external/build_kokkos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ source $SCRIPT_PATH/build_scripts/setup_folders.sh

cd $BUILD_PATH

#-DKokkos_ARCH_NATIVE=ON \
#-DKokkos_ARCH_NATIVE=ON \
cmake -DKokkos_ENABLE_SERIAL=ON \
-DKokkos_ENABLE_OPENMP=OFF \
-DKokkos_ENABLE_CUDA=OFF \
-DCMAKE_CXX_FLAGS="${CXX_FLAGS}" \
-DCMAKE_EXE_LINKER_FLAGS="${EXE_LINKER_FLAGS}" \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} \
-S ${SOURCE_PATH} \
2>&1 | tee $CMAKE_LOG_FILE
-DKokkos_ENABLE_OPENMP=OFF \
-DKokkos_ENABLE_CUDA=OFF \
-DCMAKE_CXX_FLAGS="${CXX_FLAGS}" \
-DCMAKE_EXE_LINKER_FLAGS="${EXE_LINKER_FLAGS}" \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} \
-S ${SOURCE_PATH} \
2>&1 | tee $CMAKE_LOG_FILE

make -j $THREADS 2>&1 | tee $MAKE_LOG_FILE
make -j $THREADS install
$SuperUser make -j $THREADS install
2 changes: 1 addition & 1 deletion external/build_oneTBB.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ cmake -DCMAKE_BUILD_TYPE=Release \
2>&1 | tee $CMAKE_LOG_FILE

make -j $THREADS 2>&1 | tee $MAKE_LOG_FILE
make -j $THREADS install
$SuperUser make -j $THREADS install
16 changes: 15 additions & 1 deletion external/build_scripts/setup_folders.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
mkdir -p $SCRIPT_PATH/logs
mkdir -p $BUILD_PATH
mkdir -p $INSTALL_PATH

failed_first=0
mkdir -p $INSTALL_PATH &>/dev/null && touch $INSTALL_PATH/_permission_test &>/dev/null || {
failed_first=1
}

SuperUser=""
if ((failed_first == 0)); then
echo "Elevated permissions required to write into $INSTALL_PATH."
SuperUser="sudo -E"

$SuperUser mkdir -p $INSTALL_PATH
else
rm $INSTALL_PATH/_permission_test
fi
2 changes: 1 addition & 1 deletion external/build_sundials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ cmake -DENABLE_OPENMP=ON \
2>&1 | tee $CMAKE_LOG_FILE

make -j $THREADS 2>&1 | tee $MAKE_LOG_FILE
make -j $THREADS install
$SuperUser make -j $THREADS install
2 changes: 1 addition & 1 deletion update_DiFfRG.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if [[ ${option_install_library} != "n" ]] && [[ ${option_install_library} != "N"

# Make sure the install directory is absolute
idir=$(expandPath ${option_install_library}/)
idir=$(readlink --canonicalize ${idir})
#idir=$(readlink --canonicalize ${idir})
echo "DiFfRG library will be installed in ${idir}"

# Check if the install directory is writable
Expand Down
Loading