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 385 of file main.cpp.

Constructor & Destructor Documentation

◆ MpiMetricTsProbe()

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

Definition at line 387 of file main.cpp.

388 : d_outDir(std::move(out_dir)),
389 d_interval(std::max<size_t>(1, interval)) {
390 if (util::parallel::mpiRank() == 0) {
391 std::filesystem::create_directories(d_outDir / "nodal");
392 d_os.open(d_outDir / "mpi_metric_ts.csv");
393 d_os << "step,t,max_u,com1x,com1y\n";
394 }
395 }
std::ofstream d_os
Definition main.cpp:488
std::filesystem::path d_outDir
Definition main.cpp:486
size_t d_interval
Definition main.cpp:487
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 397 of file main.cpp.

397 {
399 const size_t nstep = data.currentStep();
400 if (nstep % d_interval != 0 && nstep < data.numTimeSteps())
401 return;
402
403 double max_u = 0.;
404 for (const auto &u : data.d_u)
405 max_u = std::max(max_u, u.length());
406 if (util::parallel::mpiSize() > 1)
407 MPI_Allreduce(MPI_IN_PLACE, &max_u, 1, MPI_DOUBLE, MPI_MAX,
409 double com1x = 0., com1y = 0.;
410 if (data.d_particlesListTypeParticle.size() > 1) {
411 const auto c = data.d_particlesListTypeParticle[1]->getXCenter();
412 com1x = c.d_x;
413 com1y = c.d_y;
414 }
415 if (util::parallel::mpiRank() == 0) {
416 d_os << std::format("{},{:.12e},{:.12e},{:.12e},{:.12e}\n", nstep,
417 data.d_time, max_u, com1x, com1y);
418 d_os.flush();
419 }
420 dumpNodalUV(data, nstep);
421 }
void dumpNodalUV(data::ModelData &data, size_t nstep)
Definition main.cpp:444
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:74
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 444 of file main.cpp.

444 {
445 const size_t n = data.d_u.size();
446 std::vector<double> buf(6 * n, 0.);
447 for (size_t i = 0; i < n; ++i) {
448 if (!ownsNode(data, i))
449 continue;
450 buf[6 * i + 0] = data.d_u[i].d_x;
451 buf[6 * i + 1] = data.d_u[i].d_y;
452 buf[6 * i + 2] = data.d_u[i].d_z;
453 buf[6 * i + 3] = data.d_v[i].d_x;
454 buf[6 * i + 4] = data.d_v[i].d_y;
455 buf[6 * i + 5] = data.d_v[i].d_z;
456 }
457 if (util::parallel::mpiSize() > 1)
458 MPI_Allreduce(MPI_IN_PLACE, buf.data(), static_cast<int>(buf.size()),
459 MPI_DOUBLE, MPI_SUM, util::parallel::mpiComm());
460 if (util::parallel::mpiRank() != 0)
461 return;
462 if (!d_wroteXref) {
463 std::ofstream xr(d_outDir / "nodal" / "x_ref.bin", std::ios::binary);
464 const uint32_t nn = static_cast<uint32_t>(n);
465 xr.write(reinterpret_cast<const char *>(&nn), sizeof(nn));
466 for (size_t i = 0; i < n; ++i) {
467 const double p[3] = {data.d_xRef[i].d_x, data.d_xRef[i].d_y,
468 data.d_xRef[i].d_z};
469 xr.write(reinterpret_cast<const char *>(p), sizeof(p));
470 }
471 d_wroteXref = true;
472 }
473 const auto path =
474 d_outDir / "nodal" / std::format("uv_{:06d}.bin", nstep);
475 std::ofstream os(path, std::ios::binary);
476 const char magic[4] = {'P', 'D', 'U', 'V'};
477 const uint32_t step32 = static_cast<uint32_t>(nstep);
478 const uint32_t nn = static_cast<uint32_t>(n);
479 os.write(magic, 4);
480 os.write(reinterpret_cast<const char *>(&step32), sizeof(step32));
481 os.write(reinterpret_cast<const char *>(&nn), sizeof(nn));
482 os.write(reinterpret_cast<const char *>(buf.data()),
483 static_cast<std::streamsize>(buf.size() * sizeof(double)));
484 }
static bool ownsNode(const data::ModelData &data, size_t i)
Definition main.cpp:424

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 424 of file main.cpp.

424 {
425 const int rank = util::parallel::mpiRank();
426 if (data.d_pdDofMpi) {
427 if (i >= data.d_pdNodePartition.size())
428 return false;
429 return static_cast<int>(data.d_pdNodePartition[i]) == rank;
430 }
431 // Particle-MPI / serial: owned grains; walls only from rank 0 (replicated).
432 for (const auto *p : data.d_particlesListTypeAll) {
433 const size_t i0 = p->d_globStart;
434 const size_t i1 = i0 + p->getNumNodes();
435 if (i < i0 || i >= i1)
436 continue;
437 if (p->isWall())
438 return rank == 0;
439 return particle::isLocallyOwned(*p);
440 }
441 return rank == 0;
442 }
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 487 of file main.cpp.

Referenced by checkStop().

◆ d_os

std::ofstream MpiMetricTsProbe::d_os
private

Definition at line 488 of file main.cpp.

Referenced by checkStop(), and MpiMetricTsProbe().

◆ d_outDir

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

Definition at line 486 of file main.cpp.

Referenced by dumpNodalUV(), and MpiMetricTsProbe().

◆ d_wroteXref

bool MpiMetricTsProbe::d_wroteXref = false
private

Definition at line 489 of file main.cpp.

Referenced by dumpNodalUV().


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