Skip to content

Commit

Permalink
Use toml::DataSources in openPMD plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Aug 12, 2021
1 parent 00c5c33 commit 341225a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/picongpu/plugins/openPMD/openPMDWriter.def
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "picongpu/simulation_defines.hpp"

#include "picongpu/plugins/openPMD/Json.hpp"
#include "picongpu/plugins/openPMD/toml.hpp"
#include "picongpu/simulation/control/MovingWindow.hpp"

#include <pmacc/math/Vector.hpp>
Expand Down Expand Up @@ -89,6 +90,8 @@ namespace picongpu

std::unique_ptr<AbstractJsonMatcher> jsonMatcher;

std::unique_ptr<toml::DataSources> tomlDataSources;

WriteSpeciesStrategy strategy = WriteSpeciesStrategy::ADIOS;

pmacc::math::UInt64<simDim> fieldsSizeDims;
Expand Down
41 changes: 40 additions & 1 deletion include/picongpu/plugins/openPMD/openPMDWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ Please pick either of the following:

plugins::multi::Option<std::string> source = {"source", "data sources: ", "species_all, fields_all"};

plugins::multi::Option<std::string> tomlSources = {"toml", "specify dynamic data sources via TOML", ""};

std::vector<std::string> allowedDataSources = {"species_all", "fields_all"};

plugins::multi::Option<std::string> fileName = {"file", "openPMD file basename"};
Expand Down Expand Up @@ -302,6 +304,7 @@ Please pick either of the following:
boost::program_options::options_description& desc,
std::string const& masterPrefix = std::string{})
{
tomlSources.registerHelp(desc, masterPrefix + prefix);
compression.registerHelp(desc, masterPrefix + prefix);
fileName.registerHelp(desc, masterPrefix + prefix);
fileNameExtension.registerHelp(desc, masterPrefix + prefix);
Expand Down Expand Up @@ -409,6 +412,12 @@ Please pick either of the following:
<< std::endl;
}
}

std::string const& notifyPeriod = help.notifyPeriod.get(id);
if(!tomlDataSources && notifyPeriod == "dynamic")
{
tomlDataSources = std::make_unique<toml::DataSources>(help.tomlSources.get(id));
}
}

/** Writes simulation data to openPMD.
Expand Down Expand Up @@ -624,7 +633,14 @@ Please pick either of the following:
std::string notifyPeriod = m_help->notifyPeriod.get(id);
/* only register for notify callback when .period is set on
* command line */
if(!notifyPeriod.empty())
if(notifyPeriod == "dynamic")
{
Environment<>::get().PluginConnector().setNotificationPeriod(this, "1");

/** create notify directory */
Environment<simDim>::get().Filesystem().createDirectoryWithPermissions(outputDirectory);
}
else if(!notifyPeriod.empty())
{
Environment<>::get().PluginConnector().setNotificationPeriod(this, notifyPeriod);

Expand Down Expand Up @@ -656,6 +672,11 @@ Please pick either of the following:
// notify is only allowed if the plugin is not controlled by the
// class Checkpoint
assert(m_help->selfRegister);
if(mThreadParams.tomlDataSources && mThreadParams.tomlDataSources->currentStep() != currentStep)
{
// nothing to do
return;
}

__getTransactionEvent().waitForFinished();

Expand All @@ -665,6 +686,10 @@ Please pick either of the following:
mThreadParams.window = MovingWindow::getInstance().getWindow(currentStep);
mThreadParams.isCheckpoint = false;
dumpData(currentStep);
if(mThreadParams.tomlDataSources)
{
++*mThreadParams.tomlDataSources;
}
}

virtual void restart(uint32_t restartStep, std::string const& restartDirectory)
Expand Down Expand Up @@ -780,6 +805,20 @@ Please pick either of the following:
}

private:
std::vector<std::string> currentDataSources()
{
if(mThreadParams.tomlDataSources)
{
return mThreadParams.tomlDataSources->currentDataSources();
}
else
{
std::string dataSourceNames = m_help->source.get(m_id);

return plugins::misc::splitString(plugins::misc::removeSpaces(dataSourceNames));
}
}

void endWrite()
{
mThreadParams.fieldBuffer.resize(0);
Expand Down
38 changes: 38 additions & 0 deletions include/picongpu/plugins/openPMD/toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,47 @@

#pragma once

#include <map>
#include <set>
#include <vector>

namespace picongpu
{
namespace toml
{
class DataSources
{
using Period_t = std::map<uint32_t, std::set<std::string>>;
Period_t m_period;

/*
* For each period p, let s be the upcoming step divisible by p.
* Then m_nextActiveAt[s] contains p.
*/
std::map<uint32_t, std::vector<uint32_t>> m_nextActiveAt;

public:
DataSources(std::string tomlFiles)
{
// todo: read from toml files
}

std::vector<std::string> currentDataSources() const
{
// todo
return {std::string("fields_all"), "species_all"};
}

uint32_t currentStep() const
{
return m_period.begin()->first;
}

DataSources& operator++()
{
// todo
return *this;
}
};
} // namespace toml
} // namespace picongpu

0 comments on commit 341225a

Please sign in to comment.