diff --git a/examples/SConstruct b/examples/SConstruct index c871980..189b72a 100644 --- a/examples/SConstruct +++ b/examples/SConstruct @@ -1,12 +1,14 @@ import os env = Environment(CC = 'g++', CXXFLAGS = ['-std=c++11', '-g', '-fopenmp', '-O3'], TOOLS = ['default', tamaas], TAMAAS_PATH = '..', - TAMAAS_BUILD_TYPE = 'debug', + TAMAAS_BUILD_TYPE = 'release', LIBS = ['gomp', 'Tamaas'], ENV = os.environ) +env.AppendUnique(CPPPATH=['/opt/cuda/include']) +env.AppendUnique(LIBS=['fftw3', 'fftw3_omp']) env.Program('rough_surface.cc') diff --git a/examples/rough_surface.cc b/examples/rough_surface.cc index ac7aef6..1b610ee 100644 --- a/examples/rough_surface.cc +++ b/examples/rough_surface.cc @@ -1,76 +1,91 @@ /** * * @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 . * */ /* -------------------------------------------------------------------------- */ #include "tamaas.hh" -#include "bem_polonski.hh" -#include "surface_generator_filter_fft.hh" +#include "isopowerlaw.hh" +#include "surface_generator_filter.hh" +#include "polonsky_keer_rey.hh" +#include "model_factory.hh" /* -------------------------------------------------------------------------- */ using namespace tamaas; int main(int argc, char * argv[]) { /// Surface parameters UInt grid_size = 512; const UInt k0 = 4, k1 = 4, k2 = 32; const Real hurst = 0.8; const Real rms = 0.1; /// Initialize Tamaas initialize(); - /// Surface generation - SurfaceGeneratorFilterFFT sg; - sg.getGridSize() = grid_size; - sg.getQ0() = k0; - sg.getQ1() = k1; - sg.getQ2() = k2; - sg.getRMS() = rms; - sg.getHurst() = hurst; - sg.getRandomSeed() = 56; - sg.Init(); + /// Surface generation (2D) + SurfaceGeneratorFilter<2> sg; + sg.setSizes({grid_size, grid_size}); + sg.setRandomSeed(0); - Grid & grid = sg.buildSurface(); + Isopowerlaw<2> iso; + iso.setQ0(k0); + iso.setQ1(k1); + iso.setQ2(k2); + iso.setHurst(hurst); - /// Deprecated soon - Surface surface(grid_size, 1.); - surface.copy(grid); - std::cout << grid(0, 0, 0, 0) << std::endl; + sg.setFilter(&iso); - /// Bem initialization - BemPolonski bem(surface); - bem.setEffectiveModulus(1.); + std::cout << "Building rough surface with properties\n" + << " Q0 = " << k0 << "\n" + << " Q1 = " << k1 << "\n" + << " Q2 = " << k2 << "\n" + << " Hurst = " << hurst << "\n" + << " size = " << grid_size << "x" << grid_size << std::endl; + /// Making surface + GridBase & grid = sg.buildSurface(); + + std::cout << "Creating model" << std::endl; + + /// Model initialization + Model* model = ModelFactory::createModel(model_type::basic_2d, {1., 1.}, + {grid_size, grid_size}); Real load = 0.1; Real precision = 1e-12; + std::cout << "Solving contact problem" << std::endl; + /// Solve normal contact problem - bem.computeEquilibrium(precision, load); + PolonskyKeerRey solver{*model, grid, precision, PolonskyKeerRey::pressure, + PolonskyKeerRey::pressure}; + + solver.solve(load); + + std::cout << "Finished" << std::endl; /// Cleanup Tamaas finalize(); return EXIT_SUCCESS; } diff --git a/examples/site_scons/site_init.py b/examples/site_scons/site_init.py index 0b242f5..4df9ad8 100644 --- a/examples/site_scons/site_init.py +++ b/examples/site_scons/site_init.py @@ -1,37 +1,132 @@ -from __future__ import print_function -from os.path import abspath, join +from SCons.Script import * +from os.path import * + +import os + + +def fftw(env): + """A Tool to search for fftw headers and libraries""" + + if env.GetOption('clean'): + return + env.SetDefault(FFTW_VERSION='3') + env.SetDefault(FFTW_LIBRARY_WISH=[]) + + print("Building for fftw version {}".format(env['FFTW_VERSION'])) + + if 'FFTW_INCLUDE_DIR' in env: + env.AppendUnique(CPPPATH=env['FFTW_INCLUDE_DIR']) + + if 'FFTW_LIBRARY_DIR' in env: + env.AppendUnique(LIBPATH=env['FFTW_LIBRARY_DIR']) + + version = env['FFTW_VERSION'] + if version == "2": + lib_names = {'main': 'fftw'} + inc_names = ['fftw.h'] + else: + lib_names = {'main': 'fftw3', + 'thread': 'fftw3_threads', + 'omp': 'fftw3_omp'} + inc_names = ['fftw3.h'] + + try: + libs = [lib_names[i] for i in env['FFTW_LIBRARY_WISH']] + except: + raise SCons.Errors.StopError( + 'Incompatible wishlist {0} from version {1}'.format( + env['FFTW_LIBRARY_WISH'], env['FFTW_VERSION'])) + + env.AppendUnique(LIBS=libs) + if version == "2": + env.Append(LIBS='m') + + conf = Configure(env) + if not conf.CheckLibWithHeader(libs, inc_names, 'c++'): + raise SCons.Errors.StopError( + 'Failed to find libraries {0} or ' + 'headers {1}.'.format(str(lib_names), str(inc_names))) + + env = conf.Finish() + + +def criterion(env): + """A tool to configure for Criterion (test suite)""" + if env.GetOption('clean'): + return + + env.AppendUnique(CPPPATH=[Dir("#third-party/Criterion/include")], + LIBPATH=[abspath(str(Dir("#third-party/Criterion/build")))]) + conf = Configure(env) + # import pdb + # pdb.set_trace() + if not conf.CheckLibWithHeader('criterion', + 'criterion/criterion.h', + 'c++'): + raise SCons.Errors.StopError( + 'Failed to find library Criterion or criterion.h header in third-party') + env = conf.Finish() + + +def boost(env): + """A tool to confugure for boost""" + if env.GetOption('clean'): + return + + if 'BOOST_INCLUDE_DIR' in env: + env.AppendUnique(CPPPATH=env['BOOST_INCLUDE_DIR']) + conf = Configure(env) + if not conf.CheckCXXHeader('boost/version.hpp'): + raise SCons.Errors.StopError( + 'Failed to find Boost library') + env = conf.Finish() + + +def thrust(env): + """A tool to confugure for thrust""" + if env.GetOption('clean'): + return + + if 'THRUST_INCLUDE_DIR' in env: + env.AppendUnique(CPPPATH=env['THRUST_INCLUDE_DIR']) + conf = Configure(env) + if not conf.CheckCXXHeader('thrust/version.h'): + raise SCons.Errors.StopError( + 'Failed to find Thrust library') + env = conf.Finish() def tamaas(env): """Sets correct environement variables for Tamaas. - 'TAMAAS_PATH' is list of potential tamaas repositories - 'TAMAAS_BUILD_TYPE' is the build type of tamaas (release, debug, profiling)""" if env.GetOption("clean"): return try: build_type = env['TAMAAS_BUILD_TYPE'] except: build_type = "release" if 'TAMAAS_PATH' not in env: - print("Please set the 'TAMAAS_PATH' variable in your scons environement") + print("Please set the 'TAMAAS_PATH' variable in your scons environment") Exit(1) tm_path = env['TAMAAS_PATH'] include_dir = tm_path + '/src' - subdirs = "core model bem surface".split(" ") + subdirs = "core model solvers gpu bem surface".split(" ") include_dirs = [abspath(join(include_dir, x)) for x in subdirs] lib_dir = join(tm_path, 'build-{}/src'.format(build_type)) - env.AppendUnique(CPPPATH=include_dirs) - env.AppendUnique(LIBPATH=[abspath(lib_dir)]) - env.AppendUnique(RPATH=[abspath(lib_dir)]) - env.AppendUnique(CXXFLAGS=["-std=c++11"]) + env.AppendUnique(CPPPATH = include_dirs) + env.AppendUnique(CPPPATH = ['/opt/cuda/include']) # TODO fix this dirty hack + env.AppendUnique(LIBPATH = [abspath(lib_dir)]) + env.AppendUnique(RPATH = [abspath(lib_dir)]) + env.AppendUnique(CXXFLAGS = ["-std=c++14"]) conf = Configure(env) if not conf.CheckLibWithHeader("Tamaas", "tamaas.hh", language="CXX"): raise SCons.Errors.StopError( "Tamaas ({}) not found in {}".format(build_type, abspath(tm_path))) env['TAMAAS_PATH'] = abspath(tm_path) env = conf.Finish() diff --git a/src/surface/surface_generator_filter.cpp b/src/surface/surface_generator_filter.cpp index 9bf9a69..7c19b25 100644 --- a/src/surface/surface_generator_filter.cpp +++ b/src/surface/surface_generator_filter.cpp @@ -1,103 +1,99 @@ /** * @file * * @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 . * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "surface_generator_filter.hh" #include "fft_plan_manager.hh" #include "fftransform.hh" #include /* -------------------------------------------------------------------------- */ __BEGIN_TAMAAS__ /* -------------------------------------------------------------------------- */ template -SurfaceGeneratorFilter::~SurfaceGeneratorFilter() { - delete filter; -} +SurfaceGeneratorFilter::~SurfaceGeneratorFilter() = default; /* -------------------------------------------------------------------------- */ template void SurfaceGeneratorFilter::setFilter(Filter* new_f) { - if (filter != new_f) - delete filter; filter = new_f; } /* -------------------------------------------------------------------------- */ template void SurfaceGeneratorFilter::applyFilterOnSource() { GridHermitian fft_white_noise(this->filter_coefficients.sizes(), 1); FFTransform& wn_plan = FFTPlanManager::get().createPlan(this->white_noise, fft_white_noise); wn_plan.forwardTransform(); fft_white_noise *= filter_coefficients; FFTransform& surface_plan = FFTPlanManager::get().createPlan(this->grid, fft_white_noise); surface_plan.backwardTransform(); FFTPlanManager::get().destroyPlan(this->white_noise, fft_white_noise); FFTPlanManager::get().destroyPlan(this->grid, fft_white_noise); } /* -------------------------------------------------------------------------- */ template Grid& SurfaceGeneratorFilter::buildSurface() { if (this->grid.dataSize() == 0) TAMAAS_EXCEPTION("the size of the grid is zero, did you call setSizes() ?"); if (this->filter == nullptr) TAMAAS_EXCEPTION("filter is null, did you call setFilter() ?"); // Resizing arrays this->white_noise.resize(this->grid.sizes()); auto hermitian_dim = GridHermitian::hermitianDimensions(this->grid.sizes()); this->filter_coefficients.resize(hermitian_dim); /// Generating white noise with gaussian distribution this->generateWhiteNoise>(); /// Applying filters filter->computeFilter(this->filter_coefficients); this->applyFilterOnSource(); /// Normalizing surface for hrms independent of number of points this->grid *= std::sqrt(this->grid.dataSize()); return this->grid; } /* -------------------------------------------------------------------------- */ template class SurfaceGeneratorFilter<1>; template class SurfaceGeneratorFilter<2>; /* -------------------------------------------------------------------------- */ __END_TAMAAS__ diff --git a/src/surface/surface_generator_filter.hh b/src/surface/surface_generator_filter.hh index 728d441..884202d 100644 --- a/src/surface/surface_generator_filter.hh +++ b/src/surface/surface_generator_filter.hh @@ -1,81 +1,81 @@ /** * @file * * @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 . * */ /* -------------------------------------------------------------------------- */ #ifndef SURFACE_GENERATOR_FILTER_H #define SURFACE_GENERATOR_FILTER_H /* -------------------------------------------------------------------------- */ #include "filter.hh" #include "surface_generator.hh" #include "tamaas.hh" /* -------------------------------------------------------------------------- */ __BEGIN_TAMAAS__ template class SurfaceGeneratorFilter : public SurfaceGenerator { public: /// Default constructor SurfaceGeneratorFilter() = default; /// Destructor virtual ~SurfaceGeneratorFilter(); public: /// Build surface with Hu & Tonder algorithm Grid& buildSurface() override; /// Set filter object (need namespace for swig) void setFilter(::tamaas::Filter* new_filter); protected: /// Apply filter coefficients on white noise void applyFilterOnSource(); /// Generate white noise with given distribution template void generateWhiteNoise(); protected: - Filter* filter = nullptr; + Filter* filter = nullptr; ///< not owned GridHermitian filter_coefficients; Grid white_noise; }; /* -------------------------------------------------------------------------- */ /* Template implementations */ /* -------------------------------------------------------------------------- */ template template void SurfaceGeneratorFilter::generateWhiteNoise() { random_engine gen(this->random_seed); T distribution; for (auto& noise : white_noise) noise = distribution(gen); } __END_TAMAAS__ #endif diff --git a/tests/SConscript b/tests/SConscript index e0e8d1c..92b0c83 100644 --- a/tests/SConscript +++ b/tests/SConscript @@ -1,52 +1,51 @@ from __future__ import print_function from os.path import join, abspath Import('main_env') test_env = main_env.Clone( PRINT_CMD_LINE_FUNC=main_env['gen_print']("Copying", "red", main_env)) test_files = Split(""" run_tests.sh test_hertz_pressure.py test_westergaard.py test_patch_westergaard.py test_surface.py test_autocorrelation.py test_hertz_disp.py test_hertz_kato.py test_hertz_adhesion.py test_saturated_pressure.py test_fftransform.py test_bem_grid.py test_flood_fill.py """) src_dir = "#/tests" build_dir = 'build-' + main_env['build_type'] + '/tests' for file in test_files: source = join(src_dir, file) test_env.Command(file, source, Copy("$TARGET", "$SOURCE")) crit_env = main_env.Clone(tools=[criterion]) if 'SHCXXCOMSTR' in main_env: crit_env['CXXCOMSTR'] = main_env['SHCXXCOMSTR'] if 'SHLINKCOMSTR' in main_env: crit_env['LINKCOMSTR'] = main_env['SHLINKCOMSTR'] crit_env.AppendUnique(LIBS=['Tamaas'], LIBPATH=[abspath('build-' + main_env['build_type'] + '/src')]) cpp_test_files = Split(""" test_grid.cpp test_loop.cpp -test_cuda.cpp test_fft.cpp test_model.cpp """) for file in cpp_test_files: crit_env.Program(file)