19 #if PETSC_VERSION_LESS_THAN(3, 14, 0) 23 mooseError(
"PETSc-3.14.0 or higher is required for using StochasticTools::POD.");
29 const std::string & extra_slepc_options,
31 : _parallel_storage(parallel_storage),
32 _extra_slepc_options(extra_slepc_options),
43 std::vector<Real> & singular_values,
45 const Real energy)
const 48 #if !PETSC_VERSION_LESS_THAN(3, 14, 0) 63 local_rows += row.second.size();
64 if (row.second.size())
65 snapshot_size = row.second[0].size();
67 global_rows = local_rows;
77 _communicator.
get(), local_rows, PETSC_DECIDE, global_rows, snapshot_size, NULL, &mat));
87 unsigned int counter = 0;
92 for (
const auto & snap : row.second)
94 std::vector<PetscInt> rows(snapshot_size, (counter++) + local_beg);
97 std::vector<PetscInt> columns(snapshot_size);
98 std::iota(std::begin(columns), std::end(columns), 0);
107 snap.get_values().data(),
113 LibmeshPetscCallA(
_communicator.
get(), MatAssemblyBegin(mat, MAT_FINAL_ASSEMBLY));
114 LibmeshPetscCallA(
_communicator.
get(), MatAssemblyEnd(mat, MAT_FINAL_ASSEMBLY));
124 LibmeshPetscCallA(
_communicator.
get(), DSSetParallel(ds, DS_PARALLEL_DISTRIBUTED));
132 LibmeshPetscCallA(
_communicator.
get(), SVDSetImplicitTranspose(svd, PETSC_TRUE));
141 SVDSetDimensions(svd,
143 std::min(2 * num_modes, global_rows),
144 std::min(2 * num_modes, global_rows)));
164 u.init(snapshot_size, local_snapsize,
false,
PARALLEL);
167 v.init(global_rows, local_rows,
false,
PARALLEL);
169 left_basis_functions.clear();
170 right_basis_functions.clear();
171 singular_values.clear();
173 singular_values.resize(nconv);
175 for (PetscInt
j = 0;
j < nconv; ++
j)
177 SVDGetSingularTriplet(svd,
j, &singular_values[
j], NULL, NULL));
183 left_basis_functions.resize(num_requested_modes);
184 right_basis_functions.resize(num_requested_modes);
185 for (PetscInt
j = 0; j < cast_int<PetscInt>(num_requested_modes); ++
j)
187 LibmeshPetscCallA(
_communicator.
get(), SVDGetSingularTriplet(svd,
j, NULL,
v.vec(), u.vec()));
188 u.localize(left_basis_functions[
j].get_values());
189 v.localize(right_basis_functions[
j].get_values());
207 const Real energy)
const 212 std::size_t num_requested_modes =
213 std::min((std::size_t)num_modes_compute, singular_values.size());
215 std::vector<Real> ev_sum(singular_values.begin(), singular_values.begin() + num_requested_modes);
216 std::partial_sum(ev_sum.cbegin(),
219 [](
Real sum,
Real ev) {
return sum + ev * ev; });
222 const Real threshold = energy;
223 for (num_modes = 0; num_modes < ev_sum.size(); ++num_modes)
224 if (ev_sum[num_modes] / ev_sum.back() > 1 - threshold)
227 return num_modes + 1;
void mooseError(Args &&... args)
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
PetscInt * numeric_petsc_cast(const numeric_index_type *p)
void libmesh_ignore(const Args &...)
std::unordered_map< unsigned int, std::vector< DenseVector< Real > > > & getStorage(const VariableName &variable)
Get the stored solution vectors for a given variable.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
void max(const T &r, T &o, Request &req) const
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
A Reporter which stores serialized solution fields for given variables in a distributed fashion...