/// <summary> /// releases all C# - references on an object, making it ready for garbage-collection. /// </summary> public static void ReleaseObject(ref int _ref, out int ierr) { ierr = 0; try { object o = Infrastructure.GetObject(_ref); if (o is IDisposable) { ((IDisposable)o).Dispose(); } Infrastructure.ForgetObject(_ref); } catch (Exception e) { ierr = Infrastructure.ErrorHandler(e); } }
public static void FromXMLEnd(out int SolverRef, out int ierr) { ierr = 0; SolverRef = -1; try { if (XMLCode == null) { throw new ApplicationException("FromXMLBegin(...) must be called before."); } FromXMLInternal(out SolverRef, XMLCode); } catch (Exception e) { ierr = Infrastructure.ErrorHandler(e); } finally { XMLCode = null; } }
unsafe public static void FromXMLSubmit(byte *line, out int ierr) { ierr = 0; try { if (XMLCode == null) { throw new ApplicationException("FromXMLBegin(...) must be called before."); } string mLine = Infrastructure.FortranToDotNET(line, LineTerm); mLine += "\n"; XMLCode += mLine; } catch (Exception e) { ierr = Infrastructure.ErrorHandler(e); } }
static void FromXMLInternal(out int ref_, string xmlString) { xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \n" + "<document>\n" + xmlString + "</document>"; //Console.WriteLine(xmlString); XmlDocument docu = new XmlDocument(); docu.LoadXml(xmlString); XmlNode node = docu.SelectSingleNode("/document/sparsesolver"); var config = ilPSP.LinSolvers.SolverConfigurationParser.parseXMLConfigurationElements(node); var solver = SolverFactory.CreateSolver <ISparseSolver>(config); ref_ = Infrastructure.RegisterObject(solver); }
unsafe public static void Solve(ref int SolverRef, ref int N, double *x, double *rhs, out int ierr) { ierr = 0; try { ISparseSolver solver = (ISparseSolver)Infrastructure.GetObject(SolverRef); // create managed buffers from unmanaged ones // (ginge auch effizienter, aber ...) double[] _x = new double[N]; double[] _rhs = new double[N]; unsafe { Marshal.Copy((IntPtr)x, _x, 0, N); Marshal.Copy((IntPtr)rhs, _rhs, 0, N); // call solver solver.Solve(_x, _rhs); Marshal.Copy(_x, 0, (IntPtr)x, N); Marshal.Copy(_rhs, 0, (IntPtr)rhs, N); } } catch (Exception e) { ierr = Infrastructure.ErrorHandler(e); } }