LCOV - code coverage report
Current view: top level - src/bcs - FunctionPeriodicBoundary.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 30 31 96.8 %
Date: 2026-05-29 20:35:17 Functions: 5 5 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             : // MOOSE includes
      11             : #include "FunctionPeriodicBoundary.h"
      12             : #include "FEProblem.h"
      13             : #include "Function.h"
      14             : #include "MooseMesh.h"
      15             : 
      16             : // A mutex we can acquire to prevent simultaneous ParsedFunction
      17             : // evaluation on multiple threads.  ParsedFunction evaluation is
      18             : // currently not thread-safe.
      19             : Threads::spin_mutex parsed_function_mutex;
      20             : 
      21         126 : FunctionPeriodicBoundary::FunctionPeriodicBoundary(FEProblemBase & feproblem,
      22             :                                                    const std::vector<std::string> & fn_names,
      23         126 :                                                    const std::vector<std::string> & inv_fn_names)
      24             :   : libMesh::PeriodicBoundaryBase(),
      25         252 :     _dim(fn_names.size()),
      26         126 :     _tr(getFunctions(feproblem, fn_names)),
      27         252 :     _inv_tr(getFunctions(feproblem, inv_fn_names))
      28             : {
      29             :   mooseAssert(fn_names.size() == inv_fn_names.size(), "Size mismatch");
      30             : 
      31             :   // Make certain the the dimensions agree
      32         126 :   if (_dim != feproblem.mesh().dimension())
      33           0 :     mooseError("Transform function has to have the same dimension as the problem being solved.");
      34         126 : }
      35             : 
      36         600 : FunctionPeriodicBoundary::FunctionPeriodicBoundary(const FunctionPeriodicBoundary & o,
      37         600 :                                                    TransformationType t /* = FORWARD */)
      38             :   : libMesh::PeriodicBoundaryBase(o),
      39         600 :     _dim(o._dim),
      40         600 :     _tr(t == INVERSE ? o._inv_tr : o._tr),
      41        1200 :     _inv_tr(t == INVERSE ? o._tr : o._inv_tr)
      42             : {
      43         600 :   if (t == INVERSE)
      44         240 :     std::swap(myboundary, pairedboundary);
      45         600 : }
      46             : 
      47             : Point
      48       16972 : FunctionPeriodicBoundary::get_corresponding_pos(const Point & pt) const
      49             : {
      50             :   // Force thread-safe evaluation of what could be ParsedFunctions.
      51       16972 :   Threads::spin_mutex::scoped_lock lock(parsed_function_mutex);
      52             : 
      53       16972 :   Point p;
      54       50916 :   for (const auto i : make_range(_dim))
      55             :   {
      56             :     mooseAssert(_tr[i], "Function not provided");
      57       33944 :     p(i) = _tr[i]->value(0.0, pt);
      58             :   }
      59       33944 :   return p;
      60       16972 : }
      61             : 
      62             : std::unique_ptr<libMesh::PeriodicBoundaryBase>
      63         600 : FunctionPeriodicBoundary::clone(TransformationType t) const
      64             : {
      65         600 :   return std::make_unique<FunctionPeriodicBoundary>(*this, t);
      66             : }
      67             : 
      68             : std::array<const Function *, 3>
      69         252 : FunctionPeriodicBoundary::getFunctions(FEProblemBase & problem,
      70             :                                        const std::vector<std::string> & names)
      71             : {
      72             :   std::array<const Function *, 3> functions;
      73        1008 :   for (const auto i : index_range(functions))
      74         756 :     if (names.size() > i)
      75             :     {
      76         504 :       functions[i] = &problem.getFunction(names[i]);
      77         504 :       const_cast<Function *>(functions[i])->initialSetup();
      78             :     }
      79         252 :   return functions;
      80             : }

Generated by: LCOV version 1.14