LifeV
BCManage.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief Functions for prescribing boundary conditions
30 
31  @author Gwenol Grandperrin <grandper@iacspc85.epfl.ch>
32  @maintainer Mauro Perego <perego.mauro@gmail.com>
33 
34  @date 11-04-2009
35  */
36 
37 #include <lifev/core/fem/BCManage.hpp>
38 
39 namespace LifeV
40 {
41 
42 // =============================
43 // Implementation
44 // =============================
45 
46 void bcCalculateTangentVectors (std::map< ID, std::vector< Real > >& triad)
47 {
48 
49  std::map< ID, std::vector< Real > >::iterator mapIt;
50  for ( mapIt = triad.begin() ; mapIt != triad.end(); ++mapIt )
51  {
52  //We take max{|n x i|,|n x j|,|n x k|}
53  // =max{sqrt(ny^2+nz^2),sqrt(nx^2+nz^2),sqrt(nx^2+ny^2)}
54  // =max{r1,r2,r3}
55  Real nx ( (*mapIt).second[6]);
56  Real ny ( (*mapIt).second[7]);
57  Real nz ( (*mapIt).second[8]);
58  Real nxi = sqrt (ny * ny + nz * nz);
59  Real nxj = sqrt (nx * nx + nz * nz);
60  Real nxk = sqrt (nx * nx + ny * ny);
61  if ( (nxi >= nxj) && (nxi >= nxk) ) //max = |n x i|
62  {
63  //We create t1
64  (*mapIt).second[0] = 0;
65  (*mapIt).second[1] = nz / nxi;
66  (*mapIt).second[2] = -ny / nxi;
67 
68  //We create t2
69  (*mapIt).second[3] = -nxi;
70  (*mapIt).second[4] = nx * ny / nxi;
71  (*mapIt).second[5] = nx * nz / nxi;
72  }
73  else if ( (nxj >= nxi) && (nxj >= nxk) ) //max = |n x j|
74  {
75  //We create t1
76  (*mapIt).second[0] = -nz / nxj;
77  (*mapIt).second[1] = 0;
78  (*mapIt).second[2] = nx / nxj;
79 
80  //We create t2
81  (*mapIt).second[3] = nx * ny / nxj;
82  (*mapIt).second[4] = -nxj;
83  (*mapIt).second[5] = ny * nz / nxj;
84  }
85  else //max = |n x k|
86  {
87  //We create t1
88  (*mapIt).second[0] = ny / nxk;
89  (*mapIt).second[1] = -nx / nxk;
90  (*mapIt).second[2] = 0;
91 
92  //We create t2
93  (*mapIt).second[3] = nx * nz / nxk;
94  (*mapIt).second[4] = ny * nz / nxk;
95  (*mapIt).second[5] = -nxk;
96  }
97  }
98 }
99 
100 void bcExportTriadToParaview (std::map< ID, std::vector< Real > >& triad, std::string filename)
101 {
102  //Initialization of the map to store the normal vectors
103  std::map< ID, std::vector< Real > >::iterator mapIt;
104 
105  filename.append (".vtk");
106  std::ofstream file (filename.c_str() );
107 
108  //Is the file open?
109  if (file.fail() )
110  {
111  std::cerr << "Error: The file is not opened " << std::endl;
112  }
113  else
114  {
115  //To define herein
116  unsigned int nbPoints (triad.size() );
117 
118  //Writing the header
119  file << "# vtk DataFile Version 2.0" << std::endl;
120  file << "Normal directions" << std::endl;
121  file << "ASCII" << std::endl;
122 
123  //Writing the points
124  file << "DATASET POLYDATA" << std::endl;
125  file << "POINTS " << nbPoints << " float" << std::endl;
126  for ( mapIt = triad.begin() ; mapIt != triad.end(); ++mapIt )
127  {
128  file << (*mapIt).second[9] << "\t" << (*mapIt).second[10] << "\t" << (*mapIt).second[11] << std::endl;
129  }
130 
131  //Starting the data part of the file
132  file << "POINT_DATA " << nbPoints << std::endl;
133 
134  //Writing t1
135  file << "VECTORS cell_tangent_1 float" << std::endl;
136  for ( mapIt = triad.begin() ; mapIt != triad.end(); ++mapIt )
137  {
138  file << (*mapIt).second[0] << "\t" << (*mapIt).second[1] << "\t" << (*mapIt).second[2] << std::endl;
139  }
140 
141  //Writing t2
142  file << "VECTORS cell_tangent_2 float" << std::endl;
143  for ( mapIt = triad.begin() ; mapIt != triad.end(); ++mapIt )
144  {
145  file << (*mapIt).second[3] << "\t" << (*mapIt).second[4] << "\t" << (*mapIt).second[5] << std::endl;
146  }
147 
148  //Writing n
149  file << "VECTORS cell_normals float" << std::endl;
150  for ( mapIt = triad.begin() ; mapIt != triad.end(); ++mapIt )
151  {
152  file << (*mapIt).second[6] << "\t" << (*mapIt).second[7] << "\t" << (*mapIt).second[8] << std::endl;
153  }
154 
155  //Closing the file
156  file.close();
157  }
158 }
159 
160 } //End of namespace LifeV
void bcCalculateTangentVectors(std::map< ID, std::vector< Real > > &triad)
Definition: BCManage.cpp:46
void updateInverseJacobian(const UInt &iQuadPt)
void bcExportTriadToParaview(std::map< ID, std::vector< Real > > &triad, std::string filename)
Definition: BCManage.cpp:100