NodeSet ProjectOntoLevset(int jCell, NodeSet Nodes) { int D = Nodes.GetLength(1); int NoOfNodes = Nodes.GetLength(0); var m_Context = this.tracker.GridDat; LevelSet LevSet = (LevelSet)(this.tracker.LevelSets[this.LevelSetIndex]); MultidimensionalArray LevSetValues = MultidimensionalArray.Create(1, NoOfNodes); MultidimensionalArray LevSetGrad = MultidimensionalArray.Create(1, NoOfNodes, D); MultidimensionalArray x0_i_Local = MultidimensionalArray.Create(1, NoOfNodes, D); MultidimensionalArray x0_i_Global = MultidimensionalArray.Create(1, NoOfNodes, D); // quadrature nodes in global coordinates MultidimensionalArray x0_ip1_Local = MultidimensionalArray.Create(1, NoOfNodes, D); MultidimensionalArray x0_ip1_Global = MultidimensionalArray.Create(NoOfNodes, D); // set initial value; x0_i_Local.SetSubArray(Nodes, 0, -1, -1); int NN = NoOfNodes; for (int i = 0; i < 10; i++) { double radiusError = 0; int j = jCell; LevSet.Evaluate(j, 1, Nodes, LevSetValues, 0, 0.0); LevSet.EvaluateGradient(j, 1, Nodes, LevSetGrad); m_Context.TransformLocal2Global(new NodeSet(this.Kref, x0_i_Local.ExtractSubArrayShallow(0, -1, -1)), j, 1, x0_i_Global, 0); for (int nn = 0; nn < NN; nn++) { double sc = 0; for (int d = 0; d < D; d++) { sc += LevSetGrad[0, nn, d].Pow2(); } for (int d = 0; d < D; d++) { double xd = x0_i_Global[0, nn, d] - LevSetGrad[0, nn, d] * LevSetValues[0, nn] / sc; x0_ip1_Global[nn, d] = xd; } radiusError += Math.Abs(LevSetValues[0, nn]); } m_Context.TransformGlobal2Local(x0_ip1_Global, x0_ip1_Local, j, 1, 0); // next iter: x0_i <- x0_{i+1} x0_i_Local.Set(x0_ip1_Local); Nodes = (new NodeSet(this.Kref, x0_i_Local.ExtractSubArrayShallow(0, -1, -1))); } return(Nodes); }