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 2944000 : const auto x = ((p - _center).norm() - _radius) / _epsilon; 46 8832000 : return 1.0 / (1 + std::exp(x)); 47 : } 48 : 49 : RealGradient 50 0 : LevelSetOlssonBubble::gradient(Real /*t*/, const Point & p) const 51 : { 52 0 : Real norm = (p - _center).norm(); 53 0 : Real g = (norm - _radius) / _epsilon; 54 : RealGradient output; 55 : 56 : Real g_prime; 57 0 : for (const auto i : make_range(Moose::dim)) 58 : { 59 0 : g_prime = (p(i) - _center(i)) / (_epsilon * norm); 60 0 : output(i) = -(g_prime * std::exp(g)) / ((std::exp(g) + 1) * (std::exp(g) + 1)); 61 : } 62 0 : return output; 63 : }