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