Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "GeneratedMeshComponent.h" 11 : #include "THMMesh.h" 12 : 13 : InputParameters 14 11766 : GeneratedMeshComponent::validParams() 15 : { 16 11766 : InputParameters params = GeometricalComponent::validParams(); 17 11766 : params += DiscreteLineSegmentInterface::validParams(); 18 : 19 23532 : params.addParam<std::vector<std::string>>( 20 : "axial_region_names", {}, "Names to assign to axial regions"); 21 : 22 11766 : return params; 23 0 : } 24 : 25 5881 : GeneratedMeshComponent::GeneratedMeshComponent(const InputParameters & parameters) 26 : : GeometricalComponent(parameters), 27 : DiscreteLineSegmentInterface(this), 28 : 29 11762 : _axial_region_names(getParam<std::vector<std::string>>("axial_region_names")) 30 : { 31 5881 : checkSizeGreaterThan<Real>("length", 0); 32 11762 : checkEqualSize<Real, unsigned int>("length", "n_elems"); 33 5881 : if (_axial_region_names.size() > 0) 34 680 : checkEqualSize<Real, std::string>("length", "axial_region_names"); 35 5881 : } 36 : 37 : void 38 5881 : GeneratedMeshComponent::setupMesh() 39 : { 40 5881 : generateNodeLocations(); 41 : 42 5881 : buildMesh(); 43 : 44 : // displace nodes 45 379401 : for (auto && node_id : _node_ids) 46 : { 47 373520 : Node & curr_node = mesh().nodeRef(node_id); 48 : RealVectorValue p(curr_node(0), curr_node(1), curr_node(2)); 49 373520 : curr_node = computeRealPointFromReferencePoint(p); 50 : } 51 5881 : } 52 : 53 : void 54 5695 : GeneratedMeshComponent::check() const 55 : { 56 5695 : GeometricalComponent::check(); 57 : 58 : // Do not use TRAP q-rule with 2nd order FEs 59 5695 : if (usingSecondOrderMesh()) 60 : { 61 24 : auto actions = _app.actionWarehouse().getActionListByName("setup_quadrature"); 62 12 : const MooseEnum & quadrature_type = (*actions.begin())->getParam<MooseEnum>("type"); 63 : 64 12 : if (quadrature_type == "TRAP") 65 4 : logError("Cannot use TRAP quadrature rule with 2nd order elements. Use SIMPSON or GAUSS " 66 : "instead."); 67 : } 68 5695 : } 69 : 70 : unsigned int 71 12194 : GeneratedMeshComponent::computeNumberOfNodes(unsigned int n_elems) 72 : { 73 12194 : return usingSecondOrderMesh() ? (2 * n_elems) + 1 : n_elems + 1; 74 : } 75 : 76 : void 77 5881 : GeneratedMeshComponent::generateNodeLocations() 78 : { 79 5881 : unsigned int n_nodes = computeNumberOfNodes(_n_elem); 80 : unsigned int start_node = 0; 81 : Real start_length = 0.0; 82 11762 : _node_locations = std::vector<Real>(n_nodes); 83 5881 : _node_locations[0] = start_length; 84 : 85 12194 : for (unsigned int i = 0; i < _n_sections; ++i) 86 : { 87 6313 : Real section_length = _lengths[i]; 88 6313 : Real section_n_elems = _n_elems[i]; 89 6313 : Real section_n_nodes = computeNumberOfNodes(section_n_elems); 90 : 91 6313 : std::vector<Real> section_node_array = getUniformNodeLocations(section_length, section_n_nodes); 92 6313 : placeLocalNodeLocations(start_length, start_node, section_node_array); 93 : 94 6313 : start_length += section_length; 95 6313 : start_node += (section_n_nodes - 1); 96 : } 97 5881 : } 98 : 99 : std::vector<Real> 100 6313 : GeneratedMeshComponent::getUniformNodeLocations(Real length, unsigned int n_nodes) 101 : { 102 6313 : std::vector<Real> node_locations(n_nodes); 103 6313 : Real dx = length / (n_nodes - 1); 104 : 105 6313 : node_locations[0] = 0.0; 106 : 107 141011 : for (unsigned int i = 1; i < (n_nodes - 1); ++i) 108 134698 : node_locations[i] = node_locations[i - 1] + dx; 109 : 110 6313 : node_locations[n_nodes - 1] = length; 111 6313 : return node_locations; 112 : } 113 : 114 : void 115 6313 : GeneratedMeshComponent::placeLocalNodeLocations(Real start_length, 116 : unsigned int start_node, 117 : std::vector<Real> & local_node_locations) 118 : { 119 6313 : unsigned int n_nodes = local_node_locations.size(); 120 147324 : for (unsigned int i = 1; i < n_nodes; ++i) 121 : { 122 141011 : unsigned int global_i = i + start_node; 123 141011 : Real local_node_location = local_node_locations[i]; 124 141011 : _node_locations[global_i] = start_length + local_node_location; 125 : } 126 6313 : }