https://mooseframework.inl.gov
LoadModelDataAction.h
Go to the documentation of this file.
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"
16 
22 template <typename T>
24 {
25 public:
27 
28  LoadModelDataAction(const InputParameters & params) : Action(params) {}
29 
30  virtual void act() override;
31 
32 private:
37  void load(const T & object);
38 };
39 
40 template <typename T>
43 {
44  return Action::validParams();
45 }
46 
47 template <typename T>
48 void
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  static const auto attribute_name = T::validParams().getSystemAttributeName();
57 
58  _app.theWarehouse().query().template condition<AttribSystem>(attribute_name).queryInto(objects);
59  for (auto object_ptr : objects)
60  if (object_ptr->hasModelData())
61  load(*object_ptr);
62 }
63 
64 template <typename T>
65 void
67 {
68  // Create the object that will load in data
69  RestartableDataReader reader(
70  _app, _app.getRestartableDataMap(object.modelMetaDataName()), _app.forceRestart());
71  reader.setErrorOnLoadWithDifferentNumberOfProcessors(false);
72 
73  // Read the supplied file
74  const std::string filename = object.getModelDataFileName();
75  try
76  {
77  reader.setInput(filename);
78  reader.restore();
79  }
80  catch (...)
81  {
82  paramError("filename", "The supplied file '", filename, "' failed to load.");
83  }
84 }
virtual void act() override
LoadModelDataAction(const InputParameters &params)
static InputParameters validParams()
void load(const T &object)
Load the necessary information for the given model.
static InputParameters validParams()
InputParameters validParams()
Action for loading the model data for the mapping objects.
const std::string & getSystemAttributeName() const