https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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// Initialize constant static members.
17
19 : xi1_a(invalid_xi),
20 xi1_b(invalid_xi),
21 xi2_a(invalid_xi),
22 xi2_b(invalid_xi),
23 secondary_elem(nullptr),
24 primary_elem(nullptr)
25{
26}
27
28MortarSegmentInfo::MortarSegmentInfo(Real x1a, Real x1b, Real x2a, Real x2b)
29 : xi1_a(x1a), xi1_b(x1b), xi2_a(x2a), xi2_b(x2b), secondary_elem(nullptr), primary_elem(nullptr)
30{
31}
32
33void
35{
36 Moose::out << "xi^(1)_a=" << xi1_a << ", xi^(1)_b=" << xi1_b << std::endl;
37 Moose::out << "xi^(2)_a=" << xi2_a << ", xi^(2)_b=" << xi2_b << std::endl;
39 Moose::out << "secondary_elem=" << secondary_elem->id() << std::endl;
40 if (primary_elem)
41 Moose::out << "primary_elem=" << primary_elem->id() << std::endl;
42}
43
44bool
46{
47 bool b1 = (std::abs(xi1_a) < 1. + TOLERANCE) && (std::abs(xi1_b) < 1. + TOLERANCE);
48 bool b2 = (std::abs(xi2_a) < 1. + TOLERANCE) && (std::abs(xi2_b) < 1. + TOLERANCE);
49
50 bool xi2a_unset = (std::abs(xi2_a - invalid_xi) < TOLERANCE);
51 bool xi2b_unset = (std::abs(xi2_b - invalid_xi) < TOLERANCE);
52
53 bool xi2_set = !xi2a_unset && !xi2b_unset;
54
55 // Both xi^(1) values must be set to have a valid segment.
56 if (!b1)
57 {
58 mooseError("xi1_a = ", xi1_a, ", xi1_b = ", xi1_b, ", one or both xi^(1) values were not set.");
59 return false;
60 }
61
62 // We don't allow really short segments (this probably means
63 // something got screwed up and both xi^(1) values got the same
64 // value).
65 if (std::abs(xi1_a - xi1_b) < TOLERANCE)
66 {
67 mooseError("xi^(1) values too close together.");
68 return false;
69 }
70
71 // Must have a valid secondary Elem to have a valid segment.
72 if (secondary_elem == nullptr)
73 {
74 mooseError("Secondary Elem was not set.");
75 return false;
76 }
77
78 // Either *both* xi^(2) values should be unset or *neither* should be. Anything else is invalid.
79 if ((xi2a_unset && !xi2b_unset) || (!xi2a_unset && xi2b_unset))
80 {
81 mooseError("One xi^(2) value was set, the other was not set.");
82 return false;
83 }
84
85 // If both xi^(2) values are unset, then primary_elem should be NULL.
86 if (!xi2_set && primary_elem != nullptr)
87 {
88 mooseError("Both xi^(2) are unset, therefore primary_elem should be NULL.");
89 return false;
90 }
91
92 // On the other hand, if both xi^(2) values are unset, then make sure primary_elem is non-NULL.
93 if (xi2_set && primary_elem == nullptr)
94 {
95 mooseError("Both xi^(2) are set, the primary_elem cannot be NULL.");
96 return false;
97 }
98
99 // If the xi^(2) values are valid, make sure they don't correspond
100 // to a really short segment, which probably means they got
101 // assigned the same value by accident.
102 if (xi2_set && (std::abs(xi2_a - xi2_b) < TOLERANCE))
103 {
104 mooseError("xi^(2) are too close together.");
105 return false;
106 }
107
108 // If both xi^(2) values are set, they should be in the range.
109 if (xi2_set && !b2)
110 {
111 mooseError("xi^(2) are set, but they are not in the range [-1,1].");
112 return false;
113 }
114
115 // If we made it here, we're valid.
116 return true;
117}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Elem * primary_elem
void print() const
Prints xi values and secondary/primary Elem ids.
bool isValid() const
Returns true if the current segment is valid, false otherwise.
static const Real invalid_xi
MortarSegmentInfo()
Constructor.
const Elem * secondary_elem