Flow123d  release_2.2.0-914-gf1a3a4f
intersectionLocal.cpp
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file intersectionLocal.cpp
15  * @brief
16  */
17 
18 #include <iostream>
19 #include <algorithm>
20 #include <stdio.h>
21 #include <vector>
22 #include <cmath>
23 #include <numeric>
24 #include <limits>
25 
26 #include "system/exc_common.hh"
28 
29 namespace ngh {
30 
32 
34  return IntersectionLocal::numberInstance++;
35 }
36 
37 bool eps_double_equal(double a, double b) {
38  return fabs(a-b) < numeric_limits<double>::epsilon();
39 }
40 
42  if (! equal (IP.coord1.begin(), IP.coord1.end(), el1_coord().begin(), eps_double_equal)) return false;
43  if (! equal (IP.coord2.begin(), IP.coord2.end(), el2_coord().begin(), eps_double_equal)) return false;
44  return true;
45 }
46 
48  if (! (A1.el1_coord().size() == 1 && A2.el1_coord().size() == 1 ) ) {
49  THROW( ExcAssertMsg() << EI_Message( "Interpolation of IntersectionPoints with non line first element.") );
50  }
51  if (! (A1.el2_coord().size() == A2.el2_coord().size()) ) {
52  THROW( ExcAssertMsg() << EI_Message( "Interpolation of IntersectionPoints with non matching second element type.") );
53  }
54  std::vector<double> el2_coord(A1.el2_coord().size());
55  for(unsigned int i = 0; i < el2_coord.size(); ++i) {
56  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];
57  }
58  return new IntersectionPoint(std::vector<double>(1,t), el2_coord);
59 }
60 
62 : type(i_type)
63 {
64  id = generateId();
65 }
66 
67 
69  i_points.push_back(new IntersectionPoint(coordin1, coordin2));
70 }
71 
73  i_points.push_back(InPoint);
74 }
75 
76 void IntersectionLocal::print(FILE *out_file) {
77  int size_0 = i_points.size();
78  fprintf(out_file," %d", size_0); //pocet bodu pruniku N
79 
80  // cyklus pres body pruniku
82  i_point != i_points.end();++i_point) {
83 
84  // pocet lokalnich souradnic 1. elementu a jejich vypis
85  int size_1 = (*i_point)->coord1.size();
86  fprintf(out_file, " %d", size_1);
87  for(std::vector<double>::iterator l_coord = (*i_point)->coord1.begin();
88  l_coord != (*i_point)->coord1.end();++l_coord) {
89  float f_1 = *l_coord;
90  fprintf(out_file, " %1.7e", f_1);
91  }
92 
93  // pocet lokalnich souradnic 2. elementu a jejich vypis
94  int size_2 = (*i_point)->coord2.size();
95  fprintf(out_file, " %d", size_2);
96  for(std::vector<double>::iterator l_coord = (*i_point)->coord2.begin();
97  l_coord != (*i_point)->coord2.end();++l_coord) {
98  float f_2 = *l_coord;
99  fprintf(out_file, " %1.7e", f_2);
100  }
101  }
102 }
103 
106  i_point != i_points.end();++i_point) {
107  delete *i_point;
108  }
109 }
110 
111 } //namespace ngh
Definition: abscissa.h:25
bool eps_double_equal(double a, double b)
std::vector< double > coord1
void print(FILE *out_file)
IntersectionLocal(IntersectionType i_type)
const std::vector< double > & el2_coord() const
FMT_FUNC int fprintf(std::ostream &os, CStringRef format, ArgList args)
Definition: ostream.cc:56
void add_local_coord(const std::vector< double > &coordin1, const std::vector< double > &coordin2)
std::vector< double > coord2
void add_local_point(IntersectionPoint *InPoint)
const std::vector< double > & el1_coord() const
std::vector< IntersectionPoint * > i_points
const double epsilon
Definition: mathfce.h:23
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
IntersectionPoint * interpolate(const IntersectionPoint &A1, const IntersectionPoint &A2, double t)
bool operator==(const IntersectionPoint &)