OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
src/Sample/FromFile.h
Go to the documentation of this file.
1//
2// Class FromFile
3// This class parses a file that contains design variable values.
4// Each column belongs to a design variable.
5// The first line is considered as header and consists of the
6// design variable name. The name has to agree with the string
7// in the input file.
8//
9// Copyright (c) 2018, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
10// All rights reserved
11//
12// Implemented as part of the PhD thesis
13// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
14//
15// This file is part of OPAL.
16//
17// OPAL is free software: you can redistribute it and/or modify
18// it under the terms of the GNU General Public License as published by
19// the Free Software Foundation, either version 3 of the License, or
20// (at your option) any later version.
21//
22// You should have received a copy of the GNU General Public License
23// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
24//
25#ifndef SAMPLE_FROMFILE_H
26#define SAMPLE_FROMFILE_H
27
29
30#include <string>
31#include <vector>
32
50class FromFile : public SamplingMethod {
51
52public:
53 explicit FromFile(const std::string& filename, const std::string& dvarName, std::size_t modulo);
54
56 ~FromFile() override = default;
57
58 // Disable copying to avoid issues with memory management
59 FromFile(const FromFile&) = delete;
60 FromFile& operator=(const FromFile&) = delete;
61
62 // Allow move semantics for efficient resource transfer
63 FromFile(FromFile&&) noexcept = default;
64 FromFile& operator=(FromFile&&) noexcept = default;
65
72 void create(std::shared_ptr<SampleIndividual>& ind, std::size_t i) override;
73
82 void allocate(const CmdArguments_t& args, const Comm::Bundle_t& comm) override;
83
92 double getNext(unsigned int id);
93
99 unsigned int getSize() const;
100
101private:
103 std::vector<double> chain_m;
104
106 std::size_t mod_m;
107
110
113
116};
117
118#endif
std::shared_ptr< CmdArguments > CmdArguments_t
STL namespace.
Definition types.h:26
void allocate(const CmdArguments_t &args, const Comm::Bundle_t &comm) override
Parses and loads the data from the file into memory.
FromFile(const FromFile &)=delete
std::size_t mod_m
Modulo used to wrap indices.
~FromFile() override=default
Destructor.
std::size_t globalSize_m
Number of lines in the file (including header).
unsigned int getSize() const
Get the number of lines in the file (including the header).
std::vector< double > chain_m
The values for the selected design variable loaded from the file.
std::string dvarName_m
Name of the design variable to extract.
void create(std::shared_ptr< SampleIndividual > &ind, std::size_t i) override
Assign a sampled value to an individual's gene.
FromFile(FromFile &&) noexcept=default
FromFile & operator=(const FromFile &)=delete
std::string filename_m
File name where samples are read from.
double getNext(unsigned int id)
Returns the next value for the given individual ID.
FromFile(const std::string &filename, const std::string &dvarName, std::size_t modulo)