svMultiPhysics
Loading...
Searching...
No Matches
Integrator.h
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef INTEGRATOR_H
5#define INTEGRATOR_H
6
7#include "Array.h"
8#include "SolutionStates.h"
9#include "Vector.h"
10#include "Simulation.h"
11
12/**
13 * @brief Integrator class encapsulates the Newton iteration loop for time integration
14 *
15 * This class handles the nonlinear Newton iteration scheme for solving coupled
16 * multi-physics equations in svMultiPhysics. It manages:
17 * - Solution variables (Ag, Yg, Dg) at generalized-alpha time levels
18 * - Newton iteration loop with convergence checking
19 * - Linear system assembly and solve
20 * - Boundary condition application
21 *
22 * Related to GitHub issue #442: Encapsulate the Newton iteration in main.cpp
23 */
25
26public:
27 /**
28 * @brief Construct a new Integrator object
29 *
30 * @param simulation Pointer to the Simulation object containing problem data
31 * @param solutions Solution states containing old time level arrays (takes ownership via move)
32 */
33 Integrator(Simulation* simulation, SolutionStates&& solutions);
34
35 /**
36 * @brief Execute one time step with Newton iteration loop
37 *
38 * Performs the complete Newton iteration sequence including initialization,
39 * assembly, boundary condition application, linear solve, and convergence check.
40 *
41 * @return True if all equations converged, false otherwise
42 */
43 bool step();
44
45 /**
46 * @brief Perform predictor step for next time step
47 *
48 * Performs predictor step using generalized-alpha method to estimate
49 * solution at n+1 time level based on current solution at n time level.
50 * This should be called once per time step before the Newton iteration loop.
51 */
52 void predictor();
53
54 /**
55 * @brief Get reference to solution variable Ag (time derivative of variables)
56 *
57 * @return Reference to Ag array (acceleration in structural mechanics)
58 */
59 Array<double>& get_Ag() { return solutions_.intermediate.get_acceleration(); }
60 const Array<double>& get_Ag() const { return solutions_.intermediate.get_acceleration(); }
61
62 /**
63 * @brief Get reference to solution variable Yg (variables)
64 *
65 * @return Reference to Yg array (velocity in structural mechanics)
66 */
67 Array<double>& get_Yg() { return solutions_.intermediate.get_velocity(); }
68 const Array<double>& get_Yg() const { return solutions_.intermediate.get_velocity(); }
69
70 /**
71 * @brief Get reference to solution variable Dg (integrated variables)
72 *
73 * @return Reference to Dg array (displacement in structural mechanics)
74 */
75 Array<double>& get_Dg() { return solutions_.intermediate.get_displacement(); }
76 const Array<double>& get_Dg() const { return solutions_.intermediate.get_displacement(); }
77
78 /**
79 * @brief Get reference to solution states struct
80 *
81 * Provides access to all solution arrays at old (n) and current (n+1) time levels.
82 * Use this to access An, Dn, Yn (current) and Ao, Do, Yo (old) via:
83 * auto& solutions = integrator.get_solutions();
84 * auto& An = solutions.current.get_acceleration();
85 * auto& Do = solutions.old.get_displacement();
86 *
87 * @return Reference to SolutionStates struct containing all solution arrays
88 */
89 SolutionStates& get_solutions() { return solutions_; }
90 const SolutionStates& get_solutions() const { return solutions_; }
91
92private:
93 /** @brief Pointer to the simulation object */
94 Simulation* simulation_;
95
96 /** @brief Solution states at old, current, and intermediate time levels */
97 SolutionStates solutions_;
98
99 /** @brief Residual vector for face-based quantities */
100 Vector<double> res_;
101
102 /** @brief Increment flag for faces in linear solver */
103 Vector<int> incL_;
104
105 /** @brief Newton iteration counter for current time step */
106 int newton_count_;
107
108 /** @brief Debug output suffix string combining time step and iteration number */
109 std::string istr_;
110
111 /**
112 * @brief Initialize solution arrays for Ag, Yg, Dg based on problem size
113 */
114 void initialize_arrays();
115
116 /**
117 * @brief Perform initiator step for Generalized-alpha Method
118 *
119 * Computes quantities at intermediate time levels (n+alpha_m, n+alpha_f)
120 */
121 void initiator_step();
122
123 /**
124 * @brief Allocate right-hand side (RHS) and left-hand side (LHS) arrays
125 *
126 * @param eq Reference to the equation being solved
127 */
128 void allocate_linear_system(eqType& eq);
129
130 /**
131 * @brief Set body forces for the current time step
132 */
133 void set_body_forces();
134
135 /**
136 * @brief Assemble global equations for all meshes
137 */
138 void assemble_equations();
139
140 /**
141 * @brief Apply all boundary conditions (Neumann, Dirichlet, CMM, contact, etc.)
142 */
143 void apply_boundary_conditions();
144
145 /**
146 * @brief Solve the assembled linear system
147 */
148 void solve_linear_system();
149
150 /**
151 * @brief Perform corrector step and check convergence of all equations
152 *
153 * @return True if all equations converged, false otherwise
154 */
155 bool corrector_and_check_convergence();
156
157 /**
158 * @brief Update residual and increment arrays for linear solver
159 *
160 * @param eq Reference to the equation being solved
161 */
162 void update_residual_arrays(eqType& eq);
163
164 /**
165 * @brief Initiator function for generalized-alpha method (initiator)
166 *
167 * Computes solution variables at intermediate time levels using
168 * generalized-alpha parameters (am, af) for time integration.
169 * Updates solutions.intermediate (Ag, Yg, Dg) based on solutions.current
170 * (An, Yn, Dn) and solutions.old (Ao, Yo, Do).
171 *
172 * @param solutions Solution states containing old, current, and intermediate levels
173 */
174 void initiator(SolutionStates& solutions);
175
176 /**
177 * @brief Corrector function with convergence check (corrector)
178 *
179 * Updates solution at n+1 time level and checks convergence of Newton
180 * iterations. Also handles equation switching for coupled problems.
181 */
182 void corrector();
183
184 /**
185 * @brief Pressure correction for Taylor-Hood elements (corrector_taylor_hood)
186 *
187 * Interpolates pressure at edge nodes using reduced basis applied
188 * on element vertices for Taylor-Hood type elements.
189 */
190 void corrector_taylor_hood();
191};
192
193#endif // INTEGRATOR_H
Integrator class encapsulates the Newton iteration loop for time integration.
Definition Integrator.h:24
Array< double > & get_Dg()
Get reference to solution variable Dg (integrated variables)
Definition Integrator.h:75
bool step()
Execute one time step with Newton iteration loop.
Definition Integrator.cpp:63
SolutionStates & get_solutions()
Get reference to solution states struct.
Definition Integrator.h:89
Array< double > & get_Yg()
Get reference to solution variable Yg (variables)
Definition Integrator.h:67
Array< double > & get_Ag()
Get reference to solution variable Ag (time derivative of variables)
Definition Integrator.h:59
void predictor()
Perform predictor step for next time step.
Definition Integrator.cpp:391
Definition Simulation.h:19
The Vector template class is used for storing int and double data.
Definition Vector.h:24
Equation type.
Definition ComMod.h:1077
Holds solution state at old, current, and intermediate time levels.
Definition SolutionStates.h:39
Solution intermediate
Generalized-alpha intermediate level (Ag, Yg, Dg)
Definition SolutionStates.h:42