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.
- Loading branch information
Andrea Rovinelli
committed
Feb 3, 2020
1 parent
9f37c00
commit 9271802
Showing
3 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
test/include/userobjects/InterfaceUserObjectGetMaterialValue.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,44 @@ | ||
//* 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 "InterfaceValueUserObject.h" | ||
|
||
class InterfaceUserObjectGetMaterialValue; | ||
|
||
template <> | ||
InputParameters validParams<InterfaceUserObjectGetMaterialValue>(); | ||
|
||
/** | ||
* This userobject collect values of a variable across an interface for each QP and compute a | ||
* scalar. The computed scalar value depends on the given parameter _interface_value_type\ | ||
* _interface_value_type (see IntervafeValueTools). | ||
*/ | ||
class InterfaceUserObjectGetMaterialValue : public InterfaceValueUserObject | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
InterfaceUserObjectGetMaterialValue(const InputParameters & parameters); | ||
virtual ~InterfaceUserObjectGetMaterialValue(); | ||
|
||
virtual void initialize(); | ||
virtual void execute(); | ||
virtual void finalize() { return; }; | ||
virtual void threadJoin(const UserObject & /*uo*/) { return; }; | ||
|
||
Real getQpValue(dof_id_type elem, unsigned int side, unsigned int qp) const; | ||
|
||
protected: | ||
/// this map is used to store QP data. | ||
std::map<std::pair<dof_id_type, unsigned int>, std::vector<Real>> _map_values; | ||
const MaterialProperty<Real> & _mp; | ||
const MaterialProperty<Real> & _mp_neighbor; | ||
}; |
105 changes: 105 additions & 0 deletions
105
test/src/userobjects/InterfaceUserObjectGetMaterialValue.C
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,105 @@ | ||
//* 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 "InterfaceUserObjectGetMaterialValue.h" | ||
#include "MooseMesh.h" | ||
registerMooseObject("MooseApp", InterfaceUserObjectGetMaterialValue); | ||
|
||
defineLegacyParams(InterfaceUserObjectGetMaterialValue); | ||
|
||
InputParameters | ||
InterfaceUserObjectGetMaterialValue::validParams() | ||
{ | ||
InputParameters params = InterfaceValueUserObject::validParams(); | ||
params.addRequiredParam<MaterialPropertyName>("property", "The property name"); | ||
params.addCoupledVar("property_neighbor", "The neighbor property name"); | ||
params.addClassDescription("Test Interfae User Object computing and storing average values at " | ||
"each QP across an interface"); | ||
return params; | ||
} | ||
|
||
InterfaceUserObjectGetMaterialValue::InterfaceUserObjectGetMaterialValue( | ||
const InputParameters & parameters) | ||
: InterfaceValueUserObject(parameters), | ||
_mp(getMaterialProperty<Real>("property")), | ||
_mp_neighbor(parameters.isParamSetByUser("property") | ||
? getNeighborMaterialProperty<Real>("property") | ||
: getNeighborMaterialProperty<Real>("property_neighbor")) | ||
|
||
{ | ||
} | ||
|
||
InterfaceUserObjectGetMaterialValue::~InterfaceUserObjectGetMaterialValue() {} | ||
|
||
void | ||
InterfaceUserObjectGetMaterialValue::initialize() | ||
{ | ||
// define the boundary map and retrieve element side and boundary_ID | ||
std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> elem_side_bid = | ||
_mesh.buildSideList(); | ||
|
||
// retrieve on which boundary this UO operates | ||
std::set<BoundaryID> boundaryList = boundaryIDs(); | ||
|
||
// clear map values | ||
_map_values.clear(); | ||
|
||
// initialize the map_values looping over all the element and sides | ||
for (unsigned int i = 0; i < elem_side_bid.size(); i++) | ||
{ | ||
// check if this element side is part of the boundary, if so add element side to the interface | ||
// map | ||
if (boundaryList.find(std::get<2>(elem_side_bid[i])) != boundaryList.end()) | ||
{ | ||
// make pair | ||
std::pair<dof_id_type, unsigned int> elem_side_pair = | ||
std::make_pair(std::get<0>(elem_side_bid[i]), std::get<1>(elem_side_bid[i])); | ||
// initialize map elemenet | ||
std::vector<Real> var_values(0, 0); | ||
|
||
// add entry to the value map | ||
_map_values[elem_side_pair] = var_values; | ||
} | ||
} | ||
} | ||
|
||
void | ||
InterfaceUserObjectGetMaterialValue::execute() | ||
{ | ||
// find the entry on the map | ||
auto it = _map_values.find(std::make_pair(_current_elem->id(), _current_side)); | ||
if (it != _map_values.end()) | ||
{ | ||
// insert two vector value for each qp | ||
auto & vec = _map_values[std::make_pair(_current_elem->id(), _current_side)]; | ||
vec.resize(_qrule->n_points()); | ||
|
||
// loop over qps and do stuff | ||
for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp) | ||
{ | ||
// compute average value at qp | ||
Moose::out << "_mp[qp] " << _mp[qp] << " _mp_neighbor[qp] " << _mp_neighbor[qp] << std::endl; | ||
vec[qp] = computeInterfaceValueType(_mp[qp], _mp_neighbor[qp]); | ||
} | ||
} | ||
else | ||
mooseError("InterfaceUserObjectGetMaterialValue:: cannot find the required element and side"); | ||
} | ||
|
||
Real | ||
InterfaceUserObjectGetMaterialValue::getQpValue(dof_id_type elem, | ||
unsigned int side, | ||
unsigned int qp) const | ||
{ | ||
auto data = _map_values.find(std::make_pair(elem, side)); | ||
if (data != _map_values.end()) | ||
return data->second[qp]; | ||
else | ||
mooseError("getMeanMatProp: can't find the given qp"); | ||
} |
186 changes: 186 additions & 0 deletions
186
test/tests/userobjects/interface_user_object/interface_material_value_user_object_QP.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,186 @@ | ||
[Mesh] | ||
[gen] | ||
type = GeneratedMeshGenerator | ||
dim = 2 | ||
nx = 2 | ||
xmax = 2 | ||
ny = 2 | ||
ymax = 2 | ||
elem_type = QUAD4 | ||
[] | ||
[./subdomain_id] | ||
input = gen | ||
type = SubdomainBoundingBoxGenerator | ||
bottom_left = '0 0 0' | ||
top_right = '1 1 0' | ||
block_id = 1 | ||
[../] | ||
|
||
[./interface] | ||
type = SideSetsBetweenSubdomainsGenerator | ||
input = subdomain_id | ||
master_block = '0' | ||
paired_block = '1' | ||
new_boundary = 'interface' | ||
[../] | ||
|
||
[] | ||
|
||
[Functions] | ||
[./fn_exact] | ||
type = ParsedFunction | ||
value = 'x*x+y*y' | ||
[../] | ||
|
||
[./ffn] | ||
type = ParsedFunction | ||
value = -4 | ||
[../] | ||
[] | ||
|
||
[UserObjects] | ||
[./interface_value_uo] | ||
type = InterfaceUserObjectGetMaterialValue | ||
property = diffusivity | ||
boundary = 'interface' | ||
execute_on = 'initial timestep_end' | ||
interface_value_type = average | ||
[../] | ||
[] | ||
|
||
[Variables] | ||
[./u] | ||
family = LAGRANGE | ||
order = FIRST | ||
[../] | ||
[] | ||
|
||
|
||
[Kernels] | ||
[./diff] | ||
type = Diffusion | ||
variable = u | ||
[../] | ||
|
||
[./ffn] | ||
type = BodyForce | ||
variable = u | ||
function = ffn | ||
[../] | ||
[] | ||
|
||
[BCs] | ||
[./all] | ||
type = FunctionDirichletBC | ||
variable = u | ||
boundary = '0 1 2 3' | ||
function = fn_exact | ||
[../] | ||
[] | ||
|
||
[Materials] | ||
[./stateful1] | ||
type = StatefulMaterial | ||
block = 0 | ||
initial_diffusivity = 5 | ||
# outputs = all | ||
[../] | ||
[./stateful2] | ||
type = StatefulMaterial | ||
block = 1 | ||
initial_diffusivity = 2 | ||
# outputs = all | ||
[../] | ||
[] | ||
|
||
[AuxKernels] | ||
[./diffusivity_1] | ||
type = MaterialRealAux | ||
property = diffusivity | ||
variable = diffusivity_1 | ||
[] | ||
[./diffusivity_2] | ||
type = MaterialRealAux | ||
property = diffusivity | ||
variable = diffusivity_2 | ||
[] | ||
[] | ||
|
||
[AuxVariables] | ||
[./diffusivity_1] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[./diffusivity_2] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[./avg_qp] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[./master_minus_slave_qp] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[./slave_minus_master_qp] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[./abs_jump_qp] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[./master_qp] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[./slave_qp] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[] | ||
|
||
|
||
|
||
[Postprocessors] | ||
[./interface_average_PP] | ||
type = SideAverageValue | ||
boundary = interface | ||
variable = avg_qp | ||
[../] | ||
[./master_minus_slave_qp_PP] | ||
type = SideAverageValue | ||
boundary = interface | ||
variable = master_minus_slave_qp | ||
[../] | ||
[./slave_minus_master_qp_PP] | ||
type = SideAverageValue | ||
boundary = interface | ||
variable = slave_minus_master_qp | ||
[../] | ||
[./abs_jump_qp_PP] | ||
type = SideAverageValue | ||
boundary = interface | ||
variable = abs_jump_qp | ||
[../] | ||
[./master_qp_PP] | ||
type = SideAverageValue | ||
boundary = interface | ||
variable = master_qp | ||
[../] | ||
[./slave_qp_PP] | ||
type = SideAverageValue | ||
boundary = interface | ||
variable = slave_qp | ||
[../] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
solve_type = NEWTON | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
[] |