diff --git a/examples/adhesion.py b/examples/adhesion.py
index 4c84543..b7ca58f 100644
--- a/examples/adhesion.py
+++ b/examples/adhesion.py
@@ -1,117 +1,127 @@
#!/usr/bin/env python3
# @file
# @section LICENSE
#
# Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
import tamaas as tm
import matplotlib.pyplot as plt
import numpy as np
import argparse
+from matplotlib.colors import ListedColormap
+
class AdhesionPython(tm.Functional):
"""
Functional class that extends a C++ class and implements the virtual
methods
"""
+
def __init__(self, rho, gamma):
tm.Functional.__init__(self)
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()
# 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)
+plt.title('Rough 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(adhesion_params["rho"],
adhesion_params["surface_energy"])
# Use the C++ class
else:
adhesion = tm.ExponentialAdhesionFunctional(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.title('Contact tractions')
plt.figure()
zones = np.zeros_like(tractions)
tol = 1e-6
zones[tractions > tol] = 1
zones[tractions < -tol] = -1
-plt.imshow(zones, cmap='Greys')
+plt.imshow(zones, cmap=ListedColormap(['white', 'gray', 'black']))
+plt.colorbar(ticks=[-2/3, 0, 2/3]).set_ticklabels([
+ 'Adhesion', 'No Contact', 'Contact'
+])
+
+plt.title('Contact and Adhesion Zones')
plt.show()
diff --git a/examples/rough_contact.py b/examples/rough_contact.py
index e6f6329..4cef430 100644
--- a/examples/rough_contact.py
+++ b/examples/rough_contact.py
@@ -1,70 +1,71 @@
#!/usr/bin/env python3
# @file
# @section LICENSE
#
# Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
import tamaas as tm
import matplotlib.pyplot as plt
# Initialize threads and fftw
tm.set_log_level(tm.LogLevel.info) # Show progression of solver
# Surface size
n = 512
# Surface generator
sg = tm.SurfaceGeneratorFilter2D()
sg.setSizes([n, n])
sg.random_seed = 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.pressure,
tm.PolonskyKeerRey.pressure)
# Solve for target pressure
p_target = 0.1
solver.solve(p_target)
plt.figure()
plt.imshow(model.getTraction())
+plt.title('Contact tractions')
print(model.getTraction().mean())
plt.show()
diff --git a/examples/saturated.py b/examples/saturated.py
index 158203f..e576bde 100644
--- a/examples/saturated.py
+++ b/examples/saturated.py
@@ -1,65 +1,67 @@
# -*- coding: utf-8 -*-
# @file
# @section LICENSE
#
# Copyright (©) 2016-2020 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
import tamaas as tm
import numpy as np
import matplotlib.pyplot as plt
grid_size = 256
load = 1.6
p_sat = 100
iso = tm.Isopowerlaw2D()
iso.q0 = 4
iso.q1 = 4
iso.q2 = 16
iso.hurst = 0.8
sg = tm.SurfaceGeneratorFilter2D()
sg.random_seed = 2
sg.setSizes([grid_size, grid_size])
sg.setSpectrum(iso)
surface = sg.buildSurface()
surface -= np.max(surface)
model = tm.ModelFactory.createModel(tm.model_type.basic_2d,
[1., 1.], [grid_size, grid_size])
model.E = 1.
model.nu = 0
esolver = tm.PolonskyKeerRey(model, surface, 1e-12,
tm.PolonskyKeerRey.pressure,
tm.PolonskyKeerRey.pressure)
esolver.solve(load)
elastic_tractions = model['traction'].copy()
plt.imshow(elastic_tractions)
+plt.title('Elastic contact tractions')
plt.colorbar()
model['traction'][:] = 0.
solver = tm.KatoSaturated(model, surface, 1e-12, p_sat)
solver.setDumpFrequency(1)
solver.setMaxIterations(200)
solver.solve(load)
plt.figure()
plt.imshow(model['traction'])
+plt.title('Saturated contact tractions')
plt.colorbar()
plt.show()