-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add properties export and create restart
- Loading branch information
Showing
4 changed files
with
154 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
#include <xtensor/xjson.hpp> | ||
#include <xtensor/xtensor.hpp> | ||
|
||
#include "property.hpp" | ||
|
||
namespace nl = nlohmann; | ||
|
||
namespace nlohmann | ||
{ | ||
template <std::size_t dim> | ||
struct adl_serializer<scopi::property<dim>> | ||
{ | ||
using xt_t = xt::xtensor<double, 1>; | ||
using xt_t2 = xt::xtensor<double, 2>; | ||
using moment_t = typename std::conditional<dim == 2, double, xt_t>::type; | ||
using rotation_t = typename std::conditional<dim == 2, double, xt_t>::type; | ||
|
||
static void to_json(json&, const scopi::property<dim>&) | ||
{ | ||
} | ||
|
||
static void from_json(const json& j, scopi::property<dim>& p) | ||
{ | ||
p.velocity(j["velocity"].get<xt_t>()) | ||
.desired_velocity(j["desired_velocity"].get<xt_t>()) | ||
.omega(j["omega"].get<rotation_t>()) | ||
.desired_omega(j["desired_omega"].get<rotation_t>()) | ||
.force(j["force"].get<xt_t>()) | ||
.mass(j["mass"].get<double>()) | ||
.moment_inertia(j["moment_inertia"].get<moment_t>()); | ||
if (j["active"].get<bool>()) | ||
{ | ||
p.activate(); | ||
} | ||
else | ||
{ | ||
p.deactivate(); | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
#include <xtensor/xjson.hpp> | ||
|
||
#include "container.hpp" | ||
#include "json.hpp" | ||
#include "objects/types/plane.hpp" | ||
#include "objects/types/segment.hpp" | ||
#include "objects/types/sphere.hpp" | ||
#include "objects/types/superellipsoid.hpp" | ||
#include "objects/types/worm.hpp" | ||
#include "property.hpp" | ||
|
||
namespace nl = nlohmann; | ||
|
||
namespace scopi | ||
{ | ||
|
||
template <std::size_t dim> | ||
auto from_json(const nl::json& j) | ||
{ | ||
using xt_t = xt::xtensor<double, 1>; | ||
scopi_container<dim> container; | ||
|
||
for (const auto& o : j["objects"]) | ||
{ | ||
std::string type = o["type"]; | ||
|
||
if (type == "sphere") | ||
{ | ||
sphere<dim> s({o["position"].get<xt_t>()}, {o["quaternion"].get<xt_t>()}, o["radius"].get<double>()); | ||
container.push_back(s, o["properties"]); | ||
} | ||
else if (type == "superellipsoid") | ||
{ | ||
superellipsoid<dim> s({o["position"].get<xt_t>()}, | ||
{o["quaternion"].get<xt_t>()}, | ||
o["radius"].get<xt_t>(), | ||
o["squareness"].get<xt_t>()); | ||
container.push_back(s, o["properties"]); | ||
} | ||
else if (type == "segment") | ||
{ | ||
segment<dim> s(o["p1"].get<xt_t>(), o["p2"].get<xt_t>()); | ||
container.push_back(s, o["properties"]); | ||
} | ||
else if (type == "plane") | ||
{ | ||
plane<dim> s({o["position"].get<xt_t>()}, {o["quaternion"].get<xt_t>()}); | ||
container.push_back(s, o["properties"]); | ||
} | ||
else if (type == "worm") | ||
{ | ||
std::vector<type::position_t<dim>> pos; | ||
std::vector<type::quaternion_t> q; | ||
for (auto& p : o["worm"]) | ||
{ | ||
pos.push_back(p["position"].get<xt_t>()); | ||
q.push_back(p["quaternion"].get<xt_t>()); | ||
} | ||
worm<dim> w(pos, q, o["worm"][0]["radius"], pos.size()); | ||
container.push_back(w, o["properties"]); | ||
} | ||
} | ||
return container; | ||
} | ||
|
||
// template <std::size_t dim, class Contact> | ||
// auto contact_from_json(const nl::json& j) | ||
// { | ||
// using xt_t = xt::xtensor<double, 1>; | ||
// std::vector<std::pair<std::size_t, std::size_t>> contacts; | ||
|
||
// for (const auto& c : j["contacts"]) | ||
// { | ||
// contacts.push_back({c["id1"], c["id2"]}); | ||
// } | ||
// return contacts; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters