LCOV - code coverage report
Current view: top level - src/bcs - FunctionPeriodicBoundary.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 31 49 63.3 %
Date: 2025-07-17 01:28:37 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         214 : FunctionPeriodicBoundary::FunctionPeriodicBoundary(FEProblemBase & feproblem,
      22         214 :                                                    std::vector<std::string> fn_names)
      23         428 :   : _dim(fn_names.size()),
      24         214 :     _tr_x(&feproblem.getFunction(fn_names[0])),
      25         214 :     _tr_y(_dim > 1 ? &feproblem.getFunction(fn_names[1]) : NULL),
      26         428 :     _tr_z(_dim > 2 ? &feproblem.getFunction(fn_names[2]) : NULL)
      27             : {
      28             : 
      29             :   // Make certain the the dimensions agree
      30         214 :   if (_dim != feproblem.mesh().dimension())
      31           0 :     mooseError("Transform function has to have the same dimension as the problem being solved.");
      32             : 
      33             :   // Initialize the functions (i.e., call thier initialSetup methods)
      34         214 :   init();
      35         214 : }
      36             : 
      37         420 : FunctionPeriodicBoundary::FunctionPeriodicBoundary(const FunctionPeriodicBoundary & o)
      38         420 :   : libMesh::PeriodicBoundaryBase(o), _dim(o._dim), _tr_x(o._tr_x), _tr_y(o._tr_y), _tr_z(o._tr_z)
      39             : {
      40             :   // Initialize the functions (i.e., call thier initialSetup methods)
      41         420 :   init();
      42         420 : }
      43             : 
      44             : Point
      45       18072 : FunctionPeriodicBoundary::get_corresponding_pos(const Point & pt) const
      46             : {
      47             :   // Force thread-safe evaluation of what could be ParsedFunctions.
      48       18072 :   Threads::spin_mutex::scoped_lock lock(parsed_function_mutex);
      49             : 
      50       18072 :   Real t = 0.;
      51       18072 :   Point p;
      52       18072 :   switch (_dim)
      53             :   {
      54           0 :     case 1:
      55           0 :       return Point(_tr_x->value(t, pt));
      56             : 
      57       18072 :     case 2:
      58             :       mooseAssert(_tr_y, "Must provide a function to map y in 2D.");
      59       18072 :       return Point(_tr_x->value(t, pt), _tr_y->value(t, pt));
      60             : 
      61           0 :     case 3:
      62             :       mooseAssert(_tr_y, "Must provide a function to map y in 2D.");
      63             :       mooseAssert(_tr_z, "Must provide a function to map z in 3D.");
      64           0 :       return Point(_tr_x->value(t, pt), _tr_y->value(t, pt), _tr_z->value(t, pt));
      65             : 
      66           0 :     default:
      67           0 :       mooseError("Unsupported dimension");
      68             :       break;
      69             :   }
      70             : 
      71             :   return pt;
      72       18072 : }
      73             : 
      74             : std::unique_ptr<libMesh::PeriodicBoundaryBase>
      75         420 : FunctionPeriodicBoundary::clone(TransformationType t) const
      76             : {
      77         420 :   if (t == INVERSE)
      78           0 :     mooseError("No way to automatically clone() an inverse FunctionPeriodicBoundary object");
      79             : 
      80         420 :   return std::make_unique<FunctionPeriodicBoundary>(*this);
      81             : }
      82             : 
      83             : void
      84         634 : FunctionPeriodicBoundary::init()
      85             : {
      86         634 :   switch (_dim)
      87             :   {
      88           0 :     case 1:
      89           0 :       const_cast<Function *>(_tr_x)->initialSetup();
      90           0 :       break;
      91         634 :     case 2:
      92         634 :       const_cast<Function *>(_tr_x)->initialSetup();
      93         634 :       const_cast<Function *>(_tr_y)->initialSetup();
      94         634 :       break;
      95           0 :     case 3:
      96           0 :       const_cast<Function *>(_tr_x)->initialSetup();
      97           0 :       const_cast<Function *>(_tr_y)->initialSetup();
      98           0 :       const_cast<Function *>(_tr_z)->initialSetup();
      99           0 :       break;
     100           0 :     default:
     101           0 :       mooseError("Unsupported dimension");
     102             :       break;
     103             :   }
     104         634 : }

Generated by: LCOV version 1.14