Skip to content

Commit

Permalink
Backuo
Browse files Browse the repository at this point in the history
  • Loading branch information
egor-demidov committed Jul 16, 2024
1 parent 61e06e2 commit 7572f45
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 5 deletions.
88 changes: 88 additions & 0 deletions src/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,94 @@ void dump_particles(std::string const & name, std::vector<Eigen::Vector3d> const
ofs << "\n";
}

void dump_particles(std::string const & dir, size_t count, std::vector<Eigen::Vector3d> const & x,
std::vector<Eigen::Vector3d> const & theta,
std::vector<Eigen::Vector3d> const & v,
std::vector<Eigen::Vector3d> const & a,
std::vector<Eigen::Vector3d> const & omega,
std::vector<Eigen::Vector3d> const & alpha,
double r_part) {
std::stringstream out_file_name;
out_file_name << dir << "/particles_" << count << ".vtk";
std::ofstream ofs(out_file_name.str());

if (!ofs.good()) {
std::cerr << "Unable to create a dump file at " << out_file_name.str() << std::endl;
exit(EXIT_FAILURE);
}

ofs << "# vtk DataFile Version 4.0" << "\n";
ofs << "Generated by libFractalCommon" << "\n";
ofs << "ASCII" << "\n";
ofs << "DATASET POLYDATA" << "\n";
ofs << "POINTS " << x.size() << " FLOAT" << "\n";

// Coordinates are normalized to avoid issues with ParaView and small particles
for (auto const & p : x) {
ofs << p[0] / r_part << " " << p[1] / r_part << " " << p[2] / r_part << " ";
}

ofs << "\n\n";
ofs << "POINT_DATA " << x.size() << "\n";
ofs << "FIELD FieldData 7" << "\n";
ofs << "v 1 " << x.size() << " double\n";
for (auto const & p : v) {
ofs << p.norm() << " ";
}
ofs << "\n";
ofs << "a 1 " << x.size() << " double\n";
for (auto const & p : a) {
ofs << p.norm() << " ";
}
ofs << "\n";
ofs << "omega 1 " << x.size() << " double\n";
for (auto const & p : omega) {
ofs << p.norm() << " ";
}
ofs << "\n";
ofs << "alpha 1 " << x.size() << " double\n";
for (auto const & p : alpha) {
ofs << p.norm() << " ";
}
ofs << "\n";
ofs << "thetax 3 " << x.size() << " double\n";
for (auto const & t : theta) {
Eigen::Matrix3d m;
m = Eigen::AngleAxis(t[0], Eigen::Vector3d::UnitX())
* Eigen::AngleAxis(t[1], Eigen::Vector3d::UnitY())
* Eigen::AngleAxis(t[2], Eigen::Vector3d::UnitZ());

auto unit = Eigen::Vector3d::UnitX();
auto orient = m*unit;

ofs << orient[0] << " " << orient[1] << " " << orient[2] << " ";
}
ofs << "\n" << "thetay 3 " << x.size() << " double" << "\n";
for (auto const & t : theta) {
Eigen::Matrix3d m;
m = Eigen::AngleAxis(t[0], Eigen::Vector3d::UnitX())
* Eigen::AngleAxis(t[1], Eigen::Vector3d::UnitY())
* Eigen::AngleAxis(t[2], Eigen::Vector3d::UnitZ());

auto unit = Eigen::Vector3d::UnitY();
auto orient = m*unit;

ofs << orient[0] << " " << orient[1] << " " << orient[2] << " ";
}
ofs << "\n" << "thetaz 3 " << x.size() << " double" << "\n";
for (auto const & t : theta) {
Eigen::Matrix3d m;
m = Eigen::AngleAxis(t[0], Eigen::Vector3d::UnitX())
* Eigen::AngleAxis(t[1], Eigen::Vector3d::UnitY())
* Eigen::AngleAxis(t[2], Eigen::Vector3d::UnitZ());

auto unit = Eigen::Vector3d::UnitZ();
auto orient = m*unit;

ofs << orient[0] << " " << orient[1] << " " << orient[2] << " ";
}
}

void dump_particles(std::string const & dir, size_t count, std::vector<Eigen::Vector3d> const & x,
std::vector<Eigen::Vector3d> const & v,
std::vector<Eigen::Vector3d> const & a,
Expand Down
8 changes: 8 additions & 0 deletions src/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ void dump_particles(std::string const & dir, size_t count, std::vector<Eigen::Ve
std::vector<Eigen::Vector3d> const & alpha,
double r_part);

void dump_particles(std::string const & dir, size_t count, std::vector<Eigen::Vector3d> const & x,
std::vector<Eigen::Vector3d> const & theta,
std::vector<Eigen::Vector3d> const & v,
std::vector<Eigen::Vector3d> const & a,
std::vector<Eigen::Vector3d> const & omega,
std::vector<Eigen::Vector3d> const & alpha,
double r_part);

#endif //SOOT_AFM_WRITER_H
9 changes: 9 additions & 0 deletions validation/01_particles_colliding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";

Expand All @@ -28,6 +29,8 @@ int main() {
const double dt = 1e-13;
const double t_tot = 1.0e-10;
const auto n_steps = size_t(t_tot / dt);
const size_t n_dumps = 300;
const size_t dump_period = n_steps / n_dumps;

// General parameters
const double rho = 1700.0;
Expand Down Expand Up @@ -83,6 +86,12 @@ int main() {


for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// }
if (double(n) * dt * 1e6 <= 4.0e-6) {
t_span.emplace_back(double(n) * dt * 1e6);
ke_trs_span.emplace_back(compute_ke_trs(system.get_v(), mass));
Expand Down
9 changes: 8 additions & 1 deletion validation/02_particles_colliding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";

Expand All @@ -28,7 +29,7 @@ int main() {
const double dt = 1e-13;
const double t_tot = 1.0e-10;
const auto n_steps = size_t(t_tot / dt);
const size_t n_dumps = 1000;
const size_t n_dumps = 300;
const size_t dump_period = n_steps / n_dumps;

// General parameters
Expand Down Expand Up @@ -85,6 +86,12 @@ int main() {


for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// }
if (double(n) * dt * 1e6 <= 4.0e-6) {
t_span.emplace_back(double(n) * dt * 1e6);
ke_trs_span.emplace_back(compute_ke_trs(system.get_v(), mass));
Expand Down
9 changes: 9 additions & 0 deletions validation/03_particles_colliding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";

Expand All @@ -28,6 +29,8 @@ int main() {
const double dt = 1e-13;
const double t_tot = 1.0e-10;
const auto n_steps = size_t(t_tot / dt);
const size_t n_dumps = 300;
const size_t dump_period = n_steps / n_dumps;

// General parameters
const double rho = 1700.0;
Expand Down Expand Up @@ -83,6 +86,12 @@ int main() {


for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// }
if (double(n) * dt * 1e6 <= 4.0e-6) {
t_span.emplace_back(double(n) * dt * 1e6);
ke_trs_span.emplace_back(compute_ke_trs(system.get_v(), mass));
Expand Down
9 changes: 9 additions & 0 deletions validation/04_particles_colliding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";

Expand All @@ -28,6 +29,8 @@ int main() {
const double dt = 1e-13;
const double t_tot = 1.0e-10;
const auto n_steps = size_t(t_tot / dt);
const size_t n_dumps = 300;
const size_t dump_period = n_steps / n_dumps;

// General parameters
const double rho = 1700.0;
Expand Down Expand Up @@ -84,6 +87,12 @@ int main() {


for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// }
if (double(n) * dt * 1e6 <= 4.0e-6) {
t_span.emplace_back(double(n) * dt * 1e6);
ke_trs_span.emplace_back(compute_ke_trs(system.get_v(), mass));
Expand Down
7 changes: 7 additions & 0 deletions validation/05_hamaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"
#include "fixed_step_handler.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";
Expand Down Expand Up @@ -116,6 +117,12 @@ int main() {
ofs << "D\tKE\tU\n";

for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// }
double separation = (system.get_x()[1] - system.get_x()[0]).norm() - 2.0 * r_part;
if (separation <= h0) {
has_collided = true;
Expand Down
7 changes: 6 additions & 1 deletion validation/06_sintering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";

Expand Down Expand Up @@ -104,7 +105,11 @@ int main() {
for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// write_particles("run", system.get_x(), system.get_theta(), r_part);
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// dump_necks("run", n / dump_period, system.get_x(), std::vector<bool>{false, true, false, true, false, true, false, false,
// true}, r_part);
// }
if (n % thermo_dump_period == 0) {
auto ke_trs = compute_ke_trs(system.get_v(), mass);
Expand Down
7 changes: 6 additions & 1 deletion validation/07_sintering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";

Expand Down Expand Up @@ -104,7 +105,11 @@ int main() {
for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// write_particles("run", system.get_x(), system.get_theta(), r_part);
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// dump_necks("run", n / dump_period, system.get_x(), std::vector<bool>{false, true, false, true, false, true, false, false,
// true}, r_part);
// }
if (n % thermo_dump_period == 0) {
auto ke_trs = compute_ke_trs(system.get_v(), mass);
Expand Down
7 changes: 6 additions & 1 deletion validation/08_sintering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";

Expand Down Expand Up @@ -104,7 +105,11 @@ int main() {
for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// write_particles("run", system.get_x(), system.get_theta(), r_part);
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// dump_necks("run", n / dump_period, system.get_x(), std::vector<bool>{false, true, false, true, false, true, false, false,
// true}, r_part);
// }
if (n % thermo_dump_period == 0) {
auto ke_trs = compute_ke_trs(system.get_v(), mass);
Expand Down
7 changes: 6 additions & 1 deletion validation/09_sintering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <libgran/contact_force/contact_force.h>

#include "../src/energy.h"
#include "../src/writer.h"

static const std::filesystem::path OUTPUT_FILE = "/dev/stdout";

Expand Down Expand Up @@ -104,7 +105,11 @@ int main() {
for (size_t n = 0; n < n_steps; n ++) {
// if (n % dump_period == 0) {
// std::cout << "Dump #" << n / dump_period << std::endl;
// write_particles("run", system.get_x(), system.get_theta(), r_part);
// dump_particles("run", n / dump_period, system.get_x(), system.get_theta(),
// system.get_v(), system.get_a(),
// system.get_omega(), system.get_alpha(), r_part);
// dump_necks("run", n / dump_period, system.get_x(), std::vector<bool>{false, true, false, true, false, true, false, false,
// true}, r_part);
// }
if (n % thermo_dump_period == 0) {
auto ke_trs = compute_ke_trs(system.get_v(), mass);
Expand Down

0 comments on commit 7572f45

Please sign in to comment.