Skip to content

Commit 571b982

Browse files
committed
Added NPC directory to plotfiles and checkpoint files for NEUTRINO_DARK_PARTICLES case
1 parent 99e1033 commit 571b982

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

Source/Nyx.H

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ protected:
656656
#ifdef AGN
657657
std::string retrieveAGN();
658658
#endif
659+
#ifdef NEUTRINO_DARK_PARTICLES
660+
std::string retrieveNPC();
661+
#endif
659662

660663
#ifndef NO_HYDRO
661664
amrex::FluxRegister& get_flux_reg();

Source/Nyx.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,22 @@ Nyx::CreateLevelDirectory (const std::string &dir)
24842484
}
24852485
#endif
24862486

2487+
#ifdef NEUTRINO_DARK_MATTER
2488+
std::string npc(dir + "/" + Nyx::retrieveNPC());
2489+
if(ParallelDescriptor::IOProcessor()) {
2490+
if( ! amrex::UtilCreateDirectory(npc, 0755)) {
2491+
amrex::CreateDirectoryFailed(npc);
2492+
}
2493+
}
2494+
2495+
LevelDirectoryNames(dir, Nyx::retrieveNPC(), LevelDir, FullPath);
2496+
if(ParallelDescriptor::IOProcessor()) {
2497+
if( ! amrex::UtilCreateDirectory(FullPath, 0755)) {
2498+
amrex::CreateDirectoryFailed(FullPath);
2499+
}
2500+
}
2501+
#endif
2502+
24872503
if(parent->UsingPrecreateDirectories()) {
24882504
if(Nyx::theDMPC()) {
24892505
Nyx::theDMPC()->SetLevelDirectoriesCreated(true);

Source/NyxParticles.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace
2929
// const std::string chk_particle_file("DM");
3030
const std::string dm_chk_particle_file("DM");
3131
const std::string agn_chk_particle_file("AGN");
32+
const std::string npc_chk_particle_file("NPC");
3233

3334
//
3435
// We want to call this routine when on exit to clean up particles.
@@ -941,6 +942,45 @@ Nyx::particle_post_restart (const std::string& restart_file, bool is_checkpoint)
941942
}
942943
}
943944
#endif
945+
946+
#ifdef NEUTRINO_DARK_PARTICLES
947+
{
948+
BL_ASSERT(NPC == 0);
949+
NPC = new DarkMatterParticleContainer(parent);
950+
ActiveParticles.push_back(NPC);
951+
952+
if (parent->subCycle())
953+
{
954+
VirtNPC = new DarkMatterParticleContainer(parent);
955+
VirtualParticles.push_back(VirtNPC);
956+
957+
GhostNPC = new DarkMatterParticleContainer(parent);
958+
GhostParticles.push_back(GhostNPC);
959+
}
960+
961+
//
962+
// Make sure to call RemoveParticlesOnExit() on exit.
963+
//
964+
amrex::ExecOnFinalize(RemoveParticlesOnExit);
965+
//
966+
// 2 gives more stuff than 1.
967+
//
968+
NPC->SetVerbose(particle_verbose);
969+
NPC->Restart(restart_file, npc_chk_particle_file, is_checkpoint);
970+
//
971+
// We want the ability to write the particles out to an ascii file.
972+
//
973+
ParmParse pp("particles");
974+
975+
std::string npc_particle_output_file;
976+
pp.query("npc_particle_output_file", npc_particle_output_file);
977+
978+
if (!npc_particle_output_file.empty())
979+
{
980+
NPC->WriteAsciiFile(npc_particle_output_file);
981+
}
982+
}
983+
#endif
944984
}
945985

946986
#ifdef GRAVITY

Source/Nyx_output.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ namespace
2121

2222
const std::string agn_chk_particle_file("AGN");
2323
const std::string agn_plt_particle_file("AGN");
24+
25+
const std::string npc_chk_particle_file("NPC");
26+
const std::string npc_plt_particle_file("NPC");
27+
2428
}
2529

2630
std::string
@@ -45,6 +49,13 @@ Nyx::retrieveAGN () {
4549
}
4650
#endif
4751

52+
#ifdef NEUTRINO_DARK_PARTICLES
53+
std::string
54+
Nyx::retrieveNPC () {
55+
return npc_chk_particle_file;
56+
}
57+
#endif
58+
4859
void
4960
Nyx::setPlotVariables ()
5061
{
@@ -358,6 +369,11 @@ Nyx::writePlotFile (const std::string& dir,
358369
Nyx::theAPC()->SetLevelDirectoriesCreated(false);
359370
}
360371
#endif
372+
#ifdef NEUTRINO_DARK_PARTICLES
373+
if(Nyx::theNPC()) {
374+
Nyx::theNPC()->SetLevelDirectoriesCreated(false);
375+
}
376+
#endif
361377

362378
}
363379

@@ -373,6 +389,12 @@ Nyx::writePlotFilePre (const std::string& dir, ostream& os)
373389
}
374390
#endif
375391

392+
#ifdef NEUTRINO_DARK_PARTICLES
393+
if(Nyx::theNPC()) {
394+
Nyx::theNPC()->WritePlotFilePre();
395+
}
396+
#endif
397+
376398
}
377399

378400

@@ -387,6 +409,12 @@ Nyx::writePlotFilePost (const std::string& dir, ostream& os)
387409
Nyx::theAPC()->WritePlotFilePost();
388410
}
389411
#endif
412+
#ifdef NEUTRINO_DARK_PARTICLES
413+
if(Nyx::theNPC()) {
414+
Nyx::theNPC()->WritePlotFilePost();
415+
}
416+
#endif
417+
390418
}
391419

392420
void
@@ -574,6 +602,13 @@ Nyx::particle_plot_file (const std::string& dir)
574602
}
575603
#endif
576604

605+
#ifdef NEUTRINO_DARK_PARTICLES
606+
if (Nyx::theNPC())
607+
{
608+
Nyx::theNPC()->WriteNyxPlotFile(dir, npc_plt_particle_file);
609+
}
610+
#endif
611+
577612
#ifdef NO_HYDRO
578613
Real cur_time = state[PhiGrav_Type].curTime();
579614
#else
@@ -628,6 +663,22 @@ Nyx::particle_plot_file (const std::string& dir)
628663
File.close();
629664
}
630665
#endif
666+
667+
#ifdef NEUTRINO_DARK_PARTICLES
668+
// Write particle_plotfile_format into its own file in the particle directory
669+
if (Nyx::theNPC() && ParallelDescriptor::IOProcessor())
670+
{
671+
std::string FileName = dir + "/" + npc_plt_particle_file + "/precision";
672+
std::ofstream File;
673+
File.open(FileName.c_str(), std::ios::out|std::ios::trunc);
674+
if ( ! File.good()) {
675+
amrex::FileOpenFailed(FileName);
676+
}
677+
File.precision(15);
678+
File << particle_plotfile_format << '\n';
679+
File.close();
680+
}
681+
#endif
631682
}
632683
}
633684

@@ -647,6 +698,12 @@ Nyx::particle_check_point (const std::string& dir)
647698
Nyx::theAPC()->NyxCheckpoint(dir, agn_chk_particle_file);
648699
}
649700
#endif
701+
#ifdef NEUTRINO_DARK_PARTICLES
702+
if (Nyx::theNPC())
703+
{
704+
Nyx::theNPC()->NyxCheckpoint(dir, npc_chk_particle_file);
705+
}
706+
#endif
650707

651708
#ifdef NO_HYDRO
652709
Real cur_time = state[PhiGrav_Type].curTime();
@@ -836,6 +893,11 @@ Nyx::checkPoint (const std::string& dir,
836893
Nyx::theAPC()->SetLevelDirectoriesCreated(false);
837894
}
838895
#endif
896+
#ifdef NEUTRINO_DARK_PARTICLES
897+
if(Nyx::theNPC()) {
898+
Nyx::theNPC()->SetLevelDirectoriesCreated(false);
899+
}
900+
#endif
839901

840902
}
841903

@@ -851,6 +913,11 @@ Nyx::checkPointPre (const std::string& dir,
851913
Nyx::theAPC()->CheckpointPre();
852914
}
853915
#endif
916+
#ifdef NEUTRINO_DARK_PARTICLES
917+
if(Nyx::theNPC()) {
918+
Nyx::theNPC()->CheckpointPre();
919+
}
920+
#endif
854921

855922
}
856923

@@ -867,6 +934,11 @@ Nyx::checkPointPost (const std::string& dir,
867934
Nyx::theAPC()->CheckpointPost();
868935
}
869936
#endif
937+
#ifdef NEUTRINO_DARK_PARTICLES
938+
if(Nyx::theNPC()) {
939+
Nyx::theNPC()->CheckpointPost();
940+
}
941+
#endif
870942
}
871943

872944

0 commit comments

Comments
 (0)