From 84ff7d20a6a25d3fb4e42f076b3d90eb888f492b Mon Sep 17 00:00:00 2001 From: Pieter Collins Date: Wed, 6 Nov 2024 07:24:09 +0100 Subject: [PATCH] Allowed assignment of element of ScaledFunctionPatch from Function or FunctionPatch. --- source/function/function.cpp | 10 ++++++++-- source/function/scaled_function_patch.hpp | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/function/function.cpp b/source/function/function.cpp index f28d0362c..bd4027f42 100644 --- a/source/function/function.cpp +++ b/source/function/function.cpp @@ -396,8 +396,14 @@ template auto Function::get(SizeType i) const -> Scal template Void Function::set(SizeType i, ScalarFunction sf) { ARIADNE_ASSERT(iresult_size()); if constexpr (Same) { - const VectorOfScalarFunction& cvf = dynamic_cast,P,SIG>&>(this->_ptr.operator*()); - VectorOfScalarFunction& vf = const_cast&>(cvf); + const VectorOfScalarFunction* cvf = + dynamic_cast,P,SIG>*>(this->_ptr.operator->()); + if (cvf==nullptr) { + ARIADNE_THROW(std::runtime_error, + "Function::set(SizeType i, Function)", + "Cannot assign to component of vector-valued function "<<(*this)<<" as it is not a VectorOfScalarFunction."); + } + VectorOfScalarFunction& vf = const_cast&>(*cvf); vf[i]=sf; } else { ARIADNE_ASSERT((Same)); diff --git a/source/function/scaled_function_patch.hpp b/source/function/scaled_function_patch.hpp index 9443a43e9..0af5a80be 100644 --- a/source/function/scaled_function_patch.hpp +++ b/source/function/scaled_function_patch.hpp @@ -1192,6 +1192,7 @@ template class VectorScaledFunctionPatchElementReference , public ProvideConcreteGenericArithmeticOperators, ScalarMultivariateFunction> , public DispatchConcreteGenericAlgebraNumberOperations,NumericType,Number> { + using P=typename M::Paradigm; typedef M ModelType; typedef typename M::NumericType NumericType; typedef typename M::ErrorType ErrorType; @@ -1204,6 +1205,10 @@ template class VectorScaledFunctionPatchElementReference VectorScaledFunctionPatchElementReference(const VectorScaledFunctionPatchElementReference& x) = default; Void operator=(const VectorScaledFunctionPatchElementReference& x) { this->_c->set(this->_i,x._c->get(x._i)); } Void operator=(const ScalarScaledFunctionPatch& x) { this->_c->set(this->_i,x); } + Void operator=(const ScalarMultivariateFunctionPatch

x) { + ScalarScaledFunctionPatch sfp=factory(*this->_c).create(x); *this=sfp; } + Void operator=(const ScalarMultivariateFunction

x) { + ScalarScaledFunctionPatch sfp=factory(*this->_c).create(x); *this=sfp; } ScalarScaledFunctionPatch element() const { return this->_c->get(this->_i); } BoxDomainType const& domain() const { return this->_c->domain(); } const ModelType& model() const { return this->_c->_models[this->_i]; }