deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
petsc_ts.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2023 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_petsc_ts_h
14#define dealii_petsc_ts_h
15
16#include <deal.II/base/config.h>
17
18#ifdef DEAL_II_WITH_PETSC
19# include <deal.II/base/mpi.h>
22
26
27# include <petscts.h>
28
29# include <exception>
30
31# if defined(DEAL_II_HAVE_CXX20)
32# include <concepts>
33# endif
34
35#endif // DEAL_II_WITH_PETSC
36
38
39#ifdef DEAL_II_WITH_PETSC
40namespace PETScWrappers
41{
46 {
47 public:
53 using real_type = PetscReal;
54
90 // Running parameters
91 const std::string &options_prefix = "",
92 const std::string &ts_type = "",
93 const real_type initial_time = 0.0,
94 const real_type final_time = 0.0,
95 const real_type initial_step_size = 0.0,
96 const int max_steps = -1,
97 const bool match_step = false,
98 const bool restart_if_remesh = false,
99 // Error parameters
100 const std::string &ts_adapt_type = "none",
101 const real_type minimum_step_size = -1.0,
102 const real_type maximum_step_size = -1.0,
103 const real_type absolute_tolerance = -1.0,
104 const real_type relative_tolerance = -1.0,
105 const bool ignore_algebraic_lte = true)
120 {}
121
125 void
127
131 std::string options_prefix;
132
136 std::string ts_type;
137
142
147
154
161
166
171
175 std::string ts_adapt_type;
176
183
190
197
204
209 };
210
327 template <typename VectorType = PETScWrappers::VectorBase,
328 typename PMatrixType = PETScWrappers::MatrixBase,
329 typename AMatrixType = PMatrixType>
330# if defined(DEAL_II_HAVE_CXX20) && \
331 !defined(DEAL_II_DOXYGEN_DO_NOT_PARSE_REQUIRES_CLAUSES)
333 std::constructible_from<VectorType, Vec>) &&
335 std::constructible_from<PMatrixType, Mat>) &&
337 std::constructible_from<AMatrixType, Mat>))
338# endif
340 {
341 public:
347 using real_type = PetscReal;
348
353 const MPI_Comm mpi_comm = PETSC_COMM_WORLD);
354
359
365 operator TS() const;
366
370 TS
372
378
382 void
384
389 void
391
404 void
405 set_matrix(PMatrixType &P);
406
412 void
413 set_matrices(AMatrixType &A, PMatrixType &P);
414
420
426
430 unsigned int
432
440 unsigned int
441 solve(VectorType &y);
442
452 unsigned int
453 solve(VectorType &y, PMatrixType &P);
454
465 unsigned int
466 solve(VectorType &y, AMatrixType &A, PMatrixType &P);
467
476 std::function<void(const real_type t,
477 const VectorType &y,
478 const VectorType &y_dot,
479 VectorType &res)>
481
496 std::function<void(const real_type t,
497 const VectorType &y,
498 const VectorType &y_dot,
499 const real_type alpha,
500 AMatrixType &A,
501 PMatrixType &P)>
503
512 std::function<void(const real_type t, const VectorType &y, VectorType &res)>
514
524 std::function<void(const real_type t,
525 const VectorType &y,
526 AMatrixType &A,
527 PMatrixType &P)>
529
541 std::function<void(const real_type t,
542 const VectorType &y,
543 const unsigned int step_number)>
545
565 std::function<void(const real_type t,
566 const VectorType &y,
567 const VectorType &ydot,
568 const real_type alpha)>
570
582 std::function<void(const VectorType &src, VectorType &dst)>
584
616
622 std::function<void(const real_type t, VectorType &y)> distribute;
623
642 std::function<void(const real_type t, VectorType &y)>
644
653 std::function<void(const real_type t,
654 const unsigned int step,
655 const VectorType &y,
656 bool &resize)>
658
678 std::function<
679 bool(const real_type t, const unsigned int step, const VectorType &y)>
681
687 std::function<void(const std::vector<VectorType> &all_in,
688 std::vector<VectorType> &all_out)>
690
706 std::function<void(const real_type t,
707 const std::vector<VectorType> &all_in,
708 std::vector<VectorType> &all_out)>
710
711 private:
715 TS ts;
716
722
727
733
738
743
749 mutable std::exception_ptr pending_exception;
750
755
763 void
765
773 void
774 setup_algebraic_constraints(const VectorType &y);
775 };
776
777} // namespace PETScWrappers
778
779#endif // DEAL_II_WITH_PETSC
780
782
783#endif
void add_parameters(ParameterHandler &prm)
void reinit(const TimeStepperData &data)
std::exception_ptr pending_exception
Definition petsc_ts.h:749
unsigned int solve(VectorType &y, PMatrixType &P)
std::function< void(const real_type t, const unsigned int step, const VectorType &y, bool &resize)> decide_for_coarsening_and_refinement
Definition petsc_ts.h:657
void setup_algebraic_constraints(const VectorType &y)
std::function< void(const real_type t, const VectorType &y, const VectorType &y_dot, VectorType &res)> implicit_function
Definition petsc_ts.h:480
MPI_Comm get_mpi_communicator() const
std::function< void(const real_type t, VectorType &y)> update_constrained_components
Definition petsc_ts.h:643
std::function< void(const real_type t, const std::vector< VectorType > &all_in, std::vector< VectorType > &all_out)> transfer_solution_vectors_to_new_mesh
Definition petsc_ts.h:709
std::function< void(const real_type t, const VectorType &y, AMatrixType &A, PMatrixType &P)> explicit_jacobian
Definition petsc_ts.h:528
std::function< bool(const real_type t, const unsigned int step, const VectorType &y)> decide_and_prepare_for_remeshing
Definition petsc_ts.h:680
unsigned int get_step_number()
TimeStepper(const TimeStepperData &data=TimeStepperData(), const MPI_Comm mpi_comm=PETSC_COMM_WORLD)
unsigned int solve(VectorType &y, AMatrixType &A, PMatrixType &P)
std::function< void(const real_type t, const VectorType &y, const unsigned int step_number)> monitor
Definition petsc_ts.h:544
std::function< void(const real_type t, const VectorType &y, const VectorType &y_dot, const real_type alpha, AMatrixType &A, PMatrixType &P)> implicit_jacobian
Definition petsc_ts.h:502
std::function< IndexSet()> algebraic_components
Definition petsc_ts.h:615
ObserverPointer< PMatrixType, TimeStepper > P
Definition petsc_ts.h:721
std::function< void(const real_type t, VectorType &y)> distribute
Definition petsc_ts.h:622
std::function< void(const real_type t, const VectorType &y, const VectorType &ydot, const real_type alpha)> setup_jacobian
Definition petsc_ts.h:569
std::function< void(const real_type t, const VectorType &y, VectorType &res)> explicit_function
Definition petsc_ts.h:513
unsigned int solve(VectorType &y)
std::function< void(const VectorType &src, VectorType &dst)> solve_with_jacobian
Definition petsc_ts.h:583
ObserverPointer< AMatrixType, TimeStepper > A
Definition petsc_ts.h:720
void set_matrices(AMatrixType &A, PMatrixType &P)
PreconditionShell solve_with_jacobian_pc
Definition petsc_ts.h:726
std::function< void(const std::vector< VectorType > &all_in, std::vector< VectorType > &all_out)> interpolate
Definition petsc_ts.h:689
void set_matrix(PMatrixType &P)
#define DEAL_II_DEPRECATED
Definition config.h:294
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
TimeStepperData(const std::string &options_prefix="", const std::string &ts_type="", const real_type initial_time=0.0, const real_type final_time=0.0, const real_type initial_step_size=0.0, const int max_steps=-1, const bool match_step=false, const bool restart_if_remesh=false, const std::string &ts_adapt_type="none", const real_type minimum_step_size=-1.0, const real_type maximum_step_size=-1.0, const real_type absolute_tolerance=-1.0, const real_type relative_tolerance=-1.0, const bool ignore_algebraic_lte=true)
Definition petsc_ts.h:89
std::vector< index_type > data
Definition mpi.cc:734