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) {
65 libMesh::NumericVector<Real>* R,
66 libMesh::SparseMatrix<Real>* J,
67 libMesh::NonlinearImplicitSystem& S) {
81 libmesh_assert_equal_to(&S, &transient_sys);
91 std::vector<libMesh::dof_id_type> dof_indices;
92 const libMesh::DofMap& dof_map = transient_sys.get_dof_map();
98 std::vector<libMesh::NumericVector<Real>*>
108 libMesh::MeshBase::const_element_iterator el =
109 transient_sys.get_mesh().active_local_elements_begin();
110 const libMesh::MeshBase::const_element_iterator end_el =
111 transient_sys.get_mesh().active_local_elements_end();
113 for ( ; el != end_el; ++el) {
115 const libMesh::Elem* elem = *el;
117 dof_map.dof_indices (elem, dof_indices);
123 solver.
init(geom_elem);
126 unsigned int ndofs = (
unsigned int)dof_indices.size();
128 mat.setZero(ndofs, ndofs);
130 solver.set_element_data(dof_indices, local_qtys);
151 dof_map.constrain_element_matrix_and_vector(m, v, dof_indices);
153 dof_map.constrain_element_vector(v, dof_indices);
155 dof_map.constrain_element_matrix(m, dof_indices);
158 if (R) R->add_vector(v, dof_indices);
159 if (J) J->add_matrix(m, dof_indices);
167 for (
unsigned int i=0; i<local_qtys.size(); i++)
168 delete local_qtys[i];
184 const libMesh::NumericVector<Real>& dX,
185 libMesh::NumericVector<Real>& JdX,
186 libMesh::NonlinearImplicitSystem& S) {
199 libmesh_assert_equal_to(&S, &transient_sys);
207 std::vector<libMesh::dof_id_type> dof_indices;
208 const libMesh::DofMap& dof_map = transient_sys.get_dof_map();
213 std::vector<libMesh::NumericVector<Real>*>
215 local_perturbed_qtys;
223 solver.build_perturbed_local_quantities(dX, local_perturbed_qtys);
225 libMesh::MeshBase::const_element_iterator el =
226 transient_sys.get_mesh().active_local_elements_begin();
227 const libMesh::MeshBase::const_element_iterator end_el =
228 transient_sys.get_mesh().active_local_elements_end();
230 for ( ; el != end_el; ++el) {
232 const libMesh::Elem* elem = *el;
234 dof_map.dof_indices (elem, dof_indices);
243 unsigned int ndofs = (
unsigned int)dof_indices.size();
247 solver.set_element_data(dof_indices, local_qtys);
248 solver.set_element_perturbed_data(dof_indices, local_perturbed_qtys);
264 dof_map.constrain_element_vector(v, dof_indices);
267 JdX.add_vector(v, dof_indices);
272 for (
unsigned int i=0; i<local_qtys.size(); i++) {
274 delete local_qtys[i];
275 delete local_perturbed_qtys[i];
290 libMesh::NumericVector<Real>& sensitivity_rhs) {
301 sensitivity_rhs.zero();
306 std::vector<RealVectorX> prev_local_sols;
308 std::vector<libMesh::dof_id_type> dof_indices;
309 const libMesh::DofMap& dof_map = nonlin_sys.get_dof_map();
312 std::vector<libMesh::NumericVector<Real>*>
322 libMesh::MeshBase::const_element_iterator el =
323 nonlin_sys.get_mesh().active_local_elements_begin();
324 const libMesh::MeshBase::const_element_iterator end_el =
325 nonlin_sys.get_mesh().active_local_elements_end();
327 for ( ; el != end_el; ++el) {
329 const libMesh::Elem* elem = *el;
331 dof_map.dof_indices (elem, dof_indices);
340 unsigned int ndofs = (
unsigned int)dof_indices.size();
344 solver.set_element_data(dof_indices, local_qtys);
345 solver.extract_element_sensitivity_data(dof_indices, prev_local_qtys, prev_local_sols);
351 solver.elem_sensitivity_contribution_previous_timestep(prev_local_sols, vec2);
365 dof_map.constrain_element_vector(v, dof_indices);
368 sensitivity_rhs.add_vector(v, dof_indices);
372 for (
unsigned int i=0; i<local_qtys.size(); i++) {
374 delete local_qtys[i];
375 delete prev_local_qtys[i];
382 sensitivity_rhs.close();
MAST::AssemblyElemOperations * _elem_ops
provides assembly elem operations for use by this class
MAST::NonlinearSystem & system()
TransientAssembly()
constructor associates this assembly object with the system
libMesh::DenseMatrix< Real > DenseRealMatrix
This class implements a system for solution of nonlinear systems.
MAST::TransientAssembly::PostAssemblyOperation * _post_assembly
this object, if non-NULL is user-provided to perform actions after assembly and before returning to t...
bool close_matrix
flag to control the closing fo the Jacobian after assembly
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 ~TransientAssembly()
destructor resets the association of this assembly object with the system
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 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 .
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
Matrix< Real, Dynamic, Dynamic > RealMatrixX
virtual bool sensitivity_assemble(const MAST::FunctionBase &f, libMesh::NumericVector< Real > &sensitivity_rhs)
Assembly function.
void copy(DenseRealMatrix &m1, const RealMatrixX &m2)
virtual void build_local_quantities(const libMesh::NumericVector< Real > ¤t_sol, std::vector< libMesh::NumericVector< Real > * > &qtys)
localizes the relevant solutions for system assembly.
virtual void build_sensitivity_local_quantities(unsigned int prev_iter, std::vector< libMesh::NumericVector< Real > * > &qtys)
localizes the relevant solutions for system assembly.
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...
void set_post_assembly_operation(MAST::TransientAssembly::PostAssemblyOperation &post)
sets the PostAssemblyOperation object for use after assembly.
void init(const libMesh::NumericVector< Real > &sol, const libMesh::NumericVector< Real > *dsol=nullptr)
initializes the data structures to perform the interpolation function of sol.
virtual void clear_elem()
clears the element initialization
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 ...
virtual void init(const libMesh::Elem &elem, const MAST::SystemInitialization &sys_init)
initialize the object for the specified reference elem.
user-provided object to perform actions after assembly and before returning to the solver...
virtual void elem_linearized_jacobian_solution_product(RealVectorX &vec)=0
performs the element calculations over elem, and returns the element vector quantity in vec...
MAST::MeshFieldFunction * _sol_function
system solution that will be initialized before each solution