Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
symengine_utilities.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_differentiation_sd_symengine_utilities_h
17 #define dealii_differentiation_sd_symengine_utilities_h
18 
19 #include <deal.II/base/config.h>
20 
21 #ifdef DEAL_II_WITH_SYMENGINE
22 
23 # include <deal.II/differentiation/sd/symengine_number_types.h>
24 # include <deal.II/differentiation/sd/symengine_types.h>
25 
26 # include <symengine/basic.h>
27 # include <symengine/dict.h>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 namespace Differentiation
32 {
33  namespace SD
34  {
35  namespace Utilities
36  {
40  SymEngine::map_basic_basic
41  convert_expression_map_to_basic_map(
42  const SD::types::substitution_map &substitution_map);
43 
47  SymEngine::vec_basic
48  convert_expression_vector_to_basic_vector(
49  const SD::types::symbol_vector &symbol_vector);
50 
60  SD::types::symbol_vector
61  extract_symbols(const SD::types::substitution_map &substitution_values);
62 
74  template <typename NumberType, typename ExpressionType = SD::Expression>
75  std::vector<NumberType>
76  extract_values(const SD::types::substitution_map &substitution_values);
77 
81  template <typename StreamType>
82  StreamType &
83  print_substitution_map(
84  StreamType & stream,
85  const SD::types::substitution_map &symbol_value_map);
86 
87  } // namespace Utilities
88 
89  } // namespace SD
90 } // namespace Differentiation
91 
92 
93 /* -------------------- inline and template functions ------------------ */
94 
95 
96 # ifndef DOXYGEN
97 
98 
99 namespace Differentiation
100 {
101  namespace SD
102  {
103  namespace Utilities
104  {
105  template <typename NumberType, typename ExpressionType>
106  std::vector<NumberType>
107  extract_values(const SD::types::substitution_map &substitution_values)
108  {
109  std::vector<NumberType> values;
110  values.reserve(substitution_values.size());
111 
112  for (const auto &entry : substitution_values)
113  values.push_back(
114  static_cast<NumberType>(ExpressionType(entry.second)));
115 
116  return values;
117  }
118 
119 
120  template <typename StreamType>
121  StreamType &
122  print_substitution_map(
123  StreamType & stream,
124  const SD::types::substitution_map &symbol_value_map)
125  {
126  for (const auto &entry : symbol_value_map)
127  stream << entry.first << " = " << entry.second << "\n";
128 
129  stream << std::flush;
130  return stream;
131  }
132 
133  } // namespace Utilities
134 
135  } // namespace SD
136 } // namespace Differentiation
137 
138 
139 # endif // DOXYGEN
140 
141 
142 DEAL_II_NAMESPACE_CLOSE
143 
144 #endif // DEAL_II_WITH_SYMENGINE
145 
146 #endif // dealii_differentiation_sd_symengine_utilities_h
Definition: cuda.h:31