Go to the documentation of this file.
25 #include "libmesh/rb_eim_evaluation.h"
26 #include "libmesh/rb_eim_theta.h"
27 #include "libmesh/rb_parametrized_function.h"
30 #include "libmesh/xdr_cxx.h"
31 #include "libmesh/libmesh_logging.h"
32 #include "libmesh/replicated_mesh.h"
33 #include "libmesh/elem.h"
34 #include "libmesh/auto_ptr.h"
43 _previous_error_bound(-1),
44 _interpolation_points_mesh(comm_in)
76 bool resize_error_bound_data)
94 return cast_int<unsigned int>
108 libmesh_error_msg(
"Error: We must have var_index < get_n_parametrized_functions() in evaluate_parametrized_function.");
125 LOG_SCOPE(
"rb_solve()",
"RBEIMEvaluation");
128 libmesh_error_msg(
"ERROR: N cannot be larger than the number of basis functions in rb_solve");
131 libmesh_error_msg(
"ERROR: N must be greater than 0 in rb_solve");
136 for (
unsigned int i=0; i<N; i++)
162 Number EIM_approx_at_next_x = 0.;
163 for (
unsigned int j=0; j<N; j++)
168 Real error_estimate =
std::abs(g_at_next_x - EIM_approx_at_next_x);
171 return error_estimate;
183 LOG_SCOPE(
"rb_solve()",
"RBEIMEvaluation");
186 libmesh_error_msg(
"ERROR: N cannot be larger than the number of basis functions in rb_solve");
188 if (EIM_rhs.
size()==0)
189 libmesh_error_msg(
"ERROR: N must be greater than 0 in rb_solve");
191 const unsigned int N = EIM_rhs.
size();
222 return libmesh_make_unique<RBEIMTheta>(*
this, index);
226 const bool read_binary_data)
228 LOG_SCOPE(
"legacy_write_offline_data_to_files()",
"RBEIMEvaluation");
239 const std::string suffix = read_binary_data ?
".xdr" :
".dat";
243 std::ostringstream file_name;
247 file_name << directory_name <<
"/interpolation_matrix" << suffix;
248 Xdr interpolation_matrix_out(file_name.str(), mode);
250 for (
unsigned int i=0; i<n_bfs; i++)
252 for (
unsigned int j=0; j<=i; j++)
260 file_name << directory_name <<
"/interpolation_points" << suffix;
261 Xdr interpolation_points_out(file_name.str(), mode);
263 for (
unsigned int i=0; i<n_bfs; i++)
267 if (LIBMESH_DIM >= 2)
270 if (LIBMESH_DIM >= 3)
273 interpolation_points_out.close();
277 file_name << directory_name <<
"/interpolation_points_var" << suffix;
278 Xdr interpolation_points_var_out(file_name.str(), mode);
280 for (
unsigned int i=0; i<n_bfs; i++)
284 interpolation_points_var_out.close();
298 std::set<dof_id_type> node_ids;
299 std::map<dof_id_type, dof_id_type> node_id_map;
301 unsigned int new_node_id = 0;
303 for (
unsigned int n=0; n<old_elem->n_nodes(); n++)
305 Node & node_ref = old_elem->node_ref(n);
310 if (node_ids.find(old_node_id) == node_ids.end())
312 node_ids.insert(old_node_id);
315 node_id_map[old_node_id] = new_node_id;
323 std::map<dof_id_type,dof_id_type> elem_id_map;
333 std::map<dof_id_type,dof_id_type>::iterator id_it = elem_id_map.find(old_elem_id);
334 if (id_it == elem_id_map.end())
340 for (
unsigned int n=0; n<new_elem->
n_nodes(); n++)
354 new_elem->
set_id(new_elem_id);
355 interpolation_elem_ids[i] = new_elem->
id();
356 elem_id_map[old_elem_id] = new_elem->
id();
362 interpolation_elem_ids[i] = id_it->second;
377 std::ofstream interpolation_elem_ids_out
380 for (
const auto &
id : interpolation_elem_ids)
381 interpolation_elem_ids_out <<
id << std::endl;
383 interpolation_elem_ids_out.close();
388 bool read_error_bound_data,
389 const bool read_binary_data)
391 LOG_SCOPE(
"legacy_read_offline_data_from_files()",
"RBEIMEvaluation");
403 const std::string suffix = read_binary_data ?
".xdr" :
".dat";
406 std::ostringstream file_name;
410 file_name << directory_name <<
"/interpolation_matrix" << suffix;
413 Xdr interpolation_matrix_in(file_name.str(), mode);
415 for (
unsigned int i=0; i<n_bfs; i++)
417 for (
unsigned int j=0; j<=i; j++)
420 interpolation_matrix_in >>
value;
424 interpolation_matrix_in.close();
428 file_name << directory_name <<
"/interpolation_points" << suffix;
431 Xdr interpolation_points_in(file_name.str(), mode);
433 for (
unsigned int i=0; i<n_bfs; i++)
435 Real x_val, y_val, z_val = 0.;
436 interpolation_points_in >> x_val;
438 if (LIBMESH_DIM >= 2)
439 interpolation_points_in >> y_val;
441 if (LIBMESH_DIM >= 3)
442 interpolation_points_in >> z_val;
444 Point p(x_val, y_val, z_val);
447 interpolation_points_in.close();
451 file_name << directory_name <<
"/interpolation_points_var" << suffix;
454 Xdr interpolation_points_var_in(file_name.str(), mode);
456 for (
unsigned int i=0; i<n_bfs; i++)
459 interpolation_points_var_in >> var;
462 interpolation_points_var_in.close();
475 std::vector<dof_id_type> interpolation_elem_ids;
478 std::ifstream interpolation_elem_ids_in
479 ((directory_name +
"/interpolation_elem_ids.dat").c_str(), std::ifstream::in);
481 if (!interpolation_elem_ids_in)
482 libmesh_error_msg(
"RB data missing: " + directory_name +
"/interpolation_elem_ids.dat");
484 for (
unsigned int i=0; i<n_bfs; i++)
487 interpolation_elem_ids_in >> elem_id;
488 interpolation_elem_ids.push_back(elem_id);
490 interpolation_elem_ids_in.close();
494 for (
unsigned int i=0; i<n_bfs; i++)
std::vector< RBParametrizedFunction * > _parametrized_functions
This vector stores the parametrized functions that will be approximated in this EIM system.
virtual unsigned int get_n_basis_functions() const
Get the current number of basis functions.
unsigned int _previous_N
Store the number of basis functions used for the previous solve (so we can avoid an unnecessary repea...
virtual Real rb_solve(unsigned int N) override
Calculate the EIM approximation to parametrized_function using the first N EIM basis functions.
void legacy_read_in_interpolation_points_elem(const std::string &directory_name)
Read int interpolation_points_elem from a mesh.
void legacy_write_out_interpolation_points_elem(const std::string &directory_name)
Write out interpolation_points_elem by putting the elements into a mesh and writing out the mesh.
virtual unsigned int n_nodes() const =0
virtual const Node * node_ptr(const dof_id_type i) const override
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
The libMesh namespace provides an interface to certain functionality in the library.
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
virtual void clear() override
Clear this object.
virtual Elem * add_elem(Elem *e) override
Add elem e to the end of the element array.
virtual void clear() override
Clear this RBEvaluation object.
void set_rb_theta_expansion(RBThetaExpansion &rb_theta_expansion_in)
Set the RBThetaExpansion object.
virtual void clear() override
Clear all internal data.
processor_id_type processor_id() const
void assert_file_exists(const std::string &file_name)
Helper function that checks if file_name exists.
virtual ~RBEIMEvaluation()
Destructor.
const RBParameters & get_parameters() const
Get the current parameters.
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
std::vector< unsigned int > interpolation_points_var
The corresponding list of variables indices at which the interpolation points were identified.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
virtual void write(const std::string &name) override
Write the file specified by name.
ReplicatedMesh & get_interpolation_points_mesh()
Get a writable reference to the interpolation points mesh.
virtual void resize_data_structures(const unsigned int Nmax, bool resize_error_bound_data=true) override
Resize the data structures for storing data associated with this object.
bool evaluate_RB_error_bound
Boolean to indicate whether we evaluate a posteriori error bounds when rb_solve is called.
void initialize_eim_theta_objects()
Build a vector of RBTheta objects that accesses the components of the RB_solution member variable of ...
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
virtual void legacy_read_offline_data_from_files(const std::string &directory_name="offline_data", bool read_error_bound_data=true, const bool read_binary_data=true)
Read in the saved Offline reduced basis data to initialize the system for Online solves.
virtual void legacy_write_offline_data_to_files(const std::string &directory_name="offline_data", const bool write_binary_data=true) override
Write out all the data to text files in order to segregate the Offline stage from the Online stage.
XdrMODE
Defines an enum for read/write mode in Xdr format.
DenseVector< Number > RB_solution
The RB solution vector.
processor_id_type processor_id() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false) override
Reads the file specified by name.
A simple functor class that provides a RBParameter-dependent function.
RBParameters _previous_parameters
Store the parameters at which the previous solve was performed (so we can avoid an unnecessary repeat...
A Node is like a Point, but with more information.
ReplicatedMesh _interpolation_points_mesh
Mesh object that we use to store copies of the elements associated with interpolation points.
std::vector< std::unique_ptr< RBTheta > > & get_eim_theta_objects()
virtual unsigned int size() const override
virtual Node *& set_node(const unsigned int i)
std::vector< std::unique_ptr< RBTheta > > _rb_eim_theta_objects
The vector of RBTheta objects that are created to point to this RBEIMEvaluation.
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.
virtual dof_id_type n_elem() const override
unsigned int get_n_parametrized_functions() const
Get the number of parametrized functions that have been attached to this system.
bool compute_RB_inner_product
Boolean flag to indicate whether we compute the RB_inner_product_matrix.
virtual std::unique_ptr< RBTheta > build_eim_theta(unsigned int index)
Build a theta object corresponding to EIM index index.
subdomain_id_type subdomain_id() const
This class is part of the rbOOmit framework.
virtual const Elem * elem_ptr(const dof_id_type i) const override
void get_principal_submatrix(unsigned int sub_m, unsigned int sub_n, DenseMatrix< T > &dest) const
Put the sub_m x sub_n principal submatrix into dest.
RBThetaExpansion _empty_rb_theta_expansion
We initialize RBEIMEvaluation so that it has an "empty" RBThetaExpansion, because this isn't used at ...
This is the base class from which all geometric element types are derived.
std::vector< Point > interpolation_points
The list of interpolation points, i.e.
Real _previous_error_bound
Store the previous error bound returned by rb_solve (so we can return it if we are avoiding an unnece...
virtual void resize_data_structures(const unsigned int Nmax, bool resize_error_bound_data=true)
Resize and clear the data vectors corresponding to the value of Nmax.
std::vector< Elem * > interpolation_points_elem
The corresponding list of elements at which the interpolation points were identified.
void lu_solve(const DenseVector< T > &b, DenseVector< T > &x)
Solve the system Ax=b given the input vector b.
virtual Real get_error_bound_normalization() override
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
dof_id_type node_id(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
DenseMatrix< Number > interpolation_matrix
Dense matrix that stores the lower triangular interpolation matrix that can be used.
virtual ElemType type() const =0
RBEIMEvaluation(const libMesh::Parallel::Communicator &comm_in)
Constructor.
virtual void legacy_read_offline_data_from_files(const std::string &directory_name="offline_data", bool read_error_bound_data=true, const bool read_binary_data=true) override
Read in the saved Offline reduced basis data to initialize the system for Online solves.
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id) override
functions for adding /deleting nodes elements.
Number evaluate_parametrized_function(unsigned int var_index, const Point &p, const Elem &elem)
void attach_parametrized_function(RBParametrizedFunction *pf)
Attach the parametrized function that we will approximate using the Empirical Interpolation Method.