diff --git a/CMakeLists.txt b/CMakeLists.txt index f0488e1f..3f44b032 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -213,4 +219,4 @@ if(ELEQTRONeX_APP) ${CMAKE_BINARY_DIR}/eleqtronex COMMENT "Creating symlink eleqtronex -> ${binary_name}" ) -endif() \ No newline at end of file +endif() diff --git a/Source/Code_Definitions.H b/Source/Code_Definitions.H index d4464733..a36859cd 100644 --- a/Source/Code_Definitions.H +++ b/Source/Code_Definitions.H @@ -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 diff --git a/Source/Make.Code b/Source/Make.Code index 1ececc87..f2511b29 100644 --- a/Source/Make.Code +++ b/Source/Make.Code @@ -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 diff --git a/Source/Solver/Transport/NEGF/Graphene.H b/Source/Solver/Transport/NEGF/Graphene.H index ec03f0b7..ea696c6c 100644 --- a/Source/Solver/Transport/NEGF/Graphene.H +++ b/Source/Solver/Transport/NEGF/Graphene.H @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -14,56 +15,71 @@ class c_Graphene : public c_NEGF_Common { using BlkType = ComplexType[BLOCK_SIZE][BLOCK_SIZE]; - static amrex::Array type_id; + amrex::Real acc = 1.42e-10; + amrex::Real gamma = 2.7; + int num_zigzag_chains = 0; + MatrixBlock h_minusH0; + + void Read_GrapheneParameters(amrex::ParmParse &pp); + void Compute_SurfaceGreensFunctionImpl(MatrixBlock &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 & 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 &vec) final; + virtual int get_Hsize() final { return num_unitcells; } virtual int get_offDiag_repeatBlkSize() final { return 1; } - // virtual void Compute_SurfaceGreensFunction( - // MatrixBlock & gr, const ComplexType EmU) final - //{ - // } + virtual void Compute_SurfaceGreensFunction(MatrixBlock &gr, + const ComplexType E, + const ComplexType U) final; + virtual void Compute_SurfaceGreensFunctionForContact( + MatrixBlock &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( - 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((global_par_id - 1) % type_id[0]); + return (global_par_id - 1) % BLOCK_SIZE; } - amrex::Array type_id; }; static GetAtomIDAtSite get_atom_id_at_site() { - return GetAtomIDAtSite{type_id}; + return {}; } - virtual void Generate_AtomLocations(amrex::Vector & pos) final - { - } + virtual void Generate_AtomLocations( + amrex::Vector &pos) final; }; #endif diff --git a/Source/Solver/Transport/NEGF/Graphene.cpp b/Source/Solver/Transport/NEGF/Graphene.cpp index e078b4a4..991b5450 100644 --- a/Source/Solver/Transport/NEGF/Graphene.cpp +++ b/Source/Solver/Transport/NEGF/Graphene.cpp @@ -1,11 +1,223 @@ #include "Graphene.H" #include +#include #include #include +#include #include +#include #include "../../Utils/CodeUtils/CodeUtil.H" -amrex::Array 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 &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 &gr, const ComplexType E, const ComplexType U, + const bool right_lead) +{ + MatrixBlock epsilon = h_minusH0; + epsilon.SetDiag(E - U); + MatrixBlock epsilon_surface = epsilon; + + MatrixBlock alpha = h_Hb_loc_data.table()(0); + MatrixBlock 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 g = epsilon.Inverse(); + const MatrixBlock alpha_g_beta = alpha * g * beta; + const MatrixBlock beta_g_alpha = beta * g * alpha; + + epsilon_surface = epsilon_surface - alpha_g_beta; + epsilon = epsilon - alpha_g_beta - beta_g_alpha; + + MatrixBlock alpha_next = -1. * alpha * g * alpha; + MatrixBlock 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 &gr, + const ComplexType E, + const ComplexType U) +{ + Compute_SurfaceGreensFunctionImpl(gr, E, U, true); +} + + +void c_Graphene::Compute_SurfaceGreensFunctionForContact( + MatrixBlock &gr, const ComplexType E, const ComplexType U, + const int contact) +{ + Compute_SurfaceGreensFunctionImpl(gr, E, U, contact == 1); +} + + +void c_Graphene::Generate_AtomLocations(amrex::Vector &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::Generate_AtomLocations(pos); +} diff --git a/Source/Solver/Transport/NEGF/NEGF_Common.H b/Source/Solver/Transport/NEGF/NEGF_Common.H index ce4c0ad4..e656b51c 100644 --- a/Source/Solver/Transport/NEGF/NEGF_Common.H +++ b/Source/Solver/Transport/NEGF/NEGF_Common.H @@ -322,6 +322,13 @@ class c_NEGF_Common : protected MatrixBlock, private c_IntegrationPath virtual void Compute_SurfaceGreensFunction(MatrixBlock &gr, const ComplexType E, const ComplexType U); + virtual void Compute_SurfaceGreensFunctionForContact( + MatrixBlock &gr, const ComplexType E, const ComplexType U, + const int contact) + { + (void)contact; + Compute_SurfaceGreensFunction(gr, E, U); + } void Write_Current(const int step, const int total_iterations_in_step, const amrex::Real avg_intg_pts); @@ -584,6 +591,17 @@ class c_NEGF_Common : protected MatrixBlock, private c_IntegrationPath std::string get_step_foldername() const { return step_foldername_str; } std::string get_iter_foldername() const { return iter_foldername_str; } std::string get_read_atom_filename() const { return read_atom_filename; } + void Set_TransportCoordinatesFromAtomLocations( + const amrex::Vector &positions) + { + for (int l = 0; l < num_field_sites; ++l) + { + h_PTD_glo_vec[l] = + positions[l * num_atoms_per_field_site] + .dir[primary_transport_dir] / + 1.e-9; + } + } // for negf specific output int get_Total_Integration_Pts() const; diff --git a/Source/Solver/Transport/NEGF/NEGF_Common.cpp b/Source/Solver/Transport/NEGF/NEGF_Common.cpp index 98e39faf..b6a2f31a 100644 --- a/Source/Solver/Transport/NEGF/NEGF_Common.cpp +++ b/Source/Solver/Transport/NEGF/NEGF_Common.cpp @@ -1079,14 +1079,6 @@ void c_NEGF_Common::Generate_AtomLocations(amrex::Vector &pos) /*Also, specify PrimaryTransportDirection PTD array*/ /*amrex::Print() << "PTD is specified in nm! \n";*/ - for (int l = 0; l < num_field_sites; ++l) - { - h_PTD_glo_vec[l] = - pos[l * num_atoms_per_field_site].dir[primary_transport_dir] / - 1.e-9; - // amrex::Print() << l << " " << h_PTD_glo_vec(l) << "\n"; - } - for (int i = 0; i < num_atoms; ++i) { for (int j = 0; j < AMREX_SPACEDIM; ++j) @@ -1097,6 +1089,8 @@ void c_NEGF_Common::Generate_AtomLocations(amrex::Vector &pos) if (p_rotator != nullptr) p_rotator->RotateContainer(pos[i].dir, offset); } + + Set_TransportCoordinatesFromAtomLocations(pos); } template @@ -1660,8 +1654,8 @@ void c_NEGF_Common::Add_PotentialToHamiltonian() for (int c = 0; c < blkCol_size_loc; ++c) { - h_minusHa(c) = - -1 * h_U_loc(c); /*Note: Ha = H0a (=0) + U, so -Ha = -U */ + h_minusHa(c).SetDiag(-h_U_loc(c)); + /* Keep any within-slice hopping terms in a multi-orbital block. */ } } @@ -4174,7 +4168,7 @@ void c_NEGF_Common::get_Sigma_at_contacts(BlkTable1D &h_Sigma_contact_data, for (std::size_t c = 0; c < NUM_CONTACTS; ++c) { MatrixBlock gr; - Compute_SurfaceGreensFunction(gr, E, U_contact[c]); + Compute_SurfaceGreensFunctionForContact(gr, E, U_contact[c], c); h_Sigma(c) = h_tau(c) * gr * h_tau(c).Dagger(); } } diff --git a/Source/Solver/Transport/Nanostructure.cpp b/Source/Solver/Transport/Nanostructure.cpp index 9cbfa25e..9f7b3718 100644 --- a/Source/Solver/Transport/Nanostructure.cpp +++ b/Source/Solver/Transport/Nanostructure.cpp @@ -235,6 +235,7 @@ void c_Nanostructure::Read_AtomLocations() } } infile.close(); + NSType::Set_TransportCoordinatesFromAtomLocations(pos_vec); } } } diff --git a/Source/Solver/Transport/Transport.cpp b/Source/Solver/Transport/Transport.cpp index d34b2d5d..3e8bf3ed 100644 --- a/Source/Solver/Transport/Transport.cpp +++ b/Source/Solver/Transport/Transport.cpp @@ -302,7 +302,6 @@ int c_TransportSolver::Instantiate_Materials() case s_NS_Type::Graphene: { Create_Nanostructure(name, NS_id_counter); - amrex::Abort("NS_type graphene is not yet defined."); break; } case s_NS_Type::Silicon: