From 88e16ac1e00880f099e0ce563de6ee069c302c52 Mon Sep 17 00:00:00 2001 From: seogi Date: Fri, 2 May 2014 11:46:40 -0700 Subject: [PATCH 1/2] Working for Mumps --- simpegEM/Utils/Solver/Mumps.py | 28 ++++++++++++++++++++++++++++ simpegEM/Utils/Solver/__init__.py | 1 + 2 files changed, 29 insertions(+) create mode 100644 simpegEM/Utils/Solver/Mumps.py create mode 100644 simpegEM/Utils/Solver/__init__.py diff --git a/simpegEM/Utils/Solver/Mumps.py b/simpegEM/Utils/Solver/Mumps.py new file mode 100644 index 00000000..5acd07ea --- /dev/null +++ b/simpegEM/Utils/Solver/Mumps.py @@ -0,0 +1,28 @@ +from mumps import DMumpsContext + +class Mumps(): + A = None + ctx = None + x = None + + def __init__(self, A, **kwagrs): + + self.ctx = DMumpsContext(sym=0, par=1) + + if self.ctx.myid ==0: + self.A = A + self.ctx.set_icntl(14, 60) + self.ctx.set_centralized_sparse(A) + + self.ctx.set_silent() + self.ctx.run(job=4) # Factorization + + def solve(self,b): + self.x = b.copy() + self.ctx.set_rhs(self.x) + self.ctx.run(job=3) # Solve + + return self.x + + def clean(self): + self.ctx.destroy() \ No newline at end of file diff --git a/simpegEM/Utils/Solver/__init__.py b/simpegEM/Utils/Solver/__init__.py new file mode 100644 index 00000000..041fdbf5 --- /dev/null +++ b/simpegEM/Utils/Solver/__init__.py @@ -0,0 +1 @@ +from Mumps import Mumps \ No newline at end of file From 5cf74864ccf81160d4b820aa91b978b07ce4913a Mon Sep 17 00:00:00 2001 From: seogi Date: Fri, 2 May 2014 11:46:57 -0700 Subject: [PATCH 2/2] Working for Mumps --- simpegEM/TDEM/BaseTDEM.py | 6 ++++++ simpegEM/Utils/__init__.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/simpegEM/TDEM/BaseTDEM.py b/simpegEM/TDEM/BaseTDEM.py index 11193cf4..48e51ecc 100644 --- a/simpegEM/TDEM/BaseTDEM.py +++ b/simpegEM/TDEM/BaseTDEM.py @@ -33,6 +33,8 @@ class BaseTDEMProblem(BaseTimeProblem, BaseEMProblem): for tInd, dt in enumerate(self.timeSteps): if dt != dtFact: dtFact = dt + if tInd!=0: + Asolve.clean() A = self.getA(tInd) # print 'Factoring... (dt = ' + str(dt) + ')' Asolve = self.Solver(A, **self.solverOpts) @@ -42,6 +44,7 @@ class BaseTDEMProblem(BaseTimeProblem, BaseEMProblem): if sol.ndim == 1: sol.shape = (sol.size,1) F[:,:,tInd+1] = CalcFields(sol, tInd) + Asolve.clean() return F def adjoint(self, m, RHS, CalcFields, F=None): @@ -51,6 +54,8 @@ class BaseTDEMProblem(BaseTimeProblem, BaseEMProblem): for tInd, dt in reversed(list(enumerate(self.timeSteps))): if dt != dtFact: dtFact = dt + if tInd != self.timeSteps.size-1: + Asolve.clean() A = self.getA(tInd) # print 'Factoring... (dt = ' + str(dt) + ')' Asolve = self.Solver(A, **self.solverOpts) @@ -60,6 +65,7 @@ class BaseTDEMProblem(BaseTimeProblem, BaseEMProblem): if sol.ndim == 1: sol.shape = (sol.size,1) F[:,:,tInd+1] = CalcFields(sol, tInd) + Asolve.clean() return F def Jvec(self, m, v, u=None): diff --git a/simpegEM/Utils/__init__.py b/simpegEM/Utils/__init__.py index 2e690cbb..21404ecc 100644 --- a/simpegEM/Utils/__init__.py +++ b/simpegEM/Utils/__init__.py @@ -1,2 +1,3 @@ import Sources -import Ana \ No newline at end of file +import Ana +import Solver \ No newline at end of file