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 11768 : GeneratedMeshComponent::validParams() 15 : { 16 11768 : InputParameters params = GeometricalComponent::validParams(); 17 11768 : params += DiscreteLineSegmentInterface::validParams(); 18 : 19 23536 : params.addParam<std::vector<std::string>>( 20 : "axial_region_names", {}, "Names to assign to axial regions"); 21 : 22 11768 : return params; 23 0 : } 24 : 25 5882 : GeneratedMeshComponent::GeneratedMeshComponent(const InputParameters & parameters) 26 : : GeometricalComponent(parameters), 27 : DiscreteLineSegmentInterface(this), 28 : 29 11764 : _axial_region_names(getParam<std::vector<std::string>>("axial_region_names")) 30 : { 31 5882 : checkSizeGreaterThan<Real>("length", 0); 32 11764 : checkEqualSize<Real, unsigned int>("length", "n_elems"); 33 5882 : if (_axial_region_names.size() > 0) 34 682 : checkEqualSize<Real, std::string>("length", "axial_region_names"); 35 5882 : } 36 : 37 : void 38 5882 : GeneratedMeshComponent::setupMesh() 39 : { 40 5882 : generateNodeLocations(); 41 : 42 5882 : buildMesh(); 43 : 44 : // displace nodes 45 379494 : for (auto && node_id : _node_ids) 46 : { 47 373612 : Node & curr_node = mesh().nodeRef(node_id); 48 : RealVectorValue p(curr_node(0), curr_node(1), curr_node(2)); 49 373612 : curr_node = computeRealPointFromReferencePoint(p); 50 : } 51 5882 : } 52 : 53 : void 54 5696 : GeneratedMeshComponent::check() const 55 : { 56 : GeometricalComponent::check(); 57 : 58 : // Do not use TRAP q-rule with 2nd order FEs 59 5696 : 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 5696 : } 69 : 70 : unsigned int 71 12197 : GeneratedMeshComponent::computeNumberOfNodes(unsigned int n_elems) 72 : { 73 12197 : return usingSecondOrderMesh() ? (2 * n_elems) + 1 : n_elems + 1; 74 : } 75 : 76 : void 77 5882 : GeneratedMeshComponent::generateNodeLocations() 78 : { 79 5882 : unsigned int n_nodes = computeNumberOfNodes(_n_elem); 80 : unsigned int start_node = 0; 81 : Real start_length = 0.0; 82 5882 : _node_locations = std::vector<Real>(n_nodes); 83 5882 : _node_locations[0] = start_length; 84 : 85 12197 : for (unsigned int i = 0; i < _n_sections; ++i) 86 : { 87 6315 : Real section_length = _lengths[i]; 88 6315 : Real section_n_elems = _n_elems[i]; 89 6315 : Real section_n_nodes = computeNumberOfNodes(section_n_elems); 90 : 91 6315 : std::vector<Real> section_node_array = getUniformNodeLocations(section_length, section_n_nodes); 92 6315 : placeLocalNodeLocations(start_length, start_node, section_node_array); 93 : 94 6315 : start_length += section_length; 95 6315 : start_node += (section_n_nodes - 1); 96 6315 : } 97 5882 : } 98 : 99 : std::vector<Real> 100 6315 : GeneratedMeshComponent::getUniformNodeLocations(Real length, unsigned int n_nodes) 101 : { 102 6315 : std::vector<Real> node_locations(n_nodes); 103 6315 : Real dx = length / (n_nodes - 1); 104 : 105 6315 : node_locations[0] = 0.0; 106 : 107 141033 : for (unsigned int i = 1; i < (n_nodes - 1); ++i) 108 134718 : node_locations[i] = node_locations[i - 1] + dx; 109 : 110 6315 : node_locations[n_nodes - 1] = length; 111 6315 : return node_locations; 112 : } 113 : 114 : void 115 6315 : GeneratedMeshComponent::placeLocalNodeLocations(Real start_length, 116 : unsigned int start_node, 117 : std::vector<Real> & local_node_locations) 118 : { 119 6315 : unsigned int n_nodes = local_node_locations.size(); 120 147348 : for (unsigned int i = 1; i < n_nodes; ++i) 121 : { 122 141033 : unsigned int global_i = i + start_node; 123 141033 : Real local_node_location = local_node_locations[i]; 124 141033 : _node_locations[global_i] = start_length + local_node_location; 125 : } 126 6315 : }