|
| 1 | +#include "analysis.h" |
| 2 | +#include "mpicontroller.h" |
| 3 | +#include <voronotalt/voronotalt.h> |
| 4 | +#include <numeric> |
| 5 | + |
| 6 | +namespace Faunus::analysis { |
| 7 | + |
| 8 | +Voronota::Voronota(double probe_radius, const Faunus::Space& spc) |
| 9 | + : Analysis(spc, "voronota") |
| 10 | + , probe_radius(probe_radius) { |
| 11 | + cite = "doi:10/mq8k"; |
| 12 | + auto n_pbc = spc.geometry.asSimpleGeometry()->boundary_conditions.isPeriodic().count(); |
| 13 | + switch (n_pbc) { |
| 14 | + case 0: |
| 15 | + faunus_logger->debug("{}: No PBC detected", name); |
| 16 | + use_pbc = false; |
| 17 | + break; |
| 18 | + case 3: |
| 19 | + faunus_logger->debug("{}: 3D PBC detected", name); |
| 20 | + use_pbc = true; |
| 21 | + break; |
| 22 | + default: |
| 23 | + faunus_logger->warn("{}: Non-uniform PBC is currently ignored - be careful!", name); |
| 24 | + use_pbc = false; |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +Voronota::Voronota(const Faunus::json& input, const Faunus::Space& spc) |
| 29 | + : Voronota(input.value("radius", 1.4_angstrom), spc) { |
| 30 | + from_json(input); |
| 31 | +} |
| 32 | + |
| 33 | +void Voronota::_from_json(const Faunus::json& input) { |
| 34 | + if (filename = input.value("file", ""s); !filename.empty()) { |
| 35 | + output_stream = IO::openCompressedOutputStream(MPI::prefix + filename); |
| 36 | + *output_stream << "# step SASA\n"; |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +void Voronota::_to_json(json& json_ouput) const { |
| 41 | + if (!average_data.area.empty()) { |
| 42 | + json_ouput = {{"⟨SASA⟩", average_data.area.avg()}, |
| 43 | + {"⟨SASA²⟩-⟨SASA⟩²", average_data.area_squared.avg() - std::pow(average_data.area.avg(), 2)}}; |
| 44 | + } |
| 45 | + json_ouput["radius"] = probe_radius; |
| 46 | +} |
| 47 | + |
| 48 | +void Voronota::_to_disk() { |
| 49 | + if (output_stream) { |
| 50 | + output_stream->flush(); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +void Voronota::_sample() { |
| 55 | + using voronotalt::SimplePoint; |
| 56 | + using namespace ranges::cpp20::views; |
| 57 | + |
| 58 | + // Convert single `Particle` to Voronota's `SimpleSphere` |
| 59 | + auto to_sphere = [&](const Particle& p) -> voronotalt::SimpleSphere { |
| 60 | + return {{p.pos.x(), p.pos.y(), p.pos.z()}, 0.5 * p.traits().sigma + probe_radius}; |
| 61 | + }; |
| 62 | + const auto spheres = spc.activeParticles() | transform(to_sphere) | ranges::to_vector; |
| 63 | + |
| 64 | + voronotalt::RadicalTessellation::Result result; |
| 65 | + |
| 66 | + if (use_pbc) { |
| 67 | + auto to_point = [](const Point& p) -> SimplePoint { return {p.x(), p.y(), p.z()}; }; |
| 68 | + const auto corner = 0.5 * spc.geometry.getLength(); |
| 69 | + const std::vector<SimplePoint> box_corners = {to_point(-corner), to_point(corner)}; |
| 70 | + voronotalt::RadicalTessellation::construct_full_tessellation(spheres, box_corners, result); |
| 71 | + } else { |
| 72 | + voronotalt::RadicalTessellation::construct_full_tessellation(spheres, result); |
| 73 | + } |
| 74 | + |
| 75 | + auto areas = result.cells_summaries | transform([](auto& s) { return s.sas_area; }); |
| 76 | + const auto total_area = std::accumulate(areas.begin(), areas.end(), 0.0); |
| 77 | + average_data.area.add(total_area); |
| 78 | + average_data.area_squared.add(total_area * total_area); |
| 79 | + |
| 80 | + if (output_stream) { |
| 81 | + *output_stream << this->getNumberOfSteps() << " " << total_area << "\n"; |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +} // namespace Faunus::analysis |
0 commit comments