Commit 00217de3 authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

ChemicalH: SuperOperatorHelper virtual structure (again)

parent f1669fc0
......@@ -82,7 +82,6 @@ DISCLOSED WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
#include "ProgressIndicator.h"
#include "KroneckerDumper.h"
#include "Io/IoNg.h"
#include "SuperOperatorHelper.h"
namespace Dmrg {
......@@ -365,8 +364,8 @@ private:
BasisWithOperatorsType Xbasis("Xbasis");
typedef LeftRightSuper<BasisWithOperatorsType, BasisType> LeftRightSuper2Type;
Xbasis.setOneSite(X, model, time);
SuperOperatorHelper<SomeModelType> superOperatorHelper(model, pS.block(), X, dir);
leftOrRight.setToProduct(pS, Xbasis, superOperatorHelper);
leftOrRight.setToProduct(pS, Xbasis, model.superOpHelper(pS.block(), X, dir));
SparseMatrixType matrix = leftOrRight.hamiltonian().getCRS();
......
......@@ -88,6 +88,7 @@ DISCLOSED WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
#include "QnHash.h"
#include "ParallelHamiltonianConnection.h"
#include "Braket.h"
#include "SuperOpHelperBase.h"
namespace Dmrg {
......@@ -156,6 +157,7 @@ public:
typedef typename ModelLinksType::TermType ModelTermType;
typedef OpaqueOp OpForLinkType;
typedef typename ModelLinksType::AtomKindBase AtomKindBaseType;
typedef SuperOpHelperBase SuperOpHelperType;
ModelBase(const ParametersType& params,
const SuperGeometryType& superGeometry,
......@@ -163,7 +165,8 @@ public:
: modelCommon_(params, superGeometry),
targetQuantum_(io),
ioIn_(io),
atomKind_(0)
atomKind_(nullptr),
superOpHelper_(nullptr)
{
labeledOperators_.setModelName(params.model);
}
......@@ -185,6 +188,8 @@ public:
{
delete atomKind_;
atomKind_ = nullptr;
delete superOpHelper_;
superOpHelper_ = nullptr;
}
/* PSIDOC ModelInterface
......@@ -333,6 +338,19 @@ for (SizeType dof = 0; dof < numberOfDofs; ++dof) {
virtual PsimagLite::String oracle() const { return ""; }
virtual const SuperOpHelperType& superOpHelper(const VectorSizeType& bigBlock,
const VectorSizeType& smallBlock,
ProgramGlobals::DirectionEnum dir) const
{
if (superOpHelper_) {
delete superOpHelper_;
superOpHelper_ = nullptr;
}
superOpHelper_ = new SuperOpHelperType(bigBlock, smallBlock, dir);
return *superOpHelper_;
}
/**
The function \cppFunction{addHamiltonianConnection} implements
the Hamiltonian connection (e.g. tight-binding links in the case of the Hubbard Model
......@@ -666,6 +684,7 @@ private:
TargetQuantumElectronsType targetQuantum_;
InputValidatorType_& ioIn_;
AtomKindBaseType* atomKind_;
mutable SuperOpHelperType* superOpHelper_;
static LabeledOperatorsType labeledOperators_;
static ModelLinksType modelLinks_;
static VectorQnType qns_;
......
......@@ -455,6 +455,7 @@ private:
const VectorSizeType& permutationInverse,
const SomeSuperOperatorHelperType& someSuperOpHelper)
{
if (someSuperOpHelper.size() == 0) return;
typename PsimagLite::Vector<RealType>::Type fermionicSigns;
SizeType nSuperOps = someSuperOpHelper.size();
superOps_.resize(nSuperOps);
......
#ifndef SUPEROPERATORHELPER_H
#define SUPEROPERATORHELPER_H
#ifndef SuperOpHelperBase_H
#define SuperOpHelperBase_H
#include "ProgramGlobals.h"
#include "Vector.h"
namespace Dmrg {
template<typename ModelType>
class SuperOperatorHelper {
class SuperOpHelperBase {
public:
typedef PsimagLite::Vector<SizeType>::Type VectorSizeType;
typedef std::pair<bool, SizeType> PairBoolSizeType;
SuperOperatorHelper(const ModelType& model,
const VectorSizeType& bigBlock,
const VectorSizeType& smallBlock,
ProgramGlobals::DirectionEnum dir)
: model_(model), bigBlock_(bigBlock), smallBlock_(smallBlock), dir_(dir)
{
assert(smallBlock_.size() == 1);
isTriangle_ = (smallBlock_[0] & 1);
if (dir_ == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM)
isTriangle_ = !isTriangle_;
}
SuperOpHelperBase(const VectorSizeType&,
const VectorSizeType&,
ProgramGlobals::DirectionEnum dir)
: dir_(dir) {}
const ProgramGlobals::DirectionEnum& dir() const { return dir_; }
virtual ~SuperOpHelperBase() {}
// This below is for a plaquette, and will have to be
// written somewhere else
// testing devel FIXME TODO
SizeType size() const { return 1; }
virtual SizeType size() const { return 0; }
PairBoolSizeType leftOperatorIndex(SizeType) const
virtual PairBoolSizeType leftOperatorIndex(SizeType) const
{
if (isTriangle_) {
if (dir_ == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM) {
return PairBoolSizeType(true, 0);
} else {
return PairBoolSizeType(false, 0);
}
}
return PairBoolSizeType(false, 0);
}
PairBoolSizeType rightOperatorIndex(SizeType) const
virtual PairBoolSizeType rightOperatorIndex(SizeType) const
{
if (isTriangle_) {
if (dir_ == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM) {
return PairBoolSizeType(false, 0);
} else {
return PairBoolSizeType(false, 0);
}
}
return PairBoolSizeType(false, 0);
}
const ProgramGlobals::DirectionEnum& dir() const { return dir_; }
private:
const ModelType& model_;
const VectorSizeType& bigBlock_;
const VectorSizeType& smallBlock_;
ProgramGlobals::DirectionEnum dir_;
bool isTriangle_;
};
}
#endif // SUPEROPERATORHELPER_H
#endif // SuperOpHelperBase_H
......@@ -86,6 +86,7 @@ DISCLOSED WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
#include "VerySparseMatrix.h"
#include "ProgramGlobals.h"
#include "Utils.h"
#include "SuperOpHelperPlaquette.h"
namespace Dmrg {
......@@ -131,9 +132,16 @@ public:
: ModelBaseType(solverParams,
geometry,
io),
modelParameters_(io)
modelParameters_(io),
superOpHelper_(nullptr)
{}
~GaugeSpin()
{
delete superOpHelper_;
superOpHelper_ = nullptr;
}
void write(PsimagLite::String label1, PsimagLite::IoNg::Out::Serializer& io) const
{
if (!io.doesGroupExist(label1))
......@@ -225,6 +233,20 @@ protected:
plaquetteX.push4(sx, 'N', sx, 'N', sx, 'N', sx, 'N');
}
const SuperOpHelperPlaquette& superOpHelper(const VectorSizeType& bigBlock,
const VectorSizeType& smallBlock,
ProgramGlobals::DirectionEnum dir) const
{
if (superOpHelper_) {
delete superOpHelper_;
superOpHelper_ = nullptr;
}
superOpHelper_ = new SuperOpHelperPlaquette(bigBlock, smallBlock, dir);
return *superOpHelper_;
}
private:
//! Find S^+_site in the natural basis natBasis
......@@ -331,6 +353,7 @@ private:
}
ParametersGaugeSpin<RealType, QnType> modelParameters_;
mutable SuperOpHelperPlaquette* superOpHelper_;
}; // class GaugeSpin
} // namespace Dmrg
......
#ifndef SUPEROPERATORHELPER_H
#define SUPEROPERATORHELPER_H
#ifndef SuperOpHelperPlaquette_H
#define SuperOpHelperPlaquette_H
#include "ProgramGlobals.h"
#include "Vector.h"
#include "SuperOpHelperBase.h"
namespace Dmrg {
template<typename ModelType>
class SuperOperatorHelper {
class SuperOpHelperPlaquette : public SuperOpHelperBase {
public:
typedef PsimagLite::Vector<SizeType>::Type VectorSizeType;
typedef std::pair<bool, SizeType> PairBoolSizeType;
typedef SuperOpHelperBase BaseType;
typedef typename BaseType::VectorSizeType VectorSizeType;
typedef typename BaseType::PairBoolSizeType PairBoolSizeType;
SuperOperatorHelper(const ModelType& model,
const VectorSizeType& bigBlock,
const VectorSizeType& smallBlock,
ProgramGlobals::DirectionEnum dir)
: model_(model), bigBlock_(bigBlock), smallBlock_(smallBlock), dir_(dir)
SuperOpHelperPlaquette(const VectorSizeType& bigBlock,
const VectorSizeType& smallBlock,
ProgramGlobals::DirectionEnum dir)
: BaseType(bigBlock, smallBlock, dir), bigBlock_(bigBlock), smallBlock_(smallBlock)
{
assert(smallBlock_.size() == 1);
isTriangle_ = (smallBlock_[0] & 1);
if (dir_ == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM)
if (dir == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM)
isTriangle_ = !isTriangle_;
}
const ProgramGlobals::DirectionEnum& dir() const { return dir_; }
// This below is for a plaquette, and will have to be
// written somewhere else
// testing devel FIXME TODO
......@@ -35,7 +33,7 @@ public:
PairBoolSizeType leftOperatorIndex(SizeType) const
{
if (isTriangle_) {
if (dir_ == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM) {
if (BaseType::dir() == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM) {
return PairBoolSizeType(true, 0);
} else {
return PairBoolSizeType(false, 0);
......@@ -48,7 +46,7 @@ public:
PairBoolSizeType rightOperatorIndex(SizeType) const
{
if (isTriangle_) {
if (dir_ == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM) {
if (BaseType::dir() == ProgramGlobals::DirectionEnum::EXPAND_SYSTEM) {
return PairBoolSizeType(false, 0);
} else {
return PairBoolSizeType(false, 0);
......@@ -60,11 +58,9 @@ public:
private:
const ModelType& model_;
const VectorSizeType& bigBlock_;
const VectorSizeType& smallBlock_;
ProgramGlobals::DirectionEnum dir_;
bool isTriangle_;
};
}
#endif // SUPEROPERATORHELPER_H
#endif // SuperOpHelperPlaquette_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment