Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F71093091
bem_gigi.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jul 9, 15:01
Size
8 KB
Mime Type
text/x-c
Expires
Thu, Jul 11, 15:01 (2 d)
Engine
blob
Format
Raw Data
Handle
18906667
Attached To
rTAMAAS tamaas
bem_gigi.cpp
View Options
/**
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include <vector>
#include "surface.hh"
#include "bem_gigi.hh"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <cmath>
/* -------------------------------------------------------------------------- */
#define TIMER
#include "surface_timer.hh"
/* -------------------------------------------------------------------------- */
Real
BemGigi
::
computeEquilibrium
(
Real
epsilon
,
Real
mean_displacement
)
{
this
->
computeSpectralInfluenceOverDisplacement
();
Real
Rold
=
1.
;
Real
f
=
1e300
;
this
->
search_direction
=
0.
;
this
->
true_displacements
=
mean_displacement
;
convergence_iterations
.
clear
();
nb_iterations
=
0
;
// max_iterations = 100;
while
(
f
>
epsilon
&&
nb_iterations
++
<
max_iterations
)
{
this
->
computeGaps
();
this
->
functional
->
computeGradF
();
Real
R
=
this
->
functional
->
computeGradientNorm
();
this
->
updateSearchDirection
(
R
/
Rold
);
Rold
=
R
;
Real
tau
=
this
->
computeOptimalStep
();
this
->
updateDisplacements
(
tau
);
this
->
computeGaps
();
this
->
optimizeToMeanDisplacement
(
mean_displacement
);
f
=
R
;
if
(
nb_iterations
%
dump_freq
==
0
)
{
std
::
cout
<<
std
::
scientific
<<
std
::
setprecision
(
10
)
<<
nb_iterations
<<
" "
<<
f
<<
std
::
fixed
<<
std
::
endl
;
}
convergence_iterations
.
push_back
(
f
);
// if(nb_iterations == 2) return 0;
}
this
->
computePressures
();
this
->
computeTruePressures
();
return
f
;
}
/* -------------------------------------------------------------------------- */
Real
BemGigi
::
computeStoppingCriterion
()
{
return
1e300
;
}
/* -------------------------------------------------------------------------- */
void
BemGigi
::
optimizeToMeanDisplacement
(
Real
imposed_mean
)
{
Real
target_value
=
imposed_mean
-
SurfaceStatistics
::
computeAverage
(
surface
,
0
);
UInt
n
=
surface
.
size
();
UInt
size
=
n
*
n
;
// Initial guesses for upper and lower bound
Real
step_min
=
-
10
;
Real
step_max
=
10
;
// Gaps for upper and lower bound
Real
gap_min
=
positiveGapAverage
(
step_min
);
Real
gap_max
=
positiveGapAverage
(
step_max
);
UInt
max_expansion
=
8
;
// Expand bounds if necessary
for
(
UInt
i
=
0
;
gap_max
<
target_value
&&
i
<
max_expansion
;
i
++
,
step_max
*=
10
)
gap_max
=
positiveGapAverage
(
step_max
);
for
(
UInt
i
=
0
;
gap_min
>
target_value
&&
i
<
max_expansion
;
i
++
,
step_min
*=
10
)
gap_min
=
positiveGapAverage
(
step_min
);
Real
g
=
0.
;
Real
epsilon
=
1e-12
;
Real
step
=
0
;
while
(
fabs
(
g
-
target_value
)
>
epsilon
)
{
step
=
(
step_min
+
step_max
)
/
2.
;
g
=
positiveGapAverage
(
step
);
if
(
g
>
target_value
)
step_max
=
step
;
else
if
(
g
<
target_value
)
step_min
=
step
;
else
{
step_max
=
step
;
step_min
=
step
;
}
}
step
=
(
step_min
+
step_max
)
/
2.
;
#pragma omp parallel for
for
(
UInt
i
=
0
;
i
<
size
;
i
++
)
{
gap
(
i
)
+=
step
;
if
(
gap
(
i
)
<
0
)
gap
(
i
)
=
0
;
true_displacements
(
i
)
=
gap
(
i
)
+
surface
(
i
);
}
}
/* -------------------------------------------------------------------------- */
Real
BemGigi
::
positiveGapAverage
(
Real
shift
)
{
UInt
n
=
surface
.
size
();
Real
res
=
0
;
#pragma omp parallel for reduction(+: res)
for
(
UInt
i
=
0
;
i
<
n
*
n
;
i
++
)
{
Real
shifted_gap
=
gap
(
i
)
+
shift
;
res
+=
shifted_gap
*
(
shifted_gap
>
0
);
}
return
res
/
(
n
*
n
);
}
/* -------------------------------------------------------------------------- */
void
BemGigi
::
updateSearchDirection
(
Real
factor
)
{
STARTTIMER
(
"updateSearchDirection"
);
UInt
n
=
surface
.
size
();
UInt
size
=
n
*
n
;
Surface
<
Real
>
&
gradF
=
this
->
functional
->
getGradF
();
#pragma omp parallel for
for
(
UInt
i
=
0
;
i
<
size
;
++
i
)
{
this
->
search_direction
(
i
)
*=
factor
;
this
->
search_direction
(
i
)
=
gradF
(
i
);
}
STOPTIMER
(
"updateSearchDirection"
);
}
/* -------------------------------------------------------------------------- */
Real
BemGigi
::
computeOptimalStep
()
{
STARTTIMER
(
"computeOptimalStep"
);
search_direction
.
FFTTransform
(
spectral_search_direction
,
nthreads
);
UInt
n
=
surface
.
size
();
UInt
size
=
n
*
n
;
spectral_search_direction
(
0
)
=
0
;
#pragma omp parallel for
for
(
UInt
i
=
1
;
i
<
size
;
++
i
)
{
spectral_search_direction
(
i
)
/=
this
->
surface_spectral_influence_disp
(
i
);
}
// /!\ does not contain the spectral search direction anymore
spectral_search_direction
.
FFTITransform
(
nthreads
);
Real
average
=
SurfaceStatistics
::
computeAverage
(
spectral_search_direction
.
real
(),
0
);
spectral_search_direction
-=
average
;
Surface
<
Real
>
&
gradF
=
this
->
functional
->
getGradF
();
Real
numerator
=
0.
,
denominator
=
0.
;
#pragma omp parallel for reduction(+: numerator, denominator)
for
(
UInt
i
=
0
;
i
<
size
;
++
i
)
{
numerator
+=
gradF
(
i
)
*
search_direction
(
i
);
denominator
+=
spectral_search_direction
(
i
).
real
()
*
search_direction
(
i
);
}
Real
alpha
=
numerator
/
denominator
;
STOPTIMER
(
"computeOptimalStep"
);
return
alpha
;
}
/* -------------------------------------------------------------------------- */
void
BemGigi
::
updateDisplacements
(
Real
alpha
)
{
STARTTIMER
(
"updateDisplacements"
);
UInt
n
=
surface
.
size
();
UInt
size
=
n
*
n
;
#pragma omp parallel for
for
(
UInt
i
=
0
;
i
<
size
;
++
i
)
{
this
->
true_displacements
(
i
)
-=
alpha
*
this
->
search_direction
(
i
);
}
STOPTIMER
(
"updateDisplacements"
);
}
/* -------------------------------------------------------------------------- */
void
BemGigi
::
emptyOverlap
()
{
STARTTIMER
(
"emptyoverlap"
);
UInt
n
=
surface
.
size
();
UInt
size
=
n
*
n
;
#pragma omp parallel for
for
(
UInt
i
=
0
;
i
<
size
;
++
i
)
{
if
(
gap
(
i
)
<
0
)
this
->
true_displacements
(
i
)
=
this
->
surface
(
i
);
}
STOPTIMER
(
"emptyoverlap"
);
}
/* -------------------------------------------------------------------------- */
void
BemGigi
::
enforceMeanDisplacement
(
Real
mean_displacement
)
{
STARTTIMER
(
"enforceMeanDisplacement"
);
UInt
n
=
surface
.
size
();
UInt
size
=
n
*
n
;
Real
average
=
SurfaceStatistics
::
computeAverage
(
this
->
true_displacements
,
0
);
Real
factor
=
mean_displacement
/
average
;
#pragma omp parallel for
for
(
UInt
i
=
0
;
i
<
size
;
++
i
)
{
this
->
true_displacements
(
i
)
*=
factor
;
}
STOPTIMER
(
"enforceMeanDisplacement"
);
}
/* -------------------------------------------------------------------------- */
void
BemGigi
::
computePressures
()
{
UInt
n
=
surface
.
size
();
UInt
size
=
n
*
n
;
this
->
true_displacements
.
FFTTransform
(
this
->
surface_spectral_tractions
,
nthreads
);
this
->
surface_spectral_tractions
(
0
)
=
0
;
#pragma omp parallel for
for
(
UInt
i
=
1
;
i
<
size
;
++
i
)
{
this
->
surface_spectral_tractions
(
i
)
/=
this
->
surface_spectral_influence_disp
(
i
);
}
this
->
surface_spectral_tractions
.
FFTITransform
(
this
->
surface_tractions
,
nthreads
);
}
/* -------------------------------------------------------------------------- */
void
BemGigi
::
computeTruePressures
()
{
this
->
computeGaps
();
UInt
n
=
surface
.
size
();
Real
min_pressure
=
0.
;
#pragma omp parallel for reduction(min: min_pressure)
for
(
UInt
i
=
0
;
i
<
n
*
n
;
i
++
)
{
if
(
gap
(
i
)
==
0
&&
min_pressure
>
surface_tractions
(
i
))
min_pressure
=
surface_tractions
(
i
);
}
surface_tractions
+=
min_pressure
;
}
Event Timeline
Log In to Comment