32 #include "libmesh/nonlinear_solver.h" 33 #include "libmesh/numeric_vector.h" 34 #include "libmesh/sparse_matrix.h" 35 #include "libmesh/dof_map.h" 41 _post_assembly (nullptr),
43 _first_iter_res_l2_norm (-1.) {
67 libMesh::NumericVector<Real>* R,
68 libMesh::SparseMatrix<Real>* J,
69 libMesh::NonlinearImplicitSystem& S) {
79 libmesh_assert_equal_to(&S, &(nonlin_sys));
89 std::vector<libMesh::dof_id_type> dof_indices;
90 const libMesh::DofMap& dof_map =
_system->
system().get_dof_map();
93 std::unique_ptr<libMesh::NumericVector<Real> > localized_solution;
103 libMesh::MeshBase::const_element_iterator el =
104 nonlin_sys.get_mesh().active_local_elements_begin();
105 const libMesh::MeshBase::const_element_iterator end_el =
106 nonlin_sys.get_mesh().active_local_elements_end();
111 for ( ; el != end_el; ++el) {
113 const libMesh::Elem* elem = *el;
115 dof_map.dof_indices (elem, dof_indices);
121 unsigned int ndofs = (
unsigned int)dof_indices.size();
122 mat.setIdentity(ndofs, ndofs);
126 dof_map.constrain_element_matrix(m, dof_indices);
127 J->add_matrix(m, dof_indices);
140 unsigned int ndofs = (
unsigned int)dof_indices.size();
143 mat.setZero(ndofs, ndofs);
145 for (
unsigned int i=0; i<dof_indices.size(); i++)
146 sol(i) = (*localized_solution)(dof_indices[i]);
175 dof_map.constrain_element_matrix_and_vector(m, v, dof_indices);
177 dof_map.constrain_element_vector(v, dof_indices);
179 dof_map.constrain_element_matrix(m, dof_indices);
182 if (R) R->add_vector(v, dof_indices);
183 if (J) J->add_matrix(m, dof_indices);
197 MAST::PointLoadSetType::const_iterator
201 const libMesh::dof_id_type
202 first_dof = dof_map.first_dof(nonlin_sys.comm().rank()),
203 end_dof = dof_map.end_dof(nonlin_sys.comm().rank());
205 for ( ; it != end; it++) {
212 const std::set<const libMesh::Node*>
213 nodes = (*it)->get_nodes();
215 std::set<const libMesh::Node*>::const_iterator
216 n_it = nodes.begin(),
219 for (; n_it != n_end; n_it++) {
223 func(**n_it, nonlin_sys.time, vec);
228 dof_map.dof_indices(*n_it, dof_indices);
230 libmesh_assert_equal_to(dof_indices.size(), vec.rows());
234 for (
unsigned int i=0; i<dof_indices.size(); i++)
235 if (dof_indices[i] < first_dof ||
236 dof_indices[i] >= end_dof)
242 dof_map.constrain_element_vector(v, dof_indices);
243 R->add_vector(v, dof_indices);
274 const libMesh::NumericVector<Real>& dX,
275 libMesh::NumericVector<Real>& JdX,
276 libMesh::NonlinearImplicitSystem& S) {
289 libmesh_assert_equal_to(&S, &(nonlin_sys));
296 std::vector<libMesh::dof_id_type> dof_indices;
297 const libMesh::DofMap& dof_map =
_system->
system().get_dof_map();
300 std::unique_ptr<libMesh::NumericVector<Real> >
302 localized_perturbed_solution;
315 libMesh::MeshBase::const_element_iterator el =
316 nonlin_sys.get_mesh().active_local_elements_begin();
317 const libMesh::MeshBase::const_element_iterator end_el =
318 nonlin_sys.get_mesh().active_local_elements_end();
323 for ( ; el != end_el; ++el) {
325 const libMesh::Elem* elem = *el;
330 dof_map.dof_indices (elem, dof_indices);
339 unsigned int ndofs = (
unsigned int)dof_indices.size();
343 mat.setZero(ndofs, ndofs);
345 for (
unsigned int i=0; i<dof_indices.size(); i++) {
346 sol (i) = (*localized_solution) (dof_indices[i]);
347 dsol(i) = (*localized_perturbed_solution)(dof_indices[i]);
370 dof_map.constrain_element_vector(v, dof_indices);
373 JdX.add_vector(v, dof_indices);
390 bool if_localize_sol,
391 const libMesh::NumericVector<Real>& dX,
392 bool if_localize_sol_sens,
393 libMesh::SparseMatrix<Real>& d_JdX_dX,
394 libMesh::NonlinearImplicitSystem& S) {
407 libmesh_assert_equal_to(&S, &(nonlin_sys));
414 std::vector<libMesh::dof_id_type> dof_indices;
415 const libMesh::DofMap& dof_map =
_system->
system().get_dof_map();
417 const libMesh::NumericVector<Real>
421 std::unique_ptr<libMesh::NumericVector<Real> >
423 localized_perturbed_solution;
425 if (if_localize_sol) {
427 sol_vec = localized_solution.get();
432 if (if_localize_sol_sens) {
434 dsol_vec = localized_perturbed_solution.get();
445 libMesh::MeshBase::const_element_iterator el =
446 nonlin_sys.get_mesh().active_local_elements_begin();
447 const libMesh::MeshBase::const_element_iterator end_el =
448 nonlin_sys.get_mesh().active_local_elements_end();
453 for ( ; el != end_el; ++el) {
455 const libMesh::Elem* elem = *el;
460 dof_map.dof_indices (elem, dof_indices);
469 unsigned int ndofs = (
unsigned int)dof_indices.size();
472 mat.setZero(ndofs, ndofs);
474 for (
unsigned int i=0; i<dof_indices.size(); i++) {
475 sol (i) = (*sol_vec) (dof_indices[i]);
476 dsol(i) = (*dsol_vec)(dof_indices[i]);
497 dof_map.constrain_element_matrix(m, dof_indices);
500 d_JdX_dX.add_matrix(m, dof_indices);
518 bool if_localize_sol,
520 libMesh::NumericVector<Real>& sensitivity_rhs,
529 sensitivity_rhs.zero();
535 std::vector<libMesh::dof_id_type> dof_indices;
536 const libMesh::DofMap& dof_map = nonlin_sys.get_dof_map();
538 const libMesh::NumericVector<Real>
541 std::unique_ptr<libMesh::NumericVector<Real> > localized_solution;
543 if (if_localize_sol) {
545 sol_vec = localized_solution.get();
554 libMesh::MeshBase::const_element_iterator el =
555 nonlin_sys.get_mesh().active_local_elements_begin();
556 const libMesh::MeshBase::const_element_iterator end_el =
557 nonlin_sys.get_mesh().active_local_elements_end();
562 for ( ; el != end_el; ++el) {
564 const libMesh::Elem* elem = *el;
575 dof_map.dof_indices (elem, dof_indices);
584 unsigned int ndofs = (
unsigned int)dof_indices.size();
589 for (
unsigned int i=0; i<dof_indices.size(); i++)
590 sol(i) = (*sol_vec)(dof_indices[i]);
613 dof_map.constrain_element_vector(v, dof_indices);
616 sensitivity_rhs.add_vector(v, dof_indices);
628 MAST::PointLoadSetType::const_iterator
632 const libMesh::dof_id_type
633 first_dof = dof_map.first_dof(nonlin_sys.comm().rank()),
634 end_dof = dof_map.end_dof(nonlin_sys.comm().rank());
636 for ( ; it != end; it++) {
643 const std::set<const libMesh::Node*>
644 nodes = (*it)->get_nodes();
646 std::set<const libMesh::Node*>::const_iterator
647 n_it = nodes.begin(),
650 for (; n_it != n_end; n_it++) {
654 func.
derivative(f, **n_it, nonlin_sys.time, vec);
657 dof_map.dof_indices(*n_it, dof_indices);
659 libmesh_assert_equal_to(dof_indices.size(), vec.rows());
663 for (
unsigned int i=0; i<dof_indices.size(); i++)
664 if (dof_indices[i] < first_dof ||
665 dof_indices[i] >= end_dof)
671 dof_map.constrain_element_vector(v, dof_indices);
672 sensitivity_rhs.add_vector(v, dof_indices);
683 sensitivity_rhs.close();
MAST::AssemblyElemOperations * _elem_ops
provides assembly elem operations for use by this class
virtual void set_elem_perturbed_solution(const RealVectorX &sol)
sets the element perturbed solution
MAST::NonlinearSystem & system()
void init(const libMesh::NumericVector< Real > &sol, bool reuse_vector)
initializes the data structures to perform the interpolation function of sol.
virtual bool if_elem_depends_on_parameter(const libMesh::Elem &e, const MAST::FunctionBase &p) const =0
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 ...
libMesh::DenseMatrix< Real > DenseRealMatrix
Real _res_l2_norm
L2 norm of the last-assembled residual.
This class implements a system for solution of nonlinear systems.
virtual void set_elem_solution_sensitivity(const RealVectorX &sol)
sets the element solution sensitivity
virtual void second_derivative_dot_solution_assembly(const libMesh::NumericVector< Real > &X, bool if_localize_sol, const libMesh::NumericVector< Real > &dX, bool if_localize_sol_sens, libMesh::SparseMatrix< Real > &d_JdX_dX, libMesh::NonlinearImplicitSystem &S)
calculates .
const MAST::PointLoadSetType & point_loads() const
bool close_matrix
flag to control the closing fo the Jacobian after assembly
virtual void set_elem_solution(const RealVectorX &sol)
sets the element solution
virtual void derivative(const MAST::FunctionBase &f, ValType &v) const
calculates the value of the function derivative and returns it in v.
virtual void linearized_jacobian_solution_product(const libMesh::NumericVector< Real > &X, const libMesh::NumericVector< Real > &dX, libMesh::NumericVector< Real > &JdX, libMesh::NonlinearImplicitSystem &S)
calculates the product of the Jacobian and a perturbation in solution vector .
std::set< unsigned int > diagonal_elem_subdomain_id
subdomain ids for which residuakl and Jacobian contributions will not be computed.
MAST::SystemInitialization * _system
System for which this assembly is performed.
virtual void elem_sensitivity_calculations(const MAST::FunctionBase &f, RealVectorX &vec)=0
performs the element sensitivity calculations over elem, and returns the element residual sensitivity...
virtual bool is_topology_parameter() const
virtual void elem_calculations(bool if_jac, RealVectorX &vec, RealMatrixX &mat)=0
performs the element calculations over elem, and returns the element vector and matrix quantities in ...
unsigned int n_vars() const
MAST::PhysicsDisciplineBase * _discipline
PhysicsDisciplineBase object for which this class is assembling.
virtual void set_elem_data(unsigned int dim, const libMesh::Elem &ref_elem, MAST::GeomElem &elem) const =0
some analyses may want to set additional element data before initialization of the GeomElem...
virtual void post_assembly(const libMesh::NumericVector< Real > &X, libMesh::NumericVector< Real > *R, libMesh::SparseMatrix< Real > *J, libMesh::NonlinearImplicitSystem &S)=0
libMesh::DenseVector< Real > DenseRealVector
virtual void elem_second_derivative_dot_solution_assembly(RealMatrixX &mat)=0
calculates over elem, and returns the matrix in vec .
NonlinearImplicitAssembly()
constructor associates this assembly object with the system
MAST::NonlinearImplicitAssembly::PostAssemblyOperation * _post_assembly
this object, if non-NULL is user-provided to perform actions after assembly and before returning to t...
Matrix< Real, Dynamic, Dynamic > RealMatrixX
std::unique_ptr< libMesh::NumericVector< Real > > build_localized_vector(const libMesh::System &sys, const libMesh::NumericVector< Real > &global) const
localizes the parallel vector so that the local copy stores all values necessary for calculation of t...
void copy(DenseRealMatrix &m1, const RealMatrixX &m2)
virtual bool sensitivity_assemble(const libMesh::NumericVector< Real > &X, bool if_localize_sol, const MAST::FunctionBase &f, libMesh::NumericVector< Real > &sensitivity_rhs, bool close_vector=true)
Assembly function.
virtual void elem_topology_sensitivity_calculations(const MAST::FunctionBase &f, RealVectorX &vec)=0
performs the element topology sensitivity calculations over elem, and returns the element residual se...
void clear()
clear the solution
Matrix< Real, Dynamic, 1 > RealVectorX
virtual void init(const MAST::GeomElem &elem)=0
initializes the object for calculation of element quantities for the specified elem.
This class acts as a wrapper around libMesh::Elem for the purpose of providing a uniform interface fo...
user-provided object to perform actions after assembly and before returning to the solver...
MAST::AssemblyBase::ElemParameterDependence * _param_dependence
If provided by user, this object is used by sensitiivty analysis to check for whether or the current ...
Real _first_iter_res_l2_norm
std::set< MAST::PointLoadCondition * > PointLoadSetType
virtual void clear_elem()
clears the element initialization
virtual void init(const libMesh::Elem &elem, const MAST::SystemInitialization &sys_init)
initialize the object for the specified reference elem.
virtual void elem_linearized_jacobian_solution_product(RealVectorX &vec)=0
performs the element calculations over elem, and returns the element vector quantity in vec...
void set_post_assembly_operation(MAST::NonlinearImplicitAssembly::PostAssemblyOperation &post)
sets the PostAssemblyOperation object for use after assembly.
MAST::MeshFieldFunction * _sol_function
system solution that will be initialized before each solution
virtual ~NonlinearImplicitAssembly()
destructor resets the association of this assembly object with the system