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 "SetAdaptivityOptionsAction.h" 11 : #include "FEProblem.h" 12 : #include "RelationshipManager.h" 13 : 14 : #include "libmesh/fe.h" 15 : 16 : registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "set_adaptivity_options"); 17 : registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "add_geometric_rm"); 18 : registerMooseAction("MooseApp", SetAdaptivityOptionsAction, "add_algebraic_rm"); 19 : 20 : namespace Moose 21 : { 22 : InputParameters 23 2625 : commonAdaptivityParams() 24 : { 25 2625 : InputParameters params = Action::validParams(); 26 7875 : params.addParam<unsigned int>( 27 5250 : "steps", 0, "The number of adaptive steps to use when doing a Steady simulation."); 28 7875 : params.addRangeCheckedParam<unsigned int>( 29 5250 : "interval", 1, "interval>0", "The number of time steps betweeen each adaptivity phase"); 30 7875 : params.addParam<unsigned int>( 31 : "max_h_level", 32 5250 : 0, 33 : "Maximum number of times a single element can be refined. If 0 then infinite."); 34 7875 : params.addParam<Real>("start_time", 35 5250 : -std::numeric_limits<Real>::max(), 36 : "The time that adaptivity will be active after."); 37 7875 : params.addParam<Real>("stop_time", 38 5250 : std::numeric_limits<Real>::max(), 39 : "The time after which adaptivity will no longer be active."); 40 7875 : params.addParam<unsigned int>( 41 : "cycles_per_step", 42 5250 : 1, 43 : "The number of adaptive steps to use when on each timestep during a Transient simulation."); 44 7875 : params.addParam<bool>( 45 5250 : "recompute_markers_during_cycles", false, "Recompute markers during adaptivity cycles"); 46 2625 : params.addParam<bool>("switch_h_to_p_refinement", false, "True to perform p-refinement"); 47 2625 : return params; 48 0 : } 49 : } 50 : 51 : InputParameters 52 1988 : SetAdaptivityOptionsAction::validParams() 53 : { 54 1988 : InputParameters params = Moose::commonAdaptivityParams(); 55 1988 : params.addClassDescription("Action for defining adaptivity parameters."); 56 1988 : params.addParam<MarkerName>("marker", 57 : "The name of the Marker to use to actually adapt the mesh."); 58 5964 : params.addParam<unsigned int>( 59 3976 : "initial_steps", 0, "The number of adaptive steps to do based on the initial condition."); 60 1988 : params.addParam<MarkerName>( 61 : "initial_marker", 62 : "The name of the Marker to use to adapt the mesh during initial refinement."); 63 1988 : params.addParamNamesToGroup("initial_steps initial_marker", "Initial Adaptivity"); 64 1988 : return params; 65 0 : } 66 : 67 1784 : SetAdaptivityOptionsAction::SetAdaptivityOptionsAction(const InputParameters & params) 68 1784 : : Action(params) 69 : { 70 1784 : } 71 : 72 : void 73 5320 : SetAdaptivityOptionsAction::act() 74 : { 75 : // Here we are going to mostly mimic the default ghosting in libmesh 76 : // By default libmesh adds: 77 : // 1) GhostPointNeighbors on the mesh 78 : // 2) DefaultCoupling with 1 layer as an algebraic ghosting functor on the dof_map, which also 79 : // gets added to the mesh at the time a new System is added 80 : // 3) DefaultCoupling with 0 layers as a coupling functor on the dof_map, which also gets added to 81 : // the mesh at the time a new System is added 82 : // 83 : // What we will do differently is: 84 : // - The 3rd ghosting functor adds nothing so we will not add it at all 85 : 86 5320 : if (_current_task == "add_algebraic_rm") 87 : { 88 1768 : auto rm_params = _factory.getValidParams("ElementSideNeighborLayers"); 89 : 90 1768 : rm_params.set<std::string>("for_whom") = "Adaptivity"; 91 1768 : rm_params.set<MooseMesh *>("mesh") = _mesh.get(); 92 1768 : rm_params.set<Moose::RelationshipManagerType>("rm_type") = 93 : Moose::RelationshipManagerType::ALGEBRAIC; 94 : 95 1768 : if (rm_params.areAllRequiredParamsValid()) 96 : { 97 1768 : auto rm_obj = _factory.create<RelationshipManager>( 98 1768 : "ElementSideNeighborLayers", "adaptivity_algebraic_ghosting", rm_params); 99 : 100 : // Delete the resources created on behalf of the RM if it ends up not being added to the 101 : // App. 102 1768 : if (!_app.addRelationshipManager(rm_obj)) 103 762 : _factory.releaseSharedObjects(*rm_obj); 104 1768 : } 105 : else 106 0 : mooseError("Invalid initialization of ElementSideNeighborLayers"); 107 1768 : } 108 : 109 3552 : else if (_current_task == "add_geometric_rm") 110 : { 111 1776 : auto rm_params = _factory.getValidParams("ElementPointNeighborLayers"); 112 : 113 1776 : rm_params.set<std::string>("for_whom") = "Adaptivity"; 114 1776 : rm_params.set<MooseMesh *>("mesh") = _mesh.get(); 115 1776 : rm_params.set<Moose::RelationshipManagerType>("rm_type") = 116 : Moose::RelationshipManagerType::GEOMETRIC; 117 : 118 1776 : if (rm_params.areAllRequiredParamsValid()) 119 : { 120 1776 : auto rm_obj = _factory.create<RelationshipManager>( 121 1776 : "ElementPointNeighborLayers", "adaptivity_geometric_ghosting", rm_params); 122 : 123 : // Delete the resources created on behalf of the RM if it ends up not being added to the 124 : // App. 125 1776 : if (!_app.addRelationshipManager(rm_obj)) 126 0 : _factory.releaseSharedObjects(*rm_obj); 127 1776 : } 128 : else 129 0 : mooseError("Invalid initialization of ElementPointNeighborLayers"); 130 1776 : } 131 : 132 1776 : else if (_current_task == "set_adaptivity_options") 133 : { 134 1776 : Adaptivity & adapt = _problem->adaptivity(); 135 : 136 1776 : if (isParamValid("marker")) 137 1140 : adapt.setMarkerVariableName(getParam<MarkerName>("marker")); 138 1776 : if (isParamValid("initial_marker")) 139 654 : adapt.setInitialMarkerVariableName(getParam<MarkerName>("initial_marker")); 140 : 141 1776 : adapt.setCyclesPerStep(getParam<unsigned int>("cycles_per_step")); 142 : 143 1776 : adapt.setMaxHLevel(getParam<unsigned int>("max_h_level")); 144 : 145 1776 : adapt.init(getParam<unsigned int>("steps"), 146 3552 : getParam<unsigned int>("initial_steps"), 147 3552 : getParam<bool>("switch_h_to_p_refinement")); 148 1776 : adapt.setUseNewSystem(); 149 : 150 1776 : adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time")); 151 1776 : adapt.setInterval(getParam<unsigned int>("interval")); 152 : 153 1776 : adapt.setRecomputeMarkersFlag(getParam<bool>("recompute_markers_during_cycles")); 154 : } 155 5320 : }