Line data Source code
1 : /********************************************************************/ 2 : /* SOFTWARE COPYRIGHT NOTIFICATION */ 3 : /* Cardinal */ 4 : /* */ 5 : /* (c) 2021 UChicago Argonne, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /* */ 8 : /* Prepared by UChicago Argonne, LLC */ 9 : /* Under Contract No. DE-AC02-06CH11357 */ 10 : /* With the U. S. Department of Energy */ 11 : /* */ 12 : /* Prepared by Battelle Energy Alliance, LLC */ 13 : /* Under Contract No. DE-AC07-05ID14517 */ 14 : /* With the U. S. Department of Energy */ 15 : /* */ 16 : /* See LICENSE for full restrictions */ 17 : /********************************************************************/ 18 : 19 : #ifdef ENABLE_NEK_COUPLING 20 : 21 : #include "NekMeshInfoPostprocessor.h" 22 : #include "SubProblem.h" 23 : #include "MooseMesh.h" 24 : 25 : registerMooseObject("CardinalApp", NekMeshInfoPostprocessor); 26 : 27 : InputParameters 28 3336 : NekMeshInfoPostprocessor::validParams() 29 : { 30 3336 : InputParameters params = GeneralPostprocessor::validParams(); 31 3336 : params += NekBase::validParams(); 32 : 33 6672 : MooseEnum test_type("num_elems num_nodes node_x node_y node_z"); 34 6672 : params.addRequiredParam<MooseEnum>("test_type", 35 : test_type, 36 : "The type of info to fetch; " 37 : "this is used to toggle between many different tests to avoid " 38 : "creating tons of source files."); 39 : 40 6672 : params.addParam<libMesh::dof_id_type>("node", "Element-local node ID"); 41 6672 : params.addParam<Point>("point", "Point used to locate element"); 42 : 43 3336 : params.addClassDescription("Extract properties of the NekRS mesh"); 44 3336 : return params; 45 3336 : } 46 : 47 1112 : NekMeshInfoPostprocessor::NekMeshInfoPostprocessor(const InputParameters & parameters) 48 : : GeneralPostprocessor(parameters), 49 : NekBase(this, parameters), 50 2224 : _test_type(getParam<MooseEnum>("test_type")) 51 : { 52 1112 : if (!_nek_mesh) 53 0 : mooseError("This class is intended for testing the 'NekRSMesh' mesh, " 54 : "and cannot be used with other mesh types."); 55 : 56 : // For any of the node_x, node_y, and node_z settings, we need to grab an element ID 57 : // and an element-local node ID 58 1112 : if (_test_type == "node_x" || _test_type == "node_y" || _test_type == "node_z") 59 : { 60 1080 : auto locator = _nek_mesh->getPointLocator(); 61 : 62 2160 : if (!isParamValid("point")) 63 0 : paramError("point", "When using a node test, a point must be specified to locate an element"); 64 : 65 2160 : if (!isParamValid("node")) 66 0 : paramError("node", 67 : "A 'node' must be specified when the 'test_type' is " 68 : "'node_x', 'node_y', or 'node_z'."); 69 : 70 2160 : const Point & p = getParam<Point>("point"); 71 1080 : _element = (*locator)(p); 72 : 73 1080 : bool found_element = _element; 74 1080 : getMooseApp().getCommunicator()->max(found_element); 75 : 76 1080 : if (!found_element) 77 0 : paramError("point", "The specified point cannot be found in the mesh"); 78 : 79 2160 : _node = &getParam<libMesh::dof_id_type>("node"); 80 : 81 1080 : if (*_node >= _nek_mesh->nNodes() / _nek_mesh->nElem()) 82 0 : paramError("node", "The 'node' must be in the range [0, number of nodes / element]!"); 83 1080 : } 84 1112 : } 85 : 86 : Real 87 1112 : NekMeshInfoPostprocessor::getValue() const 88 : { 89 : 90 1112 : if (_test_type == "num_elems") 91 16 : return _nek_mesh->nElem(); 92 1096 : else if (_test_type == "num_nodes") 93 16 : return _nek_mesh->nNodes(); 94 1080 : else if (_test_type == "node_x" || _test_type == "node_y" || _test_type == "node_z") 95 : { 96 1080 : int id = _test_type == "node_x" ? 0 : (_test_type == "node_y" ? 1 : 2); 97 : 98 : Real coord; 99 1080 : libMesh::processor_id_type p_id = 0; 100 : const auto comm = getMooseApp().getCommunicator(); 101 : 102 1080 : if (_element) 103 : { 104 540 : auto node = _element->node_ptr(*_node); 105 540 : coord = (*node)(id); 106 540 : p_id = _element->processor_id(); 107 : } 108 : 109 : // can get the processor ID of the owning rank by just finding maximum, since 110 : // guaranteed rank >= 0 111 1080 : comm->max(p_id); 112 : 113 1080 : comm->broadcast(coord, p_id); 114 : 115 1080 : return coord; 116 : } 117 : else 118 0 : mooseError("Unhandled 'test_type' enum!"); 119 : } 120 : 121 : #endif