Skip to content

Commit

Permalink
Add TaskListFactory (#118)
Browse files Browse the repository at this point in the history
- update yaml file
- update main
- add TaskListFactory
  • Loading branch information
chengcli authored Jan 19, 2024
1 parent 10e81c6 commit e76d893
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
- name: create build directory
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTASK=robert3d
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTASK=robert

- name: Build
# Build your program with the given configuration
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ jobs:
- name: create build directory
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTASK=robert3d
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTASK=robert

- name: Build
# Build your program with the given configuration
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ include(${CMAKE_SOURCE_DIR}/cmake/pybind11.cmake)
## 4. set up project configure file and library ##
message(STATUS "4. Set up project libraries")
configure_file(${CMAKE_SOURCE_DIR}/configure.hpp.in configure.hpp @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/main.cpp.in main_${TASK}.cpp @ONLY)
add_subdirectory(src)
add_subdirectory(tools)
add_subdirectory(data)
Expand Down
1 change: 0 additions & 1 deletion cmake/bryan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ set(NPHASE_LEGACY 2)
set(NETCDF ON)
set(PNETCDF ON)
set(MPI ON)
set(TASKLIST ImplicitHydroTasks)
set(RSOLVER lmars)
2 changes: 1 addition & 1 deletion cmake/disort.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if(DISORT)
FetchContent_Declare(
pydisort
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
URL https://${ACCOUNT}:${TOKEN}@github.com/zoeyzyhu/pydisort/archive/refs/tags/v0.6.3b1.tar.gz
URL https://${ACCOUNT}:${TOKEN}@github.com/zoeyzyhu/pydisort/archive/refs/tags/v0.8.0.tar.gz
)

FetchContent_MakeAvailable(pydisort)
Expand Down
1 change: 0 additions & 1 deletion cmake/hywater.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ set(PNETCDF ON)
set(MPI ON)
set(DISORT ON)
set(PYTHON_BINDINGS ON)
set(TASKLIST ImplicitHydroTasks)
set(RSOLVER lmars)
3 changes: 1 addition & 2 deletions cmake/macros/macro_setup_problem.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ string(TOLOWER ${CMAKE_BUILD_TYPE} buildl)
string(TOUPPER ${CMAKE_BUILD_TYPE} buildu)

macro(setup_problem namel)
add_executable(${namel}.${buildl} ${namel}.cpp
${CMAKE_BINARY_DIR}/main_${TASK}.cpp)
add_executable(${namel}.${buildl} ${namel}.cpp ${CMAKE_SOURCE_DIR}/main.cpp)

set_target_properties(
${namel}.${buildl}
Expand Down
4 changes: 0 additions & 4 deletions cmake/parameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ set_if_empty(NINT_PARTICLE_DATA 0)

set_if_empty(NREAL_PARTICLE_DATA 0)

# set_if_empty(TASKLIST ImplicitHydroTasks)

# set_if_empty(RSOLVER lmars)

# set_if_empty(NUMBER_GHOST_CELLS 3)
Expand All @@ -50,8 +48,6 @@ else()
endif()
set(EQUATION_OF_STATE ${EOS})

set_if_empty(TASKLIST TimeIntegratorTaskList)

if(NOT AFFINE OR NOT DEFINED AFFINE)
set(AFFINE_OPTION "NOT_AFFINE")
else()
Expand Down
1 change: 0 additions & 1 deletion cmake/robert.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ set_if_empty(NUMBER_GHOST_CELLS 3)
# canoe configure
set(MPI ON)
set(PNETCDF ON)
set(TASKLIST ImplicitHydroTasks)
15 changes: 0 additions & 15 deletions cmake/robert3d.cmake

This file was deleted.

1 change: 1 addition & 0 deletions examples/2019-Li-snap/bryan.inp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configure = --prob=bryan --flux=lmars --nvapor=1 --nphase=2 --nghost=3 -pnetcdf

<job>
problem_id = bryan # problem ID: basename of output filenames
tasklist = ImplicitHydroTasks

<output1>
file_type = hst # History data dump
Expand Down
1 change: 1 addition & 0 deletions examples/2019-Li-snap/robert2d.inp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configure = --prob=robert --nghost=3 -mpi -pnetcdf --pnetcdf_path=${HOME}/opt/

<job>
problem_id = robert # problem ID: basename of output filenames
tasklist = ImplicitHydroTasks

<output1>
file_type = hst # History data dump
Expand Down
1 change: 1 addition & 0 deletions examples/2019-Li-snap/robert3d.inp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configure = --prob=robert --nghost=3 -mpi -pnetcdf --pnetcdf_path=${HOME}/opt/

<job>
problem_id = robert # problem ID: basename of output filenames
tasklist = ImplicitHydroTasks

<output1>
file_type = hst # History data dump
Expand Down
1 change: 1 addition & 0 deletions examples/2019-Li-snap/straka.inp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configure = --prob=straka --nghost=3 -netcdf

<job>
problem_id = straka # problem ID: basename of output filenames
tasklist = TimeIntegratorTaskList

<output1>
file_type = hst # History data dump
Expand Down
1 change: 1 addition & 0 deletions examples/2020-Li-polar-vortex/fig_g_intruder.inp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configure = --prob=polar_vortex --eos=shallow_water --nghost=3 -mpi -pnetcdf --p

<job>
problem_id = intruder # problem ID: basename of output filenames
tasklist = TimeIntegratorTaskList

<output0>
file_type = hst # History data dump
Expand Down
1 change: 1 addition & 0 deletions examples/2020-Li-polar-vortex/shallow_water.inp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configure = --prob=shallow_water --eos=shallow_water --nghost=3 -netcdf -mpi

<job>
problem_id = sw # problem ID: basename of output filenames
tasklist = TimeIntegratorTaskList

<output1>
file_type = hst # History data dump
Expand Down
1 change: 1 addition & 0 deletions examples/2023-jupiter-mwr-eq/juno_mwr.inp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ configure = mkdir build-juno && cmake .. -DTASK=Juno

<job>
problem_id = juno_mwr # problem ID: basename of output filenames
tasklist = TimeIntegratorTaskList

#<output1>
#file_type = fits # Binary data dump
Expand Down
1 change: 1 addition & 0 deletions examples/2024-XZhang-cloud-rt/hywater.inp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ configure = -Dpnetcdf_path=/home3/xzhang11/pnetcdf

<job>
problem_id = hywater2d # problem ID: basename of output filenames
tasklist = ImplicitHydroTasks

<output0>
file_type = rst
Expand Down
2 changes: 2 additions & 0 deletions examples/2024-XZhang-cloud-rt/hywater.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ vis:

Disort-flags:
ibcnd: false
usrtau: false
usrang: false
lamber: true
onlyfl: true
spher: false
Expand Down
11 changes: 2 additions & 9 deletions main.cpp.in → main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <athena/task_list/task_list.hpp>

// tasklist
#include <tasklist/extra_tasks.hpp>
#include <tasklist/task_list_factory.hpp>

// application
#include <application/command_line.hpp>
Expand All @@ -43,7 +43,6 @@ void mesh_setup(ParameterInput* &pin, Mesh* &mesh);
void mesh_destroy(ParameterInput* &pin, Mesh* &mesh, int mbcnt);

using OutputsPtr = std::unique_ptr<Outputs>;
using TaskListPtr = std::unique_ptr<@TASKLIST@>;

int main(int argc, char **argv) {
Application::Start(argc, argv);
Expand Down Expand Up @@ -83,13 +82,7 @@ int main(int argc, char **argv) {
mesh_setup(pinput, pmesh);

// CONSTRUCT AND INITIALIZE TASKlIST
TaskListPtr ptlist;
try {
ptlist = std::make_unique<@TASKLIST@>(pinput, pmesh);
}
catch(std::bad_alloc& ba) {
throw RuntimeError("main", "TaskList memory allocation failed");
}
auto ptlist = TaskListFactory::CreateFrom(pinput, pmesh);

#ifdef ENABLE_GLOG
FLAGS_log_dir = log_dir_name;
Expand Down
5 changes: 3 additions & 2 deletions src/harp/rt_solver_disort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ void RadiationBand::RTSolverDisort::Resize(int nlyr, int nstr) {
auto &rayout = pmy_band_->rayOutput_;
auto &&uphi_umu = RadiationHelper::get_direction_grids(rayout);

SetAtmosphereDimension(nlyr, nstr, nstr, nstr);
SetAtmosphereDimension(nlyr, nstr, nstr);

dir_dim_[0] = uphi_umu.second.size(); // umu
dir_dim_[1] = uphi_umu.first.size(); // uphi
dir_axis_.resize(dir_dim_[0] + dir_dim_[1]);

SetIntensityDimension(dir_dim_[1], 1, dir_dim_[0]);
SetIntensityDimension(std::max(dir_dim_[1], 1lu), 1,
std::max(dir_dim_[0], 1lu));
Seal();
}

Expand Down
1 change: 1 addition & 0 deletions src/tasklist/extra_tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// athena
#include <athena/globals.hpp>
#include <athena/task_list/task_list.hpp>

// forward declarations
class Mesh;
Expand Down
44 changes: 44 additions & 0 deletions src/tasklist/task_list_factory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef SRC_TASKLIST_TASK_LIST_FACTORY_HPP_
#define SRC_TASKLIST_TASK_LIST_FACTORY_HPP_

// C/C++
#include <memory>

// application
#include <application/exceptions.hpp>

#include "extra_tasks.hpp"

using TaskListPtr = std::unique_ptr<TaskList>;

class TaskListFactory {
public:
static TaskListPtr CreateFrom(ParameterInput* pin, Mesh* mesh) {
std::string tasklist_name;
TaskListPtr ptlist;

if (pin->DoesParameterExist("job", "tasklist")) {
tasklist_name = pin->GetString("job", "tasklist");
} else {
tasklist_name = "ImplicitHydroTasks";
}

try {
if (tasklist_name == "TimeIntegratorTaskList") {
ptlist = std::make_unique<TimeIntegratorTaskList>(pin, mesh);
} else if (tasklist_name == "ImplicitHydroTasks") {
ptlist = std::make_unique<ImplicitHydroTasks>(pin, mesh);
} else if (tasklist_name == "InversionTasks") {
ptlist = std::make_unique<InversionTasks>(pin, mesh);
} else {
throw RuntimeError("main", "Unknown tasklist name: " + tasklist_name);
}
} catch (std::bad_alloc& ba) {
throw RuntimeError("main", "TaskList memory allocation failed");
}

return ptlist;
}
};

#endif // SRC_TASKLIST_TASK_LIST_FACTORY_HPP_

0 comments on commit e76d893

Please sign in to comment.