From be19e76039d16e70c936fe932c943276d2492a45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Mon, 4 Apr 2022 15:26:52 +0200
Subject: [PATCH] Specialize call for the case of a single function and a
 single zone

Call was ambiguous without it:
 interpolate: mesh*(zone...)*Vh_type*(function...) -> Vh
 interpolate: mesh*(zone...)*Vh_type*function -> Vh
---
 src/language/modules/SchemeModule.cpp | 34 +++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/language/modules/SchemeModule.cpp b/src/language/modules/SchemeModule.cpp
index 08df9ba86..5d3972239 100644
--- a/src/language/modules/SchemeModule.cpp
+++ b/src/language/modules/SchemeModule.cpp
@@ -243,6 +243,40 @@ SchemeModule::SchemeModule()
 
                               ));
 
+  this
+    ->_addBuiltinFunction("interpolate",
+                          std::make_shared<BuiltinFunctionEmbedder<
+                            std::shared_ptr<const IDiscreteFunction>(std::shared_ptr<const IMesh>,
+                                                                     std::shared_ptr<const IZoneDescriptor>,
+                                                                     std::shared_ptr<const IDiscreteFunctionDescriptor>,
+                                                                     const FunctionSymbolId&)>>(
+                            [](std::shared_ptr<const IMesh> mesh,
+                               std::shared_ptr<const IZoneDescriptor> interpolation_zone,
+                               std::shared_ptr<const IDiscreteFunctionDescriptor> discrete_function_descriptor,
+                               const FunctionSymbolId& function_id) -> std::shared_ptr<const IDiscreteFunction> {
+                              switch (discrete_function_descriptor->type()) {
+                              case DiscreteFunctionType::P0: {
+                                return DiscreteFunctionInterpoler{mesh,
+                                                                  {interpolation_zone},
+                                                                  discrete_function_descriptor,
+                                                                  function_id}
+                                  .interpolate();
+                              }
+                              case DiscreteFunctionType::P0Vector: {
+                                return DiscreteFunctionVectorInterpoler{mesh,
+                                                                        {interpolation_zone},
+                                                                        discrete_function_descriptor,
+                                                                        {function_id}}
+                                  .interpolate();
+                              }
+                              default: {
+                                throw NormalError("invalid function descriptor type");
+                              }
+                              }
+                            }
+
+                            ));
+
   this->_addBuiltinFunction("randomizeMesh",
                             std::make_shared<BuiltinFunctionEmbedder<std::shared_ptr<
                               const IMesh>(std::shared_ptr<const IMesh>,
-- 
GitLab