Skip to content

Commit

Permalink
major modifications to make c_Nanostructure class polymorphic
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh-s-sawant committed Dec 6, 2024
1 parent 22a01ac commit c9da891
Show file tree
Hide file tree
Showing 10 changed files with 600 additions and 811 deletions.
10 changes: 7 additions & 3 deletions Source/Input/MacroscopicProperties/PointChargeContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ void c_PointChargeContainer::Write_OutputFile()
outfile_pc_step << std::setw(10) << step;
#ifdef USE_TRANSPORT
auto &rTransport = rCode.get_TransportSolver();
outfile_pc_step << std::setw(12) << rTransport.get_Vds()
<< std::setw(12) << rTransport.get_Vgs()
<< std::setw(10) << rTransport.get_Broyden_Step() - 1;
const auto& biases = rTransport.Get_Vec_Biases();
if(!biases.empty()) {
auto [Vds, Vgs] = biases[0]; //here biases on all nanostructures are equal
outfile_pc_step << std::setw(12) << Vds
<< std::setw(12) << Vgs;
}
outfile_pc_step << std::setw(10) << rTransport.get_Broyden_Step() - 1;
#endif
outfile_pc_step << std::setw(15) << Get_total_charge() << std::setw(15)
<< Get_total_charge() / static_cast<amrex::Real>(
Expand Down
171 changes: 0 additions & 171 deletions Source/Solver/Transport/Broyden_First_Serial.cpp

This file was deleted.

55 changes: 14 additions & 41 deletions Source/Solver/Transport/Broyden_Parallel_General.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ using namespace amrex;

enum class s_Algorithm_Type : int
{
broyden_first,
broyden_second,
simple_mixing
};
Expand Down Expand Up @@ -45,39 +44,26 @@ void c_TransportSolver::Define_Broyden_Partition()
/* Each process executes this function.
*
* Create the following:
* num_field_sites_all_NS
* my_rank
* total_proc
* site_size_loc
* site_size_loc_all_NS
* site_size_loc_cumulative vector of size equal to all nanostructure.
*/

num_field_sites_all_NS = 0;
total_proc = amrex::ParallelDescriptor::NProcs();
my_rank = amrex::ParallelDescriptor::MyProc();

// MPI_recv_count.resize(total_proc);
// MPI_recv_disp.resize(total_proc);
// num_procs_with_sites=total_proc;

site_size_loc_cumulative.resize(vp_CNT.size() + 1);
site_size_loc_cumulative.resize(vp_NS.size() + 1);
site_size_loc_cumulative[0] = 0;

for (int c = 0; c < vp_CNT.size(); ++c)
for (int c = 0; c < vp_NS.size(); ++c)
{
vp_CNT[c]->set_site_size_loc_offset(site_size_loc_cumulative[c]);
vp_NS[c]->Set_NumFieldSites_Local_NSOffset(site_size_loc_cumulative[c]);

site_size_loc_cumulative[c + 1] =
site_size_loc_cumulative[c] + vp_CNT[c]->MPI_recv_count[my_rank];
site_size_loc_cumulative[c] + vp_NS[c]->Get_NumFieldSites_Local();
}
site_size_loc_all_NS = site_size_loc_cumulative[vp_CNT.size()];

// if (ParallelDescriptor::IOProcessor())
//{
// amrex::Print() << "recv_count/recv_disp: \n";
// for(int i=0; i < total_proc; ++i) {
// amrex::Print() << i << " " << MPI_recv_count[i] << " "<<
// MPI_recv_disp[i] << "\n";
// }
// }
site_size_loc_all_NS = site_size_loc_cumulative[vp_NS.size()];

}

void c_TransportSolver::Set_Broyden_Parallel()
Expand All @@ -99,16 +85,15 @@ void c_TransportSolver::Set_Broyden_Parallel()
auto const &h_n_curr_in = h_n_curr_in_data.table();

/*Need generalization for multiple CNTs*/
for (int c = 0; c < vp_CNT.size(); ++c)
for (int c = 0; c < vp_NS.size(); ++c)
{
int NS_offset = site_size_loc_cumulative[c];
vp_CNT[c]->Fetch_InputLocalCharge_FromNanostructure(
h_n_curr_in_data, NS_offset, vp_CNT[c]->MPI_recv_disp[my_rank],
vp_CNT[c]->MPI_recv_count[my_rank]);
vp_NS[c]->Copy_ForBroydenInput_LocalChargeFromNanostructure(
h_n_curr_in_data, NS_offset);

// amrex::Print() << "Fetching h_n_curr_in for NS_id: " <<
// vp_CNT[c]->NS_Id << "\n"; for(int i=NS_offset; i< NS_offset +
// vp_CNT[c]->MPI_recv_count[my_rank]; ++i) {
// vp_NS[c]->NS_Id << "\n"; for(int i=NS_offset; i< NS_offset +
// vp_NS[c]->MPI_recv_count[my_rank]; ++i) {
// amrex::Print() << i << " " << h_n_curr_in(i) << "\n";
// }
}
Expand Down Expand Up @@ -155,14 +140,6 @@ void c_TransportSolver::Set_Broyden_Parallel()

switch (c_TransportSolver::map_AlgorithmType.at(Algorithm_Type))
{
case s_Algorithm_Type::broyden_first:
{
amrex::Abort(
"Algorithm, broyden_first is not parallelized. Compile "
"with preprocessor directive, BROYDEN_PARALLEL=False, or "
"use broyden_second algorithm.");
break;
}
case s_Algorithm_Type::broyden_second:
{
h_intermed_vector_data.resize({0}, {Broyden_Threshold_MaxStep},
Expand Down Expand Up @@ -314,10 +291,6 @@ void c_TransportSolver::Reset_Broyden_Parallel()

switch (c_TransportSolver::map_AlgorithmType.at(Algorithm_Type))
{
case s_Algorithm_Type::broyden_first:
{
break;
}
case s_Algorithm_Type::broyden_second:
{
#ifdef BROYDEN_SKIP_GPU_OPTIMIZATION
Expand Down
1 change: 0 additions & 1 deletion Source/Solver/Transport/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ CEXE_sources += Broyden_Serial_General.cpp
CEXE_sources += Broyden_Parallel_General.cpp

CEXE_sources += Simple_Mixing_Serial.cpp
CEXE_sources += Broyden_First_Serial.cpp
CEXE_sources += Broyden_Second_Serial.cpp
CEXE_sources += Broyden_Second_Parallel.cpp

Expand Down
Loading

0 comments on commit c9da891

Please sign in to comment.