Skip to content
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
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions include/reporters/ClosestElemsToLineNodalVarValue.h
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;
};
7 changes: 4 additions & 3 deletions src/reporters/ClosestElemsToLine.C
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ ClosestElemsToLine::validParams()
params.addRequiredParam<ReporterName>("point_z2",
"input reporter of z-coordinate name for point. This uses "
"the reporter syntax <reporter>/<name>.");
params.addParam<VariableName>("variable",
"Name for the variable in domain to determine uniqueness");
params.addParam<VariableName>("variable_filter",
"Variable name to filter elements by. Only one element can be "
"found for each integer value of this variable.");
params.addParam<Real>("projection_tolerance",
libMesh::TOLERANCE,
"Search tolerance between line and the closest node. If a node is not "
Expand All @@ -59,7 +60,7 @@ ClosestElemsToLine::ClosestElemsToLine(const InputParameters & parameters)
_pt_x(declareValueByName<std::vector<Real>>("point_x", REPORTER_MODE_REPLICATED)),
_pt_y(declareValueByName<std::vector<Real>>("point_y", REPORTER_MODE_REPLICATED)),
_pt_z(declareValueByName<std::vector<Real>>("point_z", REPORTER_MODE_REPLICATED)),
_var(isParamValid("variable") ? getParam<VariableName>("variable") : "")
_var(isParamValid("variable_filter") ? getParam<VariableName>("variable_filter") : "")
{
}

Expand Down
77 changes: 77 additions & 0 deletions src/reporters/ClosestElemsToLineNodalVarValue.C
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C style cast

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real(n) or static_cast<Real>(n)

Copy link
Member

@dschwen dschwen Aug 24, 2022

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;

Copy link
Collaborator Author

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.

}
_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]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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?

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
point_x2 = pt/pt2_x
point_y2 = pt/pt2_y
point_z2 = pt/pt2_z
variable = oneID
variable_filter = oneID
outputs = out
[]
[differentID_out]
Expand All @@ -119,7 +119,7 @@
point_x2 = pt/pt2_x
point_y2 = pt/pt2_y
point_z2 = pt/pt2_z
variable = differentID
variable_filter = differentID
outputs = out
[]
[noID_out]
Expand Down
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
[]
[]
Loading