LCOV - code coverage report
Current view: top level - src/actions - SetupMeshCompleteAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 42 46 91.3 %
Date: 2025-07-17 01:28:37 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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 "SetupMeshCompleteAction.h"
      11             : #include "MooseMesh.h"
      12             : #include "Moose.h"
      13             : #include "Adaptivity.h"
      14             : #include "MooseApp.h"
      15             : #include "FEProblemBase.h"
      16             : 
      17             : registerMooseAction("MooseApp", SetupMeshCompleteAction, "prepare_mesh");
      18             : 
      19             : registerMooseAction("MooseApp",
      20             :                     SetupMeshCompleteAction,
      21             :                     "delete_remote_elements_after_late_geometric_ghosting");
      22             : 
      23             : registerMooseAction("MooseApp", SetupMeshCompleteAction, "uniform_refine_mesh");
      24             : 
      25             : registerMooseAction("MooseApp", SetupMeshCompleteAction, "setup_mesh_complete");
      26             : 
      27             : InputParameters
      28       62412 : SetupMeshCompleteAction::validParams()
      29             : {
      30       62412 :   InputParameters params = Action::validParams();
      31       62412 :   params.addClassDescription("Perform operations on the mesh in preparation for a simulation.");
      32       62412 :   return params;
      33           0 : }
      34             : 
      35       62194 : SetupMeshCompleteAction::SetupMeshCompleteAction(const InputParameters & params) : Action(params) {}
      36             : 
      37             : void
      38      239045 : SetupMeshCompleteAction::act()
      39             : {
      40      239045 :   if (!_mesh)
      41           0 :     mooseError("No mesh file was supplied and no generation block was provided");
      42             : 
      43      239045 :   if (_current_task == "uniform_refine_mesh")
      44             :   {
      45             :     // we don't need to run mesh modifiers *again* after they ran already during the mesh
      46             :     // splitting process
      47             :     // A uniform refinement is helpful for some instances when using a pre-split mesh.
      48             :     // For example, a 'coarse' mesh might completely resolve geometry (also is large)
      49             :     // but does not have enough resolution for the interior. For this scenario,
      50             :     // we pre-split the coarse mesh, and load the pre-split mesh in parallel,
      51             :     // and then do a few levels of uniform refinements to have a fine mesh that
      52             :     // potentially resolves physics features.
      53       60975 :     if (_mesh->isSplit() && _mesh->skipRefineWhenUseSplit())
      54         239 :       return;
      55             : 
      56             :     // uniform refinement has been done on master, so skip
      57       60736 :     if (_app.useMasterMesh())
      58         784 :       return;
      59             : 
      60             :     /**
      61             :      * If possible we'd like to refine the mesh here before the equation systems
      62             :      * are setup to avoid doing expensive projections. If however we are doing a
      63             :      * file based restart and we need uniform refinements, we'll have to postpone
      64             :      * those refinements until after the solution has been read in.
      65             :      */
      66       59952 :     if (_app.getExodusFileRestart() == false)
      67             :     {
      68       59665 :       if (_app.isRecovering() == false || !_app.isUltimateMaster())
      69             :       {
      70       56758 :         TIME_SECTION("uniformRefine", 2, "Uniformly Refining");
      71             : 
      72       56758 :         if (_mesh->uniformRefineLevel())
      73             :         {
      74        4666 :           if (!_mesh->interiorLowerDBlocks().empty() || !_mesh->boundaryLowerDBlocks().empty())
      75           0 :             mooseError("HFEM does not support mesh uniform refinement currently.");
      76             : 
      77        4666 :           Adaptivity::uniformRefine(_mesh.get());
      78             :           // After refinement we need to make sure that all of our MOOSE-specific containers are
      79             :           // up-to-date
      80        4666 :           _mesh->meshChanged();
      81             : 
      82        4666 :           if (_displaced_mesh)
      83             :           {
      84          53 :             Adaptivity::uniformRefine(_displaced_mesh.get());
      85             :             // After refinement we need to make sure that all of our MOOSE-specific containers are
      86             :             // up-to-date
      87          53 :             _displaced_mesh->meshChanged();
      88             :           }
      89             :         }
      90       56758 :       }
      91             :     }
      92             :   }
      93      178070 :   else if (_current_task == "delete_remote_elements_after_late_geometric_ghosting")
      94             :   {
      95       56116 :     TIME_SECTION("deleteRemoteElems", 2, "Deleting Remote Elements");
      96             : 
      97       58179 :     if (_displaced_mesh &&
      98       58179 :         (_mesh->needsRemoteElemDeletion() != _displaced_mesh->needsRemoteElemDeletion()))
      99           0 :       mooseError("Our reference and displaced meshes are not in sync with respect to whether we "
     100             :                  "should delete remote elements.");
     101             : 
     102             :     // We currently only trigger the needsRemoteDeletion flag if somebody has requested a late
     103             :     // geometric ghosting functor and/or we have a displaced mesh
     104       56116 :     if (_mesh->needsRemoteElemDeletion())
     105             :     {
     106             :       // Must make sure to create the mortar meshes to build our data structures that ensure we will
     107             :       // keep the correct elements in the mesh around
     108       14323 :       _problem->updateMortarMesh();
     109       14323 :       _mesh->deleteRemoteElements();
     110       14323 :       if (_displaced_mesh)
     111        2063 :         _displaced_mesh->deleteRemoteElements();
     112             :     }
     113       56116 :   }
     114             :   else
     115             :   {
     116             :     // Prepare the mesh (may occur multiple times)
     117      121954 :     bool prepare_for_use_called_on_undisplaced = false;
     118             :     {
     119      121954 :       TIME_SECTION("completeSetupUndisplaced", 2, "Setting Up Undisplaced Mesh");
     120      121954 :       prepare_for_use_called_on_undisplaced = _mesh->prepare(/*mesh_to_clone=*/nullptr);
     121      121950 :     }
     122             : 
     123      121950 :     if (_displaced_mesh)
     124             :     {
     125        4146 :       TIME_SECTION("completeSetupDisplaced", 2, "Setting Up Displaced Mesh");
     126             :       // If the reference mesh was prepared, then we must prepare also
     127        4299 :       _displaced_mesh->prepare(
     128         153 :           /*mesh_to_clone=*/prepare_for_use_called_on_undisplaced ? &_mesh->getMesh() : nullptr);
     129        4146 :     }
     130             :   }
     131             : }

Generated by: LCOV version 1.14