Flow123d
intersectionLocal.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <algorithm>
3 #include <stdio.h>
4 #include <vector>
5 #include <cmath>
6 #include <numeric>
7 #include <limits>
8 
9 #include "system/exc_common.hh"
11 //#include "mesh/ngh/include/config.h"
12 
14 
17 }
18 
19 bool eps_double_equal(double a, double b) {
20  return fabs(a-b) < numeric_limits<double>::epsilon();
21 }
22 
24  /*cout<< "IP.coord1.begin().size: "<< IP.coord1.size() << endl;
25  cout<< "el1_coord().size: "<< el1_coord().size() << endl;
26  cout<< "IP.coord2.begin().size: "<< IP.coord2.size() << endl;
27  cout<< "el2_coord().size: "<< el2_coord().size() << endl;
28 */
29  if (! equal (IP.coord1.begin(), IP.coord1.end(), el1_coord().begin(), eps_double_equal)) return false;
30  if (! equal (IP.coord2.begin(), IP.coord2.end(), el2_coord().begin(), eps_double_equal)) return false;
31  return true;
32 }
33 
35  if (! (A1.el1_coord().size() == 1 && A2.el1_coord().size() == 1 ) ) {
36  THROW( ExcAssertMsg() << EI_Message( "Interpolation of IntersectionPoints with non line first element.") );
37  }
38  if (! (A1.el2_coord().size() == A2.el2_coord().size()) ) {
39  THROW( ExcAssertMsg() << EI_Message( "Interpolation of IntersectionPoints with non matching second element type.") );
40  }
41  std::vector<double> el2_coord(A1.el2_coord().size());
42  for(unsigned int i = 0; i < el2_coord.size(); ++i) {
43  el2_coord[i] = ((t - A1.el1_coord()[0]) / (A2.el1_coord()[0] - A1.el1_coord()[0])) * (A2.el2_coord()[i] - A1.el2_coord()[i]) + A1.el2_coord()[i];
44  }
45  return new IntersectionPoint(std::vector<double>(1,t), el2_coord);
46 }
47 
49 : type(i_type)
50 {
51  id = generateId();
52 }
53 
54 /*void IntersectionLocal::set_elements(TElement *elem1, TElement *elem2) {
55  bool pom1 = false;
56  bool pom2 = false;
57 
58  // cyklus pres body pruniku => pres vsechny body v poli i_points
59  for (std::vector<IntersectionPoint *>::iterator i_point = i_points.begin();
60  i_point!= i_points.end();++i_point) {
61  // TEST SHODY POCTU SOURADNIC S POCTEM STRAN 1.ELEMENTU
62  if ((*i_point)->coord1.size() == elem1->GetNSides() - 1) { //pocet lokal. souradnic 1.elementu
63  pom1 = true;
64  }
65  else {
66  pom1 = false;
67  //cout<<"Elem1 - pocet souradnic: "<< (*i_point)->coord1.size() << endl;
68  //cout<<"Coord1: "<< (*i_point)->coord1[0] << endl;
69  //cout<<"Coord1: "<< (*i_point)->coord1[1] << endl;
70  //cout<<"Elem2 - pocet stran: "<< elem1->GetNSides() << endl;
71  }
72  // TEST SHODY POCTU SOURADNIC S POCTEM STRAN 2.ELEMENTU
73  if ((*i_point)->coord2.size()==elem2->GetNSides() - 1) { //pocet lokal. souradnic 2.elementu
74  pom2 = true;
75  }
76  else {
77  pom2 = false;
78  //cout<<"Elem1 - pocet souradnic: "<< (*i_point)->coord2.size() << endl;
79  //cout<<"Coord2: "<< (*i_point)->coord2[0] << endl;
80  //cout<<"Coord2: "<< (*i_point)->coord2[1] << endl;
81  //cout<<"Elem2 - pocet stran: "<< elem2->GetNSides() << endl;
82  }
83  }
84  if ((pom1==true) && (pom2==true)) {
85  ele1 = elem1;
86  ele2 = elem2;
87  }
88  else {
89  THROW( ExcAssertMsg() << EI_Message( "Invalid size of the vector local coordinates.") );
90  }
91 }*/
92 
94  i_points.push_back(new IntersectionPoint(coordin1, coordin2));
95 }
96 
98  i_points.push_back(InPoint);
99  //i_points.push_back(IntersectionPoint::IntersectionPoint (InPoint));
100 }
101 
102 void IntersectionLocal::print(FILE *out_file) {
103  int size_0 = i_points.size();
104  fprintf(out_file," %d", size_0); //pocet bodu pruniku N
105 
106  // cyklus pres body pruniku
108  i_point != i_points.end();++i_point) {
109 
110  // pocet lokalnich souradnic 1. elementu a jejich vypis
111  int size_1 = (*i_point)->coord1.size();
112  fprintf(out_file, " %d", size_1);
113  for(std::vector<double>::iterator l_coord = (*i_point)->coord1.begin();
114  l_coord != (*i_point)->coord1.end();++l_coord) {
115  float f_1 = *l_coord;
116  //fprintf(out_file, " %f", f_1);
117  fprintf(out_file, " %1.7e", f_1);
118  }
119 
120  // pocet lokalnich souradnic 2. elementu a jejich vypis
121  int size_2 = (*i_point)->coord2.size();
122  fprintf(out_file, " %d", size_2);
123  for(std::vector<double>::iterator l_coord = (*i_point)->coord2.begin();
124  l_coord != (*i_point)->coord2.end();++l_coord) {
125  float f_2 = *l_coord;
126  //fprintf(out_file, " %f", f_2);
127  fprintf(out_file, " %1.7e", f_2);
128  }
129  }
130 }
131 
132 /*void IntersectionLocal::AddNewLocalcoord(std::vector<IntersectionPoint> &IntersectionPoint) {
133  i_points.push_back(); // vlozi novy prvek na konec vektoru i_points
134  i_points.pop_back(); // odeberu posledni prvek vektoru i_points
135 }*/
136 
139  i_point != i_points.end();++i_point) {
140  delete *i_point;
141  }
142 }