LCOV - code coverage report
Current view: top level - src/functions - LevelSetOlssonPlane.C (source / functions) Hit Total Coverage
Test: idaholab/moose level_set: #31405 (292dce) with base fef103 Lines: 18 27 66.7 %
Date: 2025-09-04 07:53:58 Functions: 3 4 75.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             : #include "LevelSetOlssonPlane.h"
      11             : #include "libmesh/utility.h"
      12             : 
      13             : registerMooseObject("LevelSetApp", LevelSetOlssonPlane);
      14             : 
      15             : InputParameters
      16          21 : LevelSetOlssonPlane::validParams()
      17             : {
      18          21 :   InputParameters params = Function::validParams();
      19          21 :   params.addClassDescription("Implementation of a level set function to represent a plane.");
      20          42 :   params.addParam<RealVectorValue>("point", RealVectorValue(0, 0, 0), "A point on the plane.");
      21          21 :   params.addParam<RealVectorValue>(
      22          21 :       "normal", RealVectorValue(0, 1, 0), "The normal vector to the plane.");
      23          42 :   params.addParam<Real>("epsilon", 0.01, "The interface thickness.");
      24          21 :   return params;
      25           0 : }
      26             : 
      27          12 : LevelSetOlssonPlane::LevelSetOlssonPlane(const InputParameters & parameters)
      28             :   : Function(parameters),
      29          12 :     _point(getParam<RealVectorValue>("point")),
      30          24 :     _normal(getParam<RealVectorValue>("normal")),
      31          36 :     _epsilon(getParam<Real>("epsilon"))
      32             : {
      33          12 : }
      34             : 
      35             : Real
      36      240000 : LevelSetOlssonPlane::value(Real /*t*/, const Point & p) const
      37             : {
      38      240000 :   const RealVectorValue unit_normal = _normal / _normal.norm();
      39      240000 :   const Real distance_from_orgin = -unit_normal * _point;
      40      240000 :   const Real x = -(unit_normal * p + distance_from_orgin) / _epsilon;
      41             : 
      42      240000 :   return 1.0 / (1 + std::exp(x));
      43             : }
      44             : 
      45             : RealGradient
      46           0 : LevelSetOlssonPlane::gradient(Real /*t*/, const Point & p) const
      47             : {
      48           0 :   const RealVectorValue unit_normal = _normal / _normal.norm();
      49           0 :   const Real distance_from_orgin = -unit_normal * _point;
      50           0 :   const Real x = -(unit_normal * p + distance_from_orgin) / _epsilon;
      51             : 
      52             :   RealGradient output;
      53             :   Real x_prime;
      54             : 
      55           0 :   for (const auto i : make_range(Moose::dim))
      56             :   {
      57           0 :     x_prime = -unit_normal(i) / _epsilon;
      58           0 :     output(i) = -(x_prime * std::exp(x)) / Utility::pow<2>(std::exp(x) + 1);
      59             :   }
      60             : 
      61           0 :   return output;
      62             : }

Generated by: LCOV version 1.14