forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add element and nodal reporters (idaholab#24678)
- Loading branch information
1 parent
e5d86f6
commit a3fc889
Showing
20 changed files
with
795 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
framework/doc/content/source/reporters/CoupledVarStatsElementReporter.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,23 @@ | ||
# CoupledVarStatsElementReporter | ||
|
||
!syntax description /Reporters/CoupledVarStatsElementReporter | ||
|
||
## Overview | ||
|
||
CoupledVarStatsElementReporter produces the following statistics for a | ||
variable: Maximum, Minium, Average, Integral, Total Elements. The | ||
[!param](/Reporters/CoupledVarStatsElementReporter/base_name) can be used to prepend a | ||
name to each reporter. | ||
|
||
|
||
|
||
## Example Input File Syntax | ||
|
||
!listing ele_nodal_reporters/element_reporter/coupledvarstats.i block=elem_stats | ||
indent=2 header=[Reporters] footer=[] | ||
|
||
!syntax parameters /Reporters/CoupledVarStatsElementReporter | ||
|
||
!syntax inputs /Reporters/CoupledVarStatsElementReporter | ||
|
||
!syntax children /Reporters/CoupledVarStatsElementReporter |
23 changes: 23 additions & 0 deletions
23
framework/doc/content/source/reporters/CoupledVarStatsNodalReporter.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,23 @@ | ||
# CoupledVarStatsNodalReporter | ||
|
||
!syntax description /Reporters/CoupledVarStatsNodalReporter | ||
|
||
## Overview | ||
|
||
CoupledVarStatsNodalReporter produces the following statistics for a | ||
variable: Maximum, Minium, Average, Total Nodes. The | ||
[!param](/Reporters/CoupledVarStatsNodalReporter/base_name) can be used to prepend a | ||
name to each reporter. | ||
|
||
|
||
|
||
## Example Input File Syntax | ||
|
||
!listing ele_nodal_reporters/nodal_reporter/coupledvarstats.i block=elem_stats | ||
indent=2 header=[Reporters] footer=[] | ||
|
||
!syntax parameters /Reporters/CoupledVarStatsNodalReporter | ||
|
||
!syntax inputs /Reporters/CoupledVarStatsNodalReporter | ||
|
||
!syntax children /Reporters/CoupledVarStatsNodalReporter |
25 changes: 25 additions & 0 deletions
25
framework/include/reporters/CoupledVarStatsElementReporter.h
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,25 @@ | ||
//* 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 "ElementStatsReporter.h" | ||
|
||
class CoupledVarStatsElementReporter : public ElementStatsReporter | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
CoupledVarStatsElementReporter(const InputParameters & parameters); | ||
|
||
private: | ||
/// The coupled variable used. | ||
const VariableValue & _v; | ||
virtual Real computeValue(); | ||
}; |
25 changes: 25 additions & 0 deletions
25
framework/include/reporters/CoupledVarStatsNodalReporter.h
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,25 @@ | ||
//* 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 "NodalStatsReporter.h" | ||
|
||
class CoupledVarStatsNodalReporter : public NodalStatsReporter | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
CoupledVarStatsNodalReporter(const InputParameters & parameters); | ||
|
||
private: | ||
/// The coupled variable used. | ||
const VariableValue & _v; | ||
virtual Real computeValue(); | ||
}; |
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,43 @@ | ||
//* 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 | ||
|
||
// MOOSE includes | ||
#include "ElementUserObject.h" | ||
#include "Reporter.h" | ||
|
||
/** | ||
*/ | ||
class ElementReporter : public ElementUserObject, public Reporter | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
ElementReporter(const InputParameters & parameters); | ||
|
||
/** | ||
* @returns Whether or not this Reporter should store its value at this specific time. | ||
* | ||
* If the private parameter '_always_store' is true, this will always return true. | ||
* Otherwise, it will return true if the current execute flag matches a flag | ||
* that this ElementReporter has in its 'execute_on' parameter. Otherwise, it will | ||
* return false. | ||
* | ||
* This enables ElementReporter objects that do not fill information ahead of time in | ||
* execute() but instead fill their information in the to_json implementation. | ||
* Without this, said ElementReporters would always output their information even though | ||
* the user requested that they do not execute on a specific flag. | ||
*/ | ||
bool shouldStore() const override final; | ||
|
||
private: | ||
/// Whether or not this ElementReporter should always store its information; see shouldStore() | ||
const bool _always_store; | ||
}; |
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,36 @@ | ||
//* 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 "ElementReporter.h" | ||
|
||
class ElementStatsReporter : public ElementReporter | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
ElementStatsReporter(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual void initialize() override; | ||
virtual void execute() override; | ||
virtual void finalize() override; | ||
virtual void threadJoin(const UserObject & uo) override; | ||
|
||
virtual Real computeValue() = 0; | ||
|
||
private: | ||
const std::string _base_name; | ||
Real & _max; | ||
Real & _min; | ||
Real & _average; | ||
Real & _integral; | ||
int & _number_elements; | ||
}; |
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,43 @@ | ||
//* 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 | ||
|
||
// MOOSE includes | ||
#include "NodalUserObject.h" | ||
#include "Reporter.h" | ||
|
||
/** | ||
*/ | ||
class NodalReporter : public NodalUserObject, public Reporter | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
NodalReporter(const InputParameters & parameters); | ||
|
||
/** | ||
* @returns Whether or not this Reporter should store its value at this specific time. | ||
* | ||
* If the private parameter '_always_store' is true, this will always return true. | ||
* Otherwise, it will return true if the current execute flag matches a flag | ||
* that this NodalReporter has in its 'execute_on' parameter. Otherwise, it will | ||
* return false. | ||
* | ||
* This enables NodalReporter objects that do not fill information ahead of time in | ||
* execute() but instead fill their information in the to_json implementation. | ||
* Without this, said NodalReporters would always output their information even though | ||
* the user requested that they do not execute on a specific flag. | ||
*/ | ||
bool shouldStore() const override final; | ||
|
||
private: | ||
/// Whether or not this NodalReporter should always store its information; see shouldStore() | ||
const bool _always_store; | ||
}; |
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,35 @@ | ||
//* 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 "NodalReporter.h" | ||
|
||
class NodalStatsReporter : public NodalReporter | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
NodalStatsReporter(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual void initialize() override; | ||
virtual void execute() override; | ||
virtual void finalize() override; | ||
virtual void threadJoin(const UserObject & uo) override; | ||
|
||
virtual Real computeValue() = 0; | ||
|
||
private: | ||
const std::string _base_name; | ||
Real & _max; | ||
Real & _min; | ||
Real & _average; | ||
int & _number_nodes; | ||
}; |
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,40 @@ | ||
//* 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 "CoupledVarStatsElementReporter.h" | ||
|
||
registerMooseObject("MooseApp", CoupledVarStatsElementReporter); | ||
|
||
InputParameters | ||
CoupledVarStatsElementReporter::validParams() | ||
{ | ||
InputParameters params = ElementStatsReporter::validParams(); | ||
|
||
params.addRequiredCoupledVar("coupled_var", "Coupled variable whose value is used."); | ||
|
||
params.addClassDescription("Element reporter to get statistics for a coupled variable. This can " | ||
"be transfered to other apps."); | ||
return params; | ||
} | ||
|
||
CoupledVarStatsElementReporter::CoupledVarStatsElementReporter(const InputParameters & parameters) | ||
: ElementStatsReporter(parameters), _v(coupledValue("coupled_var")) | ||
{ | ||
} | ||
Real | ||
CoupledVarStatsElementReporter::computeValue() | ||
{ | ||
Real avg_val = 0; | ||
|
||
for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp) | ||
avg_val += _v[qp] * _JxW[qp] * _coord[qp]; | ||
avg_val /= _current_elem_volume; | ||
|
||
return avg_val; | ||
} |
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,34 @@ | ||
//* 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 "CoupledVarStatsNodalReporter.h" | ||
|
||
registerMooseObject("MooseApp", CoupledVarStatsNodalReporter); | ||
|
||
InputParameters | ||
CoupledVarStatsNodalReporter::validParams() | ||
{ | ||
InputParameters params = NodalStatsReporter::validParams(); | ||
|
||
params.addRequiredCoupledVar("coupled_var", "Coupled variable whose value is used."); | ||
|
||
params.addClassDescription("Nodal reporter to get statistics for a coupled variable. This can " | ||
"be transfered to other apps."); | ||
return params; | ||
} | ||
|
||
CoupledVarStatsNodalReporter::CoupledVarStatsNodalReporter(const InputParameters & parameters) | ||
: NodalStatsReporter(parameters), _v(coupledValue("coupled_var")) | ||
{ | ||
} | ||
Real | ||
CoupledVarStatsNodalReporter::computeValue() | ||
{ | ||
return _v[_qp]; | ||
} |
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,36 @@ | ||
//* 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 | ||
|
||
// MOOSE includes | ||
#include "ElementReporter.h" | ||
|
||
InputParameters | ||
ElementReporter::validParams() | ||
{ | ||
InputParameters params = ElementUserObject::validParams(); | ||
params += Reporter::validParams(); | ||
// Whether or not to always store this object's value | ||
// See the override for shouldStore() for more information | ||
params.addPrivateParam<bool>("_always_store", true); | ||
|
||
return params; | ||
} | ||
|
||
ElementReporter::ElementReporter(const InputParameters & parameters) | ||
: ElementUserObject(parameters), Reporter(this), _always_store(getParam<bool>("_always_store")) | ||
{ | ||
} | ||
|
||
bool | ||
ElementReporter::shouldStore() const | ||
{ | ||
// Either we always store, or we store if the current execution flag matches | ||
// a flag that is within this ElementReporter's 'execute_on' | ||
return _always_store || getExecuteOnEnum().contains(_fe_problem.getCurrentExecuteOnFlag()); | ||
} |
Oops, something went wrong.