https://mooseframework.inl.gov
PCNSFVKTDC.C
Go to the documentation of this file.
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 "PCNSFVKTDC.h"
11 #include "NS.h"
13 #include "Limiter.h"
14 #include "NavierStokesApp.h"
15 #include "Executioner.h"
16 
17 using namespace Moose::FV;
18 
19 registerMooseObject("NavierStokesApp", PCNSFVKTDC);
20 
23 {
25  params.addClassDescription("Computes the residual of advective term using finite volume method "
26  "using a deferred correction approach.");
27  params.addParam<Real>(
28  "ho_implicit_fraction", 0, "The fraction of the high order flux that should be implicit");
29  return params;
30 }
31 
33  : PCNSFVKT(params),
34  _upwind_limiter(Limiter<ADReal>::build(LimiterType::Upwind)),
35  _old_upwind_fluxes(
36  declareRestartableData<std::unordered_map<dof_id_type, Real>>("old_upwind_fluxes")),
37  _old_ho_fluxes(declareRestartableData<std::unordered_map<dof_id_type, Real>>("old_ho_fluxes")),
38  _current_upwind_fluxes(
39  declareRestartableData<std::unordered_map<dof_id_type, Real>>("current_upwind_fluxes")),
40  _current_ho_fluxes(
41  declareRestartableData<std::unordered_map<dof_id_type, Real>>("current_ho_fluxes")),
42  _ho_implicit_fraction(getParam<Real>("ho_implicit_fraction"))
43 {
44 }
45 
46 void
48 {
49  // The SubProblem converged method is not restartable (it relies on data from libMesh) but the
50  // Executioner converged method is, so we use that
52  {
55  }
56 }
57 
58 void
60 {
61  _current_upwind_fluxes.clear();
62  _current_ho_fluxes.clear();
63 }
64 
65 void
67 {
68  residualSetup();
69 }
70 
71 Real
72 PCNSFVKTDC::getOldFlux(const bool upwind) const
73 {
74  if (_t_step <= 1)
75  return 0;
76 
77  const auto & flux_container = upwind ? _old_upwind_fluxes : _old_ho_fluxes;
78  auto it = flux_container.find(_face_info->id());
79  mooseAssert(it != flux_container.end(),
80  "We should have saved an old flux for the current _face_info. Do you have mesh "
81  "adaptivity on? Unfortunately we don't currently support that");
82  return it->second;
83 }
84 
85 ADReal
87 {
88  mooseAssert(!onBoundary(*_face_info), "We should never execute this object on a boundary");
89 
90  const auto current_ho_flux = PCNSFVKT::computeQpResidual();
91 #ifndef NDEBUG
92  auto pr =
93 #endif
94  _current_ho_fluxes.emplace(_face_info->id(), current_ho_flux.value());
95  mooseAssert(pr.second,
96  "Insertion should have happened. If it did not it means you are overwriting some "
97  "other face's flux!");
99  const auto current_upwind_flux = PCNSFVKT::computeQpResidual();
100 #ifndef NDEBUG
101  pr =
102 #endif
103  _current_upwind_fluxes.emplace(_face_info->id(), current_upwind_flux.value());
104  mooseAssert(pr.second,
105  "Insertion should have happened. If it did not it means you are overwriting some "
106  "other face's flux!");
107  // Swap back
109 
110  const auto old_upwind_flux = getOldFlux(/*upwind=*/true);
111  const auto old_ho_flux = getOldFlux(/*upwind=*/false);
112 
113  return _ho_implicit_fraction * current_ho_flux +
114  (1. - _ho_implicit_fraction) * (old_ho_flux + current_upwind_flux - old_upwind_flux);
115 }
PCNSFVKTDC(const InputParameters &params)
Definition: PCNSFVKTDC.C:32
static InputParameters validParams()
Definition: PCNSFVKT.C:20
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
std::unordered_map< dof_id_type, Real > & _old_ho_fluxes
Old high order fluxes.
Definition: PCNSFVKTDC.h:44
const FaceInfo * _face_info
Real getOldFlux(bool upwind) const
Definition: PCNSFVKTDC.C:72
void timestepSetup() override
Definition: PCNSFVKTDC.C:47
std::unique_ptr< Moose::FV::Limiter< ADReal > > _upwind_limiter
Definition: PCNSFVKTDC.h:41
bool onBoundary(const FaceInfo &fi) const
std::unordered_map< dof_id_type, Real > & _old_upwind_fluxes
Definition: PCNSFVKTDC.h:42
virtual ADReal computeQpResidual() override
Definition: PCNSFVKT.C:128
LimiterType
std::unique_ptr< Moose::FV::Limiter< ADReal > > _limiter
The slope limiter we will apply when interpolating from cell centroids to faces.
Definition: PCNSFVKT.h:99
std::unordered_map< dof_id_type, Real > & _current_ho_fluxes
Current high order fluxes.
Definition: PCNSFVKTDC.h:47
void jacobianSetup() override
Definition: PCNSFVKTDC.C:66
Executioner * getExecutioner() const
virtual ADReal computeQpResidual() override
Definition: PCNSFVKTDC.C:86
void residualSetup() override
Definition: PCNSFVKTDC.C:59
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
MooseApp & _app
const Real _ho_implicit_fraction
Definition: PCNSFVKTDC.h:48
dof_id_type id() const
static InputParameters validParams()
Definition: PCNSFVKTDC.C:22
void addClassDescription(const std::string &doc_string)
std::unordered_map< dof_id_type, Real > & _current_upwind_fluxes
Definition: PCNSFVKTDC.h:45
Implements the centered Kurganov-Tadmor discretization of advective fluxes.
Definition: PCNSFVKT.h:29
virtual bool lastSolveConverged() const=0
registerMooseObject("NavierStokesApp", PCNSFVKTDC)
uint8_t dof_id_type