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 * One line is written to the standard output and to the history file for every
41 * Newton iteration, including the converged one.
42 *
43 * @param[in] save_results True if the results of this time step are written to a
44 * VTU file, which flags the converged iteration with an 's' in the standard
45 * output.
46 *
47 * @return True if all equations converged, false otherwise
48 */
49 bool step(bool save_results = false);
50
51 /**
52 * @brief Perform predictor step for next time step
53 *
54 * Performs predictor step using generalized-alpha method to estimate
55 * solution at n+1 time level based on current solution at n time level.
56 * This should be called once per time step before the Newton iteration loop.
57 */
58 void predictor();
59
60 /**
61 * @brief Get reference to solution variable Ag (time derivative of variables)
62 *
63 * @return Reference to Ag array (acceleration in structural mechanics)
64 */
65 Array<double>& get_Ag() { return solutions_.intermediate.get_acceleration(); }
66 const Array<double>& get_Ag() const { return solutions_.intermediate.get_acceleration(); }
67
68 /**
69 * @brief Get reference to solution variable Yg (variables)
70 *
71 * @return Reference to Yg array (velocity in structural mechanics)
72 */
73 Array<double>& get_Yg() { return solutions_.intermediate.get_velocity(); }
74 const Array<double>& get_Yg() const { return solutions_.intermediate.get_velocity(); }
75
76 /**
77 * @brief Get reference to solution variable Dg (integrated variables)
78 *
79 * @return Reference to Dg array (displacement in structural mechanics)
80 */
81 Array<double>& get_Dg() { return solutions_.intermediate.get_displacement(); }
82 const Array<double>& get_Dg() const { return solutions_.intermediate.get_displacement(); }
83
84 /**
85 * @brief Get reference to solution states struct
86 *
87 * Provides access to all solution arrays at old (n) and current (n+1) time levels.
88 * Use this to access An, Dn, Yn (current) and Ao, Do, Yo (old) via:
89 * auto& solutions = integrator.get_solutions();
90 * auto& An = solutions.current.get_acceleration();
91 * auto& Do = solutions.old.get_displacement();
92 *
93 * @return Reference to SolutionStates struct containing all solution arrays
94 */
95 SolutionStates& get_solutions() { return solutions_; }
96 const SolutionStates& get_solutions() const { return solutions_; }
97
98private:
99 /** @brief Pointer to the simulation object */
100 Simulation* simulation_;
101
102 /** @brief Solution states at old, current, and intermediate time levels */
103 SolutionStates solutions_;
104
105 /** @brief Residual vector for face-based quantities */
106 Vector<double> res_;
107
108 /** @brief Increment flag for faces in linear solver */
109 Vector<int> incL_;
110
111 /** @brief Newton iteration counter for current time step */
112 int newton_count_;
113
114 /** @brief Debug output suffix string combining time step and iteration number */
115 std::string istr_;
116
117 /**
118 * @brief Initialize solution arrays for Ag, Yg, Dg based on problem size
119 */
120 void initialize_arrays();
121
122 /**
123 * @brief Perform initiator step for Generalized-alpha Method
124 *
125 * Computes quantities at intermediate time levels (n+alpha_m, n+alpha_f)
126 */
127 void initiator_step();
128
129 /**
130 * @brief Allocate right-hand side (RHS) and left-hand side (LHS) arrays
131 *
132 * @param eq Reference to the equation being solved
133 */
134 void allocate_linear_system(eqType& eq);
135
136 /**
137 * @brief Set body forces for the current time step
138 */
139 void set_body_forces();
140
141 /**
142 * @brief Assemble global equations for all meshes
143 */
144 void assemble_equations();
145
146 /**
147 * @brief Apply all boundary conditions (Neumann, Dirichlet, CMM, contact, etc.)
148 */
149 void apply_boundary_conditions();
150
151 /**
152 * @brief Solve the assembled linear system
153 */
154 void solve_linear_system();
155
156 /**
157 * @brief Perform corrector step and check convergence of all equations
158 *
159 * @return True if all equations converged, false otherwise
160 */
161 bool corrector_and_check_convergence();
162
163 /**
164 * @brief Update residual and increment arrays for linear solver
165 *
166 * @param eq Reference to the equation being solved
167 */
168 void update_residual_arrays(eqType& eq);
169
170 /**
171 * @brief Initiator function for generalized-alpha method (initiator)
172 *
173 * Computes solution variables at intermediate time levels using
174 * generalized-alpha parameters (am, af) for time integration.
175 * Updates solutions.intermediate (Ag, Yg, Dg) based on solutions.current
176 * (An, Yn, Dn) and solutions.old (Ao, Yo, Do).
177 *
178 * @param solutions Solution states containing old, current, and intermediate levels
179 */
180 void initiator(SolutionStates& solutions);
181
182 /**
183 * @brief Corrector function with convergence check (corrector)
184 *
185 * Updates solution at n+1 time level and checks convergence of Newton
186 * iterations. Also handles equation switching for coupled problems.
187 */
188 void corrector();
189
190 /**
191 * @brief Pressure correction for Taylor-Hood elements (corrector_taylor_hood)
192 *
193 * Interpolates pressure at edge nodes using reduced basis applied
194 * on element vertices for Taylor-Hood type elements.
195 */
196 void corrector_taylor_hood();
197};
198
199#endif // INTEGRATOR_H
Integrator class encapsulates the Newton iteration loop for time integration.
Definition Integrator.h:24
bool step(bool save_results=false)
Execute one time step with Newton iteration loop.
Definition Integrator.cpp:61
Array< double > & get_Dg()
Get reference to solution variable Dg (integrated variables)
Definition Integrator.h:81
SolutionStates & get_solutions()
Get reference to solution states struct.
Definition Integrator.h:95
Array< double > & get_Yg()
Get reference to solution variable Yg (variables)
Definition Integrator.h:73
Array< double > & get_Ag()
Get reference to solution variable Ag (time derivative of variables)
Definition Integrator.h:65
void predictor()
Perform predictor step for next time step.
Definition Integrator.cpp:395
Definition Simulation.h:19
The Vector template class is used for storing int and double data.
Definition Vector.h:26
Equation type.
Definition ComMod.h:1084
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