www.mooseframework.org
LineSegmentLevelSetAux.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 
10 #include "LineSegmentLevelSetAux.h"
12 #include "FEProblem.h"
13 
15 
16 template <>
17 InputParameters
19 {
20  InputParameters params = validParams<AuxKernel>();
21  params.addClassDescription(
22  "Auxiliary Kernel that calcuates level set value using line segments' description.");
23  params.addParam<UserObjectName>(
24  "line_segment_cut_set_user_object",
25  "Name of GeometricCutUserObject that gives the line segments information.");
26  return params;
27 }
28 
29 LineSegmentLevelSetAux::LineSegmentLevelSetAux(const InputParameters & parameters)
30  : AuxKernel(parameters)
31 {
32  if (!isNodal())
33  mooseError("LineSegmentLevelSetAux: Aux variable must be nodal variable.");
34 
35  FEProblemBase * fe_problem = dynamic_cast<FEProblemBase *>(&_subproblem);
36 
37  const UserObject * uo = &(
38  fe_problem->getUserObjectBase(getParam<UserObjectName>("line_segment_cut_set_user_object")));
39 
40  if (dynamic_cast<const LineSegmentCutSetUserObject *>(uo) == nullptr)
41  mooseError(
42  "Failed to cast UserObject to LineSegmentCutSetUserObject in LineSegmentLevelSetAux");
43 
44  _linesegment_uo = dynamic_cast<const LineSegmentCutSetUserObject *>(uo);
45 }
46 
47 Real
49 {
50  const int line_cut_data_len = 6;
51 
52  Real min_dist = std::numeric_limits<Real>::max();
53 
54  for (unsigned int i = 0; i < _cut_data.size() / line_cut_data_len; ++i)
55  {
56  Point a = Point(_cut_data[i * line_cut_data_len + 0], _cut_data[i * line_cut_data_len + 1], 0);
57  Point b = Point(_cut_data[i * line_cut_data_len + 2], _cut_data[i * line_cut_data_len + 3], 0);
58 
59  Point c = p - a;
60  Point v = (b - a) / (b - a).norm();
61  Real d = (b - a).norm();
62  Real t = v * c;
63 
64  Real dist;
65  Point nearest_point;
66 
67  if (t < 0)
68  {
69  dist = (p - a).norm();
70  nearest_point = a;
71  }
72  else if (t > d)
73  {
74  dist = (p - b).norm();
75  nearest_point = b;
76  }
77  else
78  {
79  v *= t;
80  dist = (p - a - v).norm();
81  nearest_point = (a + v);
82  }
83 
84  Point p_nearest_point = nearest_point - p;
85 
86  Point normal_ab = Point(-(b - a)(1), (b - a)(0), 0);
87 
88  if (normal_ab * p_nearest_point < 0)
89  dist = -dist;
90 
91  if (std::abs(dist) < std::abs(min_dist))
92  min_dist = dist;
93  }
94 
95  return min_dist;
96 }
97 
98 void
100 {
102  AuxKernel::compute();
103 }
104 
105 Real
107 {
108  return calculateSignedDistance(*_current_node);
109 }
LineSegmentLevelSetAux::LineSegmentLevelSetAux
LineSegmentLevelSetAux(const InputParameters &parameters)
Definition: LineSegmentLevelSetAux.C:29
LineSegmentLevelSetAux::compute
virtual void compute() override
Definition: LineSegmentLevelSetAux.C:99
registerMooseObject
registerMooseObject("MooseApp", LineSegmentLevelSetAux)
LineSegmentCutSetUserObject::getCutData
virtual std::vector< Real > getCutData() const
Get the cut location information.
Definition: LineSegmentCutSetUserObject.h:32
LineSegmentLevelSetAux
Calculate level set values for an interface that is defined by a set of line segments.
Definition: LineSegmentLevelSetAux.h:24
LineSegmentLevelSetAux::_cut_data
std::vector< Real > _cut_data
Store the cut locations.
Definition: LineSegmentLevelSetAux.h:44
LineSegmentCutSetUserObject.h
validParams< LineSegmentLevelSetAux >
InputParameters validParams< LineSegmentLevelSetAux >()
Definition: LineSegmentLevelSetAux.C:18
LineSegmentLevelSetAux::calculateSignedDistance
Real calculateSignedDistance(Point p)
calculate the signed distance value for a given point.
Definition: LineSegmentLevelSetAux.C:48
LineSegmentLevelSetAux.h
LineSegmentLevelSetAux::_linesegment_uo
const LineSegmentCutSetUserObject * _linesegment_uo
Pointer to the LineSegmentCutSetUserObject object.
Definition: LineSegmentLevelSetAux.h:41
LineSegmentLevelSetAux::computeValue
virtual Real computeValue() override
Definition: LineSegmentLevelSetAux.C:106