Dear Wolfgang, Here is a simple test code (I also attached the source code):
int main() { using namespace dealii; const unsigned int *matrix_dimension* = 4; Tensor<2, matrix_dimension> myTensor; FullMatrix<double> myMatrix(matrix_dimension, matrix_dimension); for (unsigned int i = 0; i < matrix_dimension; i++) for (unsigned int j = 0; j < matrix_dimension; j++) { myMatrix(i,j) = i + j; } myMatrix.copy_to(myTensor); std::cout << myTensor.dimension << std::endl; return 0; } When *matrix_dimension =*2 or 3, the code works fine. When *matrix_dimension *= 4, it has a linking error as below: *error: undefined reference to 'void dealii::FullMatrix<double>::copy_to<4>(dealii::Tensor<2, 4, double>&, unsigned long, unsigned long, unsigned long, unsigned long, unsigned int, unsigned int) const'collect2: error: ld returned 1 exit statusmake[3]: *** [CMakeFiles/main.dir/build.make:116: main] Error 1* The version of deal.ii is 9.4.0. I looked into the source code. Indeed, in "full_matrix.h", there is a declaration of "copy_to". However, the actual implementation is not in "/dealii-9.4.0/src/source/lac/full_matrix.cc", but in "/dealii-9.4.0/src/source/lac/full_matrix.inst.in" *for (S : REAL_SCALARS) { template void FullMatrix<S>::copy_to<1>(Tensor<2, 1> &, const size_type, const size_type, const size_type, const size_type, const unsigned int, const unsigned int) const; template void FullMatrix<S>::copy_to<2>(Tensor<2, 2> &, const size_type, const size_type, const size_type, const size_type, const unsigned int, const unsigned int) const; template void FullMatrix<S>::copy_to<3>(Tensor<2, 3> &, const size_type, const size_type, const size_type, const size_type, const unsigned int, const unsigned int) const; }* I assume this is related with explicit instantiation? Best, Tao On Wednesday, June 7, 2023 at 10:38:35 AM UTC-4 Wolfgang Bangerth wrote: > On 6/6/23 15:46, Tao Jin wrote: > > > > However, the above copy_to() function only works when the tensor > dimension is > > less or equal to 3, that is, > > Tensor<2, dim>, dim <=3. > > When dim is larger than 3, I have to use for loops to copy each matrix > entry > > into the rank-2 tensor. > > What happens for dim>3? You only say "it only works when", but you don't > describe what goes wrong if dim>3? > > > > I know that it is typical to set dim as 2 or 3. However, does it make > sense to > > make FullMatrix::copy_to() work for a general rank-2 tensor? > > I see no reason why this should not work. The function is implemented in > the > full_matrix.h file, so I believe it should just work if you call the > function > on tensors that are larger than 3x3. > > Best > W. > > -- > ------------------------------------------------------------------------ > Wolfgang Bangerth email: bang...@colostate.edu > www: http://www.math.colostate.edu/~bangerth/ > > > -- The deal.II project is located at http://www.dealii.org/ For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en --- You received this message because you are subscribed to the Google Groups "deal.II User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to dealii+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/447fb768-3783-4dac-805f-89ec14773fc7n%40googlegroups.com.
/* --------------------------------------------------------------------- * * Copyright (C) 2006 - 2020 by the deal.II authors * * This file is part of the deal.II library. * * The deal.II library is free software; you can use it, redistribute * it, and/or modify it under the terms of the GNU Lesser General * Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * The full text of the license can be found in the file LICENSE.md at * the top level directory of deal.II. * * --------------------------------------------------------------------- * * Author: Tao Jin * University of Ottawa, Ottawa, Ontario, Canada * June 2023 */ // In this example, we test the copy_to member function of // FullMatrix #include <deal.II/lac/full_matrix.h> #include <deal.II/base/tensor.h> int main() { using namespace dealii; const unsigned int matrix_dimension = 4; Tensor<2, matrix_dimension> myTensor; FullMatrix<double> myMatrix(matrix_dimension, matrix_dimension); for (unsigned int i = 0; i < matrix_dimension; i++) for (unsigned int j = 0; j < matrix_dimension; j++) { myMatrix(i,j) = i + j; } myMatrix.copy_to(myTensor); std::cout << myTensor.dimension << std::endl; return 0; }