Skip to content

Commit

Permalink
Implement toml::DataSources except for reading from TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Aug 13, 2021
1 parent 341225a commit 77ed1a1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
39 changes: 39 additions & 0 deletions include/picongpu/plugins/openPMD/toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,45 @@ namespace picongpu
{
namespace toml
{
DataSources::DataSources(std::string tomlFiles) : m_period{{100, {std::string("fields_all"), "species_all"}}}
{
// todo: read from toml files
// verify that a step will always be available
m_upcomingSteps[0].reserve(m_period.size());
for(auto pair : m_period)
{
m_upcomingSteps[0].push_back(pair.first);
}
}

std::vector<std::string> DataSources::currentDataSources() const
{
std::set<std::string> result;
for(SimulationStep_t period : m_upcomingSteps.begin()->second)
{
for(std::string const& source : m_period.at(period))
{
result.insert(source);
}
}
return {result.begin(), result.end()};
}

auto DataSources::currentStep() const -> SimulationStep_t
{
return m_upcomingSteps.begin()->first;
}

DataSources& DataSources::operator++()
{
SimulationStep_t current = currentStep();
for(auto period : m_upcomingSteps.begin()->second)
{
m_upcomingSteps[current + period].push_back(period);
}
m_upcomingSteps.erase(m_upcomingSteps.begin());
return *this;
}
} // namespace toml
} // namespace picongpu

Expand Down
32 changes: 12 additions & 20 deletions include/picongpu/plugins/openPMD/toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

#pragma once

#include <cstdint>
#include <map>
#include <set>
#include <string>
#include <vector>

namespace picongpu
Expand All @@ -29,37 +31,27 @@ namespace picongpu
{
class DataSources
{
using Period_t = std::map<uint32_t, std::set<std::string>>;
public:
using SimulationStep_t = uint32_t;

private:
using Period_t = std::map<SimulationStep_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;
std::map<SimulationStep_t, std::vector<SimulationStep_t>> m_upcomingSteps;

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

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

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

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

0 comments on commit 77ed1a1

Please sign in to comment.