https://mooseframework.inl.gov
MortarSegmentInfo.C
Go to the documentation of this file.
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.
19 
21  : xi1_a(invalid_xi),
22  xi1_b(invalid_xi),
23  xi2_a(invalid_xi),
24  xi2_b(invalid_xi),
25  secondary_elem(nullptr),
26  primary_elem(nullptr)
27 {
28 }
29 
30 MortarSegmentInfo::MortarSegmentInfo(Real x1a, Real x1b, Real x2a, Real x2b)
31  : xi1_a(x1a), xi1_b(x1b), xi2_a(x2a), xi2_b(x2b), secondary_elem(nullptr), primary_elem(nullptr)
32 {
33 }
34 
35 void
37 {
38  Moose::out << "xi^(1)_a=" << xi1_a << ", xi^(1)_b=" << xi1_b << std::endl;
39  Moose::out << "xi^(2)_a=" << xi2_a << ", xi^(2)_b=" << xi2_b << std::endl;
40  if (secondary_elem)
41  Moose::out << "secondary_elem=" << secondary_elem->id() << std::endl;
42  if (primary_elem)
43  Moose::out << "primary_elem=" << primary_elem->id() << std::endl;
44 }
45 
46 bool
48 {
49  bool b1 = (std::abs(xi1_a) < 1. + TOLERANCE) && (std::abs(xi1_b) < 1. + TOLERANCE);
50  bool b2 = (std::abs(xi2_a) < 1. + TOLERANCE) && (std::abs(xi2_b) < 1. + TOLERANCE);
51 
52  bool xi2a_unset = (std::abs(xi2_a - invalid_xi) < TOLERANCE);
53  bool xi2b_unset = (std::abs(xi2_b - invalid_xi) < TOLERANCE);
54 
55  bool xi2_set = !xi2a_unset && !xi2b_unset;
56 
57  // Both xi^(1) values must be set to have a valid segment.
58  if (!b1)
59  {
60  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  if (std::abs(xi1_a - xi1_b) < TOLERANCE)
68  {
69  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  if (secondary_elem == nullptr)
75  {
76  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  if ((xi2a_unset && !xi2b_unset) || (!xi2a_unset && xi2b_unset))
82  {
83  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  if (!xi2_set && primary_elem != nullptr)
89  {
90  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  if (xi2_set && primary_elem == nullptr)
96  {
97  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  if (xi2_set && (std::abs(xi2_a - xi2_b) < TOLERANCE))
105  {
106  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  if (xi2_set && !b2)
112  {
113  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  return true;
119 }
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:42
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
static const Real invalid_xi
bool isValid() const
Returns true if the current segment is valid, false otherwise.
const Elem * primary_elem
dof_id_type id() const
void print() const
Prints xi values and secondary/primary Elem ids.
const Elem * secondary_elem
MortarSegmentInfo()
Constructor.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real