/// <summary> /// Includes assembly of the matrix. /// </summary> /// <param name="L"></param> protected override void CreateEquationsAndSolvers(GridUpdateDataVaultBase L) { using (FuncTrace tr = new FuncTrace()) { // create operator // =============== { double D = this.GridData.SpatialDimension; double penalty_base = (T.Basis.Degree + 1) * (T.Basis.Degree + D) / D; double penalty_factor = base.Control.penalty_poisson; BoundaryCondMap<BoundaryType> PoissonBcMap = new BoundaryCondMap<BoundaryType>(this.GridData, this.Control.BoundaryValues, "T"); LapaceIp = new SpatialOperator(1, 1, QuadOrderFunc.SumOfMaxDegrees(), "T", "T"); var flux = new ipFlux(penalty_base * base.Control.penalty_poisson, ((GridData)(this.GridData)).Cells.cj, PoissonBcMap); LapaceIp.EquationComponents["T"].Add(flux); LapaceIp.Commit(); } //double condNo = LaplaceMtx.condest(BatchmodeConnector.Flavor.Octave); //Console.WriteLine("condition number: {0:0.####E-00} ",condNo); } }
///// <summary> ///// Mapping from edge tags to boundary values.<br/> ///// 1st index: edge tag;<br/> ///// 2nd index: spatial direction ///// </summary> //protected Func<double[], double, double>[,] velFunction; public ConstitutiveEqns_Convective(int _Component, BoundaryCondMap <IncompressibleBcType> _BcMap, double Weissenberg, double alpha = 1.0) { Component = _Component; this.m_BcMap = _BcMap; this.m_Weissenberg = Weissenberg; this.m_alpha = alpha; StressFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2, 2]; var stressXXfuncS = m_BcMap.bndFunction[VariableNames.StressXX]; var stressXYfuncS = m_BcMap.bndFunction[VariableNames.StressXY]; var stressYYfuncS = m_BcMap.bndFunction[VariableNames.StressYY]; for (int et = 0; et < GridCommons.FIRST_PERIODIC_BC_TAG; et++) { StressFunction[et, 0, 0] = stressXXfuncS[et]; StressFunction[et, 1, 0] = stressXYfuncS[et]; StressFunction[et, 0, 1] = stressXYfuncS[et]; StressFunction[et, 1, 1] = stressYYfuncS[et]; } //velFunction = new Func<double[], double, double>[GridCommons.FIRST_PERIODIC_BC_TAG, 2]; //for (int d = 0; d < 2; d++) // velFunction.SetColumn(m_BcMap.bndFunction[VariableNames.Velocity_d(d)], d); }
public XOptimizedLaplacianArtificialViscosityFlux(BoundaryCondMap <XDGHeatBcType> boundaryCondMap, LevelSetTracker levelSetTracker, string ArgumentVarName, double penaltySafetyFactor, double penaltyFactor, Dictionary <SpeciesId, MultidimensionalArray> inverseLengthScales) { this.GridData = levelSetTracker.GridDat; this.ArgumentName = ArgumentVarName; this.boundaryCondMap = boundaryCondMap; // Calculate penalties CellMask cutCells = levelSetTracker.Regions.GetCutCellMask(); CellMask speciesAWithOutCutCells = levelSetTracker.Regions.GetSpeciesMask("A").Except(cutCells); CellMask speciesBWithOutCutCells = levelSetTracker.Regions.GetSpeciesMask("B").Except(cutCells); double[] lengthScales_A = inverseLengthScales[levelSetTracker.GetSpeciesId("A")].To1DArray(); double[] lengthScales_B = inverseLengthScales[levelSetTracker.GetSpeciesId("B")].To1DArray(); this.penalties = new double[lengthScales_A.Length]; foreach (int cell in speciesAWithOutCutCells.ItemEnum) { this.penalties[cell] = penaltySafetyFactor * penaltyFactor * lengthScales_A[cell]; } foreach (int cell in speciesBWithOutCutCells.ItemEnum) { this.penalties[cell] = penaltySafetyFactor * penaltyFactor * lengthScales_B[cell]; } foreach (int cell in cutCells.ItemEnum) { this.penalties[cell] = double.NaN; } }
public ConstitutiveEqns_Objective_withGrad(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap, double Weissenberg, double ObjectiveParam) { this.Component = Component; this.m_BcMap = _BcMap; this.m_Weissenberg = Weissenberg; this.m_ObjectiveParam = ObjectiveParam; }
/// <summary> /// Initialize objective /// </summary> public ConstitutiveEqns_Objective(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap, double Weissenberg, double ObjectiveParam, double Penalty) { this.Component = Component; this.m_BcMap = _BcMap; this.m_Weissenberg = Weissenberg; this.m_ObjectiveParam = ObjectiveParam; this.m_StressPenalty = Penalty; }
/// <summary> /// Initialize objective /// </summary> public ConstitutiveEqns_Objective(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap, double Weissenberg, double Penalty, bool UseFDJacobian) { this.Component = Component; this.m_BcMap = _BcMap; this.m_Weissenberg = Weissenberg; this.m_StressPenalty = Penalty; this.m_useFDJacobian = UseFDJacobian; }
public mu_Diffusion(int D, double penalty_const, MultidimensionalArray cj, double __cahn, BoundaryCondMap <BoundaryType> __boundaryCondMap) : base(penalty_const, cj, "phi") // note: in the equation for 'mu', we have the Laplacian of 'phi' { m_D = D; m_cahn = __cahn * __cahn; m_boundaryCondMap = __boundaryCondMap; m_bndFunc = m_boundaryCondMap.bndFunction["phi"]; }
public phi_Diffusion(int D, double penalty_const, MultidimensionalArray cj, double __diff, double __lambda, BoundaryCondMap <BoundaryType> __boundaryCondMap) : base(penalty_const, cj, "mu") // note: in the equation for 'phi', we have the Laplacian of 'mu' { m_D = D; m_diff = __diff; m_boundaryCondMap = __boundaryCondMap; m_lambda = __lambda; }
public VelocityGradXX(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap) { this.Component = Component; this.m_BcMap = _BcMap; VelFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2]; VelFunction.SetColumn(m_BcMap.bndFunction[VariableNames.VelocityX], 0); VelFunction.SetColumn(m_BcMap.bndFunction[VariableNames.VelocityY], 1); }
public ConstitutiveEqns_Viscosity(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap, double beta, double[] Penalty1) { this.Component = Component; this.m_BcMap = _BcMap; this.m_ViscosityNonNewton = 1.0 - beta; this.pen1 = Penalty1; VelFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2]; VelFunction.SetColumn(m_BcMap.bndFunction[VariableNames.VelocityX], 0); VelFunction.SetColumn(m_BcMap.bndFunction[VariableNames.VelocityY], 1); }
public VelocityGrad_SU(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap) { this.Component = Component; this.m_BcMap = _BcMap; velFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2]; for (int d = 0; d < 2; d++) { velFunction.SetColumn(m_BcMap.bndFunction[VariableNames.Velocity_d(d)], d); } }
/// <summary> /// Ctor. /// </summary> /// <param name="SpatDimension"></param> /// <param name="EoS"></param> /// <param name="bcmap"></param> public CoupledLaxFriedrichsScalar(int SpatDimension, MaterialLaw EoS, IncompressibleBoundaryCondMap bcmap) { this.SpatDimension = SpatDimension; this.EoS = EoS; this.bcmap = bcmap; velFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, SpatDimension]; for (int d = 0; d < SpatDimension; d++) { velFunction.SetColumn(bcmap.bndFunction[VariableNames.Velocity_d(d)], d); } scalarFunction = bcmap.bndFunction[VariableNames.LevelSet]; }
public ConstitutiveEqns_Convective_FluxDiff(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap, double Weissenberg, double alpha) { this.Component = Component; this.m_BcMap = _BcMap; this.m_Weissenberg = Weissenberg; this.m_alpha = 0.5; // alpha; StressFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 3]; StressFunction.SetColumn(m_BcMap.bndFunction[VariableNames.StressXX], 0); StressFunction.SetColumn(m_BcMap.bndFunction[VariableNames.StressXY], 1); StressFunction.SetColumn(m_BcMap.bndFunction[VariableNames.StressYY], 2); velFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2]; for (int d = 0; d < 2; d++) { velFunction.SetColumn(m_BcMap.bndFunction[VariableNames.Velocity_d(d)], d); } }
public StressDivergence_Burman(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap, double Reynolds, double[] Penalty1, double Penalty2) { this.Component = Component; this.m_BcMap = _BcMap; this.InverseReynolds = -1 / (Reynolds); this.pen1 = Penalty1; this.pen2 = Penalty2; StressFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 3]; StressFunction.SetColumn(m_BcMap.bndFunction[VariableNames.StressXX], 0); StressFunction.SetColumn(m_BcMap.bndFunction[VariableNames.StressXY], 1); StressFunction.SetColumn(m_BcMap.bndFunction[VariableNames.StressYY], 2); VelFunction = new Func <double[], double, double> [GridCommons.FIRST_PERIODIC_BC_TAG, 2]; VelFunction.SetColumn(m_BcMap.bndFunction[VariableNames.VelocityX], 0); VelFunction.SetColumn(m_BcMap.bndFunction[VariableNames.VelocityY], 1); }
/// <summary> /// Includes assembly of the matrix. /// </summary> /// <param name="L"></param> protected override void CreateEquationsAndSolvers(GridUpdateDataVaultBase L) { using (FuncTrace tr = new FuncTrace()) { // create operator // =============== { double D = this.GridData.SpatialDimension; double penalty_base = (T.Basis.Degree + 1) * (T.Basis.Degree + D) / D; double penalty_factor = base.Control.penalty_poisson; BoundaryCondMap <BoundaryType> PoissonBcMap = new BoundaryCondMap <BoundaryType>(this.GridData, this.Control.BoundaryValues, "T"); LapaceIp = new SpatialOperator(1, 1, QuadOrderFunc.SumOfMaxDegrees(), "T", "T"); MultidimensionalArray LengthScales; if (this.GridData is GridData) { LengthScales = ((GridData)GridData).Cells.cj; } else if (this.GridData is AggregationGridData) { LengthScales = ((AggregationGridData)GridData).AncestorGrid.Cells.cj; } else { throw new NotImplementedException(); } var flux = new ipFlux(penalty_base * base.Control.penalty_poisson, LengthScales, PoissonBcMap); LapaceIp.EquationComponents["T"].Add(flux); LapaceIp.Commit(); } } }
/// <summary> /// Includes assembly of the matrix. /// </summary> /// <param name="L"></param> protected override void CreateEquationsAndSolvers(GridUpdateDataVaultBase L) { using (FuncTrace tr = new FuncTrace()) { // create operator // =============== SpatialOperator LapaceIp; { double D = this.GridData.SpatialDimension; double penalty_base = (T.Basis.Degree + 1) * (T.Basis.Degree + D) / D; double penalty_factor = base.Control.penalty_poisson; BoundaryCondMap <BoundaryType> PoissonBcMap = new BoundaryCondMap <BoundaryType>(this.GridData, this.Control.BoundaryValues, "T"); LapaceIp = new SpatialOperator(1, 1, QuadOrderFunc.SumOfMaxDegrees(), "T", "T"); var flux = new ipFlux(penalty_base * base.Control.penalty_poisson, this.GridData.Cells.cj, PoissonBcMap); LapaceIp.EquationComponents["T"].Add(flux); LapaceIp.Commit(); } // Create Matrices // =============== { // time measurement for matrix assembly Stopwatch stw = new Stopwatch(); stw.Start(); // console Console.WriteLine("creating sparse system for {0} DOF's ...", T.Mapping.Ntotal); // quadrature domain var volQrSch = new CellQuadratureScheme(true, CellMask.GetFullMask(this.GridData)); var edgQrSch = new EdgeQuadratureScheme(true, EdgeMask.GetFullMask(this.GridData)); #if DEBUG // in DEBUG mode, we compare 'MsrMatrix' (old, reference implementation) and 'BlockMsrMatrix' (new standard) var RefLaplaceMtx = new MsrMatrix(T.Mapping); #endif using (new BlockTrace("SipMatrixAssembly", tr)) { LaplaceMtx = new BlockMsrMatrix(T.Mapping); LaplaceAffine = new double[T.Mapping.LocalLength]; LapaceIp.ComputeMatrixEx(T.Mapping, null, T.Mapping, LaplaceMtx, LaplaceAffine, volQuadScheme: volQrSch, edgeQuadScheme: edgQrSch); } #if DEBUG LaplaceAffine.ClearEntries(); LapaceIp.ComputeMatrixEx(T.Mapping, null, T.Mapping, RefLaplaceMtx, LaplaceAffine, volQuadScheme: volQrSch, edgeQuadScheme: edgQrSch); MsrMatrix ErrMtx = RefLaplaceMtx.CloneAs(); ErrMtx.Acc(-1.0, LaplaceMtx); double err = ErrMtx.InfNorm(); double infNrm = LaplaceMtx.InfNorm(); Console.WriteLine("Matrix comparison error: " + err + ", matrix norm is: " + infNrm); Assert.Less(err, infNrm * 1e-10, "MsrMatrix2 comparison failed."); #endif stw.Stop(); Console.WriteLine("done {0} sec.", stw.Elapsed.TotalSeconds); } //double condNo = LaplaceMtx.condest(BatchmodeConnector.Flavor.Octave); //Console.WriteLine("condition number: {0:0.####E-00} ",condNo); } }
public phi_Flux(int D, BoundaryCondMap <BoundaryType> __boundaryCondMap) { m_D = D; m_boundaryCondMap = __boundaryCondMap; m_bndFunc = m_boundaryCondMap.bndFunction["phi"]; }
/// <summary> /// ctor /// </summary> /// <param name="_d"> /// spatial direction of derivative /// </param> /// <param name="bcmap"></param> public PressureGradientLin_d(int _d, IncompressibleBoundaryCondMap bcmap) { m_d = _d; m_bcmap = bcmap; pressureFunction = bcmap.bndFunction[VariableNames.Pressure]; }
public ipFlux(double penalty_const, MultidimensionalArray cj, BoundaryCondMap<BoundaryType> __boundaryCondMap) : base(penalty_const, cj, "T") // { m_boundaryCondMap = __boundaryCondMap; m_bndFunc = m_boundaryCondMap.bndFunction["T"]; }
protected override SpatialOperator GetOperatorInstance(int D) { // create operator // =============== { double _D = D; double penalty_base = (phi.Basis.Degree + 1) * (phi.Basis.Degree + _D) / _D; // Get this from where? double penalty_factor = this.Control.penalty_poisson * penalty_base; //BoundaryCondMap<BoundaryType> PoissonBcMap = new BoundaryCondMap<BoundaryType>(this.GridData, this.Control.BoundaryValues, "T"); MultidimensionalArray LengthScales; if (this.GridData is GridData) { LengthScales = ((GridData)this.GridData).Cells.cj; } else if (this.GridData is AggregationGridData) { LengthScales = ((AggregationGridData)this.GridData).AncestorGrid.Cells.cj; } else { throw new NotImplementedException(); } m_bcMap = new BoundaryCondMap <BoundaryType>(this.GridData, BoundaryTranslator(ParentControl.BoundaryValues), "phi"); #region variables //create Parameter and Variablelists string[] paramVar = VariableNames.VelocityVector(D).Cat("phi0"); string[] domainVar = new string[] { "phi" }; string[] codomainVar = new string[] { "Res_phi" }; switch (this.Control.ModTyp) { case PhasefieldControl.ModelType.modelA: break; case PhasefieldControl.ModelType.modelB: domainVar = domainVar.Cat("mu"); codomainVar = codomainVar.Cat("Res_mu"); break; case PhasefieldControl.ModelType.modelC: default: throw new NotImplementedException(); break; } switch (this.Control.CurvatureCorrectionType) { case PhasefieldControl.CurvatureCorrection.FullyCoupled: domainVar = domainVar.Cat(VariableNames.Curvature); codomainVar = codomainVar.Cat("Res_" + VariableNames.Curvature); break; case PhasefieldControl.CurvatureCorrection.DirectCoupledIterative: case PhasefieldControl.CurvatureCorrection.DirectCoupledOnce: domainVar = domainVar.Cat(VariableNames.Curvature); codomainVar = codomainVar.Cat("Res_" + VariableNames.Curvature); paramVar = paramVar.Cat("D" + VariableNames.Curvature); break; case PhasefieldControl.CurvatureCorrection.None: default: break; } #endregion CHOp = new SpatialOperator( domainVar, paramVar, codomainVar, (DomainVariableDegrees, ParameterDegrees, CodomainVariableDegrees) => 4 * DomainVariableDegrees[0] //QuadOrderFunc.NonLinear(3) ); CHOp.ParameterUpdates.Add(CompleteParameterUpdate); CHOp.ParameterFactories.Add(AllocateParameters); #region equation components // convection term CHOp.EquationComponents["Res_phi"].Add( new phi_Flux(D, m_bcMap) ); switch (this.Control.ModTyp) { case PhasefieldControl.ModelType.modelA: CHOp.EquationComponents["Res_phi"].Add( new phi_Source(this.Control.diff) ); CHOp.EquationComponents["Res_phi"].Add( new mu_Diffusion(D, penalty_factor, LengthScales, this.Control.cahn * this.Control.diff.Sqrt(), m_bcMap) ); switch (this.Control.CurvatureCorrectionType) { case PhasefieldControl.CurvatureCorrection.FullyCoupled: CHOp.EquationComponents["Res_phi"].Add( new phi_CurvatureCorrection(D, this.Control.cahn * this.Control.diff.Sqrt()) ); CHOp.EquationComponents["Res_" + VariableNames.Curvature].Add( new curvature_Source(D) ); CHOp.EquationComponents["Res_" + VariableNames.Curvature].Add( new curvature_Divergence(D, penalty_factor, 0.001 / this.Control.cahn, LengthScales) ); break; case PhasefieldControl.CurvatureCorrection.DirectCoupledIterative: case PhasefieldControl.CurvatureCorrection.DirectCoupledOnce: CHOp.EquationComponents["Res_phi"].Add( new phi_CurvatureCorrection(D, this.Control.cahn * this.Control.diff.Sqrt()) ); CHOp.EquationComponents["Res_" + VariableNames.Curvature].Add( new curvature_Direct(D) ); break; case PhasefieldControl.CurvatureCorrection.None: default: break; } break; case PhasefieldControl.ModelType.modelB: CHOp.EquationComponents["Res_phi"].Add( new phi_Diffusion(D, penalty_factor, LengthScales, this.Control.diff, this.Control.lambda, m_bcMap) ); CHOp.EquationComponents["Res_mu"].Add( new mu_Diffusion(D, penalty_factor, LengthScales, this.Control.cahn, m_bcMap) ); CHOp.EquationComponents["Res_mu"].Add( new mu_Source() ); switch (this.Control.CurvatureCorrectionType) { case PhasefieldControl.CurvatureCorrection.FullyCoupled: CHOp.EquationComponents["Res_mu"].Add( new phi_CurvatureCorrection(D, this.Control.cahn) ); CHOp.EquationComponents["Res_" + VariableNames.Curvature].Add( new curvature_Source(D) ); CHOp.EquationComponents["Res_" + VariableNames.Curvature].Add( new curvature_Divergence(D, penalty_factor, 0.001 / this.Control.cahn, LengthScales) ); break; case PhasefieldControl.CurvatureCorrection.DirectCoupledIterative: case PhasefieldControl.CurvatureCorrection.DirectCoupledOnce: CHOp.EquationComponents["Res_mu"].Add( new phi_CurvatureCorrection(D, this.Control.cahn) ); CHOp.EquationComponents["Res_" + VariableNames.Curvature].Add( new curvature_Direct(D) ); break; case PhasefieldControl.CurvatureCorrection.None: default: break; } break; case PhasefieldControl.ModelType.modelC: throw new NotImplementedException(); break; default: throw new ArgumentOutOfRangeException(); break; } #endregion // temporal derivative double[] MassScales = new double[domainVar.Length]; MassScales[0] = 1.0; CHOp.TemporalOperator = new ConstantTemporalOperator(CHOp, MassScales); CHOp.LinearizationHint = LinearizationHint.GetJacobiOperator; CHOp.Commit(); return(CHOp); } }
public ConstitutiveEqns_Objective_allparam(int Component, BoundaryCondMap <IncompressibleBcType> _BcMap, double Weissenberg) { this.Component = Component; this.m_BcMap = _BcMap; this.m_Weissenberg = Weissenberg; }
/// <summary> /// Implements the negative Laplace operator, inherits from <see cref="SIPLaplace"/> /// </summary> /// <param name="boundaryCondMap">Information about boundary conditions</param> /// <param name="penaltySafteyFactor">A user definded factor, typically set to 4.0</param> /// <param name="penaltyFactor">A factor based on the grid type (tetras, quads, etc.)</param> /// <param name="lengthScales">A cell length scale</param> /// <param name="argumentName">The variable where the operator acts on</param> public LaplacianArtificialViscosityFlux(BoundaryCondMap <XDGHeatBcType> boundaryCondMap, double penaltySafteyFactor, double penaltyFactor, MultidimensionalArray lengthScales, string argumentName) : base(penaltySafteyFactor * penaltyFactor, lengthScales, argumentName) { this.boundaryCondMap = boundaryCondMap; }