OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
FromFile Class Referenceabstract

Sampling method that reads design variable values from a text file. More...

#include <FromFile.h>

Inheritance diagram for FromFile:
Collaboration diagram for FromFile:

Public Member Functions

 FromFile (const std::string &filename, const std::string &dvarName, std::size_t modulo)
 ~FromFile () override=default
 Destructor.
 FromFile (const FromFile &)=delete
FromFileoperator= (const FromFile &)=delete
 FromFile (FromFile &&) noexcept=default
FromFileoperator= (FromFile &&) noexcept=default
void create (std::shared_ptr< SampleIndividual > &ind, std::size_t i) override
 Assign a sampled value to an individual's gene.
void allocate (const CmdArguments_t &args, const Comm::Bundle_t &comm) override
 Parses and loads the data from the file into memory.
double getNext (unsigned int id)
 Returns the next value for the given individual ID.
unsigned int getSize () const
 Get the number of lines in the file (including the header).
Expressions::Result_t operator() (client::function::arguments_t args)
virtual void create (std::shared_ptr< SampleIndividual > &ind, size_t i)=0

Static Public Attributes

static const std::string name

Private Member Functions

void readValues ()
 reads a simple list of double values

Private Attributes

std::vector< double > chain_m
 The values for the selected design variable loaded from the file.
std::size_t mod_m
 Modulo used to wrap indices.
std::string filename_m
 File name where samples are read from.
std::string dvarName_m
 Name of the design variable to extract.
std::size_t globalSize_m
 Number of lines in the file (including header).
std::vector< double > values_
std::string filename_

Detailed Description

Sampling method that reads design variable values from a text file.

This class parses a file containing design variable samples. Each column corresponds to a variable, and the first line must contain the names of the variables. It supports selecting a specific column and accessing values sequentially or cyclically.

The expected file format is:

a b c
1 2 3
4 5 6
...
constexpr double c
The velocity of light in m/s.
Definition Physics.h:45
std::complex< double > a

where "a", "b", "c" are variable names and subsequent lines are numerical values.

Definition at line 50 of file src/Sample/FromFile.h.

Constructor & Destructor Documentation

◆ FromFile() [1/3]

FromFile::FromFile ( const std::string & filename,
const std::string & dvarName,
std::size_t modulo )
explicit

Definition at line 34 of file src/Sample/FromFile.cpp.

References dvarName_m, filename_m, globalSize_m, and mod_m.

Referenced by FromFile(), FromFile(), operator=(), and operator=().

◆ ~FromFile()

FromFile::~FromFile ( )
overridedefault

Destructor.

◆ FromFile() [2/3]

FromFile::FromFile ( const FromFile & )
delete

References FromFile().

Here is the call graph for this function:

◆ FromFile() [3/3]

FromFile::FromFile ( FromFile && )
defaultnoexcept

References FromFile().

Here is the call graph for this function:

Member Function Documentation

◆ allocate()

void FromFile::allocate ( const CmdArguments_t & args,
const Comm::Bundle_t & comm )
overridevirtual

Parses and loads the data from the file into memory.

Parameters
argsCommand-line arguments (unused here).
commCommunication context (unused here).
Exceptions
OpalExceptionif the file is invalid or the variable is missing.

Reimplemented from SamplingMethod.

Definition at line 64 of file src/Sample/FromFile.cpp.

References chain_m, dvarName_m, filename_m, and globalSize_m.

Referenced by operator=().

◆ create() [1/2]

void FromFile::create ( std::shared_ptr< SampleIndividual > & ind,
std::size_t i )
override

Assign a sampled value to an individual's gene.

Parameters
indThe individual to modify.
iIndex of the gene (design variable) to assign.

Definition at line 60 of file src/Sample/FromFile.cpp.

References getNext().

Referenced by operator=().

Here is the call graph for this function:

◆ create() [2/2]

virtual void SamplingMethod::create ( std::shared_ptr< SampleIndividual > & ind,
size_t i )
pure virtualinherited

◆ getNext()

double FromFile::getNext ( unsigned int id)

Returns the next value for the given individual ID.

The value is selected cyclically from the chain.

Parameters
idThe individual's ID.
Returns
The corresponding sample value.

Definition at line 126 of file src/Sample/FromFile.cpp.

References chain_m, dvarName_m, filename_m, globalSize_m, and mod_m.

Referenced by create(), and operator=().

◆ getSize()

unsigned int FromFile::getSize ( ) const

Get the number of lines in the file (including the header).

Returns
Number of total lines parsed from the file.

Definition at line 137 of file src/Sample/FromFile.cpp.

References globalSize_m.

Referenced by OpalSample::initialize(), and operator=().

◆ operator()()

Expressions::Result_t FromFile::operator() ( client::function::arguments_t args)
inline

Definition at line 48 of file optimizer/Expression/FromFile.h.

References filename_, readValues(), sum(), and values_.

Here is the call graph for this function:

◆ operator=() [1/2]

FromFile & FromFile::operator= ( const FromFile & )
delete

References FromFile().

Here is the call graph for this function:

◆ operator=() [2/2]

FromFile & FromFile::operator= ( FromFile && )
defaultnoexcept

References allocate(), create(), FromFile(), getNext(), and getSize().

Here is the call graph for this function:

◆ readValues()

void FromFile::readValues ( )
private

reads a simple list of double values

Definition at line 29 of file optimizer/Expression/FromFile.cpp.

References filename_, and values_.

Referenced by operator()().

Member Data Documentation

◆ chain_m

std::vector<double> FromFile::chain_m
private

The values for the selected design variable loaded from the file.

Definition at line 103 of file src/Sample/FromFile.h.

Referenced by allocate(), and getNext().

◆ dvarName_m

std::string FromFile::dvarName_m
private

Name of the design variable to extract.

Definition at line 112 of file src/Sample/FromFile.h.

Referenced by allocate(), FromFile(), and getNext().

◆ filename_

std::string FromFile::filename_
private

Definition at line 76 of file optimizer/Expression/FromFile.h.

Referenced by operator()(), and readValues().

◆ filename_m

std::string FromFile::filename_m
private

File name where samples are read from.

Definition at line 109 of file src/Sample/FromFile.h.

Referenced by allocate(), FromFile(), and getNext().

◆ globalSize_m

std::size_t FromFile::globalSize_m
private

Number of lines in the file (including header).

Definition at line 115 of file src/Sample/FromFile.h.

Referenced by allocate(), FromFile(), getNext(), and getSize().

◆ mod_m

std::size_t FromFile::mod_m
private

Modulo used to wrap indices.

Definition at line 106 of file src/Sample/FromFile.h.

Referenced by FromFile(), and getNext().

◆ name

const std::string FromFile::name
static

Definition at line 46 of file optimizer/Expression/FromFile.h.

◆ values_

std::vector<double> FromFile::values_
private

Definition at line 74 of file optimizer/Expression/FromFile.h.

Referenced by operator()(), and readValues().


The documentation for this class was generated from the following files: