Skip to content

Commit

Permalink
Setup transfer actions moved before EquationSystems reinit (refs #1913)
Browse files Browse the repository at this point in the history
Since transfers and multiapps rely on output file name set, another action is required to be triggered before those and set the output file name.

r23187
  • Loading branch information
andrsd authored and permcody committed Feb 14, 2014
1 parent 641bcbc commit b5bfb81
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 41 deletions.
40 changes: 40 additions & 0 deletions framework/include/actions/SetupOutputNameAction.h
@@ -0,0 +1,40 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef SETUPOUTPUTNAMEACTION_H_
#define SETUPOUTPUTNAMEACTION_H_

#include "Action.h"

class SetupOutputNameAction;

template<>
InputParameters validParams<SetupOutputNameAction>();

/**
*/
class SetupOutputNameAction : public Action
{
public:
SetupOutputNameAction(const std::string & name, InputParameters parameters);
virtual ~SetupOutputNameAction();

virtual void act();

protected:

};


#endif /* SETUPOUTPUTNAMEACTION_H_ */
34 changes: 0 additions & 34 deletions framework/src/actions/SetupOutputAction.C
Expand Up @@ -31,7 +31,6 @@ InputParameters validParams<SetupOutputAction>()
InputParameters params = validParams<Action>();
MooseEnum pps_fit_mode(FormattedTable::getWidthModes());

params.addParam<OutFileBase>("file_base", "The desired solution output name without an extension (Defaults to the mesh file name + '_out' or 'out' if generating the mesh by some other means)");
params.addParam<unsigned int>("interval", 1, "The interval at which timesteps are output to the solution file");
params.addParam<unsigned int>("screen_interval", 1, "The interval at which postprocessors are output to the screen. This value must evenly divide \"interval\" so that postprocessors are calculated at corresponding solution timesteps. In addition, if \"screen_interval\" is strictly greater than \"interval\", \"output_initial\" must be set to true");
params.addParam<bool>("exodus", false, "Specifies that you would like Exodus output solution file(s)");
Expand Down Expand Up @@ -97,26 +96,10 @@ SetupOutputAction::setupOutputObject(Output &output, InputParameters & params)
{
mooseAssert(params.have_parameter<std::vector<VariableName> >("output_variables"), "Output Variables are required");

OutFileBase base = params.get<OutFileBase>("file_base");

// Set the append parameter on the Output object (default false).
if (_app.isRecovering())
output.setAppend(true);

if(params.isParamValid("output_if_base_contains"))
{
const std::vector<std::string> & strings = params.get<std::vector<std::string> >("output_if_base_contains");

bool found_it = false;
for(unsigned int i=0; i<strings.size(); i++)
found_it = found_it || ( base.find(strings[i]) != std::string::npos);

if(!found_it) // Didn't find a match so no output should be done
return;
}

output.fileBase(base);

if (params.get<bool>("exodus"))
{
if (params.have_parameter<bool>("exodus_inputfile_output") && !params.get<bool>("exodus_inputfile_output"))
Expand Down Expand Up @@ -173,18 +156,10 @@ SetupOutputAction::act()
if(_pars.isParamValid("position"))
_app.setOutputPosition(_pars.get<Point>("position"));

// If the user didn't provide a filename - see if the parser has a filename that we can use as a base
if (!_pars.isParamValid("file_base"))
mooseError("\"file_base\" wasn't populated either by the input file or the parser.");

_problem->setOutputVariables();

Output & output = _problem->out(); // can't use use this with coupled problems on different meshes

// Has the filebase been overriden at the application level?
if(_app.getOutputFileBase() != "")
_pars.set<OutFileBase>("file_base") = _app.getOutputFileBase();

setupOutputObject(output, _pars);

const bool output_initial = getParam<bool>("output_initial");
Expand Down Expand Up @@ -264,14 +239,5 @@ SetupOutputAction::act()
}
}

// Test to make sure that the user can write to the directory specified in file_base
std::string base = "./" + getParam<OutFileBase>("file_base");
base = base.substr(0, base.find_last_of('/'));

// TODO: We have a function that tests read/write in the Parser namespace. We should probably
// use that instead of creating another one here
if (access(base.c_str(), W_OK) == -1)
mooseError("Can not write to directory: " + base + " for file base: " + getParam<OutFileBase>("file_base"));

_problem->getNonlinearSystem().printAllVariableNorms(getParam<bool>("all_var_norms"));
}
73 changes: 73 additions & 0 deletions framework/src/actions/SetupOutputNameAction.C
@@ -0,0 +1,73 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "SetupOutputNameAction.h"
#include "MooseApp.h"
#include "FEProblem.h"
#include "OutputProblem.h"
#include "unistd.h"

template<>
InputParameters validParams<SetupOutputNameAction>()
{
InputParameters params = validParams<Action>();
params.addParam<OutFileBase>("file_base", "out", "The desired solution output name without an extension (Defaults to the mesh file name + '_out' or 'out' if generating the mesh by some other means)");
return params;
}

SetupOutputNameAction::SetupOutputNameAction(const std::string & name, InputParameters parameters) :
Action(name, parameters)
{
}

SetupOutputNameAction::~SetupOutputNameAction()
{
}

void
SetupOutputNameAction::act()
{
OutFileBase file_base = _pars.get<OutFileBase>("file_base");

// Has the filebase been overridden at the application level?
if (_app.getOutputFileBase() != "")
file_base = _app.getOutputFileBase();

if (_problem != NULL)
{
Output & output = _problem->out(); // can't use use this with coupled problems on different meshes

if(_pars.isParamValid("output_if_base_contains"))
{
const std::vector<std::string> & strings = _pars.get<std::vector<std::string> >("output_if_base_contains");

bool found_it = false;
for(unsigned int i=0; i<strings.size(); i++)
found_it = found_it || (file_base.find(strings[i]) != std::string::npos);

if(!found_it) // Didn't find a match so no output should be done
return;
}

output.fileBase(file_base);

// Test to make sure that the user can write to the directory specified in file_base
std::string base = "./" + file_base;
base = base.substr(0, base.find_last_of('/'));
// TODO: We have a function that tests read/write in the Parser namespace. We should probably
// use that instead of creating another one here
if (access(base.c_str(), W_OK) == -1)
mooseError("Can not write to directory: " + base + " for file base: " + file_base);
}
}
11 changes: 6 additions & 5 deletions framework/src/actions/SetupOverSamplingAction.C
Expand Up @@ -47,11 +47,11 @@ InputParameters validParams<SetupOverSamplingAction>()

params.addParam<std::vector<VariableName> >("output_variables", "A list of the variables that should be in the Exodus output file. If this is not provided then all variables will be in the output.");

params.addParam<int>("interval", 1, "The iterval at which timesteps are output to the solution file");
params.addParam<int>("interval", 1, "The interval at which timesteps are output to the solution file");
params.addParam<Real>("iteration_plot_start_time", std::numeric_limits<Real>::max(), "Specifies a time after which the solution will be written following each nonlinear iteration");
params.addParam<bool>("output_initial", false, "Requests that the initial condition is output to the solution file");

params.addParam<Point>("position", "Set a positional offset. This vector will get added to the nodal cooardinates to move the domain.");
params.addParam<Point>("position", "Set a positional offset. This vector will get added to the nodal coordinates to move the domain.");
params.addParam<MeshFileName>("file", "The name of the mesh file to read");

return params;
Expand Down Expand Up @@ -81,7 +81,8 @@ SetupOverSamplingAction::act()
if(_pars.isParamValid("position"))
out_problem.setPosition(_pars.get<Point>("position"));

_pars.set<OutFileBase>("file_base") = _problem->out().fileBase() + "_oversample";
std::string file_base = _problem->out().fileBase() + "_oversample";
output.fileBase(file_base);

setupOutputObject(output, _pars);

Expand All @@ -96,8 +97,8 @@ SetupOverSamplingAction::act()
output.iterationPlotStartTime(getParam<Real>("iteration_plot_start_time"));

// Test to make sure that the user can write to the directory specified in file_base
std::string base = "./" + getParam<OutFileBase>("file_base");
std::string base = "./" + file_base;
base = base.substr(0, base.find_last_of('/'));
if (access(base.c_str(), W_OK) == -1)
mooseError("Can not write to directory: " + base + " for file base: " + getParam<OutFileBase>("file_base"));
mooseError("Can not write to directory: " + base + " for file base: " + file_base);
}
8 changes: 6 additions & 2 deletions framework/src/base/Moose.C
Expand Up @@ -278,6 +278,7 @@
#include "SetupMeshAction.h"
#include "AddMeshModifierAction.h"
#include "SetupMeshCompleteAction.h"
#include "SetupOutputNameAction.h"
#include "SetupOutputAction.h"
#include "AddMaterialAction.h"
#include "GlobalParamsAction.h"
Expand Down Expand Up @@ -581,6 +582,7 @@ addActionTypes(Syntax & syntax)
registerActionName("init_displaced_problem", false);
registerActionName("create_problem", true);
registerActionName("setup_output", false);
registerActionName("setup_output_name", true);
registerActionName("init_problem", true);
registerActionName("check_copy_nodal_vars", true);
registerActionName("copy_nodal_vars", true);
Expand Down Expand Up @@ -680,6 +682,9 @@ addActionTypes(Syntax & syntax)
"(setup_dampers)"
"(setup_residual_debug)"
"(add_bounds_vectors)"
"(setup_output_name)"
"(add_multi_app)"
"(add_transfer)"
"(init_problem)"
"(copy_nodal_vars, copy_nodal_aux_vars)"
"(initial_mesh_refinement)"
Expand All @@ -690,8 +695,6 @@ addActionTypes(Syntax & syntax)
"(setup_output)"
"(setup_oversampling)"
"(setup_debug)"
"(add_multi_app)"
"(add_transfer)"
"(check_integrity)"
);

Expand Down Expand Up @@ -740,6 +743,7 @@ registerActions(Syntax & syntax, ActionFactory & action_factory)
registerAction(InitDisplacedProblemAction, "init_displaced_problem");
registerAction(CreateProblemAction, "create_problem");
registerAction(SetupOutputAction, "setup_output");
registerAction(SetupOutputNameAction, "setup_output_name");
registerAction(GlobalParamsAction, "set_global_params");
registerAction(SetupPredictorAction, "setup_predictor");

Expand Down
1 change: 1 addition & 0 deletions framework/src/parser/MooseSyntax.C
Expand Up @@ -76,6 +76,7 @@ void associateSyntax(Syntax & syntax, ActionFactory & action_factory)

syntax.registerActionSyntax("RecoverBaseAction", "Output");
syntax.registerActionSyntax("SetupOutputAction", "Output");
syntax.registerActionSyntax("SetupOutputNameAction", "Output");
syntax.registerActionSyntax("SetupOverSamplingAction", "Output/OverSampling");

// Note: Preconditioner Actions will be built by this setup action
Expand Down

0 comments on commit b5bfb81

Please sign in to comment.