LCOV - code coverage report
Current view: top level - src/userobjects - EllipseCutUserObject.C (source / functions) Hit Total Coverage
Test: idaholab/moose xfem: #31405 (292dce) with base fef103 Lines: 34 43 79.1 %
Date: 2025-09-04 07:58:55 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             : #include "EllipseCutUserObject.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseError.h"
      14             : 
      15             : // XFEM includes
      16             : #include "XFEMFuncs.h"
      17             : 
      18             : registerMooseObject("XFEMApp", EllipseCutUserObject);
      19             : 
      20             : InputParameters
      21           8 : EllipseCutUserObject::validParams()
      22             : {
      23             :   // Get input parameters from parent class
      24           8 :   InputParameters params = GeometricCut3DUserObject::validParams();
      25             : 
      26             :   // Add required parameters
      27          16 :   params.addRequiredParam<std::vector<Real>>("cut_data",
      28             :                                              "Vector of Real values providing cut information");
      29             :   // Class description
      30           8 :   params.addClassDescription("Creates a UserObject for elliptical cuts on 3D meshes for XFEM");
      31             :   // Return the parameters
      32           8 :   return params;
      33           0 : }
      34             : 
      35           4 : EllipseCutUserObject::EllipseCutUserObject(const InputParameters & parameters)
      36          12 :   : GeometricCut3DUserObject(parameters), _cut_data(getParam<std::vector<Real>>("cut_data"))
      37             : {
      38             :   // Set up constant parameters
      39             :   const int cut_data_len = 9;
      40             : 
      41             :   // Throw error if length of cut_data is incorrect
      42           4 :   if (_cut_data.size() != cut_data_len)
      43           0 :     mooseError("Length of EllipseCutUserObject cut_data must be 9");
      44             : 
      45             :   // Assign cut_data to vars used to construct cuts
      46           4 :   _center = Point(_cut_data[0], _cut_data[1], _cut_data[2]);
      47           4 :   _vertices.push_back(Point(_cut_data[3], _cut_data[4], _cut_data[5]));
      48           4 :   _vertices.push_back(Point(_cut_data[6], _cut_data[7], _cut_data[8]));
      49             : 
      50             :   std::pair<Point, Point> rays = std::make_pair(_vertices[0] - _center, _vertices[1] - _center);
      51             : 
      52           4 :   if (std::abs(rays.first * rays.second) > 1e-6)
      53           0 :     mooseError(
      54             :         "EllipseCutUserObject only works on an elliptic cut. Users should provide two points at "
      55             :         "the long and short axis.");
      56             : 
      57           4 :   _normal = rays.first.cross(rays.second);
      58           4 :   Xfem::normalizePoint(_normal);
      59             : 
      60             :   std::pair<Real, Real> ray_radii =
      61           4 :       std::make_pair(std::sqrt(rays.first.norm_sq()), std::sqrt(rays.second.norm_sq()));
      62             : 
      63             :   // Determine which the long and short axes
      64           4 :   if (ray_radii.first > ray_radii.second)
      65             :   {
      66           0 :     _unit_vec1 = rays.first;
      67           0 :     _unit_vec2 = rays.second;
      68           0 :     _long_axis = ray_radii.first;
      69           0 :     _short_axis = ray_radii.second;
      70             :   }
      71             :   else
      72             :   {
      73           4 :     _unit_vec1 = rays.second;
      74           4 :     _unit_vec2 = rays.first;
      75           4 :     _long_axis = ray_radii.second;
      76           4 :     _short_axis = ray_radii.first;
      77             :   }
      78             : 
      79           4 :   Xfem::normalizePoint(_unit_vec1);
      80           4 :   Xfem::normalizePoint(_unit_vec2);
      81           4 : }
      82             : 
      83             : bool
      84        6264 : EllipseCutUserObject::isInsideCutPlane(Point p) const
      85             : {
      86             :   Point ray = p - _center;
      87        6264 :   if (std::abs(ray * _normal) < 1e-6)
      88             :   {
      89             :     std::pair<Real, Real> xy_loc = std::make_pair(ray * _unit_vec1, ray * _unit_vec2);
      90             : 
      91        6264 :     if (std::sqrt(xy_loc.first * xy_loc.first / (_long_axis * _long_axis) +
      92        6264 :                   xy_loc.second * xy_loc.second / (_short_axis * _short_axis)) < 1)
      93             :       return true;
      94             :   }
      95             :   return false;
      96             : }
      97             : 
      98             : const std::vector<Point>
      99           4 : EllipseCutUserObject::getCrackFrontPoints(unsigned int number_crack_front_points) const
     100             : {
     101           4 :   std::vector<Point> crack_front_points(number_crack_front_points);
     102          52 :   for (unsigned int i = 0; i < number_crack_front_points; ++i)
     103             :   {
     104          48 :     Real theta = 2.0 * libMesh::pi / number_crack_front_points * i;
     105          48 :     crack_front_points[i] = _center + _long_axis * std::sin(theta) * _unit_vec1 +
     106          48 :                             _short_axis * std::cos(theta) * _unit_vec2;
     107             :   }
     108           4 :   return crack_front_points;
     109             : }
     110             : 
     111             : const std::vector<RealVectorValue>
     112           0 : EllipseCutUserObject::getCrackPlaneNormals(unsigned int /*num_crack_front_points*/) const
     113             : {
     114           0 :   mooseError("getCrackPlaneNormals() is not implemented for this object.");
     115             : }

Generated by: LCOV version 1.14