oomph::ODEElement Class Reference

Element for integrating an initial value ODE. More...

#include <ode_elements.h>

+ Inheritance diagram for oomph::ODEElement:

Public Member Functions

 ODEElement ()
 Default constructor: null any pointers. More...
 
 ODEElement (TimeStepper *time_stepper_pt, SolutionFunctorBase *exact_solution_pt)
 
void build (TimeStepper *time_stepper_pt, SolutionFunctorBase *exact_solution_pt)
 Store pointers, create internal data. More...
 
virtual ~ODEElement ()
 
unsigned nvalue () const
 
virtual void fill_in_contribution_to_residuals (Vector< double > &residuals)
 Get residuals. More...
 
virtual void fill_in_contribution_to_jacobian (Vector< double > &residuals, DenseMatrix< double > &jacobian)
 
virtual void fill_in_contribution_to_mass_matrix (Vector< double > &residuals, DenseMatrix< double > &mm)
 
Vector< doubleexact_solution (const double &t) const
 Exact solution. More...
 
Vector< doublederivative_function (const double &t, const Vector< double > &u)
 Exact solution. More...
 
- Public Member Functions inherited from oomph::GeneralisedElement
 GeneralisedElement ()
 Constructor: Initialise all pointers and all values to zero. More...
 
virtual ~GeneralisedElement ()
 Virtual destructor to clean up any memory allocated by the object. More...
 
 GeneralisedElement (const GeneralisedElement &)=delete
 Broken copy constructor. More...
 
void operator= (const GeneralisedElement &)=delete
 Broken assignment operator. More...
 
Data *& internal_data_pt (const unsigned &i)
 Return a pointer to i-th internal data object. More...
 
Data *const & internal_data_pt (const unsigned &i) const
 Return a pointer to i-th internal data object (const version) More...
 
Data *& external_data_pt (const unsigned &i)
 Return a pointer to i-th external data object. More...
 
Data *const & external_data_pt (const unsigned &i) const
 Return a pointer to i-th external data object (const version) More...
 
unsigned long eqn_number (const unsigned &ieqn_local) const
 
int local_eqn_number (const unsigned long &ieqn_global) const
 
unsigned add_external_data (Data *const &data_pt, const bool &fd=true)
 
bool external_data_fd (const unsigned &i) const
 
void exclude_external_data_fd (const unsigned &i)
 
void include_external_data_fd (const unsigned &i)
 
void flush_external_data ()
 Flush all external data. More...
 
void flush_external_data (Data *const &data_pt)
 Flush the object addressed by data_pt from the external data array. More...
 
unsigned ninternal_data () const
 Return the number of internal data objects. More...
 
unsigned nexternal_data () const
 Return the number of external data objects. More...
 
unsigned ndof () const
 Return the number of equations/dofs in the element. More...
 
void dof_vector (const unsigned &t, Vector< double > &dof)
 Return the vector of dof values at time level t. More...
 
void dof_pt_vector (Vector< double * > &dof_pt)
 Return the vector of pointers to dof values. More...
 
void set_internal_data_time_stepper (const unsigned &i, TimeStepper *const &time_stepper_pt, const bool &preserve_existing_data)
 
void assign_internal_eqn_numbers (unsigned long &global_number, Vector< double * > &Dof_pt)
 
void describe_dofs (std::ostream &out, const std::string &current_string) const
 
virtual void describe_local_dofs (std::ostream &out, const std::string &current_string) const
 
void add_internal_value_pt_to_map (std::map< unsigned, double * > &map_of_value_pt)
 
virtual void assign_local_eqn_numbers (const bool &store_local_dof_pt)
 
virtual void complete_setup_of_dependencies ()
 
virtual void get_residuals (Vector< double > &residuals)
 
virtual void get_jacobian (Vector< double > &residuals, DenseMatrix< double > &jacobian)
 
virtual void get_mass_matrix (Vector< double > &residuals, DenseMatrix< double > &mass_matrix)
 
virtual void get_jacobian_and_mass_matrix (Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
 
virtual void get_dresiduals_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam)
 
virtual void get_djacobian_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam)
 
virtual void get_djacobian_and_dmass_matrix_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam, DenseMatrix< double > &dmass_matrix_dparam)
 
virtual void get_hessian_vector_products (Vector< double > const &Y, DenseMatrix< double > const &C, DenseMatrix< double > &product)
 
virtual void get_inner_products (Vector< std::pair< unsigned, unsigned >> const &history_index, Vector< double > &inner_product)
 
virtual void get_inner_product_vectors (Vector< unsigned > const &history_index, Vector< Vector< double >> &inner_product_vector)
 
virtual unsigned self_test ()
 
virtual void compute_norm (Vector< double > &norm)
 
virtual void compute_norm (double &norm)
 
virtual unsigned ndof_types () const
 
virtual void get_dof_numbers_for_unknowns (std::list< std::pair< unsigned long, unsigned >> &dof_lookup_list) const
 

Public Attributes

SolutionFunctorBaseExact_solution_pt
 
bool Use_fd_jacobian
 

Additional Inherited Members

- Static Public Attributes inherited from oomph::GeneralisedElement
static bool Suppress_warning_about_repeated_internal_data
 
static bool Suppress_warning_about_repeated_external_data = true
 
static double Default_fd_jacobian_step = 1.0e-8
 
- Protected Member Functions inherited from oomph::GeneralisedElement
unsigned add_internal_data (Data *const &data_pt, const bool &fd=true)
 
bool internal_data_fd (const unsigned &i) const
 
void exclude_internal_data_fd (const unsigned &i)
 
void include_internal_data_fd (const unsigned &i)
 
void clear_global_eqn_numbers ()
 
void add_global_eqn_numbers (std::deque< unsigned long > const &global_eqn_numbers, std::deque< double * > const &global_dof_pt)
 
virtual void assign_internal_and_external_local_eqn_numbers (const bool &store_local_dof_pt)
 
virtual void assign_all_generic_local_eqn_numbers (const bool &store_local_dof_pt)
 
virtual void assign_additional_local_eqn_numbers ()
 
int internal_local_eqn (const unsigned &i, const unsigned &j) const
 
int external_local_eqn (const unsigned &i, const unsigned &j)
 
void fill_in_jacobian_from_internal_by_fd (Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
 
void fill_in_jacobian_from_internal_by_fd (DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
 
void fill_in_jacobian_from_external_by_fd (Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
 
void fill_in_jacobian_from_external_by_fd (DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
 
virtual void update_before_internal_fd ()
 
virtual void reset_after_internal_fd ()
 
virtual void update_in_internal_fd (const unsigned &i)
 
virtual void reset_in_internal_fd (const unsigned &i)
 
virtual void update_before_external_fd ()
 
virtual void reset_after_external_fd ()
 
virtual void update_in_external_fd (const unsigned &i)
 
virtual void reset_in_external_fd (const unsigned &i)
 
virtual void fill_in_contribution_to_jacobian_and_mass_matrix (Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
 
virtual void fill_in_contribution_to_dresiduals_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam)
 
virtual void fill_in_contribution_to_djacobian_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam)
 
virtual void fill_in_contribution_to_djacobian_and_dmass_matrix_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam, DenseMatrix< double > &dmass_matrix_dparam)
 
virtual void fill_in_contribution_to_hessian_vector_products (Vector< double > const &Y, DenseMatrix< double > const &C, DenseMatrix< double > &product)
 
virtual void fill_in_contribution_to_inner_products (Vector< std::pair< unsigned, unsigned >> const &history_index, Vector< double > &inner_product)
 
virtual void fill_in_contribution_to_inner_product_vectors (Vector< unsigned > const &history_index, Vector< Vector< double >> &inner_product_vector)
 
- Static Protected Attributes inherited from oomph::GeneralisedElement
static DenseMatrix< doubleDummy_matrix
 
static std::deque< double * > Dof_pt_deque
 

Detailed Description

Element for integrating an initial value ODE.

Constructor & Destructor Documentation

◆ ODEElement() [1/2]

oomph::ODEElement::ODEElement ( )
inline

Default constructor: null any pointers.

45  {
47 
48  Use_fd_jacobian = false;
49  }
bool Use_fd_jacobian
Definition: ode_elements.h:182
SolutionFunctorBase * Exact_solution_pt
Definition: ode_elements.h:180

References Exact_solution_pt, and Use_fd_jacobian.

◆ ODEElement() [2/2]

oomph::ODEElement::ODEElement ( TimeStepper time_stepper_pt,
SolutionFunctorBase exact_solution_pt 
)
inline

Constructor: Pass time stepper and a solution function pointer, then build the element.

55  {
56  build(time_stepper_pt, exact_solution_pt);
57  }
void build(TimeStepper *time_stepper_pt, SolutionFunctorBase *exact_solution_pt)
Store pointers, create internal data.
Definition: ode_elements.h:60

References build().

◆ ~ODEElement()

virtual oomph::ODEElement::~ODEElement ( )
inlinevirtual
74 {}

Member Function Documentation

◆ build()

void oomph::ODEElement::build ( TimeStepper time_stepper_pt,
SolutionFunctorBase exact_solution_pt 
)
inline

Store pointers, create internal data.

62  {
63  Exact_solution_pt = exact_solution_pt;
64 
65  Vector<double> exact = this->exact_solution(0);
66  unsigned nvalue = exact.size();
67 
68  add_internal_data(new Data(time_stepper_pt, nvalue));
69 
70  Use_fd_jacobian = false;
71  }
unsigned add_internal_data(Data *const &data_pt, const bool &fd=true)
Definition: elements.cc:62
Vector< double > exact_solution(const double &t) const
Exact solution.
Definition: ode_elements.h:151
unsigned nvalue() const
Definition: ode_elements.h:76

References oomph::GeneralisedElement::add_internal_data(), exact_solution(), Exact_solution_pt, nvalue(), and Use_fd_jacobian.

Referenced by ODEElement().

◆ derivative_function()

Vector<double> oomph::ODEElement::derivative_function ( const double t,
const Vector< double > &  u 
)
inline

Exact solution.

167  {
168 #ifdef PARANOID
169  if (Exact_solution_pt == 0)
170  {
171  throw OomphLibError("No derivative function",
174  }
175 #endif
176  Vector<double> dummy_x;
177  return Exact_solution_pt->derivative(t, dummy_x, u);
178  }
virtual Vector< double > derivative(const double &t, const Vector< double > &x, const Vector< double > &u) const =0
Call the derivative function.
t
Definition: plotPSD.py:36
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::SolutionFunctorBase::derivative(), Exact_solution_pt, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and plotPSD::t.

Referenced by oomph::IMRODEElement::fill_in_contribution_to_residuals(), and fill_in_contribution_to_residuals().

◆ exact_solution()

Vector<double> oomph::ODEElement::exact_solution ( const double t) const
inline

Exact solution.

152  {
153 #ifdef PARANOID
154  if (Exact_solution_pt == 0)
155  {
156  throw OomphLibError("No exact solution function",
159  }
160 #endif
161  Vector<double> dummy_x;
162  return (*Exact_solution_pt)(t, dummy_x);
163  }

References Exact_solution_pt, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and plotPSD::t.

Referenced by build(), and oomph::ODEProblem::exact_solution().

◆ fill_in_contribution_to_jacobian()

virtual void oomph::ODEElement::fill_in_contribution_to_jacobian ( Vector< double > &  residuals,
DenseMatrix< double > &  jacobian 
)
inlinevirtual

Add the elemental contribution to the jacobian matrix. and the residuals vector. Note that this function will NOT initialise the residuals vector or the jacobian matrix. It must be called after the residuals vector and jacobian matrix have been initialised to zero. The default is to use finite differences to calculate the jacobian

Reimplemented from oomph::GeneralisedElement.

Reimplemented in oomph::IMRODEElement.

111  {
112  // Get residuals
114 
116  {
117  // get df/du jacobian
118  double t = internal_data_pt(0)->time_stepper_pt()->time();
119  Vector<double> dummy, u(nvalue(), 0.0);
120  internal_data_pt(0)->value(u);
121  Exact_solution_pt->jacobian(t, dummy, u, jacobian);
122 
123  // We need jacobian of residual = f - dudt so subtract diagonal
124  // (dudt)/du term.
125  const double a = internal_data_pt(0)->time_stepper_pt()->weight(1, 0);
126  const unsigned n = nvalue();
127  for (unsigned i = 0; i < n; i++)
128  {
129  jacobian(i, i) -= a;
130  }
131  }
132  else
133  {
134  // Use FD for jacobian
136  residuals, jacobian, true);
137  }
138  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
TimeStepper *& time_stepper_pt()
Return the pointer to the timestepper.
Definition: nodes.h:238
double value(const unsigned &i) const
Definition: nodes.h:293
Data *& internal_data_pt(const unsigned &i)
Return a pointer to i-th internal data object.
Definition: elements.h:622
void fill_in_jacobian_from_internal_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
Definition: elements.cc:1102
virtual void fill_in_contribution_to_residuals(Vector< double > &residuals)
Get residuals.
Definition: ode_elements.h:82
virtual void jacobian(const double &t, const Vector< double > &x, const Vector< double > &u, DenseMatrix< double > &jacobian) const
Definition: oomph_utilities.h:1142
virtual bool have_jacobian() const
Is a jacobian function implemented?
Definition: oomph_utilities.h:1153
virtual double weight(const unsigned &i, const unsigned &j) const
Access function for j-th weight for the i-th derivative.
Definition: timesteppers.h:594
double & time()
Return current value of continous time.
Definition: timesteppers.h:332
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, Exact_solution_pt, fill_in_contribution_to_residuals(), oomph::GeneralisedElement::fill_in_jacobian_from_internal_by_fd(), oomph::SolutionFunctorBase::have_jacobian(), i, oomph::GeneralisedElement::internal_data_pt(), oomph::SolutionFunctorBase::jacobian(), n, nvalue(), plotPSD::t, oomph::TimeStepper::time(), oomph::Data::time_stepper_pt(), Use_fd_jacobian, oomph::Data::value(), and oomph::TimeStepper::weight().

◆ fill_in_contribution_to_mass_matrix()

virtual void oomph::ODEElement::fill_in_contribution_to_mass_matrix ( Vector< double > &  residuals,
DenseMatrix< double > &  mass_matrix 
)
inlinevirtual

Add the elemental contribution to the mass matrix matrix. and the residuals vector. Note that this function should NOT initialise the residuals vector or the mass matrix. It must be called after the residuals vector and jacobian matrix have been initialised to zero. The default is deliberately broken

Add the elemental contribution to the mass matrix and the residuals vector. Note that this function will NOT initialise the residuals vector or the mass matrix. It must be called after the residuals vector and jacobian matrix have been initialised to zero. The default is deliberately broken.

Reimplemented from oomph::GeneralisedElement.

142  {
144  for (unsigned j = 0, nj = nvalue(); j < nj; j++)
145  {
146  mm(j, j) = 1;
147  }
148  }
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References fill_in_contribution_to_residuals(), j, and nvalue().

◆ fill_in_contribution_to_residuals()

virtual void oomph::ODEElement::fill_in_contribution_to_residuals ( Vector< double > &  residuals)
inlinevirtual

Get residuals.

Reimplemented from oomph::GeneralisedElement.

Reimplemented in oomph::IMRODEElement.

83  {
84  // Get pointer to one-and-only internal data object
85  Data* dat_pt = internal_data_pt(0);
86 
87  // Get it's values
88  Vector<double> u(nvalue(), 0.0);
89  dat_pt->value(u);
90 
91  // Get time stepper
92  TimeStepper* time_stepper_pt = dat_pt->time_stepper_pt();
93 
94  // Get continuous time
95  double t = time_stepper_pt->time();
96 
97  Vector<double> deriv = derivative_function(t, u);
98  for (unsigned j = 0, nj = deriv.size(); j < nj; j++)
99  {
100  // Get dudt approximation from time stepper
101  double dudt = time_stepper_pt->time_derivative(1, dat_pt, j);
102 
103  // Residual is difference between the exact derivative and our
104  // time stepper's derivative estimate.
105  residuals[j] = deriv[j] - dudt;
106  }
107  }
Vector< double > derivative_function(const double &t, const Vector< double > &u)
Exact solution.
Definition: ode_elements.h:166

References derivative_function(), oomph::GeneralisedElement::internal_data_pt(), j, nvalue(), plotPSD::t, oomph::TimeStepper::time(), oomph::TimeStepper::time_derivative(), oomph::Data::time_stepper_pt(), and oomph::Data::value().

Referenced by fill_in_contribution_to_jacobian(), and fill_in_contribution_to_mass_matrix().

◆ nvalue()

unsigned oomph::ODEElement::nvalue ( ) const
inline

Member Data Documentation

◆ Exact_solution_pt

◆ Use_fd_jacobian


The documentation for this class was generated from the following file: