LCOV - code coverage report
Current view: top level - src/variables - MooseVariableDataLinearFV.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 64 69 92.8 %
Date: 2025-07-17 01:28:37 Functions: 7 9 77.8 %
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 "MooseVariableDataLinearFV.h"
      11             : #include "MooseVariableDataFV.h"
      12             : #include "MooseVariableField.h"
      13             : #include "Assembly.h"
      14             : #include "MooseError.h"
      15             : #include "DisplacedSystem.h"
      16             : #include "TimeIntegrator.h"
      17             : #include "MooseVariableFV.h"
      18             : #include "MooseTypes.h"
      19             : #include "MooseMesh.h"
      20             : #include "Attributes.h"
      21             : #include "FVDirichletBCBase.h"
      22             : #include "SubProblem.h"
      23             : #include "FVKernel.h"
      24             : #include "ADUtils.h"
      25             : #include "MooseLinearVariableFV.h"
      26             : 
      27             : #include "libmesh/quadrature.h"
      28             : #include "libmesh/fe_base.h"
      29             : #include "libmesh/system.h"
      30             : #include "libmesh/type_n_tensor.h"
      31             : 
      32             : template <typename OutputType>
      33        2622 : MooseVariableDataLinearFV<OutputType>::MooseVariableDataLinearFV(
      34             :     const MooseLinearVariableFV<OutputType> & var,
      35             :     SystemBase & sys,
      36             :     THREAD_ID tid,
      37             :     Moose::ElementType element_type,
      38             :     const Elem * const & elem)
      39             :   : MooseVariableDataBase<OutputType>(var, sys, tid),
      40        2622 :     _var(var),
      41        5244 :     _fe_type(_var.feType()),
      42        2622 :     _var_num(_var.number()),
      43        2622 :     _assembly(_subproblem.assembly(_tid, var.kind() == Moose::VAR_SOLVER ? sys.number() : 0)),
      44        2622 :     _element_type(element_type),
      45        2622 :     _time_integrator(_sys.queryTimeIntegrator(_var_num)),
      46        2622 :     _elem(elem),
      47        2622 :     _displaced(dynamic_cast<const DisplacedSystem *>(&_sys) ? true : false),
      48        5244 :     _qrule(nullptr)
      49             : {
      50        2622 : }
      51             : 
      52             : template <typename OutputType>
      53             : void
      54      631522 : MooseVariableDataLinearFV<OutputType>::setGeometry(Moose::GeometryType gm_type)
      55             : {
      56      631522 :   switch (gm_type)
      57             :   {
      58      631182 :     case Moose::Volume:
      59             :     {
      60      631182 :       _qrule = _assembly.qRule();
      61             :       // TODO: set integration multiplier to cell volume
      62      631182 :       break;
      63             :     }
      64         340 :     case Moose::Face:
      65             :     {
      66         340 :       _qrule = _assembly.qRuleFace();
      67             :       // TODO: set integration multiplier to face area
      68         340 :       break;
      69             :     }
      70             :   }
      71      631522 : }
      72             : 
      73             : template <typename OutputType>
      74             : void
      75      631522 : MooseVariableDataLinearFV<OutputType>::initializeSolnVars()
      76             : {
      77             :   auto && active_coupleable_matrix_tags =
      78      631522 :       _sys.subproblem().getActiveFEVariableCoupleableMatrixTags(_tid);
      79             :   mooseAssert(_qrule, "We should have a non-null qrule");
      80      631522 :   const auto nqp = _qrule->n_points();
      81             : 
      82     1264052 :   for (auto tag : _required_vector_tags)
      83      632530 :     if (_need_vector_tag_u[tag])
      84             :     {
      85      631618 :       _vector_tag_u[tag].resize(nqp);
      86      631618 :       assignForAllQps(0, _vector_tag_u[tag], nqp);
      87             :     }
      88             : 
      89      632194 :   for (auto tag : active_coupleable_matrix_tags)
      90         672 :     if (_need_matrix_tag_u[tag])
      91             :     {
      92          48 :       _matrix_tag_u[tag].resize(nqp);
      93          48 :       assignForAllQps(0, _matrix_tag_u[tag], nqp);
      94             :     }
      95      631522 : }
      96             : 
      97             : template <typename OutputType>
      98             : const std::vector<dof_id_type> &
      99      631522 : MooseVariableDataLinearFV<OutputType>::initDofIndices()
     100             : {
     101      631522 :   Moose::initDofIndices(*this, *_elem);
     102      631522 :   return _dof_indices;
     103             : }
     104             : 
     105             : template <typename OutputType>
     106             : void
     107      631522 : MooseVariableDataLinearFV<OutputType>::computeValues()
     108             : {
     109      631522 :   initDofIndices();
     110      631522 :   initializeSolnVars();
     111             : 
     112      631522 :   unsigned int num_dofs = _dof_indices.size();
     113             : 
     114      631522 :   if (num_dofs > 0)
     115      536042 :     fetchDoFValues();
     116             :   else
     117             :     // We don't have any dofs. There's nothing to do
     118       95480 :     return;
     119             : 
     120             :   mooseAssert(num_dofs == 1 && _vector_tags_dof_u[_solution_tag].size() == 1,
     121             :               "There should only be one dof per elem for FV variables");
     122             : 
     123      536042 :   const auto nqp = _qrule->n_points();
     124             :   auto && active_coupleable_matrix_tags =
     125      536042 :       _sys.subproblem().getActiveFEVariableCoupleableMatrixTags(_tid);
     126             : 
     127     1072084 :   for (const auto qp : make_range(nqp))
     128             :   {
     129     1073092 :     for (auto tag : _required_vector_tags)
     130      537050 :       if (_need_vector_tag_u[tag])
     131      536138 :         _vector_tag_u[tag][qp] = _vector_tags_dof_u[tag][0];
     132             : 
     133      536714 :     for (auto tag : active_coupleable_matrix_tags)
     134         672 :       if (_need_matrix_tag_u[tag])
     135          48 :         _matrix_tag_u[tag][qp] = _matrix_tags_dof_u[tag][0];
     136             :   }
     137             : }
     138             : 
     139             : template <typename OutputType>
     140             : void
     141         432 : MooseVariableDataLinearFV<OutputType>::setDofValue(const OutputData & value, unsigned int index)
     142             : {
     143             :   mooseAssert(index == 0, "We only ever have one dof value locally");
     144         432 :   _vector_tags_dof_u[_solution_tag][index] = value;
     145         432 :   _has_dof_values = true;
     146             : 
     147         432 :   auto & u = _vector_tag_u[_solution_tag];
     148             :   // Update the qp values as well
     149         864 :   for (const auto qp : index_range(u))
     150         432 :     u[qp] = value;
     151         432 : }
     152             : 
     153             : template <typename OutputType>
     154             : void
     155         144 : MooseVariableDataLinearFV<OutputType>::setDofValues(const DenseVector<OutputData> & values)
     156             : {
     157         144 :   auto & dof_values = _vector_tags_dof_u[_solution_tag];
     158         288 :   for (unsigned int i = 0; i < values.size(); i++)
     159         144 :     dof_values[i] = values(i);
     160         144 :   _has_dof_values = true;
     161         144 : }
     162             : 
     163             : template <typename OutputType>
     164             : void
     165           0 : MooseVariableDataLinearFV<OutputType>::getDofIndices(const Elem * elem,
     166             :                                                      std::vector<dof_id_type> & dof_indices) const
     167             : {
     168           0 :   _dof_map.dof_indices(elem, dof_indices, _var_num);
     169           0 : }
     170             : 
     171             : template <typename OutputType>
     172             : const MooseLinearVariableFV<OutputType> &
     173           0 : MooseVariableDataLinearFV<OutputType>::var() const
     174             : {
     175           0 :   return _var;
     176             : }
     177             : 
     178             : template class MooseVariableDataLinearFV<Real>;
     179             : // TODO: implement vector fv variable support. This will require some template
     180             : // specializations for various member functions in this and the FV variable
     181             : // classes. And then you will need to uncomment out the line below:
     182             : // template class MooseVariableDataLinearFV<RealVectorValue>;

Generated by: LCOV version 1.14