https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 "MooseApp.h"
17
23template <typename T>
25{
26public:
28
29 LoadModelDataAction(const InputParameters & params) : Action(params) {}
30
31 virtual void act() override;
32
33private:
38 void load(const T & object);
39};
40
41template <typename T>
47
48template <typename T>
49void
51{
52 static_assert(std::is_base_of<RestartableModelInterface, T>::value,
53 "You must derive from RestartableModelInterface to use this action");
54
55 // We fetch the mapping objects and then load the necessary data
56 std::vector<T *> objects;
57 static const auto attribute_name = T::validParams().getSystemAttributeName();
58
59 _app.theWarehouse().query().template condition<AttribSystem>(attribute_name).queryInto(objects);
60 for (auto object_ptr : objects)
61 if (object_ptr->hasModelData())
62 load(*object_ptr);
63}
64
65template <typename T>
66void
68{
69 if (object.hasExplicitModelData())
70 {
71 // Create the object that will load in data
73 _app, _app.getRestartableDataMap(object.modelMetaDataName()), _app.forceRestart());
75
76 // Read the supplied file
77 const std::string filename = object.getModelDataFileName();
78 try
79 {
80 reader.setInput(filename);
81 reader.restore();
82 }
83 catch (...)
84 {
85 paramError("filename", "The supplied file '", filename, "' failed to load.");
86 }
87 }
88 else if (_app.isRecovering())
89 // Restore model data from the recover checkpoint into the already-declared map
90 _app.possiblyLoadRestartableMetaData(object.modelMetaDataName(),
91 _app.getRestartRecoverFileBase() +
92 MooseApp::checkpointSuffix());
93}
const double T
static InputParameters validParams()
Action for loading the model data for the mapping objects.
virtual void act() override
static InputParameters validParams()
LoadModelDataAction(const InputParameters &params)
void load(const T &object)
Load the necessary information for the given model.
void setErrorOnLoadWithDifferentNumberOfProcessors(bool value)
void restore(const DataNames &filter_names={})
void setInput(std::unique_ptr< std::stringstream > header_stream, std::unique_ptr< std::stringstream > data_stream)