From 927180231b599e5fa171ea045bdc000d82c11d28 Mon Sep 17 00:00:00 2001 From: Andrea Rovinelli Date: Mon, 3 Feb 2020 11:43:04 -0600 Subject: [PATCH] ref #14680 --- .../InterfaceUserObjectGetMaterialValue.h | 44 +++++ .../InterfaceUserObjectGetMaterialValue.C | 105 ++++++++++ .../interface_material_value_user_object_QP.i | 186 ++++++++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 test/include/userobjects/InterfaceUserObjectGetMaterialValue.h create mode 100644 test/src/userobjects/InterfaceUserObjectGetMaterialValue.C create mode 100644 test/tests/userobjects/interface_user_object/interface_material_value_user_object_QP.i diff --git a/test/include/userobjects/InterfaceUserObjectGetMaterialValue.h b/test/include/userobjects/InterfaceUserObjectGetMaterialValue.h new file mode 100644 index 000000000000..cfdb5e5bf0a8 --- /dev/null +++ b/test/include/userobjects/InterfaceUserObjectGetMaterialValue.h @@ -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(); + +/** + * 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::vector> _map_values; + const MaterialProperty & _mp; + const MaterialProperty & _mp_neighbor; +}; diff --git a/test/src/userobjects/InterfaceUserObjectGetMaterialValue.C b/test/src/userobjects/InterfaceUserObjectGetMaterialValue.C new file mode 100644 index 000000000000..de69bf20b506 --- /dev/null +++ b/test/src/userobjects/InterfaceUserObjectGetMaterialValue.C @@ -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("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("property")), + _mp_neighbor(parameters.isParamSetByUser("property") + ? getNeighborMaterialProperty("property") + : getNeighborMaterialProperty("property_neighbor")) + +{ +} + +InterfaceUserObjectGetMaterialValue::~InterfaceUserObjectGetMaterialValue() {} + +void +InterfaceUserObjectGetMaterialValue::initialize() +{ + // define the boundary map and retrieve element side and boundary_ID + std::vector> elem_side_bid = + _mesh.buildSideList(); + + // retrieve on which boundary this UO operates + std::set 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 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 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"); +} diff --git a/test/tests/userobjects/interface_user_object/interface_material_value_user_object_QP.i b/test/tests/userobjects/interface_user_object/interface_material_value_user_object_QP.i new file mode 100644 index 000000000000..13f2e3a81f81 --- /dev/null +++ b/test/tests/userobjects/interface_user_object/interface_material_value_user_object_QP.i @@ -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 +[]