21#include "libmesh/libmesh_config.h"
25#if defined(LIBMESH_HAVE_SLEPC) && (LIBMESH_HAVE_GLPK)
28#include "libmesh/rb_scm_evaluation.h"
29#include "libmesh/rb_theta_expansion.h"
32#include "libmesh/dof_map.h"
33#include "libmesh/equation_systems.h"
34#include "libmesh/getpot.h"
35#include "libmesh/int_range.h"
36#include "libmesh/libmesh_logging.h"
37#include "libmesh/numeric_vector.h"
38#include "libmesh/sparse_matrix.h"
39#include "libmesh/xdr_cxx.h"
72 libmesh_error_msg_if(!
rb_theta_expansion,
"Error: rb_theta_expansion hasn't been initialized yet");
79 libmesh_error_msg_if(j >=
C_J_stability_vector.size(),
"Error: Input parameter j is too large in set_C_J_stability_constraint.");
90 libmesh_error_msg_if(j >=
C_J_stability_vector.size(),
"Error: Input parameter j is too large in get_C_J_stability_constraint.");
98 libmesh_error_msg_if(j >=
SCM_UB_vectors.size(),
"Error: We must have j < J in set_SCM_UB_vector.");
101 libmesh_error_msg_if(q >=
SCM_UB_vectors[0].size(),
"Error: q is too large in set_SCM_UB_vector.");
109 libmesh_error_msg_if(j >=
SCM_UB_vectors.size(),
"Error: We must have j < J in get_SCM_UB_vector.");
110 libmesh_error_msg_if(q >=
SCM_UB_vectors[0].size(),
"Error: q is too large in get_SCM_UB_vector.");
117 libmesh_error_msg_if(j >=
C_J.size(),
"Error: Input parameter j is too large in get_C_J.");
124 libmesh_error_msg_if(q >=
B_min.size(),
"Error: q is too large in get_B_min.");
132 libmesh_error_msg_if(q >=
B_max.size(),
"Error: q is too large in get_B_max.");
139 libmesh_error_msg_if(q >=
B_min.size(),
"Error: q is too large in set_B_min.");
141 B_min[q] = B_min_val;
146 libmesh_error_msg_if(q >=
B_max.size(),
"Error: q is too large in set_B_max.");
148 B_max[q] = B_max_val;
153 LOG_SCOPE(
"get_SCM_LB()",
"RBSCMEvaluation");
157 lp = glp_create_prob();
158 glp_set_obj_dir(lp,GLP_MIN);
171 glp_set_col_bnds(lp, q+1, GLP_FR, 0., 0.);
176 glp_set_col_bnds(lp, q+1, GLP_DB,
double(
B_min[q]),
double(
B_max[q]));
187 unsigned int n_rows = cast_int<unsigned int>(
C_J.size());
188 glp_add_rows(lp, n_rows);
194 std::vector<int> ia(matrix_size+1);
195 std::vector<int> ja(matrix_size+1);
196 std::vector<double> ar(matrix_size+1);
197 unsigned int count=0;
198 for (
unsigned int m=0; m<n_rows; m++)
225 glp_load_matrix(lp, matrix_size, ia.data(), ja.data(), ar.data());
240 glp_init_smcp(&parm);
241 parm.msg_lev = GLP_MSG_ERR;
242 parm.meth = GLP_DUAL;
246 glp_simplex(lp, &parm);
248 Real min_J_obj = glp_get_obj_val(lp);
269 LOG_SCOPE(
"get_SCM_UB()",
"RBSCMEvaluation");
274 unsigned int n_rows = cast_int<unsigned int>(
C_J.size());
281 for (
unsigned int m=0; m<n_rows; m++)
291 if ((m==0) || (J_obj < min_J_obj))
316 const bool write_binary_data)
318 LOG_SCOPE(
"legacy_write_offline_data_to_files()",
"RBSCMEvaluation");
323 if (mkdir(directory_name.c_str(), 0777) == -1)
325 libMesh::out <<
"In RBSCMEvaluation::write_offline_data_to_files, directory "
326 << directory_name <<
" already exists, overwriting contents." << std::endl;
333 const std::string suffix = write_binary_data ?
".xdr" :
".dat";
336 std::ostringstream file_name;
340 file_name << directory_name <<
"/parameter_ranges" << suffix;
341 std::string continuous_param_file_name = file_name.str();
345 file_name << directory_name <<
"/discrete_parameter_values" << suffix;
346 std::string discrete_param_file_name = file_name.str();
349 discrete_param_file_name,
354 file_name << directory_name <<
"/B_min" << suffix;
355 Xdr B_min_out(file_name.str(), mode);
360 B_min_out << B_min_i;
367 file_name << directory_name <<
"/B_max" << suffix;
368 Xdr B_max_out(file_name.str(), mode);
373 B_max_out << B_max_i;
379 file_name << directory_name <<
"/C_J_length" << suffix;
380 Xdr C_J_length_out(file_name.str(), mode);
382 unsigned int C_J_length = cast_int<unsigned int>(
C_J.size());
383 C_J_length_out << C_J_length;
384 C_J_length_out.
close();
388 file_name << directory_name <<
"/C_J_stability_vector" << suffix;
389 Xdr C_J_stability_vector_out(file_name.str(), mode);
394 C_J_stability_vector_out << C_J_stability_constraint_i;
396 C_J_stability_vector_out.
close();
400 file_name << directory_name <<
"/C_J" << suffix;
401 Xdr C_J_out(file_name.str(), mode);
403 for (
const auto & param :
C_J)
404 for (
const auto & pr : param)
405 for (
const auto & value_vector : pr.second)
409 libmesh_error_msg_if(value_vector.size() != 1,
410 "Error: multi-value RB parameters are not yet supported here.");
411 Real param_value = value_vector[0];
412 C_J_out << param_value;
418 file_name << directory_name <<
"/SCM_UB_vectors" << suffix;
419 Xdr SCM_UB_vectors_out(file_name.str(), mode);
425 SCM_UB_vectors_out << SCM_UB_vector_ij;
427 SCM_UB_vectors_out.
close();
433 const bool read_binary_data)
435 LOG_SCOPE(
"legacy_read_offline_data_from_files()",
"RBSCMEvaluation");
441 const std::string suffix = read_binary_data ?
".xdr" :
".dat";
444 std::ostringstream file_name;
448 file_name << directory_name <<
"/parameter_ranges" << suffix;
449 std::string continuous_param_file_name = file_name.str();
453 file_name << directory_name <<
"/discrete_parameter_values" << suffix;
454 std::string discrete_param_file_name = file_name.str();
456 discrete_param_file_name,
462 file_name << directory_name <<
"/B_min" << suffix;
463 Xdr B_min_in(file_name.str(), mode);
469 B_min_in >> B_min_val;
470 B_min.push_back(B_min_val);
478 file_name << directory_name <<
"/B_max" << suffix;
479 Xdr B_max_in(file_name.str(), mode);
485 B_max_in >> B_max_val;
486 B_max.push_back(B_max_val);
491 file_name << directory_name <<
"/C_J_length" << suffix;
492 Xdr C_J_length_in(file_name.str(), mode);
494 unsigned int C_J_length;
495 C_J_length_in >> C_J_length;
496 C_J_length_in.
close();
500 file_name << directory_name <<
"/C_J_stability_vector" << suffix;
501 Xdr C_J_stability_vector_in(file_name.str(), mode);
504 for (
unsigned int i=0; i<C_J_length; i++)
506 Real C_J_stability_val;
507 C_J_stability_vector_in >> C_J_stability_val;
510 C_J_stability_vector_in.
close();
514 file_name << directory_name <<
"/C_J" << suffix;
515 Xdr C_J_in(file_name.str(), mode);
518 C_J.resize( C_J_length );
519 for (
auto & params :
C_J)
522 const std::string & param_name = pr.first;
524 C_J_in >> param_value;
525 params.set_value(param_name, param_value);
532 file_name << directory_name <<
"/SCM_UB_vectors" << suffix;
533 Xdr SCM_UB_vectors_in(file_name.str(), mode);
545 SCM_UB_vectors_in.
close();
An object whose state is distributed along a set of processors.
processor_id_type processor_id() const
This class is part of the rbOOmit framework.
void write_parameter_data_to_files(const std::string &continuous_param_file_name, const std::string &discrete_param_file_name, const bool write_binary_data)
Write out the parameter ranges to files.
const RBParameters & get_parameters() const
Get the current parameters.
bool set_parameters(const RBParameters ¶ms)
Set the current parameters to params The parameters are checked for validity; an error is thrown if t...
void read_parameter_data_from_files(const std::string &continuous_param_file_name, const std::string &discrete_param_file_name, const bool read_binary_data)
Read in the parameter ranges from files.
virtual ~RBSCMEvaluation()
Destructor.
virtual void legacy_read_offline_data_from_files(const std::string &directory_name="offline_data", const bool read_binary_data=true)
Read in the saved Offline reduced basis data to initialize the system for Online solves.
Real get_B_min(unsigned int i) const
Get B_min and B_max.
RBSCMEvaluation(const Parallel::Communicator &comm)
Constructor.
Real get_C_J_stability_constraint(unsigned int j) const
Get stability constraints (i.e.
std::vector< Real > B_max
Real get_SCM_UB_vector(unsigned int j, unsigned int q)
Get entries of SCM_UB_vector, which stores the vector y, corresponding to the minimizing eigenvectors...
virtual Real get_SCM_LB()
Evaluate single SCM lower bound.
RBParameters saved_parameters
Vector in which to save a parameter set.
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the rb_theta_expansion.
Real get_B_max(unsigned int i) const
void set_SCM_UB_vector(unsigned int j, unsigned int q, Real y_q)
Set entries of SCM_UB_vector, which stores the vector y, corresponding to the minimizing eigenvectors...
virtual void set_current_parameters_from_C_J(unsigned int C_J_index)
Set parameters based on values saved in "C_J".
virtual Real get_SCM_UB()
Evaluate single SCM upper bound.
virtual void legacy_write_offline_data_to_files(const std::string &directory_name="offline_data", const bool write_binary_data=true)
Write out all the data to text files in order to segregate the Offline stage from the Online stage.
RBThetaExpansion * rb_theta_expansion
A pointer to to the object that stores the theta expansion.
void set_B_max(unsigned int i, Real B_max_val)
std::vector< Real > C_J_stability_vector
Vector storing the (truth) stability values at the parameters in C_J.
std::vector< Real > B_min
B_min, B_max define the bounding box.
virtual void reload_current_parameters()
Helper function to (re)load current_parameters from saved_parameters.
void set_C_J_stability_constraint(unsigned int j, Real stability_constraint_in)
Set stability constraints (i.e.
std::vector< std::vector< Real > > SCM_UB_vectors
This matrix stores the infimizing vectors y_1( ),...,y_Q_a( ), for each in C_J, which are used in co...
void set_B_min(unsigned int i, Real B_min_val)
Set B_min and B_max.
void set_rb_theta_expansion(RBThetaExpansion &rb_theta_expansion_in)
Set the RBThetaExpansion object.
const RBParameters & get_C_J_entry(unsigned int j)
Get entry of C_J.
virtual void save_current_parameters()
Helper function to save current_parameters in saved_parameters.
std::vector< RBParameters > C_J
Vector storing the greedily selected parameters during SCM training.
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
unsigned int get_n_A_terms() const
Get Q_a, the number of terms in the affine expansion for the bilinear form.
virtual Number eval_A_theta(unsigned int q, const RBParameters &mu) const
Evaluate theta_q_a at the current parameter.
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
void close()
Closes the file if it is open.
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
XdrMODE
Defines an enum for read/write mode in Xdr format.
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...