Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include <vector> 13 : 14 : #include "InputParameters.h" 15 : #include "MooseTypes.h" 16 : #include "Restartable.h" 17 : 18 : class ConsoleStream; 19 : 20 : /** 21 : * This class is designed to provide a uniform interface for any class that uses an array of 22 : * coefficients for any of its operations. In particular, the MultiAppFXTransfer mechanism transfers 23 : * coefficients using this interface. Any derived class of MutableCoefficientsInterface can easily 24 : * be used in any MultiAppFXTransfer-based transfer. 25 : */ 26 0 : class MutableCoefficientsInterface : public Restartable 27 : { 28 : public: 29 : static InputParameters validParams(); 30 : 31 : MutableCoefficientsInterface(const MooseObject * moose_object, 32 : const InputParameters & parameters); 33 : 34 : // Coefficient access 35 : /** 36 : * Get the value of the coefficient at the corresponding index 37 : */ 38 : Real operator[](std::size_t index) const; 39 : /** 40 : * Get a reference to the characteristics array 41 : */ 42 : const std::vector<std::size_t> & getCharacteristics() const; 43 : /** 44 : * Get a read-only reference to the vector of coefficients 45 : */ 46 : const std::vector<Real> & getCoefficients() const; 47 : /** 48 : * Get a writeable reference to the vector of coefficients 49 : */ 50 : std::vector<Real> & getCoefficients(); 51 : /** 52 : * Get a formatted string of the coefficients 53 : */ 54 : std::string getCoefficientsTable() const; 55 : 56 : // Current state 57 : /** 58 : * Get the size, aka number of coefficients 59 : */ 60 : std::size_t getSize() const; 61 : /** 62 : * Checks to see if another instance is compatible 63 : */ 64 : bool isCompatibleWith(const MutableCoefficientsInterface & other) const; 65 : /** 66 : * Returns true if the size of the coefficient array is fixed and enforced 67 : */ 68 : bool isSizeEnforced() const; 69 : /** 70 : * Toggle whether the size of the coefficient array can be changed 71 : */ 72 : void enforceSize(bool enforce); 73 : 74 : // Mutable aspect 75 : /** 76 : * Import the coefficients from another instance 77 : */ 78 : void importCoefficients(const MutableCoefficientsInterface & other); 79 : /** 80 : * Resize the array, using the value for fill if the new size is larger 81 : */ 82 : void resize(std::size_t size, Real fill = 0.0, bool fill_out_to_size = true); 83 : /** 84 : * Sets the characteristics array 85 : */ 86 : void setCharacteristics(const std::vector<std::size_t> & new_characteristics); 87 : /** 88 : * Set the coefficients using a copy operation 89 : */ 90 : void setCoefficients(const std::vector<Real> & new_coefficients); 91 : /** 92 : * Set the coefficients using a move operation (only works with temp objects) 93 : */ 94 : void setCoefficients(std::vector<Real> && dropin_coefficients); 95 : 96 : /** 97 : * Friend operator to easily print out the array of coefficients 98 : */ 99 : friend std::ostream & operator<<(std::ostream & stream, const MutableCoefficientsInterface & me); 100 : 101 : protected: 102 : /** 103 : * Called when the coefficients have been changed 104 : */ 105 0 : virtual void coefficientsChanged(){}; 106 : 107 : /// An array of integer characteristics that can be used to check compatibility 108 : std::vector<std::size_t> & _characteristics; 109 : 110 : /// The coefficient array 111 : std::vector<Real> & _coefficients; 112 : 113 : /// Boolean that locks or allows resizing of the coefficient array 114 : bool _enforce_size; 115 : 116 : /// Boolean to flag if the coefficients should be printed when set 117 : const bool _print_coefficients; 118 : 119 : private: 120 : /// MooseObject instance of `this` to provide access to `_console` 121 : const ConsoleStream & _console; 122 : };