www.mooseframework.org
XFEMCrackGrowthIncrement2DCut.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
11 #include "XFEMFuncs.h"
12 #include "GeometricCutUserObject.h"
13 #include "MooseError.h"
14 #include "libmesh/string_to_enum.h"
15 
17  Real x0, Real y0, Real x1, Real y1, Real t0, Real t1)
18  : _time_range(std::make_pair(t0, t1)),
19  _cut_line_endpoints(std::make_pair(Point(x0, y0, 0.0), Point(x1, y1, 0.0)))
20 {
21 }
22 
23 Real
25 {
26  Real fraction = 0.0;
27  if (time >= _time_range.first)
28  {
29  if (time >= _time_range.second)
30  fraction = 1.0;
31  else
32  fraction = (time - _time_range.first) / (_time_range.second - _time_range.first);
33  }
34  return fraction;
35 }
36 
37 bool
39  const Elem * elem, std::vector<CutEdgeForCrackGrowthIncr> & cut_edges, Real time)
40 {
41  bool cut_elem = false;
42 
43  Real fraction = cutCompletionFraction(time);
44 
45  if (fraction > 0.0)
46  {
47  unsigned int n_sides = elem->n_sides();
48 
49  for (unsigned int i = 0; i < n_sides; ++i)
50  {
51  // This returns the lowest-order type of side, which should always
52  // be an EDGE2 here because this class is for 2D only.
53  std::unique_ptr<const Elem> curr_side = elem->side_ptr(i);
54  if (curr_side->type() != EDGE2)
55  mooseError("In cutElementByGeometry element side must be EDGE2, but type is: ",
56  libMesh::Utility::enum_to_string(curr_side->type()),
57  " base element type is: ",
58  libMesh::Utility::enum_to_string(elem->type()));
59 
60  const Node * node1 = curr_side->node_ptr(0);
61  const Node * node2 = curr_side->node_ptr(1);
62  Real seg_int_frac = 0.0;
63 
64  if (IntersectSegmentWithCutLine(*node1, *node2, _cut_line_endpoints, fraction, seg_int_frac))
65  {
66  cut_elem = true;
68  mycut._id1 = node1->id();
69  mycut._id2 = node2->id();
70  mycut._distance = seg_int_frac;
71  mycut._host_side_id = i;
72  cut_edges.push_back(mycut);
73  }
74  }
75  }
76  return cut_elem;
77 }
78 
79 bool
81  const Point & segment_point1,
82  const Point & segment_point2,
83  const std::pair<Point, Point> & cutting_line_points,
84  const Real & cutting_line_fraction,
85  Real & segment_intersection_fraction)
86 {
87  // Use the algorithm described here to determine whether a line segment is intersected
88  // by a cutting line, and to compute the fraction along that line where the intersection
89  // occurs:
90  // http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
91 
92  bool cut_segment = false;
93  Point seg_dir = segment_point2 - segment_point1;
94  Point cut_dir = cutting_line_points.second - cutting_line_points.first;
95  Point cut_start_to_seg_start = segment_point1 - cutting_line_points.first;
96 
97  Real cut_dir_cross_seg_dir = crossProduct2D(cut_dir, seg_dir);
98 
99  if (std::abs(cut_dir_cross_seg_dir) > Xfem::tol)
100  {
101  // Fraction of the distance along the cutting segment where it intersects the edge segment
102  Real cut_int_frac = crossProduct2D(cut_start_to_seg_start, seg_dir) / cut_dir_cross_seg_dir;
103 
104  if (cut_int_frac >= 0.0 && cut_int_frac <= cutting_line_fraction)
105  { // Cutting segment intersects the line of the edge segment, but the intersection point may be
106  // outside the segment
107  Real int_frac = crossProduct2D(cut_start_to_seg_start, cut_dir) / cut_dir_cross_seg_dir;
108  if (int_frac >= 0.0 &&
109  int_frac <= 1.0) // TODO: revisit end cases for intersections with corners
110  {
111  cut_segment = true;
112  segment_intersection_fraction = int_frac;
113  }
114  }
115  }
116  return cut_segment;
117 }
118 
119 Real
120 XFEMCrackGrowthIncrement2DCut::crossProduct2D(const Point & point_a, const Point & point_b)
121 {
122  return (point_a(0) * point_b(1) - point_b(0) * point_a(1));
123 }
XFEMCrackGrowthIncrement2DCut::_cut_line_endpoints
const std::pair< Point, Point > _cut_line_endpoints
Definition: XFEMCrackGrowthIncrement2DCut.h:49
XFEMCrackGrowthIncrement2DCut::crossProduct2D
Real crossProduct2D(const Point &point_a, const Point &point_b)
Definition: XFEMCrackGrowthIncrement2DCut.C:120
CutEdgeForCrackGrowthIncr
Definition: XFEMCrackGrowthIncrement2DCut.h:18
GeometricCutUserObject.h
XFEMCrackGrowthIncrement2DCut.h
XFEMFuncs.h
XFEMCrackGrowthIncrement2DCut::XFEMCrackGrowthIncrement2DCut
XFEMCrackGrowthIncrement2DCut(Real x0, Real y0, Real x1, Real y1, Real t0, Real t1)
Definition: XFEMCrackGrowthIncrement2DCut.C:16
XFEMCrackGrowthIncrement2DCut::cutCompletionFraction
Real cutCompletionFraction(Real time)
Definition: XFEMCrackGrowthIncrement2DCut.C:24
CutEdgeForCrackGrowthIncr::_distance
Real _distance
Definition: XFEMCrackGrowthIncrement2DCut.h:22
Xfem::tol
static const double tol
Definition: XFEMFuncs.h:20
CutEdgeForCrackGrowthIncr::_id2
unsigned int _id2
Definition: XFEMCrackGrowthIncrement2DCut.h:21
XFEMCrackGrowthIncrement2DCut::cutElementByCrackGrowthIncrement
virtual bool cutElementByCrackGrowthIncrement(const Elem *elem, std::vector< CutEdgeForCrackGrowthIncr > &cut_edges, Real time)
Definition: XFEMCrackGrowthIncrement2DCut.C:38
CutEdgeForCrackGrowthIncr::_host_side_id
unsigned int _host_side_id
Definition: XFEMCrackGrowthIncrement2DCut.h:23
XFEMCrackGrowthIncrement2DCut::IntersectSegmentWithCutLine
bool IntersectSegmentWithCutLine(const Point &segment_point1, const Point &segment_point2, const std::pair< Point, Point > &cutting_line_points, const Real &cutting_line_fraction, Real &segment_intersection_fraction)
Definition: XFEMCrackGrowthIncrement2DCut.C:80
CutEdgeForCrackGrowthIncr::_id1
unsigned int _id1
Definition: XFEMCrackGrowthIncrement2DCut.h:20
XFEMCrackGrowthIncrement2DCut::_time_range
const std::pair< Real, Real > _time_range
Definition: XFEMCrackGrowthIncrement2DCut.h:46