Skip to content

Commit ffbe975

Browse files
Lutz Grossclaude
andcommitted
Add domain-level default solver package (issue #130)
Addresses the 'odd construct' where the solver package in SolverOptions affected the system matrix type, meaning a change in solver method could inadvertently change the matrix backend and trigger an unnecessary rebuild. New API: domain.setDefaultSolverPackage(SolverOptions.TRILINOS) # or PASO/DEFAULT domain.getDefaultSolverPackage() The domain default is applied when SolverOptions.package == SO_DEFAULT, after the hard constraints (complex/direct → Trilinos) but before the build-time fallback. An explicit package in SolverOptions still overrides the domain default for individual solves. Changed files: - escriptcore/src/AbstractContinuousDomain.{h,cpp}: new member + getter/setter - escriptcore/src/escriptcpp.cpp: Python binding - finley/src/FinleyDomain.cpp: honour domain default in getSystemMatrixTypeId - ripley/src/RipleyDomain.cpp: same - oxley/src/OxleyDomain.cpp: same - doc/user/linearPDE.tex: document new domain methods - doc/user/trilinos.tex: document domain-level package selection Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 92b4eb1 commit ffbe975

8 files changed

Lines changed: 105 additions & 4 deletions

File tree

doc/user/linearPDE.tex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,31 @@ \subsubsection*{class SolverOptions}
594594
\paragraph{SolverOptions.getPackage()}
595595
returns the solver package key.
596596

597+
\paragraph{domain.setDefaultSolverPackage(package)}
598+
\label{DOMAIN DEFAULT PACKAGE}
599+
sets the default solver package for the domain.
600+
The value of \var{package} must be one of \member{SolverOptions.DEFAULT},
601+
\member{SolverOptions.PASO} or \member{SolverOptions.TRILINOS}.
602+
Setting the package at the domain level keeps the matrix type stable regardless
603+
of which solver method is selected per solve. In particular, changing the
604+
iterative solver method (e.g.\ from \PCG to \GMRES) will never trigger an
605+
unnecessary rebuild of the system matrix.
606+
607+
If \member{SolverOptions.DEFAULT} is used (the default), the package is chosen
608+
automatically: \TRILINOS is used for direct and complex-valued problems; \PASO
609+
is used otherwise (when available).
610+
611+
Example usage:
612+
\begin{python}
613+
from esys.escript import SolverOptions
614+
from esys.finley import Rectangle
615+
domain = Rectangle(20, 20, 1)
616+
domain.setDefaultSolverPackage(SolverOptions.TRILINOS)
617+
\end{python}
618+
619+
\paragraph{domain.getDefaultSolverPackage()}
620+
returns the default solver package set for the domain, or
621+
\member{SolverOptions.DEFAULT} if none has been explicitly set.
597622

598623
\paragraph{SolverOptions.setTrilinosParameter(\optional{ name , value)}
599624
}

doc/user/trilinos.tex

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,27 @@ \section{Example Problem}
138138
\end{itemize}
139139
Tolerance and solver output can be controlled by adding to the basic listing.
140140
\begin{python}[caption=tolerance , label=tolerance ]
141-
options = pde.getSolverOptions()
142-
options.setTolerance(1e-8)
143-
options.setVerbosityOn()
141+
options = pde.getSolverOptions()
142+
options.setTolerance(1e-8)
143+
options.setVerbosityOn()
144144
\end{python}
145145

146+
\subsection{Setting the Solver Package at the Domain Level}
147+
When both \PASO and \TRILINOS are available, the default iterative solver uses
148+
\PASO. To use Trilinos for all solves on a given domain---regardless of the
149+
iterative method selected per solve---set the default solver package on the
150+
domain itself:
151+
\begin{python}
152+
from esys.escript import SolverOptions
153+
domain.setDefaultSolverPackage(SolverOptions.TRILINOS)
154+
\end{python}
155+
This fixes the solver backend for the domain so that changing the iterative
156+
method (e.g.\ from \PCG to \GMRES) never triggers an unnecessary rebuild of
157+
the system matrix. The package set in \verb|SolverOptions.setPackage()| still
158+
overrides the domain default for individual solves.
146159

160+
Use \verb|domain.getDefaultSolverPackage()| to query the current setting.
161+
See also Section~\ref{DOMAIN DEFAULT PACKAGE} in Chapter~\ref{SEC LinearPDE}.
147162

148163
\section{Solver Options Summary}
149164
Table~\ref{tab:solver_summary} provides a quick reference for the most commonly used Trilinos solver options in escript.

escriptcore/src/AbstractContinuousDomain.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,21 @@ int AbstractContinuousDomain::getSystemMatrixTypeId(const boost::python::object&
141141
return 0;
142142
}
143143

144-
int AbstractContinuousDomain::getTransportTypeId(int solver, int precondioner, int package, bool symmetry) const
144+
int AbstractContinuousDomain::getTransportTypeId(int solver, int precondioner, int package, bool symmetry) const
145145
{
146146
return 0;
147147
}
148148

149+
void AbstractContinuousDomain::setDefaultSolverPackage(int package)
150+
{
151+
m_defaultSolverPackage = package;
152+
}
153+
154+
int AbstractContinuousDomain::getDefaultSolverPackage() const
155+
{
156+
return m_defaultSolverPackage;
157+
}
158+
149159
void AbstractContinuousDomain::addPDEToSystem(
150160
AbstractSystemMatrix& mat, escript::Data& rhs,
151161
const escript::Data& A, const escript::Data& B, const escript::Data& C,

escriptcore/src/AbstractContinuousDomain.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,22 @@ class ESCRIPT_DLL_API AbstractContinuousDomain : public AbstractDomain
302302
const escript::FunctionSpace& functionspace,
303303
const int type) const;
304304

305+
/**
306+
\brief
307+
Set the default solver package for this domain.
308+
The package is used when the solver options leave the package at SO_DEFAULT.
309+
Valid values are SO_DEFAULT (auto), SO_PACKAGE_PASO, SO_PACKAGE_TRILINOS.
310+
This allows the solver backend to be fixed at the domain level rather than
311+
per-solve, avoiding unexpected operator rebuilds when the solver method changes.
312+
*/
313+
void setDefaultSolverPackage(int package);
314+
315+
/**
316+
\brief
317+
Returns the default solver package for this domain, or SO_DEFAULT if not set.
318+
*/
319+
int getDefaultSolverPackage() const;
320+
305321
/**
306322
\brief
307323
Return the number of data points summed across all MPI processes
@@ -326,6 +342,10 @@ class ESCRIPT_DLL_API AbstractContinuousDomain : public AbstractDomain
326342
\param full
327343
*/
328344
virtual void Print_Mesh_Info(const bool full=false) const;
345+
346+
private:
347+
/// Default solver package; SO_DEFAULT means use the build-time fallback.
348+
int m_defaultSolverPackage = 0; // 0 == SO_DEFAULT
329349
};
330350

331351
} // end of namespace

escriptcore/src/escriptcpp.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ args("options"),
270270
":rtype: int")
271271
.def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId,
272272
args("solver", "preconditioner", "package", "symmetry"))
273+
.def("setDefaultSolverPackage",&escript::AbstractContinuousDomain::setDefaultSolverPackage,
274+
args("package"),
275+
"Set the default solver package for this domain.\n\n"
276+
"The package is used when SolverOptions leaves the package at SO_DEFAULT. "
277+
"Valid values are ``SolverOptions.DEFAULT``, ``SolverOptions.PASO``, "
278+
"``SolverOptions.TRILINOS``. Setting the package at the domain level avoids "
279+
"unexpected operator rebuilds when the solver method changes between solves.\n\n"
280+
":param package: solver package identifier\n"
281+
":type package: `int`")
282+
.def("getDefaultSolverPackage",&escript::AbstractContinuousDomain::getDefaultSolverPackage,
283+
"Returns the default solver package set for this domain, or ``SolverOptions.DEFAULT`` "
284+
"if none has been set.\n\n"
285+
":rtype: `int`")
273286

274287
.def("addPDEToSystem",&escript::AbstractContinuousDomain::addPDEToSystem,
275288
args("mat", "rhs","A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact", "d_dirac", "y_dirac"),

finley/src/FinleyDomain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,12 @@ int FinleyDomain::getSystemMatrixTypeId(const bp::object& options) const
17451745
}
17461746
}
17471747
#endif
1748+
// honour the domain-level default before falling back to build-time defaults
1749+
if (package == escript::SO_DEFAULT) {
1750+
int domDefault = getDefaultSolverPackage();
1751+
if (domDefault != escript::SO_DEFAULT)
1752+
package = domDefault;
1753+
}
17481754
#ifdef ESYS_HAVE_PASO
17491755
if (package == escript::SO_DEFAULT)
17501756
package = escript::SO_PACKAGE_PASO;

oxley/src/OxleyDomain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,12 @@ namespace oxley {
11271127
}
11281128
}
11291129
#endif
1130+
// honour the domain-level default before falling back to build-time defaults
1131+
if (package == escript::SO_DEFAULT) {
1132+
int domDefault = getDefaultSolverPackage();
1133+
if (domDefault != escript::SO_DEFAULT)
1134+
package = domDefault;
1135+
}
11301136
#ifdef ESYS_HAVE_PASO
11311137
if (package == escript::SO_DEFAULT)
11321138
package = escript::SO_PACKAGE_PASO;

ripley/src/RipleyDomain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,12 @@ int RipleyDomain::getSystemMatrixTypeId(const bp::object& options) const
947947
}
948948
}
949949
#endif
950+
// honour the domain-level default before falling back to build-time defaults
951+
if (package == escript::SO_DEFAULT) {
952+
int domDefault = getDefaultSolverPackage();
953+
if (domDefault != escript::SO_DEFAULT)
954+
package = domDefault;
955+
}
950956
#ifdef ESYS_HAVE_PASO
951957
if (package == escript::SO_DEFAULT)
952958
package = escript::SO_PACKAGE_PASO;

0 commit comments

Comments
 (0)