]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement function to merge substitution maps
authorJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 25 Apr 2019 06:57:02 +0000 (08:57 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Sat, 27 Apr 2019 08:37:43 +0000 (10:37 +0200)
include/deal.II/differentiation/sd/symengine_scalar_operations.h
source/differentiation/sd/symengine_scalar_operations.cc

index 51417f7d4f86c55c244e1408d78fe9169a422815..777ee737df7ec056ce2f97cb060f48fed8806a99 100644 (file)
@@ -435,6 +435,45 @@ namespace Differentiation
       const std::pair<SymbolicType, ValueType> &symbol_value,
       const Args &... other_symbol_values);
 
+    /**
+     * Concatenate two symbolic maps, merging a second map @p substitution_map_in
+     * in-place into the initial and resultant map @p substitution_map_out. The map
+     * @p substitution_map_out need not initially be empty.
+     *
+     * @note Duplicate symbols (keys) in the maps are permitted, so long as their
+     * values are equal. If this is not the case then an error will be thrown.
+     */
+    void
+    merge_substitution_maps(types::substitution_map &      substitution_map_out,
+                            const types::substitution_map &substitution_map_in);
+
+    /**
+     * Concatenate multiple symbolic maps, merging the maps @p substitution_map_in
+     * and @p other_substitution_maps_in, a collection of other maps,
+     * in-place into the resultant map @p substitution_map_out. The map
+     * @p substitution_map_out need not initially be empty.
+     *
+     * @note Duplicate symbols (keys) in the maps are permitted, so long as their
+     * values are equal. If this is not the case then an error will be thrown.
+     */
+    template <typename... Args>
+    void
+    merge_substitution_maps(types::substitution_map &      substitution_map_out,
+                            const types::substitution_map &substitution_map_in,
+                            const Args &... other_substitution_maps_in);
+
+    /**
+     * Concatenate multiple symbolic maps, merging the maps @p substitution_map_in
+     * and @p other_substitution_maps_in and returning the result.
+     *
+     * @note Duplicate symbols (keys) in the maps are permitted, so long as their
+     * values are equal. If this is not the case then an error will be thrown.
+     */
+    template <typename... Args>
+    types::substitution_map
+    merge_substitution_maps(const types::substitution_map &substitution_map_in,
+                            const Args &... other_substitution_maps_in);
+
     //@}
 
   } // namespace SD
@@ -611,6 +650,32 @@ namespace Differentiation
                                                       other_symbol_values...);
     }
 
+
+    template <typename... Args>
+    types::substitution_map
+    merge_substitution_maps(
+      const types::substitution_map &substitution_map_in_1,
+      const Args &... other_substitution_maps_in)
+    {
+      types::substitution_map substitution_map_out = substitution_map_in_1;
+      merge_substitution_maps(substitution_map_out,
+                              other_substitution_maps_in...);
+      return substitution_map_out;
+    }
+
+
+    template <typename... Args>
+    void
+    merge_substitution_maps(
+      types::substitution_map &      substitution_map_out,
+      const types::substitution_map &substitution_map_in_1,
+      const Args &... other_substitution_maps_in)
+    {
+      merge_substitution_maps(substitution_map_out, substitution_map_in_1);
+      merge_substitution_maps(substitution_map_out,
+                              other_substitution_maps_in...);
+    }
+
   } // namespace SD
 } // namespace Differentiation
 
index b9e898b5ac482fb022d7d6aefe2d5da8557de290..ea573e56946ce085fd721ee961d73b22c0e34b09 100644 (file)
@@ -120,6 +120,30 @@ namespace Differentiation
 
     } // namespace internal
 
+
+    /* ---------------- Symbolic substitution map enlargement --------------*/
+
+
+    void
+    merge_substitution_maps(types::substitution_map &      symb_map_out,
+                            const types::substitution_map &symb_map_in)
+    {
+      // Do this by hand so that we can perform some sanity checks
+      for (const auto &entry : symb_map_in)
+        {
+          const typename types::substitution_map::const_iterator it_other =
+            symb_map_out.find(entry.first);
+          if (it_other == symb_map_out.end())
+            symb_map_out.insert(std::make_pair(entry.first, entry.second));
+          else
+            {
+              Assert(SE::eq(*(entry.second.get_RCP()),
+                            *(it_other->second.get_RCP())),
+                     ExcMessage("Key already in map, but values don't match"));
+            }
+        }
+    }
+
   } // namespace SD
 } // namespace Differentiation
 

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.