TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Trier.cpp
1/****************************************************************************
2* Copyright (c) 2022, 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 <TRUSTVect.h>
17#include <Trier.h>
18
19void QuickSort(const DoubleVect& a,int g, int d, ArrOfInt& c)
20{
21 int t,i,j;
22 double v;
23 if (g < d)
24 {
25 if(a[c[g]]>a[c[d]])
26 {
27 t=c[g];
28 c[g]=c[d];
29 c[d]=t;
30 }
31 v = a[c[d]];
32 i = g-1;
33 j = d;
34 do
35 {
36 do i++;
37 while (a[c[i]] < v);
38 do j--;
39 while (a[c[j]] > v);
40 t = c[i];
41 c[i] = c[j];
42 c[j] = t;
43 }
44 while (j > i);
45 c[j] = c[i];
46 c[i] = c[d];
47 c[d] = t;
48 QuickSort (a, g, i-1,c);
49 QuickSort (a, i+1, d,c);
50 }
51}
52
53void trier_abs(const DoubleVect& a, ArrOfInt& c)
54{
55 DoubleVect a2(a.size_array());
57 int i;
58
59 for (i=0; i<a2.size_array(); i++) a2[i]=std::fabs(a[i]);
60 for ( i=0; i<c.size_array(); i++) c[i]=i;
61
62 QuickSort(a2, 0, a2.size_array()-1, c);
63}
64
65void trier(const DoubleVect& a, ArrOfInt& c)
66{
68 int i;
69 for (i=0; i<c.size_array(); i++) c[i]=i;
70 QuickSort(a, 0, a.size_array()-1, c);
71}
72
73void essai()
74{
75 DoubleVect a(5);
76 ArrOfInt c(5);
77 int i;
78 a[0]=-10.1;
79 a[1]=8.3;
80 a[2]=7.31;
81 a[3]=7.3;
82 a[4]=7.1;
83 Cerr << "a before selecting " << finl;
84 for (i=0; i<5; i++) Cerr << a[i] << " ";
85 Cerr << finl;
86 trier (a,c);
87 Cerr << "a after selecting " << finl;
88 for ( i=0; i<5; i++) Cerr << a[c[i]] << " ";
89 Cerr << finl;
90 trier_abs (a,c);
91 Cerr << "a after selecting abs " << finl;
92 for ( i=0; i<5; i++) Cerr << a[c[i]] << " ";
93 Cerr << finl;
94}
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)