diff_context.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_DIFF_CONTEXT_H
21 #define LIBMESH_DIFF_CONTEXT_H
22 
23 // Local Includes
24 #include "libmesh/dense_matrix.h"
27 #include "libmesh/dense_vector.h"
28 #include "libmesh/id_types.h"
29 
30 // C++ includes
31 #include <cstddef>
32 #include <map>
33 #include <vector>
34 #include <memory>
35 
36 namespace libMesh
37 {
38 
39 // Forward declarations
40 template <typename T> class NumericVector;
41 class System;
42 
56 {
57 public:
58 
63  explicit
64  DiffContext (const System &);
65 
69  virtual ~DiffContext ();
70 
76  virtual void elem_reinit(Real /* theta */) {}
77 
82  virtual void elem_side_reinit(Real /* theta */) {}
83 
88  virtual void elem_edge_reinit(Real /* theta */) {}
89 
94  virtual void nonlocal_reinit(Real /* theta */) {}
95 
99  unsigned int n_vars() const
100  { return cast_int<unsigned int>(_dof_indices_var.size()); }
101 
105  const System & get_system() const
106  { return _system; }
107 
112  { return _elem_solution; }
113 
118  { return _elem_solution; }
119 
124  const DenseSubVector<Number> & get_elem_solution( unsigned int var ) const
125  {
126  libmesh_assert_greater(_elem_subsolutions.size(), var);
127  libmesh_assert(_elem_subsolutions[var]);
128  return *(_elem_subsolutions[var]);
129  }
130 
136  {
137  libmesh_assert_greater(_elem_subsolutions.size(), var);
138  libmesh_assert(_elem_subsolutions[var]);
139  return *(_elem_subsolutions[var]);
140  }
141 
146  { return _elem_solution_rate; }
147 
153  { return _elem_solution_rate; }
154 
159  const DenseSubVector<Number> & get_elem_solution_rate( unsigned int var ) const
160  {
161  libmesh_assert_greater(_elem_subsolution_rates.size(), var);
162  libmesh_assert(_elem_subsolution_rates[var]);
163  return *(_elem_subsolution_rates[var]);
164  }
165 
171  {
172  libmesh_assert_greater(_elem_subsolution_rates.size(), var);
173  libmesh_assert(_elem_subsolution_rates[var]);
174  return *(_elem_subsolution_rates[var]);
175  }
176 
181  { return _elem_solution_accel; }
182 
188  { return _elem_solution_accel; }
189 
194  const DenseSubVector<Number> & get_elem_solution_accel( unsigned int var ) const
195  {
196  libmesh_assert_greater(_elem_subsolution_accels.size(), var);
197  libmesh_assert(_elem_subsolution_accels[var]);
198  return *(_elem_subsolution_accels[var]);
199  }
200 
206  {
207  libmesh_assert_greater(_elem_subsolution_accels.size(), var);
208  libmesh_assert(_elem_subsolution_accels[var]);
209  return *(_elem_subsolution_accels[var]);
210  }
211 
216  { return _elem_fixed_solution; }
217 
222  { return _elem_fixed_solution; }
223 
228  const DenseSubVector<Number> & get_elem_fixed_solution( unsigned int var ) const
229  {
230  libmesh_assert_greater(_elem_fixed_subsolutions.size(), var);
231  libmesh_assert(_elem_fixed_subsolutions[var]);
232  return *(_elem_fixed_subsolutions[var]);
233  }
234 
240  {
241  libmesh_assert_greater(_elem_fixed_subsolutions.size(), var);
242  libmesh_assert(_elem_fixed_subsolutions[var]);
243  return *(_elem_fixed_subsolutions[var]);
244  }
245 
250  { return _elem_residual; }
251 
256  { return _elem_residual; }
257 
262  const DenseSubVector<Number> & get_elem_residual( unsigned int var ) const
263  {
264  libmesh_assert_greater(_elem_subresiduals.size(), var);
265  libmesh_assert(_elem_subresiduals[var]);
266  return *(_elem_subresiduals[var]);
267  }
268 
274  {
275  libmesh_assert_greater(_elem_subresiduals.size(), var);
276  libmesh_assert(_elem_subresiduals[var]);
277  return *(_elem_subresiduals[var]);
278  }
279 
284  { return _elem_jacobian; }
285 
290  { return _elem_jacobian; }
291 
296  const DenseSubMatrix<Number> & get_elem_jacobian( unsigned int var1, unsigned int var2 ) const
297  {
298  libmesh_assert_greater(_elem_subjacobians.size(), var1);
299  libmesh_assert_greater(_elem_subjacobians[var1].size(), var2);
300  libmesh_assert(_elem_subjacobians[var1][var2]);
301  return *(_elem_subjacobians[var1][var2]);
302  }
303 
308  DenseSubMatrix<Number> & get_elem_jacobian( unsigned int var1, unsigned int var2 )
309  {
310  libmesh_assert_greater(_elem_subjacobians.size(), var1);
311  libmesh_assert_greater(_elem_subjacobians[var1].size(), var2);
312  libmesh_assert(_elem_subjacobians[var1][var2]);
313  return *(_elem_subjacobians[var1][var2]);
314  }
315 
319  const std::vector<Number> & get_qois() const
320  { return _elem_qoi; }
321 
325  std::vector<Number> & get_qois()
326  { return _elem_qoi; }
327 
331  const std::vector<DenseVector<Number>> & get_qoi_derivatives() const
332  { return _elem_qoi_derivative; }
333 
337  std::vector<DenseVector<Number>> & get_qoi_derivatives()
338  { return _elem_qoi_derivative; }
339 
344  const DenseSubVector<Number> & get_qoi_derivatives( std::size_t qoi, unsigned int var ) const
345  {
346  libmesh_assert_greater(_elem_qoi_subderivatives.size(), qoi);
347  libmesh_assert_greater(_elem_qoi_subderivatives[qoi].size(), var);
348  libmesh_assert(_elem_qoi_subderivatives[qoi][var]);
349  return *(_elem_qoi_subderivatives[qoi][var]);
350  }
351 
356  DenseSubVector<Number> & get_qoi_derivatives( std::size_t qoi, unsigned int var )
357  {
358  libmesh_assert_greater(_elem_qoi_subderivatives.size(), qoi);
359  libmesh_assert_greater(_elem_qoi_subderivatives[qoi].size(), var);
360  libmesh_assert(_elem_qoi_subderivatives[qoi][var]);
361  return *(_elem_qoi_subderivatives[qoi][var]);
362  }
363 
367  const std::vector<dof_id_type> & get_dof_indices() const
368  { return _dof_indices; }
369 
373  std::vector<dof_id_type> & get_dof_indices()
374  { return _dof_indices; }
375 
380  const std::vector<dof_id_type> & get_dof_indices( unsigned int var ) const
381  {
382  libmesh_assert_greater(_dof_indices_var.size(), var);
383  return _dof_indices_var[var];
384  }
385 
390  std::vector<dof_id_type> & get_dof_indices( unsigned int var )
391  {
392  libmesh_assert_greater(_dof_indices_var.size(), var);
393  return _dof_indices_var[var];
394  }
395 
399  unsigned int n_dof_indices() const
400  { return cast_int<unsigned int>(_dof_indices.size()); }
401 
406  unsigned int n_dof_indices( unsigned int var ) const
407  {
408  libmesh_assert_greater(_dof_indices_var.size(), var);
409  return cast_int<unsigned int>(_dof_indices_var[var].size());
410  }
411 
416  { return system_time; }
417 
421  Real get_time() const
422  { return time; }
423 
427  void set_time( Real time_in )
428  { time = time_in; }
429 
437  { return elem_solution_derivative; }
438 
447 
456 
464  { return fixed_solution_derivative; }
465 
470  bool is_adjoint() const
471  { return _is_adjoint; }
472 
477  bool & is_adjoint()
478  { return _is_adjoint; }
479 
486 
495 
501 
508 
515 
522 
527  void set_deltat_pointer(Real * dt);
528 
534 
539  void add_localized_vector (NumericVector<Number> & localized_vector, const System & sys);
540 
544  typedef std::map<const NumericVector<Number> *, std::pair<DenseVector<Number>, std::vector<std::unique_ptr<DenseSubVector<Number>>>>>::iterator localized_vectors_iterator;
545 
551 
555  const DenseVector<Number> & get_localized_vector (const NumericVector<Number> & localized_vector) const;
556 
561  DenseSubVector<Number> & get_localized_subvector (const NumericVector<Number> & localized_vector, unsigned int var);
562 
566  const DenseSubVector<Number> & get_localized_subvector (const NumericVector<Number> & localized_vector, unsigned int var) const;
567 
568 protected:
569 
575  std::map<const NumericVector<Number> *, std::pair<DenseVector<Number>, std::vector<std::unique_ptr<DenseSubVector<Number>>>>> _localized_vectors;
576 
582  std::vector<std::unique_ptr<DenseSubVector<Number>>> _elem_subsolutions;
583 
589  std::vector<std::unique_ptr<DenseSubVector<Number>>> _elem_subsolution_rates;
590 
596  std::vector<std::unique_ptr<DenseSubVector<Number>>> _elem_subsolution_accels;
597 
604  std::vector<std::unique_ptr<DenseSubVector<Number>>> _elem_fixed_subsolutions;
605 
610 
616 
620  std::vector<Number> _elem_qoi;
621 
625  std::vector<DenseVector<Number>> _elem_qoi_derivative;
626  std::vector<std::vector<std::unique_ptr<DenseSubVector<Number>>>> _elem_qoi_subderivatives;
627 
631  std::vector<std::unique_ptr<DenseSubVector<Number>>> _elem_subresiduals;
632  std::vector<std::vector<std::unique_ptr<DenseSubMatrix<Number>>>> _elem_subjacobians;
633 
637  std::vector<dof_id_type> _dof_indices;
638  std::vector<std::vector<dof_id_type>> _dof_indices_var;
639 
640 private:
641 
654 
658  const System & _system;
659 
664 
665 };
666 
667 } // namespace libMesh
668 
669 
670 #endif // LIBMESH_DIFF_CONTEXT_H
std::vector< std::vector< dof_id_type > > _dof_indices_var
Definition: diff_context.h:638
DenseSubMatrix< Number > & get_elem_jacobian(unsigned int var1, unsigned int var2)
Definition: diff_context.h:308
DenseSubVector< Number > & get_elem_solution_accel(unsigned int var)
Definition: diff_context.h:205
Real get_elem_solution_derivative() const
Definition: diff_context.h:436
const std::vector< Number > & get_qois() const
Definition: diff_context.h:319
DenseVector< Number > _elem_solution
Definition: diff_context.h:581
const DenseMatrix< Number > & get_elem_jacobian() const
Definition: diff_context.h:283
DenseSubVector< Number > & get_qoi_derivatives(std::size_t qoi, unsigned int var)
Definition: diff_context.h:356
std::vector< Number > _elem_qoi
Definition: diff_context.h:620
std::vector< std::unique_ptr< DenseSubVector< Number > > > _elem_subsolution_rates
Definition: diff_context.h:589
DenseVector< Number > & get_elem_residual()
Definition: diff_context.h:255
const DenseVector< Number > & get_elem_fixed_solution() const
Definition: diff_context.h:215
DenseVector< Number > _elem_fixed_solution
Definition: diff_context.h:603
const DenseVector< Number > & get_elem_solution_rate() const
Definition: diff_context.h:145
const DenseSubVector< Number > & get_elem_fixed_solution(unsigned int var) const
Definition: diff_context.h:228
const DenseSubVector< Number > & get_elem_solution_accel(unsigned int var) const
Definition: diff_context.h:194
const DenseSubVector< Number > & get_elem_solution_rate(unsigned int var) const
Definition: diff_context.h:159
const DenseSubVector< Number > & get_elem_solution(unsigned int var) const
Definition: diff_context.h:124
std::vector< std::unique_ptr< DenseSubVector< Number > > > _elem_subresiduals
Definition: diff_context.h:631
unsigned int n_dof_indices() const
Definition: diff_context.h:399
std::vector< std::unique_ptr< DenseSubVector< Number > > > _elem_subsolution_accels
Definition: diff_context.h:596
DenseSubVector< Number > & get_elem_solution_rate(unsigned int var)
Definition: diff_context.h:170
std::vector< DenseVector< Number > > _elem_qoi_derivative
Definition: diff_context.h:625
DenseVector< Number > & get_elem_solution_accel()
Definition: diff_context.h:187
DenseMatrix< Number > _elem_jacobian
Definition: diff_context.h:615
std::vector< std::vector< std::unique_ptr< DenseSubVector< Number > > > > _elem_qoi_subderivatives
Definition: diff_context.h:626
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
bool is_adjoint() const
Definition: diff_context.h:470
DenseMatrix< Number > & get_elem_jacobian()
Definition: diff_context.h:289
virtual void elem_reinit(Real)
Definition: diff_context.h:76
std::vector< dof_id_type > _dof_indices
Definition: diff_context.h:637
DiffContext(const System &)
Definition: diff_context.C:30
virtual ~DiffContext()
Definition: diff_context.C:98
std::vector< DenseVector< Number > > & get_qoi_derivatives()
Definition: diff_context.h:337
void add_localized_vector(NumericVector< Number > &localized_vector, const System &sys)
Definition: diff_context.C:119
const std::vector< dof_id_type > & get_dof_indices(unsigned int var) const
Definition: diff_context.h:380
DenseVector< Number > & get_elem_fixed_solution()
Definition: diff_context.h:221
Real get_fixed_solution_derivative() const
Definition: diff_context.h:463
std::map< const NumericVector< Number > *, std::pair< DenseVector< Number >, std::vector< std::unique_ptr< DenseSubVector< Number > > > > > _localized_vectors
Definition: diff_context.h:575
Real elem_solution_rate_derivative
Definition: diff_context.h:507
const DenseVector< Number > & get_elem_solution() const
Definition: diff_context.h:111
DenseSubVector< Number > & get_elem_residual(unsigned int var)
Definition: diff_context.h:273
const System & get_system() const
Definition: diff_context.h:105
std::vector< Number > & get_qois()
Definition: diff_context.h:325
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:92
DenseSubVector< Number > & get_elem_fixed_solution(unsigned int var)
Definition: diff_context.h:239
std::vector< std::unique_ptr< DenseSubVector< Number > > > _elem_subsolutions
Definition: diff_context.h:582
const DenseSubVector< Number > & get_elem_residual(unsigned int var) const
Definition: diff_context.h:262
const System & _system
Definition: diff_context.h:658
DenseVector< Number > & get_elem_solution_rate()
Definition: diff_context.h:152
const std::vector< dof_id_type > & get_dof_indices() const
Definition: diff_context.h:367
std::vector< std::vector< std::unique_ptr< DenseSubMatrix< Number > > > > _elem_subjacobians
Definition: diff_context.h:632
void set_time(Real time_in)
Definition: diff_context.h:427
unsigned int n_dof_indices(unsigned int var) const
Definition: diff_context.h:406
const Real system_time
Definition: diff_context.h:494
DenseSubVector< Number > & get_localized_subvector(const NumericVector< Number > &localized_vector, unsigned int var)
Definition: diff_context.C:148
Real get_system_time() const
Definition: diff_context.h:415
Real get_elem_solution_accel_derivative() const
Definition: diff_context.h:454
const DenseSubVector< Number > & get_qoi_derivatives(std::size_t qoi, unsigned int var) const
Definition: diff_context.h:344
const DenseVector< Number > & get_elem_residual() const
Definition: diff_context.h:249
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< dof_id_type > & get_dof_indices()
Definition: diff_context.h:373
std::vector< dof_id_type > & get_dof_indices(unsigned int var)
Definition: diff_context.h:390
virtual void elem_edge_reinit(Real)
Definition: diff_context.h:88
virtual void elem_side_reinit(Real)
Definition: diff_context.h:82
const DenseVector< Number > & get_elem_solution_accel() const
Definition: diff_context.h:180
Real get_elem_solution_rate_derivative() const
Definition: diff_context.h:445
DenseVector< Number > _elem_residual
Definition: diff_context.h:609
const DenseSubMatrix< Number > & get_elem_jacobian(unsigned int var1, unsigned int var2) const
Definition: diff_context.h:296
DenseVector< Number > & get_localized_vector(const NumericVector< Number > &localized_vector)
Definition: diff_context.C:134
void set_deltat_pointer(Real *dt)
Definition: diff_context.C:103
Real get_time() const
Definition: diff_context.h:421
DenseSubVector< Number > & get_elem_solution(unsigned int var)
Definition: diff_context.h:135
DenseVector< Number > _elem_solution_accel
Definition: diff_context.h:595
unsigned int n_vars() const
Definition: diff_context.h:99
const std::vector< DenseVector< Number > > & get_qoi_derivatives() const
Definition: diff_context.h:331
Real elem_solution_accel_derivative
Definition: diff_context.h:514
DenseVector< Number > & get_elem_solution()
Definition: diff_context.h:117
std::vector< std::unique_ptr< DenseSubVector< Number > > > _elem_fixed_subsolutions
Definition: diff_context.h:604
virtual void nonlocal_reinit(Real)
Definition: diff_context.h:94
std::map< const NumericVector< Number > *, std::pair< DenseVector< Number >, std::vector< std::unique_ptr< DenseSubVector< Number > > > > >::iterator localized_vectors_iterator
Definition: diff_context.h:544
DenseVector< Number > _elem_solution_rate
Definition: diff_context.h:588