35 #include "libmesh/numeric_vector.h" 36 #include "libmesh/dof_map.h" 42 _discipline (nullptr),
44 _sol_function (nullptr),
45 _solver_monitor (nullptr),
46 _param_dependence (nullptr) {
65 "Error: Discipline not yet attached to Assembly.");
75 "Error: Discipline not yet attached to Assembly.");
86 "Error: System not yet attached to Assembly.");
95 "Error: System not yet attached to Assembly.");
104 "Error: Not yet initialized.");
113 "Error: System not yet attached to Assembly.");
166 "Error: Assembly should be cleared before attaching System.");
190 "Error: Assembly should be cleared before attaching Elem.");
209 std::unique_ptr<libMesh::NumericVector<Real> >
212 const libMesh::NumericVector<Real>& global)
const {
214 libMesh::NumericVector<Real>* local =
215 libMesh::NumericVector<Real>::build(sys.comm()).release();
217 const std::vector<libMesh::dof_id_type>& send_list =
218 sys.get_dof_map().get_send_list();
220 local->init(sys.n_dofs(),
225 global.localize(*local, send_list);
227 return std::unique_ptr<libMesh::NumericVector<Real> >(local);
269 std::vector<libMesh::dof_id_type> dof_indices;
270 const libMesh::DofMap& dof_map =
_system->
system().get_dof_map();
272 std::unique_ptr<libMesh::NumericVector<Real> > localized_solution;
281 libMesh::MeshBase::const_element_iterator el =
282 nonlin_sys.get_mesh().active_local_elements_begin();
283 const libMesh::MeshBase::const_element_iterator end_el =
284 nonlin_sys.get_mesh().active_local_elements_end();
287 for ( ; el != end_el; ++el) {
289 const libMesh::Elem* elem = *el;
291 dof_map.dof_indices (elem, dof_indices);
294 unsigned int ndofs = (
unsigned int)dof_indices.size();
297 for (
unsigned int i=0; i<dof_indices.size(); i++)
298 sol(i) = (*localized_solution)(dof_indices[i]);
306 geom_elem.init(*elem, *
_system);
308 output.
init(geom_elem);
330 libMesh::NumericVector<Real>& dq_dX) {
346 std::vector<libMesh::dof_id_type> dof_indices;
347 const libMesh::DofMap& dof_map =
_system->
system().get_dof_map();
350 std::unique_ptr<libMesh::NumericVector<Real> > localized_solution;
360 libMesh::MeshBase::const_element_iterator el =
361 nonlin_sys.get_mesh().active_local_elements_begin();
362 const libMesh::MeshBase::const_element_iterator end_el =
363 nonlin_sys.get_mesh().active_local_elements_end();
366 for ( ; el != end_el; ++el) {
368 const libMesh::Elem* elem = *el;
370 dof_map.dof_indices (elem, dof_indices);
373 unsigned int ndofs = (
unsigned int)dof_indices.size();
377 for (
unsigned int i=0; i<dof_indices.size(); i++)
378 sol(i) = (*localized_solution)(dof_indices[i]);
385 geom_elem.init(*elem, *
_system);
387 output.
init(geom_elem);
394 dof_map.constrain_element_vector(v, dof_indices);
395 dq_dX.add_vector(v, dof_indices);
413 const libMesh::NumericVector<Real>* dXdp,
431 std::vector<libMesh::dof_id_type> dof_indices;
432 const libMesh::DofMap& dof_map =
_system->
system().get_dof_map();
435 std::unique_ptr<libMesh::NumericVector<Real> >
437 localized_solution_sens;
450 libMesh::MeshBase::const_element_iterator el =
451 nonlin_sys.get_mesh().active_local_elements_begin();
452 const libMesh::MeshBase::const_element_iterator end_el =
453 nonlin_sys.get_mesh().active_local_elements_end();
456 for ( ; el != end_el; ++el) {
458 const libMesh::Elem* elem = *el;
470 dof_map.dof_indices (elem, dof_indices);
473 unsigned int ndofs = (
unsigned int)dof_indices.size();
477 for (
unsigned int i=0; i<dof_indices.size(); i++) {
478 sol(i) = (*localized_solution)(dof_indices[i]);
480 dsol(i) = (*localized_solution_sens)(dof_indices[i]);
488 geom_elem.init(*elem, *
_system);
490 output.
init(geom_elem);
512 const libMesh::NumericVector<Real>& dq_dX,
516 const bool include_partial_sens) {
523 libMesh::NumericVector<Real>
524 &dres_dp = nonlin_sys.add_sensitivity_rhs();
531 dq_dp = dq_dX.dot(dres_dp);
533 if (include_partial_sens) {
MAST::AssemblyElemOperations * _elem_ops
provides assembly elem operations for use by this class
MAST::NonlinearSystem & system()
virtual bool if_elem_depends_on_parameter(const libMesh::Elem &e, const MAST::FunctionBase &p) const =0
AssemblyBase()
constructor takes a reference to the discipline that provides the boundary conditions, volume loads, properties, etc.
void clear_solver_monitor()
clears the monitor object
This class implements a system for solution of nonlinear systems.
bool override_flag
if true, assume zero solution sensitivity when elem does not dependent on parameter.
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.
This provides a wrapper FieldFunction compatible class that interpolates the solution using libMesh's...
void attach_solution_function(MAST::MeshFieldFunction &f)
tells the assembly object that this function is will need to be initialized before each residual eval...
virtual void calculate_output_derivative(const libMesh::NumericVector< Real > &X, MAST::OutputAssemblyElemOperations &output, libMesh::NumericVector< Real > &dq_dX)
calculates
void attach_elem_parameter_dependence_object(MAST::AssemblyBase::ElemParameterDependence &dep)
This object, if provided by user, will be used to reduce unnecessary computations in sensitivity anal...
virtual Real calculate_output_adjoint_sensitivity(const libMesh::NumericVector< Real > &X, const libMesh::NumericVector< Real > &dq_dX, const MAST::FunctionBase &p, MAST::AssemblyElemOperations &elem_ops, MAST::OutputAssemblyElemOperations &output, const bool include_partial_sens=true)
Evaluates the total sensitivity of output wrt p using the adjoint solution provided in dq_dX for a li...
virtual void set_elem_solution_sensitivity(const RealVectorX &sol)
sets the element solution sensitivity
void set_solver_monitor(MAST::AssemblyBase::SolverMonitor &monitor)
attaches the solver monitor, which is a user provided routine that is called each time ...
virtual void set_assembly(MAST::AssemblyBase &assembly)
sets the assembly object
This provides the base class for definitin of element level contribution of output quantity in an ana...
virtual void zero_for_sensitivity()=0
zeroes the output quantity values stored inside this object so that assembly process can begin...
bool close_matrix
flag to control the closing fo the Jacobian after assembly
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...
virtual void set_elem_solution(const RealVectorX &sol)
sets the element solution
virtual void evaluate()=0
this is the abstract interface to be implemented by derived classes.
MAST::SystemInitialization * _system
System for which this assembly is performed.
void detach_solution_function()
removes the attachment of the solution function
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 clear_discipline_and_system()
clears association with a system to this discipline
virtual void calculate_output(const libMesh::NumericVector< Real > &X, MAST::OutputAssemblyElemOperations &output)
calculates the value of quantity .
libMesh::DenseVector< Real > DenseRealVector
virtual void clear_assembly()
clears the assembly object
void copy(DenseRealMatrix &m1, const RealMatrixX &m2)
void clear()
clear the solution
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 init(const MAST::GeomElem &elem)=0
initializes the object for calculation of element quantities for the specified elem.
virtual void output_derivative_for_elem(RealVectorX &dq_dX)=0
returns the output quantity derivative with respect to state vector in dq_dX.
void clear_elem_parameter_dependence_object()
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...
MAST::AssemblyBase::SolverMonitor * get_solver_monitor()
This class acts as a wrapper around libMesh::Elem for the purpose of providing a uniform interface fo...
Inherited objects from this class can be provided by the user provide assessment of whether or not an...
MAST::SystemInitialization & system_init()
virtual void zero_for_analysis()=0
zeroes the output quantity values stored inside this object so that assembly process can begin...
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 ...
virtual void set_discipline_and_system(MAST::PhysicsDisciplineBase &discipline, MAST::SystemInitialization &system)
attaches a system to this discipline
virtual void clear_elem()
clears the element initialization
virtual ~AssemblyBase()
virtual destructor
MAST::AssemblyElemOperations & get_elem_ops()
MAST::AssemblyBase::SolverMonitor * _solver_monitor
User provided solver monitor is attached to the linear nonlinear solvers, if provided.
const MAST::NonlinearSystem & system() const
virtual void evaluate_sensitivity(const MAST::FunctionBase &f)=0
this evaluates all relevant sensitivity components on the element.
MAST::MeshFieldFunction * _sol_function
system solution that will be initialized before each solution
const MAST::PhysicsDisciplineBase & discipline() const