World Builder  1.1.0-pre
A geodynamic initial conditions generator
grains.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018-2024 by the authors of the World Builder code.
3 
4  This file is part of the World Builder.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19 
20 #include "world_builder/grains.h"
21 
22 namespace WorldBuilder
23 {
24 
26 
27 
28  = default;
29 
30 
31  grains::grains(const std::vector<double> &vector,
32  const size_t number_of_grains,
33  const size_t start_entry)
34  {
35  sizes.resize(number_of_grains);
36  for (unsigned int i_grain = 0; i_grain < number_of_grains; i_grain++)
37  {
38  sizes[i_grain] = vector[start_entry+i_grain];
39  }
40 
41  rotation_matrices.resize(number_of_grains);
42  for (unsigned int i_grain = 0; i_grain < number_of_grains; i_grain++)
43  {
44  rotation_matrices[i_grain][0][0] = vector[start_entry+number_of_grains+i_grain*9];
45  rotation_matrices[i_grain][0][1] = vector[start_entry+number_of_grains+i_grain*9+1];
46  rotation_matrices[i_grain][0][2] = vector[start_entry+number_of_grains+i_grain*9+2];
47  rotation_matrices[i_grain][1][0] = vector[start_entry+number_of_grains+i_grain*9+3];
48  rotation_matrices[i_grain][1][1] = vector[start_entry+number_of_grains+i_grain*9+4];
49  rotation_matrices[i_grain][1][2] = vector[start_entry+number_of_grains+i_grain*9+5];
50  rotation_matrices[i_grain][2][0] = vector[start_entry+number_of_grains+i_grain*9+6];
51  rotation_matrices[i_grain][2][1] = vector[start_entry+number_of_grains+i_grain*9+7];
52  rotation_matrices[i_grain][2][2] = vector[start_entry+number_of_grains+i_grain*9+8];
53  }
54  }
55 
56 
57  void
58  grains::unroll_into(std::vector<double> &vector, const size_t start_entry) const
59  {
60  const size_t number_of_grains = sizes.size();
61 
62  for (unsigned int i_grain = 0; i_grain < number_of_grains; i_grain++)
63  {
64  vector[start_entry+i_grain] = sizes[i_grain];
65  }
66 
67  for (unsigned int i_grain = 0; i_grain < number_of_grains; i_grain++)
68  {
69  vector[start_entry+number_of_grains+i_grain*9] = rotation_matrices[i_grain][0][0];
70  vector[start_entry+number_of_grains+i_grain*9+1] = rotation_matrices[i_grain][0][1];
71  vector[start_entry+number_of_grains+i_grain*9+2] = rotation_matrices[i_grain][0][2];
72  vector[start_entry+number_of_grains+i_grain*9+3] = rotation_matrices[i_grain][1][0];
73  vector[start_entry+number_of_grains+i_grain*9+4] = rotation_matrices[i_grain][1][1];
74  vector[start_entry+number_of_grains+i_grain*9+5] = rotation_matrices[i_grain][1][2];
75  vector[start_entry+number_of_grains+i_grain*9+6] = rotation_matrices[i_grain][2][0];
76  vector[start_entry+number_of_grains+i_grain*9+7] = rotation_matrices[i_grain][2][1];
77  vector[start_entry+number_of_grains+i_grain*9+8] = rotation_matrices[i_grain][2][2];
78  }
79  }
80 } // namespace WorldBuilder
std::vector< double > sizes
Definition: grains.h:47
std::vector< std::array< std::array< double, 3 >, 3 > > rotation_matrices
Definition: grains.h:51
void unroll_into(std::vector< double > &vector, const size_t start_entry=0) const
Definition: grains.cc:58