32 #include "libmesh/sparse_matrix.h" 33 #include "libmesh/numeric_vector.h" 34 #include "libmesh/linear_solver.h" 35 #include "libmesh/petsc_matrix.h" 36 #include "libmesh/enum_norm_type.h" 37 #include "libmesh/dof_map.h" 46 _use_eigenvalue_stabilization (true),
47 _assemble_mass (false),
84 libmesh_assert_greater(
max_amp, 0.);
90 LOG_SCOPE(
"sensitivity_solve()",
"StabilizedSensitivity");
96 libMesh::SparseMatrix<Real>
102 std::unique_ptr<libMesh::SparseMatrix<Real>>
103 M0(libMesh::SparseMatrix<Real>::build(sys.comm()).release());
104 sys.get_dof_map().attach_matrix(*M0);
111 libMesh::NumericVector<Real>
115 &rhs = sys.add_sensitivity_rhs();
117 std::unique_ptr<libMesh::NumericVector<Real>>
118 f_int(rhs.zero_clone().release()),
119 vec1(rhs.zero_clone().release());
134 sys.time += this->
dt;
141 while (continue_it) {
144 std::ostringstream oss;
151 J_int.add(this->
dt, M1);
156 Mat M_avg_mat =
dynamic_cast<libMesh::PetscMatrix<Real>&
>(M_avg).mat();
157 PetscErrorCode ierr = MatScale(M_avg_mat, (sys.time -
_t0 - this->dt)/(sys.time -
_t0));
158 CHKERRABORT(sys.comm().get(), ierr);
159 M_avg.add(this->
dt/(sys.time -
_t0), M1);
168 f_int->add(this->
dt, rhs);
171 M_avg.vector_mult(rhs, dsol0);
183 M1.add(this->
beta, J_int);
188 M0->add(-(1.-this->
beta), J_int);
195 std::pair<unsigned int, Real>
199 libMesh::SparseMatrix<Real> * pc = sys.request_matrix(
"Preconditioner");
201 std::pair<unsigned int, Real> rval =
205 solver_params.second,
206 solver_params.first);
209 #ifdef LIBMESH_ENABLE_CONSTRAINTS 210 sys.get_dof_map().enforce_constraints_exactly (sys, &dsol1,
true);
213 M_avg.vector_mult(*vec1, dsol1);
231 libMesh::out <<
"accepting sol" << std::endl;
233 dsol0.add(1., dsol1);
239 dsol1.add(1., dsol0);
242 libMesh::out <<
"reached final step. Rjecting solution" << std::endl;
248 sys.time += this->
dt;
271 libMesh::NumericVector<Real>
276 std::unique_ptr<libMesh::NumericVector<Real>>
277 dx(dx0.zero_clone().release());
284 std::ostringstream oss;
290 eta = (sys.time-
_t0)/(t1-
_t0);
293 dx->add(1.-eta, dx0);
311 const std::vector<libMesh::NumericVector<Real>*>& sols) {
313 libmesh_assert_equal_to(sols.size(), 2);
315 const unsigned int n_dofs = (
unsigned int)dof_indices.size();
320 sol = RealVectorX::Zero(n_dofs),
321 vel = RealVectorX::Zero(n_dofs);
324 const libMesh::NumericVector<Real>
325 &sol_global = *sols[0],
326 &vel_global = *sols[1];
330 for (
unsigned int i=0; i<n_dofs; i++) {
332 sol(i) = sol_global(dof_indices[i]);
333 vel(i) = vel_global(dof_indices[i]);
336 _assembly_ops->set_elem_solution(sol);
337 _assembly_ops->set_elem_velocity(vel);
345 const std::vector<libMesh::NumericVector<Real>*>& sols,
346 std::vector<RealVectorX>& local_sols) {
348 libmesh_assert_equal_to(sols.size(), 2);
350 const unsigned int n_dofs = (
unsigned int)dof_indices.size();
352 local_sols.resize(2);
355 &sol = local_sols[0],
356 &vel = local_sols[1];
358 sol = RealVectorX::Zero(n_dofs);
359 vel = RealVectorX::Zero(n_dofs);
361 const libMesh::NumericVector<Real>
362 &sol_global = *sols[0],
363 &vel_global = *sols[1];
367 for (
unsigned int i=0; i<n_dofs; i++) {
369 sol(i) = sol_global(dof_indices[i]);
370 vel(i) = vel_global(dof_indices[i]);
379 const libMesh::NumericVector<Real>& sol) {
381 const libMesh::NumericVector<Real>
387 vec.add(-1., prev_sol);
399 const libMesh::NumericVector<Real>& sol) {
401 const libMesh::NumericVector<Real>
407 vec.add(-1., prev_sol);
423 libmesh_assert(_assembly_ops);
424 unsigned int n_dofs = (
unsigned int)vec.size();
427 f_x = RealVectorX::Zero(n_dofs),
428 f_m = RealVectorX::Zero(n_dofs);
431 f_m_jac_xdot = RealMatrixX::Zero(n_dofs, n_dofs),
432 f_m_jac = RealMatrixX::Zero(n_dofs, n_dofs),
433 f_x_jac = RealMatrixX::Zero(n_dofs, n_dofs);
436 _assembly_ops->elem_calculations(if_jac,
446 mat = f_m_jac + f_x_jac;
457 libmesh_assert(_assembly_ops);
458 unsigned int n_dofs = (
unsigned int)vec.size();
461 f_x = RealVectorX::Zero(n_dofs),
462 f_m = RealVectorX::Zero(n_dofs);
465 _assembly_ops->elem_sensitivity_calculations(f,
488 const libMesh::NumericVector<Real>& sol1) {
503 var_norm = RealVectorX::Zero(n_vars);
505 for (
unsigned int i=0; i<n_vars; i++) {
507 norm0 = sys.calculate_norm(sol0, i, libMesh::L2);
508 norm1 = sys.calculate_norm(sol1, i, libMesh::L2);
511 var_norm(i) = norm1/norm0;
514 libMesh::out <<
"amp coeffs: " << var_norm.transpose() << std::endl;
515 return var_norm.maxCoeff();
522 libMesh::SparseMatrix<Real>& B) {
529 std::unique_ptr<MAST::SlepcEigenSolver>
532 if (libMesh::on_command_line(
"--solver_system_names")) {
534 EPS eps = eigen_solver.get()->eps();
535 std::string nm = sys.name() +
"_";
536 EPSSetOptionsPrefix(eps, nm.c_str());
539 eigen_solver->set_position_of_spectrum(libMesh::LARGEST_MAGNITUDE);
540 eigen_solver->init();
544 std::pair<unsigned int, unsigned int>
545 solve_data = eigen_solver->solve_generalized (A, B,
552 libmesh_assert(solve_data.first);
554 std::pair<Real, Real> pair = eigen_solver->get_eigenvalue(0);
555 std::complex<Real> eig(pair.first, pair.second);
556 Real amp = std::abs(eig);
558 libMesh::out <<
"amp coeffs: " << amp << std::endl;
MAST::NonlinearSystem & system()
virtual ~StabilizedFirstOrderNewmarkTransientSensitivitySolver()
void set_nolinear_solution_location(std::string &file_root, std::string &dir)
sets the directory where the nonlinear solutions are stored.
void read_in_vector(libMesh::NumericVector< Real > &vec, const std::string &directory_name, const std::string &data_name, const bool read_binary_vectors)
reads the specified vector with the specified name in a directory.
This class implements a system for solution of nonlinear systems.
virtual void elem_sensitivity_calculations(const MAST::FunctionBase &f, RealVectorX &vec)
performs the element sensitivity calculations over elem, and returns the element residual sensitivity...
virtual void clear_elem_operation_object()
clears the association of this object with the assembly element operation object. ...
virtual bool sensitivity_assemble(const MAST::FunctionBase &f, libMesh::NumericVector< Real > &sensitivity_rhs)
Assembly function.
virtual void extract_element_sensitivity_data(const std::vector< libMesh::dof_id_type > &dof_indices, const std::vector< libMesh::NumericVector< Real > * > &sols, std::vector< RealVectorX > &local_sols)
void set_eigenvalue_stabilization(bool f)
sets if the eigenvalue-based stabilization will be used.
This provides the base class for definitin of element level contribution of output quantity in an ana...
unsigned int n_vars() const
std::string _sol_name_root
virtual void set_elem_operation_object(MAST::AssemblyElemOperations &elem_ops)
attaches a element operation to this object, and associated this with the element operation object...
This class inherits from libMesh::SlepcEigenSolver<Real> and implements a method for retriving the re...
void set_eigenproblem_type(libMesh::EigenProblemType ept)
Sets the type of the current eigen problem.
libMesh::NumericVector< Real > & solution_sensitivity(unsigned int prev_iter=0) const
libMesh::NumericVector< Real > & velocity(unsigned int prev_iter=0) const
bool _use_eigenvalue_stabilization
virtual void sensitivity_solve(MAST::AssemblyBase &assembly, const MAST::FunctionBase &f)
solvers the current time step for sensitivity wrt f
virtual void update_sensitivity_velocity(libMesh::NumericVector< Real > &vec, const libMesh::NumericVector< Real > &sol)
update the transient sensitivity velocity based on the current sensitivity solution ...
Real _compute_eig_amplification_factor(libMesh::SparseMatrix< Real > &A, libMesh::SparseMatrix< Real > &B)
libMesh::SparseMatrix< Real > * matrix_A
The system matrix for standard eigenvalue problems.
Matrix< Real, Dynamic, Dynamic > RealMatrixX
virtual void set_element_data(const std::vector< libMesh::dof_id_type > &dof_indices, const std::vector< libMesh::NumericVector< Real > * > &sols)
Real max_amp
parameter used by this solver.
libMesh::NumericVector< Real > & velocity_sensitivity(unsigned int prev_iter=0) const
virtual std::pair< unsigned int, Real > get_linear_solve_parameters()
calls NonlinearImplicitSystem::set_solver_parameters() before accessing the values.
virtual void calculate_output_direct_sensitivity(const libMesh::NumericVector< Real > &X, const libMesh::NumericVector< Real > *dXdp, const MAST::FunctionBase &p, MAST::OutputAssemblyElemOperations &output)
evaluates the sensitivity of the outputs in the attached discipline with respect to the parametrs in ...
Matrix< Real, Dynamic, 1 > RealVectorX
virtual Real output_sensitivity_total(const MAST::FunctionBase &p)=0
virtual void elem_sensitivity_contribution_previous_timestep(const std::vector< RealVectorX > &prev_sols, RealVectorX &vec)
libMesh::SparseMatrix< Real > * matrix_B
A second system matrix for generalized eigenvalue problems.
libMesh::NumericVector< Real > & solution(unsigned int prev_iter=0) const
Real _compute_norm_amplification_factor(const libMesh::NumericVector< Real > &sol0, const libMesh::NumericVector< Real > &sol1)
virtual void zero_for_analysis()=0
zeroes the output quantity values stored inside this object so that assembly process can begin...
std::unique_ptr< libMesh::LinearSolver< Real > > linear_solver
The LinearSolver for solution of the linear equations.
virtual void residual_and_jacobian(const libMesh::NumericVector< Real > &X, libMesh::NumericVector< Real > *R, libMesh::SparseMatrix< Real > *J, libMesh::NonlinearImplicitSystem &S)
function that assembles the matrices and vectors quantities for nonlinear solution ...
unsigned int max_index
index of solution that is used for current linearization
virtual void elem_calculations(bool if_jac, RealVectorX &vec, RealMatrixX &mat)
performs the element calculations over elem, and returns the element vector and matrix quantities in ...
const MAST::NonlinearSystem & system() const
virtual Real evaluate_q_sens_for_previous_interval(MAST::AssemblyBase &assembly, const MAST::FunctionBase &p, MAST::OutputAssemblyElemOperations &output)
StabilizedFirstOrderNewmarkTransientSensitivitySolver()
virtual void update_velocity(libMesh::NumericVector< Real > &vel, const libMesh::NumericVector< Real > &sol)
update the transient velocity based on the current solution
MAST::SystemInitialization * _system