LCOV - code coverage report
Current view: top level - src/functions - LevelSetOlssonBubble.C (source / functions) Hit Total Coverage
Test: idaholab/moose level_set: #31706 (f8ed4a) with base bb0a08 Lines: 19 27 70.4 %
Date: 2025-11-03 17:25:18 Functions: 4 5 80.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 "LevelSetOlssonBubble.h"
      12             : 
      13             : registerMooseObject("LevelSetApp", LevelSetOlssonBubble);
      14             : 
      15             : InputParameters
      16         229 : LevelSetOlssonBubble::validParams()
      17             : {
      18         229 :   InputParameters params = Function::validParams();
      19         229 :   params.addClassDescription("Implementation of 'bubble' ranging from 0 to 1.");
      20         229 :   params.addParam<RealVectorValue>(
      21         229 :       "center", RealVectorValue(0.5, 0.5, 0), "The center of the bubble.");
      22         458 :   params.addParam<Real>("radius", 0.15, "The radius of the bubble.");
      23         458 :   params.addParam<Real>("epsilon", 0.01, "The interface thickness.");
      24         229 :   return params;
      25           0 : }
      26             : 
      27         131 : LevelSetOlssonBubble::LevelSetOlssonBubble(const InputParameters & parameters)
      28             :   : Function(parameters),
      29         131 :     _center(getParam<RealVectorValue>("center")),
      30         262 :     _radius(getParam<Real>("radius")),
      31         393 :     _epsilon(getParam<Real>("epsilon"))
      32             : {
      33         131 : }
      34             : 
      35             : Real
      36     1689690 : LevelSetOlssonBubble::value(Real /*t*/, const Point & p) const
      37             : {
      38     1689690 :   const auto x = ((p - _center).norm() - _radius) / _epsilon;
      39     1689690 :   return 1.0 / (1 + std::exp(x));
      40             : }
      41             : 
      42             : ADReal
      43     2944000 : LevelSetOlssonBubble::value(const ADReal & /*t*/, const ADPoint & p) const
      44             : {
      45             :   using std::exp;
      46     2944000 :   const auto x = ((p - _center).norm() - _radius) / _epsilon;
      47     8832000 :   return 1.0 / (1 + exp(x));
      48             : }
      49             : 
      50             : RealGradient
      51           0 : LevelSetOlssonBubble::gradient(Real /*t*/, const Point & p) const
      52             : {
      53           0 :   Real norm = (p - _center).norm();
      54           0 :   Real g = (norm - _radius) / _epsilon;
      55             :   RealGradient output;
      56             : 
      57             :   Real g_prime;
      58           0 :   for (const auto i : make_range(Moose::dim))
      59             :   {
      60           0 :     g_prime = (p(i) - _center(i)) / (_epsilon * norm);
      61           0 :     output(i) = -(g_prime * std::exp(g)) / ((std::exp(g) + 1) * (std::exp(g) + 1));
      62             :   }
      63           0 :   return output;
      64             : }

Generated by: LCOV version 1.14