libMesh
rb_eim_assembly.C
Go to the documentation of this file.
1 // rbOOmit: An implementation of the Certified Reduced Basis method.
2 // Copyright (C) 2009, 2010 David J. Knezevic
3 
4 // This file is part of rbOOmit.
5 
6 // rbOOmit is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 
11 // rbOOmit is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 // rbOOmit includes
21 #include "libmesh/rb_eim_assembly.h"
22 #include "libmesh/rb_eim_construction.h"
23 #include "libmesh/rb_evaluation.h"
24 
25 // libMesh includes
26 #include "libmesh/fem_context.h"
27 #include "libmesh/dof_map.h"
28 #include "libmesh/quadrature.h"
29 #include "libmesh/libmesh_logging.h"
30 #include "libmesh/int_range.h"
31 
32 namespace libMesh
33 {
34 
36  unsigned int basis_function_index_in)
37  : _rb_eim_con(rb_eim_con_in),
38  _basis_function_index(basis_function_index_in),
39  _ghosted_basis_function(NumericVector<Number>::build(rb_eim_con_in.get_explicit_system().comm()))
40 {
41  // localize the vector that stores the basis function for this assembly object,
42  // i.e. the vector that is used in evaluate_basis_function_at_quad_pts
43 #ifdef LIBMESH_ENABLE_GHOSTED
47  false,
48  GHOSTED);
50  localize(*_ghosted_basis_function,
52 #else
55  localize(*_ghosted_basis_function);
56 #endif
57 
58  initialize_fe();
59 }
60 
62 {
63 }
64 
66  const Elem & element,
67  const std::vector<Point> & points,
68  std::vector<Number> & values)
69 {
70  LOG_SCOPE("evaluate_basis_function", "RBEIMAssembly");
71 
72  const std::vector<std::vector<Real>> & phi = get_fe().get_phi();
73 
74  // The FE object caches data, hence we recompute as little as
75  // possible on the call to reinit.
76  get_fe().reinit (&element, &points);
77 
78  std::vector<dof_id_type> dof_indices_var;
79 
81  dof_map.dof_indices (&element, dof_indices_var, var);
82 
83  libmesh_assert(dof_indices_var.size() == phi.size());
84 
85  unsigned int n_points = points.size();
86  values.resize(n_points);
87 
88  for (unsigned int pt_index=0; pt_index<n_points; pt_index++)
89  {
90  values[pt_index] = 0.;
91  for (auto i : index_range(dof_indices_var))
92  values[pt_index] += (*_ghosted_basis_function)(dof_indices_var[i]) * phi[i][pt_index];
93  }
94 }
95 
97 {
98  return _rb_eim_con;
99 }
100 
102 {
103  return *_ghosted_basis_function;
104 }
105 
107 {
108  return *_fe;
109 }
110 
112 {
114 
115  const unsigned int dim =
117 
118  FEType fe_type = dof_map.variable_type(0);
119  _fe = FEBase::build(dim, fe_type);
120 
121  // Pre-request the shape function for efficieny's sake
122  _fe->get_phi();
123 }
124 
125 }
libMesh::RBEIMAssembly::get_fe
FEBase & get_fe()
Retrieve the FE object.
Definition: rb_eim_assembly.C:106
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::DofMap::dof_indices
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1967
libMesh::RBEIMAssembly::_rb_eim_con
RBEIMConstruction & _rb_eim_con
The RBEIMConstruction object that this RBEIMAssembly is based on.
Definition: rb_eim_assembly.h:99
libMesh::SERIAL
Definition: enum_parallel_type.h:35
libMesh::index_range
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...
Definition: int_range.h:106
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::FEGenericBase
This class forms the foundation from which generic finite elements may be derived.
Definition: exact_error_estimator.h:39
libMesh::GHOSTED
Definition: enum_parallel_type.h:37
libMesh::MeshBase::mesh_dimension
unsigned int mesh_dimension() const
Definition: mesh_base.C:135
libMesh::RBEIMAssembly::get_ghosted_basis_function
NumericVector< Number > & get_ghosted_basis_function()
Get a reference to the ghosted_basis_function.
Definition: rb_eim_assembly.C:101
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::NumericVector
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Definition: vector_fe_ex5.C:43
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::RBEIMAssembly::_ghosted_basis_function
std::unique_ptr< NumericVector< Number > > _ghosted_basis_function
The basis function that we sample to evaluate the empirical interpolation approximation.
Definition: rb_eim_assembly.h:111
libMesh::System::n_local_dofs
dof_id_type n_local_dofs() const
Definition: system.C:187
libMesh::RBEIMAssembly::RBEIMAssembly
RBEIMAssembly(RBEIMConstruction &rb_eim_con_in, unsigned int basis_function_index_in)
Constructor.
Definition: rb_eim_assembly.C:35
libMesh::System::get_mesh
const MeshBase & get_mesh() const
Definition: system.h:2083
libMesh::FEGenericBase::build
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
libMesh::RBConstruction::get_rb_evaluation
RBEvaluation & get_rb_evaluation()
Get a reference to the RBEvaluation object.
Definition: rb_construction.C:175
libMesh::DofMap::variable_type
const FEType & variable_type(const unsigned int c) const
Definition: dof_map.h:1924
libMesh::RBEIMAssembly::evaluate_basis_function
virtual void evaluate_basis_function(unsigned int var, const Elem &element, const std::vector< Point > &points, std::vector< Number > &values)
Evaluate variable var_number of this object's EIM basis function at the points points,...
Definition: rb_eim_assembly.C:65
libMesh::DofMap::get_send_list
const std::vector< dof_id_type > & get_send_list() const
Definition: dof_map.h:496
libMesh::RBEIMAssembly::_fe
std::unique_ptr< FEBase > _fe
We store an FE object so we can easily reinit in evaluate_basis_function.
Definition: rb_eim_assembly.h:116
libMesh::FEType
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:178
libMesh::RBEIMAssembly::~RBEIMAssembly
virtual ~RBEIMAssembly()
Destructor.
Definition: rb_eim_assembly.C:61
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::RBEIMConstruction::get_explicit_system
ExplicitSystem & get_explicit_system()
Get the ExplicitSystem associated with this system.
Definition: rb_eim_construction.C:267
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::System::n_dofs
dof_id_type n_dofs() const
Definition: system.C:150
libMesh::FEGenericBase::get_phi
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:206
libMesh::RBEIMAssembly::get_rb_eim_construction
RBEIMConstruction & get_rb_eim_construction()
Get a reference to the RBEIMConstruction object.
Definition: rb_eim_assembly.C:96
libMesh::FEAbstract::reinit
virtual void reinit(const Elem *elem, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr)=0
This is at the core of this class.
libMesh::RBEvaluation::get_basis_function
NumericVector< Number > & get_basis_function(unsigned int i)
Get a reference to the i^th basis function.
Definition: rb_evaluation.C:202
libMesh::RBEIMConstruction
This class is part of the rbOOmit framework.
Definition: rb_eim_construction.h:48
libMesh::RBEIMAssembly::initialize_fe
void initialize_fe()
Initialize the FE object.
Definition: rb_eim_assembly.C:111
libMesh::RBEIMAssembly::_basis_function_index
unsigned int _basis_function_index
The EIM basis function index (from rb_eim_eval) for this assembly object.
Definition: rb_eim_assembly.h:104