LCOV - code coverage report
Current view: top level - src/constraints - MortarSegmentInfo.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 8 42 19.0 %
Date: 2025-07-17 01:28:37 Functions: 1 4 25.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 "MortarSegmentInfo.h"
      11             : #include "MooseError.h"
      12             : 
      13             : #include "libmesh/elem.h"
      14             : 
      15             : using namespace libMesh;
      16             : 
      17             : // Initialize constant static members.
      18             : const Real MortarSegmentInfo::invalid_xi = 99;
      19             : 
      20      104371 : MortarSegmentInfo::MortarSegmentInfo()
      21      104371 :   : xi1_a(invalid_xi),
      22      104371 :     xi1_b(invalid_xi),
      23      104371 :     xi2_a(invalid_xi),
      24      104371 :     xi2_b(invalid_xi),
      25      104371 :     secondary_elem(nullptr),
      26      104371 :     primary_elem(nullptr)
      27             : {
      28      104371 : }
      29             : 
      30           0 : MortarSegmentInfo::MortarSegmentInfo(Real x1a, Real x1b, Real x2a, Real x2b)
      31           0 :   : xi1_a(x1a), xi1_b(x1b), xi2_a(x2a), xi2_b(x2b), secondary_elem(nullptr), primary_elem(nullptr)
      32             : {
      33           0 : }
      34             : 
      35             : void
      36           0 : MortarSegmentInfo::print() const
      37             : {
      38           0 :   Moose::out << "xi^(1)_a=" << xi1_a << ", xi^(1)_b=" << xi1_b << std::endl;
      39           0 :   Moose::out << "xi^(2)_a=" << xi2_a << ", xi^(2)_b=" << xi2_b << std::endl;
      40           0 :   if (secondary_elem)
      41           0 :     Moose::out << "secondary_elem=" << secondary_elem->id() << std::endl;
      42           0 :   if (primary_elem)
      43           0 :     Moose::out << "primary_elem=" << primary_elem->id() << std::endl;
      44           0 : }
      45             : 
      46             : bool
      47           0 : MortarSegmentInfo::isValid() const
      48             : {
      49           0 :   bool b1 = (std::abs(xi1_a) < 1. + TOLERANCE) && (std::abs(xi1_b) < 1. + TOLERANCE);
      50           0 :   bool b2 = (std::abs(xi2_a) < 1. + TOLERANCE) && (std::abs(xi2_b) < 1. + TOLERANCE);
      51             : 
      52           0 :   bool xi2a_unset = (std::abs(xi2_a - invalid_xi) < TOLERANCE);
      53           0 :   bool xi2b_unset = (std::abs(xi2_b - invalid_xi) < TOLERANCE);
      54             : 
      55           0 :   bool xi2_set = !xi2a_unset && !xi2b_unset;
      56             : 
      57             :   // Both xi^(1) values must be set to have a valid segment.
      58           0 :   if (!b1)
      59             :   {
      60           0 :     mooseError("xi1_a = ", xi1_a, ", xi1_b = ", xi1_b, ", one or both xi^(1) values were not set.");
      61             :     return false;
      62             :   }
      63             : 
      64             :   // We don't allow really short segments (this probably means
      65             :   // something got screwed up and both xi^(1) values got the same
      66             :   // value).
      67           0 :   if (std::abs(xi1_a - xi1_b) < TOLERANCE)
      68             :   {
      69           0 :     mooseError("xi^(1) values too close together.");
      70             :     return false;
      71             :   }
      72             : 
      73             :   // Must have a valid secondary Elem to have a valid segment.
      74           0 :   if (secondary_elem == nullptr)
      75             :   {
      76           0 :     mooseError("Secondary Elem was not set.");
      77             :     return false;
      78             :   }
      79             : 
      80             :   // Either *both* xi^(2) values should be unset or *neither* should be. Anything else is invalid.
      81           0 :   if ((xi2a_unset && !xi2b_unset) || (!xi2a_unset && xi2b_unset))
      82             :   {
      83           0 :     mooseError("One xi^(2) value was set, the other was not set.");
      84             :     return false;
      85             :   }
      86             : 
      87             :   // If both xi^(2) values are unset, then primary_elem should be NULL.
      88           0 :   if (!xi2_set && primary_elem != nullptr)
      89             :   {
      90           0 :     mooseError("Both xi^(2) are unset, therefore primary_elem should be NULL.");
      91             :     return false;
      92             :   }
      93             : 
      94             :   // On the other hand, if both xi^(2) values are unset, then make sure primary_elem is non-NULL.
      95           0 :   if (xi2_set && primary_elem == nullptr)
      96             :   {
      97           0 :     mooseError("Both xi^(2) are set, the primary_elem cannot be NULL.");
      98             :     return false;
      99             :   }
     100             : 
     101             :   // If the xi^(2) values are valid, make sure they don't correspond
     102             :   // to a really short segment, which probably means they got
     103             :   // assigned the same value by accident.
     104           0 :   if (xi2_set && (std::abs(xi2_a - xi2_b) < TOLERANCE))
     105             :   {
     106           0 :     mooseError("xi^(2) are too close together.");
     107             :     return false;
     108             :   }
     109             : 
     110             :   // If both xi^(2) values are set, they should be in the range.
     111           0 :   if (xi2_set && !b2)
     112             :   {
     113           0 :     mooseError("xi^(2) are set, but they are not in the range [-1,1].");
     114             :     return false;
     115             :   }
     116             : 
     117             :   // If we made it here, we're valid.
     118           0 :   return true;
     119             : }

Generated by: LCOV version 1.14