Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
leapfrog.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes 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 GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Andrea Cassara <andrea.cassara@mail.polimi.it>
22// Author: Francesco Barrale <francesco.barrale@mail.polimi.it>
23// Author: Pedro Peixoto <ppeixoto@usp.br>
24// Author: Samuele Vincenzo Angelone <samuelevincenzo.angelone@mail.polimi.it>
25
26#ifndef VULPES_TIMEINTEGRATION_LEAPFROG_HPP_
27#define VULPES_TIMEINTEGRATION_LEAPFROG_HPP_
28
29#include <functional>
30
33#include "vulpes/la/vector.hpp"
34
35namespace vulpes {
36namespace timeintegration {
37
56 public:
57 using real_t = PetscScalar;
58 using ForceFunc = std::function<void(real_t, la::Vector&)>;
59
71 real_t time_step,
72 real_t initial_time,
73 real_t final_time,
74 const la::SparseMatrix& lin_op,
75 const la::SparseMatrix& mass,
76 const la::Vector& u0,
77 const la::Vector& v0,
78 const ForceFunc& force_func);
79
80 void step();
81
85 la::LinearSolver::Type solver_type,
87 m_solver_type = solver_type;
88 m_pc_type = pc_type;
89 m_solver_ready = false;
90 }
91
92 auto& getSolver() { return m_solver; }
93 const la::Vector& getSolution() const { return m_u; };
96 real_t time() const { return m_time; }
97 real_t finalTime() const { return m_final_time; }
98
99 private:
100 void setupSolver();
101
106 PetscInt m_iter = 0;
107
110
111 // M - h^2 A / 2
113
116 // w = M du/dt
118 la::Vector* m_f_old = nullptr;
119 la::Vector* m_f_new = nullptr;
124
128 bool m_solver_ready = false;
129
131};
132
133} // namespace timeintegration
134} // namespace vulpes
135
136#endif // VULPES_TIMEINTEGRATION_LEAPFROG_HPP_
A linear solver class wrapping PETSc KSP solvers.
Definition linear_solver.hpp:47
Type
Enumeration of available solver types.
Definition linear_solver.hpp:52
@ PrecondOnly
Definition linear_solver.hpp:57
PrecondType
Enumeration of available preconditioner types.
Definition linear_solver.hpp:63
@ MUMPS
Definition linear_solver.hpp:74
Definition sparse_matrix.hpp:52
A wrapper around PETSc Vec for distributed vectors.
Definition vector.hpp:54
void step()
Definition leapfrog.cpp:86
real_t m_time_step
Definition leapfrog.hpp:102
la::LinearSolver::PrecondType m_pc_type
Definition leapfrog.hpp:127
real_t m_initial_time
Definition leapfrog.hpp:103
la::SparseMatrix m_RHS
Definition leapfrog.hpp:112
const la::SparseMatrix & m_mass
Definition leapfrog.hpp:108
la::Vector m_f_1
Definition leapfrog.hpp:120
la::Vector getVelocity()
Velocity du/dt, obtained solving a system with M.
Definition leapfrog.cpp:77
const la::Vector & getSolution() const
Definition leapfrog.hpp:93
la::Vector m_u
Definition leapfrog.hpp:114
la::Vector * m_f_old
Definition leapfrog.hpp:118
la::LinearSolver::Type m_solver_type
Definition leapfrog.hpp:126
PetscScalar real_t
Definition leapfrog.hpp:57
la::Vector m_rhs
Definition leapfrog.hpp:123
la::Vector m_w
Definition leapfrog.hpp:117
const ForceFunc m_force_func
Definition leapfrog.hpp:130
real_t time() const
Definition leapfrog.hpp:96
la::LinearSolver m_solver
Definition leapfrog.hpp:125
la::Vector * m_f_new
Definition leapfrog.hpp:119
auto & getSolver()
Definition leapfrog.hpp:92
bool m_solver_ready
Definition leapfrog.hpp:128
LeapfrogSolver(real_t time_step, real_t initial_time, real_t final_time, const la::SparseMatrix &lin_op, const la::SparseMatrix &mass, const la::Vector &u0, const la::Vector &v0, const ForceFunc &force_func)
Definition leapfrog.cpp:35
la::Vector m_f_2
Definition leapfrog.hpp:121
la::Vector m_tmp
Definition leapfrog.hpp:122
const la::SparseMatrix & m_lin_op
Definition leapfrog.hpp:109
void setupSolver()
Definition leapfrog.cpp:70
la::Vector m_u_old
Definition leapfrog.hpp:115
real_t m_time
Definition leapfrog.hpp:104
std::function< void(real_t, la::Vector &)> ForceFunc
Definition leapfrog.hpp:58
real_t m_final_time
Definition leapfrog.hpp:105
PetscInt m_iter
Definition leapfrog.hpp:106
void setSolverType(la::LinearSolver::Type solver_type, la::LinearSolver::PrecondType pc_type)
Definition leapfrog.hpp:84
real_t finalTime() const
Definition leapfrog.hpp:97
Definition butcher_tables.hpp:32
Definition cell_manager.hpp:38