Line data Source code
1 : // MOOSE includes 2 : #include "FEProblemBase.h" 3 : #include "MultiApp.h" 4 : #include "PiecewiseBase.h" 5 : 6 : // MASTODON includes 7 : #include "PiecewiseFunctionTransfer.h" 8 : 9 : registerMooseObject("MastodonApp", PiecewiseFunctionTransfer); 10 : 11 : InputParameters 12 28 : PiecewiseFunctionTransfer::validParams() 13 : { 14 28 : InputParameters params = MultiAppTransfer::validParams(); 15 28 : params.addClassDescription("Transfers from one Piecewise function to another."); 16 : 17 56 : params.addRequiredParam<std::string>("to_function", 18 : "The name of the function being transferred into."); 19 : 20 56 : params.addRequiredParam<std::string>("from_function", 21 : "The name of the function being transferred out of."); 22 : 23 28 : return params; 24 0 : } 25 : 26 14 : PiecewiseFunctionTransfer::PiecewiseFunctionTransfer(const InputParameters & parameters) 27 14 : : MultiAppTransfer(parameters) 28 : { 29 14 : } 30 : 31 : void 32 92 : PiecewiseFunctionTransfer::execute() 33 : { 34 92 : const std::string & from_name = getParam<std::string>("from_function"); 35 92 : const std::string & to_name = getParam<std::string>("to_function"); 36 : 37 92 : if (_direction == TO_MULTIAPP) 38 : { 39 86 : FEProblemBase & from_problem = getToMultiApp()->problemBase(); 40 : PiecewiseBase & from_function = 41 86 : dynamic_cast<PiecewiseBase &>(from_problem.getFunction(from_name)); 42 504 : for (unsigned int i = 0; i < getToMultiApp()->numGlobalApps(); i++) 43 332 : if (getToMultiApp()->hasLocalApp(i)) 44 : { 45 166 : FEProblemBase & to_problem = getMultiApp()->appProblemBase(i); 46 : PiecewiseBase & to_function = 47 166 : dynamic_cast<PiecewiseBase &>(to_problem.getFunction(to_name)); 48 166 : transfer(from_function, to_function); 49 : } 50 : } 51 : 52 6 : else if (_direction == FROM_MULTIAPP) 53 : { 54 6 : FEProblemBase & to_problem = getFromMultiApp()->problemBase(); 55 6 : PiecewiseBase & to_function = dynamic_cast<PiecewiseBase &>(to_problem.getFunction(to_name)); 56 24 : for (unsigned int i = 0; i < getFromMultiApp()->numGlobalApps(); i++) 57 12 : if (getFromMultiApp()->hasLocalApp(i)) 58 : { 59 6 : FEProblemBase & from_problem = getMultiApp()->appProblemBase(i); 60 : PiecewiseBase & from_function = 61 6 : dynamic_cast<PiecewiseBase &>(from_problem.getFunction(from_name)); 62 6 : transfer(from_function, to_function); 63 : } 64 : } 65 92 : } 66 : 67 : void 68 172 : PiecewiseFunctionTransfer::transfer(PiecewiseBase & from_function, PiecewiseBase & to_function) 69 : { 70 172 : std::size_t n = from_function.functionSize(); 71 172 : std::vector<Real> x(n), y(n); 72 1636 : for (std::size_t i = 0; i < n; ++i) 73 : { 74 1464 : x[i] = from_function.domain(i); 75 1464 : y[i] = from_function.range(i); 76 : } 77 172 : to_function.setData(x, y); 78 172 : }