Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ option(ELEQTRONeX_TRANSPORT "Transport support" ON)
option(ELEQTRONeX_TIME_DEPENDENT "Time-dependent support" ON)
option(ELEQTRONeX_BROYDEN_PARALLEL "Broyden parallel support" ON)
option(ELEQTRONeX_HYPRE "HYPRE support" OFF)
set(ELEQTRONeX_BLOCK_SIZE 1 CACHE STRING
"NEGF block dimension (for graphene ribbons, twice the zigzag-chain count)")
if(ELEQTRONeX_BLOCK_SIZE LESS 1)
message(FATAL_ERROR "ELEQTRONeX_BLOCK_SIZE must be a positive integer")
endif()

# Dependency options
option(ELEQTRONeX_amrex_internal "Download & build AMReX" ON)
Expand Down Expand Up @@ -162,6 +167,7 @@ if(ELEQTRONeX_APP)

if(ELEQTRONeX_TRANSPORT)
target_compile_definitions(${binary_name} PRIVATE USE_TRANSPORT)
target_compile_definitions(${binary_name} PRIVATE BLOCK_SIZE=${ELEQTRONeX_BLOCK_SIZE})
endif()

if(ELEQTRONeX_BROYDEN_PARALLEL)
Expand Down Expand Up @@ -213,4 +219,4 @@ if(ELEQTRONeX_APP)
${CMAKE_BINARY_DIR}/eleqtronex
COMMENT "Creating symlink eleqtronex -> ${binary_name}"
)
endif()
endif()
2 changes: 2 additions & 0 deletions Source/Code_Definitions.H
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#define VFRAC_THREASHOLD 1e-5

#define NUM_MODES 1
#ifndef BLOCK_SIZE
#define BLOCK_SIZE 1
#endif
#define NUM_CONTACTS 2
#define NUM_ENERGY_PTS_REAL 10

Expand Down
4 changes: 4 additions & 0 deletions Source/Make.Code
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ endif

include $(AMREX_HOME)/Tools/GNUMake/Make.defs

ifneq ($(strip $(BLOCK_SIZE)),)
DEFINES += -DBLOCK_SIZE=$(BLOCK_SIZE)
endif

include $(CODE_HOME)/Source/Make.package

Code_dirs = Utils Input Solver PostProcessor Diagnostics Output
Expand Down
68 changes: 42 additions & 26 deletions Source/Solver/Transport/NEGF/Graphene.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <AMReX_Array.H>
#include <AMReX_BoxArray.H>
#include <AMReX_ParmParse.H>
#include <AMReX_REAL.H>

#include <array>
Expand All @@ -14,56 +15,71 @@ class c_Graphene : public c_NEGF_Common<ComplexType[BLOCK_SIZE][BLOCK_SIZE]>
{
using BlkType = ComplexType[BLOCK_SIZE][BLOCK_SIZE];

static amrex::Array<int, 2> type_id;
amrex::Real acc = 1.42e-10;
amrex::Real gamma = 2.7;
int num_zigzag_chains = 0;
MatrixBlock<BlkType> h_minusH0;

void Read_GrapheneParameters(amrex::ParmParse &pp);
void Compute_SurfaceGreensFunctionImpl(MatrixBlock<BlkType> &gr,
const ComplexType E,
const ComplexType U,
bool right_lead);

protected:
virtual void Read_MaterialSpecificNanostructureProperties() final {}
virtual void Set_MaterialSpecificParameters() final {}
virtual void Print_MaterialSpecificReadData() final {}
virtual void Read_MaterialSpecificNanostructureProperties() final;
virtual void Set_MaterialSpecificParameters() final;
virtual void Print_MaterialSpecificReadData() final;

virtual void Construct_Hamiltonian() final {}
virtual void Define_ContactInfo() final {}
virtual void Define_MPI_BlkType() final{};
virtual void Construct_Hamiltonian() final;
virtual void Define_ContactInfo() final;
virtual void Define_MPI_BlkType() final;

virtual int Compute_NumAtoms() final { return 0; }
virtual int Compute_AtomsPerUnitcell() final { return 0; }
virtual int Compute_NumFieldSites() final { return 0; }
virtual int Compute_NumAtomsPerFieldSite() final { return 0; }
virtual int Compute_NumAtoms() final
{
return num_unitcells * BLOCK_SIZE;
}
virtual int Compute_AtomsPerUnitcell() final { return BLOCK_SIZE; }
virtual int Compute_NumFieldSites() final { return num_unitcells; }
virtual int Compute_NumAtomsPerFieldSite() final { return BLOCK_SIZE; }
virtual int Set_PrimaryTransportDir() final { return 1; /*Y*/ }
virtual int Set_AverageFieldFlag() final { return 1; }
virtual int Compute_NumAtomsToAvgOver() final { return 1; }
virtual void Set_BlockDegeneracyVector(amrex::Vector<int> & vec) final {}
virtual int get_Hsize() final { return 0; }
virtual int Compute_NumAtomsToAvgOver() final
{
return (avg_type == s_AVG_Type::ALL) ? num_atoms_per_field_site
: vec_avg_indices.size();
}
virtual void Set_BlockDegeneracyVector(amrex::Vector<int> &vec) final;
virtual int get_Hsize() final { return num_unitcells; }
virtual int get_offDiag_repeatBlkSize() final { return 1; }

// virtual void Compute_SurfaceGreensFunction(
// MatrixBlock<BlkType> & gr, const ComplexType EmU) final
//{
// }
virtual void Compute_SurfaceGreensFunction(MatrixBlock<BlkType> &gr,
const ComplexType E,
const ComplexType U) final;
virtual void Compute_SurfaceGreensFunctionForContact(
MatrixBlock<BlkType> &gr, const ComplexType E, const ComplexType U,
const int contact) final;

public:
static int get_1D_site_id(int par_id_local_to_NS)
{
return static_cast<int>(
amrex::Math::floor((par_id_local_to_NS - 1) / type_id[0]));
return (par_id_local_to_NS - 1) / BLOCK_SIZE;
}

struct GetAtomIDAtSite
{
AMREX_GPU_HOST_DEVICE int operator()(int global_par_id) const
{
return static_cast<int>((global_par_id - 1) % type_id[0]);
return (global_par_id - 1) % BLOCK_SIZE;
}
amrex::Array<int, 2> type_id;
};

static GetAtomIDAtSite get_atom_id_at_site()
{
return GetAtomIDAtSite{type_id};
return {};
}

virtual void Generate_AtomLocations(amrex::Vector<s_Position3D> & pos) final
{
}
virtual void Generate_AtomLocations(
amrex::Vector<s_Position3D> &pos) final;
};
#endif
214 changes: 213 additions & 1 deletion Source/Solver/Transport/NEGF/Graphene.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,223 @@
#include "Graphene.H"

#include <AMReX_Particles.H>
#include <AMReX_Print.H>
#include <math.h>
#include <stdlib.h>

#include <algorithm>
#include <cmath>
#include <string>

#include "../../Utils/CodeUtils/CodeUtil.H"

amrex::Array<int, 2> c_Graphene::type_id;
void c_Graphene::Read_GrapheneParameters(amrex::ParmParse &pp)
{
queryWithParser(pp, "acc", acc);
queryWithParser(pp, "gamma", gamma);
queryWithParser(pp, "num_zigzag_chains", num_zigzag_chains);
}


void c_Graphene::Read_MaterialSpecificNanostructureProperties()
{
amrex::ParmParse pp_default("Graphene_default");
amrex::ParmParse pp_ns(name);

Read_GrapheneParameters(pp_default);
Read_GrapheneParameters(pp_ns);
}


void c_Graphene::Set_MaterialSpecificParameters()
{
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
num_zigzag_chains > 0,
"Graphene_default.num_zigzag_chains must be a positive integer.");
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
2 * num_zigzag_chains == BLOCK_SIZE,
"A graphene zigzag ribbon has 2*num_zigzag_chains atoms per transport "
"slice. Set ELEQTRONeX_BLOCK_SIZE to that value when configuring the "
"build.");
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
acc > 0. && gamma > 0.,
"Graphene bond length acc and hopping gamma must be positive.");
}


void c_Graphene::Print_MaterialSpecificReadData()
{
amrex::Print() << "##### Graphene zigzag nanoribbon parameters:\n";
amrex::Print() << "##### acc / (m): " << acc << "\n";
amrex::Print() << "##### gamma / (eV): " << gamma << "\n";
amrex::Print() << "##### num_zigzag_chains: " << num_zigzag_chains << "\n";
amrex::Print() << "##### atoms per transport slice: " << BLOCK_SIZE << "\n";
}


void c_Graphene::Set_BlockDegeneracyVector(amrex::Vector<int> &vec)
{
vec.resize(BLOCK_SIZE);
std::fill(vec.begin(), vec.end(), 1);
}


void c_Graphene::Define_MPI_BlkType()
{
MPI_Type_contiguous(BLOCK_SIZE * BLOCK_SIZE, MPI_DOUBLE_COMPLEX,
&MPI_BlkType);
MPI_Type_commit(&MPI_BlkType);
}


void c_Graphene::Construct_Hamiltonian()
{
const ComplexType zero(0., 0.);
h_minusH0 = zero;

const int N = num_zigzag_chains;
for (int n = 0; n < N; ++n)
{
const int atom_A = n;

// Within-slice A_n--B_n bond. B_n is present for n < N-1.
if (n + 1 < N)
{
const int atom_B_n = N + n + 1;
h_minusH0.block[atom_A][atom_B_n] = gamma;
h_minusH0.block[atom_B_n][atom_A] = gamma;
}

// Within-slice A_n--B_(n-1) bond.
const int atom_B_previous = N + n;
h_minusH0.block[atom_A][atom_B_previous] = gamma;
h_minusH0.block[atom_B_previous][atom_A] = gamma;
}

auto const &h_minusHa = h_minusHa_loc_data.table();
auto const &h_Hb = h_Hb_loc_data.table();
auto const &h_Hc = h_Hc_loc_data.table();
for (std::size_t i = 0; i < blkCol_size_loc; ++i)
{
h_minusHa(i) = h_minusH0;
}

// The off-diagonal blocks store -(H_hopping). A_n in this slice is
// coupled to B_(n-1) in the next slice.
h_Hb(0) = zero;
h_Hc(0) = zero;
for (int n = 0; n < N; ++n)
{
const int atom_A = n;
const int atom_B_previous = N + n;
h_Hb(0).block[atom_A][atom_B_previous] = gamma;
h_Hc(0).block[atom_B_previous][atom_A] = gamma;
}
}


void c_Graphene::Define_ContactInfo()
{
global_contact_index[0] = 0;
global_contact_index[1] = Hsize_glo - 1;
contact_transmission_index[0] = Hsize_glo - 1;
contact_transmission_index[1] = 0;

auto const &h_tau = h_tau_glo_data.table();
auto const &h_Hb = h_Hb_loc_data.table();
auto const &h_Hc = h_Hc_loc_data.table();
h_tau(0) = h_Hc(0);
h_tau(1) = h_Hb(0);
}


void c_Graphene::Compute_SurfaceGreensFunctionImpl(
MatrixBlock<BlkType> &gr, const ComplexType E, const ComplexType U,
const bool right_lead)
{
MatrixBlock<BlkType> epsilon = h_minusH0;
epsilon.SetDiag(E - U);
MatrixBlock<BlkType> epsilon_surface = epsilon;

MatrixBlock<BlkType> alpha = h_Hb_loc_data.table()(0);
MatrixBlock<BlkType> beta = h_Hc_loc_data.table()(0);
if (!right_lead) std::swap(alpha, beta);

const amrex::Real tolerance = 1.e-12 * std::max(1., gamma);
for (int iter = 0; iter < 100; ++iter)
{
const MatrixBlock<BlkType> g = epsilon.Inverse();
const MatrixBlock<BlkType> alpha_g_beta = alpha * g * beta;
const MatrixBlock<BlkType> beta_g_alpha = beta * g * alpha;

epsilon_surface = epsilon_surface - alpha_g_beta;
epsilon = epsilon - alpha_g_beta - beta_g_alpha;

MatrixBlock<BlkType> alpha_next = -1. * alpha * g * alpha;
MatrixBlock<BlkType> beta_next = -1. * beta * g * beta;
const amrex::Real error =
std::sqrt(amrex::norm(alpha_next.FrobeniusNorm())) +
std::sqrt(amrex::norm(beta_next.FrobeniusNorm()));

alpha = alpha_next;
beta = beta_next;
if (error < tolerance) break;
}

gr = epsilon_surface.Inverse();
}


void c_Graphene::Compute_SurfaceGreensFunction(MatrixBlock<BlkType> &gr,
const ComplexType E,
const ComplexType U)
{
Compute_SurfaceGreensFunctionImpl(gr, E, U, true);
}


void c_Graphene::Compute_SurfaceGreensFunctionForContact(
MatrixBlock<BlkType> &gr, const ComplexType E, const ComplexType U,
const int contact)
{
Compute_SurfaceGreensFunctionImpl(gr, E, U, contact == 1);
}


void c_Graphene::Generate_AtomLocations(amrex::Vector<s_Position3D> &pos)
{
const amrex::Real sqrt3 = std::sqrt(3.);
const int N = num_zigzag_chains;

const amrex::Real x_min = -0.5 * acc;
const amrex::Real x_max = 1.5 * acc * (N - 1);
const amrex::Real x_center = 0.5 * (x_min + x_max);
const amrex::Real y_min = -0.5 * sqrt3 * acc;
const amrex::Real y_max = sqrt3 * acc *
(num_unitcells - 1. + 0.5 * (N - 1));
const amrex::Real y_center = 0.5 * (y_min + y_max);

for (int cell = 0; cell < num_unitcells; ++cell)
{
for (int n = 0; n < N; ++n)
{
const int atom_A = cell * BLOCK_SIZE + n;
const int atom_B = cell * BLOCK_SIZE + N + n;

// A_n at (sqrt(3)a(m+n/2), 3an/2).
pos[atom_A].dir[0] = 1.5 * acc * n - x_center;
pos[atom_A].dir[1] = sqrt3 * acc * (cell + 0.5 * n) - y_center;

// B_(n-1), the shifted basis row that gives zigzag terminations.
pos[atom_B].dir[0] = 1.5 * acc * n - 0.5 * acc - x_center;
pos[atom_B].dir[1] =
sqrt3 * acc * (cell + 0.5 * (n - 1)) - y_center;
#if AMREX_SPACEDIM == 3
pos[atom_A].dir[2] = 0.;
pos[atom_B].dir[2] = 0.;
#endif
}
}

c_NEGF_Common<BlkType>::Generate_AtomLocations(pos);
}
Loading
Loading