Skip to content

Commit

Permalink
seperate main.cpp into two files
Browse files Browse the repository at this point in the history
  • Loading branch information
yoctoyotta1024 committed Apr 16, 2024
1 parent 8d8b186 commit fbfaeb0
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 220 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_executable(cleocoupledsdm main.cpp)
target_link_libraries(cleocoupledsdm PRIVATE coupldyn_fromfile cartesiandomain ${CLEOLIBS})
target_link_libraries(cleocoupledsdm PUBLIC Kokkos::kokkos)
target_include_directories(cleocoupledsdm PRIVATE "${CMAKE_SOURCE_DIR}/libs")
#target_include_directories(cleocoupledsdm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(cleocoupledsdm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

# set specific C++ compiler options for target (optional)
#target_compile_options(cleocoupledsdm PRIVATE)
Expand Down
220 changes: 1 addition & 219 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,225 +21,7 @@
* ./src/cleocoupledsdm ../src/config/config.txt
*/

#include <Kokkos_Core.hpp>
#include <cmath>
#include <concepts>
#include <iostream>
#include <stdexcept>
#include <string_view>

#include "cartesiandomain/cartesianmaps.hpp"
#include "cartesiandomain/cartesianmotion.hpp"
#include "cartesiandomain/cartesianmotion_withreset.hpp"
#include "cartesiandomain/createcartesianmaps.hpp"
#include "coupldyn_fromfile/fromfile_cartesian_dynamics.hpp"
#include "coupldyn_fromfile/fromfilecomms.hpp"
#include "gridboxes/gridboxmaps.hpp"
#include "gridboxes/movesupersindomain.hpp"
#include "initialise/config.hpp"
#include "initialise/initgbxs_null.hpp"
#include "initialise/initsupers_frombinary.hpp"
#include "initialise/timesteps.hpp"
#include "observers/gbxindex_observer.hpp"
#include "observers/massmoments_observer.hpp"
#include "observers/nsupers_observer.hpp"
#include "observers/observers.hpp"
#include "observers/runstats_observer.hpp"
#include "observers/state_observer.hpp"
#include "observers/streamout_observer.hpp"
#include "observers/superdrops_observer.hpp"
#include "observers/time_observer.hpp"
#include "observers/totnsupers_observer.hpp"
#include "runcleo/coupleddynamics.hpp"
#include "runcleo/couplingcomms.hpp"
#include "runcleo/initialconditions.hpp"
#include "runcleo/runcleo.hpp"
#include "runcleo/sdmmethods.hpp"
#include "superdrops/collisions/breakup.hpp"
#include "superdrops/collisions/breakup_nfrags.hpp"
#include "superdrops/collisions/coalbure.hpp"
#include "superdrops/collisions/coalbure_flag.hpp"
#include "superdrops/collisions/coalescence.hpp"
#include "superdrops/collisions/constprob.hpp"
#include "superdrops/collisions/golovinprob.hpp"
#include "superdrops/collisions/longhydroprob.hpp"
#include "superdrops/collisions/lowlistprob.hpp"
#include "superdrops/condensation.hpp"
#include "superdrops/microphysicalprocess.hpp"
#include "superdrops/motion.hpp"
#include "superdrops/terminalvelocity.hpp"
#include "zarr/dataset.hpp"
#include "zarr/fsstore.hpp"

struct NullBoundaryConditions {
void operator()(const GridboxMaps auto &gbxmaps, viewd_gbx d_gbxs,
const viewd_supers totsupers) const {}
};

inline CoupledDynamics auto create_coupldyn(const Config &config, const CartesianMaps &gbxmaps,
const unsigned int couplstep,
const unsigned int t_end) {
const auto h_ndims(gbxmaps.ndims_hostcopy());
const std::array<size_t, 3> ndims({h_ndims(0), h_ndims(1), h_ndims(2)});

const auto nsteps = (unsigned int)(std::ceil(t_end / couplstep) + 1);

return FromFileDynamics(config, couplstep, ndims, nsteps);
}

inline InitialConditions auto create_initconds(const Config &config) {
const InitSupersFromBinary initsupers(config);
const InitGbxsNull initgbxs(config);

return InitConds(initsupers, initgbxs);
}

inline GridboxMaps auto create_gbxmaps(const Config &config) {
const auto gbxmaps = create_cartesian_maps(config.ngbxs, config.nspacedims, config.grid_filename);
return gbxmaps;
}

inline Motion<CartesianMaps> auto create_motion(const unsigned int motionstep) {
// const auto terminalv = NullTerminalVelocity{};
// const auto terminalv = RogersYauTerminalVelocity{};
// const auto terminalv = SimmelTerminalVelocity{};
const auto terminalv = RogersGKTerminalVelocity{};

// const auto ngbxs = (unsigned int)15; // total number of gbxs
// const auto ngbxs4reset = (unsigned int)5; // number of gbxs to randomly select in reset
// return CartesianMotionWithReset(motionstep,
// &step2dimlesstime,
// terminalv,
// ngbxs,
// ngbxs4reset);

return CartesianMotion(motionstep, &step2dimlesstime, terminalv);

// return NullMotion{};
}

inline auto create_boundary_conditions(const Config &config) { return NullBoundaryConditions{}; }

template <GridboxMaps GbxMaps>
inline auto create_movement(const Config &config, const Timesteps &tsteps, const GbxMaps &gbxmaps) {
const Motion<GbxMaps> auto motion(create_motion(tsteps.get_motionstep()));

const auto boundary_conditions(create_boundary_conditions(config));

return MoveSupersInDomain(gbxmaps, motion, boundary_conditions);
}

inline MicrophysicalProcess auto config_condensation(const Config &config,
const Timesteps &tsteps) {
return Condensation(tsteps.get_condstep(), config.doAlterThermo, config.cond_iters,
&step2dimlesstime, config.cond_rtol, config.cond_atol, config.cond_SUBTSTEP,
&realtime2dimless);
}

inline MicrophysicalProcess auto config_collisions(const Config &config, const Timesteps &tsteps) {
// const PairProbability auto collprob = LongHydroProb();
// // const NFragments auto nfrags = ConstNFrags(5.0);
// const NFragments auto nfrags = CollisionKineticEnergyNFrags{};
// // const CoalBuReFlag auto coalbure_flag = SUCoalBuReFlag{};
// const CoalBuReFlag auto coalbure_flag = TSCoalBuReFlag{};
// const MicrophysicalProcess auto colls = CoalBuRe(tsteps.get_collstep(),
// &step2realtime,
// collprob,
// nfrags,
// coalbure_flag);
// return colls;

// const PairProbability auto buprob = LowListBuProb();
// const NFragments auto nfrags = ConstNFrags(5.0);
// const MicrophysicalProcess auto bu = CollBu(tsteps.get_collstep(),
// &step2realtime,
// buprob,
// nfrags);

// const PairProbability auto coalprob = LowListCoalProb();
// const PairProbability auto coalprob = GolovinProb();
const PairProbability auto coalprob = LongHydroProb(1.0);
const MicrophysicalProcess auto coal = CollCoal(tsteps.get_collstep(), &step2realtime, coalprob);

return coal;
// return coal >> bu;
}

inline MicrophysicalProcess auto create_microphysics(const Config &config,
const Timesteps &tsteps) {
const MicrophysicalProcess auto cond = config_condensation(config, tsteps);

const MicrophysicalProcess auto colls = config_collisions(config, tsteps);

// const MicrophysicalProcess auto null = NullMicrophysicalProcess{};

return colls >> cond;
}

template <typename Store>
inline Observer auto create_superdrops_observer(const unsigned int interval,
Dataset<Store> &dataset, const int maxchunk) {
CollectDataForDataset<Store> auto sdid = CollectSdId(dataset, maxchunk);
CollectDataForDataset<Store> auto sdgbxindex = CollectSdgbxindex(dataset, maxchunk);
CollectDataForDataset<Store> auto xi = CollectXi(dataset, maxchunk);
CollectDataForDataset<Store> auto radius = CollectRadius(dataset, maxchunk);
CollectDataForDataset<Store> auto msol = CollectMsol(dataset, maxchunk);
CollectDataForDataset<Store> auto coord3 = CollectCoord3(dataset, maxchunk);
// CollectDataForDataset<Store> auto coord1 = CollectCoord1(dataset, maxchunk);
// CollectDataForDataset<Store> auto coord2 = CollectCoord2(dataset, maxchunk);

const auto collect_sddata = coord3 >> msol >> radius >> xi >> sdgbxindex >> sdid;
return SuperdropsObserver(interval, dataset, maxchunk, collect_sddata);
}

template <typename Store>
inline Observer auto create_gridboxes_observer(const unsigned int interval, Dataset<Store> &dataset,
const int maxchunk, const size_t ngbxs) {
const CollectDataForDataset<Store> auto thermo = CollectThermo(dataset, maxchunk, ngbxs);
const CollectDataForDataset<Store> auto windvel = CollectWindVel(dataset, maxchunk, ngbxs);
const CollectDataForDataset<Store> auto nsupers = CollectNsupers(dataset, maxchunk, ngbxs);

const CollectDataForDataset<Store> auto collect_gbxdata = nsupers >> windvel >> thermo;
return WriteToDatasetObserver(interval, dataset, collect_gbxdata);
}

template <typename Store>
inline Observer auto create_observer(const Config &config, const Timesteps &tsteps,
Dataset<Store> &dataset) {
const auto obsstep = (unsigned int)tsteps.get_obsstep();
const auto maxchunk = int{config.maxchunk};

const Observer auto obs0 = RunStatsObserver(obsstep, config.stats_filename);

const Observer auto obs1 = StreamOutObserver(obsstep * 10, &step2realtime);

const Observer auto obs2 = TimeObserver(obsstep, dataset, maxchunk, &step2dimlesstime);

const Observer auto obs3 = GbxindexObserver(dataset, maxchunk, config.ngbxs);

const Observer auto obs4 = TotNsupersObserver(obsstep, dataset, maxchunk);

const Observer auto obs5 = MassMomentsObserver(obsstep, dataset, maxchunk, config.ngbxs);

const Observer auto obs6 = MassMomentsRaindropsObserver(obsstep, dataset, maxchunk, config.ngbxs);

const Observer auto obsgbx = create_gridboxes_observer(obsstep, dataset, maxchunk, config.ngbxs);

const Observer auto obssd = create_superdrops_observer(obsstep, dataset, maxchunk);

return obssd >> obsgbx >> obs6 >> obs5 >> obs4 >> obs3 >> obs2 >> obs1 >> obs0;
}

template <typename Store>
inline auto create_sdm(const Config &config, const Timesteps &tsteps, Dataset<Store> &dataset) {
const auto couplstep = (unsigned int)tsteps.get_couplstep();
const GridboxMaps auto gbxmaps(create_gbxmaps(config));
const MicrophysicalProcess auto microphys(create_microphysics(config, tsteps));
const auto movesupers(create_movement(config, tsteps, gbxmaps));
const Observer auto obs(create_observer(config, tsteps, dataset));

return SDMMethods(couplstep, gbxmaps, microphys, movesupers, obs);
}
#include "./main_impl.hpp"

int main(int argc, char *argv[]) {
if (argc < 2) {
Expand Down
Loading

0 comments on commit fbfaeb0

Please sign in to comment.