TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
FTd_tools.cpp
1/****************************************************************************
2* Copyright (c) 2015 - 2016, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <FTd_tools.h>
17#include <math.h>
18#include <TRUSTTabFT.h>
19
20/*! @brief Cette fonction calcule le max de la norme d'un ensemble de vecteurs
21 *
22 * @param (vecteurs) vecteurs a mesurer
23 * @return (double) le max du deplacement
24 */
25double FTd_calculer_max_norme_vecteurs(const DoubleTab& vecteurs)
26{
27 int som,k;
28 double norme2max = 0., norme2;
29 int nbsom = vecteurs.dimension(0);
30 for (som=0 ; som<nbsom ; som++)
31 {
32 norme2 = vecteurs(som,0) * vecteurs(som,0);
33 for (k=1 ; k<Objet_U::dimension ; k++)
34 {
35 norme2 += vecteurs(som,k) * vecteurs(som,k);
36 }
37 if (norme2>norme2max)
38 {
39 norme2max = norme2;
40 }
41 }
42
43 return sqrt(norme2max);
44}
45
46// The area of a triangle is half of the cross-product!
47double FTd_calculer_aire_triangle(const FTd_vecteur2& coord_som0,
48 const FTd_vecteur2& coord_som1,
49 const FTd_vecteur2& coord_som2)
50{
51 double x0 = coord_som0[0];
52 double y0 = coord_som0[1];
53
54 double x1 = coord_som1[0];
55 double y1 = coord_som1[1];
56
57 double x2 = coord_som2[0];
58 double y2 = coord_som2[1];
59
60 double aire_tr = 0.5*((x1-x0) * (y2-y0) - (y1-y0) * (x2-x0));
61
62 return aire_tr;
63}
64double FTd_calculer_volume_tetraedre(const FTd_vecteur3& coord_som0,
65 const FTd_vecteur3& coord_som1,
66 const FTd_vecteur3& coord_som2,
67 const FTd_vecteur3& coord_som3)
68{
69 double x0 = coord_som0[0];
70 double y0 = coord_som0[1];
71 double z0 = coord_som0[2];
72
73 double x1 = coord_som1[0];
74 double y1 = coord_som1[1];
75 double z1 = coord_som1[2];
76
77 double x2 = coord_som2[0];
78 double y2 = coord_som2[1];
79 double z2 = coord_som2[2];
80
81 double x3 = coord_som3[0];
82 double y3 = coord_som3[1];
83 double z3 = coord_som3[2];
84
85 double vol = ( (x1-x0)*( (y2-y0)*(z3-z0)-(y3-y0)*(z2-z0) )
86 - (x2-x0)*( (y1-y0)*(z3-z0)-(y3-y0)*(z1-z0) )
87 + (x3-x0)*( (y1-y0)*(z2-z0)-(y2-y0)*(z1-z0) ) )/6;
88
89 return vol;
90}
91
92//en numerotation globale, cette fonction renvoie
93// -1 si som0 < som1
94// 0 si som0 = som1
95// 1 si som0 > som1
96//En numerotation globale,
97// som0=som1 si
98// - peO==pe1 && som0==som1
99// som0<som1
100// - pe0<pe1 ou (pe0==pe1 && som0<som1)
101// som0>som1
102// - pe0>pe1 ou (pe0==pe1 && som0>som1)
103int FTd_compare_sommets_global(int pe0, int numOwner0, int pe1, int numOwner1)
104{
105 if (pe0==pe1)
106 {
107 if (numOwner0==numOwner1)
108 {
109 return 0;
110 }
111 else if (numOwner0<numOwner1)
112 {
113 return -1;
114 }
115 }
116 else if (pe0<pe1)
117 {
118 return -1;
119 }
120
121 return 1;
122}
static int dimension
Definition Objet_U.h:99
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133