libMesh::Euler2Solver Class Reference

#include <euler2_solver.h>

Inheritance diagram for libMesh::Euler2Solver:

Public Types

typedef UnsteadySolver Parent
 
typedef DifferentiableSystem sys_type
 

Public Member Functions

 Euler2Solver (sys_type &s)
 
virtual ~Euler2Solver ()
 
virtual Real error_order () const
 
virtual bool element_residual (bool request_jacobian, DiffContext &)
 
virtual bool side_residual (bool request_jacobian, DiffContext &)
 
virtual void init ()
 
virtual void init_data ()
 
virtual void reinit ()
 
virtual void solve ()
 
virtual void advance_timestep ()
 
virtual void adjoint_advance_timestep ()
 
virtual void retrieve_timestep ()
 
Number old_nonlinear_solution (const dof_id_type global_dof_number) const
 
virtual Real du (const SystemNorm &norm) const
 
virtual bool is_steady () const
 
virtual void before_timestep ()
 
const sys_typesystem () const
 
sys_typesystem ()
 
virtual AutoPtr< DiffSolver > & diff_solver ()
 
virtual AutoPtr< LinearSolver
< Number > > & 
linear_solver ()
 
void set_solution_history (const SolutionHistory &_solution_history)
 
bool is_adjoint () const
 
void set_is_adjoint (bool _is_adjoint_value)
 

Static Public Member Functions

static std::string get_info ()
 
static void print_info (std::ostream &out=libMesh::out)
 
static unsigned int n_objects ()
 
static void enable_print_counter_info ()
 
static void disable_print_counter_info ()
 

Public Attributes

Real theta
 
AutoPtr< NumericVector< Number > > old_local_nonlinear_solution
 
bool quiet
 
unsigned int reduce_deltat_on_diffsolver_failure
 

Protected Types

typedef std::map< std::string,
std::pair< unsigned int,
unsigned int > > 
Counts
 

Protected Member Functions

void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

bool first_solve
 
bool first_adjoint_step
 
AutoPtr< DiffSolver_diff_solver
 
AutoPtr< LinearSolver< Number > > _linear_solver
 
sys_type_system
 
AutoPtr< SolutionHistorysolution_history
 

Static Protected Attributes

static Counts _counts
 
static Threads::atomic
< unsigned int > 
_n_objects
 
static Threads::spin_mutex _mutex
 
static bool _enable_print_counter = true
 

Detailed Description

This class defines a theta-method (defaulting to Backward Euler with theta = 1.0) solver to handle time integration of DifferentiableSystems. The "Euler2" solver differs from Euler in how it evaluates residuals at intermediate theta values: Euler solves m(u,u') = f(theta*u_new + (1-theta)*u_old), Euler2 solves m(u') = theta*f(u_new) + (1-theta)*f(u_old) i.e. the trapezoidal rule for theta = 0.5

This class is part of the new DifferentiableSystem framework, which is still experimental. Users of this framework should beware of bugs and future API changes.

Author
Roy H. Stogner 2006

Definition at line 50 of file euler2_solver.h.

Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information. The log is identified by the class name.

Definition at line 113 of file reference_counter.h.

The parent class

Definition at line 56 of file euler2_solver.h.

The type of system

Definition at line 66 of file time_solver.h.

Constructor & Destructor Documentation

libMesh::Euler2Solver::Euler2Solver ( sys_type s)
explicit

Constructor. Requires a reference to the system to be solved.

Definition at line 27 of file euler2_solver.C.

28  : UnsteadySolver(s), theta(1.)
29 {
30 }
libMesh::Euler2Solver::~Euler2Solver ( )
virtual

Destructor.

Definition at line 34 of file euler2_solver.C.

35 {
36 }

Member Function Documentation

void libMesh::UnsteadySolver::adjoint_advance_timestep ( )
virtualinherited

This method advances the adjoint solution to the previous timestep, after an adjoint_solve() has been performed. This will be done before every UnsteadySolver::adjoint_solve().

Reimplemented from libMesh::TimeSolver.

Definition at line 176 of file unsteady_solver.C.

References libMesh::TimeSolver::_system, libMesh::DifferentiableSystem::deltat, libMesh::UnsteadySolver::first_adjoint_step, libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), libMesh::System::get_vector(), libMesh::NumericVector< T >::localize(), libMesh::UnsteadySolver::old_local_nonlinear_solution, libMesh::TimeSolver::solution_history, and libMesh::System::time.

177 {
178  // On the first call of this function, we dont save the adjoint solution or
179  // decrement the time, we just call the retrieve function below
180  if(!first_adjoint_step)
181  {
182  // Call the store function to store the last adjoint before decrementing the time
183  solution_history->store();
184  // Decrement the system time
186  }
187  else
188  {
189  first_adjoint_step = false;
190  }
191 
192  // Retrieve the primal solution vectors at this time using the
193  // solution_history object
194  solution_history->retrieve();
195 
196  // Dont forget to localize the old_nonlinear_solution !
197  _system.get_vector("_old_nonlinear_solution").localize
200 }
void libMesh::UnsteadySolver::advance_timestep ( )
virtualinherited

This method advances the solution to the next timestep, after a solve() has been performed. Often this will be done after every UnsteadySolver::solve(), but adaptive mesh refinement and/or adaptive time step selection may require some solve() steps to be repeated.

Reimplemented from libMesh::TimeSolver.

Reimplemented in libMesh::AdaptiveTimeSolver.

Definition at line 150 of file unsteady_solver.C.

References libMesh::TimeSolver::_system, libMesh::DifferentiableSystem::deltat, libMesh::UnsteadySolver::first_solve, libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), libMesh::System::get_vector(), libMesh::NumericVector< T >::localize(), libMesh::UnsteadySolver::old_local_nonlinear_solution, libMesh::System::solution, libMesh::TimeSolver::solution_history, and libMesh::System::time.

Referenced by libMesh::UnsteadySolver::solve().

151 {
152  if (!first_solve)
153  {
154  // Store the solution, does nothing by default
155  // User has to attach appropriate solution_history object for this to
156  // actually store anything anywhere
157  solution_history->store();
158 
160  }
161 
162  NumericVector<Number> &old_nonlinear_soln =
163  _system.get_vector("_old_nonlinear_solution");
164  NumericVector<Number> &nonlinear_solution =
165  *(_system.solution);
166 
167  old_nonlinear_soln = nonlinear_solution;
168 
169  old_nonlinear_soln.localize
172 }
virtual void libMesh::TimeSolver::before_timestep ( )
inlinevirtualinherited

This method is for subclasses or users to override to do arbitrary processing between timesteps

Definition at line 152 of file time_solver.h.

152 {}
virtual AutoPtr<DiffSolver>& libMesh::TimeSolver::diff_solver ( )
inlinevirtualinherited

An implicit linear or nonlinear solver to use at each timestep.

Reimplemented in libMesh::AdaptiveTimeSolver.

Definition at line 167 of file time_solver.h.

References libMesh::TimeSolver::_diff_solver.

167 { return _diff_solver; }
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

107 {
108  _enable_print_counter = false;
109  return;
110 }
Real libMesh::UnsteadySolver::du ( const SystemNorm norm) const
virtualinherited

Computes the size of ||u^{n+1} - u^{n}|| in some norm.

Note that, while you can always call this function, its result may or may not be very meaningful. For example, if you call this function right after calling advance_timestep() then you'll get a result of zero since old_nonlinear_solution is set equal to nonlinear_solution in this function.

Implements libMesh::TimeSolver.

Definition at line 225 of file unsteady_solver.C.

References libMesh::TimeSolver::_system, libMesh::System::calculate_norm(), libMesh::System::get_vector(), and libMesh::System::solution.

226 {
227 
228  AutoPtr<NumericVector<Number> > solution_copy =
229  _system.solution->clone();
230 
231  solution_copy->add(-1., _system.get_vector("_old_nonlinear_solution"));
232 
233  solution_copy->close();
234 
235  return _system.calculate_norm(*solution_copy, norm);
236 }
bool libMesh::Euler2Solver::element_residual ( bool  request_jacobian,
DiffContext context 
)
virtual

This method uses the DifferentiableSystem's element_time_derivative() and element_constraint() to build a full residual on an element. What combination it uses will depend on theta.

Implements libMesh::TimeSolver.

Definition at line 50 of file euler2_solver.C.

References libMesh::TimeSolver::_system, libMesh::DifferentiableSystem::deltat, libMesh::DiffContext::elem_reinit(), libMesh::DiffContext::elem_solution_derivative, libMesh::DifferentiablePhysics::element_constraint(), libMesh::DifferentiablePhysics::element_time_derivative(), libMesh::DifferentiablePhysics::eulerian_residual(), libMesh::DiffContext::fixed_solution_derivative, libMesh::DiffContext::get_dof_indices(), libMesh::DiffContext::get_elem_fixed_solution(), libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::DiffContext::get_elem_solution(), libMesh::DifferentiablePhysics::mass_residual(), libMesh::UnsteadySolver::old_nonlinear_solution(), libMesh::DenseVector< T >::size(), libMesh::DenseVector< T >::swap(), libMesh::DenseMatrix< T >::swap(), theta, libMesh::System::use_fixed_solution, libMesh::DenseMatrix< T >::zero(), and libMesh::DenseVector< T >::zero().

52 {
53  unsigned int n_dofs = context.get_elem_solution().size();
54 
55  // Local nonlinear solution at old timestep
56  DenseVector<Number> old_elem_solution(n_dofs);
57  for (unsigned int i=0; i != n_dofs; ++i)
58  old_elem_solution(i) =
59  old_nonlinear_solution(context.get_dof_indices()[i]);
60 
61  // We evaluate mass_residual with the change in solution
62  // to get the mass matrix, reusing old_elem_solution to hold that
63  // delta_solution.
64  DenseVector<Number> delta_elem_solution(context.get_elem_solution());
65  delta_elem_solution -= old_elem_solution;
66 
67  // Our first evaluations are at the true elem_solution
68  context.elem_solution_derivative = 1.0;
69 
70  // If a fixed solution is requested, we'll use the elem_solution
71  // at the new timestep
73  context.get_elem_fixed_solution() = context.get_elem_solution();
74 
75  context.fixed_solution_derivative = 1.0;
76 
77  // We're going to compute just the change in elem_residual
78  // (and possibly elem_jacobian), then add back the old values
79  DenseVector<Number> total_elem_residual(context.get_elem_residual());
80  DenseMatrix<Number> old_elem_jacobian, total_elem_jacobian;
81  if (request_jacobian)
82  {
83  old_elem_jacobian = context.get_elem_jacobian();
84  total_elem_jacobian = context.get_elem_jacobian();
85  context.get_elem_jacobian().zero();
86  }
87  context.get_elem_residual().zero();
88 
89  // First, evaluate time derivative at the new timestep.
90  // The element should already be in the proper place
91  // even for a moving mesh problem.
92  bool jacobian_computed =
93  _system.element_time_derivative(request_jacobian, context);
94 
95  // For a moving mesh problem we may need the pseudoconvection term too
96  jacobian_computed =
97  _system.eulerian_residual(jacobian_computed, context) && jacobian_computed;
98 
99  // Scale the new time-dependent residual and jacobian correctly
100  context.get_elem_residual() *= (theta * _system.deltat);
101  total_elem_residual += context.get_elem_residual();
102  context.get_elem_residual().zero();
103 
104  if (jacobian_computed)
105  {
106  context.get_elem_jacobian() *= (theta * _system.deltat);
107  total_elem_jacobian += context.get_elem_jacobian();
108  context.get_elem_jacobian().zero();
109  }
110 
111  // Next, evaluate the mass residual at the new timestep,
112  // with the delta_solution.
113  // Evaluating the mass residual at both old and new timesteps will be
114  // redundant in most problems but may be necessary for time accuracy
115  // or stability in moving mesh problems or problems with user-overridden
116  // mass_residual functions
117 
118  // Move elem_->delta_, delta_->elem_
119  context.get_elem_solution().swap(delta_elem_solution);
120 
121  jacobian_computed = _system.mass_residual(jacobian_computed, context) &&
122  jacobian_computed;
123 
124  context.get_elem_residual() *= -theta;
125  total_elem_residual += context.get_elem_residual();
126  context.get_elem_residual().zero();
127 
128  if (jacobian_computed)
129  {
130  // The minus sign trick here is to avoid using a non-1
131  // elem_solution_derivative:
132  context.get_elem_jacobian() *= -theta;
133  total_elem_jacobian += context.get_elem_jacobian();
134  context.get_elem_jacobian().zero();
135  }
136 
137  // Add the time-dependent term for the old solution
138 
139  // Make sure elem_solution is set up for elem_reinit to use
140  // Move delta_->old_, old_->elem_
141  context.get_elem_solution().swap(old_elem_solution);
142 
143  // Move the mesh into place first if necessary
144  context.elem_reinit(0.);
145 
147  {
148  context.elem_solution_derivative = 0.0;
149  jacobian_computed =
150  _system.element_time_derivative(jacobian_computed, context) &&
151  jacobian_computed;
152  jacobian_computed =
153  _system.eulerian_residual(jacobian_computed, context) &&
154  jacobian_computed;
155  context.elem_solution_derivative = 1.0;
156  context.get_elem_residual() *= ((1. - theta) * _system.deltat);
157  total_elem_residual += context.get_elem_residual();
158  if (jacobian_computed)
159  {
160  context.get_elem_jacobian() *= ((1. - theta) * _system.deltat);
161  total_elem_jacobian += context.get_elem_jacobian();
162  context.get_elem_jacobian().zero();
163  }
164  }
165  else
166  {
167  // FIXME - we should detect if element_time_derivative() edits
168  // elem_jacobian and lies about it!
169  _system.element_time_derivative(false, context);
170  _system.eulerian_residual(false, context);
171  context.get_elem_residual() *= ((1. - theta) * _system.deltat);
172  total_elem_residual += context.get_elem_residual();
173  }
174 
175  context.get_elem_residual().zero();
176 
177  // Add the mass residual term for the old solution
178 
179  // Move old_->old_, delta_->elem_
180  context.get_elem_solution().swap(old_elem_solution);
181 
182  jacobian_computed = _system.mass_residual(jacobian_computed, context) &&
183  jacobian_computed;
184 
185  context.get_elem_residual() *= -(1. - theta);
186  total_elem_residual += context.get_elem_residual();
187  context.get_elem_residual().zero();
188 
189  if (jacobian_computed)
190  {
191  // The minus sign trick here is to avoid using a non-1
192  // *_solution_derivative:
193  context.get_elem_jacobian() *= -(1. - theta);
194  total_elem_jacobian += context.get_elem_jacobian();
195  context.get_elem_jacobian().zero();
196  }
197 
198  // Restore the elem_solution
199  // Move elem_->elem_, delta_->delta_
200  context.get_elem_solution().swap(delta_elem_solution);
201 
202  // Restore the elem position if necessary
203  context.elem_reinit(1.);
204 
205  // Add the constraint term
206  jacobian_computed = _system.element_constraint(jacobian_computed, context) &&
207  jacobian_computed;
208 
209  // Add back the previously accumulated residual and jacobian
210  context.get_elem_residual() += total_elem_residual;
211  if (request_jacobian)
212  {
213  if (jacobian_computed)
214  context.get_elem_jacobian() += total_elem_jacobian;
215  else
216  context.get_elem_jacobian().swap(old_elem_jacobian);
217  }
218 
219  return jacobian_computed;
220 }
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = true;
103  return;
104 }
Real libMesh::Euler2Solver::error_order ( ) const
virtual

Error convergence order: 2 for Crank-Nicolson, 1 otherwise

Implements libMesh::UnsteadySolver.

Definition at line 40 of file euler2_solver.C.

References theta.

41 {
42  if (theta == 0.5)
43  return 2.;
44  return 1.;
45 }
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

Referenced by libMesh::ReferenceCounter::print_info().

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (Counts::iterator it = _counts.begin();
59  it != _counts.end(); ++it)
60  {
61  const std::string name(it->first);
62  const unsigned int creations = it->second.first;
63  const unsigned int destructions = it->second.second;
64 
65  oss << "| " << name << " reference count information:\n"
66  << "| Creations: " << creations << '\n'
67  << "| Destructions: " << destructions << '\n';
68  }
69 
70  oss << " ---------------------------------------------------------------------------- \n";
71 
72  return oss.str();
73 
74 #else
75 
76  return "";
77 
78 #endif
79 }
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectedinherited

Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.

Definition at line 163 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

164 {
165  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
166  std::pair<unsigned int, unsigned int>& p = _counts[name];
167 
168  p.first++;
169 }
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectedinherited

Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.

Definition at line 176 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

177 {
178  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
179  std::pair<unsigned int, unsigned int>& p = _counts[name];
180 
181  p.second++;
182 }
void libMesh::UnsteadySolver::init ( )
virtualinherited

The initialization function. This method is used to initialize internal data structures before a simulation begins.

Reimplemented from libMesh::TimeSolver.

Reimplemented in libMesh::AdaptiveTimeSolver.

Definition at line 46 of file unsteady_solver.C.

References libMesh::TimeSolver::_system, libMesh::System::add_vector(), and libMesh::TimeSolver::init().

47 {
49 
50  _system.add_vector("_old_nonlinear_solution");
51 }
void libMesh::UnsteadySolver::init_data ( )
virtualinherited

The data initialization function. This method is used to initialize internal data structures after the underlying System has been initialized

Reimplemented from libMesh::TimeSolver.

Definition at line 55 of file unsteady_solver.C.

References libMesh::TimeSolver::_system, libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), libMeshEnums::GHOSTED, libMesh::System::n_dofs(), libMesh::System::n_local_dofs(), libMesh::UnsteadySolver::old_local_nonlinear_solution, and libMeshEnums::SERIAL.

56 {
57 #ifdef LIBMESH_ENABLE_GHOSTED
60  GHOSTED);
61 #else
63 #endif
64 }
bool libMesh::TimeSolver::is_adjoint ( ) const
inlineinherited

Accessor for querying whether we need to do a primal or adjoint solve

Definition at line 217 of file time_solver.h.

References libMesh::TimeSolver::_is_adjoint.

Referenced by libMesh::FEMSystem::build_context().

218  { return _is_adjoint; }
virtual bool libMesh::UnsteadySolver::is_steady ( ) const
inlinevirtualinherited

This is not a steady-state solver.

Implements libMesh::TimeSolver.

Definition at line 149 of file unsteady_solver.h.

149 { return false; }
virtual AutoPtr<LinearSolver<Number> >& libMesh::TimeSolver::linear_solver ( )
inlinevirtualinherited

An implicit linear solver to use for adjoint and sensitivity problems.

Definition at line 172 of file time_solver.h.

References libMesh::TimeSolver::_linear_solver.

172 { return _linear_solver; }
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 79 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

80  { return _n_objects; }
Number libMesh::UnsteadySolver::old_nonlinear_solution ( const dof_id_type  global_dof_number) const
inherited
Returns
the old nonlinear solution for the specified global DOF.

Definition at line 214 of file unsteady_solver.C.

References libMesh::TimeSolver::_system, libMesh::System::get_dof_map(), libMesh::DofMap::n_dofs(), and libMesh::UnsteadySolver::old_local_nonlinear_solution.

Referenced by libMesh::EulerSolver::element_residual(), element_residual(), libMesh::EulerSolver::side_residual(), and side_residual().

216 {
217  libmesh_assert_less (global_dof_number, _system.get_dof_map().n_dofs());
218  libmesh_assert_less (global_dof_number, old_local_nonlinear_solution->size());
219 
220  return (*old_local_nonlinear_solution)(global_dof_number);
221 }
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

Definition at line 88 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

89 {
91 }
void libMesh::UnsteadySolver::reinit ( )
virtualinherited

The reinitialization function. This method is used to resize internal data vectors after a mesh change.

Reimplemented from libMesh::TimeSolver.

Reimplemented in libMesh::AdaptiveTimeSolver.

Definition at line 68 of file unsteady_solver.C.

References libMesh::TimeSolver::_system, libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), libMesh::System::get_vector(), libMeshEnums::GHOSTED, libMesh::NumericVector< T >::localize(), libMesh::System::n_dofs(), libMesh::System::n_local_dofs(), libMesh::UnsteadySolver::old_local_nonlinear_solution, libMesh::TimeSolver::reinit(), and libMeshEnums::SERIAL.

69 {
71 
72 #ifdef LIBMESH_ENABLE_GHOSTED
75  GHOSTED);
76 #else
78 #endif
79 
80  // localize the old solution
81  NumericVector<Number> &old_nonlinear_soln =
82  _system.get_vector("_old_nonlinear_solution");
83 
84  old_nonlinear_soln.localize
87 }
void libMesh::UnsteadySolver::retrieve_timestep ( )
virtualinherited

This method retrieves all the stored solutions at the current system.time

Reimplemented from libMesh::TimeSolver.

Definition at line 202 of file unsteady_solver.C.

References libMesh::TimeSolver::_system, libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), libMesh::System::get_vector(), libMesh::NumericVector< T >::localize(), libMesh::UnsteadySolver::old_local_nonlinear_solution, and libMesh::TimeSolver::solution_history.

203  {
204  // Retrieve all the stored vectors at the current time
205  solution_history->retrieve();
206 
207  // Dont forget to localize the old_nonlinear_solution !
208  _system.get_vector("_old_nonlinear_solution").localize
211  }
void libMesh::TimeSolver::set_is_adjoint ( bool  _is_adjoint_value)
inlineinherited

Accessor for setting whether we need to do a primal or adjoint solve

Definition at line 224 of file time_solver.h.

References libMesh::TimeSolver::_is_adjoint.

Referenced by libMesh::DifferentiableSystem::adjoint_solve(), libMesh::FEMSystem::postprocess(), and libMesh::DifferentiableSystem::solve().

225  { _is_adjoint = _is_adjoint_value; }
void libMesh::TimeSolver::set_solution_history ( const SolutionHistory _solution_history)
inherited

A setter function users will employ if they need to do something other than save no solution history

Definition at line 91 of file time_solver.C.

References libMesh::SolutionHistory::clone(), and libMesh::TimeSolver::solution_history.

92  {
93  solution_history = _solution_history.clone();
94  }
bool libMesh::Euler2Solver::side_residual ( bool  request_jacobian,
DiffContext context 
)
virtual

This method uses the DifferentiableSystem's side_time_derivative() and side_constraint() to build a full residual on an element's side. What combination it uses will depend on theta.

Implements libMesh::TimeSolver.

Definition at line 224 of file euler2_solver.C.

References libMesh::TimeSolver::_system, libMesh::DifferentiableSystem::deltat, libMesh::DiffContext::elem_side_reinit(), libMesh::DiffContext::elem_solution_derivative, libMesh::DiffContext::fixed_solution_derivative, libMesh::DiffContext::get_dof_indices(), libMesh::DiffContext::get_elem_fixed_solution(), libMesh::DiffContext::get_elem_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::DiffContext::get_elem_solution(), libMesh::UnsteadySolver::old_nonlinear_solution(), libMesh::DifferentiablePhysics::side_constraint(), libMesh::DifferentiablePhysics::side_mass_residual(), libMesh::DifferentiablePhysics::side_time_derivative(), libMesh::DenseVector< T >::size(), libMesh::DenseVector< T >::swap(), libMesh::DenseMatrix< T >::swap(), theta, libMesh::System::use_fixed_solution, libMesh::DenseMatrix< T >::zero(), and libMesh::DenseVector< T >::zero().

226 {
227  unsigned int n_dofs = context.get_elem_solution().size();
228 
229  // Local nonlinear solution at old timestep
230  DenseVector<Number> old_elem_solution(n_dofs);
231  for (unsigned int i=0; i != n_dofs; ++i)
232  old_elem_solution(i) =
233  old_nonlinear_solution(context.get_dof_indices()[i]);
234 
235  // We evaluate mass_residual with the change in solution
236  // to get the mass matrix, reusing old_elem_solution to hold that
237  // delta_solution.
238  DenseVector<Number> delta_elem_solution(context.get_elem_solution());
239  delta_elem_solution -= old_elem_solution;
240 
241  // Our first evaluations are at the true elem_solution
242  context.elem_solution_derivative = 1.0;
243 
244  // If a fixed solution is requested, we'll use the elem_solution
245  // at the new timestep
247  context.get_elem_fixed_solution() = context.get_elem_solution();
248 
249  context.fixed_solution_derivative = 1.0;
250 
251  // We're going to compute just the change in elem_residual
252  // (and possibly elem_jacobian), then add back the old values
253  DenseVector<Number> total_elem_residual(context.get_elem_residual());
254  DenseMatrix<Number> old_elem_jacobian, total_elem_jacobian;
255  if (request_jacobian)
256  {
257  old_elem_jacobian = context.get_elem_jacobian();
258  total_elem_jacobian = context.get_elem_jacobian();
259  context.get_elem_jacobian().zero();
260  }
261  context.get_elem_residual().zero();
262 
263  // First, evaluate time derivative at the new timestep.
264  // The element should already be in the proper place
265  // even for a moving mesh problem.
266  bool jacobian_computed =
267  _system.side_time_derivative(request_jacobian, context);
268 
269  // Scale the time-dependent residual and jacobian correctly
270  context.get_elem_residual() *= (theta * _system.deltat);
271  total_elem_residual += context.get_elem_residual();
272  context.get_elem_residual().zero();
273 
274  if (jacobian_computed)
275  {
276  context.get_elem_jacobian() *= (theta * _system.deltat);
277  total_elem_jacobian += context.get_elem_jacobian();
278  context.get_elem_jacobian().zero();
279  }
280 
281  // Next, evaluate the mass residual at the new timestep,
282  // with the delta_solution.
283  // Evaluating the mass residual at both old and new timesteps will be
284  // redundant in most problems but may be necessary for time accuracy
285  // or stability in moving mesh problems or problems with user-overridden
286  // mass_residual functions
287 
288  // Move elem_->delta_, delta_->elem_
289  context.get_elem_solution().swap(delta_elem_solution);
290 
291  jacobian_computed = _system.side_mass_residual(jacobian_computed, context) &&
292  jacobian_computed;
293 
294  context.get_elem_residual() *= -theta;
295  total_elem_residual += context.get_elem_residual();
296  context.get_elem_residual().zero();
297 
298  if (jacobian_computed)
299  {
300  // The minus sign trick here is to avoid using a non-1
301  // elem_solution_derivative:
302  context.get_elem_jacobian() *= -theta;
303  total_elem_jacobian += context.get_elem_jacobian();
304  context.get_elem_jacobian().zero();
305  }
306 
307  // Add the time-dependent term for the old solution
308 
309  // Make sure elem_solution is set up for elem_reinit to use
310  // Move delta_->old_, old_->elem_
311  context.get_elem_solution().swap(old_elem_solution);
312 
313  // Move the mesh into place first if necessary
314  context.elem_side_reinit(0.);
315 
317  {
318  context.elem_solution_derivative = 0.0;
319  jacobian_computed =
320  _system.side_time_derivative(jacobian_computed, context) &&
321  jacobian_computed;
322  context.elem_solution_derivative = 1.0;
323  context.get_elem_residual() *= ((1. - theta) * _system.deltat);
324  total_elem_residual += context.get_elem_residual();
325  if (jacobian_computed)
326  {
327  context.get_elem_jacobian() *= ((1. - theta) * _system.deltat);
328  total_elem_jacobian += context.get_elem_jacobian();
329  context.get_elem_jacobian().zero();
330  }
331  }
332  else
333  {
334  // FIXME - we should detect if side_time_derivative() edits
335  // elem_jacobian and lies about it!
336  _system.side_time_derivative(false, context);
337  context.get_elem_residual() *= ((1. - theta) * _system.deltat);
338  total_elem_residual += context.get_elem_residual();
339  }
340 
341  context.get_elem_residual().zero();
342 
343  // Add the mass residual term for the old solution
344 
345  // Move old_->old_, delta_->elem_
346  context.get_elem_solution().swap(old_elem_solution);
347 
348  jacobian_computed =
349  _system.side_mass_residual(jacobian_computed, context) &&
350  jacobian_computed;
351 
352  context.get_elem_residual() *= -(1. - theta);
353  total_elem_residual += context.get_elem_residual();
354  context.get_elem_residual().zero();
355 
356  if (jacobian_computed)
357  {
358  // The minus sign trick here is to avoid using a non-1
359  // *_solution_derivative:
360  context.get_elem_jacobian() *= -(1. - theta);
361  total_elem_jacobian += context.get_elem_jacobian();
362  context.get_elem_jacobian().zero();
363  }
364 
365  // Restore the elem_solution
366  // Move elem_->elem_, delta_->delta_
367  context.get_elem_solution().swap(delta_elem_solution);
368 
369  // Restore the elem position if necessary
370  context.elem_side_reinit(1.);
371 
372  // Add the constraint term
373  jacobian_computed = _system.side_constraint(jacobian_computed, context) &&
374  jacobian_computed;
375 
376  // Add back the previously accumulated residual and jacobian
377  context.get_elem_residual() += total_elem_residual;
378  if (request_jacobian)
379  {
380  if (jacobian_computed)
381  context.get_elem_jacobian() += total_elem_jacobian;
382  else
383  context.get_elem_jacobian().swap(old_elem_jacobian);
384  }
385 
386  return jacobian_computed;
387 }
void libMesh::UnsteadySolver::solve ( )
virtualinherited

This method solves for the solution at the next timestep. Usually we will only need to solve one (non)linear system per timestep, but more complex subclasses may override this.

Reimplemented from libMesh::TimeSolver.

Reimplemented in libMesh::AdaptiveTimeSolver, and libMesh::TwostepTimeSolver.

Definition at line 91 of file unsteady_solver.C.

References libMesh::TimeSolver::_diff_solver, libMesh::TimeSolver::_system, libMesh::UnsteadySolver::advance_timestep(), libMesh::DifferentiableSystem::deltat, libMesh::DiffSolver::DIVERGED_BACKTRACKING_FAILURE, libMesh::DiffSolver::DIVERGED_MAX_NONLINEAR_ITERATIONS, libMesh::UnsteadySolver::first_solve, libMesh::out, libMesh::TimeSolver::quiet, and libMesh::TimeSolver::reduce_deltat_on_diffsolver_failure.

92 {
93  if (first_solve)
94  {
96  first_solve = false;
97  }
98 
99  unsigned int solve_result = _diff_solver->solve();
100 
101  // If we requested the UnsteadySolver to attempt reducing dt after a
102  // failed DiffSolver solve, check the results of the solve now.
104  {
105  bool backtracking_failed =
107 
108  bool max_iterations =
110 
111  if (backtracking_failed || max_iterations)
112  {
113  // Cut timestep in half
114  for (unsigned int nr=0; nr<reduce_deltat_on_diffsolver_failure; ++nr)
115  {
116  _system.deltat *= 0.5;
117  libMesh::out << "Newton backtracking failed. Trying with smaller timestep, dt="
118  << _system.deltat << std::endl;
119 
120  solve_result = _diff_solver->solve();
121 
122  // Check solve results with reduced timestep
123  bool backtracking_still_failed =
125 
126  bool backtracking_max_iterations =
128 
129  if (!backtracking_still_failed && !backtracking_max_iterations)
130  {
131  if (!quiet)
132  libMesh::out << "Reduced dt solve succeeded." << std::endl;
133  return;
134  }
135  }
136 
137  // If we made it here, we still couldn't converge the solve after
138  // reducing deltat
139  libMesh::out << "DiffSolver::solve() did not succeed after "
140  << reduce_deltat_on_diffsolver_failure
141  << " attempts." << std::endl;
142  libmesh_convergence_failure();
143 
144  } // end if (backtracking_failed || max_iterations)
145  } // end if (reduce_deltat_on_diffsolver_failure)
146 }
const sys_type& libMesh::TimeSolver::system ( ) const
inlineinherited
Returns
a constant reference to the system we are solving.

Definition at line 157 of file time_solver.h.

References libMesh::TimeSolver::_system.

Referenced by libMesh::TimeSolver::reinit(), and libMesh::TimeSolver::solve().

157 { return _system; }
sys_type& libMesh::TimeSolver::system ( )
inlineinherited
Returns
a writeable reference to the system we are solving.

Definition at line 162 of file time_solver.h.

References libMesh::TimeSolver::_system.

162 { return _system; }

Member Data Documentation

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited
AutoPtr<DiffSolver> libMesh::TimeSolver::_diff_solver
protectedinherited

An implicit linear or nonlinear solver to use at each timestep.

Definition at line 232 of file time_solver.h.

Referenced by libMesh::TimeSolver::diff_solver(), libMesh::TimeSolver::init(), libMesh::TimeSolver::reinit(), libMesh::UnsteadySolver::solve(), and libMesh::TimeSolver::solve().

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 137 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

AutoPtr<LinearSolver<Number> > libMesh::TimeSolver::_linear_solver
protectedinherited

An implicit linear solver to use for adjoint problems.

Definition at line 237 of file time_solver.h.

Referenced by libMesh::TimeSolver::init(), libMesh::TimeSolver::linear_solver(), and libMesh::TimeSolver::reinit().

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 131 of file reference_counter.h.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects. Print the reference count information when the number returns to 0.

Definition at line 126 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

bool libMesh::UnsteadySolver::first_adjoint_step
protectedinherited

A bool that will be true the first time adjoint_advance_timestep() is called, (when the primal solution is to be used to set adjoint boundary conditions) and false thereafter

Definition at line 163 of file unsteady_solver.h.

Referenced by libMesh::UnsteadySolver::adjoint_advance_timestep().

bool libMesh::UnsteadySolver::first_solve
protectedinherited

A bool that will be true the first time solve() is called, and false thereafter

Definition at line 157 of file unsteady_solver.h.

Referenced by libMesh::AdaptiveTimeSolver::advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), libMesh::TwostepTimeSolver::solve(), and libMesh::UnsteadySolver::solve().

bool libMesh::TimeSolver::quiet
inherited

Print extra debugging information if quiet == false.

Definition at line 177 of file time_solver.h.

Referenced by libMesh::TwostepTimeSolver::solve(), libMesh::UnsteadySolver::solve(), and libMesh::EigenTimeSolver::solve().

unsigned int libMesh::TimeSolver::reduce_deltat_on_diffsolver_failure
inherited

This value (which defaults to zero) is the number of times the TimeSolver is allowed to halve deltat and let the DiffSolver repeat the latest failed solve with a reduced timestep. Note that this has no effect for SteadySolvers. Note that you must set at least one of the DiffSolver flags "continue_after_max_iterations" or "continue_after_backtrack_failure" to allow the TimeSolver to retry the solve.

Definition at line 205 of file time_solver.h.

Referenced by libMesh::TwostepTimeSolver::solve(), and libMesh::UnsteadySolver::solve().

AutoPtr<SolutionHistory> libMesh::TimeSolver::solution_history
protectedinherited

An AutoPtr to a SolutionHistory object. Default is NoSolutionHistory, which the user can override by declaring a different kind of SolutionHistory in the application

Definition at line 260 of file time_solver.h.

Referenced by libMesh::UnsteadySolver::adjoint_advance_timestep(), libMesh::UnsteadySolver::advance_timestep(), libMesh::UnsteadySolver::retrieve_timestep(), and libMesh::TimeSolver::set_solution_history().

Real libMesh::Euler2Solver::theta

The value for the theta method to employ: 1.0 corresponds to backwards Euler, 0.0 corresponds to forwards Euler, 0.5 corresponds to a Crank-Nicolson-like scheme.

Definition at line 98 of file euler2_solver.h.

Referenced by element_residual(), error_order(), and side_residual().


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

Site Created By: libMesh Developers
Last modified: February 07 2014 16:58:00 UTC

Hosted By:
SourceForge.net Logo