diff --git a/src/SConscript b/src/SConscript
index 4ca9821..e6d2b16 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1,167 +1,168 @@
# -*- mode:python; coding: utf-8 -*-
# vim: set ft=python:
# @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 os
Import('main_env')
def prepend(path, list):
return [os.path.join(path, x) for x in list]
env = main_env.Clone()
# Core
core_list = """
fft_engine.cpp
grid.cpp
grid_hermitian.cpp
statistics.cpp
surface.cpp
tamaas.cpp
legacy_types.cpp
loop.cpp
computes.cpp
logger.cpp
""".split()
if env['legacy_bem']:
core_list.append('surface_statistics.cpp')
core_list = prepend('core', core_list)
info_file = main_env.Substfile('tamaas_info.cpp', 'tamaas_info.cpp.in')
core_list.append(info_file)
# Lib roughcontact
generator_list = """
surface_generator.cpp
surface_generator_filter.cpp
surface_generator_filter_fft.cpp
surface_generator_random_phase.cpp
isopowerlaw.cpp
regularized_powerlaw.cpp
""".split()
generator_list = prepend('surface', generator_list)
# Lib PERCOLATION
percolation_list = """
flood_fill.cpp
""".split()
percolation_list = prepend('percolation', percolation_list)
# BEM PERCOLATION
bem_list = """
bem_kato.cpp
bem_polonski.cpp
bem_gigi.cpp
bem_gigipol.cpp
bem_penalty.cpp
bem_uzawa.cpp
bem_fft_base.cpp
bem_functional.cpp
bem_meta_functional.cpp
elastic_energy_functional.cpp
exponential_adhesion_functional.cpp
squared_exponential_adhesion_functional.cpp
maugis_adhesion_functional.cpp
complimentary_term_functional.cpp
bem_grid.cpp
bem_grid_polonski.cpp
bem_grid_kato.cpp
bem_grid_teboulle.cpp
bem_grid_condat.cpp
""".split()
bem_list = prepend('bem', bem_list)
# Model
model_list = """
model.cpp
model_factory.cpp
model_type.cpp
model_template.cpp
+integral_operator.cpp
be_engine.cpp
westergaard.cpp
elastic_functional.cpp
meta_functional.cpp
adhesion_functional.cpp
volume_potential.cpp
kelvin.cpp
mindlin.cpp
boussinesq.cpp
elasto_plastic/isotropic_hardening.cpp
elasto_plastic/residual.cpp
integration/element.cpp
""".split()
model_list = prepend('model', model_list)
# Solvers
solvers_list = """
contact_solver.cpp
polonsky_keer_rey.cpp
kato_saturated.cpp
kato.cpp
beck_teboulle.cpp
condat.cpp
polonsky_keer_tan.cpp
ep_solver.cpp
epic.cpp
""".split()
solvers_list = prepend('solvers', solvers_list)
# GPU API
gpu_list = """
fftransform_cufft.cpp
""".split()
gpu_list = prepend('gpu', gpu_list)
# Assembling total list
rough_contact_list = \
core_list + generator_list + percolation_list + model_list + solvers_list
# Adding legacy code
if env['legacy_bem']:
rough_contact_list += bem_list
# Adding GPU if needed
if env['backend'] == 'cuda':
rough_contact_list += gpu_list
# Adding extra warnings for Tamaas base lib
env.AppendUnique(CXXFLAGS=['-Wextra'])
# Build library
libTamaas = env.SharedLibrary('Tamaas',
rough_contact_list,
SHLIBVERSION=env['version'])
# Defining alias for cpp builds
main_env.Alias('build-cpp', libTamaas)
# Specify install target to install lib
lib_prefix = os.path.join(env['prefix'], 'lib')
lib_install = env.InstallVersionedLib(target=lib_prefix,
source=libTamaas)
main_env.Alias('install-lib', lib_install)
# Export target for use in python builds
Export('libTamaas')
diff --git a/src/core/logger.cpp b/src/core/logger.cpp
index 32f8090..e187857 100644
--- a/src/core/logger.cpp
+++ b/src/core/logger.cpp
@@ -1,62 +1,78 @@
/**
* @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 .
*
*/
/* -------------------------------------------------------------------------- */
#include "logger.hh"
#include
#include
#include
/* -------------------------------------------------------------------------- */
namespace tamaas {
/* -------------------------------------------------------------------------- */
LogLevel Logger::current_level = LogLevel::info;
+template
+struct LogLevelTraits;
+
+#define LOGLVLTRAIT(val) \
+ template <> \
+ struct LogLevelTraits { \
+ static constexpr char repr[]{#val}; \
+ }; \
+ constexpr char LogLevelTraits::repr[]
+
+LOGLVLTRAIT(debug);
+LOGLVLTRAIT(info);
+LOGLVLTRAIT(warning);
+LOGLVLTRAIT(error);
+#undef LOGLVLTRAIT
+
std::ostream& operator<<(std::ostream& o, const LogLevel& val) {
switch (val) {
#define PRINT_LOGLEVEL(r, data, type) \
case data::type: \
- o << BOOST_PP_STRINGIZE(type); \
+ o << LogLevelTraits::repr; \
break;
BOOST_PP_SEQ_FOR_EACH(PRINT_LOGLEVEL, LogLevel,
(debug)(info)(warning)(error));
#undef PRINT_LOGLEVEL
}
return o;
}
Logger::~Logger() {
if (wish_level >= current_level) {
fprintf(stderr, "%s", stream.str().c_str());
fflush(stderr);
}
}
std::ostream& Logger::get(LogLevel level) {
wish_level = level;
// std::string name;
// stream << level << ": ";
return stream;
}
void Logger::setLevel(LogLevel level) { current_level = level; }
/* -------------------------------------------------------------------------- */
} // namespace tamaas
diff --git a/src/core/logger.cpp b/src/model/integral_operator.cpp
similarity index 51%
copy from src/core/logger.cpp
copy to src/model/integral_operator.cpp
index 32f8090..08d8def 100644
--- a/src/core/logger.cpp
+++ b/src/model/integral_operator.cpp
@@ -1,62 +1,58 @@
/**
* @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 .
*
*/
/* -------------------------------------------------------------------------- */
-#include "logger.hh"
-#include
-#include
-#include
+#include "integral_operator.hh"
+#include
/* -------------------------------------------------------------------------- */
namespace tamaas {
-/* -------------------------------------------------------------------------- */
-LogLevel Logger::current_level = LogLevel::info;
-std::ostream& operator<<(std::ostream& o, const LogLevel& val) {
+template
+struct kind_traits;
+
+#define KINDTRAITS(val) \
+ template <> \
+ struct kind_traits { \
+ static constexpr char repr[]{#val}; \
+ }; \
+ constexpr char kind_traits::repr[]
+KINDTRAITS(neumann);
+KINDTRAITS(dirichlet);
+#undef KINDTRAITS
+
+#define INTEGRAL_KINDS (neumann)(dirichlet)
+
+std::ostream& operator<<(std::ostream& o, const IntegralOperator::kind& val) {
switch (val) {
-#define PRINT_LOGLEVEL(r, data, type) \
- case data::type: \
- o << BOOST_PP_STRINGIZE(type); \
+#define PRINT_INTEGRAL_KIND(r, data, kind) \
+ case data::kind: \
+ o << kind_traits::repr; \
break;
- BOOST_PP_SEQ_FOR_EACH(PRINT_LOGLEVEL, LogLevel,
- (debug)(info)(warning)(error));
-#undef PRINT_LOGLEVEL
+ BOOST_PP_SEQ_FOR_EACH(PRINT_INTEGRAL_KIND, IntegralOperator,
+ INTEGRAL_KINDS);
+#undef PRINT_INTEGRAL_KIND
}
return o;
}
-Logger::~Logger() {
- if (wish_level >= current_level) {
- fprintf(stderr, "%s", stream.str().c_str());
- fflush(stderr);
- }
-}
-
-std::ostream& Logger::get(LogLevel level) {
- wish_level = level;
- // std::string name;
- // stream << level << ": ";
- return stream;
-}
+#undef INTEGRAL_KINDS
-void Logger::setLevel(LogLevel level) { current_level = level; }
-
-/* -------------------------------------------------------------------------- */
} // namespace tamaas
diff --git a/src/model/integral_operator.hh b/src/model/integral_operator.hh
index cc24709..c96436e 100644
--- a/src/model/integral_operator.hh
+++ b/src/model/integral_operator.hh
@@ -1,105 +1,87 @@
/**
* @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 .
*
*/
/* -------------------------------------------------------------------------- */
#ifndef INTEGRAL_OPERATOR_HH
#define INTEGRAL_OPERATOR_HH
/* -------------------------------------------------------------------------- */
#include "grid_base.hh"
#include "model_type.hh"
#include
#include
#include
/* -------------------------------------------------------------------------- */
namespace tamaas {
/* -------------------------------------------------------------------------- */
class Model;
/**
* @brief Generic class for integral operators
*/
class IntegralOperator {
public:
/// Kind of operator
enum kind { neumann, dirichlet };
public:
/// Constructor
IntegralOperator(Model* model) : model(model) {}
/// Virtual destructor for subclasses
virtual ~IntegralOperator() = default;
/// Apply operator on input
virtual void apply(GridBase& input, GridBase& output) const = 0;
/// Apply operator on filtered input
virtual void applyIf(GridBase& input, GridBase& output,
std::function) const {
apply(input, output);
}
/// Update any data dependent on model parameters
virtual void updateFromModel() = 0;
/// Get model
const Model& getModel() const { return *model; }
/// Kind
virtual kind getKind() const = 0;
/// Type
virtual model_type getType() const = 0;
/// Norm
virtual Real getOperatorNorm() {
TAMAAS_EXCEPTION("operator does not implement norm");
}
protected:
Model* model = nullptr;
};
/* -------------------------------------------------------------------------- */
/* Printing IntegralOperator::kind to string */
/* -------------------------------------------------------------------------- */
-#define INTEGRAL_KINDS (neumann)(dirichlet)
-
-inline std::ostream& operator<<(std::ostream& o,
- const IntegralOperator::kind& val) {
- switch (val) {
-#define PRINT_INTEGRAL_KIND(r, data, kind) \
- case data::kind: \
- o << BOOST_PP_STRINGIZE(kind); \
- break;
- BOOST_PP_SEQ_FOR_EACH(PRINT_INTEGRAL_KIND, IntegralOperator,
- INTEGRAL_KINDS);
-#undef PRINT_INTEGRAL_KIND
- }
- return o;
-}
-
-#undef INTEGRAL_KINDS
-
-/* -------------------------------------------------------------------------- */
+std::ostream& operator<<(std::ostream& o, const IntegralOperator::kind& val);
} // namespace tamaas
#endif // INTEGRAL_OPERATOR_HH
diff --git a/src/model/model_type.cpp b/src/model/model_type.cpp
index 4761a09..6d894a1 100644
--- a/src/model/model_type.cpp
+++ b/src/model/model_type.cpp
@@ -1,36 +1,43 @@
/**
* @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 .
*
*/
/* -------------------------------------------------------------------------- */
#include "model_type.hh"
/* -------------------------------------------------------------------------- */
namespace tamaas {
/* -------------------------------------------------------------------------- */
-std::vector model_type_traits::indices = {};
-std::vector model_type_traits::indices = {};
-std::vector model_type_traits::indices = {};
-std::vector model_type_traits::indices = {};
-std::vector model_type_traits::indices = {0};
-std::vector model_type_traits::indices = {0};
+const std::vector model_type_traits::indices = {};
+const std::vector model_type_traits::indices = {};
+const std::vector model_type_traits::indices = {};
+const std::vector model_type_traits::indices = {};
+const std::vector model_type_traits::indices = {0};
+const std::vector model_type_traits::indices = {0};
+
+constexpr char model_type_traits::repr[];
+constexpr char model_type_traits::repr[];
+constexpr char model_type_traits::repr[];
+constexpr char model_type_traits::repr[];
+constexpr char model_type_traits::repr[];
+constexpr char model_type_traits::repr[];
/* -------------------------------------------------------------------------- */
} // namespace tamaas
diff --git a/src/model/model_type.hh b/src/model/model_type.hh
index 8aa0d31..baca1cc 100644
--- a/src/model/model_type.hh
+++ b/src/model/model_type.hh
@@ -1,173 +1,175 @@
/**
* @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 .
*
*/
/* -------------------------------------------------------------------------- */
#ifndef __MODEL_TYPE_HH__
#define __MODEL_TYPE_HH__
/* -------------------------------------------------------------------------- */
#include "grid.hh"
#include "grid_base.hh"
#include "static_types.hh"
#include "tamaas.hh"
#include
#include
#include
#include
#include
/* -------------------------------------------------------------------------- */
namespace tamaas {
// clang-format off
/// Models types **for printing only**
#define TAMAAS_MODEL_TYPES \
- (basic_1d) \
- (basic_2d) \
- (surface_1d) \
- (surface_2d) \
- (volume_1d) \
+ (basic_1d) \
+ (basic_2d) \
+ (surface_1d) \
+ (surface_2d) \
+ (volume_1d) \
(volume_2d)
// clang-format on
/// Types for grid dimensions and number of components
enum class model_type {
basic_1d, ///< one component line
basic_2d, ///< one component surface
surface_1d, ///< two components line
surface_2d, ///< three components surface
volume_1d, ///< two components volume
volume_2d ///< three components volume
};
-inline std::ostream& operator<<(std::ostream& o, const model_type& val) {
- switch (val) {
-#define PRINT_MODEL_TYPE(r, data, type) \
- case data::type: \
- o << BOOST_PP_STRINGIZE(type); \
- break;
- BOOST_PP_SEQ_FOR_EACH(PRINT_MODEL_TYPE, model_type, TAMAAS_MODEL_TYPES);
-#undef PRINT_MODEL_TYPE
- }
- return o;
-}
-
/// Trait class to store physical dimension of domain, of boundary and
/// number of components
template
struct model_type_traits {};
#define MODEL_TYPE_TRAITS_MACRO(type, dim, comp, bdim) \
template <> \
struct model_type_traits { \
+ static constexpr char repr[]{#type}; \
static constexpr UInt dimension = dim; \
static constexpr UInt components = comp; \
static constexpr UInt boundary_dimension = bdim; \
static constexpr UInt voigt = voigt_size::value; \
- static std::vector indices; \
+ static const std::vector indices; \
}
MODEL_TYPE_TRAITS_MACRO(basic_1d, 1, 1, 1);
MODEL_TYPE_TRAITS_MACRO(basic_2d, 2, 1, 2);
MODEL_TYPE_TRAITS_MACRO(surface_1d, 1, 2, 1);
MODEL_TYPE_TRAITS_MACRO(surface_2d, 2, 3, 2);
MODEL_TYPE_TRAITS_MACRO(volume_1d, 2, 2, 1);
MODEL_TYPE_TRAITS_MACRO(volume_2d, 3, 3, 2);
#undef MODEL_TYPE_TRAITS_MACRO
namespace detail {
template
struct dim_choice
: std::integral_constant<
UInt, (boundary) ? model_type_traits::boundary_dimension
: model_type_traits::dimension> {};
} // namespace detail
template
std::unique_ptr::value>>
allocateGrid(Container&& n, UInt nc) {
return std::make_unique::value>>(
std::begin(n), std::end(n), nc);
}
#define ALLOC_GRID_CASE_MACRO(a, data, type) \
case data::type: { \
ptr = allocateGrid( \
n, model_type_traits::components); \
break; \
}
/// Helper function for grid allocation
template
std::unique_ptr> allocateGrid(model_type type, Container&& n) {
std::unique_ptr> ptr = nullptr;
switch (type) {
BOOST_PP_SEQ_FOR_EACH(ALLOC_GRID_CASE_MACRO, model_type,
TAMAAS_MODEL_TYPES);
}
return ptr;
}
#undef ALLOC_GRID_CASE_MACRO
#define ALLOC_GRID_CASE_MACRO(a, data, type) \
case data::type: { \
ptr = allocateGrid(n, nc); \
break; \
}
/// Helper function for grid allocation with
/// non-standard components
template
std::unique_ptr> allocateGrid(model_type type, Container&& n,
UInt nc) {
std::unique_ptr> ptr = nullptr;
switch (type) {
BOOST_PP_SEQ_FOR_EACH(ALLOC_GRID_CASE_MACRO, model_type,
TAMAAS_MODEL_TYPES);
}
return ptr;
}
+/// Print function for model_type
+inline std::ostream& operator<<(std::ostream& o, const model_type& val) {
+ switch (val) {
+#define PRINT_MODEL_TYPE(r, data, type) \
+ case data::type: \
+ o << model_type_traits::repr; \
+ break;
+ BOOST_PP_SEQ_FOR_EACH(PRINT_MODEL_TYPE, model_type, TAMAAS_MODEL_TYPES);
+#undef PRINT_MODEL_TYPE
+ }
+ return o;
+}
+
#undef ALLOC_GRID_CASE_MACRO
// clang-format off
#ifdef TAMAAS_MODEL_TYPES
#undef TAMAAS_MODEL_TYPES
#endif
#define TAMAAS_MODEL_TYPES \
(model_type::basic_1d) \
(model_type::basic_2d) \
(model_type::surface_1d) \
(model_type::surface_2d) \
(model_type::volume_1d) \
(model_type::volume_2d)
// clang-format on
} // namespace tamaas
/* --------------------------------------------------------------------------
*/
#endif // __MODEL_TYPE_HH__