PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
postprocess::Postprocess Class Reference

Extra postprocessing and stop criteria (VTU writing is in rw::). More...

#include <postprocess.h>

Inheritance diagram for postprocess::Postprocess:
Collaboration diagram for postprocess::Postprocess:

Public Member Functions

virtual ~Postprocess ()=default
 
virtual void close (data::ModelData &data)
 
virtual std::string twoParticle (data::ModelData &data)
 
virtual std::string compressive (data::ModelData &data)
 
virtual void checkStop (data::ModelData &data)
 

Detailed Description

Extra postprocessing and stop criteria (VTU writing is in rw::).

Definition at line 24 of file postprocess.h.

Constructor & Destructor Documentation

◆ ~Postprocess()

virtual postprocess::Postprocess::~Postprocess ( )
virtualdefault

Member Function Documentation

◆ checkStop()

void postprocess::Postprocess::checkStop ( data::ModelData data)
virtual

Reimplemented in anonymous_namespace{main.cpp}::GrainContactProbe, anonymous_namespace{main.cpp}::ContactWitness, RestitutionProbe, LateralProbe, and MpiMetricTsProbe.

Definition at line 147 of file postprocess.cpp.

147 {
148
149
150 if (data.d_outputDeck_p->d_outCriteria == "max_particle_dist" &&
151 data.d_testDeck_p->d_testName == "two_particle") {
152
153 // compute max distance between two particles
154 // current center position
155 const auto &xci = data.d_particlesListTypeAll[0]->getXCenter();
156 const auto &xcj = data.d_particlesListTypeAll[1]->getXCenter();
157
158 // check
159 if (util::isGreater(xci.dist(xcj),
160 data.d_outputDeck_p->d_outCriteriaParams[0])) {
161
162 if(data.d_ppFile.is_open())
163 data.d_ppFile.close();
164 exit(1);
165 }
166 }
167 else if (data.d_outputDeck_p->d_outCriteria == "max_node_dist") {
168
169 // static int msg_printed = 0;
170 // if (msg_printed == 0) {
171 // std::cout << "Check = " << data.d_outputDeck_p->d_outCriteria
172 // << " is no longer supported. In future, this test will be implemented when function util::methods::maxLength() is defined." << std::endl;
173 // msg_printed = 1;
174 // }
175 //exit(EXIT_FAILURE);
176 auto max_pt_and_index = util::methods::maxLengthAndMaxLengthIndex(data.d_x);
177 auto max_x = data.d_x[max_pt_and_index.second];
178
179 // check
180 if (util::isGreater(max_pt_and_index.first,
181 data.d_outputDeck_p->d_outCriteriaParams[0])) {
182
183 // close open file
184 if(data.d_ppFile.is_open())
185 data.d_ppFile.close();
186
187 util::io::log(0, std::format("{}: Terminating simulation as one of the failing"
188 " criteria is met. Point ({:.6f}, {:.6f}, {:.6f}) is at "
189 "distance {:.6f} "
190 "more than"
191 " allowed distance {:.6f}\n",
192 data.d_name, max_x.d_x, max_x.d_y, max_x.d_z, max_x.length(),
193 data.d_outputDeck_p->d_outCriteriaParams[0]));
194 exit(1);
195 }
196 }
197
198}
Definition contact.h:20
void log(std::ostringstream &oss, bool screen_out=false, int printMpiRank=print_default_mpi_rank)
Global method to log the message.
Definition io.cpp:41
std::pair< double, size_t > maxLengthAndMaxLengthIndex(const std::vector< util::Point > &data)
Returns the maximum length of point and index from list of points.
Definition vecMethods.h:208
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15

References util::isGreater(), util::io::log(), and util::methods::maxLengthAndMaxLengthIndex().

Referenced by anonymous_namespace{main.cpp}::GrainContactProbe::checkStop(), anonymous_namespace{main.cpp}::ContactWitness::checkStop(), RestitutionProbe::checkStop(), LateralProbe::checkStop(), and MpiMetricTsProbe::checkStop().

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

◆ close()

void postprocess::Postprocess::close ( data::ModelData data)
virtual

Definition at line 25 of file postprocess.cpp.

25 {
26
27 if (data.d_ppFile.is_open())
28 data.d_ppFile.close();
29
30}

◆ compressive()

std::string postprocess::Postprocess::compressive ( data::ModelData data)
virtual

Definition at line 89 of file postprocess.cpp.

89 {
90
91 bool continue_dt = false;
92 auto check_dt = data.d_outputDeck_p->d_dtTestOut;
93 if ((data.d_n % check_dt == 0) && (data.d_n >= check_dt))
94 continue_dt = true;
95
96 if (!continue_dt)
97 return "";
98
99 // get wall
100 auto w_id = data.d_testDeck_p->d_particleIdCompressiveTest;
101 auto f_dir = data.d_testDeck_p->d_particleForceDirectionCompressiveTest - 1;
102 const auto &wall = data.d_particlesListTypeAll[w_id];
103
104 // find the penetration of the wall from it's original location
105 auto dx = wall->getXLocal(0) - wall->getXRefLocal(0);
106 double wall_penetration = dx[f_dir];
107
108 // Local wall reaction; under particle-MPI each rank only sees contact from
109 // owned grains, so sum across ranks before recording.
110 double tot_reaction_force = 0.;
111 for (size_t i = 0; i < wall->getNumNodes(); i++) {
112 tot_reaction_force += wall->getFLocal(i)[f_dir] * wall->getVolLocal(i);
113 }
114 if (util::parallel::mpiSize() > 1) {
115 double reduced = 0.;
116 MPI_Allreduce(&tot_reaction_force, &reduced, 1, MPI_DOUBLE, MPI_SUM,
118 tot_reaction_force = reduced;
119 }
120
121 // Rank 0 only: avoid interleaved multi-rank appends to the same CSV.
122 if (util::parallel::mpiRank() == 0) {
123 if (!data.d_ppFile.is_open()) {
124 std::string tag_pp_file = data.d_outputDeck_p->d_tagPPFile.empty()
125 ? "0"
126 : data.d_outputDeck_p->d_tagPPFile;
127 std::string filename = data.d_outputDeck_p->d_path + "pp_" +
128 data.d_testDeck_p->d_testName + "_" +
129 tag_pp_file + ".csv";
130 data.d_ppFile.open(filename.c_str(), std::ofstream::out | std::ofstream::app);
131 data.d_ppFile << "t, delta, force \n";
132 }
133 data.d_ppFile << std::format("{:.6e}, {:.6e}, {:.6e}\n", data.d_time,
134 wall_penetration, tot_reaction_force);
135 }
136
137 data.setKeyData("wall_penetration", wall_penetration);
138 data.setKeyData("tot_reaction_force", tot_reaction_force);
139
140 return std::format(" Post-processing: wall penetration = {:"
141 ".6f}, "
142 "reaction force = {:5.3e} \n",
143 wall_penetration, tot_reaction_force);
144
145}
int mpiSize()
Get size (number) of processors.
int mpiRank()
get rank (id) of this processor
MPI_Comm mpiComm()
Get MPI comm.

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

Here is the call graph for this function:

◆ twoParticle()

std::string postprocess::Postprocess::twoParticle ( data::ModelData data)
virtual

Definition at line 32 of file postprocess.cpp.

32 {
33
34
35 bool continue_dt = false;
36 auto check_dt = data.d_outputDeck_p->d_dtTestOut;
37 if ((data.d_n % check_dt == 0) && (data.d_n >= check_dt))
38 continue_dt = true;
39
40 if (!continue_dt)
41 return "";
42
43 // get alias for particles
44 const auto &p0 = data.d_particlesListTypeAll[0];
45 const auto &p1 = data.d_particlesListTypeAll[1];
46
47 // get penetration distance
48 const auto &xc0 = p0->getXCenter();
49 const auto &xc1 = p1->getXCenter();
50 const double &r = p0->d_geom_p->boundingRadius();
51
52 const auto &contact = data.d_particleDeck_p->d_contactDeck.getContact(p0->getGroupId("contact_id"), p1->getGroupId("contact_id"));
53 double r_e = r + contact.d_contactR;
54
55 double pen_dist = xc1.dist(xc0) - r_e - r;
56 double contact_area_radius = 0.;
57 if (util::isLess(pen_dist, 0.))
58 contact_area_radius =
59 std::sqrt(std::pow(r_e, 2.) - std::pow(r_e + pen_dist, 2.));
60 else if (util::isGreater(pen_dist, 0.)) {
61 pen_dist = 0.;
62 contact_area_radius = 0.;
63 }
64
65 // get max distance of second particle (i.e. the y-coord of center + radius)
66 double max_dist = xc1.d_y + p1->d_geom_p->boundingRadius();
67
68 // compute maximum y coordinate of particle 2
69 double max_y_loc = p1->getXLocal(0).d_y;
70 double max_y = 0.;
71 for (size_t i = 0; i < p1->getNumNodes(); i++)
72 if (util::isLess(max_y_loc, p1->getXLocal(i).d_y))
73 max_y_loc = p1->getXLocal(i).d_y;
74
75 if (util::isLess(max_y, max_y_loc))
76 max_y = max_y_loc;
77
78 data.setKeyData("pen_dist", pen_dist);
79 data.setKeyData("contact_area_radius", contact_area_radius);
80 data.setKeyData("max_y", max_y);
81 data.setKeyData("max_dist", max_dist);
82 data.setKeyData("max_y_loc", max_y_loc);
83
84
85 return std::format(" Post-processing: max y = {:.6f} \n", max_y);
86
87}
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20

References util::isGreater(), and util::isLess().

Here is the call graph for this function:

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