OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
olb::opti::Controller< S > Class Template Reference

#include <controller.h>

+ Inheritance diagram for olb::opti::Controller< S >:
+ Collaboration diagram for olb::opti::Controller< S >:

Public Member Functions

 Controller (int dimControl)
 
 Controller (std::vector< S > &initialValues)
 
S const & getControl (int i) const
 
S & getControl (int i)
 
const std::vector< S > & getControl ()
 
int getDimControl () const
 
void setControl (const std::vector< S > &control, int dimControl)
 
void print ()
 
void writeToFile (const char *fname=nullptr)
 
void readFromFile (const char *fname)
 

Protected Attributes

int _dimControl
 
std::vector< S > _control
 

Detailed Description

template<typename S>
class olb::opti::Controller< S >

Definition at line 43 of file controller.h.

Constructor & Destructor Documentation

◆ Controller() [1/2]

template<typename S >
olb::opti::Controller< S >::Controller ( int dimControl)
inline

Definition at line 50 of file controller.h.

51 : _dimControl (dimControl),
52 _control (dimControl, 0.0)
53 { }
std::vector< S > _control
Definition controller.h:47

◆ Controller() [2/2]

template<typename S >
olb::opti::Controller< S >::Controller ( std::vector< S > & initialValues)
inline

Definition at line 55 of file controller.h.

56 : _dimControl(initialValues.size()), _control(initialValues)
57 { }

Member Function Documentation

◆ getControl() [1/3]

template<typename S >
const std::vector< S > & olb::opti::Controller< S >::getControl ( )
inline

Definition at line 67 of file controller.h.

68 {
69 return _control;
70 };

References olb::opti::Controller< S >::_control.

◆ getControl() [2/3]

template<typename S >
S & olb::opti::Controller< S >::getControl ( int i)
inline

Definition at line 63 of file controller.h.

64 {
65 return _control[i];
66 };

References olb::opti::Controller< S >::_control.

◆ getControl() [3/3]

template<typename S >
S const & olb::opti::Controller< S >::getControl ( int i) const
inline

Definition at line 59 of file controller.h.

60 {
61 return _control[i];
62 };

References olb::opti::Controller< S >::_control.

+ Here is the caller graph for this function:

◆ getDimControl()

template<typename S >
int olb::opti::Controller< S >::getDimControl ( ) const
inline

Definition at line 72 of file controller.h.

73 {
74 return _dimControl;
75 };

References olb::opti::Controller< S >::_dimControl.

◆ print()

template<typename S >
void olb::opti::Controller< S >::print ( )
inline

Definition at line 83 of file controller.h.

84 {
85 static OstreamManager clout(std::cout,"Controller");
86
87 clout << " control={ ";
88 for (int i=0; i<_dimControl; i++) {
89 clout << _control[i] << " ";
90 }
91 clout << "}" << std::endl;
92
93 };

References olb::opti::Controller< S >::_control, and olb::opti::Controller< S >::_dimControl.

◆ readFromFile()

template<typename S >
void olb::opti::Controller< S >::readFromFile ( const char * fname)
inline

Definition at line 116 of file controller.h.

117 {
118 static OstreamManager clout(std::cout,"Controller");
119 std::ifstream file;
120 // if (file.open(fname)) {
121 file.open(fname);
122 int dim;
123 file >> dim;
124 if (dim!=_dimControl) {
125 clout << "Error: dimensions do not match! dim_controller=" << _dimControl << "; dim_file=" << dim << std::endl;
126 assert(false);
127 }
128 else {
129 for (int i=0; i<_dimControl; i++) {
130 double tmpVal;
131 file >> tmpVal;
132 _control[i] = tmpVal;
133 }
134 }
135 file.close();
136 // }
137 }

References olb::opti::Controller< S >::_control, and olb::opti::Controller< S >::_dimControl.

◆ setControl()

template<typename S >
void olb::opti::Controller< S >::setControl ( const std::vector< S > & control,
int dimControl )
inline

Definition at line 77 of file controller.h.

78 {
80 _dimControl = dimControl;
81 };

References olb::opti::Controller< S >::_control, olb::opti::Controller< S >::_dimControl, and olb::opti::control.

◆ writeToFile()

template<typename S >
void olb::opti::Controller< S >::writeToFile ( const char * fname = nullptr)
inline

Definition at line 95 of file controller.h.

96 {
97 static OstreamManager clout(std::cout,"Controller");
98 std::ofstream file;
99 if (fname==nullptr) {
100 static int iter(0);
101 std::stringstream number;
102 number << std::setw(3) << std::setfill('0') << iter++;
103 file.open(("Controller" + number.str() + ".txt").c_str());
104 }
105 else {
106 file.open(fname);
107 }
108
109 file << _dimControl << std::endl;
110 for (int i=0; i<_dimControl; i++) {
111 file << _control[i] << std::endl;
112 }
113 file.close();
114 };

References olb::opti::Controller< S >::_control, and olb::opti::Controller< S >::_dimControl.

Member Data Documentation

◆ _control

template<typename S >
std::vector<S> olb::opti::Controller< S >::_control
protected

Definition at line 47 of file controller.h.

◆ _dimControl

template<typename S >
int olb::opti::Controller< S >::_dimControl
protected

Definition at line 46 of file controller.h.


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