PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
MpiMetricTsProbe Class Reference
Inheritance diagram for MpiMetricTsProbe:
Collaboration diagram for MpiMetricTsProbe:

Public Member Functions

 MpiMetricTsProbe (std::filesystem::path out_dir, size_t interval)
 
void checkStop (data::ModelData &data) override
 
- Public Member Functions inherited from postprocess::Postprocess
virtual ~Postprocess ()=default
 
virtual void close (data::ModelData &data)
 
virtual std::string twoParticle (data::ModelData &data)
 
virtual std::string compressive (data::ModelData &data)
 

Private Member Functions

void dumpNodalUV (data::ModelData &data, size_t nstep)
 

Static Private Member Functions

static bool ownsNode (const data::ModelData &data, size_t i)
 

Private Attributes

std::filesystem::path d_outDir
 
size_t d_interval
 
std::ofstream d_os
 
bool d_wroteXref = false
 

Detailed Description

Sample scalars + dump gathered nodal u,v for MPI identity checks.

Definition at line 442 of file main.cpp.

Constructor & Destructor Documentation

◆ MpiMetricTsProbe()

MpiMetricTsProbe::MpiMetricTsProbe ( std::filesystem::path  out_dir,
size_t  interval 
)
inline

Definition at line 444 of file main.cpp.

445 : d_outDir(std::move(out_dir)),
446 d_interval(std::max<size_t>(1, interval)) {
447 if (util::parallel::mpiRank() == 0) {
448 std::filesystem::create_directories(d_outDir / "nodal");
449 d_os.open(d_outDir / "mpi_metric_ts.csv");
450 d_os << "step,t,max_u,com1x,com1y\n";
451 }
452 }
std::ofstream d_os
Definition main.cpp:545
std::filesystem::path d_outDir
Definition main.cpp:543
size_t d_interval
Definition main.cpp:544
int mpiRank()
get rank (id) of this processor

References d_os, d_outDir, and util::parallel::mpiRank().

Here is the call graph for this function:

Member Function Documentation

◆ checkStop()

void MpiMetricTsProbe::checkStop ( data::ModelData &  data)
inlineoverridevirtual

Reimplemented from postprocess::Postprocess.

Definition at line 454 of file main.cpp.

454 {
456 const size_t nstep = data.currentStep();
457 if (nstep % d_interval != 0 && nstep < data.numTimeSteps())
458 return;
459
460 double max_u = 0.;
461 for (const auto &u : data.d_u)
462 max_u = std::max(max_u, u.length());
463 if (util::parallel::mpiSize() > 1)
464 MPI_Allreduce(MPI_IN_PLACE, &max_u, 1, MPI_DOUBLE, MPI_MAX,
466 double com1x = 0., com1y = 0.;
467 if (data.d_particlesListTypeParticle.size() > 1) {
468 const auto c = data.d_particlesListTypeParticle[1]->getXCenter();
469 com1x = c.d_x;
470 com1y = c.d_y;
471 }
472 if (util::parallel::mpiRank() == 0) {
473 d_os << std::format("{},{:.12e},{:.12e},{:.12e},{:.12e}\n", nstep,
474 data.d_time, max_u, com1x, com1y);
475 d_os.flush();
476 }
477 dumpNodalUV(data, nstep);
478 }
void dumpNodalUV(data::ModelData &data, size_t nstep)
Definition main.cpp:501
virtual void checkStop(data::ModelData &data)
Definition contact.h:20
T max(const std::vector< T > &data)
Returns the maximum from list of data.
Definition vecMethods.h:76
int mpiSize()
Get size (number) of processors.
MPI_Comm mpiComm()
Get MPI comm.

References postprocess::Postprocess::checkStop(), d_interval, d_os, dumpNodalUV(), util::parallel::mpiComm(), util::parallel::mpiRank(), and util::parallel::mpiSize().

Here is the call graph for this function:

◆ dumpNodalUV()

void MpiMetricTsProbe::dumpNodalUV ( data::ModelData &  data,
size_t  nstep 
)
inlineprivate

Definition at line 501 of file main.cpp.

501 {
502 const size_t n = data.d_u.size();
503 std::vector<double> buf(6 * n, 0.);
504 for (size_t i = 0; i < n; ++i) {
505 if (!ownsNode(data, i))
506 continue;
507 buf[6 * i + 0] = data.d_u[i].d_x;
508 buf[6 * i + 1] = data.d_u[i].d_y;
509 buf[6 * i + 2] = data.d_u[i].d_z;
510 buf[6 * i + 3] = data.d_v[i].d_x;
511 buf[6 * i + 4] = data.d_v[i].d_y;
512 buf[6 * i + 5] = data.d_v[i].d_z;
513 }
514 if (util::parallel::mpiSize() > 1)
515 MPI_Allreduce(MPI_IN_PLACE, buf.data(), static_cast<int>(buf.size()),
516 MPI_DOUBLE, MPI_SUM, util::parallel::mpiComm());
517 if (util::parallel::mpiRank() != 0)
518 return;
519 if (!d_wroteXref) {
520 std::ofstream xr(d_outDir / "nodal" / "x_ref.bin", std::ios::binary);
521 const uint32_t nn = static_cast<uint32_t>(n);
522 xr.write(reinterpret_cast<const char *>(&nn), sizeof(nn));
523 for (size_t i = 0; i < n; ++i) {
524 const double p[3] = {data.d_xRef[i].d_x, data.d_xRef[i].d_y,
525 data.d_xRef[i].d_z};
526 xr.write(reinterpret_cast<const char *>(p), sizeof(p));
527 }
528 d_wroteXref = true;
529 }
530 const auto path =
531 d_outDir / "nodal" / std::format("uv_{:06d}.bin", nstep);
532 std::ofstream os(path, std::ios::binary);
533 const char magic[4] = {'P', 'D', 'U', 'V'};
534 const uint32_t step32 = static_cast<uint32_t>(nstep);
535 const uint32_t nn = static_cast<uint32_t>(n);
536 os.write(magic, 4);
537 os.write(reinterpret_cast<const char *>(&step32), sizeof(step32));
538 os.write(reinterpret_cast<const char *>(&nn), sizeof(nn));
539 os.write(reinterpret_cast<const char *>(buf.data()),
540 static_cast<std::streamsize>(buf.size() * sizeof(double)));
541 }
static bool ownsNode(const data::ModelData &data, size_t i)
Definition main.cpp:481

References d_outDir, d_wroteXref, util::parallel::mpiComm(), util::parallel::mpiRank(), util::parallel::mpiSize(), and ownsNode().

Referenced by checkStop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ownsNode()

static bool MpiMetricTsProbe::ownsNode ( const data::ModelData &  data,
size_t  i 
)
inlinestaticprivate

Definition at line 481 of file main.cpp.

481 {
482 const int rank = util::parallel::mpiRank();
483 if (data.d_pdDofMpi) {
484 if (i >= data.d_pdNodePartition.size())
485 return false;
486 return static_cast<int>(data.d_pdNodePartition[i]) == rank;
487 }
488 // Particle-MPI / serial: owned grains; walls only from rank 0 (replicated).
489 for (const auto *p : data.d_particlesListTypeAll) {
490 const size_t i0 = p->d_globStart;
491 const size_t i1 = i0 + p->getNumNodes();
492 if (i < i0 || i >= i1)
493 continue;
494 if (p->isWall())
495 return rank == 0;
496 return particle::isLocallyOwned(*p);
497 }
498 return rank == 0;
499 }
bool isLocallyOwned(const BaseParticle &p)
True if this rank updates / assembles forces for the particle. Walls are replicated on every rank....

References particle::isLocallyOwned(), and util::parallel::mpiRank().

Referenced by dumpNodalUV().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ d_interval

size_t MpiMetricTsProbe::d_interval
private

Definition at line 544 of file main.cpp.

Referenced by checkStop().

◆ d_os

std::ofstream MpiMetricTsProbe::d_os
private

Definition at line 545 of file main.cpp.

Referenced by checkStop(), and MpiMetricTsProbe().

◆ d_outDir

std::filesystem::path MpiMetricTsProbe::d_outDir
private

Definition at line 543 of file main.cpp.

Referenced by dumpNodalUV(), and MpiMetricTsProbe().

◆ d_wroteXref

bool MpiMetricTsProbe::d_wroteXref = false
private

Definition at line 546 of file main.cpp.

Referenced by dumpNodalUV().


The documentation for this class was generated from the following file: