[Dune] passing functions as arguments
Aleksejs Fomins
aleksejs.fomins at lspr.ch
Fri Aug 15 18:20:30 CEST 2014
Dear Dune,
Sorry, I am still struggling with understanding how to use Dune::Function.
Very briefly, what I am trying to do is something like this:
------------------------------------------------------
class f1 : Dune::Function { // Define f1.evaluate }
class f2 : Dune::Function { // Define f2.evaluate }
class f3 : Dune::Function { // Define f3.evaluate }
double integral( Dune::Function g)
{
return g.evaluate(3) + g.evaluate(5) + g.evaluate(7);
}
int main()
{
cout << integral(f1) << integral(f2) << integral(f3);
}
------------------------------------------------------
I have a suspicion that if I write it this way, the generic evaluate
method from Dune::Function will be called inside the integral function.
Can you please suggest how to correctly use the Dune::Function class?
Regards,
Aleksejs
On 08/11/2014 11:46 AM, Aleksejs Fomins wrote:
> Hi Marcus,
>
> I had the idea to just define the functions/objects for each function I
> need to integrate, and then pass them as arguments. Do you think that
> might not work?
>
> Thanks,
> Aleksejs
>
> On 08/11/2014 10:47 AM, Markus Blatt wrote:
>> Somewhen in time the OP wrote:
>>>>> For that, the integrator procedure
>>>>> needs to sample from some function decided at runtime.
>>
>> On Mon, Aug 11, 2014 at 10:31:36AM +0200, Christian Engwer wrote:
>>> we have an interface class for functions in dune-common. I didn't
>>> have a look whether we have example as well. In any case I'd suggest
>>> to use this interface as it allows many other people to use it
>>> without modifying their code.
>>
>> I kind of have the feeling that this does not work with switching the
>> function at runtime.
>>
>> Markus
>>
>>>
>>> Christian
>>>
>>> On 11. August 2014 10:06:38 OEZ, Aleksejs Fomins <aleksejs.fomins at lspr.ch> wrote:
>>>> Dear Jayesh,
>>>>
>>>> Thank you for your link. I will read through it closer today.
>>>>
>>>> I would still like to know if there is really a problem with simply
>>>> passing functions as arguments, before I go into more complicated stuff
>>>>
>>>> Cheers,
>>>> Aleksejs
>>>>
>>>>
>>>>
>>>>
>>>> On 08/08/2014 06:10 PM, Jayesh Badwaik wrote:
>>>>> Hi,
>>>>>
>>>>> You have to use functors. You can see this for a basic reference:
>>>>> http://web.stanford.edu/class/cs106l/course-reader/Ch13_Functors.pdf
>>>>>
>>>>
>>>>
>>>> -------------------------------
>>>>
>>>> Dear Dune,
>>>>
>>>> I have decided to implement an approximate integration method
>>>> alternative to the Quadrature Rule. For that, the integrator procedure
>>>> needs to sample from some function decided at runtime.
>>>>
>>>> How would you approach such a construction?
>>>>
>>>> As in, should I pass function/object as parameter? Also, I was told
>>>> that
>>>> I should avoid using virtual functions when doing this.
>>>>
>>>> Regards,
>>>> Aleksejs
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>> _______________________________________________
>>>> Dune mailing list
>>>> Dune at dune-project.org
>>>> http://lists.dune-project.org/mailman/listinfo/dune
>>>
>>>
>>> _______________________________________________
>>> Dune mailing list
>>> Dune at dune-project.org
>>> http://lists.dune-project.org/mailman/listinfo/dune
>>>
>>
>>
>>
>> _______________________________________________
>> Dune mailing list
>> Dune at dune-project.org
>> http://lists.dune-project.org/mailman/listinfo/dune
>>
>
>
>
> _______________________________________________
> Dune mailing list
> Dune at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20140815/9a7e4e67/attachment.sig>
More information about the Dune
mailing list