Skip to content

Commit

Permalink
Merge pull request #24707 from maxnezdyur/Ele_Nodal_Reporters_24678
Browse files Browse the repository at this point in the history
Create Element and Nodal Reporters
  • Loading branch information
zachmprince authored Jun 28, 2023
2 parents b7bebfa + 936b7e6 commit a6da4af
Show file tree
Hide file tree
Showing 22 changed files with 801 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ElementVariableStatistics

!syntax description /Reporters/ElementVariableStatistics

## Overview

ElementVariableStatistics produces the following statistics for a
variable: Maximum, Minium, Average, Integral, Total Elements. The
[!param](/Reporters/ElementVariableStatistics/base_name) can be used to prepend a
name to each reporter.



## Example Input File Syntax

!listing element_reporter/elem_stats.i block=elem_stats
indent=2 header=[Reporters] footer=[]

!syntax parameters /Reporters/ElementVariableStatistics

!syntax inputs /Reporters/ElementVariableStatistics

!syntax children /Reporters/ElementVariableStatistics
23 changes: 23 additions & 0 deletions framework/doc/content/source/reporters/NodalVariableStatistics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# NodalVariableStatistics

!syntax description /Reporters/NodalVariableStatistics

## Overview

NodalVariableStatistics produces the following statistics for a
variable: Maximum, Minium, Average, Total Nodes. The
[!param](/Reporters/NodalVariableStatistics/base_name) can be used to prepend a
name to each reporter.



## Example Input File Syntax

!listing nodal_reporter/nodal_stats.i block=nodal_stats
indent=2 header=[Reporters] footer=[]

!syntax parameters /Reporters/NodalVariableStatistics

!syntax inputs /Reporters/NodalVariableStatistics

!syntax children /Reporters/NodalVariableStatistics
43 changes: 43 additions & 0 deletions framework/include/reporters/ElementReporter.h
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;
};
36 changes: 36 additions & 0 deletions framework/include/reporters/ElementStatistics.h
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 ElementStatistics : public ElementReporter
{
public:
static InputParameters validParams();

ElementStatistics(const InputParameters & parameters);

protected:
virtual void initialize() override;
virtual void execute() override;
virtual void threadJoin(const UserObject &) override;
virtual void finalize() override;

virtual Real computeValue() = 0;

private:
const std::string _base_name;
Real & _max;
Real & _min;
Real & _average;
Real & _integral;
int & _number_elements;
};
26 changes: 26 additions & 0 deletions framework/include/reporters/ElementVariableStatistics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//* 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 "ElementStatistics.h"

class ElementVariableStatistics : public ElementStatistics
{
public:
static InputParameters validParams();

ElementVariableStatistics(const InputParameters & parameters);

private:
virtual Real computeValue() override;

/// The coupled variable used.
const VariableValue & _v;
};
43 changes: 43 additions & 0 deletions framework/include/reporters/NodalReporter.h
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;
};
34 changes: 34 additions & 0 deletions framework/include/reporters/NodalStatistics.h
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

#pragma once

#include "NodalReporter.h"

class NodalStatistics : public NodalReporter
{
public:
static InputParameters validParams();

NodalStatistics(const InputParameters & parameters);

protected:
virtual void initialize() override;
virtual void execute() override;
virtual void finalize() override;
virtual void threadJoin(const UserObject &) override;
virtual Real computeValue() = 0;

private:
const std::string _base_name;
Real & _max;
Real & _min;
Real & _average;
int & _number_nodes;
};
26 changes: 26 additions & 0 deletions framework/include/reporters/NodalVariableStatistics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//* 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 "NodalStatistics.h"

class NodalVariableStatistics : public NodalStatistics
{
public:
static InputParameters validParams();

NodalVariableStatistics(const InputParameters & parameters);

private:
virtual Real computeValue() override;

/// The coupled variable used.
const VariableValue & _v;
};
8 changes: 8 additions & 0 deletions framework/include/reporters/Reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma once

// Moose includes
#include "MooseTypes.h"
#include "OutputInterface.h"
#include "ReporterData.h"
#include "InputParameters.h"
Expand Down Expand Up @@ -243,6 +244,13 @@ Reporter::declareValueByName(const ReporterValueName & value_name,

buildOutputHideVariableList({state_name.getCombinedName()});

// Only thread 0 will declare the reporter value. The rest will get a reference
// to an UnusedValue
const THREAD_ID tid = _reporter_moose_object.parameters().isParamValid("_tid")
? _reporter_moose_object.parameters().get<THREAD_ID>("_tid")
: 0;
if (tid)
return declareUnusedValue<T>();
return _reporter_data.declareReporterValue<T, S>(
state_name, mode, _reporter_moose_object, args...);
}
Expand Down
4 changes: 2 additions & 2 deletions framework/src/outputs/JSONOutput.C
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ JSONOutput::outputReporters()
.attributes();
auto qid = _problem_ptr->theWarehouse().queryID(attr);
_problem_ptr->theWarehouse().queryInto(qid, objs, true);
mooseAssert(objs.size() <= 1,
"Multiple Reporter objects with the same name located, how did you do that?");

// There can now be multiple reporter objects with the same name, but
// there will only be one reporter that stores all the data.
if (!objs.empty())
{
auto & reporter = *objs.front();
Expand Down
36 changes: 36 additions & 0 deletions framework/src/reporters/ElementReporter.C
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());
}
Loading

0 comments on commit a6da4af

Please sign in to comment.