void AssembleOptimization::inequality_constraints_jacobian (const NumericVector<Number> & X, SparseMatrix<Number> & C_ineq_jac, OptimizationSystem & sys) { C_ineq_jac.zero(); std::unique_ptr<NumericVector<Number>> X_localized = NumericVector<Number>::build(X.comm()); X_localized->init(X.size(), false, SERIAL); X.localize(*X_localized); std::vector<std::vector<Number>> constraint_jac_values(1); std::vector<std::vector<dof_id_type>> constraint_jac_indices(1); constraint_jac_values[0].resize(2); constraint_jac_indices[0].resize(2); constraint_jac_values[0][0] = 2.* (*X_localized)(200); constraint_jac_values[0][1] = 1.; constraint_jac_indices[0][0] = 200; constraint_jac_indices[0][1] = 201; for (std::size_t i=0; i<constraint_jac_values.size(); i++) for (std::size_t j=0; j<constraint_jac_values[i].size(); j++) if ((sys.C_ineq->first_local_index() <= i) && (i < sys.C_ineq->last_local_index())) { dof_id_type col_index = constraint_jac_indices[i][j]; Number value = constraint_jac_values[i][j]; C_ineq_jac.set(i, col_index, value); } }
void AssembleOptimization::inequality_constraints (const NumericVector<Number> & X, NumericVector<Number> & C_ineq, OptimizationSystem & /*sys*/) { C_ineq.zero(); std::unique_ptr<NumericVector<Number>> X_localized = NumericVector<Number>::build(X.comm()); X_localized->init(X.size(), false, SERIAL); X.localize(*X_localized); std::vector<Number> constraint_values(1); constraint_values[0] = (*X_localized)(200)*(*X_localized)(200) + (*X_localized)(201) - 5.; for (std::size_t i=0; i<constraint_values.size(); i++) if ((C_ineq.first_local_index() <= i) && (i < C_ineq.last_local_index())) C_ineq.set(i, constraint_values[i]); }
void AssembleOptimization::equality_constraints (const NumericVector<Number> & X, NumericVector<Number> & C_eq, OptimizationSystem & /*sys*/) { C_eq.zero(); UniquePtr<NumericVector<Number> > X_localized = NumericVector<Number>::build(X.comm()); X_localized->init(X.size(), false, SERIAL); X.localize(*X_localized); std::vector<Number> constraint_values(3); constraint_values[0] = (*X_localized)(17); constraint_values[1] = (*X_localized)(23); constraint_values[2] = (*X_localized)(98) + (*X_localized)(185); for (unsigned int i=0; i<constraint_values.size(); i++) if ((C_eq.first_local_index() <= i) && (i < C_eq.last_local_index())) C_eq.set(i, constraint_values[i]); }
void AdamsPredictor::apply(NumericVector<Number> & sln) { // At the moment, I don't believe there is a function in Predictor // that gets called on time step begin. // That means that history control must go here. historyControl(); // AB2 can only be applied if there are enough old solutions // AB1 could potentially be used for the time step prior? // It would be possible to do VSVO Adams, Kevin has the info // Doing so requires a time stack of some sort.... if (_dt == 0 || _dt_old == 0 || _dt_older == 0 || _t_step < 2) return; // localize current solution to working vec sln.localize(_solution_predictor); // NumericVector<Number> & vector1 = _tmp_previous_solution; NumericVector<Number> & vector2 = _tmp_residual_old; NumericVector<Number> & vector3 = _tmp_third_vector; Real commonpart = _dt / _dt_old; Real firstpart = (1 + .5 * commonpart); Real secondpart = .5 * _dt / _dt_older; _older_solution.localize(vector2); _oldest_solution.localize(vector3); _solution_predictor *= 1 + commonpart * firstpart; vector2 *= -1. * commonpart * (firstpart + secondpart); vector3 *= commonpart * secondpart; _solution_predictor += vector2; _solution_predictor += vector3; _solution_predictor.localize(sln); }
void LinearElasticityWithContact::move_mesh (MeshBase & input_mesh, const NumericVector<Number> & input_solution) { // Maintain a set of node ids that we've encountered. LIBMESH_BEST_UNORDERED_SET<dof_id_type> encountered_node_ids; // Localize input_solution so that we have the data to move all // elements (not just elements local to this processor). UniquePtr< NumericVector<Number> > localized_input_solution = NumericVector<Number>::build(input_solution.comm()); localized_input_solution->init (input_solution.size(), false, SERIAL); input_solution.localize(*localized_input_solution); MeshBase::const_element_iterator el = input_mesh.active_elements_begin(); const MeshBase::const_element_iterator end_el = input_mesh.active_elements_end(); for ( ; el != end_el; ++el) { Elem * elem = *el; Elem * orig_elem = _sys.get_mesh().elem_ptr(elem->id()); for (unsigned int node_id=0; node_id<elem->n_nodes(); node_id++) { Node & node = elem->node_ref(node_id); if (encountered_node_ids.find(node.id()) != encountered_node_ids.end()) continue; encountered_node_ids.insert(node.id()); std::vector<std::string> uvw_names(3); uvw_names[0] = "u"; uvw_names[1] = "v"; uvw_names[2] = "w"; { const Point master_point = elem->master_point(node_id); Point uvw; for (unsigned int index=0; index<uvw_names.size(); index++) { const unsigned int var = _sys.variable_number(uvw_names[index]); const FEType & fe_type = _sys.get_dof_map().variable_type(var); FEComputeData data (_sys.get_equation_systems(), master_point); FEInterface::compute_data(elem->dim(), fe_type, elem, data); std::vector<dof_id_type> dof_indices_var; _sys.get_dof_map().dof_indices (orig_elem, dof_indices_var, var); for (unsigned int i=0; i<dof_indices_var.size(); i++) { Number value = (*localized_input_solution)(dof_indices_var[i]) * data.shape[i]; #ifdef LIBMESH_USE_COMPLEX_NUMBERS // We explicitly store the real part in uvw uvw(index) += value.real(); #else uvw(index) += value; #endif } } // Update the node's location node += uvw; } } } }