1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
// 2018 © William Chèvremont <william.chevremont@univ-grenoble-alpes.fr>
#pragma once
#include <pkg/common/NormShearPhys.hpp>
#include <pkg/common/PeriodicEngines.hpp>
#include <pkg/dem/ScGeom.hpp>
#include <boost/multi_array.hpp>
namespace yade { // Cannot have #include directive inside.
class PDFEngine : public PeriodicEngine {
public:
class PDFCalculator {
public:
PDFCalculator(string const& n)
: name(n) {};
virtual ~PDFCalculator() {};
virtual vector<string> getSuffixes() const { return vector<string>({ "" }); }
virtual vector<string> getDatas() const = 0;
virtual void cleanData() = 0;
virtual bool addData(const shared_ptr<Interaction>&, Real const& dS, Real const& V, int const& N, bool inversed) = 0;
string name;
};
typedef boost::multi_array<shared_ptr<PDFCalculator>, 2> PDF;
static void getSpectrums(vector<PDF>&);
void action() override;
// clang-format off
YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(PDFEngine, PeriodicEngine,
"Base class for spectrums calculations. Compute Probability Density Functions of normalStress, shearStress, distance, velocity and interactions in spherical coordinates and write result to a file. Column name format is: Data(theta, phi). Convention used: x: phi = 0, y: theta = 0, z: phi = pi/2",
((uint, numDiscretizeAngleTheta, 20,,"Number of sector for theta-angle"))
((uint, numDiscretizeAnglePhi, 20,,"Number of sector for phi-angle"))
//((Real, discretizeRadius, 0.1,,"d/a interval size"))
((string, filename, "PDF.txt", , "Filename"))
((bool, firstRun, true, (Attr::hidden | Attr::readonly), ""))
((bool, warnedOnce, false, , "For one-time warning. May trigger usefull warnings"))
,,
//.def("getSpectrums", &LubricationDPFEngine::PyGetSpectrums,(py::arg("nPhi")=40, py::arg("nTheta")=20), "Get Stress spectrums").staticmethod("getSpectrums")
);
// clang-format on
DECLARE_LOGGER;
protected:
void writeToFile(vector<PDF> const&);
};
REGISTER_SERIALIZABLE(PDFEngine);
template <class Phys> class PDFSpheresStressCalculator : public PDFEngine::PDFCalculator {
public:
PDFSpheresStressCalculator(Vector3r Phys::*member, string name2)
: PDFEngine::PDFCalculator(name2)
, m_member(member)
, m_stress(Matrix3r::Zero()) {};
vector<string> getSuffixes() const override { return vector<string>({ "xx", "xy", "xz", "yx", "yy", "yz", "zx", "zy", "zz" }); }
vector<string> getDatas() const override
{
vector<string> out;
for (int i(0); i < 3; i++)
for (int j(0); j < 3; j++)
out.push_back(math::toString(m_stress(i, j)));
return out;
}
void cleanData() override { m_stress = Matrix3r::Zero(); }
bool addData(const shared_ptr<Interaction>& I, Real const& dS, Real const& V, int const&, bool) override
{
if (!I->isReal()) return false;
ScGeom* geom = dynamic_cast<ScGeom*>(I->geom.get());
Phys* phys = dynamic_cast<Phys*>(I->phys.get());
if (geom && phys) {
Real r = geom->radius1 + geom->radius2 - geom->penetrationDepth;
Vector3r l = r / (V * dS) * geom->normal;
m_stress += phys->*(m_member)*l.transpose();
return true;
} else
return false;
}
private:
Vector3r Phys::*m_member;
Matrix3r m_stress;
};
class PDFSpheresDistanceCalculator : public PDFEngine::PDFCalculator {
public:
PDFSpheresDistanceCalculator(string name);
vector<string> getDatas() const override;
void cleanData() override;
bool addData(const shared_ptr<Interaction>&, Real const& dS, Real const& V, int const& N, bool inversed) override;
private:
Real m_h;
uint m_N;
};
class PDFSpheresVelocityCalculator : public PDFEngine::PDFCalculator {
public:
PDFSpheresVelocityCalculator(string name);
vector<string> getSuffixes() const override;
vector<string> getDatas() const override;
void cleanData() override;
bool addData(const shared_ptr<Interaction>&, Real const& dS, Real const& V, int const& N, bool inversed) override;
private:
Vector3r m_vel;
uint m_N;
};
class PDFSpheresIntrsCalculator : public PDFEngine::PDFCalculator {
public:
PDFSpheresIntrsCalculator(
string name, bool (*)(shared_ptr<Interaction> const&) = [](shared_ptr<Interaction> const&) { return true; });
vector<string> getDatas() const override;
void cleanData() override;
bool addData(const shared_ptr<Interaction>&, Real const& dS, Real const& V, int const& N, bool inversed) override;
private:
Real m_P;
bool (*m_accepter)(shared_ptr<Interaction> const&);
};
} // namespace yade
|