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 "RelationshipManager.h" 11 : #include "MooseApp.h" 12 : 13 : using namespace libMesh; 14 : 15 : InputParameters 16 1394905 : RelationshipManager::validParams() 17 : { 18 1394905 : InputParameters params = MooseObject::validParams(); 19 : 20 : /** 21 : * Param to indicate whether all necessary GeometricRelationshipManagers can be attached during 22 : * the setup of the mesh. When true (and when running with DistributedMesh) the framework can 23 : * perform two optimizations: 24 : * 25 : * 1) Elements not needed by any ghosting functor can be safely deleted during Mesh::init() prior 26 : * to building the EquationSystems object or other MOOSE objects. This may result in 27 : * significant memory savings during the setup phase. 28 : * 29 : * 2) A late mesh reinitialization can be skipped reducing the overall setup time of the 30 : * simulation. 31 : * 32 : * When in doubt and to allow for maximum flexibility, developers may choose to return false here 33 : * to simplify setting up Algebraic and Geometric at the same time. 34 : */ 35 1394905 : params.addPrivateParam<bool>("attach_geometric_early", true); 36 : 37 : /** 38 : * This parameter indicates which type of RelationshipManager this class represents prior to its 39 : * construction. Geometric-only RelationshipManagers may be buildable early in which case the 40 : * framework can optimize memory usage for Distributed Mesh by allowing remote elements to be 41 : * deleted. Depending on the mesh size and EquationSystems size, this may have a significant 42 : * impact on total memory usage during the problem setup phase. 43 : */ 44 1394905 : params.addPrivateParam<Moose::RelationshipManagerType>("rm_type"); 45 : 46 : /** 47 : * The name of the object (or Action) requesting this RM 48 : */ 49 1394905 : params.addRequiredParam<std::string>("for_whom", "What object is requesting this RM?"); 50 : 51 4184715 : params.addParam<bool>( 52 : "use_displaced_mesh", 53 2789810 : false, 54 : "Whether this RM should be placed on the undisplaced or displaced problem. Note: yes, it " 55 : "still says 'mesh' to match with common parameter name in MOOSE - but if it's purely " 56 : "algebraic then it's going to the DofMap no matter what!"); 57 : 58 : // Set by MOOSE 59 1394905 : params.addPrivateParam<MooseMesh *>("mesh"); 60 1394905 : params.registerBase("RelationshipManager"); 61 1394905 : return params; 62 0 : } 63 : 64 560970 : RelationshipManager::RelationshipManager(const InputParameters & parameters) 65 : : MooseObject(parameters), 66 : GhostingFunctor(), 67 560970 : _moose_mesh(getCheckedPointerParam<MooseMesh *>( 68 : "mesh", 69 : "Mesh is null in RelationshipManager constructor. This could well be because No mesh file " 70 : "was supplied and no generation block was provided")), 71 560966 : _attach_geometric_early(getParam<bool>("attach_geometric_early")), 72 560966 : _rm_type(getParam<Moose::RelationshipManagerType>("rm_type")), 73 1682902 : _use_displaced_mesh(getParam<bool>("use_displaced_mesh")) 74 : { 75 560966 : _for_whom.push_back(getParam<std::string>("for_whom")); 76 560966 : } 77 : 78 144584 : RelationshipManager::RelationshipManager(const RelationshipManager & other) 79 : : MooseObject(other._pars), 80 : GhostingFunctor(other), 81 144584 : _moose_mesh(other._moose_mesh), 82 144584 : _attach_geometric_early(other._attach_geometric_early), 83 144584 : _rm_type(other._rm_type), 84 144584 : _for_whom(other._for_whom), 85 144584 : _use_displaced_mesh(other._use_displaced_mesh) 86 : { 87 144584 : } 88 : 89 : bool 90 0 : RelationshipManager::isGeometric(Moose::RelationshipManagerType input_rm) 91 : { 92 0 : return (input_rm & Moose::RelationshipManagerType::GEOMETRIC) == 93 0 : Moose::RelationshipManagerType::GEOMETRIC; 94 : } 95 : 96 : bool 97 0 : RelationshipManager::isAlgebraic(Moose::RelationshipManagerType input_rm) 98 : { 99 0 : return (input_rm & Moose::RelationshipManagerType::ALGEBRAIC) == 100 0 : Moose::RelationshipManagerType::ALGEBRAIC; 101 : } 102 : 103 : bool 104 0 : RelationshipManager::isCoupling(Moose::RelationshipManagerType input_rm) 105 : { 106 0 : return (input_rm & Moose::RelationshipManagerType::COUPLING) == 107 0 : Moose::RelationshipManagerType::COUPLING; 108 : } 109 : 110 : bool 111 374455 : RelationshipManager::baseGreaterEqual(const RelationshipManager & rhs) const 112 : { 113 : // !attach early = attach late 114 : // If we are supposed to be attached late, then we should take precedence over the rhs. You can 115 : // think of this as being >= because we if we are attaching late, then we are asking that *all* 116 : // elements be geometrically ghosted during the initial mesh preparation phase. We will only allow 117 : // remote elements to be deleted later on after addition of late geomeric ghosting functors (at 118 : // the same time as algebraic and coupling) 119 374455 : return isType(rhs._rm_type) && (!_attach_geometric_early >= !rhs._attach_geometric_early); 120 : } 121 : 122 : Moose::RelationshipManagerType RelationshipManager::geo_and_alg = 123 : Moose::RelationshipManagerType::GEOMETRIC | Moose::RelationshipManagerType::ALGEBRAIC; 124 : 125 : Moose::RelationshipManagerType RelationshipManager::geo_alg_and_coupl = 126 : Moose::RelationshipManagerType::GEOMETRIC | Moose::RelationshipManagerType::ALGEBRAIC | 127 : Moose::RelationshipManagerType::COUPLING; 128 : 129 : InputParameters 130 2522 : dummyParams() 131 : { 132 2522 : auto params = emptyInputParameters(); 133 2522 : params.set<std::string>("_moose_base") = "dummy"; 134 2522 : return params; 135 0 : } 136 : 137 : InputParameters 138 0 : RelationshipManager::zeroLayerGhosting() 139 : { 140 0 : auto params = dummyParams(); 141 0 : params.addRelationshipManager("ElementSideNeighborLayers", 142 : Moose::RelationshipManagerType::COUPLING, 143 0 : [](const InputParameters &, InputParameters & rm_params) 144 0 : { rm_params.set<unsigned short>("layers") = 0; }); 145 0 : return params; 146 0 : } 147 : 148 : InputParameters 149 2522 : RelationshipManager::oneLayerGhosting(Moose::RelationshipManagerType rm_type) 150 : { 151 2522 : auto params = dummyParams(); 152 2522 : params.addRelationshipManager("ElementSideNeighborLayers", rm_type); 153 2522 : return params; 154 0 : } 155 : 156 : void 157 148349 : RelationshipManager::init(MooseMesh & moose_mesh, 158 : const MeshBase & mesh, 159 : const DofMap * const dof_map) 160 : { 161 : mooseAssert(_dof_map ? dof_map == _dof_map : true, 162 : "Trying to initialize with a different dof map"); 163 : 164 148349 : _dof_map = dof_map; 165 : // During the mesh generation phase we haven't set the mesh base in the moose mesh yet 166 148349 : if (moose_mesh.getMeshPtr()) 167 : mooseAssert(moose_mesh.getMeshPtr() == &mesh, "These should match"); 168 148349 : _moose_mesh = &moose_mesh; 169 : 170 : // It is conceivable that this init method gets called twice, once during early geometric setup 171 : // and later when we're doing algebraic/coupling (and late geometric) setup. There might be new 172 : // information available during the latter call that the derived RelationshipManager can 173 : // leverage, so we should make sure we call through to internal init both times 174 148349 : internalInitWithMesh(mesh); 175 : 176 : // One would hope that internalInitWithMesh set the mesh, but we can't be sure 177 148349 : set_mesh(&mesh); 178 : 179 148349 : _inited = true; 180 148349 : }