sxs-collaboration / spectre

SpECTRE is a code for multi-scale, multi-physics problems in astrophysics and gravitational physics.
https://spectre-code.org
Other
158 stars 187 forks source link

Tensor expression to apply coordinate transformation #3704

Open nilsvu opened 2 years ago

nilsvu commented 2 years ago

Feature request:

I think it would be quite useful to have a function that applies a coordinate transformation to a tensor component, or to all components. Some specialized functions were implemented in PointwiseFunctions/GeneralRelativity/Transform.hpp, but they currently only work for a tnsr::ii and for the first index of a tnsr::ijj. My suggestions is to generalize these functions, possibly using tensor expressions, so they support expressions like these:

J^a_b X^b
J^a_b J^c_d T^bd
J^a_b J^{-1}^c_d T^b_c

Perhaps the answer to this issue is just to use a tensor-expression contraction, or maybe we can add tensor-expression functions to make these coordinate transformation even easier.

nilsvu commented 2 years ago

@macedo22 @nilsdeppe any thoughts on this?

macedo22 commented 2 years ago

@nilsleiffischer My first thought is that this sounds like a really nice use case, but I'm not sure if it's too soon to add this. I've been doing some benchmarking of different tensor equations written with TensorExpressions vs for loops lately, and for many equations, TEs are faster, but I've been seeing TEs run slower than loops for inner products when > 1 index is being summed over, and it gets worse with more indices to sum over. So, I would expect expressions like the ones you've shown where 2 or more indices are being summed over to be slower than with loops. Given that I imagine these functions are used in multiple places, I'm not sure it's wise to release TE inner products into the wild just yet. I can benchmark specific coordinate transformation cases like these, if that's something you and/or @nilsdeppe think is worth me doing. I just generated a bunch of benchmark cases involving inner products, and I plan to profile them with perf starting this week in order to try to understand why some of these inner products are slower with TEs.

@nilsdeppe What are your thoughts?

nilsdeppe commented 2 years ago

I think it's easier to just use TEs directly. Otherwise you have to make various assumptions about what people will want, etc. and that will cause us to have to implement several copies of the function, all to replace something that will be roughly as long as the TE itself.

macedo22 commented 2 years ago

Whoops, I jumped the gun thinking about runtime before implementation. Even though TEs could provide some amount of generalization for this, I agree with Nils that we would still need to implement multiple functions for different transformations and that it would be easier to use TEs directly wherever needed.