Commit b358f4eb authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

parameters for Lanczos solver

Parameters for Lanczos solver now uses a rabbit hole
procedure to read the parameters, as follows.
if ind < 0 then use the hare approach.
if ind >= 0 then use the bunnie approach.

Hare approach: if prefix + postfix exists use it and return

Bunnie approach:
if prefix + ind + postfix exists then
           use it and return

if prefix + jnd + postfix exists AND jnd < ind then
           use the largest jnd found, and return
parent 65425a99
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public:

	ChebyshevSolver(MatrixType const &mat,
	                SolverParametersType& params)
	    : progress_("ChebyshevSolver",params.threadId),
	    : progress_("ChebyshevSolver"),
	      mat_(mat),
	      params_(params),
	      mode_(WITH_INFO),
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public:

	DavidsonSolver(MatrixType const &mat,
	               const SolverParametersType& params)
	    : progress_("DavidsonSolver",params.threadId),
	    : progress_("DavidsonSolver"),
	      mat_(mat),
	      steps_(params.steps),
	      eps_(params.tolerance)
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public:
	LanczosCore(const MatrixType& mat,
	            const SolverParametersType& params,
	            bool isReorthoEnabled)
	    : progress_("LanczosCore", params.threadId),
	    : progress_("LanczosCore"),
	      mat_(mat),
	      params_(params),
	      steps_(params.steps),
+71 −43
Original line number Diff line number Diff line
@@ -99,65 +99,94 @@ struct ParametersForSolver {
	static const SizeType LanczosSteps = 200; // max number of external Lanczos steps

	ParametersForSolver()
	    : steps(LanczosSteps),minSteps(4),tolerance(1e-12),stepsForEnergyConvergence(MaxLanczosSteps),
	      options(""),oneOverA(0),b(0),Eg(0),weight(0),isign(0),lotaMemory(false),
	      threadId(0)
	    : steps(LanczosSteps),
	      minSteps(4),
	      tolerance(1e-12),
	      stepsForEnergyConvergence(MaxLanczosSteps),
	      options(""),
	      oneOverA(0),
	      b(0),
	      Eg(0),
	      weight(0),
	      isign(0),
	      lotaMemory(false)
	{}

	template<typename IoInputType>
	ParametersForSolver(IoInputType& io,String prefix)
	    : steps(LanczosSteps),minSteps(4),tolerance(1e-12),stepsForEnergyConvergence(MaxLanczosSteps),
	      options(""),oneOverA(0),b(0),Eg(0),weight(0),isign(0),lotaMemory(true),
	      threadId(0)
	ParametersForSolver(IoInputType& io, String prefix, int ind = -1)
	    : steps(LanczosSteps),
	      minSteps(4),
	      tolerance(1e-12),
	      stepsForEnergyConvergence(MaxLanczosSteps),
	      options("none"),
	      oneOverA(0),
	      b(0),
	      Eg(0),
	      weight(0),
	      isign(0),
	      lotaMemory(true)
	{
		try {
			io.readline(steps,prefix + "Steps=");
		} catch (std::exception&) {}

		try {
			io.readline(minSteps,prefix + "MinSteps=");
		} catch (std::exception&) {}
		rabbitHole(steps, prefix, ind, "Steps", io);

		try {
			io.readline(tolerance,prefix + "Eps=");
		} catch (std::exception&) {}
		rabbitHole(minSteps, prefix, ind, "MinSteps", io);

		try {
			io.readline(stepsForEnergyConvergence,prefix + "StepsForEnergyConvergence=");
		} catch (std::exception&) {}
		rabbitHole(tolerance, prefix, ind, "Eps", io);

		try {
			io.readline(options,prefix + "Options=");
		} catch (std::exception&) {
			options = "none";
			io.rewind();
		rabbitHole(stepsForEnergyConvergence, prefix, ind, "StepsForEnergyConvergence", io);

		rabbitHole(options, prefix, ind, "Options", io);

		rabbitHole(oneOverA, prefix, ind, "OneOverA", io);

		rabbitHole(b, prefix, ind, "B", io);

		rabbitHole(Eg, prefix, ind, "Energy", io);

		int x = 0;
		rabbitHole(x, prefix, ind, "NoSaveLanczosVectors", io);
		lotaMemory = (x > 0) ? 0 : 1;
	}

		try {
			io.readline(oneOverA,prefix + "OneOverA=");
		} catch (std::exception&) {}
	template<typename T, typename IoInputType>
	static void rabbitHole(T& t, String prefix, int ind, String postfix, IoInputType& io)
	{
		if (ind >= 0) {
			bunnie(t, prefix, ind, postfix, io);
		} else {
			hare(t, prefix, postfix, io);
		}
	}

	template<typename T, typename IoInputType>
	static void hare(T& t, String prefix, String postfix, IoInputType& io)
	{
		// if prefix + postfix exists use it
		try {
			io.readline(b,prefix + "B=");
			io.readline(t, prefix + postfix + "=");
			return;
		} catch (std::exception&) {}
	}

	template<typename T, typename IoInputType>
	static void bunnie(T& t, String prefix, SizeType ind, String postfix, IoInputType& io)
	{
		// if prefix + ind + postfix exists --> use it and return
		try {
			io.readline(Eg,prefix + "Energy=");
			io.readline(t, prefix + ttos(ind) + postfix + "=");
			return;
		} catch (std::exception&) {}

		// if prefix + jnd + postfix exists with jnd < ind --> use the largest jnd and return
		for (SizeType i = 0; i < ind; ++i) {
			const SizeType jnd = ind - i - 1;
			try {
			int x = 0;
			io.readline(x,prefix + "SaveLanczosVectors=");
			PsimagLite::String msg("prefix + SaveLanczosVectors=");
			msg +="	should not be present in input file anymore\n";
			throw RuntimeError(msg);
				io.readline(t, prefix + ttos(jnd) + postfix + "=");
				return;
			} catch (std::exception&) {}
		}

		try {
			int x = 0;
			io.readline(x,prefix + "NoSaveLanczosVectors=");
			lotaMemory = (x > 0) ? 0 : 1;
		} catch (std::exception&) {}
		hare(t, prefix, postfix, io);
	}

	SizeType steps;
@@ -170,7 +199,6 @@ struct ParametersForSolver {
	RealType weight;
	int isign;
	bool lotaMemory;
	SizeType threadId;
}; // class ParametersForSolver
} // namespace PsimagLite