]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add more utilities to convert from SymEngine types
authorJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 2 Apr 2020 09:13:25 +0000 (11:13 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Mon, 4 May 2020 13:46:02 +0000 (15:46 +0200)
include/deal.II/differentiation/sd/symengine_utilities.h
source/differentiation/sd/symengine_utilities.cc

index 0725503f58c72440e98ba5bb8234174fd76fd3f0..a2e211c41c3eb35e531aa22b453f2f9db3f9b82b 100644 (file)
@@ -1,6 +1,6 @@
 // ---------------------------------------------------------------------
 //
-// Copyright (C) 2019 by the deal.II authors
+// Copyright (C) 2019-2020 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
@@ -41,6 +41,13 @@ namespace Differentiation
       convert_expression_map_to_basic_map(
         const SD::types::substitution_map &substitution_map);
 
+      /**
+       * Convert to a map of Expressions from its SymEngine counterpart.
+       */
+      SD::types::substitution_map
+      convert_basic_map_to_expression_map(
+        const SymEngine::map_basic_basic &substitution_map);
+
       /**
        * Convert a vector of Expressions to its SymEngine counterpart.
        */
@@ -48,6 +55,21 @@ namespace Differentiation
       convert_expression_vector_to_basic_vector(
         const SD::types::symbol_vector &symbol_vector);
 
+      /**
+       * Convert to a vector of Expressions from its SymEngine counterpart.
+       */
+      SD::types::symbol_vector
+      convert_basic_vector_to_expression_vector(
+        const SymEngine::vec_basic &symbol_vector);
+
+      /**
+       * Convert to a vector of pairs of Expressions from its SymEngine
+       * counterpart.
+       */
+      std::vector<std::pair<Expression, Expression>>
+      convert_basic_pair_vector_to_expression_pair_vector(
+        const SymEngine::vec_pair &symbol_value_vector);
+
       /**
        * Extract the symbols (key entries) from a substitution map.
        *
index 9bf37986081379f64053b7507d6a6b69392afa7e..f47a4a2715aad53747b3a7afbe80c6ec6ce992c5 100644 (file)
@@ -1,6 +1,6 @@
 // ---------------------------------------------------------------------
 //
-// Copyright (C) 2019 by the deal.II authors
+// Copyright (C) 2019-2020 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
@@ -31,6 +31,7 @@ namespace Differentiation
     namespace Utilities
     {
 #  ifndef DOXYGEN
+
       SE::map_basic_basic
       convert_expression_map_to_basic_map(
         const SD::types::substitution_map &substitution_map)
@@ -40,7 +41,19 @@ namespace Differentiation
           sub_map[entry.first.get_RCP()] = entry.second.get_RCP();
         return sub_map;
       }
-#  endif
+
+
+
+      SD::types::substitution_map
+      convert_basic_map_to_expression_map(
+        const SymEngine::map_basic_basic &substitution_map)
+      {
+        SD::types::substitution_map sub_map;
+        for (const auto &entry : substitution_map)
+          sub_map[Expression(entry.first)] = SD::Expression(entry.second);
+        return sub_map;
+      }
+
 
 
       SE::vec_basic
@@ -55,7 +68,20 @@ namespace Differentiation
       }
 
 
-#  ifndef DOXYGEN
+
+      SD::types::symbol_vector
+      convert_basic_vector_to_expression_vector(
+        const SE::vec_basic &symbol_vector)
+      {
+        SD::types::symbol_vector symb_vec;
+        symb_vec.reserve(symbol_vector.size());
+        for (const auto &entry : symbol_vector)
+          symb_vec.push_back(SD::Expression(entry));
+        return symb_vec;
+      }
+
+
+
       SD::types::symbol_vector
       extract_symbols(const SD::types::substitution_map &substitution_values)
       {
@@ -67,7 +93,22 @@ namespace Differentiation
 
         return symbols;
       }
-#  endif
+
+
+
+      std::vector<std::pair<SD::Expression, SD::Expression>>
+      convert_basic_pair_vector_to_expression_pair_vector(
+        const SymEngine::vec_pair &symbol_value_vector)
+      {
+        std::vector<std::pair<SD::Expression, SD::Expression>> symb_val_vec;
+        symb_val_vec.reserve(symbol_value_vector.size());
+        for (const auto &entry : symbol_value_vector)
+          symb_val_vec.push_back(std::make_pair(SD::Expression(entry.first),
+                                                SD::Expression(entry.second)));
+        return symb_val_vec;
+      }
+
+#  endif // DOXYGEN
 
     } // namespace Utilities
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.