40 m_timeStepper (
nullptr),
47 m_cheatConvergence(
true),
50 m_timeStepper = ceps::getNew<TimeStepper>(pb->getStartTime(),pb->getEndTime(),pb->getTimeStep());
55 this->initializeWriter();
56 m_timeWriter = ceps::getNew<TimeWriter>(m_problem->getOutputFileBase()+
"_probes.dat",
57 m_problem->getProbePoints(),
61 if (pb->getParameters())
64 m_doError = pb->hasAnalyticSolution();
66 enableErrorComputation();
68 determineSolverType(m_type);
72 m_dtMat = m_discretization->newDofMatrix();
74 m_timeDerEqsVec = m_discretization->newDofHaloVector();
75 m_noTimeDerEqsVec = m_discretization->newDofHaloVector();
139 std::cout << std::endl;
154 return 2 +
CepsUInt(std::floor((tpb->getEndTime()-tpb->getStartTime())/
155 tpb->getSnapshotTime()));
181 if (not key.starts_with(
"__"))
190 if (immediateWriting)
226 for (
CepsUInt normt=0; normt<2; normt++)
227 for (
CepsUInt norm =0; norm <3; norm ++)
232 for (
CepsUInt norm =0; norm <3; norm ++)
246 return ceps::runtimeCast<AbstractTimedPdeProblem*>(
m_problem);
259 std::cout <<
"\r Simulation time : " << std::setw(10) << t <<
"/" << std::setw(10) << tEnd <<
" ms ("
260 << std::setw(3) << done <<
"%)" << std::flush;
273 std::stringstream ss(opt);
281 else if (
m_type ==
"SBDF")
300 CEPS_ABORT (
"Timed Pde Solver: Unknown solver type: "
301 <<
m_type <<
" .Valid types are\n"
302 <<
" - FBE (for single step Euler method)\n"
303 <<
" - SBDF <order> where order is an integer between 1 and 4\n"
305 <<
" - CN (or Crank-Nicolson)");
@ Laplace
A source term that multiplies grad phi (for FE)
@ Stimulation
Apply cardiac specific treatment before adding.
@ TimeDerivative
Compute matrix of time derivatives.
@ SpatialOperator
Compute matrix of spatial operators.
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_CHECK_IS_NAN(value, message)
Check if a value is nan or inf.
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::basic_string< CepsChar > CepsString
C++ format string.
CepsArray< _Type, 2U > CepsArray2
C++ array, 2 elements.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
float CepsReal
Need single precision floating point.
std::shared_ptr< DistributedHaloVector > DHVecPtr
Typedef for pointer on Distributed Halo CepsVector.
void addFieldValuesTo(ScalarField< _SupportType > &f, DistributedVector *vec, CepsReal t=0.)
Add values to a distributed vector. Exclusive to scalar fields. Field data may be evaluated on the fl...
void setMatrix(DistributedMatrix *mat)
The matrix to assemble.
void setScaleFactor(CepsReal scaleFactor)
Factor that multiplies all coefficients to put in linear system.
void setVector(DistributedVector *vec)
The vector to assemble.
void setAssemblingFlag(const CepsAssemblingFlag &value)
Part to assemble in an assembler, see values of CepsAssemblingFlag.
virtual void assemble(CepsReal t=0., CepsBool finalize=true)=0
The main routine to call to assemble linear system.
virtual CepsBool isChangingBetweenTimes(CepsReal t1, CepsReal t2) const
Tells if this assembler changes between the two times.
DHVecPtr newDofHaloVector() const
Get a new vector from the factory, with halo data.
void evaluateFunctionOnDofs(ceps::Function< CepsReal(CepsStandardArgs)> *func, DHVecPtr v, CepsReal t=0.) const
Fills vector v with values of function func at owned and halo dofs and time t.
DMatPtr newDofMatrix() const
Get a new matrix from the factory.
CepsVector< Unknown * > getSpatialUnknowns() const
A vector of all unknowns of pb defined on cells or points.
ScalarFunction * getAnalyticSolution() const
Pointer on analytic or refScalarFunction solution.
CepsBool hasAnalyticSolution() const
Tells if there is an analytic or reference solution.
SourceTermManager * getSourceTermManager() const
Get boundary condition manager.
CepsString getProblemName() const
Get the name of the problem.
CepsBool usesReferenceSolution() const
Tells if analytic solution and if it is loaded from files.
CepsReal getReferenceSolutionOutputPeriod() const
Output dt of reference.
const CepsVector< Unknown * > & getUnknowns() const
List of unknowns of the pb.
Base class for PDE solving.
virtual void initializeAssemblers()=0
Creates the right type of assemblers for LHS and BCs. Needs to be overriden.
VtkWriter * m_writer
Manages output.
AbstractAssembler * m_lapSrcAsb
Assembler for laplace source terms.
virtual void assembleAndSolve()=0
Main routine used during solving, perform one single step on time problem or solve directly in static...
DMatPtr m_bcMat
Matrix of boundary conditions.
CepsBool m_hasRegSrc
Flag telling if there are regular source terms.
AbstractDiscretization * m_discretization
Link to PDE discretization.
AbstractAssembler * m_bcAsb
Assembler for Robin and Neumann BCs.
PdeErrorCalculator * m_errors
Error computation.
CepsBool m_doOutput
Enables/disables outputs.
DMatPtr m_opMat
Matrix of operator.
TimeWriter * m_timeWriter
Writer for time dependant data (even for static problems...)
DVecPtr m_bcVec
Vector of boundary conditions.
AbstractAssembler * m_opAsb
Assembler for the operator matrix.
CepsBool m_hasLapSrc
Flag telling if there are Delta f source terms.
AbstractPdeProblem * m_problem
Link to PDE to solve.
CepsBool m_doError
Compute error wrt analytic solution or reference.
DMatPtr m_lapSrcMat
Matrix used for laplace source terms.
Astract Problem which does depend on time.
virtual void getInitialCondition(DHVecPtr v) const
Build vector from function pointed by m_initialCondition.
CepsReal getTimeStep() const
pde time step
virtual void allocateArrays()
Allocates the arrays with the correct number of multistep.
virtual void displayProgress() const
Tells time.
TimeStepper * m_timeStepper
Monitors time evolution.
DHVecPtr getSolution() const
Returns a copy of the distributed vector containing the current solution.
void determineSolverType(CepsString s)
Initialize the type from parameter string.
virtual void swapMultiStepPointers()
Swaps vectors of array pointers for next step (for multistep methods)
virtual CepsBool finished() const
Tells if simulation reached end time or, if enabled, all points have seen an AP.
void solve() override
Solves the all PDE (all iterations)
CepsVector< DHVecPtr > m_regSourcesNm
Sources at previous steps (if problem has source terms)
CepsString m_type
Numerical scheme descriptor.
DMatPtr m_dtMat
Matrix of time derivative of the system.
void enableErrorComputation()
Sets the comparison with analytic solution.
CepsVector< DHVecPtr > m_uNm
Solution vectors at different time steps. Several vectors are needed for multi-step methods....
CepsUInt m_nbMultiSteps
Maximum number of steps needed to compute next solution (eg CN:2)
DVecPtr m_timeDerEqsVec
Vector of 1 or 0, depending on whether the dof equation has a time derivative or not.
CepsVector< DHVecPtr > m_lapSourcesNm
Sources at previous steps (if problem has laplace source terms)
CepsUInt getExpectedNumberOfOutputs() const override
Number of files written.
virtual ~AbstractTimedPdeSolver()
Destructor.
AbstractTimedPdeSolver(AbstractTimedPdeProblem *pb)
Default constructor.
void setupWithParameters(InputParameters *params) override
Set attributes from input file. Parameters are passed as arguments in case one wants to use other par...
CepsUInt m_nbIterSnapshot
Output perdiodicity.
AbstractTimedPdeProblem * getTimedProblem() const
Returns a pointer with the appropriate type of pb.
void updateAssemblers() override
Update assemblers and recompute everything is needed.
CepsArray2< CepsArray3< CepsArray3< CepsReal > > > getErrors() const
Gets the currently computed errors. First index selects absolute(0) or relative(1) second index selec...
virtual void output(DHVecPtr solution, CepsBool immediateWriting=true)
Prints the solution.
DVecPtr m_noTimeDerEqsVec
The opposite version of m_timeDerEqsVec, such as m_timeDerEqsVec + m_noTimeDerEqsVec = vec(1)
DHVecPtr m_uNp1
Vectors of unknowns at time t^n+1.
virtual void fillSourceTermsVector(CepsReal tn)
Adds contributions from all source terms into m_regSourcesNm[0].
Profiler * getProfiler() const
Access to profiler.
CepsReal getAbsoluteErrorNow(CepsInt px) const
Get norm of difference at current time.
CepsReal getRelativeErrorNow(CepsInt px) const
Get relative norm of difference at current time.
CepsReal getAbsoluteErrorCumulative(CepsInt px, CepsInt pt) const
Get cumulated norm of difference.
CepsReal getRelativeErrorCumulative(CepsInt px, CepsInt pt) const
Get relative cumulated norm of difference.
void compute(DHVecPtr num, CepsReal time=0.)
Compute the error at current time and add to total.
void stop(CepsString lbl)
Stops the measure of a labeled chronometer.
void start(CepsString lbl, CepsString dspl="")
Creates or continue a labeled chronometer.
void logMemoryUsage(const CepsString &xtic)
Writes a line with memory usage in profiling log, xtic is used to describe what the program is curren...
void actualizeAll(CepsReal time)
Actualize all data inside.
Manager *const getManager() const
Get a map of all source terms.
CepsVector< ScalarSourceTerm * > asVector() const
Get a vector of all source terms.
Source term, essentially a ScalarField.
CepsReal getTimeStep() const
Time step.
virtual CepsReal getTime()
current simulation time
void takeOneStep()
Updates the number of steps taken (derived steppers may compute new time and time step here)
CepsBool atEnd()
Whether time stepper has reached the end time or not.
CepsUInt getNbTakenTimeSteps() const
Number of time steps performed until now.
CepsReal getEndTime() const
End time of simulation.
CepsReal getStartTime() const
startTime start time of simulation
CepsBool hasSomethingToWrite() const
Tells if some data must be written. If not, why bother ?
void write(CepsReal t, DHVecPtr data)
Writes the content of data at indices set in constructor.
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
void addScalarData(const DHVecPtr &v, const CepsVector< CepsString > &fieldNames, const CepsVector< Unknown * > &us)
Set multiple scalar fields to be output by this writer. addScalarData for several unknowns.
void write(CepsReal time=0., CepsBool writeXmlEntry=true)
Write all stored data.
constexpr CepsHash get(_Type const &i)
get a hash from a single value
CepsString toString(_Tp value)
Convert a given value to a string (input has to be compatible with std::to_string)
CepsBool isVerbose()
Check if the verbosity is enabled on the master proc (always false on slave procs).
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
CepsInt readInt(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
CepsBool isMaster()
Is calling process the master ?
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).
void destroyObject(_Type &)
Destroy[delete] any type.