Skip to content

Commit

Permalink
frontend bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ryichando committed Dec 31, 2024
1 parent 3b029d6 commit 7613e04
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/friction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scene.add(\"slope\").rotate(-deg,\"z\").pin()\n",
"\n",
"fixed = scene.build().report()\n",
"fixed.preview();"
"fixed.preview()"
]
},
{
Expand Down
14 changes: 7 additions & 7 deletions examples/hang.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"param = app.session.param().set(\"dt\",0.001)\n",
"param.set(\"strain-limit-eps\", 0.005).set(\"strain-limit-tau\", 0.005)\n",
"param.set(\"frames\",200)\n",
"param.dyn(\"gravity\").time(1).hold().time(1+jitter_time).change(9.8).time(2.0).change(-9.8);"
"param.dyn(\"gravity\").time(1).hold().time(1+jitter_time).change(9.8).time(2.0).change(-9.8)"
]
},
{
Expand All @@ -47,8 +47,8 @@
"outputs": [],
"source": [
"session = app.session.create(\"two-pins-hang\").init(fixed)\n",
"session.start(param).preview();\n",
"session.stream();"
"session.start(param).preview()\n",
"session.stream()"
]
},
{
Expand All @@ -59,7 +59,7 @@
"outputs": [],
"source": [
"# run this cell after sufficnt frames are simulated\n",
"session.animate();"
"session.animate()"
]
},
{
Expand Down Expand Up @@ -105,8 +105,8 @@
"param.set(\"dt\",0.1).set(\"enable-retry\",True)\n",
"\n",
"session = app.session.create(\"two-pins-hang-dt-01\").init(fixed)\n",
"session.start(param).preview();\n",
"session.stream();"
"session.start(param).preview()\n",
"session.stream()"
]
},
{
Expand All @@ -117,7 +117,7 @@
"outputs": [],
"source": [
"# run this cell after sufficnt frames are simulated\n",
"session.animate();"
"session.animate()"
]
},
{
Expand Down
48 changes: 34 additions & 14 deletions frontend/_parse_.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,47 @@ def get_logging_docstrings(root: str) -> dict[str, dict[str, str]]:
desc = ""
description_mode = False

def register(name):
nonlocal par_name
def clear():
nonlocal doc
nonlocal desc
nonlocal description_mode
if desc:
doc["Description"] = desc
if par_name:
doc["filename"] = f"{par_name}.{name}.out"
else:
doc["filename"] = f"{name}.out"
if "Map" in doc:
name = doc["Map"]
del doc["Map"]
doc = {}
desc = ""
description_mode = False
result[name.replace("_", "-")] = doc.copy()

def register(name):
nonlocal par_name
nonlocal doc
nonlocal desc
nonlocal description_mode

if "Name" in doc.keys():
if desc:
doc["Description"] = desc
if par_name:
doc["filename"] = f"{par_name}.{name}.out"
else:
doc["filename"] = f"{name}.out"
if "Map" in doc:
name = doc["Map"]
del doc["Map"]
result[name.replace("_", "-")] = doc.copy()
clear()

def extract_name(line):
start = line.find('"') + 1
end = line.find('"', start)
return line[start:end].replace(" ", "_")
name = line[start:end].replace(" ", "_")
return name

def parse_line(line: str):
nonlocal par_name
nonlocal description_mode
nonlocal desc
nonlocal doc

if line.strip() == "":
clear()

skip_lables = ["File", "Author", "License", "https"]
if line.startswith("//"):
Expand All @@ -58,7 +72,10 @@ def parse_line(line: str):
content = fields[1].strip()
doc[label] = content
elif line.startswith("SimpleLog logging"):
par_name = extract_name(line)
par_name = ""
name = extract_name(line)
register(name)
par_name = name
elif line.startswith("/*== push"):
register(extract_name(line))
elif "logging.push(" in line:
Expand All @@ -78,6 +95,7 @@ def parse_line(line: str):
if "#include" not in line:
parse_line(line)

result = dict(sorted(result.items()))
return result


Expand Down Expand Up @@ -197,4 +215,6 @@ def clear_doc():
curr_attributes = []
else:
curr_attributes = []

result = dict(sorted(result.items()))
return result
5 changes: 1 addition & 4 deletions frontend/_session_.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ def float_or_int(var):
entries.append([float_or_int(entry[0]), float_or_int(entry[1])])
return entries
else:
print(f"File {path} does not exist")
return None

def number(self, name: str):
Expand Down Expand Up @@ -889,9 +888,7 @@ def convert_time(time) -> str:
if live_update and is_running():

def update_dataframe(table, curr_frame):
time_per_frame = convert_time(
self.get.log.number("time-per-frame")
)
time_per_frame = convert_time(self.get.log.number("time-per-frame"))
time_per_step = convert_time(self.get.log.number("time-per-step"))
n_contact = convert_integer(self.get.log.number("num-contact"))
n_newton = convert_integer(self.get.log.number("newton-steps"))
Expand Down
4 changes: 2 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct Args {
// When an object is moving in the air, both drag and lift forces are computed.
// This value controls the ratio of the tangential friction to the normal friction.
#[clap(long, default_value_t = 0.2)]
pub aerial_friction: f32,
pub air_friction: f32,

// Name: Extended Line Search Maximum Time
// Recommended Range: 1.25 to 1.75
Expand Down Expand Up @@ -339,7 +339,7 @@ pub struct Args {
// Description:
// Per-vertex air dragging coefficient.
#[clap(long, default_value_t = 0.0)]
pub isotropic_aerial_friction: f32,
pub isotropic_air_friction: f32,

// Name: Bend Stiffness for Shells
// Recommended Range: 0.0 to 1e2
Expand Down
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub fn make_param(args: &Args) -> data::ParamSet {
data::ParamSet {
time: 0.0,
fitting: false,
aerial_friction: args.aerial_friction,
air_friction: args.air_friction,
air_density: args.air_density,
strain_limit_tau,
strain_limit_eps,
Expand All @@ -355,7 +355,7 @@ pub fn make_param(args: &Args) -> data::ParamSet {
eiganalysis_eps: args.eiganalysis_eps,
friction: args.friction,
friction_eps: args.friction_eps,
isotropic_aerial_friction: args.isotropic_aerial_friction,
isotropic_air_friction: args.isotropic_air_friction,
gravity: Vec3f::new(0.0, args.gravity, 0.0),
wind,
model_shell: match args.model_shell.as_str() {
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct Constraint {
struct ParamSet {
double time;
bool fitting;
float aerial_friction;
float air_friction;
float air_density;
float strain_limit_tau;
float strain_limit_eps;
Expand All @@ -233,7 +233,7 @@ struct ParamSet {
float eiganalysis_eps;
float friction;
float friction_eps;
float isotropic_aerial_friction;
float isotropic_air_friction;
Vec3f gravity;
Vec3f wind;
Model model_shell;
Expand Down
12 changes: 6 additions & 6 deletions src/cpp/energy/energy.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "../eigenanalysis/eigenanalysis.hpp"
#include "../utility/dispatcher.hpp"
#include "../utility/utility.hpp"
#include "model/aerial_damper.hpp"
#include "model/air_damper.hpp"
#include "model/arap.hpp"
#include "model/baraffwitkin.hpp"
#include "model/dihedral_angle.hpp"
Expand Down Expand Up @@ -39,9 +39,9 @@ embed_vertex_force_hessian(const DataSet &data, const Vec<Vec3f> &eval_x,
Mat3x3f H = Mat3x3f::Zero();
if (normal.isZero() == false && param.air_density) {
f += area * param.air_density *
aerial_damper::face_gradient(dt, y, x, normal, wind, param);
air_damper::face_gradient(dt, y, x, normal, wind, param);
H += area * param.air_density *
aerial_damper::face_hessian(dt, normal, param);
air_damper::face_hessian(dt, normal, param);
}
bool pulled(false);
for (unsigned j = 0; j < data.constraint.pull.size; ++j) {
Expand All @@ -58,10 +58,10 @@ embed_vertex_force_hessian(const DataSet &data, const Vec<Vec3f> &eval_x,
f += mass * momentum::gradient(dt, y, target[i]);
H += mass * momentum::hessian(dt);
}
if (param.isotropic_aerial_friction) {
f += param.isotropic_aerial_friction * (y - x) / (dt * dt);
if (param.isotropic_air_friction) {
f += param.isotropic_air_friction * (y - x) / (dt * dt);
H +=
(param.isotropic_aerial_friction / (dt * dt)) * Mat3x3f::Identity();
(param.isotropic_air_friction / (dt * dt)) * Mat3x3f::Identity();
}
if (param.fix_xz && y[1] > param.fix_xz) {
float t = fmin(1.0f, y[1] - param.fix_xz);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// File: aerial_damper.hpp
// File: air_damper.hpp
// Author: Ryoichi Ando (ryoichi.ando@zozo.com)
// License: Apache v2.0

#ifndef AERIAL_DAMP_HPP
#define AERIAL_DAMP_HPP
#ifndef air_DAMP_HPP
#define air_DAMP_HPP

#include "../../data.hpp"

namespace aerial_damper {
namespace air_damper {

__device__ Mat3x3f get_proj_op(const Vec3f &normal) {
return Mat3x3f::Identity() - normal * normal.transpose();
Expand All @@ -20,7 +20,7 @@ __device__ float face_energy(float dt, const Vec3f &x1, const Vec3f &x0,
Mat3x3f P = get_proj_op(normal);
float f = normal.dot(x1 - z);
Vec3f g = P * (x1 - z);
return 0.5f * (f * f + param.aerial_friction * g.squaredNorm()) / (dt * dt);
return 0.5f * (f * f + param.air_friction * g.squaredNorm()) / (dt * dt);
}

__device__ Vec3f face_gradient(float dt, const Vec3f &x1, const Vec3f &x0,
Expand All @@ -29,16 +29,16 @@ __device__ Vec3f face_gradient(float dt, const Vec3f &x1, const Vec3f &x0,
Vec3f z = x0 + dt * wind;
Mat3x3f P = get_proj_op(normal);
return normal * normal.dot(x1 - z) / (dt * dt) +
param.aerial_friction * P * (x1 - z) / (dt * dt);
param.air_friction * P * (x1 - z) / (dt * dt);
}

__device__ Mat3x3f face_hessian(float dt, const Vec3f &normal,
const ParamSet &param) {
Mat3x3f P = get_proj_op(normal);
return normal * normal.transpose() / (dt * dt) +
param.aerial_friction * P / (dt * dt);
param.air_friction * P / (dt * dt);
}

} // namespace aerial_damper
} // namespace air_damper

#endif
4 changes: 2 additions & 2 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ pub struct Constraint {
pub struct ParamSet {
pub time: f64,
pub fitting: bool,
pub aerial_friction: f32,
pub air_friction: f32,
pub air_density: f32,
pub strain_limit_tau: f32,
pub strain_limit_eps: f32,
Expand All @@ -307,7 +307,7 @@ pub struct ParamSet {
pub eiganalysis_eps: f32,
pub friction: f32,
pub friction_eps: f32,
pub isotropic_aerial_friction: f32,
pub isotropic_air_friction: f32,
pub gravity: Vec3f,
pub wind: Vec3f,
pub model_shell: Model,
Expand Down

0 comments on commit 7613e04

Please sign in to comment.