v0.14.0
Loading...
Searching...
No Matches
Functions | Variables
segments_distance.cpp File Reference

test segments distance More...

#include <MoFEM.hpp>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "testing mesh cut test\n\n"
 

Detailed Description

test segments distance

Definition in file segments_distance.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 15 of file segments_distance.cpp.

15 {
16
17 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
18
19 try {
20
21 auto run_test = [](auto w, auto v, auto k, auto l, auto expected_result,
22 double expected_t0, double expected_t1) {
24 double t0 = 0, t1 = 0;
25 auto result = Tools::minDistanceFromSegments(w, v, k, l, &t0, &t1);
26 FTensor::Tensor1<const double *, 3> t_w(w, &w[1], &w[2]);
32 t_delta(i) =
33 (t_w(i) + t0 * (t_v(i) - t_w(i))) - (t_k(i) + t1 * (t_l(i) - t_k(i)));
34 std::cout << "Result " << result << " : " << t0 << " " << t1 << " dist "
35 << sqrt(t_delta(i) * t_delta(i)) << std::endl;
36
37 if (result != expected_result)
38 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID, "Expected solution");
39 if (fabs(t0 - expected_t0) > 1e-12)
40 SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
41 "Wrong value of t0 %3.4e != %3.4e", t0, expected_t0);
42 if (fabs(t1 - expected_t1) > 1e-12)
43 SETERRQ2(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
44 "Wrong value of t1 %3.4e != %3.4e", t1, expected_t1);
46 };
47
48 {
49 const double w[] = {-1, 0, 0};
50 const double v[] = {1, 0, 0};
51 const double k[] = {0, -1, 1};
52 const double l[] = {0, 1, 1};
53 CHKERR run_test(w, v, k, l, Tools::SOLUTION_EXIST, 0.5, 0.5);
54 }
55
56 {
57 const double w[] = {-1, 0, 0};
58 const double v[] = {1, 0, 0};
59 const double k[] = {0, 1, 0};
60 const double l[] = {0, 2, 0};
61 CHKERR run_test(w, v, k, l, Tools::SOLUTION_EXIST, 0.5, -1);
62 }
63
64 {
65 const double w[] = {-1, 0, 0};
66 const double v[] = {1, 0, 0};
67 const double k[] = {-1, -1, 0};
68 const double l[] = {1, 1, 0};
69 CHKERR run_test(w, v, k, l, Tools::SOLUTION_EXIST, 0.5, 0.5);
70 }
71
72 {
73 const double w[] = {-1, 0, 1};
74 const double v[] = {1, 0, 1};
75 const double k[] = {-1, -1, 0};
76 const double l[] = {1, 1, 0};
77 CHKERR run_test(w, v, k, l, Tools::SOLUTION_EXIST, 0.5, 0.5);
78 }
79
80 {
81 const double w[] = {0, 0, 0};
82 const double v[] = {0, 0, 0};
83 const double k[] = {0, 0, 0};
84 const double l[] = {0, 1, 0};
85 CHKERR run_test(w, v, k, l, Tools::SEGMENT_ONE_IS_POINT, 0, 0);
86 }
87
88 {
89 const double w[] = {1, 0, 0};
90 const double v[] = {1, 0, 0};
91 const double k[] = {0, 0, 0};
92 const double l[] = {1, 0, 0};
93 CHKERR run_test(w, v, k, l, Tools::SEGMENT_ONE_IS_POINT, 0, 1);
94 }
95
96 {
97 const double w[] = {0, 0, 0};
98 const double v[] = {1, 0, 0};
99 const double k[] = {1, 0, 0};
100 const double l[] = {1, 0, 0};
101 CHKERR run_test(w, v, k, l, Tools::SEGMENT_TWO_IS_POINT, 1, 0);
102 }
103
104 {
105 const double w[] = {-1, 0, 0};
106 const double v[] = {1, 0, 0};
107 const double k[] = {0, 1, 0};
108 const double l[] = {0, 1, 0};
109 CHKERR run_test(w, v, k, l, Tools::SEGMENT_TWO_IS_POINT, 0.5, 0);
110 }
111
112 {
113 const double w[] = {0, 0, 0};
114 const double v[] = {0, 0, 0};
115 const double k[] = {1, 1, -1};
116 const double l[] = {1, 1, 1};
117 CHKERR run_test(w, v, k, l, Tools::SEGMENT_ONE_IS_POINT, 0, 0.5);
118 }
119
120 {
121 const double w[] = {0, 0, 0};
122 const double v[] = {0, 0, 1};
123 const double k[] = {0, 0, 0};
124 const double l[] = {0, 0, 1};
125 CHKERR run_test(w, v, k, l, Tools::NO_SOLUTION, 0, 0);
126 }
127
128 {
129 const double w[] = {1, 0, 0};
130 const double v[] = {1, 0, 1};
131 const double k[] = {0, 0, 0};
132 const double l[] = {0, 0, 1};
133 CHKERR run_test(w, v, k, l, Tools::NO_SOLUTION, 0, 0);
134 }
135
136 {
137 const double w[] = {1, -1, 0};
138 const double v[] = {1, 1, 1};
139 const double k[] = {0, 1, 0};
140 const double l[] = {0, -1, 1};
141 CHKERR run_test(w, v, k, l, Tools::SOLUTION_EXIST, 0.5, 0.5);
142 }
143
144 {
145 const double w[] = {0, 1, 0};
146 const double v[] = {0, 2, 0};
147 const double k[] = {0, 0, 0};
148 const double l[] = {1, 0, 0};
149 CHKERR run_test(w, v, k, l, Tools::SOLUTION_EXIST, -1, 0);
150 }
151
152 {
153 const double w[] = {0, 0, 0};
154 const double v[] = {1, 0, 0};
155 const double k[] = {0, 1, 0};
156 const double l[] = {0, 2, 0};
157 CHKERR run_test(w, v, k, l, Tools::SOLUTION_EXIST, 0, -1);
158 }
159
160
161 }
163
165
166 return 0;
167}
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
FTensor::Index< 'i', SPACE_DIM > i
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'l', 3 > l
FTensor::Index< 'k', 3 > k
double w(const double g, const double t)
static char help[]
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
static SEGMENT_MIN_DISTANCE minDistanceFromSegments(const double *w_ptr, const double *v_ptr, const double *k_ptr, const double *l_ptr, double *const tvw_ptr=nullptr, double *const tlk_ptr=nullptr)
Find points on two segments in closest distance.
Definition: Tools.cpp:471
@ SOLUTION_EXIST
Definition: Tools.hpp:515
@ SEGMENT_ONE_IS_POINT
Definition: Tools.hpp:516
@ SEGMENT_TWO_IS_POINT
Definition: Tools.hpp:517

Variable Documentation

◆ help

char help[] = "testing mesh cut test\n\n"
static

Definition at line 13 of file segments_distance.cpp.