ufl team mailing list archive
-
ufl team
-
Mailing list archive
-
Message #00435
Re: Evaluating tensor expressions
2008/10/21 Anders Logg <logg@xxxxxxxxx>:
> On Tue, Oct 21, 2008 at 05:27:55PM +0200, Anders Logg wrote:
>> Is there a simple way to evaluate tensor expressions? For example, if
>>
>> a = dot(v, u)*dx
>>
>> is there then a way to convert this to
>>
>> v[0]*u[0] + v[1]*u[1] + ...
>>
>> ?
>
> I found the following in Dot:
>
> def as_basic(self, dim, a, b):
> ii = Index()
> aa = a[ii] if (a.rank() == 1) else a[...,ii]
> bb = b[ii] if (b.rank() == 1) else b[ii,...]
> return aa*bb
>
> Why are the arguments dim, a and b required? A Dot already knows its
> operands.
>
> --
> Anders
>> On Tue, Oct 21, 2008 at 05:27:55PM +0200, Anders Logg wrote:
>> Is there a simple way to evaluate tensor expressions? For example, if
>>
>> a = dot(v, u)*dx
>>
>> is there then a way to convert this to
>>
>> v[0]*u[0] + v[1]*u[1] + ...
>>
>> ?
>
> I found the following in Dot:
>
> def as_basic(self, dim, a, b):
> ii = Index()
> aa = a[ii] if (a.rank() == 1) else a[...,ii]
> bb = b[ii] if (b.rank() == 1) else b[ii,...]
> return aa*bb
>
> Why are the arguments dim, a and b required? A Dot already knows its
> operands.
>
> --
> Anders
Because it is used in an algorithm that first expands its operands,
so a and b here are not necessarily its original operands.
As you see, dim is not used here, but it's used in some other Compounds.
These functions could of course also be placed in the algorithm
in question instead of in each Compound object, like with several
other algorithms. But I think that's a detail we can discuss later,
in context with other similar issues.
--
Martin
Follow ups
References