/* $Id: problemtr.h,v 1.1.1.1 1996/10/02 10:35:53 roitzsch Exp $ */

#ifndef PROBLEMTRANS_H
#define PROBLEMTRANS_H

#include "problem.h"

class MLMatrix;

//-------------------------------------------------------------------------


class TransientProblem : virtual public Problem
{
  public:

    virtual TransientProblem* castToTransientProblem() { return this; }
    virtual Bool solve(Real globalPrecision);

  protected:

    Bool	midPointRule, implicitEuler, lumpedMass;
    Real	theta;

    Real	tau, maxTau, time, startTime, endTime;
    Real	rhoTime, rhoSpace, fSpace;	
    int 	maxTimeSteps, maxReductions;
    Bool	constTimeStep, fixedFirstStep, staticFirstStep, dynamicScaling;
    Bool	transientMode;

    int 	plotTimeStep, postTimeStep, writeTimeStep;

    Vector<Num> uPrev, uPrevOnNewMesh;


    TransientProblem();
    virtual ~TransientProblem() { }

    virtual Bool fixedTimeSteps   (Real globalPrecision);
    virtual Bool adaptiveTimeSteps(Real globalPrecision);

    virtual void initialUNorm(Real* UNorm);
    virtual void adaptiveInitialSolution(Real* UNorm, Real TOL);
    virtual void staticInitialSolution(Real* UNorm, Real TOL);

     virtual void compTimeError(Real* timeError, Real* newUNorm, Real TOL);
    virtual void timeErrorByMidPointRule(Real* timeError, Real* newUNorm, 
					 Real TOL);
    virtual void timeErrorInfo(Real totalError, Real timeError, Real spaceError,
			       Real UNorm, Real TOL, Real tau, Real newTau, 
			       int timeStep, int reductions);

    virtual Bool timeConvergence(Real TOL, Real timeError, Real UNorm, 
				 Real* newTau, int timeStep, int reductions);

    virtual void assembleGlobalDefect(MLMatrix& AD, Vector<Num>& MD, 
				      Vector<Num>& bD);

    virtual Real compUNorm(Vector<Num>& u, Vector<Num>* MDiag=0);
    virtual Real L2MassNorm  (const Vector<Num>& x) const;

    virtual MESH* PrevMesh() const = 0;
    virtual void  shiftMesh() = 0;

    void TransientSolutionInfo(int timeStep, Real time, Real tau);

    void solutionToNewMesh(Vector<Num>& uPrevOnNewMesh, 
			   const Interface* interfaceDLY = 0) const;
    void missingTau();
    void notImplemented(const char* name) const;

    friend class DLY;
    friend class RK1;
    friend class RKA;
    friend class RK2;
};
//-------------------------------------------------------------------------


class TransientHeatConduction :  public TransientProblem
{
  public:

    TransientHeatConduction();

  protected:

    virtual DirichletBCs* newDirichletBCs();
    virtual void newMaterial();
 
    virtual void assembleGlobal(Real time);
    virtual void assemble(const Element& elem, const PATCH& t, 
			  const Jacobian& Jac, Matrix<Num>& A, 
			  Vector<Num>& b, const Matrix<Bool>* APattern, 
			  Bool errorEstimator=False);

    virtual void assembleGlobalDefect(MLMatrix& AD, Vector<Num>& MD, 
				      Vector<Num>& bD);
    virtual void assembleDefect(const Element& elem, const PATCH& t, 
				const Jacobian& Jac, Matrix<Num>& AD, 
				Vector<Num>& MD, Vector<Num>& bD);
};

#endif
