forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MessageFromInput UserObject, test and doco
closes idaholab#21736
- Loading branch information
1 parent
fa6b53a
commit 0cdab3d
Showing
6 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
framework/doc/content/source/userobjects/MessageFromInput.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# MessageFromInput | ||
|
||
!syntax description /UserObjects/MessageFromInput | ||
|
||
## Description | ||
|
||
This user object provides an option to print a message to the screen during the simulation. The message can be written in the input file. The user can customize *when* the message should print, the default option is to print it at the initialization of the simulation, with `execute_on = INITIAL`. | ||
|
||
## Example Input Syntax | ||
|
||
!listing test/tests/userobjects/message_from_input/message_from_input.i block=UserObjects | ||
|
||
!syntax parameters /UserObjects/MessageFromInput | ||
|
||
!syntax inputs /UserObjects/MessageFromInput | ||
|
||
!syntax children /UserObjects/MessageFromInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
#include "GeneralUserObject.h" | ||
|
||
/** | ||
* User object that get a message from an input file and | ||
* print it out during the simulation | ||
*/ | ||
class MessageFromInput : public GeneralUserObject | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
MessageFromInput(const InputParameters & parameters); | ||
virtual ~MessageFromInput(); | ||
|
||
// Required pure virtual function(not used) | ||
virtual void initialize() override {}; | ||
|
||
// Required pure virtual function(not used) | ||
virtual void finalize() override {}; | ||
|
||
// Print out the message with specified color | ||
virtual void execute() override; | ||
|
||
private: | ||
// hold the message from the input file | ||
const std::string _input_message; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "MessageFromInput.h" | ||
#include "Console.h" | ||
#include "ConsoleUtils.h" | ||
|
||
registerMooseObject("MooseApp", MessageFromInput); | ||
|
||
InputParameters | ||
MessageFromInput::validParams() | ||
{ | ||
// Get the input parameters from the parent class | ||
InputParameters params = GeneralUserObject::validParams(); | ||
|
||
// Add parameters | ||
params.addRequiredParam<std::string>("message", "The message to print out"); | ||
|
||
// we run this object once at the initialization by default | ||
params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; | ||
|
||
params.addClassDescription("Print out a message from the input file"); | ||
|
||
return params; | ||
} | ||
|
||
MessageFromInput::MessageFromInput(const InputParameters & parameters) | ||
: GeneralUserObject(parameters), _input_message(getParam<std::string>("message")) | ||
{ | ||
} | ||
|
||
MessageFromInput::~MessageFromInput() {} | ||
|
||
void | ||
MessageFromInput::execute() | ||
{ | ||
// Only print out once | ||
if (processor_id() == 0) | ||
{ | ||
auto total_width = std::setw(ConsoleUtils::console_field_width); | ||
_console << total_width << "\n"; | ||
_console << "Message: " << std::endl | ||
<< ConsoleUtils::indent(2) << COLOR_YELLOW << _input_message << "\n"; | ||
_console << COLOR_DEFAULT << total_width << "\n" << std::endl; | ||
_console << std ::flush; | ||
} | ||
} |
Submodule thermochimica
deleted from
cabaad
59 changes: 59 additions & 0 deletions
59
test/tests/userobjects/message_from_input/message_from_input.i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 2 | ||
nx = 2 | ||
ny = 2 | ||
xmax = 1 | ||
ymax = 1 | ||
[] | ||
|
||
[Variables] | ||
[u] | ||
[] | ||
[] | ||
|
||
|
||
[BCs] | ||
[left] | ||
type = DirichletBC | ||
variable = u | ||
boundary = left | ||
value = 1 | ||
[] | ||
[right] | ||
type = DirichletBC | ||
variable = u | ||
boundary = right | ||
value = 0 | ||
[] | ||
[] | ||
|
||
[Kernels] | ||
[diff] | ||
type = Diffusion | ||
variable = u | ||
[] | ||
[] | ||
|
||
[Problem] | ||
type = FEProblem | ||
[] | ||
|
||
[UserObjects] | ||
[message_out] | ||
type = MessageFromInput | ||
execute_on = timestep_end | ||
[] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
solve_type = 'NEWTON' | ||
petsc_options_iname = '-pc_type -pc_factor_mat_solver_type' | ||
petsc_options_value = 'lu superlu_dist' | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
[] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[Tests] | ||
[test] | ||
requirement = 'The system shall print out a message to screen from the input file' | ||
design = 'MessageFromInput.md' | ||
issues = '#21736' | ||
|
||
[message_from_input] | ||
type = 'RunApp' | ||
input = 'message_from_input.i' | ||
cli_args = "UserObjects/message_out/message='Test Message'" | ||
expect_out = 'Test Message' | ||
|
||
detail = "print out the user-defined message" | ||
[] | ||
[] | ||
[] |