Skip to content

Commit

Permalink
Make Cardinal an optional dependency of FENIX
Browse files Browse the repository at this point in the history
  • Loading branch information
cticenhour committed Aug 27, 2024
1 parent ffa88f9 commit a134ecb
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 237 deletions.
139 changes: 20 additions & 119 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ifneq ($(wildcard $(MOOSE_SUBMODULE)/framework/Makefile),)
else
MOOSE_DIR ?= $(shell dirname `pwd`)/moose
endif
FRAMEWORK_DIR := $(MOOSE_DIR)/framework

# Use the TMAP8 submodule if it exists and TMAP8_DIR is not set
# If it doesn't exist, and TMAP8_DIR is not set, then look for it adjacent to the application
Expand All @@ -42,82 +43,16 @@ else
TMAP8_DIR ?= $(shell dirname `pwd`)/tmap8
endif

# Use the Cardinal submodule if it exists and CARDINAL_DIR is not set
# If it doesn't exist, and CARDINAL_DIR is not set, then look for it adjacent to the application
CARDINAL_SUBMODULE := $(CURDIR)/cardinal
ifneq ($(wildcard $(CARDINAL_SUBMODULE)/Makefile),)
CARDINAL_DIR ?= $(CARDINAL_SUBMODULE)
else
CARDINAL_DIR ?= $(shell dirname `pwd`)/cardinal
endif

# Cardinal contrib variables
CARDINAL_CONTRIB_DIR := $(CARDINAL_DIR)/contrib
CARDINAL_CONTRIB_INSTALL_DIR ?= $(CARDINAL_DIR)/install
OPENMC_INSTALL_DIR := $(CARDINAL_CONTRIB_INSTALL_DIR)
OPENMC_LIBDIR := $(OPENMC_INSTALL_DIR)/lib
OPENMC_BUILDDIR := $(CARDINAL_DIR)/build/openmc
OPENMC_INSTALL_DIR := $(CARDINAL_CONTRIB_INSTALL_DIR)
OPENMC_INCLUDES := -I$(OPENMC_INSTALL_DIR)/include
OPENMC_LIBDIR := $(OPENMC_INSTALL_DIR)/lib
OPENMC_LIB := $(OPENMC_LIBDIR)/libopenmc.so

PETSC_DIR ?= $(MOOSE_DIR)/petsc
PETSC_ARCH ?= arch-moose
LIBMESH_DIR ?= $(MOOSE_DIR)/libmesh/installed/

# This is the Eigen3 location on CIVET. If you are using MOOSE's conda environment,
# you don't need to set these variables, because conda sets them for you. The only
# scenario where you might need to manually set these is if you're not using the
# conda environment. You will get a compile error about FindEigen3.cmake if you
# do indeed need to set these.
EIGEN3_DIR ?= $(LIBMESH_DIR)/include
Eigen3_DIR ?= $(EIGEN3_DIR)

# If HDF5_DIR is set, use those settings to link HDF5 to OpenMC.
# Otherwise, use the PETSc location, as the self-built HDF5 libraries will be housed within.
ifeq ($(HDF5_DIR),)
HDF5_DIR := $(PETSC_DIR)
export HDF5_DIR
endif

# HDF5_ROOT is used in makefiles for the Cardinal third-party dependencies.
# Set it using HDF5_DIR
HDF5_ROOT := $(HDF5_DIR)
export HDF5_ROOT
# Check for optional dependencies and, if found, configure for building.
# Set default for ENABLE_CARDINAL.
ENABLE_CARDINAL := no
include config/check_deps.mk

HDF5_INCLUDE_DIR ?= $(HDF5_DIR)/include
HDF5_LIBDIR ?= $(HDF5_DIR)/lib
# This is used in $(FRAMEWORK_DIR)/build.mk
HDF5_INCLUDES := -I$(HDF5_INCLUDE_DIR) -I$(HDF5_DIR)/include

# BUILD_TYPE will be passed to CMake via CMAKE_BUILD_TYPE
ifeq ($(METHOD),dbg)
BUILD_TYPE := Debug
else
BUILD_TYPE := Release
endif

DAGMC_BUILDDIR := $(CARDINAL_DIR)/build/DAGMC
DAGMC_INSTALL_DIR := $(CARDINAL_CONTRIB_INSTALL_DIR)

MOAB_BUILDDIR := $(CARDINAL_DIR)/build/moab
MOAB_INSTALL_DIR := $(CARDINAL_CONTRIB_INSTALL_DIR)

# Set default values for all third party dependencies
OPENMC_DIR ?= $(CARDINAL_CONTRIB_DIR)/openmc
DAGMC_DIR ?= $(CARDINAL_CONTRIB_DIR)/DAGMC
MOAB_DIR ?= $(CARDINAL_CONTRIB_DIR)/moab

# Use compiler info discovered by PETSC
ifeq ($(PETSC_ARCH),)
include $(PETSC_DIR)/$(PETSC_ARCH)/lib/petsc/conf/petscvariables
else
include $(PETSC_DIR)/lib/petsc/conf/petscvariables
ifeq ($(ENABLE_CARDINAL),yes)
include config/configure_cardinal.mk
endif

# framework
FRAMEWORK_DIR := $(MOOSE_DIR)/framework
include $(FRAMEWORK_DIR)/build.mk
include $(FRAMEWORK_DIR)/moose.mk

Expand Down Expand Up @@ -158,31 +93,6 @@ XFEM := no
include $(MOOSE_DIR)/modules/modules.mk
###############################################################################

# Add OpenMC flags
ADDITIONAL_CPPFLAGS += $(HDF5_INCLUDES) $(OPENMC_INCLUDES)
libmesh_CXXFLAGS += -DENABLE_OPENMC_COUPLING

# Add DagMC flags (-DDAGMC is used in OpenMC)
libmesh_CXXFLAGS += -DENABLE_DAGMC -DDAGMC

# Configure and build MOAB, DagMC, and then OpenMC
include $(CARDINAL_DIR)/config/moab.mk
include $(CARDINAL_DIR)/config/dagmc.mk

# autoconf-archive puts some arguments (e.g. -std=c++17) into the compiler
# variable rather than the compiler flags variable.
#
# cmake allows this, but wants any compiler arguments to be
# semicolon-separated, not space-separated
# libmesh_CC, etc., were defined in build.mk
space := $(subst ,, )
LIBMESH_CC_LIST := $(subst $(space),;,$(libmesh_CC))
LIBMESH_CXX_LIST := $(subst $(space),;,$(libmesh_CXX))
LIBMESH_F90_LIST := $(subst $(space),;,$(libmesh_F90))

ENABLE_DAGMC := ON
include $(CARDINAL_DIR)/config/openmc.mk

# TMAP8
APPLICATION_DIR := $(TMAP8_DIR)
APPLICATION_NAME := tmap8
Expand All @@ -191,35 +101,26 @@ GEN_REVISION := no
include $(FRAMEWORK_DIR)/app.mk

# Cardinal
APPLICATION_DIR := $(CARDINAL_DIR)
APPLICATION_NAME := cardinal
BUILD_EXEC := no
GEN_REVISION := yes
include $(FRAMEWORK_DIR)/app.mk

# app_objects are defined in moose.mk and built according to the rules in build.mk
# We need to build these first so we get include dirs
$(app_objects): build_moab build_dagmc build_openmc
$(test_objects): build_moab build_dagmc build_openmc
ifeq ($(ENABLE_CARDINAL),yes)
include config/build_cardinal.mk
endif

# FENIX
APPLICATION_DIR := $(CURDIR)
APPLICATION_NAME := fenix
BUILD_EXEC := yes
GEN_REVISION := yes

# Cardinal dependency libraries
ADDITIONAL_LIBS := -L$(CARDINAL_DIR)/lib $(CC_LINKER_SLFLAG)$(CARDINAL_DIR)/lib \
-L$(OPENMC_LIBDIR) -lopenmc -lhdf5_hl -ldagmc -lMOAB \
$(CC_LINKER_SLFLAG)$(OPENMC_LIBDIR)
# Cardinal dependency libraries needed for FENIX linking
ifeq ($(ENABLE_CARDINAL),yes)
ADDITIONAL_LIBS := -L$(CARDINAL_DIR)/lib $(CC_LINKER_SLFLAG)$(CARDINAL_DIR)/lib \
-L$(OPENMC_LIBDIR) -lopenmc -lhdf5_hl -ldagmc -lMOAB \
$(CC_LINKER_SLFLAG)$(OPENMC_LIBDIR)
endif

include $(FRAMEWORK_DIR)/app.mk


# Cardinal contrib flags used in app.mk targets
CARDINAL_EXTERNAL_FLAGS := -L$(CARDINAL_DIR)/lib $(CC_LINKER_SLFLAG)$(CARDINAL_DIR)/lib $(BLASLAPACK_LIB) $(PETSC_EXTERNAL_LIB_BASIC) -L$(OPENMC_LIBDIR) -L$(HDF5_LIBDIR) -lopenmc -ldagmc -lMOAB $(CC_LINKER_SLFLAG)$(OPENMC_LIBDIR) $(CC_LINKER_SLFLAG)$(HDF5_LIBDIR)

# EXTERNAL_FLAGS is used in rules for app.mk
$(app_LIB): EXTERNAL_FLAGS := $(CARDINAL_EXTERNAL_FLAGS)
$(app_test_LIB): EXTERNAL_FLAGS := $(CARDINAL_EXTERNAL_FLAGS)
$(app_EXEC): EXTERNAL_FLAGS := $(CARDINAL_EXTERNAL_FLAGS)
# External flags
ifeq ($(ENABLE_CARDINAL),yes)
include config/external_cardinal_flags.mk
endif
37 changes: 37 additions & 0 deletions config/build_cardinal.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Add OpenMC flags
ADDITIONAL_CPPFLAGS += $(HDF5_INCLUDES) $(OPENMC_INCLUDES)
libmesh_CXXFLAGS += -DENABLE_OPENMC_COUPLING

# Add DagMC flags (-DDAGMC is used in OpenMC)
libmesh_CXXFLAGS += -DENABLE_DAGMC -DDAGMC

# Configure and build MOAB, DagMC, and then OpenMC
include $(CARDINAL_DIR)/config/moab.mk
include $(CARDINAL_DIR)/config/dagmc.mk

# autoconf-archive puts some arguments (e.g. -std=c++17) into the compiler
# variable rather than the compiler flags variable.
#
# cmake allows this, but wants any compiler arguments to be
# semicolon-separated, not space-separated
# libmesh_CC, etc., were defined in build.mk
space := $(subst ,, )
LIBMESH_CC_LIST := $(subst $(space),;,$(libmesh_CC))
LIBMESH_CXX_LIST := $(subst $(space),;,$(libmesh_CXX))
LIBMESH_F90_LIST := $(subst $(space),;,$(libmesh_F90))

ENABLE_DAGMC := ON
include $(CARDINAL_DIR)/config/openmc.mk

# Cardinal
libmesh_CXXFLAGS += -DENABLE_CARDINAL
APPLICATION_DIR := $(CARDINAL_DIR)
APPLICATION_NAME := cardinal
BUILD_EXEC := no
GEN_REVISION := yes
include $(FRAMEWORK_DIR)/app.mk

# app_objects are defined in moose.mk and built according to the rules in build.mk
# We need to build these first so we get include dirs
$(app_objects): build_moab build_dagmc build_openmc
$(test_objects): build_moab build_dagmc build_openmc
18 changes: 18 additions & 0 deletions config/check_deps.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
define n


endef

# Set default value for Cardinal
CARDINAL_DIR ?= $(CURDIR)/cardinal

# Check for CARDINAL_CONTENT within CARDINAL_DIR. This will cause Cardinal (and contribs)
# to either be built or skipped within the configure_cardinal.mk file.
CARDINAL_CONTENT := $(shell ls $(CARDINAL_DIR) 2> /dev/null)

ifeq ($(CARDINAL_CONTENT),)
$(warning $n"Cardinal does not seem to be available. If usage of Cardinal is desired within FENIX, make sure that either the submodule is checked out$nor that CARDINAL_DIR points to a location with the Cardinal source.")
else
$(info FENIX is using Cardinal from $(CARDINAL_DIR))
ENABLE_CARDINAL := yes
endif
64 changes: 64 additions & 0 deletions config/configure_cardinal.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Cardinal contrib variables
CARDINAL_CONTRIB_DIR := $(CARDINAL_DIR)/contrib
CARDINAL_CONTRIB_INSTALL_DIR ?= $(CARDINAL_DIR)/install
OPENMC_INSTALL_DIR := $(CARDINAL_CONTRIB_INSTALL_DIR)
OPENMC_LIBDIR := $(OPENMC_INSTALL_DIR)/lib
OPENMC_BUILDDIR := $(CARDINAL_DIR)/build/openmc
OPENMC_INSTALL_DIR := $(CARDINAL_CONTRIB_INSTALL_DIR)
OPENMC_INCLUDES := -I$(OPENMC_INSTALL_DIR)/include
OPENMC_LIBDIR := $(OPENMC_INSTALL_DIR)/lib
OPENMC_LIB := $(OPENMC_LIBDIR)/libopenmc.so

PETSC_DIR ?= $(MOOSE_DIR)/petsc
PETSC_ARCH ?= arch-moose
LIBMESH_DIR ?= $(MOOSE_DIR)/libmesh/installed/

# This is the Eigen3 location on CIVET. If you are using MOOSE's conda environment,
# you don't need to set these variables, because conda sets them for you. The only
# scenario where you might need to manually set these is if you're not using the
# conda environment. You will get a compile error about FindEigen3.cmake if you
# do indeed need to set these.
EIGEN3_DIR ?= $(LIBMESH_DIR)/include
Eigen3_DIR ?= $(EIGEN3_DIR)

# If HDF5_DIR is set, use those settings to link HDF5 to OpenMC.
# Otherwise, use the PETSc location, as the self-built HDF5 libraries will be housed within.
ifeq ($(HDF5_DIR),)
HDF5_DIR := $(PETSC_DIR)
export HDF5_DIR
endif

# HDF5_ROOT is used in makefiles for the Cardinal third-party dependencies.
# Set it using HDF5_DIR
HDF5_ROOT := $(HDF5_DIR)
export HDF5_ROOT

HDF5_INCLUDE_DIR ?= $(HDF5_DIR)/include
HDF5_LIBDIR ?= $(HDF5_DIR)/lib
# This is used in $(FRAMEWORK_DIR)/build.mk
HDF5_INCLUDES := -I$(HDF5_INCLUDE_DIR) -I$(HDF5_DIR)/include

# BUILD_TYPE will be passed to CMake via CMAKE_BUILD_TYPE
ifeq ($(METHOD),dbg)
BUILD_TYPE := Debug
else
BUILD_TYPE := Release
endif

DAGMC_BUILDDIR := $(CARDINAL_DIR)/build/DAGMC
DAGMC_INSTALL_DIR := $(CARDINAL_CONTRIB_INSTALL_DIR)

MOAB_BUILDDIR := $(CARDINAL_DIR)/build/moab
MOAB_INSTALL_DIR := $(CARDINAL_CONTRIB_INSTALL_DIR)

# Set default values for all third party dependencies
OPENMC_DIR ?= $(CARDINAL_CONTRIB_DIR)/openmc
DAGMC_DIR ?= $(CARDINAL_CONTRIB_DIR)/DAGMC
MOAB_DIR ?= $(CARDINAL_CONTRIB_DIR)/moab

# Use compiler info discovered by PETSC
ifeq ($(PETSC_ARCH),)
include $(PETSC_DIR)/$(PETSC_ARCH)/lib/petsc/conf/petscvariables
else
include $(PETSC_DIR)/lib/petsc/conf/petscvariables
endif
9 changes: 9 additions & 0 deletions config/external_cardinal_flags.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ifeq ($(ENABLE_CARDINAL),yes)
# Cardinal contrib flags used in app.mk targets
CARDINAL_EXTERNAL_FLAGS := -L$(CARDINAL_DIR)/lib $(CC_LINKER_SLFLAG)$(CARDINAL_DIR)/lib $(BLASLAPACK_LIB) $(PETSC_EXTERNAL_LIB_BASIC) -L$(OPENMC_LIBDIR) -L$(HDF5_LIBDIR) -lopenmc -ldagmc -lMOAB $(CC_LINKER_SLFLAG)$(OPENMC_LIBDIR) $(CC_LINKER_SLFLAG)$(HDF5_LIBDIR)

# EXTERNAL_FLAGS is used in rules for app.mk
$(app_LIB): EXTERNAL_FLAGS := $(CARDINAL_EXTERNAL_FLAGS)
$(app_test_LIB): EXTERNAL_FLAGS := $(CARDINAL_EXTERNAL_FLAGS)
$(app_EXEC): EXTERNAL_FLAGS := $(CARDINAL_EXTERNAL_FLAGS)
endif
8 changes: 8 additions & 0 deletions src/base/FenixApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

// contribs
#include "TMAP8App.h"
#ifdef ENABLE_CARDINAL
#include "CardinalApp.h"
#endif

InputParameters
FenixApp::validParams()
Expand All @@ -47,7 +49,10 @@ FenixApp::registerAll(Factory & f, ActionFactory & af, Syntax & s)
Registry::registerActionsTo(af, {"FenixApp"});

TMAP8App::registerAll(f, af, s);

#ifdef ENABLE_CARDINAL
CardinalApp::registerAll(f, af, s);
#endif

/* register custom execute flags, action syntax, etc. here */
}
Expand All @@ -58,7 +63,10 @@ FenixApp::registerApps()
registerApp(FenixApp);
ModulesApp::registerApps();
TMAP8App::registerApps();

#ifdef ENABLE_CARDINAL
CardinalApp::registerApps();
#endif
}

/***************************************************************************************************
Expand Down
Loading

0 comments on commit a134ecb

Please sign in to comment.