diff --git a/.gitignore b/.gitignore index 9460480..7f24725 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *~ .sconf_temp .sconsign.dblite *.log build* -site_scons/site_tools/swig.pyc +*.pyc diff --git a/tests/test_fftransform.py_no b/tests/test_fftransform.py_no index bd579d0..883d8e1 100644 --- a/tests/test_fftransform.py_no +++ b/tests/test_fftransform.py_no @@ -1,55 +1,58 @@ #!/usr/bin/env python # coding: utf-8 # ----------------------------------------------------------------------------- # @author Lucas Frérot # # @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 . # ----------------------------------------------------------------------------- import sys -import tamaas as tm import numpy as np import matplotlib.pyplot as plt +from util_test import import_tamaas + def main(): + tm = import_tamaas() + size = 512 # Generate random rough surface SG = tm.SurfaceGeneratorFilterFFT() SG.getGridSize().assign(size) SG.getHurst().assign(0.8) SG.getRMS().assign(1.); SG.getQ0().assign(4); SG.getQ1().assign(4); SG.getQ2().assign(32); SG.getRandomSeed().assign(156); SG.Init() surface = SG.buildSurface() # Compute fourier transform through numpy numpy_spectral = np.fft.fft2(surface) # Compute fourier tranform through tamaas tamaas_spectral = np.zeros((size, size)) #transform = tm.FFTransformReal(size, surface, transform) return 0 if __name__ == '__main__': sys.exit(main()) diff --git a/tests/test_fractal.py b/tests/test_fractal.py index 750b7e1..2f3fe86 100644 --- a/tests/test_fractal.py +++ b/tests/test_fractal.py @@ -1,100 +1,102 @@ #!/usr/bin/python # -*- coding: utf-8 -*- ##* # # @author Guillaume Anciaux # # @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 . # # ################################################################ -import sys -from tamaas import * +import sys, imp + +from util_test import import_tamaas def main(): + tm = import_tamaas() #generate surface - SG = SurfaceGeneratorFilterFFT() + SG = tm.SurfaceGeneratorFilterFFT() SG.getGridSize().assign(512) SG.getHurst().assign(0.8) SG.getRMS().assign(1.); SG.getQ0().assign(4); SG.getQ1().assign(4); SG.getQ2().assign(32); SG.getRandomSeed().assign(156); SG.Init() a = SG.buildSurface() #compute and print surface statistics class Stats: def __getitem__(self,key): return self.__dict__[key] stats = Stats() stats.size = SG.getGridSize() stats.hurst = SG.getHurst().value() stats.rms = SG.getRMS() stats.k0 = SG.getQ0() stats.k1 = SG.getQ1().value() stats.k2 = SG.getQ2().value() stats.seed = SG.getRandomSeed() - stats.rms_spectral = SurfaceStatistics.computeSpectralStdev(a); - stats.rms_slopes_spectral = SurfaceStatistics.computeSpectralRMSSlope(a); - stats.rms_geometric = SurfaceStatistics.computeStdev(SurfaceForPythonReal(a)); - stats.rms_slopes_geometric = SurfaceStatistics.computeRMSSlope(a); - stats.moments = SurfaceStatistics.computeMoments(a); + stats.rms_spectral = tm.SurfaceStatistics.computeSpectralStdev(a); + stats.rms_slopes_spectral = tm.SurfaceStatistics.computeSpectralRMSSlope(a); + stats.rms_geometric = tm.SurfaceStatistics.computeStdev(SurfaceForPythonReal(a)); + stats.rms_slopes_geometric = tm.SurfaceStatistics.computeRMSSlope(a); + stats.moments = tm.SurfaceStatistics.computeMoments(a); stats.m0 = stats['rms_spectral']**2 stats.m2 = stats.moments[0] stats.m4 = stats.moments[1] stats.alpha = stats['m0']*stats['m4']/(stats['m2']**2) stats.L = 1. - stats.m0prime = SurfaceStatistics.computeAnalyticFractalMoment(0,stats.k1,stats.k2,stats.hurst,1. , stats.L) + stats.m0prime = tm.SurfaceStatistics.computeAnalyticFractalMoment(0,stats.k1,stats.k2,stats.hurst,1. , stats.L) stats.moment_A = stats.m0/stats.m0prime - stats.analytic_m0 = SurfaceStatistics.computeAnalyticFractalMoment(0,stats.k1,stats.k2,stats.hurst,stats.moment_A,stats.L); - stats.analytic_m2 = SurfaceStatistics.computeAnalyticFractalMoment(2,stats.k1,stats.k2,stats.hurst,stats.moment_A,stats.L); - stats.analytic_m4 = SurfaceStatistics.computeAnalyticFractalMoment(4,stats.k1,stats.k2,stats.hurst,stats.moment_A,stats.L); + stats.analytic_m0 = tm.SurfaceStatistics.computeAnalyticFractalMoment(0,stats.k1,stats.k2,stats.hurst,stats.moment_A,stats.L); + stats.analytic_m2 = tm.SurfaceStatistics.computeAnalyticFractalMoment(2,stats.k1,stats.k2,stats.hurst,stats.moment_A,stats.L); + stats.analytic_m4 = tm.SurfaceStatistics.computeAnalyticFractalMoment(4,stats.k1,stats.k2,stats.hurst,stats.moment_A,stats.L); stats.analytic_alpha = stats.analytic_m0*stats.analytic_m4/(stats.analytic_m2*stats.analytic_m2); print """ [N] {size} [rms] {rms} [rmsSpectral] {rms_spectral} [rmsSlopeSpectral] {rms_slopes_spectral} [rmsSlopeGeometric] {rms_slopes_geometric} [Hurst] {hurst} [k1] {k1} [k2] {k2} [moment A] {moment_A} [m0] {m0} [analytic m0] {analytic_m0} [m2] {m2} [analytic m2] {analytic_m2} [m4] {m4} [analytic m4] {analytic_m4} [alpha] {alpha} [analytic_alpha] {analytic_alpha} [seed] {seed} """.format(**stats.__dict__) return 0 if __name__ == "__main__": sys.exit(main()) diff --git a/tests/test_hertzian.py b/tests/test_hertzian.py index 7164ca1..9c618b5 100644 --- a/tests/test_hertzian.py +++ b/tests/test_hertzian.py @@ -1,121 +1,124 @@ #!/usr/bin/env python # coding: utf-8 # ----------------------------------------------------------------------------- # @author Lucas Frérot # # @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 . # ----------------------------------------------------------------------------- import sys -import tamaas as tm import numpy as np import matplotlib.pyplot as plt +from util_test import import_tamaas + def plotSurface(surface): fig = plt.figure() ax = fig.add_subplot(111) img = ax.imshow(surface) fig.colorbar(img) def constructHertzProfile(size, curvature): radius = 1. / curvature x = np.linspace(-0.5, 0.5, size) y = np.linspace(-0.5, 0.5, size) x, y = np.meshgrid(x, y) surface = np.sqrt(radius**2 - x**2 - y**2) surface -= surface.mean() return surface.copy() def computeHertzDisplacement(e_star, contact_size, max_pressure, size): x = np.linspace(-0.5, 0.5, size) y = np.linspace(-0.5, 0.5, size) x, y = np.meshgrid(x, y) disp = np.pi * max_pressure / (4 * contact_size * e_star) * (2 * contact_size**2 - (x**2 + y**2)) return disp.copy() def main(): + tm = import_tamaas() + grid_size = 1024 curvature = 0.1 effective_modulus = 1. load = 0.0001 surface = constructHertzProfile(grid_size, curvature) bem = tm.BemPolonski(surface) bem.setEffectiveModulus(effective_modulus) bem.computeEquilibrium(1e-12, load) tractions = bem.getTractions() displacements = bem.getDisplacements() # Testing contact area against Hertz solution for solids of revolution contact_area = tm.SurfaceStatistics.computeContactArea(tractions) hertz_contact_size = (3 * load / (4 * curvature * effective_modulus))**(1. / 3.) hertz_area = np.pi * hertz_contact_size**2 area_error = np.abs(hertz_area - contact_area) / hertz_area print "Area error: {}".format(area_error) # Testing maximum pressure max_pressure = tractions.max() hertz_max_pressure = (6 * load * effective_modulus**2 * curvature ** 2)**(1. / 3.) / np.pi pressure_error = np.abs(hertz_max_pressure - max_pressure) / hertz_max_pressure print "Max pressure error: {}".format(pressure_error) # Testing displacements hertz_displacements = computeHertzDisplacement(effective_modulus, hertz_contact_size, hertz_max_pressure, grid_size) # Selecing only the points that are in contact contact_indexes = [(i, j, tractions[i, j] > 0) for i in range(grid_size) for j in range(grid_size)] contact_indexes = map(lambda x: x[0:2], filter(lambda x: x[2], contact_indexes)) # Displacements of bem are centered around the mean of the whole surface # and Hertz displacements are not centered, so we need to compute mean # on the contact zone for both arrays bem_mean = 0. hertz_mean = 0. for index in contact_indexes: bem_mean += displacements[index] hertz_mean += hertz_displacements[index] bem_mean /= len(contact_indexes) hertz_mean /= len(contact_indexes) # Correction applied when computing error correction = hertz_mean - bem_mean # Computation of error of displacement in contact zone error = 0. hertz_norm = 0. for index in contact_indexes: error += (hertz_displacements[index] - displacements[index] - correction)**2 hertz_norm += (hertz_displacements[index] - hertz_mean)**2 displacement_error = np.sqrt(error / hertz_norm) print "Displacement error (in contact zone): {}".format(displacement_error) if area_error > 1e-3 or pressure_error > 3e-3 or displacement_error > 1e-4: return 1 return 0 if __name__ == "__main__": sys.exit(main()) diff --git a/tests/test_westergaard.py b/tests/test_westergaard.py index e0a20fd..be93b6f 100644 --- a/tests/test_westergaard.py +++ b/tests/test_westergaard.py @@ -1,76 +1,79 @@ #!/usr/bin/env python # coding: utf-8 # ----------------------------------------------------------------------------- # @author Lucas Frérot # # @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 . # ----------------------------------------------------------------------------- import sys -import tamaas as tm import numpy as np import matplotlib.pyplot as plt +from util_test import import_tamaas + def constructSinProfile(size, mode, amplitude): x = np.linspace(0, 1, size) y = np.linspace(0, 1, size) x, y = np.meshgrid(x, y) surface = amplitude * np.sin(2*np.pi*x*mode) return surface.copy() def main(): + tm = import_tamaas() + grid_size = 256 mode = 1 delta = 0.1 effective_modulus = 1. p_star = np.pi * effective_modulus * delta * mode # Full contact load load = 0.4 * p_star surface = constructSinProfile(grid_size, mode, delta) bem = tm.BemPolonski(surface) bem.setEffectiveModulus(effective_modulus) bem.computeEquilibrium(1e-12, load) tractions = bem.getTractions() displacements = bem.getDisplacements() # Testing contact area against Westergaard solution contact_area = tm.SurfaceStatistics.computeContactArea(tractions) westergaard_contact_size = 2. / (mode * np.pi) * np.arcsin(np.sqrt(load / p_star)) area_error = np.abs(contact_area - mode * westergaard_contact_size) / (mode * westergaard_contact_size) print "Area error: {}".format(area_error) # Testing displacements at full contact load = 1.1 * p_star bem.computeEquilibrium(1e-12, load) contact_area = tm.SurfaceStatistics.computeContactArea(tractions) print "Area at load > full contact : {}".format(contact_area) # Testing pressure distribution at full contact westergaard_pressure = constructSinProfile(grid_size, mode, p_star) tractions_amplitude = tractions.max() - tractions.mean() return 0 if __name__ == "__main__": sys.exit(main()) diff --git a/tests/util_test.py b/tests/util_test.py new file mode 100644 index 0000000..311b166 --- /dev/null +++ b/tests/util_test.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +##* + # + # @author Lucas Frérot + # + # @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 . + # + # +################################################################ + +import imp + +def import_tamaas(): + """Importing tamaas using relative path""" + tamaas_info = imp.find_module("tamaas", ["../build-release/python", + "../build-debug/python", + "../build-profiling/python"]) + return imp.load_module("tamaas", *tamaas_info) +