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);
124 unsigned int ndofs = (
unsigned int)dof_indices.size();
127 mat.setZero(ndofs, ndofs);
129 for (
unsigned int i=0; i<dof_indices.size(); i++)
130 sol(i) = (*localized_solution)(dof_indices[i]);
159 dof_map.constrain_element_matrix_and_vector(m, v, dof_indices);
161 dof_map.constrain_element_vector(v, dof_indices);
163 dof_map.constrain_element_matrix(m, dof_indices);
166 if (R) R->add_vector(v, dof_indices);
167 if (J) J->add_matrix(m, dof_indices);
180 MAST::PointLoadSetType::const_iterator
184 const libMesh::dof_id_type
185 first_dof = dof_map.first_dof(nonlin_sys.comm().rank()),
186 last_dof = dof_map.last_dof(nonlin_sys.comm().rank());
188 for ( ; it != end; it++) {
195 const std::set<const libMesh::Node*>
196 nodes = (*it)->get_nodes();
198 std::set<const libMesh::Node*>::const_iterator
199 n_it = nodes.begin(),
202 for (; n_it != n_end; n_it++) {
206 func(**n_it, nonlin_sys.time, vec);
211 dof_map.dof_indices(*n_it, dof_indices);
213 libmesh_assert_equal_to(dof_indices.size(), vec.rows());
217 for (
unsigned int i=0; i<dof_indices.size(); i++)
218 if (dof_indices[i] < first_dof ||
219 dof_indices[i] >= last_dof)
225 dof_map.constrain_element_vector(v, dof_indices);
226 R->add_vector(v, dof_indices);
257 const libMesh::NumericVector<Real>& dX,
258 libMesh::NumericVector<Real>& JdX,
259 libMesh::NonlinearImplicitSystem& S) {
272 libmesh_assert_equal_to(&S, &(nonlin_sys));
279 std::vector<libMesh::dof_id_type> dof_indices;
280 const libMesh::DofMap& dof_map =
_system->
system().get_dof_map();
283 std::unique_ptr<libMesh::NumericVector<Real> >
285 localized_perturbed_solution;
298 libMesh::MeshBase::const_element_iterator el =
299 nonlin_sys.get_mesh().active_local_elements_begin();
300 const libMesh::MeshBase::const_element_iterator end_el =
301 nonlin_sys.get_mesh().active_local_elements_end();
306 for ( ; el != end_el; ++el) {
308 const libMesh::Elem* elem = *el;
310 dof_map.dof_indices (elem, dof_indices);
319 unsigned int ndofs = (
unsigned int)dof_indices.size();
323 mat.setZero(ndofs, ndofs);
325 for (
unsigned int i=0; i<dof_indices.size(); i++) {
326 sol (i) = (*localized_solution) (dof_indices[i]);
327 dsol(i) = (*localized_perturbed_solution)(dof_indices[i]);
350 dof_map.constrain_element_vector(v, dof_indices);
353 JdX.add_vector(v, dof_indices);
370 const libMesh::NumericVector<Real>& dX,
371 libMesh::SparseMatrix<Real>& d_JdX_dX,
372 libMesh::NonlinearImplicitSystem& S) {
385 libmesh_assert_equal_to(&S, &(nonlin_sys));
392 std::vector<libMesh::dof_id_type> dof_indices;
393 const libMesh::DofMap& dof_map =
_system->
system().get_dof_map();
396 std::unique_ptr<libMesh::NumericVector<Real> >
398 localized_perturbed_solution;
411 libMesh::MeshBase::const_element_iterator el =
412 nonlin_sys.get_mesh().active_local_elements_begin();
413 const libMesh::MeshBase::const_element_iterator end_el =
414 nonlin_sys.get_mesh().active_local_elements_end();
419 for ( ; el != end_el; ++el) {
421 const libMesh::Elem* elem = *el;
423 dof_map.dof_indices (elem, dof_indices);
432 unsigned int ndofs = (
unsigned int)dof_indices.size();
435 mat.setZero(ndofs, ndofs);
437 for (
unsigned int i=0; i<dof_indices.size(); i++) {
438 sol (i) = (*localized_solution) (dof_indices[i]);
439 dsol(i) = (*localized_perturbed_solution)(dof_indices[i]);
460 dof_map.constrain_element_matrix(m, dof_indices);
463 d_JdX_dX.add_matrix(m, dof_indices);
481 libMesh::NumericVector<Real>& sensitivity_rhs) {
489 sensitivity_rhs.zero();
495 std::vector<libMesh::dof_id_type> dof_indices;
496 const libMesh::DofMap& dof_map = nonlin_sys.get_dof_map();
499 std::unique_ptr<libMesh::NumericVector<Real> > localized_solution;
501 *nonlin_sys.solution).release());
507 libMesh::MeshBase::const_element_iterator el =
508 nonlin_sys.get_mesh().active_local_elements_begin();
509 const libMesh::MeshBase::const_element_iterator end_el =
510 nonlin_sys.get_mesh().active_local_elements_end();
515 for ( ; el != end_el; ++el) {
517 const libMesh::Elem* elem = *el;
525 dof_map.dof_indices (elem, dof_indices);
534 unsigned int ndofs = (
unsigned int)dof_indices.size();
538 for (
unsigned int i=0; i<dof_indices.size(); i++)
539 sol(i) = (*localized_solution)(dof_indices[i]);
557 dof_map.constrain_element_vector(v, dof_indices);
560 sensitivity_rhs.add_vector(v, dof_indices);
572 MAST::PointLoadSetType::const_iterator
576 const libMesh::dof_id_type
577 first_dof = dof_map.first_dof(nonlin_sys.comm().rank()),
578 last_dof = dof_map.last_dof(nonlin_sys.comm().rank());
580 for ( ; it != end; it++) {
587 const std::set<const libMesh::Node*>
588 nodes = (*it)->get_nodes();
590 std::set<const libMesh::Node*>::const_iterator
591 n_it = nodes.begin(),
594 for (; n_it != n_end; n_it++) {
598 func.
derivative(f, **n_it, nonlin_sys.time, vec);
601 dof_map.dof_indices(*n_it, dof_indices);
603 libmesh_assert_equal_to(dof_indices.size(), vec.rows());
607 for (
unsigned int i=0; i<dof_indices.size(); i++)
608 if (dof_indices[i] < first_dof ||
609 dof_indices[i] >= last_dof)
615 dof_map.constrain_element_vector(v, dof_indices);
616 sensitivity_rhs.add_vector(v, dof_indices);
626 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()
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
unsigned int n_vars() const
bool close_matrix
flag to control the closing fo the Jacobian after assembly
virtual bool sensitivity_assemble(const MAST::FunctionBase &f, libMesh::NumericVector< Real > &sensitivity_rhs)
Assembly function.
virtual void set_elem_solution(const RealVectorX &sol)
sets the element solution
virtual void second_derivative_dot_solution_assembly(const libMesh::NumericVector< Real > &X, const libMesh::NumericVector< Real > &dX, libMesh::SparseMatrix< Real > &d_JdX_dX, libMesh::NonlinearImplicitSystem &S)
calculates .
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 .
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 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 ...
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
virtual void derivative(const MAST::FunctionBase &f, ValType &v) const
calculates the value of the function derivative and returns it in v.
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
void copy(DenseRealMatrix &m1, const RealMatrixX &m2)
const MAST::PointLoadSetType & point_loads() const
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.
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...
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...
void init(const libMesh::NumericVector< Real > &sol, const libMesh::NumericVector< Real > *dsol=nullptr)
initializes the data structures to perform the interpolation function of sol.
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