https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ElemExtrema.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 "ElemExtrema.h"
11
12// libMesh includes
13#include "libmesh/elem.h"
14
15const Point &
17{
18 return elem->point(vertex());
19}
20
21std::unique_ptr<const libMesh::Elem>
23{
24 mooseAssert(atEdge(), "Did not intersect edge");
25 mooseAssert(first < elem->n_vertices(), "Invalid first vertex for given element");
26 mooseAssert(second < elem->n_vertices(), "Invalid second vertex for given element");
27
28 for (const auto e : elem->edge_index_range())
29 if (elem->is_node_on_edge(first, e) && elem->is_node_on_edge(second, e))
30 return elem->build_edge_ptr(e);
31
32 mooseError("Element does not contain vertices in ElemExtrema");
33}
34
35std::string
37{
38 std::stringstream oss;
39 if (atVertex())
40 oss << "at vertex " << vertex();
41 else if (atEdge())
42 oss << "at edge with vertices " << first << " and " << second;
43 else
44 oss << "not at extrema";
45 return oss.str();
46}
47
48bool
49ElemExtrema::isValid(const Elem * const elem, const Point & point) const
50{
51 mooseAssert(first == RayTracingCommon::invalid_vertex || first < elem->n_vertices(),
52 "Invalid first vertex for given element");
53 mooseAssert(second == RayTracingCommon::invalid_vertex || second < elem->n_vertices(),
54 "Invalid second vertex for given element");
55
56 if (atVertex())
57 return vertexPoint(elem).absolute_fuzzy_equals(point);
58 if (elem->dim() == 3 && atEdge())
59 return buildEdge(elem)->contains_point(point);
60
61 return true;
62}
63
64std::ostream &
65operator<<(std::ostream & os, const ElemExtrema & elem_extrema)
66{
67 os << elem_extrema.print();
68 return os;
69}
std::ostream & operator<<(std::ostream &os, const ElemExtrema &elem_extrema)
Definition ElemExtrema.C:65
void mooseError(Args &&... args)
const Point & point(const unsigned int i) const
virtual std::unique_ptr< Elem > build_edge_ptr(const unsigned int i)=0
IntRange< unsigned short > edge_index_range() const
virtual bool is_node_on_edge(const unsigned int n, const unsigned int e) const=0
static const unsigned short invalid_vertex
Identifier for an invalid vertex index.
Helper for defining if at an element's edge, vertex, or neither.
Definition ElemExtrema.h:26
std::unique_ptr< const libMesh::Elem > buildEdge(const Elem *elem) const
Definition ElemExtrema.C:22
bool atEdge() const
Definition ElemExtrema.h:71
unsigned short vertex() const
Definition ElemExtrema.h:96
const Point & vertexPoint(const libMesh::Elem *elem) const
Definition ElemExtrema.C:16
bool isValid(const Elem *const elem, const Point &point) const
Definition ElemExtrema.C:49
bool atVertex() const
Definition ElemExtrema.h:56
std::string print() const
Prints the current state (at edge, at vertex, not at either)
Definition ElemExtrema.C:36