Skip to content

Commit

Permalink
Partially de-template StabilityTester and make master non-templated
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertnash committed Jun 5, 2024
1 parent 9887f89 commit f99030b
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 221 deletions.
2 changes: 1 addition & 1 deletion Code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if (HEMELB_USE_DEBUGGER)
set(CMAKE_BUILD_TYPE Debug)
endif()

add_executable(${HEMELB_EXECUTABLE} main.cc)
add_executable(${HEMELB_EXECUTABLE} SimulationMaster.cc main.cc)
codesign(${HEMELB_EXECUTABLE})

include_directories(${PROJECT_SOURCE_DIR})
Expand Down
64 changes: 16 additions & 48 deletions Code/SimulationMaster.impl.h → Code/SimulationMaster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// the HemeLB team and/or their institutions, as detailed in the
// file AUTHORS. This software is provided under the terms of the
// license in the file LICENSE.
#ifndef HEMELB_SIMULATIONMASTER_IMPL_H
#define HEMELB_SIMULATIONMASTER_IMPL_H

#include "SimulationMaster.h"

Expand Down Expand Up @@ -39,8 +37,7 @@ namespace hemelb
* Initialises member variables including the network topology
* object.
*/
template<class TRAITS>
SimulationMaster<TRAITS>::SimulationMaster(configuration::CommandLine & options,
SimulationMaster::SimulationMaster(configuration::CommandLine & options,
const net::IOCommunicator& ioComm) :
build_info(), ioComms(ioComm.Duplicate()), communicationNet(ioComms)
{
Expand All @@ -56,32 +53,16 @@ namespace hemelb
// Use it to initialise self
auto builder = configuration::SimBuilder(simConfig);
log::Logger::Log<log::Info, log::Singleton>("Beginning Initialisation.");
builder(*this);
builder.build<>(*this);
}

/**
* Destructor for the SimulationMaster class.
*
* Deallocates dynamically allocated memory to contained classes.
*/
template<class TRAITS>
SimulationMaster<TRAITS>::~SimulationMaster() = default;

/**
* Returns true if the current processor is the dedicated I/O
* processor.
*/
template<class TRAITS>
bool SimulationMaster<TRAITS>::IsCurrentProcTheIOProc()
{
return ioComms.OnIORank();
}
/// Destructor for the SimulationMaster class.
SimulationMaster::~SimulationMaster() = default;

/**
* Returns the number of processors involved in the simulation.
*/
template<class TRAITS>
int SimulationMaster<TRAITS>::GetProcessorCount()
int SimulationMaster::GetProcessorCount()
{
return ioComms.Size();
}
Expand All @@ -90,20 +71,17 @@ namespace hemelb
* Initialises various elements of the simulation if necessary:
* domain decomposition, LBM and visualisation.
*/
template<class TRAITS>
void SimulationMaster<TRAITS>::Initialise()
void SimulationMaster::Initialise()
{

}

template<class TRAITS>
void SimulationMaster<TRAITS>::HandleActors()
void SimulationMaster::HandleActors()
{
stepManager->CallActions();
}

template<class TRAITS>
void SimulationMaster<TRAITS>::OnUnstableSimulation()
void SimulationMaster::OnUnstableSimulation()
{
LogStabilityReport();
log::Logger::Log<log::Warning, log::Singleton>("Aborting: time step length: %f\n",
Expand All @@ -115,8 +93,7 @@ namespace hemelb
/**
* Begin the simulation.
*/
template<class TRAITS>
void SimulationMaster<TRAITS>::RunSimulation()
void SimulationMaster::RunSimulation()
{
log::Logger::Log<log::Info, log::Singleton>("Beginning to run simulation.");
timings.simulation().Start();
Expand Down Expand Up @@ -145,8 +122,7 @@ namespace hemelb
Finalise();
}

template<class TRAITS>
void SimulationMaster<TRAITS>::Finalise()
void SimulationMaster::Finalise()
{
timings.total().Stop();
timings.Reduce(ioComms);
Expand All @@ -164,8 +140,7 @@ namespace hemelb
log::Logger::Log<log::Info, log::Singleton>("Finish running simulation.");
}

template<class TRAITS>
void SimulationMaster<TRAITS>::DoTimeStep()
void SimulationMaster::DoTimeStep()
{
log::Logger::Log<log::Debug, log::OnePerCore>("Current LB time: %e",
simulationState->GetTime());
Expand Down Expand Up @@ -218,8 +193,7 @@ namespace hemelb
simulationState->Increment();
}

template<class TRAITS>
void SimulationMaster<TRAITS>::RecalculatePropertyRequirements()
void SimulationMaster::RecalculatePropertyRequirements()
{
// Get the property cache & reset its list of properties to get.
lb::MacroscopicPropertyCache& propertyCache = latticeBoltzmannModel->GetPropertyCache();
Expand All @@ -242,8 +216,7 @@ namespace hemelb
/**
* Called on error to abort the simulation and pull-down the MPI environment.
*/
template<class TRAITS>
void SimulationMaster<TRAITS>::Abort()
void SimulationMaster::Abort()
{
// This gives us something to work from when we have an error - we get the rank
// that calls abort, and we get a stack-trace from the exception having been thrown.
Expand All @@ -253,8 +226,7 @@ namespace hemelb
exit(1);
}

template<class TRAITS>
void SimulationMaster<TRAITS>::LogStabilityReport()
void SimulationMaster::LogStabilityReport()
{
if (incompressibilityChecker && incompressibilityChecker->AreDensitiesAvailable())
{
Expand All @@ -274,20 +246,16 @@ namespace hemelb
}
}

template<class TRAITS>
const util::UnitConverter& SimulationMaster<TRAITS>::GetUnitConverter() const
const util::UnitConverter& SimulationMaster::GetUnitConverter() const
{
return *unitConverter;
}

template <class TRAITS>
configuration::SimConfig SimulationMaster<TRAITS>::ToConfig() const {
configuration::SimConfig SimulationMaster::ToConfig() const {
using namespace configuration;
SimConfig ans = simConfig;
if (simConfig.HasColloidSection())
throw (Exception() << "Checkpointing not implemented for colloids");
return ans;
}
}

#endif
17 changes: 8 additions & 9 deletions Code/SimulationMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <memory>

#include "lb/Lattices.h"
#include "lb/lb.hpp"
#include "lb/lb.h"
#include "lb/StabilityTester.h"
#include "net/net.h"
#include "lb/EntropyTester.h"
Expand All @@ -32,13 +32,10 @@ namespace hemelb
namespace extraction { class PropertyActor; }
namespace io { class Checkpointer; }

template<class TRAITS = Traits<>>
class SimulationMaster
{
public:
friend class configuration::SimBuilder;
using Traits = TRAITS;
using LatticeType = typename Traits::Lattice;

protected:
reporting::BuildInfo build_info;
Expand All @@ -53,7 +50,7 @@ namespace hemelb
/* The next quantities are protected because they are used by MultiscaleSimulationMaster */
std::shared_ptr<geometry::Domain> domainData;
std::shared_ptr<geometry::FieldData> fieldData;
std::shared_ptr<lb::LBM<Traits>> latticeBoltzmannModel;
std::shared_ptr<lb::LBMBase> latticeBoltzmannModel;
std::shared_ptr<geometry::neighbouring::NeighbouringDataManager> neighbouringDataManager;

std::shared_ptr<io::PathManager> fileManager;
Expand All @@ -62,8 +59,8 @@ namespace hemelb
std::shared_ptr<lb::SimulationState> simulationState;

/** Struct containing the configuration of various checkers/testers */
std::shared_ptr<lb::StabilityTester<LatticeType>> stabilityTester;
std::shared_ptr<lb::EntropyTester<LatticeType>> entropyTester;
std::shared_ptr<lb::StabilityTester> stabilityTester;
// std::shared_ptr<lb::EntropyTester<LatticeType>> entropyTester;
/** Actor in charge of checking the maximum density difference across the domain */
using ICC = lb::IncompressibilityChecker<net::PhasedBroadcastRegular<>>;
std::shared_ptr<ICC> incompressibilityChecker;
Expand All @@ -87,7 +84,10 @@ namespace hemelb

void Abort();

bool IsCurrentProcTheIOProc();
/// Returns true if the current processor is the dedicated I/O processor.
inline bool IsCurrentProcTheIOProc() {
return ioComms.OnIORank();
}

int GetProcessorCount();

Expand Down Expand Up @@ -143,5 +143,4 @@ namespace hemelb
};
}

#include "SimulationMaster.impl.h"
#endif /* HEMELB_SIMULATIONMASTER_H */
25 changes: 13 additions & 12 deletions Code/configuration/SimBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#ifndef HEMELB_CONFIGURATION_SIMBUILDER_H
#define HEMELB_CONFIGURATION_SIMBUILDER_H

#include "SimulationMaster.h"
#include "configuration/SimConfig.h"
#include "extraction/LbDataSourceIterator.h"
#include "extraction/PropertyActor.h"
#include "io/Checkpointer.h"
#include "geometry/GmyReadResult.h"
#include "geometry/neighbouring/NeighbouringDataManager.h"
#include "lb/lb.hpp"
#include "lb/InitialCondition.h"
#include "lb/StabilityTester.h"
#include "lb/IncompressibilityChecker.hpp"
Expand Down Expand Up @@ -64,8 +66,8 @@ namespace hemelb::configuration {
}

// Fully build the T = SimulationMaster<Traits> from the configuration.
template <typename T>
void operator()(T & control) const;
template <typename TRAITS = hemelb::Traits<>>
void build(SimulationMaster& control) const;

// The below could probably be protected/private, but handy for testing.
[[nodiscard]] std::shared_ptr<lb::SimulationState> BuildSimulationState() const;
Expand All @@ -89,8 +91,8 @@ namespace hemelb::configuration {
[[nodiscard]] std::shared_ptr<redblood::FlowExtension> BuildFlowExtension(FlowExtensionConfig const& conf) const;

[[nodiscard]] std::shared_ptr<net::IteratedAction> BuildColloidController() const;
template <typename T>
[[nodiscard]] std::shared_ptr<net::IteratedAction> BuildCellController(T const& control, reporting::Timers& timings) const;
template <typename traitsType>
[[nodiscard]] std::shared_ptr<net::IteratedAction> BuildCellController(SimulationMaster const& control, reporting::Timers& timings) const;
[[nodiscard]] lb::InitialCondition BuildInitialCondition() const;
[[nodiscard]] std::shared_ptr<extraction::PropertyActor> BuildPropertyExtraction(
std::filesystem::path const& xtr_path,
Expand All @@ -115,10 +117,9 @@ namespace hemelb::configuration {
};


template <typename T>
void SimBuilder::operator()(T& control) const {
using traitsType = typename T::Traits;
using LatticeType = typename T::LatticeType;
template <typename traitsType>
void SimBuilder::build(SimulationMaster& control) const {
using LatticeType = typename traitsType::Lattice;

auto& timings = control.timings;
auto& ioComms = control.ioComms;
Expand Down Expand Up @@ -198,7 +199,7 @@ namespace hemelb::configuration {
);
maybe_register_actor(control.outletValues, 1);

maybe_register_actor(control.cellController = BuildCellController<T>(control, timings), 1);
maybe_register_actor(control.cellController = BuildCellController<traitsType>(control, timings), 1);

// Copy cos about to scale to lattice units.
auto mon_conf = config.GetMonitoringConfiguration();
Expand All @@ -207,7 +208,7 @@ namespace hemelb::configuration {
}

// Always track stability
control.stabilityTester = std::make_shared<lb::StabilityTester<LatticeType>>(
control.stabilityTester = std::make_shared<lb::StabilityTesterImpl<LatticeType>>(
control.fieldData,
&control.communicationNet,
&*control.simulationState,
Expand Down Expand Up @@ -294,8 +295,8 @@ namespace hemelb::configuration {
}
#endif

template <typename T>
[[nodiscard]] std::shared_ptr<net::IteratedAction> SimBuilder::BuildCellController(T const& control, reporting::Timers& timings) const {
template <typename traitsType>
[[nodiscard]] std::shared_ptr<net::IteratedAction> SimBuilder::BuildCellController(SimulationMaster const& control, reporting::Timers& timings) const {
if (config.HasRBCSection()) {
#ifdef HEMELB_BUILD_RBC
using traitsType = typename T::Traits;
Expand Down
Loading

0 comments on commit f99030b

Please sign in to comment.