Line data Source code
1 : // The libMesh Finite Element Library.
2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 :
4 : // This library is free software; you can redistribute it and/or
5 : // modify it under the terms of the GNU Lesser General Public
6 : // License as published by the Free Software Foundation; either
7 : // version 2.1 of the License, or (at your option) any later version.
8 :
9 : // This library is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : // Lesser General Public License for more details.
13 :
14 : // You should have received a copy of the GNU Lesser General Public
15 : // License along with this library; if not, write to the Free Software
16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 :
18 : #include "libmesh/second_order_unsteady_solver.h"
19 :
20 : #include "libmesh/diff_system.h"
21 : #include "libmesh/dof_map.h"
22 : #include "libmesh/numeric_vector.h"
23 :
24 : namespace libMesh
25 : {
26 426 : SecondOrderUnsteadySolver::SecondOrderUnsteadySolver (sys_type & s)
27 : : UnsteadySolver(s),
28 402 : _old_local_solution_rate(NumericVector<Number>::build(s.comm())),
29 828 : _old_local_solution_accel(NumericVector<Number>::build(s.comm()))
30 426 : {}
31 :
32 402 : SecondOrderUnsteadySolver::~SecondOrderUnsteadySolver () = default;
33 :
34 426 : void SecondOrderUnsteadySolver::init ()
35 : {
36 426 : UnsteadySolver::init();
37 :
38 426 : _system.add_vector("_old_solution_rate");
39 426 : _system.add_vector("_old_solution_accel");
40 426 : }
41 :
42 426 : void SecondOrderUnsteadySolver::init_data()
43 : {
44 426 : UnsteadySolver::init_data();
45 :
46 : #ifdef LIBMESH_ENABLE_GHOSTED
47 438 : _old_local_solution_rate->init (_system.n_dofs(), _system.n_local_dofs(),
48 426 : _system.get_dof_map().get_send_list(), false,
49 24 : GHOSTED);
50 :
51 438 : _old_local_solution_accel->init (_system.n_dofs(), _system.n_local_dofs(),
52 426 : _system.get_dof_map().get_send_list(), false,
53 24 : GHOSTED);
54 : #else
55 : _old_local_solution_rate->init (_system.n_dofs(), false, SERIAL);
56 : _old_local_solution_accel->init (_system.n_dofs(), false, SERIAL);
57 : #endif
58 426 : }
59 :
60 0 : void SecondOrderUnsteadySolver::reinit ()
61 : {
62 0 : UnsteadySolver::reinit();
63 :
64 : #ifdef LIBMESH_ENABLE_GHOSTED
65 0 : _old_local_solution_rate->init (_system.n_dofs(), _system.n_local_dofs(),
66 0 : _system.get_dof_map().get_send_list(), false,
67 0 : GHOSTED);
68 :
69 0 : _old_local_solution_accel->init (_system.n_dofs(), _system.n_local_dofs(),
70 0 : _system.get_dof_map().get_send_list(), false,
71 0 : GHOSTED);
72 : #else
73 : _old_local_solution_rate->init (_system.n_dofs(), false, SERIAL);
74 : _old_local_solution_accel->init (_system.n_dofs(), false, SERIAL);
75 : #endif
76 :
77 : // localize the old solutions
78 : NumericVector<Number> & old_solution_rate =
79 0 : _system.get_vector("_old_solution_rate");
80 :
81 : NumericVector<Number> & old_solution_accel =
82 0 : _system.get_vector("_old_solution_accel");
83 :
84 : old_solution_rate.localize
85 0 : (*_old_local_solution_rate,
86 0 : _system.get_dof_map().get_send_list());
87 :
88 : old_solution_accel.localize
89 0 : (*_old_local_solution_accel,
90 0 : _system.get_dof_map().get_send_list());
91 0 : }
92 :
93 0 : void SecondOrderUnsteadySolver::retrieve_timestep()
94 : {
95 0 : libmesh_not_implemented();
96 : }
97 :
98 0 : void SecondOrderUnsteadySolver::project_initial_rate(FunctionBase<Number> * f,
99 : FunctionBase<Gradient> * g)
100 : {
101 : NumericVector<Number> & old_solution_rate =
102 0 : _system.get_vector("_old_solution_rate");
103 :
104 0 : _system.project_vector( old_solution_rate, f, g );
105 0 : }
106 :
107 35797152 : Number SecondOrderUnsteadySolver::old_solution_rate(const dof_id_type global_dof_number)
108 : const
109 : {
110 2985232 : libmesh_assert_less (global_dof_number, _system.get_dof_map().n_dofs());
111 2985232 : libmesh_assert_less (global_dof_number, _old_local_solution_rate->size());
112 :
113 35797152 : return (*_old_local_solution_rate)(global_dof_number);
114 : }
115 :
116 35797152 : Number SecondOrderUnsteadySolver::old_solution_accel(const dof_id_type global_dof_number)
117 : const
118 : {
119 2985232 : libmesh_assert_less (global_dof_number, _system.get_dof_map().n_dofs());
120 2985232 : libmesh_assert_less (global_dof_number, _old_local_solution_accel->size());
121 :
122 35797152 : return (*_old_local_solution_accel)(global_dof_number);
123 : }
124 :
125 : } // end namespace libMesh
|