1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
// ------------------------------------------------------------------------
//
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (C) 2025 by the deal.II authors
//
// This file is part of the deal.II library.
//
// Part of the source code is dual licensed under Apache-2.0 WITH
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
// governing the source code and code contributions can be found in
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
//
// ------------------------------------------------------------------------
// It is very inefficient in the module system to have repeated
// #includes in many module partition files because when you 'import'
// those partitions, you also have to load everything they
// #included. In other words, you get the same content *many times*,
// once from each imported partition, rather than only once via the
// old-style #include system. We deal with this by wrapping all of our
// external packages into partitions that we can 'import' wherever we
// need.
// This is the file that wraps everything we need from ADOL-C into one
// module partition.
module;
#include <deal.II/base/config.h>
#ifdef DEAL_II_WITH_ADOLC
# include <adolc/adolc_fatalerror.h>
# include <adolc/adouble.h> // Taped double
# include <adolc/adtl.h> // Tapeless double
# include <adolc/drivers/drivers.h>
# include <adolc/internal/adolc_settings.h>
# include <adolc/internal/adubfunc.h> // Taped double math functions
# include <adolc/internal/usrparms.h>
# include <adolc/taping.h>
#endif
export module dealii.external.adolc;
#ifdef DEAL_II_WITH_ADOLC
export
{
using ::adouble;
using ::adub;
using ::badouble;
using ::cachedTraceTags;
using ::FatalError;
using ::function;
using ::gradient;
using ::hessian;
using ::jacobian;
using ::removeTape;
using ::TapeRemovalType;
using ::tapestats;
using ::trace_off;
using ::trace_on;
namespace adtl
{
using ::adtl::adouble;
using ::adtl::fabs;
using ::adtl::getNumDir;
using ::adtl::setNumDir;
} // namespace adtl
}
// ADOL-C also defines symbols that are either
// implemented as macros, or perhaps as constants in header
// files. In the former case, they cannot be referenced in 'using'
// expressions, and so we need to work around things by creating
// *variables* of the same names. In the latter case, they are often
// implemented as constants with internal linkage that we can't
// re-export (e.g., if they are members of anonymous enums).
//
// Dealing with this situation requires creating some other set of
// variable, undefining the macro names, and then creating variables
// with the same names as the macro names. Because we would end up
// with name clashes if these new variables were in the global
// namespace for those MPI implementations that implement things as
// variables in the global namespace, we put everything into the
// dealii namespace.
//
// We put the exportable symbols into namespace 'dealii'. This is
// necessary for cases where the symbol we create is derived not from
// a preprocessor macro, but for example as a member of an anonymous
// enum. Such symbols can't be exported, so we declare a variable that
// we *can* export, but it will not have the type of the enum, but of
// the underlying int. The compiler will therefore complain that the
// variable we're creating here redeclares another one but with a
// different type. We can avoid this by putting things into our own
// namespace.
# define CREATE_EXPORTABLE_PREPROCESSOR_SYMBOL(sym) \
namespace dealii \
{ \
namespace Adolc_Macros \
{ \
[[maybe_unused]] const auto exportable_##sym = sym; \
} \
} // namespace dealii
# define EXPORT_PREPROCESSOR_SYMBOL(sym) \
namespace dealii \
{ \
export const auto &sym = dealii::Adolc_Macros::exportable_##sym; \
}
CREATE_EXPORTABLE_PREPROCESSOR_SYMBOL(TBUFNUM)
# undef TBUFNUM
EXPORT_PREPROCESSOR_SYMBOL(TBUFNUM)
#endif
|