-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reporter for nodal variable values at the elements located by nearestElemsToLine #109
Open
lynnmunday
wants to merge
3
commits into
idaholab:devel
Choose a base branch
from
lynnmunday:closestElemNodalVar
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,33 @@ | ||
//* 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 "ClosestElemsToLine.h" | ||
#include "MooseVariableInterface.h" | ||
|
||
class ClosestElemsToLineNodalVarValue : public ClosestElemsToLine, | ||
public MooseVariableInterface<Real> | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
ClosestElemsToLineNodalVarValue(const InputParameters & parameters); | ||
|
||
virtual void initialSetup() override; | ||
|
||
virtual void initialize() override{}; | ||
virtual void execute() override; | ||
virtual void finalize() override; | ||
|
||
private: | ||
std::string _var_name; | ||
MooseVariable & _var; | ||
std::vector<Real> & _value; | ||
}; |
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
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,77 @@ | ||
//* 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 "ClosestElemsToLineNodalVarValue.h" | ||
#include "MooseMesh.h" | ||
#include "MooseVariable.h" | ||
|
||
registerMooseObject("FalconApp", ClosestElemsToLineNodalVarValue); | ||
|
||
InputParameters | ||
ClosestElemsToLineNodalVarValue::validParams() | ||
{ | ||
InputParameters params = ClosestElemsToLine::validParams(); | ||
params.addClassDescription("Creates a real_vector_names reporter that has each " | ||
"elements average nodal variable value."); | ||
params.addRequiredParam<VariableName>("variable_to_sample", "The nodal variable to monitor."); | ||
return params; | ||
} | ||
|
||
ClosestElemsToLineNodalVarValue::ClosestElemsToLineNodalVarValue(const InputParameters & parameters) | ||
: ClosestElemsToLine(parameters), | ||
MooseVariableInterface<Real>(this, | ||
false, | ||
"variable_to_sample", | ||
Moose::VarKindType::VAR_ANY, | ||
Moose::VarFieldType::VAR_FIELD_STANDARD), | ||
_var_name(parameters.get<VariableName>("variable_to_sample")), | ||
_var(_subproblem.getStandardVariable(_tid, _var_name)), | ||
_value(declareValueByName<std::vector<Real>>(_var_name, REPORTER_MODE_REPLICATED)) | ||
{ | ||
if (!_var.isNodal()) | ||
mooseError("variable_to_sample must be a nodal variable."); | ||
} | ||
|
||
void | ||
ClosestElemsToLineNodalVarValue::initialSetup() | ||
{ | ||
ClosestElemsToLine::initialSetup(); | ||
_value.resize(_eid.size(), std::numeric_limits<Real>::max()); | ||
} | ||
|
||
void | ||
ClosestElemsToLineNodalVarValue::execute() | ||
{ | ||
const MooseMesh & mesh = _subproblem.mesh(); | ||
for (size_t i = 0; i < _eid.size(); ++i) | ||
{ | ||
Real value = 0.0; | ||
const Elem * elem = mesh.getMesh().query_elem_ptr(_eid[i]); | ||
if (elem->processor_id() == processor_id()) | ||
{ | ||
size_t n = 0; | ||
for (auto & node : elem->node_ref_range()) | ||
{ | ||
value += _var.getNodalValue(node); | ||
n++; | ||
} | ||
if (n > 0) | ||
value /= (Real)n; | ||
} | ||
_value[i] = value; | ||
} | ||
} | ||
|
||
void | ||
ClosestElemsToLineNodalVarValue::finalize() | ||
{ | ||
//_value should be zero on every proc so this will just communicate it. | ||
for (size_t i = 0; i < _eid.size(); ++i) | ||
gatherSum(_value[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dschwen is this a good way to get the value to all the processors? |
||
} |
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
72 changes: 72 additions & 0 deletions
72
test/tests/reporters/closest_elems_to_line_NodalVarValue/dfn_test.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,72 @@ | ||
[Mesh] | ||
[cluster34] | ||
type = FileMeshGenerator | ||
file = 'Cluster_34_zid.e' | ||
use_for_exodus_restart = true | ||
[] | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[AuxVariables] | ||
[z_id] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
initial_from_file_var = z_id | ||
initial_from_file_timestep = 'LATEST' | ||
[] | ||
[one] | ||
order = FIRST | ||
family = LAGRANGE | ||
initial_condition = 1 | ||
[] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[Reporters] | ||
[pt] | ||
type = ConstantReporter | ||
real_vector_names = 'pt1_x pt1_y pt1_z pt2_x pt2_y pt2_z' | ||
real_vector_values = '132.1; 97.5; 189.5; 136.5; 103.2; 50.6' | ||
outputs = none | ||
[] | ||
|
||
[no_var] | ||
block = "9 10" | ||
type = ClosestElemsToLineNodalVarValue | ||
projection_tolerance = 5 | ||
point_x1 = pt/pt1_x | ||
point_y1 = pt/pt1_y | ||
point_z1 = pt/pt1_z | ||
point_x2 = pt/pt2_x | ||
point_y2 = pt/pt2_y | ||
point_z2 = pt/pt2_z | ||
variable_to_sample = one | ||
outputs = out | ||
[] | ||
[domain_var] | ||
type = ClosestElemsToLineNodalVarValue | ||
projection_tolerance = 5 | ||
point_x1 = pt/pt1_x | ||
point_y1 = pt/pt1_y | ||
point_z1 = pt/pt1_z | ||
point_x2 = pt/pt2_x | ||
point_y2 = pt/pt2_y | ||
point_z2 = pt/pt2_z | ||
variable_filter = z_id | ||
variable_to_sample = one | ||
outputs = out | ||
[] | ||
[] | ||
|
||
[Outputs] | ||
[out] | ||
type = JSON | ||
execute_system_information_on = none | ||
[] | ||
[] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C style cast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Real(n)
orstatic_cast<Real>(n)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but neither is needed here, just do
value /= n;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dschwen would you look at this pr again. I didn't do averaging over gauss points because reporters don't have a base class that derives off the elem or nodal userobjects.