https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
MutableCoefficientsInterface Class Reference

This class is designed to provide a uniform interface for any class that uses an array of coefficients for any of its operations. More...

#include <MutableCoefficientsInterface.h>

Inheritance diagram for MutableCoefficientsInterface:
[legend]

Public Member Functions

 MutableCoefficientsInterface (const MooseObject *moose_object, const InputParameters &parameters)
 
Real operator[] (std::size_t index) const
 Get the value of the coefficient at the corresponding index.
 
const std::vector< std::size_t > & getCharacteristics () const
 Get a reference to the characteristics array.
 
const std::vector< Real > & getCoefficients () const
 Get a read-only reference to the vector of coefficients.
 
std::vector< Real > & getCoefficients ()
 Get a writeable reference to the vector of coefficients.
 
std::string getCoefficientsTable () const
 Get a formatted string of the coefficients.
 
std::size_t getSize () const
 Get the size, aka number of coefficients.
 
bool isCompatibleWith (const MutableCoefficientsInterface &other) const
 Checks to see if another instance is compatible.
 
bool isSizeEnforced () const
 Returns true if the size of the coefficient array is fixed and enforced.
 
void enforceSize (bool enforce)
 Toggle whether the size of the coefficient array can be changed.
 
void importCoefficients (const MutableCoefficientsInterface &other)
 Import the coefficients from another instance.
 
void resize (std::size_t size, Real fill=0.0, bool fill_out_to_size=true)
 Resize the array, using the value for fill if the new size is larger.
 
void setCharacteristics (const std::vector< std::size_t > &new_characteristics)
 Sets the characteristics array.
 
void setCoefficients (const std::vector< Real > &new_coefficients)
 Set the coefficients using a copy operation.
 
void setCoefficients (std::vector< Real > &&dropin_coefficients)
 Set the coefficients using a move operation (only works with temp objects)
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

virtual void coefficientsChanged ()
 Called when the coefficients have been changed.
 
TdeclareRestartableData (const std::string &data_name, Args &&... args)
 
ManagedValue< TdeclareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
const TgetRestartableData (const std::string &data_name) const
 
TdeclareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
TdeclareRecoverableData (const std::string &data_name, Args &&... args)
 
TdeclareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 
TdeclareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 
std::string restartableName (const std::string &data_name) const
 

Protected Attributes

std::vector< std::size_t > & _characteristics
 An array of integer characteristics that can be used to check compatibility.
 
std::vector< Real > & _coefficients
 The coefficient array.
 
bool _enforce_size
 Boolean that locks or allows resizing of the coefficient array.
 
const bool _print_coefficients
 Boolean to flag if the coefficients should be printed when set.
 
MooseApp_restartable_app
 
const std::string _restartable_system_name
 
const THREAD_ID _restartable_tid
 
const bool _restartable_read_only
 

Private Member Functions

RestartableDataValueregisterRestartableDataOnApp (std::unique_ptr< RestartableDataValue > data, THREAD_ID tid) const
 
void registerRestartableNameWithFilterOnApp (const std::string &name, Moose::RESTARTABLE_FILTER filter)
 
RestartableData< T > & declareRestartableDataHelper (const std::string &data_name, void *context, Args &&... args) const
 

Private Attributes

const ConsoleStream_console
 MooseObject instance of this to provide access to _console
 
const RestartableDataMapName _metaname
 
std::string _restartable_name
 

Friends

std::ostream & operator<< (std::ostream &stream, const MutableCoefficientsInterface &me)
 Friend operator to easily print out the array of coefficients.
 

Detailed Description

This class is designed to provide a uniform interface for any class that uses an array of coefficients for any of its operations.

In particular, the MultiAppFXTransfer mechanism transfers coefficients using this interface. Any derived class of MutableCoefficientsInterface can easily be used in any MultiAppFXTransfer-based transfer.

Definition at line 26 of file MutableCoefficientsInterface.h.

Constructor & Destructor Documentation

◆ MutableCoefficientsInterface()

MutableCoefficientsInterface::MutableCoefficientsInterface ( const MooseObject moose_object,
const InputParameters parameters 
)

Definition at line 30 of file MutableCoefficientsInterface.C.

32 : Restartable(moose_object->getMooseApp(),
33 moose_object->name() + "_coefs",
34 "MutableCoefficientsInterface",
35 moose_object->parameters().get<THREAD_ID>("_tid")),
36 _characteristics(declareRestartableData<std::vector<std::size_t>>("characteristics")),
37 _coefficients(declareRestartableData<std::vector<Real>>("coefficients")),
38 _enforce_size(false),
39 _print_coefficients(parameters.get<bool>("print_when_set")),
40 _console(moose_object->_console)
41{
42}
unsigned int THREAD_ID
const ConsoleStream _console
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const InputParameters & parameters() const
const std::string & name() const
MooseApp & getMooseApp() const
bool _enforce_size
Boolean that locks or allows resizing of the coefficient array.
std::vector< std::size_t > & _characteristics
An array of integer characteristics that can be used to check compatibility.
const bool _print_coefficients
Boolean to flag if the coefficients should be printed when set.
const ConsoleStream & _console
MooseObject instance of this to provide access to _console
std::vector< Real > & _coefficients
The coefficient array.
T & declareRestartableData(const std::string &data_name, Args &&... args)

Member Function Documentation

◆ coefficientsChanged()

virtual void MutableCoefficientsInterface::coefficientsChanged ( )
inlineprotectedvirtual

Called when the coefficients have been changed.

Reimplemented in MutableCoefficientsFunctionInterface.

Definition at line 105 of file MutableCoefficientsInterface.h.

105{}

Referenced by importCoefficients(), resize(), setCoefficients(), and setCoefficients().

◆ enforceSize()

void MutableCoefficientsInterface::enforceSize ( bool  enforce)

Toggle whether the size of the coefficient array can be changed.

Definition at line 111 of file MutableCoefficientsInterface.C.

112{
113 _enforce_size = enforce;
114}

Referenced by FunctionSeries::FunctionSeries(), and MutableCoefficientsFunctionInterface::MutableCoefficientsFunctionInterface().

◆ getCharacteristics()

const std::vector< std::size_t > & MutableCoefficientsInterface::getCharacteristics ( ) const

Get a reference to the characteristics array.

Definition at line 51 of file MutableCoefficientsInterface.C.

52{
53 return _characteristics;
54}

◆ getCoefficients() [1/2]

std::vector< Real > & MutableCoefficientsInterface::getCoefficients ( )

Get a writeable reference to the vector of coefficients.

Definition at line 63 of file MutableCoefficientsInterface.C.

64{
65 return _coefficients;
66}

◆ getCoefficients() [2/2]

const std::vector< Real > & MutableCoefficientsInterface::getCoefficients ( ) const

Get a read-only reference to the vector of coefficients.

Definition at line 57 of file MutableCoefficientsInterface.C.

58{
59 return _coefficients;
60}

◆ getCoefficientsTable()

std::string MutableCoefficientsInterface::getCoefficientsTable ( ) const

Get a formatted string of the coefficients.

Definition at line 69 of file MutableCoefficientsInterface.C.

70{
71 std::stringbuf string;
72 std::ostream table(&string);
73
74 table << *this;
75
76 return string.str();
77}

◆ getSize()

std::size_t MutableCoefficientsInterface::getSize ( ) const

Get the size, aka number of coefficients.

Definition at line 80 of file MutableCoefficientsInterface.C.

81{
82 return _coefficients.size();
83}

Referenced by isCompatibleWith().

◆ importCoefficients()

void MutableCoefficientsInterface::importCoefficients ( const MutableCoefficientsInterface other)

Import the coefficients from another instance.

Definition at line 117 of file MutableCoefficientsInterface.C.

118{
119 if (!isCompatibleWith(other))
120 mooseError("Cannot import coefficients from incompatible MutableCoefficientsInterface");
121
123
125 _console << *this;
126
128}
void mooseError(Args &&... args)
virtual void coefficientsChanged()
Called when the coefficients have been changed.
bool isCompatibleWith(const MutableCoefficientsInterface &other) const
Checks to see if another instance is compatible.

Referenced by MultiAppFXTransfer::execute().

◆ isCompatibleWith()

bool MutableCoefficientsInterface::isCompatibleWith ( const MutableCoefficientsInterface other) const

Checks to see if another instance is compatible.

Definition at line 86 of file MutableCoefficientsInterface.C.

87{
88 // Check the coefficient sizes if requested
89 if ((_enforce_size && other._enforce_size) && getSize() != other.getSize())
90 return false;
91
92 // Check the size of the characteristics array
93 if (_characteristics.size() != other._characteristics.size())
94 return false;
95
96 // Check the values of the characteristics array
97 for (std::size_t i = 0; i < _characteristics.size(); ++i)
98 if (_characteristics[i] != other._characteristics[i])
99 return false;
100
101 return true;
102}
std::size_t getSize() const
Get the size, aka number of coefficients.

Referenced by MultiAppFXTransfer::execute(), and importCoefficients().

◆ isSizeEnforced()

bool MutableCoefficientsInterface::isSizeEnforced ( ) const

Returns true if the size of the coefficient array is fixed and enforced.

Definition at line 105 of file MutableCoefficientsInterface.C.

106{
107 return _enforce_size;
108}

◆ operator[]()

Real MutableCoefficientsInterface::operator[] ( std::size_t  index) const

Get the value of the coefficient at the corresponding index.

Definition at line 45 of file MutableCoefficientsInterface.C.

46{
47 return _coefficients[index];
48}

◆ resize()

void MutableCoefficientsInterface::resize ( std::size_t  size,
Real  fill = 0.0,
bool  fill_out_to_size = true 
)

Resize the array, using the value for fill if the new size is larger.

Definition at line 131 of file MutableCoefficientsInterface.C.

132{
133 if (size != _coefficients.size())
134 {
135 if (_enforce_size &&
136 (size > _coefficients.size() || (size < _coefficients.size() && !fill_out_to_size)))
137 mooseError("Cannot resize coefficient array with size enforcement enabled.");
138
139 _coefficients.resize(size, fill);
140
142 _console << *this;
143
145 }
146}

Referenced by FunctionSeries::FunctionSeries(), and FXIntegralBaseUserObject< IntegralBaseVariableUserObject >::FXIntegralBaseUserObject().

◆ setCharacteristics()

void MutableCoefficientsInterface::setCharacteristics ( const std::vector< std::size_t > &  new_characteristics)

Sets the characteristics array.

Definition at line 149 of file MutableCoefficientsInterface.C.

151{
152 _characteristics = new_characteristics;
153}

Referenced by FunctionSeries::FunctionSeries().

◆ setCoefficients() [1/2]

void MutableCoefficientsInterface::setCoefficients ( const std::vector< Real > &  new_coefficients)

Set the coefficients using a copy operation.

Definition at line 156 of file MutableCoefficientsInterface.C.

157{
158 if (_enforce_size && new_coefficients.size() != _coefficients.size())
159 mooseError("Cannon assigned a coefficient array with differing size when size enforcement is "
160 "enabled.");
161
162 _coefficients = new_coefficients;
163
165 _console << *this;
166
168}

Referenced by MutableCoefficientsFunctionInterface::MutableCoefficientsFunctionInterface().

◆ setCoefficients() [2/2]

void MutableCoefficientsInterface::setCoefficients ( std::vector< Real > &&  dropin_coefficients)

Set the coefficients using a move operation (only works with temp objects)

Definition at line 171 of file MutableCoefficientsInterface.C.

172{
173 if (_enforce_size && dropin_coefficients.size() != _coefficients.size())
174 mooseError("Cannon assigned a coefficient array with differing size when size enforcement is "
175 "enabled.");
176
177 _coefficients = dropin_coefficients;
178
180 _console << *this;
181
183}

◆ validParams()

InputParameters MutableCoefficientsInterface::validParams ( )
static

Definition at line 18 of file MutableCoefficientsInterface.C.

19{
21
22 params.addClassDescription("This interface universalizes the communication standards for "
23 "array-based coefficient transfers.");
24
25 params.addParam<bool>("print_when_set", false, "Print the array of coefficients when set");
26
27 return params;
28}
InputParameters emptyInputParameters()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)

Referenced by MutableCoefficientsFunctionInterface::validParams(), and FXIntegralBaseUserObject< IntegralBaseVariableUserObject >::validParams().

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  stream,
const MutableCoefficientsInterface me 
)
friend

Friend operator to easily print out the array of coefficients.

Definition at line 185 of file MutableCoefficientsInterface.C.

187{
188 const MooseObject * myself_again = dynamic_cast<const MooseObject *>(&me);
189 stream << "\n\n"
190 << "MutableCoefficientsInterface: " << (myself_again ? myself_again->name() : "Unknown")
191 << "\n"
192 << " Number of Coefficients: " << me.getSize() << "\n";
193
194 for (std::size_t i = 0; i < me.getSize(); ++i)
195 stream << std::setw(4) << i << ": " << std::setw(12) << me[i] << ((i % 6 == 5) ? "\n" : " ");
196
197 stream << "\n\n" << std::flush;
198
199 return stream;
200}

Member Data Documentation

◆ _characteristics

std::vector<std::size_t>& MutableCoefficientsInterface::_characteristics
protected

An array of integer characteristics that can be used to check compatibility.

Definition at line 108 of file MutableCoefficientsInterface.h.

Referenced by FXIntegralBaseUserObject< IntegralBaseVariableUserObject >::FXIntegralBaseUserObject(), getCharacteristics(), isCompatibleWith(), and setCharacteristics().

◆ _coefficients

std::vector<Real>& MutableCoefficientsInterface::_coefficients
protected

◆ _console

const ConsoleStream& MutableCoefficientsInterface::_console
private

MooseObject instance of this to provide access to _console

Definition at line 121 of file MutableCoefficientsInterface.h.

Referenced by importCoefficients(), resize(), setCoefficients(), and setCoefficients().

◆ _enforce_size

bool MutableCoefficientsInterface::_enforce_size
protected

Boolean that locks or allows resizing of the coefficient array.

Definition at line 114 of file MutableCoefficientsInterface.h.

Referenced by enforceSize(), isCompatibleWith(), isSizeEnforced(), resize(), setCoefficients(), and setCoefficients().

◆ _print_coefficients

const bool MutableCoefficientsInterface::_print_coefficients
protected

Boolean to flag if the coefficients should be printed when set.

Definition at line 117 of file MutableCoefficientsInterface.h.

Referenced by importCoefficients(), resize(), setCoefficients(), and setCoefficients().


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