/// <summary> /// ctor. /// </summary> /// <param name="temporalOp"> /// Indicates, for each each equation whether it is /// <list type="bullet"> /// <item>(false) a auxiliary condition i.e. a variable where no time derivative occurs in the equation, or</item> /// <item>(true) a differential equation</item> /// </list> /// At least one equation must be time-dependent; /// Otherwise, the <see cref="BoSSS.Solution.Solvers.LinearSolver"/> should be used; /// </param> /// <param name="spatialOp"></param> /// <param name="fields"></param> /// <param name="solver"> /// </param> public ImplicitTimeStepper(ISparseSolverExt solver, bool[] temporalOp, SpatialOperator spatialOp, CoordinateMapping fields) { // check operator and arguments if (!spatialOp.IsCommited) { throw new ArgumentException("operator must be committed first.", "spatialOp"); } if (spatialOp.ContainsNonlinear) { throw new ArgumentException("spatial differential operator cannot contain nonlinear components for implicit euler.", "spatialOp"); } if (!spatialOp.ContainsLinear()) { throw new ArgumentException("spatial differential operator seems to contain no components.", "spatialOp"); } if (spatialOp.DomainVar.Count != spatialOp.CodomainVar.Count) { throw new ArgumentException("spatial differential operator must have the same number of domain and codomain variables.", "spatialOp"); } if (fields.Fields.Count != spatialOp.CodomainVar.Count) { throw new ArgumentException("the number of fields in the coordinate mapping must be equal to the number of domain/codomain variables of the spatial differential operator", "fields"); } m_Solver = solver; m_Mapping = fields; //m_AffineOffset1 = new double[fields.LocalLength]; MsrMatrix eM; ImplicitTimeStepper.ComputeMatrix(spatialOp, fields, false, out eM, out m_AffineOffset1); //Setup2(eM, temporalOp); Setup1(solver, temporalOp, eM, m_AffineOffset1, fields); }
/// <summary> /// /// </summary> public static TimeStepperType Factory <TimeStepperType>(ISparseSolverExt solver, bool[] temporalOp, MsrMatrix spatialOpMtx, IList <double> spatialOpAffine, CoordinateMapping fields) where TimeStepperType : ImplicitTimeStepper, new() { TimeStepperType timestepper = new TimeStepperType(); timestepper.Setup1(solver, temporalOp, spatialOpMtx, spatialOpAffine, fields); //timestepper.Setup2( return(timestepper); }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public CrankNicolson(ISparseSolverExt solver, bool[] temporalOp, SpatialOperator spatialOp, params DGField[] fields) : this(solver, temporalOp, spatialOp, new CoordinateMapping(fields)) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public CrankNicolson(ISparseSolverExt solver, SpatialOperator spatialOp, params DGField[] fields) : this(solver, AllTrue(fields.Length), spatialOp, fields) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public CrankNicolson(ISparseSolverExt solver, bool[] temporalOp, SpatialOperator spatialOp, CoordinateMapping fields) : base(solver, temporalOp, spatialOp, fields) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public CrankNicolson(ISparseSolverExt solver, SpatialOperator spatialOp, CoordinateMapping fields) : this(solver, AllTrue(fields.Fields.Count), spatialOp, fields) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public CrankNicolson(ISparseSolverExt solver, bool[] temporalOp, MsrMatrix spatialOpMtx, IList <double> spatialOpAffine, CoordinateMapping fields) : base(solver, temporalOp, spatialOpMtx, spatialOpAffine, fields) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public CrankNicolson(ISparseSolverExt solver, MsrMatrix spatialOpMtx, IList <double> spatialOpAffine, CoordinateMapping fields) : this(solver, AllTrue(fields.Fields.Count), spatialOpMtx, spatialOpAffine, fields) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public CrankNicolson(ISparseSolverExt solver, MsrMatrix spatialOpMtx, IList <double> spatialOpAffine, params DGField[] fields) : this(solver, AllTrue(fields.Length), spatialOpMtx, spatialOpAffine, new CoordinateMapping(fields)) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public CrankNicolson(ISparseSolverExt solver, bool[] temporalOp, MsrMatrix spatialOpMtx, IList <double> spatialOpAffine, params DGField[] fields) : this(solver, spatialOpMtx, spatialOpAffine, new CoordinateMapping(fields)) { }
/// <summary> /// Constructs an implicit timestepper from a given matrix (i.e. the /// spatial discretization is done elsewhere); /// </summary> public ImplicitTimeStepper(ISparseSolverExt solver, bool[] temporalOp, MsrMatrix spatialOpMtx, IList <double> spatialOpAffine, CoordinateMapping fields) { Setup1(solver, temporalOp, spatialOpMtx, spatialOpAffine, fields); }
/// <summary> /// common for all constructors /// </summary> protected void Setup1(ISparseSolverExt solver, bool[] temporalOp, MsrMatrix spatialOpMtx, IList <double> spatialOpAffine, CoordinateMapping fields) { // check operator and arguments if (spatialOpMtx.NoOfRows != spatialOpMtx.NoOfCols) { throw new ArgumentException("matrix must be quadratic.", "spatialOpMtx"); } if (spatialOpMtx.NoOfRows != fields.GlobalCount) { throw new ArgumentException("matrix size must be equal to the GlobalCount of fields mapping", "fields,spatialOpMtx"); } if (spatialOpMtx.RowPartitioning.LocalLength != fields.LocalLength) { throw new ArgumentException("number of locally stored matrix rows nust be equal to NUpdate of fields mapping.", "fields,spatialOpMtx"); } if (spatialOpAffine.Count < fields.LocalLength) { throw new ArgumentException("length affine offset vector must be equal or larger than NUpdate of the mapping", "spatialOpAffine"); } m_Solver = solver; m_Mapping = fields; m_AffineOffset1 = spatialOpAffine.ToArray(); //Setup2(spatialOpMtx, temporalOp); //} ///// <summary> ///// Common to all constructors; Passes the Matrix <paramref name="eM"/> ///// to the solver and initializes <see cref="m_diagVecOneSec"/>; ///// </summary> ///// <param name="eM"><see cref="eM"/></param> ///// <param name="temporalOp"><see cref="ImplicitTimeStepper"/></param> //private void _Setup2(MsrMatrix eM, bool[] temporalOp) { { // check temporal operator // ----------------------- if (m_Mapping.Fields.Count != temporalOp.Length) { throw new ArgumentException( "length of temporalOp must be equal to number of domain/codomain variables of the spatial differential operator", "temporalOp"); } m_DGCoordinates = new CoordinateVector(m_Mapping); bool timedep = false; bool fullyTimeDep = true; foreach (bool b in temporalOp) { timedep = timedep || b; fullyTimeDep = fullyTimeDep & b; } if (!timedep) { throw new ArgumentException("at least one equation must be time-dependent; one entry in temporalOp must be true;", "temporalOp"); } // Construct diagonal matrix vector // -------------------------------- m_diagVecOneSec = new double[m_Mapping.MaxTotalNoOfCoordinatesPerCell]; IList <DGField> _fields = m_Mapping.Fields; for (int g = 0; g < temporalOp.Length; g++) { if (temporalOp[g]) { DGField gamma = _fields[g]; for (int n = 0; n < gamma.Basis.MaximalLength; n++) { m_diagVecOneSec[m_Mapping.LocalUniqueCoordinateIndex(g, 0, n)] = 1.0; } } } // initialize linear solver m_Solver.DefineMatrix(spatialOpMtx); } }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public ImplicitEuler(ISparseSolverExt solver, bool[] temporalOp, SpatialOperator spatialOp, params DGField[] fields) : this(solver, temporalOp, spatialOp, new CoordinateMapping(fields)) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public ImplicitEuler(ISparseSolverExt solver, SpatialOperator spatialOp, params DGField[] fields) : this(solver, AllTrue(fields.Length), spatialOp, fields) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public ImplicitEuler(ISparseSolverExt solver, bool[] temporalOp, SpatialOperator spatialOp, CoordinateMapping fields) : base(solver, temporalOp, spatialOp, fields) { }
/// <summary> /// See <see cref="ImplicitTimeStepper"/> /// </summary> public ImplicitEuler(ISparseSolverExt solver, SpatialOperator spatialOp, CoordinateMapping fields) : this(solver, AllTrue(fields.Fields.Count), spatialOp, fields) { }