Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F84372293
new_adhesion.py
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
Sun, Sep 22, 11:02
Size
2 KB
Mime Type
text/x-python
Expires
Tue, Sep 24, 11:02 (2 d)
Engine
blob
Format
Raw Data
Handle
21001499
Attached To
rTAMAAS tamaas
new_adhesion.py
View Options
import
tamaas
as
tm
import
sys
import
matplotlib.pyplot
as
plt
import
numpy
as
np
import
argparse
#-------------------------------------------------------------------------------
class
AdhesionPython
(
tm
.
Functional
):
"""
Functional class that extends a C++ class and implements the virtual
methods
"""
def
__init__
(
self
,
engine
,
rho
,
gamma
):
tm
.
Functional
.
__init__
(
self
,
engine
)
self
.
rho
=
rho
self
.
gamma
=
gamma
def
computeF
(
self
,
gap
,
pressure
):
return
-
self
.
gamma
*
np
.
sum
(
np
.
exp
(
-
gap
/
self
.
rho
))
def
computeGradF
(
self
,
gap
,
gradient
):
gradient
+=
self
.
gamma
*
np
.
exp
(
-
gap
/
self
.
rho
)
/
self
.
rho
#-------------------------------------------------------------------------------
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--local-functional'
,
dest
=
"py_adh"
,
action
=
"store_true"
,
help
=
"use the adhesion functional written in python"
)
args
=
parser
.
parse_args
()
# Initialize threads and fftw
tm
.
initialize
()
# Surface size
n
=
1024
# Surface generator
sg
=
tm
.
SurfaceGeneratorFilter2D
()
sg
.
setSizes
([
n
,
n
])
sg
.
setRandomSeed
(
0
)
# Spectrum
spectrum
=
tm
.
Isopowerlaw2D
()
sg
.
setFilter
(
spectrum
)
# Parameters
spectrum
.
q0
=
16
spectrum
.
q1
=
16
spectrum
.
q2
=
64
spectrum
.
hurst
=
0.8
# Generating surface
surface
=
sg
.
buildSurface
()
#surface /= tm.SurfaceStatistics.computeSpectralRMSSlope(surface)
surface
/=
n
#print(spectrum.rmsSlopes())
#print(tm.SurfaceStatistics.computeRMSSlope(surface))
plt
.
imshow
(
surface
)
# Creating model
model
=
tm
.
ModelFactory
.
createModel
(
tm
.
model_type_basic_2d
,
[
1.
,
1.
],
[
n
,
n
])
# Solver
solver
=
tm
.
PolonskyKeerRey
(
model
,
surface
,
1e-12
,
tm
.
PolonskyKeerRey
.
gap
,
tm
.
PolonskyKeerRey
.
gap
)
adhesion_params
=
{
"rho"
:
2e-3
,
"surface_energy"
:
2e-5
}
# Use the python derived from C++ functional class
if
args
.
py_adh
:
adhesion
=
AdhesionPython
(
model
.
getBEEngine
(),
adhesion_params
[
"rho"
],
adhesion_params
[
"surface_energy"
])
# Use the C++ class
else
:
adhesion
=
tm
.
ExponentialAdhesionFunctional
(
model
.
getBEEngine
(),
surface
)
adhesion
.
setParameters
(
adhesion_params
)
solver
.
addFunctionalTerm
(
adhesion
)
# Solve for target pressure
g_target
=
5e-2
solver
.
solve
(
g_target
)
tractions
=
model
.
getTraction
()
plt
.
figure
()
plt
.
imshow
(
tractions
)
plt
.
colorbar
()
plt
.
figure
()
zones
=
np
.
zeros_like
(
tractions
)
tol
=
1e-6
zones
[
tractions
>
tol
]
=
1
zones
[
tractions
<
-
tol
]
=
-
1
plt
.
imshow
(
zones
,
cmap
=
'Greys'
)
# Cleanup threads
tm
.
finalize
()
plt
.
show
()
Event Timeline
Log In to Comment