OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
FromFile Class Reference

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

#include <FromFile.h>

Inheritance diagram for FromFile:
Inheritance graph
[legend]
Collaboration diagram for FromFile:
Collaboration graph
[legend]

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)
 
- Public Member Functions inherited from SamplingMethod
virtual ~SamplingMethod ()
 
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
...
std::complex< double > a

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

Definition at line 50 of file 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 FromFile.cpp.

References filename_m, and globalSize_m.

◆ ~FromFile()

FromFile::~FromFile ( )
overridedefault

Destructor.

◆ FromFile() [2/3]

FromFile::FromFile ( const FromFile )
delete

◆ FromFile() [3/3]

FromFile::FromFile ( FromFile &&  )
defaultnoexcept

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 FromFile.cpp.

References chain_m, dvarName_m, filename_m, and globalSize_m.

◆ create()

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 FromFile.cpp.

References getNext().

Here is the call graph for this function:

◆ 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 FromFile.cpp.

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

Referenced by create().

◆ 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 FromFile.cpp.

References globalSize_m.

◆ operator()()

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

Definition at line 45 of file 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

◆ operator=() [2/2]

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

◆ readValues()

void FromFile::readValues ( )
private

reads a simple list of double values

Definition at line 29 of file 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 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 FromFile.h.

Referenced by allocate(), and getNext().

◆ filename_

std::string FromFile::filename_
private

Definition at line 73 of file 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 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 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 FromFile.h.

Referenced by getNext().

◆ name

const std::string FromFile::name
static

Definition at line 43 of file FromFile.h.

◆ values_

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

Definition at line 71 of file FromFile.h.

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


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