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 all commits
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
30 changes: 30 additions & 0 deletions include/reporters/ClosestElemsToLineVarValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//* 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"

class ClosestElemsToLineVarValue : public ClosestElemsToLine
{
public:
static InputParameters validParams();

ClosestElemsToLineVarValue(const InputParameters & parameters);

virtual void initialSetup() override;

virtual void initialize() override{};
virtual void execute() override{};
virtual void finalize() override;

private:
std::string _var_name;
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
72 changes: 72 additions & 0 deletions src/reporters/ClosestElemsToLineVarValue.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//* 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 "ClosestElemsToLineVarValue.h"

// MOOSE includes
#include "MooseMesh.h"
#include "MooseVariable.h"
#include "SubProblem.h"

registerMooseObject("FalconApp", ClosestElemsToLineVarValue);

InputParameters
ClosestElemsToLineVarValue::validParams()
{
InputParameters params = ClosestElemsToLine::validParams();
params.addClassDescription("Creates a real_vector_names reporter that has each "
"elements average variable value.");
params.addRequiredParam<VariableName>("variable_to_sample", "The variable to sample.");
return params;
}

ClosestElemsToLineVarValue::ClosestElemsToLineVarValue(const InputParameters & parameters)
: ClosestElemsToLine(parameters),
_var_name(parameters.get<VariableName>("variable_to_sample")),
_value(declareValueByName<std::vector<Real>>(_var_name, REPORTER_MODE_REPLICATED))
{
}

void
ClosestElemsToLineVarValue::initialSetup()
{
ClosestElemsToLine::initialSetup();
_value.resize(_eid.size(), std::numeric_limits<Real>::max());
}

void
ClosestElemsToLineVarValue::finalize()
{
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())
{
// The element average is computed this way because the reporter system
// does not have a base class that derives off the nodal or element userobject
_fe_problem.setCurrentSubdomainID(elem, 0);
_subproblem.prepare(elem, _tid);
_subproblem.reinitElem(elem, _tid);

MooseVariableField<Real> & var = static_cast<MooseVariableField<Real> &>(
_subproblem.getActualFieldVariable(_tid, _var_name));
const VariableValue & u = var.sln();
unsigned int n = u.size();
for (unsigned int i = 0; i < n; i++)
value += u[i];
value /= n;
}
_value[i] = value;
}
//_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]);
}
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
Binary file not shown.
72 changes: 72 additions & 0 deletions test/tests/reporters/closest_elems_to_line_VarValue/dfn_test.i
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 = ClosestElemsToLineVarValue
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 = ClosestElemsToLineVarValue
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