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 2799 : commonAdaptivityParams() 24 : { 25 2799 : InputParameters params = Action::validParams(); 26 8397 : params.addParam<unsigned int>( 27 5598 : "steps", 0, "The number of adaptive steps to use when doing a Steady simulation."); 28 8397 : params.addRangeCheckedParam<unsigned int>( 29 5598 : "interval", 1, "interval>0", "The number of time steps betweeen each adaptivity phase"); 30 8397 : params.addParam<unsigned int>( 31 : "max_h_level", 32 5598 : 0, 33 : "Maximum number of times a single element can be refined. If 0 then infinite."); 34 8397 : params.addParam<Real>("start_time", 35 5598 : -std::numeric_limits<Real>::max(), 36 : "The time that adaptivity will be active after."); 37 8397 : params.addParam<Real>("stop_time", 38 5598 : std::numeric_limits<Real>::max(), 39 : "The time after which adaptivity will no longer be active."); 40 8397 : params.addParam<unsigned int>( 41 : "cycles_per_step", 42 5598 : 1, 43 : "The number of adaptive steps to use when on each timestep during a Transient simulation."); 44 8397 : params.addParam<bool>( 45 5598 : "recompute_markers_during_cycles", false, "Recompute markers during adaptivity cycles"); 46 2799 : params.addParam<bool>("switch_h_to_p_refinement", false, "True to perform p-refinement"); 47 2799 : return params; 48 0 : } 49 : } 50 : 51 : InputParameters 52 2130 : SetAdaptivityOptionsAction::validParams() 53 : { 54 2130 : InputParameters params = Moose::commonAdaptivityParams(); 55 2130 : params.addClassDescription("Action for defining adaptivity parameters."); 56 2130 : params.addParam<MarkerName>("marker", 57 : "The name of the Marker to use to actually adapt the mesh."); 58 6390 : params.addParam<unsigned int>( 59 4260 : "initial_steps", 0, "The number of adaptive steps to do based on the initial condition."); 60 2130 : params.addParam<MarkerName>( 61 : "initial_marker", 62 : "The name of the Marker to use to adapt the mesh during initial refinement."); 63 2130 : params.addParamNamesToGroup("initial_steps initial_marker", "Initial Adaptivity"); 64 2130 : return params; 65 0 : } 66 : 67 1926 : SetAdaptivityOptionsAction::SetAdaptivityOptionsAction(const InputParameters & params) 68 1926 : : Action(params) 69 : { 70 1926 : } 71 : 72 : void 73 5746 : 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 5746 : if (_current_task == "add_algebraic_rm") 87 : { 88 1910 : auto rm_params = _factory.getValidParams("ElementSideNeighborLayers"); 89 : 90 1910 : rm_params.set<std::string>("for_whom") = "Adaptivity"; 91 1910 : rm_params.set<MooseMesh *>("mesh") = _mesh.get(); 92 1910 : rm_params.set<Moose::RelationshipManagerType>("rm_type") = 93 : Moose::RelationshipManagerType::ALGEBRAIC; 94 : 95 1910 : if (rm_params.areAllRequiredParamsValid()) 96 : { 97 1910 : auto rm_obj = _factory.create<RelationshipManager>( 98 1910 : "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 1910 : if (!_app.addRelationshipManager(rm_obj)) 103 821 : _factory.releaseSharedObjects(*rm_obj); 104 1910 : } 105 : else 106 0 : mooseError("Invalid initialization of ElementSideNeighborLayers"); 107 1910 : } 108 : 109 3836 : else if (_current_task == "add_geometric_rm") 110 : { 111 1918 : auto rm_params = _factory.getValidParams("ElementPointNeighborLayers"); 112 : 113 1918 : rm_params.set<std::string>("for_whom") = "Adaptivity"; 114 1918 : rm_params.set<MooseMesh *>("mesh") = _mesh.get(); 115 1918 : rm_params.set<Moose::RelationshipManagerType>("rm_type") = 116 : Moose::RelationshipManagerType::GEOMETRIC; 117 : 118 1918 : if (rm_params.areAllRequiredParamsValid()) 119 : { 120 1918 : auto rm_obj = _factory.create<RelationshipManager>( 121 1918 : "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 1918 : if (!_app.addRelationshipManager(rm_obj)) 126 0 : _factory.releaseSharedObjects(*rm_obj); 127 1918 : } 128 : else 129 0 : mooseError("Invalid initialization of ElementPointNeighborLayers"); 130 1918 : } 131 : 132 1918 : else if (_current_task == "set_adaptivity_options") 133 : { 134 1918 : Adaptivity & adapt = _problem->adaptivity(); 135 : 136 1918 : if (isParamValid("marker")) 137 1225 : adapt.setMarkerVariableName(getParam<MarkerName>("marker")); 138 1918 : if (isParamValid("initial_marker")) 139 710 : adapt.setInitialMarkerVariableName(getParam<MarkerName>("initial_marker")); 140 : 141 1918 : adapt.setCyclesPerStep(getParam<unsigned int>("cycles_per_step")); 142 : 143 1918 : adapt.setMaxHLevel(getParam<unsigned int>("max_h_level")); 144 : 145 1918 : adapt.init(getParam<unsigned int>("steps"), 146 3836 : getParam<unsigned int>("initial_steps"), 147 3836 : getParam<bool>("switch_h_to_p_refinement")); 148 1918 : adapt.setUseNewSystem(); 149 : 150 1918 : adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time")); 151 1918 : adapt.setInterval(getParam<unsigned int>("interval")); 152 : 153 1918 : adapt.setRecomputeMarkersFlag(getParam<bool>("recompute_markers_during_cycles")); 154 : } 155 5746 : }