Line data Source code
1 : #include "ClusteringUserObjectBase.h" 2 : #include "AuxiliarySystem.h" 3 : #include "libmesh/dof_map.h" 4 : #include "libmesh/mesh_base.h" 5 : #include "libmesh/elem.h" 6 : 7 : InputParameters 8 54 : ClusteringUserObjectBase::validParams() 9 : { 10 54 : InputParameters params = GeneralUserObject::validParams(); 11 108 : params.addRequiredParam<AuxVariableName>( 12 : "metric_variable_name", "The name of the variable based on which clustering will be done"); 13 : 14 54 : return params; 15 0 : } 16 : 17 30 : ClusteringUserObjectBase::ClusteringUserObjectBase(const InputParameters & parameters) 18 : : GeneralUserObject(parameters), 19 30 : _mesh(_fe_problem.mesh().getMesh()), 20 30 : _metric_variable_name(getParam<AuxVariableName>("metric_variable_name")), 21 30 : _metric_variable(_fe_problem.getVariable(_tid, _metric_variable_name)), 22 30 : _auxiliary_system(_fe_problem.getAuxiliarySystem()), 23 30 : _dof_map(_auxiliary_system.dofMap()), 24 30 : _metric_variable_index(_auxiliary_system.getVariable(_tid, _metric_variable_name).number()), 25 60 : _serialized_metric_solution(_auxiliary_system.serializedSolution()) 26 : { 27 : // check if the element type if CONSTANT MONOMIAL. If not then throw a mooseError. 28 30 : if (_metric_variable.feType() != FEType(CONSTANT, MONOMIAL)) 29 3 : paramError("metric_variable_name", 30 3 : _metric_variable_name + " must be of type CONSTANT MONOMIAL"); 31 : // check if mesh is replicated. If not then throw a moose error. 32 27 : if (!_mesh.is_replicated()) 33 0 : mooseError("Mesh must be replicated"); 34 27 : } 35 : 36 : void 37 36 : ClusteringUserObjectBase::initialize() 38 : { 39 36 : _auxiliary_system.serializeSolution(); 40 36 : } 41 : 42 : Real 43 19254 : ClusteringUserObjectBase::getMetricData(const libMesh::Elem * elem) const 44 : { 45 : std::vector<dof_id_type> dof_indices; 46 19254 : std::vector<double> solution_value(1); 47 19254 : _dof_map.dof_indices(elem, dof_indices, _metric_variable_index); 48 19254 : _serialized_metric_solution.get(dof_indices, solution_value); 49 : // We can return simply the first DOF index because we restrict this object to const monomial 50 19254 : return solution_value[0]; 51 19254 : }