Flow123d  release_2.2.0-19-g1279b7e
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 
30 
33 }
34 
35 bool eps_double_equal(double a, double b) {
36  return fabs(a-b) < numeric_limits<double>::epsilon();
37 }
38 
40  if (! equal (IP.coord1.begin(), IP.coord1.end(), el1_coord().begin(), eps_double_equal)) return false;
41  if (! equal (IP.coord2.begin(), IP.coord2.end(), el2_coord().begin(), eps_double_equal)) return false;
42  return true;
43 }
44 
46  if (! (A1.el1_coord().size() == 1 && A2.el1_coord().size() == 1 ) ) {
47  THROW( ExcAssertMsg() << EI_Message( "Interpolation of IntersectionPoints with non line first element.") );
48  }
49  if (! (A1.el2_coord().size() == A2.el2_coord().size()) ) {
50  THROW( ExcAssertMsg() << EI_Message( "Interpolation of IntersectionPoints with non matching second element type.") );
51  }
52  std::vector<double> el2_coord(A1.el2_coord().size());
53  for(unsigned int i = 0; i < el2_coord.size(); ++i) {
54  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];
55  }
56  return new IntersectionPoint(std::vector<double>(1,t), el2_coord);
57 }
58 
60 : type(i_type)
61 {
62  id = generateId();
63 }
64 
65 
67  i_points.push_back(new IntersectionPoint(coordin1, coordin2));
68 }
69 
71  i_points.push_back(InPoint);
72 }
73 
74 void IntersectionLocal::print(FILE *out_file) {
75  int size_0 = i_points.size();
76  fprintf(out_file," %d", size_0); //pocet bodu pruniku N
77 
78  // cyklus pres body pruniku
80  i_point != i_points.end();++i_point) {
81 
82  // pocet lokalnich souradnic 1. elementu a jejich vypis
83  int size_1 = (*i_point)->coord1.size();
84  fprintf(out_file, " %d", size_1);
85  for(std::vector<double>::iterator l_coord = (*i_point)->coord1.begin();
86  l_coord != (*i_point)->coord1.end();++l_coord) {
87  float f_1 = *l_coord;
88  fprintf(out_file, " %1.7e", f_1);
89  }
90 
91  // pocet lokalnich souradnic 2. elementu a jejich vypis
92  int size_2 = (*i_point)->coord2.size();
93  fprintf(out_file, " %d", size_2);
94  for(std::vector<double>::iterator l_coord = (*i_point)->coord2.begin();
95  l_coord != (*i_point)->coord2.end();++l_coord) {
96  float f_2 = *l_coord;
97  fprintf(out_file, " %1.7e", f_2);
98  }
99  }
100 }
101 
104  i_point != i_points.end();++i_point) {
105  delete *i_point;
106  }
107 }
std::vector< double > coord2
IntersectionPoint * interpolate(const IntersectionPoint &A1, const IntersectionPoint &A2, double t)
void print(FILE *out_file)
static int numberInstance
const std::vector< double > & el2_coord() const
bool operator==(const IntersectionPoint &)
std::vector< double > coord1
const std::vector< double > & el1_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)
IntersectionLocal(IntersectionType i_type)
std::vector< IntersectionPoint * > i_points
const double epsilon
Definition: mathfce.h:23
bool eps_double_equal(double a, double b)
IntersectionType type
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
void add_local_point(IntersectionPoint *InPoint)