idaholab / moose

Multiphysics Object Oriented Simulation Environment
https://www.mooseframework.org
GNU Lesser General Public License v2.1
1.76k stars 1.05k forks source link

#20193 breaks compatiblity with Fastor tensors as MaterialProperties #20364

Open matthiasneuner opened 2 years ago

matthiasneuner commented 2 years ago

Bug Description

Hi, I used to be able to use Fastor (https://github.com/romeric/Fastor) tensors as MaterialProperties, implementing my own dataStore functions (https://github.com/matthiasneuner/chamois/blob/e07fb99bd2120198a800a1a088d37cef15d5d555/include/utils/FastorHelper.h#L36), see an example here: https://github.com/matthiasneuner/chamois/blob/e07fb99bd2120198a800a1a088d37cef15d5d555/src/kernels/GradientEnhancedMicropolarDamage.C#L50

However, it seems that recent commit 2e8a4feb5528fd359348a5f1c342024f3d0b0480 breaks this functionality, leading to completely strange clashes with AD (I am not using AD at all in any of my source files):

In file included from /home/matthias/anaconda3/envs/moose/include/Fastor/tensor/Tensor.h:190,                                                                                                                                                          
                 from /home/matthias/anaconda3/envs/moose/include/Fastor/Fastor.h:19,                                                                                                                                                                  
                 from /home/matthias/constitutiveModelling/CondaMoose/chamois/build/header_symlinks/FastorHelper.h:29,                                                                                                                                 
                 from /home/matthias/constitutiveModelling/CondaMoose/chamois/build/header_symlinks/FiniteStrainPressure.h:29,                                                                                                                         
                 from /home/matthias/constitutiveModelling/CondaMoose/chamois/src/bcs/FiniteStrainPressure.C:24,                                                                                                                                       
                 from /home/matthias/constitutiveModelling/CondaMoose/chamois/build/unity_src/bcs_Unity.C:2:                                                                                                                                           
/home/matthias/anaconda3/envs/moose/include/Fastor/tensor/TensorAssignment.h: In instantiation of 'void Fastor::assign(Fastor::AbstractTensor<Derived, DIM>&, const Fastor::Tensor<T, Rest ...>&) [with Derived = Fastor::Tensor<double, 3>; long unsig
ned int DIM = 1; T = MetaPhysicL::DualNumber<double, MetaPhysicL::SemiDynamicSparseNumberArray<double, long unsigned int, MetaPhysicL::NWrapper<50> >, true>; long unsigned int ...Rest = {3}]':                                                       
/home/matthias/anaconda3/envs/moose/include/Fastor/tensor/Tensor.h:99:15:   required from 'Fastor::Tensor<T, Rest>::Tensor(const Fastor::AbstractTensor<Derived, DIMS>&) [with Derived = Fastor::Tensor<MetaPhysicL::DualNumber<double, MetaPhysicL::Se
miDynamicSparseNumberArray<double, long unsigned int, MetaPhysicL::NWrapper<50> >, true>, 3>; long unsigned int DIMS = 1; typename std::enable_if<((((! has_tensor_view_v<Derived>) && (! has_tensor_fixed_view_2d_v<Derived>)) && (! has_tensor_fixed_
view_nd_v<Derived>)) || (DIMS != sizeof... (Rest))), bool>::type <anonymous> = false; T = double; long unsigned int ...Rest = {3}]'                                                                                                                    
/home/matthias/constitutiveModelling/CondaMoose/moose/framework/build/header_symlinks/MaterialProperty.h:223:7:   required from 'void moose::internal::rawValueEqualityHelper(T1&, const T2&) [with T1 = Fastor::Tensor<double, 3>; T2 = Fastor::Tensor
<MetaPhysicL::DualNumber<double, MetaPhysicL::SemiDynamicSparseNumberArray<double, long unsigned int, MetaPhysicL::NWrapper<50> >, true>, 3>]'                                                                                                         
/home/matthias/constitutiveModelling/CondaMoose/moose/framework/build/header_symlinks/MaterialProperty.h:315:44:   required from 'void MaterialPropertyBase<T, is_ad>::swap(PropertyValue*) [with T = Fastor::Tensor<double, 3>; bool is_ad = false]'  /home/matthias/constitutiveModelling/CondaMoose/moose/framework/build/header_symlinks/MaterialProperty.h:286:1:   required from here                                                                                                                   /home/matthias/anaconda3/envs/moose/include/Fastor/tensor/TensorAssignment.h:249:26: error: comparison between distinct pointer types 'double*' and 'MetaPhysicL::DualNumber<double, MetaPhysicL::SemiDynamicSparseNumberArray<double, long unsigned in
t, MetaPhysicL::NWrapper<50> >, true>*' lacks a cast [-fpermissive]                                                                                                                                                                                    
  249 |     if (dst.self().data()==src.data()) return;   

On the other hand, parent commit 7b6285b5791df4d1ddf0a91882c717a9305708f7 still works fine. Unfortunately, I am not that much a MOOSE/libMesh/AD pro, so I have no real idea what this type of error means and why it is caused at all, so I have not much hope in resolving that issue. Just want to leave that here in case somebody else has similar problems.

Steps to Reproduce

Switch from commit 7b6285b5791df4d1ddf0a91882c717a9305708f7 to 2e8a4feb5528fd359348a5f1c342024f3d0b0480 from #20193.

Impact

Cannot use Fastor tensors anymore as material properties.

loganharbour commented 2 years ago

Updated title and description to include the PR. Ping @dschwen

dschwen commented 2 years ago

Oh, yeah, I think there is a simple fix for that. We need a MooseADWrapper specialization. I think the specialization I added for std::array breaks for Fastor tensors (Fastor::Tensor<double, 3>) which also seem to match the pattern otherwise.

The MooseADWrapper is a helper structure to get the corresponding AD type for a non-AD type. This is required internally in the material property system.