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 "Action.h" 13 : #include "Attributes.h" 14 : #include "RestartableDataReader.h" 15 : #include "RestartableModelInterface.h" 16 : 17 : /** 18 : * Action for loading the model data for the mapping objects 19 : * @tparam The type of the object which needs to be loaded. This needs to be 20 : * a derived class of `RestartableModelInterface` at the moment. 21 : */ 22 : template <typename T> 23 : class LoadModelDataAction : public Action 24 : { 25 : public: 26 : static InputParameters validParams(); 27 : 28 78552 : LoadModelDataAction(const InputParameters & params) : Action(params) {} 29 : 30 : virtual void act() override; 31 : 32 : private: 33 : /** 34 : * Load the necessary information for the given model 35 : * @param object Reference to the object whose data shall be loaded 36 : */ 37 : void load(const T & object); 38 : }; 39 : 40 : template <typename T> 41 : InputParameters 42 : LoadModelDataAction<T>::validParams() 43 : { 44 78552 : return Action::validParams(); 45 : } 46 : 47 : template <typename T> 48 : void 49 78264 : LoadModelDataAction<T>::act() 50 : { 51 : static_assert(std::is_base_of<RestartableModelInterface, T>::value, 52 : "You must derive from RestartableModelInterface to use this action"); 53 : 54 : // We fetch the mapping objects and then load the necessary data 55 : std::vector<T *> objects; 56 78264 : static const auto attribute_name = T::validParams().getSystemAttributeName(); 57 : 58 156528 : _app.theWarehouse().query().template condition<AttribSystem>(attribute_name).queryInto(objects); 59 79872 : for (auto object_ptr : objects) 60 1608 : if (object_ptr->hasModelData()) 61 708 : load(*object_ptr); 62 78264 : } 63 : 64 : template <typename T> 65 : void 66 708 : LoadModelDataAction<T>::load(const T & object) 67 : { 68 : // Create the object that will load in data 69 708 : RestartableDataReader reader( 70 708 : _app, _app.getRestartableDataMap(object.modelMetaDataName()), _app.forceRestart()); 71 : reader.setErrorOnLoadWithDifferentNumberOfProcessors(false); 72 : 73 : // Read the supplied file 74 708 : const std::string filename = object.getModelDataFileName(); 75 : try 76 : { 77 708 : reader.setInput(filename); 78 1416 : reader.restore(); 79 : } 80 0 : catch (...) 81 : { 82 0 : paramError("filename", "The supplied file '", filename, "' failed to load."); 83 : } 84 708 : }