///
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
/// 
/// =========================================================================
//! @examplefile combustion1.icc The combustion problem: class body for the Newton method
combustion::combustion (const geo& omega, string approx)
 : lambda(0), Xh(), m(), pm(), a1(), pa1(), event("lambda","u") {
  if (approx != "") reset (omega, approx);
}
void combustion::reset (const geo& omega, string approx) {
  Xh = space (omega, approx);
  Xh.block ("boundary");
  m = form (Xh, Xh, "mass");
  pm = problem (m);
}
field combustion::initial (std::string restart) {
  if (restart == "") return field (Xh, 0);
  idiststream in (restart);
  field xh0;
  get (in, xh0);
  derr << "# restart from lambda=" << lambda << endl;
  return xh0;
}
odiststream& combustion::put (odiststream& os, const field& uh) const {
  return os << event(lambda,uh);
}
idiststream& combustion::get (idiststream& is, field& uh) {
  is >> event(lambda,uh);
  if (!is) return is;
  if (Xh.name() == "") reset (uh.get_geo(), uh.get_approx());
  if (uh.b().dis_size() == 0) {
    // re-allocate the field with right blocked/unblocked sizes
    field tmp = field(Xh, 0);
    std::copy (uh.begin_dof(), uh.end_dof(), tmp.begin_dof());
    uh = tmp;
  }
  return is;
}
