This example shows how to implement a virtual container for ordinary lattice points that can be used by simulation software.
#ifndef LATTICE_POINTS_H
#define LATTICE_POINTS_H
class LatticePoints {
public:
typedef std::vector<double> value_type;
typedef size_t size_type;
LatticePoints(size_type numPoints, std::vector<unsigned long> gen):
m_numPoints(numPoints),
m_intGen(std::move(gen)),
m_gen(m_intGen.size())
{ updateGen(); }
size_type numPoints() const { return m_numPoints; }
size_type size() const { return m_numPoints; }
size_type dimension() const { return m_gen.size(); }
value_type operator[](size_type i) const
{
std::vector<double> point(dimension());
for (size_type j = 0; j < point.size(); j++) {
double x = i * m_gen[j];
point[j] = x - int(x);
}
return point;
}
private:
size_type m_numPoints;
std::vector<unsigned long> m_intGen;
std::vector<double> m_gen;
void updateGen()
{
for (size_type j = 0; j < m_gen.size(); j++)
m_gen[j] = double(m_intGen[j]) / m_numPoints;
}
};
#endif