/// <summary> /// Returns the index of species '<paramref name="_SpeciesId"/>' in the cell '<paramref name="jCell"/>'. /// </summary> /// <param name="jCell"> /// a local cell index /// </param> /// <param name="_SpeciesId"> /// species identification /// </param> public int GetSpeciesIndex(SpeciesId _SpeciesId, int jCell) { ReducedRegionCode rrc; int NoOfSpc = this.GetNoOfSpecies(jCell, out rrc); return(m_owner.GetSpeciesIndex(rrc, _SpeciesId)); }
/// <summary> /// See <see cref="IMatrix"/> /// </summary> public double this[int j, int n] { get { ReducedRegionCode rrc; int NoOfSpec = LsTrk.Regions.GetNoOfSpecies(j, out rrc); int iSpec = LsTrk.GetSpeciesIndex(rrc, m_SpecisId); if (iSpec < 0) { return(0); // directly from nirvana } int n0; n0 = iSpec * NSep; if (n < NSep) { return(owner.Coordinates[j, n + n0]); } else { return(owner.Coordinates[j, n + (NoOfSpec - 1) * NSep]); } } set { ReducedRegionCode rrc; int NoOfSpec = LsTrk.Regions.GetNoOfSpecies(j, out rrc); int iSpec = LsTrk.GetSpeciesIndex(rrc, m_SpecisId); if (iSpec < 0) { return; // directly to nirvana } int n0; n0 = iSpec * NSep; if (n < NSep) { owner.Coordinates[j, n + n0] = value; } else { owner.Coordinates[j, n + NoOfSpec * NSep] = value; } } }
void ILinearLevelSetComponent_V.LevelSetForm_V(LevSetIntParams inp, MultidimensionalArray Koeff_V) { int j0 = inp.i0; int Len = inp.Len; int N = inp.X.GetLength(1); // nodes per cell int D = inp.X.GetLength(2); // spatial dim. int NoOfVars = this.ArgumentOrdering.Count; LevelSetTracker lsTrk = m_LsTrk; // check dimension of input array Koeff_V.CheckLengths(Len, N, 2); // create temp mem: double[] node = new double[D]; double[] normal = new double[D]; int NP = (this.ParameterOrdering != null) ? this.ParameterOrdering.Count : 0; double[] ParamsPos = new double[NP]; double[] ParamsNeg = new double[NP]; CommonParamsLs cp = default(CommonParamsLs); cp.n = normal; cp.x = node; cp.ParamsNeg = ParamsNeg; cp.ParamsPos = ParamsPos; cp.time = inp.time; // temp mem. double[] uA = new double[NoOfVars]; double[] uB = new double[NoOfVars]; double[,] Grad_uA = new double[NoOfVars, D]; double[,] Grad_uB = new double[NoOfVars, D]; double vA = 0; double vB = 0; double[] Grad_vA = new double[D]; double[] Grad_vB = new double[D]; var h_min = this.m_LsTrk.GridDat.Cells.h_min; //LevelSetSignCode pos; //LevelSetSignCode neg; //GetSignCode(out neg, out pos); SpeciesId posSpc = this.PositiveSpecies; SpeciesId negSpc = this.NegativeSpecies; var Reg = lsTrk.Regions; for (int j = 0; j < Len; j++) // loop over items... { ReducedRegionCode rrc; int NoOf = Reg.GetNoOfSpecies(j + inp.i0, out rrc); Debug.Assert(NoOf == 2); //int iSpcPos = lsTrk.GetSpeciesIndex(rrc, pos); //int iSpcNeg = lsTrk.GetSpeciesIndex(rrc, neg); int iSpcPos = lsTrk.GetSpeciesIndex(rrc, posSpc); int iSpcNeg = lsTrk.GetSpeciesIndex(rrc, negSpc); cp.jCell = j + inp.i0; if (inp.PosCellLengthScale != null) { cp.PosCellLengthScale = inp.PosCellLengthScale[cp.jCell]; } else { cp.PosCellLengthScale = double.NaN; } if (inp.NegCellLengthScale != null) { cp.NegCellLengthScale = inp.NegCellLengthScale[cp.jCell]; } else { cp.NegCellLengthScale = double.NaN; } for (int n = 0; n < N; n++) // loop over nodes... { inp.Normal.CopyTo(normal, j, n, -1); inp.X.CopyTo(node, j, n, -1); for (int i = 0; i < NP; i++) { ParamsPos[i] = inp.ParamsPos[i][j, n]; ParamsNeg[i] = inp.ParamsNeg[i][j, n]; } Koeff_V[j, n, iSpcNeg] = GetSourceCoeff(ref vA, ref cp, uA, uB, Grad_uA, Grad_uB, ref vA, ref vB, Grad_vA, Grad_vB); Koeff_V[j, n, iSpcPos] = GetSourceCoeff(ref vB, ref cp, uA, uB, Grad_uA, Grad_uB, ref vA, ref vB, Grad_vA, Grad_vB); } } }
/// <summary> /// evaluation of field in cut- or near - cells; /// </summary> private void EvaluateMultiphase(int jCell, NodeSet NS, ReducedRegionCode ReducedRegionCode, int NoOfSpecies, MultidimensionalArray result, int ResultCellindexOffset, double ResultPreScale, EvaluateInternalSignature EvalFunc, ref MultidimensionalArray[] Buffer, Func <int, int[]> BufferDim, Picker p) { LevelSetTracker trk = this.Basis.Tracker; int NoOfLevSets = trk.LevelSets.Count; int M = NS.NoOfNodes; { //var resultAcc = result.ExtractSubArrayShallow(new int[] { ResultCellindexOffset + j, 0 }, new int[] { ResultCellindexOffset + j, M - 1 }); ushort RegionCode = trk.Regions.m_LevSetRegions[jCell]; bool OnlyOneSpecies = true; for (int i = 0; i < NoOfLevSets; i++) { int dst = LevelSetTracker.DecodeLevelSetDist(RegionCode, i); if (dst == 0) { // cut-cell with respect or levelset #i // +++++++++++++++++++++++++++++++++++++ OnlyOneSpecies = false; _levSetVals[i] = trk.DataHistories[i].Current.GetLevSetValues(NS, jCell, 1); } else { // near-cell with respect or levelset #i // +++++++++++++++++++++++++++++++++++++ // find the species index... _levSetVals[i] = null; _levSetSign[i] = dst; } //_levSetSign2[i] = dst; } if (OnlyOneSpecies) { // all level sets are 'NEAR' // +++++++++++++++++++++++++ LevelSetSignCode levset_bytecode = LevelSetSignCode.ComputeLevelSetBytecode(_levSetSign); int SpecInd = trk.GetSpeciesIndex(ReducedRegionCode, levset_bytecode); // evaluate species ... Evaluate_ithSpecies(jCell, NS, result, ResultCellindexOffset, ResultPreScale, SpecInd, EvalFunc); } else { // at least one cell is 'CUT' // ++++++++++++++++++++++++++ // allocate buffers/evaluate all species ... if (Buffer.Length < NoOfSpecies) { int oldL = Buffer.Length; Array.Resize(ref Buffer, NoOfSpecies); for (int i = oldL; i < NoOfSpecies; i++) { Buffer[i] = MultidimensionalArray.Create(BufferDim(M)); } } for (int i = 0; i < NoOfSpecies; i++) { if (Buffer[i].Dimension > 1 && Buffer[i].GetLength(1) != M) { Buffer[i].Allocate(BufferDim(M)); } this.Evaluate_ithSpecies(jCell, NS, Buffer[i], 0, 0.0, i, EvalFunc); } // ... and pick the right species for the Node for (int m = 0; m < M; m++) // loop over nodes { for (int i = 0; i < NoOfLevSets; i++) { if (_levSetVals[i] != null) { _levSetSign[i] = _levSetVals[i][0, m]; } } LevelSetSignCode levset_bytecode = LevelSetSignCode.ComputeLevelSetBytecode(_levSetSign); int SpecInd = trk.GetSpeciesIndex(ReducedRegionCode, levset_bytecode); p(result, ResultCellindexOffset, m, SpecInd, Buffer); } } } }